houdini 2.0.0-next.1 → 2.0.0-next.2

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.
@@ -74990,20 +74990,21 @@ var CacheInternal = class {
74990
74990
  } else if (Array.isArray(value) && // make typescript happy
74991
74991
  (typeof previousValue === "undefined" || previousValue === null || Array.isArray(previousValue))) {
74992
74992
  let oldIDs = [...previousValue || []];
74993
- const emptyEdges = !updates ? [] : oldIDs.map((id) => {
74994
- if (!id) {
74995
- return "";
74996
- }
74997
- const { value: cursorField } = this.storage.get(id, "cursor");
74998
- if (cursorField) {
74999
- return "";
75000
- }
75001
- const { value: node } = this.storage.get(id, "node");
75002
- if (!node) {
75003
- return "";
75004
- }
75005
- return node;
75006
- });
74993
+ if (updates?.includes("append") || updates?.includes("prepend")) {
74994
+ oldIDs = oldIDs.filter((id) => {
74995
+ for (const layer2 of this.storage.data) {
74996
+ for (const operation of Object.values(layer2.operations)) {
74997
+ if (operation.fields?.[key])
74998
+ for (const listOperation of operation.fields[key]) {
74999
+ if ("id" in listOperation && listOperation.id === id) {
75000
+ return false;
75001
+ }
75002
+ }
75003
+ }
75004
+ }
75005
+ return true;
75006
+ });
75007
+ }
75007
75008
  let linkedIDs = [];
75008
75009
  const { newIDs, nestedIDs } = this.extractNestedListIDs({
75009
75010
  value,
@@ -75022,39 +75023,45 @@ var CacheInternal = class {
75022
75023
  layer.writeLink(parent2, key, linkedIDs);
75023
75024
  };
75024
75025
  if (applyUpdates && updates) {
75025
- if (key === "edges") {
75026
- const newNodeIDs = [];
75027
- for (const id of newIDs) {
75026
+ const filterIDs = (keep, insert) => {
75027
+ const existingIDs = /* @__PURE__ */ new Set();
75028
+ for (const id of keep) {
75028
75029
  if (!id) {
75029
75030
  continue;
75030
75031
  }
75031
75032
  const { value: node } = this.storage.get(id, "node");
75032
- if (typeof node !== "string") {
75033
+ if (!node) {
75033
75034
  continue;
75034
75035
  }
75035
- if (!node || !this.storage.get(node, "__typename")) {
75036
+ const nodeID = this.storage.get(node, "id");
75037
+ if (!nodeID) {
75036
75038
  continue;
75037
75039
  }
75038
- newNodeIDs.push(node);
75040
+ existingIDs.add(nodeID.value);
75039
75041
  }
75040
- oldIDs = oldIDs.filter((id) => {
75042
+ return insert.filter((id) => {
75041
75043
  if (!id) {
75042
75044
  return true;
75043
75045
  }
75044
- const { value: value2 } = this.storage.get(id, "node");
75045
- const node = value2;
75046
- if (newNodeIDs.includes(node) && emptyEdges.includes(node)) {
75047
- return false;
75046
+ const { value: node } = this.storage.get(id, "node");
75047
+ if (!node) {
75048
+ return true;
75048
75049
  }
75049
- return true;
75050
+ const nodeID = this.storage.get(node, "id");
75051
+ if (!nodeID) {
75052
+ return true;
75053
+ }
75054
+ return !existingIDs.has(nodeID.value);
75050
75055
  });
75051
- }
75056
+ };
75052
75057
  for (const update of applyUpdates) {
75053
75058
  if (update !== "replace" && !updates.includes(update)) {
75054
75059
  continue;
75055
75060
  }
75056
75061
  if (update === "prepend") {
75057
- linkedIDs = newIDs.concat(oldIDs);
75062
+ linkedIDs = newIDs.concat(
75063
+ filterIDs(newIDs, oldIDs)
75064
+ );
75058
75065
  if (layer?.optimistic) {
75059
75066
  action = () => {
75060
75067
  for (const id of newIDs) {
@@ -75065,7 +75072,7 @@ var CacheInternal = class {
75065
75072
  };
75066
75073
  }
75067
75074
  } else if (update === "append") {
75068
- linkedIDs = oldIDs.concat(newIDs);
75075
+ linkedIDs = filterIDs(newIDs, oldIDs).concat(newIDs);
75069
75076
  if (layer?.optimistic) {
75070
75077
  action = () => {
75071
75078
  for (const id of newIDs) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "houdini",
3
- "version": "2.0.0-next.1",
3
+ "version": "2.0.0-next.2",
4
4
  "description": "The disappearing GraphQL clients",
5
5
  "keywords": [
6
6
  "typescript",