@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
|
@@ -1,85 +1,168 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { PersistedResourceKey, RequestKey, ResourceKey } from "../identifier.js";
|
|
2
2
|
import type { Value } from "../json/raw.js";
|
|
3
3
|
import type { ExistingResourceObject } from "../spec/json-api-raw.js";
|
|
4
4
|
import type { Relationship } from "./relationship.js";
|
|
5
|
+
/**
|
|
6
|
+
* All operations are objects with at least one property,
|
|
7
|
+
* `op` which contains a string with the name of the operation
|
|
8
|
+
* to perform.
|
|
9
|
+
*/
|
|
5
10
|
export interface Op {
|
|
11
|
+
/**
|
|
12
|
+
* The name of the {@link Op | operation}
|
|
13
|
+
*/
|
|
6
14
|
op: string;
|
|
7
15
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Occasionally the Store discovers that two previously
|
|
18
|
+
* thought to be distinct resources refer to the same resource.
|
|
19
|
+
*
|
|
20
|
+
* This operation will be performed, giving the Cache the chance
|
|
21
|
+
* to cleanup and merge internal state as desired when this discovery
|
|
22
|
+
* is made.
|
|
23
|
+
*/
|
|
16
24
|
export interface MergeOperation extends Op {
|
|
17
25
|
op: "mergeIdentifiers";
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
26
|
+
/**
|
|
27
|
+
* The stale {@link ResourceKey | ResourceKey} that
|
|
28
|
+
* the cache should eliminate in favor of {@link MergeOperation.value | value}
|
|
29
|
+
*/
|
|
30
|
+
record: ResourceKey;
|
|
31
|
+
/**
|
|
32
|
+
* The kept {@link ResourceKey | ResourceKey} that
|
|
33
|
+
* the cache should also keep and merge {@link MergeOperation.record | record} into.
|
|
34
|
+
*/
|
|
35
|
+
value: ResourceKey;
|
|
22
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Removes a document and its associated request from
|
|
39
|
+
* the cache.
|
|
40
|
+
*/
|
|
23
41
|
export interface RemoveDocumentOperation extends Op {
|
|
24
42
|
op: "remove";
|
|
25
|
-
|
|
43
|
+
/**
|
|
44
|
+
* The cache key for the request
|
|
45
|
+
*/
|
|
46
|
+
record: RequestKey;
|
|
26
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Removes a resource from the cache. This is treated
|
|
50
|
+
* as if a remote deletion has occurred, and all references
|
|
51
|
+
* to the resource should be eliminated.
|
|
52
|
+
*/
|
|
27
53
|
export interface RemoveResourceOperation extends Op {
|
|
28
54
|
op: "remove";
|
|
29
|
-
|
|
55
|
+
/**
|
|
56
|
+
* The cache key for the resource
|
|
57
|
+
*/
|
|
58
|
+
record: PersistedResourceKey;
|
|
30
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Adds a resource to the cache.
|
|
62
|
+
*/
|
|
31
63
|
export interface AddResourceOperation extends Op {
|
|
32
64
|
op: "add";
|
|
33
|
-
|
|
65
|
+
/**
|
|
66
|
+
* The cache key for the resource
|
|
67
|
+
*/
|
|
68
|
+
record: PersistedResourceKey;
|
|
69
|
+
/**
|
|
70
|
+
* The data for the resource
|
|
71
|
+
*/
|
|
34
72
|
value: ExistingResourceObject;
|
|
35
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Upserts (merges) new state for a resource
|
|
76
|
+
*/
|
|
36
77
|
export interface UpdateResourceOperation extends Op {
|
|
37
78
|
op: "update";
|
|
38
|
-
record:
|
|
79
|
+
record: PersistedResourceKey;
|
|
39
80
|
value: ExistingResourceObject;
|
|
40
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* Replaces the state of a field with a new state
|
|
84
|
+
*/
|
|
41
85
|
export interface UpdateResourceFieldOperation extends Op {
|
|
42
86
|
op: "update";
|
|
43
|
-
record:
|
|
87
|
+
record: PersistedResourceKey;
|
|
44
88
|
field: string;
|
|
45
89
|
value: Value;
|
|
46
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* Replaces the state of a relationship with a new state
|
|
93
|
+
*/
|
|
47
94
|
export interface UpdateResourceRelationshipOperation extends Op {
|
|
48
95
|
op: "update";
|
|
49
|
-
record:
|
|
96
|
+
record: PersistedResourceKey;
|
|
50
97
|
field: string;
|
|
51
|
-
value: Relationship<
|
|
98
|
+
value: Relationship<PersistedResourceKey>;
|
|
52
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* Adds a resource to a request document, optionally
|
|
102
|
+
* at a specific index. This can be used to update the
|
|
103
|
+
* result of a request.
|
|
104
|
+
*/
|
|
53
105
|
export interface AddToDocumentOperation extends Op {
|
|
54
106
|
op: "add";
|
|
55
|
-
record:
|
|
107
|
+
record: RequestKey;
|
|
56
108
|
field: "data" | "included";
|
|
57
|
-
value:
|
|
109
|
+
value: PersistedResourceKey | PersistedResourceKey[];
|
|
58
110
|
index?: number;
|
|
59
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* Adds the specified ResourceKeys to a relationship
|
|
114
|
+
*/
|
|
60
115
|
export interface AddToResourceRelationshipOperation extends Op {
|
|
61
116
|
op: "add";
|
|
62
|
-
record:
|
|
117
|
+
record: PersistedResourceKey;
|
|
63
118
|
field: string;
|
|
64
|
-
value:
|
|
119
|
+
value: PersistedResourceKey | PersistedResourceKey[];
|
|
65
120
|
index?: number;
|
|
66
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* Removes the specified ResourceKeys from a relationship
|
|
124
|
+
*/
|
|
67
125
|
export interface RemoveFromResourceRelationshipOperation extends Op {
|
|
68
126
|
op: "remove";
|
|
69
|
-
record:
|
|
127
|
+
record: PersistedResourceKey;
|
|
70
128
|
field: string;
|
|
71
|
-
value:
|
|
129
|
+
value: PersistedResourceKey | PersistedResourceKey[];
|
|
72
130
|
index?: number;
|
|
73
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* Removes a resource from a request document, optionally
|
|
134
|
+
* at a specific index. This can be used to update the
|
|
135
|
+
* result of a request.
|
|
136
|
+
*/
|
|
74
137
|
export interface RemoveFromDocumentOperation extends Op {
|
|
75
138
|
op: "remove";
|
|
76
|
-
record:
|
|
139
|
+
record: RequestKey;
|
|
77
140
|
field: "data" | "included";
|
|
78
|
-
value:
|
|
141
|
+
value: PersistedResourceKey | PersistedResourceKey[];
|
|
79
142
|
index?: number;
|
|
80
143
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
144
|
+
/**
|
|
145
|
+
* {@link Cache} Operations perform updates to the
|
|
146
|
+
* Cache's "remote" (or clean) state to reflect external
|
|
147
|
+
* changes.
|
|
148
|
+
*
|
|
149
|
+
* Usually operations represent the result of a {@link WebSocket} or
|
|
150
|
+
* {@link EventSource | ServerEvent} message, though they can also be used to carefully
|
|
151
|
+
* patch the state of the cache with information known by the
|
|
152
|
+
* application or developer.
|
|
153
|
+
*
|
|
154
|
+
* Operations are applied via {@link Cache.patch}.
|
|
155
|
+
*
|
|
156
|
+
* See also:
|
|
157
|
+
* - {@link MergeOperation}
|
|
158
|
+
* - {@link RemoveResourceOperation}
|
|
159
|
+
* - {@link RemoveDocumentOperation}
|
|
160
|
+
* - {@link AddResourceOperation}
|
|
161
|
+
* - {@link UpdateResourceOperation}
|
|
162
|
+
* - {@link UpdateResourceFieldOperation}
|
|
163
|
+
* - {@link AddToResourceRelationshipOperation}
|
|
164
|
+
* - {@link RemoveFromResourceRelationshipOperation}
|
|
165
|
+
* - {@link AddToDocumentOperation}
|
|
166
|
+
* - {@link RemoveFromDocumentOperation}
|
|
167
|
+
*/
|
|
85
168
|
export type Operation = MergeOperation | RemoveResourceOperation | RemoveDocumentOperation | AddResourceOperation | UpdateResourceOperation | UpdateResourceFieldOperation | AddToResourceRelationshipOperation | RemoveFromResourceRelationshipOperation | AddToDocumentOperation | RemoveFromDocumentOperation;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ResourceKey } from "../identifier.js";
|
|
2
2
|
import type { Links, Meta, PaginationLinks } from "../spec/json-api-raw.js";
|
|
3
3
|
// we request that it be in the stable form already.
|
|
4
|
-
export interface ResourceRelationship<T =
|
|
4
|
+
export interface ResourceRelationship<T = ResourceKey> {
|
|
5
5
|
data?: T | null;
|
|
6
6
|
meta?: Meta;
|
|
7
7
|
links?: Links;
|
|
8
8
|
}
|
|
9
9
|
// Note: in v1 data could be a ResourceIdentifier, now
|
|
10
10
|
// we request that it be in the stable form already.
|
|
11
|
-
export interface CollectionRelationship<T =
|
|
11
|
+
export interface CollectionRelationship<T = ResourceKey> {
|
|
12
12
|
data?: T[];
|
|
13
13
|
meta?: Meta;
|
|
14
14
|
links?: PaginationLinks;
|
|
15
15
|
}
|
|
16
|
-
export type Relationship<T =
|
|
16
|
+
export type Relationship<T = ResourceKey> = ResourceRelationship<T> | CollectionRelationship<T>;
|
|
@@ -3,7 +3,7 @@ import type { Change } from "./cache/change.js";
|
|
|
3
3
|
import type { Mutation } from "./cache/mutations.js";
|
|
4
4
|
import type { Operation } from "./cache/operations.js";
|
|
5
5
|
import type { CollectionRelationship, ResourceRelationship } from "./cache/relationship.js";
|
|
6
|
-
import type {
|
|
6
|
+
import type { RequestKey, ResourceKey } from "./identifier.js";
|
|
7
7
|
import type { Value } from "./json/raw.js";
|
|
8
8
|
import type { TypeFromInstanceOrString } from "./record.js";
|
|
9
9
|
import type { RequestContext, StructuredDataDocument, StructuredDocument } from "./request.js";
|
|
@@ -13,20 +13,19 @@ import type { ApiError } from "./spec/error.js";
|
|
|
13
13
|
* A hash of changed attributes with the key being the attribute name and the value being an
|
|
14
14
|
* array of `[oldValue, newValue]`.
|
|
15
15
|
*
|
|
16
|
-
* @internal
|
|
17
16
|
*/
|
|
18
17
|
export type ChangedAttributesHash = Record<string, [Value | undefined, Value]>;
|
|
19
18
|
export type RelationshipDiff = {
|
|
20
19
|
kind: "collection";
|
|
21
|
-
remoteState:
|
|
22
|
-
additions: Set<
|
|
23
|
-
removals: Set<
|
|
24
|
-
localState:
|
|
20
|
+
remoteState: ResourceKey[];
|
|
21
|
+
additions: Set<ResourceKey>;
|
|
22
|
+
removals: Set<ResourceKey>;
|
|
23
|
+
localState: ResourceKey[];
|
|
25
24
|
reordered: boolean;
|
|
26
25
|
} | {
|
|
27
26
|
kind: "resource";
|
|
28
|
-
remoteState:
|
|
29
|
-
localState:
|
|
27
|
+
remoteState: ResourceKey | null;
|
|
28
|
+
localState: ResourceKey | null;
|
|
30
29
|
};
|
|
31
30
|
/**
|
|
32
31
|
* The interface for WarpDrive Caches.
|
|
@@ -34,16 +33,13 @@ export type RelationshipDiff = {
|
|
|
34
33
|
* A Cache handles in-memory storage of Document and Resource
|
|
35
34
|
* data.
|
|
36
35
|
*
|
|
37
|
-
* @class (Interface) Cache
|
|
38
36
|
* @public
|
|
39
37
|
*/
|
|
40
38
|
export interface Cache {
|
|
41
39
|
/**
|
|
42
40
|
* The Cache Version that this implementation implements.
|
|
43
41
|
*
|
|
44
|
-
* @type {'2'}
|
|
45
42
|
* @public
|
|
46
|
-
* @property version
|
|
47
43
|
*/
|
|
48
44
|
version: "2";
|
|
49
45
|
// Cache Management
|
|
@@ -65,8 +61,6 @@ export interface Cache {
|
|
|
65
61
|
* a `content` member and therefor must not assume the existence
|
|
66
62
|
* of `request` and `response` on the document.
|
|
67
63
|
*
|
|
68
|
-
* @param {StructuredDocument} doc
|
|
69
|
-
* @return {ResourceDocument}
|
|
70
64
|
* @public
|
|
71
65
|
*/
|
|
72
66
|
put<T>(doc: StructuredDocument<T> | {
|
|
@@ -77,15 +71,12 @@ export interface Cache {
|
|
|
77
71
|
* by merging new information into the existing state.
|
|
78
72
|
*
|
|
79
73
|
* @public
|
|
80
|
-
* @param
|
|
81
|
-
* @return {void}
|
|
74
|
+
* @param op the operation(s) to perform
|
|
82
75
|
*/
|
|
83
76
|
patch(op: Operation | Operation[]): void;
|
|
84
77
|
/**
|
|
85
78
|
* Update the "local" or "current" (unpersisted) state of the Cache
|
|
86
79
|
*
|
|
87
|
-
* @param {Mutation} mutation
|
|
88
|
-
* @return {void}
|
|
89
80
|
* @public
|
|
90
81
|
*/
|
|
91
82
|
mutate(mutation: Mutation): void;
|
|
@@ -117,11 +108,10 @@ export interface Cache {
|
|
|
117
108
|
* notifications for relational data.
|
|
118
109
|
*
|
|
119
110
|
* @public
|
|
120
|
-
* @
|
|
121
|
-
* @return {ResourceDocument | ResourceBlob | null} the known resource data
|
|
111
|
+
* @return the known resource data, if any
|
|
122
112
|
*/
|
|
123
|
-
peek<T = unknown>(
|
|
124
|
-
peek(
|
|
113
|
+
peek<T = unknown>(cacheKey: ResourceKey<TypeFromInstanceOrString<T>>): T | null;
|
|
114
|
+
peek(cacheKey: RequestKey): ResourceDocument | null;
|
|
125
115
|
/**
|
|
126
116
|
* Peek remote resource data from the Cache.
|
|
127
117
|
*
|
|
@@ -152,11 +142,10 @@ export interface Cache {
|
|
|
152
142
|
* notifications for relational data.
|
|
153
143
|
*
|
|
154
144
|
* @public
|
|
155
|
-
* @
|
|
156
|
-
* @return {ResourceDocument | ResourceBlob | null} the known resource data
|
|
145
|
+
* @return the known data, if any
|
|
157
146
|
*/
|
|
158
|
-
peekRemoteState<T = unknown>(
|
|
159
|
-
peekRemoteState(
|
|
147
|
+
peekRemoteState<T = unknown>(cacheKey: ResourceKey<TypeFromInstanceOrString<T>>): T | null;
|
|
148
|
+
peekRemoteState(cacheKey: RequestKey): ResourceDocument | null;
|
|
160
149
|
/**
|
|
161
150
|
* Peek the Cache for the existing request data associated with
|
|
162
151
|
* a cacheable request
|
|
@@ -165,21 +154,16 @@ export interface Cache {
|
|
|
165
154
|
* that it will return the the request, response, and content
|
|
166
155
|
* whereas `peek` will return just the `content`.
|
|
167
156
|
*
|
|
168
|
-
* @param {StableDocumentIdentifier}
|
|
169
|
-
* @return {StructuredDocument<ResourceDocument> | null}
|
|
170
157
|
* @public
|
|
171
158
|
*/
|
|
172
|
-
peekRequest(
|
|
159
|
+
peekRequest(cacheKey: RequestKey): StructuredDocument<ResourceDocument> | null;
|
|
173
160
|
/**
|
|
174
|
-
* Push resource data from a remote source into the cache for this
|
|
161
|
+
* Push resource data from a remote source into the cache for this ResourceKey
|
|
175
162
|
*
|
|
176
163
|
* @public
|
|
177
|
-
* @
|
|
178
|
-
* @param data
|
|
179
|
-
* @param hasRecord
|
|
180
|
-
* @return {void | string[]} if `hasRecord` is true then calculated key changes should be returned
|
|
164
|
+
* @return if `hasRecord` is true then calculated key changes should be returned
|
|
181
165
|
*/
|
|
182
|
-
upsert(
|
|
166
|
+
upsert(cacheKey: ResourceKey, data: ResourceBlob, hasRecord: boolean): void | string[];
|
|
183
167
|
// Cache Forking Support
|
|
184
168
|
// =====================
|
|
185
169
|
/**
|
|
@@ -190,7 +174,6 @@ export interface Cache {
|
|
|
190
174
|
* utilize this method to fork the cache.
|
|
191
175
|
*
|
|
192
176
|
* @public
|
|
193
|
-
* @return {Promise<Cache>}
|
|
194
177
|
*/
|
|
195
178
|
fork(): Promise<Cache>;
|
|
196
179
|
/**
|
|
@@ -200,9 +183,6 @@ export interface Cache {
|
|
|
200
183
|
* preferring instead to merge at the Store level, which will
|
|
201
184
|
* utilize this method to merge the caches.
|
|
202
185
|
*
|
|
203
|
-
* @param {Cache} cache
|
|
204
|
-
* @public
|
|
205
|
-
* @return {Promise<void>}
|
|
206
186
|
*/
|
|
207
187
|
merge(cache: Cache): Promise<void>;
|
|
208
188
|
/**
|
|
@@ -214,7 +194,7 @@ export interface Cache {
|
|
|
214
194
|
* `Change` entry in the returned array.
|
|
215
195
|
*
|
|
216
196
|
* A `Change` is described by an object containing up to
|
|
217
|
-
* three properties: (1) the `
|
|
197
|
+
* three properties: (1) the `CacheKey` of the entity that
|
|
218
198
|
* changed; (2) the `op` code of that change being one of
|
|
219
199
|
* `upsert` or `remove`, and if the op is `upsert` a `patch`
|
|
220
200
|
* containing the data to merge into the cache for the given
|
|
@@ -229,7 +209,7 @@ export interface Cache {
|
|
|
229
209
|
*
|
|
230
210
|
* ```ts
|
|
231
211
|
* interface Change {
|
|
232
|
-
*
|
|
212
|
+
* key: ResourceKey | RequestKey;
|
|
233
213
|
* op: 'upsert' | 'remove';
|
|
234
214
|
* patch?: unknown;
|
|
235
215
|
* }
|
|
@@ -261,8 +241,6 @@ export interface Cache {
|
|
|
261
241
|
* behavior supports optimizing pre/fetching of data for route transitions
|
|
262
242
|
* via data-only SSR modes.
|
|
263
243
|
*
|
|
264
|
-
* @param {ReadableStream} stream
|
|
265
|
-
* @return {Promise<void>}
|
|
266
244
|
* @public
|
|
267
245
|
*/
|
|
268
246
|
hydrate(stream: ReadableStream<unknown>): Promise<void>;
|
|
@@ -275,37 +253,31 @@ export interface Cache {
|
|
|
275
253
|
* process. This return value behavior is deprecated.
|
|
276
254
|
*
|
|
277
255
|
* @public
|
|
278
|
-
* @param identifier
|
|
279
|
-
* @param createArgs
|
|
280
256
|
*/
|
|
281
|
-
clientDidCreate(
|
|
257
|
+
clientDidCreate(cacheKey: ResourceKey, createArgs?: Record<string, unknown>): Record<string, unknown>;
|
|
282
258
|
/**
|
|
283
259
|
* [LIFECYCLE] Signals to the cache that a resource
|
|
284
260
|
* will be part of a save transaction.
|
|
285
261
|
*
|
|
286
262
|
* @public
|
|
287
|
-
* @param identifier
|
|
288
263
|
*/
|
|
289
|
-
willCommit(
|
|
264
|
+
willCommit(cacheKey: ResourceKey, context: RequestContext | null): void;
|
|
290
265
|
/**
|
|
291
266
|
* [LIFECYCLE] Signals to the cache that a resource
|
|
292
267
|
* was successfully updated as part of a save transaction.
|
|
293
268
|
*
|
|
294
269
|
* @public
|
|
295
|
-
* @param
|
|
270
|
+
* @param the primary ResourceKey that was operated on
|
|
296
271
|
* @param data - a document in the cache format containing any updated data
|
|
297
|
-
* @return {SingleResourceDataDocument}
|
|
298
272
|
*/
|
|
299
|
-
didCommit(
|
|
273
|
+
didCommit(cacheKey: ResourceKey, result: StructuredDataDocument<unknown> | null): SingleResourceDataDocument;
|
|
300
274
|
/**
|
|
301
275
|
* [LIFECYCLE] Signals to the cache that a resource
|
|
302
276
|
* was update via a save transaction failed.
|
|
303
277
|
*
|
|
304
278
|
* @public
|
|
305
|
-
* @param identifier
|
|
306
|
-
* @param errors
|
|
307
279
|
*/
|
|
308
|
-
commitWasRejected(
|
|
280
|
+
commitWasRejected(cacheKey: ResourceKey, errors?: ApiError[]): void;
|
|
309
281
|
/**
|
|
310
282
|
* [LIFECYCLE] Signals to the cache that all data for a resource
|
|
311
283
|
* should be cleared.
|
|
@@ -313,40 +285,30 @@ export interface Cache {
|
|
|
313
285
|
* This method is a candidate to become a mutation
|
|
314
286
|
*
|
|
315
287
|
* @public
|
|
316
|
-
* @param identifier
|
|
317
288
|
*/
|
|
318
|
-
unloadRecord(
|
|
289
|
+
unloadRecord(cacheKey: ResourceKey): void;
|
|
319
290
|
// Granular Resource Data APIs
|
|
320
291
|
// ===========================
|
|
321
292
|
/**
|
|
322
293
|
* Retrieve the data for an attribute from the cache
|
|
323
294
|
*
|
|
324
295
|
* @public
|
|
325
|
-
* @param identifier
|
|
326
|
-
* @param field
|
|
327
|
-
* @return {unknown}
|
|
328
296
|
*/
|
|
329
|
-
getAttr(
|
|
297
|
+
getAttr(cacheKey: ResourceKey, field: string | string[]): Value | undefined;
|
|
330
298
|
/**
|
|
331
299
|
* Retrieve remote state without any local changes for a specific attribute
|
|
332
300
|
*
|
|
333
301
|
* @public
|
|
334
|
-
* @param identifier
|
|
335
|
-
* @param field
|
|
336
|
-
* @return {unknown}
|
|
337
302
|
*/
|
|
338
|
-
getRemoteAttr(
|
|
303
|
+
getRemoteAttr(cacheKey: ResourceKey, field: string | string[]): Value | undefined;
|
|
339
304
|
/**
|
|
340
305
|
* Mutate the data for an attribute in the cache
|
|
341
306
|
*
|
|
342
307
|
* This method is a candidate to become a mutation
|
|
343
308
|
*
|
|
344
309
|
* @public
|
|
345
|
-
* @param identifier
|
|
346
|
-
* @param field
|
|
347
|
-
* @param value
|
|
348
310
|
*/
|
|
349
|
-
setAttr(
|
|
311
|
+
setAttr(cacheKey: ResourceKey, field: string | string[], value: Value): void;
|
|
350
312
|
/**
|
|
351
313
|
* Query the cache for the changed attributes of a resource.
|
|
352
314
|
*
|
|
@@ -357,28 +319,23 @@ export interface Cache {
|
|
|
357
319
|
* ```
|
|
358
320
|
*
|
|
359
321
|
* @public
|
|
360
|
-
* @param identifier
|
|
361
|
-
* @return {Record<string, [unknown, unknown]>} `{ <field>: [<old>, <new>] }`
|
|
362
322
|
*/
|
|
363
|
-
changedAttrs(
|
|
323
|
+
changedAttrs(cacheKey: ResourceKey): ChangedAttributesHash;
|
|
364
324
|
/**
|
|
365
325
|
* Query the cache for whether any mutated attributes exist
|
|
366
326
|
*
|
|
367
327
|
* @public
|
|
368
|
-
* @param identifier
|
|
369
|
-
* @return {Boolean}
|
|
370
328
|
*/
|
|
371
|
-
hasChangedAttrs(
|
|
329
|
+
hasChangedAttrs(cacheKey: ResourceKey): boolean;
|
|
372
330
|
/**
|
|
373
331
|
* Tell the cache to discard any uncommitted mutations to attributes
|
|
374
332
|
*
|
|
375
333
|
* This method is a candidate to become a mutation
|
|
376
334
|
*
|
|
377
335
|
* @public
|
|
378
|
-
* @
|
|
379
|
-
* @return {String[]} the names of fields that were restored
|
|
336
|
+
* @return the names of fields that were restored
|
|
380
337
|
*/
|
|
381
|
-
rollbackAttrs(
|
|
338
|
+
rollbackAttrs(cacheKey: ResourceKey): string[];
|
|
382
339
|
/**
|
|
383
340
|
* Query the cache for the changes to relationships of a resource.
|
|
384
341
|
*
|
|
@@ -388,32 +345,28 @@ export interface Cache {
|
|
|
388
345
|
* type RelationshipDiff =
|
|
389
346
|
| {
|
|
390
347
|
kind: 'collection';
|
|
391
|
-
remoteState:
|
|
392
|
-
additions: Set<
|
|
393
|
-
removals: Set<
|
|
394
|
-
localState:
|
|
348
|
+
remoteState: ResourceKey[];
|
|
349
|
+
additions: Set<ResourceKey>;
|
|
350
|
+
removals: Set<ResourceKey>;
|
|
351
|
+
localState: ResourceKey[];
|
|
395
352
|
reordered: boolean;
|
|
396
353
|
}
|
|
397
354
|
| {
|
|
398
355
|
kind: 'resource';
|
|
399
|
-
remoteState:
|
|
400
|
-
localState:
|
|
356
|
+
remoteState: ResourceKey | null;
|
|
357
|
+
localState: ResourceKey | null;
|
|
401
358
|
};
|
|
402
359
|
```
|
|
403
360
|
*
|
|
404
361
|
* @public
|
|
405
|
-
* @param {StableRecordIdentifier} identifier
|
|
406
|
-
* @return {Map<string, RelationshipDiff>}
|
|
407
362
|
*/
|
|
408
|
-
changedRelationships(
|
|
363
|
+
changedRelationships(cacheKey: ResourceKey): Map<string, RelationshipDiff>;
|
|
409
364
|
/**
|
|
410
365
|
* Query the cache for whether any mutated attributes exist
|
|
411
366
|
*
|
|
412
367
|
* @public
|
|
413
|
-
* @param {StableRecordIdentifier} identifier
|
|
414
|
-
* @return {Boolean}
|
|
415
368
|
*/
|
|
416
|
-
hasChangedRelationships(
|
|
369
|
+
hasChangedRelationships(cacheKey: ResourceKey): boolean;
|
|
417
370
|
/**
|
|
418
371
|
* Tell the cache to discard any uncommitted mutations to relationships.
|
|
419
372
|
*
|
|
@@ -422,28 +375,23 @@ export interface Cache {
|
|
|
422
375
|
* This method is a candidate to become a mutation
|
|
423
376
|
*
|
|
424
377
|
* @public
|
|
425
|
-
* @
|
|
426
|
-
* @return {String[]} the names of relationships that were restored
|
|
378
|
+
* @return the names of relationships that were restored
|
|
427
379
|
*/
|
|
428
|
-
rollbackRelationships(
|
|
380
|
+
rollbackRelationships(cacheKey: ResourceKey): string[];
|
|
429
381
|
/**
|
|
430
382
|
* Query the cache for the current state of a relationship property
|
|
431
383
|
*
|
|
432
384
|
* @public
|
|
433
|
-
* @param {StableRecordIdentifier} identifier
|
|
434
|
-
* @param {String} field
|
|
435
385
|
* @return resource relationship object
|
|
436
386
|
*/
|
|
437
|
-
getRelationship(
|
|
387
|
+
getRelationship(cacheKey: ResourceKey, field: string, isCollection?: boolean): ResourceRelationship | CollectionRelationship;
|
|
438
388
|
/**
|
|
439
389
|
* Query the cache for the server state of a relationship property without any local changes
|
|
440
390
|
*
|
|
441
391
|
* @public
|
|
442
|
-
* @param {StableRecordIdentifier} identifier
|
|
443
|
-
* @param {String} field
|
|
444
392
|
* @return resource relationship object
|
|
445
393
|
*/
|
|
446
|
-
getRemoteRelationship(
|
|
394
|
+
getRemoteRelationship(cacheKey: ResourceKey, field: string, isCollection?: boolean): ResourceRelationship | CollectionRelationship;
|
|
447
395
|
// Resource State
|
|
448
396
|
// ===============
|
|
449
397
|
/**
|
|
@@ -453,49 +401,39 @@ export interface Cache {
|
|
|
453
401
|
* This method is a candidate to become a mutation
|
|
454
402
|
*
|
|
455
403
|
* @public
|
|
456
|
-
* @param identifier
|
|
457
|
-
* @param {Boolean} isDeleted
|
|
458
404
|
*/
|
|
459
|
-
setIsDeleted(
|
|
405
|
+
setIsDeleted(cacheKey: ResourceKey, isDeleted: boolean): void;
|
|
460
406
|
/**
|
|
461
407
|
* Query the cache for any validation errors applicable to the given resource.
|
|
462
408
|
*
|
|
463
409
|
* @public
|
|
464
410
|
*/
|
|
465
|
-
getErrors(
|
|
411
|
+
getErrors(cacheKey: ResourceKey): ApiError[];
|
|
466
412
|
/**
|
|
467
413
|
* Query the cache for whether a given resource has any available data
|
|
468
414
|
*
|
|
469
415
|
* @public
|
|
470
|
-
* @param identifier
|
|
471
|
-
* @return {Boolean}
|
|
472
416
|
*/
|
|
473
|
-
isEmpty(
|
|
417
|
+
isEmpty(cacheKey: ResourceKey): boolean;
|
|
474
418
|
/**
|
|
475
419
|
* Query the cache for whether a given resource was created locally and not
|
|
476
420
|
* yet persisted.
|
|
477
421
|
*
|
|
478
422
|
* @public
|
|
479
|
-
* @param identifier
|
|
480
|
-
* @return {Boolean}
|
|
481
423
|
*/
|
|
482
|
-
isNew(
|
|
424
|
+
isNew(cacheKey: ResourceKey): boolean;
|
|
483
425
|
/**
|
|
484
426
|
* Query the cache for whether a given resource is marked as deleted (but not
|
|
485
427
|
* necessarily persisted yet).
|
|
486
428
|
*
|
|
487
429
|
* @public
|
|
488
|
-
* @param identifier
|
|
489
|
-
* @return {Boolean}
|
|
490
430
|
*/
|
|
491
|
-
isDeleted(
|
|
431
|
+
isDeleted(cacheKey: ResourceKey): boolean;
|
|
492
432
|
/**
|
|
493
433
|
* Query the cache for whether a given resource has been deleted and that deletion
|
|
494
434
|
* has also been persisted.
|
|
495
435
|
*
|
|
496
436
|
* @public
|
|
497
|
-
* @param identifier
|
|
498
|
-
* @return {Boolean}
|
|
499
437
|
*/
|
|
500
|
-
isDeletionCommitted(
|
|
438
|
+
isDeletionCommitted(cacheKey: ResourceKey): boolean;
|
|
501
439
|
}
|