@malloydata/render 0.0.340 → 0.0.341
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/module/index.mjs +12 -3
- package/dist/module/index.umd.js +2 -2
- package/package.json +5 -5
package/dist/module/index.mjs
CHANGED
|
@@ -7552,11 +7552,20 @@ class uue {
|
|
|
7552
7552
|
break;
|
|
7553
7553
|
}
|
|
7554
7554
|
}
|
|
7555
|
+
/**
|
|
7556
|
+
* Like `skipWs`, but also eats commas. Used in statement-list
|
|
7557
|
+
* contexts (top-level document and properties blocks) so commas
|
|
7558
|
+
* can serve as optional separators between statements.
|
|
7559
|
+
*/
|
|
7560
|
+
skipWsAndCommas() {
|
|
7561
|
+
for (this.skipWs(); this.peekChar() === ","; )
|
|
7562
|
+
this.advance(1), this.skipWs();
|
|
7563
|
+
}
|
|
7555
7564
|
// ── Statement Dispatch ──────────────────────────────────────────
|
|
7556
7565
|
parseStatements() {
|
|
7557
7566
|
const t = [];
|
|
7558
|
-
for (this.
|
|
7559
|
-
t.push(this.parseStatement()), this.
|
|
7567
|
+
for (this.skipWsAndCommas(); this.pos < this.input.length; )
|
|
7568
|
+
t.push(this.parseStatement()), this.skipWsAndCommas();
|
|
7560
7569
|
return t;
|
|
7561
7570
|
}
|
|
7562
7571
|
parseStatement() {
|
|
@@ -8021,7 +8030,7 @@ class uue {
|
|
|
8021
8030
|
}
|
|
8022
8031
|
const n = [];
|
|
8023
8032
|
for (; ; ) {
|
|
8024
|
-
if (this.
|
|
8033
|
+
if (this.skipWsAndCommas(), this.eatChar("}"))
|
|
8025
8034
|
return n;
|
|
8026
8035
|
if (this.pos >= this.input.length)
|
|
8027
8036
|
throw this.errorSpan("Unclosed '{'", t);
|
package/dist/module/index.umd.js
CHANGED
|
@@ -47,12 +47,12 @@ ${n}}`,r}constructor(t={},n){if(n!==void 0&&(this._parent=n),t.eq!==void 0&&(Arr
|
|
|
47
47
|
`,n}find(t){let n=this;for(const r of t){let i;if(typeof r=="number"?i=n.getArrayElement(r):i=n.getProperty(r),i===void 0)return;n=i}return n.deleted?void 0:n}has(...t){return this.find(t)!==void 0}set(t,n=null){let r=this,i,s;for(const a of t)if(i=r,s=a,typeof a=="number"){if(r.eq===void 0||!Array.isArray(r.eq))r.eq=Array.from({length:a+1}).map(()=>new rt({},r));else if(r.eq.length<=a){const o=r.eq,l=Array.from({length:a+1}).map((u,c)=>c<o.length?o[c]:new rt({},r));r.eq=l}r=r.eq[a]}else{const o=r.properties;o===void 0?(r.properties={[a]:new rt({},r)},r=r.properties[a]):a in o?(r=o[a],r.deleted&&(r.deleted=!1)):(o[a]=new rt({},r),r=o[a])}if(n===null)r.eq=void 0;else if(n instanceof rt){const a=n.clone(i);i&&s!==void 0&&(typeof s=="number"&&Array.isArray(i.eq)?i.eq[s]=a:typeof s=="string"&&i.properties&&(i.properties[s]=a))}else typeof n=="string"||typeof n=="number"||typeof n=="boolean"||n instanceof Date?r.eq=n:Array.isArray(n)&&(r.eq=n.map(a=>new rt({eq:a},r)));return this}delete(...t){return this.remove(t,!1)}unset(...t){return this.remove(t,!0)}remove(t,n=!1){var r;let i=this;for(const a of t.slice(0,t.length-1))if(typeof a=="number"){if(i.eq===void 0||!Array.isArray(i.eq)){if(!n)return this;i.eq=Array.from({length:a}).map(()=>new rt({},i))}else if(i.eq.length<=a){if(!n)return this;const o=i.eq,l=Array.from({length:a}).map((u,c)=>c<o.length?o[c]:new rt({},i));i.eq=l}i=i.eq[a]}else{const o=i.properties;if(o===void 0){if(!n)return this;i.properties={[a]:new rt({},i)},i=i.properties[a]}else if(a in o)i=o[a];else{if(!n)return this;o[a]=new rt({},i),i=o[a]}}const s=t[t.length-1];return typeof s=="string"?i.properties&&s in i.properties?delete i.properties[s]:n&&((r=i.properties)!==null&&r!==void 0||(i.properties={}),i.properties[s]=new rt({deleted:!0},i)):Array.isArray(i.eq)&&i.eq.splice(s,1),this}}zo.Tag=rt,rt.ids=new Map,rt.nextTagId=1e3;class N6 extends rt{constructor(t,n,r){super({},r),this.ups=t,this.refPath=n}resolve(){let t;if(this.ups===0)t=this.root;else{t=this.parent;for(let n=0;n<this.ups&&t!==void 0;n++)t=t.parent}if(t!==void 0)return t.find(this.refPath)}quoteSegment(t){return/^[0-9A-Za-z_\u00C0-\u024F\u1E00-\u1EFF]+$/.test(t)?t:"`"+t.replace(/\\/g,"\\\\").replace(/`/g,"\\`")+"`"}toRefString(){const t="$"+"^".repeat(this.ups),n=this.refPath.map((r,i)=>{if(typeof r=="number")return`[${r}]`;const s=this.quoteSegment(r);return i===0?s:`.${s}`}).join("");return t+n}getEq(){var t;return(t=this.resolve())===null||t===void 0?void 0:t.getEq()}getProperty(t){var n;return(n=this.resolve())===null||n===void 0?void 0:n.getProperty(t)}getArrayElement(t){var n;return(n=this.resolve())===null||n===void 0?void 0:n.getArrayElement(t)}hasProperties(){var t,n;return(n=(t=this.resolve())===null||t===void 0?void 0:t.hasProperties())!==null&&n!==void 0?n:!1}toObjectValue(t){if(t.has(this))return;const n=this.resolve();if(n===void 0)return;t.add(this);const r=n.toObjectValue(t);return t.delete(this),r}toJSON(){return{linkTo:this.toRefString()}}collectReferenceErrors(t,n){if(this.resolve()===void 0){const r=n.length>0?n.join("."):"root";t.push(`Unresolved reference at ${r}: ${this.toRefString()}`)}}clone(t){return new N6(this.ups,[...this.refPath],t)}}zo.RefTag=N6;function I6(e){const t={};return e.eq!==void 0&&(Array.isArray(e.eq)?t.eq=e.eq.map(n=>I6(n)):t.eq=e.eq),e.properties!==void 0&&(t.properties=hO(e.properties)),e.deleted&&(t.deleted=!0),t}function hO(e){const t={};for(const[n,r]of Object.entries(e))t[n]=I6(r);return t}var L1={},mO={},$2={},z6={};Object.defineProperty(z6,"__esModule",{value:!0}),z6.parse=yue;class pue{constructor(t){this.input=t,this.pos=0}remaining(){return this.input.substring(this.pos)}peekChar(){return this.pos<this.input.length?this.input[this.pos]:void 0}advance(t){this.pos+=t}startsWith(t){return this.input.startsWith(t,this.pos)}eatChar(t){return this.peekChar()===t?(this.advance(1),!0):!1}expectChar(t){if(!this.eatChar(t))throw this.errorPoint(`Expected '${t}'`)}position(){const t=this.input.substring(0,this.pos),n=(t.match(/\n/g)||[]).length,r=t.lastIndexOf(`
|
|
48
48
|
`),i=this.pos-(r===-1?0:r+1);return{line:n,column:i,offset:this.pos}}errorPoint(t){const n=this.position();return{code:"tag-parse-syntax-error",message:t,begin:n,end:n}}errorSpan(t,n){return{code:"tag-parse-syntax-error",message:t,begin:n,end:this.position()}}skipWs(){for(;;){for(;this.pos<this.input.length;){const t=this.input[this.pos];if(t===" "||t===" "||t==="\r"||t===`
|
|
49
49
|
`)this.pos++;else break}if(this.peekChar()==="#")for(;this.pos<this.input.length;){const t=this.input[this.pos];if(t==="\r"||t===`
|
|
50
|
-
`)break;this.pos++}else break}}parseStatements(){const t=[];for(this.
|
|
50
|
+
`)break;this.pos++}else break}}skipWsAndCommas(){for(this.skipWs();this.peekChar()===",";)this.advance(1),this.skipWs()}parseStatements(){const t=[];for(this.skipWsAndCommas();this.pos<this.input.length;)t.push(this.parseStatement()),this.skipWsAndCommas();return t}parseStatement(){if(this.startsWith("-..."))return this.advance(4),{kind:"clearAll"};if(this.peekChar()==="-")return this.advance(1),{kind:"define",path:this.parsePropName(),deleted:!0};const t=this.parsePropName();this.skipWs();const n=this.peekChar();if(n==="="){if(this.advance(1),this.skipWs(),this.startsWith("...")){const i=this.pos;if(this.advance(3),this.skipWs(),this.peekChar()==="{"){const s=this.parsePropertiesBlock();return{kind:"replaceProperties",path:t,properties:s,preserveValue:!0}}this.pos=i}if(this.peekChar()==="{"){const i=this.parsePropertiesBlock();return{kind:"replaceProperties",path:t,properties:i,preserveValue:!1}}const r=this.parseEqValue();if(this.skipWs(),this.peekChar()==="{"){const i=this.pos;if(this.advance(1),this.skipWs(),this.startsWith("...")){const a=this.pos;if(this.advance(3),this.skipWs(),this.peekChar()==="}")return this.advance(1),{kind:"setEq",path:t,value:r,properties:null,preserveProperties:!0};this.pos=a}this.pos=i;const s=this.parsePropertiesBlock();return{kind:"setEq",path:t,value:r,properties:s,preserveProperties:!1}}return{kind:"setEq",path:t,value:r,properties:null,preserveProperties:!1}}if(n===":"){this.advance(1),this.skipWs();const r=this.parsePropertiesBlock();return{kind:"replaceProperties",path:t,properties:r,preserveValue:!1}}if(n==="{"){const r=this.parsePropertiesBlock();return{kind:"updateProperties",path:t,properties:r}}return{kind:"define",path:t,deleted:!1}}parsePropName(){const n=[this.parseIdentifier()];for(;this.peekChar()===".";)this.advance(1),n.push(this.parseIdentifier());return n}parseIdentifier(){return this.peekChar()==="`"?this.parseBacktickString():this.parseBareString()}parseEqValue(){const t=this.peekChar();if(t==="[")return{kind:"array",elements:this.parseArray()};if(t==="@")return{kind:"scalar",value:this.parseAtValue()};if(t==="$")return{kind:"scalar",value:this.parseReference()};if(t==='"')return this.startsWith('"""')?{kind:"scalar",value:{kind:"string",value:this.parseTripleString()}}:{kind:"scalar",value:{kind:"string",value:this.parseDoubleQuotedString()}};if(t==="'")return this.startsWith("'''")?{kind:"scalar",value:{kind:"string",value:this.parseTripleSingleQuotedString()}}:{kind:"scalar",value:{kind:"string",value:this.parseSingleQuotedString()}};if(t!==void 0&&(t==="-"||t>="0"&&t<="9"||t==="."))return this.parseNumberOrString();if(t!==void 0&&gc(t))return{kind:"scalar",value:{kind:"string",value:this.parseBareString()}};throw this.errorPoint("Expected a value")}parseScalarValue(){const t=this.peekChar();if(t==="@")return{kind:"scalar",value:this.parseAtValue()};if(t==="$")return{kind:"scalar",value:this.parseReference()};if(t==='"')return this.startsWith('"""')?{kind:"scalar",value:{kind:"string",value:this.parseTripleString()}}:{kind:"scalar",value:{kind:"string",value:this.parseDoubleQuotedString()}};if(t==="'")return this.startsWith("'''")?{kind:"scalar",value:{kind:"string",value:this.parseTripleSingleQuotedString()}}:{kind:"scalar",value:{kind:"string",value:this.parseSingleQuotedString()}};if(t!==void 0&&(t>="0"&&t<="9"||t==="."||t==="-"))return this.parseNumberOrString();if(t!==void 0&&gc(t))return{kind:"scalar",value:{kind:"string",value:this.parseBareString()}};throw this.errorPoint("Expected a value")}parseAtValue(){const t=this.position();if(this.expectChar("@"),this.startsWith("true")&&!this.isBareCharAt(4))return this.advance(4),{kind:"boolean",value:!0};if(this.startsWith("false")&&!this.isBareCharAt(5))return this.advance(5),{kind:"boolean",value:!1};const n=this.peekChar();if(n!==void 0&&n>="0"&&n<="9")return this.parseDate(t);const r=this.pos;for(;this.pos<this.input.length&&gc(this.input[this.pos]);)this.pos++;const i=this.pos>r?this.input.substring(r,this.pos):"";throw this.errorSpan(`Illegal constant @${i}; expected @true, @false, or @date`,t)}isBareCharAt(t){const n=this.remaining();return t<n.length&&gc(n[t])}parseDate(t){const n=this.pos;if(this.consumeDigits(4,t),this.expectChar("-"),this.consumeDigits(2,t),this.expectChar("-"),this.consumeDigits(2,t),this.peekChar()==="T"){if(this.advance(1),this.consumeDigits(2,t),this.expectChar(":"),this.consumeDigits(2,t),this.peekChar()===":"&&(this.advance(1),this.consumeDigits(2,t),this.peekChar()===".")){this.advance(1);const s=this.pos;for(;this.pos<this.input.length&&this.input[this.pos]>="0"&&this.input[this.pos]<="9";)this.pos++;if(this.pos===s)throw this.errorSpan("Expected fractional digits in date",t)}const i=this.peekChar();i==="Z"?this.advance(1):(i==="+"||i==="-")&&(this.advance(1),this.consumeDigits(2,t),this.peekChar()===":"&&this.advance(1),this.consumeDigits(2,t))}return{kind:"date",value:this.input.substring(n,this.pos)}}consumeDigits(t,n){for(let r=0;r<t;r++){const i=this.peekChar();if(i===void 0||i<"0"||i>"9")throw this.errorSpan("Expected digit",n);this.advance(1)}}parseNumberOrString(){const t=this.pos,n=this.position(),r=this.peekChar()==="-";r&&this.advance(1);let i=!1,s=!1;for(;this.pos<this.input.length&&this.input[this.pos]>="0"&&this.input[this.pos]<="9";)i=!0,this.advance(1);if(this.peekChar()==="."){s=!0,this.advance(1);const c=this.pos;for(;this.pos<this.input.length&&this.input[this.pos]>="0"&&this.input[this.pos]<="9";)this.advance(1);if(this.pos===c)return this.pos=t,this.parseIntegerOrBare(t,r)}if(!i&&!s){if(this.pos=t,r)throw this.errorPoint("Expected a value");return{kind:"scalar",value:{kind:"string",value:this.parseBareString()}}}const a=this.peekChar();if(a==="e"||a==="E"){this.advance(1);const c=this.peekChar();(c==="+"||c==="-")&&this.advance(1);const f=this.pos;for(;this.pos<this.input.length&&this.input[this.pos]>="0"&&this.input[this.pos]<="9";)this.advance(1);if(this.pos===f)throw this.errorSpan("Expected exponent digits",n)}const o=this.peekChar();if(o!==void 0&&gc(o)&&!(o>="0"&&o<="9")){if(this.pos=t,r)throw this.errorPoint("Expected a value");return{kind:"scalar",value:{kind:"string",value:this.parseBareString()}}}const l=this.input.substring(t,this.pos),u=parseFloat(l);if(isNaN(u))throw this.errorSpan(`Invalid number: ${l}`,n);return{kind:"scalar",value:{kind:"number",value:u}}}parseIntegerOrBare(t,n){this.pos=t;const r=this.position();n&&this.advance(1);const i=this.pos;for(;this.pos<this.input.length&&this.input[this.pos]>="0"&&this.input[this.pos]<="9";)this.advance(1);if(this.pos===i){if(this.pos=t,n)throw this.errorPoint("Expected a value");return{kind:"scalar",value:{kind:"string",value:this.parseBareString()}}}if(!n){const l=this.peekChar();if(l!==void 0&&gc(l)&&!(l>="0"&&l<="9"))return this.pos=t,{kind:"scalar",value:{kind:"string",value:this.parseBareString()}}}const s=this.peekChar();if(s==="e"||s==="E"){this.advance(1);const l=this.peekChar();(l==="+"||l==="-")&&this.advance(1);const u=this.pos;for(;this.pos<this.input.length&&this.input[this.pos]>="0"&&this.input[this.pos]<="9";)this.advance(1);if(this.pos===u)throw this.errorSpan("Expected exponent digits",r)}const a=this.input.substring(t,this.pos),o=parseFloat(a);if(isNaN(o))throw this.errorSpan(`Invalid number: ${a}`,r);return{kind:"scalar",value:{kind:"number",value:o}}}parseBareString(){const t=this.pos;for(;this.pos<this.input.length&&gc(this.input[this.pos]);)this.pos++;if(this.pos===t)throw this.errorPoint("Expected an identifier");return this.input.substring(t,this.pos)}parseDoubleQuotedString(){const t=this.position();this.expectChar('"');let n="";for(;;){const r=this.peekChar();if(r===void 0||r==="\r"||r===`
|
|
51
51
|
`)throw this.errorSpan("Unterminated string",t);if(r==='"')return this.advance(1),n;r==="\\"?(this.advance(1),n+=this.parseEscapeChar()):(this.advance(1),n+=r)}}parseSingleQuotedString(){const t=this.position();this.expectChar("'");let n="";for(;;){const r=this.peekChar();if(r===void 0||r==="\r"||r===`
|
|
52
52
|
`)throw this.errorSpan("Unterminated string",t);if(r==="'")return this.advance(1),n;if(r==="\\"){this.advance(1),n+="\\";const i=this.peekChar();if(i===void 0||i==="\r"||i===`
|
|
53
53
|
`)throw this.errorSpan("Unterminated string",t);this.advance(1),n+=i}else this.advance(1),n+=r}}parseTripleSingleQuotedString(){const t=this.position();if(!this.startsWith("'''"))throw this.errorPoint("Expected triple-single-quoted string");this.advance(3);let n="";for(;;){if(this.startsWith("'''"))return this.advance(3),n;const r=this.peekChar();if(r===void 0)throw this.errorSpan("Unterminated triple-single-quoted string",t);if(r==="\\"){this.advance(1),n+="\\";const i=this.peekChar();if(i===void 0)throw this.errorSpan("Unterminated triple-single-quoted string",t);this.advance(1),n+=i}else this.advance(1),n+=r}}parseBacktickString(){const t=this.position();this.expectChar("`");let n="";for(;;){const r=this.peekChar();if(r===void 0||r==="\r"||r===`
|
|
54
54
|
`)throw this.errorSpan("Unterminated backtick string",t);if(r==="`")return this.advance(1),n;r==="\\"?(this.advance(1),n+=this.parseEscapeChar()):(this.advance(1),n+=r)}}parseTripleString(){const t=this.position();if(!this.startsWith('"""'))throw this.errorPoint("Expected triple-quoted string");this.advance(3);let n="";for(;;){if(this.startsWith('"""'))return this.advance(3),n;const r=this.peekChar();if(r===void 0)throw this.errorSpan("Unterminated triple-quoted string",t);r==="\\"?(this.advance(1),n+=this.parseEscapeChar()):(this.advance(1),n+=r)}}parseEscapeChar(){const t=this.peekChar();if(t===void 0)throw this.errorPoint("Unterminated escape sequence");switch(t){case"b":return this.advance(1),"\b";case"f":return this.advance(1),"\f";case"n":return this.advance(1),`
|
|
55
|
-
`;case"r":return this.advance(1),"\r";case"t":return this.advance(1)," ";case"u":{const n=this.position();this.advance(1);const r=this.pos;for(let a=0;a<4;a++){const o=this.peekChar();if(o===void 0||!gue(o))throw this.errorSpan("Expected 4 hex digits in \\uXXXX",n);this.advance(1)}const i=this.input.substring(r,this.pos),s=parseInt(i,16);return String.fromCharCode(s)}default:return this.advance(1),t}}parseArray(){const t=this.position();if(this.expectChar("["),this.skipWs(),this.eatChar("]"))return[];const n=[];for(n.push(this.parseArrayElement());;){if(this.skipWs(),this.eatChar("]"))return n;if(this.eatChar(",")){if(this.skipWs(),this.peekChar()==="]")return this.advance(1),n;n.push(this.parseArrayElement())}else throw this.pos>=this.input.length?this.errorSpan("Unclosed '['",t):this.errorPoint("Expected ',' or ']' in array")}}parseArrayElement(){this.skipWs();const t=this.peekChar();if(t==="{")return{value:null,properties:this.parsePropertiesBlock()};if(t==="[")return{value:{kind:"array",elements:this.parseArray()},properties:null};const n=this.parseScalarValue();if(this.skipWs(),this.peekChar()==="{"){const r=this.parsePropertiesBlock();return{value:n,properties:r}}return{value:n,properties:null}}parsePropertiesBlock(){const t=this.position();if(this.expectChar("{"),this.skipWs(),this.startsWith("...")){const r=this.pos;if(this.advance(3),this.skipWs(),this.peekChar()==="}")return this.advance(1),[];this.pos=r}const n=[];for(;;){if(this.skipWs(),this.eatChar("}"))return n;if(this.pos>=this.input.length)throw this.errorSpan("Unclosed '{'",t);n.push(this.parseStatement())}}parseReference(){this.expectChar("$");let t=0;for(;this.peekChar()==="^";)this.advance(1),t++;const n=[],r=this.parseIdentifier();if(n.push({kind:"name",name:r}),this.peekChar()==="["){this.advance(1),this.skipWs();const i=this.parseRefIndex();n.push({kind:"index",index:i}),this.skipWs(),this.expectChar("]")}for(;this.peekChar()===".";){this.advance(1);const i=this.parseIdentifier();if(n.push({kind:"name",name:i}),this.peekChar()==="["){this.advance(1),this.skipWs();const s=this.parseRefIndex();n.push({kind:"index",index:s}),this.skipWs(),this.expectChar("]")}}return{kind:"reference",ups:t,path:n}}parseRefIndex(){const t=this.position(),n=this.pos;for(;this.pos<this.input.length&&this.input[this.pos]>="0"&&this.input[this.pos]<="9";)this.pos++;if(this.pos===n)throw this.errorPoint("Expected array index");const r=parseInt(this.input.substring(n,this.pos),10);if(isNaN(r))throw this.errorSpan("Invalid array index",t);return r}}function gc(e){const t=e.charCodeAt(0);return t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122||t===95||t>=192&&t<=591||t>=7680&&t<=7935}function gue(e){const t=e.charCodeAt(0);return t>=48&&t<=57||t>=65&&t<=70||t>=97&&t<=102}function yue(e){return new pue(e).parseStatements()}var P6={};Object.defineProperty(P6,"__esModule",{value:!0}),P6.execute=bue;function bue(e,t){for(const n of e)wd(n,t);return t}function wd(e,t){switch(e.kind){case"setEq":vue(t,e.path,e.value,e.properties,e.preserveProperties);break;case"replaceProperties":xue(t,e.path,e.properties,e.preserveValue);break;case"updateProperties":wue(t,e.path,e.properties);break;case"define":$ue(t,e.path,e.deleted);break;case"clearAll":t.properties={};break}}function vue(e,t,n,r,i){if(n.kind==="scalar"&&n.value.kind==="reference"&&r===null&&!i){const[o,l]=B1(e,t),u=Po(l);u[o]={linkTo:gO(n.value.ups,n.value.path)};return}const[s,a]=B1(e,t);if(r!==null){const o=S2(n);for(const u of r)wd(u,o);const l=Po(a);l[s]=o}else if(i){const o=Po(a),l=o[s];if(l!==void 0&&!k2(l)){const u=S2(n);l.properties&&(u.properties=l.properties),o[s]=u}else o[s]=S2(n)}else{const o=Po(a);o[s]=S2(n)}}function xue(e,t,n,r){const[i,s]=B1(e,t),a={};if(r){const u=Po(s)[i];u!==void 0&&!k2(u)&&(a.eq=u.eq)}for(const l of n)wd(l,a);const o=Po(s);o[i]=a}function wue(e,t,n){const[r,i]=B1(e,t),s=Po(i);let a=s[r];if(a===void 0&&(a={},s[r]=a),k2(a)){const o={};for(const l of n)wd(l,o);s[r]=o}else for(const o of n)wd(o,a)}function $ue(e,t,n){const[r,i]=B1(e,t),s=Po(i);n?s[r]={deleted:!0}:s[r]={}}function B1(e,t){let n=e;for(let r=0;r<t.length-1;r++){const i=t[r],s=Po(n);let a=s[i];a===void 0&&(a={},s[i]=a),k2(a)&&(a={},s[i]=a),n=a}return[t[t.length-1],n]}function S2(e){if(e.kind==="array")return{eq:pO(e.elements)};const t=e.value;switch(t.kind){case"string":return{eq:t.value};case"number":return{eq:t.value};case"boolean":return{eq:t.value};case"date":return{eq:new Date(t.value)};case"reference":return{}}}function pO(e){return e.map(Sue)}function Sue(e){if(e.value!==null&&e.value.kind==="scalar"&&e.value.value.kind==="reference"&&e.properties===null)return{linkTo:gO(e.value.value.ups,e.value.value.path)};const t={};if(e.value!==null)if(e.value.kind==="array")t.eq=pO(e.value.elements);else{const n=e.value.value;switch(n.kind){case"string":t.eq=n.value;break;case"number":t.eq=n.value;break;case"boolean":t.eq=n.value;break;case"date":t.eq=new Date(n.value);break}}if(e.properties!==null)for(const n of e.properties)wd(n,t);return t}function gO(e,t){let n="$";for(let i=0;i<e;i++)n+="^";let r=!0;for(const i of t)i.kind==="name"?(r||(n+="."),n+=i.name,r=!1):n+=`[${i.index}]`;return n}function k2(e){return"linkTo"in e}function Po(e){return e.properties||(e.properties={}),e.properties}var E2={};Object.defineProperty(E2,"__esModule",{value:!0}),E2.validateReferences=kue,E2.validateSchema=Aue;function ln(e){return"linkTo"in e}function q1(e){return typeof e.eq=="string"?e.eq:void 0}function yO(e){if(!ln(e))return q1(e)}function L6(e,t){if(!e.properties)return;const n=e.properties[t];if(!(n===void 0||ln(n)))return n.properties}function kue(e){const t=[];return B6(e,[],[e],e,t),t}function B6(e,t,n,r,i){if(e.eq!==void 0&&Array.isArray(e.eq)&&Eue(e.eq,t,n,e,r,i),e.properties)for(const s of Object.keys(e.properties)){const a=e.properties[s];if(t.push(s),ln(a)){const o=bO(a,n,r);o!==null&&i.push({message:o,path:[...t],code:"unresolved-reference"})}else n.push(e),B6(a,t,n,r,i),n.pop();t.pop()}}function Eue(e,t,n,r,i,s){for(let a=0;a<e.length;a++){const o=e[a],l=`[${a}]`;if(t.push(l),ln(o)){const u=bO(o,n,i);u!==null&&s.push({message:u,path:[...t],code:"unresolved-reference"})}else n.push(r),B6(o,t,n,i,s),n.pop();t.pop()}}function bO(e,t,n){const{ups:r,segments:i}=_ue(e.linkTo);let s;if(r===0)s=n;else{const a=t.length-r;if(a<0||a>=t.length)return`Reference "${e.linkTo}" goes ${r} level(s) up but only ${t.length} ancestor(s) available`;s=t[a]}return Cue(s,i,e.linkTo)}function _ue(e){let t=0;t<e.length&&e[t]==="$"&&t++;let n=0;for(;t<e.length&&e[t]==="^";)n++,t++;const r=[];let i="";for(;t<e.length;){const s=e[t];if(s===".")i.length>0&&(r.push({kind:"name",name:i}),i=""),t++;else if(s==="["){i.length>0&&(r.push({kind:"name",name:i}),i=""),t++;let a="";for(;t<e.length&&e[t]!=="]";)a+=e[t],t++;t<e.length&&t++;const o=parseInt(a,10);!isNaN(o)&&o>=0&&r.push({kind:"index",index:o})}else i+=s,t++}return i.length>0&&r.push({kind:"name",name:i}),{ups:n,segments:r}}function Cue(e,t,n){let r={kind:"node",node:e};for(const i of t){if(r.kind==="terminal")return`Reference "${n}" could not be resolved: cannot follow path through a link`;const s=r.node;if(i.kind==="name"){if(!s.properties)return`Reference "${n}" could not be resolved: property "${i.name}" not found (node has no properties)`;const a=s.properties[i.name];if(a===void 0)return`Reference "${n}" could not be resolved: property "${i.name}" not found`;ln(a)?r={kind:"terminal"}:r={kind:"node",node:a}}else{if(s.eq===void 0||!Array.isArray(s.eq))return`Reference "${n}" could not be resolved: index [${i.index}] used on non-array`;if(i.index>=s.eq.length)return`Reference "${n}" could not be resolved: index [${i.index}] out of bounds (array length ${s.eq.length})`;const a=s.eq[i.index];ln(a)?r={kind:"terminal"}:r={kind:"node",node:a}}}return null}function Aue(e,t){const n=[],r=L6(t,"Types");return vO(e,t,r,[],n),n}function Mue(e){if(!e.properties)return{kind:"reject"};const t=e.properties.Additional;if(t===void 0)return{kind:"reject"};if(ln(t))return{kind:"reject"};const n=q1(t);return n!==void 0?n==="allow"?{kind:"allow"}:n==="reject"?{kind:"reject"}:{kind:"validateAs",typeName:n}:{kind:"allow"}}function vO(e,t,n,r,i){const s=L6(t,"Required"),a=L6(t,"Optional"),o=Mue(t),l=e.properties;if(s)for(const u of Object.keys(s)){const c=[...r,u],f=l?l[u]:void 0;f===void 0?i.push({message:`Missing required property "${u}"`,path:c,code:"missing-required"}):U1(f,s[u],n,c,i)}if(a&&l)for(const u of Object.keys(a)){const c=l[u];c!==void 0&&U1(c,a[u],n,[...r,u],i)}if(l){const u=new Set;if(s)for(const c of Object.keys(s))u.add(c);if(a)for(const c of Object.keys(a))u.add(c);for(const c of Object.keys(l)){if(u.has(c))continue;const f=[...r,c];switch(o.kind){case"reject":i.push({message:`Unknown property "${c}"`,path:f,code:"unknown-property"});break;case"allow":break;case"validateAs":{const d=xO(o.typeName);U1(l[c],d,n,f,i);break}}}}}function xO(e){return{eq:e}}function U1(e,t,n,r,i){if(ln(t))return;if(t.properties){const a=t.properties.oneOf;if(a!==void 0&&!ln(a)){Lue(e,a,n,r,i);return}}if(t.properties){const a=t.properties.eq;if(a!==void 0&&!ln(a)&&Array.isArray(a.eq)){zue(e,a.eq,r,i);return}const o=t.properties.matches;if(o!==void 0&&!ln(o)){const l=q1(t);l!==void 0&&q6(e,l,n,r,i),Pue(e,o,r,i);return}}const s=q1(t);if(s===void 0){t.properties&&("Required"in t.properties||"Optional"in t.properties||"Additional"in t.properties)&&(ln(e)?i.push({message:"Expected a tag but found a link",path:[...r],code:"wrong-type"}):vO(e,t,n,r,i));return}q6(e,s,n,r,i)}function q6(e,t,n,r,i){if(t.endsWith("[]")){const s=t.slice(0,-2);Iue(e,s,n,r,i);return}switch(t){case"string":Fue(e,r,i);break;case"number":Tue(e,r,i);break;case"boolean":Due(e,r,i);break;case"date":Oue(e,r,i);break;case"tag":Rue(e,r,i);break;case"flag":Nue(e,r,i);break;case"any":break;default:if(n){const s=n[t];s!==void 0?U1(e,s,n,r,i):i.push({message:`Unknown type "${t}" in schema`,path:[...r],code:"invalid-schema"})}else i.push({message:`Unknown type "${t}" (no Types section in schema)`,path:[...r],code:"invalid-schema"})}}function Fue(e,t,n){if(ln(e)){n.push({message:'Expected type "string" but found a link',path:[...t],code:"wrong-type"});return}typeof e.eq!="string"&&n.push({message:'Expected type "string"',path:[...t],code:"wrong-type"})}function Tue(e,t,n){if(ln(e)){n.push({message:'Expected type "number" but found a link',path:[...t],code:"wrong-type"});return}typeof e.eq!="number"&&n.push({message:'Expected type "number"',path:[...t],code:"wrong-type"})}function Due(e,t,n){if(ln(e)){n.push({message:'Expected type "boolean" but found a link',path:[...t],code:"wrong-type"});return}typeof e.eq!="boolean"&&n.push({message:'Expected type "boolean"',path:[...t],code:"wrong-type"})}function Oue(e,t,n){if(ln(e)){n.push({message:'Expected type "date" but found a link',path:[...t],code:"wrong-type"});return}e.eq instanceof Date||n.push({message:'Expected type "date"',path:[...t],code:"wrong-type"})}function Rue(e,t,n){ln(e)&&n.push({message:'Expected type "tag" but found a link',path:[...t],code:"wrong-type"})}function Nue(e,t,n){ln(e)&&n.push({message:'Expected type "flag" but found a link',path:[...t],code:"wrong-type"})}function Iue(e,t,n,r,i){if(ln(e)){i.push({message:`Expected type "${t}[]" but found a link`,path:[...r],code:"wrong-type"});return}if(!Array.isArray(e.eq)){i.push({message:`Expected type "${t}[]" but value is not an array`,path:[...r],code:"wrong-type"});return}for(let s=0;s<e.eq.length;s++){const a=[...r,`[${s}]`];q6(e.eq[s],t,n,a,i)}}function zue(e,t,n,r){if(ln(e)){r.push({message:"Expected an enum value but found a link",path:[...n],code:"wrong-type"});return}const i=e.eq;if(i===void 0||typeof i!="string"&&typeof i!="number"&&typeof i!="boolean"&&!(i instanceof Date)){r.push({message:"Expected an enum value",path:[...n],code:"invalid-enum-value"});return}if(!t.some(a=>{if(ln(a))return!1;const o=a.eq;return o instanceof Date&&i instanceof Date?o.getTime()===i.getTime():o===i})){const a=t.filter(o=>!ln(o)).map(o=>{const l=o.eq;return JSON.stringify(String(l))});r.push({message:`Value does not match any allowed enum value. Allowed: [${a.join(", ")}]`,path:[...n],code:"invalid-enum-value"})}}function Pue(e,t,n,r){const i=q1(t);if(i!==void 0){if(ln(e)){r.push({message:"Expected a value matching a pattern but found a link",path:[...n],code:"wrong-type"});return}if(typeof e.eq!="string"){r.push({message:`Expected a string matching pattern "${i}"`,path:[...n],code:"pattern-mismatch"});return}try{new RegExp(i).test(e.eq)||r.push({message:`Value "${e.eq}" does not match pattern "${i}"`,path:[...n],code:"pattern-mismatch"})}catch(s){r.push({message:`Invalid regex pattern "${i}": ${s}`,path:[...n],code:"invalid-schema"})}}}function Lue(e,t,n,r,i){if(!Array.isArray(t.eq))return;for(const a of t.eq){const o=yO(a);if(o===void 0)continue;const l=[],u=xO(o);if(U1(e,u,n,r,l),l.length===0)return}const s=t.eq.map(a=>yO(a)).filter(a=>a!==void 0);i.push({message:`Value does not match any type in oneOf: [${s.join(", ")}]`,path:[...r],code:"wrong-type"})}Object.defineProperty($2,"__esModule",{value:!0}),$2.MOTLYSession=void 0;const wO=z6,$O=P6,SO=E2;class Bue{constructor(){this.value={},this.schema=null,this.disposed=!1}parse(t){this.ensureAlive();try{const n=(0,wO.parse)(t);return this.value=(0,$O.execute)(n,this.value),[]}catch(n){if(kO(n))return[n];throw n}}parseSchema(t){this.ensureAlive();try{const n=(0,wO.parse)(t);return this.schema=(0,$O.execute)(n,{}),[]}catch(n){if(kO(n))return[n];throw n}}reset(){this.ensureAlive(),this.value={}}getValue(){return this.ensureAlive(),EO(this.value)}validateSchema(){return this.ensureAlive(),this.schema===null?[]:(0,SO.validateSchema)(this.value,this.schema)}validateReferences(){return this.ensureAlive(),(0,SO.validateReferences)(this.value)}dispose(){this.disposed=!0}ensureAlive(){if(this.disposed)throw new Error("MOTLYSession has been disposed")}}$2.MOTLYSession=Bue;function kO(e){return typeof e=="object"&&e!==null&&"code"in e&&"message"in e&&"begin"in e&&"end"in e}function EO(e){const t={};if(e.deleted&&(t.deleted=!0),e.eq!==void 0&&(e.eq instanceof Date?t.eq=new Date(e.eq.getTime()):Array.isArray(e.eq)?t.eq=e.eq.map(_O):t.eq=e.eq),e.properties){const n={};for(const r of Object.keys(e.properties))n[r]=_O(e.properties[r]);t.properties=n}return t}function _O(e){return"linkTo"in e?{linkTo:e.linkTo}:EO(e)}(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.MOTLYSession=void 0;var t=$2;Object.defineProperty(e,"MOTLYSession",{enumerable:!0,get:function(){return t.MOTLYSession}})})(mO),Object.defineProperty(L1,"__esModule",{value:!0}),L1.TagParser=void 0,L1.parseTag=Hue;const que=mO,CO=zo;function Uue(e){if(e[0]==="#"){const t=e.indexOf(" ");return t>0?e.slice(t):""}return e}function jue(e){return{code:e.code,message:e.message,line:e.begin.line,offset:e.begin.column}}function Wue(e){let t=1,n=0;for(;t<e.length&&e[t]==="^";)n++,t++;const r=[],i=e.slice(t);if(i.length===0)return{ups:n,refPath:r};let s=0;for(;s<i.length;){if(i[s]==="."){s++;continue}if(i[s]==="["){const o=i.indexOf("]",s);r.push(Number(i.slice(s+1,o))),s=o+1;continue}if(i[s]==="`"){s++;let o="";for(;s<i.length&&i[s]!=="`";)i[s]==="\\"&&s++,o+=i[s],s++;s++,r.push(o);continue}let a="";for(;s<i.length&&i[s]!=="."&&i[s]!=="["&&i[s]!=="`";)a+=i[s],s++;a.length>0&&r.push(a)}return{ups:n,refPath:r}}function Vue(e){return"linkTo"in e}function _2(e,t){if(Vue(e)){const{ups:r,refPath:i}=Wue(e.linkTo);return new CO.RefTag(r,i,t)}const n=new CO.Tag({},t);if(e.eq!==void 0&&(Array.isArray(e.eq)?n.eq=e.eq.map(r=>_2(r,n)):e.eq instanceof Date?n.eq=new Date(e.eq):n.eq=e.eq),e.properties!==void 0){n.properties={};for(const[r,i]of Object.entries(e.properties))n.properties[r]=_2(i,n)}return e.deleted&&(n.deleted=!0),n}class AO{constructor(){this.session=new que.MOTLYSession}parse(t){const n=Uue(t),i=this.session.parse(n).map(jue),s=this.session.getValue();return{tag:_2(s),log:i}}finish(){const t=this.session.getValue();return this.session.dispose(),_2(t)}}L1.TagParser=AO;function Hue(e){const t=new AO;if(typeof e=="string")return t.parse(e);const n=[];for(let r=0;r<e.length;r++){const i=t.parse(e[r]);for(const s of i.log)n.push({...s,line:r+s.line})}return{tag:t.finish(),log:n}}var U6={};Object.defineProperty(U6,"__esModule",{value:!0}),U6.parseString=Gue;var qs;(function(e){e[e.Normal=0]="Normal",e[e.ReverseVirgule=1]="ReverseVirgule",e[e.Unicode=2]="Unicode"})(qs||(qs={}));function Gue(e,t=""){let n=e.slice(t.length),r=qs.Normal;t.length&&(n=n.slice(0,-t.length));let i="",s="";for(const a of n)switch(r){case qs.Normal:{a==="\\"?r=qs.ReverseVirgule:i+=a;break}case qs.ReverseVirgule:{let o=a;if(a==="u"){r=qs.Unicode,s="";continue}a==="b"?o="\b":a==="f"?o="\f":a==="n"?o=`
|
|
55
|
+
`;case"r":return this.advance(1),"\r";case"t":return this.advance(1)," ";case"u":{const n=this.position();this.advance(1);const r=this.pos;for(let a=0;a<4;a++){const o=this.peekChar();if(o===void 0||!gue(o))throw this.errorSpan("Expected 4 hex digits in \\uXXXX",n);this.advance(1)}const i=this.input.substring(r,this.pos),s=parseInt(i,16);return String.fromCharCode(s)}default:return this.advance(1),t}}parseArray(){const t=this.position();if(this.expectChar("["),this.skipWs(),this.eatChar("]"))return[];const n=[];for(n.push(this.parseArrayElement());;){if(this.skipWs(),this.eatChar("]"))return n;if(this.eatChar(",")){if(this.skipWs(),this.peekChar()==="]")return this.advance(1),n;n.push(this.parseArrayElement())}else throw this.pos>=this.input.length?this.errorSpan("Unclosed '['",t):this.errorPoint("Expected ',' or ']' in array")}}parseArrayElement(){this.skipWs();const t=this.peekChar();if(t==="{")return{value:null,properties:this.parsePropertiesBlock()};if(t==="[")return{value:{kind:"array",elements:this.parseArray()},properties:null};const n=this.parseScalarValue();if(this.skipWs(),this.peekChar()==="{"){const r=this.parsePropertiesBlock();return{value:n,properties:r}}return{value:n,properties:null}}parsePropertiesBlock(){const t=this.position();if(this.expectChar("{"),this.skipWs(),this.startsWith("...")){const r=this.pos;if(this.advance(3),this.skipWs(),this.peekChar()==="}")return this.advance(1),[];this.pos=r}const n=[];for(;;){if(this.skipWsAndCommas(),this.eatChar("}"))return n;if(this.pos>=this.input.length)throw this.errorSpan("Unclosed '{'",t);n.push(this.parseStatement())}}parseReference(){this.expectChar("$");let t=0;for(;this.peekChar()==="^";)this.advance(1),t++;const n=[],r=this.parseIdentifier();if(n.push({kind:"name",name:r}),this.peekChar()==="["){this.advance(1),this.skipWs();const i=this.parseRefIndex();n.push({kind:"index",index:i}),this.skipWs(),this.expectChar("]")}for(;this.peekChar()===".";){this.advance(1);const i=this.parseIdentifier();if(n.push({kind:"name",name:i}),this.peekChar()==="["){this.advance(1),this.skipWs();const s=this.parseRefIndex();n.push({kind:"index",index:s}),this.skipWs(),this.expectChar("]")}}return{kind:"reference",ups:t,path:n}}parseRefIndex(){const t=this.position(),n=this.pos;for(;this.pos<this.input.length&&this.input[this.pos]>="0"&&this.input[this.pos]<="9";)this.pos++;if(this.pos===n)throw this.errorPoint("Expected array index");const r=parseInt(this.input.substring(n,this.pos),10);if(isNaN(r))throw this.errorSpan("Invalid array index",t);return r}}function gc(e){const t=e.charCodeAt(0);return t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122||t===95||t>=192&&t<=591||t>=7680&&t<=7935}function gue(e){const t=e.charCodeAt(0);return t>=48&&t<=57||t>=65&&t<=70||t>=97&&t<=102}function yue(e){return new pue(e).parseStatements()}var P6={};Object.defineProperty(P6,"__esModule",{value:!0}),P6.execute=bue;function bue(e,t){for(const n of e)wd(n,t);return t}function wd(e,t){switch(e.kind){case"setEq":vue(t,e.path,e.value,e.properties,e.preserveProperties);break;case"replaceProperties":xue(t,e.path,e.properties,e.preserveValue);break;case"updateProperties":wue(t,e.path,e.properties);break;case"define":$ue(t,e.path,e.deleted);break;case"clearAll":t.properties={};break}}function vue(e,t,n,r,i){if(n.kind==="scalar"&&n.value.kind==="reference"&&r===null&&!i){const[o,l]=B1(e,t),u=Po(l);u[o]={linkTo:gO(n.value.ups,n.value.path)};return}const[s,a]=B1(e,t);if(r!==null){const o=S2(n);for(const u of r)wd(u,o);const l=Po(a);l[s]=o}else if(i){const o=Po(a),l=o[s];if(l!==void 0&&!k2(l)){const u=S2(n);l.properties&&(u.properties=l.properties),o[s]=u}else o[s]=S2(n)}else{const o=Po(a);o[s]=S2(n)}}function xue(e,t,n,r){const[i,s]=B1(e,t),a={};if(r){const u=Po(s)[i];u!==void 0&&!k2(u)&&(a.eq=u.eq)}for(const l of n)wd(l,a);const o=Po(s);o[i]=a}function wue(e,t,n){const[r,i]=B1(e,t),s=Po(i);let a=s[r];if(a===void 0&&(a={},s[r]=a),k2(a)){const o={};for(const l of n)wd(l,o);s[r]=o}else for(const o of n)wd(o,a)}function $ue(e,t,n){const[r,i]=B1(e,t),s=Po(i);n?s[r]={deleted:!0}:s[r]={}}function B1(e,t){let n=e;for(let r=0;r<t.length-1;r++){const i=t[r],s=Po(n);let a=s[i];a===void 0&&(a={},s[i]=a),k2(a)&&(a={},s[i]=a),n=a}return[t[t.length-1],n]}function S2(e){if(e.kind==="array")return{eq:pO(e.elements)};const t=e.value;switch(t.kind){case"string":return{eq:t.value};case"number":return{eq:t.value};case"boolean":return{eq:t.value};case"date":return{eq:new Date(t.value)};case"reference":return{}}}function pO(e){return e.map(Sue)}function Sue(e){if(e.value!==null&&e.value.kind==="scalar"&&e.value.value.kind==="reference"&&e.properties===null)return{linkTo:gO(e.value.value.ups,e.value.value.path)};const t={};if(e.value!==null)if(e.value.kind==="array")t.eq=pO(e.value.elements);else{const n=e.value.value;switch(n.kind){case"string":t.eq=n.value;break;case"number":t.eq=n.value;break;case"boolean":t.eq=n.value;break;case"date":t.eq=new Date(n.value);break}}if(e.properties!==null)for(const n of e.properties)wd(n,t);return t}function gO(e,t){let n="$";for(let i=0;i<e;i++)n+="^";let r=!0;for(const i of t)i.kind==="name"?(r||(n+="."),n+=i.name,r=!1):n+=`[${i.index}]`;return n}function k2(e){return"linkTo"in e}function Po(e){return e.properties||(e.properties={}),e.properties}var E2={};Object.defineProperty(E2,"__esModule",{value:!0}),E2.validateReferences=kue,E2.validateSchema=Aue;function ln(e){return"linkTo"in e}function q1(e){return typeof e.eq=="string"?e.eq:void 0}function yO(e){if(!ln(e))return q1(e)}function L6(e,t){if(!e.properties)return;const n=e.properties[t];if(!(n===void 0||ln(n)))return n.properties}function kue(e){const t=[];return B6(e,[],[e],e,t),t}function B6(e,t,n,r,i){if(e.eq!==void 0&&Array.isArray(e.eq)&&Eue(e.eq,t,n,e,r,i),e.properties)for(const s of Object.keys(e.properties)){const a=e.properties[s];if(t.push(s),ln(a)){const o=bO(a,n,r);o!==null&&i.push({message:o,path:[...t],code:"unresolved-reference"})}else n.push(e),B6(a,t,n,r,i),n.pop();t.pop()}}function Eue(e,t,n,r,i,s){for(let a=0;a<e.length;a++){const o=e[a],l=`[${a}]`;if(t.push(l),ln(o)){const u=bO(o,n,i);u!==null&&s.push({message:u,path:[...t],code:"unresolved-reference"})}else n.push(r),B6(o,t,n,i,s),n.pop();t.pop()}}function bO(e,t,n){const{ups:r,segments:i}=_ue(e.linkTo);let s;if(r===0)s=n;else{const a=t.length-r;if(a<0||a>=t.length)return`Reference "${e.linkTo}" goes ${r} level(s) up but only ${t.length} ancestor(s) available`;s=t[a]}return Cue(s,i,e.linkTo)}function _ue(e){let t=0;t<e.length&&e[t]==="$"&&t++;let n=0;for(;t<e.length&&e[t]==="^";)n++,t++;const r=[];let i="";for(;t<e.length;){const s=e[t];if(s===".")i.length>0&&(r.push({kind:"name",name:i}),i=""),t++;else if(s==="["){i.length>0&&(r.push({kind:"name",name:i}),i=""),t++;let a="";for(;t<e.length&&e[t]!=="]";)a+=e[t],t++;t<e.length&&t++;const o=parseInt(a,10);!isNaN(o)&&o>=0&&r.push({kind:"index",index:o})}else i+=s,t++}return i.length>0&&r.push({kind:"name",name:i}),{ups:n,segments:r}}function Cue(e,t,n){let r={kind:"node",node:e};for(const i of t){if(r.kind==="terminal")return`Reference "${n}" could not be resolved: cannot follow path through a link`;const s=r.node;if(i.kind==="name"){if(!s.properties)return`Reference "${n}" could not be resolved: property "${i.name}" not found (node has no properties)`;const a=s.properties[i.name];if(a===void 0)return`Reference "${n}" could not be resolved: property "${i.name}" not found`;ln(a)?r={kind:"terminal"}:r={kind:"node",node:a}}else{if(s.eq===void 0||!Array.isArray(s.eq))return`Reference "${n}" could not be resolved: index [${i.index}] used on non-array`;if(i.index>=s.eq.length)return`Reference "${n}" could not be resolved: index [${i.index}] out of bounds (array length ${s.eq.length})`;const a=s.eq[i.index];ln(a)?r={kind:"terminal"}:r={kind:"node",node:a}}}return null}function Aue(e,t){const n=[],r=L6(t,"Types");return vO(e,t,r,[],n),n}function Mue(e){if(!e.properties)return{kind:"reject"};const t=e.properties.Additional;if(t===void 0)return{kind:"reject"};if(ln(t))return{kind:"reject"};const n=q1(t);return n!==void 0?n==="allow"?{kind:"allow"}:n==="reject"?{kind:"reject"}:{kind:"validateAs",typeName:n}:{kind:"allow"}}function vO(e,t,n,r,i){const s=L6(t,"Required"),a=L6(t,"Optional"),o=Mue(t),l=e.properties;if(s)for(const u of Object.keys(s)){const c=[...r,u],f=l?l[u]:void 0;f===void 0?i.push({message:`Missing required property "${u}"`,path:c,code:"missing-required"}):U1(f,s[u],n,c,i)}if(a&&l)for(const u of Object.keys(a)){const c=l[u];c!==void 0&&U1(c,a[u],n,[...r,u],i)}if(l){const u=new Set;if(s)for(const c of Object.keys(s))u.add(c);if(a)for(const c of Object.keys(a))u.add(c);for(const c of Object.keys(l)){if(u.has(c))continue;const f=[...r,c];switch(o.kind){case"reject":i.push({message:`Unknown property "${c}"`,path:f,code:"unknown-property"});break;case"allow":break;case"validateAs":{const d=xO(o.typeName);U1(l[c],d,n,f,i);break}}}}}function xO(e){return{eq:e}}function U1(e,t,n,r,i){if(ln(t))return;if(t.properties){const a=t.properties.oneOf;if(a!==void 0&&!ln(a)){Lue(e,a,n,r,i);return}}if(t.properties){const a=t.properties.eq;if(a!==void 0&&!ln(a)&&Array.isArray(a.eq)){zue(e,a.eq,r,i);return}const o=t.properties.matches;if(o!==void 0&&!ln(o)){const l=q1(t);l!==void 0&&q6(e,l,n,r,i),Pue(e,o,r,i);return}}const s=q1(t);if(s===void 0){t.properties&&("Required"in t.properties||"Optional"in t.properties||"Additional"in t.properties)&&(ln(e)?i.push({message:"Expected a tag but found a link",path:[...r],code:"wrong-type"}):vO(e,t,n,r,i));return}q6(e,s,n,r,i)}function q6(e,t,n,r,i){if(t.endsWith("[]")){const s=t.slice(0,-2);Iue(e,s,n,r,i);return}switch(t){case"string":Fue(e,r,i);break;case"number":Tue(e,r,i);break;case"boolean":Due(e,r,i);break;case"date":Oue(e,r,i);break;case"tag":Rue(e,r,i);break;case"flag":Nue(e,r,i);break;case"any":break;default:if(n){const s=n[t];s!==void 0?U1(e,s,n,r,i):i.push({message:`Unknown type "${t}" in schema`,path:[...r],code:"invalid-schema"})}else i.push({message:`Unknown type "${t}" (no Types section in schema)`,path:[...r],code:"invalid-schema"})}}function Fue(e,t,n){if(ln(e)){n.push({message:'Expected type "string" but found a link',path:[...t],code:"wrong-type"});return}typeof e.eq!="string"&&n.push({message:'Expected type "string"',path:[...t],code:"wrong-type"})}function Tue(e,t,n){if(ln(e)){n.push({message:'Expected type "number" but found a link',path:[...t],code:"wrong-type"});return}typeof e.eq!="number"&&n.push({message:'Expected type "number"',path:[...t],code:"wrong-type"})}function Due(e,t,n){if(ln(e)){n.push({message:'Expected type "boolean" but found a link',path:[...t],code:"wrong-type"});return}typeof e.eq!="boolean"&&n.push({message:'Expected type "boolean"',path:[...t],code:"wrong-type"})}function Oue(e,t,n){if(ln(e)){n.push({message:'Expected type "date" but found a link',path:[...t],code:"wrong-type"});return}e.eq instanceof Date||n.push({message:'Expected type "date"',path:[...t],code:"wrong-type"})}function Rue(e,t,n){ln(e)&&n.push({message:'Expected type "tag" but found a link',path:[...t],code:"wrong-type"})}function Nue(e,t,n){ln(e)&&n.push({message:'Expected type "flag" but found a link',path:[...t],code:"wrong-type"})}function Iue(e,t,n,r,i){if(ln(e)){i.push({message:`Expected type "${t}[]" but found a link`,path:[...r],code:"wrong-type"});return}if(!Array.isArray(e.eq)){i.push({message:`Expected type "${t}[]" but value is not an array`,path:[...r],code:"wrong-type"});return}for(let s=0;s<e.eq.length;s++){const a=[...r,`[${s}]`];q6(e.eq[s],t,n,a,i)}}function zue(e,t,n,r){if(ln(e)){r.push({message:"Expected an enum value but found a link",path:[...n],code:"wrong-type"});return}const i=e.eq;if(i===void 0||typeof i!="string"&&typeof i!="number"&&typeof i!="boolean"&&!(i instanceof Date)){r.push({message:"Expected an enum value",path:[...n],code:"invalid-enum-value"});return}if(!t.some(a=>{if(ln(a))return!1;const o=a.eq;return o instanceof Date&&i instanceof Date?o.getTime()===i.getTime():o===i})){const a=t.filter(o=>!ln(o)).map(o=>{const l=o.eq;return JSON.stringify(String(l))});r.push({message:`Value does not match any allowed enum value. Allowed: [${a.join(", ")}]`,path:[...n],code:"invalid-enum-value"})}}function Pue(e,t,n,r){const i=q1(t);if(i!==void 0){if(ln(e)){r.push({message:"Expected a value matching a pattern but found a link",path:[...n],code:"wrong-type"});return}if(typeof e.eq!="string"){r.push({message:`Expected a string matching pattern "${i}"`,path:[...n],code:"pattern-mismatch"});return}try{new RegExp(i).test(e.eq)||r.push({message:`Value "${e.eq}" does not match pattern "${i}"`,path:[...n],code:"pattern-mismatch"})}catch(s){r.push({message:`Invalid regex pattern "${i}": ${s}`,path:[...n],code:"invalid-schema"})}}}function Lue(e,t,n,r,i){if(!Array.isArray(t.eq))return;for(const a of t.eq){const o=yO(a);if(o===void 0)continue;const l=[],u=xO(o);if(U1(e,u,n,r,l),l.length===0)return}const s=t.eq.map(a=>yO(a)).filter(a=>a!==void 0);i.push({message:`Value does not match any type in oneOf: [${s.join(", ")}]`,path:[...r],code:"wrong-type"})}Object.defineProperty($2,"__esModule",{value:!0}),$2.MOTLYSession=void 0;const wO=z6,$O=P6,SO=E2;class Bue{constructor(){this.value={},this.schema=null,this.disposed=!1}parse(t){this.ensureAlive();try{const n=(0,wO.parse)(t);return this.value=(0,$O.execute)(n,this.value),[]}catch(n){if(kO(n))return[n];throw n}}parseSchema(t){this.ensureAlive();try{const n=(0,wO.parse)(t);return this.schema=(0,$O.execute)(n,{}),[]}catch(n){if(kO(n))return[n];throw n}}reset(){this.ensureAlive(),this.value={}}getValue(){return this.ensureAlive(),EO(this.value)}validateSchema(){return this.ensureAlive(),this.schema===null?[]:(0,SO.validateSchema)(this.value,this.schema)}validateReferences(){return this.ensureAlive(),(0,SO.validateReferences)(this.value)}dispose(){this.disposed=!0}ensureAlive(){if(this.disposed)throw new Error("MOTLYSession has been disposed")}}$2.MOTLYSession=Bue;function kO(e){return typeof e=="object"&&e!==null&&"code"in e&&"message"in e&&"begin"in e&&"end"in e}function EO(e){const t={};if(e.deleted&&(t.deleted=!0),e.eq!==void 0&&(e.eq instanceof Date?t.eq=new Date(e.eq.getTime()):Array.isArray(e.eq)?t.eq=e.eq.map(_O):t.eq=e.eq),e.properties){const n={};for(const r of Object.keys(e.properties))n[r]=_O(e.properties[r]);t.properties=n}return t}function _O(e){return"linkTo"in e?{linkTo:e.linkTo}:EO(e)}(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.MOTLYSession=void 0;var t=$2;Object.defineProperty(e,"MOTLYSession",{enumerable:!0,get:function(){return t.MOTLYSession}})})(mO),Object.defineProperty(L1,"__esModule",{value:!0}),L1.TagParser=void 0,L1.parseTag=Hue;const que=mO,CO=zo;function Uue(e){if(e[0]==="#"){const t=e.indexOf(" ");return t>0?e.slice(t):""}return e}function jue(e){return{code:e.code,message:e.message,line:e.begin.line,offset:e.begin.column}}function Wue(e){let t=1,n=0;for(;t<e.length&&e[t]==="^";)n++,t++;const r=[],i=e.slice(t);if(i.length===0)return{ups:n,refPath:r};let s=0;for(;s<i.length;){if(i[s]==="."){s++;continue}if(i[s]==="["){const o=i.indexOf("]",s);r.push(Number(i.slice(s+1,o))),s=o+1;continue}if(i[s]==="`"){s++;let o="";for(;s<i.length&&i[s]!=="`";)i[s]==="\\"&&s++,o+=i[s],s++;s++,r.push(o);continue}let a="";for(;s<i.length&&i[s]!=="."&&i[s]!=="["&&i[s]!=="`";)a+=i[s],s++;a.length>0&&r.push(a)}return{ups:n,refPath:r}}function Vue(e){return"linkTo"in e}function _2(e,t){if(Vue(e)){const{ups:r,refPath:i}=Wue(e.linkTo);return new CO.RefTag(r,i,t)}const n=new CO.Tag({},t);if(e.eq!==void 0&&(Array.isArray(e.eq)?n.eq=e.eq.map(r=>_2(r,n)):e.eq instanceof Date?n.eq=new Date(e.eq):n.eq=e.eq),e.properties!==void 0){n.properties={};for(const[r,i]of Object.entries(e.properties))n.properties[r]=_2(i,n)}return e.deleted&&(n.deleted=!0),n}class AO{constructor(){this.session=new que.MOTLYSession}parse(t){const n=Uue(t),i=this.session.parse(n).map(jue),s=this.session.getValue();return{tag:_2(s),log:i}}finish(){const t=this.session.getValue();return this.session.dispose(),_2(t)}}L1.TagParser=AO;function Hue(e){const t=new AO;if(typeof e=="string")return t.parse(e);const n=[];for(let r=0;r<e.length;r++){const i=t.parse(e[r]);for(const s of i.log)n.push({...s,line:r+s.line})}return{tag:t.finish(),log:n}}var U6={};Object.defineProperty(U6,"__esModule",{value:!0}),U6.parseString=Gue;var qs;(function(e){e[e.Normal=0]="Normal",e[e.ReverseVirgule=1]="ReverseVirgule",e[e.Unicode=2]="Unicode"})(qs||(qs={}));function Gue(e,t=""){let n=e.slice(t.length),r=qs.Normal;t.length&&(n=n.slice(0,-t.length));let i="",s="";for(const a of n)switch(r){case qs.Normal:{a==="\\"?r=qs.ReverseVirgule:i+=a;break}case qs.ReverseVirgule:{let o=a;if(a==="u"){r=qs.Unicode,s="";continue}a==="b"?o="\b":a==="f"?o="\f":a==="n"?o=`
|
|
56
56
|
`:a==="r"?o="\r":a==="t"&&(o=" "),i+=o,r=qs.Normal;break}case qs.Unicode:"ABCDEFabcdef0123456789".includes(a)?(s+=a,s.length===4&&(i+=String.fromCharCode(parseInt(s,16)),r=qs.Normal)):r=qs.Normal}return i}(function(e){var t=gr&&gr.__createBinding||(Object.create?function(a,o,l,u){u===void 0&&(u=l);var c=Object.getOwnPropertyDescriptor(o,l);(!c||("get"in c?!o.__esModule:c.writable||c.configurable))&&(c={enumerable:!0,get:function(){return o[l]}}),Object.defineProperty(a,u,c)}:function(a,o,l,u){u===void 0&&(u=l),a[u]=o[l]}),n=gr&&gr.__setModuleDefault||(Object.create?function(a,o){Object.defineProperty(a,"default",{enumerable:!0,value:o})}:function(a,o){a.default=o}),r=gr&&gr.__exportStar||function(a,o){for(var l in a)l!=="default"&&!Object.prototype.hasOwnProperty.call(o,l)&&t(o,a,l)},i=gr&&gr.__importStar||function(){var a=function(o){return a=Object.getOwnPropertyNames||function(l){var u=[];for(var c in l)Object.prototype.hasOwnProperty.call(l,c)&&(u[u.length]=c);return u},a(o)};return function(o){if(o&&o.__esModule)return o;var l={};if(o!=null)for(var u=a(o),c=0;c<u.length;c++)u[c]!=="default"&&t(l,o,u[c]);return n(l,o),l}}();Object.defineProperty(e,"__esModule",{value:!0}),e.ParseUtil=e.TagParser=e.parseTag=void 0,r(zo,e);var s=L1;Object.defineProperty(e,"parseTag",{enumerable:!0,get:function(){return s.parseTag}}),Object.defineProperty(e,"TagParser",{enumerable:!0,get:function(){return s.TagParser}}),e.ParseUtil=i(U6)})(xd);var $d=(e=>(e.Dollars="usd",e.Euros="euro",e.Pounds="pound",e))($d||{}),Kl=(e=>(e.Bytes="bytes",e.Kilobytes="kb",e.Megabytes="mb",e.Gigabytes="gb",e.Terabytes="tb",e))(Kl||{}),ct=(e=>(e.Nanoseconds="nanoseconds",e.Microseconds="microseconds",e.Milliseconds="milliseconds",e.Seconds="seconds",e.Minutes="minutes",e.Hours="hours",e.Days="days",e))(ct||{});function j6(e){return Object.values(ct).includes(e)}var Lr=(e=>(e.Array="array",e.RepeatedRecord="repeated_record",e.Record="record",e.Number="number",e.Date="date",e.JSON="json",e.String="string",e.Timestamp="timestamp",e.Boolean="boolean",e.SQLNative="sql_native",e))(Lr||{});const Yue=["bar_chart","line_chart"],Xue=["bar","line"];function MO(e){return{bar_chart:"bar",line_chart:"line",table:"table",dashboard:"dashboard"}[e]??e}function j1(e){if(e.has("viz"))return e;const t=e.properties??{},r=Object.keys(t).reverse().find(i=>Yue.includes(i)&&!t[i].deleted);if(r){const i=e.tag(r);return i?e.set(["viz"],i).set(["viz"],MO(r)):e.set(["viz"],MO(r))}return e}var W1={},V1={};Object.defineProperty(V1,"__esModule",{value:!0}),V1.MALLOY_INTERFACE_TYPES=void 0,V1.MALLOY_INTERFACE_TYPES={Aggregate:{type:"struct",name:"Aggregate",fields:{name:{type:"string",optional:!0,array:!1},field:{type:"Field",optional:!1,array:!1}}},Annotation:{type:"struct",name:"Annotation",fields:{value:{type:"string",optional:!1,array:!1}}},AnonymousQueryInfo:{type:"struct",name:"AnonymousQueryInfo",fields:{schema:{type:"Schema",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0},definition:{type:"Query",optional:!0,array:!1},code:{type:"string",optional:!0,array:!1},location:{type:"Location",optional:!0,array:!1}}},ArrayCell:{type:"struct",name:"ArrayCell",fields:{array_value:{type:"Cell",array:!0,optional:!1}}},ArrayType:{type:"struct",name:"ArrayType",fields:{element_type:{type:"AtomicType",optional:!1,array:!1}}},AtomicType:{type:"union",name:"AtomicType",options:{string_type:"StringType",boolean_type:"BooleanType",number_type:"NumberType",json_type:"JSONType",sql_native_type:"SQLNativeType",date_type:"DateType",timestamp_type:"TimestampType",array_type:"ArrayType",record_type:"RecordType",timestamptz_type:"TimestamptzType"}},BooleanCell:{type:"struct",name:"BooleanCell",fields:{boolean_value:{type:"boolean",optional:!1,array:!1}}},BooleanLiteral:{type:"struct",name:"BooleanLiteral",fields:{boolean_value:{type:"boolean",optional:!1,array:!1}}},BooleanType:{type:"struct",name:"BooleanType",fields:{}},CalculateInfo:{type:"struct",name:"CalculateInfo",fields:{name:{type:"string",optional:!1,array:!1},type:{type:"AtomicType",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0}}},CalculateOperation:{type:"struct",name:"CalculateOperation",fields:{name:{type:"string",optional:!1,array:!1},field:{type:"Field",optional:!1,array:!1}}},Cell:{type:"union",name:"Cell",options:{string_cell:"StringCell",boolean_cell:"BooleanCell",date_cell:"DateCell",timestamp_cell:"TimestampCell",number_cell:"NumberCell",json_cell:"JSONCell",record_cell:"RecordCell",array_cell:"ArrayCell",null_cell:"NullCell",sql_native_cell:"SQLNativeCell"}},CompileModelRequest:{type:"struct",name:"CompileModelRequest",fields:{model_url:{type:"string",optional:!1,array:!1},extend_model_url:{type:"string",optional:!0,array:!1},exclude_references:{type:"boolean",optional:!0,array:!1},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1}}},CompileModelResponse:{type:"struct",name:"CompileModelResponse",fields:{model:{type:"ModelInfo",optional:!0,array:!1},logs:{type:"LogMessage",array:!0,optional:!0},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1},translations:{type:"Translation",array:!0,optional:!0},timing_info:{type:"TimingInfo",optional:!0,array:!1}}},CompileQueryRequest:{type:"struct",name:"CompileQueryRequest",fields:{model_url:{type:"string",optional:!1,array:!1},query:{type:"Query",optional:!0,array:!1},query_malloy:{type:"string",optional:!0,array:!1},default_row_limit:{type:"number",optional:!0,array:!1},exclude_references:{type:"boolean",optional:!0,array:!1},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1}}},CompileQueryResponse:{type:"struct",name:"CompileQueryResponse",fields:{result:{type:"Result",optional:!0,array:!1},default_row_limit_added:{type:"number",optional:!0,array:!1},logs:{type:"LogMessage",array:!0,optional:!0},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1},translations:{type:"Translation",array:!0,optional:!0},timing_info:{type:"TimingInfo",optional:!0,array:!1}}},CompileSourceRequest:{type:"struct",name:"CompileSourceRequest",fields:{model_url:{type:"string",optional:!1,array:!1},name:{type:"string",optional:!1,array:!1},extend_model_url:{type:"string",optional:!0,array:!1},exclude_references:{type:"boolean",optional:!0,array:!1},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1}}},CompileSourceResponse:{type:"struct",name:"CompileSourceResponse",fields:{source:{type:"SourceInfo",optional:!0,array:!1},logs:{type:"LogMessage",array:!0,optional:!0},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1},timing_info:{type:"TimingInfo",optional:!0,array:!1}}},CompilerNeeds:{type:"struct",name:"CompilerNeeds",fields:{table_schemas:{type:"SQLTable",array:!0,optional:!0},sql_schemas:{type:"SQLQuery",array:!0,optional:!0},files:{type:"File",array:!0,optional:!0},connections:{type:"Connection",array:!0,optional:!0},translations:{type:"Translation",array:!0,optional:!0}}},Connection:{type:"struct",name:"Connection",fields:{name:{type:"string",optional:!1,array:!1},dialect:{type:"string",optional:!0,array:!1}}},Data:{type:"union",name:"Data",options:{record_cell:"RecordCell",array_cell:"ArrayCell"}},DateCell:{type:"struct",name:"DateCell",fields:{date_value:{type:"string",optional:!1,array:!1}}},DateLiteral:{type:"struct",name:"DateLiteral",fields:{date_value:{type:"string",optional:!1,array:!1},granularity:{type:"DateTimeframe",optional:!0,array:!1},timezone:{type:"string",optional:!0,array:!1}}},DateTimeframe:{type:"enum",name:"DateTimeframe",values:{year:1,quarter:2,month:3,week:4,day:5}},DateType:{type:"struct",name:"DateType",fields:{timeframe:{type:"DateTimeframe",optional:!0,array:!1}}},DimensionInfo:{type:"struct",name:"DimensionInfo",fields:{name:{type:"string",optional:!1,array:!1},type:{type:"AtomicType",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0}}},DocumentPosition:{type:"struct",name:"DocumentPosition",fields:{line:{type:"number",optional:!1,array:!1},character:{type:"number",optional:!1,array:!1}}},DocumentRange:{type:"struct",name:"DocumentRange",fields:{start:{type:"DocumentPosition",optional:!1,array:!1},end:{type:"DocumentPosition",optional:!1,array:!1}}},DrillOperation:{type:"struct",name:"DrillOperation",fields:{filter:{type:"Filter",optional:!1,array:!1}}},Expression:{type:"union",name:"Expression",options:{field_reference:"Reference",time_truncation:"TimeTruncationFieldReference",filtered_field:"FilteredField",literal_value:"LiteralValueExpression",moving_average:"MovingAverage"}},Field:{type:"struct",name:"Field",fields:{expression:{type:"Expression",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0}}},FieldInfo:{type:"union",name:"FieldInfo",options:{dimension:"DimensionInfo",measure:"MeasureInfo",join:"JoinInfo",view:"ViewInfo",calculate:"CalculateInfo"}},File:{type:"struct",name:"File",fields:{url:{type:"string",optional:!1,array:!1},contents:{type:"string",optional:!0,array:!1},invalidation_key:{type:"string",optional:!0,array:!1}}},Filter:{type:"union",name:"Filter",options:{filter_string:"FilterStringApplication",literal_equality:"LiteralEqualityComparison"}},FilterExpressionLiteral:{type:"struct",name:"FilterExpressionLiteral",fields:{filter_expression_value:{type:"string",optional:!1,array:!1}}},FilterExpressionType:{type:"struct",name:"FilterExpressionType",fields:{filter_type:{type:"FilterableType",optional:!1,array:!1}}},FilterOperation:{type:"struct",name:"FilterOperation",fields:{filter:{type:"Filter",optional:!1,array:!1}}},FilterStringApplication:{type:"struct",name:"FilterStringApplication",fields:{expression:{type:"Expression",optional:!1,array:!1},filter:{type:"string",optional:!1,array:!1}}},FilterableType:{type:"union",name:"FilterableType",options:{string_type:"StringType",boolean_type:"BooleanType",number_type:"NumberType",date_type:"DateType",timestamp_type:"TimestampType",timestamptz_type:"TimestamptzType"}},FilteredField:{type:"struct",name:"FilteredField",fields:{field_reference:{type:"Reference",optional:!1,array:!1},where:{type:"FilterOperation",array:!0,optional:!1}}},GroupBy:{type:"struct",name:"GroupBy",fields:{name:{type:"string",optional:!0,array:!1},field:{type:"Field",optional:!1,array:!1}}},JSONCell:{type:"struct",name:"JSONCell",fields:{json_value:{type:"string",optional:!1,array:!1}}},JSONType:{type:"struct",name:"JSONType",fields:{}},JoinInfo:{type:"struct",name:"JoinInfo",fields:{name:{type:"string",optional:!1,array:!1},schema:{type:"Schema",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0},relationship:{type:"Relationship",optional:!1,array:!1}}},Limit:{type:"struct",name:"Limit",fields:{limit:{type:"number",optional:!1,array:!1}}},LiteralEqualityComparison:{type:"struct",name:"LiteralEqualityComparison",fields:{expression:{type:"Expression",optional:!1,array:!1},value:{type:"LiteralValue",optional:!1,array:!1}}},LiteralValue:{type:"union",name:"LiteralValue",options:{string_literal:"StringLiteral",number_literal:"NumberLiteral",date_literal:"DateLiteral",timestamp_literal:"TimestampLiteral",boolean_literal:"BooleanLiteral",null_literal:"NullLiteral",filter_expression_literal:"FilterExpressionLiteral"}},LiteralValueExpression:{type:"struct",name:"LiteralValueExpression",fields:{literal_value:{type:"LiteralValue",optional:!1,array:!1}}},Location:{type:"struct",name:"Location",fields:{url:{type:"string",optional:!1,array:!1},range:{type:"Range",optional:!1,array:!1}}},LogMessage:{type:"struct",name:"LogMessage",fields:{url:{type:"string",optional:!1,array:!1},range:{type:"DocumentRange",optional:!1,array:!1},severity:{type:"LogSeverity",optional:!1,array:!1},message:{type:"string",optional:!1,array:!1}}},LogSeverity:{type:"enum",name:"LogSeverity",values:{debug:1,info:2,warn:3,error:4}},MeasureInfo:{type:"struct",name:"MeasureInfo",fields:{name:{type:"string",optional:!1,array:!1},type:{type:"AtomicType",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0}}},ModelEntryValue:{type:"union",name:"ModelEntryValue",options:{source:"SourceInfo",query:"QueryInfo"}},ModelInfo:{type:"struct",name:"ModelInfo",fields:{entries:{type:"ModelEntryValue",array:!0,optional:!1},annotations:{type:"Annotation",array:!0,optional:!0},anonymous_queries:{type:"AnonymousQueryInfo",array:!0,optional:!1}}},MovingAverage:{type:"struct",name:"MovingAverage",fields:{field_reference:{type:"Reference",optional:!1,array:!1},rows_preceding:{type:"number",optional:!0,array:!1},rows_following:{type:"number",optional:!0,array:!1},partition_fields:{type:"Reference",array:!0,optional:!0}}},Nest:{type:"struct",name:"Nest",fields:{name:{type:"string",optional:!0,array:!1},view:{type:"View",optional:!1,array:!1}}},NullCell:{type:"struct",name:"NullCell",fields:{}},NullLiteral:{type:"struct",name:"NullLiteral",fields:{}},NumberCell:{type:"struct",name:"NumberCell",fields:{number_value:{type:"number",optional:!1,array:!1},subtype:{type:"NumberSubtype",optional:!0,array:!1},string_value:{type:"string",optional:!0,array:!1}}},NumberLiteral:{type:"struct",name:"NumberLiteral",fields:{number_value:{type:"number",optional:!1,array:!1},string_value:{type:"string",optional:!0,array:!1}}},NumberSubtype:{type:"enum",name:"NumberSubtype",values:{integer:1,decimal:2,bigint:3}},NumberType:{type:"struct",name:"NumberType",fields:{subtype:{type:"NumberSubtype",optional:!0,array:!1}}},OrderBy:{type:"struct",name:"OrderBy",fields:{field_reference:{type:"Reference",optional:!1,array:!1},direction:{type:"OrderByDirection",optional:!0,array:!1}}},OrderByDirection:{type:"enum",name:"OrderByDirection",values:{asc:1,desc:2}},ParameterInfo:{type:"struct",name:"ParameterInfo",fields:{name:{type:"string",optional:!1,array:!1},type:{type:"ParameterType",optional:!1,array:!1},default_value:{type:"LiteralValue",optional:!0,array:!1}}},ParameterType:{type:"union",name:"ParameterType",options:{string_type:"StringType",boolean_type:"BooleanType",number_type:"NumberType",json_type:"JSONType",sql_native_type:"SQLNativeType",date_type:"DateType",timestamp_type:"TimestampType",array_type:"ArrayType",record_type:"RecordType",filter_expression_type:"FilterExpressionType",timestamptz_type:"TimestamptzType"}},ParameterValue:{type:"struct",name:"ParameterValue",fields:{name:{type:"string",optional:!1,array:!1},value:{type:"LiteralValue",optional:!1,array:!1}}},Position:{type:"struct",name:"Position",fields:{line:{type:"number",optional:!1,array:!1},character:{type:"number",optional:!1,array:!1}}},Query:{type:"struct",name:"Query",fields:{definition:{type:"QueryDefinition",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0}}},QueryArrow:{type:"struct",name:"QueryArrow",fields:{source:{type:"QueryArrowSource",optional:!1,array:!1},view:{type:"ViewDefinition",optional:!1,array:!1}}},QueryArrowSource:{type:"union",name:"QueryArrowSource",options:{refinement:"QueryRefinement",source_reference:"Reference"}},QueryDefinition:{type:"union",name:"QueryDefinition",options:{arrow:"QueryArrow",query_reference:"Reference",refinement:"QueryRefinement"}},QueryInfo:{type:"struct",name:"QueryInfo",fields:{name:{type:"string",optional:!1,array:!1},schema:{type:"Schema",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0},definition:{type:"Query",optional:!0,array:!1},code:{type:"string",optional:!0,array:!1},location:{type:"Location",optional:!0,array:!1}}},QueryRefinement:{type:"struct",name:"QueryRefinement",fields:{base:{type:"QueryDefinition",optional:!1,array:!1},refinement:{type:"ViewDefinition",optional:!1,array:!1}}},Range:{type:"struct",name:"Range",fields:{start:{type:"Position",optional:!1,array:!1},end:{type:"Position",optional:!1,array:!1}}},RecordCell:{type:"struct",name:"RecordCell",fields:{record_value:{type:"Cell",array:!0,optional:!1}}},RecordType:{type:"struct",name:"RecordType",fields:{fields:{type:"DimensionInfo",array:!0,optional:!1}}},Reference:{type:"struct",name:"Reference",fields:{name:{type:"string",optional:!1,array:!1},path:{type:"string",array:!0,optional:!0},parameters:{type:"ParameterValue",array:!0,optional:!0}}},Relationship:{type:"enum",name:"Relationship",values:{one:1,many:2,cross:3}},Result:{type:"struct",name:"Result",fields:{data:{type:"Data",optional:!0,array:!1},schema:{type:"Schema",optional:!1,array:!1},sql:{type:"string",optional:!0,array:!1},connection_name:{type:"string",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0},model_annotations:{type:"Annotation",array:!0,optional:!0},query_timezone:{type:"string",optional:!0,array:!1},source_annotations:{type:"Annotation",array:!0,optional:!0}}},RunIndexQueryRequest:{type:"struct",name:"RunIndexQueryRequest",fields:{model_url:{type:"string",optional:!1,array:!1},source_name:{type:"string",optional:!1,array:!1},exclude_references:{type:"boolean",optional:!0,array:!1},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1}}},RunIndexQueryResponse:{type:"struct",name:"RunIndexQueryResponse",fields:{result:{type:"Result",optional:!0,array:!1},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1},timing_info:{type:"TimingInfo",optional:!0,array:!1}}},RunQueryRequest:{type:"struct",name:"RunQueryRequest",fields:{model_url:{type:"string",optional:!1,array:!1},query:{type:"Query",optional:!0,array:!1},query_malloy:{type:"string",optional:!0,array:!1},default_row_limit:{type:"number",optional:!0,array:!1},exclude_references:{type:"boolean",optional:!0,array:!1},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1}}},RunQueryResponse:{type:"struct",name:"RunQueryResponse",fields:{result:{type:"Result",optional:!0,array:!1},default_row_limit_added:{type:"number",optional:!0,array:!1},logs:{type:"LogMessage",array:!0,optional:!0},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1},timing_info:{type:"TimingInfo",optional:!0,array:!1}}},SQLNativeCell:{type:"struct",name:"SQLNativeCell",fields:{sql_native_value:{type:"string",optional:!1,array:!1}}},SQLNativeType:{type:"struct",name:"SQLNativeType",fields:{sql_type:{type:"string",optional:!0,array:!1}}},SQLQuery:{type:"struct",name:"SQLQuery",fields:{sql:{type:"string",optional:!1,array:!1},schema:{type:"Schema",optional:!0,array:!1},connection_name:{type:"string",optional:!1,array:!1}}},SQLTable:{type:"struct",name:"SQLTable",fields:{name:{type:"string",optional:!1,array:!1},schema:{type:"Schema",optional:!0,array:!1},connection_name:{type:"string",optional:!1,array:!1}}},Schema:{type:"struct",name:"Schema",fields:{fields:{type:"FieldInfo",array:!0,optional:!1}}},SourceInfo:{type:"struct",name:"SourceInfo",fields:{name:{type:"string",optional:!1,array:!1},schema:{type:"Schema",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0},parameters:{type:"ParameterInfo",array:!0,optional:!0}}},StringCell:{type:"struct",name:"StringCell",fields:{string_value:{type:"string",optional:!1,array:!1}}},StringLiteral:{type:"struct",name:"StringLiteral",fields:{string_value:{type:"string",optional:!1,array:!1}}},StringType:{type:"struct",name:"StringType",fields:{}},TimeTruncationFieldReference:{type:"struct",name:"TimeTruncationFieldReference",fields:{field_reference:{type:"Reference",optional:!1,array:!1},truncation:{type:"TimestampTimeframe",optional:!1,array:!1}}},TimestampCell:{type:"struct",name:"TimestampCell",fields:{timestamp_value:{type:"string",optional:!1,array:!1}}},TimestampLiteral:{type:"struct",name:"TimestampLiteral",fields:{timestamp_value:{type:"string",optional:!1,array:!1},granularity:{type:"TimestampTimeframe",optional:!0,array:!1},timezone:{type:"string",optional:!0,array:!1}}},TimestampTimeframe:{type:"enum",name:"TimestampTimeframe",values:{year:1,quarter:2,month:3,week:4,day:5,hour:6,minute:7,second:8}},TimestampType:{type:"struct",name:"TimestampType",fields:{timeframe:{type:"TimestampTimeframe",optional:!0,array:!1}}},TimestamptzType:{type:"struct",name:"TimestamptzType",fields:{timeframe:{type:"TimestampTimeframe",optional:!0,array:!1}}},TimingInfo:{type:"struct",name:"TimingInfo",fields:{name:{type:"string",optional:!1,array:!1},duration_ms:{type:"number",optional:!1,array:!1},detailed_timing:{type:"TimingInfo",array:!0,optional:!0}}},Translation:{type:"struct",name:"Translation",fields:{url:{type:"string",optional:!1,array:!1},compiled_model_json:{type:"string",optional:!0,array:!1}}},View:{type:"struct",name:"View",fields:{definition:{type:"ViewDefinition",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0}}},ViewArrow:{type:"struct",name:"ViewArrow",fields:{source:{type:"ViewDefinition",optional:!1,array:!1},view:{type:"ViewDefinition",optional:!1,array:!1}}},ViewDefinition:{type:"union",name:"ViewDefinition",options:{arrow:"ViewArrow",view_reference:"Reference",refinement:"ViewRefinement",segment:"ViewSegment"}},ViewInfo:{type:"struct",name:"ViewInfo",fields:{name:{type:"string",optional:!1,array:!1},schema:{type:"Schema",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0},definition:{type:"View",optional:!0,array:!1}}},ViewOperation:{type:"union",name:"ViewOperation",options:{group_by:"GroupBy",aggregate:"Aggregate",order_by:"OrderBy",limit:"Limit",where:"FilterOperation",nest:"Nest",having:"FilterOperation",drill:"DrillOperation",calculate:"CalculateOperation"}},ViewRefinement:{type:"struct",name:"ViewRefinement",fields:{base:{type:"ViewDefinition",optional:!1,array:!1},refinement:{type:"ViewDefinition",optional:!1,array:!1}}},ViewSegment:{type:"struct",name:"ViewSegment",fields:{operations:{type:"ViewOperation",array:!0,optional:!1}}}};var C2={},W6={},A2={};Object.defineProperty(A2,"__esModule",{value:!0}),A2.RESERVED_WORDS=void 0,A2.RESERVED_WORDS=["accept","aggregate","declare","dimension","except","explore","group_by","having","index","join_cross","join_one","join_many","limit","measure","nest","order_by","primary_key","project","query","rename","sample","source","sql","turduck","top","where","all","as","asc","avg","boolean","by","case","cast","condition","count","date","day","days","desc","distinct","else","end","exclude","false","for","from","from_sql","has","hour","hours","import","is","json","last","max","min","minute","minutes","month","months","not","now","null","number","on","or","pick","quarter","quarters","second","seconds","string","sum","table","then","this","timestamp","to","true","turtle","week","weeks","when","with","year","years","ungrouped"],Object.defineProperty(W6,"__esModule",{value:!0}),W6.maybeQuoteIdentifier=Jue;const Zue=A2;function Que(e){const t=!e.match(/^[A-Za-z_][A-Za-z_0-9]*$/),n=Zue.RESERVED_WORDS.includes(e.toLowerCase());return t||n}function Jue(e){return Que(e)?`\`${e}\``:e}Object.defineProperty(C2,"__esModule",{value:!0}),C2.queryToMalloy=Kue,C2.filterToMalloy=ece;const H1=W6;function Kue(e,{tabWidth:t}={tabWidth:2}){const n=ice(e);return FO(n,{tabWidth:t})}function ece(e,{tabWidth:t}={tabWidth:2}){const n=NO(e);return FO(n,{tabWidth:t})}const V6=Symbol("indent"),Us=Symbol("newline"),H6=Symbol("outdent"),tce=Symbol("optional_newline_indent");function FO(e,{tabWidth:t}={tabWidth:2}){let n="",r=0,i=!0;for(const s of e)if(s===Us)n+=`
|
|
57
57
|
`,i=!0;else if(s===H6)r--;else if(s===V6)r++;else{if(s===tce)continue;i&&(n+=" ".repeat(r*t),i=!1),n+=s}return n}function Sd(e,t,n,r){var i;if(t.includes(Us))return[e,Us,V6,...t,Us,H6,n];const a=((i=r==null?void 0:r.spaces)!==null&&i!==void 0?i:!0)?" ":"";return[e,a,...t,a,n]}function nce(e){return{contents:e,quoteCharacter:'"'}}function rce(e,t){const n=[];for(let r=0;r<e.length;r++){const i=e[r];n.push(i),r<e.length-1&&n.push(t)}return n}function G6(e){var t,n;switch(e.kind){case"filter_expression_literal":return[RO(e.filter_expression_value)];case"boolean_literal":return[e.boolean_value.toString()];case"string_literal":{const{contents:r,quoteCharacter:i}=nce(e.string_value);return[i,r,i]}case"number_literal":return[e.number_value.toString()];case"null_literal":return["null"];case"date_literal":return[DO(TO(e.date_value),(t=e.granularity)!==null&&t!==void 0?t:"day",e.timezone)];case"timestamp_literal":return[DO(TO(e.timestamp_value),(n=e.granularity)!==null&&n!==void 0?n:"second",e.timezone)]}}function TO(e){let t;if(t=/(\d\d\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/.exec(e)){const[n,r,i,s,a,o,l]=t;return[r,i,s,a,o,l]}else if(t=/(\d\d\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d)/.exec(e)){const[n,r,i,s,a,o]=t;return[r,i,s,a,o,"00"]}else if(t=/(\d\d\d\d)-(\d\d)-(\d\d) (\d\d)(?:00)?/.exec(e)){const[n,r,i,s,a]=t;return[r,i,s,a,"00","00"]}else if(t=/(\d\d\d\d)-(\d\d)-(\d\d)/.exec(e)){const[n,r,i,s]=t;return[r,i,s,"00","00","00"]}else if(t=/(\d\d\d\d)-(\d\d)/.exec(e)){const[n,r,i]=t;return[r,i,"01","00","00","00"]}else if(t=/(\d\d\d\d)/.exec(e)){const[n,r]=t;return[r,"01","01","00","00","00"]}return["1970","01","01","00","00","00"]}function DO([e,t,n,r,i,s],a,o){switch(a){case"year":return`@${e}`;case"quarter":{const l=Math.floor(+t/3)+1;return`@${e}-Q${l}`}case"month":return`@${e}-${t}`;case"week":return`@${e}-${t}-${n}-WK`;case"day":return`@${e}-${t}-${n}`;case"hour":return`@${e}-${t}-${n} ${r}`;case"minute":return`@${e}-${t}-${n} ${r}:${i}`;case"second":return o!==void 0?`@${e}-${t}-${n} ${r}:${i}:${s}[${o}]`:`@${e}-${t}-${n} ${r}:${i}:${s}`;default:throw new Error("Unknown timeframe.")}}function Lo(e){var t;const n=[];for(const r of(t=e.path)!==null&&t!==void 0?t:[])n.push((0,H1.maybeQuoteIdentifier)(r)),n.push(".");if(n.push((0,H1.maybeQuoteIdentifier)(e.name)),e.parameters){const r=[];for(let i=0;i<e.parameters.length;i++){const s=e.parameters[i];r.push((0,H1.maybeQuoteIdentifier)(s.name)),r.push(" is "),r.push(...G6(s.value)),i<e.parameters.length-1&&r.push(",",Us)}n.push(...Sd("(",r,")",{spaces:!1}))}return n}function ice(e){const t=[];return t.push(...G1(e.annotations)),t.push("run: "),t.push(...Y6(e.definition)),t}function sce(e){const t=[];switch(e.kind){case"source_reference":{t.push(...Lo(e));break}case"refinement":t.push(...Y6(e));break}return t}function Y6(e){const t=[];switch(e.kind){case"arrow":{t.push(...sce(e.source)),t.push(" -> "),t.push(...yc(e.view));break}case"query_reference":{t.push(...Lo(e));break}case"refinement":{const n=Y6(e.base);e.base.kind==="arrow"?t.push(...Sd("(",n,")",{spaces:!1})):t.push(...n),t.push(" + "),t.push(...yc(e.refinement));break}}return t}function yc(e){const t=[];switch(e.kind){case"arrow":{t.push(...yc(e.source)),t.push(" -> "),t.push(...yc(e.view));break}case"view_reference":{t.push(...Lo(e));break}case"refinement":{t.push(...yc(e.base)),t.push(" + "),t.push(...yc(e.refinement));break}case"segment":{t.push(...ace(e));break}}return t}function ace(e){if(e.operations.length===0)return["{ }"];const t=e.operations.length>1,n=[];for(let r=0;r<e.operations.length;r++){const i=e.operations[r],s=[i];for(;r<e.operations.length-1;){const a=e.operations[r+1];if(a.kind===i.kind)s.push(a),r++;else break}n.push(...oce(s)),t&&r<e.operations.length-1&&n.push(Us)}return Sd("{",n,"}")}function oce(e){switch(e[0].kind){case"aggregate":return Z6(e,"aggregate");case"group_by":return Z6(e,"group_by");case"order_by":return cce(e);case"nest":return dce(e);case"limit":return gce(e);case"where":return OO(e);case"having":return bce(e);case"drill":return yce(e);case"calculate":return Z6(e,"calculate")}}function kd(e,t,n=""){const r=[];r.push(`${e}:`);const i=t.length>1||t.some(s=>s.includes(Us));i?r.push(Us,V6):r.push(" ");for(let s=0;s<t.length;s++){const a=t[s];r.push(...a),t.length>1&&s<t.length-1&&r.push(n),i&&s<t.length-1&&r.push(Us)}return i&&r.push(H6),r}function lce(e){const t=[];return t.push(...X6(e.expression)),t}function oZe(e){return e}function X6(e){var t;switch(e.kind){case"field_reference":return Lo(e);case"time_truncation":return[...Lo(e.field_reference),".",e.truncation];case"filtered_field":return[...Lo(e.field_reference),...Sd(" {",OO(e.where),"}")];case"literal_value":return G6(e.literal_value);case"moving_average":{const n=["avg_moving",...Sd("(",[...Lo(e.field_reference),e.rows_preceding!==void 0?`, ${e.rows_preceding}`:", 0",e.rows_following!==void 0?`, ${e.rows_following}`:""],")",{spaces:!1})];return!((t=e.partition_fields)===null||t===void 0)&&t.length&&n.push(...Sd(" {",["partition_by",": ",...rce(e.partition_fields.flatMap(r=>Lo(r)),", ")],"}")),n}}}function uce(e,t=!1){const n=[];return t||n.push(...G1(e.field.annotations)),e.name&&(n.push((0,H1.maybeQuoteIdentifier)(e.name)),n.push(" is ")),n.push(...lce(e.field)),n}function Z6(e,t){const n=[],r=e.length===1;return r&&n.push(...G1(e[0].field.annotations)),n.push(...kd(t,e.map(i=>uce(i,r)))),n}function cce(e){return kd("order_by",e.map(fce),",")}function fce(e){const t=[];return t.push(...Lo(e.field_reference)),e.direction&&(t.push(" "),t.push(e.direction)),t}function dce(e){const t=[],n=e.length===1;return n&&t.push(...G1(e[0].view.annotations)),t.push(...kd("nest",e.map(r=>hce(r,n)))),t}function hce(e,t=!1){const n=[];return t||n.push(...G1(e.view.annotations)),e.name&&(n.push((0,H1.maybeQuoteIdentifier)(e.name)),n.push(" is ")),n.push(...mce(e.view)),n}function mce(e){return yc(e.definition)}function pce(e){return[`limit: ${e.limit}`]}function gce(e){const t=[];for(let n=0;n<e.length;n++)n!==0&&t.push(Us),t.push(...pce(e[n]));return t}function OO(e){return kd("where",e.map(Q6),",")}function yce(e){return kd("drill",e.map(Q6),",")}function bce(e){return kd("having",e.map(Q6),",")}const vce=["`","'",'"'];function RO(e){let t,n;for(const r of vce){const i=xce(e,r);if(i===e)return`f${r}${e}${r}`;(n===void 0||i.length<n.length)&&(t=r,n=i)}return`f${t}${n}${t}`}function xce(e,t){let n="";for(let r=0;r<e.length;r++)e.slice(r).startsWith(t)?(n+="\\"+t,r+=t.length):(n+=e[r],e[r]==="\\"&&(n+=e[++r]));return n}function NO(e){switch(e.kind){case"filter_string":return[...X6(e.expression)," ~ ",RO(e.filter)];case"literal_equality":return[...X6(e.expression)," = ",...G6(e.value)]}}function Q6(e){return NO(e.filter)}function G1(e){return e?e.flatMap(wce):[]}function wce(e){return[e.value.trim(),Us]}var Ed={};Object.defineProperty(Ed,"__esModule",{value:!0}),Ed.nestUnions=J6,Ed.unnestUnions=M2,Ed.convertFromThrift=F2,Ed.convertToThrift=T2;const $ce=V1;function J6(e){if(e==null)return e;if(typeof e=="string"||typeof e=="number"||typeof e=="boolean")return e;if(Array.isArray(e))return e.map(J6);{const t={};let n;for(const r in e)r==="kind"?n=e[r]:t[r]=J6(e[r]);return n===void 0?t:{[n]:t}}}function M2(e,t){if(e==null)return e;if(typeof e=="string"||typeof e=="number"||typeof e=="boolean")return e;if(Array.isArray(e))return e.map(n=>M2(n,t));{const n=_d(t);if(n.type==="union"){for(const r in n.options)if(e[r]!==void 0){const i=M2(e[r],n.options[r]);if(typeof i=="object")return{kind:r,...i}}}else if(n.type==="struct"){const r={};for(const i in e){const s=n.fields[i];if(s===void 0)throw new Error(`Unknown field ${i} in ${t}`);r[i]=M2(e[i],s.type)}return r}else throw new Error(`Cannot unnest unions in an enum type ${t}`)}}function F2(e,t){if(e==null)return e;if(typeof e=="string"||typeof e=="boolean")return e;if(typeof e=="number"){if(t==="number")return e;const n=_d(t);if(n.type!=="enum")throw new Error(`Found a number where a ${t} was expected`);const r=Object.entries(n.values).find(([,i])=>i===e);if(r===void 0)throw new Error(`${e} is not a valid enum value for ${t}`);return r[0]}else{if(Array.isArray(e))return e.map(n=>F2(n,t));{const n=_d(t);if(n.type==="union"){for(const r in n.options)if(e[r]!==void 0&&e[r]!==null){const i=F2(e[r],n.options[r]);if(typeof i=="object")return{kind:r,...i}}}else if(n.type==="struct"){const r={};for(const i in e){const s=n.fields[i];if(s===void 0)throw new Error(`Unknown field ${i} in ${t}`);r[i]=F2(e[i],s.type)}return r}else throw new Error(`Cannot unnest unions in an enum type ${t}`)}}}function _d(e){const t=$ce.MALLOY_INTERFACE_TYPES[e];if(t===void 0)throw new Error(`Unknown Malloy interface type ${e}`);return t}function T2(e,t){if(e==null)return e;if(typeof e=="number"||typeof e=="boolean")return e;if(typeof e=="string"){if(t==="string")return e;const n=_d(t);if(n.type==="enum"){const r=n.values[e];if(r===void 0)throw new Error(`${e} is not a valid enum value for ${t}`);return r}}else{if(Array.isArray(e))return e.map(n=>T2(n,t));{const n=_d(t);if(n.type==="union"){const r=e.kind,i=n.options[r];if(i===void 0)throw new Error(`${r} is not a valid union of ${t}`);const s=_d(i);if(s.type!=="struct")throw new Error("Union fields must be structs");const a={};for(const o in e){if(o==="kind")continue;const l=s.fields[o];a[o]=T2(e[o],l.type)}return{[r]:a}}else if(n.type==="struct"){const r={};for(const i in e){const s=n.fields[i];if(s===void 0)throw new Error(`Unknown field ${i} in ${t}`);r[i]=T2(e[i],s.type)}return r}}}}(function(e){var t=gr&&gr.__createBinding||(Object.create?function(s,a,o,l){l===void 0&&(l=o);var u=Object.getOwnPropertyDescriptor(a,o);(!u||("get"in u?!a.__esModule:u.writable||u.configurable))&&(u={enumerable:!0,get:function(){return a[o]}}),Object.defineProperty(s,l,u)}:function(s,a,o,l){l===void 0&&(l=o),s[l]=a[o]}),n=gr&&gr.__exportStar||function(s,a){for(var o in s)o!=="default"&&!Object.prototype.hasOwnProperty.call(a,o)&&t(a,s,o)};Object.defineProperty(e,"__esModule",{value:!0}),e.thingy4sddfdfsd=e.thingy4sdfsd=e.thingy4dfdsfs=e.thingy4asdfas=e.thingy4asdfasdf=e.thingy3dfdf=e.thingy3=e.thingy2asdf=e.thingyssdfg=e.thingy123r=e.thingy1=e.res=e.test=e.convertToThrift=e.convertFromThrift=e.unnestUnions=e.nestUnions=e.filterToMalloy=e.queryToMalloy=void 0,n(V1,e);var r=C2;Object.defineProperty(e,"queryToMalloy",{enumerable:!0,get:function(){return r.queryToMalloy}}),Object.defineProperty(e,"filterToMalloy",{enumerable:!0,get:function(){return r.filterToMalloy}});var i=Ed;Object.defineProperty(e,"nestUnions",{enumerable:!0,get:function(){return i.nestUnions}}),Object.defineProperty(e,"unnestUnions",{enumerable:!0,get:function(){return i.unnestUnions}}),Object.defineProperty(e,"convertFromThrift",{enumerable:!0,get:function(){return i.convertFromThrift}}),Object.defineProperty(e,"convertToThrift",{enumerable:!0,get:function(){return i.convertToThrift}}),e.test={entries:[{kind:"source",name:"flights",schema:{fields:[{kind:"dimension",name:"carrier",type:{kind:"boolean_type"},annotations:[{value:"# foo=1"}]},{kind:"dimension",name:"arr",type:{kind:"array_type",element_type:{kind:"boolean_type"}}},{kind:"dimension",name:"arr_rec",type:{kind:"array_type",element_type:{kind:"record_type",fields:[{name:"arr",type:{kind:"array_type",element_type:{kind:"boolean_type"}}}]}}},{kind:"dimension",name:"rec",type:{kind:"record_type",fields:[{name:"arr",type:{kind:"array_type",element_type:{kind:"boolean_type"}}}]}},{kind:"join",name:"carriers",relationship:"one",schema:{fields:[{kind:"dimension",name:"code",type:{kind:"string_type"}}]}},{kind:"view",name:"by_carrier",schema:{fields:[{kind:"dimension",name:"carrier",type:{kind:"string_type"}},{kind:"dimension",name:"flight_count",type:{kind:"number_type"}}]}}]},parameters:[{name:"param",type:{kind:"number_type"},default_value:{kind:"number_literal",number_value:7}}]}],anonymous_queries:[]},e.res={connection_name:"foo",data:{kind:"array_cell",array_value:[{kind:"record_cell",record_value:[{kind:"string_cell",string_value:"UA"},{kind:"number_cell",number_value:12341234}]},{kind:"record_cell",record_value:[{kind:"string_cell",string_value:"AA"},{kind:"number_cell",number_value:2343}]}]},schema:{fields:[{kind:"dimension",name:"carrier",type:{kind:"string_type"}},{kind:"dimension",name:"flight_count",type:{kind:"number_type"}}]},sql:"SELECT * ..."},e.thingy1={definition:{kind:"query_reference",name:"flights_by_carrier"}},e.thingy123r={definition:{kind:"arrow",source:{kind:"source_reference",name:"flights"},view:{kind:"view_reference",name:"by_carrier"}}},e.thingyssdfg={definition:{kind:"refinement",base:{kind:"query_reference",name:"flights"},refinement:{kind:"view_reference",name:"by_carrier"}}},e.thingy2asdf={definition:{kind:"arrow",source:{kind:"source_reference",name:"flights"},view:{kind:"refinement",base:{kind:"view_reference",name:"by_carrier"},refinement:{kind:"segment",operations:[{kind:"where",filter:{kind:"filter_string",expression:{kind:"field_reference",name:"carrier"},filter:"WN"}}]}}}},e.thingy3={definition:{kind:"arrow",source:{kind:"source_reference",name:"flights"},view:{kind:"refinement",base:{kind:"view_reference",name:"by_carrier"},refinement:{kind:"segment",operations:[{kind:"group_by",field:{expression:{kind:"field_reference",name:"carrier"}}},{kind:"group_by",field:{expression:{kind:"field_reference",name:"foo"}}}]}}}},e.thingy3dfdf={definition:{kind:"arrow",source:{kind:"source_reference",name:"flights"},view:{kind:"refinement",base:{kind:"view_reference",name:"by_carrier"},refinement:{kind:"view_reference",name:"top10"}}}},e.thingy4asdfasdf={definition:{kind:"arrow",source:{kind:"source_reference",name:"flights"},view:{kind:"segment",operations:[{kind:"group_by",field:{expression:{kind:"field_reference",name:"carrier"}}},{kind:"group_by",field:{expression:{kind:"field_reference",name:"foo"}}}]}}},e.thingy4asdfas={definition:{kind:"arrow",source:{kind:"source_reference",name:"flights"},view:{kind:"view_reference",name:"by_carrier"}}},e.thingy4dfdsfs={definition:{kind:"arrow",source:{kind:"source_reference",name:"flights"},view:{kind:"refinement",base:{kind:"view_reference",name:"by_carrier"},refinement:{kind:"segment",operations:[{kind:"limit",limit:10}]}}}},e.thingy4sdfsd={definition:{kind:"arrow",source:{kind:"source_reference",name:"flights"},view:{kind:"segment",operations:[{kind:"group_by",field:{expression:{kind:"field_reference",name:"carrier"}}},{kind:"limit",limit:10}]}}},e.thingy4sddfdfsd={definition:{kind:"arrow",source:{kind:"source_reference",name:"flights"},view:{kind:"segment",operations:[]}}}})(W1);function Y1(e,t){if(t==="string")return e.text();if(t==="number")return e.numeric();if(t==="boolean")return e.text()==="true";const n=W1.MALLOY_INTERFACE_TYPES[t];if(n===void 0)throw new Error(`Unknown Malloy interface type ${t}`);if(n.type==="enum"){const r=e.text();if(r===void 0)throw new Error(`Missing value for enum ${t}`);if(r in n.values)return r;throw new Error(`Unknown value ${r} for enum ${t}`)}else if(n.type==="struct"){const r={};for(const[i,s]of Object.entries(n.fields)){const a=e.tag(i);if(a===void 0){if(s.optional)continue;throw new Error(`Missing value for key ${i} of type ${s}`)}if(s.array){const o=[],l=a.array();if(l===void 0)throw new Error(`Missing array value for key ${i} of type ${s}`);for(const u of l)o.push(Y1(u,s.type));r[i]=o}else{const o=Y1(a,s.type);o!=null&&(r[i]=o)}}return r}else{const r=e.text("kind");if(r===void 0)throw new Error(`Missing kind for union ${t}`);const i=n.options[r];if(i===void 0)throw new Error(`Unknown kind ${r} for union ${t}`);const s=Y1(e,i);return{kind:r,...s}}}function Sce(e){return e.type.kind==="array_type"}function kce(e){return e.type.kind==="array_type"&&e.type.element_type.kind==="record_type"}function Ece(e){return e.type.kind==="record_type"}function _ce(e){return e.type.kind==="number_type"}function Cce(e){return e.type.kind==="date_type"}function Ace(e){return e.type.kind==="json_type"}function Mce(e){return e.type.kind==="string_type"}function Fce(e){return e.type.kind==="timestamp_type"||e.type.kind==="timestamptz_type"}function Tce(e){return e.type.kind==="boolean_type"}function Dce(e){return e.type.kind==="sql_native_type"}const Oce=["link","image","cell","list","list_detail","bar_chart","line_chart","dashboard","scatter_chart","shape_map","segment_map","big_value"];function Rce({field:e,tagOverride:t}){var c;const n=(c=e.getPlugins().at(0))==null?void 0:c.name;if(n)return n;const r=j1(t??e.tag),i=r.text("viz");if(i){if(i==="table")return"table";if(i==="dashboard")return"dashboard";if(Xue.includes(i))return"chart"}const s=r.properties??{},a=Object.keys(s).reverse();for(const f of a)if(Oce.includes(f)&&!s[f].deleted)return["list","list_detail"].includes(f)?"list":["bar_chart","line_chart"].includes(f)?"chart":f;const o=e.parent;return e instanceof Uo&&o&&o.renderAs()==="chart"?"none":e instanceof eu||e instanceof Uo?"table":"cell"}function Nce(e,t="# "){return c7(e.annotations,t)}function IO(e){try{return Y1(e,"Expression")}catch{return}}function zO(e){try{return Y1(e,"LiteralValue")}catch{return}}function Ice(e){if(e instanceof eu)return Lr.RepeatedRecord;if(e instanceof Md)return Lr.Array;if(e instanceof Uo)return Lr.Record;if(e instanceof X1)return Lr.Number;if(e instanceof Z1)return Lr.Date;if(e instanceof K1)return Lr.JSON;if(e instanceof Ad)return Lr.String;if(e instanceof Q1)return Lr.Timestamp;if(e instanceof e0)return Lr.Boolean;if(e instanceof J1)return Lr.SQLNative;throw new Error("Unknown field type")}class Bo{constructor(t,n,r=!1){this.field=t,this.parent=n,this.valueSet=new Set,this.plugins=[],this._renderAs="",this.tag=Yce(this.field.annotations),this.metadataTag=r?this.tag:Nce(this.field,"#(malloy) "),this.path=n?[...n.path,t.name]:[]}getPlugins(){return this.plugins}setPlugins(t){this.plugins=t,this._renderAs=Rce({field:this})}renderAs(){return this._renderAs}isRoot(){return this.path.length===0}root(){if(this.parent)return this.parent.root();if(this.isRoot())return this;throw new Error("Root field was not an instance of RootField")}getEffectiveQueryTimezone(){const t=this.metadataTag.text("query_timezone");return t||(this.parent?this.parent.getEffectiveQueryTimezone():this.root().queryTimezone)}get drillStableExpression(){const t=this.metadataTag.tag("drill_expression");if(t!==void 0)return IO(t)}get sourceName(){return this.metadataTag.text("source","name")??"__source__"}get sourceArguments(){const t=this.metadataTag.array("source","parameters");if(t===void 0)return;const n=[];for(const r of t){const i=r.text("name"),s=r.tag("value");if(i===void 0||s===void 0)continue;const a=zO(s);a!==void 0&&n.push({name:i,value:a})}if(n.length!==0)return n}get name(){return this.field.name}fieldAt(t){return typeof t=="string"?this.fieldAtPath(JSON.parse(t)):this.fieldAtPath(t)}getParentRecord(t){let n=this.asField();for(;n&&t>0;){for(n=n.parent;n!=null&&n.isArray();)n=n.parent;t--}if(!(n!=null&&n.isRecord()))throw new Error(`Parent ${t} levels up was not a record`);return n}get key(){return JSON.stringify(this.path)}fieldAtPath(t){if(t.length===0)return this.asField();throw new Error(`${this.constructor.name} cannot contain fields`)}registerNullValue(){this.valueSet.add(jt)}get drillFilters(){return(this.metadataTag.array("drill_filters")??[]).map(t=>{if(t.text("filter_view"))return;const n=this.getStableDrillFilter(t);return n===void 0?t.text("code"):W1.filterToMalloy(n)}).filter(Kce)}getStableDrillFilter(t){const n=t.text("kind"),r=t.tag("expression");if(r===void 0)return;const i=IO(r);if(!(n===void 0||i===void 0)){if(n==="filter_expression"){const s=t.text("filter_expression");return s===void 0?void 0:{kind:"filter_string",expression:i,filter:s}}else if(n==="literal_equality"){const s=t.tag("value");if(s===void 0)return;const a=zO(s);if(a!==void 0)return{kind:"literal_equality",expression:i,value:a}}}}get stableDrillFilters(){const t=[],n=this.metadataTag.array("drill_filters");for(const r of n??[]){if(r.text("filter_view"))continue;const i=this.getStableDrillFilter(r);if(i===void 0)return;t.push(i)}return t}get referenceId(){return this.metadataTag.text("reference_id")}escapeIdentifier(t){return t.replace(/\\/g,"\\\\").replace("`","\\`")}identifierCode(){return this.name.match(/^[A-Za-z_][0-9A-Za-z_]*$/)?this.name:`\`${this.escapeIdentifier(this.name)}\``}drillExpression(){return this.metadataTag.text("drill_expression")??this.identifierCode()}wasDimension(){return!this.wasCalculation()}wasCalculation(){return this.metadataTag.has("calculation")}isHidden(){return this.tag.has("hidden")}get minNumber(){}get maxNumber(){}get maxString(){}asField(){if(this instanceof Md||this instanceof eu||this instanceof Uo||this instanceof X1||this instanceof Z1||this instanceof K1||this instanceof Ad||this instanceof Q1||this instanceof e0||this instanceof J1)return this;throw new Error("Not a field")}isArray(){return this instanceof Md}isRepeatedRecord(){return this instanceof eu}isRecord(){return this instanceof Uo}isNumber(){return this instanceof X1}isBoolean(){return this instanceof e0}isString(){return this instanceof Ad}isRecordOrRepeatedRecord(){return this.isRecord()||this.isRepeatedRecord()}isDate(){return this instanceof Z1}isTimestamp(){return this instanceof Q1}isTime(){return this.isDate()||this.isTimestamp()}isSQLNative(){return this instanceof J1}isJSON(){return this instanceof K1}isBasic(){return!this.isNest()}isNest(){return this.isRecord()||this.isRepeatedRecord()}getLocationInParent(){return this.parent&&"fields"in this.parent?this.parent.fields.findIndex(t=>t===this)??-1:-1}isLastChild(){const t=this.parent;return t===void 0?!0:"fields"in t?this.getLocationInParent()===t.fields.length:!0}isFirstChild(){return this.getLocationInParent()===0}pathTo(t){const n=this.path,r=t.path,i=n.length;let s=0;for(;n[s];){if(n[s]!==r[s])throw new Error("Tried to get path from parent field to child field, but parent field is not a parent of child field.");s++}return JSON.stringify(r.slice(i))}}function bc(e,t,n){if(t==null)return jt;const r=n??e.tag;if(r.has("currency"))return zce(r,t);if(r.has("percent"))return Io.format("#,##0.00%",t);if(r.has("duration")){const s=r.text("duration")??ct.Seconds;return Qce(e,t,{durationUnit:s})??t.toLocaleString()}return r.has("number")?Pce(r,t):t.toLocaleString()}function PO(e){const t=e.text("currency"),n=t?nfe(t):null;let r="$",i,s,a="lower";if(n)r=n.symbol,i=n.scale,s=n.decimals;else{switch(t){case"euro":r="€";break;case"pound":r="£";break;case"usd":default:r="$";break}const o=e.text("currency","scale");i=h7(o),s=e.numeric("currency","decimals")??void 0;const l=e.text("currency","suffix");l?a=l:i&&(a="letter")}return{symbol:r,scale:i,decimals:s,suffixFormat:a}}function zce(e,t){const{symbol:n,scale:r,decimals:i,suffixFormat:s}=PO(e);if(r){const a=Td(t,{scale:r,decimals:i??2,suffix:s});return`${n}${a}`}else{const a=i??2,o=a>0?`${n}#,##0.${"0".repeat(a)}`:`${n}#,##0`;return Io.format(o,t)}}function Pce(e,t){const n=e.text("number"),r=n?JO(n):null;if(r){if(r.isId)return String(t);if(r.scale)return Td(t,{scale:r.scale,decimals:r.decimals??2,suffix:"lower"});if(r.decimals!==void 0)return Number(t.toFixed(r.decimals)).toLocaleString("en-US",{minimumFractionDigits:0,maximumFractionDigits:r.decimals})}const i=e.text("number","scale"),s=h7(i);if(s){const a=e.numeric("number","decimals")??2,l=e.text("number","suffix")??"letter";return Td(t,{scale:s,decimals:a,suffix:l})}return n==="big"?d7(t):n?Io.format(n,t):Io.format("#",t)}function Cd(e){const t=e.startsWith("-"),r=(t?e.slice(1):e).replace(/\B(?=(\d{3})+(?!\d))/g,",");return t?`-${r}`:r}function Lce(e,t){const{symbol:n,scale:r,decimals:i,suffixFormat:s}=PO(e);if(r){const o=Number(t),l=Td(o,{scale:r,decimals:i??2,suffix:s});return`${n}${l}`}const a=i??2;return a===0?`${n}${Cd(t)}`:`${n}${Cd(t)}.${"0".repeat(a)}`}function Bce(e,t,n){if(t==null)return jt;const r=n??e.tag;return r.has("currency")?Lce(r,t):r.has("percent")||r.has("duration")?bc(e,Number(t),r):r.has("number")?qce(r,t):Cd(t)}function qce(e,t){const n=e.text("number"),r=n?JO(n):null;if(r){if(r.isId)return t;if(r.scale)return Td(Number(t),{scale:r.scale,decimals:r.decimals??2,suffix:"lower"});if(r.decimals!==void 0)return r.decimals===0?Cd(t):`${Cd(t)}.${"0".repeat(r.decimals)}`}const i=e.text("number","scale"),s=h7(i);if(s){const a=e.numeric("number","decimals")??2,l=e.text("number","suffix")??"letter";return Td(Number(t),{scale:s,decimals:a,suffix:l})}return n==="big"?d7(Number(t)):n?Io.format(n,Number(t)):Cd(t)}function LO(e,t){return e.stringValue!==void 0?Bce(e.field,e.stringValue,t):bc(e.field,e.value,t)}function qo(e,t,n={},r){if(t==null)return jt;const i=r??e.tag;if(i.has("number")){const o=i.text("number");if(o)try{return Io.format(o,t)}catch{console.warn(`Invalid date format "${o}" for field ${e.name}, falling back to default formatting`)}}const s=n.isDate?void 0:n.timezone??e.getEffectiveQueryTimezone(),a={...n,timezone:s};return ZO(t,a)}class X1 extends Bo{constructor(t,n){super(t,n),this.field=t,this.min=void 0,this.max=void 0,this._maxString=void 0}registerValue(t){this.valueSet.add(t),(this.max===void 0||t>this.max)&&(this.max=t),(this.min===void 0||t<this.min)&&(this.min=t);const n=t.toString();(this._maxString===void 0||n.length>this._maxString.length)&&(this._maxString=n)}fieldAtPath(t){if(t.length===0)return this.asField();throw new Error("NumberField cannot contain fields")}get minNumber(){return this.min}get maxNumber(){return this.max}get maxString(){return this._maxString}}class Z1 extends Bo{constructor(t,n){super(t,n),this.field=t,this.min=void 0,this.max=void 0,this._maxString=void 0}get timeframe(){return this.field.type.timeframe}registerValue(t){const n=Number(t);this.valueSet.add(n),(this.max===void 0||t>this.max)&&(this.max=t),(this.min===void 0||t<this.min)&&(this.min=t);const r=qo(this.asField(),t,{isDate:!0,timeframe:this.timeframe}).toString();(this._maxString===void 0||r.length>this._maxString.length)&&(this._maxString=r)}get minValue(){return this.min}get maxValue(){return this.max}get maxString(){return this._maxString}get minNumber(){return this.min!==void 0?Number(this.min):void 0}get maxNumber(){return this.max!==void 0?Number(this.max):void 0}}class Q1 extends Bo{constructor(t,n){super(t,n),this.field=t,this.min=void 0,this.max=void 0,this._maxString=void 0}get timeframe(){return this.field.type.timeframe}registerValue(t){const n=Number(t);this.valueSet.add(n),(this.max===void 0||t>this.max)&&(this.max=t),(this.min===void 0||t<this.min)&&(this.min=t);const r=qo(this.asField(),t,{isDate:!1,timeframe:this.timeframe}).toString();(this._maxString===void 0||r.length>this._maxString.length)&&(this._maxString=r)}get minValue(){return this.min}get maxValue(){return this.max}get maxString(){return this._maxString}}class Ad extends Bo{constructor(t,n){super(t,n),this.field=t,this.min=void 0,this.max=void 0,this._maxString=void 0}registerValue(t){this.valueSet.add(t),(this.max===void 0||t>this.max)&&(this.max=t),(this.min===void 0||t<this.min)&&(this.min=t),(this._maxString===void 0||t.length>this._maxString.length)&&(this._maxString=t)}get minValue(){return this.min}get maxValue(){return this.max}get maxString(){return this._maxString}}class J1 extends Bo{constructor(t,n){super(t,n),this.field=t}}class K1 extends Bo{constructor(t,n){super(t,n),this.field=t}}class e0 extends Bo{constructor(t,n){super(t,n),this.field=t,this._maxString=void 0}get maxString(){return this._maxString}registerValue(t){this.valueSet.add(t);const n=String(t);(this._maxString===void 0||this._maxString.length<n.length)&&(this._maxString=n)}}class Md extends Bo{constructor(t,n,r=!1){super(t,n,r),this.field=t,this.maxUniqueFieldValueCounts=new Map}get elementField(){if(!this._elementField){const t={name:"element",type:this.field.type.element_type};this._elementField=Fd.from(t,this)}return this._elementField}get isDrillable(){return this.metadataTag.has("drillable")}}class eu extends Md{constructor(t,n){super(t,n),this.field=t,this.maxRecordCount=0,this._fieldsWithOrder=void 0;const r=this.field.type.element_type;if(r.kind!=="record_type")throw new Error("Expected element_type of RepeatedRecordField to be a record");this.fields=r.fields.map(s=>Fd.from(s,this)),this.fieldsByName=Object.fromEntries(this.fields.map(s=>[s.name,s]));const i={name:"record",type:this.field.type.element_type};this.nestedRecordField=new Uo(i,this,{fields:this.fields,skipTagParsing:!0})}get elementField(){return this._elementField||(this._elementField=this.nestedRecordField),this._elementField}fieldAtPath(t){if(t.length===0)return this.asField();{const[n,...r]=t,i=this.fieldsByName[n];if(i===void 0)throw new Error(`No such field ${n} in ${this.path}`);return i.fieldAtPath(r)}}registerRecordCount(t){this.maxRecordCount=Math.max(t,this.maxRecordCount)}registerValueSetSize(t,n){this.maxUniqueFieldValueCounts.set(t,Math.max(this.maxUniqueFieldValueCounts.get(t)??0,n))}get fieldsWithOrder(){var t;if(!this._fieldsWithOrder){const n=this.metadataTag.tag("ordered_by"),r=(n&&((t=n.array())==null?void 0:t.map(s=>{const a=Object.keys(s.properties??{})[0],o=s.text(a);return{field:this.fieldAt(a),dir:o}})))??[],i=new Set(r.map(s=>s.field.name));this._fieldsWithOrder=[...r,...this.fields.filter(s=>!i.has(s.name)).map(s=>({field:s,dir:"asc"}))]}return this._fieldsWithOrder}}class Uce extends eu{constructor(t,n){super(t,void 0),this.field=t,this.modelTag=n.modelTag,this.queryTimezone=n.queryTimezone}}class Uo extends Bo{constructor(t,n,r){super(t,n,r==null?void 0:r.skipTagParsing),this.field=t,this.maxUniqueFieldValueCounts=new Map,this._fieldsWithOrder=void 0,r!=null&&r.fields?(this.fields=r.fields,this.fieldsByName=Object.fromEntries(this.fields.map(i=>[i.name,i]))):(this.fields=t.type.fields.map(i=>Fd.from(i,this)),this.fieldsByName=Object.fromEntries(this.fields.map(i=>[i.name,i])))}fieldAtPath(t){if(t.length===0)return this.asField();{const[n,...r]=t,i=this.fieldsByName[n];if(i===void 0)throw new Error(`No such field ${n} in ${this.path}`);return i.fieldAtPath(r)}}get fieldsWithOrder(){return this._fieldsWithOrder===void 0&&(this._fieldsWithOrder=[...this.fields.map(t=>({field:t,dir:"asc"}))]),this._fieldsWithOrder}}const Fd={from(e,t){if(kce(e))return new eu(e,t);if(Sce(e))return new Md(e,t);if(Ece(e))return new Uo(e,t);if(Tce(e))return new e0(e,t);if(Ace(e))return new K1(e,t);if(Cce(e))return new Z1(e,t);if(Fce(e))return new Q1(e,t);if(Mce(e))return new Ad(e,t);if(_ce(e))return new X1(e,t);if(Dce(e))return new J1(e,t);throw new Error(`Unknown field type ${e.type.kind}`)},isNestField(e){return e instanceof eu||e instanceof Uo},pathFromString(e){return JSON.parse(e)},pathToString(e){return JSON.stringify(e)}};function jce(e){let t=e;for(;t;){const n=t.field;if(n.isArray()&&!n.isDrillable)return!1;t=t.parent}return!0}function BO(e){const t=K6(e);if(t===void 0)return;const n=t.map(i=>({kind:"drill",...i})),r=e.field.root();return{definition:{kind:"arrow",source:{kind:"source_reference",name:r.sourceName,parameters:r.sourceArguments},view:{kind:"segment",operations:[...n]}}}}function K6(e){let t=e;const n=[];for(;t;){const{field:r}=t;if(r.isArray()){const i=r.stableDrillFilters;if(i===void 0)return;n.unshift(...i.map(s=>({kind:"drill",filter:s})))}if(r.isRecord()){const i=r.fields.filter(a=>a.isBasic()&&a.wasDimension()),s=[];for(const a of i){const l=t.column(a.name).literalValue;if(l===void 0)continue;const u=a.drillStableExpression;if(u===void 0)return;const c={kind:"literal_equality",expression:u,value:l};s.push({filter:c})}n.unshift(...s)}t=t.parent}return n}function qO(e){let t=e;const n=[];for(;t;){const r=t.field;if(r.isArray()){const i=r.drillFilters;n.unshift(...i.map(s=>({where:s})))}if(r.isRecord()){const i=r.fields.filter(a=>a.isBasic()&&a.wasDimension()),s=[];for(const a of i){const o=t.column(a.name),l=o.literalValue;if(l===void 0)continue;const u=a.drillStableExpression;if(u!==void 0){const c={kind:"literal_equality",expression:u,value:l};s.push({where:W1.filterToMalloy(c)})}else{const c=a.drillExpression();s.push({where:`${c} = ${QO(o)}`})}}n.unshift(...s)}t=t.parent}return n}function UO(e){return qO(e).map(n=>{if("where"in n)return n.where;const r=QO(n.value);return`${n.field.drillExpression()} = ${r}`})}function Wce(e){const t=qO(e),n=[];for(const r of t)"where"in r?n.push(r):(r.value.isNull()||r.value.isTime()||r.value.isString()||r.value.isNumber()||r.value.isBoolean())&&n.push({field:r.field,value:r.value.value});return n}function jO(e){var n;if(((n=K6(e))==null?void 0:n.length)===0)return`run: ${e.field.root().sourceName} -> { select: * }`;const t=BO(e);if(t!==void 0)return W1.queryToMalloy(t)+" + { select: * }"}function Vce(e){const t=jO(e);if(t!==void 0)return t;const n=UO(e);let r=`run: ${e.field.root().sourceName} ->`;return n.length>0&&(r+=` {
|
|
58
58
|
drill:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@malloydata/render",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.341",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/module/index.umd.js",
|
|
6
6
|
"types": "dist/module/index.d.ts",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"generate-flow": "ts-node ../../scripts/gen-flow.ts"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@malloydata/malloy-interfaces": "0.0.
|
|
33
|
-
"@malloydata/malloy-tag": "0.0.
|
|
32
|
+
"@malloydata/malloy-interfaces": "0.0.341",
|
|
33
|
+
"@malloydata/malloy-tag": "0.0.341",
|
|
34
34
|
"@tanstack/solid-virtual": "^3.10.4",
|
|
35
35
|
"lodash": "^4.17.20",
|
|
36
36
|
"luxon": "^3.5.0",
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"vega-lite": "^5.2.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@malloydata/
|
|
46
|
-
"@malloydata/
|
|
45
|
+
"@malloydata/db-duckdb": "0.0.341",
|
|
46
|
+
"@malloydata/malloy": "0.0.341",
|
|
47
47
|
"@storybook/addon-essentials": "^8.6.15",
|
|
48
48
|
"@storybook/addon-interactions": "^8.6.15",
|
|
49
49
|
"@storybook/addon-links": "^8.6.15",
|