@malloy-publisher/server 0.18.5 → 0.18.6
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/app/api-doc.yaml +37 -12
- package/dist/instrumentation.mjs +1 -1
- package/dist/package_load_worker.mjs +778 -492
- package/dist/server.mjs +1124 -342
- package/package.json +1 -1
package/dist/server.mjs
CHANGED
|
@@ -110771,6 +110771,20 @@ function readableSchemaScope(rootSlash, recorded) {
|
|
|
110771
110771
|
}
|
|
110772
110772
|
return `${rootSlash}${trimmed}/`;
|
|
110773
110773
|
}
|
|
110774
|
+
function recordManagedScope(connection, dbName, prefixes) {
|
|
110775
|
+
const holder = scopeHolder(connection);
|
|
110776
|
+
let byName = managedScopes.get(holder);
|
|
110777
|
+
if (!byName) {
|
|
110778
|
+
byName = new Map;
|
|
110779
|
+
managedScopes.set(holder, byName);
|
|
110780
|
+
}
|
|
110781
|
+
byName.set(dbName, [...prefixes]);
|
|
110782
|
+
}
|
|
110783
|
+
function managedScopeOf(connection, dbName) {
|
|
110784
|
+
if (!connection || typeof connection !== "object")
|
|
110785
|
+
return;
|
|
110786
|
+
return managedScopes.get(scopeHolder(connection))?.get(dbName);
|
|
110787
|
+
}
|
|
110774
110788
|
function storageSecretScope(input) {
|
|
110775
110789
|
const root = input.configuredDataPath || input.recordedDataPath;
|
|
110776
110790
|
if (!root || isBucketlessUrl(root))
|
|
@@ -110822,13 +110836,14 @@ function storageSecretScope(input) {
|
|
|
110822
110836
|
}
|
|
110823
110837
|
return [...new Set([mainScope, ...owners.map(([, prefix]) => prefix)])];
|
|
110824
110838
|
}
|
|
110825
|
-
var METADATA_CATALOG_PREFIX = "__ducklake_metadata_", ScopeContainmentError;
|
|
110839
|
+
var METADATA_CATALOG_PREFIX = "__ducklake_metadata_", managedScopes, scopeHolder = (connection) => duckDBInstanceOf(connection) ?? connection, ScopeContainmentError;
|
|
110826
110840
|
var init_ducklake_catalog = __esm(() => {
|
|
110827
110841
|
init_logger();
|
|
110828
110842
|
init_duckdb_lockdown();
|
|
110829
110843
|
init_connection_type();
|
|
110830
110844
|
init_duckdb_session_setup();
|
|
110831
110845
|
init_quoting();
|
|
110846
|
+
managedScopes = new WeakMap;
|
|
110832
110847
|
ScopeContainmentError = class ScopeContainmentError extends Error {
|
|
110833
110848
|
};
|
|
110834
110849
|
});
|
|
@@ -111187,6 +111202,10 @@ async function secureCatalogStorage(connection, dbName, storage, input) {
|
|
|
111187
111202
|
if (root)
|
|
111188
111203
|
allowForLockdown(connection, root);
|
|
111189
111204
|
}
|
|
111205
|
+
const allowed = (roots ?? []).filter((r) => !!r);
|
|
111206
|
+
if (managedView && allowed.length > 0) {
|
|
111207
|
+
recordManagedScope(connection, dbName, allowed);
|
|
111208
|
+
}
|
|
111190
111209
|
}
|
|
111191
111210
|
if (storage) {
|
|
111192
111211
|
try {
|
|
@@ -111203,6 +111222,8 @@ async function secureCatalogStorage(connection, dbName, storage, input) {
|
|
|
111203
111222
|
await attachCloudStorage(connection, storage, options.origin, scope);
|
|
111204
111223
|
for (const prefix of scope)
|
|
111205
111224
|
allowForLockdown(connection, prefix);
|
|
111225
|
+
if (managedView)
|
|
111226
|
+
recordManagedScope(connection, dbName, scope);
|
|
111206
111227
|
} catch (error) {
|
|
111207
111228
|
if (isInstanceLocked(connection)) {
|
|
111208
111229
|
logger.error("DuckLake storage secret failed after its instance was locked; the catalog is left attached", {
|
|
@@ -135432,10 +135453,19 @@ function keyUniquenessOfContract(contract, sources, leaves = []) {
|
|
|
135432
135453
|
if (source)
|
|
135433
135454
|
read("leaf", leaf.joinPath, source);
|
|
135434
135455
|
}
|
|
135456
|
+
const grainJoinKeys = {};
|
|
135457
|
+
for (const [name, check] of Object.entries(keys)) {
|
|
135458
|
+
const joinKey = contractKeyWithoutLevel(name, "grain_join");
|
|
135459
|
+
if (joinKey !== undefined && check.level === "grain_join") {
|
|
135460
|
+
grainJoinKeys[joinKey] = passed(check);
|
|
135461
|
+
}
|
|
135462
|
+
}
|
|
135435
135463
|
const anyParent = Object.keys(parentKeys).length > 0;
|
|
135436
|
-
|
|
135464
|
+
const anyGrainJoin = Object.keys(grainJoinKeys).length > 0;
|
|
135465
|
+
if (!own && !anyParent && !anyGrainJoin)
|
|
135437
135466
|
return;
|
|
135438
135467
|
return {
|
|
135468
|
+
...anyGrainJoin ? { grainJoinKeys } : {},
|
|
135439
135469
|
...own ? {
|
|
135440
135470
|
keyColumn: contractKeyWithoutLevel(own[0], "rollup"),
|
|
135441
135471
|
unique: passed(own[1])
|
|
@@ -141389,8 +141419,65 @@ var init_persist_annotation_validation = __esm(() => {
|
|
|
141389
141419
|
SAFE_NAME_PATH = /^[A-Za-z0-9_-]+(\.[A-Za-z0-9_-]+)*$/;
|
|
141390
141420
|
});
|
|
141391
141421
|
|
|
141392
|
-
// src/service/
|
|
141422
|
+
// src/service/governance/ir/sql_embeds.ts
|
|
141393
141423
|
import { isSourceDef as isSourceDef7 } from "@malloydata/malloy";
|
|
141424
|
+
function sqlSelectsWithin(root) {
|
|
141425
|
+
const found = [];
|
|
141426
|
+
const seen = new Set;
|
|
141427
|
+
const stack = [root];
|
|
141428
|
+
while (stack.length > 0) {
|
|
141429
|
+
const node = stack.pop();
|
|
141430
|
+
if (Array.isArray(node)) {
|
|
141431
|
+
stack.push(...node);
|
|
141432
|
+
continue;
|
|
141433
|
+
}
|
|
141434
|
+
if (!isObj2(node) || seen.has(node))
|
|
141435
|
+
continue;
|
|
141436
|
+
seen.add(node);
|
|
141437
|
+
if (node.type === "sql_select" && Array.isArray(node.selectSegments)) {
|
|
141438
|
+
found.push(node);
|
|
141439
|
+
}
|
|
141440
|
+
stack.push(...Object.values(node));
|
|
141441
|
+
}
|
|
141442
|
+
return found;
|
|
141443
|
+
}
|
|
141444
|
+
function embeddedStructs(segment, modelDef) {
|
|
141445
|
+
if (segment.type === "query") {
|
|
141446
|
+
const ref = segment.structRef;
|
|
141447
|
+
let base = ref;
|
|
141448
|
+
if (typeof ref === "string")
|
|
141449
|
+
base = modelDef.contents[ref];
|
|
141450
|
+
if (!isObj2(base) || !isSourceDef7(base)) {
|
|
141451
|
+
return {
|
|
141452
|
+
unreadable: "its source reference does not resolve in the model",
|
|
141453
|
+
label: typeof ref === "string" ? ref : "<embedded query>"
|
|
141454
|
+
};
|
|
141455
|
+
}
|
|
141456
|
+
const structs = [base];
|
|
141457
|
+
const resolved = segment.compositeResolvedSourceDef;
|
|
141458
|
+
if (isObj2(resolved) && isSourceDef7(resolved)) {
|
|
141459
|
+
structs.push(resolved);
|
|
141460
|
+
}
|
|
141461
|
+
return { structs };
|
|
141462
|
+
}
|
|
141463
|
+
if (isSourceDef7(segment)) {
|
|
141464
|
+
return { structs: [segment] };
|
|
141465
|
+
}
|
|
141466
|
+
return {
|
|
141467
|
+
unreadable: `its segment shape (type ${JSON.stringify(segment.type)}) is not one Publisher reads`,
|
|
141468
|
+
label: labelOf(segment)
|
|
141469
|
+
};
|
|
141470
|
+
}
|
|
141471
|
+
var isObj2 = (value) => typeof value === "object" && value !== null, INLINE_SQL = "<inline sql()>", labelOf = (struct) => {
|
|
141472
|
+
const label = struct.as ?? struct.name;
|
|
141473
|
+
if (typeof label !== "string")
|
|
141474
|
+
return "<unnamed>";
|
|
141475
|
+
return label.startsWith("sql://") ? INLINE_SQL : label;
|
|
141476
|
+
};
|
|
141477
|
+
var init_sql_embeds = () => {};
|
|
141478
|
+
|
|
141479
|
+
// src/service/materialization/text/source_map.ts
|
|
141480
|
+
import { isSourceDef as isSourceDef8 } from "@malloydata/malloy";
|
|
141394
141481
|
function structRefSourceId(structRef) {
|
|
141395
141482
|
if (typeof structRef === "string")
|
|
141396
141483
|
return structRef;
|
|
@@ -141550,7 +141637,7 @@ function reachableSourceIDs(roots, modelDef) {
|
|
|
141550
141637
|
add(structRefSourceId(member));
|
|
141551
141638
|
visit(typeof member === "string" ? byId(modelDef, member) : member);
|
|
141552
141639
|
}
|
|
141553
|
-
if (modelDef !== undefined &&
|
|
141640
|
+
if (modelDef !== undefined && isSourceDef8(node)) {
|
|
141554
141641
|
const struct = node;
|
|
141555
141642
|
const model = modelDef;
|
|
141556
141643
|
const declared = resolveDeclaredSource(struct, model);
|
|
@@ -141561,6 +141648,11 @@ function reachableSourceIDs(roots, modelDef) {
|
|
|
141561
141648
|
visit(resolveQuerySourceBase(struct, model));
|
|
141562
141649
|
visit(resolveCompositeResolvedBase(struct));
|
|
141563
141650
|
}
|
|
141651
|
+
const segments = def.selectSegments;
|
|
141652
|
+
if (Array.isArray(segments)) {
|
|
141653
|
+
for (const segment of segments)
|
|
141654
|
+
visitEmbed(segment);
|
|
141655
|
+
}
|
|
141564
141656
|
for (const field of def.fields ?? []) {
|
|
141565
141657
|
const f = field;
|
|
141566
141658
|
if (typeof f?.join === "string") {
|
|
@@ -141571,6 +141663,22 @@ function reachableSourceIDs(roots, modelDef) {
|
|
|
141571
141663
|
}
|
|
141572
141664
|
}
|
|
141573
141665
|
};
|
|
141666
|
+
const visitEmbed = (segment) => {
|
|
141667
|
+
if (segment === null || typeof segment !== "object")
|
|
141668
|
+
return;
|
|
141669
|
+
const embed = segment;
|
|
141670
|
+
if ("sql" in embed && embed.type === undefined)
|
|
141671
|
+
return;
|
|
141672
|
+
add(structRefSourceId(embed.structRef));
|
|
141673
|
+
const read = modelDef !== undefined ? embeddedStructs(embed, modelDef) : undefined;
|
|
141674
|
+
if (read !== undefined && "structs" in read) {
|
|
141675
|
+
for (const struct of read.structs)
|
|
141676
|
+
visit(struct);
|
|
141677
|
+
} else {
|
|
141678
|
+
scanWhole(embed, 0);
|
|
141679
|
+
}
|
|
141680
|
+
visitPipeline(embed.pipeline);
|
|
141681
|
+
};
|
|
141574
141682
|
for (const root of roots)
|
|
141575
141683
|
visit(root);
|
|
141576
141684
|
return ids;
|
|
@@ -141683,6 +141791,7 @@ function reachPersisted(ctx, name, isPersisted) {
|
|
|
141683
141791
|
}
|
|
141684
141792
|
var SourceMap, MAX_PIPELINE_DEPTH = 200;
|
|
141685
141793
|
var init_source_map = __esm(() => {
|
|
141794
|
+
init_sql_embeds();
|
|
141686
141795
|
init_source_graph();
|
|
141687
141796
|
SourceMap = class SourceMap {
|
|
141688
141797
|
modelDef;
|
|
@@ -149357,7 +149466,7 @@ var require_dist11 = __commonJS(function(exports) {
|
|
|
149357
149466
|
|
|
149358
149467
|
// src/service/given.ts
|
|
149359
149468
|
import {
|
|
149360
|
-
isSourceDef as
|
|
149469
|
+
isSourceDef as isSourceDef9
|
|
149361
149470
|
} from "@malloydata/malloy";
|
|
149362
149471
|
function presentText(tag, ...path) {
|
|
149363
149472
|
const raw = tagText(tag, ...path);
|
|
@@ -149447,7 +149556,7 @@ function suggestGivenLookup(modelDef, gatesBySource, surfaced) {
|
|
|
149447
149556
|
const bySource = new Map;
|
|
149448
149557
|
const byQuery = new Map;
|
|
149449
149558
|
for (const obj of Object.values(modelDef.contents)) {
|
|
149450
|
-
if (
|
|
149559
|
+
if (isSourceDef9(obj)) {
|
|
149451
149560
|
const name = obj.as || obj.name;
|
|
149452
149561
|
const refs = new Set;
|
|
149453
149562
|
collectGivenRefs(obj.filterList, refs);
|
|
@@ -150432,6 +150541,7 @@ var init_key_check = __esm(() => {
|
|
|
150432
150541
|
pair_level: { nullKey: "fails", onRepeat: "fail_build" },
|
|
150433
150542
|
rollup_key: { nullKey: "ignored", onRepeat: "record" },
|
|
150434
150543
|
parent_key: { nullKey: "fails", onRepeat: "record" },
|
|
150544
|
+
grain_join_key: { nullKey: "ignored", onRepeat: "record" },
|
|
150435
150545
|
stored_key: { nullKey: "fails", onRepeat: "record" }
|
|
150436
150546
|
};
|
|
150437
150547
|
});
|
|
@@ -150480,6 +150590,11 @@ var init_key_check_text = __esm(() => {
|
|
|
150480
150590
|
inline_join_one: { count: "matches", key: undefined, notNull: "is not" },
|
|
150481
150591
|
pair_level: { count: "matches", key: undefined, isNull: "is" },
|
|
150482
150592
|
rollup_key: { count: "key_rows__check", key: undefined, notNull: "!=" },
|
|
150593
|
+
grain_join_key: {
|
|
150594
|
+
count: "key_rows__check",
|
|
150595
|
+
key: undefined,
|
|
150596
|
+
notNull: "!="
|
|
150597
|
+
},
|
|
150483
150598
|
parent_key: { count: "key_rows__check", key: "key__check", isNull: "=" }
|
|
150484
150599
|
};
|
|
150485
150600
|
});
|
|
@@ -152696,6 +152811,7 @@ function pathReadsCurrentTime(g, facts) {
|
|
|
152696
152811
|
}
|
|
152697
152812
|
function joinOneGrainOf(grain, facts) {
|
|
152698
152813
|
const byJoin = new Map;
|
|
152814
|
+
const uncovered = new Set;
|
|
152699
152815
|
const add = (join, entry) => {
|
|
152700
152816
|
if (facts.joins.get(join)?.relationship !== "one")
|
|
152701
152817
|
return;
|
|
@@ -152708,15 +152824,39 @@ function joinOneGrainOf(grain, facts) {
|
|
|
152708
152824
|
const path = grainPathOf(g);
|
|
152709
152825
|
if (path) {
|
|
152710
152826
|
add(path.join, g);
|
|
152827
|
+
const join = facts.joins.get(path.join);
|
|
152828
|
+
if (!join)
|
|
152829
|
+
continue;
|
|
152830
|
+
const field = joinedSourceReads(join).fieldJoins.get(path.field);
|
|
152831
|
+
if (field === undefined || field.joins.size > 0 || field.nested) {
|
|
152832
|
+
uncovered.add(path.join);
|
|
152833
|
+
}
|
|
152711
152834
|
continue;
|
|
152712
152835
|
}
|
|
152713
|
-
|
|
152836
|
+
const usage = facts.joinUsage.get(g);
|
|
152837
|
+
for (const j of usage?.joins ?? [])
|
|
152714
152838
|
add(j, g);
|
|
152839
|
+
const onlyOnes = [...usage?.joins ?? []].every((j) => facts.joins.get(j)?.relationship === "one");
|
|
152840
|
+
if (usage === undefined || usage.nested || !onlyOnes) {
|
|
152841
|
+
for (const j of usage?.joins ?? [])
|
|
152842
|
+
uncovered.add(j);
|
|
152843
|
+
}
|
|
152844
|
+
}
|
|
152845
|
+
for (const join of byJoin.keys()) {
|
|
152846
|
+
const condition = facts.joins.get(join)?.condition;
|
|
152847
|
+
const filter = filterJoinReads(facts.byName.get(join));
|
|
152848
|
+
if (condition === undefined || condition.joins.size > 0 || condition.nested || filter === undefined || filter.joins.size > 0 || filter.nested) {
|
|
152849
|
+
uncovered.add(join);
|
|
152850
|
+
}
|
|
152715
152851
|
}
|
|
152716
152852
|
if (byJoin.size === 0)
|
|
152717
152853
|
return {};
|
|
152718
152854
|
return {
|
|
152719
|
-
joinOneGrain: [...byJoin].sort(([a], [b]) => byCodepoint3(a, b)).map(([join, entries]) => ({
|
|
152855
|
+
joinOneGrain: [...byJoin].sort(([a], [b]) => byCodepoint3(a, b)).map(([join, entries]) => ({
|
|
152856
|
+
join,
|
|
152857
|
+
grain: entries,
|
|
152858
|
+
...uncovered.has(join) ? { uncovered: true } : {}
|
|
152859
|
+
}))
|
|
152720
152860
|
};
|
|
152721
152861
|
}
|
|
152722
152862
|
function exactPathRead(e) {
|
|
@@ -153094,6 +153234,9 @@ function storedKeyChecksOf(plans, needs, primaryKeyOf, sourceIDs) {
|
|
|
153094
153234
|
function parentKeyCheckQuery(name, keyColumn) {
|
|
153095
153235
|
return `run: ${keyCheckPipeline("parent_key", name, keyColumn)}`;
|
|
153096
153236
|
}
|
|
153237
|
+
function grainJoinKeyCheckQuery(name, keyColumn) {
|
|
153238
|
+
return `run: ${keyCheckPipeline("grain_join_key", name, keyColumn)}`;
|
|
153239
|
+
}
|
|
153097
153240
|
function joinOneKey(sourceID, keyColumn) {
|
|
153098
153241
|
return `${sourceID}\x00${keyColumn}`;
|
|
153099
153242
|
}
|
|
@@ -153136,6 +153279,7 @@ var init_rollup_plan = __esm(() => {
|
|
|
153136
153279
|
init_rollup_measure_grammar();
|
|
153137
153280
|
init_table_plans();
|
|
153138
153281
|
init_read_text();
|
|
153282
|
+
init_source_graph();
|
|
153139
153283
|
V1_PREAGGREGATE_NOTE = /^\s*#@\s*-?preaggregate\b/;
|
|
153140
153284
|
scopes = new WeakMap;
|
|
153141
153285
|
LOCK_WORDS = new Set(["and", "in", "true", "false"]);
|
|
@@ -154286,7 +154430,7 @@ function materializedUpstream(sourceID, map) {
|
|
|
154286
154430
|
}
|
|
154287
154431
|
function storedElsewhereReason(upstreams) {
|
|
154288
154432
|
const stored = upstreams.find((u) => u.storage !== undefined);
|
|
154289
|
-
return stored ? `its upstream '${stored.name}' is stored in the storage= destination ` + `'${stored.storage}', whose table a build in the warehouse cannot ` + `read, and a downstream is never built by recomputing its upstream ` + `from raw; it is
|
|
154433
|
+
return stored ? `its upstream '${stored.name}' is stored in the storage= destination ` + `'${stored.storage}', whose table a build in the warehouse cannot ` + `read, and a downstream is never built by recomputing its upstream ` + `from raw; it is answered live` : undefined;
|
|
154290
154434
|
}
|
|
154291
154435
|
function persistOverMaterializedReason(upstreams, destination) {
|
|
154292
154436
|
const stored = upstreams.find((u) => u.materialize && u.storage === destination);
|
|
@@ -154299,7 +154443,7 @@ function placementReason(downstream, upstream) {
|
|
|
154299
154443
|
if (downstream === undefined) {
|
|
154300
154444
|
return storedElsewhereReason([upstream]);
|
|
154301
154445
|
}
|
|
154302
|
-
return `its upstream '${upstream.name}' is stored in the storage= destination ` + `'${upstream.storage}', and it is built into the storage= destination ` + `'${downstream}', which cannot read that table; a downstream is never ` + `built by recomputing its upstream from raw, so it is answered live
|
|
154446
|
+
return `its upstream '${upstream.name}' is stored in the storage= destination ` + `'${upstream.storage}', and it is built into the storage= destination ` + `'${downstream}', which cannot read that table; a downstream is never ` + `built by recomputing its upstream from raw, so it is answered live`;
|
|
154303
154447
|
}
|
|
154304
154448
|
var UPSTREAM_TABLE_UNUSABLE_REASON = "upstream_table_unusable";
|
|
154305
154449
|
var init_downstream_upstreams = __esm(() => {
|
|
@@ -156691,10 +156835,13 @@ function parseKeyUniqueness(raw) {
|
|
|
156691
156835
|
const own = typeof k.keyColumn === "string" && typeof k.unique === "boolean" ? { keyColumn: k.keyColumn, unique: k.unique } : undefined;
|
|
156692
156836
|
const parentKeys = recordOf(k.parentKeys, "boolean");
|
|
156693
156837
|
const parentKeyColumns = recordOf(k.parentKeyColumns, "string");
|
|
156694
|
-
|
|
156838
|
+
const grainJoinKeys = recordOf(k.grainJoinKeys, "boolean");
|
|
156839
|
+
if (!own && !parentKeys && !parentKeyColumns && !grainJoinKeys) {
|
|
156695
156840
|
return;
|
|
156841
|
+
}
|
|
156696
156842
|
return {
|
|
156697
156843
|
...own ?? {},
|
|
156844
|
+
...grainJoinKeys ? { grainJoinKeys } : {},
|
|
156698
156845
|
...parentKeys ? { parentKeys } : {},
|
|
156699
156846
|
...parentKeyColumns ? { parentKeyColumns } : {}
|
|
156700
156847
|
};
|
|
@@ -156721,21 +156868,27 @@ function rollupKeyOf(entry) {
|
|
|
156721
156868
|
const k = keyUniquenessOf(entry);
|
|
156722
156869
|
return k?.keyColumn !== undefined && k.unique !== undefined ? { keyColumn: k.keyColumn, unique: k.unique } : undefined;
|
|
156723
156870
|
}
|
|
156871
|
+
function grainJoinKeysOf(entry) {
|
|
156872
|
+
return keyUniquenessOf(entry)?.grainJoinKeys;
|
|
156873
|
+
}
|
|
156724
156874
|
function withEntryKeyChecks(binding, entry) {
|
|
156725
156875
|
const {
|
|
156726
156876
|
primaryKeys: _was,
|
|
156727
156877
|
primaryKeyColumns: _wasColumns,
|
|
156728
156878
|
rollupKey: _wasKey,
|
|
156879
|
+
grainJoinKeys: _wasJoinKeys,
|
|
156729
156880
|
...rest
|
|
156730
156881
|
} = binding;
|
|
156731
156882
|
const primaryKeys = primaryKeysOf(entry);
|
|
156732
156883
|
const primaryKeyColumns = primaryKeyColumnsOf(entry);
|
|
156733
156884
|
const rollupKey = isRollupOrigin(entry.origin) ? rollupKeyOf(entry) : undefined;
|
|
156885
|
+
const grainJoinKeys = isRollupOrigin(entry.origin) ? grainJoinKeysOf(entry) : undefined;
|
|
156734
156886
|
return {
|
|
156735
156887
|
...rest,
|
|
156736
156888
|
...primaryKeys ? { primaryKeys } : {},
|
|
156737
156889
|
...primaryKeyColumns ? { primaryKeyColumns } : {},
|
|
156738
|
-
...rollupKey ? { rollupKey } : {}
|
|
156890
|
+
...rollupKey ? { rollupKey } : {},
|
|
156891
|
+
...grainJoinKeys ? { grainJoinKeys } : {}
|
|
156739
156892
|
};
|
|
156740
156893
|
}
|
|
156741
156894
|
function deriveServeBindings(entries, aliasesBySourceName, destinationSchema, sourceIDsFor) {
|
|
@@ -156755,6 +156908,7 @@ function deriveServeBindings(entries, aliasesBySourceName, destinationSchema, so
|
|
|
156755
156908
|
const primaryKeys = primaryKeysOf(entry);
|
|
156756
156909
|
const primaryKeyColumns = primaryKeyColumnsOf(entry);
|
|
156757
156910
|
const rollupKey = isRollupOrigin(entry.origin) ? rollupKeyOf(entry) : undefined;
|
|
156911
|
+
const grainJoinKeys = isRollupOrigin(entry.origin) ? grainJoinKeysOf(entry) : undefined;
|
|
156758
156912
|
for (const sourceName of names) {
|
|
156759
156913
|
const sourceIDs = sourceIDsFor?.(sourceName, entry.sourceEntityId);
|
|
156760
156914
|
bindings.push({
|
|
@@ -156771,7 +156925,8 @@ function deriveServeBindings(entries, aliasesBySourceName, destinationSchema, so
|
|
|
156771
156925
|
freshnessFallback: entry.freshnessFallback,
|
|
156772
156926
|
...primaryKeys ? { primaryKeys } : {},
|
|
156773
156927
|
...primaryKeyColumns ? { primaryKeyColumns } : {},
|
|
156774
|
-
...rollupKey ? { rollupKey } : {}
|
|
156928
|
+
...rollupKey ? { rollupKey } : {},
|
|
156929
|
+
...grainJoinKeys ? { grainJoinKeys } : {}
|
|
156775
156930
|
});
|
|
156776
156931
|
}
|
|
156777
156932
|
}
|
|
@@ -158364,11 +158519,14 @@ class GeneratedFiles {
|
|
|
158364
158519
|
static over(factory) {
|
|
158365
158520
|
return new GeneratedFiles(factory);
|
|
158366
158521
|
}
|
|
158367
|
-
async loadModel(overlay = new Map) {
|
|
158522
|
+
async loadModel(overlay = new Map, options = {}) {
|
|
158368
158523
|
const { runtime, importBaseURL, modelURL } = await this.runtimeFor(keyedOverlay(overlay));
|
|
158369
158524
|
if (!modelURL)
|
|
158370
158525
|
throw new Error("no package model to load");
|
|
158371
|
-
const materializer = runtime.loadModel(modelURL, {
|
|
158526
|
+
const materializer = runtime.loadModel(modelURL, {
|
|
158527
|
+
importBaseURL,
|
|
158528
|
+
...options.virtualMap ? { virtualMap: options.virtualMap } : {}
|
|
158529
|
+
});
|
|
158372
158530
|
return { runtime, importBaseURL, materializer };
|
|
158373
158531
|
}
|
|
158374
158532
|
runtime(overlay = new Map) {
|
|
@@ -158444,7 +158602,7 @@ var init_generated_files = __esm(() => {
|
|
|
158444
158602
|
});
|
|
158445
158603
|
|
|
158446
158604
|
// package.json
|
|
158447
|
-
var version = "0.18.
|
|
158605
|
+
var version = "0.18.6";
|
|
158448
158606
|
var init_package = () => {};
|
|
158449
158607
|
|
|
158450
158608
|
// src/version.ts
|
|
@@ -158607,7 +158765,7 @@ var init_column_contract_capture = __esm(() => {
|
|
|
158607
158765
|
});
|
|
158608
158766
|
|
|
158609
158767
|
// src/service/annotation_near_miss.ts
|
|
158610
|
-
import { isSourceDef as
|
|
158768
|
+
import { isSourceDef as isSourceDef10 } from "@malloydata/malloy";
|
|
158611
158769
|
function ownedRoutes() {
|
|
158612
158770
|
return getMaterializeEnabled() ? OWNED_ROUTES : OWNED_V1_ROUTES;
|
|
158613
158771
|
}
|
|
@@ -158756,7 +158914,7 @@ function authoredNotes(modelDef) {
|
|
|
158756
158914
|
add(ownModelNoteObjects(modelDef));
|
|
158757
158915
|
const structs = [];
|
|
158758
158916
|
for (const [name, obj] of Object.entries(modelDef.contents)) {
|
|
158759
|
-
if (
|
|
158917
|
+
if (isSourceDef10(obj)) {
|
|
158760
158918
|
structs.push({ name, struct: obj });
|
|
158761
158919
|
} else if (obj.type === "query") {
|
|
158762
158920
|
add(ownLevelNotes(obj.annotations), name);
|
|
@@ -158766,7 +158924,7 @@ function authoredNotes(modelDef) {
|
|
|
158766
158924
|
const entry = value.entry;
|
|
158767
158925
|
if (entry.type === "source_registry_reference")
|
|
158768
158926
|
continue;
|
|
158769
|
-
if (!
|
|
158927
|
+
if (!isSourceDef10(entry))
|
|
158770
158928
|
continue;
|
|
158771
158929
|
const struct = entry;
|
|
158772
158930
|
structs.push({ name: struct.as ?? struct.name, struct });
|
|
@@ -162056,6 +162214,61 @@ async function compileParentKeyChecks(plans, needs, joinedKeys = []) {
|
|
|
162056
162214
|
delete plan.parentKeyChecks;
|
|
162057
162215
|
}
|
|
162058
162216
|
}
|
|
162217
|
+
async function compileGrainJoinKeyChecks(plans, joinsOf, sourceOf, stored) {
|
|
162218
|
+
const compiled = new Map;
|
|
162219
|
+
for (const plan of plans) {
|
|
162220
|
+
if (plan.variant !== true)
|
|
162221
|
+
continue;
|
|
162222
|
+
const checks = [];
|
|
162223
|
+
for (const { join, uncovered } of plan.joinOneGrain ?? []) {
|
|
162224
|
+
if (uncovered) {
|
|
162225
|
+
logger.info("A #(rollup) rollup's grain join key is not checked; queries that read nothing through the join are answered live", {
|
|
162226
|
+
rollup: plan.rollupSourceName,
|
|
162227
|
+
join,
|
|
162228
|
+
reason: "the build joins past it, through another join"
|
|
162229
|
+
});
|
|
162230
|
+
continue;
|
|
162231
|
+
}
|
|
162232
|
+
const j = joinsOf(plan.baseSourceID).find((x) => x.name === join && x.relationship === "one");
|
|
162233
|
+
const source = j?.sourceID ? sourceOf(j.sourceID) : undefined;
|
|
162234
|
+
const why = j?.sourceID === undefined || j.keyColumn === undefined ? "its join is not keyed on one column of a declared source" : source === undefined ? "no model names the joined source" : [...source.reads()].some((id) => stored.has(id)) ? "the joined source reads a table the run stores" : undefined;
|
|
162235
|
+
if (why !== undefined || !j?.sourceID || !j.keyColumn || !source) {
|
|
162236
|
+
logger.info("A #(rollup) rollup's grain join key is not checked; queries that read nothing through the join are answered live", { rollup: plan.rollupSourceName, join, reason: why });
|
|
162237
|
+
continue;
|
|
162238
|
+
}
|
|
162239
|
+
const { sourceID, keyColumn } = j;
|
|
162240
|
+
const key = `${sourceID}\x00${keyColumn}`;
|
|
162241
|
+
let sql = compiled.get(key);
|
|
162242
|
+
if (sql === undefined) {
|
|
162243
|
+
sql = source.compile(grainJoinKeyCheckQuery(source.name, keyColumn)).catch((error) => {
|
|
162244
|
+
logger.warn("A #(rollup) rollup's grain join key check did not compile; queries that read nothing through the join are answered live", {
|
|
162245
|
+
rollup: plan.rollupSourceName,
|
|
162246
|
+
join,
|
|
162247
|
+
source: source.name,
|
|
162248
|
+
keyColumn,
|
|
162249
|
+
code: errorCodeOf(error)
|
|
162250
|
+
});
|
|
162251
|
+
return;
|
|
162252
|
+
});
|
|
162253
|
+
compiled.set(key, sql);
|
|
162254
|
+
}
|
|
162255
|
+
const text = await sql;
|
|
162256
|
+
if (text === undefined)
|
|
162257
|
+
continue;
|
|
162258
|
+
checks.push({
|
|
162259
|
+
join,
|
|
162260
|
+
sourceID,
|
|
162261
|
+
keyColumn,
|
|
162262
|
+
connectionName: source.connectionName,
|
|
162263
|
+
sql: text
|
|
162264
|
+
});
|
|
162265
|
+
}
|
|
162266
|
+
if (checks.length > 0)
|
|
162267
|
+
plan.grainJoinKeyChecks = checks;
|
|
162268
|
+
else
|
|
162269
|
+
delete plan.grainJoinKeyChecks;
|
|
162270
|
+
}
|
|
162271
|
+
}
|
|
162059
162272
|
async function compileRollupKeyChecks(plans, materializer, modelPath) {
|
|
162060
162273
|
for (const plan of plans) {
|
|
162061
162274
|
const text = rollupKeyCheckQuery(plan);
|
|
@@ -162257,7 +162470,7 @@ function noModelGateLines() {
|
|
|
162257
162470
|
import { Manifest as Manifest2 } from "@malloydata/malloy";
|
|
162258
162471
|
import * as path22 from "path";
|
|
162259
162472
|
import { fileURLToPath as fileURLToPath9, pathToFileURL as pathToFileURL11 } from "url";
|
|
162260
|
-
import { Annotations as Annotations10, isSourceDef as
|
|
162473
|
+
import { Annotations as Annotations10, isSourceDef as isSourceDef11 } from "@malloydata/malloy";
|
|
162261
162474
|
function wireTerm(term) {
|
|
162262
162475
|
return { code: term.code, givens: term.givens };
|
|
162263
162476
|
}
|
|
@@ -162366,7 +162579,7 @@ function declaredPersistSourceIDs(malloyModel) {
|
|
|
162366
162579
|
const ids = [];
|
|
162367
162580
|
try {
|
|
162368
162581
|
for (const def of Object.values(modelDefOf(malloyModel)?.contents ?? {})) {
|
|
162369
|
-
if (!
|
|
162582
|
+
if (!isSourceDef11(def) || !def.annotations)
|
|
162370
162583
|
continue;
|
|
162371
162584
|
try {
|
|
162372
162585
|
if (declares(new Annotations10(def.annotations), "@", "persist")) {
|
|
@@ -162382,7 +162595,7 @@ function sourceIDsWithNoteAt(malloyModel, at) {
|
|
|
162382
162595
|
const ids = [];
|
|
162383
162596
|
try {
|
|
162384
162597
|
for (const def of Object.values(modelDefOf(malloyModel)?.contents ?? {})) {
|
|
162385
|
-
if (!
|
|
162598
|
+
if (!isSourceDef11(def) || !def.annotations || !def.sourceID)
|
|
162386
162599
|
continue;
|
|
162387
162600
|
try {
|
|
162388
162601
|
const notes = new Annotations10(def.annotations).forRoute("@");
|
|
@@ -162609,7 +162822,7 @@ function pairParentUnusable(plan, boundContract) {
|
|
|
162609
162822
|
return `it extends '${over.sourceName}', whose pair table it is built over ` + `with its join put back, and the leaf key check of its inlined ` + `join_many, which that build relies on, ${what} when the table was ` + `built; it builds once the parent's table records the check passed`;
|
|
162610
162823
|
}
|
|
162611
162824
|
async function authorSourceGate(sourceID, authorDef, args) {
|
|
162612
|
-
const authorSource = Object.values(authorDef.contents ?? {}).find((object) =>
|
|
162825
|
+
const authorSource = Object.values(authorDef.contents ?? {}).find((object) => isSourceDef11(object) && object.sourceID === sourceID);
|
|
162613
162826
|
return authorSource ? await classifyPersistSourceGate({ _sourceDef: authorSource, sourceID }, authorDef, args.materializer, args.deps, args.modelPath) : { classification: "rejected", attributed: false };
|
|
162614
162827
|
}
|
|
162615
162828
|
async function collectGeneratedRollups(parts, args) {
|
|
@@ -162899,7 +163112,7 @@ async function collectGeneratedPersistedViews(parts, args) {
|
|
|
162899
163112
|
parts.builds.push(...sourceBuildsOf(targets));
|
|
162900
163113
|
}
|
|
162901
163114
|
async function persistedQueryGate(source, query, ctx) {
|
|
162902
|
-
const runTarget = query.sourceID !== undefined ? Object.values(ctx.authorDef.contents ?? {}).find((object) =>
|
|
163115
|
+
const runTarget = query.sourceID !== undefined ? Object.values(ctx.authorDef.contents ?? {}).find((object) => isSourceDef11(object) && object.sourceID === query.sourceID) : inlineRunTarget(ctx.authorDef, query.queryName);
|
|
162903
163116
|
return runTarget ? await classifyPersistSourceGate({
|
|
162904
163117
|
_sourceDef: runTarget,
|
|
162905
163118
|
sourceID: query.sourceID ?? source.sourceID
|
|
@@ -162964,7 +163177,7 @@ function queryStorage(query) {
|
|
|
162964
163177
|
function inlineRunTarget(modelDef, name) {
|
|
162965
163178
|
const query = (modelDef.contents ?? {})[name];
|
|
162966
163179
|
const ref = query?.type === "query" ? query.structRef : undefined;
|
|
162967
|
-
return ref && typeof ref === "object" &&
|
|
163180
|
+
return ref && typeof ref === "object" && isSourceDef11(ref) ? ref : undefined;
|
|
162968
163181
|
}
|
|
162969
163182
|
function addAccessReads(parts, malloyModel) {
|
|
162970
163183
|
const reads = new Set(parts.accessReads);
|
|
@@ -164355,7 +164568,7 @@ var init_gate_registry_walk = __esm(() => {
|
|
|
164355
164568
|
// src/service/source_extraction.ts
|
|
164356
164569
|
import {
|
|
164357
164570
|
isJoined as isJoined5,
|
|
164358
|
-
isSourceDef as
|
|
164571
|
+
isSourceDef as isSourceDef12
|
|
164359
164572
|
} from "@malloydata/malloy";
|
|
164360
164573
|
function joinFieldNamesUnresolvableDeclaration(field, modelDef) {
|
|
164361
164574
|
const ids = [field.referenceID, field.sourceID].filter((id) => !!id);
|
|
@@ -164366,7 +164579,7 @@ function joinFieldNamesUnresolvableDeclaration(field, modelDef) {
|
|
|
164366
164579
|
if (!entry)
|
|
164367
164580
|
continue;
|
|
164368
164581
|
const declared = entry.type === "source_registry_reference" ? modelDef.contents[entry.name] : entry;
|
|
164369
|
-
if (declared &&
|
|
164582
|
+
if (declared && isSourceDef12(declared))
|
|
164370
164583
|
return false;
|
|
164371
164584
|
}
|
|
164372
164585
|
return true;
|
|
@@ -164384,7 +164597,7 @@ function considerNoteOwner(declaredBy, note, candidate) {
|
|
|
164384
164597
|
}
|
|
164385
164598
|
}
|
|
164386
164599
|
function collectSourceInfos(modelDef) {
|
|
164387
|
-
const names = Object.keys(modelDef.contents).filter((name) =>
|
|
164600
|
+
const names = Object.keys(modelDef.contents).filter((name) => isSourceDef12(modelDef.contents[name]));
|
|
164388
164601
|
const exports = [...new Set([...modelDef.exports, ...names])];
|
|
164389
164602
|
return modelInfoOf({ ...modelDef, exports }).entries.filter((entry) => entry.kind === "source");
|
|
164390
164603
|
}
|
|
@@ -164400,7 +164613,7 @@ function extractSourcesFromModelDef(modelDef, givens, onParseError) {
|
|
|
164400
164613
|
const nearMissAuthorize = [];
|
|
164401
164614
|
const sweptStructs = [];
|
|
164402
164615
|
for (const obj of Object.values(modelDef.contents)) {
|
|
164403
|
-
if (!
|
|
164616
|
+
if (!isSourceDef12(obj))
|
|
164404
164617
|
continue;
|
|
164405
164618
|
const struct = obj;
|
|
164406
164619
|
sweptStructs.push(obj);
|
|
@@ -164420,7 +164633,7 @@ function extractSourcesFromModelDef(modelDef, givens, onParseError) {
|
|
|
164420
164633
|
const entry = value.entry;
|
|
164421
164634
|
if (entry.type === "source_registry_reference")
|
|
164422
164635
|
continue;
|
|
164423
|
-
if (!
|
|
164636
|
+
if (!isSourceDef12(entry))
|
|
164424
164637
|
continue;
|
|
164425
164638
|
sweptStructs.push(entry);
|
|
164426
164639
|
for (const note of ownLevelNotes(entry.annotations)) {
|
|
@@ -164462,7 +164675,7 @@ function extractSourcesFromModelDef(modelDef, givens, onParseError) {
|
|
|
164462
164675
|
});
|
|
164463
164676
|
}
|
|
164464
164677
|
}
|
|
164465
|
-
const sources = Object.values(modelDef.contents).filter((obj) =>
|
|
164678
|
+
const sources = Object.values(modelDef.contents).filter((obj) => isSourceDef12(obj)).map((sourceObj) => {
|
|
164466
164679
|
const struct = sourceObj;
|
|
164467
164680
|
const sourceName = struct.as || struct.name;
|
|
164468
164681
|
const annotations = annotationTexts(struct.annotations);
|
|
@@ -164531,7 +164744,7 @@ function extractSourcesFromModelDef(modelDef, givens, onParseError) {
|
|
|
164531
164744
|
continue;
|
|
164532
164745
|
}
|
|
164533
164746
|
const fieldName = field.as || field.name;
|
|
164534
|
-
if (isJoined5(field) &&
|
|
164747
|
+
if (isJoined5(field) && isSourceDef12(field)) {
|
|
164535
164748
|
const joinedStruct = field;
|
|
164536
164749
|
if (joinFieldNamesUnresolvableDeclaration(joinedStruct, modelDef)) {
|
|
164537
164750
|
continue;
|
|
@@ -164596,54 +164809,6 @@ var init_source_extraction = __esm(() => {
|
|
|
164596
164809
|
});
|
|
164597
164810
|
|
|
164598
164811
|
// src/service/sql_embed_gates.ts
|
|
164599
|
-
import { isSourceDef as isSourceDef12 } from "@malloydata/malloy";
|
|
164600
|
-
function sqlSelectsWithin(root) {
|
|
164601
|
-
const found = [];
|
|
164602
|
-
const seen = new Set;
|
|
164603
|
-
const stack = [root];
|
|
164604
|
-
while (stack.length > 0) {
|
|
164605
|
-
const node = stack.pop();
|
|
164606
|
-
if (Array.isArray(node)) {
|
|
164607
|
-
stack.push(...node);
|
|
164608
|
-
continue;
|
|
164609
|
-
}
|
|
164610
|
-
if (!isObj2(node) || seen.has(node))
|
|
164611
|
-
continue;
|
|
164612
|
-
seen.add(node);
|
|
164613
|
-
if (node.type === "sql_select" && Array.isArray(node.selectSegments)) {
|
|
164614
|
-
found.push(node);
|
|
164615
|
-
}
|
|
164616
|
-
stack.push(...Object.values(node));
|
|
164617
|
-
}
|
|
164618
|
-
return found;
|
|
164619
|
-
}
|
|
164620
|
-
function embeddedStructs(segment, modelDef) {
|
|
164621
|
-
if (segment.type === "query") {
|
|
164622
|
-
const ref = segment.structRef;
|
|
164623
|
-
let base = ref;
|
|
164624
|
-
if (typeof ref === "string")
|
|
164625
|
-
base = modelDef.contents[ref];
|
|
164626
|
-
if (!isObj2(base) || !isSourceDef12(base)) {
|
|
164627
|
-
return {
|
|
164628
|
-
unreadable: "its source reference does not resolve in the model",
|
|
164629
|
-
label: typeof ref === "string" ? ref : "<embedded query>"
|
|
164630
|
-
};
|
|
164631
|
-
}
|
|
164632
|
-
const structs = [base];
|
|
164633
|
-
const resolved = segment.compositeResolvedSourceDef;
|
|
164634
|
-
if (isObj2(resolved) && isSourceDef12(resolved)) {
|
|
164635
|
-
structs.push(resolved);
|
|
164636
|
-
}
|
|
164637
|
-
return { structs };
|
|
164638
|
-
}
|
|
164639
|
-
if (isSourceDef12(segment)) {
|
|
164640
|
-
return { structs: [segment] };
|
|
164641
|
-
}
|
|
164642
|
-
return {
|
|
164643
|
-
unreadable: `its segment shape (type ${JSON.stringify(segment.type)}) is not one Publisher reads`,
|
|
164644
|
-
label: labelOf(segment)
|
|
164645
|
-
};
|
|
164646
|
-
}
|
|
164647
164812
|
function runLabel(query, index, cell) {
|
|
164648
164813
|
const line = isObj2(query) ? query.location?.range?.start?.line : undefined;
|
|
164649
164814
|
const at = typeof line === "number" ? `line ${line + 1}` : `#${index + 1}`;
|
|
@@ -164759,13 +164924,8 @@ function assertNoSqlEmbedsOfGatedSources(modelDef, scope = {}) {
|
|
|
164759
164924
|
` + `Malloy compiles the embedded read into the SQL text, where no ` + `#(authorize) or #(access_filter) gate can be enforced, so every ` + `caller would read the gated rows. Query the gated source through ` + `Malloy instead (derive from it with \`->\`, or extend it), so its ` + `gate applies, or remove the gate if the source is meant to be open.`
|
|
164760
164925
|
});
|
|
164761
164926
|
}
|
|
164762
|
-
var isObj2 = (value) => typeof value === "object" && value !== null, INLINE_SQL = "<inline sql()>", labelOf = (struct) => {
|
|
164763
|
-
const label = struct.as ?? struct.name;
|
|
164764
|
-
if (typeof label !== "string")
|
|
164765
|
-
return "<unnamed>";
|
|
164766
|
-
return label.startsWith("sql://") ? INLINE_SQL : label;
|
|
164767
|
-
};
|
|
164768
164927
|
var init_sql_embed_gates = __esm(() => {
|
|
164928
|
+
init_sql_embeds();
|
|
164769
164929
|
init_errors2();
|
|
164770
164930
|
init_gate_plan();
|
|
164771
164931
|
});
|
|
@@ -165066,11 +165226,15 @@ function emptyKeyCheckInputs() {
|
|
|
165066
165226
|
parentKeyNeeds: [],
|
|
165067
165227
|
joinedKeyNeeds: [],
|
|
165068
165228
|
primaryKeys: new Map,
|
|
165229
|
+
joins: new Map,
|
|
165230
|
+
namedSources: new Map,
|
|
165069
165231
|
keyCheckCompilers: new Map
|
|
165070
165232
|
};
|
|
165071
165233
|
}
|
|
165072
165234
|
function addKeyCheckInputs(into, malloyModel, materializer) {
|
|
165073
|
-
const
|
|
165235
|
+
const modelDef = modelDefOf(malloyModel);
|
|
165236
|
+
const map = SourceMap.of(modelDef);
|
|
165237
|
+
const compile = parentKeyCheckCompiler(materializer);
|
|
165074
165238
|
for (const key of joinOneKeysOf(map))
|
|
165075
165239
|
into.joinOneKeys.add(key);
|
|
165076
165240
|
for (const node of map.nodes()) {
|
|
@@ -165078,17 +165242,29 @@ function addKeyCheckInputs(into, malloyModel, materializer) {
|
|
|
165078
165242
|
if (key !== undefined && !into.primaryKeys.has(node.sourceID)) {
|
|
165079
165243
|
into.primaryKeys.set(node.sourceID, key);
|
|
165080
165244
|
}
|
|
165245
|
+
if (!into.joins.has(node.sourceID)) {
|
|
165246
|
+
into.joins.set(node.sourceID, map.joinsOf(node.sourceID));
|
|
165247
|
+
}
|
|
165248
|
+
if (node.name !== undefined && !into.namedSources.has(node.sourceID)) {
|
|
165249
|
+
const connection = node.def.connection;
|
|
165250
|
+
into.namedSources.set(node.sourceID, {
|
|
165251
|
+
name: node.name,
|
|
165252
|
+
connectionName: typeof connection === "string" ? connection : undefined,
|
|
165253
|
+
reads: () => reachableSourceIDs([node.def], modelDef),
|
|
165254
|
+
compile
|
|
165255
|
+
});
|
|
165256
|
+
}
|
|
165081
165257
|
}
|
|
165082
165258
|
for (const need of parentKeyNeedsOf(map)) {
|
|
165083
165259
|
into.parentKeyNeeds.push({
|
|
165084
165260
|
need,
|
|
165085
|
-
compile
|
|
165261
|
+
compile
|
|
165086
165262
|
});
|
|
165087
165263
|
}
|
|
165088
165264
|
for (const need of joinedKeyNeedsOf(map)) {
|
|
165089
165265
|
into.joinedKeyNeeds.push({
|
|
165090
165266
|
need,
|
|
165091
|
-
compile
|
|
165267
|
+
compile
|
|
165092
165268
|
});
|
|
165093
165269
|
}
|
|
165094
165270
|
}
|
|
@@ -165100,6 +165276,7 @@ async function compileRunKeyChecks(parts, inputs) {
|
|
|
165100
165276
|
}
|
|
165101
165277
|
}
|
|
165102
165278
|
await compileParentKeyChecks(rollupPlans, inputs.parentKeyNeeds, inputs.joinedKeyNeeds);
|
|
165279
|
+
await compileGrainJoinKeyChecks(rollupPlans, (sourceID) => inputs.joins.get(sourceID) ?? [], (sourceID) => inputs.namedSources.get(sourceID), new Set(Object.keys(parts.tables).filter((sourceID) => !parts.tables[sourceID].rollup)));
|
|
165103
165280
|
const storedKeyChecks = storedKeyChecksOf(rollupPlans, inputs.parentKeyNeeds.map(({ need }) => need), (sourceID) => inputs.primaryKeys.get(sourceID), Object.keys(parts.tables).filter((sourceID) => !parts.tables[sourceID].rollup));
|
|
165104
165281
|
for (const [sourceID, keyColumn] of Object.entries(storedKeyChecks)) {
|
|
165105
165282
|
parts.tables[sourceID].storedKeyCheck = keyColumn;
|
|
@@ -165925,6 +166102,110 @@ var init_passthrough_build = __esm(() => {
|
|
|
165925
166102
|
});
|
|
165926
166103
|
});
|
|
165927
166104
|
|
|
166105
|
+
// src/service/same_catalog_tables.ts
|
|
166106
|
+
function fileInScope(file, prefixes) {
|
|
166107
|
+
if (/[%\\\0]/.test(file))
|
|
166108
|
+
return false;
|
|
166109
|
+
const at = file.indexOf("://");
|
|
166110
|
+
const rest = at >= 0 ? file.slice(at + 3) : file;
|
|
166111
|
+
if (rest.split("/").some((part) => part === "." || part === "..")) {
|
|
166112
|
+
return false;
|
|
166113
|
+
}
|
|
166114
|
+
return prefixes.some((prefix) => prefix.endsWith("/") && file.startsWith(prefix));
|
|
166115
|
+
}
|
|
166116
|
+
async function fileOutsideScope(run, catalog, snapshot, tables, prefixes) {
|
|
166117
|
+
if (!/^\d+$/.test(snapshot))
|
|
166118
|
+
throw new Error("not a snapshot id");
|
|
166119
|
+
for (const [schema, table] of tables) {
|
|
166120
|
+
const files = await run(`SELECT data_file, delete_file FROM ducklake_list_files(${literal(catalog)}, ${literal(table)}, ` + `schema => ${literal(schema)}, snapshot_version => ${snapshot})`);
|
|
166121
|
+
for (const row of files) {
|
|
166122
|
+
for (const file of [row.data_file, row.delete_file]) {
|
|
166123
|
+
if (file === null || file === undefined)
|
|
166124
|
+
continue;
|
|
166125
|
+
if (typeof file !== "string" || !fileInScope(file, prefixes)) {
|
|
166126
|
+
return `the table '${schema}.${table}' holds a file outside the connection's storage scope`;
|
|
166127
|
+
}
|
|
166128
|
+
}
|
|
166129
|
+
}
|
|
166130
|
+
}
|
|
166131
|
+
return;
|
|
166132
|
+
}
|
|
166133
|
+
function scopeIdentity(config, prefixes) {
|
|
166134
|
+
const ducklake = config?.ducklakeConnection;
|
|
166135
|
+
return JSON.stringify([
|
|
166136
|
+
ducklake?.storage?.bucketUrl ?? null,
|
|
166137
|
+
ducklake?.catalog?.metadataSchema ?? null,
|
|
166138
|
+
[...prefixes].sort()
|
|
166139
|
+
]);
|
|
166140
|
+
}
|
|
166141
|
+
async function sameCatalogTablesReadable(config, read) {
|
|
166142
|
+
if (read.tables.length === 0)
|
|
166143
|
+
return true;
|
|
166144
|
+
const [destination, managed] = await Promise.all([
|
|
166145
|
+
config.connections.lookupConnection(read.alias),
|
|
166146
|
+
config.connections.lookupConnection(read.connection)
|
|
166147
|
+
]);
|
|
166148
|
+
const prefixes = managedScopeOf(managed, read.connection);
|
|
166149
|
+
if (!prefixes)
|
|
166150
|
+
return false;
|
|
166151
|
+
const run = async (sql) => (await runInternalSQL(destination, sql)).rows;
|
|
166152
|
+
const scopeKey = scopeIdentity(connectionConfigOf(managed), prefixes);
|
|
166153
|
+
const key = (schema, table) => `${scopeKey}\x00${schema.toLowerCase()}.${table.toLowerCase()}`;
|
|
166154
|
+
const byCatalog = new Map;
|
|
166155
|
+
for (const t of read.tables) {
|
|
166156
|
+
byCatalog.set(t[0], [...byCatalog.get(t[0]) ?? [], t]);
|
|
166157
|
+
}
|
|
166158
|
+
let known = verdicts.get(destination);
|
|
166159
|
+
if (!known) {
|
|
166160
|
+
known = new Map;
|
|
166161
|
+
verdicts.set(destination, known);
|
|
166162
|
+
}
|
|
166163
|
+
for (const [catalog, wanted] of byCatalog) {
|
|
166164
|
+
const held = known.get(catalog);
|
|
166165
|
+
if (held && wanted.every(([, s, t]) => held.readable.has(key(s, t)))) {
|
|
166166
|
+
const [row] = await run(`SELECT id FROM ${ident(catalog)}.current_snapshot()`);
|
|
166167
|
+
if (row && String(row.id) === held.snapshot) {
|
|
166168
|
+
if (wanted.some(([, s, t]) => !held.readable.get(key(s, t)))) {
|
|
166169
|
+
return false;
|
|
166170
|
+
}
|
|
166171
|
+
continue;
|
|
166172
|
+
}
|
|
166173
|
+
}
|
|
166174
|
+
const matches = wanted.map(([, s, t]) => `(lower(t.table_schema) = lower(${literal(s)}) AND lower(t.table_name) = lower(${literal(t)}))`).join(" OR ");
|
|
166175
|
+
const rows = await run("SELECT s.id AS snapshot_id, t.table_schema, t.table_name, t.table_type " + `FROM ${ident(catalog)}.current_snapshot() s ` + "LEFT JOIN information_schema.tables t " + `ON t.table_catalog = ${literal(catalog)} AND (${matches})`);
|
|
166176
|
+
if (rows.length === 0)
|
|
166177
|
+
return false;
|
|
166178
|
+
const snapshot = String(rows[0].snapshot_id);
|
|
166179
|
+
const types = new Map;
|
|
166180
|
+
for (const r of rows) {
|
|
166181
|
+
if (r.table_name == null)
|
|
166182
|
+
continue;
|
|
166183
|
+
const k = key(String(r.table_schema), String(r.table_name));
|
|
166184
|
+
types.set(k, [...types.get(k) ?? [], r.table_type]);
|
|
166185
|
+
}
|
|
166186
|
+
const base = wanted.filter(([, s, t]) => {
|
|
166187
|
+
const found = types.get(key(s, t)) ?? [];
|
|
166188
|
+
return found.length === 1 && found[0] === "BASE TABLE";
|
|
166189
|
+
});
|
|
166190
|
+
const outside = base.length === wanted.length ? await fileOutsideScope(run, catalog, snapshot, base.map(([, s, t]) => [s, t]), prefixes) : "not a base table";
|
|
166191
|
+
const ok = outside === undefined;
|
|
166192
|
+
const readable = new Map(held?.snapshot === snapshot ? held.readable : []);
|
|
166193
|
+
for (const [, s, t] of wanted)
|
|
166194
|
+
readable.set(key(s, t), ok);
|
|
166195
|
+
known.set(catalog, { snapshot, readable });
|
|
166196
|
+
if (!ok)
|
|
166197
|
+
return false;
|
|
166198
|
+
}
|
|
166199
|
+
return true;
|
|
166200
|
+
}
|
|
166201
|
+
var literal = (value) => `'${value.replace(/'/g, "''")}'`, ident = (value) => `"${value.replace(/"/g, '""')}"`, verdicts;
|
|
166202
|
+
var init_same_catalog_tables = __esm(() => {
|
|
166203
|
+
init_connection_type();
|
|
166204
|
+
init_ducklake_catalog();
|
|
166205
|
+
init_duckdb_lockdown();
|
|
166206
|
+
verdicts = new WeakMap;
|
|
166207
|
+
});
|
|
166208
|
+
|
|
165928
166209
|
// src/service/materialization/run/materialization_build_session.ts
|
|
165929
166210
|
import { DuckDBConnection as DuckDBConnection5 } from "@malloydata/db-duckdb";
|
|
165930
166211
|
import {
|
|
@@ -166296,7 +166577,15 @@ async function buildSameCatalogIntoStorage(params) {
|
|
|
166296
166577
|
const captured = {};
|
|
166297
166578
|
const schema = await createTableWithDeclaredTypes(session, target, params.buildSQL, { columns: params.declaredColumns ?? [], ...params.castOptions }, {
|
|
166298
166579
|
captured,
|
|
166299
|
-
...params.replacesView ? { replacesView: params.replacesView } : {}
|
|
166580
|
+
...params.replacesView ? { replacesView: params.replacesView } : {},
|
|
166581
|
+
...params.sourceConnection.managed === true ? {
|
|
166582
|
+
beforeCreate: () => refuseOutOfScopeReads(session, params.buildSQL, {
|
|
166583
|
+
alias,
|
|
166584
|
+
destinationName,
|
|
166585
|
+
sourceConnection: params.sourceConnection,
|
|
166586
|
+
managedScope: params.managedScope
|
|
166587
|
+
})
|
|
166588
|
+
} : {}
|
|
166300
166589
|
});
|
|
166301
166590
|
return {
|
|
166302
166591
|
storageDestinationName: destinationName,
|
|
@@ -166307,6 +166596,77 @@ async function buildSameCatalogIntoStorage(params) {
|
|
|
166307
166596
|
};
|
|
166308
166597
|
});
|
|
166309
166598
|
}
|
|
166599
|
+
async function namesReadIn(selectSQL, alias) {
|
|
166600
|
+
const parsed = await serializeSQL(selectSQL);
|
|
166601
|
+
if (parsed.error || !Array.isArray(parsed.statements))
|
|
166602
|
+
return;
|
|
166603
|
+
const catalog = alias.toLowerCase();
|
|
166604
|
+
const names = [];
|
|
166605
|
+
const str = (v) => typeof v === "string" ? v.toLowerCase() : "";
|
|
166606
|
+
const walk = (node) => {
|
|
166607
|
+
if (node === null || typeof node !== "object")
|
|
166608
|
+
return;
|
|
166609
|
+
if (Array.isArray(node)) {
|
|
166610
|
+
node.forEach(walk);
|
|
166611
|
+
return;
|
|
166612
|
+
}
|
|
166613
|
+
const record = node;
|
|
166614
|
+
if (record.type === "BASE_TABLE") {
|
|
166615
|
+
const [c, s, t] = [
|
|
166616
|
+
str(record.catalog_name),
|
|
166617
|
+
str(record.schema_name),
|
|
166618
|
+
str(record.table_name)
|
|
166619
|
+
];
|
|
166620
|
+
if (c) {
|
|
166621
|
+
if (c === catalog)
|
|
166622
|
+
names.push([s || "main", t]);
|
|
166623
|
+
} else if (s) {
|
|
166624
|
+
names.push([s, t]);
|
|
166625
|
+
if (s === catalog)
|
|
166626
|
+
names.push(["main", t]);
|
|
166627
|
+
} else {
|
|
166628
|
+
names.push(["main", t]);
|
|
166629
|
+
}
|
|
166630
|
+
}
|
|
166631
|
+
Object.values(record).forEach(walk);
|
|
166632
|
+
};
|
|
166633
|
+
walk(parsed.statements);
|
|
166634
|
+
return names;
|
|
166635
|
+
}
|
|
166636
|
+
async function refuseOutOfScopeReads(session, selectSQL, params) {
|
|
166637
|
+
const { alias, destinationName, sourceConnection } = params;
|
|
166638
|
+
const names = await namesReadIn(selectSQL, alias);
|
|
166639
|
+
const refuse = (why) => new BadRequestError(`Cannot materialize a source from managed connection '${sourceConnection.name}' ` + `into storage destination '${destinationName}' that ${why}: the build ` + `reads the catalog with the destination's credential, so it reads only ` + `base tables whose files the connection's own storage scope reaches.`);
|
|
166640
|
+
if (!names)
|
|
166641
|
+
throw refuse("reads SQL it cannot parse");
|
|
166642
|
+
if (names.length === 0)
|
|
166643
|
+
return;
|
|
166644
|
+
const run = async (sql) => (await runInternalSQL(session, sql)).rows;
|
|
166645
|
+
let outside;
|
|
166646
|
+
try {
|
|
166647
|
+
const types = await run("SELECT lower(table_schema) AS s, lower(table_name) AS t, table_type " + "FROM information_schema.tables " + `WHERE lower(table_catalog) = '${alias.toLowerCase().replace(/'/g, "''")}'`);
|
|
166648
|
+
const typeOf = new Map(types.map((r) => [`${String(r.s)}.${String(r.t)}`, r.table_type]));
|
|
166649
|
+
const read = names.filter(([s, t]) => typeOf.has(`${s}.${t}`));
|
|
166650
|
+
if (read.some(([s, t]) => typeOf.get(`${s}.${t}`) !== "BASE TABLE")) {
|
|
166651
|
+
throw refuse("reads a view");
|
|
166652
|
+
}
|
|
166653
|
+
if (read.length === 0)
|
|
166654
|
+
return;
|
|
166655
|
+
const [snapshot] = await run(`SELECT id FROM ${quoteIdentifier(alias, STORAGE_DIALECT)}.current_snapshot()`);
|
|
166656
|
+
const distinct = [...new Map(read.map((r) => [r.join("."), r])).values()];
|
|
166657
|
+
const prefixes = await params.managedScope?.();
|
|
166658
|
+
if (!prefixes) {
|
|
166659
|
+
throw refuse("reads tables while its storage scope is not known (the connection is not attached)");
|
|
166660
|
+
}
|
|
166661
|
+
outside = await fileOutsideScope(run, alias, String(snapshot?.id), distinct, prefixes);
|
|
166662
|
+
} catch (error) {
|
|
166663
|
+
if (error instanceof BadRequestError)
|
|
166664
|
+
throw error;
|
|
166665
|
+
throw refuse("reads tables whose files could not be checked against its storage scope");
|
|
166666
|
+
}
|
|
166667
|
+
if (outside)
|
|
166668
|
+
throw refuse(`reads ${outside}`);
|
|
166669
|
+
}
|
|
166310
166670
|
function leaveOutFailing(files, err, build) {
|
|
166311
166671
|
if (!(err instanceof MalloyError3) || !build.leaveOutWithin?.length) {
|
|
166312
166672
|
return false;
|
|
@@ -166630,6 +166990,7 @@ async function createTableAndDescribe(session, quotedTablePath, selectSQL, optio
|
|
|
166630
166990
|
for (const sql of options.replacesView ?? []) {
|
|
166631
166991
|
await session.runSQL(sql);
|
|
166632
166992
|
}
|
|
166993
|
+
await options.beforeCreate?.();
|
|
166633
166994
|
await session.runSQL(`CREATE OR REPLACE TABLE ${quotedTablePath} AS (${selectSQL})`);
|
|
166634
166995
|
let described = await describeTable(session, quotedTablePath);
|
|
166635
166996
|
const renames = canonicalRenames(described, options.declaredNames ?? []);
|
|
@@ -166780,6 +167141,8 @@ var init_materialization_build_session = __esm(() => {
|
|
|
166780
167141
|
init_passthrough_build();
|
|
166781
167142
|
init_connection();
|
|
166782
167143
|
init_ducklake();
|
|
167144
|
+
init_single_select();
|
|
167145
|
+
init_same_catalog_tables();
|
|
166783
167146
|
init_dialects();
|
|
166784
167147
|
init_duckdb_session_setup();
|
|
166785
167148
|
init_connection_config();
|
|
@@ -167331,6 +167694,7 @@ function compileInputOf(b) {
|
|
|
167331
167694
|
holdsOnlyUngatedRows: _ungated,
|
|
167332
167695
|
retypedColumns: _retyped,
|
|
167333
167696
|
rollupKey: _rollupKey,
|
|
167697
|
+
grainJoinKeys: _grainJoinKeys,
|
|
167334
167698
|
...read
|
|
167335
167699
|
} = b;
|
|
167336
167700
|
input = JSON.stringify(read);
|
|
@@ -167454,6 +167818,62 @@ var init_served_copy_lanes = __esm(() => {
|
|
|
167454
167818
|
compileInputs = new WeakMap;
|
|
167455
167819
|
});
|
|
167456
167820
|
|
|
167821
|
+
// src/service/materialization/serve/sql_embed_reads.ts
|
|
167822
|
+
function sqlEmbedReads(modelDefs) {
|
|
167823
|
+
const out = new Map;
|
|
167824
|
+
for (const modelDef of modelDefs) {
|
|
167825
|
+
for (const select of sqlSelectsWithin(modelDef)) {
|
|
167826
|
+
const connection = select.connection;
|
|
167827
|
+
if (typeof connection !== "string")
|
|
167828
|
+
continue;
|
|
167829
|
+
const segments = select.selectSegments.filter((s) => typeof s === "object" && s !== null && !(("sql" in s) && s.type === undefined));
|
|
167830
|
+
if (segments.length === 0)
|
|
167831
|
+
continue;
|
|
167832
|
+
const isQuery = (s) => s.type === "query";
|
|
167833
|
+
const read = {
|
|
167834
|
+
via: labelOf(select),
|
|
167835
|
+
connection,
|
|
167836
|
+
...typeof select.sourceID === "string" ? { sourceID: select.sourceID } : {},
|
|
167837
|
+
reaches: reachableSourceIDs(segments.filter(isQuery), modelDef),
|
|
167838
|
+
bareReaches: reachableSourceIDs(segments.filter((s) => !isQuery(s)), modelDef)
|
|
167839
|
+
};
|
|
167840
|
+
const key = [
|
|
167841
|
+
read.via,
|
|
167842
|
+
connection,
|
|
167843
|
+
[...read.reaches].sort().join(","),
|
|
167844
|
+
[...read.bareReaches].sort().join(",")
|
|
167845
|
+
].join("\x00");
|
|
167846
|
+
if (!out.has(key))
|
|
167847
|
+
out.set(key, read);
|
|
167848
|
+
}
|
|
167849
|
+
}
|
|
167850
|
+
return [...out.values()];
|
|
167851
|
+
}
|
|
167852
|
+
function conflictingSqlEmbeds(reads, sourceID, servedOn, rerooted) {
|
|
167853
|
+
const out = [];
|
|
167854
|
+
for (const read of reads) {
|
|
167855
|
+
if (read.sourceID !== undefined && rerooted(read.sourceID))
|
|
167856
|
+
continue;
|
|
167857
|
+
if (read.bareReaches.has(sourceID)) {
|
|
167858
|
+
out.push({ read, conflict: "bare" });
|
|
167859
|
+
} else if (read.connection !== servedOn && read.reaches.has(sourceID)) {
|
|
167860
|
+
out.push({ read, conflict: "cross_connection" });
|
|
167861
|
+
}
|
|
167862
|
+
}
|
|
167863
|
+
return out;
|
|
167864
|
+
}
|
|
167865
|
+
function ownSqlEmbedReach(struct, modelDef) {
|
|
167866
|
+
const select = struct;
|
|
167867
|
+
if (select?.type !== "sql_select" || !Array.isArray(select.selectSegments)) {
|
|
167868
|
+
return new Set;
|
|
167869
|
+
}
|
|
167870
|
+
return reachableSourceIDs(select.selectSegments.filter((s) => typeof s === "object" && s !== null && !(("sql" in s) && s.type === undefined)), modelDef);
|
|
167871
|
+
}
|
|
167872
|
+
var init_sql_embed_reads = __esm(() => {
|
|
167873
|
+
init_sql_embeds();
|
|
167874
|
+
init_source_map();
|
|
167875
|
+
});
|
|
167876
|
+
|
|
167457
167877
|
// src/service/materialization/text/chain_build_files.ts
|
|
167458
167878
|
function chainBuildFileSet(args) {
|
|
167459
167879
|
const { lift } = args;
|
|
@@ -170350,6 +170770,7 @@ async function readSameCatalogThroughDestination(args) {
|
|
|
170350
170770
|
...declaringFiles(args.modelDef, names)
|
|
170351
170771
|
]);
|
|
170352
170772
|
const out = new Map(args.files);
|
|
170773
|
+
const moved = [];
|
|
170353
170774
|
for (const move of moves) {
|
|
170354
170775
|
const paths = [];
|
|
170355
170776
|
for (const url of urls) {
|
|
@@ -170379,13 +170800,24 @@ async function readSameCatalogThroughDestination(args) {
|
|
|
170379
170800
|
const [catalog, schema, table] = destinationTablePath(path, move).split(".");
|
|
170380
170801
|
return [catalog, schema, table];
|
|
170381
170802
|
});
|
|
170382
|
-
|
|
170383
|
-
|
|
170803
|
+
const read = {
|
|
170804
|
+
alias: move.alias,
|
|
170805
|
+
connection: move.connection,
|
|
170806
|
+
schemas: move.schemas,
|
|
170807
|
+
tables
|
|
170808
|
+
};
|
|
170809
|
+
if (!await args.ports.readable(read)) {
|
|
170810
|
+
return {
|
|
170811
|
+
declined: "a table it reads is not a base table, or holds a file outside the connection's storage scope"
|
|
170812
|
+
};
|
|
170384
170813
|
}
|
|
170814
|
+
if (tables.length > 0)
|
|
170815
|
+
moved.push(read);
|
|
170385
170816
|
}
|
|
170386
170817
|
return {
|
|
170387
170818
|
files: out,
|
|
170388
|
-
destinations: new Set(moves.map((m) => m.destination))
|
|
170819
|
+
destinations: new Set(moves.map((m) => m.destination)),
|
|
170820
|
+
moved
|
|
170389
170821
|
};
|
|
170390
170822
|
}
|
|
170391
170823
|
var PLAIN;
|
|
@@ -170412,17 +170844,6 @@ async function sameCatalogScope(config, connection, alias) {
|
|
|
170412
170844
|
const schemas = managedSchemasOf(source);
|
|
170413
170845
|
return schemas && isSameCatalog(connectionConfigOf(source), connectionConfigOf(destination)) ? schemas : undefined;
|
|
170414
170846
|
}
|
|
170415
|
-
async function allBaseTables(config, alias, tables) {
|
|
170416
|
-
const destination = await config.connections.lookupConnection(alias);
|
|
170417
|
-
for (const [catalog, schema, table] of tables) {
|
|
170418
|
-
const result = await destination.runSQL("SELECT table_type FROM information_schema.tables " + `WHERE table_catalog = '${catalog}' ` + `AND lower(table_schema) = lower('${schema}') ` + `AND lower(table_name) = lower('${table}')`);
|
|
170419
|
-
const rows = result.rows;
|
|
170420
|
-
if (rows.length !== 1 || rows[0].table_type !== "BASE TABLE") {
|
|
170421
|
-
return false;
|
|
170422
|
-
}
|
|
170423
|
-
}
|
|
170424
|
-
return true;
|
|
170425
|
-
}
|
|
170426
170847
|
var init_same_catalog_destination = __esm(() => {
|
|
170427
170848
|
init_connection_type();
|
|
170428
170849
|
init_same_catalog_build();
|
|
@@ -171276,6 +171697,21 @@ import {
|
|
|
171276
171697
|
function servedConnectionOf(b) {
|
|
171277
171698
|
return isDatabase(b) ? b.destinationName : servedCopyAlias(b.destinationName);
|
|
171278
171699
|
}
|
|
171700
|
+
function importedFileURLs(modelDef) {
|
|
171701
|
+
const urls = new Set;
|
|
171702
|
+
const walk = (tree, depth) => {
|
|
171703
|
+
if (depth > 64 || typeof tree !== "object" || tree === null)
|
|
171704
|
+
return;
|
|
171705
|
+
for (const [url, below] of Object.entries(tree)) {
|
|
171706
|
+
if (urls.has(url))
|
|
171707
|
+
continue;
|
|
171708
|
+
urls.add(url);
|
|
171709
|
+
walk(below, depth + 1);
|
|
171710
|
+
}
|
|
171711
|
+
};
|
|
171712
|
+
walk(modelDef?.dependencies, 0);
|
|
171713
|
+
return [...urls];
|
|
171714
|
+
}
|
|
171279
171715
|
function leftOutJoinDetail(joins) {
|
|
171280
171716
|
const named = joins.map((j) => {
|
|
171281
171717
|
const join = j.join ?? j.name;
|
|
@@ -171475,6 +171911,7 @@ class ServedCopyServe {
|
|
|
171475
171911
|
...asWritten ? { tableIds: asWritten.tableIds } : {}
|
|
171476
171912
|
});
|
|
171477
171913
|
}
|
|
171914
|
+
await this.recheckSameCatalog(compiled);
|
|
171478
171915
|
const declined = compiled.declined?.get(queryString);
|
|
171479
171916
|
if (declined !== undefined)
|
|
171480
171917
|
throw declined;
|
|
@@ -171684,6 +172121,7 @@ class ServedCopyServe {
|
|
|
171684
172121
|
};
|
|
171685
172122
|
}
|
|
171686
172123
|
async checkJoinVariant(compiled, args) {
|
|
172124
|
+
await this.recheckSameCatalog(compiled);
|
|
171687
172125
|
const decline = (reason, code, callerDetail) => {
|
|
171688
172126
|
throw new LegDecline(code, callerDetail, { message: reason });
|
|
171689
172127
|
};
|
|
@@ -171719,6 +172157,17 @@ class ServedCopyServe {
|
|
|
171719
172157
|
decline
|
|
171720
172158
|
});
|
|
171721
172159
|
}
|
|
172160
|
+
async recheckSameCatalog(compiled) {
|
|
172161
|
+
if (!compiled.sameCatalogRecheck)
|
|
172162
|
+
return;
|
|
172163
|
+
const ok = await compiled.sameCatalogRecheck().catch(() => false);
|
|
172164
|
+
if (ok)
|
|
172165
|
+
return;
|
|
172166
|
+
logger.warn("A served copy's table read through its storage destination is no longer a base table, holds a file outside the managed connection's storage scope, or could not be checked; answering live", { modelPath: this.host.modelPath() });
|
|
172167
|
+
throw new LegDecline("served_copy_not_served", undefined, {
|
|
172168
|
+
message: "a table the served copy reads through its storage destination is no longer a base table, holds a file outside the managed connection's storage scope, or could not be checked"
|
|
172169
|
+
});
|
|
172170
|
+
}
|
|
171722
172171
|
readsRollingWindow(binding) {
|
|
171723
172172
|
return (binding.sourceIDs ?? []).some((id) => rollingWindowsOf(this.materializePlans[id]?.readTimeTerms).length > 0);
|
|
171724
172173
|
}
|
|
@@ -172047,6 +172496,39 @@ class ServedCopyServe {
|
|
|
172047
172496
|
rerootedSpans
|
|
172048
172497
|
};
|
|
172049
172498
|
}
|
|
172499
|
+
ownSqlEmbedReach(struct, modelDef) {
|
|
172500
|
+
return ownSqlEmbedReach(struct, modelDef);
|
|
172501
|
+
}
|
|
172502
|
+
withoutConflictingSqlEmbeds(candidates, map, problems) {
|
|
172503
|
+
const modelDef = this.host.modelDef();
|
|
172504
|
+
const reads = sqlEmbedReads([
|
|
172505
|
+
modelDef,
|
|
172506
|
+
...importedFileURLs(modelDef).map((url) => this.host.siblingModelDef?.(url))
|
|
172507
|
+
]);
|
|
172508
|
+
if (reads.length === 0)
|
|
172509
|
+
return candidates;
|
|
172510
|
+
const rerootedIDs = new Set(candidates.map((c) => c.reroot.sourceID));
|
|
172511
|
+
const rerooted = (sqlSourceID) => {
|
|
172512
|
+
const node = map.node(sqlSourceID);
|
|
172513
|
+
const chain = node ? map.chainOf(node.def) : [sqlSourceID];
|
|
172514
|
+
return chain.some((id) => rerootedIDs.has(id));
|
|
172515
|
+
};
|
|
172516
|
+
return candidates.filter((c) => {
|
|
172517
|
+
const conflicts = conflictingSqlEmbeds(reads, c.reroot.sourceID, servedConnectionOf(c.binding), rerooted);
|
|
172518
|
+
if (conflicts.length === 0)
|
|
172519
|
+
return true;
|
|
172520
|
+
const whole = conflicts.some((x) => x.conflict === "bare");
|
|
172521
|
+
problems.push({
|
|
172522
|
+
sourceName: c.reroot.sourceName,
|
|
172523
|
+
sourceID: c.reroot.sourceID,
|
|
172524
|
+
reason: whole ? "sql_embed_bare" : "sql_embed_cross_connection",
|
|
172525
|
+
detail: [
|
|
172526
|
+
...new Set(conflicts.filter((x) => !whole || x.conflict === "bare").map(({ read }) => `\`${read.via}\` on \`${read.connection}\``))
|
|
172527
|
+
].join(", ")
|
|
172528
|
+
});
|
|
172529
|
+
return false;
|
|
172530
|
+
});
|
|
172531
|
+
}
|
|
172050
172532
|
rerootCandidates(bindings, map, lift, problems, lane, passedOver = new Set, twins, restatesStageZoned = false) {
|
|
172051
172533
|
let candidates = [];
|
|
172052
172534
|
const reservedNames = modelFieldNames(map);
|
|
@@ -172076,6 +172558,7 @@ class ServedCopyServe {
|
|
|
172076
172558
|
const tiers = (byKey.get(keyOf(c)) ?? []).filter((o) => !passedOver.has(o.binding)).map((o) => o.binding.tier);
|
|
172077
172559
|
return servedCopyReadsTier(c.binding.tier, tiers);
|
|
172078
172560
|
});
|
|
172561
|
+
candidates = this.withoutConflictingSqlEmbeds(candidates, map, problems);
|
|
172079
172562
|
const rerootedIDs = new Set(candidates.map((c) => c.reroot.sourceID));
|
|
172080
172563
|
const rerootedNames = new Set(candidates.map((c) => c.reroot.sourceName));
|
|
172081
172564
|
const throughBase = [];
|
|
@@ -172245,7 +172728,7 @@ class ServedCopyServe {
|
|
|
172245
172728
|
const packagePath = this.packagePath;
|
|
172246
172729
|
const packageConfig = this.packageConfig;
|
|
172247
172730
|
const config = servedCopyConfig(packageConfig, destinations(), new Set(rerooted.filter((b) => !isDatabase(b)).map((b) => b.destinationName)));
|
|
172248
|
-
const load = this.passLoader(packagePath, config);
|
|
172731
|
+
const load = this.passLoader(packagePath, config, aliased);
|
|
172249
172732
|
const underAlias = this.underAliasLoader(packagePath, packageConfig, destinations, rerooted);
|
|
172250
172733
|
const loaded = await this.loadCopy(state, copy, overlay, load, lift, config, underAlias);
|
|
172251
172734
|
if (loaded === "retry")
|
|
@@ -172262,7 +172745,6 @@ class ServedCopyServe {
|
|
|
172262
172745
|
};
|
|
172263
172746
|
}
|
|
172264
172747
|
const { materializer, servedDef, servedRuntime, leftOut, files } = loaded;
|
|
172265
|
-
const compiledConfig = loaded.config ?? config;
|
|
172266
172748
|
problems.push(...state.inlinedKept.filter((p) => state.candidates.some((c) => c.reroot.sourceName === p.sourceName)));
|
|
172267
172749
|
state.inlinedKept = [];
|
|
172268
172750
|
problems.push(...state.pairsDropped);
|
|
@@ -172282,10 +172764,11 @@ class ServedCopyServe {
|
|
|
172282
172764
|
materializer,
|
|
172283
172765
|
leftOut,
|
|
172284
172766
|
files,
|
|
172285
|
-
config:
|
|
172767
|
+
config: loaded.config ?? config,
|
|
172286
172768
|
rerooted,
|
|
172287
172769
|
aliased,
|
|
172288
|
-
throughBase
|
|
172770
|
+
throughBase,
|
|
172771
|
+
sameCatalogReads: loaded.sameCatalogReads
|
|
172289
172772
|
});
|
|
172290
172773
|
}
|
|
172291
172774
|
return {
|
|
@@ -172299,12 +172782,20 @@ class ServedCopyServe {
|
|
|
172299
172782
|
};
|
|
172300
172783
|
}
|
|
172301
172784
|
underAliasLoader(packagePath, packageConfig, destinations, rerooted) {
|
|
172785
|
+
const aliased = rerooted.map((b) => ({
|
|
172786
|
+
...b,
|
|
172787
|
+
destinationName: servedConnectionOf(b)
|
|
172788
|
+
}));
|
|
172302
172789
|
return (names) => {
|
|
172303
172790
|
const config = servedCopyConfig(packageConfig, destinations(), new Set(rerooted.filter((b) => !isDatabase(b)).map((b) => b.destinationName)), names);
|
|
172304
|
-
return {
|
|
172791
|
+
return {
|
|
172792
|
+
config,
|
|
172793
|
+
load: this.passLoader(packagePath, config, aliased)
|
|
172794
|
+
};
|
|
172305
172795
|
};
|
|
172306
172796
|
}
|
|
172307
|
-
passLoader(packagePath, config) {
|
|
172797
|
+
passLoader(packagePath, config, aliased) {
|
|
172798
|
+
const virtualMap = buildVirtualMap(aliased);
|
|
172308
172799
|
const modelPath = this.host.modelPath();
|
|
172309
172800
|
const compiler = packageFiles(packagePath, modelPath, config);
|
|
172310
172801
|
return async (files) => {
|
|
@@ -172312,11 +172803,14 @@ class ServedCopyServe {
|
|
|
172312
172803
|
packagePath,
|
|
172313
172804
|
modelPath,
|
|
172314
172805
|
config,
|
|
172315
|
-
files: keyedOverlay(files)
|
|
172806
|
+
files: keyedOverlay(files),
|
|
172807
|
+
virtualMap
|
|
172316
172808
|
});
|
|
172317
172809
|
if (elsewhere)
|
|
172318
172810
|
return elsewhere;
|
|
172319
|
-
const { runtime, materializer } = await compiler.loadModel(files
|
|
172811
|
+
const { runtime, materializer } = await compiler.loadModel(files, {
|
|
172812
|
+
virtualMap
|
|
172813
|
+
});
|
|
172320
172814
|
const model = await materializer.getModel();
|
|
172321
172815
|
return {
|
|
172322
172816
|
materializer,
|
|
@@ -172472,7 +172966,7 @@ class ServedCopyServe {
|
|
|
172472
172966
|
ports: {
|
|
172473
172967
|
scope: (connection, alias) => sameCatalogScope(config, connection, alias),
|
|
172474
172968
|
pathRefusal: (path, connection, schemas) => this.host.managedTablePathRefusal ? this.host.managedTablePathRefusal(path, connection, schemas) : Promise.resolve("no managed scope check is available"),
|
|
172475
|
-
|
|
172969
|
+
readable: (read) => this.host.sameCatalogTablesReadable ? this.host.sameCatalogTablesReadable(config, read) : Promise.resolve(false)
|
|
172476
172970
|
}
|
|
172477
172971
|
}).catch(() => ({ declined: "a read of its connections failed" }));
|
|
172478
172972
|
if ("declined" in moved) {
|
|
@@ -172490,7 +172984,8 @@ class ServedCopyServe {
|
|
|
172490
172984
|
servedRuntime: loaded.runtime,
|
|
172491
172985
|
leftOut: [],
|
|
172492
172986
|
files: keyed,
|
|
172493
|
-
config: aliased
|
|
172987
|
+
config: aliased,
|
|
172988
|
+
sameCatalogReads: moved.moved
|
|
172494
172989
|
};
|
|
172495
172990
|
} catch (again) {
|
|
172496
172991
|
logger.debug("A served copy's same-catalog read does not compile; its joins are left out", {
|
|
@@ -172554,6 +173049,7 @@ class ServedCopyServe {
|
|
|
172554
173049
|
const { key, generation, over, lane, modelDef, servedMap } = built;
|
|
172555
173050
|
const { servedDef, servedRuntime, materializer, leftOut } = built;
|
|
172556
173051
|
const { files, config, rerooted, aliased, throughBase } = built;
|
|
173052
|
+
const sameCatalogReads = built.sameCatalogReads ?? [];
|
|
172557
173053
|
const optOutIDs = new Set;
|
|
172558
173054
|
for (const node of servedMap.nodes()) {
|
|
172559
173055
|
if (optsOutOfPersist(node.def)) {
|
|
@@ -172622,6 +173118,15 @@ class ServedCopyServe {
|
|
|
172622
173118
|
rerooted,
|
|
172623
173119
|
rerootedSourceIDs: rerootedSourceIDsOf(candidates, throughBase),
|
|
172624
173120
|
...throughBase.length > 0 ? { throughBase } : {},
|
|
173121
|
+
...sameCatalogReads.length > 0 ? {
|
|
173122
|
+
sameCatalogRecheck: async () => {
|
|
173123
|
+
const readable = this.host.sameCatalogTablesReadable;
|
|
173124
|
+
if (!readable)
|
|
173125
|
+
return false;
|
|
173126
|
+
const each = await Promise.all(sameCatalogReads.map((r) => readable(config, r)));
|
|
173127
|
+
return each.every(Boolean);
|
|
173128
|
+
}
|
|
173129
|
+
} : {},
|
|
172625
173130
|
aliased,
|
|
172626
173131
|
problems,
|
|
172627
173132
|
pairs: candidates.flatMap((c) => c.reroot.pair ? [
|
|
@@ -173771,6 +174276,7 @@ var init_served_copy_serve = __esm(() => {
|
|
|
173771
174276
|
init_filter_binding_guard();
|
|
173772
174277
|
init_authorize();
|
|
173773
174278
|
init_overlay_key();
|
|
174279
|
+
init_sql_embed_reads();
|
|
173774
174280
|
init_event_loop_yield();
|
|
173775
174281
|
init_package_files();
|
|
173776
174282
|
init_source_map();
|
|
@@ -173935,6 +174441,92 @@ var init_storage_bindings = __esm(() => {
|
|
|
173935
174441
|
init_stored_column_types();
|
|
173936
174442
|
});
|
|
173937
174443
|
|
|
174444
|
+
// src/service/materialization/domain/source_decline.ts
|
|
174445
|
+
function byActionability(reasons) {
|
|
174446
|
+
const rank = (r) => {
|
|
174447
|
+
const at = ACTIONABLE_ORDER.indexOf(r);
|
|
174448
|
+
return at < 0 ? ACTIONABLE_ORDER.length : at;
|
|
174449
|
+
};
|
|
174450
|
+
return [...new Set(reasons)].map((r, i) => ({ r, i })).sort((a, b) => rank(a.r) - rank(b.r) || a.i - b.i).map((x) => x.r);
|
|
174451
|
+
}
|
|
174452
|
+
function servesInPart(reason) {
|
|
174453
|
+
const row = SOURCE_DECLINES[reason];
|
|
174454
|
+
return row.servesInPart === true;
|
|
174455
|
+
}
|
|
174456
|
+
function servedCopyOutcomes(problems, rerootedSourceIDs) {
|
|
174457
|
+
const bySource = new Map;
|
|
174458
|
+
const out = [];
|
|
174459
|
+
for (const p of problems) {
|
|
174460
|
+
const key = p.sourceID !== undefined ? `id:${p.sourceID}` : p.sourceName !== undefined ? `name:${p.sourceName}` : undefined;
|
|
174461
|
+
if (key === undefined) {
|
|
174462
|
+
out.push({ outcome: "declined", reason: p.reason });
|
|
174463
|
+
continue;
|
|
174464
|
+
}
|
|
174465
|
+
const reasons = bySource.get(key) ?? [];
|
|
174466
|
+
reasons.push(p.reason);
|
|
174467
|
+
bySource.set(key, reasons);
|
|
174468
|
+
}
|
|
174469
|
+
for (const [key, reasons] of bySource) {
|
|
174470
|
+
const leavesOut = reasons.find((r) => !servesInPart(r));
|
|
174471
|
+
if (leavesOut !== undefined) {
|
|
174472
|
+
out.push({ outcome: "declined", reason: leavesOut });
|
|
174473
|
+
continue;
|
|
174474
|
+
}
|
|
174475
|
+
const stillServed = key.startsWith("id:") && rerootedSourceIDs.has(key.slice(3));
|
|
174476
|
+
out.push({
|
|
174477
|
+
outcome: stillServed ? "partial" : "declined",
|
|
174478
|
+
reason: reasons[0]
|
|
174479
|
+
});
|
|
174480
|
+
}
|
|
174481
|
+
return out;
|
|
174482
|
+
}
|
|
174483
|
+
var SOURCE_DECLINES, SQL_EMBED_FIX, ACTIONABLE_ORDER, SOURCE_DECLINE_REASONS;
|
|
174484
|
+
var init_source_decline = __esm(() => {
|
|
174485
|
+
SOURCE_DECLINES = {
|
|
174486
|
+
build_plan_unavailable: { stage: "bind" },
|
|
174487
|
+
refused: { stage: "bind" },
|
|
174488
|
+
missing_table: { stage: "bind" },
|
|
174489
|
+
unquotable_name: { stage: "bind" },
|
|
174490
|
+
compile_failed: { stage: "served_copy" },
|
|
174491
|
+
cross_connection_unbuilt: { stage: "served_copy" },
|
|
174492
|
+
column_types: { stage: "served_copy" },
|
|
174493
|
+
no_declaration: { stage: "served_copy" },
|
|
174494
|
+
definition_not_parsed: { stage: "served_copy" },
|
|
174495
|
+
pair_join_not_found: { stage: "served_copy" },
|
|
174496
|
+
pair_not_compiled: { stage: "served_copy" },
|
|
174497
|
+
fields_not_carried: { stage: "served_copy" },
|
|
174498
|
+
read_terms_not_kept: { stage: "served_copy" },
|
|
174499
|
+
cross_connection_join: { stage: "served_copy", servesInPart: true },
|
|
174500
|
+
inline_join_kept: { stage: "served_copy", servesInPart: true },
|
|
174501
|
+
reroot_not_compiled: { stage: "served_copy" },
|
|
174502
|
+
classification_not_kept: { stage: "served_copy" },
|
|
174503
|
+
sql_embed_cross_connection: { stage: "served_copy" },
|
|
174504
|
+
sql_embed_bare: { stage: "served_copy" }
|
|
174505
|
+
};
|
|
174506
|
+
SQL_EMBED_FIX = {
|
|
174507
|
+
sql_embed_cross_connection: "To serve it, persist the `.sql()` source itself with the same `storage=` as the sources " + "its `%{}` reads: the copy then reads the `.sql()` source's own table, and theirs serve too. " + "Or drop `storage=` from the sources it reads, so they are built in their own database, where " + "its `%{}` reads their tables. On a DuckLake or managed connection, which builds no author SQL " + "and places every table itself, build what it reads into a warehouse table and read that with " + "`.table()`.",
|
|
174508
|
+
sql_embed_bare: "To serve it, embed it as a query, `%{ <source> -> { select: * } }` (whose columns are the " + "source's fields, not its SQL's): in the source's own database the copy then reads its table, " + "and in a storage destination the fix for `sql_embed_cross_connection` applies."
|
|
174509
|
+
};
|
|
174510
|
+
ACTIONABLE_ORDER = [
|
|
174511
|
+
"cross_connection_join",
|
|
174512
|
+
"cross_connection_unbuilt",
|
|
174513
|
+
"sql_embed_cross_connection",
|
|
174514
|
+
"sql_embed_bare",
|
|
174515
|
+
"inline_join_kept",
|
|
174516
|
+
"read_terms_not_kept",
|
|
174517
|
+
"fields_not_carried",
|
|
174518
|
+
"column_types",
|
|
174519
|
+
"classification_not_kept",
|
|
174520
|
+
"pair_join_not_found",
|
|
174521
|
+
"pair_not_compiled",
|
|
174522
|
+
"definition_not_parsed",
|
|
174523
|
+
"compile_failed",
|
|
174524
|
+
"no_declaration",
|
|
174525
|
+
"reroot_not_compiled"
|
|
174526
|
+
];
|
|
174527
|
+
SOURCE_DECLINE_REASONS = Object.keys(SOURCE_DECLINES);
|
|
174528
|
+
});
|
|
174529
|
+
|
|
173938
174530
|
// ../../node_modules/cron-parser/dist/fields/types.js
|
|
173939
174531
|
var require_types3 = __commonJS(function(exports) {
|
|
173940
174532
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -180685,6 +181277,33 @@ function deploymentVerdict(s, destination, storageBound) {
|
|
|
180685
181277
|
}
|
|
180686
181278
|
return;
|
|
180687
181279
|
}
|
|
181280
|
+
function contractLiveVerdict(s) {
|
|
181281
|
+
const { source, facts, subject, live } = s;
|
|
181282
|
+
const judged = facts.contractVerdicts?.get(source.sourceEntityId ?? "");
|
|
181283
|
+
if (!judged)
|
|
181284
|
+
return;
|
|
181285
|
+
const table = {
|
|
181286
|
+
physicalTableName: judged.physicalTableName,
|
|
181287
|
+
...judged.builtAt ? { builtAt: judged.builtAt } : {}
|
|
181288
|
+
};
|
|
181289
|
+
if (judged.reason === "upstream_unread") {
|
|
181290
|
+
return {
|
|
181291
|
+
...live("upstream_unread", `${subject}'s table is bound, but the read of a warehouse table ` + `it was built from failed, so whether that table changed since ` + `the build is not known; no query is answered from it until a ` + `read of it succeeds and finds it unchanged.`, [
|
|
181292
|
+
"Restore the warehouse connection, or the catalog read that failed: the package's next manifest bind or rebind reads it again.",
|
|
181293
|
+
"Or reload the package."
|
|
181294
|
+
]),
|
|
181295
|
+
table
|
|
181296
|
+
};
|
|
181297
|
+
}
|
|
181298
|
+
return judged.reason === "contract_missing" ? {
|
|
181299
|
+
...live("contract_missing", `${subject}'s table carries no column contract (it was built ` + `before contracts were recorded), so no query is answered ` + `from it until a build rebuilds it in full.`, ["Run a build: the table is rebuilt in full, with its contract."]),
|
|
181300
|
+
table
|
|
181301
|
+
} : {
|
|
181302
|
+
...live("incompatible", `${subject}'s table no longer matches the column contract its ` + `build recorded (${judged.incompatibility?.code ?? "changed"}: ` + `${(judged.incompatibility?.columns ?? []).join(", ")}), so no ` + `query is answered from it until a build rebuilds it.`, ["Run a build: the table is rebuilt from its source."]),
|
|
181303
|
+
table,
|
|
181304
|
+
...judged.incompatibility ? { incompatibility: judged.incompatibility } : {}
|
|
181305
|
+
};
|
|
181306
|
+
}
|
|
180688
181307
|
function boundVerdict(s, storageBound, materialized) {
|
|
180689
181308
|
const { sourceID, source, facts, origin, tier, subject, live } = s;
|
|
180690
181309
|
const copy = s.servedCopy ? facts.servedCopyOutcome?.(sourceID) : undefined;
|
|
@@ -180692,7 +181311,13 @@ function boundVerdict(s, storageBound, materialized) {
|
|
|
180692
181311
|
...copy && copy.notServedIn.length > 0 ? { notServedIn: copy.notServedIn } : {}
|
|
180693
181312
|
};
|
|
180694
181313
|
const base = { ...s.base, ...where };
|
|
180695
|
-
const
|
|
181314
|
+
const sqlEmbedReasons = new Set((copy?.notServedIn ?? []).flatMap((n) => n.reasons));
|
|
181315
|
+
const onlySqlEmbed = copy !== undefined && copy.notServedIn.length > 0 && [...sqlEmbedReasons].every((r) => r === "sql_embed_cross_connection" || r === "sql_embed_bare");
|
|
181316
|
+
const notServed = () => onlySqlEmbed ? {
|
|
181317
|
+
...live("served_copy", `${subject}'s table is bound, but a \`.sql()\` source's ` + "`%{}` reads it " + (sqlEmbedReasons.has("sql_embed_bare") ? "whole (`%{ <source> }`), which its stored table " + "cannot be embedded as" : "with SQL that runs on another connection than its " + "table is read on (a storage destination, or a " + "managed catalog read through one), which a `%{}` " + "cannot reach") + ", so no query is answered from it (" + copy.notServedIn.map((n) => n.model).join(", ") + "). The served-copy-not-served warning names the " + "`.sql()` source.", [...sqlEmbedReasons].map((r) => SQL_EMBED_FIX[r])),
|
|
181318
|
+
...where
|
|
181319
|
+
} : notServedAny();
|
|
181320
|
+
const notServedAny = () => ({
|
|
180696
181321
|
...live("served_copy", `${subject}'s table is bound, but no model's served copy reads ` + `it, so no query is answered from it` + (copy && copy.notServedIn.length > 0 ? ` (${copy.notServedIn.map((n) => `${n.model}: ${n.reasons.join(", ")}`).join("; ")})` : "") + `. The served-copy-not-served warning on each model says why.`, origin === "materialize" ? [
|
|
180697
181322
|
"Fix what the served-copy-not-served warning names, if there is one.",
|
|
180698
181323
|
"Or drop #(materialize) from it if a source it is built on already answers its queries."
|
|
@@ -180705,25 +181330,7 @@ function boundVerdict(s, storageBound, materialized) {
|
|
|
180705
181330
|
const stale = () => live("stale", `${subject}'s table is past its freshness window, so no query is ` + `answered from it until a build refreshes it.`, [
|
|
180706
181331
|
"Run a build, or widen the freshness window, or set its fallback to stale_ok."
|
|
180707
181332
|
]);
|
|
180708
|
-
const contractVerdict = () =>
|
|
180709
|
-
const judged = facts.contractVerdicts?.get(source.sourceEntityId ?? "");
|
|
180710
|
-
if (!judged)
|
|
180711
|
-
return;
|
|
180712
|
-
const table = {
|
|
180713
|
-
physicalTableName: judged.physicalTableName,
|
|
180714
|
-
...judged.builtAt ? { builtAt: judged.builtAt } : {}
|
|
180715
|
-
};
|
|
180716
|
-
return judged.reason === "contract_missing" ? {
|
|
180717
|
-
...live("contract_missing", `${subject}'s table carries no column contract (it was built ` + `before contracts were recorded), so no query is answered ` + `from it until a build rebuilds it in full.`, [
|
|
180718
|
-
"Run a build: the table is rebuilt in full, with its contract."
|
|
180719
|
-
]),
|
|
180720
|
-
table
|
|
180721
|
-
} : {
|
|
180722
|
-
...live("incompatible", `${subject}'s table no longer matches the column contract its ` + `build recorded (${judged.incompatibility?.code ?? "changed"}: ` + `${(judged.incompatibility?.columns ?? []).join(", ")}), so no ` + `query is answered from it until a build rebuilds it.`, ["Run a build: the table is rebuilt from its source."]),
|
|
180723
|
-
table,
|
|
180724
|
-
...judged.incompatibility ? { incompatibility: judged.incompatibility } : {}
|
|
180725
|
-
};
|
|
180726
|
-
};
|
|
181333
|
+
const contractVerdict = () => contractLiveVerdict(s);
|
|
180727
181334
|
if (tier === "storage") {
|
|
180728
181335
|
const views = facts.views?.get(sourceID);
|
|
180729
181336
|
const withViews = views && views.length > 0 ? { views } : {};
|
|
@@ -180778,6 +181385,7 @@ function boundVerdict(s, storageBound, materialized) {
|
|
|
180778
181385
|
}
|
|
180779
181386
|
var MATERIALIZATION_UNREACHABLE_CODE = "materialization-unreachable", MATERIALIZATION_DESTINATION_MISSING_CODE = "materialization-destination-missing", MATERIALIZATION_CONNECTION_CANNOT_HOLD_TABLE_CODE = "materialization-connection-cannot-hold-table", MATERIALIZATION_CONTRACT_MISSING_CODE = "materialization-contract-missing", MATERIALIZATION_TABLE_INCOMPATIBLE_CODE = "materialization-table-incompatible", VERDICT_WARNING_CODES;
|
|
180780
181387
|
var init_serve_verdict = __esm(() => {
|
|
181388
|
+
init_source_decline();
|
|
180781
181389
|
init_table_plans();
|
|
180782
181390
|
VERDICT_WARNING_CODES = {
|
|
180783
181391
|
unreachable: MATERIALIZATION_UNREACHABLE_CODE,
|
|
@@ -180815,6 +181423,31 @@ function repeatedJoinOneKeyWarnings(plan, databaseEntries, storageBindings) {
|
|
|
180815
181423
|
if (b.rollupKey)
|
|
180816
181424
|
checks.set(b.virtualHandle, b.rollupKey);
|
|
180817
181425
|
}
|
|
181426
|
+
const grainJoins = new Map(Object.entries(databaseEntries ?? {}).flatMap(([id, entry]) => entry.keyUniqueness?.grainJoinKeys ? [[id, entry.keyUniqueness.grainJoinKeys]] : []));
|
|
181427
|
+
for (const b of storageBindings) {
|
|
181428
|
+
if (b.grainJoinKeys)
|
|
181429
|
+
grainJoins.set(b.virtualHandle, b.grainJoinKeys);
|
|
181430
|
+
}
|
|
181431
|
+
for (const [sourceEntityId, keys] of grainJoins) {
|
|
181432
|
+
const source = bySourceEntity.get(sourceEntityId);
|
|
181433
|
+
const rollup = source?.preaggregate;
|
|
181434
|
+
if (!rollup)
|
|
181435
|
+
continue;
|
|
181436
|
+
for (const [joinKey, unique] of Object.entries(keys)) {
|
|
181437
|
+
if (unique)
|
|
181438
|
+
continue;
|
|
181439
|
+
const dot = joinKey.indexOf(".");
|
|
181440
|
+
const join = joinKey.slice(0, dot);
|
|
181441
|
+
const keyColumn = joinKey.slice(dot + 1);
|
|
181442
|
+
warnings.push({
|
|
181443
|
+
...source?.modelPath ? { model: source.modelPath } : {},
|
|
181444
|
+
subject: rollup.baseSourceName,
|
|
181445
|
+
code: ROLLUP_JOIN_ONE_KEY_REPEATED_CODE,
|
|
181446
|
+
severity: "warn",
|
|
181447
|
+
message: `joins \`${join}\` on \`${keyColumn}\`, which the joined ` + `source holds more than once, found by its #(rollup) ` + `rollup's last build (grain ` + `${rollup.grainDimensions.join(", ")}): the rollup was built ` + `over that join_one, so its partials repeat the rows each ` + `key meets. Queries that read nothing through \`${join}\` are ` + `answered live. Fix the data or declare the join as join_many.`
|
|
181448
|
+
});
|
|
181449
|
+
}
|
|
181450
|
+
}
|
|
180818
181451
|
for (const [sourceEntityId, check] of checks) {
|
|
180819
181452
|
if (check?.unique !== false || check.keyColumn === undefined)
|
|
180820
181453
|
continue;
|
|
@@ -181237,6 +181870,10 @@ function servedCopyProblemReasonMessage(problem, inlinedButKept = false, takesIn
|
|
|
181237
181870
|
return `This source inlines its join${join ? ` \`${join}\`` : ""} (inline=), but its served copy does not compile ` + "with the join answered from the stored columns, so the join is kept as written and every query " + "through it reads the joined source through the join" + compilerReasons(problem.detail) + " A definition that reads the joined source past one hop (a join of the joined source), or reads " + "one of its measures or views, is the usual cause.";
|
|
181238
181871
|
case "classification_not_kept":
|
|
181239
181872
|
return "This source's re-root changed what it exposes or how a field is classified, which the load's " + "classification checks flag on the served copy, so its queries are not answered from the " + "stored tables (a Publisher bug; please report it): " + [...problem.leaks ?? [], ...problem.coverage ?? []].join(" ");
|
|
181873
|
+
case "sql_embed_cross_connection":
|
|
181874
|
+
return "This source is read through a `.sql()` source's `%{}`" + (problem.detail ? ` (${problem.detail})` : "") + ", whose SQL runs on its own connection, while its table is read on another (a storage " + "destination, or a managed catalog read through one), which a `%{}` cannot reach. The served copy " + "leaves this source as written, so its queries are answered live, and the model's other stored " + "sources still serve. " + SQL_EMBED_FIX.sql_embed_cross_connection;
|
|
181875
|
+
case "sql_embed_bare":
|
|
181876
|
+
return "This source is embedded whole by a `.sql()` source's `%{}`" + (problem.detail ? ` (${problem.detail})` : "") + ", which Malloy allows only of a source it can compile to SQL, and its stored table is not " + "one. The served copy leaves this source as written, so its queries are answered live, and " + "the model's other stored sources still serve. " + SQL_EMBED_FIX.sql_embed_bare;
|
|
181240
181877
|
}
|
|
181241
181878
|
}
|
|
181242
181879
|
function databaseTableUnreadWarnings(unread, plan, retryPending, storageRetryPending = false) {
|
|
@@ -181269,6 +181906,7 @@ function databaseTableUnreadWarnings(unread, plan, retryPending, storageRetryPen
|
|
|
181269
181906
|
var MISMATCH_HANDLING_TEXT, ROLLUP_JOIN_ONE_KEY_REPEATED_CODE = "rollup-join-one-key-repeated", CHECK_DOES, TABLE_KEPT_CODE = "table-kept", KEPT_REASON_TEXT, PERSIST_READS_CURRENT_TIME_CODE = "persist-reads-current-time", DATABASE_TABLE_UNREAD_CODE = "database-table-unread", STORAGE_TABLE_UNREAD_CODE = "storage-table-unread", UNREAD_REASON_TEXT;
|
|
181270
181907
|
var init_package_warnings = __esm(() => {
|
|
181271
181908
|
init_annotation_reader();
|
|
181909
|
+
init_source_decline();
|
|
181272
181910
|
init_constants();
|
|
181273
181911
|
init_classification();
|
|
181274
181912
|
init_load_gate_text();
|
|
@@ -181317,6 +181955,7 @@ class PlanLifecycle {
|
|
|
181317
181955
|
connectionsChangedSinceDerived = new Set;
|
|
181318
181956
|
refreshFailedTransiently = false;
|
|
181319
181957
|
heldWithdrawn = new Set;
|
|
181958
|
+
heldWithdrawnUnread = new Set;
|
|
181320
181959
|
stale;
|
|
181321
181960
|
staleSeq = 0;
|
|
181322
181961
|
refreshChain = Promise.resolve(true);
|
|
@@ -181393,18 +182032,24 @@ class PlanLifecycle {
|
|
|
181393
182032
|
set databaseSourceEligibility(databaseSourceEligibility) {
|
|
181394
182033
|
this.patch({ databaseSourceEligibility });
|
|
181395
182034
|
}
|
|
181396
|
-
withdraw(sourceIDs) {
|
|
182035
|
+
withdraw(sourceIDs, unread = []) {
|
|
181397
182036
|
const record = this.state.serving;
|
|
181398
|
-
if (!record
|
|
182037
|
+
if (!record)
|
|
181399
182038
|
return;
|
|
181400
|
-
|
|
181401
|
-
|
|
181402
|
-
|
|
181403
|
-
|
|
181404
|
-
|
|
181405
|
-
|
|
182039
|
+
if (sourceIDs.length === 0 && unread.length === 0 && record.withdrawnUnread.size === 0) {
|
|
182040
|
+
return;
|
|
182041
|
+
}
|
|
182042
|
+
const addresses = (ids) => ids.flatMap((id) => {
|
|
182043
|
+
const address = record.plan?.sources[id]?.sourceEntityId;
|
|
182044
|
+
return address ? [address] : [];
|
|
182045
|
+
});
|
|
182046
|
+
const changed = new Set([
|
|
182047
|
+
...[...record.withdrawn].filter((a) => !record.withdrawnUnread.has(a)),
|
|
182048
|
+
...addresses(sourceIDs)
|
|
181406
182049
|
]);
|
|
181407
|
-
const
|
|
182050
|
+
const withdrawnUnread = new Set(addresses(unread).filter((a) => !changed.has(a)));
|
|
182051
|
+
const withdrawn = new Set([...changed, ...withdrawnUnread]);
|
|
182052
|
+
const serving = { ...record, withdrawn, withdrawnUnread };
|
|
181408
182053
|
this.state = {
|
|
181409
182054
|
...this.state,
|
|
181410
182055
|
serving,
|
|
@@ -181415,8 +182060,15 @@ class PlanLifecycle {
|
|
|
181415
182060
|
get withdrawn() {
|
|
181416
182061
|
return this.serving().withdrawn;
|
|
181417
182062
|
}
|
|
182063
|
+
get withdrawnUnread() {
|
|
182064
|
+
return this.serving().withdrawnUnread;
|
|
182065
|
+
}
|
|
182066
|
+
get holdingWithdrawn() {
|
|
182067
|
+
return this.heldWithdrawn.size > 0;
|
|
182068
|
+
}
|
|
181418
182069
|
holdWithdrawn(hold) {
|
|
181419
182070
|
this.heldWithdrawn = hold ? new Set(this.withdrawn) : new Set;
|
|
182071
|
+
this.heldWithdrawnUnread = hold ? new Set(this.withdrawnUnread) : new Set;
|
|
181420
182072
|
}
|
|
181421
182073
|
servingPlan() {
|
|
181422
182074
|
return this.state.serving?.plan ?? null;
|
|
@@ -181468,6 +182120,7 @@ class PlanLifecycle {
|
|
|
181468
182120
|
asOfBuild: outcome.asOfBuild ?? {},
|
|
181469
182121
|
upstreamSchemas: outcome.upstreamSchemas ?? {},
|
|
181470
182122
|
withdrawn: new Set(this.heldWithdrawn),
|
|
182123
|
+
withdrawnUnread: new Set(this.heldWithdrawnUnread),
|
|
181471
182124
|
stringCapabilityReads: outcome.stringCapabilityReads ?? {}
|
|
181472
182125
|
};
|
|
181473
182126
|
}
|
|
@@ -181648,6 +182301,7 @@ var init_plan_lifecycle = __esm(() => {
|
|
|
181648
182301
|
asOfBuild: {},
|
|
181649
182302
|
upstreamSchemas: {},
|
|
181650
182303
|
withdrawn: new Set,
|
|
182304
|
+
withdrawnUnread: new Set,
|
|
181651
182305
|
stringCapabilityReads: {}
|
|
181652
182306
|
};
|
|
181653
182307
|
});
|
|
@@ -181965,15 +182619,34 @@ function storageTableDecisions(input, tally, tables, decided, storageDecision, f
|
|
|
181965
182619
|
}
|
|
181966
182620
|
}
|
|
181967
182621
|
const tablesRead = input.storageTablesRead ?? [];
|
|
181968
|
-
const
|
|
182622
|
+
const own = input.chain.map((id) => tablesRead.find((b) => b.sourceIDs?.includes(id))).find((b) => b !== undefined);
|
|
182623
|
+
const embedded = tablesRead.filter((b) => b.sourceIDs?.some((id) => input.sqlEmbedReach?.has(id)));
|
|
182624
|
+
const answering = own ? [own] : embedded.length > 0 ? embedded : tablesRead.slice(0, 1);
|
|
181969
182625
|
const placed = storageAnswered || considered.some((c) => c.outcome === "used" || c.reason === "READ_FAILED");
|
|
181970
|
-
if (storageDecision.outcome === "used" &&
|
|
181971
|
-
const
|
|
181972
|
-
|
|
181973
|
-
|
|
181974
|
-
|
|
181975
|
-
|
|
181976
|
-
|
|
182626
|
+
if (storageDecision.outcome === "used" && !placed) {
|
|
182627
|
+
const named = new Set;
|
|
182628
|
+
for (const b of answering) {
|
|
182629
|
+
const t = stateOfBinding(input, b, freshStorage);
|
|
182630
|
+
if (t.tableId !== undefined) {
|
|
182631
|
+
if (named.has(t.tableId))
|
|
182632
|
+
continue;
|
|
182633
|
+
named.add(t.tableId);
|
|
182634
|
+
}
|
|
182635
|
+
if (input.runFailed) {
|
|
182636
|
+
skip(t, "READ_FAILED");
|
|
182637
|
+
} else if (storageAnswered) {
|
|
182638
|
+
if (t.tableId) {
|
|
182639
|
+
considered.push({
|
|
182640
|
+
tableId: t.tableId,
|
|
182641
|
+
kind: t.kind,
|
|
182642
|
+
...originField(t),
|
|
182643
|
+
outcome: "used"
|
|
182644
|
+
});
|
|
182645
|
+
}
|
|
182646
|
+
} else {
|
|
182647
|
+
markUsed(t);
|
|
182648
|
+
storageAnswered = true;
|
|
182649
|
+
}
|
|
181977
182650
|
}
|
|
181978
182651
|
}
|
|
181979
182652
|
} else {
|
|
@@ -182136,6 +182809,8 @@ function verdictWarningMessage(reason) {
|
|
|
182136
182809
|
return "This table's connection cannot hold a table, so its queries are answered live.";
|
|
182137
182810
|
case "incompatible":
|
|
182138
182811
|
return "This table no longer matches the column contract its build recorded, so its queries are answered live until a build rebuilds it.";
|
|
182812
|
+
case "upstream_unread":
|
|
182813
|
+
return "A warehouse table this table was built from could not be read, so whether it changed is not known; its queries are answered live until a read of it succeeds.";
|
|
182139
182814
|
case "contract_missing":
|
|
182140
182815
|
return "This table carries no column contract, so its queries are answered live until a build rebuilds it in full.";
|
|
182141
182816
|
case "types_unrecorded":
|
|
@@ -182405,88 +183080,14 @@ var MAX_NOT_CONSIDERED = 10, CONTRACT_VERDICTS, FIELD_PATH_SKIPPED_KEYS3;
|
|
|
182405
183080
|
var init_query_path = __esm(() => {
|
|
182406
183081
|
init_array_query();
|
|
182407
183082
|
init_leg_decline();
|
|
182408
|
-
CONTRACT_VERDICTS = new Set([
|
|
183083
|
+
CONTRACT_VERDICTS = new Set([
|
|
183084
|
+
"incompatible",
|
|
183085
|
+
"contract_missing",
|
|
183086
|
+
"upstream_unread"
|
|
183087
|
+
]);
|
|
182409
183088
|
FIELD_PATH_SKIPPED_KEYS3 = new Set(["overload", "at"]);
|
|
182410
183089
|
});
|
|
182411
183090
|
|
|
182412
|
-
// src/service/materialization/domain/source_decline.ts
|
|
182413
|
-
function byActionability(reasons) {
|
|
182414
|
-
const rank = (r) => {
|
|
182415
|
-
const at = ACTIONABLE_ORDER.indexOf(r);
|
|
182416
|
-
return at < 0 ? ACTIONABLE_ORDER.length : at;
|
|
182417
|
-
};
|
|
182418
|
-
return [...new Set(reasons)].map((r, i) => ({ r, i })).sort((a, b) => rank(a.r) - rank(b.r) || a.i - b.i).map((x) => x.r);
|
|
182419
|
-
}
|
|
182420
|
-
function servesInPart(reason) {
|
|
182421
|
-
const row = SOURCE_DECLINES[reason];
|
|
182422
|
-
return row.servesInPart === true;
|
|
182423
|
-
}
|
|
182424
|
-
function servedCopyOutcomes(problems, rerootedSourceIDs) {
|
|
182425
|
-
const bySource = new Map;
|
|
182426
|
-
const out = [];
|
|
182427
|
-
for (const p of problems) {
|
|
182428
|
-
const key = p.sourceID !== undefined ? `id:${p.sourceID}` : p.sourceName !== undefined ? `name:${p.sourceName}` : undefined;
|
|
182429
|
-
if (key === undefined) {
|
|
182430
|
-
out.push({ outcome: "declined", reason: p.reason });
|
|
182431
|
-
continue;
|
|
182432
|
-
}
|
|
182433
|
-
const reasons = bySource.get(key) ?? [];
|
|
182434
|
-
reasons.push(p.reason);
|
|
182435
|
-
bySource.set(key, reasons);
|
|
182436
|
-
}
|
|
182437
|
-
for (const [key, reasons] of bySource) {
|
|
182438
|
-
const leavesOut = reasons.find((r) => !servesInPart(r));
|
|
182439
|
-
if (leavesOut !== undefined) {
|
|
182440
|
-
out.push({ outcome: "declined", reason: leavesOut });
|
|
182441
|
-
continue;
|
|
182442
|
-
}
|
|
182443
|
-
const stillServed = key.startsWith("id:") && rerootedSourceIDs.has(key.slice(3));
|
|
182444
|
-
out.push({
|
|
182445
|
-
outcome: stillServed ? "partial" : "declined",
|
|
182446
|
-
reason: reasons[0]
|
|
182447
|
-
});
|
|
182448
|
-
}
|
|
182449
|
-
return out;
|
|
182450
|
-
}
|
|
182451
|
-
var SOURCE_DECLINES, ACTIONABLE_ORDER, SOURCE_DECLINE_REASONS;
|
|
182452
|
-
var init_source_decline = __esm(() => {
|
|
182453
|
-
SOURCE_DECLINES = {
|
|
182454
|
-
build_plan_unavailable: { stage: "bind" },
|
|
182455
|
-
refused: { stage: "bind" },
|
|
182456
|
-
missing_table: { stage: "bind" },
|
|
182457
|
-
unquotable_name: { stage: "bind" },
|
|
182458
|
-
compile_failed: { stage: "served_copy" },
|
|
182459
|
-
cross_connection_unbuilt: { stage: "served_copy" },
|
|
182460
|
-
column_types: { stage: "served_copy" },
|
|
182461
|
-
no_declaration: { stage: "served_copy" },
|
|
182462
|
-
definition_not_parsed: { stage: "served_copy" },
|
|
182463
|
-
pair_join_not_found: { stage: "served_copy" },
|
|
182464
|
-
pair_not_compiled: { stage: "served_copy" },
|
|
182465
|
-
fields_not_carried: { stage: "served_copy" },
|
|
182466
|
-
read_terms_not_kept: { stage: "served_copy" },
|
|
182467
|
-
cross_connection_join: { stage: "served_copy", servesInPart: true },
|
|
182468
|
-
inline_join_kept: { stage: "served_copy", servesInPart: true },
|
|
182469
|
-
reroot_not_compiled: { stage: "served_copy" },
|
|
182470
|
-
classification_not_kept: { stage: "served_copy" }
|
|
182471
|
-
};
|
|
182472
|
-
ACTIONABLE_ORDER = [
|
|
182473
|
-
"cross_connection_join",
|
|
182474
|
-
"cross_connection_unbuilt",
|
|
182475
|
-
"inline_join_kept",
|
|
182476
|
-
"read_terms_not_kept",
|
|
182477
|
-
"fields_not_carried",
|
|
182478
|
-
"column_types",
|
|
182479
|
-
"classification_not_kept",
|
|
182480
|
-
"pair_join_not_found",
|
|
182481
|
-
"pair_not_compiled",
|
|
182482
|
-
"definition_not_parsed",
|
|
182483
|
-
"compile_failed",
|
|
182484
|
-
"no_declaration",
|
|
182485
|
-
"reroot_not_compiled"
|
|
182486
|
-
];
|
|
182487
|
-
SOURCE_DECLINE_REASONS = Object.keys(SOURCE_DECLINES);
|
|
182488
|
-
});
|
|
182489
|
-
|
|
182490
183091
|
// src/service/materialization/serve_verdicts.ts
|
|
182491
183092
|
import { isSourceDef as isSourceDef13 } from "@malloydata/malloy";
|
|
182492
183093
|
function declaresMaterialize2(def) {
|
|
@@ -185001,15 +185602,18 @@ class PackageMaterialization {
|
|
|
185001
185602
|
...t.builtAt ? { builtAt: t.builtAt } : {}
|
|
185002
185603
|
});
|
|
185003
185604
|
}
|
|
185605
|
+
const unread = this.plan.withdrawnUnread;
|
|
185004
185606
|
for (const id of this.plan.withdrawn) {
|
|
185005
185607
|
const t = tableOf(id);
|
|
185006
185608
|
if (!t.physicalTableName)
|
|
185007
185609
|
continue;
|
|
185008
185610
|
verdicts.set(id, {
|
|
185009
|
-
reason: "incompatible",
|
|
185010
185611
|
physicalTableName: t.physicalTableName,
|
|
185011
185612
|
...t.builtAt ? { builtAt: t.builtAt } : {},
|
|
185012
|
-
|
|
185613
|
+
...unread.has(id) ? { reason: "upstream_unread" } : {
|
|
185614
|
+
reason: "incompatible",
|
|
185615
|
+
incompatibility: { code: "upstream_altered", columns: [] }
|
|
185616
|
+
}
|
|
185013
185617
|
});
|
|
185014
185618
|
}
|
|
185015
185619
|
for (const i of this.observedOutcome.incompatible) {
|
|
@@ -188380,7 +188984,7 @@ async function readTargetContainer(connection, container, runOptions) {
|
|
|
188380
188984
|
if (parts.length > 2)
|
|
188381
188985
|
return { unread: true };
|
|
188382
188986
|
const [database, schema] = parts.length === 2 ? parts : [undefined, parts[0]];
|
|
188383
|
-
const row = await countRow(connection, `SELECT row_to_json(p) AS "row" FROM (SELECT current_database() AS db, (SELECT COUNT(*) FROM pg_catalog.pg_namespace WHERE nspname = ${
|
|
188987
|
+
const row = await countRow(connection, `SELECT row_to_json(p) AS "row" FROM (SELECT current_database() AS db, (SELECT COUNT(*) FROM pg_catalog.pg_namespace WHERE nspname = ${literal2(schema)}) AS n) AS p`, runOptions);
|
|
188384
188988
|
if (row === undefined || database !== undefined && String(row.db) !== database) {
|
|
188385
188989
|
return { unread: true };
|
|
188386
188990
|
}
|
|
@@ -188391,12 +188995,12 @@ async function readTargetContainer(connection, container, runOptions) {
|
|
|
188391
188995
|
return { unread: true };
|
|
188392
188996
|
const [database, schema] = parts.length === 2 ? parts : [undefined, parts[0]];
|
|
188393
188997
|
const catalog = database === undefined ? "information_schema" : `"${database.replace(/"/g, '""')}".information_schema`;
|
|
188394
|
-
return answer(await countRow(connection, `SELECT COUNT(*) AS n FROM ${catalog}.schemata WHERE schema_name = ${
|
|
188998
|
+
return answer(await countRow(connection, `SELECT COUNT(*) AS n FROM ${catalog}.schemata WHERE schema_name = ${literal2(schema)}`, runOptions));
|
|
188395
188999
|
}
|
|
188396
189000
|
case "duckdb_schemas": {
|
|
188397
189001
|
if (parts.length > 2)
|
|
188398
189002
|
return { unread: true };
|
|
188399
|
-
const where = parts.length === 2 ? `lower(database_name) = lower(${
|
|
189003
|
+
const where = parts.length === 2 ? `lower(database_name) = lower(${literal2(parts[0])}) AND lower(schema_name) = lower(${literal2(parts[1])})` : `(database_name = current_database() AND lower(schema_name) = lower(${literal2(parts[0])})) OR lower(database_name) = lower(${literal2(parts[0])})`;
|
|
188400
189004
|
const sql = `SELECT COUNT(*) AS n FROM duckdb_schemas() WHERE ${where}`;
|
|
188401
189005
|
return answer(await runAsInternalStatement(sql, () => countRow(connection, sql, runOptions)));
|
|
188402
189006
|
}
|
|
@@ -188466,7 +189070,7 @@ function answer(row) {
|
|
|
188466
189070
|
return { unread: true };
|
|
188467
189071
|
return n > 0 ? { found: true } : { notFound: true };
|
|
188468
189072
|
}
|
|
188469
|
-
function
|
|
189073
|
+
function literal2(value) {
|
|
188470
189074
|
return `'${value.replace(/'/g, "''")}'`;
|
|
188471
189075
|
}
|
|
188472
189076
|
function unquoted2(segment) {
|
|
@@ -188997,6 +189601,9 @@ async function buildFromWarehouse(ctx, refresh) {
|
|
|
188997
189601
|
sourceConnection,
|
|
188998
189602
|
buildSQL: params.storedBuildSQL,
|
|
188999
189603
|
sourceCarriesAuthorSql: carriesAuthorSql(sourceDefOf(persistSource)),
|
|
189604
|
+
...environment.managedStorageScope ? {
|
|
189605
|
+
managedScope: async () => sourceConnection.name ? environment.managedStorageScope(sourceConnection.name) : undefined
|
|
189606
|
+
} : {},
|
|
189000
189607
|
physicalTableName,
|
|
189001
189608
|
declaredColumns,
|
|
189002
189609
|
castOptions,
|
|
@@ -193789,6 +194396,24 @@ async function checkRollupKeys(compiled, persistSource, entry, connection, conne
|
|
|
193789
194396
|
};
|
|
193790
194397
|
}
|
|
193791
194398
|
}
|
|
194399
|
+
for (const check of groupsBaseRows ? rollupGrainJoinKeyChecksOf(compiled, sourceID) : []) {
|
|
194400
|
+
if (check.connectionName !== connectionName)
|
|
194401
|
+
continue;
|
|
194402
|
+
const record = await checkKeyAndWarn("grain_join", () => DATABASE3.checkKey({ connection }, check), {
|
|
194403
|
+
notRun: "A #(rollup) rollup's grain join key check did not run; queries that read nothing through the join are answered live",
|
|
194404
|
+
notUnique: "A source joined by a #(rollup) rollup's grain holds the join's key more than once; queries that read nothing through the join are answered live"
|
|
194405
|
+
}, {
|
|
194406
|
+
rollup: persistSource.name,
|
|
194407
|
+
join: check.join,
|
|
194408
|
+
keyColumn: check.keyColumn
|
|
194409
|
+
});
|
|
194410
|
+
if (record) {
|
|
194411
|
+
keys[contractKeyName("grain_join", check.join, check.keyColumn)] = {
|
|
194412
|
+
unique: record.unique,
|
|
194413
|
+
level: "grain_join"
|
|
194414
|
+
};
|
|
194415
|
+
}
|
|
194416
|
+
}
|
|
193792
194417
|
const parents = await checkParentKeys(rollupParentKeyChecksOf(compiled, sourceID).filter((check) => groupsBaseRows || check.sourceID !== baseSourceID), connection, connectionName, persistSource.name);
|
|
193793
194418
|
for (const { check, record } of parents) {
|
|
193794
194419
|
const subject = relative?.(check.sourceID);
|
|
@@ -193804,6 +194429,9 @@ async function checkRollupKeys(compiled, persistSource, entry, connection, conne
|
|
|
193804
194429
|
function rollupKeyCheckOf(compiled, sourceID) {
|
|
193805
194430
|
return compiled.tables[sourceID]?.rollup?.keyCheck;
|
|
193806
194431
|
}
|
|
194432
|
+
function rollupGrainJoinKeyChecksOf(compiled, sourceID) {
|
|
194433
|
+
return compiled.tables[sourceID]?.rollup?.grainJoinKeyChecks ?? [];
|
|
194434
|
+
}
|
|
193807
194435
|
function rollupParentKeyChecksOf(compiled, sourceID) {
|
|
193808
194436
|
return compiled.tables[sourceID]?.rollup?.parentKeyChecks ?? [];
|
|
193809
194437
|
}
|
|
@@ -196228,6 +196856,7 @@ function readingsOf(connection) {
|
|
|
196228
196856
|
return readings;
|
|
196229
196857
|
}
|
|
196230
196858
|
async function readUpstreamSchemas(args) {
|
|
196859
|
+
const keepLast = args.keepLastOnFailure ?? true;
|
|
196231
196860
|
const out = {};
|
|
196232
196861
|
const connections = new Map;
|
|
196233
196862
|
const digests = new Map;
|
|
@@ -196287,8 +196916,8 @@ async function readUpstreamSchemas(args) {
|
|
|
196287
196916
|
};
|
|
196288
196917
|
readings.set(t.cached, reading);
|
|
196289
196918
|
} else if (reading.unread === "read_failed") {
|
|
196290
|
-
const last = readings.get(t.cached);
|
|
196291
|
-
logger.warn(last ? "Upstream table's columns could not be read; keeping its last reading" : "Upstream table's columns could not be read; the sources that read it are refused until a read succeeds", { connectionName: t.table.connectionName, reason });
|
|
196919
|
+
const last = keepLast ? readings.get(t.cached) : undefined;
|
|
196920
|
+
logger.warn(last ? "Upstream table's columns could not be read; keeping its last reading" : keepLast ? "Upstream table's columns could not be read; the sources that read it are refused until a read succeeds" : "Upstream table's columns could not be read; it reads as unread", { connectionName: t.table.connectionName, reason });
|
|
196292
196921
|
if (last)
|
|
196293
196922
|
reading = last;
|
|
196294
196923
|
}
|
|
@@ -370901,7 +371530,7 @@ function toApiSources(result) {
|
|
|
370901
371530
|
var init_to_api = () => {};
|
|
370902
371531
|
|
|
370903
371532
|
// src/package_load/protocol.ts
|
|
370904
|
-
var PACKAGE_LOAD_PROTOCOL_VERSION =
|
|
371533
|
+
var PACKAGE_LOAD_PROTOCOL_VERSION = 10;
|
|
370905
371534
|
|
|
370906
371535
|
// src/package_load/protocol_decode.ts
|
|
370907
371536
|
function isRecord2(value) {
|
|
@@ -371389,7 +372018,10 @@ class PackageLoadPool {
|
|
|
371389
372018
|
environmentName: qj.request.environmentName,
|
|
371390
372019
|
modelPath: qj.request.modelPath,
|
|
371391
372020
|
defaultConnectionName: qj.request.defaultConnectionName,
|
|
371392
|
-
files: [...qj.request.files]
|
|
372021
|
+
files: [...qj.request.files],
|
|
372022
|
+
...qj.request.virtualMap ? {
|
|
372023
|
+
virtualMap: [...qj.request.virtualMap].map(([connection, handles]) => [connection, [...handles]])
|
|
372024
|
+
} : {}
|
|
371393
372025
|
};
|
|
371394
372026
|
pw.worker.postMessage(message);
|
|
371395
372027
|
return;
|
|
@@ -375962,6 +376594,7 @@ async function queryPathFor(host, answer, args) {
|
|
|
375962
376594
|
storageWarned: !storageServes(getPersistStorageMode()),
|
|
375963
376595
|
considered: answer.considered,
|
|
375964
376596
|
storageTablesRead: routed?.tablesRead?.map(toTable),
|
|
376597
|
+
sqlEmbedReach: host.servedCopy.ownSqlEmbedReach(struct, modelDef),
|
|
375965
376598
|
...answer.leg === "rollup" ? {
|
|
375966
376599
|
rollupTablesRead: answer.answer.shapeBindings.filter((b) => b.kind !== "rollup").map(toTable)
|
|
375967
376600
|
} : {},
|
|
@@ -377475,7 +378108,8 @@ async function compileServedCopyOnWorker(pool, args) {
|
|
|
377475
378108
|
modelPath: args.modelPath,
|
|
377476
378109
|
malloyConfig: args.config,
|
|
377477
378110
|
defaultConnectionName: DEFAULT_CONNECTION,
|
|
377478
|
-
files: args.files
|
|
378111
|
+
files: args.files,
|
|
378112
|
+
...args.virtualMap ? { virtualMap: args.virtualMap } : {}
|
|
377479
378113
|
});
|
|
377480
378114
|
if (!pending)
|
|
377481
378115
|
return;
|
|
@@ -380421,7 +381055,7 @@ class RollupVariantServe {
|
|
|
380421
381055
|
groupedBy: readThroughJoin(name, q.shape.groupedBy),
|
|
380422
381056
|
filteredBy: readThroughJoin(name, q.shape.filteredBy),
|
|
380423
381057
|
measures: readThroughJoin(name, q.shape.measures)
|
|
380424
|
-
});
|
|
381058
|
+
}, (join) => this.grainJoinKeyUniqueness(plan, join, q.args.pinned));
|
|
380425
381059
|
if (coarse)
|
|
380426
381060
|
throw coarse;
|
|
380427
381061
|
const missing = joinCoverageDecline(name, q.shape, grain, measures);
|
|
@@ -380675,7 +381309,7 @@ class RollupVariantServe {
|
|
|
380675
381309
|
const measures = new Set(plan.rollupMeasures.map((m) => m.name));
|
|
380676
381310
|
const dimensions = query.extension ? extensionDimensions(query.extension, plan, measures) : [];
|
|
380677
381311
|
const grain = queryGrainOf(plan, dimensions);
|
|
380678
|
-
const shapeSkip = baseShapeDecline(plan, shape, grain, measures);
|
|
381312
|
+
const shapeSkip = baseShapeDecline(plan, shape, grain, measures, (join) => this.grainJoinKeyUniqueness(plan, join, args.pinned));
|
|
380679
381313
|
if (shapeSkip)
|
|
380680
381314
|
throw shapeSkip;
|
|
380681
381315
|
if (query.zoned) {
|
|
@@ -380768,6 +381402,15 @@ class RollupVariantServe {
|
|
|
380768
381402
|
const id = table?.sourceEntityId;
|
|
380769
381403
|
return verdictOf(table?.binding ? table.binding.rollupKey?.unique : id === undefined ? undefined : pinned.snapshot.entries[id]?.keyUniqueness?.unique);
|
|
380770
381404
|
}
|
|
381405
|
+
grainJoinKeyUniqueness(plan, join, pinned) {
|
|
381406
|
+
const keyColumn = SourceMap.of(this.host.modelDef()).joinsOf(plan.baseSourceID).find((j) => j.name === join)?.keyColumn;
|
|
381407
|
+
const table = this.tableOf(plan, pinned);
|
|
381408
|
+
const id = table?.sourceEntityId;
|
|
381409
|
+
if (keyColumn === undefined || table === undefined)
|
|
381410
|
+
return "unknown";
|
|
381411
|
+
const checks = table.binding ? table.binding.grainJoinKeys : id === undefined ? undefined : pinned.snapshot.entries[id]?.keyUniqueness?.grainJoinKeys;
|
|
381412
|
+
return verdictOf(checks?.[`${join}.${keyColumn}`]);
|
|
381413
|
+
}
|
|
380771
381414
|
parentKeyUniqueness(plan, struct, pinned) {
|
|
380772
381415
|
const sourceID = struct?.sourceID;
|
|
380773
381416
|
const id = this.tableOf(plan, pinned)?.sourceEntityId;
|
|
@@ -381912,16 +382555,26 @@ function grainDecline(shape, grain, measures) {
|
|
|
381912
382555
|
}
|
|
381913
382556
|
return;
|
|
381914
382557
|
}
|
|
381915
|
-
function baseShapeDecline(plan, shape, grain, measures) {
|
|
381916
|
-
return grainDecline(shape, grain, measures) ?? coverageDecline(shape, measures) ?? joinOneDecline(plan, shape);
|
|
382558
|
+
function baseShapeDecline(plan, shape, grain, measures, keyVerdict) {
|
|
382559
|
+
return grainDecline(shape, grain, measures) ?? coverageDecline(shape, measures) ?? joinOneDecline(plan, shape, keyVerdict);
|
|
381917
382560
|
}
|
|
381918
|
-
function joinOneDecline(plan, shape) {
|
|
382561
|
+
function joinOneDecline(plan, shape, keyVerdict) {
|
|
381919
382562
|
const reads = [...shape.groupedBy, ...shape.filteredBy, ...shape.measures];
|
|
381920
382563
|
const measureReads = (name, join) => plan.rollupMeasures.some((m) => m.name === name && m.partials.some((p) => p.leaf.joinPath[0] === join || p.leaf.reads.some((r) => r[0] === join)));
|
|
381921
|
-
|
|
382564
|
+
let verdict = "unique";
|
|
382565
|
+
let past = false;
|
|
382566
|
+
const unread = (plan.joinOneGrain ?? []).find(({ join, grain, uncovered }) => {
|
|
382567
|
+
if (reads.some((p) => p.startsWith(`${join}.`) || grain.includes(p) || measureReads(p, join))) {
|
|
382568
|
+
return false;
|
|
382569
|
+
}
|
|
382570
|
+
past = uncovered === true;
|
|
382571
|
+
verdict = past ? "unknown" : keyVerdict(join);
|
|
382572
|
+
return !requireUnique(verdict);
|
|
382573
|
+
});
|
|
381922
382574
|
if (unread === undefined)
|
|
381923
382575
|
return;
|
|
381924
|
-
|
|
382576
|
+
const why = past ? "the build joined past it, through another join no key check covers, so a repeat there would have inflated the partials it summed" : verdict === "repeated" ? "the rollup's last build found its key held more than once in the joined source, so the partials it summed are inflated" : "its key was not checked unique when the rollup was built, so a repeat would have inflated the partials it summed";
|
|
382577
|
+
return new LegDecline("rollup_count_semantics", `the query reads nothing through \`${unread.join}\`, a join_one the rollup's grain reads (${unread.grain.map((g) => `\`${g}\``).join(", ")}): ${why}, where live, not joining it, counts each row once`, { shapeCheck: true });
|
|
381925
382578
|
}
|
|
381926
382579
|
function coverageDecline(shape, measures) {
|
|
381927
382580
|
const missing = shape.measures.find((m) => !measures.has(m));
|
|
@@ -382119,7 +382772,7 @@ function compileErrorLine(message) {
|
|
|
382119
382772
|
function malloynbRunQuery(cell) {
|
|
382120
382773
|
return cell?.type === "code" ? lastRunStatementText(cell.text) : undefined;
|
|
382121
382774
|
}
|
|
382122
|
-
var MALLOY_VERSION, NO_PREAGGREGATE_VIOLATIONS, Model;
|
|
382775
|
+
var MALLOY_VERSION, RENDER_TAG_CODE = "render-tag", RENDER_TAG_CHECK_FAILED_CODE = "render-tag-check-failed", NO_PREAGGREGATE_VIOLATIONS, Model;
|
|
382123
382776
|
var init_model = __esm(() => {
|
|
382124
382777
|
init_telemetry();
|
|
382125
382778
|
init_materialization_metrics();
|
|
@@ -382177,6 +382830,7 @@ var init_model = __esm(() => {
|
|
|
382177
382830
|
init_model_query_request();
|
|
382178
382831
|
init_annotation_near_miss();
|
|
382179
382832
|
init_managed_catalog_scope();
|
|
382833
|
+
init_same_catalog_tables();
|
|
382180
382834
|
init_column_contract();
|
|
382181
382835
|
init_model_query_request();
|
|
382182
382836
|
init_model_policy();
|
|
@@ -383391,6 +384045,7 @@ var init_model = __esm(() => {
|
|
|
383391
384045
|
newServedCopy() {
|
|
383392
384046
|
return new ServedCopyServe({
|
|
383393
384047
|
managedTablePathRefusal,
|
|
384048
|
+
sameCatalogTablesReadable,
|
|
383394
384049
|
authorResultShape: async (queryString, givens) => {
|
|
383395
384050
|
const materializer = this.modelMaterializer;
|
|
383396
384051
|
if (!materializer)
|
|
@@ -383404,6 +384059,7 @@ var init_model = __esm(() => {
|
|
|
383404
384059
|
ensureSharedQueryModel: (materializer) => this.ensureSharedQueryModel(materializer),
|
|
383405
384060
|
modelPath: () => this.modelPath,
|
|
383406
384061
|
modelDef: () => this.modelDef,
|
|
384062
|
+
siblingModelDef: (url) => this.siblingModelDefResolver?.(url),
|
|
383407
384063
|
serveDestinationConfig: () => this.servingDestinationConfig(),
|
|
383408
384064
|
pinned: () => this.pinNow(),
|
|
383409
384065
|
compileElsewhere: (args) => compileServedCopyOnWorker(currentPackageLoadPool(), args)
|
|
@@ -383656,6 +384312,7 @@ var init_model = __esm(() => {
|
|
|
383656
384312
|
const pinned = pin(makeSnapshot(bindings), new Date(0));
|
|
383657
384313
|
const copy = new ServedCopyServe({
|
|
383658
384314
|
managedTablePathRefusal,
|
|
384315
|
+
sameCatalogTablesReadable,
|
|
383659
384316
|
modelPath: () => this.modelPath,
|
|
383660
384317
|
modelDef: () => this.modelDef,
|
|
383661
384318
|
serveDestinationConfig: () => destinations && storageServes(getPersistStorageMode()) ? () => compileOnlyDestinationConfig(destinations()) : undefined,
|
|
@@ -383682,6 +384339,7 @@ var init_model = __esm(() => {
|
|
|
383682
384339
|
const pinned = pin(makeSnapshot(stored), new Date(0));
|
|
383683
384340
|
const copy = new ServedCopyServe({
|
|
383684
384341
|
managedTablePathRefusal,
|
|
384342
|
+
sameCatalogTablesReadable,
|
|
383685
384343
|
modelPath: () => this.modelPath,
|
|
383686
384344
|
modelDef: () => this.modelDef,
|
|
383687
384345
|
quiet: true,
|
|
@@ -384194,14 +384852,25 @@ import {
|
|
|
384194
384852
|
MalloyError as MalloyError16,
|
|
384195
384853
|
Model as MalloyModel
|
|
384196
384854
|
} from "@malloydata/malloy";
|
|
384855
|
+
function upstreamWithdrawalSentences(withdrawn, among) {
|
|
384856
|
+
const pick = (sources) => among ? sources.filter((s) => among.includes(s)) : sources;
|
|
384857
|
+
const changed = pick(withdrawn.sources);
|
|
384858
|
+
const unread = pick(withdrawn.unread.sources);
|
|
384859
|
+
const out = [];
|
|
384860
|
+
if (changed.length > 0) {
|
|
384861
|
+
out.push(`Upstream table ${withdrawn.tables.join(", ")} changed since the ` + `last build, so ${changed.join(", ")} answer live until a reload ` + `compiles and a run rebuilds them.`);
|
|
384862
|
+
}
|
|
384863
|
+
if (unread.length > 0) {
|
|
384864
|
+
const tables = withdrawn.unread.tables;
|
|
384865
|
+
out.push((tables && tables.length > 0 ? `Upstream table ${tables.join(", ")} could not be read` : `The upstream tables of ${unread.join(", ")} could not be read`) + `, so whether it changed since the last build is not known: ` + `${unread.join(", ")} answer live until a read of it succeeds ` + `and finds it unchanged (the package's next manifest bind or ` + `rebind reads it again) or a reload plans it afresh.`);
|
|
384866
|
+
}
|
|
384867
|
+
return out;
|
|
384868
|
+
}
|
|
384197
384869
|
function recompileFailedWarning(kept, withdrawn) {
|
|
384198
|
-
const live = withdrawn.sources.filter((s) => kept.sources.includes(s));
|
|
384199
384870
|
const parts = [
|
|
384200
|
-
`${kept.modelPath} did not recompile, so its sources ` + `(${kept.sources.join(", ") || "none"}) are served from the model ` + `it last compiled: ${kept.error}
|
|
384871
|
+
`${kept.modelPath} did not recompile, so its sources ` + `(${kept.sources.join(", ") || "none"}) are served from the model ` + `it last compiled: ${kept.error}`,
|
|
384872
|
+
...upstreamWithdrawalSentences(withdrawn, kept.sources)
|
|
384201
384873
|
];
|
|
384202
|
-
if (live.length > 0) {
|
|
384203
|
-
parts.push(`Upstream table ${withdrawn.tables.join(", ")} changed since the ` + `last build, so ${live.join(", ")} answer live until a reload ` + `compiles and a run rebuilds them.`);
|
|
384204
|
-
}
|
|
384205
384874
|
return {
|
|
384206
384875
|
code: MODEL_RECOMPILE_FAILED,
|
|
384207
384876
|
model: kept.modelPath,
|
|
@@ -384222,7 +384891,7 @@ function packageLoadFailureStatus(error) {
|
|
|
384222
384891
|
}
|
|
384223
384892
|
return "error";
|
|
384224
384893
|
}
|
|
384225
|
-
var MODEL_RECOMPILE_FAILED = "model-recompile-failed", COMPUTED_PACKAGE_FIELDS, JOIN_BYPASS_NOTE, Package;
|
|
384894
|
+
var MODEL_RECOMPILE_FAILED = "model-recompile-failed", NOTHING_WITHDRAWN, COMPUTED_PACKAGE_FIELDS, JOIN_BYPASS_NOTE, Package;
|
|
384226
384895
|
var init_package2 = __esm(() => {
|
|
384227
384896
|
init_materialization();
|
|
384228
384897
|
init_malloy_text();
|
|
@@ -384278,6 +384947,11 @@ var init_package2 = __esm(() => {
|
|
|
384278
384947
|
init_secure_givens();
|
|
384279
384948
|
init_persist_annotation_validation();
|
|
384280
384949
|
init_package_load_gates();
|
|
384950
|
+
NOTHING_WITHDRAWN = {
|
|
384951
|
+
sources: [],
|
|
384952
|
+
tables: [],
|
|
384953
|
+
unread: { sources: [], tables: [] }
|
|
384954
|
+
};
|
|
384281
384955
|
COMPUTED_PACKAGE_FIELDS = [
|
|
384282
384956
|
"manifestBindingStatus",
|
|
384283
384957
|
"manifestEntryCount",
|
|
@@ -384338,6 +385012,10 @@ var init_package2 = __esm(() => {
|
|
|
384338
385012
|
renderTagWarnings = [];
|
|
384339
385013
|
recompileFailedWarnings = [];
|
|
384340
385014
|
keptModelStaleness;
|
|
385015
|
+
kept = {
|
|
385016
|
+
models: [],
|
|
385017
|
+
withdrawn: NOTHING_WITHDRAWN
|
|
385018
|
+
};
|
|
384341
385019
|
compiledFrom = new Map;
|
|
384342
385020
|
reloadedFor;
|
|
384343
385021
|
connectionEdits = 0;
|
|
@@ -384717,7 +385395,8 @@ var init_package2 = __esm(() => {
|
|
|
384717
385395
|
renderTagWarnings.push({
|
|
384718
385396
|
model: sm.modelPath,
|
|
384719
385397
|
message: `The load-time checks could not read this model ` + `(${errMessage(hydrateErr)}), so its render-tag and dashboard findings ` + `are unknown rather than clean.`,
|
|
384720
|
-
severity: "error"
|
|
385398
|
+
severity: "error",
|
|
385399
|
+
code: RENDER_TAG_CHECK_FAILED_CODE
|
|
384721
385400
|
});
|
|
384722
385401
|
models.set(sm.modelPath, placeholder(sm, hydrateErr instanceof Error ? hydrateErr : new Error(String(hydrateErr))));
|
|
384723
385402
|
continue;
|
|
@@ -384744,7 +385423,8 @@ var init_package2 = __esm(() => {
|
|
|
384744
385423
|
renderTagWarnings.push({
|
|
384745
385424
|
model: sm.modelPath,
|
|
384746
385425
|
message: `The render-tag check did not finish for this model, so ` + `its render-tag findings are unknown rather than clean.`,
|
|
384747
|
-
severity: "warn"
|
|
385426
|
+
severity: "warn",
|
|
385427
|
+
code: RENDER_TAG_CHECK_FAILED_CODE
|
|
384748
385428
|
});
|
|
384749
385429
|
}
|
|
384750
385430
|
models.set(sm.modelPath, placeholder(sm, err));
|
|
@@ -384757,7 +385437,8 @@ var init_package2 = __esm(() => {
|
|
|
384757
385437
|
model: sm.modelPath,
|
|
384758
385438
|
subject: w.subject,
|
|
384759
385439
|
message: w.message,
|
|
384760
|
-
severity: w.severity
|
|
385440
|
+
severity: w.severity,
|
|
385441
|
+
code: RENDER_TAG_CODE
|
|
384761
385442
|
});
|
|
384762
385443
|
}
|
|
384763
385444
|
const afterHydrateStart = performance.now();
|
|
@@ -385582,27 +386263,88 @@ var init_package2 = __esm(() => {
|
|
|
385582
386263
|
async getMalloyConnection(connectionName) {
|
|
385583
386264
|
return this.malloyConfig.connections.lookupConnection(connectionName);
|
|
385584
386265
|
}
|
|
385585
|
-
async withdrawChangedUpstreams() {
|
|
386266
|
+
async withdrawChangedUpstreams(options = {}) {
|
|
386267
|
+
const plan = this.mz.plan;
|
|
386268
|
+
const unreadBefore = plan.withdrawnUnread;
|
|
386269
|
+
if (options.onlyUnread && unreadBefore.size === 0) {
|
|
386270
|
+
return NOTHING_WITHDRAWN;
|
|
386271
|
+
}
|
|
386272
|
+
let inScope = [];
|
|
386273
|
+
let found;
|
|
386274
|
+
try {
|
|
386275
|
+
inScope = Object.entries(plan.servingPlan()?.sources ?? {}).filter(([, source]) => !options.onlyUnread || source.sourceEntityId !== undefined && unreadBefore.has(source.sourceEntityId));
|
|
386276
|
+
found = await this.readChangedUpstreams(inScope);
|
|
386277
|
+
} catch (error) {
|
|
386278
|
+
logger.warn("Could not read the upstream tables of a model kept from before a failed recompile; its stored tables answer live until a read succeeds", { packageName: this.packageName, error: errMessage(error) });
|
|
386279
|
+
const changedBefore = (id) => id !== undefined && plan.withdrawn.has(id) && !unreadBefore.has(id);
|
|
386280
|
+
const unread = inScope.filter(([, source]) => !changedBefore(source.sourceEntityId) && (source.sourceEntityId !== undefined && unreadBefore.has(source.sourceEntityId) || options.modelPaths === undefined || source.modelPath !== undefined && options.modelPaths.includes(source.modelPath)));
|
|
386281
|
+
found = {
|
|
386282
|
+
changed: [],
|
|
386283
|
+
changedTables: [],
|
|
386284
|
+
unread,
|
|
386285
|
+
unreadTables: undefined
|
|
386286
|
+
};
|
|
386287
|
+
if (unread.length === 0)
|
|
386288
|
+
return NOTHING_WITHDRAWN;
|
|
386289
|
+
}
|
|
386290
|
+
plan.withdraw(found.changed.map(([id]) => id), found.unread.map(([id]) => id));
|
|
386291
|
+
if (options.hold && plan.withdrawn.size > 0)
|
|
386292
|
+
plan.holdWithdrawn(true);
|
|
386293
|
+
const names = (sources) => [...new Set(sources.map(([, s]) => s.name))].sort();
|
|
386294
|
+
return {
|
|
386295
|
+
sources: names(found.changed),
|
|
386296
|
+
tables: found.changedTables,
|
|
386297
|
+
unread: { sources: names(found.unread), tables: found.unreadTables }
|
|
386298
|
+
};
|
|
386299
|
+
}
|
|
386300
|
+
async readChangedUpstreams(sources) {
|
|
385586
386301
|
const known = this.mz.plan.upstreamSchemas;
|
|
385587
|
-
const
|
|
386302
|
+
const keys = new Set(sources.flatMap(([, s]) => (s.reads ?? []).map(upstreamTableKey).filter((key) => (key in known))));
|
|
386303
|
+
const tables = [...keys].map((key) => {
|
|
385588
386304
|
const [connectionName, table] = JSON.parse(key);
|
|
385589
386305
|
return { connectionName, table };
|
|
385590
386306
|
});
|
|
385591
|
-
|
|
385592
|
-
return { sources: [], tables: [] };
|
|
385593
|
-
const now = await readUpstreamSchemas({
|
|
386307
|
+
const now = tables.length === 0 ? {} : await readUpstreamSchemas({
|
|
385594
386308
|
tables,
|
|
385595
386309
|
connection: (name) => this.getMalloyConnection(name),
|
|
385596
|
-
refresh: true
|
|
386310
|
+
refresh: true,
|
|
386311
|
+
keepLastOnFailure: false
|
|
385597
386312
|
});
|
|
386313
|
+
const unreadNow = (t) => {
|
|
386314
|
+
const key = upstreamTableKey(t);
|
|
386315
|
+
if (!(key in known))
|
|
386316
|
+
return false;
|
|
386317
|
+
const reading = now[key];
|
|
386318
|
+
return reading === undefined || "unread" in reading && reading.unread === "read_failed";
|
|
386319
|
+
};
|
|
385598
386320
|
const moved = (reads, sql) => upstreamSchemaFold(reads, known, sql) !== upstreamSchemaFold(reads, now, sql);
|
|
385599
|
-
const
|
|
385600
|
-
const
|
|
385601
|
-
const
|
|
385602
|
-
|
|
385603
|
-
|
|
385604
|
-
|
|
385605
|
-
|
|
386321
|
+
const changed = [];
|
|
386322
|
+
const unread = [];
|
|
386323
|
+
const changedTables = new Set;
|
|
386324
|
+
const unreadTables = new Set;
|
|
386325
|
+
for (const entry of sources) {
|
|
386326
|
+
const [, source] = entry;
|
|
386327
|
+
if (source.reads === undefined)
|
|
386328
|
+
continue;
|
|
386329
|
+
const failed = source.reads.filter(unreadNow);
|
|
386330
|
+
const read = source.reads.filter((t) => !unreadNow(t));
|
|
386331
|
+
const movedTables = read.filter((t) => moved([t], source.sql));
|
|
386332
|
+
if (read.length > 0 && moved(read, source.sql)) {
|
|
386333
|
+
changed.push(entry);
|
|
386334
|
+
for (const t of movedTables)
|
|
386335
|
+
changedTables.add(t.table);
|
|
386336
|
+
} else if (failed.length > 0) {
|
|
386337
|
+
unread.push(entry);
|
|
386338
|
+
for (const t of failed)
|
|
386339
|
+
unreadTables.add(t.table);
|
|
386340
|
+
}
|
|
386341
|
+
}
|
|
386342
|
+
return {
|
|
386343
|
+
changed,
|
|
386344
|
+
changedTables: [...changedTables].sort(),
|
|
386345
|
+
unread,
|
|
386346
|
+
unreadTables: [...unreadTables].sort()
|
|
386347
|
+
};
|
|
385606
386348
|
}
|
|
385607
386349
|
readTargetContainers(containers) {
|
|
385608
386350
|
return readTargetContainers({
|
|
@@ -385704,13 +386446,14 @@ var init_package2 = __esm(() => {
|
|
|
385704
386446
|
const compiledFor = Package.compileKeyOf(entries);
|
|
385705
386447
|
if (options.ifChanged && this.isCompiledFor(compiledFor)) {
|
|
385706
386448
|
const last = this.reloadedFor;
|
|
385707
|
-
if (last.bound === requested && !this.mz.hasUnreadDatabaseTables()) {
|
|
386449
|
+
if (last.bound === requested && !this.mz.hasUnreadDatabaseTables() && this.mz.plan.withdrawnUnread.size === 0) {
|
|
385708
386450
|
logger.debug("Skipped reloading models: the manifest is unchanged", {
|
|
385709
386451
|
packageName: this.packageName
|
|
385710
386452
|
});
|
|
385711
386453
|
return false;
|
|
385712
386454
|
}
|
|
385713
386455
|
const quoted = last.quotedFrom === requested ? last.quoted : await this.quoteBoundTableNames(entries);
|
|
386456
|
+
await this.rereadWithdrawnUpstreams();
|
|
385714
386457
|
await this.mz.bindCompiled({
|
|
385715
386458
|
database: quoted,
|
|
385716
386459
|
databaseAsGiven: true,
|
|
@@ -385754,21 +386497,18 @@ var init_package2 = __esm(() => {
|
|
|
385754
386497
|
modelPolicy: nextModelPolicy
|
|
385755
386498
|
}, "placeholder");
|
|
385756
386499
|
const kept = this.keepLastGoodModels(nextModels, outcome.fileDigests);
|
|
385757
|
-
const withdrawn = kept.length > 0 ? await this.withdrawChangedUpstreams(
|
|
385758
|
-
|
|
385759
|
-
|
|
385760
|
-
error: errMessage(error)
|
|
385761
|
-
});
|
|
385762
|
-
return { sources: [], tables: [] };
|
|
385763
|
-
}) : { sources: [], tables: [] };
|
|
386500
|
+
const withdrawn = kept.length > 0 ? await this.withdrawChangedUpstreams({
|
|
386501
|
+
modelPaths: kept.map((k) => k.modelPath)
|
|
386502
|
+
}) : await this.withdrawChangedUpstreams(this.mz.plan.holdingWithdrawn ? {} : { onlyUnread: true });
|
|
385764
386503
|
const discoveryStarted = performance.now();
|
|
385765
386504
|
const discovery = await this.discoverReportsIn(nextModels, "reload");
|
|
385766
386505
|
const discoveryMs = performance.now() - discoveryStarted;
|
|
385767
386506
|
this.models = nextModels;
|
|
385768
386507
|
this.modelPolicy.handOffTo(nextModelPolicy);
|
|
385769
386508
|
this.modelPolicy = nextModelPolicy;
|
|
386509
|
+
this.kept = { models: kept, withdrawn };
|
|
385770
386510
|
this.recompileFailedWarnings = kept.map((k) => recompileFailedWarning(k, withdrawn));
|
|
385771
|
-
this.mz.plan.holdWithdrawn(kept.length > 0);
|
|
386511
|
+
this.mz.plan.holdWithdrawn(kept.length > 0 || this.mz.plan.withdrawnUnread.size > 0);
|
|
385772
386512
|
const compiledFrom = this.compiledFromOf(nextModels, outcome.fileDigests);
|
|
385773
386513
|
for (const { modelPath } of kept) {
|
|
385774
386514
|
const prior = this.compiledFrom.get(modelPath);
|
|
@@ -385812,6 +386552,28 @@ var init_package2 = __esm(() => {
|
|
|
385812
386552
|
this.logEmptyDiscoveryWarnings();
|
|
385813
386553
|
return true;
|
|
385814
386554
|
}
|
|
386555
|
+
async rereadWithdrawnUpstreams() {
|
|
386556
|
+
if (this.mz.plan.withdrawnUnread.size === 0)
|
|
386557
|
+
return;
|
|
386558
|
+
const holding = this.mz.plan.holdingWithdrawn;
|
|
386559
|
+
const reread = await this.withdrawChangedUpstreams({ onlyUnread: true });
|
|
386560
|
+
const before = this.kept.withdrawn;
|
|
386561
|
+
const withdrawn = {
|
|
386562
|
+
sources: [...new Set([...before.sources, ...reread.sources])].sort(),
|
|
386563
|
+
tables: [...new Set([...before.tables, ...reread.tables])].sort(),
|
|
386564
|
+
unread: reread.unread
|
|
386565
|
+
};
|
|
386566
|
+
const models = this.kept.models;
|
|
386567
|
+
this.kept = { models, withdrawn };
|
|
386568
|
+
this.recompileFailedWarnings = models.map((k) => recompileFailedWarning(k, withdrawn));
|
|
386569
|
+
this.mz.plan.holdWithdrawn((holding || models.length > 0) && this.mz.plan.withdrawn.size > 0);
|
|
386570
|
+
if (this.keptModelStaleness) {
|
|
386571
|
+
this.keptModelStaleness = {
|
|
386572
|
+
...this.keptModelStaleness,
|
|
386573
|
+
message: this.recompileFailedWarnings.map((w) => w.message).join(" ")
|
|
386574
|
+
};
|
|
386575
|
+
}
|
|
386576
|
+
}
|
|
385815
386577
|
keepLastGoodModels(nextModels, digests) {
|
|
385816
386578
|
const kept = [];
|
|
385817
386579
|
for (const [modelPath, next] of nextModels) {
|
|
@@ -387741,7 +388503,7 @@ async function compilePackageDryRun(ctx) {
|
|
|
387741
388503
|
}
|
|
387742
388504
|
}
|
|
387743
388505
|
for (const warning of renderTagWarnings) {
|
|
387744
|
-
collect([warningAsProblem(warning,
|
|
388506
|
+
collect([warningAsProblem(warning, warning.code ?? RENDER_TAG_CODE)], warning.model);
|
|
387745
388507
|
}
|
|
387746
388508
|
for (const warning of reportWarnings) {
|
|
387747
388509
|
collect([warningAsProblem(warning, warning.code ?? UNCODED_REPORT_FINDING)], warning.model);
|
|
@@ -388436,6 +389198,7 @@ function callerVisibleEvent(event) {
|
|
|
388436
389198
|
}
|
|
388437
389199
|
var STAGING_DIR_NAME2 = ".staging", RETIRED_DIR_NAME = ".retired", MANIFEST_FETCH_TIMEOUT_MS = 15000, REBIND_ATTEMPTS = 3, REBIND_RETRY_MS = 500, RETIRED_CONNECTION_DRAIN_MS = 30000, DESTINATION_READ_FIELDS, getQueryAdmissionRejectionsCounter, getPackageAdmissionRejectionsCounter, STATUS_VERSIONS_RETRY_FIRST_MS = 250, STATUS_VERSIONS_RETRY_CAP_MS = 30000, STATUS_VERSIONS_RETRIES_BEFORE_ERROR = 8, Environment;
|
|
388438
389200
|
var init_environment = __esm(() => {
|
|
389201
|
+
init_ducklake_catalog();
|
|
388439
389202
|
init_driver_errors();
|
|
388440
389203
|
init_materialization_metrics();
|
|
388441
389204
|
init_report();
|
|
@@ -388906,6 +389669,9 @@ var init_environment = __esm(() => {
|
|
|
388906
389669
|
async getMalloyConnection(connectionName) {
|
|
388907
389670
|
return this.malloyConfig.malloyConfig.connections.lookupConnection(connectionName);
|
|
388908
389671
|
}
|
|
389672
|
+
async managedStorageScope(connectionName) {
|
|
389673
|
+
return managedScopeOf(await this.getMalloyConnection(connectionName), connectionName);
|
|
389674
|
+
}
|
|
388909
389675
|
getEnvironmentMalloyConfig() {
|
|
388910
389676
|
return this.malloyConfig.malloyConfig;
|
|
388911
389677
|
}
|
|
@@ -390213,12 +390979,17 @@ var init_environment = __esm(() => {
|
|
|
390213
390979
|
} catch (error) {
|
|
390214
390980
|
logger.error(`Failed to load package ${packageName}`, { error });
|
|
390215
390981
|
if (existingPackage !== undefined) {
|
|
390216
|
-
const withdrawn = refreshSchemas ? await existingPackage.withdrawChangedUpstreams(
|
|
390982
|
+
const withdrawn = refreshSchemas ? await existingPackage.withdrawChangedUpstreams({
|
|
390983
|
+
hold: true
|
|
390984
|
+
}) : undefined;
|
|
390217
390985
|
const message = redactPgSecrets(error instanceof Error ? error.message : String(error));
|
|
390218
390986
|
this.transition(packageName, {
|
|
390219
390987
|
type: "reloadFailed",
|
|
390220
390988
|
stale: {
|
|
390221
|
-
message:
|
|
390989
|
+
message: [
|
|
390990
|
+
message,
|
|
390991
|
+
...withdrawn ? upstreamWithdrawalSentences(withdrawn) : []
|
|
390992
|
+
].join(" "),
|
|
390222
390993
|
failedAt: new Date().toISOString()
|
|
390223
390994
|
}
|
|
390224
390995
|
});
|
|
@@ -390428,7 +391199,9 @@ var init_environment = __esm(() => {
|
|
|
390428
391199
|
oldPackage
|
|
390429
391200
|
});
|
|
390430
391201
|
if (oldPackage !== undefined && this.packages.get(packageName) === oldPackage) {
|
|
390431
|
-
const withdrawn = await oldPackage.withdrawChangedUpstreams(
|
|
391202
|
+
const withdrawn = await oldPackage.withdrawChangedUpstreams({
|
|
391203
|
+
hold: true
|
|
391204
|
+
});
|
|
390432
391205
|
if (withdrawn.sources.length > 0) {
|
|
390433
391206
|
logger.warn("A failed publish found upstream tables changed; their stored tables answer live", {
|
|
390434
391207
|
environmentName: this.environmentName,
|
|
@@ -390436,6 +391209,13 @@ var init_environment = __esm(() => {
|
|
|
390436
391209
|
sources: withdrawn.sources
|
|
390437
391210
|
});
|
|
390438
391211
|
}
|
|
391212
|
+
if (withdrawn.unread.sources.length > 0) {
|
|
391213
|
+
logger.warn("A failed publish could not read upstream tables; their stored tables answer live until a read succeeds", {
|
|
391214
|
+
environmentName: this.environmentName,
|
|
391215
|
+
packageName,
|
|
391216
|
+
sources: withdrawn.unread.sources
|
|
391217
|
+
});
|
|
391218
|
+
}
|
|
390439
391219
|
}
|
|
390440
391220
|
throw err;
|
|
390441
391221
|
}
|
|
@@ -390654,6 +391434,8 @@ var init_environment = __esm(() => {
|
|
|
390654
391434
|
const recompiled = (hasDatabase || hadDatabase) && await pkg.reloadAllModels(tableNameManifest, {
|
|
390655
391435
|
ifChanged: recompile === "if-changed"
|
|
390656
391436
|
});
|
|
391437
|
+
if (!(hasDatabase || hadDatabase))
|
|
391438
|
+
await pkg.rereadWithdrawnUpstreams();
|
|
390657
391439
|
if (hasStorage || hadStorage) {
|
|
390658
391440
|
await pkg.materialization().bindCompiled({
|
|
390659
391441
|
storage: storageEntries,
|
|
@@ -459176,7 +459958,7 @@ function _enum(values, params) {
|
|
|
459176
459958
|
...normalizeParams(params)
|
|
459177
459959
|
});
|
|
459178
459960
|
}
|
|
459179
|
-
function
|
|
459961
|
+
function literal3(value, params) {
|
|
459180
459962
|
return new ZodLiteral({
|
|
459181
459963
|
type: "literal",
|
|
459182
459964
|
values: Array.isArray(value) ? value : [value],
|
|
@@ -459791,16 +460573,16 @@ var init_types5 = __esm(() => {
|
|
|
459791
460573
|
});
|
|
459792
460574
|
RequestIdSchema = union([string3(), number3().int()]);
|
|
459793
460575
|
JSONRPCRequestSchema = object({
|
|
459794
|
-
jsonrpc:
|
|
460576
|
+
jsonrpc: literal3(JSONRPC_VERSION),
|
|
459795
460577
|
id: RequestIdSchema,
|
|
459796
460578
|
...RequestSchema.shape
|
|
459797
460579
|
}).strict();
|
|
459798
460580
|
JSONRPCNotificationSchema = object({
|
|
459799
|
-
jsonrpc:
|
|
460581
|
+
jsonrpc: literal3(JSONRPC_VERSION),
|
|
459800
460582
|
...NotificationSchema.shape
|
|
459801
460583
|
}).strict();
|
|
459802
460584
|
JSONRPCResultResponseSchema = object({
|
|
459803
|
-
jsonrpc:
|
|
460585
|
+
jsonrpc: literal3(JSONRPC_VERSION),
|
|
459804
460586
|
id: RequestIdSchema,
|
|
459805
460587
|
result: ResultSchema
|
|
459806
460588
|
}).strict();
|
|
@@ -459815,7 +460597,7 @@ var init_types5 = __esm(() => {
|
|
|
459815
460597
|
ErrorCode[ErrorCode["UrlElicitationRequired"] = -32042] = "UrlElicitationRequired";
|
|
459816
460598
|
})(ErrorCode || (ErrorCode = {}));
|
|
459817
460599
|
JSONRPCErrorResponseSchema = object({
|
|
459818
|
-
jsonrpc:
|
|
460600
|
+
jsonrpc: literal3(JSONRPC_VERSION),
|
|
459819
460601
|
id: RequestIdSchema.optional(),
|
|
459820
460602
|
error: object({
|
|
459821
460603
|
code: number3().int(),
|
|
@@ -459836,7 +460618,7 @@ var init_types5 = __esm(() => {
|
|
|
459836
460618
|
reason: string3().optional()
|
|
459837
460619
|
});
|
|
459838
460620
|
CancelledNotificationSchema = NotificationSchema.extend({
|
|
459839
|
-
method:
|
|
460621
|
+
method: literal3("notifications/cancelled"),
|
|
459840
460622
|
params: CancelledNotificationParamsSchema
|
|
459841
460623
|
});
|
|
459842
460624
|
IconSchema = object({
|
|
@@ -459913,7 +460695,7 @@ var init_types5 = __esm(() => {
|
|
|
459913
460695
|
clientInfo: ImplementationSchema
|
|
459914
460696
|
});
|
|
459915
460697
|
InitializeRequestSchema = RequestSchema.extend({
|
|
459916
|
-
method:
|
|
460698
|
+
method: literal3("initialize"),
|
|
459917
460699
|
params: InitializeRequestParamsSchema
|
|
459918
460700
|
});
|
|
459919
460701
|
ServerCapabilitiesSchema = object({
|
|
@@ -459940,11 +460722,11 @@ var init_types5 = __esm(() => {
|
|
|
459940
460722
|
instructions: string3().optional()
|
|
459941
460723
|
});
|
|
459942
460724
|
InitializedNotificationSchema = NotificationSchema.extend({
|
|
459943
|
-
method:
|
|
460725
|
+
method: literal3("notifications/initialized"),
|
|
459944
460726
|
params: NotificationsParamsSchema.optional()
|
|
459945
460727
|
});
|
|
459946
460728
|
PingRequestSchema = RequestSchema.extend({
|
|
459947
|
-
method:
|
|
460729
|
+
method: literal3("ping"),
|
|
459948
460730
|
params: BaseRequestParamsSchema.optional()
|
|
459949
460731
|
});
|
|
459950
460732
|
ProgressSchema = object({
|
|
@@ -459958,7 +460740,7 @@ var init_types5 = __esm(() => {
|
|
|
459958
460740
|
progressToken: ProgressTokenSchema
|
|
459959
460741
|
});
|
|
459960
460742
|
ProgressNotificationSchema = NotificationSchema.extend({
|
|
459961
|
-
method:
|
|
460743
|
+
method: literal3("notifications/progress"),
|
|
459962
460744
|
params: ProgressNotificationParamsSchema
|
|
459963
460745
|
});
|
|
459964
460746
|
PaginatedRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
@@ -459985,31 +460767,31 @@ var init_types5 = __esm(() => {
|
|
|
459985
460767
|
});
|
|
459986
460768
|
TaskStatusNotificationParamsSchema = NotificationsParamsSchema.merge(TaskSchema);
|
|
459987
460769
|
TaskStatusNotificationSchema = NotificationSchema.extend({
|
|
459988
|
-
method:
|
|
460770
|
+
method: literal3("notifications/tasks/status"),
|
|
459989
460771
|
params: TaskStatusNotificationParamsSchema
|
|
459990
460772
|
});
|
|
459991
460773
|
GetTaskRequestSchema = RequestSchema.extend({
|
|
459992
|
-
method:
|
|
460774
|
+
method: literal3("tasks/get"),
|
|
459993
460775
|
params: BaseRequestParamsSchema.extend({
|
|
459994
460776
|
taskId: string3()
|
|
459995
460777
|
})
|
|
459996
460778
|
});
|
|
459997
460779
|
GetTaskResultSchema = ResultSchema.merge(TaskSchema);
|
|
459998
460780
|
GetTaskPayloadRequestSchema = RequestSchema.extend({
|
|
459999
|
-
method:
|
|
460781
|
+
method: literal3("tasks/result"),
|
|
460000
460782
|
params: BaseRequestParamsSchema.extend({
|
|
460001
460783
|
taskId: string3()
|
|
460002
460784
|
})
|
|
460003
460785
|
});
|
|
460004
460786
|
GetTaskPayloadResultSchema = ResultSchema.loose();
|
|
460005
460787
|
ListTasksRequestSchema = PaginatedRequestSchema.extend({
|
|
460006
|
-
method:
|
|
460788
|
+
method: literal3("tasks/list")
|
|
460007
460789
|
});
|
|
460008
460790
|
ListTasksResultSchema = PaginatedResultSchema.extend({
|
|
460009
460791
|
tasks: array(TaskSchema)
|
|
460010
460792
|
});
|
|
460011
460793
|
CancelTaskRequestSchema = RequestSchema.extend({
|
|
460012
|
-
method:
|
|
460794
|
+
method: literal3("tasks/cancel"),
|
|
460013
460795
|
params: BaseRequestParamsSchema.extend({
|
|
460014
460796
|
taskId: string3()
|
|
460015
460797
|
})
|
|
@@ -460060,13 +460842,13 @@ var init_types5 = __esm(() => {
|
|
|
460060
460842
|
_meta: optional2(looseObject({}))
|
|
460061
460843
|
});
|
|
460062
460844
|
ListResourcesRequestSchema = PaginatedRequestSchema.extend({
|
|
460063
|
-
method:
|
|
460845
|
+
method: literal3("resources/list")
|
|
460064
460846
|
});
|
|
460065
460847
|
ListResourcesResultSchema = PaginatedResultSchema.extend({
|
|
460066
460848
|
resources: array(ResourceSchema)
|
|
460067
460849
|
});
|
|
460068
460850
|
ListResourceTemplatesRequestSchema = PaginatedRequestSchema.extend({
|
|
460069
|
-
method:
|
|
460851
|
+
method: literal3("resources/templates/list")
|
|
460070
460852
|
});
|
|
460071
460853
|
ListResourceTemplatesResultSchema = PaginatedResultSchema.extend({
|
|
460072
460854
|
resourceTemplates: array(ResourceTemplateSchema)
|
|
@@ -460076,31 +460858,31 @@ var init_types5 = __esm(() => {
|
|
|
460076
460858
|
});
|
|
460077
460859
|
ReadResourceRequestParamsSchema = ResourceRequestParamsSchema;
|
|
460078
460860
|
ReadResourceRequestSchema = RequestSchema.extend({
|
|
460079
|
-
method:
|
|
460861
|
+
method: literal3("resources/read"),
|
|
460080
460862
|
params: ReadResourceRequestParamsSchema
|
|
460081
460863
|
});
|
|
460082
460864
|
ReadResourceResultSchema = ResultSchema.extend({
|
|
460083
460865
|
contents: array(union([TextResourceContentsSchema, BlobResourceContentsSchema]))
|
|
460084
460866
|
});
|
|
460085
460867
|
ResourceListChangedNotificationSchema = NotificationSchema.extend({
|
|
460086
|
-
method:
|
|
460868
|
+
method: literal3("notifications/resources/list_changed"),
|
|
460087
460869
|
params: NotificationsParamsSchema.optional()
|
|
460088
460870
|
});
|
|
460089
460871
|
SubscribeRequestParamsSchema = ResourceRequestParamsSchema;
|
|
460090
460872
|
SubscribeRequestSchema = RequestSchema.extend({
|
|
460091
|
-
method:
|
|
460873
|
+
method: literal3("resources/subscribe"),
|
|
460092
460874
|
params: SubscribeRequestParamsSchema
|
|
460093
460875
|
});
|
|
460094
460876
|
UnsubscribeRequestParamsSchema = ResourceRequestParamsSchema;
|
|
460095
460877
|
UnsubscribeRequestSchema = RequestSchema.extend({
|
|
460096
|
-
method:
|
|
460878
|
+
method: literal3("resources/unsubscribe"),
|
|
460097
460879
|
params: UnsubscribeRequestParamsSchema
|
|
460098
460880
|
});
|
|
460099
460881
|
ResourceUpdatedNotificationParamsSchema = NotificationsParamsSchema.extend({
|
|
460100
460882
|
uri: string3()
|
|
460101
460883
|
});
|
|
460102
460884
|
ResourceUpdatedNotificationSchema = NotificationSchema.extend({
|
|
460103
|
-
method:
|
|
460885
|
+
method: literal3("notifications/resources/updated"),
|
|
460104
460886
|
params: ResourceUpdatedNotificationParamsSchema
|
|
460105
460887
|
});
|
|
460106
460888
|
PromptArgumentSchema = object({
|
|
@@ -460116,7 +460898,7 @@ var init_types5 = __esm(() => {
|
|
|
460116
460898
|
_meta: optional2(looseObject({}))
|
|
460117
460899
|
});
|
|
460118
460900
|
ListPromptsRequestSchema = PaginatedRequestSchema.extend({
|
|
460119
|
-
method:
|
|
460901
|
+
method: literal3("prompts/list")
|
|
460120
460902
|
});
|
|
460121
460903
|
ListPromptsResultSchema = PaginatedResultSchema.extend({
|
|
460122
460904
|
prompts: array(PromptSchema)
|
|
@@ -460126,44 +460908,44 @@ var init_types5 = __esm(() => {
|
|
|
460126
460908
|
arguments: record(string3(), string3()).optional()
|
|
460127
460909
|
});
|
|
460128
460910
|
GetPromptRequestSchema = RequestSchema.extend({
|
|
460129
|
-
method:
|
|
460911
|
+
method: literal3("prompts/get"),
|
|
460130
460912
|
params: GetPromptRequestParamsSchema
|
|
460131
460913
|
});
|
|
460132
460914
|
TextContentSchema = object({
|
|
460133
|
-
type:
|
|
460915
|
+
type: literal3("text"),
|
|
460134
460916
|
text: string3(),
|
|
460135
460917
|
annotations: AnnotationsSchema.optional(),
|
|
460136
460918
|
_meta: record(string3(), unknown()).optional()
|
|
460137
460919
|
});
|
|
460138
460920
|
ImageContentSchema = object({
|
|
460139
|
-
type:
|
|
460921
|
+
type: literal3("image"),
|
|
460140
460922
|
data: Base64Schema,
|
|
460141
460923
|
mimeType: string3(),
|
|
460142
460924
|
annotations: AnnotationsSchema.optional(),
|
|
460143
460925
|
_meta: record(string3(), unknown()).optional()
|
|
460144
460926
|
});
|
|
460145
460927
|
AudioContentSchema = object({
|
|
460146
|
-
type:
|
|
460928
|
+
type: literal3("audio"),
|
|
460147
460929
|
data: Base64Schema,
|
|
460148
460930
|
mimeType: string3(),
|
|
460149
460931
|
annotations: AnnotationsSchema.optional(),
|
|
460150
460932
|
_meta: record(string3(), unknown()).optional()
|
|
460151
460933
|
});
|
|
460152
460934
|
ToolUseContentSchema = object({
|
|
460153
|
-
type:
|
|
460935
|
+
type: literal3("tool_use"),
|
|
460154
460936
|
name: string3(),
|
|
460155
460937
|
id: string3(),
|
|
460156
460938
|
input: record(string3(), unknown()),
|
|
460157
460939
|
_meta: record(string3(), unknown()).optional()
|
|
460158
460940
|
});
|
|
460159
460941
|
EmbeddedResourceSchema = object({
|
|
460160
|
-
type:
|
|
460942
|
+
type: literal3("resource"),
|
|
460161
460943
|
resource: union([TextResourceContentsSchema, BlobResourceContentsSchema]),
|
|
460162
460944
|
annotations: AnnotationsSchema.optional(),
|
|
460163
460945
|
_meta: record(string3(), unknown()).optional()
|
|
460164
460946
|
});
|
|
460165
460947
|
ResourceLinkSchema = ResourceSchema.extend({
|
|
460166
|
-
type:
|
|
460948
|
+
type: literal3("resource_link")
|
|
460167
460949
|
});
|
|
460168
460950
|
ContentBlockSchema = union([
|
|
460169
460951
|
TextContentSchema,
|
|
@@ -460181,7 +460963,7 @@ var init_types5 = __esm(() => {
|
|
|
460181
460963
|
messages: array(PromptMessageSchema)
|
|
460182
460964
|
});
|
|
460183
460965
|
PromptListChangedNotificationSchema = NotificationSchema.extend({
|
|
460184
|
-
method:
|
|
460966
|
+
method: literal3("notifications/prompts/list_changed"),
|
|
460185
460967
|
params: NotificationsParamsSchema.optional()
|
|
460186
460968
|
});
|
|
460187
460969
|
ToolAnnotationsSchema = object({
|
|
@@ -460199,12 +460981,12 @@ var init_types5 = __esm(() => {
|
|
|
460199
460981
|
...IconsSchema.shape,
|
|
460200
460982
|
description: string3().optional(),
|
|
460201
460983
|
inputSchema: object({
|
|
460202
|
-
type:
|
|
460984
|
+
type: literal3("object"),
|
|
460203
460985
|
properties: record(string3(), AssertObjectSchema).optional(),
|
|
460204
460986
|
required: array(string3()).optional()
|
|
460205
460987
|
}).catchall(unknown()),
|
|
460206
460988
|
outputSchema: object({
|
|
460207
|
-
type:
|
|
460989
|
+
type: literal3("object"),
|
|
460208
460990
|
properties: record(string3(), AssertObjectSchema).optional(),
|
|
460209
460991
|
required: array(string3()).optional()
|
|
460210
460992
|
}).catchall(unknown()).optional(),
|
|
@@ -460213,7 +460995,7 @@ var init_types5 = __esm(() => {
|
|
|
460213
460995
|
_meta: record(string3(), unknown()).optional()
|
|
460214
460996
|
});
|
|
460215
460997
|
ListToolsRequestSchema = PaginatedRequestSchema.extend({
|
|
460216
|
-
method:
|
|
460998
|
+
method: literal3("tools/list")
|
|
460217
460999
|
});
|
|
460218
461000
|
ListToolsResultSchema = PaginatedResultSchema.extend({
|
|
460219
461001
|
tools: array(ToolSchema)
|
|
@@ -460231,11 +461013,11 @@ var init_types5 = __esm(() => {
|
|
|
460231
461013
|
arguments: record(string3(), unknown()).optional()
|
|
460232
461014
|
});
|
|
460233
461015
|
CallToolRequestSchema = RequestSchema.extend({
|
|
460234
|
-
method:
|
|
461016
|
+
method: literal3("tools/call"),
|
|
460235
461017
|
params: CallToolRequestParamsSchema
|
|
460236
461018
|
});
|
|
460237
461019
|
ToolListChangedNotificationSchema = NotificationSchema.extend({
|
|
460238
|
-
method:
|
|
461020
|
+
method: literal3("notifications/tools/list_changed"),
|
|
460239
461021
|
params: NotificationsParamsSchema.optional()
|
|
460240
461022
|
});
|
|
460241
461023
|
ListChangedOptionsBaseSchema = object({
|
|
@@ -460247,7 +461029,7 @@ var init_types5 = __esm(() => {
|
|
|
460247
461029
|
level: LoggingLevelSchema
|
|
460248
461030
|
});
|
|
460249
461031
|
SetLevelRequestSchema = RequestSchema.extend({
|
|
460250
|
-
method:
|
|
461032
|
+
method: literal3("logging/setLevel"),
|
|
460251
461033
|
params: SetLevelRequestParamsSchema
|
|
460252
461034
|
});
|
|
460253
461035
|
LoggingMessageNotificationParamsSchema = NotificationsParamsSchema.extend({
|
|
@@ -460256,7 +461038,7 @@ var init_types5 = __esm(() => {
|
|
|
460256
461038
|
data: unknown()
|
|
460257
461039
|
});
|
|
460258
461040
|
LoggingMessageNotificationSchema = NotificationSchema.extend({
|
|
460259
|
-
method:
|
|
461041
|
+
method: literal3("notifications/message"),
|
|
460260
461042
|
params: LoggingMessageNotificationParamsSchema
|
|
460261
461043
|
});
|
|
460262
461044
|
ModelHintSchema = object({
|
|
@@ -460272,7 +461054,7 @@ var init_types5 = __esm(() => {
|
|
|
460272
461054
|
mode: _enum(["auto", "required", "none"]).optional()
|
|
460273
461055
|
});
|
|
460274
461056
|
ToolResultContentSchema = object({
|
|
460275
|
-
type:
|
|
461057
|
+
type: literal3("tool_result"),
|
|
460276
461058
|
toolUseId: string3().describe("The unique identifier for the corresponding tool call."),
|
|
460277
461059
|
content: array(ContentBlockSchema).default([]),
|
|
460278
461060
|
structuredContent: object({}).loose().optional(),
|
|
@@ -460305,7 +461087,7 @@ var init_types5 = __esm(() => {
|
|
|
460305
461087
|
toolChoice: ToolChoiceSchema.optional()
|
|
460306
461088
|
});
|
|
460307
461089
|
CreateMessageRequestSchema = RequestSchema.extend({
|
|
460308
|
-
method:
|
|
461090
|
+
method: literal3("sampling/createMessage"),
|
|
460309
461091
|
params: CreateMessageRequestParamsSchema
|
|
460310
461092
|
});
|
|
460311
461093
|
CreateMessageResultSchema = ResultSchema.extend({
|
|
@@ -460321,13 +461103,13 @@ var init_types5 = __esm(() => {
|
|
|
460321
461103
|
content: union([SamplingMessageContentBlockSchema, array(SamplingMessageContentBlockSchema)])
|
|
460322
461104
|
});
|
|
460323
461105
|
BooleanSchemaSchema = object({
|
|
460324
|
-
type:
|
|
461106
|
+
type: literal3("boolean"),
|
|
460325
461107
|
title: string3().optional(),
|
|
460326
461108
|
description: string3().optional(),
|
|
460327
461109
|
default: boolean3().optional()
|
|
460328
461110
|
});
|
|
460329
461111
|
StringSchemaSchema = object({
|
|
460330
|
-
type:
|
|
461112
|
+
type: literal3("string"),
|
|
460331
461113
|
title: string3().optional(),
|
|
460332
461114
|
description: string3().optional(),
|
|
460333
461115
|
minLength: number3().optional(),
|
|
@@ -460344,14 +461126,14 @@ var init_types5 = __esm(() => {
|
|
|
460344
461126
|
default: number3().optional()
|
|
460345
461127
|
});
|
|
460346
461128
|
UntitledSingleSelectEnumSchemaSchema = object({
|
|
460347
|
-
type:
|
|
461129
|
+
type: literal3("string"),
|
|
460348
461130
|
title: string3().optional(),
|
|
460349
461131
|
description: string3().optional(),
|
|
460350
461132
|
enum: array(string3()),
|
|
460351
461133
|
default: string3().optional()
|
|
460352
461134
|
});
|
|
460353
461135
|
TitledSingleSelectEnumSchemaSchema = object({
|
|
460354
|
-
type:
|
|
461136
|
+
type: literal3("string"),
|
|
460355
461137
|
title: string3().optional(),
|
|
460356
461138
|
description: string3().optional(),
|
|
460357
461139
|
oneOf: array(object({
|
|
@@ -460361,7 +461143,7 @@ var init_types5 = __esm(() => {
|
|
|
460361
461143
|
default: string3().optional()
|
|
460362
461144
|
});
|
|
460363
461145
|
LegacyTitledEnumSchemaSchema = object({
|
|
460364
|
-
type:
|
|
461146
|
+
type: literal3("string"),
|
|
460365
461147
|
title: string3().optional(),
|
|
460366
461148
|
description: string3().optional(),
|
|
460367
461149
|
enum: array(string3()),
|
|
@@ -460370,19 +461152,19 @@ var init_types5 = __esm(() => {
|
|
|
460370
461152
|
});
|
|
460371
461153
|
SingleSelectEnumSchemaSchema = union([UntitledSingleSelectEnumSchemaSchema, TitledSingleSelectEnumSchemaSchema]);
|
|
460372
461154
|
UntitledMultiSelectEnumSchemaSchema = object({
|
|
460373
|
-
type:
|
|
461155
|
+
type: literal3("array"),
|
|
460374
461156
|
title: string3().optional(),
|
|
460375
461157
|
description: string3().optional(),
|
|
460376
461158
|
minItems: number3().optional(),
|
|
460377
461159
|
maxItems: number3().optional(),
|
|
460378
461160
|
items: object({
|
|
460379
|
-
type:
|
|
461161
|
+
type: literal3("string"),
|
|
460380
461162
|
enum: array(string3())
|
|
460381
461163
|
}),
|
|
460382
461164
|
default: array(string3()).optional()
|
|
460383
461165
|
});
|
|
460384
461166
|
TitledMultiSelectEnumSchemaSchema = object({
|
|
460385
|
-
type:
|
|
461167
|
+
type: literal3("array"),
|
|
460386
461168
|
title: string3().optional(),
|
|
460387
461169
|
description: string3().optional(),
|
|
460388
461170
|
minItems: number3().optional(),
|
|
@@ -460399,30 +461181,30 @@ var init_types5 = __esm(() => {
|
|
|
460399
461181
|
EnumSchemaSchema = union([LegacyTitledEnumSchemaSchema, SingleSelectEnumSchemaSchema, MultiSelectEnumSchemaSchema]);
|
|
460400
461182
|
PrimitiveSchemaDefinitionSchema = union([EnumSchemaSchema, BooleanSchemaSchema, StringSchemaSchema, NumberSchemaSchema]);
|
|
460401
461183
|
ElicitRequestFormParamsSchema = TaskAugmentedRequestParamsSchema.extend({
|
|
460402
|
-
mode:
|
|
461184
|
+
mode: literal3("form").optional(),
|
|
460403
461185
|
message: string3(),
|
|
460404
461186
|
requestedSchema: object({
|
|
460405
|
-
type:
|
|
461187
|
+
type: literal3("object"),
|
|
460406
461188
|
properties: record(string3(), PrimitiveSchemaDefinitionSchema),
|
|
460407
461189
|
required: array(string3()).optional()
|
|
460408
461190
|
})
|
|
460409
461191
|
});
|
|
460410
461192
|
ElicitRequestURLParamsSchema = TaskAugmentedRequestParamsSchema.extend({
|
|
460411
|
-
mode:
|
|
461193
|
+
mode: literal3("url"),
|
|
460412
461194
|
message: string3(),
|
|
460413
461195
|
elicitationId: string3(),
|
|
460414
461196
|
url: string3().url()
|
|
460415
461197
|
});
|
|
460416
461198
|
ElicitRequestParamsSchema = union([ElicitRequestFormParamsSchema, ElicitRequestURLParamsSchema]);
|
|
460417
461199
|
ElicitRequestSchema = RequestSchema.extend({
|
|
460418
|
-
method:
|
|
461200
|
+
method: literal3("elicitation/create"),
|
|
460419
461201
|
params: ElicitRequestParamsSchema
|
|
460420
461202
|
});
|
|
460421
461203
|
ElicitationCompleteNotificationParamsSchema = NotificationsParamsSchema.extend({
|
|
460422
461204
|
elicitationId: string3()
|
|
460423
461205
|
});
|
|
460424
461206
|
ElicitationCompleteNotificationSchema = NotificationSchema.extend({
|
|
460425
|
-
method:
|
|
461207
|
+
method: literal3("notifications/elicitation/complete"),
|
|
460426
461208
|
params: ElicitationCompleteNotificationParamsSchema
|
|
460427
461209
|
});
|
|
460428
461210
|
ElicitResultSchema = ResultSchema.extend({
|
|
@@ -460430,11 +461212,11 @@ var init_types5 = __esm(() => {
|
|
|
460430
461212
|
content: preprocess((val) => val === null ? undefined : val, record(string3(), union([string3(), number3(), boolean3(), array(string3())])).optional())
|
|
460431
461213
|
});
|
|
460432
461214
|
ResourceTemplateReferenceSchema = object({
|
|
460433
|
-
type:
|
|
461215
|
+
type: literal3("ref/resource"),
|
|
460434
461216
|
uri: string3()
|
|
460435
461217
|
});
|
|
460436
461218
|
PromptReferenceSchema = object({
|
|
460437
|
-
type:
|
|
461219
|
+
type: literal3("ref/prompt"),
|
|
460438
461220
|
name: string3()
|
|
460439
461221
|
});
|
|
460440
461222
|
CompleteRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
@@ -460448,7 +461230,7 @@ var init_types5 = __esm(() => {
|
|
|
460448
461230
|
}).optional()
|
|
460449
461231
|
});
|
|
460450
461232
|
CompleteRequestSchema = RequestSchema.extend({
|
|
460451
|
-
method:
|
|
461233
|
+
method: literal3("completion/complete"),
|
|
460452
461234
|
params: CompleteRequestParamsSchema
|
|
460453
461235
|
});
|
|
460454
461236
|
CompleteResultSchema = ResultSchema.extend({
|
|
@@ -460464,14 +461246,14 @@ var init_types5 = __esm(() => {
|
|
|
460464
461246
|
_meta: record(string3(), unknown()).optional()
|
|
460465
461247
|
});
|
|
460466
461248
|
ListRootsRequestSchema = RequestSchema.extend({
|
|
460467
|
-
method:
|
|
461249
|
+
method: literal3("roots/list"),
|
|
460468
461250
|
params: BaseRequestParamsSchema.optional()
|
|
460469
461251
|
});
|
|
460470
461252
|
ListRootsResultSchema = ResultSchema.extend({
|
|
460471
461253
|
roots: array(RootSchema)
|
|
460472
461254
|
});
|
|
460473
461255
|
RootsListChangedNotificationSchema = NotificationSchema.extend({
|
|
460474
|
-
method:
|
|
461256
|
+
method: literal3("notifications/roots/list_changed"),
|
|
460475
461257
|
params: NotificationsParamsSchema.optional()
|
|
460476
461258
|
});
|
|
460477
461259
|
ClientRequestSchema = union([
|