houdini 1.2.53 → 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
@@ -1,7 +1,6 @@
1
1
  import { flatten } from "../lib/flatten";
2
2
  import { getFieldsForType } from "../lib/selection";
3
- import { rootID } from "./cache";
4
- import { evaluateKey } from "./stuff";
3
+ import { evaluateKey, rootID } from "./stuff";
5
4
  class InMemorySubscriptions {
6
5
  cache;
7
6
  constructor(cache) {
@@ -12,6 +11,9 @@ class InMemorySubscriptions {
12
11
  activeFields(parent) {
13
12
  return Object.keys(this.subscribers.get(parent) || {});
14
13
  }
14
+ copySubscribers(from, to) {
15
+ this.subscribers.set(to, this.subscribers.get(from) || /* @__PURE__ */ new Map());
16
+ }
15
17
  add({
16
18
  parent,
17
19
  spec,
@@ -194,6 +196,11 @@ class InMemorySubscriptions {
194
196
  get(id, field) {
195
197
  return this.subscribers.get(id)?.get(field)?.selections || [];
196
198
  }
199
+ getAll(id) {
200
+ return [...this.subscribers.get(id)?.values() || []].flatMap(
201
+ (fieldSub) => fieldSub.selections
202
+ );
203
+ }
197
204
  remove(id, selection, targets, variables, visited = []) {
198
205
  visited.push(id);
199
206
  const linkedIDs = [];
@@ -235,7 +242,7 @@ class InMemorySubscriptions {
235
242
  }
236
243
  const subscriberField = subscriber.get(fieldName);
237
244
  for (const spec of specs) {
238
- const counts = subscriber.get(fieldName)?.referenceCounts;
245
+ const counts = subscriberField?.referenceCounts;
239
246
  if (!counts?.has(spec.set)) {
240
247
  continue;
241
248
  }
@@ -258,24 +265,23 @@ class InMemorySubscriptions {
258
265
  this.subscribers.delete(id);
259
266
  }
260
267
  }
261
- removeAllSubscribers(id, targets, visited = []) {
262
- visited.push(id);
263
- const subscriber = this.subscribers.get(id);
264
- for (const [key, val] of subscriber?.entries() ?? []) {
265
- const subscribers = targets || val.selections.map(([spec]) => spec);
266
- this.removeSubscribers(id, key, subscribers);
267
- const { value, kind } = this.cache._internal_unstable.storage.get(id, key);
268
- if (kind === "scalar") {
269
- continue;
270
- }
271
- const nextTargets = Array.isArray(value) ? flatten(value) : [value];
272
- for (const id2 of nextTargets) {
273
- if (visited.includes(id2)) {
274
- continue;
275
- }
276
- this.removeAllSubscribers(id2, subscribers, visited);
268
+ removeAllSubscribers(id, targets) {
269
+ if (!targets) {
270
+ targets = [...this.subscribers.get(id)?.values() || []].flatMap(
271
+ (spec) => spec.selections.flatMap((sel) => sel[0])
272
+ );
273
+ }
274
+ for (const target of targets) {
275
+ for (const subselection of this.findSubSelections(
276
+ target.parentID || rootID,
277
+ target.selection,
278
+ target.variables || {},
279
+ id
280
+ )) {
281
+ this.remove(id, subselection, targets, target.variables || {});
277
282
  }
278
283
  }
284
+ return;
279
285
  }
280
286
  get size() {
281
287
  let size = 0;
@@ -286,6 +292,32 @@ class InMemorySubscriptions {
286
292
  }
287
293
  return size;
288
294
  }
295
+ findSubSelections(parentID, selection, variables, searchTarget, selections = []) {
296
+ const __typename = this.cache._internal_unstable.storage.get(parentID, "__typename").value;
297
+ let targetSelection = getFieldsForType(selection, __typename, false);
298
+ for (const fieldSelection of Object.values(targetSelection || {})) {
299
+ if (!fieldSelection.selection) {
300
+ continue;
301
+ }
302
+ const key = evaluateKey(fieldSelection.keyRaw, variables || {});
303
+ const linkedRecord = this.cache._internal_unstable.storage.get(parentID, key);
304
+ const links = !Array.isArray(linkedRecord.value) ? [linkedRecord.value] : flatten(linkedRecord.value);
305
+ if (links.includes(searchTarget)) {
306
+ selections.push(fieldSelection.selection);
307
+ } else {
308
+ for (const link of links) {
309
+ this.findSubSelections(
310
+ link,
311
+ fieldSelection.selection,
312
+ variables,
313
+ searchTarget,
314
+ selections
315
+ );
316
+ }
317
+ }
318
+ }
319
+ return selections;
320
+ }
289
321
  }
290
322
  export {
291
323
  InMemorySubscriptions
@@ -64,7 +64,9 @@ const optimisticKeys = (cache, callbackCache = callbacks, keyCache = keys, objec
64
64
  });
65
65
  delete callbackCache[optimisticValue];
66
66
  },
67
- onIDChange: (optimisticValue, realValue) => cache.registerKeyMap(optimisticValue, realValue)
67
+ onIDChange: (optimisticValue, realValue) => {
68
+ cache.registerKeyMap(optimisticValue, realValue);
69
+ }
68
70
  }
69
71
  );
70
72
  }
@@ -1,4 +1,4 @@
1
- import { rootID } from "../cache/cache";
1
+ import { rootID } from "../cache/stuff";
2
2
  import { marshalInputs } from "../lib";
3
3
  import { keyFieldsForType } from "../lib/config";
4
4
  class Record {
@@ -54523,6 +54523,35 @@ var GarbageCollector = class {
54523
54523
  }
54524
54524
  };
54525
54525
 
54526
+ // src/runtime/cache/stuff.ts
54527
+ function evaluateKey(key, variables = null) {
54528
+ let evaluated = "";
54529
+ let varName = "";
54530
+ let inString = false;
54531
+ for (const char of key) {
54532
+ if (varName) {
54533
+ if (varChars.includes(char)) {
54534
+ varName += char;
54535
+ continue;
54536
+ }
54537
+ const value = variables?.[varName.slice(1)];
54538
+ evaluated += typeof value !== "undefined" ? JSON.stringify(value) : "undefined";
54539
+ varName = "";
54540
+ }
54541
+ if (char === "$" && !inString) {
54542
+ varName = "$";
54543
+ continue;
54544
+ }
54545
+ if (char === '"') {
54546
+ inString = !inString;
54547
+ }
54548
+ evaluated += char;
54549
+ }
54550
+ return evaluated;
54551
+ }
54552
+ var varChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789";
54553
+ var rootID = "_ROOT_";
54554
+
54526
54555
  // src/runtime/cache/lists.ts
54527
54556
  var ListManager = class {
54528
54557
  rootID;
@@ -54589,11 +54618,15 @@ var ListManager = class {
54589
54618
  this.listsByField.get(parentID).get(list.key).push(handler);
54590
54619
  }
54591
54620
  removeIDFromAllLists(id, layer) {
54621
+ let removed = false;
54592
54622
  for (const fieldMap of this.lists.values()) {
54593
54623
  for (const list of fieldMap.values()) {
54594
- list.removeID(id, void 0, layer);
54624
+ if (list.removeID(id, void 0, layer)) {
54625
+ removed = true;
54626
+ }
54595
54627
  }
54596
54628
  }
54629
+ return removed;
54597
54630
  }
54598
54631
  deleteField(parentID, field) {
54599
54632
  if (!this.listsByField.get(parentID)?.has(field)) {
@@ -54896,7 +54929,13 @@ var ListCollection = class {
54896
54929
  this.lists.forEach((list) => list.addToList(...args));
54897
54930
  }
54898
54931
  removeID(...args) {
54899
- this.lists.forEach((list) => list.removeID(...args));
54932
+ let removed = false;
54933
+ this.lists.forEach((list) => {
54934
+ if (list.removeID(...args)) {
54935
+ removed = true;
54936
+ }
54937
+ });
54938
+ return removed;
54900
54939
  }
54901
54940
  remove(...args) {
54902
54941
  this.lists.forEach((list) => list.remove(...args));
@@ -55015,6 +55054,7 @@ var InMemoryStorage = class {
55015
55054
  }
55016
55055
  registerIDMapping(from, to) {
55017
55056
  this.idMaps[from] = to;
55057
+ this.idMaps[to] = from;
55018
55058
  }
55019
55059
  createLayer(optimistic = false) {
55020
55060
  const layer = new Layer(this.idCount++);
@@ -55025,11 +55065,11 @@ var InMemoryStorage = class {
55025
55065
  insert(id, field, location, target) {
55026
55066
  return this.topLayer.insert(id, field, location, target);
55027
55067
  }
55028
- remove(id, field, target, layerToUser = this.topLayer) {
55029
- return layerToUser.remove(id, field, target);
55068
+ remove(id, field, target, layer = this.topLayer) {
55069
+ return layer.remove(id, field, target);
55030
55070
  }
55031
- delete(id, layerToUser = this.topLayer) {
55032
- return layerToUser.delete(id);
55071
+ delete(id, layer = this.topLayer) {
55072
+ return layer.delete(id);
55033
55073
  }
55034
55074
  deleteField(id, field) {
55035
55075
  return this.topLayer.deleteField(id, field);
@@ -55067,6 +55107,9 @@ var InMemoryStorage = class {
55067
55107
  return;
55068
55108
  }
55069
55109
  operations.remove.add(v);
55110
+ if (this.idMaps[v]) {
55111
+ operations.remove.add(this.idMaps[v]);
55112
+ }
55070
55113
  });
55071
55114
  if (typeof layerValue === "undefined" && defaultValue) {
55072
55115
  const targetLayer = this.topLayer;
@@ -55093,7 +55136,11 @@ var InMemoryStorage = class {
55093
55136
  operations.remove.add(op.id);
55094
55137
  }
55095
55138
  if (isInsertOperation(op)) {
55096
- operations.insert[op.location].unshift(op.id);
55139
+ if (op.location === OperationLocation.end) {
55140
+ operations.insert[op.location].unshift(op.id);
55141
+ } else {
55142
+ operations.insert[op.location].push(op.id);
55143
+ }
55097
55144
  }
55098
55145
  if (isDeleteOperation(op)) {
55099
55146
  return {
@@ -55339,7 +55386,7 @@ var Layer = class {
55339
55386
  }
55340
55387
  for (const [id, ops] of Object.entries(layer.operations)) {
55341
55388
  const fields = {};
55342
- for (const opMap of [this.operations[id], layer.operations[id]].filter(Boolean)) {
55389
+ for (const opMap of [layer.operations[id], this.operations[id]].filter(Boolean)) {
55343
55390
  for (const [fieldName, operations] of Object.entries(opMap.fields || {})) {
55344
55391
  fields[fieldName] = [...fields[fieldName] || [], ...operations];
55345
55392
  }
@@ -55404,34 +55451,6 @@ var OperationKind = {
55404
55451
  remove: "remove"
55405
55452
  };
55406
55453
 
55407
- // src/runtime/cache/stuff.ts
55408
- function evaluateKey(key, variables = null) {
55409
- let evaluated = "";
55410
- let varName = "";
55411
- let inString = false;
55412
- for (const char of key) {
55413
- if (varName) {
55414
- if (varChars.includes(char)) {
55415
- varName += char;
55416
- continue;
55417
- }
55418
- const value = variables?.[varName.slice(1)];
55419
- evaluated += typeof value !== "undefined" ? JSON.stringify(value) : "undefined";
55420
- varName = "";
55421
- }
55422
- if (char === "$" && !inString) {
55423
- varName = "$";
55424
- continue;
55425
- }
55426
- if (char === '"') {
55427
- inString = !inString;
55428
- }
55429
- evaluated += char;
55430
- }
55431
- return evaluated;
55432
- }
55433
- var varChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789";
55434
-
55435
55454
  // src/runtime/cache/subscription.ts
55436
55455
  var InMemorySubscriptions = class {
55437
55456
  cache;
@@ -55443,6 +55462,9 @@ var InMemorySubscriptions = class {
55443
55462
  activeFields(parent2) {
55444
55463
  return Object.keys(this.subscribers.get(parent2) || {});
55445
55464
  }
55465
+ copySubscribers(from, to) {
55466
+ this.subscribers.set(to, this.subscribers.get(from) || /* @__PURE__ */ new Map());
55467
+ }
55446
55468
  add({
55447
55469
  parent: parent2,
55448
55470
  spec,
@@ -55625,6 +55647,11 @@ var InMemorySubscriptions = class {
55625
55647
  get(id, field) {
55626
55648
  return this.subscribers.get(id)?.get(field)?.selections || [];
55627
55649
  }
55650
+ getAll(id) {
55651
+ return [...this.subscribers.get(id)?.values() || []].flatMap(
55652
+ (fieldSub) => fieldSub.selections
55653
+ );
55654
+ }
55628
55655
  remove(id, selection, targets, variables, visited = []) {
55629
55656
  visited.push(id);
55630
55657
  const linkedIDs = [];
@@ -55666,7 +55693,7 @@ var InMemorySubscriptions = class {
55666
55693
  }
55667
55694
  const subscriberField = subscriber.get(fieldName);
55668
55695
  for (const spec of specs) {
55669
- const counts = subscriber.get(fieldName)?.referenceCounts;
55696
+ const counts = subscriberField?.referenceCounts;
55670
55697
  if (!counts?.has(spec.set)) {
55671
55698
  continue;
55672
55699
  }
@@ -55689,24 +55716,23 @@ var InMemorySubscriptions = class {
55689
55716
  this.subscribers.delete(id);
55690
55717
  }
55691
55718
  }
55692
- removeAllSubscribers(id, targets, visited = []) {
55693
- visited.push(id);
55694
- const subscriber = this.subscribers.get(id);
55695
- for (const [key, val] of subscriber?.entries() ?? []) {
55696
- const subscribers = targets || val.selections.map(([spec]) => spec);
55697
- this.removeSubscribers(id, key, subscribers);
55698
- const { value, kind } = this.cache._internal_unstable.storage.get(id, key);
55699
- if (kind === "scalar") {
55700
- continue;
55701
- }
55702
- const nextTargets = Array.isArray(value) ? flatten(value) : [value];
55703
- for (const id2 of nextTargets) {
55704
- if (visited.includes(id2)) {
55705
- continue;
55706
- }
55707
- this.removeAllSubscribers(id2, subscribers, visited);
55719
+ removeAllSubscribers(id, targets) {
55720
+ if (!targets) {
55721
+ targets = [...this.subscribers.get(id)?.values() || []].flatMap(
55722
+ (spec) => spec.selections.flatMap((sel) => sel[0])
55723
+ );
55724
+ }
55725
+ for (const target of targets) {
55726
+ for (const subselection of this.findSubSelections(
55727
+ target.parentID || rootID,
55728
+ target.selection,
55729
+ target.variables || {},
55730
+ id
55731
+ )) {
55732
+ this.remove(id, subselection, targets, target.variables || {});
55708
55733
  }
55709
55734
  }
55735
+ return;
55710
55736
  }
55711
55737
  get size() {
55712
55738
  let size = 0;
@@ -55717,6 +55743,32 @@ var InMemorySubscriptions = class {
55717
55743
  }
55718
55744
  return size;
55719
55745
  }
55746
+ findSubSelections(parentID, selection, variables, searchTarget, selections = []) {
55747
+ const __typename = this.cache._internal_unstable.storage.get(parentID, "__typename").value;
55748
+ let targetSelection = getFieldsForType(selection, __typename, false);
55749
+ for (const fieldSelection of Object.values(targetSelection || {})) {
55750
+ if (!fieldSelection.selection) {
55751
+ continue;
55752
+ }
55753
+ const key = evaluateKey(fieldSelection.keyRaw, variables || {});
55754
+ const linkedRecord = this.cache._internal_unstable.storage.get(parentID, key);
55755
+ const links = !Array.isArray(linkedRecord.value) ? [linkedRecord.value] : flatten(linkedRecord.value);
55756
+ if (links.includes(searchTarget)) {
55757
+ selections.push(fieldSelection.selection);
55758
+ } else {
55759
+ for (const link of links) {
55760
+ this.findSubSelections(
55761
+ link,
55762
+ fieldSelection.selection,
55763
+ variables,
55764
+ searchTarget,
55765
+ selections
55766
+ );
55767
+ }
55768
+ }
55769
+ }
55770
+ return selections;
55771
+ }
55720
55772
  };
55721
55773
 
55722
55774
  // src/runtime/cache/cache.ts
@@ -55794,11 +55846,17 @@ var Cache = class {
55794
55846
  }
55795
55847
  registerKeyMap(source, mapped) {
55796
55848
  this._internal_unstable.storage.registerIDMapping(source, mapped);
55849
+ this._internal_unstable.subscriptions.copySubscribers(source, mapped);
55797
55850
  }
55798
55851
  delete(id, layer) {
55799
- this._internal_unstable.subscriptions.removeAllSubscribers(id);
55800
- this._internal_unstable.lists.removeIDFromAllLists(id, layer);
55801
- this._internal_unstable.storage.delete(id, layer);
55852
+ const recordIDs = [this._internal_unstable.storage.idMaps[id], id].filter(
55853
+ Boolean
55854
+ );
55855
+ for (const recordID of recordIDs) {
55856
+ this._internal_unstable.subscriptions.removeAllSubscribers(recordID);
55857
+ this._internal_unstable.lists.removeIDFromAllLists(recordID, layer);
55858
+ this._internal_unstable.storage.delete(recordID, layer);
55859
+ }
55802
55860
  }
55803
55861
  setConfig(config) {
55804
55862
  this._internal_unstable.setConfig(config);
@@ -56104,6 +56162,9 @@ var CacheInternal = class {
56104
56162
  layer,
56105
56163
  forceNotify
56106
56164
  });
56165
+ let action = () => {
56166
+ layer.writeLink(parent2, key, linkedIDs);
56167
+ };
56107
56168
  if (applyUpdates && updates) {
56108
56169
  if (key === "edges") {
56109
56170
  const newNodeIDs = [];
@@ -56138,8 +56199,26 @@ var CacheInternal = class {
56138
56199
  }
56139
56200
  if (update === "prepend") {
56140
56201
  linkedIDs = newIDs.concat(oldIDs);
56202
+ if (layer?.optimistic) {
56203
+ action = () => {
56204
+ for (const id of newIDs) {
56205
+ if (id) {
56206
+ layer.insert(parent2, key, "start", id);
56207
+ }
56208
+ }
56209
+ };
56210
+ }
56141
56211
  } else if (update === "append") {
56142
56212
  linkedIDs = oldIDs.concat(newIDs);
56213
+ if (layer?.optimistic) {
56214
+ action = () => {
56215
+ for (const id of newIDs) {
56216
+ if (id) {
56217
+ layer.insert(parent2, key, "end", id);
56218
+ }
56219
+ }
56220
+ };
56221
+ }
56143
56222
  } else if (update === "replace") {
56144
56223
  linkedIDs = newIDs;
56145
56224
  }
@@ -56158,7 +56237,7 @@ var CacheInternal = class {
56158
56237
  this.subscriptions.remove(lostID, fieldSelection, specs, variables);
56159
56238
  }
56160
56239
  if (contentChanged || oldIDs.length === 0 && newIDs.length === 0) {
56161
- layer.writeLink(parent2, key, linkedIDs);
56240
+ action();
56162
56241
  }
56163
56242
  for (const id of newIDs.filter((id2) => !oldIDs.includes(id2))) {
56164
56243
  if (id == null) {
@@ -56213,6 +56292,9 @@ var CacheInternal = class {
56213
56292
  if (!targetID) {
56214
56293
  continue;
56215
56294
  }
56295
+ toNotify.push(
56296
+ ...this.subscriptions.getAll(targetID).filter((sub) => sub[0].parentID !== targetID)
56297
+ );
56216
56298
  this.cache.delete(targetID, layer);
56217
56299
  }
56218
56300
  }
@@ -56634,7 +56716,6 @@ function variableValue(value, args) {
56634
56716
  );
56635
56717
  }
56636
56718
  }
56637
- var rootID = "_ROOT_";
56638
56719
  function defaultComponentField({
56639
56720
  cache,
56640
56721
  component,