@warp-drive/core 5.6.0-beta.1 → 5.6.0-beta.2

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 (120) 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 +2 -2
  4. package/declarations/graph/-private/-utils.d.ts +5 -5
  5. package/declarations/graph/-private/debug/assert-polymorphic-type.d.ts +3 -3
  6. package/declarations/graph/-private/edges/collection.d.ts +10 -10
  7. package/declarations/graph/-private/edges/implicit.d.ts +5 -5
  8. package/declarations/graph/-private/edges/resource.d.ts +6 -7
  9. package/declarations/graph/-private/graph.d.ts +17 -15
  10. package/declarations/graph/-private/operations/replace-related-records.d.ts +4 -4
  11. package/declarations/graph/-private/operations/update-relationship.d.ts +3 -3
  12. package/declarations/index.d.ts +1 -1
  13. package/declarations/reactive/-private/default-mode.d.ts +73 -0
  14. package/declarations/reactive/-private/document.d.ts +11 -27
  15. package/declarations/reactive/-private/fields/get-field-key.d.ts +8 -0
  16. package/declarations/reactive/-private/fields/managed-array.d.ts +7 -10
  17. package/declarations/reactive/-private/fields/managed-object.d.ts +7 -9
  18. package/declarations/reactive/-private/fields/many-array-manager.d.ts +2 -2
  19. package/declarations/reactive/-private/hooks.d.ts +2 -2
  20. package/declarations/reactive/-private/kind/alias-field.d.ts +4 -0
  21. package/declarations/reactive/-private/kind/array-field.d.ts +4 -0
  22. package/declarations/reactive/-private/kind/attribute-field.d.ts +4 -0
  23. package/declarations/reactive/-private/kind/belongs-to-field.d.ts +4 -0
  24. package/declarations/reactive/-private/kind/collection-field.d.ts +4 -0
  25. package/declarations/reactive/-private/kind/derived-field.d.ts +4 -0
  26. package/declarations/reactive/-private/kind/generic-field.d.ts +4 -0
  27. package/declarations/reactive/-private/kind/has-many-field.d.ts +4 -0
  28. package/declarations/reactive/-private/kind/hash-field.d.ts +4 -0
  29. package/declarations/reactive/-private/kind/identity-field.d.ts +4 -0
  30. package/declarations/reactive/-private/kind/local-field.d.ts +4 -0
  31. package/declarations/reactive/-private/kind/object-field.d.ts +4 -0
  32. package/declarations/reactive/-private/kind/resource-field.d.ts +4 -0
  33. package/declarations/reactive/-private/kind/schema-array-field.d.ts +4 -0
  34. package/declarations/reactive/-private/kind/schema-object-field.d.ts +4 -0
  35. package/declarations/reactive/-private/record.d.ts +44 -33
  36. package/declarations/reactive/-private/schema.d.ts +50 -66
  37. package/declarations/reactive/-private/symbols.d.ts +2 -7
  38. package/declarations/reactive/-private.d.ts +1 -1
  39. package/declarations/reactive.d.ts +278 -1
  40. package/declarations/request/-private/context.d.ts +3 -5
  41. package/declarations/request/-private/fetch.d.ts +2 -0
  42. package/declarations/request/-private/manager.d.ts +24 -28
  43. package/declarations/request/-private/types.d.ts +22 -23
  44. package/declarations/request/-private/utils.d.ts +44 -2
  45. package/declarations/store/-private/cache-handler/handler.d.ts +2 -8
  46. package/declarations/store/-private/cache-handler/types.d.ts +10 -10
  47. package/declarations/store/-private/cache-handler/utils.d.ts +4 -4
  48. package/declarations/store/-private/caches/instance-cache.d.ts +22 -27
  49. package/declarations/store/-private/debug/utils.d.ts +1 -0
  50. package/declarations/store/-private/default-cache-policy.d.ts +25 -38
  51. package/declarations/store/-private/managers/cache-capabilities-manager.d.ts +24 -15
  52. package/declarations/store/-private/{caches/identifier-cache.d.ts → managers/cache-key-manager.d.ts} +38 -52
  53. package/declarations/store/-private/managers/cache-manager.d.ts +46 -95
  54. package/declarations/store/-private/managers/notification-manager.d.ts +30 -43
  55. package/declarations/store/-private/managers/record-array-manager.d.ts +44 -41
  56. package/declarations/store/-private/network/request-cache.d.ts +21 -24
  57. package/declarations/store/-private/new-core-tmp/expensive-subscription.d.ts +24 -0
  58. package/declarations/store/-private/new-core-tmp/reactivity/configure.d.ts +3 -41
  59. package/declarations/store/-private/new-core-tmp/reactivity/internal.d.ts +14 -29
  60. package/declarations/store/-private/new-core-tmp/reactivity/signal.d.ts +24 -3
  61. package/declarations/store/-private/new-core-tmp/request-state.d.ts +133 -37
  62. package/declarations/store/-private/new-core-tmp/request-subscription.d.ts +51 -133
  63. package/declarations/store/-private/record-arrays/-utils.d.ts +80 -0
  64. package/declarations/store/-private/record-arrays/legacy-live-array.d.ts +81 -0
  65. package/declarations/store/-private/record-arrays/legacy-many-array.d.ts +133 -0
  66. package/declarations/store/-private/record-arrays/legacy-query.d.ts +81 -0
  67. package/declarations/store/-private/record-arrays/native-proxy-type-fix.d.ts +1 -124
  68. package/declarations/store/-private/record-arrays/resource-array.d.ts +75 -0
  69. package/declarations/store/-private/store-service.d.ts +167 -872
  70. package/declarations/store/-private.d.ts +14 -10
  71. package/declarations/store/-types/q/cache-capabilities-manager.d.ts +15 -24
  72. package/declarations/store/-types/q/identifier.d.ts +9 -6
  73. package/declarations/store/-types/q/record-instance.d.ts +0 -1
  74. package/declarations/store/-types/q/schema-service.d.ts +64 -40
  75. package/declarations/store/-types/q/store.d.ts +6 -7
  76. package/declarations/store/deprecated/-private.d.ts +224 -0
  77. package/declarations/store/deprecated/store.d.ts +787 -0
  78. package/declarations/types/-private.d.ts +1 -1
  79. package/declarations/types/cache/aliases.d.ts +2 -2
  80. package/declarations/types/cache/change.d.ts +2 -2
  81. package/declarations/types/cache/mutations.d.ts +13 -13
  82. package/declarations/types/cache/operations.d.ts +115 -32
  83. package/declarations/types/cache/relationship.d.ts +4 -4
  84. package/declarations/types/cache.d.ts +51 -115
  85. package/declarations/types/graph.d.ts +12 -12
  86. package/declarations/types/identifier.d.ts +52 -76
  87. package/declarations/types/params.d.ts +2 -3
  88. package/declarations/types/request.d.ts +69 -42
  89. package/declarations/types/schema/concepts.d.ts +2 -2
  90. package/declarations/types/schema/fields.d.ts +391 -14
  91. package/declarations/types/spec/document.d.ts +6 -6
  92. package/declarations/types/spec/json-api-raw.d.ts +6 -8
  93. package/declarations/types.d.ts +2 -1
  94. package/declarations/utils/string.d.ts +2 -2
  95. package/dist/{configure-B48bFHOl.js → configure-C3x8YXzL.js} +5 -5
  96. package/dist/configure.js +1 -1
  97. package/dist/{context-COmAnXUQ.js → context-C_7OLieY.js} +48 -6
  98. package/dist/graph/-private.js +137 -144
  99. package/dist/index.js +25 -14
  100. package/dist/reactive/-private.js +1 -1
  101. package/dist/reactive.js +337 -1422
  102. package/dist/{request-state-CjLph1LP.js → request-state-C955e0AL.js} +8352 -5912
  103. package/dist/request.js +1 -1
  104. package/dist/store/-private.js +2 -3
  105. package/dist/store.js +32 -44
  106. package/dist/{symbols-SIstXMLI.js → symbols-sql1_mdx.js} +3 -8
  107. package/dist/types/-private.js +1 -1
  108. package/dist/types/identifier.js +19 -45
  109. package/dist/types/request.js +45 -3
  110. package/dist/types/schema/fields.js +23 -2
  111. package/dist/utils/string.js +2 -2
  112. package/package.json +10 -10
  113. package/declarations/reactive/-private/fields/compute.d.ts +0 -43
  114. package/declarations/store/-private/caches/cache-utils.d.ts +0 -12
  115. package/declarations/store/-private/legacy-model-support/record-reference.d.ts +0 -159
  116. package/declarations/store/-private/legacy-model-support/shim-model-class.d.ts +0 -17
  117. package/declarations/store/-private/record-arrays/identifier-array.d.ts +0 -147
  118. package/declarations/store/-private/record-arrays/many-array.d.ts +0 -197
  119. package/declarations/store/-types/q/ds-model.d.ts +0 -21
  120. package/dist/handler-C2T-IyJK.js +0 -339
@@ -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,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 {Operation | Operation[]} op the operation(s) to perform
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
- * @param {StableRecordIdentifier | StableDocumentIdentifier} identifier
121
- * @return {ResourceDocument | ResourceBlob | null} the known resource data
111
+ * @return the known resource data, if any
122
112
  */
123
- peek<T = unknown>(identifier: StableRecordIdentifier<TypeFromInstanceOrString<T>>): T | null;
124
- peek(identifier: StableDocumentIdentifier): ResourceDocument | null;
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
- * @param {StableRecordIdentifier | StableDocumentIdentifier} identifier
156
- * @return {ResourceDocument | ResourceBlob | null} the known resource data
145
+ * @return the known data, if any
157
146
  */
158
- peekRemoteState<T = unknown>(identifier: StableRecordIdentifier<TypeFromInstanceOrString<T>>): T | null;
159
- peekRemoteState(identifier: StableDocumentIdentifier): ResourceDocument | null;
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(identifier: StableDocumentIdentifier): StructuredDocument<ResourceDocument> | null;
159
+ peekRequest(cacheKey: RequestKey): StructuredDocument<ResourceDocument> | null;
173
160
  /**
174
- * Push resource data from a remote source into the cache for this identifier
161
+ * Push resource data from a remote source into the cache for this ResourceKey
175
162
  *
176
163
  * @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
164
+ * @return if `hasRecord` is true then calculated key changes should be returned
181
165
  */
182
- upsert(identifier: StableRecordIdentifier, data: ResourceBlob, hasRecord: boolean): void | string[];
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 `identifier` of the entity that
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
- * identifier: StableRecordIdentifier | StableDocumentIdentifier;
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(identifier: StableRecordIdentifier, createArgs?: Record<string, unknown>): Record<string, unknown>;
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(identifier: StableRecordIdentifier, context: RequestContext): void;
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 identifier - the primary identifier that was operated on
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(identifier: StableRecordIdentifier, result: StructuredDataDocument<unknown>): SingleResourceDataDocument;
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(identifier: StableRecordIdentifier, errors?: ApiError[]): void;
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(identifier: StableRecordIdentifier): void;
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(identifier: StableRecordIdentifier, field: string | string[]): Value | undefined;
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(identifier: StableRecordIdentifier, field: string | string[]): Value | undefined;
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(identifier: StableRecordIdentifier, field: string | string[], value: Value): void;
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(identifier: StableRecordIdentifier): ChangedAttributesHash;
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(identifier: StableRecordIdentifier): boolean;
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
- * @param identifier
379
- * @return {String[]} the names of fields that were restored
336
+ * @return the names of fields that were restored
380
337
  */
381
- rollbackAttrs(identifier: StableRecordIdentifier): string[];
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: StableRecordIdentifier[];
392
- additions: Set<StableRecordIdentifier>;
393
- removals: Set<StableRecordIdentifier>;
394
- localState: StableRecordIdentifier[];
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: StableRecordIdentifier | null;
400
- localState: StableRecordIdentifier | null;
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(identifier: StableRecordIdentifier): Map<string, RelationshipDiff>;
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(identifier: StableRecordIdentifier): boolean;
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
- * @param {StableRecordIdentifier} identifier
426
- * @return {String[]} the names of relationships that were restored
378
+ * @return the names of relationships that were restored
427
379
  */
428
- rollbackRelationships(identifier: StableRecordIdentifier): string[];
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(identifier: StableRecordIdentifier, field: string, isCollection?: boolean): ResourceRelationship | CollectionRelationship;
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(identifier: StableRecordIdentifier, field: string, isCollection?: boolean): ResourceRelationship | CollectionRelationship;
394
+ getRemoteRelationship(cacheKey: ResourceKey, field: string, isCollection?: boolean): ResourceRelationship | CollectionRelationship;
447
395
  // Resource State
448
396
  // ===============
449
397
  /**
@@ -453,51 +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(identifier: StableRecordIdentifier, isDeleted: boolean): void;
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
- * @param identifier
465
- * @return {JsonApiError[]}
466
410
  */
467
- getErrors(identifier: StableRecordIdentifier): ApiError[];
411
+ getErrors(cacheKey: ResourceKey): ApiError[];
468
412
  /**
469
413
  * Query the cache for whether a given resource has any available data
470
414
  *
471
415
  * @public
472
- * @param identifier
473
- * @return {Boolean}
474
416
  */
475
- isEmpty(identifier: StableRecordIdentifier): boolean;
417
+ isEmpty(cacheKey: ResourceKey): boolean;
476
418
  /**
477
419
  * Query the cache for whether a given resource was created locally and not
478
420
  * yet persisted.
479
421
  *
480
422
  * @public
481
- * @param identifier
482
- * @return {Boolean}
483
423
  */
484
- isNew(identifier: StableRecordIdentifier): boolean;
424
+ isNew(cacheKey: ResourceKey): boolean;
485
425
  /**
486
426
  * Query the cache for whether a given resource is marked as deleted (but not
487
427
  * necessarily persisted yet).
488
428
  *
489
429
  * @public
490
- * @param identifier
491
- * @return {Boolean}
492
430
  */
493
- isDeleted(identifier: StableRecordIdentifier): boolean;
431
+ isDeleted(cacheKey: ResourceKey): boolean;
494
432
  /**
495
433
  * Query the cache for whether a given resource has been deleted and that deletion
496
434
  * has also been persisted.
497
435
  *
498
436
  * @public
499
- * @param identifier
500
- * @return {Boolean}
501
437
  */
502
- isDeletionCommitted(identifier: StableRecordIdentifier): boolean;
438
+ isDeletionCommitted(cacheKey: ResourceKey): boolean;
503
439
  }
@@ -1,46 +1,46 @@
1
1
  import type { AddToResourceRelationshipMutation as AddResourceMutation, RemoveFromResourceRelationshipMutation as RemoveResourceMutation } from "./cache/mutations.js";
2
2
  import type { AddToResourceRelationshipOperation as AddResourceOperation, RemoveFromResourceRelationshipOperation as RemoveResourceOperation, UpdateResourceRelationshipOperation } from "./cache/operations.js";
3
- import type { StableRecordIdentifier } from "./identifier.js";
3
+ import type { ResourceKey } from "./identifier.js";
4
4
  import type { CollectionResourceRelationship, SingleResourceRelationship } from "./spec/json-api-raw.js";
5
5
  export interface Operation {
6
6
  op: string;
7
7
  }
8
8
  export interface UpdateRelationshipOperation {
9
9
  op: "updateRelationship";
10
- record: StableRecordIdentifier;
10
+ record: ResourceKey;
11
11
  field: string;
12
12
  value: SingleResourceRelationship | CollectionResourceRelationship;
13
13
  }
14
14
  export interface DeleteRecordOperation {
15
15
  op: "deleteRecord";
16
- record: StableRecordIdentifier;
16
+ record: ResourceKey;
17
17
  isNew: boolean;
18
18
  }
19
19
  export interface UnknownOperation {
20
20
  op: "never";
21
- record: StableRecordIdentifier;
21
+ record: ResourceKey;
22
22
  field: string;
23
23
  }
24
24
  export interface ReplaceRelatedRecordOperation {
25
25
  op: "replaceRelatedRecord";
26
- record: StableRecordIdentifier;
26
+ record: ResourceKey;
27
27
  field: string;
28
- value: StableRecordIdentifier | null;
29
- prior?: StableRecordIdentifier;
28
+ value: ResourceKey | null;
29
+ prior?: ResourceKey;
30
30
  index?: number;
31
31
  }
32
32
  export interface SortRelatedRecords {
33
33
  op: "sortRelatedRecords";
34
- record: StableRecordIdentifier;
34
+ record: ResourceKey;
35
35
  field: string;
36
- value: StableRecordIdentifier[];
36
+ value: ResourceKey[];
37
37
  }
38
38
  export interface ReplaceRelatedRecordsOperation {
39
39
  op: "replaceRelatedRecords";
40
- record: StableRecordIdentifier;
40
+ record: ResourceKey;
41
41
  field: string;
42
- value: StableRecordIdentifier[];
43
- prior?: StableRecordIdentifier[];
42
+ value: ResourceKey[];
43
+ prior?: ResourceKey[];
44
44
  index?: number;
45
45
  }
46
46
  export type RemoteRelationshipOperation = UpdateResourceRelationshipOperation | UpdateRelationshipOperation | ReplaceRelatedRecordOperation | ReplaceRelatedRecordsOperation | RemoveResourceOperation | AddResourceOperation | DeleteRecordOperation | SortRelatedRecords;
@@ -1,112 +1,88 @@
1
1
  // provided for additional debuggability
2
2
  export declare const DEBUG_CLIENT_ORIGINATED: unique symbol;
3
- export declare const DEBUG_IDENTIFIER_BUCKET: unique symbol;
3
+ export declare const DEBUG_KEY_TYPE: unique symbol;
4
4
  export declare const DEBUG_STALE_CACHE_OWNER: unique symbol;
5
5
  // also present in production
6
6
  export declare const CACHE_OWNER: "__$co";
7
- export type IdentifierBucket = "record" | "document";
8
- export interface Identifier {
9
- lid: string;
10
- clientId?: string;
11
- }
12
- export interface ExistingRecordIdentifier<T extends string = string> extends Identifier {
13
- id: string;
14
- type: T;
15
- }
16
- export interface NewRecordIdentifier<T extends string = string> extends Identifier {
17
- id: string | null;
18
- type: T;
19
- }
20
- export type StableDocumentIdentifier = {
21
- lid: string;
22
- };
23
- export type RequestKey = StableDocumentIdentifier;
7
+ export type CacheKeyType = "record" | "document";
24
8
  /**
25
- * An Identifier specific to a record which may or may not
26
- * be present in the cache.
9
+ * A referentially stable object with a unique string (lid) that can be used
10
+ * as a reference to request data in the cache.
27
11
  *
28
- * The absence of an `id` DOES NOT indicate that this
29
- * Identifier is for a new client-created record as it
30
- * may also indicate that it was generated for a secondary
31
- * index and the primary `id` index is not yet known.
12
+ * Only requests that are assigned a RequestKey are retrievable/replayable from
13
+ * the cache, though requests without RequestKeys may still update cache state.
32
14
  *
33
- * @internal
15
+ * @public
34
16
  */
35
- export type RecordIdentifier<T extends string = string> = ExistingRecordIdentifier<T> | NewRecordIdentifier<T>;
17
+ export interface RequestKey {
18
+ lid: string;
19
+ type: "@document";
20
+ }
21
+ /** @deprecated use {@link RequestKey} */
22
+ export type StableDocumentIdentifier = RequestKey;
36
23
  /**
37
- * Used when an Identifier is known to be the stable version
38
- *
39
- * @internal
24
+ * Used when an ResourceKey is known to be the stable version
40
25
  */
41
- export interface StableIdentifier extends Identifier {
42
- [DEBUG_IDENTIFIER_BUCKET]?: string;
26
+ interface ResourceKeyBase<T extends string = string> {
27
+ /**
28
+ * A string representing a unique identity.
29
+ *
30
+ * @public
31
+ */
32
+ lid: string;
33
+ /**
34
+ * the primary `ResourceType` or "model name" this ResourceKey belongs to.
35
+ *
36
+ * @public
37
+ */
38
+ type: T;
43
39
  }
44
40
  /**
45
- * Used when a StableRecordIdentifier was not created locally as part
41
+ * Used when a ResourceKey was not created locally as part
46
42
  * of a call to store.createRecord
47
43
  *
48
- * Distinguishing between this Identifier and one for a client created
49
- * record that was created with an ID is generally speaking not possible
44
+ * Distinguishing between this ResourceKey and one for a client created
45
+ * resource that was created with an ID is generally speaking not possible
50
46
  * at runtime, so anything with an ID typically narrows to this.
51
- *
52
- * @internal
53
47
  */
54
- export interface StableExistingRecordIdentifier<T extends string = string> extends StableIdentifier {
48
+ export interface PersistedResourceKey<T extends string = string> extends ResourceKeyBase<T> {
49
+ /**
50
+ * the PrimaryKey for the resource this ResourceKey represents.
51
+ *
52
+ * @public
53
+ */
55
54
  id: string;
56
- type: T;
57
- [DEBUG_CLIENT_ORIGINATED]?: boolean;
58
- [CACHE_OWNER]: number | undefined;
59
- [DEBUG_STALE_CACHE_OWNER]?: number | undefined;
60
55
  }
56
+ /** @deprecated use {@link PersistedResourceKey} */
57
+ export type StableExistingRecordIdentifier<T extends string = string> = PersistedResourceKey<T>;
61
58
  /**
62
- * Used when a StableRecordIdentifier was created locally
59
+ * Used when a ResourceKey was created locally
63
60
  * (by a call to store.createRecord).
64
61
  *
65
- * It is possible in rare circumstances to have a StableRecordIdentifier
62
+ * It is possible in rare circumstances to have a ResourceKey
66
63
  * that is not for a new record but does not have an ID. This would
67
64
  * happen if a user intentionally created one for use with a secondary-index
68
65
  * prior to the record having been fully loaded.
69
- *
70
- * @internal
71
66
  */
72
- export interface StableNewRecordIdentifier<T extends string = string> extends StableIdentifier {
67
+ export interface NewResourceKey<T extends string = string> extends ResourceKeyBase<T> {
68
+ /**
69
+ * the PrimaryKey for the resource this ResourceKey represents. `null`
70
+ * if not yet assigned a PrimaryKey value.
71
+ *
72
+ * @public
73
+ */
73
74
  id: string | null;
74
- type: T;
75
- [DEBUG_CLIENT_ORIGINATED]?: boolean;
76
- [CACHE_OWNER]: number | undefined;
77
- [DEBUG_STALE_CACHE_OWNER]?: number | undefined;
78
75
  }
79
76
  /**
80
77
  * A referentially stable object with a unique string (lid) that can be used
81
78
  * as a reference to data in the cache.
82
79
  *
83
- * Every record instance has a unique identifier, and identifiers may refer
80
+ * Every resource has a unique ResourceKey, and ResourceKeys may refer
84
81
  * to data that has never been loaded (for instance, in an async relationship).
85
82
  *
86
- * @class StableRecordIdentifier
87
- * @public
88
- */
89
- /**
90
- * A string representing a unique identity.
91
- *
92
- * @property lid
93
- * @type {String}
94
- * @public
95
- */
96
- /**
97
- * the primary resource `type` or `modelName` this identity belongs to.
98
- *
99
- * @property type
100
- * @type {String}
101
- * @public
102
- */
103
- /**
104
- * the primary id for the record this identity belongs to. `null`
105
- * if not yet assigned an id.
106
- *
107
- * @property id
108
- * @type {String | null}
109
83
  * @public
110
84
  */
111
- export type StableRecordIdentifier<T extends string = string> = StableExistingRecordIdentifier<T> | StableNewRecordIdentifier<T>;
112
- export type ResourceKey<T extends string = string> = StableRecordIdentifier<T>;
85
+ export type ResourceKey<T extends string = string> = PersistedResourceKey<T> | NewResourceKey<T>;
86
+ /** @deprecated use {@link ResourceKey} */
87
+ export type StableRecordIdentifier<T extends string = string> = ResourceKey<T>;
88
+ export {};
@@ -1,9 +1,8 @@
1
- import type { Includes, TypedRecordInstance } from "./record.js";
2
1
  export type SerializablePrimitive = string | number | boolean | null;
3
2
  export type Serializable = SerializablePrimitive | SerializablePrimitive[];
4
3
  export type QueryParamsSerializationOptions = {
5
4
  arrayFormat?: "bracket" | "indices" | "repeat" | "comma";
6
5
  };
7
- export type QueryParamsSource<T = unknown> = ({
8
- include?: T extends TypedRecordInstance ? Includes<T>[] : string | string[];
6
+ export type QueryParamsSource = ({
7
+ include?: string | string[];
9
8
  } & Record<Exclude<string, "include">, Serializable>) | URLSearchParams;