CocodaSDK

CocodaSDK class

Constructor

new CocodaSDK(configopt)

CDK constructor.

Parameters:
NameTypeAttributesDefaultDescription
configObject<optional>
{}

Cocoda-stye config object

Members

config

Current configuration.

providers

Map of registered providers.

Methods

addProvider(provider)

Method to add custom provider.

Parameters:
NameTypeDescription
providerObject

provider class that extends BaseProvider

createInstance(config) → {CocodaSDK}

Creates a new CDK instance (same as new CocodaSDK(config)).

Parameters:
NameTypeDescription
configObject

Cocoda config object

Returns:

new CDK instance

Type: 
CocodaSDK

getRegistryForUri(uri) → (nullable) {Object}

Method to get a registry by URI.

Parameters:
NameTypeDescription
uristring

URI of registry in config

Returns:

initialized registry from config if found

Type: 
Object

(async) getSchemes(configopt) → {Array.<Object>}

Gets schemes from all registries that support schemes and merges the results.

Parameters:
NameTypeAttributesDefaultDescription
configObject<optional>
{}

configuration object that will be used as a parameter for internal getSchemes calls

Returns:

array of JSKOS schemes

Type: 
Array.<Object>

initializeRegistry(registry) → {Object}

Method to initialize registry.

Parameters:
NameTypeDescription
registryObject

JSKOS registry object

Returns:

initialized registry

Type: 
Object

loadBuildInfo(config) → {Object}

Method to load buildInfo.

Callback will only be called if buildInfo changes; it will not be called when there is no previous value.

Parameters:
NameTypeDescription
configObject
Properties
NameTypeAttributesDefaultDescription
urlstring<optional>

full URL for build-info.json (default is taken from config.cocodaBaseUrl)

buildInfoObject<optional>

current buildInfo

intervalnumber<optional>
60000

interval to load buildInfo in ms

callbackfunction

callback function called with two parameters (error, buildInfo, previousBuildInfo)

Returns:

object with two function properties, stop to cancel the repeating request, start to restart the repeating request, as well as three convenience properties, isPaused (whether it is currently paused), lastResult, hasErrored (whether the last call of the function has errored)

Type: 
Object

(async) loadConfig(url)

Offer method to load a config file from URL.

Parameters:
NameTypeDescription
urlstring

URL of config as JSON

registryForScheme(scheme, dataTypeopt) → {Object|null}

Parameters:
NameTypeAttributesDefaultDescription
schemeObject

JSKOS concept scheme object

dataTypestring<optional>
"concepts"

only use providers that support a certain data type (default is "concepts" for backward compatibility)

Returns:

registry object, or null if determining the registry was not successful

Type: 
Object | null

repeat(config) → {Object}

Repeatedly call a certain function.

Notes:

  • Callback will only be called if the results were changed.
  • The function will only be repeated after the previous call is resolved. This means that the total interval duration is (interval + duration of function call).

Example:

 cdk.repeat({
   function: () => registry.getMappings(),
   callback: (error, result) => console.log(result),
 })
Parameters:
NameTypeDescription
configObject
Properties
NameTypeAttributesDefaultDescription
functionstring

a function to be called (can be async)

intervalnumber<optional>
15000

interval in ms

callbackfunction

callback function called with two parameters (error, result, previousResult)

callImmediatelyboolean<optional>
true

whether to call the function immediately

Returns:

object with two function properties, stop to cancel the repeating request, start to restart the repeating request, as well as three convenience properties, isPaused (whether it is currently paused), lastResult, hasErrored (whether the last call of the function has errored)

Type: 
Object

setConfig(config)

Method to set the configuration.

Parameters:
NameTypeDescription
configObject

Cocoda-stye config object

(static) addProvider(provider)

Static method to add custom provider.

Parameters:
NameTypeDescription
providerObject

provider class that extends BaseProvider