@ember-data-mirror/serializer 5.6.0-alpha.2 → 5.6.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +5 -10
- package/dist/index.js.map +1 -1
- package/dist/{json-CVTR4xWv.js → json-CYP2BhR9.js} +42 -89
- package/dist/json-CYP2BhR9.js.map +1 -0
- package/dist/json-api.js +14 -31
- package/dist/json-api.js.map +1 -1
- package/dist/json.js +1 -1
- package/dist/rest.js +30 -59
- package/dist/rest.js.map +1 -1
- package/dist/transform.js +9 -32
- package/dist/transform.js.map +1 -1
- package/package.json +13 -16
- package/unstable-preview-types/-private/embedded-records-mixin.d.ts +1 -4
- package/unstable-preview-types/-private/embedded-records-mixin.d.ts.map +1 -1
- package/unstable-preview-types/-private/transforms/boolean.d.ts +2 -5
- package/unstable-preview-types/-private/transforms/boolean.d.ts.map +1 -1
- package/unstable-preview-types/-private/transforms/date.d.ts +1 -4
- package/unstable-preview-types/-private/transforms/date.d.ts.map +1 -1
- package/unstable-preview-types/-private/transforms/number.d.ts +1 -4
- package/unstable-preview-types/-private/transforms/number.d.ts.map +1 -1
- package/unstable-preview-types/-private/transforms/string.d.ts +1 -4
- package/unstable-preview-types/-private/transforms/string.d.ts.map +1 -1
- package/unstable-preview-types/-private/transforms/transform.d.ts +4 -9
- package/unstable-preview-types/-private/transforms/transform.d.ts.map +1 -1
- package/unstable-preview-types/index.d.ts +7 -12
- package/unstable-preview-types/index.d.ts.map +1 -1
- package/unstable-preview-types/json-api.d.ts +9 -24
- package/unstable-preview-types/json-api.d.ts.map +1 -1
- package/unstable-preview-types/json.d.ts +19 -62
- package/unstable-preview-types/json.d.ts.map +1 -1
- package/unstable-preview-types/rest.d.ts +11 -24
- package/unstable-preview-types/rest.d.ts.map +1 -1
- package/unstable-preview-types/transform.d.ts +0 -3
- package/unstable-preview-types/transform.d.ts.map +1 -1
- package/dist/json-CVTR4xWv.js.map +0 -1
|
@@ -14,10 +14,6 @@ function coerceId(id) {
|
|
|
14
14
|
return String(id);
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @module @ember-data-mirror/serializer/json
|
|
20
|
-
*/
|
|
21
17
|
const SOURCE_POINTER_REGEXP = /^\/?data\/(attributes|relationships)\/(.*)/;
|
|
22
18
|
const SOURCE_POINTER_PRIMARY_REGEXP = /^\/?data/;
|
|
23
19
|
const PRIMARY_ATTRIBUTE_KEY = 'base';
|
|
@@ -43,7 +39,7 @@ const PRIMARY_ATTRIBUTE_KEY = 'base';
|
|
|
43
39
|
|
|
44
40
|
For example, given the following `User` model and JSON payload:
|
|
45
41
|
|
|
46
|
-
```app/models/user.js
|
|
42
|
+
```js [app/models/user.js]
|
|
47
43
|
import Model, { attr, belongsTo, hasMany } from '@ember-data-mirror/model';
|
|
48
44
|
|
|
49
45
|
export default class UserModel extends Model {
|
|
@@ -94,10 +90,8 @@ const PRIMARY_ATTRIBUTE_KEY = 'base';
|
|
|
94
90
|
- `normalize` delegates to these methods to
|
|
95
91
|
turn the record payload into the JSON API format.
|
|
96
92
|
|
|
97
|
-
@main @ember-data-mirror/serializer/json
|
|
98
93
|
@class JSONSerializer
|
|
99
94
|
@public
|
|
100
|
-
@extends Serializer
|
|
101
95
|
*/
|
|
102
96
|
const JSONSerializer = Serializer.extend({
|
|
103
97
|
/**
|
|
@@ -108,7 +102,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
108
102
|
`primaryKey` property to match the `primaryKey` of your external
|
|
109
103
|
store.
|
|
110
104
|
Example
|
|
111
|
-
```app/serializers/application.js
|
|
105
|
+
```js [app/serializers/application.js]
|
|
112
106
|
import JSONSerializer from '@ember-data-mirror/serializer/json';
|
|
113
107
|
export default class ApplicationSerializer extends JSONSerializer {
|
|
114
108
|
primaryKey = '_id'
|
|
@@ -127,7 +121,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
127
121
|
property `key` can also be used to designate the attribute's key on
|
|
128
122
|
the response payload.
|
|
129
123
|
Example
|
|
130
|
-
```app/models/person.js
|
|
124
|
+
```js [app/models/person.js]
|
|
131
125
|
import Model, { attr } from '@ember-data-mirror/model';
|
|
132
126
|
export default class PersonModel extends Model {
|
|
133
127
|
@attr('string') firstName;
|
|
@@ -136,7 +130,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
136
130
|
@attr('boolean') admin;
|
|
137
131
|
}
|
|
138
132
|
```
|
|
139
|
-
```app/serializers/person.js
|
|
133
|
+
```js [app/serializers/person.js]
|
|
140
134
|
import JSONSerializer from '@ember-data-mirror/serializer/json';
|
|
141
135
|
export default class PersonSerializer extends JSONSerializer {
|
|
142
136
|
attrs = {
|
|
@@ -148,7 +142,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
148
142
|
You can also remove attributes and relationships by setting the `serialize`
|
|
149
143
|
key to `false` in your mapping object.
|
|
150
144
|
Example
|
|
151
|
-
```app/serializers/person.js
|
|
145
|
+
```js [app/serializers/person.js]
|
|
152
146
|
import JSONSerializer from '@ember-data-mirror/serializer/json';
|
|
153
147
|
export default class PostSerializer extends JSONSerializer {
|
|
154
148
|
attrs = {
|
|
@@ -180,8 +174,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
180
174
|
`Transform#deserialize` method on the matching property of the
|
|
181
175
|
JSON object. This method is typically called after the
|
|
182
176
|
serializer's `normalize` method.
|
|
183
|
-
@
|
|
184
|
-
@private
|
|
177
|
+
@private
|
|
185
178
|
@param {Model} typeClass
|
|
186
179
|
@param {Object} data The data to transform
|
|
187
180
|
@return {Object} data The transformed data object
|
|
@@ -218,7 +211,6 @@ const JSONSerializer = Serializer.extend({
|
|
|
218
211
|
});
|
|
219
212
|
```
|
|
220
213
|
@since 1.13.0
|
|
221
|
-
@method normalizeResponse
|
|
222
214
|
@public
|
|
223
215
|
@param {Store} store
|
|
224
216
|
@param {Model} primaryModelClass
|
|
@@ -255,7 +247,6 @@ const JSONSerializer = Serializer.extend({
|
|
|
255
247
|
Called by the default normalizeResponse implementation when the
|
|
256
248
|
type of request is `findRecord`
|
|
257
249
|
@since 1.13.0
|
|
258
|
-
@method normalizeFindRecordResponse
|
|
259
250
|
@public
|
|
260
251
|
@param {Store} store
|
|
261
252
|
@param {Model} primaryModelClass
|
|
@@ -271,7 +262,6 @@ const JSONSerializer = Serializer.extend({
|
|
|
271
262
|
Called by the default normalizeResponse implementation when the
|
|
272
263
|
type of request is `queryRecord`
|
|
273
264
|
@since 1.13.0
|
|
274
|
-
@method normalizeQueryRecordResponse
|
|
275
265
|
@public
|
|
276
266
|
@param {Store} store
|
|
277
267
|
@param {Model} primaryModelClass
|
|
@@ -287,7 +277,6 @@ const JSONSerializer = Serializer.extend({
|
|
|
287
277
|
Called by the default normalizeResponse implementation when the
|
|
288
278
|
type of request is `findAll`
|
|
289
279
|
@since 1.13.0
|
|
290
|
-
@method normalizeFindAllResponse
|
|
291
280
|
@public
|
|
292
281
|
@param {Store} store
|
|
293
282
|
@param {Model} primaryModelClass
|
|
@@ -303,7 +292,6 @@ const JSONSerializer = Serializer.extend({
|
|
|
303
292
|
Called by the default normalizeResponse implementation when the
|
|
304
293
|
type of request is `findBelongsTo`
|
|
305
294
|
@since 1.13.0
|
|
306
|
-
@method normalizeFindBelongsToResponse
|
|
307
295
|
@public
|
|
308
296
|
@param {Store} store
|
|
309
297
|
@param {Model} primaryModelClass
|
|
@@ -319,7 +307,6 @@ const JSONSerializer = Serializer.extend({
|
|
|
319
307
|
Called by the default normalizeResponse implementation when the
|
|
320
308
|
type of request is `findHasMany`
|
|
321
309
|
@since 1.13.0
|
|
322
|
-
@method normalizeFindHasManyResponse
|
|
323
310
|
@public
|
|
324
311
|
@param {Store} store
|
|
325
312
|
@param {Model} primaryModelClass
|
|
@@ -335,7 +322,6 @@ const JSONSerializer = Serializer.extend({
|
|
|
335
322
|
Called by the default normalizeResponse implementation when the
|
|
336
323
|
type of request is `findMany`
|
|
337
324
|
@since 1.13.0
|
|
338
|
-
@method normalizeFindManyResponse
|
|
339
325
|
@public
|
|
340
326
|
@param {Store} store
|
|
341
327
|
@param {Model} primaryModelClass
|
|
@@ -351,7 +337,6 @@ const JSONSerializer = Serializer.extend({
|
|
|
351
337
|
Called by the default normalizeResponse implementation when the
|
|
352
338
|
type of request is `query`
|
|
353
339
|
@since 1.13.0
|
|
354
|
-
@method normalizeQueryResponse
|
|
355
340
|
@public
|
|
356
341
|
@param {Store} store
|
|
357
342
|
@param {Model} primaryModelClass
|
|
@@ -367,7 +352,6 @@ const JSONSerializer = Serializer.extend({
|
|
|
367
352
|
Called by the default normalizeResponse implementation when the
|
|
368
353
|
type of request is `createRecord`
|
|
369
354
|
@since 1.13.0
|
|
370
|
-
@method normalizeCreateRecordResponse
|
|
371
355
|
@public
|
|
372
356
|
@param {Store} store
|
|
373
357
|
@param {Model} primaryModelClass
|
|
@@ -383,7 +367,6 @@ const JSONSerializer = Serializer.extend({
|
|
|
383
367
|
Called by the default normalizeResponse implementation when the
|
|
384
368
|
type of request is `deleteRecord`
|
|
385
369
|
@since 1.13.0
|
|
386
|
-
@method normalizeDeleteRecordResponse
|
|
387
370
|
@public
|
|
388
371
|
@param {Store} store
|
|
389
372
|
@param {Model} primaryModelClass
|
|
@@ -399,7 +382,6 @@ const JSONSerializer = Serializer.extend({
|
|
|
399
382
|
Called by the default normalizeResponse implementation when the
|
|
400
383
|
type of request is `updateRecord`
|
|
401
384
|
@since 1.13.0
|
|
402
|
-
@method normalizeUpdateRecordResponse
|
|
403
385
|
@public
|
|
404
386
|
@param {Store} store
|
|
405
387
|
@param {Model} primaryModelClass
|
|
@@ -415,7 +397,6 @@ const JSONSerializer = Serializer.extend({
|
|
|
415
397
|
normalizeUpdateRecordResponse, normalizeCreateRecordResponse and
|
|
416
398
|
normalizeDeleteRecordResponse delegate to this method by default.
|
|
417
399
|
@since 1.13.0
|
|
418
|
-
@method normalizeSaveResponse
|
|
419
400
|
@public
|
|
420
401
|
@param {Store} store
|
|
421
402
|
@param {Model} primaryModelClass
|
|
@@ -431,7 +412,6 @@ const JSONSerializer = Serializer.extend({
|
|
|
431
412
|
normalizeQueryResponse and normalizeFindRecordResponse delegate to this
|
|
432
413
|
method by default.
|
|
433
414
|
@since 1.13.0
|
|
434
|
-
@method normalizeSingleResponse
|
|
435
415
|
@public
|
|
436
416
|
@param {Store} store
|
|
437
417
|
@param {Model} primaryModelClass
|
|
@@ -447,7 +427,6 @@ const JSONSerializer = Serializer.extend({
|
|
|
447
427
|
normalizeQueryResponse, normalizeFindManyResponse, and normalizeFindHasManyResponse delegate
|
|
448
428
|
to this method by default.
|
|
449
429
|
@since 1.13.0
|
|
450
|
-
@method normalizeArrayResponse
|
|
451
430
|
@public
|
|
452
431
|
@param {Store} store
|
|
453
432
|
@param {Model} primaryModelClass
|
|
@@ -460,7 +439,6 @@ const JSONSerializer = Serializer.extend({
|
|
|
460
439
|
return this._normalizeResponse(store, primaryModelClass, payload, id, requestType, false);
|
|
461
440
|
},
|
|
462
441
|
/**
|
|
463
|
-
@method _normalizeResponse
|
|
464
442
|
@param {Store} store
|
|
465
443
|
@param {Model} primaryModelClass
|
|
466
444
|
@param {Object} payload
|
|
@@ -520,7 +498,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
520
498
|
You can use this method, for example, to normalize underscored keys to camelized
|
|
521
499
|
or other general-purpose normalizations.
|
|
522
500
|
Example
|
|
523
|
-
```app/serializers/application.js
|
|
501
|
+
```js [app/serializers/application.js]
|
|
524
502
|
import JSONSerializer from '@ember-data-mirror/serializer/json';
|
|
525
503
|
import { underscore } from '<app-name>/utils/string-utils';
|
|
526
504
|
import { get } from '@ember/object';
|
|
@@ -537,8 +515,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
537
515
|
}
|
|
538
516
|
}
|
|
539
517
|
```
|
|
540
|
-
@
|
|
541
|
-
@public
|
|
518
|
+
@public
|
|
542
519
|
@param {Model} typeClass
|
|
543
520
|
@param {Object} hash
|
|
544
521
|
@return {Object}
|
|
@@ -567,8 +544,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
567
544
|
},
|
|
568
545
|
/**
|
|
569
546
|
Returns the resource's ID.
|
|
570
|
-
@
|
|
571
|
-
@public
|
|
547
|
+
@public
|
|
572
548
|
@param {Object} modelClass
|
|
573
549
|
@param {Object} resourceHash
|
|
574
550
|
@return {String}
|
|
@@ -581,8 +557,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
581
557
|
/**
|
|
582
558
|
Returns the resource's attributes formatted as a JSON-API "attributes object".
|
|
583
559
|
http://jsonapi.org/format/#document-resource-object-attributes
|
|
584
|
-
@
|
|
585
|
-
@public
|
|
560
|
+
@public
|
|
586
561
|
@param {Object} modelClass
|
|
587
562
|
@param {Object} resourceHash
|
|
588
563
|
@return {Object}
|
|
@@ -601,8 +576,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
601
576
|
/**
|
|
602
577
|
Returns a relationship formatted as a JSON-API "relationship object".
|
|
603
578
|
http://jsonapi.org/format/#document-resource-object-relationships
|
|
604
|
-
@
|
|
605
|
-
@public
|
|
579
|
+
@public
|
|
606
580
|
@param {Object} relationshipModelName
|
|
607
581
|
@param {Object} relationshipHash
|
|
608
582
|
@return {Object}
|
|
@@ -641,8 +615,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
641
615
|
- `relationshipKey` key under which the value for the relationship is
|
|
642
616
|
extracted from the resourceHash
|
|
643
617
|
- `relationshipMeta` meta information about the relationship
|
|
644
|
-
@
|
|
645
|
-
@public
|
|
618
|
+
@public
|
|
646
619
|
@param {Object} relationshipModelName
|
|
647
620
|
@param {Object} relationshipHash
|
|
648
621
|
@param {Object} relationshipOptions
|
|
@@ -654,8 +627,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
654
627
|
/**
|
|
655
628
|
Returns the resource's relationships formatted as a JSON-API "relationships object".
|
|
656
629
|
http://jsonapi.org/format/#document-resource-object-relationships
|
|
657
|
-
@
|
|
658
|
-
@public
|
|
630
|
+
@public
|
|
659
631
|
@param {Object} modelClass
|
|
660
632
|
@param {Object} resourceHash
|
|
661
633
|
@return {Object}
|
|
@@ -722,8 +694,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
722
694
|
},
|
|
723
695
|
/**
|
|
724
696
|
Dasherizes the model name in the payload
|
|
725
|
-
@
|
|
726
|
-
@public
|
|
697
|
+
@public
|
|
727
698
|
@param {String} key
|
|
728
699
|
@return {String} the model's modelName
|
|
729
700
|
*/
|
|
@@ -731,7 +702,6 @@ const JSONSerializer = Serializer.extend({
|
|
|
731
702
|
return dasherize(singularize(key));
|
|
732
703
|
},
|
|
733
704
|
/**
|
|
734
|
-
@method normalizeRelationships
|
|
735
705
|
@private
|
|
736
706
|
*/
|
|
737
707
|
normalizeRelationships(typeClass, hash) {
|
|
@@ -751,7 +721,6 @@ const JSONSerializer = Serializer.extend({
|
|
|
751
721
|
}
|
|
752
722
|
},
|
|
753
723
|
/**
|
|
754
|
-
@method normalizeUsingDeclaredMapping
|
|
755
724
|
@private
|
|
756
725
|
*/
|
|
757
726
|
normalizeUsingDeclaredMapping(modelClass, hash) {
|
|
@@ -780,8 +749,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
780
749
|
/**
|
|
781
750
|
Looks up the property key that was set by the custom `attr` mapping
|
|
782
751
|
passed to the serializer.
|
|
783
|
-
@
|
|
784
|
-
@private
|
|
752
|
+
@private
|
|
785
753
|
@param {String} key
|
|
786
754
|
@return {String} key
|
|
787
755
|
*/
|
|
@@ -807,8 +775,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
807
775
|
/**
|
|
808
776
|
Check attrs.key.serialize property to inform if the `key`
|
|
809
777
|
can be serialized
|
|
810
|
-
@
|
|
811
|
-
@private
|
|
778
|
+
@private
|
|
812
779
|
@param {String} key
|
|
813
780
|
@return {Boolean} true if the key can be serialized
|
|
814
781
|
*/
|
|
@@ -820,8 +787,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
820
787
|
When attrs.key.serialize is set to true then
|
|
821
788
|
it takes priority over the other checks and the related
|
|
822
789
|
attribute/relationship will be serialized
|
|
823
|
-
@
|
|
824
|
-
@private
|
|
790
|
+
@private
|
|
825
791
|
@param {String} key
|
|
826
792
|
@return {Boolean} true if the key must be serialized
|
|
827
793
|
*/
|
|
@@ -833,8 +799,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
833
799
|
Check if the given hasMany relationship should be serialized
|
|
834
800
|
By default only many-to-many and many-to-none relationships are serialized.
|
|
835
801
|
This could be configured per relationship by Serializer's `attrs` object.
|
|
836
|
-
@
|
|
837
|
-
@public
|
|
802
|
+
@public
|
|
838
803
|
@param {Snapshot} snapshot
|
|
839
804
|
@param {String} key
|
|
840
805
|
@param {RelationshipSchema} relationship
|
|
@@ -855,7 +820,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
855
820
|
By default, it creates a JSON object with a key for
|
|
856
821
|
each attribute and belongsTo relationship.
|
|
857
822
|
For example, consider this model:
|
|
858
|
-
```app/models/comment.js
|
|
823
|
+
```js [app/models/comment.js]
|
|
859
824
|
import Model, { attr, belongsTo } from '@ember-data-mirror/model';
|
|
860
825
|
export default class CommentModel extends Model {
|
|
861
826
|
@attr title;
|
|
@@ -888,7 +853,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
888
853
|
built-in serialization format.
|
|
889
854
|
In that case, you can implement `serialize` yourself and
|
|
890
855
|
return a JSON hash of your choosing.
|
|
891
|
-
```app/serializers/post.js
|
|
856
|
+
```js [app/serializers/post.js]
|
|
892
857
|
import JSONSerializer from '@ember-data-mirror/serializer/json';
|
|
893
858
|
export default class PostSerializer extends JSONSerializer {
|
|
894
859
|
serialize(snapshot, options) {
|
|
@@ -908,7 +873,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
908
873
|
If you want to define a serializer for your entire
|
|
909
874
|
application, you'll probably want to use `eachAttribute`
|
|
910
875
|
and `eachRelationship` on the record.
|
|
911
|
-
```app/serializers/application.js
|
|
876
|
+
```js [app/serializers/application.js]
|
|
912
877
|
import JSONSerializer from '@ember-data-mirror/serializer/json';
|
|
913
878
|
import { singularize } from '<app-name>/utils/string-utils';
|
|
914
879
|
export default class ApplicationSerializer extends JSONSerializer {
|
|
@@ -947,7 +912,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
947
912
|
If you just want to do some small tweaks on the default JSON,
|
|
948
913
|
you can call `super.serialize` first and make the tweaks on
|
|
949
914
|
the returned JSON.
|
|
950
|
-
```app/serializers/post.js
|
|
915
|
+
```js [app/serializers/post.js]
|
|
951
916
|
import JSONSerializer from '@ember-data-mirror/serializer/json';
|
|
952
917
|
export default class PostSerializer extends JSONSerializer {
|
|
953
918
|
serialize(snapshot, options) {
|
|
@@ -958,8 +923,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
958
923
|
}
|
|
959
924
|
}
|
|
960
925
|
```
|
|
961
|
-
@
|
|
962
|
-
@public
|
|
926
|
+
@public
|
|
963
927
|
@param {Snapshot} snapshot
|
|
964
928
|
@param {Object} options
|
|
965
929
|
@return {Object} json
|
|
@@ -992,7 +956,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
992
956
|
Otherwise you can override this method to customize how the record is added to the hash.
|
|
993
957
|
The hash property should be modified by reference.
|
|
994
958
|
For example, your server may expect underscored root objects.
|
|
995
|
-
```app/serializers/application.js
|
|
959
|
+
```js [app/serializers/application.js]
|
|
996
960
|
import RESTSerializer from '@ember-data-mirror/serializer/rest';
|
|
997
961
|
import { underscoren} from '<app-name>/utils/string-utils';
|
|
998
962
|
export default class ApplicationSerializer extends RESTSerializer {
|
|
@@ -1002,8 +966,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
1002
966
|
}
|
|
1003
967
|
}
|
|
1004
968
|
```
|
|
1005
|
-
@
|
|
1006
|
-
@public
|
|
969
|
+
@public
|
|
1007
970
|
@param {Object} hash
|
|
1008
971
|
@param {Model} typeClass
|
|
1009
972
|
@param {Snapshot} snapshot
|
|
@@ -1018,7 +981,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
1018
981
|
For example if you wanted to ensure all your attributes were always
|
|
1019
982
|
serialized as properties on an `attributes` object you could
|
|
1020
983
|
write:
|
|
1021
|
-
```app/serializers/application.js
|
|
984
|
+
```js [app/serializers/application.js]
|
|
1022
985
|
import JSONSerializer from '@ember-data-mirror/serializer/json';
|
|
1023
986
|
export default class ApplicationSerializer extends JSONSerializer {
|
|
1024
987
|
serializeAttribute(snapshot, json, key, attributes) {
|
|
@@ -1027,8 +990,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
1027
990
|
}
|
|
1028
991
|
}
|
|
1029
992
|
```
|
|
1030
|
-
@
|
|
1031
|
-
@public
|
|
993
|
+
@public
|
|
1032
994
|
@param {Snapshot} snapshot
|
|
1033
995
|
@param {Object} json
|
|
1034
996
|
@param {String} key
|
|
@@ -1057,7 +1019,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
1057
1019
|
`serializeBelongsTo` can be used to customize how `belongsTo`
|
|
1058
1020
|
properties are serialized.
|
|
1059
1021
|
Example
|
|
1060
|
-
```app/serializers/post.js
|
|
1022
|
+
```js [app/serializers/post.js]
|
|
1061
1023
|
import JSONSerializer from '@ember-data-mirror/serializer/json';
|
|
1062
1024
|
export default class PostSerializer extends JSONSerializer {
|
|
1063
1025
|
serializeBelongsTo(snapshot, json, relationship) {
|
|
@@ -1068,8 +1030,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
1068
1030
|
}
|
|
1069
1031
|
}
|
|
1070
1032
|
```
|
|
1071
|
-
@
|
|
1072
|
-
@public
|
|
1033
|
+
@public
|
|
1073
1034
|
@param {Snapshot} snapshot
|
|
1074
1035
|
@param {Object} json
|
|
1075
1036
|
@param {Object} relationship
|
|
@@ -1104,7 +1065,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
1104
1065
|
`serializeHasMany` can be used to customize how `hasMany`
|
|
1105
1066
|
properties are serialized.
|
|
1106
1067
|
Example
|
|
1107
|
-
```app/serializers/post.js
|
|
1068
|
+
```js [app/serializers/post.js]
|
|
1108
1069
|
import JSONSerializer from '@ember-data-mirror/serializer/json';
|
|
1109
1070
|
export default class PostSerializer extends JSONSerializer {
|
|
1110
1071
|
serializeHasMany(snapshot, json, relationship) {
|
|
@@ -1117,8 +1078,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
1117
1078
|
}
|
|
1118
1079
|
}
|
|
1119
1080
|
```
|
|
1120
|
-
|
|
1121
|
-
@public
|
|
1081
|
+
@public
|
|
1122
1082
|
@param {Snapshot} snapshot
|
|
1123
1083
|
@param {Object} json
|
|
1124
1084
|
@param {Object} relationship
|
|
@@ -1148,7 +1108,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
1148
1108
|
`{ polymorphic: true }` is pass as the second argument to the
|
|
1149
1109
|
`belongsTo` function.
|
|
1150
1110
|
Example
|
|
1151
|
-
```app/serializers/comment.js
|
|
1111
|
+
```js [app/serializers/comment.js]
|
|
1152
1112
|
import JSONSerializer from '@ember-data-mirror/serializer/json';
|
|
1153
1113
|
export default class CommentSerializer extends JSONSerializer {
|
|
1154
1114
|
serializePolymorphicType(snapshot, json, relationship) {
|
|
@@ -1163,8 +1123,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
1163
1123
|
}
|
|
1164
1124
|
}
|
|
1165
1125
|
```
|
|
1166
|
-
@
|
|
1167
|
-
@public
|
|
1126
|
+
@public
|
|
1168
1127
|
@param {Snapshot} snapshot
|
|
1169
1128
|
@param {Object} json
|
|
1170
1129
|
@param {Object} relationship
|
|
@@ -1175,7 +1134,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
1175
1134
|
adapter payload. By default Ember Data expects meta information to
|
|
1176
1135
|
be located on the `meta` property of the payload object.
|
|
1177
1136
|
Example
|
|
1178
|
-
```app/serializers/post.js
|
|
1137
|
+
```js [app/serializers/post.js]
|
|
1179
1138
|
import JSONSerializer from '@ember-data-mirror/serializer/json';
|
|
1180
1139
|
export default class PostSerializer extends JSONSerializer {
|
|
1181
1140
|
extractMeta(store, typeClass, payload) {
|
|
@@ -1187,8 +1146,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
1187
1146
|
}
|
|
1188
1147
|
}
|
|
1189
1148
|
```
|
|
1190
|
-
@
|
|
1191
|
-
@public
|
|
1149
|
+
@public
|
|
1192
1150
|
@param {Store} store
|
|
1193
1151
|
@param {Model} modelClass
|
|
1194
1152
|
@param {Object} payload
|
|
@@ -1254,7 +1212,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
1254
1212
|
```
|
|
1255
1213
|
Example of alternative implementation, overriding the default
|
|
1256
1214
|
behavior to deal with a different format of errors:
|
|
1257
|
-
```app/serializers/post.js
|
|
1215
|
+
```js [app/serializers/post.js]
|
|
1258
1216
|
import JSONSerializer from '@ember-data-mirror/serializer/json';
|
|
1259
1217
|
export default class PostSerializer extends JSONSerializer {
|
|
1260
1218
|
extractErrors(store, typeClass, payload, id) {
|
|
@@ -1266,8 +1224,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
1266
1224
|
}
|
|
1267
1225
|
}
|
|
1268
1226
|
```
|
|
1269
|
-
@
|
|
1270
|
-
@public
|
|
1227
|
+
@public
|
|
1271
1228
|
@param {Store} store
|
|
1272
1229
|
@param {Model} typeClass
|
|
1273
1230
|
@param {Object} payload
|
|
@@ -1320,7 +1277,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
1320
1277
|
`keyForAttribute` can be used to define rules for how to convert an
|
|
1321
1278
|
attribute name in your model to a key in your JSON.
|
|
1322
1279
|
Example
|
|
1323
|
-
```app/serializers/application.js
|
|
1280
|
+
```js [app/serializers/application.js]
|
|
1324
1281
|
import JSONSerializer from '@ember-data-mirror/serializer/json';
|
|
1325
1282
|
import { underscore } from '<app-name>/utils/string-utils';
|
|
1326
1283
|
export default class ApplicationSerializer extends JSONSerializer {
|
|
@@ -1329,8 +1286,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
1329
1286
|
}
|
|
1330
1287
|
}
|
|
1331
1288
|
```
|
|
1332
|
-
@
|
|
1333
|
-
@public
|
|
1289
|
+
@public
|
|
1334
1290
|
@param {String} key
|
|
1335
1291
|
@param {String} method
|
|
1336
1292
|
@return {String} normalized key
|
|
@@ -1343,7 +1299,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
1343
1299
|
serializing and deserializing relationship properties. By default
|
|
1344
1300
|
`JSONSerializer` does not provide an implementation of this method.
|
|
1345
1301
|
Example
|
|
1346
|
-
```app/serializers/post.js
|
|
1302
|
+
```js [app/serializers/post.js]
|
|
1347
1303
|
import JSONSerializer from '@ember-data-mirror/serializer/json';
|
|
1348
1304
|
import { underscore } from '<app-name>/utils/string-utils';
|
|
1349
1305
|
export default class PostSerializer extends JSONSerializer {
|
|
@@ -1352,8 +1308,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
1352
1308
|
}
|
|
1353
1309
|
}
|
|
1354
1310
|
```
|
|
1355
|
-
@
|
|
1356
|
-
@public
|
|
1311
|
+
@public
|
|
1357
1312
|
@param {String} key
|
|
1358
1313
|
@param {String} typeClass
|
|
1359
1314
|
@param {String} method
|
|
@@ -1365,8 +1320,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
1365
1320
|
/**
|
|
1366
1321
|
`keyForLink` can be used to define a custom key when deserializing link
|
|
1367
1322
|
properties.
|
|
1368
|
-
|
|
1369
|
-
@public
|
|
1323
|
+
@public
|
|
1370
1324
|
@param {String} key
|
|
1371
1325
|
@param {String} kind `belongsTo` or `hasMany`
|
|
1372
1326
|
@return {String} normalized key
|
|
@@ -1377,7 +1331,6 @@ const JSONSerializer = Serializer.extend({
|
|
|
1377
1331
|
// HELPERS
|
|
1378
1332
|
|
|
1379
1333
|
/**
|
|
1380
|
-
@method transformFor
|
|
1381
1334
|
@private
|
|
1382
1335
|
@param {String} attributeType
|
|
1383
1336
|
@param {Boolean} skipAssertion
|