Skip to content

BlairAllegroTech/js-data-jsonapi

Repository files navigation

# js-data-jsonapi

npm version npm downloads cicleci build Coveralls

JsonApi Adapter for js-data

This adapter implements the JsonApi Protocol and ties it to a js-data data store.

It ties

  • JsonApi types to js-data resource
  • JsonApi relations to js-data toOne, toMany Relationships

See the Project Wiki site for more information and examples (under construction)

Goals

Goal Status Tests
Serialize JsonApi requests code complete Yes
When deserializing JsonApi data add 'ParentIds' so that js-data belongsTo relationships can work code complete Yes
When deserializing JsonApi data add 'LocalKey/LocalKeys' or 'ForeignKeys' depending on js-data configurations so that js-data hasOne and hasMany relationships can work code complete Yes
Add metadata to indicate if an object is a jsonApi reference, indicating that it is partially populated only code complete Yes
Transparently request full objects when requested from js-data cache and object is a jsonApi reference only, e.g. Not fully populated code complete Yes
Store hyperlinking data within metadata of stored data code complete Yes
Use metadata hyperlinks to request related data from JsonApi data store complete Yes
Use metadata hyperlinks to add new items to relationships In Progress Yes

Known Issues

  1. Test coverage is pretty good.Testing is by no means complete, there are many more scenarios that need to be covered off
    • (Done).
  2. None of the xxxxAll adapter methods have been tested yet. e.g findAll, destroyAll, updateAll
    • findAll (done)
  3. ~~Bower package has not been tested
  4. The code creates the DSHttpDataAdapter internally.
    • Allow the adapter to be injected or a constructor function passed via constructor options. (Done)
  5. Code is some what brittle in terms of requiring your js-data configuration to match very closely your jsonApi
    • Could look at adding additional configuration to allow flexible mapping between js-data and jsonapi
    • Further documentation required illustrating the relationships between JsonApi data structure and js-data configuration (Partially Done)
  6. I haven't actually tested this against a 3rd part JsonApi implementation yet like ember.
    • More testing to be done...... (In Progress)

Quick Start

npm install --save js-data js-data-http js-data-jsonapi or bower install --save js-data js-data-http js-data-jsonapi.

Load js-data-jsonapi.js after js-data-http.js and after js-data.js.

var adapter = new DSJsonApiAdapter.JsonApiAdapter();

var store = new JSData.DS();
store.registerAdapter('jsonApi', adapter, { default: true });

// "store" will now use the jsonApi adapter for all async operations

Or alternatively to use an existing HttpAdapter for example when using js-data-angular

.run(function(DS, DSHttpAdapter) {
    
    var options = {adapter:DSHttpAdapter};
    var adapter = new DSJsonApiAdapter.JsonApiAdapter(options);
    DS.registerAdapter('jsonApi', adapter, { default: true });
    ....
}

Version

0.0.0-alpha.21

Tech

js-data-jsonapi uses a number of open source projects to work properly:

License

The MIT License (MIT)

Copyright (c) 2015-2016 Blair Jacobs

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.