@ember-data-mirror/serializer 5.4.0-alpha.49

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.
Files changed (58) hide show
  1. package/LICENSE.md +11 -0
  2. package/README.md +98 -0
  3. package/addon/-private.js +3 -0
  4. package/addon/-private.js.map +1 -0
  5. package/addon/embedded-records-mixin-QJe_8jrF.js +572 -0
  6. package/addon/embedded-records-mixin-QJe_8jrF.js.map +1 -0
  7. package/addon/index.js +181 -0
  8. package/addon/index.js.map +1 -0
  9. package/addon/json-api.js +508 -0
  10. package/addon/json-api.js.map +1 -0
  11. package/addon/json.js +1375 -0
  12. package/addon/json.js.map +1 -0
  13. package/addon/rest.js +684 -0
  14. package/addon/rest.js.map +1 -0
  15. package/addon/string-Juwz4cu0.js +345 -0
  16. package/addon/string-Juwz4cu0.js.map +1 -0
  17. package/addon/transform.js +1 -0
  18. package/addon/transform.js.map +1 -0
  19. package/addon/utils-NcVD2Jb5.js +12 -0
  20. package/addon/utils-NcVD2Jb5.js.map +1 -0
  21. package/addon-main.js +94 -0
  22. package/blueprints/serializer/files/__root__/__path__/__name__.js +4 -0
  23. package/blueprints/serializer/index.js +14 -0
  24. package/blueprints/serializer/native-files/__root__/__path__/__name__.js +4 -0
  25. package/blueprints/serializer-test/index.js +29 -0
  26. package/blueprints/serializer-test/qunit-files/__root__/__path__/__test__.js +24 -0
  27. package/blueprints/transform/files/__root__/__path__/__name__.js +13 -0
  28. package/blueprints/transform/index.js +7 -0
  29. package/blueprints/transform/native-files/__root__/__path__/__name__.js +13 -0
  30. package/blueprints/transform-test/index.js +29 -0
  31. package/blueprints/transform-test/qunit-files/__root__/__path__/__test__.js +13 -0
  32. package/package.json +113 -0
  33. package/unstable-preview-types/-private/embedded-records-mixin.d.ts +7 -0
  34. package/unstable-preview-types/-private/embedded-records-mixin.d.ts.map +1 -0
  35. package/unstable-preview-types/-private/transforms/boolean.d.ts +52 -0
  36. package/unstable-preview-types/-private/transforms/boolean.d.ts.map +1 -0
  37. package/unstable-preview-types/-private/transforms/date.d.ts +33 -0
  38. package/unstable-preview-types/-private/transforms/date.d.ts.map +1 -0
  39. package/unstable-preview-types/-private/transforms/number.d.ts +34 -0
  40. package/unstable-preview-types/-private/transforms/number.d.ts.map +1 -0
  41. package/unstable-preview-types/-private/transforms/string.d.ts +34 -0
  42. package/unstable-preview-types/-private/transforms/string.d.ts.map +1 -0
  43. package/unstable-preview-types/-private/transforms/transform.d.ts +128 -0
  44. package/unstable-preview-types/-private/transforms/transform.d.ts.map +1 -0
  45. package/unstable-preview-types/-private/utils.d.ts +6 -0
  46. package/unstable-preview-types/-private/utils.d.ts.map +1 -0
  47. package/unstable-preview-types/-private.d.ts +13 -0
  48. package/unstable-preview-types/-private.d.ts.map +1 -0
  49. package/unstable-preview-types/index.d.ts +278 -0
  50. package/unstable-preview-types/index.d.ts.map +1 -0
  51. package/unstable-preview-types/json-api.d.ts +515 -0
  52. package/unstable-preview-types/json-api.d.ts.map +1 -0
  53. package/unstable-preview-types/json.d.ts +1094 -0
  54. package/unstable-preview-types/json.d.ts.map +1 -0
  55. package/unstable-preview-types/rest.d.ts +602 -0
  56. package/unstable-preview-types/rest.d.ts.map +1 -0
  57. package/unstable-preview-types/transform.d.ts +7 -0
  58. package/unstable-preview-types/transform.d.ts.map +1 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../src/json.js"],"names":[],"mappings":";;AAgBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA4EE;AACF;IACE;;;;;;;;;;;;;;;;;;;;;;MAsBE;;IAGF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAkEE;sBADO,MAAM;IAIf;;;;;;;;;;;;MAYE;4CAFO,MAAM,GACL,MAAM;IAkBhB;;;;;;;;;;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;IAKF;;;;;;;;;MASE;;IAOF;;;;;;MAME;;EAQD;uBA/jDoB,GAAG"}
@@ -0,0 +1,602 @@
1
+ declare module '@ember-data-mirror/serializer/rest' {
2
+ /// <reference types="ember-source/types" />
3
+ export { EmbeddedRecordsMixin } from "./-private";
4
+ export default RESTSerializer;
5
+ /**
6
+ * <blockquote style="margin: 1em; padding: .1em 1em .1em 1em; border-left: solid 1em #E34C32; background: #e0e0e0;">
7
+ <p>
8
+ ⚠️ <strong>This is LEGACY documentation</strong> for a feature that is no longer encouraged to be used.
9
+ If starting a new app or thinking of implementing a new adapter, consider writing a
10
+ <a href="/ember-data/release/classes/%3CInterface%3E%20Handler">Handler</a> instead to be used with the <a href="https://github.com/emberjs/data/tree/main/packages/request#readme">RequestManager</a>
11
+ </p>
12
+ </blockquote>
13
+
14
+ Normally, applications will use the `RESTSerializer` by implementing
15
+ the `normalize` method.
16
+
17
+ This allows you to do whatever kind of munging you need and is
18
+ especially useful if your server is inconsistent and you need to
19
+ do munging differently for many different kinds of responses.
20
+
21
+ See the `normalize` documentation for more information.
22
+
23
+ ## Across the Board Normalization
24
+
25
+ There are also a number of hooks that you might find useful to define
26
+ across-the-board rules for your payload. These rules will be useful
27
+ if your server is consistent, or if you're building an adapter for
28
+ an infrastructure service, like Firebase, and want to encode service
29
+ conventions.
30
+
31
+ For example, if all of your keys are underscored and all-caps, but
32
+ otherwise consistent with the names you use in your models, you
33
+ can implement across-the-board rules for how to convert an attribute
34
+ name in your model to a key in your JSON.
35
+
36
+ ```app/serializers/application.js
37
+ import RESTSerializer from '@ember-data-mirror/serializer/rest';
38
+ import { underscore } from '<app-name>/utils/string-utils';
39
+
40
+ export default class ApplicationSerializer extends RESTSerializer {
41
+ keyForAttribute(attr, method) {
42
+ return underscore(attr).toUpperCase();
43
+ }
44
+ }
45
+ ```
46
+
47
+ You can also implement `keyForRelationship`, which takes the name
48
+ of the relationship as the first parameter, the kind of
49
+ relationship (`hasMany` or `belongsTo`) as the second parameter, and
50
+ the method (`serialize` or `deserialize`) as the third parameter.
51
+
52
+ @class RESTSerializer
53
+ @main @ember-data-mirror/serializer/rest
54
+ @public
55
+ @extends JSONSerializer
56
+ */
57
+ const RESTSerializer: Readonly<Readonly<typeof import("@ember-data-mirror/serializer").default> & (new (owner?: import("@ember/-internals/owner").default | undefined) => import(".").default) & {
58
+ primaryKey: string;
59
+ mergedProperties: Object;
60
+ applyTransforms(typeClass: Model, data: Object): Object;
61
+ normalizeResponse(store: Store, primaryModelClass: Model, payload: Object, id: string | number, requestType: string, ...args: any[]): Object;
62
+ normalizeFindRecordResponse(store: Store, primaryModelClass: Model, payload: Object, id: string | number, requestType: string, ...args: any[]): Object;
63
+ normalizeQueryRecordResponse(store: Store, primaryModelClass: Model, payload: Object, id: string | number, requestType: string, ...args: any[]): Object;
64
+ normalizeFindAllResponse(store: Store, primaryModelClass: Model, payload: Object, id: string | number, requestType: string, ...args: any[]): Object;
65
+ normalizeFindBelongsToResponse(store: Store, primaryModelClass: Model, payload: Object, id: string | number, requestType: string, ...args: any[]): Object; /**
66
+ This method allows you to push a payload containing top-level
67
+ collections of records organized per type.
68
+
69
+ ```js
70
+ {
71
+ "posts": [{
72
+ "id": "1",
73
+ "title": "Rails is omakase",
74
+ "author", "1",
75
+ "comments": [ "1" ]
76
+ }],
77
+ "comments": [{
78
+ "id": "1",
79
+ "body": "FIRST"
80
+ }],
81
+ "users": [{
82
+ "id": "1",
83
+ "name": "@d2h"
84
+ }]
85
+ }
86
+ ```
87
+
88
+ It will first normalize the payload, so you can use this to push
89
+ in data streaming in from your server structured the same way
90
+ that fetches and saves are structured.
91
+
92
+ @method pushPayload
93
+ @public
94
+ @param {Store} store
95
+ @param {Object} payload
96
+ */
97
+ normalizeFindHasManyResponse(store: Store, primaryModelClass: Model, payload: Object, id: string | number, requestType: string, ...args: any[]): Object;
98
+ normalizeFindManyResponse(store: Store, primaryModelClass: Model, payload: Object, id: string | number, requestType: string, ...args: any[]): Object;
99
+ normalizeQueryResponse(store: Store, primaryModelClass: Model, payload: Object, id: string | number, requestType: string, ...args: any[]): Object;
100
+ normalizeCreateRecordResponse(store: Store, primaryModelClass: Model, payload: Object, id: string | number, requestType: string, ...args: any[]): Object;
101
+ normalizeDeleteRecordResponse(store: Store, primaryModelClass: Model, payload: Object, id: string | number, requestType: string, ...args: any[]): Object;
102
+ normalizeUpdateRecordResponse(store: Store, primaryModelClass: Model, payload: Object, id: string | number, requestType: string, ...args: any[]): Object;
103
+ normalizeSaveResponse(store: Store, primaryModelClass: Model, payload: Object, id: string | number, requestType: string, ...args: any[]): Object;
104
+ normalizeSingleResponse(store: Store, primaryModelClass: Model, payload: Object, id: string | number, requestType: string): Object;
105
+ normalizeArrayResponse(store: Store, primaryModelClass: Model, payload: Object, id: string | number, requestType: string): Object;
106
+ _normalizeResponse(store: Store, primaryModelClass: Model, payload: Object, id: string | number, requestType: string, isSingle: boolean): Object;
107
+ normalize(modelClass: any, resourceHash: any): Object;
108
+ extractId(modelClass: Object, resourceHash: Object): string;
109
+ extractAttributes(modelClass: Object, resourceHash: Object): Object;
110
+ extractRelationship(relationshipModelName: Object, relationshipHash: Object): Object;
111
+ extractPolymorphicRelationship(relationshipModelName: Object, relationshipHash: Object, relationshipOptions: Object): Object;
112
+ extractRelationships(modelClass: Object, resourceHash: Object): Object;
113
+ modelNameFromPayloadKey(key: string): string;
114
+ normalizeRelationships(typeClass: any, hash: any): void;
115
+ normalizeUsingDeclaredMapping(modelClass: any, hash: any): void;
116
+ _getMappedKey(key: string, modelClass: any): string;
117
+ _canSerialize(key: string): boolean;
118
+ _mustSerialize(key: string): boolean;
119
+ shouldSerializeHasMany(snapshot: Snapshot, key: string, relationship: RelationshipSchema): boolean;
120
+ serialize(snapshot: Snapshot, options: Object): Object;
121
+ serializeIntoHash(hash: Object, typeClass: Model, snapshot: Snapshot, options: Object): void;
122
+ serializeAttribute(snapshot: Snapshot, json: Object, key: string, attribute: Object): void;
123
+ serializeBelongsTo(snapshot: Snapshot, json: Object, relationship: Object): void;
124
+ serializeHasMany(snapshot: Snapshot, json: Object, relationship: Object): void;
125
+ serializePolymorphicType(): void;
126
+ extractMeta(store: Store, modelClass: Model, payload: Object): any;
127
+ extractErrors(store: Store, typeClass: Model, payload: Object, id: string | number): Object;
128
+ keyForAttribute(key: string, method: string): string;
129
+ keyForRelationship(key: string, typeClass: string, method: string): string;
130
+ keyForLink(key: string, kind: string): string;
131
+ transformFor(attributeType: string, skipAssertion: boolean): Transform;
132
+ }> & (new (owner?: import("@ember-data-mirror/serializer/@ember/-internals/owner").default | undefined) => import(".").default) & {
133
+ /**
134
+ `keyForPolymorphicType` can be used to define a custom key when
135
+ serializing and deserializing a polymorphic type. By default, the
136
+ returned key is `${key}Type`.
137
+
138
+ Example
139
+
140
+ ```app/serializers/post.js
141
+ import RESTSerializer from '@ember-data-mirror/serializer/rest';
142
+
143
+ export default class ApplicationSerializer extends RESTSerializer {
144
+ keyForPolymorphicType(key, relationship) {
145
+ let relationshipKey = this.keyForRelationship(key);
146
+
147
+ return 'type-' + relationshipKey;
148
+ }
149
+ }
150
+ ```
151
+
152
+ @method keyForPolymorphicType
153
+ @public
154
+ @param {String} key
155
+ @param {String} typeClass
156
+ @param {String} method
157
+ @return {String} normalized key
158
+ */
159
+ keyForPolymorphicType(key: string, typeClass: string, method: string): string;
160
+ /**
161
+ Normalizes a part of the JSON payload returned by
162
+ the server. You should override this method, munge the hash
163
+ and call super if you have generic normalization to do.
164
+
165
+ It takes the type of the record that is being normalized
166
+ (as a Model class), the property where the hash was
167
+ originally found, and the hash to normalize.
168
+
169
+ For example, if you have a payload that looks like this:
170
+
171
+ ```js
172
+ {
173
+ "post": {
174
+ "id": 1,
175
+ "title": "Rails is omakase",
176
+ "comments": [ 1, 2 ]
177
+ },
178
+ "comments": [{
179
+ "id": 1,
180
+ "body": "FIRST"
181
+ }, {
182
+ "id": 2,
183
+ "body": "Rails is unagi"
184
+ }]
185
+ }
186
+ ```
187
+
188
+ The `normalize` method will be called three times:
189
+
190
+ * With `App.Post`, `"posts"` and `{ id: 1, title: "Rails is omakase", ... }`
191
+ * With `App.Comment`, `"comments"` and `{ id: 1, body: "FIRST" }`
192
+ * With `App.Comment`, `"comments"` and `{ id: 2, body: "Rails is unagi" }`
193
+
194
+ You can use this method, for example, to normalize underscored keys to camelized
195
+ or other general-purpose normalizations. You will only need to implement
196
+ `normalize` and manipulate the payload as desired.
197
+
198
+ For example, if the `IDs` under `"comments"` are provided as `_id` instead of
199
+ `id`, you can specify how to normalize just the comments:
200
+
201
+ ```app/serializers/post.js
202
+ import RESTSerializer from '@ember-data-mirror/serializer/rest';
203
+
204
+ export default class ApplicationSerializer extends RESTSerializer {
205
+ normalize(model, hash, prop) {
206
+ if (prop === 'comments') {
207
+ hash.id = hash._id;
208
+ delete hash._id;
209
+ }
210
+
211
+ return super.normalize(...arguments);
212
+ }
213
+ }
214
+ ```
215
+
216
+ On each call to the `normalize` method, the third parameter (`prop`) is always
217
+ one of the keys that were in the original payload or in the result of another
218
+ normalization as `normalizeResponse`.
219
+
220
+ @method normalize
221
+ @public
222
+ @param {Model} modelClass
223
+ @param {Object} resourceHash
224
+ @param {String} prop
225
+ @return {Object}
226
+ */
227
+ /**
228
+ Normalizes an array of resource payloads and returns a JSON-API Document
229
+ with primary data and, if any, included data as `{ data, included }`.
230
+
231
+ @method _normalizeArray
232
+ @param {Store} store
233
+ @param {String} modelName
234
+ @param {Object} arrayHash
235
+ @param {String} prop
236
+ @return {Object}
237
+ @private
238
+ */
239
+ _normalizeArray(store: Store, modelName: string, arrayHash: Object, prop: string): Object;
240
+ _normalizePolymorphicRecord(store: any, hash: any, prop: any, primaryModelClass: any, primarySerializer: any): any;
241
+ /**
242
+ @method _normalizeResponse
243
+ @param {Store} store
244
+ @param {Model} primaryModelClass
245
+ @param {Object} payload
246
+ @param {String|Number} id
247
+ @param {String} requestType
248
+ @param {Boolean} isSingle
249
+ @return {Object} JSON-API Document
250
+ @private
251
+ */
252
+ _normalizeResponse(store: Store, primaryModelClass: Model, payload: Object, id: string | number, requestType: string, isSingle: boolean): Object;
253
+ isPrimaryType(store: any, modelName: any, primaryModelClass: any): boolean;
254
+ /**
255
+ This method allows you to push a payload containing top-level
256
+ collections of records organized per type.
257
+
258
+ ```js
259
+ {
260
+ "posts": [{
261
+ "id": "1",
262
+ "title": "Rails is omakase",
263
+ "author", "1",
264
+ "comments": [ "1" ]
265
+ }],
266
+ "comments": [{
267
+ "id": "1",
268
+ "body": "FIRST"
269
+ }],
270
+ "users": [{
271
+ "id": "1",
272
+ "name": "@d2h"
273
+ }]
274
+ }
275
+ ```
276
+
277
+ It will first normalize the payload, so you can use this to push
278
+ in data streaming in from your server structured the same way
279
+ that fetches and saves are structured.
280
+
281
+ @method pushPayload
282
+ @public
283
+ @param {Store} store
284
+ @param {Object} payload
285
+ */
286
+ pushPayload(store: Store, payload: Object): void;
287
+ /**
288
+ This method is used to convert each JSON root key in the payload
289
+ into a modelName that it can use to look up the appropriate model for
290
+ that part of the payload.
291
+
292
+ For example, your server may send a model name that does not correspond with
293
+ the name of the model in your app. Let's take a look at an example model,
294
+ and an example payload:
295
+
296
+ ```app/models/post.js
297
+ import Model from '@ember-data-mirror/model';
298
+
299
+ export default class Post extends Model {}
300
+ ```
301
+
302
+ ```javascript
303
+ {
304
+ "blog/post": {
305
+ "id": "1
306
+ }
307
+ }
308
+ ```
309
+
310
+ Ember Data is going to normalize the payload's root key for the modelName. As a result,
311
+ it will try to look up the "blog/post" model. Since we don't have a model called "blog/post"
312
+ (or a file called app/models/blog/post.js in ember-cli), Ember Data will throw an error
313
+ because it cannot find the "blog/post" model.
314
+
315
+ Since we want to remove this namespace, we can define a serializer for the application that will
316
+ remove "blog/" from the payload key whenver it's encountered by Ember Data:
317
+
318
+ ```app/serializers/application.js
319
+ import RESTSerializer from '@ember-data-mirror/serializer/rest';
320
+
321
+ export default class ApplicationSerializer extends RESTSerializer {
322
+ modelNameFromPayloadKey(payloadKey) {
323
+ if (payloadKey === 'blog/post') {
324
+ return super.modelNameFromPayloadKey(payloadKey.replace('blog/', ''));
325
+ } else {
326
+ return super.modelNameFromPayloadKey(payloadKey);
327
+ }
328
+ }
329
+ }
330
+ ```
331
+
332
+ After refreshing, Ember Data will appropriately look up the "post" model.
333
+
334
+ By default the modelName for a model is its
335
+ name in dasherized form. This means that a payload key like "blogPost" would be
336
+ normalized to "blog-post" when Ember Data looks up the model. Usually, Ember Data
337
+ can use the correct inflection to do this for you. Most of the time, you won't
338
+ need to override `modelNameFromPayloadKey` for this purpose.
339
+
340
+ @method modelNameFromPayloadKey
341
+ @public
342
+ @param {String} key
343
+ @return {String} the model's modelName
344
+ */
345
+ modelNameFromPayloadKey(key: string): string;
346
+ /**
347
+ Called when a record is saved in order to convert the
348
+ record into JSON.
349
+
350
+ By default, it creates a JSON object with a key for
351
+ each attribute and belongsTo relationship.
352
+
353
+ For example, consider this model:
354
+
355
+ ```app/models/comment.js
356
+ import Model, { attr, belongsTo } from '@ember-data-mirror/model';
357
+
358
+ export default class Comment extends Model {
359
+ @attr title
360
+ @attr body
361
+
362
+ @belongsTo('user') author
363
+ }
364
+ ```
365
+
366
+ The default serialization would create a JSON object like:
367
+
368
+ ```js
369
+ {
370
+ "title": "Rails is unagi",
371
+ "body": "Rails? Omakase? O_O",
372
+ "author": 12
373
+ }
374
+ ```
375
+
376
+ By default, attributes are passed through as-is, unless
377
+ you specified an attribute type (`attr('date')`). If
378
+ you specify a transform, the JavaScript value will be
379
+ serialized when inserted into the JSON hash.
380
+
381
+ By default, belongs-to relationships are converted into
382
+ IDs when inserted into the JSON hash.
383
+
384
+ ## IDs
385
+
386
+ `serialize` takes an options hash with a single option:
387
+ `includeId`. If this option is `true`, `serialize` will,
388
+ by default include the ID in the JSON object it builds.
389
+
390
+ The adapter passes in `includeId: true` when serializing
391
+ a record for `createRecord`, but not for `updateRecord`.
392
+
393
+ ## Customization
394
+
395
+ Your server may expect a different JSON format than the
396
+ built-in serialization format.
397
+
398
+ In that case, you can implement `serialize` yourself and
399
+ return a JSON hash of your choosing.
400
+
401
+ ```app/serializers/post.js
402
+ import RESTSerializer from '@ember-data-mirror/serializer/rest';
403
+
404
+ export default class ApplicationSerializer extends RESTSerializer {
405
+ serialize(snapshot, options) {
406
+ let json = {
407
+ POST_TTL: snapshot.attr('title'),
408
+ POST_BDY: snapshot.attr('body'),
409
+ POST_CMS: snapshot.hasMany('comments', { ids: true })
410
+ };
411
+
412
+ if (options.includeId) {
413
+ json.POST_ID_ = snapshot.id;
414
+ }
415
+
416
+ return json;
417
+ }
418
+ }
419
+ ```
420
+
421
+ ## Customizing an App-Wide Serializer
422
+
423
+ If you want to define a serializer for your entire
424
+ application, you'll probably want to use `eachAttribute`
425
+ and `eachRelationship` on the record.
426
+
427
+ ```app/serializers/application.js
428
+ import RESTSerializer from '@ember-data-mirror/serializer/rest';
429
+ import { pluralize } from '<app-name>/utils/string-utils';
430
+
431
+ export default class ApplicationSerializer extends RESTSerializer {
432
+ serialize(snapshot, options) {
433
+ let json = {};
434
+
435
+ snapshot.eachAttribute(function(name) {
436
+ json[serverAttributeName(name)] = snapshot.attr(name);
437
+ });
438
+
439
+ snapshot.eachRelationship(function(name, relationship) {
440
+ if (relationship.kind === 'hasMany') {
441
+ json[serverHasManyName(name)] = snapshot.hasMany(name, { ids: true });
442
+ }
443
+ });
444
+
445
+ if (options.includeId) {
446
+ json.ID_ = snapshot.id;
447
+ }
448
+
449
+ return json;
450
+ }
451
+ }
452
+
453
+ function serverAttributeName(attribute) {
454
+ return attribute.underscore().toUpperCase();
455
+ }
456
+
457
+ function serverHasManyName(name) {
458
+ return serverAttributeName(singularize(name)) + "_IDS";
459
+ }
460
+ ```
461
+
462
+ This serializer will generate JSON that looks like this:
463
+
464
+ ```js
465
+ {
466
+ "TITLE": "Rails is omakase",
467
+ "BODY": "Yep. Omakase.",
468
+ "COMMENT_IDS": [ 1, 2, 3 ]
469
+ }
470
+ ```
471
+
472
+ ## Tweaking the Default JSON
473
+
474
+ If you just want to do some small tweaks on the default JSON,
475
+ you can call super first and make the tweaks on the returned
476
+ JSON.
477
+
478
+ ```app/serializers/post.js
479
+ import RESTSerializer from '@ember-data-mirror/serializer/rest';
480
+
481
+ export default class ApplicationSerializer extends RESTSerializer {
482
+ serialize(snapshot, options) {
483
+ let json = super.serialize(snapshot, options);
484
+
485
+ json.subject = json.title;
486
+ delete json.title;
487
+
488
+ return json;
489
+ }
490
+ }
491
+ ```
492
+
493
+ @method serialize
494
+ @public
495
+ @param {Snapshot} snapshot
496
+ @param {Object} options
497
+ @return {Object} json
498
+ */
499
+ serialize(snapshot: Snapshot, options: Object, ...args: any[]): Object;
500
+ /**
501
+ You can use this method to customize the root keys serialized into the JSON.
502
+ The hash property should be modified by reference (possibly using something like _.extend)
503
+ By default the REST Serializer sends the modelName of a model, which is a camelized
504
+ version of the name.
505
+
506
+ For example, your server may expect underscored root objects.
507
+
508
+ ```app/serializers/application.js
509
+ import RESTSerializer from '@ember-data-mirror/serializer/rest';
510
+ import { decamelize } from '<app-name>/utils/string-utils';
511
+
512
+ export default class ApplicationSerializer extends RESTSerializer {
513
+ serializeIntoHash(data, type, record, options) {
514
+ let root = decamelize(type.modelName);
515
+ data[root] = this.serialize(record, options);
516
+ }
517
+ }
518
+ ```
519
+
520
+ @method serializeIntoHash
521
+ @public
522
+ @param {Object} hash
523
+ @param {Model} typeClass
524
+ @param {Snapshot} snapshot
525
+ @param {Object} options
526
+ */
527
+ serializeIntoHash(hash: Object, typeClass: Model, snapshot: Snapshot, options: Object): void;
528
+ /**
529
+ You can use `payloadKeyFromModelName` to override the root key for an outgoing
530
+ request. By default, the RESTSerializer returns a camelized version of the
531
+ model's name.
532
+
533
+ For a model called TacoParty, its `modelName` would be the string `taco-party`. The RESTSerializer
534
+ will send it to the server with `tacoParty` as the root key in the JSON payload:
535
+
536
+ ```js
537
+ {
538
+ "tacoParty": {
539
+ "id": "1",
540
+ "location": "Matthew Beale's House"
541
+ }
542
+ }
543
+ ```
544
+
545
+ For example, your server may expect dasherized root objects:
546
+
547
+ ```app/serializers/application.js
548
+ import RESTSerializer from '@ember-data-mirror/serializer/rest';
549
+ import { dasherize } from '<app-name>/utils/string-utils';
550
+
551
+ export default class ApplicationSerializer extends RESTSerializer {
552
+ payloadKeyFromModelName(modelName) {
553
+ return dasherize(modelName);
554
+ }
555
+ }
556
+ ```
557
+
558
+ Given a `TacoParty` model, calling `save` on it would produce an outgoing
559
+ request like:
560
+
561
+ ```js
562
+ {
563
+ "taco-party": {
564
+ "id": "1",
565
+ "location": "Matthew Beale's House"
566
+ }
567
+ }
568
+ ```
569
+
570
+ @method payloadKeyFromModelName
571
+ @public
572
+ @param {String} modelName
573
+ @return {String}
574
+ */
575
+ payloadKeyFromModelName(modelName: string): string;
576
+ /**
577
+ You can use this method to customize how polymorphic objects are serialized.
578
+ By default the REST Serializer creates the key by appending `Type` to
579
+ the attribute and value from the model's camelcased model name.
580
+
581
+ @method serializePolymorphicType
582
+ @public
583
+ @param {Snapshot} snapshot
584
+ @param {Object} json
585
+ @param {Object} relationship
586
+ */
587
+ serializePolymorphicType(snapshot: Snapshot, json: Object, relationship: Object): void;
588
+ /**
589
+ You can use this method to customize how a polymorphic relationship should
590
+ be extracted.
591
+
592
+ @method extractPolymorphicRelationship
593
+ @public
594
+ @param {Object} relationshipType
595
+ @param {Object} relationshipHash
596
+ @param {Object} relationshipOptions
597
+ @return {Object}
598
+ */
599
+ extractPolymorphicRelationship(relationshipType: Object, relationshipHash: Object, relationshipOptions: Object, ...args: any[]): Object;
600
+ };
601
+ }
602
+ //# sourceMappingURL=rest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rest.d.ts","sourceRoot":"","sources":["../src/rest.js"],"names":[],"mappings":";;;AAiBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmDE;AACF;;;;;;;;+JAsSE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MA+BE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IApUF;;;;;;;;;;;;;;;;;;;;;;;;;MAyBE;;IAOF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAkEE;IAEF;;;;;;;;;;;MAWE;gEAJQ,MAAM,iBAEL,MAAM;;IA0CjB;;;;;;;;;;MAUE;wEANQ,MAAM,MACN,eAAa,2CAGZ,MAAM;;IAsIjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MA+BE;uCADQ,MAAM;IA+BhB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAyDE;;IAOF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAwJE;2CAFQ,MAAM,mBACL,MAAM;IAMjB;;;;;;;;;;;;;;;;;;;;;;;;;;MA0BE;4BAJQ,MAAM,iDAGN,MAAM;IAOhB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MA8CE;;IAKF;;;;;;;;;;MAUE;uDAFQ,MAAM,gBACN,MAAM;IAchB;;;;;;;;;;OAUG;qDAJO,MAAM,oBACN,MAAM,uBACN,MAAM,mBACL,MAAM;EAmChB"}
@@ -0,0 +1,7 @@
1
+ declare module '@ember-data-mirror/serializer/transform' {
2
+ /**
3
+ @module @ember-data-mirror/serializer
4
+ */
5
+ export { Transform as default, BooleanTransform, DateTransform, NumberTransform, StringTransform } from '@ember-data-mirror/serializer/-private';
6
+ }
7
+ //# sourceMappingURL=transform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../src/transform.ts"],"names":[],"mappings":"AAAA;;EAEE;AACF,OAAO,EAAE,SAAS,IAAI,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC"}