@warp-drive/core 5.7.0-alpha.9 → 5.7.0-beta.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,9 +1,9 @@
1
1
  import type { Cache, ChangedAttributesHash, RelationshipDiff } from "../../../types/cache.js";
2
2
  import type { Change } from "../../../types/cache/change.js";
3
- import type { MergeOperation } from "../../../types/cache/operations.js";
3
+ import type { Operation } from "../../../types/cache/operations.js";
4
4
  import type { CollectionRelationship, ResourceRelationship } from "../../../types/cache/relationship.js";
5
5
  import type { LocalRelationshipOperation } from "../../../types/graph.js";
6
- import type { StableDocumentIdentifier, StableRecordIdentifier } from "../../../types/identifier.js";
6
+ import type { RequestKey, ResourceKey } from "../../../types/identifier.js";
7
7
  import type { Value } from "../../../types/json/raw.js";
8
8
  import type { StructuredDataDocument, StructuredDocument } from "../../../types/request.js";
9
9
  import type { ResourceDocument, SingleResourceDataDocument } from "../../../types/spec/document.js";
@@ -28,11 +28,8 @@ import type { StoreRequestContext } from "../cache-handler/handler.js";
28
28
  * @public
29
29
  */
30
30
  export declare class CacheManager implements Cache {
31
- #private;
32
31
  version: "2";
33
32
  constructor(cache: Cache);
34
- // Cache Management
35
- // ================
36
33
  /**
37
34
  * Cache the response to a request
38
35
  *
@@ -61,14 +58,11 @@ export declare class CacheManager implements Cache {
61
58
  /**
62
59
  * Perform an operation on the cache to update the remote state.
63
60
  *
64
- * Note: currently the only valid operation is a MergeOperation
65
- * which occurs when a collision of identifiers is detected.
66
- *
67
61
  * @public
68
62
  * @param op the operation to perform
69
63
  * @return {void}
70
64
  */
71
- patch(op: MergeOperation): void;
65
+ patch(op: Operation | Operation[]): void;
72
66
  /**
73
67
  * Update resource data with a local mutation. Currently supports operations
74
68
  * on relationships only.
@@ -105,34 +99,29 @@ export declare class CacheManager implements Cache {
105
99
  * notifications for relational data.
106
100
  *
107
101
  * @public
108
- * @param {StableRecordIdentifier | StableDocumentIdentifier} identifier
102
+ * @param {ResourceKey | RequestKey} cacheKey
109
103
  * @return {ResourceDocument | ResourceBlob | null} the known resource data
110
104
  */
111
- peek(identifier: StableRecordIdentifier): unknown;
112
- peek(identifier: StableDocumentIdentifier): ResourceDocument | null;
113
- peekRemoteState(identifier: StableRecordIdentifier): unknown;
114
- peekRemoteState(identifier: StableDocumentIdentifier): ResourceDocument | null;
105
+ peek(cacheKey: ResourceKey): unknown;
106
+ peek(cacheKey: RequestKey): ResourceDocument | null;
107
+ peekRemoteState(cacheKey: ResourceKey): unknown;
108
+ peekRemoteState(cacheKey: RequestKey): ResourceDocument | null;
115
109
  /**
116
110
  * Peek the Cache for the existing request data associated with
117
111
  * a cacheable request
118
112
  *
119
- * @param {StableDocumentIdentifier}
120
- * @return {StableDocumentIdentifier | null}
113
+ * @param {RequestKey}
114
+ * @return {RequestKey | null}
121
115
  * @public
122
116
  */
123
- peekRequest(identifier: StableDocumentIdentifier): StructuredDocument<ResourceDocument> | null;
117
+ peekRequest(key: RequestKey): StructuredDocument<ResourceDocument> | null;
124
118
  /**
125
- * Push resource data from a remote source into the cache for this identifier
119
+ * Push resource data from a remote source into the cache for this ResourceKey
126
120
  *
127
121
  * @public
128
- * @param identifier
129
- * @param data
130
- * @param hasRecord
131
- * @return {void | string[]} if `hasRecord` is true then calculated key changes should be returned
122
+ * @return if `hasRecord` is true then calculated key changes should be returned
132
123
  */
133
- upsert(identifier: StableRecordIdentifier, data: unknown, hasRecord: boolean): void | string[];
134
- // Cache Forking Support
135
- // =====================
124
+ upsert(key: ResourceKey, data: unknown, hasRecord: boolean): void | string[];
136
125
  /**
137
126
  * Create a fork of the cache from the current state.
138
127
  *
@@ -165,7 +154,7 @@ export declare class CacheManager implements Cache {
165
154
  * `Change` entry in the returned array.
166
155
  *
167
156
  * A `Change` is described by an object containing up to
168
- * three properties: (1) the `identifier` of the entity that
157
+ * three properties: (1) the `ResourceKey` of the entity that
169
158
  * changed; (2) the `op` code of that change being one of
170
159
  * `upsert` or `remove`, and if the op is `upsert` a `patch`
171
160
  * containing the data to merge into the cache for the given
@@ -180,7 +169,7 @@ export declare class CacheManager implements Cache {
180
169
  *
181
170
  * ```ts
182
171
  * interface Change {
183
- * identifier: StableRecordIdentifier | StableDocumentIdentifier;
172
+ * key: ResourceKey | RequestKey;
184
173
  * op: 'upsert' | 'remove';
185
174
  * patch?: unknown;
186
175
  * }
@@ -189,8 +178,6 @@ export declare class CacheManager implements Cache {
189
178
  * @public
190
179
  */
191
180
  diff(): Promise<Change[]>;
192
- // SSR Support
193
- // ===========
194
181
  /**
195
182
  * Serialize the entire contents of the Cache into a Stream
196
183
  * which may be fed back into a new instance of the same Cache
@@ -217,10 +204,6 @@ export declare class CacheManager implements Cache {
217
204
  * @public
218
205
  */
219
206
  hydrate(stream: ReadableStream<unknown>): Promise<void>;
220
- // Cache
221
- // =====
222
- // Resource Support
223
- // ================
224
207
  /**
225
208
  * [LIFECYCLE] Signal to the cache that a new record has been instantiated on the client
226
209
  *
@@ -228,99 +211,74 @@ export declare class CacheManager implements Cache {
228
211
  * process. This return value behavior is deprecated.
229
212
  *
230
213
  * @public
231
- * @param identifier
232
- * @param options
233
214
  */
234
- clientDidCreate(identifier: StableRecordIdentifier, options?: Record<string, unknown>): Record<string, unknown>;
215
+ clientDidCreate(key: ResourceKey, options?: Record<string, unknown>): Record<string, unknown>;
235
216
  /**
236
217
  * [LIFECYCLE] Signals to the cache that a resource
237
218
  * will be part of a save transaction.
238
219
  *
239
220
  * @public
240
- * @param identifier
221
+ * @param key
241
222
  */
242
- willCommit(identifier: StableRecordIdentifier, context: StoreRequestContext): void;
223
+ willCommit(key: ResourceKey, context: StoreRequestContext): void;
243
224
  /**
244
225
  * [LIFECYCLE] Signals to the cache that a resource
245
226
  * was successfully updated as part of a save transaction.
246
227
  *
247
228
  * @public
248
- * @param identifier
249
- * @param data
250
229
  */
251
- didCommit(identifier: StableRecordIdentifier, result: StructuredDataDocument<unknown>): SingleResourceDataDocument;
230
+ didCommit(key: ResourceKey, result: StructuredDataDocument<unknown>): SingleResourceDataDocument;
252
231
  /**
253
232
  * [LIFECYCLE] Signals to the cache that a resource
254
233
  * was update via a save transaction failed.
255
234
  *
256
235
  * @public
257
- * @param identifier
258
- * @param errors
259
236
  */
260
- commitWasRejected(identifier: StableRecordIdentifier, errors?: ApiError[]): void;
237
+ commitWasRejected(key: ResourceKey, errors?: ApiError[]): void;
261
238
  /**
262
239
  * [LIFECYCLE] Signals to the cache that all data for a resource
263
240
  * should be cleared.
264
241
  *
265
242
  * @public
266
- * @param identifier
267
243
  */
268
- unloadRecord(identifier: StableRecordIdentifier): void;
269
- // Granular Resource Data APIs
270
- // ===========================
244
+ unloadRecord(key: ResourceKey): void;
271
245
  /**
272
246
  * Retrieve the data for an attribute from the cache
273
247
  *
274
248
  * @public
275
- * @param identifier
276
- * @param propertyName
277
- * @return {unknown}
278
249
  */
279
- getAttr(identifier: StableRecordIdentifier, propertyName: string): Value | undefined;
250
+ getAttr(key: ResourceKey, propertyName: string): Value | undefined;
280
251
  /**
281
252
  * Retrieve the remote state for an attribute from the cache
282
253
  *
283
254
  * @public
284
- * @param identifier
285
- * @param propertyName
286
- * @return {unknown}
287
255
  */
288
- getRemoteAttr(identifier: StableRecordIdentifier, propertyName: string): Value | undefined;
256
+ getRemoteAttr(key: ResourceKey, propertyName: string): Value | undefined;
289
257
  /**
290
258
  * Mutate the data for an attribute in the cache
291
259
  *
292
260
  * @public
293
- * @param identifier
294
- * @param propertyName
295
- * @param value
296
261
  */
297
- setAttr(identifier: StableRecordIdentifier, propertyName: string, value: Value): void;
262
+ setAttr(key: ResourceKey, propertyName: string, value: Value): void;
298
263
  /**
299
264
  * Query the cache for the changed attributes of a resource.
300
265
  *
301
266
  * @public
302
- * @param identifier
303
- * @return
304
267
  */
305
- changedAttrs(identifier: StableRecordIdentifier): ChangedAttributesHash;
268
+ changedAttrs(key: ResourceKey): ChangedAttributesHash;
306
269
  /**
307
270
  * Query the cache for whether any mutated attributes exist
308
271
  *
309
272
  * @public
310
- * @param identifier
311
- * @return {Boolean}
312
273
  */
313
- hasChangedAttrs(identifier: StableRecordIdentifier): boolean;
274
+ hasChangedAttrs(key: ResourceKey): boolean;
314
275
  /**
315
276
  * Tell the cache to discard any uncommitted mutations to attributes
316
277
  *
317
278
  * @public
318
- * @param identifier
319
279
  * @return the names of attributes that were restored
320
280
  */
321
- rollbackAttrs(identifier: StableRecordIdentifier): string[];
322
- // Relationships
323
- // =============
281
+ rollbackAttrs(key: ResourceKey): string[];
324
282
  /**
325
283
  * Query the cache for the changes to relationships of a resource.
326
284
  *
@@ -330,32 +288,28 @@ export declare class CacheManager implements Cache {
330
288
  * type RelationshipDiff =
331
289
  | {
332
290
  kind: 'collection';
333
- remoteState: StableRecordIdentifier[];
334
- additions: Set<StableRecordIdentifier>;
335
- removals: Set<StableRecordIdentifier>;
336
- localState: StableRecordIdentifier[];
291
+ remoteState: ResourceKey[];
292
+ additions: Set<ResourceKey>;
293
+ removals: Set<ResourceKey>;
294
+ localState: ResourceKey[];
337
295
  reordered: boolean;
338
296
  }
339
297
  | {
340
298
  kind: 'resource';
341
- remoteState: StableRecordIdentifier | null;
342
- localState: StableRecordIdentifier | null;
299
+ remoteState: ResourceKey | null;
300
+ localState: ResourceKey | null;
343
301
  };
344
302
  ```
345
303
  *
346
304
  * @public
347
- * @param {StableRecordIdentifier} identifier
348
- * @return {Map<string, RelationshipDiff>}
349
305
  */
350
- changedRelationships(identifier: StableRecordIdentifier): Map<string, RelationshipDiff>;
306
+ changedRelationships(key: ResourceKey): Map<string, RelationshipDiff>;
351
307
  /**
352
308
  * Query the cache for whether any mutated attributes exist
353
309
  *
354
310
  * @public
355
- * @param {StableRecordIdentifier} identifier
356
- * @return {Boolean}
357
311
  */
358
- hasChangedRelationships(identifier: StableRecordIdentifier): boolean;
312
+ hasChangedRelationships(key: ResourceKey): boolean;
359
313
  /**
360
314
  * Tell the cache to discard any uncommitted mutations to relationships.
361
315
  *
@@ -364,80 +318,61 @@ export declare class CacheManager implements Cache {
364
318
  * This method is a candidate to become a mutation
365
319
  *
366
320
  * @public
367
- * @param {StableRecordIdentifier} identifier
368
- * @return {String[]} the names of relationships that were restored
321
+ * @return the names of relationships that were restored
369
322
  */
370
- rollbackRelationships(identifier: StableRecordIdentifier): string[];
323
+ rollbackRelationships(key: ResourceKey): string[];
371
324
  /**
372
325
  * Query the cache for the current state of a relationship property
373
326
  *
374
327
  * @public
375
- * @param identifier
376
- * @param propertyName
377
328
  * @return resource relationship object
378
329
  */
379
- getRelationship(identifier: StableRecordIdentifier, propertyName: string): ResourceRelationship | CollectionRelationship;
330
+ getRelationship(key: ResourceKey, propertyName: string): ResourceRelationship | CollectionRelationship;
380
331
  /**
381
332
  * Query the cache for the remote state of a relationship property
382
333
  *
383
334
  * @public
384
- * @param identifier
385
- * @param propertyName
386
335
  * @return resource relationship object
387
336
  */
388
- getRemoteRelationship(identifier: StableRecordIdentifier, propertyName: string): ResourceRelationship | CollectionRelationship;
389
- // Resource State
390
- // ===============
337
+ getRemoteRelationship(key: ResourceKey, propertyName: string): ResourceRelationship | CollectionRelationship;
391
338
  /**
392
339
  * Update the cache state for the given resource to be marked as locally deleted,
393
340
  * or remove such a mark.
394
341
  *
395
342
  * @public
396
- * @param identifier
397
- * @param isDeleted
398
343
  */
399
- setIsDeleted(identifier: StableRecordIdentifier, isDeleted: boolean): void;
344
+ setIsDeleted(key: ResourceKey, isDeleted: boolean): void;
400
345
  /**
401
346
  * Query the cache for any validation errors applicable to the given resource.
402
347
  *
403
348
  * @public
404
- * @param identifier
405
- * @return
406
349
  */
407
- getErrors(identifier: StableRecordIdentifier): ApiError[];
350
+ getErrors(key: ResourceKey): ApiError[];
408
351
  /**
409
352
  * Query the cache for whether a given resource has any available data
410
353
  *
411
354
  * @public
412
- * @param identifier
413
- * @return {Boolean}
414
355
  */
415
- isEmpty(identifier: StableRecordIdentifier): boolean;
356
+ isEmpty(key: ResourceKey): boolean;
416
357
  /**
417
358
  * Query the cache for whether a given resource was created locally and not
418
359
  * yet persisted.
419
360
  *
420
361
  * @public
421
- * @param identifier
422
- * @return {Boolean}
423
362
  */
424
- isNew(identifier: StableRecordIdentifier): boolean;
363
+ isNew(key: ResourceKey): boolean;
425
364
  /**
426
365
  * Query the cache for whether a given resource is marked as deleted (but not
427
366
  * necessarily persisted yet).
428
367
  *
429
368
  * @public
430
- * @param identifier
431
- * @return {Boolean}
432
369
  */
433
- isDeleted(identifier: StableRecordIdentifier): boolean;
370
+ isDeleted(key: ResourceKey): boolean;
434
371
  /**
435
372
  * Query the cache for whether a given resource has been deleted and that deletion
436
373
  * has also been persisted.
437
374
  *
438
375
  * @public
439
- * @param identifier
440
- * @return {Boolean}
441
376
  */
442
- isDeletionCommitted(identifier: StableRecordIdentifier): boolean;
377
+ isDeletionCommitted(key: ResourceKey): boolean;
443
378
  }
@@ -1,21 +1,19 @@
1
- import type { StableDocumentIdentifier, StableRecordIdentifier } from "../../../types/identifier.js";
1
+ import type { RequestKey, ResourceKey } from "../../../types/identifier.js";
2
2
  import type { Store } from "../store-service.js";
3
3
  export type UnsubscribeToken = object;
4
4
  export type CacheOperation = "added" | "removed" | "updated" | "state";
5
5
  export type DocumentCacheOperation = "invalidated" | "added" | "removed" | "updated" | "state";
6
6
  export type NotificationType = "attributes" | "relationships" | "identity" | "errors" | "meta" | CacheOperation;
7
7
  export interface NotificationCallback {
8
- (identifier: StableRecordIdentifier, notificationType: "attributes" | "relationships", key?: string): void;
9
- (identifier: StableRecordIdentifier, notificationType: "errors" | "meta" | "identity" | "state"): void;
10
- (identifier: StableRecordIdentifier, notificationType: CacheOperation): void;
8
+ (cacheKey: ResourceKey, notificationType: "attributes" | "relationships", key?: string): void;
9
+ (cacheKey: ResourceKey, notificationType: "errors" | "meta" | "identity" | "state"): void;
10
+ (cacheKey: ResourceKey, notificationType: CacheOperation): void;
11
11
  }
12
12
  export interface ResourceOperationCallback {
13
- // resource updates
14
- (identifier: StableRecordIdentifier, notificationType: CacheOperation): void;
13
+ (cacheKey: ResourceKey, notificationType: CacheOperation): void;
15
14
  }
16
15
  export interface DocumentOperationCallback {
17
- // document updates
18
- (identifier: StableDocumentIdentifier, notificationType: DocumentCacheOperation): void;
16
+ (cacheKey: RequestKey, notificationType: DocumentCacheOperation): void;
19
17
  }
20
18
  /**
21
19
  * The NotificationManager provides the ability to subscribe to
@@ -28,48 +26,35 @@ export interface DocumentOperationCallback {
28
26
  * @public
29
27
  */
30
28
  export default class NotificationManager {
31
- /** @internal */
32
- private store;
33
- /** @internal */
34
- private isDestroyed;
35
- /** @internal */
36
- private _buffered;
37
- /** @internal */
38
- private _cache;
39
- /** @internal */
40
- private _hasFlush;
41
- /** @internal */
42
- private _onFlushCB?;
43
29
  constructor(store: Store);
44
30
  /**
45
- * Subscribe to changes for a given resource identifier, resource addition/removal, or document addition/removal.
31
+ * Subscribe to changes for a given ResourceKey, RequestKey, or addition/removal of any resource
32
+ * or document.
46
33
  *
47
34
  * ```ts
48
35
  * export type CacheOperation = 'added' | 'removed' | 'updated' | 'state';
49
36
  *
50
37
  * export interface NotificationCallback {
51
- * (identifier: StableRecordIdentifier, notificationType: 'attributes' | 'relationships', key?: string): void;
52
- * (identifier: StableRecordIdentifier, notificationType: 'errors' | 'meta' | 'identity' | 'state'): void;
53
- * (identifier: StableRecordIdentifier, notificationType: NotificationType, key?: string): void;
38
+ * (cacheKey: ResourceKey, notificationType: 'attributes' | 'relationships', key?: string): void;
39
+ * (cacheKey: ResourceKey, notificationType: 'errors' | 'meta' | 'identity' | 'state'): void;
40
+ * (cacheKey: ResourceKey, notificationType: NotificationType, key?: string): void;
54
41
  * }
55
42
  * export interface ResourceOperationCallback {
56
43
  * // resource updates
57
- * (identifier: StableRecordIdentifier, notificationType: CacheOperation): void;
44
+ * (cacheKey: ResourceKey, notificationType: CacheOperation): void;
58
45
  * }
59
46
  * export interface DocumentOperationCallback {
60
47
  * // document updates
61
- * (identifier: StableDocumentIdentifier, notificationType: CacheOperation): void;
48
+ * (cacheKey: RequestKey, notificationType: CacheOperation): void;
62
49
  * }
63
50
  * ```
64
51
  *
65
52
  * @public
66
- * @param {StableDocumentIdentifier | StableRecordIdentifier | 'resource' | 'document'} identifier
67
- * @param {NotificationCallback | ResourceOperationCallback | DocumentOperationCallback} callback
68
- * @return {UnsubscribeToken} an opaque token to be used with unsubscribe
53
+ * @return an opaque token to be used with unsubscribe
69
54
  */
70
- subscribe(identifier: StableRecordIdentifier, callback: NotificationCallback): UnsubscribeToken;
71
- subscribe(identifier: "resource", callback: ResourceOperationCallback): UnsubscribeToken;
72
- subscribe(identifier: "document" | StableDocumentIdentifier, callback: DocumentOperationCallback): UnsubscribeToken;
55
+ subscribe(cacheKey: ResourceKey, callback: NotificationCallback): UnsubscribeToken;
56
+ subscribe(cacheKey: "resource", callback: ResourceOperationCallback): UnsubscribeToken;
57
+ subscribe(cacheKey: "document" | RequestKey, callback: DocumentOperationCallback): UnsubscribeToken;
73
58
  /**
74
59
  * remove a previous subscription
75
60
  *
@@ -81,18 +66,18 @@ export default class NotificationManager {
81
66
  *
82
67
  * @private
83
68
  */
84
- notify(identifier: StableRecordIdentifier, value: "attributes" | "relationships", key?: string): boolean;
85
- notify(identifier: StableRecordIdentifier, value: "errors" | "meta" | "identity" | "state"): boolean;
86
- notify(identifier: StableRecordIdentifier, value: CacheOperation): boolean;
87
- notify(identifier: StableDocumentIdentifier, value: DocumentCacheOperation): boolean;
88
- /** @internal */
89
- _onNextFlush(cb: () => void): void;
90
- private _scheduleNotify;
91
- /** @internal */
69
+ notify(cacheKey: ResourceKey, value: "attributes" | "relationships", key?: string | null): boolean;
70
+ notify(cacheKey: ResourceKey, value: "errors" | "meta" | "identity" | "state", key?: null): boolean;
71
+ notify(cacheKey: ResourceKey, value: CacheOperation, key?: null): boolean;
72
+ notify(cacheKey: RequestKey, value: DocumentCacheOperation, key?: null): boolean;
73
+ }
74
+ /**
75
+ * This type exists for internal use only for
76
+ * where intimate contracts still exist either for
77
+ * the Test Suite or for Legacy code.
78
+ *
79
+ * @private
80
+ */
81
+ export interface PrivateNotificationManager extends NotificationManager {
92
82
  _flush(): void;
93
- private _flushNotification;
94
- private _flushNotification;
95
- private _flushNotification;
96
- /** @internal */
97
- destroy(): void;
98
83
  }
@@ -1,10 +1,11 @@
1
1
  import type { LocalRelationshipOperation } from "../../../types/graph.js";
2
- import type { StableDocumentIdentifier, StableRecordIdentifier } from "../../../types/identifier.js";
2
+ import type { RequestKey, ResourceKey } from "../../../types/identifier.js";
3
3
  import type { ImmutableRequestInfo } from "../../../types/request.js";
4
4
  import type { CollectionResourceDocument } from "../../../types/spec/json-api-raw.js";
5
- import { Collection, IdentifierArray } from "../record-arrays/identifier-array.js";
5
+ import type { LegacyLiveArray } from "../record-arrays/legacy-live-array.js";
6
+ import { type LegacyQueryArray } from "../record-arrays/legacy-query.js";
7
+ import { type ReactiveResourceArray } from "../record-arrays/resource-array.js";
6
8
  import type { Store } from "../store-service.js";
7
- import type { UnsubscribeToken } from "./notification-manager.js";
8
9
  /**
9
10
  * This is a clever optimization.
10
11
  *
@@ -38,60 +39,62 @@ import type { UnsubscribeToken } from "./notification-manager.js";
38
39
  * Sincerely,
39
40
  * - runspired (Chris Thoburn) 08/21/2022
40
41
  *
41
- * @function fastPush
42
- * @internal
42
+ * @private
43
43
  * @param target the array to push into
44
44
  * @param source the items to push into target
45
45
  */
46
46
  export declare function fastPush<T>(target: T[], source: T[]): void;
47
- type ChangeSet = Map<StableRecordIdentifier, "add" | "del">;
47
+ interface LegacyQueryInit {
48
+ type: string;
49
+ query: ImmutableRequestInfo | Record<string, unknown>;
50
+ }
51
+ interface AnonymousRequestCollectionInit {
52
+ source: ResourceKey[];
53
+ }
54
+ interface RequestCollectionInit {
55
+ source: ResourceKey[];
56
+ requestKey: RequestKey;
57
+ }
58
+ type ChangeSet = Map<ResourceKey, "add" | "del">;
48
59
  /**
49
- @class RecordArrayManager
50
- @internal
60
+ @hideconstructor
61
+ @private
51
62
  */
52
63
  export declare class RecordArrayManager {
53
- store: Store;
54
- isDestroying: boolean;
55
- isDestroyed: boolean;
56
- _set: Map<IdentifierArray, Set<StableRecordIdentifier>>;
57
- _live: Map<string, IdentifierArray>;
58
- _managed: Set<IdentifierArray>;
59
- _pending: Map<IdentifierArray, ChangeSet>;
60
- _identifiers: Map<StableRecordIdentifier, Set<Collection>>;
61
- _staged: Map<string, ChangeSet>;
62
- _subscription: UnsubscribeToken;
63
- _documentSubscription: UnsubscribeToken;
64
- _keyedArrays: Map<string, Collection>;
65
- _visibilitySet: Map<StableRecordIdentifier, boolean>;
66
64
  constructor(options: {
67
65
  store: Store;
68
66
  });
69
- _syncArray(array: IdentifierArray | Collection): void;
70
67
  mutate(mutation: LocalRelationshipOperation): void;
71
68
  /**
72
69
  Get the `RecordArray` for a modelName, which contains all loaded records of
73
70
  given modelName.
74
71
 
75
- @internal
76
- @param {String} modelName
77
- @return {RecordArray}
72
+ @private
78
73
  */
79
- liveArrayFor(type: string): IdentifierArray;
80
- getCollection(config: {
81
- type?: string;
82
- query?: ImmutableRequestInfo | Record<string, unknown>;
83
- identifiers?: StableRecordIdentifier[];
84
- doc?: CollectionResourceDocument;
85
- identifier?: StableDocumentIdentifier | null;
86
- }): Collection;
87
- dirtyArray(array: IdentifierArray, delta: number, shouldSyncFromCache: boolean): void;
88
- _getPendingFor(identifier: StableRecordIdentifier, includeManaged: boolean, isRemove?: boolean): Map<IdentifierArray, ChangeSet> | void;
89
- populateManagedArray(array: Collection, identifiers: StableRecordIdentifier[], payload: CollectionResourceDocument | null): void;
90
- identifierAdded(identifier: StableRecordIdentifier): void;
91
- identifierRemoved(identifier: StableRecordIdentifier): void;
92
- identifierChanged(identifier: StableRecordIdentifier): void;
93
- clear(isClear?: boolean): void;
74
+ liveArrayFor(type: string): LegacyLiveArray;
75
+ getCollection(config: LegacyQueryInit): LegacyQueryArray;
76
+ getCollection(config: AnonymousRequestCollectionInit): ReactiveResourceArray;
77
+ getCollection(config: RequestCollectionInit): ReactiveResourceArray;
78
+ /**
79
+ * @private
80
+ */
81
+ populateManagedArray(array: ReactiveResourceArray, identifiers: ResourceKey[], payload: CollectionResourceDocument | null): void;
82
+ pause(): void;
83
+ resume(): void;
94
84
  destroy(): void;
95
85
  }
96
- export declare function disassociateIdentifier(ArraysCache: Map<StableRecordIdentifier, Set<Collection>>, array: Collection, identifier: StableRecordIdentifier): void;
86
+ /**
87
+ * This type exists for internal use only for
88
+ * where intimate contracts still exist either for
89
+ * the Test Suite or for Legacy code.
90
+ *
91
+ * @private
92
+ */
93
+ export interface PrivateRecordArrayManager extends RecordArrayManager {
94
+ _live: Map<string, LegacyLiveArray>;
95
+ _pending: Map<ReactiveResourceArray, ChangeSet>;
96
+ _managed: Set<ReactiveResourceArray>;
97
+ clear(isClear?: boolean): void;
98
+ }
99
+ export declare function disassociateIdentifier(ArraysCache: Map<ResourceKey, Set<ReactiveResourceArray>>, array: ReactiveResourceArray, identifier: ResourceKey): void;
97
100
  export {};