@sequenceholdings/orm 2.9.0 → 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.
package/dist/cli.cjs CHANGED
@@ -1816,19 +1816,20 @@ var variableIrSchema = zod.z.object({
1816
1816
  defaultValue: variableDefaultIrSchema.optional()
1817
1817
  });
1818
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();
1819
1826
  var compiledOperationSchema = zod.z.object({
1820
1827
  language: zod.z.literal("sql").optional(),
1821
1828
  /** Server-compiled object catalog and permission ceiling, never caller SQL. */
1822
1829
  sqlQuery: zod.z.object({
1823
1830
  catalog: zod.z.object({
1824
1831
  identity: zod.z.string(),
1825
- objects: zod.z.array(zod.z.object({
1826
- ref: zod.z.string(),
1827
- table: zod.z.string(),
1828
- columns: zod.z.array(sqlColumnSchema.extend({ type: zod.z.string() })).min(1),
1829
- scan: zod.z.string().min(1),
1830
- read: zod.z.array(zod.z.string()).min(1)
1831
- }).strict()).min(1).max(256)
1832
+ objects: zod.z.array(sqlObjectIrSchema).min(1).max(256)
1832
1833
  }).strict(),
1833
1834
  read: zod.z.array(zod.z.string()).min(1).max(256),
1834
1835
  maxRows: zod.z.number().int().min(1).max(1e4)
@@ -2488,6 +2489,7 @@ var FLIPPED = {
2488
2489
  ">=": "<="
2489
2490
  };
2490
2491
  function resolveTable(resolver, table) {
2492
+ resolver.onTable?.(table);
2491
2493
  const info = resolver.tables[table];
2492
2494
  if (!info) {
2493
2495
  throw new PolicyCompileError(`unknown table '${table}'`, "unknown-table", Object.keys(resolver.tables));
@@ -5403,10 +5405,13 @@ function sqlHash(value) {
5403
5405
  return `sha256:${crypto.createHash("sha256").update(value).digest("hex")}`;
5404
5406
  }
5405
5407
  function createSqlCatalog({ canonical, publishedObjects, executionTarget }) {
5406
- if (!publishedObjects.length || new Set(publishedObjects).size !== publishedObjects.length) throw new Error("SQL objects must be explicitly declared and unique");
5407
5408
  const { ctx, diagnostics } = buildCompileContext(canonical);
5408
5409
  if (diagnostics.some((d) => d.severity === "error")) throw new Error(diagnostics.map((d) => d.message).join("; "));
5409
- 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}`);
5410
5415
  const logicalNames = new Map(Object.entries(ctx.tables).map(([key, meta]) => [meta, key]));
5411
5416
  const refOf = (meta) => `${meta.namespace ?? canonical.namespace}/${logicalNames.get(meta)}`;
5412
5417
  const definitions = [canonical, ...canonical.imports ?? []];
@@ -5517,9 +5522,10 @@ var SqlEmitter = class {
5517
5522
  only(cte, ["ctename", "ctequery", "ctematerialized", "location"]);
5518
5523
  const name2 = str(cte.ctename);
5519
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");
5520
5526
  const result2 = this.select(obj(cte.ctequery), { ...parent, ctes: scope.ctes });
5521
5527
  scope.ctes.set(name2, result2);
5522
- ctes.push(`${quoteIdentifier(name2)} AS (${result2.text})`);
5528
+ ctes.push(`${quoteIdentifier(name2)} AS ${materialization}(${result2.text})`);
5523
5529
  }
5524
5530
  }
5525
5531
  const result = node.op === "SETOP_UNION" ? this.union(node, scope) : this.projection(node, scope);
@@ -11428,6 +11434,11 @@ var BASE_URL_ENV = "SEQUENCE_ORM_BASE_URL";
11428
11434
  var TOKEN_ENV = "SEQUENCE_ORM_TOKEN";
11429
11435
  var SOURCE_ENV = "SEQUENCE_ORM_SOURCE";
11430
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
+ }
11431
11442
  function applySourceFromEnv(env = process.env) {
11432
11443
  const reason = env[UNVERIFIED_SOURCE_REASON_ENV]?.trim();
11433
11444
  const override = reason ? { unverified_source_reason: reason } : {};
@@ -11987,7 +11998,8 @@ function describeActivation(activation) {
11987
11998
  const by = `by ${activation.actor_sub.replace(/^google-apps\|/, "")}`;
11988
11999
  if (activation.source_commit && activation.source_branch) {
11989
12000
  const at = activation.source_path ? ` at ${activation.source_path}` : "";
11990
- return `${since} from ${activation.source_commit.slice(0, 12)} on ${activation.source_branch}${at} (${activation.provenance_class}) ${by}`;
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}`;
11991
12003
  }
11992
12004
  const failure = activation.reported_source?.verification_failure;
11993
12005
  const why = typeof failure === "string" ? `: ${failure}` : "";
@@ -12199,7 +12211,7 @@ async function applyV2Command(rest, dir) {
12199
12211
  ...allowDestructive ? { allow_destructive: true } : {},
12200
12212
  ...schemaAlreadyActive && registered.operation_set_id ? { operation_set_id: registered.operation_set_id } : {},
12201
12213
  ...applySourceFromEnv()
12202
- });
12214
+ }, applySourceHeaders());
12203
12215
  const live = { namespace, contentHash: registered.content_hash };
12204
12216
  if ("ops_only" in applied) {
12205
12217
  console.log(
@@ -12657,7 +12669,7 @@ async function applyCommand(rest) {
12657
12669
  version_id: registered.version_id,
12658
12670
  ...allowDestructive ? { allow_destructive: true } : {},
12659
12671
  ...applySourceFromEnv()
12660
- });
12672
+ }, applySourceHeaders());
12661
12673
  if ("status" in applied) {
12662
12674
  const verdict = await awaitQueuedApply({ dir, namespace, contentHash: registered.content_hash, runId: applied.run_id, applyWait });
12663
12675
  return verdict === "live" ? writeGeneratedTypes(dir, loaded) : verdict;
@@ -12802,7 +12814,7 @@ async function apiRequest(method, path, body, options) {
12802
12814
  if (!token) throw new Error("not authenticated \u2014 run: seq-studio login");
12803
12815
  const response = await fetch(`${baseUrl}${path}`, {
12804
12816
  method,
12805
- headers: { Authorization: `Bearer ${token}`, "Content-Type": "application/json" },
12817
+ headers: { ...options?.headers, Authorization: `Bearer ${token}`, "Content-Type": "application/json" },
12806
12818
  body: body === void 0 ? void 0 : JSON.stringify(body)
12807
12819
  });
12808
12820
  if (response.status === 404 && options?.allow404) return null;
@@ -12829,8 +12841,8 @@ function errorDetail(payload) {
12829
12841
  const fields = details && typeof details === "object" ? Object.entries(details).filter(([, value]) => typeof value === "string").map(([key, value]) => `${key}: ${String(value)}`) : [];
12830
12842
  return `${String(first.message)}${code ? ` (${code})` : ""}${fields.length ? ` [${fields.join(", ")}]` : ""}`;
12831
12843
  }
12832
- async function apiRequestStrict(method, path, body) {
12833
- const result = await apiRequest(method, path, body);
12844
+ async function apiRequestStrict(method, path, body, headers) {
12845
+ const result = await apiRequest(method, path, body, { headers });
12834
12846
  if (result === null) throw new Error(`${method} ${path} returned no payload`);
12835
12847
  return result;
12836
12848
  }
@@ -12859,10 +12871,12 @@ var firstLine2 = (sql4) => sql4.split("\n")[0] ?? sql4;
12859
12871
 
12860
12872
  exports.BASE_URL_ENV = BASE_URL_ENV;
12861
12873
  exports.ORM_MODULE_PATH_ENV = ORM_MODULE_PATH_ENV;
12874
+ exports.SOURCE_AUTHORIZATION_ENV = SOURCE_AUTHORIZATION_ENV;
12862
12875
  exports.SOURCE_ENV = SOURCE_ENV;
12863
12876
  exports.TOKEN_ENV = TOKEN_ENV;
12864
12877
  exports.UNVERIFIED_SOURCE_REASON_ENV = UNVERIFIED_SOURCE_REASON_ENV;
12865
12878
  exports.applySourceFromEnv = applySourceFromEnv;
12879
+ exports.applySourceHeaders = applySourceHeaders;
12866
12880
  exports.describeActivation = describeActivation;
12867
12881
  exports.errorDetail = errorDetail;
12868
12882
  exports.parseApplyWait = parseApplyWait;