@sequenceholdings/orm 2.5.0 → 2.6.1
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/README.md +23 -0
- package/dist/cli.cjs +23 -11
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +23 -11
- package/dist/cli.js.map +1 -1
- package/dist/client.cjs +10 -5
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +37 -30
- package/dist/client.d.ts +37 -30
- package/dist/client.js +10 -6
- package/dist/client.js.map +1 -1
- package/dist/compiler.cjs +127 -9
- package/dist/compiler.cjs.map +1 -1
- package/dist/compiler.d.cts +25 -2
- package/dist/compiler.d.ts +25 -2
- package/dist/compiler.js +125 -10
- package/dist/compiler.js.map +1 -1
- package/dist/index.cjs +260 -138
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +25 -3
- package/dist/index.d.ts +25 -3
- package/dist/index.js +260 -139
- package/dist/index.js.map +1 -1
- package/dist/ir.cjs +5 -1
- package/dist/ir.cjs.map +1 -1
- package/dist/ir.js +5 -1
- package/dist/ir.js.map +1 -1
- package/dist/predicate-v2.cjs +5 -1
- package/dist/predicate-v2.cjs.map +1 -1
- package/dist/predicate-v2.js +5 -1
- package/dist/predicate-v2.js.map +1 -1
- package/dist/sdl.cjs +7 -1
- package/dist/sdl.cjs.map +1 -1
- package/dist/sdl.js +7 -1
- package/dist/sdl.js.map +1 -1
- package/package.json +1 -1
- package/templates/orm-namespace/package.json +2 -0
- package/templates/orm-namespace/schema/tables.ts +7 -3
package/dist/compiler.d.cts
CHANGED
|
@@ -484,11 +484,34 @@ declare const sqlQueryInputSchema: z.ZodObject<{
|
|
|
484
484
|
}, z.core.$strict>;
|
|
485
485
|
type SqlQueryInput = z.infer<typeof sqlQueryInputSchema>;
|
|
486
486
|
/** The returned plan contains no bound parameter values or caller identity. */
|
|
487
|
-
declare function compileRuntimeSql({ operation, input }: {
|
|
487
|
+
declare function compileRuntimeSql({ operation, input, qualified }: {
|
|
488
488
|
operation: CompiledOperation;
|
|
489
489
|
input: SqlQueryInput;
|
|
490
|
+
qualified?: boolean;
|
|
490
491
|
}): Promise<CompiledOperation>;
|
|
491
492
|
|
|
493
|
+
/** Discover identities from parsed syntax only; the closed compiler validates
|
|
494
|
+
* every clause before execution. Unqualified names may be CTEs, never objects. */
|
|
495
|
+
declare function referencedSqlObjects({ sql }: {
|
|
496
|
+
sql: string;
|
|
497
|
+
}): Promise<string[]>;
|
|
498
|
+
|
|
499
|
+
/** Replace named binds only in SQL code, never strings, identifiers, or comments. */
|
|
500
|
+
declare function bindNamedParameters({ sql, names }: {
|
|
501
|
+
sql: string;
|
|
502
|
+
names: string[];
|
|
503
|
+
}): string;
|
|
504
|
+
|
|
505
|
+
/** Compose SQL metadata by qualified identity. GraphQL's bare-name composition
|
|
506
|
+
* is deliberately not used across unrelated namespace catalogs. */
|
|
507
|
+
declare function compileBuiltinSqlArtifact({ namespace, definitions, read, unbackedObjects, executionTarget }: {
|
|
508
|
+
namespace: string;
|
|
509
|
+
definitions: readonly CanonicalDefinition[];
|
|
510
|
+
read: readonly string[];
|
|
511
|
+
unbackedObjects?: readonly string[];
|
|
512
|
+
executionTarget?: string;
|
|
513
|
+
}): CompiledArtifact;
|
|
514
|
+
|
|
492
515
|
declare const DATASET_PREVIEW_LIMIT = 100;
|
|
493
516
|
/**
|
|
494
517
|
* Fixed runtime-owned reads, separate from the published operation manifest.
|
|
@@ -508,4 +531,4 @@ declare function validateManagedViewQueries({ canonical }: {
|
|
|
508
531
|
canonical: CanonicalDefinition;
|
|
509
532
|
}): Promise<void>;
|
|
510
533
|
|
|
511
|
-
export { type BuildContextResult, COMPILER_MAJOR, CONST_TRUE, type ClientManifest, type ClientManifestOperation, type CompileContext, type CompileNamespaceInput, type CompileNamespaceResult, type CompilerDiagnostic, DATASET_PREVIEW_LIMIT, DEFAULT_LIMIT, type DiagnosticSeverity, DocumentCompileError, MAX_LIMIT, type MutationOp, type MutationRootInfo, NamespaceCompileError, OperationLowerer, PLATFORM_USER_TABLE, type ParseDocumentsResult, type ParsedDocument, type PinnedColumn, type QueryRootInfo, type RestrictedOperation, type SourceDocument, type SqlQueryInput, andPred, buildCompileContext, canonicalOperationText, classifyInputType, collectPinnedColumns, compileDatasetPreviews, compileNamespace, compileNamespaceOrThrow, compileOperationDocuments, compileRuntimeSql, computeOpHash, computeOpsHash, computePinnedColumnsByTable, computeSchemaHash, flattenOperation, injectPolicies, inputTypeName, isSqlOperationDocument, lowerOperation, mutationRootNames, parseDocuments, parseSdl, platformUserMeta, predContains, predContainsExists, queryRootNames, restrictOperation, sqlQueryInputSchema, typeNameForTable, validateManagedViewQueries, walkPred };
|
|
534
|
+
export { type BuildContextResult, COMPILER_MAJOR, CONST_TRUE, type ClientManifest, type ClientManifestOperation, type CompileContext, type CompileNamespaceInput, type CompileNamespaceResult, type CompilerDiagnostic, DATASET_PREVIEW_LIMIT, DEFAULT_LIMIT, type DiagnosticSeverity, DocumentCompileError, MAX_LIMIT, type MutationOp, type MutationRootInfo, NamespaceCompileError, OperationLowerer, PLATFORM_USER_TABLE, type ParseDocumentsResult, type ParsedDocument, type PinnedColumn, type QueryRootInfo, type RestrictedOperation, type SourceDocument, type SqlQueryInput, andPred, bindNamedParameters, buildCompileContext, canonicalOperationText, classifyInputType, collectPinnedColumns, compileBuiltinSqlArtifact, compileDatasetPreviews, compileNamespace, compileNamespaceOrThrow, compileOperationDocuments, compileRuntimeSql, computeOpHash, computeOpsHash, computePinnedColumnsByTable, computeSchemaHash, flattenOperation, injectPolicies, inputTypeName, isSqlOperationDocument, lowerOperation, mutationRootNames, parseDocuments, parseSdl, platformUserMeta, predContains, predContainsExists, queryRootNames, referencedSqlObjects, restrictOperation, sqlQueryInputSchema, typeNameForTable, validateManagedViewQueries, walkPred };
|
package/dist/compiler.d.ts
CHANGED
|
@@ -484,11 +484,34 @@ declare const sqlQueryInputSchema: z.ZodObject<{
|
|
|
484
484
|
}, z.core.$strict>;
|
|
485
485
|
type SqlQueryInput = z.infer<typeof sqlQueryInputSchema>;
|
|
486
486
|
/** The returned plan contains no bound parameter values or caller identity. */
|
|
487
|
-
declare function compileRuntimeSql({ operation, input }: {
|
|
487
|
+
declare function compileRuntimeSql({ operation, input, qualified }: {
|
|
488
488
|
operation: CompiledOperation;
|
|
489
489
|
input: SqlQueryInput;
|
|
490
|
+
qualified?: boolean;
|
|
490
491
|
}): Promise<CompiledOperation>;
|
|
491
492
|
|
|
493
|
+
/** Discover identities from parsed syntax only; the closed compiler validates
|
|
494
|
+
* every clause before execution. Unqualified names may be CTEs, never objects. */
|
|
495
|
+
declare function referencedSqlObjects({ sql }: {
|
|
496
|
+
sql: string;
|
|
497
|
+
}): Promise<string[]>;
|
|
498
|
+
|
|
499
|
+
/** Replace named binds only in SQL code, never strings, identifiers, or comments. */
|
|
500
|
+
declare function bindNamedParameters({ sql, names }: {
|
|
501
|
+
sql: string;
|
|
502
|
+
names: string[];
|
|
503
|
+
}): string;
|
|
504
|
+
|
|
505
|
+
/** Compose SQL metadata by qualified identity. GraphQL's bare-name composition
|
|
506
|
+
* is deliberately not used across unrelated namespace catalogs. */
|
|
507
|
+
declare function compileBuiltinSqlArtifact({ namespace, definitions, read, unbackedObjects, executionTarget }: {
|
|
508
|
+
namespace: string;
|
|
509
|
+
definitions: readonly CanonicalDefinition[];
|
|
510
|
+
read: readonly string[];
|
|
511
|
+
unbackedObjects?: readonly string[];
|
|
512
|
+
executionTarget?: string;
|
|
513
|
+
}): CompiledArtifact;
|
|
514
|
+
|
|
492
515
|
declare const DATASET_PREVIEW_LIMIT = 100;
|
|
493
516
|
/**
|
|
494
517
|
* Fixed runtime-owned reads, separate from the published operation manifest.
|
|
@@ -508,4 +531,4 @@ declare function validateManagedViewQueries({ canonical }: {
|
|
|
508
531
|
canonical: CanonicalDefinition;
|
|
509
532
|
}): Promise<void>;
|
|
510
533
|
|
|
511
|
-
export { type BuildContextResult, COMPILER_MAJOR, CONST_TRUE, type ClientManifest, type ClientManifestOperation, type CompileContext, type CompileNamespaceInput, type CompileNamespaceResult, type CompilerDiagnostic, DATASET_PREVIEW_LIMIT, DEFAULT_LIMIT, type DiagnosticSeverity, DocumentCompileError, MAX_LIMIT, type MutationOp, type MutationRootInfo, NamespaceCompileError, OperationLowerer, PLATFORM_USER_TABLE, type ParseDocumentsResult, type ParsedDocument, type PinnedColumn, type QueryRootInfo, type RestrictedOperation, type SourceDocument, type SqlQueryInput, andPred, buildCompileContext, canonicalOperationText, classifyInputType, collectPinnedColumns, compileDatasetPreviews, compileNamespace, compileNamespaceOrThrow, compileOperationDocuments, compileRuntimeSql, computeOpHash, computeOpsHash, computePinnedColumnsByTable, computeSchemaHash, flattenOperation, injectPolicies, inputTypeName, isSqlOperationDocument, lowerOperation, mutationRootNames, parseDocuments, parseSdl, platformUserMeta, predContains, predContainsExists, queryRootNames, restrictOperation, sqlQueryInputSchema, typeNameForTable, validateManagedViewQueries, walkPred };
|
|
534
|
+
export { type BuildContextResult, COMPILER_MAJOR, CONST_TRUE, type ClientManifest, type ClientManifestOperation, type CompileContext, type CompileNamespaceInput, type CompileNamespaceResult, type CompilerDiagnostic, DATASET_PREVIEW_LIMIT, DEFAULT_LIMIT, type DiagnosticSeverity, DocumentCompileError, MAX_LIMIT, type MutationOp, type MutationRootInfo, NamespaceCompileError, OperationLowerer, PLATFORM_USER_TABLE, type ParseDocumentsResult, type ParsedDocument, type PinnedColumn, type QueryRootInfo, type RestrictedOperation, type SourceDocument, type SqlQueryInput, andPred, bindNamedParameters, buildCompileContext, canonicalOperationText, classifyInputType, collectPinnedColumns, compileBuiltinSqlArtifact, compileDatasetPreviews, compileNamespace, compileNamespaceOrThrow, compileOperationDocuments, compileRuntimeSql, computeOpHash, computeOpsHash, computePinnedColumnsByTable, computeSchemaHash, flattenOperation, injectPolicies, inputTypeName, isSqlOperationDocument, lowerOperation, mutationRootNames, parseDocuments, parseSdl, platformUserMeta, predContains, predContainsExists, queryRootNames, referencedSqlObjects, restrictOperation, sqlQueryInputSchema, typeNameForTable, validateManagedViewQueries, walkPred };
|
package/dist/compiler.js
CHANGED
|
@@ -1308,6 +1308,9 @@ function normalizeCanonical(definition) {
|
|
|
1308
1308
|
return normalized;
|
|
1309
1309
|
}
|
|
1310
1310
|
|
|
1311
|
+
// src/client/sql.ts
|
|
1312
|
+
var BUILTIN_SQL_READ_HASH = "sha256:a50c477c952a5e0fe68ed158a4530e4aab573c09bcbb1a8ac454dc88a39a6258";
|
|
1313
|
+
|
|
1311
1314
|
// src/ir/index.ts
|
|
1312
1315
|
var IR_VERSION = 5;
|
|
1313
1316
|
var LEGACY_IR_VERSION = 1;
|
|
@@ -1641,7 +1644,8 @@ var compiledOperationSchema = z.object({
|
|
|
1641
1644
|
}).superRefine((operation, ctx) => {
|
|
1642
1645
|
if (operation.language === "sql") {
|
|
1643
1646
|
const validPlan = operation.sqlQuery ? !operation.sql && operation.irVersion === RUNTIME_SQL_IR_VERSION : !!operation.sql && operation.irVersion === SQL_IR_VERSION;
|
|
1644
|
-
|
|
1647
|
+
const builtin = operation.name === "BuiltinSqlRead" && operation.opHash === BUILTIN_SQL_READ_HASH && operation.requires === null;
|
|
1648
|
+
if (!validPlan || operation.kind !== "query" || operation.roots.length !== 0 || !builtin && !operation.requires?.capability) {
|
|
1645
1649
|
ctx.addIssue({ code: "custom", message: "SQL operations require a query-only v4 plan or v5 runtime contract, capability, and no GraphQL roots" });
|
|
1646
1650
|
}
|
|
1647
1651
|
} else if (operation.sql || operation.sqlQuery || operation.roots.length === 0) {
|
|
@@ -5419,9 +5423,9 @@ function compilePredIrToSql(pred, options = {}) {
|
|
|
5419
5423
|
case "cmp":
|
|
5420
5424
|
return compileCmp(pred.op, pred.column, pred.value, options);
|
|
5421
5425
|
case "capability":
|
|
5422
|
-
return `(${capabilityExpression(pred.key, pred.namespace ?? options.namespace)})`;
|
|
5426
|
+
return `(${options.statementClaimChecks ? "SELECT " : ""}${capabilityExpression(pred.key, pred.namespace ?? options.namespace)})`;
|
|
5423
5427
|
case "role":
|
|
5424
|
-
return `(${roleExpression(pred.key, pred.namespace ?? options.namespace)})`;
|
|
5428
|
+
return `(${options.statementClaimChecks ? "SELECT " : ""}${roleExpression(pred.key, pred.namespace ?? options.namespace)})`;
|
|
5425
5429
|
case "exists":
|
|
5426
5430
|
if (options.exists) return options.exists(pred);
|
|
5427
5431
|
throw new OrmDefinitionError("synced view read policy cannot use 'exists' without a relationship resolver");
|
|
@@ -5529,7 +5533,8 @@ function createSqlCatalog({ canonical, publishedObjects, executionTarget }) {
|
|
|
5529
5533
|
const { ctx, diagnostics } = buildCompileContext(canonical);
|
|
5530
5534
|
if (diagnostics.some((d) => d.severity === "error")) throw new Error(diagnostics.map((d) => d.message).join("; "));
|
|
5531
5535
|
const identity = sqlHash(`ontology-sql-v1\0${computeSchemaHash(canonical)}\0${executionTarget}`);
|
|
5532
|
-
const
|
|
5536
|
+
const logicalNames = new Map(Object.entries(ctx.tables).map(([key, meta]) => [meta, key]));
|
|
5537
|
+
const refOf = (meta) => `${meta.namespace ?? canonical.namespace}/${logicalNames.get(meta)}`;
|
|
5533
5538
|
const definitions = [canonical, ...canonical.imports ?? []];
|
|
5534
5539
|
const internal = new Set(definitions.flatMap((owner) => [
|
|
5535
5540
|
...owner.tables.filter((t) => t.internal).map((t) => `${owner.namespace}/${t.table}`),
|
|
@@ -5605,15 +5610,48 @@ function only(node, keys) {
|
|
|
5605
5610
|
var parser;
|
|
5606
5611
|
var SQL_TYPES = ["text", "boolean", "integer", "bigint", "numeric", "double", "uuid", "date", "timestamptz"];
|
|
5607
5612
|
var pgType = (type) => type === "double" ? "double precision" : SQL_TYPES.some((t) => t === type) ? type : fail3("unsupported SQL type");
|
|
5608
|
-
async function
|
|
5609
|
-
if (
|
|
5613
|
+
async function parseSelect(sql) {
|
|
5614
|
+
if (Buffer.byteLength(sql) > 65536) fail3("SQL limit exceeded");
|
|
5610
5615
|
parser ??= new PgParser({ version: 17 });
|
|
5611
5616
|
const parsed = await parser.parse(sql);
|
|
5612
5617
|
if (parsed.error || !parsed.tree) fail3("invalid SQL");
|
|
5613
5618
|
const statements = list(obj(parsed.tree).stmts);
|
|
5614
5619
|
if (statements.length !== 1) fail3("one SQL SELECT is required");
|
|
5620
|
+
const statement = obj(obj(statements[0]).stmt);
|
|
5621
|
+
if (!statement.SelectStmt) fail3("one SQL SELECT is required");
|
|
5622
|
+
return statement;
|
|
5623
|
+
}
|
|
5624
|
+
async function referencedSqlObjects({ sql }) {
|
|
5625
|
+
const objects = /* @__PURE__ */ new Set();
|
|
5626
|
+
let nodes = 0;
|
|
5627
|
+
function visit2(value, depth) {
|
|
5628
|
+
if (++nodes > 1e4 || depth > 96) fail3("SQL complexity limit exceeded");
|
|
5629
|
+
if (Array.isArray(value)) {
|
|
5630
|
+
for (const child of value) visit2(child, depth + 1);
|
|
5631
|
+
return;
|
|
5632
|
+
}
|
|
5633
|
+
if (!value || typeof value !== "object") return;
|
|
5634
|
+
const node = obj(value);
|
|
5635
|
+
if (node.RangeVar) {
|
|
5636
|
+
const range = obj(node.RangeVar);
|
|
5637
|
+
if (range.schemaname) {
|
|
5638
|
+
const namespace = str(range.schemaname), name2 = str(range.relname);
|
|
5639
|
+
if (!/^[a-z][a-z0-9_]{0,40}$/.test(namespace) || namespace === "pg_catalog" || namespace === "information_schema") fail3("invalid ontology namespace");
|
|
5640
|
+
objects.add(`${namespace}/${name2}`);
|
|
5641
|
+
if (objects.size > 256) fail3("too many SQL objects");
|
|
5642
|
+
}
|
|
5643
|
+
}
|
|
5644
|
+
for (const child of Object.values(node)) visit2(child, depth + 1);
|
|
5645
|
+
}
|
|
5646
|
+
visit2(await parseSelect(sql), 0);
|
|
5647
|
+
if (!objects.size) fail3("SQL operation must read an ontology object");
|
|
5648
|
+
return [...objects].sort();
|
|
5649
|
+
}
|
|
5650
|
+
async function compileOntologySql({ catalog, sql, parameterTypes = [], maxRows = 1e3 }) {
|
|
5651
|
+
if (!Number.isInteger(maxRows) || maxRows < 1 || maxRows > 1e4 || Buffer.byteLength(sql) > 65536) fail3("SQL limit exceeded");
|
|
5652
|
+
const statement = await parseSelect(sql);
|
|
5615
5653
|
const emitter = new SqlEmitter({ catalog, parameterTypes });
|
|
5616
|
-
const result = emitter.select(
|
|
5654
|
+
const result = emitter.select(statement, { relations: [], ctes: /* @__PURE__ */ new Map() });
|
|
5617
5655
|
if (emitter.used.size !== parameterTypes.length) fail3("SQL parameters must be used exactly as declared");
|
|
5618
5656
|
if (!emitter.read.size) fail3("SQL operation must read an ontology object");
|
|
5619
5657
|
return {
|
|
@@ -6201,7 +6239,7 @@ var sqlQueryInputSchema = z.object({
|
|
|
6201
6239
|
sql: z.string().min(1).max(65536).refine((value) => Buffer.byteLength(value) <= 65536, "SQL exceeds 64 KiB"),
|
|
6202
6240
|
parameters: z.record(parameterName, parameter).refine((value) => Object.keys(value).length <= 128, "too many SQL parameters").default({})
|
|
6203
6241
|
}).strict();
|
|
6204
|
-
async function compileRuntimeSql({ operation, input }) {
|
|
6242
|
+
async function compileRuntimeSql({ operation, input, qualified = false }) {
|
|
6205
6243
|
const contract = operation.sqlQuery;
|
|
6206
6244
|
if (!contract) throw new Error("missing runtime SQL contract");
|
|
6207
6245
|
const names = Object.keys(input.parameters).sort();
|
|
@@ -6217,10 +6255,87 @@ async function compileRuntimeSql({ operation, input }) {
|
|
|
6217
6255
|
sqlQuery: void 0,
|
|
6218
6256
|
irVersion: SQL_IR_VERSION,
|
|
6219
6257
|
variables: names.map((name2) => ({ name: name2, type: { kind: "scalar", scalar: input.parameters[name2].type }, nullable: true, list: false })),
|
|
6220
|
-
tableSet: plan.read.map((ref) => ref.split("/")[1]).sort(),
|
|
6258
|
+
tableSet: qualified ? plan.read : plan.read.map((ref) => ref.split("/")[1]).sort(),
|
|
6221
6259
|
sql: { text: plan.text, columns: plan.columns, parameters: names, read: plan.read, maxRows: plan.maxRows }
|
|
6222
6260
|
});
|
|
6223
6261
|
}
|
|
6262
|
+
|
|
6263
|
+
// src/sql/builtin.ts
|
|
6264
|
+
function localHash(definition) {
|
|
6265
|
+
const { imports: _imports, ...local } = definition;
|
|
6266
|
+
return computeSchemaHash(normalizeCanonical(local));
|
|
6267
|
+
}
|
|
6268
|
+
function compileBuiltinSqlArtifact({ namespace, definitions, read, unbackedObjects = [], executionTarget = "default" }) {
|
|
6269
|
+
const anchor = definitions.find((definition) => definition.namespace === namespace);
|
|
6270
|
+
if (!anchor) throw new Error("missing SQL namespace definition");
|
|
6271
|
+
const tables = {};
|
|
6272
|
+
const policies = {};
|
|
6273
|
+
const objects = [];
|
|
6274
|
+
for (const definition of definitions) {
|
|
6275
|
+
const owner = definition.namespace;
|
|
6276
|
+
const { ctx, diagnostics } = buildCompileContext(definition);
|
|
6277
|
+
if (diagnostics.some((diagnostic) => diagnostic.severity === "error")) throw new Error("SQL namespace definition is invalid");
|
|
6278
|
+
const ref = (key) => {
|
|
6279
|
+
const meta = ctx.tables[key];
|
|
6280
|
+
if (!meta) throw new Error("SQL dependency is unavailable");
|
|
6281
|
+
return `${meta.namespace ?? owner}/${key}`;
|
|
6282
|
+
};
|
|
6283
|
+
for (const [key, meta] of Object.entries(ctx.tables)) {
|
|
6284
|
+
if ((meta.namespace ?? owner) !== owner) continue;
|
|
6285
|
+
const identity = ref(key);
|
|
6286
|
+
tables[identity] = {
|
|
6287
|
+
...meta,
|
|
6288
|
+
namespace: owner,
|
|
6289
|
+
links: meta.links.map((link) => ({ ...link, ...link.target ? { target: ref(link.target) } : {} })),
|
|
6290
|
+
...meta.dependencies ? { dependencies: meta.dependencies.map(ref) } : {},
|
|
6291
|
+
...meta.foreignReferences ? { foreignReferences: meta.foreignReferences.map((link) => ({ ...link, target: ref(link.target) })) } : {}
|
|
6292
|
+
};
|
|
6293
|
+
const policy = ctx.readPolicies.get(key);
|
|
6294
|
+
if (policy) policies[identity] = policy;
|
|
6295
|
+
}
|
|
6296
|
+
const selected = read.filter((identity) => identity.startsWith(`${owner}/`));
|
|
6297
|
+
if (!selected.length) continue;
|
|
6298
|
+
if (owner !== namespace && selected.some((identity) => !definition.exports?.[identity.slice(owner.length + 1)]?.read)) {
|
|
6299
|
+
throw new Error("SQL object is not exported");
|
|
6300
|
+
}
|
|
6301
|
+
objects.push(...createSqlCatalog({ canonical: definition, publishedObjects: selected, executionTarget }).objects);
|
|
6302
|
+
}
|
|
6303
|
+
if (objects.length !== read.length) throw new Error("SQL object is unavailable");
|
|
6304
|
+
const actualRead = [...new Set(objects.flatMap((object) => object.read))].sort();
|
|
6305
|
+
const catalog = { objects, identity: sqlHash(JSON.stringify([
|
|
6306
|
+
"builtin-sql-catalog-v1",
|
|
6307
|
+
namespace,
|
|
6308
|
+
executionTarget,
|
|
6309
|
+
read,
|
|
6310
|
+
definitions.map((definition) => [definition.namespace, computeSchemaHash(definition)]).sort()
|
|
6311
|
+
])) };
|
|
6312
|
+
return normalizeIr({
|
|
6313
|
+
irVersion: RUNTIME_SQL_IR_VERSION,
|
|
6314
|
+
namespace,
|
|
6315
|
+
schemaHash: catalog.identity,
|
|
6316
|
+
ownSchemaHash: localHash(anchor),
|
|
6317
|
+
opsHash: BUILTIN_SQL_READ_HASH,
|
|
6318
|
+
dependencies: Object.fromEntries(definitions.filter((definition) => definition.namespace !== namespace).map((definition) => [definition.namespace, localHash(definition)])),
|
|
6319
|
+
tables,
|
|
6320
|
+
readPolicies: policies,
|
|
6321
|
+
unbackedTables: [...unbackedObjects],
|
|
6322
|
+
operations: { BuiltinSqlRead: {
|
|
6323
|
+
irVersion: RUNTIME_SQL_IR_VERSION,
|
|
6324
|
+
name: "BuiltinSqlRead",
|
|
6325
|
+
opHash: BUILTIN_SQL_READ_HASH,
|
|
6326
|
+
language: "sql",
|
|
6327
|
+
kind: "query",
|
|
6328
|
+
requires: null,
|
|
6329
|
+
roots: [],
|
|
6330
|
+
tableSet: actualRead,
|
|
6331
|
+
variables: [
|
|
6332
|
+
{ name: "sql", type: { kind: "scalar", scalar: "text" }, nullable: false, list: false },
|
|
6333
|
+
{ name: "parameters", type: { kind: "scalar", scalar: "jsonb" }, nullable: true, list: false }
|
|
6334
|
+
],
|
|
6335
|
+
sqlQuery: { catalog, read: actualRead, maxRows: 1e3 }
|
|
6336
|
+
} }
|
|
6337
|
+
});
|
|
6338
|
+
}
|
|
6224
6339
|
var DATASET_PREVIEW_LIMIT = 100;
|
|
6225
6340
|
function compileDatasetPreviews(input) {
|
|
6226
6341
|
const canonical = normalizeCanonical(input);
|
|
@@ -6266,6 +6381,6 @@ function compileDatasetPreviews(input) {
|
|
|
6266
6381
|
return operations;
|
|
6267
6382
|
}
|
|
6268
6383
|
|
|
6269
|
-
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, buildCompileContext, camelCase, canonicalOperationText, classifyInputType, collectPinnedColumns, compileDatasetPreviews, compileNamespace, compileNamespaceOrThrow, compileOperationDocuments, compilePolicy, compilePredicateV2, compileRuntimeSql, computeOpHash, computeOpsHash, computePinnedColumnsByTable, computeSchemaHash, defineOperation, enumTypeName, flattenOperation, injectPolicies, inputTypeName, isSqlOperationDocument, lowerOperation, mutationRootNames, parseDocuments, parsePolicy, parseSdl, pascalCase, platformUserMeta, predContains, predContainsExists, queryRootNames, restrictOperation, sqlOperationDefinitionSchema, sqlQueryInputSchema, typeNameForTable, validateAppendInput, validateBoolExpInput, validateInsertInput, validateManagedViewQueries, validateOnConflictInput, validateOrderByInput, validateSelectColumns, validateSetInput, walkPolicy, walkPred };
|
|
6384
|
+
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, compileNamespace, compileNamespaceOrThrow, compileOperationDocuments, compilePolicy, compilePredicateV2, compileRuntimeSql, computeOpHash, computeOpsHash, computePinnedColumnsByTable, computeSchemaHash, defineOperation, enumTypeName, flattenOperation, 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 };
|
|
6270
6385
|
//# sourceMappingURL=compiler.js.map
|
|
6271
6386
|
//# sourceMappingURL=compiler.js.map
|