import {bJ as F,J as J$1}from'./main-WUGO6e7n.js';function de(t){return t?t.toLowerCase().endsWith(".slog"):false}function ue(t){return [...t.entries].sort((e,n)=>{let i=e.entry.seq-n.entry.seq;return i!==0?i:e.sourceIndex-n.sourceIndex})}function s(t,e,n){return F({code:t,message:e},n)}function Y(t){let e=[],n=false;return {warnings:e,add(i){if(e.length<t){e.push(i);return}n||(e.push(s("entry-limit-exceeded","warning limit exceeded; additional warnings were truncated")),n=true);}}}function k(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Z(t){return {[Symbol.iterator](){let e=0,n=1,i=false;return {next(){if(i)return {done:true,value:void 0};if(e>=t.length)return i=true,{done:true,value:void 0};let r=t.indexOf(`
`,e);if(r===-1){let c=t.slice(e).replace(/\r$/,"");return i=true,{done:false,value:{line:c,sourceLineNumber:n}}}let d=t.slice(e,r).replace(/\r$/,""),o=n;return n+=1,e=r+1,{done:false,value:{line:d,sourceLineNumber:o}}}}}}}function x(t,e){return t===void 0||!Number.isFinite(t)||t<0?e:Math.trunc(t)}function ee(t,e){let n=0;for(let i=0;i<t.length;i+=1){let r=t.charCodeAt(i);if(r<=127)n+=1;else if(r<=2047)n+=2;else if(r>=55296&&r<=56319){let d=t.charCodeAt(i+1);d>=56320&&d<=57343?(n+=4,i+=1):n+=3;}else n+=3;if(e!==void 0&&n>e)return n}return n}function ne(t,e){let n=[{value:t,depth:1}];for(;n.length>0;){let i=n.pop();if(i){if(i.depth>e)return  true;if(Array.isArray(i.value)){for(let r of i.value)(k(r)||Array.isArray(r))&&n.push({value:r,depth:i.depth+1});continue}if(k(i.value))for(let r of Object.values(i.value))(k(r)||Array.isArray(r))&&n.push({value:r,depth:i.depth+1});}}return  false}function q(t,e,n,i,r){return typeof t!="string"?(n.add(s("invalid-field",`${e} must be a string`,{sourceLineNumber:i})),null):t.length>r?(n.add(s("string-truncated",`${e} exceeded max string length and was truncated`,{sourceLineNumber:i})),t.slice(0,r)):t}function te(t,e,n,i,r){if(t===void 0)return;if(!k(t)){e.add(s("invalid-field","parameters must be an object",{sourceLineNumber:n}));return}let d=Object.entries(t);d.length>r&&e.add(s("entry-limit-exceeded","parameter count exceeded max limit",{sourceLineNumber:n}));let o=Object.create(null);for(let[c,b]of d.slice(0,r)){let l=c;if(c.length>i&&(e.add(s("string-truncated","parameter key exceeded max string length and was truncated",{sourceLineNumber:n})),l=c.slice(0,i)),typeof b!="string"){e.add(s("invalid-field",`parameter ${l} must be a string`,{sourceLineNumber:n}));continue}if(Object.hasOwn(o,l)){e.add(s("invalid-field",`parameter ${l} collided after truncation and was discarded`,{sourceLineNumber:n}));continue}if(b.length>i){e.add(s("string-truncated",`parameter ${l} exceeded max string length and was truncated`,{sourceLineNumber:n})),o[l]=b.slice(0,i);continue}o[l]=b;}return o}function ie(t,e,n,i){let r=q(t.timestamp,"timestamp",e,n,i.maxStringLength),d=q(t.description,"description",e,n,i.maxStringLength),o=t.seq,c=t.event;if(typeof c!="string")return e.add(s("invalid-field","event must be a string",{sourceLineNumber:n})),null;if(c.length>i.maxStringLength)return e.add(s("invalid-field","event exceeded max string length",{sourceLineNumber:n})),null;if(r===null||d===null)return null;if(typeof o!="number"||!Number.isInteger(o)||o<0)return e.add(s("invalid-field","seq must be a non-negative integer",{sourceLineNumber:n})),null;if(!Number.isSafeInteger(o))return e.add(s("invalid-field","seq must be a safe integer",{sourceLineNumber:n})),null;i.warnOnInvalidTimestamp&&Number.isNaN(Date.parse(r))&&e.add(s("invalid-field","timestamp is not a valid date string",{sourceLineNumber:n,seq:o})),U.has(c)||e.add(s("unknown-event-type","event is not one of the known lifecycle events",{sourceLineNumber:n,seq:o}));let b=t.actor===void 0?void 0:q(t.actor,"actor",e,n,i.maxStringLength),l=t.locale===void 0?void 0:q(t.locale,"locale",e,n,i.maxStringLength),p=t.host===void 0?void 0:q(t.host,"host",e,n,i.maxStringLength),h=t.sessionType===void 0?void 0:q(t.sessionType,"sessionType",e,n,i.maxStringLength),m=t.object===void 0?void 0:q(t.object,"object",e,n,i.maxStringLength),a=te(t.parameters,e,n,i.maxStringLength,i.maxParameterCount),j=Object.entries(t).filter(([N])=>!z.has(N));j.length>i.maxUnknownFieldCount&&e.add(s("entry-limit-exceeded","unknown top-level field count exceeded max limit",{sourceLineNumber:n}));let L=Object.create(null);for(let[N,T]of j.slice(0,i.maxUnknownFieldCount))L[N]=T;return {entry:F(F(F(F(F(F(F({timestamp:r,seq:o,event:c,description:d},b==null?{}:{actor:b}),l==null?{}:{locale:l}),p==null?{}:{host:p}),h==null?{}:{sessionType:h}),m==null?{}:{object:m}),a?{parameters:a}:{}),Object.keys(L).length===0?{}:{unknownFields:L}),originalEvent:c}}function ce(t,e){let n=[],i=x(e?.maxLineLengthBytes,D),r=x(e?.maxRetainedSourceTextBytes,J),d=x(e?.maxStringLength,B),o=x(e?.maxParameterCount,_),c=x(e?.maxObjectDepth,G),b=x(e?.maxParsedEntries,H),l=x(e?.maxScannedLines,K),p=x(e?.maxMissingSequenceWarnings,Q),h=x(e?.maxUnknownFieldCount,V),m=x(e?.maxWarnings,X),a=Y(m),j=e?.warnOnInvalidTimestamp??true,L=false,N=false,T=false,I=false,F=0,E=0,R=t.endsWith(`
`);for(let{line:f,sourceLineNumber:u}of Z(t)){let w=f.trim().length>0;if(w&&(L=true),E+=1,E>l){N=true,a.add(s("entry-limit-exceeded","scanned line limit exceeded",{sourceLineNumber:u}));break}if(!w)continue;if(n.length>=b){a.add(s("entry-limit-exceeded","parsed entry limit exceeded",{sourceLineNumber:u}));break}let g=ee(f,i);if(g>i){a.add(s("entry-limit-exceeded","line exceeds max byte size",{sourceLineNumber:u}));continue}let v;try{v=JSON.parse(f);}catch(C){a.add(s("malformed-line","line is not valid JSON",{sourceLineNumber:u}));continue}if(!k(v)){a.add(s("malformed-line","line JSON must be an object",{sourceLineNumber:u}));continue}if(ne(v,c)){a.add(s("invalid-field","line object exceeds max depth",{sourceLineNumber:u}));continue}let O=ie(v,a,u,{maxStringLength:d,maxParameterCount:o,maxUnknownFieldCount:h,warnOnInvalidTimestamp:j});if(O){if(F+g>r){a.add(s("entry-limit-exceeded","retained source text byte budget exceeded",{sourceLineNumber:u}));break}F+=g,O.originalEvent==="session.start"?T=true:O.originalEvent==="session.end"&&(I=true),n.push({entry:O.entry,sourceLineNumber:u,sourceIndex:n.length,sourceText:f});}}!R&&t.length>0&&a.add(s("unterminated-final-line","final line does not end with newline"));let A=new Set,$=-1;for(let f of n){let u=f.entry.seq;A.has(u)?a.add(s("duplicate-sequence","sequence number is duplicated",{sourceLineNumber:f.sourceLineNumber,seq:u})):A.add(u),u<$&&a.add(s("sequence-order-mismatch","file order does not match sequence order",{sourceLineNumber:f.sourceLineNumber,seq:u})),$=u;}if(A.size>0){let f=[-1,...Array.from(A).sort((g,v)=>g-v)],u=0;for(let g=1;g<f.length;g+=1){let v=f[g]-f[g-1]-1;v>0&&(u+=v);}let w=0;if(u>0&&p>0)for(let g=1;g<f.length;g+=1){let v=f[g-1]+1,O=f[g];for(let C=v;C<O&&(a.add(s("missing-sequence","sequence number is missing",{seq:C})),w+=1,!(w>=p));C+=1);if(w>=p)break}u>w&&a.add(s("entry-limit-exceeded",`missing sequence warnings truncated: ${u-w} additional missing sequences`));}return n.length>0&&!T&&a.add(s("missing-session-start","session.start is missing")),n.length>0&&!I&&a.add(s("missing-session-end","session.end is missing")),{entries:n,warnings:a.warnings,completionState:I||!L&&!N?"complete":"ended-unexpectedly"}}function se(t){return Number.isFinite(t)?Math.max(1,Math.min(re,Math.trunc(t??W))):W}function M(t,e){return e?t:t.toLowerCase()}function oe(t){let e=new Set,n=new Set;for(let i of t??[]){if(i.sourceLineNumber!==void 0){e.add(i.sourceLineNumber);continue}i.seq!==void 0&&n.add(i.seq);}return {lineNumbers:e,sequences:n}}function S(t,e,n,i,r){t&&M(t,n).includes(e)&&r.add(i);}function le(t,e,n){let i=e.trim(),r=se(n?.limit),d=n?.caseSensitive??false,o=M(i,d),c=n?.eventTypes,b=n?.onlyWithWarnings??false,l=oe(n?.warnings),p=[];for(let h of t){if(c&&c.length>0&&!c.includes(h.entry.event)||b&&!l.lineNumbers.has(h.sourceLineNumber)&&!l.sequences.has(h.entry.seq))continue;let m=new Set,a=h.entry;if(o.length>0){S(a.timestamp,o,d,"timestamp",m),S(a.description,o,d,"description",m),S(a.object,o,d,"object",m),S(a.actor,o,d,"actor",m),S(a.host,o,d,"host",m),S(a.sessionType,o,d,"sessionType",m);let j=a.parameters??{};for(let[L,N]of Object.entries(j))S(L,o,d,"parameter-key",m),S(N,o,d,"parameter-value",m);}if(!(o.length>0&&m.size===0)&&(p.push({entry:h,sourceIndex:h.sourceIndex,sourceLineNumber:h.sourceLineNumber,matchedFields:[...m]}),p.length>=r))break}return p}var U,z,D,J,B,_,G,H,K,Q,V,X,W,re,ae=J$1(()=>{U=new Set(["session.start","session.action","session.end"]),z=new Set(["timestamp","seq","event","description","actor","locale","host","sessionType","object","parameters"]),D=256*1024,J=8*1024*1024,B=4096,_=200,G=8,H=1e4,K=2e4,Q=1e3,V=100,X=1e4;W=100,re=1e3;});export{ae as a,ce as c,de as d,le as l,ue as u};