-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move everything in CouchDB to CouchDB-Core, and add basic support for…
… attachments.
- Loading branch information
1 parent
83d25d5
commit 657d8a4
Showing
27 changed files
with
332 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/CouchDB/Boolean.extension.st → src/CouchDB-Core/Boolean.extension.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Extension { #name : #Boolean } | ||
|
||
{ #category : #'*CouchDB' } | ||
{ #category : #'*CouchDB-Core' } | ||
Boolean >> couchWriteOn: aStream [ | ||
self printOn: aStream | ||
] |
2 changes: 1 addition & 1 deletion
2
src/CouchDB/Character.extension.st → src/CouchDB-Core/Character.extension.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/CouchDB/Collection.extension.st → src/CouchDB-Core/Collection.extension.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
Class { | ||
#name : #CouchAttachment, | ||
#superclass : #CouchObject, | ||
#instVars : [ | ||
'document', | ||
'name', | ||
'mimeType', | ||
'stub', | ||
'contents' | ||
], | ||
#category : #'CouchDB-Core-CouchDB-Core' | ||
} | ||
|
||
{ #category : #'instance creation' } | ||
CouchAttachment class >> delete: aCouchAttachment [ | ||
|
||
self request: [ :zn | | ||
zn url: aCouchAttachment address. | ||
zn headerAt: 'If-Match' put: aCouchAttachment revision. | ||
zn delete | ||
] | ||
] | ||
|
||
{ #category : #'instance creation' } | ||
CouchAttachment class >> name: aString mimeType: mimeType in: aCouchDocument [ | ||
"Creates a new instance of receiver belonging to aCouchDocument, | ||
with name aString and a mimeType." | ||
|
||
^self new | ||
setName: aString | ||
mimeType: mimeType asZnMimeType | ||
document: aCouchDocument | ||
|
||
] | ||
|
||
{ #category : #'instance creation' } | ||
CouchAttachment class >> save: aCouchAttachment [ | ||
|
||
self request: [ :zn | | ||
zn url: aCouchAttachment address. | ||
zn headerAt: 'If-Match' put: aCouchAttachment document revision. | ||
zn beBinary. | ||
zn contents: aCouchAttachment contents. | ||
zn contentType: aCouchAttachment mimeType. | ||
zn put | ||
] | ||
] | ||
|
||
{ #category : #accessing } | ||
CouchAttachment >> address [ | ||
|
||
^address ifNil: [ address := self document address / self name ] | ||
] | ||
|
||
{ #category : #accessing } | ||
CouchAttachment >> contents [ | ||
^ contents | ||
] | ||
|
||
{ #category : #accessing } | ||
CouchAttachment >> contents: aByteArray [ | ||
contents := aByteArray | ||
] | ||
|
||
{ #category : #accessing } | ||
CouchAttachment >> document [ | ||
^ document | ||
] | ||
|
||
{ #category : #initialization } | ||
CouchAttachment >> isStub [ | ||
|
||
^contents isNil | ||
] | ||
|
||
{ #category : #accessing } | ||
CouchAttachment >> mimeType [ | ||
^ mimeType | ||
] | ||
|
||
{ #category : #accessing } | ||
CouchAttachment >> name [ | ||
^ name | ||
] | ||
|
||
{ #category : #initialization } | ||
CouchAttachment >> setName: aString mimeType: aZnMimeType document: aCouchDocument [ | ||
|
||
name := aString. | ||
mimeType := aZnMimeType. | ||
document := aCouchDocument | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
" | ||
I'm an utility class created with the purpose of not cluttering other classes with helper methods. | ||
" | ||
Class { | ||
#name : #CouchJSONWriter, | ||
#superclass : #Object, | ||
#category : #'CouchDB-Core-CouchDB-Core' | ||
} | ||
|
||
{ #category : #'character-encoding' } | ||
CouchJSONWriter class >> doesCodePointNeedEscaping: code [ | ||
code < 32 ifTrue: [ ^ true ]. | ||
( code = 34 or: [ code = 92 ]) ifTrue: [ ^ true ]. | ||
^code > 126 | ||
] | ||
|
||
{ #category : #'character-encoding' } | ||
CouchJSONWriter class >> escapeChar: codePoint on: writeStream [ | ||
|
||
codePoint = 34 | ||
ifTrue: [ ^ writeStream nextPutAll: '\"' ]. | ||
codePoint = 92 | ||
ifTrue: [ ^ writeStream nextPutAll: '\\' ]. | ||
codePoint = 47 | ||
ifTrue: [ ^ writeStream nextPutAll: '\/' ]. | ||
codePoint = 8 | ||
ifTrue: [ ^ writeStream nextPutAll: '\b' ]. | ||
codePoint = 12 | ||
ifTrue: [ ^ writeStream nextPutAll: '\f' ]. | ||
codePoint = 10 | ||
ifTrue: [ ^ writeStream nextPutAll: '\n' ]. | ||
codePoint = 13 | ||
ifTrue: [ ^ writeStream nextPutAll: '\r' ]. | ||
codePoint = 9 | ||
ifTrue: [ ^ writeStream nextPutAll: '\t' ]. | ||
|
||
self escapeUnicode: codePoint on: writeStream | ||
] | ||
|
||
{ #category : #'character-encoding' } | ||
CouchJSONWriter class >> escapeUnicode4: codePoint on: writeStream [ | ||
writeStream nextPutAll: '\u'. | ||
codePoint printOn: writeStream base: 16 nDigits: 4 | ||
] | ||
|
||
{ #category : #'character-encoding' } | ||
CouchJSONWriter class >> escapeUnicode: codePoint on: writeStream [ | ||
|
||
codePoint <= 16rFFFF | ||
ifTrue: [ self escapeUnicode4: codePoint on: writeStream ] | ||
ifFalse: [ | ||
codePoint <= 16r10FFFF | ||
ifTrue: [ | leadSurrogate trailSurrogate shifted | | ||
"Characters not in the Basic Multilingual Plane are encoded as a UTF-16 surrogate pair" | ||
"See https://tools.ietf.org/html/rfc7159#section-7" | ||
shifted := codePoint - 16r10000. | ||
leadSurrogate := 16rD800 + (shifted // 16r400). | ||
trailSurrogate := 16rDC00 + (shifted \\ 16r400). | ||
self escapeUnicode4: leadSurrogate on: writeStream. | ||
self escapeUnicode4: trailSurrogate on: writeStream] | ||
ifFalse: [ self error: 'Character Unicode code point outside encoder range' ] ] | ||
] | ||
|
||
{ #category : #writing } | ||
CouchJSONWriter class >> writeChar: char on: writeStream [ | ||
|
||
| codePoint | | ||
codePoint := char codePoint. | ||
(self doesCodePointNeedEscaping: codePoint) | ||
ifTrue: [ self escapeChar: codePoint on: writeStream ] | ||
ifFalse: [ writeStream nextPut: char ] | ||
] | ||
|
||
{ #category : #writing } | ||
CouchJSONWriter class >> writeString: aString on: aStream [ | ||
aStream nextPut: $". | ||
aString do: [ :char | self writeChar: char on: aStream ]. | ||
aStream nextPut: $" | ||
] |
Oops, something went wrong.