Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Woops, missed adding of touchdb framework

  • Loading branch information...
commit 7e0da5a8249cecaed59f993459ad256ee4b68d38 1 parent 7c27434
@deepwinter authored
Showing with 1,044 additions and 0 deletions.
  1. BIN  Frameworks/TouchDB.framework/.DS_Store
  2. +38 −0 Frameworks/TouchDB.framework/Headers/TDBody.h
  3. +71 −0 Frameworks/TouchDB.framework/Headers/TDDatabase+Attachments.h
  4. +63 −0 Frameworks/TouchDB.framework/Headers/TDDatabase+Insertion.h
  5. +24 −0 Frameworks/TouchDB.framework/Headers/TDDatabase+LocalDocs.h
  6. +26 −0 Frameworks/TouchDB.framework/Headers/TDDatabase+Replication.h
  7. +159 −0 Frameworks/TouchDB.framework/Headers/TDDatabase.h
  8. +43 −0 Frameworks/TouchDB.framework/Headers/TDPuller.h
  9. +22 −0 Frameworks/TouchDB.framework/Headers/TDPusher.h
  10. +118 −0 Frameworks/TouchDB.framework/Headers/TDReplicator.h
  11. +98 −0 Frameworks/TouchDB.framework/Headers/TDRevision.h
  12. +98 −0 Frameworks/TouchDB.framework/Headers/TDRouter.h
  13. +33 −0 Frameworks/TouchDB.framework/Headers/TDServer.h
  14. +49 −0 Frameworks/TouchDB.framework/Headers/TDStatus.h
  15. +42 −0 Frameworks/TouchDB.framework/Headers/TDURLProtocol.h
  16. +111 −0 Frameworks/TouchDB.framework/Headers/TDView.h
  17. +23 −0 Frameworks/TouchDB.framework/Headers/TouchDB.h
  18. BIN  Frameworks/TouchDB.framework/Info.plist
  19. BIN  Frameworks/TouchDB.framework/TouchDB
  20. +26 −0 Frameworks/TouchDBListener.framework/Headers/TDListener.h
  21. BIN  Frameworks/TouchDBListener.framework/TouchDBListener
View
BIN  Frameworks/TouchDB.framework/.DS_Store
Binary file not shown
View
38 Frameworks/TouchDB.framework/Headers/TDBody.h
@@ -0,0 +1,38 @@
+//
+// TDBody.h
+// TouchDB
+//
+// Created by Jens Alfke on 6/19/10.
+// Copyright (c) 2011 Couchbase, Inc. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+
+/** A request/response/document body, stored as either JSON or an NSDictionary. */
+@interface TDBody : NSObject
+{
+ @private
+ NSData* _json;
+ NSDictionary* _object;
+ BOOL _error;
+}
+
+- (id) initWithProperties: (NSDictionary*)properties;
+- (id) initWithArray: (NSArray*)array;
+- (id) initWithJSON: (NSData*)json;
+
++ (TDBody*) bodyWithProperties: (id)properties;
++ (TDBody*) bodyWithJSON: (NSData*)json;
+
+@property (readonly) BOOL isValidJSON;
+@property (readonly) NSData* asJSON;
+@property (readonly) NSData* asPrettyJSON;
+@property (readonly) NSString* asJSONString;
+@property (readonly) id asObject;
+@property (readonly) BOOL error;
+
+@property (readonly) NSDictionary* properties;
+- (id) propertyForKey: (NSString*)key;
+
+@end
View
71 Frameworks/TouchDB.framework/Headers/TDDatabase+Attachments.h
@@ -0,0 +1,71 @@
+//
+// TDDatabase+Attachments.h
+// TouchDB
+//
+// Created by Jens Alfke on 1/18/12.
+// Copyright (c) 2012 Couchbase, Inc. All rights reserved.
+//
+
+#import "TDDatabase.h"
+@class TDBlobStoreWriter, TDMultipartWriter;
+
+
+/** Types of encoding/compression of stored attachments. */
+typedef enum {
+ kTDAttachmentEncodingNone,
+ kTDAttachmentEncodingGZIP
+} TDAttachmentEncoding;
+
+
+@interface TDDatabase (Attachments)
+
+/** Creates a TDBlobStoreWriter object that can be used to stream an attachment to the store. */
+- (TDBlobStoreWriter*) attachmentWriter;
+
+/** Creates TDAttachment objects from the revision's '_attachments' property. */
+- (NSDictionary*) attachmentsFromRevision: (TDRevision*)rev
+ status: (TDStatus*)outStatus;
+
+/** Given a newly-added revision, adds the necessary attachment rows to the database and stores inline attachments into the blob store. */
+- (TDStatus) processAttachments: (NSDictionary*)attachments
+ forRevision: (TDRevision*)rev
+ withParentSequence: (SequenceNumber)parentSequence;
+
+/** Constructs an "_attachments" dictionary for a revision, to be inserted in its JSON body. */
+- (NSDictionary*) getAttachmentDictForSequence: (SequenceNumber)sequence
+ options: (TDContentOptions)options;
+
+/** Modifies a TDRevision's _attachments dictionary by changing all attachments with revpos < minRevPos into stubs; and if 'attachmentsFollow' is true, the remaining attachments will be modified to _not_ be stubs but include a "follows" key instead of a body. */
++ (void) stubOutAttachmentsIn: (TDRevision*)rev
+ beforeRevPos: (int)minRevPos
+ attachmentsFollow: (BOOL)attachmentsFollow;
+
+/** Generates a MIME multipart writer for a revision, with separate body parts for each attachment whose "follows" property is set. */
+- (TDMultipartWriter*) multipartWriterForRevision: (TDRevision*)rev
+ contentType: (NSString*)contentType;
+
+/** Returns the content and metadata of an attachment.
+ If you pass NULL for the 'outEncoding' parameter, it signifies that you don't care about encodings and just want the 'real' data, so it'll be decoded for you. */
+- (NSData*) getAttachmentForSequence: (SequenceNumber)sequence
+ named: (NSString*)filename
+ type: (NSString**)outType
+ encoding: (TDAttachmentEncoding*)outEncoding
+ status: (TDStatus*)outStatus;
+
+/** Uses the "digest" field of the attachment dict to look up the attachment in the store and return an input stream to read its data. */
+- (NSInputStream*) inputStreamForAttachmentDict: (NSDictionary*)attachmentDict
+ length: (UInt64*)outLength;
+
+/** Deletes obsolete attachments from the database and blob store. */
+- (TDStatus) garbageCollectAttachments;
+
+/** Updates or deletes an attachment, creating a new document revision in the process.
+ Used by the PUT / DELETE methods called on attachment URLs. */
+- (TDRevision*) updateAttachment: (NSString*)filename
+ body: (NSData*)body
+ type: (NSString*)contentType
+ encoding: (TDAttachmentEncoding)encoding
+ ofDocID: (NSString*)docID
+ revID: (NSString*)oldRevID
+ status: (TDStatus*)outStatus;
+@end
View
63 Frameworks/TouchDB.framework/Headers/TDDatabase+Insertion.h
@@ -0,0 +1,63 @@
+//
+// TDDatabase+Insertion.h
+// TouchDB
+//
+// Created by Jens Alfke on 1/18/12.
+// Copyright (c) 2012 Couchbase, Inc. All rights reserved.
+//
+
+#import "TDDatabase.h"
+@protocol TDValidationContext;
+
+
+/** Validation block, used to approve revisions being added to the database. */
+typedef BOOL (^TDValidationBlock) (TDRevision* newRevision,
+ id<TDValidationContext> context);
+
+
+@interface TDDatabase (Insertion)
+
++ (BOOL) isValidDocumentID: (NSString*)str;
+
++ (NSString*) generateDocumentID;
+
+/** Stores a new (or initial) revision of a document. This is what's invoked by a PUT or POST. As with those, the previous revision ID must be supplied when necessary and the call will fail if it doesn't match.
+ @param revision The revision to add. If the docID is nil, a new UUID will be assigned. Its revID must be nil. It must have a JSON body.
+ @param prevRevID The ID of the revision to replace (same as the "?rev=" parameter to a PUT), or nil if this is a new document.
+ @param allowConflict If NO, an error status kTDStatusConflict will be returned if the insertion would create a conflict, i.e. if the previous revision already has a child.
+ @param status On return, an HTTP status code indicating success or failure.
+ @return A new TDRevision with the docID, revID and sequence filled in (but no body). */
+- (TDRevision*) putRevision: (TDRevision*)revision
+ prevRevisionID: (NSString*)prevRevID
+ allowConflict: (BOOL)allowConflict
+ status: (TDStatus*)outStatus;
+
+/** Inserts an already-existing revision replicated from a remote database. It must already have a revision ID. This may create a conflict! The revision's history must be given; ancestor revision IDs that don't already exist locally will create phantom revisions with no content. */
+- (TDStatus) forceInsert: (TDRevision*)rev
+ revisionHistory: (NSArray*)history
+ source: (NSURL*)source;
+
+/** Parses the _revisions dict from a document into an array of revision ID strings */
++ (NSArray*) parseCouchDBRevisionHistory: (NSDictionary*)docProperties;
+
+/** Define or clear a named document validation function. */
+- (void) defineValidation: (NSString*)validationName asBlock: (TDValidationBlock)validationBlock;
+- (TDValidationBlock) validationNamed: (NSString*)validationName;
+
+@end
+
+
+
+/** Context passed into a TDValidationBlock. */
+@protocol TDValidationContext <NSObject>
+/** The contents of the current revision of the document, or nil if this is a new document. */
+@property (readonly) TDRevision* currentRevision;
+
+/** The type of HTTP status to report, if the validate block returns NO.
+ The default value is 403 ("Forbidden"). */
+@property TDStatus errorType;
+
+/** The error message to return in the HTTP response, if the validate block returns NO.
+ The default value is "invalid document". */
+@property (copy) NSString* errorMessage;
+@end
View
24 Frameworks/TouchDB.framework/Headers/TDDatabase+LocalDocs.h
@@ -0,0 +1,24 @@
+//
+// TDDatabase+LocalDocs.h
+// TouchDB
+//
+// Created by Jens Alfke on 1/10/12.
+// Copyright (c) 2012 Couchbase, Inc. All rights reserved.
+//
+
+#import "TDDatabase.h"
+
+
+@interface TDDatabase (LocalDocs)
+
+- (TDRevision*) getLocalDocumentWithID: (NSString*)docID
+ revisionID: (NSString*)revID;
+
+- (TDRevision*) putLocalRevision: (TDRevision*)revision
+ prevRevisionID: (NSString*)prevRevID
+ status: (TDStatus*)outStatus;
+
+- (TDStatus) deleteLocalDocumentWithID: (NSString*)docID
+ revisionID: (NSString*)revID;
+
+@end
View
26 Frameworks/TouchDB.framework/Headers/TDDatabase+Replication.h
@@ -0,0 +1,26 @@
+//
+// TDDatabase+Replication.h
+// TouchDB
+//
+// Created by Jens Alfke on 1/18/12.
+// Copyright (c) 2012 Couchbase, Inc. All rights reserved.
+//
+
+#import "TDDatabase.h"
+@class TDReplicator;
+
+
+@interface TDDatabase (Replication)
+
+@property (readonly) NSArray* activeReplicators;
+
+- (TDReplicator*) activeReplicatorWithRemoteURL: (NSURL*)remote
+ push: (BOOL)push;
+
+- (TDReplicator*) replicatorWithRemoteURL: (NSURL*)remote
+ push: (BOOL)push
+ continuous: (BOOL)continuous;
+
+- (BOOL) findMissingRevisions: (TDRevisionList*)revs;
+
+@end
View
159 Frameworks/TouchDB.framework/Headers/TDDatabase.h
@@ -0,0 +1,159 @@
+/*
+ * TDDatabase.h
+ * TouchDB
+ *
+ * Created by Jens Alfke on 6/19/10.
+ * Copyright (c) 2011 Couchbase, Inc. All rights reserved.
+ *
+ */
+
+#import <TouchDB/TDRevision.h>
+#import "TDStatus.h"
+@class FMDatabase, TDView, TDBlobStore;
+struct TDQueryOptions; // declared in TDView.h
+
+
+/** NSNotification posted when a document is updated.
+ The userInfo key "rev" has a TDRevision* as its value. */
+extern NSString* const TDDatabaseChangeNotification;
+
+
+/** Filter block, used in changes feeds and replication. */
+typedef BOOL (^TDFilterBlock) (TDRevision* revision);
+
+
+/** Options for what metadata to include in document bodies */
+typedef unsigned TDContentOptions;
+enum {
+ kTDIncludeAttachments = 1, // adds inline bodies of attachments
+ kTDIncludeConflicts = 2, // adds '_conflicts' property (if relevant)
+ kTDIncludeRevs = 4, // adds '_revisions' property
+ kTDIncludeRevsInfo = 8, // adds '_revs_info' property
+ kTDIncludeLocalSeq = 16, // adds '_local_seq' property
+ kTDLeaveAttachmentsEncoded = 32, // i.e. don't decode
+ kTDBigAttachmentsFollow = 64, // i.e. add 'follows' key instead of data for big ones
+ kTDNoBody = 128 // omit regular doc body properties
+};
+
+
+/** Options for _changes feed (-changesSinceSequence:). */
+typedef struct TDChangesOptions {
+ unsigned limit;
+ TDContentOptions contentOptions;
+ BOOL includeDocs;
+ BOOL includeConflicts;
+ BOOL sortBySequence;
+} TDChangesOptions;
+
+extern const TDChangesOptions kDefaultTDChangesOptions;
+
+
+
+/** A TouchDB database. */
+@interface TDDatabase : NSObject
+{
+ @private
+ NSString* _path;
+ NSString* _name;
+ FMDatabase *_fmdb;
+ BOOL _open;
+ NSInteger _transactionLevel;
+ NSMutableDictionary* _views;
+ NSMutableDictionary* _validations;
+ NSMutableDictionary* _filters;
+ TDBlobStore* _attachments;
+ NSMutableDictionary* _pendingAttachmentsByDigest;
+ NSMutableArray* _activeReplicators;
+}
+
+- (id) initWithPath: (NSString*)path;
+- (BOOL) open;
+- (BOOL) close;
+- (BOOL) deleteDatabase: (NSError**)outError;
+
++ (TDDatabase*) createEmptyDBAtPath: (NSString*)path;
+
+/** Replaces the database with a copy of another database.
+ This is primarily used to install a canned database on first launch of an app, in which case you should first check .exists to avoid replacing the database if it exists already. The canned database would have been copied into your app bundle at build time.
+ @param databasePath Path of the database file that should replace this one.
+ @param attachmentsPath Path of the associated attachments directory, or nil if there are no attachments.
+ @param error If an error occurs, it will be stored into this parameter on return.
+ @return YES if the database was copied, NO if an error occurred. */
+- (BOOL) replaceWithDatabaseFile: (NSString*)databasePath
+ withAttachments: (NSString*)attachmentsPath
+ error: (NSError**)outError;
+
+@property (readonly) NSString* path;
+@property (readonly, copy) NSString* name;
+@property (readonly) BOOL exists;
+@property (readonly) UInt64 totalDataSize;
+
+@property (readonly) NSUInteger documentCount;
+@property (readonly) SequenceNumber lastSequence;
+@property (readonly) NSString* privateUUID;
+@property (readonly) NSString* publicUUID;
+
+/** Begins a database transaction. Transactions can nest. Every -beginTransaction must be balanced by a later -endTransaction:. */
+- (BOOL) beginTransaction;
+
+/** Commits or aborts (rolls back) a transaction.
+ @param commit If YES, commits; if NO, aborts and rolls back, undoing all changes made since the matching -beginTransaction call, *including* any committed nested transactions. */
+- (BOOL) endTransaction: (BOOL)commit;
+
+/** Compacts the database storage by removing the bodies and attachments of obsolete revisions. */
+- (TDStatus) compact;
+
+// DOCUMENTS:
+
+- (TDRevision*) getDocumentWithID: (NSString*)docID
+ revisionID: (NSString*)revID
+ options: (TDContentOptions)options;
+
+- (BOOL) existsDocumentWithID: (NSString*)docID
+ revisionID: (NSString*)revID;
+
+- (TDStatus) loadRevisionBody: (TDRevision*)rev
+ options: (TDContentOptions)options;
+
+/** Returns an array of TDRevs in reverse chronological order,
+ starting with the given revision. */
+- (NSArray*) getRevisionHistory: (TDRevision*)rev;
+
+/** Returns the revision history as a _revisions dictionary, as returned by the REST API's ?revs=true option. */
+- (NSDictionary*) getRevisionHistoryDict: (TDRevision*)rev;
+
+/** Returns all the known revisions (or all current/conflicting revisions) of a document. */
+- (TDRevisionList*) getAllRevisionsOfDocumentID: (NSString*)docID
+ onlyCurrent: (BOOL)onlyCurrent;
+
+- (NSArray*) getConflictingRevisionIDsOfDocID: (NSString*)docID;
+
+/** Returns all known revision IDs of the same document, that have a lower generation number. */
+- (NSArray*) getPossibleAncestorRevisionIDs: (TDRevision*)rev;
+
+/** Returns the most recent member of revIDs that appears in rev's ancestry. */
+- (NSString*) findCommonAncestorOf: (TDRevision*)rev withRevIDs: (NSArray*)revIDs;
+
+// VIEWS & QUERIES:
+
+- (NSDictionary*) getAllDocs: (const struct TDQueryOptions*)options;
+
+- (NSDictionary*) getDocsWithIDs: (NSArray*)docIDs
+ options: (const struct TDQueryOptions*)options;
+
+- (TDView*) viewNamed: (NSString*)name;
+
+- (TDView*) existingViewNamed: (NSString*)name;
+
+@property (readonly) NSArray* allViews;
+
+- (TDRevisionList*) changesSinceSequence: (SequenceNumber)lastSequence
+ options: (const TDChangesOptions*)options
+ filter: (TDFilterBlock)filter;
+
+/** Define or clear a named filter function. These aren't used directly by TDDatabase, but they're looked up by TDRouter when a _changes request has a ?filter parameter. */
+- (void) defineFilter: (NSString*)filterName asBlock: (TDFilterBlock)filterBlock;
+
+- (TDFilterBlock) filterNamed: (NSString*)filterName;
+
+@end
View
43 Frameworks/TouchDB.framework/Headers/TDPuller.h
@@ -0,0 +1,43 @@
+//
+// TDPuller.h
+// TouchDB
+//
+// Created by Jens Alfke on 12/2/11.
+// Copyright (c) 2011 Couchbase, Inc. All rights reserved.
+//
+
+#import "TDReplicator.h"
+#import "TDRevision.h"
+@class TDChangeTracker, TDSequenceMap;
+
+
+/** Replicator that pulls from a remote CouchDB. */
+@interface TDPuller : TDReplicator
+{
+ @private
+ TDChangeTracker* _changeTracker;
+ NSString* _endingSequence;
+ TDSequenceMap* _pendingSequences;
+ NSMutableArray* _revsToPull;
+ NSMutableArray* _deletedRevsToPull;
+ NSMutableArray* _bulkRevsToPull;
+ NSUInteger _httpConnectionCount;
+ TDBatcher* _downloadsToInsert;
+}
+
+@end
+
+
+
+/** A revision received from a remote server during a pull. Tracks the opaque remote sequence ID. */
+@interface TDPulledRevision : TDRevision
+{
+@private
+ NSString* _remoteSequenceID;
+ bool _conflicted;
+}
+
+@property (copy) NSString* remoteSequenceID;
+@property bool conflicted;
+
+@end
View
22 Frameworks/TouchDB.framework/Headers/TDPusher.h
@@ -0,0 +1,22 @@
+//
+// TDPusher.h
+// TouchDB
+//
+// Created by Jens Alfke on 12/5/11.
+// Copyright (c) 2011 Couchbase, Inc. All rights reserved.
+//
+
+#import "TDPuller.h"
+#import "TDDatabase.h"
+
+
+/** Replicator that pushes to a remote CouchDB. */
+@interface TDPusher : TDReplicator
+{
+ BOOL _createTarget;
+ BOOL _observing;
+}
+
+@property BOOL createTarget;
+
+@end
View
118 Frameworks/TouchDB.framework/Headers/TDReplicator.h
@@ -0,0 +1,118 @@
+//
+// TDReplicator.h
+// TouchDB
+//
+// Created by Jens Alfke on 12/6/11.
+// Copyright (c) 2011 Couchbase, Inc. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@class TDDatabase, TDRevisionList, TDBatcher, TDReachability;
+@protocol TDAuthorizer;
+
+
+/** Posted when changesProcessed or changesTotal changes. */
+extern NSString* TDReplicatorProgressChangedNotification;
+
+/** Posted when replicator stops running. */
+extern NSString* TDReplicatorStoppedNotification;
+
+
+/** Abstract base class for push or pull replications. */
+@interface TDReplicator : NSObject
+{
+ @protected
+ TDDatabase* _db;
+ NSURL* _remote;
+ TDReachability* _host;
+ BOOL _continuous;
+ NSString* _filterName;
+ NSDictionary* _filterParameters;
+ NSString* _lastSequence;
+ BOOL _lastSequenceChanged;
+ NSDictionary* _remoteCheckpoint;
+ BOOL _savingCheckpoint, _overdueForSave;
+ BOOL _running, _online, _active;
+ NSError* _error;
+ NSString* _sessionID;
+ TDBatcher* _batcher;
+ int _asyncTaskCount;
+ NSUInteger _changesProcessed, _changesTotal;
+ CFAbsoluteTime _startTime;
+ id<TDAuthorizer> _authorizer;
+}
+
+- (id) initWithDB: (TDDatabase*)db
+ remote: (NSURL*)remote
+ push: (BOOL)push
+ continuous: (BOOL)continuous;
+
+@property (readonly) TDDatabase* db;
+@property (readonly) NSURL* remote;
+@property (readonly) BOOL isPush;
+@property (readonly) BOOL continuous;
+@property (copy) NSString* filterName;
+@property (copy) NSDictionary* filterParameters;
+@property (retain) id<TDAuthorizer> authorizer;
+
+/** Starts the replicator.
+ Replicators run asynchronously so nothing will happen until later.
+ A replicator can only be started once; don't reuse it after it stops. */
+- (void) start;
+
+/** Request to stop the replicator.
+ Any pending asynchronous operations will be finished first.
+ TDReplicatorStoppedNotification will be posted when it finally stops. */
+- (void) stop;
+
+/** Is the replicator running? (Observable) */
+@property (readonly, nonatomic) BOOL running;
+
+/** Is the replicator able to connect to the remote host? */
+@property (readonly, nonatomic) BOOL online;
+
+/** Is the replicator actively sending/receiving revisions? (Observable) */
+@property (readonly, nonatomic) BOOL active;
+
+/** Latest error encountered while replicating.
+ This is set to nil when starting. It may also be set to nil by the client if desired.
+ Not all errors are fatal; if .running is still true, the replicator will retry. */
+@property (retain, nonatomic) NSError* error;
+
+/** A unique-per-process string identifying this replicator instance. */
+@property (copy, nonatomic) NSString* sessionID;
+
+/** Number of changes (docs or other metadata) transferred so far. */
+@property (readonly, nonatomic) NSUInteger changesProcessed;
+
+/** Approximate total number of changes to transfer.
+ This is only an estimate and its value will change during replication. It starts at zero and returns to zero when replication stops. */
+@property (readonly, nonatomic) NSUInteger changesTotal;
+
+@end
+
+
+
+/** Protocol for adding authorization to HTTP requests sent by a TDReplicator. */
+@protocol TDAuthorizer <NSObject>
+
+/** Should generate and return an authorization string for the given request.
+ The string, if non-nil, will be set as the value of the "Authorization:" HTTP header. */
+- (NSString*) authorizeURLRequest: (NSMutableURLRequest*)request;
+
+@end
+
+
+
+/** Simple implementation of TDAuthorizer that does HTTP Basic Auth. */
+@interface TDBasicAuthorizer : NSObject <TDAuthorizer>
+{
+ @private
+ NSURLCredential* _credential;
+}
+
+/** Initialize given a credential object that contains a username and password. */
+- (id) initWithCredential: (NSURLCredential*)credential;
+
+@end
View
98 Frameworks/TouchDB.framework/Headers/TDRevision.h
@@ -0,0 +1,98 @@
+//
+// TDRevision.h
+// TouchDB
+//
+// Created by Jens Alfke on 12/2/11.
+// Copyright (c) 2011 Couchbase, Inc. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+@class TDBody;
+
+
+/** Database sequence ID */
+typedef SInt64 SequenceNumber;
+
+
+/** Stores information about a revision -- its docID, revID, and whether it's deleted. It can also store the sequence number and document contents (they can be added after creation). */
+@interface TDRevision : NSObject
+{
+ @private
+ NSString* _docID, *_revID;
+ BOOL _deleted;
+ TDBody* _body;
+ SequenceNumber _sequence;
+}
+
+- (id) initWithDocID: (NSString*)docID
+ revID: (NSString*)revID
+ deleted: (BOOL)deleted;
+- (id) initWithBody: (TDBody*)body;
+- (id) initWithProperties: (NSDictionary*)properties;
+
++ (TDRevision*) revisionWithProperties: (NSDictionary*)properties;
+
+@property (readonly) NSString* docID;
+@property (readonly) NSString* revID;
+@property (readonly) BOOL deleted;
+
+@property (retain) TDBody* body;
+@property (copy) NSDictionary* properties;
+@property (copy) NSData* asJSON;
+
+@property SequenceNumber sequence;
+
+- (NSComparisonResult) compareSequences: (TDRevision*)rev;
+
+/** Generation number: 1 for a new document, 2 for the 2nd revision, ...
+ Extracted from the numeric prefix of the revID. */
+@property (readonly) unsigned generation;
+
++ (unsigned) generationFromRevID: (NSString*)revID;
+
++ (BOOL) parseRevID: (NSString*)revID
+ intoGeneration: (int*)outNum
+ andSuffix: (NSString**)outSuffix;
+
+- (TDRevision*) copyWithDocID: (NSString*)docID revID: (NSString*)revID;
+
+@end
+
+
+
+/** An ordered list of TDRevs. */
+@interface TDRevisionList : NSObject <NSFastEnumeration>
+{
+ @private
+ NSMutableArray* _revs;
+}
+
+- (id) init;
+- (id) initWithArray: (NSArray*)revs;
+
+@property (readonly) NSUInteger count;
+
+- (TDRevision*) revWithDocID: (NSString*)docID revID: (NSString*)revID;
+
+- (NSEnumerator*) objectEnumerator;
+
+@property (readonly) NSArray* allRevisions;
+@property (readonly) NSArray* allDocIDs;
+@property (readonly) NSArray* allRevIDs;
+
+- (void) addRev: (TDRevision*)rev;
+- (void) removeRev: (TDRevision*)rev;
+
+- (void) limit: (NSUInteger)limit;
+- (void) sortBySequence;
+
+@end
+
+
+/** Compares revision IDs by CouchDB rules: generation number first, then the suffix. */
+NSComparisonResult TDCompareRevIDs(NSString* revID1, NSString* revID2);
+
+/** SQLite-compatible collation (comparison) function for revision IDs. */
+int TDCollateRevIDs(void *context,
+ int len1, const void * chars1,
+ int len2, const void * chars2);
View
98 Frameworks/TouchDB.framework/Headers/TDRouter.h
@@ -0,0 +1,98 @@
+//
+// TDRouter.h
+// TouchDB
+//
+// Created by Jens Alfke on 11/30/11.
+// Copyright (c) 2011 Couchbase, Inc. All rights reserved.
+//
+
+#import "TDDatabase.h"
+@class TDServer, TDDatabaseManager, TDResponse, TDBody, TDMultipartWriter;
+
+
+typedef void (^OnResponseReadyBlock)(TDResponse*);
+typedef void (^OnDataAvailableBlock)(NSData* data, BOOL finished);
+typedef void (^OnFinishedBlock)();
+
+
+@interface TDRouter : NSObject
+{
+ @private
+ TDServer* _server;
+ TDDatabaseManager* _dbManager;
+ NSURLRequest* _request;
+ NSMutableArray* _path;
+ NSDictionary* _queries;
+ TDResponse* _response;
+ TDDatabase* _db;
+ BOOL _waiting;
+ BOOL _responseSent;
+ OnResponseReadyBlock _onResponseReady;
+ OnDataAvailableBlock _onDataAvailable;
+ OnFinishedBlock _onFinished;
+ BOOL _running;
+ BOOL _longpoll;
+ TDFilterBlock _changesFilter;
+ BOOL _changesIncludeDocs;
+}
+
+- (id) initWithServer: (TDServer*)server request: (NSURLRequest*)request;
+
+@property (copy) OnResponseReadyBlock onResponseReady;
+@property (copy) OnDataAvailableBlock onDataAvailable;
+@property (copy) OnFinishedBlock onFinished;
+
+@property (readonly) NSURLRequest* request;
+@property (readonly) TDResponse* response;
+
+- (void) start;
+- (void) stop;
+
++ (NSString*) versionString;
+
+@end
+
+
+@interface TDRouter (Internal)
+- (NSString*) query: (NSString*)param;
+- (BOOL) boolQuery: (NSString*)param;
+- (int) intQuery: (NSString*)param defaultValue: (int)defaultValue;
+- (id) jsonQuery: (NSString*)param error: (NSError**)outError;
+- (BOOL) cacheWithEtag: (NSString*)etag;
+- (TDContentOptions) contentOptions;
+- (BOOL) getQueryOptions: (struct TDQueryOptions*)options;
+@property (readonly) NSString* multipartRequestType;
+@property (readonly) NSDictionary* bodyAsDictionary;
+@property (readonly) NSString* ifMatch;
+- (TDStatus) openDB;
+- (void) sendResponse;
+- (void) finished;
+@end
+
+
+
+@interface TDResponse : NSObject
+{
+ @private
+ TDStatus _internalStatus;
+ int _status;
+ NSString* _statusMsg;
+ NSMutableDictionary* _headers;
+ TDBody* _body;
+}
+
+@property (nonatomic) TDStatus internalStatus;
+@property (nonatomic) int status;
+@property (nonatomic, readonly) NSString* statusMsg;
+@property (nonatomic, retain) NSMutableDictionary* headers;
+@property (nonatomic, retain) TDBody* body;
+@property (nonatomic, copy) id bodyObject;
+@property (nonatomic, readonly) NSString* baseContentType;
+
+- (void) reset;
+- (void) setValue: (NSString*)value ofHeader: (NSString*)header;
+
+- (void) setMultipartBody: (TDMultipartWriter*)mp;
+- (void) setMultipartBody: (NSArray*)parts type: (NSString*)type;
+
+@end
View
33 Frameworks/TouchDB.framework/Headers/TDServer.h
@@ -0,0 +1,33 @@
+//
+// TDServer.h
+// TouchDB
+//
+// Created by Jens Alfke on 11/30/11.
+// Copyright (c) 2011 Couchbase, Inc. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+@class TDDatabase, TDDatabaseManager;
+
+
+/** Thread-safe top-level interface to TouchDB API.
+ A TDServer owns a background thread on which it runs a TDDatabaseManager and all related tasks.
+ The database objects can only be called by queueing blocks that will run on the background thread. */
+@interface TDServer : NSObject
+{
+ @private
+ TDDatabaseManager* _manager;
+ NSThread* _serverThread;
+}
+
+- (id) initWithDirectory: (NSString*)dirPath error: (NSError**)outError;
+
+@property (readonly) NSString* directory;
+
+- (void) queue: (void(^)())block;
+- (void) tellDatabaseManager: (void (^)(TDDatabaseManager*))block;
+- (void) tellDatabaseNamed: (NSString*)dbName to: (void (^)(TDDatabase*))block;
+
+- (void) close;
+
+@end
View
49 Frameworks/TouchDB.framework/Headers/TDStatus.h
@@ -0,0 +1,49 @@
+//
+// TDStatus.h
+// TouchDB
+//
+// Created by Jens Alfke on 4/5/12.
+// Copyright (c) 2012 Couchbase, Inc. All rights reserved.
+//
+
+
+/** TouchDB internal status/error codes. Superset of HTTP status codes. */
+typedef enum {
+ kTDStatusOK = 200,
+ kTDStatusCreated = 201,
+ kTDStatusAccepted = 206,
+
+ kTDStatusNotModified = 304,
+
+ kTDStatusBadRequest = 400,
+ kTDStatusForbidden = 403,
+ kTDStatusNotFound = 404,
+ kTDStatusNotAcceptable = 406,
+ kTDStatusConflict = 409,
+ kTDStatusDuplicate = 412, // Formally known as "Precondition Failed"
+ kTDStatusUnsupportedType= 415,
+
+ kTDStatusServerError = 500,
+ kTDStatusUpstreamError = 502, // aka Bad Gateway -- upstream server error
+
+ // Non-HTTP errors:
+ kTDStatusBadEncoding = 490,
+ kTDStatusBadAttachment = 491,
+ kTDStatusAttachmentNotFound = 492,
+ kTDStatusBadJSON = 493,
+ kTDStatusBadID = 494,
+ kTDStatusBadParam = 495,
+
+ kTDStatusDBError = 590, // SQLite error
+ kTDStatusCorruptError = 591, // bad data in database
+ kTDStatusAttachmentError= 592, // problem with attachment store
+ kTDStatusCallbackError = 593, // app callback (emit fn, etc.) failed
+ kTDStatusException = 594, // Exception raised/caught
+} TDStatus;
+
+
+static inline bool TDStatusIsError(TDStatus status) {return status >= 300;}
+
+int TDStatusToHTTPStatus( TDStatus status, NSString** outMessage );
+
+NSError* TDStatusToNSError( TDStatus status, NSURL* url );
View
42 Frameworks/TouchDB.framework/Headers/TDURLProtocol.h
@@ -0,0 +1,42 @@
+//
+// TDURLProtocol.h
+// TouchDB
+//
+// Created by Jens Alfke on 11/30/11.
+// Copyright (c) 2011 Couchbase, Inc. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+@class TDServer, TDRouter;
+
+@interface TDURLProtocol : NSURLProtocol
+{
+ @private
+ TDRouter* _router;
+}
+
+/** The root URL served by this protocol, "touchdb:///". */
++ (NSURL*) rootURL;
+
+/** Registers a TDServer instance with a URL hostname.
+ 'touchdb:' URLs with that hostname will be routed to that server.
+ If the server is nil, that hostname is unregistered, and URLs with that hostname will cause a host-not-found error.
+ If the hostname is nil or an empty string, "localhost" is substituted. */
++ (NSURL*) registerServer: (TDServer*)server forHostname: (NSString*)hostname;
+
+/** Returns the TDServer instance that's been registered with a specific hostname. */
++ (TDServer*) serverForHostname: (NSString*)hostname;
+
+/** Registers a TDServer instance with a new unique hostname, and returns the root URL at which the server can now be reached. */
++ (NSURL*) registerServer: (TDServer*)server;
+
+/** Unregisters a TDServer. After this, the server can be safely closed. */
++ (void) unregisterServer: (TDServer*)server;
+
+/** A convenience to register a server with the default hostname "localhost". */
++ (void) setServer: (TDServer*)server;
+
+/** Returns the server registered with the hostname "localhost". */
++ (TDServer*) server;
+
+@end
View
111 Frameworks/TouchDB.framework/Headers/TDView.h
@@ -0,0 +1,111 @@
+//
+// TDView.h
+// TouchDB
+//
+// Created by Jens Alfke on 12/8/11.
+// Copyright (c) 2011 Couchbase, Inc. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#import <TouchDB/TDDatabase.h>
+
+
+typedef void (^TDMapEmitBlock)(id key, id value);
+
+/** A "map" function called when a document is to be added to a view.
+ @param doc The contents of the document being analyzed.
+ @param emit A block to be called to add a key/value pair to the view. Your block can call it zero, one or multiple times. */
+typedef void (^TDMapBlock)(NSDictionary* doc, TDMapEmitBlock emit);
+
+/** A "reduce" function called to summarize the results of a view.
+ @param keys An array of keys to be reduced (or nil if this is a rereduce).
+ @param values A parallel array of values to be reduced, corresponding 1::1 with the keys.
+ @param rereduce YES if the input values are the results of previous reductions.
+ @return The reduced value; almost always a scalar or small fixed-size object. */
+typedef id (^TDReduceBlock)(NSArray* keys, NSArray* values, BOOL rereduce);
+
+
+/** Standard query options for views. */
+typedef struct TDQueryOptions {
+ __unsafe_unretained id startKey;
+ __unsafe_unretained id endKey;
+ __unsafe_unretained NSArray* keys;
+ unsigned skip;
+ unsigned limit;
+ unsigned groupLevel;
+ TDContentOptions content;
+ BOOL descending;
+ BOOL includeDocs;
+ BOOL updateSeq;
+ BOOL inclusiveEnd;
+ BOOL reduce;
+ BOOL group;
+} TDQueryOptions;
+
+extern const TDQueryOptions kDefaultTDQueryOptions;
+
+
+typedef enum {
+ kTDViewCollationUnicode,
+ kTDViewCollationRaw,
+ kTDViewCollationASCII
+} TDViewCollation;
+
+
+/** An external object that knows how to map source code of some sort into executable functions. */
+@protocol TDViewCompiler <NSObject>
+- (TDMapBlock) compileMapFunction: (NSString*)mapSource language: (NSString*)language;
+- (TDReduceBlock) compileReduceFunction: (NSString*)reduceSource language: (NSString*)language;
+@end
+
+
+/** Represents a view available in a database. */
+@interface TDView : NSObject
+{
+ @private
+ TDDatabase* _db;
+ NSString* _name;
+ int _viewID;
+ TDMapBlock _mapBlock;
+ TDReduceBlock _reduceBlock;
+ TDViewCollation _collation;
+}
+
+- (void) deleteView;
+
+@property (readonly) TDDatabase* database;
+@property (readonly) NSString* name;
+
+@property (readonly) TDMapBlock mapBlock;
+@property (readonly) TDReduceBlock reduceBlock;
+
+@property TDViewCollation collation;
+
+- (BOOL) setMapBlock: (TDMapBlock)mapBlock
+ reduceBlock: (TDReduceBlock)reduceBlock
+ version: (NSString*)version;
+
+- (void) removeIndex;
+
+/** Is the view's index currently out of date? */
+@property (readonly) BOOL stale;
+
+/** Updates the view's index (incrementally) if necessary.
+ @return 200 if updated, 304 if already up-to-date, else an error code */
+- (TDStatus) updateIndex;
+
+@property (readonly) SequenceNumber lastSequenceIndexed;
+
+/** Queries the view. Does NOT first update the index.
+ @param options The options to use.
+ @return An array of result rows -- each is a dictionary with "key" and "value" keys, and possibly "id" and "doc". */
+- (NSArray*) queryWithOptions: (const TDQueryOptions*)options
+ status: (TDStatus*)outStatus;
+
+/** Utility function to use in reduce blocks. Totals an array of NSNumbers. */
++ (NSNumber*) totalValues: (NSArray*)values;
+
++ (void) setCompiler: (id<TDViewCompiler>)compiler;
++ (id<TDViewCompiler>) compiler;
+
+@end
View
23 Frameworks/TouchDB.framework/Headers/TouchDB.h
@@ -0,0 +1,23 @@
+//
+// TouchDB.h
+// TouchDB
+//
+// Created by Jens Alfke on 12/2/11.
+// Copyright (c) 2011 Couchbase, Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+// except in compliance with the License. You may obtain a copy of the License at
+// http://www.apache.org/licenses/LICENSE-2.0
+// Unless required by applicable law or agreed to in writing, software distributed under the
+// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+// either express or implied. See the License for the specific language governing permissions
+// and limitations under the License.
+
+#import <TouchDB/TDDatabase.h>
+#import <TouchDB/TDServer.h>
+#import <TouchDB/TDView.h>
+#import <TouchDB/TDRevision.h>
+
+#import <TouchDB/TDReplicator.h>
+
+#import <TouchDB/TDURLProtocol.h>
View
BIN  Frameworks/TouchDB.framework/Info.plist
Binary file not shown
View
BIN  Frameworks/TouchDB.framework/TouchDB
Binary file not shown
View
26 Frameworks/TouchDBListener.framework/Headers/TDListener.h
@@ -0,0 +1,26 @@
+//
+// TDListener.h
+// TouchDBListener
+//
+// Created by Jens Alfke on 12/29/11.
+// Copyright (c) 2011 Couchbase, Inc. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+@class TDHTTPServer, TDServer;
+
+
+/** A simple HTTP server that provides remote access to the TouchDB REST API. */
+@interface TDListener : NSObject
+{
+ TDHTTPServer* _httpServer;
+ TDServer* _tdServer;
+}
+
+- (id) initWithTDServer: (TDServer*)server port: (UInt16)port;
+
+- (BOOL) start;
+- (void) stop;
+
+
+@end
View
BIN  Frameworks/TouchDBListener.framework/TouchDBListener
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.