@ember-data/serializer 5.4.0-alpha.5 → 5.4.0-alpha.50

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 (49) hide show
  1. package/README.md +2 -1
  2. package/addon/-private.js +3 -4
  3. package/addon/-private.js.map +1 -1
  4. package/addon/{embedded-records-mixin-d75385ff.js → embedded-records-mixin-QJe_8jrF.js} +57 -60
  5. package/addon/embedded-records-mixin-QJe_8jrF.js.map +1 -0
  6. package/addon/index.js +1 -0
  7. package/addon/index.js.map +1 -1
  8. package/addon/json-api.js +52 -173
  9. package/addon/json-api.js.map +1 -1
  10. package/addon/json.js +53 -54
  11. package/addon/json.js.map +1 -1
  12. package/addon/rest.js +31 -27
  13. package/addon/rest.js.map +1 -1
  14. package/addon/{string-22572f80.js → string-Juwz4cu0.js} +152 -20
  15. package/addon/string-Juwz4cu0.js.map +1 -0
  16. package/addon/transform.js +1 -2
  17. package/addon/transform.js.map +1 -1
  18. package/addon/{utils-075c5b79.js.map → utils-NcVD2Jb5.js.map} +1 -1
  19. package/addon-main.js +1 -0
  20. package/package.json +64 -30
  21. package/unstable-preview-types/-private/embedded-records-mixin.d.ts +7 -0
  22. package/unstable-preview-types/-private/embedded-records-mixin.d.ts.map +1 -0
  23. package/unstable-preview-types/-private/transforms/boolean.d.ts +52 -0
  24. package/unstable-preview-types/-private/transforms/boolean.d.ts.map +1 -0
  25. package/unstable-preview-types/-private/transforms/date.d.ts +33 -0
  26. package/unstable-preview-types/-private/transforms/date.d.ts.map +1 -0
  27. package/unstable-preview-types/-private/transforms/number.d.ts +34 -0
  28. package/unstable-preview-types/-private/transforms/number.d.ts.map +1 -0
  29. package/unstable-preview-types/-private/transforms/string.d.ts +34 -0
  30. package/unstable-preview-types/-private/transforms/string.d.ts.map +1 -0
  31. package/unstable-preview-types/-private/transforms/transform.d.ts +128 -0
  32. package/unstable-preview-types/-private/transforms/transform.d.ts.map +1 -0
  33. package/unstable-preview-types/-private/utils.d.ts +6 -0
  34. package/unstable-preview-types/-private/utils.d.ts.map +1 -0
  35. package/unstable-preview-types/-private.d.ts +13 -0
  36. package/unstable-preview-types/-private.d.ts.map +1 -0
  37. package/unstable-preview-types/index.d.ts +278 -0
  38. package/unstable-preview-types/index.d.ts.map +1 -0
  39. package/unstable-preview-types/json-api.d.ts +515 -0
  40. package/unstable-preview-types/json-api.d.ts.map +1 -0
  41. package/unstable-preview-types/json.d.ts +1094 -0
  42. package/unstable-preview-types/json.d.ts.map +1 -0
  43. package/unstable-preview-types/rest.d.ts +602 -0
  44. package/unstable-preview-types/rest.d.ts.map +1 -0
  45. package/unstable-preview-types/transform.d.ts +7 -0
  46. package/unstable-preview-types/transform.d.ts.map +1 -0
  47. package/addon/embedded-records-mixin-d75385ff.js.map +0 -1
  48. package/addon/string-22572f80.js.map +0 -1
  49. /package/addon/{utils-075c5b79.js → utils-NcVD2Jb5.js} +0 -0
@@ -0,0 +1,52 @@
1
+ declare module '@ember-data/serializer/-private/transforms/boolean' {
2
+ /**
3
+ @module @ember-data/serializer
4
+ */
5
+ import { TransformName } from '@warp-drive/core-types/symbols';
6
+ /**
7
+ The `BooleanTransform` class is used to serialize and deserialize
8
+ boolean attributes on Ember Data record objects. This transform is
9
+ used when `boolean` is passed as the type parameter to the
10
+ [attr](/ember-data/release/functions/@ember-data%2Fmodel/attr) function.
11
+
12
+ Usage
13
+
14
+ ```app/models/user.js
15
+ import Model, { attr } from '@ember-data/model';
16
+
17
+ export default class UserModel extends Model {
18
+ @attr('boolean') isAdmin;
19
+ @attr('string') name;
20
+ @attr('string') email;
21
+ }
22
+ ```
23
+
24
+ By default, the boolean transform only allows for values of `true` or
25
+ `false`. You can opt into allowing `null` values for
26
+ boolean attributes via `attr('boolean', { allowNull: true })`
27
+
28
+ ```app/models/user.js
29
+ import Model, { attr } from '@ember-data/model';
30
+
31
+ export default class UserModel extends Model {
32
+ @attr('string') email;
33
+ @attr('string') username;
34
+ @attr('boolean', { allowNull: true }) wantsWeeklyEmail;
35
+ }
36
+ ```
37
+
38
+ @class BooleanTransform
39
+ @public
40
+ */
41
+ export default class BooleanTransform {
42
+ deserialize(serialized: boolean | null | number | string, options?: {
43
+ allowNull?: boolean;
44
+ }): boolean | null;
45
+ serialize(deserialized: boolean | null, options?: {
46
+ allowNull?: boolean;
47
+ }): boolean | null;
48
+ [TransformName]: "boolean";
49
+ static create(): BooleanTransform;
50
+ }
51
+ }
52
+ //# sourceMappingURL=boolean.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"boolean.d.ts","sourceRoot":"","sources":["../../../src/-private/transforms/boolean.ts"],"names":[],"mappings":"AAAA;;EAEE;AAEF,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAE/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,CAAC,OAAO,OAAO,gBAAgB;IACnC,WAAW,CAAC,UAAU,EAAE,OAAO,GAAG,IAAI,GAAG,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,GAAG,IAAI;IAgB5G,SAAS,CAAC,YAAY,EAAE,OAAO,GAAG,IAAI,EAAE,OAAO,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,GAAG,IAAI;IAQ1F,CAAC,aAAa,CAAC,YAAsB;IAErC,MAAM,CAAC,MAAM;CAGd"}
@@ -0,0 +1,33 @@
1
+ declare module '@ember-data/serializer/-private/transforms/date' {
2
+ /**
3
+ @module @ember-data/serializer
4
+ */
5
+ import { TransformName } from '@warp-drive/core-types/symbols';
6
+ /**
7
+ The `DateTransform` class is used to serialize and deserialize
8
+ date attributes on Ember Data record objects. This transform is used
9
+ when `date` is passed as the type parameter to the
10
+ [attr](/ember-data/release/functions/@ember-data%2Fmodel/attr) function. It uses the [`ISO 8601`](https://en.wikipedia.org/wiki/ISO_8601)
11
+ standard.
12
+
13
+ ```app/models/score.js
14
+ import Model, { attr, belongsTo } from '@ember-data/model';
15
+
16
+ export default class ScoreModel extends Model {
17
+ @attr('number') value;
18
+ @belongsTo('player') player;
19
+ @attr('date') date;
20
+ }
21
+ ```
22
+
23
+ @class DateTransform
24
+ @public
25
+ */
26
+ export default class DateTransform {
27
+ deserialize(serialized: string | number | null, _options?: Record<string, unknown>): Date | null;
28
+ serialize(date: Date, _options?: Record<string, unknown>): string | null;
29
+ [TransformName]: "date";
30
+ static create(): DateTransform;
31
+ }
32
+ }
33
+ //# sourceMappingURL=date.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../../../src/-private/transforms/date.ts"],"names":[],"mappings":"AAAA;;EAEE;AAEF,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAE/D;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,MAAM,CAAC,OAAO,OAAO,aAAa;IAChC,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAoBlF,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,GAAG,IAAI;IASxE,CAAC,aAAa,CAAC,SAAmB;IAElC,MAAM,CAAC,MAAM;CAGd"}
@@ -0,0 +1,34 @@
1
+ declare module '@ember-data/serializer/-private/transforms/number' {
2
+ /**
3
+ @module @ember-data/serializer
4
+ */
5
+ import { TransformName } from '@warp-drive/core-types/symbols';
6
+ /**
7
+ The `NumberTransform` class is used to serialize and deserialize
8
+ numeric attributes on Ember Data record objects. This transform is
9
+ used when `number` is passed as the type parameter to the
10
+ [attr](/ember-data/release/functions/@ember-data%2Fmodel/attr) function.
11
+
12
+ Usage
13
+
14
+ ```app/models/score.js
15
+ import Model, { attr, belongsTo } from '@ember-data/model';
16
+
17
+ export default class ScoreModel extends Model {
18
+ @attr('number') value;
19
+ @belongsTo('player') player;
20
+ @attr('date') date;
21
+ }
22
+ ```
23
+
24
+ @class NumberTransform
25
+ @public
26
+ */
27
+ export default class NumberTransform {
28
+ deserialize(serialized: string | number | null | undefined, _options?: Record<string, unknown>): number | null;
29
+ serialize(deserialized: string | number | null | undefined, _options?: Record<string, unknown>): number | null;
30
+ [TransformName]: "number";
31
+ static create(): NumberTransform;
32
+ }
33
+ }
34
+ //# sourceMappingURL=number.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"number.d.ts","sourceRoot":"","sources":["../../../src/-private/transforms/number.ts"],"names":[],"mappings":"AAAA;;EAEE;AAEF,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAM/D;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,OAAO,OAAO,eAAe;IAClC,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,GAAG,IAAI;IAU9G,SAAS,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,GAAG,IAAI;IAU9G,CAAC,aAAa,CAAC,WAAqB;IAEpC,MAAM,CAAC,MAAM;CAGd"}
@@ -0,0 +1,34 @@
1
+ declare module '@ember-data/serializer/-private/transforms/string' {
2
+ /**
3
+ @module @ember-data/serializer
4
+ */
5
+ import { TransformName } from '@warp-drive/core-types/symbols';
6
+ /**
7
+ The `StringTransform` class is used to serialize and deserialize
8
+ string attributes on Ember Data record objects. This transform is
9
+ used when `string` is passed as the type parameter to the
10
+ [attr](/ember-data/release/functions/@ember-data%2Fmodel/attr) function.
11
+
12
+ Usage
13
+
14
+ ```app/models/user.js
15
+ import Model, { attr, belongsTo } from '@ember-data/model';
16
+
17
+ export default class UserModel extends Model {
18
+ @attr('boolean') isAdmin;
19
+ @attr('string') name;
20
+ @attr('string') email;
21
+ }
22
+ ```
23
+
24
+ @class StringTransform
25
+ @public
26
+ */
27
+ export default class StringTransform {
28
+ deserialize(serialized: unknown, _options?: Record<string, unknown>): string | null;
29
+ serialize(deserialized: unknown, _options?: Record<string, unknown>): string | null;
30
+ [TransformName]: "string";
31
+ static create(): StringTransform;
32
+ }
33
+ }
34
+ //# sourceMappingURL=string.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../../../src/-private/transforms/string.ts"],"names":[],"mappings":"AAAA;;EAEE;AAEF,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAE/D;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,OAAO,OAAO,eAAe;IAClC,WAAW,CAAC,UAAU,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,GAAG,IAAI;IAGnF,SAAS,CAAC,YAAY,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,GAAG,IAAI;IAInF,CAAC,aAAa,CAAC,WAAqB;IAEpC,MAAM,CAAC,MAAM;CAGd"}
@@ -0,0 +1,128 @@
1
+ declare module '@ember-data/serializer/-private/transforms/transform' {
2
+ /// <reference types="ember-source/types" />
3
+ /**
4
+ @module @ember-data/serializer
5
+ */
6
+ import EmberObject from '@ember/object';
7
+ import type { AttributeSchema } from '@warp-drive/core-types/schema';
8
+ /**
9
+ The `Transform` class is used to serialize and deserialize model
10
+ attributes when they are saved or loaded from an
11
+ adapter. Subclassing `Transform` is useful for creating custom
12
+ attributes. All subclasses of `Transform` must implement a
13
+ `serialize` and a `deserialize` method.
14
+
15
+ Example
16
+
17
+ ```app/transforms/temperature.js
18
+
19
+ // Converts centigrade in the JSON to fahrenheit in the app
20
+ export default class TemperatureTransform {
21
+ deserialize(serialized, options) {
22
+ return (serialized * 1.8) + 32;
23
+ }
24
+
25
+ serialize(deserialized, options) {
26
+ return (deserialized - 32) / 1.8;
27
+ }
28
+
29
+ static create() {
30
+ return new this();
31
+ }
32
+ }
33
+ ```
34
+
35
+ Usage
36
+
37
+ ```app/models/requirement.js
38
+ import Model, { attr } from '@ember-data/model';
39
+
40
+ export default class RequirementModel extends Model {
41
+ @attr('string') name;
42
+ @attr('temperature') temperature;
43
+ }
44
+ ```
45
+
46
+ The options passed into the `attr` function when the attribute is
47
+ declared on the model is also available in the transform.
48
+
49
+ ```app/models/post.js
50
+ import Model, { attr } from '@ember-data/model';
51
+
52
+ export default class PostModel extends Model {
53
+ @attr('string') title;
54
+ @attr('markdown', {
55
+ markdown: {
56
+ gfm: false,
57
+ sanitize: true
58
+ }
59
+ })
60
+ markdown;
61
+ }
62
+ ```
63
+
64
+ ```app/transforms/markdown.js
65
+ export default class MarkdownTransform {
66
+ serialize(deserialized, options) {
67
+ return deserialized.raw;
68
+ }
69
+
70
+ deserialize(serialized, options) {
71
+ let markdownOptions = options.markdown || {};
72
+
73
+ return marked(serialized, markdownOptions);
74
+ }
75
+
76
+ static create() {
77
+ return new this();
78
+ }
79
+ }
80
+ ```
81
+
82
+ @class Transform
83
+ @public
84
+ */
85
+ /**
86
+ When given a deserialized value from a record attribute this
87
+ method must return the serialized value.
88
+
89
+ Example
90
+
91
+ ```javascript
92
+ serialize(deserialized, options) {
93
+ return deserialized ? null : Number(deserialized);
94
+ }
95
+ ```
96
+
97
+ @method serialize
98
+ @public
99
+ @param deserialized The deserialized value
100
+ @param options hash of options passed to `attr`
101
+ @return The serialized value
102
+ */
103
+ /**
104
+ When given a serialized value from a JSON object this method must
105
+ return the deserialized value for the record attribute.
106
+
107
+ Example
108
+
109
+ ```javascript
110
+ deserialize(serialized, options) {
111
+ return empty(serialized) ? null : Number(serialized);
112
+ }
113
+ ```
114
+
115
+ @method deserialize
116
+ @public
117
+ @param serialized The serialized value
118
+ @param options hash of options passed to `attr`
119
+ @return The deserialized value
120
+ */
121
+ interface Transform {
122
+ serialize(value: unknown, options: AttributeSchema['options']): unknown;
123
+ deserialize(value: unknown, options: AttributeSchema['options']): unknown;
124
+ }
125
+ const Transform: typeof EmberObject;
126
+ export default Transform;
127
+ }
128
+ //# sourceMappingURL=transform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../../src/-private/transforms/transform.ts"],"names":[],"mappings":";AAAA;;EAEE;AACF,OAAO,WAAW,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAErE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4EG;AACH;;;;;;;;;;;;;;;;;EAiBE;AACF;;;;;;;;;;;;;;;;;EAiBE;AACF,UAAU,SAAS;IACjB,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC;IACxE,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC;CAC3E;AACD,QAAA,MAAM,SAAS,oBAAc,CAAC;AAE9B,eAAe,SAAS,CAAC"}
@@ -0,0 +1,6 @@
1
+ declare module '@ember-data/serializer/-private/utils' {
2
+ type Coercable = string | number | boolean | null | undefined | symbol;
3
+ export function coerceId(id: Coercable): string | null;
4
+ export {};
5
+ }
6
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/-private/utils.ts"],"names":[],"mappings":"AAAA,KAAK,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAAC;AAEvE,wBAAgB,QAAQ,CAAC,EAAE,EAAE,SAAS,GAAG,MAAM,GAAG,IAAI,CAUrD"}
@@ -0,0 +1,13 @@
1
+ declare module '@ember-data/serializer/-private' {
2
+ /**
3
+ @module @ember-data/serializer
4
+ */
5
+ export { default as EmbeddedRecordsMixin } from '@ember-data/serializer/-private/embedded-records-mixin';
6
+ export { default as Transform } from '@ember-data/serializer/-private/transforms/transform';
7
+ export { default as BooleanTransform } from '@ember-data/serializer/-private/transforms/boolean';
8
+ export { default as DateTransform } from '@ember-data/serializer/-private/transforms/date';
9
+ export { default as NumberTransform } from '@ember-data/serializer/-private/transforms/number';
10
+ export { default as StringTransform } from '@ember-data/serializer/-private/transforms/string';
11
+ export { coerceId } from '@ember-data/serializer/-private/utils';
12
+ }
13
+ //# sourceMappingURL=-private.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"-private.d.ts","sourceRoot":"","sources":["../src/-private.ts"],"names":[],"mappings":"AAAA;;EAEE;AAEF,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AAEpF,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAC5E,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,278 @@
1
+ /// <reference path="./json-api.d.ts" />
2
+ /// <reference path="./transform.d.ts" />
3
+ /// <reference path="./json.d.ts" />
4
+ /// <reference path="./rest.d.ts" />
5
+ /// <reference path="./-private.d.ts" />
6
+ /// <reference path="./-private/utils.d.ts" />
7
+ /// <reference path="./-private/embedded-records-mixin.d.ts" />
8
+ /// <reference path="./-private/transforms/date.d.ts" />
9
+ /// <reference path="./-private/transforms/number.d.ts" />
10
+ /// <reference path="./-private/transforms/transform.d.ts" />
11
+ /// <reference path="./-private/transforms/string.d.ts" />
12
+ /// <reference path="./-private/transforms/boolean.d.ts" />
13
+ declare module '@ember-data/serializer' {
14
+ /**
15
+ ## Overview
16
+
17
+ <blockquote style="margin: 1em; padding: .1em 1em .1em 1em; border-left: solid 1em #E34C32; background: #e0e0e0;">
18
+ <p>
19
+ ⚠️ <strong>This is LEGACY documentation</strong> for a feature that is no longer encouraged to be used.
20
+ If starting a new app or thinking of implementing a new serializer, consider writing a
21
+ <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>
22
+ </p>
23
+ </blockquote>
24
+
25
+ In order to properly manage and present your data, EmberData
26
+ needs to understand the structure of data it receives.
27
+
28
+ `Serializers` convert data between the server's API format and
29
+ the format EmberData understands.
30
+
31
+ Data received from an API response is **normalized** into
32
+ [JSON:API](https://jsonapi.org/) (the format used internally
33
+ by EmberData), while data sent to an API is **serialized**
34
+ into the format the API expects.
35
+
36
+ ### Implementing a Serializer
37
+
38
+ There are only two required serializer methods, one for
39
+ normalizing data from the server API format into JSON:API, and
40
+ another for serializing records via `Snapshots` into the expected
41
+ server API format.
42
+
43
+ To implement a serializer, export a class that conforms to the structure
44
+ described by [<Interface> Serializer](/ember-data/release/classes/%3CInterface%3E%20Serializer)
45
+ from the `app/serializers/` directory. An example is below.
46
+
47
+ ```ts
48
+ import EmberObject from '@ember/object';
49
+
50
+ export default class ApplicationSerializer extends EmberObject {
51
+ normalizeResponse(store, schema, rawPayload) {
52
+ return rawPayload;
53
+ }
54
+
55
+ serialize(snapshot, options) {
56
+ const serializedResource = {
57
+ id: snapshot.id,
58
+ type: snapshot.modelName,
59
+ attributes: snapshot.attributes()
60
+ };
61
+
62
+ return serializedResource;
63
+ }
64
+ }
65
+ ```
66
+
67
+
68
+ ### Serializer Resolution
69
+
70
+ `store.serializerFor(name)` will lookup serializers defined in
71
+ `app/serializers/` and return an instance. If no serializer is found, an
72
+ error will be thrown.
73
+
74
+ `serializerFor` first attempts to find a serializer with an exact match on `name`,
75
+ then falls back to checking for the presence of a serializer named `application`.
76
+
77
+ ```ts
78
+ store.serializerFor('author');
79
+
80
+ // lookup paths (in order) =>
81
+ // app/serializers/author.js
82
+ // app/serializers/application.js
83
+ ```
84
+
85
+ Most requests in EmberData are made with respect to a particular `type` (or `modelName`)
86
+ (e.g., "get me the full collection of **books**" or "get me the **employee** whose id is 37"). We
87
+ refer to this as the **primary** resource `type`.
88
+
89
+ Typically `serializerFor` will be used to find a serializer with a name matching that of the primary
90
+ resource `type` for the request, falling back to the `application` serializer for those types that
91
+ do not have a defined serializer. This is often described as a `per-model` or `per-type` strategy
92
+ for defining serializers. However, because APIs rarely format payloads per-type but rather
93
+ per-API-version, this may not be a desired strategy.
94
+
95
+ It is recommended that applications define only a single `application` adapter and serializer
96
+ where possible.
97
+
98
+ If you have multiple API formats and the per-type strategy is not viable, one strategy is to
99
+ write an `application` adapter and serializer that make use of `options` to specify the desired
100
+ format when making a request.
101
+
102
+ ### Using a Serializer
103
+
104
+ Any serializer in `app/serializers/` can be looked up by `name` using `store.serializerFor(name)`.
105
+
106
+ ### Default Serializers
107
+
108
+ For applications whose APIs are *very close to* or *exactly* the **REST** format or **JSON:API**
109
+ format the `@ember-data/serializer` package contains implementations these applications can
110
+ extend. It also contains a simple `JSONSerializer` for serializing to/from very basic JSON objects.
111
+
112
+ Many applications will find writing their own serializer to be more performant and less
113
+ complex than extending these classes even when their API format is very close to that expected
114
+ by these serializers.
115
+
116
+ It is recommended that apps write their own serializer to best suit the needs of their API and
117
+ application.
118
+
119
+ @module @ember-data/serializer
120
+ @main @ember-data/serializer
121
+ */
122
+ /// <reference types="ember-source/types" />
123
+ import EmberObject from '@ember/object';
124
+ import type Store from '@ember-data/store';
125
+ import type { ModelSchema } from '@ember-data/store/-types/q/ds-model';
126
+ import type { EmptyResourceDocument, SingleResourceDocument } from '@warp-drive/core-types/spec/raw';
127
+ /**
128
+ > ⚠️ CAUTION you likely want the docs for [<Interface> Serializer](/ember-data/release/classes/%3CInterface%3E%20Serializer)
129
+ > as extending this abstract class is unnecessary.
130
+
131
+ `Serializer` is an abstract base class that you may override in your
132
+ application to customize it for your backend. The minimum set of methods
133
+ that you should implement is:
134
+
135
+ * `normalizeResponse()`
136
+ * `serialize()`
137
+
138
+ And you can optionally override the following methods:
139
+
140
+ * `normalize()`
141
+
142
+ For an example implementation, see
143
+ [JSONSerializer](JSONSerializer), the included JSON serializer.
144
+
145
+ @class Serializer
146
+ @public
147
+ @extends Ember.EmberObject
148
+ */
149
+ export default class extends EmberObject {
150
+ store: Store;
151
+ /**
152
+ The `store` property is the application's `store` that contains
153
+ all records. It can be used to look up serializers for other model
154
+ types that may be nested inside the payload response.
155
+
156
+ Example:
157
+
158
+ ```js
159
+ Serializer.extend({
160
+ extractRelationship(relationshipModelName, relationshipHash) {
161
+ let modelClass = this.store.modelFor(relationshipModelName);
162
+ let relationshipSerializer = this.store.serializerFor(relationshipModelName);
163
+ return relationshipSerializer.normalize(modelClass, relationshipHash);
164
+ }
165
+ });
166
+ ```
167
+
168
+ @property store
169
+ @type {Store}
170
+ @public
171
+ */
172
+ /**
173
+ The `normalizeResponse` method is used to normalize a payload from the
174
+ server to a JSON-API Document.
175
+
176
+ http://jsonapi.org/format/#document-structure
177
+
178
+ Example:
179
+
180
+ ```js
181
+ Serializer.extend({
182
+ normalizeResponse(store, primaryModelClass, payload, id, requestType) {
183
+ if (requestType === 'findRecord') {
184
+ return this.normalize(primaryModelClass, payload);
185
+ } else {
186
+ return payload.reduce(function(documentHash, item) {
187
+ let { data, included } = this.normalize(primaryModelClass, item);
188
+ documentHash.included.push(...included);
189
+ documentHash.data.push(data);
190
+ return documentHash;
191
+ }, { data: [], included: [] })
192
+ }
193
+ }
194
+ });
195
+ ```
196
+
197
+ @since 1.13.0
198
+ @method normalizeResponse
199
+ @public
200
+ @param {Store} store
201
+ @param {Model} primaryModelClass
202
+ @param {Object} payload
203
+ @param {String|Number} id
204
+ @param {String} requestType
205
+ @return {Object} JSON-API Document
206
+ */
207
+ /**
208
+ The `serialize` method is used when a record is saved in order to convert
209
+ the record into the form that your external data source expects.
210
+
211
+ `serialize` takes an optional `options` hash with a single option:
212
+
213
+ - `includeId`: If this is `true`, `serialize` should include the ID
214
+ in the serialized object it builds.
215
+
216
+ Example:
217
+
218
+ ```js
219
+ Serializer.extend({
220
+ serialize(snapshot, options) {
221
+ let json = {
222
+ id: snapshot.id
223
+ };
224
+
225
+ snapshot.eachAttribute((key, attribute) => {
226
+ json[key] = snapshot.attr(key);
227
+ });
228
+
229
+ snapshot.eachRelationship((key, relationship) => {
230
+ if (relationship.kind === 'belongsTo') {
231
+ json[key] = snapshot.belongsTo(key, { id: true });
232
+ } else if (relationship.kind === 'hasMany') {
233
+ json[key] = snapshot.hasMany(key, { ids: true });
234
+ }
235
+ });
236
+
237
+ return json;
238
+ },
239
+ });
240
+ ```
241
+
242
+ @method serialize
243
+ @public
244
+ @param {Snapshot} snapshot
245
+ @param {Object} [options]
246
+ @return {Object}
247
+ */
248
+ /**
249
+ The `normalize` method is used to convert a payload received from your
250
+ external data source into the normalized form `store.push()` expects. You
251
+ should override this method, munge the hash and return the normalized
252
+ payload.
253
+
254
+ Example:
255
+
256
+ ```js
257
+ Serializer.extend({
258
+ normalize(modelClass, resourceHash) {
259
+ let data = {
260
+ id: resourceHash.id,
261
+ type: modelClass.modelName,
262
+ attributes: resourceHash
263
+ };
264
+ return { data: data };
265
+ }
266
+ })
267
+ ```
268
+
269
+ @method normalize
270
+ @public
271
+ @param {Model} typeClass
272
+ @param {Object} hash
273
+ @return {Object}
274
+ */
275
+ normalize(_typeClass: ModelSchema, hash: Record<string, unknown>): SingleResourceDocument | EmptyResourceDocument;
276
+ }
277
+ }
278
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2GE;;AAEF,OAAO,WAAW,MAAM,eAAe,CAAC;AAGxC,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAC3C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AACvE,OAAO,KAAK,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAErG;;;;;;;;;;;;;;;;;;;;;EAqBE;AAEF,MAAM,CAAC,OAAO,MAAO,SAAQ,WAAW;IACrB,KAAK,EAAE,KAAK,CAAC;IAC9B;;;;;;;;;;;;;;;;;;;;MAoBE;IAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAkCE;IAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAwCE;IAEF;;;;;;;;;;;;;;;;;;;;;;;;;;MA0BE;IACF,SAAS,CAAC,UAAU,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,sBAAsB,GAAG,qBAAqB;CAGlH"}