@ember-data/serializer 5.4.0-alpha.30 → 5.4.0-alpha.31

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