- Workspace
- Collection
- Fs
File system for a collection.
- Workspace
- new Workspace([opts])
- .close() ⇒
Promise.<void>
- .listCollections() ⇒
Promise.<Array.<object>>
- .createCollection(name, [opts]) ⇒
Promise.<Collection>
- .updateCollection(name, info) ⇒
Promise.<void>
- .openCollection(keyOrName) ⇒
Promise.<Collection>
- .fetch() ⇒
Promise.<object>
A Sonar workspace. Provides methods to open collection under this endpoint.
Params
- opts
object
- Optional options.- url
string
= "http://localhost:9191/api/v1/default"
- The API endpoint to talk to. - accessCode
string
- An access code to login at the endpoint. - token
string
- A JSON web token to authorize to the endpoint. - name
string
- The name of this client.
- url
Closes the client.
Get a list of all collections available on this endpoint.
Returns: Promise.<Array.<object>>
- Promise that resolves to an array of collection info objects.
workspace.createCollection(name, [opts]) ⇒ Promise.<Collection>
Creates a collection with name name on the Sonar server. The name may not contain whitespaces. opts is an optional object with:
Returns: Promise.<Collection>
- The created collection.
Params
- name
string
- Name of the new collection, may not contain whitespaces. - opts
object
- Optional options object.- key
string
- Hex string of an existing collection. Will then sync this collection instead of creating a new, empty collection. - alias
string
- When setting key, alias is required and is your nick name within this collection.
- key
Updates the config of a collection.
Params
- name
string
- Name of the collection. - info
object
- [TODO:description]- share
boolean
- Controls whether a collection is shared via p2p.
- share
workspace.openCollection(keyOrName) ⇒ Promise.<Collection>
Returns a Collection object for a given key or name of a collection.
Params
- keyOrName
string
- Key or name of the collection to open/return.
Fetch a resource.
This is a wrapper around the fetch web API. It should be API compatible to fetch, with the following changes:
Returns: Promise.<object>
- If the response has a JSON content type header, the
decoded JSON will be returned. if opts.responseType is 'binary' or 'text',
the response will be returned as a buffer or text.
TODO: Rethink the default responseType cascade.
Params
- *requestType* <code>string</code> <code> = "'json'"</code> - Request encoding and content type.
Supported values are 'json' and 'binary'
- responseType string
= "'text'"
- Response encoding. If the response
has a JSON content type, will always be set to 'json'.
Supported values are 'text', 'binary' and 'stream'.
- params object
- Query string parameters (will be encoded correctly).
- Collection
- new Collection(workspace, nameOrKey)
- .open() ⇒
Promise.<void>
- .close()
- .putFeed(key, [info])
- .query(name, args, [opts]) ⇒
Promise.<Array.<Record>>
- .put(record) ⇒
Promise.<object>
- .get(req, [opts]) ⇒
Promise.<Array.<object>>
- .getVersion(address)
- .del(record) ⇒
Promise.<object>
- .putType(schema) ⇒
Promise.<object>
- .createBatchStream() ⇒
Writable.<Record>
- .sync() ⇒
Promise.<void>
- .createEventStream() ⇒
Readable.<object>
- .pullLiveUpdates()
- .subscribe(Subscription, Async)
- .reindex(Optional)
Remote collection
Params
- workspace
Workspace
- Remote workspace - nameOrKey
string
- Name or key of the collection
Populate info and schemas for this collection from server.
Throws:
- Will throw if this collection does not exist or cannot be accessed.
Close the collection.
Properly closes open HTTP requests.
Put a new feed to the collection.
Params
- key
string
- The hex-encoded key of the feed to add. - info
object
- Optional information about the feed. TODO: Document
Query the collection.
Returns an array of matching records.
Records may have a meta property that includes query-specific metadata (e.g. the score for search queries).
Returns: Promise.<Array.<Record>>
- A promise that resolves to an array of record objects.
Params
- name
string
- The name of a supported query. Supported queries that ship with @arsonar/core are: records, search, relations, history and indexes. - args
object
- The arguments for the query. Depends on the query being used. For records:{ schema, name, id }
For history:{ from: timestamp, to: timestamp }
For search: Either a "string" for a simple full-text search, or a tantivy query object. For indexes:{ schema, prop, value, from, to, reverse, limit }
(to be documented) For relations:{ subject, object, predicate }
where subject and object are ids and predicate istype#field
- opts
object
- Optional options- sync
boolean
= false
- Wait for all pending indexing operations to be finished.
- sync
Put a new record into the collection.
Returns: Promise.<object>
- An object with an { id }
property.
Throws:
- Throws if the record is invalid.
Params
- record
object
- The record.- schema
string
- The schema of the record. - id
string
- The entity id of the record. If empoty an id will be created. - value
object
- Value of the record.
- schema
Get records by their semantic address (type and id) or by their storage address (key and seq).
Returns: Promise.<Array.<object>>
- A promise that resolves to an array of record objects.
Params
- req
object
- The get request. Either{ type, id }
or{ key, seq }
. - opts
object
- Optional options.- sync
boolean
= false
- Wait for all pending indexing operations to be finished.
- sync
Get a specific version of a record.
Params
- address
string
- The block address of the record versionfeedkey@seq
wherefeedkey
is the hex-encoded public key of a feed andseq
is a sequence number (uint).
Deletes a record.
Returns: Promise.<object>
- - An object with { id, type }
properties of the deleted record.
Params
- record
object
- The record to delete. Has to have{ id, type }
properties set.
Add a new type to the collection.
Returns: Promise.<object>
- A promise that resolves to the saved schema object.
Throws:
- Throws if the schema object is invalid or cannot be saved.
Params
- schema
object
- A schema object.
Create a writable stream to put records into the collection.
Example:
const batchStream = collection.createBatchStream()
batch.write(record)
batch.close()
Returns: Writable.<Record>
- A writable stream
Wait for all pending indexing operations to be finished.
Subscribe to events on this collection.
Returns a readable stream that emits event objects.
They look like this:
{ event: string, data: object }
Events are:
update
: with data{ lseq }
feed
: with data{ key }
schema-update
Pull live updates from the server as they happen.
After calling this method once, all new records and record versions
are pulled from the server once available. The update
event
is emitted when new records are about to arrive.
Subscribe to this collection.
This will fetch all records from the first to the last and then waits for new records. Currently only intended for usage in bots (not in short-running Browser clients).
Todo:: Prefix client ID to subscription name.
Todo:: Allow to subscribe from now instead of from the beginning.
Params
- Subscription
string
- name. Has to be unique per running Sonar instance - Async
function
- callback function that will be called for each incoming record
Reindex the secondary indexes (views) in this collection.
Use with care, this can be expensive.
Params
- Optional
Array.<string>
- array of view names to reindex. If unset all views will be reindexed.
File system for a collection.
- Fs
- new Fs(collection)
- .listDrives() ⇒
Promise.<Array.<object>>
- .createFile(stream, [metadata], [opts]) ⇒
Record
- .updateFile(id, stream, [metadata], [opts]) ⇒
Record
- .readFile(id, [opts]) ⇒
Promise.<(ArrayBuffer|Buffer)>
- .getFileMetadata(id) ⇒
Promise.<object>
File system for a collection.
Params
- collection
Collection
- Collection
List the drives that are part of this collection.
Returns: Promise.<Array.<object>>
- Array of drive objects with keys { alias, key, writable }
Create a new file
Returns: Record
- - The created file record
Params
- stream
Stream
|Buffer
- File content as stream or buffer - metadata
object
- File record metadata (see file record schema) - opts
object
- Options. - onUploadProgress: Callback to invoke with upload progress information
Update a file
Returns: Record
- - The created file record
Params
- id
string
- The file record id - stream
Stream
|Buffer
- File content as stream or buffer - metadata
object
- File record metadata (see file record schema) - opts
object
- Options. - onUploadProgress: Callback to invoke with upload progress information
Read a file into a buffer.
Returns: Promise.<(ArrayBuffer|Buffer)>
- The file content. A Buffer object in Node.js, a ArrayBuffer object in the browser.
Throws:
- Will throw if the path is not found.
Params
- id
string
- A file ID - opts
object
- Options. TODO: document.
Get the metadata for a file
Returns: Promise.<object>
- The file record value (metadata)
Throws:
- Will throw if the path is not found.
Params
- id
string
- A file ID