From 24a2e1ae5f5bd52efc621b472a679733bea47b83 Mon Sep 17 00:00:00 2001 From: Hayden Young Date: Sat, 24 Jun 2023 16:11:21 +0100 Subject: [PATCH] docs: Change namespace from database to databases. --- src/database.js | 35 ++++++++--------------------------- src/db/documents.js | 22 +++++++++++----------- src/db/events.js | 18 +++++++++--------- src/db/index.js | 9 +++++++-- src/db/keyvalue-indexed.js | 14 +++++++------- src/db/keyvalue.js | 20 ++++++++++---------- 6 files changed, 52 insertions(+), 66 deletions(-) diff --git a/src/database.js b/src/database.js index a01b6ed..2dc0000 100644 --- a/src/database.js +++ b/src/database.js @@ -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 { diff --git a/src/db/documents.js b/src/db/documents.js index 99be777..89fdb15 100644 --- a/src/db/documents.js +++ b/src/db/documents.js @@ -1,6 +1,6 @@ /** - * @namespace Database-Documents - * @memberof module:Database + * @namespace Databases-Documents + * @memberof module:Databases * @description Documents database. * @example Create documents db with default options * 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 () => { diff --git a/src/db/events.js b/src/db/events.js index 6f42fd9..ea862e7 100644 --- a/src/db/events.js +++ b/src/db/events.js @@ -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 () => { diff --git a/src/db/index.js b/src/db/index.js index 187a4a5..df80138 100644 --- a/src/db/index.js +++ b/src/db/index.js @@ -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) => { diff --git a/src/db/keyvalue-indexed.js b/src/db/keyvalue-indexed.js index d80041b..31d2dcc 100644 --- a/src/db/keyvalue-indexed.js +++ b/src/db/keyvalue-indexed.js @@ -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 } = {}) { diff --git a/src/db/keyvalue.js b/src/db/keyvalue.js index ba356fd..208a143 100644 --- a/src/db/keyvalue.js +++ b/src/db/keyvalue.js @@ -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 () => {