@malloy-publisher/server 0.18.3 → 0.18.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. package/dist/app/api-doc.yaml +39 -8
  2. package/dist/app/assets/{EnvironmentPage-CsFUI8IX.js → EnvironmentPage-BxNqq3cN.js} +1 -1
  3. package/dist/app/assets/{HomePage-B_FVtnN-.js → HomePage-B4iN5rso.js} +1 -1
  4. package/dist/app/assets/{MainPage-wFF9nPEr.js → MainPage-DGiMH0eU.js} +1 -1
  5. package/dist/app/assets/{ModelPage-CxenqDcz.js → ModelPage-BJmyMnQo.js} +2 -2
  6. package/dist/app/assets/{PackagePage-dcF6vrvw.js → PackagePage-D2Pay_Xy.js} +1 -1
  7. package/dist/app/assets/{PackageSplatRoute-CASBZk0k.js → PackageSplatRoute-CQ7PxhkD.js} +2 -2
  8. package/dist/app/assets/{RenderedResult--fYcsY1h.es-DzOt5Lwv.js → RenderedResult-BEJ_GMaW.es-DS2oXAjc.js} +1 -1
  9. package/dist/app/assets/{RouteError-CUIolYwb.js → RouteError-BysHaT0t.js} +1 -1
  10. package/dist/app/assets/{ThemeEditorPage-DgU2YYq6.js → ThemeEditorPage-BFyTBbqA.js} +1 -1
  11. package/dist/app/assets/{ToggleButtonGroup-Dmr-hVlD.js → ToggleButtonGroup-eURRljZv.js} +1 -1
  12. package/dist/app/assets/{documentRoutes-Drv-WDwO.js → documentRoutes-DgTzGqfC.js} +1 -1
  13. package/dist/app/assets/{editPageMounted-C5yJiIVi.js → editPageMounted-CWBeAIbE.js} +2 -2
  14. package/dist/app/assets/{index-BSyL0zds.js → index-CCLHq9po.js} +15 -15
  15. package/dist/app/assets/{index-Dtw4eTxH.js → index-D4DhR2vg.js} +1 -1
  16. package/dist/app/assets/{index-BIoSdsU9.js → index-N8X9kVzc.js} +1 -1
  17. package/dist/app/assets/{index-DxF3kMLJ.js → index-We9Zzxmt.js} +1 -1
  18. package/dist/app/assets/{index.es-CX9m4CBD.js → index.es-D_O2KdNW.js} +1 -1
  19. package/dist/app/assets/usePackageLinkNavigate-CllycPZP.js +1 -0
  20. package/dist/app/assets/{usePackageRoute-wJGaZEiY.js → usePackageRoute-DEUbQLf3.js} +1 -1
  21. package/dist/app/index.html +1 -1
  22. package/dist/instrumentation.mjs +1 -1
  23. package/dist/package_load_worker.mjs +413 -272
  24. package/dist/server.mjs +946 -323
  25. package/package.json +2 -2
  26. package/dist/app/assets/usePackageLinkNavigate-qNjcXPcY.js +0 -1
@@ -20380,6 +20380,21 @@ function kindOf(def, base) {
20380
20380
  return "rename";
20381
20381
  return "query";
20382
20382
  }
20383
+ function detachedNode(def) {
20384
+ const d = def;
20385
+ if (!d || typeof d !== "object" || typeof d.sourceID !== "string") {
20386
+ return;
20387
+ }
20388
+ const base = baseEdgeOf(d, undefined);
20389
+ return {
20390
+ sourceID: d.sourceID,
20391
+ name: undefined,
20392
+ kind: kindOf(d, base),
20393
+ base,
20394
+ members: compositeMemberIds(d),
20395
+ def: d
20396
+ };
20397
+ }
20383
20398
  function sourceChain(struct, modelDef) {
20384
20399
  return SourceMap.of(modelDef).chainOf(struct);
20385
20400
  }
@@ -33991,6 +34006,9 @@ var init_served_copy_containment = __esm(() => {
33991
34006
  });
33992
34007
 
33993
34008
  // src/service/materialization/text/kept_ancestors.ts
34009
+ function nodeIn(map, sourceID, elsewhere) {
34010
+ return map.node(sourceID) ?? detachedNode(elsewhere?.(sourceID));
34011
+ }
33994
34012
  function plainRenamesOf(map, sourceID, url) {
33995
34013
  const out = [];
33996
34014
  const reached = new Set([sourceID]);
@@ -34040,15 +34058,15 @@ function locatedIn(def, url) {
34040
34058
  const location = def?.location;
34041
34059
  return location?.url === url && typeof location.range?.start?.line === "number" && typeof location.range?.end?.line === "number" ? location.range : undefined;
34042
34060
  }
34043
- function keptAncestorChain(map, sourceID, url) {
34061
+ function keptAncestorChain(map, sourceID, url, elsewhere) {
34044
34062
  const out = [];
34045
- let node = map.node(sourceID);
34063
+ let node = nodeIn(map, sourceID, elsewhere);
34046
34064
  let childURL = url;
34047
34065
  for (let hops = 0;node && hops < MAX_HOPS; hops++) {
34048
34066
  const base = node.base;
34049
34067
  if (!base || base.hop === "query" || base.sourceID === undefined)
34050
34068
  break;
34051
- const parent = map.node(base.sourceID);
34069
+ const parent = nodeIn(map, base.sourceID, elsewhere);
34052
34070
  const parentURL = declaringURLOf(parent?.def);
34053
34071
  const range = parentURL ? locatedIn(parent?.def, parentURL) : undefined;
34054
34072
  if (!parent || !parentURL || !range)
@@ -34065,17 +34083,29 @@ function keptAncestorChain(map, sourceID, url) {
34065
34083
  }
34066
34084
  return out;
34067
34085
  }
34068
- function keptAncestorChainOrDeclared(map, sourceID, url, fileText) {
34069
- const chain = keptAncestorChain(map, sourceID, url);
34070
- const node = map.node(sourceID);
34071
- if (chain.length > 0 || !node || node.base !== undefined)
34072
- return chain;
34073
- const base = declaredTableBase(node.def, url, map, fileText);
34074
- if (!base)
34075
- return chain;
34076
- return [base, ...keptAncestorChain(map, base.sourceID, base.url)];
34086
+ function keptAncestorChainOrDeclared(map, sourceID, url, fileText, elsewhere) {
34087
+ const out = [];
34088
+ const seen = new Set([sourceID]);
34089
+ let tail = { sourceID, url };
34090
+ for (let hops = 0;hops < MAX_HOPS; hops++) {
34091
+ const chain = keptAncestorChain(map, tail.sourceID, tail.url, elsewhere);
34092
+ out.push(...chain);
34093
+ tail = chain.at(-1) ?? tail;
34094
+ const node = nodeIn(map, tail.sourceID, elsewhere);
34095
+ if (!node || node.base !== undefined)
34096
+ break;
34097
+ const base = declaredTableBase(node.def, tail.url, fileText, (id) => nodeIn(map, id, elsewhere));
34098
+ for (const a of chain)
34099
+ seen.add(a.sourceID);
34100
+ if (!base || seen.has(base.sourceID))
34101
+ break;
34102
+ seen.add(base.sourceID);
34103
+ out.push(base);
34104
+ tail = base;
34105
+ }
34106
+ return out;
34077
34107
  }
34078
- function declaredTableBase(def, url, map, fileText) {
34108
+ function declaredTableBase(def, url, fileText, nodeOf) {
34079
34109
  const own = def;
34080
34110
  if (own?.type !== "table")
34081
34111
  return;
@@ -34086,8 +34116,8 @@ function declaredTableBase(def, url, map, fileText) {
34086
34116
  const name = declaredBaseName(text, range);
34087
34117
  if (name === undefined)
34088
34118
  return;
34089
- const parentID = [`${name}@${url}`, map.sourceIDOf(name)].find((id) => id !== undefined && map.node(id) !== undefined);
34090
- const parent = parentID ? map.node(parentID) : undefined;
34119
+ const parentID = declaredBaseID(name, url, text, nodeOf);
34120
+ const parent = parentID ? nodeOf(parentID) : undefined;
34091
34121
  const base = parent?.def;
34092
34122
  if (!parent || base?.type !== "table" || base.connection !== own.connection || base.tablePath !== own.tablePath) {
34093
34123
  return;
@@ -34103,6 +34133,16 @@ function declaredTableBase(def, url, map, fileText) {
34103
34133
  }
34104
34134
  return { sourceID: parent.sourceID, url: parentURL, range: parentRange };
34105
34135
  }
34136
+ function declaredBaseID(name, url, text, nodeOf) {
34137
+ const imports = topLevelImports(text, url);
34138
+ if (!imports)
34139
+ return;
34140
+ const found = [
34141
+ `${name}@${url}`,
34142
+ ...imports.filter((i) => i.whole).map((i) => `${name}@${i.resolved}`)
34143
+ ].filter((id) => nodeOf(id) !== undefined);
34144
+ return found.length === 1 ? found[0] : undefined;
34145
+ }
34106
34146
  function fieldList(def) {
34107
34147
  return Array.isArray(def.fields) ? def.fields : [];
34108
34148
  }
@@ -34298,6 +34338,7 @@ var MAX_HOPS = 64;
34298
34338
  var init_kept_ancestors = __esm(() => {
34299
34339
  init_declaration_text();
34300
34340
  init_malloy_lexer_core();
34341
+ init_source_map();
34301
34342
  init_table_plans();
34302
34343
  });
34303
34344
 
@@ -38303,6 +38344,21 @@ class ServedCopyServe {
38303
38344
  async loadQuery(queryString, givens, pinned = this.current()) {
38304
38345
  return this.answer(await this.ensureCompiled(pinned), queryString, givens, pinned);
38305
38346
  }
38347
+ async queriedSourceIDs(compiled, queryString) {
38348
+ if (!compiled.leftOutColumns?.size)
38349
+ return;
38350
+ try {
38351
+ const prepared = await this.host.authorPreparedQuery?.(queryString);
38352
+ if (prepared === undefined)
38353
+ return;
38354
+ const view = preparedQueryView(prepared);
38355
+ const modelDef = view.modelDef ?? this.host.modelDef();
38356
+ const struct = resolveStructRefSource(view.structRef, modelDef);
38357
+ return struct ? sourceIDsReadThrough(struct, modelDef) : undefined;
38358
+ } catch {
38359
+ return;
38360
+ }
38361
+ }
38306
38362
  async beginAttempt(compiled, queryString, givens) {
38307
38363
  if (!compiled.materializer || compiled.rerooted.length === 0) {
38308
38364
  const crossConnection = compiled.problems.some((p) => p.reason === "cross_connection_unbuilt");
@@ -38339,24 +38395,9 @@ class ServedCopyServe {
38339
38395
  if (zoned.size > 0 && readsMissingName(zoned, error, queryString)) {
38340
38396
  decline(ZONED_TRUNCATION_REASON, "served_copy_time_zone");
38341
38397
  }
38342
- const storedLeftOut = new Set([...compiled.leftOutColumns?.values() ?? []].flatMap((n) => [
38343
- ...n
38344
- ]));
38345
- if (storedLeftOut.size > 0 && readsMissingName(storedLeftOut, error, queryString)) {
38346
- const missing = new Set([
38347
- ...String(error instanceof Error ? error.message : error).matchAll(/'([^']+)' is not defined/g)
38348
- ].map((m) => m[1]));
38349
- const read = [...storedLeftOut].filter((n) => missing.has(n));
38350
- const named = read.length > 0 ? read : [...storedLeftOut];
38351
- const sourceIDs = new Set([...compiled.leftOutColumns ?? []].filter(([, names]) => names.some((n) => named.includes(n))).map(([sourceID]) => sourceID));
38352
- const tableIds = compiled.aliased.filter((b) => b.sourceIDs?.some((id) => sourceIDs.has(id))).map((b) => b.virtualHandle);
38353
- const why = [
38354
- ...new Set(named.flatMap((c) => {
38355
- const reasons = [...sourceIDs].map((id) => compiled.leftOutWhy?.get(id)?.get(c)).filter((w) => w !== undefined);
38356
- return reasons.length > 0 ? reasons : [noCastPhrase("a stored column")];
38357
- }))
38358
- ];
38359
- decline("the query reads a stored column the served copy leaves out of its table's type", "served_copy_column_left_out", `the stored table cannot answer with live's columns: ${why.join("; ")}`, tableIds);
38398
+ const leftOut = columnLeftOutDecline(compiled, error, queryString, await this.queriedSourceIDs(compiled, queryString));
38399
+ if (leftOut) {
38400
+ decline("the query reads a stored column the served copy leaves out of its table's type", "served_copy_column_left_out", leftOut.detail, leftOut.tableIds);
38360
38401
  }
38361
38402
  throw error;
38362
38403
  }
@@ -38784,8 +38825,8 @@ class ServedCopyServe {
38784
38825
  const plan = this.materializePlans[reroot.sourceID];
38785
38826
  if (!plan)
38786
38827
  return;
38787
- const confirmed = confirmedAncestors(fileText, reroot.url, reroot.range, keptAncestorChainOrDeclared(map, reroot.sourceID, reroot.url, fileText));
38788
- const needed = confirmed.some((a) => this.materializePlans[a.sourceID] !== undefined) || confirmed.some((a) => declaresBlocks(map.node(a.sourceID)?.def));
38828
+ const confirmed = confirmedAncestors(fileText, reroot.url, reroot.range, keptAncestorChainOrDeclared(map, reroot.sourceID, reroot.url, fileText, this.declarationOf));
38829
+ const needed = confirmed.some((a) => this.materializePlans[a.sourceID] !== undefined) || confirmed.some((a) => declaresBlocks(map.node(a.sourceID)?.def ?? this.declarationOf?.(a.sourceID)));
38789
38830
  if (!needed)
38790
38831
  return;
38791
38832
  return confirmed.flatMap((a) => a.runText ? [a.runText] : []).reverse().join(" ");
@@ -39638,6 +39679,66 @@ function leftOutPhrase(ref, field, storedType) {
39638
39679
  function leftOutPhraseOf(subject, c) {
39639
39680
  return leftOutPhrase(subject.columnRef(c.name), subject.fieldsByName.get(c.name), c.type);
39640
39681
  }
39682
+ function sourceIDsReadThrough(struct, modelDef) {
39683
+ const map = SourceMap.of(modelDef);
39684
+ const out = new Map;
39685
+ const walk = (def, path, depth) => {
39686
+ for (const id of map.chainOf(def)) {
39687
+ if (!out.has(id))
39688
+ out.set(id, path);
39689
+ }
39690
+ if (depth >= JOIN_DEPTH_LIMIT)
39691
+ return;
39692
+ const fields = def?.fields;
39693
+ if (!Array.isArray(fields))
39694
+ return;
39695
+ for (const f of fields) {
39696
+ if (f?.join === undefined)
39697
+ continue;
39698
+ const name = f.as ?? f.name;
39699
+ if (!name)
39700
+ continue;
39701
+ walk(f, path ? `${path}.${name}` : name, depth + 1);
39702
+ }
39703
+ };
39704
+ walk(struct, "", 0);
39705
+ return out;
39706
+ }
39707
+ function columnLeftOutDecline(compiled, error, queryString, readIDs) {
39708
+ const storedLeftOut = new Set([...compiled.leftOutColumns?.values() ?? []].flatMap((n) => [...n]));
39709
+ if (storedLeftOut.size === 0 || !readsMissingName(storedLeftOut, error, queryString)) {
39710
+ return;
39711
+ }
39712
+ const missing = new Set([
39713
+ ...String(error instanceof Error ? error.message : error).matchAll(/'([^']+)' is not defined/g)
39714
+ ].map((m) => m[1]));
39715
+ const read = [...storedLeftOut].filter((n) => missing.has(n));
39716
+ const named = read.length > 0 ? read : [...storedLeftOut];
39717
+ const leaving = [...compiled.leftOutColumns ?? []].filter(([, names]) => names.some((n) => named.includes(n))).map(([sourceID]) => sourceID);
39718
+ const scoped = readIDs ? leaving.filter((id) => readIDs.has(id)) : [];
39719
+ const sourceIDs = new Set(scoped.length > 0 ? scoped : leaving);
39720
+ const pathOf = (id) => scoped.length > 0 ? readIDs?.get(id) : "";
39721
+ const tableIds = compiled.aliased.filter((b) => b.sourceIDs?.some((id) => sourceIDs.has(id))).map((b) => b.virtualHandle);
39722
+ const why = [
39723
+ ...new Set(named.flatMap((c) => {
39724
+ const reasons = [...sourceIDs].flatMap((id) => {
39725
+ const phrase = compiled.leftOutWhy?.get(id)?.get(c);
39726
+ if (phrase === undefined)
39727
+ return [];
39728
+ const path = pathOf(id);
39729
+ const own = `column \`${c}\``;
39730
+ return [
39731
+ path && phrase.startsWith(own) ? `column \`${path}.${c}\`${phrase.slice(own.length)}` : phrase
39732
+ ];
39733
+ });
39734
+ return reasons.length > 0 ? reasons : [noCastPhrase("a stored column")];
39735
+ }))
39736
+ ];
39737
+ return {
39738
+ detail: `the stored table cannot answer with live's columns: ${why.join("; ")}`,
39739
+ tableIds
39740
+ };
39741
+ }
39641
39742
  function noCastPhrase(ref) {
39642
39743
  return `no cast reads ${ref} as declared`;
39643
39744
  }
@@ -40500,7 +40601,7 @@ function zonedTruncations(columns, def, fieldsByName, chainZone, restatesStageZo
40500
40601
  restated: []
40501
40602
  };
40502
40603
  }
40503
- var NOTHING_PINNED, NO_DESTINATIONS = () => new MalloyConfig3({ connections: {} }), PAIR_BLOCKS_DETAIL = "The table stores more than one inlined join_many, one block of rows each, and the query reads more than one of them (live aggregates each by its own key over their cross product, which no block holds), so it is answered without this table.", LEFT_OUT_JOIN_DETAIL = "The query uses a join to a source on another connection than the destination this table is stored in, so it is answered live.", MISSING_FIELD_CODES, SERVED_COPY_WARNING_CODE = "served-copy-not-served", DECLINED_LIMIT = 1000, knownRerootFailures, REROOT_FAILURE_TTL_MS, ESCAPED_FAILURE_RETRY_MS = 30000, REROOT_FAILURES_PER_CONFIG = 64, GATE_GRAFT_DECLINE, HIDDEN_COLUMN = "a hidden column";
40604
+ var NOTHING_PINNED, NO_DESTINATIONS = () => new MalloyConfig3({ connections: {} }), PAIR_BLOCKS_DETAIL = "The table stores more than one inlined join_many, one block of rows each, and the query reads more than one of them (live aggregates each by its own key over their cross product, which no block holds), so it is answered without this table.", LEFT_OUT_JOIN_DETAIL = "The query uses a join to a source on another connection than the destination this table is stored in, so it is answered live.", MISSING_FIELD_CODES, SERVED_COPY_WARNING_CODE = "served-copy-not-served", DECLINED_LIMIT = 1000, knownRerootFailures, REROOT_FAILURE_TTL_MS, ESCAPED_FAILURE_RETRY_MS = 30000, REROOT_FAILURES_PER_CONFIG = 64, GATE_GRAFT_DECLINE, HIDDEN_COLUMN = "a hidden column", JOIN_DEPTH_LIMIT = 8;
40504
40605
  var init_served_copy_serve = __esm(() => {
40505
40606
  init_ducklake_catalog_unavailable();
40506
40607
  init_served_copy_lanes();
@@ -40807,6 +40908,216 @@ var init_error_wire = __esm(() => {
40807
40908
  init_errors2();
40808
40909
  });
40809
40910
 
40911
+ // src/package_load/job_files.ts
40912
+ import {
40913
+ CacheManager,
40914
+ InMemoryModelCache
40915
+ } from "@malloydata/malloy";
40916
+ import { createHash as createHash3 } from "crypto";
40917
+ import * as path6 from "path";
40918
+ import { fileURLToPath as fileURLToPath5, pathToFileURL as pathToFileURL5 } from "url";
40919
+ function jobFiles(inner) {
40920
+ const texts = new Map;
40921
+ const stylesByUrl = new Map;
40922
+ const reads = new Map;
40923
+ const reader = {
40924
+ readURL: (url) => {
40925
+ const key = url.toString();
40926
+ let read = reads.get(key);
40927
+ if (!read) {
40928
+ read = (async () => {
40929
+ const contents = await inner.readURL(url);
40930
+ texts.set(key, contents);
40931
+ stylesByUrl.set(key, await dataStylesForFile(key, contents, inner));
40932
+ return contents;
40933
+ })();
40934
+ reads.set(key, read);
40935
+ read.catch(() => reads.delete(key));
40936
+ }
40937
+ return read;
40938
+ }
40939
+ };
40940
+ return {
40941
+ reader,
40942
+ texts,
40943
+ stylesByUrl,
40944
+ models: new Map,
40945
+ imported: new Set,
40946
+ stats: { stored: 0, reused: 0 }
40947
+ };
40948
+ }
40949
+ function urlKey(url) {
40950
+ try {
40951
+ return new URL(url).href;
40952
+ } catch {
40953
+ return url;
40954
+ }
40955
+ }
40956
+ function decodedUrl(url) {
40957
+ try {
40958
+ return decodeURI(url);
40959
+ } catch {
40960
+ return url;
40961
+ }
40962
+ }
40963
+ function modelFileTexts(files, modelUrl, dependencies) {
40964
+ const byPath = new Map;
40965
+ for (const url of [modelUrl, ...importReadOrder(dependencies)]) {
40966
+ const key = urlKey(url);
40967
+ const text = files.texts.get(key);
40968
+ if (text !== undefined && key.startsWith("file:")) {
40969
+ byPath.set(fileURLToPath5(key), text);
40970
+ }
40971
+ }
40972
+ return byPath;
40973
+ }
40974
+ function fileTextDigests(files) {
40975
+ const digests = {};
40976
+ for (const [url, text] of files.texts) {
40977
+ const key = urlKey(url);
40978
+ if (!key.startsWith("file:"))
40979
+ continue;
40980
+ digests[key] = createHash3("sha256").update(text).digest("hex");
40981
+ }
40982
+ return digests;
40983
+ }
40984
+ function modelReadKeys(modelUrl, dependencies) {
40985
+ return [modelUrl, ...importReadOrder(dependencies)].map(urlKey);
40986
+ }
40987
+ function dataStylesForModel(files, modelUrl, dependencies) {
40988
+ let styles = {};
40989
+ for (const url of [modelUrl, ...importReadOrder(dependencies)]) {
40990
+ styles = { ...styles, ...files.stylesByUrl.get(urlKey(url)) ?? {} };
40991
+ }
40992
+ return styles;
40993
+ }
40994
+ function importReadOrder(tree) {
40995
+ const order = [];
40996
+ const seen = new Set;
40997
+ const descended = new Set;
40998
+ const visit = (node) => {
40999
+ if (!node || typeof node !== "object")
41000
+ return;
41001
+ const entries = Object.entries(node);
41002
+ for (const [url] of entries) {
41003
+ if (!seen.has(url)) {
41004
+ seen.add(url);
41005
+ order.push(url);
41006
+ }
41007
+ }
41008
+ for (const [url, sub] of entries) {
41009
+ if (descended.has(url))
41010
+ continue;
41011
+ descended.add(url);
41012
+ visit(sub);
41013
+ }
41014
+ };
41015
+ visit(tree);
41016
+ return order;
41017
+ }
41018
+ async function compileOrder(packagePath, modelPaths, reader, imported = new Set) {
41019
+ const malloy = modelPaths.filter((p) => p.endsWith(MODEL_FILE_SUFFIX));
41020
+ const inPackage = new Set(malloy);
41021
+ const imports = new Map;
41022
+ for (const modelPath of malloy) {
41023
+ const url = pathToFileURL5(path6.join(packagePath, modelPath));
41024
+ let text = "";
41025
+ try {
41026
+ text = await reader.readURL(url);
41027
+ } catch {}
41028
+ const deps = [];
41029
+ for (const match of text.matchAll(IMPORT_RE)) {
41030
+ const target = match[1] ?? match[2];
41031
+ if (!target)
41032
+ continue;
41033
+ try {
41034
+ const resolved = new URL(target, url);
41035
+ if (resolved.protocol !== "file:")
41036
+ continue;
41037
+ const rel = path6.relative(packagePath, fileURLToPath5(resolved)).replace(/\\/g, "/");
41038
+ if (inPackage.has(rel)) {
41039
+ deps.push(rel);
41040
+ imported.add(urlKey(resolved.href));
41041
+ }
41042
+ } catch {}
41043
+ }
41044
+ imports.set(modelPath, deps);
41045
+ }
41046
+ const level = new Map;
41047
+ const visiting = new Set;
41048
+ const levelOf = (modelPath) => {
41049
+ const known = level.get(modelPath);
41050
+ if (known !== undefined)
41051
+ return known;
41052
+ if (visiting.has(modelPath))
41053
+ return 0;
41054
+ visiting.add(modelPath);
41055
+ let mine = 0;
41056
+ for (const dep of imports.get(modelPath) ?? []) {
41057
+ mine = Math.max(mine, levelOf(dep) + 1);
41058
+ }
41059
+ visiting.delete(modelPath);
41060
+ level.set(modelPath, mine);
41061
+ return mine;
41062
+ };
41063
+ const levels = [];
41064
+ const waitsOn = new Map;
41065
+ for (const modelPath of malloy) {
41066
+ const mine = levelOf(modelPath);
41067
+ (levels[mine] ??= []).push(modelPath);
41068
+ waitsOn.set(modelPath, (imports.get(modelPath) ?? []).filter((dep) => levelOf(dep) < mine));
41069
+ }
41070
+ const rest = modelPaths.filter((p) => !p.endsWith(MODEL_FILE_SUFFIX));
41071
+ for (const modelPath of rest)
41072
+ waitsOn.set(modelPath, []);
41073
+ return {
41074
+ waitsOn,
41075
+ levels: [
41076
+ ...levels.filter((l) => l !== undefined && l.length > 0),
41077
+ ...rest.length > 0 ? [rest] : []
41078
+ ]
41079
+ };
41080
+ }
41081
+ var sameUrl = (a, b) => a === b || urlKey(a) === urlKey(b), ModelCacheView, IMPORT_RE;
41082
+ var init_job_files = __esm(() => {
41083
+ init_constants();
41084
+ init_data_styles();
41085
+ ModelCacheView = class ModelCacheView extends CacheManager {
41086
+ files;
41087
+ ownUrl;
41088
+ constructor(files, ownUrl) {
41089
+ super(new InMemoryModelCache);
41090
+ this.files = files;
41091
+ this.ownUrl = ownUrl;
41092
+ }
41093
+ async getCachedModelDef(...[, url]) {
41094
+ if (sameUrl(url, this.ownUrl))
41095
+ return;
41096
+ const hit = this.files.models.get(url);
41097
+ if (!hit)
41098
+ return;
41099
+ this.files.stats.reused++;
41100
+ return {
41101
+ modelDef: structuredClone(hit.modelDef),
41102
+ invalidationKeys: { ...hit.invalidationKeys }
41103
+ };
41104
+ }
41105
+ async setCachedModelDef(...[url, cached]) {
41106
+ if (!this.files.imported.has(urlKey(url)))
41107
+ return false;
41108
+ if (sameUrl(url, this.ownUrl) && decodedUrl(url) !== url)
41109
+ return false;
41110
+ this.files.models.set(url, {
41111
+ modelDef: structuredClone(cached.modelDef),
41112
+ invalidationKeys: { ...cached.invalidationKeys }
41113
+ });
41114
+ this.files.stats.stored++;
41115
+ return true;
41116
+ }
41117
+ };
41118
+ IMPORT_RE = /^\s*import\s+(?:\{[^}]*\}\s+from\s+)?(?:"([^"]+)"|'([^']+)')/gim;
41119
+ });
41120
+
40810
41121
  // src/service/translator_error.ts
40811
41122
  import { MalloyError as MalloyError6 } from "@malloydata/malloy";
40812
41123
  function translatorInvariantProblem(error) {
@@ -40947,12 +41258,12 @@ function compareText(a, b) {
40947
41258
  }
40948
41259
 
40949
41260
  // src/service/package_revision.ts
40950
- import { createHash as createHash3, randomUUID } from "crypto";
41261
+ import { createHash as createHash4, randomUUID } from "crypto";
40951
41262
  import fs5 from "fs";
40952
41263
  import path7 from "path";
40953
41264
  import { pathToFileURL as pathToFileURL6 } from "url";
40954
41265
  function computeSourceContentSha(packagePath, contentPaths, extra, contentShas) {
40955
- const hash = createHash3("sha256");
41266
+ const hash = createHash4("sha256");
40956
41267
  for (const relativePath of [...contentPaths].sort()) {
40957
41268
  hash.update(relativePath);
40958
41269
  hash.update("\x00");
@@ -40986,7 +41297,7 @@ function boundedManifestValue(value) {
40986
41297
  return "[unreadable: too deep or too large]";
40987
41298
  }
40988
41299
  function canonicalSha(value) {
40989
- return createHash3("sha256").update(canonicalJson(value)).digest("hex");
41300
+ return createHash4("sha256").update(canonicalJson(value)).digest("hex");
40990
41301
  }
40991
41302
  function mintServedRevision() {
40992
41303
  return randomUUID();
@@ -42065,9 +42376,9 @@ var init_dim_index_discovery = __esm(() => {
42065
42376
  });
42066
42377
 
42067
42378
  // src/service/entities/dim_index_entity_id.ts
42068
- import { createHash as createHash4 } from "crypto";
42379
+ import { createHash as createHash5 } from "crypto";
42069
42380
  function computeSqlFingerprint(compiledSql) {
42070
- return createHash4("sha256").update(compiledSql, "utf8").digest("hex");
42381
+ return createHash5("sha256").update(compiledSql, "utf8").digest("hex");
42071
42382
  }
42072
42383
  function buildFingerprintQuery(sourceName, dimensionPath, requiredFilterDimensions, gateDimensions = []) {
42073
42384
  const sortedFilters = [...requiredFilterDimensions].sort();
@@ -42087,6 +42398,10 @@ var init_dim_index_entity_id = __esm(() => {
42087
42398
  // src/service/entities/source_extraction.ts
42088
42399
  import path8 from "path";
42089
42400
  import { fileURLToPath as fileURLToPath7 } from "url";
42401
+ import {
42402
+ isJoined as isJoined5,
42403
+ isJoinedSource
42404
+ } from "@malloydata/malloy";
42090
42405
  function buildSourceToModelPathMap(explores, relpath, packageRoot) {
42091
42406
  const sourceToModelPath = new Map;
42092
42407
  for (const explore of explores) {
@@ -42132,6 +42447,17 @@ function parseJoinCode(joinCode, fieldName, sourceToModelPath) {
42132
42447
  is_nested_index: isNestedIndex
42133
42448
  };
42134
42449
  }
42450
+ function joinMetadataOf(field, docString, sourceToModelPath) {
42451
+ const structDef = field.structDef;
42452
+ const metadata = isJoinedSource(structDef) ? parseJoinCode(extractCodeFromEntity(field, docString), field.name, sourceToModelPath) : {
42453
+ original_source_name: null,
42454
+ original_source_path: null,
42455
+ is_nested_index: true
42456
+ };
42457
+ if (isJoined5(structDef))
42458
+ metadata.relationship = structDef.join;
42459
+ return metadata;
42460
+ }
42135
42461
  function descendsIntoJoin(joinMetadata, rootSourceName, topLevelExploreNames, boundary) {
42136
42462
  const targetName = joinMetadata.original_source_name;
42137
42463
  const targetIsAtTopLevel = targetName != null && topLevelExploreNames.has(targetName);
@@ -42142,7 +42468,7 @@ function descendsIntoJoin(joinMetadata, rootSourceName, topLevelExploreNames, bo
42142
42468
  function joinDescent(explores, relativePath, packageRoot, docString, boundary) {
42143
42469
  const sourceToModelPath = buildSourceToModelPathMap(explores, relativePath, packageRoot);
42144
42470
  const topLevelExploreNames = new Set(explores.map((e) => e.name));
42145
- return (join, parentSourceName) => descendsIntoJoin(parseJoinCode(extractCodeFromEntity(join, docString), join.name, sourceToModelPath), parentSourceName.split(".")[0], topLevelExploreNames, boundary);
42471
+ return (join, parentSourceName) => descendsIntoJoin(joinMetadataOf(join, docString, sourceToModelPath), parentSourceName.split(".")[0], topLevelExploreNames, boundary);
42146
42472
  }
42147
42473
  function getEntitiesFromExplore(explore, docString, relativePath, parentPath, sourceToModelPath, dimIndexFingerprints, topLevelExploreNames, boundary, guard) {
42148
42474
  const entities = [];
@@ -42154,8 +42480,7 @@ function getEntitiesFromExplore(explore, docString, relativePath, parentPath, so
42154
42480
  }
42155
42481
  let joinMetadata = null;
42156
42482
  if (field.isExploreField()) {
42157
- const joinCode = extractCodeFromEntity(field, docString);
42158
- joinMetadata = parseJoinCode(joinCode, field.name, sourceToModelPath);
42483
+ joinMetadata = joinMetadataOf(field, docString, sourceToModelPath);
42159
42484
  const descent = descendsIntoJoin(joinMetadata, rootSourceName, topLevelExploreNames, boundary);
42160
42485
  if (descent !== false) {
42161
42486
  const nestedEntities = getEntitiesFromExplore(field, docString, relativePath, sourceName, sourceToModelPath, dimIndexFingerprints, topLevelExploreNames, boundary, descent === true ? guard : guardDescent(guard, rootSourceName, descent.unlessQueryable));
@@ -42191,8 +42516,7 @@ function planJoinAuthorizeMetadata(explore, docString, relativePath, parentPath,
42191
42516
  }
42192
42517
  if (getAccessModifier(field) !== "public" /* Public */)
42193
42518
  continue;
42194
- const joinCode = extractCodeFromEntity(field, docString);
42195
- const joinMetadata = parseJoinCode(joinCode, field.name, sourceToModelPath);
42519
+ const joinMetadata = joinMetadataOf(field, docString, sourceToModelPath);
42196
42520
  const targetName = joinMetadata.original_source_name;
42197
42521
  const descent = descendsIntoJoin(joinMetadata, rootSourceName, topLevelExploreNames, boundary);
42198
42522
  const joinedExplore = field;
@@ -42841,7 +43165,7 @@ var init_package_relative_text = __esm(() => {
42841
43165
  });
42842
43166
 
42843
43167
  // src/service/package_retrieval_settings.ts
42844
- import { createHash as createHash5 } from "crypto";
43168
+ import { createHash as createHash6 } from "crypto";
42845
43169
  import * as fs8 from "fs";
42846
43170
  import * as path10 from "path";
42847
43171
  import { pathToFileURL as pathToFileURL9 } from "url";
@@ -43081,7 +43405,7 @@ async function readPromptFile(packageRoot, key, rel) {
43081
43405
  return {
43082
43406
  path: rel,
43083
43407
  text,
43084
- hash: createHash5("sha256").update(text).digest("hex")
43408
+ hash: createHash6("sha256").update(text).digest("hex")
43085
43409
  };
43086
43410
  }
43087
43411
  async function readPackageRetrieval(packageRoot, raw) {
@@ -43382,15 +43706,26 @@ function errorCodeOf(err) {
43382
43706
  }
43383
43707
  return "Error";
43384
43708
  }
43385
- var CODE_PATTERN;
43709
+ function runtimeErrorTextOf(err) {
43710
+ for (const e of causeChain(err)) {
43711
+ const { code } = e;
43712
+ if (typeof code === "number" && RUNTIME_ERROR_NAMES.has(e.name) && typeof e.message === "string" && RUNTIME_TEXT.test(e.message)) {
43713
+ return e.message;
43714
+ }
43715
+ }
43716
+ return;
43717
+ }
43718
+ var CODE_PATTERN, RUNTIME_ERROR_NAMES, RUNTIME_TEXT;
43386
43719
  var init_error_code = __esm(() => {
43387
43720
  init_driver_errors();
43388
43721
  init_errors2();
43389
43722
  CODE_PATTERN = /^[A-Za-z0-9][A-Za-z0-9_.:-]{0,63}$/;
43723
+ RUNTIME_ERROR_NAMES = new Set(["TimeoutError", "AbortError"]);
43724
+ RUNTIME_TEXT = /^[A-Za-z][A-Za-z ,.'-]{0,119}$/;
43390
43725
  });
43391
43726
 
43392
43727
  // src/service/materialization/domain/table_name.ts
43393
- import { createHash as createHash6 } from "crypto";
43728
+ import { createHash as createHash7 } from "crypto";
43394
43729
  function leafBudget(dialect, inDestination) {
43395
43730
  if (inDestination)
43396
43731
  return DESTINATION_LEAF_BUDGET;
@@ -43494,7 +43829,7 @@ function fitPrefix(prefix, room) {
43494
43829
  }
43495
43830
  function readableTableName(args) {
43496
43831
  const { identity } = args;
43497
- const hash = createHash6("sha256").update(JSON.stringify([
43832
+ const hash = createHash7("sha256").update(JSON.stringify([
43498
43833
  "publisher-table/1",
43499
43834
  identity.environmentName,
43500
43835
  identity.packageName,
@@ -47237,7 +47572,7 @@ var init_preaggregation_classifier = __esm(() => {
47237
47572
  import {
47238
47573
  expressionIsAggregate,
47239
47574
  expressionIsAnalytic,
47240
- isJoined as isJoined5
47575
+ isJoined as isJoined6
47241
47576
  } from "@malloydata/malloy";
47242
47577
  function isAccessRestricted(f) {
47243
47578
  return f.accessModifier != null && f.accessModifier !== "public";
@@ -47249,7 +47584,7 @@ function isView(f) {
47249
47584
  return f.type === "turtle";
47250
47585
  }
47251
47586
  function isFanoutJoin(f) {
47252
- return isJoined5(f) && f.join !== "one";
47587
+ return isJoined6(f) && f.join !== "one";
47253
47588
  }
47254
47589
  function hasFanoutJoin(source) {
47255
47590
  return (source.fields ?? []).some((f) => isFanoutJoin(f));
@@ -47258,7 +47593,7 @@ function isMeasure(f) {
47258
47593
  return expressionIsAggregate(f.expressionType) && !expressionIsAnalytic(f.expressionType);
47259
47594
  }
47260
47595
  function isGroupableDimension(f) {
47261
- if (isJoined5(f) || isView(f))
47596
+ if (isJoined6(f) || isView(f))
47262
47597
  return false;
47263
47598
  if (f.expressionType === undefined)
47264
47599
  return true;
@@ -47278,7 +47613,7 @@ function validateGrainDimension(sourceName, measure, source, grainDimension) {
47278
47613
  if (!field) {
47279
47614
  return violation("unknown_grain_dimension", `Measure \`${measure}\` declares \`#@ preaggregate\` at a grain naming \`${grainDimension}\`, but \`${head}\` is not a field of \`${sourceName}\`. Use a dimension that exists on the source; a rollup can only group by the source's own dimensions.`);
47280
47615
  }
47281
- if (isJoined5(field)) {
47616
+ if (isJoined6(field)) {
47282
47617
  return violation("grain_path_through_join", `Measure \`${measure}\` declares a grain of \`${grainDimension}\`, which reaches through the join \`${head}\`. Pre-aggregating across a join is not supported in this version; copy the value into a dimension on \`${sourceName}\` and group by that instead.`);
47283
47618
  }
47284
47619
  if (parts.length > 1) {
@@ -47353,7 +47688,7 @@ function validateSourcePreaggregation(sourceName, source) {
47353
47688
  }
47354
47689
  function fieldViolations(sourceName, source, field, declaration, grains, violations) {
47355
47690
  const name = fieldName4(field);
47356
- if (isJoined5(field)) {
47691
+ if (isJoined6(field)) {
47357
47692
  violations.push({
47358
47693
  code: "misplaced_on_join",
47359
47694
  sourceName,
@@ -48413,7 +48748,7 @@ function rollupLabel(plan) {
48413
48748
  }
48414
48749
 
48415
48750
  // src/service/materialization/plan/rollup_plan.ts
48416
- import { createHash as createHash7 } from "node:crypto";
48751
+ import { createHash as createHash8 } from "node:crypto";
48417
48752
  import { Annotations as Annotations8 } from "@malloydata/malloy";
48418
48753
  function isRollupRoute(route) {
48419
48754
  return route === ROLLUP_ROUTE || route === ROLLUP_ALIAS_ROUTE;
@@ -48546,7 +48881,7 @@ function byCodepoint2(a, b) {
48546
48881
  return a < b ? -1 : a > b ? 1 : 0;
48547
48882
  }
48548
48883
  function digest(parts) {
48549
- return createHash7("sha256").update(parts.join("\x00")).digest("hex").slice(0, 8);
48884
+ return createHash8("sha256").update(parts.join("\x00")).digest("hex").slice(0, 8);
48550
48885
  }
48551
48886
  function rollupName(baseDeclaredName, packageRelativeSourceID, grain, placement) {
48552
48887
  const slug = grain.join("_").replace(/[^A-Za-z0-9_]/g, "_");
@@ -50576,13 +50911,13 @@ var init_pair_reroot = __esm(() => {
50576
50911
  });
50577
50912
 
50578
50913
  // src/service/materialization/plan/materialize_plan.ts
50579
- import { createHash as createHash8 } from "crypto";
50914
+ import { createHash as createHash9 } from "crypto";
50580
50915
  import { Annotations as Annotations9 } from "@malloydata/malloy";
50581
50916
  function materializeTableName(sourceName) {
50582
50917
  if (PLAIN_TABLE_NAME.test(sourceName))
50583
50918
  return sourceName;
50584
50919
  const folded = sourceName.replace(/[^A-Za-z0-9_-]+/g, "_").replace(/^_+|_+$/g, "");
50585
- const hash = createHash8("sha256").update(sourceName).digest("hex");
50920
+ const hash = createHash9("sha256").update(sourceName).digest("hex");
50586
50921
  return `${folded || "source"}_${hash.slice(0, 8)}`;
50587
50922
  }
50588
50923
  function readMaterializeDeclaration(def, contents = {}) {
@@ -56943,13 +57278,14 @@ async function collectGeneratedTables(parts, args) {
56943
57278
  parts.modelGateLines.nameProblems.push(...persistNameProblems(text, modelPath));
56944
57279
  }
56945
57280
  }
57281
+ const materializeOn = getMaterializeEnabled();
56946
57282
  collectPersistQueryFindings(parts, {
56947
57283
  modelPath,
56948
57284
  packagePath,
56949
57285
  malloyModel,
56950
- notBuilt: !getMaterializeEnabled()
57286
+ notBuilt: !materializeOn
56951
57287
  });
56952
- if (!getMaterializeEnabled()) {
57288
+ if (!materializeOn) {
56953
57289
  collectPersistViewFindingsSwitchedOff(parts, {
56954
57290
  modelPath,
56955
57291
  packagePath,
@@ -56957,7 +57293,7 @@ async function collectGeneratedTables(parts, args) {
56957
57293
  });
56958
57294
  }
56959
57295
  let materialized;
56960
- if (getMaterializeEnabled()) {
57296
+ if (materializeOn) {
56961
57297
  materialized = await collectGeneratedMaterialize(parts, {
56962
57298
  modelPath,
56963
57299
  packagePath,
@@ -57074,7 +57410,7 @@ function reportPersistLineFindings(parts, targets, planned, args) {
57074
57410
  route: "@",
57075
57411
  tier: "malformed",
57076
57412
  code: "persist-not-materializable",
57077
- message: `#@ persist source "${name}" is not a source Malloy can ` + `materialize: only a query or aggregate source builds, and a ` + `filtered pass-through, a table with only added fields, or an ` + `unbound parameterized source does not. Persist a query source ` + `over it, invoke a parameterized source with a bound argument, or ` + `remove the annotation`,
57413
+ message: `#@ persist source "${name}" is not a source Malloy can ` + `materialize: only a query or aggregate source builds, and a ` + `filtered pass-through, a table with only added fields, or an ` + `unbound parameterized source does not. ` + (getMaterializeEnabled() ? `Mark a table-shaped source \`#(materialize)\` instead, ` + `which stores a table-shaped source as well as a ` + `query-shaped one; or persist a query source over it, ` : `Persist a query source over it, `) + `invoke a parameterized source with a bound argument, or ` + `remove the annotation`,
57078
57414
  subject: name,
57079
57415
  model: modelPath
57080
57416
  });
@@ -57822,6 +58158,16 @@ init_data_styles();
57822
58158
  init_overlay_key();
57823
58159
  init_errors2();
57824
58160
  init_error_wire();
58161
+ init_job_files();
58162
+ init_translator_error();
58163
+ init_model_load_checks();
58164
+ init_model_info();
58165
+ init_model_notebook_cell();
58166
+ init_package_revision();
58167
+ init_package_manifest();
58168
+ init_plan();
58169
+ init_package_retrieval_settings();
58170
+ init_utils();
57825
58171
  import {
57826
58172
  contextOverlay,
57827
58173
  MalloyConfig as MalloyConfig4,
@@ -57830,216 +58176,10 @@ import {
57830
58176
  import * as fs10 from "fs";
57831
58177
  import * as path20 from "path";
57832
58178
  import { AsyncLocalStorage as AsyncLocalStorage3 } from "node:async_hooks";
57833
- import { createHash as createHash9 } from "node:crypto";
58179
+ import { createHash as createHash10 } from "node:crypto";
57834
58180
  import { parentPort, threadId, workerData as workerData2 } from "node:worker_threads";
57835
58181
  import { fileURLToPath as fileURLToPath12, pathToFileURL as pathToFileURL17 } from "url";
57836
58182
 
57837
- // src/package_load/job_files.ts
57838
- init_constants();
57839
- init_data_styles();
57840
- import {
57841
- CacheManager,
57842
- InMemoryModelCache
57843
- } from "@malloydata/malloy";
57844
- import * as path6 from "path";
57845
- import { fileURLToPath as fileURLToPath5, pathToFileURL as pathToFileURL5 } from "url";
57846
- function jobFiles(inner) {
57847
- const texts = new Map;
57848
- const stylesByUrl = new Map;
57849
- const reads = new Map;
57850
- const reader = {
57851
- readURL: (url) => {
57852
- const key = url.toString();
57853
- let read = reads.get(key);
57854
- if (!read) {
57855
- read = (async () => {
57856
- const contents = await inner.readURL(url);
57857
- texts.set(key, contents);
57858
- stylesByUrl.set(key, await dataStylesForFile(key, contents, inner));
57859
- return contents;
57860
- })();
57861
- reads.set(key, read);
57862
- read.catch(() => reads.delete(key));
57863
- }
57864
- return read;
57865
- }
57866
- };
57867
- return {
57868
- reader,
57869
- texts,
57870
- stylesByUrl,
57871
- models: new Map,
57872
- imported: new Set,
57873
- stats: { stored: 0, reused: 0 }
57874
- };
57875
- }
57876
- function urlKey(url) {
57877
- try {
57878
- return new URL(url).href;
57879
- } catch {
57880
- return url;
57881
- }
57882
- }
57883
- var sameUrl = (a, b) => a === b || urlKey(a) === urlKey(b);
57884
- function decodedUrl(url) {
57885
- try {
57886
- return decodeURI(url);
57887
- } catch {
57888
- return url;
57889
- }
57890
- }
57891
-
57892
- class ModelCacheView extends CacheManager {
57893
- files;
57894
- ownUrl;
57895
- constructor(files, ownUrl) {
57896
- super(new InMemoryModelCache);
57897
- this.files = files;
57898
- this.ownUrl = ownUrl;
57899
- }
57900
- async getCachedModelDef(...[, url]) {
57901
- if (sameUrl(url, this.ownUrl))
57902
- return;
57903
- const hit = this.files.models.get(url);
57904
- if (!hit)
57905
- return;
57906
- this.files.stats.reused++;
57907
- return {
57908
- modelDef: structuredClone(hit.modelDef),
57909
- invalidationKeys: { ...hit.invalidationKeys }
57910
- };
57911
- }
57912
- async setCachedModelDef(...[url, cached]) {
57913
- if (!this.files.imported.has(urlKey(url)))
57914
- return false;
57915
- if (sameUrl(url, this.ownUrl) && decodedUrl(url) !== url)
57916
- return false;
57917
- this.files.models.set(url, {
57918
- modelDef: structuredClone(cached.modelDef),
57919
- invalidationKeys: { ...cached.invalidationKeys }
57920
- });
57921
- this.files.stats.stored++;
57922
- return true;
57923
- }
57924
- }
57925
- function modelFileTexts(files, modelUrl, dependencies) {
57926
- const byPath = new Map;
57927
- for (const url of [modelUrl, ...importReadOrder(dependencies)]) {
57928
- const key = urlKey(url);
57929
- const text = files.texts.get(key);
57930
- if (text !== undefined && key.startsWith("file:")) {
57931
- byPath.set(fileURLToPath5(key), text);
57932
- }
57933
- }
57934
- return byPath;
57935
- }
57936
- function dataStylesForModel(files, modelUrl, dependencies) {
57937
- let styles = {};
57938
- for (const url of [modelUrl, ...importReadOrder(dependencies)]) {
57939
- styles = { ...styles, ...files.stylesByUrl.get(urlKey(url)) ?? {} };
57940
- }
57941
- return styles;
57942
- }
57943
- function importReadOrder(tree) {
57944
- const order = [];
57945
- const seen = new Set;
57946
- const descended = new Set;
57947
- const visit = (node) => {
57948
- if (!node || typeof node !== "object")
57949
- return;
57950
- const entries = Object.entries(node);
57951
- for (const [url] of entries) {
57952
- if (!seen.has(url)) {
57953
- seen.add(url);
57954
- order.push(url);
57955
- }
57956
- }
57957
- for (const [url, sub] of entries) {
57958
- if (descended.has(url))
57959
- continue;
57960
- descended.add(url);
57961
- visit(sub);
57962
- }
57963
- };
57964
- visit(tree);
57965
- return order;
57966
- }
57967
- var IMPORT_RE = /^\s*import\s+(?:\{[^}]*\}\s+from\s+)?(?:"([^"]+)"|'([^']+)')/gim;
57968
- async function compileOrder(packagePath, modelPaths, reader, imported = new Set) {
57969
- const malloy = modelPaths.filter((p) => p.endsWith(MODEL_FILE_SUFFIX));
57970
- const inPackage = new Set(malloy);
57971
- const imports = new Map;
57972
- for (const modelPath of malloy) {
57973
- const url = pathToFileURL5(path6.join(packagePath, modelPath));
57974
- let text = "";
57975
- try {
57976
- text = await reader.readURL(url);
57977
- } catch {}
57978
- const deps = [];
57979
- for (const match of text.matchAll(IMPORT_RE)) {
57980
- const target = match[1] ?? match[2];
57981
- if (!target)
57982
- continue;
57983
- try {
57984
- const resolved = new URL(target, url);
57985
- if (resolved.protocol !== "file:")
57986
- continue;
57987
- const rel = path6.relative(packagePath, fileURLToPath5(resolved)).replace(/\\/g, "/");
57988
- if (inPackage.has(rel)) {
57989
- deps.push(rel);
57990
- imported.add(urlKey(resolved.href));
57991
- }
57992
- } catch {}
57993
- }
57994
- imports.set(modelPath, deps);
57995
- }
57996
- const level = new Map;
57997
- const visiting = new Set;
57998
- const levelOf = (modelPath) => {
57999
- const known = level.get(modelPath);
58000
- if (known !== undefined)
58001
- return known;
58002
- if (visiting.has(modelPath))
58003
- return 0;
58004
- visiting.add(modelPath);
58005
- let mine = 0;
58006
- for (const dep of imports.get(modelPath) ?? []) {
58007
- mine = Math.max(mine, levelOf(dep) + 1);
58008
- }
58009
- visiting.delete(modelPath);
58010
- level.set(modelPath, mine);
58011
- return mine;
58012
- };
58013
- const levels = [];
58014
- const waitsOn = new Map;
58015
- for (const modelPath of malloy) {
58016
- const mine = levelOf(modelPath);
58017
- (levels[mine] ??= []).push(modelPath);
58018
- waitsOn.set(modelPath, (imports.get(modelPath) ?? []).filter((dep) => levelOf(dep) < mine));
58019
- }
58020
- const rest = modelPaths.filter((p) => !p.endsWith(MODEL_FILE_SUFFIX));
58021
- for (const modelPath of rest)
58022
- waitsOn.set(modelPath, []);
58023
- return {
58024
- waitsOn,
58025
- levels: [
58026
- ...levels.filter((l) => l !== undefined && l.length > 0),
58027
- ...rest.length > 0 ? [rest] : []
58028
- ]
58029
- };
58030
- }
58031
-
58032
- // src/package_load/package_load_worker.ts
58033
- init_translator_error();
58034
- init_model_load_checks();
58035
- init_model_info();
58036
- init_model_notebook_cell();
58037
- init_package_revision();
58038
- init_package_manifest();
58039
- init_plan();
58040
- init_package_retrieval_settings();
58041
- init_utils();
58042
-
58043
58183
  // src/package_load/rpc_wait_accountant.ts
58044
58184
  class RpcWaitAccountant {
58045
58185
  now;
@@ -58796,7 +58936,7 @@ var REFERENCE_ID = /reference_id = \\"[0-9a-f-]{36}\\"/g;
58796
58936
  function digestRenderTagResults(results) {
58797
58937
  try {
58798
58938
  const json = JSON.stringify(results).replace(REFERENCE_ID, "reference_id = \\\"\\\"");
58799
- return createHash9("sha256").update(json).digest("hex");
58939
+ return createHash10("sha256").update(json).digest("hex");
58800
58940
  } catch {
58801
58941
  return;
58802
58942
  }
@@ -58992,6 +59132,7 @@ async function loadPackage(job) {
58992
59132
  models,
58993
59133
  replacementMatchedExisting,
58994
59134
  ...refresh ? { refreshedSchemaKeys: [...refresh.refetched] } : {},
59135
+ fileDigests: fileTextDigests(files),
58995
59136
  loadDurationMs: loadEnd - loadStart,
58996
59137
  timings: {
58997
59138
  compileDurationMs: Math.max(0, compileEnd - compileRegionStart - schemaFetchDurationMs),