@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
|
@@ -10,22 +10,66 @@ import type { MixtBuildURLMixin } from "./-private/build-url-mixin.js";
|
|
|
10
10
|
import type { FastBoot } from "./-private/fastboot-interface.js";
|
|
11
11
|
import { AdapterError } from "./error.js";
|
|
12
12
|
type Payload = Error | Record<string, unknown> | unknown[] | string | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* The query params built by {@link RESTAdapter.buildQuery | buildQuery} for a
|
|
15
|
+
* `findAll`/`findRecord` request.
|
|
16
|
+
*/
|
|
13
17
|
export type QueryState = {
|
|
18
|
+
/**
|
|
19
|
+
* the relationship paths to sideload
|
|
20
|
+
*/
|
|
14
21
|
include?: unknown;
|
|
22
|
+
/**
|
|
23
|
+
* a value used to request only records updated since the given value
|
|
24
|
+
*/
|
|
15
25
|
since?: unknown;
|
|
16
26
|
};
|
|
27
|
+
/**
|
|
28
|
+
* The options passed to the native `fetch` API by {@link RESTAdapter._fetchRequest | _fetchRequest}.
|
|
29
|
+
*/
|
|
17
30
|
export interface FetchRequestInit extends RequestInit {
|
|
31
|
+
/**
|
|
32
|
+
* the url to request
|
|
33
|
+
*/
|
|
18
34
|
url: string;
|
|
35
|
+
/**
|
|
36
|
+
* the HTTP method to use
|
|
37
|
+
*/
|
|
19
38
|
method: HTTPMethod;
|
|
39
|
+
/**
|
|
40
|
+
* the HTTP method to use, duplicated for jQuery/fetch option compatibility
|
|
41
|
+
*/
|
|
20
42
|
type: HTTPMethod;
|
|
21
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* The options passed to jQuery's `$.ajax` by {@link RESTAdapter._ajaxRequest | _ajaxRequest}.
|
|
46
|
+
*/
|
|
22
47
|
export interface JQueryRequestInit extends JQueryAjaxSettings {
|
|
48
|
+
/**
|
|
49
|
+
* the url to request
|
|
50
|
+
*/
|
|
23
51
|
url: string;
|
|
52
|
+
/**
|
|
53
|
+
* the HTTP method to use
|
|
54
|
+
*/
|
|
24
55
|
method: HTTPMethod;
|
|
56
|
+
/**
|
|
57
|
+
* the HTTP method to use, duplicated for jQuery/fetch option compatibility
|
|
58
|
+
*/
|
|
25
59
|
type: HTTPMethod;
|
|
26
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* A minimal description of an in-flight request, used for building
|
|
63
|
+
* error messages when a request fails.
|
|
64
|
+
*/
|
|
27
65
|
export type RequestData = {
|
|
66
|
+
/**
|
|
67
|
+
* the url that was requested
|
|
68
|
+
*/
|
|
28
69
|
url: string;
|
|
70
|
+
/**
|
|
71
|
+
* the HTTP method that was used
|
|
72
|
+
*/
|
|
29
73
|
method: HTTPMethod;
|
|
30
74
|
[key: string]: unknown;
|
|
31
75
|
};
|
|
@@ -253,9 +297,21 @@ return {
|
|
|
253
297
|
@public
|
|
254
298
|
*/
|
|
255
299
|
declare class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
300
|
+
/**
|
|
301
|
+
* @private
|
|
302
|
+
*/
|
|
256
303
|
_fastboot: FastBoot;
|
|
304
|
+
/**
|
|
305
|
+
* @private
|
|
306
|
+
*/
|
|
257
307
|
_coalesceFindRequests: boolean;
|
|
308
|
+
/**
|
|
309
|
+
* See "Host customization" above.
|
|
310
|
+
*/
|
|
258
311
|
host: string | null;
|
|
312
|
+
/**
|
|
313
|
+
* See "Namespace customization" above.
|
|
314
|
+
*/
|
|
259
315
|
namespace: string | null;
|
|
260
316
|
/**
|
|
261
317
|
This property allows ajax to still be used instead when `false`.
|
|
@@ -264,8 +320,19 @@ declare class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
264
320
|
@public
|
|
265
321
|
*/
|
|
266
322
|
useFetch: boolean;
|
|
323
|
+
/**
|
|
324
|
+
* The `Content-Type` header used when serializing request bodies
|
|
325
|
+
* that don't otherwise specify one.
|
|
326
|
+
*/
|
|
267
327
|
_defaultContentType: string;
|
|
328
|
+
/**
|
|
329
|
+
* The FastBoot service instance, if running in a FastBoot environment.
|
|
330
|
+
* Lazily looked up on first access.
|
|
331
|
+
*/
|
|
268
332
|
get fastboot(): FastBoot;
|
|
333
|
+
/**
|
|
334
|
+
* Sets the FastBoot service instance to use.
|
|
335
|
+
*/
|
|
269
336
|
set fastboot(value: FastBoot);
|
|
270
337
|
/**
|
|
271
338
|
By default, the RESTAdapter will send the query params sorted alphabetically to the
|
|
@@ -592,6 +659,13 @@ declare class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
592
659
|
@private
|
|
593
660
|
*/
|
|
594
661
|
_stripIDFromURL(store: Store, snapshot: Snapshot): string;
|
|
662
|
+
/**
|
|
663
|
+
* The maximum URL length to allow when coalescing `findRecord` requests
|
|
664
|
+
* into a single `findMany` request via {@link RESTAdapter.groupRecordsForFindMany | groupRecordsForFindMany}.
|
|
665
|
+
* Requests that would exceed this length are split into multiple groups.
|
|
666
|
+
*
|
|
667
|
+
* See http://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers
|
|
668
|
+
*/
|
|
595
669
|
maxURLLength: number;
|
|
596
670
|
/**
|
|
597
671
|
Organize records into groups, each of which is to be passed to separate
|
|
@@ -244,7 +244,13 @@ included REST adapter.
|
|
|
244
244
|
@public
|
|
245
245
|
*/
|
|
246
246
|
export declare class Adapter extends EmberObject implements MinimumAdapterInterface {
|
|
247
|
+
/**
|
|
248
|
+
* The Store service instance that owns this Adapter.
|
|
249
|
+
*/
|
|
247
250
|
store: Store;
|
|
251
|
+
/**
|
|
252
|
+
* @private
|
|
253
|
+
*/
|
|
248
254
|
_coalesceFindRequests: boolean;
|
|
249
255
|
/**
|
|
250
256
|
The `findRecord()` method is invoked when the store is asked for a record that
|
|
@@ -26,7 +26,6 @@ To that end, these builders are deprecated and will be removed in a future versi
|
|
|
26
26
|
@deprecated
|
|
27
27
|
@public
|
|
28
28
|
@param type the name of the resource
|
|
29
|
-
@param query a query to be used by the adapter
|
|
30
29
|
@param options optional, may include `adapterOptions` hash which will be passed to adapter.findAll
|
|
31
30
|
@return request config
|
|
32
31
|
*/
|
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
import { type default as EmberObject } from "@ember/object";
|
|
2
2
|
import type { CAUTION_MEGA_DANGER_ZONE_Extension } from "@warp-drive/core/reactive";
|
|
3
3
|
declare const EmberObjectMethods: readonly ["addObserver", "cacheFor", "decrementProperty", "get", "getProperties", "incrementProperty", "notifyPropertyChange", "removeObserver", "set", "setProperties", "toggleProperty"];
|
|
4
|
+
/**
|
|
5
|
+
* A schema extension that adds the classic `EmberObject` API (`get`, `set`,
|
|
6
|
+
* `getProperties`, `setProperties`, `incrementProperty`, `decrementProperty`,
|
|
7
|
+
* `toggleProperty`, `notifyPropertyChange`, `addObserver`, `removeObserver`)
|
|
8
|
+
* to reactive array resources.
|
|
9
|
+
*/
|
|
4
10
|
export declare const EmberObjectArrayExtension: CAUTION_MEGA_DANGER_ZONE_Extension;
|
|
11
|
+
/**
|
|
12
|
+
* A schema extension that adds the classic `EmberObject` API (`get`, `set`,
|
|
13
|
+
* `getProperties`, `setProperties`, `incrementProperty`, `decrementProperty`,
|
|
14
|
+
* `toggleProperty`, `notifyPropertyChange`, `addObserver`, `removeObserver`)
|
|
15
|
+
* to reactive object resources.
|
|
16
|
+
*/
|
|
5
17
|
export declare const EmberObjectExtension: CAUTION_MEGA_DANGER_ZONE_Extension;
|
|
6
18
|
declare const EmberArrayLikeFeatures: {
|
|
7
19
|
addObject<T>(this: T[], obj: T): T[];
|
|
@@ -46,14 +58,42 @@ declare const EmberArrayLikeFeatures: {
|
|
|
46
58
|
firstObject: unknown;
|
|
47
59
|
lastObject: unknown;
|
|
48
60
|
};
|
|
61
|
+
/**
|
|
62
|
+
* A schema extension that adds Ember's classic `MutableArray`/`Enumerable`
|
|
63
|
+
* style methods (`pushObject`, `removeObject`, `mapBy`, `filterBy`,
|
|
64
|
+
* `sortBy`, `firstObject`, `lastObject`, etc.) to reactive array resources.
|
|
65
|
+
*/
|
|
49
66
|
export declare const EmberArrayLikeExtension: CAUTION_MEGA_DANGER_ZONE_Extension;
|
|
67
|
+
/**
|
|
68
|
+
* Extracts the element type of an array type, or `never` if `T` is not an array.
|
|
69
|
+
*/
|
|
50
70
|
export type ArrayType<T> = T extends ReadonlyArray<infer U> ? U : never;
|
|
71
|
+
/**
|
|
72
|
+
* Adds the classic `EmberObject` API (as registered by {@link EmberObjectExtension}/
|
|
73
|
+
* {@link EmberObjectArrayExtension}) to the type of a reactive resource.
|
|
74
|
+
*/
|
|
51
75
|
export type WithEmberObject<T> = T & Pick<T & EmberObject, ArrayType<typeof EmberObjectMethods>>;
|
|
76
|
+
/**
|
|
77
|
+
* Adds Ember's classic array-like API (as registered by {@link EmberArrayLikeExtension})
|
|
78
|
+
* to the type of a reactive array resource.
|
|
79
|
+
*/
|
|
52
80
|
export type WithArrayLike<T> = T extends Array<infer U> ? U & Omit<typeof EmberArrayLikeFeatures, "firstObject" | "lastObject"> & {
|
|
81
|
+
/**
|
|
82
|
+
* the first member of the array, or `undefined` if the array is empty
|
|
83
|
+
*/
|
|
53
84
|
firstObject: T | undefined;
|
|
85
|
+
/**
|
|
86
|
+
* the last member of the array, or `undefined` if the array is empty
|
|
87
|
+
*/
|
|
54
88
|
lastObject: T | undefined;
|
|
55
89
|
} : T[] & Omit<typeof EmberArrayLikeFeatures, "firstObject" | "lastObject"> & {
|
|
90
|
+
/**
|
|
91
|
+
* the first member of the array, or `undefined` if the array is empty
|
|
92
|
+
*/
|
|
56
93
|
firstObject: T | undefined;
|
|
94
|
+
/**
|
|
95
|
+
* the last member of the array, or `undefined` if the array is empty
|
|
96
|
+
*/
|
|
57
97
|
lastObject: T | undefined;
|
|
58
98
|
};
|
|
59
99
|
export {};
|
|
@@ -1,2 +1,9 @@
|
|
|
1
1
|
import type { Handler } from "@warp-drive/core/request";
|
|
2
|
+
/**
|
|
3
|
+
* A {@link Handler} that fulfills legacy `findRecord`/`findAll`/`query`/
|
|
4
|
+
* `queryRecord`/`findBelongsTo`/`findHasMany`/`createRecord`/`updateRecord`/
|
|
5
|
+
* `deleteRecord` requests using the store's configured {@link MinimumAdapterInterface | adapter}
|
|
6
|
+
* and {@link MinimumSerializerInterface | serializer}, passing any other
|
|
7
|
+
* request through to the next handler unchanged.
|
|
8
|
+
*/
|
|
2
9
|
export declare const LegacyNetworkHandler: Handler;
|
|
@@ -5,6 +5,10 @@ import type { LegacyRelationshipField as RelationshipSchema } from "@warp-drive/
|
|
|
5
5
|
import type { Snapshot } from "./snapshot.js";
|
|
6
6
|
import type { SnapshotRecordArray } from "./snapshot-record-array.js";
|
|
7
7
|
type Group = Snapshot[];
|
|
8
|
+
/**
|
|
9
|
+
* The raw payload shape returned by a legacy adapter's request methods,
|
|
10
|
+
* prior to being normalized by a {@link MinimumSerializerInterface}.
|
|
11
|
+
*/
|
|
8
12
|
export type AdapterPayload = Record<string, unknown> | unknown[];
|
|
9
13
|
/**
|
|
10
14
|
* :::danger
|
|
@@ -4,7 +4,14 @@ import type { ObjectValue } from "@warp-drive/core/types/json/raw";
|
|
|
4
4
|
import type { JsonApiDocument, SingleResourceDocument } from "@warp-drive/core/types/spec/json-api-raw";
|
|
5
5
|
import type { AdapterPayload } from "./minimum-adapter-interface.js";
|
|
6
6
|
import type { Snapshot } from "./snapshot.js";
|
|
7
|
+
/**
|
|
8
|
+
* Options accepted by {@link MinimumSerializerInterface.serialize | serialize}
|
|
9
|
+
* and related legacy serializer methods.
|
|
10
|
+
*/
|
|
7
11
|
export type SerializerOptions = {
|
|
12
|
+
/**
|
|
13
|
+
* whether the resource's id should be included in the serialized output
|
|
14
|
+
*/
|
|
8
15
|
includeId?: boolean;
|
|
9
16
|
};
|
|
10
17
|
export type RequestType = "findRecord" | "queryRecord" | "findAll" | "findBelongsTo" | "findHasMany" | "findMany" | "query" | "createRecord" | "deleteRecord" | "updateRecord";
|
|
@@ -84,7 +84,18 @@ export declare function formattedType<T extends string>(type: T | string): T;
|
|
|
84
84
|
export declare function formattedId(id: string | number): string;
|
|
85
85
|
export declare function formattedId(id: null): null;
|
|
86
86
|
export declare function formattedId(id: string | number | null): string | null;
|
|
87
|
+
/**
|
|
88
|
+
* Like {@link formattedId}, but asserts that `id` is not `null` rather
|
|
89
|
+
* than allowing and passing through `null`.
|
|
90
|
+
*
|
|
91
|
+
* @public
|
|
92
|
+
*/
|
|
87
93
|
export declare function expectId(id: string | number): string;
|
|
94
|
+
/**
|
|
95
|
+
* Throws, since `id` is `null`.
|
|
96
|
+
*
|
|
97
|
+
* @public
|
|
98
|
+
*/
|
|
88
99
|
export declare function expectId(id: null): never;
|
|
89
100
|
/**
|
|
90
101
|
* Compares two types for strict equality, converting them to
|
package/declarations/compat.d.ts
CHANGED
|
@@ -19,11 +19,35 @@ export interface LegacyStoreCompat extends Store {
|
|
|
19
19
|
* @private
|
|
20
20
|
*/
|
|
21
21
|
_fetchManager: FetchManager;
|
|
22
|
+
/**
|
|
23
|
+
* Returns the adapter instance for the given model type, instantiating
|
|
24
|
+
* it (and caching the instance) if necessary. See {@link adapterFor}.
|
|
25
|
+
*/
|
|
22
26
|
adapterFor(this: Store, modelName: string): MinimumAdapterInterface;
|
|
27
|
+
/**
|
|
28
|
+
* Same as the single-argument overload, but returns `undefined` instead
|
|
29
|
+
* of throwing/asserting when `_allowMissing` is `true` and no adapter
|
|
30
|
+
* is found.
|
|
31
|
+
*/
|
|
23
32
|
adapterFor(this: Store, modelName: string, _allowMissing: true): MinimumAdapterInterface | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Returns the serializer instance for the given model type, instantiating
|
|
35
|
+
* it (and caching the instance) if necessary. See {@link serializerFor}.
|
|
36
|
+
*/
|
|
24
37
|
serializerFor<K extends string>(modelName: K, _allowMissing?: boolean): MinimumSerializerInterface | null;
|
|
38
|
+
/**
|
|
39
|
+
* Normalizes a payload for the given model type using its serializer.
|
|
40
|
+
* See {@link normalize}.
|
|
41
|
+
*/
|
|
25
42
|
normalize(modelName: string, payload: ObjectValue): ObjectValue;
|
|
43
|
+
/**
|
|
44
|
+
* Pushes a payload into the store using the appropriate serializer to
|
|
45
|
+
* normalize it first. See {@link pushPayload}.
|
|
46
|
+
*/
|
|
26
47
|
pushPayload(modelName: string, payload: ObjectValue): void;
|
|
48
|
+
/**
|
|
49
|
+
* Serializes a record using its serializer. See {@link serializeRecord}.
|
|
50
|
+
*/
|
|
27
51
|
serializeRecord(record: unknown, options?: SerializerOptions): unknown;
|
|
28
52
|
/**
|
|
29
53
|
* @private
|
|
@@ -153,5 +177,13 @@ store.pushPayload('post', pushData); // Will use the post serializer
|
|
|
153
177
|
@param inputPayload
|
|
154
178
|
*/
|
|
155
179
|
export declare function pushPayload(this: Store, modelName: string, inputPayload: ObjectValue): void;
|
|
180
|
+
/**
|
|
181
|
+
* Serializes a record using the store's legacy network layer, as with
|
|
182
|
+
* {@link LegacyStoreCompat.serializeRecord | store.serializeRecord}.
|
|
183
|
+
*/
|
|
156
184
|
export declare function serializeRecord(this: Store, record: unknown, options?: SerializerOptions): unknown;
|
|
185
|
+
/**
|
|
186
|
+
* Destroys any adapters/serializers the legacy network layer has created
|
|
187
|
+
* for this store, invoked when the store itself is destroyed.
|
|
188
|
+
*/
|
|
157
189
|
export declare function cleanup(this: Store): void;
|
package/declarations/index.d.ts
CHANGED
|
@@ -25,6 +25,12 @@ interface _LegacyStoreSetupOptions<T extends Cache> extends Omit<StoreSetupOptio
|
|
|
25
25
|
*/
|
|
26
26
|
modelFragments?: boolean;
|
|
27
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Setup options for a legacy store configured to use `Model` with `linksMode`
|
|
30
|
+
* enabled, meaning no legacy adapter/serializer request infrastructure is required.
|
|
31
|
+
*
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
28
34
|
export interface LegacyModelStoreSetupOptions<T extends Cache> extends _LegacyStoreSetupOptions<T> {
|
|
29
35
|
/**
|
|
30
36
|
* If true, it is presumed that no requests require use of the LegacyNetworkHandler
|
|
@@ -45,6 +51,13 @@ export interface LegacyModelStoreSetupOptions<T extends Cache> extends _LegacySt
|
|
|
45
51
|
*/
|
|
46
52
|
legacyRequests?: false;
|
|
47
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Setup options for a legacy store configured to use `Model` along with the
|
|
56
|
+
* legacy adapter/serializer network layer, but without the deprecated
|
|
57
|
+
* `store.findRecord`/`findAll`/`query`/etc. request methods.
|
|
58
|
+
*
|
|
59
|
+
* @public
|
|
60
|
+
*/
|
|
48
61
|
export interface LegacyModelAndNetworkStoreSetupOptions<T extends Cache> extends _LegacyStoreSetupOptions<T> {
|
|
49
62
|
/**
|
|
50
63
|
* If true, it is presumed that no requests require use of the LegacyNetworkHandler
|
|
@@ -63,6 +76,13 @@ export interface LegacyModelAndNetworkStoreSetupOptions<T extends Cache> extends
|
|
|
63
76
|
*/
|
|
64
77
|
legacyRequests?: false;
|
|
65
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Setup options for a legacy store configured to use `Model` along with the
|
|
81
|
+
* legacy adapter/serializer network layer and the deprecated
|
|
82
|
+
* `store.findRecord`/`findAll`/`query`/etc. request methods.
|
|
83
|
+
*
|
|
84
|
+
* @public
|
|
85
|
+
*/
|
|
66
86
|
export interface LegacyModelAndNetworkAndRequestStoreSetupOptions<T extends Cache> extends _LegacyStoreSetupOptions<T> {
|
|
67
87
|
/**
|
|
68
88
|
* If true, it is presumed that no requests require use of the LegacyNetworkHandler
|
|
@@ -81,14 +101,136 @@ export interface LegacyModelAndNetworkAndRequestStoreSetupOptions<T extends Cach
|
|
|
81
101
|
*/
|
|
82
102
|
legacyRequests: true;
|
|
83
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* The available options when setting up the legacy store,
|
|
106
|
+
* one of:
|
|
107
|
+
*
|
|
108
|
+
* - {@link LegacyModelStoreSetupOptions}
|
|
109
|
+
* - {@link LegacyModelAndNetworkStoreSetupOptions}
|
|
110
|
+
* - {@link LegacyModelAndNetworkAndRequestStoreSetupOptions}
|
|
111
|
+
*/
|
|
84
112
|
export type LegacyStoreSetupOptions<T extends Cache = Cache> = LegacyModelStoreSetupOptions<T> | LegacyModelAndNetworkStoreSetupOptions<T> | LegacyModelAndNetworkAndRequestStoreSetupOptions<T>;
|
|
85
113
|
export declare class ConfiguredStore<T extends {
|
|
114
|
+
/**
|
|
115
|
+
* The {@link Cache} implementation this store was configured with.
|
|
116
|
+
*/
|
|
86
117
|
cache: Cache;
|
|
87
118
|
}> extends Store {
|
|
88
119
|
createCache(capabilities: CacheCapabilitiesManager): T["cache"];
|
|
89
120
|
}
|
|
90
121
|
/**
|
|
91
122
|
* Use the legacy store with the given options.
|
|
123
|
+
*
|
|
124
|
+
* See {@link LegacyStoreSetupOptions} for details on the available options.
|
|
125
|
+
*
|
|
126
|
+
* ```ts
|
|
127
|
+
* import { useLegacyStore } from '@warp-drive/legacy';
|
|
128
|
+
* import { JSONAPICache } from '@warp-drive/json-api';
|
|
129
|
+
*
|
|
130
|
+
* export default useLegacyStore({
|
|
131
|
+
* linksMode: false,
|
|
132
|
+
* legacyRequests: true,
|
|
133
|
+
* cache: JSONAPICache,
|
|
134
|
+
* schemas: [],
|
|
135
|
+
* });
|
|
136
|
+
* ```
|
|
137
|
+
*
|
|
138
|
+
* ### Adding Stateful Handlers
|
|
139
|
+
*
|
|
140
|
+
* A request {@link Handler} is sometimes more than a plain object or class
|
|
141
|
+
* with a `request` method — it may need access to a stateful dependency such
|
|
142
|
+
* as an Ember service (an auth token, a feature-flags service, an i18n
|
|
143
|
+
* helper, etc.).
|
|
144
|
+
*
|
|
145
|
+
* A plain class handler that only relies on Ember's `@service` decorator will
|
|
146
|
+
* not work here on its own: the handler is never instantiated *through*
|
|
147
|
+
* Ember's container (it's just `new`'d up), so it has no owner and its
|
|
148
|
+
* `@service` injections would fail to resolve.
|
|
149
|
+
*
|
|
150
|
+
* Instead, give `handlers` a function. It receives the {@link Store} instance
|
|
151
|
+
* being configured, which by the time the function runs already has an owner
|
|
152
|
+
* assigned. Use `getOwner`/`setOwner` from `@ember/owner` to transfer that
|
|
153
|
+
* owner onto your handler instance before returning it, exactly as you would
|
|
154
|
+
* when constructing any other DI-aware object outside of the container:
|
|
155
|
+
*
|
|
156
|
+
* ```ts
|
|
157
|
+
* import { getOwner, setOwner } from '@ember/owner';
|
|
158
|
+
* import { service } from '@ember/service';
|
|
159
|
+
* import { useLegacyStore } from '@warp-drive/legacy';
|
|
160
|
+
* import type { NextFn } from '@warp-drive/core/request';
|
|
161
|
+
* import type { RequestContext } from '@warp-drive/core/types/request';
|
|
162
|
+
* import { JSONAPICache } from '@warp-drive/json-api';
|
|
163
|
+
*
|
|
164
|
+
* class AuthHandler {
|
|
165
|
+
* @service session;
|
|
166
|
+
*
|
|
167
|
+
* request<T>(context: RequestContext, next: NextFn<T>) {
|
|
168
|
+
* const headers = new Headers(context.request.headers);
|
|
169
|
+
* headers.append('Authorization', `Bearer ${this.session.accessToken}`);
|
|
170
|
+
* return next(Object.assign({}, context.request, { headers }));
|
|
171
|
+
* }
|
|
172
|
+
* }
|
|
173
|
+
*
|
|
174
|
+
* export default useLegacyStore({
|
|
175
|
+
* linksMode: false,
|
|
176
|
+
* legacyRequests: true,
|
|
177
|
+
* cache: JSONAPICache,
|
|
178
|
+
* handlers: (store) => {
|
|
179
|
+
* const authHandler = new AuthHandler();
|
|
180
|
+
* setOwner(authHandler, getOwner(store)!);
|
|
181
|
+
* return [authHandler];
|
|
182
|
+
* },
|
|
183
|
+
* });
|
|
184
|
+
* ```
|
|
185
|
+
*
|
|
186
|
+
* The `handlers` function is invoked lazily and only once per store instance,
|
|
187
|
+
* the first time `store.requestManager` is accessed, so it is safe to do
|
|
188
|
+
* owner-dependent setup like this inside of it.
|
|
189
|
+
*
|
|
190
|
+
* ### Accessing the Store from a Handler's Context
|
|
191
|
+
*
|
|
192
|
+
* If a handler only needs to read something *off of the store itself*
|
|
193
|
+
* (its cache, or a property/service you've attached to a custom store
|
|
194
|
+
* subclass) rather than an unrelated Ember service, there is a second,
|
|
195
|
+
* simpler option that requires no DI/`setOwner` wiring at all.
|
|
196
|
+
*
|
|
197
|
+
* Every request issued via {@link Store.request | store.request(...)}
|
|
198
|
+
* automatically carries the originating store along as
|
|
199
|
+
* {@link RequestInfo.store | context.request.store}. Any handler — a plain
|
|
200
|
+
* object, a function-built handler, or a class — can read it directly,
|
|
201
|
+
* without needing the `handlers` callback form shown above:
|
|
202
|
+
*
|
|
203
|
+
* ```ts
|
|
204
|
+
* import { useLegacyStore } from '@warp-drive/legacy';
|
|
205
|
+
* import type { NextFn } from '@warp-drive/core/request';
|
|
206
|
+
* import type { RequestContext } from '@warp-drive/core/types/request';
|
|
207
|
+
* import { JSONAPICache } from '@warp-drive/json-api';
|
|
208
|
+
*
|
|
209
|
+
* const LoggingHandler = {
|
|
210
|
+
* request<T>(context: RequestContext, next: NextFn<T>) {
|
|
211
|
+
* // only present when the request was made via `store.request(...)`
|
|
212
|
+
* const store = context.request.store;
|
|
213
|
+
* if (store) {
|
|
214
|
+
* console.log(`[${store.constructor.name}] ${context.request.url ?? ''}`);
|
|
215
|
+
* }
|
|
216
|
+
* return next(context.request);
|
|
217
|
+
* },
|
|
218
|
+
* };
|
|
219
|
+
*
|
|
220
|
+
* export default useLegacyStore({
|
|
221
|
+
* linksMode: false,
|
|
222
|
+
* legacyRequests: true,
|
|
223
|
+
* cache: JSONAPICache,
|
|
224
|
+
* handlers: [LoggingHandler],
|
|
225
|
+
* });
|
|
226
|
+
* ```
|
|
227
|
+
*
|
|
228
|
+
* The trade-off versus the `getOwner`/`setOwner` pattern above is that
|
|
229
|
+
* `context.request.store` is only populated for requests issued via
|
|
230
|
+
* `store.request(...)`; a request made directly against a
|
|
231
|
+
* {@link RequestManager} won't have it set unless the caller supplies it
|
|
232
|
+
* explicitly, so a handler relying on it should treat it as optional (as
|
|
233
|
+
* `LoggingHandler` does above).
|
|
92
234
|
*/
|
|
93
235
|
export declare function useLegacyStore<T extends Cache>(options: LegacyModelStoreSetupOptions<T>, StoreKlass?: typeof Store): typeof ConfiguredStore<{
|
|
94
236
|
cache: T;
|
|
@@ -36,6 +36,27 @@ export type AttrOptions<DV = PrimitiveValue | object | unknown[]> = {
|
|
|
36
36
|
*
|
|
37
37
|
*/
|
|
38
38
|
defaultValue?: DV extends PrimitiveValue ? DV : () => DV;
|
|
39
|
+
/**
|
|
40
|
+
* The name of the field as returned by the API and inserted into the
|
|
41
|
+
* cache if it differs from the name of the decorated property.
|
|
42
|
+
*
|
|
43
|
+
* For instance, if the API returns:
|
|
44
|
+
*
|
|
45
|
+
* ```ts
|
|
46
|
+
* {
|
|
47
|
+
* attributes: {
|
|
48
|
+
* 'first-name': 'Chris'
|
|
49
|
+
* }
|
|
50
|
+
* }
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* But the app desires to use `record.firstName; // 'Chris'`, then the
|
|
54
|
+
* property should be named `firstName` and `sourceKey` should be set
|
|
55
|
+
* to `'first-name'`.
|
|
56
|
+
*
|
|
57
|
+
* This option is only needed when the value differs from the property name.
|
|
58
|
+
*/
|
|
59
|
+
sourceKey?: string;
|
|
39
60
|
};
|
|
40
61
|
type LooseTransformInstance<
|
|
41
62
|
V,
|
|
@@ -10,6 +10,27 @@ export type RelationshipOptions<
|
|
|
10
10
|
as?: string;
|
|
11
11
|
linksMode?: true;
|
|
12
12
|
resetOnRemoteUpdate?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* The name of the field as returned by the API and inserted into the
|
|
15
|
+
* cache if it differs from the name of the decorated property.
|
|
16
|
+
*
|
|
17
|
+
* For instance, if the API returns:
|
|
18
|
+
*
|
|
19
|
+
* ```ts
|
|
20
|
+
* {
|
|
21
|
+
* relationships: {
|
|
22
|
+
* 'best-friend': { data: { type: 'user', id: '1' } }
|
|
23
|
+
* }
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* But the app desires to use `record.bestFriend`, then the property
|
|
28
|
+
* should be named `bestFriend` and `sourceKey` should be set to
|
|
29
|
+
* `'best-friend'`.
|
|
30
|
+
*
|
|
31
|
+
* This option is only needed when the value differs from the property name.
|
|
32
|
+
*/
|
|
33
|
+
sourceKey?: string;
|
|
13
34
|
};
|
|
14
35
|
export type NoNull<T> = Exclude<T, null>;
|
|
15
36
|
export type RelationshipDecorator<T> = <This>(target: This, key: string, desc?: PropertyDescriptor) => void;
|
|
@@ -2,9 +2,35 @@ import { type Store } from "@warp-drive/core/store/-private";
|
|
|
2
2
|
import type { ResourceKey } from "@warp-drive/core/types/identifier";
|
|
3
3
|
import type { TypeFromInstance } from "@warp-drive/core/types/record";
|
|
4
4
|
import type { Model } from "./model.js";
|
|
5
|
+
/**
|
|
6
|
+
* The `instantiateRecord` hook implementation for use with `Model`. Pass
|
|
7
|
+
* this to your store's `instantiateRecord` method when configuring the
|
|
8
|
+
* store to use `Model` for schema/record instantiation.
|
|
9
|
+
*
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
5
12
|
export declare function instantiateRecord(this: Store, identifier: ResourceKey, createRecordArgs?: {
|
|
6
13
|
[key: string]: unknown;
|
|
7
14
|
}): Model;
|
|
15
|
+
/**
|
|
16
|
+
* The `teardownRecord` hook implementation for use with `Model`. Pass this
|
|
17
|
+
* to your store's `teardownRecord` method when configuring the store to
|
|
18
|
+
* use `Model` for schema/record instantiation.
|
|
19
|
+
*
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
8
22
|
export declare function teardownRecord(record: Model): void;
|
|
23
|
+
/**
|
|
24
|
+
* The `modelFor` implementation for use with `Model`, exposed on the store
|
|
25
|
+
* as `store.modelFor(type)` when the store is configured to use `Model`.
|
|
26
|
+
* Returns the `Model` subclass registered for the given type, if any.
|
|
27
|
+
*
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
9
30
|
export declare function modelFor<T>(type: TypeFromInstance<T>): typeof Model | void;
|
|
31
|
+
/**
|
|
32
|
+
* Overload accepting a raw type string instead of a typed record instance.
|
|
33
|
+
*
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
10
36
|
export declare function modelFor(type: string): typeof Model | void;
|