@deeplake/hivemind 0.7.76 → 0.7.77

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.
@@ -1094,12 +1094,39 @@ import { createHash as createHash2 } from "node:crypto";
1094
1094
  import { mkdirSync as mkdirSync6, renameSync as renameSync3, writeFileSync as writeFileSync5 } from "node:fs";
1095
1095
  import { homedir as homedir5 } from "node:os";
1096
1096
  import { dirname as dirname3, join as join8 } from "node:path";
1097
+
1098
+ // dist/src/graph/resolve/cross-file.js
1099
+ import { posix } from "node:path";
1100
+
1101
+ // dist/src/graph/snapshot.js
1097
1102
  function graphsRoot() {
1098
1103
  return process.env.HIVEMIND_GRAPHS_HOME ?? join8(homedir5(), ".hivemind", "graphs");
1099
1104
  }
1100
1105
  function repoDir(repoKey) {
1101
1106
  return join8(graphsRoot(), repoKey);
1102
1107
  }
1108
+ function computeSnapshotSha256(snapshot) {
1109
+ const stable = {
1110
+ directed: snapshot.directed,
1111
+ multigraph: snapshot.multigraph,
1112
+ graph: snapshot.graph,
1113
+ nodes: snapshot.nodes,
1114
+ links: snapshot.links
1115
+ };
1116
+ return createHash2("sha256").update(canonicalJSON(stable)).digest("hex");
1117
+ }
1118
+ function canonicalJSON(value) {
1119
+ return JSON.stringify(value, (_key, v) => {
1120
+ if (v !== null && typeof v === "object" && !Array.isArray(v)) {
1121
+ const sorted = {};
1122
+ for (const k of Object.keys(v).sort()) {
1123
+ sorted[k] = v[k];
1124
+ }
1125
+ return sorted;
1126
+ }
1127
+ return v;
1128
+ });
1129
+ }
1103
1130
 
1104
1131
  // dist/src/graph/deeplake-pull.js
1105
1132
  function workTreeIdFor(cwd) {
@@ -1141,8 +1168,20 @@ async function pullSnapshot(cwd, deps = {}) {
1141
1168
  if (cloudPayload === null) {
1142
1169
  return errorOutcome("SELECT cloud row", new Error("invalid snapshot_jsonb payload"));
1143
1170
  }
1171
+ let parsedSnapshot;
1172
+ try {
1173
+ parsedSnapshot = JSON.parse(cloudPayload);
1174
+ } catch (err) {
1175
+ return errorOutcome("parse cloud snapshot", err);
1176
+ }
1177
+ if (parsedSnapshot === null || typeof parsedSnapshot !== "object") {
1178
+ return errorOutcome("parse cloud snapshot", new Error("snapshot not an object"));
1179
+ }
1180
+ if (!Array.isArray(parsedSnapshot.nodes) || !Array.isArray(parsedSnapshot.links)) {
1181
+ return errorOutcome("parse cloud snapshot", new Error("snapshot missing nodes/links arrays"));
1182
+ }
1144
1183
  if (cloudSha256 !== "") {
1145
- const computedSha = createHash3("sha256").update(cloudPayload).digest("hex");
1184
+ const computedSha = computeSnapshotSha256(parsedSnapshot);
1146
1185
  if (cloudSha256 !== computedSha) {
1147
1186
  return errorOutcome("SELECT cloud row", new Error(`snapshot_sha256 mismatch (expected ${cloudSha256}, got ${computedSha})`));
1148
1187
  }