@malloydata/render 0.0.425 → 0.0.426
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/module/index.mjs +19 -16
- package/dist/module/index.umd.js +2 -2
- package/package.json +5 -5
package/dist/module/index.mjs
CHANGED
|
@@ -83398,7 +83398,7 @@ function Ij() {
|
|
|
83398
83398
|
}
|
|
83399
83399
|
var X1 = {}, SA = {}, Hae;
|
|
83400
83400
|
function o9e() {
|
|
83401
|
-
return Hae || (Hae = 1, Object.defineProperty(SA, "__esModule", { value: !0 }), SA.MALLOY_VERSION = void 0, SA.MALLOY_VERSION = "0.0.
|
|
83401
|
+
return Hae || (Hae = 1, Object.defineProperty(SA, "__esModule", { value: !0 }), SA.MALLOY_VERSION = void 0, SA.MALLOY_VERSION = "0.0.426"), SA;
|
|
83402
83402
|
}
|
|
83403
83403
|
var Vae;
|
|
83404
83404
|
function $1e() {
|
|
@@ -83648,7 +83648,9 @@ ${q}`, I);
|
|
|
83648
83648
|
E = await g.lookupConnection(_);
|
|
83649
83649
|
}
|
|
83650
83650
|
if (y) {
|
|
83651
|
-
const _ = await E.runSQL(y.selectStr
|
|
83651
|
+
const _ = await E.runSQL(y.selectStr, {
|
|
83652
|
+
queryMetadata: v == null ? void 0 : v.queryMetadata
|
|
83653
|
+
});
|
|
83652
83654
|
return new c.Result({
|
|
83653
83655
|
structs: [y],
|
|
83654
83656
|
sql: y.selectStr,
|
|
@@ -84191,23 +84193,24 @@ function a9e() {
|
|
|
84191
84193
|
* or loading further related objects.
|
|
84192
84194
|
*/
|
|
84193
84195
|
loadQuery(_, b) {
|
|
84194
|
-
const {
|
|
84196
|
+
const { importBaseURL: C, testEnvironment: R, refreshSchemaCache: A, noThrowOnError: w, restrictedMode: T, method: O, ...F } = b ?? {}, N = {
|
|
84197
|
+
...this.compileQueryOptions,
|
|
84198
|
+
...F
|
|
84199
|
+
};
|
|
84195
84200
|
return this.makeQueryMaterializer(async () => {
|
|
84196
|
-
const
|
|
84197
|
-
this.runtime.isTestRuntime && (b === void 0 ? b = { testEnvironment: !0 } : b = { ...b, testEnvironment: !0 });
|
|
84198
|
-
const T = _ instanceof URL ? { url: _ } : { source: _ }, O = await this.getModel();
|
|
84201
|
+
const $ = _ instanceof URL ? { url: _ } : { source: _ };
|
|
84199
84202
|
return (await a.Malloy.compile({
|
|
84200
|
-
|
|
84201
|
-
urlReader:
|
|
84202
|
-
connections:
|
|
84203
|
-
model:
|
|
84204
|
-
refreshSchemaCache:
|
|
84205
|
-
noThrowOnError:
|
|
84206
|
-
importBaseURL:
|
|
84207
|
-
testEnvironment:
|
|
84208
|
-
...
|
|
84203
|
+
...$,
|
|
84204
|
+
urlReader: this.runtime.urlReader,
|
|
84205
|
+
connections: this.runtime.connections,
|
|
84206
|
+
model: await this.getModel(),
|
|
84207
|
+
refreshSchemaCache: A,
|
|
84208
|
+
noThrowOnError: w,
|
|
84209
|
+
importBaseURL: C,
|
|
84210
|
+
testEnvironment: R || this.runtime.isTestRuntime,
|
|
84211
|
+
...N
|
|
84209
84212
|
})).preparedQuery;
|
|
84210
|
-
});
|
|
84213
|
+
}, N);
|
|
84211
84214
|
}
|
|
84212
84215
|
/**
|
|
84213
84216
|
* Load a Malloy query whose text comes from an untrusted source — an
|
package/dist/module/index.umd.js
CHANGED
|
@@ -1380,8 +1380,8 @@ ${fe}`:z=fe}return z}childRequest(z){var J;const oe=decodeURI(new URL(z,this.sou
|
|
|
1380
1380
|
`)}}this.stream.write(`
|
|
1381
1381
|
]
|
|
1382
1382
|
`),this.stream.close()}}yd.JSONWriter=n;class r extends t{constructor(){super(...arguments),this.columnSeparator=",",this.rowSeparator=`
|
|
1383
|
-
`,this.quoteCharacter='"',this.includeHeader=!0,this.emptyCell=""}escape(s){const o=s.includes(this.quoteCharacter),a=s.includes(this.columnSeparator),u=s.includes(this.rowSeparator),c=a||o||u;return o&&(s=s.replace(new RegExp(this.quoteCharacter,"g"),this.quoteCharacter+this.quoteCharacter)),c&&(s=this.quoteCharacter+s+this.quoteCharacter),s}stringify(s){return s===null?this.emptyCell:s instanceof Date?s.toISOString():typeof s=="boolean"||typeof s=="number"?JSON.stringify(s):typeof s=="bigint"?s.toString():`${s}`}getColWeight(s){let o=s;Array.isArray(s)&&(o=s[0]);let a=0;for(const u in o){a=a+1;const c=o[u];if((0,e.isCompoundArrayData)(c)){const l=this.getColWeight(c)-1;a=a+l}}return a}getHeaderRow(s){const o=[];let a=0;for(const u in s){o.push(this.escape(u));const c=s[u];if(a++,(0,e.isCompoundArrayData)(c)){const l=this.getColWeight(c)-1;a=a+l;for(let f=0;f<l;f++)o.push(this.emptyCell)}}return{rows:[o.join(this.columnSeparator)],length:1,width:a}}mergeMatrices(s){const o=Math.max(...s.map(c=>c.length)),a=s.reduce((c,l)=>c+l.width,0),u=[];for(let c=0;c<o;c++){const l=[];for(const f of s)if(c<f.length)l.push(f.rows[c]);else{const d=Array(f.width).fill(this.emptyCell);l.push(...d)}u.push(l.join(this.columnSeparator))}return{rows:u,length:o,width:a}}getChildMatrix(s){if(Array.isArray(s)){if(s.length===0)return{rows:[""],length:1,width:1}}else return{rows:["Invalid data found, value is not an array"],length:1,width:1};const o=[],a=this.getHeaderRow(s[0]);o.push(...a.rows);const u=a.width;let c=1;for(const l of s){const f=this.getRowMatrix(l);c=c+f.length,o.push(...f.rows)}return{rows:o,length:c,width:u}}getRowMatrix(s){const o=[];for(const a in s){const u=s[a];if((0,e.isCompoundArrayData)(u)){const c=this.getChildMatrix(u);o.push(c)}else{const c={rows:[this.stringify(u)],length:1,width:1};o.push(c)}}return this.mergeMatrices(o)}async process(s){let o=!1;for await(const a of s){if(!o&&this.includeHeader){const c=this.getHeaderRow(a.toObject());this.stream.write(c.rows[0]),this.stream.write(this.rowSeparator),o=!0}const u=this.getRowMatrix(a.toObject());for(const c of u.rows)this.stream.write(c),this.stream.write(this.rowSeparator)}this.stream.close()}}return yd.CSVWriter=r,yd}var cs={},fx={},uw={},ga={},Mce;function QA(){if(Mce)return ga;Mce=1,Object.defineProperty(ga,"__esModule",{value:!0}),ga.isConnectionConfigEntry=e,ga.registerConnectionType=n,ga.getConnectionProperties=r,ga.getConnectionTypeDisplayName=i,ga.getRegisteredConnectionTypes=s,ga.getConnectionTypeDef=o,ga.validateConnectionConfigProperties=a,ga.readConnectionsConfig=u,ga.writeConnectionsConfig=c,ga.createConnectionsFromConfig=l;function e(f){return typeof f=="object"&&f!==null&&typeof f.is=="string"}const t=new Map;function n(f,d){t.set(f,d)}function r(f){var d;return(d=t.get(f))===null||d===void 0?void 0:d.properties}function i(f){var d;return(d=t.get(f))===null||d===void 0?void 0:d.displayName}function s(){return[...t.keys()]}function o(f){return t.get(f)}function a(f,d,p){var x,g;const m=(g=(x=t.get(d))===null||x===void 0?void 0:x.properties)!==null&&g!==void 0?g:[];for(const y of m){if(!y.requireLiteralString)continue;const E=p[y.name];if(E!==void 0&&typeof E!="string")throw new Error(`Connection "${f}" property "${y.name}" must be a literal string`)}}function u(f){var d;const p=JSON.parse(f),x=Object.fromEntries(Object.entries((d=p.connections)!==null&&d!==void 0?d:{}).filter(([,g])=>e(g)));return{...p,connections:x}}function c(f){return JSON.stringify(f,null,2)}function l(f,d){const p=Object.entries(f.connections),x=p.length>0?p[0][0]:void 0,g=new Map;return{async lookupConnection(m){if(m===void 0&&(m=x),m===void 0)throw new Error("No connections defined in config");const y=g.get(m);if(y)return y;const E=f.connections[m];if(!E)throw new Error(`No connection named "${m}" found in config`);const v=t.get(E.is);if(!v)throw new Error(`No registered connection type "${E.is}" for connection "${m}". Did you forget to import the connection package?`);const _={name:m};for(const[C,R]of Object.entries(E))C!=="is"&&R!=null&&(_[C]=R);a(m,E.is,_);const b=await v.factory(_);return d&&d(m,b),g.set(m,b),b},async close(){const m=[...g.values()];g.clear();for(const y of m)await y.close()},async idle(){for(const m of g.values())await m.idle()}}}return ga}var kce;function s9e(){if(kce)return uw;kce=1,Object.defineProperty(uw,"__esModule",{value:!0}),uw.compileConfig=i;const e=QA(),t=eee(),n={connections:s,manifestPath:u,givensPath:c,finalizeGivens:l,virtualMap:f,includeDefaultConnections:d},r=new Set(Object.keys(n));function i(E){const v=[],_={kind:"dict",entries:{}};if(!x(E))return v.push({message:"config is not a JSON object",severity:"error",code:"config-validation"}),{compiled:_,log:v};for(const[b,C]of Object.entries(E)){const R=n[b];if(!R){const w=(0,t.closestMatch)(b,[...r]),T=w?`. Did you mean "${w}"?`:"";v.push(g(b,`unknown config key "${b}"${T}`));continue}const A=R(C,v);A!==void 0&&(_.entries[b]=A)}return{compiled:_,log:v}}function s(E,v){if(!x(E)){v.push(g("connections",'"connections" should be an object'));return}const _=new Set((0,e.getRegisteredConnectionTypes)()),b={kind:"dict",entries:{}};for(const[C,R]of Object.entries(E)){const A=`connections.${C}`;if(!x(R)){v.push(g(A,"should be an object"));continue}const w=R.is;if(w==null||w===""){v.push(g(A,'missing required "is" field (connection type)'));continue}if(typeof w!="string"){v.push(g(`${A}.is`,'"is" should be a string'));continue}if(!_.has(w)){const O=(0,t.closestMatch)(w,[..._]),F=O?` Did you mean "${O}"?`:"";v.push(g(`${A}.is`,`unknown connection type "${w}".${F} Available types: ${[..._].join(", ")}`));continue}const T=o(A,w,R,v);b.entries[C]=T}return b}function o(E,v,_,b){var C;const R=(C=(0,e.getConnectionProperties)(v))!==null&&C!==void 0?C:[],A=new Map(R.map(T=>[T.name,T])),w={kind:"dict",entries:{}};w.entries.is={kind:"value",value:v};for(const[T,O]of Object.entries(_)){if(T==="is")continue;const F=A.get(T);if(!F){const $=(0,t.closestMatch)(T,[...A.keys()]),V=$?`. Did you mean "${$}"?`:"";b.push(g(`${E}.${T}`,`unknown property "${T}" for connection type "${v}"${V}`));continue}const N=a(`${E}.${T}`,F,O,b);N!==void 0&&(w.entries[T]=N)}return w}function a(E,v,_,b){if(_==null)return;if(v.type==="json")return{kind:"value",value:_};const C=p(_);if(C!==void 0)return v.requireLiteralString?(b.push(g(E,"must be a literal string and cannot use an overlay reference")),{kind:"value",value:_}):C;const R=y(_,v.type);if(R){if(v.requireLiteralString)return b.push(g(E,`must be a literal string, got ${m(_)}`)),{kind:"value",value:_};b.push(g(E,`${R} (expected ${v.type})`));return}return{kind:"value",value:_}}function u(E,v){const _=p(E);if(_!==void 0)return _;if(typeof E!="string"){v.push(g("manifestPath",'"manifestPath" should be a string or an overlay reference'));return}return{kind:"value",value:E}}function c(E,v){const _=p(E);if(_!==void 0)return _;if(typeof E!="string"){v.push(g("givensPath",'"givensPath" should be a string or an overlay reference'));return}return{kind:"value",value:E}}function l(E,v){if(!Array.isArray(E)||!E.every(_=>typeof _=="string")){v.push(g("finalizeGivens",'"finalizeGivens" should be an array of given names'));return}return{kind:"value",value:E}}function f(E,v){return{kind:"value",value:E}}function d(E,v){return{kind:"value",value:E}}function p(E){if(typeof E!="object"||E===null||Array.isArray(E))return;const v=Object.keys(E);if(v.length!==1)return;const _=v[0],b=E[_];if(typeof b=="string")return{kind:"reference",source:_,path:[b]};if(Array.isArray(b)&&b.every(C=>typeof C=="string"))return{kind:"reference",source:_,path:b}}function x(E){return typeof E=="object"&&E!==null&&!Array.isArray(E)}function g(E,v){return{message:`${E}: ${v}`,severity:"warn",code:"config-validation"}}function m(E){return Array.isArray(E)?"array":typeof E}function y(E,v){switch(v){case"number":if(typeof E!="number")return`should be a number, got ${typeof E}`;break;case"boolean":if(typeof E!="boolean")return`should be a boolean, got ${typeof E}`;break;case"string":case"password":case"secret":case"file":case"text":if(typeof E!="string")return`should be a string, got ${typeof E}`;break}}return uw}var lw={},$1={},Pce;function Nk(){if(Pce)return $1;Pce=1;var e={};Object.defineProperty($1,"__esModule",{value:!0}),$1.envOverlay=t,$1.contextOverlay=n,$1.defaultConfigOverlays=r,$1.isThenable=i;function t(){return typeof process>"u"||!e?()=>{}:s=>e[s[0]]}function n(s){return o=>s[o[0]]}function r(){return{env:t(),config:()=>{}}}function i(s){return typeof s=="object"&&s!==null&&"then"in s&&typeof s.then=="function"}return $1}var $ce;function o9e(){if($ce)return lw;$ce=1,Object.defineProperty(lw,"__esModule",{value:!0}),lw.prepareConfig=n;const e=QA(),t=Nk();function n(a,u,c){let l={},f,d,p,x,g=!1;for(const[m,y]of Object.entries(a.entries))switch(m){case"connections":{if(y.kind!=="dict")break;l=i(y);break}case"manifestPath":{f=o(y,u,c,"manifestPath");break}case"givensPath":{d=o(y,u,c,"givensPath");break}case"finalizeGivens":{y.kind==="value"&&r(y.value)&&(p=y.value);break}case"virtualMap":{y.kind==="value"&&(x=y.value);break}case"includeDefaultConnections":{y.kind==="value"&&typeof y.value=="boolean"&&(g=y.value);break}}return g&&s(l),{compiledConnections:l,manifestPath:f,givensPath:d,finalizeGivens:p,virtualMap:x}}function r(a){return Array.isArray(a)&&a.every(u=>typeof u=="string")}function i(a){const u={};for(const[c,l]of Object.entries(a.entries))l.kind==="dict"&&(u[c]=l);return u}function s(a){for(const u of(0,e.getRegisteredConnectionTypes)())a[u]||(a[u]={kind:"dict",entries:{is:{kind:"value",value:u}}})}function o(a,u,c,l){if(a.kind==="value")return typeof a.value=="string"?a.value:void 0;if(a.kind==="reference"){const f=u[a.source];if(!f){c.push({message:`unknown overlay source "${a.source}" for "${l}"`,severity:"warn",code:"config-overlay"});return}const d=f(a.path);if((0,t.isThenable)(d)){c.push({message:`the \`${a.source}\` overlay returned a Promise for "${l}"; top-level string settings must resolve synchronously`,severity:"warn",code:"config-overlay"});return}return typeof d=="string"?d:void 0}}return lw}var cw={},Bce;function a9e(){if(Bce)return cw;Bce=1,Object.defineProperty(cw,"__esModule",{value:!0}),cw.buildManagedLookup=t;const e=QA();function t(a,u,c){const l=Object.entries(a),f=l.length>0?l[0][0]:void 0,d=new Map;return{async lookupConnection(p){if(p===void 0&&(p=f),p===void 0)throw new Error("No connections defined in config");const x=d.get(p);if(x)return x;const g=a[p];if(!g)throw new Error(`No connection named "${p}" found in config`);const m=await n(g,u,c);if(typeof m.is!="string")throw new Error(`Connection "${p}" is missing a valid "is" field`);const y=(0,e.getConnectionTypeDef)(m.is);if(!y)throw new Error(`No registered connection type "${m.is}" for connection "${p}". Did you forget to import the connection package?`);const E={name:p};for(const[_,b]of Object.entries(m))_!=="is"&&b!=null&&(E[_]=b);(0,e.validateConnectionConfigProperties)(p,m.is,E);const v=await y.factory(E);return d.set(p,v),v},async close(){const p=[...d.values()];d.clear();for(const x of p)await x.close()},async idle(){for(const p of d.values())await p.idle()}}}async function n(a,u,c){const l=await r(a,u,c);if(!(0,e.isConnectionConfigEntry)(l))throw new Error("Connection entry did not resolve to a valid {is: string, ...} dict");return await s(l,u),l}async function r(a,u,c){switch(a.kind){case"value":return a.value;case"reference":return i(a,u,c);case"dict":{const l={};for(const[f,d]of Object.entries(a.entries)){const p=await r(d,u,c);p!==void 0&&(l[f]=p)}return l}}}async function i(a,u,c){const l=u[a.source];if(!l){c.push({message:`unknown overlay source "${a.source}" for reference path ${JSON.stringify(a.path)}`,severity:"warn",code:"config-overlay"});return}return await l(a.path)}async function s(a,u){var c;const l=a.is;if(typeof l!="string")return;const f=(c=(0,e.getConnectionProperties)(l))!==null&&c!==void 0?c:[];for(const d of f){if(d.default===void 0||a[d.name]!==void 0)continue;const p=await o(d.default,u);p!==void 0&&(a[d.name]=p)}}async function o(a,u){if(typeof a!="object")return a;const c=Object.keys(a);if(c.length!==1)return;const l=c[0],f=a[l],d=typeof f=="string"?[f]:f;if(!Array.isArray(d))return;const p=u[l];if(p)return await p(d)}return cw}var qce;function Lk(){if(qce)return fx;qce=1,Object.defineProperty(fx,"__esModule",{value:!0}),fx.MalloyConfig=fx.Manifest=void 0,fx.isBuildManifestEntry=E;const e=s9e(),t=o9e(),n=a9e(),r=Nk(),i=Dk();class s{constructor(){this._manifest={entries:{},strict:!1},this._touched=new Set}loadText(_){this._clearEntries(),this._touched.clear(),this._manifest.strict=!1,this._loadParsed(JSON.parse(_))}get buildManifest(){return this._manifest}get strict(){var _;return(_=this._manifest.strict)!==null&&_!==void 0?_:!1}set strict(_){this._manifest.strict=_}update(_,b){(0,i.requireCanonicalTablePathAnyDialect)(b.tableName,`Manifest entry '${_}'`),this._manifest.entries[_]=b,this._touched.add(_)}touch(_){this._touched.add(_)}get activeEntries(){const _={};for(const b of this._touched)this._manifest.entries[b]&&(_[b]=this._manifest.entries[b]);return{entries:_,strict:this._manifest.strict}}_clearEntries(){for(const _ of Object.keys(this._manifest.entries))delete this._manifest.entries[_]}_loadParsed(_){typeof _.strict=="boolean"&&(this._manifest.strict=_.strict);const b=y(_.entries)?_.entries:_;for(const[C,R]of Object.entries(b))C==="strict"||!E(R)||((0,i.requireCanonicalTablePathAnyDialect)(R.tableName,`Manifest entry '${C}'`),this._manifest.entries[C]=R)}}fx.Manifest=s;class o{constructor(_,b){const C=[];let R;if(typeof _=="string")try{R=JSON.parse(_)}catch($){C.push({message:`Invalid JSON: ${$ instanceof Error?$.message:String($)}`,severity:"error",code:"config-validation"}),R={}}else R=_;const A=(0,e.compileConfig)(R);C.push(...A.log);const w=f(b,C),T=g(w.configURL,"configURL",C),O=w.rootDirectory,F={...(0,r.defaultConfigOverlays)(),...w.overlays,config:(0,r.contextOverlay)({configURL:T,rootDirectory:O})},N=(0,t.prepareConfig)(A.compiled,F,C);this._managedLookup=(0,n.buildManagedLookup)(N.compiledConnections,F,C),this._connections=this._managedLookup,this._overlays=F,this.virtualMap=m(N.virtualMap,C),this.configURL=T,this.rootDirectory=O,this.manifestPath=N.manifestPath,this.manifestURL=c(N.manifestPath,T),this.givensPath=N.givensPath,this.givensURL=l(N.givensPath,T,C),this.finalizeGivens=N.finalizeGivens,this.log=C}get connections(){return this._connections}wrapConnections(_){this._connections=_(this._connections)}async shutdown(_="close"){_==="idle"?await this._managedLookup.idle():await this._managedLookup.close()}async releaseConnections(){await this.shutdown("close")}async readOverlay(_,...b){var C,R;return await((R=(C=this._overlays)[_])===null||R===void 0?void 0:R.call(C,b))}}fx.MalloyConfig=o;const a="MANIFESTS",u="malloy-manifest.json";function c(v,_){if(!_)return;let b;try{b=new URL(_)}catch{return}const C=v??a;let R;try{R=new URL(C,b)}catch{return}const A=R.toString(),w=A.endsWith("/")?R:new URL(A+"/");return new URL(u,w).toString()}function l(v,_,b){if(!v)return;if(!_){b.push({message:"givensPath is set but no configURL is available; per-runtime givens will not be loaded. Pass `configURL` (or use an absolute URL such as `file:///...`).",severity:"warn",code:"config-overlay"});return}let C;try{C=new URL(_)}catch{return}try{return new URL(v,C).toString()}catch(R){const A=R instanceof Error?R.message:String(R);b.push({message:`givensPath '${v}' could not be resolved against configURL '${_}': ${A}`,severity:"warn",code:"config-validation"});return}}function f(v,_){if(v===void 0)return{};if(d(v))return p(v,_);const b=v;if(b.overlays&&"config"in b.overlays){_.push({message:"`config` is reserved by MalloyConfig; pass `configURL` and `rootDirectory` directly instead. Supplied `overlays.config` ignored.",severity:"warn",code:"config-overlay"});const{config:C,...R}=b.overlays;return{...b,overlays:R}}return b}function d(v){for(const _ of Object.values(v))if(typeof _=="function")return!0;return!1}function p(v,_){const b=v.config;if(!b)return{overlays:v};const C=x(b,"configURL",_),R=x(b,"rootDirectory",_),{config:A,...w}=v;return{configURL:C,rootDirectory:R,overlays:w}}function x(v,_,b){const C=v([_]);if((0,r.isThenable)(C)){b.push({message:`the legacy \`config\` overlay returned a Promise for \`${_}\`; top-level FS context must resolve synchronously. ${_} will be undefined.`,severity:"warn",code:"config-overlay"});return}return typeof C=="string"?C:void 0}function g(v,_,b){if(v!==void 0)try{return new URL(v),v}catch{b.push({message:`${_} must be a URL-shaped string (e.g. 'file:///path/to/...'), got '${v}'. In Node, use \`url.pathToFileURL(path).toString()\`.`,severity:"warn",code:"config-validation"});return}}function m(v,_){if(!y(v))return;const b=new Map;for(const[C,R]of Object.entries(v)){if(!y(R))continue;const A=new Map;for(const[w,T]of Object.entries(R)){if(typeof T!="string")continue;const O=(0,i.validateCanonicalTablePathAnyDialect)(T);if(O!==void 0){_.push({message:`virtualMap entry '${C}.${w}': ${O}`,severity:"error",code:"config-validation"});continue}A.set(w,T)}A.size>0&&b.set(C,A)}return b.size>0?b:void 0}function y(v){return typeof v=="object"&&v!==null&&!Array.isArray(v)}function E(v){return y(v)&&typeof v.tableName=="string"}return fx}var B1={},GA={},Uce;function u9e(){return Uce||(Uce=1,Object.defineProperty(GA,"__esModule",{value:!0}),GA.MALLOY_VERSION=void 0,GA.MALLOY_VERSION="0.0.425"),GA}var jce;function zce(){if(jce)return B1;jce=1,Object.defineProperty(B1,"__esModule",{value:!0}),B1.Malloy=B1.MalloyError=void 0;const e=Ok(),t=QA(),n=Ti(),r=T4(),i=u9e(),s=ow(),o=Oce(),a=Kp(),u=aw(),c=Lce();function l(x="loadModel"){return`internal://${x}/${(0,a.v4)()}`}function f(x){return[...Object.keys(x),...Object.values(x).map(f).flat()]}class d extends Error{constructor(g,m=[]){super(g),this.problems=m}}B1.MalloyError=d;class p{static get version(){return i.MALLOY_VERSION}static registerConnectionType(g,m){(0,t.registerConnectionType)(g,m)}static getConnectionProperties(g){return(0,t.getConnectionProperties)(g)}static getConnectionTypeDisplayName(g){return(0,t.getConnectionTypeDisplayName)(g)}static getRegisteredConnectionTypes(){return(0,t.getRegisteredConnectionTypes)()}static _parse(g,m,y,E,v){var _;m===void 0&&(m=new URL(l(E==null?void 0:E.method)));let b=m;E!=null&&E.importBaseURL&&(b=E==null?void 0:E.importBaseURL);const C=new e.MalloyTranslator(m.toString(),b.toString(),{urls:{[m.toString()]:g}},y,(_=E==null?void 0:E.restrictedMode)!==null&&_!==void 0?_:!1);return E!=null&&E.testEnvironment&&(C.allDialectsEnabled=!0),new o.Parse(C,v)}static parse({url:g,urlReader:m,source:y,eventStream:E,options:v}){if(y!==void 0)return p._parse(y,g,E,v);if(m===void 0)throw new Error("Internal Error: urlReader is required.");if(g===void 0)throw new Error("Internal Error: url is required if source not present.");return(0,s.readURL)(m,g).then(({contents:_,invalidationKey:b})=>p._parse(_,g,E,v,b))}static async compile(g){var m,y,E,v,_;let{url:b,source:C,importBaseURL:R,cacheManager:A}=g;const{parse:w,urlReader:T,connections:O,model:F,refreshSchemaCache:N,noThrowOnError:$,eventStream:V,restrictedMode:W,method:Z}=g;W&&(A=void 0);let ce;if(N&&(ce=typeof N=="number"?N:Date.now()),b===void 0&&C===void 0&&w===void 0)throw new Error("Internal Error: url, source, or parse required.");b===void 0&&(w!==void 0?b=new URL(w._translator.sourceURL):b=new URL(l(Z)));const z={};if(C===void 0&&A!==void 0){const fe=await A.getCachedModelDef(T,b.toString());if(fe)return new u.Model(fe.modelDef,[],[b.toString(),...f(fe.modelDef.dependencies)])}R??(R=b);let J;const oe=b.toString();if(w!==void 0){if(W!==void 0&&w._translator.restrictedMode!==W)throw new Error(`Malloy.compile: restrictedMode (${W}) does not match the pre-parsed translator's restrictedMode (${w._translator.restrictedMode}). Set restrictedMode at parse time.`);J=w._translator;const fe=(m=w._invalidationKey)!==null&&m!==void 0?m:await(0,s.getInvalidationKey)(T,b);z[oe]=fe}else{if(C===void 0){const{contents:fe,invalidationKey:I}=await(0,s.readURL)(T,b);z[oe]=I,C=fe}else{const fe=await(0,s.getInvalidationKey)(T,b);z[oe]=fe}J=new e.MalloyTranslator(oe,R.toString(),{urls:{[oe]:C}},V,W??!1)}for(;;){const fe=J.translate(F==null?void 0:F._modelDef);if(fe.final)if(fe.modelDef){await(A==null?void 0:A.setCachedModelDef(b.toString(),{modelDef:fe.modelDef,invalidationKeys:z}));for(const q of J.newlyTranslatedDependencies())await(A==null?void 0:A.setCachedModelDef(q.url,{modelDef:q.modelDef,invalidationKeys:z}));const I=!fe.modelWasModified&&F?F.getExistingQueryModel():void 0;return new u.Model(fe.modelDef,fe.problems||[],[...(y=F==null?void 0:F.fromSources)!==null&&y!==void 0?y:[],...(E=fe.fromSources)!==null&&E!==void 0?E:[]],I)}else if($){const I=(0,n.mkModelDef)("modelDidNotCompile"),q=(F==null?void 0:F._modelDef)||I;return new u.Model(q,fe.problems||[],[...(v=F==null?void 0:F.fromSources)!==null&&v!==void 0?v:[],...(_=fe.fromSources)!==null&&_!==void 0?_:[]])}else{const I=fe.problems||[],q=J.prettyErrors();throw new d(`Error(s) compiling model:
|
|
1384
|
-
${q}`,I)}else{if(fe.urls)for(const I of fe.urls)try{if((0,s.isInternalURL)(I))throw new Error("In order to use relative imports, you must compile a file via a URL.");if(A!==void 0){const B=await A.getCachedModelDef(T,I);if(B){for(const L in B.invalidationKeys)z[L]=B.invalidationKeys[L];J.update({translations:{[I]:B.modelDef}});continue}}const{contents:q,invalidationKey:j}=await(0,s.readURL)(T,new URL(I)),M={[I]:q};z[I]=j,J.update({urls:M})}catch(q){J.update({errors:{urls:{[I]:q.message}}})}if(fe.tables){const I=new Map;for(const q in fe.tables){const{connectionName:j,tablePath:M}=fe.tables[q],B=I.get(j);B===void 0?I.set(j,{[q]:M}):B[q]=M}for(const[q,j]of I)try{const M=await O.lookupConnection(q),{schemas:B,errors:L}=await p.safelyFetchTableSchema(M,j,{refreshTimestamp:ce});J.update({tables:B,errors:{tables:L}})}catch(M){const B={},L={};for(const k in j)L[k]=M.toString();J.update({tables:B,errors:{tables:L}})}}if(fe.connectionDialects)for(const I in fe.connectionDialects){const{connectionName:q}=fe.connectionDialects[I];try{const j=await O.lookupConnection(q);J.update({connectionDialects:{[I]:j.dialectName}})}catch(j){J.update({errors:{connectionDialects:{[I]:j.toString()}}})}}if(fe.compileSQL){const I=fe.compileSQL,q=I.connection,j=(0,r.sqlKey)(I.connection,I.selectStr);try{const B=await(await O.lookupConnection(q)).fetchSchemaForSQLStruct(I,{refreshTimestamp:ce});B.error&&J.update({errors:{compileSQL:{[j]:B.error}}}),B.structDef&&J.update({compileSQL:{[j]:B.structDef}})}catch(M){const B={};B[j]=M.toString(),J.update({errors:{compileSQL:B}})}}}}}static async safelyFetchTableSchema(g,m,y){const E=await g.fetchSchemaForTables(m,y);for(const v of Object.keys(m))if(E.schemas[v]===void 0&&E.errors[v]===void 0)throw new Error(`Schema fetch error for ${g.name}, no response for ${v} from ${g.dialectName}`);return E}static async run({connections:g,preparedResult:m,sqlStruct:y,connection:E,options:v}){if(!E){if(!g)throw new Error("Internal Error: Connection or LookupConnection<Connection> must be provided.");const _=(y==null?void 0:y.connection)||(m==null?void 0:m.connectionName);E=await g.lookupConnection(_)}if(y){const _=await E.runSQL(y.selectStr);return new c.Result({structs:[y],sql:y.selectStr,result:_.rows,totalRows:_.totalRows,runStats:_.runStats,lastStageName:y.name,malloy:"",connectionName:y.connection,sourceExplore:"",sourceFilters:[],profilingUrl:_.profilingUrl},(0,n.mkModelDef)("empty_model"))}else if(m){const _=await E.runSQL(m.sql,v);return new c.Result({...m._rawQuery,result:_.rows,totalRows:_.totalRows,runStats:_.runStats,profilingUrl:_.profilingUrl},m._modelDef)}else throw new Error("Internal error: sqlStruct or preparedResult must be provided.")}static async*runStream({connections:g,preparedResult:m,sqlStruct:y,connection:E,options:v}){if(y===void 0&&m===void 0)throw new Error("Internal error: sqlBlock or preparedResult must be provided.");const _=(y==null?void 0:y.connection)||(m==null?void 0:m.connectionName);if(E===void 0){if(g===void 0)throw new Error("Internal Error: Connection or LookupConnection<Connection> must be provided.");E=await g.lookupConnection(_)}if(!E.canStream())throw new Error(`Connection '${_}' cannot stream results.`);let b,C;if(y)C=new u.Explore((0,u.pseudoModelFor)(y),y),b=y.selectStr;else if(m!==void 0)C=m.resultExplore,b=m.sql;else throw new Error("Internal error: sqlStruct or preparedResult must be provided.");let R=0;for await(const A of E.runSQLStream(b,v))yield new c.DataRecord(A,R,C,void 0,void 0),R+=1}static async estimateQueryCost({connections:g,preparedResult:m,sqlStruct:y}){if(!g)throw new Error("Internal Error: Connection or LookupConnection<Connection> must be provided.");const E=(y==null?void 0:y.connection)||(m==null?void 0:m.connectionName),v=await g.lookupConnection(E);if(y)return await v.estimateQueryCost(y.selectStr);if(m)return await v.estimateQueryCost(m.sql);throw new Error("Internal error: sqlStruct or preparedResult must be provided.")}}return B1.Malloy=p,B1}var Hce;function l9e(){if(Hce)return cs;Hce=1,Object.defineProperty(cs,"__esModule",{value:!0}),cs.ExploreMaterializer=cs.PreparedResultMaterializer=cs.QueryMaterializer=cs.ModelMaterializer=cs.SingleConnectionRuntime=cs.ConnectionRuntime=cs.Runtime=void 0;const e=Ti(),t=r0(),n=Dk(),r=Lk(),i=Qv(),s=ow(),o=aw(),a=zce();class u{constructor(_,b){this.runtime=_,this._materialize=b}materialize(){return this.materialized===void 0?this.rematerialize():this.materialized}rematerialize(){return this.materialized=this._materialize(),this.materialized}makeQueryMaterializer(_,b){return new p(this.runtime,_,b)}makeExploreMaterializer(_,b){return new g(this.runtime,_,b)}makePreparedResultMaterializer(_){return new x(this.runtime,_)}}class c{constructor({urlReader:_,connections:b,connection:C,config:R,buildManifest:A,eventStream:w,cacheManager:T,givens:O}){var F,N;if(this.isTestRuntime=!1,R!==void 0)this._config=R,b=b??R.connections;else if(b===void 0){if(C===void 0)throw new Error("A MalloyConfig, LookupConnection<Connection>, or Connection is required.");b={lookupConnection:()=>Promise.resolve(C)}}if(_===void 0&&(_=new s.EmptyURLReader),this._urlReader=_,this._connections=b,this._buildManifest=A,this._eventStream=w,this._cacheManager=T,O){for(const[$,V]of Object.entries(O))if(V===void 0)throw new Error(`Runtime givens.${$}: explicit undefined is not a valid value. Omit the key to defer to declaration default or the file layer; use null for an explicit null value.`)}this._constructorGivensMap=O?new Map(Object.entries(O)):new Map,this._finalizedGivensSet=new Set((N=(F=this._config)===null||F===void 0?void 0:F.finalizeGivens)!==null&&N!==void 0?N:[])}get cacheManager(){return this._cacheManager}get urlReader(){return this._urlReader}get connections(){return this._connections}get eventStream(){return this._eventStream}get _constructorGivens(){return this._constructorGivensMap}async getGivens(){const _=await this._resolveGivens(),b=new Map;if(_)for(const[C,R]of Object.entries(_))b.set(C,R);for(const[C,R]of this._constructorGivensMap)b.set(C,R);return b}get _finalizedGivens(){return this._finalizedGivensSet}set buildManifest(_){this._buildManifest=_,this._resolvedBuildManifestPromise=void 0}_resolveBuildManifest(){var _;if(this._buildManifest)return Promise.resolve(this._buildManifest);const b=(_=this._config)===null||_===void 0?void 0:_.manifestURL;return b?(this._resolvedBuildManifestPromise||(this._resolvedBuildManifestPromise=(async()=>{let C;try{const R=await this._urlReader.readURL(new URL(b));C=typeof R=="string"?R:R.contents}catch{return}try{const R=JSON.parse(C);if(!m(R))throw new Error('manifest is not an object with an "entries" map');for(const[A,w]of Object.entries(R.entries)){if(!(0,r.isBuildManifestEntry)(w))throw new Error(`Manifest entry '${A}' is missing a string tableName`);(0,n.requireCanonicalTablePathAnyDialect)(w.tableName,`Manifest entry '${A}'`)}return R}catch(R){const A=R instanceof Error?R.message:String(R);return{entries:{},loadError:`Manifest file at ${b} could not be parsed: ${A}`}}})()),this._resolvedBuildManifestPromise):Promise.resolve(void 0)}_resolveGivens(){var _;const b=(_=this._config)===null||_===void 0?void 0:_.givensURL;return b?(this._resolvedGivensPromise||(this._resolvedGivensPromise=(async()=>{let C;try{const A=await this._urlReader.readURL(new URL(b));C=typeof A=="string"?A:A.contents}catch(A){const w=A instanceof Error?A.message:String(A);throw new Error(`givens: failed to read givens file at ${b}: ${w}`)}let R;try{R=JSON.parse(C)}catch(A){const w=A instanceof Error?A.message:String(A);throw new Error(`givens: failed to parse JSON at ${b}: ${w}`)}if(!y(R)){const A=Array.isArray(R)?"array":R===null?"null":typeof R;throw new Error(`givens: file at ${b} must be a JSON object of name → value pairs, got ${A}`)}return R})()),this._resolvedGivensPromise):Promise.resolve(void 0)}_invalidateGivensCache(){this._resolvedGivensPromise=void 0}get virtualMap(){var _,b;return(_=this._virtualMap)!==null&&_!==void 0?_:(b=this._config)===null||b===void 0?void 0:b.virtualMap}set virtualMap(_){this._virtualMap=_}async shutdown(_="close"){var b;await((b=this._config)===null||b===void 0?void 0:b.shutdown(_))}async releaseConnections(){await this.shutdown("close")}loadModel(_,b){const{refreshSchemaCache:C,noThrowOnError:R}=b||{};this.isTestRuntime&&(b===void 0?b={testEnvironment:!0}:b={...b,testEnvironment:!0});const A=_ instanceof URL?{url:_}:{source:_};return new d(this,async()=>{const w=await a.Malloy.compile({...A,urlReader:this.urlReader,connections:this.connections,refreshSchemaCache:C,noThrowOnError:R,eventStream:this.eventStream,importBaseURL:b==null?void 0:b.importBaseURL,testEnvironment:b==null?void 0:b.testEnvironment,cacheManager:this.cacheManager});return this._withRuntimeContext(w)},b)}_withRuntimeContext(_){return this._finalizedGivensSet.size===0?_:new o.Model(_._modelDef,_.problems,_.fromSources,_.getExistingQueryModel(),{finalizedGivens:this._finalizedGivensSet})}_loadModelFromModelDef(_,b){return new d(this,async()=>new o.Model(_,[],[],void 0,this._finalizedGivensSet.size>0?{finalizedGivens:this._finalizedGivensSet}:void 0),b)}loadQuery(_,b){return this.loadModel(_,b).loadFinalQuery()}loadQueryByIndex(_,b,C){return this.loadModel(_,C).loadQueryByIndex(b,C)}loadQueryByName(_,b,C){return this.loadModel(_,C).loadQueryByName(b,C)}getModel(_,b){return this.loadModel(_,b).getModel()}getQuery(_,b){return this.loadQuery(_,b).getPreparedQuery()}getQueryByIndex(_,b,C){return this.loadQueryByIndex(_,b,C).getPreparedQuery()}getQueryByName(_,b,C){return this.loadQueryByName(_,b,C).getPreparedQuery()}}cs.Runtime=c;class l extends c{constructor({urlReader:_,connections:b}){super({connections:s.FixedConnectionMap.fromArray(b),urlReader:_}),this.rawConnections=b}}cs.ConnectionRuntime=l;class f extends c{constructor({urlReader:_,connection:b,eventStream:C,cacheManager:R}){super({urlReader:_,eventStream:C,cacheManager:R,connection:b}),this.connection=b}get supportsNesting(){return(0,t.getDialect)(this.connection.dialectName).supportsNesting}quote(_){return(0,t.getDialect)(this.connection.dialectName).sqlQuoteIdentifier(_)}get dialect(){return(0,t.getDialect)(this.connection.dialectName)}getQuoter(){return _=>this.quote(_.toString())}}cs.SingleConnectionRuntime=f;class d extends u{constructor(_,b,C){super(_,b),this.runtime=_,this.compileQueryOptions=C}loadFinalQuery(_){return this.makeQueryMaterializer(async()=>(await this.materialize()).getPreparedQuery(),{...this.compileQueryOptions,..._})}loadQueryByIndex(_,b){return this.makeQueryMaterializer(async()=>(await this.materialize()).getPreparedQueryByIndex(_),{...this.compileQueryOptions,...b})}loadQueryByName(_,b){return this.makeQueryMaterializer(async()=>(await this.materialize()).getPreparedQueryByName(_),{...this.compileQueryOptions,...b})}loadQuery(_,b){const{refreshSchemaCache:C,noThrowOnError:R}=b||{};return this.makeQueryMaterializer(async()=>{const A=this.runtime.urlReader,w=this.runtime.connections;this.runtime.isTestRuntime&&(b===void 0?b={testEnvironment:!0}:b={...b,testEnvironment:!0});const T=_ instanceof URL?{url:_}:{source:_},O=await this.getModel();return(await a.Malloy.compile({...T,urlReader:A,connections:w,model:O,refreshSchemaCache:C,noThrowOnError:R,importBaseURL:b==null?void 0:b.importBaseURL,testEnvironment:b==null?void 0:b.testEnvironment,...this.compileQueryOptions})).preparedQuery})}loadRestrictedQuery(_){return this.makeQueryMaterializer(async()=>{const b=this.runtime.urlReader,C=this.runtime.connections,R=this.runtime.isTestRuntime?!0:void 0,A=await this.getModel();return(await a.Malloy.compile({source:_,restrictedMode:!0,method:"query",urlReader:b,connections:C,model:A,testEnvironment:R,...this.compileQueryOptions})).preparedQuery})}extendModel(_,b){return this.runtime.isTestRuntime&&(b===void 0?b={testEnvironment:!0}:b={...b,testEnvironment:!0}),new d(this.runtime,async()=>{const C=this.runtime.urlReader,R=this.runtime.connections,A=_ instanceof URL?{url:_}:{source:_},w=await this.getModel(),T=await a.Malloy.compile({...A,urlReader:C,connections:R,model:w,method:"extendModel",refreshSchemaCache:b==null?void 0:b.refreshSchemaCache,noThrowOnError:b==null?void 0:b.noThrowOnError,importBaseURL:b==null?void 0:b.importBaseURL,testEnvironment:b==null?void 0:b.testEnvironment,...this.compileQueryOptions});return this.runtime._withRuntimeContext(T)},b)}async search(_,b,C=1e3,R=void 0){const A=await this.materialize(),w=A.queryModel,T=A.getExploreByName(_).structDef;if(!(0,e.isSourceDef)(T))throw new Error("Source to be searched was unexpectedly, not a source");const O=T.connection,F=await this.runtime.connections.lookupConnection(O);return await w.searchIndex(F,_,b,C,R)}async searchValueMap(_,b=10,C){const A=(await this.materialize()).getExploreByName(_);if(!(0,e.isSourceDef)(A.structDef))throw new Error("Source to be searched was unexpectedly, not a source");let w="{index: *}";A.getFieldByNameIfExists("search_index")&&(w="search_index");const T=`
|
|
1383
|
+
`,this.quoteCharacter='"',this.includeHeader=!0,this.emptyCell=""}escape(s){const o=s.includes(this.quoteCharacter),a=s.includes(this.columnSeparator),u=s.includes(this.rowSeparator),c=a||o||u;return o&&(s=s.replace(new RegExp(this.quoteCharacter,"g"),this.quoteCharacter+this.quoteCharacter)),c&&(s=this.quoteCharacter+s+this.quoteCharacter),s}stringify(s){return s===null?this.emptyCell:s instanceof Date?s.toISOString():typeof s=="boolean"||typeof s=="number"?JSON.stringify(s):typeof s=="bigint"?s.toString():`${s}`}getColWeight(s){let o=s;Array.isArray(s)&&(o=s[0]);let a=0;for(const u in o){a=a+1;const c=o[u];if((0,e.isCompoundArrayData)(c)){const l=this.getColWeight(c)-1;a=a+l}}return a}getHeaderRow(s){const o=[];let a=0;for(const u in s){o.push(this.escape(u));const c=s[u];if(a++,(0,e.isCompoundArrayData)(c)){const l=this.getColWeight(c)-1;a=a+l;for(let f=0;f<l;f++)o.push(this.emptyCell)}}return{rows:[o.join(this.columnSeparator)],length:1,width:a}}mergeMatrices(s){const o=Math.max(...s.map(c=>c.length)),a=s.reduce((c,l)=>c+l.width,0),u=[];for(let c=0;c<o;c++){const l=[];for(const f of s)if(c<f.length)l.push(f.rows[c]);else{const d=Array(f.width).fill(this.emptyCell);l.push(...d)}u.push(l.join(this.columnSeparator))}return{rows:u,length:o,width:a}}getChildMatrix(s){if(Array.isArray(s)){if(s.length===0)return{rows:[""],length:1,width:1}}else return{rows:["Invalid data found, value is not an array"],length:1,width:1};const o=[],a=this.getHeaderRow(s[0]);o.push(...a.rows);const u=a.width;let c=1;for(const l of s){const f=this.getRowMatrix(l);c=c+f.length,o.push(...f.rows)}return{rows:o,length:c,width:u}}getRowMatrix(s){const o=[];for(const a in s){const u=s[a];if((0,e.isCompoundArrayData)(u)){const c=this.getChildMatrix(u);o.push(c)}else{const c={rows:[this.stringify(u)],length:1,width:1};o.push(c)}}return this.mergeMatrices(o)}async process(s){let o=!1;for await(const a of s){if(!o&&this.includeHeader){const c=this.getHeaderRow(a.toObject());this.stream.write(c.rows[0]),this.stream.write(this.rowSeparator),o=!0}const u=this.getRowMatrix(a.toObject());for(const c of u.rows)this.stream.write(c),this.stream.write(this.rowSeparator)}this.stream.close()}}return yd.CSVWriter=r,yd}var cs={},fx={},uw={},ga={},Mce;function QA(){if(Mce)return ga;Mce=1,Object.defineProperty(ga,"__esModule",{value:!0}),ga.isConnectionConfigEntry=e,ga.registerConnectionType=n,ga.getConnectionProperties=r,ga.getConnectionTypeDisplayName=i,ga.getRegisteredConnectionTypes=s,ga.getConnectionTypeDef=o,ga.validateConnectionConfigProperties=a,ga.readConnectionsConfig=u,ga.writeConnectionsConfig=c,ga.createConnectionsFromConfig=l;function e(f){return typeof f=="object"&&f!==null&&typeof f.is=="string"}const t=new Map;function n(f,d){t.set(f,d)}function r(f){var d;return(d=t.get(f))===null||d===void 0?void 0:d.properties}function i(f){var d;return(d=t.get(f))===null||d===void 0?void 0:d.displayName}function s(){return[...t.keys()]}function o(f){return t.get(f)}function a(f,d,p){var x,g;const m=(g=(x=t.get(d))===null||x===void 0?void 0:x.properties)!==null&&g!==void 0?g:[];for(const y of m){if(!y.requireLiteralString)continue;const E=p[y.name];if(E!==void 0&&typeof E!="string")throw new Error(`Connection "${f}" property "${y.name}" must be a literal string`)}}function u(f){var d;const p=JSON.parse(f),x=Object.fromEntries(Object.entries((d=p.connections)!==null&&d!==void 0?d:{}).filter(([,g])=>e(g)));return{...p,connections:x}}function c(f){return JSON.stringify(f,null,2)}function l(f,d){const p=Object.entries(f.connections),x=p.length>0?p[0][0]:void 0,g=new Map;return{async lookupConnection(m){if(m===void 0&&(m=x),m===void 0)throw new Error("No connections defined in config");const y=g.get(m);if(y)return y;const E=f.connections[m];if(!E)throw new Error(`No connection named "${m}" found in config`);const v=t.get(E.is);if(!v)throw new Error(`No registered connection type "${E.is}" for connection "${m}". Did you forget to import the connection package?`);const _={name:m};for(const[C,R]of Object.entries(E))C!=="is"&&R!=null&&(_[C]=R);a(m,E.is,_);const b=await v.factory(_);return d&&d(m,b),g.set(m,b),b},async close(){const m=[...g.values()];g.clear();for(const y of m)await y.close()},async idle(){for(const m of g.values())await m.idle()}}}return ga}var kce;function s9e(){if(kce)return uw;kce=1,Object.defineProperty(uw,"__esModule",{value:!0}),uw.compileConfig=i;const e=QA(),t=eee(),n={connections:s,manifestPath:u,givensPath:c,finalizeGivens:l,virtualMap:f,includeDefaultConnections:d},r=new Set(Object.keys(n));function i(E){const v=[],_={kind:"dict",entries:{}};if(!x(E))return v.push({message:"config is not a JSON object",severity:"error",code:"config-validation"}),{compiled:_,log:v};for(const[b,C]of Object.entries(E)){const R=n[b];if(!R){const w=(0,t.closestMatch)(b,[...r]),T=w?`. Did you mean "${w}"?`:"";v.push(g(b,`unknown config key "${b}"${T}`));continue}const A=R(C,v);A!==void 0&&(_.entries[b]=A)}return{compiled:_,log:v}}function s(E,v){if(!x(E)){v.push(g("connections",'"connections" should be an object'));return}const _=new Set((0,e.getRegisteredConnectionTypes)()),b={kind:"dict",entries:{}};for(const[C,R]of Object.entries(E)){const A=`connections.${C}`;if(!x(R)){v.push(g(A,"should be an object"));continue}const w=R.is;if(w==null||w===""){v.push(g(A,'missing required "is" field (connection type)'));continue}if(typeof w!="string"){v.push(g(`${A}.is`,'"is" should be a string'));continue}if(!_.has(w)){const O=(0,t.closestMatch)(w,[..._]),F=O?` Did you mean "${O}"?`:"";v.push(g(`${A}.is`,`unknown connection type "${w}".${F} Available types: ${[..._].join(", ")}`));continue}const T=o(A,w,R,v);b.entries[C]=T}return b}function o(E,v,_,b){var C;const R=(C=(0,e.getConnectionProperties)(v))!==null&&C!==void 0?C:[],A=new Map(R.map(T=>[T.name,T])),w={kind:"dict",entries:{}};w.entries.is={kind:"value",value:v};for(const[T,O]of Object.entries(_)){if(T==="is")continue;const F=A.get(T);if(!F){const $=(0,t.closestMatch)(T,[...A.keys()]),V=$?`. Did you mean "${$}"?`:"";b.push(g(`${E}.${T}`,`unknown property "${T}" for connection type "${v}"${V}`));continue}const N=a(`${E}.${T}`,F,O,b);N!==void 0&&(w.entries[T]=N)}return w}function a(E,v,_,b){if(_==null)return;if(v.type==="json")return{kind:"value",value:_};const C=p(_);if(C!==void 0)return v.requireLiteralString?(b.push(g(E,"must be a literal string and cannot use an overlay reference")),{kind:"value",value:_}):C;const R=y(_,v.type);if(R){if(v.requireLiteralString)return b.push(g(E,`must be a literal string, got ${m(_)}`)),{kind:"value",value:_};b.push(g(E,`${R} (expected ${v.type})`));return}return{kind:"value",value:_}}function u(E,v){const _=p(E);if(_!==void 0)return _;if(typeof E!="string"){v.push(g("manifestPath",'"manifestPath" should be a string or an overlay reference'));return}return{kind:"value",value:E}}function c(E,v){const _=p(E);if(_!==void 0)return _;if(typeof E!="string"){v.push(g("givensPath",'"givensPath" should be a string or an overlay reference'));return}return{kind:"value",value:E}}function l(E,v){if(!Array.isArray(E)||!E.every(_=>typeof _=="string")){v.push(g("finalizeGivens",'"finalizeGivens" should be an array of given names'));return}return{kind:"value",value:E}}function f(E,v){return{kind:"value",value:E}}function d(E,v){return{kind:"value",value:E}}function p(E){if(typeof E!="object"||E===null||Array.isArray(E))return;const v=Object.keys(E);if(v.length!==1)return;const _=v[0],b=E[_];if(typeof b=="string")return{kind:"reference",source:_,path:[b]};if(Array.isArray(b)&&b.every(C=>typeof C=="string"))return{kind:"reference",source:_,path:b}}function x(E){return typeof E=="object"&&E!==null&&!Array.isArray(E)}function g(E,v){return{message:`${E}: ${v}`,severity:"warn",code:"config-validation"}}function m(E){return Array.isArray(E)?"array":typeof E}function y(E,v){switch(v){case"number":if(typeof E!="number")return`should be a number, got ${typeof E}`;break;case"boolean":if(typeof E!="boolean")return`should be a boolean, got ${typeof E}`;break;case"string":case"password":case"secret":case"file":case"text":if(typeof E!="string")return`should be a string, got ${typeof E}`;break}}return uw}var lw={},$1={},Pce;function Nk(){if(Pce)return $1;Pce=1;var e={};Object.defineProperty($1,"__esModule",{value:!0}),$1.envOverlay=t,$1.contextOverlay=n,$1.defaultConfigOverlays=r,$1.isThenable=i;function t(){return typeof process>"u"||!e?()=>{}:s=>e[s[0]]}function n(s){return o=>s[o[0]]}function r(){return{env:t(),config:()=>{}}}function i(s){return typeof s=="object"&&s!==null&&"then"in s&&typeof s.then=="function"}return $1}var $ce;function o9e(){if($ce)return lw;$ce=1,Object.defineProperty(lw,"__esModule",{value:!0}),lw.prepareConfig=n;const e=QA(),t=Nk();function n(a,u,c){let l={},f,d,p,x,g=!1;for(const[m,y]of Object.entries(a.entries))switch(m){case"connections":{if(y.kind!=="dict")break;l=i(y);break}case"manifestPath":{f=o(y,u,c,"manifestPath");break}case"givensPath":{d=o(y,u,c,"givensPath");break}case"finalizeGivens":{y.kind==="value"&&r(y.value)&&(p=y.value);break}case"virtualMap":{y.kind==="value"&&(x=y.value);break}case"includeDefaultConnections":{y.kind==="value"&&typeof y.value=="boolean"&&(g=y.value);break}}return g&&s(l),{compiledConnections:l,manifestPath:f,givensPath:d,finalizeGivens:p,virtualMap:x}}function r(a){return Array.isArray(a)&&a.every(u=>typeof u=="string")}function i(a){const u={};for(const[c,l]of Object.entries(a.entries))l.kind==="dict"&&(u[c]=l);return u}function s(a){for(const u of(0,e.getRegisteredConnectionTypes)())a[u]||(a[u]={kind:"dict",entries:{is:{kind:"value",value:u}}})}function o(a,u,c,l){if(a.kind==="value")return typeof a.value=="string"?a.value:void 0;if(a.kind==="reference"){const f=u[a.source];if(!f){c.push({message:`unknown overlay source "${a.source}" for "${l}"`,severity:"warn",code:"config-overlay"});return}const d=f(a.path);if((0,t.isThenable)(d)){c.push({message:`the \`${a.source}\` overlay returned a Promise for "${l}"; top-level string settings must resolve synchronously`,severity:"warn",code:"config-overlay"});return}return typeof d=="string"?d:void 0}}return lw}var cw={},Bce;function a9e(){if(Bce)return cw;Bce=1,Object.defineProperty(cw,"__esModule",{value:!0}),cw.buildManagedLookup=t;const e=QA();function t(a,u,c){const l=Object.entries(a),f=l.length>0?l[0][0]:void 0,d=new Map;return{async lookupConnection(p){if(p===void 0&&(p=f),p===void 0)throw new Error("No connections defined in config");const x=d.get(p);if(x)return x;const g=a[p];if(!g)throw new Error(`No connection named "${p}" found in config`);const m=await n(g,u,c);if(typeof m.is!="string")throw new Error(`Connection "${p}" is missing a valid "is" field`);const y=(0,e.getConnectionTypeDef)(m.is);if(!y)throw new Error(`No registered connection type "${m.is}" for connection "${p}". Did you forget to import the connection package?`);const E={name:p};for(const[_,b]of Object.entries(m))_!=="is"&&b!=null&&(E[_]=b);(0,e.validateConnectionConfigProperties)(p,m.is,E);const v=await y.factory(E);return d.set(p,v),v},async close(){const p=[...d.values()];d.clear();for(const x of p)await x.close()},async idle(){for(const p of d.values())await p.idle()}}}async function n(a,u,c){const l=await r(a,u,c);if(!(0,e.isConnectionConfigEntry)(l))throw new Error("Connection entry did not resolve to a valid {is: string, ...} dict");return await s(l,u),l}async function r(a,u,c){switch(a.kind){case"value":return a.value;case"reference":return i(a,u,c);case"dict":{const l={};for(const[f,d]of Object.entries(a.entries)){const p=await r(d,u,c);p!==void 0&&(l[f]=p)}return l}}}async function i(a,u,c){const l=u[a.source];if(!l){c.push({message:`unknown overlay source "${a.source}" for reference path ${JSON.stringify(a.path)}`,severity:"warn",code:"config-overlay"});return}return await l(a.path)}async function s(a,u){var c;const l=a.is;if(typeof l!="string")return;const f=(c=(0,e.getConnectionProperties)(l))!==null&&c!==void 0?c:[];for(const d of f){if(d.default===void 0||a[d.name]!==void 0)continue;const p=await o(d.default,u);p!==void 0&&(a[d.name]=p)}}async function o(a,u){if(typeof a!="object")return a;const c=Object.keys(a);if(c.length!==1)return;const l=c[0],f=a[l],d=typeof f=="string"?[f]:f;if(!Array.isArray(d))return;const p=u[l];if(p)return await p(d)}return cw}var qce;function Lk(){if(qce)return fx;qce=1,Object.defineProperty(fx,"__esModule",{value:!0}),fx.MalloyConfig=fx.Manifest=void 0,fx.isBuildManifestEntry=E;const e=s9e(),t=o9e(),n=a9e(),r=Nk(),i=Dk();class s{constructor(){this._manifest={entries:{},strict:!1},this._touched=new Set}loadText(_){this._clearEntries(),this._touched.clear(),this._manifest.strict=!1,this._loadParsed(JSON.parse(_))}get buildManifest(){return this._manifest}get strict(){var _;return(_=this._manifest.strict)!==null&&_!==void 0?_:!1}set strict(_){this._manifest.strict=_}update(_,b){(0,i.requireCanonicalTablePathAnyDialect)(b.tableName,`Manifest entry '${_}'`),this._manifest.entries[_]=b,this._touched.add(_)}touch(_){this._touched.add(_)}get activeEntries(){const _={};for(const b of this._touched)this._manifest.entries[b]&&(_[b]=this._manifest.entries[b]);return{entries:_,strict:this._manifest.strict}}_clearEntries(){for(const _ of Object.keys(this._manifest.entries))delete this._manifest.entries[_]}_loadParsed(_){typeof _.strict=="boolean"&&(this._manifest.strict=_.strict);const b=y(_.entries)?_.entries:_;for(const[C,R]of Object.entries(b))C==="strict"||!E(R)||((0,i.requireCanonicalTablePathAnyDialect)(R.tableName,`Manifest entry '${C}'`),this._manifest.entries[C]=R)}}fx.Manifest=s;class o{constructor(_,b){const C=[];let R;if(typeof _=="string")try{R=JSON.parse(_)}catch($){C.push({message:`Invalid JSON: ${$ instanceof Error?$.message:String($)}`,severity:"error",code:"config-validation"}),R={}}else R=_;const A=(0,e.compileConfig)(R);C.push(...A.log);const w=f(b,C),T=g(w.configURL,"configURL",C),O=w.rootDirectory,F={...(0,r.defaultConfigOverlays)(),...w.overlays,config:(0,r.contextOverlay)({configURL:T,rootDirectory:O})},N=(0,t.prepareConfig)(A.compiled,F,C);this._managedLookup=(0,n.buildManagedLookup)(N.compiledConnections,F,C),this._connections=this._managedLookup,this._overlays=F,this.virtualMap=m(N.virtualMap,C),this.configURL=T,this.rootDirectory=O,this.manifestPath=N.manifestPath,this.manifestURL=c(N.manifestPath,T),this.givensPath=N.givensPath,this.givensURL=l(N.givensPath,T,C),this.finalizeGivens=N.finalizeGivens,this.log=C}get connections(){return this._connections}wrapConnections(_){this._connections=_(this._connections)}async shutdown(_="close"){_==="idle"?await this._managedLookup.idle():await this._managedLookup.close()}async releaseConnections(){await this.shutdown("close")}async readOverlay(_,...b){var C,R;return await((R=(C=this._overlays)[_])===null||R===void 0?void 0:R.call(C,b))}}fx.MalloyConfig=o;const a="MANIFESTS",u="malloy-manifest.json";function c(v,_){if(!_)return;let b;try{b=new URL(_)}catch{return}const C=v??a;let R;try{R=new URL(C,b)}catch{return}const A=R.toString(),w=A.endsWith("/")?R:new URL(A+"/");return new URL(u,w).toString()}function l(v,_,b){if(!v)return;if(!_){b.push({message:"givensPath is set but no configURL is available; per-runtime givens will not be loaded. Pass `configURL` (or use an absolute URL such as `file:///...`).",severity:"warn",code:"config-overlay"});return}let C;try{C=new URL(_)}catch{return}try{return new URL(v,C).toString()}catch(R){const A=R instanceof Error?R.message:String(R);b.push({message:`givensPath '${v}' could not be resolved against configURL '${_}': ${A}`,severity:"warn",code:"config-validation"});return}}function f(v,_){if(v===void 0)return{};if(d(v))return p(v,_);const b=v;if(b.overlays&&"config"in b.overlays){_.push({message:"`config` is reserved by MalloyConfig; pass `configURL` and `rootDirectory` directly instead. Supplied `overlays.config` ignored.",severity:"warn",code:"config-overlay"});const{config:C,...R}=b.overlays;return{...b,overlays:R}}return b}function d(v){for(const _ of Object.values(v))if(typeof _=="function")return!0;return!1}function p(v,_){const b=v.config;if(!b)return{overlays:v};const C=x(b,"configURL",_),R=x(b,"rootDirectory",_),{config:A,...w}=v;return{configURL:C,rootDirectory:R,overlays:w}}function x(v,_,b){const C=v([_]);if((0,r.isThenable)(C)){b.push({message:`the legacy \`config\` overlay returned a Promise for \`${_}\`; top-level FS context must resolve synchronously. ${_} will be undefined.`,severity:"warn",code:"config-overlay"});return}return typeof C=="string"?C:void 0}function g(v,_,b){if(v!==void 0)try{return new URL(v),v}catch{b.push({message:`${_} must be a URL-shaped string (e.g. 'file:///path/to/...'), got '${v}'. In Node, use \`url.pathToFileURL(path).toString()\`.`,severity:"warn",code:"config-validation"});return}}function m(v,_){if(!y(v))return;const b=new Map;for(const[C,R]of Object.entries(v)){if(!y(R))continue;const A=new Map;for(const[w,T]of Object.entries(R)){if(typeof T!="string")continue;const O=(0,i.validateCanonicalTablePathAnyDialect)(T);if(O!==void 0){_.push({message:`virtualMap entry '${C}.${w}': ${O}`,severity:"error",code:"config-validation"});continue}A.set(w,T)}A.size>0&&b.set(C,A)}return b.size>0?b:void 0}function y(v){return typeof v=="object"&&v!==null&&!Array.isArray(v)}function E(v){return y(v)&&typeof v.tableName=="string"}return fx}var B1={},GA={},Uce;function u9e(){return Uce||(Uce=1,Object.defineProperty(GA,"__esModule",{value:!0}),GA.MALLOY_VERSION=void 0,GA.MALLOY_VERSION="0.0.426"),GA}var jce;function zce(){if(jce)return B1;jce=1,Object.defineProperty(B1,"__esModule",{value:!0}),B1.Malloy=B1.MalloyError=void 0;const e=Ok(),t=QA(),n=Ti(),r=T4(),i=u9e(),s=ow(),o=Oce(),a=Kp(),u=aw(),c=Lce();function l(x="loadModel"){return`internal://${x}/${(0,a.v4)()}`}function f(x){return[...Object.keys(x),...Object.values(x).map(f).flat()]}class d extends Error{constructor(g,m=[]){super(g),this.problems=m}}B1.MalloyError=d;class p{static get version(){return i.MALLOY_VERSION}static registerConnectionType(g,m){(0,t.registerConnectionType)(g,m)}static getConnectionProperties(g){return(0,t.getConnectionProperties)(g)}static getConnectionTypeDisplayName(g){return(0,t.getConnectionTypeDisplayName)(g)}static getRegisteredConnectionTypes(){return(0,t.getRegisteredConnectionTypes)()}static _parse(g,m,y,E,v){var _;m===void 0&&(m=new URL(l(E==null?void 0:E.method)));let b=m;E!=null&&E.importBaseURL&&(b=E==null?void 0:E.importBaseURL);const C=new e.MalloyTranslator(m.toString(),b.toString(),{urls:{[m.toString()]:g}},y,(_=E==null?void 0:E.restrictedMode)!==null&&_!==void 0?_:!1);return E!=null&&E.testEnvironment&&(C.allDialectsEnabled=!0),new o.Parse(C,v)}static parse({url:g,urlReader:m,source:y,eventStream:E,options:v}){if(y!==void 0)return p._parse(y,g,E,v);if(m===void 0)throw new Error("Internal Error: urlReader is required.");if(g===void 0)throw new Error("Internal Error: url is required if source not present.");return(0,s.readURL)(m,g).then(({contents:_,invalidationKey:b})=>p._parse(_,g,E,v,b))}static async compile(g){var m,y,E,v,_;let{url:b,source:C,importBaseURL:R,cacheManager:A}=g;const{parse:w,urlReader:T,connections:O,model:F,refreshSchemaCache:N,noThrowOnError:$,eventStream:V,restrictedMode:W,method:Z}=g;W&&(A=void 0);let ce;if(N&&(ce=typeof N=="number"?N:Date.now()),b===void 0&&C===void 0&&w===void 0)throw new Error("Internal Error: url, source, or parse required.");b===void 0&&(w!==void 0?b=new URL(w._translator.sourceURL):b=new URL(l(Z)));const z={};if(C===void 0&&A!==void 0){const fe=await A.getCachedModelDef(T,b.toString());if(fe)return new u.Model(fe.modelDef,[],[b.toString(),...f(fe.modelDef.dependencies)])}R??(R=b);let J;const oe=b.toString();if(w!==void 0){if(W!==void 0&&w._translator.restrictedMode!==W)throw new Error(`Malloy.compile: restrictedMode (${W}) does not match the pre-parsed translator's restrictedMode (${w._translator.restrictedMode}). Set restrictedMode at parse time.`);J=w._translator;const fe=(m=w._invalidationKey)!==null&&m!==void 0?m:await(0,s.getInvalidationKey)(T,b);z[oe]=fe}else{if(C===void 0){const{contents:fe,invalidationKey:I}=await(0,s.readURL)(T,b);z[oe]=I,C=fe}else{const fe=await(0,s.getInvalidationKey)(T,b);z[oe]=fe}J=new e.MalloyTranslator(oe,R.toString(),{urls:{[oe]:C}},V,W??!1)}for(;;){const fe=J.translate(F==null?void 0:F._modelDef);if(fe.final)if(fe.modelDef){await(A==null?void 0:A.setCachedModelDef(b.toString(),{modelDef:fe.modelDef,invalidationKeys:z}));for(const q of J.newlyTranslatedDependencies())await(A==null?void 0:A.setCachedModelDef(q.url,{modelDef:q.modelDef,invalidationKeys:z}));const I=!fe.modelWasModified&&F?F.getExistingQueryModel():void 0;return new u.Model(fe.modelDef,fe.problems||[],[...(y=F==null?void 0:F.fromSources)!==null&&y!==void 0?y:[],...(E=fe.fromSources)!==null&&E!==void 0?E:[]],I)}else if($){const I=(0,n.mkModelDef)("modelDidNotCompile"),q=(F==null?void 0:F._modelDef)||I;return new u.Model(q,fe.problems||[],[...(v=F==null?void 0:F.fromSources)!==null&&v!==void 0?v:[],...(_=fe.fromSources)!==null&&_!==void 0?_:[]])}else{const I=fe.problems||[],q=J.prettyErrors();throw new d(`Error(s) compiling model:
|
|
1384
|
+
${q}`,I)}else{if(fe.urls)for(const I of fe.urls)try{if((0,s.isInternalURL)(I))throw new Error("In order to use relative imports, you must compile a file via a URL.");if(A!==void 0){const B=await A.getCachedModelDef(T,I);if(B){for(const L in B.invalidationKeys)z[L]=B.invalidationKeys[L];J.update({translations:{[I]:B.modelDef}});continue}}const{contents:q,invalidationKey:j}=await(0,s.readURL)(T,new URL(I)),M={[I]:q};z[I]=j,J.update({urls:M})}catch(q){J.update({errors:{urls:{[I]:q.message}}})}if(fe.tables){const I=new Map;for(const q in fe.tables){const{connectionName:j,tablePath:M}=fe.tables[q],B=I.get(j);B===void 0?I.set(j,{[q]:M}):B[q]=M}for(const[q,j]of I)try{const M=await O.lookupConnection(q),{schemas:B,errors:L}=await p.safelyFetchTableSchema(M,j,{refreshTimestamp:ce});J.update({tables:B,errors:{tables:L}})}catch(M){const B={},L={};for(const k in j)L[k]=M.toString();J.update({tables:B,errors:{tables:L}})}}if(fe.connectionDialects)for(const I in fe.connectionDialects){const{connectionName:q}=fe.connectionDialects[I];try{const j=await O.lookupConnection(q);J.update({connectionDialects:{[I]:j.dialectName}})}catch(j){J.update({errors:{connectionDialects:{[I]:j.toString()}}})}}if(fe.compileSQL){const I=fe.compileSQL,q=I.connection,j=(0,r.sqlKey)(I.connection,I.selectStr);try{const B=await(await O.lookupConnection(q)).fetchSchemaForSQLStruct(I,{refreshTimestamp:ce});B.error&&J.update({errors:{compileSQL:{[j]:B.error}}}),B.structDef&&J.update({compileSQL:{[j]:B.structDef}})}catch(M){const B={};B[j]=M.toString(),J.update({errors:{compileSQL:B}})}}}}}static async safelyFetchTableSchema(g,m,y){const E=await g.fetchSchemaForTables(m,y);for(const v of Object.keys(m))if(E.schemas[v]===void 0&&E.errors[v]===void 0)throw new Error(`Schema fetch error for ${g.name}, no response for ${v} from ${g.dialectName}`);return E}static async run({connections:g,preparedResult:m,sqlStruct:y,connection:E,options:v}){if(!E){if(!g)throw new Error("Internal Error: Connection or LookupConnection<Connection> must be provided.");const _=(y==null?void 0:y.connection)||(m==null?void 0:m.connectionName);E=await g.lookupConnection(_)}if(y){const _=await E.runSQL(y.selectStr,{queryMetadata:v==null?void 0:v.queryMetadata});return new c.Result({structs:[y],sql:y.selectStr,result:_.rows,totalRows:_.totalRows,runStats:_.runStats,lastStageName:y.name,malloy:"",connectionName:y.connection,sourceExplore:"",sourceFilters:[],profilingUrl:_.profilingUrl},(0,n.mkModelDef)("empty_model"))}else if(m){const _=await E.runSQL(m.sql,v);return new c.Result({...m._rawQuery,result:_.rows,totalRows:_.totalRows,runStats:_.runStats,profilingUrl:_.profilingUrl},m._modelDef)}else throw new Error("Internal error: sqlStruct or preparedResult must be provided.")}static async*runStream({connections:g,preparedResult:m,sqlStruct:y,connection:E,options:v}){if(y===void 0&&m===void 0)throw new Error("Internal error: sqlBlock or preparedResult must be provided.");const _=(y==null?void 0:y.connection)||(m==null?void 0:m.connectionName);if(E===void 0){if(g===void 0)throw new Error("Internal Error: Connection or LookupConnection<Connection> must be provided.");E=await g.lookupConnection(_)}if(!E.canStream())throw new Error(`Connection '${_}' cannot stream results.`);let b,C;if(y)C=new u.Explore((0,u.pseudoModelFor)(y),y),b=y.selectStr;else if(m!==void 0)C=m.resultExplore,b=m.sql;else throw new Error("Internal error: sqlStruct or preparedResult must be provided.");let R=0;for await(const A of E.runSQLStream(b,v))yield new c.DataRecord(A,R,C,void 0,void 0),R+=1}static async estimateQueryCost({connections:g,preparedResult:m,sqlStruct:y}){if(!g)throw new Error("Internal Error: Connection or LookupConnection<Connection> must be provided.");const E=(y==null?void 0:y.connection)||(m==null?void 0:m.connectionName),v=await g.lookupConnection(E);if(y)return await v.estimateQueryCost(y.selectStr);if(m)return await v.estimateQueryCost(m.sql);throw new Error("Internal error: sqlStruct or preparedResult must be provided.")}}return B1.Malloy=p,B1}var Hce;function l9e(){if(Hce)return cs;Hce=1,Object.defineProperty(cs,"__esModule",{value:!0}),cs.ExploreMaterializer=cs.PreparedResultMaterializer=cs.QueryMaterializer=cs.ModelMaterializer=cs.SingleConnectionRuntime=cs.ConnectionRuntime=cs.Runtime=void 0;const e=Ti(),t=r0(),n=Dk(),r=Lk(),i=Qv(),s=ow(),o=aw(),a=zce();class u{constructor(_,b){this.runtime=_,this._materialize=b}materialize(){return this.materialized===void 0?this.rematerialize():this.materialized}rematerialize(){return this.materialized=this._materialize(),this.materialized}makeQueryMaterializer(_,b){return new p(this.runtime,_,b)}makeExploreMaterializer(_,b){return new g(this.runtime,_,b)}makePreparedResultMaterializer(_){return new x(this.runtime,_)}}class c{constructor({urlReader:_,connections:b,connection:C,config:R,buildManifest:A,eventStream:w,cacheManager:T,givens:O}){var F,N;if(this.isTestRuntime=!1,R!==void 0)this._config=R,b=b??R.connections;else if(b===void 0){if(C===void 0)throw new Error("A MalloyConfig, LookupConnection<Connection>, or Connection is required.");b={lookupConnection:()=>Promise.resolve(C)}}if(_===void 0&&(_=new s.EmptyURLReader),this._urlReader=_,this._connections=b,this._buildManifest=A,this._eventStream=w,this._cacheManager=T,O){for(const[$,V]of Object.entries(O))if(V===void 0)throw new Error(`Runtime givens.${$}: explicit undefined is not a valid value. Omit the key to defer to declaration default or the file layer; use null for an explicit null value.`)}this._constructorGivensMap=O?new Map(Object.entries(O)):new Map,this._finalizedGivensSet=new Set((N=(F=this._config)===null||F===void 0?void 0:F.finalizeGivens)!==null&&N!==void 0?N:[])}get cacheManager(){return this._cacheManager}get urlReader(){return this._urlReader}get connections(){return this._connections}get eventStream(){return this._eventStream}get _constructorGivens(){return this._constructorGivensMap}async getGivens(){const _=await this._resolveGivens(),b=new Map;if(_)for(const[C,R]of Object.entries(_))b.set(C,R);for(const[C,R]of this._constructorGivensMap)b.set(C,R);return b}get _finalizedGivens(){return this._finalizedGivensSet}set buildManifest(_){this._buildManifest=_,this._resolvedBuildManifestPromise=void 0}_resolveBuildManifest(){var _;if(this._buildManifest)return Promise.resolve(this._buildManifest);const b=(_=this._config)===null||_===void 0?void 0:_.manifestURL;return b?(this._resolvedBuildManifestPromise||(this._resolvedBuildManifestPromise=(async()=>{let C;try{const R=await this._urlReader.readURL(new URL(b));C=typeof R=="string"?R:R.contents}catch{return}try{const R=JSON.parse(C);if(!m(R))throw new Error('manifest is not an object with an "entries" map');for(const[A,w]of Object.entries(R.entries)){if(!(0,r.isBuildManifestEntry)(w))throw new Error(`Manifest entry '${A}' is missing a string tableName`);(0,n.requireCanonicalTablePathAnyDialect)(w.tableName,`Manifest entry '${A}'`)}return R}catch(R){const A=R instanceof Error?R.message:String(R);return{entries:{},loadError:`Manifest file at ${b} could not be parsed: ${A}`}}})()),this._resolvedBuildManifestPromise):Promise.resolve(void 0)}_resolveGivens(){var _;const b=(_=this._config)===null||_===void 0?void 0:_.givensURL;return b?(this._resolvedGivensPromise||(this._resolvedGivensPromise=(async()=>{let C;try{const A=await this._urlReader.readURL(new URL(b));C=typeof A=="string"?A:A.contents}catch(A){const w=A instanceof Error?A.message:String(A);throw new Error(`givens: failed to read givens file at ${b}: ${w}`)}let R;try{R=JSON.parse(C)}catch(A){const w=A instanceof Error?A.message:String(A);throw new Error(`givens: failed to parse JSON at ${b}: ${w}`)}if(!y(R)){const A=Array.isArray(R)?"array":R===null?"null":typeof R;throw new Error(`givens: file at ${b} must be a JSON object of name → value pairs, got ${A}`)}return R})()),this._resolvedGivensPromise):Promise.resolve(void 0)}_invalidateGivensCache(){this._resolvedGivensPromise=void 0}get virtualMap(){var _,b;return(_=this._virtualMap)!==null&&_!==void 0?_:(b=this._config)===null||b===void 0?void 0:b.virtualMap}set virtualMap(_){this._virtualMap=_}async shutdown(_="close"){var b;await((b=this._config)===null||b===void 0?void 0:b.shutdown(_))}async releaseConnections(){await this.shutdown("close")}loadModel(_,b){const{refreshSchemaCache:C,noThrowOnError:R}=b||{};this.isTestRuntime&&(b===void 0?b={testEnvironment:!0}:b={...b,testEnvironment:!0});const A=_ instanceof URL?{url:_}:{source:_};return new d(this,async()=>{const w=await a.Malloy.compile({...A,urlReader:this.urlReader,connections:this.connections,refreshSchemaCache:C,noThrowOnError:R,eventStream:this.eventStream,importBaseURL:b==null?void 0:b.importBaseURL,testEnvironment:b==null?void 0:b.testEnvironment,cacheManager:this.cacheManager});return this._withRuntimeContext(w)},b)}_withRuntimeContext(_){return this._finalizedGivensSet.size===0?_:new o.Model(_._modelDef,_.problems,_.fromSources,_.getExistingQueryModel(),{finalizedGivens:this._finalizedGivensSet})}_loadModelFromModelDef(_,b){return new d(this,async()=>new o.Model(_,[],[],void 0,this._finalizedGivensSet.size>0?{finalizedGivens:this._finalizedGivensSet}:void 0),b)}loadQuery(_,b){return this.loadModel(_,b).loadFinalQuery()}loadQueryByIndex(_,b,C){return this.loadModel(_,C).loadQueryByIndex(b,C)}loadQueryByName(_,b,C){return this.loadModel(_,C).loadQueryByName(b,C)}getModel(_,b){return this.loadModel(_,b).getModel()}getQuery(_,b){return this.loadQuery(_,b).getPreparedQuery()}getQueryByIndex(_,b,C){return this.loadQueryByIndex(_,b,C).getPreparedQuery()}getQueryByName(_,b,C){return this.loadQueryByName(_,b,C).getPreparedQuery()}}cs.Runtime=c;class l extends c{constructor({urlReader:_,connections:b}){super({connections:s.FixedConnectionMap.fromArray(b),urlReader:_}),this.rawConnections=b}}cs.ConnectionRuntime=l;class f extends c{constructor({urlReader:_,connection:b,eventStream:C,cacheManager:R}){super({urlReader:_,eventStream:C,cacheManager:R,connection:b}),this.connection=b}get supportsNesting(){return(0,t.getDialect)(this.connection.dialectName).supportsNesting}quote(_){return(0,t.getDialect)(this.connection.dialectName).sqlQuoteIdentifier(_)}get dialect(){return(0,t.getDialect)(this.connection.dialectName)}getQuoter(){return _=>this.quote(_.toString())}}cs.SingleConnectionRuntime=f;class d extends u{constructor(_,b,C){super(_,b),this.runtime=_,this.compileQueryOptions=C}loadFinalQuery(_){return this.makeQueryMaterializer(async()=>(await this.materialize()).getPreparedQuery(),{...this.compileQueryOptions,..._})}loadQueryByIndex(_,b){return this.makeQueryMaterializer(async()=>(await this.materialize()).getPreparedQueryByIndex(_),{...this.compileQueryOptions,...b})}loadQueryByName(_,b){return this.makeQueryMaterializer(async()=>(await this.materialize()).getPreparedQueryByName(_),{...this.compileQueryOptions,...b})}loadQuery(_,b){const{importBaseURL:C,testEnvironment:R,refreshSchemaCache:A,noThrowOnError:w,restrictedMode:T,method:O,...F}=b??{},N={...this.compileQueryOptions,...F};return this.makeQueryMaterializer(async()=>{const $=_ instanceof URL?{url:_}:{source:_};return(await a.Malloy.compile({...$,urlReader:this.runtime.urlReader,connections:this.runtime.connections,model:await this.getModel(),refreshSchemaCache:A,noThrowOnError:w,importBaseURL:C,testEnvironment:R||this.runtime.isTestRuntime,...N})).preparedQuery},N)}loadRestrictedQuery(_){return this.makeQueryMaterializer(async()=>{const b=this.runtime.urlReader,C=this.runtime.connections,R=this.runtime.isTestRuntime?!0:void 0,A=await this.getModel();return(await a.Malloy.compile({source:_,restrictedMode:!0,method:"query",urlReader:b,connections:C,model:A,testEnvironment:R,...this.compileQueryOptions})).preparedQuery})}extendModel(_,b){return this.runtime.isTestRuntime&&(b===void 0?b={testEnvironment:!0}:b={...b,testEnvironment:!0}),new d(this.runtime,async()=>{const C=this.runtime.urlReader,R=this.runtime.connections,A=_ instanceof URL?{url:_}:{source:_},w=await this.getModel(),T=await a.Malloy.compile({...A,urlReader:C,connections:R,model:w,method:"extendModel",refreshSchemaCache:b==null?void 0:b.refreshSchemaCache,noThrowOnError:b==null?void 0:b.noThrowOnError,importBaseURL:b==null?void 0:b.importBaseURL,testEnvironment:b==null?void 0:b.testEnvironment,...this.compileQueryOptions});return this.runtime._withRuntimeContext(T)},b)}async search(_,b,C=1e3,R=void 0){const A=await this.materialize(),w=A.queryModel,T=A.getExploreByName(_).structDef;if(!(0,e.isSourceDef)(T))throw new Error("Source to be searched was unexpectedly, not a source");const O=T.connection,F=await this.runtime.connections.lookupConnection(O);return await w.searchIndex(F,_,b,C,R)}async searchValueMap(_,b=10,C){const A=(await this.materialize()).getExploreByName(_);if(!(0,e.isSourceDef)(A.structDef))throw new Error("Source to be searched was unexpectedly, not a source");let w="{index: *}";A.getFieldByNameIfExists("search_index")&&(w="search_index");const T=`
|
|
1385
1385
|
run: ${_}
|
|
1386
1386
|
-> ${w}
|
|
1387
1387
|
-> {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@malloydata/render",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.426",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/module/index.umd.js",
|
|
6
6
|
"types": "dist/module/index.d.ts",
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"generate-flow": "ts-node ../../scripts/gen-flow.ts"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@malloydata/malloy-interfaces": "0.0.
|
|
35
|
-
"@malloydata/malloy-tag": "0.0.
|
|
34
|
+
"@malloydata/malloy-interfaces": "0.0.426",
|
|
35
|
+
"@malloydata/malloy-tag": "0.0.426",
|
|
36
36
|
"@tanstack/solid-virtual": "^3.13.33",
|
|
37
37
|
"lodash": "^4.18.1",
|
|
38
38
|
"luxon": "^3.7.2",
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
"vega-lite": "^5.2.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@malloydata/db-duckdb": "0.0.
|
|
48
|
-
"@malloydata/malloy": "0.0.
|
|
47
|
+
"@malloydata/db-duckdb": "0.0.426",
|
|
48
|
+
"@malloydata/malloy": "0.0.426",
|
|
49
49
|
"@storybook/addon-essentials": "^8.6.18",
|
|
50
50
|
"@storybook/addon-interactions": "^8.6.18",
|
|
51
51
|
"@storybook/addon-links": "^8.6.15",
|