spl2dql 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import{i as e}from"./jsx-runtime-Wy9s6hX0.js";import{x as t}from"./index-BO3AM1fZ.js";var n=Symbol.for(`yaml.alias`),r=Symbol.for(`yaml.document`),i=Symbol.for(`yaml.map`),a=Symbol.for(`yaml.pair`),o=Symbol.for(`yaml.scalar`),s=Symbol.for(`yaml.seq`),c=Symbol.for(`yaml.node.type`),l=e=>!!e&&typeof e==`object`&&e[c]===n,u=e=>!!e&&typeof e==`object`&&e[c]===r,d=e=>!!e&&typeof e==`object`&&e[c]===i,f=e=>!!e&&typeof e==`object`&&e[c]===a,p=e=>!!e&&typeof e==`object`&&e[c]===o,m=e=>!!e&&typeof e==`object`&&e[c]===s;function h(e){if(e&&typeof e==`object`)switch(e[c]){case i:case s:return!0}return!1}function g(e){if(e&&typeof e==`object`)switch(e[c]){case n:case i:case o:case s:return!0}return!1}var _=e=>(p(e)||h(e))&&!!e.anchor,v=Symbol(`break visit`),y=Symbol(`skip children`),b=Symbol(`remove node`);function x(e,t){let n=C(t);u(e)?S(null,e.contents,n,Object.freeze([e]))===b&&(e.contents=null):S(null,e,n,Object.freeze([]))}x.BREAK=v,x.SKIP=y,x.REMOVE=b;function S(e,t,n,r){let i=ee(e,t,n,r);if(g(i)||f(i))return w(e,r,i),S(e,i,n,r);if(typeof i!=`symbol`){if(h(t)){r=Object.freeze(r.concat(t));for(let e=0;e<t.items.length;++e){let i=S(e,t.items[e],n,r);if(typeof i==`number`)e=i-1;else if(i===v)return v;else i===b&&(t.items.splice(e,1),--e)}}else if(f(t)){r=Object.freeze(r.concat(t));let e=S(`key`,t.key,n,r);if(e===v)return v;e===b&&(t.key=null);let i=S(`value`,t.value,n,r);if(i===v)return v;i===b&&(t.value=null)}}return i}function C(e){return typeof e==`object`&&(e.Collection||e.Node||e.Value)?Object.assign({Alias:e.Node,Map:e.Node,Scalar:e.Node,Seq:e.Node},e.Value&&{Map:e.Value,Scalar:e.Value,Seq:e.Value},e.Collection&&{Map:e.Collection,Seq:e.Collection},e):e}function ee(e,t,n,r){if(typeof n==`function`)return n(e,t,r);if(d(t))return n.Map?.(e,t,r);if(m(t))return n.Seq?.(e,t,r);if(f(t))return n.Pair?.(e,t,r);if(p(t))return n.Scalar?.(e,t,r);if(l(t))return n.Alias?.(e,t,r)}function w(e,t,n){let r=t[t.length-1];if(h(r))r.items[e]=n;else if(f(r))e===`key`?r.key=n:r.value=n;else if(u(r))r.contents=n;else{let e=l(r)?`alias`:`scalar`;throw Error(`Cannot replace node with ${e} parent`)}}var T={"!":`%21`,",":`%2C`,"[":`%5B`,"]":`%5D`,"{":`%7B`,"}":`%7D`},te=e=>e.replace(/[!,[\]{}]/g,e=>T[e]),E=class e{constructor(t,n){this.docStart=null,this.docEnd=!1,this.yaml=Object.assign({},e.defaultYaml,t),this.tags=Object.assign({},e.defaultTags,n)}clone(){let t=new e(this.yaml,this.tags);return t.docStart=this.docStart,t}atDocument(){let t=new e(this.yaml,this.tags);switch(this.yaml.version){case`1.1`:this.atNextDocument=!0;break;case`1.2`:this.atNextDocument=!1,this.yaml={explicit:e.defaultYaml.explicit,version:`1.2`},this.tags=Object.assign({},e.defaultTags)}return t}add(t,n){this.atNextDocument&&=(this.yaml={explicit:e.defaultYaml.explicit,version:`1.1`},this.tags=Object.assign({},e.defaultTags),!1);let r=t.trim().split(/[ \t]+/),i=r.shift();switch(i){case`%TAG`:{if(r.length!==2&&(n(0,`%TAG directive should contain exactly two parts`),r.length<2))return!1;let[e,t]=r;return this.tags[e]=t,!0}case`%YAML`:{if(this.yaml.explicit=!0,r.length!==1)return n(0,`%YAML directive should contain exactly one part`),!1;let[e]=r;if(e===`1.1`||e===`1.2`)return this.yaml.version=e,!0;{let t=/^\d+\.\d+$/.test(e);return n(6,`Unsupported YAML version ${e}`,t),!1}}default:return n(0,`Unknown directive ${i}`,!0),!1}}tagName(e,t){if(e===`!`)return`!`;if(e[0]!==`!`)return t(`Not a valid tag: ${e}`),null;if(e[1]===`<`){let n=e.slice(2,-1);return n===`!`||n===`!!`?(t(`Verbatim tags aren't resolved, so ${e} is invalid.`),null):(e[e.length-1]!==`>`&&t(`Verbatim tags must end with a >`),n)}let[,n,r]=e.match(/^(.*!)([^!]*)$/s);r||t(`The ${e} tag has no suffix`);let i=this.tags[n];if(i)try{return i+decodeURIComponent(r)}catch(e){return t(String(e)),null}return n===`!`?e:(t(`Could not resolve tag: ${e}`),null)}tagString(e){for(let[t,n]of Object.entries(this.tags))if(e.startsWith(n))return t+te(e.substring(n.length));return e[0]===`!`?e:`!<${e}>`}toString(e){let t=this.yaml.explicit?[`%YAML ${this.yaml.version||`1.2`}`]:[],n=Object.entries(this.tags),r;if(e&&n.length>0&&g(e.contents)){let t={};x(e.contents,(e,n)=>{g(n)&&n.tag&&(t[n.tag]=!0)}),r=Object.keys(t)}else r=[];for(let[i,a]of n)i===`!!`&&a===`tag:yaml.org,2002:`||e&&!r.some(e=>e.startsWith(a))||t.push(`%TAG ${i} ${a}`);return t.join(`
1
+ import{i as e}from"./jsx-runtime-Wy9s6hX0.js";import{x as t}from"./index-Dox0eScg.js";var n=Symbol.for(`yaml.alias`),r=Symbol.for(`yaml.document`),i=Symbol.for(`yaml.map`),a=Symbol.for(`yaml.pair`),o=Symbol.for(`yaml.scalar`),s=Symbol.for(`yaml.seq`),c=Symbol.for(`yaml.node.type`),l=e=>!!e&&typeof e==`object`&&e[c]===n,u=e=>!!e&&typeof e==`object`&&e[c]===r,d=e=>!!e&&typeof e==`object`&&e[c]===i,f=e=>!!e&&typeof e==`object`&&e[c]===a,p=e=>!!e&&typeof e==`object`&&e[c]===o,m=e=>!!e&&typeof e==`object`&&e[c]===s;function h(e){if(e&&typeof e==`object`)switch(e[c]){case i:case s:return!0}return!1}function g(e){if(e&&typeof e==`object`)switch(e[c]){case n:case i:case o:case s:return!0}return!1}var _=e=>(p(e)||h(e))&&!!e.anchor,v=Symbol(`break visit`),y=Symbol(`skip children`),b=Symbol(`remove node`);function x(e,t){let n=C(t);u(e)?S(null,e.contents,n,Object.freeze([e]))===b&&(e.contents=null):S(null,e,n,Object.freeze([]))}x.BREAK=v,x.SKIP=y,x.REMOVE=b;function S(e,t,n,r){let i=ee(e,t,n,r);if(g(i)||f(i))return w(e,r,i),S(e,i,n,r);if(typeof i!=`symbol`){if(h(t)){r=Object.freeze(r.concat(t));for(let e=0;e<t.items.length;++e){let i=S(e,t.items[e],n,r);if(typeof i==`number`)e=i-1;else if(i===v)return v;else i===b&&(t.items.splice(e,1),--e)}}else if(f(t)){r=Object.freeze(r.concat(t));let e=S(`key`,t.key,n,r);if(e===v)return v;e===b&&(t.key=null);let i=S(`value`,t.value,n,r);if(i===v)return v;i===b&&(t.value=null)}}return i}function C(e){return typeof e==`object`&&(e.Collection||e.Node||e.Value)?Object.assign({Alias:e.Node,Map:e.Node,Scalar:e.Node,Seq:e.Node},e.Value&&{Map:e.Value,Scalar:e.Value,Seq:e.Value},e.Collection&&{Map:e.Collection,Seq:e.Collection},e):e}function ee(e,t,n,r){if(typeof n==`function`)return n(e,t,r);if(d(t))return n.Map?.(e,t,r);if(m(t))return n.Seq?.(e,t,r);if(f(t))return n.Pair?.(e,t,r);if(p(t))return n.Scalar?.(e,t,r);if(l(t))return n.Alias?.(e,t,r)}function w(e,t,n){let r=t[t.length-1];if(h(r))r.items[e]=n;else if(f(r))e===`key`?r.key=n:r.value=n;else if(u(r))r.contents=n;else{let e=l(r)?`alias`:`scalar`;throw Error(`Cannot replace node with ${e} parent`)}}var T={"!":`%21`,",":`%2C`,"[":`%5B`,"]":`%5D`,"{":`%7B`,"}":`%7D`},te=e=>e.replace(/[!,[\]{}]/g,e=>T[e]),E=class e{constructor(t,n){this.docStart=null,this.docEnd=!1,this.yaml=Object.assign({},e.defaultYaml,t),this.tags=Object.assign({},e.defaultTags,n)}clone(){let t=new e(this.yaml,this.tags);return t.docStart=this.docStart,t}atDocument(){let t=new e(this.yaml,this.tags);switch(this.yaml.version){case`1.1`:this.atNextDocument=!0;break;case`1.2`:this.atNextDocument=!1,this.yaml={explicit:e.defaultYaml.explicit,version:`1.2`},this.tags=Object.assign({},e.defaultTags)}return t}add(t,n){this.atNextDocument&&=(this.yaml={explicit:e.defaultYaml.explicit,version:`1.1`},this.tags=Object.assign({},e.defaultTags),!1);let r=t.trim().split(/[ \t]+/),i=r.shift();switch(i){case`%TAG`:{if(r.length!==2&&(n(0,`%TAG directive should contain exactly two parts`),r.length<2))return!1;let[e,t]=r;return this.tags[e]=t,!0}case`%YAML`:{if(this.yaml.explicit=!0,r.length!==1)return n(0,`%YAML directive should contain exactly one part`),!1;let[e]=r;if(e===`1.1`||e===`1.2`)return this.yaml.version=e,!0;{let t=/^\d+\.\d+$/.test(e);return n(6,`Unsupported YAML version ${e}`,t),!1}}default:return n(0,`Unknown directive ${i}`,!0),!1}}tagName(e,t){if(e===`!`)return`!`;if(e[0]!==`!`)return t(`Not a valid tag: ${e}`),null;if(e[1]===`<`){let n=e.slice(2,-1);return n===`!`||n===`!!`?(t(`Verbatim tags aren't resolved, so ${e} is invalid.`),null):(e[e.length-1]!==`>`&&t(`Verbatim tags must end with a >`),n)}let[,n,r]=e.match(/^(.*!)([^!]*)$/s);r||t(`The ${e} tag has no suffix`);let i=this.tags[n];if(i)try{return i+decodeURIComponent(r)}catch(e){return t(String(e)),null}return n===`!`?e:(t(`Could not resolve tag: ${e}`),null)}tagString(e){for(let[t,n]of Object.entries(this.tags))if(e.startsWith(n))return t+te(e.substring(n.length));return e[0]===`!`?e:`!<${e}>`}toString(e){let t=this.yaml.explicit?[`%YAML ${this.yaml.version||`1.2`}`]:[],n=Object.entries(this.tags),r;if(e&&n.length>0&&g(e.contents)){let t={};x(e.contents,(e,n)=>{g(n)&&n.tag&&(t[n.tag]=!0)}),r=Object.keys(t)}else r=[];for(let[i,a]of n)i===`!!`&&a===`tag:yaml.org,2002:`||e&&!r.some(e=>e.startsWith(a))||t.push(`%TAG ${i} ${a}`);return t.join(`
2
2
  `)}};E.defaultYaml={explicit:!1,version:`1.2`},E.defaultTags={"!!":`tag:yaml.org,2002:`};function ne(e){if(/[\x00-\x19\s,[\]{}]/.test(e)){let t=`Anchor must not contain whitespace or control characters: ${JSON.stringify(e)}`;throw Error(t)}return!0}function re(e){let t=new Set;return x(e,{Value(e,n){n.anchor&&t.add(n.anchor)}}),t}function ie(e,t){for(let n=1;;++n){let r=`${e}${n}`;if(!t.has(r))return r}}function ae(e,t){let n=[],r=new Map,i=null;return{onAnchor:r=>{n.push(r),i??=re(e);let a=ie(t,i);return i.add(a),a},setAnchors:()=>{for(let e of n){let t=r.get(e);if(typeof t==`object`&&t.anchor&&(p(t.node)||h(t.node)))t.node.anchor=t.anchor;else{let t=Error(`Failed to resolve repeated object (this should not happen)`);throw t.source=e,t}}},sourceObjects:r}}function D(e,t,n,r){if(r&&typeof r==`object`){if(Array.isArray(r))for(let t=0,n=r.length;t<n;++t){let n=r[t],i=D(e,r,String(t),n);i===void 0?delete r[t]:i!==n&&(r[t]=i)}else if(r instanceof Map)for(let t of Array.from(r.keys())){let n=r.get(t),i=D(e,r,t,n);i===void 0?r.delete(t):i!==n&&r.set(t,i)}else if(r instanceof Set)for(let t of Array.from(r)){let n=D(e,r,t,t);n===void 0?r.delete(t):n!==t&&(r.delete(t),r.add(n))}else for(let[t,n]of Object.entries(r)){let i=D(e,r,t,n);i===void 0?delete r[t]:i!==n&&(r[t]=i)}}return e.call(t,n,r)}function O(e,t,n){if(Array.isArray(e))return e.map((e,t)=>O(e,String(t),n));if(e&&typeof e.toJSON==`function`){if(!n||!_(e))return e.toJSON(t,n);let r={aliasCount:0,count:1,res:void 0};n.anchors.set(e,r),n.onCreate=e=>{r.res=e,delete n.onCreate};let i=e.toJSON(t,n);return n.onCreate&&n.onCreate(i),i}return typeof e==`bigint`&&!n?.keep?Number(e):e}var oe=class{constructor(e){Object.defineProperty(this,c,{value:e})}clone(){let e=Object.create(Object.getPrototypeOf(this),Object.getOwnPropertyDescriptors(this));return this.range&&(e.range=this.range.slice()),e}toJS(e,{mapAsMap:t,maxAliasCount:n,onAnchor:r,reviver:i}={}){if(!u(e))throw TypeError(`A document argument is required`);let a={anchors:new Map,doc:e,keep:!0,mapAsMap:t===!0,mapKeyWarned:!1,maxAliasCount:typeof n==`number`?n:100},o=O(this,``,a);if(typeof r==`function`)for(let{count:e,res:t}of a.anchors.values())r(t,e);return typeof i==`function`?D(i,{"":o},``,o):o}},se=class extends oe{constructor(e){super(n),this.source=e,Object.defineProperty(this,"tag",{set(){throw Error(`Alias nodes cannot have tags`)}})}resolve(e,t){if(t?.maxAliasCount===0)throw ReferenceError(`Alias resolution is disabled`);let n;t?.aliasResolveCache?n=t.aliasResolveCache:(n=[],x(e,{Node:(e,t)=>{(l(t)||_(t))&&n.push(t)}}),t&&(t.aliasResolveCache=n));let r;for(let e of n){if(e===this)break;e.anchor===this.source&&(r=e)}if(r&&t){let{anchors:e,doc:n,maxAliasCount:i}=t,a=e.get(r);if(a||=(O(r,null,t),e.get(r)),a?.res===void 0)throw ReferenceError(`This should not happen: Alias anchor was not resolved?`);if(i>=0&&(a.count+=1,a.aliasCount===0&&(a.aliasCount=ce(n,r,e)),a.count*a.aliasCount>i))throw ReferenceError(`Excessive alias count indicates a resource exhaustion attack`)}return r}toJSON(e,t){if(!t)return{source:this.source};let n=this.resolve(t.doc,t);if(!n){let e=`Unresolved alias (the anchor must be set before the alias): ${this.source}`;throw ReferenceError(e)}return t.anchors.get(n).res}toString(e,t,n){let r=`*${this.source}`;if(e){if(ne(this.source),e.options.verifyAliasOrder&&!e.anchors.has(this.source)){let e=`Unresolved alias (the anchor must be set before the alias): ${this.source}`;throw Error(e)}if(e.implicitKey)return`${r} `}return r}};function ce(e,t,n){if(l(t)){let r=t.resolve(e),i=n&&r&&n.get(r);return i?i.count*i.aliasCount:0}if(h(t)){let r=0;for(let i of t.items){let t=ce(e,i,n);t>r&&(r=t)}return r}if(f(t)){let r=ce(e,t.key,n),i=ce(e,t.value,n);return Math.max(r,i)}return 1}var le=e=>!e||typeof e!=`function`&&typeof e!=`object`,k=class extends oe{constructor(e){super(o),this.value=e}toJSON(e,t){return t?.keep?this.value:O(this.value,e,t)}toString(){return String(this.value)}};k.BLOCK_FOLDED=`BLOCK_FOLDED`,k.BLOCK_LITERAL=`BLOCK_LITERAL`,k.PLAIN=`PLAIN`,k.QUOTE_DOUBLE=`QUOTE_DOUBLE`,k.QUOTE_SINGLE=`QUOTE_SINGLE`;var ue=`tag:yaml.org,2002:`;function de(e,t,n){if(t){let e=n.filter(e=>e.tag===t),r=e.find(e=>!e.format)??e[0];if(!r)throw Error(`Tag ${t} not found`);return r}return n.find(t=>t.identify?.(e)&&!t.format)}function A(e,t,n){if(u(e)&&(e=e.contents),g(e))return e;if(f(e)){let t=n.schema[i].createNode?.(n.schema,null,n);return t.items.push(e),t}(e instanceof String||e instanceof Number||e instanceof Boolean||typeof BigInt<`u`&&e instanceof BigInt)&&(e=e.valueOf());let{aliasDuplicateObjects:r,onAnchor:a,onTagObj:o,schema:c,sourceObjects:l}=n,d;if(r&&e&&typeof e==`object`){if(d=l.get(e),d)return d.anchor??(d.anchor=a(e)),new se(d.anchor);d={anchor:null,node:null},l.set(e,d)}t?.startsWith(`!!`)&&(t=ue+t.slice(2));let p=de(e,t,c.tags);if(!p){if(e&&typeof e.toJSON==`function`&&(e=e.toJSON()),!e||typeof e!=`object`){let t=new k(e);return d&&(d.node=t),t}p=e instanceof Map?c[i]:Symbol.iterator in Object(e)?c[s]:c[i]}o&&(o(p),delete n.onTagObj);let m=p?.createNode?p.createNode(n.schema,e,n):typeof p?.nodeClass?.from==`function`?p.nodeClass.from(n.schema,e,n):new k(e);return t?m.tag=t:p.default||(m.tag=p.tag),d&&(d.node=m),m}function fe(e,t,n){let r=n;for(let e=t.length-1;e>=0;--e){let n=t[e];if(typeof n==`number`&&Number.isInteger(n)&&n>=0){let e=[];e[n]=r,r=e}else r=new Map([[n,r]])}return A(r,void 0,{aliasDuplicateObjects:!1,keepUndefined:!1,onAnchor:()=>{throw Error(`This should not happen, please report a bug.`)},schema:e,sourceObjects:new Map})}var j=e=>e==null||typeof e==`object`&&!!e[Symbol.iterator]().next().done,pe=class extends oe{constructor(e,t){super(e),Object.defineProperty(this,"schema",{value:t,configurable:!0,enumerable:!1,writable:!0})}clone(e){let t=Object.create(Object.getPrototypeOf(this),Object.getOwnPropertyDescriptors(this));return e&&(t.schema=e),t.items=t.items.map(t=>g(t)||f(t)?t.clone(e):t),this.range&&(t.range=this.range.slice()),t}addIn(e,t){if(j(e))this.add(t);else{let[n,...r]=e,i=this.get(n,!0);if(h(i))i.addIn(r,t);else if(i===void 0&&this.schema)this.set(n,fe(this.schema,r,t));else throw Error(`Expected YAML collection at ${n}. Remaining path: ${r}`)}}deleteIn(e){let[t,...n]=e;if(n.length===0)return this.delete(t);let r=this.get(t,!0);if(h(r))return r.deleteIn(n);throw Error(`Expected YAML collection at ${t}. Remaining path: ${n}`)}getIn(e,t){let[n,...r]=e,i=this.get(n,!0);return r.length===0?!t&&p(i)?i.value:i:h(i)?i.getIn(r,t):void 0}hasAllNullValues(e){return this.items.every(t=>{if(!f(t))return!1;let n=t.value;return n==null||e&&p(n)&&n.value==null&&!n.commentBefore&&!n.comment&&!n.tag})}hasIn(e){let[t,...n]=e;if(n.length===0)return this.has(t);let r=this.get(t,!0);return h(r)?r.hasIn(n):!1}setIn(e,t){let[n,...r]=e;if(r.length===0)this.set(n,t);else{let e=this.get(n,!0);if(h(e))e.setIn(r,t);else if(e===void 0&&this.schema)this.set(n,fe(this.schema,r,t));else throw Error(`Expected YAML collection at ${n}. Remaining path: ${r}`)}}},me=e=>e.replace(/^(?!$)(?: $)?/gm,`#`);function M(e,t){return/^\n+$/.test(e)?e.substring(1):t?e.replace(/^(?! *$)/gm,t):e}var N=(e,t,n)=>e.endsWith(`
3
3
  `)?M(n,t):n.includes(`
4
4
  `)?`
@@ -1,5 +1,5 @@
1
1
  const e=e=>({k:`str`,v:e}),t=e=>({k:`num`,v:String(e)}),n=e=>({k:`bool`,v:e}),r=()=>({k:`null`}),i=e=>({k:`field`,name:e}),a=e=>({k:`ident`,v:e}),o=e=>({k:`time`,v:e}),s=e=>({k:`dpl`,v:e}),c=e=>({k:`raw`,text:e}),l=(e,t)=>t?{k:`var`,name:e,mod:t}:{k:`var`,name:e},u=e=>({k:`sub`,q:{commands:e}}),d=e=>({k:`block`,items:e}),f=(e,t)=>({k:`assign`,name:e,e:t}),p=(e,t)=>({k:`dir`,e,dir:t}),m=e=>({k:`un`,op:`not`,e}),h=e=>({k:`un`,op:`-`,e}),g=(e,t,n)=>({k:`bin`,op:e,l:t,r:n}),_=(e,t)=>t===void 0?{k:`index`,e}:{k:`index`,e,key:t},v=(e,t)=>({k:`align`,e,unit:t}),y=e=>({kind:`pos`,value:e}),b=(e,t)=>({kind:`named`,name:e,value:t});function x(e,...t){return{k:`call`,fn:e,args:t.map(T)}}function S(e,...t){return{name:e,args:t.map(T)}}function C(e,t){return{name:e,args:t.map(T)}}function w(e,t){return{k:`call`,fn:e,args:t.map(T)}}function T(e){return`kind`in e?e:{kind:`pos`,value:e}}function ee(e){let t;for(let n of e)t=t?g(`and`,t,n):n;return t}function te(e){let t;for(let n of e)t=t?g(`or`,t,n):n;return t}function ne(e){return JSON.parse(JSON.stringify(e))}const re=1e6,ie=1e6,ae=5e6,oe=`error`,E=`warning`,se=`info`;function D(e,t,n,r){return{code:e,severity:t,title:n,hint:r}}const ce=[D(`SPL1001`,oe,`This part of the search could not be read.`,`Check for an unterminated string or an unbalanced bracket.`),D(`SPL1002`,oe,`The search or one of its stages is empty.`,`Remove the empty stage or the extra pipe.`),D(`SPL1003`,oe,`The command's arguments could not be read.`,`Compare the stage with Splunk's Search Reference for this command.`),D(`SPL1004`,oe,`An expression could not be read.`,`Check operators, parentheses and quotes in the expression.`),D(`SPL1005`,oe,`A macro could not be expanded.`,`Check the macro definition in the mapping file for cycles and the number of arguments.`),D(`SPL1006`,oe,`The search is too large or too deeply nested to translate.`,`Split the search, or reduce nesting of subsearches and parentheses.`),D(`SPL1007`,oe,`The search has no data source DQL can start from.`,`Start the search with an index, a lookup or another generating command.`),D(`SPL1008`,oe,`The translator hit an internal problem with this search.`,`Please report the search (with sensitive values removed) so it can be fixed.`),D(`SPL2001`,E,`This command is not known to the translator.`,`If it is a custom command, rewrite this stage by hand.`),D(`SPL2002`,E,`This command has no DQL equivalent.`,`Rewrite this stage by hand; the rest of the query is still translated.`),D(`SPL2003`,E,`An argument or option is not supported.`,`Check whether the option matters for your result.`),D(`SPL2004`,E,`This eval function has no DQL equivalent.`,`Rewrite the expression by hand.`),D(`SPL2005`,E,`This aggregation function has no DQL equivalent.`,`Rewrite the aggregation by hand or remove it.`),D(`SPL2006`,E,`This regular expression cannot be converted to a Dynatrace pattern.`,`Write the parse pattern by hand.`),D(`SPL2007`,E,`This subsearch form cannot be translated.`,`Rewrite the subsearch as a join or a filter by hand.`),D(`SPL2008`,E,`This command writes data or sends something; it was dropped.`,`Recreate the side effect in Dynatrace (workflow, lookup upload) if you still need it.`),D(`SPL2009`,E,`A wildcard field list needs the list of fields, which is not known here.`,`List the fields explicitly.`),D(`SPL2010`,E,`This command depends on the order of result rows, which DQL does not provide.`,`Rewrite this stage by hand.`),D(`SPL2011`,E,`Real-time and index-time modifiers have no DQL equivalent.`,`Use a normal time range.`),D(`SPL2012`,E,`A field name contains a backtick or a line break, which DQL cannot hold.`,`Rename the field in Splunk to a name without backticks or line breaks, or rewrite this stage by hand.`),D(`SPL3001`,E,`Case sensitivity differs from Splunk here.`,`Values that differ only in case will not match.`),D(`SPL3002`,E,`Missing or empty fields are handled differently.`,`Check rows where the field is missing.`),D(`SPL3003`,E,`The result has a different shape than in Splunk.`,`Check how the result is charted or used afterwards.`),D(`SPL3004`,E,`The result depends on record order, which DQL does not guarantee here.`,`Add an explicit sort if order matters.`),D(`SPL3005`,E,`This aggregation may be computed differently (exact or approximate).`,`Expect small numeric differences.`),D(`SPL3006`,E,`Values may be compared as a different type than in Splunk.`,`Declare the field type in the mapping file (fieldTypes).`),D(`SPL3007`,E,`An index position was adjusted from 1-based to 0-based.`,`Check the result for an off-by-one difference.`),D(`SPL3008`,E,`A regular expression was converted to a Dynatrace pattern.`,`Check the extracted values on real data.`),D(`SPL3009`,E,`Splunk applies a default limit here that DQL does not.`,`Add an explicit limit if you relied on it.`),D(`SPL3010`,E,`Time zone or time format handling may differ.`,`Check timestamps in the result.`),D(`SPL3011`,E,`Wildcard or token matching differs from Splunk.`,`Check matches on real data.`),D(`SPL3012`,E,`Part of the query runs twice inside a sub-query.`,`Expect higher query cost; both runs may see slightly different data.`),D(`SPL3013`,E,`Multivalue fields behave differently.`,`Check rows where a field has several values.`),D(`SPL3014`,E,`This command was approximated with a different construct.`,`Check the result carefully.`),D(`SPL3015`,E,`The time range could not be reproduced exactly.`,`Set the time range in Dynatrace.`),D(`SPL3016`,E,`Output field names differ from Splunk.`,`Rename fields if later steps rely on the Splunk names.`),D(`SPL3017`,E,`The generated DQL did not pass the offline syntax check.`,`Check the highlighted line; this may need a manual fix.`),D(`SPL4001`,E,`This index has no entry in the mapping file.`,`Add the index under "indexes" in the mapping file.`),D(`SPL4002`,E,`This sourcetype has no entry in the mapping file.`,`Add the sourcetype under "sourcetypes" in the mapping file.`),D(`SPL4003`,E,`This field probably comes from Splunk search-time extraction and does not exist in Grail.`,`Map it under "fields" or "extractions" in the mapping file.`),D(`SPL4004`,E,`This macro has no definition in the mapping file.`,`Copy its definition from macros.conf into "macros".`),D(`SPL4005`,E,`This lookup has no entry in the mapping file.`,`Upload the table to Grail and add it under "lookups".`),D(`SPL4006`,E,`This eventtype, tag or saved search cannot be resolved.`,`Add it under "eventtypes" or "tags" in the mapping file.`),D(`SPL4007`,E,`This metric has no entry in the mapping file.`,`Add it under "metrics" in the mapping file.`),D(`SPL4008`,E,`This data model has no entry in the mapping file.`,`Add it under "datamodels" in the mapping file: where its data is in Grail and what its fields are called there.`),D(`SPL4009`,E,`The search contains a dashboard token, which was kept as plain text.`,`Replace the token with a Dynatrace dashboard variable, or with a real value.`),D(`SPL5001`,se,`The search has no time range; DQL uses the time range chosen in Dynatrace.`,`Add from: to the fetch if the time range matters.`),D(`SPL5002`,se,`Splunk default fields were renamed to their Grail names.`,`No action needed.`),D(`SPL5003`,se,`Rows with an empty group-by field are removed first, as Splunk does.`,`No action needed.`),D(`SPL5004`,se,`A sort by time was added to reproduce Splunk event order.`,`No action needed.`),D(`SPL5005`,se,`A macro was expanded.`,`No action needed.`),D(`SPL5006`,se,`Splunk's default result limit is not reproduced; DQL returns at most 1000 records by default.`,`Add a limit if needed.`),D(`SPL5007`,se,`A display-only command was dropped; it does not change the data.`,`No action needed.`),D(`SPL5008`,se,`This is accurate but can be expensive on large data.`,`Consider an approximate function if exactness does not matter.`)],le=new Map(ce.map(e=>[e.code,e]));function ue(e){let t=le.get(e);if(!t)throw Error(`Unregistered diagnostic code ${e}`);return t}var de=class{items=[];seen=/* @__PURE__ */ new Set;strict;capped=!1;mapSpan=e=>e;constructor(e){this.strict=e}report(e,t,n,r={}){let i=ue(e),a=r.subject===void 0?void 0:`${e}\u0000${r.subject}`;if(a!==void 0){if(this.seen.has(a))return;this.seen.add(a)}let o={code:e,severity:this.strict&&e.startsWith(`SPL4`)?`error`:i.severity,message:r.detail?`${r.detail}`:i.title,hint:i.hint,span:this.mapSpan(t),stageIndex:n};r.subject!==void 0&&(o.subject=r.subject),this.add(o)}add(e){if(this.items.length<1e4){this.items.push(e);return}if(this.capped)return;this.capped=!0;let t=ue(`SPL1006`);this.items.push({code:`SPL1006`,severity:t.severity,message:`The search produced more than 10000 notes; the rest were left out.`,hint:t.hint,span:e.span,stageIndex:e.stageIndex})}reportOnce(e,t,n,r){this.report(e,t,n,r===void 0?{subject:``}:{subject:``,detail:r})}};const fe=/\s/;function pe(e,t=0,n=e.length){let r=[],i,a=[],o=t,s=!1,c=t,l=t;for(;l<n&&fe.test(e[l]??``);)l++;e[l]===`|`&&(s=!0,o=l+1,c=l+1);let u=t=>{let n=me(e,o,t);r.push({span:n,leadingPipe:r.length===0&&s})};for(;c<n;){let t=e[c];if(t==="`"&&e.startsWith("```",c)){let t=e.indexOf("```",c+3);if(t===-1||t>=n){i??={span:{start:c,end:n},detail:"A comment opened with ``` is not closed."},c=n;break}c=t+3}else if(t===`"`){let t=O(e,c,n);if(t===-1){i??={span:{start:c,end:n},detail:`A quoted string is not closed.`},c=n;break}c=t+1}else if(t==="`"){let t=e.indexOf("`",c+1);if(t===-1||t>=n){i??={span:{start:c,end:n},detail:"A macro call opened with ` is not closed."},c=n;break}c=t+1}else{if(t===`[`||t===`(`)a.push({ch:t,pos:c});else if(t===`]`||t===`)`){let e=t===`]`?`[`:`(`;a[a.length-1]?.ch===e?a.pop():i??={span:{start:c,end:c+1},detail:`Unexpected "${t}".`}}else t===`|`&&a.length===0&&(u(c),o=c+1);c++}}let d=a[a.length-1];return d&&!i&&(i={span:{start:d.pos,end:n},detail:`"${d.ch}" is not closed.`}),u(n),i?{stages:r,problem:i}:{stages:r}}function O(e,t,n=e.length){for(let r=t+1;r<n;r++){let t=e[r];if(t===`\\`)r++;else if(t===`"`)return r}return-1}function me(e,t,n){let r=t,i=n;for(;r<i&&fe.test(e[r]??``);)r++;for(;i>r&&fe.test(e[i-1]??``);)i--;for(;e.startsWith("```",r);){let t=e.indexOf("```",r+3);if(t===-1||t+3>i)break;for(r=t+3;r<i&&fe.test(e[r]??``);)r++}return{start:r,end:i}}var he=class{text;end;pos;constructor(e,t,n){this.text=e,this.pos=t,this.end=n}skipWs(){for(;this.pos<this.end;){let e=this.text[this.pos];if(e===` `||e===` `||e===`
2
- `||e===`\r`)this.pos++;else if(e==="`"&&this.text.startsWith("```",this.pos)){let e=this.text.indexOf("```",this.pos+3);this.pos=e===-1||e+3>this.end?this.end:e+3}else return}}atEnd(){return this.skipWs(),this.pos>=this.end}peek(){return this.skipWs(),this.pos<this.end?this.text[this.pos]:``}eat(e){return this.peek()===e&&(this.pos+=e.length,!0)}keyword(e){if(this.skipWs(),this.text.slice(this.pos,this.pos+e.length).toLowerCase()!==e.toLowerCase())return!1;let t=this.text[this.pos+e.length]??``;return this.pos+e.length<this.end&&/[A-Za-z0-9_]/.test(t)?!1:(this.pos+=e.length,!0)}peekKeyword(e){let t=this.pos,n=this.keyword(e);return this.pos=t,n}option(){this.skipWs();let e=/^[A-Za-z_][A-Za-z0-9_]*\s*=(?!=)/.exec(this.text.slice(this.pos,Math.min(this.end,this.pos+80)));if(!e)return;let t=this.pos,n=e[0].replace(/\s*=$/,``);this.pos+=e[0].length,this.skipWs();let r=this.value();if(!r)this.pos=t;else return{name:n,value:r.value,quoted:r.quoted,span:{start:t,end:r.span.end},valueSpan:r.span}}value(){if(this.skipWs(),this.peek()===`"`){let e=this.quoted();return e?{value:e.value,quoted:!0,span:e.span}:void 0}let e=this.word();return e?{value:e.value,quoted:!1,span:e.span}:void 0}word(e=``){this.skipWs();let t=this.pos;for(;this.pos<this.end;){let t=this.text[this.pos];if(/[\s,()[\]"|]/.test(t)||e.includes(t))break;this.pos++}if(this.pos!==t)return{value:this.text.slice(t,this.pos),span:{start:t,end:this.pos}}}fieldName(){if(this.skipWs(),this.peek()===`"`){let e=this.quoted();return e?{value:e.value,span:e.span,quoted:!0}:void 0}if(this.peek()===`'`){let e=this.text.indexOf(`'`,this.pos+1);if(e!==-1&&e<this.end){let t=this.pos;return this.pos=e+1,{value:this.text.slice(t+1,e),span:{start:t,end:this.pos},quoted:!0}}}let e=this.pos;for(;this.pos<this.end&&/[A-Za-z0-9_.*:{}@\-/$]/.test(this.text[this.pos]);)this.pos++;if(this.pos!==e){if(this.text[this.pos]===`(`){let t=ge(this.text,this.pos,this.end,`(`,`)`);if(t!==-1)return this.pos=t+1,{value:this.text.slice(e,this.pos).replace(/\s+/g,``),span:{start:e,end:this.pos},quoted:!1}}return{value:this.text.slice(e,this.pos),span:{start:e,end:this.pos},quoted:!1}}}quoted(){if(this.skipWs(),this.text[this.pos]!==`"`)return;let e=O(this.text,this.pos,this.end);if(e===-1)return;let t=this.pos;return this.pos=e+1,{value:ve(this.text.slice(t+1,e)),span:{start:t,end:this.pos}}}balanced(e,t){if(this.skipWs(),this.text[this.pos]!==e)return;let n=this.pos,r=ge(this.text,n,this.end,e,t);if(r!==-1)return this.pos=r+1,{inner:{start:n+1,end:r},span:{start:n,end:this.pos}}}integer(){this.skipWs();let e=/^\d{1,9}(?![A-Za-z0-9_.])/.exec(this.text.slice(this.pos,Math.min(this.end,this.pos+12)));if(!e)return;let t=this.pos;return this.pos+=e[0].length,{value:Number(e[0]),span:{start:t,end:this.pos}}}rest(){this.skipWs();let e={start:this.pos,end:this.end};return this.pos=this.end,e}here(){return this.skipWs(),{start:this.pos,end:Math.min(this.end,this.pos+1)}}};function ge(e,t,n,r,i){let a=0;for(let o=t;o<n;o++){let t=e[o];if(t===`"`){let t=O(e,o,n);if(t===-1)return-1;o=t}else if(t===r)a++;else if(t===i&&(a--,a===0))return o}return-1}function _e(e,t,n,r){let i=0;for(let a=t;a<n;a++){let o=e[a];if(o===`"`){let t=O(e,a,n);if(t===-1)return;a=t}else if(o===`(`||o===`[`)i++;else if(o===`)`||o===`]`)i--;else if(i===0&&/[A-Za-z]/.test(o)&&(a===t||/[\s,)]/.test(e[a-1]))){for(let t of r)if(e.slice(a,a+t.length).toLowerCase()===t&&!/[A-Za-z0-9_]/.test(e[a+t.length]??``))return{pos:a,word:t}}}}function ve(e){return e.replace(/\\(["\\])/g,`$1`)}function k(e){let t=Object.create(null);for(let[n,r]of Object.entries(e))t[n]=r;return Object.freeze(t)}const ye=k({_time:`timestamp`,_raw:`content`,host:`host.name`,source:`log.source`,index:`dt.system.bucket`}),be=/^[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)+$/,xe=/* @__PURE__ */ new Set([`_time`,`_raw`,`host`,`source`,`index`,`sourcetype`,`linecount`,`punct`,`splunk_server`,`timestamp`]);var A=class extends Error{code;span;constructor(e,t,n){super(n),this.code=e,this.span=t}},Se=class{text;mapping;options;diags;lowerSub=()=>({commands:[],incomplete:!0});lowerSubsearchFilter=()=>void 0;constructor(e,t,n){this.text=e,this.mapping=t,this.options=n,this.diags=new de(n.strict??!1)}},Ce=class{tc;state;index;command;span;argsSpan;first;next;upstream;depth;prevSeries;prevWasSort;out=[];pre=[];untranslated=!1;constructor(e){this.tc=e.tc,this.state=e.state,this.index=e.index,this.command=e.command,this.span=e.span,this.argsSpan=e.argsSpan,this.first=e.first,this.next=e.following,this.upstream=e.upstream,this.depth=e.depth,this.prevSeries=e.prevSeries,this.prevWasSort=e.prevWasSort}get following(){return this.next.names.slice(this.next.from)}get mapping(){return this.tc.mapping}scanner(){return new he(this.tc.text,this.argsSpan.start,this.argsSpan.end)}slice(e){return this.tc.text.slice(e.start,e.end)}emit(e){this.out.push({...e,origin:[this.index]})}report(e,t=this.span,n={}){this.tc.diags.report(e,t,this.index,n)}giveUp(e,t,n=this.span){this.untranslated=!0,this.out.length=0,this.report(e,n,t===void 0?{}:{detail:t}),this.out.push({name:`//`,args:[],origin:[this.index],comment:`not translated: ${this.slice(this.span)}`})}giveUpSilently(){this.untranslated=!0,this.out.length=0,this.out.push({name:`//`,args:[],origin:[this.index],comment:`not translated: ${this.slice(this.span)}`})}field(e,t,r=!1){let a=this.tc.mapping,o=this.state.datamodel,c=o!==void 0&&!r&&be.test(e)&&!a.fields.has(e)?e.slice(e.lastIndexOf(`.`)+1):e,l=(o!==void 0&&!r?o.entry?.fields.get(c):void 0)??a.fields.get(c),u=ye[c],d=l??u??c;if(r)return this.state.created.add(c),d;if(u!==void 0&&l===void 0&&this.tc.diags.reportOnce(`SPL5002`,t,this.index),this.state.schema.kind!==`events`||this.state.created.has(c)||l!==void 0||u!==void 0||c.includes(`*`))return d;let f=o===void 0?a.extractions.get(c):void 0;if(f){if(!this.state.extracted.has(c)){this.state.extracted.add(c);let e=`${f.from}\u0000${f.dpl}`;this.state.extractedPatterns.has(e)||(this.state.extractedPatterns.add(e),this.pre.push({...S(`parse`,i(f.from),s(f.dpl),b(`preserveFieldsOnFailure`,n(!0))),origin:[this.index]}))}return d}return c===`sourcetype`?(this.report(`SPL4002`,t,{subject:`sourcetype`,detail:`The sourcetype field does not exist in Grail; map the sourcetype instead.`}),d):xe.has(c)?d:o===void 0?this.state.unresolved.has(c)||this.state.opaqueUpstream?(this.report(`SPL4003`,t,{subject:c,detail:`"${c}" is unknown here; it may come from an earlier step that was not translated.`}),d):(this.report(`SPL4003`,t,{subject:c,detail:`"${c}" is not mapped and is not created earlier in the search; in Splunk it is probably extracted at search time.`}),d):(this.report(`SPL4003`,t,{subject:`datamodel:${o.key}:${c}`,detail:`"${c}" has no entry under datamodels → ${o.key} → fields in the mapping file; its Splunk name was kept.`}),d)}fieldType(e){return e===`timestamp`?`time`:this.state.types.get(e)??this.tc.mapping.fieldTypes.get(e)}setType(e,t){t?this.state.types.set(e,t):this.state.types.delete(e)}splName(e){for(let[t,n]of this.tc.mapping.fields)if(n===e)return t;for(let[t,n]of Object.entries(ye))if(n===e)return t;return e}get unorderedEvents(){return this.state.schema.kind===`events`&&!this.state.sorted}setTable(e){this.state.schema={kind:`table`,fields:Te(e)},this.state.created=new Set(this.state.created),this.state.sorted=!1}addFields(e){this.state.schema.kind!==`events`&&(this.state.schema={kind:this.state.schema.kind,fields:Te([...this.state.schema.fields,...e])})}};function we(){return{schema:{kind:`events`,fields:[]},created:/* @__PURE__ */ new Set,unresolved:/* @__PURE__ */ new Set,extracted:/* @__PURE__ */ new Set,extractedPatterns:/* @__PURE__ */ new Set,sorted:!1,series:!1,lastWasSort:!1,opaqueUpstream:!1,types:/* @__PURE__ */ new Map}}function Te(e){return[...new Set(e)]}const Ee=k({s:`s`,sec:`s`,secs:`s`,second:`s`,seconds:`s`,m:`m`,min:`m`,mins:`m`,minute:`m`,minutes:`m`,h:`h`,hr:`h`,hrs:`h`,hour:`h`,hours:`h`,d:`d`,day:`d`,days:`d`,w:`w`,week:`w`,weeks:`w`,mon:`M`,month:`M`,months:`M`,q:`q`,qtr:`q`,qtrs:`q`,quarter:`q`,quarters:`q`,y:`y`,yr:`y`,yrs:`y`,year:`y`,years:`y`}),De=k({s:1,m:60,h:3600,d:86400,w:604800});function Oe(e){return Ee[e.toLowerCase()]??(e===`M`?`M`:void 0)}function ke(e){let t=/^([A-Za-z]+)(\d?)$/.exec(e);if(!t)return;let n=(t[1]??``).toLowerCase(),r=t[2]??``;if(n===`w`)return r===``||r===`0`||r===`7`?`w0`:`w${r}`;if(r===``)return Ee[n]}function Ae(e,t){let n=e.trim().replace(/^"(.*)"$/s,`$1`);if(n===``)return{kind:`invalid`,detail:`The time modifier is empty.`};if(n.length>64)return{kind:`invalid`,detail:`The time modifier is too long.`};if(/^now(\(\))?$/i.test(n))return{kind:`now`};if(n===`0`)return{kind:`all`};if(/^rt/i.test(n))return{kind:`realtime`};if(/^\d{1,11}(\.\d+)?$/.test(n))return{kind:`absolute`,iso:Pe(Math.floor(Number(n))*1e3),fromText:!1};let r=/^(\d{1,2})\/(\d{1,2})\/(\d{4}):(\d{1,2}):(\d{2}):(\d{2})$/.exec(n);if(r){let[,e,i,a,o,s,c]=r.map(Number),l=Date.UTC(a,e-1,i,o,s,c),u=new Date(l);if(u.getUTCMonth()!==e-1||u.getUTCDate()!==i||o>23||s>59||c>59)return{kind:`invalid`,detail:`"${n}" is not a valid date.`};let d=Fe(t,l);return d===void 0?{kind:`invalid`,detail:`Unknown time zone "${t}".`}:{kind:`absolute`,iso:Pe(l-d*6e4),fromText:!0}}return je(n)}function je(e){let t=/^((?:[+-]\d+[A-Za-z]*)*)(?:@([A-Za-z]+\d?))?((?:[+-]\d+[A-Za-z]*)*)$/.exec(e);if(!t)return{kind:`invalid`,detail:`"${e}" is not a time modifier the translator understands.`};let n=Me(t[1]??``),r=Me(t[3]??``);if(!n||!r)return{kind:`invalid`,detail:`"${e}" uses an unknown time unit.`};let i=``;if(t[2]!==void 0){let e=ke(t[2]);if(!e)return{kind:`invalid`,detail:`"@${t[2]}" is not a known snap unit.`};i=`@${e}`}let a=Ne(n);if(a===void 0)return{kind:`invalid`,detail:`"${e}" mixes calendar and clock units.`};if(r.length>0){let t=Ne(r);return t===void 0?{kind:`invalid`,detail:`"${e}" mixes calendar and clock units.`}:{kind:`relative`,dql:`${a===``?`now()${i}`:`now()${a}${i}`}${t}`,exact:!1}}return a===``&&i===``?{kind:`invalid`,detail:`"${e}" is not a time modifier.`}:{kind:`relative`,dql:`${a}${i}`,exact:!0}}function Me(e){let t=[];for(let n of e.matchAll(/([+-])(\d+)([A-Za-z]*)/g)){let e=n[3]===``?`s`:Oe(n[3]??``);if(!e)return;t.push({sign:n[1]===`-`?-1:1,n:Number(n[2]),unit:e})}return t}function Ne(e){if(e.length===0)return``;if(e.length===1){let t=e[0];return`${t.sign<0?`-`:`+`}${t.n}${t.unit}`}let t=0;for(let n of e){let e=De[n.unit];if(e===void 0)return;t+=n.sign*n.n*e}for(let[e,n]of[[`w`,604800],[`d`,86400],[`h`,3600],[`m`,60]])if(t%n===0)return`${t<0?`-`:`+`}${Math.abs(t/n)}${e}`;return`${t<0?`-`:`+`}${Math.abs(t)}s`}function Pe(e){return new Date(e).toISOString().replace(/\.000Z$/,`Z`)}function Fe(e,t){if(e===`UTC`||e===`Z`)return 0;let n=/^([+-])(\d{2}):(\d{2})$/.exec(e);if(n)return(n[1]===`-`?-1:1)*(Number(n[2])*60+Number(n[3]));try{let n=new Intl.DateTimeFormat(`en-US`,{timeZone:e,hourCycle:`h23`,year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`}),r=t;for(let e=0;e<2;e++){let i=Object.fromEntries(n.formatToParts(new Date(r)).map(e=>[e.type,e.value])),a=Date.UTC(Number(i.year),Number(i.month)-1,Number(i.day),Number(i.hour),Number(i.minute),Number(i.second)),o=Math.round((a-r)/6e4);if(r=t-o*6e4,e===1)return o}return}catch{return}}function j(e,t){for(let n of t)e.push(n)}const Ie=/^-?\d+(\.\d+)?$/,Le=/* @__PURE__ */ new Set([`index`,`sourcetype`,`eventtype`,`tag`,`earliest`,`latest`]),Re=/^_index_(earliest|latest)$/;function ze(e,t,r,i=!1,a){return Be(e,t,i,a)??n(!0)}function Be(e,t,n,r){let i=e=>r??e;switch(e.t){case`and`:return ee(e.items.map(e=>Be(e,t,n,r)).filter(e=>e!==void 0));case`or`:return te(e.items.map(e=>Be(e,t,n,r)).filter(e=>e!==void 0));case`not`:{let i=Be(e.e,t,n,r);return i===void 0?void 0:x(`isFalseOrNull`,i)}case`macro`:return;case`sub`:return t.tc.lowerSubsearchFilter(e,t);case`term`:return Ve(e.v,e.quoted,!1,t,i(e.span));case`func`:return e.fn===`CASE`?Ve(e.v,!0,!0,t,i(e.span)):(t.report(`SPL3011`,i(e.span),{detail:`TERM() matches a whole token in Splunk; in DQL it becomes a phrase match.`}),Ve(e.v,!0,!1,t,i(e.span)));case`in`:return He(e,t,i(e.span));case`cmp`:return Ue(e,t,i(e.span),i(e.fieldSpan))}}function Ve(t,r,a,o,s){if(o.state.schema.kind!==`events`)throw new A(`SPL2003`,s,`A free-text term after a transforming command can only stand on its own in the search.`);!r&&t.includes(`*`)&&o.report(`SPL3011`,s,{detail:`"${t}": wildcard terms match on token boundaries that differ from Splunk's.`});let c=[i(o.field(`_raw`,s)),e(t)];return a?x(`matchesPhrase`,...c,b(`caseSensitive`,n(!0))):x(`matchesPhrase`,...c)}function He(n,r,a){let o=r.field(n.field,a),s=r.fieldType(o);return n.values.length>0&&n.values.every(e=>!e.quoted&&Ie.test(e.v))&&s!==`string`?(s!==`number`&&r.report(`SPL3006`,a,{subject:`type:${o}`,detail:`"${n.field}" has no declared type; it is compared as a number.`}),x(`in`,i(o),d(n.values.map(e=>t(e.v))))):x(`matchesValue`,i(o),d(n.values.map(t=>e(t.v))))}function Ue(n,r,a,o){let s=n.field;if(s===`earliest`||s===`latest`||Re.test(s))throw new A(`SPL2003`,a,`A time modifier can only be translated as a top-level term of the first search.`);if(s===`sourcetype`||s===`eventtype`||s===`tag`)return We(n,r,a);if(s===`index`&&r.first){r.report(`SPL3014`,a,{detail:`An index inside OR/NOT is translated as a bucket comparison.`});let t=r.mapping.indexes.get(n.value)?.buckets[0]??n.value,o=g(`==`,i(`dt.system.bucket`),e(t));return n.op===`!=`?m(o):o}let c=r.field(s,o),l=r.fieldType(c),u=n.value,d=!n.quoted&&Ie.test(u),f=()=>{l===void 0&&r.report(`SPL3006`,o,{subject:`type:${c}`,detail:`"${s}" has no declared type; it is compared as a ${d?`number`:`text`}.`})};switch(n.op){case`=`:case`!=`:{let o;return u===`*`&&!n.quoted?n.op===`!=`?(r.report(`SPL3002`,a,{detail:`${s}!=* is translated as "field is missing".`}),x(`isNull`,i(c))):x(`isNotNull`,i(c)):d&&l!==`string`?(l!==`number`&&f(),o=g(n.op===`=`?`==`:`!=`,i(c),t(u)),o):(/.\*./.test(u)&&r.report(`SPL3011`,a,{detail:`"${u}": a wildcard in the middle of a value may match differently.`}),o=x(`matchesValue`,i(c),e(u)),n.op===`!=`?m(o):o)}default:return f(),g(n.op,i(c),d?t(u):e(u))}}function We(e,t,n){let r=t.mapping,i=e.field===`sourcetype`?r.sourcetypes.get(e.value)?.filter:e.field===`eventtype`?r.eventtypes.get(e.value):r.tags.get(e.value);if(i===void 0){let r=e.field===`sourcetype`?`SPL4002`:`SPL4006`;t.report(r,n,{subject:`${e.field}=${e.value}`,detail:`${e.field} "${e.value}" has no entry in the mapping file, so it was left out; the result may include more records.`})}else return e.op===`!=`?m(c(i)):c(i)}function Ge(e){return e?e.t===`and`?e.items:[e]:[]}function Ke(e,t){let n=[],r=[];for(let e of t)e.k===`call`&&e.fn===`isFalseOrNull`&&e.args.length===1&&e.args[0]?r.push(e.args[0].value):n.push(e);let i=ee(n);i&&e.emit(S(`filter`,i));for(let t of r)e.emit(S(`filterOut`,t))}function qe(t,n,r){let i=t.mapping,o=[],s=[],l=[],u,f;for(let e of Ge(n))if(!r&&e.t===`cmp`&&e.field===`index`&&e.op===`=`)s.push(e);else if(!r&&e.t===`or`&&e.items.length>0&&e.items.every(e=>e.t===`cmp`&&e.field===`index`&&e.op===`=`))j(s,e.items);else if(e.t===`cmp`&&(e.field===`earliest`||e.field===`latest`)&&e.op===`=`){if(t.tc.options.tokens&&/^\$[A-Za-z_][A-Za-z0-9_.]*\$$/.test(e.value))continue;let n=Ae(e.value,i.defaults.timezone);e.field===`earliest`?u={value:n,span:e.span}:f={value:n,span:e.span}}else if(e.t===`cmp`&&Re.test(e.field))t.report(`SPL2011`,e.span,{detail:`${e.field} (index time) has no DQL equivalent and was left out.`});else if(e.t===`cmp`&&Le.has(e.field)&&e.op===`=`&&e.field!==`index`){let n=We(e,t,e.span);n&&l.push(n)}else o.push(e);let p=i.defaults.dataObject,m=[];if(r)p=r.dataObject,m=[...r.buckets],r.filter!==void 0&&l.unshift(c(r.filter));else if(s.length===0)t.report(`SPL4001`,t.span,{subject:`(none)`,detail:`The search names no index; Splunk would search your default indexes, DQL reads all records of this type.`});else{let e=/* @__PURE__ */ new Set,n=!1,r=!1;for(let a of s){if(a.value===`*`){r=!0;continue}let o=Ye(i.indexes,a.value);o?(e.add(o.dataObject),j(m,o.buckets),o.filter!==void 0&&s.length===1&&l.unshift(c(o.filter))):(n=!0,t.report(`SPL4001`,a.span,{subject:a.value,detail:`Index "${a.value}" has no entry in the mapping file, so all records are read.`}))}if(e.size>1)throw new A(`SPL2003`,t.span,`These indexes map to different Grail data objects; split the search.`);e.size===1&&(p=[...e][0]),(n||r)&&(m=[])}let h=[y(a(p))];m.length>0&&h.push(b(`bucket`,d([...new Set(m)].map(e))));let g=t.tc.options.timeRange,_=i.defaults.timezone;!u&&g?.earliest!==void 0&&(u={value:Ae(g.earliest,_),span:t.span}),!f&&g?.latest!==void 0&&(f={value:Ae(g.latest,_),span:t.span}),!u&&i.defaults.timeframe!==void 0&&(u={value:Ae(i.defaults.timeframe,_),span:t.span});let v=u?Ze(t,`earliest`,u.value,u.span):void 0,x=f?Ze(t,`latest`,f.value,f.span):void 0;v&&h.push(b(`from`,v)),x&&h.push(b(`to`,x)),u||t.tc.diags.reportOnce(`SPL5001`,t.span,t.index),t.emit({name:`fetch`,args:h});let S=[...l];for(let e of o){let n=Be(e,t,!1,void 0);n&&S.push(n)}Ke(t,S)}function Je(t,n){if(!n)return;let r=[],i=[];for(let e of Ge(n)){if(t.state.schema.kind!==`events`&&e.t===`term`){i.push(e.v),t.report(`SPL3011`,e.span,{detail:`A free-text term after a transforming command is matched against all fields with the DQL search command.`});continue}if(e.t===`cmp`&&(e.field===`earliest`||e.field===`latest`)){t.report(`SPL2003`,e.span,{detail:`A time modifier in a later search stage has no DQL equivalent and was left out.`});continue}let n=Be(e,t,!1,void 0);n&&r.push(n)}Ke(t,r);for(let n of i)t.emit(S(`search`,e(n)))}function Ye(e,t){let n=e.get(t);if(n)return n;let r;for(let[n,i]of e)n.includes(`*`)&&Xe(n,t)&&(!r||n.length>r.len)&&(r={len:n.length,value:i});return r?.value}function Xe(e,t){let n=e.split(`*`),r=n[0]??``,i=n[n.length-1]??``;if(n.length===1)return e===t;if(!t.startsWith(r)||t.length<r.length+i.length||!t.endsWith(i))return!1;let a=r.length,o=t.length-i.length;for(let e=1;e<n.length-1;e++){let r=n[e],i=t.indexOf(r,a);if(i===-1||i+r.length>o)return!1;a=i+r.length}return!0}function Ze(t,n,r,i){switch(r.kind){case`now`:return;case`all`:n===`earliest`&&t.report(`SPL3015`,i,{detail:`"All time" has no DQL equivalent; choose the time range in Dynatrace.`});return;case`realtime`:t.report(`SPL2011`,i,{detail:`Real-time searches have no DQL equivalent; the time modifier was left out.`});return;case`invalid`:t.report(`SPL3015`,i,{detail:r.detail});return;case`absolute`:return r.fromText&&t.report(`SPL3010`,i,{detail:`The date was converted to UTC using the time zone "${t.mapping.defaults.timezone}".`}),e(r.iso);case`relative`:return r.exact||t.report(`SPL3015`,i,{detail:`An offset after the snap unit was kept as an expression; check that Dynatrace accepts it.`}),o(r.dql)}}var M=class extends Error{span;constructor(e,t){super(e),this.span=t}};const Qe=2e4,$e=/^[A-Za-z_][A-Za-z0-9_.:{}@-]*$/;function et(e,t,n){let r=new rt(tt(e,t,n));if(r.atEnd())return;let i=r.andExpr();return r.expectEnd(),i}function tt(e,t,n){let r=[],i=t;for(;i<n;){let t=e[i];if(/\s/.test(t)){i++;continue}if(t==="`"&&e.startsWith("```",i)){let t=e.indexOf("```",i+3);i=t===-1||t+3>n?n:t+3;continue}if(t===`(`||t===`)`){r.push({type:t,span:{start:i,end:i+1}}),i++;continue}if(t===`[`){let t=ge(e,i,n,`[`,`]`);if(t===-1)throw new M(`A subsearch "[" is not closed.`,{start:i,end:n});r.push({type:`sub`,inner:{start:i+1,end:t},span:{start:i,end:t+1}}),i=t+1;continue}if(t===`]`)throw new M(`Unexpected "]".`,{start:i,end:i+1});if(t==="`"){let t=e.indexOf("`",i+1),a=t===-1||t>=n?n:t+1;r.push({type:`macro`,span:{start:i,end:a}}),i=a;continue}if(t===`"`){let t=O(e,i,n);if(t===-1)throw new M(`A quoted string is not closed.`,{start:i,end:n});r.push({type:`word`,text:ve(e.slice(i+1,t)),quoted:!0,span:{start:i,end:t+1}}),i=t+1;continue}let a=i;for(;i<n;){let t=e[i];if(/[\s()[\]]/.test(t))break;if(t===`"`){let t=O(e,i,n);if(t===-1)throw new M(`A quoted string is not closed.`,{start:i,end:n});i=t+1}else i++}if(i===a)throw new M(`Unexpected "${t}".`,{start:i,end:i+1});r.push({type:`word`,text:e.slice(a,i),quoted:!1,span:{start:a,end:i}})}if(r.push({type:`eof`,span:{start:n,end:n}}),r.length>Qe)throw new M(`The search has more than ${Qe} terms.`,{start:t,end:n});return r}function nt(e){let t=[],n=0;for(;n<e.length;){if(e[n]===`,`){n++;continue}if(e[n]===`"`){let r=O(e,n,e.length),i=r===-1?e.length:r;t.push({v:ve(e.slice(n+1,i)),quoted:!0}),n=i+1;continue}let r=e.indexOf(`,`,n),i=r===-1?e.length:r,a=e.slice(n,i).trim();a!==``&&t.push({v:a,quoted:!1}),n=i}return t}var rt=class{i=0;depth=0;toks;constructor(e){this.toks=e}get t(){return this.toks[this.i]??this.toks[this.toks.length-1]}ty(){return this.t.type}peekTok(e){return this.toks[this.i+e]??this.toks[this.toks.length-1]}isKw(e){let t=this.t;return t.type===`word`&&!t.quoted&&t.text===e}atEnd(){return this.t.type===`eof`}expectEnd(){if(this.t.type===`)`)throw new M(`Unexpected ")".`,this.t.span);if(this.t.type!==`eof`)throw new M(`Unexpected text in the search.`,this.t.span)}enter(){if(++this.depth>200)throw new M(`The search is nested too deeply.`,this.t.span)}andExpr(){this.enter();let e=[this.orExpr()];for(;;)if(this.isKw(`AND`))this.i++,e.push(this.orExpr());else{if(this.t.type===`eof`||this.t.type===`)`)break;e.push(this.orExpr())}return this.depth--,e.length===1?e[0]:{t:`and`,items:e,span:at(e)}}orExpr(){let e=[this.notExpr()];for(;this.isKw(`OR`);)this.i++,e.push(this.notExpr());return e.length===1?e[0]:{t:`or`,items:e,span:at(e)}}notExpr(){if(this.isKw(`NOT`)){let e=this.t.span.start;this.i++,this.enter();let t=this.notExpr();return this.depth--,{t:`not`,e:t,span:{start:e,end:t.span.end}}}return this.primary()}primary(){let e=this.t;if(e.type===`(`){if(this.i++,this.t.type===`)`)throw new M(`Empty parentheses.`,this.t.span);let e=this.andExpr();if(this.ty()!==`)`)throw new M(`Expected ")".`,this.t.span);return this.i++,e}if(e.type===`sub`)return this.i++,{t:`sub`,inner:e.inner,span:e.span};if(e.type===`macro`)return this.i++,{t:`macro`,span:e.span};if(e.type!==`word`)throw new M(`Expected a search term.`,e.span);if(this.i++,e.quoted)return{t:`term`,v:e.text,quoted:!0,span:e.span};if(e.text===`AND`||e.text===`OR`)throw new M(`"${e.text}" needs a term on both sides.`,e.span);if((e.text===`CASE`||e.text===`TERM`)&&this.t.type===`(`){let t=this.peekTok(1),n=this.peekTok(2);if(t.type===`word`&&n.type===`)`)return this.i+=3,{t:`func`,fn:e.text,v:t.text,span:{start:e.span.start,end:n.span.end}}}if($e.test(e.text)&&this.t.type===`word`&&!this.t.quoted&&this.t.text.toUpperCase()===`IN`&&this.peekTok(1).type===`(`){this.i+=2;let t=[];for(;;){let e=this.t;if(this.ty()===`)`)break;if(e.type!==`word`)throw new M(`Expected a value in the IN list.`,e.span);this.i++,e.quoted?t.push({v:e.text,quoted:!0}):j(t,nt(e.text))}let n=this.t.span.end;return this.i++,{t:`in`,field:e.text,values:t,span:{start:e.span.start,end:n}}}let t=it(e.text);if(t){let{value:n,quoted:r}=t,i=e.span.end;if(n===``&&this.t.type===`word`){let e=this.t;this.i++,n=e.text,r=e.quoted,i=e.span.end}return t.valueQuoted&&(n=ve(n.slice(1,-1)),r=!0),{t:`cmp`,field:t.field,op:t.op,value:n,quoted:r,span:{start:e.span.start,end:i},fieldSpan:{start:e.span.start,end:e.span.start+t.field.length}}}let n=this.t;if($e.test(e.text)&&n.type===`word`&&!n.quoted&&/^(=|!=|<=|>=|<|>)/.test(n.text)){let t=/^(!=|<=|>=|=|<|>)/.exec(n.text)?.[1]??`=`;this.i++;let r=n.text.slice(t.length),i=!1,a=n.span.end;if(r===``&&this.t.type===`word`){let e=this.t;this.i++,r=e.text,i=e.quoted,a=e.span.end}else r.startsWith(`"`)&&r.endsWith(`"`)&&r.length>=2&&(r=ve(r.slice(1,-1)),i=!0);return{t:`cmp`,field:e.text,op:t,value:r,quoted:i,span:{start:e.span.start,end:a},fieldSpan:e.span}}return{t:`term`,v:e.text,quoted:!1,span:e.span}}};function it(e){let t=/^([A-Za-z_][A-Za-z0-9_.:{}@-]*)(!=|<=|>=|=|<|>)(.*)$/s.exec(e);if(!t)return;let n=t[3]??``,r=n.length>=2&&n.startsWith(`"`)&&n.endsWith(`"`);return{field:t[1],op:t[2],value:n,quoted:!1,valueQuoted:r}}function at(e){return{start:e[0]?.span.start??0,end:e[e.length-1]?.span.end??0}}function ot(e,t,n){return e.mapping.lookups.get(t)||(e.report(`SPL4005`,n,{subject:t,detail:`Lookup "${t}" has no entry in the mapping file; a placeholder path /lookups/${st(t)} is used.`}),{path:`/lookups/${st(t)}`})}function st(e){return e.replace(/\.csv$/i,``).replace(/[^A-Za-z0-9_.-]/g,`_`)||`lookup`}const ct=t=>S(`load`,e(t)),lt={name:`lookup`,tier:`T2`,summary:`lookup [load "<path>"], sourceField:, lookupField:, fields:{…}.`,lower(e){let t=e.scanner();for(;t.option(););let n=t.word();if(!n)throw new A(`SPL1003`,e.span,`lookup needs a table name.`);let r=[];for(;!t.atEnd()&&!t.peekKeyword(`output`)&&!t.peekKeyword(`outputnew`);){if(t.eat(`,`))continue;let e=t.fieldName();if(!e)throw new A(`SPL1003`,t.here(),`Expected a lookup field.`);let n=e.value;t.keyword(`as`)&&(n=t.fieldName()?.value??n),r.push({lookupField:e.value,local:n,span:e.span})}if(r.length===0)throw new A(`SPL1003`,e.span,`lookup needs a field to match on.`);let o=[],s=t.keyword(`outputnew`);if(s||t.keyword(`output`))for(;!t.atEnd();){if(t.eat(`,`))continue;let e=t.fieldName();if(!e)throw new A(`SPL1003`,t.here(),`Expected an output field.`);let n=e.value;t.keyword(`as`)&&(n=t.fieldName()?.value??n),o.push({col:e.value,as:n})}let c=ot(e,n.value,n.span);if(e.report(`SPL3013`,e.span,{detail:`If several rows match, Splunk returns all values; DQL takes one row.`}),r.length>1){let t=r.map(t=>(t.local,t.lookupField,i(e.field(t.local,t.span)))),n=o.length>0?[b(`fields`,d(o.map(e=>e.as===e.col?i(e.col):f(e.as,i(e.col)))))]:[];e.emit(S(`join`,u([{...ct(c.path),origin:[e.index]}]),b(`on`,d(t)),b(`kind`,a(`leftOuter`)),...n)),o.length===0&&e.report(`SPL3016`,e.span,{detail:`Lookup columns arrive with the prefix "right.".`});for(let t of o)e.field(t.as,e.span,!0);return}let l=r[0],p=[b(`sourceField`,i(e.field(l.local,l.span))),b(`lookupField`,i(c.key??l.lookupField))],m=o;m.length===0&&(c.columns?m=c.columns.filter(e=>e!==(c.key??l.lookupField)).map(e=>({col:e,as:e})):e.report(`SPL3016`,e.span,{detail:`Without OUTPUT, lookup columns arrive as lookup.<column>; list the columns in the mapping file to keep their names.`}));let h=e=>`_new_${e.replace(/[^A-Za-z0-9_]/g,`_`)}`;m.length>0&&p.push(b(`fields`,d(m.map(e=>s?f(h(e.as),i(e.col)):e.as===e.col?i(e.col):f(e.as,i(e.col)))))),e.emit({name:`lookup`,args:[{kind:`pos`,value:u([{...ct(c.path),origin:[e.index]}])},...p]}),s&&m.length>0&&(e.emit(S(`fieldsAdd`,...m.map(e=>f(e.as,x(`coalesce`,i(e.as),i(h(e.as))))))),e.emit(S(`fieldsRemove`,...m.map(e=>i(h(e.as))))));for(let t of m)e.field(t.as,e.span,!0);e.addFields(m.map(e=>e.as))}},ut={name:`inputlookup`,tier:`T2`,summary:`load "<path>" then filter.`,generating:!0,lower(e){let t=e.scanner(),n=!1;for(let e=t.option();e;e=t.option())if(e.name.toLowerCase()===`append`&&/^(t|true|1)$/i.test(e.value))n=!0;else if(e.name.toLowerCase()!==`append`)throw new A(`SPL2003`,e.span,`inputlookup ${e.name}= cannot be translated.`);let r=t.word();if(!r)throw new A(`SPL1003`,e.span,`inputlookup needs a table name.`);let i=ot(e,r.value,r.span),a;if(t.keyword(`where`)){let n=t.rest();try{a=et(e.tc.text,n.start,n.end)}catch(e){throw e instanceof M?new A(`SPL1001`,e.span,e.message):e}}else if(!t.atEnd())throw new A(`SPL1003`,t.here(),`Unexpected text in inputlookup.`);if(n){if(a)throw new A(`SPL2003`,e.span,`inputlookup append=t with where cannot be translated.`);e.emit(S(`append`,u([{...ct(i.path),origin:[e.index]}])))}else e.emit(ct(i.path)),e.setTable(i.columns?[...i.columns]:[]),e.state.schema={kind:`table`,fields:i.columns?[...i.columns]:[]},a&&Je(e,a)}};function dt(e,t){let n=e.tc.lowerSub(t.inner,e);if(n.incomplete)throw new A(`SPL2007`,t.span,`The subsearch contains a step that could not be translated.`);return n}const ft={name:`join`,tier:`T2`,summary:`join [sub], on:{keys}, kind:inner|leftOuter, fields:{…}.`,lower(e){let t=e.scanner(),n=`inner`,r=[];for(;t.peek()!==`[`&&!t.atEnd();){let i=t.option();if(i){let t=i.name.toLowerCase();if(t===`type`){let e=i.value.toLowerCase();if(e===`inner`)n=`inner`;else if(e===`left`||e===`outer`)n=`leftOuter`;else throw new A(`SPL2003`,i.span,`join type=${i.value} cannot be translated.`)}else if(t===`max`&&i.value===`0`)continue;else if(t===`left`||t===`right`||t===`where`)throw new A(`SPL2003`,i.span,`join with left=/right= aliases cannot be translated.`);else e.report(`SPL2003`,i.span,{detail:`join ${i.name}= has no DQL equivalent and was ignored.`});continue}if(t.eat(`,`))continue;let a=t.fieldName();if(!a)throw new A(`SPL1003`,t.here(),`Expected join fields.`);r.push({name:a.value,span:a.span})}let o=t.balanced(`[`,`]`);if(!o)throw new A(`SPL1003`,e.span,`join needs a subsearch in [ … ].`);if(r.length===0)throw new A(`SPL2003`,e.span,`join without fields cannot be translated.`);let s=r.map(t=>e.field(t.name,t.span)),c=dt(e,o);e.report(`SPL3009`,e.span,{detail:`Splunk join keeps one matching row by default (max=1); DQL keeps every match.`});let l=[{kind:`pos`,value:u(c.commands)},b(`on`,d(s.map(i))),b(`kind`,a(n))],f=c.outputFields?.filter(e=>!s.includes(e));if(f&&f.length>0){l.push(b(`fields`,d(f.map(i))));for(let t of f)e.field(t,e.span,!0);e.addFields(f)}else e.report(`SPL3016`,e.span,{detail:`The subsearch fields are not known here, so they arrive with the prefix "right.".`});e.emit({name:`join`,args:l})}},pt={name:`append`,tier:`T1`,summary:`append [sub].`,lower(e){let t=e.scanner();for(;t.option(););let n=t.balanced(`[`,`]`);if(!n)throw new A(`SPL1003`,e.span,`append needs a subsearch in [ … ].`);let r=dt(e,n);e.emit(S(`append`,u(r.commands))),r.outputFields&&e.addFields(r.outputFields)}};function mt(e){return{name:e,tier:`T2`,summary:`First subsearch, then append [the others].`,generating:!0,lower(t){let n=t.scanner();for(;n.option(););let r=[];for(let e=n.balanced(`[`,`]`);e;e=n.balanced(`[`,`]`))r.push(e);if(r.length===0||!n.atEnd())throw new A(`SPL1003`,t.span,`${e} needs subsearches in [ … ].`);t.report(`SPL3004`,t.span,{detail:`Results are appended one after the other, not interleaved by time.`});let i=r.map(e=>dt(t,e).commands),a=t.first&&t.upstream.length===0,o=a?i.slice(1):i;if(a)for(let e of i[0]??[])t.out.push({...e,origin:[t.index]});for(let e of o)t.emit(S(`append`,u(e)))}}}const ht=[lt,ut,ft,pt,mt(`union`),mt(`multisearch`)],gt=1e4,_t=`The regular expression would give a Dynatrace pattern longer than ${gt} characters.`;function vt(e,t){if(e.budget.left-=t,e.budget.left<0)throw new N(_t)}var N=class extends Error{};const yt=k({B:`A non-boundary (\\B) has no Dynatrace pattern equivalent.`,A:`Anchors \\A, \\z, \\G and \\K are not supported.`,z:`Anchors \\A, \\z, \\G and \\K are not supported.`,Z:`Anchors \\A, \\z, \\G and \\K are not supported.`,G:`Anchors \\A, \\z, \\G and \\K are not supported.`,K:`Anchors \\A, \\z, \\G and \\K are not supported.`,p:`Unicode classes (\\p{…}) are not supported.`,P:`Unicode classes (\\P{…}) are not supported.`,k:`Back-references have no Dynatrace pattern equivalent.`}),bt=k({d:{text:`[0-9]`,word:!0},w:{text:`[a-zA-Z0-9_]`,word:!0},s:{text:`[ \\t\\r\\n]`,word:!1},D:{text:`[^0-9]`},W:{text:`[^a-zA-Z0-9_]`,word:!1},S:{text:`[^ \\t\\r\\n]`},t:{text:`[\\t]`,word:!1},n:{text:`[\\n]`,word:!1},r:{text:`[\\r]`,word:!1}}),xt=k({d:`0-9`,w:`a-zA-Z0-9_`,s:` \\t\\r\\n`,t:`\\t`,n:`\\n`,r:`\\r`}),St=`[a-zA-Z0-9_]`,Ct=`The regular expression is too large once its repeated groups are written out.`;function wt(e,t={}){if(e.length>4e3)return{ok:!1,reason:`The regular expression is too long.`};try{let n=e,r={captures:t.captures??!1,ci:!1,dotAll:!1,budget:{left:gt}},i=/^\(\?([a-zA-Z]+)\)/.exec(n);if(i){for(let e of i[1])if(e===`i`)r.ci=!0;else if(e===`s`)r.dotAll=!0;else throw new N(`The inline flag (?${e}) is not supported; only (?i) and (?s) are.`);n=n.slice(i[0].length)}let a=!1,o=!1;n.startsWith(`^`)&&(a=!0,n=n.slice(1)),n.endsWith(`$`)&&!Dt(n)&&(o=!0,n=n.slice(0,-1));let s=qt(n),c;if(s.length>1){if(a||o)throw new N(`"^" or "$" together with alternatives (a|b) is not supported.`);c=[{k:`alts`,options:s.map(e=>Ot(e,r,1)),quant:``}]}else c=Ot(n,r,0);if(o&&c.push({k:`eos`}),Tt(c)>2e3)throw new N(Ct);let l=[],u=jt(c,l,r,{fixed:!1,end:!0});if(u.length===0)return{ok:!1,reason:`The pattern is empty.`};let d=u.join(` `);if(!a&&!t.everyMatch&&(d=`DATA? ${d}`),t.forMatch&&!o&&(d=`${d} DATA?`),d.length>1e4)throw new N(_t);return{ok:!0,dpl:d,captures:l,anchoredStart:a}}catch(e){return e instanceof N?{ok:!1,reason:e.message}:{ok:!1,reason:`The regular expression could not be converted.`}}}function Tt(e){let t=0,n=[e];for(;n.length>0;){let e=n.pop();for(let r of e){if(t++,t>2e3)return t;if(r.k===`group`||r.k===`capture`||r.k===`look`)n.push(r.items);else if(r.k===`alts`)for(let e of r.options)n.push(e)}}return t}function Et(e){if(!/[\\^$.|?*+()[\]{}]/.test(e.replace(/\\[./\-:=@#,"' ]/g,``)))return e.replace(/\\([./\-:=@#,"' ])/g,`$1`)}function Dt(e){let t=0;for(let n=e.length-2;n>=0&&e[n]===`\\`;n--)t++;return t%2==1}function Ot(e,t,n){if(n>20)throw new N(`The regular expression is nested too deeply.`);let r=[],i=``,a=()=>{i!==``&&r.push({k:`lit`,text:i}),i=``},o=(e,n)=>{let o=t.ci&&/[A-Za-z]/.test(e);if(!o&&n===``){i+=e;return}a(),Wt(n);let s=o?`[${e.toLowerCase()}${e.toUpperCase()}]`:`[${Vt(e)}]`;r.push({k:`class`,text:s,quant:n,word:/[A-Za-z0-9_]/.test(e)})},s=e.length,c=0;for(;c<s;){let l=e[c];if(l===`\\`){let t=e[c+1];if(t===void 0)throw new N(`The regular expression ends with a backslash.`);if(/[1-9]/.test(t))throw new N(`Back-references have no Dynatrace pattern equivalent.`);if(t===`b`){a(),r.push({k:`boundary`}),c+=2;continue}let n=yt[t];if(n)throw new N(n);let i=Ut(e,c+2,s),l=bt[t];if(l){a(),Wt(i);let e={k:`class`,text:l.text,quant:i};l.word!==void 0&&(e.word=l.word),r.push(e)}else if(/[A-Za-z0-9]/.test(t))throw new N(`The escape \\${t} is not supported.`);else o(t,i);c+=2+i.length;continue}if(l===`[`){let n=Gt(e,c,s),i=Ut(e,n+1,s);a(),Wt(i),r.push({k:`class`,text:Ht(e.slice(c,n+1),t.ci),quant:i}),c=n+1+i.length;continue}if(l===`.`){let t=Ut(e,c+1,s);if(a(),t===`*`||t===`*?`)r.push({k:`any`,plus:!1});else if(t===`+`||t===`+?`)r.push({k:`any`,plus:!0});else throw new N(`A single "." (any character) is only supported as ".*" or ".+".`);c+=1+t.length;continue}if(l===`(`){a();let i=Kt(e,c,s),o=Ut(e,i+1,s);for(let a of At(e.slice(c+1,i),o,t,n))r.push(a);c=i+1+o.length;continue}if(l===`|`)throw new N(`Alternatives must stand alone in the pattern or inside a group.`);if(l===`^`||l===`$`)throw new N(`"${l}" is only supported at the start or end of the pattern.`);if(`*+?{`.includes(l)){if(l===`{`&&!/^\{\d+(,\d*)?\}/.test(e.slice(c,s))){i+=l,c++;continue}throw new N(`A quantifier must follow something to repeat.`)}if(l===`)`||l===`]`)throw new N(`Unbalanced "${l}".`);let u=Ut(e,c+1,s);o(l,u),c+=1+u.length}return a(),r}function kt(e,t,n){let r=qt(e);return r.length===1?Ot(e,t,n+1):[{k:`alts`,options:r.map(e=>Ot(e,t,n+1)),quant:``}]}function At(e,t,n,r){let i=e,a;if(e.startsWith(`?`)){let o=/^\?(?:P?<([A-Za-z_][A-Za-z0-9_]*)>|'([A-Za-z_][A-Za-z0-9_]*)')/.exec(e),s=/^\?(<?)([=!])/.exec(e);if(o)a=o[1]??o[2],i=e.slice(o[0].length);else if(e.startsWith(`?:`))i=e.slice(2);else if(s){if(t!==``)throw new N(`A look-around cannot be repeated.`);let i=kt(e.slice(s[0].length),{...n,captures:!1},r);return[{k:`look`,ahead:s[1]===``,negative:s[2]===`!`,items:i}]}else if(/^\?[a-zA-Z-]+[:)]/.test(e))throw new N(`Inline flags are only supported as (?i) or (?s) at the start of the pattern.`);else throw new N(`This group type is not supported.`)}if(a!==void 0&&n.captures){if(t!==``&&t!==`?`)throw new N(`A repeated capture group is not supported.`);if(/\(\?(?:P?<[A-Za-z_]|')/.test(i))throw new N(`Nested capture groups are not supported.`);return[{k:`capture`,name:a,inner:i,items:kt(i,n,r),optional:t===`?`}]}let o=kt(i,n,r),s=o.length===1?o[0]:void 0;if(t===``||t===`?`)return s?.k===`alts`?[{...s,quant:t}]:[{k:`group`,items:o,quant:t}];let c=/^\{(\d+)\}$/.exec(t),l=c?Number(c[1]):0;if(!c||l<1||l>8)throw new N(`A repeated group cannot be converted, except for a fixed count such as (…){3}.`);if(Tt(o)*l>2e3)throw new N(Ct);let u=[];for(let e=0;e<l;e++)for(let e of o)u.push(e);return u}function jt(e,t,n,r){let i=[];return e.forEach((a,o)=>{let s=o===e.length-1,c=e[o+1],l=s?r:{fixed:Rt(c),end:!1};switch(vt(n,1+Mt(a)),a.k){case`lit`:i.push(Bt(a.text));break;case`class`:i.push(`${a.text}${a.quant}`);break;case`any`:if(l.end){a.plus&&i.push(`DATA`);break}if(!l.fixed)throw new N(`".*" must be followed by fixed text to be converted.`);i.push(n.dotAll?`DATA`:`LD`);break;case`alts`:i.push(`${Pt(a.options,t,n)}${a.quant}`);break;case`group`:i.push(`(${Nt(a.items,t,n,a.quant===``?l:{fixed:!1,end:!1})})${a.quant}`);break;case`capture`:i.push(Lt(a,t,n,l));break;case`look`:{let e=jt(a.items,t,n,{fixed:!1,end:!1});if(e.length===0)throw new N(`An empty look-around cannot be converted.`);let r=e.length===1&&a.items[0]?.k!==`alts`?e[0]:`(${e.join(` `)})`;i.push(`${a.negative?`!`:``}${a.ahead?`>>`:`<<`}${r}`);break}case`boundary`:i.push(Ft(e[o-1],c));break;case`eos`:i.push(`EOS`)}}),i}function Mt(e){switch(e.k){case`lit`:{let t=e.text.length+2;for(let n of e.text)(n===`\\`||n===`'`)&&t++;return t}case`class`:return e.text.length+e.quant.length;case`alts`:return 2+e.quant.length+5*e.options.length;case`group`:return 2+e.quant.length;case`capture`:return 12+e.name.length;case`look`:return 5;case`boundary`:return 16;default:return 4}}function Nt(e,t,n,r){let i=jt(e,t,n,r);if(i.length===0)throw new N(`An empty group cannot be converted.`);return i.join(` `)}function Pt(e,t,n){return`(${e.map(e=>{let r=jt(e,t,n,{fixed:!1,end:!1});if(r.length===0)throw new N(`An empty alternative (a|) cannot be converted.`);return r.length===1?r[0]:`(${r.join(` `)})`}).join(` | `)})`}function Ft(e,t){let n=It(t,!0),r=It(e,!1);if(n===!0&&r!==!0)return`!<<${St}`;if(r===!0&&n!==!0)return`!>>${St}`;throw new N(`A word boundary (\\b) is only supported directly before or after a word.`)}function It(e,t){if(!e||e.k===`eos`)return!1;if(e.k===`lit`)return/[A-Za-z0-9_]/.test(t?e.text[0]:e.text[e.text.length-1]);if(e.k===`class`)return e.word}function Lt(e,t,n,r){let i=zt(e.name),a=e.inner,o=e.optional?`?`:``,s=n=>{t.push({name:e.name,type:n})};if(a===`\\d+`)return s(`number`),`LONG${o}:${i}`;if(/^-\?\\d\+\\\.\\d\+$/.test(a)||a===`\\d+\\.\\d+`)return s(`number`),`DOUBLE${o}:${i}`;if(a===`\\S+`)return s(`string`),`NSPACE${o}:${i}`;if(/^\.[*+]\??$/.test(a)){if(s(`string`),r.end)return`DATA${o}:${i}`;if(!r.fixed)throw new N(`The capture "${e.name}" (.*) must be followed by fixed text.`);return`${n.dotAll?`DATA`:`LD`}${o}:${i}`}s(`string`);let c=e.items.length===1?e.items[0]:void 0;if(c?.k===`class`)return`${c.text}${c.quant}${o}:${i}`;if(c?.k===`alts`&&c.quant===``)return`${Pt(c.options,t,n)}${o}:${i}`;if(e.items.some(e=>e.k===`any`)&&e.items[e.items.length-1]?.k!==`any`)throw new N(`The capture "${e.name}" has ".*" in the middle, which cannot be converted.`);return`(${Nt(e.items,t,n,e.optional?{fixed:!1,end:!1}:r)})${o}:${i}`}function Rt(e){return e?e.k===`lit`?!0:e.k===`class`?e.quant===``||e.quant===`+`||/^\{[1-9]/.test(e.quant):e.k===`alts`?e.quant===``:e.k===`group`?e.quant===``&&Rt(e.items[0]):e.k===`capture`?!e.optional&&!/^\.[*]/.test(e.inner)&&(e.items.length===0||Rt(e.items[0])):e.k===`look`?e.ahead&&!e.negative:e.k===`eos`:!1}function zt(e){return/^[A-Za-z][A-Za-z0-9]*$/.test(e)?e:`'${e}'`}function Bt(e){return`'${e.replace(/\\/g,`\\\\`).replace(/'/g,`\\'`)}'`}function Vt(e){return/[\]\\^-]/.test(e)?`\\${e}`:e}function Ht(e,t){let n=1,r=`[`;e[n]===`^`&&(r+=`^`,n++);let i=e.length-1,a=``;for(;n<i;){let o=e[n],s;if(o===`\\`){let t=e[n+1]??``;n+=2;let i=xt[t];if(i!==void 0){r+=i;continue}if(/[A-Za-z0-9]/.test(t))throw new N(`The escape \\${t} inside a character class is not supported.`);o=t,s=/[\]\\^[-]/.test(t)?`\\${t}`:t}else n++,s=o;let c=e[n+1];e[n]===`-`&&n+1<i&&c!==void 0&&c!==`\\`?(r+=`${s}-${c}`,t&&/[a-z]/.test(o)&&/[a-z]/.test(c)?a+=`${o.toUpperCase()}-${c.toUpperCase()}`:t&&/[A-Z]/.test(o)&&/[A-Z]/.test(c)&&(a+=`${o.toLowerCase()}-${c.toLowerCase()}`),n+=2):(r+=s,t&&/[A-Za-z]/.test(o)&&(a+=o===o.toLowerCase()?o.toUpperCase():o.toLowerCase()))}return`${r}${a}]`}function Ut(e,t,n){let r=e.slice(t,Math.min(n,t+16)),i=/^([*+?]|\{\d+(?:,\d*)?\})(\?|\+)?/.exec(r);if(!i)return``;if(i[2]===`+`)throw new N(`Possessive quantifiers are not supported.`);return i[0]}function Wt(e){if(e.endsWith(`?`)&&e.length>1)throw new N(`Lazy quantifiers are only supported on ".".`)}function Gt(e,t,n){let r=t+1;for(e[r]===`^`&&r++,e[r]===`]`&&r++;r<n;r++)if(e[r]===`\\`)r++;else{if(e[r]===`[`)throw e[r+1]===`:`?new N(`POSIX character classes ([:alpha:]) are not supported.`):new N(`Nested character classes are not supported.`);if(e[r]===`]`)return r}throw new N(`A character class "[" is not closed.`)}function Kt(e,t,n){let r=0;for(let i=t;i<n;i++){let t=e[i];if(t===`\\`)i++;else if(t===`[`)i=Gt(e,i,n);else if(t===`(`&&r++,t===`)`&&(r--,r===0))return i}throw new N(`A group "(" is not closed.`)}function qt(e){let t=[],n=0,r=``;for(let i=0;i<e.length;i++){let a=e[i];if(a===`\\`)r+=a+(e[i+1]??``),i++;else if(a===`[`){let t=i+1;for(e[t]===`^`&&t++,e[t]===`]`&&t++;t<e.length&&e[t]!==`]`;)t+=e[t]===`\\`?2:1;r+=e.slice(i,t+1),i=t}else a===`(`&&n++,a===`)`&&n--,a===`|`&&n===0?(t.push(r),r=``):r+=a}return t.push(r),t}const Jt=k({Y:`yyyy`,y:`yy`,m:`MM`,d:`dd`,e:`d`,H:`HH`,I:`hh`,M:`mm`,S:`ss`,p:`a`,b:`MMM`,B:`MMMM`,a:`EEE`,A:`EEEE`,j:`DDD`,F:`yyyy-MM-dd`,T:`HH:mm:ss`,z:`Z`,Z:`z`,Q:`SSS`});function Yt(e){let t=``,n=``,r=()=>{n!==``&&(t+=/[A-Za-z']/.test(n)?`'${n.replace(/'/g,`''`)}'`:n,n=``)};for(let i=0;i<e.length;i++){let a=e[i];if(a!==`%`){n+=a;continue}let o=e[i+1];if(o===`%`){n+=`%`,i++;continue}if(o===`3`&&e[i+2]===`N`){r(),t+=`SSS`,i+=2;continue}let s=o===void 0?void 0:Jt[o];if(!s)return{ok:!1,directive:`%${o??``}`};r(),t+=s,i++}return r(),{ok:!0,format:t}}const Xt=k({date_hour:`getHour`,date_minute:`getMinute`,date_mday:`getDayOfMonth`,date_month:`getMonth`,date_year:`getYear`,date_wday:`getDayOfWeek`});function P(n,r){switch(n.t){case`str`:return{e:e(n.v),type:`string`};case`num`:return{e:t(rn(n.v)),type:`number`,real:/[.eE]/.test(n.v)};case`field`:return Zt(n.name,n.span,r);case`un`:{let e=P(n.e,r);return n.op===`NOT`?{e:m(e.e),type:`bool`}:{e:h(e.e),type:e.type}}case`in`:return{e:x(`in`,P(n.e,r).e,d(n.list.map(e=>P(e,r).e))),type:`bool`};case`bin`:return Qt(n,r);case`call`:return _n(n,r)}}function Zt(e,t,n){let r=Xt[e];if(r&&!n.state.created.has(e))return n.report(`SPL3010`,t,{subject:e,detail:`${e} is computed from the timestamp; Splunk returns text and uses the user's time zone.`}),{e:x(r,i(`timestamp`)),type:`number`};let a=n.field(e,t),o=n.fieldType(a);return{e:i(a),type:o===`time`?`time`:o===`number`?`number`:o===`string`?`string`:`unknown`}}function Qt(e,t){let n=P(e.l,t),r=P(e.r,t);switch(e.op){case`AND`:return{e:g(`and`,n.e,r.e),type:`bool`};case`OR`:return{e:g(`or`,n.e,r.e),type:`bool`};case`XOR`:return{e:g(`xor`,n.e,r.e),type:`bool`};case`LIKE`:return{e:x(`like`,n.e,r.e),type:`bool`};case`.`:return{e:an(n.e,r.e),type:`string`};case`=`:case`==`:case`!=`:case`<`:case`<=`:case`>`:case`>=`:{let i=e.op===`=`?`==`:e.op;if(n.type===`time`&&r.type===`number`||n.type===`number`&&r.type===`time`){t.report(`SPL3006`,e.span,{detail:`A timestamp is compared with a number; it is compared as Unix seconds.`});let a=n.type===`time`?x(`unixSecondsFromTimestamp`,n.e):n.e,o=r.type===`time`?x(`unixSecondsFromTimestamp`,r.e):r.e;return{e:g(i,a,o),type:`bool`}}return tn(t,e.l,n,r),tn(t,e.r,r,n),{e:g(i,n.e,r.e),type:`bool`}}case`+`:return n.type===`string`&&r.type===`string`?{e:an(n.e,r.e),type:`string`}:nn(`+`,n,r);case`-`:return n.type===`time`&&r.type===`time`?{e:g(`/`,g(`-`,n.e,r.e),o(`1s`)),type:`number`,real:!0}:nn(`-`,n,r);case`*`:case`/`:case`%`:{let t=$t(n),i=$t(r);return e.op===`/`?{e:en(t,i),type:`number`,real:!0}:{e:g(e.op,t.e,i.e),type:`number`,real:(t.real??!1)||(i.real??!1)}}}}function $t(e){return e.type===`time`?{e:x(`unixSecondsFromTimestamp`,e.e),type:`number`}:e}function en(e,n){return e.real||n.real?g(`/`,e.e,n.e):n.e.k===`num`&&/^\d+$/.test(n.e.v)?g(`/`,e.e,t(`${n.e.v}.0`)):e.e.k===`num`&&/^\d+$/.test(e.e.v)?g(`/`,t(`${e.e.v}.0`),n.e):g(`/`,x(`toDouble`,e.e),n.e)}function tn(e,t,n,r){t.t===`field`&&n.type===`unknown`&&r.type===`number`&&n.e.k===`field`&&e.report(`SPL3006`,t.span,{subject:`type:${n.e.name}`,detail:`"${t.name}" has no declared type; DQL will not compare text with a number the way Splunk does.`})}function nn(e,t,n){return t.type===`time`&&(n.type===`number`||n.type===`unknown`)?n.e.k===`num`&&/^\d+$/.test(n.e.v)?{e:g(e,t.e,o(`${n.e.v}s`)),type:`time`}:{e:g(e,t.e,g(`*`,n.e,o(`1s`))),type:`time`}:{e:g(e,t.e,n.e),type:t.type===`number`&&n.type===`number`?`number`:`unknown`,real:(t.real??!1)||(n.real??!1)}}function rn(e){return e.replace(/^(-?)\./,`$10.`).replace(/\.(?=$|[eE])/,`.0`)}function an(e,t){let n=e=>e.k===`call`&&e.fn===`concat`?e.args.map(e=>e.value):[e];return x(`concat`,...n(e),...n(t))}const F=(e,t=`unknown`,n)=>(r,i,a)=>{if(n!==void 0&&r.length!==n)throw I(a,n);return{e:x(e,...r.map(e=>P(e,i).e)),type:t}};function on(e,t){let n=e[0];if(n===void 0)throw new A(`SPL1004`,t.span,`${t.fn}() expects at least 1 argument.`);return n}const sn=(e,t,n)=>{throw new A(`SPL2004`,n.fnSpan,`${n.fn}() has no DQL equivalent.`)};function I(e,t){return new A(`SPL1004`,e.span,`${e.fn}() expects ${t} argument${t===1?``:`s`}.`)}function cn(e,t,n){if(e?.t!==`str`)throw new A(`SPL2004`,t.span,`${t.fn}() needs ${n} as a quoted literal to be translated.`);return e.v}function ln(e){if(e?.t===`num`&&/^-?\d+$/.test(e.v))return Number(e.v)}const un=k({if:(e,t,n)=>{if(e.length!==3)throw I(n,3);let[r,i,a]=e.map(e=>P(e,t));return{e:x(`if`,r.e,i.e,b(`else`,a.e)),type:i.type}},case:(e,t,n)=>{if(e.length<2||e.length%2!=0)throw new A(`SPL1004`,n.span,`case() needs condition/value pairs.`);let i=[];for(let t=0;t<e.length;t+=2)i.push([e[t],e[t+1]]);let a,o=i[i.length-1];o&&vn(o[0])&&(a=P(o[1],t).e,i.pop());let s=a;for(let e=i.length-1;e>=0;e--){let[n,r]=i[e],a=P(n,t).e,o=P(r,t).e;s=s===void 0?x(`if`,a,o):x(`if`,a,o,b(`else`,s))}return{e:s??r(),type:`unknown`}},coalesce:F(`coalesce`),nullif:(e,t,n)=>{if(e.length!==2)throw I(n,2);let i=P(e[0],t),a=P(e[1],t);return{e:x(`if`,g(`==`,i.e,a.e),r(),b(`else`,i.e)),type:i.type}},isnull:F(`isNull`,`bool`,1),isnotnull:F(`isNotNull`,`bool`,1),isnum:dn(t=>x(`in`,x(`type`,t),d([e(`long`),e(`double`)]))),isint:dn(t=>g(`==`,x(`type`,t),e(`long`))),isstr:dn(t=>g(`==`,x(`type`,t),e(`string`))),isbool:dn(t=>g(`==`,x(`type`,t),e(`boolean`))),typeof:(e,t,n)=>{let r=on(e,n);return t.report(`SPL3006`,n.span,{detail:`typeof() returns DQL type names (long, double, string …), not Splunk ones.`}),{e:x(`type`,P(r,t).e),type:`string`}},len:F(`stringLength`,`number`,1),lower:F(`lower`,`string`,1),upper:F(`upper`,`string`,1),trim:(e,t,n)=>{if(e.length!==1)throw new A(`SPL2004`,n.span,`trim() with a character list has no DQL equivalent.`);return{e:x(`trim`,P(e[0],t).e),type:`string`}},ltrim:sn,rtrim:sn,substr:hn,replace:(t,n,r)=>{if(t.length!==3)throw I(r,3);let i=P(t[0],n).e,a=cn(t[1],r,`the regular expression`),o=cn(t[2],r,`the replacement`);if(/\\\d/.test(o))throw new A(`SPL2006`,r.span,`Back-references in the replacement have no DQL equivalent.`);let c=Et(a);if(c!==void 0)return{e:x(`replaceString`,i,e(c),e(o)),type:`string`};let l=wt(a,{});if(!l.ok)throw new A(`SPL2006`,t[1].span,l.reason);return n.report(`SPL3008`,t[1].span),{e:x(`replacePattern`,i,s(xn(l.dpl)),e(o)),type:`string`}},split:F(`splitString`,`array`,2),mvindex:(e,n,r)=>{let i=P(on(e,r),n).e,a=ln(e[1]);if(e.length===2){if(a===void 0)throw new A(`SPL2004`,r.span,`mvindex() needs a literal position to be translated.`);return{e:_(i,a),type:`unknown`}}if(e.length!==3)throw I(r,3);let o=ln(e[2]);if(a===void 0||o===void 0){n.report(`SPL3007`,r.span);let a=P(e[1],n).e,o=g(`+`,P(e[2],n).e,t(1));return{e:x(`arraySlice`,i,b(`from`,a),b(`to`,o)),type:`array`}}return o===-1?{e:x(`arraySlice`,i,b(`from`,t(a))),type:`array`}:{e:x(`arraySlice`,i,b(`from`,t(a)),b(`to`,t(o+1))),type:`array`}},mvcount:(e,t,n)=>(t.report(`SPL3013`,n.span,{detail:`mvcount() counts array elements; a single value that is not an array has no count in DQL.`}),{e:x(`arraySize`,P(on(e,n),t).e),type:`number`}),mvjoin:(e,t,n)=>{if(e.length!==2)throw I(n,2);return{e:x(`arrayToString`,P(e[0],t).e,b(`delimiter`,P(e[1],t).e)),type:`string`}},mvappend:(e,t)=>({e:w(`arrayConcat`,e.map(e=>x(`toArray`,P(e,t).e))),type:`array`}),mvdedup:F(`arrayDistinct`,`array`,1),mvsort:F(`arraySort`,`array`,1),mvfilter:(e,t,n)=>{let r=e[0],a=/* @__PURE__ */ new Set;if(r&&yn(r,a),!r||a.size!==1)throw new A(`SPL2004`,n.span,`mvfilter() can only be translated when the condition uses one field.`);let o=[...a][0],s=t.field(o,n.span),c=P(r,t).e;return{e:x(`arrayRemoveNulls`,x(`iCollectArray`,x(`if`,bn(c,s),_(i(s))))),type:`array`}},mvfind:sn,mvzip:sn,mvrange:sn,mvmap:sn,tostring:(t,n,r)=>{let i=P(on(t,r),n).e;if(t.length===1)return{e:x(`toString`,i),type:`string`};let a=cn(t[1],r,`the format`);if(a===`hex`)return{e:x(`concat`,e(`0x`),x(`numberToHexString`,i)),type:`string`};throw new A(`SPL2004`,r.span,`tostring() with format "${a}" has no DQL equivalent.`)},tonumber:(e,t,n)=>{let r=P(on(e,n),t).e;if(e.length===1)return{e:x(`toDouble`,r),type:`number`,real:!0};if(ln(e[1])===16)return{e:x(`hexStringToNumber`,r),type:`number`};if(ln(e[1])===10)return{e:x(`toDouble`,r),type:`number`,real:!0};throw new A(`SPL2004`,n.span,`tonumber() only translates for base 10 and 16.`)},round:(e,t,n)=>{let r=P(on(e,n),t).e;if(e.length===1)return{e:x(`round`,r),type:`number`};let i=ln(e[1]);if(i!==void 0&&i<0)throw new A(`SPL2004`,n.span,`round() to negative decimals has no DQL equivalent.`);return{e:x(`round`,r,b(`decimals`,P(e[1],t).e)),type:`number`}},floor:F(`floor`,`number`,1),ceil:F(`ceil`,`number`,1),ceiling:F(`ceil`,`number`,1),abs:F(`abs`,`number`,1),sqrt:F(`sqrt`,`number`,1),exp:F(`exp`,`number`,1),pow:F(`power`,`number`,2),ln:F(`log`,`number`,1),log:(e,t,n)=>{let r=P(on(e,n),t).e;return e.length===1?{e:x(`log10`,r),type:`number`}:{e:g(`/`,x(`log`,r),x(`log`,P(e[1],t).e)),type:`number`}},pi:F(`pi`,`number`,0),exact:(e,t,n)=>P(on(e,n),t),sigfig:sn,printf:sn,max:fn(`arrayMax`),min:fn(`arrayMin`),random:()=>({e:x(`toLong`,g(`*`,x(`random`),t(2147483647))),type:`number`}),like:F(`like`,`bool`,2),match:(e,t,n)=>{if(e.length!==2)throw I(n,2);let r=P(e[0],t).e,i=wt(cn(e[1],n,`the regular expression`),{forMatch:!0});if(!i.ok)throw new A(`SPL2006`,e[1].span,i.reason);return t.report(`SPL3008`,e[1].span),{e:x(`matchesPattern`,r,s(i.dpl)),type:`bool`}},searchmatch:(e,t,r)=>{let i=e[0];if(i?.t!==`str`)throw new A(`SPL2004`,r.span,`searchmatch() needs a quoted search.`);let a=i.v,o=et(a,0,a.length);return t.report(`SPL3011`,r.span),o?{e:ze(o,t,a,!0),type:`bool`}:{e:n(!0),type:`bool`}},cidrmatch:(e,t,n)=>{if(e.length!==2)throw I(n,2);return{e:x(`ipIn`,P(e[1],t).e,P(e[0],t).e),type:`bool`}},in:(e,t,n)=>{if(e.length<2)throw I(n,2);return{e:x(`in`,P(e[0],t).e,d(e.slice(1).map(e=>P(e,t).e))),type:`bool`}},md5:F(`hashMd5`,`string`,1),sha1:F(`hashSha1`,`string`,1),sha256:F(`hashSha256`,`string`,1),sha512:F(`hashSha512`,`string`,1),urldecode:F(`decodeUrl`,`string`,1),spath:pn,json_extract:pn,validate:sn,true:()=>({e:n(!0),type:`bool`}),false:()=>({e:n(!1),type:`bool`}),null:()=>({e:r(),type:`unknown`}),now:()=>({e:x(`now`),type:`time`}),time:()=>({e:x(`now`),type:`time`}),relative_time:(e,t,n)=>{if(e.length!==2)throw I(n,2);let r=P(e[0],t),i=cn(e[1],n,`the time modifier`);return{e:gn(r.type===`time`?r.e:x(`timestampFromUnixSeconds`,x(`toLong`,r.e)),i,n),type:`time`}},strftime:(t,n,r)=>{if(t.length!==2)throw I(r,2);let i=P(t[0],n),a=cn(t[1],r,`the format`),o=i.type===`time`?i.e:x(`timestampFromUnixSeconds`,x(`toLong`,i.e));if(a===`%s`)return{e:x(`unixSecondsFromTimestamp`,o),type:`number`};let s=Yt(a);if(!s.ok)throw new A(`SPL2004`,t[1].span,`The format directive ${s.directive} has no DQL equivalent.`);return n.report(`SPL3010`,r.span),{e:x(`formatTimestamp`,o,b(`format`,e(s.format))),type:`string`}},strptime:(e,t,n)=>{if(e.length!==2)throw I(n,2);let r=P(e[0],t).e,i=Yt(cn(e[1],n,`the format`));if(!i.ok)throw new A(`SPL2004`,e[1].span,`The format directive ${i.directive} has no DQL equivalent.`);return t.report(`SPL3010`,n.span),{e:x(`parse`,r,s(`TIMESTAMP('${i.format.replace(/'/g,`\\'`)}'):t`)),type:`time`}}});function dn(e){return(t,n,r)=>{let i=on(t,r);return n.report(`SPL3006`,r.span,{detail:`${r.fn}() tests the stored type in DQL, not whether the text looks like a number.`}),{e:e(P(i,n).e),type:`bool`}}}function fn(e){return(t,n,r)=>(n.report(`SPL3006`,r.span,{detail:`${r.fn}() of several values ignores values that are not numbers in DQL.`}),{e:x(e,w(`array`,t.map(e=>P(e,n).e))),type:`number`})}function pn(t,n,r){if(t.length!==2)throw I(r,2);let i=P(t[0],n).e,a=cn(t[1],r,`the path`);return{e:x(`jsonPath`,i,e(mn(a))),type:`unknown`}}function mn(e){return`$.${e.replace(/\{\}/g,`[*]`).replace(/\{(\d+)\}/g,`[$1]`)}`}function hn(e,n,r){if(e.length<2||e.length>3)throw I(r,3);let i=P(e[0],n).e,a=ln(e[1]),o=e.length===3?ln(e[2]):void 0;if(a!==void 0&&(e.length===2||o!==void 0)){if(a<0){if(o===void 0)return{e:x(`substring`,i,b(`from`,t(a))),type:`string`};let e=a+o;return e>=0?{e:x(`substring`,i,b(`from`,t(a))),type:`string`}:{e:x(`substring`,i,b(`from`,t(a)),b(`to`,t(e))),type:`string`}}let e=Math.max(0,a-1);return o===void 0?{e:x(`substring`,i,b(`from`,t(e))),type:`string`}:{e:x(`substring`,i,b(`from`,t(e)),b(`to`,t(e+o))),type:`string`}}n.report(`SPL3007`,r.span);let s=g(`-`,P(e[1],n).e,t(1));return e.length===2?{e:x(`substring`,i,b(`from`,s)),type:`string`}:{e:x(`substring`,i,b(`from`,s),b(`to`,g(`+`,s,P(e[2],n).e))),type:`string`}}function gn(e,t,n){let r=/^([+-]\d+)([A-Za-z]*)?(?:@([A-Za-z]+\d?))?$/.exec(t.trim())??/^()()@([A-Za-z]+\d?)$/.exec(t.trim());if(!r)throw new A(`SPL2004`,n.span,`relative_time() with "${t}" cannot be translated.`);let i=e;if(r[1]){let e=Oe(r[2]||`s`);if(!e)throw new A(`SPL2004`,n.span,`Unknown time unit in "${t}".`);let a=r[1].replace(/^[+-]/,``);i=g(r[1].startsWith(`-`)?`-`:`+`,i,o(`${a}${e}`))}if(r[3]){let e=r[3].toLowerCase(),a=e.startsWith(`w`)?e===`w`||e===`w7`?`w0`:e:Oe(e);if(!a)throw new A(`SPL2004`,n.span,`Unknown snap unit in "${t}".`);i=v(i,a)}return i}function _n(e,t){let n=Object.hasOwn(un,e.fn)?un[e.fn]:void 0;if(!n)throw new A(`SPL2004`,e.fnSpan,`${e.fn}() is not a function the translator knows.`);return n(e.args,t,e)}function vn(e){return e.t===`call`&&e.fn===`true`&&e.args.length===0||e.t===`bin`&&(e.op===`=`||e.op===`==`)&&e.l.t===`num`&&e.r.t===`num`&&e.l.v===e.r.v}function yn(e,t){if(e.t===`field`)t.add(e.name);else if(e.t===`call`)for(let n of e.args)yn(n,t);else if(e.t===`un`)yn(e.e,t);else if(e.t===`bin`)yn(e.l,t),yn(e.r,t);else if(e.t===`in`){yn(e.e,t);for(let n of e.list)yn(n,t)}}function bn(e,t){return e.k===`field`&&e.name===t?_(e):e.k===`call`?{...e,args:e.args.map(e=>({...e,value:bn(e.value,t)}))}:e.k===`un`?{...e,e:bn(e.e,t)}:e.k===`bin`?{...e,l:bn(e.l,t),r:bn(e.r,t)}:e.k===`block`?{...e,items:e.items.map(e=>bn(e,t))}:e}function xn(e){return e.startsWith(`DATA? `)?e.slice(6):e}const Sn=[{name:`rex`,tier:`T2`,summary:`parse field, "<pattern>" for the convertible regex subset; mode=sed → replaceString/replacePattern.`,lower(n){let r=n.scanner(),a=`_raw`,o=n.span,c=!1,l=1,u;for(;!r.atEnd();){let e=r.option();if(e){let t=e.name.toLowerCase();if(t===`field`)a=e.value,o=e.valueSpan;else if(t===`mode`&&e.value.toLowerCase()===`sed`)c=!0;else if(t===`max_match`&&/^\d{1,6}$/.test(e.value))l=Number(e.value);else throw new A(`SPL2003`,e.span,`rex ${e.name}=${e.value} cannot be translated.`);continue}let t=r.quoted();if(!t||u)throw new A(`SPL1003`,r.here(),`rex needs one quoted regular expression.`);u=t}if(!u)throw new A(`SPL1003`,n.span,`rex needs a quoted regular expression.`);let d=n.field(a,o);if(c){let t=/^s\/((?:\\.|[^/\\])*)\/((?:\\.|[^/\\])*)\/([gi0-9]*)$/.exec(u.value);if(!t)throw new A(`SPL2003`,u.span,`Only s/regex/replacement/ sed expressions can be translated.`);let[,r,a,o]=t;if(/\\\d/.test(a))throw new A(`SPL2006`,u.span,`Back-references in the replacement have no DQL equivalent.`);o.includes(`g`)||n.report(`SPL3008`,u.span,{detail:`Without the g flag sed replaces the first match only; DQL replaces every match.`});let c=a.replace(/\\\//g,`/`),l=Et(r.replace(/\\\//g,`/`));if(l!==void 0){n.emit(S(`fieldsAdd`,f(d,x(`replaceString`,i(d),e(l),e(c)))));return}let p=wt(r.replace(/\\\//g,`/`),{});if(!p.ok)throw new A(`SPL2006`,u.span,p.reason);n.report(`SPL3008`,u.span);let m=p.dpl.startsWith(`DATA? `)?p.dpl.slice(6):p.dpl;n.emit(S(`fieldsAdd`,f(d,x(`replacePattern`,i(d),s(m),e(c)))));return}let p=wt(u.value,l===1?{captures:!0}:{captures:!0,everyMatch:!0});if(!p.ok){for(let e of u.value.matchAll(/\(\?P?<([A-Za-z_][A-Za-z0-9_]*)>/g))n.state.unresolved.add(e[1]);throw new A(`SPL2006`,u.span,p.reason)}if(p.captures.length===0)throw new A(`SPL2003`,u.span,`rex without named groups (?<name>…) extracts nothing.`);if(l!==1){let e=p.captures[0];if(p.captures.length!==1||!e||p.anchoredStart){for(let e of p.captures)n.state.unresolved.add(e.name);throw new A(`SPL2003`,u.span,`rex max_match is only translated for one named group and a pattern without "^".`)}n.report(`SPL3008`,u.span),n.report(`SPL3013`,n.span,{detail:`The matches are returned as an array, not as a Splunk multivalue field.`});let r=x(`parseAll`,i(d),s(p.dpl)),a=n.field(e.name,u.span,!0);n.emit(S(`fieldsAdd`,f(a,l===0?r:x(`arraySlice`,r,b(`from`,t(0)),b(`to`,t(l)))))),n.setType(a,void 0),n.addFields([e.name])}else{n.report(`SPL3008`,u.span),n.emit(S(`parse`,i(d),s(p.dpl)));for(let e of p.captures)n.setType(n.field(e.name,u.span,!0),e.type===`number`?`number`:`string`);n.addFields(p.captures.map(e=>e.name))}}},{name:`spath`,tier:`T2`,summary:`jsonPath() for one path; without a path, parse content as JSON and flatten.`,lower(t){let n=t.scanner(),r=`_raw`,a,o;for(;!n.atEnd();){let e=n.option();if(e){let t=e.name.toLowerCase();if(t===`input`)r=e.value;else if(t===`path`)a=e.value;else if(t===`output`)o=e.value;else throw new A(`SPL2003`,e.span,`spath ${e.name}= cannot be translated.`);continue}let t=n.value();if(!t||a!==void 0)throw new A(`SPL1003`,n.here(),`Unexpected text in spath.`);a=t.value}let c=i(t.field(r,t.span));if(a===void 0){t.report(`SPL3016`,t.span,{detail:`JSON fields get Grail names (json.a.b) instead of Splunk names (a.b{}.c).`}),t.emit(S(`parse`,c,s(`JSON:json`))),t.emit(S(`fieldsFlatten`,i(`json`)));return}a.includes(`{}`)&&t.report(`SPL3013`,t.span,{detail:`An array path returns an array in DQL.`});let l=t.field(o??a,t.span,!0);t.emit(S(`fieldsAdd`,f(l,x(`jsonPath`,c,e(mn(a)))))),t.addFields([l])}}];var Cn=class extends Error{span;constructor(e,t){super(e),this.span=t}};const wn=2e4;function Tn(e,t,n){let r=new On(En(e,t,n)),i=r.expr();return r.expectEnd(),i}function En(e,t,n){let r=[],i=t;for(;i<n;){let t=e[i];if(/\s/.test(t)){i++;continue}let a=i;if(t===`"`){let t=O(e,i,n);if(t===-1)throw new Cn(`A quoted string is not closed.`,{start:i,end:n});r.push({type:`str`,text:ve(e.slice(i+1,t)),span:{start:a,end:t+1}}),i=t+1;continue}if(t===`$`){let t=/^\$[A-Za-z_][A-Za-z0-9_.]*(?:\|[A-Za-z]+)?\$/.exec(e.slice(i,Math.min(n,i+200)));if(t){r.push({type:`str`,text:t[0],span:{start:a,end:i+t[0].length}}),i+=t[0].length;continue}}if(t===`'`){let t=e.indexOf(`'`,i+1);if(t===-1||t>=n)throw new Cn(`A quoted field name is not closed.`,{start:i,end:n});r.push({type:`field`,text:e.slice(i+1,t),span:{start:a,end:t+1}}),i=t+1;continue}if(/[0-9]/.test(t)||t===`.`&&/[0-9]/.test(e[i+1]??``)){let t=/^(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?/.exec(e.slice(i,Math.min(n,i+64))),o=t?t[0].length:1;if(/[A-Za-z_]/.test(e[i+o]??``)){i=Dn(e,i,n,r);continue}r.push({type:`num`,text:e.slice(i,i+o),span:{start:a,end:i+o}}),i+=o;continue}if(/[A-Za-z_]/.test(t)){i=Dn(e,i,n,r);continue}let o=e.slice(i,i+2);if(o===`==`||o===`!=`||o===`<=`||o===`>=`)r.push({type:`op`,text:o,span:{start:a,end:i+2}}),i+=2;else if(`=<>+-*/%.`.includes(t))r.push({type:`op`,text:t,span:{start:a,end:i+1}}),i++;else if(t===`(`||t===`)`||t===`,`)r.push({type:t,text:t,span:{start:a,end:i+1}}),i++;else throw new Cn(`Unexpected character "${t}".`,{start:i,end:i+1})}if(r.push({type:`eof`,text:``,span:{start:n,end:n}}),r.length>wn)throw new Cn(`The expression has more than ${wn} parts.`,{start:t,end:n});return r}function Dn(e,t,n,r){let i=t;for(;t<n&&/[A-Za-z0-9_.{}@:]/.test(e[t])&&(e[t]!==`.`||/[A-Za-z0-9_{]/.test(e[t+1]??``));)t++;return r.push({type:`ident`,text:e.slice(i,t),span:{start:i,end:t}}),t}var On=class{i=0;depth=0;toks;constructor(e){this.toks=e}get t(){return this.toks[this.i]??this.toks[this.toks.length-1]}ty(){return this.t.type}next(){return this.toks[this.i++]??this.toks[this.toks.length-1]}word(e){return this.t.type===`ident`&&this.t.text.toUpperCase()===e}op(e){return this.t.type===`op`&&this.t.text===e}fail(e){throw new Cn(`${e}, found ${this.t.type===`eof`?`the end`:`"${this.t.text}"`}.`,this.t.span)}expectEnd(){this.t.type!==`eof`&&this.fail(`Unexpected text in expression`)}guard(e){if(++this.depth>200)throw new Cn(`The expression is nested too deeply.`,this.t.span);try{return e()}finally{this.depth--}}expr(){return this.guard(()=>this.left([`XOR`],()=>this.left([`OR`],()=>this.left([`AND`],()=>this.notExpr()))))}left(e,t){let n=t();for(;e.some(e=>this.word(e));){let e=this.next().text.toUpperCase(),r=t();n={t:`bin`,op:e,l:n,r,span:{start:n.span.start,end:r.span.end}}}return n}notExpr(){if(this.word(`NOT`)){let e=this.next().span.start,t=this.guard(()=>this.notExpr());return{t:`un`,op:`NOT`,e:t,span:{start:e,end:t.span.end}}}return this.comparison()}comparison(){let e=this.additive(),t=this.t;if(t.type===`op`&&[`=`,`==`,`!=`,`<`,`<=`,`>`,`>=`].includes(t.text)){this.next();let n=this.additive();return{t:`bin`,op:t.text,l:e,r:n,span:{start:e.span.start,end:n.span.end}}}if(this.word(`LIKE`)){this.next();let t=this.additive();return{t:`bin`,op:`LIKE`,l:e,r:t,span:{start:e.span.start,end:t.span.end}}}if(this.word(`IN`)){this.next(),this.t.type!==`(`&&this.fail(`Expected "(" after IN`),this.next();let t=[];if(this.ty()!==`)`)for(t.push(this.expr());this.ty()===`,`;)this.next(),t.push(this.expr());this.ty()!==`)`&&this.fail(`Expected ")"`);let n=this.next().span.end;return{t:`in`,e,list:t,span:{start:e.span.start,end:n}}}return e}additive(){let e=this.multiplicative();for(;this.op(`+`)||this.op(`-`)||this.op(`.`);){let t=this.next().text,n=this.multiplicative();e={t:`bin`,op:t,l:e,r:n,span:{start:e.span.start,end:n.span.end}}}return e}multiplicative(){let e=this.unary();for(;this.op(`*`)||this.op(`/`)||this.op(`%`);){let t=this.next().text,n=this.unary();e={t:`bin`,op:t,l:e,r:n,span:{start:e.span.start,end:n.span.end}}}return e}unary(){if(this.op(`-`)){let e=this.next().span.start,t=this.guard(()=>this.unary());return t.t===`num`?{t:`num`,v:`-${t.v}`,span:{start:e,end:t.span.end}}:{t:`un`,op:`-`,e:t,span:{start:e,end:t.span.end}}}return this.op(`+`)?(this.next(),this.guard(()=>this.unary())):this.primary()}primary(){let e=this.t;switch(e.type){case`num`:return this.next(),{t:`num`,v:e.text,span:e.span};case`str`:return this.next(),{t:`str`,v:e.text,span:e.span};case`field`:return this.next(),{t:`field`,name:e.text,span:e.span};case`ident`:if(this.next(),this.t.type===`(`){this.next();let t=[];if(this.ty()!==`)`)for(t.push(this.expr());this.ty()===`,`;)this.next(),t.push(this.expr());this.ty()!==`)`&&this.fail(`Expected ")" to close the function call`);let n=this.next().span.end;return{t:`call`,fn:e.text.toLowerCase(),args:t,span:{start:e.span.start,end:n},fnSpan:e.span}}return{t:`field`,name:e.text,span:e.span};case`(`:{this.next();let e=this.expr();return this.ty()!==`)`&&this.fail(`Expected ")"`),this.next(),e}default:return this.fail(`Expected a value`)}}};function kn(e,t=[]){let n=[];for(;!(e.atEnd()||t.some(t=>e.peekKeyword(t)));){if(e.eat(`,`))continue;if(/^[A-Za-z_][A-Za-z0-9_]*\s*=(?!=)/.test(e.text.slice(e.pos,Math.min(e.end,e.pos+80))))break;let t=e.fieldName();if(!t)throw new A(`SPL1003`,e.here(),`Expected a field name.`);n.push({name:t.value,span:t.span})}return n}function An(e,t){if(e.state.schema.kind!==`events`)return e.state.schema.fields.filter(n=>Xe(t,e.splName(n)))}const jn={name:`table`,tier:`T1`,summary:`fields a, b (wildcards → fieldsKeep "a*").`,lower(t){let n=kn(t.scanner());if(n.length===0)throw new A(`SPL1003`,t.span,`table needs at least one field.`);let r=[],a=!1;for(let e of n)if(e.name.includes(`*`)){let n=An(t,e.name);n?j(r,n):a=!0}else r.push(t.field(e.name,e.span));a?(t.report(`SPL2009`,t.span,{detail:`Wildcards keep matching fields, but the column order of table is not reproduced.`}),t.emit(C(`fieldsKeep`,n.map(n=>n.name.includes(`*`)?e(n.name):i(t.field(n.name,n.span))))),t.setTable(r)):(t.emit(C(`fields`,r.map(i))),t.setTable(r))}},Mn={name:`fields`,tier:`T1`,summary:`fieldsKeep / fieldsRemove; on raw events timestamp and content are kept, as Splunk keeps _time and _raw.`,lower(t){let n=t.scanner(),r=!1;n.eat(`-`)?r=!0:n.eat(`+`);let a=kn(n);if(a.length===0)throw new A(`SPL1003`,t.span,`fields needs at least one field.`);if(r){a.some(e=>e.name.startsWith(`_`)&&e.name.includes(`*`))&&t.report(`SPL2009`,t.span,{detail:`Removing internal fields (_*) has no direct equivalent; they were kept.`});let n=a.filter(e=>!(e.name.startsWith(`_`)&&e.name.includes(`*`)));if(n.length===0)return;if(t.emit(C(`fieldsRemove`,n.map(n=>n.name.includes(`*`)?e(n.name):i(t.field(n.name,n.span))))),t.state.schema.kind!==`events`){let e=new Set(n.map(e=>t.field(e.name,e.span,!0)));t.setTable(t.state.schema.fields.filter(r=>!e.has(r)&&!n.some(e=>e.name.includes(`*`)&&Xe(e.name,t.splName(r)))))}return}let o=[],s=[];for(let n of a){if(n.name.includes(`*`)){o.push(e(n.name));continue}let r=t.field(n.name,n.span);o.push(i(r)),s.push(r)}if(t.state.schema.kind===`events`)for(let e of[`timestamp`,`content`])s.includes(e)||o.push(i(e));t.emit(C(`fieldsKeep`,o)),a.every(e=>!e.name.includes(`*`))&&t.setTable(t.state.schema.kind===`events`?[...s,`timestamp`,`content`]:s)}},Nn={name:`rename`,tier:`T1`,summary:`fieldsRename new = old.`,lower(e){if(e.state.datamodel&&/^\s*"?[A-Za-z_][A-Za-z0-9_.]*"?\.\*\s+as\s+\*\s*$/i.test(e.slice(e.argsSpan))){e.report(`SPL5007`,e.span,{detail:`The data-model prefix is not carried into DQL, so this rename has nothing to do.`});return}let t=e.scanner(),n=[],r=[],a=0;for(;!t.atEnd();){if(t.eat(`,`))continue;let o=t.fieldName();if(!o||!t.keyword(`as`))throw new A(`SPL1003`,t.here(),`Expected "field AS newname".`);let s=t.fieldName();if(!s)throw new A(`SPL1003`,t.here(),`Expected a new name after AS.`);if(o.value.includes(`*`)||s.value.includes(`*`))throw new A(`SPL2009`,o.span,`Renaming with wildcards needs the list of fields.`);let c=e.field(o.value,o.span),l=e.field(s.value,s.span,!0);c===l?a++:(n.push(f(l,i(c))),r.push([c,l]))}if(!(n.length===0&&a>0)){if(n.length===0)throw new A(`SPL1003`,e.span,`rename needs "field AS newname".`);e.emit(C(`fieldsRename`,n)),e.state.schema.kind!==`events`&&e.setTable(e.state.schema.fields.map(e=>r.find(([t])=>t===e)?.[1]??e))}}};function Pn(n){return!n.quoted&&/^-?\d+(\.\d+)?$/.test(n.value)?t(n.value):e(n.value)}const Fn={name:`fillnull`,tier:`T1`,summary:`fieldsAdd f = coalesce(f, value).`,lower(e){let n=e.scanner(),r=t(0),a=n.option();if(a){if(a.name.toLowerCase()!==`value`)throw new A(`SPL2003`,a.span,`Option ${a.name} is not supported.`);r=Pn(a)}let o=kn(n),s=o.map(t=>t.name.includes(`*`)?void 0:e.field(t.name,t.span));if(o.length===0||s.includes(void 0)){let t=e.state.schema.kind===`events`?void 0:e.state.schema.fields;if(!t)throw new A(`SPL2009`,e.span,`fillnull without a field list needs the list of fields.`);s=o.length===0?t:t.filter(t=>o.some(n=>Xe(n.name,e.splName(t))))}let c=s.map(e=>f(e,x(`coalesce`,i(e),r)));c.length>0&&e.emit(C(`fieldsAdd`,c))}},In={name:`replace`,tier:`T1`,summary:`fieldsAdd f = if(f == "x", "y", else: f).`,lower(t){let n=t.scanner(),r=[];for(;!n.peekKeyword(`in`);){if(n.eat(`,`))continue;let e=n.value();if(!e||!n.keyword(`with`))throw new A(`SPL1003`,n.here(),`Expected "value WITH replacement".`);let t=n.value();if(!t)throw new A(`SPL1003`,n.here(),`Expected a replacement after WITH.`);if(e.value.includes(`*`)||t.value.includes(`*`))throw new A(`SPL2009`,e.span,`Wildcard replacements are not supported.`);r.push([e,t])}if(!n.keyword(`in`))throw new A(`SPL2003`,t.span,`replace without IN <fields> needs the list of fields.`);if(r.length>500)throw new A(`SPL1006`,t.span,`replace has more than 500 value pairs; translate it in parts.`);let a=kn(n),o=[];for(let n of a){if(n.name.includes(`*`))throw new A(`SPL2009`,n.span,`Wildcard field names need the list of fields.`);let a=t.field(n.name,n.span),s=i(a);for(let t=r.length-1;t>=0;t--){let[n,o]=r[t];s=x(`if`,g(`==`,i(a),e(n.value)),e(o.value),b(`else`,s))}o.push(f(a,s))}t.emit(C(`fieldsAdd`,o))}},Ln={name:`convert`,tier:`T2`,summary:`ctime() → formatTimestamp, num()/auto() → toDouble.`,lower(t){let n=t.scanner(),r=`MM/dd/yyyy HH:mm:ss`,a=[];for(;!n.atEnd();){if(n.eat(`,`))continue;let o=n.option();if(o){if(o.name.toLowerCase()!==`timeformat`)throw new A(`SPL2003`,o.span,`Option ${o.name} is not supported.`);let e=Yt(o.value);if(!e.ok)throw new A(`SPL2003`,o.valueSpan,`The format directive ${e.directive} has no DQL equivalent.`);r=e.format;continue}let s=n.word(`(`),c=n.balanced(`(`,`)`);if(!s||!c)throw new A(`SPL1003`,n.here(),`Expected a conversion such as ctime(field).`);let l=t.slice(c.inner).trim(),u=l;if(n.keyword(`as`)){let e=n.fieldName();if(!e)throw new A(`SPL1003`,n.here(),`Expected a name after AS.`);u=e.value}let d=t.field(l,c.inner),p=i(d),m=t.fieldType(d)===`time`,h=t.field(u,c.inner,!0);switch(s.value.toLowerCase()){case`ctime`:t.report(`SPL3010`,s.span),a.push(f(h,x(`formatTimestamp`,m?p:x(`timestampFromUnixSeconds`,x(`toLong`,p)),b(`format`,e(r))))),t.setType(h,`string`);break;case`num`:case`auto`:a.push(f(h,x(`toDouble`,p))),t.setType(h,`number`);break;case`none`:break;default:throw new A(`SPL2003`,s.span,`convert ${s.value}() has no DQL equivalent.`)}}a.length>0&&t.emit(C(`fieldsAdd`,a))}},Rn={name:`addtotals`,tier:`T2`,summary:`fieldsAdd Total = coalesce(a, 0) + coalesce(b, 0) for listed fields.`,lower(e){let n=e.scanner(),r=`Total`;for(let e=n.option();e;e=n.option()){let t=e.name.toLowerCase();if(t===`fieldname`)r=e.value;else if(t===`row`&&/^(t|true|1)$/i.test(e.value))continue;else if(t===`col`&&/^(f|false|0)$/i.test(e.value))continue;else throw new A(`SPL2003`,e.span,`addtotals ${e.name}=${e.value} has no DQL equivalent.`)}let a=kn(n);if(a.length===0||a.some(e=>e.name.includes(`*`)))throw new A(`SPL2009`,e.span,`addtotals needs an explicit list of fields to sum.`);let o=a.map(n=>x(`coalesce`,i(e.field(n.name,n.span)),t(0))).reduce((e,t)=>e?g(`+`,e,t):t,void 0);e.emit(S(`fieldsAdd`,f(e.field(r,e.span,!0),o))),e.addFields([r])}},zn={name:`foreach`,tier:`T2`,summary:`Expands the template for each listed field into fieldsAdd.`,lower(e){let t=e.scanner();for(;t.option(););let n=[];for(;t.peek()!==`[`&&!t.atEnd();){if(t.eat(`,`))continue;let e=t.fieldName();if(!e)throw new A(`SPL1003`,t.here(),`Expected field names before the [ … ] template.`);n.push({name:e.value,span:e.span})}let r=t.balanced(`[`,`]`);if(!r||n.length===0)throw new A(`SPL1003`,e.span,`foreach needs fields and a [ eval … ] template.`);let i=e.slice(r.inner).trim(),a=/^eval\s+(.+)$/is.exec(i);if(!a)throw new A(`SPL2003`,r.span,`Only an eval template can be translated.`);let o=[];for(let t of n){if(!t.name.includes(`*`)){o.push({field:t.name,match:t.name});continue}let n=An(e,t.name);if(!n)throw new A(`SPL2009`,t.span,`foreach with a wildcard needs the list of fields.`);let[r,i]=[t.name.split(`*`)[0]??``,t.name.split(`*`).slice(-1)[0]??``];for(let t of n){let n=e.splName(t);o.push({field:n,match:n.slice(r.length,n.length-i.length)})}}let s=[],c=a[1];if(o.length*c.length>2e5)throw new A(`SPL1006`,e.span,`foreach would write its template ${o.length} times (${o.length*c.length} characters); the limit is 200000.`);for(let t of o){let n=c.split(`<<FIELD>>`).join(t.field).split(`<<MATCHSTR>>`).join(t.match),i=/^\s*([A-Za-z_][A-Za-z0-9_.]*|'[^']*')\s*=(?!=)([\s\S]+)$/.exec(n);if(!i)throw new A(`SPL1003`,r.span,`The template must be "field = expression".`);let a=i[1].replace(/^'|'$/g,``),o;try{o=Tn(n,n.length-i[2].length,n.length)}catch(e){throw e instanceof Cn?new A(`SPL1004`,r.span,e.message):e}s.push(f(e.field(a,r.span,!0),P(Bn(o,r.span),e).e))}e.emit(C(`fieldsAdd`,s))}};function Bn(e,t){if(Array.isArray(e))return e.map(e=>Bn(e,t));if(e&&typeof e==`object`){let n={};for(let[r,i]of Object.entries(e))n[r]=r===`span`||r===`fnSpan`?t:Bn(i,t);return n}return e}const Vn=[jn,Mn,Nn,Fn,In,Ln,Rn,zn,{name:`makemv`,tier:`T1`,summary:`fieldsAdd f = splitString(f, delim).`,lower(t){let n=t.scanner(),r=` `;for(let e=n.option();e;e=n.option()){let t=e.name.toLowerCase();if(t===`delim`)r=e.value;else if(t===`allowempty`||t===`setsv`)continue;else throw new A(`SPL2003`,e.span,`makemv ${e.name}= has no DQL equivalent.`)}let a=n.fieldName();if(!a)throw new A(`SPL1003`,t.span,`makemv needs a field.`);let o=t.field(a.value,a.span);t.emit(S(`fieldsAdd`,f(o,x(`splitString`,i(o),e(r)))))}},{name:`mvexpand`,tier:`T1`,summary:`expand f.`,lower(e){let n=e.scanner(),r=n.fieldName();if(!r)throw new A(`SPL1003`,e.span,`mvexpand needs a field.`);let a=n.option(),o=i(e.field(r.value,r.span));if(a&&a.name.toLowerCase()===`limit`&&/^\d+$/.test(a.value))e.emit(S(`expand`,o,b(`limit`,t(a.value))));else if(a)throw new A(`SPL2003`,a.span,`mvexpand ${a.name}= is not supported.`);else e.emit(S(`expand`,o))}},{name:`nomv`,tier:`T1`,summary:`fieldsAdd f = arrayToString(f, delimiter: "\\n").`,lower(t){let n=t.scanner().fieldName();if(!n)throw new A(`SPL1003`,t.span,`nomv needs a field.`);let r=t.field(n.value,n.span);t.emit(S(`fieldsAdd`,f(r,x(`arrayToString`,i(r),b(`delimiter`,e(`
2
+ `||e===`\r`)this.pos++;else if(e==="`"&&this.text.startsWith("```",this.pos)){let e=this.text.indexOf("```",this.pos+3);this.pos=e===-1||e+3>this.end?this.end:e+3}else return}}atEnd(){return this.skipWs(),this.pos>=this.end}peek(){return this.skipWs(),this.pos<this.end?this.text[this.pos]:``}eat(e){return this.peek()===e&&(this.pos+=e.length,!0)}keyword(e){if(this.skipWs(),this.text.slice(this.pos,this.pos+e.length).toLowerCase()!==e.toLowerCase())return!1;let t=this.text[this.pos+e.length]??``;return this.pos+e.length<this.end&&/[A-Za-z0-9_]/.test(t)?!1:(this.pos+=e.length,!0)}peekKeyword(e){let t=this.pos,n=this.keyword(e);return this.pos=t,n}option(){this.skipWs();let e=/^[A-Za-z_][A-Za-z0-9_]*\s*=(?!=)/.exec(this.text.slice(this.pos,Math.min(this.end,this.pos+80)));if(!e)return;let t=this.pos,n=e[0].replace(/\s*=$/,``);this.pos+=e[0].length,this.skipWs();let r=this.value();if(!r)this.pos=t;else return{name:n,value:r.value,quoted:r.quoted,span:{start:t,end:r.span.end},valueSpan:r.span}}value(){if(this.skipWs(),this.peek()===`"`){let e=this.quoted();return e?{value:e.value,quoted:!0,span:e.span}:void 0}let e=this.word();return e?{value:e.value,quoted:!1,span:e.span}:void 0}word(e=``){this.skipWs();let t=this.pos;for(;this.pos<this.end;){let t=this.text[this.pos];if(/[\s,()[\]"|]/.test(t)||e.includes(t))break;this.pos++}if(this.pos!==t)return{value:this.text.slice(t,this.pos),span:{start:t,end:this.pos}}}fieldName(){if(this.skipWs(),this.peek()===`"`){let e=this.quoted();return e?{value:e.value,span:e.span,quoted:!0}:void 0}if(this.peek()===`'`){let e=this.text.indexOf(`'`,this.pos+1);if(e!==-1&&e<this.end){let t=this.pos;return this.pos=e+1,{value:this.text.slice(t+1,e),span:{start:t,end:this.pos},quoted:!0}}}let e=this.pos;for(;this.pos<this.end&&/[A-Za-z0-9_.*:{}@\-/$]/.test(this.text[this.pos]);)this.pos++;if(this.pos!==e){if(this.text[this.pos]===`(`){let t=ge(this.text,this.pos,this.end,`(`,`)`);if(t!==-1)return this.pos=t+1,{value:this.text.slice(e,this.pos).replace(/\s+/g,``),span:{start:e,end:this.pos},quoted:!1}}return{value:this.text.slice(e,this.pos),span:{start:e,end:this.pos},quoted:!1}}}quoted(){if(this.skipWs(),this.text[this.pos]!==`"`)return;let e=O(this.text,this.pos,this.end);if(e===-1)return;let t=this.pos;return this.pos=e+1,{value:ve(this.text.slice(t+1,e)),span:{start:t,end:this.pos}}}balanced(e,t){if(this.skipWs(),this.text[this.pos]!==e)return;let n=this.pos,r=ge(this.text,n,this.end,e,t);if(r!==-1)return this.pos=r+1,{inner:{start:n+1,end:r},span:{start:n,end:this.pos}}}integer(){this.skipWs();let e=/^\d{1,9}(?![A-Za-z0-9_.])/.exec(this.text.slice(this.pos,Math.min(this.end,this.pos+12)));if(!e)return;let t=this.pos;return this.pos+=e[0].length,{value:Number(e[0]),span:{start:t,end:this.pos}}}rest(){this.skipWs();let e={start:this.pos,end:this.end};return this.pos=this.end,e}here(){return this.skipWs(),{start:this.pos,end:Math.min(this.end,this.pos+1)}}};function ge(e,t,n,r,i){let a=0;for(let o=t;o<n;o++){let t=e[o];if(t===`"`){let t=O(e,o,n);if(t===-1)return-1;o=t}else if(t===r)a++;else if(t===i&&(a--,a===0))return o}return-1}function _e(e,t,n,r){let i=0;for(let a=t;a<n;a++){let o=e[a];if(o===`"`){let t=O(e,a,n);if(t===-1)return;a=t}else if(o===`(`||o===`[`)i++;else if(o===`)`||o===`]`)i--;else if(i===0&&/[A-Za-z]/.test(o)&&(a===t||/[\s,)]/.test(e[a-1]))){for(let t of r)if(e.slice(a,a+t.length).toLowerCase()===t&&!/[A-Za-z0-9_]/.test(e[a+t.length]??``))return{pos:a,word:t}}}}function ve(e){return e.replace(/\\(["\\])/g,`$1`)}function k(e){let t=Object.create(null);for(let[n,r]of Object.entries(e))t[n]=r;return Object.freeze(t)}const ye=k({_time:`timestamp`,_raw:`content`,host:`host.name`,source:`log.source`,index:`dt.system.bucket`}),be=/^[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)+$/,xe=/* @__PURE__ */ new Set([`_time`,`_raw`,`host`,`source`,`index`,`sourcetype`,`linecount`,`punct`,`splunk_server`,`timestamp`]);var A=class extends Error{code;span;constructor(e,t,n){super(n),this.code=e,this.span=t}},Se=class{text;mapping;options;diags;lowerSub=()=>({commands:[],incomplete:!0});lowerSubsearchFilter=()=>void 0;constructor(e,t,n){this.text=e,this.mapping=t,this.options=n,this.diags=new de(n.strict??!1)}},Ce=class{tc;state;index;command;span;argsSpan;first;next;upstream;depth;prevSeries;prevWasSort;out=[];pre=[];untranslated=!1;constructor(e){this.tc=e.tc,this.state=e.state,this.index=e.index,this.command=e.command,this.span=e.span,this.argsSpan=e.argsSpan,this.first=e.first,this.next=e.following,this.upstream=e.upstream,this.depth=e.depth,this.prevSeries=e.prevSeries,this.prevWasSort=e.prevWasSort}get following(){return this.next.names.slice(this.next.from)}get mapping(){return this.tc.mapping}scanner(){return new he(this.tc.text,this.argsSpan.start,this.argsSpan.end)}slice(e){return this.tc.text.slice(e.start,e.end)}emit(e){this.out.push({...e,origin:[this.index]})}report(e,t=this.span,n={}){this.tc.diags.report(e,t,this.index,n)}giveUp(e,t,n=this.span){this.untranslated=!0,this.out.length=0,this.report(e,n,t===void 0?{}:{detail:t}),this.out.push({name:`//`,args:[],origin:[this.index],comment:`not translated: ${this.slice(this.span)}`})}giveUpSilently(){this.untranslated=!0,this.out.length=0,this.out.push({name:`//`,args:[],origin:[this.index],comment:`not translated: ${this.slice(this.span)}`})}field(e,t,r=!1){let a=this.tc.mapping,o=this.state.datamodel,c=o!==void 0&&!r&&be.test(e)&&!a.fields.has(e)?e.slice(e.lastIndexOf(`.`)+1):e,l=(o!==void 0&&!r?o.entry?.fields.get(c):void 0)??a.fields.get(c),u=ye[c],d=l??u??c;if(r)return this.state.created.add(c),d;if(u!==void 0&&l===void 0&&this.tc.diags.reportOnce(`SPL5002`,t,this.index),this.state.schema.kind!==`events`||this.state.created.has(c)||l!==void 0||u!==void 0||c.includes(`*`))return d;let f=o===void 0?a.extractions.get(c):void 0;if(f){if(!this.state.extracted.has(c)){this.state.extracted.add(c);let e=`${f.from}\u0000${f.dpl}`;this.state.extractedPatterns.has(e)||(this.state.extractedPatterns.add(e),this.pre.push({...S(`parse`,i(f.from),s(f.dpl),b(`preserveFieldsOnFailure`,n(!0))),origin:[this.index]}))}return d}return c===`sourcetype`?(this.report(`SPL4002`,t,{subject:`sourcetype`,detail:`The sourcetype field does not exist in Grail; map the sourcetype instead.`}),d):xe.has(c)?d:o===void 0?this.state.unresolved.has(c)||this.state.opaqueUpstream?(this.report(`SPL4003`,t,{subject:c,detail:`"${c}" is unknown here; it may come from an earlier step that was not translated.`}),d):(this.report(`SPL4003`,t,{subject:c,detail:`"${c}" is not mapped and is not created earlier in the search; in Splunk it is probably extracted at search time.`}),d):(this.report(`SPL4003`,t,{subject:`datamodel:${o.key}:${c}`,detail:`"${c}" has no entry under datamodels → ${o.key} → fields in the mapping file; its Splunk name was kept.`}),d)}fieldType(e){return e===`timestamp`?`time`:this.state.types.get(e)??this.tc.mapping.fieldTypes.get(e)}setType(e,t){t?this.state.types.set(e,t):this.state.types.delete(e)}splName(e){for(let[t,n]of this.tc.mapping.fields)if(n===e)return t;for(let[t,n]of Object.entries(ye))if(n===e)return t;return e}get unorderedEvents(){return this.state.schema.kind===`events`&&!this.state.sorted}setTable(e){this.state.schema={kind:`table`,fields:Te(e)},this.state.created=new Set(this.state.created),this.state.sorted=!1}addFields(e){this.state.schema.kind!==`events`&&(this.state.schema={kind:this.state.schema.kind,fields:Te([...this.state.schema.fields,...e])})}};function we(){return{schema:{kind:`events`,fields:[]},created:/* @__PURE__ */ new Set,unresolved:/* @__PURE__ */ new Set,extracted:/* @__PURE__ */ new Set,extractedPatterns:/* @__PURE__ */ new Set,sorted:!1,series:!1,lastWasSort:!1,opaqueUpstream:!1,types:/* @__PURE__ */ new Map}}function Te(e){return[...new Set(e)]}const Ee=k({s:`s`,sec:`s`,secs:`s`,second:`s`,seconds:`s`,m:`m`,min:`m`,mins:`m`,minute:`m`,minutes:`m`,h:`h`,hr:`h`,hrs:`h`,hour:`h`,hours:`h`,d:`d`,day:`d`,days:`d`,w:`w`,week:`w`,weeks:`w`,mon:`M`,month:`M`,months:`M`,q:`q`,qtr:`q`,qtrs:`q`,quarter:`q`,quarters:`q`,y:`y`,yr:`y`,yrs:`y`,year:`y`,years:`y`}),De=k({s:1,m:60,h:3600,d:86400,w:604800});function Oe(e){return Ee[e.toLowerCase()]??(e===`M`?`M`:void 0)}function ke(e){let t=/^([A-Za-z]+)(\d?)$/.exec(e);if(!t)return;let n=(t[1]??``).toLowerCase(),r=t[2]??``;if(n===`w`)return r===``||r===`0`||r===`7`?`w0`:`w${r}`;if(r===``)return Ee[n]}function Ae(e,t){let n=e.trim().replace(/^"(.*)"$/s,`$1`);if(n===``)return{kind:`invalid`,detail:`The time modifier is empty.`};if(n.length>64)return{kind:`invalid`,detail:`The time modifier is too long.`};if(/^now(\(\))?$/i.test(n))return{kind:`now`};if(n===`0`)return{kind:`all`};if(/^rt/i.test(n))return{kind:`realtime`};if(/^\d{1,11}(\.\d+)?$/.test(n))return{kind:`absolute`,iso:Pe(Math.floor(Number(n))*1e3),fromText:!1};let r=/^(\d{1,2})\/(\d{1,2})\/(\d{4}):(\d{1,2}):(\d{2}):(\d{2})$/.exec(n);if(r){let[,e,i,a,o,s,c]=r.map(Number),l=Date.UTC(a,e-1,i,o,s,c),u=new Date(l);if(u.getUTCMonth()!==e-1||u.getUTCDate()!==i||o>23||s>59||c>59)return{kind:`invalid`,detail:`"${n}" is not a valid date.`};let d=Fe(t,l);return d===void 0?{kind:`invalid`,detail:`Unknown time zone "${t}".`}:{kind:`absolute`,iso:Pe(l-d*6e4),fromText:!0}}return je(n)}function je(e){let t=/^((?:[+-]\d+[A-Za-z]*)*)(?:@([A-Za-z]+\d?))?((?:[+-]\d+[A-Za-z]*)*)$/.exec(e);if(!t)return{kind:`invalid`,detail:`"${e}" is not a time modifier the translator understands.`};let n=Me(t[1]??``),r=Me(t[3]??``);if(!n||!r)return{kind:`invalid`,detail:`"${e}" uses an unknown time unit.`};let i=``;if(t[2]!==void 0){let e=ke(t[2]);if(!e)return{kind:`invalid`,detail:`"@${t[2]}" is not a known snap unit.`};i=`@${e}`}let a=Ne(n);if(a===void 0)return{kind:`invalid`,detail:`"${e}" mixes calendar and clock units.`};if(r.length>0){let t=Ne(r);return t===void 0?{kind:`invalid`,detail:`"${e}" mixes calendar and clock units.`}:{kind:`relative`,dql:`${a===``?`now()${i}`:`now()${a}${i}`}${t}`,exact:!1}}return a===``&&i===``?{kind:`invalid`,detail:`"${e}" is not a time modifier.`}:{kind:`relative`,dql:`${a}${i}`,exact:!0}}function Me(e){let t=[];for(let n of e.matchAll(/([+-])(\d+)([A-Za-z]*)/g)){let e=n[3]===``?`s`:Oe(n[3]??``);if(!e)return;t.push({sign:n[1]===`-`?-1:1,n:Number(n[2]),unit:e})}return t}function Ne(e){if(e.length===0)return``;if(e.length===1){let t=e[0];return`${t.sign<0?`-`:`+`}${t.n}${t.unit}`}let t=0;for(let n of e){let e=De[n.unit];if(e===void 0)return;t+=n.sign*n.n*e}for(let[e,n]of[[`w`,604800],[`d`,86400],[`h`,3600],[`m`,60]])if(t%n===0)return`${t<0?`-`:`+`}${Math.abs(t/n)}${e}`;return`${t<0?`-`:`+`}${Math.abs(t)}s`}function Pe(e){return new Date(e).toISOString().replace(/\.000Z$/,`Z`)}function Fe(e,t){if(e===`UTC`||e===`Z`)return 0;let n=/^([+-])(\d{2}):(\d{2})$/.exec(e);if(n)return(n[1]===`-`?-1:1)*(Number(n[2])*60+Number(n[3]));try{let n=new Intl.DateTimeFormat(`en-US`,{timeZone:e,hourCycle:`h23`,year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`}),r=t;for(let e=0;e<2;e++){let i=Object.fromEntries(n.formatToParts(new Date(r)).map(e=>[e.type,e.value])),a=Date.UTC(Number(i.year),Number(i.month)-1,Number(i.day),Number(i.hour),Number(i.minute),Number(i.second)),o=Math.round((a-r)/6e4);if(r=t-o*6e4,e===1)return o}return}catch{return}}function j(e,t){for(let n of t)e.push(n)}const Ie=/^-?\d+(\.\d+)?$/,Le=/* @__PURE__ */ new Set([`index`,`sourcetype`,`eventtype`,`tag`,`earliest`,`latest`]),Re=/^_index_(earliest|latest)$/;function ze(e,t,r,i=!1,a){return Be(e,t,i,a)??n(!0)}function Be(e,t,n,r){let i=e=>r??e;switch(e.t){case`and`:return ee(e.items.map(e=>Be(e,t,n,r)).filter(e=>e!==void 0));case`or`:return te(e.items.map(e=>Be(e,t,n,r)).filter(e=>e!==void 0));case`not`:{let i=Be(e.e,t,n,r);return i===void 0?void 0:x(`isFalseOrNull`,i)}case`macro`:return;case`sub`:return t.tc.lowerSubsearchFilter(e,t);case`term`:return Ve(e.v,e.quoted,!1,t,i(e.span));case`func`:return e.fn===`CASE`?Ve(e.v,!0,!0,t,i(e.span)):(t.report(`SPL3011`,i(e.span),{detail:`TERM() matches a whole token in Splunk; in DQL it becomes a phrase match.`}),Ve(e.v,!0,!1,t,i(e.span)));case`in`:return He(e,t,i(e.span));case`cmp`:return Ue(e,t,i(e.span),i(e.fieldSpan))}}function Ve(t,r,a,o,s){if(o.state.schema.kind!==`events`)throw new A(`SPL2003`,s,`A free-text term after a transforming command can only stand on its own in the search.`);!r&&t.includes(`*`)&&o.report(`SPL3011`,s,{detail:`"${t}": wildcard terms match on token boundaries that differ from Splunk's.`});let c=[i(o.field(`_raw`,s)),e(t)];return a?x(`matchesPhrase`,...c,b(`caseSensitive`,n(!0))):x(`matchesPhrase`,...c)}function He(n,r,a){let o=r.field(n.field,a),s=r.fieldType(o);return n.values.length>0&&n.values.every(e=>!e.quoted&&Ie.test(e.v))&&s!==`string`?(s!==`number`&&r.report(`SPL3006`,a,{subject:`type:${o}`,detail:`"${n.field}" has no declared type; it is compared as a number.`}),x(`in`,i(o),d(n.values.map(e=>t(e.v))))):x(`matchesValue`,i(o),d(n.values.map(t=>e(t.v))))}function Ue(n,r,a,o){let s=n.field;if(s===`earliest`||s===`latest`||Re.test(s))throw new A(`SPL2003`,a,`A time modifier can only be translated as a top-level term of the first search.`);if(s===`sourcetype`||s===`eventtype`||s===`tag`)return We(n,r,a);if(s===`index`&&r.first){r.report(`SPL3014`,a,{detail:`An index inside OR/NOT is translated as a bucket comparison.`});let t=r.mapping.indexes.get(n.value)?.buckets[0]??n.value,o=g(`==`,i(`dt.system.bucket`),e(t));return n.op===`!=`?m(o):o}let c=r.field(s,o),l=r.fieldType(c),u=n.value,d=!n.quoted&&Ie.test(u),f=()=>{l===void 0&&r.report(`SPL3006`,o,{subject:`type:${c}`,detail:`"${s}" has no declared type; it is compared as a ${d?`number`:`text`}.`})};switch(n.op){case`=`:case`!=`:{let o;return u===`*`&&!n.quoted?n.op===`!=`?(r.report(`SPL3002`,a,{detail:`${s}!=* is translated as "field is missing".`}),x(`isNull`,i(c))):x(`isNotNull`,i(c)):d&&l!==`string`?(l!==`number`&&f(),o=g(n.op===`=`?`==`:`!=`,i(c),t(u)),o):(/.\*./.test(u)&&r.report(`SPL3011`,a,{detail:`"${u}": a wildcard in the middle of a value may match differently.`}),o=x(`matchesValue`,i(c),e(u)),n.op===`!=`?m(o):o)}default:return f(),g(n.op,i(c),d?t(u):e(u))}}function We(e,t,n){let r=t.mapping,i=e.field===`sourcetype`?r.sourcetypes.get(e.value)?.filter:e.field===`eventtype`?r.eventtypes.get(e.value):r.tags.get(e.value);if(i===void 0){let r=e.field===`sourcetype`?`SPL4002`:`SPL4006`;t.report(r,n,{subject:`${e.field}=${e.value}`,detail:`${e.field} "${e.value}" has no entry in the mapping file, so it was left out; the result may include more records.`})}else return e.op===`!=`?m(c(i)):c(i)}function Ge(e){return e?e.t===`and`?e.items:[e]:[]}function Ke(e,t){let n=[],r=[];for(let e of t)e.k===`call`&&e.fn===`isFalseOrNull`&&e.args.length===1&&e.args[0]?r.push(e.args[0].value):n.push(e);let i=ee(n);i&&e.emit(S(`filter`,i));for(let t of r)e.emit(S(`filterOut`,t))}function qe(t,n,r){let i=t.mapping,o=[],s=[],l=[],u,f;for(let e of Ge(n))if(!r&&e.t===`cmp`&&e.field===`index`&&e.op===`=`)s.push(e);else if(!r&&e.t===`or`&&e.items.length>0&&e.items.every(e=>e.t===`cmp`&&e.field===`index`&&e.op===`=`))j(s,e.items);else if(e.t===`cmp`&&(e.field===`earliest`||e.field===`latest`)&&e.op===`=`){if(t.tc.options.tokens&&/^\$[A-Za-z_][A-Za-z0-9_.]*\$$/.test(e.value))continue;let n=Ae(e.value,i.defaults.timezone);e.field===`earliest`?u={value:n,span:e.span}:f={value:n,span:e.span}}else if(e.t===`cmp`&&Re.test(e.field))t.report(`SPL2011`,e.span,{detail:`${e.field} (index time) has no DQL equivalent and was left out.`});else if(e.t===`cmp`&&Le.has(e.field)&&e.op===`=`&&e.field!==`index`){let n=We(e,t,e.span);n&&l.push(n)}else o.push(e);let p=i.defaults.dataObject,m=[];if(r)p=r.dataObject,m=[...r.buckets],r.filter!==void 0&&l.unshift(c(r.filter));else if(s.length===0)t.report(`SPL4001`,t.span,{subject:`(none)`,detail:`The search names no index; Splunk would search your default indexes, DQL reads all records of this type.`});else{let e=/* @__PURE__ */ new Set,n=!1,r=!1;for(let a of s){if(a.value===`*`){r=!0;continue}let o=Ye(i.indexes,a.value);o?(e.add(o.dataObject),j(m,o.buckets),o.filter!==void 0&&s.length===1&&l.unshift(c(o.filter))):(n=!0,t.report(`SPL4001`,a.span,{subject:a.value,detail:`Index "${a.value}" has no entry in the mapping file, so all records are read.`}))}if(e.size>1)throw new A(`SPL2003`,t.span,`These indexes map to different Grail data objects; split the search.`);e.size===1&&(p=[...e][0]),(n||r)&&(m=[])}let h=[y(a(p))];m.length>0&&h.push(b(`bucket`,d([...new Set(m)].map(e))));let g=t.tc.options.timeRange,_=i.defaults.timezone;!u&&g?.earliest!==void 0&&(u={value:Ae(g.earliest,_),span:t.span}),!f&&g?.latest!==void 0&&(f={value:Ae(g.latest,_),span:t.span}),!u&&i.defaults.timeframe!==void 0&&(u={value:Ae(i.defaults.timeframe,_),span:t.span});let v=u?Ze(t,`earliest`,u.value,u.span):void 0,x=f?Ze(t,`latest`,f.value,f.span):void 0;v&&h.push(b(`from`,v)),x&&h.push(b(`to`,x)),u||t.tc.diags.reportOnce(`SPL5001`,t.span,t.index),t.emit({name:`fetch`,args:h});let S=[...l];for(let e of o){let n=Be(e,t,!1,void 0);n&&S.push(n)}Ke(t,S)}function Je(t,n){if(!n)return;let r=[],i=[];for(let e of Ge(n)){if(t.state.schema.kind!==`events`&&e.t===`term`){i.push(e.v),t.report(`SPL3011`,e.span,{detail:`A free-text term after a transforming command is matched against all fields with the DQL search command.`});continue}if(e.t===`cmp`&&(e.field===`earliest`||e.field===`latest`)){t.report(`SPL2003`,e.span,{detail:`A time modifier in a later search stage has no DQL equivalent and was left out.`});continue}let n=Be(e,t,!1,void 0);n&&r.push(n)}Ke(t,r);for(let n of i)t.emit(S(`search`,e(n)))}function Ye(e,t){let n=e.get(t);if(n)return n;let r;for(let[n,i]of e)n.includes(`*`)&&Xe(n,t)&&(!r||n.length>r.len)&&(r={len:n.length,value:i});return r?.value}function Xe(e,t){let n=e.split(`*`),r=n[0]??``,i=n[n.length-1]??``;if(n.length===1)return e===t;if(!t.startsWith(r)||t.length<r.length+i.length||!t.endsWith(i))return!1;let a=r.length,o=t.length-i.length;for(let e=1;e<n.length-1;e++){let r=n[e],i=t.indexOf(r,a);if(i===-1||i+r.length>o)return!1;a=i+r.length}return!0}function Ze(t,n,r,i){switch(r.kind){case`now`:return;case`all`:n===`earliest`&&t.report(`SPL3015`,i,{detail:`"All time" has no DQL equivalent; choose the time range in Dynatrace.`});return;case`realtime`:t.report(`SPL2011`,i,{detail:`Real-time searches have no DQL equivalent; the time modifier was left out.`});return;case`invalid`:t.report(`SPL3015`,i,{detail:r.detail});return;case`absolute`:return r.fromText&&t.report(`SPL3010`,i,{detail:`The date was converted to UTC using the time zone "${t.mapping.defaults.timezone}".`}),e(r.iso);case`relative`:return r.exact||t.report(`SPL3015`,i,{detail:`An offset after the snap unit was kept as an expression; check that Dynatrace accepts it.`}),o(r.dql)}}var M=class extends Error{span;constructor(e,t){super(e),this.span=t}};const Qe=2e4,$e=/^[A-Za-z_][A-Za-z0-9_.:{}@-]*$/;function et(e,t,n){let r=new rt(tt(e,t,n));if(r.atEnd())return;let i=r.andExpr();return r.expectEnd(),i}function tt(e,t,n){let r=[],i=t;for(;i<n;){let t=e[i];if(/\s/.test(t)){i++;continue}if(t==="`"&&e.startsWith("```",i)){let t=e.indexOf("```",i+3);i=t===-1||t+3>n?n:t+3;continue}if(t===`(`||t===`)`){r.push({type:t,span:{start:i,end:i+1}}),i++;continue}if(t===`[`){let t=ge(e,i,n,`[`,`]`);if(t===-1)throw new M(`A subsearch "[" is not closed.`,{start:i,end:n});r.push({type:`sub`,inner:{start:i+1,end:t},span:{start:i,end:t+1}}),i=t+1;continue}if(t===`]`)throw new M(`Unexpected "]".`,{start:i,end:i+1});if(t==="`"){let t=e.indexOf("`",i+1),a=t===-1||t>=n?n:t+1;r.push({type:`macro`,span:{start:i,end:a}}),i=a;continue}if(t===`"`){let t=O(e,i,n);if(t===-1)throw new M(`A quoted string is not closed.`,{start:i,end:n});r.push({type:`word`,text:ve(e.slice(i+1,t)),quoted:!0,span:{start:i,end:t+1}}),i=t+1;continue}let a=i;for(;i<n;){let t=e[i];if(/[\s()[\]]/.test(t))break;if(t===`"`){let t=O(e,i,n);if(t===-1)throw new M(`A quoted string is not closed.`,{start:i,end:n});i=t+1}else i++}if(i===a)throw new M(`Unexpected "${t}".`,{start:i,end:i+1});r.push({type:`word`,text:e.slice(a,i),quoted:!1,span:{start:a,end:i}})}if(r.push({type:`eof`,span:{start:n,end:n}}),r.length>Qe)throw new M(`The search has more than ${Qe} terms.`,{start:t,end:n});return r}function nt(e){let t=[],n=0;for(;n<e.length;){if(e[n]===`,`){n++;continue}if(e[n]===`"`){let r=O(e,n,e.length),i=r===-1?e.length:r;t.push({v:ve(e.slice(n+1,i)),quoted:!0}),n=i+1;continue}let r=e.indexOf(`,`,n),i=r===-1?e.length:r,a=e.slice(n,i).trim();a!==``&&t.push({v:a,quoted:!1}),n=i}return t}var rt=class{i=0;depth=0;toks;constructor(e){this.toks=e}get t(){return this.toks[this.i]??this.toks[this.toks.length-1]}ty(){return this.t.type}peekTok(e){return this.toks[this.i+e]??this.toks[this.toks.length-1]}isKw(e){let t=this.t;return t.type===`word`&&!t.quoted&&t.text===e}atEnd(){return this.t.type===`eof`}expectEnd(){if(this.t.type===`)`)throw new M(`Unexpected ")".`,this.t.span);if(this.t.type!==`eof`)throw new M(`Unexpected text in the search.`,this.t.span)}enter(){if(++this.depth>200)throw new M(`The search is nested too deeply.`,this.t.span)}andExpr(){this.enter();let e=[this.orExpr()];for(;;)if(this.isKw(`AND`))this.i++,e.push(this.orExpr());else{if(this.t.type===`eof`||this.t.type===`)`)break;e.push(this.orExpr())}return this.depth--,e.length===1?e[0]:{t:`and`,items:e,span:at(e)}}orExpr(){let e=[this.notExpr()];for(;this.isKw(`OR`);)this.i++,e.push(this.notExpr());return e.length===1?e[0]:{t:`or`,items:e,span:at(e)}}notExpr(){if(this.isKw(`NOT`)){let e=this.t.span.start;this.i++,this.enter();let t=this.notExpr();return this.depth--,{t:`not`,e:t,span:{start:e,end:t.span.end}}}return this.primary()}primary(){let e=this.t;if(e.type===`(`){if(this.i++,this.t.type===`)`)throw new M(`Empty parentheses.`,this.t.span);let e=this.andExpr();if(this.ty()!==`)`)throw new M(`Expected ")".`,this.t.span);return this.i++,e}if(e.type===`sub`)return this.i++,{t:`sub`,inner:e.inner,span:e.span};if(e.type===`macro`)return this.i++,{t:`macro`,span:e.span};if(e.type!==`word`)throw new M(`Expected a search term.`,e.span);if(this.i++,e.quoted)return{t:`term`,v:e.text,quoted:!0,span:e.span};if(e.text===`AND`||e.text===`OR`)throw new M(`"${e.text}" needs a term on both sides.`,e.span);if((e.text===`CASE`||e.text===`TERM`)&&this.t.type===`(`){let t=this.peekTok(1),n=this.peekTok(2);if(t.type===`word`&&n.type===`)`)return this.i+=3,{t:`func`,fn:e.text,v:t.text,span:{start:e.span.start,end:n.span.end}}}if($e.test(e.text)&&this.t.type===`word`&&!this.t.quoted&&this.t.text.toUpperCase()===`IN`&&this.peekTok(1).type===`(`){this.i+=2;let t=[];for(;;){let e=this.t;if(this.ty()===`)`)break;if(e.type!==`word`)throw new M(`Expected a value in the IN list.`,e.span);this.i++,e.quoted?t.push({v:e.text,quoted:!0}):j(t,nt(e.text))}let n=this.t.span.end;return this.i++,{t:`in`,field:e.text,values:t,span:{start:e.span.start,end:n}}}let t=it(e.text);if(t){let{value:n,quoted:r}=t,i=e.span.end;if(n===``&&this.t.type===`word`){let e=this.t;this.i++,n=e.text,r=e.quoted,i=e.span.end}return t.valueQuoted&&(n=ve(n.slice(1,-1)),r=!0),{t:`cmp`,field:t.field,op:t.op,value:n,quoted:r,span:{start:e.span.start,end:i},fieldSpan:{start:e.span.start,end:e.span.start+t.field.length}}}let n=this.t;if($e.test(e.text)&&n.type===`word`&&!n.quoted&&/^(=|!=|<=|>=|<|>)/.test(n.text)){let t=/^(!=|<=|>=|=|<|>)/.exec(n.text)?.[1]??`=`;this.i++;let r=n.text.slice(t.length),i=!1,a=n.span.end;if(r===``&&this.t.type===`word`){let e=this.t;this.i++,r=e.text,i=e.quoted,a=e.span.end}else r.startsWith(`"`)&&r.endsWith(`"`)&&r.length>=2&&(r=ve(r.slice(1,-1)),i=!0);return{t:`cmp`,field:e.text,op:t,value:r,quoted:i,span:{start:e.span.start,end:a},fieldSpan:e.span}}return{t:`term`,v:e.text,quoted:!1,span:e.span}}};function it(e){let t=/^([A-Za-z_][A-Za-z0-9_.:{}@-]*)(!=|<=|>=|=|<|>)(.*)$/s.exec(e);if(!t)return;let n=t[3]??``,r=n.length>=2&&n.startsWith(`"`)&&n.endsWith(`"`);return{field:t[1],op:t[2],value:n,quoted:!1,valueQuoted:r}}function at(e){return{start:e[0]?.span.start??0,end:e[e.length-1]?.span.end??0}}function ot(e,t,n){return e.mapping.lookups.get(t)||(e.report(`SPL4005`,n,{subject:t,detail:`Lookup "${t}" has no entry in the mapping file; a placeholder path /lookups/${st(t)} is used.`}),{path:`/lookups/${st(t)}`})}function st(e){return e.replace(/\.csv$/i,``).replace(/[^A-Za-z0-9_.-]/g,`_`)||`lookup`}const ct=t=>S(`load`,e(t)),lt={name:`lookup`,tier:`T2`,summary:`lookup [load "<path>"], sourceField:, lookupField:, fields:{…}.`,lower(e){let t=e.scanner();for(;t.option(););let n=t.word();if(!n)throw new A(`SPL1003`,e.span,`lookup needs a table name.`);let r=[];for(;!t.atEnd()&&!t.peekKeyword(`output`)&&!t.peekKeyword(`outputnew`);){if(t.eat(`,`))continue;let e=t.fieldName();if(!e)throw new A(`SPL1003`,t.here(),`Expected a lookup field.`);let n=e.value;t.keyword(`as`)&&(n=t.fieldName()?.value??n),r.push({lookupField:e.value,local:n,span:e.span})}if(r.length===0)throw new A(`SPL1003`,e.span,`lookup needs a field to match on.`);let o=[],s=t.keyword(`outputnew`);if(s||t.keyword(`output`))for(;!t.atEnd();){if(t.eat(`,`))continue;let e=t.fieldName();if(!e)throw new A(`SPL1003`,t.here(),`Expected an output field.`);let n=e.value;t.keyword(`as`)&&(n=t.fieldName()?.value??n),o.push({col:e.value,as:n})}let c=ot(e,n.value,n.span);if(e.report(`SPL3013`,e.span,{detail:`If several rows match, Splunk returns all values; DQL takes one row.`}),r.length>1){let t=r.map(t=>(t.local,t.lookupField,i(e.field(t.local,t.span)))),n=o.length>0?[b(`fields`,d(o.map(e=>e.as===e.col?i(e.col):f(e.as,i(e.col)))))]:[];e.emit(S(`join`,u([{...ct(c.path),origin:[e.index]}]),b(`on`,d(t)),b(`kind`,a(`leftOuter`)),...n)),o.length===0&&e.report(`SPL3016`,e.span,{detail:`Lookup columns arrive with the prefix "right.".`});for(let t of o)e.field(t.as,e.span,!0);return}let l=r[0],p=[b(`sourceField`,i(e.field(l.local,l.span))),b(`lookupField`,i(c.key??l.lookupField))],m=o;m.length===0&&(c.columns?m=c.columns.filter(e=>e!==(c.key??l.lookupField)).map(e=>({col:e,as:e})):e.report(`SPL3016`,e.span,{detail:`Without OUTPUT, lookup columns arrive as lookup.<column>; list the columns in the mapping file to keep their names.`}));let h=e=>`_new_${e.replace(/[^A-Za-z0-9_]/g,`_`)}`;m.length>0&&p.push(b(`fields`,d(m.map(e=>s?f(h(e.as),i(e.col)):e.as===e.col?i(e.col):f(e.as,i(e.col)))))),e.emit({name:`lookup`,args:[{kind:`pos`,value:u([{...ct(c.path),origin:[e.index]}])},...p]}),s&&m.length>0&&(e.emit(S(`fieldsAdd`,...m.map(e=>f(e.as,x(`coalesce`,i(e.as),i(h(e.as))))))),e.emit(S(`fieldsRemove`,...m.map(e=>i(h(e.as))))));for(let t of m)e.field(t.as,e.span,!0);e.addFields(m.map(e=>e.as))}},ut={name:`inputlookup`,tier:`T2`,summary:`load "<path>" then filter.`,generating:!0,lower(e){let t=e.scanner(),n=!1;for(let e=t.option();e;e=t.option())if(e.name.toLowerCase()===`append`&&/^(t|true|1)$/i.test(e.value))n=!0;else if(e.name.toLowerCase()!==`append`)throw new A(`SPL2003`,e.span,`inputlookup ${e.name}= cannot be translated.`);let r=t.word();if(!r)throw new A(`SPL1003`,e.span,`inputlookup needs a table name.`);let i=ot(e,r.value,r.span),a;if(t.keyword(`where`)){let n=t.rest();try{a=et(e.tc.text,n.start,n.end)}catch(e){throw e instanceof M?new A(`SPL1001`,e.span,e.message):e}}else if(!t.atEnd())throw new A(`SPL1003`,t.here(),`Unexpected text in inputlookup.`);if(n){if(a)throw new A(`SPL2003`,e.span,`inputlookup append=t with where cannot be translated.`);e.emit(S(`append`,u([{...ct(i.path),origin:[e.index]}])))}else e.emit(ct(i.path)),e.setTable(i.columns?[...i.columns]:[]),e.state.schema={kind:`table`,fields:i.columns?[...i.columns]:[]},a&&Je(e,a)}};function dt(e,t){let n=e.tc.lowerSub(t.inner,e);if(n.incomplete)throw new A(`SPL2007`,t.span,`The subsearch contains a step that could not be translated.`);return n}const ft={name:`join`,tier:`T2`,summary:`join [sub], on:{keys}, kind:inner|leftOuter, fields:{…}.`,lower(e){let t=e.scanner(),n=`inner`,r=[];for(;t.peek()!==`[`&&!t.atEnd();){let i=t.option();if(i){let t=i.name.toLowerCase();if(t===`type`){let e=i.value.toLowerCase();if(e===`inner`)n=`inner`;else if(e===`left`||e===`outer`)n=`leftOuter`;else throw new A(`SPL2003`,i.span,`join type=${i.value} cannot be translated.`)}else if(t===`max`&&i.value===`0`)continue;else if(t===`left`||t===`right`||t===`where`)throw new A(`SPL2003`,i.span,`join with left=/right= aliases cannot be translated.`);else e.report(`SPL2003`,i.span,{detail:`join ${i.name}= has no DQL equivalent and was ignored.`});continue}if(t.eat(`,`))continue;let a=t.fieldName();if(!a)throw new A(`SPL1003`,t.here(),`Expected join fields.`);r.push({name:a.value,span:a.span})}let o=t.balanced(`[`,`]`);if(!o)throw new A(`SPL1003`,e.span,`join needs a subsearch in [ … ].`);if(r.length===0)throw new A(`SPL2003`,e.span,`join without fields cannot be translated.`);let s=r.map(t=>e.field(t.name,t.span)),c=dt(e,o);e.report(`SPL3009`,e.span,{detail:`Splunk join keeps one matching row by default (max=1); DQL keeps every match.`});let l=[{kind:`pos`,value:u(c.commands)},b(`on`,d(s.map(i))),b(`kind`,a(n))],f=c.outputFields?.filter(e=>!s.includes(e));if(f&&f.length>0){l.push(b(`fields`,d(f.map(i))));for(let t of f)e.field(t,e.span,!0);e.addFields(f)}else e.report(`SPL3016`,e.span,{detail:`The subsearch fields are not known here, so they arrive with the prefix "right.".`});e.emit({name:`join`,args:l})}},pt={name:`append`,tier:`T1`,summary:`append [sub].`,lower(e){let t=e.scanner();for(;t.option(););let n=t.balanced(`[`,`]`);if(!n)throw new A(`SPL1003`,e.span,`append needs a subsearch in [ … ].`);let r=dt(e,n);e.emit(S(`append`,u(r.commands))),r.outputFields&&e.addFields(r.outputFields)}};function mt(e){return{name:e,tier:`T2`,summary:`First subsearch, then append [the others].`,generating:!0,lower(t){let n=t.scanner();for(;n.option(););let r=[];for(let e=n.balanced(`[`,`]`);e;e=n.balanced(`[`,`]`))r.push(e);if(r.length===0||!n.atEnd())throw new A(`SPL1003`,t.span,`${e} needs subsearches in [ … ].`);t.report(`SPL3004`,t.span,{detail:`Results are appended one after the other, not interleaved by time.`});let i=r.map(e=>dt(t,e).commands),a=t.first&&t.upstream.length===0,o=a?i.slice(1):i;if(a)for(let e of i[0]??[])t.out.push({...e,origin:[t.index]});for(let e of o)t.emit(S(`append`,u(e)))}}}const ht=[lt,ut,ft,pt,mt(`union`),mt(`multisearch`)],gt=1e4,_t=`The regular expression would give a Dynatrace pattern longer than ${gt} characters.`;function vt(e,t){if(e.budget.left-=t,e.budget.left<0)throw new N(_t)}var N=class extends Error{};const yt=k({B:`A non-boundary (\\B) has no Dynatrace pattern equivalent.`,A:`Anchors \\A, \\z, \\G and \\K are not supported.`,z:`Anchors \\A, \\z, \\G and \\K are not supported.`,Z:`Anchors \\A, \\z, \\G and \\K are not supported.`,G:`Anchors \\A, \\z, \\G and \\K are not supported.`,K:`Anchors \\A, \\z, \\G and \\K are not supported.`,p:`Unicode classes (\\p{…}) are not supported.`,P:`Unicode classes (\\P{…}) are not supported.`,k:`Back-references have no Dynatrace pattern equivalent.`}),bt=k({d:{text:`[0-9]`,word:!0},w:{text:`[a-zA-Z0-9_]`,word:!0},s:{text:`[ \\t\\r\\n]`,word:!1},D:{text:`[^0-9]`},W:{text:`[^a-zA-Z0-9_]`,word:!1},S:{text:`[^ \\t\\r\\n]`},t:{text:`[\\t]`,word:!1},n:{text:`[\\n]`,word:!1},r:{text:`[\\r]`,word:!1}}),xt=k({d:`0-9`,w:`a-zA-Z0-9_`,s:` \\t\\r\\n`,t:`\\t`,n:`\\n`,r:`\\r`}),St=`[a-zA-Z0-9_]`,Ct=`The regular expression is too large once its repeated groups are written out.`;function wt(e,t={}){if(e.length>4e3)return{ok:!1,reason:`The regular expression is too long.`};try{let n=e,r={captures:t.captures??!1,ci:!1,dotAll:!1,budget:{left:gt}},i=/^\(\?([a-zA-Z]+)\)/.exec(n);if(i){for(let e of i[1])if(e===`i`)r.ci=!0;else if(e===`s`)r.dotAll=!0;else throw new N(`The inline flag (?${e}) is not supported; only (?i) and (?s) are.`);n=n.slice(i[0].length)}let a=!1,o=!1;n.startsWith(`^`)&&(a=!0,n=n.slice(1)),n.endsWith(`$`)&&!Dt(n)&&(o=!0,n=n.slice(0,-1));let s=qt(n),c;if(s.length>1){if(a||o)throw new N(`"^" or "$" together with alternatives (a|b) is not supported.`);c=[{k:`alts`,options:s.map(e=>Ot(e,r,1)),quant:``}]}else c=Ot(n,r,0);if(o&&c.push({k:`eos`}),Tt(c)>2e3)throw new N(Ct);let l=[],u=jt(c,l,r,{fixed:!1,end:!0});if(u.length===0)return{ok:!1,reason:`The pattern is empty.`};let d=u.join(` `);if(!a&&!t.everyMatch&&(d=`DATA? ${d}`),t.forMatch&&!o&&(d=`${d} DATA?`),d.length>1e4)throw new N(_t);return{ok:!0,dpl:d,captures:l,anchoredStart:a}}catch(e){return e instanceof N?{ok:!1,reason:e.message}:{ok:!1,reason:`The regular expression could not be converted.`}}}function Tt(e){let t=0,n=[e];for(;n.length>0;){let e=n.pop();for(let r of e){if(t++,t>2e3)return t;if(r.k===`group`||r.k===`capture`||r.k===`look`)n.push(r.items);else if(r.k===`alts`)for(let e of r.options)n.push(e)}}return t}function Et(e){if(!/[\\^$.|?*+()[\]{}]/.test(e.replace(/\\[./\-:=@#,"' ]/g,``)))return e.replace(/\\([./\-:=@#,"' ])/g,`$1`)}function Dt(e){let t=0;for(let n=e.length-2;n>=0&&e[n]===`\\`;n--)t++;return t%2==1}function Ot(e,t,n){if(n>20)throw new N(`The regular expression is nested too deeply.`);let r=[],i=``,a=()=>{i!==``&&r.push({k:`lit`,text:i}),i=``},o=(e,n)=>{let o=t.ci&&/[A-Za-z]/.test(e);if(!o&&n===``){i+=e;return}a(),Wt(n);let s=o?`[${e.toLowerCase()}${e.toUpperCase()}]`:`[${Vt(e)}]`;r.push({k:`class`,text:s,quant:n,word:/[A-Za-z0-9_]/.test(e)})},s=e.length,c=0;for(;c<s;){let l=e[c];if(l===`\\`){let t=e[c+1];if(t===void 0)throw new N(`The regular expression ends with a backslash.`);if(/[1-9]/.test(t))throw new N(`Back-references have no Dynatrace pattern equivalent.`);if(t===`b`){a(),r.push({k:`boundary`}),c+=2;continue}let n=yt[t];if(n)throw new N(n);let i=Ut(e,c+2,s),l=bt[t];if(l){a(),Wt(i);let e={k:`class`,text:l.text,quant:i};l.word!==void 0&&(e.word=l.word),r.push(e)}else if(/[A-Za-z0-9]/.test(t))throw new N(`The escape \\${t} is not supported.`);else o(t,i);c+=2+i.length;continue}if(l===`[`){let n=Gt(e,c,s),i=Ut(e,n+1,s);a(),Wt(i),r.push({k:`class`,text:Ht(e.slice(c,n+1),t.ci),quant:i}),c=n+1+i.length;continue}if(l===`.`){let t=Ut(e,c+1,s);if(a(),t===`*`||t===`*?`)r.push({k:`any`,plus:!1});else if(t===`+`||t===`+?`)r.push({k:`any`,plus:!0});else throw new N(`A single "." (any character) is only supported as ".*" or ".+".`);c+=1+t.length;continue}if(l===`(`){a();let i=Kt(e,c,s),o=Ut(e,i+1,s);for(let a of At(e.slice(c+1,i),o,t,n))r.push(a);c=i+1+o.length;continue}if(l===`|`)throw new N(`Alternatives must stand alone in the pattern or inside a group.`);if(l===`^`||l===`$`)throw new N(`"${l}" is only supported at the start or end of the pattern.`);if(`*+?{`.includes(l)){if(l===`{`&&!/^\{\d+(,\d*)?\}/.test(e.slice(c,s))){i+=l,c++;continue}throw new N(`A quantifier must follow something to repeat.`)}if(l===`)`||l===`]`)throw new N(`Unbalanced "${l}".`);let u=Ut(e,c+1,s);o(l,u),c+=1+u.length}return a(),r}function kt(e,t,n){let r=qt(e);return r.length===1?Ot(e,t,n+1):[{k:`alts`,options:r.map(e=>Ot(e,t,n+1)),quant:``}]}function At(e,t,n,r){let i=e,a;if(e.startsWith(`?`)){let o=/^\?(?:P?<([A-Za-z_][A-Za-z0-9_]*)>|'([A-Za-z_][A-Za-z0-9_]*)')/.exec(e),s=/^\?(<?)([=!])/.exec(e);if(o)a=o[1]??o[2],i=e.slice(o[0].length);else if(e.startsWith(`?:`))i=e.slice(2);else if(s){if(t!==``)throw new N(`A look-around cannot be repeated.`);let i=kt(e.slice(s[0].length),{...n,captures:!1},r);return[{k:`look`,ahead:s[1]===``,negative:s[2]===`!`,items:i}]}else if(/^\?[a-zA-Z-]+[:)]/.test(e))throw new N(`Inline flags are only supported as (?i) or (?s) at the start of the pattern.`);else throw new N(`This group type is not supported.`)}if(a!==void 0&&n.captures){if(t!==``&&t!==`?`)throw new N(`A repeated capture group is not supported.`);if(/\(\?(?:P?<[A-Za-z_]|')/.test(i))throw new N(`Nested capture groups are not supported.`);return[{k:`capture`,name:a,inner:i,items:kt(i,n,r),optional:t===`?`}]}let o=kt(i,n,r),s=o.length===1?o[0]:void 0;if(t===``||t===`?`)return s?.k===`alts`?[{...s,quant:t}]:[{k:`group`,items:o,quant:t}];let c=/^\{(\d+)\}$/.exec(t),l=c?Number(c[1]):0;if(!c||l<1||l>8)throw new N(`A repeated group cannot be converted, except for a fixed count such as (…){3}.`);if(Tt(o)*l>2e3)throw new N(Ct);let u=[];for(let e=0;e<l;e++)for(let e of o)u.push(e);return u}function jt(e,t,n,r){let i=[];return e.forEach((a,o)=>{let s=o===e.length-1,c=e[o+1],l=s?r:{fixed:Rt(c),end:!1};switch(vt(n,1+Mt(a)),a.k){case`lit`:i.push(Bt(a.text));break;case`class`:i.push(`${a.text}${a.quant}`);break;case`any`:if(l.end){a.plus&&i.push(`DATA`);break}if(!l.fixed)throw new N(`".*" must be followed by fixed text to be converted.`);i.push(n.dotAll?`DATA`:`LD`);break;case`alts`:i.push(`${Pt(a.options,t,n)}${a.quant}`);break;case`group`:i.push(`(${Nt(a.items,t,n,a.quant===``?l:{fixed:!1,end:!1})})${a.quant}`);break;case`capture`:i.push(Lt(a,t,n,l));break;case`look`:{let e=jt(a.items,t,n,{fixed:!1,end:!1});if(e.length===0)throw new N(`An empty look-around cannot be converted.`);let r=e.length===1&&a.items[0]?.k!==`alts`?e[0]:`(${e.join(` `)})`;i.push(`${a.negative?`!`:``}${a.ahead?`>>`:`<<`}${r}`);break}case`boundary`:i.push(Ft(e[o-1],c));break;case`eos`:i.push(`EOS`)}}),i}function Mt(e){switch(e.k){case`lit`:{let t=e.text.length+2;for(let n of e.text)(n===`\\`||n===`'`)&&t++;return t}case`class`:return e.text.length+e.quant.length;case`alts`:return 2+e.quant.length+5*e.options.length;case`group`:return 2+e.quant.length;case`capture`:return 12+e.name.length;case`look`:return 5;case`boundary`:return 16;default:return 4}}function Nt(e,t,n,r){let i=jt(e,t,n,r);if(i.length===0)throw new N(`An empty group cannot be converted.`);return i.join(` `)}function Pt(e,t,n){return`(${e.map(e=>{let r=jt(e,t,n,{fixed:!1,end:!1});if(r.length===0)throw new N(`An empty alternative (a|) cannot be converted.`);return r.length===1?r[0]:`(${r.join(` `)})`}).join(` | `)})`}function Ft(e,t){let n=It(t,!0),r=It(e,!1);if(n===!0&&r!==!0)return`!<<${St}`;if(r===!0&&n!==!0)return`!>>${St}`;throw new N(`A word boundary (\\b) is only supported directly before or after a word.`)}function It(e,t){if(!e||e.k===`eos`)return!1;if(e.k===`lit`)return/[A-Za-z0-9_]/.test(t?e.text[0]:e.text[e.text.length-1]);if(e.k===`class`)return e.word}function Lt(e,t,n,r){let i=zt(e.name),a=e.inner,o=e.optional?`?`:``,s=n=>{t.push({name:e.name,type:n})};if(a===`\\d+`)return s(`number`),`LONG${o}:${i}`;if(/^-\?\\d\+\\\.\\d\+$/.test(a)||a===`\\d+\\.\\d+`)return s(`number`),`DOUBLE${o}:${i}`;if(a===`\\S+`)return s(`string`),`NSPACE${o}:${i}`;if(/^\.[*+]\??$/.test(a)){if(s(`string`),r.end)return`DATA${o}:${i}`;if(!r.fixed)throw new N(`The capture "${e.name}" (.*) must be followed by fixed text.`);return`${n.dotAll?`DATA`:`LD`}${o}:${i}`}s(`string`);let c=e.items.length===1?e.items[0]:void 0;if(c?.k===`class`)return`${c.text}${c.quant}${o}:${i}`;if(c?.k===`alts`&&c.quant===``)return`${Pt(c.options,t,n)}${o}:${i}`;if(e.items.some(e=>e.k===`any`)&&e.items[e.items.length-1]?.k!==`any`)throw new N(`The capture "${e.name}" has ".*" in the middle, which cannot be converted.`);return`(${Nt(e.items,t,n,e.optional?{fixed:!1,end:!1}:r)})${o}:${i}`}function Rt(e){return e?e.k===`lit`?!0:e.k===`class`?e.quant===``||e.quant===`+`||/^\{[1-9]/.test(e.quant):e.k===`alts`?e.quant===``:e.k===`group`?e.quant===``&&Rt(e.items[0]):e.k===`capture`?!e.optional&&!/^\.[*]/.test(e.inner)&&(e.items.length===0||Rt(e.items[0])):e.k===`look`?e.ahead&&!e.negative:e.k===`eos`:!1}function zt(e){return/^[A-Za-z][A-Za-z0-9]*$/.test(e)?e:`'${e}'`}function Bt(e){return`'${e.replace(/\\/g,`\\\\`).replace(/'/g,`\\'`)}'`}function Vt(e){return/[\]\\^-]/.test(e)?`\\${e}`:e}function Ht(e,t){let n=1,r=`[`;e[n]===`^`&&(r+=`^`,n++);let i=e.length-1,a=``;for(;n<i;){let o=e[n],s;if(o===`\\`){let t=e[n+1]??``;n+=2;let i=xt[t];if(i!==void 0){r+=i;continue}if(/[A-Za-z0-9]/.test(t))throw new N(`The escape \\${t} inside a character class is not supported.`);o=t,s=/[\]\\^[-]/.test(t)?`\\${t}`:t}else n++,s=o;let c=e[n+1];e[n]===`-`&&n+1<i&&c!==void 0&&c!==`\\`?(r+=`${s}-${c}`,t&&/[a-z]/.test(o)&&/[a-z]/.test(c)?a+=`${o.toUpperCase()}-${c.toUpperCase()}`:t&&/[A-Z]/.test(o)&&/[A-Z]/.test(c)&&(a+=`${o.toLowerCase()}-${c.toLowerCase()}`),n+=2):(r+=s,t&&/[A-Za-z]/.test(o)&&(a+=o===o.toLowerCase()?o.toUpperCase():o.toLowerCase()))}return`${r}${a}]`}function Ut(e,t,n){let r=e.slice(t,Math.min(n,t+16)),i=/^([*+?]|\{\d+(?:,\d*)?\})(\?|\+)?/.exec(r);if(!i)return``;if(i[2]===`+`)throw new N(`Possessive quantifiers are not supported.`);return i[0]}function Wt(e){if(e.endsWith(`?`)&&e.length>1)throw new N(`Lazy quantifiers are only supported on ".".`)}function Gt(e,t,n){let r=t+1;for(e[r]===`^`&&r++,e[r]===`]`&&r++;r<n;r++)if(e[r]===`\\`)r++;else{if(e[r]===`[`)throw e[r+1]===`:`?new N(`POSIX character classes ([:alpha:]) are not supported.`):new N(`Nested character classes are not supported.`);if(e[r]===`]`)return r}throw new N(`A character class "[" is not closed.`)}function Kt(e,t,n){let r=0;for(let i=t;i<n;i++){let t=e[i];if(t===`\\`)i++;else if(t===`[`)i=Gt(e,i,n);else if(t===`(`&&r++,t===`)`&&(r--,r===0))return i}throw new N(`A group "(" is not closed.`)}function qt(e){let t=[],n=0,r=``;for(let i=0;i<e.length;i++){let a=e[i];if(a===`\\`)r+=a+(e[i+1]??``),i++;else if(a===`[`){let t=i+1;for(e[t]===`^`&&t++,e[t]===`]`&&t++;t<e.length&&e[t]!==`]`;)t+=e[t]===`\\`?2:1;r+=e.slice(i,t+1),i=t}else a===`(`&&n++,a===`)`&&n--,a===`|`&&n===0?(t.push(r),r=``):r+=a}return t.push(r),t}const Jt=k({Y:`yyyy`,y:`yy`,m:`MM`,d:`dd`,e:`d`,H:`HH`,I:`hh`,M:`mm`,S:`ss`,p:`a`,b:`MMM`,B:`MMMM`,a:`EEE`,A:`EEEE`,j:`DDD`,F:`yyyy-MM-dd`,T:`HH:mm:ss`,z:`Z`,Z:`z`,Q:`SSS`});function Yt(e){let t=``,n=``,r=()=>{n!==``&&(t+=/[A-Za-z']/.test(n)?`'${n.replace(/'/g,`''`)}'`:n,n=``)};for(let i=0;i<e.length;i++){let a=e[i];if(a!==`%`){n+=a;continue}let o=e[i+1];if(o===`%`){n+=`%`,i++;continue}if(o===`3`&&e[i+2]===`N`){r(),t+=`SSS`,i+=2;continue}let s=o===void 0?void 0:Jt[o];if(!s)return{ok:!1,directive:`%${o??``}`};r(),t+=s,i++}return r(),{ok:!0,format:t}}const Xt=k({date_hour:`getHour`,date_minute:`getMinute`,date_mday:`getDayOfMonth`,date_month:`getMonth`,date_year:`getYear`,date_wday:`getDayOfWeek`});function P(n,r){switch(n.t){case`str`:return{e:e(n.v),type:`string`};case`num`:return{e:t(rn(n.v)),type:`number`,real:/[.eE]/.test(n.v)};case`field`:return Zt(n.name,n.span,r);case`un`:{let e=P(n.e,r);return n.op===`NOT`?{e:m(e.e),type:`bool`}:{e:h(e.e),type:e.type}}case`in`:return{e:x(`in`,P(n.e,r).e,d(n.list.map(e=>P(e,r).e))),type:`bool`};case`bin`:return Qt(n,r);case`call`:return _n(n,r)}}function Zt(e,t,n){let r=Xt[e];if(r&&!n.state.created.has(e))return n.report(`SPL3010`,t,{subject:e,detail:`${e} is computed from the timestamp; Splunk returns text and uses the user's time zone.`}),{e:x(r,i(`timestamp`)),type:`number`};let a=n.field(e,t),o=n.fieldType(a);return{e:i(a),type:o===`time`?`time`:o===`number`?`number`:o===`string`?`string`:`unknown`}}function Qt(e,t){let n=P(e.l,t),r=P(e.r,t);switch(e.op){case`AND`:return{e:g(`and`,n.e,r.e),type:`bool`};case`OR`:return{e:g(`or`,n.e,r.e),type:`bool`};case`XOR`:return{e:g(`xor`,n.e,r.e),type:`bool`};case`LIKE`:return{e:x(`like`,n.e,r.e),type:`bool`};case`.`:return{e:an(n.e,r.e),type:`string`};case`=`:case`==`:case`!=`:case`<`:case`<=`:case`>`:case`>=`:{let i=e.op===`=`?`==`:e.op;if(n.type===`time`&&r.type===`number`||n.type===`number`&&r.type===`time`){t.report(`SPL3006`,e.span,{detail:`A timestamp is compared with a number; it is compared as Unix seconds.`});let a=n.type===`time`?x(`unixSecondsFromTimestamp`,n.e):n.e,o=r.type===`time`?x(`unixSecondsFromTimestamp`,r.e):r.e;return{e:g(i,a,o),type:`bool`}}return tn(t,e.l,n,r),tn(t,e.r,r,n),{e:g(i,n.e,r.e),type:`bool`}}case`+`:return n.type===`string`&&r.type===`string`?{e:an(n.e,r.e),type:`string`}:nn(`+`,n,r);case`-`:return n.type===`time`&&r.type===`time`?{e:g(`/`,g(`-`,n.e,r.e),o(`1s`)),type:`number`,real:!0}:nn(`-`,n,r);case`*`:case`/`:case`%`:{let t=$t(n),i=$t(r);return e.op===`/`?{e:en(t,i),type:`number`,real:!0}:{e:g(e.op,t.e,i.e),type:`number`,real:(t.real??!1)||(i.real??!1)}}}}function $t(e){return e.type===`time`?{e:x(`unixSecondsFromTimestamp`,e.e),type:`number`}:e}function en(e,n){return e.real||n.real?g(`/`,e.e,n.e):n.e.k===`num`&&/^\d+$/.test(n.e.v)?g(`/`,e.e,t(`${n.e.v}.0`)):e.e.k===`num`&&/^\d+$/.test(e.e.v)?g(`/`,t(`${e.e.v}.0`),n.e):g(`/`,x(`toDouble`,e.e),n.e)}function tn(e,t,n,r){t.t===`field`&&n.type===`unknown`&&r.type===`number`&&n.e.k===`field`&&e.report(`SPL3006`,t.span,{subject:`type:${n.e.name}`,detail:`"${t.name}" has no declared type; DQL will not compare text with a number the way Splunk does.`})}function nn(e,t,n){return t.type===`time`&&(n.type===`number`||n.type===`unknown`)?n.e.k===`num`&&/^\d+$/.test(n.e.v)?{e:g(e,t.e,o(`${n.e.v}s`)),type:`time`}:{e:g(e,t.e,g(`*`,n.e,o(`1s`))),type:`time`}:{e:g(e,t.e,n.e),type:t.type===`number`&&n.type===`number`?`number`:`unknown`,real:(t.real??!1)||(n.real??!1)}}function rn(e){return e.replace(/^(-?)\./,`$10.`).replace(/\.(?=$|[eE])/,`.0`)}function an(e,t){let n=e=>e.k===`call`&&e.fn===`concat`?e.args.map(e=>e.value):[e];return x(`concat`,...n(e),...n(t))}const F=(e,t=`unknown`,n)=>(r,i,a)=>{if(n!==void 0&&r.length!==n)throw I(a,n);return{e:x(e,...r.map(e=>P(e,i).e)),type:t}};function on(e,t){let n=e[0];if(n===void 0)throw new A(`SPL1004`,t.span,`${t.fn}() expects at least 1 argument.`);return n}const sn=(e,t,n)=>{throw new A(`SPL2004`,n.fnSpan,`${n.fn}() has no DQL equivalent.`)};function I(e,t){return new A(`SPL1004`,e.span,`${e.fn}() expects ${t} argument${t===1?``:`s`}.`)}function cn(e,t,n){if(e?.t!==`str`)throw new A(`SPL2004`,t.span,`${t.fn}() needs ${n} as a quoted literal to be translated.`);return e.v}function ln(e){if(e?.t===`num`&&/^-?\d+$/.test(e.v))return Number(e.v)}const un=k({if:(e,t,n)=>{if(e.length!==3)throw I(n,3);let[r,i,a]=e.map(e=>P(e,t));return{e:x(`if`,r.e,i.e,b(`else`,a.e)),type:i.type}},case:(e,t,n)=>{if(e.length<2||e.length%2!=0)throw new A(`SPL1004`,n.span,`case() needs condition/value pairs.`);let i=[];for(let t=0;t<e.length;t+=2)i.push([e[t],e[t+1]]);let a,o=i[i.length-1];o&&vn(o[0])&&(a=P(o[1],t).e,i.pop());let s=a;for(let e=i.length-1;e>=0;e--){let[n,r]=i[e],a=P(n,t).e,o=P(r,t).e;s=s===void 0?x(`if`,a,o):x(`if`,a,o,b(`else`,s))}return{e:s??r(),type:`unknown`}},coalesce:F(`coalesce`),nullif:(e,t,n)=>{if(e.length!==2)throw I(n,2);let i=P(e[0],t),a=P(e[1],t);return{e:x(`if`,g(`==`,i.e,a.e),r(),b(`else`,i.e)),type:i.type}},isnull:F(`isNull`,`bool`,1),isnotnull:F(`isNotNull`,`bool`,1),isnum:dn(t=>x(`in`,x(`type`,t),d([e(`long`),e(`double`)]))),isint:dn(t=>g(`==`,x(`type`,t),e(`long`))),isstr:dn(t=>g(`==`,x(`type`,t),e(`string`))),isbool:dn(t=>g(`==`,x(`type`,t),e(`boolean`))),typeof:(e,t,n)=>{let r=on(e,n);return t.report(`SPL3006`,n.span,{detail:`typeof() returns DQL type names (long, double, string …), not Splunk ones.`}),{e:x(`type`,P(r,t).e),type:`string`}},len:F(`stringLength`,`number`,1),lower:F(`lower`,`string`,1),upper:F(`upper`,`string`,1),trim:(e,t,n)=>{if(e.length!==1)throw new A(`SPL2004`,n.span,`trim() with a character list has no DQL equivalent.`);return{e:x(`trim`,P(e[0],t).e),type:`string`}},ltrim:sn,rtrim:sn,substr:hn,replace:(t,n,r)=>{if(t.length!==3)throw I(r,3);let i=P(t[0],n).e,a=cn(t[1],r,`the regular expression`),o=cn(t[2],r,`the replacement`);if(/\\\d/.test(o))throw new A(`SPL2006`,r.span,`Back-references in the replacement have no DQL equivalent.`);let c=Et(a);if(c!==void 0)return{e:x(`replaceString`,i,e(c),e(o)),type:`string`};let l=wt(a,{});if(!l.ok)throw new A(`SPL2006`,t[1].span,l.reason);return n.report(`SPL3008`,t[1].span),{e:x(`replacePattern`,i,s(xn(l.dpl)),e(o)),type:`string`}},split:F(`splitString`,`array`,2),mvindex:(e,n,r)=>{let i=P(on(e,r),n).e,a=ln(e[1]);if(e.length===2){if(a===void 0)throw new A(`SPL2004`,r.span,`mvindex() needs a literal position to be translated.`);return{e:_(i,a),type:`unknown`}}if(e.length!==3)throw I(r,3);let o=ln(e[2]);if(a===void 0||o===void 0){n.report(`SPL3007`,r.span);let a=P(e[1],n).e,o=g(`+`,P(e[2],n).e,t(1));return{e:x(`arraySlice`,i,b(`from`,a),b(`to`,o)),type:`array`}}return o===-1?{e:x(`arraySlice`,i,b(`from`,t(a))),type:`array`}:{e:x(`arraySlice`,i,b(`from`,t(a)),b(`to`,t(o+1))),type:`array`}},mvcount:(e,t,n)=>(t.report(`SPL3013`,n.span,{detail:`mvcount() counts array elements; a single value that is not an array has no count in DQL.`}),{e:x(`arraySize`,P(on(e,n),t).e),type:`number`}),mvjoin:(e,t,n)=>{if(e.length!==2)throw I(n,2);return{e:x(`arrayToString`,P(e[0],t).e,b(`delimiter`,P(e[1],t).e)),type:`string`}},mvappend:(e,t)=>({e:w(`arrayConcat`,e.map(e=>x(`toArray`,P(e,t).e))),type:`array`}),mvdedup:F(`arrayDistinct`,`array`,1),mvsort:F(`arraySort`,`array`,1),mvfilter:(e,t,n)=>{let r=e[0],a=/* @__PURE__ */ new Set;if(r&&yn(r,a),!r||a.size!==1)throw new A(`SPL2004`,n.span,`mvfilter() can only be translated when the condition uses one field.`);let o=[...a][0],s=t.field(o,n.span),c=P(r,t).e;return{e:x(`arrayRemoveNulls`,x(`iCollectArray`,x(`if`,bn(c,s),_(i(s))))),type:`array`}},mvfind:sn,mvzip:sn,mvrange:sn,mvmap:sn,tostring:(t,n,r)=>{let i=P(on(t,r),n).e;if(t.length===1)return{e:x(`toString`,i),type:`string`};let a=cn(t[1],r,`the format`);if(a===`hex`)return{e:x(`concat`,e(`0x`),x(`numberToHexString`,i)),type:`string`};throw new A(`SPL2004`,r.span,`tostring() with format "${a}" has no DQL equivalent.`)},tonumber:(e,t,n)=>{let r=P(on(e,n),t).e;if(e.length===1)return{e:x(`toDouble`,r),type:`number`,real:!0};if(ln(e[1])===16)return{e:x(`hexStringToNumber`,r),type:`number`};if(ln(e[1])===10)return{e:x(`toDouble`,r),type:`number`,real:!0};throw new A(`SPL2004`,n.span,`tonumber() only translates for base 10 and 16.`)},round:(e,t,n)=>{let r=P(on(e,n),t).e;if(e.length===1)return{e:x(`round`,r),type:`number`};let i=ln(e[1]);if(i!==void 0&&i<0)throw new A(`SPL2004`,n.span,`round() to negative decimals has no DQL equivalent.`);return{e:x(`round`,r,b(`decimals`,P(e[1],t).e)),type:`number`}},floor:F(`floor`,`number`,1),ceil:F(`ceil`,`number`,1),ceiling:F(`ceil`,`number`,1),abs:F(`abs`,`number`,1),sqrt:F(`sqrt`,`number`,1),exp:F(`exp`,`number`,1),pow:F(`power`,`number`,2),ln:F(`log`,`number`,1),log:(e,t,n)=>{let r=P(on(e,n),t).e;return e.length===1?{e:x(`log10`,r),type:`number`}:{e:g(`/`,x(`log`,r),x(`log`,P(e[1],t).e)),type:`number`}},pi:F(`pi`,`number`,0),exact:(e,t,n)=>P(on(e,n),t),sigfig:sn,printf:sn,max:fn(`arrayMax`),min:fn(`arrayMin`),random:()=>({e:x(`toLong`,g(`*`,x(`random`),t(2147483647))),type:`number`}),like:F(`like`,`bool`,2),match:(e,t,n)=>{if(e.length!==2)throw I(n,2);let r=P(e[0],t).e,i=wt(cn(e[1],n,`the regular expression`),{forMatch:!0});if(!i.ok)throw new A(`SPL2006`,e[1].span,i.reason);return t.report(`SPL3008`,e[1].span),{e:x(`matchesPattern`,r,s(i.dpl)),type:`bool`}},searchmatch:(e,t,r)=>{let i=e[0];if(i?.t!==`str`)throw new A(`SPL2004`,r.span,`searchmatch() needs a quoted search.`);let a=i.v,o=et(a,0,a.length);return t.report(`SPL3011`,r.span),o?{e:ze(o,t,a,!0),type:`bool`}:{e:n(!0),type:`bool`}},cidrmatch:(e,t,n)=>{if(e.length!==2)throw I(n,2);return{e:x(`ipIn`,P(e[1],t).e,P(e[0],t).e),type:`bool`}},in:(e,t,n)=>{if(e.length<2)throw I(n,2);return{e:x(`in`,P(e[0],t).e,d(e.slice(1).map(e=>P(e,t).e))),type:`bool`}},md5:F(`hashMd5`,`string`,1),sha1:F(`hashSha1`,`string`,1),sha256:F(`hashSha256`,`string`,1),sha512:F(`hashSha512`,`string`,1),urldecode:F(`decodeUrl`,`string`,1),spath:pn,json_extract:pn,validate:sn,true:()=>({e:n(!0),type:`bool`}),false:()=>({e:n(!1),type:`bool`}),null:()=>({e:r(),type:`unknown`}),now:()=>({e:x(`now`),type:`time`}),time:()=>({e:x(`now`),type:`time`}),relative_time:(e,t,n)=>{if(e.length!==2)throw I(n,2);let r=P(e[0],t),i=cn(e[1],n,`the time modifier`);return{e:gn(r.type===`time`?r.e:x(`timestampFromUnixSeconds`,x(`toLong`,r.e)),i,n),type:`time`}},strftime:(t,n,r)=>{if(t.length!==2)throw I(r,2);let i=P(t[0],n),a=cn(t[1],r,`the format`),o=i.type===`time`?i.e:x(`timestampFromUnixSeconds`,x(`toLong`,i.e));if(a===`%s`)return{e:x(`unixSecondsFromTimestamp`,o),type:`number`};let s=Yt(a);if(!s.ok)throw new A(`SPL2004`,t[1].span,`The format directive ${s.directive} has no DQL equivalent.`);return n.report(`SPL3010`,r.span),{e:x(`formatTimestamp`,o,b(`format`,e(s.format))),type:`string`}},strptime:(e,t,n)=>{if(e.length!==2)throw I(n,2);let r=P(e[0],t).e,i=Yt(cn(e[1],n,`the format`));if(!i.ok)throw new A(`SPL2004`,e[1].span,`The format directive ${i.directive} has no DQL equivalent.`);return t.report(`SPL3010`,n.span),{e:x(`parse`,r,s(`TIMESTAMP(${Bt(i.format)}):t`)),type:`time`}}});function dn(e){return(t,n,r)=>{let i=on(t,r);return n.report(`SPL3006`,r.span,{detail:`${r.fn}() tests the stored type in DQL, not whether the text looks like a number.`}),{e:e(P(i,n).e),type:`bool`}}}function fn(e){return(t,n,r)=>(n.report(`SPL3006`,r.span,{detail:`${r.fn}() of several values ignores values that are not numbers in DQL.`}),{e:x(e,w(`array`,t.map(e=>P(e,n).e))),type:`number`})}function pn(t,n,r){if(t.length!==2)throw I(r,2);let i=P(t[0],n).e,a=cn(t[1],r,`the path`);return{e:x(`jsonPath`,i,e(mn(a))),type:`unknown`}}function mn(e){return`$.${e.replace(/\{\}/g,`[*]`).replace(/\{(\d+)\}/g,`[$1]`)}`}function hn(e,n,r){if(e.length<2||e.length>3)throw I(r,3);let i=P(e[0],n).e,a=ln(e[1]),o=e.length===3?ln(e[2]):void 0;if(a!==void 0&&(e.length===2||o!==void 0)){if(a<0){if(o===void 0)return{e:x(`substring`,i,b(`from`,t(a))),type:`string`};let e=a+o;return e>=0?{e:x(`substring`,i,b(`from`,t(a))),type:`string`}:{e:x(`substring`,i,b(`from`,t(a)),b(`to`,t(e))),type:`string`}}let e=Math.max(0,a-1);return o===void 0?{e:x(`substring`,i,b(`from`,t(e))),type:`string`}:{e:x(`substring`,i,b(`from`,t(e)),b(`to`,t(e+o))),type:`string`}}n.report(`SPL3007`,r.span);let s=g(`-`,P(e[1],n).e,t(1));return e.length===2?{e:x(`substring`,i,b(`from`,s)),type:`string`}:{e:x(`substring`,i,b(`from`,s),b(`to`,g(`+`,s,P(e[2],n).e))),type:`string`}}function gn(e,t,n){let r=/^([+-]\d+)([A-Za-z]*)?(?:@([A-Za-z]+\d?))?$/.exec(t.trim())??/^()()@([A-Za-z]+\d?)$/.exec(t.trim());if(!r)throw new A(`SPL2004`,n.span,`relative_time() with "${t}" cannot be translated.`);let i=e;if(r[1]){let e=Oe(r[2]||`s`);if(!e)throw new A(`SPL2004`,n.span,`Unknown time unit in "${t}".`);let a=r[1].replace(/^[+-]/,``);i=g(r[1].startsWith(`-`)?`-`:`+`,i,o(`${a}${e}`))}if(r[3]){let e=r[3].toLowerCase(),a=e.startsWith(`w`)?e===`w`||e===`w7`?`w0`:e:Oe(e);if(!a)throw new A(`SPL2004`,n.span,`Unknown snap unit in "${t}".`);i=v(i,a)}return i}function _n(e,t){let n=Object.hasOwn(un,e.fn)?un[e.fn]:void 0;if(!n)throw new A(`SPL2004`,e.fnSpan,`${e.fn}() is not a function the translator knows.`);return n(e.args,t,e)}function vn(e){return e.t===`call`&&e.fn===`true`&&e.args.length===0||e.t===`bin`&&(e.op===`=`||e.op===`==`)&&e.l.t===`num`&&e.r.t===`num`&&e.l.v===e.r.v}function yn(e,t){if(e.t===`field`)t.add(e.name);else if(e.t===`call`)for(let n of e.args)yn(n,t);else if(e.t===`un`)yn(e.e,t);else if(e.t===`bin`)yn(e.l,t),yn(e.r,t);else if(e.t===`in`){yn(e.e,t);for(let n of e.list)yn(n,t)}}function bn(e,t){return e.k===`field`&&e.name===t?_(e):e.k===`call`?{...e,args:e.args.map(e=>({...e,value:bn(e.value,t)}))}:e.k===`un`?{...e,e:bn(e.e,t)}:e.k===`bin`?{...e,l:bn(e.l,t),r:bn(e.r,t)}:e.k===`block`?{...e,items:e.items.map(e=>bn(e,t))}:e}function xn(e){return e.startsWith(`DATA? `)?e.slice(6):e}const Sn=[{name:`rex`,tier:`T2`,summary:`parse field, "<pattern>" for the convertible regex subset; mode=sed → replaceString/replacePattern.`,lower(n){let r=n.scanner(),a=`_raw`,o=n.span,c=!1,l=1,u;for(;!r.atEnd();){let e=r.option();if(e){let t=e.name.toLowerCase();if(t===`field`)a=e.value,o=e.valueSpan;else if(t===`mode`&&e.value.toLowerCase()===`sed`)c=!0;else if(t===`max_match`&&/^\d{1,6}$/.test(e.value))l=Number(e.value);else throw new A(`SPL2003`,e.span,`rex ${e.name}=${e.value} cannot be translated.`);continue}let t=r.quoted();if(!t||u)throw new A(`SPL1003`,r.here(),`rex needs one quoted regular expression.`);u=t}if(!u)throw new A(`SPL1003`,n.span,`rex needs a quoted regular expression.`);let d=n.field(a,o);if(c){let t=/^s\/((?:\\.|[^/\\])*)\/((?:\\.|[^/\\])*)\/([gi0-9]*)$/.exec(u.value);if(!t)throw new A(`SPL2003`,u.span,`Only s/regex/replacement/ sed expressions can be translated.`);let[,r,a,o]=t;if(/\\\d/.test(a))throw new A(`SPL2006`,u.span,`Back-references in the replacement have no DQL equivalent.`);o.includes(`g`)||n.report(`SPL3008`,u.span,{detail:`Without the g flag sed replaces the first match only; DQL replaces every match.`});let c=a.replace(/\\\//g,`/`),l=Et(r.replace(/\\\//g,`/`));if(l!==void 0){n.emit(S(`fieldsAdd`,f(d,x(`replaceString`,i(d),e(l),e(c)))));return}let p=wt(r.replace(/\\\//g,`/`),{});if(!p.ok)throw new A(`SPL2006`,u.span,p.reason);n.report(`SPL3008`,u.span);let m=p.dpl.startsWith(`DATA? `)?p.dpl.slice(6):p.dpl;n.emit(S(`fieldsAdd`,f(d,x(`replacePattern`,i(d),s(m),e(c)))));return}let p=wt(u.value,l===1?{captures:!0}:{captures:!0,everyMatch:!0});if(!p.ok){for(let e of u.value.matchAll(/\(\?P?<([A-Za-z_][A-Za-z0-9_]*)>/g))n.state.unresolved.add(e[1]);throw new A(`SPL2006`,u.span,p.reason)}if(p.captures.length===0)throw new A(`SPL2003`,u.span,`rex without named groups (?<name>…) extracts nothing.`);if(l!==1){let e=p.captures[0];if(p.captures.length!==1||!e||p.anchoredStart){for(let e of p.captures)n.state.unresolved.add(e.name);throw new A(`SPL2003`,u.span,`rex max_match is only translated for one named group and a pattern without "^".`)}n.report(`SPL3008`,u.span),n.report(`SPL3013`,n.span,{detail:`The matches are returned as an array, not as a Splunk multivalue field.`});let r=x(`parseAll`,i(d),s(p.dpl)),a=n.field(e.name,u.span,!0);n.emit(S(`fieldsAdd`,f(a,l===0?r:x(`arraySlice`,r,b(`from`,t(0)),b(`to`,t(l)))))),n.setType(a,void 0),n.addFields([e.name])}else{n.report(`SPL3008`,u.span),n.emit(S(`parse`,i(d),s(p.dpl)));for(let e of p.captures)n.setType(n.field(e.name,u.span,!0),e.type===`number`?`number`:`string`);n.addFields(p.captures.map(e=>e.name))}}},{name:`spath`,tier:`T2`,summary:`jsonPath() for one path; without a path, parse content as JSON and flatten.`,lower(t){let n=t.scanner(),r=`_raw`,a,o;for(;!n.atEnd();){let e=n.option();if(e){let t=e.name.toLowerCase();if(t===`input`)r=e.value;else if(t===`path`)a=e.value;else if(t===`output`)o=e.value;else throw new A(`SPL2003`,e.span,`spath ${e.name}= cannot be translated.`);continue}let t=n.value();if(!t||a!==void 0)throw new A(`SPL1003`,n.here(),`Unexpected text in spath.`);a=t.value}let c=i(t.field(r,t.span));if(a===void 0){t.report(`SPL3016`,t.span,{detail:`JSON fields get Grail names (json.a.b) instead of Splunk names (a.b{}.c).`}),t.emit(S(`parse`,c,s(`JSON:json`))),t.emit(S(`fieldsFlatten`,i(`json`)));return}a.includes(`{}`)&&t.report(`SPL3013`,t.span,{detail:`An array path returns an array in DQL.`});let l=t.field(o??a,t.span,!0);t.emit(S(`fieldsAdd`,f(l,x(`jsonPath`,c,e(mn(a)))))),t.addFields([l])}}];var Cn=class extends Error{span;constructor(e,t){super(e),this.span=t}};const wn=2e4;function Tn(e,t,n){let r=new On(En(e,t,n)),i=r.expr();return r.expectEnd(),i}function En(e,t,n){let r=[],i=t;for(;i<n;){let t=e[i];if(/\s/.test(t)){i++;continue}let a=i;if(t===`"`){let t=O(e,i,n);if(t===-1)throw new Cn(`A quoted string is not closed.`,{start:i,end:n});r.push({type:`str`,text:ve(e.slice(i+1,t)),span:{start:a,end:t+1}}),i=t+1;continue}if(t===`$`){let t=/^\$[A-Za-z_][A-Za-z0-9_.]*(?:\|[A-Za-z]+)?\$/.exec(e.slice(i,Math.min(n,i+200)));if(t){r.push({type:`str`,text:t[0],span:{start:a,end:i+t[0].length}}),i+=t[0].length;continue}}if(t===`'`){let t=e.indexOf(`'`,i+1);if(t===-1||t>=n)throw new Cn(`A quoted field name is not closed.`,{start:i,end:n});r.push({type:`field`,text:e.slice(i+1,t),span:{start:a,end:t+1}}),i=t+1;continue}if(/[0-9]/.test(t)||t===`.`&&/[0-9]/.test(e[i+1]??``)){let t=/^(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?/.exec(e.slice(i,Math.min(n,i+64))),o=t?t[0].length:1;if(/[A-Za-z_]/.test(e[i+o]??``)){i=Dn(e,i,n,r);continue}r.push({type:`num`,text:e.slice(i,i+o),span:{start:a,end:i+o}}),i+=o;continue}if(/[A-Za-z_]/.test(t)){i=Dn(e,i,n,r);continue}let o=e.slice(i,i+2);if(o===`==`||o===`!=`||o===`<=`||o===`>=`)r.push({type:`op`,text:o,span:{start:a,end:i+2}}),i+=2;else if(`=<>+-*/%.`.includes(t))r.push({type:`op`,text:t,span:{start:a,end:i+1}}),i++;else if(t===`(`||t===`)`||t===`,`)r.push({type:t,text:t,span:{start:a,end:i+1}}),i++;else throw new Cn(`Unexpected character "${t}".`,{start:i,end:i+1})}if(r.push({type:`eof`,text:``,span:{start:n,end:n}}),r.length>wn)throw new Cn(`The expression has more than ${wn} parts.`,{start:t,end:n});return r}function Dn(e,t,n,r){let i=t;for(;t<n&&/[A-Za-z0-9_.{}@:]/.test(e[t])&&(e[t]!==`.`||/[A-Za-z0-9_{]/.test(e[t+1]??``));)t++;return r.push({type:`ident`,text:e.slice(i,t),span:{start:i,end:t}}),t}var On=class{i=0;depth=0;toks;constructor(e){this.toks=e}get t(){return this.toks[this.i]??this.toks[this.toks.length-1]}ty(){return this.t.type}next(){return this.toks[this.i++]??this.toks[this.toks.length-1]}word(e){return this.t.type===`ident`&&this.t.text.toUpperCase()===e}op(e){return this.t.type===`op`&&this.t.text===e}fail(e){throw new Cn(`${e}, found ${this.t.type===`eof`?`the end`:`"${this.t.text}"`}.`,this.t.span)}expectEnd(){this.t.type!==`eof`&&this.fail(`Unexpected text in expression`)}guard(e){if(++this.depth>200)throw new Cn(`The expression is nested too deeply.`,this.t.span);try{return e()}finally{this.depth--}}expr(){return this.guard(()=>this.left([`XOR`],()=>this.left([`OR`],()=>this.left([`AND`],()=>this.notExpr()))))}left(e,t){let n=t();for(;e.some(e=>this.word(e));){let e=this.next().text.toUpperCase(),r=t();n={t:`bin`,op:e,l:n,r,span:{start:n.span.start,end:r.span.end}}}return n}notExpr(){if(this.word(`NOT`)){let e=this.next().span.start,t=this.guard(()=>this.notExpr());return{t:`un`,op:`NOT`,e:t,span:{start:e,end:t.span.end}}}return this.comparison()}comparison(){let e=this.additive(),t=this.t;if(t.type===`op`&&[`=`,`==`,`!=`,`<`,`<=`,`>`,`>=`].includes(t.text)){this.next();let n=this.additive();return{t:`bin`,op:t.text,l:e,r:n,span:{start:e.span.start,end:n.span.end}}}if(this.word(`LIKE`)){this.next();let t=this.additive();return{t:`bin`,op:`LIKE`,l:e,r:t,span:{start:e.span.start,end:t.span.end}}}if(this.word(`IN`)){this.next(),this.t.type!==`(`&&this.fail(`Expected "(" after IN`),this.next();let t=[];if(this.ty()!==`)`)for(t.push(this.expr());this.ty()===`,`;)this.next(),t.push(this.expr());this.ty()!==`)`&&this.fail(`Expected ")"`);let n=this.next().span.end;return{t:`in`,e,list:t,span:{start:e.span.start,end:n}}}return e}additive(){let e=this.multiplicative();for(;this.op(`+`)||this.op(`-`)||this.op(`.`);){let t=this.next().text,n=this.multiplicative();e={t:`bin`,op:t,l:e,r:n,span:{start:e.span.start,end:n.span.end}}}return e}multiplicative(){let e=this.unary();for(;this.op(`*`)||this.op(`/`)||this.op(`%`);){let t=this.next().text,n=this.unary();e={t:`bin`,op:t,l:e,r:n,span:{start:e.span.start,end:n.span.end}}}return e}unary(){if(this.op(`-`)){let e=this.next().span.start,t=this.guard(()=>this.unary());return t.t===`num`?{t:`num`,v:`-${t.v}`,span:{start:e,end:t.span.end}}:{t:`un`,op:`-`,e:t,span:{start:e,end:t.span.end}}}return this.op(`+`)?(this.next(),this.guard(()=>this.unary())):this.primary()}primary(){let e=this.t;switch(e.type){case`num`:return this.next(),{t:`num`,v:e.text,span:e.span};case`str`:return this.next(),{t:`str`,v:e.text,span:e.span};case`field`:return this.next(),{t:`field`,name:e.text,span:e.span};case`ident`:if(this.next(),this.t.type===`(`){this.next();let t=[];if(this.ty()!==`)`)for(t.push(this.expr());this.ty()===`,`;)this.next(),t.push(this.expr());this.ty()!==`)`&&this.fail(`Expected ")" to close the function call`);let n=this.next().span.end;return{t:`call`,fn:e.text.toLowerCase(),args:t,span:{start:e.span.start,end:n},fnSpan:e.span}}return{t:`field`,name:e.text,span:e.span};case`(`:{this.next();let e=this.expr();return this.ty()!==`)`&&this.fail(`Expected ")"`),this.next(),e}default:return this.fail(`Expected a value`)}}};function kn(e,t=[]){let n=[];for(;!(e.atEnd()||t.some(t=>e.peekKeyword(t)));){if(e.eat(`,`))continue;if(/^[A-Za-z_][A-Za-z0-9_]*\s*=(?!=)/.test(e.text.slice(e.pos,Math.min(e.end,e.pos+80))))break;let t=e.fieldName();if(!t)throw new A(`SPL1003`,e.here(),`Expected a field name.`);n.push({name:t.value,span:t.span})}return n}function An(e,t){if(e.state.schema.kind!==`events`)return e.state.schema.fields.filter(n=>Xe(t,e.splName(n)))}const jn={name:`table`,tier:`T1`,summary:`fields a, b (wildcards → fieldsKeep "a*").`,lower(t){let n=kn(t.scanner());if(n.length===0)throw new A(`SPL1003`,t.span,`table needs at least one field.`);let r=[],a=!1;for(let e of n)if(e.name.includes(`*`)){let n=An(t,e.name);n?j(r,n):a=!0}else r.push(t.field(e.name,e.span));a?(t.report(`SPL2009`,t.span,{detail:`Wildcards keep matching fields, but the column order of table is not reproduced.`}),t.emit(C(`fieldsKeep`,n.map(n=>n.name.includes(`*`)?e(n.name):i(t.field(n.name,n.span))))),t.setTable(r)):(t.emit(C(`fields`,r.map(i))),t.setTable(r))}},Mn={name:`fields`,tier:`T1`,summary:`fieldsKeep / fieldsRemove; on raw events timestamp and content are kept, as Splunk keeps _time and _raw.`,lower(t){let n=t.scanner(),r=!1;n.eat(`-`)?r=!0:n.eat(`+`);let a=kn(n);if(a.length===0)throw new A(`SPL1003`,t.span,`fields needs at least one field.`);if(r){a.some(e=>e.name.startsWith(`_`)&&e.name.includes(`*`))&&t.report(`SPL2009`,t.span,{detail:`Removing internal fields (_*) has no direct equivalent; they were kept.`});let n=a.filter(e=>!(e.name.startsWith(`_`)&&e.name.includes(`*`)));if(n.length===0)return;if(t.emit(C(`fieldsRemove`,n.map(n=>n.name.includes(`*`)?e(n.name):i(t.field(n.name,n.span))))),t.state.schema.kind!==`events`){let e=new Set(n.map(e=>t.field(e.name,e.span,!0)));t.setTable(t.state.schema.fields.filter(r=>!e.has(r)&&!n.some(e=>e.name.includes(`*`)&&Xe(e.name,t.splName(r)))))}return}let o=[],s=[];for(let n of a){if(n.name.includes(`*`)){o.push(e(n.name));continue}let r=t.field(n.name,n.span);o.push(i(r)),s.push(r)}if(t.state.schema.kind===`events`)for(let e of[`timestamp`,`content`])s.includes(e)||o.push(i(e));t.emit(C(`fieldsKeep`,o)),a.every(e=>!e.name.includes(`*`))&&t.setTable(t.state.schema.kind===`events`?[...s,`timestamp`,`content`]:s)}},Nn={name:`rename`,tier:`T1`,summary:`fieldsRename new = old.`,lower(e){if(e.state.datamodel&&/^\s*"?[A-Za-z_][A-Za-z0-9_.]*"?\.\*\s+as\s+\*\s*$/i.test(e.slice(e.argsSpan))){e.report(`SPL5007`,e.span,{detail:`The data-model prefix is not carried into DQL, so this rename has nothing to do.`});return}let t=e.scanner(),n=[],r=[],a=0;for(;!t.atEnd();){if(t.eat(`,`))continue;let o=t.fieldName();if(!o||!t.keyword(`as`))throw new A(`SPL1003`,t.here(),`Expected "field AS newname".`);let s=t.fieldName();if(!s)throw new A(`SPL1003`,t.here(),`Expected a new name after AS.`);if(o.value.includes(`*`)||s.value.includes(`*`))throw new A(`SPL2009`,o.span,`Renaming with wildcards needs the list of fields.`);let c=e.field(o.value,o.span),l=e.field(s.value,s.span,!0);c===l?a++:(n.push(f(l,i(c))),r.push([c,l]))}if(!(n.length===0&&a>0)){if(n.length===0)throw new A(`SPL1003`,e.span,`rename needs "field AS newname".`);e.emit(C(`fieldsRename`,n)),e.state.schema.kind!==`events`&&e.setTable(e.state.schema.fields.map(e=>r.find(([t])=>t===e)?.[1]??e))}}};function Pn(n){return!n.quoted&&/^-?\d+(\.\d+)?$/.test(n.value)?t(n.value):e(n.value)}const Fn={name:`fillnull`,tier:`T1`,summary:`fieldsAdd f = coalesce(f, value).`,lower(e){let n=e.scanner(),r=t(0),a=n.option();if(a){if(a.name.toLowerCase()!==`value`)throw new A(`SPL2003`,a.span,`Option ${a.name} is not supported.`);r=Pn(a)}let o=kn(n),s=o.map(t=>t.name.includes(`*`)?void 0:e.field(t.name,t.span));if(o.length===0||s.includes(void 0)){let t=e.state.schema.kind===`events`?void 0:e.state.schema.fields;if(!t)throw new A(`SPL2009`,e.span,`fillnull without a field list needs the list of fields.`);s=o.length===0?t:t.filter(t=>o.some(n=>Xe(n.name,e.splName(t))))}let c=s.map(e=>f(e,x(`coalesce`,i(e),r)));c.length>0&&e.emit(C(`fieldsAdd`,c))}},In={name:`replace`,tier:`T1`,summary:`fieldsAdd f = if(f == "x", "y", else: f).`,lower(t){let n=t.scanner(),r=[];for(;!n.peekKeyword(`in`);){if(n.eat(`,`))continue;let e=n.value();if(!e||!n.keyword(`with`))throw new A(`SPL1003`,n.here(),`Expected "value WITH replacement".`);let t=n.value();if(!t)throw new A(`SPL1003`,n.here(),`Expected a replacement after WITH.`);if(e.value.includes(`*`)||t.value.includes(`*`))throw new A(`SPL2009`,e.span,`Wildcard replacements are not supported.`);r.push([e,t])}if(!n.keyword(`in`))throw new A(`SPL2003`,t.span,`replace without IN <fields> needs the list of fields.`);if(r.length>500)throw new A(`SPL1006`,t.span,`replace has more than 500 value pairs; translate it in parts.`);let a=kn(n),o=[];for(let n of a){if(n.name.includes(`*`))throw new A(`SPL2009`,n.span,`Wildcard field names need the list of fields.`);let a=t.field(n.name,n.span),s=i(a);for(let t=r.length-1;t>=0;t--){let[n,o]=r[t];s=x(`if`,g(`==`,i(a),e(n.value)),e(o.value),b(`else`,s))}o.push(f(a,s))}t.emit(C(`fieldsAdd`,o))}},Ln={name:`convert`,tier:`T2`,summary:`ctime() → formatTimestamp, num()/auto() → toDouble.`,lower(t){let n=t.scanner(),r=`MM/dd/yyyy HH:mm:ss`,a=[];for(;!n.atEnd();){if(n.eat(`,`))continue;let o=n.option();if(o){if(o.name.toLowerCase()!==`timeformat`)throw new A(`SPL2003`,o.span,`Option ${o.name} is not supported.`);let e=Yt(o.value);if(!e.ok)throw new A(`SPL2003`,o.valueSpan,`The format directive ${e.directive} has no DQL equivalent.`);r=e.format;continue}let s=n.word(`(`),c=n.balanced(`(`,`)`);if(!s||!c)throw new A(`SPL1003`,n.here(),`Expected a conversion such as ctime(field).`);let l=t.slice(c.inner).trim(),u=l;if(n.keyword(`as`)){let e=n.fieldName();if(!e)throw new A(`SPL1003`,n.here(),`Expected a name after AS.`);u=e.value}let d=t.field(l,c.inner),p=i(d),m=t.fieldType(d)===`time`,h=t.field(u,c.inner,!0);switch(s.value.toLowerCase()){case`ctime`:t.report(`SPL3010`,s.span),a.push(f(h,x(`formatTimestamp`,m?p:x(`timestampFromUnixSeconds`,x(`toLong`,p)),b(`format`,e(r))))),t.setType(h,`string`);break;case`num`:case`auto`:a.push(f(h,x(`toDouble`,p))),t.setType(h,`number`);break;case`none`:break;default:throw new A(`SPL2003`,s.span,`convert ${s.value}() has no DQL equivalent.`)}}a.length>0&&t.emit(C(`fieldsAdd`,a))}},Rn={name:`addtotals`,tier:`T2`,summary:`fieldsAdd Total = coalesce(a, 0) + coalesce(b, 0) for listed fields.`,lower(e){let n=e.scanner(),r=`Total`;for(let e=n.option();e;e=n.option()){let t=e.name.toLowerCase();if(t===`fieldname`)r=e.value;else if(t===`row`&&/^(t|true|1)$/i.test(e.value))continue;else if(t===`col`&&/^(f|false|0)$/i.test(e.value))continue;else throw new A(`SPL2003`,e.span,`addtotals ${e.name}=${e.value} has no DQL equivalent.`)}let a=kn(n);if(a.length===0||a.some(e=>e.name.includes(`*`)))throw new A(`SPL2009`,e.span,`addtotals needs an explicit list of fields to sum.`);let o=a.map(n=>x(`coalesce`,i(e.field(n.name,n.span)),t(0))).reduce((e,t)=>e?g(`+`,e,t):t,void 0);e.emit(S(`fieldsAdd`,f(e.field(r,e.span,!0),o))),e.addFields([r])}},zn={name:`foreach`,tier:`T2`,summary:`Expands the template for each listed field into fieldsAdd.`,lower(e){let t=e.scanner();for(;t.option(););let n=[];for(;t.peek()!==`[`&&!t.atEnd();){if(t.eat(`,`))continue;let e=t.fieldName();if(!e)throw new A(`SPL1003`,t.here(),`Expected field names before the [ … ] template.`);n.push({name:e.value,span:e.span})}let r=t.balanced(`[`,`]`);if(!r||n.length===0)throw new A(`SPL1003`,e.span,`foreach needs fields and a [ eval … ] template.`);let i=e.slice(r.inner).trim(),a=/^eval\s+(.+)$/is.exec(i);if(!a)throw new A(`SPL2003`,r.span,`Only an eval template can be translated.`);let o=[];for(let t of n){if(!t.name.includes(`*`)){o.push({field:t.name,match:t.name});continue}let n=An(e,t.name);if(!n)throw new A(`SPL2009`,t.span,`foreach with a wildcard needs the list of fields.`);let[r,i]=[t.name.split(`*`)[0]??``,t.name.split(`*`).slice(-1)[0]??``];for(let t of n){let n=e.splName(t);o.push({field:n,match:n.slice(r.length,n.length-i.length)})}}let s=[],c=a[1];if(o.length*c.length>2e5)throw new A(`SPL1006`,e.span,`foreach would write its template ${o.length} times (${o.length*c.length} characters); the limit is 200000.`);for(let t of o){let n=c.split(`<<FIELD>>`).join(t.field).split(`<<MATCHSTR>>`).join(t.match),i=/^\s*([A-Za-z_][A-Za-z0-9_.]*|'[^']*')\s*=(?!=)([\s\S]+)$/.exec(n);if(!i)throw new A(`SPL1003`,r.span,`The template must be "field = expression".`);let a=i[1].replace(/^'|'$/g,``),o;try{o=Tn(n,n.length-i[2].length,n.length)}catch(e){throw e instanceof Cn?new A(`SPL1004`,r.span,e.message):e}s.push(f(e.field(a,r.span,!0),P(Bn(o,r.span),e).e))}e.emit(C(`fieldsAdd`,s))}};function Bn(e,t){if(Array.isArray(e))return e.map(e=>Bn(e,t));if(e&&typeof e==`object`){let n={};for(let[r,i]of Object.entries(e))n[r]=r===`span`||r===`fnSpan`?t:Bn(i,t);return n}return e}const Vn=[jn,Mn,Nn,Fn,In,Ln,Rn,zn,{name:`makemv`,tier:`T1`,summary:`fieldsAdd f = splitString(f, delim).`,lower(t){let n=t.scanner(),r=` `;for(let e=n.option();e;e=n.option()){let t=e.name.toLowerCase();if(t===`delim`)r=e.value;else if(t===`allowempty`||t===`setsv`)continue;else throw new A(`SPL2003`,e.span,`makemv ${e.name}= has no DQL equivalent.`)}let a=n.fieldName();if(!a)throw new A(`SPL1003`,t.span,`makemv needs a field.`);let o=t.field(a.value,a.span);t.emit(S(`fieldsAdd`,f(o,x(`splitString`,i(o),e(r)))))}},{name:`mvexpand`,tier:`T1`,summary:`expand f.`,lower(e){let n=e.scanner(),r=n.fieldName();if(!r)throw new A(`SPL1003`,e.span,`mvexpand needs a field.`);let a=n.option(),o=i(e.field(r.value,r.span));if(a&&a.name.toLowerCase()===`limit`&&/^\d+$/.test(a.value))e.emit(S(`expand`,o,b(`limit`,t(a.value))));else if(a)throw new A(`SPL2003`,a.span,`mvexpand ${a.name}= is not supported.`);else e.emit(S(`expand`,o))}},{name:`nomv`,tier:`T1`,summary:`fieldsAdd f = arrayToString(f, delimiter: "\\n").`,lower(t){let n=t.scanner().fieldName();if(!n)throw new A(`SPL1003`,t.span,`nomv needs a field.`);let r=t.field(n.value,n.span);t.emit(S(`fieldsAdd`,f(r,x(`arrayToString`,i(r),b(`delimiter`,e(`
3
3
  `))))))}},{name:`mvcombine`,tier:`T2`,summary:`summarize f = collectArray(f), by:{other fields}.`,lower(e){let t=e.scanner(),n=t.option();if(n&&n.name.toLowerCase()!==`delim`)throw new A(`SPL2003`,n.span,`mvcombine ${n.name}= is not supported.`);let r=t.fieldName();if(!r)throw new A(`SPL1003`,e.span,`mvcombine needs a field.`);if(e.state.schema.kind===`events`)throw new A(`SPL2009`,e.span,`mvcombine needs to know the other fields; use it after table or stats.`);let a=e.field(r.value,r.span),o=e.state.schema.fields.filter(e=>e!==a);e.report(`SPL3004`,e.span,{detail:`The order of the combined values is not guaranteed.`}),e.emit(S(`summarize`,f(a,x(`collectArray`,i(a))),b(`by`,d(o.map(i))))),e.setTable([...o,a])}},{name:`rangemap`,tier:`T2`,summary:`fieldsAdd range = if(...) for numeric ranges.`,lower(n){let r=n.scanner(),a,o,s=[];for(let t=r.option();t;t=r.option())if(t.name===`field`)a=t.value;else if(t.name==="default")o=e(t.value);else{let e=/^(-?\d+(?:\.\d+)?)-(-?\d+(?:\.\d+)?)$/.exec(t.value);if(!e)throw new A(`SPL2003`,t.span,`Range "${t.value}" is not a numeric range.`);s.push({name:t.name,lo:e[1],hi:e[2]})}if(!a||s.length===0)throw new A(`SPL1003`,n.span,`rangemap needs field= and at least one range.`);let c=i(n.field(a,n.span)),l=o??e(`None`);for(let n=s.length-1;n>=0;n--){let r=s[n];l=x(`if`,g(`and`,g(`>=`,c,t(r.lo)),g(`<=`,c,t(r.hi))),e(r.name),b(`else`,l))}n.emit(S(`fieldsAdd`,f(n.field(`range`,n.span,!0),l)))}}];function Hn(e){try{return et(e.tc.text,e.argsSpan.start,e.argsSpan.end)}catch(e){throw e instanceof M?new A(`SPL1001`,e.span,e.message):e}}function Un(e,t,n){try{return Tn(e.tc.text,t,n)}catch(e){throw e instanceof Cn?new A(`SPL1004`,e.span,e.message):e}}const Wn={name:`search`,tier:`T1`,summary:`Leading search → fetch with time range and filters; later searches → filter.`,generating:!0,lower(e){let t=Hn(e);e.first&&e.depth>=0&&e.state.schema.kind===`events`&&e.upstream.length===0?qe(e,t):Je(e,t)}},Gn={name:`where`,tier:`T1`,summary:`filter with eval semantics (case-sensitive comparisons).`,lower(e){if(e.argsSpan.start>=e.argsSpan.end||e.slice(e.argsSpan).trim()===``)throw new A(`SPL1003`,e.span,`where needs a condition.`);let t=Un(e,e.argsSpan.start,e.argsSpan.end);e.emit(S(`filter`,P(t,e).e))}},Kn={name:`eval`,tier:`T1`,summary:`fieldsAdd; split into several when an assignment uses a field set earlier in the same eval.`,lower(e){let t=qn(e);if(t.length===0)throw new A(`SPL1003`,e.span,`eval needs at least one "field = expression".`);let n=[],r=/* @__PURE__ */ new Set,i=()=>{n.length>0&&e.emit(C(`fieldsAdd`,n)),n=[],r=/* @__PURE__ */ new Set},a=0;for(let o of t){let t=Un(e,o.exprStart,o.exprEnd);[...Yn(t)].some(e=>r.has(e))&&i();try{let i=P(t,e),a=e.field(o.name,o.nameSpan,!0);n.push(f(a,i.e)),e.setType(a,i.type===`bool`?`boolean`:i.type===`array`||i.type===`unknown`?void 0:i.type),r.add(o.name)}catch(t){if(!(t instanceof A))throw t;a++,e.report(t.code,t.span,{detail:`${t.message} The assignment to "${o.name}" was left out.`}),e.state.unresolved.add(o.name)}}i(),a===t.length&&(e.untranslated=!0,e.out.length=0,e.out.push({name:`//`,args:[],origin:[e.index],comment:`not translated: ${e.slice(e.span)}`}))}};function qn(e){let t=e.tc.text,n=[],r=e.argsSpan.start,i=e.argsSpan.end;for(;r<i;){for(;r<i&&/[\s,]/.test(t[r]);)r++;if(r>=i)break;let e=/^("(?:[^"\\]|\\.)*"|'[^']*'|[A-Za-z_][A-Za-z0-9_.:{}@-]*)\s*=(?!=)/.exec(t.slice(r,Math.min(i,r+300)));if(!e)throw new A(`SPL1003`,{start:r,end:Math.min(i,r+1)},`Expected "field = expression".`);let a=e[1],o=/^["']/.test(a)?a.slice(1,-1):a,s={start:r,end:r+a.length},c=r+e[0].length,l=Jn(t,c,i);n.push({name:o,nameSpan:s,exprStart:c,exprEnd:l}),r=l+1}return n}function Jn(e,t,n){let r=0;for(let i=t;i<n;i++){let t=e[i];if(t===`"`||t===`'`){let r=e.indexOf(t,i+1);i=r===-1?n:r}else if(t===`(`)r++;else if(t===`)`)r--;else if(t===`,`&&r===0)return i}return n}function Yn(e,t=/* @__PURE__ */ new Set){if(e.t===`field`)t.add(e.name);else if(e.t===`call`)for(let n of e.args)Yn(n,t);else if(e.t===`un`)Yn(e.e,t);else if(e.t===`bin`)Yn(e.l,t),Yn(e.r,t);else if(e.t===`in`){Yn(e.e,t);for(let n of e.list)Yn(n,t)}return t}const Xn={name:`regex`,tier:`T2`,summary:`filter matchesPattern(field, "<pattern>") for the convertible regex subset.`,lower(e){let t=e.scanner(),n=`_raw`,r=!1,a=e.span,o=/^\s*([A-Za-z_][A-Za-z0-9_.]*)\s*(!=|=)\s*/.exec(e.slice(e.argsSpan));o&&(n=o[1],r=o[2]===`!=`,a={start:e.argsSpan.start+o[0].indexOf(n),end:e.argsSpan.start+o[0].indexOf(n)+n.length},t.pos=e.argsSpan.start+o[0].length);let c=t.quoted()??t.word();if(!c)throw new A(`SPL1003`,e.span,`regex needs a regular expression.`);let l=wt(c.value,{forMatch:!0});if(!l.ok)throw new A(`SPL2006`,c.span,l.reason);e.report(`SPL3008`,c.span);let u=x(`matchesPattern`,i(e.field(n,a)),s(l.dpl));e.emit(S(`filter`,r?m(u):u))}};function Zn(e){return{name:e,tier:`T1`,summary:`Dropped: display only.`,lower(t){t.report(`SPL5007`,t.span,{detail:`${e} only changes how results are shown; it was dropped.`})}}}const Qn=Zn(`fieldformat`),$n=Zn(`highlight`),er=Zn(`iconify`),tr=Zn(`abstract`),nr={name:`return`,tier:`T2`,summary:`fields f then limit N — only meaningful inside a subsearch.`,lower(e){let n=e.scanner(),r=n.integer()?.value??1,a=n.fieldName();if(!a||a.value.startsWith(`$`)||!n.atEnd())throw new A(`SPL2007`,e.span,`Only "return f" or "return N f" with one field can be translated.`);let o=e.field(a.value,a.span);e.emit(S(`fields`,i(o))),e.emit(S(`limit`,t(r))),e.setTable([o])}},rr=/* @__PURE__ */ new Set([`count`,`countIf`,`countDistinctExact`,`countDistinctApprox`,`sum`,`avg`,`median`,`percentile`,`stddev`,`variance`]);function ir(e){return e.expr.k===`bin`||e.expr.k===`call`&&rr.has(e.expr.fn)}const ar=[`by`,`over`,`where`,`from`],or=/^[A-Za-z_][A-Za-z0-9_]*\s*=(?!=)/;function sr(e,t){let n=[];for(;e.skipWs(),!(e.atEnd()||ar.some(t=>e.peekKeyword(t))||or.test(t.tc.text.slice(e.pos,Math.min(e.end,e.pos+80))));){if(e.eat(`,`))continue;let r=e.pos,i=e.word(`=(`);if(!i)throw new A(`SPL1003`,e.here(),`Expected an aggregation such as count or avg(field).`);let a=i.value.toLowerCase(),o,s;if(e.peek()===`(`&&e.pos===i.span.end){let n=e.balanced(`(`,`)`);if(!n)throw new A(`SPL1003`,i.span,`The parentheses after ${a} are not closed.`);let r=t.tc.text.slice(n.inner.start,n.inner.end).trim();if(/^eval\s*\(/i.exec(r)){let e=n.inner.start+t.tc.text.slice(n.inner.start,n.inner.end).indexOf(`(`)+1,r=ge(t.tc.text,e-1,n.inner.end,`(`,`)`);try{s=Tn(t.tc.text,e,r===-1?n.inner.end:r)}catch(e){throw e instanceof Cn?new A(`SPL1004`,e.span,e.message):e}}else if(r!==``){let e=t.tc.text.slice(n.inner.start,n.inner.end).search(/\S/),i=n.inner.start+Math.max(0,e);o={name:r.replace(/^"(.*)"$/,`$1`),span:{start:i,end:i+r.length}}}}let c=e.pos,l;if(e.keyword(`as`)){let t=e.fieldName();if(!t)throw new A(`SPL1003`,e.here(),`Expected a name after AS.`);l=t.value}let u={fn:a,defaultName:t.tc.text.slice(r,c).replace(/\s+/g,``),span:{start:r,end:e.pos}};o&&(u.fieldArg=o),s&&(u.evalArg=s),l!==void 0&&(u.alias=l),n.push(u)}return n}const cr=/* @__PURE__ */ new Set([`count`,`c`,`sum`,`avg`,`mean`,`min`,`max`,`median`,`dc`,`distinct_count`,`estdc`,`per_second`,`per_minute`,`per_hour`,`per_day`]);function lr(e){return cr.has(e.fn)||/^(perc|p|exactperc)\d{1,2}(\.\d+)?$/.test(e.fn)}const ur=k({per_second:`1s`,per_minute:`1m`,per_hour:`1h`,per_day:`1d`});function dr(e,n,r){let a=e.alias??e.defaultName,s=!1,c=()=>{if(e.evalArg){let t=P(e.evalArg,n);return s=t.type===`time`,t.e}if(e.fieldArg){if(e.fieldArg.name.includes(`*`))throw new A(`SPL2009`,e.fieldArg.span,`${e.fn}(${e.fieldArg.name}) needs the list of fields.`);let t=n.field(e.fieldArg.name,e.fieldArg.span);return s=n.fieldType(t)===`time`,i(t)}throw new A(`SPL1003`,e.span,`${e.fn}() needs a field.`)},l=(e,t,n)=>{let r={expr:x(e,t),name:a};return n&&(r.order=n),s&&(r.time=!0),r},u=r===`series`,d=u?[b(`default`,t(0))]:[],f=e.fn;if(f===`count`||f===`c`)return e.evalArg?{expr:x(`countIf`,P(e.evalArg,n).e,...d),name:a}:e.fieldArg?{expr:x(`countIf`,x(`isNotNull`,c()),...d),name:a}:{expr:w(`count`,d),name:a};let p=/^(perc|p|exactperc|upperperc)(\d{1,2}(?:\.\d+)?)$/.exec(f);if(p)return p[1]===`upperperc`?fr(e,n,`upperperc() has no DQL equivalent.`):(n.report(`SPL3005`,e.span),{expr:x(`percentile`,c(),t(p[2])),name:a});switch(f){case`dc`:case`distinct_count`:return n.report(`SPL5008`,e.span),{expr:x(`countDistinctExact`,c()),name:a};case`estdc`:return{expr:x(`countDistinctApprox`,c()),name:a};case`sum`:return{expr:x(f,c()),name:a};case`min`:case`max`:return l(f,c());case`avg`:case`mean`:return{expr:x(`avg`,c()),name:a};case`range`:return{expr:g(`-`,x(`max`,c()),x(`min`,c())),name:a};case`median`:return n.report(`SPL3005`,e.span),{expr:x(`median`,c()),name:a};case`stdev`:return{expr:x(`stddev`,c()),name:a};case`stdevp`:return n.report(`SPL3005`,e.span,{detail:`stdevp() is the population deviation; DQL stddev() may use the sample formula.`}),{expr:x(`stddev`,c()),name:a};case`var`:return{expr:x(`variance`,c()),name:a};case`varp`:return n.report(`SPL3005`,e.span,{detail:`varp() is the population variance; DQL variance() may use the sample formula.`}),{expr:x(`variance`,c()),name:a};case`sumsq`:{let e=c();return{expr:x(`sum`,g(`*`,e,e)),name:a}}case`values`:return{expr:x(`arraySort`,x(`collectDistinct`,c())),name:a};case`list`:return n.report(`SPL3004`,e.span,{detail:`list() keeps event order and at most 100 values in Splunk; DQL order is not guaranteed.`}),{expr:x(`collectArray`,c()),name:a};case`first`:case`last`:case`earliest`:case`latest`:{let t=c();return(f===`earliest`||f===`latest`)&&t.k===`field`&&t.name===`timestamp`?{expr:x(f===`earliest`?`min`:`max`,t),name:a,time:!0}:(n.report(`SPL3004`,e.span),l(f===`first`||f===`earliest`?`takeFirst`:`takeLast`,t,f))}case`earliest_time`:case`latest_time`:return n.report(`SPL3006`,e.span,{detail:`${f}() returns a timestamp in DQL, not Unix seconds.`}),{expr:x(f===`earliest_time`?`min`:`max`,i(`timestamp`)),name:a,time:!0};case`per_second`:case`per_minute`:case`per_hour`:case`per_day`:return u?{expr:x(`sum`,c(),b(`rate`,o(ur[f]))),name:a}:fr(e,n,`${f}() is only translated in timechart.`);case`mode`:case`rate`:case`sparkline`:return fr(e,n,`${f}() has no DQL equivalent.`);default:return fr(e,n,`${f}() is not an aggregation the translator knows.`)}}function fr(e,t,n){t.report(`SPL2005`,e.span,{detail:n})}function pr(t,n){let r=t.some(e=>e.order===`earliest`||e.order===`latest`);if(t.some(e=>e.order!==void 0)&&n.unorderedEvents){if(r){for(let e of t)e.order===`first`&&e.expr.k===`call`&&(e.expr={...e.expr,fn:`takeLast`}),e.order===`last`&&e.expr.k===`call`&&(e.expr={...e.expr,fn:`takeFirst`});return e(`asc`)}return e(`desc`)}}function L(e,t,n,r=[],i=!1){return{name:e,aliases:r,tier:`T3`,summary:n,generating:i,lower(e){e.giveUp(t,n)}}}const mr={name:`makeresults`,tier:`T2`,summary:`data record(timestamp = now()).`,generating:!0,lower(e){let t=e.scanner();for(let e=t.option();e;e=t.option())if(e.name.toLowerCase()!==`count`||e.value!==`1`)throw new A(`SPL2003`,e.span,`makeresults ${e.name}=${e.value} cannot be translated.`);e.emit(S(`data`,x(`record`,f(`timestamp`,x(`now`))))),e.setTable([`timestamp`])}};function hr(e){let t=/^(\d+)([A-Za-z]*)$/.exec(e),n=t?Oe(t[2]||`s`):void 0;if(t&&n&&n!==`M`&&n!==`q`&&n!==`y`)return o(`${t[1]}${n}`)}const gr=/* @__PURE__ */ new Set([`summariesonly`,`allow_old_summaries`,`local`,`chunk_size`,`include_reduced_buckets`,`use_summary_index_values`]);function _r(e,t,n){let r=t.replace(/^"(.*)"$/,`$1`).trim();if(!/^[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)*$/.test(r))throw new A(`SPL1003`,n,`"${t}" is not a data model name.`);let i=r.split(`.`),a=i[0],o,s=``;for(let t=i.length;t>0&&!o;t--)s=i.slice(0,t).join(`.`),o=e.mapping.datamodels.get(s);let c=i.length===2&&i[1]===i[0],l=c?a:r;o?s!==r&&!c&&e.report(`SPL4008`,n,{subject:r,detail:`Dataset "${r}" has no entry of its own; the entry for "${s}" is used, without the dataset's own constraint.`}):e.report(`SPL4008`,n,{subject:l,detail:`Data model "${l}" has no entry in the mapping file, so all records are read and its field names are kept.`}),e.state.datamodel=o?{model:a,key:s,entry:o}:{model:a,key:l};let u={dataObject:o?.dataObject??e.mapping.defaults.dataObject,buckets:o?.buckets??[]};return o?.filter!==void 0&&(u.filter=o.filter),{source:u}}function vr(e){let t=e=>e.t===`cmp`&&e.field===`nodename`&&e.op===`=`;if(!e)return{tree:e};if(t(e))return{tree:void 0,nodename:e.value};if(e.t!==`and`)return{tree:e};let n=e.items.find(t);if(!n)return{tree:e};let r=e.items.filter(e=>e!==n);return{tree:r.length===0?void 0:r.length===1?r[0]:{...e,items:r},nodename:n.value}}const yr={name:`tstats`,tier:`T2`,summary:`Runs on events: fetch + filter + summarize. A data model is read through its mapping entry.`,generating:!0,lower(t){let n=t.tc.text,r=t.scanner(),a=!1,s;for(let e=r.option();e;e=r.option()){let t=e.name.toLowerCase();if(!gr.has(t)){if(t===`prestats`)a=/^(t|true|1)$/i.test(e.value);else if(t===`fillnull_value`)s=e.value;else throw new A(`SPL2003`,e.span,`tstats ${e.name}= cannot be translated.`)}}let c=sr(r,t),l;if(r.keyword(`from`)){let e=r.option();if(e?.name.toLowerCase()!==`datamodel`)throw new A(`SPL4008`,t.span,`tstats from a namespace or a search id reads Splunk summaries; there is no equivalent.`);l={path:e.value,span:e.span}}let u=t.argsSpan.end,p;if(r.keyword(`where`)){p=r.pos;let e=_e(n,r.pos,t.argsSpan.end,[`by`]);u=e?e.pos:t.argsSpan.end,r.pos=u}let m=[],h;if(r.keyword(`by`))for(;!r.atEnd();){let e=r.option();if(e){if(e.name.toLowerCase()===`span`&&(h=hr(e.value)),!h)throw new A(`SPL2003`,e.span,`tstats ${e.name}=${e.value} cannot be translated.`);continue}let t=r.pos;if(j(m,kn(r)),r.pos===t)break}if(!r.atEnd())throw new A(`SPL1003`,r.here(),`Unexpected text in tstats.`);let g;try{g=p===void 0?void 0:et(n,p,u)}catch(e){throw e instanceof M?new A(`SPL1001`,e.span,e.message):e}if(t.report(`SPL3014`,t.span,{detail:`tstats reads index summaries in Splunk; here it reads the events, which costs more.`}),l){let e=vr(g);g=e.tree,qe(t,g,_r(t,e.nodename??l.path,l.span).source)}else qe(t,g);if(a)return;let _=c.map(e=>dr(e,t,`table`)).filter(e=>e!==void 0);if(_.length===0)throw new A(`SPL2005`,t.span,`None of the aggregations can be translated.`);let v=[],y=[];for(let e of m){let n=t.field(e.name,e.span);n===`timestamp`?(v.push(f(`timestamp`,x(`bin`,i(`timestamp`),h??o(`1h`)))),h||t.report(`SPL3003`,t.span,{detail:`No span was given; one-hour buckets are used.`})):v.push(i(n)),y.push(n)}let w=y.filter(e=>e!==`timestamp`);w.length>0&&s!==void 0?t.emit(C(`fieldsAdd`,w.map(t=>f(t,x(`coalesce`,i(t),e(s)))))):w.length>0&&(t.emit(S(`filter`,ee(w.map(e=>x(`isNotNull`,i(e)))))),t.report(`SPL5003`,t.span));let T=_.length===1?f(_[0]?.name??`count`,_[0]?.expr):d(_.map(e=>f(e.name,e.expr)));t.emit(v.length>0?S(`summarize`,T,b(`by`,d(v))):S(`summarize`,T)),t.setTable([...y,..._.map(e=>e.name)]);for(let e of _)t.setType(e.name,e.time?`time`:ir(e)?`number`:void 0)}},br={name:`datamodel`,tier:`T2`,summary:`datamodel <model> <dataset> search → fetch through the data model's mapping entry.`,generating:!0,lower(e){let t=e.scanner(),n=[];for(;;){let e=t.option();if(e){if(!gr.has(e.name.toLowerCase())&&e.name.toLowerCase()!==`strict_fields`)throw new A(`SPL2003`,e.span,`datamodel ${e.name}= cannot be translated.`);continue}let r=t.value();if(!r)break;n.push({value:r.value,span:r.span})}let r=n[2]?.value.toLowerCase();if(n.length!==3||r!==`search`&&r!==`flat`)throw new A(`SPL4008`,e.span,`datamodel without "search" or "flat" returns the model's definition, not events.`);qe(e,void 0,_r(e,`${n[0].value}.${n[1].value}`,e.span).source)}},xr={name:`from`,tier:`T2`,summary:`from datamodel:<model>.<dataset> → fetch through the data model's mapping entry.`,generating:!0,lower(e){let t=/^datamodel(?:\s*:\s*|\s+)("?)([A-Za-z_][A-Za-z0-9_.]*)\1$/i.exec(e.slice(e.argsSpan).trim());if(!t)throw new A(`SPL4006`,e.span,`from a saved search or dataset cannot be resolved; translate that search itself.`);qe(e,void 0,_r(e,t[2],e.span).source)}},Sr=k({avg:`avg`,mean:`avg`,sum:`sum`,min:`min`,max:`max`,count:`count`}),Cr={name:`mstats`,tier:`T2`,summary:`timeseries a = avg(<metric key>), by:{…}, interval:….`,generating:!0,lower(e){let t=e.tc.text,n=e.scanner(),r=n.option();if(r)throw new A(`SPL2003`,r.span,`mstats ${r.name}= cannot be translated.`);let a=sr(n,e),o;if(n.keyword(`where`)){let r=n.pos,i=_e(t,r,e.argsSpan.end,[`by`,`span`]),a=i?i.pos:e.argsSpan.end,s;try{s=et(t,r,a)}catch(e){throw e instanceof M?new A(`SPL1001`,e.span,e.message):e}let c=(s?s.t===`and`?s.items:[s]:[]).filter(e=>e.t!==`cmp`||e.field!==`index`);e.state.schema={kind:`table`,fields:[]};let l=c.map(n=>ze(n,e,t));e.state.schema={kind:`events`,fields:[]},o=ee(l),n.pos=a}let s,c=[];for(;!n.atEnd();){let e=n.option();if(e&&e.name.toLowerCase()===`span`){if(s=hr(e.value),!s)throw new A(`SPL2003`,e.span,`span=${e.value} cannot be translated.`)}else{if(e)throw new A(`SPL2003`,e.span,`mstats ${e.name}= cannot be translated.`);if(n.keyword(`by`))c=kn(n,[`span`]);else throw new A(`SPL1003`,n.here(),`Unexpected text in mstats.`)}}let l=[],u=[];for(let t of a){let n=t.fieldArg?.name;if(!n)throw new A(`SPL1003`,t.span,`mstats aggregations need a metric name.`);let r=e.mapping.metrics.get(n);r||e.report(`SPL4007`,t.fieldArg?.span??t.span,{subject:n,detail:`Metric "${n}" has no entry in the mapping file; its name was used as the metric key.`});let a=Sr[t.fn],o=/^(?:perc|p)(\d{1,2})$/.exec(t.fn),s=t.alias??t.defaultName,c=i(r??n);if(a)l.push(f(s,x(a,c)));else if(o)l.push(f(s,x(`percentile`,c,{k:`num`,v:o[1]})));else throw new A(`SPL2005`,t.span,`mstats ${t.fn}() cannot be translated.`);u.push(s)}if(l.length===0)throw new A(`SPL1003`,e.span,`mstats needs an aggregation.`);e.report(`SPL3003`,e.span,{detail:`The result is one row per series with arrays of values.`});let p=c.map(t=>e.field(t.name,t.span)),m=[l.length===1?l[0]:d(l)];p.length>0&&m.push(b(`by`,d(p.map(i)))),o&&m.push(b(`filter`,o)),s&&m.push(b(`interval`,s)),e.emit(C(`timeseries`,m)),e.state.schema={kind:`series`,fields:[`timeframe`,`interval`,...p,...u]},e.state.series=!0}},wr=[L(`pivot`,`SPL2002`,`pivot builds a report from a data model definition; write the search with stats instead.`,[],!0),L(`iplocation`,`SPL2002`,`There is no IP geolocation function in DQL.`),L(`geostats`,`SPL2002`,`geostats has no DQL equivalent.`),L(`map`,`SPL2002`,`map runs a search per row; DQL has no equivalent.`),L(`collect`,`SPL2008`,`collect writes to an index; it was dropped.`),L(`outputlookup`,`SPL2008`,`outputlookup writes a lookup file; it was dropped.`),L(`outputcsv`,`SPL2008`,`outputcsv writes a file; it was dropped.`),L(`sendemail`,`SPL2008`,`sendemail sends e-mail; use a Dynatrace workflow instead.`),L(`sendalert`,`SPL2008`,`sendalert triggers an alert action; use a Dynatrace workflow instead.`),L(`delete`,`SPL2008`,`delete removes indexed data; it was dropped.`),L(`mcollect`,`SPL2008`,`mcollect writes metrics; it was dropped.`),L(`tscollect`,`SPL2008`,`tscollect writes summaries; it was dropped.`),L(`predict`,`SPL2002`,`Forecasting belongs to Davis analyzers, not DQL.`),L(`anomalydetection`,`SPL2002`,`Anomaly detection belongs to Davis analyzers, not DQL.`),L(`anomalies`,`SPL2002`,`Anomaly detection belongs to Davis analyzers, not DQL.`),L(`anomalousvalue`,`SPL2002`,`Anomaly detection belongs to Davis analyzers, not DQL.`),L(`outlier`,`SPL2002`,`outlier has no DQL equivalent.`),L(`cluster`,`SPL2002`,`Clustering has no DQL equivalent.`),L(`kmeans`,`SPL2002`,`Clustering has no DQL equivalent.`),L(`rest`,`SPL2002`,`rest reads the Splunk REST API; there is no equivalent.`,[],!0),L(`metadata`,`SPL2002`,`metadata reads Splunk index metadata; there is no equivalent.`,[],!0),L(`dbinspect`,`SPL2002`,`dbinspect reads Splunk buckets; there is no equivalent.`,[],!0),L(`eventcount`,`SPL2002`,`eventcount reads index sizes; there is no equivalent.`,[],!0),L(`loadjob`,`SPL2002`,`loadjob reads a Splunk job; there is no equivalent.`,[],!0),L(`savedsearch`,`SPL4006`,`Saved searches cannot be resolved; translate the saved search itself.`,[],!0),L(`script`,`SPL2002`,`Custom scripts have no DQL equivalent.`),L(`appendcols`,`SPL2010`,`appendcols pastes rows by position; DQL has no equivalent.`),L(`appendpipe`,`SPL2002`,`appendpipe has no DQL equivalent.`),L(`xyseries`,`SPL2002`,`Pivoting rows into columns has no DQL equivalent.`),L(`untable`,`SPL2002`,`Unpivoting columns into rows has no DQL equivalent.`),L(`timewrap`,`SPL2002`,`timewrap has no DQL equivalent.`),L(`addinfo`,`SPL2002`,`addinfo adds Splunk search metadata; there is no equivalent.`),L(`addcoltotals`,`SPL2002`,`Adding a totals row has no DQL equivalent.`),L(`transpose`,`SPL2002`,`transpose has no DQL equivalent.`),L(`extract`,`SPL2002`,`Search-time key=value extraction: write a parse pattern with KVP by hand.`,[`kv`]),L(`xmlkv`,`SPL2002`,`Search-time XML extraction has no DQL equivalent.`),L(`multikv`,`SPL2002`,`Table extraction has no DQL equivalent.`),L(`format`,`SPL2007`,`format builds search strings; there is no equivalent.`),L(`gentimes`,`SPL2002`,`gentimes has no DQL equivalent.`,[],!0),L(`inputcsv`,`SPL2002`,`inputcsv reads a file on the Splunk server; upload it as a lookup instead.`,[],!0),L(`localize`,`SPL2002`,`localize has no DQL equivalent.`),L(`concurrency`,`SPL2002`,`concurrency has no DQL equivalent.`),L(`associate`,`SPL2002`,`associate has no DQL equivalent.`),L(`correlate`,`SPL2002`,`correlate has no DQL equivalent.`),L(`contingency`,`SPL2002`,`contingency has no DQL equivalent.`,[`counttable`,`ctable`]),L(`arules`,`SPL2002`,`arules has no DQL equivalent.`),L(`autoregress`,`SPL2002`,`autoregress depends on row order; there is no equivalent.`),L(`filldown`,`SPL2010`,`filldown depends on row order; there is no equivalent.`),L(`makecontinuous`,`SPL2002`,`makecontinuous has no DQL equivalent.`),L(`setfields`,`SPL2002`,`setfields has no DQL equivalent.`),L(`tags`,`SPL4006`,`Tags cannot be resolved without their definitions.`),L(`typer`,`SPL4006`,`Event types cannot be resolved without their definitions.`),L(`erex`,`SPL2002`,`erex generates a regex from examples; write the pattern by hand.`),L(`scrub`,`SPL2002`,`scrub has no DQL equivalent.`),L(`xpath`,`SPL2002`,`xpath has no DQL equivalent.`),L(`sichart`,`SPL2002`,`Summary-indexing commands have no DQL equivalent.`,[`sistats`,`sitimechart`,`sitop`,`sirare`])],Tr=[mr,yr,Cr,br,xr],Er=/^\$([A-Za-z_][A-Za-z0-9_.]*)\$$/,Dr=/^(\*?)\$([A-Za-z_][A-Za-z0-9_.]*)\$(\*?)$/,Or=/* @__PURE__ */ new Set([`<`,`<=`,`>`,`>=`]);function kr(e,t){return e.get(t)??(t.startsWith(`form.`)?e.get(t.slice(5)):void 0)}function Ar(e,t,r){let i={used:/* @__PURE__ */ new Set,fieldChoosers:/* @__PURE__ */ new Set},a=e=>{if(e?.k!==`str`)return;let n=Er.exec(e.v),r=n?kr(t,n[1]):void 0;return r&&r.kind!==`time`?r:void 0},o=(e,t)=>(i.used.add(e.variable),l(e.variable,t)),s=e=>e.k===`field`&&r(e.name)===`number`,c=e=>{switch(e.k){case`str`:{let t=a(e);return t?o(t):e}case`field`:{let n=Er.exec(e.name),r=n?kr(t,n[1]):void 0;return!r||r.kind===`time`?e:(i.fieldChoosers.add(r.variable),o(r,`backtick`))}case`call`:{let[r,i]=e.args;if(e.args.length===2&&r?.kind===`pos`&&i?.kind===`pos`&&i.value.k===`str`){let l=c(r.value),u=a(i.value);if(e.fn===`matchesValue`&&u)return u.kind===`multiple`?x(`in`,l,x(`array`,o(u))):s(l)?g(`==`,l,o(u,`noquote`)):x(`matchesValue`,l,o(u));if(e.fn===`matchesPhrase`&&u)return x(`matchesPhrase`,l,o(u,`triplequote`));let d=e.fn===`matchesValue`?Dr.exec(i.value.v):null,f=d?kr(t,d[2]):void 0;if(d&&f&&f.kind!==`time`&&f.kind!==`multiple`&&(d[1]!==``||d[3]!==``))return x(d[1]!==``&&d[3]!==``?`contains`:d[1]===``?`startsWith`:`endsWith`,l,o(f),b(`caseSensitive`,n(!1)))}return{...e,args:e.args.map(e=>({...e,value:c(e.value)}))}}case`bin`:{let t=a(e.l),n=a(e.r);if(n&&!t){let t=c(e.l);return g(e.op,t,o(n,Or.has(e.op)||s(t)?`noquote`:void 0))}if(t&&!n){let n=c(e.r);return g(e.op,o(t,Or.has(e.op)||s(n)?`noquote`:void 0),n)}return{...e,l:c(e.l),r:c(e.r)}}case`un`:return{...e,e:c(e.e)};case`block`:return{...e,items:e.items.map(c)};case`assign`:case`dir`:case`index`:case`align`:return{...e,e:c(e.e)};case`sub`:return{...e,q:{commands:e.q.commands.map(u)}};case`var`:return i.used.add(e.name),e;default:return e}},u=e=>e.name===`//`?e:{...e,args:e.args.map(e=>({...e,value:c(e.value)}))};for(let t=0;t<e.length;t++)e[t]=u(e[t]);return i}function jr(e){return[...new Set([...e.matchAll(/\$[A-Za-z_][A-Za-z0-9_.]*(?:\|[A-Za-z]+)?\$/g)].map(e=>e[0]))]}const Mr={name:`sort`,tier:`T1`,summary:`sort a asc, b desc; a count becomes a limit.`,lower(e){let n=e.scanner(),r=n.integer()?.value,a=n.option();if(a){if(a.name.toLowerCase()===`limit`&&/^\d+$/.test(a.value))r=Number(a.value);else throw new A(`SPL2003`,a.span,`sort ${a.name}= is not supported.`)}let o=[],s=!1;for(;!n.atEnd();){if(n.eat(`,`))continue;if(n.keyword(`desc`)||n.keyword(`d`)){s=!0;continue}let t=!1;n.eat(`-`)?t=!0:n.eat(`+`);let r=/^(num|str|ip|auto)\s*\(/i.exec(e.tc.text.slice(n.pos,n.pos+8));if(r){let a=r[1].toLowerCase();n.pos+=r[0].length-1;let s=n.balanced(`(`,`)`);if(!s)throw new A(`SPL1003`,n.here(),`${a}( is not closed.`);let c=e.slice(s.inner).trim(),l=i(e.field(c,s.inner)),u=a===`num`?x(`toDouble`,l):a===`str`?x(`toString`,l):a===`ip`?x(`toIp`,l):l;o.push({expr:u,desc:t});continue}let a=n.fieldName();if(!a)throw new A(`SPL1003`,n.here(),`Expected a field to sort by.`);let c=e.field(a.value,a.span);e.fieldType(c)===void 0&&e.state.schema.kind===`events`&&c!==`timestamp`&&e.report(`SPL3006`,a.span,{subject:`type:${c}`,detail:`"${a.value}" has no declared type; DQL sorts by the stored type, Splunk decides per value.`}),o.push({expr:i(c),desc:t,name:c})}if(o.length===0)throw new A(`SPL1003`,e.span,`sort needs a field.`);let c=o.map(e=>p(e.expr,e.desc===s?`asc`:`desc`));e.emit(C(`sort`,c)),r!==void 0&&r>0?e.emit(S(`limit`,t(r))):r===void 0&&e.report(`SPL5006`,e.span,{detail:`Splunk sort returns at most 10,000 rows by default; DQL has no such limit here.`}),e.state.sorted=!0,e.state.lastSort=c,e.state.lastWasSort=!0}};function Nr(e){return e.map(e=>e.k===`dir`?p(e.e,e.dir===`asc`?`desc`:`asc`):e)}function Pr(e){e.unorderedEvents&&(e.emit(S(`sort`,p(i(`timestamp`),`desc`))),e.report(`SPL5004`,e.span),e.state.sorted=!0)}const Fr=[Mr,{name:`head`,tier:`T1`,summary:`limit N (default 10); on raw events sorted newest first, as in Splunk.`,lower(e){let n=/^\s*\$([A-Za-z_][A-Za-z0-9_.]*)\$\s*$/.exec(e.slice(e.argsSpan)),r=n&&e.tc.options.tokens?kr(e.tc.options.tokens,n[1]):void 0;if(r&&r.kind!==`time`){Pr(e),e.emit(S(`limit`,l(r.variable,`noquote`)));return}let i=e.scanner(),a=i.integer()?.value,o=i.option();if(o){if(o.name.toLowerCase()===`limit`&&/^\d+$/.test(o.value))a=Number(o.value);else throw new A(`SPL2003`,o.span,`head ${o.name}= cannot be translated.`)}if(!i.atEnd())throw new A(`SPL2003`,e.span,`head with an expression cannot be translated.`);Pr(e),e.emit(S(`limit`,t(a??10)))}},{name:`tail`,tier:`T2`,summary:`sort timestamp asc, limit N — on raw events only.`,lower(e){let n=e.scanner().integer()?.value??10;if(e.prevWasSort&&e.state.lastSort){let r=Nr(e.state.lastSort);e.emit(C(`sort`,r)),e.emit(S(`limit`,t(n))),e.state.sorted=!0,e.state.lastSort=r,e.state.lastWasSort=!0}else{if(e.state.schema.kind!==`events`)throw new A(`SPL2010`,e.span,`tail after a transforming command depends on row order.`);e.report(`SPL3004`,e.span,{detail:`tail returns the oldest events here; Splunk returns the last events of its own order.`}),e.emit(S(`sort`,p(i(`timestamp`),`asc`))),e.emit(S(`limit`,t(n))),e.state.sorted=!0}}},{name:`reverse`,tier:`T2`,summary:`After sort: the opposite sort. On raw events: oldest first.`,lower(e){if(e.prevWasSort&&e.state.lastSort){let t=Nr(e.state.lastSort);e.emit(C(`sort`,t)),e.state.sorted=!0,e.state.lastSort=t,e.state.lastWasSort=!0}else if(e.state.schema.kind===`events`){e.report(`SPL3004`,e.span,{detail:`reverse is translated as "oldest first".`});let t=[p(i(`timestamp`),`asc`)];e.emit(C(`sort`,t)),e.state.sorted=!0,e.state.lastSort=t,e.state.lastWasSort=!0}else throw new A(`SPL2010`,e.span,`reverse here depends on row order.`)}},{name:`dedup`,tier:`T1`,summary:`dedup f, sort:{timestamp desc}; rows where f is empty are removed first, as in Splunk.`,lower(e){let t=e.scanner();if(t.integer())throw new A(`SPL2003`,e.span,`dedup keeping more than one row per value cannot be translated.`);let n=!1,r=[],a=[],o;for(;!t.atEnd();){let n=t.option();if(n){r.push(n);continue}if(t.keyword(`sortby`)){for(o=[];!t.atEnd();){if(t.eat(`,`))continue;let n=!1;t.eat(`-`)?n=!0:t.eat(`+`);let r=t.fieldName();if(!r)break;o.push(p(i(e.field(r.value,r.span)),n?`desc`:`asc`))}continue}if(t.eat(`,`))continue;let s=t.fieldName();if(!s)throw new A(`SPL1003`,t.here(),`Expected a field.`);a.push({name:s.value,span:s.span})}for(let e of r){let t=e.name.toLowerCase(),r=/^(t|true|1)$/i.test(e.value);if(t===`keepempty`)n=r;else if((t===`consecutive`||t===`keepevents`)&&r)throw new A(`SPL2003`,e.span,`dedup ${t}=true cannot be translated.`);else if(t!==`consecutive`&&t!==`keepevents`)throw new A(`SPL2003`,e.span,`dedup ${e.name}= cannot be translated.`)}if(a.length===0)throw new A(`SPL1003`,e.span,`dedup needs a field.`);let s=a.map(t=>{if(t.name.includes(`*`))throw new A(`SPL2009`,t.span,`dedup by a wildcard needs the list of fields.`);return e.field(t.name,t.span)});n?e.report(`SPL3002`,e.span,{detail:`With keepempty=true Splunk keeps every event with an empty field; DQL keeps one.`}):e.emit(S(`filter`,ee(s.map(e=>x(`isNotNull`,i(e))))));let c=s.map(i);o&&o.length>0?c.push(b(`sort`,d(o))):e.state.schema.kind===`events`&&!e.state.sorted?c.push(b(`sort`,d([p(i(`timestamp`),`desc`)]))):e.state.schema.kind!==`events`&&e.report(`SPL3004`,e.span,{detail:`Which row is kept per value is not guaranteed after a transforming command.`}),e.emit(C(`dedup`,c))}},{name:`uniq`,tier:`T2`,summary:`dedup on all known fields.`,lower(e){if(e.state.schema.kind===`events`||e.state.schema.fields.length===0)throw new A(`SPL2009`,e.span,`uniq needs to know all fields; use it after table or stats.`);e.emit(C(`dedup`,e.state.schema.fields.map(i)))}}];function R(e){let t=[];for(let n=e.option();n;n=e.option())t.push({name:n.name.toLowerCase(),value:n.value,span:n.span});return t}function Ir(e,t,n){let r=[];for(let i of e)try{let e=dr(i,t,n);e&&r.push(e)}catch(e){if(!(e instanceof A))throw e;t.report(e.code,e.span,{detail:`${e.message} This aggregation was left out.`})}if(r.length===0)throw new A(`SPL2005`,t.span,`None of the aggregations can be translated.`);return r}function Lr(e,t){for(let n of t)e.setType(n.name,n.time?`time`:ir(n)?`number`:void 0)}function Rr(e){let t=e.map(e=>f(e.name,e.expr));return t.length===1?t[0]:d(t)}function zr(e,t){return t.map(t=>{if(t.name.includes(`*`))throw new A(`SPL2009`,t.span,`Grouping by a wildcard needs the list of fields.`);return e.field(t.name,t.span)})}function Br(e,t){let n=pr(t,e);n&&n.k===`str`&&(e.emit(S(`sort`,p(i(`timestamp`),n.v))),e.report(`SPL5004`,e.span))}function Vr(e,t){t.length!==0&&(e.emit(S(`filter`,ee(t.map(e=>x(`isNotNull`,i(e)))))),e.report(`SPL5003`,e.span))}const Hr={name:`stats`,tier:`T1`,summary:`summarize {…}, by:{…}; rows with an empty group are removed first, as in Splunk.`,lower(e){let t=e.scanner();for(let n of R(t))e.report(`SPL2003`,n.span,{detail:`stats ${n.name}= has no DQL equivalent and was ignored.`});let n=sr(t,e),r=t.keyword(`by`)?kn(t):[];if(!t.atEnd())throw new A(`SPL1003`,t.here(),`Unexpected text after the BY clause.`);if(n.length===0)throw new A(`SPL1003`,e.span,`stats needs at least one aggregation.`);let a=Ir(n,e,`table`),o=zr(e,r);Br(e,a),Vr(e,o);let s=[Rr(a)];e.emit(o.length>0?S(`summarize`,...s,b(`by`,d(o.map(i)))):C(`summarize`,s)),e.setTable([...o,...a.map(e=>e.name)]),Lr(e,a)}},Ur={name:`chart`,tier:`T1`,summary:`summarize by the over/by fields; two group fields give long rows instead of columns.`,lower(e){let n=e.scanner(),r=R(n),a=sr(n,e),o,s=[],c;if(n.keyword(`over`)){let e=n.fieldName();if(!e)throw new A(`SPL1003`,n.here(),`Expected a field after OVER.`);o={name:e.value,span:e.span},j(r,R(n))}if(n.keyword(`by`)&&(s=kn(n),j(r,R(n))),!n.atEnd())throw new A(`SPL1003`,n.here(),`Unexpected text in chart.`);if(!o&&s.length>0&&(o=s.shift()),s.length>1)throw new A(`SPL2003`,e.span,`chart with more than two group fields has no equivalent.`);let l=Ir(a,e,`table`),u=[],p=[];if(o){let n=e.field(o.name,o.span);for(let e of r)if(e.name===`span`||e.name===`bins`){let r=/^\d+(\.\d+)?$/.test(e.value)?t(e.value):void 0;if(!r)throw new A(`SPL2003`,e.span,`chart ${e.name}=${e.value} cannot be translated.`);c=f(n,x(`bin`,i(n),r))}u.push(c??i(n)),p.push(n)}for(let t of s){let n=e.field(t.name,t.span);u.push(i(n)),p.push(n)}for(let t of r)t.name!==`span`&&t.name!==`bins`&&([`limit`,`useother`,`usenull`,`nullstr`,`otherstr`].includes(t.name)?e.report(`SPL3009`,t.span,{detail:`chart ${t.name}= is not reproduced.`}):e.report(`SPL2003`,t.span,{detail:`chart ${t.name}= has no DQL equivalent and was ignored.`}));s.length>0&&(e.report(`SPL3003`,e.span,{detail:`chart over … by … gives one row per pair in DQL instead of one column per value.`}),e.report(`SPL3009`,e.span,{detail:`Splunk keeps the top 10 series and groups the rest as OTHER; DQL keeps all.`})),Br(e,l),e.emit(u.length>0?S(`summarize`,Rr(l),b(`by`,d(u))):S(`summarize`,Rr(l))),e.setTable([...p,...l.map(e=>e.name)]),Lr(e,l)}},Wr=/* @__PURE__ */ new Set([`streamstats`,`accum`,`delta`,`trendline`,`fieldformat`,`highlight`,`iconify`]),Gr={name:`timechart`,tier:`T2`,summary:`makeTimeseries (series) or summarize by bin(timestamp, span) (tabular).`,lower(e){let n=e.scanner(),r=R(n),a=sr(n,e),s;if(n.keyword(`by`)){let t=n.fieldName();if(!t)throw new A(`SPL1003`,n.here(),`Expected a field after BY.`);s={name:t.value,span:t.span},j(r,R(n)),n.keyword(`where`)&&(e.report(`SPL2003`,e.span,{detail:`The WHERE clause of timechart (top series) is not reproduced.`}),n.rest())}if(!n.atEnd())throw new A(`SPL1003`,n.here(),`Unexpected text in timechart.`);if(a.length===0)throw new A(`SPL1003`,e.span,`timechart needs an aggregation.`);let c,l,u;for(let n of r)if(n.name===`span`){let e=/^(\d+)([A-Za-z]*)$/.exec(n.value),t=e?Oe(e[2]||`s`):void 0;if(!e||!t)throw new A(`SPL2003`,n.span,`span=${n.value} cannot be translated.`);if(t===`M`||t===`q`||t===`y`){if(e[1]!==`1`)throw new A(`SPL2003`,n.span,`span=${n.value} cannot be translated; only 1mon, 1q and 1y are.`);l=t}else c=o(`${e[1]}${t}`)}else n.name===`bins`&&/^\d+$/.test(n.value)?u=t(n.value):[`limit`,`useother`,`usenull`,`nullstr`,`otherstr`].includes(n.name)||e.report(`SPL2003`,n.span,{detail:`timechart ${n.name}= has no DQL equivalent and was ignored.`});let p=e.following.every(e=>Wr.has(e)),m=!l&&p&&a.every(lr),h=Ir(a,e,m?`series`:`table`),g=s?e.field(s.name,s.span):void 0;if(e.report(`SPL3003`,e.span,{detail:m?`timechart gives one row per series with arrays of values in DQL.`:`timechart gives one row per time bucket and series in DQL; empty buckets have no row.`}),g&&e.report(`SPL3009`,e.span,{detail:`Splunk keeps the top 10 series and groups the rest as OTHER; DQL keeps all.`}),m){let t=[Rr(h)];g&&t.push(b(`by`,d([i(g)]))),c&&t.push(b(`interval`,c)),u&&t.push(b(`bins`,u)),e.emit(C(`makeTimeseries`,t)),e.state.schema={kind:`series`,fields:[`timeframe`,`interval`,...g?[g]:[],...h.map(e=>e.name)]},e.state.series=!0,e.state.sorted=!0;return}Lr(e,h);let _;l?_=f(`timestamp`,v(i(`timestamp`),l)):(c||=(e.report(`SPL3003`,e.span,{detail:`No span was given; one-hour buckets are used.`}),o(`1h`)),_=f(`timestamp`,x(`bin`,i(`timestamp`),c)));let y=[_,...g?[i(g)]:[]];Br(e,h),e.emit(S(`summarize`,Rr(h),b(`by`,d(y)))),e.setTable([`timestamp`,...g?[g]:[],...h.map(e=>e.name)])}};function Kr(e){return{name:e,tier:`T1`,summary:e===`top`?`Count by field, add percent, sort descending, limit.`:`Count by field, add percent, sort ascending, limit.`,lower(n){let r=n.scanner(),a=r.integer()?.value??10,o=`count`,s=`percent`,c=!0,l=!0,u=e=>/^(t|true|1)$/i.test(e),m=[],h=[],v=!1;for(;!r.atEnd();){let t=r.option();if(t){let r=t.name.toLowerCase();r===`limit`&&/^\d+$/.test(t.value)?a=Number(t.value):r===`countfield`?o=t.value:r===`percentfield`?s=t.value:r===`showcount`?c=u(t.value):r===`showperc`?l=u(t.value):n.report(`SPL2003`,t.span,{detail:`${e} ${t.name}= is not reproduced.`});continue}if(r.keyword(`by`)){v=!0;continue}if(r.eat(`,`))continue;let i=r.fieldName();if(!i)throw new A(`SPL1003`,r.here(),`Unexpected text in ${e}.`);(v?h:m).push({name:i.value,span:i.span})}if(m.length===0)throw new A(`SPL1003`,n.span,`${e} needs a field.`);let y=zr(n,m),C=zr(n,h),w=e===`top`?`desc`:`asc`,T=n.field(o,n.span,!0);if(n.setType(T,`number`),Vr(n,y),C.length>0)n.report(`SPL3014`,n.span,{detail:`${e} … by … sorts within each group but does not limit per group or add percentages.`}),n.emit(S(`summarize`,f(T,x(`count`)),b(`by`,d([...C,...y].map(i))))),n.emit(S(`sort`,...C.map(e=>p(i(e),`asc`)),p(i(T),w))),n.setTable([...C,...y,T]);else{if(n.emit(S(`summarize`,f(T,x(`count`)),b(`by`,d(y.map(i))))),l){let e=n.field(s,n.span,!0);n.setType(e,`number`),n.emit(S(`summarize`,d([f(`_r`,x(`collectArray`,x(`record`,...y.map(i),i(T)))),f(`_total`,x(`sum`,i(T)))]))),n.emit(S(`expand`,i(`_r`))),n.emit(S(`fields`,...y.map(e=>f(e,_(i(`_r`),e))),f(T,_(i(`_r`),T)),f(e,g(`/`,g(`*`,t(`100.0`),_(i(`_r`),T)),i(`_total`))))),n.setTable([...y,T,e])}else n.setTable([...y,T]);n.emit(S(`sort`,p(i(T),w))),a>0&&n.emit(S(`limit`,t(a))),c||(n.emit(S(`fieldsRemove`,i(T))),n.setTable(n.state.schema.fields.filter(e=>e!==T))),n.state.sorted=!0}}}}const qr=Kr(`top`),Jr=Kr(`rare`),Yr={name:`eventstats`,tier:`T2`,summary:`Aggregates added to every row: collect-and-expand when the fields are known, otherwise a self-join.`,lower(e){let n=e.scanner();for(let t of R(n))e.report(`SPL2003`,t.span,{detail:`eventstats ${t.name}= was ignored.`});let r=sr(n,e),o=n.keyword(`by`)?kn(n):[];if(!n.atEnd())throw new A(`SPL1003`,n.here(),`Unexpected text after the BY clause.`);let s=Ir(r,e,`table`),c=zr(e,o),l=s.map(e=>e.name);for(let t of l)e.field(t,e.span,!0);if(Lr(e,s),e.state.schema.kind===`table`){let t=e.state.schema.fields.filter(e=>!c.includes(e)&&!l.includes(e)),n=d([f(`_rows`,x(`collectArray`,w(`record`,t.map(i)))),...s.map(e=>f(e.name,e.expr))]);e.emit(c.length>0?S(`summarize`,n,b(`by`,d(c.map(i)))):S(`summarize`,n)),e.emit(S(`expand`,i(`_rows`))),e.emit(S(`fields`,...c.map(i),...t.map(e=>f(e,_(i(`_rows`),e))),...l.map(i))),e.setTable([...c,...t,...l]);return}e.report(`SPL3012`,e.span);let p=e.upstream.filter(e=>e.name!==`//`).map(ne),m=c.length===0,h=m?[`_k`]:c;m&&(e.emit(S(`fieldsAdd`,f(`_k`,t(1)))),p.push({...S(`fieldsAdd`,f(`_k`,t(1))),origin:[e.index]})),p.push({...S(`summarize`,Rr(s),b(`by`,d(h.map(i)))),origin:[e.index]}),e.emit(S(`join`,u(p),b(`on`,d(h.map(i))),b(`kind`,a(`leftOuter`)),b(`fields`,d(l.map(i))))),m&&e.emit(S(`fieldsRemove`,i(`_k`)))}};function Xr(e,t){if(!e.prevSeries)throw new A(`SPL2010`,e.span,`${t} depends on the order of rows; it is only translated right after a timechart.`)}const Zr=k({sum:`arrayMovingSum`,avg:`arrayMovingAvg`,min:`arrayMovingMin`,max:`arrayMovingMax`}),Qr=[Hr,Ur,Gr,qr,Jr,Yr,{name:`streamstats`,tier:`T3`,summary:`Not translated, except cumulative/windowed sums and averages right after timechart (array functions).`,lower(e){Xr(e,`streamstats`);let n=e.scanner(),r;for(let e of R(n))if(e.name===`window`&&/^\d+$/.test(e.value))r=Number(e.value);else throw new A(`SPL2010`,e.span,`streamstats ${e.name}= cannot be translated.`);let a=sr(n,e);if(!n.atEnd())throw new A(`SPL2010`,n.here(),`streamstats … by … cannot be translated.`);let o=[];for(let n of a){if(!n.fieldArg)throw new A(`SPL2010`,n.span,`streamstats ${n.fn} cannot be translated.`);let a=i(e.field(n.fieldArg.name,n.fieldArg.span)),s=n.alias??n.defaultName,c;if(c=r===void 0||r===0?n.fn===`sum`?`arrayCumulativeSum`:void 0:Zr[n.fn],!c)throw new A(`SPL2010`,n.span,`streamstats ${n.fn}() ${r?`with a window`:`without a window`} cannot be translated.`);o.push(f(e.field(s,n.span,!0),r?x(c,a,t(r)):x(c,a)))}e.emit(C(`fieldsAdd`,o)),e.state.series=!0}},{name:`accum`,tier:`T2`,summary:`arrayCumulativeSum right after timechart.`,lower(e){Xr(e,`accum`);let t=e.scanner(),n=t.fieldName();if(!n)throw new A(`SPL1003`,e.span,`accum needs a field.`);let r=t.keyword(`as`)?t.fieldName()?.value??n.value:n.value;e.emit(S(`fieldsAdd`,f(e.field(r,n.span,!0),x(`arrayCumulativeSum`,i(e.field(n.value,n.span)))))),e.state.series=!0}},{name:`delta`,tier:`T2`,summary:`arrayDelta right after timechart.`,lower(e){Xr(e,`delta`);let t=e.scanner(),n=t.fieldName();if(!n)throw new A(`SPL1003`,e.span,`delta needs a field.`);let r=t.keyword(`as`)?t.fieldName()?.value??`delta(${n.value})`:`delta(${n.value})`,a=t.option();if(a&&(a.name!==`p`||a.value!==`1`))throw new A(`SPL2003`,a.span,`delta with p other than 1 cannot be translated.`);e.emit(S(`fieldsAdd`,f(e.field(r,n.span,!0),x(`arrayDelta`,i(e.field(n.value,n.span)))))),e.state.series=!0}},{name:`trendline`,tier:`T2`,summary:`smaN → arrayMovingAvg right after timechart.`,lower(e){Xr(e,`trendline`);let n=e.scanner(),r=[];for(;!n.atEnd();){let a=n.word(`(`),o=n.balanced(`(`,`)`),s=a?/^sma(\d{1,4})$/i.exec(a.value):null;if(!a||!o||!s)throw new A(`SPL2003`,a?.span??e.span,`Only smaN(field) trendlines can be translated.`);let c=e.slice(o.inner).trim(),l=n.keyword(`as`)?n.fieldName()?.value??`${a.value}(${c})`:`${a.value}(${c})`;r.push(f(e.field(l,a.span,!0),x(`arrayMovingAvg`,i(e.field(c,o.inner)),t(s[1]))))}e.emit(C(`fieldsAdd`,r)),e.state.series=!0}},{name:`transaction`,tier:`T2`,summary:`summarize start/end/eventcount/content by the fields; any option → not translated.`,lower(e){let t=e.scanner(),n=[];for(;!t.atEnd();){if(t.option())throw new A(`SPL2002`,e.span,`transaction with options has no DQL equivalent.`);if(t.eat(`,`))continue;let r=t.fieldName();if(!r)throw new A(`SPL2002`,e.span,`transaction with options has no DQL equivalent.`);n.push({name:r.value,span:r.span})}if(n.length===0)throw new A(`SPL2002`,e.span,`transaction without fields has no DQL equivalent.`);let r=zr(e,n);e.report(`SPL3014`,e.span,{detail:`transaction is approximated by grouping on the fields; time gaps and start/end markers are ignored.`});let a=e.field(`_raw`,e.span);e.emit(S(`summarize`,d([f(`_start`,x(`min`,i(`timestamp`))),f(`_end`,x(`max`,i(`timestamp`))),f(`eventcount`,x(`count`)),f(a,x(`collectArray`,i(a)))]),b(`by`,d(r.map(i))))),e.emit(S(`fieldsAdd`,f(`duration`,g(`/`,g(`-`,i(`_end`),i(`_start`)),o(`1s`))),f(`timestamp`,i(`_start`)))),e.setTable([...r,`_start`,`_end`,`eventcount`,a,`duration`,`timestamp`]),e.setType(`eventcount`,`number`),e.setType(`duration`,`number`)}},{name:`bin`,aliases:[`bucket`],tier:`T1`,summary:`fieldsAdd f = bin(f, span); calendar spans use @M/@q/@y.`,lower(e){let n=e.scanner(),r=R(n),a=n.fieldName();if(!a)throw new A(`SPL1003`,e.span,`bin needs a field.`);j(r,R(n));let s=a.value;n.keyword(`as`)&&(s=n.fieldName()?.value??s),j(r,R(n));let c=e.field(a.value,a.span),l=c===`timestamp`||e.fieldType(c)===`time`,u=e.field(s,a.span,!0),d;for(let t of r)if(t.name===`span`)d=t;else if(t.name===`aligntime`)e.report(`SPL2003`,t.span,{detail:`aligntime= was ignored.`});else throw new A(`SPL2003`,t.span,`bin ${t.name}= cannot be translated; use span=.`);if(!d)throw new A(`SPL2003`,e.span,`bin without span= cannot be translated.`);if(l){let t=/^(\d+)([A-Za-z]*)$/.exec(d.value),n=t?Oe(t[2]||`s`):void 0;if(!t||!n)throw new A(`SPL2003`,d.span,`span=${d.value} cannot be translated.`);if(n===`M`||n===`q`||n===`y`){if(t[1]!==`1`)throw new A(`SPL2003`,d.span,`span=${d.value} cannot be translated.`);e.emit(S(`fieldsAdd`,f(u,v(i(c),n))))}else e.emit(S(`fieldsAdd`,f(u,x(`bin`,i(c),o(`${t[1]}${n}`)))))}else{if(!/^\d+(\.\d+)?$/.test(d.value))throw new A(`SPL2003`,d.span,`span=${d.value} cannot be translated for a number field.`);e.emit(S(`fieldsAdd`,f(u,x(`bin`,i(c),t(d.value)))))}e.addFields([u])}}],$r=[Wn,Gn,Kn,Xn,Qn,$n,er,tr,nr,...Vn,...Qr,...Fr,...Sn,...ht,...Tr,...wr],ei=(()=>{let e=/* @__PURE__ */ new Map;for(let t of $r)for(let n of[t.name,...t.aliases??[]]){if(e.has(n))throw Error(`Duplicate command ${n}`);e.set(n,t)}return e})();function ti(e){return ei.get(e.toLowerCase())}const ni=Object.freeze(Object.assign(Object.create(null),{append:[],data:[`json`],dedup:[`direction`,`filterPushThrough`,`limit`,`sort`],describe:[],expand:[`limit`],fetch:[`bucket`,`from`,`samplingRatio`,`scanLimitGBytes`,`timeframe`,`to`],fields:[],fieldsAdd:[],fieldsFlatten:[`depth`,`fields`,`prefix`],fieldsKeep:[],fieldsRemove:[],fieldsRename:[],fieldsSnapshot:[`bucket`,`by`],fieldsSummary:[`extrapolateSamples`,`topValues`],filter:[],filterOut:[],join:[`broadcast`,`executionOrder`,`fields`,`kind`,`on`,`prefix`],joinNested:[`broadcast`,`executionOrder`,`fields`,`on`],limit:[],load:[`offset`],lookup:[`broadcast`,`executionOrder`,`fields`,`lookupField`,`prefix`,`sourceField`],makeTimeseries:[`bins`,`by`,`default`,`from`,`interval`,`nonempty`,`rate`,`spread`,`time`,`timeframe`,`to`],metrics:[`bucket`,`from`,`timeframe`,`to`],parse:[`baseTime`,`parsingPrerequisite`,`preserveFieldsOnFailure`],search:[`caseSensitive`,`scope`],smartscapeEdges:[`from`,`timeframe`,`to`],smartscapeNodes:[`from`,`timeframe`,`to`],sort:[`direction`],summarize:[`by`],timeseries:[`bins`,`bucket`,`by`,`default`,`filter`,`from`,`interval`,`nonempty`,`rate`,`rollup`,`shift`,`timeframe`,`to`,`union`],traverse:[`direction`,`fieldsKeep`,`nodeId`]})),ri=Object.freeze(Object.assign(Object.create(null),{abs:[],acos:[],array:[],arrayAvg:[],arrayConcat:[],arrayCumulativeSum:[],arrayDelta:[],arrayDiff:[],arrayDistinct:[],arrayElement:[],arrayFirst:[],arrayFlatten:[],arrayIndexOf:[],arrayLast:[],arrayLastIndexOf:[],arrayMax:[],arrayMedian:[],arrayMin:[],arrayMovingAvg:[],arrayMovingMax:[],arrayMovingMin:[],arrayMovingSum:[],arrayPercentile:[],arrayRemoveNulls:[],arrayReverse:[],arraySize:[],arraySlice:[`from`,`to`],arraySort:[`direction`],arraySum:[],arrayToString:[`delimiter`],asArray:[],asBinary:[],asBoolean:[],asDouble:[],asDuration:[],asIp:[],asLong:[],asNumber:[],asRecord:[],asSmartscapeId:[],asString:[],asTimeframe:[],asTimestamp:[],asUid:[],asin:[],atan:[],atan2:[],avg:[`default`,`filter`,`rate`,`rollup`,`scalar`],bin:[`at`],bitwiseAnd:[],bitwiseCountOnes:[],bitwiseNot:[],bitwiseOr:[],bitwiseShiftLeft:[],bitwiseShiftRight:[`ignoreSign`],bitwiseXor:[],cbrt:[],ceil:[],classicEntitySelector:[],coalesce:[],collectArray:[`expand`,`maxLength`],collectDistinct:[`expand`,`maxLength`],concat:[`delimiter`],contains:[`caseSensitive`],correlation:[],cos:[],cosh:[],count:[`default`,`filter`,`rate`,`scalar`],countDistinct:[`default`,`filter`,`precision`,`rate`,`scalar`],countDistinctApprox:[`default`,`precision`,`rate`,`scalar`],countDistinctExact:[`default`,`rate`,`scalar`],countIf:[`default`,`rate`,`scalar`],decodeBase16ToBinary:[],decodeBase16ToString:[],decodeBase64ToBinary:[],decodeBase64ToString:[],decodeUrl:[],degreeToRadian:[],duration:[],e:[],encodeBase16:[],encodeBase64:[],encodeUrl:[],end:[],endsWith:[`caseSensitive`],entityAttr:[`type`],entityName:[`type`],escape:[],exists:[],exp:[],floor:[],formatTimestamp:[`format`,`interval`,`locale`,`timezone`],getCharacter:[],getDayOfMonth:[`timezone`],getDayOfWeek:[`timezone`],getDayOfYear:[`timezone`],getEnd:[],getHighBits:[],getHour:[`timezone`],getLowBits:[],getMinute:[`timezone`],getMonth:[`timezone`],getNodeField:[],getNodeName:[],getSecond:[`timezone`],getStart:[],getWeekOfYear:[`timezone`],getYear:[`timezone`],hashCrc32:[],hashMd5:[],hashSha1:[],hashSha256:[],hashSha512:[],hashXxHash32:[],hashXxHash64:[],hexStringToNumber:[],hypotenuse:[],iAny:[],iCollectArray:[],iIndex:[],if:[`else`],in:[],indexOf:[`from`],ip:[],ipIn:[],ipIsLinkLocal:[],ipIsLoopback:[],ipIsPrivate:[],ipIsPublic:[],ipMask:[`ipv6MaskBits`],isFalseOrNull:[],isIp:[],isIpV4:[],isIpV6:[],isNotNull:[],isNull:[],isTrueOrNull:[],isUid128:[],isUid64:[],isUuid:[],jsonField:[`seek`],jsonPath:[`seek`],lastIndexOf:[`from`],levenshteinDistance:[],like:[],log:[],log10:[],log1p:[],lookup:[`broadcast`,`executionOrder`,`lookupField`,`sourceField`],lower:[],matchesPattern:[],matchesPhrase:[`caseSensitive`,`wildcard`],matchesRegex:[],matchesValue:[`caseSensitive`,`wildcard`],max:[`default`,`filter`,`rate`,`rollup`,`scalar`],median:[`default`,`filter`,`rate`,`rollup`,`scalar`,`weight`],min:[`default`,`filter`,`rate`,`rollup`,`scalar`],now:[],numberToHexString:[`minLength`],parse:[`baseTime`],parseAll:[`baseTime`],percentRank:[`default`,`filter`,`rate`,`rollup`,`scalar`],percentile:[`default`,`filter`,`rate`,`rollup`,`scalar`,`weight`],percentileFromSamples:[`default`,`originalCount`,`rate`,`scalar`],percentiles:[`weight`],pi:[],power:[],punctuation:[`count`,`withSpace`],radianToDegree:[],random:[],range:[`at`],record:[],replacePattern:[],replaceString:[],round:[`decimals`],signum:[],sin:[],sinh:[],smartscapeId:[],splitByPattern:[],splitString:[],sqrt:[],start:[],startsWith:[`caseSensitive`],stddev:[],stringLength:[],substring:[`from`,`to`],sum:[`default`,`filter`,`rate`,`rollup`,`scalar`],takeAny:[],takeFirst:[],takeLast:[],takeMax:[],takeMin:[],tan:[],tanh:[],timeframe:[`to`],timestamp:[`micros`,`millis`,`nanos`,`timezone`],timestampFromUnixMillis:[],timestampFromUnixNanos:[],timestampFromUnixSeconds:[],toArray:[],toBoolean:[],toDouble:[],toDuration:[],toIp:[],toLong:[],toSmartscapeId:[],toString:[],toTimeframe:[],toTimestamp:[],toUid:[],toVariant:[],trim:[],type:[`withSubtype`],uid128:[],uid64:[],unescape:[],unescapeHtml:[],unixMillisFromTimestamp:[],unixNanosFromTimestamp:[],unixSecondsFromTimestamp:[],upper:[],uuid:[],variance:[],vectorCosineDistance:[],vectorInnerProductDistance:[],vectorL1Distance:[],vectorL2Distance:[]})),ii=[`ns`,`us`,`ms`,`s`,`m`,`h`,`d`,`w`,`M`,`q`,`y`],ai=/* @__PURE__ */ new Set([`==`,`!=`,`<=`,`>=`]),oi=/* @__PURE__ */ new Set([`|`,`,`,`:`,`(`,`)`,`{`,`}`,`[`,`]`,`=`,`<`,`>`,`+`,`-`,`*`,`/`,`%`,`.`]);function si(e){let t=[],n=e.length,r=0,i=(n,r,i)=>{t.push({type:n,text:e.slice(r,i),span:{start:r,end:i}})};for(;r<n;){let t=e.charCodeAt(r),a=e[r];if(a===` `||a===` `||a===`
4
4
  `||a===`\r`){r++;continue}let o=r;if(a===`/`&&e[r+1]===`/`){for(;r<n&&e[r]!==`
5
5
  `;)r++;i(`comment`,o,r);continue}if(a===`"`){if(e.startsWith(`"""`,r)){let t=e.indexOf(`"""`,r+3);r=t===-1?n:t+3,i(t===-1?`error`:`string`,o,r);continue}r=ci(e,r,`"`),i(r<0?`error`:`string`,o,r<0?n:r),r<0&&(r=n);continue}if(a===`'`){r=ci(e,r,`'`),i(r<0?`error`:`string`,o,r<0?n:r),r<0&&(r=n);continue}if(a==="`"){r=ci(e,r,"`"),i(r<0?`error`:`backtick`,o,r<0?n:r),r<0&&(r=n);continue}if(t>=48&&t<=57){for(;r<n&&li(e.charCodeAt(r));)r++;if(e[r]===`.`&&li(e.charCodeAt(r+1)))for(r++;r<n&&li(e.charCodeAt(r));)r++;if((e[r]===`e`||e[r]===`E`)&&/[0-9+-]/.test(e[r+1]??``)){let t=r;if(r++,(e[r]===`+`||e[r]===`-`)&&r++,li(e.charCodeAt(r)))for(;r<n&&li(e.charCodeAt(r));)r++;else r=t}let t=ii.find(t=>e.startsWith(t,r)&&!di(e.charCodeAt(r+t.length)));t?(r+=t.length,i(`duration`,o,r)):i(`number`,o,r);continue}if(a===`@`){for(r++;r<n&&di(e.charCodeAt(r));)r++;i(r-o>1?`align`:`error`,o,r);continue}if(a===`$`&&ui(e.charCodeAt(r+1))){for(r++;r<n&&/[A-Za-z0-9_]/.test(e[r]);)r++;let t=/^:(noquote|backtick|triplequote)(?![A-Za-z0-9_])/.exec(e.slice(r,r+13));t&&(r+=t[0].length),i(t?.[1]===`noquote`?`number`:t?.[1]===`backtick`?`backtick`:`string`,o,r);continue}if(ui(t)){for(;r<n&&di(e.charCodeAt(r));)r++;i(`ident`,o,r);continue}let s=e.slice(r,r+2);ai.has(s)?(r+=2,i(`punct`,o,r)):oi.has(a)?(r++,i(`punct`,o,r)):(r+=t>=55296&&t<=56319&&r+1<n?2:1,i(`error`,o,r))}return t.push({type:`eof`,text:``,span:{start:n,end:n}}),t}function ci(e,t,n){for(let r=t+1;r<e.length;r++){let t=e[r];if(t===`\\`)r++;else if(t===n)return r+1}return-1}function li(e){return e>=48&&e<=57}function ui(e){return e>=65&&e<=90||e>=97&&e<=122||e===95}function di(e){return ui(e)||li(e)}function fi(e){return mi(e,e=>{e.query(),e.expectEof()})}function pi(e){return mi(e,e=>{e.expr(),e.expectEof()})}function mi(e,t){let n={commands:[],calls:[]};if(e.length>1e6)return n.error={message:`The query is too long.`,span:{start:0,end:0}},n;let r=new gi(si(e).filter(e=>e.type!==`comment`),n);try{t(r)}catch(e){if(!(e instanceof hi))throw e;n.error={message:e.message,span:e.span}}return n}var hi=class extends Error{span;constructor(e,t){super(e),this.span=t}},gi=class e{i=0;depth=0;tokens;out;constructor(e,t){this.tokens=e,this.out=t}get t(){return this.tokens[this.i]??this.tokens[this.tokens.length-1]}peek(e=1){return this.tokens[this.i+e]??this.tokens[this.tokens.length-1]}is(e){return this.t.type===`punct`&&this.t.text===e}isWord(e){return this.t.type===`ident`&&this.t.text===e}next(){let e=this.t;if(e.type===`error`)throw new hi(_i(e),e.span);return this.i++,e}expect(e){return this.is(e)||this.fail(`Expected "${e}"`),this.next()}fail(e){let t=this.t;throw t.type===`error`?new hi(_i(t),t.span):new hi(`${e}, found ${t.type===`eof`?`end of query`:`"${t.text}"`}.`,t.span)}enter(){if(++this.depth>256)throw new hi(`The query is nested too deeply.`,this.t.span)}leave(){this.depth--}expectEof(){this.t.type!==`eof`&&this.fail(`Unexpected text`)}query(){for(this.command();this.is(`|`);)this.next(),this.command()}command(){this.t.type!==`ident`&&this.fail(`Expected a command name`);let e=this.next(),t={name:e.text,span:e.span,named:[]};if(this.out.commands.push(t),!this.atArgsEnd()){for(this.argument(t.named);this.is(`,`);)this.next(),this.argument(t.named);this.atArgsEnd()||this.fail(`Expected "," or "|"`)}}atArgsEnd(){return this.t.type===`eof`||this.is(`|`)||this.is(`]`)}argument(e){if(this.t.type===`ident`&&this.peek().type===`punct`&&this.peek().text===`:`){let t=this.next();e.push({name:t.text,span:t.span}),this.next(),this.valueWithDirection()}else this.valueWithDirection()}valueWithDirection(){this.assignOrExpr(),(this.isWord(`asc`)||this.isWord(`desc`))&&this.next()}assignOrExpr(){let e=this.i;if(this.t.type===`backtick`||this.t.type===`ident`){for(this.next();this.is(`.`)&&(this.peek().type===`ident`||this.peek().type===`backtick`);)this.next(),this.next();if(this.is(`=`)){this.next(),this.expr();return}this.i=e}this.expr()}expr(){this.enter(),this.binary(0),this.leave()}static LEVELS=[[`or`],[`xor`],[`and`],[`==`,`!=`,`<`,`<=`,`>`,`>=`,`in`],[`+`,`-`],[`*`,`/`,`%`]];binary(t){let n=e.LEVELS[t];if(!n)this.unary();else if(t===3)this.notLevel();else for(this.binary(t+1);this.isOp(n);)this.next(),this.binary(t+1)}notLevel(){if(this.isWord(`not`)){this.next(),this.enter(),this.notLevel(),this.leave();return}this.binary(4);let t=e.LEVELS[3]??[];for(;this.isOp(t);)this.next(),this.binary(4)}isOp(e){let t=this.t;return t.type===`punct`||t.type===`ident`?e.includes(t.text):!1}unary(){this.is(`-`)||this.is(`+`)?(this.next(),this.enter(),this.unary(),this.leave()):this.postfix()}postfix(){for(this.primary();;)if(this.is(`[`))this.next(),this.is(`]`)||this.expr(),this.expect(`]`);else if(this.t.type===`align`)this.next();else return}primary(){let e=this.t;switch(e.type){case`number`:case`duration`:case`string`:case`align`:this.next();return;case`backtick`:this.next();return;case`ident`:if(this.peek().type===`punct`&&this.peek().text===`(`){this.call();return}for(this.next();this.is(`.`)&&(this.peek().type===`ident`||this.peek().type===`backtick`);)this.next(),this.next();return;case`punct`:if(e.text===`(`){this.next(),this.expr(),this.expect(`)`);return}if(e.text===`{`){if(this.next(),this.enter(),!this.is(`}`))for(this.valueWithDirection();this.is(`,`);)this.next(),this.valueWithDirection();this.expect(`}`),this.leave();return}if(e.text===`[`){this.next(),this.enter(),this.query(),this.leave(),this.expect(`]`);return}this.fail(`Expected a value`);return;default:this.fail(`Expected a value`)}}call(){let e=this.next(),t={fn:e.text,span:e.span,named:[]};if(this.out.calls.push(t),this.expect(`(`),this.enter(),!this.is(`)`))for(this.callArg(t);this.is(`,`);)this.next(),this.callArg(t);this.leave(),this.expect(`)`)}callArg(e){if(this.t.type===`ident`&&this.peek().type===`punct`&&this.peek().text===`:`){let t=this.next();e.named.push({name:t.text,span:t.span}),this.next()}this.assignOrExpr()}};function _i(e){return e.text.startsWith(`"`)||e.text.startsWith(`'`)?`A string is not closed.`:e.text.startsWith("`")?`A backtick-quoted name is not closed.`:`Unexpected character "${e.text}".`}function vi(e){return xi(fi(e))}function yi(e){let t=xi(pi(e)),n=si(e).find(e=>e.type===`comment`);return n?{ok:!1,issues:[...t.issues,{severity:`error`,message:`Comments are not allowed here.`,span:n.span}]}:t}const bi=k({});function xi(e){let t=[];e.error&&t.push({severity:`error`,message:e.error.message,span:e.error.span});for(let n of e.commands){let e=Object.hasOwn(ni,n.name)?ni[n.name]:void 0;if(!e)t.push({severity:`error`,message:`Unknown command "${n.name}".`,span:n.span});else for(let r of n.named)e.includes(r.name)||t.push({severity:`error`,message:`"${n.name}" has no parameter "${r.name}".`,span:r.span})}for(let n of e.calls){if(!Object.hasOwn(ri,n.fn)){t.push({severity:`error`,message:`Unknown function "${n.fn}".`,span:n.span});continue}let e=[...ri[n.fn]??[],...bi[n.fn]??[]];for(let r of n.named)e.includes(r.name)||t.push({severity:`error`,message:`"${n.fn}" has no parameter "${r.name}".`,span:r.span})}return t.sort((e,t)=>e.span.start-t.span.start),{ok:!t.some(e=>e.severity===`error`),issues:t}}var Si=class extends Error{},Ci=class extends Error{fieldName;constructor(e){super(`A field name contains a backtick or a line break.`),this.fieldName=e}};let wi=1/0;function Ti(e){if(e.length>wi)throw new Si;return e}function Ei(e,t,n){let r=``;for(let i=0;i<e.length;i++)r=Ti(i===0?t(e[i]):`${r}${n}${t(e[i])}`);return r}function Di(e,t){let n=wi;wi=Math.min(wi,e);try{return t()}finally{wi=n}}function Oi(e,t=1/0){return Di(t,()=>{let t=[],n=[],r=0,i=!0;for(let a of e.commands){let e;if(a.name===`//`?e=`// ${Ki(a.comment??``)}`:(e=`${i?``:`| `}${ji(a)}`,i=!1),n.push({start:r,end:r+e.length}),t.push(e),r+=e.length+1,r-1>wi)throw new Si}return{text:t.join(`
package/web/index.html CHANGED
@@ -28,7 +28,7 @@
28
28
  <link rel="manifest" href="./manifest.webmanifest">
29
29
  <link rel="icon" href="./icon.svg" type="image/svg+xml">
30
30
  <link rel="apple-touch-icon" href="./icon-180.png">
31
- <script type="module" crossorigin src="./assets/index-BO3AM1fZ.js"></script>
31
+ <script type="module" crossorigin src="./assets/index-Dox0eScg.js"></script>
32
32
  <link rel="modulepreload" crossorigin href="./assets/jsx-runtime-Wy9s6hX0.js">
33
33
  <link rel="stylesheet" crossorigin href="./assets/index-DPywAY6M.css">
34
34
  </head>