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.
- package/dist/inputs.js +5 -2
- package/dist/main.js +2 -1
- package/dist/mapping.js +12 -13
- package/dist/safe-fs.d.ts +11 -0
- package/dist/safe-fs.js +33 -1
- package/dist/serve/server.js +13 -4
- package/package.json +4 -4
- package/web/THIRD-PARTY-NOTICES.txt +1 -1
- package/web/assets/{BatchView-CJw9TDhQ.js → BatchView-CIkOhHdk.js} +1 -1
- package/web/assets/{DashboardsView-gW0FEoq7.js → DashboardsView-CCo2UqSu.js} +1 -1
- package/web/assets/{DropZone-CIbk77sc.js → DropZone-Cm1HZT4A.js} +1 -1
- package/web/assets/{MappingView-Co21Vkp_.js → MappingView-Co7N_18o.js} +1 -1
- package/web/assets/{ReferenceView-S1R-kCt6.js → ReferenceView-BMehx7sH.js} +1 -1
- package/web/assets/{index-BO3AM1fZ.js → index-Dox0eScg.js} +4 -4
- package/web/assets/{mapping-text-B64_Oh2A.js → mapping-text-DAJ9FWwj.js} +1 -1
- package/web/assets/{translate.worker-C2M3Sf23.js → translate.worker-B0yZ5sFl.js} +1 -1
- package/web/index.html +1 -1
- package/web/sw.js +2 -2
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{t as e}from"./dict-9ToLi8Te.js";import{T as t}from"./index-BO3AM1fZ.js";import{a as n,n as r,t as i}from"./jsx-runtime-Wy9s6hX0.js";var a=e=>({k:`str`,v:e}),o=e=>({k:`num`,v:String(e)}),s=e=>({k:`bool`,v:e}),c=()=>({k:`null`}),l=e=>({k:`field`,name:e}),u=e=>({k:`ident`,v:e}),d=e=>({k:`time`,v:e}),f=e=>({k:`dpl`,v:e}),p=e=>({k:`raw`,text:e}),m=(e,t)=>t?{k:`var`,name:e,mod:t}:{k:`var`,name:e},h=e=>({k:`sub`,q:{commands:e}}),g=e=>({k:`block`,items:e}),_=(e,t)=>({k:`assign`,name:e,e:t}),v=(e,t)=>({k:`dir`,e,dir:t}),y=e=>({k:`un`,op:`not`,e}),b=e=>({k:`un`,op:`-`,e}),x=(e,t,n)=>({k:`bin`,op:e,l:t,r:n}),S=(e,t)=>t===void 0?{k:`index`,e}:{k:`index`,e,key:t},ee=(e,t)=>({k:`align`,e,unit:t}),te=e=>({kind:`pos`,value:e}),C=(e,t)=>({kind:`named`,name:e,value:t});function w(e,...t){return{k:`call`,fn:e,args:t.map(re)}}function T(e,...t){return{name:e,args:t.map(re)}}function E(e,t){return{name:e,args:t.map(re)}}function ne(e,t){return{k:`call`,fn:e,args:t.map(re)}}function re(e){return`kind`in e?e:{kind:`pos`,value:e}}function D(e){let t;for(let n of e)t=t?x(`and`,t,n):n;return t}function ie(e){let t;for(let n of e)t=t?x(`or`,t,n):n;return t}function ae(e){return JSON.parse(JSON.stringify(e))}var oe=2e5,O=`error`,k=`warning`,A=`info`;function j(e,t,n,r){return{code:e,severity:t,title:n,hint:r}}var se=[j(`SPL1001`,O,`This part of the search could not be read.`,`Check for an unterminated string or an unbalanced bracket.`),j(`SPL1002`,O,`The search or one of its stages is empty.`,`Remove the empty stage or the extra pipe.`),j(`SPL1003`,O,`The command's arguments could not be read.`,`Compare the stage with Splunk's Search Reference for this command.`),j(`SPL1004`,O,`An expression could not be read.`,`Check operators, parentheses and quotes in the expression.`),j(`SPL1005`,O,`A macro could not be expanded.`,`Check the macro definition in the mapping file for cycles and the number of arguments.`),j(`SPL1006`,O,`The search is too large or too deeply nested to translate.`,`Split the search, or reduce nesting of subsearches and parentheses.`),j(`SPL1007`,O,`The search has no data source DQL can start from.`,`Start the search with an index, a lookup or another generating command.`),j(`SPL1008`,O,`The translator hit an internal problem with this search.`,`Please report the search (with sensitive values removed) so it can be fixed.`),j(`SPL2001`,k,`This command is not known to the translator.`,`If it is a custom command, rewrite this stage by hand.`),j(`SPL2002`,k,`This command has no DQL equivalent.`,`Rewrite this stage by hand; the rest of the query is still translated.`),j(`SPL2003`,k,`An argument or option is not supported.`,`Check whether the option matters for your result.`),j(`SPL2004`,k,`This eval function has no DQL equivalent.`,`Rewrite the expression by hand.`),j(`SPL2005`,k,`This aggregation function has no DQL equivalent.`,`Rewrite the aggregation by hand or remove it.`),j(`SPL2006`,k,`This regular expression cannot be converted to a Dynatrace pattern.`,`Write the parse pattern by hand.`),j(`SPL2007`,k,`This subsearch form cannot be translated.`,`Rewrite the subsearch as a join or a filter by hand.`),j(`SPL2008`,k,`This command writes data or sends something; it was dropped.`,`Recreate the side effect in Dynatrace (workflow, lookup upload) if you still need it.`),j(`SPL2009`,k,`A wildcard field list needs the list of fields, which is not known here.`,`List the fields explicitly.`),j(`SPL2010`,k,`This command depends on the order of result rows, which DQL does not provide.`,`Rewrite this stage by hand.`),j(`SPL2011`,k,`Real-time and index-time modifiers have no DQL equivalent.`,`Use a normal time range.`),j(`SPL2012`,k,`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.`),j(`SPL3001`,k,`Case sensitivity differs from Splunk here.`,`Values that differ only in case will not match.`),j(`SPL3002`,k,`Missing or empty fields are handled differently.`,`Check rows where the field is missing.`),j(`SPL3003`,k,`The result has a different shape than in Splunk.`,`Check how the result is charted or used afterwards.`),j(`SPL3004`,k,`The result depends on record order, which DQL does not guarantee here.`,`Add an explicit sort if order matters.`),j(`SPL3005`,k,`This aggregation may be computed differently (exact or approximate).`,`Expect small numeric differences.`),j(`SPL3006`,k,`Values may be compared as a different type than in Splunk.`,`Declare the field type in the mapping file (fieldTypes).`),j(`SPL3007`,k,`An index position was adjusted from 1-based to 0-based.`,`Check the result for an off-by-one difference.`),j(`SPL3008`,k,`A regular expression was converted to a Dynatrace pattern.`,`Check the extracted values on real data.`),j(`SPL3009`,k,`Splunk applies a default limit here that DQL does not.`,`Add an explicit limit if you relied on it.`),j(`SPL3010`,k,`Time zone or time format handling may differ.`,`Check timestamps in the result.`),j(`SPL3011`,k,`Wildcard or token matching differs from Splunk.`,`Check matches on real data.`),j(`SPL3012`,k,`Part of the query runs twice inside a sub-query.`,`Expect higher query cost; both runs may see slightly different data.`),j(`SPL3013`,k,`Multivalue fields behave differently.`,`Check rows where a field has several values.`),j(`SPL3014`,k,`This command was approximated with a different construct.`,`Check the result carefully.`),j(`SPL3015`,k,`The time range could not be reproduced exactly.`,`Set the time range in Dynatrace.`),j(`SPL3016`,k,`Output field names differ from Splunk.`,`Rename fields if later steps rely on the Splunk names.`),j(`SPL3017`,k,`The generated DQL did not pass the offline syntax check.`,`Check the highlighted line; this may need a manual fix.`),j(`SPL4001`,k,`This index has no entry in the mapping file.`,`Add the index under "indexes" in the mapping file.`),j(`SPL4002`,k,`This sourcetype has no entry in the mapping file.`,`Add the sourcetype under "sourcetypes" in the mapping file.`),j(`SPL4003`,k,`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.`),j(`SPL4004`,k,`This macro has no definition in the mapping file.`,`Copy its definition from macros.conf into "macros".`),j(`SPL4005`,k,`This lookup has no entry in the mapping file.`,`Upload the table to Grail and add it under "lookups".`),j(`SPL4006`,k,`This eventtype, tag or saved search cannot be resolved.`,`Add it under "eventtypes" or "tags" in the mapping file.`),j(`SPL4007`,k,`This metric has no entry in the mapping file.`,`Add it under "metrics" in the mapping file.`),j(`SPL4008`,k,`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.`),j(`SPL4009`,k,`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.`),j(`SPL5001`,A,`The search has no time range; DQL uses the time range chosen in Dynatrace.`,`Add from: to the fetch if the time range matters.`),j(`SPL5002`,A,`Splunk default fields were renamed to their Grail names.`,`No action needed.`),j(`SPL5003`,A,`Rows with an empty group-by field are removed first, as Splunk does.`,`No action needed.`),j(`SPL5004`,A,`A sort by time was added to reproduce Splunk event order.`,`No action needed.`),j(`SPL5005`,A,`A macro was expanded.`,`No action needed.`),j(`SPL5006`,A,`Splunk's default result limit is not reproduced; DQL returns at most 1000 records by default.`,`Add a limit if needed.`),j(`SPL5007`,A,`A display-only command was dropped; it does not change the data.`,`No action needed.`),j(`SPL5008`,A,`This is accurate but can be expensive on large data.`,`Consider an approximate function if exactness does not matter.`)];new Map(se.map(e=>[e.code,e]));function ce(){return se}function le(e,n,r,i,a){let o=0;for(let s=n;s<r;s++){let n=e[s];if(n===`"`){let n=t(e,s,r);if(n===-1)return-1;s=n}else if(n===i)o++;else if(n===a&&(o--,o===0))return s}return-1}function ue(e,n,r,i){let a=0;for(let o=n;o<r;o++){let s=e[o];if(s===`"`){let n=t(e,o,r);if(n===-1)return;o=n}else if(s===`(`||s===`[`)a++;else if(s===`)`||s===`]`)a--;else if(a===0&&/[A-Za-z]/.test(s)&&(o===n||/[\s,)]/.test(e[o-1]))){for(let t of i)if(e.slice(o,o+t.length).toLowerCase()===t&&!/[A-Za-z0-9_]/.test(e[o+t.length]??``))return{pos:o,word:t}}}}function de(e){return e.replace(/\\(["\\])/g,`$1`)}e({_time:`timestamp`,_raw:`content`,host:`host.name`,source:`log.source`,index:`dt.system.bucket`});var M=class extends Error{code;span;constructor(e,t,n){super(n),this.code=e,this.span=t}},fe=e({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`}),pe=e({s:1,m:60,h:3600,d:86400,w:604800});function N(e){return fe[e.toLowerCase()]??(e===`M`?`M`:void 0)}function me(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 fe[n]}function he(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:ye(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=be(t,l);return d===void 0?{kind:`invalid`,detail:`Unknown time zone "${t}".`}:{kind:`absolute`,iso:ye(l-d*6e4),fromText:!0}}return ge(n)}function ge(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=_e(t[1]??``),r=_e(t[3]??``);if(!n||!r)return{kind:`invalid`,detail:`"${e}" uses an unknown time unit.`};let i=``;if(t[2]!==void 0){let e=me(t[2]);if(!e)return{kind:`invalid`,detail:`"@${t[2]}" is not a known snap unit.`};i=`@${e}`}let a=ve(n);if(a===void 0)return{kind:`invalid`,detail:`"${e}" mixes calendar and clock units.`};if(r.length>0){let t=ve(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 _e(e){let t=[];for(let n of e.matchAll(/([+-])(\d+)([A-Za-z]*)/g)){let e=n[3]===``?`s`:N(n[3]??``);if(!e)return;t.push({sign:n[1]===`-`?-1:1,n:Number(n[2]),unit:e})}return t}function ve(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=pe[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 ye(e){return new Date(e).toISOString().replace(/\.000Z$/,`Z`)}function be(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 P(e,t){for(let n of t)e.push(n)}var xe=/^-?\d+(\.\d+)?$/,Se=new Set([`index`,`sourcetype`,`eventtype`,`tag`,`earliest`,`latest`]),Ce=/^_index_(earliest|latest)$/;function we(e,t,n,r=!1,i){return F(e,t,r,i)??s(!0)}function F(e,t,n,r){let i=e=>r??e;switch(e.t){case`and`:return D(e.items.map(e=>F(e,t,n,r)).filter(e=>e!==void 0));case`or`:return ie(e.items.map(e=>F(e,t,n,r)).filter(e=>e!==void 0));case`not`:{let i=F(e.e,t,n,r);return i===void 0?void 0:w(`isFalseOrNull`,i)}case`macro`:return;case`sub`:return t.tc.lowerSubsearchFilter(e,t);case`term`:return Te(e.v,e.quoted,!1,t,i(e.span));case`func`:return e.fn===`CASE`?Te(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.`}),Te(e.v,!0,!1,t,i(e.span)));case`in`:return Ee(e,t,i(e.span));case`cmp`:return De(e,t,i(e.span),i(e.fieldSpan))}}function Te(e,t,n,r,i){if(r.state.schema.kind!==`events`)throw new M(`SPL2003`,i,`A free-text term after a transforming command can only stand on its own in the search.`);!t&&e.includes(`*`)&&r.report(`SPL3011`,i,{detail:`"${e}": wildcard terms match on token boundaries that differ from Splunk's.`});let o=[l(r.field(`_raw`,i)),a(e)];return n?w(`matchesPhrase`,...o,C(`caseSensitive`,s(!0))):w(`matchesPhrase`,...o)}function Ee(e,t,n){let r=t.field(e.field,n),i=t.fieldType(r);return e.values.length>0&&e.values.every(e=>!e.quoted&&xe.test(e.v))&&i!==`string`?(i!==`number`&&t.report(`SPL3006`,n,{subject:`type:${r}`,detail:`"${e.field}" has no declared type; it is compared as a number.`}),w(`in`,l(r),g(e.values.map(e=>o(e.v))))):w(`matchesValue`,l(r),g(e.values.map(e=>a(e.v))))}function De(e,t,n,r){let i=e.field;if(i===`earliest`||i===`latest`||Ce.test(i))throw new M(`SPL2003`,n,`A time modifier can only be translated as a top-level term of the first search.`);if(i===`sourcetype`||i===`eventtype`||i===`tag`)return Oe(e,t,n);if(i===`index`&&t.first){t.report(`SPL3014`,n,{detail:`An index inside OR/NOT is translated as a bucket comparison.`});let r=t.mapping.indexes.get(e.value)?.buckets[0]??e.value,i=x(`==`,l(`dt.system.bucket`),a(r));return e.op===`!=`?y(i):i}let s=t.field(i,r),c=t.fieldType(s),u=e.value,d=!e.quoted&&xe.test(u),f=()=>{c===void 0&&t.report(`SPL3006`,r,{subject:`type:${s}`,detail:`"${i}" has no declared type; it is compared as a ${d?`number`:`text`}.`})};switch(e.op){case`=`:case`!=`:{let r;return u===`*`&&!e.quoted?e.op===`!=`?(t.report(`SPL3002`,n,{detail:`${i}!=* is translated as "field is missing".`}),w(`isNull`,l(s))):w(`isNotNull`,l(s)):d&&c!==`string`?(c!==`number`&&f(),r=x(e.op===`=`?`==`:`!=`,l(s),o(u)),r):(/.\*./.test(u)&&t.report(`SPL3011`,n,{detail:`"${u}": a wildcard in the middle of a value may match differently.`}),r=w(`matchesValue`,l(s),a(u)),e.op===`!=`?y(r):r)}default:return f(),x(e.op,l(s),d?o(u):a(u))}}function Oe(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===`!=`?y(p(i)):p(i)}function ke(e){return e?e.t===`and`?e.items:[e]:[]}function Ae(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=D(n);i&&e.emit(T(`filter`,i));for(let t of r)e.emit(T(`filterOut`,t))}function je(e,t,n){let r=e.mapping,i=[],o=[],s=[],c,l;for(let a of ke(t))if(!n&&a.t===`cmp`&&a.field===`index`&&a.op===`=`)o.push(a);else if(!n&&a.t===`or`&&a.items.length>0&&a.items.every(e=>e.t===`cmp`&&e.field===`index`&&e.op===`=`))P(o,a.items);else if(a.t===`cmp`&&(a.field===`earliest`||a.field===`latest`)&&a.op===`=`){if(e.tc.options.tokens&&/^\$[A-Za-z_][A-Za-z0-9_.]*\$$/.test(a.value))continue;let t=he(a.value,r.defaults.timezone);a.field===`earliest`?c={value:t,span:a.span}:l={value:t,span:a.span}}else if(a.t===`cmp`&&Ce.test(a.field))e.report(`SPL2011`,a.span,{detail:`${a.field} (index time) has no DQL equivalent and was left out.`});else if(a.t===`cmp`&&Se.has(a.field)&&a.op===`=`&&a.field!==`index`){let t=Oe(a,e,a.span);t&&s.push(t)}else i.push(a);let d=r.defaults.dataObject,f=[];if(n)d=n.dataObject,f=[...n.buckets],n.filter!==void 0&&s.unshift(p(n.filter));else if(o.length===0)e.report(`SPL4001`,e.span,{subject:`(none)`,detail:`The search names no index; Splunk would search your default indexes, DQL reads all records of this type.`});else{let t=new Set,n=!1,i=!1;for(let a of o){if(a.value===`*`){i=!0;continue}let c=Ne(r.indexes,a.value);c?(t.add(c.dataObject),P(f,c.buckets),c.filter!==void 0&&o.length===1&&s.unshift(p(c.filter))):(n=!0,e.report(`SPL4001`,a.span,{subject:a.value,detail:`Index "${a.value}" has no entry in the mapping file, so all records are read.`}))}if(t.size>1)throw new M(`SPL2003`,e.span,`These indexes map to different Grail data objects; split the search.`);t.size===1&&(d=[...t][0]),(n||i)&&(f=[])}let m=[te(u(d))];f.length>0&&m.push(C(`bucket`,g([...new Set(f)].map(a))));let h=e.tc.options.timeRange,_=r.defaults.timezone;!c&&h?.earliest!==void 0&&(c={value:he(h.earliest,_),span:e.span}),!l&&h?.latest!==void 0&&(l={value:he(h.latest,_),span:e.span}),!c&&r.defaults.timeframe!==void 0&&(c={value:he(r.defaults.timeframe,_),span:e.span});let v=c?Fe(e,`earliest`,c.value,c.span):void 0,y=l?Fe(e,`latest`,l.value,l.span):void 0;v&&m.push(C(`from`,v)),y&&m.push(C(`to`,y)),c||e.tc.diags.reportOnce(`SPL5001`,e.span,e.index),e.emit({name:`fetch`,args:m});let b=[...s];for(let t of i){let n=F(t,e,!1,void 0);n&&b.push(n)}Ae(e,b)}function Me(e,t){if(!t)return;let n=[],r=[];for(let i of ke(t)){if(e.state.schema.kind!==`events`&&i.t===`term`){r.push(i.v),e.report(`SPL3011`,i.span,{detail:`A free-text term after a transforming command is matched against all fields with the DQL search command.`});continue}if(i.t===`cmp`&&(i.field===`earliest`||i.field===`latest`)){e.report(`SPL2003`,i.span,{detail:`A time modifier in a later search stage has no DQL equivalent and was left out.`});continue}let t=F(i,e,!1,void 0);t&&n.push(t)}Ae(e,n);for(let t of r)e.emit(T(`search`,a(t)))}function Ne(e,t){let n=e.get(t);if(n)return n;let r;for(let[n,i]of e)n.includes(`*`)&&Pe(n,t)&&(!r||n.length>r.len)&&(r={len:n.length,value:i});return r?.value}function Pe(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 Fe(e,t,n,r){switch(n.kind){case`now`:return;case`all`:t===`earliest`&&e.report(`SPL3015`,r,{detail:`"All time" has no DQL equivalent; choose the time range in Dynatrace.`});return;case`realtime`:e.report(`SPL2011`,r,{detail:`Real-time searches have no DQL equivalent; the time modifier was left out.`});return;case`invalid`:e.report(`SPL3015`,r,{detail:n.detail});return;case`absolute`:return n.fromText&&e.report(`SPL3010`,r,{detail:`The date was converted to UTC using the time zone "${e.mapping.defaults.timezone}".`}),a(n.iso);case`relative`:return n.exact||e.report(`SPL3015`,r,{detail:`An offset after the snap unit was kept as an expression; check that Dynatrace accepts it.`}),d(n.dql)}}var I=class extends Error{span;constructor(e,t){super(e),this.span=t}},Ie=200,Le=2e4,Re=/^[A-Za-z_][A-Za-z0-9_.:{}@-]*$/;function ze(e,t,n){let r=new He(Be(e,t,n));if(r.atEnd())return;let i=r.andExpr();return r.expectEnd(),i}function Be(e,n,r){let i=[],a=n;for(;a<r;){let n=e[a];if(/\s/.test(n)){a++;continue}if(n==="`"&&e.startsWith("```",a)){let t=e.indexOf("```",a+3);a=t===-1||t+3>r?r:t+3;continue}if(n===`(`||n===`)`){i.push({type:n,span:{start:a,end:a+1}}),a++;continue}if(n===`[`){let t=le(e,a,r,`[`,`]`);if(t===-1)throw new I(`A subsearch "[" is not closed.`,{start:a,end:r});i.push({type:`sub`,inner:{start:a+1,end:t},span:{start:a,end:t+1}}),a=t+1;continue}if(n===`]`)throw new I(`Unexpected "]".`,{start:a,end:a+1});if(n==="`"){let t=e.indexOf("`",a+1),n=t===-1||t>=r?r:t+1;i.push({type:`macro`,span:{start:a,end:n}}),a=n;continue}if(n===`"`){let n=t(e,a,r);if(n===-1)throw new I(`A quoted string is not closed.`,{start:a,end:r});i.push({type:`word`,text:de(e.slice(a+1,n)),quoted:!0,span:{start:a,end:n+1}}),a=n+1;continue}let o=a;for(;a<r;){let n=e[a];if(/[\s()[\]]/.test(n))break;if(n===`"`){let n=t(e,a,r);if(n===-1)throw new I(`A quoted string is not closed.`,{start:a,end:r});a=n+1}else a++}if(a===o)throw new I(`Unexpected "${n}".`,{start:a,end:a+1});i.push({type:`word`,text:e.slice(o,a),quoted:!1,span:{start:o,end:a}})}if(i.push({type:`eof`,span:{start:r,end:r}}),i.length>Le)throw new I(`The search has more than ${Le} terms.`,{start:n,end:r});return i}function Ve(e){let n=[],r=0;for(;r<e.length;){if(e[r]===`,`){r++;continue}if(e[r]===`"`){let i=t(e,r,e.length),a=i===-1?e.length:i;n.push({v:de(e.slice(r+1,a)),quoted:!0}),r=a+1;continue}let i=e.indexOf(`,`,r),a=i===-1?e.length:i,o=e.slice(r,a).trim();o!==``&&n.push({v:o,quoted:!1}),r=a}return n}var He=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 I(`Unexpected ")".`,this.t.span);if(this.t.type!==`eof`)throw new I(`Unexpected text in the search.`,this.t.span)}enter(){if(++this.depth>Ie)throw new I(`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:We(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:We(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 I(`Empty parentheses.`,this.t.span);let e=this.andExpr();if(this.ty()!==`)`)throw new I(`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 I(`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 I(`"${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(Re.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 I(`Expected a value in the IN list.`,e.span);this.i++,e.quoted?t.push({v:e.text,quoted:!0}):P(t,Ve(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=Ue(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=de(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(Re.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=de(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 Ue(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 We(e){return{start:e[0]?.span.start??0,end:e[e.length-1]?.span.end??0}}function Ge(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/${Ke(t)} is used.`}),{path:`/lookups/${Ke(t)}`})}function Ke(e){return e.replace(/\.csv$/i,``).replace(/[^A-Za-z0-9_.-]/g,`_`)||`lookup`}var qe=e=>T(`load`,a(e)),Je={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 M(`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 M(`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 M(`SPL1003`,e.span,`lookup needs a field to match on.`);let i=[],a=t.keyword(`outputnew`);if(a||t.keyword(`output`))for(;!t.atEnd();){if(t.eat(`,`))continue;let e=t.fieldName();if(!e)throw new M(`SPL1003`,t.here(),`Expected an output field.`);let n=e.value;t.keyword(`as`)&&(n=t.fieldName()?.value??n),i.push({col:e.value,as:n})}let o=Ge(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,l(e.field(t.local,t.span)))),n=i.length>0?[C(`fields`,g(i.map(e=>e.as===e.col?l(e.col):_(e.as,l(e.col)))))]:[];e.emit(T(`join`,h([{...qe(o.path),origin:[e.index]}]),C(`on`,g(t)),C(`kind`,u(`leftOuter`)),...n)),i.length===0&&e.report(`SPL3016`,e.span,{detail:`Lookup columns arrive with the prefix "right.".`});for(let t of i)e.field(t.as,e.span,!0);return}let s=r[0],c=[C(`sourceField`,l(e.field(s.local,s.span))),C(`lookupField`,l(o.key??s.lookupField))],d=i;d.length===0&&(o.columns?d=o.columns.filter(e=>e!==(o.key??s.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 f=e=>`_new_${e.replace(/[^A-Za-z0-9_]/g,`_`)}`;d.length>0&&c.push(C(`fields`,g(d.map(e=>a?_(f(e.as),l(e.col)):e.as===e.col?l(e.col):_(e.as,l(e.col)))))),e.emit({name:`lookup`,args:[{kind:`pos`,value:h([{...qe(o.path),origin:[e.index]}])},...c]}),a&&d.length>0&&(e.emit(T(`fieldsAdd`,...d.map(e=>_(e.as,w(`coalesce`,l(e.as),l(f(e.as))))))),e.emit(T(`fieldsRemove`,...d.map(e=>l(f(e.as))))));for(let t of d)e.field(t.as,e.span,!0);e.addFields(d.map(e=>e.as))}},Ye={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 M(`SPL2003`,e.span,`inputlookup ${e.name}= cannot be translated.`);let r=t.word();if(!r)throw new M(`SPL1003`,e.span,`inputlookup needs a table name.`);let i=Ge(e,r.value,r.span),a;if(t.keyword(`where`)){let n=t.rest();try{a=ze(e.tc.text,n.start,n.end)}catch(e){throw e instanceof I?new M(`SPL1001`,e.span,e.message):e}}else if(!t.atEnd())throw new M(`SPL1003`,t.here(),`Unexpected text in inputlookup.`);if(n){if(a)throw new M(`SPL2003`,e.span,`inputlookup append=t with where cannot be translated.`);e.emit(T(`append`,h([{...qe(i.path),origin:[e.index]}])))}else e.emit(qe(i.path)),e.setTable(i.columns?[...i.columns]:[]),e.state.schema={kind:`table`,fields:i.columns?[...i.columns]:[]},a&&Me(e,a)}};function Xe(e,t){let n=e.tc.lowerSub(t.inner,e);if(n.incomplete)throw new M(`SPL2007`,t.span,`The subsearch contains a step that could not be translated.`);return n}var Ze={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 M(`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 M(`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 M(`SPL1003`,t.here(),`Expected join fields.`);r.push({name:a.value,span:a.span})}let i=t.balanced(`[`,`]`);if(!i)throw new M(`SPL1003`,e.span,`join needs a subsearch in [ … ].`);if(r.length===0)throw new M(`SPL2003`,e.span,`join without fields cannot be translated.`);let a=r.map(t=>e.field(t.name,t.span)),o=Xe(e,i);e.report(`SPL3009`,e.span,{detail:`Splunk join keeps one matching row by default (max=1); DQL keeps every match.`});let s=[{kind:`pos`,value:h(o.commands)},C(`on`,g(a.map(l))),C(`kind`,u(n))],c=o.outputFields?.filter(e=>!a.includes(e));if(c&&c.length>0){s.push(C(`fields`,g(c.map(l))));for(let t of c)e.field(t,e.span,!0);e.addFields(c)}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:s})}},Qe={name:`append`,tier:`T1`,summary:`append [sub].`,lower(e){let t=e.scanner();for(;t.option(););let n=t.balanced(`[`,`]`);if(!n)throw new M(`SPL1003`,e.span,`append needs a subsearch in [ … ].`);let r=Xe(e,n);e.emit(T(`append`,h(r.commands))),r.outputFields&&e.addFields(r.outputFields)}};function $e(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 M(`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=>Xe(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(T(`append`,h(e)))}}}var et=[Je,Ye,Ze,Qe,$e(`union`),$e(`multisearch`)],tt=1e4,nt=`The regular expression would give a Dynatrace pattern longer than ${tt} characters.`;function rt(e,t){if(e.budget.left-=t,e.budget.left<0)throw new L(nt)}var L=class extends Error{},it=e({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.`}),at=e({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}}),ot=e({d:`0-9`,w:`a-zA-Z0-9_`,s:` \\t\\r\\n`,t:`\\t`,n:`\\n`,r:`\\r`}),st=`[a-zA-Z0-9_]`,ct=4e3,lt=8,ut=`The regular expression is too large once its repeated groups are written out.`;function dt(e,t={}){if(e.length>ct)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:tt}},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 L(`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(`$`)&&!mt(n)&&(o=!0,n=n.slice(0,-1));let s=Pt(n),c;if(s.length>1){if(a||o)throw new L(`"^" or "$" together with alternatives (a|b) is not supported.`);c=[{k:`alts`,options:s.map(e=>ht(e,r,1)),quant:``}]}else c=ht(n,r,0);if(o&&c.push({k:`eos`}),ft(c)>2e3)throw new L(ut);let l=[],u=vt(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 L(nt);return{ok:!0,dpl:d,captures:l,anchoredStart:a}}catch(e){return e instanceof L?{ok:!1,reason:e.message}:{ok:!1,reason:`The regular expression could not be converted.`}}}function ft(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 pt(e){if(!/[\\^$.|?*+()[\]{}]/.test(e.replace(/\\[./\-:=@#,"' ]/g,``)))return e.replace(/\\([./\-:=@#,"' ])/g,`$1`)}function mt(e){let t=0;for(let n=e.length-2;n>=0&&e[n]===`\\`;n--)t++;return t%2==1}function ht(e,t,n){if(n>20)throw new L(`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(),jt(n);let s=o?`[${e.toLowerCase()}${e.toUpperCase()}]`:`[${Ot(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 L(`The regular expression ends with a backslash.`);if(/[1-9]/.test(t))throw new L(`Back-references have no Dynatrace pattern equivalent.`);if(t===`b`){a(),r.push({k:`boundary`}),c+=2;continue}let n=it[t];if(n)throw new L(n);let i=At(e,c+2,s),l=at[t];if(l){a(),jt(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 L(`The escape \\${t} is not supported.`);else o(t,i);c+=2+i.length;continue}if(l===`[`){let n=Mt(e,c,s),i=At(e,n+1,s);a(),jt(i),r.push({k:`class`,text:kt(e.slice(c,n+1),t.ci),quant:i}),c=n+1+i.length;continue}if(l===`.`){let t=At(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 L(`A single "." (any character) is only supported as ".*" or ".+".`);c+=1+t.length;continue}if(l===`(`){a();let i=Nt(e,c,s),o=At(e,i+1,s);for(let a of _t(e.slice(c+1,i),o,t,n))r.push(a);c=i+1+o.length;continue}if(l===`|`)throw new L(`Alternatives must stand alone in the pattern or inside a group.`);if(l===`^`||l===`$`)throw new L(`"${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 L(`A quantifier must follow something to repeat.`)}if(l===`)`||l===`]`)throw new L(`Unbalanced "${l}".`);let u=At(e,c+1,s);o(l,u),c+=1+u.length}return a(),r}function gt(e,t,n){let r=Pt(e);return r.length===1?ht(e,t,n+1):[{k:`alts`,options:r.map(e=>ht(e,t,n+1)),quant:``}]}function _t(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 L(`A look-around cannot be repeated.`);let i=gt(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 L(`Inline flags are only supported as (?i) or (?s) at the start of the pattern.`);else throw new L(`This group type is not supported.`)}if(a!==void 0&&n.captures){if(t!==``&&t!==`?`)throw new L(`A repeated capture group is not supported.`);if(/\(\?(?:P?<[A-Za-z_]|')/.test(i))throw new L(`Nested capture groups are not supported.`);return[{k:`capture`,name:a,inner:i,items:gt(i,n,r),optional:t===`?`}]}let o=gt(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>lt)throw new L(`A repeated group cannot be converted, except for a fixed count such as (…){3}.`);if(ft(o)*l>2e3)throw new L(ut);let u=[];for(let e=0;e<l;e++)for(let e of o)u.push(e);return u}function vt(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:Tt(c),end:!1};switch(rt(n,1+yt(a)),a.k){case`lit`:i.push(Dt(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 L(`".*" must be followed by fixed text to be converted.`);i.push(n.dotAll?`DATA`:`LD`);break;case`alts`:i.push(`${xt(a.options,t,n)}${a.quant}`);break;case`group`:i.push(`(${bt(a.items,t,n,a.quant===``?l:{fixed:!1,end:!1})})${a.quant}`);break;case`capture`:i.push(wt(a,t,n,l));break;case`look`:{let e=vt(a.items,t,n,{fixed:!1,end:!1});if(e.length===0)throw new L(`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(St(e[o-1],c));break;case`eos`:i.push(`EOS`)}}),i}function yt(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 bt(e,t,n,r){let i=vt(e,t,n,r);if(i.length===0)throw new L(`An empty group cannot be converted.`);return i.join(` `)}function xt(e,t,n){return`(${e.map(e=>{let r=vt(e,t,n,{fixed:!1,end:!1});if(r.length===0)throw new L(`An empty alternative (a|) cannot be converted.`);return r.length===1?r[0]:`(${r.join(` `)})`}).join(` | `)})`}function St(e,t){let n=Ct(t,!0),r=Ct(e,!1);if(n===!0&&r!==!0)return`!<<${st}`;if(r===!0&&n!==!0)return`!>>${st}`;throw new L(`A word boundary (\\b) is only supported directly before or after a word.`)}function Ct(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 wt(e,t,n,r){let i=Et(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 L(`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`${xt(c.options,t,n)}${o}:${i}`;if(e.items.some(e=>e.k===`any`)&&e.items[e.items.length-1]?.k!==`any`)throw new L(`The capture "${e.name}" has ".*" in the middle, which cannot be converted.`);return`(${bt(e.items,t,n,e.optional?{fixed:!1,end:!1}:r)})${o}:${i}`}function Tt(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===``&&Tt(e.items[0]):e.k===`capture`?!e.optional&&!/^\.[*]/.test(e.inner)&&(e.items.length===0||Tt(e.items[0])):e.k===`look`?e.ahead&&!e.negative:e.k===`eos`:!1}function Et(e){return/^[A-Za-z][A-Za-z0-9]*$/.test(e)?e:`'${e}'`}function Dt(e){return`'${e.replace(/\\/g,`\\\\`).replace(/'/g,`\\'`)}'`}function Ot(e){return/[\]\\^-]/.test(e)?`\\${e}`:e}function kt(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=ot[t];if(i!==void 0){r+=i;continue}if(/[A-Za-z0-9]/.test(t))throw new L(`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 At(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 L(`Possessive quantifiers are not supported.`);return i[0]}function jt(e){if(e.endsWith(`?`)&&e.length>1)throw new L(`Lazy quantifiers are only supported on ".".`)}function Mt(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 L(`POSIX character classes ([:alpha:]) are not supported.`):new L(`Nested character classes are not supported.`);if(e[r]===`]`)return r}throw new L(`A character class "[" is not closed.`)}function Nt(e,t,n){let r=0;for(let i=t;i<n;i++){let t=e[i];if(t===`\\`)i++;else if(t===`[`)i=Mt(e,i,n);else if(t===`(`&&r++,t===`)`&&(r--,r===0))return i}throw new L(`A group "(" is not closed.`)}function Pt(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}var Ft=e({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 It(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:Ft[o];if(!s)return{ok:!1,directive:`%${o??``}`};r(),t+=s,i++}return r(),{ok:!0,format:t}}var Lt=e({date_hour:`getHour`,date_minute:`getMinute`,date_mday:`getDayOfMonth`,date_month:`getMonth`,date_year:`getYear`,date_wday:`getDayOfWeek`});function R(e,t){switch(e.t){case`str`:return{e:a(e.v),type:`string`};case`num`:return{e:o(Wt(e.v)),type:`number`,real:/[.eE]/.test(e.v)};case`field`:return Rt(e.name,e.span,t);case`un`:{let n=R(e.e,t);return e.op===`NOT`?{e:y(n.e),type:`bool`}:{e:b(n.e),type:n.type}}case`in`:return{e:w(`in`,R(e.e,t).e,g(e.list.map(e=>R(e,t).e))),type:`bool`};case`bin`:return zt(e,t);case`call`:return $t(e,t)}}function Rt(e,t,n){let r=Lt[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:w(r,l(`timestamp`)),type:`number`};let i=n.field(e,t),a=n.fieldType(i);return{e:l(i),type:a===`time`?`time`:a===`number`?`number`:a===`string`?`string`:`unknown`}}function zt(e,t){let n=R(e.l,t),r=R(e.r,t);switch(e.op){case`AND`:return{e:x(`and`,n.e,r.e),type:`bool`};case`OR`:return{e:x(`or`,n.e,r.e),type:`bool`};case`XOR`:return{e:x(`xor`,n.e,r.e),type:`bool`};case`LIKE`:return{e:w(`like`,n.e,r.e),type:`bool`};case`.`:return{e:Gt(n.e,r.e),type:`string`};case`=`:case`==`:case`!=`:case`<`:case`<=`:case`>`:case`>=`:{let i=e.op===`=`?`==`:e.op;return 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.`}),{e:x(i,n.type===`time`?w(`unixSecondsFromTimestamp`,n.e):n.e,r.type===`time`?w(`unixSecondsFromTimestamp`,r.e):r.e),type:`bool`}):(Ht(t,e.l,n,r),Ht(t,e.r,r,n),{e:x(i,n.e,r.e),type:`bool`})}case`+`:return n.type===`string`&&r.type===`string`?{e:Gt(n.e,r.e),type:`string`}:Ut(`+`,n,r);case`-`:return n.type===`time`&&r.type===`time`?{e:x(`/`,x(`-`,n.e,r.e),d(`1s`)),type:`number`,real:!0}:Ut(`-`,n,r);case`*`:case`/`:case`%`:{let t=Bt(n),i=Bt(r);return e.op===`/`?{e:Vt(t,i),type:`number`,real:!0}:{e:x(e.op,t.e,i.e),type:`number`,real:(t.real??!1)||(i.real??!1)}}}}function Bt(e){return e.type===`time`?{e:w(`unixSecondsFromTimestamp`,e.e),type:`number`}:e}function Vt(e,t){return e.real||t.real?x(`/`,e.e,t.e):t.e.k===`num`&&/^\d+$/.test(t.e.v)?x(`/`,e.e,o(`${t.e.v}.0`)):e.e.k===`num`&&/^\d+$/.test(e.e.v)?x(`/`,o(`${e.e.v}.0`),t.e):x(`/`,w(`toDouble`,e.e),t.e)}function Ht(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 Ut(e,t,n){return t.type===`time`&&(n.type===`number`||n.type===`unknown`)?n.e.k===`num`&&/^\d+$/.test(n.e.v)?{e:x(e,t.e,d(`${n.e.v}s`)),type:`time`}:{e:x(e,t.e,x(`*`,n.e,d(`1s`))),type:`time`}:{e:x(e,t.e,n.e),type:t.type===`number`&&n.type===`number`?`number`:`unknown`,real:(t.real??!1)||(n.real??!1)}}function Wt(e){return e.replace(/^(-?)\./,`$10.`).replace(/\.(?=$|[eE])/,`.0`)}function Gt(e,t){let n=e=>e.k===`call`&&e.fn===`concat`?e.args.map(e=>e.value):[e];return w(`concat`,...n(e),...n(t))}var z=(e,t=`unknown`,n)=>(r,i,a)=>{if(n!==void 0&&r.length!==n)throw H(a,n);return{e:w(e,...r.map(e=>R(e,i).e)),type:t}};function B(e,t){let n=e[0];if(n===void 0)throw new M(`SPL1004`,t.span,`${t.fn}() expects at least 1 argument.`);return n}var V=(e,t,n)=>{throw new M(`SPL2004`,n.fnSpan,`${n.fn}() has no DQL equivalent.`)};function H(e,t){return new M(`SPL1004`,e.span,`${e.fn}() expects ${t} argument${t===1?``:`s`}.`)}function U(e,t,n){if(e?.t!==`str`)throw new M(`SPL2004`,t.span,`${t.fn}() needs ${n} as a quoted literal to be translated.`);return e.v}function W(e){if(e?.t===`num`&&/^-?\d+$/.test(e.v))return Number(e.v)}var Kt=e({if:(e,t,n)=>{if(e.length!==3)throw H(n,3);let[r,i,a]=e.map(e=>R(e,t));return{e:w(`if`,r.e,i.e,C(`else`,a.e)),type:i.type}},case:(e,t,n)=>{if(e.length<2||e.length%2!=0)throw new M(`SPL1004`,n.span,`case() needs condition/value pairs.`);let r=[];for(let t=0;t<e.length;t+=2)r.push([e[t],e[t+1]]);let i,a=r[r.length-1];a&&en(a[0])&&(i=R(a[1],t).e,r.pop());let o=i;for(let e=r.length-1;e>=0;e--){let[n,i]=r[e],a=R(n,t).e,s=R(i,t).e;o=o===void 0?w(`if`,a,s):w(`if`,a,s,C(`else`,o))}return{e:o??c(),type:`unknown`}},coalesce:z(`coalesce`),nullif:(e,t,n)=>{if(e.length!==2)throw H(n,2);let r=R(e[0],t),i=R(e[1],t);return{e:w(`if`,x(`==`,r.e,i.e),c(),C(`else`,r.e)),type:r.type}},isnull:z(`isNull`,`bool`,1),isnotnull:z(`isNotNull`,`bool`,1),isnum:qt(e=>w(`in`,w(`type`,e),g([a(`long`),a(`double`)]))),isint:qt(e=>x(`==`,w(`type`,e),a(`long`))),isstr:qt(e=>x(`==`,w(`type`,e),a(`string`))),isbool:qt(e=>x(`==`,w(`type`,e),a(`boolean`))),typeof:(e,t,n)=>{let r=B(e,n);return t.report(`SPL3006`,n.span,{detail:`typeof() returns DQL type names (long, double, string …), not Splunk ones.`}),{e:w(`type`,R(r,t).e),type:`string`}},len:z(`stringLength`,`number`,1),lower:z(`lower`,`string`,1),upper:z(`upper`,`string`,1),trim:(e,t,n)=>{if(e.length!==1)throw new M(`SPL2004`,n.span,`trim() with a character list has no DQL equivalent.`);return{e:w(`trim`,R(e[0],t).e),type:`string`}},ltrim:V,rtrim:V,substr:Zt,replace:(e,t,n)=>{if(e.length!==3)throw H(n,3);let r=R(e[0],t).e,i=U(e[1],n,`the regular expression`),o=U(e[2],n,`the replacement`);if(/\\\d/.test(o))throw new M(`SPL2006`,n.span,`Back-references in the replacement have no DQL equivalent.`);let s=pt(i);if(s!==void 0)return{e:w(`replaceString`,r,a(s),a(o)),type:`string`};let c=dt(i,{});if(!c.ok)throw new M(`SPL2006`,e[1].span,c.reason);return t.report(`SPL3008`,e[1].span),{e:w(`replacePattern`,r,f(tn(c.dpl)),a(o)),type:`string`}},split:z(`splitString`,`array`,2),mvindex:(e,t,n)=>{let r=R(B(e,n),t).e,i=W(e[1]);if(e.length===2){if(i===void 0)throw new M(`SPL2004`,n.span,`mvindex() needs a literal position to be translated.`);return{e:S(r,i),type:`unknown`}}if(e.length!==3)throw H(n,3);let a=W(e[2]);if(i===void 0||a===void 0){t.report(`SPL3007`,n.span);let i=R(e[1],t).e,a=x(`+`,R(e[2],t).e,o(1));return{e:w(`arraySlice`,r,C(`from`,i),C(`to`,a)),type:`array`}}return a===-1?{e:w(`arraySlice`,r,C(`from`,o(i))),type:`array`}:{e:w(`arraySlice`,r,C(`from`,o(i)),C(`to`,o(a+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:w(`arraySize`,R(B(e,n),t).e),type:`number`}),mvjoin:(e,t,n)=>{if(e.length!==2)throw H(n,2);return{e:w(`arrayToString`,R(e[0],t).e,C(`delimiter`,R(e[1],t).e)),type:`string`}},mvappend:(e,t)=>({e:ne(`arrayConcat`,e.map(e=>w(`toArray`,R(e,t).e))),type:`array`}),mvdedup:z(`arrayDistinct`,`array`,1),mvsort:z(`arraySort`,`array`,1),mvfilter:(e,t,n)=>{let r=e[0],i=new Set;if(r&&G(r,i),!r||i.size!==1)throw new M(`SPL2004`,n.span,`mvfilter() can only be translated when the condition uses one field.`);let a=[...i][0],o=t.field(a,n.span),s=R(r,t).e;return{e:w(`arrayRemoveNulls`,w(`iCollectArray`,w(`if`,K(s,o),S(l(o))))),type:`array`}},mvfind:V,mvzip:V,mvrange:V,mvmap:V,tostring:(e,t,n)=>{let r=R(B(e,n),t).e;if(e.length===1)return{e:w(`toString`,r),type:`string`};let i=U(e[1],n,`the format`);if(i===`hex`)return{e:w(`concat`,a(`0x`),w(`numberToHexString`,r)),type:`string`};throw new M(`SPL2004`,n.span,`tostring() with format "${i}" has no DQL equivalent.`)},tonumber:(e,t,n)=>{let r=R(B(e,n),t).e;if(e.length===1)return{e:w(`toDouble`,r),type:`number`,real:!0};if(W(e[1])===16)return{e:w(`hexStringToNumber`,r),type:`number`};if(W(e[1])===10)return{e:w(`toDouble`,r),type:`number`,real:!0};throw new M(`SPL2004`,n.span,`tonumber() only translates for base 10 and 16.`)},round:(e,t,n)=>{let r=R(B(e,n),t).e;if(e.length===1)return{e:w(`round`,r),type:`number`};let i=W(e[1]);if(i!==void 0&&i<0)throw new M(`SPL2004`,n.span,`round() to negative decimals has no DQL equivalent.`);return{e:w(`round`,r,C(`decimals`,R(e[1],t).e)),type:`number`}},floor:z(`floor`,`number`,1),ceil:z(`ceil`,`number`,1),ceiling:z(`ceil`,`number`,1),abs:z(`abs`,`number`,1),sqrt:z(`sqrt`,`number`,1),exp:z(`exp`,`number`,1),pow:z(`power`,`number`,2),ln:z(`log`,`number`,1),log:(e,t,n)=>{let r=R(B(e,n),t).e;return e.length===1?{e:w(`log10`,r),type:`number`}:{e:x(`/`,w(`log`,r),w(`log`,R(e[1],t).e)),type:`number`}},pi:z(`pi`,`number`,0),exact:(e,t,n)=>R(B(e,n),t),sigfig:V,printf:V,max:Jt(`arrayMax`),min:Jt(`arrayMin`),random:()=>({e:w(`toLong`,x(`*`,w(`random`),o(2147483647))),type:`number`}),like:z(`like`,`bool`,2),match:(e,t,n)=>{if(e.length!==2)throw H(n,2);let r=R(e[0],t).e,i=dt(U(e[1],n,`the regular expression`),{forMatch:!0});if(!i.ok)throw new M(`SPL2006`,e[1].span,i.reason);return t.report(`SPL3008`,e[1].span),{e:w(`matchesPattern`,r,f(i.dpl)),type:`bool`}},searchmatch:(e,t,n)=>{let r=e[0];if(r?.t!==`str`)throw new M(`SPL2004`,n.span,`searchmatch() needs a quoted search.`);let i=r.v,a=ze(i,0,i.length);return t.report(`SPL3011`,n.span),a?{e:we(a,t,i,!0),type:`bool`}:{e:s(!0),type:`bool`}},cidrmatch:(e,t,n)=>{if(e.length!==2)throw H(n,2);return{e:w(`ipIn`,R(e[1],t).e,R(e[0],t).e),type:`bool`}},in:(e,t,n)=>{if(e.length<2)throw H(n,2);return{e:w(`in`,R(e[0],t).e,g(e.slice(1).map(e=>R(e,t).e))),type:`bool`}},md5:z(`hashMd5`,`string`,1),sha1:z(`hashSha1`,`string`,1),sha256:z(`hashSha256`,`string`,1),sha512:z(`hashSha512`,`string`,1),urldecode:z(`decodeUrl`,`string`,1),spath:Yt,json_extract:Yt,validate:V,true:()=>({e:s(!0),type:`bool`}),false:()=>({e:s(!1),type:`bool`}),null:()=>({e:c(),type:`unknown`}),now:()=>({e:w(`now`),type:`time`}),time:()=>({e:w(`now`),type:`time`}),relative_time:(e,t,n)=>{if(e.length!==2)throw H(n,2);let r=R(e[0],t),i=U(e[1],n,`the time modifier`);return{e:Qt(r.type===`time`?r.e:w(`timestampFromUnixSeconds`,w(`toLong`,r.e)),i,n),type:`time`}},strftime:(e,t,n)=>{if(e.length!==2)throw H(n,2);let r=R(e[0],t),i=U(e[1],n,`the format`),o=r.type===`time`?r.e:w(`timestampFromUnixSeconds`,w(`toLong`,r.e));if(i===`%s`)return{e:w(`unixSecondsFromTimestamp`,o),type:`number`};let s=It(i);if(!s.ok)throw new M(`SPL2004`,e[1].span,`The format directive ${s.directive} has no DQL equivalent.`);return t.report(`SPL3010`,n.span),{e:w(`formatTimestamp`,o,C(`format`,a(s.format))),type:`string`}},strptime:(e,t,n)=>{if(e.length!==2)throw H(n,2);let r=R(e[0],t).e,i=It(U(e[1],n,`the format`));if(!i.ok)throw new M(`SPL2004`,e[1].span,`The format directive ${i.directive} has no DQL equivalent.`);return t.report(`SPL3010`,n.span),{e:w(`parse`,r,f(`TIMESTAMP('${i.format.replace(/'/g,`\\'`)}'):t`)),type:`time`}}});function qt(e){return(t,n,r)=>{let i=B(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(R(i,n).e),type:`bool`}}}function Jt(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:w(e,ne(`array`,t.map(e=>R(e,n).e))),type:`number`})}function Yt(e,t,n){if(e.length!==2)throw H(n,2);let r=R(e[0],t).e;return{e:w(`jsonPath`,r,a(Xt(U(e[1],n,`the path`)))),type:`unknown`}}function Xt(e){return`$.${e.replace(/\{\}/g,`[*]`).replace(/\{(\d+)\}/g,`[$1]`)}`}function Zt(e,t,n){if(e.length<2||e.length>3)throw H(n,3);let r=R(e[0],t).e,i=W(e[1]),a=e.length===3?W(e[2]):void 0;if(i!==void 0&&(e.length===2||a!==void 0)){if(i<0){if(a===void 0)return{e:w(`substring`,r,C(`from`,o(i))),type:`string`};let e=i+a;return e>=0?{e:w(`substring`,r,C(`from`,o(i))),type:`string`}:{e:w(`substring`,r,C(`from`,o(i)),C(`to`,o(e))),type:`string`}}let e=Math.max(0,i-1);return a===void 0?{e:w(`substring`,r,C(`from`,o(e))),type:`string`}:{e:w(`substring`,r,C(`from`,o(e)),C(`to`,o(e+a))),type:`string`}}t.report(`SPL3007`,n.span);let s=x(`-`,R(e[1],t).e,o(1));return e.length===2?{e:w(`substring`,r,C(`from`,s)),type:`string`}:{e:w(`substring`,r,C(`from`,s),C(`to`,x(`+`,s,R(e[2],t).e))),type:`string`}}function Qt(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 M(`SPL2004`,n.span,`relative_time() with "${t}" cannot be translated.`);let i=e;if(r[1]){let e=N(r[2]||`s`);if(!e)throw new M(`SPL2004`,n.span,`Unknown time unit in "${t}".`);let a=r[1].replace(/^[+-]/,``);i=x(r[1].startsWith(`-`)?`-`:`+`,i,d(`${a}${e}`))}if(r[3]){let e=r[3].toLowerCase(),a=e.startsWith(`w`)?e===`w`||e===`w7`?`w0`:e:N(e);if(!a)throw new M(`SPL2004`,n.span,`Unknown snap unit in "${t}".`);i=ee(i,a)}return i}function $t(e,t){let n=Object.hasOwn(Kt,e.fn)?Kt[e.fn]:void 0;if(!n)throw new M(`SPL2004`,e.fnSpan,`${e.fn}() is not a function the translator knows.`);return n(e.args,t,e)}function en(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 G(e,t){if(e.t===`field`)t.add(e.name);else if(e.t===`call`)for(let n of e.args)G(n,t);else if(e.t===`un`)G(e.e,t);else if(e.t===`bin`)G(e.l,t),G(e.r,t);else if(e.t===`in`){G(e.e,t);for(let n of e.list)G(n,t)}}function K(e,t){return e.k===`field`&&e.name===t?S(e):e.k===`call`?{...e,args:e.args.map(e=>({...e,value:K(e.value,t)}))}:e.k===`un`?{...e,e:K(e.e,t)}:e.k===`bin`?{...e,l:K(e.l,t),r:K(e.r,t)}:e.k===`block`?{...e,items:e.items.map(e=>K(e,t))}:e}function tn(e){return e.startsWith(`DATA? `)?e.slice(6):e}var nn=[{name:`rex`,tier:`T2`,summary:`parse field, "<pattern>" for the convertible regex subset; mode=sed → replaceString/replacePattern.`,lower(e){let t=e.scanner(),n=`_raw`,r=e.span,i=!1,s=1,c;for(;!t.atEnd();){let e=t.option();if(e){let t=e.name.toLowerCase();if(t===`field`)n=e.value,r=e.valueSpan;else if(t===`mode`&&e.value.toLowerCase()===`sed`)i=!0;else if(t===`max_match`&&/^\d{1,6}$/.test(e.value))s=Number(e.value);else throw new M(`SPL2003`,e.span,`rex ${e.name}=${e.value} cannot be translated.`);continue}let a=t.quoted();if(!a||c)throw new M(`SPL1003`,t.here(),`rex needs one quoted regular expression.`);c=a}if(!c)throw new M(`SPL1003`,e.span,`rex needs a quoted regular expression.`);let u=e.field(n,r);if(i){let t=/^s\/((?:\\.|[^/\\])*)\/((?:\\.|[^/\\])*)\/([gi0-9]*)$/.exec(c.value);if(!t)throw new M(`SPL2003`,c.span,`Only s/regex/replacement/ sed expressions can be translated.`);let[,n,r,i]=t;if(/\\\d/.test(r))throw new M(`SPL2006`,c.span,`Back-references in the replacement have no DQL equivalent.`);i.includes(`g`)||e.report(`SPL3008`,c.span,{detail:`Without the g flag sed replaces the first match only; DQL replaces every match.`});let o=r.replace(/\\\//g,`/`),s=pt(n.replace(/\\\//g,`/`));if(s!==void 0){e.emit(T(`fieldsAdd`,_(u,w(`replaceString`,l(u),a(s),a(o)))));return}let d=dt(n.replace(/\\\//g,`/`),{});if(!d.ok)throw new M(`SPL2006`,c.span,d.reason);e.report(`SPL3008`,c.span);let p=d.dpl.startsWith(`DATA? `)?d.dpl.slice(6):d.dpl;e.emit(T(`fieldsAdd`,_(u,w(`replacePattern`,l(u),f(p),a(o)))));return}let d=dt(c.value,s===1?{captures:!0}:{captures:!0,everyMatch:!0});if(!d.ok){for(let t of c.value.matchAll(/\(\?P?<([A-Za-z_][A-Za-z0-9_]*)>/g))e.state.unresolved.add(t[1]);throw new M(`SPL2006`,c.span,d.reason)}if(d.captures.length===0)throw new M(`SPL2003`,c.span,`rex without named groups (?<name>…) extracts nothing.`);if(s!==1){let t=d.captures[0];if(d.captures.length!==1||!t||d.anchoredStart){for(let t of d.captures)e.state.unresolved.add(t.name);throw new M(`SPL2003`,c.span,`rex max_match is only translated for one named group and a pattern without "^".`)}e.report(`SPL3008`,c.span),e.report(`SPL3013`,e.span,{detail:`The matches are returned as an array, not as a Splunk multivalue field.`});let n=w(`parseAll`,l(u),f(d.dpl)),r=e.field(t.name,c.span,!0);e.emit(T(`fieldsAdd`,_(r,s===0?n:w(`arraySlice`,n,C(`from`,o(0)),C(`to`,o(s)))))),e.setType(r,void 0),e.addFields([t.name])}else{e.report(`SPL3008`,c.span),e.emit(T(`parse`,l(u),f(d.dpl)));for(let t of d.captures)e.setType(e.field(t.name,c.span,!0),t.type===`number`?`number`:`string`);e.addFields(d.captures.map(e=>e.name))}}},{name:`spath`,tier:`T2`,summary:`jsonPath() for one path; without a path, parse content as JSON and flatten.`,lower(e){let t=e.scanner(),n=`_raw`,r,i;for(;!t.atEnd();){let e=t.option();if(e){let t=e.name.toLowerCase();if(t===`input`)n=e.value;else if(t===`path`)r=e.value;else if(t===`output`)i=e.value;else throw new M(`SPL2003`,e.span,`spath ${e.name}= cannot be translated.`);continue}let a=t.value();if(!a||r!==void 0)throw new M(`SPL1003`,t.here(),`Unexpected text in spath.`);r=a.value}let o=l(e.field(n,e.span));if(r===void 0){e.report(`SPL3016`,e.span,{detail:`JSON fields get Grail names (json.a.b) instead of Splunk names (a.b{}.c).`}),e.emit(T(`parse`,o,f(`JSON:json`))),e.emit(T(`fieldsFlatten`,l(`json`)));return}r.includes(`{}`)&&e.report(`SPL3013`,e.span,{detail:`An array path returns an array in DQL.`});let s=e.field(i??r,e.span,!0);e.emit(T(`fieldsAdd`,_(s,w(`jsonPath`,o,a(Xt(r)))))),e.addFields([s])}}],q=class extends Error{span;constructor(e,t){super(e),this.span=t}},rn=200,an=2e4;function on(e,t,n){let r=new ln(sn(e,t,n)),i=r.expr();return r.expectEnd(),i}function sn(e,n,r){let i=[],a=n;for(;a<r;){let n=e[a];if(/\s/.test(n)){a++;continue}let o=a;if(n===`"`){let n=t(e,a,r);if(n===-1)throw new q(`A quoted string is not closed.`,{start:a,end:r});i.push({type:`str`,text:de(e.slice(a+1,n)),span:{start:o,end:n+1}}),a=n+1;continue}if(n===`$`){let t=/^\$[A-Za-z_][A-Za-z0-9_.]*(?:\|[A-Za-z]+)?\$/.exec(e.slice(a,Math.min(r,a+200)));if(t){i.push({type:`str`,text:t[0],span:{start:o,end:a+t[0].length}}),a+=t[0].length;continue}}if(n===`'`){let t=e.indexOf(`'`,a+1);if(t===-1||t>=r)throw new q(`A quoted field name is not closed.`,{start:a,end:r});i.push({type:`field`,text:e.slice(a+1,t),span:{start:o,end:t+1}}),a=t+1;continue}if(/[0-9]/.test(n)||n===`.`&&/[0-9]/.test(e[a+1]??``)){let t=/^(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?/.exec(e.slice(a,Math.min(r,a+64))),n=t?t[0].length:1;if(/[A-Za-z_]/.test(e[a+n]??``)){a=cn(e,a,r,i);continue}i.push({type:`num`,text:e.slice(a,a+n),span:{start:o,end:a+n}}),a+=n;continue}if(/[A-Za-z_]/.test(n)){a=cn(e,a,r,i);continue}let s=e.slice(a,a+2);if(s===`==`||s===`!=`||s===`<=`||s===`>=`)i.push({type:`op`,text:s,span:{start:o,end:a+2}}),a+=2;else if(`=<>+-*/%.`.includes(n))i.push({type:`op`,text:n,span:{start:o,end:a+1}}),a++;else if(n===`(`||n===`)`||n===`,`)i.push({type:n,text:n,span:{start:o,end:a+1}}),a++;else throw new q(`Unexpected character "${n}".`,{start:a,end:a+1})}if(i.push({type:`eof`,text:``,span:{start:r,end:r}}),i.length>an)throw new q(`The expression has more than ${an} parts.`,{start:n,end:r});return i}function cn(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 ln=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 q(`${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>rn)throw new q(`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 J(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 M(`SPL1003`,e.here(),`Expected a field name.`);n.push({name:t.value,span:t.span})}return n}function un(e,t){if(e.state.schema.kind!==`events`)return e.state.schema.fields.filter(n=>Pe(t,e.splName(n)))}var dn={name:`table`,tier:`T1`,summary:`fields a, b (wildcards → fieldsKeep "a*").`,lower(e){let t=J(e.scanner());if(t.length===0)throw new M(`SPL1003`,e.span,`table needs at least one field.`);let n=[],r=!1;for(let i of t)if(i.name.includes(`*`)){let t=un(e,i.name);t?P(n,t):r=!0}else n.push(e.field(i.name,i.span));r?(e.report(`SPL2009`,e.span,{detail:`Wildcards keep matching fields, but the column order of table is not reproduced.`}),e.emit(E(`fieldsKeep`,t.map(t=>t.name.includes(`*`)?a(t.name):l(e.field(t.name,t.span))))),e.setTable(n)):(e.emit(E(`fields`,n.map(l))),e.setTable(n))}},fn={name:`fields`,tier:`T1`,summary:`fieldsKeep / fieldsRemove; on raw events timestamp and content are kept, as Splunk keeps _time and _raw.`,lower(e){let t=e.scanner(),n=!1;t.eat(`-`)?n=!0:t.eat(`+`);let r=J(t);if(r.length===0)throw new M(`SPL1003`,e.span,`fields needs at least one field.`);if(n){r.some(e=>e.name.startsWith(`_`)&&e.name.includes(`*`))&&e.report(`SPL2009`,e.span,{detail:`Removing internal fields (_*) has no direct equivalent; they were kept.`});let t=r.filter(e=>!(e.name.startsWith(`_`)&&e.name.includes(`*`)));if(t.length===0)return;if(e.emit(E(`fieldsRemove`,t.map(t=>t.name.includes(`*`)?a(t.name):l(e.field(t.name,t.span))))),e.state.schema.kind!==`events`){let n=new Set(t.map(t=>e.field(t.name,t.span,!0)));e.setTable(e.state.schema.fields.filter(r=>!n.has(r)&&!t.some(t=>t.name.includes(`*`)&&Pe(t.name,e.splName(r)))))}return}let i=[],o=[];for(let t of r){if(t.name.includes(`*`)){i.push(a(t.name));continue}let n=e.field(t.name,t.span);i.push(l(n)),o.push(n)}if(e.state.schema.kind===`events`)for(let e of[`timestamp`,`content`])o.includes(e)||i.push(l(e));e.emit(E(`fieldsKeep`,i)),r.every(e=>!e.name.includes(`*`))&&e.setTable(e.state.schema.kind===`events`?[...o,`timestamp`,`content`]:o)}},pn={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=[],i=0;for(;!t.atEnd();){if(t.eat(`,`))continue;let a=t.fieldName();if(!a||!t.keyword(`as`))throw new M(`SPL1003`,t.here(),`Expected "field AS newname".`);let o=t.fieldName();if(!o)throw new M(`SPL1003`,t.here(),`Expected a new name after AS.`);if(a.value.includes(`*`)||o.value.includes(`*`))throw new M(`SPL2009`,a.span,`Renaming with wildcards needs the list of fields.`);let s=e.field(a.value,a.span),c=e.field(o.value,o.span,!0);s===c?i++:(n.push(_(c,l(s))),r.push([s,c]))}if(!(n.length===0&&i>0)){if(n.length===0)throw new M(`SPL1003`,e.span,`rename needs "field AS newname".`);e.emit(E(`fieldsRename`,n)),e.state.schema.kind!==`events`&&e.setTable(e.state.schema.fields.map(e=>r.find(([t])=>t===e)?.[1]??e))}}};function mn(e){return!e.quoted&&/^-?\d+(\.\d+)?$/.test(e.value)?o(e.value):a(e.value)}var hn={name:`fillnull`,tier:`T1`,summary:`fieldsAdd f = coalesce(f, value).`,lower(e){let t=e.scanner(),n=o(0),r=t.option();if(r){if(r.name.toLowerCase()!==`value`)throw new M(`SPL2003`,r.span,`Option ${r.name} is not supported.`);n=mn(r)}let i=J(t),a=i.map(t=>t.name.includes(`*`)?void 0:e.field(t.name,t.span));if(i.length===0||a.includes(void 0)){let t=e.state.schema.kind===`events`?void 0:e.state.schema.fields;if(!t)throw new M(`SPL2009`,e.span,`fillnull without a field list needs the list of fields.`);a=i.length===0?t:t.filter(t=>i.some(n=>Pe(n.name,e.splName(t))))}let s=a.map(e=>_(e,w(`coalesce`,l(e),n)));s.length>0&&e.emit(E(`fieldsAdd`,s))}},gn=500,_n={name:`replace`,tier:`T1`,summary:`fieldsAdd f = if(f == "x", "y", else: f).`,lower(e){let t=e.scanner(),n=[];for(;!t.peekKeyword(`in`);){if(t.eat(`,`))continue;let e=t.value();if(!e||!t.keyword(`with`))throw new M(`SPL1003`,t.here(),`Expected "value WITH replacement".`);let r=t.value();if(!r)throw new M(`SPL1003`,t.here(),`Expected a replacement after WITH.`);if(e.value.includes(`*`)||r.value.includes(`*`))throw new M(`SPL2009`,e.span,`Wildcard replacements are not supported.`);n.push([e,r])}if(!t.keyword(`in`))throw new M(`SPL2003`,e.span,`replace without IN <fields> needs the list of fields.`);if(n.length>gn)throw new M(`SPL1006`,e.span,`replace has more than ${gn} value pairs; translate it in parts.`);let r=J(t),i=[];for(let t of r){if(t.name.includes(`*`))throw new M(`SPL2009`,t.span,`Wildcard field names need the list of fields.`);let r=e.field(t.name,t.span),o=l(r);for(let e=n.length-1;e>=0;e--){let[t,i]=n[e];o=w(`if`,x(`==`,l(r),a(t.value)),a(i.value),C(`else`,o))}i.push(_(r,o))}e.emit(E(`fieldsAdd`,i))}},vn={name:`convert`,tier:`T2`,summary:`ctime() → formatTimestamp, num()/auto() → toDouble.`,lower(e){let t=e.scanner(),n=`MM/dd/yyyy HH:mm:ss`,r=[];for(;!t.atEnd();){if(t.eat(`,`))continue;let i=t.option();if(i){if(i.name.toLowerCase()!==`timeformat`)throw new M(`SPL2003`,i.span,`Option ${i.name} is not supported.`);let e=It(i.value);if(!e.ok)throw new M(`SPL2003`,i.valueSpan,`The format directive ${e.directive} has no DQL equivalent.`);n=e.format;continue}let o=t.word(`(`),s=t.balanced(`(`,`)`);if(!o||!s)throw new M(`SPL1003`,t.here(),`Expected a conversion such as ctime(field).`);let c=e.slice(s.inner).trim(),u=c;if(t.keyword(`as`)){let e=t.fieldName();if(!e)throw new M(`SPL1003`,t.here(),`Expected a name after AS.`);u=e.value}let d=e.field(c,s.inner),f=l(d),p=e.fieldType(d)===`time`,m=e.field(u,s.inner,!0);switch(o.value.toLowerCase()){case`ctime`:e.report(`SPL3010`,o.span),r.push(_(m,w(`formatTimestamp`,p?f:w(`timestampFromUnixSeconds`,w(`toLong`,f)),C(`format`,a(n))))),e.setType(m,`string`);break;case`num`:case`auto`:r.push(_(m,w(`toDouble`,f))),e.setType(m,`number`);break;case`none`:break;default:throw new M(`SPL2003`,o.span,`convert ${o.value}() has no DQL equivalent.`)}}r.length>0&&e.emit(E(`fieldsAdd`,r))}},yn={name:`addtotals`,tier:`T2`,summary:`fieldsAdd Total = coalesce(a, 0) + coalesce(b, 0) for listed fields.`,lower(e){let t=e.scanner(),n=`Total`;for(let e=t.option();e;e=t.option()){let t=e.name.toLowerCase();if(t===`fieldname`)n=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 M(`SPL2003`,e.span,`addtotals ${e.name}=${e.value} has no DQL equivalent.`)}let r=J(t);if(r.length===0||r.some(e=>e.name.includes(`*`)))throw new M(`SPL2009`,e.span,`addtotals needs an explicit list of fields to sum.`);let i=r.map(t=>w(`coalesce`,l(e.field(t.name,t.span)),o(0))).reduce((e,t)=>e?x(`+`,e,t):t,void 0);e.emit(T(`fieldsAdd`,_(e.field(n,e.span,!0),i))),e.addFields([n])}},bn={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 M(`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 M(`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 M(`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=un(e,t.name);if(!n)throw new M(`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 M(`SPL1006`,e.span,`foreach would write its template ${o.length} times (${o.length*c.length} characters); the limit is ${oe}.`);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 M(`SPL1003`,r.span,`The template must be "field = expression".`);let a=i[1].replace(/^'|'$/g,``),o;try{o=on(n,n.length-i[2].length,n.length)}catch(e){throw e instanceof q?new M(`SPL1004`,r.span,e.message):e}s.push(_(e.field(a,r.span,!0),R(xn(o,r.span),e).e))}e.emit(E(`fieldsAdd`,s))}};function xn(e,t){if(Array.isArray(e))return e.map(e=>xn(e,t));if(e&&typeof e==`object`){let n={};for(let[r,i]of Object.entries(e))n[r]=r===`span`||r===`fnSpan`?t:xn(i,t);return n}return e}var Sn=[dn,fn,pn,hn,_n,vn,yn,bn,{name:`makemv`,tier:`T1`,summary:`fieldsAdd f = splitString(f, delim).`,lower(e){let t=e.scanner(),n=` `;for(let e=t.option();e;e=t.option()){let t=e.name.toLowerCase();if(t===`delim`)n=e.value;else if(t===`allowempty`||t===`setsv`)continue;else throw new M(`SPL2003`,e.span,`makemv ${e.name}= has no DQL equivalent.`)}let r=t.fieldName();if(!r)throw new M(`SPL1003`,e.span,`makemv needs a field.`);let i=e.field(r.value,r.span);e.emit(T(`fieldsAdd`,_(i,w(`splitString`,l(i),a(n)))))}},{name:`mvexpand`,tier:`T1`,summary:`expand f.`,lower(e){let t=e.scanner(),n=t.fieldName();if(!n)throw new M(`SPL1003`,e.span,`mvexpand needs a field.`);let r=t.option(),i=l(e.field(n.value,n.span));if(r&&r.name.toLowerCase()===`limit`&&/^\d+$/.test(r.value))e.emit(T(`expand`,i,C(`limit`,o(r.value))));else if(r)throw new M(`SPL2003`,r.span,`mvexpand ${r.name}= is not supported.`);else e.emit(T(`expand`,i))}},{name:`nomv`,tier:`T1`,summary:`fieldsAdd f = arrayToString(f, delimiter: "\\n").`,lower(e){let t=e.scanner().fieldName();if(!t)throw new M(`SPL1003`,e.span,`nomv needs a field.`);let n=e.field(t.value,t.span);e.emit(T(`fieldsAdd`,_(n,w(`arrayToString`,l(n),C(`delimiter`,a(`
|
|
1
|
+
import{t as e}from"./dict-9ToLi8Te.js";import{T as t}from"./index-Dox0eScg.js";import{a as n,n as r,t as i}from"./jsx-runtime-Wy9s6hX0.js";var a=e=>({k:`str`,v:e}),o=e=>({k:`num`,v:String(e)}),s=e=>({k:`bool`,v:e}),c=()=>({k:`null`}),l=e=>({k:`field`,name:e}),u=e=>({k:`ident`,v:e}),d=e=>({k:`time`,v:e}),f=e=>({k:`dpl`,v:e}),p=e=>({k:`raw`,text:e}),m=(e,t)=>t?{k:`var`,name:e,mod:t}:{k:`var`,name:e},h=e=>({k:`sub`,q:{commands:e}}),g=e=>({k:`block`,items:e}),_=(e,t)=>({k:`assign`,name:e,e:t}),v=(e,t)=>({k:`dir`,e,dir:t}),y=e=>({k:`un`,op:`not`,e}),b=e=>({k:`un`,op:`-`,e}),x=(e,t,n)=>({k:`bin`,op:e,l:t,r:n}),S=(e,t)=>t===void 0?{k:`index`,e}:{k:`index`,e,key:t},ee=(e,t)=>({k:`align`,e,unit:t}),te=e=>({kind:`pos`,value:e}),C=(e,t)=>({kind:`named`,name:e,value:t});function w(e,...t){return{k:`call`,fn:e,args:t.map(re)}}function T(e,...t){return{name:e,args:t.map(re)}}function E(e,t){return{name:e,args:t.map(re)}}function ne(e,t){return{k:`call`,fn:e,args:t.map(re)}}function re(e){return`kind`in e?e:{kind:`pos`,value:e}}function D(e){let t;for(let n of e)t=t?x(`and`,t,n):n;return t}function ie(e){let t;for(let n of e)t=t?x(`or`,t,n):n;return t}function ae(e){return JSON.parse(JSON.stringify(e))}var oe=2e5,O=`error`,k=`warning`,A=`info`;function j(e,t,n,r){return{code:e,severity:t,title:n,hint:r}}var se=[j(`SPL1001`,O,`This part of the search could not be read.`,`Check for an unterminated string or an unbalanced bracket.`),j(`SPL1002`,O,`The search or one of its stages is empty.`,`Remove the empty stage or the extra pipe.`),j(`SPL1003`,O,`The command's arguments could not be read.`,`Compare the stage with Splunk's Search Reference for this command.`),j(`SPL1004`,O,`An expression could not be read.`,`Check operators, parentheses and quotes in the expression.`),j(`SPL1005`,O,`A macro could not be expanded.`,`Check the macro definition in the mapping file for cycles and the number of arguments.`),j(`SPL1006`,O,`The search is too large or too deeply nested to translate.`,`Split the search, or reduce nesting of subsearches and parentheses.`),j(`SPL1007`,O,`The search has no data source DQL can start from.`,`Start the search with an index, a lookup or another generating command.`),j(`SPL1008`,O,`The translator hit an internal problem with this search.`,`Please report the search (with sensitive values removed) so it can be fixed.`),j(`SPL2001`,k,`This command is not known to the translator.`,`If it is a custom command, rewrite this stage by hand.`),j(`SPL2002`,k,`This command has no DQL equivalent.`,`Rewrite this stage by hand; the rest of the query is still translated.`),j(`SPL2003`,k,`An argument or option is not supported.`,`Check whether the option matters for your result.`),j(`SPL2004`,k,`This eval function has no DQL equivalent.`,`Rewrite the expression by hand.`),j(`SPL2005`,k,`This aggregation function has no DQL equivalent.`,`Rewrite the aggregation by hand or remove it.`),j(`SPL2006`,k,`This regular expression cannot be converted to a Dynatrace pattern.`,`Write the parse pattern by hand.`),j(`SPL2007`,k,`This subsearch form cannot be translated.`,`Rewrite the subsearch as a join or a filter by hand.`),j(`SPL2008`,k,`This command writes data or sends something; it was dropped.`,`Recreate the side effect in Dynatrace (workflow, lookup upload) if you still need it.`),j(`SPL2009`,k,`A wildcard field list needs the list of fields, which is not known here.`,`List the fields explicitly.`),j(`SPL2010`,k,`This command depends on the order of result rows, which DQL does not provide.`,`Rewrite this stage by hand.`),j(`SPL2011`,k,`Real-time and index-time modifiers have no DQL equivalent.`,`Use a normal time range.`),j(`SPL2012`,k,`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.`),j(`SPL3001`,k,`Case sensitivity differs from Splunk here.`,`Values that differ only in case will not match.`),j(`SPL3002`,k,`Missing or empty fields are handled differently.`,`Check rows where the field is missing.`),j(`SPL3003`,k,`The result has a different shape than in Splunk.`,`Check how the result is charted or used afterwards.`),j(`SPL3004`,k,`The result depends on record order, which DQL does not guarantee here.`,`Add an explicit sort if order matters.`),j(`SPL3005`,k,`This aggregation may be computed differently (exact or approximate).`,`Expect small numeric differences.`),j(`SPL3006`,k,`Values may be compared as a different type than in Splunk.`,`Declare the field type in the mapping file (fieldTypes).`),j(`SPL3007`,k,`An index position was adjusted from 1-based to 0-based.`,`Check the result for an off-by-one difference.`),j(`SPL3008`,k,`A regular expression was converted to a Dynatrace pattern.`,`Check the extracted values on real data.`),j(`SPL3009`,k,`Splunk applies a default limit here that DQL does not.`,`Add an explicit limit if you relied on it.`),j(`SPL3010`,k,`Time zone or time format handling may differ.`,`Check timestamps in the result.`),j(`SPL3011`,k,`Wildcard or token matching differs from Splunk.`,`Check matches on real data.`),j(`SPL3012`,k,`Part of the query runs twice inside a sub-query.`,`Expect higher query cost; both runs may see slightly different data.`),j(`SPL3013`,k,`Multivalue fields behave differently.`,`Check rows where a field has several values.`),j(`SPL3014`,k,`This command was approximated with a different construct.`,`Check the result carefully.`),j(`SPL3015`,k,`The time range could not be reproduced exactly.`,`Set the time range in Dynatrace.`),j(`SPL3016`,k,`Output field names differ from Splunk.`,`Rename fields if later steps rely on the Splunk names.`),j(`SPL3017`,k,`The generated DQL did not pass the offline syntax check.`,`Check the highlighted line; this may need a manual fix.`),j(`SPL4001`,k,`This index has no entry in the mapping file.`,`Add the index under "indexes" in the mapping file.`),j(`SPL4002`,k,`This sourcetype has no entry in the mapping file.`,`Add the sourcetype under "sourcetypes" in the mapping file.`),j(`SPL4003`,k,`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.`),j(`SPL4004`,k,`This macro has no definition in the mapping file.`,`Copy its definition from macros.conf into "macros".`),j(`SPL4005`,k,`This lookup has no entry in the mapping file.`,`Upload the table to Grail and add it under "lookups".`),j(`SPL4006`,k,`This eventtype, tag or saved search cannot be resolved.`,`Add it under "eventtypes" or "tags" in the mapping file.`),j(`SPL4007`,k,`This metric has no entry in the mapping file.`,`Add it under "metrics" in the mapping file.`),j(`SPL4008`,k,`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.`),j(`SPL4009`,k,`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.`),j(`SPL5001`,A,`The search has no time range; DQL uses the time range chosen in Dynatrace.`,`Add from: to the fetch if the time range matters.`),j(`SPL5002`,A,`Splunk default fields were renamed to their Grail names.`,`No action needed.`),j(`SPL5003`,A,`Rows with an empty group-by field are removed first, as Splunk does.`,`No action needed.`),j(`SPL5004`,A,`A sort by time was added to reproduce Splunk event order.`,`No action needed.`),j(`SPL5005`,A,`A macro was expanded.`,`No action needed.`),j(`SPL5006`,A,`Splunk's default result limit is not reproduced; DQL returns at most 1000 records by default.`,`Add a limit if needed.`),j(`SPL5007`,A,`A display-only command was dropped; it does not change the data.`,`No action needed.`),j(`SPL5008`,A,`This is accurate but can be expensive on large data.`,`Consider an approximate function if exactness does not matter.`)];new Map(se.map(e=>[e.code,e]));function ce(){return se}function le(e,n,r,i,a){let o=0;for(let s=n;s<r;s++){let n=e[s];if(n===`"`){let n=t(e,s,r);if(n===-1)return-1;s=n}else if(n===i)o++;else if(n===a&&(o--,o===0))return s}return-1}function ue(e,n,r,i){let a=0;for(let o=n;o<r;o++){let s=e[o];if(s===`"`){let n=t(e,o,r);if(n===-1)return;o=n}else if(s===`(`||s===`[`)a++;else if(s===`)`||s===`]`)a--;else if(a===0&&/[A-Za-z]/.test(s)&&(o===n||/[\s,)]/.test(e[o-1]))){for(let t of i)if(e.slice(o,o+t.length).toLowerCase()===t&&!/[A-Za-z0-9_]/.test(e[o+t.length]??``))return{pos:o,word:t}}}}function de(e){return e.replace(/\\(["\\])/g,`$1`)}e({_time:`timestamp`,_raw:`content`,host:`host.name`,source:`log.source`,index:`dt.system.bucket`});var M=class extends Error{code;span;constructor(e,t,n){super(n),this.code=e,this.span=t}},fe=e({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`}),pe=e({s:1,m:60,h:3600,d:86400,w:604800});function N(e){return fe[e.toLowerCase()]??(e===`M`?`M`:void 0)}function me(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 fe[n]}function he(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:ye(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=be(t,l);return d===void 0?{kind:`invalid`,detail:`Unknown time zone "${t}".`}:{kind:`absolute`,iso:ye(l-d*6e4),fromText:!0}}return ge(n)}function ge(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=_e(t[1]??``),r=_e(t[3]??``);if(!n||!r)return{kind:`invalid`,detail:`"${e}" uses an unknown time unit.`};let i=``;if(t[2]!==void 0){let e=me(t[2]);if(!e)return{kind:`invalid`,detail:`"@${t[2]}" is not a known snap unit.`};i=`@${e}`}let a=ve(n);if(a===void 0)return{kind:`invalid`,detail:`"${e}" mixes calendar and clock units.`};if(r.length>0){let t=ve(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 _e(e){let t=[];for(let n of e.matchAll(/([+-])(\d+)([A-Za-z]*)/g)){let e=n[3]===``?`s`:N(n[3]??``);if(!e)return;t.push({sign:n[1]===`-`?-1:1,n:Number(n[2]),unit:e})}return t}function ve(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=pe[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 ye(e){return new Date(e).toISOString().replace(/\.000Z$/,`Z`)}function be(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 P(e,t){for(let n of t)e.push(n)}var xe=/^-?\d+(\.\d+)?$/,Se=new Set([`index`,`sourcetype`,`eventtype`,`tag`,`earliest`,`latest`]),Ce=/^_index_(earliest|latest)$/;function we(e,t,n,r=!1,i){return F(e,t,r,i)??s(!0)}function F(e,t,n,r){let i=e=>r??e;switch(e.t){case`and`:return D(e.items.map(e=>F(e,t,n,r)).filter(e=>e!==void 0));case`or`:return ie(e.items.map(e=>F(e,t,n,r)).filter(e=>e!==void 0));case`not`:{let i=F(e.e,t,n,r);return i===void 0?void 0:w(`isFalseOrNull`,i)}case`macro`:return;case`sub`:return t.tc.lowerSubsearchFilter(e,t);case`term`:return Te(e.v,e.quoted,!1,t,i(e.span));case`func`:return e.fn===`CASE`?Te(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.`}),Te(e.v,!0,!1,t,i(e.span)));case`in`:return Ee(e,t,i(e.span));case`cmp`:return De(e,t,i(e.span),i(e.fieldSpan))}}function Te(e,t,n,r,i){if(r.state.schema.kind!==`events`)throw new M(`SPL2003`,i,`A free-text term after a transforming command can only stand on its own in the search.`);!t&&e.includes(`*`)&&r.report(`SPL3011`,i,{detail:`"${e}": wildcard terms match on token boundaries that differ from Splunk's.`});let o=[l(r.field(`_raw`,i)),a(e)];return n?w(`matchesPhrase`,...o,C(`caseSensitive`,s(!0))):w(`matchesPhrase`,...o)}function Ee(e,t,n){let r=t.field(e.field,n),i=t.fieldType(r);return e.values.length>0&&e.values.every(e=>!e.quoted&&xe.test(e.v))&&i!==`string`?(i!==`number`&&t.report(`SPL3006`,n,{subject:`type:${r}`,detail:`"${e.field}" has no declared type; it is compared as a number.`}),w(`in`,l(r),g(e.values.map(e=>o(e.v))))):w(`matchesValue`,l(r),g(e.values.map(e=>a(e.v))))}function De(e,t,n,r){let i=e.field;if(i===`earliest`||i===`latest`||Ce.test(i))throw new M(`SPL2003`,n,`A time modifier can only be translated as a top-level term of the first search.`);if(i===`sourcetype`||i===`eventtype`||i===`tag`)return Oe(e,t,n);if(i===`index`&&t.first){t.report(`SPL3014`,n,{detail:`An index inside OR/NOT is translated as a bucket comparison.`});let r=t.mapping.indexes.get(e.value)?.buckets[0]??e.value,i=x(`==`,l(`dt.system.bucket`),a(r));return e.op===`!=`?y(i):i}let s=t.field(i,r),c=t.fieldType(s),u=e.value,d=!e.quoted&&xe.test(u),f=()=>{c===void 0&&t.report(`SPL3006`,r,{subject:`type:${s}`,detail:`"${i}" has no declared type; it is compared as a ${d?`number`:`text`}.`})};switch(e.op){case`=`:case`!=`:{let r;return u===`*`&&!e.quoted?e.op===`!=`?(t.report(`SPL3002`,n,{detail:`${i}!=* is translated as "field is missing".`}),w(`isNull`,l(s))):w(`isNotNull`,l(s)):d&&c!==`string`?(c!==`number`&&f(),r=x(e.op===`=`?`==`:`!=`,l(s),o(u)),r):(/.\*./.test(u)&&t.report(`SPL3011`,n,{detail:`"${u}": a wildcard in the middle of a value may match differently.`}),r=w(`matchesValue`,l(s),a(u)),e.op===`!=`?y(r):r)}default:return f(),x(e.op,l(s),d?o(u):a(u))}}function Oe(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===`!=`?y(p(i)):p(i)}function ke(e){return e?e.t===`and`?e.items:[e]:[]}function Ae(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=D(n);i&&e.emit(T(`filter`,i));for(let t of r)e.emit(T(`filterOut`,t))}function je(e,t,n){let r=e.mapping,i=[],o=[],s=[],c,l;for(let a of ke(t))if(!n&&a.t===`cmp`&&a.field===`index`&&a.op===`=`)o.push(a);else if(!n&&a.t===`or`&&a.items.length>0&&a.items.every(e=>e.t===`cmp`&&e.field===`index`&&e.op===`=`))P(o,a.items);else if(a.t===`cmp`&&(a.field===`earliest`||a.field===`latest`)&&a.op===`=`){if(e.tc.options.tokens&&/^\$[A-Za-z_][A-Za-z0-9_.]*\$$/.test(a.value))continue;let t=he(a.value,r.defaults.timezone);a.field===`earliest`?c={value:t,span:a.span}:l={value:t,span:a.span}}else if(a.t===`cmp`&&Ce.test(a.field))e.report(`SPL2011`,a.span,{detail:`${a.field} (index time) has no DQL equivalent and was left out.`});else if(a.t===`cmp`&&Se.has(a.field)&&a.op===`=`&&a.field!==`index`){let t=Oe(a,e,a.span);t&&s.push(t)}else i.push(a);let d=r.defaults.dataObject,f=[];if(n)d=n.dataObject,f=[...n.buckets],n.filter!==void 0&&s.unshift(p(n.filter));else if(o.length===0)e.report(`SPL4001`,e.span,{subject:`(none)`,detail:`The search names no index; Splunk would search your default indexes, DQL reads all records of this type.`});else{let t=new Set,n=!1,i=!1;for(let a of o){if(a.value===`*`){i=!0;continue}let c=Ne(r.indexes,a.value);c?(t.add(c.dataObject),P(f,c.buckets),c.filter!==void 0&&o.length===1&&s.unshift(p(c.filter))):(n=!0,e.report(`SPL4001`,a.span,{subject:a.value,detail:`Index "${a.value}" has no entry in the mapping file, so all records are read.`}))}if(t.size>1)throw new M(`SPL2003`,e.span,`These indexes map to different Grail data objects; split the search.`);t.size===1&&(d=[...t][0]),(n||i)&&(f=[])}let m=[te(u(d))];f.length>0&&m.push(C(`bucket`,g([...new Set(f)].map(a))));let h=e.tc.options.timeRange,_=r.defaults.timezone;!c&&h?.earliest!==void 0&&(c={value:he(h.earliest,_),span:e.span}),!l&&h?.latest!==void 0&&(l={value:he(h.latest,_),span:e.span}),!c&&r.defaults.timeframe!==void 0&&(c={value:he(r.defaults.timeframe,_),span:e.span});let v=c?Fe(e,`earliest`,c.value,c.span):void 0,y=l?Fe(e,`latest`,l.value,l.span):void 0;v&&m.push(C(`from`,v)),y&&m.push(C(`to`,y)),c||e.tc.diags.reportOnce(`SPL5001`,e.span,e.index),e.emit({name:`fetch`,args:m});let b=[...s];for(let t of i){let n=F(t,e,!1,void 0);n&&b.push(n)}Ae(e,b)}function Me(e,t){if(!t)return;let n=[],r=[];for(let i of ke(t)){if(e.state.schema.kind!==`events`&&i.t===`term`){r.push(i.v),e.report(`SPL3011`,i.span,{detail:`A free-text term after a transforming command is matched against all fields with the DQL search command.`});continue}if(i.t===`cmp`&&(i.field===`earliest`||i.field===`latest`)){e.report(`SPL2003`,i.span,{detail:`A time modifier in a later search stage has no DQL equivalent and was left out.`});continue}let t=F(i,e,!1,void 0);t&&n.push(t)}Ae(e,n);for(let t of r)e.emit(T(`search`,a(t)))}function Ne(e,t){let n=e.get(t);if(n)return n;let r;for(let[n,i]of e)n.includes(`*`)&&Pe(n,t)&&(!r||n.length>r.len)&&(r={len:n.length,value:i});return r?.value}function Pe(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 Fe(e,t,n,r){switch(n.kind){case`now`:return;case`all`:t===`earliest`&&e.report(`SPL3015`,r,{detail:`"All time" has no DQL equivalent; choose the time range in Dynatrace.`});return;case`realtime`:e.report(`SPL2011`,r,{detail:`Real-time searches have no DQL equivalent; the time modifier was left out.`});return;case`invalid`:e.report(`SPL3015`,r,{detail:n.detail});return;case`absolute`:return n.fromText&&e.report(`SPL3010`,r,{detail:`The date was converted to UTC using the time zone "${e.mapping.defaults.timezone}".`}),a(n.iso);case`relative`:return n.exact||e.report(`SPL3015`,r,{detail:`An offset after the snap unit was kept as an expression; check that Dynatrace accepts it.`}),d(n.dql)}}var I=class extends Error{span;constructor(e,t){super(e),this.span=t}},Ie=200,Le=2e4,Re=/^[A-Za-z_][A-Za-z0-9_.:{}@-]*$/;function ze(e,t,n){let r=new He(Be(e,t,n));if(r.atEnd())return;let i=r.andExpr();return r.expectEnd(),i}function Be(e,n,r){let i=[],a=n;for(;a<r;){let n=e[a];if(/\s/.test(n)){a++;continue}if(n==="`"&&e.startsWith("```",a)){let t=e.indexOf("```",a+3);a=t===-1||t+3>r?r:t+3;continue}if(n===`(`||n===`)`){i.push({type:n,span:{start:a,end:a+1}}),a++;continue}if(n===`[`){let t=le(e,a,r,`[`,`]`);if(t===-1)throw new I(`A subsearch "[" is not closed.`,{start:a,end:r});i.push({type:`sub`,inner:{start:a+1,end:t},span:{start:a,end:t+1}}),a=t+1;continue}if(n===`]`)throw new I(`Unexpected "]".`,{start:a,end:a+1});if(n==="`"){let t=e.indexOf("`",a+1),n=t===-1||t>=r?r:t+1;i.push({type:`macro`,span:{start:a,end:n}}),a=n;continue}if(n===`"`){let n=t(e,a,r);if(n===-1)throw new I(`A quoted string is not closed.`,{start:a,end:r});i.push({type:`word`,text:de(e.slice(a+1,n)),quoted:!0,span:{start:a,end:n+1}}),a=n+1;continue}let o=a;for(;a<r;){let n=e[a];if(/[\s()[\]]/.test(n))break;if(n===`"`){let n=t(e,a,r);if(n===-1)throw new I(`A quoted string is not closed.`,{start:a,end:r});a=n+1}else a++}if(a===o)throw new I(`Unexpected "${n}".`,{start:a,end:a+1});i.push({type:`word`,text:e.slice(o,a),quoted:!1,span:{start:o,end:a}})}if(i.push({type:`eof`,span:{start:r,end:r}}),i.length>Le)throw new I(`The search has more than ${Le} terms.`,{start:n,end:r});return i}function Ve(e){let n=[],r=0;for(;r<e.length;){if(e[r]===`,`){r++;continue}if(e[r]===`"`){let i=t(e,r,e.length),a=i===-1?e.length:i;n.push({v:de(e.slice(r+1,a)),quoted:!0}),r=a+1;continue}let i=e.indexOf(`,`,r),a=i===-1?e.length:i,o=e.slice(r,a).trim();o!==``&&n.push({v:o,quoted:!1}),r=a}return n}var He=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 I(`Unexpected ")".`,this.t.span);if(this.t.type!==`eof`)throw new I(`Unexpected text in the search.`,this.t.span)}enter(){if(++this.depth>Ie)throw new I(`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:We(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:We(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 I(`Empty parentheses.`,this.t.span);let e=this.andExpr();if(this.ty()!==`)`)throw new I(`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 I(`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 I(`"${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(Re.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 I(`Expected a value in the IN list.`,e.span);this.i++,e.quoted?t.push({v:e.text,quoted:!0}):P(t,Ve(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=Ue(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=de(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(Re.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=de(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 Ue(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 We(e){return{start:e[0]?.span.start??0,end:e[e.length-1]?.span.end??0}}function Ge(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/${Ke(t)} is used.`}),{path:`/lookups/${Ke(t)}`})}function Ke(e){return e.replace(/\.csv$/i,``).replace(/[^A-Za-z0-9_.-]/g,`_`)||`lookup`}var qe=e=>T(`load`,a(e)),Je={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 M(`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 M(`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 M(`SPL1003`,e.span,`lookup needs a field to match on.`);let i=[],a=t.keyword(`outputnew`);if(a||t.keyword(`output`))for(;!t.atEnd();){if(t.eat(`,`))continue;let e=t.fieldName();if(!e)throw new M(`SPL1003`,t.here(),`Expected an output field.`);let n=e.value;t.keyword(`as`)&&(n=t.fieldName()?.value??n),i.push({col:e.value,as:n})}let o=Ge(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,l(e.field(t.local,t.span)))),n=i.length>0?[C(`fields`,g(i.map(e=>e.as===e.col?l(e.col):_(e.as,l(e.col)))))]:[];e.emit(T(`join`,h([{...qe(o.path),origin:[e.index]}]),C(`on`,g(t)),C(`kind`,u(`leftOuter`)),...n)),i.length===0&&e.report(`SPL3016`,e.span,{detail:`Lookup columns arrive with the prefix "right.".`});for(let t of i)e.field(t.as,e.span,!0);return}let s=r[0],c=[C(`sourceField`,l(e.field(s.local,s.span))),C(`lookupField`,l(o.key??s.lookupField))],d=i;d.length===0&&(o.columns?d=o.columns.filter(e=>e!==(o.key??s.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 f=e=>`_new_${e.replace(/[^A-Za-z0-9_]/g,`_`)}`;d.length>0&&c.push(C(`fields`,g(d.map(e=>a?_(f(e.as),l(e.col)):e.as===e.col?l(e.col):_(e.as,l(e.col)))))),e.emit({name:`lookup`,args:[{kind:`pos`,value:h([{...qe(o.path),origin:[e.index]}])},...c]}),a&&d.length>0&&(e.emit(T(`fieldsAdd`,...d.map(e=>_(e.as,w(`coalesce`,l(e.as),l(f(e.as))))))),e.emit(T(`fieldsRemove`,...d.map(e=>l(f(e.as))))));for(let t of d)e.field(t.as,e.span,!0);e.addFields(d.map(e=>e.as))}},Ye={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 M(`SPL2003`,e.span,`inputlookup ${e.name}= cannot be translated.`);let r=t.word();if(!r)throw new M(`SPL1003`,e.span,`inputlookup needs a table name.`);let i=Ge(e,r.value,r.span),a;if(t.keyword(`where`)){let n=t.rest();try{a=ze(e.tc.text,n.start,n.end)}catch(e){throw e instanceof I?new M(`SPL1001`,e.span,e.message):e}}else if(!t.atEnd())throw new M(`SPL1003`,t.here(),`Unexpected text in inputlookup.`);if(n){if(a)throw new M(`SPL2003`,e.span,`inputlookup append=t with where cannot be translated.`);e.emit(T(`append`,h([{...qe(i.path),origin:[e.index]}])))}else e.emit(qe(i.path)),e.setTable(i.columns?[...i.columns]:[]),e.state.schema={kind:`table`,fields:i.columns?[...i.columns]:[]},a&&Me(e,a)}};function Xe(e,t){let n=e.tc.lowerSub(t.inner,e);if(n.incomplete)throw new M(`SPL2007`,t.span,`The subsearch contains a step that could not be translated.`);return n}var Ze={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 M(`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 M(`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 M(`SPL1003`,t.here(),`Expected join fields.`);r.push({name:a.value,span:a.span})}let i=t.balanced(`[`,`]`);if(!i)throw new M(`SPL1003`,e.span,`join needs a subsearch in [ … ].`);if(r.length===0)throw new M(`SPL2003`,e.span,`join without fields cannot be translated.`);let a=r.map(t=>e.field(t.name,t.span)),o=Xe(e,i);e.report(`SPL3009`,e.span,{detail:`Splunk join keeps one matching row by default (max=1); DQL keeps every match.`});let s=[{kind:`pos`,value:h(o.commands)},C(`on`,g(a.map(l))),C(`kind`,u(n))],c=o.outputFields?.filter(e=>!a.includes(e));if(c&&c.length>0){s.push(C(`fields`,g(c.map(l))));for(let t of c)e.field(t,e.span,!0);e.addFields(c)}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:s})}},Qe={name:`append`,tier:`T1`,summary:`append [sub].`,lower(e){let t=e.scanner();for(;t.option(););let n=t.balanced(`[`,`]`);if(!n)throw new M(`SPL1003`,e.span,`append needs a subsearch in [ … ].`);let r=Xe(e,n);e.emit(T(`append`,h(r.commands))),r.outputFields&&e.addFields(r.outputFields)}};function $e(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 M(`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=>Xe(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(T(`append`,h(e)))}}}var et=[Je,Ye,Ze,Qe,$e(`union`),$e(`multisearch`)],tt=1e4,nt=`The regular expression would give a Dynatrace pattern longer than ${tt} characters.`;function rt(e,t){if(e.budget.left-=t,e.budget.left<0)throw new L(nt)}var L=class extends Error{},it=e({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.`}),at=e({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}}),ot=e({d:`0-9`,w:`a-zA-Z0-9_`,s:` \\t\\r\\n`,t:`\\t`,n:`\\n`,r:`\\r`}),st=`[a-zA-Z0-9_]`,ct=4e3,lt=8,ut=`The regular expression is too large once its repeated groups are written out.`;function dt(e,t={}){if(e.length>ct)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:tt}},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 L(`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(`$`)&&!mt(n)&&(o=!0,n=n.slice(0,-1));let s=Pt(n),c;if(s.length>1){if(a||o)throw new L(`"^" or "$" together with alternatives (a|b) is not supported.`);c=[{k:`alts`,options:s.map(e=>ht(e,r,1)),quant:``}]}else c=ht(n,r,0);if(o&&c.push({k:`eos`}),ft(c)>2e3)throw new L(ut);let l=[],u=vt(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 L(nt);return{ok:!0,dpl:d,captures:l,anchoredStart:a}}catch(e){return e instanceof L?{ok:!1,reason:e.message}:{ok:!1,reason:`The regular expression could not be converted.`}}}function ft(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 pt(e){if(!/[\\^$.|?*+()[\]{}]/.test(e.replace(/\\[./\-:=@#,"' ]/g,``)))return e.replace(/\\([./\-:=@#,"' ])/g,`$1`)}function mt(e){let t=0;for(let n=e.length-2;n>=0&&e[n]===`\\`;n--)t++;return t%2==1}function ht(e,t,n){if(n>20)throw new L(`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(),jt(n);let s=o?`[${e.toLowerCase()}${e.toUpperCase()}]`:`[${Ot(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 L(`The regular expression ends with a backslash.`);if(/[1-9]/.test(t))throw new L(`Back-references have no Dynatrace pattern equivalent.`);if(t===`b`){a(),r.push({k:`boundary`}),c+=2;continue}let n=it[t];if(n)throw new L(n);let i=At(e,c+2,s),l=at[t];if(l){a(),jt(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 L(`The escape \\${t} is not supported.`);else o(t,i);c+=2+i.length;continue}if(l===`[`){let n=Mt(e,c,s),i=At(e,n+1,s);a(),jt(i),r.push({k:`class`,text:kt(e.slice(c,n+1),t.ci),quant:i}),c=n+1+i.length;continue}if(l===`.`){let t=At(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 L(`A single "." (any character) is only supported as ".*" or ".+".`);c+=1+t.length;continue}if(l===`(`){a();let i=Nt(e,c,s),o=At(e,i+1,s);for(let a of _t(e.slice(c+1,i),o,t,n))r.push(a);c=i+1+o.length;continue}if(l===`|`)throw new L(`Alternatives must stand alone in the pattern or inside a group.`);if(l===`^`||l===`$`)throw new L(`"${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 L(`A quantifier must follow something to repeat.`)}if(l===`)`||l===`]`)throw new L(`Unbalanced "${l}".`);let u=At(e,c+1,s);o(l,u),c+=1+u.length}return a(),r}function gt(e,t,n){let r=Pt(e);return r.length===1?ht(e,t,n+1):[{k:`alts`,options:r.map(e=>ht(e,t,n+1)),quant:``}]}function _t(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 L(`A look-around cannot be repeated.`);let i=gt(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 L(`Inline flags are only supported as (?i) or (?s) at the start of the pattern.`);else throw new L(`This group type is not supported.`)}if(a!==void 0&&n.captures){if(t!==``&&t!==`?`)throw new L(`A repeated capture group is not supported.`);if(/\(\?(?:P?<[A-Za-z_]|')/.test(i))throw new L(`Nested capture groups are not supported.`);return[{k:`capture`,name:a,inner:i,items:gt(i,n,r),optional:t===`?`}]}let o=gt(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>lt)throw new L(`A repeated group cannot be converted, except for a fixed count such as (…){3}.`);if(ft(o)*l>2e3)throw new L(ut);let u=[];for(let e=0;e<l;e++)for(let e of o)u.push(e);return u}function vt(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:Tt(c),end:!1};switch(rt(n,1+yt(a)),a.k){case`lit`:i.push(Dt(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 L(`".*" must be followed by fixed text to be converted.`);i.push(n.dotAll?`DATA`:`LD`);break;case`alts`:i.push(`${xt(a.options,t,n)}${a.quant}`);break;case`group`:i.push(`(${bt(a.items,t,n,a.quant===``?l:{fixed:!1,end:!1})})${a.quant}`);break;case`capture`:i.push(wt(a,t,n,l));break;case`look`:{let e=vt(a.items,t,n,{fixed:!1,end:!1});if(e.length===0)throw new L(`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(St(e[o-1],c));break;case`eos`:i.push(`EOS`)}}),i}function yt(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 bt(e,t,n,r){let i=vt(e,t,n,r);if(i.length===0)throw new L(`An empty group cannot be converted.`);return i.join(` `)}function xt(e,t,n){return`(${e.map(e=>{let r=vt(e,t,n,{fixed:!1,end:!1});if(r.length===0)throw new L(`An empty alternative (a|) cannot be converted.`);return r.length===1?r[0]:`(${r.join(` `)})`}).join(` | `)})`}function St(e,t){let n=Ct(t,!0),r=Ct(e,!1);if(n===!0&&r!==!0)return`!<<${st}`;if(r===!0&&n!==!0)return`!>>${st}`;throw new L(`A word boundary (\\b) is only supported directly before or after a word.`)}function Ct(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 wt(e,t,n,r){let i=Et(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 L(`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`${xt(c.options,t,n)}${o}:${i}`;if(e.items.some(e=>e.k===`any`)&&e.items[e.items.length-1]?.k!==`any`)throw new L(`The capture "${e.name}" has ".*" in the middle, which cannot be converted.`);return`(${bt(e.items,t,n,e.optional?{fixed:!1,end:!1}:r)})${o}:${i}`}function Tt(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===``&&Tt(e.items[0]):e.k===`capture`?!e.optional&&!/^\.[*]/.test(e.inner)&&(e.items.length===0||Tt(e.items[0])):e.k===`look`?e.ahead&&!e.negative:e.k===`eos`:!1}function Et(e){return/^[A-Za-z][A-Za-z0-9]*$/.test(e)?e:`'${e}'`}function Dt(e){return`'${e.replace(/\\/g,`\\\\`).replace(/'/g,`\\'`)}'`}function Ot(e){return/[\]\\^-]/.test(e)?`\\${e}`:e}function kt(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=ot[t];if(i!==void 0){r+=i;continue}if(/[A-Za-z0-9]/.test(t))throw new L(`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 At(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 L(`Possessive quantifiers are not supported.`);return i[0]}function jt(e){if(e.endsWith(`?`)&&e.length>1)throw new L(`Lazy quantifiers are only supported on ".".`)}function Mt(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 L(`POSIX character classes ([:alpha:]) are not supported.`):new L(`Nested character classes are not supported.`);if(e[r]===`]`)return r}throw new L(`A character class "[" is not closed.`)}function Nt(e,t,n){let r=0;for(let i=t;i<n;i++){let t=e[i];if(t===`\\`)i++;else if(t===`[`)i=Mt(e,i,n);else if(t===`(`&&r++,t===`)`&&(r--,r===0))return i}throw new L(`A group "(" is not closed.`)}function Pt(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}var Ft=e({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 It(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:Ft[o];if(!s)return{ok:!1,directive:`%${o??``}`};r(),t+=s,i++}return r(),{ok:!0,format:t}}var Lt=e({date_hour:`getHour`,date_minute:`getMinute`,date_mday:`getDayOfMonth`,date_month:`getMonth`,date_year:`getYear`,date_wday:`getDayOfWeek`});function R(e,t){switch(e.t){case`str`:return{e:a(e.v),type:`string`};case`num`:return{e:o(Wt(e.v)),type:`number`,real:/[.eE]/.test(e.v)};case`field`:return Rt(e.name,e.span,t);case`un`:{let n=R(e.e,t);return e.op===`NOT`?{e:y(n.e),type:`bool`}:{e:b(n.e),type:n.type}}case`in`:return{e:w(`in`,R(e.e,t).e,g(e.list.map(e=>R(e,t).e))),type:`bool`};case`bin`:return zt(e,t);case`call`:return $t(e,t)}}function Rt(e,t,n){let r=Lt[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:w(r,l(`timestamp`)),type:`number`};let i=n.field(e,t),a=n.fieldType(i);return{e:l(i),type:a===`time`?`time`:a===`number`?`number`:a===`string`?`string`:`unknown`}}function zt(e,t){let n=R(e.l,t),r=R(e.r,t);switch(e.op){case`AND`:return{e:x(`and`,n.e,r.e),type:`bool`};case`OR`:return{e:x(`or`,n.e,r.e),type:`bool`};case`XOR`:return{e:x(`xor`,n.e,r.e),type:`bool`};case`LIKE`:return{e:w(`like`,n.e,r.e),type:`bool`};case`.`:return{e:Gt(n.e,r.e),type:`string`};case`=`:case`==`:case`!=`:case`<`:case`<=`:case`>`:case`>=`:{let i=e.op===`=`?`==`:e.op;return 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.`}),{e:x(i,n.type===`time`?w(`unixSecondsFromTimestamp`,n.e):n.e,r.type===`time`?w(`unixSecondsFromTimestamp`,r.e):r.e),type:`bool`}):(Ht(t,e.l,n,r),Ht(t,e.r,r,n),{e:x(i,n.e,r.e),type:`bool`})}case`+`:return n.type===`string`&&r.type===`string`?{e:Gt(n.e,r.e),type:`string`}:Ut(`+`,n,r);case`-`:return n.type===`time`&&r.type===`time`?{e:x(`/`,x(`-`,n.e,r.e),d(`1s`)),type:`number`,real:!0}:Ut(`-`,n,r);case`*`:case`/`:case`%`:{let t=Bt(n),i=Bt(r);return e.op===`/`?{e:Vt(t,i),type:`number`,real:!0}:{e:x(e.op,t.e,i.e),type:`number`,real:(t.real??!1)||(i.real??!1)}}}}function Bt(e){return e.type===`time`?{e:w(`unixSecondsFromTimestamp`,e.e),type:`number`}:e}function Vt(e,t){return e.real||t.real?x(`/`,e.e,t.e):t.e.k===`num`&&/^\d+$/.test(t.e.v)?x(`/`,e.e,o(`${t.e.v}.0`)):e.e.k===`num`&&/^\d+$/.test(e.e.v)?x(`/`,o(`${e.e.v}.0`),t.e):x(`/`,w(`toDouble`,e.e),t.e)}function Ht(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 Ut(e,t,n){return t.type===`time`&&(n.type===`number`||n.type===`unknown`)?n.e.k===`num`&&/^\d+$/.test(n.e.v)?{e:x(e,t.e,d(`${n.e.v}s`)),type:`time`}:{e:x(e,t.e,x(`*`,n.e,d(`1s`))),type:`time`}:{e:x(e,t.e,n.e),type:t.type===`number`&&n.type===`number`?`number`:`unknown`,real:(t.real??!1)||(n.real??!1)}}function Wt(e){return e.replace(/^(-?)\./,`$10.`).replace(/\.(?=$|[eE])/,`.0`)}function Gt(e,t){let n=e=>e.k===`call`&&e.fn===`concat`?e.args.map(e=>e.value):[e];return w(`concat`,...n(e),...n(t))}var z=(e,t=`unknown`,n)=>(r,i,a)=>{if(n!==void 0&&r.length!==n)throw H(a,n);return{e:w(e,...r.map(e=>R(e,i).e)),type:t}};function B(e,t){let n=e[0];if(n===void 0)throw new M(`SPL1004`,t.span,`${t.fn}() expects at least 1 argument.`);return n}var V=(e,t,n)=>{throw new M(`SPL2004`,n.fnSpan,`${n.fn}() has no DQL equivalent.`)};function H(e,t){return new M(`SPL1004`,e.span,`${e.fn}() expects ${t} argument${t===1?``:`s`}.`)}function U(e,t,n){if(e?.t!==`str`)throw new M(`SPL2004`,t.span,`${t.fn}() needs ${n} as a quoted literal to be translated.`);return e.v}function W(e){if(e?.t===`num`&&/^-?\d+$/.test(e.v))return Number(e.v)}var Kt=e({if:(e,t,n)=>{if(e.length!==3)throw H(n,3);let[r,i,a]=e.map(e=>R(e,t));return{e:w(`if`,r.e,i.e,C(`else`,a.e)),type:i.type}},case:(e,t,n)=>{if(e.length<2||e.length%2!=0)throw new M(`SPL1004`,n.span,`case() needs condition/value pairs.`);let r=[];for(let t=0;t<e.length;t+=2)r.push([e[t],e[t+1]]);let i,a=r[r.length-1];a&&en(a[0])&&(i=R(a[1],t).e,r.pop());let o=i;for(let e=r.length-1;e>=0;e--){let[n,i]=r[e],a=R(n,t).e,s=R(i,t).e;o=o===void 0?w(`if`,a,s):w(`if`,a,s,C(`else`,o))}return{e:o??c(),type:`unknown`}},coalesce:z(`coalesce`),nullif:(e,t,n)=>{if(e.length!==2)throw H(n,2);let r=R(e[0],t),i=R(e[1],t);return{e:w(`if`,x(`==`,r.e,i.e),c(),C(`else`,r.e)),type:r.type}},isnull:z(`isNull`,`bool`,1),isnotnull:z(`isNotNull`,`bool`,1),isnum:qt(e=>w(`in`,w(`type`,e),g([a(`long`),a(`double`)]))),isint:qt(e=>x(`==`,w(`type`,e),a(`long`))),isstr:qt(e=>x(`==`,w(`type`,e),a(`string`))),isbool:qt(e=>x(`==`,w(`type`,e),a(`boolean`))),typeof:(e,t,n)=>{let r=B(e,n);return t.report(`SPL3006`,n.span,{detail:`typeof() returns DQL type names (long, double, string …), not Splunk ones.`}),{e:w(`type`,R(r,t).e),type:`string`}},len:z(`stringLength`,`number`,1),lower:z(`lower`,`string`,1),upper:z(`upper`,`string`,1),trim:(e,t,n)=>{if(e.length!==1)throw new M(`SPL2004`,n.span,`trim() with a character list has no DQL equivalent.`);return{e:w(`trim`,R(e[0],t).e),type:`string`}},ltrim:V,rtrim:V,substr:Zt,replace:(e,t,n)=>{if(e.length!==3)throw H(n,3);let r=R(e[0],t).e,i=U(e[1],n,`the regular expression`),o=U(e[2],n,`the replacement`);if(/\\\d/.test(o))throw new M(`SPL2006`,n.span,`Back-references in the replacement have no DQL equivalent.`);let s=pt(i);if(s!==void 0)return{e:w(`replaceString`,r,a(s),a(o)),type:`string`};let c=dt(i,{});if(!c.ok)throw new M(`SPL2006`,e[1].span,c.reason);return t.report(`SPL3008`,e[1].span),{e:w(`replacePattern`,r,f(tn(c.dpl)),a(o)),type:`string`}},split:z(`splitString`,`array`,2),mvindex:(e,t,n)=>{let r=R(B(e,n),t).e,i=W(e[1]);if(e.length===2){if(i===void 0)throw new M(`SPL2004`,n.span,`mvindex() needs a literal position to be translated.`);return{e:S(r,i),type:`unknown`}}if(e.length!==3)throw H(n,3);let a=W(e[2]);if(i===void 0||a===void 0){t.report(`SPL3007`,n.span);let i=R(e[1],t).e,a=x(`+`,R(e[2],t).e,o(1));return{e:w(`arraySlice`,r,C(`from`,i),C(`to`,a)),type:`array`}}return a===-1?{e:w(`arraySlice`,r,C(`from`,o(i))),type:`array`}:{e:w(`arraySlice`,r,C(`from`,o(i)),C(`to`,o(a+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:w(`arraySize`,R(B(e,n),t).e),type:`number`}),mvjoin:(e,t,n)=>{if(e.length!==2)throw H(n,2);return{e:w(`arrayToString`,R(e[0],t).e,C(`delimiter`,R(e[1],t).e)),type:`string`}},mvappend:(e,t)=>({e:ne(`arrayConcat`,e.map(e=>w(`toArray`,R(e,t).e))),type:`array`}),mvdedup:z(`arrayDistinct`,`array`,1),mvsort:z(`arraySort`,`array`,1),mvfilter:(e,t,n)=>{let r=e[0],i=new Set;if(r&&G(r,i),!r||i.size!==1)throw new M(`SPL2004`,n.span,`mvfilter() can only be translated when the condition uses one field.`);let a=[...i][0],o=t.field(a,n.span),s=R(r,t).e;return{e:w(`arrayRemoveNulls`,w(`iCollectArray`,w(`if`,K(s,o),S(l(o))))),type:`array`}},mvfind:V,mvzip:V,mvrange:V,mvmap:V,tostring:(e,t,n)=>{let r=R(B(e,n),t).e;if(e.length===1)return{e:w(`toString`,r),type:`string`};let i=U(e[1],n,`the format`);if(i===`hex`)return{e:w(`concat`,a(`0x`),w(`numberToHexString`,r)),type:`string`};throw new M(`SPL2004`,n.span,`tostring() with format "${i}" has no DQL equivalent.`)},tonumber:(e,t,n)=>{let r=R(B(e,n),t).e;if(e.length===1)return{e:w(`toDouble`,r),type:`number`,real:!0};if(W(e[1])===16)return{e:w(`hexStringToNumber`,r),type:`number`};if(W(e[1])===10)return{e:w(`toDouble`,r),type:`number`,real:!0};throw new M(`SPL2004`,n.span,`tonumber() only translates for base 10 and 16.`)},round:(e,t,n)=>{let r=R(B(e,n),t).e;if(e.length===1)return{e:w(`round`,r),type:`number`};let i=W(e[1]);if(i!==void 0&&i<0)throw new M(`SPL2004`,n.span,`round() to negative decimals has no DQL equivalent.`);return{e:w(`round`,r,C(`decimals`,R(e[1],t).e)),type:`number`}},floor:z(`floor`,`number`,1),ceil:z(`ceil`,`number`,1),ceiling:z(`ceil`,`number`,1),abs:z(`abs`,`number`,1),sqrt:z(`sqrt`,`number`,1),exp:z(`exp`,`number`,1),pow:z(`power`,`number`,2),ln:z(`log`,`number`,1),log:(e,t,n)=>{let r=R(B(e,n),t).e;return e.length===1?{e:w(`log10`,r),type:`number`}:{e:x(`/`,w(`log`,r),w(`log`,R(e[1],t).e)),type:`number`}},pi:z(`pi`,`number`,0),exact:(e,t,n)=>R(B(e,n),t),sigfig:V,printf:V,max:Jt(`arrayMax`),min:Jt(`arrayMin`),random:()=>({e:w(`toLong`,x(`*`,w(`random`),o(2147483647))),type:`number`}),like:z(`like`,`bool`,2),match:(e,t,n)=>{if(e.length!==2)throw H(n,2);let r=R(e[0],t).e,i=dt(U(e[1],n,`the regular expression`),{forMatch:!0});if(!i.ok)throw new M(`SPL2006`,e[1].span,i.reason);return t.report(`SPL3008`,e[1].span),{e:w(`matchesPattern`,r,f(i.dpl)),type:`bool`}},searchmatch:(e,t,n)=>{let r=e[0];if(r?.t!==`str`)throw new M(`SPL2004`,n.span,`searchmatch() needs a quoted search.`);let i=r.v,a=ze(i,0,i.length);return t.report(`SPL3011`,n.span),a?{e:we(a,t,i,!0),type:`bool`}:{e:s(!0),type:`bool`}},cidrmatch:(e,t,n)=>{if(e.length!==2)throw H(n,2);return{e:w(`ipIn`,R(e[1],t).e,R(e[0],t).e),type:`bool`}},in:(e,t,n)=>{if(e.length<2)throw H(n,2);return{e:w(`in`,R(e[0],t).e,g(e.slice(1).map(e=>R(e,t).e))),type:`bool`}},md5:z(`hashMd5`,`string`,1),sha1:z(`hashSha1`,`string`,1),sha256:z(`hashSha256`,`string`,1),sha512:z(`hashSha512`,`string`,1),urldecode:z(`decodeUrl`,`string`,1),spath:Yt,json_extract:Yt,validate:V,true:()=>({e:s(!0),type:`bool`}),false:()=>({e:s(!1),type:`bool`}),null:()=>({e:c(),type:`unknown`}),now:()=>({e:w(`now`),type:`time`}),time:()=>({e:w(`now`),type:`time`}),relative_time:(e,t,n)=>{if(e.length!==2)throw H(n,2);let r=R(e[0],t),i=U(e[1],n,`the time modifier`);return{e:Qt(r.type===`time`?r.e:w(`timestampFromUnixSeconds`,w(`toLong`,r.e)),i,n),type:`time`}},strftime:(e,t,n)=>{if(e.length!==2)throw H(n,2);let r=R(e[0],t),i=U(e[1],n,`the format`),o=r.type===`time`?r.e:w(`timestampFromUnixSeconds`,w(`toLong`,r.e));if(i===`%s`)return{e:w(`unixSecondsFromTimestamp`,o),type:`number`};let s=It(i);if(!s.ok)throw new M(`SPL2004`,e[1].span,`The format directive ${s.directive} has no DQL equivalent.`);return t.report(`SPL3010`,n.span),{e:w(`formatTimestamp`,o,C(`format`,a(s.format))),type:`string`}},strptime:(e,t,n)=>{if(e.length!==2)throw H(n,2);let r=R(e[0],t).e,i=It(U(e[1],n,`the format`));if(!i.ok)throw new M(`SPL2004`,e[1].span,`The format directive ${i.directive} has no DQL equivalent.`);return t.report(`SPL3010`,n.span),{e:w(`parse`,r,f(`TIMESTAMP(${Dt(i.format)}):t`)),type:`time`}}});function qt(e){return(t,n,r)=>{let i=B(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(R(i,n).e),type:`bool`}}}function Jt(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:w(e,ne(`array`,t.map(e=>R(e,n).e))),type:`number`})}function Yt(e,t,n){if(e.length!==2)throw H(n,2);let r=R(e[0],t).e;return{e:w(`jsonPath`,r,a(Xt(U(e[1],n,`the path`)))),type:`unknown`}}function Xt(e){return`$.${e.replace(/\{\}/g,`[*]`).replace(/\{(\d+)\}/g,`[$1]`)}`}function Zt(e,t,n){if(e.length<2||e.length>3)throw H(n,3);let r=R(e[0],t).e,i=W(e[1]),a=e.length===3?W(e[2]):void 0;if(i!==void 0&&(e.length===2||a!==void 0)){if(i<0){if(a===void 0)return{e:w(`substring`,r,C(`from`,o(i))),type:`string`};let e=i+a;return e>=0?{e:w(`substring`,r,C(`from`,o(i))),type:`string`}:{e:w(`substring`,r,C(`from`,o(i)),C(`to`,o(e))),type:`string`}}let e=Math.max(0,i-1);return a===void 0?{e:w(`substring`,r,C(`from`,o(e))),type:`string`}:{e:w(`substring`,r,C(`from`,o(e)),C(`to`,o(e+a))),type:`string`}}t.report(`SPL3007`,n.span);let s=x(`-`,R(e[1],t).e,o(1));return e.length===2?{e:w(`substring`,r,C(`from`,s)),type:`string`}:{e:w(`substring`,r,C(`from`,s),C(`to`,x(`+`,s,R(e[2],t).e))),type:`string`}}function Qt(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 M(`SPL2004`,n.span,`relative_time() with "${t}" cannot be translated.`);let i=e;if(r[1]){let e=N(r[2]||`s`);if(!e)throw new M(`SPL2004`,n.span,`Unknown time unit in "${t}".`);let a=r[1].replace(/^[+-]/,``);i=x(r[1].startsWith(`-`)?`-`:`+`,i,d(`${a}${e}`))}if(r[3]){let e=r[3].toLowerCase(),a=e.startsWith(`w`)?e===`w`||e===`w7`?`w0`:e:N(e);if(!a)throw new M(`SPL2004`,n.span,`Unknown snap unit in "${t}".`);i=ee(i,a)}return i}function $t(e,t){let n=Object.hasOwn(Kt,e.fn)?Kt[e.fn]:void 0;if(!n)throw new M(`SPL2004`,e.fnSpan,`${e.fn}() is not a function the translator knows.`);return n(e.args,t,e)}function en(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 G(e,t){if(e.t===`field`)t.add(e.name);else if(e.t===`call`)for(let n of e.args)G(n,t);else if(e.t===`un`)G(e.e,t);else if(e.t===`bin`)G(e.l,t),G(e.r,t);else if(e.t===`in`){G(e.e,t);for(let n of e.list)G(n,t)}}function K(e,t){return e.k===`field`&&e.name===t?S(e):e.k===`call`?{...e,args:e.args.map(e=>({...e,value:K(e.value,t)}))}:e.k===`un`?{...e,e:K(e.e,t)}:e.k===`bin`?{...e,l:K(e.l,t),r:K(e.r,t)}:e.k===`block`?{...e,items:e.items.map(e=>K(e,t))}:e}function tn(e){return e.startsWith(`DATA? `)?e.slice(6):e}var nn=[{name:`rex`,tier:`T2`,summary:`parse field, "<pattern>" for the convertible regex subset; mode=sed → replaceString/replacePattern.`,lower(e){let t=e.scanner(),n=`_raw`,r=e.span,i=!1,s=1,c;for(;!t.atEnd();){let e=t.option();if(e){let t=e.name.toLowerCase();if(t===`field`)n=e.value,r=e.valueSpan;else if(t===`mode`&&e.value.toLowerCase()===`sed`)i=!0;else if(t===`max_match`&&/^\d{1,6}$/.test(e.value))s=Number(e.value);else throw new M(`SPL2003`,e.span,`rex ${e.name}=${e.value} cannot be translated.`);continue}let a=t.quoted();if(!a||c)throw new M(`SPL1003`,t.here(),`rex needs one quoted regular expression.`);c=a}if(!c)throw new M(`SPL1003`,e.span,`rex needs a quoted regular expression.`);let u=e.field(n,r);if(i){let t=/^s\/((?:\\.|[^/\\])*)\/((?:\\.|[^/\\])*)\/([gi0-9]*)$/.exec(c.value);if(!t)throw new M(`SPL2003`,c.span,`Only s/regex/replacement/ sed expressions can be translated.`);let[,n,r,i]=t;if(/\\\d/.test(r))throw new M(`SPL2006`,c.span,`Back-references in the replacement have no DQL equivalent.`);i.includes(`g`)||e.report(`SPL3008`,c.span,{detail:`Without the g flag sed replaces the first match only; DQL replaces every match.`});let o=r.replace(/\\\//g,`/`),s=pt(n.replace(/\\\//g,`/`));if(s!==void 0){e.emit(T(`fieldsAdd`,_(u,w(`replaceString`,l(u),a(s),a(o)))));return}let d=dt(n.replace(/\\\//g,`/`),{});if(!d.ok)throw new M(`SPL2006`,c.span,d.reason);e.report(`SPL3008`,c.span);let p=d.dpl.startsWith(`DATA? `)?d.dpl.slice(6):d.dpl;e.emit(T(`fieldsAdd`,_(u,w(`replacePattern`,l(u),f(p),a(o)))));return}let d=dt(c.value,s===1?{captures:!0}:{captures:!0,everyMatch:!0});if(!d.ok){for(let t of c.value.matchAll(/\(\?P?<([A-Za-z_][A-Za-z0-9_]*)>/g))e.state.unresolved.add(t[1]);throw new M(`SPL2006`,c.span,d.reason)}if(d.captures.length===0)throw new M(`SPL2003`,c.span,`rex without named groups (?<name>…) extracts nothing.`);if(s!==1){let t=d.captures[0];if(d.captures.length!==1||!t||d.anchoredStart){for(let t of d.captures)e.state.unresolved.add(t.name);throw new M(`SPL2003`,c.span,`rex max_match is only translated for one named group and a pattern without "^".`)}e.report(`SPL3008`,c.span),e.report(`SPL3013`,e.span,{detail:`The matches are returned as an array, not as a Splunk multivalue field.`});let n=w(`parseAll`,l(u),f(d.dpl)),r=e.field(t.name,c.span,!0);e.emit(T(`fieldsAdd`,_(r,s===0?n:w(`arraySlice`,n,C(`from`,o(0)),C(`to`,o(s)))))),e.setType(r,void 0),e.addFields([t.name])}else{e.report(`SPL3008`,c.span),e.emit(T(`parse`,l(u),f(d.dpl)));for(let t of d.captures)e.setType(e.field(t.name,c.span,!0),t.type===`number`?`number`:`string`);e.addFields(d.captures.map(e=>e.name))}}},{name:`spath`,tier:`T2`,summary:`jsonPath() for one path; without a path, parse content as JSON and flatten.`,lower(e){let t=e.scanner(),n=`_raw`,r,i;for(;!t.atEnd();){let e=t.option();if(e){let t=e.name.toLowerCase();if(t===`input`)n=e.value;else if(t===`path`)r=e.value;else if(t===`output`)i=e.value;else throw new M(`SPL2003`,e.span,`spath ${e.name}= cannot be translated.`);continue}let a=t.value();if(!a||r!==void 0)throw new M(`SPL1003`,t.here(),`Unexpected text in spath.`);r=a.value}let o=l(e.field(n,e.span));if(r===void 0){e.report(`SPL3016`,e.span,{detail:`JSON fields get Grail names (json.a.b) instead of Splunk names (a.b{}.c).`}),e.emit(T(`parse`,o,f(`JSON:json`))),e.emit(T(`fieldsFlatten`,l(`json`)));return}r.includes(`{}`)&&e.report(`SPL3013`,e.span,{detail:`An array path returns an array in DQL.`});let s=e.field(i??r,e.span,!0);e.emit(T(`fieldsAdd`,_(s,w(`jsonPath`,o,a(Xt(r)))))),e.addFields([s])}}],q=class extends Error{span;constructor(e,t){super(e),this.span=t}},rn=200,an=2e4;function on(e,t,n){let r=new ln(sn(e,t,n)),i=r.expr();return r.expectEnd(),i}function sn(e,n,r){let i=[],a=n;for(;a<r;){let n=e[a];if(/\s/.test(n)){a++;continue}let o=a;if(n===`"`){let n=t(e,a,r);if(n===-1)throw new q(`A quoted string is not closed.`,{start:a,end:r});i.push({type:`str`,text:de(e.slice(a+1,n)),span:{start:o,end:n+1}}),a=n+1;continue}if(n===`$`){let t=/^\$[A-Za-z_][A-Za-z0-9_.]*(?:\|[A-Za-z]+)?\$/.exec(e.slice(a,Math.min(r,a+200)));if(t){i.push({type:`str`,text:t[0],span:{start:o,end:a+t[0].length}}),a+=t[0].length;continue}}if(n===`'`){let t=e.indexOf(`'`,a+1);if(t===-1||t>=r)throw new q(`A quoted field name is not closed.`,{start:a,end:r});i.push({type:`field`,text:e.slice(a+1,t),span:{start:o,end:t+1}}),a=t+1;continue}if(/[0-9]/.test(n)||n===`.`&&/[0-9]/.test(e[a+1]??``)){let t=/^(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?/.exec(e.slice(a,Math.min(r,a+64))),n=t?t[0].length:1;if(/[A-Za-z_]/.test(e[a+n]??``)){a=cn(e,a,r,i);continue}i.push({type:`num`,text:e.slice(a,a+n),span:{start:o,end:a+n}}),a+=n;continue}if(/[A-Za-z_]/.test(n)){a=cn(e,a,r,i);continue}let s=e.slice(a,a+2);if(s===`==`||s===`!=`||s===`<=`||s===`>=`)i.push({type:`op`,text:s,span:{start:o,end:a+2}}),a+=2;else if(`=<>+-*/%.`.includes(n))i.push({type:`op`,text:n,span:{start:o,end:a+1}}),a++;else if(n===`(`||n===`)`||n===`,`)i.push({type:n,text:n,span:{start:o,end:a+1}}),a++;else throw new q(`Unexpected character "${n}".`,{start:a,end:a+1})}if(i.push({type:`eof`,text:``,span:{start:r,end:r}}),i.length>an)throw new q(`The expression has more than ${an} parts.`,{start:n,end:r});return i}function cn(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 ln=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 q(`${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>rn)throw new q(`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 J(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 M(`SPL1003`,e.here(),`Expected a field name.`);n.push({name:t.value,span:t.span})}return n}function un(e,t){if(e.state.schema.kind!==`events`)return e.state.schema.fields.filter(n=>Pe(t,e.splName(n)))}var dn={name:`table`,tier:`T1`,summary:`fields a, b (wildcards → fieldsKeep "a*").`,lower(e){let t=J(e.scanner());if(t.length===0)throw new M(`SPL1003`,e.span,`table needs at least one field.`);let n=[],r=!1;for(let i of t)if(i.name.includes(`*`)){let t=un(e,i.name);t?P(n,t):r=!0}else n.push(e.field(i.name,i.span));r?(e.report(`SPL2009`,e.span,{detail:`Wildcards keep matching fields, but the column order of table is not reproduced.`}),e.emit(E(`fieldsKeep`,t.map(t=>t.name.includes(`*`)?a(t.name):l(e.field(t.name,t.span))))),e.setTable(n)):(e.emit(E(`fields`,n.map(l))),e.setTable(n))}},fn={name:`fields`,tier:`T1`,summary:`fieldsKeep / fieldsRemove; on raw events timestamp and content are kept, as Splunk keeps _time and _raw.`,lower(e){let t=e.scanner(),n=!1;t.eat(`-`)?n=!0:t.eat(`+`);let r=J(t);if(r.length===0)throw new M(`SPL1003`,e.span,`fields needs at least one field.`);if(n){r.some(e=>e.name.startsWith(`_`)&&e.name.includes(`*`))&&e.report(`SPL2009`,e.span,{detail:`Removing internal fields (_*) has no direct equivalent; they were kept.`});let t=r.filter(e=>!(e.name.startsWith(`_`)&&e.name.includes(`*`)));if(t.length===0)return;if(e.emit(E(`fieldsRemove`,t.map(t=>t.name.includes(`*`)?a(t.name):l(e.field(t.name,t.span))))),e.state.schema.kind!==`events`){let n=new Set(t.map(t=>e.field(t.name,t.span,!0)));e.setTable(e.state.schema.fields.filter(r=>!n.has(r)&&!t.some(t=>t.name.includes(`*`)&&Pe(t.name,e.splName(r)))))}return}let i=[],o=[];for(let t of r){if(t.name.includes(`*`)){i.push(a(t.name));continue}let n=e.field(t.name,t.span);i.push(l(n)),o.push(n)}if(e.state.schema.kind===`events`)for(let e of[`timestamp`,`content`])o.includes(e)||i.push(l(e));e.emit(E(`fieldsKeep`,i)),r.every(e=>!e.name.includes(`*`))&&e.setTable(e.state.schema.kind===`events`?[...o,`timestamp`,`content`]:o)}},pn={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=[],i=0;for(;!t.atEnd();){if(t.eat(`,`))continue;let a=t.fieldName();if(!a||!t.keyword(`as`))throw new M(`SPL1003`,t.here(),`Expected "field AS newname".`);let o=t.fieldName();if(!o)throw new M(`SPL1003`,t.here(),`Expected a new name after AS.`);if(a.value.includes(`*`)||o.value.includes(`*`))throw new M(`SPL2009`,a.span,`Renaming with wildcards needs the list of fields.`);let s=e.field(a.value,a.span),c=e.field(o.value,o.span,!0);s===c?i++:(n.push(_(c,l(s))),r.push([s,c]))}if(!(n.length===0&&i>0)){if(n.length===0)throw new M(`SPL1003`,e.span,`rename needs "field AS newname".`);e.emit(E(`fieldsRename`,n)),e.state.schema.kind!==`events`&&e.setTable(e.state.schema.fields.map(e=>r.find(([t])=>t===e)?.[1]??e))}}};function mn(e){return!e.quoted&&/^-?\d+(\.\d+)?$/.test(e.value)?o(e.value):a(e.value)}var hn={name:`fillnull`,tier:`T1`,summary:`fieldsAdd f = coalesce(f, value).`,lower(e){let t=e.scanner(),n=o(0),r=t.option();if(r){if(r.name.toLowerCase()!==`value`)throw new M(`SPL2003`,r.span,`Option ${r.name} is not supported.`);n=mn(r)}let i=J(t),a=i.map(t=>t.name.includes(`*`)?void 0:e.field(t.name,t.span));if(i.length===0||a.includes(void 0)){let t=e.state.schema.kind===`events`?void 0:e.state.schema.fields;if(!t)throw new M(`SPL2009`,e.span,`fillnull without a field list needs the list of fields.`);a=i.length===0?t:t.filter(t=>i.some(n=>Pe(n.name,e.splName(t))))}let s=a.map(e=>_(e,w(`coalesce`,l(e),n)));s.length>0&&e.emit(E(`fieldsAdd`,s))}},gn=500,_n={name:`replace`,tier:`T1`,summary:`fieldsAdd f = if(f == "x", "y", else: f).`,lower(e){let t=e.scanner(),n=[];for(;!t.peekKeyword(`in`);){if(t.eat(`,`))continue;let e=t.value();if(!e||!t.keyword(`with`))throw new M(`SPL1003`,t.here(),`Expected "value WITH replacement".`);let r=t.value();if(!r)throw new M(`SPL1003`,t.here(),`Expected a replacement after WITH.`);if(e.value.includes(`*`)||r.value.includes(`*`))throw new M(`SPL2009`,e.span,`Wildcard replacements are not supported.`);n.push([e,r])}if(!t.keyword(`in`))throw new M(`SPL2003`,e.span,`replace without IN <fields> needs the list of fields.`);if(n.length>gn)throw new M(`SPL1006`,e.span,`replace has more than ${gn} value pairs; translate it in parts.`);let r=J(t),i=[];for(let t of r){if(t.name.includes(`*`))throw new M(`SPL2009`,t.span,`Wildcard field names need the list of fields.`);let r=e.field(t.name,t.span),o=l(r);for(let e=n.length-1;e>=0;e--){let[t,i]=n[e];o=w(`if`,x(`==`,l(r),a(t.value)),a(i.value),C(`else`,o))}i.push(_(r,o))}e.emit(E(`fieldsAdd`,i))}},vn={name:`convert`,tier:`T2`,summary:`ctime() → formatTimestamp, num()/auto() → toDouble.`,lower(e){let t=e.scanner(),n=`MM/dd/yyyy HH:mm:ss`,r=[];for(;!t.atEnd();){if(t.eat(`,`))continue;let i=t.option();if(i){if(i.name.toLowerCase()!==`timeformat`)throw new M(`SPL2003`,i.span,`Option ${i.name} is not supported.`);let e=It(i.value);if(!e.ok)throw new M(`SPL2003`,i.valueSpan,`The format directive ${e.directive} has no DQL equivalent.`);n=e.format;continue}let o=t.word(`(`),s=t.balanced(`(`,`)`);if(!o||!s)throw new M(`SPL1003`,t.here(),`Expected a conversion such as ctime(field).`);let c=e.slice(s.inner).trim(),u=c;if(t.keyword(`as`)){let e=t.fieldName();if(!e)throw new M(`SPL1003`,t.here(),`Expected a name after AS.`);u=e.value}let d=e.field(c,s.inner),f=l(d),p=e.fieldType(d)===`time`,m=e.field(u,s.inner,!0);switch(o.value.toLowerCase()){case`ctime`:e.report(`SPL3010`,o.span),r.push(_(m,w(`formatTimestamp`,p?f:w(`timestampFromUnixSeconds`,w(`toLong`,f)),C(`format`,a(n))))),e.setType(m,`string`);break;case`num`:case`auto`:r.push(_(m,w(`toDouble`,f))),e.setType(m,`number`);break;case`none`:break;default:throw new M(`SPL2003`,o.span,`convert ${o.value}() has no DQL equivalent.`)}}r.length>0&&e.emit(E(`fieldsAdd`,r))}},yn={name:`addtotals`,tier:`T2`,summary:`fieldsAdd Total = coalesce(a, 0) + coalesce(b, 0) for listed fields.`,lower(e){let t=e.scanner(),n=`Total`;for(let e=t.option();e;e=t.option()){let t=e.name.toLowerCase();if(t===`fieldname`)n=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 M(`SPL2003`,e.span,`addtotals ${e.name}=${e.value} has no DQL equivalent.`)}let r=J(t);if(r.length===0||r.some(e=>e.name.includes(`*`)))throw new M(`SPL2009`,e.span,`addtotals needs an explicit list of fields to sum.`);let i=r.map(t=>w(`coalesce`,l(e.field(t.name,t.span)),o(0))).reduce((e,t)=>e?x(`+`,e,t):t,void 0);e.emit(T(`fieldsAdd`,_(e.field(n,e.span,!0),i))),e.addFields([n])}},bn={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 M(`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 M(`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 M(`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=un(e,t.name);if(!n)throw new M(`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 M(`SPL1006`,e.span,`foreach would write its template ${o.length} times (${o.length*c.length} characters); the limit is ${oe}.`);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 M(`SPL1003`,r.span,`The template must be "field = expression".`);let a=i[1].replace(/^'|'$/g,``),o;try{o=on(n,n.length-i[2].length,n.length)}catch(e){throw e instanceof q?new M(`SPL1004`,r.span,e.message):e}s.push(_(e.field(a,r.span,!0),R(xn(o,r.span),e).e))}e.emit(E(`fieldsAdd`,s))}};function xn(e,t){if(Array.isArray(e))return e.map(e=>xn(e,t));if(e&&typeof e==`object`){let n={};for(let[r,i]of Object.entries(e))n[r]=r===`span`||r===`fnSpan`?t:xn(i,t);return n}return e}var Sn=[dn,fn,pn,hn,_n,vn,yn,bn,{name:`makemv`,tier:`T1`,summary:`fieldsAdd f = splitString(f, delim).`,lower(e){let t=e.scanner(),n=` `;for(let e=t.option();e;e=t.option()){let t=e.name.toLowerCase();if(t===`delim`)n=e.value;else if(t===`allowempty`||t===`setsv`)continue;else throw new M(`SPL2003`,e.span,`makemv ${e.name}= has no DQL equivalent.`)}let r=t.fieldName();if(!r)throw new M(`SPL1003`,e.span,`makemv needs a field.`);let i=e.field(r.value,r.span);e.emit(T(`fieldsAdd`,_(i,w(`splitString`,l(i),a(n)))))}},{name:`mvexpand`,tier:`T1`,summary:`expand f.`,lower(e){let t=e.scanner(),n=t.fieldName();if(!n)throw new M(`SPL1003`,e.span,`mvexpand needs a field.`);let r=t.option(),i=l(e.field(n.value,n.span));if(r&&r.name.toLowerCase()===`limit`&&/^\d+$/.test(r.value))e.emit(T(`expand`,i,C(`limit`,o(r.value))));else if(r)throw new M(`SPL2003`,r.span,`mvexpand ${r.name}= is not supported.`);else e.emit(T(`expand`,i))}},{name:`nomv`,tier:`T1`,summary:`fieldsAdd f = arrayToString(f, delimiter: "\\n").`,lower(e){let t=e.scanner().fieldName();if(!t)throw new M(`SPL1003`,e.span,`nomv needs a field.`);let n=e.field(t.value,t.span);e.emit(T(`fieldsAdd`,_(n,w(`arrayToString`,l(n),C(`delimiter`,a(`
|
|
2
2
|
`))))))}},{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 M(`SPL2003`,n.span,`mvcombine ${n.name}= is not supported.`);let r=t.fieldName();if(!r)throw new M(`SPL1003`,e.span,`mvcombine needs a field.`);if(e.state.schema.kind===`events`)throw new M(`SPL2009`,e.span,`mvcombine needs to know the other fields; use it after table or stats.`);let i=e.field(r.value,r.span),a=e.state.schema.fields.filter(e=>e!==i);e.report(`SPL3004`,e.span,{detail:`The order of the combined values is not guaranteed.`}),e.emit(T(`summarize`,_(i,w(`collectArray`,l(i))),C(`by`,g(a.map(l))))),e.setTable([...a,i])}},{name:`rangemap`,tier:`T2`,summary:`fieldsAdd range = if(...) for numeric ranges.`,lower(e){let t=e.scanner(),n,r,i=[];for(let e=t.option();e;e=t.option())if(e.name===`field`)n=e.value;else if(e.name==="default")r=a(e.value);else{let t=/^(-?\d+(?:\.\d+)?)-(-?\d+(?:\.\d+)?)$/.exec(e.value);if(!t)throw new M(`SPL2003`,e.span,`Range "${e.value}" is not a numeric range.`);i.push({name:e.name,lo:t[1],hi:t[2]})}if(!n||i.length===0)throw new M(`SPL1003`,e.span,`rangemap needs field= and at least one range.`);let s=l(e.field(n,e.span)),c=r??a(`None`);for(let e=i.length-1;e>=0;e--){let t=i[e];c=w(`if`,x(`and`,x(`>=`,s,o(t.lo)),x(`<=`,s,o(t.hi))),a(t.name),C(`else`,c))}e.emit(T(`fieldsAdd`,_(e.field(`range`,e.span,!0),c)))}}];function Cn(e){try{return ze(e.tc.text,e.argsSpan.start,e.argsSpan.end)}catch(e){throw e instanceof I?new M(`SPL1001`,e.span,e.message):e}}function wn(e,t,n){try{return on(e.tc.text,t,n)}catch(e){throw e instanceof q?new M(`SPL1004`,e.span,e.message):e}}var Tn={name:`search`,tier:`T1`,summary:`Leading search → fetch with time range and filters; later searches → filter.`,generating:!0,lower(e){let t=Cn(e);e.first&&e.depth>=0&&e.state.schema.kind===`events`&&e.upstream.length===0?je(e,t):Me(e,t)}},En={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 M(`SPL1003`,e.span,`where needs a condition.`);let t=wn(e,e.argsSpan.start,e.argsSpan.end);e.emit(T(`filter`,R(t,e).e))}},Dn={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=On(e);if(t.length===0)throw new M(`SPL1003`,e.span,`eval needs at least one "field = expression".`);let n=[],r=new Set,i=()=>{n.length>0&&e.emit(E(`fieldsAdd`,n)),n=[],r=new Set},a=0;for(let o of t){let t=wn(e,o.exprStart,o.exprEnd);[...Y(t)].some(e=>r.has(e))&&i();try{let i=R(t,e),a=e.field(o.name,o.nameSpan,!0);n.push(_(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 M))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 On(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 M(`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=kn(t,c,i);n.push({name:o,nameSpan:s,exprStart:c,exprEnd:l}),r=l+1}return n}function kn(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 Y(e,t=new Set){if(e.t===`field`)t.add(e.name);else if(e.t===`call`)for(let n of e.args)Y(n,t);else if(e.t===`un`)Y(e.e,t);else if(e.t===`bin`)Y(e.l,t),Y(e.r,t);else if(e.t===`in`){Y(e.e,t);for(let n of e.list)Y(n,t)}return t}var An={name:`regex`,tier:`T2`,summary:`filter matchesPattern(field, "<pattern>") for the convertible regex subset.`,lower(e){let t=e.scanner(),n=`_raw`,r=!1,i=e.span,a=/^\s*([A-Za-z_][A-Za-z0-9_.]*)\s*(!=|=)\s*/.exec(e.slice(e.argsSpan));a&&(n=a[1],r=a[2]===`!=`,i={start:e.argsSpan.start+a[0].indexOf(n),end:e.argsSpan.start+a[0].indexOf(n)+n.length},t.pos=e.argsSpan.start+a[0].length);let o=t.quoted()??t.word();if(!o)throw new M(`SPL1003`,e.span,`regex needs a regular expression.`);let s=dt(o.value,{forMatch:!0});if(!s.ok)throw new M(`SPL2006`,o.span,s.reason);e.report(`SPL3008`,o.span);let c=w(`matchesPattern`,l(e.field(n,i)),f(s.dpl));e.emit(T(`filter`,r?y(c):c))}};function jn(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.`})}}}var Mn=jn(`fieldformat`),Nn=jn(`highlight`),Pn=jn(`iconify`),Fn=jn(`abstract`),In={name:`return`,tier:`T2`,summary:`fields f then limit N — only meaningful inside a subsearch.`,lower(e){let t=e.scanner(),n=t.integer()?.value??1,r=t.fieldName();if(!r||r.value.startsWith(`$`)||!t.atEnd())throw new M(`SPL2007`,e.span,`Only "return f" or "return N f" with one field can be translated.`);let i=e.field(r.value,r.span);e.emit(T(`fields`,l(i))),e.emit(T(`limit`,o(n))),e.setTable([i])}},Ln=new Set([`count`,`countIf`,`countDistinctExact`,`countDistinctApprox`,`sum`,`avg`,`median`,`percentile`,`stddev`,`variance`]);function Rn(e){return e.expr.k===`bin`||e.expr.k===`call`&&Ln.has(e.expr.fn)}var zn=[`by`,`over`,`where`,`from`],Bn=/^[A-Za-z_][A-Za-z0-9_]*\s*=(?!=)/;function X(e,t){let n=[];for(;e.skipWs(),!(e.atEnd()||zn.some(t=>e.peekKeyword(t))||Bn.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 M(`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 M(`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=le(t.tc.text,e-1,n.inner.end,`(`,`)`);try{s=on(t.tc.text,e,r===-1?n.inner.end:r)}catch(e){throw e instanceof q?new M(`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 M(`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}var Vn=new Set([`count`,`c`,`sum`,`avg`,`mean`,`min`,`max`,`median`,`dc`,`distinct_count`,`estdc`,`per_second`,`per_minute`,`per_hour`,`per_day`]);function Hn(e){return Vn.has(e.fn)||/^(perc|p|exactperc)\d{1,2}(\.\d+)?$/.test(e.fn)}var Un=e({per_second:`1s`,per_minute:`1m`,per_hour:`1h`,per_day:`1d`});function Wn(e,t,n){let r=e.alias??e.defaultName,i=!1,a=()=>{if(e.evalArg){let n=R(e.evalArg,t);return i=n.type===`time`,n.e}if(e.fieldArg){if(e.fieldArg.name.includes(`*`))throw new M(`SPL2009`,e.fieldArg.span,`${e.fn}(${e.fieldArg.name}) needs the list of fields.`);let n=t.field(e.fieldArg.name,e.fieldArg.span);return i=t.fieldType(n)===`time`,l(n)}throw new M(`SPL1003`,e.span,`${e.fn}() needs a field.`)},s=(e,t,n)=>{let a={expr:w(e,t),name:r};return n&&(a.order=n),i&&(a.time=!0),a},c=n===`series`,u=c?[C(`default`,o(0))]:[],f=e.fn;if(f===`count`||f===`c`)return e.evalArg?{expr:w(`countIf`,R(e.evalArg,t).e,...u),name:r}:e.fieldArg?{expr:w(`countIf`,w(`isNotNull`,a()),...u),name:r}:{expr:ne(`count`,u),name:r};let p=/^(perc|p|exactperc|upperperc)(\d{1,2}(?:\.\d+)?)$/.exec(f);if(p)return p[1]===`upperperc`?Gn(e,t,`upperperc() has no DQL equivalent.`):(t.report(`SPL3005`,e.span),{expr:w(`percentile`,a(),o(p[2])),name:r});switch(f){case`dc`:case`distinct_count`:return t.report(`SPL5008`,e.span),{expr:w(`countDistinctExact`,a()),name:r};case`estdc`:return{expr:w(`countDistinctApprox`,a()),name:r};case`sum`:return{expr:w(f,a()),name:r};case`min`:case`max`:return s(f,a());case`avg`:case`mean`:return{expr:w(`avg`,a()),name:r};case`range`:return{expr:x(`-`,w(`max`,a()),w(`min`,a())),name:r};case`median`:return t.report(`SPL3005`,e.span),{expr:w(`median`,a()),name:r};case`stdev`:return{expr:w(`stddev`,a()),name:r};case`stdevp`:return t.report(`SPL3005`,e.span,{detail:`stdevp() is the population deviation; DQL stddev() may use the sample formula.`}),{expr:w(`stddev`,a()),name:r};case`var`:return{expr:w(`variance`,a()),name:r};case`varp`:return t.report(`SPL3005`,e.span,{detail:`varp() is the population variance; DQL variance() may use the sample formula.`}),{expr:w(`variance`,a()),name:r};case`sumsq`:{let e=a();return{expr:w(`sum`,x(`*`,e,e)),name:r}}case`values`:return{expr:w(`arraySort`,w(`collectDistinct`,a())),name:r};case`list`:return t.report(`SPL3004`,e.span,{detail:`list() keeps event order and at most 100 values in Splunk; DQL order is not guaranteed.`}),{expr:w(`collectArray`,a()),name:r};case`first`:case`last`:case`earliest`:case`latest`:{let n=a();return(f===`earliest`||f===`latest`)&&n.k===`field`&&n.name===`timestamp`?{expr:w(f===`earliest`?`min`:`max`,n),name:r,time:!0}:(t.report(`SPL3004`,e.span),s(f===`first`||f===`earliest`?`takeFirst`:`takeLast`,n,f))}case`earliest_time`:case`latest_time`:return t.report(`SPL3006`,e.span,{detail:`${f}() returns a timestamp in DQL, not Unix seconds.`}),{expr:w(f===`earliest_time`?`min`:`max`,l(`timestamp`)),name:r,time:!0};case`per_second`:case`per_minute`:case`per_hour`:case`per_day`:return c?{expr:w(`sum`,a(),C(`rate`,d(Un[f]))),name:r}:Gn(e,t,`${f}() is only translated in timechart.`);case`mode`:case`rate`:case`sparkline`:return Gn(e,t,`${f}() has no DQL equivalent.`);default:return Gn(e,t,`${f}() is not an aggregation the translator knows.`)}}function Gn(e,t,n){t.report(`SPL2005`,e.span,{detail:n})}function Kn(e,t){let n=e.some(e=>e.order===`earliest`||e.order===`latest`);if(e.some(e=>e.order!==void 0)&&t.unorderedEvents){if(n){for(let t of e)t.order===`first`&&t.expr.k===`call`&&(t.expr={...t.expr,fn:`takeLast`}),t.order===`last`&&t.expr.k===`call`&&(t.expr={...t.expr,fn:`takeFirst`});return a(`asc`)}return a(`desc`)}}function Z(e,t,n,r=[],i=!1){return{name:e,aliases:r,tier:`T3`,summary:n,generating:i,lower(e){e.giveUp(t,n)}}}var qn={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 M(`SPL2003`,e.span,`makeresults ${e.name}=${e.value} cannot be translated.`);e.emit(T(`data`,w(`record`,_(`timestamp`,w(`now`))))),e.setTable([`timestamp`])}};function Jn(e){let t=/^(\d+)([A-Za-z]*)$/.exec(e),n=t?N(t[2]||`s`):void 0;if(t&&n&&n!==`M`&&n!==`q`&&n!==`y`)return d(`${t[1]}${n}`)}var Yn=new Set([`summariesonly`,`allow_old_summaries`,`local`,`chunk_size`,`include_reduced_buckets`,`use_summary_index_values`]);function Xn(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 M(`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 Zn(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}}var Qn={name:`tstats`,tier:`T2`,summary:`Runs on events: fetch + filter + summarize. A data model is read through its mapping entry.`,generating:!0,lower(e){let t=e.tc.text,n=e.scanner(),r=!1,i;for(let e=n.option();e;e=n.option()){let t=e.name.toLowerCase();if(!Yn.has(t)){if(t===`prestats`)r=/^(t|true|1)$/i.test(e.value);else if(t===`fillnull_value`)i=e.value;else throw new M(`SPL2003`,e.span,`tstats ${e.name}= cannot be translated.`)}}let o=X(n,e),s;if(n.keyword(`from`)){let t=n.option();if(t?.name.toLowerCase()!==`datamodel`)throw new M(`SPL4008`,e.span,`tstats from a namespace or a search id reads Splunk summaries; there is no equivalent.`);s={path:t.value,span:t.span}}let c=e.argsSpan.end,u;if(n.keyword(`where`)){u=n.pos;let r=ue(t,n.pos,e.argsSpan.end,[`by`]);c=r?r.pos:e.argsSpan.end,n.pos=c}let f=[],p;if(n.keyword(`by`))for(;!n.atEnd();){let e=n.option();if(e){if(e.name.toLowerCase()===`span`&&(p=Jn(e.value)),!p)throw new M(`SPL2003`,e.span,`tstats ${e.name}=${e.value} cannot be translated.`);continue}let t=n.pos;if(P(f,J(n)),n.pos===t)break}if(!n.atEnd())throw new M(`SPL1003`,n.here(),`Unexpected text in tstats.`);let m;try{m=u===void 0?void 0:ze(t,u,c)}catch(e){throw e instanceof I?new M(`SPL1001`,e.span,e.message):e}if(e.report(`SPL3014`,e.span,{detail:`tstats reads index summaries in Splunk; here it reads the events, which costs more.`}),s){let t=Zn(m);m=t.tree,je(e,m,Xn(e,t.nodename??s.path,s.span).source)}else je(e,m);if(r)return;let h=o.map(t=>Wn(t,e,`table`)).filter(e=>e!==void 0);if(h.length===0)throw new M(`SPL2005`,e.span,`None of the aggregations can be translated.`);let v=[],y=[];for(let t of f){let n=e.field(t.name,t.span);n===`timestamp`?(v.push(_(`timestamp`,w(`bin`,l(`timestamp`),p??d(`1h`)))),p||e.report(`SPL3003`,e.span,{detail:`No span was given; one-hour buckets are used.`})):v.push(l(n)),y.push(n)}let b=y.filter(e=>e!==`timestamp`);b.length>0&&i!==void 0?e.emit(E(`fieldsAdd`,b.map(e=>_(e,w(`coalesce`,l(e),a(i)))))):b.length>0&&(e.emit(T(`filter`,D(b.map(e=>w(`isNotNull`,l(e)))))),e.report(`SPL5003`,e.span));let x=h.length===1?_(h[0]?.name??`count`,h[0]?.expr):g(h.map(e=>_(e.name,e.expr)));e.emit(v.length>0?T(`summarize`,x,C(`by`,g(v))):T(`summarize`,x)),e.setTable([...y,...h.map(e=>e.name)]);for(let t of h)e.setType(t.name,t.time?`time`:Rn(t)?`number`:void 0)}},$n={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(!Yn.has(e.name.toLowerCase())&&e.name.toLowerCase()!==`strict_fields`)throw new M(`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 M(`SPL4008`,e.span,`datamodel without "search" or "flat" returns the model's definition, not events.`);je(e,void 0,Xn(e,`${n[0].value}.${n[1].value}`,e.span).source)}},er={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 M(`SPL4006`,e.span,`from a saved search or dataset cannot be resolved; translate that search itself.`);je(e,void 0,Xn(e,t[2],e.span).source)}},tr=e({avg:`avg`,mean:`avg`,sum:`sum`,min:`min`,max:`max`,count:`count`}),nr={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 M(`SPL2003`,r.span,`mstats ${r.name}= cannot be translated.`);let i=X(n,e),a;if(n.keyword(`where`)){let r=n.pos,i=ue(t,r,e.argsSpan.end,[`by`,`span`]),o=i?i.pos:e.argsSpan.end,s;try{s=ze(t,r,o)}catch(e){throw e instanceof I?new M(`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=>we(n,e,t));e.state.schema={kind:`events`,fields:[]},a=D(l),n.pos=o}let o,s=[];for(;!n.atEnd();){let e=n.option();if(e&&e.name.toLowerCase()===`span`){if(o=Jn(e.value),!o)throw new M(`SPL2003`,e.span,`span=${e.value} cannot be translated.`)}else{if(e)throw new M(`SPL2003`,e.span,`mstats ${e.name}= cannot be translated.`);if(n.keyword(`by`))s=J(n,[`span`]);else throw new M(`SPL1003`,n.here(),`Unexpected text in mstats.`)}}let c=[],u=[];for(let t of i){let n=t.fieldArg?.name;if(!n)throw new M(`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 i=tr[t.fn],a=/^(?:perc|p)(\d{1,2})$/.exec(t.fn),o=t.alias??t.defaultName,s=l(r??n);if(i)c.push(_(o,w(i,s)));else if(a)c.push(_(o,w(`percentile`,s,{k:`num`,v:a[1]})));else throw new M(`SPL2005`,t.span,`mstats ${t.fn}() cannot be translated.`);u.push(o)}if(c.length===0)throw new M(`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 d=s.map(t=>e.field(t.name,t.span)),f=[c.length===1?c[0]:g(c)];d.length>0&&f.push(C(`by`,g(d.map(l)))),a&&f.push(C(`filter`,a)),o&&f.push(C(`interval`,o)),e.emit(E(`timeseries`,f)),e.state.schema={kind:`series`,fields:[`timeframe`,`interval`,...d,...u]},e.state.series=!0}},rr=[Z(`pivot`,`SPL2002`,`pivot builds a report from a data model definition; write the search with stats instead.`,[],!0),Z(`iplocation`,`SPL2002`,`There is no IP geolocation function in DQL.`),Z(`geostats`,`SPL2002`,`geostats has no DQL equivalent.`),Z(`map`,`SPL2002`,`map runs a search per row; DQL has no equivalent.`),Z(`collect`,`SPL2008`,`collect writes to an index; it was dropped.`),Z(`outputlookup`,`SPL2008`,`outputlookup writes a lookup file; it was dropped.`),Z(`outputcsv`,`SPL2008`,`outputcsv writes a file; it was dropped.`),Z(`sendemail`,`SPL2008`,`sendemail sends e-mail; use a Dynatrace workflow instead.`),Z(`sendalert`,`SPL2008`,`sendalert triggers an alert action; use a Dynatrace workflow instead.`),Z(`delete`,`SPL2008`,`delete removes indexed data; it was dropped.`),Z(`mcollect`,`SPL2008`,`mcollect writes metrics; it was dropped.`),Z(`tscollect`,`SPL2008`,`tscollect writes summaries; it was dropped.`),Z(`predict`,`SPL2002`,`Forecasting belongs to Davis analyzers, not DQL.`),Z(`anomalydetection`,`SPL2002`,`Anomaly detection belongs to Davis analyzers, not DQL.`),Z(`anomalies`,`SPL2002`,`Anomaly detection belongs to Davis analyzers, not DQL.`),Z(`anomalousvalue`,`SPL2002`,`Anomaly detection belongs to Davis analyzers, not DQL.`),Z(`outlier`,`SPL2002`,`outlier has no DQL equivalent.`),Z(`cluster`,`SPL2002`,`Clustering has no DQL equivalent.`),Z(`kmeans`,`SPL2002`,`Clustering has no DQL equivalent.`),Z(`rest`,`SPL2002`,`rest reads the Splunk REST API; there is no equivalent.`,[],!0),Z(`metadata`,`SPL2002`,`metadata reads Splunk index metadata; there is no equivalent.`,[],!0),Z(`dbinspect`,`SPL2002`,`dbinspect reads Splunk buckets; there is no equivalent.`,[],!0),Z(`eventcount`,`SPL2002`,`eventcount reads index sizes; there is no equivalent.`,[],!0),Z(`loadjob`,`SPL2002`,`loadjob reads a Splunk job; there is no equivalent.`,[],!0),Z(`savedsearch`,`SPL4006`,`Saved searches cannot be resolved; translate the saved search itself.`,[],!0),Z(`script`,`SPL2002`,`Custom scripts have no DQL equivalent.`),Z(`appendcols`,`SPL2010`,`appendcols pastes rows by position; DQL has no equivalent.`),Z(`appendpipe`,`SPL2002`,`appendpipe has no DQL equivalent.`),Z(`xyseries`,`SPL2002`,`Pivoting rows into columns has no DQL equivalent.`),Z(`untable`,`SPL2002`,`Unpivoting columns into rows has no DQL equivalent.`),Z(`timewrap`,`SPL2002`,`timewrap has no DQL equivalent.`),Z(`addinfo`,`SPL2002`,`addinfo adds Splunk search metadata; there is no equivalent.`),Z(`addcoltotals`,`SPL2002`,`Adding a totals row has no DQL equivalent.`),Z(`transpose`,`SPL2002`,`transpose has no DQL equivalent.`),Z(`extract`,`SPL2002`,`Search-time key=value extraction: write a parse pattern with KVP by hand.`,[`kv`]),Z(`xmlkv`,`SPL2002`,`Search-time XML extraction has no DQL equivalent.`),Z(`multikv`,`SPL2002`,`Table extraction has no DQL equivalent.`),Z(`format`,`SPL2007`,`format builds search strings; there is no equivalent.`),Z(`gentimes`,`SPL2002`,`gentimes has no DQL equivalent.`,[],!0),Z(`inputcsv`,`SPL2002`,`inputcsv reads a file on the Splunk server; upload it as a lookup instead.`,[],!0),Z(`localize`,`SPL2002`,`localize has no DQL equivalent.`),Z(`concurrency`,`SPL2002`,`concurrency has no DQL equivalent.`),Z(`associate`,`SPL2002`,`associate has no DQL equivalent.`),Z(`correlate`,`SPL2002`,`correlate has no DQL equivalent.`),Z(`contingency`,`SPL2002`,`contingency has no DQL equivalent.`,[`counttable`,`ctable`]),Z(`arules`,`SPL2002`,`arules has no DQL equivalent.`),Z(`autoregress`,`SPL2002`,`autoregress depends on row order; there is no equivalent.`),Z(`filldown`,`SPL2010`,`filldown depends on row order; there is no equivalent.`),Z(`makecontinuous`,`SPL2002`,`makecontinuous has no DQL equivalent.`),Z(`setfields`,`SPL2002`,`setfields has no DQL equivalent.`),Z(`tags`,`SPL4006`,`Tags cannot be resolved without their definitions.`),Z(`typer`,`SPL4006`,`Event types cannot be resolved without their definitions.`),Z(`erex`,`SPL2002`,`erex generates a regex from examples; write the pattern by hand.`),Z(`scrub`,`SPL2002`,`scrub has no DQL equivalent.`),Z(`xpath`,`SPL2002`,`xpath has no DQL equivalent.`),Z(`sichart`,`SPL2002`,`Summary-indexing commands have no DQL equivalent.`,[`sistats`,`sitimechart`,`sitop`,`sirare`])],ir=[qn,Qn,nr,$n,er];function ar(e,t){return e.get(t)??(t.startsWith(`form.`)?e.get(t.slice(5)):void 0)}var or={name:`sort`,tier:`T1`,summary:`sort a asc, b desc; a count becomes a limit.`,lower(e){let t=e.scanner(),n=t.integer()?.value,r=t.option();if(r){if(r.name.toLowerCase()===`limit`&&/^\d+$/.test(r.value))n=Number(r.value);else throw new M(`SPL2003`,r.span,`sort ${r.name}= is not supported.`)}let i=[],a=!1;for(;!t.atEnd();){if(t.eat(`,`))continue;if(t.keyword(`desc`)||t.keyword(`d`)){a=!0;continue}let n=!1;t.eat(`-`)?n=!0:t.eat(`+`);let r=/^(num|str|ip|auto)\s*\(/i.exec(e.tc.text.slice(t.pos,t.pos+8));if(r){let a=r[1].toLowerCase();t.pos+=r[0].length-1;let o=t.balanced(`(`,`)`);if(!o)throw new M(`SPL1003`,t.here(),`${a}( is not closed.`);let s=e.slice(o.inner).trim(),c=l(e.field(s,o.inner)),u=a===`num`?w(`toDouble`,c):a===`str`?w(`toString`,c):a===`ip`?w(`toIp`,c):c;i.push({expr:u,desc:n});continue}let o=t.fieldName();if(!o)throw new M(`SPL1003`,t.here(),`Expected a field to sort by.`);let s=e.field(o.value,o.span);e.fieldType(s)===void 0&&e.state.schema.kind===`events`&&s!==`timestamp`&&e.report(`SPL3006`,o.span,{subject:`type:${s}`,detail:`"${o.value}" has no declared type; DQL sorts by the stored type, Splunk decides per value.`}),i.push({expr:l(s),desc:n,name:s})}if(i.length===0)throw new M(`SPL1003`,e.span,`sort needs a field.`);let s=i.map(e=>v(e.expr,e.desc===a?`asc`:`desc`));e.emit(E(`sort`,s)),n!==void 0&&n>0?e.emit(T(`limit`,o(n))):n===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=s,e.state.lastWasSort=!0}};function sr(e){return e.map(e=>e.k===`dir`?v(e.e,e.dir===`asc`?`desc`:`asc`):e)}function cr(e){e.unorderedEvents&&(e.emit(T(`sort`,v(l(`timestamp`),`desc`))),e.report(`SPL5004`,e.span),e.state.sorted=!0)}var lr=[or,{name:`head`,tier:`T1`,summary:`limit N (default 10); on raw events sorted newest first, as in Splunk.`,lower(e){let t=/^\s*\$([A-Za-z_][A-Za-z0-9_.]*)\$\s*$/.exec(e.slice(e.argsSpan)),n=t&&e.tc.options.tokens?ar(e.tc.options.tokens,t[1]):void 0;if(n&&n.kind!==`time`){cr(e),e.emit(T(`limit`,m(n.variable,`noquote`)));return}let r=e.scanner(),i=r.integer()?.value,a=r.option();if(a){if(a.name.toLowerCase()===`limit`&&/^\d+$/.test(a.value))i=Number(a.value);else throw new M(`SPL2003`,a.span,`head ${a.name}= cannot be translated.`)}if(!r.atEnd())throw new M(`SPL2003`,e.span,`head with an expression cannot be translated.`);cr(e),e.emit(T(`limit`,o(i??10)))}},{name:`tail`,tier:`T2`,summary:`sort timestamp asc, limit N — on raw events only.`,lower(e){let t=e.scanner().integer()?.value??10;if(e.prevWasSort&&e.state.lastSort){let n=sr(e.state.lastSort);e.emit(E(`sort`,n)),e.emit(T(`limit`,o(t))),e.state.sorted=!0,e.state.lastSort=n,e.state.lastWasSort=!0}else{if(e.state.schema.kind!==`events`)throw new M(`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(T(`sort`,v(l(`timestamp`),`asc`))),e.emit(T(`limit`,o(t))),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=sr(e.state.lastSort);e.emit(E(`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=[v(l(`timestamp`),`asc`)];e.emit(E(`sort`,t)),e.state.sorted=!0,e.state.lastSort=t,e.state.lastWasSort=!0}else throw new M(`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 M(`SPL2003`,e.span,`dedup keeping more than one row per value cannot be translated.`);let n=!1,r=[],i=[],a;for(;!t.atEnd();){let n=t.option();if(n){r.push(n);continue}if(t.keyword(`sortby`)){for(a=[];!t.atEnd();){if(t.eat(`,`))continue;let n=!1;t.eat(`-`)?n=!0:t.eat(`+`);let r=t.fieldName();if(!r)break;a.push(v(l(e.field(r.value,r.span)),n?`desc`:`asc`))}continue}if(t.eat(`,`))continue;let o=t.fieldName();if(!o)throw new M(`SPL1003`,t.here(),`Expected a field.`);i.push({name:o.value,span:o.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 M(`SPL2003`,e.span,`dedup ${t}=true cannot be translated.`);else if(t!==`consecutive`&&t!==`keepevents`)throw new M(`SPL2003`,e.span,`dedup ${e.name}= cannot be translated.`)}if(i.length===0)throw new M(`SPL1003`,e.span,`dedup needs a field.`);let o=i.map(t=>{if(t.name.includes(`*`))throw new M(`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(T(`filter`,D(o.map(e=>w(`isNotNull`,l(e))))));let s=o.map(l);a&&a.length>0?s.push(C(`sort`,g(a))):e.state.schema.kind===`events`&&!e.state.sorted?s.push(C(`sort`,g([v(l(`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(E(`dedup`,s))}},{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 M(`SPL2009`,e.span,`uniq needs to know all fields; use it after table or stats.`);e.emit(E(`dedup`,e.state.schema.fields.map(l)))}}];function Q(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 ur(e,t,n){let r=[];for(let i of e)try{let e=Wn(i,t,n);e&&r.push(e)}catch(e){if(!(e instanceof M))throw e;t.report(e.code,e.span,{detail:`${e.message} This aggregation was left out.`})}if(r.length===0)throw new M(`SPL2005`,t.span,`None of the aggregations can be translated.`);return r}function dr(e,t){for(let n of t)e.setType(n.name,n.time?`time`:Rn(n)?`number`:void 0)}function fr(e){let t=e.map(e=>_(e.name,e.expr));return t.length===1?t[0]:g(t)}function pr(e,t){return t.map(t=>{if(t.name.includes(`*`))throw new M(`SPL2009`,t.span,`Grouping by a wildcard needs the list of fields.`);return e.field(t.name,t.span)})}function mr(e,t){let n=Kn(t,e);n&&n.k===`str`&&(e.emit(T(`sort`,v(l(`timestamp`),n.v))),e.report(`SPL5004`,e.span))}function hr(e,t){t.length!==0&&(e.emit(T(`filter`,D(t.map(e=>w(`isNotNull`,l(e)))))),e.report(`SPL5003`,e.span))}var gr={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 Q(t))e.report(`SPL2003`,n.span,{detail:`stats ${n.name}= has no DQL equivalent and was ignored.`});let n=X(t,e),r=t.keyword(`by`)?J(t):[];if(!t.atEnd())throw new M(`SPL1003`,t.here(),`Unexpected text after the BY clause.`);if(n.length===0)throw new M(`SPL1003`,e.span,`stats needs at least one aggregation.`);let i=ur(n,e,`table`),a=pr(e,r);mr(e,i),hr(e,a);let o=[fr(i)];e.emit(a.length>0?T(`summarize`,...o,C(`by`,g(a.map(l)))):E(`summarize`,o)),e.setTable([...a,...i.map(e=>e.name)]),dr(e,i)}},_r={name:`chart`,tier:`T1`,summary:`summarize by the over/by fields; two group fields give long rows instead of columns.`,lower(e){let t=e.scanner(),n=Q(t),r=X(t,e),i,a=[],s;if(t.keyword(`over`)){let e=t.fieldName();if(!e)throw new M(`SPL1003`,t.here(),`Expected a field after OVER.`);i={name:e.value,span:e.span},P(n,Q(t))}if(t.keyword(`by`)&&(a=J(t),P(n,Q(t))),!t.atEnd())throw new M(`SPL1003`,t.here(),`Unexpected text in chart.`);if(!i&&a.length>0&&(i=a.shift()),a.length>1)throw new M(`SPL2003`,e.span,`chart with more than two group fields has no equivalent.`);let c=ur(r,e,`table`),u=[],d=[];if(i){let t=e.field(i.name,i.span);for(let e of n)if(e.name===`span`||e.name===`bins`){let n=/^\d+(\.\d+)?$/.test(e.value)?o(e.value):void 0;if(!n)throw new M(`SPL2003`,e.span,`chart ${e.name}=${e.value} cannot be translated.`);s=_(t,w(`bin`,l(t),n))}u.push(s??l(t)),d.push(t)}for(let t of a){let n=e.field(t.name,t.span);u.push(l(n)),d.push(n)}for(let t of n)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.`}));a.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.`})),mr(e,c),e.emit(u.length>0?T(`summarize`,fr(c),C(`by`,g(u))):T(`summarize`,fr(c))),e.setTable([...d,...c.map(e=>e.name)]),dr(e,c)}},vr=new Set([`streamstats`,`accum`,`delta`,`trendline`,`fieldformat`,`highlight`,`iconify`]),yr={name:`timechart`,tier:`T2`,summary:`makeTimeseries (series) or summarize by bin(timestamp, span) (tabular).`,lower(e){let t=e.scanner(),n=Q(t),r=X(t,e),i;if(t.keyword(`by`)){let r=t.fieldName();if(!r)throw new M(`SPL1003`,t.here(),`Expected a field after BY.`);i={name:r.value,span:r.span},P(n,Q(t)),t.keyword(`where`)&&(e.report(`SPL2003`,e.span,{detail:`The WHERE clause of timechart (top series) is not reproduced.`}),t.rest())}if(!t.atEnd())throw new M(`SPL1003`,t.here(),`Unexpected text in timechart.`);if(r.length===0)throw new M(`SPL1003`,e.span,`timechart needs an aggregation.`);let a,s,c;for(let t of n)if(t.name===`span`){let e=/^(\d+)([A-Za-z]*)$/.exec(t.value),n=e?N(e[2]||`s`):void 0;if(!e||!n)throw new M(`SPL2003`,t.span,`span=${t.value} cannot be translated.`);if(n===`M`||n===`q`||n===`y`){if(e[1]!==`1`)throw new M(`SPL2003`,t.span,`span=${t.value} cannot be translated; only 1mon, 1q and 1y are.`);s=n}else a=d(`${e[1]}${n}`)}else t.name===`bins`&&/^\d+$/.test(t.value)?c=o(t.value):[`limit`,`useother`,`usenull`,`nullstr`,`otherstr`].includes(t.name)||e.report(`SPL2003`,t.span,{detail:`timechart ${t.name}= has no DQL equivalent and was ignored.`});let u=e.following.every(e=>vr.has(e)),f=!s&&u&&r.every(Hn),p=ur(r,e,f?`series`:`table`),m=i?e.field(i.name,i.span):void 0;if(e.report(`SPL3003`,e.span,{detail:f?`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.`}),m&&e.report(`SPL3009`,e.span,{detail:`Splunk keeps the top 10 series and groups the rest as OTHER; DQL keeps all.`}),f){let t=[fr(p)];m&&t.push(C(`by`,g([l(m)]))),a&&t.push(C(`interval`,a)),c&&t.push(C(`bins`,c)),e.emit(E(`makeTimeseries`,t)),e.state.schema={kind:`series`,fields:[`timeframe`,`interval`,...m?[m]:[],...p.map(e=>e.name)]},e.state.series=!0,e.state.sorted=!0;return}dr(e,p);let h;s?h=_(`timestamp`,ee(l(`timestamp`),s)):(a||=(e.report(`SPL3003`,e.span,{detail:`No span was given; one-hour buckets are used.`}),d(`1h`)),h=_(`timestamp`,w(`bin`,l(`timestamp`),a)));let v=[h,...m?[l(m)]:[]];mr(e,p),e.emit(T(`summarize`,fr(p),C(`by`,g(v)))),e.setTable([`timestamp`,...m?[m]:[],...p.map(e=>e.name)])}};function br(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(t){let n=t.scanner(),r=n.integer()?.value??10,i=`count`,a=`percent`,s=!0,c=!0,u=e=>/^(t|true|1)$/i.test(e),d=[],f=[],p=!1;for(;!n.atEnd();){let o=n.option();if(o){let n=o.name.toLowerCase();n===`limit`&&/^\d+$/.test(o.value)?r=Number(o.value):n===`countfield`?i=o.value:n===`percentfield`?a=o.value:n===`showcount`?s=u(o.value):n===`showperc`?c=u(o.value):t.report(`SPL2003`,o.span,{detail:`${e} ${o.name}= is not reproduced.`});continue}if(n.keyword(`by`)){p=!0;continue}if(n.eat(`,`))continue;let l=n.fieldName();if(!l)throw new M(`SPL1003`,n.here(),`Unexpected text in ${e}.`);(p?f:d).push({name:l.value,span:l.span})}if(d.length===0)throw new M(`SPL1003`,t.span,`${e} needs a field.`);let m=pr(t,d),h=pr(t,f),y=e===`top`?`desc`:`asc`,b=t.field(i,t.span,!0);if(t.setType(b,`number`),hr(t,m),h.length>0)t.report(`SPL3014`,t.span,{detail:`${e} … by … sorts within each group but does not limit per group or add percentages.`}),t.emit(T(`summarize`,_(b,w(`count`)),C(`by`,g([...h,...m].map(l))))),t.emit(T(`sort`,...h.map(e=>v(l(e),`asc`)),v(l(b),y))),t.setTable([...h,...m,b]);else{if(t.emit(T(`summarize`,_(b,w(`count`)),C(`by`,g(m.map(l))))),c){let e=t.field(a,t.span,!0);t.setType(e,`number`),t.emit(T(`summarize`,g([_(`_r`,w(`collectArray`,w(`record`,...m.map(l),l(b)))),_(`_total`,w(`sum`,l(b)))]))),t.emit(T(`expand`,l(`_r`))),t.emit(T(`fields`,...m.map(e=>_(e,S(l(`_r`),e))),_(b,S(l(`_r`),b)),_(e,x(`/`,x(`*`,o(`100.0`),S(l(`_r`),b)),l(`_total`))))),t.setTable([...m,b,e])}else t.setTable([...m,b]);t.emit(T(`sort`,v(l(b),y))),r>0&&t.emit(T(`limit`,o(r))),s||(t.emit(T(`fieldsRemove`,l(b))),t.setTable(t.state.schema.fields.filter(e=>e!==b))),t.state.sorted=!0}}}}var xr=br(`top`),Sr=br(`rare`),Cr={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 t=e.scanner();for(let n of Q(t))e.report(`SPL2003`,n.span,{detail:`eventstats ${n.name}= was ignored.`});let n=X(t,e),r=t.keyword(`by`)?J(t):[];if(!t.atEnd())throw new M(`SPL1003`,t.here(),`Unexpected text after the BY clause.`);let i=ur(n,e,`table`),a=pr(e,r),s=i.map(e=>e.name);for(let t of s)e.field(t,e.span,!0);if(dr(e,i),e.state.schema.kind===`table`){let t=e.state.schema.fields.filter(e=>!a.includes(e)&&!s.includes(e)),n=g([_(`_rows`,w(`collectArray`,ne(`record`,t.map(l)))),...i.map(e=>_(e.name,e.expr))]);e.emit(a.length>0?T(`summarize`,n,C(`by`,g(a.map(l)))):T(`summarize`,n)),e.emit(T(`expand`,l(`_rows`))),e.emit(T(`fields`,...a.map(l),...t.map(e=>_(e,S(l(`_rows`),e))),...s.map(l))),e.setTable([...a,...t,...s]);return}e.report(`SPL3012`,e.span);let c=e.upstream.filter(e=>e.name!==`//`).map(ae),d=a.length===0,f=d?[`_k`]:a;d&&(e.emit(T(`fieldsAdd`,_(`_k`,o(1)))),c.push({...T(`fieldsAdd`,_(`_k`,o(1))),origin:[e.index]})),c.push({...T(`summarize`,fr(i),C(`by`,g(f.map(l)))),origin:[e.index]}),e.emit(T(`join`,h(c),C(`on`,g(f.map(l))),C(`kind`,u(`leftOuter`)),C(`fields`,g(s.map(l))))),d&&e.emit(T(`fieldsRemove`,l(`_k`)))}};function wr(e,t){if(!e.prevSeries)throw new M(`SPL2010`,e.span,`${t} depends on the order of rows; it is only translated right after a timechart.`)}var Tr=e({sum:`arrayMovingSum`,avg:`arrayMovingAvg`,min:`arrayMovingMin`,max:`arrayMovingMax`}),Er=[gr,_r,yr,xr,Sr,Cr,{name:`streamstats`,tier:`T3`,summary:`Not translated, except cumulative/windowed sums and averages right after timechart (array functions).`,lower(e){wr(e,`streamstats`);let t=e.scanner(),n;for(let e of Q(t))if(e.name===`window`&&/^\d+$/.test(e.value))n=Number(e.value);else throw new M(`SPL2010`,e.span,`streamstats ${e.name}= cannot be translated.`);let r=X(t,e);if(!t.atEnd())throw new M(`SPL2010`,t.here(),`streamstats … by … cannot be translated.`);let i=[];for(let t of r){if(!t.fieldArg)throw new M(`SPL2010`,t.span,`streamstats ${t.fn} cannot be translated.`);let r=l(e.field(t.fieldArg.name,t.fieldArg.span)),a=t.alias??t.defaultName,s;if(s=n===void 0||n===0?t.fn===`sum`?`arrayCumulativeSum`:void 0:Tr[t.fn],!s)throw new M(`SPL2010`,t.span,`streamstats ${t.fn}() ${n?`with a window`:`without a window`} cannot be translated.`);i.push(_(e.field(a,t.span,!0),n?w(s,r,o(n)):w(s,r)))}e.emit(E(`fieldsAdd`,i)),e.state.series=!0}},{name:`accum`,tier:`T2`,summary:`arrayCumulativeSum right after timechart.`,lower(e){wr(e,`accum`);let t=e.scanner(),n=t.fieldName();if(!n)throw new M(`SPL1003`,e.span,`accum needs a field.`);let r=t.keyword(`as`)?t.fieldName()?.value??n.value:n.value;e.emit(T(`fieldsAdd`,_(e.field(r,n.span,!0),w(`arrayCumulativeSum`,l(e.field(n.value,n.span)))))),e.state.series=!0}},{name:`delta`,tier:`T2`,summary:`arrayDelta right after timechart.`,lower(e){wr(e,`delta`);let t=e.scanner(),n=t.fieldName();if(!n)throw new M(`SPL1003`,e.span,`delta needs a field.`);let r=t.keyword(`as`)?t.fieldName()?.value??`delta(${n.value})`:`delta(${n.value})`,i=t.option();if(i&&(i.name!==`p`||i.value!==`1`))throw new M(`SPL2003`,i.span,`delta with p other than 1 cannot be translated.`);e.emit(T(`fieldsAdd`,_(e.field(r,n.span,!0),w(`arrayDelta`,l(e.field(n.value,n.span)))))),e.state.series=!0}},{name:`trendline`,tier:`T2`,summary:`smaN → arrayMovingAvg right after timechart.`,lower(e){wr(e,`trendline`);let t=e.scanner(),n=[];for(;!t.atEnd();){let r=t.word(`(`),i=t.balanced(`(`,`)`),a=r?/^sma(\d{1,4})$/i.exec(r.value):null;if(!r||!i||!a)throw new M(`SPL2003`,r?.span??e.span,`Only smaN(field) trendlines can be translated.`);let s=e.slice(i.inner).trim(),c=t.keyword(`as`)?t.fieldName()?.value??`${r.value}(${s})`:`${r.value}(${s})`;n.push(_(e.field(c,r.span,!0),w(`arrayMovingAvg`,l(e.field(s,i.inner)),o(a[1]))))}e.emit(E(`fieldsAdd`,n)),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 M(`SPL2002`,e.span,`transaction with options has no DQL equivalent.`);if(t.eat(`,`))continue;let r=t.fieldName();if(!r)throw new M(`SPL2002`,e.span,`transaction with options has no DQL equivalent.`);n.push({name:r.value,span:r.span})}if(n.length===0)throw new M(`SPL2002`,e.span,`transaction without fields has no DQL equivalent.`);let r=pr(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 i=e.field(`_raw`,e.span);e.emit(T(`summarize`,g([_(`_start`,w(`min`,l(`timestamp`))),_(`_end`,w(`max`,l(`timestamp`))),_(`eventcount`,w(`count`)),_(i,w(`collectArray`,l(i)))]),C(`by`,g(r.map(l))))),e.emit(T(`fieldsAdd`,_(`duration`,x(`/`,x(`-`,l(`_end`),l(`_start`)),d(`1s`))),_(`timestamp`,l(`_start`)))),e.setTable([...r,`_start`,`_end`,`eventcount`,i,`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 t=e.scanner(),n=Q(t),r=t.fieldName();if(!r)throw new M(`SPL1003`,e.span,`bin needs a field.`);P(n,Q(t));let i=r.value;t.keyword(`as`)&&(i=t.fieldName()?.value??i),P(n,Q(t));let a=e.field(r.value,r.span),s=a===`timestamp`||e.fieldType(a)===`time`,c=e.field(i,r.span,!0),u;for(let t of n)if(t.name===`span`)u=t;else if(t.name===`aligntime`)e.report(`SPL2003`,t.span,{detail:`aligntime= was ignored.`});else throw new M(`SPL2003`,t.span,`bin ${t.name}= cannot be translated; use span=.`);if(!u)throw new M(`SPL2003`,e.span,`bin without span= cannot be translated.`);if(s){let t=/^(\d+)([A-Za-z]*)$/.exec(u.value),n=t?N(t[2]||`s`):void 0;if(!t||!n)throw new M(`SPL2003`,u.span,`span=${u.value} cannot be translated.`);if(n===`M`||n===`q`||n===`y`){if(t[1]!==`1`)throw new M(`SPL2003`,u.span,`span=${u.value} cannot be translated.`);e.emit(T(`fieldsAdd`,_(c,ee(l(a),n))))}else e.emit(T(`fieldsAdd`,_(c,w(`bin`,l(a),d(`${t[1]}${n}`)))))}else{if(!/^\d+(\.\d+)?$/.test(u.value))throw new M(`SPL2003`,u.span,`span=${u.value} cannot be translated for a number field.`);e.emit(T(`fieldsAdd`,_(c,w(`bin`,l(a),o(u.value)))))}e.addFields([c])}}],Dr=[Tn,En,Dn,An,Mn,Nn,Pn,Fn,In,...Sn,...Er,...lr,...nn,...et,...ir,...rr];(()=>{let e=new Map;for(let t of Dr)for(let n of[t.name,...t.aliases??[]]){if(e.has(n))throw Error(`Duplicate command ${n}`);e.set(n,t)}return e})();function Or(){return Dr.map(e=>({name:e.name,aliases:e.aliases??[],tier:e.tier,summary:e.summary})).sort((e,t)=>e.name<t.name?-1:+(e.name>t.name))}var kr=n(r(),1),$=i(),Ar={T1:{word:`Exact`,mark:`●`,cls:`mark-exact`},T2:{word:`Check`,mark:`▲`,cls:`mark-check`},T3:{word:`Not translated`,mark:`■`,cls:`mark-untranslated`}};function jr(){let[e,t]=(0,kr.useState)(``),n=(0,kr.useMemo)(()=>Or(),[]),r=(0,kr.useMemo)(()=>ce(),[]),i=e.trim().toLowerCase(),a=n.filter(e=>!i||e.name.includes(i)||e.summary.toLowerCase().includes(i)||e.aliases.some(e=>e.includes(i))),o=r.filter(e=>!i||e.code.toLowerCase().includes(i)||e.title.toLowerCase().includes(i));return(0,$.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,$.jsxs)(`div`,{className:`mx-auto max-w-5xl px-4 py-6`,children:[(0,$.jsxs)(`label`,{className:`flex max-w-md flex-col gap-1 text-sm`,children:[(0,$.jsx)(`span`,{className:`font-semibold`,children:`Find a command or note code`}),(0,$.jsx)(`input`,{className:`field`,value:e,onChange:e=>t(e.target.value),placeholder:`stats, SPL3001, lookup…`})]}),(0,$.jsx)(`h2`,{className:`mt-8 text-lg font-semibold`,children:`Commands`}),(0,$.jsx)(`p`,{className:`mt-1 max-w-[70ch] text-sm text-muted`,children:`Exact: translated with the same meaning. Check: translated, with a known difference the notes explain. Not translated: left as a comment line; the rest of the search is still translated.`}),(0,$.jsxs)(`table`,{className:`mt-3 w-full border-collapse bg-surface text-sm`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{className:`text-left`,children:[(0,$.jsx)(`th`,{className:`border-b border-line px-3 py-2`,children:`Command`}),(0,$.jsx)(`th`,{className:`border-b border-line px-3 py-2`,children:`Best case`}),(0,$.jsx)(`th`,{className:`border-b border-line px-3 py-2`,children:`How it translates`})]})}),(0,$.jsx)(`tbody`,{children:a.map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsxs)(`td`,{className:`border-b border-line px-3 py-2 align-top font-code`,children:[e.name,e.aliases.length>0&&(0,$.jsxs)(`span`,{className:`block text-xs text-muted`,children:[`also `,e.aliases.join(`, `)]})]}),(0,$.jsxs)(`td`,{className:`whitespace-nowrap border-b border-line px-3 py-2 align-top`,children:[(0,$.jsxs)(`span`,{className:Ar[e.tier].cls,"aria-hidden":`true`,children:[Ar[e.tier].mark,` `]}),Ar[e.tier].word]}),(0,$.jsx)(`td`,{className:`border-b border-line px-3 py-2 align-top`,children:e.summary})]},e.name))})]}),(0,$.jsx)(`h2`,{className:`mt-10 text-lg font-semibold`,children:`Note codes`}),(0,$.jsxs)(`table`,{className:`mt-3 w-full border-collapse bg-surface text-sm`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{className:`text-left`,children:[(0,$.jsx)(`th`,{className:`border-b border-line px-3 py-2`,children:`Code`}),(0,$.jsx)(`th`,{className:`border-b border-line px-3 py-2`,children:`Meaning`}),(0,$.jsx)(`th`,{className:`border-b border-line px-3 py-2`,children:`What to do`})]})}),(0,$.jsx)(`tbody`,{children:o.map(e=>(0,$.jsxs)(`tr`,{id:e.code,children:[(0,$.jsxs)(`td`,{className:`whitespace-nowrap border-b border-line px-3 py-2 align-top font-code`,children:[(0,$.jsxs)(`span`,{className:e.severity===`error`?`mark-error`:e.severity===`warning`?`mark-check`:`mark-info`,"aria-hidden":`true`,children:[e.severity===`error`?`■`:e.severity===`warning`?`▲`:`●`,` `]}),e.code]}),(0,$.jsx)(`td`,{className:`border-b border-line px-3 py-2 align-top`,children:e.title}),(0,$.jsx)(`td`,{className:`border-b border-line px-3 py-2 align-top text-muted`,children:e.hint})]},e.code))})]})]})})}export{jr as ReferenceView};
|