@malloy-publisher/server 0.0.178 → 0.0.180

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.
@@ -1,4 +1,4 @@
1
- import{V as I0,W as Mp}from"./index-BJUsHnGO.js";function qp(a,d){for(var y=0;y<d.length;y++){const m=d[y];if(typeof m!="string"&&!Array.isArray(m)){for(const h in m)if(h!=="default"&&!(h in a)){const u=Object.getOwnPropertyDescriptor(m,h);u&&Object.defineProperty(a,h,u.get?u:{enumerable:!0,get:()=>m[h]})}}}return Object.freeze(Object.defineProperty(a,Symbol.toStringTag,{value:"Module"}))}var mo={},Cr={},Xe={},Ma;function pe(){if(Ma)return Xe;Ma=1;/*!
1
+ import{V as I0,W as Mp}from"./index-C2IkGoJ8.js";function qp(a,d){for(var y=0;y<d.length;y++){const m=d[y];if(typeof m!="string"&&!Array.isArray(m)){for(const h in m)if(h!=="default"&&!(h in a)){const u=Object.getOwnPropertyDescriptor(m,h);u&&Object.defineProperty(a,h,u.get?u:{enumerable:!0,get:()=>m[h]})}}}return Object.freeze(Object.defineProperty(a,Symbol.toStringTag,{value:"Module"}))}var mo={},Cr={},Xe={},Ma;function pe(){if(Ma)return Xe;Ma=1;/*!
2
2
  * Copyright 2016 The ANTLR Project. All rights reserved.
3
3
  * Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
4
4
  */Object.defineProperty(Xe,"__esModule",{value:!0}),Xe.SuppressWarnings=Xe.Override=Xe.Nullable=Xe.NotNull=void 0;function a(h,u,r){}Xe.NotNull=a;function d(h,u,r){}Xe.Nullable=d;function y(h,u,r){}Xe.Override=y;function m(h){return(u,r,o)=>{}}return Xe.SuppressWarnings=m,Xe}var Or={},Dr={},qa;function Ve(){if(qa)return Dr;qa=1;/*!
@@ -1,4 +1,4 @@
1
- import{L as uO,r as D,j as w,N as gr,R as v4,Q as _4,U as oo}from"./index-BJUsHnGO.js";import{r as S4,a as $2,b as A4,c as b4,d as R4,e as T4,f as w4,g as D4,h as L4,j as q2,k as j2,l as O0,m as Qh,n as O4,o as lO,p as N4,q as F4,s as I4,t as D3,u as L3,v as O3,w as At}from"./index--80Q7qw1.js";import{a as S1}from"./index.umd-Cf-wqh-R.js";var Ca={},ry={},Hr={},ny={},lv;function st(){return lv||(lv=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.TD=e.ValueType=void 0,e.safeRecordGet=r,e.mkSafeRecord=s,e.exprHasKids=a,e.exprHasE=o,e.exprIsLeaf=c,e.isAsymmetricExpr=d,e.mkTemporal=f,e.isRawCast=u,e.isFilterExprType=p,e.isTimeLiteral=h,e.isParameterType=m,e.paramHasValue=x,e.expressionIsScalar=E,e.expressionIsAggregate=C,e.expressionIsUngroupedAggregate=g,e.expressionInvolvesAggregate=_,e.expressionIsCalculation=S,e.expressionIsAnalytic=R,e.isExpressionTypeLEQ=b,e.maxExpressionType=T,e.maxOfExpressionTypes=N,e.hasExpression=k,e.isTemporalType=L,e.isBasicAtomicType=F,e.isAtomicFieldType=M,e.canOrderBy=q,e.fieldIsIntrinsic=B,e.mkFieldDef=P,e.mkArrayDef=Y,e.mkArrayTypeDef=ee,e.isRepeatedRecordFunctionParam=oe,e.isRepeatedRecord=I,e.isRecordOrRepeatedRecord=X,e.isBasicArray=G,e.isMatrixOperation=te,e.isJoinable=V,e.isJoined=se,e.isJoinedSource=Ee,e.isDateUnit=Ce,e.isTimestampUnit=le,e.isExtractUnit=ae,e.refIsStructDef=ce,e.segmentHasErrors=ie,e.structHasErrors=xe,e.isReduceSegment=me,e.isPartialSegment=Te,e.isProjectSegment=ye,e.isQuerySegment=be,e.isSamplingRows=pe,e.isSamplingPercent=Pe,e.isSamplingEnable=qe,e.isRawSegment=Ue,e.isIndexSegment=pt,e.bareFieldUsage=gt,e.isSegmentSQL=St,e.isSegmentSource=Ot,e.isSourceRegistryReference=Qt,e.sourceBase=br,e.isSourceDef=rr,e.isPersistableSourceDef=Le,e.isBaseTable=We,e.isLiteral=wt,e.mergeEvalSpaces=He,e.isBasicAtomic=de,e.getIdentifier=he,e.isUserTypeDef=ke,e.isCompoundArrayData=Be,e.isTurtle=Ke,e.isAtomic=ot,e.isValueString=rt,e.isValueNumber=Nt,e.isValueBoolean=Rt,e.isValueTimestamp=Se,e.isValueDate=it,e.mergeUniqueKeyRequirement=Ge;const t=Object.prototype.hasOwnProperty;function r(re,we){return t.call(re,we)?re[we]:void 0}function s(){return Object.create(null)}function a(re){return"kids"in re}function o(re){return"e"in re}function c(re){return!(a(re)||o(re))}function d(re){return re.node==="aggregate"&&["sum","avg","count","distinct"].includes(re.function)}function l(re){return re.node!=="arrayLiteral"&&re.node!=="recordLiteral"}function f(re,we){if(!("typeDef"in re)){const Ye=typeof we=="string"?{type:we}:we;if(l(re))return{...re,typeDef:{...Ye}}}return re}function u(re){return"dstSQLType"in re}function p(re){return["string","number","boolean","date","timestamp","timestamptz"].includes(re)}function h(re){return re.node==="dateLiteral"||re.node==="timestampLiteral"||re.node==="timestamptzLiteral"}function m(re){return["string","number","boolean","date","timestamp","timestamptz","filter expression","error"].includes(re)}function x(re){return re.value!==null}function E(re){return re===void 0||re==="scalar"}function C(re){return re==="aggregate"||re==="ungrouped_aggregate"}function g(re){return re==="ungrouped_aggregate"}function _(re){return re==="aggregate"||re==="ungrouped_aggregate"||re==="aggregate_analytic"}function S(re){return re==="aggregate"||re==="scalar_analytic"||re==="aggregate_analytic"||re==="ungrouped_aggregate"}function R(re){return re==="aggregate_analytic"||re==="scalar_analytic"}function v(re){return{scalar:0,aggregate:1,ungrouped_aggregate:2,scalar_analytic:2,aggregate_analytic:3}[re]}function b(re,we){return re===we||v(re)<v(we)}function T(re,we){let Ye="scalar";return(re==="aggregate"||we==="aggregate")&&(Ye="aggregate"),(re==="ungrouped_aggregate"||we==="ungrouped_aggregate")&&(Ye="ungrouped_aggregate"),(re==="scalar_analytic"||we==="scalar_analytic")&&(Ye="scalar_analytic"),(re==="aggregate_analytic"||we==="aggregate_analytic")&&(Ye="aggregate_analytic"),(re==="scalar_analytic"&&we==="aggregate"||re==="aggregate"&&we==="scalar_analytic")&&(Ye="aggregate_analytic"),Ye}function N(re){return re.reduce(T,"scalar")}function k(re){return"e"in re&&re.e!==void 0}function L(re){return re==="date"||re==="timestamp"||re==="timestamptz"}function F(re){return["string","number","date","timestamp","timestamptz","boolean","json","sql native","error"].includes(re)}function M(re){return F(re)||re==="record"||re==="array"}function q(re){return["string","number","date","boolean","date","timestamp","timestamptz"].includes(re)}function B(re){return M(re.type)&&!k(re)}function P(re,we){if(G(re))return Y(re.elementTypeDef,we);if(I(re)){const{type:ze,fields:mt,elementTypeDef:Ct}=re;return{type:ze,fields:mt,elementTypeDef:Ct,join:"many",name:we}}if(re.type==="record"){const{type:ze,fields:mt}=re;return{type:ze,fields:mt,join:"one",name:we}}const Ye={name:we,type:re.type};switch(re.type){case"sql native":return{...Ye,rawType:re.rawType};case"number":{const ze=re.numberType;return ze?{...Ye,numberType:ze}:Ye}case"date":{const ze=re.timeframe;return ze?{name:we,type:"date",timeframe:ze}:Ye}case"timestamp":{const ze={name:we,type:"timestamp"};return re.timeframe&&(ze.timeframe=re.timeframe),ze}case"timestamptz":{const ze={name:we,type:"timestamptz"};return re.timeframe&&(ze.timeframe=re.timeframe),ze}}return Ye}function Y(re,we){if(re.type==="record")return{type:"array",join:"many",name:we,elementTypeDef:{type:"record_element"},fields:re.fields};const Ye=P(re,"value");return{type:"array",join:"many",name:we,elementTypeDef:re,fields:[Ye,{...Ye,name:"each",e:{node:"field",path:["value"]}}]}}function ee(re){return re.type==="record"?{type:"array",elementTypeDef:{type:"record_element"},fields:re.fields}:{type:"array",elementTypeDef:re}}function oe(re){return re.type==="array"&&re.elementTypeDef.type==="record_element"}function I(re){return re.type==="array"&&re.elementTypeDef.type==="record_element"}function X(re){return re.type==="record"||re.type==="array"&&"elementTypeDef"in re&&re.elementTypeDef.type==="record_element"}function G(re){return re.type==="array"&&re.elementTypeDef.type!=="record_element"}function te(re){return["left","right","full","inner"].includes(re)}function V(re){return["composite","table","sql_select","query_source","virtual","array","record"].includes(re.type)}function se(re){return"join"in re}function Ee(re){return rr(re)&&se(re)}function Ce(re){return["day","week","month","quarter","year"].includes(re)}function le(re){return Ce(re)||["hour","minute","second"].includes(re)}function ae(re){return le(re)||re==="day_of_week"||re==="day_of_year"}var Z;(function(re){re.Date="date",re.Timestamp="timestamp",re.Number="number",re.String="string"})(Z||(e.ValueType=Z={}));function ce(re){return typeof re!="string"}function ie(re){return!!((re.type==="reduce"||re.type==="project"||re.type==="partial")&&(re.extendSource&&re.extendSource.some(we=>we.type==="error")||re.queryFields.some(we=>we.type==="error")))}function xe(re){return re.fields.some(we=>we.type==="error")}function me(re){return re.type==="reduce"}function Te(re){return re.type==="partial"}function ye(re){return re.type==="project"}function be(re){return ye(re)||me(re)}function pe(re){return re.rows!==void 0}function Pe(re){return re.percent!==void 0}function qe(re){return re.enable!==void 0}function Ue(re){return re.type==="raw"}function pt(re){return re.type==="index"}function gt(re){return re.uniqueKeyRequirement===void 0&&re.analyticFunctionUse===void 0}function St(re){return"sql"in re}function Ot(re){return"type"in re&&(re.type==="sql_select"||re.type==="query_source")}function Qt(re){return re.type==="source_registry_reference"}function br(re){return{...re}}function rr(re){return re.type==="table"||re.type==="sql_select"||re.type==="query_source"||re.type==="query_result"||re.type==="finalize"||re.type==="nest_source"||re.type==="virtual"||re.type==="composite"}function Le(re){return re.type==="sql_select"||re.type==="query_source"}function We(re){return Ee(re)?!1:!!rr(re)}function wt(re){return re==="literal"}function He(...re){return re.length<=1&&re.every(we=>we==="literal")?"literal":re.every(we=>we==="constant"||we==="literal")?"constant":re.every(we=>we==="output"||we==="constant"||we==="literal")?"output":"input"}function de(re){return re.type==="string"||L(re.type)||re.type==="number"||re.type==="boolean"||re.type==="json"||re.type==="sql native"||re.type==="error"}function he(re){return re.as!==void 0?re.as:re.name}function ke(re){return re.type==="userType"}function Be(re){return Array.isArray(re)&&(re.length===0||typeof re[0]=="object"&&re[0]!==null&&!Array.isArray(re[0]))}function Ke(re){return re.type==="turtle"}function ot(re){return M(re.type)}function rt(re,we){return we.type==="string"}function Nt(re,we){return we.type==="number"}function Rt(re,we){return we.type==="boolean"}function Se(re,we){return we.type==="timestamp"}function it(re,we){return we.type==="date"}e.TD={isAtomic(re){return re!==void 0&&M(re.type)},isBasicAtomic(re){return re!==void 0&&de({type:re.type})},isString:re=>re?.type==="string",isNumber:re=>re?.type==="number",isBoolean:re=>re?.type==="boolean",isJSON:re=>re?.type==="json",isSQL:re=>re?.type==="sql native",isDate:re=>re?.type==="date",isTimestamp:re=>re?.type==="timestamp",isTimestamptz:re=>re?.type==="timestamptz",isAnyTimestamp(re){return re?.type==="timestamp"||re?.type==="timestamptz"},isTemporal(re){var we;const Ye=(we=re?.type)!==null&&we!==void 0?we:"";return L(Ye)},isError:re=>re?.type==="error",eq(re,we){if(re===void 0||we===void 0)return!1;function Ye(ze,mt){const Ct={},Tt=ze.fields||[],at=mt.fields||[];if(Tt.length!==at.length)return!1;for(const vt of Tt)if(vt.name)Ct[vt.name]=vt;else return!1;for(const vt of at)if(!e.TD.eq(Ct[vt.name],vt))return!1;return!0}return re.type==="array"&&we.type==="array"?re.elementTypeDef.type!==we.elementTypeDef.type?!1:re.elementTypeDef.type!=="record_element"&&we.elementTypeDef.type!=="record_element"?e.TD.eq(re.elementTypeDef,we.elementTypeDef):e.TD.isAtomic(re)&&e.TD.isAtomic(we)&&Ye(re,we):re.type==="record"&&we.type==="record"?e.TD.isAtomic(re)&&e.TD.isAtomic(we)&&Ye(re,we):re.type==="sql native"&&we.type==="sql native"?re.rawType!==void 0&&re.rawType===we.rawType:re.type===we.type}};function Ge(re,we){return re?we?{isCount:re.isCount||we.isCount}:re:we}})(ny)),ny}var cv;function ho(){if(cv)return Hr;cv=1,Object.defineProperty(Hr,"__esModule",{value:!0}),Hr.arg=t,Hr.spread=r,Hr.sql=s,Hr.constant=a,Hr.output=o,Hr.literal=c,Hr.variadicParam=d,Hr.param=l,Hr.makeParam=f,Hr.maxScalar=u,Hr.maxAggregate=p,Hr.anyExprType=h,Hr.maxUngroupedAggregate=m,Hr.maxAnalytic=x,Hr.minScalar=E,Hr.minAggregate=C,Hr.minAnalytic=g,Hr.overload=_,Hr.expandBlueprintMap=te,Hr.expandOverrideMapFromBase=Ee,Hr.def=le;const e=st();function t(ae){return{node:"function_parameter",name:ae}}function r(ae,Z=void 0,ce=void 0){return{node:"spread",e:ae,prefix:Z,suffix:ce}}function s(ae,...Z){const ce={node:"genericSQLExpr",kids:{args:[]},src:[]},ie=[...Z];let xe="";for(const me of ae){xe+=me;const Te=ie.shift();Te!==void 0&&(typeof Te=="string"?xe+=Te:(ce.src.push(xe),ce.kids.args.push(Te),xe=""))}return xe.length>0&&ce.src.push(xe),ce}function a(ae){return{...ae,evalSpace:"constant"}}function o(ae){return{...ae,evalSpace:"output"}}function c(ae){return{...ae,evalSpace:"literal"}}function d(ae,...Z){return{name:ae,isVariadic:!0,allowedTypes:Z}}function l(ae,...Z){return{name:ae,isVariadic:!1,allowedTypes:Z}}function f(ae,...Z){return{param:l(ae,...Z),arg:t(ae)}}function u(ae){return{...ae,expressionType:"scalar",evalSpace:"input"}}function p(ae){return{...ae,expressionType:"aggregate",evalSpace:"input"}}function h(ae){return{...ae,expressionType:void 0,evalSpace:"input"}}function m(ae){return{...ae,expressionType:"ungrouped_aggregate",evalSpace:"input"}}function x(ae){return{...ae,expressionType:"aggregate_analytic",evalSpace:"input"}}function E(ae){return{...ae,expressionType:"scalar",evalSpace:"input"}}function C(ae){return{...ae,expressionType:"aggregate",evalSpace:"input"}}function g(ae){return{...ae,expressionType:"scalar_analytic",evalSpace:"input"}}function _(ae,Z,ce,ie){return{returnType:ae,params:Z,e:ce,needsWindowOrderBy:ie?.needsWindowOrderBy,between:ie?.between,isSymmetric:ie?.isSymmetric,supportsOrderBy:ie?.supportsOrderBy,defaultOrderByArgIndex:ie?.defaultOrderByArgIndex,supportsLimit:ie?.supportsLimit}}function S(ae,Z=!0,ce=!0){if(!Z&&ae==="any")throw new Error("Return type cannot include any");if(typeof ae=="string")return{type:ae};if("array"in ae){const ie=Z?S(ae.array,!0):S(ae.array,!1);return ie.type==="record"?{type:"array",elementTypeDef:{type:"record_element"},fields:ie.fields}:{type:"array",elementTypeDef:ie}}else if("record"in ae){const ie=[];for(const[xe,me]of Object.entries(ae.record)){const Te=Z?S(me,!0):S(me,!1);e.TD.isAtomic(Te)&&ie.push((0,e.mkFieldDef)(Te,xe))}return{type:"record",fields:ie}}else if("generic"in ae){if(!ce)throw new Error("Cannot use generic");return{type:"generic",generic:ae.generic}}else if("sql_native"in ae)return{type:"sql native",rawType:ae.sql_native};throw new Error("Cannot figure out type")}function R(ae){if(ae==="any")throw new Error("Cannot return any type");if(typeof ae=="string")return E({type:ae});if("array"in ae)return h(S(ae,!1));if("record"in ae)return h(S(ae,!1));if("generic"in ae)return E(S(ae,!1));if("literal"in ae)return c(E(S(ae.literal,!1)));if("constant"in ae)return a(E(S(ae.constant,!1)));if("dimension"in ae)return E(S(ae.dimension,!1));if("measure"in ae)return C(S(ae.measure,!1));if("sql_native"in ae)return h({type:"sql native",rawType:ae.sql_native});if("calculation"in ae)return g(S(ae.calculation,!1));throw new Error("Invalid function blueprint")}function v(ae){return typeof ae=="string"||"array"in ae||"record"in ae||"generic"in ae||"literal"in ae||"constant"in ae||"dimension"in ae||"measure"in ae||"calculation"in ae||"sql_native"in ae}function b(ae){return v(ae)?[ae]:Array.isArray(ae)?ae:v(ae.variadic)?[ae.variadic]:ae.variadic}function T(ae){if(typeof ae=="string")return h({type:ae});if("generic"in ae)return h(S(ae));if("literal"in ae)return c(u(S(ae.literal)));if("constant"in ae)return a(u(S(ae.constant)));if("dimension"in ae)return u(S(ae.dimension));if("measure"in ae)return p(S(ae.measure));if("array"in ae)return h(S(ae,!1));if("record"in ae)return h(S(ae,!1));if("sql_native"in ae)return h({type:"sql native",rawType:ae.sql_native});if("calculation"in ae)return x(S(ae.calculation));throw new Error("Invalid function blueprint")}function N(ae){return ae.map(Z=>T(Z))}function k(ae){return typeof ae!="string"&&"variadic"in ae}function L(ae,Z){return{name:ae,allowedTypes:N(b(Z)),isVariadic:k(Z)}}function F(ae){return Object.entries(ae).map(ce=>L(ce[0],ce[1]))}function M(ae){const Z=[],ce=[];let ie=ae;for(;ie.length>0;){const me=ie.indexOf("${");if(me===-1){Z.push(ie);break}const Te=ie.slice(0,me);ie=ie.slice(me);const ye=ie.indexOf("}");if(ye===-1){Z.push(Te+ie);break}const be=ie.slice(2,ye);ie=ie.slice(ye+1);const pe=be.startsWith("..."),Pe=be.endsWith(":"),qe=pe?be.slice(3):Pe?be.slice(0,-1):be,Ue={node:"function_parameter",name:qe};Z.push(Te),pe?ce.push({node:"spread",e:Ue,prefix:"",suffix:""}):Pe&&qe==="order_by"?ce.push({node:"aggregate_order_by"}):Pe&&qe==="limit"?ce.push({node:"aggregate_limit"}):ce.push(Ue)}return{node:"genericSQLExpr",kids:{args:ce},src:Z}}function q(ae,Z){return k(Z)?{node:"spread",e:{node:"function_parameter",name:ae},prefix:"",suffix:""}:{node:"function_parameter",name:ae}}function B(ae,Z){const ce=Object.entries(Z.takes),ie=ce.length>0?ce.length-1:0;return{node:"genericSQLExpr",kids:{args:ce.map(xe=>q(xe[0],xe[1]))},src:[`${ae}(`,...Array(ie).fill(","),")"]}}function P(ae){return"sql"in ae.impl?M(ae.impl.sql):"expr"in ae.impl?ae.impl.expr:B(ae.impl.function,ae)}function Y(ae){return{e:P(ae),between:ae.impl.between,needsWindowOrderBy:ae.impl.needsWindowOrderBy,defaultOrderByArgIndex:ae.impl.defaultOrderByArgIndex}}function ee(ae){if(ae!==void 0)return Object.entries(ae).map(([Z,ce])=>({name:Z,acceptibleTypes:ce.map(ie=>S(ie,!0,!1))}))}function oe(ae){return{returnType:R(ae.returns),params:F(ae.takes),isSymmetric:ae.isSymmetric,supportsOrderBy:ae.supportsOrderBy,supportsLimit:ae.supportsLimit,genericTypes:ee(ae.generic),...Y(ae)}}function I(ae){return"takes"in ae&&"returns"in ae&&"impl"in ae}function X(ae){return"function"in ae||"sql"in ae||"expr"in ae}function G(ae){return I(ae)?[oe(ae)]:Object.values(ae).flatMap(Z=>oe(Z))}function te(ae){const Z={};for(const ce in ae)Z[ce]=G(ae[ce]);return Z}function V(ae,Z){return[oe({...ae,impl:Z})]}function se(ae,Z,ce){if(X(ce)){if(!I(Z))throw new Error(`Malformed function override: ${ae}. Attempt to override multiple overloads with a single overload (missing: ${Object.keys(Z)})`);return V(Z,ce)}else{if(I(Z))throw new Error(`Malformed function override: ${ae}. Attempt to override a single overload with multiple overloads (extraneous: ${Object.keys(ce)})`);return Object.entries(ce).flatMap(([ie,xe])=>{const me=Z[ie];if(me===void 0)throw new Error(`Malformed function override: ${ae}. No overload named ${ie}`);return V(me,xe)})}}function Ee(ae,Z){const ce={};for(const ie in Z){if(!(ie in ae))throw new Error(`Malformed function override: ${ie}. No such function in Malloy standard`);ce[ie]=se(ie,ae[ie],Z[ie])}return ce}function*Ce(ae){if(typeof ae!="string"){if("generic"in ae)yield ae;else if("record"in ae)for(const Z of Object.values(ae.record))yield*Ce(Z);else for(const Z of["array","literal","measure","dimension","measure","constant","cacluation"])if(Z in ae){yield*Ce(ae[Z]);return}}}function le(ae,Z,ce,ie={}){let xe=!1;const me={};for(const ye of Object.values(Z))for(const be of Ce(ye))me[be.generic]=["any"],xe=!0;xe&&ie.generic===void 0&&(ie.generic=me);const Te={takes:Z,returns:ce,impl:{function:ae.toUpperCase()},...ie};return{[ae]:Te}}return Hr}var iy={},dv;function za(){return dv||(dv=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.Dialect=e.dayIndex=e.MAX_DECIMAL38=e.MIN_DECIMAL38=e.MAX_INT128=e.MIN_INT128=e.MAX_INT64=e.MIN_INT64=e.MAX_INT32=e.MIN_INT32=void 0,e.inDays=s,e.qtz=a;const t=st();e.MIN_INT32=-2147483648,e.MAX_INT32=2147483647,e.MIN_INT64=BigInt("-9223372036854775808"),e.MAX_INT64=BigInt("9223372036854775807"),e.MIN_INT128=BigInt("-170141183460469231731687303715884105728"),e.MAX_INT128=BigInt("170141183460469231731687303715884105727"),e.MIN_DECIMAL38=BigInt("-99999999999999999999999999999999999999"),e.MAX_DECIMAL38=BigInt("99999999999999999999999999999999999999");const r=["microsecond","millisecond","second","minute","hour","day","week","month","quarter","year"];e.dayIndex=r.indexOf("day");function s(c){return r.indexOf(c)>=e.dayIndex}function a(c){const d=c.queryTimezone;if(!(d===void 0||d===c.systemTimezone))return d}class o{constructor(){this.cantPartitionWindowFunctionsOnExpressions=!1,this.supportsPipelinesInViews=!0,this.supportsArraysInData=!0,this.hasTimestamptz=!1,this.readsNestedData=!0,this.orderByClause="ordinal",this.nullMatchesFunctionSignature=!0,this.supportsSelectReplace=!0,this.supportsBigIntPrecision=!0,this.supportsComplexFilteredSources=!0,this.supportsTempTables=!0,this.maxIdentifierLength=128,this.hasModOperator=!0,this.supportsLeftJoinUnnest=!0,this.requiresExplicitUnnestOrdering=!1,this.hasLateralColumnAliasInSelect=!1,this.supportsCountApprox=!1,this.supportsHyperLogLog=!1,this.supportsFullJoin=!0,this.nestedArrays=!0,this.compoundObjectInSchema=!0,this.booleanType="supported",this.likeEscape=!0,this.integerTypeMappings=[{min:BigInt(e.MIN_INT32),max:BigInt(e.MAX_INT32),numberType:"integer"},{min:e.MIN_INT64,max:e.MAX_INT64,numberType:"bigint"}]}sqlLateralJoinBag(d){throw this.cantPartitionWindowFunctionsOnExpressions?new Error(`Dialect '${this.name}' sets cantPartitionWindowFunctionsOnExpressions but does not implement sqlLateralJoinBag`):new Error("Internal error: sqlLateralJoinBag called but cantPartitionWindowFunctionsOnExpressions is false")}literalNumberType(d){if(!/^-?\d+$/.test(d))return{type:"number",numberType:"float"};const f=BigInt(d);for(const u of this.integerTypeMappings)if(f>=u.min&&f<=u.max)return{type:"number",numberType:u.numberType};return{type:"number",numberType:"bigint"}}static makeTimeLiteralNode(d,l,f,u,p){var h;const m=(h=d?.hasTimestamptz)!==null&&h!==void 0?h:!1;return p==="date"?{node:"dateLiteral",literal:l,typeDef:{type:"date",timeframe:u!==void 0&&(0,t.isDateUnit)(u)?u:void 0}}:f&&m?{node:"timestamptzLiteral",literal:l,typeDef:{type:"timestamptz",timeframe:u},timezone:f}:f?{node:"timestampLiteral",literal:l,typeDef:{type:"timestamp",timeframe:u},timezone:f}:{node:"timestampLiteral",literal:l,typeDef:{type:"timestamp",timeframe:u}}}sqlTurtleOrderByClause(d){const l=d.map(f=>` ${f.field} ${f.dir.toUpperCase()}`);return" "+this.sqlOrderBy(l,"turtle")}sqlFinalStage(d,l){throw new Error("Dialect has no final Stage but called Anyway")}sqlDateToString(d){return this.castToString(`DATE(${d})`)}sqlLiteralNumber(d){return d}ignoreInProject(d){return!1}needsCivilTimeComputation(d,l,f,u){const p=["day","week","month","quarter","year"],h=l!==void 0&&p.includes(l),m=f!==void 0&&p.includes(f),x=a(u);return{needed:t.TD.isAnyTimestamp(d)&&(h||m)&&x!==void 0,tz:x}}sqlTruncAndOffset(d,l,f,u){if(t.TD.isAnyTimestamp(d.typeDef)){const{needed:h,tz:m}=this.needsCivilTimeComputation(d.typeDef,f,u?.unit,l);if(h&&m){const x=this.sqlConvertToCivilTime(d.sql,m,d.typeDef);let E=x.sql;const C=x.typeDef;return f&&(E=this.sqlTruncate(E,f,C,!0,m)),u&&(E=this.sqlOffsetTime(E,u.op,u.magnitude,u.unit,C,!0,m)),this.sqlConvertFromCivilTime(E,m,d.typeDef)}}let p=d.sql;return f&&(p=this.sqlTruncate(p,f,d.typeDef,!1,a(l))),u&&(p=this.sqlOffsetTime(p,u.op,u.magnitude,u.unit,d.typeDef,!1,a(l))),p}exprToSQL(d,l){switch(l.node){case"now":return this.sqlNowExpr();case"timeDiff":return this.sqlMeasureTimeExpr(l);case"delta":{const f=l.kids.base;return f.node==="trunc"?this.sqlTruncAndOffset(f.e,d,f.units,{op:l.op,magnitude:l.kids.delta.sql,unit:l.units}):this.sqlTruncAndOffset(f,d,void 0,{op:l.op,magnitude:l.kids.delta.sql,unit:l.units})}case"trunc":return this.sqlTruncAndOffset(l.e,d,l.units);case"extract":return this.sqlTimeExtractExpr(d,l);case"cast":return this.sqlCast(d,l);case"regexpMatch":return this.sqlRegexpMatch(l);case"/":return this.divisionIsInteger?`${l.kids.left.sql}*1.0/${l.kids.right.sql}`:void 0;case"%":return this.hasModOperator?void 0:`MOD(${l.kids.left.sql},${l.kids.right.sql})`;case"dateLiteral":return this.sqlDateLiteral(d,l.literal);case"timestampLiteral":return this.sqlTimestampLiteral(d,l.literal,l.timezone);case"timestamptzLiteral":return this.sqlTimestamptzLiteral(d,l.literal,l.timezone);case"stringLiteral":return this.sqlLiteralString(l.literal);case"numberLiteral":return this.sqlLiteralNumber(l.literal);case"regexpLiteral":return this.sqlLiteralRegexp(l.literal);case"recordLiteral":return this.sqlLiteralRecord(l);case"arrayLiteral":return this.sqlLiteralArray(l)}}sqlSumDistinct(d,l,f){return"sqlSumDistinct called but not implemented"}sqlAggDistinct(d,l,f){return"sqlAggDistinct called but not implemented"}sqlSampleTable(d,l){if(l!==void 0)throw new Error(`Sampling is not supported on dialect ${this.name}.`);return d}sqlOrderBy(d,l){return`ORDER BY ${d.join(",")}`}sqlTzStr(d){return`"${d.queryTimezone}"`}sqlMakeUnnestKey(d,l){return this.concat(d,"'x'",l)}sqlStringAggDistinct(d,l,f){const u="__STRING_AGG_KS__",p="__STRING_AGG_KE__";return`REGEXP_REPLACE(
1
+ import{L as uO,r as D,j as w,N as gr,R as v4,Q as _4,U as oo}from"./index-C2IkGoJ8.js";import{r as S4,a as $2,b as A4,c as b4,d as R4,e as T4,f as w4,g as D4,h as L4,j as q2,k as j2,l as O0,m as Qh,n as O4,o as lO,p as N4,q as F4,s as I4,t as D3,u as L3,v as O3,w as At}from"./index-Cev5PtEG.js";import{a as S1}from"./index.umd-BwIMLH79.js";var Ca={},ry={},Hr={},ny={},lv;function st(){return lv||(lv=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.TD=e.ValueType=void 0,e.safeRecordGet=r,e.mkSafeRecord=s,e.exprHasKids=a,e.exprHasE=o,e.exprIsLeaf=c,e.isAsymmetricExpr=d,e.mkTemporal=f,e.isRawCast=u,e.isFilterExprType=p,e.isTimeLiteral=h,e.isParameterType=m,e.paramHasValue=x,e.expressionIsScalar=E,e.expressionIsAggregate=C,e.expressionIsUngroupedAggregate=g,e.expressionInvolvesAggregate=_,e.expressionIsCalculation=S,e.expressionIsAnalytic=R,e.isExpressionTypeLEQ=b,e.maxExpressionType=T,e.maxOfExpressionTypes=N,e.hasExpression=k,e.isTemporalType=L,e.isBasicAtomicType=F,e.isAtomicFieldType=M,e.canOrderBy=q,e.fieldIsIntrinsic=B,e.mkFieldDef=P,e.mkArrayDef=Y,e.mkArrayTypeDef=ee,e.isRepeatedRecordFunctionParam=oe,e.isRepeatedRecord=I,e.isRecordOrRepeatedRecord=X,e.isBasicArray=G,e.isMatrixOperation=te,e.isJoinable=V,e.isJoined=se,e.isJoinedSource=Ee,e.isDateUnit=Ce,e.isTimestampUnit=le,e.isExtractUnit=ae,e.refIsStructDef=ce,e.segmentHasErrors=ie,e.structHasErrors=xe,e.isReduceSegment=me,e.isPartialSegment=Te,e.isProjectSegment=ye,e.isQuerySegment=be,e.isSamplingRows=pe,e.isSamplingPercent=Pe,e.isSamplingEnable=qe,e.isRawSegment=Ue,e.isIndexSegment=pt,e.bareFieldUsage=gt,e.isSegmentSQL=St,e.isSegmentSource=Ot,e.isSourceRegistryReference=Qt,e.sourceBase=br,e.isSourceDef=rr,e.isPersistableSourceDef=Le,e.isBaseTable=We,e.isLiteral=wt,e.mergeEvalSpaces=He,e.isBasicAtomic=de,e.getIdentifier=he,e.isUserTypeDef=ke,e.isCompoundArrayData=Be,e.isTurtle=Ke,e.isAtomic=ot,e.isValueString=rt,e.isValueNumber=Nt,e.isValueBoolean=Rt,e.isValueTimestamp=Se,e.isValueDate=it,e.mergeUniqueKeyRequirement=Ge;const t=Object.prototype.hasOwnProperty;function r(re,we){return t.call(re,we)?re[we]:void 0}function s(){return Object.create(null)}function a(re){return"kids"in re}function o(re){return"e"in re}function c(re){return!(a(re)||o(re))}function d(re){return re.node==="aggregate"&&["sum","avg","count","distinct"].includes(re.function)}function l(re){return re.node!=="arrayLiteral"&&re.node!=="recordLiteral"}function f(re,we){if(!("typeDef"in re)){const Ye=typeof we=="string"?{type:we}:we;if(l(re))return{...re,typeDef:{...Ye}}}return re}function u(re){return"dstSQLType"in re}function p(re){return["string","number","boolean","date","timestamp","timestamptz"].includes(re)}function h(re){return re.node==="dateLiteral"||re.node==="timestampLiteral"||re.node==="timestamptzLiteral"}function m(re){return["string","number","boolean","date","timestamp","timestamptz","filter expression","error"].includes(re)}function x(re){return re.value!==null}function E(re){return re===void 0||re==="scalar"}function C(re){return re==="aggregate"||re==="ungrouped_aggregate"}function g(re){return re==="ungrouped_aggregate"}function _(re){return re==="aggregate"||re==="ungrouped_aggregate"||re==="aggregate_analytic"}function S(re){return re==="aggregate"||re==="scalar_analytic"||re==="aggregate_analytic"||re==="ungrouped_aggregate"}function R(re){return re==="aggregate_analytic"||re==="scalar_analytic"}function v(re){return{scalar:0,aggregate:1,ungrouped_aggregate:2,scalar_analytic:2,aggregate_analytic:3}[re]}function b(re,we){return re===we||v(re)<v(we)}function T(re,we){let Ye="scalar";return(re==="aggregate"||we==="aggregate")&&(Ye="aggregate"),(re==="ungrouped_aggregate"||we==="ungrouped_aggregate")&&(Ye="ungrouped_aggregate"),(re==="scalar_analytic"||we==="scalar_analytic")&&(Ye="scalar_analytic"),(re==="aggregate_analytic"||we==="aggregate_analytic")&&(Ye="aggregate_analytic"),(re==="scalar_analytic"&&we==="aggregate"||re==="aggregate"&&we==="scalar_analytic")&&(Ye="aggregate_analytic"),Ye}function N(re){return re.reduce(T,"scalar")}function k(re){return"e"in re&&re.e!==void 0}function L(re){return re==="date"||re==="timestamp"||re==="timestamptz"}function F(re){return["string","number","date","timestamp","timestamptz","boolean","json","sql native","error"].includes(re)}function M(re){return F(re)||re==="record"||re==="array"}function q(re){return["string","number","date","boolean","date","timestamp","timestamptz"].includes(re)}function B(re){return M(re.type)&&!k(re)}function P(re,we){if(G(re))return Y(re.elementTypeDef,we);if(I(re)){const{type:ze,fields:mt,elementTypeDef:Ct}=re;return{type:ze,fields:mt,elementTypeDef:Ct,join:"many",name:we}}if(re.type==="record"){const{type:ze,fields:mt}=re;return{type:ze,fields:mt,join:"one",name:we}}const Ye={name:we,type:re.type};switch(re.type){case"sql native":return{...Ye,rawType:re.rawType};case"number":{const ze=re.numberType;return ze?{...Ye,numberType:ze}:Ye}case"date":{const ze=re.timeframe;return ze?{name:we,type:"date",timeframe:ze}:Ye}case"timestamp":{const ze={name:we,type:"timestamp"};return re.timeframe&&(ze.timeframe=re.timeframe),ze}case"timestamptz":{const ze={name:we,type:"timestamptz"};return re.timeframe&&(ze.timeframe=re.timeframe),ze}}return Ye}function Y(re,we){if(re.type==="record")return{type:"array",join:"many",name:we,elementTypeDef:{type:"record_element"},fields:re.fields};const Ye=P(re,"value");return{type:"array",join:"many",name:we,elementTypeDef:re,fields:[Ye,{...Ye,name:"each",e:{node:"field",path:["value"]}}]}}function ee(re){return re.type==="record"?{type:"array",elementTypeDef:{type:"record_element"},fields:re.fields}:{type:"array",elementTypeDef:re}}function oe(re){return re.type==="array"&&re.elementTypeDef.type==="record_element"}function I(re){return re.type==="array"&&re.elementTypeDef.type==="record_element"}function X(re){return re.type==="record"||re.type==="array"&&"elementTypeDef"in re&&re.elementTypeDef.type==="record_element"}function G(re){return re.type==="array"&&re.elementTypeDef.type!=="record_element"}function te(re){return["left","right","full","inner"].includes(re)}function V(re){return["composite","table","sql_select","query_source","virtual","array","record"].includes(re.type)}function se(re){return"join"in re}function Ee(re){return rr(re)&&se(re)}function Ce(re){return["day","week","month","quarter","year"].includes(re)}function le(re){return Ce(re)||["hour","minute","second"].includes(re)}function ae(re){return le(re)||re==="day_of_week"||re==="day_of_year"}var Z;(function(re){re.Date="date",re.Timestamp="timestamp",re.Number="number",re.String="string"})(Z||(e.ValueType=Z={}));function ce(re){return typeof re!="string"}function ie(re){return!!((re.type==="reduce"||re.type==="project"||re.type==="partial")&&(re.extendSource&&re.extendSource.some(we=>we.type==="error")||re.queryFields.some(we=>we.type==="error")))}function xe(re){return re.fields.some(we=>we.type==="error")}function me(re){return re.type==="reduce"}function Te(re){return re.type==="partial"}function ye(re){return re.type==="project"}function be(re){return ye(re)||me(re)}function pe(re){return re.rows!==void 0}function Pe(re){return re.percent!==void 0}function qe(re){return re.enable!==void 0}function Ue(re){return re.type==="raw"}function pt(re){return re.type==="index"}function gt(re){return re.uniqueKeyRequirement===void 0&&re.analyticFunctionUse===void 0}function St(re){return"sql"in re}function Ot(re){return"type"in re&&(re.type==="sql_select"||re.type==="query_source")}function Qt(re){return re.type==="source_registry_reference"}function br(re){return{...re}}function rr(re){return re.type==="table"||re.type==="sql_select"||re.type==="query_source"||re.type==="query_result"||re.type==="finalize"||re.type==="nest_source"||re.type==="virtual"||re.type==="composite"}function Le(re){return re.type==="sql_select"||re.type==="query_source"}function We(re){return Ee(re)?!1:!!rr(re)}function wt(re){return re==="literal"}function He(...re){return re.length<=1&&re.every(we=>we==="literal")?"literal":re.every(we=>we==="constant"||we==="literal")?"constant":re.every(we=>we==="output"||we==="constant"||we==="literal")?"output":"input"}function de(re){return re.type==="string"||L(re.type)||re.type==="number"||re.type==="boolean"||re.type==="json"||re.type==="sql native"||re.type==="error"}function he(re){return re.as!==void 0?re.as:re.name}function ke(re){return re.type==="userType"}function Be(re){return Array.isArray(re)&&(re.length===0||typeof re[0]=="object"&&re[0]!==null&&!Array.isArray(re[0]))}function Ke(re){return re.type==="turtle"}function ot(re){return M(re.type)}function rt(re,we){return we.type==="string"}function Nt(re,we){return we.type==="number"}function Rt(re,we){return we.type==="boolean"}function Se(re,we){return we.type==="timestamp"}function it(re,we){return we.type==="date"}e.TD={isAtomic(re){return re!==void 0&&M(re.type)},isBasicAtomic(re){return re!==void 0&&de({type:re.type})},isString:re=>re?.type==="string",isNumber:re=>re?.type==="number",isBoolean:re=>re?.type==="boolean",isJSON:re=>re?.type==="json",isSQL:re=>re?.type==="sql native",isDate:re=>re?.type==="date",isTimestamp:re=>re?.type==="timestamp",isTimestamptz:re=>re?.type==="timestamptz",isAnyTimestamp(re){return re?.type==="timestamp"||re?.type==="timestamptz"},isTemporal(re){var we;const Ye=(we=re?.type)!==null&&we!==void 0?we:"";return L(Ye)},isError:re=>re?.type==="error",eq(re,we){if(re===void 0||we===void 0)return!1;function Ye(ze,mt){const Ct={},Tt=ze.fields||[],at=mt.fields||[];if(Tt.length!==at.length)return!1;for(const vt of Tt)if(vt.name)Ct[vt.name]=vt;else return!1;for(const vt of at)if(!e.TD.eq(Ct[vt.name],vt))return!1;return!0}return re.type==="array"&&we.type==="array"?re.elementTypeDef.type!==we.elementTypeDef.type?!1:re.elementTypeDef.type!=="record_element"&&we.elementTypeDef.type!=="record_element"?e.TD.eq(re.elementTypeDef,we.elementTypeDef):e.TD.isAtomic(re)&&e.TD.isAtomic(we)&&Ye(re,we):re.type==="record"&&we.type==="record"?e.TD.isAtomic(re)&&e.TD.isAtomic(we)&&Ye(re,we):re.type==="sql native"&&we.type==="sql native"?re.rawType!==void 0&&re.rawType===we.rawType:re.type===we.type}};function Ge(re,we){return re?we?{isCount:re.isCount||we.isCount}:re:we}})(ny)),ny}var cv;function ho(){if(cv)return Hr;cv=1,Object.defineProperty(Hr,"__esModule",{value:!0}),Hr.arg=t,Hr.spread=r,Hr.sql=s,Hr.constant=a,Hr.output=o,Hr.literal=c,Hr.variadicParam=d,Hr.param=l,Hr.makeParam=f,Hr.maxScalar=u,Hr.maxAggregate=p,Hr.anyExprType=h,Hr.maxUngroupedAggregate=m,Hr.maxAnalytic=x,Hr.minScalar=E,Hr.minAggregate=C,Hr.minAnalytic=g,Hr.overload=_,Hr.expandBlueprintMap=te,Hr.expandOverrideMapFromBase=Ee,Hr.def=le;const e=st();function t(ae){return{node:"function_parameter",name:ae}}function r(ae,Z=void 0,ce=void 0){return{node:"spread",e:ae,prefix:Z,suffix:ce}}function s(ae,...Z){const ce={node:"genericSQLExpr",kids:{args:[]},src:[]},ie=[...Z];let xe="";for(const me of ae){xe+=me;const Te=ie.shift();Te!==void 0&&(typeof Te=="string"?xe+=Te:(ce.src.push(xe),ce.kids.args.push(Te),xe=""))}return xe.length>0&&ce.src.push(xe),ce}function a(ae){return{...ae,evalSpace:"constant"}}function o(ae){return{...ae,evalSpace:"output"}}function c(ae){return{...ae,evalSpace:"literal"}}function d(ae,...Z){return{name:ae,isVariadic:!0,allowedTypes:Z}}function l(ae,...Z){return{name:ae,isVariadic:!1,allowedTypes:Z}}function f(ae,...Z){return{param:l(ae,...Z),arg:t(ae)}}function u(ae){return{...ae,expressionType:"scalar",evalSpace:"input"}}function p(ae){return{...ae,expressionType:"aggregate",evalSpace:"input"}}function h(ae){return{...ae,expressionType:void 0,evalSpace:"input"}}function m(ae){return{...ae,expressionType:"ungrouped_aggregate",evalSpace:"input"}}function x(ae){return{...ae,expressionType:"aggregate_analytic",evalSpace:"input"}}function E(ae){return{...ae,expressionType:"scalar",evalSpace:"input"}}function C(ae){return{...ae,expressionType:"aggregate",evalSpace:"input"}}function g(ae){return{...ae,expressionType:"scalar_analytic",evalSpace:"input"}}function _(ae,Z,ce,ie){return{returnType:ae,params:Z,e:ce,needsWindowOrderBy:ie?.needsWindowOrderBy,between:ie?.between,isSymmetric:ie?.isSymmetric,supportsOrderBy:ie?.supportsOrderBy,defaultOrderByArgIndex:ie?.defaultOrderByArgIndex,supportsLimit:ie?.supportsLimit}}function S(ae,Z=!0,ce=!0){if(!Z&&ae==="any")throw new Error("Return type cannot include any");if(typeof ae=="string")return{type:ae};if("array"in ae){const ie=Z?S(ae.array,!0):S(ae.array,!1);return ie.type==="record"?{type:"array",elementTypeDef:{type:"record_element"},fields:ie.fields}:{type:"array",elementTypeDef:ie}}else if("record"in ae){const ie=[];for(const[xe,me]of Object.entries(ae.record)){const Te=Z?S(me,!0):S(me,!1);e.TD.isAtomic(Te)&&ie.push((0,e.mkFieldDef)(Te,xe))}return{type:"record",fields:ie}}else if("generic"in ae){if(!ce)throw new Error("Cannot use generic");return{type:"generic",generic:ae.generic}}else if("sql_native"in ae)return{type:"sql native",rawType:ae.sql_native};throw new Error("Cannot figure out type")}function R(ae){if(ae==="any")throw new Error("Cannot return any type");if(typeof ae=="string")return E({type:ae});if("array"in ae)return h(S(ae,!1));if("record"in ae)return h(S(ae,!1));if("generic"in ae)return E(S(ae,!1));if("literal"in ae)return c(E(S(ae.literal,!1)));if("constant"in ae)return a(E(S(ae.constant,!1)));if("dimension"in ae)return E(S(ae.dimension,!1));if("measure"in ae)return C(S(ae.measure,!1));if("sql_native"in ae)return h({type:"sql native",rawType:ae.sql_native});if("calculation"in ae)return g(S(ae.calculation,!1));throw new Error("Invalid function blueprint")}function v(ae){return typeof ae=="string"||"array"in ae||"record"in ae||"generic"in ae||"literal"in ae||"constant"in ae||"dimension"in ae||"measure"in ae||"calculation"in ae||"sql_native"in ae}function b(ae){return v(ae)?[ae]:Array.isArray(ae)?ae:v(ae.variadic)?[ae.variadic]:ae.variadic}function T(ae){if(typeof ae=="string")return h({type:ae});if("generic"in ae)return h(S(ae));if("literal"in ae)return c(u(S(ae.literal)));if("constant"in ae)return a(u(S(ae.constant)));if("dimension"in ae)return u(S(ae.dimension));if("measure"in ae)return p(S(ae.measure));if("array"in ae)return h(S(ae,!1));if("record"in ae)return h(S(ae,!1));if("sql_native"in ae)return h({type:"sql native",rawType:ae.sql_native});if("calculation"in ae)return x(S(ae.calculation));throw new Error("Invalid function blueprint")}function N(ae){return ae.map(Z=>T(Z))}function k(ae){return typeof ae!="string"&&"variadic"in ae}function L(ae,Z){return{name:ae,allowedTypes:N(b(Z)),isVariadic:k(Z)}}function F(ae){return Object.entries(ae).map(ce=>L(ce[0],ce[1]))}function M(ae){const Z=[],ce=[];let ie=ae;for(;ie.length>0;){const me=ie.indexOf("${");if(me===-1){Z.push(ie);break}const Te=ie.slice(0,me);ie=ie.slice(me);const ye=ie.indexOf("}");if(ye===-1){Z.push(Te+ie);break}const be=ie.slice(2,ye);ie=ie.slice(ye+1);const pe=be.startsWith("..."),Pe=be.endsWith(":"),qe=pe?be.slice(3):Pe?be.slice(0,-1):be,Ue={node:"function_parameter",name:qe};Z.push(Te),pe?ce.push({node:"spread",e:Ue,prefix:"",suffix:""}):Pe&&qe==="order_by"?ce.push({node:"aggregate_order_by"}):Pe&&qe==="limit"?ce.push({node:"aggregate_limit"}):ce.push(Ue)}return{node:"genericSQLExpr",kids:{args:ce},src:Z}}function q(ae,Z){return k(Z)?{node:"spread",e:{node:"function_parameter",name:ae},prefix:"",suffix:""}:{node:"function_parameter",name:ae}}function B(ae,Z){const ce=Object.entries(Z.takes),ie=ce.length>0?ce.length-1:0;return{node:"genericSQLExpr",kids:{args:ce.map(xe=>q(xe[0],xe[1]))},src:[`${ae}(`,...Array(ie).fill(","),")"]}}function P(ae){return"sql"in ae.impl?M(ae.impl.sql):"expr"in ae.impl?ae.impl.expr:B(ae.impl.function,ae)}function Y(ae){return{e:P(ae),between:ae.impl.between,needsWindowOrderBy:ae.impl.needsWindowOrderBy,defaultOrderByArgIndex:ae.impl.defaultOrderByArgIndex}}function ee(ae){if(ae!==void 0)return Object.entries(ae).map(([Z,ce])=>({name:Z,acceptibleTypes:ce.map(ie=>S(ie,!0,!1))}))}function oe(ae){return{returnType:R(ae.returns),params:F(ae.takes),isSymmetric:ae.isSymmetric,supportsOrderBy:ae.supportsOrderBy,supportsLimit:ae.supportsLimit,genericTypes:ee(ae.generic),...Y(ae)}}function I(ae){return"takes"in ae&&"returns"in ae&&"impl"in ae}function X(ae){return"function"in ae||"sql"in ae||"expr"in ae}function G(ae){return I(ae)?[oe(ae)]:Object.values(ae).flatMap(Z=>oe(Z))}function te(ae){const Z={};for(const ce in ae)Z[ce]=G(ae[ce]);return Z}function V(ae,Z){return[oe({...ae,impl:Z})]}function se(ae,Z,ce){if(X(ce)){if(!I(Z))throw new Error(`Malformed function override: ${ae}. Attempt to override multiple overloads with a single overload (missing: ${Object.keys(Z)})`);return V(Z,ce)}else{if(I(Z))throw new Error(`Malformed function override: ${ae}. Attempt to override a single overload with multiple overloads (extraneous: ${Object.keys(ce)})`);return Object.entries(ce).flatMap(([ie,xe])=>{const me=Z[ie];if(me===void 0)throw new Error(`Malformed function override: ${ae}. No overload named ${ie}`);return V(me,xe)})}}function Ee(ae,Z){const ce={};for(const ie in Z){if(!(ie in ae))throw new Error(`Malformed function override: ${ie}. No such function in Malloy standard`);ce[ie]=se(ie,ae[ie],Z[ie])}return ce}function*Ce(ae){if(typeof ae!="string"){if("generic"in ae)yield ae;else if("record"in ae)for(const Z of Object.values(ae.record))yield*Ce(Z);else for(const Z of["array","literal","measure","dimension","measure","constant","cacluation"])if(Z in ae){yield*Ce(ae[Z]);return}}}function le(ae,Z,ce,ie={}){let xe=!1;const me={};for(const ye of Object.values(Z))for(const be of Ce(ye))me[be.generic]=["any"],xe=!0;xe&&ie.generic===void 0&&(ie.generic=me);const Te={takes:Z,returns:ce,impl:{function:ae.toUpperCase()},...ie};return{[ae]:Te}}return Hr}var iy={},dv;function za(){return dv||(dv=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.Dialect=e.dayIndex=e.MAX_DECIMAL38=e.MIN_DECIMAL38=e.MAX_INT128=e.MIN_INT128=e.MAX_INT64=e.MIN_INT64=e.MAX_INT32=e.MIN_INT32=void 0,e.inDays=s,e.qtz=a;const t=st();e.MIN_INT32=-2147483648,e.MAX_INT32=2147483647,e.MIN_INT64=BigInt("-9223372036854775808"),e.MAX_INT64=BigInt("9223372036854775807"),e.MIN_INT128=BigInt("-170141183460469231731687303715884105728"),e.MAX_INT128=BigInt("170141183460469231731687303715884105727"),e.MIN_DECIMAL38=BigInt("-99999999999999999999999999999999999999"),e.MAX_DECIMAL38=BigInt("99999999999999999999999999999999999999");const r=["microsecond","millisecond","second","minute","hour","day","week","month","quarter","year"];e.dayIndex=r.indexOf("day");function s(c){return r.indexOf(c)>=e.dayIndex}function a(c){const d=c.queryTimezone;if(!(d===void 0||d===c.systemTimezone))return d}class o{constructor(){this.cantPartitionWindowFunctionsOnExpressions=!1,this.supportsPipelinesInViews=!0,this.supportsArraysInData=!0,this.hasTimestamptz=!1,this.readsNestedData=!0,this.orderByClause="ordinal",this.nullMatchesFunctionSignature=!0,this.supportsSelectReplace=!0,this.supportsBigIntPrecision=!0,this.supportsComplexFilteredSources=!0,this.supportsTempTables=!0,this.maxIdentifierLength=128,this.hasModOperator=!0,this.supportsLeftJoinUnnest=!0,this.requiresExplicitUnnestOrdering=!1,this.hasLateralColumnAliasInSelect=!1,this.supportsCountApprox=!1,this.supportsHyperLogLog=!1,this.supportsFullJoin=!0,this.nestedArrays=!0,this.compoundObjectInSchema=!0,this.booleanType="supported",this.likeEscape=!0,this.integerTypeMappings=[{min:BigInt(e.MIN_INT32),max:BigInt(e.MAX_INT32),numberType:"integer"},{min:e.MIN_INT64,max:e.MAX_INT64,numberType:"bigint"}]}sqlLateralJoinBag(d){throw this.cantPartitionWindowFunctionsOnExpressions?new Error(`Dialect '${this.name}' sets cantPartitionWindowFunctionsOnExpressions but does not implement sqlLateralJoinBag`):new Error("Internal error: sqlLateralJoinBag called but cantPartitionWindowFunctionsOnExpressions is false")}literalNumberType(d){if(!/^-?\d+$/.test(d))return{type:"number",numberType:"float"};const f=BigInt(d);for(const u of this.integerTypeMappings)if(f>=u.min&&f<=u.max)return{type:"number",numberType:u.numberType};return{type:"number",numberType:"bigint"}}static makeTimeLiteralNode(d,l,f,u,p){var h;const m=(h=d?.hasTimestamptz)!==null&&h!==void 0?h:!1;return p==="date"?{node:"dateLiteral",literal:l,typeDef:{type:"date",timeframe:u!==void 0&&(0,t.isDateUnit)(u)?u:void 0}}:f&&m?{node:"timestamptzLiteral",literal:l,typeDef:{type:"timestamptz",timeframe:u},timezone:f}:f?{node:"timestampLiteral",literal:l,typeDef:{type:"timestamp",timeframe:u},timezone:f}:{node:"timestampLiteral",literal:l,typeDef:{type:"timestamp",timeframe:u}}}sqlTurtleOrderByClause(d){const l=d.map(f=>` ${f.field} ${f.dir.toUpperCase()}`);return" "+this.sqlOrderBy(l,"turtle")}sqlFinalStage(d,l){throw new Error("Dialect has no final Stage but called Anyway")}sqlDateToString(d){return this.castToString(`DATE(${d})`)}sqlLiteralNumber(d){return d}ignoreInProject(d){return!1}needsCivilTimeComputation(d,l,f,u){const p=["day","week","month","quarter","year"],h=l!==void 0&&p.includes(l),m=f!==void 0&&p.includes(f),x=a(u);return{needed:t.TD.isAnyTimestamp(d)&&(h||m)&&x!==void 0,tz:x}}sqlTruncAndOffset(d,l,f,u){if(t.TD.isAnyTimestamp(d.typeDef)){const{needed:h,tz:m}=this.needsCivilTimeComputation(d.typeDef,f,u?.unit,l);if(h&&m){const x=this.sqlConvertToCivilTime(d.sql,m,d.typeDef);let E=x.sql;const C=x.typeDef;return f&&(E=this.sqlTruncate(E,f,C,!0,m)),u&&(E=this.sqlOffsetTime(E,u.op,u.magnitude,u.unit,C,!0,m)),this.sqlConvertFromCivilTime(E,m,d.typeDef)}}let p=d.sql;return f&&(p=this.sqlTruncate(p,f,d.typeDef,!1,a(l))),u&&(p=this.sqlOffsetTime(p,u.op,u.magnitude,u.unit,d.typeDef,!1,a(l))),p}exprToSQL(d,l){switch(l.node){case"now":return this.sqlNowExpr();case"timeDiff":return this.sqlMeasureTimeExpr(l);case"delta":{const f=l.kids.base;return f.node==="trunc"?this.sqlTruncAndOffset(f.e,d,f.units,{op:l.op,magnitude:l.kids.delta.sql,unit:l.units}):this.sqlTruncAndOffset(f,d,void 0,{op:l.op,magnitude:l.kids.delta.sql,unit:l.units})}case"trunc":return this.sqlTruncAndOffset(l.e,d,l.units);case"extract":return this.sqlTimeExtractExpr(d,l);case"cast":return this.sqlCast(d,l);case"regexpMatch":return this.sqlRegexpMatch(l);case"/":return this.divisionIsInteger?`${l.kids.left.sql}*1.0/${l.kids.right.sql}`:void 0;case"%":return this.hasModOperator?void 0:`MOD(${l.kids.left.sql},${l.kids.right.sql})`;case"dateLiteral":return this.sqlDateLiteral(d,l.literal);case"timestampLiteral":return this.sqlTimestampLiteral(d,l.literal,l.timezone);case"timestamptzLiteral":return this.sqlTimestamptzLiteral(d,l.literal,l.timezone);case"stringLiteral":return this.sqlLiteralString(l.literal);case"numberLiteral":return this.sqlLiteralNumber(l.literal);case"regexpLiteral":return this.sqlLiteralRegexp(l.literal);case"recordLiteral":return this.sqlLiteralRecord(l);case"arrayLiteral":return this.sqlLiteralArray(l)}}sqlSumDistinct(d,l,f){return"sqlSumDistinct called but not implemented"}sqlAggDistinct(d,l,f){return"sqlAggDistinct called but not implemented"}sqlSampleTable(d,l){if(l!==void 0)throw new Error(`Sampling is not supported on dialect ${this.name}.`);return d}sqlOrderBy(d,l){return`ORDER BY ${d.join(",")}`}sqlTzStr(d){return`"${d.queryTimezone}"`}sqlMakeUnnestKey(d,l){return this.concat(d,"'x'",l)}sqlStringAggDistinct(d,l,f){const u="__STRING_AGG_KS__",p="__STRING_AGG_KE__";return`REGEXP_REPLACE(
2
2
  STRING_AGG(DISTINCT ${`concat('${u}', ${d}, '${p}', ${l})`}${f.length>0?","+f:""}),
3
3
  '${u}.*?${p}',
4
4
  ''
@@ -729,7 +729,7 @@ ${te}`:I=te}return I}childRequest(I){var X;const G=decodeURI(new URL(I,this.sour
729
729
  `)}}this.stream.write(`
730
730
  ]
731
731
  `),this.stream.close()}}La.JSONWriter=r;class s extends t{constructor(){super(...arguments),this.columnSeparator=",",this.rowSeparator=`
732
- `,this.quoteCharacter='"',this.includeHeader=!0,this.emptyCell=""}escape(o){const c=o.includes(this.quoteCharacter),d=o.includes(this.columnSeparator),l=o.includes(this.rowSeparator),f=d||c||l;return c&&(o=o.replace(new RegExp(this.quoteCharacter,"g"),this.quoteCharacter+this.quoteCharacter)),f&&(o=this.quoteCharacter+o+this.quoteCharacter),o}stringify(o){return o===null?this.emptyCell:o instanceof Date?o.toISOString():typeof o=="boolean"||typeof o=="number"?JSON.stringify(o):typeof o=="bigint"?o.toString():`${o}`}getColWeight(o){let c=o;Array.isArray(o)&&(c=o[0]);let d=0;for(const l in c){d=d+1;const f=c[l];if((0,e.isCompoundArrayData)(f)){const u=this.getColWeight(f)-1;d=d+u}}return d}getHeaderRow(o){const c=[];let d=0;for(const l in o){c.push(this.escape(l));const f=o[l];if(d++,(0,e.isCompoundArrayData)(f)){const u=this.getColWeight(f)-1;d=d+u;for(let p=0;p<u;p++)c.push(this.emptyCell)}}return{rows:[c.join(this.columnSeparator)],length:1,width:d}}mergeMatrices(o){const c=Math.max(...o.map(f=>f.length)),d=o.reduce((f,u)=>f+u.width,0),l=[];for(let f=0;f<c;f++){const u=[];for(const p of o)if(f<p.length)u.push(p.rows[f]);else{const h=Array(p.width).fill(this.emptyCell);u.push(...h)}l.push(u.join(this.columnSeparator))}return{rows:l,length:c,width:d}}getChildMatrix(o){if(Array.isArray(o)){if(o.length===0)return{rows:[""],length:1,width:1}}else return{rows:["Invalid data found, value is not an array"],length:1,width:1};const c=[],d=this.getHeaderRow(o[0]);c.push(...d.rows);const l=d.width;let f=1;for(const u of o){const p=this.getRowMatrix(u);f=f+p.length,c.push(...p.rows)}return{rows:c,length:f,width:l}}getRowMatrix(o){const c=[];for(const d in o){const l=o[d];if((0,e.isCompoundArrayData)(l)){const f=this.getChildMatrix(l);c.push(f)}else{const f={rows:[this.stringify(l)],length:1,width:1};c.push(f)}}return this.mergeMatrices(c)}async process(o){let c=!1;for await(const d of o){if(!c&&this.includeHeader){const f=this.getHeaderRow(d.toObject());this.stream.write(f.rows[0]),this.stream.write(this.rowSeparator),c=!0}const l=this.getRowMatrix(d.toObject());for(const f of l.rows)this.stream.write(f),this.stream.write(this.rowSeparator)}this.stream.close()}}return La.CSVWriter=s,La}var Ln={},Hl={},ki={},Fb;function ng(){if(Fb)return ki;Fb=1;var e={};Object.defineProperty(ki,"__esModule",{value:!0}),ki.isValueRef=t,ki.resolveValue=r,ki.isConnectionConfigEntry=s,ki.registerConnectionType=o,ki.getConnectionProperties=c,ki.getConnectionTypeDisplayName=d,ki.getRegisteredConnectionTypes=l,ki.readConnectionsConfig=f,ki.writeConnectionsConfig=u,ki.createConnectionsFromConfig=p;function t(h){return typeof h=="object"&&h!==null&&!Array.isArray(h)&&Object.keys(h).length===1&&"env"in h&&typeof h.env=="string"}function r(h){return e[h.env]}function s(h){return typeof h=="object"&&h!==null&&typeof h.is=="string"}const a=new Map;function o(h,m){a.set(h,m)}function c(h){var m;return(m=a.get(h))===null||m===void 0?void 0:m.properties}function d(h){var m;return(m=a.get(h))===null||m===void 0?void 0:m.displayName}function l(){return[...a.keys()]}function f(h){var m;const x=JSON.parse(h),E=Object.fromEntries(Object.entries((m=x.connections)!==null&&m!==void 0?m:{}).filter(([,C])=>s(C)));return{...x,connections:E}}function u(h){return JSON.stringify(h,null,2)}function p(h,m){const x=Object.entries(h.connections),E=x.length>0?x[0][0]:void 0,C=new Map;return{async lookupConnection(g){if(g===void 0&&(g=E),g===void 0)throw new Error("No connections defined in config");const _=C.get(g);if(_)return _;const S=h.connections[g];if(!S)throw new Error(`No connection named "${g}" found in config`);const R=a.get(S.is);if(!R)throw new Error(`No registered connection type "${S.is}" for connection "${g}". Did you forget to import the connection package?`);const v=new Set(R.properties.filter(N=>N.type==="json").map(N=>N.name)),b={name:g};for(const[N,k]of Object.entries(S))if(N!=="is"&&k!=null)if(!v.has(N)&&t(k)){const L=r(k);L!==void 0&&(b[N]=L)}else b[N]=k;const T=await R.factory(b);return m&&m(g,T),C.set(g,T),T},async close(){const g=[...C.values()];C.clear();for(const _ of g)await _.close()}}}return ki}var Gf={},Ib;function cI(){return Ib||(Ib=1,Object.defineProperty(Gf,"__esModule",{value:!0}),Gf.MALLOY_VERSION=void 0,Gf.MALLOY_VERSION="0.0.369"),Gf}var kb;function $6(){if(kb)return Hl;kb=1,Object.defineProperty(Hl,"__esModule",{value:!0}),Hl.Malloy=Hl.MalloyError=void 0;const e=lE(),t=ng(),r=En(),s=ep(),a=cI(),o=tg(),c=P6(),d=rg(),l=B6(),f="internal://internal.malloy";function u(m){return[...Object.keys(m),...Object.values(m).map(u).flat()]}class p extends Error{constructor(x,E=[]){super(x),this.problems=E}}Hl.MalloyError=p;class h{static get version(){return a.MALLOY_VERSION}static registerConnectionType(x,E){(0,t.registerConnectionType)(x,E)}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,E,C,g,_){E===void 0&&(E=new URL(f));let S=E;g?.importBaseURL&&(S=g?.importBaseURL);const R=new e.MalloyTranslator(E.toString(),S.toString(),{urls:{[E.toString()]:x}},C);return g?.testEnvironment&&(R.allDialectsEnabled=!0),new c.Parse(R,_)}static parse({url:x,urlReader:E,source:C,eventStream:g,options:_}){if(C!==void 0)return h._parse(C,x,g,_);if(E===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,o.readURL)(E,x).then(({contents:S,invalidationKey:R})=>h._parse(S,x,g,_,R))}static async compile({url:x,source:E,parse:C,urlReader:g,connections:_,model:S,refreshSchemaCache:R,noThrowOnError:v,eventStream:b,importBaseURL:T,cacheManager:N}){var k,L,F,M,q;let B;if(R&&(B=typeof R=="number"?R:Date.now()),x===void 0&&E===void 0&&C===void 0)throw new Error("Internal Error: url, source, or parse required.");x===void 0&&(C!==void 0?x=new URL(C._translator.sourceURL):x=new URL(f));const P={};if(E===void 0&&N!==void 0){const oe=await N.getCachedModelDef(g,x.toString());if(oe)return new d.Model(oe.modelDef,[],[x.toString(),...u(oe.modelDef.dependencies)])}T??(T=x);let Y;const ee=x.toString();if(C!==void 0){Y=C._translator;const oe=(k=C._invalidationKey)!==null&&k!==void 0?k:await(0,o.getInvalidationKey)(g,x);P[ee]=oe}else{if(E===void 0){const{contents:oe,invalidationKey:I}=await(0,o.readURL)(g,x);P[ee]=I,E=oe}else{const oe=await(0,o.getInvalidationKey)(g,x);P[ee]=oe}Y=new e.MalloyTranslator(ee,T.toString(),{urls:{[ee]:E}},b)}for(;;){const oe=Y.translate(S?._modelDef);if(oe.final)if(oe.modelDef){await N?.setCachedModelDef(x.toString(),{modelDef:oe.modelDef,invalidationKeys:P});for(const X of Y.newlyTranslatedDependencies())await N?.setCachedModelDef(X.url,{modelDef:X.modelDef,invalidationKeys:P});const I=!oe.modelWasModified&&S?S.getExistingQueryModel():void 0;return new d.Model(oe.modelDef,oe.problems||[],[...(L=S?.fromSources)!==null&&L!==void 0?L:[],...(F=oe.fromSources)!==null&&F!==void 0?F:[]],I)}else if(v){const I=(0,r.mkModelDef)("modelDidNotCompile"),X=S?._modelDef||I;return new d.Model(X,oe.problems||[],[...(M=S?.fromSources)!==null&&M!==void 0?M:[],...(q=oe.fromSources)!==null&&q!==void 0?q:[]])}else{const I=oe.problems||[],X=Y.prettyErrors();throw new p(`Error(s) compiling model:
732
+ `,this.quoteCharacter='"',this.includeHeader=!0,this.emptyCell=""}escape(o){const c=o.includes(this.quoteCharacter),d=o.includes(this.columnSeparator),l=o.includes(this.rowSeparator),f=d||c||l;return c&&(o=o.replace(new RegExp(this.quoteCharacter,"g"),this.quoteCharacter+this.quoteCharacter)),f&&(o=this.quoteCharacter+o+this.quoteCharacter),o}stringify(o){return o===null?this.emptyCell:o instanceof Date?o.toISOString():typeof o=="boolean"||typeof o=="number"?JSON.stringify(o):typeof o=="bigint"?o.toString():`${o}`}getColWeight(o){let c=o;Array.isArray(o)&&(c=o[0]);let d=0;for(const l in c){d=d+1;const f=c[l];if((0,e.isCompoundArrayData)(f)){const u=this.getColWeight(f)-1;d=d+u}}return d}getHeaderRow(o){const c=[];let d=0;for(const l in o){c.push(this.escape(l));const f=o[l];if(d++,(0,e.isCompoundArrayData)(f)){const u=this.getColWeight(f)-1;d=d+u;for(let p=0;p<u;p++)c.push(this.emptyCell)}}return{rows:[c.join(this.columnSeparator)],length:1,width:d}}mergeMatrices(o){const c=Math.max(...o.map(f=>f.length)),d=o.reduce((f,u)=>f+u.width,0),l=[];for(let f=0;f<c;f++){const u=[];for(const p of o)if(f<p.length)u.push(p.rows[f]);else{const h=Array(p.width).fill(this.emptyCell);u.push(...h)}l.push(u.join(this.columnSeparator))}return{rows:l,length:c,width:d}}getChildMatrix(o){if(Array.isArray(o)){if(o.length===0)return{rows:[""],length:1,width:1}}else return{rows:["Invalid data found, value is not an array"],length:1,width:1};const c=[],d=this.getHeaderRow(o[0]);c.push(...d.rows);const l=d.width;let f=1;for(const u of o){const p=this.getRowMatrix(u);f=f+p.length,c.push(...p.rows)}return{rows:c,length:f,width:l}}getRowMatrix(o){const c=[];for(const d in o){const l=o[d];if((0,e.isCompoundArrayData)(l)){const f=this.getChildMatrix(l);c.push(f)}else{const f={rows:[this.stringify(l)],length:1,width:1};c.push(f)}}return this.mergeMatrices(c)}async process(o){let c=!1;for await(const d of o){if(!c&&this.includeHeader){const f=this.getHeaderRow(d.toObject());this.stream.write(f.rows[0]),this.stream.write(this.rowSeparator),c=!0}const l=this.getRowMatrix(d.toObject());for(const f of l.rows)this.stream.write(f),this.stream.write(this.rowSeparator)}this.stream.close()}}return La.CSVWriter=s,La}var Ln={},Hl={},ki={},Fb;function ng(){if(Fb)return ki;Fb=1;var e={};Object.defineProperty(ki,"__esModule",{value:!0}),ki.isValueRef=t,ki.resolveValue=r,ki.isConnectionConfigEntry=s,ki.registerConnectionType=o,ki.getConnectionProperties=c,ki.getConnectionTypeDisplayName=d,ki.getRegisteredConnectionTypes=l,ki.readConnectionsConfig=f,ki.writeConnectionsConfig=u,ki.createConnectionsFromConfig=p;function t(h){return typeof h=="object"&&h!==null&&!Array.isArray(h)&&Object.keys(h).length===1&&"env"in h&&typeof h.env=="string"}function r(h){return e[h.env]}function s(h){return typeof h=="object"&&h!==null&&typeof h.is=="string"}const a=new Map;function o(h,m){a.set(h,m)}function c(h){var m;return(m=a.get(h))===null||m===void 0?void 0:m.properties}function d(h){var m;return(m=a.get(h))===null||m===void 0?void 0:m.displayName}function l(){return[...a.keys()]}function f(h){var m;const x=JSON.parse(h),E=Object.fromEntries(Object.entries((m=x.connections)!==null&&m!==void 0?m:{}).filter(([,C])=>s(C)));return{...x,connections:E}}function u(h){return JSON.stringify(h,null,2)}function p(h,m){const x=Object.entries(h.connections),E=x.length>0?x[0][0]:void 0,C=new Map;return{async lookupConnection(g){if(g===void 0&&(g=E),g===void 0)throw new Error("No connections defined in config");const _=C.get(g);if(_)return _;const S=h.connections[g];if(!S)throw new Error(`No connection named "${g}" found in config`);const R=a.get(S.is);if(!R)throw new Error(`No registered connection type "${S.is}" for connection "${g}". Did you forget to import the connection package?`);const v=new Set(R.properties.filter(N=>N.type==="json").map(N=>N.name)),b={name:g};for(const[N,k]of Object.entries(S))if(N!=="is"&&k!=null)if(!v.has(N)&&t(k)){const L=r(k);L!==void 0&&(b[N]=L)}else b[N]=k;const T=await R.factory(b);return m&&m(g,T),C.set(g,T),T},async close(){const g=[...C.values()];C.clear();for(const _ of g)await _.close()}}}return ki}var Gf={},Ib;function cI(){return Ib||(Ib=1,Object.defineProperty(Gf,"__esModule",{value:!0}),Gf.MALLOY_VERSION=void 0,Gf.MALLOY_VERSION="0.0.370"),Gf}var kb;function $6(){if(kb)return Hl;kb=1,Object.defineProperty(Hl,"__esModule",{value:!0}),Hl.Malloy=Hl.MalloyError=void 0;const e=lE(),t=ng(),r=En(),s=ep(),a=cI(),o=tg(),c=P6(),d=rg(),l=B6(),f="internal://internal.malloy";function u(m){return[...Object.keys(m),...Object.values(m).map(u).flat()]}class p extends Error{constructor(x,E=[]){super(x),this.problems=E}}Hl.MalloyError=p;class h{static get version(){return a.MALLOY_VERSION}static registerConnectionType(x,E){(0,t.registerConnectionType)(x,E)}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,E,C,g,_){E===void 0&&(E=new URL(f));let S=E;g?.importBaseURL&&(S=g?.importBaseURL);const R=new e.MalloyTranslator(E.toString(),S.toString(),{urls:{[E.toString()]:x}},C);return g?.testEnvironment&&(R.allDialectsEnabled=!0),new c.Parse(R,_)}static parse({url:x,urlReader:E,source:C,eventStream:g,options:_}){if(C!==void 0)return h._parse(C,x,g,_);if(E===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,o.readURL)(E,x).then(({contents:S,invalidationKey:R})=>h._parse(S,x,g,_,R))}static async compile({url:x,source:E,parse:C,urlReader:g,connections:_,model:S,refreshSchemaCache:R,noThrowOnError:v,eventStream:b,importBaseURL:T,cacheManager:N}){var k,L,F,M,q;let B;if(R&&(B=typeof R=="number"?R:Date.now()),x===void 0&&E===void 0&&C===void 0)throw new Error("Internal Error: url, source, or parse required.");x===void 0&&(C!==void 0?x=new URL(C._translator.sourceURL):x=new URL(f));const P={};if(E===void 0&&N!==void 0){const oe=await N.getCachedModelDef(g,x.toString());if(oe)return new d.Model(oe.modelDef,[],[x.toString(),...u(oe.modelDef.dependencies)])}T??(T=x);let Y;const ee=x.toString();if(C!==void 0){Y=C._translator;const oe=(k=C._invalidationKey)!==null&&k!==void 0?k:await(0,o.getInvalidationKey)(g,x);P[ee]=oe}else{if(E===void 0){const{contents:oe,invalidationKey:I}=await(0,o.readURL)(g,x);P[ee]=I,E=oe}else{const oe=await(0,o.getInvalidationKey)(g,x);P[ee]=oe}Y=new e.MalloyTranslator(ee,T.toString(),{urls:{[ee]:E}},b)}for(;;){const oe=Y.translate(S?._modelDef);if(oe.final)if(oe.modelDef){await N?.setCachedModelDef(x.toString(),{modelDef:oe.modelDef,invalidationKeys:P});for(const X of Y.newlyTranslatedDependencies())await N?.setCachedModelDef(X.url,{modelDef:X.modelDef,invalidationKeys:P});const I=!oe.modelWasModified&&S?S.getExistingQueryModel():void 0;return new d.Model(oe.modelDef,oe.problems||[],[...(L=S?.fromSources)!==null&&L!==void 0?L:[],...(F=oe.fromSources)!==null&&F!==void 0?F:[]],I)}else if(v){const I=(0,r.mkModelDef)("modelDidNotCompile"),X=S?._modelDef||I;return new d.Model(X,oe.problems||[],[...(M=S?.fromSources)!==null&&M!==void 0?M:[],...(q=oe.fromSources)!==null&&q!==void 0?q:[]])}else{const I=oe.problems||[],X=Y.prettyErrors();throw new p(`Error(s) compiling model:
733
733
  ${X}`,I)}else{if(oe.urls)for(const X of oe.urls)try{if((0,o.isInternalURL)(X))throw new Error("In order to use relative imports, you must compile a file via a URL.");if(N!==void 0){const se=await N.getCachedModelDef(g,X);if(se){for(const Ee in se.invalidationKeys)P[Ee]=se.invalidationKeys[Ee];Y.update({translations:{[X]:se.modelDef}});continue}}const{contents:G,invalidationKey:te}=await(0,o.readURL)(g,new URL(X)),V={[X]:G};P[X]=te,Y.update({urls:V})}catch(G){Y.update({errors:{urls:{[X]:G.message}}})}const{modelAnnotation:I}=Y.modelAnnotation(S?._modelDef);if(oe.tables){const X=new Map;for(const G in oe.tables){const{connectionName:te,tablePath:V}=oe.tables[G],se=X.get(te);se===void 0?X.set(te,{[G]:V}):se[G]=V}for(const[G,te]of X)try{const V=await _.lookupConnection(G),{schemas:se,errors:Ee}=await h.safelyFetchTableSchema(V,te,{refreshTimestamp:B,modelAnnotation:I});Y.update({tables:se,errors:{tables:Ee}})}catch(V){const se={},Ee={};for(const Ce in te)Ee[Ce]=V.toString();Y.update({tables:se,errors:{tables:Ee}})}}if(oe.connectionDialects)for(const X in oe.connectionDialects){const{connectionName:G}=oe.connectionDialects[X];try{const te=await _.lookupConnection(G);Y.update({connectionDialects:{[X]:te.dialectName}})}catch(te){Y.update({errors:{connectionDialects:{[X]:te.toString()}}})}}if(oe.compileSQL){const X=oe.compileSQL,G=X.connection,te=(0,s.sqlKey)(X.connection,X.selectStr);try{const se=await(await _.lookupConnection(G)).fetchSchemaForSQLStruct(X,{refreshTimestamp:B,modelAnnotation:I});se.error&&Y.update({errors:{compileSQL:{[te]:se.error}}}),se.structDef&&Y.update({compileSQL:{[te]:se.structDef}})}catch(V){const se={};se[te]=V.toString(),Y.update({errors:{compileSQL:se}})}}}}}static async safelyFetchTableSchema(x,E,C){const g=await x.fetchSchemaForTables(E,C);for(const _ of Object.keys(E))if(g.schemas[_]===void 0&&g.errors[_]===void 0)throw new Error(`Schema fetch error for ${x.name}, no response for ${_} from ${x.dialectName}`);return g}static async run({connections:x,preparedResult:E,sqlStruct:C,connection:g,options:_}){if(!g){if(!x)throw new Error("Internal Error: Connection or LookupConnection<Connection> must be provided.");const S=C?.connection||E?.connectionName;g=await x.lookupConnection(S)}if(C){const S=await g.runSQL(C.selectStr);return new l.Result({structs:[C],sql:C.selectStr,result:S.rows,totalRows:S.totalRows,runStats:S.runStats,lastStageName:C.name,malloy:"",connectionName:C.connection,sourceExplore:"",sourceFilters:[],profilingUrl:S.profilingUrl},(0,r.mkModelDef)("empty_model"))}else if(E){const S=await g.runSQL(E.sql,_);return new l.Result({...E._rawQuery,result:S.rows,totalRows:S.totalRows,runStats:S.runStats,profilingUrl:S.profilingUrl},E._modelDef)}else throw new Error("Internal error: sqlStruct or preparedResult must be provided.")}static async*runStream({connections:x,preparedResult:E,sqlStruct:C,connection:g,options:_}){if(C===void 0&&E===void 0)throw new Error("Internal error: sqlBlock or preparedResult must be provided.");const S=C?.connection||E?.connectionName;if(g===void 0){if(x===void 0)throw new Error("Internal Error: Connection or LookupConnection<Connection> must be provided.");g=await x.lookupConnection(S)}if(!g.canStream())throw new Error(`Connection '${S}' cannot stream results.`);let R,v;if(C)v=new d.Explore(C),R=C.selectStr;else if(E!==void 0)v=E.resultExplore,R=E.sql;else throw new Error("Internal error: sqlStruct or preparedResult must be provided.");let b=0;for await(const T of g.runSQLStream(R,_))yield new l.DataRecord(T,b,v,void 0,void 0),b+=1}static async estimateQueryCost({connections:x,preparedResult:E,sqlStruct:C}){if(!x)throw new Error("Internal Error: Connection or LookupConnection<Connection> must be provided.");const g=C?.connection||E?.connectionName,_=await x.lookupConnection(g);if(C)return await _.estimateQueryCost(C.selectStr);if(E)return await _.estimateQueryCost(E.sql);throw new Error("Internal error: sqlStruct or preparedResult must be provided.")}}return Hl.Malloy=h,Hl}var Mb;function dI(){if(Mb)return Ln;Mb=1,Object.defineProperty(Ln,"__esModule",{value:!0}),Ln.ExploreMaterializer=Ln.PreparedResultMaterializer=Ln.QueryMaterializer=Ln.ModelMaterializer=Ln.SingleConnectionRuntime=Ln.ConnectionRuntime=Ln.Runtime=void 0;const e=En(),t=cc(),r=Vh(),s=tg(),a=rg(),o=$6();class c{constructor(C,g){this.runtime=C,this._materialize=g}materialize(){return this.materialized===void 0?this.rematerialize():this.materialized}rematerialize(){return this.materialized=this._materialize(),this.materialized}makeQueryMaterializer(C,g){return new h(this.runtime,C,g)}makeExploreMaterializer(C,g){return new x(this.runtime,C,g)}makePreparedResultMaterializer(C){return new m(this.runtime,C)}}class d{constructor({urlReader:C,connections:g,connection:_,config:S,eventStream:R,cacheManager:v}){if(this.isTestRuntime=!1,S!==void 0)this._config=S,g=g??S.connections;else if(g===void 0){if(_===void 0)throw new Error("A MalloyConfig, LookupConnection<Connection>, or Connection is required.");g={lookupConnection:()=>Promise.resolve(_)}}C===void 0&&(C=new s.EmptyURLReader),this._urlReader=C,this._connections=g,this._eventStream=R,this._cacheManager=v}get cacheManager(){return this._cacheManager}get urlReader(){return this._urlReader}get connections(){return this._connections}get eventStream(){return this._eventStream}get buildManifest(){var C,g;return(C=this._buildManifest)!==null&&C!==void 0?C:(g=this._config)===null||g===void 0?void 0:g.manifest.buildManifest}set buildManifest(C){this._buildManifest=C}get virtualMap(){var C,g;return(C=this._virtualMap)!==null&&C!==void 0?C:(g=this._config)===null||g===void 0?void 0:g.virtualMap}set virtualMap(C){this._virtualMap=C}loadModel(C,g){const{refreshSchemaCache:_,noThrowOnError:S}=g||{};this.isTestRuntime&&(g===void 0?g={testEnvironment:!0}:g={...g,testEnvironment:!0});const R=C instanceof URL?{url:C}:{source:C};return new u(this,async()=>o.Malloy.compile({...R,urlReader:this.urlReader,connections:this.connections,refreshSchemaCache:_,noThrowOnError:S,eventStream:this.eventStream,importBaseURL:g?.importBaseURL,testEnvironment:g?.testEnvironment,cacheManager:this.cacheManager}),g)}_loadModelFromModelDef(C,g){return new u(this,async()=>new a.Model(C,[],[]),g)}loadQuery(C,g){return this.loadModel(C,g).loadFinalQuery()}loadQueryByIndex(C,g,_){return this.loadModel(C,_).loadQueryByIndex(g,_)}loadQueryByName(C,g,_){return this.loadModel(C,_).loadQueryByName(g,_)}getModel(C,g){return this.loadModel(C,g).getModel()}getQuery(C,g){return this.loadQuery(C,g).getPreparedQuery()}getQueryByIndex(C,g,_){return this.loadQueryByIndex(C,g,_).getPreparedQuery()}getQueryByName(C,g,_){return this.loadQueryByName(C,g,_).getPreparedQuery()}}Ln.Runtime=d;class l extends d{constructor({urlReader:C,connections:g}){super({connections:s.FixedConnectionMap.fromArray(g),urlReader:C}),this.rawConnections=g}}Ln.ConnectionRuntime=l;class f extends d{constructor({urlReader:C,connection:g,eventStream:_,cacheManager:S}){super({urlReader:C,eventStream:_,cacheManager:S,connection:g}),this.connection=g}get supportsNesting(){return(0,t.getDialect)(this.connection.dialectName).supportsNesting}quote(C){return(0,t.getDialect)(this.connection.dialectName).sqlMaybeQuoteIdentifier(C)}get dialect(){return(0,t.getDialect)(this.connection.dialectName)}getQuoter(){return C=>this.quote(C.toString())}}Ln.SingleConnectionRuntime=f;class u extends c{constructor(C,g,_){super(C,g),this.runtime=C,this.compileQueryOptions=_}loadFinalQuery(C){return this.makeQueryMaterializer(async()=>(await this.materialize()).getPreparedQuery(),{...this.compileQueryOptions,...C})}loadQueryByIndex(C,g){return this.makeQueryMaterializer(async()=>(await this.materialize()).getPreparedQueryByIndex(C),{...this.compileQueryOptions,...g})}loadQueryByName(C,g){return this.makeQueryMaterializer(async()=>(await this.materialize()).getPreparedQueryByName(C),{...this.compileQueryOptions,...g})}loadQuery(C,g){const{refreshSchemaCache:_,noThrowOnError:S}=g||{};return this.makeQueryMaterializer(async()=>{const R=this.runtime.urlReader,v=this.runtime.connections;this.runtime.isTestRuntime&&(g===void 0?g={testEnvironment:!0}:g={...g,testEnvironment:!0});const b=C instanceof URL?{url:C}:{source:C},T=await this.getModel();return(await o.Malloy.compile({...b,urlReader:R,connections:v,model:T,refreshSchemaCache:_,noThrowOnError:S,importBaseURL:g?.importBaseURL,testEnvironment:g?.testEnvironment,...this.compileQueryOptions})).preparedQuery})}extendModel(C,g){return this.runtime.isTestRuntime&&(g===void 0?g={testEnvironment:!0}:g={...g,testEnvironment:!0}),new u(this.runtime,async()=>{const _=this.runtime.urlReader,S=this.runtime.connections,R=C instanceof URL?{url:C}:{source:C},v=await this.getModel();return await o.Malloy.compile({...R,urlReader:_,connections:S,model:v,refreshSchemaCache:g?.refreshSchemaCache,noThrowOnError:g?.noThrowOnError,importBaseURL:g?.importBaseURL,testEnvironment:g?.testEnvironment,...this.compileQueryOptions})},g)}async search(C,g,_=1e3,S=void 0){const R=await this.materialize(),v=R.queryModel,b=R.getExploreByName(C).structDef;if(!(0,e.isSourceDef)(b))throw new Error("Source to be searched was unexpectedly, not a source");const T=b.connection,N=await this.runtime.connections.lookupConnection(T);return await v.searchIndex(N,C,g,_,S)}async searchValueMap(C,g=10,_){const R=(await this.materialize()).getExploreByName(C);if(!(0,e.isSourceDef)(R.structDef))throw new Error("Source to be searched was unexpectedly, not a source");let v="{index: *}";R.getFieldByNameIfExists("search_index")&&(v="search_index");const b=`
734
734
  run: ${C}
735
735
  -> ${v}