@malloydata/render 0.0.401 → 0.0.402

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.
@@ -22875,16 +22875,10 @@ function Xx() {
22875
22875
  return i(this.annote, p).map((x) => x.text);
22876
22876
  }
22877
22877
  /**
22878
- * Your route's notes as {@link RoutedNote}s — for callers that parse the
22879
- * payload with their own parser (instead of MOTLY). Read `.content` to
22880
- * feed your parser, and `.at` + `.indentStripped` to map your parser's
22881
- * errors back to source.
22882
- *
22883
- * `malformed-route` annotations are excluded (no clean route to resolve
22884
- * to). `reserved-route` annotations are included — they parse to a real
22885
- * route and the user got a compile-time warning. Route filtering is
22886
- * level-blind (`#` and `##` both go to route `''`); the entity hands
22887
- * you the annotations that apply at its level.
22878
+ * Notes as {@link RoutedNote}s — for callers that parse the payload with
22879
+ * their own parser (instead of MOTLY). Pass a route to filter; omit it
22880
+ * to enumerate every annotation (the only way to reach malformed-prefix
22881
+ * ones). `malformed-route` annotations are excluded when filtering.
22888
22882
  */
22889
22883
  forRoute(p) {
22890
22884
  return i(this.annote, p);
@@ -82244,7 +82238,7 @@ function fj() {
82244
82238
  }
82245
82239
  var e2 = {}, vA = {}, Joe;
82246
82240
  function c9e() {
82247
- return Joe || (Joe = 1, Object.defineProperty(vA, "__esModule", { value: !0 }), vA.MALLOY_VERSION = void 0, vA.MALLOY_VERSION = "0.0.401"), vA;
82241
+ return Joe || (Joe = 1, Object.defineProperty(vA, "__esModule", { value: !0 }), vA.MALLOY_VERSION = void 0, vA.MALLOY_VERSION = "0.0.402"), vA;
82248
82242
  }
82249
82243
  var Xoe;
82250
82244
  function Ume() {
@@ -1364,7 +1364,7 @@ ${$}`:W=$}return W}childRequest(W){var ue;const Z=decodeURI(new URL(W,this.sourc
1364
1364
  `)}}this.stream.write(`
1365
1365
  ]
1366
1366
  `),this.stream.close()}}Ad.JSONWriter=n;class r extends t{constructor(){super(...arguments),this.columnSeparator=",",this.rowSeparator=`
1367
- `,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={},zle;function UA(){if(zle)return _a;zle=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 S={name:g};for(const[T,_]of Object.entries(E))T!=="is"&&_!=null&&(S[T]=_);a(g,E.is,S);const A=await v.factory(S);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 Hle;function uIe(){if(Hle)return GR;Hle=1,Object.defineProperty(GR,"__esModule",{value:!0}),GR.compileConfig=i;const e=UA(),t=Ple(),n={connections:s,manifestPath:u,givensPath:c,finalizeGivens:l,virtualMap:f,includeDefaultConnections:d},r=new Set(Object.keys(n));function i(E){const v=[],S={kind:"dict",entries:{}};if(!x(E))return v.push({message:"config is not a JSON object",severity:"error",code:"config-validation"}),{compiled:S,log:v};for(const[A,T]of Object.entries(E)){const _=n[A];if(!_){const D=(0,t.closestMatch)(A,[...r]),R=D?`. Did you mean "${D}"?`:"";v.push(m(A,`unknown config key "${A}"${R}`));continue}const C=_(T,v);C!==void 0&&(S.entries[A]=C)}return{compiled:S,log:v}}function s(E,v){if(!x(E)){v.push(m("connections",'"connections" should be an object'));return}const S=new Set((0,e.getRegisteredConnectionTypes)()),A={kind:"dict",entries:{}};for(const[T,_]of Object.entries(E)){const C=`connections.${T}`;if(!x(_)){v.push(m(C,"should be an object"));continue}const D=_.is;if(D==null||D===""){v.push(m(C,'missing required "is" field (connection type)'));continue}if(typeof D!="string"){v.push(m(`${C}.is`,'"is" should be a string'));continue}if(!S.has(D)){const F=(0,t.closestMatch)(D,[...S]),O=F?` Did you mean "${F}"?`:"";v.push(m(`${C}.is`,`unknown connection type "${D}".${O} Available types: ${[...S].join(", ")}`));continue}const R=o(C,D,_,v);A.entries[T]=R}return A}function o(E,v,S,A){var T;const _=(T=(0,e.getConnectionProperties)(v))!==null&&T!==void 0?T:[],C=new Map(_.map(R=>[R.name,R])),D={kind:"dict",entries:{}};D.entries.is={kind:"value",value:v};for(const[R,F]of Object.entries(S)){if(R==="is")continue;const O=C.get(R);if(!O){const q=(0,t.closestMatch)(R,[...C.keys()]),j=q?`. Did you mean "${q}"?`:"";A.push(m(`${E}.${R}`,`unknown property "${R}" for connection type "${v}"${j}`));continue}const N=a(`${E}.${R}`,O,F,A);N!==void 0&&(D.entries[R]=N)}return D}function a(E,v,S,A){if(S==null)return;if(v.type==="json")return{kind:"value",value:S};const T=p(S);if(T!==void 0)return v.requireLiteralString?(A.push(m(E,"must be a literal string and cannot use an overlay reference")),{kind:"value",value:S}):T;const _=y(S,v.type);if(_){if(v.requireLiteralString)return A.push(m(E,`must be a literal string, got ${g(S)}`)),{kind:"value",value:S};A.push(m(E,`${_} (expected ${v.type})`));return}return{kind:"value",value:S}}function u(E,v){const S=p(E);if(S!==void 0)return S;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 S=p(E);if(S!==void 0)return S;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(S=>typeof S=="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 S=v[0],A=E[S];if(typeof A=="string")return{kind:"reference",source:S,path:[A]};if(Array.isArray(A)&&A.every(T=>typeof T=="string"))return{kind:"reference",source:S,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={},Qle;function ck(){if(Qle)return U1;Qle=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 Vle;function lIe(){if(Vle)return WR;Vle=1,Object.defineProperty(WR,"__esModule",{value:!0}),WR.prepareConfig=n;const e=UA(),t=ck();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={},Gle;function cIe(){if(Gle)return YR;Gle=1,Object.defineProperty(YR,"__esModule",{value:!0}),YR.buildManagedLookup=t;const e=UA();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[S,A]of Object.entries(g))S!=="is"&&A!=null&&(E[S]=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 Wle;function fk(){if(Wle)return px;Wle=1,Object.defineProperty(px,"__esModule",{value:!0}),px.MalloyConfig=px.Manifest=void 0,px.isBuildManifestEntry=E;const e=uIe(),t=lIe(),n=cIe(),r=ck(),i=ak();class s{constructor(){this._manifest={entries:{},strict:!1},this._touched=new Set}loadText(S){this._clearEntries(),this._touched.clear(),this._manifest.strict=!1,this._loadParsed(JSON.parse(S))}get buildManifest(){return this._manifest}get strict(){var S;return(S=this._manifest.strict)!==null&&S!==void 0?S:!1}set strict(S){this._manifest.strict=S}update(S,A){(0,i.requireCanonicalTablePathAnyDialect)(A.tableName,`Manifest entry '${S}'`),this._manifest.entries[S]=A,this._touched.add(S)}touch(S){this._touched.add(S)}get activeEntries(){const S={};for(const A of this._touched)this._manifest.entries[A]&&(S[A]=this._manifest.entries[A]);return{entries:S,strict:this._manifest.strict}}_clearEntries(){for(const S of Object.keys(this._manifest.entries))delete this._manifest.entries[S]}_loadParsed(S){typeof S.strict=="boolean"&&(this._manifest.strict=S.strict);const A=y(S.entries)?S.entries:S;for(const[T,_]of Object.entries(A))T==="strict"||!E(_)||((0,i.requireCanonicalTablePathAnyDialect)(_.tableName,`Manifest entry '${T}'`),this._manifest.entries[T]=_)}}px.Manifest=s;class o{constructor(S,A){const T=[];let _;if(typeof S=="string")try{_=JSON.parse(S)}catch(q){T.push({message:`Invalid JSON: ${q instanceof Error?q.message:String(q)}`,severity:"error",code:"config-validation"}),_={}}else _=S;const C=(0,e.compileConfig)(_);T.push(...C.log);const D=f(A,T),R=m(D.configURL,"configURL",T),F=D.rootDirectory,O={...(0,r.defaultConfigOverlays)(),...D.overlays,config:(0,r.contextOverlay)({configURL:R,rootDirectory:F})},N=(0,t.prepareConfig)(C.compiled,O,T);this._managedLookup=(0,n.buildManagedLookup)(N.compiledConnections,O,T),this._connections=this._managedLookup,this._overlays=O,this.virtualMap=g(N.virtualMap,T),this.configURL=R,this.rootDirectory=F,this.manifestPath=N.manifestPath,this.manifestURL=c(N.manifestPath,R),this.givensPath=N.givensPath,this.givensURL=l(N.givensPath,R,T),this.finalizeGivens=N.finalizeGivens,this.log=T}get connections(){return this._connections}wrapConnections(S){this._connections=S(this._connections)}async shutdown(S="close"){S==="idle"?await this._managedLookup.idle():await this._managedLookup.close()}async releaseConnections(){await this.shutdown("close")}async readOverlay(S,...A){var T,_;return await((_=(T=this._overlays)[S])===null||_===void 0?void 0:_.call(T,A))}}px.MalloyConfig=o;const a="MANIFESTS",u="malloy-manifest.json";function c(v,S){if(!S)return;let A;try{A=new URL(S)}catch{return}const T=v??a;let _;try{_=new URL(T,A)}catch{return}const C=_.toString(),D=C.endsWith("/")?_:new URL(C+"/");return new URL(u,D).toString()}function l(v,S,A){if(!v)return;if(!S){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 T;try{T=new URL(S)}catch{return}try{return new URL(v,T).toString()}catch(_){const C=_ instanceof Error?_.message:String(_);A.push({message:`givensPath '${v}' could not be resolved against configURL '${S}': ${C}`,severity:"warn",code:"config-validation"});return}}function f(v,S){if(v===void 0)return{};if(d(v))return p(v,S);const A=v;if(A.overlays&&"config"in A.overlays){S.push({message:"`config` is reserved by MalloyConfig; pass `configURL` and `rootDirectory` directly instead. Supplied `overlays.config` ignored.",severity:"warn",code:"config-overlay"});const{config:T,..._}=A.overlays;return{...A,overlays:_}}return A}function d(v){for(const S of Object.values(v))if(typeof S=="function")return!0;return!1}function p(v,S){const A=v.config;if(!A)return{overlays:v};const T=x(A,"configURL",S),_=x(A,"rootDirectory",S),{config:C,...D}=v;return{configURL:T,rootDirectory:_,overlays:D}}function x(v,S,A){const T=v([S]);if((0,r.isThenable)(T)){A.push({message:`the legacy \`config\` overlay returned a Promise for \`${S}\`; top-level FS context must resolve synchronously. ${S} will be undefined.`,severity:"warn",code:"config-overlay"});return}return typeof T=="string"?T:void 0}function m(v,S,A){if(v!==void 0)try{return new URL(v),v}catch{A.push({message:`${S} 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,S){if(!y(v))return;const A=new Map;for(const[T,_]of Object.entries(v)){if(!y(_))continue;const C=new Map;for(const[D,R]of Object.entries(_)){if(typeof R!="string")continue;const F=(0,i.validateCanonicalTablePathAnyDialect)(R);if(F!==void 0){S.push({message:`virtualMap entry '${T}.${D}': ${F}`,severity:"error",code:"config-validation"});continue}C.set(D,R)}C.size>0&&A.set(T,C)}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={},jA={},Yle;function fIe(){return Yle||(Yle=1,Object.defineProperty(jA,"__esModule",{value:!0}),jA.MALLOY_VERSION=void 0,jA.MALLOY_VERSION="0.0.401"),jA}var Kle;function Xle(){if(Kle)return j1;Kle=1,Object.defineProperty(j1,"__esModule",{value:!0}),j1.Malloy=j1.MalloyError=void 0;const e=uk(),t=UA(),n=Ei(),r=aR(),i=fIe(),s=HR(),o=Mle(),a=VR(),u=Ule(),c="internal://internal.malloy";function l(p){return[...Object.keys(p),...Object.values(p).map(l).flat()]}class f extends Error{constructor(x,m=[]){super(x),this.problems=m}}j1.MalloyError=f;class d{static get version(){return i.MALLOY_VERSION}static registerConnectionType(x,m){(0,t.registerConnectionType)(x,m)}static getConnectionProperties(x){return(0,t.getConnectionProperties)(x)}static getConnectionTypeDisplayName(x){return(0,t.getConnectionTypeDisplayName)(x)}static getRegisteredConnectionTypes(){return(0,t.getRegisteredConnectionTypes)()}static _parse(x,m,g,y,E){var v;m===void 0&&(m=new URL(c));let S=m;y!=null&&y.importBaseURL&&(S=y==null?void 0:y.importBaseURL);const A=new e.MalloyTranslator(m.toString(),S.toString(),{urls:{[m.toString()]:x}},g,(v=y==null?void 0:y.restrictedMode)!==null&&v!==void 0?v:!1);return y!=null&&y.testEnvironment&&(A.allDialectsEnabled=!0),new o.Parse(A,E)}static parse({url:x,urlReader:m,source:g,eventStream:y,options:E}){if(g!==void 0)return d._parse(g,x,y,E);if(m===void 0)throw new Error("Internal Error: urlReader is required.");if(x===void 0)throw new Error("Internal Error: url is required if source not present.");return(0,s.readURL)(m,x).then(({contents:v,invalidationKey:S})=>d._parse(v,x,y,E,S))}static async compile(x){var m,g,y,E,v;let{url:S,source:A,importBaseURL:T,cacheManager:_}=x;const{parse:C,urlReader:D,connections:R,model:F,refreshSchemaCache:O,noThrowOnError:N,eventStream:q,restrictedMode:j}=x;j&&(_=void 0);let K;if(O&&(K=typeof O=="number"?O:Date.now()),S===void 0&&A===void 0&&C===void 0)throw new Error("Internal Error: url, source, or parse required.");S===void 0&&(C!==void 0?S=new URL(C._translator.sourceURL):S=new URL(c));const ae={};if(A===void 0&&_!==void 0){const W=await _.getCachedModelDef(D,S.toString());if(W)return new a.Model(W.modelDef,[],[S.toString(),...l(W.modelDef.dependencies)])}T??(T=S);let he;const ee=S.toString();if(C!==void 0){if(j!==void 0&&C._translator.restrictedMode!==j)throw new Error(`Malloy.compile: restrictedMode (${j}) does not match the pre-parsed translator's restrictedMode (${C._translator.restrictedMode}). Set restrictedMode at parse time.`);he=C._translator;const W=(m=C._invalidationKey)!==null&&m!==void 0?m:await(0,s.getInvalidationKey)(D,S);ae[ee]=W}else{if(A===void 0){const{contents:W,invalidationKey:ue}=await(0,s.readURL)(D,S);ae[ee]=ue,A=W}else{const W=await(0,s.getInvalidationKey)(D,S);ae[ee]=W}he=new e.MalloyTranslator(ee,T.toString(),{urls:{[ee]:A}},q,j??!1)}for(;;){const W=he.translate(F==null?void 0:F._modelDef);if(W.final)if(W.modelDef){await(_==null?void 0:_.setCachedModelDef(S.toString(),{modelDef:W.modelDef,invalidationKeys:ae}));for(const Z of he.newlyTranslatedDependencies())await(_==null?void 0:_.setCachedModelDef(Z.url,{modelDef:Z.modelDef,invalidationKeys:ae}));const ue=!W.modelWasModified&&F?F.getExistingQueryModel():void 0;return new a.Model(W.modelDef,W.problems||[],[...(g=F==null?void 0:F.fromSources)!==null&&g!==void 0?g:[],...(y=W.fromSources)!==null&&y!==void 0?y:[]],ue)}else if(N){const ue=(0,n.mkModelDef)("modelDidNotCompile"),Z=(F==null?void 0:F._modelDef)||ue;return new a.Model(Z,W.problems||[],[...(E=F==null?void 0:F.fromSources)!==null&&E!==void 0?E:[],...(v=W.fromSources)!==null&&v!==void 0?v:[]])}else{const ue=W.problems||[],Z=he.prettyErrors();throw new f(`Error(s) compiling model:
1367
+ `,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={},zle;function UA(){if(zle)return _a;zle=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 S={name:g};for(const[T,_]of Object.entries(E))T!=="is"&&_!=null&&(S[T]=_);a(g,E.is,S);const A=await v.factory(S);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 Hle;function uIe(){if(Hle)return GR;Hle=1,Object.defineProperty(GR,"__esModule",{value:!0}),GR.compileConfig=i;const e=UA(),t=Ple(),n={connections:s,manifestPath:u,givensPath:c,finalizeGivens:l,virtualMap:f,includeDefaultConnections:d},r=new Set(Object.keys(n));function i(E){const v=[],S={kind:"dict",entries:{}};if(!x(E))return v.push({message:"config is not a JSON object",severity:"error",code:"config-validation"}),{compiled:S,log:v};for(const[A,T]of Object.entries(E)){const _=n[A];if(!_){const D=(0,t.closestMatch)(A,[...r]),R=D?`. Did you mean "${D}"?`:"";v.push(m(A,`unknown config key "${A}"${R}`));continue}const C=_(T,v);C!==void 0&&(S.entries[A]=C)}return{compiled:S,log:v}}function s(E,v){if(!x(E)){v.push(m("connections",'"connections" should be an object'));return}const S=new Set((0,e.getRegisteredConnectionTypes)()),A={kind:"dict",entries:{}};for(const[T,_]of Object.entries(E)){const C=`connections.${T}`;if(!x(_)){v.push(m(C,"should be an object"));continue}const D=_.is;if(D==null||D===""){v.push(m(C,'missing required "is" field (connection type)'));continue}if(typeof D!="string"){v.push(m(`${C}.is`,'"is" should be a string'));continue}if(!S.has(D)){const F=(0,t.closestMatch)(D,[...S]),O=F?` Did you mean "${F}"?`:"";v.push(m(`${C}.is`,`unknown connection type "${D}".${O} Available types: ${[...S].join(", ")}`));continue}const R=o(C,D,_,v);A.entries[T]=R}return A}function o(E,v,S,A){var T;const _=(T=(0,e.getConnectionProperties)(v))!==null&&T!==void 0?T:[],C=new Map(_.map(R=>[R.name,R])),D={kind:"dict",entries:{}};D.entries.is={kind:"value",value:v};for(const[R,F]of Object.entries(S)){if(R==="is")continue;const O=C.get(R);if(!O){const q=(0,t.closestMatch)(R,[...C.keys()]),j=q?`. Did you mean "${q}"?`:"";A.push(m(`${E}.${R}`,`unknown property "${R}" for connection type "${v}"${j}`));continue}const N=a(`${E}.${R}`,O,F,A);N!==void 0&&(D.entries[R]=N)}return D}function a(E,v,S,A){if(S==null)return;if(v.type==="json")return{kind:"value",value:S};const T=p(S);if(T!==void 0)return v.requireLiteralString?(A.push(m(E,"must be a literal string and cannot use an overlay reference")),{kind:"value",value:S}):T;const _=y(S,v.type);if(_){if(v.requireLiteralString)return A.push(m(E,`must be a literal string, got ${g(S)}`)),{kind:"value",value:S};A.push(m(E,`${_} (expected ${v.type})`));return}return{kind:"value",value:S}}function u(E,v){const S=p(E);if(S!==void 0)return S;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 S=p(E);if(S!==void 0)return S;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(S=>typeof S=="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 S=v[0],A=E[S];if(typeof A=="string")return{kind:"reference",source:S,path:[A]};if(Array.isArray(A)&&A.every(T=>typeof T=="string"))return{kind:"reference",source:S,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={},Qle;function ck(){if(Qle)return U1;Qle=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 Vle;function lIe(){if(Vle)return WR;Vle=1,Object.defineProperty(WR,"__esModule",{value:!0}),WR.prepareConfig=n;const e=UA(),t=ck();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={},Gle;function cIe(){if(Gle)return YR;Gle=1,Object.defineProperty(YR,"__esModule",{value:!0}),YR.buildManagedLookup=t;const e=UA();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[S,A]of Object.entries(g))S!=="is"&&A!=null&&(E[S]=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 Wle;function fk(){if(Wle)return px;Wle=1,Object.defineProperty(px,"__esModule",{value:!0}),px.MalloyConfig=px.Manifest=void 0,px.isBuildManifestEntry=E;const e=uIe(),t=lIe(),n=cIe(),r=ck(),i=ak();class s{constructor(){this._manifest={entries:{},strict:!1},this._touched=new Set}loadText(S){this._clearEntries(),this._touched.clear(),this._manifest.strict=!1,this._loadParsed(JSON.parse(S))}get buildManifest(){return this._manifest}get strict(){var S;return(S=this._manifest.strict)!==null&&S!==void 0?S:!1}set strict(S){this._manifest.strict=S}update(S,A){(0,i.requireCanonicalTablePathAnyDialect)(A.tableName,`Manifest entry '${S}'`),this._manifest.entries[S]=A,this._touched.add(S)}touch(S){this._touched.add(S)}get activeEntries(){const S={};for(const A of this._touched)this._manifest.entries[A]&&(S[A]=this._manifest.entries[A]);return{entries:S,strict:this._manifest.strict}}_clearEntries(){for(const S of Object.keys(this._manifest.entries))delete this._manifest.entries[S]}_loadParsed(S){typeof S.strict=="boolean"&&(this._manifest.strict=S.strict);const A=y(S.entries)?S.entries:S;for(const[T,_]of Object.entries(A))T==="strict"||!E(_)||((0,i.requireCanonicalTablePathAnyDialect)(_.tableName,`Manifest entry '${T}'`),this._manifest.entries[T]=_)}}px.Manifest=s;class o{constructor(S,A){const T=[];let _;if(typeof S=="string")try{_=JSON.parse(S)}catch(q){T.push({message:`Invalid JSON: ${q instanceof Error?q.message:String(q)}`,severity:"error",code:"config-validation"}),_={}}else _=S;const C=(0,e.compileConfig)(_);T.push(...C.log);const D=f(A,T),R=m(D.configURL,"configURL",T),F=D.rootDirectory,O={...(0,r.defaultConfigOverlays)(),...D.overlays,config:(0,r.contextOverlay)({configURL:R,rootDirectory:F})},N=(0,t.prepareConfig)(C.compiled,O,T);this._managedLookup=(0,n.buildManagedLookup)(N.compiledConnections,O,T),this._connections=this._managedLookup,this._overlays=O,this.virtualMap=g(N.virtualMap,T),this.configURL=R,this.rootDirectory=F,this.manifestPath=N.manifestPath,this.manifestURL=c(N.manifestPath,R),this.givensPath=N.givensPath,this.givensURL=l(N.givensPath,R,T),this.finalizeGivens=N.finalizeGivens,this.log=T}get connections(){return this._connections}wrapConnections(S){this._connections=S(this._connections)}async shutdown(S="close"){S==="idle"?await this._managedLookup.idle():await this._managedLookup.close()}async releaseConnections(){await this.shutdown("close")}async readOverlay(S,...A){var T,_;return await((_=(T=this._overlays)[S])===null||_===void 0?void 0:_.call(T,A))}}px.MalloyConfig=o;const a="MANIFESTS",u="malloy-manifest.json";function c(v,S){if(!S)return;let A;try{A=new URL(S)}catch{return}const T=v??a;let _;try{_=new URL(T,A)}catch{return}const C=_.toString(),D=C.endsWith("/")?_:new URL(C+"/");return new URL(u,D).toString()}function l(v,S,A){if(!v)return;if(!S){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 T;try{T=new URL(S)}catch{return}try{return new URL(v,T).toString()}catch(_){const C=_ instanceof Error?_.message:String(_);A.push({message:`givensPath '${v}' could not be resolved against configURL '${S}': ${C}`,severity:"warn",code:"config-validation"});return}}function f(v,S){if(v===void 0)return{};if(d(v))return p(v,S);const A=v;if(A.overlays&&"config"in A.overlays){S.push({message:"`config` is reserved by MalloyConfig; pass `configURL` and `rootDirectory` directly instead. Supplied `overlays.config` ignored.",severity:"warn",code:"config-overlay"});const{config:T,..._}=A.overlays;return{...A,overlays:_}}return A}function d(v){for(const S of Object.values(v))if(typeof S=="function")return!0;return!1}function p(v,S){const A=v.config;if(!A)return{overlays:v};const T=x(A,"configURL",S),_=x(A,"rootDirectory",S),{config:C,...D}=v;return{configURL:T,rootDirectory:_,overlays:D}}function x(v,S,A){const T=v([S]);if((0,r.isThenable)(T)){A.push({message:`the legacy \`config\` overlay returned a Promise for \`${S}\`; top-level FS context must resolve synchronously. ${S} will be undefined.`,severity:"warn",code:"config-overlay"});return}return typeof T=="string"?T:void 0}function m(v,S,A){if(v!==void 0)try{return new URL(v),v}catch{A.push({message:`${S} 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,S){if(!y(v))return;const A=new Map;for(const[T,_]of Object.entries(v)){if(!y(_))continue;const C=new Map;for(const[D,R]of Object.entries(_)){if(typeof R!="string")continue;const F=(0,i.validateCanonicalTablePathAnyDialect)(R);if(F!==void 0){S.push({message:`virtualMap entry '${T}.${D}': ${F}`,severity:"error",code:"config-validation"});continue}C.set(D,R)}C.size>0&&A.set(T,C)}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={},jA={},Yle;function fIe(){return Yle||(Yle=1,Object.defineProperty(jA,"__esModule",{value:!0}),jA.MALLOY_VERSION=void 0,jA.MALLOY_VERSION="0.0.402"),jA}var Kle;function Xle(){if(Kle)return j1;Kle=1,Object.defineProperty(j1,"__esModule",{value:!0}),j1.Malloy=j1.MalloyError=void 0;const e=uk(),t=UA(),n=Ei(),r=aR(),i=fIe(),s=HR(),o=Mle(),a=VR(),u=Ule(),c="internal://internal.malloy";function l(p){return[...Object.keys(p),...Object.values(p).map(l).flat()]}class f extends Error{constructor(x,m=[]){super(x),this.problems=m}}j1.MalloyError=f;class d{static get version(){return i.MALLOY_VERSION}static registerConnectionType(x,m){(0,t.registerConnectionType)(x,m)}static getConnectionProperties(x){return(0,t.getConnectionProperties)(x)}static getConnectionTypeDisplayName(x){return(0,t.getConnectionTypeDisplayName)(x)}static getRegisteredConnectionTypes(){return(0,t.getRegisteredConnectionTypes)()}static _parse(x,m,g,y,E){var v;m===void 0&&(m=new URL(c));let S=m;y!=null&&y.importBaseURL&&(S=y==null?void 0:y.importBaseURL);const A=new e.MalloyTranslator(m.toString(),S.toString(),{urls:{[m.toString()]:x}},g,(v=y==null?void 0:y.restrictedMode)!==null&&v!==void 0?v:!1);return y!=null&&y.testEnvironment&&(A.allDialectsEnabled=!0),new o.Parse(A,E)}static parse({url:x,urlReader:m,source:g,eventStream:y,options:E}){if(g!==void 0)return d._parse(g,x,y,E);if(m===void 0)throw new Error("Internal Error: urlReader is required.");if(x===void 0)throw new Error("Internal Error: url is required if source not present.");return(0,s.readURL)(m,x).then(({contents:v,invalidationKey:S})=>d._parse(v,x,y,E,S))}static async compile(x){var m,g,y,E,v;let{url:S,source:A,importBaseURL:T,cacheManager:_}=x;const{parse:C,urlReader:D,connections:R,model:F,refreshSchemaCache:O,noThrowOnError:N,eventStream:q,restrictedMode:j}=x;j&&(_=void 0);let K;if(O&&(K=typeof O=="number"?O:Date.now()),S===void 0&&A===void 0&&C===void 0)throw new Error("Internal Error: url, source, or parse required.");S===void 0&&(C!==void 0?S=new URL(C._translator.sourceURL):S=new URL(c));const ae={};if(A===void 0&&_!==void 0){const W=await _.getCachedModelDef(D,S.toString());if(W)return new a.Model(W.modelDef,[],[S.toString(),...l(W.modelDef.dependencies)])}T??(T=S);let he;const ee=S.toString();if(C!==void 0){if(j!==void 0&&C._translator.restrictedMode!==j)throw new Error(`Malloy.compile: restrictedMode (${j}) does not match the pre-parsed translator's restrictedMode (${C._translator.restrictedMode}). Set restrictedMode at parse time.`);he=C._translator;const W=(m=C._invalidationKey)!==null&&m!==void 0?m:await(0,s.getInvalidationKey)(D,S);ae[ee]=W}else{if(A===void 0){const{contents:W,invalidationKey:ue}=await(0,s.readURL)(D,S);ae[ee]=ue,A=W}else{const W=await(0,s.getInvalidationKey)(D,S);ae[ee]=W}he=new e.MalloyTranslator(ee,T.toString(),{urls:{[ee]:A}},q,j??!1)}for(;;){const W=he.translate(F==null?void 0:F._modelDef);if(W.final)if(W.modelDef){await(_==null?void 0:_.setCachedModelDef(S.toString(),{modelDef:W.modelDef,invalidationKeys:ae}));for(const Z of he.newlyTranslatedDependencies())await(_==null?void 0:_.setCachedModelDef(Z.url,{modelDef:Z.modelDef,invalidationKeys:ae}));const ue=!W.modelWasModified&&F?F.getExistingQueryModel():void 0;return new a.Model(W.modelDef,W.problems||[],[...(g=F==null?void 0:F.fromSources)!==null&&g!==void 0?g:[],...(y=W.fromSources)!==null&&y!==void 0?y:[]],ue)}else if(N){const ue=(0,n.mkModelDef)("modelDidNotCompile"),Z=(F==null?void 0:F._modelDef)||ue;return new a.Model(Z,W.problems||[],[...(E=F==null?void 0:F.fromSources)!==null&&E!==void 0?E:[],...(v=W.fromSources)!==null&&v!==void 0?v:[]])}else{const ue=W.problems||[],Z=he.prettyErrors();throw new f(`Error(s) compiling model:
1368
1368
  ${Z}`,ue)}else{if(W.urls)for(const Z of W.urls)try{if((0,s.isInternalURL)(Z))throw new Error("In order to use relative imports, you must compile a file via a URL.");if(_!==void 0){const H=await _.getCachedModelDef(D,Z);if(H){for(const G in H.invalidationKeys)ae[G]=H.invalidationKeys[G];he.update({translations:{[Z]:H.modelDef}});continue}}const{contents:$,invalidationKey:I}=await(0,s.readURL)(D,new URL(Z)),P={[Z]:$};ae[Z]=I,he.update({urls:P})}catch($){he.update({errors:{urls:{[Z]:$.message}}})}const{modelAnnotations:ue}=he.modelAnnotation(F==null?void 0:F._modelDef);if(W.tables){const Z=new Map;for(const $ in W.tables){const{connectionName:I,tablePath:P}=W.tables[$],H=Z.get(I);H===void 0?Z.set(I,{[$]:P}):H[$]=P}for(const[$,I]of Z)try{const P=await R.lookupConnection($),{schemas:H,errors:G}=await d.safelyFetchTableSchema(P,I,{refreshTimestamp:K,modelAnnotations:ue});he.update({tables:H,errors:{tables:G}})}catch(P){const H={},G={};for(const k in I)G[k]=P.toString();he.update({tables:H,errors:{tables:G}})}}if(W.connectionDialects)for(const Z in W.connectionDialects){const{connectionName:$}=W.connectionDialects[Z];try{const I=await R.lookupConnection($);he.update({connectionDialects:{[Z]:I.dialectName}})}catch(I){he.update({errors:{connectionDialects:{[Z]:I.toString()}}})}}if(W.compileSQL){const Z=W.compileSQL,$=Z.connection,I=(0,r.sqlKey)(Z.connection,Z.selectStr);try{const H=await(await R.lookupConnection($)).fetchSchemaForSQLStruct(Z,{refreshTimestamp:K,modelAnnotations:ue});H.error&&he.update({errors:{compileSQL:{[I]:H.error}}}),H.structDef&&he.update({compileSQL:{[I]:H.structDef}})}catch(P){const H={};H[I]=P.toString(),he.update({errors:{compileSQL:H}})}}}}}static async safelyFetchTableSchema(x,m,g){const y=await x.fetchSchemaForTables(m,g);for(const E of Object.keys(m))if(y.schemas[E]===void 0&&y.errors[E]===void 0)throw new Error(`Schema fetch error for ${x.name}, no response for ${E} from ${x.dialectName}`);return y}static async run({connections:x,preparedResult:m,sqlStruct:g,connection:y,options:E}){if(!y){if(!x)throw new Error("Internal Error: Connection or LookupConnection<Connection> must be provided.");const v=(g==null?void 0:g.connection)||(m==null?void 0:m.connectionName);y=await x.lookupConnection(v)}if(g){const v=await y.runSQL(g.selectStr);return new u.Result({structs:[g],sql:g.selectStr,result:v.rows,totalRows:v.totalRows,runStats:v.runStats,lastStageName:g.name,malloy:"",connectionName:g.connection,sourceExplore:"",sourceFilters:[],profilingUrl:v.profilingUrl},(0,n.mkModelDef)("empty_model"))}else if(m){const v=await y.runSQL(m.sql,E);return new u.Result({...m._rawQuery,result:v.rows,totalRows:v.totalRows,runStats:v.runStats,profilingUrl:v.profilingUrl},m._modelDef)}else throw new Error("Internal error: sqlStruct or preparedResult must be provided.")}static async*runStream({connections:x,preparedResult:m,sqlStruct:g,connection:y,options:E}){if(g===void 0&&m===void 0)throw new Error("Internal error: sqlBlock or preparedResult must be provided.");const v=(g==null?void 0:g.connection)||(m==null?void 0:m.connectionName);if(y===void 0){if(x===void 0)throw new Error("Internal Error: Connection or LookupConnection<Connection> must be provided.");y=await x.lookupConnection(v)}if(!y.canStream())throw new Error(`Connection '${v}' cannot stream results.`);let S,A;if(g)A=new a.Explore(g),S=g.selectStr;else if(m!==void 0)A=m.resultExplore,S=m.sql;else throw new Error("Internal error: sqlStruct or preparedResult must be provided.");let T=0;for await(const _ of y.runSQLStream(S,E))yield new u.DataRecord(_,T,A,void 0,void 0),T+=1}static async estimateQueryCost({connections:x,preparedResult:m,sqlStruct:g}){if(!x)throw new Error("Internal Error: Connection or LookupConnection<Connection> must be provided.");const y=(g==null?void 0:g.connection)||(m==null?void 0:m.connectionName),E=await x.lookupConnection(y);if(g)return await E.estimateQueryCost(g.selectStr);if(m)return await E.estimateQueryCost(m.sql);throw new Error("Internal error: sqlStruct or preparedResult must be provided.")}}return j1.Malloy=d,j1}var Jle;function dIe(){if(Jle)return os;Jle=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=Ei(),t=u0(),n=ak(),r=fk(),i=Vv(),s=HR(),o=VR(),a=Xle();class u{constructor(A,T){this.runtime=A,this._materialize=T}materialize(){return this.materialized===void 0?this.rematerialize():this.materialized}rematerialize(){return this.materialized=this._materialize(),this.materialized}makeQueryMaterializer(A,T){return new x(this.runtime,A,T)}makeExploreMaterializer(A,T){return new g(this.runtime,A,T)}makePreparedResultMaterializer(A){return new m(this.runtime,A)}}class c{constructor({urlReader:A,connections:T,connection:_,config:C,buildManifest:D,eventStream:R,cacheManager:F,givens:O}){var N,q;if(this.isTestRuntime=!1,C!==void 0)this._config=C,T=T??C.connections;else if(T===void 0){if(_===void 0)throw new Error("A MalloyConfig, LookupConnection<Connection>, or Connection is required.");T={lookupConnection:()=>Promise.resolve(_)}}if(A===void 0&&(A=new s.EmptyURLReader),this._urlReader=A,this._connections=T,this._buildManifest=D,this._eventStream=R,this._cacheManager=F,O){for(const[j,K]of Object.entries(O))if(K===void 0)throw new Error(`Runtime givens.${j}: 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((q=(N=this._config)===null||N===void 0?void 0:N.finalizeGivens)!==null&&q!==void 0?q:[])}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 A=await this._resolveGivens(),T=new Map;if(A)for(const[_,C]of Object.entries(A))T.set(_,C);for(const[_,C]of this._constructorGivensMap)T.set(_,C);return T}get _finalizedGivens(){return this._finalizedGivensSet}set buildManifest(A){this._buildManifest=A,this._resolvedBuildManifestPromise=void 0}_resolveBuildManifest(){var A;if(this._buildManifest)return Promise.resolve(this._buildManifest);const T=(A=this._config)===null||A===void 0?void 0:A.manifestURL;return T?(this._resolvedBuildManifestPromise||(this._resolvedBuildManifestPromise=(async()=>{let _;try{const C=await this._urlReader.readURL(new URL(T));_=typeof C=="string"?C:C.contents}catch{return}try{const C=JSON.parse(_);if(!y(C))throw new Error('manifest is not an object with an "entries" map');for(const[D,R]of Object.entries(C.entries)){if(!(0,r.isBuildManifestEntry)(R))throw new Error(`Manifest entry '${D}' is missing a string tableName`);(0,n.requireCanonicalTablePathAnyDialect)(R.tableName,`Manifest entry '${D}'`)}return C}catch(C){const D=C instanceof Error?C.message:String(C);return{entries:{},loadError:`Manifest file at ${T} could not be parsed: ${D}`}}})()),this._resolvedBuildManifestPromise):Promise.resolve(void 0)}_resolveGivens(){var A;const T=(A=this._config)===null||A===void 0?void 0:A.givensURL;return T?(this._resolvedGivensPromise||(this._resolvedGivensPromise=(async()=>{let _;try{const D=await this._urlReader.readURL(new URL(T));_=typeof D=="string"?D:D.contents}catch(D){const R=D instanceof Error?D.message:String(D);throw new Error(`givens: failed to read givens file at ${T}: ${R}`)}let C;try{C=JSON.parse(_)}catch(D){const R=D instanceof Error?D.message:String(D);throw new Error(`givens: failed to parse JSON at ${T}: ${R}`)}if(!E(C)){const D=Array.isArray(C)?"array":C===null?"null":typeof C;throw new Error(`givens: file at ${T} must be a JSON object of name → value pairs, got ${D}`)}return C})()),this._resolvedGivensPromise):Promise.resolve(void 0)}_invalidateGivensCache(){this._resolvedGivensPromise=void 0}get virtualMap(){var A,T;return(A=this._virtualMap)!==null&&A!==void 0?A:(T=this._config)===null||T===void 0?void 0:T.virtualMap}set virtualMap(A){this._virtualMap=A}async shutdown(A="close"){var T;await((T=this._config)===null||T===void 0?void 0:T.shutdown(A))}async releaseConnections(){await this.shutdown("close")}loadModel(A,T){const{refreshSchemaCache:_,noThrowOnError:C}=T||{};this.isTestRuntime&&(T===void 0?T={testEnvironment:!0}:T={...T,testEnvironment:!0});const D=A instanceof URL?{url:A}:{source:A};return new d(this,async()=>{const R=await a.Malloy.compile({...D,urlReader:this.urlReader,connections:this.connections,refreshSchemaCache:_,noThrowOnError:C,eventStream:this.eventStream,importBaseURL:T==null?void 0:T.importBaseURL,testEnvironment:T==null?void 0:T.testEnvironment,cacheManager:this.cacheManager});return this._withRuntimeContext(R)},T)}_withRuntimeContext(A){return this._finalizedGivensSet.size===0?A:new o.Model(A._modelDef,A.problems,A.fromSources,A.getExistingQueryModel(),{finalizedGivens:this._finalizedGivensSet})}_loadModelFromModelDef(A,T){return new d(this,async()=>new o.Model(A,[],[],void 0,this._finalizedGivensSet.size>0?{finalizedGivens:this._finalizedGivensSet}:void 0),T)}loadQuery(A,T){return this.loadModel(A,T).loadFinalQuery()}loadQueryByIndex(A,T,_){return this.loadModel(A,_).loadQueryByIndex(T,_)}loadQueryByName(A,T,_){return this.loadModel(A,_).loadQueryByName(T,_)}getModel(A,T){return this.loadModel(A,T).getModel()}getQuery(A,T){return this.loadQuery(A,T).getPreparedQuery()}getQueryByIndex(A,T,_){return this.loadQueryByIndex(A,T,_).getPreparedQuery()}getQueryByName(A,T,_){return this.loadQueryByName(A,T,_).getPreparedQuery()}}os.Runtime=c;class l extends c{constructor({urlReader:A,connections:T}){super({connections:s.FixedConnectionMap.fromArray(T),urlReader:A}),this.rawConnections=T}}os.ConnectionRuntime=l;class f extends c{constructor({urlReader:A,connection:T,eventStream:_,cacheManager:C}){super({urlReader:A,eventStream:_,cacheManager:C,connection:T}),this.connection=T}get supportsNesting(){return(0,t.getDialect)(this.connection.dialectName).supportsNesting}quote(A){return(0,t.getDialect)(this.connection.dialectName).sqlQuoteIdentifier(A)}get dialect(){return(0,t.getDialect)(this.connection.dialectName)}getQuoter(){return A=>this.quote(A.toString())}}os.SingleConnectionRuntime=f;class d extends u{constructor(A,T,_){super(A,T),this.runtime=A,this.compileQueryOptions=_}loadFinalQuery(A){return this.makeQueryMaterializer(async()=>(await this.materialize()).getPreparedQuery(),{...this.compileQueryOptions,...A})}loadQueryByIndex(A,T){return this.makeQueryMaterializer(async()=>(await this.materialize()).getPreparedQueryByIndex(A),{...this.compileQueryOptions,...T})}loadQueryByName(A,T){return this.makeQueryMaterializer(async()=>(await this.materialize()).getPreparedQueryByName(A),{...this.compileQueryOptions,...T})}loadQuery(A,T){const{refreshSchemaCache:_,noThrowOnError:C}=T||{};return this.makeQueryMaterializer(async()=>{const D=this.runtime.urlReader,R=this.runtime.connections;this.runtime.isTestRuntime&&(T===void 0?T={testEnvironment:!0}:T={...T,testEnvironment:!0});const F=A instanceof URL?{url:A}:{source:A},O=await this.getModel();return(await a.Malloy.compile({...F,urlReader:D,connections:R,model:O,refreshSchemaCache:_,noThrowOnError:C,importBaseURL:T==null?void 0:T.importBaseURL,testEnvironment:T==null?void 0:T.testEnvironment,...this.compileQueryOptions})).preparedQuery})}loadRestrictedQuery(A){return this.makeQueryMaterializer(async()=>{const T=this.runtime.urlReader,_=this.runtime.connections,C=this.runtime.isTestRuntime?!0:void 0,D=await this.getModel();return(await a.Malloy.compile({source:A,restrictedMode:!0,urlReader:T,connections:_,model:D,testEnvironment:C,...this.compileQueryOptions})).preparedQuery})}extendModel(A,T){return this.runtime.isTestRuntime&&(T===void 0?T={testEnvironment:!0}:T={...T,testEnvironment:!0}),new d(this.runtime,async()=>{const _=this.runtime.urlReader,C=this.runtime.connections,D=A instanceof URL?{url:A}:{source:A},R=await this.getModel(),F=await a.Malloy.compile({...D,urlReader:_,connections:C,model:R,refreshSchemaCache:T==null?void 0:T.refreshSchemaCache,noThrowOnError:T==null?void 0:T.noThrowOnError,importBaseURL:T==null?void 0:T.importBaseURL,testEnvironment:T==null?void 0:T.testEnvironment,...this.compileQueryOptions});return this.runtime._withRuntimeContext(F)},T)}async search(A,T,_=1e3,C=void 0){const D=await this.materialize(),R=D.queryModel,F=D.getExploreByName(A).structDef;if(!(0,e.isSourceDef)(F))throw new Error("Source to be searched was unexpectedly, not a source");const O=F.connection,N=await this.runtime.connections.lookupConnection(O);return await R.searchIndex(N,A,T,_,C)}async searchValueMap(A,T=10,_){const D=(await this.materialize()).getExploreByName(A);if(!(0,e.isSourceDef)(D.structDef))throw new Error("Source to be searched was unexpectedly, not a source");let R="{index: *}";D.getFieldByNameIfExists("search_index")&&(R="search_index");const F=`
1369
1369
  run: ${A}
1370
1370
  -> ${R}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/render",
3
- "version": "0.0.401",
3
+ "version": "0.0.402",
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.401",
33
- "@malloydata/malloy-tag": "0.0.401",
32
+ "@malloydata/malloy-interfaces": "0.0.402",
33
+ "@malloydata/malloy-tag": "0.0.402",
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.401",
46
- "@malloydata/malloy": "0.0.401",
45
+ "@malloydata/db-duckdb": "0.0.402",
46
+ "@malloydata/malloy": "0.0.402",
47
47
  "@storybook/addon-essentials": "^8.6.15",
48
48
  "@storybook/addon-interactions": "^8.6.15",
49
49
  "@storybook/addon-links": "^8.6.15",