@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,224 +1,223 @@
1
- import type { Store } from '@warp-drive/core';
2
- import type { ModelSchema } from '@warp-drive/core/types';
3
- import type { ObjectValue } from '@warp-drive/core/types/json/raw';
4
- import type { JsonApiDocument, SingleResourceDocument } from '@warp-drive/core/types/spec/json-api-raw';
5
- import type { AdapterPayload } from './minimum-adapter-interface.ts';
6
- import type { Snapshot } from './snapshot.ts';
1
+ import type { Store } from "@warp-drive/core";
2
+ import type { ModelSchema } from "@warp-drive/core/types";
3
+ import type { ObjectValue } from "@warp-drive/core/types/json/raw";
4
+ import type { JsonApiDocument, SingleResourceDocument } from "@warp-drive/core/types/spec/json-api-raw";
5
+ import type { AdapterPayload } from "./minimum-adapter-interface.js";
6
+ import type { Snapshot } from "./snapshot.js";
7
7
  export type SerializerOptions = {
8
- includeId?: boolean;
8
+ includeId?: boolean;
9
9
  };
10
- export type RequestType = 'findRecord' | 'queryRecord' | 'findAll' | 'findBelongsTo' | 'findHasMany' | 'findMany' | 'query' | 'createRecord' | 'deleteRecord' | 'updateRecord';
10
+ export type RequestType = "findRecord" | "queryRecord" | "findAll" | "findBelongsTo" | "findHasMany" | "findMany" | "query" | "createRecord" | "deleteRecord" | "updateRecord";
11
11
  /**
12
- * <blockquote style="margin: 1em; padding: .1em 1em .1em 1em; border-left: solid 1em #E34C32; background: #e0e0e0;">
13
- <p>
14
- ⚠️ <strong>This is LEGACY documentation</strong> for a feature that is no longer encouraged to be used.
15
- If starting a new app or thinking of implementing a new adapter, consider writing a
16
- <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>
17
- </p>
18
- </blockquote>
12
+ * <blockquote style="margin: 1em; padding: .1em 1em .1em 1em; border-left: solid 1em #E34C32; background: #e0e0e0;">
13
+ <p>
14
+ ⚠️ <strong>This is LEGACY documentation</strong> for a feature that is no longer encouraged to be used.
15
+ If starting a new app or thinking of implementing a new adapter, consider writing a
16
+ <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>
17
+ </p>
18
+ </blockquote>
19
19
 
20
- The following documentation describes the methods an application
21
- serializer should implement with descriptions around when an
22
- application might expect these methods to be called.
20
+ The following documentation describes the methods an application
21
+ serializer should implement with descriptions around when an
22
+ application might expect these methods to be called.
23
23
 
24
- Methods that are not required are marked as **optional**.
24
+ Methods that are not required are marked as **optional**.
25
25
 
26
- @class (Interface) Serializer
27
- @public
26
+ @class (Interface) Serializer
27
+ @public
28
28
  */
29
29
  export interface MinimumSerializerInterface {
30
- /**
31
- * This method is responsible for normalizing the value resolved from the promise returned
32
- * by an Adapter request into the format expected by the `Store`.
33
- *
34
- * The output should be a [JSON:API Document](https://jsonapi.org/format/#document-structure)
35
- * with the following additional restrictions:
36
- *
37
- * - `type` should be formatted in the `singular` `dasherized` `lowercase` form
38
- * - `members` (the property names of attributes and relationships) should be formatted
39
- * to match their definition in the corresponding `Model` definition. Typically this
40
- * will be `camelCase`.
41
- * - [`lid`](https://github.com/emberjs/rfcs/blob/main/text/0403-ember-data-identifiers.md) is
42
- * a valid optional sibling to `id` and `type` in both [Resources](https://jsonapi.org/format/#document-resource-objects)
43
- * and [Resource Identifier Objects](https://jsonapi.org/format/#document-resource-identifier-objects)
44
- *
45
- * @public
46
- * @param {Store} store The store service that initiated the request being normalized
47
- * @param {ModelSchema} schema An object with methods for accessing information about
48
- * the type, attributes and relationships of the primary type associated with the request.
49
- * @param {JSONObject} rawPayload The raw JSON response data returned from an API request.
50
- * This correlates to the value the promise returned by the adapter method that performed
51
- * the request resolved to.
52
- * @param {string|null} id For a findRecord request, this is the id initially provided
53
- * in the call to store.findRecord. Else this value is null.
54
- * @param {'findRecord' | 'queryRecord' | 'findAll' | 'findBelongsTo' | 'findHasMany' | 'findMany' | 'query' | 'createRecord' | 'deleteRecord' | 'updateRecord'} requestType The
55
- * type of request the Adapter had been asked to perform.
56
- *
57
- * @return {JsonApiDocument} a document following the structure of a JSON:API Document.
58
- */
59
- normalizeResponse(store: Store, schema: ModelSchema, rawPayload: AdapterPayload, id: string | null, requestType: 'findRecord' | 'queryRecord' | 'findAll' | 'findBelongsTo' | 'findHasMany' | 'findMany' | 'query' | 'createRecord' | 'deleteRecord' | 'updateRecord'): JsonApiDocument;
60
- /**
61
- * This method is responsible for serializing an individual record
62
- * via a [Snapshot](Snapshot) into the format expected by the API.
63
- *
64
- * This method is called by `snapshot.serialize()`.
65
- *
66
- * When using `Model`, this method is called by `record.serialize()`.
67
- *
68
- * When using `JSONAPIAdapter` or `RESTAdapter` this method is called
69
- * by `updateRecord` and `createRecord` if `Serializer.serializeIntoHash`
70
- * is not implemented.
71
- *
72
- * @public
73
- * @param {Snapshot} snapshot A Snapshot for the record to serialize
74
- * @param {Object} [options]
75
- */
76
- serialize(snapshot: Snapshot, options?: SerializerOptions): ObjectValue;
77
- /**
78
- * This method is intended to normalize data into a [JSON:API Document](https://jsonapi.org/format/#document-structure)
79
- * with a data member containing a single [Resource](https://jsonapi.org/format/#document-resource-objects).
80
- *
81
- * - `type` should be formatted in the singular, dasherized and lowercase form
82
- * - `members` (the property names of attributes and relationships) should be formatted
83
- * to match their definition in the corresponding `Model` definition. Typically this
84
- * will be `camelCase`.
85
- * - [`lid`](https://github.com/emberjs/rfcs/blob/main/text/0403-ember-data-identifiers.md) is
86
- * a valid optional sibling to `id` and `type` in both [Resources](https://jsonapi.org/format/#document-resource-objects)
87
- * and [Resource Identifier Objects](https://jsonapi.org/format/#document-resource-identifier-objects)
88
- *
89
- * This method is called by the `Store` when `store.normalize(modelName, payload)` is
90
- * called. It is recommended to use `store.serializerFor(modelName).normalizeResponse`
91
- * over `store.normalize`.
92
- *
93
- * This method may be called when also using the `RESTSerializer`
94
- * when `serializer.pushPayload` is called by `store.pushPayload`.
95
- * However, it is recommended to use `store.push` over `store.pushPayload` after normalizing
96
- * the payload directly.
97
- *
98
- * Example:
99
- * ```js
100
- * function pushPayload(store, modelName, rawPayload) {
101
- * const ModelClass = store.modelFor(modelName);
102
- * const serializer = store.serializerFor(modelName);
103
- * const jsonApiPayload = serializer.normalizeResponse(store, ModelClass, rawPayload, null, 'query');
104
- *
105
- * return store.push(jsonApiPayload);
106
- * }
107
- * ```
108
- *
109
- * This method may be called when also using the `JSONAPISerializer`
110
- * when normalizing included records. If mixing serializer usage in this way
111
- * we recommend implementing this method, but caution that it may lead
112
- * to unexpected mixing of formats.
113
- *
114
- * This method may also be called when normalizing embedded relationships when
115
- * using the `EmbeddedRecordsMixin`. If using this mixin in a serializer in
116
- * your application we recommend implementing this method, but caution that
117
- * it may lead to unexpected mixing of formats.
118
- *
119
- * @public
120
- * @optional
121
- * @param {ModelSchema} schema An object with methods for accessing information about
122
- * the type, attributes and relationships of the primary type associated with the request.
123
- * @param {JSONObject} rawPayload Some raw JSON data to be normalized into a JSON:API Resource.
124
- * @param {String} [prop] When called by the EmbeddedRecordsMixin this param will be the
125
- * property at which the object provided as rawPayload was found.
126
- * @return {SingleResourceDocument} A JSON:API Document
127
- * containing a single JSON:API Resource
128
- * as its primary data.
129
- */
130
- normalize?(schema: ModelSchema, rawPayload: ObjectValue, prop?: string): SingleResourceDocument;
131
- /**
132
- * When using `JSONAPIAdapter` or `RESTAdapter` this method is called
133
- * by `adapter.updateRecord` and `adapter.createRecord` if `serializer.serializeIntoHash`
134
- * is implemented. If this method is not implemented, `serializer.serialize`
135
- * will be called in this case.
136
- *
137
- * You can use this method to customize the root keys serialized into the payload.
138
- * The hash property should be modified by reference.
139
- *
140
- * For instance, your API may expect resources to be keyed by underscored type in the payload:
141
- *
142
- * ```js
143
- * {
144
- * _user: {
145
- * type: 'user',
146
- * id: '1'
147
- * }
148
- * }
149
- * ```
150
- *
151
- * Which when using these adapters can be achieved by implementing this method similar
152
- * to the following:
153
- *
154
- * ```js
155
- * serializeIntoHash(hash, ModelClass, snapshot, options) {
156
- * hash[`_${snapshot.modelName}`] = this.serialize(snapshot, options).data;
157
- * }
158
- * ```
159
- *
160
- * @public
161
- * @optional
162
- * @param hash A top most object of the request payload onto
163
- * which to append the serialized record
164
- * @param {ModelSchema} schema An object with methods for accessing information about
165
- * the type, attributes and relationships of the primary type associated with the request.
166
- * @param {Snapshot} snapshot A Snapshot for the record to serialize
167
- * @param [options]
168
- * @return {void}
169
- */
170
- serializeIntoHash?(hash: object, schema: ModelSchema, snapshot: Snapshot, options?: SerializerOptions): void;
171
- /**
172
- * This method allows for normalization of data when `store.pushPayload` is called
173
- * and should be implemented if you want to use that method.
174
- *
175
- * The method is responsible for pushing new data to the store using `store.push`
176
- * once any necessary normalization has occurred, and no data in the store will be
177
- * updated unless it does so.
178
- *
179
- * The normalized form pushed to the store should be a [JSON:API Document](https://jsonapi.org/format/#document-structure)
180
- * with the following additional restrictions:
181
- *
182
- * - `type` should be formatted in the singular, dasherized and lowercase form
183
- * - `members` (the property names of attributes and relationships) should be formatted
184
- * to match their definition in the corresponding `Model` definition. Typically this
185
- * will be `camelCase`.
186
- * - [`lid`](https://github.com/emberjs/rfcs/blob/main/text/0403-ember-data-identifiers.md) is
187
- * a valid optional sibling to `id` and `type` in both [Resources](https://jsonapi.org/format/#document-resource-objects)
188
- * and [Resource Identifier Objects](https://jsonapi.org/format/#document-resource-identifier-objects)
189
- *
190
- * If you need better control over normalization or want access to the records being added or updated
191
- * in the store, we recommended using `store.push` over `store.pushPayload` after normalizing
192
- * the payload directly. This can even take advantage of an existing serializer for the format
193
- * the data is in, for example:
194
- *
195
- * ```js
196
- * function pushPayload(store, modelName, rawPayload) {
197
- * const ModelClass = store.modelFor(modelName);
198
- * const serializer = store.serializerFor(modelName);
199
- * const jsonApiPayload = serializer.normalizeResponse(store, ModelClass, rawPayload, null, 'query');
200
- *
201
- * return store.push(jsonApiPayload);
202
- * }
203
- * ```
204
- *
205
- * @public
206
- * @optional
207
- * @param {Store} store The store service that initiated the request being normalized
208
- * @param {Object} rawPayload The raw JSON response data returned from an API request.
209
- * This JSON should be in the API format expected by the serializer.
210
- * @return {void}
211
- */
212
- pushPayload?(store: Store, rawPayload: ObjectValue): void;
213
- /**
214
- * In some situations the serializer may need to perform cleanup when destroyed,
215
- * that cleanup can be done in `destroy`.
216
- *
217
- * If not implemented, the store does not inform the serializer of destruction.
218
- *
219
- * @public
220
- * @optional
221
- */
222
- destroy?(): void;
30
+ /**
31
+ * This method is responsible for normalizing the value resolved from the promise returned
32
+ * by an Adapter request into the format expected by the `Store`.
33
+ *
34
+ * The output should be a [JSON:API Document](https://jsonapi.org/format/#document-structure)
35
+ * with the following additional restrictions:
36
+ *
37
+ * - `type` should be formatted in the `singular` `dasherized` `lowercase` form
38
+ * - `members` (the property names of attributes and relationships) should be formatted
39
+ * to match their definition in the corresponding `Model` definition. Typically this
40
+ * will be `camelCase`.
41
+ * - [`lid`](https://github.com/emberjs/rfcs/blob/main/text/0403-ember-data-identifiers.md) is
42
+ * a valid optional sibling to `id` and `type` in both [Resources](https://jsonapi.org/format/#document-resource-objects)
43
+ * and [Resource Identifier Objects](https://jsonapi.org/format/#document-resource-identifier-objects)
44
+ *
45
+ * @public
46
+ * @param {Store} store The store service that initiated the request being normalized
47
+ * @param {ModelSchema} schema An object with methods for accessing information about
48
+ * the type, attributes and relationships of the primary type associated with the request.
49
+ * @param {JSONObject} rawPayload The raw JSON response data returned from an API request.
50
+ * This correlates to the value the promise returned by the adapter method that performed
51
+ * the request resolved to.
52
+ * @param {string|null} id For a findRecord request, this is the id initially provided
53
+ * in the call to store.findRecord. Else this value is null.
54
+ * @param {'findRecord' | 'queryRecord' | 'findAll' | 'findBelongsTo' | 'findHasMany' | 'findMany' | 'query' | 'createRecord' | 'deleteRecord' | 'updateRecord'} requestType The
55
+ * type of request the Adapter had been asked to perform.
56
+ *
57
+ * @return {JsonApiDocument} a document following the structure of a JSON:API Document.
58
+ */
59
+ normalizeResponse(store: Store, schema: ModelSchema, rawPayload: AdapterPayload, id: string | null, requestType: "findRecord" | "queryRecord" | "findAll" | "findBelongsTo" | "findHasMany" | "findMany" | "query" | "createRecord" | "deleteRecord" | "updateRecord"): JsonApiDocument;
60
+ /**
61
+ * This method is responsible for serializing an individual record
62
+ * via a [Snapshot](Snapshot) into the format expected by the API.
63
+ *
64
+ * This method is called by `snapshot.serialize()`.
65
+ *
66
+ * When using `Model`, this method is called by `record.serialize()`.
67
+ *
68
+ * When using `JSONAPIAdapter` or `RESTAdapter` this method is called
69
+ * by `updateRecord` and `createRecord` if `Serializer.serializeIntoHash`
70
+ * is not implemented.
71
+ *
72
+ * @public
73
+ * @param {Snapshot} snapshot A Snapshot for the record to serialize
74
+ * @param {Object} [options]
75
+ */
76
+ serialize(snapshot: Snapshot, options?: SerializerOptions): ObjectValue;
77
+ /**
78
+ * This method is intended to normalize data into a [JSON:API Document](https://jsonapi.org/format/#document-structure)
79
+ * with a data member containing a single [Resource](https://jsonapi.org/format/#document-resource-objects).
80
+ *
81
+ * - `type` should be formatted in the singular, dasherized and lowercase form
82
+ * - `members` (the property names of attributes and relationships) should be formatted
83
+ * to match their definition in the corresponding `Model` definition. Typically this
84
+ * will be `camelCase`.
85
+ * - [`lid`](https://github.com/emberjs/rfcs/blob/main/text/0403-ember-data-identifiers.md) is
86
+ * a valid optional sibling to `id` and `type` in both [Resources](https://jsonapi.org/format/#document-resource-objects)
87
+ * and [Resource Identifier Objects](https://jsonapi.org/format/#document-resource-identifier-objects)
88
+ *
89
+ * This method is called by the `Store` when `store.normalize(modelName, payload)` is
90
+ * called. It is recommended to use `store.serializerFor(modelName).normalizeResponse`
91
+ * over `store.normalize`.
92
+ *
93
+ * This method may be called when also using the `RESTSerializer`
94
+ * when `serializer.pushPayload` is called by `store.pushPayload`.
95
+ * However, it is recommended to use `store.push` over `store.pushPayload` after normalizing
96
+ * the payload directly.
97
+ *
98
+ * Example:
99
+ * ```js
100
+ * function pushPayload(store, modelName, rawPayload) {
101
+ * const ModelClass = store.modelFor(modelName);
102
+ * const serializer = store.serializerFor(modelName);
103
+ * const jsonApiPayload = serializer.normalizeResponse(store, ModelClass, rawPayload, null, 'query');
104
+ *
105
+ * return store.push(jsonApiPayload);
106
+ * }
107
+ * ```
108
+ *
109
+ * This method may be called when also using the `JSONAPISerializer`
110
+ * when normalizing included records. If mixing serializer usage in this way
111
+ * we recommend implementing this method, but caution that it may lead
112
+ * to unexpected mixing of formats.
113
+ *
114
+ * This method may also be called when normalizing embedded relationships when
115
+ * using the `EmbeddedRecordsMixin`. If using this mixin in a serializer in
116
+ * your application we recommend implementing this method, but caution that
117
+ * it may lead to unexpected mixing of formats.
118
+ *
119
+ * @public
120
+ * @optional
121
+ * @param {ModelSchema} schema An object with methods for accessing information about
122
+ * the type, attributes and relationships of the primary type associated with the request.
123
+ * @param {JSONObject} rawPayload Some raw JSON data to be normalized into a JSON:API Resource.
124
+ * @param {String} [prop] When called by the EmbeddedRecordsMixin this param will be the
125
+ * property at which the object provided as rawPayload was found.
126
+ * @return {SingleResourceDocument} A JSON:API Document
127
+ * containing a single JSON:API Resource
128
+ * as its primary data.
129
+ */
130
+ normalize?(schema: ModelSchema, rawPayload: ObjectValue, prop?: string): SingleResourceDocument;
131
+ /**
132
+ * When using `JSONAPIAdapter` or `RESTAdapter` this method is called
133
+ * by `adapter.updateRecord` and `adapter.createRecord` if `serializer.serializeIntoHash`
134
+ * is implemented. If this method is not implemented, `serializer.serialize`
135
+ * will be called in this case.
136
+ *
137
+ * You can use this method to customize the root keys serialized into the payload.
138
+ * The hash property should be modified by reference.
139
+ *
140
+ * For instance, your API may expect resources to be keyed by underscored type in the payload:
141
+ *
142
+ * ```js
143
+ * {
144
+ * _user: {
145
+ * type: 'user',
146
+ * id: '1'
147
+ * }
148
+ * }
149
+ * ```
150
+ *
151
+ * Which when using these adapters can be achieved by implementing this method similar
152
+ * to the following:
153
+ *
154
+ * ```js
155
+ * serializeIntoHash(hash, ModelClass, snapshot, options) {
156
+ * hash[`_${snapshot.modelName}`] = this.serialize(snapshot, options).data;
157
+ * }
158
+ * ```
159
+ *
160
+ * @public
161
+ * @optional
162
+ * @param hash A top most object of the request payload onto
163
+ * which to append the serialized record
164
+ * @param {ModelSchema} schema An object with methods for accessing information about
165
+ * the type, attributes and relationships of the primary type associated with the request.
166
+ * @param {Snapshot} snapshot A Snapshot for the record to serialize
167
+ * @param [options]
168
+ * @return {void}
169
+ */
170
+ serializeIntoHash?(hash: object, schema: ModelSchema, snapshot: Snapshot, options?: SerializerOptions): void;
171
+ /**
172
+ * This method allows for normalization of data when `store.pushPayload` is called
173
+ * and should be implemented if you want to use that method.
174
+ *
175
+ * The method is responsible for pushing new data to the store using `store.push`
176
+ * once any necessary normalization has occurred, and no data in the store will be
177
+ * updated unless it does so.
178
+ *
179
+ * The normalized form pushed to the store should be a [JSON:API Document](https://jsonapi.org/format/#document-structure)
180
+ * with the following additional restrictions:
181
+ *
182
+ * - `type` should be formatted in the singular, dasherized and lowercase form
183
+ * - `members` (the property names of attributes and relationships) should be formatted
184
+ * to match their definition in the corresponding `Model` definition. Typically this
185
+ * will be `camelCase`.
186
+ * - [`lid`](https://github.com/emberjs/rfcs/blob/main/text/0403-ember-data-identifiers.md) is
187
+ * a valid optional sibling to `id` and `type` in both [Resources](https://jsonapi.org/format/#document-resource-objects)
188
+ * and [Resource Identifier Objects](https://jsonapi.org/format/#document-resource-identifier-objects)
189
+ *
190
+ * If you need better control over normalization or want access to the records being added or updated
191
+ * in the store, we recommended using `store.push` over `store.pushPayload` after normalizing
192
+ * the payload directly. This can even take advantage of an existing serializer for the format
193
+ * the data is in, for example:
194
+ *
195
+ * ```js
196
+ * function pushPayload(store, modelName, rawPayload) {
197
+ * const ModelClass = store.modelFor(modelName);
198
+ * const serializer = store.serializerFor(modelName);
199
+ * const jsonApiPayload = serializer.normalizeResponse(store, ModelClass, rawPayload, null, 'query');
200
+ *
201
+ * return store.push(jsonApiPayload);
202
+ * }
203
+ * ```
204
+ *
205
+ * @public
206
+ * @optional
207
+ * @param {Store} store The store service that initiated the request being normalized
208
+ * @param {Object} rawPayload The raw JSON response data returned from an API request.
209
+ * This JSON should be in the API format expected by the serializer.
210
+ * @return {void}
211
+ */
212
+ pushPayload?(store: Store, rawPayload: ObjectValue): void;
213
+ /**
214
+ * In some situations the serializer may need to perform cleanup when destroyed,
215
+ * that cleanup can be done in `destroy`.
216
+ *
217
+ * If not implemented, the store does not inform the serializer of destruction.
218
+ *
219
+ * @public
220
+ * @optional
221
+ */
222
+ destroy?(): void;
223
223
  }
224
- //# sourceMappingURL=minimum-serializer-interface.d.ts.map
@@ -1,7 +1,6 @@
1
- import type { Store } from '@warp-drive/core';
2
- import type { ModelSchema } from '@warp-drive/core/types';
3
- import type { JsonApiDocument } from '@warp-drive/core/types/spec/json-api-raw';
4
- import type { AdapterPayload } from './minimum-adapter-interface.ts';
5
- import type { MinimumSerializerInterface, RequestType } from './minimum-serializer-interface.ts';
1
+ import type { Store } from "@warp-drive/core";
2
+ import type { ModelSchema } from "@warp-drive/core/types";
3
+ import type { JsonApiDocument } from "@warp-drive/core/types/spec/json-api-raw";
4
+ import type { AdapterPayload } from "./minimum-adapter-interface.js";
5
+ import type { MinimumSerializerInterface, RequestType } from "./minimum-serializer-interface.js";
6
6
  export declare function normalizeResponseHelper(serializer: MinimumSerializerInterface | null, store: Store, modelClass: ModelSchema, payload: AdapterPayload, id: string | null, requestType: RequestType): JsonApiDocument;
7
- //# sourceMappingURL=serializer-response.d.ts.map
@@ -1,89 +1,88 @@
1
- import type { Store } from '@warp-drive/core';
2
- import type { LiveArray } from '@warp-drive/core/store/-private';
3
- import type { FindAllOptions, ModelSchema } from '@warp-drive/core/types';
4
- import type { Snapshot } from './snapshot.ts';
1
+ import type { Store } from "@warp-drive/core";
2
+ import type { LiveArray } from "@warp-drive/core/store/-private";
3
+ import type { FindAllOptions, ModelSchema } from "@warp-drive/core/types";
4
+ import type { Snapshot } from "./snapshot.js";
5
5
  /**
6
- SnapshotRecordArray is not directly instantiable.
7
- Instances are provided to consuming application's
8
- adapters for certain `findAll` requests.
6
+ SnapshotRecordArray is not directly instantiable.
7
+ Instances are provided to consuming application's
8
+ adapters for certain `findAll` requests.
9
9
 
10
- @class SnapshotRecordArray
11
- @public
10
+ @class SnapshotRecordArray
11
+ @public
12
12
  */
13
13
  export declare class SnapshotRecordArray {
14
- _snapshots: Snapshot[] | null;
15
- _type: ModelSchema | null;
16
- modelName: string;
17
- __store: Store;
18
- adapterOptions?: Record<string, unknown>;
19
- include?: string | string[];
20
- /**
21
- SnapshotRecordArray is not directly instantiable.
22
- Instances are provided to consuming application's
23
- adapters and serializers for certain requests.
24
-
25
- @private
26
- @constructor
27
- @param {Store} store
28
- @param {String} type
29
- @param options
30
- */
31
- constructor(store: Store, type: string, options?: FindAllOptions);
32
- /**
33
- An array of records
34
-
35
- @property _recordArray
36
- @private
37
- @type {Array}
38
- */
39
- get _recordArray(): LiveArray;
40
- /**
41
- Number of records in the array
42
-
43
- Example
44
-
45
- ```js [app/adapters/post.js]
46
- import JSONAPIAdapter from '@ember-data/adapter/json-api';
47
-
48
- export default class PostAdapter extends JSONAPIAdapter {
49
- shouldReloadAll(store, snapshotRecordArray) {
50
- return !snapshotRecordArray.length;
51
- }
52
- });
53
- ```
54
-
55
- @property length
56
- @public
57
- @type {Number}
58
- */
59
- get length(): number;
60
- /**
61
- Get snapshots of the underlying record array
62
-
63
- Example
64
-
65
- ```js [app/adapters/post.js]
66
- import JSONAPIAdapter from '@ember-data/adapter/json-api';
67
-
68
- export default class PostAdapter extends JSONAPIAdapter {
69
- shouldReloadAll(store, snapshotArray) {
70
- let snapshots = snapshotArray.snapshots();
71
-
72
- return snapshots.any(function(ticketSnapshot) {
73
- let timeDiff = moment().diff(ticketSnapshot.attr('lastAccessedAt'), 'minutes');
74
- if (timeDiff > 20) {
75
- return true;
76
- } else {
77
- return false;
78
- }
79
- });
80
- }
81
- }
82
- ```
83
-
84
- @public
85
- @return {Array} Array of snapshots
86
- */
87
- snapshots(): Snapshot<unknown>[];
14
+ _snapshots: Snapshot[] | null;
15
+ _type: ModelSchema | null;
16
+ modelName: string;
17
+ __store: Store;
18
+ adapterOptions?: Record<string, unknown>;
19
+ include?: string | string[];
20
+ /**
21
+ SnapshotRecordArray is not directly instantiable.
22
+ Instances are provided to consuming application's
23
+ adapters and serializers for certain requests.
24
+
25
+ @private
26
+ @constructor
27
+ @param {Store} store
28
+ @param {String} type
29
+ @param options
30
+ */
31
+ constructor(store: Store, type: string, options?: FindAllOptions);
32
+ /**
33
+ An array of records
34
+
35
+ @property _recordArray
36
+ @private
37
+ @type {Array}
38
+ */
39
+ get _recordArray(): LiveArray;
40
+ /**
41
+ Number of records in the array
42
+
43
+ Example
44
+
45
+ ```js [app/adapters/post.js]
46
+ import JSONAPIAdapter from '@ember-data/adapter/json-api';
47
+
48
+ export default class PostAdapter extends JSONAPIAdapter {
49
+ shouldReloadAll(store, snapshotRecordArray) {
50
+ return !snapshotRecordArray.length;
51
+ }
52
+ });
53
+ ```
54
+
55
+ @property length
56
+ @public
57
+ @type {Number}
58
+ */
59
+ get length(): number;
60
+ /**
61
+ Get snapshots of the underlying record array
62
+
63
+ Example
64
+
65
+ ```js [app/adapters/post.js]
66
+ import JSONAPIAdapter from '@ember-data/adapter/json-api';
67
+
68
+ export default class PostAdapter extends JSONAPIAdapter {
69
+ shouldReloadAll(store, snapshotArray) {
70
+ let snapshots = snapshotArray.snapshots();
71
+
72
+ return snapshots.any(function(ticketSnapshot) {
73
+ let timeDiff = moment().diff(ticketSnapshot.attr('lastAccessedAt'), 'minutes');
74
+ if (timeDiff > 20) {
75
+ return true;
76
+ } else {
77
+ return false;
78
+ }
79
+ });
80
+ }
81
+ }
82
+ ```
83
+
84
+ @public
85
+ @return Array of snapshots
86
+ */
87
+ snapshots(): Snapshot[];
88
88
  }
89
- //# sourceMappingURL=snapshot-record-array.d.ts.map