@warp-drive/legacy 5.6.0-alpha.11

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 (211) hide show
  1. package/CHANGELOG.md +1 -0
  2. package/LICENSE.md +23 -0
  3. package/README.md +54 -0
  4. package/addon-main.cjs +5 -0
  5. package/declarations/adapter/-private/build-url-mixin.d.ts +34 -0
  6. package/declarations/adapter/-private/build-url-mixin.d.ts.map +1 -0
  7. package/declarations/adapter/-private/fastboot-interface.d.ts +9 -0
  8. package/declarations/adapter/-private/fastboot-interface.d.ts.map +1 -0
  9. package/declarations/adapter/-private/utils/continue-on-reject.d.ts +8 -0
  10. package/declarations/adapter/-private/utils/continue-on-reject.d.ts.map +1 -0
  11. package/declarations/adapter/-private/utils/determine-body-promise.d.ts +5 -0
  12. package/declarations/adapter/-private/utils/determine-body-promise.d.ts.map +1 -0
  13. package/declarations/adapter/-private/utils/fetch.d.ts +9 -0
  14. package/declarations/adapter/-private/utils/fetch.d.ts.map +1 -0
  15. package/declarations/adapter/-private/utils/parse-response-headers.d.ts +2 -0
  16. package/declarations/adapter/-private/utils/parse-response-headers.d.ts.map +1 -0
  17. package/declarations/adapter/-private/utils/serialize-into-hash.d.ts +7 -0
  18. package/declarations/adapter/-private/utils/serialize-into-hash.d.ts.map +1 -0
  19. package/declarations/adapter/-private/utils/serialize-query-params.d.ts +6 -0
  20. package/declarations/adapter/-private/utils/serialize-query-params.d.ts.map +1 -0
  21. package/declarations/adapter/-private.d.ts +6 -0
  22. package/declarations/adapter/-private.d.ts.map +1 -0
  23. package/declarations/adapter/error.d.ts +188 -0
  24. package/declarations/adapter/error.d.ts.map +1 -0
  25. package/declarations/adapter/json-api.d.ts +234 -0
  26. package/declarations/adapter/json-api.d.ts.map +1 -0
  27. package/declarations/adapter/rest.d.ts +823 -0
  28. package/declarations/adapter/rest.d.ts.map +1 -0
  29. package/declarations/adapter.d.ts +801 -0
  30. package/declarations/adapter.d.ts.map +1 -0
  31. package/declarations/compat/-private.d.ts +14 -0
  32. package/declarations/compat/-private.d.ts.map +1 -0
  33. package/declarations/compat/builders/find-all.d.ts +33 -0
  34. package/declarations/compat/builders/find-all.d.ts.map +1 -0
  35. package/declarations/compat/builders/find-record.d.ts +54 -0
  36. package/declarations/compat/builders/find-record.d.ts.map +1 -0
  37. package/declarations/compat/builders/query.d.ts +61 -0
  38. package/declarations/compat/builders/query.d.ts.map +1 -0
  39. package/declarations/compat/builders/save-record.d.ts +32 -0
  40. package/declarations/compat/builders/save-record.d.ts.map +1 -0
  41. package/declarations/compat/builders/utils.d.ts +4 -0
  42. package/declarations/compat/builders/utils.d.ts.map +1 -0
  43. package/declarations/compat/builders.d.ts +15 -0
  44. package/declarations/compat/builders.d.ts.map +1 -0
  45. package/declarations/compat/legacy-network-handler/fetch-manager.d.ts +47 -0
  46. package/declarations/compat/legacy-network-handler/fetch-manager.d.ts.map +1 -0
  47. package/declarations/compat/legacy-network-handler/identifier-has-id.d.ts +3 -0
  48. package/declarations/compat/legacy-network-handler/identifier-has-id.d.ts.map +1 -0
  49. package/declarations/compat/legacy-network-handler/legacy-data-fetch.d.ts +12 -0
  50. package/declarations/compat/legacy-network-handler/legacy-data-fetch.d.ts.map +1 -0
  51. package/declarations/compat/legacy-network-handler/legacy-data-utils.d.ts +6 -0
  52. package/declarations/compat/legacy-network-handler/legacy-data-utils.d.ts.map +1 -0
  53. package/declarations/compat/legacy-network-handler/legacy-network-handler.d.ts +3 -0
  54. package/declarations/compat/legacy-network-handler/legacy-network-handler.d.ts.map +1 -0
  55. package/declarations/compat/legacy-network-handler/minimum-adapter-interface.d.ts +527 -0
  56. package/declarations/compat/legacy-network-handler/minimum-adapter-interface.d.ts.map +1 -0
  57. package/declarations/compat/legacy-network-handler/minimum-serializer-interface.d.ts +224 -0
  58. package/declarations/compat/legacy-network-handler/minimum-serializer-interface.d.ts.map +1 -0
  59. package/declarations/compat/legacy-network-handler/serializer-response.d.ts +7 -0
  60. package/declarations/compat/legacy-network-handler/serializer-response.d.ts.map +1 -0
  61. package/declarations/compat/legacy-network-handler/snapshot-record-array.d.ts +89 -0
  62. package/declarations/compat/legacy-network-handler/snapshot-record-array.d.ts.map +1 -0
  63. package/declarations/compat/legacy-network-handler/snapshot.d.ts +237 -0
  64. package/declarations/compat/legacy-network-handler/snapshot.d.ts.map +1 -0
  65. package/declarations/compat/utils.d.ts +138 -0
  66. package/declarations/compat/utils.d.ts.map +1 -0
  67. package/declarations/compat.d.ts +134 -0
  68. package/declarations/compat.d.ts.map +1 -0
  69. package/declarations/model/-private/attr.d.ts +165 -0
  70. package/declarations/model/-private/attr.d.ts.map +1 -0
  71. package/declarations/model/-private/attr.type-test.d.ts +2 -0
  72. package/declarations/model/-private/attr.type-test.d.ts.map +1 -0
  73. package/declarations/model/-private/belongs-to.d.ts +173 -0
  74. package/declarations/model/-private/belongs-to.d.ts.map +1 -0
  75. package/declarations/model/-private/belongs-to.type-test.d.ts +2 -0
  76. package/declarations/model/-private/belongs-to.type-test.d.ts.map +1 -0
  77. package/declarations/model/-private/debug/assert-polymorphic-type.d.ts +6 -0
  78. package/declarations/model/-private/debug/assert-polymorphic-type.d.ts.map +1 -0
  79. package/declarations/model/-private/errors.d.ts +290 -0
  80. package/declarations/model/-private/errors.d.ts.map +1 -0
  81. package/declarations/model/-private/has-many.d.ts +164 -0
  82. package/declarations/model/-private/has-many.d.ts.map +1 -0
  83. package/declarations/model/-private/has-many.type-test.d.ts +2 -0
  84. package/declarations/model/-private/has-many.type-test.d.ts.map +1 -0
  85. package/declarations/model/-private/hooks.d.ts +11 -0
  86. package/declarations/model/-private/hooks.d.ts.map +1 -0
  87. package/declarations/model/-private/legacy-relationships-support.d.ts +57 -0
  88. package/declarations/model/-private/legacy-relationships-support.d.ts.map +1 -0
  89. package/declarations/model/-private/model-for-mixin.d.ts +4 -0
  90. package/declarations/model/-private/model-for-mixin.d.ts.map +1 -0
  91. package/declarations/model/-private/model-methods.d.ts +35 -0
  92. package/declarations/model/-private/model-methods.d.ts.map +1 -0
  93. package/declarations/model/-private/model.d.ts +1270 -0
  94. package/declarations/model/-private/model.d.ts.map +1 -0
  95. package/declarations/model/-private/model.type-test.d.ts +2 -0
  96. package/declarations/model/-private/model.type-test.d.ts.map +1 -0
  97. package/declarations/model/-private/notify-changes.d.ts +5 -0
  98. package/declarations/model/-private/notify-changes.d.ts.map +1 -0
  99. package/declarations/model/-private/promise-belongs-to.d.ts +40 -0
  100. package/declarations/model/-private/promise-belongs-to.d.ts.map +1 -0
  101. package/declarations/model/-private/promise-many-array.d.ts +126 -0
  102. package/declarations/model/-private/promise-many-array.d.ts.map +1 -0
  103. package/declarations/model/-private/promise-proxy-base.d.ts +3 -0
  104. package/declarations/model/-private/promise-proxy-base.d.ts.map +1 -0
  105. package/declarations/model/-private/record-state.d.ts +78 -0
  106. package/declarations/model/-private/record-state.d.ts.map +1 -0
  107. package/declarations/model/-private/references/belongs-to.d.ts +495 -0
  108. package/declarations/model/-private/references/belongs-to.d.ts.map +1 -0
  109. package/declarations/model/-private/references/has-many.d.ts +504 -0
  110. package/declarations/model/-private/references/has-many.d.ts.map +1 -0
  111. package/declarations/model/-private/schema-provider.d.ts +63 -0
  112. package/declarations/model/-private/schema-provider.d.ts.map +1 -0
  113. package/declarations/model/-private/type-utils.d.ts +57 -0
  114. package/declarations/model/-private/type-utils.d.ts.map +1 -0
  115. package/declarations/model/-private/util.d.ts +6 -0
  116. package/declarations/model/-private/util.d.ts.map +1 -0
  117. package/declarations/model/-private.d.ts +8 -0
  118. package/declarations/model/-private.d.ts.map +1 -0
  119. package/declarations/model/migration-support.d.ts +287 -0
  120. package/declarations/model/migration-support.d.ts.map +1 -0
  121. package/declarations/model/migration-support.type-test.d.ts +2 -0
  122. package/declarations/model/migration-support.type-test.d.ts.map +1 -0
  123. package/declarations/model.d.ts +50 -0
  124. package/declarations/model.d.ts.map +1 -0
  125. package/declarations/serializer/-private/embedded-records-mixin.d.ts +97 -0
  126. package/declarations/serializer/-private/embedded-records-mixin.d.ts.map +1 -0
  127. package/declarations/serializer/-private/transforms/boolean.d.ts +47 -0
  128. package/declarations/serializer/-private/transforms/boolean.d.ts.map +1 -0
  129. package/declarations/serializer/-private/transforms/boolean.type-test.d.ts +2 -0
  130. package/declarations/serializer/-private/transforms/boolean.type-test.d.ts.map +1 -0
  131. package/declarations/serializer/-private/transforms/date.d.ts +28 -0
  132. package/declarations/serializer/-private/transforms/date.d.ts.map +1 -0
  133. package/declarations/serializer/-private/transforms/number.d.ts +29 -0
  134. package/declarations/serializer/-private/transforms/number.d.ts.map +1 -0
  135. package/declarations/serializer/-private/transforms/string.d.ts +29 -0
  136. package/declarations/serializer/-private/transforms/string.d.ts.map +1 -0
  137. package/declarations/serializer/-private/transforms/transform.d.ts +119 -0
  138. package/declarations/serializer/-private/transforms/transform.d.ts.map +1 -0
  139. package/declarations/serializer/-private/utils.d.ts +4 -0
  140. package/declarations/serializer/-private/utils.d.ts.map +1 -0
  141. package/declarations/serializer/json-api.d.ts +496 -0
  142. package/declarations/serializer/json-api.d.ts.map +1 -0
  143. package/declarations/serializer/json.d.ts +1047 -0
  144. package/declarations/serializer/json.d.ts.map +1 -0
  145. package/declarations/serializer/rest.d.ts +554 -0
  146. package/declarations/serializer/rest.d.ts.map +1 -0
  147. package/declarations/serializer/transform.d.ts +6 -0
  148. package/declarations/serializer/transform.d.ts.map +1 -0
  149. package/declarations/serializer.d.ts +258 -0
  150. package/declarations/serializer.d.ts.map +1 -0
  151. package/dist/-private-DFfBszo5.js +1182 -0
  152. package/dist/-private-DFfBszo5.js.map +1 -0
  153. package/dist/adapter/-private.js +1 -0
  154. package/dist/adapter/-private.js.map +1 -0
  155. package/dist/adapter/error.js +254 -0
  156. package/dist/adapter/error.js.map +1 -0
  157. package/dist/adapter/json-api.js +129 -0
  158. package/dist/adapter/json-api.js.map +1 -0
  159. package/dist/adapter/rest.js +1262 -0
  160. package/dist/adapter/rest.js.map +1 -0
  161. package/dist/adapter.js +1284 -0
  162. package/dist/adapter.js.map +1 -0
  163. package/dist/compat/-private.js +1 -0
  164. package/dist/compat/-private.js.map +1 -0
  165. package/dist/compat/builders.js +292 -0
  166. package/dist/compat/builders.js.map +1 -0
  167. package/dist/compat/utils.js +225 -0
  168. package/dist/compat/utils.js.map +1 -0
  169. package/dist/compat.js +999 -0
  170. package/dist/compat.js.map +1 -0
  171. package/dist/errors-D74uk36r.js +2541 -0
  172. package/dist/errors-D74uk36r.js.map +1 -0
  173. package/dist/json-BCH3fil7.js +1349 -0
  174. package/dist/json-BCH3fil7.js.map +1 -0
  175. package/dist/model/-private.js +2 -0
  176. package/dist/model/-private.js.map +1 -0
  177. package/dist/model/migration-support.js +453 -0
  178. package/dist/model/migration-support.js.map +1 -0
  179. package/dist/model.js +736 -0
  180. package/dist/model.js.map +1 -0
  181. package/dist/runtime-BPCpkOf1-BKOwiRJp.js +65 -0
  182. package/dist/runtime-BPCpkOf1-BKOwiRJp.js.map +1 -0
  183. package/dist/schema-provider-CXFLTMjg.js +2228 -0
  184. package/dist/schema-provider-CXFLTMjg.js.map +1 -0
  185. package/dist/serialize-into-hash-BxfqWC8u.js +260 -0
  186. package/dist/serialize-into-hash-BxfqWC8u.js.map +1 -0
  187. package/dist/serializer/json-api.js +514 -0
  188. package/dist/serializer/json-api.js.map +1 -0
  189. package/dist/serializer/json.js +6 -0
  190. package/dist/serializer/json.js.map +1 -0
  191. package/dist/serializer/rest.js +1245 -0
  192. package/dist/serializer/rest.js.map +1 -0
  193. package/dist/serializer/transform.js +313 -0
  194. package/dist/serializer/transform.js.map +1 -0
  195. package/dist/serializer.js +252 -0
  196. package/dist/serializer.js.map +1 -0
  197. package/logos/NCC-1701-a-blue.svg +4 -0
  198. package/logos/NCC-1701-a-gold.svg +4 -0
  199. package/logos/NCC-1701-a-gold_100.svg +1 -0
  200. package/logos/NCC-1701-a-gold_base-64.txt +1 -0
  201. package/logos/NCC-1701-a.svg +4 -0
  202. package/logos/README.md +4 -0
  203. package/logos/docs-badge.svg +2 -0
  204. package/logos/ember-data-logo-dark.svg +12 -0
  205. package/logos/ember-data-logo-light.svg +12 -0
  206. package/logos/github-header.svg +444 -0
  207. package/logos/social1.png +0 -0
  208. package/logos/social2.png +0 -0
  209. package/logos/warp-drive-logo-dark.svg +4 -0
  210. package/logos/warp-drive-logo-gold.svg +4 -0
  211. package/package.json +72 -0
@@ -0,0 +1,801 @@
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
+ ```
144
+
145
+
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
+
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
+
172
+ ### Using an Adapter
173
+
174
+ Any adapter in `app/adapters/` can be looked up by `name` using `store.adapterFor(name)`.
175
+
176
+ ### Default Adapters
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.
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.
184
+
185
+ @module
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';
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`.
199
+
200
+ > ⚠️ CAUTION you likely want the docs for {@link MinimumAdapterInterface}
201
+ > as extending this abstract class is unnecessary.
202
+
203
+ ### Creating an Adapter
204
+
205
+ Create a new subclass of `Adapter` in the `app/adapters` folder:
206
+
207
+ ```js [app/adapters/application.js]
208
+ import { Adapter } from '@warp-drive/legacy/adapter';
209
+
210
+ export default class extends Adapter {
211
+ // ...your code here
212
+ }
213
+ ```
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.
217
+
218
+ ```js [app/adapters/post.js]
219
+ import { Adapter } from '@warp-drive/legacy/adapter';
220
+
221
+ export default class extends Adapter {
222
+ // ...Post-specific adapter code goes here
223
+ }
224
+ ```
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:
229
+
230
+ * `findRecord()`
231
+ * `createRecord()`
232
+ * `updateRecord()`
233
+ * `deleteRecord()`
234
+ * `findAll()`
235
+ * `query()`
236
+
237
+ To improve the network performance of your application, you can optimize
238
+ your adapter by overriding these lower-level methods:
239
+
240
+ * `findMany()`
241
+
242
+
243
+ For an example of the implementation, see `RESTAdapter`, the
244
+ included REST adapter.
245
+
246
+ @class Adapter
247
+ @public
248
+ */
249
+ 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;
799
+ }
800
+ export { BuildURLMixin } from './adapter/-private/build-url-mixin.ts';
801
+ //# sourceMappingURL=adapter.d.ts.map