@sequenceholdings/orm 2.8.5 → 2.10.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.
Files changed (56) hide show
  1. package/dist/authoring.cjs.map +1 -1
  2. package/dist/authoring.d.cts +2 -2
  3. package/dist/authoring.d.ts +2 -2
  4. package/dist/authoring.js.map +1 -1
  5. package/dist/canonical.cjs.map +1 -1
  6. package/dist/canonical.d.cts +72 -72
  7. package/dist/canonical.d.ts +72 -72
  8. package/dist/canonical.js.map +1 -1
  9. package/dist/cli.cjs +122 -68
  10. package/dist/cli.cjs.map +1 -1
  11. package/dist/cli.d.cts +32 -1
  12. package/dist/cli.d.ts +32 -1
  13. package/dist/cli.js +117 -69
  14. package/dist/cli.js.map +1 -1
  15. package/dist/client.cjs.map +1 -1
  16. package/dist/client.d.cts +1 -1
  17. package/dist/client.d.ts +1 -1
  18. package/dist/client.js.map +1 -1
  19. package/dist/compiler.cjs +259 -18
  20. package/dist/compiler.cjs.map +1 -1
  21. package/dist/compiler.d.cts +183 -3
  22. package/dist/compiler.d.ts +183 -3
  23. package/dist/compiler.js +254 -19
  24. package/dist/compiler.js.map +1 -1
  25. package/dist/{constants-Dou1RkTo.d.cts → constants-D2o0vK6U.d.cts} +8 -1
  26. package/dist/{constants-Dou1RkTo.d.ts → constants-D2o0vK6U.d.ts} +8 -1
  27. package/dist/dynamic-input.d.cts +1 -1
  28. package/dist/dynamic-input.d.ts +1 -1
  29. package/dist/index.cjs +53 -31
  30. package/dist/index.cjs.map +1 -1
  31. package/dist/index.d.cts +61 -60
  32. package/dist/index.d.ts +61 -60
  33. package/dist/index.js +51 -32
  34. package/dist/index.js.map +1 -1
  35. package/dist/ir.cjs +9 -7
  36. package/dist/ir.cjs.map +1 -1
  37. package/dist/ir.d.cts +85 -74
  38. package/dist/ir.d.ts +85 -74
  39. package/dist/ir.js +9 -8
  40. package/dist/ir.js.map +1 -1
  41. package/dist/predicate-v2.cjs +9 -7
  42. package/dist/predicate-v2.cjs.map +1 -1
  43. package/dist/predicate-v2.d.cts +3 -1
  44. package/dist/predicate-v2.d.ts +3 -1
  45. package/dist/predicate-v2.js +9 -7
  46. package/dist/predicate-v2.js.map +1 -1
  47. package/dist/sdl.cjs +8 -7
  48. package/dist/sdl.cjs.map +1 -1
  49. package/dist/sdl.d.cts +1 -1
  50. package/dist/sdl.d.ts +1 -1
  51. package/dist/sdl.js +8 -7
  52. package/dist/sdl.js.map +1 -1
  53. package/package.json +3 -3
  54. package/templates/orm-namespace/package.json +2 -1
  55. package/dist/{definition-DjfC7Lll.d.cts → definition-B99BsOAO.d.cts} +4 -4
  56. package/dist/{definition-DjfC7Lll.d.ts → definition-B99BsOAO.d.ts} +4 -4
package/dist/cli.cjs CHANGED
@@ -105,6 +105,8 @@ function materializedRefreshFunctionName(table) {
105
105
  function materializeLockKey(schema, table) {
106
106
  return `orm:materialize:${schema}.${table}`;
107
107
  }
108
+ var OPERATION_DOCUMENTS_FILE = "operations.documents.json";
109
+ var OPERATION_DOCUMENTS_VERSION = 1;
108
110
 
109
111
  // src/hash.ts
110
112
  function stableJson(value) {
@@ -1814,19 +1816,20 @@ var variableIrSchema = zod.z.object({
1814
1816
  defaultValue: variableDefaultIrSchema.optional()
1815
1817
  });
1816
1818
  var sqlColumnSchema = zod.z.object({ name: zod.z.string(), type: zod.z.enum(["text", "boolean", "integer", "bigint", "numeric", "double", "uuid", "date", "timestamptz", "jsonb"]), nullable: zod.z.boolean() });
1819
+ var sqlObjectIrSchema = zod.z.object({
1820
+ ref: zod.z.string(),
1821
+ table: zod.z.string(),
1822
+ columns: zod.z.array(sqlColumnSchema.extend({ type: zod.z.string() })).min(1),
1823
+ scan: zod.z.string().min(1),
1824
+ read: zod.z.array(zod.z.string()).min(1)
1825
+ }).strict();
1817
1826
  var compiledOperationSchema = zod.z.object({
1818
1827
  language: zod.z.literal("sql").optional(),
1819
1828
  /** Server-compiled object catalog and permission ceiling, never caller SQL. */
1820
1829
  sqlQuery: zod.z.object({
1821
1830
  catalog: zod.z.object({
1822
1831
  identity: zod.z.string(),
1823
- objects: zod.z.array(zod.z.object({
1824
- ref: zod.z.string(),
1825
- table: zod.z.string(),
1826
- columns: zod.z.array(sqlColumnSchema.extend({ type: zod.z.string() })).min(1),
1827
- scan: zod.z.string().min(1),
1828
- read: zod.z.array(zod.z.string()).min(1)
1829
- }).strict()).min(1).max(256)
1832
+ objects: zod.z.array(sqlObjectIrSchema).min(1).max(256)
1830
1833
  }).strict(),
1831
1834
  read: zod.z.array(zod.z.string()).min(1).max(256),
1832
1835
  maxRows: zod.z.number().int().min(1).max(1e4)
@@ -2486,6 +2489,7 @@ var FLIPPED = {
2486
2489
  ">=": "<="
2487
2490
  };
2488
2491
  function resolveTable(resolver, table) {
2492
+ resolver.onTable?.(table);
2489
2493
  const info = resolver.tables[table];
2490
2494
  if (!info) {
2491
2495
  throw new PolicyCompileError(`unknown table '${table}'`, "unknown-table", Object.keys(resolver.tables));
@@ -5401,10 +5405,13 @@ function sqlHash(value) {
5401
5405
  return `sha256:${crypto.createHash("sha256").update(value).digest("hex")}`;
5402
5406
  }
5403
5407
  function createSqlCatalog({ canonical, publishedObjects, executionTarget }) {
5404
- if (!publishedObjects.length || new Set(publishedObjects).size !== publishedObjects.length) throw new Error("SQL objects must be explicitly declared and unique");
5405
5408
  const { ctx, diagnostics } = buildCompileContext(canonical);
5406
5409
  if (diagnostics.some((d) => d.severity === "error")) throw new Error(diagnostics.map((d) => d.message).join("; "));
5407
- const identity = sqlHash(`ontology-sql-v1\0${computeSchemaHash(canonical)}\0${executionTarget}`);
5410
+ return createSqlCatalogFromContext({ canonical, publishedObjects, executionTarget, ctx });
5411
+ }
5412
+ function createSqlCatalogFromContext({ canonical, publishedObjects, executionTarget, ctx, identity: suppliedIdentity }) {
5413
+ if (!publishedObjects.length || new Set(publishedObjects).size !== publishedObjects.length) throw new Error("SQL objects must be explicitly declared and unique");
5414
+ const identity = suppliedIdentity ?? sqlHash(`ontology-sql-v1\0${computeSchemaHash(canonical)}\0${executionTarget}`);
5408
5415
  const logicalNames = new Map(Object.entries(ctx.tables).map(([key, meta]) => [meta, key]));
5409
5416
  const refOf = (meta) => `${meta.namespace ?? canonical.namespace}/${logicalNames.get(meta)}`;
5410
5417
  const definitions = [canonical, ...canonical.imports ?? []];
@@ -5515,9 +5522,10 @@ var SqlEmitter = class {
5515
5522
  only(cte, ["ctename", "ctequery", "ctematerialized", "location"]);
5516
5523
  const name2 = str(cte.ctename);
5517
5524
  if (scope.ctes.has(name2)) fail3("duplicate CTE");
5525
+ const materialization = cte.ctematerialized === "CTEMaterializeAlways" ? "MATERIALIZED " : cte.ctematerialized === "CTEMaterializeNever" ? "NOT MATERIALIZED " : cte.ctematerialized === "CTEMaterializeDefault" ? "" : fail3("unsupported CTE materialization");
5518
5526
  const result2 = this.select(obj(cte.ctequery), { ...parent, ctes: scope.ctes });
5519
5527
  scope.ctes.set(name2, result2);
5520
- ctes.push(`${quoteIdentifier(name2)} AS (${result2.text})`);
5528
+ ctes.push(`${quoteIdentifier(name2)} AS ${materialization}(${result2.text})`);
5521
5529
  }
5522
5530
  }
5523
5531
  const result = node.op === "SETOP_UNION" ? this.union(node, scope) : this.projection(node, scope);
@@ -10346,6 +10354,42 @@ async function readSnapshot(dir, ordinal) {
10346
10354
  const path$1 = path.join(dir, MIGRATIONS_DIRNAME, META_DIRNAME, `${pad(ordinal)}.snapshot.json`);
10347
10355
  return parseJson(path$1, await readSnapshotText(dir, ordinal));
10348
10356
  }
10357
+ async function verifyCommittedLedger(dir, entries) {
10358
+ const firstRequiredSnapshot = entries.length - 2;
10359
+ let previousId3;
10360
+ let previousSnapshotPresent = false;
10361
+ let previousHash = null;
10362
+ for (const [index3, entry] of entries.entries()) {
10363
+ const sql4 = await readMigrationSql(dir, entry);
10364
+ if (checksumOf(sql4) !== entry.checksum) {
10365
+ return `${MIGRATIONS_DIRNAME}/${entry.name}.sql does not match its journal checksum \u2014 committed migrations must not be edited`;
10366
+ }
10367
+ const snapshotText = index3 >= firstRequiredSnapshot ? await readSnapshotText(dir, entry.ordinal) : await readPrunableSnapshotText(dir, entry.ordinal);
10368
+ if (snapshotText !== void 0) {
10369
+ if (checksumOf(snapshotText) !== entry.snapshot_checksum) {
10370
+ return `the snapshot for ${entry.name} does not match its journal checksum \u2014 committed snapshots must not be edited (the next diff builds on it)`;
10371
+ }
10372
+ const snapshot = JSON.parse(snapshotText);
10373
+ if (previousSnapshotPresent && snapshot.prevId !== previousId3) {
10374
+ return `snapshot chain broken at ${entry.name} \u2014 regenerate the workspace with \`seq-studio orm diff\``;
10375
+ }
10376
+ previousId3 = snapshot.id;
10377
+ }
10378
+ previousSnapshotPresent = snapshotText !== void 0;
10379
+ if (entry.previous_content_hash !== previousHash) {
10380
+ return `content-hash chain broken at ${entry.name} \u2014 migrations must be appended in order by \`seq-studio orm diff\``;
10381
+ }
10382
+ previousHash = entry.content_hash;
10383
+ }
10384
+ return void 0;
10385
+ }
10386
+ async function readPrunableSnapshotText(dir, ordinal) {
10387
+ const path$1 = path.join(dir, MIGRATIONS_DIRNAME, META_DIRNAME, `${pad(ordinal)}.snapshot.json`);
10388
+ return promises.readFile(path$1, "utf8").catch((error) => {
10389
+ if (error instanceof Error && "code" in error && error.code === "ENOENT") return void 0;
10390
+ throw error;
10391
+ });
10392
+ }
10349
10393
  async function readMigrationSql(dir, entry) {
10350
10394
  const path$1 = path.join(dir, MIGRATIONS_DIRNAME, `${entry.name}.sql`);
10351
10395
  return promises.readFile(path$1, "utf8").catch(() => {
@@ -10506,30 +10550,10 @@ async function checkWorkspace({
10506
10550
  log(`no committed migrations for '${loaded.definition.namespace}' \u2014 run \`seq-studio orm diff\` and commit the result`);
10507
10551
  return 1;
10508
10552
  }
10509
- let previousId3;
10510
- let previousHash = null;
10511
- for (const entry of workspace.journal.entries) {
10512
- const sql4 = await readMigrationSql(dir, entry);
10513
- if (checksumOf(sql4) !== entry.checksum) {
10514
- log(`${MIGRATIONS_DIRNAME}/${entry.name}.sql does not match its journal checksum \u2014 committed migrations must not be edited`);
10515
- return 1;
10516
- }
10517
- const snapshotText = await readSnapshotText(dir, entry.ordinal);
10518
- if (checksumOf(snapshotText) !== entry.snapshot_checksum) {
10519
- log(`the snapshot for ${entry.name} does not match its journal checksum \u2014 committed snapshots must not be edited (the next diff builds on it)`);
10520
- return 1;
10521
- }
10522
- const snapshot = JSON.parse(snapshotText);
10523
- if (entry.ordinal > 1 && snapshot.prevId !== previousId3) {
10524
- log(`snapshot chain broken at ${entry.name} \u2014 regenerate the workspace with \`seq-studio orm diff\``);
10525
- return 1;
10526
- }
10527
- if (entry.previous_content_hash !== previousHash) {
10528
- log(`content-hash chain broken at ${entry.name} \u2014 migrations must be appended in order by \`seq-studio orm diff\``);
10529
- return 1;
10530
- }
10531
- previousId3 = snapshot.id;
10532
- previousHash = entry.content_hash;
10553
+ const broken = await verifyCommittedLedger(dir, workspace.journal.entries);
10554
+ if (broken) {
10555
+ log(broken);
10556
+ return 1;
10533
10557
  }
10534
10558
  if (tip.content_hash !== loaded.contentHash) {
10535
10559
  log(`definitions changed since ${tip.name} \u2014 run \`seq-studio orm diff\` and commit the new migration`);
@@ -11408,6 +11432,27 @@ function parseArgs(argv) {
11408
11432
  // src/cli.ts
11409
11433
  var BASE_URL_ENV = "SEQUENCE_ORM_BASE_URL";
11410
11434
  var TOKEN_ENV = "SEQUENCE_ORM_TOKEN";
11435
+ var SOURCE_ENV = "SEQUENCE_ORM_SOURCE";
11436
+ var UNVERIFIED_SOURCE_REASON_ENV = "SEQUENCE_ORM_UNVERIFIED_SOURCE_REASON";
11437
+ var SOURCE_AUTHORIZATION_ENV = "SEQUENCE_ORM_SOURCE_AUTHORIZATION";
11438
+ function applySourceHeaders(env = process.env) {
11439
+ const token = env[SOURCE_AUTHORIZATION_ENV]?.trim();
11440
+ return token ? { "x-sequence-source-authorization": `Bearer ${token}` } : {};
11441
+ }
11442
+ function applySourceFromEnv(env = process.env) {
11443
+ const reason = env[UNVERIFIED_SOURCE_REASON_ENV]?.trim();
11444
+ const override = reason ? { unverified_source_reason: reason } : {};
11445
+ const raw = env[SOURCE_ENV];
11446
+ if (!raw) return override;
11447
+ let parsed;
11448
+ try {
11449
+ parsed = JSON.parse(raw);
11450
+ } catch {
11451
+ throw new Error(`${SOURCE_ENV} is not valid JSON`);
11452
+ }
11453
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) throw new Error(`${SOURCE_ENV} must be a JSON object`);
11454
+ return { source: Object.fromEntries(Object.entries(parsed)), ...override };
11455
+ }
11411
11456
  var ORM_MODULE_PATH_ENV = "SEQUENCE_ORM_MODULE_PATH";
11412
11457
  var USAGE = `usage:
11413
11458
  seq-studio orm init <dir> scaffold a namespace package (v2: TypeScript schema + persisted operations)
@@ -11725,15 +11770,21 @@ async function generateCommand(rest) {
11725
11770
  await writeGenerateOutputs(dir, compiled.project);
11726
11771
  const { loaded, manifest } = compiled.project;
11727
11772
  console.log(
11728
- `wrote ${SCHEMA_GRAPHQL_FILE}, ${OPERATIONS_MANIFEST_FILE}, ${TYPE_POLICIES_FILE}, sql-operations.gen.ts, namespace.contract.json (${loaded.canonical.tables.length} table(s), ${loaded.canonical.views?.length ?? 0} view(s), ${Object.keys(manifest.operations).length} operation(s))`
11773
+ `wrote ${SCHEMA_GRAPHQL_FILE}, ${OPERATIONS_MANIFEST_FILE}, ${OPERATION_DOCUMENTS_FILE}, ${TYPE_POLICIES_FILE}, sql-operations.gen.ts, namespace.contract.json (${loaded.canonical.tables.length} table(s), ${loaded.canonical.views?.length ?? 0} view(s), ${Object.keys(manifest.operations).length} operation(s))`
11729
11774
  );
11730
11775
  return runConsumerCodegen(dir);
11731
11776
  }
11732
11777
  async function writeGenerateOutputs(dir, project) {
11733
- const { loaded, sdl, manifest } = project;
11778
+ const { loaded, sdl, manifest, documents } = project;
11734
11779
  await promises.writeFile(path.join(dir, SCHEMA_GRAPHQL_FILE), sdl);
11735
11780
  await promises.writeFile(path.join(dir, "namespace.contract.json"), `${JSON.stringify(loaded.canonical, null, 2)}
11736
11781
  `);
11782
+ const sortedDocuments = [...documents].sort((a, b) => a.path.localeCompare(b.path)).map(({ path, contents }) => ({ path, contents }));
11783
+ await promises.writeFile(
11784
+ path.join(dir, OPERATION_DOCUMENTS_FILE),
11785
+ `${JSON.stringify({ documentsVersion: OPERATION_DOCUMENTS_VERSION, documents: sortedDocuments }, null, 2)}
11786
+ `
11787
+ );
11737
11788
  const operations = Object.entries(manifest.operations).map(([name2, op]) => ({
11738
11789
  name: name2,
11739
11790
  kind: op.kind,
@@ -11939,8 +11990,21 @@ function reportRegistryState(registry) {
11939
11990
  if (match && match.id === registry.activeVersionId) console.log("-- registry: this content is the ACTIVE version");
11940
11991
  else if (match) console.log(`-- registry: registered (status ${match.status}), not active`);
11941
11992
  else console.log(`-- registry: new content (active is ${active ? active.content_hash.slice(0, 12) : "none"})`);
11993
+ if (registry.activeActivation) console.log(`-- registry: ${describeActivation(registry.activeActivation)}`);
11942
11994
  return 0;
11943
11995
  }
11996
+ function describeActivation(activation) {
11997
+ const since = `live since ${activation.activated_at.slice(0, 16).replace("T", " ")}Z`;
11998
+ const by = `by ${activation.actor_sub.replace(/^google-apps\|/, "")}`;
11999
+ if (activation.source_commit && activation.source_branch) {
12000
+ const at = activation.source_path ? ` at ${activation.source_path}` : "";
12001
+ const branch = activation.source_environment ? `${activation.source_environment}:${activation.source_branch}` : activation.source_branch;
12002
+ return `${since} from ${activation.source_commit.slice(0, 12)} on ${branch}${at} (${activation.provenance_class}) ${by}`;
12003
+ }
12004
+ const failure = activation.reported_source?.verification_failure;
12005
+ const why = typeof failure === "string" ? `: ${failure}` : "";
12006
+ return `${since} from an untraced source (${activation.provenance_class}${why}) ${by}`;
12007
+ }
11944
12008
  var META_DIRNAME2 = "meta";
11945
12009
  var JOURNAL_FILENAME2 = "journal.json";
11946
12010
  var padOrdinal = (ordinal) => String(ordinal).padStart(4, "0");
@@ -12028,30 +12092,10 @@ async function checkWorkspaceV2({
12028
12092
  log(`no committed migrations for '${namespace}' \u2014 run \`seq-studio orm diff\` and commit the result`);
12029
12093
  return 1;
12030
12094
  }
12031
- let previousId3;
12032
- let previousHash = null;
12033
- for (const entry of workspace.journal.entries) {
12034
- const sql4 = await readMigrationSql(dir, entry);
12035
- if (checksumOf(sql4) !== entry.checksum) {
12036
- log(`${MIGRATIONS_DIRNAME}/${entry.name}.sql does not match its journal checksum \u2014 committed migrations must not be edited`);
12037
- return 1;
12038
- }
12039
- const snapshotText = await readSnapshotText(dir, entry.ordinal);
12040
- if (checksumOf(snapshotText) !== entry.snapshot_checksum) {
12041
- log(`the snapshot for ${entry.name} does not match its journal checksum \u2014 committed snapshots must not be edited (the next diff builds on it)`);
12042
- return 1;
12043
- }
12044
- const snapshot = JSON.parse(snapshotText);
12045
- if (entry.ordinal > 1 && snapshot.prevId !== previousId3) {
12046
- log(`snapshot chain broken at ${entry.name} \u2014 regenerate the workspace with \`seq-studio orm diff\``);
12047
- return 1;
12048
- }
12049
- if (entry.previous_content_hash !== previousHash) {
12050
- log(`content-hash chain broken at ${entry.name} \u2014 migrations must be appended in order by \`seq-studio orm diff\``);
12051
- return 1;
12052
- }
12053
- previousId3 = snapshot.id;
12054
- previousHash = entry.content_hash;
12095
+ const broken = await verifyCommittedLedger(dir, workspace.journal.entries);
12096
+ if (broken) {
12097
+ log(broken);
12098
+ return 1;
12055
12099
  }
12056
12100
  if (tip.content_hash !== loaded.hash) {
12057
12101
  log(`definitions changed since ${tip.name} \u2014 run \`seq-studio orm diff\` and commit the new migration`);
@@ -12165,8 +12209,9 @@ async function applyV2Command(rest, dir) {
12165
12209
  const applied = await apiRequestStrict("POST", `/api/orm/namespaces/${namespace}/apply`, {
12166
12210
  version_id: registered.version_id,
12167
12211
  ...allowDestructive ? { allow_destructive: true } : {},
12168
- ...schemaAlreadyActive && registered.operation_set_id ? { operation_set_id: registered.operation_set_id } : {}
12169
- });
12212
+ ...schemaAlreadyActive && registered.operation_set_id ? { operation_set_id: registered.operation_set_id } : {},
12213
+ ...applySourceFromEnv()
12214
+ }, applySourceHeaders());
12170
12215
  const live = { namespace, contentHash: registered.content_hash };
12171
12216
  if ("ops_only" in applied) {
12172
12217
  console.log(
@@ -12622,8 +12667,9 @@ async function applyCommand(rest) {
12622
12667
  if (dryRun) return dryRunRehearsal({ namespace, versionId: registered.version_id, contentHash: registered.content_hash });
12623
12668
  const applied = await apiRequestStrict("POST", `/api/orm/namespaces/${namespace}/apply`, {
12624
12669
  version_id: registered.version_id,
12625
- ...allowDestructive ? { allow_destructive: true } : {}
12626
- });
12670
+ ...allowDestructive ? { allow_destructive: true } : {},
12671
+ ...applySourceFromEnv()
12672
+ }, applySourceHeaders());
12627
12673
  if ("status" in applied) {
12628
12674
  const verdict = await awaitQueuedApply({ dir, namespace, contentHash: registered.content_hash, runId: applied.run_id, applyWait });
12629
12675
  return verdict === "live" ? writeGeneratedTypes(dir, loaded) : verdict;
@@ -12768,7 +12814,7 @@ async function apiRequest(method, path, body, options) {
12768
12814
  if (!token) throw new Error("not authenticated \u2014 run: seq-studio login");
12769
12815
  const response = await fetch(`${baseUrl}${path}`, {
12770
12816
  method,
12771
- headers: { Authorization: `Bearer ${token}`, "Content-Type": "application/json" },
12817
+ headers: { ...options?.headers, Authorization: `Bearer ${token}`, "Content-Type": "application/json" },
12772
12818
  body: body === void 0 ? void 0 : JSON.stringify(body)
12773
12819
  });
12774
12820
  if (response.status === 404 && options?.allow404) return null;
@@ -12795,18 +12841,20 @@ function errorDetail(payload) {
12795
12841
  const fields = details && typeof details === "object" ? Object.entries(details).filter(([, value]) => typeof value === "string").map(([key, value]) => `${key}: ${String(value)}`) : [];
12796
12842
  return `${String(first.message)}${code ? ` (${code})` : ""}${fields.length ? ` [${fields.join(", ")}]` : ""}`;
12797
12843
  }
12798
- async function apiRequestStrict(method, path, body) {
12799
- const result = await apiRequest(method, path, body);
12844
+ async function apiRequestStrict(method, path, body, headers) {
12845
+ const result = await apiRequest(method, path, body, { headers });
12800
12846
  if (result === null) throw new Error(`${method} ${path} returned no payload`);
12801
12847
  return result;
12802
12848
  }
12803
12849
  async function fetchRegistryState(namespace, contentHash) {
12804
12850
  if (!process.env[BASE_URL_ENV]?.trim() || !await resolveToken()) return { kind: "offline" };
12805
- const body = await apiRequest("GET", `/api/orm/namespaces/${namespace}?hash=${encodeURIComponent(contentHash)}`, void 0, { allow404: true });
12851
+ const body = await apiRequest("GET", `/api/orm/namespaces/${namespace}?hash=${encodeURIComponent(contentHash)}&activations_limit=1`, void 0, { allow404: true });
12806
12852
  if (!body) return { kind: "missing" };
12853
+ const latest = body.activations?.[0];
12807
12854
  return {
12808
12855
  kind: "found",
12809
12856
  activeVersionId: body.namespace.active_version_id,
12857
+ activeActivation: latest && latest.id === body.namespace.active_activation_id ? latest : null,
12810
12858
  versions: body.versions,
12811
12859
  hashVersion: body.hash_version ?? null
12812
12860
  };
@@ -12823,7 +12871,13 @@ var firstLine2 = (sql4) => sql4.split("\n")[0] ?? sql4;
12823
12871
 
12824
12872
  exports.BASE_URL_ENV = BASE_URL_ENV;
12825
12873
  exports.ORM_MODULE_PATH_ENV = ORM_MODULE_PATH_ENV;
12874
+ exports.SOURCE_AUTHORIZATION_ENV = SOURCE_AUTHORIZATION_ENV;
12875
+ exports.SOURCE_ENV = SOURCE_ENV;
12826
12876
  exports.TOKEN_ENV = TOKEN_ENV;
12877
+ exports.UNVERIFIED_SOURCE_REASON_ENV = UNVERIFIED_SOURCE_REASON_ENV;
12878
+ exports.applySourceFromEnv = applySourceFromEnv;
12879
+ exports.applySourceHeaders = applySourceHeaders;
12880
+ exports.describeActivation = describeActivation;
12827
12881
  exports.errorDetail = errorDetail;
12828
12882
  exports.parseApplyWait = parseApplyWait;
12829
12883
  exports.runCli = runCli;