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