@warp-drive/legacy 5.8.0-alpha.4 → 5.8.0-alpha.40

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 (213) hide show
  1. package/README.md +14 -27
  2. package/declarations/adapter/error.d.ts +5 -5
  3. package/declarations/adapter/json-api.d.ts +6 -8
  4. package/declarations/adapter/rest.d.ts +5 -8
  5. package/declarations/adapter.d.ts +4 -6
  6. package/declarations/compat/-private.d.ts +1 -1
  7. package/declarations/compat/builders/find-all.d.ts +6 -6
  8. package/declarations/compat/builders/find-record.d.ts +8 -8
  9. package/declarations/compat/builders/query.d.ts +12 -12
  10. package/declarations/compat/extensions.d.ts +1 -1
  11. package/declarations/compat/legacy-network-handler/minimum-adapter-interface.d.ts +7 -9
  12. package/declarations/compat/legacy-network-handler/minimum-serializer-interface.d.ts +20 -30
  13. package/declarations/compat/utils.d.ts +17 -17
  14. package/declarations/compat.d.ts +35 -11
  15. package/declarations/index.d.ts +70 -0
  16. package/declarations/model/-private/attr.d.ts +5 -6
  17. package/declarations/model/-private/belongs-to.d.ts +4 -5
  18. package/declarations/model/-private/has-many.d.ts +4 -5
  19. package/declarations/model/-private/hooks.d.ts +1 -1
  20. package/declarations/model/-private/legacy-relationships-support.d.ts +2 -2
  21. package/declarations/model/-private/model.d.ts +8 -8
  22. package/declarations/model/-private/record-state.d.ts +1 -1
  23. package/declarations/model/-private/references/belongs-to.d.ts +5 -5
  24. package/declarations/model/-private/references/has-many.d.ts +3 -3
  25. package/declarations/model/migration-support.d.ts +46 -21
  26. package/declarations/model-fragments/extensions/fragment-array.d.ts +16 -0
  27. package/declarations/model-fragments/extensions/fragment.d.ts +15 -0
  28. package/declarations/model-fragments/hooks/model-for.d.ts +20 -0
  29. package/declarations/model-fragments/index.d.ts +5 -0
  30. package/declarations/model-fragments/instance-initializers/fragment-extensions.d.ts +9 -0
  31. package/declarations/model-fragments/utilities/with-array-defaults.d.ts +15 -0
  32. package/declarations/model-fragments/utilities/with-fragment-array-defaults.d.ts +20 -0
  33. package/declarations/model-fragments/utilities/with-fragment-defaults.d.ts +19 -0
  34. package/declarations/model-fragments/utilities/with-legacy.d.ts +3 -0
  35. package/declarations/model-fragments.d.ts +9 -0
  36. package/declarations/model.d.ts +2 -2
  37. package/declarations/serializer/-private/embedded-records-mixin.d.ts +1 -6
  38. package/declarations/serializer/-private/transforms/boolean.d.ts +2 -2
  39. package/declarations/serializer/-private/transforms/date.d.ts +2 -2
  40. package/declarations/serializer/-private/transforms/number.d.ts +1 -1
  41. package/declarations/serializer/-private/transforms/string.d.ts +1 -1
  42. package/declarations/serializer/json-api.d.ts +7 -9
  43. package/declarations/serializer/json.d.ts +7 -9
  44. package/declarations/serializer/rest.d.ts +4 -6
  45. package/declarations/serializer.d.ts +9 -12
  46. package/dist/{-private-8UmnAf9J.js → -private-B1pSSN52.js} +1 -1
  47. package/dist/adapter/-private.js +1 -1
  48. package/dist/adapter/error.js +12 -13
  49. package/dist/adapter/json-api.js +4 -1
  50. package/dist/adapter/rest.js +6 -9
  51. package/dist/adapter.js +4 -6
  52. package/dist/compat/-private.js +1 -1
  53. package/dist/compat/builders.js +26 -26
  54. package/dist/compat/utils.js +17 -18
  55. package/dist/compat.js +58 -41
  56. package/dist/{errors-8kD2mSe_.js → errors-CIGPcDvd.js} +87 -65
  57. package/dist/hooks-QqRnX108.js +74 -0
  58. package/dist/index.js +195 -0
  59. package/dist/{json-DziiodPf.js → json-BNrV8EYG.js} +12 -16
  60. package/dist/model/-private.js +1 -1
  61. package/dist/model/migration-support.js +54 -24
  62. package/dist/model-for-CqXsIKws.js +221 -0
  63. package/dist/model-fragments.js +76 -0
  64. package/dist/model.js +18 -90
  65. package/dist/{schema-provider-DQu4Rjco.js → schema-provider-g5MfTj8n.js} +18 -20
  66. package/dist/{serialize-into-hash-CS0MIv4F.js → serialize-into-hash-BnYvPex3.js} +1 -1
  67. package/dist/serializer/json-api.js +17 -44
  68. package/dist/serializer/json.js +1 -1
  69. package/dist/serializer/rest.js +14 -21
  70. package/dist/serializer/transform.js +15 -6
  71. package/dist/serializer.js +9 -13
  72. package/dist/store.js +3 -0
  73. package/dist/unpkg/dev/-private-DbaSCSym.js +1205 -0
  74. package/dist/unpkg/dev/adapter/-private.js +1 -0
  75. package/dist/unpkg/dev/adapter/error.js +335 -0
  76. package/dist/unpkg/dev/adapter/json-api.js +271 -0
  77. package/dist/unpkg/dev/adapter/rest.js +1255 -0
  78. package/dist/unpkg/dev/adapter.js +1252 -0
  79. package/dist/unpkg/dev/compat/-private.js +1 -0
  80. package/dist/unpkg/dev/compat/builders.js +275 -0
  81. package/dist/unpkg/dev/compat/extensions.js +242 -0
  82. package/dist/unpkg/dev/compat/utils.js +223 -0
  83. package/dist/unpkg/dev/compat.js +1146 -0
  84. package/dist/unpkg/dev/errors-DD96TBEs.js +2591 -0
  85. package/dist/unpkg/dev/hooks-CqWjNWeL.js +73 -0
  86. package/dist/unpkg/dev/index.js +197 -0
  87. package/dist/unpkg/dev/json-CCU-ZQ4b.js +1269 -0
  88. package/dist/unpkg/dev/model/-private.js +1 -0
  89. package/dist/unpkg/dev/model/migration-support.js +551 -0
  90. package/dist/unpkg/dev/model-for-CqXsIKws.js +221 -0
  91. package/dist/unpkg/dev/model-fragments.js +76 -0
  92. package/dist/unpkg/dev/model.js +678 -0
  93. package/dist/unpkg/dev/runtime-BPCpkOf1-BKOwiRJp.js +65 -0
  94. package/dist/unpkg/dev/schema-provider-B8jiJOYC.js +2229 -0
  95. package/dist/unpkg/dev/serialize-into-hash-CPAZXrQU.js +259 -0
  96. package/dist/unpkg/dev/serializer/json-api.js +648 -0
  97. package/dist/unpkg/dev/serializer/json.js +4 -0
  98. package/dist/unpkg/dev/serializer/rest.js +1242 -0
  99. package/dist/unpkg/dev/serializer/transform.js +278 -0
  100. package/dist/unpkg/dev/serializer.js +248 -0
  101. package/dist/unpkg/dev/store.js +636 -0
  102. package/dist/unpkg/dev/util-DvanW33H.js +20 -0
  103. package/dist/unpkg/dev/utils-BhvS1iTS.js +8 -0
  104. package/dist/unpkg/dev-deprecated/-private-DbaSCSym.js +1205 -0
  105. package/dist/unpkg/dev-deprecated/adapter/-private.js +1 -0
  106. package/dist/unpkg/dev-deprecated/adapter/error.js +335 -0
  107. package/dist/unpkg/dev-deprecated/adapter/json-api.js +271 -0
  108. package/dist/unpkg/dev-deprecated/adapter/rest.js +1255 -0
  109. package/dist/unpkg/dev-deprecated/adapter.js +1252 -0
  110. package/dist/unpkg/dev-deprecated/compat/-private.js +1 -0
  111. package/dist/unpkg/dev-deprecated/compat/builders.js +275 -0
  112. package/dist/unpkg/dev-deprecated/compat/extensions.js +242 -0
  113. package/dist/unpkg/dev-deprecated/compat/utils.js +223 -0
  114. package/dist/unpkg/dev-deprecated/compat.js +1146 -0
  115. package/dist/unpkg/dev-deprecated/errors-DEnabIZj.js +2594 -0
  116. package/dist/unpkg/dev-deprecated/hooks-CAll-Ets.js +73 -0
  117. package/dist/unpkg/dev-deprecated/index.js +196 -0
  118. package/dist/unpkg/dev-deprecated/json-CCU-ZQ4b.js +1269 -0
  119. package/dist/unpkg/dev-deprecated/model/-private.js +1 -0
  120. package/dist/unpkg/dev-deprecated/model/migration-support.js +568 -0
  121. package/dist/unpkg/dev-deprecated/model-for-CqXsIKws.js +221 -0
  122. package/dist/unpkg/dev-deprecated/model-fragments.js +76 -0
  123. package/dist/unpkg/dev-deprecated/model.js +682 -0
  124. package/dist/unpkg/dev-deprecated/runtime-BPCpkOf1-BKOwiRJp.js +65 -0
  125. package/dist/unpkg/dev-deprecated/schema-provider-k2qXQTBg.js +2254 -0
  126. package/dist/unpkg/dev-deprecated/serialize-into-hash-CPAZXrQU.js +259 -0
  127. package/dist/unpkg/dev-deprecated/serializer/json-api.js +648 -0
  128. package/dist/unpkg/dev-deprecated/serializer/json.js +4 -0
  129. package/dist/unpkg/dev-deprecated/serializer/rest.js +1242 -0
  130. package/dist/unpkg/dev-deprecated/serializer/transform.js +278 -0
  131. package/dist/unpkg/dev-deprecated/serializer.js +248 -0
  132. package/dist/unpkg/dev-deprecated/store.js +636 -0
  133. package/dist/unpkg/dev-deprecated/util-CWr5WQOT.js +24 -0
  134. package/dist/unpkg/dev-deprecated/utils-C9PJehtL.js +12 -0
  135. package/dist/unpkg/prod/-private-Cvf_97EG.js +970 -0
  136. package/dist/unpkg/prod/adapter/-private.js +1 -0
  137. package/dist/unpkg/prod/adapter/error.js +330 -0
  138. package/dist/unpkg/prod/adapter/json-api.js +266 -0
  139. package/dist/unpkg/prod/adapter/rest.js +1218 -0
  140. package/dist/unpkg/prod/adapter.js +1219 -0
  141. package/dist/unpkg/prod/compat/-private.js +1 -0
  142. package/dist/unpkg/prod/compat/builders.js +210 -0
  143. package/dist/unpkg/prod/compat/extensions.js +232 -0
  144. package/dist/unpkg/prod/compat/utils.js +218 -0
  145. package/dist/unpkg/prod/compat.js +726 -0
  146. package/dist/unpkg/prod/errors-CXnfnBfQ.js +2343 -0
  147. package/dist/unpkg/prod/hooks-DvyWhLNg.js +41 -0
  148. package/dist/unpkg/prod/index.js +151 -0
  149. package/dist/unpkg/prod/json-BYrUP8ao.js +1256 -0
  150. package/dist/unpkg/prod/model/-private.js +1 -0
  151. package/dist/unpkg/prod/model/migration-support.js +544 -0
  152. package/dist/unpkg/prod/model-for-CqXsIKws.js +221 -0
  153. package/dist/unpkg/prod/model-fragments.js +76 -0
  154. package/dist/unpkg/prod/model.js +593 -0
  155. package/dist/unpkg/prod/runtime-BPCpkOf1-BKOwiRJp.js +65 -0
  156. package/dist/unpkg/prod/schema-provider-CHujJvA9.js +1904 -0
  157. package/dist/unpkg/prod/serialize-into-hash-DYU2egXl.js +215 -0
  158. package/dist/unpkg/prod/serializer/json-api.js +591 -0
  159. package/dist/unpkg/prod/serializer/json.js +4 -0
  160. package/dist/unpkg/prod/serializer/rest.js +1210 -0
  161. package/dist/unpkg/prod/serializer/transform.js +278 -0
  162. package/dist/unpkg/prod/serializer.js +248 -0
  163. package/dist/unpkg/prod/store.js +504 -0
  164. package/dist/unpkg/prod/util-DvanW33H.js +20 -0
  165. package/dist/unpkg/prod/utils-BhvS1iTS.js +8 -0
  166. package/dist/unpkg/prod-deprecated/-private-Cvf_97EG.js +970 -0
  167. package/dist/unpkg/prod-deprecated/adapter/-private.js +1 -0
  168. package/dist/unpkg/prod-deprecated/adapter/error.js +330 -0
  169. package/dist/unpkg/prod-deprecated/adapter/json-api.js +266 -0
  170. package/dist/unpkg/prod-deprecated/adapter/rest.js +1218 -0
  171. package/dist/unpkg/prod-deprecated/adapter.js +1219 -0
  172. package/dist/unpkg/prod-deprecated/compat/-private.js +1 -0
  173. package/dist/unpkg/prod-deprecated/compat/builders.js +210 -0
  174. package/dist/unpkg/prod-deprecated/compat/extensions.js +232 -0
  175. package/dist/unpkg/prod-deprecated/compat/utils.js +218 -0
  176. package/dist/unpkg/prod-deprecated/compat.js +726 -0
  177. package/dist/unpkg/prod-deprecated/errors-CG1SPYVg.js +2346 -0
  178. package/dist/unpkg/prod-deprecated/hooks-BIUBiNGR.js +41 -0
  179. package/dist/unpkg/prod-deprecated/index.js +150 -0
  180. package/dist/unpkg/prod-deprecated/json-BYrUP8ao.js +1256 -0
  181. package/dist/unpkg/prod-deprecated/model/-private.js +1 -0
  182. package/dist/unpkg/prod-deprecated/model/migration-support.js +561 -0
  183. package/dist/unpkg/prod-deprecated/model-for-CqXsIKws.js +221 -0
  184. package/dist/unpkg/prod-deprecated/model-fragments.js +76 -0
  185. package/dist/unpkg/prod-deprecated/model.js +596 -0
  186. package/dist/unpkg/prod-deprecated/runtime-BPCpkOf1-BKOwiRJp.js +65 -0
  187. package/dist/unpkg/prod-deprecated/schema-provider-BJ4TWnZf.js +1947 -0
  188. package/dist/unpkg/prod-deprecated/serialize-into-hash-DYU2egXl.js +215 -0
  189. package/dist/unpkg/prod-deprecated/serializer/json-api.js +591 -0
  190. package/dist/unpkg/prod-deprecated/serializer/json.js +4 -0
  191. package/dist/unpkg/prod-deprecated/serializer/rest.js +1210 -0
  192. package/dist/unpkg/prod-deprecated/serializer/transform.js +278 -0
  193. package/dist/unpkg/prod-deprecated/serializer.js +248 -0
  194. package/dist/unpkg/prod-deprecated/store.js +504 -0
  195. package/dist/unpkg/prod-deprecated/util-B6cn-i93.js +23 -0
  196. package/dist/unpkg/prod-deprecated/utils-BUWwQwCh.js +11 -0
  197. package/logos/README.md +2 -2
  198. package/logos/logo-yellow-slab.svg +1 -0
  199. package/logos/word-mark-black.svg +1 -0
  200. package/logos/word-mark-white.svg +1 -0
  201. package/package.json +14 -6
  202. package/logos/NCC-1701-a-blue.svg +0 -4
  203. package/logos/NCC-1701-a-gold.svg +0 -4
  204. package/logos/NCC-1701-a-gold_100.svg +0 -1
  205. package/logos/NCC-1701-a-gold_base-64.txt +0 -1
  206. package/logos/NCC-1701-a.svg +0 -4
  207. package/logos/docs-badge.svg +0 -2
  208. package/logos/ember-data-logo-dark.svg +0 -12
  209. package/logos/ember-data-logo-light.svg +0 -12
  210. package/logos/social1.png +0 -0
  211. package/logos/social2.png +0 -0
  212. package/logos/warp-drive-logo-dark.svg +0 -4
  213. package/logos/warp-drive-logo-gold.svg +0 -4
@@ -0,0 +1 @@
1
+ export { d as determineBodyPromise, g as fetch, p as parseResponseHeaders, b as serializeIntoHash, s as serializeQueryParams, a as setupFastboot } from "../serialize-into-hash-DYU2egXl.js";
@@ -0,0 +1,330 @@
1
+ import { getOrSetGlobal } from '@warp-drive/core/types/-private';
2
+
3
+ /* eslint-disable @typescript-eslint/no-unsafe-assignment */
4
+ /* eslint-disable @typescript-eslint/no-unsafe-member-access */
5
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
6
+
7
+ /**
8
+ ## Overview
9
+
10
+ :::danger
11
+ ⚠️ **This is LEGACY documentation** for a feature that is no longer encouraged to be used.
12
+ If starting a new app or thinking of implementing a new adapter, consider writing a
13
+ {@link Handler} instead to be used with the {@link RequestManager}
14
+ :::
15
+
16
+ An `AdapterError` is used by an adapter to signal that an error occurred
17
+ during a request to an external API. It indicates a generic error, and
18
+ subclasses are used to indicate specific error states.
19
+
20
+ To create a custom error to signal a specific error state in communicating
21
+ with an external API, extend the `AdapterError`. For example, if the
22
+ external API exclusively used HTTP `503 Service Unavailable` to indicate
23
+ it was closed for maintenance:
24
+
25
+ ```js [app/adapters/maintenance-error.js]
26
+ import AdapterError from '@warp-drive/legacy/adapter/error';
27
+
28
+ export default AdapterError.extend({ message: "Down for maintenance." });
29
+ ```
30
+
31
+ This error would then be returned by an adapter's `handleResponse` method:
32
+
33
+ ```js [app/adapters/application.js]
34
+ import JSONAPIAdapter from '@warp-drive/legacy/adapter/json-api';
35
+ import MaintenanceError from './maintenance-error';
36
+
37
+ export default class ApplicationAdapter extends JSONAPIAdapter {
38
+ handleResponse(status) {
39
+ if (503 === status) {
40
+ return new MaintenanceError();
41
+ }
42
+
43
+ return super.handleResponse(...arguments);
44
+ }
45
+ }
46
+ ```
47
+
48
+ And can then be detected in an application and used to send the user to an
49
+ `under-maintenance` route:
50
+
51
+ ```js [app/routes/application.js]
52
+ import MaintenanceError from '../adapters/maintenance-error';
53
+
54
+ export default class ApplicationRoute extends Route {
55
+ actions: {
56
+ error(error, transition) {
57
+ if (error instanceof MaintenanceError) {
58
+ this.transitionTo('under-maintenance');
59
+ return;
60
+ }
61
+
62
+ // ...other error handling logic
63
+ }
64
+ }
65
+ }
66
+ ```
67
+
68
+ @class AdapterError
69
+ @public
70
+ */
71
+ function _AdapterError(errors, message = 'Adapter operation failed') {
72
+ this.isAdapterError = true;
73
+ const error = Error.call(this, message);
74
+ if (error) {
75
+ this.stack = error.stack;
76
+ // @ts-expect-error untyped
77
+ this.description = error.description;
78
+ // @ts-expect-error untyped
79
+ this.fileName = error.fileName;
80
+ // @ts-expect-error untyped
81
+ this.lineNumber = error.lineNumber;
82
+ this.message = error.message;
83
+ this.name = error.name;
84
+ // @ts-expect-error untyped
85
+ this.number = error.number;
86
+ }
87
+ this.errors = errors || [{
88
+ title: 'Adapter Error',
89
+ detail: message
90
+ }];
91
+ }
92
+ _AdapterError.prototype = Object.create(Error.prototype);
93
+ _AdapterError.prototype.code = 'AdapterError';
94
+ _AdapterError.extend = extendFn(_AdapterError);
95
+ const AdapterError = getOrSetGlobal('AdapterError', _AdapterError);
96
+ function extendFn(ErrorClass) {
97
+ return function ({
98
+ message: defaultMessage
99
+ } = {}) {
100
+ return extend(ErrorClass, defaultMessage);
101
+ };
102
+ }
103
+ function extend(ParentErrorClass, defaultMessage) {
104
+ const ErrorClass = function (errors, message) {
105
+ ParentErrorClass.call(this, errors, message || defaultMessage);
106
+ };
107
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
108
+ ErrorClass.prototype = Object.create(ParentErrorClass.prototype);
109
+ ErrorClass.extend = extendFn(ErrorClass);
110
+ return ErrorClass;
111
+ }
112
+
113
+ /**
114
+ A `InvalidError` is used by an adapter to signal the external API
115
+ was unable to process a request because the content was not
116
+ semantically correct or meaningful per the API. Usually, this means a
117
+ record failed some form of server-side validation. When a promise
118
+ from an adapter is rejected with a `InvalidError` the record will
119
+ transition to the `invalid` state and the errors will be set to the
120
+ `errors` property on the record.
121
+
122
+ For Ember Data to correctly map errors to their corresponding
123
+ properties on the model, Ember Data expects each error to be
124
+ a valid JSON-API error object with a `source/pointer` that matches
125
+ the property name. For example, if you had a Post model that
126
+ looked like this.
127
+
128
+ ```js [app/models/post.js]
129
+ import { Model, attr } from '@warp-drive/legacy/model';
130
+
131
+ export default class PostModel extends Model {
132
+ @attr('string') title;
133
+ @attr('string') content;
134
+ }
135
+ ```
136
+
137
+ To show an error from the server related to the `title` and
138
+ `content` properties your adapter could return a promise that
139
+ rejects with a `InvalidError` object that looks like this:
140
+
141
+ ```js [app/adapters/post.js]
142
+ import RSVP from 'RSVP';
143
+ import RESTAdapter from '@warp-drive/legacy/adapter/rest';
144
+ import { InvalidError } from '@warp-drive/legacy/adapter/error';
145
+
146
+ export default class ApplicationAdapter extends RESTAdapter {
147
+ updateRecord() {
148
+ // Fictional adapter that always rejects
149
+ return RSVP.reject(new InvalidError([
150
+ {
151
+ detail: 'Must be unique',
152
+ source: { pointer: '/data/attributes/title' }
153
+ },
154
+ {
155
+ detail: 'Must not be blank',
156
+ source: { pointer: '/data/attributes/content'}
157
+ }
158
+ ]));
159
+ }
160
+ }
161
+ ```
162
+
163
+ Your backend may use different property names for your records the
164
+ store will attempt to extract and normalize the errors using the
165
+ serializer's `extractErrors` method before the errors get added to
166
+ the model. As a result, it is safe for the `InvalidError` to
167
+ wrap the error payload unaltered.
168
+
169
+ @class InvalidError
170
+ @public
171
+ */
172
+ // TODO @deprecate extractError documentation
173
+
174
+ const InvalidError = getOrSetGlobal('InvalidError', extend(AdapterError, 'The adapter rejected the commit because it was invalid'));
175
+ InvalidError.prototype.code = 'InvalidError';
176
+
177
+ /**
178
+ A `TimeoutError` is used by an adapter to signal that a request
179
+ to the external API has timed out. I.e. no response was received from
180
+ the external API within an allowed time period.
181
+
182
+ An example use case would be to warn the user to check their internet
183
+ connection if an adapter operation has timed out:
184
+
185
+ ```js [app/routes/application.js]
186
+ import { TimeoutError } from '@warp-drive/legacy/adapter/error';
187
+
188
+ export default class ApplicationRoute extends Route {
189
+ @action
190
+ error(error, transition) {
191
+ if (error instanceof TimeoutError) {
192
+ // alert the user
193
+ alert('Are you still connected to the Internet?');
194
+ return;
195
+ }
196
+
197
+ // ...other error handling logic
198
+ }
199
+ }
200
+ ```
201
+
202
+ @class TimeoutError
203
+ @public
204
+ */
205
+
206
+ const TimeoutError = getOrSetGlobal('TimeoutError', extend(AdapterError, 'The adapter operation timed out'));
207
+ TimeoutError.prototype.code = 'TimeoutError';
208
+
209
+ /**
210
+ A `AbortError` is used by an adapter to signal that a request to
211
+ the external API was aborted. For example, this can occur if the user
212
+ navigates away from the current page after a request to the external API
213
+ has been initiated but before a response has been received.
214
+
215
+ @class AbortError
216
+ @public
217
+ */
218
+
219
+ const AbortError = getOrSetGlobal('AbortError', extend(AdapterError, 'The adapter operation was aborted'));
220
+ AbortError.prototype.code = 'AbortError';
221
+
222
+ /**
223
+ A `UnauthorizedError` equates to a HTTP `401 Unauthorized` response
224
+ status. It is used by an adapter to signal that a request to the external
225
+ API was rejected because authorization is required and has failed or has not
226
+ yet been provided.
227
+
228
+ An example use case would be to redirect the user to a login route if a
229
+ request is unauthorized:
230
+
231
+ ```js [app/routes/application.js]
232
+ import { UnauthorizedError } from '@warp-drive/legacy/adapter/error';
233
+
234
+ export default class ApplicationRoute extends Route {
235
+ @action
236
+ error(error, transition) {
237
+ if (error instanceof UnauthorizedError) {
238
+ // go to the login route
239
+ this.transitionTo('login');
240
+ return;
241
+ }
242
+
243
+ // ...other error handling logic
244
+ }
245
+ }
246
+ ```
247
+
248
+ @class UnauthorizedError
249
+ @public
250
+ */
251
+
252
+ const UnauthorizedError = getOrSetGlobal('UnauthorizedError', extend(AdapterError, 'The adapter operation is unauthorized'));
253
+ UnauthorizedError.prototype.code = 'UnauthorizedError';
254
+
255
+ /**
256
+ A `ForbiddenError` equates to a HTTP `403 Forbidden` response status.
257
+ It is used by an adapter to signal that a request to the external API was
258
+ valid but the server is refusing to respond to it. If authorization was
259
+ provided and is valid, then the authenticated user does not have the
260
+ necessary permissions for the request.
261
+
262
+ @class ForbiddenError
263
+ @public
264
+ */
265
+
266
+ const ForbiddenError = getOrSetGlobal('ForbiddenError', extend(AdapterError, 'The adapter operation is forbidden'));
267
+ ForbiddenError.prototype.code = 'ForbiddenError';
268
+
269
+ /**
270
+ A `NotFoundError` equates to a HTTP `404 Not Found` response status.
271
+ It is used by an adapter to signal that a request to the external API
272
+ was rejected because the resource could not be found on the API.
273
+
274
+ An example use case would be to detect if the user has entered a route
275
+ for a specific model that does not exist. For example:
276
+
277
+ ```js [app/routes/post.js]
278
+ import { NotFoundError } from '@warp-drive/legacy/adapter/error';
279
+
280
+ export default class PostRoute extends Route {
281
+ @service store;
282
+ model(params) {
283
+ return this.store.findRecord('post', params.post_id);
284
+ }
285
+ @action
286
+ error(error, transition) {
287
+ if (error instanceof NotFoundError) {
288
+ // redirect to a list of all posts instead
289
+ this.transitionTo('posts');
290
+ } else {
291
+ // otherwise let the error bubble
292
+ return true;
293
+ }
294
+ }
295
+ }
296
+ ```
297
+
298
+ @class NotFoundError
299
+ @public
300
+ */
301
+
302
+ const NotFoundError = getOrSetGlobal('NotFoundError', extend(AdapterError, 'The adapter could not find the resource'));
303
+ NotFoundError.prototype.code = 'NotFoundError';
304
+
305
+ /**
306
+ A `ConflictError` equates to a HTTP `409 Conflict` response status.
307
+ It is used by an adapter to indicate that the request could not be processed
308
+ because of a conflict in the request. An example scenario would be when
309
+ creating a record with a client-generated ID but that ID is already known
310
+ to the external API.
311
+
312
+ @class ConflictError
313
+ @public
314
+ */
315
+
316
+ const ConflictError = getOrSetGlobal('ConflictError', extend(AdapterError, 'The adapter operation failed due to a conflict'));
317
+ ConflictError.prototype.code = 'ConflictError';
318
+
319
+ /**
320
+ A `ServerError` equates to a HTTP `500 Internal Server Error` response
321
+ status. It is used by the adapter to indicate that a request has failed
322
+ because of an error in the external API.
323
+
324
+ @class ServerError
325
+ @public
326
+ */
327
+
328
+ const ServerError = getOrSetGlobal('ServerError', extend(AdapterError, 'The adapter operation failed due to a server error'));
329
+ ServerError.prototype.code = 'ServerError';
330
+ export { AbortError, AdapterError, ConflictError, ForbiddenError, InvalidError, NotFoundError, ServerError, TimeoutError, UnauthorizedError };
@@ -0,0 +1,266 @@
1
+ import { dasherize, pluralize } from '@warp-drive/utilities/string';
2
+ import { b as serializeIntoHash } from "../serialize-into-hash-DYU2egXl.js";
3
+ import { RESTAdapter } from './rest.js';
4
+
5
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
6
+
7
+ /**
8
+ ## Overview
9
+
10
+ :::danger
11
+ ⚠️ **This is LEGACY documentation** for a feature that is no longer encouraged to be used.
12
+ If starting a new app or thinking of implementing a new adapter, consider writing a
13
+ {@link Handler} instead to be used with the {@link RequestManager}
14
+ :::
15
+
16
+ The `JSONAPIAdapter` is an adapter whichtransforms the store's
17
+ requests into HTTP requests that follow the [JSON API format](http://jsonapi.org/format/).
18
+
19
+ ## JSON API Conventions
20
+
21
+ The JSONAPIAdapter uses JSON API conventions for building the URL
22
+ for a record and selecting the HTTP verb to use with a request. The
23
+ actions you can take on a record map onto the following URLs in the
24
+ JSON API adapter:
25
+
26
+ <table>
27
+ <tr>
28
+ <th>
29
+ Action
30
+ </th>
31
+ <th>
32
+ HTTP Verb
33
+ </th>
34
+ <th>
35
+ URL
36
+ </th>
37
+ </tr>
38
+ <tr>
39
+ <th>
40
+ `store.findRecord('post', 123)`
41
+ </th>
42
+ <td>
43
+ GET
44
+ </td>
45
+ <td>
46
+ /posts/123
47
+ </td>
48
+ </tr>
49
+ <tr>
50
+ <th>
51
+ `store.findAll('post')`
52
+ </th>
53
+ <td>
54
+ GET
55
+ </td>
56
+ <td>
57
+ /posts
58
+ </td>
59
+ </tr>
60
+ <tr>
61
+ <th>
62
+ Update `postRecord.save()`
63
+ </th>
64
+ <td>
65
+ PATCH
66
+ </td>
67
+ <td>
68
+ /posts/123
69
+ </td>
70
+ </tr>
71
+ <tr>
72
+ <th>
73
+ Create `store.createRecord('post').save()`
74
+ </th>
75
+ <td>
76
+ POST
77
+ </td>
78
+ <td>
79
+ /posts
80
+ </td>
81
+ </tr>
82
+ <tr>
83
+ <th>
84
+ Delete `postRecord.destroyRecord()`
85
+ </th>
86
+ <td>
87
+ DELETE
88
+ </td>
89
+ <td>
90
+ /posts/123
91
+ </td>
92
+ </tr>
93
+ </table>
94
+
95
+ ## Success and failure
96
+
97
+ The JSONAPIAdapter will consider a success any response with a
98
+ status code of the 2xx family ("Success"), as well as 304 ("Not
99
+ Modified"). Any other status code will be considered a failure.
100
+
101
+ On success, the request promise will be resolved with the full
102
+ response payload.
103
+
104
+ Failed responses with status code 422 ("Unprocessable Entity") will
105
+ be considered "invalid". The response will be discarded, except for
106
+ the `errors` key. The request promise will be rejected with a
107
+ `InvalidError`. This error object will encapsulate the saved
108
+ `errors` value.
109
+
110
+ Any other status codes will be treated as an adapter error. The
111
+ request promise will be rejected, similarly to the invalid case,
112
+ but with an instance of `AdapterError` instead.
113
+
114
+ ### Endpoint path customization
115
+
116
+ Endpoint paths can be prefixed with a `namespace` by setting the
117
+ namespace property on the adapter:
118
+
119
+ ```js [app/adapters/application.js]
120
+ import JSONAPIAdapter from '@warp-drive/legacy/adapter/json-api';
121
+
122
+ export default class ApplicationAdapter extends JSONAPIAdapter {
123
+ namespace = 'api/1';
124
+ }
125
+ ```
126
+ Requests for the `person` model would now target `/api/1/people/1`.
127
+
128
+ ### Host customization
129
+
130
+ An adapter can target other hosts by setting the `host` property.
131
+
132
+ ```js [app/adapters/application.js]
133
+ import JSONAPIAdapter from '@warp-drive/legacy/adapter/json-api';
134
+
135
+ export default class ApplicationAdapter extends JSONAPIAdapter {
136
+ host = 'https://api.example.com';
137
+ }
138
+ ```
139
+
140
+ Requests for the `person` model would now target
141
+ `https://api.example.com/people/1`.
142
+
143
+ @since 1.13.0
144
+ @class JSONAPIAdapter
145
+ @public
146
+ @constructor
147
+ */
148
+ class JSONAPIAdapter extends RESTAdapter {
149
+ _defaultContentType = 'application/vnd.api+json';
150
+
151
+ /**
152
+ @private
153
+ @param {String} url
154
+ @param {String} type The request type GET, POST, PUT, DELETE etc.
155
+ @param {Object} options
156
+ @return {Object}
157
+ */
158
+ ajaxOptions(url, type, options = {}) {
159
+ const hash = super.ajaxOptions(url, type, options);
160
+ const headers = hash.headers = hash.headers || {};
161
+ headers['Accept'] = headers['Accept'] || 'application/vnd.api+json';
162
+ return hash;
163
+ }
164
+
165
+ /**
166
+ By default the JSONAPIAdapter will send each find request coming from a `store.find`
167
+ or from accessing a relationship separately to the server. If your server supports passing
168
+ ids as a query string, you can set coalesceFindRequests to true to coalesce all find requests
169
+ within a single runloop.
170
+ For example, if you have an initial payload of:
171
+ ```javascript
172
+ {
173
+ data: {
174
+ id: 1,
175
+ type: 'post',
176
+ relationship: {
177
+ comments: {
178
+ data: [
179
+ { id: 1, type: 'comment' },
180
+ { id: 2, type: 'comment' }
181
+ ]
182
+ }
183
+ }
184
+ }
185
+ }
186
+ ```
187
+ By default calling `post.comments` will trigger the following requests(assuming the
188
+ comments haven't been loaded before):
189
+ ```
190
+ GET /comments/1
191
+ GET /comments/2
192
+ ```
193
+ If you set coalesceFindRequests to `true` it will instead trigger the following request:
194
+ ```
195
+ GET /comments?filter[id]=1,2
196
+ ```
197
+ Setting coalesceFindRequests to `true` also works for `store.find` requests and `belongsTo`
198
+ relationships accessed within the same runloop. If you set `coalesceFindRequests: true`
199
+ ```javascript
200
+ store.findRecord('comment', 1);
201
+ store.findRecord('comment', 2);
202
+ ```
203
+ will also send a request to: `GET /comments?filter[id]=1,2`
204
+ Note: Requests coalescing rely on URL building strategy. So if you override `buildURL` in your app
205
+ `groupRecordsForFindMany` more likely should be overridden as well in order for coalescing to work.
206
+ @property coalesceFindRequests
207
+ @public
208
+ @type {Boolean}
209
+ */
210
+ get coalesceFindRequests() {
211
+ const coalesceFindRequests = this._coalesceFindRequests;
212
+ if (typeof coalesceFindRequests === 'boolean') {
213
+ return coalesceFindRequests;
214
+ }
215
+ return this._coalesceFindRequests = false;
216
+ }
217
+ set coalesceFindRequests(value) {
218
+ this._coalesceFindRequests = value;
219
+ }
220
+ findMany(store, type, ids, snapshots) {
221
+ const url = this.buildURL(type.modelName, ids, snapshots, 'findMany');
222
+ return this.ajax(url, 'GET', {
223
+ data: {
224
+ filter: {
225
+ id: ids.join(',')
226
+ }
227
+ }
228
+ });
229
+ }
230
+ pathForType(modelName) {
231
+ const dasherized = dasherize(modelName);
232
+ return pluralize(dasherized);
233
+ }
234
+ updateRecord(store, schema, snapshot) {
235
+ const data = serializeIntoHash(store, schema, snapshot);
236
+ const type = snapshot.modelName;
237
+ const id = snapshot.id;
238
+ const url = this.buildURL(type, id, snapshot, 'updateRecord');
239
+ return this.ajax(url, 'PATCH', {
240
+ data: data
241
+ });
242
+ }
243
+
244
+ /**
245
+ Used by `findAll` and `findRecord` to build the query's `data` hash
246
+ supplied to the ajax method.
247
+ @since 2.5.0
248
+ @public
249
+ @param {Snapshot} snapshot
250
+ @return {Object}
251
+ */
252
+ buildQuery(snapshot) {
253
+ const query = {};
254
+ if (snapshot) {
255
+ const {
256
+ include
257
+ } = snapshot;
258
+ const normalizedInclude = Array.isArray(include) ? include.join(',') : include;
259
+ if (normalizedInclude) {
260
+ query.include = normalizedInclude;
261
+ }
262
+ }
263
+ return query;
264
+ }
265
+ }
266
+ export { JSONAPIAdapter };