houdini 1.2.54 → 1.2.55

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 (50) hide show
  1. package/build/cmd-cjs/index.js +141 -60
  2. package/build/cmd-esm/index.js +141 -60
  3. package/build/codegen-cjs/index.js +139 -58
  4. package/build/codegen-esm/index.js +139 -58
  5. package/build/lib-cjs/index.js +142 -59
  6. package/build/lib-esm/index.js +142 -59
  7. package/build/runtime/cache/cache.d.ts +1 -2
  8. package/build/runtime/cache/constants.d.ts +1 -0
  9. package/build/runtime/cache/lists.d.ts +2 -2
  10. package/build/runtime/cache/storage.d.ts +4 -4
  11. package/build/runtime/cache/stuff.d.ts +1 -0
  12. package/build/runtime/cache/subscription.d.ts +4 -1
  13. package/build/runtime-cjs/cache/cache.d.ts +1 -2
  14. package/build/runtime-cjs/cache/cache.js +41 -14
  15. package/build/runtime-cjs/cache/constants.d.ts +1 -0
  16. package/build/runtime-cjs/cache/constants.js +28 -0
  17. package/build/runtime-cjs/cache/lists.d.ts +2 -2
  18. package/build/runtime-cjs/cache/lists.js +14 -4
  19. package/build/runtime-cjs/cache/storage.d.ts +4 -4
  20. package/build/runtime-cjs/cache/storage.js +14 -6
  21. package/build/runtime-cjs/cache/stuff.d.ts +1 -0
  22. package/build/runtime-cjs/cache/stuff.js +5 -2
  23. package/build/runtime-cjs/cache/subscription.d.ts +4 -1
  24. package/build/runtime-cjs/cache/subscription.js +51 -19
  25. package/build/runtime-cjs/client/plugins/optimisticKeys.js +3 -1
  26. package/build/runtime-cjs/public/record.js +2 -2
  27. package/build/runtime-esm/cache/cache.d.ts +1 -2
  28. package/build/runtime-esm/cache/cache.js +35 -7
  29. package/build/runtime-esm/cache/constants.d.ts +1 -0
  30. package/build/runtime-esm/cache/constants.js +4 -0
  31. package/build/runtime-esm/cache/lists.d.ts +2 -2
  32. package/build/runtime-esm/cache/lists.js +13 -3
  33. package/build/runtime-esm/cache/storage.d.ts +4 -4
  34. package/build/runtime-esm/cache/storage.js +14 -6
  35. package/build/runtime-esm/cache/stuff.d.ts +1 -0
  36. package/build/runtime-esm/cache/stuff.js +3 -1
  37. package/build/runtime-esm/cache/subscription.d.ts +4 -1
  38. package/build/runtime-esm/cache/subscription.js +51 -19
  39. package/build/runtime-esm/client/plugins/optimisticKeys.js +3 -1
  40. package/build/runtime-esm/public/record.js +1 -1
  41. package/build/test-cjs/index.js +139 -58
  42. package/build/test-esm/index.js +139 -58
  43. package/build/vite-cjs/index.js +139 -58
  44. package/build/vite-esm/index.js +139 -58
  45. package/package.json +1 -1
  46. package/build/runtime/cache/schema.d.ts +0 -21
  47. package/build/runtime-cjs/cache/schema.d.ts +0 -21
  48. package/build/runtime-cjs/cache/schema.js +0 -66
  49. package/build/runtime-esm/cache/schema.d.ts +0 -21
  50. package/build/runtime-esm/cache/schema.js +0 -42
@@ -24,7 +24,7 @@ __export(lists_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(lists_exports);
26
26
  var import_flatten = require("../lib/flatten");
27
- var import_cache = require("./cache");
27
+ var import_stuff = require("./stuff");
28
28
  class ListManager {
29
29
  rootID;
30
30
  cache;
@@ -90,11 +90,15 @@ class ListManager {
90
90
  this.listsByField.get(parentID).get(list.key).push(handler);
91
91
  }
92
92
  removeIDFromAllLists(id, layer) {
93
+ let removed = false;
93
94
  for (const fieldMap of this.lists.values()) {
94
95
  for (const list of fieldMap.values()) {
95
- list.removeID(id, void 0, layer);
96
+ if (list.removeID(id, void 0, layer)) {
97
+ removed = true;
98
+ }
96
99
  }
97
100
  }
101
+ return removed;
98
102
  }
99
103
  deleteField(parentID, field) {
100
104
  if (!this.listsByField.get(parentID)?.has(field)) {
@@ -139,7 +143,7 @@ class List {
139
143
  manager,
140
144
  abstract
141
145
  }) {
142
- this.recordID = recordID || import_cache.rootID;
146
+ this.recordID = recordID || import_stuff.rootID;
143
147
  this.recordType = recordType;
144
148
  this.key = key;
145
149
  this.type = listType;
@@ -397,7 +401,13 @@ class ListCollection {
397
401
  this.lists.forEach((list) => list.addToList(...args));
398
402
  }
399
403
  removeID(...args) {
400
- this.lists.forEach((list) => list.removeID(...args));
404
+ let removed = false;
405
+ this.lists.forEach((list) => {
406
+ if (list.removeID(...args)) {
407
+ removed = true;
408
+ }
409
+ });
410
+ return removed;
401
411
  }
402
412
  remove(...args) {
403
413
  this.lists.forEach((list) => list.remove(...args));
@@ -3,15 +3,15 @@ export declare class InMemoryStorage {
3
3
  data: Layer[];
4
4
  private idCount;
5
5
  private rank;
6
- private idMaps;
6
+ idMaps: Record<string, string>;
7
7
  constructor();
8
8
  get layerCount(): number;
9
9
  get nextRank(): number;
10
- registerIDMapping(from: string | number, to: string | number): void;
10
+ registerIDMapping(from: string, to: string): void;
11
11
  createLayer(optimistic?: boolean): Layer;
12
12
  insert(id: string, field: string, location: OperationLocations, target: string): void;
13
- remove(id: string, field: string, target: string, layerToUser?: Layer): void;
14
- delete(id: string, layerToUser?: Layer): void;
13
+ remove(id: string, field: string, target: string, layer?: Layer): void;
14
+ delete(id: string, layer?: Layer): void;
15
15
  deleteField(id: string, field: string): void;
16
16
  getLayer(id: number): Layer;
17
17
  replaceID(replacement: {
@@ -41,6 +41,7 @@ class InMemoryStorage {
41
41
  }
42
42
  registerIDMapping(from, to) {
43
43
  this.idMaps[from] = to;
44
+ this.idMaps[to] = from;
44
45
  }
45
46
  createLayer(optimistic = false) {
46
47
  const layer = new Layer(this.idCount++);
@@ -51,11 +52,11 @@ class InMemoryStorage {
51
52
  insert(id, field, location, target) {
52
53
  return this.topLayer.insert(id, field, location, target);
53
54
  }
54
- remove(id, field, target, layerToUser = this.topLayer) {
55
- return layerToUser.remove(id, field, target);
55
+ remove(id, field, target, layer = this.topLayer) {
56
+ return layer.remove(id, field, target);
56
57
  }
57
- delete(id, layerToUser = this.topLayer) {
58
- return layerToUser.delete(id);
58
+ delete(id, layer = this.topLayer) {
59
+ return layer.delete(id);
59
60
  }
60
61
  deleteField(id, field) {
61
62
  return this.topLayer.deleteField(id, field);
@@ -93,6 +94,9 @@ class InMemoryStorage {
93
94
  return;
94
95
  }
95
96
  operations.remove.add(v);
97
+ if (this.idMaps[v]) {
98
+ operations.remove.add(this.idMaps[v]);
99
+ }
96
100
  });
97
101
  if (typeof layerValue === "undefined" && defaultValue) {
98
102
  const targetLayer = this.topLayer;
@@ -119,7 +123,11 @@ class InMemoryStorage {
119
123
  operations.remove.add(op.id);
120
124
  }
121
125
  if (isInsertOperation(op)) {
122
- operations.insert[op.location].unshift(op.id);
126
+ if (op.location === OperationLocation.end) {
127
+ operations.insert[op.location].unshift(op.id);
128
+ } else {
129
+ operations.insert[op.location].push(op.id);
130
+ }
123
131
  }
124
132
  if (isDeleteOperation(op)) {
125
133
  return {
@@ -365,7 +373,7 @@ class Layer {
365
373
  }
366
374
  for (const [id, ops] of Object.entries(layer.operations)) {
367
375
  const fields = {};
368
- for (const opMap of [this.operations[id], layer.operations[id]].filter(Boolean)) {
376
+ for (const opMap of [layer.operations[id], this.operations[id]].filter(Boolean)) {
369
377
  for (const [fieldName, operations] of Object.entries(opMap.fields || {})) {
370
378
  fields[fieldName] = [...fields[fieldName] || [], ...operations];
371
379
  }
@@ -1 +1,2 @@
1
1
  export declare function evaluateKey(key: string, variables?: Record<string, any> | null): string;
2
+ export declare const rootID = "_ROOT_";
@@ -18,7 +18,8 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var stuff_exports = {};
20
20
  __export(stuff_exports, {
21
- evaluateKey: () => evaluateKey
21
+ evaluateKey: () => evaluateKey,
22
+ rootID: () => rootID
22
23
  });
23
24
  module.exports = __toCommonJS(stuff_exports);
24
25
  function evaluateKey(key, variables = null) {
@@ -47,7 +48,9 @@ function evaluateKey(key, variables = null) {
47
48
  return evaluated;
48
49
  }
49
50
  const varChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789";
51
+ const rootID = "_ROOT_";
50
52
  // Annotate the CommonJS export names for ESM import in node:
51
53
  0 && (module.exports = {
52
- evaluateKey
54
+ evaluateKey,
55
+ rootID
53
56
  });
@@ -10,6 +10,7 @@ export declare class InMemorySubscriptions {
10
10
  private subscribers;
11
11
  private keyVersions;
12
12
  activeFields(parent: string): string[];
13
+ copySubscribers(from: string, to: string): void;
13
14
  add({ parent, spec, selection, variables, parentType, }: {
14
15
  parent: string;
15
16
  parentType?: string;
@@ -41,9 +42,11 @@ export declare class InMemorySubscriptions {
41
42
  parentType: string;
42
43
  }): void;
43
44
  get(id: string, field: string): FieldSelection[];
45
+ getAll(id: string): FieldSelection[];
44
46
  remove(id: string, selection: SubscriptionSelection, targets: SubscriptionSpec[], variables: {}, visited?: string[]): void;
45
47
  reset(): SubscriptionSpec[];
46
48
  private removeSubscribers;
47
- removeAllSubscribers(id: string, targets?: SubscriptionSpec[], visited?: string[]): void;
49
+ removeAllSubscribers(id: string, targets?: SubscriptionSpec[]): void;
48
50
  get size(): number;
51
+ findSubSelections(parentID: string, selection: SubscriptionSelection, variables: {}, searchTarget: string, selections?: SubscriptionSelection[]): Array<SubscriptionSelection>;
49
52
  }
@@ -23,7 +23,6 @@ __export(subscription_exports, {
23
23
  module.exports = __toCommonJS(subscription_exports);
24
24
  var import_flatten = require("../lib/flatten");
25
25
  var import_selection = require("../lib/selection");
26
- var import_cache = require("./cache");
27
26
  var import_stuff = require("./stuff");
28
27
  class InMemorySubscriptions {
29
28
  cache;
@@ -35,6 +34,9 @@ class InMemorySubscriptions {
35
34
  activeFields(parent) {
36
35
  return Object.keys(this.subscribers.get(parent) || {});
37
36
  }
37
+ copySubscribers(from, to) {
38
+ this.subscribers.set(to, this.subscribers.get(from) || /* @__PURE__ */ new Map());
39
+ }
38
40
  add({
39
41
  parent,
40
42
  spec,
@@ -217,6 +219,11 @@ class InMemorySubscriptions {
217
219
  get(id, field) {
218
220
  return this.subscribers.get(id)?.get(field)?.selections || [];
219
221
  }
222
+ getAll(id) {
223
+ return [...this.subscribers.get(id)?.values() || []].flatMap(
224
+ (fieldSub) => fieldSub.selections
225
+ );
226
+ }
220
227
  remove(id, selection, targets, variables, visited = []) {
221
228
  visited.push(id);
222
229
  const linkedIDs = [];
@@ -241,7 +248,7 @@ class InMemorySubscriptions {
241
248
  }
242
249
  }
243
250
  reset() {
244
- const subscribers = [...this.subscribers.entries()].filter(([id]) => !id.startsWith(import_cache.rootID));
251
+ const subscribers = [...this.subscribers.entries()].filter(([id]) => !id.startsWith(import_stuff.rootID));
245
252
  for (const [id, _fields] of subscribers) {
246
253
  this.subscribers.delete(id);
247
254
  }
@@ -258,7 +265,7 @@ class InMemorySubscriptions {
258
265
  }
259
266
  const subscriberField = subscriber.get(fieldName);
260
267
  for (const spec of specs) {
261
- const counts = subscriber.get(fieldName)?.referenceCounts;
268
+ const counts = subscriberField?.referenceCounts;
262
269
  if (!counts?.has(spec.set)) {
263
270
  continue;
264
271
  }
@@ -281,24 +288,23 @@ class InMemorySubscriptions {
281
288
  this.subscribers.delete(id);
282
289
  }
283
290
  }
284
- removeAllSubscribers(id, targets, visited = []) {
285
- visited.push(id);
286
- const subscriber = this.subscribers.get(id);
287
- for (const [key, val] of subscriber?.entries() ?? []) {
288
- const subscribers = targets || val.selections.map(([spec]) => spec);
289
- this.removeSubscribers(id, key, subscribers);
290
- const { value, kind } = this.cache._internal_unstable.storage.get(id, key);
291
- if (kind === "scalar") {
292
- continue;
293
- }
294
- const nextTargets = Array.isArray(value) ? (0, import_flatten.flatten)(value) : [value];
295
- for (const id2 of nextTargets) {
296
- if (visited.includes(id2)) {
297
- continue;
298
- }
299
- this.removeAllSubscribers(id2, subscribers, visited);
291
+ removeAllSubscribers(id, targets) {
292
+ if (!targets) {
293
+ targets = [...this.subscribers.get(id)?.values() || []].flatMap(
294
+ (spec) => spec.selections.flatMap((sel) => sel[0])
295
+ );
296
+ }
297
+ for (const target of targets) {
298
+ for (const subselection of this.findSubSelections(
299
+ target.parentID || import_stuff.rootID,
300
+ target.selection,
301
+ target.variables || {},
302
+ id
303
+ )) {
304
+ this.remove(id, subselection, targets, target.variables || {});
300
305
  }
301
306
  }
307
+ return;
302
308
  }
303
309
  get size() {
304
310
  let size = 0;
@@ -309,6 +315,32 @@ class InMemorySubscriptions {
309
315
  }
310
316
  return size;
311
317
  }
318
+ findSubSelections(parentID, selection, variables, searchTarget, selections = []) {
319
+ const __typename = this.cache._internal_unstable.storage.get(parentID, "__typename").value;
320
+ let targetSelection = (0, import_selection.getFieldsForType)(selection, __typename, false);
321
+ for (const fieldSelection of Object.values(targetSelection || {})) {
322
+ if (!fieldSelection.selection) {
323
+ continue;
324
+ }
325
+ const key = (0, import_stuff.evaluateKey)(fieldSelection.keyRaw, variables || {});
326
+ const linkedRecord = this.cache._internal_unstable.storage.get(parentID, key);
327
+ const links = !Array.isArray(linkedRecord.value) ? [linkedRecord.value] : (0, import_flatten.flatten)(linkedRecord.value);
328
+ if (links.includes(searchTarget)) {
329
+ selections.push(fieldSelection.selection);
330
+ } else {
331
+ for (const link of links) {
332
+ this.findSubSelections(
333
+ link,
334
+ fieldSelection.selection,
335
+ variables,
336
+ searchTarget,
337
+ selections
338
+ );
339
+ }
340
+ }
341
+ }
342
+ return selections;
343
+ }
312
344
  }
313
345
  // Annotate the CommonJS export names for ESM import in node:
314
346
  0 && (module.exports = {
@@ -93,7 +93,9 @@ const optimisticKeys = (cache, callbackCache = callbacks, keyCache = keys, objec
93
93
  });
94
94
  delete callbackCache[optimisticValue];
95
95
  },
96
- onIDChange: (optimisticValue, realValue) => cache.registerKeyMap(optimisticValue, realValue)
96
+ onIDChange: (optimisticValue, realValue) => {
97
+ cache.registerKeyMap(optimisticValue, realValue);
98
+ }
97
99
  }
98
100
  );
99
101
  }
@@ -21,7 +21,7 @@ __export(record_exports, {
21
21
  Record: () => Record
22
22
  });
23
23
  module.exports = __toCommonJS(record_exports);
24
- var import_cache = require("../cache/cache");
24
+ var import_stuff = require("../cache/stuff");
25
25
  var import_lib = require("../lib");
26
26
  var import_config = require("../lib/config");
27
27
  class Record {
@@ -39,7 +39,7 @@ class Record {
39
39
  this.#id = id;
40
40
  this.type = type;
41
41
  this.idFields = idFields;
42
- if (id !== import_cache.rootID) {
42
+ if (id !== import_stuff.rootID) {
43
43
  for (const key of (0, import_config.keyFieldsForType)(this.#cache.config, type)) {
44
44
  if (!(key in idFields)) {
45
45
  throw new Error("Missing key in idFields: " + key);
@@ -36,7 +36,7 @@ export declare class Cache {
36
36
  subscribe(spec: SubscriptionSpec, variables?: {}): void;
37
37
  unsubscribe(spec: SubscriptionSpec, variables?: {}): void;
38
38
  list(name: string, parentID?: string, allLists?: boolean): ListCollection;
39
- registerKeyMap(source: string | number, mapped: string | number): void;
39
+ registerKeyMap(source: string, mapped: string): void;
40
40
  delete(id: string, layer?: Layer): void;
41
41
  setConfig(config: ConfigFile): void;
42
42
  markTypeStale(options?: {
@@ -153,7 +153,6 @@ export declare function evaluateVariables(variables: ValueMap, args: GraphQLObje
153
153
  [k: string]: GraphQLValue;
154
154
  };
155
155
  export declare function variableValue(value: ValueNode, args: GraphQLObject): GraphQLValue;
156
- export declare const rootID = "_ROOT_";
157
156
  export declare function fragmentReference({ component, prop, }: {
158
157
  component: {
159
158
  name: string;
@@ -8,7 +8,7 @@ import { GarbageCollector } from "./gc";
8
8
  import { ListManager } from "./lists";
9
9
  import { StaleManager } from "./staleManager";
10
10
  import { InMemoryStorage } from "./storage";
11
- import { evaluateKey } from "./stuff";
11
+ import { evaluateKey, rootID } from "./stuff";
12
12
  import { InMemorySubscriptions } from "./subscription";
13
13
  class Cache {
14
14
  _internal_unstable;
@@ -84,11 +84,17 @@ class Cache {
84
84
  }
85
85
  registerKeyMap(source, mapped) {
86
86
  this._internal_unstable.storage.registerIDMapping(source, mapped);
87
+ this._internal_unstable.subscriptions.copySubscribers(source, mapped);
87
88
  }
88
89
  delete(id, layer) {
89
- this._internal_unstable.subscriptions.removeAllSubscribers(id);
90
- this._internal_unstable.lists.removeIDFromAllLists(id, layer);
91
- this._internal_unstable.storage.delete(id, layer);
90
+ const recordIDs = [this._internal_unstable.storage.idMaps[id], id].filter(
91
+ Boolean
92
+ );
93
+ for (const recordID of recordIDs) {
94
+ this._internal_unstable.subscriptions.removeAllSubscribers(recordID);
95
+ this._internal_unstable.lists.removeIDFromAllLists(recordID, layer);
96
+ this._internal_unstable.storage.delete(recordID, layer);
97
+ }
92
98
  }
93
99
  setConfig(config) {
94
100
  this._internal_unstable.setConfig(config);
@@ -394,6 +400,9 @@ class CacheInternal {
394
400
  layer,
395
401
  forceNotify
396
402
  });
403
+ let action = () => {
404
+ layer.writeLink(parent, key, linkedIDs);
405
+ };
397
406
  if (applyUpdates && updates) {
398
407
  if (key === "edges") {
399
408
  const newNodeIDs = [];
@@ -428,8 +437,26 @@ class CacheInternal {
428
437
  }
429
438
  if (update === "prepend") {
430
439
  linkedIDs = newIDs.concat(oldIDs);
440
+ if (layer?.optimistic) {
441
+ action = () => {
442
+ for (const id of newIDs) {
443
+ if (id) {
444
+ layer.insert(parent, key, "start", id);
445
+ }
446
+ }
447
+ };
448
+ }
431
449
  } else if (update === "append") {
432
450
  linkedIDs = oldIDs.concat(newIDs);
451
+ if (layer?.optimistic) {
452
+ action = () => {
453
+ for (const id of newIDs) {
454
+ if (id) {
455
+ layer.insert(parent, key, "end", id);
456
+ }
457
+ }
458
+ };
459
+ }
433
460
  } else if (update === "replace") {
434
461
  linkedIDs = newIDs;
435
462
  }
@@ -448,7 +475,7 @@ class CacheInternal {
448
475
  this.subscriptions.remove(lostID, fieldSelection, specs, variables);
449
476
  }
450
477
  if (contentChanged || oldIDs.length === 0 && newIDs.length === 0) {
451
- layer.writeLink(parent, key, linkedIDs);
478
+ action();
452
479
  }
453
480
  for (const id of newIDs.filter((id2) => !oldIDs.includes(id2))) {
454
481
  if (id == null) {
@@ -503,6 +530,9 @@ class CacheInternal {
503
530
  if (!targetID) {
504
531
  continue;
505
532
  }
533
+ toNotify.push(
534
+ ...this.subscriptions.getAll(targetID).filter((sub) => sub[0].parentID !== targetID)
535
+ );
506
536
  this.cache.delete(targetID, layer);
507
537
  }
508
538
  }
@@ -924,7 +954,6 @@ function variableValue(value, args) {
924
954
  );
925
955
  }
926
956
  }
927
- const rootID = "_ROOT_";
928
957
  function fragmentReference({
929
958
  component,
930
959
  prop
@@ -962,6 +991,5 @@ export {
962
991
  defaultComponentField,
963
992
  evaluateVariables,
964
993
  fragmentReference,
965
- rootID,
966
994
  variableValue
967
995
  };
@@ -0,0 +1 @@
1
+ export declare const rootID = "_ROOT_";
@@ -0,0 +1,4 @@
1
+ const rootID = "_ROOT_";
2
+ export {
3
+ rootID
4
+ };
@@ -21,7 +21,7 @@ export declare class ListManager {
21
21
  filters?: List['filters'];
22
22
  abstract?: boolean;
23
23
  }): void;
24
- removeIDFromAllLists(id: string, layer?: Layer): void;
24
+ removeIDFromAllLists(id: string, layer?: Layer): boolean;
25
25
  deleteField(parentID: string, field: string): void;
26
26
  reset(): void;
27
27
  }
@@ -77,7 +77,7 @@ export declare class ListCollection {
77
77
  append(...args: Parameters<List['append']>): void;
78
78
  prepend(...args: Parameters<List['prepend']>): void;
79
79
  addToList(...args: Parameters<List['addToList']>): void;
80
- removeID(...args: Parameters<List['removeID']>): void;
80
+ removeID(...args: Parameters<List['removeID']>): boolean;
81
81
  remove(...args: Parameters<List['remove']>): void;
82
82
  toggleElement(...args: Parameters<List['toggleElement']>): void;
83
83
  when(when?: ListWhen): ListCollection;
@@ -1,5 +1,5 @@
1
1
  import { flatten } from "../lib/flatten";
2
- import { rootID } from "./cache";
2
+ import { rootID } from "./stuff";
3
3
  class ListManager {
4
4
  rootID;
5
5
  cache;
@@ -65,11 +65,15 @@ class ListManager {
65
65
  this.listsByField.get(parentID).get(list.key).push(handler);
66
66
  }
67
67
  removeIDFromAllLists(id, layer) {
68
+ let removed = false;
68
69
  for (const fieldMap of this.lists.values()) {
69
70
  for (const list of fieldMap.values()) {
70
- list.removeID(id, void 0, layer);
71
+ if (list.removeID(id, void 0, layer)) {
72
+ removed = true;
73
+ }
71
74
  }
72
75
  }
76
+ return removed;
73
77
  }
74
78
  deleteField(parentID, field) {
75
79
  if (!this.listsByField.get(parentID)?.has(field)) {
@@ -372,7 +376,13 @@ class ListCollection {
372
376
  this.lists.forEach((list) => list.addToList(...args));
373
377
  }
374
378
  removeID(...args) {
375
- this.lists.forEach((list) => list.removeID(...args));
379
+ let removed = false;
380
+ this.lists.forEach((list) => {
381
+ if (list.removeID(...args)) {
382
+ removed = true;
383
+ }
384
+ });
385
+ return removed;
376
386
  }
377
387
  remove(...args) {
378
388
  this.lists.forEach((list) => list.remove(...args));
@@ -3,15 +3,15 @@ export declare class InMemoryStorage {
3
3
  data: Layer[];
4
4
  private idCount;
5
5
  private rank;
6
- private idMaps;
6
+ idMaps: Record<string, string>;
7
7
  constructor();
8
8
  get layerCount(): number;
9
9
  get nextRank(): number;
10
- registerIDMapping(from: string | number, to: string | number): void;
10
+ registerIDMapping(from: string, to: string): void;
11
11
  createLayer(optimistic?: boolean): Layer;
12
12
  insert(id: string, field: string, location: OperationLocations, target: string): void;
13
- remove(id: string, field: string, target: string, layerToUser?: Layer): void;
14
- delete(id: string, layerToUser?: Layer): void;
13
+ remove(id: string, field: string, target: string, layer?: Layer): void;
14
+ delete(id: string, layer?: Layer): void;
15
15
  deleteField(id: string, field: string): void;
16
16
  getLayer(id: number): Layer;
17
17
  replaceID(replacement: {
@@ -15,6 +15,7 @@ class InMemoryStorage {
15
15
  }
16
16
  registerIDMapping(from, to) {
17
17
  this.idMaps[from] = to;
18
+ this.idMaps[to] = from;
18
19
  }
19
20
  createLayer(optimistic = false) {
20
21
  const layer = new Layer(this.idCount++);
@@ -25,11 +26,11 @@ class InMemoryStorage {
25
26
  insert(id, field, location, target) {
26
27
  return this.topLayer.insert(id, field, location, target);
27
28
  }
28
- remove(id, field, target, layerToUser = this.topLayer) {
29
- return layerToUser.remove(id, field, target);
29
+ remove(id, field, target, layer = this.topLayer) {
30
+ return layer.remove(id, field, target);
30
31
  }
31
- delete(id, layerToUser = this.topLayer) {
32
- return layerToUser.delete(id);
32
+ delete(id, layer = this.topLayer) {
33
+ return layer.delete(id);
33
34
  }
34
35
  deleteField(id, field) {
35
36
  return this.topLayer.deleteField(id, field);
@@ -67,6 +68,9 @@ class InMemoryStorage {
67
68
  return;
68
69
  }
69
70
  operations.remove.add(v);
71
+ if (this.idMaps[v]) {
72
+ operations.remove.add(this.idMaps[v]);
73
+ }
70
74
  });
71
75
  if (typeof layerValue === "undefined" && defaultValue) {
72
76
  const targetLayer = this.topLayer;
@@ -93,7 +97,11 @@ class InMemoryStorage {
93
97
  operations.remove.add(op.id);
94
98
  }
95
99
  if (isInsertOperation(op)) {
96
- operations.insert[op.location].unshift(op.id);
100
+ if (op.location === OperationLocation.end) {
101
+ operations.insert[op.location].unshift(op.id);
102
+ } else {
103
+ operations.insert[op.location].push(op.id);
104
+ }
97
105
  }
98
106
  if (isDeleteOperation(op)) {
99
107
  return {
@@ -339,7 +347,7 @@ class Layer {
339
347
  }
340
348
  for (const [id, ops] of Object.entries(layer.operations)) {
341
349
  const fields = {};
342
- for (const opMap of [this.operations[id], layer.operations[id]].filter(Boolean)) {
350
+ for (const opMap of [layer.operations[id], this.operations[id]].filter(Boolean)) {
343
351
  for (const [fieldName, operations] of Object.entries(opMap.fields || {})) {
344
352
  fields[fieldName] = [...fields[fieldName] || [], ...operations];
345
353
  }
@@ -1 +1,2 @@
1
1
  export declare function evaluateKey(key: string, variables?: Record<string, any> | null): string;
2
+ export declare const rootID = "_ROOT_";
@@ -24,6 +24,8 @@ function evaluateKey(key, variables = null) {
24
24
  return evaluated;
25
25
  }
26
26
  const varChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789";
27
+ const rootID = "_ROOT_";
27
28
  export {
28
- evaluateKey
29
+ evaluateKey,
30
+ rootID
29
31
  };
@@ -10,6 +10,7 @@ export declare class InMemorySubscriptions {
10
10
  private subscribers;
11
11
  private keyVersions;
12
12
  activeFields(parent: string): string[];
13
+ copySubscribers(from: string, to: string): void;
13
14
  add({ parent, spec, selection, variables, parentType, }: {
14
15
  parent: string;
15
16
  parentType?: string;
@@ -41,9 +42,11 @@ export declare class InMemorySubscriptions {
41
42
  parentType: string;
42
43
  }): void;
43
44
  get(id: string, field: string): FieldSelection[];
45
+ getAll(id: string): FieldSelection[];
44
46
  remove(id: string, selection: SubscriptionSelection, targets: SubscriptionSpec[], variables: {}, visited?: string[]): void;
45
47
  reset(): SubscriptionSpec[];
46
48
  private removeSubscribers;
47
- removeAllSubscribers(id: string, targets?: SubscriptionSpec[], visited?: string[]): void;
49
+ removeAllSubscribers(id: string, targets?: SubscriptionSpec[]): void;
48
50
  get size(): number;
51
+ findSubSelections(parentID: string, selection: SubscriptionSelection, variables: {}, searchTarget: string, selections?: SubscriptionSelection[]): Array<SubscriptionSelection>;
49
52
  }