@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.d.mts CHANGED
@@ -767,6 +767,15 @@ declare class SysMetadataRepository implements MetadataRepository {
767
767
  * callers (e.g. LayeredRepository) fall through to lower layers.
768
768
  */
769
769
  get(ref: MetaRef): Promise<MetadataItem | null>;
770
+ /**
771
+ * Resolve a historical version by content hash (ADR-0009).
772
+ *
773
+ * Looks up `sys_metadata_history` by `(organization_id, type, name,
774
+ * checksum)`. Returns null if no row matches. `executionPinned` types
775
+ * are guaranteed to find their body here because history GC skips
776
+ * them.
777
+ */
778
+ getByHash(ref: MetaRef, hash: string): Promise<MetadataItem | null>;
770
779
  put(ref: MetaRef, spec: unknown, opts: PutOptions): Promise<PutResult>;
771
780
  delete(ref: MetaRef, opts: DeleteOptions): Promise<DeleteResult>;
772
781
  list(filter: ListFilter): AsyncIterable<MetadataItemHeader>;
package/dist/index.d.ts CHANGED
@@ -767,6 +767,15 @@ declare class SysMetadataRepository implements MetadataRepository {
767
767
  * callers (e.g. LayeredRepository) fall through to lower layers.
768
768
  */
769
769
  get(ref: MetaRef): Promise<MetadataItem | null>;
770
+ /**
771
+ * Resolve a historical version by content hash (ADR-0009).
772
+ *
773
+ * Looks up `sys_metadata_history` by `(organization_id, type, name,
774
+ * checksum)`. Returns null if no row matches. `executionPinned` types
775
+ * are guaranteed to find their body here because history GC skips
776
+ * them.
777
+ */
778
+ getByHash(ref: MetaRef, hash: string): Promise<MetadataItem | null>;
770
779
  put(ref: MetaRef, spec: unknown, opts: PutOptions): Promise<PutResult>;
771
780
  delete(ref: MetaRef, opts: DeleteOptions): Promise<DeleteResult>;
772
781
  list(filter: ListFilter): AsyncIterable<MetadataItemHeader>;
package/dist/index.js CHANGED
@@ -717,6 +717,42 @@ var SysMetadataRepository = class {
717
717
  if (!row) return null;
718
718
  return this.rowToItem(ref, row);
719
719
  }
720
+ /**
721
+ * Resolve a historical version by content hash (ADR-0009).
722
+ *
723
+ * Looks up `sys_metadata_history` by `(organization_id, type, name,
724
+ * checksum)`. Returns null if no row matches. `executionPinned` types
725
+ * are guaranteed to find their body here because history GC skips
726
+ * them.
727
+ */
728
+ async getByHash(ref, hash) {
729
+ this.assertOpen();
730
+ const full = this.fullRef(ref);
731
+ const row = await this.engine.findOne(this.historyTable, {
732
+ where: {
733
+ organization_id: this.organizationId,
734
+ type: full.type,
735
+ name: full.name,
736
+ checksum: hash
737
+ }
738
+ });
739
+ if (!row) return null;
740
+ const rawBody = row.metadata;
741
+ if (rawBody === null || rawBody === void 0) {
742
+ return null;
743
+ }
744
+ const body = typeof rawBody === "string" ? JSON.parse(rawBody) : rawBody;
745
+ return {
746
+ ref: { ...full, version: void 0 },
747
+ body,
748
+ hash,
749
+ parentHash: row.previous_checksum ?? null,
750
+ authoredBy: row.recorded_by ?? "unknown",
751
+ authoredAt: row.recorded_at ?? (/* @__PURE__ */ new Date(0)).toISOString(),
752
+ message: row.change_note ?? void 0,
753
+ seq: row.event_seq ?? 0
754
+ };
755
+ }
720
756
  async put(ref, spec, opts) {
721
757
  this.assertOpen();
722
758
  this.assertAllowed(ref.type);
@@ -749,7 +785,6 @@ var SysMetadataRepository = class {
749
785
  version,
750
786
  updated_at: now
751
787
  };
752
- let parentId;
753
788
  if (existing) {
754
789
  const existingId = existing.id;
755
790
  if (existingId === void 0) {
@@ -757,22 +792,19 @@ var SysMetadataRepository = class {
757
792
  `SysMetadataRepository.put: existing row for ${ref.type}/${ref.name} has no id column`
758
793
  );
759
794
  }
760
- parentId = existingId;
761
795
  await this.engine.update("sys_metadata", parentRowData, {
762
796
  where: { id: existingId },
763
797
  context: ctx
764
798
  });
765
799
  } else {
766
800
  parentRowData.created_at = now;
767
- const inserted = await this.engine.insert("sys_metadata", parentRowData, { context: ctx });
768
- parentId = inserted.id;
801
+ await this.engine.insert("sys_metadata", parentRowData, { context: ctx });
769
802
  }
770
803
  await this.engine.insert(
771
804
  this.historyTable,
772
805
  {
773
806
  id: this.uuid(),
774
807
  event_seq: eventSeq,
775
- metadata_id: parentId,
776
808
  type: ref.type,
777
809
  name: ref.name,
778
810
  version,
@@ -861,7 +893,6 @@ var SysMetadataRepository = class {
861
893
  {
862
894
  id: this.uuid(),
863
895
  event_seq: eventSeq,
864
- metadata_id: existingId,
865
896
  type: ref.type,
866
897
  name: ref.name,
867
898
  version,