@ember-data/serializer 5.4.0-beta.3 → 5.4.0-beta.5

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