mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-10-07 22:57:07 +00:00
docs: Change namespace from database to databases.
This commit is contained in:
@@ -39,18 +39,18 @@ const defaultCacheSize = 1000
|
||||
* automatically. Otherwise, false.
|
||||
* @param {function} [params.onUpdate] A function callback. Fired when an
|
||||
* entry is added to the oplog.
|
||||
* @return {module:Database~Database} An instance of Database.
|
||||
* @return {module:Databases~Database} An instance of Database.
|
||||
* @instance
|
||||
*/
|
||||
const Database = async ({ ipfs, identity, address, name, access, directory, meta, headsStorage, entryStorage, indexStorage, referencesCount, syncAutomatically, onUpdate }) => {
|
||||
/**
|
||||
* @namespace module:Database~Database
|
||||
* @namespace module:Databases~Database
|
||||
* @description The instance returned by {@link module:Database~Database}.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Event fired when an update occurs.
|
||||
* @event module:Database~Database#update
|
||||
* @event module:Databases~Database#update
|
||||
* @param {module:Entry} entry An entry.
|
||||
* @example
|
||||
* database.events.on('update', (entry) => ...)
|
||||
@@ -58,14 +58,14 @@ const Database = async ({ ipfs, identity, address, name, access, directory, meta
|
||||
|
||||
/**
|
||||
* Event fired when a close occurs.
|
||||
* @event module:Database~Database#close
|
||||
* @event module:Databases~Database#close
|
||||
* @example
|
||||
* database.events.on('close', () => ...)
|
||||
*/
|
||||
|
||||
/**
|
||||
* Event fired when a drop occurs.
|
||||
* @event module:Database~Database#drop
|
||||
* @event module:Databases~Database#drop
|
||||
* @example
|
||||
* database.events.on('drop', () => ...)
|
||||
*/
|
||||
@@ -91,16 +91,6 @@ const Database = async ({ ipfs, identity, address, name, access, directory, meta
|
||||
|
||||
const log = await Log(identity, { logId: address, access, entryStorage, headsStorage, indexStorage })
|
||||
|
||||
/**
|
||||
* Event emitter that emits updates.
|
||||
* @name events
|
||||
* @†ype EventEmitter
|
||||
* @fires update when an entry is added to the database.
|
||||
* @fires close When the database is closed.
|
||||
* @fires drop When the database is dropped.
|
||||
* @memberof module:Database~Database
|
||||
* @instance
|
||||
*/
|
||||
const events = new EventEmitter()
|
||||
|
||||
const queue = new PQueue({ concurrency: 1 })
|
||||
@@ -110,7 +100,7 @@ const Database = async ({ ipfs, identity, address, name, access, directory, meta
|
||||
* @function addOperation
|
||||
* @param {*} op Some operation to add to the oplog.
|
||||
* @return {string} The hash of the operation.
|
||||
* @memberof module:Database~Database
|
||||
* @memberof module:Databases~Database
|
||||
* @instance
|
||||
* @async
|
||||
*/
|
||||
@@ -147,7 +137,7 @@ const Database = async ({ ipfs, identity, address, name, access, directory, meta
|
||||
|
||||
/**
|
||||
* Closes the database, stopping sync and closing the oplog.
|
||||
* @memberof module:Database~Database
|
||||
* @memberof module:Databases~Database
|
||||
* @instance
|
||||
* @async
|
||||
*/
|
||||
@@ -160,7 +150,7 @@ const Database = async ({ ipfs, identity, address, name, access, directory, meta
|
||||
|
||||
/**
|
||||
* Drops the database, clearing the oplog.
|
||||
* @memberof module:Database~Database
|
||||
* @memberof module:Databases~Database
|
||||
* @instance
|
||||
* @async
|
||||
*/
|
||||
@@ -170,15 +160,6 @@ const Database = async ({ ipfs, identity, address, name, access, directory, meta
|
||||
events.emit('drop')
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the [Sync protocol]{@link module:Sync~Sync}.
|
||||
*
|
||||
* Sync protocol exchanges OpLog heads (latest known entries) between peers
|
||||
* when they connect.
|
||||
* @memberof module:Database~Database
|
||||
* @instance
|
||||
* @async
|
||||
*/
|
||||
const sync = await Sync({ ipfs, log, events, onSynced: applyOperation, start: syncAutomatically })
|
||||
|
||||
return {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* @namespace Database-Documents
|
||||
* @memberof module:Database
|
||||
* @namespace Databases-Documents
|
||||
* @memberof module:Databases
|
||||
* @description Documents database.
|
||||
* @example <caption>Create documents db with default options</caption>
|
||||
* import { create } from 'IPFS'
|
||||
@@ -47,15 +47,15 @@ const DefaultOptions = { indexBy: '_id' }
|
||||
* @function
|
||||
* @instance
|
||||
* @async
|
||||
* @memberof module:Database.Database-Documents
|
||||
* @memberof module:Databases.Databases-Documents
|
||||
*/
|
||||
|
||||
/**
|
||||
* Defines a Documents database.
|
||||
* @param {Object} options Various options for configuring the Document store.
|
||||
* @param {string} [params.indexBy=_id] An index.
|
||||
* @return {module:Database.Database-Documents} A Documents function.
|
||||
* @memberof module:Database
|
||||
* @return {module:Databases.Databases-Documents} A Documents function.
|
||||
* @memberof module:Databases
|
||||
*/
|
||||
const Documents = ({ indexBy } = DefaultOptions) => async ({ ipfs, identity, address, name, access, directory, meta, headsStorage, entryStorage, indexStorage, referencesCount, syncAutomatically, onUpdate }) => {
|
||||
const database = await Database({ ipfs, identity, address, name, access, directory, meta, headsStorage, entryStorage, indexStorage, referencesCount, syncAutomatically })
|
||||
@@ -67,7 +67,7 @@ const Documents = ({ indexBy } = DefaultOptions) => async ({ ipfs, identity, add
|
||||
* @function
|
||||
* @param {Object} doc An object representing a key/value list of fields.
|
||||
* @return {string} The hash of the new oplog entry.
|
||||
* @memberof module:Database.Database-Documents
|
||||
* @memberof module:Databases.Databases-Documents
|
||||
* @instance
|
||||
*/
|
||||
const put = async (doc) => {
|
||||
@@ -83,7 +83,7 @@ const Documents = ({ indexBy } = DefaultOptions) => async ({ ipfs, identity, add
|
||||
* @function
|
||||
* @param {string} key The key of the doc to delete.
|
||||
* @return {string} The hash of the new oplog entry.
|
||||
* @memberof module:Database.Database-Documents
|
||||
* @memberof module:Databases.Databases-Documents
|
||||
* @instance
|
||||
*/
|
||||
const del = async (key) => {
|
||||
@@ -97,7 +97,7 @@ const Documents = ({ indexBy } = DefaultOptions) => async ({ ipfs, identity, add
|
||||
* @function
|
||||
* @param {string} key The key of the doc to get.
|
||||
* @return {Object} The doc corresponding to key or null.
|
||||
* @memberof module:Database.Database-Documents
|
||||
* @memberof module:Databases.Databases-Documents
|
||||
* @instance
|
||||
*/
|
||||
const get = async (key) => {
|
||||
@@ -114,7 +114,7 @@ const Documents = ({ indexBy } = DefaultOptions) => async ({ ipfs, identity, add
|
||||
* @param {function(Object)} findFn A function for querying for specific
|
||||
* results.
|
||||
* @return {Array} Found documents.
|
||||
* @memberof module:Database.Database-Documents
|
||||
* @memberof module:Databases.Databases-Documents
|
||||
* @instance
|
||||
*/
|
||||
const query = async (findFn) => {
|
||||
@@ -135,7 +135,7 @@ const Documents = ({ indexBy } = DefaultOptions) => async ({ ipfs, identity, add
|
||||
* @param {Object} [filters={}] Various filters to apply to the iterator.
|
||||
* @param {string} [filters.amount=-1] The number of results to fetch.
|
||||
* @yields [string, string, string] The next document as hash/key/value.
|
||||
* @memberof module:Database.Database-Documents
|
||||
* @memberof module:Databases.Databases-Documents
|
||||
* @instance
|
||||
*/
|
||||
const iterator = async function * ({ amount } = {}) {
|
||||
@@ -162,7 +162,7 @@ const Documents = ({ indexBy } = DefaultOptions) => async ({ ipfs, identity, add
|
||||
* @function
|
||||
* @return [][string, string, string] An array of documents as hash/key
|
||||
* value entries.
|
||||
* @memberof module:Database.Database-Documents
|
||||
* @memberof module:Databases.Databases-Documents
|
||||
* @instance
|
||||
*/
|
||||
const all = async () => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* @namespace Database-Events
|
||||
* @memberof module:Database
|
||||
* @namespace Databases-Events
|
||||
* @memberof module:Databases
|
||||
* @description Events database.
|
||||
*/
|
||||
import Database from '../database.js'
|
||||
@@ -32,13 +32,13 @@ import Database from '../database.js'
|
||||
* @function
|
||||
* @instance
|
||||
* @async
|
||||
* @memberof module:Database.Database-Events
|
||||
* @memberof module:Databases.Databases-Events
|
||||
*/
|
||||
|
||||
/**
|
||||
* Defines an Events database.
|
||||
* @return {module:Database.Database-Events} A Events function.
|
||||
* @memberof module:Database
|
||||
* @return {module:Databases.Databases-Events} A Events function.
|
||||
* @memberof module:Databases
|
||||
*/
|
||||
const Events = () => async ({ ipfs, identity, address, name, access, directory, meta, headsStorage, entryStorage, indexStorage, referencesCount, syncAutomatically, onUpdate }) => {
|
||||
const database = await Database({ ipfs, identity, address, name, access, directory, meta, headsStorage, entryStorage, indexStorage, referencesCount, syncAutomatically, onUpdate })
|
||||
@@ -50,7 +50,7 @@ const Events = () => async ({ ipfs, identity, address, name, access, directory,
|
||||
* @function
|
||||
* @param {*} value The event to be added.
|
||||
* @return {string} The hash of the new oplog entry.
|
||||
* @memberof module:Database.Database-Events
|
||||
* @memberof module:Databases.Databases-Events
|
||||
* @instance
|
||||
*/
|
||||
const add = async (value) => {
|
||||
@@ -62,7 +62,7 @@ const Events = () => async ({ ipfs, identity, address, name, access, directory,
|
||||
* @function
|
||||
* @param {string} hash The hash of the event to get.
|
||||
* @return {*} The value corresponding to hash or null.
|
||||
* @memberof module:Database.Database-Events
|
||||
* @memberof module:Databases.Databases-Events
|
||||
* @instance
|
||||
*/
|
||||
const get = async (hash) => {
|
||||
@@ -84,7 +84,7 @@ const Events = () => async ({ ipfs, identity, address, name, access, directory,
|
||||
* the given hash.
|
||||
* @param {string} [filters.amount=-1] The number of results to fetch.
|
||||
* @yields [string, string] The next event as hash/value.
|
||||
* @memberof module:Database.Database-Events
|
||||
* @memberof module:Databases.Databases-Events
|
||||
* @instance
|
||||
*/
|
||||
const iterator = async function * ({ gt, gte, lt, lte, amount } = {}) {
|
||||
@@ -100,7 +100,7 @@ const Events = () => async ({ ipfs, identity, address, name, access, directory,
|
||||
* Returns all events.
|
||||
* @function
|
||||
* @return [][string, string] An array of events as hash/value entries.
|
||||
* @memberof module:Database.Database-Events
|
||||
* @memberof module:Databases.Databases-Events
|
||||
* @instance
|
||||
*/
|
||||
const all = async () => {
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
/**
|
||||
* @module Databases
|
||||
* @description
|
||||
* Provides various database structures for storing data.
|
||||
*/
|
||||
import Documents from './documents.js'
|
||||
import Events from './events.js'
|
||||
import KeyValue from './keyvalue.js'
|
||||
import KeyValueIndexed from './keyvalue-indexed.js'
|
||||
|
||||
/**
|
||||
|
||||
* An array of available database types.
|
||||
* @name databaseTypes
|
||||
* @†ype []
|
||||
@@ -28,7 +33,7 @@ const databaseTypes = {
|
||||
* addDatabaseType('customDBType', CustomDBTypeModule)
|
||||
* @function addDatabaseType
|
||||
* @param {string} type The database type.
|
||||
* @param {module:Database} store A Database-compatible module.
|
||||
* @param {module:Databases} store A Database-compatible module.
|
||||
* @memberof module:OrbitDB
|
||||
*/
|
||||
const addDatabaseType = (type, store) => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* @namespace Database-KeyValueIndexed
|
||||
* @memberof module:Database
|
||||
* @namespace Databases-KeyValueIndexed
|
||||
* @memberof module:Databases
|
||||
* @description
|
||||
* KeyValueIndexed database.
|
||||
*
|
||||
@@ -46,7 +46,7 @@ const valueEncoding = 'json'
|
||||
* @function
|
||||
* @instance
|
||||
* @async
|
||||
* @memberof module:Database.Database-KeyValueIndexed
|
||||
* @memberof module:Databases.Databases-KeyValueIndexed
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -54,9 +54,9 @@ const valueEncoding = 'json'
|
||||
* @param {Object} options Various options for configuring the KeyValueIndexed
|
||||
* store.
|
||||
* @param {module:Storage} [storage=LevelStorage] A compatible storage.
|
||||
* @return {module:Database.Database-KeyValueIndexed} A KeyValueIndexed
|
||||
* @return {module:Databases.Databases-KeyValueIndexed} A KeyValueIndexed
|
||||
* function.
|
||||
* @memberof module:Database
|
||||
* @memberof module:Databases
|
||||
*/
|
||||
const KeyValueIndexed = ({ storage } = {}) => async ({ ipfs, identity, address, name, access, directory, meta, headsStorage, entryStorage, indexStorage, referencesCount, syncAutomatically, onUpdate }) => {
|
||||
const indexDirectory = pathJoin(directory || './orbitdb', `./${address}/_index/`)
|
||||
@@ -94,7 +94,7 @@ const KeyValueIndexed = ({ storage } = {}) => async ({ ipfs, identity, address,
|
||||
* @function
|
||||
* @param {string} key The key of the value to get.
|
||||
* @return {*} The value corresponding to key or null.
|
||||
* @memberof module:Database.Database-KeyValueIndexed
|
||||
* @memberof module:Databases.Databases-KeyValueIndexed
|
||||
* @instance
|
||||
*/
|
||||
const get = async (key) => {
|
||||
@@ -111,7 +111,7 @@ const KeyValueIndexed = ({ storage } = {}) => async ({ ipfs, identity, address,
|
||||
* @param {Object} [filters={}] Various filters to apply to the iterator.
|
||||
* @param {string} [filters.amount=-1] The number of results to fetch.
|
||||
* @yields [string, string, string] The next key/value as key/value/hash.
|
||||
* @memberof module:Database.Database-KeyValueIndexed
|
||||
* @memberof module:Databases.Databases-KeyValueIndexed
|
||||
* @instance
|
||||
*/
|
||||
const iterator = async function * ({ amount } = {}) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* @namespace Database-KeyValue
|
||||
* @memberof module:Database
|
||||
* @namespace Databases-KeyValue
|
||||
* @memberof module:Databases
|
||||
* @description KeyValue database.
|
||||
*/
|
||||
import Database from '../database.js'
|
||||
@@ -32,13 +32,13 @@ import Database from '../database.js'
|
||||
* @function
|
||||
* @instance
|
||||
* @async
|
||||
* @memberof module:Database.Database-KeyValue
|
||||
* @memberof module:Databases.Databases-KeyValue
|
||||
*/
|
||||
|
||||
/**
|
||||
* Defines an KeyValue database.
|
||||
* @return {module:Database.Database-KeyValue} A KeyValue function.
|
||||
* @memberof module:Database
|
||||
* @return {module:Databases.Databases-KeyValue} A KeyValue function.
|
||||
* @memberof module:Databases
|
||||
*/
|
||||
const KeyValue = () => async ({ ipfs, identity, address, name, access, directory, meta, headsStorage, entryStorage, indexStorage, referencesCount, syncAutomatically, onUpdate }) => {
|
||||
const database = await Database({ ipfs, identity, address, name, access, directory, meta, headsStorage, entryStorage, indexStorage, referencesCount, syncAutomatically, onUpdate })
|
||||
@@ -51,7 +51,7 @@ const KeyValue = () => async ({ ipfs, identity, address, name, access, directory
|
||||
* @param {string} key The key to store.
|
||||
* @param {*} value The value to store.
|
||||
* @return {string} The hash of the new oplog entry.
|
||||
* @memberof module:Database.Database-KeyValue
|
||||
* @memberof module:Databases.Databases-KeyValue
|
||||
* @instance
|
||||
*/
|
||||
const put = async (key, value) => {
|
||||
@@ -62,7 +62,7 @@ const KeyValue = () => async ({ ipfs, identity, address, name, access, directory
|
||||
* Deletes a key/value pair from the store.
|
||||
* @function
|
||||
* @param {string} key The key of the key/value pair to delete.
|
||||
* @memberof module:Database.Database-KeyValue
|
||||
* @memberof module:Databases.Databases-KeyValue
|
||||
* @instance
|
||||
*/
|
||||
const del = async (key) => {
|
||||
@@ -74,7 +74,7 @@ const KeyValue = () => async ({ ipfs, identity, address, name, access, directory
|
||||
* @function
|
||||
* @param {string} key The key of the value to get.
|
||||
* @return {*} The value corresponding to key or null.
|
||||
* @memberof module:Database.Database-KeyValue
|
||||
* @memberof module:Databases.Databases-KeyValue
|
||||
* @instance
|
||||
*/
|
||||
const get = async (key) => {
|
||||
@@ -94,7 +94,7 @@ const KeyValue = () => async ({ ipfs, identity, address, name, access, directory
|
||||
* @param {Object} [filters={}] Various filters to apply to the iterator.
|
||||
* @param {string} [filters.amount=-1] The number of results to fetch.
|
||||
* @yields [string, string, string] The next key/value as key/value/hash.
|
||||
* @memberof module:Database.Database-KeyValue
|
||||
* @memberof module:Databases.Databases-KeyValue
|
||||
* @instance
|
||||
*/
|
||||
const iterator = async function * ({ amount } = {}) {
|
||||
@@ -121,7 +121,7 @@ const KeyValue = () => async ({ ipfs, identity, address, name, access, directory
|
||||
* @function
|
||||
* @return [][string, string, string] An array of key/value pairs as
|
||||
* key/value/hash entries.
|
||||
* @memberof module:Database.Database-KeyValue
|
||||
* @memberof module:Databases.Databases-KeyValue
|
||||
* @instance
|
||||
*/
|
||||
const all = async () => {
|
||||
|
||||
Reference in New Issue
Block a user