8000 Add Codecov + Readme exemples · Wikodit/js-data-jsonapi-light@16ee9db · GitHub
[go: up one dir, main page]

Skip to content

Commit 16ee9db

Browse files
committed
Add Codecov + Readme exemples
1 parent d7f5c49 commit 16ee9db

File tree

5 files changed

+98
-20
lines changed

5 files changed

+98
-20
lines changed

README.md

Lines changed: 80 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,50 @@
11
# js-data-jsonapi-light
22

3+
[![NPM][npmB]][npmL] [![CircleCI build][circleciMB]][circleciML] [![CircleCI build develop][circleciB]][circleciL] [![Codecov][codecovB]][codecovL] [![Issues][issuesB]][issuesL]
4+
5+
[npmB]: https://img.shields.io/npm/v/js-data-jsonapi-light.svg?style=flat
6+
[npmL]: https://www.npmjs.org/package/js-data-json-light
7+
[issuesB]: https://img.shields.io/github/issues/Wikodit/js-data-jsonapi-light.svg
8+
[issuesL]: https://github.com/Wikodit/js-data-jsonapi-light/issues
9+
[circleciB]: https://img.shields.io/circleci/project/Wikodit/js-data-jsonapi-light/develop.svg?style=flat&label=build%20develop
10+
[circleciL]: https://circleci.com/gh/Wikodit/js-data-jsonapi-light/tree/develop
11+
[circleciMB]: https://img.shields.io/circleci/project/Wikodit/js-data-jsonapi-light/master.svg?style=flat&label=build%20master
12+
[circleciML]: https://circleci.com/gh/Wikodit/js-data-jsonapi-light/tree/master
13+
[codecovB]: https://img.shields.io/codecov/c/github/Wikodit/js-data-jsonapi-light/develop.svg?style=flat&label=coverage
14+
[codecovL]: https://codecov.io/gh/Wikodit/js-data-jsonapi-light
15+
316
## Overview
417

518
JsonAPI Adapter based on [js-data-http](https://github.com/js-data/js-data-http) for [js-data](http://www.js-data.io)
619

720
This adapter just add a light serialize and deserialize layer over DSHttpAdapter.
821

9-
For a more complete integration, you could use: [js-data-jsonapi](https://github.com/BlairAllegroTech/js-data-jsonapi)
22+
## Compatibility
23+
24+
| js-data | >= 3.0.0-rc.7 |
25+
| js-data-http | >= 3.0.0-rc.2 |
26+
27+
By design it is not compatible with JS-Data v2, for a full integration on v2, you could use: [js-data-jsonapi](https://github.com/BlairAllegroTech/js-data-jsonapi).
1028

1129
## Quick Start
1230

13-
`npm install --save js-data js-data-http js-data-jsonapi`
31+
First you need to install everything needed :
32+
33+
`npm install --save js-data js-data-http js-data-jsonapi js-data-jsonapi-light`
1434

1535
Load `js-data-jsonapi-light.js` last.
1636

1737
```js
1838
import { DataStore } from 'js-data'
39+
// or `var DataStore = JSDate.DataStore`
40+
1941
import { JsonApiAdapter } from 'js-data-jsonapi-light'
42+
// or `var JsonApiAdapter = JSDataJsonApiLight.JsonApiAdapter`
2043

21-
// Or :
22-
// const store = new JSData.DataStore();
44+
// Initialize our Store
2345
const store = new DataStore();
2446

25-
// Or :
26-
// const jsonApiAdapter = new JSDataJsonApiLight.JsonApiAdapter({
47+
// Initialize our Adapter
2748
const jsonApiAdapter = new JsonApiAdapter({
2849
// Store needs to be given to the adapter
2950
store: store
@@ -33,13 +54,64 @@ const jsonApiAdapter = new JsonApiAdapter({
3354
// If a deserialization option is given, it will be run after JSONApi deserialization has occured
3455
});
3556

57+
// Register the Adapter as the default one in the store
3658
store.registerAdapter('jsonApi', jsonApiAdapter, { default: true })
3759
```
3860

39-
## Advanced support
61+
## Exemples
62+
63+
### Use case
64+
65+
* You can find examples of Mapper Definitions in [test/resources](https://github.com/Wikodit/js-data-jsonapi-light/tree/develop/test/resources).
66+
* Fake JsonAPI responses corresponding to those mapper can be found in [test/api](https://github.com/Wikodit/js-data-jsonapi-light/tree/develop/test/api)
67+
* Bootstrap of JSData + JsonAPI could be found in [test/ds](https://github.com/Wikodit/js-data-jsonapi-light/tree/develop/test/ds.ts)
68+
* Exemple of use could be found in [test/unit](https://github.com/Wikodit/js-data-jsonapi-light/tree/develop/test/unit)
69+
70+
### Define your mappers
71+
72+
JSData works with mappers which define the communication part and the way your resources are linked together
73+
74+
```
75+
const UserMapper = window.store.defineMapper('User',{
76+
endpoint: 'users', // optional, it will default to `User`
77+
relations: {
78+
hasOne: {
79+
'UserProfile': {
80+
localField: 'profile',
81+
foreignKey: 'userId'
82+
}
83+
},
84+
hasMany: {
85+
'Article': {
86+
localField: 'articles',
87+
foreignKey: 'authorId'
88+
}
89+
},
90+
belongsTo: {
91+
'UserGroup': {
92+
localField: 'group',
93+
localKey: 'groupId'
94+
}
95+
}
96+
}
97+
})
98+
```
99+
100+
### Fetch your data
40101

102+
```
103+
UserMapper.findAll({ include: 'profile' }).then((records) => {
104+
console.log(records);
105+
})
106+
```
107+
108+
Once some records has been loaded they are also cached in the DataStore, you can access them synchronously with :
109+
```
110+
records = store.getAll('User')
111+
```
41112

42-
### JSONApi Meta
113+
114+
### Get JSONApi Meta
43115

44116
To retrieve JSONApi Meta on every call :
45117

@@ -52,7 +124,6 @@ store.findAll('User', {}, {
52124
})
53125
```
54126

55-
56127
## Development Status
57128

58129
### Version

circle.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
test:
22
pre:
33
- npm install -g karma-cli
4+
post:
5+
- bash <(curl -s https://codecov.io/bash)
46
machine:
57
node:
68
version: 6.1.0

dist/js-data-jsonapi-light.js

Lines changed: 11 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
0