houdini-svelte 2.2.0-next.2 → 2.2.0-next.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.
@@ -87144,20 +87144,21 @@ var CacheInternal = class {
87144
87144
  } else if (Array.isArray(value) && // make typescript happy
87145
87145
  (typeof previousValue === "undefined" || previousValue === null || Array.isArray(previousValue))) {
87146
87146
  let oldIDs = [...previousValue || []];
87147
- const emptyEdges = !updates ? [] : oldIDs.map((id) => {
87148
- if (!id) {
87149
- return "";
87150
- }
87151
- const { value: cursorField } = this.storage.get(id, "cursor");
87152
- if (cursorField) {
87153
- return "";
87154
- }
87155
- const { value: node } = this.storage.get(id, "node");
87156
- if (!node) {
87157
- return "";
87158
- }
87159
- return node;
87160
- });
87147
+ if (updates?.includes("append") || updates?.includes("prepend")) {
87148
+ oldIDs = oldIDs.filter((id) => {
87149
+ for (const layer2 of this.storage.data) {
87150
+ for (const operation of Object.values(layer2.operations)) {
87151
+ if (operation.fields?.[key])
87152
+ for (const listOperation of operation.fields[key]) {
87153
+ if ("id" in listOperation && listOperation.id === id) {
87154
+ return false;
87155
+ }
87156
+ }
87157
+ }
87158
+ }
87159
+ return true;
87160
+ });
87161
+ }
87161
87162
  let linkedIDs = [];
87162
87163
  const { newIDs, nestedIDs } = this.extractNestedListIDs({
87163
87164
  value,
@@ -87176,39 +87177,45 @@ var CacheInternal = class {
87176
87177
  layer.writeLink(parent2, key, linkedIDs);
87177
87178
  };
87178
87179
  if (applyUpdates && updates) {
87179
- if (key === "edges") {
87180
- const newNodeIDs = [];
87181
- for (const id of newIDs) {
87180
+ const filterIDs = (keep, insert) => {
87181
+ const existingIDs = /* @__PURE__ */ new Set();
87182
+ for (const id of keep) {
87182
87183
  if (!id) {
87183
87184
  continue;
87184
87185
  }
87185
87186
  const { value: node } = this.storage.get(id, "node");
87186
- if (typeof node !== "string") {
87187
+ if (!node) {
87187
87188
  continue;
87188
87189
  }
87189
- if (!node || !this.storage.get(node, "__typename")) {
87190
+ const nodeID = this.storage.get(node, "id");
87191
+ if (!nodeID) {
87190
87192
  continue;
87191
87193
  }
87192
- newNodeIDs.push(node);
87194
+ existingIDs.add(nodeID.value);
87193
87195
  }
87194
- oldIDs = oldIDs.filter((id) => {
87196
+ return insert.filter((id) => {
87195
87197
  if (!id) {
87196
87198
  return true;
87197
87199
  }
87198
- const { value: value2 } = this.storage.get(id, "node");
87199
- const node = value2;
87200
- if (newNodeIDs.includes(node) && emptyEdges.includes(node)) {
87201
- return false;
87200
+ const { value: node } = this.storage.get(id, "node");
87201
+ if (!node) {
87202
+ return true;
87202
87203
  }
87203
- return true;
87204
+ const nodeID = this.storage.get(node, "id");
87205
+ if (!nodeID) {
87206
+ return true;
87207
+ }
87208
+ return !existingIDs.has(nodeID.value);
87204
87209
  });
87205
- }
87210
+ };
87206
87211
  for (const update of applyUpdates) {
87207
87212
  if (update !== "replace" && !updates.includes(update)) {
87208
87213
  continue;
87209
87214
  }
87210
87215
  if (update === "prepend") {
87211
- linkedIDs = newIDs.concat(oldIDs);
87216
+ linkedIDs = newIDs.concat(
87217
+ filterIDs(newIDs, oldIDs)
87218
+ );
87212
87219
  if (layer?.optimistic) {
87213
87220
  action = () => {
87214
87221
  for (const id of newIDs) {
@@ -87219,7 +87226,7 @@ var CacheInternal = class {
87219
87226
  };
87220
87227
  }
87221
87228
  } else if (update === "append") {
87222
- linkedIDs = oldIDs.concat(newIDs);
87229
+ linkedIDs = filterIDs(newIDs, oldIDs).concat(newIDs);
87223
87230
  if (layer?.optimistic) {
87224
87231
  action = () => {
87225
87232
  for (const id of newIDs) {
@@ -158920,20 +158927,21 @@ var CacheInternal2 = class {
158920
158927
  } else if (Array.isArray(value) && // make typescript happy
158921
158928
  (typeof previousValue === "undefined" || previousValue === null || Array.isArray(previousValue))) {
158922
158929
  let oldIDs = [...previousValue || []];
158923
- const emptyEdges = !updates ? [] : oldIDs.map((id) => {
158924
- if (!id) {
158925
- return "";
158926
- }
158927
- const { value: cursorField } = this.storage.get(id, "cursor");
158928
- if (cursorField) {
158929
- return "";
158930
- }
158931
- const { value: node } = this.storage.get(id, "node");
158932
- if (!node) {
158933
- return "";
158934
- }
158935
- return node;
158936
- });
158930
+ if (updates?.includes("append") || updates?.includes("prepend")) {
158931
+ oldIDs = oldIDs.filter((id) => {
158932
+ for (const layer2 of this.storage.data) {
158933
+ for (const operation of Object.values(layer2.operations)) {
158934
+ if (operation.fields?.[key])
158935
+ for (const listOperation of operation.fields[key]) {
158936
+ if ("id" in listOperation && listOperation.id === id) {
158937
+ return false;
158938
+ }
158939
+ }
158940
+ }
158941
+ }
158942
+ return true;
158943
+ });
158944
+ }
158937
158945
  let linkedIDs = [];
158938
158946
  const { newIDs, nestedIDs } = this.extractNestedListIDs({
158939
158947
  value,
@@ -158952,39 +158960,45 @@ var CacheInternal2 = class {
158952
158960
  layer.writeLink(parent2, key, linkedIDs);
158953
158961
  };
158954
158962
  if (applyUpdates && updates) {
158955
- if (key === "edges") {
158956
- const newNodeIDs = [];
158957
- for (const id of newIDs) {
158963
+ const filterIDs = (keep, insert) => {
158964
+ const existingIDs = /* @__PURE__ */ new Set();
158965
+ for (const id of keep) {
158958
158966
  if (!id) {
158959
158967
  continue;
158960
158968
  }
158961
158969
  const { value: node } = this.storage.get(id, "node");
158962
- if (typeof node !== "string") {
158970
+ if (!node) {
158963
158971
  continue;
158964
158972
  }
158965
- if (!node || !this.storage.get(node, "__typename")) {
158973
+ const nodeID = this.storage.get(node, "id");
158974
+ if (!nodeID) {
158966
158975
  continue;
158967
158976
  }
158968
- newNodeIDs.push(node);
158977
+ existingIDs.add(nodeID.value);
158969
158978
  }
158970
- oldIDs = oldIDs.filter((id) => {
158979
+ return insert.filter((id) => {
158971
158980
  if (!id) {
158972
158981
  return true;
158973
158982
  }
158974
- const { value: value2 } = this.storage.get(id, "node");
158975
- const node = value2;
158976
- if (newNodeIDs.includes(node) && emptyEdges.includes(node)) {
158977
- return false;
158983
+ const { value: node } = this.storage.get(id, "node");
158984
+ if (!node) {
158985
+ return true;
158978
158986
  }
158979
- return true;
158987
+ const nodeID = this.storage.get(node, "id");
158988
+ if (!nodeID) {
158989
+ return true;
158990
+ }
158991
+ return !existingIDs.has(nodeID.value);
158980
158992
  });
158981
- }
158993
+ };
158982
158994
  for (const update of applyUpdates) {
158983
158995
  if (update !== "replace" && !updates.includes(update)) {
158984
158996
  continue;
158985
158997
  }
158986
158998
  if (update === "prepend") {
158987
- linkedIDs = newIDs.concat(oldIDs);
158999
+ linkedIDs = newIDs.concat(
159000
+ filterIDs(newIDs, oldIDs)
159001
+ );
158988
159002
  if (layer?.optimistic) {
158989
159003
  action = () => {
158990
159004
  for (const id of newIDs) {
@@ -158995,7 +159009,7 @@ var CacheInternal2 = class {
158995
159009
  };
158996
159010
  }
158997
159011
  } else if (update === "append") {
158998
- linkedIDs = oldIDs.concat(newIDs);
159012
+ linkedIDs = filterIDs(newIDs, oldIDs).concat(newIDs);
158999
159013
  if (layer?.optimistic) {
159000
159014
  action = () => {
159001
159015
  for (const id of newIDs) {
@@ -161078,9 +161092,7 @@ import type { ${functionImportsToBring.join(
161078
161092
  ", "
161079
161093
  )} } from '${houdiniRelative}/plugins/houdini-svelte/runtime/types';` : "";
161080
161094
  typeImports = typeImports.concat(functionImports).concat(layoutTypeImports).concat(pageTypeImports).concat(componentQueryTypeImports);
161081
- const layoutParams = `${layoutQueries.length > 0 && !utilityTypes.includes("LayoutParams") ? "\ntype LayoutParams = LayoutLoadEvent['params'];" : ""}`;
161082
- const pageParams = `${pageQueries.length > 0 && !utilityTypes.includes("PageParams") ? "\ntype PageParams = PageLoadEvent['params'];" : ""}`;
161083
- utilityTypes = utilityTypes.concat(layoutParams).concat(pageParams).replaceAll(/\$types\.js/gm, "$houdini");
161095
+ utilityTypes = utilityTypes.replaceAll(/\$types\.js/gm, "$houdini");
161084
161096
  typeExports = typeExports.concat(append_loadInput([...layoutQueries, ...pageQueries])).concat(layout_append_beforeLoad).concat(page_append_beforeLoad).concat(layout_append_afterLoad).concat(page_append_afterLoad).concat(layout_append_onError).concat(page_append_onError).concat(layout_append_VariablesFunction).concat(page_append_VariablesFunction).concat(component_append_VariablesFunction).replace(
161085
161097
  //regex to append our generated stores to the existing
161086
161098
  //match all between 'LayoutData =' and ';' and combine additional types
@@ -161165,7 +161177,7 @@ function append_VariablesFunction(type, filepath, config, queries) {
161165
161177
  return `
161166
161178
  export type ${config.variableFunctionName(
161167
161179
  name
161168
- )} = VariableFunction<${type}Params, ${input_type}>;`;
161180
+ )} = VariableFunction<${type}LoadEvent, ${input_type}>;`;
161169
161181
  }).join("\n");
161170
161182
  }
161171
161183
  function append_ComponentVariablesFunction(filepath, config, queries) {
@@ -87140,20 +87140,21 @@ var CacheInternal = class {
87140
87140
  } else if (Array.isArray(value) && // make typescript happy
87141
87141
  (typeof previousValue === "undefined" || previousValue === null || Array.isArray(previousValue))) {
87142
87142
  let oldIDs = [...previousValue || []];
87143
- const emptyEdges = !updates ? [] : oldIDs.map((id) => {
87144
- if (!id) {
87145
- return "";
87146
- }
87147
- const { value: cursorField } = this.storage.get(id, "cursor");
87148
- if (cursorField) {
87149
- return "";
87150
- }
87151
- const { value: node } = this.storage.get(id, "node");
87152
- if (!node) {
87153
- return "";
87154
- }
87155
- return node;
87156
- });
87143
+ if (updates?.includes("append") || updates?.includes("prepend")) {
87144
+ oldIDs = oldIDs.filter((id) => {
87145
+ for (const layer2 of this.storage.data) {
87146
+ for (const operation of Object.values(layer2.operations)) {
87147
+ if (operation.fields?.[key])
87148
+ for (const listOperation of operation.fields[key]) {
87149
+ if ("id" in listOperation && listOperation.id === id) {
87150
+ return false;
87151
+ }
87152
+ }
87153
+ }
87154
+ }
87155
+ return true;
87156
+ });
87157
+ }
87157
87158
  let linkedIDs = [];
87158
87159
  const { newIDs, nestedIDs } = this.extractNestedListIDs({
87159
87160
  value,
@@ -87172,39 +87173,45 @@ var CacheInternal = class {
87172
87173
  layer.writeLink(parent2, key, linkedIDs);
87173
87174
  };
87174
87175
  if (applyUpdates && updates) {
87175
- if (key === "edges") {
87176
- const newNodeIDs = [];
87177
- for (const id of newIDs) {
87176
+ const filterIDs = (keep, insert) => {
87177
+ const existingIDs = /* @__PURE__ */ new Set();
87178
+ for (const id of keep) {
87178
87179
  if (!id) {
87179
87180
  continue;
87180
87181
  }
87181
87182
  const { value: node } = this.storage.get(id, "node");
87182
- if (typeof node !== "string") {
87183
+ if (!node) {
87183
87184
  continue;
87184
87185
  }
87185
- if (!node || !this.storage.get(node, "__typename")) {
87186
+ const nodeID = this.storage.get(node, "id");
87187
+ if (!nodeID) {
87186
87188
  continue;
87187
87189
  }
87188
- newNodeIDs.push(node);
87190
+ existingIDs.add(nodeID.value);
87189
87191
  }
87190
- oldIDs = oldIDs.filter((id) => {
87192
+ return insert.filter((id) => {
87191
87193
  if (!id) {
87192
87194
  return true;
87193
87195
  }
87194
- const { value: value2 } = this.storage.get(id, "node");
87195
- const node = value2;
87196
- if (newNodeIDs.includes(node) && emptyEdges.includes(node)) {
87197
- return false;
87196
+ const { value: node } = this.storage.get(id, "node");
87197
+ if (!node) {
87198
+ return true;
87198
87199
  }
87199
- return true;
87200
+ const nodeID = this.storage.get(node, "id");
87201
+ if (!nodeID) {
87202
+ return true;
87203
+ }
87204
+ return !existingIDs.has(nodeID.value);
87200
87205
  });
87201
- }
87206
+ };
87202
87207
  for (const update of applyUpdates) {
87203
87208
  if (update !== "replace" && !updates.includes(update)) {
87204
87209
  continue;
87205
87210
  }
87206
87211
  if (update === "prepend") {
87207
- linkedIDs = newIDs.concat(oldIDs);
87212
+ linkedIDs = newIDs.concat(
87213
+ filterIDs(newIDs, oldIDs)
87214
+ );
87208
87215
  if (layer?.optimistic) {
87209
87216
  action = () => {
87210
87217
  for (const id of newIDs) {
@@ -87215,7 +87222,7 @@ var CacheInternal = class {
87215
87222
  };
87216
87223
  }
87217
87224
  } else if (update === "append") {
87218
- linkedIDs = oldIDs.concat(newIDs);
87225
+ linkedIDs = filterIDs(newIDs, oldIDs).concat(newIDs);
87219
87226
  if (layer?.optimistic) {
87220
87227
  action = () => {
87221
87228
  for (const id of newIDs) {
@@ -158915,20 +158922,21 @@ var CacheInternal2 = class {
158915
158922
  } else if (Array.isArray(value) && // make typescript happy
158916
158923
  (typeof previousValue === "undefined" || previousValue === null || Array.isArray(previousValue))) {
158917
158924
  let oldIDs = [...previousValue || []];
158918
- const emptyEdges = !updates ? [] : oldIDs.map((id) => {
158919
- if (!id) {
158920
- return "";
158921
- }
158922
- const { value: cursorField } = this.storage.get(id, "cursor");
158923
- if (cursorField) {
158924
- return "";
158925
- }
158926
- const { value: node } = this.storage.get(id, "node");
158927
- if (!node) {
158928
- return "";
158929
- }
158930
- return node;
158931
- });
158925
+ if (updates?.includes("append") || updates?.includes("prepend")) {
158926
+ oldIDs = oldIDs.filter((id) => {
158927
+ for (const layer2 of this.storage.data) {
158928
+ for (const operation of Object.values(layer2.operations)) {
158929
+ if (operation.fields?.[key])
158930
+ for (const listOperation of operation.fields[key]) {
158931
+ if ("id" in listOperation && listOperation.id === id) {
158932
+ return false;
158933
+ }
158934
+ }
158935
+ }
158936
+ }
158937
+ return true;
158938
+ });
158939
+ }
158932
158940
  let linkedIDs = [];
158933
158941
  const { newIDs, nestedIDs } = this.extractNestedListIDs({
158934
158942
  value,
@@ -158947,39 +158955,45 @@ var CacheInternal2 = class {
158947
158955
  layer.writeLink(parent2, key, linkedIDs);
158948
158956
  };
158949
158957
  if (applyUpdates && updates) {
158950
- if (key === "edges") {
158951
- const newNodeIDs = [];
158952
- for (const id of newIDs) {
158958
+ const filterIDs = (keep, insert) => {
158959
+ const existingIDs = /* @__PURE__ */ new Set();
158960
+ for (const id of keep) {
158953
158961
  if (!id) {
158954
158962
  continue;
158955
158963
  }
158956
158964
  const { value: node } = this.storage.get(id, "node");
158957
- if (typeof node !== "string") {
158965
+ if (!node) {
158958
158966
  continue;
158959
158967
  }
158960
- if (!node || !this.storage.get(node, "__typename")) {
158968
+ const nodeID = this.storage.get(node, "id");
158969
+ if (!nodeID) {
158961
158970
  continue;
158962
158971
  }
158963
- newNodeIDs.push(node);
158972
+ existingIDs.add(nodeID.value);
158964
158973
  }
158965
- oldIDs = oldIDs.filter((id) => {
158974
+ return insert.filter((id) => {
158966
158975
  if (!id) {
158967
158976
  return true;
158968
158977
  }
158969
- const { value: value2 } = this.storage.get(id, "node");
158970
- const node = value2;
158971
- if (newNodeIDs.includes(node) && emptyEdges.includes(node)) {
158972
- return false;
158978
+ const { value: node } = this.storage.get(id, "node");
158979
+ if (!node) {
158980
+ return true;
158973
158981
  }
158974
- return true;
158982
+ const nodeID = this.storage.get(node, "id");
158983
+ if (!nodeID) {
158984
+ return true;
158985
+ }
158986
+ return !existingIDs.has(nodeID.value);
158975
158987
  });
158976
- }
158988
+ };
158977
158989
  for (const update of applyUpdates) {
158978
158990
  if (update !== "replace" && !updates.includes(update)) {
158979
158991
  continue;
158980
158992
  }
158981
158993
  if (update === "prepend") {
158982
- linkedIDs = newIDs.concat(oldIDs);
158994
+ linkedIDs = newIDs.concat(
158995
+ filterIDs(newIDs, oldIDs)
158996
+ );
158983
158997
  if (layer?.optimistic) {
158984
158998
  action = () => {
158985
158999
  for (const id of newIDs) {
@@ -158990,7 +159004,7 @@ var CacheInternal2 = class {
158990
159004
  };
158991
159005
  }
158992
159006
  } else if (update === "append") {
158993
- linkedIDs = oldIDs.concat(newIDs);
159007
+ linkedIDs = filterIDs(newIDs, oldIDs).concat(newIDs);
158994
159008
  if (layer?.optimistic) {
158995
159009
  action = () => {
158996
159010
  for (const id of newIDs) {
@@ -161073,9 +161087,7 @@ import type { ${functionImportsToBring.join(
161073
161087
  ", "
161074
161088
  )} } from '${houdiniRelative}/plugins/houdini-svelte/runtime/types';` : "";
161075
161089
  typeImports = typeImports.concat(functionImports).concat(layoutTypeImports).concat(pageTypeImports).concat(componentQueryTypeImports);
161076
- const layoutParams = `${layoutQueries.length > 0 && !utilityTypes.includes("LayoutParams") ? "\ntype LayoutParams = LayoutLoadEvent['params'];" : ""}`;
161077
- const pageParams = `${pageQueries.length > 0 && !utilityTypes.includes("PageParams") ? "\ntype PageParams = PageLoadEvent['params'];" : ""}`;
161078
- utilityTypes = utilityTypes.concat(layoutParams).concat(pageParams).replaceAll(/\$types\.js/gm, "$houdini");
161090
+ utilityTypes = utilityTypes.replaceAll(/\$types\.js/gm, "$houdini");
161079
161091
  typeExports = typeExports.concat(append_loadInput([...layoutQueries, ...pageQueries])).concat(layout_append_beforeLoad).concat(page_append_beforeLoad).concat(layout_append_afterLoad).concat(page_append_afterLoad).concat(layout_append_onError).concat(page_append_onError).concat(layout_append_VariablesFunction).concat(page_append_VariablesFunction).concat(component_append_VariablesFunction).replace(
161080
161092
  //regex to append our generated stores to the existing
161081
161093
  //match all between 'LayoutData =' and ';' and combine additional types
@@ -161160,7 +161172,7 @@ function append_VariablesFunction(type, filepath, config, queries) {
161160
161172
  return `
161161
161173
  export type ${config.variableFunctionName(
161162
161174
  name
161163
- )} = VariableFunction<${type}Params, ${input_type}>;`;
161175
+ )} = VariableFunction<${type}LoadEvent, ${input_type}>;`;
161164
161176
  }).join("\n");
161165
161177
  }
161166
161178
  function append_ComponentVariablesFunction(filepath, config, queries) {