@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/compiler.js CHANGED
@@ -1663,19 +1663,20 @@ var variableIrSchema = z.object({
1663
1663
  defaultValue: variableDefaultIrSchema.optional()
1664
1664
  });
1665
1665
  var sqlColumnSchema = z.object({ name: z.string(), type: z.enum(["text", "boolean", "integer", "bigint", "numeric", "double", "uuid", "date", "timestamptz", "jsonb"]), nullable: z.boolean() });
1666
+ var sqlObjectIrSchema = z.object({
1667
+ ref: z.string(),
1668
+ table: z.string(),
1669
+ columns: z.array(sqlColumnSchema.extend({ type: z.string() })).min(1),
1670
+ scan: z.string().min(1),
1671
+ read: z.array(z.string()).min(1)
1672
+ }).strict();
1666
1673
  var compiledOperationSchema = z.object({
1667
1674
  language: z.literal("sql").optional(),
1668
1675
  /** Server-compiled object catalog and permission ceiling, never caller SQL. */
1669
1676
  sqlQuery: z.object({
1670
1677
  catalog: z.object({
1671
1678
  identity: z.string(),
1672
- objects: z.array(z.object({
1673
- ref: z.string(),
1674
- table: z.string(),
1675
- columns: z.array(sqlColumnSchema.extend({ type: z.string() })).min(1),
1676
- scan: z.string().min(1),
1677
- read: z.array(z.string()).min(1)
1678
- }).strict()).min(1).max(256)
1679
+ objects: z.array(sqlObjectIrSchema).min(1).max(256)
1679
1680
  }).strict(),
1680
1681
  read: z.array(z.string()).min(1).max(256),
1681
1682
  maxRows: z.number().int().min(1).max(1e4)
@@ -2335,6 +2336,7 @@ var FLIPPED = {
2335
2336
  ">=": "<="
2336
2337
  };
2337
2338
  function resolveTable(resolver, table) {
2339
+ resolver.onTable?.(table);
2338
2340
  const info = resolver.tables[table];
2339
2341
  if (!info) {
2340
2342
  throw new PolicyCompileError(`unknown table '${table}'`, "unknown-table", Object.keys(resolver.tables));
@@ -3558,12 +3560,12 @@ function computeOpHash({
3558
3560
  definition,
3559
3561
  schemaHash
3560
3562
  }) {
3561
- const digest = createHash("sha256").update(OP_HASH_DOMAIN).update(`${COMPILER_MAJOR}\0${schemaHash}\0`).update(canonicalOperationText(definition)).digest("hex");
3562
- return `sha256:${digest}`;
3563
+ const digest2 = createHash("sha256").update(OP_HASH_DOMAIN).update(`${COMPILER_MAJOR}\0${schemaHash}\0`).update(canonicalOperationText(definition)).digest("hex");
3564
+ return `sha256:${digest2}`;
3563
3565
  }
3564
3566
  function computeOpsHash(opHashes) {
3565
- const digest = createHash("sha256").update(OPS_HASH_DOMAIN).update([...opHashes].sort().join("\n")).digest("hex");
3566
- return `sha256:${digest}`;
3567
+ const digest2 = createHash("sha256").update(OPS_HASH_DOMAIN).update([...opHashes].sort().join("\n")).digest("hex");
3568
+ return `sha256:${digest2}`;
3567
3569
  }
3568
3570
  var SOURCE_DIRECTIVES = /* @__PURE__ */ new Set(["prefetch", "writeback", "localOnly"]);
3569
3571
  var fail = (message, code) => {
@@ -5018,8 +5020,8 @@ function restrictOperation({
5018
5020
  // src/compiler-gql/artifact.ts
5019
5021
  var SCHEMA_HASH_DOMAIN = "sequence-orm-canonical-v2\0";
5020
5022
  function computeSchemaHash(canonical) {
5021
- const digest = createHash("sha256").update(SCHEMA_HASH_DOMAIN).update(stableJson(canonical)).digest("hex");
5022
- return `sha256:${digest}`;
5023
+ const digest2 = createHash("sha256").update(SCHEMA_HASH_DOMAIN).update(stableJson(canonical)).digest("hex");
5024
+ return `sha256:${digest2}`;
5023
5025
  }
5024
5026
  function compileNamespace({ canonical, sdl, documents }) {
5025
5027
  const { ctx, diagnostics } = buildCompileContext(canonical);
@@ -6473,10 +6475,13 @@ function sqlHash(value) {
6473
6475
  return `sha256:${createHash("sha256").update(value).digest("hex")}`;
6474
6476
  }
6475
6477
  function createSqlCatalog({ canonical, publishedObjects, executionTarget }) {
6476
- if (!publishedObjects.length || new Set(publishedObjects).size !== publishedObjects.length) throw new Error("SQL objects must be explicitly declared and unique");
6477
6478
  const { ctx, diagnostics } = buildCompileContext(canonical);
6478
6479
  if (diagnostics.some((d) => d.severity === "error")) throw new Error(diagnostics.map((d) => d.message).join("; "));
6479
- const identity = sqlHash(`ontology-sql-v1\0${computeSchemaHash(canonical)}\0${executionTarget}`);
6480
+ return createSqlCatalogFromContext({ canonical, publishedObjects, executionTarget, ctx });
6481
+ }
6482
+ function createSqlCatalogFromContext({ canonical, publishedObjects, executionTarget, ctx, identity: suppliedIdentity }) {
6483
+ if (!publishedObjects.length || new Set(publishedObjects).size !== publishedObjects.length) throw new Error("SQL objects must be explicitly declared and unique");
6484
+ const identity = suppliedIdentity ?? sqlHash(`ontology-sql-v1\0${computeSchemaHash(canonical)}\0${executionTarget}`);
6480
6485
  const logicalNames = new Map(Object.entries(ctx.tables).map(([key, meta]) => [meta, key]));
6481
6486
  const refOf = (meta) => `${meta.namespace ?? canonical.namespace}/${logicalNames.get(meta)}`;
6482
6487
  const definitions = [canonical, ...canonical.imports ?? []];
@@ -6613,9 +6618,10 @@ var SqlEmitter = class {
6613
6618
  only(cte, ["ctename", "ctequery", "ctematerialized", "location"]);
6614
6619
  const name2 = str(cte.ctename);
6615
6620
  if (scope.ctes.has(name2)) fail3("duplicate CTE");
6621
+ const materialization = cte.ctematerialized === "CTEMaterializeAlways" ? "MATERIALIZED " : cte.ctematerialized === "CTEMaterializeNever" ? "NOT MATERIALIZED " : cte.ctematerialized === "CTEMaterializeDefault" ? "" : fail3("unsupported CTE materialization");
6616
6622
  const result2 = this.select(obj(cte.ctequery), { ...parent, ctes: scope.ctes });
6617
6623
  scope.ctes.set(name2, result2);
6618
- ctes.push(`${quoteIdentifier(name2)} AS (${result2.text})`);
6624
+ ctes.push(`${quoteIdentifier(name2)} AS ${materialization}(${result2.text})`);
6619
6625
  }
6620
6626
  }
6621
6627
  const result = node.op === "SETOP_UNION" ? this.union(node, scope) : this.projection(node, scope);
@@ -7221,7 +7227,7 @@ function compileBuiltinSqlArtifact({ namespace, definitions, read, unbackedObjec
7221
7227
  if (owner !== namespace && selected.some((identity) => !definition.exports?.[identity.slice(owner.length + 1)]?.read)) {
7222
7228
  throw new Error("SQL object is not exported");
7223
7229
  }
7224
- objects.push(...createSqlCatalog({ canonical: definition, publishedObjects: selected, executionTarget }).objects);
7230
+ objects.push(...createSqlCatalogFromContext({ canonical: definition, publishedObjects: selected, executionTarget, ctx }).objects);
7225
7231
  }
7226
7232
  if (objects.length !== read.length) throw new Error("SQL object is unavailable");
7227
7233
  const actualRead = [...new Set(objects.flatMap((object) => object.read))].sort();
@@ -7233,7 +7239,7 @@ function compileBuiltinSqlArtifact({ namespace, definitions, read, unbackedObjec
7233
7239
  definitions.map((definition) => [definition.namespace, computeSchemaHash(definition)]).sort()
7234
7240
  ])) };
7235
7241
  return normalizeIr({
7236
- irVersion: RUNTIME_SQL_IR_VERSION,
7242
+ irVersion: usesServicePrincipal(policies) ? SERVICE_PRINCIPAL_IR_VERSION : RUNTIME_SQL_IR_VERSION,
7237
7243
  namespace,
7238
7244
  schemaHash: catalog.identity,
7239
7245
  ownSchemaHash: localHash(anchor),
@@ -7259,6 +7265,177 @@ function compileBuiltinSqlArtifact({ namespace, definitions, read, unbackedObjec
7259
7265
  } }
7260
7266
  });
7261
7267
  }
7268
+ var OBJECT_METADATA_FORMAT = 1;
7269
+ var digest = z.string().regex(/^sha256:[a-f0-9]{64}$/u);
7270
+ var objectSqlBundleSchema = z.object({
7271
+ format: z.literal(OBJECT_METADATA_FORMAT),
7272
+ dependencies: z.record(z.string(), digest),
7273
+ object: sqlObjectIrSchema,
7274
+ tables: z.record(z.string(), tableMetaIrSchema),
7275
+ readPolicies: z.record(z.string(), predIrSchema)
7276
+ }).strict();
7277
+ function contractHashes(canonical) {
7278
+ const hashes = /* @__PURE__ */ new Map();
7279
+ for (const owner of [canonical, ...canonical.imports ?? []]) {
7280
+ for (const relation of [...owner.tables, ...owner.views ?? []]) {
7281
+ const name2 = "table" in relation ? relation.table : relation.view;
7282
+ hashes.set(`${owner.namespace}/${name2}`, sqlHash(stableJson([
7283
+ "orm-object-contract-v1",
7284
+ owner.namespace,
7285
+ relation,
7286
+ owner.enums,
7287
+ owner.exports?.[name2]
7288
+ ])));
7289
+ }
7290
+ }
7291
+ return hashes;
7292
+ }
7293
+ function objectClosure({ roots, tables, policies, sourceDependencies }) {
7294
+ const required = /* @__PURE__ */ new Set(), links = /* @__PURE__ */ new Map();
7295
+ const walk = (pred, table) => {
7296
+ if (!pred) return;
7297
+ if (pred.kind === "and" || pred.kind === "or") for (const operand of pred.operands) walk(operand, table);
7298
+ else if (pred.kind === "not") walk(pred.operand, table);
7299
+ else if (pred.kind === "exists" || pred.kind === "aggPredicate") {
7300
+ const link = tables[table]?.links.find((candidate) => candidate.name === pred.link);
7301
+ if (!link) throw new Error("object policy dependency is unavailable");
7302
+ const used = links.get(table) ?? /* @__PURE__ */ new Set();
7303
+ used.add(link.name);
7304
+ links.set(table, used);
7305
+ visit2(link.target);
7306
+ walk(pred.where, link.target);
7307
+ }
7308
+ };
7309
+ const visit2 = (ref) => {
7310
+ if (required.has(ref)) return;
7311
+ const meta = tables[ref];
7312
+ if (!meta) throw new Error("object dependency is unavailable");
7313
+ required.add(ref);
7314
+ if (required.size > 1024) throw new Error("object dependency budget exceeded");
7315
+ walk(policies[ref], ref);
7316
+ for (const dependency of sourceDependencies.get(ref) ?? []) visit2(dependency);
7317
+ for (const backing of meta.dependencies ?? []) visit2(backing);
7318
+ };
7319
+ for (const root of roots) visit2(root);
7320
+ return { required: [...required].sort(), links };
7321
+ }
7322
+ async function compileObjectMetadata({ canonical: raw }) {
7323
+ const canonical = normalizeCanonical(canonicalDefinitionSchema.parse(raw));
7324
+ await validateManagedViewQueries({ canonical });
7325
+ const context = buildCompileContext(canonical);
7326
+ if (context.diagnostics.some((item) => item.severity === "error")) throw new Error("invalid object metadata definition");
7327
+ const { ctx } = context;
7328
+ const hashes = contractHashes(canonical);
7329
+ const ref = (key) => {
7330
+ const meta = ctx.tables[key];
7331
+ if (!meta) throw new Error("object dependency is unavailable");
7332
+ return `${meta.namespace ?? canonical.namespace}/${key}`;
7333
+ };
7334
+ const tables = {}, policies = {};
7335
+ const sourceDependencies = /* @__PURE__ */ new Map();
7336
+ const relations = [canonical, ...canonical.imports ?? []].flatMap(canonicalRelations);
7337
+ const expressions = new Map(relations.map((relation) => [relation.table, relation.policies.read]));
7338
+ for (const [key, meta] of Object.entries(ctx.tables)) {
7339
+ tables[ref(key)] = {
7340
+ ...meta,
7341
+ namespace: meta.namespace ?? canonical.namespace,
7342
+ links: meta.links.map((link) => ({ ...link, target: ref(link.target) })),
7343
+ ...meta.dependencies ? { dependencies: meta.dependencies.map(ref) } : {},
7344
+ ...meta.foreignReferences ? { foreignReferences: meta.foreignReferences.map((link) => ({ ...link, target: ref(link.target) })) } : {}
7345
+ };
7346
+ const policy = ctx.readPolicies.get(key);
7347
+ if (policy) policies[ref(key)] = policy;
7348
+ const expression = expressions.get(key);
7349
+ if (expression !== void 0) {
7350
+ const consulted = /* @__PURE__ */ new Set();
7351
+ compilePolicy({ expression, table: key, access: "read", resolver: {
7352
+ tables: ctx.tables,
7353
+ onTable: (table) => {
7354
+ consulted.add(ref(table));
7355
+ },
7356
+ readPolicy: (table) => expressions.get(table),
7357
+ policyNamespace: (table) => ctx.tables[table]?.namespace
7358
+ } });
7359
+ sourceDependencies.set(ref(key), [...consulted]);
7360
+ }
7361
+ }
7362
+ const objects = [];
7363
+ for (const relation of [...canonical.tables, ...canonical.views ?? []]) {
7364
+ const name2 = "table" in relation ? relation.table : relation.view;
7365
+ const identity = `${canonical.namespace}/${name2}`, contractHash = hashes.get(identity);
7366
+ let bundle = null;
7367
+ if (!relation.internal) {
7368
+ const object = createSqlCatalogFromContext({
7369
+ canonical,
7370
+ ctx,
7371
+ identity: contractHash,
7372
+ publishedObjects: [identity],
7373
+ executionTarget: "default"
7374
+ }).objects[0];
7375
+ const closure = objectClosure({ roots: object.read, tables, policies, sourceDependencies });
7376
+ bundle = objectSqlBundleSchema.parse({
7377
+ format: OBJECT_METADATA_FORMAT,
7378
+ object,
7379
+ // platformUsers is compiler-owned metadata, pinned by the format above.
7380
+ dependencies: Object.fromEntries(closure.required.filter((key) => hashes.has(key)).map((key) => [key, hashes.get(key)])),
7381
+ tables: Object.fromEntries(closure.required.map((key) => {
7382
+ const { foreignReferences: _writeReferences, ...meta } = tables[key];
7383
+ return [key, { ...meta, links: meta.links.filter((link) => closure.links.get(key)?.has(link.name)) }];
7384
+ })),
7385
+ readPolicies: Object.fromEntries(closure.required.filter((key) => policies[key]).map((key) => [key, policies[key]]))
7386
+ });
7387
+ }
7388
+ objects.push({ name: name2, contractHash, bundle });
7389
+ }
7390
+ return {
7391
+ format: OBJECT_METADATA_FORMAT,
7392
+ objects,
7393
+ relations: Object.values(ctx.tables).map(({ schema, table }) => ({ schema, table }))
7394
+ };
7395
+ }
7396
+ function composeObjectSqlArtifact({ namespace, bundles }) {
7397
+ const tables = {}, readPolicies = {};
7398
+ const pins = /* @__PURE__ */ new Map();
7399
+ const objects = bundles.map((bundle) => {
7400
+ if (!bundle.object.ref.startsWith(`${namespace}/`) && !bundle.tables[bundle.object.ref]?.exportRead) throw new Error("SQL object is not exported");
7401
+ for (const [ref, hash] of Object.entries(bundle.dependencies)) {
7402
+ if (pins.has(ref) && pins.get(ref) !== hash) throw new Error("inconsistent object contracts");
7403
+ pins.set(ref, hash);
7404
+ }
7405
+ for (const [ref, meta] of Object.entries(bundle.tables)) {
7406
+ const previous = tables[ref];
7407
+ const links = new Map([...previous?.links ?? [], ...meta.links].map((link) => [link.name, link]));
7408
+ tables[ref] = { ...meta, links: [...links.values()] };
7409
+ }
7410
+ Object.assign(readPolicies, bundle.readPolicies);
7411
+ return bundle.object;
7412
+ });
7413
+ const read = [...new Set(objects.flatMap((object) => object.read))].sort();
7414
+ const identity = sqlHash(stableJson(["orm-object-sql-v1", namespace, bundles]));
7415
+ return normalizeIr({
7416
+ irVersion: usesServicePrincipal(readPolicies) ? SERVICE_PRINCIPAL_IR_VERSION : RUNTIME_SQL_IR_VERSION,
7417
+ namespace,
7418
+ schemaHash: identity,
7419
+ opsHash: BUILTIN_SQL_READ_HASH,
7420
+ tables,
7421
+ readPolicies,
7422
+ operations: { BuiltinSqlRead: {
7423
+ irVersion: RUNTIME_SQL_IR_VERSION,
7424
+ name: "BuiltinSqlRead",
7425
+ opHash: BUILTIN_SQL_READ_HASH,
7426
+ language: "sql",
7427
+ kind: "query",
7428
+ requires: null,
7429
+ roots: [],
7430
+ tableSet: read,
7431
+ variables: [
7432
+ { name: "sql", type: { kind: "scalar", scalar: "text" }, nullable: false, list: false },
7433
+ { name: "parameters", type: { kind: "scalar", scalar: "jsonb" }, nullable: true, list: false }
7434
+ ],
7435
+ sqlQuery: { catalog: { identity, objects }, read, maxRows: 1e3 }
7436
+ } }
7437
+ });
7438
+ }
7262
7439
  var DATASET_PREVIEW_LIMIT = 100;
7263
7440
  function compileDatasetPreviews(input) {
7264
7441
  const canonical = normalizeCanonical(input);
@@ -7304,6 +7481,64 @@ function compileDatasetPreviews(input) {
7304
7481
  return operations;
7305
7482
  }
7306
7483
 
7307
- export { COMPILER_MAJOR, CONST_TRUE, DATASET_PREVIEW_LIMIT, DEFAULT_LIMIT, DocumentCompileError, MAX_LIMIT, NamespaceCompileError, ORDER_BY_DIRECTIONS, OperationLowerer, PLATFORM_USER_TABLE, PLATFORM_USER_TYPENAME, POLICY_COMPARE_OPS, POLICY_MAX_LINK_DEPTH, PolicyCompileError, PolicyParseError, allowedBoolExpOperators, allowedOps, andPred, assertClaimsOnlyWhen, bindNamedParameters, buildCompileContext, camelCase, canonicalOperationText, classifyInputType, collectPinnedColumns, compileBuiltinSqlArtifact, compileDatasetPreviews, compileDefaultOperations, compileNamespace, compileNamespaceOrThrow, compileOperationDocuments, compilePolicy, compilePredicateV2, compileRuntimeSql, computeOpHash, computeOpsHash, computePinnedColumnsByTable, computeSchemaHash, defineOperation, enumTypeName, flattenOperation, generateDefaultOperations, injectPolicies, inputTypeName, isSqlOperationDocument, lowerOperation, mutationRootNames, parseDocuments, parsePolicy, parseSdl, pascalCase, platformUserMeta, predContains, predContainsExists, queryRootNames, referencedSqlObjects, restrictOperation, sqlOperationDefinitionSchema, sqlQueryInputSchema, typeNameForTable, validateAppendInput, validateBoolExpInput, validateInsertInput, validateManagedViewQueries, validateOnConflictInput, validateOrderByInput, validateSelectColumns, validateSetInput, walkPolicy, walkPred };
7484
+ // src/compiler-gql/operation-metadata.ts
7485
+ var OPERATION_METADATA_FORMAT = 1;
7486
+ function projectOperationMetadata({ artifact, operation }) {
7487
+ const required = /* @__PURE__ */ new Set(), dynamic = /* @__PURE__ */ new Set();
7488
+ const visit2 = (table) => {
7489
+ if (required.has(table)) return;
7490
+ const meta = artifact.tables[table];
7491
+ if (!meta) throw new Error(`operation metadata references missing table '${table}'`);
7492
+ required.add(table);
7493
+ walk(artifact.readPolicies?.[table], table);
7494
+ for (const dependency of meta.dependencies ?? []) visit2(dependency);
7495
+ };
7496
+ const walk = (value, table) => {
7497
+ if (Array.isArray(value)) {
7498
+ for (const child of value) walk(child, table);
7499
+ return;
7500
+ }
7501
+ if (!value || typeof value !== "object") return;
7502
+ const node = value;
7503
+ let scope = typeof node.table === "string" && artifact.tables[node.table] ? node.table : table;
7504
+ if (scope !== table) visit2(scope);
7505
+ if (typeof node.link === "string") {
7506
+ const link = artifact.tables[scope]?.links.find((candidate) => candidate.name === node.link);
7507
+ if (!link) throw new Error("operation metadata has an unresolved relationship");
7508
+ scope = link.target;
7509
+ visit2(scope);
7510
+ }
7511
+ for (const [key, child] of Object.entries(node)) {
7512
+ if (["value", "objects", "set", "inc", "append", "pk", "onConflict"].includes(key)) continue;
7513
+ walk(child, scope);
7514
+ }
7515
+ };
7516
+ const visitDynamic = (table) => {
7517
+ if (dynamic.has(table)) return;
7518
+ dynamic.add(table);
7519
+ visit2(table);
7520
+ for (const link of artifact.tables[table].links) visitDynamic(link.target);
7521
+ };
7522
+ for (const table of operation.tableSet) visit2(table);
7523
+ for (const root of operation.roots) {
7524
+ visit2(root.table);
7525
+ walk(root, root.table);
7526
+ if (root.kind === "mutation" && !["delete", "deleteByPk", "cowRevert"].includes(root.op)) {
7527
+ for (const reference of artifact.tables[root.table].foreignReferences ?? []) visit2(reference.target);
7528
+ }
7529
+ }
7530
+ for (const variable of operation.variables) if (variable.type.kind === "inputRef") {
7531
+ visit2(variable.type.table);
7532
+ if (["boolExp", "orderBy"].includes(variable.type.input)) visitDynamic(variable.type.table);
7533
+ }
7534
+ return normalizeIr({
7535
+ ...artifact,
7536
+ tables: Object.fromEntries([...required].sort().map((table) => [table, artifact.tables[table]])),
7537
+ readPolicies: Object.fromEntries([...required].filter((table) => artifact.readPolicies?.[table]).map((table) => [table, artifact.readPolicies[table]])),
7538
+ operations: { [operation.name]: operation }
7539
+ });
7540
+ }
7541
+
7542
+ export { COMPILER_MAJOR, CONST_TRUE, DATASET_PREVIEW_LIMIT, DEFAULT_LIMIT, DocumentCompileError, MAX_LIMIT, NamespaceCompileError, OBJECT_METADATA_FORMAT, OPERATION_METADATA_FORMAT, ORDER_BY_DIRECTIONS, OperationLowerer, PLATFORM_USER_TABLE, PLATFORM_USER_TYPENAME, POLICY_COMPARE_OPS, POLICY_MAX_LINK_DEPTH, PolicyCompileError, PolicyParseError, allowedBoolExpOperators, allowedOps, andPred, assertClaimsOnlyWhen, bindNamedParameters, buildCompileContext, camelCase, canonicalOperationText, classifyInputType, collectPinnedColumns, compileBuiltinSqlArtifact, compileDatasetPreviews, compileDefaultOperations, compileNamespace, compileNamespaceOrThrow, compileObjectMetadata, compileOperationDocuments, compilePolicy, compilePredicateV2, compileRuntimeSql, composeObjectSqlArtifact, computeOpHash, computeOpsHash, computePinnedColumnsByTable, computeSchemaHash, defineOperation, enumTypeName, flattenOperation, generateDefaultOperations, injectPolicies, inputTypeName, isSqlOperationDocument, lowerOperation, mutationRootNames, objectSqlBundleSchema, parseDocuments, parsePolicy, parseSdl, pascalCase, platformUserMeta, predContains, predContainsExists, projectOperationMetadata, queryRootNames, referencedSqlObjects, restrictOperation, sqlOperationDefinitionSchema, sqlQueryInputSchema, typeNameForTable, validateAppendInput, validateBoolExpInput, validateInsertInput, validateManagedViewQueries, validateOnConflictInput, validateOrderByInput, validateSelectColumns, validateSetInput, walkPolicy, walkPred };
7308
7543
  //# sourceMappingURL=compiler.js.map
7309
7544
  //# sourceMappingURL=compiler.js.map