@ember-data/serializer 5.4.0-alpha.32 → 5.4.0-alpha.33

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.
@@ -1,1092 +1,1094 @@
1
- /// <reference types="ember-source/types" />
2
- export default JSONSerializer;
3
- /**
4
- * <blockquote style="margin: 1em; padding: .1em 1em .1em 1em; border-left: solid 1em #E34C32; background: #e0e0e0;">
5
- <p>
6
- ⚠️ <strong>This is LEGACY documentation</strong> for a feature that is no longer encouraged to be used.
7
- If starting a new app or thinking of implementing a new adapter, consider writing a
8
- <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>
9
- </p>
10
- </blockquote>
11
-
12
- In EmberData a Serializer is used to serialize and deserialize
13
- records when they are transferred in and out of an external source.
14
- This process involves normalizing property names, transforming
15
- attribute values and serializing relationships.
16
-
17
- By default, EmberData uses and recommends the `JSONAPISerializer`.
18
-
19
- `JSONSerializer` is useful for simpler or legacy backends that may
20
- not support the http://jsonapi.org/ spec.
21
-
22
- For example, given the following `User` model and JSON payload:
23
-
24
- ```app/models/user.js
25
- import Model, { attr, belongsTo, hasMany } from '@ember-data/model';
26
-
27
- export default class UserModel extends Model {
28
- @hasMany('user') friends;
29
- @belongsTo('location') house;
30
-
31
- @attr('string') name;
32
- }
33
- ```
34
-
35
- ```js
36
- {
37
- id: 1,
38
- name: 'Sebastian',
39
- friends: [3, 4],
40
- links: {
41
- house: '/houses/lefkada'
1
+ declare module '@ember-data/serializer/json' {
2
+ /// <reference types="ember-source/types" />
3
+ export default JSONSerializer;
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
+ In EmberData a Serializer is used to serialize and deserialize
14
+ records when they are transferred in and out of an external source.
15
+ This process involves normalizing property names, transforming
16
+ attribute values and serializing relationships.
17
+
18
+ By default, EmberData uses and recommends the `JSONAPISerializer`.
19
+
20
+ `JSONSerializer` is useful for simpler or legacy backends that may
21
+ not support the http://jsonapi.org/ spec.
22
+
23
+ For example, given the following `User` model and JSON payload:
24
+
25
+ ```app/models/user.js
26
+ import Model, { attr, belongsTo, hasMany } from '@ember-data/model';
27
+
28
+ export default class UserModel extends Model {
29
+ @hasMany('user') friends;
30
+ @belongsTo('location') house;
31
+
32
+ @attr('string') name;
42
33
  }
43
- }
44
- ```
45
-
46
- `JSONSerializer` will normalize the JSON payload to the JSON API format that the
47
- Ember Data store expects.
48
-
49
- You can customize how JSONSerializer processes its payload by passing options in
50
- the `attrs` hash or by subclassing the `JSONSerializer` and overriding hooks:
51
-
52
- - To customize how a single record is normalized, use the `normalize` hook.
53
- - To customize how `JSONSerializer` normalizes the whole server response, use the
54
- `normalizeResponse` hook.
55
- - To customize how `JSONSerializer` normalizes a specific response from the server,
56
- use one of the many specific `normalizeResponse` hooks.
57
- - To customize how `JSONSerializer` normalizes your id, attributes or relationships,
58
- use the `extractId`, `extractAttributes` and `extractRelationships` hooks.
59
-
60
- The `JSONSerializer` normalization process follows these steps:
61
-
62
- 1. `normalizeResponse`
63
- - entry method to the serializer.
64
- 2. `normalizeCreateRecordResponse`
65
- - a `normalizeResponse` for a specific operation is called.
66
- 3. `normalizeSingleResponse`|`normalizeArrayResponse`
67
- - for methods like `createRecord` we expect a single record back, while for methods like `findAll` we expect multiple records back.
68
- 4. `normalize`
69
- - `normalizeArrayResponse` iterates and calls `normalize` for each of its records while `normalizeSingle`
70
- calls it once. This is the method you most likely want to subclass.
71
- 5. `extractId` | `extractAttributes` | `extractRelationships`
72
- - `normalize` delegates to these methods to
73
- turn the record payload into the JSON API format.
74
-
75
- @main @ember-data/serializer/json
76
- @class JSONSerializer
77
- @public
78
- @extends Serializer
79
- */
80
- declare const JSONSerializer: Readonly<typeof Serializer> & (new (owner?: import("@ember/-internals/owner").default | undefined) => Serializer) & {
81
- /**
82
- The `primaryKey` is used when serializing and deserializing
83
- data. Ember Data always uses the `id` property to store the id of
84
- the record. The external source may not always follow this
85
- convention. In these cases it is useful to override the
86
- `primaryKey` property to match the `primaryKey` of your external
87
- store.
88
-
89
- Example
90
-
91
- ```app/serializers/application.js
92
- import JSONSerializer from '@ember-data/serializer/json';
93
-
94
- export default class ApplicationSerializer extends JSONSerializer {
95
- primaryKey = '_id'
96
- }
97
- ```
98
-
99
- @property primaryKey
100
- @type {String}
101
- @public
102
- @default 'id'
103
- */
104
- primaryKey: string;
105
- /**
106
- The `attrs` object can be used to declare a simple mapping between
107
- property names on `Model` records and payload keys in the
108
- serialized JSON object representing the record. An object with the
109
- property `key` can also be used to designate the attribute's key on
110
- the response payload.
111
-
112
- Example
113
-
114
- ```app/models/person.js
115
- import Model, { attr } from '@ember-data/model';
116
-
117
- export default class PersonModel extends Model {
118
- @attr('string') firstName;
119
- @attr('string') lastName;
120
- @attr('string') occupation;
121
- @attr('boolean') admin;
34
+ ```
35
+
36
+ ```js
37
+ {
38
+ id: 1,
39
+ name: 'Sebastian',
40
+ friends: [3, 4],
41
+ links: {
42
+ house: '/houses/lefkada'
122
43
  }
123
- ```
124
-
125
- ```app/serializers/person.js
126
- import JSONSerializer from '@ember-data/serializer/json';
127
-
128
- export default class PersonSerializer extends JSONSerializer {
129
- attrs = {
130
- admin: 'is_admin',
131
- occupation: { key: 'career' }
44
+ }
45
+ ```
46
+
47
+ `JSONSerializer` will normalize the JSON payload to the JSON API format that the
48
+ Ember Data store expects.
49
+
50
+ You can customize how JSONSerializer processes its payload by passing options in
51
+ the `attrs` hash or by subclassing the `JSONSerializer` and overriding hooks:
52
+
53
+ - To customize how a single record is normalized, use the `normalize` hook.
54
+ - To customize how `JSONSerializer` normalizes the whole server response, use the
55
+ `normalizeResponse` hook.
56
+ - To customize how `JSONSerializer` normalizes a specific response from the server,
57
+ use one of the many specific `normalizeResponse` hooks.
58
+ - To customize how `JSONSerializer` normalizes your id, attributes or relationships,
59
+ use the `extractId`, `extractAttributes` and `extractRelationships` hooks.
60
+
61
+ The `JSONSerializer` normalization process follows these steps:
62
+
63
+ 1. `normalizeResponse`
64
+ - entry method to the serializer.
65
+ 2. `normalizeCreateRecordResponse`
66
+ - a `normalizeResponse` for a specific operation is called.
67
+ 3. `normalizeSingleResponse`|`normalizeArrayResponse`
68
+ - for methods like `createRecord` we expect a single record back, while for methods like `findAll` we expect multiple records back.
69
+ 4. `normalize`
70
+ - `normalizeArrayResponse` iterates and calls `normalize` for each of its records while `normalizeSingle`
71
+ calls it once. This is the method you most likely want to subclass.
72
+ 5. `extractId` | `extractAttributes` | `extractRelationships`
73
+ - `normalize` delegates to these methods to
74
+ turn the record payload into the JSON API format.
75
+
76
+ @main @ember-data/serializer/json
77
+ @class JSONSerializer
78
+ @public
79
+ @extends Serializer
80
+ */
81
+ declare const JSONSerializer: Readonly<typeof Serializer> & (new (owner?: import("@ember/-internals/owner").default | undefined) => Serializer) & {
82
+ /**
83
+ The `primaryKey` is used when serializing and deserializing
84
+ data. Ember Data always uses the `id` property to store the id of
85
+ the record. The external source may not always follow this
86
+ convention. In these cases it is useful to override the
87
+ `primaryKey` property to match the `primaryKey` of your external
88
+ store.
89
+
90
+ Example
91
+
92
+ ```app/serializers/application.js
93
+ import JSONSerializer from '@ember-data/serializer/json';
94
+
95
+ export default class ApplicationSerializer extends JSONSerializer {
96
+ primaryKey = '_id'
132
97
  }
133
- }
134
- ```
135
-
136
- You can also remove attributes and relationships by setting the `serialize`
137
- key to `false` in your mapping object.
138
-
139
- Example
140
-
141
- ```app/serializers/person.js
142
- import JSONSerializer from '@ember-data/serializer/json';
143
-
144
- export default class PostSerializer extends JSONSerializer {
145
- attrs = {
146
- admin: { serialize: false },
147
- occupation: { key: 'career' }
98
+ ```
99
+
100
+ @property primaryKey
101
+ @type {String}
102
+ @public
103
+ @default 'id'
104
+ */
105
+ primaryKey: string;
106
+ /**
107
+ The `attrs` object can be used to declare a simple mapping between
108
+ property names on `Model` records and payload keys in the
109
+ serialized JSON object representing the record. An object with the
110
+ property `key` can also be used to designate the attribute's key on
111
+ the response payload.
112
+
113
+ Example
114
+
115
+ ```app/models/person.js
116
+ import Model, { attr } from '@ember-data/model';
117
+
118
+ export default class PersonModel extends Model {
119
+ @attr('string') firstName;
120
+ @attr('string') lastName;
121
+ @attr('string') occupation;
122
+ @attr('boolean') admin;
148
123
  }
149
- }
150
- ```
151
-
152
- When serialized:
153
-
154
- ```javascript
155
- {
156
- "firstName": "Harry",
157
- "lastName": "Houdini",
158
- "career": "magician"
159
- }
160
- ```
161
-
162
- Note that the `admin` is now not included in the payload.
163
-
164
- Setting `serialize` to `true` enforces serialization for hasMany
165
- relationships even if it's neither a many-to-many nor many-to-none
166
- relationship.
167
-
168
- @property attrs
169
- @public
170
- @type {Object}
171
- */
172
- mergedProperties: Object;
173
- /**
174
- Given a subclass of `Model` and a JSON object this method will
175
- iterate through each attribute of the `Model` and invoke the
176
- `Transform#deserialize` method on the matching property of the
177
- JSON object. This method is typically called after the
178
- serializer's `normalize` method.
179
-
180
- @method applyTransforms
181
- @private
182
- @param {Model} typeClass
183
- @param {Object} data The data to transform
184
- @return {Object} data The transformed data object
185
- */
186
- applyTransforms(typeClass: Model, data: Object): Object;
187
- /**
188
- The `normalizeResponse` method is used to normalize a payload from the
189
- server to a JSON-API Document.
190
-
191
- http://jsonapi.org/format/#document-structure
192
-
193
- This method delegates to a more specific normalize method based on
194
- the `requestType`.
195
-
196
- To override this method with a custom one, make sure to call
197
- `return super.normalizeResponse(store, primaryModelClass, payload, id, requestType)` with your
198
- pre-processed data.
199
-
200
- Here's an example of using `normalizeResponse` manually:
201
-
202
- ```javascript
203
- socket.on('message', function(message) {
204
- let data = message.data;
205
- let modelClass = store.modelFor(data.modelName);
206
- let serializer = store.serializerFor(data.modelName);
207
- let normalized = serializer.normalizeSingleResponse(store, modelClass, data, data.id);
208
-
209
- store.push(normalized);
210
- });
211
- ```
212
-
213
- @since 1.13.0
214
- @method normalizeResponse
215
- @public
216
- @param {Store} store
217
- @param {Model} primaryModelClass
218
- @param {Object} payload
219
- @param {String|Number} id
220
- @param {String} requestType
221
- @return {Object} JSON-API Document
222
- */
223
- normalizeResponse(store: Store, primaryModelClass: Model, payload: Object, id: string | number, requestType: string, ...args: any[]): Object;
224
- /**
225
- Called by the default normalizeResponse implementation when the
226
- type of request is `findRecord`
227
-
228
- @since 1.13.0
229
- @method normalizeFindRecordResponse
230
- @public
231
- @param {Store} store
232
- @param {Model} primaryModelClass
233
- @param {Object} payload
234
- @param {String|Number} id
235
- @param {String} requestType
236
- @return {Object} JSON-API Document
237
- */
238
- normalizeFindRecordResponse(store: Store, primaryModelClass: Model, payload: Object, id: string | number, requestType: string, ...args: any[]): Object;
239
- /**
240
- Called by the default normalizeResponse implementation when the
241
- type of request is `queryRecord`
242
-
243
- @since 1.13.0
244
- @method normalizeQueryRecordResponse
245
- @public
246
- @param {Store} store
247
- @param {Model} primaryModelClass
248
- @param {Object} payload
249
- @param {String|Number} id
250
- @param {String} requestType
251
- @return {Object} JSON-API Document
252
- */
253
- normalizeQueryRecordResponse(store: Store, primaryModelClass: Model, payload: Object, id: string | number, requestType: string, ...args: any[]): Object;
254
- /**
255
- Called by the default normalizeResponse implementation when the
256
- type of request is `findAll`
257
-
258
- @since 1.13.0
259
- @method normalizeFindAllResponse
260
- @public
261
- @param {Store} store
262
- @param {Model} primaryModelClass
263
- @param {Object} payload
264
- @param {String|Number} id
265
- @param {String} requestType
266
- @return {Object} JSON-API Document
267
- */
268
- normalizeFindAllResponse(store: Store, primaryModelClass: Model, payload: Object, id: string | number, requestType: string, ...args: any[]): Object;
269
- /**
270
- Called by the default normalizeResponse implementation when the
271
- type of request is `findBelongsTo`
272
-
273
- @since 1.13.0
274
- @method normalizeFindBelongsToResponse
275
- @public
276
- @param {Store} store
277
- @param {Model} primaryModelClass
278
- @param {Object} payload
279
- @param {String|Number} id
280
- @param {String} requestType
281
- @return {Object} JSON-API Document
282
- */
283
- normalizeFindBelongsToResponse(store: Store, primaryModelClass: Model, payload: Object, id: string | number, requestType: string, ...args: any[]): Object;
284
- /**
285
- Called by the default normalizeResponse implementation when the
286
- type of request is `findHasMany`
287
-
288
- @since 1.13.0
289
- @method normalizeFindHasManyResponse
290
- @public
291
- @param {Store} store
292
- @param {Model} primaryModelClass
293
- @param {Object} payload
294
- @param {String|Number} id
295
- @param {String} requestType
296
- @return {Object} JSON-API Document
297
- */
298
- normalizeFindHasManyResponse(store: Store, primaryModelClass: Model, payload: Object, id: string | number, requestType: string, ...args: any[]): Object;
299
- /**
300
- Called by the default normalizeResponse implementation when the
301
- type of request is `findMany`
302
-
303
- @since 1.13.0
304
- @method normalizeFindManyResponse
305
- @public
306
- @param {Store} store
307
- @param {Model} primaryModelClass
308
- @param {Object} payload
309
- @param {String|Number} id
310
- @param {String} requestType
311
- @return {Object} JSON-API Document
312
- */
313
- normalizeFindManyResponse(store: Store, primaryModelClass: Model, payload: Object, id: string | number, requestType: string, ...args: any[]): Object;
314
- /**
315
- Called by the default normalizeResponse implementation when the
316
- type of request is `query`
317
-
318
- @since 1.13.0
319
- @method normalizeQueryResponse
320
- @public
321
- @param {Store} store
322
- @param {Model} primaryModelClass
323
- @param {Object} payload
324
- @param {String|Number} id
325
- @param {String} requestType
326
- @return {Object} JSON-API Document
327
- */
328
- normalizeQueryResponse(store: Store, primaryModelClass: Model, payload: Object, id: string | number, requestType: string, ...args: any[]): Object;
329
- /**
330
- Called by the default normalizeResponse implementation when the
331
- type of request is `createRecord`
332
-
333
- @since 1.13.0
334
- @method normalizeCreateRecordResponse
335
- @public
336
- @param {Store} store
337
- @param {Model} primaryModelClass
338
- @param {Object} payload
339
- @param {String|Number} id
340
- @param {String} requestType
341
- @return {Object} JSON-API Document
342
- */
343
- normalizeCreateRecordResponse(store: Store, primaryModelClass: Model, payload: Object, id: string | number, requestType: string, ...args: any[]): Object;
344
- /**
345
- Called by the default normalizeResponse implementation when the
346
- type of request is `deleteRecord`
347
-
348
- @since 1.13.0
349
- @method normalizeDeleteRecordResponse
350
- @public
351
- @param {Store} store
352
- @param {Model} primaryModelClass
353
- @param {Object} payload
354
- @param {String|Number} id
355
- @param {String} requestType
356
- @return {Object} JSON-API Document
357
- */
358
- normalizeDeleteRecordResponse(store: Store, primaryModelClass: Model, payload: Object, id: string | number, requestType: string, ...args: any[]): Object;
359
- /**
360
- Called by the default normalizeResponse implementation when the
361
- type of request is `updateRecord`
362
-
363
- @since 1.13.0
364
- @method normalizeUpdateRecordResponse
365
- @public
366
- @param {Store} store
367
- @param {Model} primaryModelClass
368
- @param {Object} payload
369
- @param {String|Number} id
370
- @param {String} requestType
371
- @return {Object} JSON-API Document
372
- */
373
- normalizeUpdateRecordResponse(store: Store, primaryModelClass: Model, payload: Object, id: string | number, requestType: string, ...args: any[]): Object;
374
- /**
375
- normalizeUpdateRecordResponse, normalizeCreateRecordResponse and
376
- normalizeDeleteRecordResponse delegate to this method by default.
377
-
378
- @since 1.13.0
379
- @method normalizeSaveResponse
380
- @public
381
- @param {Store} store
382
- @param {Model} primaryModelClass
383
- @param {Object} payload
384
- @param {String|Number} id
385
- @param {String} requestType
386
- @return {Object} JSON-API Document
387
- */
388
- normalizeSaveResponse(store: Store, primaryModelClass: Model, payload: Object, id: string | number, requestType: string, ...args: any[]): Object;
389
- /**
390
- normalizeQueryResponse and normalizeFindRecordResponse delegate to this
391
- method by default.
392
-
393
- @since 1.13.0
394
- @method normalizeSingleResponse
395
- @public
396
- @param {Store} store
397
- @param {Model} primaryModelClass
398
- @param {Object} payload
399
- @param {String|Number} id
400
- @param {String} requestType
401
- @return {Object} JSON-API Document
402
- */
403
- normalizeSingleResponse(store: Store, primaryModelClass: Model, payload: Object, id: string | number, requestType: string): Object;
404
- /**
405
- normalizeQueryResponse, normalizeFindManyResponse, and normalizeFindHasManyResponse delegate
406
- to this method by default.
407
-
408
- @since 1.13.0
409
- @method normalizeArrayResponse
410
- @public
411
- @param {Store} store
412
- @param {Model} primaryModelClass
413
- @param {Object} payload
414
- @param {String|Number} id
415
- @param {String} requestType
416
- @return {Object} JSON-API Document
417
- */
418
- normalizeArrayResponse(store: Store, primaryModelClass: Model, payload: Object, id: string | number, requestType: string): Object;
419
- /**
420
- @method _normalizeResponse
421
- @param {Store} store
422
- @param {Model} primaryModelClass
423
- @param {Object} payload
424
- @param {String|Number} id
425
- @param {String} requestType
426
- @param {Boolean} isSingle
427
- @return {Object} JSON-API Document
428
- @private
429
- */
430
- _normalizeResponse(store: Store, primaryModelClass: Model, payload: Object, id: string | number, requestType: string, isSingle: boolean): Object;
431
- /**
432
- Normalizes a part of the JSON payload returned by
433
- the server. You should override this method, munge the hash
434
- and call super if you have generic normalization to do.
435
-
436
- It takes the type of the record that is being normalized
437
- (as a Model class), the property where the hash was
438
- originally found, and the hash to normalize.
439
-
440
- You can use this method, for example, to normalize underscored keys to camelized
441
- or other general-purpose normalizations.
442
-
443
- Example
444
-
445
- ```app/serializers/application.js
446
- import JSONSerializer from '@ember-data/serializer/json';
447
- import { underscore } from '<app-name>/utils/string-utils';
448
- import { get } from '@ember/object';
449
-
450
- export default class ApplicationSerializer extends JSONSerializer {
451
- normalize(typeClass, hash) {
452
- let fields = typeClass.fields;
453
-
454
- fields.forEach(function(type, field) {
455
- let payloadField = underscore(field);
456
- if (field === payloadField) { return; }
457
-
458
- hash[field] = hash[payloadField];
459
- delete hash[payloadField];
460
- });
461
-
462
- return super.normalize(...arguments);
124
+ ```
125
+
126
+ ```app/serializers/person.js
127
+ import JSONSerializer from '@ember-data/serializer/json';
128
+
129
+ export default class PersonSerializer extends JSONSerializer {
130
+ attrs = {
131
+ admin: 'is_admin',
132
+ occupation: { key: 'career' }
133
+ }
463
134
  }
464
- }
465
- ```
466
-
467
- @method normalize
468
- @public
469
- @param {Model} typeClass
470
- @param {Object} hash
471
- @return {Object}
472
- */
473
- normalize(modelClass: any, resourceHash: any): Object;
474
- /**
475
- Returns the resource's ID.
476
-
477
- @method extractId
478
- @public
479
- @param {Object} modelClass
480
- @param {Object} resourceHash
481
- @return {String}
482
- */
483
- extractId(modelClass: Object, resourceHash: Object): string;
484
- /**
485
- Returns the resource's attributes formatted as a JSON-API "attributes object".
486
-
487
- http://jsonapi.org/format/#document-resource-object-attributes
488
-
489
- @method extractAttributes
490
- @public
491
- @param {Object} modelClass
492
- @param {Object} resourceHash
493
- @return {Object}
494
- */
495
- extractAttributes(modelClass: Object, resourceHash: Object): Object;
496
- /**
497
- Returns a relationship formatted as a JSON-API "relationship object".
498
-
499
- http://jsonapi.org/format/#document-resource-object-relationships
500
-
501
- @method extractRelationship
502
- @public
503
- @param {Object} relationshipModelName
504
- @param {Object} relationshipHash
505
- @return {Object}
506
- */
507
- extractRelationship(relationshipModelName: Object, relationshipHash: Object): Object;
508
- /**
509
- Returns a polymorphic relationship formatted as a JSON-API "relationship object".
510
-
511
- http://jsonapi.org/format/#document-resource-object-relationships
512
-
513
- `relationshipOptions` is a hash which contains more information about the
514
- polymorphic relationship which should be extracted:
515
- - `resourceHash` complete hash of the resource the relationship should be
516
- extracted from
517
- - `relationshipKey` key under which the value for the relationship is
518
- extracted from the resourceHash
519
- - `relationshipMeta` meta information about the relationship
520
-
521
- @method extractPolymorphicRelationship
522
- @public
523
- @param {Object} relationshipModelName
524
- @param {Object} relationshipHash
525
- @param {Object} relationshipOptions
526
- @return {Object}
527
- */
528
- extractPolymorphicRelationship(relationshipModelName: Object, relationshipHash: Object, relationshipOptions: Object): Object;
529
- /**
530
- Returns the resource's relationships formatted as a JSON-API "relationships object".
531
-
532
- http://jsonapi.org/format/#document-resource-object-relationships
533
-
534
- @method extractRelationships
535
- @public
536
- @param {Object} modelClass
537
- @param {Object} resourceHash
538
- @return {Object}
539
- */
540
- extractRelationships(modelClass: Object, resourceHash: Object): Object;
541
- /**
542
- Dasherizes the model name in the payload
543
-
544
- @method modelNameFromPayloadKey
545
- @public
546
- @param {String} key
547
- @return {String} the model's modelName
548
- */
549
- modelNameFromPayloadKey(key: string): string;
550
- /**
551
- @method normalizeRelationships
552
- @private
553
- */
554
- normalizeRelationships(typeClass: any, hash: any): void;
555
- /**
556
- @method normalizeUsingDeclaredMapping
557
- @private
558
- */
559
- normalizeUsingDeclaredMapping(modelClass: any, hash: any): void;
560
- /**
561
- Looks up the property key that was set by the custom `attr` mapping
562
- passed to the serializer.
563
-
564
- @method _getMappedKey
565
- @private
566
- @param {String} key
567
- @return {String} key
568
- */
569
- _getMappedKey(key: string, modelClass: any): string;
570
- /**
571
- Check attrs.key.serialize property to inform if the `key`
572
- can be serialized
573
-
574
- @method _canSerialize
575
- @private
576
- @param {String} key
577
- @return {boolean} true if the key can be serialized
578
- */
579
- _canSerialize(key: string): boolean;
580
- /**
581
- When attrs.key.serialize is set to true then
582
- it takes priority over the other checks and the related
583
- attribute/relationship will be serialized
584
-
585
- @method _mustSerialize
586
- @private
587
- @param {String} key
588
- @return {boolean} true if the key must be serialized
589
- */
590
- _mustSerialize(key: string): boolean;
591
- /**
592
- Check if the given hasMany relationship should be serialized
593
-
594
- By default only many-to-many and many-to-none relationships are serialized.
595
- This could be configured per relationship by Serializer's `attrs` object.
596
-
597
- @method shouldSerializeHasMany
598
- @public
599
- @param {Snapshot} snapshot
600
- @param {String} key
601
- @param {RelationshipSchema} relationship
602
- @return {boolean} true if the hasMany relationship should be serialized
603
- */
604
- shouldSerializeHasMany(snapshot: Snapshot, key: string, relationship: RelationshipSchema): boolean;
605
- /**
606
- Called when a record is saved in order to convert the
607
- record into JSON.
608
-
609
- By default, it creates a JSON object with a key for
610
- each attribute and belongsTo relationship.
611
-
612
- For example, consider this model:
613
-
614
- ```app/models/comment.js
615
- import Model, { attr, belongsTo } from '@ember-data/model';
616
-
617
- export default class CommentModel extends Model {
618
- @attr title;
619
- @attr body;
620
-
621
- @belongsTo('user') author;
622
- }
623
- ```
624
-
625
- The default serialization would create a JSON object like:
626
-
627
- ```javascript
628
- {
629
- "title": "Rails is unagi",
630
- "body": "Rails? Omakase? O_O",
631
- "author": 12
632
- }
633
- ```
634
-
635
- By default, attributes are passed through as-is, unless
636
- you specified an attribute type (`attr('date')`). If
637
- you specify a transform, the JavaScript value will be
638
- serialized when inserted into the JSON hash.
639
-
640
- By default, belongs-to relationships are converted into
641
- IDs when inserted into the JSON hash.
642
-
643
- ## IDs
644
-
645
- `serialize` takes an options hash with a single option:
646
- `includeId`. If this option is `true`, `serialize` will,
647
- by default include the ID in the JSON object it builds.
648
-
649
- The adapter passes in `includeId: true` when serializing
650
- a record for `createRecord`, but not for `updateRecord`.
651
-
652
- ## Customization
653
-
654
- Your server may expect a different JSON format than the
655
- built-in serialization format.
656
-
657
- In that case, you can implement `serialize` yourself and
658
- return a JSON hash of your choosing.
659
-
660
- ```app/serializers/post.js
661
- import JSONSerializer from '@ember-data/serializer/json';
662
-
663
- export default class PostSerializer extends JSONSerializer {
664
- serialize(snapshot, options) {
665
- let json = {
666
- POST_TTL: snapshot.attr('title'),
667
- POST_BDY: snapshot.attr('body'),
668
- POST_CMS: snapshot.hasMany('comments', { ids: true })
669
- };
670
-
671
- if (options.includeId) {
672
- json.POST_ID_ = snapshot.id;
135
+ ```
136
+
137
+ You can also remove attributes and relationships by setting the `serialize`
138
+ key to `false` in your mapping object.
139
+
140
+ Example
141
+
142
+ ```app/serializers/person.js
143
+ import JSONSerializer from '@ember-data/serializer/json';
144
+
145
+ export default class PostSerializer extends JSONSerializer {
146
+ attrs = {
147
+ admin: { serialize: false },
148
+ occupation: { key: 'career' }
673
149
  }
674
-
675
- return json;
676
150
  }
677
- }
678
- ```
679
-
680
- ## Customizing an App-Wide Serializer
681
-
682
- If you want to define a serializer for your entire
683
- application, you'll probably want to use `eachAttribute`
684
- and `eachRelationship` on the record.
685
-
686
- ```app/serializers/application.js
687
- import JSONSerializer from '@ember-data/serializer/json';
688
- import { singularize } from '<app-name>/utils/string-utils';
689
-
690
- export default class ApplicationSerializer extends JSONSerializer {
691
- serialize(snapshot, options) {
692
- let json = {};
693
-
694
- snapshot.eachAttribute((name) => {
695
- json[serverAttributeName(name)] = snapshot.attr(name);
696
- });
697
-
698
- snapshot.eachRelationship((name, relationship) => {
699
- if (relationship.kind === 'hasMany') {
700
- json[serverHasManyName(name)] = snapshot.hasMany(name, { ids: true });
151
+ ```
152
+
153
+ When serialized:
154
+
155
+ ```javascript
156
+ {
157
+ "firstName": "Harry",
158
+ "lastName": "Houdini",
159
+ "career": "magician"
160
+ }
161
+ ```
162
+
163
+ Note that the `admin` is now not included in the payload.
164
+
165
+ Setting `serialize` to `true` enforces serialization for hasMany
166
+ relationships even if it's neither a many-to-many nor many-to-none
167
+ relationship.
168
+
169
+ @property attrs
170
+ @public
171
+ @type {Object}
172
+ */
173
+ mergedProperties: Object;
174
+ /**
175
+ Given a subclass of `Model` and a JSON object this method will
176
+ iterate through each attribute of the `Model` and invoke the
177
+ `Transform#deserialize` method on the matching property of the
178
+ JSON object. This method is typically called after the
179
+ serializer's `normalize` method.
180
+
181
+ @method applyTransforms
182
+ @private
183
+ @param {Model} typeClass
184
+ @param {Object} data The data to transform
185
+ @return {Object} data The transformed data object
186
+ */
187
+ applyTransforms(typeClass: Model, data: Object): Object;
188
+ /**
189
+ The `normalizeResponse` method is used to normalize a payload from the
190
+ server to a JSON-API Document.
191
+
192
+ http://jsonapi.org/format/#document-structure
193
+
194
+ This method delegates to a more specific normalize method based on
195
+ the `requestType`.
196
+
197
+ To override this method with a custom one, make sure to call
198
+ `return super.normalizeResponse(store, primaryModelClass, payload, id, requestType)` with your
199
+ pre-processed data.
200
+
201
+ Here's an example of using `normalizeResponse` manually:
202
+
203
+ ```javascript
204
+ socket.on('message', function(message) {
205
+ let data = message.data;
206
+ let modelClass = store.modelFor(data.modelName);
207
+ let serializer = store.serializerFor(data.modelName);
208
+ let normalized = serializer.normalizeSingleResponse(store, modelClass, data, data.id);
209
+
210
+ store.push(normalized);
211
+ });
212
+ ```
213
+
214
+ @since 1.13.0
215
+ @method normalizeResponse
216
+ @public
217
+ @param {Store} store
218
+ @param {Model} primaryModelClass
219
+ @param {Object} payload
220
+ @param {String|Number} id
221
+ @param {String} requestType
222
+ @return {Object} JSON-API Document
223
+ */
224
+ normalizeResponse(store: Store, primaryModelClass: Model, payload: Object, id: string | number, requestType: string, ...args: any[]): Object;
225
+ /**
226
+ Called by the default normalizeResponse implementation when the
227
+ type of request is `findRecord`
228
+
229
+ @since 1.13.0
230
+ @method normalizeFindRecordResponse
231
+ @public
232
+ @param {Store} store
233
+ @param {Model} primaryModelClass
234
+ @param {Object} payload
235
+ @param {String|Number} id
236
+ @param {String} requestType
237
+ @return {Object} JSON-API Document
238
+ */
239
+ normalizeFindRecordResponse(store: Store, primaryModelClass: Model, payload: Object, id: string | number, requestType: string, ...args: any[]): Object;
240
+ /**
241
+ Called by the default normalizeResponse implementation when the
242
+ type of request is `queryRecord`
243
+
244
+ @since 1.13.0
245
+ @method normalizeQueryRecordResponse
246
+ @public
247
+ @param {Store} store
248
+ @param {Model} primaryModelClass
249
+ @param {Object} payload
250
+ @param {String|Number} id
251
+ @param {String} requestType
252
+ @return {Object} JSON-API Document
253
+ */
254
+ normalizeQueryRecordResponse(store: Store, primaryModelClass: Model, payload: Object, id: string | number, requestType: string, ...args: any[]): Object;
255
+ /**
256
+ Called by the default normalizeResponse implementation when the
257
+ type of request is `findAll`
258
+
259
+ @since 1.13.0
260
+ @method normalizeFindAllResponse
261
+ @public
262
+ @param {Store} store
263
+ @param {Model} primaryModelClass
264
+ @param {Object} payload
265
+ @param {String|Number} id
266
+ @param {String} requestType
267
+ @return {Object} JSON-API Document
268
+ */
269
+ normalizeFindAllResponse(store: Store, primaryModelClass: Model, payload: Object, id: string | number, requestType: string, ...args: any[]): Object;
270
+ /**
271
+ Called by the default normalizeResponse implementation when the
272
+ type of request is `findBelongsTo`
273
+
274
+ @since 1.13.0
275
+ @method normalizeFindBelongsToResponse
276
+ @public
277
+ @param {Store} store
278
+ @param {Model} primaryModelClass
279
+ @param {Object} payload
280
+ @param {String|Number} id
281
+ @param {String} requestType
282
+ @return {Object} JSON-API Document
283
+ */
284
+ normalizeFindBelongsToResponse(store: Store, primaryModelClass: Model, payload: Object, id: string | number, requestType: string, ...args: any[]): Object;
285
+ /**
286
+ Called by the default normalizeResponse implementation when the
287
+ type of request is `findHasMany`
288
+
289
+ @since 1.13.0
290
+ @method normalizeFindHasManyResponse
291
+ @public
292
+ @param {Store} store
293
+ @param {Model} primaryModelClass
294
+ @param {Object} payload
295
+ @param {String|Number} id
296
+ @param {String} requestType
297
+ @return {Object} JSON-API Document
298
+ */
299
+ normalizeFindHasManyResponse(store: Store, primaryModelClass: Model, payload: Object, id: string | number, requestType: string, ...args: any[]): Object;
300
+ /**
301
+ Called by the default normalizeResponse implementation when the
302
+ type of request is `findMany`
303
+
304
+ @since 1.13.0
305
+ @method normalizeFindManyResponse
306
+ @public
307
+ @param {Store} store
308
+ @param {Model} primaryModelClass
309
+ @param {Object} payload
310
+ @param {String|Number} id
311
+ @param {String} requestType
312
+ @return {Object} JSON-API Document
313
+ */
314
+ normalizeFindManyResponse(store: Store, primaryModelClass: Model, payload: Object, id: string | number, requestType: string, ...args: any[]): Object;
315
+ /**
316
+ Called by the default normalizeResponse implementation when the
317
+ type of request is `query`
318
+
319
+ @since 1.13.0
320
+ @method normalizeQueryResponse
321
+ @public
322
+ @param {Store} store
323
+ @param {Model} primaryModelClass
324
+ @param {Object} payload
325
+ @param {String|Number} id
326
+ @param {String} requestType
327
+ @return {Object} JSON-API Document
328
+ */
329
+ normalizeQueryResponse(store: Store, primaryModelClass: Model, payload: Object, id: string | number, requestType: string, ...args: any[]): Object;
330
+ /**
331
+ Called by the default normalizeResponse implementation when the
332
+ type of request is `createRecord`
333
+
334
+ @since 1.13.0
335
+ @method normalizeCreateRecordResponse
336
+ @public
337
+ @param {Store} store
338
+ @param {Model} primaryModelClass
339
+ @param {Object} payload
340
+ @param {String|Number} id
341
+ @param {String} requestType
342
+ @return {Object} JSON-API Document
343
+ */
344
+ normalizeCreateRecordResponse(store: Store, primaryModelClass: Model, payload: Object, id: string | number, requestType: string, ...args: any[]): Object;
345
+ /**
346
+ Called by the default normalizeResponse implementation when the
347
+ type of request is `deleteRecord`
348
+
349
+ @since 1.13.0
350
+ @method normalizeDeleteRecordResponse
351
+ @public
352
+ @param {Store} store
353
+ @param {Model} primaryModelClass
354
+ @param {Object} payload
355
+ @param {String|Number} id
356
+ @param {String} requestType
357
+ @return {Object} JSON-API Document
358
+ */
359
+ normalizeDeleteRecordResponse(store: Store, primaryModelClass: Model, payload: Object, id: string | number, requestType: string, ...args: any[]): Object;
360
+ /**
361
+ Called by the default normalizeResponse implementation when the
362
+ type of request is `updateRecord`
363
+
364
+ @since 1.13.0
365
+ @method normalizeUpdateRecordResponse
366
+ @public
367
+ @param {Store} store
368
+ @param {Model} primaryModelClass
369
+ @param {Object} payload
370
+ @param {String|Number} id
371
+ @param {String} requestType
372
+ @return {Object} JSON-API Document
373
+ */
374
+ normalizeUpdateRecordResponse(store: Store, primaryModelClass: Model, payload: Object, id: string | number, requestType: string, ...args: any[]): Object;
375
+ /**
376
+ normalizeUpdateRecordResponse, normalizeCreateRecordResponse and
377
+ normalizeDeleteRecordResponse delegate to this method by default.
378
+
379
+ @since 1.13.0
380
+ @method normalizeSaveResponse
381
+ @public
382
+ @param {Store} store
383
+ @param {Model} primaryModelClass
384
+ @param {Object} payload
385
+ @param {String|Number} id
386
+ @param {String} requestType
387
+ @return {Object} JSON-API Document
388
+ */
389
+ normalizeSaveResponse(store: Store, primaryModelClass: Model, payload: Object, id: string | number, requestType: string, ...args: any[]): Object;
390
+ /**
391
+ normalizeQueryResponse and normalizeFindRecordResponse delegate to this
392
+ method by default.
393
+
394
+ @since 1.13.0
395
+ @method normalizeSingleResponse
396
+ @public
397
+ @param {Store} store
398
+ @param {Model} primaryModelClass
399
+ @param {Object} payload
400
+ @param {String|Number} id
401
+ @param {String} requestType
402
+ @return {Object} JSON-API Document
403
+ */
404
+ normalizeSingleResponse(store: Store, primaryModelClass: Model, payload: Object, id: string | number, requestType: string): Object;
405
+ /**
406
+ normalizeQueryResponse, normalizeFindManyResponse, and normalizeFindHasManyResponse delegate
407
+ to this method by default.
408
+
409
+ @since 1.13.0
410
+ @method normalizeArrayResponse
411
+ @public
412
+ @param {Store} store
413
+ @param {Model} primaryModelClass
414
+ @param {Object} payload
415
+ @param {String|Number} id
416
+ @param {String} requestType
417
+ @return {Object} JSON-API Document
418
+ */
419
+ normalizeArrayResponse(store: Store, primaryModelClass: Model, payload: Object, id: string | number, requestType: string): Object;
420
+ /**
421
+ @method _normalizeResponse
422
+ @param {Store} store
423
+ @param {Model} primaryModelClass
424
+ @param {Object} payload
425
+ @param {String|Number} id
426
+ @param {String} requestType
427
+ @param {Boolean} isSingle
428
+ @return {Object} JSON-API Document
429
+ @private
430
+ */
431
+ _normalizeResponse(store: Store, primaryModelClass: Model, payload: Object, id: string | number, requestType: string, isSingle: boolean): Object;
432
+ /**
433
+ Normalizes a part of the JSON payload returned by
434
+ the server. You should override this method, munge the hash
435
+ and call super if you have generic normalization to do.
436
+
437
+ It takes the type of the record that is being normalized
438
+ (as a Model class), the property where the hash was
439
+ originally found, and the hash to normalize.
440
+
441
+ You can use this method, for example, to normalize underscored keys to camelized
442
+ or other general-purpose normalizations.
443
+
444
+ Example
445
+
446
+ ```app/serializers/application.js
447
+ import JSONSerializer from '@ember-data/serializer/json';
448
+ import { underscore } from '<app-name>/utils/string-utils';
449
+ import { get } from '@ember/object';
450
+
451
+ export default class ApplicationSerializer extends JSONSerializer {
452
+ normalize(typeClass, hash) {
453
+ let fields = typeClass.fields;
454
+
455
+ fields.forEach(function(type, field) {
456
+ let payloadField = underscore(field);
457
+ if (field === payloadField) { return; }
458
+
459
+ hash[field] = hash[payloadField];
460
+ delete hash[payloadField];
461
+ });
462
+
463
+ return super.normalize(...arguments);
464
+ }
465
+ }
466
+ ```
467
+
468
+ @method normalize
469
+ @public
470
+ @param {Model} typeClass
471
+ @param {Object} hash
472
+ @return {Object}
473
+ */
474
+ normalize(modelClass: any, resourceHash: any): Object;
475
+ /**
476
+ Returns the resource's ID.
477
+
478
+ @method extractId
479
+ @public
480
+ @param {Object} modelClass
481
+ @param {Object} resourceHash
482
+ @return {String}
483
+ */
484
+ extractId(modelClass: Object, resourceHash: Object): string;
485
+ /**
486
+ Returns the resource's attributes formatted as a JSON-API "attributes object".
487
+
488
+ http://jsonapi.org/format/#document-resource-object-attributes
489
+
490
+ @method extractAttributes
491
+ @public
492
+ @param {Object} modelClass
493
+ @param {Object} resourceHash
494
+ @return {Object}
495
+ */
496
+ extractAttributes(modelClass: Object, resourceHash: Object): Object;
497
+ /**
498
+ Returns a relationship formatted as a JSON-API "relationship object".
499
+
500
+ http://jsonapi.org/format/#document-resource-object-relationships
501
+
502
+ @method extractRelationship
503
+ @public
504
+ @param {Object} relationshipModelName
505
+ @param {Object} relationshipHash
506
+ @return {Object}
507
+ */
508
+ extractRelationship(relationshipModelName: Object, relationshipHash: Object): Object;
509
+ /**
510
+ Returns a polymorphic relationship formatted as a JSON-API "relationship object".
511
+
512
+ http://jsonapi.org/format/#document-resource-object-relationships
513
+
514
+ `relationshipOptions` is a hash which contains more information about the
515
+ polymorphic relationship which should be extracted:
516
+ - `resourceHash` complete hash of the resource the relationship should be
517
+ extracted from
518
+ - `relationshipKey` key under which the value for the relationship is
519
+ extracted from the resourceHash
520
+ - `relationshipMeta` meta information about the relationship
521
+
522
+ @method extractPolymorphicRelationship
523
+ @public
524
+ @param {Object} relationshipModelName
525
+ @param {Object} relationshipHash
526
+ @param {Object} relationshipOptions
527
+ @return {Object}
528
+ */
529
+ extractPolymorphicRelationship(relationshipModelName: Object, relationshipHash: Object, relationshipOptions: Object): Object;
530
+ /**
531
+ Returns the resource's relationships formatted as a JSON-API "relationships object".
532
+
533
+ http://jsonapi.org/format/#document-resource-object-relationships
534
+
535
+ @method extractRelationships
536
+ @public
537
+ @param {Object} modelClass
538
+ @param {Object} resourceHash
539
+ @return {Object}
540
+ */
541
+ extractRelationships(modelClass: Object, resourceHash: Object): Object;
542
+ /**
543
+ Dasherizes the model name in the payload
544
+
545
+ @method modelNameFromPayloadKey
546
+ @public
547
+ @param {String} key
548
+ @return {String} the model's modelName
549
+ */
550
+ modelNameFromPayloadKey(key: string): string;
551
+ /**
552
+ @method normalizeRelationships
553
+ @private
554
+ */
555
+ normalizeRelationships(typeClass: any, hash: any): void;
556
+ /**
557
+ @method normalizeUsingDeclaredMapping
558
+ @private
559
+ */
560
+ normalizeUsingDeclaredMapping(modelClass: any, hash: any): void;
561
+ /**
562
+ Looks up the property key that was set by the custom `attr` mapping
563
+ passed to the serializer.
564
+
565
+ @method _getMappedKey
566
+ @private
567
+ @param {String} key
568
+ @return {String} key
569
+ */
570
+ _getMappedKey(key: string, modelClass: any): string;
571
+ /**
572
+ Check attrs.key.serialize property to inform if the `key`
573
+ can be serialized
574
+
575
+ @method _canSerialize
576
+ @private
577
+ @param {String} key
578
+ @return {boolean} true if the key can be serialized
579
+ */
580
+ _canSerialize(key: string): boolean;
581
+ /**
582
+ When attrs.key.serialize is set to true then
583
+ it takes priority over the other checks and the related
584
+ attribute/relationship will be serialized
585
+
586
+ @method _mustSerialize
587
+ @private
588
+ @param {String} key
589
+ @return {boolean} true if the key must be serialized
590
+ */
591
+ _mustSerialize(key: string): boolean;
592
+ /**
593
+ Check if the given hasMany relationship should be serialized
594
+
595
+ By default only many-to-many and many-to-none relationships are serialized.
596
+ This could be configured per relationship by Serializer's `attrs` object.
597
+
598
+ @method shouldSerializeHasMany
599
+ @public
600
+ @param {Snapshot} snapshot
601
+ @param {String} key
602
+ @param {RelationshipSchema} relationship
603
+ @return {boolean} true if the hasMany relationship should be serialized
604
+ */
605
+ shouldSerializeHasMany(snapshot: Snapshot, key: string, relationship: RelationshipSchema): boolean;
606
+ /**
607
+ Called when a record is saved in order to convert the
608
+ record into JSON.
609
+
610
+ By default, it creates a JSON object with a key for
611
+ each attribute and belongsTo relationship.
612
+
613
+ For example, consider this model:
614
+
615
+ ```app/models/comment.js
616
+ import Model, { attr, belongsTo } from '@ember-data/model';
617
+
618
+ export default class CommentModel extends Model {
619
+ @attr title;
620
+ @attr body;
621
+
622
+ @belongsTo('user') author;
623
+ }
624
+ ```
625
+
626
+ The default serialization would create a JSON object like:
627
+
628
+ ```javascript
629
+ {
630
+ "title": "Rails is unagi",
631
+ "body": "Rails? Omakase? O_O",
632
+ "author": 12
633
+ }
634
+ ```
635
+
636
+ By default, attributes are passed through as-is, unless
637
+ you specified an attribute type (`attr('date')`). If
638
+ you specify a transform, the JavaScript value will be
639
+ serialized when inserted into the JSON hash.
640
+
641
+ By default, belongs-to relationships are converted into
642
+ IDs when inserted into the JSON hash.
643
+
644
+ ## IDs
645
+
646
+ `serialize` takes an options hash with a single option:
647
+ `includeId`. If this option is `true`, `serialize` will,
648
+ by default include the ID in the JSON object it builds.
649
+
650
+ The adapter passes in `includeId: true` when serializing
651
+ a record for `createRecord`, but not for `updateRecord`.
652
+
653
+ ## Customization
654
+
655
+ Your server may expect a different JSON format than the
656
+ built-in serialization format.
657
+
658
+ In that case, you can implement `serialize` yourself and
659
+ return a JSON hash of your choosing.
660
+
661
+ ```app/serializers/post.js
662
+ import JSONSerializer from '@ember-data/serializer/json';
663
+
664
+ export default class PostSerializer extends JSONSerializer {
665
+ serialize(snapshot, options) {
666
+ let json = {
667
+ POST_TTL: snapshot.attr('title'),
668
+ POST_BDY: snapshot.attr('body'),
669
+ POST_CMS: snapshot.hasMany('comments', { ids: true })
670
+ };
671
+
672
+ if (options.includeId) {
673
+ json.POST_ID_ = snapshot.id;
701
674
  }
702
- });
703
-
704
- if (options.includeId) {
705
- json.ID_ = snapshot.id;
675
+
676
+ return json;
706
677
  }
707
-
708
- return json;
709
678
  }
710
- }
711
-
712
- function serverAttributeName(attribute) {
713
- return attribute.underscore().toUpperCase();
714
- }
715
-
716
- function serverHasManyName(name) {
717
- return serverAttributeName(singularize(name)) + "_IDS";
718
- }
719
- ```
720
-
721
- This serializer will generate JSON that looks like this:
722
-
723
- ```javascript
724
- {
725
- "TITLE": "Rails is omakase",
726
- "BODY": "Yep. Omakase.",
727
- "COMMENT_IDS": [ "1", "2", "3" ]
728
- }
729
- ```
730
-
731
- ## Tweaking the Default JSON
732
-
733
- If you just want to do some small tweaks on the default JSON,
734
- you can call `super.serialize` first and make the tweaks on
735
- the returned JSON.
736
-
737
- ```app/serializers/post.js
738
- import JSONSerializer from '@ember-data/serializer/json';
739
-
740
- export default class PostSerializer extends JSONSerializer {
741
- serialize(snapshot, options) {
742
- let json = super.serialize(...arguments);
743
-
744
- json.subject = json.title;
745
- delete json.title;
746
-
747
- return json;
679
+ ```
680
+
681
+ ## Customizing an App-Wide Serializer
682
+
683
+ If you want to define a serializer for your entire
684
+ application, you'll probably want to use `eachAttribute`
685
+ and `eachRelationship` on the record.
686
+
687
+ ```app/serializers/application.js
688
+ import JSONSerializer from '@ember-data/serializer/json';
689
+ import { singularize } from '<app-name>/utils/string-utils';
690
+
691
+ export default class ApplicationSerializer extends JSONSerializer {
692
+ serialize(snapshot, options) {
693
+ let json = {};
694
+
695
+ snapshot.eachAttribute((name) => {
696
+ json[serverAttributeName(name)] = snapshot.attr(name);
697
+ });
698
+
699
+ snapshot.eachRelationship((name, relationship) => {
700
+ if (relationship.kind === 'hasMany') {
701
+ json[serverHasManyName(name)] = snapshot.hasMany(name, { ids: true });
702
+ }
703
+ });
704
+
705
+ if (options.includeId) {
706
+ json.ID_ = snapshot.id;
707
+ }
708
+
709
+ return json;
710
+ }
748
711
  }
749
- }
750
- ```
751
-
752
- @method serialize
753
- @public
754
- @param {Snapshot} snapshot
755
- @param {Object} options
756
- @return {Object} json
757
- */
758
- serialize(snapshot: Snapshot, options: Object): Object;
759
- /**
760
- You can use this method to customize how a serialized record is added to the complete
761
- JSON hash to be sent to the server. By default the JSON Serializer does not namespace
762
- the payload and just sends the raw serialized JSON object.
763
- If your server expects namespaced keys, you should consider using the RESTSerializer.
764
- Otherwise you can override this method to customize how the record is added to the hash.
765
- The hash property should be modified by reference.
766
-
767
- For example, your server may expect underscored root objects.
768
-
769
- ```app/serializers/application.js
770
- import RESTSerializer from '@ember-data/serializer/rest';
771
- import { decamelize } from '<app-name>/utils/string-utils';
772
-
773
- export default class ApplicationSerializer extends RESTSerializer {
774
- serializeIntoHash(data, type, snapshot, options) {
775
- let root = decamelize(type.modelName);
776
- data[root] = this.serialize(snapshot, options);
712
+
713
+ function serverAttributeName(attribute) {
714
+ return attribute.underscore().toUpperCase();
777
715
  }
778
- }
779
- ```
780
-
781
- @method serializeIntoHash
782
- @public
783
- @param {Object} hash
784
- @param {Model} typeClass
785
- @param {Snapshot} snapshot
786
- @param {Object} options
787
- */
788
- serializeIntoHash(hash: Object, typeClass: Model, snapshot: Snapshot, options: Object): void;
789
- /**
790
- `serializeAttribute` can be used to customize how `attr`
791
- properties are serialized
792
-
793
- For example if you wanted to ensure all your attributes were always
794
- serialized as properties on an `attributes` object you could
795
- write:
796
-
797
- ```app/serializers/application.js
798
- import JSONSerializer from '@ember-data/serializer/json';
799
-
800
- export default class ApplicationSerializer extends JSONSerializer {
801
- serializeAttribute(snapshot, json, key, attributes) {
802
- json.attributes = json.attributes || {};
803
- super.serializeAttribute(snapshot, json.attributes, key, attributes);
716
+
717
+ function serverHasManyName(name) {
718
+ return serverAttributeName(singularize(name)) + "_IDS";
804
719
  }
805
- }
806
- ```
807
-
808
- @method serializeAttribute
809
- @public
810
- @param {Snapshot} snapshot
811
- @param {Object} json
812
- @param {String} key
813
- @param {Object} attribute
814
- */
815
- serializeAttribute(snapshot: Snapshot, json: Object, key: string, attribute: Object): void;
816
- /**
817
- `serializeBelongsTo` can be used to customize how `belongsTo`
818
- properties are serialized.
819
-
820
- Example
821
-
822
- ```app/serializers/post.js
823
- import JSONSerializer from '@ember-data/serializer/json';
824
-
825
- export default class PostSerializer extends JSONSerializer {
826
- serializeBelongsTo(snapshot, json, relationship) {
827
- let key = relationship.name;
828
- let belongsTo = snapshot.belongsTo(key);
829
-
830
- key = this.keyForRelationship ? this.keyForRelationship(key, "belongsTo", "serialize") : key;
831
-
832
- json[key] = !belongsTo ? null : belongsTo.record.toJSON();
720
+ ```
721
+
722
+ This serializer will generate JSON that looks like this:
723
+
724
+ ```javascript
725
+ {
726
+ "TITLE": "Rails is omakase",
727
+ "BODY": "Yep. Omakase.",
728
+ "COMMENT_IDS": [ "1", "2", "3" ]
833
729
  }
834
- }
835
- ```
836
-
837
- @method serializeBelongsTo
838
- @public
839
- @param {Snapshot} snapshot
840
- @param {Object} json
841
- @param {Object} relationship
842
- */
843
- serializeBelongsTo(snapshot: Snapshot, json: Object, relationship: Object): void;
844
- /**
845
- `serializeHasMany` can be used to customize how `hasMany`
846
- properties are serialized.
847
-
848
- Example
849
-
850
- ```app/serializers/post.js
851
- import JSONSerializer from '@ember-data/serializer/json';
852
-
853
- export default class PostSerializer extends JSONSerializer {
854
- serializeHasMany(snapshot, json, relationship) {
855
- let key = relationship.name;
856
- if (key === 'comments') {
857
- return;
858
- } else {
859
- super.serializeHasMany(...arguments);
860
- }
861
- }
862
- }
863
- ```
864
-
865
- @method serializeHasMany
866
- @public
867
- @param {Snapshot} snapshot
868
- @param {Object} json
869
- @param {Object} relationship
870
- */
871
- serializeHasMany(snapshot: Snapshot, json: Object, relationship: Object): void;
872
- /**
873
- You can use this method to customize how polymorphic objects are
874
- serialized. Objects are considered to be polymorphic if
875
- `{ polymorphic: true }` is pass as the second argument to the
876
- `belongsTo` function.
877
-
878
- Example
879
-
880
- ```app/serializers/comment.js
881
- import JSONSerializer from '@ember-data/serializer/json';
882
-
883
- export default class CommentSerializer extends JSONSerializer {
884
- serializePolymorphicType(snapshot, json, relationship) {
885
- let key = relationship.name;
886
- let belongsTo = snapshot.belongsTo(key);
887
-
888
- key = this.keyForAttribute ? this.keyForAttribute(key, 'serialize') : key;
889
-
890
- if (!belongsTo) {
891
- json[key + '_type'] = null;
892
- } else {
893
- json[key + '_type'] = belongsTo.modelName;
730
+ ```
731
+
732
+ ## Tweaking the Default JSON
733
+
734
+ If you just want to do some small tweaks on the default JSON,
735
+ you can call `super.serialize` first and make the tweaks on
736
+ the returned JSON.
737
+
738
+ ```app/serializers/post.js
739
+ import JSONSerializer from '@ember-data/serializer/json';
740
+
741
+ export default class PostSerializer extends JSONSerializer {
742
+ serialize(snapshot, options) {
743
+ let json = super.serialize(...arguments);
744
+
745
+ json.subject = json.title;
746
+ delete json.title;
747
+
748
+ return json;
894
749
  }
895
750
  }
896
- }
897
- ```
898
-
899
- @method serializePolymorphicType
900
- @public
901
- @param {Snapshot} snapshot
902
- @param {Object} json
903
- @param {Object} relationship
904
- */
905
- serializePolymorphicType(): void;
906
- /**
907
- `extractMeta` is used to deserialize any meta information in the
908
- adapter payload. By default Ember Data expects meta information to
909
- be located on the `meta` property of the payload object.
910
-
911
- Example
912
-
913
- ```app/serializers/post.js
914
- import JSONSerializer from '@ember-data/serializer/json';
915
-
916
- export default class PostSerializer extends JSONSerializer {
917
- extractMeta(store, typeClass, payload) {
918
- if (payload && payload.hasOwnProperty('_pagination')) {
919
- let meta = payload._pagination;
920
- delete payload._pagination;
921
- return meta;
751
+ ```
752
+
753
+ @method serialize
754
+ @public
755
+ @param {Snapshot} snapshot
756
+ @param {Object} options
757
+ @return {Object} json
758
+ */
759
+ serialize(snapshot: Snapshot, options: Object): Object;
760
+ /**
761
+ You can use this method to customize how a serialized record is added to the complete
762
+ JSON hash to be sent to the server. By default the JSON Serializer does not namespace
763
+ the payload and just sends the raw serialized JSON object.
764
+ If your server expects namespaced keys, you should consider using the RESTSerializer.
765
+ Otherwise you can override this method to customize how the record is added to the hash.
766
+ The hash property should be modified by reference.
767
+
768
+ For example, your server may expect underscored root objects.
769
+
770
+ ```app/serializers/application.js
771
+ import RESTSerializer from '@ember-data/serializer/rest';
772
+ import { decamelize } from '<app-name>/utils/string-utils';
773
+
774
+ export default class ApplicationSerializer extends RESTSerializer {
775
+ serializeIntoHash(data, type, snapshot, options) {
776
+ let root = decamelize(type.modelName);
777
+ data[root] = this.serialize(snapshot, options);
922
778
  }
923
779
  }
924
- }
925
- ```
926
-
927
- @method extractMeta
928
- @public
929
- @param {Store} store
930
- @param {Model} modelClass
931
- @param {Object} payload
932
- */
933
- extractMeta(store: Store, modelClass: Model, payload: Object): any;
934
- /**
935
- `extractErrors` is used to extract model errors when a call
936
- to `Model#save` fails with an `InvalidError`. By default
937
- Ember Data expects error information to be located on the `errors`
938
- property of the payload object.
939
-
940
- This serializer expects this `errors` object to be an Array similar
941
- to the following, compliant with the https://jsonapi.org/format/#errors specification:
942
-
943
- ```js
944
- {
945
- "errors": [
946
- {
947
- "detail": "This username is already taken!",
948
- "source": {
949
- "pointer": "data/attributes/username"
950
- }
951
- }, {
952
- "detail": "Doesn't look like a valid email.",
953
- "source": {
954
- "pointer": "data/attributes/email"
955
- }
780
+ ```
781
+
782
+ @method serializeIntoHash
783
+ @public
784
+ @param {Object} hash
785
+ @param {Model} typeClass
786
+ @param {Snapshot} snapshot
787
+ @param {Object} options
788
+ */
789
+ serializeIntoHash(hash: Object, typeClass: Model, snapshot: Snapshot, options: Object): void;
790
+ /**
791
+ `serializeAttribute` can be used to customize how `attr`
792
+ properties are serialized
793
+
794
+ For example if you wanted to ensure all your attributes were always
795
+ serialized as properties on an `attributes` object you could
796
+ write:
797
+
798
+ ```app/serializers/application.js
799
+ import JSONSerializer from '@ember-data/serializer/json';
800
+
801
+ export default class ApplicationSerializer extends JSONSerializer {
802
+ serializeAttribute(snapshot, json, key, attributes) {
803
+ json.attributes = json.attributes || {};
804
+ super.serializeAttribute(snapshot, json.attributes, key, attributes);
956
805
  }
957
- ]
958
- }
959
- ```
960
-
961
- The key `detail` provides a textual description of the problem.
962
- Alternatively, the key `title` can be used for the same purpose.
963
-
964
- The nested keys `source.pointer` detail which specific element
965
- of the request data was invalid.
966
-
967
- Note that JSON-API also allows for object-level errors to be placed
968
- in an object with pointer `data`, signifying that the problem
969
- cannot be traced to a specific attribute:
970
-
971
- ```javascript
972
- {
973
- "errors": [
974
- {
975
- "detail": "Some generic non property error message",
976
- "source": {
977
- "pointer": "data"
806
+ }
807
+ ```
808
+
809
+ @method serializeAttribute
810
+ @public
811
+ @param {Snapshot} snapshot
812
+ @param {Object} json
813
+ @param {String} key
814
+ @param {Object} attribute
815
+ */
816
+ serializeAttribute(snapshot: Snapshot, json: Object, key: string, attribute: Object): void;
817
+ /**
818
+ `serializeBelongsTo` can be used to customize how `belongsTo`
819
+ properties are serialized.
820
+
821
+ Example
822
+
823
+ ```app/serializers/post.js
824
+ import JSONSerializer from '@ember-data/serializer/json';
825
+
826
+ export default class PostSerializer extends JSONSerializer {
827
+ serializeBelongsTo(snapshot, json, relationship) {
828
+ let key = relationship.name;
829
+ let belongsTo = snapshot.belongsTo(key);
830
+
831
+ key = this.keyForRelationship ? this.keyForRelationship(key, "belongsTo", "serialize") : key;
832
+
833
+ json[key] = !belongsTo ? null : belongsTo.record.toJSON();
834
+ }
835
+ }
836
+ ```
837
+
838
+ @method serializeBelongsTo
839
+ @public
840
+ @param {Snapshot} snapshot
841
+ @param {Object} json
842
+ @param {Object} relationship
843
+ */
844
+ serializeBelongsTo(snapshot: Snapshot, json: Object, relationship: Object): void;
845
+ /**
846
+ `serializeHasMany` can be used to customize how `hasMany`
847
+ properties are serialized.
848
+
849
+ Example
850
+
851
+ ```app/serializers/post.js
852
+ import JSONSerializer from '@ember-data/serializer/json';
853
+
854
+ export default class PostSerializer extends JSONSerializer {
855
+ serializeHasMany(snapshot, json, relationship) {
856
+ let key = relationship.name;
857
+ if (key === 'comments') {
858
+ return;
859
+ } else {
860
+ super.serializeHasMany(...arguments);
861
+ }
862
+ }
863
+ }
864
+ ```
865
+
866
+ @method serializeHasMany
867
+ @public
868
+ @param {Snapshot} snapshot
869
+ @param {Object} json
870
+ @param {Object} relationship
871
+ */
872
+ serializeHasMany(snapshot: Snapshot, json: Object, relationship: Object): void;
873
+ /**
874
+ You can use this method to customize how polymorphic objects are
875
+ serialized. Objects are considered to be polymorphic if
876
+ `{ polymorphic: true }` is pass as the second argument to the
877
+ `belongsTo` function.
878
+
879
+ Example
880
+
881
+ ```app/serializers/comment.js
882
+ import JSONSerializer from '@ember-data/serializer/json';
883
+
884
+ export default class CommentSerializer extends JSONSerializer {
885
+ serializePolymorphicType(snapshot, json, relationship) {
886
+ let key = relationship.name;
887
+ let belongsTo = snapshot.belongsTo(key);
888
+
889
+ key = this.keyForAttribute ? this.keyForAttribute(key, 'serialize') : key;
890
+
891
+ if (!belongsTo) {
892
+ json[key + '_type'] = null;
893
+ } else {
894
+ json[key + '_type'] = belongsTo.modelName;
978
895
  }
979
896
  }
980
- ]
981
- }
982
- ```
983
-
984
- When turn into a `Errors` object, you can read these errors
985
- through the property `base`:
986
-
987
- ```handlebars
988
- {{#each @model.errors.base as |error|}}
989
- <div class="error">
990
- {{error.message}}
991
- </div>
992
- {{/each}}
993
- ```
994
-
995
- Example of alternative implementation, overriding the default
996
- behavior to deal with a different format of errors:
997
-
998
- ```app/serializers/post.js
999
- import JSONSerializer from '@ember-data/serializer/json';
1000
-
1001
- export default class PostSerializer extends JSONSerializer {
1002
- extractErrors(store, typeClass, payload, id) {
1003
- if (payload && typeof payload === 'object' && payload._problems) {
1004
- payload = payload._problems;
1005
- this.normalizeErrors(typeClass, payload);
897
+ }
898
+ ```
899
+
900
+ @method serializePolymorphicType
901
+ @public
902
+ @param {Snapshot} snapshot
903
+ @param {Object} json
904
+ @param {Object} relationship
905
+ */
906
+ serializePolymorphicType(): void;
907
+ /**
908
+ `extractMeta` is used to deserialize any meta information in the
909
+ adapter payload. By default Ember Data expects meta information to
910
+ be located on the `meta` property of the payload object.
911
+
912
+ Example
913
+
914
+ ```app/serializers/post.js
915
+ import JSONSerializer from '@ember-data/serializer/json';
916
+
917
+ export default class PostSerializer extends JSONSerializer {
918
+ extractMeta(store, typeClass, payload) {
919
+ if (payload && payload.hasOwnProperty('_pagination')) {
920
+ let meta = payload._pagination;
921
+ delete payload._pagination;
922
+ return meta;
923
+ }
1006
924
  }
1007
- return payload;
1008
925
  }
1009
- }
1010
- ```
1011
-
1012
- @method extractErrors
1013
- @public
1014
- @param {Store} store
1015
- @param {Model} typeClass
1016
- @param {Object} payload
1017
- @param {(String|Number)} id
1018
- @return {Object} json The deserialized errors
1019
- */
1020
- extractErrors(store: Store, typeClass: Model, payload: Object, id: (string | number)): Object;
1021
- /**
1022
- `keyForAttribute` can be used to define rules for how to convert an
1023
- attribute name in your model to a key in your JSON.
1024
-
1025
- Example
1026
-
1027
- ```app/serializers/application.js
1028
- import JSONSerializer from '@ember-data/serializer/json';
1029
- import { underscore } from '<app-name>/utils/string-utils';
1030
-
1031
- export default class ApplicationSerializer extends JSONSerializer {
1032
- keyForAttribute(attr, method) {
1033
- return underscore(attr).toUpperCase();
926
+ ```
927
+
928
+ @method extractMeta
929
+ @public
930
+ @param {Store} store
931
+ @param {Model} modelClass
932
+ @param {Object} payload
933
+ */
934
+ extractMeta(store: Store, modelClass: Model, payload: Object): any;
935
+ /**
936
+ `extractErrors` is used to extract model errors when a call
937
+ to `Model#save` fails with an `InvalidError`. By default
938
+ Ember Data expects error information to be located on the `errors`
939
+ property of the payload object.
940
+
941
+ This serializer expects this `errors` object to be an Array similar
942
+ to the following, compliant with the https://jsonapi.org/format/#errors specification:
943
+
944
+ ```js
945
+ {
946
+ "errors": [
947
+ {
948
+ "detail": "This username is already taken!",
949
+ "source": {
950
+ "pointer": "data/attributes/username"
951
+ }
952
+ }, {
953
+ "detail": "Doesn't look like a valid email.",
954
+ "source": {
955
+ "pointer": "data/attributes/email"
956
+ }
957
+ }
958
+ ]
1034
959
  }
1035
- }
1036
- ```
1037
-
1038
- @method keyForAttribute
1039
- @public
1040
- @param {String} key
1041
- @param {String} method
1042
- @return {String} normalized key
1043
- */
1044
- keyForAttribute(key: string, method: string): string;
1045
- /**
1046
- `keyForRelationship` can be used to define a custom key when
1047
- serializing and deserializing relationship properties. By default
1048
- `JSONSerializer` does not provide an implementation of this method.
1049
-
1050
- Example
1051
-
960
+ ```
961
+
962
+ The key `detail` provides a textual description of the problem.
963
+ Alternatively, the key `title` can be used for the same purpose.
964
+
965
+ The nested keys `source.pointer` detail which specific element
966
+ of the request data was invalid.
967
+
968
+ Note that JSON-API also allows for object-level errors to be placed
969
+ in an object with pointer `data`, signifying that the problem
970
+ cannot be traced to a specific attribute:
971
+
972
+ ```javascript
973
+ {
974
+ "errors": [
975
+ {
976
+ "detail": "Some generic non property error message",
977
+ "source": {
978
+ "pointer": "data"
979
+ }
980
+ }
981
+ ]
982
+ }
983
+ ```
984
+
985
+ When turn into a `Errors` object, you can read these errors
986
+ through the property `base`:
987
+
988
+ ```handlebars
989
+ {{#each @model.errors.base as |error|}}
990
+ <div class="error">
991
+ {{error.message}}
992
+ </div>
993
+ {{/each}}
994
+ ```
995
+
996
+ Example of alternative implementation, overriding the default
997
+ behavior to deal with a different format of errors:
998
+
1052
999
  ```app/serializers/post.js
1053
1000
  import JSONSerializer from '@ember-data/serializer/json';
1054
- import { underscore } from '<app-name>/utils/string-utils';
1055
-
1001
+
1056
1002
  export default class PostSerializer extends JSONSerializer {
1057
- keyForRelationship(key, relationship, method) {
1058
- return `rel_${underscore(key)}`;
1003
+ extractErrors(store, typeClass, payload, id) {
1004
+ if (payload && typeof payload === 'object' && payload._problems) {
1005
+ payload = payload._problems;
1006
+ this.normalizeErrors(typeClass, payload);
1007
+ }
1008
+ return payload;
1059
1009
  }
1060
1010
  }
1061
1011
  ```
1062
-
1063
- @method keyForRelationship
1064
- @public
1065
- @param {String} key
1066
- @param {String} typeClass
1067
- @param {String} method
1068
- @return {String} normalized key
1069
- */
1070
- keyForRelationship(key: string, typeClass: string, method: string): string;
1071
- /**
1072
- `keyForLink` can be used to define a custom key when deserializing link
1073
- properties.
1074
-
1075
- @method keyForLink
1076
- @public
1077
- @param {String} key
1078
- @param {String} kind `belongsTo` or `hasMany`
1079
- @return {String} normalized key
1080
- */
1081
- keyForLink(key: string, kind: string): string;
1082
- /**
1083
- @method transformFor
1084
- @private
1085
- @param {String} attributeType
1086
- @param {Boolean} skipAssertion
1087
- @return {Transform} transform
1088
- */
1089
- transformFor(attributeType: string, skipAssertion: boolean): Transform;
1090
- };
1091
- import Serializer from '.';
1092
- //# sourceMappingURL=json.d.ts.map
1012
+
1013
+ @method extractErrors
1014
+ @public
1015
+ @param {Store} store
1016
+ @param {Model} typeClass
1017
+ @param {Object} payload
1018
+ @param {(String|Number)} id
1019
+ @return {Object} json The deserialized errors
1020
+ */
1021
+ extractErrors(store: Store, typeClass: Model, payload: Object, id: (string | number)): Object;
1022
+ /**
1023
+ `keyForAttribute` can be used to define rules for how to convert an
1024
+ attribute name in your model to a key in your JSON.
1025
+
1026
+ Example
1027
+
1028
+ ```app/serializers/application.js
1029
+ import JSONSerializer from '@ember-data/serializer/json';
1030
+ import { underscore } from '<app-name>/utils/string-utils';
1031
+
1032
+ export default class ApplicationSerializer extends JSONSerializer {
1033
+ keyForAttribute(attr, method) {
1034
+ return underscore(attr).toUpperCase();
1035
+ }
1036
+ }
1037
+ ```
1038
+
1039
+ @method keyForAttribute
1040
+ @public
1041
+ @param {String} key
1042
+ @param {String} method
1043
+ @return {String} normalized key
1044
+ */
1045
+ keyForAttribute(key: string, method: string): string;
1046
+ /**
1047
+ `keyForRelationship` can be used to define a custom key when
1048
+ serializing and deserializing relationship properties. By default
1049
+ `JSONSerializer` does not provide an implementation of this method.
1050
+
1051
+ Example
1052
+
1053
+ ```app/serializers/post.js
1054
+ import JSONSerializer from '@ember-data/serializer/json';
1055
+ import { underscore } from '<app-name>/utils/string-utils';
1056
+
1057
+ export default class PostSerializer extends JSONSerializer {
1058
+ keyForRelationship(key, relationship, method) {
1059
+ return `rel_${underscore(key)}`;
1060
+ }
1061
+ }
1062
+ ```
1063
+
1064
+ @method keyForRelationship
1065
+ @public
1066
+ @param {String} key
1067
+ @param {String} typeClass
1068
+ @param {String} method
1069
+ @return {String} normalized key
1070
+ */
1071
+ keyForRelationship(key: string, typeClass: string, method: string): string;
1072
+ /**
1073
+ `keyForLink` can be used to define a custom key when deserializing link
1074
+ properties.
1075
+
1076
+ @method keyForLink
1077
+ @public
1078
+ @param {String} key
1079
+ @param {String} kind `belongsTo` or `hasMany`
1080
+ @return {String} normalized key
1081
+ */
1082
+ keyForLink(key: string, kind: string): string;
1083
+ /**
1084
+ @method transformFor
1085
+ @private
1086
+ @param {String} attributeType
1087
+ @param {Boolean} skipAssertion
1088
+ @return {Transform} transform
1089
+ */
1090
+ transformFor(attributeType: string, skipAssertion: boolean): Transform;
1091
+ };
1092
+ import Serializer from '@ember-data/serializer';
1093
+ //# sourceMappingURL=json.d.ts.map
1094
+ }