{"_id":"@beliven/rb-core-module","name":"@beliven/rb-core-module","dist-tags":{"latest":"0.32.1"},"versions":{"0.32.1":{"name":"@beliven/rb-core-module","version":"0.32.1","description":"The Restboard core module","main":"src/index.js","type":"module","scripts":{"test":"tap --disable-coverage --allow-empty-coverage"},"repository":{"type":"git","url":"git+https://github.com/beliven-it/rb-core-module.git"},"keywords":["restboard","core","resources"],"author":{"name":"Emanuele Bertoldi","email":"emanuele.bertoldi@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/beliven-it/rb-core-module/issues"},"homepage":"https://github.com/beliven-it/rb-core-module#readme","dependencies":{"humanize-string":"^3.0.0"},"devDependencies":{"eslint":"^8.48.0","tap":"^18.6.1"},"publishConfig":{"access":"public"},"_id":"@beliven/rb-core-module@0.32.1","gitHead":"3e99d8cafa0d167e97f64774630959d0733a5fe5","_nodeVersion":"20.19.0","_npmVersion":"10.8.2","dist":{"integrity":"sha512-s/8XVnYiVvQXhZJoSWWOlyYYAwRFOEolHccwDght8B39iBcerXXH6Wum/U2nEsuMuvkpaxjYPzSpmkSJCvzFwg==","shasum":"4a07012312784c556ddd89ed72c824c9d41fb094","tarball":"https://registry.npmjs.org/@beliven/rb-core-module/-/rb-core-module-0.32.1.tgz","fileCount":18,"unpackedSize":56010,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIGV8+guXQtIGHQ1/GI3V2oZNd1H7Qfs1pidy5Ee3JXWqAiEA/ISYTJMFmgQAoeoIQOcE2H3gQMRqyhAx5JsI8gMbFmo="}]},"_npmUser":{"name":"beliven.dev","email":"dev@beliven.com"},"directories":{},"maintainers":[{"name":"beliven.dev","email":"dev@beliven.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/rb-core-module_0.32.1_1744183514300_0.1735138969628549"},"_hasShrinkwrap":false}},"time":{"created":"2025-04-09T07:25:14.201Z","0.32.1":"2025-04-09T07:25:14.509Z","modified":"2025-04-09T07:25:14.818Z"},"maintainers":[{"name":"beliven.dev","email":"dev@beliven.com"}],"description":"The Restboard core module","homepage":"https://github.com/beliven-it/rb-core-module#readme","keywords":["restboard","core","resources"],"repository":{"type":"git","url":"git+https://github.com/beliven-it/rb-core-module.git"},"author":{"name":"Emanuele Bertoldi","email":"emanuele.bertoldi@gmail.com"},"bugs":{"url":"https://github.com/beliven-it/rb-core-module/issues"},"license":"MIT","readme":"# rb-core-module\n\nThe [Restboard](https://restboard.github.io/) core module\n\n[![Node.js CI](https://github.com/beliven-it/rb-core-module/actions/workflows/node.js.yml/badge.svg)](https://github.com/beliven-it/rb-core-module/actions/workflows/node.js.yml)\n\n## Getting started\n\nFirst of all, you need to install the package in your project:\n\n```bash\nnpm i --save @beliven/rb-core-module\n```\n\nNow, you can start to define and use your [resources](#RbResource):\n\n```js\nimport { createResource } from '@beliven/rb-core-module'\n\n// Create a new resource\nconst users = createResource({\n  name: 'users',\n  provider: ..., // The data provider used to query the API\n  ...\n})\n\n// Resources can then be used to interact with the remote API:\nconst me = await users.getOne(1)\n```\n\n## RbResource\n\n`RbResource` is a base class used to implement a proxy to interact with a remote API resource.\n\n### Options\n\n| Name            | Description | Default |\n| --------------- | ----------- | ------- |\n| `name`          | The unique resource name (e.g. `users`) ||\n| `provider`      | The data provider used to interact with the API ||\n| `key`           | The identifier attribute name | `id` |\n| `path`          | The resource base path (if different than `name`) | `name` |\n| `label`         | A human-readable description label for the resource | capitalized `name` |\n| `displayAttr`   | The attr used as representation of a single resource instance | `key` |\n| `stringify`     | A function used to get a human-readable reperesentation of a single resource instance | `instance => instance[resource.displayAttr]` |\n| `schema`        | The JSON schema representing the strcuture of resource instances | `undefined` |\n| `updateSchema`  | The JSON schema used on update | `schema` |\n| `createSchema`  | The JSON schema used on creation | `schema` |\n| `defaultParams` | Default params passed to the data provider when fetching the API (e.g. default filters) | `{}` |\n| `isKeyEditable` | If `true`, allows editing the `key` of an instance | `false` |\n| `actions`       | A map of actions executable on a single resource instance | `{}` |\n| `listeners`     | A list of callbacks to be called when the resource is marked as dirty | `[]` |\n| `methods`       | A dictionary of extra methods to extend the default resource API | `{}` |\n| `ui`            | An 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 | `{}` |\n\n### Methods\n\n| Signature                      | Description |\n| ------------------------------ | ----------- |\n| `getKey(instance)`             | Retrieve the primary key of the given resource `instance` |\n| `stringify(instance)`          | Render a string representation of the given resource `instance` |\n| `getOne(key, params)`          | Retrieve a single resource instance, identified by `key` and (optional) `params` |\n| `getMany(params)`              | Retrieve a list of resource instances according to the given (optional) `params` |\n| `createOne(data, params)`      | Insert a single resource instance with the given `data` and identified by (optional) `params` |\n| `updateOne(key, data, params)` | Update a single resource instance, identified by `key` and (optional) `params`, with the given `data` |\n| `updateMany(data, params)`     | Update multiple resource instances according to `data` and (optional) `params` |\n| `deleteOne(key, params)`       | Delete a single resource instance identified by `key` and (optional) `params` |\n| `deleteMany(keys, params)`     | Delete multiple resource instances identified by the `keys` array and (optional) `params` |\n| `getRelation(key, name, opts)` | Return the related resource identified by `name`, scoped to the instance identified by `key`. For `opts` see **Relation options** |\n| `getActions()`                 | Return a dictionary of resource actions, where each action is bound to the resource |\n| `setDirty()`                   | Set the resource `lastUpdate` with the current timestamp and notify registered listeners |\n| `addListener(callback)`        | Register a new listener callback |\n| `removeListener(callback)`     | Unregister a previously registered listener callback |\n| `mergeParams(params)`          | Merge given `params` with resource default ones |\n\n### Relation options\n\n| Name                  | Description                                                | Default |\n| --------------------- | ---------------------------------------------------------- | ------- |\n| `notifyParentOnDirty` | If `true` mark also the parent resource as dirty on change | `true`  |\n\n## RbDataProvider\n\n`RbDataProvider` is a generic interface used by resources to interact with a\nthird-party API using the correct protocol and dialect.\n\n### Methods\n\n| Signature                                    | Description                   |\n| -------------------------------------------- | ----------------------------- |\n| `getOne(resourcePath, key, params)`          | See [RbResource](#RbResource) |\n| `getMany(resourcePath, params)`              | See [RbResource](#RbResource) |\n| `createOne(resourcePath, data, params)`      | See [RbResource](#RbResource) |\n| `updateOne(resourcePath, key, data, params)` | See [RbResource](#RbResource) |\n| `updateMany(resourcePath, data, params)`     | See [RbResource](#RbResource) |\n| `deleteOne(resourcePath, key, params)`       | See [RbResource](#RbResource) |\n| `deleteMany(resourcePath, keys, params)`     | See [RbResource](#RbResource) |\n\n## RbAuthProvider\n\n`RbAuthProvider` is a generic interface used to perform authentication and\nauthorization over a third-party API, abstracting the details of underlying\nstrategies.\n\n### Methods\n\n| Signature                             | Description |\n| ------------------------------------- | ----------- |\n| `login(credentials)`                  | Attempt to log the user identified by the given `credentials` |\n| `logout()`                            | Terminate the current authenticated session |\n| `recoverCredentials(challenge)`       | Attempt to recover user credentials providing a valid `challenge` response |\n| `activateOrResetCredentials(payload)` | Activate or reset existing user credentials |\n| `checkAuth()`                         | Check if the current authenticated session is still valid |\n| `getIdentity(user)`                   | Given a `user`, retrieve its textual representation |\n| `getTenantIdentity(user)`             | Given a `user`, retireve its tenant identity |\n| `can(user, action, subject)`          | Check if the given `user` can perform `action` on the `subject` |\n\n## Development\n\n```bash\n# Install dependencies\nnpm install\n\n# Run tests\nnpm test\n```\n\n## Contribute\n\nIf you want, you can also freely donate to fund the project development:\n\n[![Donate](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://paypal.me/EBertoldi)\n\n## Have you found a bug?\n\nPlease open a new issue on:\n\n<https://github.com/beliven-it/rb-core-module/issues>\n\n## License\n\nCopyright (c) Emanuele Bertoldi\n\n[MIT License](http://en.wikipedia.org/wiki/MIT_License)\n","readmeFilename":"README.md","_rev":"1-465c0fd0cc214be5e16a3fad3004e2c5"}