BaseProvider

BaseProvider to be subclassed to implement specific providers. Do not initialize a registry directly with this!

Prefix all internal method and properties with underscore (e.g. this._cache)!

Static members that should be set:

  • providerName (This is how a provider is identified in a "registry" object in field provider.)
  • providerType (Optional BARTOC API type URI. Supported types: https://github.com/gbv/bartoc.org/blob/main/data/bartoc-api-types.concepts.csv, the URI prefix is "http://bartoc.org/api-type/".)
  • supports (Optional object of supported capabilities. The keys should be values from this list: https://github.com/gbv/cocoda-sdk/blob/9145952398d6828004beb395c1d392a4d24e9288/src/utils/index.js#L159-L174; values should be a boolean. false values can be left out. They will be used to initialize this.has (see below). Alternatively, this.has can be filled in _prepare or _setup.)

Methods that can be overridden:

  • Do not override the constructor! Use _prepare or _setup instead.
  • _prepare: will be called before the registry is initialized (i.e. it's /status endpoint is queries if necessasry)
  • _setup: will be called after registry is initialized (i.e. it's /status endpoint is queries if necessasry), should be used to set properties on this.has and custom preparations
  • isAuthorizedFor: override if you want to customize
  • supportsScheme: override if you want to customize
  • getRegistries
  • getSchemes
  • getTypes
  • suggest
  • getConcordances
  • getOccurrences
  • getTop
  • getConcepts
  • getNarrower
  • getAncestors
  • search
  • getMapping
  • getMappings
  • postMapping
  • postMappings
  • putMapping
  • patchMapping
  • deleteMapping
  • deleteMappings
  • getAnnotations
  • postAnnotation
  • putAnnotation
  • patchAnnotation
  • deleteAnnotation

Internal (starting with underscore) and external properties that can be used:

  • this.cdk: a reference to the current CDK instance (can be use to request other registries or initialize a new registry)
  • this.has: an object of functionality of the registry (needs to be set by subclasses)
  • this.languages: an array of language tags provided by the user in order of priority
  • this._jskos: the raw JSKOS object used to initialize this registry
  • this._path: if available, the path of the current browser window
  • this._defaultLanguages: an array of default language tags
  • this._auth: authentication key and token
  • this._api: object of API endpoints for the registry
  • this._config: configuration of the registry as provided by the /status endpoint if available

All of the request methods take ONE parameter which is a config object. Actual parameters should be properties on this object. The config object should be destructured to remove the properties your method needs, and the remaining config object should be given to the axios request. Example:

 getConcept({ concept, ...config }) {
   return this.axios({
     ...config,
     method: "get",
     params: {
       uri: concept.uri,
     },
   })
 }

Always use this.axios like in the example for http requests!

Constructor

new BaseProvider(registry)

Provider constructor.

Parameters:
NameTypeDescription
registryObject

the registry for this provider

Members

(readonly) has :Object

A dictionary with functionality of the registry (e.g. registry.has.schemes).

Type:
  • Object

languages :Array.<string>

A list of RFC 3066 language tags in lowercase in order of priority.

Type:
  • Array.<string>

Methods

(async) deleteMappings(config) → {Array.<Object>}

DELETEs multiple mappings. Do not override in subclass!

Parameters:
NameTypeDescription
configObject
Properties
NameTypeDescription
mappingsArray

array of mapping objects

Returns:

array of results (true if successful); in case of failure, consult the _errors property on the array at the index of the failed request

Type: 
Array.<Object>

getCancelTokenSource() → {Object}

Returns a source for a axios cancel token.

Returns:

axios cancel token source

Type: 
Object

(async) init() → {Promise}

Load data about registry via the status endpoint.

Returns:

Promise that resolves when initialization is complete.

Type: 
Promise

isAuthorizedFor(options) → {boolean}

Returns whether a user is authorized for a certain request.

Parameters:
NameTypeDescription
optionsObject
Properties
NameTypeAttributesDescription
typestring

type of item (e.g. mappings)

actionstring

action to be performed (read/create/update/delete)

userObject

user object

crossUserboolean<optional>

whether the request is a crossUser request (i.e. updading/deleting another user's item)

Returns:
Type: 
boolean

(async) postMappings(config) → {Array.<Object>}

POSTs multiple mappings. Do not override in subclass!

Parameters:
NameTypeDescription
configObject
Properties
NameTypeDescription
mappingsArray

array of mapping objects

Returns:

array of created mapping objects; in case of failure, consult the _errors property on the array at the index of the failed request

Type: 
Array.<Object>

setAuth(options)

Sets authentication credentials.

Parameters:
NameTypeDescription
optionsObject
Properties
NameTypeDescription
keystring

public key of login-server instance the user is authorized for

bearerTokenstring

token that is sent with each request

setRetryConfig(config)

Sets retry configuration.

Parameters:
NameTypeDescription
configObject
Properties
NameTypeAttributesDefaultDescription
methodsArray.<string><optional>
["get", "head", "options"]

HTTP methods to retry (lowercase)

statusCodesArray.<number><optional>
[401, 403]

status codes to retry

countnumber<optional>
3

maximum number of retries

delaynumber | function<optional>
300*count

a delay in ms or a function that takes the number of current retries and returns a delay in ms

supportsScheme(scheme) → {boolean}

Returns a boolean whether a certain target scheme is supported or not.

Parameters:
NameTypeDescription
schemeObject
Returns:
Type: 
boolean