houdini 1.2.54 → 1.2.56

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 +142 -60
  2. package/build/cmd-esm/index.js +142 -60
  3. package/build/codegen-cjs/index.js +140 -58
  4. package/build/codegen-esm/index.js +140 -58
  5. package/build/lib-cjs/index.js +143 -59
  6. package/build/lib-esm/index.js +143 -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 +15 -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 +15 -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 +140 -58
  42. package/build/test-esm/index.js +140 -58
  43. package/build/vite-cjs/index.js +140 -58
  44. package/build/vite-esm/index.js +140 -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
  }
@@ -55379,6 +55426,7 @@ var Layer = class {
55379
55426
  [id]: {
55380
55427
  ...this.operations[id],
55381
55428
  fields: {
55429
+ ...this.operations[id]?.fields,
55382
55430
  [field]: [...this.operations[id]?.fields[field] || [], operation]
55383
55431
  }
55384
55432
  }
@@ -55404,34 +55452,6 @@ var OperationKind = {
55404
55452
  remove: "remove"
55405
55453
  };
55406
55454
 
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
55455
  // src/runtime/cache/subscription.ts
55436
55456
  var InMemorySubscriptions = class {
55437
55457
  cache;
@@ -55443,6 +55463,9 @@ var InMemorySubscriptions = class {
55443
55463
  activeFields(parent2) {
55444
55464
  return Object.keys(this.subscribers.get(parent2) || {});
55445
55465
  }
55466
+ copySubscribers(from, to) {
55467
+ this.subscribers.set(to, this.subscribers.get(from) || /* @__PURE__ */ new Map());
55468
+ }
55446
55469
  add({
55447
55470
  parent: parent2,
55448
55471
  spec,
@@ -55625,6 +55648,11 @@ var InMemorySubscriptions = class {
55625
55648
  get(id, field) {
55626
55649
  return this.subscribers.get(id)?.get(field)?.selections || [];
55627
55650
  }
55651
+ getAll(id) {
55652
+ return [...this.subscribers.get(id)?.values() || []].flatMap(
55653
+ (fieldSub) => fieldSub.selections
55654
+ );
55655
+ }
55628
55656
  remove(id, selection, targets, variables, visited = []) {
55629
55657
  visited.push(id);
55630
55658
  const linkedIDs = [];
@@ -55666,7 +55694,7 @@ var InMemorySubscriptions = class {
55666
55694
  }
55667
55695
  const subscriberField = subscriber.get(fieldName);
55668
55696
  for (const spec of specs) {
55669
- const counts = subscriber.get(fieldName)?.referenceCounts;
55697
+ const counts = subscriberField?.referenceCounts;
55670
55698
  if (!counts?.has(spec.set)) {
55671
55699
  continue;
55672
55700
  }
@@ -55689,24 +55717,23 @@ var InMemorySubscriptions = class {
55689
55717
  this.subscribers.delete(id);
55690
55718
  }
55691
55719
  }
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);
55720
+ removeAllSubscribers(id, targets) {
55721
+ if (!targets) {
55722
+ targets = [...this.subscribers.get(id)?.values() || []].flatMap(
55723
+ (spec) => spec.selections.flatMap((sel) => sel[0])
55724
+ );
55725
+ }
55726
+ for (const target of targets) {
55727
+ for (const subselection of this.findSubSelections(
55728
+ target.parentID || rootID,
55729
+ target.selection,
55730
+ target.variables || {},
55731
+ id
55732
+ )) {
55733
+ this.remove(id, subselection, targets, target.variables || {});
55708
55734
  }
55709
55735
  }
55736
+ return;
55710
55737
  }
55711
55738
  get size() {
55712
55739
  let size = 0;
@@ -55717,6 +55744,32 @@ var InMemorySubscriptions = class {
55717
55744
  }
55718
55745
  return size;
55719
55746
  }
55747
+ findSubSelections(parentID, selection, variables, searchTarget, selections = []) {
55748
+ const __typename = this.cache._internal_unstable.storage.get(parentID, "__typename").value;
55749
+ let targetSelection = getFieldsForType(selection, __typename, false);
55750
+ for (const fieldSelection of Object.values(targetSelection || {})) {
55751
+ if (!fieldSelection.selection) {
55752
+ continue;
55753
+ }
55754
+ const key = evaluateKey(fieldSelection.keyRaw, variables || {});
55755
+ const linkedRecord = this.cache._internal_unstable.storage.get(parentID, key);
55756
+ const links = !Array.isArray(linkedRecord.value) ? [linkedRecord.value] : flatten(linkedRecord.value);
55757
+ if (links.includes(searchTarget)) {
55758
+ selections.push(fieldSelection.selection);
55759
+ } else {
55760
+ for (const link of links) {
55761
+ this.findSubSelections(
55762
+ link,
55763
+ fieldSelection.selection,
55764
+ variables,
55765
+ searchTarget,
55766
+ selections
55767
+ );
55768
+ }
55769
+ }
55770
+ }
55771
+ return selections;
55772
+ }
55720
55773
  };
55721
55774
 
55722
55775
  // src/runtime/cache/cache.ts
@@ -55794,11 +55847,17 @@ var Cache = class {
55794
55847
  }
55795
55848
  registerKeyMap(source, mapped) {
55796
55849
  this._internal_unstable.storage.registerIDMapping(source, mapped);
55850
+ this._internal_unstable.subscriptions.copySubscribers(source, mapped);
55797
55851
  }
55798
55852
  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);
55853
+ const recordIDs = [this._internal_unstable.storage.idMaps[id], id].filter(
55854
+ Boolean
55855
+ );
55856
+ for (const recordID of recordIDs) {
55857
+ this._internal_unstable.subscriptions.removeAllSubscribers(recordID);
55858
+ this._internal_unstable.lists.removeIDFromAllLists(recordID, layer);
55859
+ this._internal_unstable.storage.delete(recordID, layer);
55860
+ }
55802
55861
  }
55803
55862
  setConfig(config) {
55804
55863
  this._internal_unstable.setConfig(config);
@@ -56104,6 +56163,9 @@ var CacheInternal = class {
56104
56163
  layer,
56105
56164
  forceNotify
56106
56165
  });
56166
+ let action = () => {
56167
+ layer.writeLink(parent2, key, linkedIDs);
56168
+ };
56107
56169
  if (applyUpdates && updates) {
56108
56170
  if (key === "edges") {
56109
56171
  const newNodeIDs = [];
@@ -56138,8 +56200,26 @@ var CacheInternal = class {
56138
56200
  }
56139
56201
  if (update === "prepend") {
56140
56202
  linkedIDs = newIDs.concat(oldIDs);
56203
+ if (layer?.optimistic) {
56204
+ action = () => {
56205
+ for (const id of newIDs) {
56206
+ if (id) {
56207
+ layer.insert(parent2, key, "start", id);
56208
+ }
56209
+ }
56210
+ };
56211
+ }
56141
56212
  } else if (update === "append") {
56142
56213
  linkedIDs = oldIDs.concat(newIDs);
56214
+ if (layer?.optimistic) {
56215
+ action = () => {
56216
+ for (const id of newIDs) {
56217
+ if (id) {
56218
+ layer.insert(parent2, key, "end", id);
56219
+ }
56220
+ }
56221
+ };
56222
+ }
56143
56223
  } else if (update === "replace") {
56144
56224
  linkedIDs = newIDs;
56145
56225
  }
@@ -56158,7 +56238,7 @@ var CacheInternal = class {
56158
56238
  this.subscriptions.remove(lostID, fieldSelection, specs, variables);
56159
56239
  }
56160
56240
  if (contentChanged || oldIDs.length === 0 && newIDs.length === 0) {
56161
- layer.writeLink(parent2, key, linkedIDs);
56241
+ action();
56162
56242
  }
56163
56243
  for (const id of newIDs.filter((id2) => !oldIDs.includes(id2))) {
56164
56244
  if (id == null) {
@@ -56213,6 +56293,9 @@ var CacheInternal = class {
56213
56293
  if (!targetID) {
56214
56294
  continue;
56215
56295
  }
56296
+ toNotify.push(
56297
+ ...this.subscriptions.getAll(targetID).filter((sub) => sub[0].parentID !== targetID)
56298
+ );
56216
56299
  this.cache.delete(targetID, layer);
56217
56300
  }
56218
56301
  }
@@ -56634,7 +56717,6 @@ function variableValue(value, args) {
56634
56717
  );
56635
56718
  }
56636
56719
  }
56637
- var rootID = "_ROOT_";
56638
56720
  function defaultComponentField({
56639
56721
  cache,
56640
56722
  component,