@warp-drive/legacy 5.7.0-alpha.8 → 5.7.0-beta.0
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/-private/build-url-mixin.d.ts +0 -13
- package/declarations/adapter/-private/utils/continue-on-reject.d.ts +1 -7
- package/declarations/adapter/-private/utils/serialize-query-params.d.ts +0 -4
- package/declarations/adapter/error.d.ts +0 -1
- package/declarations/adapter/rest.d.ts +0 -2
- package/declarations/adapter.d.ts +0 -5
- package/declarations/compat/builders/find-all.d.ts +2 -2
- package/declarations/compat/builders/query.d.ts +2 -2
- package/declarations/compat/builders/save-record.d.ts +3 -3
- package/declarations/compat/legacy-network-handler/fetch-manager.d.ts +24 -17
- package/declarations/compat/legacy-network-handler/identifier-has-id.d.ts +2 -2
- package/declarations/compat/legacy-network-handler/legacy-data-fetch.d.ts +5 -5
- package/declarations/compat/legacy-network-handler/minimum-adapter-interface.d.ts +3 -8
- package/declarations/compat/legacy-network-handler/snapshot-record-array.d.ts +40 -18
- package/declarations/compat/legacy-network-handler/snapshot.d.ts +63 -44
- package/declarations/compat.d.ts +3 -6
- package/declarations/model/-private/attr.d.ts +1 -14
- package/declarations/model/-private/belongs-to.d.ts +0 -11
- package/declarations/model/-private/debug/assert-polymorphic-type.d.ts +2 -14
- package/declarations/model/-private/errors.d.ts +0 -6
- package/declarations/model/-private/has-many.d.ts +0 -4
- package/declarations/model/-private/hooks.d.ts +2 -2
- package/declarations/model/-private/legacy-relationships-support.d.ts +18 -27
- package/declarations/model/-private/model-for-mixin.d.ts +0 -16
- package/declarations/model/-private/model-methods.d.ts +0 -4
- package/declarations/model/-private/model.d.ts +13 -69
- package/declarations/model/-private/notify-changes.d.ts +2 -2
- package/declarations/model/-private/promise-belongs-to.d.ts +0 -6
- package/declarations/model/-private/promise-many-array.d.ts +0 -11
- package/declarations/model/-private/record-state.d.ts +2 -25
- package/declarations/model/-private/references/belongs-to.d.ts +6 -7
- package/declarations/model/-private/references/has-many.d.ts +6 -13
- package/declarations/model/-private/schema-provider.d.ts +6 -10
- package/declarations/model/-private.d.ts +1 -2
- package/declarations/model/migration-support.d.ts +9 -33
- package/declarations/serializer/json-api.d.ts +0 -1
- package/declarations/serializer/json.d.ts +0 -1
- package/declarations/serializer/rest.d.ts +0 -1
- package/declarations/store/-private.d.ts +12 -24
- package/dist/{-private-CKrP0ogQ.js → -private-8UmnAf9J.js} +169 -141
- package/dist/adapter/-private.js +1 -1
- package/dist/adapter/json-api.js +1 -1
- package/dist/adapter/rest.js +1 -1
- package/dist/compat/-private.js +1 -1
- package/dist/compat/builders.js +3 -2
- package/dist/compat.js +7 -2
- package/dist/{errors-BX5wowuz.js → errors-8kD2mSe_.js} +66 -36
- package/dist/model/-private.js +1 -2
- package/dist/model/migration-support.js +7 -4
- package/dist/model.js +13 -11
- package/dist/{schema-provider-Cbnf6sKm.js → schema-provider-DQu4Rjco.js} +62 -26
- package/dist/{serialize-into-hash-Bp58npke.js → serialize-into-hash-CS0MIv4F.js} +2 -1
- package/dist/store.js +8 -6
- package/package.json +15 -15
|
@@ -1,15 +1,5 @@
|
|
|
1
1
|
import Mixin from "@ember/object/mixin";
|
|
2
2
|
import type { Snapshot, SnapshotRecordArray } from "../../compat/-private.js";
|
|
3
|
-
/*
|
|
4
|
-
The structure of this file is such because typing Mixins is hard. Here we've structured it in
|
|
5
|
-
such a way as to maximize the type information that a consumer can utilize. There are simpler
|
|
6
|
-
ways to type a mixin but we would not be able to provide the nice overload signature for buildURL
|
|
7
|
-
*/
|
|
8
|
-
// the interface must fully declare the function signatures that the individual functions
|
|
9
|
-
// will also declare. If instead we try to keep them in sync by doing something like
|
|
10
|
-
// `interface BuildURLMixin { buildURL: typeof buildURL }`
|
|
11
|
-
// then an extending class overwriting one of the methods will break because typescript
|
|
12
|
-
// thinks it is a switch from an instance prop (that is a method) to an instance method.
|
|
13
3
|
export interface BuildURLMixin {
|
|
14
4
|
buildURL(this: MixtBuildURLMixin, modelName: string, id: string, snapshot: Snapshot, requestType: "findRecord"): string;
|
|
15
5
|
buildURL(this: MixtBuildURLMixin, modelName: string, id: null, snapshot: SnapshotRecordArray, requestType: "findAll"): string;
|
|
@@ -36,9 +26,6 @@ export interface BuildURLMixin {
|
|
|
36
26
|
urlPrefix(this: MixtBuildURLMixin, path?: string | null, parentURL?: string): string;
|
|
37
27
|
pathForType(this: MixtBuildURLMixin, modelName: string): string;
|
|
38
28
|
}
|
|
39
|
-
// prevents the final constructed object from needing to add
|
|
40
|
-
// host and namespace which are provided by the final consuming
|
|
41
|
-
// class to the prototype which can result in overwrite errors
|
|
42
29
|
export interface MixtBuildURLMixin extends BuildURLMixin {
|
|
43
30
|
host: string | null;
|
|
44
31
|
namespace: string | null;
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
interface PlainObject {
|
|
2
2
|
[key: string]: string | PlainObject | PlainObject[] | string[];
|
|
3
3
|
}
|
|
4
|
-
/*
|
|
5
|
-
* Helper function that turns the data/body of a request into a query param string.
|
|
6
|
-
* This is directly copied from jQuery.param.
|
|
7
|
-
*/
|
|
8
4
|
export declare function serializeQueryParams(queryParamsObject: PlainObject | string): string;
|
|
9
5
|
export {};
|
|
@@ -71,7 +71,6 @@ wrap the error payload unaltered.
|
|
|
71
71
|
@class InvalidError
|
|
72
72
|
@public
|
|
73
73
|
*/
|
|
74
|
-
// TODO @deprecate extractError documentation
|
|
75
74
|
export type InvalidError = AdapterRequestError<"InvalidError">;
|
|
76
75
|
export declare const InvalidError: AdapterRequestErrorConstructor<InvalidError>;
|
|
77
76
|
/**
|
|
@@ -650,7 +650,6 @@ declare class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
650
650
|
*/
|
|
651
651
|
deleteRecord(store: Store, schema: ModelSchema, snapshot: Snapshot): Promise<AdapterPayload>;
|
|
652
652
|
_stripIDFromURL(store: Store, snapshot: Snapshot): string;
|
|
653
|
-
// http://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers
|
|
654
653
|
maxURLLength: number;
|
|
655
654
|
/**
|
|
656
655
|
Organize records into groups, each of which is to be passed to separate
|
|
@@ -806,7 +805,6 @@ declare class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
806
805
|
*/
|
|
807
806
|
buildQuery(snapshot: Snapshot | SnapshotRecordArray): QueryState;
|
|
808
807
|
}
|
|
809
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
810
808
|
interface RESTAdapter extends MixtBuildURLMixin {}
|
|
811
809
|
/**
|
|
812
810
|
* Helper function that translates the options passed to `jQuery.ajax` into a format that `fetch` expects.
|
|
@@ -277,7 +277,6 @@ export declare class Adapter extends EmberObject implements MinimumAdapterInterf
|
|
|
277
277
|
|
|
278
278
|
@public
|
|
279
279
|
*/
|
|
280
|
-
// @ts-expect-error
|
|
281
280
|
findRecord(store: Store, type: ModelSchema, id: string, snapshot: Snapshot): Promise<AdapterPayload>;
|
|
282
281
|
/**
|
|
283
282
|
The `findAll()` method is used to retrieve all records for a given type.
|
|
@@ -331,7 +330,6 @@ export declare class Adapter extends EmberObject implements MinimumAdapterInterf
|
|
|
331
330
|
|
|
332
331
|
@public
|
|
333
332
|
*/
|
|
334
|
-
// @ts-expect-error
|
|
335
333
|
query(store: Store, type: ModelSchema, query: Record<string, unknown>): Promise<AdapterPayload>;
|
|
336
334
|
/**
|
|
337
335
|
The `queryRecord()` method is invoked when the store is asked for a single
|
|
@@ -448,7 +446,6 @@ export declare class Adapter extends EmberObject implements MinimumAdapterInterf
|
|
|
448
446
|
|
|
449
447
|
@public
|
|
450
448
|
*/
|
|
451
|
-
// @ts-expect-error
|
|
452
449
|
createRecord(store: Store, type: ModelSchema, snapshot: Snapshot): Promise<AdapterPayload>;
|
|
453
450
|
/**
|
|
454
451
|
Implement this method in a subclass to handle the updating of
|
|
@@ -499,7 +496,6 @@ export declare class Adapter extends EmberObject implements MinimumAdapterInterf
|
|
|
499
496
|
@return {Promise} promise
|
|
500
497
|
@public
|
|
501
498
|
*/
|
|
502
|
-
// @ts-expect-error
|
|
503
499
|
updateRecord(store: Store, type: ModelSchema, snapshot: Snapshot): Promise<AdapterPayload>;
|
|
504
500
|
/**
|
|
505
501
|
Implement this method in a subclass to handle the deletion of
|
|
@@ -542,7 +538,6 @@ export declare class Adapter extends EmberObject implements MinimumAdapterInterf
|
|
|
542
538
|
@return {Promise} promise
|
|
543
539
|
@public
|
|
544
540
|
*/
|
|
545
|
-
// @ts-expect-error
|
|
546
541
|
deleteRecord(store: Store, type: ModelSchema, snapshot: Snapshot): Promise<AdapterPayload>;
|
|
547
542
|
/**
|
|
548
543
|
By default the store will try to coalesce all `findRecord` calls within the same runloop
|
|
@@ -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 {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type StoreRequestInput } from "@warp-drive/core";
|
|
2
|
-
import type {
|
|
2
|
+
import type { ResourceKey } from "@warp-drive/core/types";
|
|
3
3
|
import type { TypedRecordInstance, TypeFromInstance } from "@warp-drive/core/types/record";
|
|
4
4
|
import type { RequestSignature } from "@warp-drive/core/types/symbols";
|
|
5
5
|
type SaveRecordRequestInput<
|
|
@@ -8,10 +8,10 @@ type SaveRecordRequestInput<
|
|
|
8
8
|
> = StoreRequestInput & {
|
|
9
9
|
op: "createRecord" | "deleteRecord" | "updateRecord";
|
|
10
10
|
data: {
|
|
11
|
-
record:
|
|
11
|
+
record: ResourceKey<T>;
|
|
12
12
|
options: SaveRecordBuilderOptions;
|
|
13
13
|
};
|
|
14
|
-
records: [
|
|
14
|
+
records: [ResourceKey<T>];
|
|
15
15
|
[RequestSignature]?: RT;
|
|
16
16
|
};
|
|
17
17
|
type SaveRecordBuilderOptions = Record<string, unknown>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Store } from "@warp-drive/core";
|
|
2
2
|
import { createDeferred } from "@warp-drive/core/request";
|
|
3
|
-
import type { Request
|
|
3
|
+
import type { Request } from "@warp-drive/core/store/-private";
|
|
4
4
|
import type { FindRecordOptions } from "@warp-drive/core/types";
|
|
5
|
-
import type {
|
|
5
|
+
import type { PersistedResourceKey, ResourceKey } from "@warp-drive/core/types/identifier";
|
|
6
6
|
import type { TypeFromInstance } from "@warp-drive/core/types/record";
|
|
7
7
|
import type { ImmutableRequestInfo } from "@warp-drive/core/types/request";
|
|
8
8
|
import type { SingleResourceDocument } from "@warp-drive/core/types/spec/json-api-raw";
|
|
@@ -13,36 +13,43 @@ export type FetchMutationOptions = FindRecordOptions & {
|
|
|
13
13
|
[SaveOp]: "createRecord" | "deleteRecord" | "updateRecord";
|
|
14
14
|
};
|
|
15
15
|
interface PendingFetchItem {
|
|
16
|
-
identifier:
|
|
16
|
+
identifier: PersistedResourceKey;
|
|
17
17
|
queryRequest: Request;
|
|
18
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
19
18
|
resolver: Deferred<any>;
|
|
20
19
|
options: FindRecordOptions;
|
|
21
20
|
trace?: unknown;
|
|
22
|
-
promise: Promise<
|
|
21
|
+
promise: Promise<PersistedResourceKey>;
|
|
23
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* @private
|
|
25
|
+
*/
|
|
24
26
|
export declare class FetchManager {
|
|
25
|
-
isDestroyed: boolean;
|
|
26
|
-
requestCache: RequestStateService;
|
|
27
|
-
// fetches pending in the runloop, waiting to be coalesced
|
|
28
|
-
_pendingFetch: Map<string, Map<StableExistingRecordIdentifier, PendingFetchItem[]>>;
|
|
29
|
-
_store: Store;
|
|
30
27
|
constructor(store: Store);
|
|
31
|
-
createSnapshot<T>(identifier:
|
|
32
|
-
createSnapshot(identifier:
|
|
28
|
+
createSnapshot<T>(identifier: ResourceKey<TypeFromInstance<T>>, options?: FindRecordOptions): Snapshot<T>;
|
|
29
|
+
createSnapshot(identifier: ResourceKey, options?: FindRecordOptions): Snapshot;
|
|
33
30
|
/**
|
|
34
31
|
This method is called by `record.save`, and gets passed a
|
|
35
32
|
resolver for the promise that `record.save` returns.
|
|
36
33
|
|
|
37
34
|
It schedules saving to happen at the end of the run loop.
|
|
38
35
|
|
|
39
|
-
@
|
|
36
|
+
@private
|
|
40
37
|
*/
|
|
41
|
-
scheduleSave(identifier:
|
|
42
|
-
scheduleFetch(identifier:
|
|
43
|
-
getPendingFetch(identifier:
|
|
38
|
+
scheduleSave(identifier: ResourceKey, options: FetchMutationOptions): Promise<null | SingleResourceDocument>;
|
|
39
|
+
scheduleFetch(identifier: PersistedResourceKey, options: FindRecordOptions, request: ImmutableRequestInfo): Promise<PersistedResourceKey>;
|
|
40
|
+
getPendingFetch(identifier: PersistedResourceKey, options: FindRecordOptions): Promise<PersistedResourceKey> | undefined;
|
|
44
41
|
flushAllPendingFetches(): void;
|
|
45
|
-
fetchDataIfNeededForIdentifier(identifier:
|
|
42
|
+
fetchDataIfNeededForIdentifier(identifier: PersistedResourceKey, options: FindRecordOptions | undefined, request: ImmutableRequestInfo): Promise<PersistedResourceKey>;
|
|
46
43
|
destroy(): void;
|
|
47
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* This type exists for internal use only for
|
|
47
|
+
* where intimate contracts still exist either for
|
|
48
|
+
* the Test Suite or for Legacy code.
|
|
49
|
+
*
|
|
50
|
+
* @private
|
|
51
|
+
*/
|
|
52
|
+
export interface PrivateFetchManager extends FetchManager {
|
|
53
|
+
_pendingFetch: Map<string, Map<PersistedResourceKey, PendingFetchItem[]>>;
|
|
54
|
+
}
|
|
48
55
|
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function assertIdentifierHasId(identifier: unknown): asserts identifier is
|
|
1
|
+
import type { PersistedResourceKey } from "@warp-drive/core/types/identifier";
|
|
2
|
+
export declare function assertIdentifierHasId(identifier: unknown): asserts identifier is PersistedResourceKey;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { Store } from "@warp-drive/core";
|
|
2
2
|
import type { BaseFinderOptions } from "@warp-drive/core/types";
|
|
3
|
-
import type {
|
|
3
|
+
import type { PersistedResourceKey, ResourceKey } from "@warp-drive/core/types/identifier";
|
|
4
4
|
import type { LegacyRelationshipField as RelationshipSchema } from "@warp-drive/core/types/schema/fields";
|
|
5
5
|
import type { MinimumAdapterInterface } from "./minimum-adapter-interface.js";
|
|
6
|
-
export declare function _findHasMany(adapter: MinimumAdapterInterface, store: Store, identifier:
|
|
6
|
+
export declare function _findHasMany(adapter: MinimumAdapterInterface, store: Store, identifier: ResourceKey, link: string | null | {
|
|
7
7
|
href: string;
|
|
8
|
-
}, relationship: RelationshipSchema, options: BaseFinderOptions): Promise<
|
|
9
|
-
export declare function _findBelongsTo(store: Store, identifier:
|
|
8
|
+
}, relationship: RelationshipSchema, options: BaseFinderOptions): Promise<PersistedResourceKey[]>;
|
|
9
|
+
export declare function _findBelongsTo(store: Store, identifier: ResourceKey, link: string | null | {
|
|
10
10
|
href: string;
|
|
11
|
-
}, relationship: RelationshipSchema, options: BaseFinderOptions): Promise<
|
|
11
|
+
}, relationship: RelationshipSchema, options: BaseFinderOptions): Promise<PersistedResourceKey | null>;
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
import type { Store } from "@warp-drive/core";
|
|
2
|
-
import type {
|
|
2
|
+
import type { LegacyQueryArray } from "@warp-drive/core/store/-private";
|
|
3
3
|
import type { ModelSchema } from "@warp-drive/core/types";
|
|
4
4
|
import type { LegacyRelationshipField as RelationshipSchema } from "@warp-drive/core/types/schema/fields";
|
|
5
5
|
import type { Snapshot } from "./snapshot.js";
|
|
6
6
|
import type { SnapshotRecordArray } from "./snapshot-record-array.js";
|
|
7
7
|
type Group = Snapshot[];
|
|
8
|
-
// TODO this should probably just alias unknown
|
|
9
|
-
// since in theory a user could pass a blob or a string
|
|
10
|
-
// however those deserialization cases are handled
|
|
11
|
-
// far easier in the adapter itself and are unlikely
|
|
12
|
-
// to be passed to the serializer today.
|
|
13
8
|
export type AdapterPayload = Record<string, unknown> | unknown[];
|
|
14
9
|
/**
|
|
15
10
|
* <blockquote style="margin: 1em; padding: .1em 1em .1em 1em; border-left: solid 1em #E34C32; background: #e0e0e0;">
|
|
@@ -113,11 +108,11 @@ export interface MinimumAdapterInterface {
|
|
|
113
108
|
* @param {ModelSchema} schema An object with methods for accessing information about
|
|
114
109
|
* the type, attributes and relationships of the primary type associated with the request.
|
|
115
110
|
* @param {Object} query
|
|
116
|
-
* @param {
|
|
111
|
+
* @param {LegacyQueryArray} recordArray
|
|
117
112
|
* @param {Object} options
|
|
118
113
|
* @return {Promise} a promise resolving with resource data to feed to the associated serializer
|
|
119
114
|
*/
|
|
120
|
-
query(store: Store, schema: ModelSchema, query: Record<string, unknown>, recordArray:
|
|
115
|
+
query(store: Store, schema: ModelSchema, query: Record<string, unknown>, recordArray: LegacyQueryArray, options: {
|
|
121
116
|
adapterOptions?: unknown;
|
|
122
117
|
}): Promise<AdapterPayload>;
|
|
123
118
|
/**
|
|
@@ -1,21 +1,55 @@
|
|
|
1
1
|
import type { Store } from "@warp-drive/core";
|
|
2
|
-
import type {
|
|
3
|
-
import type { FindAllOptions, ModelSchema } from "@warp-drive/core/types";
|
|
2
|
+
import type { FindAllOptions } from "@warp-drive/core/types";
|
|
4
3
|
import type { Snapshot } from "./snapshot.js";
|
|
5
4
|
/**
|
|
6
5
|
SnapshotRecordArray is not directly instantiable.
|
|
7
6
|
Instances are provided to consuming application's
|
|
8
7
|
adapters for certain `findAll` requests.
|
|
9
8
|
|
|
10
|
-
@
|
|
9
|
+
@hideconstructor
|
|
11
10
|
@public
|
|
12
11
|
*/
|
|
13
12
|
export declare class SnapshotRecordArray {
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
/**
|
|
14
|
+
* The ResourceType of the underlying records for the {@link Snapshot | Snapshots} in the array
|
|
15
|
+
*/
|
|
16
16
|
modelName: string;
|
|
17
|
-
|
|
17
|
+
/**
|
|
18
|
+
* A hash of adapter options passed into the store method for this request.
|
|
19
|
+
|
|
20
|
+
Example
|
|
21
|
+
|
|
22
|
+
```js [app/adapters/post.js]
|
|
23
|
+
import MyCustomAdapter from './custom-adapter';
|
|
24
|
+
|
|
25
|
+
export default class PostAdapter extends MyCustomAdapter {
|
|
26
|
+
findAll(store, type, sinceToken, snapshotRecordArray) {
|
|
27
|
+
if (snapshotRecordArray.adapterOptions.subscribe) {
|
|
28
|
+
// ...
|
|
29
|
+
}
|
|
30
|
+
// ...
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
*/
|
|
18
35
|
adapterOptions?: Record<string, unknown>;
|
|
36
|
+
/**
|
|
37
|
+
* The relationships to include for this request.
|
|
38
|
+
|
|
39
|
+
Example
|
|
40
|
+
|
|
41
|
+
```js [app/adapters/application.js]
|
|
42
|
+
import Adapter from '@ember-data/adapter';
|
|
43
|
+
|
|
44
|
+
export default class ApplicationAdapter extends Adapter {
|
|
45
|
+
findAll(store, type, snapshotRecordArray) {
|
|
46
|
+
let url = `/${type.modelName}?include=${encodeURIComponent(snapshotRecordArray.include)}`;
|
|
47
|
+
|
|
48
|
+
return fetch(url).then((response) => response.json())
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
*/
|
|
19
53
|
include?: string | string[];
|
|
20
54
|
/**
|
|
21
55
|
SnapshotRecordArray is not directly instantiable.
|
|
@@ -30,14 +64,6 @@ export declare class SnapshotRecordArray {
|
|
|
30
64
|
*/
|
|
31
65
|
constructor(store: Store, type: string, options?: FindAllOptions);
|
|
32
66
|
/**
|
|
33
|
-
An array of records
|
|
34
|
-
|
|
35
|
-
@property _recordArray
|
|
36
|
-
@private
|
|
37
|
-
@type {Array}
|
|
38
|
-
*/
|
|
39
|
-
get _recordArray(): LiveArray;
|
|
40
|
-
/**
|
|
41
67
|
Number of records in the array
|
|
42
68
|
|
|
43
69
|
Example
|
|
@@ -51,10 +77,6 @@ export declare class SnapshotRecordArray {
|
|
|
51
77
|
}
|
|
52
78
|
});
|
|
53
79
|
```
|
|
54
|
-
|
|
55
|
-
@property length
|
|
56
|
-
@public
|
|
57
|
-
@type {Number}
|
|
58
80
|
*/
|
|
59
81
|
get length(): number;
|
|
60
82
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Store } from "@warp-drive/core";
|
|
2
2
|
import type { FindRecordOptions } from "@warp-drive/core/types";
|
|
3
3
|
import type { ChangedAttributesHash } from "@warp-drive/core/types/cache";
|
|
4
|
-
import type {
|
|
4
|
+
import type { ResourceKey } from "@warp-drive/core/types/identifier";
|
|
5
5
|
import type { TypedRecordInstance, TypeFromInstance } from "@warp-drive/core/types/record";
|
|
6
6
|
import type { LegacyAttributeField, LegacyRelationshipField } from "@warp-drive/core/types/schema/fields";
|
|
7
7
|
import type { SerializerOptions } from "./minimum-serializer-interface.js";
|
|
@@ -14,46 +14,64 @@ adapters and serializers for certain requests.
|
|
|
14
14
|
Snapshots are only available when using `@ember-data/legacy-compat`
|
|
15
15
|
for legacy compatibility with adapters and serializers.
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
For serialization of records in modern paradigms, request data from
|
|
18
|
+
the cache or off the record directly.
|
|
19
|
+
|
|
20
|
+
@hideconstructor
|
|
18
21
|
@public
|
|
19
22
|
*/
|
|
20
23
|
export declare class Snapshot<R = unknown> {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
/**
|
|
25
|
+
The unique ResourceKey associated with this Snapshot.
|
|
26
|
+
|
|
27
|
+
@public
|
|
28
|
+
*/
|
|
29
|
+
identifier: ResourceKey<R extends TypedRecordInstance ? TypeFromInstance<R> : string>;
|
|
30
|
+
/**
|
|
31
|
+
The ResourceType of the underlying record for this Snapshot, as a string.
|
|
32
|
+
|
|
33
|
+
@public
|
|
34
|
+
*/
|
|
28
35
|
modelName: R extends TypedRecordInstance ? TypeFromInstance<R> : string;
|
|
36
|
+
/**
|
|
37
|
+
The id of the snapshot's underlying record
|
|
38
|
+
|
|
39
|
+
Example
|
|
40
|
+
|
|
41
|
+
```js
|
|
42
|
+
// store.push('post', { id: 1, author: 'Tomster', title: 'Ember.js rocks' });
|
|
43
|
+
postSnapshot.id; // => '1'
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
@public
|
|
47
|
+
*/
|
|
29
48
|
id: string | null;
|
|
49
|
+
/**
|
|
50
|
+
If `include` was passed to the options for the request, the value
|
|
51
|
+
would be available here.
|
|
52
|
+
|
|
53
|
+
@public
|
|
54
|
+
*/
|
|
30
55
|
include?: string | string[];
|
|
31
|
-
adapterOptions?: Record<string, unknown>;
|
|
32
|
-
_store: Store;
|
|
33
56
|
/**
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
* @param identifier
|
|
38
|
-
* @param _store
|
|
57
|
+
The adapterOptions passed to the request which generated this Snapshot, if any
|
|
58
|
+
|
|
59
|
+
@public
|
|
39
60
|
*/
|
|
40
|
-
|
|
61
|
+
adapterOptions?: Record<string, unknown>;
|
|
62
|
+
constructor(options: FindRecordOptions, identifier: ResourceKey<R extends TypedRecordInstance ? TypeFromInstance<R> : string>, store: Store);
|
|
41
63
|
/**
|
|
42
64
|
The underlying record for this snapshot. Can be used to access methods and
|
|
43
65
|
properties defined on the record.
|
|
44
66
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
```javascript
|
|
48
|
-
let json = snapshot.record.toJSON();
|
|
67
|
+
```js
|
|
68
|
+
const someValue = snapshot.record.someProp;
|
|
49
69
|
```
|
|
50
70
|
|
|
51
71
|
@property record
|
|
52
|
-
@type {Model}
|
|
53
72
|
@public
|
|
54
73
|
*/
|
|
55
74
|
get record(): R | null;
|
|
56
|
-
get _attributes(): Record<keyof R & string, unknown>;
|
|
57
75
|
get isNew(): boolean;
|
|
58
76
|
/**
|
|
59
77
|
Returns the value of an attribute.
|
|
@@ -68,22 +86,28 @@ export declare class Snapshot<R = unknown> {
|
|
|
68
86
|
|
|
69
87
|
Note: Values are loaded eagerly and cached when the snapshot is created.
|
|
70
88
|
|
|
71
|
-
@
|
|
72
|
-
@return {Object} The attribute value or undefined
|
|
89
|
+
@return The attribute value or undefined
|
|
73
90
|
@public
|
|
74
91
|
*/
|
|
75
92
|
attr(keyName: keyof R & string): unknown;
|
|
76
93
|
/**
|
|
77
94
|
Returns all attributes and their corresponding values.
|
|
78
95
|
|
|
96
|
+
::: warning ⚠️ WARNING
|
|
97
|
+
Attributes are SHALLOW copied from the cache.
|
|
98
|
+
Because they are NOT deep copied from the cache, mutating
|
|
99
|
+
any object or array fields will cause unintended side-effects
|
|
100
|
+
and bugs.
|
|
101
|
+
:::
|
|
102
|
+
|
|
79
103
|
Example
|
|
80
104
|
|
|
81
|
-
```
|
|
105
|
+
```js
|
|
82
106
|
// store.push('post', { id: 1, author: 'Tomster', title: 'Ember.js rocks' });
|
|
83
107
|
postSnapshot.attributes(); // => { author: 'Tomster', title: 'Ember.js rocks' }
|
|
84
108
|
```
|
|
85
109
|
|
|
86
|
-
@return
|
|
110
|
+
@return All attributes of the current snapshot
|
|
87
111
|
@public
|
|
88
112
|
*/
|
|
89
113
|
attributes(): Record<keyof R & string, unknown>;
|
|
@@ -92,13 +116,13 @@ export declare class Snapshot<R = unknown> {
|
|
|
92
116
|
|
|
93
117
|
Example
|
|
94
118
|
|
|
95
|
-
```
|
|
119
|
+
```js
|
|
96
120
|
// store.push('post', { id: 1, author: 'Tomster', title: 'Ember.js rocks' });
|
|
97
121
|
postModel.set('title', 'Ember.js rocks!');
|
|
98
122
|
postSnapshot.changedAttributes(); // => { title: ['Ember.js rocks', 'Ember.js rocks!'] }
|
|
99
123
|
```
|
|
100
124
|
|
|
101
|
-
@return
|
|
125
|
+
@return All changed attributes of the current snapshot
|
|
102
126
|
@public
|
|
103
127
|
*/
|
|
104
128
|
changedAttributes(): ChangedAttributesHash;
|
|
@@ -113,7 +137,7 @@ export declare class Snapshot<R = unknown> {
|
|
|
113
137
|
|
|
114
138
|
Example
|
|
115
139
|
|
|
116
|
-
```
|
|
140
|
+
```js
|
|
117
141
|
// store.push('post', { id: 1, title: 'Hello World' });
|
|
118
142
|
// store.createRecord('comment', { body: 'Lorem ipsum', post: post });
|
|
119
143
|
commentSnapshot.belongsTo('post'); // => Snapshot
|
|
@@ -130,12 +154,10 @@ export declare class Snapshot<R = unknown> {
|
|
|
130
154
|
|
|
131
155
|
Note: Relationships are loaded lazily and cached upon first access.
|
|
132
156
|
|
|
133
|
-
@param {String} keyName
|
|
134
|
-
@param {Object} [options]
|
|
135
157
|
@public
|
|
136
|
-
@return
|
|
137
|
-
relationship
|
|
138
|
-
|
|
158
|
+
@return A snapshot or ID of a known relationship or null if the
|
|
159
|
+
relationship is known but unset. undefined will be returned if the
|
|
160
|
+
contents of the relationship are unknown.
|
|
139
161
|
*/
|
|
140
162
|
belongsTo(keyName: string, options?: {
|
|
141
163
|
id?: boolean;
|
|
@@ -162,10 +184,8 @@ export declare class Snapshot<R = unknown> {
|
|
|
162
184
|
|
|
163
185
|
Note: Relationships are loaded lazily and cached upon first access.
|
|
164
186
|
|
|
165
|
-
@param {String} keyName
|
|
166
|
-
@param {Object} [options]
|
|
167
187
|
@public
|
|
168
|
-
@return
|
|
188
|
+
@return An array of snapshots or IDs of a known
|
|
169
189
|
relationship or an empty array if the relationship is known but unset.
|
|
170
190
|
undefined will be returned if the contents of the relationship is unknown.
|
|
171
191
|
*/
|
|
@@ -184,8 +204,8 @@ export declare class Snapshot<R = unknown> {
|
|
|
184
204
|
});
|
|
185
205
|
```
|
|
186
206
|
|
|
187
|
-
@param
|
|
188
|
-
@param
|
|
207
|
+
@param callback the callback to execute
|
|
208
|
+
@param binding the optional value to which the callback's `this` should be bound
|
|
189
209
|
@public
|
|
190
210
|
*/
|
|
191
211
|
eachAttribute(callback: (key: string, meta: LegacyAttributeField) => void, binding?: unknown): void;
|
|
@@ -201,8 +221,8 @@ export declare class Snapshot<R = unknown> {
|
|
|
201
221
|
});
|
|
202
222
|
```
|
|
203
223
|
|
|
204
|
-
@param
|
|
205
|
-
@param
|
|
224
|
+
@param callback the callback to execute
|
|
225
|
+
@param binding the optional value to which the callback's `this` should be bound
|
|
206
226
|
@public
|
|
207
227
|
*/
|
|
208
228
|
eachRelationship(callback: (key: string, meta: LegacyRelationshipField) => void, binding?: unknown): void;
|
|
@@ -227,8 +247,7 @@ export declare class Snapshot<R = unknown> {
|
|
|
227
247
|
});
|
|
228
248
|
```
|
|
229
249
|
|
|
230
|
-
@
|
|
231
|
-
@return {Object} an object whose values are primitive JSON values only
|
|
250
|
+
@return an object whose values are primitive JSON values only
|
|
232
251
|
@public
|
|
233
252
|
*/
|
|
234
253
|
serialize(options?: SerializerOptions): unknown;
|
package/declarations/compat.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { AdapterPayload, MinimumAdapterInterface } from "./compat/legacy-ne
|
|
|
6
6
|
import type { MinimumSerializerInterface, SerializerOptions } from "./compat/legacy-network-handler/minimum-serializer-interface.js";
|
|
7
7
|
export { LegacyNetworkHandler } from "./compat/legacy-network-handler/legacy-network-handler.js";
|
|
8
8
|
export type { MinimumAdapterInterface, MinimumSerializerInterface, SerializerOptions, AdapterPayload };
|
|
9
|
-
export
|
|
9
|
+
export interface LegacyStoreCompat extends Store {
|
|
10
10
|
_fetchManager: FetchManager;
|
|
11
11
|
adapterFor(this: Store, modelName: string): MinimumAdapterInterface;
|
|
12
12
|
adapterFor(this: Store, modelName: string, _allowMissing: true): MinimumAdapterInterface | undefined;
|
|
@@ -20,8 +20,8 @@ export type LegacyStoreCompat = {
|
|
|
20
20
|
_serializerCache: Record<string, MinimumSerializerInterface & {
|
|
21
21
|
store: Store;
|
|
22
22
|
}>;
|
|
23
|
-
}
|
|
24
|
-
export type CompatStore =
|
|
23
|
+
}
|
|
24
|
+
export type CompatStore = LegacyStoreCompat;
|
|
25
25
|
/**
|
|
26
26
|
Returns an instance of the adapter for a given type. For
|
|
27
27
|
example, `adapterFor('person')` will return an instance of
|
|
@@ -72,7 +72,6 @@ store.push(store.normalize(modelName, data));
|
|
|
72
72
|
@param modelName The name of the model type for this payload
|
|
73
73
|
@return The normalized payload
|
|
74
74
|
*/
|
|
75
|
-
// TODO @runspired @deprecate users should call normalize on the associated serializer directly
|
|
76
75
|
export declare function normalize(this: Store, modelName: string, payload: ObjectValue): SingleResourceDocument;
|
|
77
76
|
/**
|
|
78
77
|
Push some raw data into the store.
|
|
@@ -129,8 +128,6 @@ store.pushPayload('post', pushData); // Will use the post serializer
|
|
|
129
128
|
@param {String} modelName Optionally, a model type used to determine which serializer will be used
|
|
130
129
|
@param {Object} inputPayload
|
|
131
130
|
*/
|
|
132
|
-
// TODO @runspired @deprecate pushPayload in favor of looking up the serializer
|
|
133
131
|
export declare function pushPayload(this: Store, modelName: string, inputPayload: ObjectValue): void;
|
|
134
|
-
// TODO @runspired @deprecate records should implement their own serialization if desired
|
|
135
132
|
export declare function serializeRecord(this: Store, record: unknown, options?: SerializerOptions): unknown;
|
|
136
133
|
export declare function cleanup(this: Store): void;
|