Skip to content

Commit 002b24a

Browse files
chore(release): 2.0.1 [skip ci]
### [2.0.1](v2.0.0...v2.0.1) (2022-05-01) ### Bug Fixes * release ([0809e68](0809e68)) * release ([fc49664](fc49664))
1 parent 0809e68 commit 002b24a

File tree

7 files changed

+100
-18
lines changed

7 files changed

+100
-18
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
### [2.0.1](https://github.com/andersondanilo/jsonapi-fractal/compare/v2.0.0...v2.0.1) (2022-05-01)
2+
3+
4+
### Bug Fixes
5+
6+
* release ([0809e68](https://github.com/andersondanilo/jsonapi-fractal/commit/0809e68f177d0b26b8abcc0dda2a315012ed740b))
7+
* release ([fc49664](https://github.com/andersondanilo/jsonapi-fractal/commit/fc4966435357bfd857e664b3be728044a5d55cfd))
8+
19
## [2.0.0](https://github.com/andersondanilo/jsonapi-fractal/compare/v1.1.0...v2.0.0) (2022-05-01)
210

311

README.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,80 @@ console.log(JSON.stringify(entity))
109109
## Serialize with transformers
110110
```js
111111
// examples/serialize-with-transformers.js
112+
113+
const { Transformer, DefaultTransformer, transform, whitelist } = require('jsonapi-fractal')
114+
115+
class UserTransformer extends Transformer {
116+
constructor() {
117+
super()
118+
this.type = 'users'
119+
this.relationships = {
120+
images: this.images,
121+
}
122+
}
123+
124+
transform(user, options) {
125+
return whitelist(user, ['_id', 'firstName', 'lastName'])
126+
}
127+
128+
images(user, options) {
129+
return transform()
130+
.withInput(user.images)
131+
.withTransformer(new DefaultTransformer('images'))
132+
.withIncluded(true)
133+
.toContext()
134+
}
135+
}
136+
137+
const user = {
138+
_id: 1,
139+
firstName: 'Joe',
140+
lastName: 'Doe',
141+
images: [{ _id: 5, url: 'http://' }],
142+
}
143+
144+
const serialized = transform()
145+
.withInput(user)
146+
.withTransformer(new UserTransformer())
147+
.withOptions({ idKey: '_id' })
148+
.serialize()
149+
150+
console.log(JSON.stringify(serialized))
151+
152+
/**
153+
* OUTPUT:
154+
*
155+
* {
156+
* "data": {
157+
* "id": 1,
158+
* "type": "users",
159+
* "attributes": {
160+
* "firstName": "Joe",
161+
* "lastName": "Doe"
162+
* },
163+
* "relationships": {
164+
* "images": {
165+
* "data": [
166+
* {
167+
* "id": 5,
168+
* "type": "images"
169+
* }
170+
* ]
171+
* }
172+
* }
173+
* },
174+
* "included": [
175+
* {
176+
* "id": 5,
177+
* "type": "images",
178+
* "attributes": {
179+
* "url": "http://"
180+
* }
181+
* }
182+
* ]
183+
* }
184+
*/
185+
112186
```
113187

114188
## Links

docs/README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jsonapi-fractal
3333

3434
#### Defined in
3535

36-
[src/types.ts:17](https://github.com/andersondanilo/jsonapi-fractal/blob/7bc2651/src/types.ts#L17)
36+
[src/types.ts:17](https://github.com/andersondanilo/jsonapi-fractal/blob/0809e68/src/types.ts#L17)
3737

3838
___
3939

@@ -59,7 +59,7 @@ ___
5959

6060
#### Defined in
6161

62-
[src/context.ts:5](https://github.com/andersondanilo/jsonapi-fractal/blob/7bc2651/src/context.ts#L5)
62+
[src/context.ts:5](https://github.com/andersondanilo/jsonapi-fractal/blob/0809e68/src/context.ts#L5)
6363

6464
___
6565

@@ -69,7 +69,7 @@ ___
6969

7070
#### Defined in
7171

72-
[src/types.ts:15](https://github.com/andersondanilo/jsonapi-fractal/blob/7bc2651/src/types.ts#L15)
72+
[src/types.ts:15](https://github.com/andersondanilo/jsonapi-fractal/blob/0809e68/src/types.ts#L15)
7373

7474
___
7575

@@ -94,7 +94,7 @@ ___
9494

9595
#### Defined in
9696

97-
[src/types.ts:46](https://github.com/andersondanilo/jsonapi-fractal/blob/7bc2651/src/types.ts#L46)
97+
[src/types.ts:46](https://github.com/andersondanilo/jsonapi-fractal/blob/0809e68/src/types.ts#L46)
9898

9999
___
100100

@@ -111,7 +111,7 @@ ___
111111

112112
#### Defined in
113113

114-
[src/transformer.ts:14](https://github.com/andersondanilo/jsonapi-fractal/blob/7bc2651/src/transformer.ts#L14)
114+
[src/transformer.ts:14](https://github.com/andersondanilo/jsonapi-fractal/blob/0809e68/src/transformer.ts#L14)
115115

116116
## Functions
117117

@@ -141,7 +141,7 @@ Deserialize a JSON:API response
141141

142142
#### Defined in
143143

144-
[src/deserializer.ts:12](https://github.com/andersondanilo/jsonapi-fractal/blob/7bc2651/src/deserializer.ts#L12)
144+
[src/deserializer.ts:12](https://github.com/andersondanilo/jsonapi-fractal/blob/0809e68/src/deserializer.ts#L12)
145145

146146
___
147147

@@ -172,7 +172,7 @@ Serialize the entity
172172

173173
#### Defined in
174174

175-
[src/serializer.ts:32](https://github.com/andersondanilo/jsonapi-fractal/blob/7bc2651/src/serializer.ts#L32)
175+
[src/serializer.ts:32](https://github.com/andersondanilo/jsonapi-fractal/blob/0809e68/src/serializer.ts#L32)
176176

177177
___
178178

@@ -195,7 +195,7 @@ Create a ContextBuilder, used to configure the transformation
195195

196196
#### Defined in
197197

198-
[src/serializer.ts:21](https://github.com/andersondanilo/jsonapi-fractal/blob/7bc2651/src/serializer.ts#L21)
198+
[src/serializer.ts:21](https://github.com/andersondanilo/jsonapi-fractal/blob/0809e68/src/serializer.ts#L21)
199199

200200
___
201201

@@ -218,4 +218,4 @@ Keep only a set of fields on a given object
218218

219219
#### Defined in
220220

221-
[src/utils.ts:40](https://github.com/andersondanilo/jsonapi-fractal/blob/7bc2651/src/utils.ts#L40)
221+
[src/utils.ts:40](https://github.com/andersondanilo/jsonapi-fractal/blob/0809e68/src/utils.ts#L40)

docs/classes/DefaultTransformer.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656

5757
#### Defined in
5858

59-
[src/default-transformer.ts:8](https://github.com/andersondanilo/jsonapi-fractal/blob/7bc2651/src/default-transformer.ts#L8)
59+
[src/default-transformer.ts:8](https://github.com/andersondanilo/jsonapi-fractal/blob/0809e68/src/default-transformer.ts#L8)
6060

6161
## Properties
6262

@@ -70,7 +70,7 @@
7070

7171
#### Defined in
7272

73-
[src/default-transformer.ts:6](https://github.com/andersondanilo/jsonapi-fractal/blob/7bc2651/src/default-transformer.ts#L6)
73+
[src/default-transformer.ts:6](https://github.com/andersondanilo/jsonapi-fractal/blob/0809e68/src/default-transformer.ts#L6)
7474

7575
___
7676

@@ -104,4 +104,4 @@ ___
104104

105105
#### Defined in
106106

107-
[src/default-transformer.ts:23](https://github.com/andersondanilo/jsonapi-fractal/blob/7bc2651/src/default-transformer.ts#L23)
107+
[src/default-transformer.ts:23](https://github.com/andersondanilo/jsonapi-fractal/blob/0809e68/src/default-transformer.ts#L23)

docs/classes/JsonApiFractalError.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Error.constructor
4444

4545
#### Defined in
4646

47-
[src/errors.ts:2](https://github.com/andersondanilo/jsonapi-fractal/blob/7bc2651/src/errors.ts#L2)
47+
[src/errors.ts:2](https://github.com/andersondanilo/jsonapi-fractal/blob/0809e68/src/errors.ts#L2)
4848

4949
## Properties
5050

docs/classes/Transformer.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
#### Defined in
4747

48-
[src/transformer.ts:8](https://github.com/andersondanilo/jsonapi-fractal/blob/7bc2651/src/transformer.ts#L8)
48+
[src/transformer.ts:8](https://github.com/andersondanilo/jsonapi-fractal/blob/0809e68/src/transformer.ts#L8)
4949

5050
## Properties
5151

@@ -55,7 +55,7 @@
5555

5656
#### Defined in
5757

58-
[src/transformer.ts:5](https://github.com/andersondanilo/jsonapi-fractal/blob/7bc2651/src/transformer.ts#L5)
58+
[src/transformer.ts:5](https://github.com/andersondanilo/jsonapi-fractal/blob/0809e68/src/transformer.ts#L5)
5959

6060
___
6161

@@ -65,7 +65,7 @@ ___
6565

6666
#### Defined in
6767

68-
[src/transformer.ts:4](https://github.com/andersondanilo/jsonapi-fractal/blob/7bc2651/src/transformer.ts#L4)
68+
[src/transformer.ts:4](https://github.com/andersondanilo/jsonapi-fractal/blob/0809e68/src/transformer.ts#L4)
6969

7070
## Methods
7171

@@ -86,4 +86,4 @@ ___
8686

8787
#### Defined in
8888

89-
[src/transformer.ts:6](https://github.com/andersondanilo/jsonapi-fractal/blob/7bc2651/src/transformer.ts#L6)
89+
[src/transformer.ts:6](https://github.com/andersondanilo/jsonapi-fractal/blob/0809e68/src/transformer.ts#L6)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jsonapi-fractal",
3-
"version": "2.0.0",
3+
"version": "2.0.1",
44
"description": "JSON:API Serializer inspired by Fractal (PHP)",
55
"license": "MIT",
66
"main": "dist/index",

0 commit comments

Comments
 (0)