@warp-drive/legacy 5.9.0-alpha.2 → 5.9.0-alpha.21

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 (162) hide show
  1. package/README.md +6 -0
  2. package/declarations/adapter/-private/build-url-mixin.d.ts +156 -0
  3. package/declarations/adapter/error.d.ts +385 -169
  4. package/declarations/adapter/json-api.d.ts +12 -1
  5. package/declarations/adapter/rest.d.ts +74 -0
  6. package/declarations/adapter.d.ts +6 -0
  7. package/declarations/compat/builders/find-all.d.ts +0 -1
  8. package/declarations/compat/extensions.d.ts +40 -0
  9. package/declarations/compat/legacy-network-handler/legacy-network-handler.d.ts +7 -0
  10. package/declarations/compat/legacy-network-handler/minimum-adapter-interface.d.ts +4 -0
  11. package/declarations/compat/legacy-network-handler/minimum-serializer-interface.d.ts +7 -0
  12. package/declarations/compat/utils.d.ts +11 -0
  13. package/declarations/compat.d.ts +32 -0
  14. package/declarations/index.d.ts +142 -0
  15. package/declarations/model/-private/attr.d.ts +21 -0
  16. package/declarations/model/-private/belongs-to.d.ts +21 -0
  17. package/declarations/model/-private/hooks.d.ts +26 -0
  18. package/declarations/model/-private/model.d.ts +55 -4
  19. package/declarations/model/-private/promise-many-array.d.ts +25 -1
  20. package/declarations/model/-private/schema-provider.d.ts +11 -1
  21. package/declarations/model/migration-support.d.ts +31 -5
  22. package/declarations/model-fragments/extensions/fragment-array.d.ts +38 -0
  23. package/declarations/model-fragments/extensions/fragment.d.ts +35 -0
  24. package/declarations/model-fragments/hooks/model-for.d.ts +7 -0
  25. package/declarations/model-fragments/index.d.ts +8 -0
  26. package/declarations/model-fragments/instance-initializers/fragment-extensions.d.ts +6 -0
  27. package/declarations/model-fragments/utilities/with-array-defaults.d.ts +30 -0
  28. package/declarations/model-fragments/utilities/with-fragment-array-defaults.d.ts +18 -0
  29. package/declarations/model-fragments/utilities/with-fragment-defaults.d.ts +15 -0
  30. package/declarations/model-fragments/utilities/with-legacy.d.ts +8 -0
  31. package/declarations/serializer/-private/transforms/boolean.d.ts +13 -0
  32. package/declarations/serializer/-private/transforms/date.d.ts +15 -1
  33. package/declarations/serializer/-private/transforms/number.d.ts +14 -1
  34. package/declarations/serializer/-private/transforms/string.d.ts +14 -1
  35. package/declarations/serializer/-private/utils.d.ts +24 -0
  36. package/declarations/serializer/json-api.d.ts +1 -1
  37. package/declarations/serializer.d.ts +4 -6
  38. package/declarations/store/-private.d.ts +2 -2
  39. package/declarations/store.d.ts +7 -0
  40. package/dist/adapter/error.js +386 -241
  41. package/dist/adapter/json-api.js +12 -0
  42. package/dist/adapter/rest.js +39 -3
  43. package/dist/adapter.js +23 -26
  44. package/dist/compat/builders.js +0 -1
  45. package/dist/compat/extensions.js +80 -3
  46. package/dist/compat/utils.js +14 -0
  47. package/dist/compat.js +17 -0
  48. package/dist/{errors-Cz5KrzBk.js → errors-DZKA206g.js} +24 -1
  49. package/dist/{hooks-D6diaM34.js → hooks-BvOqJBei.js} +33 -2
  50. package/dist/index.js +168 -13
  51. package/dist/{json-ChdEfB0X.js → json-DU8m1pGf.js} +83 -6
  52. package/dist/model/-private.js +1 -1
  53. package/dist/model/migration-support.js +15 -2
  54. package/dist/{unpkg/dev-deprecated/model-for-CqXsIKws.js → model-for-CXkJw59V.js} +77 -1
  55. package/dist/model-fragments.js +18 -2
  56. package/dist/model.js +12 -8
  57. package/dist/{schema-provider-DJCV_6AF.js → schema-provider-DtPOp0d7.js} +93 -6
  58. package/dist/serializer/json-api.js +8 -3
  59. package/dist/serializer/json.js +1 -1
  60. package/dist/serializer/rest.js +3 -4
  61. package/dist/serializer/transform.js +51 -3
  62. package/dist/serializer.js +4 -7
  63. package/dist/store.js +13 -7
  64. package/dist/unpkg/dev/adapter/error.js +386 -241
  65. package/dist/unpkg/dev/adapter/json-api.js +13 -1
  66. package/dist/unpkg/dev/adapter/rest.js +39 -3
  67. package/dist/unpkg/dev/adapter.js +23 -26
  68. package/dist/unpkg/dev/compat/builders.js +0 -1
  69. package/dist/unpkg/dev/compat/extensions.js +80 -3
  70. package/dist/unpkg/dev/compat/utils.js +14 -0
  71. package/dist/unpkg/dev/compat.js +34 -1
  72. package/dist/unpkg/dev/{errors-DmGGJr3T.js → errors-DngRU-If.js} +24 -1
  73. package/dist/unpkg/dev/{hooks-CkYiE6Ud.js → hooks-UuiLxWxS.js} +33 -2
  74. package/dist/unpkg/dev/index.js +171 -13
  75. package/dist/unpkg/dev/json-K2Y9z6MN.js +1333 -0
  76. package/dist/unpkg/dev/model/-private.js +1 -1
  77. package/dist/unpkg/dev/model/migration-support.js +16 -2
  78. package/dist/unpkg/{prod-deprecated/model-for-CqXsIKws.js → dev/model-for-CXkJw59V.js} +77 -1
  79. package/dist/unpkg/dev/model-fragments.js +18 -2
  80. package/dist/unpkg/dev/model.js +12 -8
  81. package/dist/unpkg/dev/{schema-provider-DDVYxmUV.js → schema-provider-0D7f-QOn.js} +92 -6
  82. package/dist/unpkg/dev/serializer/json-api.js +9 -4
  83. package/dist/unpkg/dev/serializer/json.js +1 -1
  84. package/dist/unpkg/dev/serializer/rest.js +3 -4
  85. package/dist/unpkg/dev/serializer/transform.js +51 -3
  86. package/dist/unpkg/dev/serializer.js +4 -7
  87. package/dist/unpkg/dev/store.js +21 -7
  88. package/dist/unpkg/dev-deprecated/adapter/error.js +386 -241
  89. package/dist/unpkg/dev-deprecated/adapter/json-api.js +13 -1
  90. package/dist/unpkg/dev-deprecated/adapter/rest.js +39 -3
  91. package/dist/unpkg/dev-deprecated/adapter.js +23 -26
  92. package/dist/unpkg/dev-deprecated/compat/builders.js +0 -1
  93. package/dist/unpkg/dev-deprecated/compat/extensions.js +80 -3
  94. package/dist/unpkg/dev-deprecated/compat/utils.js +14 -0
  95. package/dist/unpkg/dev-deprecated/compat.js +34 -1
  96. package/dist/unpkg/dev-deprecated/{errors-Spt6ubMd.js → errors-Bzidntpi.js} +24 -1
  97. package/dist/unpkg/dev-deprecated/{hooks-DOXegvhL.js → hooks-DVXhMW14.js} +33 -2
  98. package/dist/unpkg/dev-deprecated/index.js +171 -13
  99. package/dist/unpkg/{prod-deprecated/json-BWrZ5546.js → dev-deprecated/json-K2Y9z6MN.js} +96 -6
  100. package/dist/unpkg/dev-deprecated/model/-private.js +1 -1
  101. package/dist/unpkg/dev-deprecated/model/migration-support.js +16 -2
  102. package/dist/unpkg/{dev/model-for-CqXsIKws.js → dev-deprecated/model-for-CXkJw59V.js} +77 -1
  103. package/dist/unpkg/dev-deprecated/model-fragments.js +18 -2
  104. package/dist/unpkg/dev-deprecated/model.js +12 -8
  105. package/dist/unpkg/dev-deprecated/{schema-provider-BP6_8N-V.js → schema-provider-ZwO5_fZw.js} +84 -3
  106. package/dist/unpkg/dev-deprecated/serializer/json-api.js +9 -4
  107. package/dist/unpkg/dev-deprecated/serializer/json.js +1 -1
  108. package/dist/unpkg/dev-deprecated/serializer/rest.js +3 -4
  109. package/dist/unpkg/dev-deprecated/serializer/transform.js +51 -3
  110. package/dist/unpkg/dev-deprecated/serializer.js +4 -7
  111. package/dist/unpkg/dev-deprecated/store.js +21 -7
  112. package/dist/unpkg/prod/adapter/error.js +386 -241
  113. package/dist/unpkg/prod/adapter/json-api.js +13 -1
  114. package/dist/unpkg/prod/adapter/rest.js +39 -3
  115. package/dist/unpkg/prod/adapter.js +23 -26
  116. package/dist/unpkg/prod/compat/builders.js +0 -1
  117. package/dist/unpkg/prod/compat/extensions.js +70 -3
  118. package/dist/unpkg/prod/compat/utils.js +14 -0
  119. package/dist/unpkg/prod/compat.js +17 -0
  120. package/dist/unpkg/prod/{errors-BGVFCBmi.js → errors-B-PWeYlW.js} +24 -1
  121. package/dist/unpkg/prod/{hooks-BztVA_x0.js → hooks-Bx-zBziU.js} +32 -1
  122. package/dist/unpkg/prod/index.js +171 -5
  123. package/dist/unpkg/{dev/json-Cu1LNgmQ.js → prod/json-Qewu-UN9.js} +63 -19
  124. package/dist/unpkg/prod/model/-private.js +1 -1
  125. package/dist/unpkg/prod/model/migration-support.js +16 -2
  126. package/dist/unpkg/prod/model-for-CXkJw59V.js +297 -0
  127. package/dist/unpkg/prod/model-fragments.js +18 -2
  128. package/dist/unpkg/prod/model.js +12 -8
  129. package/dist/unpkg/prod/{schema-provider-DJtD_8jZ.js → schema-provider-BgRqk8i9.js} +96 -6
  130. package/dist/unpkg/prod/serializer/json-api.js +9 -4
  131. package/dist/unpkg/prod/serializer/json.js +1 -1
  132. package/dist/unpkg/prod/serializer/rest.js +3 -4
  133. package/dist/unpkg/prod/serializer/transform.js +51 -3
  134. package/dist/unpkg/prod/serializer.js +4 -7
  135. package/dist/unpkg/prod/store.js +21 -7
  136. package/dist/unpkg/prod-deprecated/adapter/error.js +386 -241
  137. package/dist/unpkg/prod-deprecated/adapter/json-api.js +13 -1
  138. package/dist/unpkg/prod-deprecated/adapter/rest.js +39 -3
  139. package/dist/unpkg/prod-deprecated/adapter.js +23 -26
  140. package/dist/unpkg/prod-deprecated/compat/builders.js +0 -1
  141. package/dist/unpkg/prod-deprecated/compat/extensions.js +70 -3
  142. package/dist/unpkg/prod-deprecated/compat/utils.js +14 -0
  143. package/dist/unpkg/prod-deprecated/compat.js +17 -0
  144. package/dist/unpkg/prod-deprecated/{errors-CdDaK81x.js → errors-Dl2J9d1D.js} +24 -1
  145. package/dist/unpkg/prod-deprecated/{hooks-yId87yyG.js → hooks-Cm60wWTf.js} +32 -1
  146. package/dist/unpkg/prod-deprecated/index.js +171 -5
  147. package/dist/unpkg/{dev-deprecated/json-Cu1LNgmQ.js → prod-deprecated/json-Qewu-UN9.js} +63 -19
  148. package/dist/unpkg/prod-deprecated/model/-private.js +1 -1
  149. package/dist/unpkg/prod-deprecated/model/migration-support.js +16 -2
  150. package/dist/{model-for-CqXsIKws.js → unpkg/prod-deprecated/model-for-CXkJw59V.js} +77 -1
  151. package/dist/unpkg/prod-deprecated/model-fragments.js +18 -2
  152. package/dist/unpkg/prod-deprecated/model.js +12 -8
  153. package/dist/unpkg/prod-deprecated/{schema-provider-CjX55uSY.js → schema-provider-Dh6tRqVI.js} +79 -3
  154. package/dist/unpkg/prod-deprecated/serializer/json-api.js +9 -4
  155. package/dist/unpkg/prod-deprecated/serializer/json.js +1 -1
  156. package/dist/unpkg/prod-deprecated/serializer/rest.js +3 -4
  157. package/dist/unpkg/prod-deprecated/serializer/transform.js +51 -3
  158. package/dist/unpkg/prod-deprecated/serializer.js +4 -7
  159. package/dist/unpkg/prod-deprecated/store.js +21 -7
  160. package/package.json +8 -8
  161. package/dist/unpkg/prod/json-BWrZ5546.js +0 -1243
  162. package/dist/unpkg/prod/model-for-CqXsIKws.js +0 -221
@@ -4,70 +4,6 @@ import { getOrSetGlobal } from '@warp-drive/core/types/-private';
4
4
  /* eslint-disable @typescript-eslint/no-unsafe-member-access */
5
5
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
6
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
7
  function _AdapterError(errors, message = 'Adapter operation failed') {
72
8
  this.isAdapterError = true;
73
9
  const error = Error.call(this, message);
@@ -89,9 +25,122 @@ function _AdapterError(errors, message = 'Adapter operation failed') {
89
25
  detail: message
90
26
  }];
91
27
  }
28
+
29
+ /**
30
+ * The shape of the errors thrown/returned by {@link AdapterError} and its subclasses.
31
+ */
32
+
33
+ /**
34
+ * The static interface shared by {@link AdapterError} and its subclasses,
35
+ * allowing further subclassing via {@link AdapterRequestErrorConstructor.extend | extend}.
36
+ */
37
+
92
38
  _AdapterError.prototype = Object.create(Error.prototype);
93
39
  _AdapterError.prototype.code = 'AdapterError';
94
40
  _AdapterError.extend = extendFn(_AdapterError);
41
+
42
+ /**
43
+ * The {@link AdapterRequestError} shape thrown by the {@link AdapterError} constructor.
44
+ */
45
+
46
+ /**
47
+ * :::danger
48
+ * ⚠️ **This is LEGACY documentation** for a feature that is no longer encouraged to be used.
49
+ * If starting a new app or thinking of implementing a new adapter, consider writing a
50
+ * {@link Handler} instead to be used with the {@link RequestManager}
51
+ * :::
52
+ *
53
+ * An `AdapterError` is used by an adapter to signal that an error occurred
54
+ * during a request to an external API. It indicates a generic error, and
55
+ * subclasses are used to indicate specific error states.
56
+ *
57
+ * To create a custom error to signal a specific error state in communicating
58
+ * with an external API, extend the `AdapterError`. For example, if the
59
+ * external API exclusively used HTTP `503 Service Unavailable` to indicate
60
+ * it was closed for maintenance:
61
+ *
62
+ * ```js [app/adapters/maintenance-error.js]
63
+ * import AdapterError from '@warp-drive/legacy/adapter/error';
64
+ *
65
+ * export default AdapterError.extend({ message: "Down for maintenance." });
66
+ * ```
67
+ *
68
+ * This error would then be returned by an adapter's `handleResponse` method:
69
+ *
70
+ * ```js [app/adapters/application.js]
71
+ * import JSONAPIAdapter from '@warp-drive/legacy/adapter/json-api';
72
+ * import MaintenanceError from './maintenance-error';
73
+ *
74
+ * export default class ApplicationAdapter extends JSONAPIAdapter {
75
+ * handleResponse(status) {
76
+ * if (503 === status) {
77
+ * return new MaintenanceError();
78
+ * }
79
+ *
80
+ * return super.handleResponse(...arguments);
81
+ * }
82
+ * }
83
+ * ```
84
+ *
85
+ * And can then be detected in an application and used to send the user to an
86
+ * `under-maintenance` route:
87
+ *
88
+ * ```js [app/routes/application.js]
89
+ * import MaintenanceError from '../adapters/maintenance-error';
90
+ *
91
+ * export default class ApplicationRoute extends Route {
92
+ * actions: {
93
+ * error(error, transition) {
94
+ * if (error instanceof MaintenanceError) {
95
+ * this.transitionTo('under-maintenance');
96
+ * return;
97
+ * }
98
+ *
99
+ * // ...other error handling logic
100
+ * }
101
+ * }
102
+ * }
103
+ * ```
104
+ *
105
+ * ### Signaling an Error Without Extending `AdapterError`
106
+ *
107
+ * Extending `AdapterError` (or one of its subclasses) is a convenience, not
108
+ * a requirement. WarpDrive only inspects an error for the {@link AdapterRequestError}
109
+ * shape: an `isAdapterError` flag, a `code`, and an {json:api}-formatted
110
+ * `errors` array. Any object satisfying that shape — including a plain
111
+ * `Error` with those properties attached — will be handled identically to
112
+ * an instance created via `new AdapterError()` or one of its subclasses.
113
+ *
114
+ * This is useful when you'd rather not introduce a class hierarchy, or
115
+ * when the error needs to be constructed from data you don't control
116
+ * (for example, re-throwing an error surfaced by a third-party library):
117
+ *
118
+ * ```js [app/adapters/application.js]
119
+ * import JSONAPIAdapter from '@warp-drive/legacy/adapter/json-api';
120
+ *
121
+ * export default class ApplicationAdapter extends JSONAPIAdapter {
122
+ * handleResponse(status, headers, payload) {
123
+ * if (status === 503) {
124
+ * const error = new Error('Down for maintenance.');
125
+ * error.isAdapterError = true;
126
+ * error.code = 'MaintenanceError';
127
+ * error.errors = [{ title: 'Service Unavailable', detail: 'Down for maintenance.' }];
128
+ * return error;
129
+ * }
130
+ *
131
+ * return super.handleResponse(status, headers, payload);
132
+ * }
133
+ * }
134
+ * ```
135
+ *
136
+ * Because `code` is just a string you control, `error instanceof AdapterError`
137
+ * checks won't match a plain object built this way — consumers should
138
+ * instead branch on `error.isAdapterError && error.code === 'MaintenanceError'`,
139
+ * or on whichever of the {@link AdapterError} subclasses' `code` values
140
+ * (e.g. `'InvalidError'`, `'NotFoundError'`) the error's `code` matches.
141
+ *
142
+ * @public
143
+ */
95
144
  const AdapterError = getOrSetGlobal('AdapterError', _AdapterError);
96
145
  function extendFn(ErrorClass) {
97
146
  return function ({
@@ -116,220 +165,316 @@ function extend(ParentErrorClass, defaultMessage) {
116
165
  }
117
166
 
118
167
  /**
119
- A `InvalidError` is used by an adapter to signal the external API
120
- was unable to process a request because the content was not
121
- semantically correct or meaningful per the API. Usually, this means a
122
- record failed some form of server-side validation. When a promise
123
- from an adapter is rejected with a `InvalidError` the record will
124
- transition to the `invalid` state and the errors will be set to the
125
- `errors` property on the record.
126
-
127
- For WarpDrive to correctly map errors to their corresponding
128
- properties on the model, WarpDrive expects each error to be
129
- a valid JSON-API error object with a `source/pointer` that matches
130
- the property name. For example, if you had a Post model that
131
- looked like this.
132
-
133
- ```js [app/models/post.js]
134
- import { Model, attr } from '@warp-drive/legacy/model';
135
-
136
- export default class PostModel extends Model {
137
- @attr('string') title;
138
- @attr('string') content;
139
- }
140
- ```
141
-
142
- To show an error from the server related to the `title` and
143
- `content` properties your adapter could return a promise that
144
- rejects with a `InvalidError` object that looks like this:
145
-
146
- ```js [app/adapters/post.js]
147
- import RSVP from 'RSVP';
148
- import RESTAdapter from '@warp-drive/legacy/adapter/rest';
149
- import { InvalidError } from '@warp-drive/legacy/adapter/error';
150
-
151
- export default class ApplicationAdapter extends RESTAdapter {
152
- updateRecord() {
153
- // Fictional adapter that always rejects
154
- return RSVP.reject(new InvalidError([
155
- {
156
- detail: 'Must be unique',
157
- source: { pointer: '/data/attributes/title' }
158
- },
159
- {
160
- detail: 'Must not be blank',
161
- source: { pointer: '/data/attributes/content'}
162
- }
163
- ]));
164
- }
165
- }
166
- ```
167
-
168
- Your backend may use different property names for your records the
169
- store will attempt to extract and normalize the errors using the
170
- serializer's `extractErrors` method before the errors get added to
171
- the model. As a result, it is safe for the `InvalidError` to
172
- wrap the error payload unaltered.
173
-
174
- @class InvalidError
175
- @public
176
- */
168
+ * The {@link AdapterRequestError} shape thrown by the {@link InvalidError} constructor.
169
+ */
177
170
  // TODO @deprecate extractError documentation
178
171
 
172
+ /**
173
+ * An `InvalidError` is used by an adapter to signal that the external API
174
+ * was unable to process a request because the content was not semantically
175
+ * correct or meaningful per the API. Usually, this means a record failed
176
+ * some form of server-side validation. When a promise from an adapter is
177
+ * rejected with an `InvalidError` the record will transition to the
178
+ * `invalid` state and the errors will be set to the `errors` property on
179
+ * the record.
180
+ *
181
+ * For WarpDrive to correctly map errors to their corresponding properties
182
+ * on the model, WarpDrive expects each error to be a valid {json:api} error
183
+ * object with a `source.pointer` that matches the property name. For
184
+ * example, if you had a `Post` model that looked like this:
185
+ *
186
+ * ```js [app/models/post.js]
187
+ * import { Model, attr } from '@warp-drive/legacy/model';
188
+ *
189
+ * export default class PostModel extends Model {
190
+ * @attr('string') title;
191
+ * @attr('string') content;
192
+ * }
193
+ * ```
194
+ *
195
+ * To show an error from the server related to the `title` and `content`
196
+ * properties your adapter could return a promise that rejects with an
197
+ * `InvalidError` that looks like this:
198
+ *
199
+ * ```js [app/adapters/post.js]
200
+ * import RSVP from 'RSVP';
201
+ * import RESTAdapter from '@warp-drive/legacy/adapter/rest';
202
+ * import { InvalidError } from '@warp-drive/legacy/adapter/error';
203
+ *
204
+ * export default class ApplicationAdapter extends RESTAdapter {
205
+ * updateRecord() {
206
+ * // Fictional adapter that always rejects
207
+ * return RSVP.reject(new InvalidError([
208
+ * {
209
+ * detail: 'Must be unique',
210
+ * source: { pointer: '/data/attributes/title' }
211
+ * },
212
+ * {
213
+ * detail: 'Must not be blank',
214
+ * source: { pointer: '/data/attributes/content' }
215
+ * }
216
+ * ]));
217
+ * }
218
+ * }
219
+ * ```
220
+ *
221
+ * Your backend may use different property names for your records; the
222
+ * store will attempt to extract and normalize the errors using the
223
+ * serializer's `extractErrors` method before the errors get added to the
224
+ * model. As a result, it is safe for the `InvalidError` to wrap the error
225
+ * payload unaltered.
226
+ *
227
+ * @public
228
+ */
179
229
  const InvalidError = getOrSetGlobal('InvalidError', extend(AdapterError, 'The adapter rejected the commit because it was invalid'));
180
230
  InvalidError.prototype.code = 'InvalidError';
181
231
 
182
232
  /**
183
- A `TimeoutError` is used by an adapter to signal that a request
184
- to the external API has timed out. I.e. no response was received from
185
- the external API within an allowed time period.
186
-
187
- An example use case would be to warn the user to check their internet
188
- connection if an adapter operation has timed out:
189
-
190
- ```js [app/routes/application.js]
191
- import { TimeoutError } from '@warp-drive/legacy/adapter/error';
192
-
193
- export default class ApplicationRoute extends Route {
194
- @action
195
- error(error, transition) {
196
- if (error instanceof TimeoutError) {
197
- // alert the user
198
- alert('Are you still connected to the Internet?');
199
- return;
200
- }
201
-
202
- // ...other error handling logic
203
- }
204
- }
205
- ```
206
-
207
- @class TimeoutError
208
- @public
209
- */
233
+ * The {@link AdapterRequestError} shape thrown by the {@link TimeoutError} constructor.
234
+ */
210
235
 
236
+ /**
237
+ * A `TimeoutError` is used by an adapter to signal that a request to the
238
+ * external API has timed out, i.e. no response was received from the
239
+ * external API within an allowed time period.
240
+ *
241
+ * An example use case would be to warn the user to check their internet
242
+ * connection if an adapter operation has timed out:
243
+ *
244
+ * ```js [app/routes/application.js]
245
+ * import { TimeoutError } from '@warp-drive/legacy/adapter/error';
246
+ *
247
+ * export default class ApplicationRoute extends Route {
248
+ * @action
249
+ * error(error, transition) {
250
+ * if (error instanceof TimeoutError) {
251
+ * // alert the user
252
+ * alert('Are you still connected to the Internet?');
253
+ * return;
254
+ * }
255
+ *
256
+ * // ...other error handling logic
257
+ * }
258
+ * }
259
+ * ```
260
+ *
261
+ * @public
262
+ */
211
263
  const TimeoutError = getOrSetGlobal('TimeoutError', extend(AdapterError, 'The adapter operation timed out'));
212
264
  TimeoutError.prototype.code = 'TimeoutError';
213
265
 
214
266
  /**
215
- A `AbortError` is used by an adapter to signal that a request to
216
- the external API was aborted. For example, this can occur if the user
217
- navigates away from the current page after a request to the external API
218
- has been initiated but before a response has been received.
219
-
220
- @class AbortError
221
- @public
222
- */
267
+ * The {@link AdapterRequestError} shape thrown by the {@link AbortError} constructor.
268
+ */
223
269
 
270
+ /**
271
+ * An `AbortError` is used by an adapter to signal that a request to the
272
+ * external API was aborted. For example, this can occur if the user
273
+ * navigates away from the current page after a request to the external API
274
+ * has been initiated but before a response has been received.
275
+ *
276
+ * Because an aborted request is typically expected (the user chose to
277
+ * navigate away, or a newer request superseded this one) rather than
278
+ * exceptional, an example use case would be to silently ignore it instead
279
+ * of surfacing an error to the user:
280
+ *
281
+ * ```js [app/routes/application.js]
282
+ * import { AbortError } from '@warp-drive/legacy/adapter/error';
283
+ *
284
+ * export default class ApplicationRoute extends Route {
285
+ * @action
286
+ * error(error, transition) {
287
+ * if (error instanceof AbortError) {
288
+ * // the request was aborted, nothing to report
289
+ * return;
290
+ * }
291
+ *
292
+ * // ...other error handling logic
293
+ * }
294
+ * }
295
+ * ```
296
+ *
297
+ * @public
298
+ */
224
299
  const AbortError = getOrSetGlobal('AbortError', extend(AdapterError, 'The adapter operation was aborted'));
225
300
  AbortError.prototype.code = 'AbortError';
226
301
 
227
302
  /**
228
- A `UnauthorizedError` equates to a HTTP `401 Unauthorized` response
229
- status. It is used by an adapter to signal that a request to the external
230
- API was rejected because authorization is required and has failed or has not
231
- yet been provided.
232
-
233
- An example use case would be to redirect the user to a login route if a
234
- request is unauthorized:
235
-
236
- ```js [app/routes/application.js]
237
- import { UnauthorizedError } from '@warp-drive/legacy/adapter/error';
238
-
239
- export default class ApplicationRoute extends Route {
240
- @action
241
- error(error, transition) {
242
- if (error instanceof UnauthorizedError) {
243
- // go to the login route
244
- this.transitionTo('login');
245
- return;
246
- }
247
-
248
- // ...other error handling logic
249
- }
250
- }
251
- ```
252
-
253
- @class UnauthorizedError
254
- @public
255
- */
303
+ * The {@link AdapterRequestError} shape thrown by the {@link UnauthorizedError} constructor.
304
+ */
256
305
 
306
+ /**
307
+ * A `UnauthorizedError` equates to an HTTP `401 Unauthorized` response
308
+ * status. It is used by an adapter to signal that a request to the external
309
+ * API was rejected because authorization is required and has failed or has
310
+ * not yet been provided.
311
+ *
312
+ * An example use case would be to redirect the user to a login route if a
313
+ * request is unauthorized:
314
+ *
315
+ * ```js [app/routes/application.js]
316
+ * import { UnauthorizedError } from '@warp-drive/legacy/adapter/error';
317
+ *
318
+ * export default class ApplicationRoute extends Route {
319
+ * @action
320
+ * error(error, transition) {
321
+ * if (error instanceof UnauthorizedError) {
322
+ * // go to the login route
323
+ * this.transitionTo('login');
324
+ * return;
325
+ * }
326
+ *
327
+ * // ...other error handling logic
328
+ * }
329
+ * }
330
+ * ```
331
+ *
332
+ * @public
333
+ */
257
334
  const UnauthorizedError = getOrSetGlobal('UnauthorizedError', extend(AdapterError, 'The adapter operation is unauthorized'));
258
335
  UnauthorizedError.prototype.code = 'UnauthorizedError';
259
336
 
260
337
  /**
261
- A `ForbiddenError` equates to a HTTP `403 Forbidden` response status.
262
- It is used by an adapter to signal that a request to the external API was
263
- valid but the server is refusing to respond to it. If authorization was
264
- provided and is valid, then the authenticated user does not have the
265
- necessary permissions for the request.
266
-
267
- @class ForbiddenError
268
- @public
269
- */
338
+ * The {@link AdapterRequestError} shape thrown by the {@link ForbiddenError} constructor.
339
+ */
270
340
 
341
+ /**
342
+ * A `ForbiddenError` equates to an HTTP `403 Forbidden` response status.
343
+ * It is used by an adapter to signal that a request to the external API was
344
+ * valid but the server is refusing to respond to it. If authorization was
345
+ * provided and is valid, then the authenticated user does not have the
346
+ * necessary permissions for the request.
347
+ *
348
+ * Unlike an {@link UnauthorizedError}, retrying the request with different
349
+ * credentials will not help; the currently authenticated user simply lacks
350
+ * permission. An example use case would be to show the user a "you don't
351
+ * have access to this" message rather than redirecting them to log in:
352
+ *
353
+ * ```js [app/routes/application.js]
354
+ * import { ForbiddenError } from '@warp-drive/legacy/adapter/error';
355
+ *
356
+ * export default class ApplicationRoute extends Route {
357
+ * @action
358
+ * error(error, transition) {
359
+ * if (error instanceof ForbiddenError) {
360
+ * this.transitionTo('forbidden');
361
+ * return;
362
+ * }
363
+ *
364
+ * // ...other error handling logic
365
+ * }
366
+ * }
367
+ * ```
368
+ *
369
+ * @public
370
+ */
271
371
  const ForbiddenError = getOrSetGlobal('ForbiddenError', extend(AdapterError, 'The adapter operation is forbidden'));
272
372
  ForbiddenError.prototype.code = 'ForbiddenError';
273
373
 
274
374
  /**
275
- A `NotFoundError` equates to a HTTP `404 Not Found` response status.
276
- It is used by an adapter to signal that a request to the external API
277
- was rejected because the resource could not be found on the API.
278
-
279
- An example use case would be to detect if the user has entered a route
280
- for a specific model that does not exist. For example:
281
-
282
- ```js [app/routes/post.js]
283
- import { NotFoundError } from '@warp-drive/legacy/adapter/error';
284
-
285
- export default class PostRoute extends Route {
286
- @service store;
287
- model(params) {
288
- return this.store.findRecord('post', params.post_id);
289
- }
290
- @action
291
- error(error, transition) {
292
- if (error instanceof NotFoundError) {
293
- // redirect to a list of all posts instead
294
- this.transitionTo('posts');
295
- } else {
296
- // otherwise let the error bubble
297
- return true;
298
- }
299
- }
300
- }
301
- ```
302
-
303
- @class NotFoundError
304
- @public
305
- */
375
+ * The {@link AdapterRequestError} shape thrown by the {@link NotFoundError} constructor.
376
+ */
306
377
 
378
+ /**
379
+ * A `NotFoundError` equates to an HTTP `404 Not Found` response status.
380
+ * It is used by an adapter to signal that a request to the external API
381
+ * was rejected because the resource could not be found on the API.
382
+ *
383
+ * An example use case would be to detect if the user has entered a route
384
+ * for a specific model that does not exist. For example:
385
+ *
386
+ * ```js [app/routes/post.js]
387
+ * import { NotFoundError } from '@warp-drive/legacy/adapter/error';
388
+ *
389
+ * export default class PostRoute extends Route {
390
+ * @service store;
391
+ * model(params) {
392
+ * return this.store.findRecord('post', params.post_id);
393
+ * }
394
+ * @action
395
+ * error(error, transition) {
396
+ * if (error instanceof NotFoundError) {
397
+ * // redirect to a list of all posts instead
398
+ * this.transitionTo('posts');
399
+ * } else {
400
+ * // otherwise let the error bubble
401
+ * return true;
402
+ * }
403
+ * }
404
+ * }
405
+ * ```
406
+ *
407
+ * @public
408
+ */
307
409
  const NotFoundError = getOrSetGlobal('NotFoundError', extend(AdapterError, 'The adapter could not find the resource'));
308
410
  NotFoundError.prototype.code = 'NotFoundError';
309
411
 
310
412
  /**
311
- A `ConflictError` equates to a HTTP `409 Conflict` response status.
312
- It is used by an adapter to indicate that the request could not be processed
313
- because of a conflict in the request. An example scenario would be when
314
- creating a record with a client-generated ID but that ID is already known
315
- to the external API.
316
-
317
- @class ConflictError
318
- @public
319
- */
413
+ * The {@link AdapterRequestError} shape thrown by the {@link ConflictError} constructor.
414
+ */
320
415
 
416
+ /**
417
+ * A `ConflictError` equates to an HTTP `409 Conflict` response status.
418
+ * It is used by an adapter to indicate that the request could not be
419
+ * processed because of a conflict in the request. An example scenario
420
+ * would be when creating a record with a client-generated ID but that ID
421
+ * is already known to the external API.
422
+ *
423
+ * An example use case would be to surface a conflict-specific message so
424
+ * the user can retry with different input:
425
+ *
426
+ * ```js [app/routes/application.js]
427
+ * import { ConflictError } from '@warp-drive/legacy/adapter/error';
428
+ *
429
+ * export default class ApplicationRoute extends Route {
430
+ * @action
431
+ * error(error, transition) {
432
+ * if (error instanceof ConflictError) {
433
+ * alert('That identifier is already in use, please choose another.');
434
+ * return;
435
+ * }
436
+ *
437
+ * // ...other error handling logic
438
+ * }
439
+ * }
440
+ * ```
441
+ *
442
+ * @public
443
+ */
321
444
  const ConflictError = getOrSetGlobal('ConflictError', extend(AdapterError, 'The adapter operation failed due to a conflict'));
322
445
  ConflictError.prototype.code = 'ConflictError';
323
446
 
324
447
  /**
325
- A `ServerError` equates to a HTTP `500 Internal Server Error` response
326
- status. It is used by the adapter to indicate that a request has failed
327
- because of an error in the external API.
328
-
329
- @class ServerError
330
- @public
331
- */
448
+ * The {@link AdapterRequestError} shape thrown by the {@link ServerError} constructor.
449
+ */
332
450
 
451
+ /**
452
+ * A `ServerError` equates to an HTTP `500 Internal Server Error` response
453
+ * status. It is used by the adapter to indicate that a request has failed
454
+ * because of an error in the external API, and is unlikely to succeed if
455
+ * retried immediately.
456
+ *
457
+ * An example use case would be to show a generic "something went wrong on
458
+ * our end" message rather than one implying the user made a mistake:
459
+ *
460
+ * ```js [app/routes/application.js]
461
+ * import { ServerError } from '@warp-drive/legacy/adapter/error';
462
+ *
463
+ * export default class ApplicationRoute extends Route {
464
+ * @action
465
+ * error(error, transition) {
466
+ * if (error instanceof ServerError) {
467
+ * alert('Something went wrong on our end. Please try again later.');
468
+ * return;
469
+ * }
470
+ *
471
+ * // ...other error handling logic
472
+ * }
473
+ * }
474
+ * ```
475
+ *
476
+ * @public
477
+ */
333
478
  const ServerError = getOrSetGlobal('ServerError', extend(AdapterError, 'The adapter operation failed due to a server error'));
334
479
  ServerError.prototype.code = 'ServerError';
335
480
  export { AbortError, AdapterError, ConflictError, ForbiddenError, InvalidError, NotFoundError, ServerError, TimeoutError, UnauthorizedError };