@warp-drive/legacy 5.6.0-alpha.15 → 5.6.0-alpha.18

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