@warp-drive/legacy 5.7.0-alpha.1 → 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.d.ts +1 -0
- package/declarations/model/migration-support.d.ts +1 -1
- package/declarations/store/-private.d.ts +7 -7
- package/dist/adapter/error.js +66 -0
- package/dist/adapter/rest.js +1 -1
- package/dist/model/migration-support.js +7 -2
- 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 {};
|
|
@@ -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";
|
|
@@ -249,7 +249,7 @@ export declare class DelegatingSchemaService implements SchemaService {
|
|
|
249
249
|
CAUTION_MEGA_DANGER_ZONE_resourceExtensions(resource: StableRecordIdentifier | {
|
|
250
250
|
type: string;
|
|
251
251
|
}): null | ProcessedExtension["features"];
|
|
252
|
-
CAUTION_MEGA_DANGER_ZONE_objectExtensions(field: ExtensibleField): null | ProcessedExtension["features"];
|
|
252
|
+
CAUTION_MEGA_DANGER_ZONE_objectExtensions(field: ExtensibleField, resolvedType: string | null): null | ProcessedExtension["features"];
|
|
253
253
|
CAUTION_MEGA_DANGER_ZONE_arrayExtensions(field: ExtensibleField): null | ProcessedExtension["features"];
|
|
254
254
|
/**
|
|
255
255
|
* This is an internal method used to register behaviors for legacy mode.
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { type InstanceCache } from "@warp-drive/core/store/-private";
|
|
2
2
|
import type { StableNewRecordIdentifier, StableRecordIdentifier } from "@warp-drive/core/types/identifier";
|
|
3
3
|
import type { Value } from "@warp-drive/core/types/json/raw";
|
|
4
|
-
import type {
|
|
4
|
+
import type { OpaqueRecordInstance, TypedRecordInstance, TypeFromInstance } from "@warp-drive/core/types/record";
|
|
5
5
|
import type { LegacyAttributeField, LegacyRelationshipField } from "@warp-drive/core/types/schema/fields";
|
|
6
6
|
import type { SingleResourceDocument } from "@warp-drive/core/types/spec/json-api-raw";
|
|
7
7
|
import type { Store } from "../store.js";
|
|
8
8
|
export declare function preloadData(store: Store, identifier: StableNewRecordIdentifier, preload: Record<string, Value>): void;
|
|
9
|
-
export interface BaseFinderOptions
|
|
9
|
+
export interface BaseFinderOptions {
|
|
10
10
|
reload?: boolean;
|
|
11
11
|
backgroundReload?: boolean;
|
|
12
|
-
include?:
|
|
12
|
+
include?: string | string[];
|
|
13
13
|
adapterOptions?: Record<string, unknown>;
|
|
14
14
|
}
|
|
15
|
-
export interface FindRecordOptions
|
|
15
|
+
export interface FindRecordOptions extends BaseFinderOptions {
|
|
16
16
|
/**
|
|
17
17
|
* Data to preload into the store before the request is made.
|
|
18
18
|
* This feature is *highly* discouraged and has no corresponding
|
|
@@ -31,9 +31,9 @@ export interface FindRecordOptions<T = unknown> extends BaseFinderOptions<T> {
|
|
|
31
31
|
preload?: Record<string, Value>;
|
|
32
32
|
}
|
|
33
33
|
export type QueryOptions = { [K in string | "adapterOptions"]? : K extends "adapterOptions" ? Record<string, unknown> : unknown };
|
|
34
|
-
export type FindAllOptions
|
|
35
|
-
export type LegacyResourceQuery
|
|
36
|
-
include?:
|
|
34
|
+
export type FindAllOptions = BaseFinderOptions;
|
|
35
|
+
export type LegacyResourceQuery = {
|
|
36
|
+
include?: string | string[];
|
|
37
37
|
[key: string]: Value | undefined;
|
|
38
38
|
};
|
|
39
39
|
export type KeyOrString<T> = keyof T & string extends never ? string : keyof T & string;
|
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);
|
|
@@ -310,27 +310,32 @@ function registerDerivations(schema) {
|
|
|
310
310
|
schema._registerMode('@legacy', {
|
|
311
311
|
belongsTo: {
|
|
312
312
|
get(store, record, cacheKey, field) {
|
|
313
|
+
// FIXME field.name here should likely be field.sourceKey || field.name
|
|
313
314
|
return lookupLegacySupport(record).getBelongsTo(field.name);
|
|
314
315
|
},
|
|
315
316
|
set(store, record, cacheKey, field, value) {
|
|
316
317
|
store._join(() => {
|
|
318
|
+
// FIXME field.name here should likely be field.sourceKey || field.name
|
|
317
319
|
lookupLegacySupport(record).setDirtyBelongsTo(field.name, value);
|
|
318
320
|
});
|
|
319
321
|
}
|
|
320
322
|
},
|
|
321
323
|
hasMany: {
|
|
322
324
|
get(store, record, cacheKey, field) {
|
|
325
|
+
// FIXME field.name here should likely be field.sourceKey || field.name
|
|
323
326
|
return lookupLegacySupport(record).getHasMany(field.name);
|
|
324
327
|
},
|
|
325
328
|
set(store, record, cacheKey, field, value) {
|
|
326
329
|
store._join(() => {
|
|
327
330
|
const support = lookupLegacySupport(record);
|
|
331
|
+
// FIXME field.name here should likely be field.sourceKey || field.name
|
|
328
332
|
const manyArray = support.getManyArray(field.name);
|
|
329
333
|
manyArray.splice(0, manyArray.length, ...value);
|
|
330
334
|
});
|
|
331
335
|
},
|
|
332
336
|
notify(store, record, cacheKey, field) {
|
|
333
337
|
const support = lookupLegacySupport(record);
|
|
338
|
+
// FIXME field.name here should likely be field.sourceKey || field.name
|
|
334
339
|
const manyArray = support && support._manyArrayCache[field.name];
|
|
335
340
|
const hasPromise = support && support._relationshipPromisesCache[field.name];
|
|
336
341
|
if (manyArray && hasPromise) {
|
|
@@ -480,8 +485,8 @@ class DelegatingSchemaService {
|
|
|
480
485
|
CAUTION_MEGA_DANGER_ZONE_resourceExtensions(resource) {
|
|
481
486
|
return this._preferred.CAUTION_MEGA_DANGER_ZONE_resourceExtensions(resource);
|
|
482
487
|
}
|
|
483
|
-
CAUTION_MEGA_DANGER_ZONE_objectExtensions(field) {
|
|
484
|
-
return this._preferred.CAUTION_MEGA_DANGER_ZONE_objectExtensions(field);
|
|
488
|
+
CAUTION_MEGA_DANGER_ZONE_objectExtensions(field, resolvedType) {
|
|
489
|
+
return this._preferred.CAUTION_MEGA_DANGER_ZONE_objectExtensions(field, resolvedType);
|
|
485
490
|
}
|
|
486
491
|
CAUTION_MEGA_DANGER_ZONE_arrayExtensions(field) {
|
|
487
492
|
return this._preferred.CAUTION_MEGA_DANGER_ZONE_arrayExtensions(field);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@warp-drive/legacy",
|
|
3
|
-
"version": "5.7.0-alpha.
|
|
3
|
+
"version": "5.7.0-alpha.10",
|
|
4
4
|
"description": "Decommissioned Packages for WarpDrive | Things your app might still want to maintain use of for a little longer.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ember-addon"
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"@warp-drive/core": "5.7.0-alpha.
|
|
36
|
-
"@warp-drive/utilities": "5.7.0-alpha.
|
|
35
|
+
"@warp-drive/core": "5.7.0-alpha.10",
|
|
36
|
+
"@warp-drive/utilities": "5.7.0-alpha.10"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@embroider/macros": "^1.16.12"
|
|
@@ -43,9 +43,9 @@
|
|
|
43
43
|
"@babel/plugin-transform-typescript": "^7.27.0",
|
|
44
44
|
"@babel/preset-typescript": "^7.27.0",
|
|
45
45
|
"@types/jquery": "^3.5.32",
|
|
46
|
-
"@warp-drive/internal-config": "5.7.0-alpha.
|
|
47
|
-
"@warp-drive/core": "5.7.0-alpha.
|
|
48
|
-
"@warp-drive/utilities": "5.7.0-alpha.
|
|
46
|
+
"@warp-drive/internal-config": "5.7.0-alpha.10",
|
|
47
|
+
"@warp-drive/core": "5.7.0-alpha.10",
|
|
48
|
+
"@warp-drive/utilities": "5.7.0-alpha.10",
|
|
49
49
|
"ember-source": "~6.3.0",
|
|
50
50
|
"decorator-transforms": "^2.3.0",
|
|
51
51
|
"expect-type": "^1.2.1",
|