Skip to content
mluto edited this page May 23, 2013 · 5 revisions

Complete me based on src/server/model.coffee All these methods operate on documents, except for closeDb and flushDb.

Available Methods

create (docName, type, meta, callback)

  • docName, the name of the doc to create
  • type, the type of the doc to create
  • meta (optional), ???
  • callback, called with (error, doc)

delete (docName, callback)

  • docName, the name of the doc to delete
  • callback, called with (error)

WARNING: This isn't well supported throughout the code. E.g.: Streaming clients aren't told about the deletion and subsequent op submissions will fail.

getOps (docName, start, end, callback)

  • docName, the name of the doc to get ops from
  • start, first op to get
  • end, can be null, which means 'get me all ops from start'.
  • callback, called with (error, ops)

Gets all operations from [start...end]. (That is, its not inclusive.) Each op returned is in the form {op:o, meta:m, v:version}.

getSnapshot (docName, callback)

  • docName
  • callback, called with (error, {v: <version>, type: <type>, snapshot: <snapshot>, meta: <meta>})

Returns the current state (version, type, content and meta) of this document.

getVersion (docName, callback)

  • docName
  • callback, called with (error, version)

applyOp (docName, opData, callback)

  • docName
  • opData, the operation to apply
  • callback, called with (error, applied version #)

Applies the OT-op given in opData the current content of this document, opData has to be structured like this:

{
  op: [{ /* ... */ }], // array of ops to apply (has to be an array)
  v: 0, // version to apply the op on
  meta: null
}

See JSON-Operations for further documentation of the op-value.

applyMetaOp (docName, metaOpData, callback)

  • docName
  • metaOpData
  • callback

listen (docName, version, listener, callback)

  • docName
  • version
  • listener
  • callback

removeListener (docName, listener)

  • docName
  • listener

flush()

closeDb()