{"id":16350338,"url":"https://github.com/niksy/jsonapi-data-manager","last_synced_at":"2025-08-22T23:06:32.200Z","repository":{"id":57285617,"uuid":"90860645","full_name":"niksy/jsonapi-data-manager","owner":"niksy","description":"Handle JSON API data.","archived":false,"fork":false,"pushed_at":"2024-05-10T06:56:15.000Z","size":204,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-11T06:42:02.965Z","etag":null,"topics":["json-api","jsonapi"],"latest_commit_sha":null,"homepage":"https://niksy.github.io/jsonapi-data-manager/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"beauby/jsonapi-datastore","license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/niksy.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-05-10T12:16:29.000Z","updated_at":"2024-05-10T06:56:19.000Z","dependencies_parsed_at":null,"dependency_job_id":"524e1c26-553d-43f5-8e3f-8cc0826ecb97","html_url":"https://github.com/niksy/jsonapi-data-manager","commit_stats":{"total_commits":83,"total_committers":11,"mean_commits":7.545454545454546,"dds":"0.45783132530120485","last_synced_commit":"af702cdcbd58bfbc5b0e100394e6fa4e8985f732"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niksy%2Fjsonapi-data-manager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niksy%2Fjsonapi-data-manager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niksy%2Fjsonapi-data-manager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niksy%2Fjsonapi-data-manager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/niksy","download_url":"https://codeload.github.com/niksy/jsonapi-data-manager/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234444578,"owners_count":18833657,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["json-api","jsonapi"],"created_at":"2024-10-11T01:03:20.899Z","updated_at":"2025-01-17T23:49:37.737Z","avatar_url":"https://github.com/niksy.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jsonapi-data-manager\n\n[![Build Status][ci-img]][ci] [![BrowserStack Status][browserstack-img]][browserstack]\n\nHandle [JSON API][jsonapi] data.\n\n⚠️ **Based on [`jsonapi-data-store`](https://github.com/beauby/jsonapi-datastore) module which is\ncurrently unmaintained.**\n\nThe [JSON API][jsonapi] standard is great for exchanging data (which is its purpose), but the format\nis not ideal to work directly with in an application. This module is framework-agnostic library that\ntakes away the burden of handling [JSON API][jsonapi] data on the client side.\n\nWhat it does:\n\n-   Read JSON API payloads\n-   Rebuild the underlying data graph\n-   Allows you to query models and access their relationships directly\n-   Create new models\n-   Serialize models for creation/update\n\nWhat it does not do:\n\n-   Make requests to your API. You design your endpoints URLs, the way you handle authentication,\n    caching, etc. is totally up to you.\n\n## Install\n\n```sh\nnpm install jsonapi-data-manager --save\n```\n\n## Usage\n\n[**Full documentation**](https://niksy.github.io/jsonapi-data-manager/)\n\n`Store` and `Model` classes are available as named exports.\n\n```js\nimport { Store, Model } from 'jsonapi-data-manager';\n```\n\n### Parsing data\n\nCall the `.sync()` method of your store.\n\n```js\nconst store = new Store();\nstore.sync(data);\n```\n\nThis parses the data and incorporates it in the store, taking care of already existing records (by\nupdating them) and relationships.\n\nTop level data in your payload (e.g. `meta`) are stored directly on store.\n\n### Retrieving models\n\nCall the `.find(type, id)` method of your store.\n\n```js\nconst article = store.find('article', '123');\n```\n\nor call the `.findAll(type)` method of your store to get all the models of that type.\n\n```js\nconst articles = store.findAll('article');\n```\n\nAll the attributes _and_ relationships are accessible through the model as object properties.\n\n```js\narticle.author.name;\n```\n\nIn case a related resource has not been fetched yet (either as a primary resource or as an included\nresource), the corresponding property on the model will contain only the `type` and `id`. However,\nthe models are _updated in place_, so you can fetch a related resource later, and your data will\nremain consistent.\n\n### Serializing data\n\nCall the `.serialize()` method on the model.\n\n```js\narticle.serialize();\n```\n\n### Examples\n\n```js\nimport { Store } from 'jsonapi-data-manager';\n\n// Create a store:\nconst store = new Store();\n\n// Then, given the following payload, containing two `articles`, with a related `user` who is the author of both:\nconst payload = {\n\tdata: [\n\t\t{\n\t\t\ttype: 'article',\n\t\t\tid: '1337',\n\t\t\tattributes: {\n\t\t\t\ttitle: 'Cool article'\n\t\t\t},\n\t\t\trelationships: {\n\t\t\t\tauthor: {\n\t\t\t\t\tdata: {\n\t\t\t\t\t\ttype: 'user',\n\t\t\t\t\t\tid: '1'\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\ttype: 'article',\n\t\t\tid: '300',\n\t\t\tattributes: {\n\t\t\t\ttitle: 'Even cooler article'\n\t\t\t},\n\t\t\trelationships: {\n\t\t\t\tauthor: {\n\t\t\t\t\tdata: {\n\t\t\t\t\t\ttype: 'user',\n\t\t\t\t\t\tid: '1'\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t]\n};\n\n// We can sync it:\nstore.sync(payload);\n\n// We can retrieve list of synced articles:\nconst articles = store.findAll('article');\n\n// Later, we can retrieve one of those:\nconst article = store.find('article', '1337');\n\n// If the author resource has not been synced yet, we can only access its id and its type:\narticle.author;\n// { id: 1, type: 'article' }\n\n// If we do sync the author resource later:\nconst authorPayload = {\n\tdata: {\n\t\ttype: 'user',\n\t\tid: '1',\n\t\tattributes: {\n\t\t\tname: 'Lucas'\n\t\t}\n\t}\n};\n\nstore.sync(authorPayload);\n\n// We can then access the author's name through our old `article` reference:\narticle.author.name;\n// 'Lucas'\n\n// We can also serialize any whole model in a JSONAPI-compliant way:\narticle.serialize();\n\n// Or just a subset of its attributes/relationships:\narticle.serialize({ attributes: ['title'], relationships: [] });\n```\n\n## Browser support\n\nTested in IE11+ and all modern browsers.\n\n## Test\n\nFor automated tests, run `npm test` (append `:watch` for watcher support).\n\n## License\n\nMIT © [Ivan Nikolić](http://ivannikolic.com)\n\n\u003c!-- prettier-ignore-start --\u003e\n\n[ci]: https://github.com/niksy/jsonapi-data-manager/actions?query=workflow%3ACI\n[ci-img]: https://github.com/niksy/jsonapi-data-manager/actions/workflows/ci.yml/badge.svg?branch=master\n[browserstack]: https://www.browserstack.com/\n[browserstack-img]: https://www.browserstack.com/automate/badge.svg?badge_key=eDV0YitYd2FNR2FNamNDT0tuaGl0QmI3dFNwMkVVcVJUdmtVZ0lCZ0FlYz0tLTZQWUEvdERLS21tRmV3MWRJN0xWQUE9PQ==--465652cfc13a0b91e1905e1f65b6f11d791a9041\n[jsonapi]: https://jsonapi.org/\n\n\u003c!-- prettier-ignore-end --\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fniksy%2Fjsonapi-data-manager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fniksy%2Fjsonapi-data-manager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fniksy%2Fjsonapi-data-manager/lists"}