@warp-drive/core 5.7.0-alpha.9 → 5.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/declarations/graph/-private/-diff.d.ts +7 -20
  2. package/declarations/graph/-private/-edge-definition.d.ts +3 -12
  3. package/declarations/graph/-private/-state.d.ts +0 -87
  4. package/declarations/graph/-private/-utils.d.ts +5 -11
  5. package/declarations/graph/-private/coerce-id.d.ts +0 -6
  6. package/declarations/graph/-private/debug/assert-polymorphic-type.d.ts +2 -14
  7. package/declarations/graph/-private/edges/collection.d.ts +10 -10
  8. package/declarations/graph/-private/edges/implicit.d.ts +5 -5
  9. package/declarations/graph/-private/edges/resource.d.ts +6 -7
  10. package/declarations/graph/-private/graph.d.ts +17 -51
  11. package/declarations/graph/-private/normalize-link.d.ts +0 -6
  12. package/declarations/graph/-private/operations/replace-related-records.d.ts +4 -59
  13. package/declarations/graph/-private/operations/update-relationship.d.ts +3 -7
  14. package/declarations/index.d.ts +1 -1
  15. package/declarations/reactive/-private/default-mode.d.ts +2 -2
  16. package/declarations/reactive/-private/document.d.ts +11 -27
  17. package/declarations/reactive/-private/fields/managed-array.d.ts +4 -6
  18. package/declarations/reactive/-private/fields/managed-object.d.ts +2 -8
  19. package/declarations/reactive/-private/fields/many-array-manager.d.ts +2 -2
  20. package/declarations/reactive/-private/hooks.d.ts +2 -2
  21. package/declarations/reactive/-private/record.d.ts +42 -30
  22. package/declarations/reactive/-private/schema.d.ts +11 -73
  23. package/declarations/reactive/-private/symbols.d.ts +2 -33
  24. package/declarations/reactive/-private.d.ts +1 -1
  25. package/declarations/reactive.d.ts +277 -1
  26. package/declarations/request/-private/context.d.ts +3 -5
  27. package/declarations/request/-private/fetch.d.ts +2 -2
  28. package/declarations/request/-private/manager.d.ts +24 -28
  29. package/declarations/request/-private/types.d.ts +22 -24
  30. package/declarations/request/-private/utils.d.ts +44 -2
  31. package/declarations/store/-private/cache-handler/handler.d.ts +2 -8
  32. package/declarations/store/-private/cache-handler/types.d.ts +10 -10
  33. package/declarations/store/-private/cache-handler/utils.d.ts +4 -5
  34. package/declarations/store/-private/caches/instance-cache.d.ts +21 -20
  35. package/declarations/store/-private/debug/utils.d.ts +1 -0
  36. package/declarations/store/-private/default-cache-policy.d.ts +25 -40
  37. package/declarations/store/-private/managers/cache-capabilities-manager.d.ts +24 -15
  38. package/declarations/store/-private/{caches/identifier-cache.d.ts → managers/cache-key-manager.d.ts} +35 -53
  39. package/declarations/store/-private/managers/cache-manager.d.ts +46 -111
  40. package/declarations/store/-private/managers/notification-manager.d.ts +30 -45
  41. package/declarations/store/-private/managers/record-array-manager.d.ts +44 -41
  42. package/declarations/store/-private/network/request-cache.d.ts +21 -25
  43. package/declarations/store/-private/new-core-tmp/expensive-subscription.d.ts +24 -0
  44. package/declarations/store/-private/new-core-tmp/reactivity/configure.d.ts +3 -41
  45. package/declarations/store/-private/new-core-tmp/reactivity/internal.d.ts +14 -29
  46. package/declarations/store/-private/new-core-tmp/reactivity/signal.d.ts +24 -3
  47. package/declarations/store/-private/new-core-tmp/request-state.d.ts +132 -37
  48. package/declarations/store/-private/new-core-tmp/request-subscription.d.ts +51 -135
  49. package/declarations/store/-private/record-arrays/-utils.d.ts +80 -0
  50. package/declarations/store/-private/record-arrays/legacy-live-array.d.ts +81 -0
  51. package/declarations/store/-private/record-arrays/legacy-many-array.d.ts +133 -0
  52. package/declarations/store/-private/record-arrays/legacy-query.d.ts +81 -0
  53. package/declarations/store/-private/record-arrays/native-proxy-type-fix.d.ts +1 -124
  54. package/declarations/store/-private/record-arrays/resource-array.d.ts +67 -0
  55. package/declarations/store/-private/store-service.d.ts +156 -106
  56. package/declarations/store/-private/utils/coerce-id.d.ts +0 -6
  57. package/declarations/store/-private.d.ts +11 -13
  58. package/declarations/store/-types/q/cache-capabilities-manager.d.ts +15 -24
  59. package/declarations/store/-types/q/identifier.d.ts +9 -6
  60. package/declarations/store/-types/q/record-instance.d.ts +0 -1
  61. package/declarations/store/-types/q/schema-service.d.ts +9 -9
  62. package/declarations/store/-types/q/store.d.ts +6 -7
  63. package/declarations/store/deprecated/-private.d.ts +12 -24
  64. package/declarations/store/deprecated/store.d.ts +11 -16
  65. package/declarations/types/-private.d.ts +1 -1
  66. package/declarations/types/cache/aliases.d.ts +0 -11
  67. package/declarations/types/cache/change.d.ts +2 -2
  68. package/declarations/types/cache/mutations.d.ts +13 -37
  69. package/declarations/types/cache/operations.d.ts +115 -32
  70. package/declarations/types/cache/relationship.d.ts +4 -7
  71. package/declarations/types/cache.d.ts +51 -125
  72. package/declarations/types/graph.d.ts +12 -12
  73. package/declarations/types/identifier.d.ts +52 -78
  74. package/declarations/types/params.d.ts +2 -3
  75. package/declarations/types/request.d.ts +66 -42
  76. package/declarations/types/schema/concepts.d.ts +2 -2
  77. package/declarations/types/schema/fields.d.ts +30 -3
  78. package/declarations/types/spec/document.d.ts +6 -10
  79. package/declarations/types/spec/json-api-raw.d.ts +6 -9
  80. package/declarations/types.d.ts +0 -1
  81. package/declarations/utils/string.d.ts +2 -3
  82. package/dist/{configure-B48bFHOl.js → configure-C3x8YXzL.js} +5 -5
  83. package/dist/configure.js +1 -1
  84. package/dist/{context-COmAnXUQ.js → context-C_7OLieY.js} +48 -6
  85. package/dist/graph/-private.js +137 -144
  86. package/dist/index.js +25 -14
  87. package/dist/reactive/-private.js +1 -1
  88. package/dist/reactive.js +144 -1926
  89. package/dist/{request-state-CeN66aML.js → request-state-C955e0AL.js} +5968 -3033
  90. package/dist/request.js +1 -1
  91. package/dist/store/-private.js +2 -3
  92. package/dist/store.js +32 -44
  93. package/dist/{symbols-SIstXMLI.js → symbols-sql1_mdx.js} +3 -8
  94. package/dist/types/-private.js +1 -1
  95. package/dist/types/identifier.js +19 -45
  96. package/dist/types/request.js +45 -3
  97. package/dist/types/schema/fields.js +6 -0
  98. package/dist/utils/string.js +2 -2
  99. package/package.json +11 -11
  100. package/declarations/store/-private/caches/cache-utils.d.ts +0 -12
  101. package/declarations/store/-private/record-arrays/identifier-array.d.ts +0 -147
  102. package/declarations/store/-private/record-arrays/many-array.d.ts +0 -197
  103. package/dist/handler-SdXlte1w.js +0 -339
@@ -1,85 +1,168 @@
1
- import type { StableDocumentIdentifier, StableExistingRecordIdentifier, StableRecordIdentifier } from "../identifier.js";
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
- // Occasionally the IdentifierCache
9
- // discovers that two previously thought
10
- // to be distinct Identifiers refer to
11
- // the same ResourceBlob. This Operation
12
- // will be performed giving the Cache the
13
- // change to cleanup and merge internal
14
- // state as desired when this discovery
15
- // is made.
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
- // existing
19
- record: StableRecordIdentifier;
20
- // new
21
- value: StableRecordIdentifier;
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
- record: StableDocumentIdentifier;
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
- record: StableExistingRecordIdentifier;
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
- record: StableExistingRecordIdentifier;
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: StableExistingRecordIdentifier;
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: StableExistingRecordIdentifier;
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: StableExistingRecordIdentifier;
96
+ record: PersistedResourceKey;
50
97
  field: string;
51
- value: Relationship<StableExistingRecordIdentifier>;
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: StableDocumentIdentifier;
107
+ record: RequestKey;
56
108
  field: "data" | "included";
57
- value: StableExistingRecordIdentifier | StableExistingRecordIdentifier[];
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: StableExistingRecordIdentifier;
117
+ record: PersistedResourceKey;
63
118
  field: string;
64
- value: StableExistingRecordIdentifier | StableExistingRecordIdentifier[];
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: StableExistingRecordIdentifier;
127
+ record: PersistedResourceKey;
70
128
  field: string;
71
- value: StableExistingRecordIdentifier | StableExistingRecordIdentifier[];
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: StableDocumentIdentifier;
139
+ record: RequestKey;
77
140
  field: "data" | "included";
78
- value: StableExistingRecordIdentifier | StableExistingRecordIdentifier[];
141
+ value: PersistedResourceKey | PersistedResourceKey[];
79
142
  index?: number;
80
143
  }
81
- // An Operation is an action that updates
82
- // the remote state of the Cache in some
83
- // manner. Additional Operations will be
84
- // added in the future.
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,13 @@
1
- import type { StableRecordIdentifier } from "../identifier.js";
1
+ import type { ResourceKey } from "../identifier.js";
2
2
  import type { Links, Meta, PaginationLinks } from "../spec/json-api-raw.js";
3
- // we request that it be in the stable form already.
4
- export interface ResourceRelationship<T = StableRecordIdentifier> {
3
+ export interface ResourceRelationship<T = ResourceKey> {
5
4
  data?: T | null;
6
5
  meta?: Meta;
7
6
  links?: Links;
8
7
  }
9
- // Note: in v1 data could be a ResourceIdentifier, now
10
- // we request that it be in the stable form already.
11
- export interface CollectionRelationship<T = StableRecordIdentifier> {
8
+ export interface CollectionRelationship<T = ResourceKey> {
12
9
  data?: T[];
13
10
  meta?: Meta;
14
11
  links?: PaginationLinks;
15
12
  }
16
- export type Relationship<T = StableRecordIdentifier> = ResourceRelationship<T> | CollectionRelationship<T>;
13
+ 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 { StableDocumentIdentifier, StableRecordIdentifier } from "./identifier.js";
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: StableRecordIdentifier[];
22
- additions: Set<StableRecordIdentifier>;
23
- removals: Set<StableRecordIdentifier>;
24
- localState: StableRecordIdentifier[];
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: StableRecordIdentifier | null;
29
- localState: StableRecordIdentifier | null;
27
+ remoteState: ResourceKey | null;
28
+ localState: ResourceKey | null;
30
29
  };
31
30
  /**
32
31
  * The interface for WarpDrive Caches.
@@ -34,20 +33,15 @@ 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
- // Cache Management
50
- // ================
51
45
  /**
52
46
  * Cache the response to a request
53
47
  *
@@ -65,8 +59,6 @@ export interface Cache {
65
59
  * a `content` member and therefor must not assume the existence
66
60
  * of `request` and `response` on the document.
67
61
  *
68
- * @param {StructuredDocument} doc
69
- * @return {ResourceDocument}
70
62
  * @public
71
63
  */
72
64
  put<T>(doc: StructuredDocument<T> | {
@@ -77,15 +69,12 @@ export interface Cache {
77
69
  * by merging new information into the existing state.
78
70
  *
79
71
  * @public
80
- * @param {Operation | Operation[]} op the operation(s) to perform
81
- * @return {void}
72
+ * @param op the operation(s) to perform
82
73
  */
83
74
  patch(op: Operation | Operation[]): void;
84
75
  /**
85
76
  * Update the "local" or "current" (unpersisted) state of the Cache
86
77
  *
87
- * @param {Mutation} mutation
88
- * @return {void}
89
78
  * @public
90
79
  */
91
80
  mutate(mutation: Mutation): void;
@@ -117,11 +106,10 @@ export interface Cache {
117
106
  * notifications for relational data.
118
107
  *
119
108
  * @public
120
- * @param {StableRecordIdentifier | StableDocumentIdentifier} identifier
121
- * @return {ResourceDocument | ResourceBlob | null} the known resource data
109
+ * @return the known resource data, if any
122
110
  */
123
- peek<T = unknown>(identifier: StableRecordIdentifier<TypeFromInstanceOrString<T>>): T | null;
124
- peek(identifier: StableDocumentIdentifier): ResourceDocument | null;
111
+ peek<T = unknown>(cacheKey: ResourceKey<TypeFromInstanceOrString<T>>): T | null;
112
+ peek(cacheKey: RequestKey): ResourceDocument | null;
125
113
  /**
126
114
  * Peek remote resource data from the Cache.
127
115
  *
@@ -152,11 +140,10 @@ export interface Cache {
152
140
  * notifications for relational data.
153
141
  *
154
142
  * @public
155
- * @param {StableRecordIdentifier | StableDocumentIdentifier} identifier
156
- * @return {ResourceDocument | ResourceBlob | null} the known resource data
143
+ * @return the known data, if any
157
144
  */
158
- peekRemoteState<T = unknown>(identifier: StableRecordIdentifier<TypeFromInstanceOrString<T>>): T | null;
159
- peekRemoteState(identifier: StableDocumentIdentifier): ResourceDocument | null;
145
+ peekRemoteState<T = unknown>(cacheKey: ResourceKey<TypeFromInstanceOrString<T>>): T | null;
146
+ peekRemoteState(cacheKey: RequestKey): ResourceDocument | null;
160
147
  /**
161
148
  * Peek the Cache for the existing request data associated with
162
149
  * a cacheable request
@@ -165,23 +152,16 @@ export interface Cache {
165
152
  * that it will return the the request, response, and content
166
153
  * whereas `peek` will return just the `content`.
167
154
  *
168
- * @param {StableDocumentIdentifier}
169
- * @return {StructuredDocument<ResourceDocument> | null}
170
155
  * @public
171
156
  */
172
- peekRequest(identifier: StableDocumentIdentifier): StructuredDocument<ResourceDocument> | null;
157
+ peekRequest(cacheKey: RequestKey): StructuredDocument<ResourceDocument> | null;
173
158
  /**
174
- * Push resource data from a remote source into the cache for this identifier
159
+ * Push resource data from a remote source into the cache for this ResourceKey
175
160
  *
176
161
  * @public
177
- * @param identifier
178
- * @param data
179
- * @param hasRecord
180
- * @return {void | string[]} if `hasRecord` is true then calculated key changes should be returned
162
+ * @return if `hasRecord` is true then calculated key changes should be returned
181
163
  */
182
- upsert(identifier: StableRecordIdentifier, data: ResourceBlob, hasRecord: boolean): void | string[];
183
- // Cache Forking Support
184
- // =====================
164
+ upsert(cacheKey: ResourceKey, data: ResourceBlob, hasRecord: boolean): void | string[];
185
165
  /**
186
166
  * Create a fork of the cache from the current state.
187
167
  *
@@ -190,7 +170,6 @@ export interface Cache {
190
170
  * utilize this method to fork the cache.
191
171
  *
192
172
  * @public
193
- * @return {Promise<Cache>}
194
173
  */
195
174
  fork(): Promise<Cache>;
196
175
  /**
@@ -200,9 +179,6 @@ export interface Cache {
200
179
  * preferring instead to merge at the Store level, which will
201
180
  * utilize this method to merge the caches.
202
181
  *
203
- * @param {Cache} cache
204
- * @public
205
- * @return {Promise<void>}
206
182
  */
207
183
  merge(cache: Cache): Promise<void>;
208
184
  /**
@@ -214,7 +190,7 @@ export interface Cache {
214
190
  * `Change` entry in the returned array.
215
191
  *
216
192
  * A `Change` is described by an object containing up to
217
- * three properties: (1) the `identifier` of the entity that
193
+ * three properties: (1) the `CacheKey` of the entity that
218
194
  * changed; (2) the `op` code of that change being one of
219
195
  * `upsert` or `remove`, and if the op is `upsert` a `patch`
220
196
  * containing the data to merge into the cache for the given
@@ -229,7 +205,7 @@ export interface Cache {
229
205
  *
230
206
  * ```ts
231
207
  * interface Change {
232
- * identifier: StableRecordIdentifier | StableDocumentIdentifier;
208
+ * key: ResourceKey | RequestKey;
233
209
  * op: 'upsert' | 'remove';
234
210
  * patch?: unknown;
235
211
  * }
@@ -238,8 +214,6 @@ export interface Cache {
238
214
  * @public
239
215
  */
240
216
  diff(): Promise<Change[]>;
241
- // SSR Support
242
- // ===========
243
217
  /**
244
218
  * Serialize the entire contents of the Cache into a Stream
245
219
  * which may be fed back into a new instance of the same Cache
@@ -261,13 +235,9 @@ export interface Cache {
261
235
  * behavior supports optimizing pre/fetching of data for route transitions
262
236
  * via data-only SSR modes.
263
237
  *
264
- * @param {ReadableStream} stream
265
- * @return {Promise<void>}
266
238
  * @public
267
239
  */
268
240
  hydrate(stream: ReadableStream<unknown>): Promise<void>;
269
- // Resource Support
270
- // ================
271
241
  /**
272
242
  * [LIFECYCLE] Signal to the cache that a new record has been instantiated on the client
273
243
  *
@@ -275,37 +245,31 @@ export interface Cache {
275
245
  * process. This return value behavior is deprecated.
276
246
  *
277
247
  * @public
278
- * @param identifier
279
- * @param createArgs
280
248
  */
281
- clientDidCreate(identifier: StableRecordIdentifier, createArgs?: Record<string, unknown>): Record<string, unknown>;
249
+ clientDidCreate(cacheKey: ResourceKey, createArgs?: Record<string, unknown>): Record<string, unknown>;
282
250
  /**
283
251
  * [LIFECYCLE] Signals to the cache that a resource
284
252
  * will be part of a save transaction.
285
253
  *
286
254
  * @public
287
- * @param identifier
288
255
  */
289
- willCommit(identifier: StableRecordIdentifier, context: RequestContext): void;
256
+ willCommit(cacheKey: ResourceKey, context: RequestContext | null): void;
290
257
  /**
291
258
  * [LIFECYCLE] Signals to the cache that a resource
292
259
  * was successfully updated as part of a save transaction.
293
260
  *
294
261
  * @public
295
- * @param identifier - the primary identifier that was operated on
262
+ * @param the primary ResourceKey that was operated on
296
263
  * @param data - a document in the cache format containing any updated data
297
- * @return {SingleResourceDataDocument}
298
264
  */
299
- didCommit(identifier: StableRecordIdentifier, result: StructuredDataDocument<unknown>): SingleResourceDataDocument;
265
+ didCommit(cacheKey: ResourceKey, result: StructuredDataDocument<unknown> | null): SingleResourceDataDocument;
300
266
  /**
301
267
  * [LIFECYCLE] Signals to the cache that a resource
302
268
  * was update via a save transaction failed.
303
269
  *
304
270
  * @public
305
- * @param identifier
306
- * @param errors
307
271
  */
308
- commitWasRejected(identifier: StableRecordIdentifier, errors?: ApiError[]): void;
272
+ commitWasRejected(cacheKey: ResourceKey, errors?: ApiError[]): void;
309
273
  /**
310
274
  * [LIFECYCLE] Signals to the cache that all data for a resource
311
275
  * should be cleared.
@@ -313,40 +277,28 @@ export interface Cache {
313
277
  * This method is a candidate to become a mutation
314
278
  *
315
279
  * @public
316
- * @param identifier
317
280
  */
318
- unloadRecord(identifier: StableRecordIdentifier): void;
319
- // Granular Resource Data APIs
320
- // ===========================
281
+ unloadRecord(cacheKey: ResourceKey): void;
321
282
  /**
322
283
  * Retrieve the data for an attribute from the cache
323
284
  *
324
285
  * @public
325
- * @param identifier
326
- * @param field
327
- * @return {unknown}
328
286
  */
329
- getAttr(identifier: StableRecordIdentifier, field: string | string[]): Value | undefined;
287
+ getAttr(cacheKey: ResourceKey, field: string | string[]): Value | undefined;
330
288
  /**
331
289
  * Retrieve remote state without any local changes for a specific attribute
332
290
  *
333
291
  * @public
334
- * @param identifier
335
- * @param field
336
- * @return {unknown}
337
292
  */
338
- getRemoteAttr(identifier: StableRecordIdentifier, field: string | string[]): Value | undefined;
293
+ getRemoteAttr(cacheKey: ResourceKey, field: string | string[]): Value | undefined;
339
294
  /**
340
295
  * Mutate the data for an attribute in the cache
341
296
  *
342
297
  * This method is a candidate to become a mutation
343
298
  *
344
299
  * @public
345
- * @param identifier
346
- * @param field
347
- * @param value
348
300
  */
349
- setAttr(identifier: StableRecordIdentifier, field: string | string[], value: Value): void;
301
+ setAttr(cacheKey: ResourceKey, field: string | string[], value: Value): void;
350
302
  /**
351
303
  * Query the cache for the changed attributes of a resource.
352
304
  *
@@ -357,28 +309,23 @@ export interface Cache {
357
309
  * ```
358
310
  *
359
311
  * @public
360
- * @param identifier
361
- * @return {Record<string, [unknown, unknown]>} `{ <field>: [<old>, <new>] }`
362
312
  */
363
- changedAttrs(identifier: StableRecordIdentifier): ChangedAttributesHash;
313
+ changedAttrs(cacheKey: ResourceKey): ChangedAttributesHash;
364
314
  /**
365
315
  * Query the cache for whether any mutated attributes exist
366
316
  *
367
317
  * @public
368
- * @param identifier
369
- * @return {Boolean}
370
318
  */
371
- hasChangedAttrs(identifier: StableRecordIdentifier): boolean;
319
+ hasChangedAttrs(cacheKey: ResourceKey): boolean;
372
320
  /**
373
321
  * Tell the cache to discard any uncommitted mutations to attributes
374
322
  *
375
323
  * This method is a candidate to become a mutation
376
324
  *
377
325
  * @public
378
- * @param identifier
379
- * @return {String[]} the names of fields that were restored
326
+ * @return the names of fields that were restored
380
327
  */
381
- rollbackAttrs(identifier: StableRecordIdentifier): string[];
328
+ rollbackAttrs(cacheKey: ResourceKey): string[];
382
329
  /**
383
330
  * Query the cache for the changes to relationships of a resource.
384
331
  *
@@ -388,32 +335,28 @@ export interface Cache {
388
335
  * type RelationshipDiff =
389
336
  | {
390
337
  kind: 'collection';
391
- remoteState: StableRecordIdentifier[];
392
- additions: Set<StableRecordIdentifier>;
393
- removals: Set<StableRecordIdentifier>;
394
- localState: StableRecordIdentifier[];
338
+ remoteState: ResourceKey[];
339
+ additions: Set<ResourceKey>;
340
+ removals: Set<ResourceKey>;
341
+ localState: ResourceKey[];
395
342
  reordered: boolean;
396
343
  }
397
344
  | {
398
345
  kind: 'resource';
399
- remoteState: StableRecordIdentifier | null;
400
- localState: StableRecordIdentifier | null;
346
+ remoteState: ResourceKey | null;
347
+ localState: ResourceKey | null;
401
348
  };
402
349
  ```
403
350
  *
404
351
  * @public
405
- * @param {StableRecordIdentifier} identifier
406
- * @return {Map<string, RelationshipDiff>}
407
352
  */
408
- changedRelationships(identifier: StableRecordIdentifier): Map<string, RelationshipDiff>;
353
+ changedRelationships(cacheKey: ResourceKey): Map<string, RelationshipDiff>;
409
354
  /**
410
355
  * Query the cache for whether any mutated attributes exist
411
356
  *
412
357
  * @public
413
- * @param {StableRecordIdentifier} identifier
414
- * @return {Boolean}
415
358
  */
416
- hasChangedRelationships(identifier: StableRecordIdentifier): boolean;
359
+ hasChangedRelationships(cacheKey: ResourceKey): boolean;
417
360
  /**
418
361
  * Tell the cache to discard any uncommitted mutations to relationships.
419
362
  *
@@ -422,30 +365,23 @@ export interface Cache {
422
365
  * This method is a candidate to become a mutation
423
366
  *
424
367
  * @public
425
- * @param {StableRecordIdentifier} identifier
426
- * @return {String[]} the names of relationships that were restored
368
+ * @return the names of relationships that were restored
427
369
  */
428
- rollbackRelationships(identifier: StableRecordIdentifier): string[];
370
+ rollbackRelationships(cacheKey: ResourceKey): string[];
429
371
  /**
430
372
  * Query the cache for the current state of a relationship property
431
373
  *
432
374
  * @public
433
- * @param {StableRecordIdentifier} identifier
434
- * @param {String} field
435
375
  * @return resource relationship object
436
376
  */
437
- getRelationship(identifier: StableRecordIdentifier, field: string, isCollection?: boolean): ResourceRelationship | CollectionRelationship;
377
+ getRelationship(cacheKey: ResourceKey, field: string, isCollection?: boolean): ResourceRelationship | CollectionRelationship;
438
378
  /**
439
379
  * Query the cache for the server state of a relationship property without any local changes
440
380
  *
441
381
  * @public
442
- * @param {StableRecordIdentifier} identifier
443
- * @param {String} field
444
382
  * @return resource relationship object
445
383
  */
446
- getRemoteRelationship(identifier: StableRecordIdentifier, field: string, isCollection?: boolean): ResourceRelationship | CollectionRelationship;
447
- // Resource State
448
- // ===============
384
+ getRemoteRelationship(cacheKey: ResourceKey, field: string, isCollection?: boolean): ResourceRelationship | CollectionRelationship;
449
385
  /**
450
386
  * Update the cache state for the given resource to be marked
451
387
  * as locally deleted, or remove such a mark.
@@ -453,49 +389,39 @@ export interface Cache {
453
389
  * This method is a candidate to become a mutation
454
390
  *
455
391
  * @public
456
- * @param identifier
457
- * @param {Boolean} isDeleted
458
392
  */
459
- setIsDeleted(identifier: StableRecordIdentifier, isDeleted: boolean): void;
393
+ setIsDeleted(cacheKey: ResourceKey, isDeleted: boolean): void;
460
394
  /**
461
395
  * Query the cache for any validation errors applicable to the given resource.
462
396
  *
463
397
  * @public
464
398
  */
465
- getErrors(identifier: StableRecordIdentifier): ApiError[];
399
+ getErrors(cacheKey: ResourceKey): ApiError[];
466
400
  /**
467
401
  * Query the cache for whether a given resource has any available data
468
402
  *
469
403
  * @public
470
- * @param identifier
471
- * @return {Boolean}
472
404
  */
473
- isEmpty(identifier: StableRecordIdentifier): boolean;
405
+ isEmpty(cacheKey: ResourceKey): boolean;
474
406
  /**
475
407
  * Query the cache for whether a given resource was created locally and not
476
408
  * yet persisted.
477
409
  *
478
410
  * @public
479
- * @param identifier
480
- * @return {Boolean}
481
411
  */
482
- isNew(identifier: StableRecordIdentifier): boolean;
412
+ isNew(cacheKey: ResourceKey): boolean;
483
413
  /**
484
414
  * Query the cache for whether a given resource is marked as deleted (but not
485
415
  * necessarily persisted yet).
486
416
  *
487
417
  * @public
488
- * @param identifier
489
- * @return {Boolean}
490
418
  */
491
- isDeleted(identifier: StableRecordIdentifier): boolean;
419
+ isDeleted(cacheKey: ResourceKey): boolean;
492
420
  /**
493
421
  * Query the cache for whether a given resource has been deleted and that deletion
494
422
  * has also been persisted.
495
423
  *
496
424
  * @public
497
- * @param identifier
498
- * @return {Boolean}
499
425
  */
500
- isDeletionCommitted(identifier: StableRecordIdentifier): boolean;
426
+ isDeletionCommitted(cacheKey: ResourceKey): boolean;
501
427
  }