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
@@ -65292,6 +65292,35 @@ var GarbageCollector = class {
65292
65292
  }
65293
65293
  };
65294
65294
 
65295
+ // src/runtime/cache/stuff.ts
65296
+ function evaluateKey(key, variables = null) {
65297
+ let evaluated = "";
65298
+ let varName = "";
65299
+ let inString = false;
65300
+ for (const char of key) {
65301
+ if (varName) {
65302
+ if (varChars.includes(char)) {
65303
+ varName += char;
65304
+ continue;
65305
+ }
65306
+ const value = variables?.[varName.slice(1)];
65307
+ evaluated += typeof value !== "undefined" ? JSON.stringify(value) : "undefined";
65308
+ varName = "";
65309
+ }
65310
+ if (char === "$" && !inString) {
65311
+ varName = "$";
65312
+ continue;
65313
+ }
65314
+ if (char === '"') {
65315
+ inString = !inString;
65316
+ }
65317
+ evaluated += char;
65318
+ }
65319
+ return evaluated;
65320
+ }
65321
+ var varChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789";
65322
+ var rootID = "_ROOT_";
65323
+
65295
65324
  // src/runtime/cache/lists.ts
65296
65325
  var ListManager = class {
65297
65326
  rootID;
@@ -65358,11 +65387,15 @@ var ListManager = class {
65358
65387
  this.listsByField.get(parentID).get(list.key).push(handler);
65359
65388
  }
65360
65389
  removeIDFromAllLists(id, layer) {
65390
+ let removed = false;
65361
65391
  for (const fieldMap of this.lists.values()) {
65362
65392
  for (const list of fieldMap.values()) {
65363
- list.removeID(id, void 0, layer);
65393
+ if (list.removeID(id, void 0, layer)) {
65394
+ removed = true;
65395
+ }
65364
65396
  }
65365
65397
  }
65398
+ return removed;
65366
65399
  }
65367
65400
  deleteField(parentID, field) {
65368
65401
  if (!this.listsByField.get(parentID)?.has(field)) {
@@ -65665,7 +65698,13 @@ var ListCollection = class {
65665
65698
  this.lists.forEach((list) => list.addToList(...args));
65666
65699
  }
65667
65700
  removeID(...args) {
65668
- this.lists.forEach((list) => list.removeID(...args));
65701
+ let removed = false;
65702
+ this.lists.forEach((list) => {
65703
+ if (list.removeID(...args)) {
65704
+ removed = true;
65705
+ }
65706
+ });
65707
+ return removed;
65669
65708
  }
65670
65709
  remove(...args) {
65671
65710
  this.lists.forEach((list) => list.remove(...args));
@@ -65784,6 +65823,7 @@ var InMemoryStorage = class {
65784
65823
  }
65785
65824
  registerIDMapping(from, to) {
65786
65825
  this.idMaps[from] = to;
65826
+ this.idMaps[to] = from;
65787
65827
  }
65788
65828
  createLayer(optimistic = false) {
65789
65829
  const layer = new Layer(this.idCount++);
@@ -65794,11 +65834,11 @@ var InMemoryStorage = class {
65794
65834
  insert(id, field, location, target) {
65795
65835
  return this.topLayer.insert(id, field, location, target);
65796
65836
  }
65797
- remove(id, field, target, layerToUser = this.topLayer) {
65798
- return layerToUser.remove(id, field, target);
65837
+ remove(id, field, target, layer = this.topLayer) {
65838
+ return layer.remove(id, field, target);
65799
65839
  }
65800
- delete(id, layerToUser = this.topLayer) {
65801
- return layerToUser.delete(id);
65840
+ delete(id, layer = this.topLayer) {
65841
+ return layer.delete(id);
65802
65842
  }
65803
65843
  deleteField(id, field) {
65804
65844
  return this.topLayer.deleteField(id, field);
@@ -65836,6 +65876,9 @@ var InMemoryStorage = class {
65836
65876
  return;
65837
65877
  }
65838
65878
  operations.remove.add(v2);
65879
+ if (this.idMaps[v2]) {
65880
+ operations.remove.add(this.idMaps[v2]);
65881
+ }
65839
65882
  });
65840
65883
  if (typeof layerValue === "undefined" && defaultValue) {
65841
65884
  const targetLayer = this.topLayer;
@@ -65862,7 +65905,11 @@ var InMemoryStorage = class {
65862
65905
  operations.remove.add(op.id);
65863
65906
  }
65864
65907
  if (isInsertOperation(op)) {
65865
- operations.insert[op.location].unshift(op.id);
65908
+ if (op.location === OperationLocation.end) {
65909
+ operations.insert[op.location].unshift(op.id);
65910
+ } else {
65911
+ operations.insert[op.location].push(op.id);
65912
+ }
65866
65913
  }
65867
65914
  if (isDeleteOperation(op)) {
65868
65915
  return {
@@ -66108,7 +66155,7 @@ var Layer = class {
66108
66155
  }
66109
66156
  for (const [id, ops] of Object.entries(layer.operations)) {
66110
66157
  const fields = {};
66111
- for (const opMap of [this.operations[id], layer.operations[id]].filter(Boolean)) {
66158
+ for (const opMap of [layer.operations[id], this.operations[id]].filter(Boolean)) {
66112
66159
  for (const [fieldName, operations] of Object.entries(opMap.fields || {})) {
66113
66160
  fields[fieldName] = [...fields[fieldName] || [], ...operations];
66114
66161
  }
@@ -66173,34 +66220,6 @@ var OperationKind = {
66173
66220
  remove: "remove"
66174
66221
  };
66175
66222
 
66176
- // src/runtime/cache/stuff.ts
66177
- function evaluateKey(key, variables = null) {
66178
- let evaluated = "";
66179
- let varName = "";
66180
- let inString = false;
66181
- for (const char of key) {
66182
- if (varName) {
66183
- if (varChars.includes(char)) {
66184
- varName += char;
66185
- continue;
66186
- }
66187
- const value = variables?.[varName.slice(1)];
66188
- evaluated += typeof value !== "undefined" ? JSON.stringify(value) : "undefined";
66189
- varName = "";
66190
- }
66191
- if (char === "$" && !inString) {
66192
- varName = "$";
66193
- continue;
66194
- }
66195
- if (char === '"') {
66196
- inString = !inString;
66197
- }
66198
- evaluated += char;
66199
- }
66200
- return evaluated;
66201
- }
66202
- var varChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789";
66203
-
66204
66223
  // src/runtime/cache/subscription.ts
66205
66224
  var InMemorySubscriptions = class {
66206
66225
  cache;
@@ -66212,6 +66231,9 @@ var InMemorySubscriptions = class {
66212
66231
  activeFields(parent2) {
66213
66232
  return Object.keys(this.subscribers.get(parent2) || {});
66214
66233
  }
66234
+ copySubscribers(from, to) {
66235
+ this.subscribers.set(to, this.subscribers.get(from) || /* @__PURE__ */ new Map());
66236
+ }
66215
66237
  add({
66216
66238
  parent: parent2,
66217
66239
  spec,
@@ -66394,6 +66416,11 @@ var InMemorySubscriptions = class {
66394
66416
  get(id, field) {
66395
66417
  return this.subscribers.get(id)?.get(field)?.selections || [];
66396
66418
  }
66419
+ getAll(id) {
66420
+ return [...this.subscribers.get(id)?.values() || []].flatMap(
66421
+ (fieldSub) => fieldSub.selections
66422
+ );
66423
+ }
66397
66424
  remove(id, selection, targets, variables, visited = []) {
66398
66425
  visited.push(id);
66399
66426
  const linkedIDs = [];
@@ -66435,7 +66462,7 @@ var InMemorySubscriptions = class {
66435
66462
  }
66436
66463
  const subscriberField = subscriber.get(fieldName);
66437
66464
  for (const spec of specs) {
66438
- const counts = subscriber.get(fieldName)?.referenceCounts;
66465
+ const counts = subscriberField?.referenceCounts;
66439
66466
  if (!counts?.has(spec.set)) {
66440
66467
  continue;
66441
66468
  }
@@ -66458,24 +66485,23 @@ var InMemorySubscriptions = class {
66458
66485
  this.subscribers.delete(id);
66459
66486
  }
66460
66487
  }
66461
- removeAllSubscribers(id, targets, visited = []) {
66462
- visited.push(id);
66463
- const subscriber = this.subscribers.get(id);
66464
- for (const [key, val] of subscriber?.entries() ?? []) {
66465
- const subscribers = targets || val.selections.map(([spec]) => spec);
66466
- this.removeSubscribers(id, key, subscribers);
66467
- const { value, kind } = this.cache._internal_unstable.storage.get(id, key);
66468
- if (kind === "scalar") {
66469
- continue;
66470
- }
66471
- const nextTargets = Array.isArray(value) ? flatten(value) : [value];
66472
- for (const id2 of nextTargets) {
66473
- if (visited.includes(id2)) {
66474
- continue;
66475
- }
66476
- this.removeAllSubscribers(id2, subscribers, visited);
66488
+ removeAllSubscribers(id, targets) {
66489
+ if (!targets) {
66490
+ targets = [...this.subscribers.get(id)?.values() || []].flatMap(
66491
+ (spec) => spec.selections.flatMap((sel) => sel[0])
66492
+ );
66493
+ }
66494
+ for (const target of targets) {
66495
+ for (const subselection of this.findSubSelections(
66496
+ target.parentID || rootID,
66497
+ target.selection,
66498
+ target.variables || {},
66499
+ id
66500
+ )) {
66501
+ this.remove(id, subselection, targets, target.variables || {});
66477
66502
  }
66478
66503
  }
66504
+ return;
66479
66505
  }
66480
66506
  get size() {
66481
66507
  let size = 0;
@@ -66486,6 +66512,32 @@ var InMemorySubscriptions = class {
66486
66512
  }
66487
66513
  return size;
66488
66514
  }
66515
+ findSubSelections(parentID, selection, variables, searchTarget, selections = []) {
66516
+ const __typename = this.cache._internal_unstable.storage.get(parentID, "__typename").value;
66517
+ let targetSelection = getFieldsForType(selection, __typename, false);
66518
+ for (const fieldSelection of Object.values(targetSelection || {})) {
66519
+ if (!fieldSelection.selection) {
66520
+ continue;
66521
+ }
66522
+ const key = evaluateKey(fieldSelection.keyRaw, variables || {});
66523
+ const linkedRecord = this.cache._internal_unstable.storage.get(parentID, key);
66524
+ const links = !Array.isArray(linkedRecord.value) ? [linkedRecord.value] : flatten(linkedRecord.value);
66525
+ if (links.includes(searchTarget)) {
66526
+ selections.push(fieldSelection.selection);
66527
+ } else {
66528
+ for (const link of links) {
66529
+ this.findSubSelections(
66530
+ link,
66531
+ fieldSelection.selection,
66532
+ variables,
66533
+ searchTarget,
66534
+ selections
66535
+ );
66536
+ }
66537
+ }
66538
+ }
66539
+ return selections;
66540
+ }
66489
66541
  };
66490
66542
 
66491
66543
  // src/runtime/cache/cache.ts
@@ -66563,11 +66615,17 @@ var Cache = class {
66563
66615
  }
66564
66616
  registerKeyMap(source, mapped) {
66565
66617
  this._internal_unstable.storage.registerIDMapping(source, mapped);
66618
+ this._internal_unstable.subscriptions.copySubscribers(source, mapped);
66566
66619
  }
66567
66620
  delete(id, layer) {
66568
- this._internal_unstable.subscriptions.removeAllSubscribers(id);
66569
- this._internal_unstable.lists.removeIDFromAllLists(id, layer);
66570
- this._internal_unstable.storage.delete(id, layer);
66621
+ const recordIDs = [this._internal_unstable.storage.idMaps[id], id].filter(
66622
+ Boolean
66623
+ );
66624
+ for (const recordID of recordIDs) {
66625
+ this._internal_unstable.subscriptions.removeAllSubscribers(recordID);
66626
+ this._internal_unstable.lists.removeIDFromAllLists(recordID, layer);
66627
+ this._internal_unstable.storage.delete(recordID, layer);
66628
+ }
66571
66629
  }
66572
66630
  setConfig(config) {
66573
66631
  this._internal_unstable.setConfig(config);
@@ -66873,6 +66931,9 @@ var CacheInternal = class {
66873
66931
  layer,
66874
66932
  forceNotify
66875
66933
  });
66934
+ let action = () => {
66935
+ layer.writeLink(parent2, key, linkedIDs);
66936
+ };
66876
66937
  if (applyUpdates && updates) {
66877
66938
  if (key === "edges") {
66878
66939
  const newNodeIDs = [];
@@ -66907,8 +66968,26 @@ var CacheInternal = class {
66907
66968
  }
66908
66969
  if (update === "prepend") {
66909
66970
  linkedIDs = newIDs.concat(oldIDs);
66971
+ if (layer?.optimistic) {
66972
+ action = () => {
66973
+ for (const id of newIDs) {
66974
+ if (id) {
66975
+ layer.insert(parent2, key, "start", id);
66976
+ }
66977
+ }
66978
+ };
66979
+ }
66910
66980
  } else if (update === "append") {
66911
66981
  linkedIDs = oldIDs.concat(newIDs);
66982
+ if (layer?.optimistic) {
66983
+ action = () => {
66984
+ for (const id of newIDs) {
66985
+ if (id) {
66986
+ layer.insert(parent2, key, "end", id);
66987
+ }
66988
+ }
66989
+ };
66990
+ }
66912
66991
  } else if (update === "replace") {
66913
66992
  linkedIDs = newIDs;
66914
66993
  }
@@ -66927,7 +67006,7 @@ var CacheInternal = class {
66927
67006
  this.subscriptions.remove(lostID, fieldSelection, specs, variables);
66928
67007
  }
66929
67008
  if (contentChanged || oldIDs.length === 0 && newIDs.length === 0) {
66930
- layer.writeLink(parent2, key, linkedIDs);
67009
+ action();
66931
67010
  }
66932
67011
  for (const id of newIDs.filter((id2) => !oldIDs.includes(id2))) {
66933
67012
  if (id == null) {
@@ -66982,6 +67061,9 @@ var CacheInternal = class {
66982
67061
  if (!targetID) {
66983
67062
  continue;
66984
67063
  }
67064
+ toNotify.push(
67065
+ ...this.subscriptions.getAll(targetID).filter((sub) => sub[0].parentID !== targetID)
67066
+ );
66985
67067
  this.cache.delete(targetID, layer);
66986
67068
  }
66987
67069
  }
@@ -67403,7 +67485,6 @@ function variableValue(value, args) {
67403
67485
  );
67404
67486
  }
67405
67487
  }
67406
- var rootID = "_ROOT_";
67407
67488
  function defaultComponentField({
67408
67489
  cache,
67409
67490
  component,
@@ -78330,12 +78411,12 @@ async function packageJSON(targetPath, frameworkInfo) {
78330
78411
  }
78331
78412
  packageJSON2.devDependencies = {
78332
78413
  ...packageJSON2.devDependencies,
78333
- houdini: "^1.2.53"
78414
+ houdini: "^1.2.55"
78334
78415
  };
78335
78416
  if (frameworkInfo.framework === "svelte" || frameworkInfo.framework === "kit") {
78336
78417
  packageJSON2.devDependencies = {
78337
78418
  ...packageJSON2.devDependencies,
78338
- "houdini-svelte": "^1.2.53"
78419
+ "houdini-svelte": "^1.2.55"
78339
78420
  };
78340
78421
  } else {
78341
78422
  throw new Error(`Unmanaged framework: "${JSON.stringify(frameworkInfo)}"`);