@warp-drive/legacy 5.7.0-alpha.0 → 5.7.0-alpha.10
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/declarations/adapter/error.d.ts +2 -2
- package/declarations/compat/builders/find-all.d.ts +2 -2
- package/declarations/compat/builders/query.d.ts +2 -2
- package/declarations/model/-private/model-methods.d.ts +3 -0
- package/declarations/model/-private/model.d.ts +3 -0
- package/declarations/model/-private.d.ts +1 -0
- package/declarations/model/migration-support.d.ts +2 -20
- package/declarations/model.d.ts +1 -1
- package/declarations/store/-private.d.ts +235 -0
- package/declarations/store.d.ts +3 -0
- package/dist/adapter/error.js +66 -0
- package/dist/adapter/rest.js +1 -1
- package/dist/compat/builders.js +1 -21
- package/dist/model/migration-support.js +90 -8
- package/dist/model.js +3 -2
- package/dist/{schema-provider-BdQhkT-Q.js → schema-provider-Cbnf6sKm.js} +104 -35
- package/dist/store.js +631 -0
- package/dist/util-Dul6TZts.js +35 -0
- package/dist/utils-Cqw9eRj5.js +23 -0
- package/package.json +6 -6
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ApiError } from "@warp-drive/core/types/spec/error";
|
|
2
2
|
export interface AdapterRequestError<T extends string = string> extends Error {
|
|
3
3
|
isAdapterError: true;
|
|
4
4
|
code: T;
|
|
5
|
-
errors:
|
|
5
|
+
errors: ApiError[];
|
|
6
6
|
}
|
|
7
7
|
export interface AdapterRequestErrorConstructor<Instance extends AdapterRequestError = AdapterRequestError> {
|
|
8
8
|
new (errors?: unknown[], message?: string): Instance;
|
|
@@ -13,7 +13,7 @@ type FindAllRequestInput<
|
|
|
13
13
|
};
|
|
14
14
|
[RequestSignature]?: RT;
|
|
15
15
|
};
|
|
16
|
-
type FindAllBuilderOptions
|
|
16
|
+
type FindAllBuilderOptions = FindAllOptions;
|
|
17
17
|
/**
|
|
18
18
|
This function builds a request config to perform a `findAll` request for the given type.
|
|
19
19
|
When passed to `store.request`, this config will result in the same behavior as a `store.findAll` request.
|
|
@@ -30,6 +30,6 @@ To that end, these builders are deprecated and will be removed in a future versi
|
|
|
30
30
|
@param {FindAllBuilderOptions} [options] optional, may include `adapterOptions` hash which will be passed to adapter.findAll
|
|
31
31
|
@return {FindAllRequestInput} request config
|
|
32
32
|
*/
|
|
33
|
-
export declare function findAllBuilder<T extends TypedRecordInstance>(type: TypeFromInstance<T>, options?: FindAllBuilderOptions
|
|
33
|
+
export declare function findAllBuilder<T extends TypedRecordInstance>(type: TypeFromInstance<T>, options?: FindAllBuilderOptions): FindAllRequestInput<TypeFromInstance<T>, T[]>;
|
|
34
34
|
export declare function findAllBuilder(type: string, options?: FindAllBuilderOptions): FindAllRequestInput;
|
|
35
35
|
export {};
|
|
@@ -31,7 +31,7 @@ To that end, these builders are deprecated and will be removed in a future versi
|
|
|
31
31
|
@param {QueryBuilderOptions} [options] optional, may include `adapterOptions` hash which will be passed to adapter.query
|
|
32
32
|
@return {QueryRequestInput} request config
|
|
33
33
|
*/
|
|
34
|
-
export declare function queryBuilder<T extends TypedRecordInstance>(type: TypeFromInstance<T>, query: LegacyResourceQuery
|
|
34
|
+
export declare function queryBuilder<T extends TypedRecordInstance>(type: TypeFromInstance<T>, query: LegacyResourceQuery, options?: QueryBuilderOptions): QueryRequestInput<TypeFromInstance<T>, T[]>;
|
|
35
35
|
export declare function queryBuilder(type: string, query: LegacyResourceQuery, options?: QueryBuilderOptions): QueryRequestInput;
|
|
36
36
|
type QueryRecordRequestInput<
|
|
37
37
|
T extends string = string,
|
|
@@ -61,6 +61,6 @@ To that end, these builders are deprecated and will be removed in a future versi
|
|
|
61
61
|
@param {QueryBuilderOptions} [options] optional, may include `adapterOptions` hash which will be passed to adapter.query
|
|
62
62
|
@return {QueryRecordRequestInput} request config
|
|
63
63
|
*/
|
|
64
|
-
export declare function queryRecordBuilder<T extends TypedRecordInstance>(type: TypeFromInstance<T>, query: LegacyResourceQuery
|
|
64
|
+
export declare function queryRecordBuilder<T extends TypedRecordInstance>(type: TypeFromInstance<T>, query: LegacyResourceQuery, options?: QueryBuilderOptions): QueryRecordRequestInput<TypeFromInstance<T>, T | null>;
|
|
65
65
|
export declare function queryRecordBuilder(type: string, query: LegacyResourceQuery, options?: QueryBuilderOptions): QueryRecordRequestInput;
|
|
66
66
|
export {};
|
|
@@ -32,9 +32,12 @@ export declare function hasMany<
|
|
|
32
32
|
K extends MaybeHasManyFields<T>
|
|
33
33
|
>(this: T, prop: K): HasManyReference<T, K>;
|
|
34
34
|
export declare function reload<T extends MinimalLegacyRecord>(this: T, options?: Record<string, unknown>): Promise<T>;
|
|
35
|
+
export declare function _reload<T extends MinimalLegacyRecord>(this: T, options?: Record<string, unknown>): Promise<T>;
|
|
35
36
|
export declare function changedAttributes<T extends MinimalLegacyRecord>(this: T): ChangedAttributesHash;
|
|
36
37
|
export declare function serialize<T extends MinimalLegacyRecord>(this: T, options?: Record<string, unknown>): unknown;
|
|
37
38
|
export declare function deleteRecord<T extends MinimalLegacyRecord>(this: T): void;
|
|
38
39
|
export declare function save<T extends MinimalLegacyRecord>(this: T, options?: Record<string, unknown>): Promise<T>;
|
|
40
|
+
export declare function _save<T extends MinimalLegacyRecord>(this: T, options?: Record<string, unknown>): Promise<T>;
|
|
39
41
|
export declare function destroyRecord<T extends MinimalLegacyRecord>(this: T, options?: Record<string, unknown>): Promise<T>;
|
|
42
|
+
export declare function _destroyRecord<T extends MinimalLegacyRecord>(this: T, options?: Record<string, unknown>): Promise<T>;
|
|
40
43
|
export declare function createSnapshot<T extends MinimalLegacyRecord>(this: T): Snapshot<T>;
|
|
@@ -47,6 +47,8 @@ interface Model {
|
|
|
47
47
|
/** @internal */
|
|
48
48
|
___private_notifications: object;
|
|
49
49
|
/** @internal */
|
|
50
|
+
_isReloading: boolean;
|
|
51
|
+
/** @internal */
|
|
50
52
|
[RecordStore]: Store;
|
|
51
53
|
/**
|
|
52
54
|
Create a JSON representation of the record, using the serialization
|
|
@@ -1319,4 +1321,5 @@ declare class Model extends EmberObject implements MinimalLegacyRecord {
|
|
|
1319
1321
|
*/
|
|
1320
1322
|
static toString(): string;
|
|
1321
1323
|
}
|
|
1324
|
+
export declare function restoreDeprecatedModelRequestBehaviors(ModelKlass: typeof Model): void;
|
|
1322
1325
|
export { Model };
|
|
@@ -6,3 +6,4 @@ export { PromiseBelongsTo } from "./-private/promise-belongs-to.js";
|
|
|
6
6
|
export { PromiseManyArray } from "./-private/promise-many-array.js";
|
|
7
7
|
// // Used by tests, migration support
|
|
8
8
|
export { lookupLegacySupport, LEGACY_SUPPORT } from "./-private/legacy-relationships-support.js";
|
|
9
|
+
export type { MaybeHasManyFields, MaybeBelongsToFields, MaybeRelationshipFields } from "./-private/type-utils.js";
|
|
@@ -1,22 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This module provides support for migrating away from @ember-data/model
|
|
3
|
-
* to @warp-drive/schema-record.
|
|
4
|
-
*
|
|
5
|
-
* It includes:
|
|
6
|
-
*
|
|
7
|
-
* - A `withDefaults` function to assist in creating a schema in LegacyMode
|
|
8
|
-
* - A `registerDerivations` function to register the derivations necessary to support LegacyMode
|
|
9
|
-
* - A `DelegatingSchemaService` that can be used to provide a schema service that works with both
|
|
10
|
-
* @ember-data/model and @warp-drive/schema-record simultaneously for migration purposes.
|
|
11
|
-
* - A `WithLegacy` type util that can be used to create a type that includes the legacy
|
|
12
|
-
* properties and methods of a record.
|
|
13
|
-
*
|
|
14
|
-
* Using LegacyMode features on a ReactiveResource *requires* the use of these derivations and schema
|
|
15
|
-
* additions. LegacyMode is not intended to be a long-term solution, but rather a stepping stone
|
|
16
|
-
* to assist in more rapidly adopting modern WarpDrive features.
|
|
17
|
-
*
|
|
18
|
-
* @module
|
|
19
|
-
*/
|
|
20
1
|
import type { Store } from "@warp-drive/core";
|
|
21
2
|
import type { CAUTION_MEGA_DANGER_ZONE_Extension, ProcessedExtension } from "@warp-drive/core/reactive";
|
|
22
3
|
import type { ExtensibleField } from "@warp-drive/core/reactive/-private/schema";
|
|
@@ -170,6 +151,7 @@ export type WithLegacy<T extends TypedRecordInstance> = T & LegacyModeRecord<T>;
|
|
|
170
151
|
* @public
|
|
171
152
|
*/
|
|
172
153
|
export declare function withDefaults(schema: WithPartial<LegacyResourceSchema, "legacy" | "identity">): LegacyResourceSchema;
|
|
154
|
+
export declare function withRestoredDeprecatedModelRequestBehaviors(schema: WithPartial<LegacyResourceSchema, "legacy" | "identity">): LegacyResourceSchema;
|
|
173
155
|
/**
|
|
174
156
|
* A function which registers the necessary derivations to support
|
|
175
157
|
* the LegacyMode features of @ember-data/model while migrating to WarpDrive.
|
|
@@ -267,7 +249,7 @@ export declare class DelegatingSchemaService implements SchemaService {
|
|
|
267
249
|
CAUTION_MEGA_DANGER_ZONE_resourceExtensions(resource: StableRecordIdentifier | {
|
|
268
250
|
type: string;
|
|
269
251
|
}): null | ProcessedExtension["features"];
|
|
270
|
-
CAUTION_MEGA_DANGER_ZONE_objectExtensions(field: ExtensibleField): null | ProcessedExtension["features"];
|
|
252
|
+
CAUTION_MEGA_DANGER_ZONE_objectExtensions(field: ExtensibleField, resolvedType: string | null): null | ProcessedExtension["features"];
|
|
271
253
|
CAUTION_MEGA_DANGER_ZONE_arrayExtensions(field: ExtensibleField): null | ProcessedExtension["features"];
|
|
272
254
|
/**
|
|
273
255
|
* This is an internal method used to register behaviors for legacy mode.
|
package/declarations/model.d.ts
CHANGED
|
@@ -39,7 +39,7 @@ and dasherized.
|
|
|
39
39
|
export { attr } from "./model/-private/attr.js";
|
|
40
40
|
export { belongsTo } from "./model/-private/belongs-to.js";
|
|
41
41
|
export { hasMany } from "./model/-private/has-many.js";
|
|
42
|
-
export { Model } from "./model/-private/model.js";
|
|
42
|
+
export { Model, restoreDeprecatedModelRequestBehaviors } from "./model/-private/model.js";
|
|
43
43
|
export { Model as default } from "./model/-private/model.js";
|
|
44
44
|
export type { PromiseBelongsTo as AsyncBelongsTo } from "./model/-private/promise-belongs-to.js";
|
|
45
45
|
export type { PromiseManyArray as AsyncHasMany } from "./model/-private/promise-many-array.js";
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { type InstanceCache } from "@warp-drive/core/store/-private";
|
|
2
|
+
import type { StableNewRecordIdentifier, StableRecordIdentifier } from "@warp-drive/core/types/identifier";
|
|
3
|
+
import type { Value } from "@warp-drive/core/types/json/raw";
|
|
4
|
+
import type { OpaqueRecordInstance, TypedRecordInstance, TypeFromInstance } from "@warp-drive/core/types/record";
|
|
5
|
+
import type { LegacyAttributeField, LegacyRelationshipField } from "@warp-drive/core/types/schema/fields";
|
|
6
|
+
import type { SingleResourceDocument } from "@warp-drive/core/types/spec/json-api-raw";
|
|
7
|
+
import type { Store } from "../store.js";
|
|
8
|
+
export declare function preloadData(store: Store, identifier: StableNewRecordIdentifier, preload: Record<string, Value>): void;
|
|
9
|
+
export interface BaseFinderOptions {
|
|
10
|
+
reload?: boolean;
|
|
11
|
+
backgroundReload?: boolean;
|
|
12
|
+
include?: string | string[];
|
|
13
|
+
adapterOptions?: Record<string, unknown>;
|
|
14
|
+
}
|
|
15
|
+
export interface FindRecordOptions extends BaseFinderOptions {
|
|
16
|
+
/**
|
|
17
|
+
* Data to preload into the store before the request is made.
|
|
18
|
+
* This feature is *highly* discouraged and has no corresponding
|
|
19
|
+
* feature when using builders and handlers.
|
|
20
|
+
*
|
|
21
|
+
* Excepting relationships: the data should be in the form of a
|
|
22
|
+
* JSON object where the keys are fields on the record and the value
|
|
23
|
+
* is the raw value to be added to the cache.
|
|
24
|
+
*
|
|
25
|
+
* Relationships can either be provided as string IDs from which
|
|
26
|
+
* an identifier will be built base upon the relationship's expected
|
|
27
|
+
* resource type, or be record instances from which the identifier
|
|
28
|
+
* will be extracted.
|
|
29
|
+
*
|
|
30
|
+
*/
|
|
31
|
+
preload?: Record<string, Value>;
|
|
32
|
+
}
|
|
33
|
+
export type QueryOptions = { [K in string | "adapterOptions"]? : K extends "adapterOptions" ? Record<string, unknown> : unknown };
|
|
34
|
+
export type FindAllOptions = BaseFinderOptions;
|
|
35
|
+
export type LegacyResourceQuery = {
|
|
36
|
+
include?: string | string[];
|
|
37
|
+
[key: string]: Value | undefined;
|
|
38
|
+
};
|
|
39
|
+
export type KeyOrString<T> = keyof T & string extends never ? string : keyof T & string;
|
|
40
|
+
/**
|
|
41
|
+
* Minimum subset of static schema methods and properties on the
|
|
42
|
+
* "model" class.
|
|
43
|
+
*
|
|
44
|
+
* Only used when using the legacy schema-service implementation
|
|
45
|
+
* for @ember-data/model or when wrapping schema for legacy
|
|
46
|
+
* Adapters/Serializers.
|
|
47
|
+
*
|
|
48
|
+
*/
|
|
49
|
+
export interface ModelSchema<T = unknown> {
|
|
50
|
+
modelName: T extends TypedRecordInstance ? TypeFromInstance<T> : string;
|
|
51
|
+
fields: Map<KeyOrString<T>, "attribute" | "belongsTo" | "hasMany">;
|
|
52
|
+
attributes: Map<KeyOrString<T>, LegacyAttributeField>;
|
|
53
|
+
relationshipsByName: Map<KeyOrString<T>, LegacyRelationshipField>;
|
|
54
|
+
eachAttribute<K extends KeyOrString<T>>(callback: (this: ModelSchema<T>, key: K, attribute: LegacyAttributeField) => void, binding?: T): void;
|
|
55
|
+
eachRelationship<K extends KeyOrString<T>>(callback: (this: ModelSchema<T>, key: K, relationship: LegacyRelationshipField) => void, binding?: T): void;
|
|
56
|
+
eachTransformedAttribute<K extends KeyOrString<T>>(callback: (this: ModelSchema<T>, key: K, type: string | null) => void, binding?: T): void;
|
|
57
|
+
}
|
|
58
|
+
export declare function resourceIsFullyDeleted(instanceCache: InstanceCache, identifier: StableRecordIdentifier): boolean;
|
|
59
|
+
/**
|
|
60
|
+
A `RecordReference` is a low-level API that allows users and
|
|
61
|
+
addon authors to perform meta-operations on a record.
|
|
62
|
+
|
|
63
|
+
@hideconstructor
|
|
64
|
+
@public
|
|
65
|
+
*/
|
|
66
|
+
export declare class RecordReference {
|
|
67
|
+
/** @internal */
|
|
68
|
+
private store;
|
|
69
|
+
/** @internal */
|
|
70
|
+
// unsubscribe token given to us by the notification manager
|
|
71
|
+
private ___token;
|
|
72
|
+
/** @internal */
|
|
73
|
+
private ___identifier;
|
|
74
|
+
/** @internal */
|
|
75
|
+
private _ref;
|
|
76
|
+
constructor(store: Store, identifier: StableRecordIdentifier);
|
|
77
|
+
/** @internal */
|
|
78
|
+
destroy(): void;
|
|
79
|
+
get type(): string;
|
|
80
|
+
/**
|
|
81
|
+
The `id` of the record that this reference refers to.
|
|
82
|
+
|
|
83
|
+
Together, the `type` and `id` properties form a composite key for
|
|
84
|
+
the identity map.
|
|
85
|
+
|
|
86
|
+
Example
|
|
87
|
+
|
|
88
|
+
```javascript
|
|
89
|
+
let userRef = store.getReference('user', 1);
|
|
90
|
+
|
|
91
|
+
userRef.id(); // '1'
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
@public
|
|
95
|
+
@return The id of the record.
|
|
96
|
+
*/
|
|
97
|
+
id(): string | null;
|
|
98
|
+
/**
|
|
99
|
+
The `identifier` of the record that this reference refers to.
|
|
100
|
+
|
|
101
|
+
Together, the `type` and `id` properties form a composite key for
|
|
102
|
+
the identity map.
|
|
103
|
+
|
|
104
|
+
Example
|
|
105
|
+
|
|
106
|
+
```javascript
|
|
107
|
+
let userRef = store.getReference('user', 1);
|
|
108
|
+
|
|
109
|
+
userRef.identifier(); // '1'
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
@public
|
|
113
|
+
@return The identifier of the record.
|
|
114
|
+
*/
|
|
115
|
+
identifier(): StableRecordIdentifier;
|
|
116
|
+
/**
|
|
117
|
+
How the reference will be looked up when it is loaded. Currently
|
|
118
|
+
this always returns `identity` to signify that a record will be
|
|
119
|
+
loaded by its `type` and `id`.
|
|
120
|
+
|
|
121
|
+
Example
|
|
122
|
+
|
|
123
|
+
```javascript
|
|
124
|
+
const userRef = store.getReference('user', 1);
|
|
125
|
+
|
|
126
|
+
userRef.remoteType(); // 'identity'
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
@public
|
|
130
|
+
*/
|
|
131
|
+
remoteType(): "identity";
|
|
132
|
+
/**
|
|
133
|
+
This API allows you to provide a reference with new data. The
|
|
134
|
+
simplest usage of this API is similar to `store.push`: you provide a
|
|
135
|
+
normalized hash of data and the object represented by the reference
|
|
136
|
+
will update.
|
|
137
|
+
|
|
138
|
+
If you pass a promise to `push`, Ember Data will not ask the adapter
|
|
139
|
+
for the data if another attempt to fetch it is made in the
|
|
140
|
+
interim. When the promise resolves, the underlying object is updated
|
|
141
|
+
with the new data, and the promise returned by *this function* is resolved
|
|
142
|
+
with that object.
|
|
143
|
+
|
|
144
|
+
For example, `recordReference.push(promise)` will be resolved with a
|
|
145
|
+
record.
|
|
146
|
+
|
|
147
|
+
Example
|
|
148
|
+
|
|
149
|
+
```javascript
|
|
150
|
+
let userRef = store.getReference('user', 1);
|
|
151
|
+
|
|
152
|
+
// provide data for reference
|
|
153
|
+
userRef.push({
|
|
154
|
+
data: {
|
|
155
|
+
id: "1",
|
|
156
|
+
type: "user",
|
|
157
|
+
attributes: {
|
|
158
|
+
username: "@user"
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}).then(function(user) {
|
|
162
|
+
userRef.value() === user;
|
|
163
|
+
});
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
@public
|
|
167
|
+
@param objectOrPromise a JSON:API ResourceDocument or a promise resolving to one
|
|
168
|
+
@return a promise for the value (record or relationship)
|
|
169
|
+
*/
|
|
170
|
+
push(objectOrPromise: SingleResourceDocument | Promise<SingleResourceDocument>): Promise<OpaqueRecordInstance>;
|
|
171
|
+
/**
|
|
172
|
+
If the entity referred to by the reference is already loaded, it is
|
|
173
|
+
present as `reference.value`. Otherwise the value returned by this function
|
|
174
|
+
is `null`.
|
|
175
|
+
|
|
176
|
+
Example
|
|
177
|
+
|
|
178
|
+
```javascript
|
|
179
|
+
let userRef = store.getReference('user', 1);
|
|
180
|
+
|
|
181
|
+
userRef.value(); // user
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
@public
|
|
185
|
+
@return {Model} the record for this RecordReference
|
|
186
|
+
*/
|
|
187
|
+
value(): OpaqueRecordInstance | null;
|
|
188
|
+
/**
|
|
189
|
+
Triggers a fetch for the backing entity based on its `remoteType`
|
|
190
|
+
(see `remoteType` definitions per reference type).
|
|
191
|
+
|
|
192
|
+
Example
|
|
193
|
+
|
|
194
|
+
```javascript
|
|
195
|
+
let userRef = store.getReference('user', 1);
|
|
196
|
+
|
|
197
|
+
// load user (via store.find)
|
|
198
|
+
userRef.load().then(...)
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
@public
|
|
202
|
+
@return the record for this RecordReference
|
|
203
|
+
*/
|
|
204
|
+
load(): Promise<unknown>;
|
|
205
|
+
/**
|
|
206
|
+
Reloads the record if it is already loaded. If the record is not
|
|
207
|
+
loaded it will load the record via `store.findRecord`
|
|
208
|
+
|
|
209
|
+
Example
|
|
210
|
+
|
|
211
|
+
```javascript
|
|
212
|
+
let userRef = store.getReference('user', 1);
|
|
213
|
+
|
|
214
|
+
// or trigger a reload
|
|
215
|
+
userRef.reload().then(...)
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
@public
|
|
219
|
+
@return the record for this RecordReference
|
|
220
|
+
*/
|
|
221
|
+
reload(): Promise<unknown>;
|
|
222
|
+
}
|
|
223
|
+
export declare function getShimClass<T>(store: Store, modelName: T extends TypedRecordInstance ? TypeFromInstance<T> : string): ShimModelClass<T>;
|
|
224
|
+
// Mimics the static apis of @ember-data/model
|
|
225
|
+
export declare class ShimModelClass<T = unknown> implements ModelSchema<T> {
|
|
226
|
+
__store: Store;
|
|
227
|
+
modelName: T extends TypedRecordInstance ? TypeFromInstance<T> : string;
|
|
228
|
+
constructor(store: Store, modelName: T extends TypedRecordInstance ? TypeFromInstance<T> : string);
|
|
229
|
+
get fields(): Map<KeyOrString<T>, "attribute" | "belongsTo" | "hasMany">;
|
|
230
|
+
get attributes(): Map<KeyOrString<T>, LegacyAttributeField>;
|
|
231
|
+
get relationshipsByName(): Map<KeyOrString<T>, LegacyRelationshipField>;
|
|
232
|
+
eachAttribute<K extends KeyOrString<T>>(callback: (key: K, attribute: LegacyAttributeField) => void, binding?: T): void;
|
|
233
|
+
eachRelationship<K extends KeyOrString<T>>(callback: (key: K, relationship: LegacyRelationshipField) => void, binding?: T): void;
|
|
234
|
+
eachTransformedAttribute<K extends KeyOrString<T>>(callback: (key: K, type: string | null) => void, binding?: T): void;
|
|
235
|
+
}
|
package/dist/adapter/error.js
CHANGED
|
@@ -4,6 +4,72 @@ import { macroCondition, getGlobalConfig } from '@embroider/macros';
|
|
|
4
4
|
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
5
5
|
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
## Overview
|
|
9
|
+
|
|
10
|
+
<blockquote style="margin: 1em; padding: .1em 1em .1em 1em; border-left: solid 1em #E34C32; background: #e0e0e0;">
|
|
11
|
+
<p>
|
|
12
|
+
⚠️ <strong>This is LEGACY documentation</strong> for a feature that is no longer encouraged to be used.
|
|
13
|
+
If starting a new app or thinking of implementing a new adapter, consider writing a
|
|
14
|
+
<a href="/ember-data/release/classes/%3CInterface%3E%20Handler">Handler</a> instead to be used with the <a href="https://github.com/emberjs/data/tree/main/packages/request#readme">RequestManager</a>
|
|
15
|
+
</p>
|
|
16
|
+
</blockquote>
|
|
17
|
+
|
|
18
|
+
An `AdapterError` is used by an adapter to signal that an error occurred
|
|
19
|
+
during a request to an external API. It indicates a generic error, and
|
|
20
|
+
subclasses are used to indicate specific error states.
|
|
21
|
+
|
|
22
|
+
To create a custom error to signal a specific error state in communicating
|
|
23
|
+
with an external API, extend the `AdapterError`. For example, if the
|
|
24
|
+
external API exclusively used HTTP `503 Service Unavailable` to indicate
|
|
25
|
+
it was closed for maintenance:
|
|
26
|
+
|
|
27
|
+
```js [app/adapters/maintenance-error.js]
|
|
28
|
+
import AdapterError from '@ember-data/adapter/error';
|
|
29
|
+
|
|
30
|
+
export default AdapterError.extend({ message: "Down for maintenance." });
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
This error would then be returned by an adapter's `handleResponse` method:
|
|
34
|
+
|
|
35
|
+
```js [app/adapters/application.js]
|
|
36
|
+
import JSONAPIAdapter from '@ember-data/adapter/json-api';
|
|
37
|
+
import MaintenanceError from './maintenance-error';
|
|
38
|
+
|
|
39
|
+
export default class ApplicationAdapter extends JSONAPIAdapter {
|
|
40
|
+
handleResponse(status) {
|
|
41
|
+
if (503 === status) {
|
|
42
|
+
return new MaintenanceError();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return super.handleResponse(...arguments);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
And can then be detected in an application and used to send the user to an
|
|
51
|
+
`under-maintenance` route:
|
|
52
|
+
|
|
53
|
+
```js [app/routes/application.js]
|
|
54
|
+
import MaintenanceError from '../adapters/maintenance-error';
|
|
55
|
+
|
|
56
|
+
export default class ApplicationRoute extends Route {
|
|
57
|
+
actions: {
|
|
58
|
+
error(error, transition) {
|
|
59
|
+
if (error instanceof MaintenanceError) {
|
|
60
|
+
this.transitionTo('under-maintenance');
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// ...other error handling logic
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
@class AdapterError
|
|
71
|
+
@public
|
|
72
|
+
*/
|
|
7
73
|
function _AdapterError(errors, message = 'Adapter operation failed') {
|
|
8
74
|
this.isAdapterError = true;
|
|
9
75
|
const error = Error.call(this, message);
|
package/dist/adapter/rest.js
CHANGED
|
@@ -776,7 +776,7 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
776
776
|
if (this.isSuccess(status, headers, payload)) {
|
|
777
777
|
return payload;
|
|
778
778
|
} else if (this.isInvalid(status, headers, payload)) {
|
|
779
|
-
// @ts-expect-error needs cast to
|
|
779
|
+
// @ts-expect-error needs cast to ApiError
|
|
780
780
|
return new InvalidError(typeof payload === 'object' && 'errors' in payload ? payload.errors : undefined);
|
|
781
781
|
}
|
|
782
782
|
const errors = this.normalizeErrorResponse(status, headers, payload);
|
package/dist/compat/builders.js
CHANGED
|
@@ -1,28 +1,8 @@
|
|
|
1
1
|
import { SkipCache } from '@warp-drive/core/types/request';
|
|
2
|
-
import {
|
|
3
|
-
import { dasherize } from '@warp-drive/utilities/string';
|
|
2
|
+
import { n as normalizeModelName, i as isMaybeIdentifier } from "../utils-Cqw9eRj5.js";
|
|
4
3
|
import { macroCondition, getGlobalConfig } from '@embroider/macros';
|
|
5
4
|
import { ensureStringId, constructResource } from '@warp-drive/core/store/-private';
|
|
6
5
|
import { storeFor, recordIdentifierFor } from '@warp-drive/core';
|
|
7
|
-
function isMaybeIdentifier(maybeIdentifier) {
|
|
8
|
-
return Boolean(maybeIdentifier !== null && typeof maybeIdentifier === 'object' && ('id' in maybeIdentifier && 'type' in maybeIdentifier && maybeIdentifier.id && maybeIdentifier.type || maybeIdentifier.lid));
|
|
9
|
-
}
|
|
10
|
-
function normalizeModelName(type) {
|
|
11
|
-
if (macroCondition(getGlobalConfig().WarpDrive.deprecations.DEPRECATE_NON_STRICT_TYPES)) {
|
|
12
|
-
const result = dasherize(type);
|
|
13
|
-
deprecate(`The resource type '${type}' is not normalized. Update your application code to use '${result}' instead of '${type}'.`, result === type, {
|
|
14
|
-
id: 'ember-data:deprecate-non-strict-types',
|
|
15
|
-
until: '6.0',
|
|
16
|
-
for: 'ember-data',
|
|
17
|
-
since: {
|
|
18
|
-
available: '4.13',
|
|
19
|
-
enabled: '5.3'
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
return result;
|
|
23
|
-
}
|
|
24
|
-
return type;
|
|
25
|
-
}
|
|
26
6
|
|
|
27
7
|
/**
|
|
28
8
|
This function builds a request config to perform a `findAll` request for the given type.
|