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
@@ -65298,6 +65298,35 @@ var GarbageCollector = class {
65298
65298
  }
65299
65299
  };
65300
65300
 
65301
+ // src/runtime/cache/stuff.ts
65302
+ function evaluateKey(key, variables = null) {
65303
+ let evaluated = "";
65304
+ let varName = "";
65305
+ let inString = false;
65306
+ for (const char of key) {
65307
+ if (varName) {
65308
+ if (varChars.includes(char)) {
65309
+ varName += char;
65310
+ continue;
65311
+ }
65312
+ const value = variables?.[varName.slice(1)];
65313
+ evaluated += typeof value !== "undefined" ? JSON.stringify(value) : "undefined";
65314
+ varName = "";
65315
+ }
65316
+ if (char === "$" && !inString) {
65317
+ varName = "$";
65318
+ continue;
65319
+ }
65320
+ if (char === '"') {
65321
+ inString = !inString;
65322
+ }
65323
+ evaluated += char;
65324
+ }
65325
+ return evaluated;
65326
+ }
65327
+ var varChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789";
65328
+ var rootID = "_ROOT_";
65329
+
65301
65330
  // src/runtime/cache/lists.ts
65302
65331
  var ListManager = class {
65303
65332
  rootID;
@@ -65364,11 +65393,15 @@ var ListManager = class {
65364
65393
  this.listsByField.get(parentID).get(list.key).push(handler);
65365
65394
  }
65366
65395
  removeIDFromAllLists(id, layer) {
65396
+ let removed = false;
65367
65397
  for (const fieldMap of this.lists.values()) {
65368
65398
  for (const list of fieldMap.values()) {
65369
- list.removeID(id, void 0, layer);
65399
+ if (list.removeID(id, void 0, layer)) {
65400
+ removed = true;
65401
+ }
65370
65402
  }
65371
65403
  }
65404
+ return removed;
65372
65405
  }
65373
65406
  deleteField(parentID, field) {
65374
65407
  if (!this.listsByField.get(parentID)?.has(field)) {
@@ -65671,7 +65704,13 @@ var ListCollection = class {
65671
65704
  this.lists.forEach((list) => list.addToList(...args));
65672
65705
  }
65673
65706
  removeID(...args) {
65674
- this.lists.forEach((list) => list.removeID(...args));
65707
+ let removed = false;
65708
+ this.lists.forEach((list) => {
65709
+ if (list.removeID(...args)) {
65710
+ removed = true;
65711
+ }
65712
+ });
65713
+ return removed;
65675
65714
  }
65676
65715
  remove(...args) {
65677
65716
  this.lists.forEach((list) => list.remove(...args));
@@ -65790,6 +65829,7 @@ var InMemoryStorage = class {
65790
65829
  }
65791
65830
  registerIDMapping(from, to) {
65792
65831
  this.idMaps[from] = to;
65832
+ this.idMaps[to] = from;
65793
65833
  }
65794
65834
  createLayer(optimistic = false) {
65795
65835
  const layer = new Layer(this.idCount++);
@@ -65800,11 +65840,11 @@ var InMemoryStorage = class {
65800
65840
  insert(id, field, location, target) {
65801
65841
  return this.topLayer.insert(id, field, location, target);
65802
65842
  }
65803
- remove(id, field, target, layerToUser = this.topLayer) {
65804
- return layerToUser.remove(id, field, target);
65843
+ remove(id, field, target, layer = this.topLayer) {
65844
+ return layer.remove(id, field, target);
65805
65845
  }
65806
- delete(id, layerToUser = this.topLayer) {
65807
- return layerToUser.delete(id);
65846
+ delete(id, layer = this.topLayer) {
65847
+ return layer.delete(id);
65808
65848
  }
65809
65849
  deleteField(id, field) {
65810
65850
  return this.topLayer.deleteField(id, field);
@@ -65842,6 +65882,9 @@ var InMemoryStorage = class {
65842
65882
  return;
65843
65883
  }
65844
65884
  operations.remove.add(v2);
65885
+ if (this.idMaps[v2]) {
65886
+ operations.remove.add(this.idMaps[v2]);
65887
+ }
65845
65888
  });
65846
65889
  if (typeof layerValue === "undefined" && defaultValue) {
65847
65890
  const targetLayer = this.topLayer;
@@ -65868,7 +65911,11 @@ var InMemoryStorage = class {
65868
65911
  operations.remove.add(op.id);
65869
65912
  }
65870
65913
  if (isInsertOperation(op)) {
65871
- operations.insert[op.location].unshift(op.id);
65914
+ if (op.location === OperationLocation.end) {
65915
+ operations.insert[op.location].unshift(op.id);
65916
+ } else {
65917
+ operations.insert[op.location].push(op.id);
65918
+ }
65872
65919
  }
65873
65920
  if (isDeleteOperation(op)) {
65874
65921
  return {
@@ -66114,7 +66161,7 @@ var Layer = class {
66114
66161
  }
66115
66162
  for (const [id, ops] of Object.entries(layer.operations)) {
66116
66163
  const fields = {};
66117
- for (const opMap of [this.operations[id], layer.operations[id]].filter(Boolean)) {
66164
+ for (const opMap of [layer.operations[id], this.operations[id]].filter(Boolean)) {
66118
66165
  for (const [fieldName, operations] of Object.entries(opMap.fields || {})) {
66119
66166
  fields[fieldName] = [...fields[fieldName] || [], ...operations];
66120
66167
  }
@@ -66154,6 +66201,7 @@ var Layer = class {
66154
66201
  [id]: {
66155
66202
  ...this.operations[id],
66156
66203
  fields: {
66204
+ ...this.operations[id]?.fields,
66157
66205
  [field]: [...this.operations[id]?.fields[field] || [], operation]
66158
66206
  }
66159
66207
  }
@@ -66179,34 +66227,6 @@ var OperationKind = {
66179
66227
  remove: "remove"
66180
66228
  };
66181
66229
 
66182
- // src/runtime/cache/stuff.ts
66183
- function evaluateKey(key, variables = null) {
66184
- let evaluated = "";
66185
- let varName = "";
66186
- let inString = false;
66187
- for (const char of key) {
66188
- if (varName) {
66189
- if (varChars.includes(char)) {
66190
- varName += char;
66191
- continue;
66192
- }
66193
- const value = variables?.[varName.slice(1)];
66194
- evaluated += typeof value !== "undefined" ? JSON.stringify(value) : "undefined";
66195
- varName = "";
66196
- }
66197
- if (char === "$" && !inString) {
66198
- varName = "$";
66199
- continue;
66200
- }
66201
- if (char === '"') {
66202
- inString = !inString;
66203
- }
66204
- evaluated += char;
66205
- }
66206
- return evaluated;
66207
- }
66208
- var varChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789";
66209
-
66210
66230
  // src/runtime/cache/subscription.ts
66211
66231
  var InMemorySubscriptions = class {
66212
66232
  cache;
@@ -66218,6 +66238,9 @@ var InMemorySubscriptions = class {
66218
66238
  activeFields(parent2) {
66219
66239
  return Object.keys(this.subscribers.get(parent2) || {});
66220
66240
  }
66241
+ copySubscribers(from, to) {
66242
+ this.subscribers.set(to, this.subscribers.get(from) || /* @__PURE__ */ new Map());
66243
+ }
66221
66244
  add({
66222
66245
  parent: parent2,
66223
66246
  spec,
@@ -66400,6 +66423,11 @@ var InMemorySubscriptions = class {
66400
66423
  get(id, field) {
66401
66424
  return this.subscribers.get(id)?.get(field)?.selections || [];
66402
66425
  }
66426
+ getAll(id) {
66427
+ return [...this.subscribers.get(id)?.values() || []].flatMap(
66428
+ (fieldSub) => fieldSub.selections
66429
+ );
66430
+ }
66403
66431
  remove(id, selection, targets, variables, visited = []) {
66404
66432
  visited.push(id);
66405
66433
  const linkedIDs = [];
@@ -66441,7 +66469,7 @@ var InMemorySubscriptions = class {
66441
66469
  }
66442
66470
  const subscriberField = subscriber.get(fieldName);
66443
66471
  for (const spec of specs) {
66444
- const counts = subscriber.get(fieldName)?.referenceCounts;
66472
+ const counts = subscriberField?.referenceCounts;
66445
66473
  if (!counts?.has(spec.set)) {
66446
66474
  continue;
66447
66475
  }
@@ -66464,24 +66492,23 @@ var InMemorySubscriptions = class {
66464
66492
  this.subscribers.delete(id);
66465
66493
  }
66466
66494
  }
66467
- removeAllSubscribers(id, targets, visited = []) {
66468
- visited.push(id);
66469
- const subscriber = this.subscribers.get(id);
66470
- for (const [key, val] of subscriber?.entries() ?? []) {
66471
- const subscribers = targets || val.selections.map(([spec]) => spec);
66472
- this.removeSubscribers(id, key, subscribers);
66473
- const { value, kind } = this.cache._internal_unstable.storage.get(id, key);
66474
- if (kind === "scalar") {
66475
- continue;
66476
- }
66477
- const nextTargets = Array.isArray(value) ? flatten(value) : [value];
66478
- for (const id2 of nextTargets) {
66479
- if (visited.includes(id2)) {
66480
- continue;
66481
- }
66482
- this.removeAllSubscribers(id2, subscribers, visited);
66495
+ removeAllSubscribers(id, targets) {
66496
+ if (!targets) {
66497
+ targets = [...this.subscribers.get(id)?.values() || []].flatMap(
66498
+ (spec) => spec.selections.flatMap((sel) => sel[0])
66499
+ );
66500
+ }
66501
+ for (const target of targets) {
66502
+ for (const subselection of this.findSubSelections(
66503
+ target.parentID || rootID,
66504
+ target.selection,
66505
+ target.variables || {},
66506
+ id
66507
+ )) {
66508
+ this.remove(id, subselection, targets, target.variables || {});
66483
66509
  }
66484
66510
  }
66511
+ return;
66485
66512
  }
66486
66513
  get size() {
66487
66514
  let size = 0;
@@ -66492,6 +66519,32 @@ var InMemorySubscriptions = class {
66492
66519
  }
66493
66520
  return size;
66494
66521
  }
66522
+ findSubSelections(parentID, selection, variables, searchTarget, selections = []) {
66523
+ const __typename = this.cache._internal_unstable.storage.get(parentID, "__typename").value;
66524
+ let targetSelection = getFieldsForType(selection, __typename, false);
66525
+ for (const fieldSelection of Object.values(targetSelection || {})) {
66526
+ if (!fieldSelection.selection) {
66527
+ continue;
66528
+ }
66529
+ const key = evaluateKey(fieldSelection.keyRaw, variables || {});
66530
+ const linkedRecord = this.cache._internal_unstable.storage.get(parentID, key);
66531
+ const links = !Array.isArray(linkedRecord.value) ? [linkedRecord.value] : flatten(linkedRecord.value);
66532
+ if (links.includes(searchTarget)) {
66533
+ selections.push(fieldSelection.selection);
66534
+ } else {
66535
+ for (const link of links) {
66536
+ this.findSubSelections(
66537
+ link,
66538
+ fieldSelection.selection,
66539
+ variables,
66540
+ searchTarget,
66541
+ selections
66542
+ );
66543
+ }
66544
+ }
66545
+ }
66546
+ return selections;
66547
+ }
66495
66548
  };
66496
66549
 
66497
66550
  // src/runtime/cache/cache.ts
@@ -66569,11 +66622,17 @@ var Cache = class {
66569
66622
  }
66570
66623
  registerKeyMap(source, mapped) {
66571
66624
  this._internal_unstable.storage.registerIDMapping(source, mapped);
66625
+ this._internal_unstable.subscriptions.copySubscribers(source, mapped);
66572
66626
  }
66573
66627
  delete(id, layer) {
66574
- this._internal_unstable.subscriptions.removeAllSubscribers(id);
66575
- this._internal_unstable.lists.removeIDFromAllLists(id, layer);
66576
- this._internal_unstable.storage.delete(id, layer);
66628
+ const recordIDs = [this._internal_unstable.storage.idMaps[id], id].filter(
66629
+ Boolean
66630
+ );
66631
+ for (const recordID of recordIDs) {
66632
+ this._internal_unstable.subscriptions.removeAllSubscribers(recordID);
66633
+ this._internal_unstable.lists.removeIDFromAllLists(recordID, layer);
66634
+ this._internal_unstable.storage.delete(recordID, layer);
66635
+ }
66577
66636
  }
66578
66637
  setConfig(config) {
66579
66638
  this._internal_unstable.setConfig(config);
@@ -66879,6 +66938,9 @@ var CacheInternal = class {
66879
66938
  layer,
66880
66939
  forceNotify
66881
66940
  });
66941
+ let action = () => {
66942
+ layer.writeLink(parent2, key, linkedIDs);
66943
+ };
66882
66944
  if (applyUpdates && updates) {
66883
66945
  if (key === "edges") {
66884
66946
  const newNodeIDs = [];
@@ -66913,8 +66975,26 @@ var CacheInternal = class {
66913
66975
  }
66914
66976
  if (update === "prepend") {
66915
66977
  linkedIDs = newIDs.concat(oldIDs);
66978
+ if (layer?.optimistic) {
66979
+ action = () => {
66980
+ for (const id of newIDs) {
66981
+ if (id) {
66982
+ layer.insert(parent2, key, "start", id);
66983
+ }
66984
+ }
66985
+ };
66986
+ }
66916
66987
  } else if (update === "append") {
66917
66988
  linkedIDs = oldIDs.concat(newIDs);
66989
+ if (layer?.optimistic) {
66990
+ action = () => {
66991
+ for (const id of newIDs) {
66992
+ if (id) {
66993
+ layer.insert(parent2, key, "end", id);
66994
+ }
66995
+ }
66996
+ };
66997
+ }
66918
66998
  } else if (update === "replace") {
66919
66999
  linkedIDs = newIDs;
66920
67000
  }
@@ -66933,7 +67013,7 @@ var CacheInternal = class {
66933
67013
  this.subscriptions.remove(lostID, fieldSelection, specs, variables);
66934
67014
  }
66935
67015
  if (contentChanged || oldIDs.length === 0 && newIDs.length === 0) {
66936
- layer.writeLink(parent2, key, linkedIDs);
67016
+ action();
66937
67017
  }
66938
67018
  for (const id of newIDs.filter((id2) => !oldIDs.includes(id2))) {
66939
67019
  if (id == null) {
@@ -66988,6 +67068,9 @@ var CacheInternal = class {
66988
67068
  if (!targetID) {
66989
67069
  continue;
66990
67070
  }
67071
+ toNotify.push(
67072
+ ...this.subscriptions.getAll(targetID).filter((sub) => sub[0].parentID !== targetID)
67073
+ );
66991
67074
  this.cache.delete(targetID, layer);
66992
67075
  }
66993
67076
  }
@@ -67409,7 +67492,6 @@ function variableValue(value, args) {
67409
67492
  );
67410
67493
  }
67411
67494
  }
67412
- var rootID = "_ROOT_";
67413
67495
  function defaultComponentField({
67414
67496
  cache,
67415
67497
  component,
@@ -78335,12 +78417,12 @@ async function packageJSON(targetPath, frameworkInfo) {
78335
78417
  }
78336
78418
  packageJSON2.devDependencies = {
78337
78419
  ...packageJSON2.devDependencies,
78338
- houdini: "^1.2.54"
78420
+ houdini: "^1.2.56"
78339
78421
  };
78340
78422
  if (frameworkInfo.framework === "svelte" || frameworkInfo.framework === "kit") {
78341
78423
  packageJSON2.devDependencies = {
78342
78424
  ...packageJSON2.devDependencies,
78343
- "houdini-svelte": "^1.2.54"
78425
+ "houdini-svelte": "^1.2.56"
78344
78426
  };
78345
78427
  } else {
78346
78428
  throw new Error(`Unmanaged framework: "${JSON.stringify(frameworkInfo)}"`);