@malloydata/render 0.0.410 → 0.0.411
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
CHANGED
|
@@ -82062,7 +82062,7 @@ function dj() {
|
|
|
82062
82062
|
}
|
|
82063
82063
|
var Z1 = {}, _A = {}, Zoe;
|
|
82064
82064
|
function dIe() {
|
|
82065
|
-
return Zoe || (Zoe = 1, Object.defineProperty(_A, "__esModule", { value: !0 }), _A.MALLOY_VERSION = void 0, _A.MALLOY_VERSION = "0.0.
|
|
82065
|
+
return Zoe || (Zoe = 1, Object.defineProperty(_A, "__esModule", { value: !0 }), _A.MALLOY_VERSION = void 0, _A.MALLOY_VERSION = "0.0.411"), _A;
|
|
82066
82066
|
}
|
|
82067
82067
|
var eae;
|
|
82068
82068
|
function Hme() {
|
package/dist/module/index.umd.js
CHANGED
|
@@ -1367,7 +1367,7 @@ ${ce}`:G=ce}return G}childRequest(G){var ee;const oe=decodeURI(new URL(G,this.so
|
|
|
1367
1367
|
`)}}this.stream.write(`
|
|
1368
1368
|
]
|
|
1369
1369
|
`),this.stream.close()}}Ad.JSONWriter=n;class r extends t{constructor(){super(...arguments),this.columnSeparator=",",this.rowSeparator=`
|
|
1370
|
-
`,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 Ad.CSVWriter=r,Ad}var os={},px={},GR={},_a={},Vle;function jA(){if(Vle)return _a;Vle=1,Object.defineProperty(_a,"__esModule",{value:!0}),_a.isConnectionConfigEntry=e,_a.registerConnectionType=n,_a.getConnectionProperties=r,_a.getConnectionTypeDisplayName=i,_a.getRegisteredConnectionTypes=s,_a.getConnectionTypeDef=o,_a.validateConnectionConfigProperties=a,_a.readConnectionsConfig=u,_a.writeConnectionsConfig=c,_a.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,m;const g=(m=(x=t.get(d))===null||x===void 0?void 0:x.properties)!==null&&m!==void 0?m:[];for(const y of g){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(([,m])=>e(m)));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,m=new Map;return{async lookupConnection(g){if(g===void 0&&(g=x),g===void 0)throw new Error("No connections defined in config");const y=m.get(g);if(y)return y;const E=f.connections[g];if(!E)throw new Error(`No connection named "${g}" found in config`);const v=t.get(E.is);if(!v)throw new Error(`No registered connection type "${E.is}" for connection "${g}". Did you forget to import the connection package?`);const _={name:g};for(const[C,S]of Object.entries(E))C!=="is"&&S!=null&&(_[C]=S);a(g,E.is,_);const A=await v.factory(_);return d&&d(g,A),m.set(g,A),A},async close(){const g=[...m.values()];m.clear();for(const y of g)await y.close()},async idle(){for(const g of m.values())await g.idle()}}}return _a}var Gle;function cIe(){if(Gle)return GR;Gle=1,Object.defineProperty(GR,"__esModule",{value:!0}),GR.compileConfig=i;const e=jA(),t=hZ(),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[A,C]of Object.entries(E)){const S=n[A];if(!S){const D=(0,t.closestMatch)(A,[...r]),R=D?`. Did you mean "${D}"?`:"";v.push(m(A,`unknown config key "${A}"${R}`));continue}const T=S(C,v);T!==void 0&&(_.entries[A]=T)}return{compiled:_,log:v}}function s(E,v){if(!x(E)){v.push(m("connections",'"connections" should be an object'));return}const _=new Set((0,e.getRegisteredConnectionTypes)()),A={kind:"dict",entries:{}};for(const[C,S]of Object.entries(E)){const T=`connections.${C}`;if(!x(S)){v.push(m(T,"should be an object"));continue}const D=S.is;if(D==null||D===""){v.push(m(T,'missing required "is" field (connection type)'));continue}if(typeof D!="string"){v.push(m(`${T}.is`,'"is" should be a string'));continue}if(!_.has(D)){const O=(0,t.closestMatch)(D,[..._]),F=O?` Did you mean "${O}"?`:"";v.push(m(`${T}.is`,`unknown connection type "${D}".${F} Available types: ${[..._].join(", ")}`));continue}const R=o(T,D,S,v);A.entries[C]=R}return A}function o(E,v,_,A){var C;const S=(C=(0,e.getConnectionProperties)(v))!==null&&C!==void 0?C:[],T=new Map(S.map(R=>[R.name,R])),D={kind:"dict",entries:{}};D.entries.is={kind:"value",value:v};for(const[R,O]of Object.entries(_)){if(R==="is")continue;const F=T.get(R);if(!F){const q=(0,t.closestMatch)(R,[...T.keys()]),H=q?`. Did you mean "${q}"?`:"";A.push(m(`${E}.${R}`,`unknown property "${R}" for connection type "${v}"${H}`));continue}const L=a(`${E}.${R}`,F,O,A);L!==void 0&&(D.entries[R]=L)}return D}function a(E,v,_,A){if(_==null)return;if(v.type==="json")return{kind:"value",value:_};const C=p(_);if(C!==void 0)return v.requireLiteralString?(A.push(m(E,"must be a literal string and cannot use an overlay reference")),{kind:"value",value:_}):C;const S=y(_,v.type);if(S){if(v.requireLiteralString)return A.push(m(E,`must be a literal string, got ${g(_)}`)),{kind:"value",value:_};A.push(m(E,`${S} (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(m("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(m("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(m("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],A=E[_];if(typeof A=="string")return{kind:"reference",source:_,path:[A]};if(Array.isArray(A)&&A.every(C=>typeof C=="string"))return{kind:"reference",source:_,path:A}}function x(E){return typeof E=="object"&&E!==null&&!Array.isArray(E)}function m(E,v){return{message:`${E}: ${v}`,severity:"warn",code:"config-validation"}}function g(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 GR}var WR={},U1={},Wle;function fk(){if(Wle)return U1;Wle=1;var e={};Object.defineProperty(U1,"__esModule",{value:!0}),U1.envOverlay=t,U1.contextOverlay=n,U1.defaultConfigOverlays=r,U1.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 U1}var Yle;function fIe(){if(Yle)return WR;Yle=1,Object.defineProperty(WR,"__esModule",{value:!0}),WR.prepareConfig=n;const e=jA(),t=fk();function n(a,u,c){let l={},f,d,p,x,m=!1;for(const[g,y]of Object.entries(a.entries))switch(g){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"&&(m=y.value);break}}return m&&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 WR}var YR={},Kle;function dIe(){if(Kle)return YR;Kle=1,Object.defineProperty(YR,"__esModule",{value:!0}),YR.buildManagedLookup=t;const e=jA();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 m=a[p];if(!m)throw new Error(`No connection named "${p}" found in config`);const g=await n(m,u,c);if(typeof g.is!="string")throw new Error(`Connection "${p}" is missing a valid "is" field`);const y=(0,e.getConnectionTypeDef)(g.is);if(!y)throw new Error(`No registered connection type "${g.is}" for connection "${p}". Did you forget to import the connection package?`);const E={name:p};for(const[_,A]of Object.entries(g))_!=="is"&&A!=null&&(E[_]=A);(0,e.validateConnectionConfigProperties)(p,g.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 YR}var Xle;function dk(){if(Xle)return px;Xle=1,Object.defineProperty(px,"__esModule",{value:!0}),px.MalloyConfig=px.Manifest=void 0,px.isBuildManifestEntry=E;const e=cIe(),t=fIe(),n=dIe(),r=fk(),i=uk();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(_,A){(0,i.requireCanonicalTablePathAnyDialect)(A.tableName,`Manifest entry '${_}'`),this._manifest.entries[_]=A,this._touched.add(_)}touch(_){this._touched.add(_)}get activeEntries(){const _={};for(const A of this._touched)this._manifest.entries[A]&&(_[A]=this._manifest.entries[A]);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 A=y(_.entries)?_.entries:_;for(const[C,S]of Object.entries(A))C==="strict"||!E(S)||((0,i.requireCanonicalTablePathAnyDialect)(S.tableName,`Manifest entry '${C}'`),this._manifest.entries[C]=S)}}px.Manifest=s;class o{constructor(_,A){const C=[];let S;if(typeof _=="string")try{S=JSON.parse(_)}catch(q){C.push({message:`Invalid JSON: ${q instanceof Error?q.message:String(q)}`,severity:"error",code:"config-validation"}),S={}}else S=_;const T=(0,e.compileConfig)(S);C.push(...T.log);const D=f(A,C),R=m(D.configURL,"configURL",C),O=D.rootDirectory,F={...(0,r.defaultConfigOverlays)(),...D.overlays,config:(0,r.contextOverlay)({configURL:R,rootDirectory:O})},L=(0,t.prepareConfig)(T.compiled,F,C);this._managedLookup=(0,n.buildManagedLookup)(L.compiledConnections,F,C),this._connections=this._managedLookup,this._overlays=F,this.virtualMap=g(L.virtualMap,C),this.configURL=R,this.rootDirectory=O,this.manifestPath=L.manifestPath,this.manifestURL=c(L.manifestPath,R),this.givensPath=L.givensPath,this.givensURL=l(L.givensPath,R,C),this.finalizeGivens=L.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(_,...A){var C,S;return await((S=(C=this._overlays)[_])===null||S===void 0?void 0:S.call(C,A))}}px.MalloyConfig=o;const a="MANIFESTS",u="malloy-manifest.json";function c(v,_){if(!_)return;let A;try{A=new URL(_)}catch{return}const C=v??a;let S;try{S=new URL(C,A)}catch{return}const T=S.toString(),D=T.endsWith("/")?S:new URL(T+"/");return new URL(u,D).toString()}function l(v,_,A){if(!v)return;if(!_){A.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(S){const T=S instanceof Error?S.message:String(S);A.push({message:`givensPath '${v}' could not be resolved against configURL '${_}': ${T}`,severity:"warn",code:"config-validation"});return}}function f(v,_){if(v===void 0)return{};if(d(v))return p(v,_);const A=v;if(A.overlays&&"config"in A.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,...S}=A.overlays;return{...A,overlays:S}}return A}function d(v){for(const _ of Object.values(v))if(typeof _=="function")return!0;return!1}function p(v,_){const A=v.config;if(!A)return{overlays:v};const C=x(A,"configURL",_),S=x(A,"rootDirectory",_),{config:T,...D}=v;return{configURL:C,rootDirectory:S,overlays:D}}function x(v,_,A){const C=v([_]);if((0,r.isThenable)(C)){A.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 m(v,_,A){if(v!==void 0)try{return new URL(v),v}catch{A.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 g(v,_){if(!y(v))return;const A=new Map;for(const[C,S]of Object.entries(v)){if(!y(S))continue;const T=new Map;for(const[D,R]of Object.entries(S)){if(typeof R!="string")continue;const O=(0,i.validateCanonicalTablePathAnyDialect)(R);if(O!==void 0){_.push({message:`virtualMap entry '${C}.${D}': ${O}`,severity:"error",code:"config-validation"});continue}T.set(D,R)}T.size>0&&A.set(C,T)}return A.size>0?A: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 px}var j1={},zA={},Jle;function hIe(){return Jle||(Jle=1,Object.defineProperty(zA,"__esModule",{value:!0}),zA.MALLOY_VERSION=void 0,zA.MALLOY_VERSION="0.0.410"),zA}var Zle;function ece(){if(Zle)return j1;Zle=1,Object.defineProperty(j1,"__esModule",{value:!0}),j1.Malloy=j1.MalloyError=void 0;const e=lk(),t=jA(),n=vi(),r=lR(),i=hIe(),s=QR(),o=Ule(),a=em,u=VR(),c=Hle();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(m,g=[]){super(m),this.problems=g}}j1.MalloyError=d;class p{static get version(){return i.MALLOY_VERSION}static registerConnectionType(m,g){(0,t.registerConnectionType)(m,g)}static getConnectionProperties(m){return(0,t.getConnectionProperties)(m)}static getConnectionTypeDisplayName(m){return(0,t.getConnectionTypeDisplayName)(m)}static getRegisteredConnectionTypes(){return(0,t.getRegisteredConnectionTypes)()}static _parse(m,g,y,E,v){var _;g===void 0&&(g=new URL(l(E==null?void 0:E.method)));let A=g;E!=null&&E.importBaseURL&&(A=E==null?void 0:E.importBaseURL);const C=new e.MalloyTranslator(g.toString(),A.toString(),{urls:{[g.toString()]:m}},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:m,urlReader:g,source:y,eventStream:E,options:v}){if(y!==void 0)return p._parse(y,m,E,v);if(g===void 0)throw new Error("Internal Error: urlReader is required.");if(m===void 0)throw new Error("Internal Error: url is required if source not present.");return(0,s.readURL)(g,m).then(({contents:_,invalidationKey:A})=>p._parse(_,m,E,v,A))}static async compile(m){var g,y,E,v,_;let{url:A,source:C,importBaseURL:S,cacheManager:T}=m;const{parse:D,urlReader:R,connections:O,model:F,refreshSchemaCache:L,noThrowOnError:q,eventStream:H,restrictedMode:J,method:ae}=m;J&&(T=void 0);let le;if(L&&(le=typeof L=="number"?L:Date.now()),A===void 0&&C===void 0&&D===void 0)throw new Error("Internal Error: url, source, or parse required.");A===void 0&&(D!==void 0?A=new URL(D._translator.sourceURL):A=new URL(l(ae)));const G={};if(C===void 0&&T!==void 0){const ce=await T.getCachedModelDef(R,A.toString());if(ce)return new u.Model(ce.modelDef,[],[A.toString(),...f(ce.modelDef.dependencies)])}S??(S=A);let ee;const oe=A.toString();if(D!==void 0){if(J!==void 0&&D._translator.restrictedMode!==J)throw new Error(`Malloy.compile: restrictedMode (${J}) does not match the pre-parsed translator's restrictedMode (${D._translator.restrictedMode}). Set restrictedMode at parse time.`);ee=D._translator;const ce=(g=D._invalidationKey)!==null&&g!==void 0?g:await(0,s.getInvalidationKey)(R,A);G[oe]=ce}else{if(C===void 0){const{contents:ce,invalidationKey:I}=await(0,s.readURL)(R,A);G[oe]=I,C=ce}else{const ce=await(0,s.getInvalidationKey)(R,A);G[oe]=ce}ee=new e.MalloyTranslator(oe,S.toString(),{urls:{[oe]:C}},H,J??!1)}for(;;){const ce=ee.translate(F==null?void 0:F._modelDef);if(ce.final)if(ce.modelDef){await(T==null?void 0:T.setCachedModelDef(A.toString(),{modelDef:ce.modelDef,invalidationKeys:G}));for(const B of ee.newlyTranslatedDependencies())await(T==null?void 0:T.setCachedModelDef(B.url,{modelDef:B.modelDef,invalidationKeys:G}));const I=!ce.modelWasModified&&F?F.getExistingQueryModel():void 0;return new u.Model(ce.modelDef,ce.problems||[],[...(y=F==null?void 0:F.fromSources)!==null&&y!==void 0?y:[],...(E=ce.fromSources)!==null&&E!==void 0?E:[]],I)}else if(q){const I=(0,n.mkModelDef)("modelDidNotCompile"),B=(F==null?void 0:F._modelDef)||I;return new u.Model(B,ce.problems||[],[...(v=F==null?void 0:F.fromSources)!==null&&v!==void 0?v:[],...(_=ce.fromSources)!==null&&_!==void 0?_:[]])}else{const I=ce.problems||[],B=ee.prettyErrors();throw new d(`Error(s) compiling model:
|
|
1370
|
+
`,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 Ad.CSVWriter=r,Ad}var os={},px={},GR={},_a={},Vle;function jA(){if(Vle)return _a;Vle=1,Object.defineProperty(_a,"__esModule",{value:!0}),_a.isConnectionConfigEntry=e,_a.registerConnectionType=n,_a.getConnectionProperties=r,_a.getConnectionTypeDisplayName=i,_a.getRegisteredConnectionTypes=s,_a.getConnectionTypeDef=o,_a.validateConnectionConfigProperties=a,_a.readConnectionsConfig=u,_a.writeConnectionsConfig=c,_a.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,m;const g=(m=(x=t.get(d))===null||x===void 0?void 0:x.properties)!==null&&m!==void 0?m:[];for(const y of g){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(([,m])=>e(m)));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,m=new Map;return{async lookupConnection(g){if(g===void 0&&(g=x),g===void 0)throw new Error("No connections defined in config");const y=m.get(g);if(y)return y;const E=f.connections[g];if(!E)throw new Error(`No connection named "${g}" found in config`);const v=t.get(E.is);if(!v)throw new Error(`No registered connection type "${E.is}" for connection "${g}". Did you forget to import the connection package?`);const _={name:g};for(const[C,S]of Object.entries(E))C!=="is"&&S!=null&&(_[C]=S);a(g,E.is,_);const A=await v.factory(_);return d&&d(g,A),m.set(g,A),A},async close(){const g=[...m.values()];m.clear();for(const y of g)await y.close()},async idle(){for(const g of m.values())await g.idle()}}}return _a}var Gle;function cIe(){if(Gle)return GR;Gle=1,Object.defineProperty(GR,"__esModule",{value:!0}),GR.compileConfig=i;const e=jA(),t=hZ(),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[A,C]of Object.entries(E)){const S=n[A];if(!S){const D=(0,t.closestMatch)(A,[...r]),R=D?`. Did you mean "${D}"?`:"";v.push(m(A,`unknown config key "${A}"${R}`));continue}const T=S(C,v);T!==void 0&&(_.entries[A]=T)}return{compiled:_,log:v}}function s(E,v){if(!x(E)){v.push(m("connections",'"connections" should be an object'));return}const _=new Set((0,e.getRegisteredConnectionTypes)()),A={kind:"dict",entries:{}};for(const[C,S]of Object.entries(E)){const T=`connections.${C}`;if(!x(S)){v.push(m(T,"should be an object"));continue}const D=S.is;if(D==null||D===""){v.push(m(T,'missing required "is" field (connection type)'));continue}if(typeof D!="string"){v.push(m(`${T}.is`,'"is" should be a string'));continue}if(!_.has(D)){const O=(0,t.closestMatch)(D,[..._]),F=O?` Did you mean "${O}"?`:"";v.push(m(`${T}.is`,`unknown connection type "${D}".${F} Available types: ${[..._].join(", ")}`));continue}const R=o(T,D,S,v);A.entries[C]=R}return A}function o(E,v,_,A){var C;const S=(C=(0,e.getConnectionProperties)(v))!==null&&C!==void 0?C:[],T=new Map(S.map(R=>[R.name,R])),D={kind:"dict",entries:{}};D.entries.is={kind:"value",value:v};for(const[R,O]of Object.entries(_)){if(R==="is")continue;const F=T.get(R);if(!F){const q=(0,t.closestMatch)(R,[...T.keys()]),H=q?`. Did you mean "${q}"?`:"";A.push(m(`${E}.${R}`,`unknown property "${R}" for connection type "${v}"${H}`));continue}const L=a(`${E}.${R}`,F,O,A);L!==void 0&&(D.entries[R]=L)}return D}function a(E,v,_,A){if(_==null)return;if(v.type==="json")return{kind:"value",value:_};const C=p(_);if(C!==void 0)return v.requireLiteralString?(A.push(m(E,"must be a literal string and cannot use an overlay reference")),{kind:"value",value:_}):C;const S=y(_,v.type);if(S){if(v.requireLiteralString)return A.push(m(E,`must be a literal string, got ${g(_)}`)),{kind:"value",value:_};A.push(m(E,`${S} (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(m("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(m("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(m("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],A=E[_];if(typeof A=="string")return{kind:"reference",source:_,path:[A]};if(Array.isArray(A)&&A.every(C=>typeof C=="string"))return{kind:"reference",source:_,path:A}}function x(E){return typeof E=="object"&&E!==null&&!Array.isArray(E)}function m(E,v){return{message:`${E}: ${v}`,severity:"warn",code:"config-validation"}}function g(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 GR}var WR={},U1={},Wle;function fk(){if(Wle)return U1;Wle=1;var e={};Object.defineProperty(U1,"__esModule",{value:!0}),U1.envOverlay=t,U1.contextOverlay=n,U1.defaultConfigOverlays=r,U1.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 U1}var Yle;function fIe(){if(Yle)return WR;Yle=1,Object.defineProperty(WR,"__esModule",{value:!0}),WR.prepareConfig=n;const e=jA(),t=fk();function n(a,u,c){let l={},f,d,p,x,m=!1;for(const[g,y]of Object.entries(a.entries))switch(g){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"&&(m=y.value);break}}return m&&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 WR}var YR={},Kle;function dIe(){if(Kle)return YR;Kle=1,Object.defineProperty(YR,"__esModule",{value:!0}),YR.buildManagedLookup=t;const e=jA();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 m=a[p];if(!m)throw new Error(`No connection named "${p}" found in config`);const g=await n(m,u,c);if(typeof g.is!="string")throw new Error(`Connection "${p}" is missing a valid "is" field`);const y=(0,e.getConnectionTypeDef)(g.is);if(!y)throw new Error(`No registered connection type "${g.is}" for connection "${p}". Did you forget to import the connection package?`);const E={name:p};for(const[_,A]of Object.entries(g))_!=="is"&&A!=null&&(E[_]=A);(0,e.validateConnectionConfigProperties)(p,g.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 YR}var Xle;function dk(){if(Xle)return px;Xle=1,Object.defineProperty(px,"__esModule",{value:!0}),px.MalloyConfig=px.Manifest=void 0,px.isBuildManifestEntry=E;const e=cIe(),t=fIe(),n=dIe(),r=fk(),i=uk();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(_,A){(0,i.requireCanonicalTablePathAnyDialect)(A.tableName,`Manifest entry '${_}'`),this._manifest.entries[_]=A,this._touched.add(_)}touch(_){this._touched.add(_)}get activeEntries(){const _={};for(const A of this._touched)this._manifest.entries[A]&&(_[A]=this._manifest.entries[A]);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 A=y(_.entries)?_.entries:_;for(const[C,S]of Object.entries(A))C==="strict"||!E(S)||((0,i.requireCanonicalTablePathAnyDialect)(S.tableName,`Manifest entry '${C}'`),this._manifest.entries[C]=S)}}px.Manifest=s;class o{constructor(_,A){const C=[];let S;if(typeof _=="string")try{S=JSON.parse(_)}catch(q){C.push({message:`Invalid JSON: ${q instanceof Error?q.message:String(q)}`,severity:"error",code:"config-validation"}),S={}}else S=_;const T=(0,e.compileConfig)(S);C.push(...T.log);const D=f(A,C),R=m(D.configURL,"configURL",C),O=D.rootDirectory,F={...(0,r.defaultConfigOverlays)(),...D.overlays,config:(0,r.contextOverlay)({configURL:R,rootDirectory:O})},L=(0,t.prepareConfig)(T.compiled,F,C);this._managedLookup=(0,n.buildManagedLookup)(L.compiledConnections,F,C),this._connections=this._managedLookup,this._overlays=F,this.virtualMap=g(L.virtualMap,C),this.configURL=R,this.rootDirectory=O,this.manifestPath=L.manifestPath,this.manifestURL=c(L.manifestPath,R),this.givensPath=L.givensPath,this.givensURL=l(L.givensPath,R,C),this.finalizeGivens=L.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(_,...A){var C,S;return await((S=(C=this._overlays)[_])===null||S===void 0?void 0:S.call(C,A))}}px.MalloyConfig=o;const a="MANIFESTS",u="malloy-manifest.json";function c(v,_){if(!_)return;let A;try{A=new URL(_)}catch{return}const C=v??a;let S;try{S=new URL(C,A)}catch{return}const T=S.toString(),D=T.endsWith("/")?S:new URL(T+"/");return new URL(u,D).toString()}function l(v,_,A){if(!v)return;if(!_){A.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(S){const T=S instanceof Error?S.message:String(S);A.push({message:`givensPath '${v}' could not be resolved against configURL '${_}': ${T}`,severity:"warn",code:"config-validation"});return}}function f(v,_){if(v===void 0)return{};if(d(v))return p(v,_);const A=v;if(A.overlays&&"config"in A.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,...S}=A.overlays;return{...A,overlays:S}}return A}function d(v){for(const _ of Object.values(v))if(typeof _=="function")return!0;return!1}function p(v,_){const A=v.config;if(!A)return{overlays:v};const C=x(A,"configURL",_),S=x(A,"rootDirectory",_),{config:T,...D}=v;return{configURL:C,rootDirectory:S,overlays:D}}function x(v,_,A){const C=v([_]);if((0,r.isThenable)(C)){A.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 m(v,_,A){if(v!==void 0)try{return new URL(v),v}catch{A.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 g(v,_){if(!y(v))return;const A=new Map;for(const[C,S]of Object.entries(v)){if(!y(S))continue;const T=new Map;for(const[D,R]of Object.entries(S)){if(typeof R!="string")continue;const O=(0,i.validateCanonicalTablePathAnyDialect)(R);if(O!==void 0){_.push({message:`virtualMap entry '${C}.${D}': ${O}`,severity:"error",code:"config-validation"});continue}T.set(D,R)}T.size>0&&A.set(C,T)}return A.size>0?A: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 px}var j1={},zA={},Jle;function hIe(){return Jle||(Jle=1,Object.defineProperty(zA,"__esModule",{value:!0}),zA.MALLOY_VERSION=void 0,zA.MALLOY_VERSION="0.0.411"),zA}var Zle;function ece(){if(Zle)return j1;Zle=1,Object.defineProperty(j1,"__esModule",{value:!0}),j1.Malloy=j1.MalloyError=void 0;const e=lk(),t=jA(),n=vi(),r=lR(),i=hIe(),s=QR(),o=Ule(),a=em,u=VR(),c=Hle();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(m,g=[]){super(m),this.problems=g}}j1.MalloyError=d;class p{static get version(){return i.MALLOY_VERSION}static registerConnectionType(m,g){(0,t.registerConnectionType)(m,g)}static getConnectionProperties(m){return(0,t.getConnectionProperties)(m)}static getConnectionTypeDisplayName(m){return(0,t.getConnectionTypeDisplayName)(m)}static getRegisteredConnectionTypes(){return(0,t.getRegisteredConnectionTypes)()}static _parse(m,g,y,E,v){var _;g===void 0&&(g=new URL(l(E==null?void 0:E.method)));let A=g;E!=null&&E.importBaseURL&&(A=E==null?void 0:E.importBaseURL);const C=new e.MalloyTranslator(g.toString(),A.toString(),{urls:{[g.toString()]:m}},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:m,urlReader:g,source:y,eventStream:E,options:v}){if(y!==void 0)return p._parse(y,m,E,v);if(g===void 0)throw new Error("Internal Error: urlReader is required.");if(m===void 0)throw new Error("Internal Error: url is required if source not present.");return(0,s.readURL)(g,m).then(({contents:_,invalidationKey:A})=>p._parse(_,m,E,v,A))}static async compile(m){var g,y,E,v,_;let{url:A,source:C,importBaseURL:S,cacheManager:T}=m;const{parse:D,urlReader:R,connections:O,model:F,refreshSchemaCache:L,noThrowOnError:q,eventStream:H,restrictedMode:J,method:ae}=m;J&&(T=void 0);let le;if(L&&(le=typeof L=="number"?L:Date.now()),A===void 0&&C===void 0&&D===void 0)throw new Error("Internal Error: url, source, or parse required.");A===void 0&&(D!==void 0?A=new URL(D._translator.sourceURL):A=new URL(l(ae)));const G={};if(C===void 0&&T!==void 0){const ce=await T.getCachedModelDef(R,A.toString());if(ce)return new u.Model(ce.modelDef,[],[A.toString(),...f(ce.modelDef.dependencies)])}S??(S=A);let ee;const oe=A.toString();if(D!==void 0){if(J!==void 0&&D._translator.restrictedMode!==J)throw new Error(`Malloy.compile: restrictedMode (${J}) does not match the pre-parsed translator's restrictedMode (${D._translator.restrictedMode}). Set restrictedMode at parse time.`);ee=D._translator;const ce=(g=D._invalidationKey)!==null&&g!==void 0?g:await(0,s.getInvalidationKey)(R,A);G[oe]=ce}else{if(C===void 0){const{contents:ce,invalidationKey:I}=await(0,s.readURL)(R,A);G[oe]=I,C=ce}else{const ce=await(0,s.getInvalidationKey)(R,A);G[oe]=ce}ee=new e.MalloyTranslator(oe,S.toString(),{urls:{[oe]:C}},H,J??!1)}for(;;){const ce=ee.translate(F==null?void 0:F._modelDef);if(ce.final)if(ce.modelDef){await(T==null?void 0:T.setCachedModelDef(A.toString(),{modelDef:ce.modelDef,invalidationKeys:G}));for(const B of ee.newlyTranslatedDependencies())await(T==null?void 0:T.setCachedModelDef(B.url,{modelDef:B.modelDef,invalidationKeys:G}));const I=!ce.modelWasModified&&F?F.getExistingQueryModel():void 0;return new u.Model(ce.modelDef,ce.problems||[],[...(y=F==null?void 0:F.fromSources)!==null&&y!==void 0?y:[],...(E=ce.fromSources)!==null&&E!==void 0?E:[]],I)}else if(q){const I=(0,n.mkModelDef)("modelDidNotCompile"),B=(F==null?void 0:F._modelDef)||I;return new u.Model(B,ce.problems||[],[...(v=F==null?void 0:F.fromSources)!==null&&v!==void 0?v:[],...(_=ce.fromSources)!==null&&_!==void 0?_:[]])}else{const I=ce.problems||[],B=ee.prettyErrors();throw new d(`Error(s) compiling model:
|
|
1371
1371
|
${B}`,I)}else{if(ce.urls)for(const I of ce.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(T!==void 0){const $=await T.getCachedModelDef(R,I);if($){for(const N in $.invalidationKeys)G[N]=$.invalidationKeys[N];ee.update({translations:{[I]:$.modelDef}});continue}}const{contents:B,invalidationKey:z}=await(0,s.readURL)(R,new URL(I)),M={[I]:B};G[I]=z,ee.update({urls:M})}catch(B){ee.update({errors:{urls:{[I]:B.message}}})}if(ce.tables){const I=new Map;for(const B in ce.tables){const{connectionName:z,tablePath:M}=ce.tables[B],$=I.get(z);$===void 0?I.set(z,{[B]:M}):$[B]=M}for(const[B,z]of I)try{const M=await O.lookupConnection(B),{schemas:$,errors:N}=await p.safelyFetchTableSchema(M,z,{refreshTimestamp:le});ee.update({tables:$,errors:{tables:N}})}catch(M){const $={},N={};for(const k in z)N[k]=M.toString();ee.update({tables:$,errors:{tables:N}})}}if(ce.connectionDialects)for(const I in ce.connectionDialects){const{connectionName:B}=ce.connectionDialects[I];try{const z=await O.lookupConnection(B);ee.update({connectionDialects:{[I]:z.dialectName}})}catch(z){ee.update({errors:{connectionDialects:{[I]:z.toString()}}})}}if(ce.compileSQL){const I=ce.compileSQL,B=I.connection,z=(0,r.sqlKey)(I.connection,I.selectStr);try{const $=await(await O.lookupConnection(B)).fetchSchemaForSQLStruct(I,{refreshTimestamp:le});$.error&&ee.update({errors:{compileSQL:{[z]:$.error}}}),$.structDef&&ee.update({compileSQL:{[z]:$.structDef}})}catch(M){const $={};$[z]=M.toString(),ee.update({errors:{compileSQL:$}})}}}}}static async safelyFetchTableSchema(m,g,y){const E=await m.fetchSchemaForTables(g,y);for(const v of Object.keys(g))if(E.schemas[v]===void 0&&E.errors[v]===void 0)throw new Error(`Schema fetch error for ${m.name}, no response for ${v} from ${m.dialectName}`);return E}static async run({connections:m,preparedResult:g,sqlStruct:y,connection:E,options:v}){if(!E){if(!m)throw new Error("Internal Error: Connection or LookupConnection<Connection> must be provided.");const _=(y==null?void 0:y.connection)||(g==null?void 0:g.connectionName);E=await m.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(g){const _=await E.runSQL(g.sql,v);return new c.Result({...g._rawQuery,result:_.rows,totalRows:_.totalRows,runStats:_.runStats,profilingUrl:_.profilingUrl},g._modelDef)}else throw new Error("Internal error: sqlStruct or preparedResult must be provided.")}static async*runStream({connections:m,preparedResult:g,sqlStruct:y,connection:E,options:v}){if(y===void 0&&g===void 0)throw new Error("Internal error: sqlBlock or preparedResult must be provided.");const _=(y==null?void 0:y.connection)||(g==null?void 0:g.connectionName);if(E===void 0){if(m===void 0)throw new Error("Internal Error: Connection or LookupConnection<Connection> must be provided.");E=await m.lookupConnection(_)}if(!E.canStream())throw new Error(`Connection '${_}' cannot stream results.`);let A,C;if(y)C=new u.Explore((0,u.pseudoModelFor)(y),y),A=y.selectStr;else if(g!==void 0)C=g.resultExplore,A=g.sql;else throw new Error("Internal error: sqlStruct or preparedResult must be provided.");let S=0;for await(const T of E.runSQLStream(A,v))yield new c.DataRecord(T,S,C,void 0,void 0),S+=1}static async estimateQueryCost({connections:m,preparedResult:g,sqlStruct:y}){if(!m)throw new Error("Internal Error: Connection or LookupConnection<Connection> must be provided.");const E=(y==null?void 0:y.connection)||(g==null?void 0:g.connectionName),v=await m.lookupConnection(E);if(y)return await v.estimateQueryCost(y.selectStr);if(g)return await v.estimateQueryCost(g.sql);throw new Error("Internal error: sqlStruct or preparedResult must be provided.")}}return j1.Malloy=p,j1}var tce;function xIe(){if(tce)return os;tce=1,Object.defineProperty(os,"__esModule",{value:!0}),os.ExploreMaterializer=os.PreparedResultMaterializer=os.QueryMaterializer=os.ModelMaterializer=os.SingleConnectionRuntime=os.ConnectionRuntime=os.Runtime=void 0;const e=vi(),t=u0(),n=uk(),r=dk(),i=Qv(),s=QR(),o=VR(),a=ece();class u{constructor(_,A){this.runtime=_,this._materialize=A}materialize(){return this.materialized===void 0?this.rematerialize():this.materialized}rematerialize(){return this.materialized=this._materialize(),this.materialized}makeQueryMaterializer(_,A){return new p(this.runtime,_,A)}makeExploreMaterializer(_,A){return new m(this.runtime,_,A)}makePreparedResultMaterializer(_){return new x(this.runtime,_)}}class c{constructor({urlReader:_,connections:A,connection:C,config:S,buildManifest:T,eventStream:D,cacheManager:R,givens:O}){var F,L;if(this.isTestRuntime=!1,S!==void 0)this._config=S,A=A??S.connections;else if(A===void 0){if(C===void 0)throw new Error("A MalloyConfig, LookupConnection<Connection>, or Connection is required.");A={lookupConnection:()=>Promise.resolve(C)}}if(_===void 0&&(_=new s.EmptyURLReader),this._urlReader=_,this._connections=A,this._buildManifest=T,this._eventStream=D,this._cacheManager=R,O){for(const[q,H]of Object.entries(O))if(H===void 0)throw new Error(`Runtime givens.${q}: 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((L=(F=this._config)===null||F===void 0?void 0:F.finalizeGivens)!==null&&L!==void 0?L:[])}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(),A=new Map;if(_)for(const[C,S]of Object.entries(_))A.set(C,S);for(const[C,S]of this._constructorGivensMap)A.set(C,S);return A}get _finalizedGivens(){return this._finalizedGivensSet}set buildManifest(_){this._buildManifest=_,this._resolvedBuildManifestPromise=void 0}_resolveBuildManifest(){var _;if(this._buildManifest)return Promise.resolve(this._buildManifest);const A=(_=this._config)===null||_===void 0?void 0:_.manifestURL;return A?(this._resolvedBuildManifestPromise||(this._resolvedBuildManifestPromise=(async()=>{let C;try{const S=await this._urlReader.readURL(new URL(A));C=typeof S=="string"?S:S.contents}catch{return}try{const S=JSON.parse(C);if(!g(S))throw new Error('manifest is not an object with an "entries" map');for(const[T,D]of Object.entries(S.entries)){if(!(0,r.isBuildManifestEntry)(D))throw new Error(`Manifest entry '${T}' is missing a string tableName`);(0,n.requireCanonicalTablePathAnyDialect)(D.tableName,`Manifest entry '${T}'`)}return S}catch(S){const T=S instanceof Error?S.message:String(S);return{entries:{},loadError:`Manifest file at ${A} could not be parsed: ${T}`}}})()),this._resolvedBuildManifestPromise):Promise.resolve(void 0)}_resolveGivens(){var _;const A=(_=this._config)===null||_===void 0?void 0:_.givensURL;return A?(this._resolvedGivensPromise||(this._resolvedGivensPromise=(async()=>{let C;try{const T=await this._urlReader.readURL(new URL(A));C=typeof T=="string"?T:T.contents}catch(T){const D=T instanceof Error?T.message:String(T);throw new Error(`givens: failed to read givens file at ${A}: ${D}`)}let S;try{S=JSON.parse(C)}catch(T){const D=T instanceof Error?T.message:String(T);throw new Error(`givens: failed to parse JSON at ${A}: ${D}`)}if(!y(S)){const T=Array.isArray(S)?"array":S===null?"null":typeof S;throw new Error(`givens: file at ${A} must be a JSON object of name → value pairs, got ${T}`)}return S})()),this._resolvedGivensPromise):Promise.resolve(void 0)}_invalidateGivensCache(){this._resolvedGivensPromise=void 0}get virtualMap(){var _,A;return(_=this._virtualMap)!==null&&_!==void 0?_:(A=this._config)===null||A===void 0?void 0:A.virtualMap}set virtualMap(_){this._virtualMap=_}async shutdown(_="close"){var A;await((A=this._config)===null||A===void 0?void 0:A.shutdown(_))}async releaseConnections(){await this.shutdown("close")}loadModel(_,A){const{refreshSchemaCache:C,noThrowOnError:S}=A||{};this.isTestRuntime&&(A===void 0?A={testEnvironment:!0}:A={...A,testEnvironment:!0});const T=_ instanceof URL?{url:_}:{source:_};return new d(this,async()=>{const D=await a.Malloy.compile({...T,urlReader:this.urlReader,connections:this.connections,refreshSchemaCache:C,noThrowOnError:S,eventStream:this.eventStream,importBaseURL:A==null?void 0:A.importBaseURL,testEnvironment:A==null?void 0:A.testEnvironment,cacheManager:this.cacheManager});return this._withRuntimeContext(D)},A)}_withRuntimeContext(_){return this._finalizedGivensSet.size===0?_:new o.Model(_._modelDef,_.problems,_.fromSources,_.getExistingQueryModel(),{finalizedGivens:this._finalizedGivensSet})}_loadModelFromModelDef(_,A){return new d(this,async()=>new o.Model(_,[],[],void 0,this._finalizedGivensSet.size>0?{finalizedGivens:this._finalizedGivensSet}:void 0),A)}loadQuery(_,A){return this.loadModel(_,A).loadFinalQuery()}loadQueryByIndex(_,A,C){return this.loadModel(_,C).loadQueryByIndex(A,C)}loadQueryByName(_,A,C){return this.loadModel(_,C).loadQueryByName(A,C)}getModel(_,A){return this.loadModel(_,A).getModel()}getQuery(_,A){return this.loadQuery(_,A).getPreparedQuery()}getQueryByIndex(_,A,C){return this.loadQueryByIndex(_,A,C).getPreparedQuery()}getQueryByName(_,A,C){return this.loadQueryByName(_,A,C).getPreparedQuery()}}os.Runtime=c;class l extends c{constructor({urlReader:_,connections:A}){super({connections:s.FixedConnectionMap.fromArray(A),urlReader:_}),this.rawConnections=A}}os.ConnectionRuntime=l;class f extends c{constructor({urlReader:_,connection:A,eventStream:C,cacheManager:S}){super({urlReader:_,eventStream:C,cacheManager:S,connection:A}),this.connection=A}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())}}os.SingleConnectionRuntime=f;class d extends u{constructor(_,A,C){super(_,A),this.runtime=_,this.compileQueryOptions=C}loadFinalQuery(_){return this.makeQueryMaterializer(async()=>(await this.materialize()).getPreparedQuery(),{...this.compileQueryOptions,..._})}loadQueryByIndex(_,A){return this.makeQueryMaterializer(async()=>(await this.materialize()).getPreparedQueryByIndex(_),{...this.compileQueryOptions,...A})}loadQueryByName(_,A){return this.makeQueryMaterializer(async()=>(await this.materialize()).getPreparedQueryByName(_),{...this.compileQueryOptions,...A})}loadQuery(_,A){const{refreshSchemaCache:C,noThrowOnError:S}=A||{};return this.makeQueryMaterializer(async()=>{const T=this.runtime.urlReader,D=this.runtime.connections;this.runtime.isTestRuntime&&(A===void 0?A={testEnvironment:!0}:A={...A,testEnvironment:!0});const R=_ instanceof URL?{url:_}:{source:_},O=await this.getModel();return(await a.Malloy.compile({...R,urlReader:T,connections:D,model:O,refreshSchemaCache:C,noThrowOnError:S,importBaseURL:A==null?void 0:A.importBaseURL,testEnvironment:A==null?void 0:A.testEnvironment,...this.compileQueryOptions})).preparedQuery})}loadRestrictedQuery(_){return this.makeQueryMaterializer(async()=>{const A=this.runtime.urlReader,C=this.runtime.connections,S=this.runtime.isTestRuntime?!0:void 0,T=await this.getModel();return(await a.Malloy.compile({source:_,restrictedMode:!0,method:"query",urlReader:A,connections:C,model:T,testEnvironment:S,...this.compileQueryOptions})).preparedQuery})}extendModel(_,A){return this.runtime.isTestRuntime&&(A===void 0?A={testEnvironment:!0}:A={...A,testEnvironment:!0}),new d(this.runtime,async()=>{const C=this.runtime.urlReader,S=this.runtime.connections,T=_ instanceof URL?{url:_}:{source:_},D=await this.getModel(),R=await a.Malloy.compile({...T,urlReader:C,connections:S,model:D,method:"extendModel",refreshSchemaCache:A==null?void 0:A.refreshSchemaCache,noThrowOnError:A==null?void 0:A.noThrowOnError,importBaseURL:A==null?void 0:A.importBaseURL,testEnvironment:A==null?void 0:A.testEnvironment,...this.compileQueryOptions});return this.runtime._withRuntimeContext(R)},A)}async search(_,A,C=1e3,S=void 0){const T=await this.materialize(),D=T.queryModel,R=T.getExploreByName(_).structDef;if(!(0,e.isSourceDef)(R))throw new Error("Source to be searched was unexpectedly, not a source");const O=R.connection,F=await this.runtime.connections.lookupConnection(O);return await D.searchIndex(F,_,A,C,S)}async searchValueMap(_,A=10,C){const T=(await this.materialize()).getExploreByName(_);if(!(0,e.isSourceDef)(T.structDef))throw new Error("Source to be searched was unexpectedly, not a source");let D="{index: *}";T.getFieldByNameIfExists("search_index")&&(D="search_index");const R=`
|
|
1372
1372
|
run: ${_}
|
|
1373
1373
|
-> ${D}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@malloydata/render",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.411",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/module/index.umd.js",
|
|
6
6
|
"types": "dist/module/index.d.ts",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"generate-flow": "ts-node ../../scripts/gen-flow.ts"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@malloydata/malloy-interfaces": "0.0.
|
|
33
|
-
"@malloydata/malloy-tag": "0.0.
|
|
32
|
+
"@malloydata/malloy-interfaces": "0.0.411",
|
|
33
|
+
"@malloydata/malloy-tag": "0.0.411",
|
|
34
34
|
"@tanstack/solid-virtual": "^3.10.4",
|
|
35
35
|
"lodash": "^4.18.1",
|
|
36
36
|
"luxon": "^3.5.0",
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"vega-lite": "^5.2.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@malloydata/db-duckdb": "0.0.
|
|
46
|
-
"@malloydata/malloy": "0.0.
|
|
45
|
+
"@malloydata/db-duckdb": "0.0.411",
|
|
46
|
+
"@malloydata/malloy": "0.0.411",
|
|
47
47
|
"@storybook/addon-essentials": "^8.6.15",
|
|
48
48
|
"@storybook/addon-interactions": "^8.6.15",
|
|
49
49
|
"@storybook/addon-links": "^8.6.15",
|