mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-05-30 18:56:36 +00:00
docs: type is required.
This commit is contained in:
parent
4c3a338205
commit
7fafda8416
@ -1,21 +1,30 @@
|
||||
/**
|
||||
* @module AccessControllers
|
||||
* @description
|
||||
* Provides a platform for managing access controllers. Supported access
|
||||
* Provides a system for managing access controllers. Supported access
|
||||
* controllers can be added and removed from the access controller list, and
|
||||
* can load the associated module if they are supported.
|
||||
*
|
||||
* An AccessController module needs to only expose one function,
|
||||
* canAppend(entry) which returns true if the entry can be appended to the
|
||||
* oplog, or false otherwise:
|
||||
* ```javascript
|
||||
* const CustomAccessController = ({ write } = {}) => async => {
|
||||
* An AccessController module needs to only expose one constant, type, and one function, canAppend(entry), which returns true if the entry can be appended to
|
||||
* the oplog, or false otherwise:
|
||||
* ```js
|
||||
* type = 'custom'
|
||||
*
|
||||
* const CustomAccessController = ({ write } = {}) => async ({ orbitdb, identities, address }) => {
|
||||
* const canAppend = async (entry) => {
|
||||
* // Use entry.identity to determine whether the entry can be appended.
|
||||
* // Return true if entry can be appended to OpLog.
|
||||
* // Or return false otherwise.
|
||||
* }
|
||||
*
|
||||
* return {
|
||||
* canAppend,
|
||||
* type
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* export default CustomAccessController
|
||||
* ```
|
||||
*/
|
||||
import IPFSAccessController from './ipfs.js'
|
||||
import OrbitDBAccessController from './orbitdb.js'
|
||||
@ -37,7 +46,7 @@ const accessControllers = {
|
||||
* @return {AccessController} The access controller module.
|
||||
*/
|
||||
const getAccessController = (type) => {
|
||||
if (!Object.keys(accessControllers).includes(type)) {
|
||||
if (!accessControllers[type]) {
|
||||
throw new Error(`AccessController type '${type}' is not supported`)
|
||||
}
|
||||
return accessControllers[type]
|
||||
@ -53,12 +62,12 @@ const getAccessController = (type) => {
|
||||
* controller module does not implement a type property.
|
||||
*/
|
||||
const addAccessController = (accessController) => {
|
||||
if (accessControllers[accessController.type]) {
|
||||
throw new Error(`Access controller '${accessController.type}' already added.`)
|
||||
if (!accessController.type) {
|
||||
throw new Error('Access controller does not contain required field \'type\'')
|
||||
}
|
||||
|
||||
if (!accessController.type) {
|
||||
throw new Error('Given AccessController class needs to implement: type.')
|
||||
if (accessControllers[accessController.type]) {
|
||||
throw new Error(`Access controller '${accessController.type}' already added.`)
|
||||
}
|
||||
|
||||
accessControllers[accessController.type] = accessController
|
||||
|
Loading…
x
Reference in New Issue
Block a user