0.31.1 • Published 4 months ago

rb-core-module v0.31.1

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

rb-core-module

The Restboard core module

Node.js CI

Getting started

First of all, you need to install the package in your project:

npm i --save rb-core-module

Now, you can start to define and use your resources:

import { createResource } from 'rb-core-module'

// Create a new resource
const users = createResource({
  name: 'users',
  provider: ..., // The data provider used to query the API
  ...
})

// Resources can then be used to interact with the remote API:
const me = await users.getOne(1)

RbResource

RbResource is a base class used to implement a proxy to interact with a remote API resource.

Options

NameDescriptionDefault
nameThe unique resource name (e.g. users)
providerThe data provider used to interact with the API
keyThe identifier attribute nameid
pathThe resource base path (if different than name)name
labelA human-readable description label for the resourcecapitalized name
displayAttrThe attr used as representation of a single resource instancekey
stringifyA function used to get a human-readable reperesentation of a single resource instanceinstance => instance[resource.displayAttr]
schemaThe JSON schema representing the strcuture of resource instancesundefined
updateSchemaThe JSON schema used on updateschema
createSchemaThe JSON schema used on creationschema
defaultParamsDefault params passed to the data provider when fetching the API (e.g. default filters){}
isKeyEditableIf true, allows editing the key of an instancefalse
actionsA map of actions executable on a single resource instance{}
listenersA list of callbacks to be called when the resource is marked as dirty[]
methodsA dictionary of extra methods to extend the default resource API{}
uiAn object containing UI-specific options and methods. A special formComponent key will be used to assign default form components for creation (ui.createFormComponent) and update (ui.updateFormComponent) if none are specified{}

Methods

SignatureDescription
getKey(instance)Retrieve the primary key of the given resource instance
stringify(instance)Render a string representantion of the given resource instance
getMany(params)Retrieve a list of resource instances according to the given params
getOne(key, params)Retrieve a single resource instance, identified by key and params
updateOne(key, data, params)Update a single resource instance, identified by key and params, with the given data
updateMany(data, params)Update multiple resource instances according to data and params
deleteOne(key, params)Delete a single resource instance identified by key and params
deleteMany(keys, params)Delete multiple resource instances identified by the keys array and params
getRelation(key, name, opts)Return the related resource identified by name, scoped to the instance identified by key. For opts see Relation options
getActions()Return a dictionary of resource actions, where each action is bound to the resource
setDirty()Set the resource lastUpdate with the current timestamp and notify registered listeners
addListener(callback)Register a new listener callback
removeListener(callback)Unregister a previously registered listener callback
mergeParams(params)Merge given params with resource default ones

Relation options

NameDescriptionDefault
notifyParentOnDirtyIf true mark also the parent resource as dirtytrue

RbDataProvider

RbDataProvider is a generic interface used by resources to interact with a third-party API using the correct protocol and dialect.

Methods

SignatureDescription
getMany(resourcePath, params)See RbResource
getOne(resourcePath, key, params)See RbResource
updateOne(resourcePath, key, data, params)See RbResource
updateMany(resourcePath, data, params)See RbResource
deleteOne(resourcePath, key, params)See RbResource
deleteMany(resourcePath, keys, params)See RbResource

RbAuthProvider

RbAuthProvider is a generic interface used to perform authentication and authorization over a third-party API, abstracting the details of underlying strategies.

Methods

SignatureDescription
login(credentials)Attempt to log the user identified by the given credentials
logout()Terminate the current authenticated session
checkAuth()Check if the current authenticated session is still valid
getIdentity(user)Given a user, retrieve its textual representation
getTenantIdentity(user)Given a user, retireve its tenant identity
can(user, action, subject)Check if the given user can perform action on the subject

Development

# Install dependencies
npm install

# Run tests
npm test

Contribute

If you want, you can also freely donate to fund the project development:

Donate

Have you found a bug?

Please open a new issue on:

https://github.com/restboard/rb-core-module/issues

License

Copyright (c) Emanuele Bertoldi

MIT License

0.31.1

4 months ago

0.31.0

4 months ago

0.30.0

9 months ago

0.29.0

1 year ago

0.28.1

1 year ago

0.28.0

1 year ago

0.29.1

1 year ago

0.27.0

1 year ago

0.26.1

2 years ago

0.26.0

2 years ago

0.21.0

2 years ago

0.20.0

2 years ago

0.25.0

2 years ago

0.24.0

2 years ago

0.23.1

2 years ago

0.23.0

2 years ago

0.22.0

2 years ago

0.16.0

2 years ago

0.15.1

2 years ago

0.15.0

3 years ago

0.14.0

3 years ago

0.13.0

3 years ago

0.12.0

3 years ago

0.11.0

3 years ago

0.10.0

3 years ago

0.9.0

3 years ago

0.8.0

3 years ago

0.6.0

3 years ago

0.3.0

3 years ago

0.5.0

3 years ago

0.4.0

3 years ago

0.2.1

3 years ago