@semiont/make-meaning 0.5.13 → 0.5.14

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.
@@ -10095,6 +10095,21 @@ var Weaver = class _Weaver {
10095
10095
  }
10096
10096
  return summary;
10097
10097
  }
10098
+ /**
10099
+ * Key-order-independent serialization for deep equality (W9-deep): two
10100
+ * structurally equal bodies must compare equal regardless of the property
10101
+ * order their storage backend happens to preserve.
10102
+ */
10103
+ static canonicalJson(value) {
10104
+ if (Array.isArray(value)) {
10105
+ return `[${value.map((v) => _Weaver.canonicalJson(v)).join(",")}]`;
10106
+ }
10107
+ if (value !== null && typeof value === "object") {
10108
+ const entries = Object.entries(value).filter(([, v]) => v !== void 0).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
10109
+ return `{${entries.map(([k, v]) => `${JSON.stringify(k)}:${_Weaver.canonicalJson(v)}`).join(",")}}`;
10110
+ }
10111
+ return JSON.stringify(value) ?? "null";
10112
+ }
10098
10113
  /** Compare one resource's graph state against its view; null = in sync. */
10099
10114
  async divergenceOf(resource) {
10100
10115
  const graphDb = this.ensureInitialized();
@@ -10115,6 +10130,14 @@ var Weaver = class _Weaver {
10115
10130
  for (const id of viewIds) {
10116
10131
  if (!graphIds.has(id)) return "annotation-set-mismatch";
10117
10132
  }
10133
+ const viewById = new Map(annotations.map((a) => [String(a.id), a]));
10134
+ for (const graphAnnotation of graphAnnotations) {
10135
+ const viewAnnotation = viewById.get(String(graphAnnotation.id));
10136
+ if (!viewAnnotation) continue;
10137
+ if (_Weaver.canonicalJson(graphAnnotation.body) !== _Weaver.canonicalJson(viewAnnotation.body)) {
10138
+ return "annotation-body-mismatch";
10139
+ }
10140
+ }
10118
10141
  return null;
10119
10142
  }
10120
10143
  async handleRebuildCommand(command) {
@@ -10471,7 +10494,12 @@ var Weaver = class _Weaver {
10471
10494
  const graphDb = this.ensureInitialized();
10472
10495
  this.logger.info("Rebuilding entire GraphDB from events");
10473
10496
  this.logger.info("Using two-pass approach: nodes first, then edges");
10497
+ const entityTypes = await graphDb.getEntityTypes();
10474
10498
  await graphDb.clearDatabase();
10499
+ if (entityTypes.length > 0) {
10500
+ await graphDb.addEntityTypes(entityTypes);
10501
+ this.logger.info("Re-registered frame vocabulary across the wipe", { count: entityTypes.length });
10502
+ }
10475
10503
  const allResourceIds = (await this.fetchAllResources()).map((resource) => resource["@id"]).filter((rid) => !!rid);
10476
10504
  this.logger.info("Found resources to rebuild", { count: allResourceIds.length });
10477
10505
  const ledger = /* @__PURE__ */ new Map();