houdini 1.2.2 → 1.2.4

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 (64) hide show
  1. package/build/cmd-cjs/index.js +183 -63
  2. package/build/cmd-esm/index.js +183 -63
  3. package/build/codegen-cjs/index.js +181 -61
  4. package/build/codegen-esm/index.js +181 -61
  5. package/build/lib/fs.d.ts +8 -1
  6. package/build/lib/index.d.ts +1 -0
  7. package/build/lib/parse.d.ts +1 -1
  8. package/build/lib/types.d.ts +11 -0
  9. package/build/lib-cjs/index.js +181 -69
  10. package/build/lib-esm/index.js +179 -69
  11. package/build/runtime/cache/cache.d.ts +5 -1
  12. package/build/runtime/cache/lists.d.ts +3 -3
  13. package/build/runtime/cache/storage.d.ts +8 -2
  14. package/build/runtime/cache/subscription.d.ts +1 -0
  15. package/build/runtime/client/documentStore.d.ts +9 -2
  16. package/build/runtime/client/index.d.ts +6 -3
  17. package/build/runtime/lib/index.d.ts +1 -0
  18. package/build/runtime/lib/lru.d.ts +52 -0
  19. package/build/runtime/lib/types.d.ts +1 -0
  20. package/build/runtime-cjs/cache/cache.d.ts +5 -1
  21. package/build/runtime-cjs/cache/cache.js +84 -27
  22. package/build/runtime-cjs/cache/lists.d.ts +3 -3
  23. package/build/runtime-cjs/cache/lists.js +20 -8
  24. package/build/runtime-cjs/cache/storage.d.ts +8 -2
  25. package/build/runtime-cjs/cache/storage.js +22 -5
  26. package/build/runtime-cjs/cache/subscription.d.ts +1 -0
  27. package/build/runtime-cjs/cache/subscription.js +3 -0
  28. package/build/runtime-cjs/client/documentStore.d.ts +9 -2
  29. package/build/runtime-cjs/client/documentStore.js +13 -9
  30. package/build/runtime-cjs/client/index.d.ts +6 -3
  31. package/build/runtime-cjs/client/index.js +6 -8
  32. package/build/runtime-cjs/client/plugins/cache.js +3 -0
  33. package/build/runtime-cjs/client/plugins/mutation.js +10 -6
  34. package/build/runtime-cjs/lib/index.d.ts +1 -0
  35. package/build/runtime-cjs/lib/index.js +1 -0
  36. package/build/runtime-cjs/lib/lru.d.ts +52 -0
  37. package/build/runtime-cjs/lib/lru.js +73 -0
  38. package/build/runtime-cjs/lib/types.d.ts +1 -0
  39. package/build/runtime-cjs/lib/types.js +7 -2
  40. package/build/runtime-esm/cache/cache.d.ts +5 -1
  41. package/build/runtime-esm/cache/cache.js +84 -27
  42. package/build/runtime-esm/cache/lists.d.ts +3 -3
  43. package/build/runtime-esm/cache/lists.js +20 -8
  44. package/build/runtime-esm/cache/storage.d.ts +8 -2
  45. package/build/runtime-esm/cache/storage.js +22 -5
  46. package/build/runtime-esm/cache/subscription.d.ts +1 -0
  47. package/build/runtime-esm/cache/subscription.js +3 -0
  48. package/build/runtime-esm/client/documentStore.d.ts +9 -2
  49. package/build/runtime-esm/client/documentStore.js +13 -9
  50. package/build/runtime-esm/client/index.d.ts +6 -3
  51. package/build/runtime-esm/client/index.js +6 -8
  52. package/build/runtime-esm/client/plugins/cache.js +3 -0
  53. package/build/runtime-esm/client/plugins/mutation.js +10 -6
  54. package/build/runtime-esm/lib/index.d.ts +1 -0
  55. package/build/runtime-esm/lib/index.js +1 -0
  56. package/build/runtime-esm/lib/lru.d.ts +52 -0
  57. package/build/runtime-esm/lib/lru.js +48 -0
  58. package/build/runtime-esm/lib/types.d.ts +1 -0
  59. package/build/runtime-esm/lib/types.js +5 -1
  60. package/build/test-cjs/index.js +181 -61
  61. package/build/test-esm/index.js +181 -61
  62. package/build/vite-cjs/index.js +200 -62
  63. package/build/vite-esm/index.js +200 -62
  64. package/package.json +1 -1
@@ -46,18 +46,16 @@ class HoudiniClient {
46
46
  this.url = url;
47
47
  }
48
48
  observe({
49
- artifact,
50
- cache = true,
51
- initialValue,
52
- fetching = false
49
+ enableCache = true,
50
+ fetching = false,
51
+ ...rest
53
52
  }) {
54
53
  return new DocumentStore({
55
54
  client: this,
56
- artifact,
57
55
  plugins: createPluginHooks(this.plugins),
58
- cache,
59
- initialValue,
60
- fetching
56
+ fetching,
57
+ enableCache,
58
+ ...rest
61
59
  });
62
60
  }
63
61
  }
@@ -68,6 +68,9 @@ const cachePolicy = ({
68
68
  },
69
69
  afterNetwork(ctx, { resolve, value, marshalVariables }) {
70
70
  if (value.source !== DataSource.Cache && enabled && value.data && !ctx.cacheParams?.disableWrite) {
71
+ if (ctx.cacheParams && "serverSideFallback" in ctx.cacheParams) {
72
+ serverSideFallback = ctx.cacheParams?.serverSideFallback ?? serverSideFallback;
73
+ }
71
74
  const targetCache = serverSide && serverSideFallback ? new Cache({ disabled: false }) : localCache;
72
75
  let layer;
73
76
  if (!serverSide && ctx.cacheParams?.layer) {
@@ -5,7 +5,7 @@ import { documentPlugin } from "../utils";
5
5
  const mutation = documentPlugin(ArtifactKind.Mutation, () => {
6
6
  return {
7
7
  async start(ctx, { next, marshalVariables }) {
8
- const layer = cache._internal_unstable.storage.createLayer(true);
8
+ const layerOptimistic = cache._internal_unstable.storage.createLayer(true);
9
9
  const optimisticResponse = ctx.stuff.optimisticResponse;
10
10
  let toNotify = [];
11
11
  if (optimisticResponse) {
@@ -16,25 +16,29 @@ const mutation = documentPlugin(ArtifactKind.Mutation, () => {
16
16
  data: optimisticResponse
17
17
  }),
18
18
  variables: marshalVariables(ctx),
19
- layer: layer.id
19
+ layer: layerOptimistic.id
20
20
  });
21
21
  }
22
22
  ctx.cacheParams = {
23
23
  ...ctx.cacheParams,
24
- layer,
24
+ layer: layerOptimistic,
25
25
  notifySubscribers: toNotify,
26
26
  forceNotify: true
27
27
  };
28
28
  next(ctx);
29
29
  },
30
30
  afterNetwork(ctx, { resolve }) {
31
- ctx.cacheParams?.layer?.clear();
31
+ if (ctx.cacheParams?.layer) {
32
+ cache.clearLayer(ctx.cacheParams.layer.id);
33
+ }
32
34
  resolve(ctx);
33
35
  },
34
36
  end(ctx, { resolve, value }) {
35
37
  const hasErrors = value.errors && value.errors.length > 0;
36
38
  if (hasErrors) {
37
- ctx.cacheParams?.layer?.clear();
39
+ if (ctx.cacheParams?.layer) {
40
+ cache.clearLayer(ctx.cacheParams.layer.id);
41
+ }
38
42
  }
39
43
  if (ctx.cacheParams?.layer) {
40
44
  cache._internal_unstable.storage.resolveLayer(ctx.cacheParams.layer.id);
@@ -44,7 +48,7 @@ const mutation = documentPlugin(ArtifactKind.Mutation, () => {
44
48
  catch(ctx, { error }) {
45
49
  if (ctx.cacheParams?.layer) {
46
50
  const { layer } = ctx.cacheParams;
47
- layer.clear();
51
+ cache.clearLayer(layer.id);
48
52
  cache._internal_unstable.storage.resolveLayer(layer.id);
49
53
  }
50
54
  throw error;
@@ -6,3 +6,4 @@ export * from './scalars';
6
6
  export * from './types';
7
7
  export * from './store';
8
8
  export * from './key';
9
+ export * from './lru';
@@ -6,3 +6,4 @@ export * from "./scalars";
6
6
  export * from "./types";
7
7
  export * from "./store";
8
8
  export * from "./key";
9
+ export * from "./lru";
@@ -0,0 +1,52 @@
1
+ /**
2
+ * This file is a copy and paste of a very simple and effective LRU cache
3
+ * using javascript maps. It was copied under the MIT license found at the
4
+ * bottom of the page.
5
+ */
6
+ /**
7
+ * JS maps (both plain objects and Map) maintain key insertion
8
+ * order, which means there is an easy way to simulate LRU behavior
9
+ * that should also perform quite well:
10
+ *
11
+ * To insert a new value, first delete the key from the inner _map,
12
+ * then _map.set(k, v). By deleting and reinserting, you ensure that the
13
+ * map sees the key as the last inserted key.
14
+ *
15
+ * Get does the same: if the key is present, delete and reinsert it.
16
+ */
17
+ export declare class LRUCache<T> {
18
+ _capacity: number;
19
+ _map: Map<string, T>;
20
+ constructor(capacity?: number);
21
+ set(key: string, value: T): void;
22
+ get(key: string): T | null;
23
+ has(key: string): boolean;
24
+ delete(key: string): void;
25
+ size(): number;
26
+ capacity(): number;
27
+ clear(): void;
28
+ }
29
+ export declare function createLRUCache<T>(capacity?: number): LRUCache<T>;
30
+ /**
31
+ MIT License
32
+
33
+ Copyright (c) Meta Platforms, Inc. and affiliates.
34
+
35
+ Permission is hereby granted, free of charge, to any person obtaining a copy
36
+ of this software and associated documentation files (the "Software"), to deal
37
+ in the Software without restriction, including without limitation the rights
38
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
39
+ copies of the Software, and to permit persons to whom the Software is
40
+ furnished to do so, subject to the following conditions:
41
+
42
+ The above copyright notice and this permission notice shall be included in all
43
+ copies or substantial portions of the Software.
44
+
45
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
46
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
47
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
48
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
49
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
50
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
51
+ SOFTWARE.
52
+ */
@@ -0,0 +1,48 @@
1
+ class LRUCache {
2
+ _capacity;
3
+ _map;
4
+ constructor(capacity = 1e3) {
5
+ this._capacity = capacity;
6
+ this._map = /* @__PURE__ */ new Map();
7
+ }
8
+ set(key, value) {
9
+ this._map.delete(key);
10
+ this._map.set(key, value);
11
+ if (this._map.size > this._capacity) {
12
+ const firstKey = this._map.keys().next();
13
+ if (!firstKey.done) {
14
+ this._map.delete(firstKey.value);
15
+ }
16
+ }
17
+ }
18
+ get(key) {
19
+ const value = this._map.get(key);
20
+ if (value != null) {
21
+ this._map.delete(key);
22
+ this._map.set(key, value);
23
+ }
24
+ return value ?? null;
25
+ }
26
+ has(key) {
27
+ return this._map.has(key);
28
+ }
29
+ delete(key) {
30
+ this._map.delete(key);
31
+ }
32
+ size() {
33
+ return this._map.size;
34
+ }
35
+ capacity() {
36
+ return this._capacity - this._map.size;
37
+ }
38
+ clear() {
39
+ this._map.clear();
40
+ }
41
+ }
42
+ function createLRUCache(capacity = 1e3) {
43
+ return new LRUCache(capacity);
44
+ }
45
+ export {
46
+ LRUCache,
47
+ createLRUCache
48
+ };
@@ -316,4 +316,5 @@ interface VariableNode {
316
316
  }
317
317
  export declare const PendingValue: unique symbol;
318
318
  export type LoadingType = typeof PendingValue;
319
+ export declare function isPending(value: any): value is LoadingType;
319
320
  export {};
@@ -30,6 +30,9 @@ const DataSource = {
30
30
  };
31
31
  const fragmentKey = " $fragments";
32
32
  const PendingValue = Symbol("houdini_loading");
33
+ function isPending(value) {
34
+ return typeof value === "symbol";
35
+ }
33
36
  export {
34
37
  ArtifactKind,
35
38
  CachePolicy,
@@ -41,5 +44,6 @@ export {
41
44
  PaginateMode,
42
45
  PendingValue,
43
46
  RefetchUpdateMode,
44
- fragmentKey
47
+ fragmentKey,
48
+ isPending
45
49
  };
@@ -54390,6 +54390,7 @@ __export(fs_exports, {
54390
54390
  recursiveCopy: () => recursiveCopy,
54391
54391
  remove: () => remove,
54392
54392
  rmdir: () => rmdir,
54393
+ snapshot: () => snapshot,
54393
54394
  stat: () => stat,
54394
54395
  writeFile: () => writeFile
54395
54396
  });
@@ -54584,16 +54585,17 @@ function existsSync(dirPath) {
54584
54585
  }
54585
54586
  return import_memfs.fs.existsSync(dirPath);
54586
54587
  }
54587
- async function readdir(filepath) {
54588
+ async function readdir(filepath, opts) {
54588
54589
  if (!houdini_mode.is_testing) {
54589
- return await import_promises.default.readdir(filepath);
54590
+ return await import_promises.default.readdir(filepath, opts);
54590
54591
  }
54591
54592
  if (filepath.includes("build/runtime")) {
54592
- return await import_promises.default.readdir(filepath);
54593
+ return await import_promises.default.readdir(filepath, opts);
54593
54594
  }
54594
54595
  try {
54595
- return import_memfs.fs.readdirSync(filepath);
54596
- } catch {
54596
+ return import_memfs.fs.readdirSync(filepath, opts);
54597
+ } catch (e) {
54598
+ console.log(e);
54597
54599
  return [];
54598
54600
  }
54599
54601
  }
@@ -54644,6 +54646,11 @@ async function recursiveCopy(source, target, transforms, notRoot) {
54644
54646
  );
54645
54647
  }
54646
54648
  }
54649
+ function snapshot(base) {
54650
+ return Object.fromEntries(
54651
+ Object.entries(import_memfs.vol.toJSON()).filter(([key]) => !base || key.startsWith(base)).map(([key, value]) => [!base ? key : key.substring(base.length), value])
54652
+ );
54653
+ }
54647
54654
  async function glob(pattern) {
54648
54655
  return await (0, import_node_util.promisify)(import_glob.glob)(posixify(pattern));
54649
54656
  }
@@ -54775,10 +54782,10 @@ var ListManager = class {
54775
54782
  this.lists.get(list.name).get(parentID).lists.push(handler);
54776
54783
  this.listsByField.get(parentID).get(list.key).push(handler);
54777
54784
  }
54778
- removeIDFromAllLists(id) {
54785
+ removeIDFromAllLists(id, layer) {
54779
54786
  for (const fieldMap of this.lists.values()) {
54780
54787
  for (const list of fieldMap.values()) {
54781
- list.removeID(id);
54788
+ list.removeID(id, void 0, layer);
54782
54789
  }
54783
54790
  }
54784
54791
  }
@@ -54875,6 +54882,10 @@ var List = class {
54875
54882
  updates: ["append", "prepend"],
54876
54883
  selection: {
54877
54884
  fields: {
54885
+ __typename: {
54886
+ keyRaw: "__typename",
54887
+ type: "String"
54888
+ },
54878
54889
  node: {
54879
54890
  type: listType,
54880
54891
  keyRaw: "node",
@@ -54899,7 +54910,15 @@ var List = class {
54899
54910
  };
54900
54911
  insertData = {
54901
54912
  newEntry: {
54902
- edges: [{ node: { ...data, __typename: listType } }]
54913
+ edges: [
54914
+ {
54915
+ __typename: listType + "Edge",
54916
+ node: {
54917
+ ...data,
54918
+ __typename: listType
54919
+ }
54920
+ }
54921
+ ]
54903
54922
  }
54904
54923
  };
54905
54924
  } else {
@@ -54935,7 +54954,7 @@ var List = class {
54935
54954
  layer: layer?.id
54936
54955
  });
54937
54956
  }
54938
- removeID(id, variables = {}) {
54957
+ removeID(id, variables = {}, layer) {
54939
54958
  if (!this.validateWhen()) {
54940
54959
  return;
54941
54960
  }
@@ -54982,7 +55001,7 @@ var List = class {
54982
55001
  subscribers.map((sub) => sub[0]),
54983
55002
  variables
54984
55003
  );
54985
- this.cache._internal_unstable.storage.remove(parentID, targetKey, targetID);
55004
+ this.cache._internal_unstable.storage.remove(parentID, targetKey, targetID, layer);
54986
55005
  for (const [spec] of subscribers) {
54987
55006
  spec.set(
54988
55007
  this.cache._internal_unstable.getSelection({
@@ -54995,12 +55014,12 @@ var List = class {
54995
55014
  }
54996
55015
  return true;
54997
55016
  }
54998
- remove(data, variables = {}) {
55017
+ remove(data, variables = {}, layer) {
54999
55018
  const targetID = this.cache._internal_unstable.id(this.listType(data), data);
55000
55019
  if (!targetID) {
55001
55020
  return;
55002
55021
  }
55003
- return this.removeID(targetID, variables);
55022
+ return this.removeID(targetID, variables, layer);
55004
55023
  }
55005
55024
  listType(data) {
55006
55025
  return data.__typename || this.type;
@@ -55032,7 +55051,7 @@ var List = class {
55032
55051
  layer,
55033
55052
  where
55034
55053
  }) {
55035
- if (!this.remove(data, variables)) {
55054
+ if (!this.remove(data, variables, layer)) {
55036
55055
  this.addToList(selection, data, variables, where, layer);
55037
55056
  }
55038
55057
  }
@@ -55169,7 +55188,7 @@ var StaleManager = class {
55169
55188
  // src/runtime/cache/storage.ts
55170
55189
  var InMemoryStorage = class {
55171
55190
  data;
55172
- idCount = 0;
55191
+ idCount = 1;
55173
55192
  rank = 0;
55174
55193
  constructor() {
55175
55194
  this.data = [];
@@ -55189,11 +55208,11 @@ var InMemoryStorage = class {
55189
55208
  insert(id, field, location, target) {
55190
55209
  return this.topLayer.insert(id, field, location, target);
55191
55210
  }
55192
- remove(id, field, target) {
55193
- return this.topLayer.remove(id, field, target);
55211
+ remove(id, field, target, layerToUser = this.topLayer) {
55212
+ return layerToUser.remove(id, field, target);
55194
55213
  }
55195
- delete(id) {
55196
- return this.topLayer.delete(id);
55214
+ delete(id, layerToUser = this.topLayer) {
55215
+ return layerToUser.delete(id);
55197
55216
  }
55198
55217
  deleteField(id, field) {
55199
55218
  return this.topLayer.deleteField(id, field);
@@ -55327,6 +55346,23 @@ var InMemoryStorage = class {
55327
55346
  }
55328
55347
  return this.data[this.data.length - 1];
55329
55348
  }
55349
+ serialize() {
55350
+ return JSON.stringify({
55351
+ rank: this.rank,
55352
+ fields: this.topLayer.fields,
55353
+ links: this.topLayer.links
55354
+ });
55355
+ }
55356
+ hydrate(args, layer) {
55357
+ if (!args) {
55358
+ return;
55359
+ }
55360
+ const { rank, fields, links } = args;
55361
+ this.rank = rank;
55362
+ layer ??= this.createLayer(true);
55363
+ layer.fields = fields;
55364
+ layer.links = links;
55365
+ }
55330
55366
  };
55331
55367
  var Layer = class {
55332
55368
  id;
@@ -55565,6 +55601,9 @@ var InMemorySubscriptions = class {
55565
55601
  subscribers = {};
55566
55602
  referenceCounts = {};
55567
55603
  keyVersions = {};
55604
+ activeFields(parent2) {
55605
+ return Object.keys(this.subscribers[parent2] || {});
55606
+ }
55568
55607
  add({
55569
55608
  parent: parent2,
55570
55609
  spec,
@@ -55833,20 +55872,7 @@ var Cache = class {
55833
55872
  }) {
55834
55873
  const layer = layerID ? this._internal_unstable.storage.getLayer(layerID) : this._internal_unstable.storage.topLayer;
55835
55874
  const subscribers = this._internal_unstable.writeSelection({ ...args, layer }).map((sub) => sub[0]);
55836
- const notified = [];
55837
- for (const spec of subscribers.concat(notifySubscribers)) {
55838
- if (!notified.includes(spec.set)) {
55839
- notified.push(spec.set);
55840
- spec.set(
55841
- this._internal_unstable.getSelection({
55842
- parent: spec.parentID || rootID,
55843
- selection: spec.selection,
55844
- variables: spec.variables?.() || {},
55845
- ignoreMasking: false
55846
- }).data
55847
- );
55848
- }
55849
- }
55875
+ this.#notifySubscribers(subscribers.concat(notifySubscribers));
55850
55876
  return subscribers;
55851
55877
  }
55852
55878
  read(...args) {
@@ -55885,10 +55911,10 @@ var Cache = class {
55885
55911
  }
55886
55912
  return handler;
55887
55913
  }
55888
- delete(id) {
55914
+ delete(id, layer) {
55889
55915
  this._internal_unstable.subscriptions.removeAllSubscribers(id);
55890
- this._internal_unstable.lists.removeIDFromAllLists(id);
55891
- this._internal_unstable.storage.delete(id);
55916
+ this._internal_unstable.lists.removeIDFromAllLists(id, layer);
55917
+ this._internal_unstable.storage.delete(id, layer);
55892
55918
  }
55893
55919
  setConfig(config2) {
55894
55920
  this._internal_unstable.setConfig(config2);
@@ -55920,6 +55946,76 @@ var Cache = class {
55920
55946
  config() {
55921
55947
  return this._internal_unstable.config;
55922
55948
  }
55949
+ serialize() {
55950
+ return this._internal_unstable.storage.serialize();
55951
+ }
55952
+ hydrate(...args) {
55953
+ return this._internal_unstable.storage.hydrate(...args);
55954
+ }
55955
+ clearLayer(layerID) {
55956
+ const layer = this._internal_unstable.storage.getLayer(layerID);
55957
+ if (!layer) {
55958
+ throw new Error("Cannot find layer with id: " + layerID);
55959
+ }
55960
+ const toNotify = [];
55961
+ const allFields = [];
55962
+ for (const target of [layer.fields, layer.links]) {
55963
+ for (const [id, fields] of Object.entries(target)) {
55964
+ allFields.push(
55965
+ ...Object.entries(fields).map(([field, value]) => ({ id, field, value }))
55966
+ );
55967
+ }
55968
+ }
55969
+ const displayFields = [];
55970
+ for (const pair of allFields) {
55971
+ const { displayLayers } = this._internal_unstable.storage.get(pair.id, pair.field);
55972
+ if (!displayLayers.includes(layerID)) {
55973
+ continue;
55974
+ }
55975
+ displayFields.push(pair);
55976
+ }
55977
+ for (const [id, operation] of Object.entries(layer.operations)) {
55978
+ if (operation.deleted) {
55979
+ displayFields.push(
55980
+ ...this._internal_unstable.subscriptions.activeFields(id).map((field) => ({ id, field }))
55981
+ );
55982
+ }
55983
+ const fields = Object.keys(operation.fields ?? {});
55984
+ if (fields.length > 0) {
55985
+ displayFields.push(...fields.map((field) => ({ id, field })));
55986
+ }
55987
+ }
55988
+ layer.clear();
55989
+ for (const display of displayFields) {
55990
+ const { field, id } = display;
55991
+ const notify = !("value" in display) || this._internal_unstable.storage.get(id, field).value !== display.value;
55992
+ if (notify) {
55993
+ toNotify.push(
55994
+ ...this._internal_unstable.subscriptions.get(id, field).map((sub) => sub[0])
55995
+ );
55996
+ }
55997
+ }
55998
+ this.#notifySubscribers(toNotify);
55999
+ }
56000
+ #notifySubscribers(subs) {
56001
+ if (subs.length === 0) {
56002
+ return;
56003
+ }
56004
+ const notified = [];
56005
+ for (const spec of subs) {
56006
+ if (!notified.includes(spec.set)) {
56007
+ notified.push(spec.set);
56008
+ spec.set(
56009
+ this._internal_unstable.getSelection({
56010
+ parent: spec.parentID || rootID,
56011
+ selection: spec.selection,
56012
+ variables: spec.variables?.() || {},
56013
+ ignoreMasking: false
56014
+ }).data
56015
+ );
56016
+ }
56017
+ }
56018
+ }
55923
56019
  };
55924
56020
  var CacheInternal = class {
55925
56021
  _disabled = false;
@@ -56207,8 +56303,16 @@ var CacheInternal = class {
56207
56303
  operation.position || "last",
56208
56304
  layer
56209
56305
  );
56306
+ } else if (operation.action === "toggle" && target instanceof Object && fieldSelection && operation.list) {
56307
+ this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).toggleElement({
56308
+ selection: fieldSelection,
56309
+ data: target,
56310
+ variables,
56311
+ where: operation.position || "last",
56312
+ layer
56313
+ });
56210
56314
  } else if (operation.action === "remove" && target instanceof Object && fieldSelection && operation.list) {
56211
- this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).remove(target, variables);
56315
+ this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).remove(target, variables, layer);
56212
56316
  } else if (operation.action === "delete" && operation.type) {
56213
56317
  if (typeof target !== "string") {
56214
56318
  throw new Error("Cannot delete a record with a non-string ID");
@@ -56217,15 +56321,7 @@ var CacheInternal = class {
56217
56321
  if (!targetID) {
56218
56322
  continue;
56219
56323
  }
56220
- this.cache.delete(targetID);
56221
- } else if (operation.action === "toggle" && target instanceof Object && fieldSelection && operation.list) {
56222
- this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).toggleElement({
56223
- selection: fieldSelection,
56224
- data: target,
56225
- variables,
56226
- where: operation.position || "last",
56227
- layer
56228
- });
56324
+ this.cache.delete(targetID, layer);
56229
56325
  }
56230
56326
  }
56231
56327
  }
@@ -56760,7 +56856,7 @@ var fragment = documentPlugin(ArtifactKind.Fragment, function() {
56760
56856
  var mutation = documentPlugin(ArtifactKind.Mutation, () => {
56761
56857
  return {
56762
56858
  async start(ctx, { next, marshalVariables }) {
56763
- const layer = cache_default._internal_unstable.storage.createLayer(true);
56859
+ const layerOptimistic = cache_default._internal_unstable.storage.createLayer(true);
56764
56860
  const optimisticResponse = ctx.stuff.optimisticResponse;
56765
56861
  let toNotify = [];
56766
56862
  if (optimisticResponse) {
@@ -56771,25 +56867,29 @@ var mutation = documentPlugin(ArtifactKind.Mutation, () => {
56771
56867
  data: optimisticResponse
56772
56868
  }),
56773
56869
  variables: marshalVariables(ctx),
56774
- layer: layer.id
56870
+ layer: layerOptimistic.id
56775
56871
  });
56776
56872
  }
56777
56873
  ctx.cacheParams = {
56778
56874
  ...ctx.cacheParams,
56779
- layer,
56875
+ layer: layerOptimistic,
56780
56876
  notifySubscribers: toNotify,
56781
56877
  forceNotify: true
56782
56878
  };
56783
56879
  next(ctx);
56784
56880
  },
56785
56881
  afterNetwork(ctx, { resolve: resolve2 }) {
56786
- ctx.cacheParams?.layer?.clear();
56882
+ if (ctx.cacheParams?.layer) {
56883
+ cache_default.clearLayer(ctx.cacheParams.layer.id);
56884
+ }
56787
56885
  resolve2(ctx);
56788
56886
  },
56789
56887
  end(ctx, { resolve: resolve2, value }) {
56790
56888
  const hasErrors = value.errors && value.errors.length > 0;
56791
56889
  if (hasErrors) {
56792
- ctx.cacheParams?.layer?.clear();
56890
+ if (ctx.cacheParams?.layer) {
56891
+ cache_default.clearLayer(ctx.cacheParams.layer.id);
56892
+ }
56793
56893
  }
56794
56894
  if (ctx.cacheParams?.layer) {
56795
56895
  cache_default._internal_unstable.storage.resolveLayer(ctx.cacheParams.layer.id);
@@ -56799,7 +56899,7 @@ var mutation = documentPlugin(ArtifactKind.Mutation, () => {
56799
56899
  catch(ctx, { error }) {
56800
56900
  if (ctx.cacheParams?.layer) {
56801
56901
  const { layer } = ctx.cacheParams;
56802
- layer.clear();
56902
+ cache_default.clearLayer(layer.id);
56803
56903
  cache_default._internal_unstable.storage.resolveLayer(layer.id);
56804
56904
  }
56805
56905
  throw error;
@@ -57590,7 +57690,7 @@ function deepMerge2(filepath, ...targets) {
57590
57690
  }
57591
57691
 
57592
57692
  // src/lib/parse.ts
57593
- async function parseJS(str, config2) {
57693
+ function parseJS(str, config2) {
57594
57694
  const defaultConfig = {
57595
57695
  plugins: ["typescript", "importAssertions"],
57596
57696
  sourceType: "module"
@@ -58817,7 +58917,7 @@ function operationObject({
58817
58917
  if (operationKind === "insert" || operationKind === "toggle") {
58818
58918
  operation.position = position;
58819
58919
  }
58820
- if (operationKind === "insert" && allLists) {
58920
+ if (allLists && operationKind !== "delete") {
58821
58921
  operation.target = "all";
58822
58922
  }
58823
58923
  if (parentID) {
@@ -60653,12 +60753,28 @@ ${exportStatement("config")}
60653
60753
  },
60654
60754
  [path_exports.join(config2.runtimeSource, "client", "plugins", "injectedPlugins.js")]: (content) => injectPlugins({ config: config2, content, importStatement, exportStatement })
60655
60755
  }),
60656
- ...config2.plugins.filter((plugin2) => plugin2.includeRuntime).map((plugin2) => generatePluginRuntime(config2, docs, plugin2)),
60756
+ ...config2.plugins.filter((plugin2) => plugin2.includeRuntime).map(
60757
+ (plugin2) => generatePluginRuntime({
60758
+ config: config2,
60759
+ docs,
60760
+ plugin: plugin2,
60761
+ importStatement,
60762
+ exportDefaultStatement: exportStatement,
60763
+ exportStarStatement: exportStar
60764
+ })
60765
+ ),
60657
60766
  generatePluginIndex({ config: config2, exportStatement: exportStar })
60658
60767
  ]);
60659
60768
  await generateGraphqlReturnTypes(config2, docs);
60660
60769
  }
60661
- async function generatePluginRuntime(config2, docs, plugin2) {
60770
+ async function generatePluginRuntime({
60771
+ config: config2,
60772
+ docs,
60773
+ plugin: plugin2,
60774
+ importStatement,
60775
+ exportDefaultStatement,
60776
+ exportStarStatement
60777
+ }) {
60662
60778
  if (houdini_mode.is_testing || !plugin2.includeRuntime) {
60663
60779
  return;
60664
60780
  }
@@ -60686,7 +60802,13 @@ async function generatePluginRuntime(config2, docs, plugin2) {
60686
60802
  Object.fromEntries(
60687
60803
  Object.entries(transformMap).map(([key, value]) => [
60688
60804
  path_exports.join(runtime_path, key),
60689
- (content) => value({ config: config2, content })
60805
+ (content) => value({
60806
+ config: config2,
60807
+ content,
60808
+ importStatement,
60809
+ exportDefaultStatement,
60810
+ exportStarStatement
60811
+ })
60690
60812
  ])
60691
60813
  )
60692
60814
  );
@@ -62554,14 +62676,12 @@ async function typeCheck(config2, docs) {
62554
62676
  for (const targetType of targetTypes) {
62555
62677
  const missingIDFields = config2.keyFieldsForType(targetType.name).filter((fieldName) => !targetType.getFields()[fieldName]);
62556
62678
  if (missingIDFields.length > 0) {
62557
- const message = `@${config2.listDirective} on ${logGreen(
62558
- targetType.name
62559
- )} as a configuration issue. Object identification missing: ${missingIDFields.map((c) => `"${logYellow(c)}"`).join(", ")}. Check 'Custom IDs' if needed.`;
62560
62679
  errors.push(
62561
62680
  new HoudiniError({
62562
62681
  filepath: filename,
62563
- message,
62564
- description: message
62682
+ message: `@${config2.listDirective} on ${logGreen(
62683
+ targetType.name
62684
+ )} has a configuration issue: ${targetType} dos not have a valid key. Please check this link for more information: https://houdinigraphql.com/guides/caching-data#custom-ids`
62565
62685
  })
62566
62686
  );
62567
62687
  return;