@warp-drive/core 5.7.0-alpha.2 → 5.7.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/declarations/graph/-private/-diff.d.ts +8 -8
- package/declarations/graph/-private/-edge-definition.d.ts +2 -2
- package/declarations/graph/-private/-state.d.ts +2 -2
- package/declarations/graph/-private/-utils.d.ts +5 -5
- package/declarations/graph/-private/debug/assert-polymorphic-type.d.ts +3 -3
- package/declarations/graph/-private/edges/collection.d.ts +10 -10
- package/declarations/graph/-private/edges/implicit.d.ts +5 -5
- package/declarations/graph/-private/edges/resource.d.ts +5 -5
- package/declarations/graph/-private/graph.d.ts +17 -15
- package/declarations/graph/-private/operations/replace-related-records.d.ts +4 -4
- package/declarations/graph/-private/operations/update-relationship.d.ts +3 -3
- package/declarations/index.d.ts +1 -1
- package/declarations/reactive/-private/default-mode.d.ts +73 -0
- package/declarations/reactive/-private/document.d.ts +11 -21
- package/declarations/reactive/-private/fields/get-field-key.d.ts +8 -0
- package/declarations/reactive/-private/fields/managed-array.d.ts +7 -10
- package/declarations/reactive/-private/fields/managed-object.d.ts +7 -9
- package/declarations/reactive/-private/fields/many-array-manager.d.ts +2 -2
- package/declarations/reactive/-private/hooks.d.ts +2 -2
- package/declarations/reactive/-private/kind/alias-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/array-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/attribute-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/belongs-to-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/collection-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/derived-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/generic-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/has-many-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/hash-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/identity-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/local-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/object-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/resource-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/schema-array-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/schema-object-field.d.ts +4 -0
- package/declarations/reactive/-private/record.d.ts +50 -25
- package/declarations/reactive/-private/schema.d.ts +18 -14
- package/declarations/reactive/-private/symbols.d.ts +2 -7
- package/declarations/reactive/-private.d.ts +1 -1
- package/declarations/reactive.d.ts +278 -1
- package/declarations/request/-private/context.d.ts +2 -2
- package/declarations/request/-private/fetch.d.ts +2 -0
- package/declarations/request/-private/manager.d.ts +3 -6
- package/declarations/request/-private/types.d.ts +4 -4
- package/declarations/request/-private/utils.d.ts +44 -2
- package/declarations/store/-private/cache-handler/handler.d.ts +2 -8
- package/declarations/store/-private/cache-handler/types.d.ts +10 -10
- package/declarations/store/-private/cache-handler/utils.d.ts +4 -4
- package/declarations/store/-private/caches/instance-cache.d.ts +20 -18
- package/declarations/store/-private/default-cache-policy.d.ts +25 -38
- package/declarations/store/-private/managers/cache-capabilities-manager.d.ts +13 -11
- package/declarations/store/-private/{caches/identifier-cache.d.ts → managers/cache-key-manager.d.ts} +22 -19
- package/declarations/store/-private/managers/cache-manager.d.ts +46 -94
- package/declarations/store/-private/managers/notification-manager.d.ts +21 -25
- package/declarations/store/-private/managers/record-array-manager.d.ts +78 -27
- package/declarations/store/-private/network/request-cache.d.ts +11 -11
- package/declarations/store/-private/new-core-tmp/expensive-subscription.d.ts +24 -0
- package/declarations/store/-private/new-core-tmp/reactivity/signal.d.ts +1 -0
- package/declarations/store/-private/new-core-tmp/request-state.d.ts +15 -22
- package/declarations/store/-private/new-core-tmp/request-subscription.d.ts +4 -8
- package/declarations/store/-private/record-arrays/-utils.d.ts +82 -0
- package/declarations/store/-private/record-arrays/legacy-live-array.d.ts +89 -0
- package/declarations/store/-private/record-arrays/{many-array.d.ts → legacy-many-array.d.ts} +43 -101
- package/declarations/store/-private/record-arrays/legacy-query.d.ts +103 -0
- package/declarations/store/-private/record-arrays/resource-array.d.ts +82 -0
- package/declarations/store/-private/store-service.d.ts +78 -35
- package/declarations/store/-private.d.ts +5 -5
- package/declarations/store/-types/q/cache-capabilities-manager.d.ts +15 -24
- package/declarations/store/-types/q/identifier.d.ts +9 -6
- package/declarations/store/-types/q/schema-service.d.ts +28 -40
- package/declarations/store/-types/q/store.d.ts +6 -7
- package/declarations/store/deprecated/-private.d.ts +12 -12
- package/declarations/store/deprecated/store.d.ts +11 -12
- package/declarations/types/-private.d.ts +1 -1
- package/declarations/types/cache/aliases.d.ts +2 -2
- package/declarations/types/cache/change.d.ts +2 -2
- package/declarations/types/cache/mutations.d.ts +13 -13
- package/declarations/types/cache/operations.d.ts +115 -32
- package/declarations/types/cache/relationship.d.ts +4 -4
- package/declarations/types/cache.d.ts +51 -113
- package/declarations/types/graph.d.ts +12 -12
- package/declarations/types/identifier.d.ts +60 -76
- package/declarations/types/params.d.ts +2 -3
- package/declarations/types/request.d.ts +47 -35
- package/declarations/types/schema/concepts.d.ts +2 -2
- package/declarations/types/schema/fields.d.ts +378 -14
- package/declarations/types/spec/document.d.ts +6 -6
- package/dist/{context-COmAnXUQ.js → context-kQXhkeBj.js} +13 -0
- package/dist/graph/-private.js +135 -139
- package/dist/index.js +6 -3
- package/dist/reactive/-private.js +1 -1
- package/dist/reactive.js +193 -1409
- package/dist/{request-state-CejVJgdj.js → request-state-glkInb2R.js} +5139 -2758
- package/dist/request.js +1 -1
- package/dist/store/-private.js +1 -2
- package/dist/store.js +32 -44
- package/dist/{symbols-SIstXMLI.js → symbols-sql1_mdx.js} +3 -8
- package/dist/types/-private.js +1 -1
- package/dist/types/identifier.js +19 -45
- package/dist/types/request.js +27 -0
- package/dist/types/schema/fields.js +23 -2
- package/package.json +3 -3
- package/declarations/reactive/-private/fields/compute.d.ts +0 -43
- package/declarations/store/-private/caches/cache-utils.d.ts +0 -12
- package/declarations/store/-private/record-arrays/identifier-array.d.ts +0 -147
- package/dist/handler-D2jjnIA-.js +0 -339
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { GenericField } from "../../../types/schema/fields.js";
|
|
2
|
+
import type { KindContext } from "../default-mode.js";
|
|
3
|
+
export declare function getGenericField(context: KindContext<GenericField>): unknown;
|
|
4
|
+
export declare function setGenericField(context: KindContext<GenericField>): boolean;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { LegacyHasManyField } from "../../../types/schema/fields.js";
|
|
2
|
+
import type { KindContext } from "../default-mode.js";
|
|
3
|
+
export declare function getHasManyField(context: KindContext<LegacyHasManyField>): unknown;
|
|
4
|
+
export declare function setHasManyField(context: KindContext<LegacyHasManyField>): boolean;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { HashField } from "../../../types/schema/fields.js";
|
|
2
|
+
import type { KindContext } from "../default-mode.js";
|
|
3
|
+
export declare function getHashField(context: KindContext<HashField>): unknown;
|
|
4
|
+
export declare function setHashField(context: KindContext<HashField>): boolean;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { IdentityField } from "../../../types/schema/fields.js";
|
|
2
|
+
import type { KindContext } from "../default-mode.js";
|
|
3
|
+
export declare function getIdentityField(context: KindContext<IdentityField>): unknown;
|
|
4
|
+
export declare function setIdentityField(context: KindContext<IdentityField>): boolean;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { LocalField } from "../../../types/schema/fields.js";
|
|
2
|
+
import type { KindContext } from "../default-mode.js";
|
|
3
|
+
export declare function getLocalField(context: KindContext<LocalField>): unknown;
|
|
4
|
+
export declare function setLocalField(context: KindContext<LocalField>): boolean;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ObjectField } from "../../../types/schema/fields.js";
|
|
2
|
+
import type { KindContext } from "../default-mode.js";
|
|
3
|
+
export declare function getObjectField(context: KindContext<ObjectField>): unknown;
|
|
4
|
+
export declare function setObjectField(context: KindContext<ObjectField>): boolean;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ResourceField } from "../../../types/schema/fields.js";
|
|
2
|
+
import type { KindContext } from "../default-mode.js";
|
|
3
|
+
export declare function getResourceField(context: KindContext<ResourceField>): unknown;
|
|
4
|
+
export declare function setResourceField(context: KindContext<ResourceField>): boolean;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { SchemaArrayField } from "../../../types/schema/fields.js";
|
|
2
|
+
import type { KindContext } from "../default-mode.js";
|
|
3
|
+
export { getArrayField as getSchemaArrayField } from "./array-field.js";
|
|
4
|
+
export declare function setSchemaArrayField(context: KindContext<SchemaArrayField>): boolean;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { SchemaObjectField } from "../../../types/schema/fields.js";
|
|
2
|
+
import type { KindContext } from "../default-mode.js";
|
|
3
|
+
export declare function getSchemaObjectField(context: KindContext<SchemaObjectField>): unknown;
|
|
4
|
+
export declare function setSchemaObjectField(context: KindContext<SchemaObjectField>): boolean;
|
|
@@ -1,37 +1,28 @@
|
|
|
1
|
-
import type { Store } from "../../
|
|
2
|
-
import type { StableRecordIdentifier } from "../../types/identifier.js";
|
|
3
|
-
import type { SchemaArrayField, SchemaObjectField } from "../../types/schema/fields.js";
|
|
1
|
+
import type { Store } from "../../store/-private.js";
|
|
4
2
|
import { RecordStore } from "../../types/symbols.js";
|
|
5
|
-
import {
|
|
6
|
-
|
|
3
|
+
import type { ObjectContext, ResourceContext } from "./default-mode.js";
|
|
4
|
+
import { Checkout, Commit, Context, Destroy } from "./symbols.js";
|
|
7
5
|
export interface ReactiveResource {
|
|
8
|
-
[Symbol.toStringTag]: `ReactiveResource<${string}>`;
|
|
9
|
-
/** @internal */
|
|
10
|
-
[RecordStore]: Store;
|
|
11
|
-
/** @internal */
|
|
12
|
-
[Identifier]: StableRecordIdentifier;
|
|
13
6
|
/** @internal */
|
|
14
|
-
[
|
|
15
|
-
/** @internal */
|
|
16
|
-
[EmbeddedField]: SchemaArrayField | SchemaObjectField | null;
|
|
17
|
-
/** @internal */
|
|
18
|
-
[EmbeddedPath]: string[] | null;
|
|
7
|
+
[Symbol.toStringTag]: `ReactiveResource<${string}>`;
|
|
19
8
|
/** @internal */
|
|
20
|
-
[
|
|
9
|
+
[Context]: ObjectContext | ResourceContext;
|
|
21
10
|
/** @internal */
|
|
22
|
-
[
|
|
11
|
+
[RecordStore]: Store;
|
|
23
12
|
/** @internal */
|
|
24
13
|
___notifications: object;
|
|
25
14
|
/** @internal */
|
|
26
15
|
[Destroy](): void;
|
|
16
|
+
/** @internal */
|
|
17
|
+
[Commit](): Promise<void>;
|
|
27
18
|
/**
|
|
28
19
|
* Create an editable copy of the record
|
|
29
20
|
*
|
|
30
21
|
* ReactiveResource instances are not editable by default. This method creates an editable copy of the record. To use,
|
|
31
|
-
* import the `Checkout` symbol from `@warp-drive/
|
|
22
|
+
* import the `Checkout` symbol from `@warp-drive/core/reactive` and call it on the record.
|
|
32
23
|
*
|
|
33
24
|
* ```ts
|
|
34
|
-
* import { Checkout } from '@warp-drive/
|
|
25
|
+
* import { Checkout } from '@warp-drive/core/reactive';
|
|
35
26
|
*
|
|
36
27
|
* const record = store.peekRecord('user', '1');
|
|
37
28
|
* const editableRecord = await record[Checkout]();
|
|
@@ -39,13 +30,13 @@ export interface ReactiveResource {
|
|
|
39
30
|
*
|
|
40
31
|
* @returns a promise that resolves to the editable record
|
|
41
32
|
* @throws if the record is already editable or if the record is embedded
|
|
42
|
-
*
|
|
33
|
+
* @internal
|
|
43
34
|
*/
|
|
44
35
|
[Checkout]<T>(): Promise<T>;
|
|
45
36
|
}
|
|
46
37
|
/**
|
|
47
38
|
* A class that uses a the ResourceSchema for a ResourceType
|
|
48
|
-
* and a
|
|
39
|
+
* and a ResourceKey to transform data from the cache into a rich, reactive
|
|
49
40
|
* object.
|
|
50
41
|
*
|
|
51
42
|
* This class is not directly instantiable. To use it, you should
|
|
@@ -57,8 +48,42 @@ export interface ReactiveResource {
|
|
|
57
48
|
*/
|
|
58
49
|
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
|
|
59
50
|
export declare class ReactiveResource {
|
|
60
|
-
constructor(
|
|
61
|
-
[Editable]: boolean;
|
|
62
|
-
[Legacy]: boolean;
|
|
63
|
-
}, isEmbedded?: boolean, embeddedField?: SchemaArrayField | SchemaObjectField | null, embeddedPath?: string[] | null);
|
|
51
|
+
constructor(context: ResourceContext | ObjectContext);
|
|
64
52
|
}
|
|
53
|
+
export declare function _CHECKOUT(record: ReactiveResource): ReactiveResource;
|
|
54
|
+
/**
|
|
55
|
+
* Checkout an immutable resource for editing.
|
|
56
|
+
*
|
|
57
|
+
* {@link ReactiveResource | ReactiveResources} are not editable by default. This method
|
|
58
|
+
* creates an editable copy of the resource.
|
|
59
|
+
*
|
|
60
|
+
* This returns a promise which resolves with the editable
|
|
61
|
+
* version of the resource.
|
|
62
|
+
*
|
|
63
|
+
* ```ts
|
|
64
|
+
* import { checkout } from '@warp-drive/core/reactive';
|
|
65
|
+
*
|
|
66
|
+
* const immutable = store.peekRecord('user', '1');
|
|
67
|
+
* const editable = await checkout(immutable);
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* Edits to editable resources will be automatically committed if a new
|
|
71
|
+
* payload from the cache matches their existing value.
|
|
72
|
+
*
|
|
73
|
+
* @public
|
|
74
|
+
*
|
|
75
|
+
* @returns a promise that resolves to the editable resource
|
|
76
|
+
* @throws if the resource is already editable or if resource is an embedded object
|
|
77
|
+
*/
|
|
78
|
+
export declare function checkout<T>(resource: unknown): Promise<T & ReactiveResource>;
|
|
79
|
+
/**
|
|
80
|
+
* Forcibly commit all local changes on an editable resource to
|
|
81
|
+
* the remote (immutable) version.
|
|
82
|
+
*
|
|
83
|
+
* This API should only be used cautiously. Typically a better
|
|
84
|
+
* approach is for either the API or a Handler to reflect saved
|
|
85
|
+
* changes back to update the cache.
|
|
86
|
+
*
|
|
87
|
+
* @public
|
|
88
|
+
*/
|
|
89
|
+
export declare function commit(record: ReactiveResource): Promise<void>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Store } from "../../store/-private.js";
|
|
2
2
|
import type { SchemaService as SchemaServiceInterface } from "../../types.js";
|
|
3
|
-
import type {
|
|
3
|
+
import type { ResourceKey } from "../../types/identifier.js";
|
|
4
4
|
import type { ObjectValue, Value } from "../../types/json/raw.js";
|
|
5
5
|
import type { Derivation, HashFn } from "../../types/schema/concepts.js";
|
|
6
|
-
import { type ArrayField, type DerivedField, type FieldSchema, type GenericField, type HashField, type LegacyAttributeField, type LegacyBelongsToField, type LegacyHasManyField, type LegacyRelationshipField, type ObjectField, type ObjectSchema, type PolarisResourceSchema, type ResourceSchema, type Trait } from "../../types/schema/fields.js";
|
|
6
|
+
import { type ArrayField, type CacheableFieldSchema, type DerivedField, type FieldSchema, type GenericField, type HashField, type IdentityField, type LegacyAttributeField, type LegacyBelongsToField, type LegacyHasManyField, type LegacyRelationshipField, type ObjectField, type ObjectSchema, type PolarisResourceSchema, type ResourceSchema, type Trait } from "../../types/schema/fields.js";
|
|
7
7
|
import { Type } from "../../types/symbols.js";
|
|
8
8
|
import type { WithPartial } from "../../types/utils.js";
|
|
9
9
|
import type { ReactiveResource } from "./record.js";
|
|
@@ -95,11 +95,11 @@ interface FromIdentityDerivation {
|
|
|
95
95
|
}, key: string): string | null;
|
|
96
96
|
(record: ReactiveResource, options: {
|
|
97
97
|
key: "^";
|
|
98
|
-
}, key: string):
|
|
98
|
+
}, key: string): ResourceKey;
|
|
99
99
|
(record: ReactiveResource, options: null, key: string): asserts options;
|
|
100
100
|
(record: ReactiveResource, options: {
|
|
101
101
|
key: "id" | "lid" | "type" | "^";
|
|
102
|
-
} | null, key: string):
|
|
102
|
+
} | null, key: string): ResourceKey | string | null;
|
|
103
103
|
[Type]: "@identity";
|
|
104
104
|
}
|
|
105
105
|
/**
|
|
@@ -141,6 +141,7 @@ interface InternalSchema {
|
|
|
141
141
|
finalized: boolean;
|
|
142
142
|
traits: Set<string>;
|
|
143
143
|
fields: Map<string, FieldSchema>;
|
|
144
|
+
cacheFields: Map<string, Exclude<CacheableFieldSchema, IdentityField>>;
|
|
144
145
|
attributes: Record<string, LegacyAttributeField>;
|
|
145
146
|
relationships: Record<string, LegacyRelationshipField>;
|
|
146
147
|
}
|
|
@@ -150,18 +151,18 @@ export type Transformation<
|
|
|
150
151
|
> = {
|
|
151
152
|
serialize(value: PT, options: Record<string, unknown> | null, record: ReactiveResource): T;
|
|
152
153
|
hydrate(value: T | undefined, options: Record<string, unknown> | null, record: ReactiveResource): PT;
|
|
153
|
-
defaultValue?(options: Record<string, unknown> | null, identifier:
|
|
154
|
+
defaultValue?(options: Record<string, unknown> | null, identifier: ResourceKey): T;
|
|
154
155
|
[Type]: string;
|
|
155
156
|
};
|
|
156
157
|
interface KindFns {
|
|
157
158
|
belongsTo: {
|
|
158
|
-
get: (store: Store, record: object, resourceKey:
|
|
159
|
-
set: (store: Store, record: object, cacheKey:
|
|
159
|
+
get: (store: Store, record: object, resourceKey: ResourceKey, field: LegacyBelongsToField) => unknown;
|
|
160
|
+
set: (store: Store, record: object, cacheKey: ResourceKey, field: LegacyBelongsToField, value: unknown) => void;
|
|
160
161
|
};
|
|
161
162
|
hasMany: {
|
|
162
|
-
get: (store: Store, record: object, resourceKey:
|
|
163
|
-
set: (store: Store, record: object, cacheKey:
|
|
164
|
-
notify: (store: Store, record: object, cacheKey:
|
|
163
|
+
get: (store: Store, record: object, resourceKey: ResourceKey, field: LegacyHasManyField) => unknown;
|
|
164
|
+
set: (store: Store, record: object, cacheKey: ResourceKey, field: LegacyHasManyField, value: unknown) => void;
|
|
165
|
+
notify: (store: Store, record: object, cacheKey: ResourceKey, field: LegacyHasManyField) => boolean;
|
|
165
166
|
};
|
|
166
167
|
}
|
|
167
168
|
export interface SchemaService {
|
|
@@ -211,7 +212,7 @@ export declare class SchemaService implements SchemaServiceInterface {
|
|
|
211
212
|
constructor();
|
|
212
213
|
resourceTypes(): Readonly<string[]>;
|
|
213
214
|
hasTrait(type: string): boolean;
|
|
214
|
-
resourceHasTrait(resource:
|
|
215
|
+
resourceHasTrait(resource: ResourceKey | {
|
|
215
216
|
type: string;
|
|
216
217
|
}, trait: string): boolean;
|
|
217
218
|
transformation(field: GenericField | ObjectField | ArrayField | {
|
|
@@ -223,7 +224,7 @@ export declare class SchemaService implements SchemaServiceInterface {
|
|
|
223
224
|
hashFn(field: HashField | {
|
|
224
225
|
type: string;
|
|
225
226
|
}): HashFn;
|
|
226
|
-
resource(resource:
|
|
227
|
+
resource(resource: ResourceKey | {
|
|
227
228
|
type: string;
|
|
228
229
|
}): ResourceSchema | ObjectSchema;
|
|
229
230
|
registerResources(schemas: Array<ResourceSchema | ObjectSchema>): void;
|
|
@@ -267,10 +268,10 @@ export declare class SchemaService implements SchemaServiceInterface {
|
|
|
267
268
|
FM extends ObjectValue | null
|
|
268
269
|
>(derivation: Derivation<R, T, FM>): void;
|
|
269
270
|
CAUTION_MEGA_DANGER_ZONE_registerExtension(extension: CAUTION_MEGA_DANGER_ZONE_Extension): void;
|
|
270
|
-
CAUTION_MEGA_DANGER_ZONE_resourceExtensions(resource:
|
|
271
|
+
CAUTION_MEGA_DANGER_ZONE_resourceExtensions(resource: ResourceKey | {
|
|
271
272
|
type: string;
|
|
272
273
|
}): null | ProcessedExtension["features"];
|
|
273
|
-
CAUTION_MEGA_DANGER_ZONE_objectExtensions(field: ExtensibleField): null | ProcessedExtension["features"];
|
|
274
|
+
CAUTION_MEGA_DANGER_ZONE_objectExtensions(field: ExtensibleField, resolvedType: string | null): null | ProcessedExtension["features"];
|
|
274
275
|
CAUTION_MEGA_DANGER_ZONE_arrayExtensions(field: ExtensibleField): null | ProcessedExtension["features"];
|
|
275
276
|
CAUTION_MEGA_DANGER_ZONE_hasExtension(ext: {
|
|
276
277
|
kind: "object" | "array";
|
|
@@ -304,6 +305,9 @@ export declare class SchemaService implements SchemaServiceInterface {
|
|
|
304
305
|
fields({ type }: {
|
|
305
306
|
type: string;
|
|
306
307
|
}): InternalSchema["fields"];
|
|
308
|
+
cacheFields({ type }: {
|
|
309
|
+
type: string;
|
|
310
|
+
}): InternalSchema["cacheFields"];
|
|
307
311
|
hasResource(resource: {
|
|
308
312
|
type: string;
|
|
309
313
|
}): boolean;
|
|
@@ -25,12 +25,7 @@
|
|
|
25
25
|
// Note that none of these symbols are part of the public API, these are used for
|
|
26
26
|
// debugging DX and as a safe way to provide an intimate contract on public objects.
|
|
27
27
|
export declare const SOURCE: "___(unique) Symbol(SOURCE)";
|
|
28
|
-
export declare const MUTATE: "___(unique) Symbol(MUTATE)";
|
|
29
28
|
export declare const Destroy: "___(unique) Symbol(Destroy)";
|
|
30
|
-
export declare const Identifier: "___(unique) Symbol(Identifier)";
|
|
31
|
-
export declare const Editable: "___(unique) Symbol(Editable)";
|
|
32
|
-
export declare const Parent: "___(unique) Symbol(Parent)";
|
|
33
29
|
export declare const Checkout: "___(unique) Symbol(Checkout)";
|
|
34
|
-
export declare const
|
|
35
|
-
export declare const
|
|
36
|
-
export declare const EmbeddedField: "___(unique) Symbol(EmbeddedField)";
|
|
30
|
+
export declare const Commit: "___(unique) Symbol(Commit)";
|
|
31
|
+
export declare const Context: "___(unique) Symbol(Context)";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { Context } from "./-private/symbols.js";
|
|
@@ -1,4 +1,281 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* # About
|
|
3
|
+
*
|
|
4
|
+
* This module provides an implementation of reactive objects that a Store may use for creating
|
|
5
|
+
* reactive representations of the raw data for requests, resources and their relationships
|
|
6
|
+
* stored in the cache.
|
|
7
|
+
*
|
|
8
|
+
* - For configuring the store to use these reactive objects, see [The Setup Guide](/guides/1-configuration/2-setup/1-universal.md)
|
|
9
|
+
* - For defining resource schemas, see [The Schema Guide](/guides)
|
|
10
|
+
*
|
|
11
|
+
* Any method that returns a record instance will use the `instantiateRecord`
|
|
12
|
+
* hook configured above to instantiate a ReactiveResource once this is in place.
|
|
13
|
+
* After that, its up to you what ReactiveResource can do.
|
|
14
|
+
*
|
|
15
|
+
* ## Modes
|
|
16
|
+
*
|
|
17
|
+
* ReactiveResource has two modes: `legacy` and `polaris`.
|
|
18
|
+
*
|
|
19
|
+
* **LegacyMode** can be used to emulate the behaviors and capabilities of WarpDrive's `Model` class,
|
|
20
|
+
* and because there is little distinction between Model and a ReactiveResource in LegacyMode we refer
|
|
21
|
+
* to both of these approaches as LegacyMode. This mode is the default experience in V5.
|
|
22
|
+
*
|
|
23
|
+
* In LegacyMode:
|
|
24
|
+
*
|
|
25
|
+
* - records are mutable
|
|
26
|
+
* - local changes immediately reflect app wide
|
|
27
|
+
* - records have all the APIs of Model (references, state props, currentState, methods etc)
|
|
28
|
+
* - the continued use of `@warp-drive/legacy` is required (though most imports from it can be removed)
|
|
29
|
+
* - `async: true` relationships are supported (but not recommended outside of [LinksMode](https://github.com/emberjs/data/blob/main/guides/relationships/features/links-mode.md))
|
|
30
|
+
*
|
|
31
|
+
* ---
|
|
32
|
+
*
|
|
33
|
+
* **PolarisMode** is an upcoming suite of features that will become the default experience in V6.
|
|
34
|
+
*
|
|
35
|
+
* In PolarisMode:
|
|
36
|
+
*
|
|
37
|
+
* - records are immutable, unless creating a new resource or explicitly checking out a record for editing
|
|
38
|
+
* - local changes are isolated until committed, displaying only via the editable version of the record
|
|
39
|
+
* - records have a more limited API, focused on only what is in their schema.
|
|
40
|
+
* - some common operations may have more friction to perform because intended utilities are not yet available
|
|
41
|
+
* - `async: true` relationships are not supported (see [LinksMode](https://github.com/emberjs/data/blob/main/guides/relationships/features/links-mode.md))
|
|
42
|
+
* - The `@warp-drive/legacy` package is not required
|
|
43
|
+
*
|
|
44
|
+
* These modes are interopable. The reactive object (record) for a resource in PolarisMode can relate to
|
|
45
|
+
* a record in LegacyMode and vice-versa. This interopability is true whether the record in LegacyMode is
|
|
46
|
+
* a ReactiveResource or a Model.
|
|
47
|
+
*
|
|
48
|
+
* ---
|
|
49
|
+
*
|
|
50
|
+
* ## Basic Usage
|
|
51
|
+
*
|
|
52
|
+
* ReactiveResource is a reactive object that transforms raw data from an associated
|
|
53
|
+
* cache into reactive data backed by Signals.
|
|
54
|
+
*
|
|
55
|
+
* The shape of the object and the transformation of raw cache data into its
|
|
56
|
+
* reactive form is controlled by a resource schema.
|
|
57
|
+
*
|
|
58
|
+
* For instance, lets say your API is a [{JSON:API}](https://jsonapi.org) and your store is using
|
|
59
|
+
* the Cache provided by [@warp-drive/json-api](/api/@warp-drive/json-api), and a request
|
|
60
|
+
* returns the following raw data:
|
|
61
|
+
*
|
|
62
|
+
* ```ts
|
|
63
|
+
* {
|
|
64
|
+
* data: {
|
|
65
|
+
* type: 'user',
|
|
66
|
+
* id: '1',
|
|
67
|
+
* attributes: { firstName: 'Chris', lastName: 'Thoburn' },
|
|
68
|
+
* relationships: { pets: { data: [{ type: 'dog', id: '1' }] }}
|
|
69
|
+
* },
|
|
70
|
+
* included: [
|
|
71
|
+
* {
|
|
72
|
+
* type: 'dog',
|
|
73
|
+
* id: '1',
|
|
74
|
+
* attributes: { name: 'Rey' },
|
|
75
|
+
* relationships: { owner: { data: { type: 'user', id: '1' }}}
|
|
76
|
+
* }
|
|
77
|
+
* ]
|
|
78
|
+
* }
|
|
79
|
+
* ```
|
|
80
|
+
*
|
|
81
|
+
* We could describe the `'user'` and `'dog'` resources in the above payload
|
|
82
|
+
* with the following schemas:
|
|
83
|
+
*
|
|
84
|
+
* ```ts
|
|
85
|
+
* store.schema.registerResources([
|
|
86
|
+
* {
|
|
87
|
+
* type: 'user',
|
|
88
|
+
* identity: { type: '@id', name: 'id' },
|
|
89
|
+
* fields: [
|
|
90
|
+
* {
|
|
91
|
+
* type: '@identity',
|
|
92
|
+
* name: '$type',
|
|
93
|
+
* kind: 'derived',
|
|
94
|
+
* options: { key: 'type' },
|
|
95
|
+
* },
|
|
96
|
+
* { kind: 'field', name: 'firstName' },
|
|
97
|
+
* { kind: 'field', name: 'lastName' },
|
|
98
|
+
* {
|
|
99
|
+
* kind: 'derived',
|
|
100
|
+
* name: 'name',
|
|
101
|
+
* type: 'concat',
|
|
102
|
+
* options: { fields: ['firstName', 'lastName'], separator: ' ' }
|
|
103
|
+
* },
|
|
104
|
+
* {
|
|
105
|
+
* kind: 'hasMany',
|
|
106
|
+
* name: 'pets',
|
|
107
|
+
* type: 'pet',
|
|
108
|
+
* options: {
|
|
109
|
+
* async: false,
|
|
110
|
+
* inverse: 'owner',
|
|
111
|
+
* polymorphic: true,
|
|
112
|
+
* linksMode: true,
|
|
113
|
+
* }
|
|
114
|
+
* }
|
|
115
|
+
* ]
|
|
116
|
+
* },
|
|
117
|
+
* {
|
|
118
|
+
* type: 'dog',
|
|
119
|
+
* identity: { type: '@id', name: 'id' },
|
|
120
|
+
* fields: [
|
|
121
|
+
* {
|
|
122
|
+
* type: '@identity',
|
|
123
|
+
* name: '$type',
|
|
124
|
+
* kind: 'derived',
|
|
125
|
+
* options: { key: 'type' },
|
|
126
|
+
* },
|
|
127
|
+
* { kind: 'field', name: 'name' },
|
|
128
|
+
* {
|
|
129
|
+
* kind: 'belongsTo',
|
|
130
|
+
* name: 'owner',
|
|
131
|
+
* type: 'user',
|
|
132
|
+
* options: {
|
|
133
|
+
* async: false,
|
|
134
|
+
* inverse: 'pets',
|
|
135
|
+
* as: 'pet',
|
|
136
|
+
* linksMode: true,
|
|
137
|
+
* }
|
|
138
|
+
* }
|
|
139
|
+
* ]
|
|
140
|
+
* }
|
|
141
|
+
* ]);
|
|
142
|
+
* ```
|
|
143
|
+
*
|
|
144
|
+
* With these schemas in place, the reactive objects that the store would
|
|
145
|
+
* provide us whenever we encountered a `'user'` or a `'dog'` would be:
|
|
146
|
+
*
|
|
147
|
+
* ```ts
|
|
148
|
+
* interface Pet {
|
|
149
|
+
* readonly id: string;
|
|
150
|
+
* readonly owner: User;
|
|
151
|
+
* }
|
|
152
|
+
*
|
|
153
|
+
* interface Dog extends Pet {
|
|
154
|
+
* readonly $type: 'dog';
|
|
155
|
+
* readonly name: string;
|
|
156
|
+
* }
|
|
157
|
+
*
|
|
158
|
+
* interface EditableUser {
|
|
159
|
+
* readonly $type: 'user';
|
|
160
|
+
* readonly id: string;
|
|
161
|
+
* firstName: string;
|
|
162
|
+
* lastName: string;
|
|
163
|
+
* readonly name: string;
|
|
164
|
+
* pets: Array<Dog | Pet>;
|
|
165
|
+
* }
|
|
166
|
+
*
|
|
167
|
+
* interface User {
|
|
168
|
+
* readonly $type: 'user';
|
|
169
|
+
* readonly id: string;
|
|
170
|
+
* readonly firstName: string;
|
|
171
|
+
* readonly lastName: string;
|
|
172
|
+
* readonly name: string;
|
|
173
|
+
* readonly pets: Readonly<Array<Dog | Pet>>;
|
|
174
|
+
* [Checkout]: Promise<EditableUser>
|
|
175
|
+
* }>
|
|
176
|
+
* ```
|
|
177
|
+
*
|
|
178
|
+
* Note how based on the schema the reactive object we receive is able to produce
|
|
179
|
+
* `name` on user (despite no name field being in the cache), provide `$type`
|
|
180
|
+
* pulled from the identity of the resource, and flatten the individual attributes
|
|
181
|
+
* and relationships onto the record for easier use.
|
|
182
|
+
*
|
|
183
|
+
* Notice also how we typed this object with `readonly`. This is because while
|
|
184
|
+
* ReactiveResource instances are ***deeply reactive***, they are also ***immutable***.
|
|
185
|
+
*
|
|
186
|
+
* We can mutate a ReactiveResource only be explicitly asking permission to do so, and
|
|
187
|
+
* in the process gaining access to an editable copy. The immutable version will
|
|
188
|
+
* not show any in-process edits made to this editable copy.
|
|
189
|
+
*
|
|
190
|
+
* ```ts
|
|
191
|
+
* import { Checkout } from '@warp-drive/schema-record';
|
|
192
|
+
*
|
|
193
|
+
* const editable = await user[Checkout]();
|
|
194
|
+
* ```
|
|
195
|
+
*
|
|
196
|
+
* ## Utilities
|
|
197
|
+
*
|
|
198
|
+
* ReactiveResource provides a schema builder that simplifies setting up a couple of
|
|
199
|
+
* conventional fields like identity and `$type`. We can rewrite the schema
|
|
200
|
+
* definition above using this utility like so:
|
|
201
|
+
*
|
|
202
|
+
* ```ts
|
|
203
|
+
* import { withDefaults } from '@warp-drive/core/reactive';
|
|
204
|
+
*
|
|
205
|
+
* store.schema.registerResources([
|
|
206
|
+
* withDefaults({
|
|
207
|
+
* type: 'user',
|
|
208
|
+
* fields: [
|
|
209
|
+
* { kind: 'field', name: 'firstName' },
|
|
210
|
+
* { kind: 'field', name: 'lastName' },
|
|
211
|
+
* {
|
|
212
|
+
* kind: 'derived',
|
|
213
|
+
* name: 'name',
|
|
214
|
+
* type: 'concat',
|
|
215
|
+
* options: { fields: ['firstName', 'lastName'], separator: ' ' }
|
|
216
|
+
* },
|
|
217
|
+
* {
|
|
218
|
+
* kind: 'hasMany',
|
|
219
|
+
* name: 'pets',
|
|
220
|
+
* type: 'pet',
|
|
221
|
+
* options: {
|
|
222
|
+
* async: false,
|
|
223
|
+
* inverse: 'owner',
|
|
224
|
+
* polymorphic: true,
|
|
225
|
+
* linksMode: true,
|
|
226
|
+
* resetOnRemoteUpdate: false,
|
|
227
|
+
* }
|
|
228
|
+
* }
|
|
229
|
+
* ]
|
|
230
|
+
* }),
|
|
231
|
+
* withDefaults({
|
|
232
|
+
* type: 'dog',
|
|
233
|
+
* fields: [
|
|
234
|
+
* { kind: 'field', name: 'name' },
|
|
235
|
+
* {
|
|
236
|
+
* kind: 'belongsTo',
|
|
237
|
+
* name: 'owner',
|
|
238
|
+
* type: 'user',
|
|
239
|
+
* options: {
|
|
240
|
+
* async: false,
|
|
241
|
+
* inverse: 'pets',
|
|
242
|
+
* as: 'pet',
|
|
243
|
+
* linksMode: true,
|
|
244
|
+
* resetOnRemoteUpdate: false,
|
|
245
|
+
* }
|
|
246
|
+
* }
|
|
247
|
+
* ]
|
|
248
|
+
* })
|
|
249
|
+
* ]);
|
|
250
|
+
* ```
|
|
251
|
+
*
|
|
252
|
+
* ## Type Support
|
|
253
|
+
*
|
|
254
|
+
* ### Resource Schemas
|
|
255
|
+
*
|
|
256
|
+
* - {@link PolarisResourceSchema}
|
|
257
|
+
* - {@link LegacyResourceSchema}
|
|
258
|
+
* - {@link ObjectSchema}
|
|
259
|
+
*
|
|
260
|
+
* ### Resource Schema Type Utils
|
|
261
|
+
*
|
|
262
|
+
* - {@link resourceSchema}
|
|
263
|
+
* - {@link objectSchema}
|
|
264
|
+
* - {@link isResourceSchema}
|
|
265
|
+
* - {@link isLegacyResourceSchema}
|
|
266
|
+
*
|
|
267
|
+
* ### Field Schemas
|
|
268
|
+
*
|
|
269
|
+
* - {@link LegacyModeFieldSchema}
|
|
270
|
+
* - {@link PolarisModeFieldSchema}
|
|
271
|
+
*
|
|
272
|
+
* @module
|
|
273
|
+
*/
|
|
274
|
+
import { checkout } from "./reactive/-private/record.js";
|
|
1
275
|
export { instantiateRecord, teardownRecord } from "./reactive/-private/hooks.js";
|
|
2
276
|
export { type CAUTION_MEGA_DANGER_ZONE_Extension, type ProcessedExtension, type ExtensionDef, type Transformation, SchemaService, withDefaults, fromIdentity, registerDerivations } from "./reactive/-private/schema.js";
|
|
3
|
-
export { type ReactiveResource } from "./reactive/-private/record.js";
|
|
277
|
+
export { commit, type ReactiveResource } from "./reactive/-private/record.js";
|
|
278
|
+
export { checkout };
|
|
4
279
|
export { Checkout } from "./reactive/-private/symbols.js";
|
|
280
|
+
export { type ReactiveDocument } from "./reactive/-private/document.js";
|
|
281
|
+
export { getExpensiveRequestSubscription } from "./store/-private/new-core-tmp/expensive-subscription.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RequestKey } from "../../types/identifier.js";
|
|
2
2
|
import type { ImmutableHeaders, ImmutableRequestInfo, RequestInfo, ResponseInfo } from "../../types/request.js";
|
|
3
3
|
import type { DeferredStream, GodContext } from "./types.js";
|
|
4
4
|
export declare function upgradeHeaders(headers: Headers | ImmutableHeaders): ImmutableHeaders;
|
|
@@ -34,7 +34,7 @@ export declare class Context {
|
|
|
34
34
|
constructor(owner: ContextOwner, isCacheHandler: boolean);
|
|
35
35
|
setStream(stream: ReadableStream | Promise<ReadableStream | null>): void;
|
|
36
36
|
setResponse(response: ResponseInfo | Response | null): void;
|
|
37
|
-
setIdentifier(identifier:
|
|
37
|
+
setIdentifier(identifier: RequestKey): void;
|
|
38
38
|
get hasRequestedStream(): boolean;
|
|
39
39
|
_finalize(): void;
|
|
40
40
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RequestKey } from "../../types/identifier.js";
|
|
2
2
|
import type { RequestInfo } from "../../types/request.js";
|
|
3
3
|
import type { CacheHandler, Future, GenericCreateArgs, Handler, ManagedRequestPriority } from "./types.js";
|
|
4
4
|
import { IS_CACHE_HANDLER } from "./utils.js";
|
|
@@ -107,7 +107,7 @@ export declare class RequestManager {
|
|
|
107
107
|
*/
|
|
108
108
|
_pending: Map<number, Promise<unknown>>;
|
|
109
109
|
/** @internal */
|
|
110
|
-
_deduped: Map<
|
|
110
|
+
_deduped: Map<RequestKey, {
|
|
111
111
|
priority: ManagedRequestPriority;
|
|
112
112
|
promise: Promise<unknown>;
|
|
113
113
|
}>;
|
|
@@ -145,10 +145,7 @@ export declare class RequestManager {
|
|
|
145
145
|
* @param {RequestInfo} request
|
|
146
146
|
* @return {Future}
|
|
147
147
|
*/
|
|
148
|
-
request<
|
|
149
|
-
RT,
|
|
150
|
-
T = unknown
|
|
151
|
-
>(request: RequestInfo<RT, T>): Future<RT>;
|
|
148
|
+
request<RT>(request: RequestInfo<RT>): Future<RT>;
|
|
152
149
|
/**
|
|
153
150
|
* This method exists so that the RequestManager can be created
|
|
154
151
|
* can be created by container/factory systems that expect to
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable no-irregular-whitespace */
|
|
2
|
-
import type {
|
|
2
|
+
import type { RequestKey } from "../../types/identifier.js";
|
|
3
3
|
import type { IS_FUTURE, RequestContext, RequestInfo, ResponseInfo, StructuredDataDocument } from "../../types/request.js";
|
|
4
4
|
export interface GodContext {
|
|
5
5
|
controller: AbortController;
|
|
@@ -7,7 +7,7 @@ export interface GodContext {
|
|
|
7
7
|
stream: ReadableStream | Promise<ReadableStream | null> | null;
|
|
8
8
|
hasRequestedStream: boolean;
|
|
9
9
|
id: number;
|
|
10
|
-
identifier:
|
|
10
|
+
identifier: RequestKey | null;
|
|
11
11
|
}
|
|
12
12
|
export type Deferred<T> = {
|
|
13
13
|
resolve(v: T): void;
|
|
@@ -64,10 +64,10 @@ export interface Future<T> extends Promise<StructuredDataDocument<T>> {
|
|
|
64
64
|
* assigned by the CacheHandler.
|
|
65
65
|
*
|
|
66
66
|
* @property lid
|
|
67
|
-
* @type {
|
|
67
|
+
* @type {RequestKey | null}
|
|
68
68
|
* @public
|
|
69
69
|
*/
|
|
70
|
-
lid:
|
|
70
|
+
lid: RequestKey | null;
|
|
71
71
|
/**
|
|
72
72
|
* The id of the associated request, if any, as assigned
|
|
73
73
|
* by the RequestManager
|