-
Notifications
You must be signed in to change notification settings - Fork 40
Indirect JavaScript Binding
A JavaScript binding would of course be very useful. However, some popular JavaScript-based app environments like PhoneGap / Cordova and React Native don't support direct bindings to native code; instead, they define an RPC-like mechanism where native plugins define named functions that take and return JSON objects:
Thus, to support these we'll need to define an internal API that uses such a mechanism.
In particular, since there's no intrinsic notion of an object, it probably makes more sense to use a stateless API as much as we can. That's a lot like the REST API; we can borrow some ideas from it.
Databases are identified by name. A database is implicitly opened when first referred to. (Do we need API to close a db?)
Document bodies do not have "magic" properties like _id
. Metadata is outside the body.
An error is a two-element array [domain, code, message]
, matching the C CBLError
struct.
Parameters: db
Result: true
or error
Parameters: db
Result: true
or error
Parameters: db
, enabled
Parameters: db
, id
Result: Document body
Parameters: db
, ids
Result: Object mapping ids to document bodies
Parameters: db
, id
, body
, delete
Result: true
, or [
error code, message]
Parameters: db
, docs
Result: Object mapping ids to errors
docs
is an array of {id:, body:, delete:}
objects.
Parameters: db
, ids
Result: Object mapping ids to errors
Parameters: db
, spec
Result: Number (query ID) or error
Parameters: db
, query
Result: true
or error
Parameters: db
, query
Result: {rows:[]}
or error
These use the reverse mechanism where PhoneGap/React lets native code invoke a named function that's handled by a callback registered by JS code.
parameters: db
, docs
docs
is an array of docIDs.