@ember-data-types/serializer 5.6.0-alpha.5 → 5.6.0-beta.1

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