@warp-drive/legacy 5.6.0-beta.1 → 5.6.0-beta.3
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 +2 -3
- 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 +3 -4
- package/declarations/model/-private/model.d.ts +14 -67
- 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 +2 -2
- package/declarations/model/migration-support.d.ts +11 -53
- package/declarations/model.d.ts +1 -1
- 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 +223 -0
- package/declarations/store.d.ts +3 -0
- package/dist/{-private-CKrP0ogQ.js → -private-8UmnAf9J.js} +169 -141
- package/dist/adapter/-private.js +1 -1
- package/dist/adapter/error.js +66 -0
- package/dist/adapter/json-api.js +1 -1
- package/dist/adapter/rest.js +2 -2
- package/dist/compat/-private.js +1 -1
- package/dist/compat/builders.js +4 -23
- 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 +96 -11
- package/dist/model.js +14 -11
- package/dist/{schema-provider-BdQhkT-Q.js → schema-provider-DQu4Rjco.js} +165 -60
- package/dist/{serialize-into-hash-Bp58npke.js → serialize-into-hash-CS0MIv4F.js} +2 -1
- package/dist/store.js +633 -0
- package/dist/util-Dul6TZts.js +35 -0
- package/dist/utils-Cqw9eRj5.js +23 -0
- package/package.json +15 -15
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ArrayValue, ObjectValue, PrimitiveValue } from "@warp-drive/core/types/json/raw";
|
|
2
|
-
import type
|
|
2
|
+
import { type TransformName } from "@warp-drive/core/types/symbols";
|
|
3
3
|
import type { DecoratorPropertyDescriptor } from "./util.js";
|
|
4
4
|
/**
|
|
5
5
|
* Options provided to the attr decorator are
|
|
@@ -37,13 +37,6 @@ export type AttrOptions<DV = PrimitiveValue | object | unknown[]> = {
|
|
|
37
37
|
*/
|
|
38
38
|
defaultValue?: DV extends PrimitiveValue ? DV : () => DV;
|
|
39
39
|
};
|
|
40
|
-
// NOTE: Usage of Explicit ANY
|
|
41
|
-
// -------------------------------------------------------------------
|
|
42
|
-
// any is required here because we are the maximal not the minimal
|
|
43
|
-
// subset of options allowed. If we used unknown, object, or
|
|
44
|
-
// Record<string, unknown> we would get type errors when we try to
|
|
45
|
-
// assert against a more specific implementation with precise options.
|
|
46
|
-
// -------------------------------------------------------------------
|
|
47
40
|
type LooseTransformInstance<
|
|
48
41
|
V,
|
|
49
42
|
Raw,
|
|
@@ -53,15 +46,11 @@ type LooseTransformInstance<
|
|
|
53
46
|
* value type must match the return type of the deserialize method
|
|
54
47
|
*
|
|
55
48
|
*/
|
|
56
|
-
// see note on Explicit ANY above
|
|
57
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
58
49
|
serialize: (value: V, options: any) => Raw;
|
|
59
50
|
/**
|
|
60
51
|
* defaultValue type must match the return type of the deserialize method
|
|
61
52
|
*
|
|
62
53
|
*/
|
|
63
|
-
// see note on Explicit ANY above
|
|
64
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
65
54
|
deserialize: (value: Raw, options: any) => V;
|
|
66
55
|
[TransformName]: Name;
|
|
67
56
|
};
|
|
@@ -72,8 +61,6 @@ export type TypedTransformInstance<
|
|
|
72
61
|
V,
|
|
73
62
|
T extends string
|
|
74
63
|
> = LooseTransformInstance<V, string, T> | LooseTransformInstance<V, number, T> | LooseTransformInstance<V, boolean, T> | LooseTransformInstance<V, null, T> | LooseTransformInstance<V, ObjectValue, T> | LooseTransformInstance<V, ArrayValue, T> | LooseTransformInstance<V, string | null, T> | LooseTransformInstance<V, number | null, T> | LooseTransformInstance<V, boolean | null, T> | LooseTransformInstance<V, ObjectValue | null, T> | LooseTransformInstance<V, ArrayValue | null, T>;
|
|
75
|
-
// see note on Explicit ANY above
|
|
76
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
77
64
|
export type GetMaybeDeserializeValue<T> = T extends {
|
|
78
65
|
deserialize: (...args: any[]) => unknown;
|
|
79
66
|
} ? ReturnType<T["deserialize"]> : never;
|
|
@@ -12,13 +12,6 @@ export type RelationshipOptions<
|
|
|
12
12
|
resetOnRemoteUpdate?: boolean;
|
|
13
13
|
};
|
|
14
14
|
export type NoNull<T> = Exclude<T, null>;
|
|
15
|
-
// type BelongsToDecoratorObject<getT> = {
|
|
16
|
-
// get: () => getT;
|
|
17
|
-
// // set: (value: Awaited<getT>) => void;
|
|
18
|
-
// set: (value: getT) => void;
|
|
19
|
-
// // init: () => getT;
|
|
20
|
-
// };
|
|
21
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
22
15
|
export type RelationshipDecorator<T> = <This>(target: This, key: string, desc?: PropertyDescriptor) => void;
|
|
23
16
|
/**
|
|
24
17
|
`belongsTo` is used to define One-To-One and One-To-Many, and One-To-None
|
|
@@ -179,8 +172,4 @@ type each record satisfies on both sides.
|
|
|
179
172
|
export declare function belongsTo(): never;
|
|
180
173
|
export declare function belongsTo(type: string): never;
|
|
181
174
|
export declare function belongsTo<T>(type: TypeFromInstance<NoNull<T>>, options: RelationshipOptions<T, boolean>): RelationshipDecorator<T>;
|
|
182
|
-
// export function belongsTo<K extends Promise<unknown>, T extends Awaited<K> = Awaited<K>>(
|
|
183
|
-
// type: TypeFromInstance<NoNull<T>>,
|
|
184
|
-
// options: RelationshipOptions<T, true>
|
|
185
|
-
// ): RelationshipDecorator<K>;
|
|
186
175
|
export declare function belongsTo(type: string, options: RelationshipOptions<unknown, boolean>): RelationshipDecorator<unknown>;
|
|
@@ -1,17 +1,5 @@
|
|
|
1
1
|
import type { Store } from "@warp-drive/core";
|
|
2
2
|
import type { UpgradedMeta } from "@warp-drive/core/graph/-private";
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
Assert that `addedRecord` has a valid type so it can be added to the
|
|
6
|
-
relationship of the `record`.
|
|
7
|
-
|
|
8
|
-
The assert basically checks if the `addedRecord` can be added to the
|
|
9
|
-
relationship (specified via `relationshipMeta`) of the `record`.
|
|
10
|
-
|
|
11
|
-
This utility should only be used internally, as both record parameters must
|
|
12
|
-
be stable record identifiers and the `relationshipMeta` needs to be the meta
|
|
13
|
-
information about the relationship, retrieved via
|
|
14
|
-
`record.relationshipFor(key)`.
|
|
15
|
-
*/
|
|
16
|
-
declare let assertPolymorphicType: (parentIdentifier: StableRecordIdentifier, parentDefinition: UpgradedMeta, addedIdentifier: StableRecordIdentifier, store: Store) => void;
|
|
3
|
+
import type { ResourceKey } from "@warp-drive/core/types/identifier";
|
|
4
|
+
declare let assertPolymorphicType: (parentIdentifier: ResourceKey, parentDefinition: UpgradedMeta, addedIdentifier: ResourceKey, store: Store) => void;
|
|
17
5
|
export { assertPolymorphicType };
|
|
@@ -6,16 +6,10 @@ type ValidationError = {
|
|
|
6
6
|
message: string;
|
|
7
7
|
};
|
|
8
8
|
interface ArrayProxyWithCustomOverrides<T> extends Omit<ArrayProxy<T>, "clear" | "content"> {
|
|
9
|
-
// Omit causes `content` to be merged with the class def for ArrayProxy
|
|
10
|
-
// which then causes it to be seen as a property, disallowing defining it
|
|
11
|
-
// as an accessor. This restores our ability to define it as an accessor.
|
|
12
9
|
content: NativeArray<T>;
|
|
13
10
|
clear(): void;
|
|
14
11
|
_has(name: string): boolean;
|
|
15
12
|
}
|
|
16
|
-
// we force the type here to our own construct because mixin and extend patterns
|
|
17
|
-
// lose generic signatures. We also do this because we need to Omit `clear` from
|
|
18
|
-
// the type of ArrayProxy as we override it's signature.
|
|
19
13
|
declare const ArrayProxyWithCustomOverrides: new <T>() => ArrayProxyWithCustomOverrides<T>;
|
|
20
14
|
/**
|
|
21
15
|
Holds validation errors for a given record, organized by attribute names.
|
|
@@ -160,8 +160,4 @@ type each record satisfies on both sides.
|
|
|
160
160
|
export declare function hasMany(): never;
|
|
161
161
|
export declare function hasMany(type: string): never;
|
|
162
162
|
export declare function hasMany<T>(type: TypeFromInstance<NoNull<T>>, options: RelationshipOptions<T, boolean>): RelationshipDecorator<T>;
|
|
163
|
-
// export function hasMany<K extends Promise<unknown>, T extends Awaited<K> = Awaited<K>>(
|
|
164
|
-
// type: TypeFromInstance<NoNull<T>>,
|
|
165
|
-
// options: RelationshipOptions<T, true>
|
|
166
|
-
// ): RelationshipDecorator<K>;
|
|
167
163
|
export declare function hasMany(type: string, options: RelationshipOptions<unknown, boolean>): RelationshipDecorator<unknown>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type Store } from "@warp-drive/core/store/-private";
|
|
2
|
-
import type {
|
|
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
|
-
export declare function instantiateRecord(this: Store, identifier:
|
|
5
|
+
export declare function instantiateRecord(this: Store, identifier: ResourceKey, createRecordArgs: {
|
|
6
6
|
[key: string]: unknown;
|
|
7
7
|
}): Model;
|
|
8
8
|
export declare function teardownRecord(record: Model): void;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import type { Store } from "@warp-drive/core";
|
|
2
|
-
import type { CollectionEdge,
|
|
3
|
-
import type {
|
|
4
|
-
import {
|
|
5
|
-
import type { BaseFinderOptions, StableRecordIdentifier } from "@warp-drive/core/types";
|
|
6
|
-
import type { Cache } from "@warp-drive/core/types/cache";
|
|
2
|
+
import type { CollectionEdge, ResourceEdge, UpgradedMeta } from "@warp-drive/core/graph/-private";
|
|
3
|
+
import type { LegacyManyArray } from "@warp-drive/core/store/-private";
|
|
4
|
+
import type { BaseFinderOptions, ResourceKey } from "@warp-drive/core/types";
|
|
7
5
|
import type { CollectionRelationship } from "@warp-drive/core/types/cache/relationship";
|
|
8
6
|
import type { LocalRelationshipOperation } from "@warp-drive/core/types/graph";
|
|
9
7
|
import type { OpaqueRecordInstance, TypeFromInstanceOrString } from "@warp-drive/core/types/record";
|
|
@@ -15,33 +13,26 @@ import type { HasManyProxyCreateArgs } from "./promise-many-array.js";
|
|
|
15
13
|
import { PromiseManyArray } from "./promise-many-array.js";
|
|
16
14
|
import BelongsToReference from "./references/belongs-to.js";
|
|
17
15
|
import HasManyReference from "./references/has-many.js";
|
|
18
|
-
export declare const LEGACY_SUPPORT: Map<
|
|
16
|
+
export declare const LEGACY_SUPPORT: Map<ResourceKey | MinimalLegacyRecord, LegacySupport>;
|
|
19
17
|
export declare function lookupLegacySupport(record: MinimalLegacyRecord): LegacySupport;
|
|
18
|
+
/**
|
|
19
|
+
* @hideconstructor
|
|
20
|
+
*/
|
|
20
21
|
export declare class LegacySupport {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
references: Record<string, BelongsToReference | HasManyReference>;
|
|
26
|
-
identifier: StableRecordIdentifier;
|
|
27
|
-
_manyArrayCache: Record<string, ManyArray>;
|
|
28
|
-
_relationshipPromisesCache: Record<string, Promise<ManyArray | OpaqueRecordInstance>>;
|
|
29
|
-
_relationshipProxyCache: Record<string, PromiseManyArray | PromiseBelongsTo | undefined>;
|
|
30
|
-
_pending: Record<string, Promise<StableRecordIdentifier | null> | undefined>;
|
|
31
|
-
isDestroying: boolean;
|
|
32
|
-
isDestroyed: boolean;
|
|
33
|
-
constructor(record: MinimalLegacyRecord);
|
|
34
|
-
_syncArray(array: LiveArray): void;
|
|
22
|
+
identifier: ResourceKey;
|
|
23
|
+
constructor(record: MinimalLegacyRecord, identifier: ResourceKey);
|
|
24
|
+
/** @private */
|
|
25
|
+
_syncArray(array: LegacyManyArray): void;
|
|
35
26
|
mutate(mutation: LocalRelationshipOperation): void;
|
|
36
27
|
_findBelongsTo(key: string, resource: SingleResourceRelationship, relationship: ResourceEdge, options?: BaseFinderOptions): Promise<OpaqueRecordInstance | null>;
|
|
37
28
|
reloadBelongsTo(key: string, options?: BaseFinderOptions): Promise<OpaqueRecordInstance | null>;
|
|
38
29
|
getBelongsTo(key: string, options?: BaseFinderOptions): PromiseBelongsTo | OpaqueRecordInstance | null;
|
|
39
30
|
setDirtyBelongsTo(key: string, value: OpaqueRecordInstance | null): void;
|
|
40
|
-
_getCurrentState<T>(identifier:
|
|
41
|
-
getManyArray<T>(key: string, definition?: UpgradedMeta):
|
|
42
|
-
fetchAsyncHasMany(key: string, relationship: CollectionEdge, manyArray:
|
|
43
|
-
reloadHasMany<T>(key: string, options?: BaseFinderOptions): Promise<
|
|
44
|
-
getHasMany(key: string, options?: BaseFinderOptions): PromiseManyArray |
|
|
31
|
+
_getCurrentState<T>(identifier: ResourceKey, field: string): [ResourceKey<TypeFromInstanceOrString<T>>[], CollectionRelationship];
|
|
32
|
+
getManyArray<T>(key: string, definition?: UpgradedMeta): LegacyManyArray<T>;
|
|
33
|
+
fetchAsyncHasMany(key: string, relationship: CollectionEdge, manyArray: LegacyManyArray, options?: BaseFinderOptions): Promise<LegacyManyArray>;
|
|
34
|
+
reloadHasMany<T>(key: string, options?: BaseFinderOptions): Promise<LegacyManyArray<T>> | PromiseManyArray<T>;
|
|
35
|
+
getHasMany(key: string, options?: BaseFinderOptions): PromiseManyArray | LegacyManyArray;
|
|
45
36
|
_updatePromiseProxyFor(kind: "hasMany", key: string, args: HasManyProxyCreateArgs): PromiseManyArray;
|
|
46
37
|
_updatePromiseProxyFor(kind: "belongsTo", key: string, args: BelongsToProxyCreateArgs): PromiseBelongsTo;
|
|
47
38
|
_updatePromiseProxyFor(kind: "belongsTo", key: string, args: {
|
|
@@ -49,8 +40,8 @@ export declare class LegacySupport {
|
|
|
49
40
|
}): PromiseBelongsTo;
|
|
50
41
|
referenceFor(kind: "belongsTo", name: string): BelongsToReference;
|
|
51
42
|
referenceFor(kind: "hasMany", name: string): HasManyReference;
|
|
52
|
-
_findHasManyByJsonApiResource(resource: CollectionResourceRelationship, parentIdentifier:
|
|
53
|
-
_findBelongsToByJsonApiResource(resource: SingleResourceRelationship, parentIdentifier:
|
|
43
|
+
_findHasManyByJsonApiResource(resource: CollectionResourceRelationship, parentIdentifier: ResourceKey, relationship: CollectionEdge, options?: BaseFinderOptions): Promise<void | unknown[]> | void;
|
|
44
|
+
_findBelongsToByJsonApiResource(resource: SingleResourceRelationship, parentIdentifier: ResourceKey, relationship: ResourceEdge, options?: BaseFinderOptions): Promise<ResourceKey | null>;
|
|
54
45
|
destroy(): void;
|
|
55
46
|
}
|
|
56
47
|
export declare function areAllInverseRecordsLoaded(store: Store, resource: InnerRelationshipDocument): boolean;
|
|
@@ -1,19 +1,3 @@
|
|
|
1
1
|
import type { Store } from "@warp-drive/core";
|
|
2
2
|
import { type ModelFactory } from "./model.js";
|
|
3
|
-
/*
|
|
4
|
-
In case someone defined a relationship to a mixin, for example:
|
|
5
|
-
```ts
|
|
6
|
-
class CommentModel extends Model {
|
|
7
|
-
@belongsTo('commentable', { polymorphic: true }) owner;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
let Commentable = Mixin.create({
|
|
11
|
-
@hasMany('comment') comments;
|
|
12
|
-
});
|
|
13
|
-
```
|
|
14
|
-
we want to look up a Commentable class which has all the necessary
|
|
15
|
-
relationship meta data. Thus, we look up the mixin and create a mock
|
|
16
|
-
Model, so we can access the relationship CPs of the mixin (`comments`)
|
|
17
|
-
in this case
|
|
18
|
-
*/
|
|
19
3
|
export default function modelForMixin(store: Store, normalizedModelName: string): ModelFactory | undefined;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import type { Store } from "@warp-drive/core";
|
|
2
1
|
import type { ChangedAttributesHash } from "@warp-drive/core/types/cache";
|
|
3
|
-
import { RecordStore } from "@warp-drive/core/types/symbols";
|
|
4
2
|
import type { Snapshot } from "../../compat/-private.js";
|
|
5
3
|
import type { Errors } from "./errors.js";
|
|
6
4
|
import type RecordState from "./record-state.js";
|
|
@@ -9,13 +7,11 @@ import type HasManyReference from "./references/has-many.js";
|
|
|
9
7
|
import type { MaybeBelongsToFields, MaybeHasManyFields } from "./type-utils.js";
|
|
10
8
|
export interface MinimalLegacyRecord {
|
|
11
9
|
errors: Errors;
|
|
12
|
-
___recordState: RecordState;
|
|
13
10
|
currentState: RecordState;
|
|
14
11
|
isDestroyed: boolean;
|
|
15
12
|
isDestroying: boolean;
|
|
16
13
|
isReloading: boolean;
|
|
17
14
|
isValid: boolean;
|
|
18
|
-
[RecordStore]: Store;
|
|
19
15
|
deleteRecord(): void;
|
|
20
16
|
unloadRecord(): void;
|
|
21
17
|
save<T extends MinimalLegacyRecord>(this: T, options?: Record<string, unknown>): Promise<this>;
|
|
@@ -32,9 +28,12 @@ export declare function hasMany<
|
|
|
32
28
|
K extends MaybeHasManyFields<T>
|
|
33
29
|
>(this: T, prop: K): HasManyReference<T, K>;
|
|
34
30
|
export declare function reload<T extends MinimalLegacyRecord>(this: T, options?: Record<string, unknown>): Promise<T>;
|
|
31
|
+
export declare function _reload<T extends MinimalLegacyRecord>(this: T, options?: Record<string, unknown>): Promise<T>;
|
|
35
32
|
export declare function changedAttributes<T extends MinimalLegacyRecord>(this: T): ChangedAttributesHash;
|
|
36
33
|
export declare function serialize<T extends MinimalLegacyRecord>(this: T, options?: Record<string, unknown>): unknown;
|
|
37
34
|
export declare function deleteRecord<T extends MinimalLegacyRecord>(this: T): void;
|
|
38
35
|
export declare function save<T extends MinimalLegacyRecord>(this: T, options?: Record<string, unknown>): Promise<T>;
|
|
36
|
+
export declare function _save<T extends MinimalLegacyRecord>(this: T, options?: Record<string, unknown>): Promise<T>;
|
|
39
37
|
export declare function destroyRecord<T extends MinimalLegacyRecord>(this: T, options?: Record<string, unknown>): Promise<T>;
|
|
38
|
+
export declare function _destroyRecord<T extends MinimalLegacyRecord>(this: T, options?: Record<string, unknown>): Promise<T>;
|
|
40
39
|
export declare function createSnapshot<T extends MinimalLegacyRecord>(this: T): Snapshot<T>;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import EmberObject from "@ember/object";
|
|
2
2
|
import type { Store } from "@warp-drive/core";
|
|
3
|
-
import type { ModelSchema,
|
|
4
|
-
import type {
|
|
3
|
+
import type { ModelSchema, ResourceKey } from "@warp-drive/core/types";
|
|
4
|
+
import type { ChangedAttributesHash } from "@warp-drive/core/types/cache";
|
|
5
5
|
import type { LegacyAttributeField, LegacyRelationshipField } from "@warp-drive/core/types/schema/fields";
|
|
6
|
-
import { RecordStore } from "@warp-drive/core/types/symbols";
|
|
7
6
|
import type { Snapshot } from "../../compat/-private.js";
|
|
8
7
|
import { Errors } from "./errors.js";
|
|
9
8
|
import type { MinimalLegacyRecord } from "./model-methods.js";
|
|
@@ -13,12 +12,10 @@ import type HasManyReference from "./references/has-many.js";
|
|
|
13
12
|
import type { _MaybeBelongsToFields, isSubClass, MaybeAttrFields, MaybeHasManyFields, MaybeRelationshipFields } from "./type-utils.js";
|
|
14
13
|
export type ModelCreateArgs = {
|
|
15
14
|
_createProps: Record<string, unknown>;
|
|
16
|
-
// TODO @deprecate consider deprecating accessing record properties during init which the below is necessary for
|
|
17
15
|
_secretInit: {
|
|
18
|
-
identifier:
|
|
19
|
-
cache: Cache;
|
|
16
|
+
identifier: ResourceKey;
|
|
20
17
|
store: Store;
|
|
21
|
-
cb: (record: Model,
|
|
18
|
+
cb: (record: Model, identifier: ResourceKey, store: Store) => void;
|
|
22
19
|
};
|
|
23
20
|
};
|
|
24
21
|
export type StaticModel = typeof Model & {
|
|
@@ -28,8 +25,6 @@ export type ModelFactory = {
|
|
|
28
25
|
class: StaticModel;
|
|
29
26
|
};
|
|
30
27
|
export type FactoryCache = Record<string, ModelFactory>;
|
|
31
|
-
// we put this on the store for interop because it's used by modelFor and
|
|
32
|
-
// instantiateRecord as well.
|
|
33
28
|
export type ModelStore = Store & {
|
|
34
29
|
_modelFactoryCache: FactoryCache;
|
|
35
30
|
};
|
|
@@ -37,17 +32,10 @@ export type ModelStore = Store & {
|
|
|
37
32
|
* @noInheritDoc
|
|
38
33
|
*/
|
|
39
34
|
interface Model {
|
|
40
|
-
// set during create by the store
|
|
41
35
|
/**
|
|
42
36
|
* The store service instance which created this record instance
|
|
43
37
|
*/
|
|
44
38
|
store: Store;
|
|
45
|
-
/** @internal */
|
|
46
|
-
___recordState: RecordState;
|
|
47
|
-
/** @internal */
|
|
48
|
-
___private_notifications: object;
|
|
49
|
-
/** @internal */
|
|
50
|
-
[RecordStore]: Store;
|
|
51
39
|
/**
|
|
52
40
|
Create a JSON representation of the record, using the serialization
|
|
53
41
|
strategy of the store's adapter.
|
|
@@ -177,7 +165,6 @@ interface Model {
|
|
|
177
165
|
@public
|
|
178
166
|
*/
|
|
179
167
|
rollbackAttributes<T extends MinimalLegacyRecord>(this: T): void;
|
|
180
|
-
// TODO @deprecate in favor of a public API or examples of how to test successfully
|
|
181
168
|
/**
|
|
182
169
|
@private
|
|
183
170
|
*/
|
|
@@ -249,10 +236,6 @@ interface Model {
|
|
|
249
236
|
with an error.
|
|
250
237
|
*/
|
|
251
238
|
reload<T extends MinimalLegacyRecord>(this: T, options?: Record<string, unknown>): Promise<T>;
|
|
252
|
-
// belongsTo<T extends MinimalLegacyRecord, K extends MaybeBelongsToFields<T>>(
|
|
253
|
-
// this: T,
|
|
254
|
-
// prop: K
|
|
255
|
-
// ): BelongsToReference<T, K>;
|
|
256
239
|
/**
|
|
257
240
|
Get the reference for the specified belongsTo relationship.
|
|
258
241
|
|
|
@@ -434,10 +417,7 @@ interface Model {
|
|
|
434
417
|
* @noInheritDoc
|
|
435
418
|
*/
|
|
436
419
|
declare class Model extends EmberObject implements MinimalLegacyRecord {
|
|
437
|
-
/** @
|
|
438
|
-
init(options: ModelCreateArgs): void;
|
|
439
|
-
/** @internal */
|
|
440
|
-
// @ts-expect-error destroy should not return a value, but ember's types force it to
|
|
420
|
+
/** @private */
|
|
441
421
|
destroy(): this;
|
|
442
422
|
/**
|
|
443
423
|
If this property is `true` the record is in the `empty`
|
|
@@ -687,8 +667,6 @@ declare class Model extends EmberObject implements MinimalLegacyRecord {
|
|
|
687
667
|
@property currentState
|
|
688
668
|
@private
|
|
689
669
|
*/
|
|
690
|
-
// TODO we can probably make this a computeOnce
|
|
691
|
-
// we likely do not need to notify the currentState root anymore
|
|
692
670
|
get currentState(): RecordState;
|
|
693
671
|
set currentState(_v: RecordState);
|
|
694
672
|
/**
|
|
@@ -758,18 +736,7 @@ declare class Model extends EmberObject implements MinimalLegacyRecord {
|
|
|
758
736
|
*/
|
|
759
737
|
get adapterError(): unknown;
|
|
760
738
|
set adapterError(v: unknown);
|
|
761
|
-
/*
|
|
762
|
-
We hook the default implementation to ensure
|
|
763
|
-
our tagged properties are properly notified
|
|
764
|
-
as well. We still super for everything because
|
|
765
|
-
sync observers require a direct call occuring
|
|
766
|
-
to trigger their flush. We wouldn't need to
|
|
767
|
-
super in 4.0+ where sync observers are removed.
|
|
768
|
-
*/
|
|
769
|
-
// @ts-expect-error no return is necessary, but Ember's types are forcing it
|
|
770
739
|
notifyPropertyChange(prop: string): this;
|
|
771
|
-
/** @internal */
|
|
772
|
-
attr(): void;
|
|
773
740
|
/**
|
|
774
741
|
Given a callback, iterates over each of the relationships in the model,
|
|
775
742
|
invoking the callback with the name of each relationship and its relationship
|
|
@@ -819,18 +786,14 @@ declare class Model extends EmberObject implements MinimalLegacyRecord {
|
|
|
819
786
|
```
|
|
820
787
|
|
|
821
788
|
@public
|
|
822
|
-
@param
|
|
823
|
-
@param
|
|
789
|
+
@param callback the callback to invoke
|
|
790
|
+
@param binding the value to which the callback's `this` should be bound
|
|
824
791
|
*/
|
|
825
792
|
eachRelationship<T>(callback: (this: NoInfer<T> | undefined, key: MaybeRelationshipFields<this>, meta: LegacyRelationshipField) => void, binding?: T): void;
|
|
826
793
|
relationshipFor(name: string): LegacyRelationshipField | undefined;
|
|
827
794
|
inverseFor(name: string): LegacyRelationshipField | null;
|
|
828
795
|
eachAttribute<T>(callback: (this: NoInfer<T> | undefined, key: isSubClass<this> extends true ? MaybeAttrFields<this> : string, meta: LegacyAttributeField) => void, binding?: T): void;
|
|
829
796
|
/**
|
|
830
|
-
* @internal
|
|
831
|
-
*/
|
|
832
|
-
static isModel: boolean;
|
|
833
|
-
/**
|
|
834
797
|
Represents the model's class name as a string. This can be used to look up the model's class name through
|
|
835
798
|
`Store`'s modelFor method.
|
|
836
799
|
|
|
@@ -860,22 +823,6 @@ declare class Model extends EmberObject implements MinimalLegacyRecord {
|
|
|
860
823
|
@readonly
|
|
861
824
|
*/
|
|
862
825
|
static modelName: string;
|
|
863
|
-
/*
|
|
864
|
-
These class methods below provide relationship
|
|
865
|
-
introspection abilities about relationships.
|
|
866
|
-
|
|
867
|
-
A note about the computed properties contained here:
|
|
868
|
-
|
|
869
|
-
**These properties are effectively sealed once called for the first time.**
|
|
870
|
-
To avoid repeatedly doing expensive iteration over a model's fields, these
|
|
871
|
-
values are computed once and then cached for the remainder of the runtime of
|
|
872
|
-
your application.
|
|
873
|
-
|
|
874
|
-
If your application needs to modify a class after its initial definition
|
|
875
|
-
(for example, using `reopen()` to add additional attributes), make sure you
|
|
876
|
-
do it before using your model with the store, which uses these properties
|
|
877
|
-
extensively.
|
|
878
|
-
*/
|
|
879
826
|
/**
|
|
880
827
|
For a given relationship name, returns the model type of the relationship.
|
|
881
828
|
|
|
@@ -892,9 +839,9 @@ declare class Model extends EmberObject implements MinimalLegacyRecord {
|
|
|
892
839
|
Calling `store.modelFor('post').typeForRelationship('comments', store)` will return `Comment`.
|
|
893
840
|
|
|
894
841
|
@public
|
|
895
|
-
@param
|
|
896
|
-
@param
|
|
897
|
-
@return
|
|
842
|
+
@param name the name of the relationship
|
|
843
|
+
@param store an instance of Store
|
|
844
|
+
@return the type of the relationship, or undefined
|
|
898
845
|
*/
|
|
899
846
|
static typeForRelationship(name: string, store: Store): ModelSchema | undefined;
|
|
900
847
|
static get inverseMap(): Record<string, LegacyRelationshipField | null>;
|
|
@@ -925,12 +872,11 @@ declare class Model extends EmberObject implements MinimalLegacyRecord {
|
|
|
925
872
|
```
|
|
926
873
|
|
|
927
874
|
@public
|
|
928
|
-
@param
|
|
929
|
-
@param
|
|
930
|
-
@return
|
|
875
|
+
@param name the name of the relationship
|
|
876
|
+
@param store
|
|
877
|
+
@return the inverse relationship, or null
|
|
931
878
|
*/
|
|
932
879
|
static inverseFor(name: string, store: Store): LegacyRelationshipField | null;
|
|
933
|
-
//Calculate the inverse, ignoring the cache
|
|
934
880
|
static _findInverseFor(name: string, store: Store): LegacyRelationshipField | null;
|
|
935
881
|
/**
|
|
936
882
|
The model's relationships as a map, keyed on the type of the
|
|
@@ -1319,4 +1265,5 @@ declare class Model extends EmberObject implements MinimalLegacyRecord {
|
|
|
1319
1265
|
*/
|
|
1320
1266
|
static toString(): string;
|
|
1321
1267
|
}
|
|
1268
|
+
export declare function restoreDeprecatedModelRequestBehaviors(ModelKlass: typeof Model): void;
|
|
1322
1269
|
export { Model };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { NotificationType, Store } from "@warp-drive/core";
|
|
2
|
-
import type {
|
|
2
|
+
import type { ResourceKey } from "@warp-drive/core/types/identifier";
|
|
3
3
|
import type { Model } from "./model.js";
|
|
4
|
-
export default function notifyChanges(identifier:
|
|
4
|
+
export default function notifyChanges(identifier: ResourceKey, value: NotificationType, key: string | undefined, record: Model, store: Store): void;
|
|
@@ -16,13 +16,10 @@ export interface BelongsToProxyCreateArgs<T = unknown> {
|
|
|
16
16
|
}
|
|
17
17
|
export declare const LegacyPromiseProxy: unique symbol;
|
|
18
18
|
interface PromiseObjectType<T> extends PromiseProxyMixin<T | null>, ObjectProxy<T> {
|
|
19
|
-
// eslint-disable-next-line @typescript-eslint/no-misused-new
|
|
20
19
|
new <PT>(...args: unknown[]): PromiseObjectType<PT>;
|
|
21
20
|
}
|
|
22
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-extraneous-class
|
|
23
21
|
declare class PromiseObjectType<T> {}
|
|
24
22
|
declare const Extended: PromiseObjectType<OpaqueRecordInstance>;
|
|
25
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
26
23
|
interface PromiseBelongsTo<T> {
|
|
27
24
|
[LegacyPromiseProxy]: true;
|
|
28
25
|
}
|
|
@@ -37,9 +34,6 @@ Right now we proxy:
|
|
|
37
34
|
declare class PromiseBelongsTo<T = unknown> extends Extended<T> {
|
|
38
35
|
_belongsToState: BelongsToProxyMeta<T>;
|
|
39
36
|
get id(): string | null;
|
|
40
|
-
// we don't proxy meta because we would need to proxy it to the relationship state container
|
|
41
|
-
// however, meta on relationships does not trigger change notifications.
|
|
42
|
-
// if you need relationship meta, you should do `record.belongsTo(relationshipName).meta()`
|
|
43
37
|
get meta(): void;
|
|
44
38
|
reload(options: Record<string, unknown>): Promise<this>;
|
|
45
39
|
}
|
|
@@ -6,7 +6,6 @@ export interface HasManyProxyCreateArgs<T = unknown> {
|
|
|
6
6
|
promise: Promise<ManyArray<T>>;
|
|
7
7
|
content?: ManyArray<T>;
|
|
8
8
|
}
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
10
9
|
export interface PromiseManyArray<T> {
|
|
11
10
|
[LegacyPromiseProxy]: true;
|
|
12
11
|
}
|
|
@@ -37,10 +36,6 @@ export declare class PromiseManyArray<T = unknown> {
|
|
|
37
36
|
* @public
|
|
38
37
|
*/
|
|
39
38
|
get length(): number;
|
|
40
|
-
// this will error if someone tries to call
|
|
41
|
-
// A(identifierArray) since it is not configurable
|
|
42
|
-
// which is preferrable to the `meta` override we used
|
|
43
|
-
// before which required importing all of Ember
|
|
44
39
|
get "[]"(): 0 | ManyArray<T> | undefined;
|
|
45
40
|
/**
|
|
46
41
|
* Iterate the proxied content. Called by the glimmer iterator in #each
|
|
@@ -59,7 +54,6 @@ export declare class PromiseManyArray<T = unknown> {
|
|
|
59
54
|
* @return
|
|
60
55
|
*/
|
|
61
56
|
reload(options: Omit<BaseFinderOptions, "">): this;
|
|
62
|
-
//---- Properties/Methods from the PromiseProxyMixin that we will keep as our API
|
|
63
57
|
/**
|
|
64
58
|
* Whether the loading promise is still pending
|
|
65
59
|
*
|
|
@@ -113,9 +107,7 @@ export declare class PromiseManyArray<T = unknown> {
|
|
|
113
107
|
* @return {Promise}
|
|
114
108
|
*/
|
|
115
109
|
finally(cb: Parameters<Promise<ManyArray<T>>["finally"]>[0]): Promise<unknown>;
|
|
116
|
-
//---- Methods on EmberObject that we should keep
|
|
117
110
|
destroy(): void;
|
|
118
|
-
//---- Methods/Properties on ManyArray that we own and proxy to
|
|
119
111
|
/**
|
|
120
112
|
* Retrieve the links for this relationship
|
|
121
113
|
* @property links
|
|
@@ -128,8 +120,5 @@ export declare class PromiseManyArray<T = unknown> {
|
|
|
128
120
|
* @public
|
|
129
121
|
*/
|
|
130
122
|
get meta(): Record<string, unknown> | null | undefined;
|
|
131
|
-
//---- Our own stuff
|
|
132
|
-
/** @internal */
|
|
133
|
-
_update(promise: Promise<ManyArray<T>>, content?: ManyArray<T>): void;
|
|
134
123
|
static create<T>({ promise, content }: HasManyProxyCreateArgs<T>): PromiseManyArray<T>;
|
|
135
124
|
}
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
import type { Store } from "@warp-drive/core";
|
|
2
|
-
import type { RequestCacheRequestState, RequestStateService } from "@warp-drive/core/store/-private";
|
|
3
|
-
import type { Cache } from "@warp-drive/core/types/cache";
|
|
4
|
-
import type { StableRecordIdentifier } from "@warp-drive/core/types/identifier";
|
|
5
|
-
import type { Errors } from "./errors.js";
|
|
6
1
|
import type { MinimalLegacyRecord } from "./model-methods.js";
|
|
7
2
|
/**
|
|
8
3
|
Historically EmberData managed a state machine
|
|
@@ -41,29 +36,11 @@ uncommitted
|
|
|
41
36
|
invalid
|
|
42
37
|
inFlight
|
|
43
38
|
|
|
44
|
-
@
|
|
39
|
+
@hideconstructor
|
|
40
|
+
@private
|
|
45
41
|
*/
|
|
46
42
|
export default class RecordState {
|
|
47
|
-
store: Store;
|
|
48
|
-
identifier: StableRecordIdentifier;
|
|
49
|
-
record: MinimalLegacyRecord;
|
|
50
|
-
rs: RequestStateService;
|
|
51
|
-
pendingCount: number;
|
|
52
|
-
fulfilledCount: number;
|
|
53
|
-
rejectedCount: number;
|
|
54
|
-
cache: Cache;
|
|
55
|
-
_errorRequests: RequestCacheRequestState[];
|
|
56
|
-
_lastError: RequestCacheRequestState | null;
|
|
57
|
-
handler: object;
|
|
58
43
|
constructor(record: MinimalLegacyRecord);
|
|
59
|
-
/** @internal */
|
|
60
|
-
destroy(): void;
|
|
61
|
-
/** @internal */
|
|
62
|
-
notify(key: keyof this & string): void;
|
|
63
|
-
/** @internal */
|
|
64
|
-
updateInvalidErrors(errors: Errors): void;
|
|
65
|
-
/** @internal */
|
|
66
|
-
cleanErrorRequests(): void;
|
|
67
44
|
isSaving: boolean;
|
|
68
45
|
get isLoading(): boolean;
|
|
69
46
|
get isLoaded(): boolean;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Store } from "@warp-drive/core";
|
|
2
2
|
import type { Graph, ResourceEdge } from "@warp-drive/core/graph/-private";
|
|
3
|
-
import type {
|
|
3
|
+
import type { ResourceKey } from "@warp-drive/core/types/identifier";
|
|
4
4
|
import type { TypeFromInstance, TypeFromInstanceOrString } from "@warp-drive/core/types/record";
|
|
5
5
|
import type { Links, Meta, SingleResourceDocument, SingleResourceRelationship } from "@warp-drive/core/types/spec/json-api-raw";
|
|
6
6
|
import type { IsUnknown } from "../belongs-to.js";
|
|
@@ -57,22 +57,21 @@ export default class BelongsToReference<
|
|
|
57
57
|
* @public
|
|
58
58
|
*/
|
|
59
59
|
type: TypeFromInstanceOrString<Related>;
|
|
60
|
-
// unsubscribe tokens given to us by the notification manager
|
|
61
60
|
___token: object;
|
|
62
|
-
___identifier:
|
|
61
|
+
___identifier: ResourceKey<TypeFromInstanceOrString<T>>;
|
|
63
62
|
___relatedToken: object | null;
|
|
64
63
|
_ref: number;
|
|
65
|
-
constructor(store: Store, graph: Graph, parentIdentifier:
|
|
64
|
+
constructor(store: Store, graph: Graph, parentIdentifier: ResourceKey<TypeFromInstanceOrString<T>>, belongsToRelationship: ResourceEdge, key: K);
|
|
66
65
|
destroy(): void;
|
|
67
66
|
/**
|
|
68
67
|
* The identifier of the record that this reference refers to.
|
|
69
68
|
* `null` if no related record is known.
|
|
70
69
|
*
|
|
71
70
|
* @property identifier
|
|
72
|
-
* @type {
|
|
71
|
+
* @type {ResourceKey | null}
|
|
73
72
|
* @public
|
|
74
73
|
*/
|
|
75
|
-
get identifier():
|
|
74
|
+
get identifier(): ResourceKey<TypeFromInstanceOrString<Related>> | null;
|
|
76
75
|
/**
|
|
77
76
|
The `id` of the record that this reference refers to. Together, the
|
|
78
77
|
`type()` and `id()` methods form a composite key for the identity
|
|
@@ -198,7 +197,7 @@ export default class BelongsToReference<
|
|
|
198
197
|
@return {Object} The meta information for the belongs-to relationship.
|
|
199
198
|
*/
|
|
200
199
|
meta(): Meta | null;
|
|
201
|
-
_resource(): SingleResourceRelationship<
|
|
200
|
+
_resource(): SingleResourceRelationship<ResourceKey<TypeFromInstance<Related>>>;
|
|
202
201
|
/**
|
|
203
202
|
This returns a string that represents how the reference will be
|
|
204
203
|
looked up when it is loaded. If the relationship has a link it will
|
|
@@ -2,7 +2,7 @@ import type { Store } from "@warp-drive/core";
|
|
|
2
2
|
import type { CollectionEdge, Graph } from "@warp-drive/core/graph/-private";
|
|
3
3
|
import type { RelatedCollection as ManyArray } from "@warp-drive/core/store/-private";
|
|
4
4
|
import type { BaseFinderOptions } from "@warp-drive/core/types";
|
|
5
|
-
import type {
|
|
5
|
+
import type { ResourceKey } from "@warp-drive/core/types/identifier";
|
|
6
6
|
import type { TypeFromInstanceOrString } from "@warp-drive/core/types/record";
|
|
7
7
|
import type { CollectionResourceDocument, CollectionResourceRelationship, ExistingResourceObject, LinkObject, Meta, PaginationLinks } from "@warp-drive/core/types/spec/json-api-raw";
|
|
8
8
|
import type { IsUnknown } from "../belongs-to.js";
|
|
@@ -66,26 +66,19 @@ export default class HasManyReference<
|
|
|
66
66
|
* @public
|
|
67
67
|
*/
|
|
68
68
|
type: TypeFromInstanceOrString<Related>;
|
|
69
|
-
// unsubscribe tokens given to us by the notification manager
|
|
70
69
|
___token: object;
|
|
71
|
-
___identifier:
|
|
72
|
-
___relatedTokenMap: Map<
|
|
70
|
+
___identifier: ResourceKey<TypeFromInstanceOrString<T>>;
|
|
71
|
+
___relatedTokenMap: Map<ResourceKey, object>;
|
|
73
72
|
_ref: number;
|
|
74
|
-
constructor(store: Store, graph: Graph, parentIdentifier:
|
|
75
|
-
/**
|
|
76
|
-
* This method should never be called by user code.
|
|
77
|
-
*
|
|
78
|
-
* @internal
|
|
79
|
-
*/
|
|
80
|
-
destroy(): void;
|
|
73
|
+
constructor(store: Store, graph: Graph, parentIdentifier: ResourceKey<TypeFromInstanceOrString<T>>, hasManyRelationship: CollectionEdge, key: K);
|
|
81
74
|
/**
|
|
82
75
|
* An array of identifiers for the records that this reference refers to.
|
|
83
76
|
*
|
|
84
77
|
* @property identifiers
|
|
85
|
-
* @type {
|
|
78
|
+
* @type {ResourceKey[]}
|
|
86
79
|
* @public
|
|
87
80
|
*/
|
|
88
|
-
get identifiers():
|
|
81
|
+
get identifiers(): ResourceKey<TypeFromInstanceOrString<Related>>[];
|
|
89
82
|
_resource(): CollectionResourceRelationship;
|
|
90
83
|
/**
|
|
91
84
|
This returns a string that represents how the reference will be
|