@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,823 @@
1
+ import type { Store } from '@warp-drive/core';
2
+ import type { ModelSchema } from '@warp-drive/core/types';
3
+ import type { HTTPMethod } from '@warp-drive/core/types/request';
4
+ import { Adapter } from '../adapter.ts';
5
+ import type { AdapterPayload } from '../compat.ts';
6
+ import type { Snapshot, SnapshotRecordArray } from '../compat/-private.ts';
7
+ import type { MixtBuildURLMixin } from './-private/build-url-mixin.ts';
8
+ import type { FastBoot } from './-private/fastboot-interface.ts';
9
+ import { AdapterError } from './error.js';
10
+ type Payload = Error | Record<string, unknown> | unknown[] | string | undefined;
11
+ export type QueryState = {
12
+ include?: unknown;
13
+ since?: unknown;
14
+ };
15
+ export interface FetchRequestInit extends RequestInit {
16
+ url: string;
17
+ method: HTTPMethod;
18
+ type: HTTPMethod;
19
+ }
20
+ export interface JQueryRequestInit extends JQueryAjaxSettings {
21
+ url: string;
22
+ method: HTTPMethod;
23
+ type: HTTPMethod;
24
+ }
25
+ export type RequestData = {
26
+ url: string;
27
+ method: HTTPMethod;
28
+ [key: string]: unknown;
29
+ };
30
+ declare const RESTAdapter_base: Readonly<typeof Adapter> & (new (owner?: import("@ember/-internals/owner").default) => Adapter) & import("@ember/object/mixin").default;
31
+ /**
32
+ * <blockquote style="margin: 1em; padding: .1em 1em .1em 1em; border-left: solid 1em #E34C32; background: #e0e0e0;">
33
+ <p>
34
+ ⚠️ <strong>This is LEGACY documentation</strong> for a feature that is no longer encouraged to be used.
35
+ If starting a new app or thinking of implementing a new adapter, consider writing a
36
+ <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>
37
+ </p>
38
+ </blockquote>
39
+
40
+ The REST adapter allows your store to communicate with an HTTP server by
41
+ transmitting JSON via XHR.
42
+
43
+ This adapter is designed around the idea that the JSON exchanged with
44
+ the server should be conventional. It builds URLs in a manner that follows
45
+ the structure of most common REST-style web services.
46
+
47
+ ## Success and failure
48
+
49
+ The REST adapter will consider a success any response with a status code
50
+ of the 2xx family ("Success"), as well as 304 ("Not Modified"). Any other
51
+ status code will be considered a failure.
52
+
53
+ On success, the request promise will be resolved with the full response
54
+ payload.
55
+
56
+ Failed responses with status code 422 ("Unprocessable Entity") will be
57
+ considered "invalid". The response will be discarded, except for the
58
+ `errors` key. The request promise will be rejected with a `InvalidError`.
59
+ This error object will encapsulate the saved `errors` value.
60
+
61
+ Any other status codes will be treated as an "adapter error". The request
62
+ promise will be rejected, similarly to the "invalid" case, but with
63
+ an instance of `AdapterError` instead.
64
+
65
+ ## JSON Structure
66
+
67
+ The REST adapter expects the JSON returned from your server to follow
68
+ these conventions.
69
+
70
+ ### Object Root
71
+
72
+ The JSON payload should be an object that contains the record inside a
73
+ root property. For example, in response to a `GET` request for
74
+ `/posts/1`, the JSON should look like this:
75
+
76
+ ```js
77
+ {
78
+ "posts": {
79
+ "id": 1,
80
+ "title": "I'm Running to Reform the W3C",
81
+ "author": "Yehuda Katz"
82
+ }
83
+ }
84
+ ```
85
+
86
+ Similarly, in response to a `GET` request for `/posts`, the JSON should
87
+ look like this:
88
+
89
+ ```js
90
+ {
91
+ "posts": [
92
+ {
93
+ "id": 1,
94
+ "title": "I'm Running to Reform the W3C",
95
+ "author": "Yehuda Katz"
96
+ },
97
+ {
98
+ "id": 2,
99
+ "title": "Rails is omakase",
100
+ "author": "D2H"
101
+ }
102
+ ]
103
+ }
104
+ ```
105
+
106
+ Note that the object root can be pluralized for both a single-object response
107
+ and an array response: the REST adapter is not strict on this. Further, if the
108
+ HTTP server responds to a `GET` request to `/posts/1` (e.g. the response to a
109
+ `findRecord` query) with more than one object in the array, Ember Data will
110
+ only display the object with the matching ID.
111
+
112
+ ### Conventional Names
113
+
114
+ Attribute names in your JSON payload should be the camelCased versions of
115
+ the attributes in your Ember.js models.
116
+
117
+ For example, if you have a `Person` model:
118
+
119
+ ```js [app/models/person.js]
120
+ import { Model, attr } from '@warp-drive/legacy/model';
121
+
122
+ export default Model.extend({
123
+ firstName: attr('string'),
124
+ lastName: attr('string'),
125
+ occupation: attr('string')
126
+ });
127
+ ```
128
+
129
+ The JSON returned should look like this:
130
+
131
+ ```js
132
+ {
133
+ "people": {
134
+ "id": 5,
135
+ "firstName": "Zaphod",
136
+ "lastName": "Beeblebrox",
137
+ "occupation": "President"
138
+ }
139
+ }
140
+ ```
141
+
142
+ #### Relationships
143
+
144
+ Relationships are usually represented by ids to the record in the
145
+ relationship. The related records can then be sideloaded in the
146
+ response under a key for the type.
147
+
148
+ ```js
149
+ {
150
+ "posts": {
151
+ "id": 5,
152
+ "title": "I'm Running to Reform the W3C",
153
+ "author": "Yehuda Katz",
154
+ "comments": [1, 2]
155
+ },
156
+ "comments": [{
157
+ "id": 1,
158
+ "author": "User 1",
159
+ "message": "First!",
160
+ }, {
161
+ "id": 2,
162
+ "author": "User 2",
163
+ "message": "Good Luck!",
164
+ }]
165
+ }
166
+ ```
167
+
168
+ If the records in the relationship are not known when the response
169
+ is serialized it's also possible to represent the relationship as a
170
+ URL using the `links` key in the response. Ember Data will fetch
171
+ this URL to resolve the relationship when it is accessed for the
172
+ first time.
173
+
174
+ ```js
175
+ {
176
+ "posts": {
177
+ "id": 5,
178
+ "title": "I'm Running to Reform the W3C",
179
+ "author": "Yehuda Katz",
180
+ "links": {
181
+ "comments": "/posts/5/comments"
182
+ }
183
+ }
184
+ }
185
+ ```
186
+
187
+ ### Errors
188
+
189
+ If a response is considered a failure, the JSON payload is expected to include
190
+ a top-level key `errors`, detailing any specific issues. For example:
191
+
192
+ ```js
193
+ {
194
+ "errors": {
195
+ "msg": "Something went wrong"
196
+ }
197
+ }
198
+ ```
199
+
200
+ This adapter does not make any assumptions as to the format of the `errors`
201
+ object. It will simply be passed along as is, wrapped in an instance
202
+ of `InvalidError` or `AdapterError`. The serializer can interpret it
203
+ afterwards.
204
+
205
+ ## Customization
206
+
207
+ ### Endpoint path customization
208
+
209
+ Endpoint paths can be prefixed with a `namespace` by setting the namespace
210
+ property on the adapter:
211
+
212
+ ```js [app/adapters/application.js]
213
+ import { RESTAdapter } from '@warp-drive/legacy/adapter/rest';
214
+
215
+ export default class ApplicationAdapter extends RESTAdapter {
216
+ namespace = 'api/1';
217
+ }
218
+ ```
219
+ Requests for the `Person` model would now target `/api/1/people/1`.
220
+
221
+ ### Host customization
222
+
223
+ An adapter can target other hosts by setting the `host` property.
224
+
225
+ ```js [app/adapters/application.js]
226
+ import { RESTAdapter } from '@warp-drive/legacy/adapter/rest';
227
+
228
+ export default class ApplicationAdapter extends RESTAdapter {
229
+ host = 'https://api.example.com';
230
+ }
231
+ ```
232
+
233
+ ### Headers customization
234
+
235
+ Some APIs require HTTP headers, e.g. to provide an API key. Arbitrary
236
+ headers can be set as key/value pairs on the `RESTAdapter`'s `headers`
237
+ object and WarpDrive will send them along with each ajax request.
238
+
239
+
240
+ ```js [app/adapters/application.js]
241
+ import { RESTAdapter } from '@warp-drive/legacy/adapter/rest';
242
+
243
+ export default class ApplicationAdapter extends RESTAdapter {
244
+ get headers() {
245
+ return {
246
+ 'API_KEY': 'secret key',
247
+ 'ANOTHER_HEADER': 'Some header value'
248
+ };
249
+ }
250
+ }
251
+ ```
252
+
253
+ @class RESTAdapter
254
+ @public
255
+ @constructor
256
+ @uses BuildURLMixin
257
+ */
258
+ declare class RESTAdapter extends RESTAdapter_base {
259
+ _fastboot: FastBoot;
260
+ _coalesceFindRequests: boolean;
261
+ host: string | null;
262
+ namespace: string | null;
263
+ /**
264
+ This property allows ajax to still be used instead when `false`.
265
+
266
+ @property useFetch
267
+ @type {Boolean}
268
+ @default true
269
+ @public
270
+ */
271
+ useFetch: boolean;
272
+ _defaultContentType: string;
273
+ get fastboot(): FastBoot;
274
+ set fastboot(value: FastBoot);
275
+ /**
276
+ By default, the RESTAdapter will send the query params sorted alphabetically to the
277
+ server.
278
+
279
+ For example:
280
+
281
+ ```js
282
+ store.query('posts', { sort: 'price', category: 'pets' });
283
+ ```
284
+
285
+ will generate a requests like this `/posts?category=pets&sort=price`, even if the
286
+ parameters were specified in a different order.
287
+
288
+ That way the generated URL will be deterministic and that simplifies caching mechanisms
289
+ in the backend.
290
+
291
+ Setting `sortQueryParams` to a falsey value will respect the original order.
292
+
293
+ In case you want to sort the query parameters with a different criteria, set
294
+ `sortQueryParams` to your custom sort function.
295
+
296
+ ```js [app/adapters/application.js]
297
+ import { RESTAdapter } from '@warp-drive/legacy/adapter/rest';
298
+
299
+ export default class ApplicationAdapter extends RESTAdapter {
300
+ sortQueryParams(params) {
301
+ let sortedKeys = Object.keys(params).sort().reverse();
302
+ let len = sortedKeys.length, newParams = {};
303
+
304
+ for (let i = 0; i < len; i++) {
305
+ newParams[sortedKeys[i]] = params[sortedKeys[i]];
306
+ }
307
+
308
+ return newParams;
309
+ }
310
+ }
311
+ ```
312
+
313
+ @param {Object} obj
314
+ @return {Object}
315
+ @public
316
+ */
317
+ sortQueryParams(obj: Record<string, unknown>): Record<string, unknown>;
318
+ /**
319
+ By default the RESTAdapter will send each find request coming from a `store.find`
320
+ or from accessing a relationship separately to the server. If your server supports passing
321
+ ids as a query string, you can set coalesceFindRequests to true to coalesce all find requests
322
+ within a single runloop.
323
+
324
+ For example, if you have an initial payload of:
325
+
326
+ ```javascript
327
+ {
328
+ post: {
329
+ id: 1,
330
+ comments: [1, 2]
331
+ }
332
+ }
333
+ ```
334
+
335
+ By default calling `post.comments` will trigger the following requests(assuming the
336
+ comments haven't been loaded before):
337
+
338
+ ```
339
+ GET /comments/1
340
+ GET /comments/2
341
+ ```
342
+
343
+ If you set coalesceFindRequests to `true` it will instead trigger the following request:
344
+
345
+ ```
346
+ GET /comments?ids[]=1&ids[]=2
347
+ ```
348
+
349
+ Setting coalesceFindRequests to `true` also works for `store.find` requests and `belongsTo`
350
+ relationships accessed within the same runloop. If you set `coalesceFindRequests: true`
351
+
352
+ ```javascript
353
+ store.findRecord('comment', 1);
354
+ store.findRecord('comment', 2);
355
+ ```
356
+
357
+ will also send a request to: `GET /comments?ids[]=1&ids[]=2`
358
+
359
+ Note: Requests coalescing rely on URL building strategy. So if you override `buildURL` in your app
360
+ `groupRecordsForFindMany` more likely should be overridden as well in order for coalescing to work.
361
+
362
+ @property coalesceFindRequests
363
+ @public
364
+ @type {Boolean}
365
+ */
366
+ get coalesceFindRequests(): boolean;
367
+ set coalesceFindRequests(value: boolean);
368
+ /**
369
+ Endpoint paths can be prefixed with a `namespace` by setting the namespace
370
+ property on the adapter:
371
+
372
+ ```js [app/adapters/application.js]
373
+ import { RESTAdapter } from '@warp-drive/legacy/adapter/rest';
374
+
375
+ export default class ApplicationAdapter extends RESTAdapter {
376
+ namespace = 'api/1';
377
+ }
378
+ ```
379
+
380
+ Requests for the `Post` model would now target `/api/1/post/`.
381
+
382
+ @property namespace
383
+ @public
384
+ @type {String}
385
+ */
386
+ /**
387
+ An adapter can target other hosts by setting the `host` property.
388
+
389
+ ```js [app/adapters/application.js]
390
+ import { RESTAdapter } from '@warp-drive/legacy/adapter/rest';
391
+
392
+ export default class ApplicationAdapter extends RESTAdapter {
393
+ host = 'https://api.example.com';
394
+ }
395
+ ```
396
+
397
+ Requests for the `Post` model would now target `https://api.example.com/post/`.
398
+
399
+ @property host
400
+ @public
401
+ @type {String}
402
+ */
403
+ /**
404
+ Some APIs require HTTP headers, e.g. to provide an API
405
+ key. Arbitrary headers can be set as key/value pairs on the
406
+ `RESTAdapter`'s `headers` object and Ember Data will send them
407
+ along with each ajax request. For dynamic headers see [headers
408
+ customization](/ember-data/release/classes/RESTAdapter).
409
+
410
+ ```js [app/adapters/application.js]
411
+ import { RESTAdapter } from '@warp-drive/legacy/adapter/rest';
412
+
413
+ export default class ApplicationAdapter extends RESTAdapter {
414
+ get headers() {
415
+ return {
416
+ 'API_KEY': 'secret key',
417
+ 'ANOTHER_HEADER': 'Some header value'
418
+ };
419
+ }
420
+ }
421
+ ```
422
+
423
+ @property headers
424
+ @public
425
+ @type {Object}
426
+ */
427
+ headers: Record<string, unknown> | undefined;
428
+ /**
429
+ Called by the store in order to fetch the JSON for a given
430
+ type and ID.
431
+
432
+ The `findRecord` method makes an Ajax request to a URL computed by
433
+ `buildURL`, and returns a promise for the resulting payload.
434
+
435
+ This method performs an HTTP `GET` request with the id provided as part of the query string.
436
+
437
+ @since 1.13.0
438
+ @public
439
+ @param {Store} store
440
+ @param {Model} type
441
+ @param {String} id
442
+ @param {Snapshot} snapshot
443
+ @return {Promise} promise
444
+ */
445
+ findRecord(store: Store, type: ModelSchema, id: string, snapshot: Snapshot): Promise<AdapterPayload>;
446
+ /**
447
+ Called by the store in order to fetch a JSON array for all
448
+ of the records for a given type.
449
+
450
+ The `findAll` method makes an Ajax (HTTP GET) request to a URL computed by `buildURL`, and returns a
451
+ promise for the resulting payload.
452
+
453
+ @public
454
+ @param {Store} store
455
+ @param {Model} type
456
+ @param {undefined} neverSet a value is never provided to this argument
457
+ @param {SnapshotRecordArray} snapshotRecordArray
458
+ @return {Promise} promise
459
+ */
460
+ findAll(store: Store, type: ModelSchema, sinceToken: null, snapshotRecordArray: SnapshotRecordArray): Promise<AdapterPayload>;
461
+ /**
462
+ Called by the store in order to fetch a JSON array for
463
+ the records that match a particular query.
464
+
465
+ The `query` method makes an Ajax (HTTP GET) request to a URL
466
+ computed by `buildURL`, and returns a promise for the resulting
467
+ payload.
468
+
469
+ The `query` argument is a simple JavaScript object that will be passed directly
470
+ to the server as parameters.
471
+
472
+ @public
473
+ @param {Store} store
474
+ @param {Model} type
475
+ @param {Object} query
476
+ @param {Collection} recordArray
477
+ @param {Object} adapterOptions
478
+ @return {Promise} promise
479
+ */
480
+ query(store: Store, type: ModelSchema, query: Record<string, unknown>): Promise<AdapterPayload>;
481
+ /**
482
+ Called by the store in order to fetch a JSON object for
483
+ the record that matches a particular query.
484
+
485
+ The `queryRecord` method makes an Ajax (HTTP GET) request to a URL
486
+ computed by `buildURL`, and returns a promise for the resulting
487
+ payload.
488
+
489
+ The `query` argument is a simple JavaScript object that will be passed directly
490
+ to the server as parameters.
491
+
492
+ @since 1.13.0
493
+ @public
494
+ @param {Store} store
495
+ @param {Model} type
496
+ @param {Object} query
497
+ @param {Object} adapterOptions
498
+ @return {Promise} promise
499
+ */
500
+ queryRecord(store: Store, type: ModelSchema, query: Record<string, unknown>, adapterOptions: Record<string, unknown>): Promise<AdapterPayload>;
501
+ /**
502
+ Called by the store in order to fetch several records together if `coalesceFindRequests` is true
503
+
504
+ For example, if the original payload looks like:
505
+
506
+ ```js
507
+ {
508
+ "id": 1,
509
+ "title": "Rails is omakase",
510
+ "comments": [ 1, 2, 3 ]
511
+ }
512
+ ```
513
+
514
+ The IDs will be passed as a URL-encoded Array of IDs, in this form:
515
+
516
+ ```
517
+ ids[]=1&ids[]=2&ids[]=3
518
+ ```
519
+
520
+ Many servers, such as Rails and PHP, will automatically convert this URL-encoded array
521
+ into an Array for you on the server-side. If you want to encode the
522
+ IDs, differently, just override this (one-line) method.
523
+
524
+ The `findMany` method makes an Ajax (HTTP GET) request to a URL computed by `buildURL`, and returns a
525
+ promise for the resulting payload.
526
+
527
+ @public
528
+ @param {Store} store
529
+ @param {Model} type
530
+ @param {Array} ids
531
+ @param {Array} snapshots
532
+ @return {Promise} promise
533
+ */
534
+ findMany(store: Store, type: ModelSchema, ids: string[], snapshots: Snapshot[]): Promise<AdapterPayload>;
535
+ /**
536
+ Called by the store in order to fetch a JSON array for
537
+ the unloaded records in a has-many relationship that were originally
538
+ specified as a URL (inside of `links`).
539
+
540
+ For example, if your original payload looks like this:
541
+
542
+ ```js
543
+ {
544
+ "post": {
545
+ "id": 1,
546
+ "title": "Rails is omakase",
547
+ "links": { "comments": "/posts/1/comments" }
548
+ }
549
+ }
550
+ ```
551
+
552
+ This method will be called with the parent record and `/posts/1/comments`.
553
+
554
+ The `findHasMany` method will make an Ajax (HTTP GET) request to the originally specified URL.
555
+
556
+ The format of your `links` value will influence the final request URL via the `urlPrefix` method:
557
+
558
+ * Links beginning with `//`, `http://`, `https://`, will be used as is, with no further manipulation.
559
+
560
+ * Links beginning with a single `/` will have the current adapter's `host` value prepended to it.
561
+
562
+ * Links with no beginning `/` will have a parentURL prepended to it, via the current adapter's `buildURL`.
563
+
564
+ @public
565
+ @param {Store} store
566
+ @param {Snapshot} snapshot
567
+ @param {String} url
568
+ @param {Object} relationship meta object describing the relationship
569
+ @return {Promise} promise
570
+ */
571
+ findHasMany(store: Store, snapshot: Snapshot, url: string, relationship: Record<string, unknown>): Promise<AdapterPayload>;
572
+ /**
573
+ Called by the store in order to fetch the JSON for the unloaded record in a
574
+ belongs-to relationship that was originally specified as a URL (inside of
575
+ `links`).
576
+
577
+ For example, if your original payload looks like this:
578
+
579
+ ```js
580
+ {
581
+ "person": {
582
+ "id": 1,
583
+ "name": "Tom Dale",
584
+ "links": { "group": "/people/1/group" }
585
+ }
586
+ }
587
+ ```
588
+
589
+ This method will be called with the parent record and `/people/1/group`.
590
+
591
+ The `findBelongsTo` method will make an Ajax (HTTP GET) request to the originally specified URL.
592
+
593
+ The format of your `links` value will influence the final request URL via the `urlPrefix` method:
594
+
595
+ * Links beginning with `//`, `http://`, `https://`, will be used as is, with no further manipulation.
596
+
597
+ * Links beginning with a single `/` will have the current adapter's `host` value prepended to it.
598
+
599
+ * Links with no beginning `/` will have a parentURL prepended to it, via the current adapter's `buildURL`.
600
+
601
+ @public
602
+ @param {Store} store
603
+ @param {Snapshot} snapshot
604
+ @param {String} url
605
+ @param {Object} relationship meta object describing the relationship
606
+ @return {Promise} promise
607
+ */
608
+ findBelongsTo(store: Store, snapshot: Snapshot, url: string, relationship: any): Promise<AdapterPayload>;
609
+ /**
610
+ Called by the store when a newly created record is
611
+ saved via the `save` method on a model record instance.
612
+
613
+ The `createRecord` method serializes the record and makes an Ajax (HTTP POST) request
614
+ to a URL computed by `buildURL`.
615
+
616
+ See `serialize` for information on how to customize the serialized form
617
+ of a record.
618
+
619
+ @public
620
+ @param {Store} store
621
+ @param {Model} type
622
+ @param {Snapshot} snapshot
623
+ @return {Promise} promise
624
+ */
625
+ createRecord(store: Store, type: ModelSchema, snapshot: Snapshot): Promise<AdapterPayload>;
626
+ /**
627
+ Called by the store when an existing record is saved
628
+ via the `save` method on a model record instance.
629
+
630
+ The `updateRecord` method serializes the record and makes an Ajax (HTTP PUT) request
631
+ to a URL computed by `buildURL`.
632
+
633
+ See `serialize` for information on how to customize the serialized form
634
+ of a record.
635
+
636
+ @public
637
+ @param {Store} store
638
+ @param {Model} schema
639
+ @param {Snapshot} snapshot
640
+ @return {Promise} promise
641
+ */
642
+ updateRecord(store: Store, schema: ModelSchema, snapshot: Snapshot): Promise<AdapterPayload>;
643
+ /**
644
+ Called by the store when a record is deleted.
645
+
646
+ The `deleteRecord` method makes an Ajax (HTTP DELETE) request to a URL computed by `buildURL`.
647
+
648
+ @public
649
+ @param {Store} store
650
+ @param {Model} type
651
+ @param {Snapshot} snapshot
652
+ @return {Promise} promise
653
+ */
654
+ deleteRecord(store: Store, schema: ModelSchema, snapshot: Snapshot): Promise<AdapterPayload>;
655
+ _stripIDFromURL(store: Store, snapshot: Snapshot): string;
656
+ maxURLLength: number;
657
+ /**
658
+ Organize records into groups, each of which is to be passed to separate
659
+ calls to `findMany`.
660
+
661
+ This implementation groups together records that have the same base URL but
662
+ differing ids. For example `/comments/1` and `/comments/2` will be grouped together
663
+ because we know findMany can coalesce them together as `/comments?ids[]=1&ids[]=2`
664
+
665
+ It also supports urls where ids are passed as a query param, such as `/comments?id=1`
666
+ but not those where there is more than 1 query param such as `/comments?id=2&name=David`
667
+ Currently only the query param of `id` is supported. If you need to support others, please
668
+ override this or the `_stripIDFromURL` method.
669
+
670
+ It does not group records that have differing base urls, such as for example: `/posts/1/comments/2`
671
+ and `/posts/2/comments/3`
672
+
673
+ @public
674
+ @param {Store} store
675
+ @param {Array} snapshots
676
+ @return {Array} an array of arrays of records, each of which is to be
677
+ loaded separately by `findMany`.
678
+ */
679
+ groupRecordsForFindMany(store: Store, snapshots: Snapshot[]): Snapshot[][];
680
+ /**
681
+ Takes an ajax response, and returns the json payload or an error.
682
+
683
+ By default this hook just returns the json payload passed to it.
684
+ You might want to override it in two cases:
685
+
686
+ 1. Your API might return useful results in the response headers.
687
+ Response headers are passed in as the second argument.
688
+
689
+ 2. Your API might return errors as successful responses with status code
690
+ 200 and an Errors text or object. You can return a `InvalidError` or a
691
+ `AdapterError` (or a sub class) from this hook and it will automatically
692
+ reject the promise and put your record into the invalid or error state.
693
+
694
+ Returning a `InvalidError` from this method will cause the
695
+ record to transition into the `invalid` state and make the
696
+ `errors` object available on the record. When returning an
697
+ `InvalidError` the store will attempt to normalize the error data
698
+ returned from the server using the serializer's `extractErrors`
699
+ method.
700
+
701
+ @since 1.13.0
702
+ @public
703
+ @param {Number} status
704
+ @param {Object} headers
705
+ @param {Object} payload
706
+ @param {Object} requestData - the original request information
707
+ @return {Object | AdapterError} response
708
+ */
709
+ handleResponse(status: number, headers: Record<string, string>, payload: Payload, requestData: RequestData): Payload | typeof AdapterError;
710
+ /**
711
+ Default `handleResponse` implementation uses this hook to decide if the
712
+ response is a success.
713
+
714
+ @since 1.13.0
715
+ @public
716
+ @param {Number} status
717
+ @param {Object} headers
718
+ @param {Object} payload
719
+ @return {Boolean}
720
+ */
721
+ isSuccess(status: number, _headers: Record<string, unknown>, _payload: Payload): boolean;
722
+ /**
723
+ Default `handleResponse` implementation uses this hook to decide if the
724
+ response is an invalid error.
725
+
726
+ @since 1.13.0
727
+ @public
728
+ @param {Number} status
729
+ @param {Object} headers
730
+ @param {Object} payload
731
+ @return {Boolean}
732
+ */
733
+ isInvalid(status: number, _headers: Record<string, unknown>, _payload: Payload): boolean;
734
+ /**
735
+ Takes a URL, an HTTP method and a hash of data, and makes an
736
+ HTTP request.
737
+
738
+ When the server responds with a payload, Ember Data will call into `extractSingle`
739
+ or `extractArray` (depending on whether the original query was for one record or
740
+ many records).
741
+
742
+ By default, `ajax` method has the following behavior:
743
+
744
+ * It sets the response `dataType` to `"json"`
745
+ * If the HTTP method is not `"GET"`, it sets the `Content-Type` to be
746
+ `application/json; charset=utf-8`
747
+ * If the HTTP method is not `"GET"`, it stringifies the data passed in. The
748
+ data is the serialized record in the case of a save.
749
+ * Registers success and failure handlers.
750
+
751
+ @private
752
+ @param {String} url
753
+ @param {String} type The request type GET, POST, PUT, DELETE etc.
754
+ @param {Object} options
755
+ @return {Promise} promise
756
+ */
757
+ ajax(url: string, type: HTTPMethod, options?: JQueryAjaxSettings | RequestInit): Promise<AdapterPayload>;
758
+ /**
759
+ @private
760
+ @param {Object} options jQuery ajax options to be used for the ajax request
761
+ */
762
+ _ajaxRequest(options: JQueryRequestInit): void;
763
+ _fetchRequest(options: FetchRequestInit): Promise<Response>;
764
+ _ajax(options: FetchRequestInit | JQueryRequestInit): void;
765
+ /**
766
+ @private
767
+ @param {String} url
768
+ @param {String} type The request type GET, POST, PUT, DELETE etc.
769
+ @param {Object} options
770
+ @return {Object}
771
+ */
772
+ ajaxOptions(url: string, method: HTTPMethod, options: JQueryAjaxSettings | RequestInit): JQueryRequestInit | FetchRequestInit;
773
+ _ajaxURL(url: string): string;
774
+ /**
775
+ @private
776
+ @param {String} responseText
777
+ @return {Object}
778
+ */
779
+ parseErrorResponse(responseText: string): Record<string, unknown> | string;
780
+ /**
781
+ @private
782
+ @param {Number} status
783
+ @param {Object} headers
784
+ @param {Object} payload
785
+ @return {Array} errors payload
786
+ */
787
+ normalizeErrorResponse(status: number, _headers: Record<string, unknown>, payload: Payload): Record<string, unknown>[];
788
+ /**
789
+ Generates a detailed ("friendly") error message, with plenty
790
+ of information for debugging (good luck!)
791
+
792
+ @private
793
+ @param {Number} status
794
+ @param {Object} headers
795
+ @param {Object} payload
796
+ @param {Object} requestData
797
+ @return {String} detailed error message
798
+ */
799
+ generatedDetailedMessage(status: number, headers: Record<string, string>, payload: Payload, requestData: RequestData): string;
800
+ /**
801
+ Used by `findAll` and `findRecord` to build the query's `data` hash
802
+ supplied to the ajax method.
803
+
804
+ @since 2.5.0
805
+ @public
806
+ @param {Snapshot} snapshot
807
+ @return {Object}
808
+ */
809
+ buildQuery(snapshot: Snapshot | SnapshotRecordArray): QueryState;
810
+ }
811
+ interface RESTAdapter extends MixtBuildURLMixin {
812
+ }
813
+ /**
814
+ * Helper function that translates the options passed to `jQuery.ajax` into a format that `fetch` expects.
815
+ *
816
+ * @param {Object} _options
817
+ * @param {Adapter} adapter
818
+ * @private
819
+ * @return {Object}
820
+ */
821
+ export declare function fetchOptions(options: JQueryRequestInit & Partial<FetchRequestInit>, adapter: RESTAdapter): FetchRequestInit;
822
+ export { RESTAdapter };
823
+ //# sourceMappingURL=rest.d.ts.map