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

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