@objectstack/objectql 5.0.0 → 5.1.0

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.
package/dist/index.mjs CHANGED
@@ -667,6 +667,42 @@ var SysMetadataRepository = class {
667
667
  if (!row) return null;
668
668
  return this.rowToItem(ref, row);
669
669
  }
670
+ /**
671
+ * Resolve a historical version by content hash (ADR-0009).
672
+ *
673
+ * Looks up `sys_metadata_history` by `(organization_id, type, name,
674
+ * checksum)`. Returns null if no row matches. `executionPinned` types
675
+ * are guaranteed to find their body here because history GC skips
676
+ * them.
677
+ */
678
+ async getByHash(ref, hash) {
679
+ this.assertOpen();
680
+ const full = this.fullRef(ref);
681
+ const row = await this.engine.findOne(this.historyTable, {
682
+ where: {
683
+ organization_id: this.organizationId,
684
+ type: full.type,
685
+ name: full.name,
686
+ checksum: hash
687
+ }
688
+ });
689
+ if (!row) return null;
690
+ const rawBody = row.metadata;
691
+ if (rawBody === null || rawBody === void 0) {
692
+ return null;
693
+ }
694
+ const body = typeof rawBody === "string" ? JSON.parse(rawBody) : rawBody;
695
+ return {
696
+ ref: { ...full, version: void 0 },
697
+ body,
698
+ hash,
699
+ parentHash: row.previous_checksum ?? null,
700
+ authoredBy: row.recorded_by ?? "unknown",
701
+ authoredAt: row.recorded_at ?? (/* @__PURE__ */ new Date(0)).toISOString(),
702
+ message: row.change_note ?? void 0,
703
+ seq: row.event_seq ?? 0
704
+ };
705
+ }
670
706
  async put(ref, spec, opts) {
671
707
  this.assertOpen();
672
708
  this.assertAllowed(ref.type);
@@ -699,7 +735,6 @@ var SysMetadataRepository = class {
699
735
  version,
700
736
  updated_at: now
701
737
  };
702
- let parentId;
703
738
  if (existing) {
704
739
  const existingId = existing.id;
705
740
  if (existingId === void 0) {
@@ -707,22 +742,19 @@ var SysMetadataRepository = class {
707
742
  `SysMetadataRepository.put: existing row for ${ref.type}/${ref.name} has no id column`
708
743
  );
709
744
  }
710
- parentId = existingId;
711
745
  await this.engine.update("sys_metadata", parentRowData, {
712
746
  where: { id: existingId },
713
747
  context: ctx
714
748
  });
715
749
  } else {
716
750
  parentRowData.created_at = now;
717
- const inserted = await this.engine.insert("sys_metadata", parentRowData, { context: ctx });
718
- parentId = inserted.id;
751
+ await this.engine.insert("sys_metadata", parentRowData, { context: ctx });
719
752
  }
720
753
  await this.engine.insert(
721
754
  this.historyTable,
722
755
  {
723
756
  id: this.uuid(),
724
757
  event_seq: eventSeq,
725
- metadata_id: parentId,
726
758
  type: ref.type,
727
759
  name: ref.name,
728
760
  version,
@@ -811,7 +843,6 @@ var SysMetadataRepository = class {
811
843
  {
812
844
  id: this.uuid(),
813
845
  event_seq: eventSeq,
814
- metadata_id: existingId,
815
846
  type: ref.type,
816
847
  name: ref.name,
817
848
  version,