{"_id":"jsonapi-datastore","_rev":"6-30ce89885a0dc39618d06bbb5f9fa6c7","name":"jsonapi-datastore","description":"JavaScript client-side JSON API data handling made easy.","dist-tags":{"latest":"0.4.0-beta"},"versions":{"0.3.0-beta":{"name":"jsonapi-datastore","version":"0.3.0-beta","description":"JavaScript client-side JSON API data handling made easy.","main":"dist/node-jsonapi-datastore.js","files":["dist/"],"directories":{"test":"test"},"scripts":{"test":"gulp test"},"repository":{"type":"git","url":"git+https://github.com/beauby/jsonapi-datastore.git"},"keywords":["JSON","parsing","serializing","datastore","JSONAPI"],"author":{"name":"Lucas Hosseini","email":"lucas.hosseini@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/beauby/jsonapi-datastore/issues"},"homepage":"https://github.com/beauby/jsonapi-datastore#readme","devDependencies":{"chai":"^3.2.0","gulp":"^3.9.0","gulp-concat":"^2.6.0","gulp-jsbeautify":"^0.1.1","gulp-jscs":"^2.0.0","gulp-jshint":"^1.11.2","gulp-markdox":"^0.1.1","gulp-mocha":"^2.1.3","gulp-rename":"^1.2.2","gulp-uglify":"^1.2.0","gulp-wrap":"^0.11.0","mocha":"^2.2.5"},"gitHead":"0fb81e2cb212789c85cb743d529c9a976afefc01","_id":"jsonapi-datastore@0.3.0-beta","_shasum":"8f7055320468b55598c0cae0288de5e48effa164","_from":".","_npmVersion":"2.11.3","_nodeVersion":"0.12.7","_npmUser":{"name":"beauby","email":"lucas.hosseini@gmail.com"},"dist":{"shasum":"8f7055320468b55598c0cae0288de5e48effa164","tarball":"https://registry.npmjs.org/jsonapi-datastore/-/jsonapi-datastore-0.3.0-beta.tgz","integrity":"sha512-Tgjp1NM9BDmHnAlgX2+F1pRNc6qADhRFAFHCOHDvI+fIJlZZrYFzScOLCYLKu6pSIC0591/eRXdSLpFhUAtbmg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIDh0FbE2ZmmfWs4DgOvBPncudP8eO9ywowEIyI6TV/qYAiEA/+M9anUVuNcAtt0jUDnTulHkuNr0HaPWUbPQiHiSL9M="}]},"maintainers":[{"name":"beauby","email":"lucas.hosseini@gmail.com"}]},"0.3.1-beta":{"name":"jsonapi-datastore","version":"0.3.1-beta","description":"JavaScript client-side JSON API data handling made easy.","main":"dist/node-jsonapi-datastore.js","files":["dist/"],"directories":{"test":"test"},"scripts":{"test":"gulp test"},"repository":{"type":"git","url":"git+https://github.com/beauby/jsonapi-datastore.git"},"keywords":["JSON","parsing","serializing","datastore","JSONAPI"],"author":{"name":"Lucas Hosseini","email":"lucas.hosseini@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/beauby/jsonapi-datastore/issues"},"homepage":"https://github.com/beauby/jsonapi-datastore#readme","devDependencies":{"chai":"^3.2.0","gulp":"^3.9.0","gulp-concat":"^2.6.0","gulp-jsbeautify":"^0.1.1","gulp-jscs":"^2.0.0","gulp-jshint":"^1.11.2","gulp-markdox":"^0.1.1","gulp-mocha":"^2.1.3","gulp-rename":"^1.2.2","gulp-uglify":"^1.2.0","gulp-wrap":"^0.11.0","mocha":"^2.2.5"},"gitHead":"e2bde36a300b99068b39d9ebb776dcf63c7c9fd6","_id":"jsonapi-datastore@0.3.1-beta","_shasum":"b1dee4046f09cda31685a674055378bbb6e1f9f1","_from":".","_npmVersion":"2.13.5","_nodeVersion":"0.12.7","_npmUser":{"name":"beauby","email":"lucas.hosseini@gmail.com"},"dist":{"shasum":"b1dee4046f09cda31685a674055378bbb6e1f9f1","tarball":"https://registry.npmjs.org/jsonapi-datastore/-/jsonapi-datastore-0.3.1-beta.tgz","integrity":"sha512-VTP0lbUmkDVDRK/W92LUlFtSRqEqKUiqQrVt2N9aWMhLfJAhLYsrIXHNZ6ijp83XLe1koWYZcI7LsRh9aOFy7Q==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIEPYfFAMXxqaKI8SRB3B+Gksrnp2a0fZsXyk7AWyoGIzAiBtFMUBvgBHQVywawxaw+s49VMfe6HviR4HpQKv0hfILg=="}]},"maintainers":[{"name":"beauby","email":"lucas.hosseini@gmail.com"}]},"0.3.2-beta":{"name":"jsonapi-datastore","version":"0.3.2-beta","description":"JavaScript client-side JSON API data handling made easy.","main":"dist/node-jsonapi-datastore.js","files":["dist/"],"directories":{"test":"test"},"scripts":{"test":"gulp test"},"repository":{"type":"git","url":"git+https://github.com/beauby/jsonapi-datastore.git"},"keywords":["JSON","parsing","serializing","datastore","JSONAPI"],"author":{"name":"Lucas Hosseini","email":"lucas.hosseini@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/beauby/jsonapi-datastore/issues"},"homepage":"https://github.com/beauby/jsonapi-datastore#readme","devDependencies":{"chai":"^3.2.0","gulp":"^3.9.0","gulp-concat":"^2.6.0","gulp-jsbeautify":"^0.1.1","gulp-jscs":"^2.0.0","gulp-jshint":"^1.11.2","gulp-markdox":"^0.1.1","gulp-mocha":"^2.1.3","gulp-rename":"^1.2.2","gulp-uglify":"^1.2.0","gulp-wrap":"^0.11.0","gulp-babel":"^5.2.1","babel":"^5.8.23","mocha":"^2.2.5"},"gitHead":"ae70e0b3634eb879e98dc4f7cfcc078051641ca2","_id":"jsonapi-datastore@0.3.2-beta","_shasum":"e143b991b39074cdc79a00bd9ad240cb04a34917","_from":".","_npmVersion":"2.13.5","_nodeVersion":"0.12.7","_npmUser":{"name":"beauby","email":"lucas.hosseini@gmail.com"},"dist":{"shasum":"e143b991b39074cdc79a00bd9ad240cb04a34917","tarball":"https://registry.npmjs.org/jsonapi-datastore/-/jsonapi-datastore-0.3.2-beta.tgz","integrity":"sha512-KFnMK9abaNtsXEz3//VjfQvlOLVbNn44vZ498m+UKFGjqvzV1gJt1I7FQx0B9iP7UHEP0E7yd1PvmV2dVJVq+w==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAlW47l6vzW7FGSTFAA51NVv96B/YtWlVYFg8DgdPuvCAiEA3Ib/r+4oiQKAfBIhziyfRWuHRAnbWTdfiD1UThNWNpA="}]},"maintainers":[{"name":"beauby","email":"lucas.hosseini@gmail.com"}]},"0.4.0-beta":{"name":"jsonapi-datastore","version":"0.4.0-beta","description":"JavaScript client-side JSON API data handling made easy.","main":"dist/node-jsonapi-datastore.js","files":["dist/"],"directories":{"test":"test"},"scripts":{"test":"gulp test"},"repository":{"type":"git","url":"git+https://github.com/beauby/jsonapi-datastore.git"},"keywords":["JSON","parsing","serializing","datastore","JSONAPI"],"author":{"name":"Lucas Hosseini","email":"lucas.hosseini@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/beauby/jsonapi-datastore/issues"},"homepage":"https://github.com/beauby/jsonapi-datastore#readme","devDependencies":{"chai":"^3.2.0","gulp":"^3.9.0","gulp-concat":"^2.6.0","gulp-jsbeautify":"^0.1.1","gulp-jscs":"^2.0.0","gulp-jshint":"^1.11.2","gulp-markdox":"^0.1.1","gulp-mocha":"^2.1.3","gulp-rename":"^1.2.2","gulp-uglify":"^1.2.0","gulp-wrap":"^0.11.0","gulp-babel":"^5.2.1","babel":"^5.8.23","mocha":"^2.2.5"},"gitHead":"56512d7be9b424cbd0da0a71acbed65eab14e042","_id":"jsonapi-datastore@0.4.0-beta","_shasum":"b499fce924d45e2bc3c6178681520063e2361f10","_from":".","_npmVersion":"2.13.5","_nodeVersion":"0.12.7","_npmUser":{"name":"beauby","email":"lucas.hosseini@gmail.com"},"dist":{"shasum":"b499fce924d45e2bc3c6178681520063e2361f10","tarball":"https://registry.npmjs.org/jsonapi-datastore/-/jsonapi-datastore-0.4.0-beta.tgz","integrity":"sha512-RkI3oL1Ww6HefMEVZXdBLmdVY/s4P5FlRzccyXb7QmsuyTQqYDXgI8QN6Py8QJRZF05f4b4gecdeBz/oTOgRVA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIApC/rhJpB1L1XxX6G7m5Q+Cj+mK3azivPrjVd9YODg2AiEA1nDo6aecz5O41Qvctt2m8PdwDTPXLSlBUPWKsxhERfc="}]},"maintainers":[{"name":"beauby","email":"lucas.hosseini@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/jsonapi-datastore-0.4.0-beta.tgz_1458052797419_0.7578040463849902"}}},"readme":"# jsonapi-datastore\n[![Build Status](https://travis-ci.org/beauby/jsonapi-datastore.svg)](https://travis-ci.org/beauby/jsonapi-datastore)\n\nJavaScript client-side [JSON API](http://jsonapi.org) data handling made easy.\n\nCurrent version is v0.4.0-beta. It is still a work in progress, but should do what it says.\n\n## Description\n\nThe [JSONAPI](http://jsonapi.org) standard is great for exchanging data (which is its purpose), but the format is not ideal to work directly with in an application.\njsonapi-datastore is a JavaScript framework-agnostic library (but an [AngularJS version](#angularjs) is provided for convenience) that takes away the burden of handling [JSONAPI](http://jsonapi.org) data on the client side.\n\nWhat it does:\n- read JSONAPI 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- make requests to your API. You design your endpoints URLs, the way you handle authentication, caching, etc. is totally up to you.\n\n## Installing\n\nInstall jsonapi-datastore with `bower` by running:\n```\n$ bower install jsonapi-datastore\n```\nor with `npm` by running:\n```\n$ npm install jsonapi-datastore\n```\n\n## Parsing data\n\nJust call the `.sync()` method of your store.\n```javascript\nvar store = new JsonApiDataStore();\nstore.sync(data);\n```\nThis parses the data and incorporates it in the store, taking care of already existing records (by updating them) and relationships.\n\n## Parsing with meta data\n\nIf you have meta data in your payload use the `.syncWithMeta` method of your store.\n```javascript\nvar store = new JsonApiDataStore();\nstore.syncWithMeta(data);\n```\nThis does everything that `.sync()` does, but returns an object with data and meta split.\n\n## Retrieving models\n\nJust call the `.find(type, id)` method of your store.\n```javascript\nvar article = store.find('article', 123);\n```\nor call the `.findAll(type)` method of your store to get all the models of that type.\n```javascript\nvar articles = store.findAll('article');\n```\nAll the attributes *and* relationships are accessible through the model as object properties.\n```javascript\nconsole.log(article.author.name);\n```\nIn case a related resource has not been fetched yet (either as a primary resource or as an included resource), the corresponding property on the model will contain only the `type` and `id` (and the `._placeHolder` property will be set to `true`). However, the models are *updated in place*, so you can fetch a related resource later, and your data will remain consistent.\n\n## Serializing data\n\nJust call the `.serialize()` method on the model.\n```javascript\nconsole.log(article.serialize());\n```\n\n## Examples\n\n```javascript\n// Create a store:\nvar store = new JsonApiDataStore();\n\n// Then, given the following payload, containing two `articles`, with a related `user` who is the author of both:\nvar payload = {\n  data: [{\n    type: 'article',\n    id: 1337,\n    attributes: {\n      title: 'Cool article'\n    },\n    relationships: {\n      author: {\n        data: {\n          type: 'user',\n          id: 1\n        }\n      }\n    }\n  }, {\n    type: 'article',\n    id: 300,\n    attributes: {\n      title: 'Even cooler article'\n    },\n    relationships: {\n      author: {\n        data: {\n          type: 'user',\n          id: 1\n        }\n      }\n    }\n  }]\n};\n\n// we can sync it:\nvar articles = store.sync(payload);\n\n// which will return the list of synced articles.\n\n// Later, we can retrieve one of those:\nvar 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:\nconsole.log(article.author);\n// { id: 1, _type: 'article' }\n\n// If we do sync the author resource later:\nvar authorPayload = {\n  data: {\n    type: 'user',\n    id: 1,\n    attributes: {\n      name: 'Lucas'\n    }\n  }\n};\n\nstore.sync(authorPayload);\n\n// we can then access the author's name through our old `article` reference:\nconsole.log(article.author.name);\n// 'Lucas'\n\n// We can also serialize any whole model in a JSONAPI-compliant way:\nconsole.log(article.serialize());\n// ...\n// or just a subset of its attributes/relationships:\nconsole.log(article.serialize({ attributes: ['title'], relationships: []}));\n// ...\n```\n\n## Documentation\n\nSee [DOCUMENTATION.md](DOCUMENTATION.md).\n\n## What's missing\n\nCurrently, the store does not handle `links` attributes or resource-level or relationship-level meta.\n\n## Notes\n\n### AngularJS\n\njsonapi-datastore is bundled with an AngularJs wrapper. Just include `ng-jsonapi-datastore.js` in your `index.html` and require the module `beauby.jsonApiDataStore` in your application.\nYou can then use the `JsonApiDataStore` factory, which is essentially defined as follows:\n```javascript\n{\n  store: new JsonApiDataStore(),\n  Model: JsonApiDataStoreModel\n}\n```\nso that you can use it as follows:\n\n```javascript\nangular\n  .module('myApp')\n  .controller('myController', function(JsonApiDataStore) {\n    var article = JsonApiDataStore.store.find('article', 1337);\n    var newArticle = new JsonApiDataStore.Model('article');\n    newArticle.setAttribute('title', 'My cool article');\n    console.log(newArticle.serialize());\n  });\n```\n\n\n## Contributing\n\nAll pull-requests welcome!\n","maintainers":[{"name":"beauby","email":"lucas.hosseini@gmail.com"}],"time":{"modified":"2022-06-19T06:34:57.873Z","created":"2015-08-20T17:44:33.410Z","0.3.0-beta":"2015-08-20T17:44:33.410Z","0.3.1-beta":"2015-08-21T11:52:27.568Z","0.3.2-beta":"2015-10-30T14:38:04.709Z","0.4.0-beta":"2016-03-15T14:39:59.853Z"},"homepage":"https://github.com/beauby/jsonapi-datastore#readme","keywords":["JSON","parsing","serializing","datastore","JSONAPI"],"repository":{"type":"git","url":"git+https://github.com/beauby/jsonapi-datastore.git"},"author":{"name":"Lucas Hosseini","email":"lucas.hosseini@gmail.com"},"bugs":{"url":"https://github.com/beauby/jsonapi-datastore/issues"},"license":"MIT","readmeFilename":"README.md"}