@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,801 +1,777 @@
1
1
  /**
2
- * ## Overview
3
- *
4
- * <blockquote style="margin: 1em; padding: .1em 1em .1em 1em; border-left: solid 1em #E34C32; background: #e0e0e0;">
5
- * <p>
6
- * ⚠️ <strong>This is LEGACY documentation</strong> for a feature that is no longer encouraged to be used.
7
- * If starting a new app or thinking of implementing a new adapter, consider writing a
8
- * <a href="/ember-data/release/classes/%3CInterface%3E%20Handler">Handler</a> instead to be used with the <a href="https://github.com/emberjs/data/tree/main/packages/request#readme">RequestManager</a>
9
- * </p>
10
- * </blockquote>
11
- *
12
- * In order to properly fetch and update data, @warp-drive/legacy
13
- * needs to understand how to connect to your API.
14
- *
15
- * `Adapters` accept various kinds of requests from the store
16
- * and manage fulfillment of the request from your API.
17
- *
18
- * ### Request Flow
19
- *
20
- * When the store decides it needs to issue a request it uses the following flow to manage the request and process the data.
21
- *
22
- * - find the appropriate adapter
23
- * - issue the request to the adapter
24
- * - await the adapter's response
25
- * - if an error occurs reject with the error
26
- * - if no error
27
- * - if there is response data
28
- * - pass the response data to the appropriate serializer
29
- * - update the cache using the JSON:API formatted data from the serializer's response
30
- * - return the primary record(s) associated with the request
31
- *
32
- * ### Request Errors
33
- *
34
- * When a request errors and your adapter does not have the ability to recover from the error,
35
- * you may either reject the promise returned by your adapter method with the error or simply
36
- * throw the error.
37
- *
38
- * If the request was for a `createRecord` `updateRecord` or `deleteRecord` special rules
39
- * apply to how this error will affect the state of the store and additional properties on
40
- * the `Error` class may be used. See the documentation for these methods in
41
- * {@link MinimumAdapterInterface} for more information.
42
- *
43
- * ### Implementing an Adapter
44
- *
45
- * There are seven required adapter methods, one for each of
46
- * the primary request types that @warp-drive/legacy issues.
47
- *
48
- * They are:
49
- *
50
- * - findRecord
51
- * - findAll
52
- * - queryRecord
53
- * - query
54
- * - createRecord
55
- * - updateRecord
56
- * - deleteRecord
57
- *
58
- * Each of these request types has a matching store method that triggers it
59
- * and matching `requestType` that is passed to the serializer's
60
- * `normalizeResponse` method.
61
- *
62
- * If your app only reads data but never writes data, it is not necessary
63
- * to implement the methods for create, update, and delete. This extends to
64
- * all of the store's find methods with the exception of `findRecord` (`findAll`,
65
- * `query`, `queryRecord`): if you do not use the store method in your app then
66
- * your Adapter does not need the method.
67
- *
68
- * ```ts
69
- * async function fetchData(url, options = {}) {
70
- * let response = await fetch(url, options);
71
- * return response.toJSON();
72
- * }
73
- *
74
- * export default class ApplicationAdapter {
75
- * findRecord(_, { modelName }, id) {
76
- * return fetchData(`./${modelName}s/${id}`);
77
- * }
78
- *
79
- * static create() {
80
- * return new this();
81
- * }
82
- * }
83
- * ```
84
- *
85
- * ### Adapter Resolution
86
- *
87
- * `store.adapterFor(name)` will lookup adapters defined in `app/adapters/` and
88
- * return an instance.
89
- *
90
- * `adapterFor` first attempts to find an adapter with an exact match on `name`,
91
- then falls back to checking for the presence of an adapter named `application`.
92
-
93
- If no adapter is found, an error will be thrown.
94
-
95
- ```ts
96
- store.adapterFor('author');
97
-
98
- // lookup paths (in order) =>
99
- // app/adapters/author.js
100
- // app/adapters/application.js
101
- ```
102
-
103
- Most requests in @warp-drive/legacy are made with respect to a particular `type` (or `modelName`)
104
- (e.g., "get me the full collection of **books**" or "get me the **employee** whose id is 37"). We
105
- refer to this as the **primary** resource `type`.
106
-
107
- `adapterFor` is used by the store to find an adapter with a name matching that of the primary
108
- resource `type` for the request, which then falls back to the `application` adapter.
109
-
110
- It is recommended that applications define only a single `application` adapter and serializer
111
- where possible, only implementing an adapter specific to the `type` when absolutely necessary.
112
-
113
- If you need to support multiple API versions for the same type, the per-type strategy for
114
- defining adapters might not be adequate.
115
-
116
- If you have multiple APIs or multiple API versions and the single application adapter and per-type
117
- strategy does not suite your needs, one strategy is to write an `application` adapter and serializer
118
- that make use of `options` to specify the desired format when making a request, then forwards to the
119
- request to the desired adapter or serializer as needed.
120
-
121
- ```js [app/adapters/application.js]
122
- export default class Adapter extends EmberObject {
123
- findRecord(store, schema, id, snapshot) {
124
- let { apiVersion } = snapshot.adapterOptions;
125
- return this.adapterFor(`-api-${apiVersion}`).findRecord(store, schema, id, snapshot);
126
- }
127
- }
128
- ```
129
-
130
- ### Overriding `Store.adapterFor`
131
-
132
- ```js
133
- import Store from '@ember-data/store';
134
- import Adapter from '@ember-data/adapter/json-api';
135
-
136
- class extends Store {
137
- #adapter = new Adapter();
138
-
139
- adapterFor() {
140
- return this.#adapter;
141
- }
142
- }
143
- ```
2
+ * ## Overview
3
+ *
4
+ * <blockquote style="margin: 1em; padding: .1em 1em .1em 1em; border-left: solid 1em #E34C32; background: #e0e0e0;">
5
+ * <p>
6
+ * ⚠️ <strong>This is LEGACY documentation</strong> for a feature that is no longer encouraged to be used.
7
+ * If starting a new app or thinking of implementing a new adapter, consider writing a
8
+ * <a href="/ember-data/release/classes/%3CInterface%3E%20Handler">Handler</a> instead to be used with the <a href="https://github.com/emberjs/data/tree/main/packages/request#readme">RequestManager</a>
9
+ * </p>
10
+ * </blockquote>
11
+ *
12
+ * In order to properly fetch and update data, @warp-drive/legacy
13
+ * needs to understand how to connect to your API.
14
+ *
15
+ * `Adapters` accept various kinds of requests from the store
16
+ * and manage fulfillment of the request from your API.
17
+ *
18
+ * ### Request Flow
19
+ *
20
+ * When the store decides it needs to issue a request it uses the following flow to manage the request and process the data.
21
+ *
22
+ * - find the appropriate adapter
23
+ * - issue the request to the adapter
24
+ * - await the adapter's response
25
+ * - if an error occurs reject with the error
26
+ * - if no error
27
+ * - if there is response data
28
+ * - pass the response data to the appropriate serializer
29
+ * - update the cache using the JSON:API formatted data from the serializer's response
30
+ * - return the primary record(s) associated with the request
31
+ *
32
+ * ### Request Errors
33
+ *
34
+ * When a request errors and your adapter does not have the ability to recover from the error,
35
+ * you may either reject the promise returned by your adapter method with the error or simply
36
+ * throw the error.
37
+ *
38
+ * If the request was for a `createRecord` `updateRecord` or `deleteRecord` special rules
39
+ * apply to how this error will affect the state of the store and additional properties on
40
+ * the `Error` class may be used. See the documentation for these methods in
41
+ * {@link MinimumAdapterInterface} for more information.
42
+ *
43
+ * ### Implementing an Adapter
44
+ *
45
+ * There are seven required adapter methods, one for each of
46
+ * the primary request types that @warp-drive/legacy issues.
47
+ *
48
+ * They are:
49
+ *
50
+ * - findRecord
51
+ * - findAll
52
+ * - queryRecord
53
+ * - query
54
+ * - createRecord
55
+ * - updateRecord
56
+ * - deleteRecord
57
+ *
58
+ * Each of these request types has a matching store method that triggers it
59
+ * and matching `requestType` that is passed to the serializer's
60
+ * `normalizeResponse` method.
61
+ *
62
+ * If your app only reads data but never writes data, it is not necessary
63
+ * to implement the methods for create, update, and delete. This extends to
64
+ * all of the store's find methods with the exception of `findRecord` (`findAll`,
65
+ * `query`, `queryRecord`): if you do not use the store method in your app then
66
+ * your Adapter does not need the method.
67
+ *
68
+ * ```ts
69
+ * async function fetchData(url, options = {}) {
70
+ * let response = await fetch(url, options);
71
+ * return response.toJSON();
72
+ * }
73
+ *
74
+ * export default class ApplicationAdapter {
75
+ * findRecord(_, { modelName }, id) {
76
+ * return fetchData(`./${modelName}s/${id}`);
77
+ * }
78
+ *
79
+ * static create() {
80
+ * return new this();
81
+ * }
82
+ * }
83
+ * ```
84
+ *
85
+ * ### Adapter Resolution
86
+ *
87
+ * `store.adapterFor(name)` will lookup adapters defined in `app/adapters/` and
88
+ * return an instance.
89
+ *
90
+ * `adapterFor` first attempts to find an adapter with an exact match on `name`,
91
+ then falls back to checking for the presence of an adapter named `application`.
92
+
93
+ If no adapter is found, an error will be thrown.
94
+
95
+ ```ts
96
+ store.adapterFor('author');
97
+
98
+ // lookup paths (in order) =>
99
+ // app/adapters/author.js
100
+ // app/adapters/application.js
101
+ ```
102
+
103
+ Most requests in @warp-drive/legacy are made with respect to a particular `type` (or `modelName`)
104
+ (e.g., "get me the full collection of **books**" or "get me the **employee** whose id is 37"). We
105
+ refer to this as the **primary** resource `type`.
106
+
107
+ `adapterFor` is used by the store to find an adapter with a name matching that of the primary
108
+ resource `type` for the request, which then falls back to the `application` adapter.
109
+
110
+ It is recommended that applications define only a single `application` adapter and serializer
111
+ where possible, only implementing an adapter specific to the `type` when absolutely necessary.
112
+
113
+ If you need to support multiple API versions for the same type, the per-type strategy for
114
+ defining adapters might not be adequate.
115
+
116
+ If you have multiple APIs or multiple API versions and the single application adapter and per-type
117
+ strategy does not suite your needs, one strategy is to write an `application` adapter and serializer
118
+ that make use of `options` to specify the desired format when making a request, then forwards to the
119
+ request to the desired adapter or serializer as needed.
120
+
121
+ ```js [app/adapters/application.js]
122
+ export default class Adapter extends EmberObject {
123
+ findRecord(store, schema, id, snapshot) {
124
+ let { apiVersion } = snapshot.adapterOptions;
125
+ return this.adapterFor(`-api-${apiVersion}`).findRecord(store, schema, id, snapshot);
126
+ }
127
+ }
128
+ ```
144
129
 
130
+ ### Overriding `Store.adapterFor`
145
131
 
146
- Note: If you are using Ember and would like to make use of `service` injections in your adapter, you will want to additionally `setOwner` for the Adapter.
132
+ ```js
133
+ import Store from '@ember-data/store';
134
+ import Adapter from '@ember-data/adapter/json-api';
147
135
 
148
- ```js
149
- import Store from '@ember-data/store';
150
- import Adapter from '@ember-data/adapter/json-api';
151
- import { getOwner, setOwner } from '@ember/owner';
136
+ class extends Store {
137
+ #adapter = new Adapter();
152
138
 
153
- class extends Store {
154
- #adapter = null;
139
+ adapterFor() {
140
+ return this.#adapter;
141
+ }
142
+ }
143
+ ```
155
144
 
156
- adapterFor() {
157
- let adapter = this.#adapter;
158
- if (!adapter) {
159
- const owner = getOwner(this);
160
- adapter = new Adapter();
161
- setOwner(adapter, owner);
162
- this.#adapter = adapter;
163
- }
164
145
 
165
- return adapter;
166
- }
167
- }
168
- ```
146
+ Note: If you are using Ember and would like to make use of `service` injections in your adapter, you will want to additionally `setOwner` for the Adapter.
147
+
148
+ ```js
149
+ import Store from '@ember-data/store';
150
+ import Adapter from '@ember-data/adapter/json-api';
151
+ import { getOwner, setOwner } from '@ember/owner';
152
+
153
+ class extends Store {
154
+ #adapter = null;
155
+
156
+ adapterFor() {
157
+ let adapter = this.#adapter;
158
+ if (!adapter) {
159
+ const owner = getOwner(this);
160
+ adapter = new Adapter();
161
+ setOwner(adapter, owner);
162
+ this.#adapter = adapter;
163
+ }
164
+
165
+ return adapter;
166
+ }
167
+ }
168
+ ```
169
169
 
170
170
  By default when using with Ember you only need to implement this hook if you want your adapter usage to be statically analyzeable. *Ember***Data** will attempt to resolve adapters using Ember's resolver. To provide a single Adapter for your application like the above you would provide it as the default export of the file `app/adapters/application.{js/ts}`
171
171
 
172
- ### Using an Adapter
172
+ ### Using an Adapter
173
173
 
174
- Any adapter in `app/adapters/` can be looked up by `name` using `store.adapterFor(name)`.
174
+ Any adapter in `app/adapters/` can be looked up by `name` using `store.adapterFor(name)`.
175
175
 
176
- ### Default Adapters
176
+ ### Default Adapters
177
177
 
178
- Applications whose API's structure endpoint URLs *very close to* or *exactly* the **REST**
179
- or **JSON:API** convention, the `@ember-data/adapter` package contains implementations
180
- these applications can extend.
178
+ Applications whose API's structure endpoint URLs *very close to* or *exactly* the **REST**
179
+ or **JSON:API** convention, the `@ember-data/adapter` package contains implementations
180
+ these applications can extend.
181
181
 
182
- Many applications will find writing their own adapter to be allow greater flexibility,
183
- customization, and maintenance than attempting to override methods in these adapters.
182
+ Many applications will find writing their own adapter to be allow greater flexibility,
183
+ customization, and maintenance than attempting to override methods in these adapters.
184
184
 
185
- @module
185
+ @module
186
186
  */
187
- import EmberObject from '@ember/object';
188
- import type { Store } from '@warp-drive/core';
189
- import type { ModelSchema } from '@warp-drive/core/types';
190
- import type { AdapterPayload, MinimumAdapterInterface, SerializerOptions } from './compat.ts';
191
- import type { Snapshot, SnapshotRecordArray } from './compat/-private.ts';
187
+ import EmberObject from "@ember/object";
188
+ import type { Store } from "@warp-drive/core";
189
+ import type { ModelSchema } from "@warp-drive/core/types";
190
+ import type { AdapterPayload, MinimumAdapterInterface, SerializerOptions } from "./compat.js";
191
+ import type { Snapshot, SnapshotRecordArray } from "./compat/-private.js";
192
192
  /**
193
- An adapter is an object that receives requests from a store and
194
- translates them into the appropriate action to take against your
195
- persistence layer. The persistence layer is usually an HTTP API but
196
- may be anything, such as the browser's local storage. Typically the
197
- adapter is not invoked directly instead its functionality is accessed
198
- through the `store`.
193
+ An adapter is an object that receives requests from a store and
194
+ translates them into the appropriate action to take against your
195
+ persistence layer. The persistence layer is usually an HTTP API but
196
+ may be anything, such as the browser's local storage. Typically the
197
+ adapter is not invoked directly instead its functionality is accessed
198
+ through the `store`.
199
199
 
200
- > ⚠️ CAUTION you likely want the docs for {@link MinimumAdapterInterface}
201
- > as extending this abstract class is unnecessary.
200
+ > ⚠️ CAUTION you likely want the docs for {@link MinimumAdapterInterface}
201
+ > as extending this abstract class is unnecessary.
202
202
 
203
- ### Creating an Adapter
203
+ ### Creating an Adapter
204
204
 
205
- Create a new subclass of `Adapter` in the `app/adapters` folder:
205
+ Create a new subclass of `Adapter` in the `app/adapters` folder:
206
206
 
207
- ```js [app/adapters/application.js]
208
- import { Adapter } from '@warp-drive/legacy/adapter';
207
+ ```js [app/adapters/application.js]
208
+ import { Adapter } from '@warp-drive/legacy/adapter';
209
209
 
210
- export default class extends Adapter {
211
- // ...your code here
212
- }
213
- ```
210
+ export default class extends Adapter {
211
+ // ...your code here
212
+ }
213
+ ```
214
214
 
215
- Model-specific adapters can be created by putting your adapter
216
- class in an `app/adapters/` + `model-name` + `.js` file of the application.
215
+ Model-specific adapters can be created by putting your adapter
216
+ class in an `app/adapters/` + `model-name` + `.js` file of the application.
217
217
 
218
- ```js [app/adapters/post.js]
219
- import { Adapter } from '@warp-drive/legacy/adapter';
218
+ ```js [app/adapters/post.js]
219
+ import { Adapter } from '@warp-drive/legacy/adapter';
220
220
 
221
- export default class extends Adapter {
222
- // ...Post-specific adapter code goes here
223
- }
224
- ```
221
+ export default class extends Adapter {
222
+ // ...Post-specific adapter code goes here
223
+ }
224
+ ```
225
225
 
226
- `Adapter` is an abstract base class that you should override in your
227
- application to customize it for your backend. The minimum set of methods
228
- that you should implement is:
226
+ `Adapter` is an abstract base class that you should override in your
227
+ application to customize it for your backend. The minimum set of methods
228
+ that you should implement is:
229
229
 
230
- * `findRecord()`
231
- * `createRecord()`
232
- * `updateRecord()`
233
- * `deleteRecord()`
234
- * `findAll()`
235
- * `query()`
230
+ * `findRecord()`
231
+ * `createRecord()`
232
+ * `updateRecord()`
233
+ * `deleteRecord()`
234
+ * `findAll()`
235
+ * `query()`
236
236
 
237
- To improve the network performance of your application, you can optimize
238
- your adapter by overriding these lower-level methods:
237
+ To improve the network performance of your application, you can optimize
238
+ your adapter by overriding these lower-level methods:
239
239
 
240
- * `findMany()`
240
+ * `findMany()`
241
241
 
242
242
 
243
- For an example of the implementation, see `RESTAdapter`, the
244
- included REST adapter.
243
+ For an example of the implementation, see `RESTAdapter`, the
244
+ included REST adapter.
245
245
 
246
- @class Adapter
247
- @public
246
+ @public
248
247
  */
249
248
  export declare class Adapter extends EmberObject implements MinimumAdapterInterface {
250
- store: Store;
251
- _coalesceFindRequests: boolean;
252
- /**
253
- The `findRecord()` method is invoked when the store is asked for a record that
254
- has not previously been loaded. In response to `findRecord()` being called, you
255
- should query your persistence layer for a record with the given ID. The `findRecord`
256
- method should return a promise that will resolve to a JavaScript object that will be
257
- normalized by the serializer.
258
-
259
- Here is an example of the `findRecord` implementation:
260
-
261
- ```js [app/adapters/application.js]
262
- import { Adapter } from '@warp-drive/legacy/adapter';
263
- import RSVP from 'RSVP';
264
- import $ from 'jquery';
265
-
266
- export default class ApplicationAdapter extends Adapter {
267
- findRecord(store, type, id, snapshot) {
268
- return new RSVP.Promise(function(resolve, reject) {
269
- $.getJSON(`/${type.modelName}/${id}`).then(function(data) {
270
- resolve(data);
271
- }, function(jqXHR) {
272
- reject(jqXHR);
273
- });
274
- });
275
- }
276
- }
277
- ```
278
-
279
- @param {Store} store
280
- @param {Model} type
281
- @param {String} id
282
- @param {Snapshot} snapshot
283
- @return {Promise} promise
284
- @public
285
- */
286
- findRecord(store: Store, type: ModelSchema, id: string, snapshot: Snapshot): Promise<AdapterPayload>;
287
- /**
288
- The `findAll()` method is used to retrieve all records for a given type.
289
-
290
- Example
291
-
292
- ```js [app/adapters/application.js]
293
- import { Adapter } from '@warp-drive/legacy/adapter';
294
- import RSVP from 'RSVP';
295
- import $ from 'jquery';
296
-
297
- export default class ApplicationAdapter extends Adapter {
298
- findAll(store, type) {
299
- return new RSVP.Promise(function(resolve, reject) {
300
- $.getJSON(`/${type.modelName}`).then(function(data) {
301
- resolve(data);
302
- }, function(jqXHR) {
303
- reject(jqXHR);
304
- });
305
- });
306
- }
307
- }
308
- ```
309
-
310
- @param {Store} store
311
- @param {Model} type
312
- @param {null} neverSet a value is never provided to this argument
313
- @param {SnapshotRecordArray} snapshotRecordArray
314
- @return {Promise} promise
315
- @public
316
- */
317
- findAll(store: Store, type: ModelSchema, neverSet: null, snapshotRecordArray: SnapshotRecordArray): Promise<AdapterPayload>;
318
- /**
319
- This method is called when you call `query` on the store.
320
-
321
- Example
322
-
323
- ```js [app/adapters/application.js]
324
- import { Adapter } from '@warp-drive/legacy/adapter';
325
- import RSVP from 'RSVP';
326
- import $ from 'jquery';
327
-
328
- export default class ApplicationAdapter extends Adapter {
329
- query(store, type, query) {
330
- return new RSVP.Promise(function(resolve, reject) {
331
- $.getJSON(`/${type.modelName}`, query).then(function(data) {
332
- resolve(data);
333
- }, function(jqXHR) {
334
- reject(jqXHR);
335
- });
336
- });
337
- }
338
- }
339
- ```
340
-
341
- @param {Store} store
342
- @param {Model} type
343
- @param {Object} query
344
- @param {Collection} recordArray
345
- @param {Object} adapterOptions
346
- @return {Promise} promise
347
- @public
348
- */
349
- query(store: Store, type: ModelSchema, query: any): Promise<AdapterPayload>;
350
- /**
351
- The `queryRecord()` method is invoked when the store is asked for a single
352
- record through a query object.
353
-
354
- In response to `queryRecord()` being called, you should always fetch fresh
355
- data. Once found, you can asynchronously call the store's `push()` method
356
- to push the record into the store.
357
-
358
- Here is an example `queryRecord` implementation:
359
-
360
- Example
361
-
362
- ```js [app/adapters/application.js]
363
- import { Adapter, BuildURLMixin } from '@warp-drive/legacy/adapter';
364
-
365
- export default class ApplicationAdapter extends Adapter.extend(BuildURLMixin) {
366
- queryRecord(store, type, query) {
367
- return fetch(`/${type.modelName}`, { body: JSON.stringify(query) })
368
- .then((response) => response.json());
369
- }
370
- }
371
- ```
372
-
373
- @param {Store} store
374
- @param {subclass of Model} type
375
- @param {Object} query
376
- @param {Object} adapterOptions
377
- @return {Promise} promise
378
- @public
379
- */
380
- queryRecord(store: Store, type: ModelSchema, query: any, adapterOptions: any): Promise<AdapterPayload>;
381
- /**
382
- If the globally unique IDs for your records should be generated on the client,
383
- implement the `generateIdForRecord()` method. This method will be invoked
384
- each time you create a new record, and the value returned from it will be
385
- assigned to the record's `primaryKey`.
386
-
387
- Most traditional REST-like HTTP APIs will not use this method. Instead, the ID
388
- of the record will be set by the server, and your adapter will update the store
389
- with the new ID when it calls `didCreateRecord()`. Only implement this method if
390
- you intend to generate record IDs on the client-side.
391
-
392
- The `generateIdForRecord()` method will be invoked with the requesting store as
393
- the first parameter and the newly created record as the second parameter:
394
-
395
- ```javascript
396
- import { Adapter } from '@warp-drive/legacy/adapter';
397
- import { v4 } from 'uuid';
398
-
399
- export default class ApplicationAdapter extends Adapter {
400
- generateIdForRecord(store, type, inputProperties) {
401
- return v4();
402
- }
403
- }
404
- ```
405
-
406
- @param {Store} store
407
- @param {Model} type the Model class of the record
408
- @param {Object} inputProperties a hash of properties to set on the
409
- newly created record.
410
- @return {(String|Number)} id
411
- @public
412
- */
413
- /**
414
- Proxies to the serializer's `serialize` method.
415
-
416
- Example
417
-
418
- ```js [app/adapters/application.js]
419
- import { Adapter } from '@warp-drive/legacy/adapter';
420
-
421
- export default class ApplicationAdapter extends Adapter {
422
- createRecord(store, type, snapshot) {
423
- let data = this.serialize(snapshot, { includeId: true });
424
- let url = `/${type.modelName}`;
425
-
426
- // ...
427
- }
428
- }
429
- ```
430
-
431
- @param {Snapshot} snapshot
432
- @param {Object} options
433
- @return {Object} serialized snapshot
434
- @public
435
- */
436
- serialize(snapshot: Snapshot, options: SerializerOptions): Record<string, unknown>;
437
- /**
438
- Implement this method in a subclass to handle the creation of
439
- new records.
440
-
441
- Serializes the record and sends it to the server.
442
-
443
- Example
444
-
445
- ```js [app/adapters/application.js]
446
- import { Adapter } from '@warp-drive/legacy/adapter';
447
- import RSVP from 'RSVP';
448
- import $ from 'jquery';
449
-
450
- export default class ApplicationAdapter extends Adapter {
451
- createRecord(store, type, snapshot) {
452
- let data = this.serialize(snapshot, { includeId: true });
453
-
454
- return new RSVP.Promise(function (resolve, reject) {
455
- $.ajax({
456
- type: 'POST',
457
- url: `/${type.modelName}`,
458
- dataType: 'json',
459
- data: data
460
- }).then(function (data) {
461
- resolve(data);
462
- }, function (jqXHR) {
463
- jqXHR.then = null; // tame jQuery's ill mannered promises
464
- reject(jqXHR);
465
- });
466
- });
467
- }
468
- }
469
- ```
470
-
471
- @param {Store} store
472
- @param {Model} type the Model class of the record
473
- @param {Snapshot} snapshot
474
- @return {Promise} promise
475
- @public
476
- */
477
- createRecord(store: Store, type: ModelSchema, snapshot: Snapshot): Promise<AdapterPayload>;
478
- /**
479
- Implement this method in a subclass to handle the updating of
480
- a record.
481
-
482
- Serializes the record update and sends it to the server.
483
-
484
- The updateRecord method is expected to return a promise that will
485
- resolve with the serialized record. This allows the backend to
486
- inform the Ember Data store the current state of this record after
487
- the update. If it is not possible to return a serialized record
488
- the updateRecord promise can also resolve with `undefined` and the
489
- Ember Data store will assume all of the updates were successfully
490
- applied on the backend.
491
-
492
- Example
493
-
494
- ```js [app/adapters/application.js]
495
- import { Adapter } from '@warp-drive/legacy/adapter';
496
- import RSVP from 'RSVP';
497
- import $ from 'jquery';
498
-
499
- export default class ApplicationAdapter extends Adapter {
500
- updateRecord(store, type, snapshot) {
501
- let data = this.serialize(snapshot, { includeId: true });
502
- let id = snapshot.id;
503
-
504
- return new RSVP.Promise(function(resolve, reject) {
505
- $.ajax({
506
- type: 'PUT',
507
- url: `/${type.modelName}/${id}`,
508
- dataType: 'json',
509
- data: data
510
- }).then(function(data) {
511
- resolve(data);
512
- }, function(jqXHR) {
513
- jqXHR.then = null; // tame jQuery's ill mannered promises
514
- reject(jqXHR);
515
- });
516
- });
517
- }
518
- }
519
- ```
520
-
521
- @param {Store} store
522
- @param {Model} type the Model class of the record
523
- @param {Snapshot} snapshot
524
- @return {Promise} promise
525
- @public
526
- */
527
- updateRecord(store: Store, type: ModelSchema, snapshot: Snapshot): Promise<AdapterPayload>;
528
- /**
529
- Implement this method in a subclass to handle the deletion of
530
- a record.
531
-
532
- Sends a delete request for the record to the server.
533
-
534
- Example
535
-
536
- ```js [app/adapters/application.js]
537
- import { Adapter } from '@warp-drive/legacy/adapter';
538
- import RSVP from 'RSVP';
539
- import $ from 'jquery';
540
-
541
- export default class ApplicationAdapter extends Adapter {
542
- deleteRecord(store, type, snapshot) {
543
- let data = this.serialize(snapshot, { includeId: true });
544
- let id = snapshot.id;
545
-
546
- return new RSVP.Promise(function(resolve, reject) {
547
- $.ajax({
548
- type: 'DELETE',
549
- url: `/${type.modelName}/${id}`,
550
- dataType: 'json',
551
- data: data
552
- }).then(function(data) {
553
- resolve(data)
554
- }, function(jqXHR) {
555
- jqXHR.then = null; // tame jQuery's ill mannered promises
556
- reject(jqXHR);
557
- });
558
- });
559
- }
560
- }
561
- ```
562
-
563
- @param {Store} store
564
- @param {Model} type the Model class of the record
565
- @param {Snapshot} snapshot
566
- @return {Promise} promise
567
- @public
568
- */
569
- deleteRecord(store: Store, type: ModelSchema, snapshot: Snapshot): Promise<AdapterPayload>;
570
- /**
571
- By default the store will try to coalesce all `findRecord` calls within the same runloop
572
- into as few requests as possible by calling groupRecordsForFindMany and passing it into a findMany call.
573
- You can opt out of this behaviour by either not implementing the findMany hook or by setting
574
- coalesceFindRequests to false.
575
-
576
- @property coalesceFindRequests
577
- @public
578
- @type {Boolean}
579
- */
580
- get coalesceFindRequests(): boolean;
581
- set coalesceFindRequests(value: boolean);
582
- /**
583
- The store will call `findMany` instead of multiple `findRecord`
584
- requests to find multiple records at once if coalesceFindRequests
585
- is true.
586
-
587
- ```js [app/adapters/application.js]
588
- import { Adapter } from '@warp-drive/legacy/adapter';
589
- import RSVP from 'RSVP';
590
- import $ from 'jquery';
591
-
592
- export default class ApplicationAdapter extends Adapter {
593
- findMany(store, type, ids, snapshots) {
594
- return new RSVP.Promise(function(resolve, reject) {
595
- $.ajax({
596
- type: 'GET',
597
- url: `/${type.modelName}/`,
598
- dataType: 'json',
599
- data: { filter: { id: ids.join(',') } }
600
- }).then(function(data) {
601
- resolve(data);
602
- }, function(jqXHR) {
603
- jqXHR.then = null; // tame jQuery's ill mannered promises
604
- reject(jqXHR);
605
- });
606
- });
607
- }
608
- }
609
- ```
610
-
611
- @param {Store} store
612
- @param {Model} type the Model class of the records
613
- @param {Array} ids
614
- @param {Array} snapshots
615
- @return {Promise} promise
616
- @public
617
- */
618
- /**
619
- Organize records into groups, each of which is to be passed to separate
620
- calls to `findMany`.
621
-
622
- For example, if your API has nested URLs that depend on the parent, you will
623
- want to group records by their parent.
624
-
625
- The default implementation returns the records as a single group.
626
-
627
- @public
628
- @param {Store} store
629
- @param {Array} snapshots
630
- @return {Array} an array of arrays of records, each of which is to be
631
- loaded separately by `findMany`.
632
- */
633
- groupRecordsForFindMany(store: Store, snapshots: Snapshot[]): Snapshot[][];
634
- /**
635
- This method is used by the store to determine if the store should
636
- reload a record from the adapter when a record is requested by
637
- `store.findRecord`.
638
-
639
- If this method returns `true`, the store will re-fetch a record from
640
- the adapter. If this method returns `false`, the store will resolve
641
- immediately using the cached record.
642
-
643
- For example, if you are building an events ticketing system, in which users
644
- can only reserve tickets for 20 minutes at a time, and want to ensure that
645
- in each route you have data that is no more than 20 minutes old you could
646
- write:
647
-
648
- ```javascript
649
- shouldReloadRecord(store, ticketSnapshot) {
650
- let lastAccessedAt = ticketSnapshot.attr('lastAccessedAt');
651
- let timeDiff = moment().diff(lastAccessedAt, 'minutes');
652
-
653
- if (timeDiff > 20) {
654
- return true;
655
- } else {
656
- return false;
657
- }
658
- }
659
- ```
660
-
661
- This method would ensure that whenever you do `store.findRecord('ticket',
662
- id)` you will always get a ticket that is no more than 20 minutes old. In
663
- case the cached version is more than 20 minutes old, `findRecord` will not
664
- resolve until you fetched the latest version.
665
-
666
- By default this hook returns `false`, as most UIs should not block user
667
- interactions while waiting on data update.
668
-
669
- Note that, with default settings, `shouldBackgroundReloadRecord` will always
670
- re-fetch the records in the background even if `shouldReloadRecord` returns
671
- `false`. You can override `shouldBackgroundReloadRecord` if this does not
672
- suit your use case.
673
-
674
- @since 1.13.0
675
- @param {Store} store
676
- @param {Snapshot} snapshot
677
- @return {Boolean}
678
- @public
679
- */
680
- shouldReloadRecord(store: Store, snapshot: Snapshot): boolean;
681
- /**
682
- This method is used by the store to determine if the store should
683
- reload all records from the adapter when records are requested by
684
- `store.findAll`.
685
-
686
- If this method returns `true`, the store will re-fetch all records from
687
- the adapter. If this method returns `false`, the store will resolve
688
- immediately using the cached records.
689
-
690
- For example, if you are building an events ticketing system, in which users
691
- can only reserve tickets for 20 minutes at a time, and want to ensure that
692
- in each route you have data that is no more than 20 minutes old you could
693
- write:
694
-
695
- ```javascript
696
- shouldReloadAll(store, snapshotArray) {
697
- let snapshots = snapshotArray.snapshots();
698
-
699
- return snapshots.any((ticketSnapshot) => {
700
- let lastAccessedAt = ticketSnapshot.attr('lastAccessedAt');
701
- let timeDiff = moment().diff(lastAccessedAt, 'minutes');
702
-
703
- if (timeDiff > 20) {
704
- return true;
705
- } else {
706
- return false;
707
- }
708
- });
709
- }
710
- ```
711
-
712
- This method would ensure that whenever you do `store.findAll('ticket')` you
713
- will always get a list of tickets that are no more than 20 minutes old. In
714
- case a cached version is more than 20 minutes old, `findAll` will not
715
- resolve until you fetched the latest versions.
716
-
717
- By default, this method returns `true` if the passed `snapshotRecordArray`
718
- is empty (meaning that there are no records locally available yet),
719
- otherwise, it returns `false`.
720
-
721
- Note that, with default settings, `shouldBackgroundReloadAll` will always
722
- re-fetch all the records in the background even if `shouldReloadAll` returns
723
- `false`. You can override `shouldBackgroundReloadAll` if this does not suit
724
- your use case.
725
-
726
- @since 1.13.0
727
- @param {Store} store
728
- @param {SnapshotRecordArray} snapshotRecordArray
729
- @return {Boolean}
730
- @public
731
- */
732
- shouldReloadAll(store: Store, snapshotRecordArray: SnapshotRecordArray): boolean;
733
- /**
734
- This method is used by the store to determine if the store should
735
- reload a record after the `store.findRecord` method resolves a
736
- cached record.
737
-
738
- This method is *only* checked by the store when the store is
739
- returning a cached record.
740
-
741
- If this method returns `true` the store will re-fetch a record from
742
- the adapter.
743
-
744
- For example, if you do not want to fetch complex data over a mobile
745
- connection, or if the network is down, you can implement
746
- `shouldBackgroundReloadRecord` as follows:
747
-
748
- ```javascript
749
- shouldBackgroundReloadRecord(store, snapshot) {
750
- let { downlink, effectiveType } = navigator.connection;
751
-
752
- return downlink > 0 && effectiveType === '4g';
753
- }
754
- ```
755
-
756
- By default, this hook returns `true` so the data for the record is updated
757
- in the background.
758
-
759
- @since 1.13.0
760
- @param {Store} store
761
- @param {Snapshot} snapshot
762
- @return {Boolean}
763
- @public
764
- */
765
- shouldBackgroundReloadRecord(store: Store, snapshot: Snapshot): boolean;
766
- /**
767
- This method is used by the store to determine if the store should
768
- reload a record array after the `store.findAll` method resolves
769
- with a cached record array.
770
-
771
- This method is *only* checked by the store when the store is
772
- returning a cached record array.
773
-
774
- If this method returns `true` the store will re-fetch all records
775
- from the adapter.
776
-
777
- For example, if you do not want to fetch complex data over a mobile
778
- connection, or if the network is down, you can implement
779
- `shouldBackgroundReloadAll` as follows:
780
-
781
- ```javascript
782
- shouldBackgroundReloadAll(store, snapshotArray) {
783
- let { downlink, effectiveType } = navigator.connection;
784
-
785
- return downlink > 0 && effectiveType === '4g';
786
- }
787
- ```
788
-
789
- By default this method returns `true`, indicating that a background reload
790
- should always be triggered.
791
-
792
- @since 1.13.0
793
- @param {Store} store
794
- @param {SnapshotRecordArray} snapshotRecordArray
795
- @return {Boolean}
796
- @public
797
- */
798
- shouldBackgroundReloadAll(store: Store, snapshotRecordArray: SnapshotRecordArray): boolean;
249
+ store: Store;
250
+ _coalesceFindRequests: boolean;
251
+ /**
252
+ The `findRecord()` method is invoked when the store is asked for a record that
253
+ has not previously been loaded. In response to `findRecord()` being called, you
254
+ should query your persistence layer for a record with the given ID. The `findRecord`
255
+ method should return a promise that will resolve to a JavaScript object that will be
256
+ normalized by the serializer.
257
+
258
+ Here is an example of the `findRecord` implementation:
259
+
260
+ ```js [app/adapters/application.js]
261
+ import { Adapter } from '@warp-drive/legacy/adapter';
262
+ import RSVP from 'RSVP';
263
+ import $ from 'jquery';
264
+
265
+ export default class ApplicationAdapter extends Adapter {
266
+ findRecord(store, type, id, snapshot) {
267
+ return new RSVP.Promise(function(resolve, reject) {
268
+ $.getJSON(`/${type.modelName}/${id}`).then(function(data) {
269
+ resolve(data);
270
+ }, function(jqXHR) {
271
+ reject(jqXHR);
272
+ });
273
+ });
274
+ }
275
+ }
276
+ ```
277
+
278
+ @public
279
+ */
280
+ // @ts-expect-error
281
+ findRecord(store: Store, type: ModelSchema, id: string, snapshot: Snapshot): Promise<AdapterPayload>;
282
+ /**
283
+ The `findAll()` method is used to retrieve all records for a given type.
284
+
285
+ Example
286
+
287
+ ```js [app/adapters/application.js]
288
+ import { Adapter } from '@warp-drive/legacy/adapter';
289
+ import RSVP from 'RSVP';
290
+ import $ from 'jquery';
291
+
292
+ export default class ApplicationAdapter extends Adapter {
293
+ findAll(store, type) {
294
+ return new RSVP.Promise(function(resolve, reject) {
295
+ $.getJSON(`/${type.modelName}`).then(function(data) {
296
+ resolve(data);
297
+ }, function(jqXHR) {
298
+ reject(jqXHR);
299
+ });
300
+ });
301
+ }
302
+ }
303
+ ```
304
+
305
+ @param neverSet a value is never provided to this argument
306
+ @public
307
+ */
308
+ findAll(store: Store, type: ModelSchema, neverSet: null, snapshotRecordArray: SnapshotRecordArray): Promise<AdapterPayload>;
309
+ /**
310
+ This method is called when you call `query` on the store.
311
+
312
+ Example
313
+
314
+ ```js [app/adapters/application.js]
315
+ import { Adapter } from '@warp-drive/legacy/adapter';
316
+ import RSVP from 'RSVP';
317
+ import $ from 'jquery';
318
+
319
+ export default class ApplicationAdapter extends Adapter {
320
+ query(store, type, query) {
321
+ return new RSVP.Promise(function(resolve, reject) {
322
+ $.getJSON(`/${type.modelName}`, query).then(function(data) {
323
+ resolve(data);
324
+ }, function(jqXHR) {
325
+ reject(jqXHR);
326
+ });
327
+ });
328
+ }
329
+ }
330
+ ```
331
+
332
+ @public
333
+ */
334
+ // @ts-expect-error
335
+ query(store: Store, type: ModelSchema, query: Record<string, unknown>): Promise<AdapterPayload>;
336
+ /**
337
+ The `queryRecord()` method is invoked when the store is asked for a single
338
+ record through a query object.
339
+
340
+ In response to `queryRecord()` being called, you should always fetch fresh
341
+ data. Once found, you can asynchronously call the store's `push()` method
342
+ to push the record into the store.
343
+
344
+ Here is an example `queryRecord` implementation:
345
+
346
+ Example
347
+
348
+ ```js [app/adapters/application.js]
349
+ import { Adapter, BuildURLMixin } from '@warp-drive/legacy/adapter';
350
+
351
+ export default class ApplicationAdapter extends Adapter.extend(BuildURLMixin) {
352
+ queryRecord(store, type, query) {
353
+ return fetch(`/${type.modelName}`, { body: JSON.stringify(query) })
354
+ .then((response) => response.json());
355
+ }
356
+ }
357
+ ```
358
+
359
+ @public
360
+ */
361
+ queryRecord(store: Store, type: ModelSchema, query: Record<string, unknown>, adapterOptions: object): Promise<AdapterPayload>;
362
+ /**
363
+ If the globally unique IDs for your records should be generated on the client,
364
+ implement the `generateIdForRecord()` method. This method will be invoked
365
+ each time you create a new record, and the value returned from it will be
366
+ assigned to the record's `primaryKey`.
367
+
368
+ Most traditional REST-like HTTP APIs will not use this method. Instead, the ID
369
+ of the record will be set by the server, and your adapter will update the store
370
+ with the new ID when it calls `didCreateRecord()`. Only implement this method if
371
+ you intend to generate record IDs on the client-side.
372
+
373
+ The `generateIdForRecord()` method will be invoked with the requesting store as
374
+ the first parameter and the newly created record as the second parameter:
375
+
376
+ ```javascript
377
+ import { Adapter } from '@warp-drive/legacy/adapter';
378
+ import { v4 } from 'uuid';
379
+
380
+ export default class ApplicationAdapter extends Adapter {
381
+ generateIdForRecord(store, type, inputProperties) {
382
+ return v4();
383
+ }
384
+ }
385
+ ```
386
+
387
+ @param {Store} store
388
+ @param {Model} type the Model class of the record
389
+ @param {Object} inputProperties a hash of properties to set on the
390
+ newly created record.
391
+ @return {(String|Number)} id
392
+ @public
393
+ */
394
+ /**
395
+ Proxies to the serializer's `serialize` method.
396
+
397
+ Example
398
+
399
+ ```js [app/adapters/application.js]
400
+ import { Adapter } from '@warp-drive/legacy/adapter';
401
+
402
+ export default class ApplicationAdapter extends Adapter {
403
+ createRecord(store, type, snapshot) {
404
+ let data = this.serialize(snapshot, { includeId: true });
405
+ let url = `/${type.modelName}`;
406
+
407
+ // ...
408
+ }
409
+ }
410
+ ```
411
+
412
+ @public
413
+ */
414
+ serialize(snapshot: Snapshot, options: SerializerOptions): Record<string, unknown>;
415
+ /**
416
+ Implement this method in a subclass to handle the creation of
417
+ new records.
418
+
419
+ Serializes the record and sends it to the server.
420
+
421
+ Example
422
+
423
+ ```js [app/adapters/application.js]
424
+ import { Adapter } from '@warp-drive/legacy/adapter';
425
+ import RSVP from 'RSVP';
426
+ import $ from 'jquery';
427
+
428
+ export default class ApplicationAdapter extends Adapter {
429
+ createRecord(store, type, snapshot) {
430
+ let data = this.serialize(snapshot, { includeId: true });
431
+
432
+ return new RSVP.Promise(function (resolve, reject) {
433
+ $.ajax({
434
+ type: 'POST',
435
+ url: `/${type.modelName}`,
436
+ dataType: 'json',
437
+ data: data
438
+ }).then(function (data) {
439
+ resolve(data);
440
+ }, function (jqXHR) {
441
+ jqXHR.then = null; // tame jQuery's ill mannered promises
442
+ reject(jqXHR);
443
+ });
444
+ });
445
+ }
446
+ }
447
+ ```
448
+
449
+ @public
450
+ */
451
+ // @ts-expect-error
452
+ createRecord(store: Store, type: ModelSchema, snapshot: Snapshot): Promise<AdapterPayload>;
453
+ /**
454
+ Implement this method in a subclass to handle the updating of
455
+ a record.
456
+
457
+ Serializes the record update and sends it to the server.
458
+
459
+ The updateRecord method is expected to return a promise that will
460
+ resolve with the serialized record. This allows the backend to
461
+ inform the Ember Data store the current state of this record after
462
+ the update. If it is not possible to return a serialized record
463
+ the updateRecord promise can also resolve with `undefined` and the
464
+ Ember Data store will assume all of the updates were successfully
465
+ applied on the backend.
466
+
467
+ Example
468
+
469
+ ```js [app/adapters/application.js]
470
+ import { Adapter } from '@warp-drive/legacy/adapter';
471
+ import RSVP from 'RSVP';
472
+ import $ from 'jquery';
473
+
474
+ export default class ApplicationAdapter extends Adapter {
475
+ updateRecord(store, type, snapshot) {
476
+ let data = this.serialize(snapshot, { includeId: true });
477
+ let id = snapshot.id;
478
+
479
+ return new RSVP.Promise(function(resolve, reject) {
480
+ $.ajax({
481
+ type: 'PUT',
482
+ url: `/${type.modelName}/${id}`,
483
+ dataType: 'json',
484
+ data: data
485
+ }).then(function(data) {
486
+ resolve(data);
487
+ }, function(jqXHR) {
488
+ jqXHR.then = null; // tame jQuery's ill mannered promises
489
+ reject(jqXHR);
490
+ });
491
+ });
492
+ }
493
+ }
494
+ ```
495
+
496
+ @param {Store} store
497
+ @param {Model} type the Model class of the record
498
+ @param {Snapshot} snapshot
499
+ @return {Promise} promise
500
+ @public
501
+ */
502
+ // @ts-expect-error
503
+ updateRecord(store: Store, type: ModelSchema, snapshot: Snapshot): Promise<AdapterPayload>;
504
+ /**
505
+ Implement this method in a subclass to handle the deletion of
506
+ a record.
507
+
508
+ Sends a delete request for the record to the server.
509
+
510
+ Example
511
+
512
+ ```js [app/adapters/application.js]
513
+ import { Adapter } from '@warp-drive/legacy/adapter';
514
+ import RSVP from 'RSVP';
515
+ import $ from 'jquery';
516
+
517
+ export default class ApplicationAdapter extends Adapter {
518
+ deleteRecord(store, type, snapshot) {
519
+ let data = this.serialize(snapshot, { includeId: true });
520
+ let id = snapshot.id;
521
+
522
+ return new RSVP.Promise(function(resolve, reject) {
523
+ $.ajax({
524
+ type: 'DELETE',
525
+ url: `/${type.modelName}/${id}`,
526
+ dataType: 'json',
527
+ data: data
528
+ }).then(function(data) {
529
+ resolve(data)
530
+ }, function(jqXHR) {
531
+ jqXHR.then = null; // tame jQuery's ill mannered promises
532
+ reject(jqXHR);
533
+ });
534
+ });
535
+ }
536
+ }
537
+ ```
538
+
539
+ @param {Store} store
540
+ @param {Model} type the Model class of the record
541
+ @param {Snapshot} snapshot
542
+ @return {Promise} promise
543
+ @public
544
+ */
545
+ // @ts-expect-error
546
+ deleteRecord(store: Store, type: ModelSchema, snapshot: Snapshot): Promise<AdapterPayload>;
547
+ /**
548
+ By default the store will try to coalesce all `findRecord` calls within the same runloop
549
+ into as few requests as possible by calling groupRecordsForFindMany and passing it into a findMany call.
550
+ You can opt out of this behaviour by either not implementing the findMany hook or by setting
551
+ coalesceFindRequests to false.
552
+
553
+ @property coalesceFindRequests
554
+ @public
555
+ @type {Boolean}
556
+ */
557
+ get coalesceFindRequests(): boolean;
558
+ set coalesceFindRequests(value: boolean);
559
+ /**
560
+ The store will call `findMany` instead of multiple `findRecord`
561
+ requests to find multiple records at once if coalesceFindRequests
562
+ is true.
563
+
564
+ ```js [app/adapters/application.js]
565
+ import { Adapter } from '@warp-drive/legacy/adapter';
566
+ import RSVP from 'RSVP';
567
+ import $ from 'jquery';
568
+
569
+ export default class ApplicationAdapter extends Adapter {
570
+ findMany(store, type, ids, snapshots) {
571
+ return new RSVP.Promise(function(resolve, reject) {
572
+ $.ajax({
573
+ type: 'GET',
574
+ url: `/${type.modelName}/`,
575
+ dataType: 'json',
576
+ data: { filter: { id: ids.join(',') } }
577
+ }).then(function(data) {
578
+ resolve(data);
579
+ }, function(jqXHR) {
580
+ jqXHR.then = null; // tame jQuery's ill mannered promises
581
+ reject(jqXHR);
582
+ });
583
+ });
584
+ }
585
+ }
586
+ ```
587
+
588
+ @param {Store} store
589
+ @param {Model} type the Model class of the records
590
+ @param {Array} ids
591
+ @param {Array} snapshots
592
+ @return {Promise} promise
593
+ @public
594
+ */
595
+ /**
596
+ Organize records into groups, each of which is to be passed to separate
597
+ calls to `findMany`.
598
+
599
+ For example, if your API has nested URLs that depend on the parent, you will
600
+ want to group records by their parent.
601
+
602
+ The default implementation returns the records as a single group.
603
+
604
+ @public
605
+ @param {Store} store
606
+ @param {Array} snapshots
607
+ @return {Array} an array of arrays of records, each of which is to be
608
+ loaded separately by `findMany`.
609
+ */
610
+ groupRecordsForFindMany(store: Store, snapshots: Snapshot[]): Snapshot[][];
611
+ /**
612
+ This method is used by the store to determine if the store should
613
+ reload a record from the adapter when a record is requested by
614
+ `store.findRecord`.
615
+
616
+ If this method returns `true`, the store will re-fetch a record from
617
+ the adapter. If this method returns `false`, the store will resolve
618
+ immediately using the cached record.
619
+
620
+ For example, if you are building an events ticketing system, in which users
621
+ can only reserve tickets for 20 minutes at a time, and want to ensure that
622
+ in each route you have data that is no more than 20 minutes old you could
623
+ write:
624
+
625
+ ```javascript
626
+ shouldReloadRecord(store, ticketSnapshot) {
627
+ let lastAccessedAt = ticketSnapshot.attr('lastAccessedAt');
628
+ let timeDiff = moment().diff(lastAccessedAt, 'minutes');
629
+
630
+ if (timeDiff > 20) {
631
+ return true;
632
+ } else {
633
+ return false;
634
+ }
635
+ }
636
+ ```
637
+
638
+ This method would ensure that whenever you do `store.findRecord('ticket',
639
+ id)` you will always get a ticket that is no more than 20 minutes old. In
640
+ case the cached version is more than 20 minutes old, `findRecord` will not
641
+ resolve until you fetched the latest version.
642
+
643
+ By default this hook returns `false`, as most UIs should not block user
644
+ interactions while waiting on data update.
645
+
646
+ Note that, with default settings, `shouldBackgroundReloadRecord` will always
647
+ re-fetch the records in the background even if `shouldReloadRecord` returns
648
+ `false`. You can override `shouldBackgroundReloadRecord` if this does not
649
+ suit your use case.
650
+
651
+ @since 1.13.0
652
+ @param {Store} store
653
+ @param {Snapshot} snapshot
654
+ @return {Boolean}
655
+ @public
656
+ */
657
+ shouldReloadRecord(store: Store, snapshot: Snapshot): boolean;
658
+ /**
659
+ This method is used by the store to determine if the store should
660
+ reload all records from the adapter when records are requested by
661
+ `store.findAll`.
662
+
663
+ If this method returns `true`, the store will re-fetch all records from
664
+ the adapter. If this method returns `false`, the store will resolve
665
+ immediately using the cached records.
666
+
667
+ For example, if you are building an events ticketing system, in which users
668
+ can only reserve tickets for 20 minutes at a time, and want to ensure that
669
+ in each route you have data that is no more than 20 minutes old you could
670
+ write:
671
+
672
+ ```javascript
673
+ shouldReloadAll(store, snapshotArray) {
674
+ let snapshots = snapshotArray.snapshots();
675
+
676
+ return snapshots.any((ticketSnapshot) => {
677
+ let lastAccessedAt = ticketSnapshot.attr('lastAccessedAt');
678
+ let timeDiff = moment().diff(lastAccessedAt, 'minutes');
679
+
680
+ if (timeDiff > 20) {
681
+ return true;
682
+ } else {
683
+ return false;
684
+ }
685
+ });
686
+ }
687
+ ```
688
+
689
+ This method would ensure that whenever you do `store.findAll('ticket')` you
690
+ will always get a list of tickets that are no more than 20 minutes old. In
691
+ case a cached version is more than 20 minutes old, `findAll` will not
692
+ resolve until you fetched the latest versions.
693
+
694
+ By default, this method returns `true` if the passed `snapshotRecordArray`
695
+ is empty (meaning that there are no records locally available yet),
696
+ otherwise, it returns `false`.
697
+
698
+ Note that, with default settings, `shouldBackgroundReloadAll` will always
699
+ re-fetch all the records in the background even if `shouldReloadAll` returns
700
+ `false`. You can override `shouldBackgroundReloadAll` if this does not suit
701
+ your use case.
702
+
703
+ @since 1.13.0
704
+ @param {Store} store
705
+ @param {SnapshotRecordArray} snapshotRecordArray
706
+ @return {Boolean}
707
+ @public
708
+ */
709
+ shouldReloadAll(store: Store, snapshotRecordArray: SnapshotRecordArray): boolean;
710
+ /**
711
+ This method is used by the store to determine if the store should
712
+ reload a record after the `store.findRecord` method resolves a
713
+ cached record.
714
+
715
+ This method is *only* checked by the store when the store is
716
+ returning a cached record.
717
+
718
+ If this method returns `true` the store will re-fetch a record from
719
+ the adapter.
720
+
721
+ For example, if you do not want to fetch complex data over a mobile
722
+ connection, or if the network is down, you can implement
723
+ `shouldBackgroundReloadRecord` as follows:
724
+
725
+ ```javascript
726
+ shouldBackgroundReloadRecord(store, snapshot) {
727
+ let { downlink, effectiveType } = navigator.connection;
728
+
729
+ return downlink > 0 && effectiveType === '4g';
730
+ }
731
+ ```
732
+
733
+ By default, this hook returns `true` so the data for the record is updated
734
+ in the background.
735
+
736
+ @since 1.13.0
737
+ @param {Store} store
738
+ @param {Snapshot} snapshot
739
+ @return {Boolean}
740
+ @public
741
+ */
742
+ shouldBackgroundReloadRecord(store: Store, snapshot: Snapshot): boolean;
743
+ /**
744
+ This method is used by the store to determine if the store should
745
+ reload a record array after the `store.findAll` method resolves
746
+ with a cached record array.
747
+
748
+ This method is *only* checked by the store when the store is
749
+ returning a cached record array.
750
+
751
+ If this method returns `true` the store will re-fetch all records
752
+ from the adapter.
753
+
754
+ For example, if you do not want to fetch complex data over a mobile
755
+ connection, or if the network is down, you can implement
756
+ `shouldBackgroundReloadAll` as follows:
757
+
758
+ ```javascript
759
+ shouldBackgroundReloadAll(store, snapshotArray) {
760
+ let { downlink, effectiveType } = navigator.connection;
761
+
762
+ return downlink > 0 && effectiveType === '4g';
763
+ }
764
+ ```
765
+
766
+ By default this method returns `true`, indicating that a background reload
767
+ should always be triggered.
768
+
769
+ @since 1.13.0
770
+ @param {Store} store
771
+ @param {SnapshotRecordArray} snapshotRecordArray
772
+ @return {Boolean}
773
+ @public
774
+ */
775
+ shouldBackgroundReloadAll(store: Store, snapshotRecordArray: SnapshotRecordArray): boolean;
799
776
  }
800
- export { BuildURLMixin } from './adapter/-private/build-url-mixin.ts';
801
- //# sourceMappingURL=adapter.d.ts.map
777
+ export { BuildURLMixin } from "./adapter/-private/build-url-mixin.js";