houdini 1.2.1 → 1.2.3

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 (35) hide show
  1. package/build/cmd-cjs/index.js +149 -104
  2. package/build/cmd-esm/index.js +149 -104
  3. package/build/codegen/generators/artifacts/selection.d.ts +2 -1
  4. package/build/codegen/utils/flattenSelections.d.ts +2 -4
  5. package/build/codegen-cjs/index.js +147 -102
  6. package/build/codegen-esm/index.js +147 -102
  7. package/build/lib-cjs/index.js +103 -45
  8. package/build/lib-esm/index.js +103 -45
  9. package/build/runtime/cache/cache.d.ts +3 -1
  10. package/build/runtime/cache/lists.d.ts +3 -3
  11. package/build/runtime/cache/storage.d.ts +2 -2
  12. package/build/runtime/cache/subscription.d.ts +1 -0
  13. package/build/runtime-cjs/cache/cache.d.ts +3 -1
  14. package/build/runtime-cjs/cache/cache.js +78 -27
  15. package/build/runtime-cjs/cache/lists.d.ts +3 -3
  16. package/build/runtime-cjs/cache/lists.js +7 -7
  17. package/build/runtime-cjs/cache/storage.d.ts +2 -2
  18. package/build/runtime-cjs/cache/storage.js +5 -5
  19. package/build/runtime-cjs/cache/subscription.d.ts +1 -0
  20. package/build/runtime-cjs/cache/subscription.js +3 -0
  21. package/build/runtime-cjs/client/plugins/mutation.js +10 -6
  22. package/build/runtime-esm/cache/cache.d.ts +3 -1
  23. package/build/runtime-esm/cache/cache.js +78 -27
  24. package/build/runtime-esm/cache/lists.d.ts +3 -3
  25. package/build/runtime-esm/cache/lists.js +7 -7
  26. package/build/runtime-esm/cache/storage.d.ts +2 -2
  27. package/build/runtime-esm/cache/storage.js +5 -5
  28. package/build/runtime-esm/cache/subscription.d.ts +1 -0
  29. package/build/runtime-esm/cache/subscription.js +3 -0
  30. package/build/runtime-esm/client/plugins/mutation.js +10 -6
  31. package/build/test-cjs/index.js +147 -102
  32. package/build/test-esm/index.js +147 -102
  33. package/build/vite-cjs/index.js +147 -102
  34. package/build/vite-esm/index.js +147 -102
  35. package/package.json +1 -1
@@ -63799,10 +63799,10 @@ var ListManager = class {
63799
63799
  this.lists.get(list.name).get(parentID).lists.push(handler);
63800
63800
  this.listsByField.get(parentID).get(list.key).push(handler);
63801
63801
  }
63802
- removeIDFromAllLists(id) {
63802
+ removeIDFromAllLists(id, layer) {
63803
63803
  for (const fieldMap of this.lists.values()) {
63804
63804
  for (const list of fieldMap.values()) {
63805
- list.removeID(id);
63805
+ list.removeID(id, void 0, layer);
63806
63806
  }
63807
63807
  }
63808
63808
  }
@@ -63959,7 +63959,7 @@ var List = class {
63959
63959
  layer: layer?.id
63960
63960
  });
63961
63961
  }
63962
- removeID(id, variables = {}) {
63962
+ removeID(id, variables = {}, layer) {
63963
63963
  if (!this.validateWhen()) {
63964
63964
  return;
63965
63965
  }
@@ -64006,7 +64006,7 @@ var List = class {
64006
64006
  subscribers.map((sub) => sub[0]),
64007
64007
  variables
64008
64008
  );
64009
- this.cache._internal_unstable.storage.remove(parentID, targetKey, targetID);
64009
+ this.cache._internal_unstable.storage.remove(parentID, targetKey, targetID, layer);
64010
64010
  for (const [spec] of subscribers) {
64011
64011
  spec.set(
64012
64012
  this.cache._internal_unstable.getSelection({
@@ -64019,12 +64019,12 @@ var List = class {
64019
64019
  }
64020
64020
  return true;
64021
64021
  }
64022
- remove(data, variables = {}) {
64022
+ remove(data, variables = {}, layer) {
64023
64023
  const targetID = this.cache._internal_unstable.id(this.listType(data), data);
64024
64024
  if (!targetID) {
64025
64025
  return;
64026
64026
  }
64027
- return this.removeID(targetID, variables);
64027
+ return this.removeID(targetID, variables, layer);
64028
64028
  }
64029
64029
  listType(data) {
64030
64030
  return data.__typename || this.type;
@@ -64056,7 +64056,7 @@ var List = class {
64056
64056
  layer,
64057
64057
  where
64058
64058
  }) {
64059
- if (!this.remove(data, variables)) {
64059
+ if (!this.remove(data, variables, layer)) {
64060
64060
  this.addToList(selection, data, variables, where, layer);
64061
64061
  }
64062
64062
  }
@@ -64193,7 +64193,7 @@ var StaleManager = class {
64193
64193
  // src/runtime/cache/storage.ts
64194
64194
  var InMemoryStorage = class {
64195
64195
  data;
64196
- idCount = 0;
64196
+ idCount = 1;
64197
64197
  rank = 0;
64198
64198
  constructor() {
64199
64199
  this.data = [];
@@ -64213,11 +64213,11 @@ var InMemoryStorage = class {
64213
64213
  insert(id, field, location, target) {
64214
64214
  return this.topLayer.insert(id, field, location, target);
64215
64215
  }
64216
- remove(id, field, target) {
64217
- return this.topLayer.remove(id, field, target);
64216
+ remove(id, field, target, layerToUser = this.topLayer) {
64217
+ return layerToUser.remove(id, field, target);
64218
64218
  }
64219
- delete(id) {
64220
- return this.topLayer.delete(id);
64219
+ delete(id, layerToUser = this.topLayer) {
64220
+ return layerToUser.delete(id);
64221
64221
  }
64222
64222
  deleteField(id, field) {
64223
64223
  return this.topLayer.deleteField(id, field);
@@ -64589,6 +64589,9 @@ var InMemorySubscriptions = class {
64589
64589
  subscribers = {};
64590
64590
  referenceCounts = {};
64591
64591
  keyVersions = {};
64592
+ activeFields(parent) {
64593
+ return Object.keys(this.subscribers[parent] || {});
64594
+ }
64592
64595
  add({
64593
64596
  parent,
64594
64597
  spec,
@@ -64857,20 +64860,7 @@ var Cache = class {
64857
64860
  }) {
64858
64861
  const layer = layerID ? this._internal_unstable.storage.getLayer(layerID) : this._internal_unstable.storage.topLayer;
64859
64862
  const subscribers = this._internal_unstable.writeSelection({ ...args, layer }).map((sub) => sub[0]);
64860
- const notified = [];
64861
- for (const spec of subscribers.concat(notifySubscribers)) {
64862
- if (!notified.includes(spec.set)) {
64863
- notified.push(spec.set);
64864
- spec.set(
64865
- this._internal_unstable.getSelection({
64866
- parent: spec.parentID || rootID,
64867
- selection: spec.selection,
64868
- variables: spec.variables?.() || {},
64869
- ignoreMasking: false
64870
- }).data
64871
- );
64872
- }
64873
- }
64863
+ this.#notifySubscribers(subscribers.concat(notifySubscribers));
64874
64864
  return subscribers;
64875
64865
  }
64876
64866
  read(...args) {
@@ -64909,10 +64899,10 @@ var Cache = class {
64909
64899
  }
64910
64900
  return handler;
64911
64901
  }
64912
- delete(id) {
64902
+ delete(id, layer) {
64913
64903
  this._internal_unstable.subscriptions.removeAllSubscribers(id);
64914
- this._internal_unstable.lists.removeIDFromAllLists(id);
64915
- this._internal_unstable.storage.delete(id);
64904
+ this._internal_unstable.lists.removeIDFromAllLists(id, layer);
64905
+ this._internal_unstable.storage.delete(id, layer);
64916
64906
  }
64917
64907
  setConfig(config) {
64918
64908
  this._internal_unstable.setConfig(config);
@@ -64944,6 +64934,70 @@ var Cache = class {
64944
64934
  config() {
64945
64935
  return this._internal_unstable.config;
64946
64936
  }
64937
+ clearLayer(layerID) {
64938
+ const layer = this._internal_unstable.storage.getLayer(layerID);
64939
+ if (!layer) {
64940
+ throw new Error("Cannot find layer with id: " + layerID);
64941
+ }
64942
+ const toNotify = [];
64943
+ const allFields = [];
64944
+ for (const target of [layer.fields, layer.links]) {
64945
+ for (const [id, fields] of Object.entries(target)) {
64946
+ allFields.push(
64947
+ ...Object.entries(fields).map(([field, value]) => ({ id, field, value }))
64948
+ );
64949
+ }
64950
+ }
64951
+ const displayFields = [];
64952
+ for (const pair of allFields) {
64953
+ const { displayLayers } = this._internal_unstable.storage.get(pair.id, pair.field);
64954
+ if (!displayLayers.includes(layerID)) {
64955
+ continue;
64956
+ }
64957
+ displayFields.push(pair);
64958
+ }
64959
+ for (const [id, operation] of Object.entries(layer.operations)) {
64960
+ if (operation.deleted) {
64961
+ displayFields.push(
64962
+ ...this._internal_unstable.subscriptions.activeFields(id).map((field) => ({ id, field }))
64963
+ );
64964
+ }
64965
+ const fields = Object.keys(operation.fields ?? {});
64966
+ if (fields.length > 0) {
64967
+ displayFields.push(...fields.map((field) => ({ id, field })));
64968
+ }
64969
+ }
64970
+ layer.clear();
64971
+ for (const display of displayFields) {
64972
+ const { field, id } = display;
64973
+ const notify = !("value" in display) || this._internal_unstable.storage.get(id, field).value !== display.value;
64974
+ if (notify) {
64975
+ toNotify.push(
64976
+ ...this._internal_unstable.subscriptions.get(id, field).map((sub) => sub[0])
64977
+ );
64978
+ }
64979
+ }
64980
+ this.#notifySubscribers(toNotify);
64981
+ }
64982
+ #notifySubscribers(subs) {
64983
+ if (subs.length === 0) {
64984
+ return;
64985
+ }
64986
+ const notified = [];
64987
+ for (const spec of subs) {
64988
+ if (!notified.includes(spec.set)) {
64989
+ notified.push(spec.set);
64990
+ spec.set(
64991
+ this._internal_unstable.getSelection({
64992
+ parent: spec.parentID || rootID,
64993
+ selection: spec.selection,
64994
+ variables: spec.variables?.() || {},
64995
+ ignoreMasking: false
64996
+ }).data
64997
+ );
64998
+ }
64999
+ }
65000
+ }
64947
65001
  };
64948
65002
  var CacheInternal = class {
64949
65003
  _disabled = false;
@@ -65231,8 +65285,16 @@ var CacheInternal = class {
65231
65285
  operation.position || "last",
65232
65286
  layer
65233
65287
  );
65288
+ } else if (operation.action === "toggle" && target instanceof Object && fieldSelection && operation.list) {
65289
+ this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).toggleElement({
65290
+ selection: fieldSelection,
65291
+ data: target,
65292
+ variables,
65293
+ where: operation.position || "last",
65294
+ layer
65295
+ });
65234
65296
  } else if (operation.action === "remove" && target instanceof Object && fieldSelection && operation.list) {
65235
- this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).remove(target, variables);
65297
+ this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).remove(target, variables, layer);
65236
65298
  } else if (operation.action === "delete" && operation.type) {
65237
65299
  if (typeof target !== "string") {
65238
65300
  throw new Error("Cannot delete a record with a non-string ID");
@@ -65241,15 +65303,7 @@ var CacheInternal = class {
65241
65303
  if (!targetID) {
65242
65304
  continue;
65243
65305
  }
65244
- this.cache.delete(targetID);
65245
- } else if (operation.action === "toggle" && target instanceof Object && fieldSelection && operation.list) {
65246
- this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).toggleElement({
65247
- selection: fieldSelection,
65248
- data: target,
65249
- variables,
65250
- where: operation.position || "last",
65251
- layer
65252
- });
65306
+ this.cache.delete(targetID, layer);
65253
65307
  }
65254
65308
  }
65255
65309
  }
@@ -65875,7 +65929,7 @@ var fragment = documentPlugin(ArtifactKind.Fragment, function() {
65875
65929
  var mutation = documentPlugin(ArtifactKind.Mutation, () => {
65876
65930
  return {
65877
65931
  async start(ctx, { next, marshalVariables: marshalVariables2 }) {
65878
- const layer = cache_default._internal_unstable.storage.createLayer(true);
65932
+ const layerOptimistic = cache_default._internal_unstable.storage.createLayer(true);
65879
65933
  const optimisticResponse = ctx.stuff.optimisticResponse;
65880
65934
  let toNotify = [];
65881
65935
  if (optimisticResponse) {
@@ -65886,25 +65940,29 @@ var mutation = documentPlugin(ArtifactKind.Mutation, () => {
65886
65940
  data: optimisticResponse
65887
65941
  }),
65888
65942
  variables: marshalVariables2(ctx),
65889
- layer: layer.id
65943
+ layer: layerOptimistic.id
65890
65944
  });
65891
65945
  }
65892
65946
  ctx.cacheParams = {
65893
65947
  ...ctx.cacheParams,
65894
- layer,
65948
+ layer: layerOptimistic,
65895
65949
  notifySubscribers: toNotify,
65896
65950
  forceNotify: true
65897
65951
  };
65898
65952
  next(ctx);
65899
65953
  },
65900
65954
  afterNetwork(ctx, { resolve: resolve2 }) {
65901
- ctx.cacheParams?.layer?.clear();
65955
+ if (ctx.cacheParams?.layer) {
65956
+ cache_default.clearLayer(ctx.cacheParams.layer.id);
65957
+ }
65902
65958
  resolve2(ctx);
65903
65959
  },
65904
65960
  end(ctx, { resolve: resolve2, value }) {
65905
65961
  const hasErrors = value.errors && value.errors.length > 0;
65906
65962
  if (hasErrors) {
65907
- ctx.cacheParams?.layer?.clear();
65963
+ if (ctx.cacheParams?.layer) {
65964
+ cache_default.clearLayer(ctx.cacheParams.layer.id);
65965
+ }
65908
65966
  }
65909
65967
  if (ctx.cacheParams?.layer) {
65910
65968
  cache_default._internal_unstable.storage.resolveLayer(ctx.cacheParams.layer.id);
@@ -65914,7 +65972,7 @@ var mutation = documentPlugin(ArtifactKind.Mutation, () => {
65914
65972
  catch(ctx, { error }) {
65915
65973
  if (ctx.cacheParams?.layer) {
65916
65974
  const { layer } = ctx.cacheParams;
65917
- layer.clear();
65975
+ cache_default.clearLayer(layer.id);
65918
65976
  cache_default._internal_unstable.storage.resolveLayer(layer.id);
65919
65977
  }
65920
65978
  throw error;
@@ -63741,10 +63741,10 @@ var ListManager = class {
63741
63741
  this.lists.get(list.name).get(parentID).lists.push(handler);
63742
63742
  this.listsByField.get(parentID).get(list.key).push(handler);
63743
63743
  }
63744
- removeIDFromAllLists(id) {
63744
+ removeIDFromAllLists(id, layer) {
63745
63745
  for (const fieldMap of this.lists.values()) {
63746
63746
  for (const list of fieldMap.values()) {
63747
- list.removeID(id);
63747
+ list.removeID(id, void 0, layer);
63748
63748
  }
63749
63749
  }
63750
63750
  }
@@ -63901,7 +63901,7 @@ var List = class {
63901
63901
  layer: layer?.id
63902
63902
  });
63903
63903
  }
63904
- removeID(id, variables = {}) {
63904
+ removeID(id, variables = {}, layer) {
63905
63905
  if (!this.validateWhen()) {
63906
63906
  return;
63907
63907
  }
@@ -63948,7 +63948,7 @@ var List = class {
63948
63948
  subscribers.map((sub) => sub[0]),
63949
63949
  variables
63950
63950
  );
63951
- this.cache._internal_unstable.storage.remove(parentID, targetKey, targetID);
63951
+ this.cache._internal_unstable.storage.remove(parentID, targetKey, targetID, layer);
63952
63952
  for (const [spec] of subscribers) {
63953
63953
  spec.set(
63954
63954
  this.cache._internal_unstable.getSelection({
@@ -63961,12 +63961,12 @@ var List = class {
63961
63961
  }
63962
63962
  return true;
63963
63963
  }
63964
- remove(data, variables = {}) {
63964
+ remove(data, variables = {}, layer) {
63965
63965
  const targetID = this.cache._internal_unstable.id(this.listType(data), data);
63966
63966
  if (!targetID) {
63967
63967
  return;
63968
63968
  }
63969
- return this.removeID(targetID, variables);
63969
+ return this.removeID(targetID, variables, layer);
63970
63970
  }
63971
63971
  listType(data) {
63972
63972
  return data.__typename || this.type;
@@ -63998,7 +63998,7 @@ var List = class {
63998
63998
  layer,
63999
63999
  where
64000
64000
  }) {
64001
- if (!this.remove(data, variables)) {
64001
+ if (!this.remove(data, variables, layer)) {
64002
64002
  this.addToList(selection, data, variables, where, layer);
64003
64003
  }
64004
64004
  }
@@ -64135,7 +64135,7 @@ var StaleManager = class {
64135
64135
  // src/runtime/cache/storage.ts
64136
64136
  var InMemoryStorage = class {
64137
64137
  data;
64138
- idCount = 0;
64138
+ idCount = 1;
64139
64139
  rank = 0;
64140
64140
  constructor() {
64141
64141
  this.data = [];
@@ -64155,11 +64155,11 @@ var InMemoryStorage = class {
64155
64155
  insert(id, field, location, target) {
64156
64156
  return this.topLayer.insert(id, field, location, target);
64157
64157
  }
64158
- remove(id, field, target) {
64159
- return this.topLayer.remove(id, field, target);
64158
+ remove(id, field, target, layerToUser = this.topLayer) {
64159
+ return layerToUser.remove(id, field, target);
64160
64160
  }
64161
- delete(id) {
64162
- return this.topLayer.delete(id);
64161
+ delete(id, layerToUser = this.topLayer) {
64162
+ return layerToUser.delete(id);
64163
64163
  }
64164
64164
  deleteField(id, field) {
64165
64165
  return this.topLayer.deleteField(id, field);
@@ -64531,6 +64531,9 @@ var InMemorySubscriptions = class {
64531
64531
  subscribers = {};
64532
64532
  referenceCounts = {};
64533
64533
  keyVersions = {};
64534
+ activeFields(parent) {
64535
+ return Object.keys(this.subscribers[parent] || {});
64536
+ }
64534
64537
  add({
64535
64538
  parent,
64536
64539
  spec,
@@ -64799,20 +64802,7 @@ var Cache = class {
64799
64802
  }) {
64800
64803
  const layer = layerID ? this._internal_unstable.storage.getLayer(layerID) : this._internal_unstable.storage.topLayer;
64801
64804
  const subscribers = this._internal_unstable.writeSelection({ ...args, layer }).map((sub) => sub[0]);
64802
- const notified = [];
64803
- for (const spec of subscribers.concat(notifySubscribers)) {
64804
- if (!notified.includes(spec.set)) {
64805
- notified.push(spec.set);
64806
- spec.set(
64807
- this._internal_unstable.getSelection({
64808
- parent: spec.parentID || rootID,
64809
- selection: spec.selection,
64810
- variables: spec.variables?.() || {},
64811
- ignoreMasking: false
64812
- }).data
64813
- );
64814
- }
64815
- }
64805
+ this.#notifySubscribers(subscribers.concat(notifySubscribers));
64816
64806
  return subscribers;
64817
64807
  }
64818
64808
  read(...args) {
@@ -64851,10 +64841,10 @@ var Cache = class {
64851
64841
  }
64852
64842
  return handler;
64853
64843
  }
64854
- delete(id) {
64844
+ delete(id, layer) {
64855
64845
  this._internal_unstable.subscriptions.removeAllSubscribers(id);
64856
- this._internal_unstable.lists.removeIDFromAllLists(id);
64857
- this._internal_unstable.storage.delete(id);
64846
+ this._internal_unstable.lists.removeIDFromAllLists(id, layer);
64847
+ this._internal_unstable.storage.delete(id, layer);
64858
64848
  }
64859
64849
  setConfig(config) {
64860
64850
  this._internal_unstable.setConfig(config);
@@ -64886,6 +64876,70 @@ var Cache = class {
64886
64876
  config() {
64887
64877
  return this._internal_unstable.config;
64888
64878
  }
64879
+ clearLayer(layerID) {
64880
+ const layer = this._internal_unstable.storage.getLayer(layerID);
64881
+ if (!layer) {
64882
+ throw new Error("Cannot find layer with id: " + layerID);
64883
+ }
64884
+ const toNotify = [];
64885
+ const allFields = [];
64886
+ for (const target of [layer.fields, layer.links]) {
64887
+ for (const [id, fields] of Object.entries(target)) {
64888
+ allFields.push(
64889
+ ...Object.entries(fields).map(([field, value]) => ({ id, field, value }))
64890
+ );
64891
+ }
64892
+ }
64893
+ const displayFields = [];
64894
+ for (const pair of allFields) {
64895
+ const { displayLayers } = this._internal_unstable.storage.get(pair.id, pair.field);
64896
+ if (!displayLayers.includes(layerID)) {
64897
+ continue;
64898
+ }
64899
+ displayFields.push(pair);
64900
+ }
64901
+ for (const [id, operation] of Object.entries(layer.operations)) {
64902
+ if (operation.deleted) {
64903
+ displayFields.push(
64904
+ ...this._internal_unstable.subscriptions.activeFields(id).map((field) => ({ id, field }))
64905
+ );
64906
+ }
64907
+ const fields = Object.keys(operation.fields ?? {});
64908
+ if (fields.length > 0) {
64909
+ displayFields.push(...fields.map((field) => ({ id, field })));
64910
+ }
64911
+ }
64912
+ layer.clear();
64913
+ for (const display of displayFields) {
64914
+ const { field, id } = display;
64915
+ const notify = !("value" in display) || this._internal_unstable.storage.get(id, field).value !== display.value;
64916
+ if (notify) {
64917
+ toNotify.push(
64918
+ ...this._internal_unstable.subscriptions.get(id, field).map((sub) => sub[0])
64919
+ );
64920
+ }
64921
+ }
64922
+ this.#notifySubscribers(toNotify);
64923
+ }
64924
+ #notifySubscribers(subs) {
64925
+ if (subs.length === 0) {
64926
+ return;
64927
+ }
64928
+ const notified = [];
64929
+ for (const spec of subs) {
64930
+ if (!notified.includes(spec.set)) {
64931
+ notified.push(spec.set);
64932
+ spec.set(
64933
+ this._internal_unstable.getSelection({
64934
+ parent: spec.parentID || rootID,
64935
+ selection: spec.selection,
64936
+ variables: spec.variables?.() || {},
64937
+ ignoreMasking: false
64938
+ }).data
64939
+ );
64940
+ }
64941
+ }
64942
+ }
64889
64943
  };
64890
64944
  var CacheInternal = class {
64891
64945
  _disabled = false;
@@ -65173,8 +65227,16 @@ var CacheInternal = class {
65173
65227
  operation.position || "last",
65174
65228
  layer
65175
65229
  );
65230
+ } else if (operation.action === "toggle" && target instanceof Object && fieldSelection && operation.list) {
65231
+ this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).toggleElement({
65232
+ selection: fieldSelection,
65233
+ data: target,
65234
+ variables,
65235
+ where: operation.position || "last",
65236
+ layer
65237
+ });
65176
65238
  } else if (operation.action === "remove" && target instanceof Object && fieldSelection && operation.list) {
65177
- this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).remove(target, variables);
65239
+ this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).remove(target, variables, layer);
65178
65240
  } else if (operation.action === "delete" && operation.type) {
65179
65241
  if (typeof target !== "string") {
65180
65242
  throw new Error("Cannot delete a record with a non-string ID");
@@ -65183,15 +65245,7 @@ var CacheInternal = class {
65183
65245
  if (!targetID) {
65184
65246
  continue;
65185
65247
  }
65186
- this.cache.delete(targetID);
65187
- } else if (operation.action === "toggle" && target instanceof Object && fieldSelection && operation.list) {
65188
- this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).toggleElement({
65189
- selection: fieldSelection,
65190
- data: target,
65191
- variables,
65192
- where: operation.position || "last",
65193
- layer
65194
- });
65248
+ this.cache.delete(targetID, layer);
65195
65249
  }
65196
65250
  }
65197
65251
  }
@@ -65817,7 +65871,7 @@ var fragment = documentPlugin(ArtifactKind.Fragment, function() {
65817
65871
  var mutation = documentPlugin(ArtifactKind.Mutation, () => {
65818
65872
  return {
65819
65873
  async start(ctx, { next, marshalVariables: marshalVariables2 }) {
65820
- const layer = cache_default._internal_unstable.storage.createLayer(true);
65874
+ const layerOptimistic = cache_default._internal_unstable.storage.createLayer(true);
65821
65875
  const optimisticResponse = ctx.stuff.optimisticResponse;
65822
65876
  let toNotify = [];
65823
65877
  if (optimisticResponse) {
@@ -65828,25 +65882,29 @@ var mutation = documentPlugin(ArtifactKind.Mutation, () => {
65828
65882
  data: optimisticResponse
65829
65883
  }),
65830
65884
  variables: marshalVariables2(ctx),
65831
- layer: layer.id
65885
+ layer: layerOptimistic.id
65832
65886
  });
65833
65887
  }
65834
65888
  ctx.cacheParams = {
65835
65889
  ...ctx.cacheParams,
65836
- layer,
65890
+ layer: layerOptimistic,
65837
65891
  notifySubscribers: toNotify,
65838
65892
  forceNotify: true
65839
65893
  };
65840
65894
  next(ctx);
65841
65895
  },
65842
65896
  afterNetwork(ctx, { resolve: resolve2 }) {
65843
- ctx.cacheParams?.layer?.clear();
65897
+ if (ctx.cacheParams?.layer) {
65898
+ cache_default.clearLayer(ctx.cacheParams.layer.id);
65899
+ }
65844
65900
  resolve2(ctx);
65845
65901
  },
65846
65902
  end(ctx, { resolve: resolve2, value }) {
65847
65903
  const hasErrors = value.errors && value.errors.length > 0;
65848
65904
  if (hasErrors) {
65849
- ctx.cacheParams?.layer?.clear();
65905
+ if (ctx.cacheParams?.layer) {
65906
+ cache_default.clearLayer(ctx.cacheParams.layer.id);
65907
+ }
65850
65908
  }
65851
65909
  if (ctx.cacheParams?.layer) {
65852
65910
  cache_default._internal_unstable.storage.resolveLayer(ctx.cacheParams.layer.id);
@@ -65856,7 +65914,7 @@ var mutation = documentPlugin(ArtifactKind.Mutation, () => {
65856
65914
  catch(ctx, { error }) {
65857
65915
  if (ctx.cacheParams?.layer) {
65858
65916
  const { layer } = ctx.cacheParams;
65859
- layer.clear();
65917
+ cache_default.clearLayer(layer.id);
65860
65918
  cache_default._internal_unstable.storage.resolveLayer(layer.id);
65861
65919
  }
65862
65920
  throw error;
@@ -8,6 +8,7 @@ import type { Layer, LayerID } from './storage';
8
8
  import { InMemoryStorage } from './storage';
9
9
  import { InMemorySubscriptions, type FieldSelection } from './subscription';
10
10
  export declare class Cache {
11
+ #private;
11
12
  _internal_unstable: CacheInternal;
12
13
  constructor({ disabled, ...config }?: ConfigFile & {
13
14
  disabled?: boolean;
@@ -33,7 +34,7 @@ export declare class Cache {
33
34
  subscribe(spec: SubscriptionSpec, variables?: {}): void;
34
35
  unsubscribe(spec: SubscriptionSpec, variables?: {}): void;
35
36
  list(name: string, parentID?: string, allLists?: boolean): ListCollection;
36
- delete(id: string): void;
37
+ delete(id: string, layer?: Layer): void;
37
38
  setConfig(config: ConfigFile): void;
38
39
  markTypeStale(options?: {
39
40
  type: string;
@@ -46,6 +47,7 @@ export declare class Cache {
46
47
  }): void;
47
48
  getFieldTime(id: string, field: string): number | null | undefined;
48
49
  config(): ConfigFile;
50
+ clearLayer(layerID: Layer['id']): void;
49
51
  }
50
52
  declare class CacheInternal {
51
53
  private _disabled;
@@ -21,7 +21,7 @@ export declare class ListManager {
21
21
  filters?: List['filters'];
22
22
  abstract?: boolean;
23
23
  }): void;
24
- removeIDFromAllLists(id: string): void;
24
+ removeIDFromAllLists(id: string, layer?: Layer): void;
25
25
  deleteField(parentID: string, field: string): void;
26
26
  }
27
27
  export declare class List {
@@ -54,8 +54,8 @@ export declare class List {
54
54
  layer?: Layer;
55
55
  }): void;
56
56
  addToList(selection: SubscriptionSelection, data: {}, variables: {} | undefined, where: 'first' | 'last', layer?: Layer): void;
57
- removeID(id: string, variables?: {}): true | undefined;
58
- remove(data: {}, variables?: {}): true | undefined;
57
+ removeID(id: string, variables?: {}, layer?: Layer): true | undefined;
58
+ remove(data: {}, variables?: {}, layer?: Layer): true | undefined;
59
59
  listType(data: {
60
60
  __typename?: string;
61
61
  }): string;
@@ -8,8 +8,8 @@ export declare class InMemoryStorage {
8
8
  get nextRank(): number;
9
9
  createLayer(optimistic?: boolean): Layer;
10
10
  insert(id: string, field: string, location: OperationLocations, target: string): void;
11
- remove(id: string, field: string, target: string): void;
12
- delete(id: string): void;
11
+ remove(id: string, field: string, target: string, layerToUser?: Layer): void;
12
+ delete(id: string, layerToUser?: Layer): void;
13
13
  deleteField(id: string, field: string): void;
14
14
  getLayer(id: number): Layer;
15
15
  replaceID(replacement: {
@@ -10,6 +10,7 @@ export declare class InMemorySubscriptions {
10
10
  private subscribers;
11
11
  private referenceCounts;
12
12
  private keyVersions;
13
+ activeFields(parent: string): string[];
13
14
  add({ parent, spec, selection, variables, parentType, }: {
14
15
  parent: string;
15
16
  parentType?: string;
@@ -8,6 +8,7 @@ import type { Layer, LayerID } from './storage';
8
8
  import { InMemoryStorage } from './storage';
9
9
  import { InMemorySubscriptions, type FieldSelection } from './subscription';
10
10
  export declare class Cache {
11
+ #private;
11
12
  _internal_unstable: CacheInternal;
12
13
  constructor({ disabled, ...config }?: ConfigFile & {
13
14
  disabled?: boolean;
@@ -33,7 +34,7 @@ export declare class Cache {
33
34
  subscribe(spec: SubscriptionSpec, variables?: {}): void;
34
35
  unsubscribe(spec: SubscriptionSpec, variables?: {}): void;
35
36
  list(name: string, parentID?: string, allLists?: boolean): ListCollection;
36
- delete(id: string): void;
37
+ delete(id: string, layer?: Layer): void;
37
38
  setConfig(config: ConfigFile): void;
38
39
  markTypeStale(options?: {
39
40
  type: string;
@@ -46,6 +47,7 @@ export declare class Cache {
46
47
  }): void;
47
48
  getFieldTime(id: string, field: string): number | null | undefined;
48
49
  config(): ConfigFile;
50
+ clearLayer(layerID: Layer['id']): void;
49
51
  }
50
52
  declare class CacheInternal {
51
53
  private _disabled;