@cratis/screenplay-language 4.92.0 → 4.93.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,33 +0,0 @@
1
- import{a as l}from"./chunk-AYDF3IFZ.js";var _a="screenplay",Yf={id:_a,extensions:[".play"],aliases:["Screenplay","screenplay","play"],mimetypes:["text/x-screenplay"]},Wf=["domain","import","concept","type","policy","persona","authentication","module","layout","theme","ui","feature","slice","event","system","eventsource","operation","command","query","projection","capture","reaction","reducer","readmodel","trigger","screen","dialog","form","contribute","constraint","specification","example","seed","behavior"];var Dr=["depends","description","documentation","template","profile","require","authenticated","role","claim","subject","authorize","validate","produces","reads","as","handler","performer","observable","identifier","reason","from","when","given","then","arguments","result","clock","exactly","error","message","not","empty","rule","matches","all","max","min","length","today","true","false","and","or","by","filter","data","via","action","navigate","to","label","section","table","summary","title","column","field","on","unique","file","concurrency","eventSource","sourceType","streamType","streamId","tag","for","readmodel","no","when","every","at","where","invokes","contains","starts","with","provider","uses","parameter","order","open","close","refresh","set","notify","confirm","raise","interval","success","failure","click","double","select","submit","change","load","unload","enter","leave","info","warning"],Uf=["csharp","typescript","react","html","sql"],ui=["command","arguments","tenant","causedBy","causation","occurred","identity"],mi=["subject","name","userName"],yi=["id","name","userName","isAuthenticated","roles","claims"],hi=["StateChange","StateView","Automation","Translate"],sn=["Uuid","String","Int","Decimal","Bool","Date","DateTime"],zf=["@pii","@sensitive"],Ja=/^\s*(?:module|feature|slice\s+\w+|type|command|event|readmodel|reducer|projection|capture|reaction|screen|dialog|form|contribute|specification|constraint|persona|policy|behavior|layout|theme|ui\s+profile|trigger|authentication|seed|system|eventsource|operation|screen\s+template|dialog\s+template|produces\s+event|validate|handler|on)\b[^=]*$/,Vf={comments:{lineComment:"//"},brackets:[["(",")"],["[","]"]],autoClosingPairs:[{open:"(",close:")"},{open:"[",close:"]"},{open:'"',close:'"'}],surroundingPairs:[{open:"(",close:")"},{open:"[",close:"]"},{open:'"',close:'"'}],folding:{offSide:!0},onEnterRules:[{beforeText:Ja,action:{indentAction:1}}],indentationRules:{increaseIndentPattern:/^\s*(module|feature|slice|policy|persona|authentication|provider|event|command|query|type|screen|projection|capture|reaction|trigger|constraint|specification|layout|template|validate|produces|handler|implementation(?=\s*$)|performer|rule|section|action|otherwise(?=\s+execute\b)|concurrency|seed|for|when|then|arguments|result|every|at|invokes|on)\b.*$/,decreaseIndentPattern:/(?!)/}};function It(t){let e=/^([\w.]+)(\[\])?(\?|\s+optional)?$/.exec(t);return{name:e?.[1]??t,isCollection:e?.[2]!==void 0,isOptional:e?.[3]!==void 0}}l(It,"typeReferenceSymbol");function Gf(t){return`${t.name}${t.isCollection?"[]":""}${t.isOptional?" optional":""}`}l(Gf,"typeReferenceText");function Ee(t){let e=!1,n=!1;for(let i=0;i<t.length;i++){let r=t[i];if(r==="\\"&&e&&i+1<t.length)i++;else if(r==='"'&&!n)e=!e;else if(r==="`"&&!e)n=!n;else if(!e&&!n&&r==="/"&&t[i+1]==="/")return t.slice(0,i)}return t}l(Ee,"withoutComment");function J(t){return t.length-t.trimStart().length}l(J,"indentOf");function Si(t){return t.trim().split(/\s+/)[0]??""}l(Si,"firstWord");function me(t){let e=new Array(t.length).fill(!1),n=!1;for(let i=0;i<t.length;i++){if(/^\s*```(?:[a-z]+)?\s*$/.test(t[i])&&(!n||/^\s*```\s*$/.test(t[i]))){e[i]=!0,n=!n;continue}e[i]=n}return e}l(me,"fenceMap");function Mr(t,e,n,i){let r=[],o=i;for(let s=n-1;s>=0&&o>0;s--){if(e[s])continue;let a=Ee(t[s]);if(a.trim().length===0)continue;let c=J(a);c<o&&(r.push(Si(a)),o=c)}return r}l(Mr,"enclosingChain");function _f(t,e,n,i){for(let r=n-1;r>=0&&i>0;r--){if(e[r])continue;let o=Ee(t[r]);if(o.trim().length!==0&&J(o)<i)return o.trim()}}l(_f,"nearestEnclosingLine");function Jf(t,e,n,i){let r=[],o=i;for(let s=n-1;s>=0&&o>0;s--){if(e[s])continue;let a=Ee(t[s]);if(a.trim().length===0)continue;let c=J(a);c<o&&(r.push(a.trim()),o=c)}return r}l(Jf,"enclosingHeaders");var Nr="EventContext",Tt={EventContext:[{name:"eventType",type:"EventType",kind:"composite",description:"The type of the event - its identifier, generation and whether it is a tombstone."},{name:"eventSourceType",type:"EventSourceType",kind:"value",description:"The type of the event source the event was appended to."},{name:"eventSourceId",type:"EventSourceId",kind:"value",description:"The identifier of the event source the event was appended to - the value $eventSourceId resolves."},{name:"eventStreamType",type:"EventStreamType",kind:"value",description:"The type of the event stream the event belongs to."},{name:"eventStreamId",type:"EventStreamId",kind:"value",description:"The identifier of the event stream the event belongs to."},{name:"sequenceNumber",type:"EventSequenceNumber",kind:"value",description:"The position of the event in its event sequence."},{name:"occurred",type:"DateTimeOffset",kind:"value",description:"When the event occurred - the time it was appended unless one was given."},{name:"eventStore",type:"EventStoreName",kind:"value",description:"The name of the event store the event belongs to."},{name:"namespace",type:"EventStoreNamespaceName",kind:"value",description:"The namespace within the event store the event belongs to."},{name:"correlationId",type:"CorrelationId",kind:"value",description:"The correlation identifier the event was appended with."},{name:"causation",type:"IEnumerable<Causation>",kind:"collection",description:"The chain of causes that led to the event - a collection, not addressable below."},{name:"causedBy",type:"Identity",kind:"composite",description:"The identity that caused the event."},{name:"tags",type:"IEnumerable<Tag>",kind:"collection",description:"The tags the event was appended with - a collection, not addressable below."},{name:"hash",type:"EventHash",kind:"value",description:"The hash of the event content."},{name:"observationState",type:"EventObservationState",kind:"value",description:"Whether the observer sees the event for the first time or again on replay - differs between live processing and replay."},{name:"subject",type:"Subject",kind:"value",description:"The compliance subject the event is about - the event source identifier unless one was given."},{name:"subjectIsEventSourceId",type:"bool",kind:"value",description:"Whether the subject is the event source identifier."}],EventType:[{name:"id",type:"EventTypeId",kind:"value",description:"The identifier of the event type."},{name:"generation",type:"EventTypeGeneration",kind:"value",description:"The generation of the event type."},{name:"tombstone",type:"bool",kind:"value",description:"Whether the event is a tombstone event."}],EventSourceType:[{name:"value",type:"string",kind:"value",description:"The underlying string value."}],EventSourceId:[{name:"value",type:"string",kind:"value",description:"The underlying string value."}],EventStreamType:[{name:"value",type:"string",kind:"value",description:"The underlying string value."}],EventStreamId:[{name:"value",type:"string",kind:"value",description:"The underlying string value."}],EventSequenceNumber:[{name:"value",type:"ulong",kind:"value",description:"The underlying ulong value."}],DateTimeOffset:[{name:"Week",type:"int",kind:"function",description:"The ISO 8601 week of the year the value falls in."}],EventStoreName:[{name:"value",type:"string",kind:"value",description:"The underlying string value."}],EventStoreNamespaceName:[{name:"value",type:"string",kind:"value",description:"The underlying string value."}],CorrelationId:[{name:"value",type:"Guid",kind:"value",description:"The underlying Guid value."}],Identity:[{name:"subject",type:"string",kind:"value",description:"The subject identifier of the identity."},{name:"name",type:"string",kind:"value",description:"The display name of the identity."},{name:"userName",type:"string",kind:"value",description:"The user name of the identity."},{name:"onBehalfOf",type:"Identity",kind:"composite",description:"The identity this identity acted on behalf of, if any - an identity with the same members."}],EventHash:[{name:"value",type:"string",kind:"value",description:"The underlying string value."}],Subject:[{name:"value",type:"string",kind:"value",description:"The underlying string value."}],EventTypeId:[{name:"value",type:"string",kind:"value",description:"The underlying string value."}],EventTypeGeneration:[{name:"value",type:"uint",kind:"value",description:"The underlying uint value."}]},gi=[{path:"eventType",name:"eventType",type:"EventType",kind:"composite",description:"The type of the event - its identifier, generation and whether it is a tombstone."},{path:"eventType.id",name:"id",type:"EventTypeId",kind:"value",description:"The identifier of the event type."},{path:"eventType.id.value",name:"value",type:"string",kind:"value",description:"The underlying string value."},{path:"eventType.generation",name:"generation",type:"EventTypeGeneration",kind:"value",description:"The generation of the event type."},{path:"eventType.generation.value",name:"value",type:"uint",kind:"value",description:"The underlying uint value."},{path:"eventType.tombstone",name:"tombstone",type:"bool",kind:"value",description:"Whether the event is a tombstone event."},{path:"eventSourceType",name:"eventSourceType",type:"EventSourceType",kind:"value",description:"The type of the event source the event was appended to."},{path:"eventSourceType.value",name:"value",type:"string",kind:"value",description:"The underlying string value."},{path:"eventSourceId",name:"eventSourceId",type:"EventSourceId",kind:"value",description:"The identifier of the event source the event was appended to - the value $eventSourceId resolves."},{path:"eventSourceId.value",name:"value",type:"string",kind:"value",description:"The underlying string value."},{path:"eventStreamType",name:"eventStreamType",type:"EventStreamType",kind:"value",description:"The type of the event stream the event belongs to."},{path:"eventStreamType.value",name:"value",type:"string",kind:"value",description:"The underlying string value."},{path:"eventStreamId",name:"eventStreamId",type:"EventStreamId",kind:"value",description:"The identifier of the event stream the event belongs to."},{path:"eventStreamId.value",name:"value",type:"string",kind:"value",description:"The underlying string value."},{path:"sequenceNumber",name:"sequenceNumber",type:"EventSequenceNumber",kind:"value",description:"The position of the event in its event sequence."},{path:"sequenceNumber.value",name:"value",type:"ulong",kind:"value",description:"The underlying ulong value."},{path:"occurred",name:"occurred",type:"DateTimeOffset",kind:"value",description:"When the event occurred - the time it was appended unless one was given."},{path:"occurred.Week",name:"Week",type:"int",kind:"function",description:"The ISO 8601 week of the year the value falls in."},{path:"eventStore",name:"eventStore",type:"EventStoreName",kind:"value",description:"The name of the event store the event belongs to."},{path:"eventStore.value",name:"value",type:"string",kind:"value",description:"The underlying string value."},{path:"namespace",name:"namespace",type:"EventStoreNamespaceName",kind:"value",description:"The namespace within the event store the event belongs to."},{path:"namespace.value",name:"value",type:"string",kind:"value",description:"The underlying string value."},{path:"correlationId",name:"correlationId",type:"CorrelationId",kind:"value",description:"The correlation identifier the event was appended with."},{path:"correlationId.value",name:"value",type:"Guid",kind:"value",description:"The underlying Guid value."},{path:"causation",name:"causation",type:"IEnumerable<Causation>",kind:"collection",description:"The chain of causes that led to the event - a collection, not addressable below."},{path:"causedBy",name:"causedBy",type:"Identity",kind:"composite",description:"The identity that caused the event."},{path:"causedBy.subject",name:"subject",type:"string",kind:"value",description:"The subject identifier of the identity."},{path:"causedBy.name",name:"name",type:"string",kind:"value",description:"The display name of the identity."},{path:"causedBy.userName",name:"userName",type:"string",kind:"value",description:"The user name of the identity."},{path:"causedBy.onBehalfOf",name:"onBehalfOf",type:"Identity",kind:"composite",description:"The identity this identity acted on behalf of, if any - an identity with the same members."},{path:"tags",name:"tags",type:"IEnumerable<Tag>",kind:"collection",description:"The tags the event was appended with - a collection, not addressable below."},{path:"hash",name:"hash",type:"EventHash",kind:"value",description:"The hash of the event content."},{path:"hash.value",name:"value",type:"string",kind:"value",description:"The underlying string value."},{path:"observationState",name:"observationState",type:"EventObservationState",kind:"value",description:"Whether the observer sees the event for the first time or again on replay - differs between live processing and replay."},{path:"subject",name:"subject",type:"Subject",kind:"value",description:"The compliance subject the event is about - the event source identifier unless one was given."},{path:"subject.value",name:"value",type:"string",kind:"value",description:"The underlying string value."},{path:"subjectIsEventSourceId",name:"subjectIsEventSourceId",type:"bool",kind:"value",description:"Whether the subject is the event source identifier."}];function xi(t,e){if(t.kind==="function")return e===t.name||e===`${t.name}()`;let n=t.name[0].toUpperCase()+t.name.slice(1);return e===n||e.length>0&&e[0].toUpperCase()+e.slice(1)===n}l(xi,"namesEventContextMember");var vi=Tt[Nr];function Ha(t){let e=vi;for(let n of t){let i=e.find(r=>xi(r,n));if(!i||i.kind==="collection"||i.kind==="function")return;e=Tt[i.type]??[]}return e}l(Ha,"eventContextMembersAfter");function nu(t){return t.length===0?void 0:Ha(t.slice(0,-1))?.find(n=>xi(n,t[t.length-1]))}l(nu,"eventContextMemberAt");function $i(t){let e,n=vi;for(let i of t.split(".")){if(i.length===0)return{status:"missing",member:e,expected:n};if(e?.kind==="collection")return{status:"belowCollection",member:e,segment:i,expected:[]};let r=n.find(o=>xi(o,i));if(!r)return{status:e?"unknownSubPath":"unknownMember",member:e,segment:i,expected:n};e=r,n=r.kind==="function"?[]:Tt[r.type]??[]}return{status:"known",member:e,expected:[]}}l($i,"resolveEventContextPath");function iu(){return["**$eventContext**","","Metadata about the event being projected. Paths are checked against the event-context catalog; `causation` and `tags` are collections and cannot be addressed below.","","**Members:**",...vi.map(t=>`- \`${t.name}\` (${t.type}) - ${t.description}`)].join(`
2
- `)}l(iu,"describeEventContext");function ru(t,e){let n=e.kind==="collection"||e.kind==="function"?[]:Tt[e.type]??[],i=[`**$eventContext.${t}**: \`${e.type}\``,"",e.description];return n.length>0&&i.push("",`**Members:** ${n.map(r=>`\`${r.name}\``).join(", ")}`),i.join(`
3
- `)}l(ru,"describeEventContextMember");var Ke={label:"documentation",insertText:"documentation\n ```markdown\n ${1:Reasoning, assumptions or rejected alternatives}\n ```",documentation:"One nonempty authoring-only Markdown block; report-only (PLAY0270), with no executable effect."};var st=[{label:"example",insertText:"example ${1:Name} : ${2:Type}\n ${3:property} = ${4:value}",documentation:"One possibly partial event, command or read-model fixture. Step assignments override its values; no implicit defaults."}];var ki=[{label:"on",insertText:"on ${1|click,select,submit,change,load,unload,enter,leave|}\n ${2:execute command}",documentation:"Wires what happens on an interaction - a click, a submit, entering or leaving the screen."},{label:"uses",insertText:"uses ${1:Behavior}",documentation:"Attaches a named behavior declared at the top level."}],Xa=[Ke,...st,{label:"description",insertText:'description "${1:what this module is for}"',documentation:"A human-readable description."},{label:"authorize",insertText:"authorize ${1:PolicyName}",documentation:"Policies that must pass for everything in the module."},{label:"depends on",insertText:"depends on ${1:Name}",documentation:"Declares an allowed module or feature dependency. Opts this container into independent explicit-reference checks."},{label:'import "\u2026"',insertText:'import "${1:*/*.play}"',documentation:"Imports `.play` files into this module \u2014 their top level is the module's body."},{label:"feature",insertText:"feature ${1:Name}\n ",documentation:"Groups related slices into a vertical feature."},{label:"screen",insertText:"screen ${1:Name}\n data ${2:ReadModel} via query ${3:QueryName}",documentation:"Declares a module-level UI screen."},{label:"screen template",insertText:"screen template ${1:Name}\n fits slot ${2:content}\n\n ${3:slot}",documentation:"Declares a reusable screen shape that fits a slot of the shell."},{label:"dialog template",insertText:"dialog template ${1:Name}\n ${2:body}\n ${3:actions}",documentation:"Declares a reusable dialog shape that opens over the shell."},{label:"form",insertText:'form ${1:Name} for ${2:Command}\n field ${3:property} label "${4:Label}"',documentation:"Declares a form bound to a command."},{label:"contribute",insertText:'contribute to ${1:Navigation}\n navigate to ${2:Screen}\n label "${3:Label}"',documentation:"Contributes an entry to a slot of the shell, such as navigation."},...ki],es=[Ke,...st,{label:"description",insertText:'description "${1:what this feature is for}"',documentation:"A human-readable description."},{label:"authorize",insertText:"authorize ${1:PolicyName}",documentation:"Policies that must pass for everything in the feature."},{label:"depends on",insertText:"depends on ${1:Name}",documentation:"Declares an allowed module or feature dependency. Sibling feature names resolve before module names."},{label:'import "\u2026"',insertText:'import "${1:*.play}"',documentation:"Imports `.play` files into this feature \u2014 their top level is the feature's body."},{label:"feature",insertText:"feature ${1:Name}\n ",documentation:"Declares a nested sub-feature."},{label:"slice StateChange",insertText:"slice StateChange ${1:Name}\n ",documentation:"A command \u2192 events flow; something that changes the system."},{label:"slice StateView",insertText:"slice StateView ${1:Name}\n ",documentation:"A query + projection + screen; something that reads the system."},{label:"slice Automation",insertText:"slice Automation ${1:Name}\n ",documentation:"A reaction or reducer; something that runs when something happens."},{label:"slice Translate",insertText:"slice Translate ${1:Name}\n ",documentation:"A capture; converts external data into events."},{label:"contribute",insertText:'contribute to ${1:Navigation}\n navigate to ${2:Screen}\n label "${3:Label}"',documentation:"Contributes an entry to a slot of the shell, such as navigation."},...ki],pu=[Ke,{label:"description",insertText:'description "${1:what one instance holds}"',documentation:"A human-readable description."},{label:"file",insertText:"file ${1:Path}",documentation:"Names the file this read model is realized by."},{label:"property",insertText:"${1:property} ${2:Type}",documentation:"A property of the read model \u2014 a name and a type reference."}],fu=[{label:"description",insertText:'description "${1:what the reducer does}"',documentation:"A human-readable description."},{label:"on",insertText:"on ${1:EventType}\n ```csharp\n ${2}\n ```",documentation:"A rule applied when the event occurs, in code or from a file."}],uu=[{label:"populate via query",insertText:"populate via query ${1:Query} by ${2:parameter}",documentation:"Fills the form from a query before it is shown."},{label:"populate from item",insertText:"populate from item",documentation:"Fills the form from the item the screen was opened for."},{label:"field",insertText:'field ${1:property} label "${2:Label}"',documentation:"A form field bound to a command property."},...ki],mu=[{label:"navigate to",insertText:"navigate to ${1:Screen}",documentation:"The screen the entry opens."},{label:"label",insertText:'label "${1:Label}"',documentation:"The text of the entry."},{label:"order",insertText:"order ${1:10}",documentation:"Where the entry sits among the others; lower comes first."}],yu=[{label:"description",insertText:'description "${1:what the behavior does}"',documentation:"A human-readable description."},{label:"parameter",insertText:"parameter ${1:name} ${2:Type}",documentation:"A value the behavior is given where it is attached."},{label:"order",insertText:"order ${1:10}",documentation:"The order behaviors attached to the same element run in."},{label:"on",insertText:"on ${1|click,select,submit,change,load,unload,enter,leave|}\n ${2:execute command}",documentation:"Wires what happens on an interaction."}],Ce=l((t,e,n)=>({label:t,insertText:e,documentation:n}),"step"),ts=[Ce("execute","execute ${1:command}","Runs a command."),Ce("navigate to","navigate to ${1:Screen}","Opens a screen."),Ce("open","open ${1:Dialog}","Opens a dialog."),Ce("close","close","Closes the dialog."),Ce("refresh","refresh ${1:query}","Reloads a query."),Ce("set","set ${1:name} ${2:value}","Sets a value."),Ce("notify",'notify ${1|info,warning,error|} "${2:message}"',"Shows a notification."),Ce("confirm","confirm ${1:message}\n on success\n ${2:execute command}","Asks before continuing."),Ce("raise","raise ${1:Trigger}","Raises a trigger.")],hu=[Ce("on success",'on success\n ${1:notify info "Done"}',"What happens when it succeeds."),Ce("on failure",'on failure\n ${1:notify error "Failed"}',"What happens when it fails."),...ts],Su=[{label:"description",insertText:'description "${1:who they are}"',documentation:"A human-readable description."},{label:"policy",insertText:"policy ${1:PolicyName}",documentation:"A policy this persona holds."}],gu=[{label:"provider",insertText:"provider ${1:Name}",documentation:"An identity provider."},{label:"provider (named)",insertText:"provider ${1:Kind} name ${2:Name}",documentation:"An identity provider of a kind, under its own name."}],xu=[{label:"for",insertText:'for ${1:"event-source-id"}\n ${2:EventType}\n ${3:property} = ${4:value}',documentation:"Events to seed for one event source id."}],vu=[{label:"compatible with",insertText:"compatible with ${1:Package}",documentation:"A component package the theme is compatible with."}],$u=[{label:"target platform",insertText:"target platform ${1:web}",documentation:"The platforms the profile is for."},{label:"target size",insertText:"target size ${1|compact,regular|}",documentation:"The screen sizes the profile is for."},{label:"packages",insertText:"packages\n ${1:Package}",documentation:"The component packages the profile uses."},{label:"layout",insertText:"layout ${1:Layout}",documentation:"The layout of the profile."},{label:"theme",insertText:"theme ${1:Theme}",documentation:"The theme of the profile."}],ns=[{label:"slot",insertText:"${1:slot}",documentation:"A named slot of the shell."},{label:"slot contributes",insertText:"${1:slot} contributes ${2:Name}",documentation:"A slot other declarations contribute to, such as `navigation contributes Navigation`."},{label:"arrangement",insertText:`arrangement flow
4
- column
5
- \${1:slot}`,documentation:"How the slots are placed."}],ku=[{label:"fits slot",insertText:"fits slot ${1:content}",documentation:"The slot of the shell the template fits."},...ns,{label:"on",insertText:"on ${1|enter,leave,load,unload|}\n ${2:refresh query}",documentation:"Wires what happens on an interaction."}];var wu=[{label:"optional",insertText:"optional",documentation:"Allows the complete value, including a collection, to be absent."}],ye=l(t=>`\`\`\`${t}
6
- \${1}
7
- \`\`\``,"fenced"),Ou=[...st,{label:"eventsource",insertText:"eventsource ${1:Name}\n identifier ${2:Type}\n stream ${3:Name}",documentation:"Application-owned source with nested streams; not admitted by any supported executable model (ESM) version yet (PLAY0268)."},{label:"system",insertText:'system ${1:Name}\n description "${2:external system}"',documentation:"Application-scoped external system; not admitted by any supported executable model (ESM) version yet."},{label:"import",insertText:"import ${1:Module}.${2:Type}",documentation:"Imports a type from another module by its qualified name."},{label:'import "\u2026"',insertText:'import "${1:**/*.play}"',documentation:"Imports other `.play` files by path or glob, relative to this file's folder, as whole documents of the application."},{label:"concept",insertText:"concept ${1:Name} : ${2|Uuid,String,Int,Decimal,Bool,Date,DateTime|}",documentation:"Declares a formalized value type wrapping a primitive."},{label:"concept (enum)",insertText:"concept ${1:Name} : Enum\n ${2:value}",documentation:"Declares an enumeration concept with a fixed set of values."},{label:"concept (@pii with reason)",insertText:'concept ${1:Name} : ${2|String,Uuid,Int,Decimal,Bool,Date,DateTime|} @pii\n pii reason "${3:why this is personal data, its purpose and lawful basis}"',documentation:"Declares a personal-data concept together with the reason it is personal data."},{label:"type",insertText:"type ${1:Name}\n ${2:property} ${3:Type}",documentation:"Declares a composite value type \u2014 a named shape built from several properties."},{label:"policy",insertText:"policy ${1:Name}\n require ${2:authenticated}",documentation:"Declares a named authorization rule for commands and queries."},{label:"module",insertText:"module ${1:Name}\n ",documentation:"Declares the top-level namespace \u2014 maps to a bounded context."},{label:"domain",insertText:"domain ${1:Name}",documentation:"The domain the file belongs to \u2014 optional, at most one per file, before everything else."},{label:"persona",insertText:'persona ${1:Name}\n description "${2:who they are}"',documentation:"A named role interacting with the application, with the policies it holds."},{label:"authentication",insertText:"authentication\n provider ${1:Name}\n ${2:setting} ${3:value}",documentation:"Declares the identity providers of the application \u2014 at most one block per file."},{label:"seed",insertText:"seed\n for ${1:EventSourceId}\n ${2:EventType}",documentation:"Declares events to seed into the event store per event source id."},{label:"layout",insertText:"layout ${1:Name}\n ${2:slot}",documentation:"Declares the application shell with named slots."},{label:"theme",insertText:"theme ${1:Name}\n compatible with ${2:Package}",documentation:"Declares a theme and the component packages it is compatible with."},{label:"ui profile",insertText:"ui profile ${1:Name}\n target platform ${2:web}\n layout ${3:Layout}\n theme ${4:Theme}",documentation:"Binds a target platform and size to a layout, theme and component packages."},{label:"behavior",insertText:"behavior ${1:Name}\n on ${2:click}\n ${3:execute command}",documentation:"A named interaction wiring, attached to a screen, form or dialog with `uses`."},{label:"trigger",insertText:"trigger ${1:Name}\n ${2:property} ${3:Type}",documentation:"Declares an integration signal a reaction can run on."}],Iu=[{label:"uses",insertText:"uses ${1:System}",documentation:"Exactly one application-scoped external system."},{label:"description",insertText:'description "${1:intent}"',documentation:"Describes operation intent, without requiring code."},{label:"input",insertText:"${1:input} ${2:Type}",documentation:"Typed operation input; no identifier or generated modifier."},{label:"execute",insertText:'execute\n description "${1:effect}"',documentation:"Optional execution intent; not admitted by any supported executable model (ESM) version yet."},{label:"compensate",insertText:'compensate\n description "${1:undo intent}"',documentation:"Optional compensation intent; not admitted by any supported executable model (ESM) version yet."}],is=[{label:"hint",insertText:'hint "${1:implementation guidance}"',documentation:"Ordered authoring guidance; not an executable implementation role."},{label:"file",insertText:"file ${1:Path}",documentation:"Selects the phase\u2019s sole source attachment."},...["csharp","typescript","react","html","sql"].map(t=>({label:t,insertText:ye(t),documentation:"Selects the phase\u2019s sole inline source; not admitted by any supported executable model (ESM) version yet."}))],Tu=[{label:"description",insertText:'description "${1:phase intent}"',documentation:"A description-only phase is valid, pending intent."},{label:"implementation",insertText:'implementation\n hint "${1:guidance}"',documentation:"Hints with optional source; phase owns File/Code, wrapper owns hints only."},...is.filter(t=>t.label!=="hint")],Ru=[{label:"file",insertText:"file ${1:Path}",documentation:"Names the repository relative file this declaration is realized by, so the document can be navigated back to the code."},{label:"pii reason",insertText:'pii reason "${1:why this is personal data, its purpose and lawful basis}"',documentation:"Records why the `@pii` marker applies \u2014 purpose, lawful basis, whose subject it lives under."},{label:"sensitive reason",insertText:'sensitive reason "${1:why this value is sensitive}"',documentation:"Records why the `@sensitive` marker applies."},{label:"validate",insertText:'validate\n ${1:not empty} message "${2:message}"',documentation:"Validation rules that travel with the value everywhere it appears."}],Du=[{label:"file",insertText:"file ${1:Path}",documentation:"Names the repository relative file this declaration is realized by, so the document can be navigated back to the code."},{label:"description",insertText:'description "${1:what this shape represents}"',documentation:"A human-readable description of the type."},{label:"property",insertText:"${1:property} ${2:Type}",documentation:"A property of the type \u2014 a name and a type reference."}],jr=[Ke,...st,{label:"operation",insertText:"operation ${1:Name}\n uses ${2:System}\n ${3:input} ${4:Type}",documentation:"Reusable slice-owned operation intent; not admitted by any supported executable model (ESM) version yet."},{label:"file",insertText:"file ${1:Path}",documentation:"Names the repository relative file this declaration is realized by, so the document can be navigated back to the code."},{label:"event",insertText:"event ${1:Name}\n ${2:property} ${3:Type}",documentation:"Declares an event type \u2014 an immutable, past-tense fact."},{label:"event generation",insertText:"event ${1:Name} generation ${2:2}\n ${3:property} ${4:Type}",documentation:"Declares a complete numbered event generation; start at 1 and do not skip a number."},{label:"command",insertText:"command ${1:Name}\n ${2:property} ${3:Type}",documentation:"Declares a command \u2014 an imperative intent that produces events."},{label:"query",insertText:"query ${1:Name} => ${2:ReadModel}",documentation:"Declares a read-side entry point mapping to a return type."},{label:"query observable",insertText:"query ${1:Name} => observable ${2:ReadModel}",documentation:"Declares a live read \u2014 the query keeps pushing as the read model changes, instead of answering once."},{label:"readmodel",insertText:"readmodel ${1:Name}\n ${2:property} ${3:Type}",documentation:"Declares the shape of a read model \u2014 its properties \u2014 that a projection, reducer or query fills and returns."},{label:"reducer",insertText:"reducer ${1:Name} => ${2:ReadModel}\n on ${3:EventType}\n ```csharp\n ${4}\n ```",documentation:"Declares a reducer building a read model from events with imperative code, for what a projection cannot express."},{label:"specification",insertText:"specification ${1:Name}\n given ${2:EventType}\n when ${3:Command}\n then ${4:EventType}",documentation:"Given/when/then acceptance criteria for the slice."},{label:"projection",insertText:"projection ${1:Name} => ${2:ReadModel}\n from ${3:EventType}",documentation:"Declares how events project into a read model (PDL)."},{label:"capture",insertText:"capture ${1:Name}\n source ${2:api}",documentation:"Declares a change data capture converting external data into events (CDL)."},{label:"reaction",insertText:"reaction ${1:Name}\n when ${2:Trigger}",documentation:"Declares behavior that runs when something happens."},{label:"screen",insertText:"screen ${1:Name}\n data ${2:ReadModel} via query ${3:QueryName}",documentation:"Declares a UI screen."},{label:"constraint",insertText:"constraint ${1:Name}\n unique ${2:property} on ${3:EventType}",documentation:"Declares a server-side rule enforced before events are committed."}],Mu=[Ke,{label:"property",insertText:"${1:property} ${2:Type}",documentation:"An input of the command \u2014 a name and a type reference."},{label:"produces operation",insertText:"produces operation ${1:Name}\n uses ${2:System}\n ${3:input} ${4:Type} = ${5:source}",documentation:"Declares ordered operation intent; not admitted by any supported executable model (ESM) version yet (PLAY0268)."},{label:"returns property",insertText:"returns @${1:property}",documentation:"Scalar response from a direct command property, only on acceptance. Executable as ESM v7."},{label:"returns block",insertText:"returns\n ${1:field} = ${2:property}",documentation:"Unnamed record response with inferred or explicit field types, only on acceptance. Executable as ESM v7."},{label:"produces event",insertText:"produces event ${1:Name}\n ${2:property} ${3:Type} = ${4:source}",documentation:"Declares a slice-owned generation-1 event and maps its properties. An omitted for uses the command identifier."},{label:"identifier property",insertText:"${1:property} ${2:Type} identifier",documentation:"Marks the property a runtime resolves the event source id from. At most one per command."},{label:"authorize",insertText:"authorize ${1:PolicyName}",documentation:"References the policies that must pass for the command to execute."},{label:"reads",insertText:"reads ${1:View} by ${2:property}",documentation:"Declares a view the command consults. Executable binding is not yet supported."},{label:"reads as",insertText:"reads ${1:View} as ${2:alias} by ${3:property}",documentation:"Names one instance of a view; every instance needs a unique alias when reading the same view more than once."},{label:"validate",insertText:'validate\n ${1:property} not empty message "${2:message}"',documentation:"Declarative validation rules with messages."},{label:"validate csharp",insertText:`validate
8
- ${ye("csharp")}`,documentation:"Imperative validation in C#, yielding the message of every rule the artifact breaks."},{label:"produces",insertText:"produces ${1:EventType}\n ${2:property} = ${3:source}",documentation:"Declares the event the command emits, with property mappings."},{label:"produces when",insertText:"produces when ${1:condition}\n ${2:EventType}\n ${3:property} = ${4:source}",documentation:"Conditionally emits an event when the condition holds."},{label:"description",insertText:'description "${1:what the command asks for}"',documentation:"A human-readable description."},{label:"concurrency",insertText:"concurrency\n ${1|eventSource,sourceType,streamType,streamId,events|}",documentation:"The scope of the concurrency check made when the command appends events."},{label:"handler",insertText:`handler
9
- `,documentation:"Fully imperative command implementation \u2014 file reference or inline C#, instead of produces."}],rs=[{label:"property",insertText:"${1:property} ${2:Type}",documentation:"A property of the event \u2014 a name and a type reference."},{label:"description",insertText:'description "${1:what happened}"',documentation:"Authoring metadata, as one line or a text/markdown fence."},{label:"documentation",insertText:"documentation\n ```markdown\n ${1:Details}\n ```",documentation:"Authoring-only Markdown documentation."},{label:"id",insertText:'id "${1:OldName}"',documentation:"Preserves a previous persisted event name after a rename. Leave absent for new events."},{label:"tag",insertText:"tag ${1:audit}",documentation:"An event-type tag stamped on every occurrence."}],Nu=[...rs,{label:"for",insertText:"for ${1:identifier}",documentation:"Explicitly names the command identifier used as the event source."},{label:"property mapping",insertText:"${1:property} ${2:Type} = ${3:source}",documentation:"Declares and maps an event property on one line."}],ju=[{label:"when",insertText:"when ${1:condition}",documentation:"Guards the produced event with a condition."}],Lu=[{label:"hint",insertText:'hint "${1:implementation guidance}"',documentation:"Ordered nonblank guidance for a handler implementation. Not an execution guarantee."},{label:"file",insertText:"file ${1:Path}",documentation:"Selects one existing model-relative attachment."},...["csharp","typescript","react","html","sql"].map(t=>({label:t,insertText:ye(t),documentation:"Selects one inline payload. Handler execution remains unsupported."}))],qu=[{label:"implementation",insertText:'implementation\n hint "${1:implementation guidance}"',documentation:"Handler-only implementation intent with optional file or tagged fence. With no payload it is pending."},{label:"file",insertText:"file ${1:Path}",documentation:"Delegates the command implementation to an external C# file."},{label:"csharp",insertText:ye("csharp"),documentation:"Inline C# returning the events to append."}],Bu=[{label:"description",insertText:'description "${1:what this query is trying to accomplish}"',documentation:"What the query is for, in prose \u2014 what a generator or reviewer works from."},{label:"by",insertText:"by ${1:param} ${2:Type}",documentation:"Declares the identifying parameter of the query."},{label:"filter",insertText:"filter ${1:param} ${2:Type} optional",documentation:"Declares an optional filter parameter supplied by the caller."},{label:"filter from context",insertText:"filter ${1:param} ${2:Type} from $context.${3|tenant,causedBy.subject,occurred|}",documentation:"Declares a parameter filled from the query context instead of the caller."},{label:"authorize",insertText:"authorize ${1:PolicyName}",documentation:"References the policies that must pass for the query to execute."},{label:"performer",insertText:`performer
10
- `,documentation:"The code that performs the query \u2014 a file reference or an inline csharp/sql block."}],Fu=[{label:"file",insertText:"file ${1:Path}",documentation:"Delegates the query implementation to an external file."},{label:"csharp",insertText:ye("csharp"),documentation:"Inline C# returning the query result, with the QueryContext in scope as context."},{label:"sql",insertText:ye("sql"),documentation:"Inline SQL returning the query result."}],Yu=[{label:"unique",insertText:"unique ${1:property} on ${2:EventType}",documentation:"Enforces a unique property value across an event type."},{label:"unique event",insertText:"unique event ${1:EventType}",documentation:"Enforces that the event type occurs at most once per event source."},{label:"file",insertText:"file ${1:Path}",documentation:"Delegates the constraint to a custom C# implementation."}],Wu=[Ke,{label:"description",insertText:'description "${1:what this reaction does}"',documentation:"What the reaction does \u2014 a complete statement of intent before any code exists."},{label:"when",insertText:"when ${1:Trigger}",documentation:"An event, a declared trigger or a host signal that sets the reaction off. A trigger needs no body."},{label:"every",insertText:"every ${1:15} ${2|seconds,minutes,hours,days|}",documentation:"Runs the reaction on an interval."},{label:"at",insertText:"at ${1:08:00}",documentation:"Runs the reaction at a time of day \u2014 every day unless narrowed with `on <Weekday>` or `on day <n>`."},{label:"where",insertText:"where ${1:condition}",documentation:"Narrows which occurrences actually run the reaction."}],Uu=[{label:"reads",insertText:"reads ${1:View}",documentation:"The view this trigger consults. Optionally use `as <alias> by <trigger value>`; clock triggers take no values and cannot use `by`."},{label:"description",insertText:'description "${1:what this reaction does}"',documentation:"What this particular reaction does \u2014 enough on its own, with no file to point at."},{label:"produces",insertText:"produces ${1:EventType}",documentation:"An event the reaction appends."},{label:"invokes",insertText:"invokes ${1:Command}",documentation:"A command the reaction hands on. A command is asked for, not produced \u2014 it may still be rejected."},{label:"file",insertText:"file ${1:Path}",documentation:"Delegates the reaction to an external C# file."},{label:"csharp",insertText:ye("csharp"),documentation:"Inline C# returning event side effects."}],Ze="Syntax-only; reaction refusal handling and redelivery are not yet executable (PLAY0268).",zu=[{label:"on refused",insertText:`on refused
11
- acknowledge`,documentation:`Handles validation and constraint refusals, not authorization. ${Ze}`},{label:"on refused by validation",insertText:`on refused by validation
12
- acknowledge`,documentation:`Handles validation refusals. ${Ze}`},{label:"on refused by constraint",insertText:"on refused by constraint ${1:Name}\n acknowledge",documentation:`Handles a named constraint refusal; omit the name for any constraint. ${Ze}`},{label:"on refused by authorization",insertText:`on refused by authorization
13
- acknowledge`,documentation:`Explicitly handles unauthorized results, never Unsupported. ${Ze}`}],Vu=[{label:"acknowledge",insertText:"acknowledge",documentation:`Acknowledges alone, without productions. ${Ze}`},{label:"produces",insertText:"produces ${1:Event}\n ${2:reason} = \\$refusal.reason",documentation:`Records the refusal with ordinary event productions. ${Ze}`}],Qu=[{label:"file",insertText:"file ${1:Path}",documentation:"Names the repository relative file this declaration is realized by, so the document can be navigated back to the code."},{label:"description",insertText:'description "${1:when this occurs}"',documentation:"What makes an occurrence of this trigger happen."},{label:"value",insertText:"${1:name} ${2:Type}",documentation:"A value an occurrence hands the reaction. The type is optional."}],Gu=[{label:"description",insertText:'description "${1:rule or case witnessed}"',documentation:"Authoring-only description of what this scenario demonstrates."},{label:"when redelivered",insertText:"when redelivered ${1:Event} to ${2:Reaction}\n for ${3:value}",documentation:`Selects exactly one given event occurrence for one event-trigger reaction; does not append it again. ${Ze}`},{label:"given operation fails",insertText:"given operation ${1:Name} fails",documentation:"Failure fixture leaf; not admitted by any supported executable model (ESM) version yet (PLAY0268)."},{label:"then operation",insertText:"then operation ${1:Name}\n ${2:input} = ${3:value}",documentation:"Partial requested-operation assertion; not admitted by any supported executable model (ESM) version yet (PLAY0268)."},{label:"then compensated",insertText:"then compensated ${1:Name}",documentation:"Compensation assertion leaf; not admitted by any supported executable model (ESM) version yet (PLAY0268)."},{label:"file",insertText:"file ${1:Path}",documentation:"Names the repository relative file this declaration is realized by, so the document can be navigated back to the code."},{label:"given",insertText:"given ${1:EventType}\n ${2:property} = ${3:value}",documentation:"Establishes prior state by replaying an event before the command runs."},{label:"given readmodel",insertText:"given readmodel ${1:ReadModelType}\n ${2:property} = ${3:value}",documentation:"Establishes prior read model state directly."},{label:"when",insertText:"when ${1:CommandType}\n ${2:property} = ${3:value}",documentation:"The command being exercised."},{label:"then",insertText:"then ${1:EventType}\n ${2:property} = ${3:value}",documentation:"An event expected to be produced by the command."},{label:"then readmodel",insertText:"then readmodel ${1:ReadModelType}\n ${2:property} = ${3:value}",documentation:"The read model state expected after the command."},{label:"then no readmodel",insertText:"then no readmodel ${1:ReadModelType} for ${2:key}",documentation:"Asserts that precisely one keyed read-model instance does not exist; another key may still be present."},{label:"then query",insertText:"then query ${1:QueryName}\n arguments\n ${2:argument} = ${3:value}\n result\n ${4:property} = ${5:value}",documentation:"The ordered query results expected for explicit arguments. Remove the result block to assert an empty result."},{label:"then error",insertText:"then error",documentation:"A rejection, for a reason this specification does not name."},{label:'then error "..."',insertText:'then error "${1:reason}"',documentation:"A rejection, for the named reason."},{label:"given clock",insertText:'given clock "${1:2026-10-05T08:00:00Z}"',documentation:"The instant the scenario happens at - the occurrence time of everything it does. At most once."},{label:"given capture",insertText:"given capture ${1:Capture}\n ${2:field} = ${3:value}",documentation:"A record the capture's source held before."},{label:"when clock",insertText:'when clock "${1:2026-10-05T09:00:00Z}"',documentation:"The clock reaches an instant, as the action."},{label:"when trigger",insertText:"when trigger ${1:Trigger}\n ${2:value} = ${3:value}",documentation:"An application trigger fires, as the action."},{label:"when capture",insertText:"when capture ${1:Capture}\n ${2:field} = ${3:value}",documentation:"The record a capture's source holds now, as the action."},{label:"when query",insertText:"when query ${1:Query}\n ${2:argument} = ${3:value}",documentation:"Performs a query, as the action."},{label:"then result",insertText:"then result\n ${1:property} = ${2:value}",documentation:"One result the query performed by `when query` returns, in order."},{label:"then no result",insertText:"then no result",documentation:"The query performed by `when query` returns nothing."},{label:"then no events",insertText:"then no events",documentation:"Syntax-only assertion of no new events after a non-append action (PLAY0268); cannot accompany event, error or denial expectations."}],Lr={given:[{label:"operation",insertText:"operation ${1:Name} fails",documentation:"Syntax-only failure fixture; no children."},{label:"clock",insertText:'clock "${1:2026-10-05T08:00:00Z}"',documentation:"The instant the scenario happens at - the occurrence time of everything it does."},{label:"capture",insertText:"capture ${1:Capture}\n ${2:field} = ${3:value}",documentation:"A record the capture's source held before. Repeat it for several records."},{label:"readmodel",insertText:"readmodel ${1:ReadModelType}\n ${2:property} = ${3:value}",documentation:"Establishes prior read model state directly."},{label:"caller",insertText:"caller\n ${1:authenticated}",documentation:"The identity the scenario runs as."}],when:[{label:"redelivered",insertText:"redelivered ${1:Event} to ${2:Reaction}\n for ${3:value}",documentation:`Selects exactly one given event occurrence for one reaction. ${Ze}`},{label:"clock",insertText:'clock "${1:2026-10-05T09:00:00Z}"',documentation:"The clock reaches an instant - what a scheduled reaction responds to."},{label:"trigger",insertText:"trigger ${1:Trigger}\n ${2:value} = ${3:value}",documentation:"An application trigger fires, with the values it carries."},{label:"capture",insertText:"capture ${1:Capture}\n ${2:field} = ${3:value}",documentation:"The record a capture's source holds now."},{label:"query",insertText:"query ${1:Query}\n ${2:argument} = ${3:value}",documentation:"Performs a query; assert what it returns with `then result` or `then no result`."},{label:"append",insertText:"append ${1:EventType}\n ${2:property} = ${3:value}",documentation:"An event occurs, instead of a command being executed."}],then:[{label:"operation",insertText:"operation ${1:Name}\n ${2:input} = ${3:value}",documentation:"Syntax-only partial operation assertion; not admitted by any supported executable model (ESM) version yet."},{label:"compensated",insertText:"compensated ${1:Name}",documentation:"Syntax-only compensation assertion; no children."},{label:"returns value",insertText:"returns ${1:value}",documentation:"Scalar response expectation, compared by semantic value equality. Executable as ESM v7."},{label:"returns block",insertText:"returns\n ${1:field} = ${2:value}",documentation:"Nonempty subset of response fields asserted by name. Executable as ESM v7."},{label:"result",insertText:"result\n ${1:property} = ${2:value}",documentation:"One result the query performed by `when query` returns, in order."},{label:"result exactly",insertText:"result exactly\n ${1:property} = ${2:value}",documentation:"One result, with every property asserted."},{label:"no result",insertText:"no result",documentation:"The query performed by `when query` returns nothing."},{label:"no events",insertText:"no events",documentation:"Syntax-only assertion of no new events after a non-append action; not yet executable (PLAY0268)."},{label:"readmodel",insertText:"readmodel ${1:ReadModelType}\n ${2:property} = ${3:value}",documentation:"The read model state expected afterwards."},{label:"error",insertText:'error "${1:reason}"',documentation:"A rejection, for the named reason."},{label:"denied",insertText:"denied",documentation:"The action is denied to the caller."}]},os=[{label:"hint",insertText:'hint "${1:predicate guidance}"',documentation:"Ordered nonblank authoring guidance. Does not execute or confirm the predicate."},{label:"file",insertText:"file ${1:Path}",documentation:"The sole named-rule predicate attachment."},{label:"csharp",insertText:ye("csharp"),documentation:"Opaque named-rule predicate returning a bool. Requires an admitting target."}],Ku=[{label:"implementation",insertText:'implementation\n hint "${1:predicate guidance}"',documentation:"Command named-rule intent with optional file or tagged fence. Pending intent cannot bind."},...os.filter(t=>t.label!=="hint")],Zu=[{label:"file",insertText:"file ${1:Path}",documentation:"Gives the named predicate its implementation in an external C# file."},{label:"csharp",insertText:ye("csharp"),documentation:"Gives the named predicate its implementation as inline C# returning a bool."}],_u=[{label:"require authenticated",insertText:"require authenticated",documentation:"Requires an authenticated caller."},{label:"require role",insertText:'require role "${1:role}"',documentation:"Requires the caller to have a role."},{label:"require not role",insertText:'require not role "${1:role}"',documentation:"Excludes callers with a role. Add authenticated to require a signed-in caller."},{label:"require not claim",insertText:'require not claim "${1:claim}" matches ${2:subject}',documentation:"Requires that no claim value matches the subject or a value."},{label:"require claim",insertText:'require claim "${1:claim}" matches ${2:subject}',documentation:"Requires a claim to match the subject or a value."},{label:"csharp",insertText:ye("csharp"),documentation:"Fully custom policy logic in C#, returning a bool."}],Ju=[{label:"not empty",insertText:'${1:property} not empty message "${2:message}"',documentation:"The property must have a value."},{label:"max",insertText:'${1:property} max ${2:500} message "${3:message}"',documentation:"Maximum length or value."},{label:"min",insertText:'${1:property} min ${2:1} message "${3:message}"',documentation:"Minimum length or value."},{label:"matches",insertText:'${1:property} matches "${2:pattern}" message "${3:message}"',documentation:"The property must match a regular expression."},{label:"rule",insertText:'${1:property} rule ${2:PredicateName} message "${3:message}"',documentation:"Names a predicate \u2014 optionally followed by an indented `file` reference or inline `csharp` block giving it a body; bare, it just states that a constraint exists."},{label:"==",insertText:'${1:property} == ${2:value} message "${3:message}"',documentation:"The property must equal the value."},{label:"!=",insertText:'${1:property} != ${2:value} message "${3:message}"',documentation:"The property must not equal the value."},{label:"length ==",insertText:'${1:property} length == ${2:3} message "${3:message}"',documentation:"The property must have an exact length."},{label:"all >",insertText:'${1:collection}.${2:property} all > ${3:0} message "${4:message}"',documentation:"Every element of a collection must satisfy the comparison."}],Hu=[{label:"data",insertText:"data ${1:ReadModel} via query ${2:QueryName}",documentation:"Binds a read model to the screen through a query."},{label:"action",insertText:"action ${1:CommandName}",documentation:"Makes a command available as an action on the screen."},{label:'action "\u2026"',insertText:'action "${1:Label}"\n when item.${2:status} == "${3:open}" execute ${4:CommandName}\n otherwise hidden',documentation:"One labeled button selecting the first matching command; hidden without a subject or match."},{label:"layout",insertText:"layout ${1:LayoutName}",documentation:"Uses a layout template and fills its slots."},{label:"section",insertText:"section ${1:name}",documentation:"A named structural section of the screen."},{label:"table",insertText:'table ${1:name}\n column ${2:property} label "${3:text}"',documentation:"A table widget over a read model or collection."},{label:"summary",insertText:'summary ${1:ReadModel}\n field ${2:property} label "${3:text}"',documentation:"A summary widget showing labeled fields."},{label:"title",insertText:'title "${1:text}"',documentation:"The title of the screen or section."},{label:"file",insertText:"file ${1:Path}",documentation:"Full external implementation \u2014 Stage uses the referenced file."},{label:"react",insertText:ye("react"),documentation:"Inline React/TSX component receiving the data contract as Props."},{label:"typescript",insertText:ye("typescript"),documentation:"Inline plain TypeScript."},{label:"html",insertText:ye("html"),documentation:"Inline static HTML."}],as=[{label:"navigate to",insertText:"navigate to ${1:ScreenName}",documentation:"Navigates to a screen after the action completes."},{label:"label",insertText:'label "${1:text}"',documentation:"The display label of the action."}],Xu=[{label:"when \u2026 execute",insertText:'when item.${1:status} == "${2:open}" execute ${3:CommandName}',documentation:"First matching alternative selects the command; authorization never falls through."},{label:"otherwise hidden",insertText:"otherwise hidden",documentation:"Hides the action when no alternative matches; also the default."},{label:"otherwise execute",insertText:"otherwise execute ${1:CommandName}",documentation:"Selects a fallback command when no alternative matches and a subject exists."},...as.filter(t=>t.label!=="label")],em=[{label:"with \u2026 from",insertText:"with ${1:property} from item.${2:property}",documentation:"Explicit input binding for this command alternative, before same-name item fields or its form."}],tm=[{label:"column",insertText:'column ${1:property} label "${2:text}"',documentation:"A column bound to a property."},{label:"on row-click",insertText:"on row-click navigate to ${1:ScreenName} by ${2:param}",documentation:"Navigates when a row is clicked."}],nm=[{label:"$context.occurred",insertText:"$context.occurred",documentation:"When the command or query was received."},{label:"$context.tenant",insertText:"$context.tenant",documentation:"The tenant the command or query is executing for."},{label:"$context.command.",insertText:"$context.command.${1:property}",documentation:"A property of the command being handled."},{label:"$context.arguments.",insertText:"$context.arguments.${1:name}",documentation:"An argument of the query being performed."},{label:"$context.causedBy.subject",insertText:"$context.causedBy.subject",documentation:"Subject of the identity that caused the command or query."},{label:"$context.causedBy.name",insertText:"$context.causedBy.name",documentation:"Display name of the identity that caused the command or query."},{label:"$context.causedBy.userName",insertText:"$context.causedBy.userName",documentation:"User name of the identity that caused the command or query."},{label:"$context.causation.type",insertText:"$context.causation.type",documentation:"What caused this \u2014 a command, a reactor, a schedule."},{label:"$context.identity.id",insertText:"$context.identity.id",documentation:"The identifier of the caller from the auth token."},{label:"$context.identity.name",insertText:"$context.identity.name",documentation:"The display name of the caller."},{label:"$context.identity.userName",insertText:"$context.identity.userName",documentation:"The user name of the caller."},{label:"$context.identity.isAuthenticated",insertText:"$context.identity.isAuthenticated",documentation:"Whether the caller is authenticated."},{label:"$context.identity.roles",insertText:"$context.identity.roles",documentation:"The roles the caller holds."},{label:"$context.identity.claims.",insertText:"$context.identity.claims.${1:name}",documentation:"The value of a claim the caller carries."},{label:"$env.",insertText:"$env.${1:VAR_NAME}",documentation:"An environment variable."},...gi.filter(t=>t.name!=="value").map(t=>({label:`$eventContext.${t.path}`,insertText:`$eventContext.${t.path}`,documentation:`${t.description} (PDL)`}))],ss={StateChange:["operation","file","description","event","event generation","command","constraint","screen","specification"],StateView:["file","description","readmodel","query","query observable","projection","reducer","screen","specification","event","event generation"],Automation:["operation","file","description","reaction","reducer","command","event","event generation","readmodel","specification"],Translate:["file","description","capture","event","event generation","specification"]};function im(t){let e=t?ss[t]:void 0;return e?jr.filter(n=>n.label==="example"||n.label==="documentation"||e.includes(n.label)):jr}l(im,"sliceItemsFor");var p={ConflictingScreenDataBinding:"PLAY0530",ScreenDataQueryMismatch:"PLAY0531",ActionWithoutInputSurface:"PLAY0532",CommandWithoutInputSurface:"PLAY0533",ReadModelFieldWithoutOrigin:"PLAY0534",QueryParameterNotHeldByView:"PLAY0535",UnconsumedEvent:"PLAY0536",UnreachableScreen:"PLAY0537",UnknownActionSubjectField:"PLAY0345",UnresolvedActionSubject:"PLAY0346",UnreachableActionAlternative:"PLAY0347",UnknownActionArgumentProperty:"PLAY0348",UnreachableRefusalBranch:"PLAY0540",InvalidRefusalValue:"PLAY0541",UnknownRefusalConstraint:"PLAY0542",UnknownRedeliveryReaction:"PLAY0544",IndeterminateNegatedClaimTarget:"PLAY0546",InvalidRefusalBranch:"PLAY0538",InvalidRefusalBranchBody:"PLAY0539",UnmatchedRedeliveredOccurrence:"PLAY0543",InvalidNoEventsExpectation:"PLAY0545",InvalidProducesDeclaration:"PLAY0042",ProducesWhenWithoutEvent:"PLAY0043",InvalidPropertyMapping:"PLAY0044",DuplicateProducesTarget:"PLAY0193",EventSourceIdInPayload:"PLAY0469",ExplicitProducesTargetsRequired:"PLAY0470",RedundantEventId:"PLAY0471",InvalidEventId:"PLAY0472",InlineEventCollision:"PLAY0473",InlineEventOutsideCommand:"PLAY0474",InlineEventGeneration:"PLAY0475",ReservedProductionMetadata:"PLAY0476",InvalidEventDocumentation:"PLAY0477",OmittedProductionDestination:"PLAY0478",UnknownConstraintProperty:"PLAY0391",UnknownTopLevelConstruct:"PLAY0001",InvalidDomainDeclaration:"PLAY0002",DuplicateDomain:"PLAY0003",DomainNotFirst:"PLAY0004",InvalidImportDeclaration:"PLAY0005",TabIndentation:"PLAY0006",InvalidConceptDeclaration:"PLAY0007",UnknownPrimitiveType:"PLAY0008",InvalidEnumerationValue:"PLAY0009",UnknownConceptDirective:"PLAY0010",ValidateReadAsEnumerationBlock:"PLAY0011",AttributeReasonWithoutAttribute:"PLAY0012",DuplicateAttributeReason:"PLAY0013",InvalidTypeDeclaration:"PLAY0014",TypeWithoutProperties:"PLAY0015",InvalidPropertyDeclaration:"PLAY0016",IdentifierOutsideCommand:"PLAY0017",InvalidEventDeclaration:"PLAY0018",IdentifierOnEventProperty:"PLAY0019",TagPropertyReadAsTag:"PLAY0020",InvalidModuleDeclaration:"PLAY0021",UnknownModuleDirective:"PLAY0022",InvalidFeatureDeclaration:"PLAY0023",UnknownFeatureDirective:"PLAY0024",InvalidSliceDeclaration:"PLAY0027",UnknownSliceType:"PLAY0028",UnknownSliceDirective:"PLAY0029",InvalidPersonaDeclaration:"PLAY0030",InvalidPersonaPolicyReference:"PLAY0031",UnknownPersonaDirective:"PLAY0032",InvalidCommandDeclaration:"PLAY0033",UnknownCommandDirective:"PLAY0034",DuplicateCommandIdentifier:"PLAY0036",InvalidQueryDeclaration:"PLAY0047",UnknownQueryDirective:"PLAY0048",InvalidQueryParameter:"PLAY0049",InvalidProjectionDeclaration:"PLAY0056",EmptyProjection:"PLAY0057",UnknownProjectionDirective:"PLAY0058",FromWithoutEvent:"PLAY0061",InvalidEventReference:"PLAY0062",InvalidJoinDeclaration:"PLAY0063",JoinWithoutEvent:"PLAY0064",InvalidChildrenDeclaration:"PLAY0065",InvalidNestedDeclaration:"PLAY0066",NestedBlockWithoutFrom:"PLAY0067",InvalidRemoveDeclaration:"PLAY0068",UnknownRemoveDirective:"PLAY0069",InvalidClearDeclaration:"PLAY0070",ClearWithOutsideNestedBlock:"PLAY0071",InvalidSpecificationDeclaration:"PLAY0094",UnknownSpecificationDirective:"PLAY0095",InvalidSpecificationWhen:"PLAY0096",DuplicateSpecificationWhen:"PLAY0097",InvalidThenError:"PLAY0098",InvalidReadModelStep:"PLAY0099",InvalidEventStep:"PLAY0100",InvalidSpecificationValue:"PLAY0101",InvalidScreenDeclaration:"PLAY0102",UnknownScreenDirective:"PLAY0103",InvalidDataDirective:"PLAY0104",InvalidActionDirective:"PLAY0105",UnknownActionDirective:"PLAY0106",InvalidNavigation:"PLAY0107",InvalidScreenLayoutSlot:"PLAY0108",InvalidTitleDirective:"PLAY0109",UnknownTableDirective:"PLAY0110",UnknownSummaryDirective:"PLAY0111",AuthorizeWithoutPolicy:"PLAY0122",InvalidPolicyReference:"PLAY0123",InvalidConstraintDeclaration:"PLAY0132",ConstraintWithoutRule:"PLAY0133",InvalidConstraintBody:"PLAY0134",DuplicateConstraintBody:"PLAY0135",InvalidReactionDeclaration:"PLAY0136",InvalidReactionTrigger:"PLAY0137",ReactionWithoutTrigger:"PLAY0138",InvalidValidateDeclaration:"PLAY0140",InvalidValidationRule:"PLAY0141",InvalidRuleName:"PLAY0143",UnknownRuleImplementationDirective:"PLAY0144",InvalidDescription:"PLAY0145",EmptyDescription:"PLAY0146",DuplicateDescription:"PLAY0147",TagWithoutValue:"PLAY0148",InvalidTagValue:"PLAY0149",UnknownContextPath:"PLAY0153",UnknownContextCausedByProperty:"PLAY0154",UnknownContextIdentityProperty:"PLAY0155",ExpectedCodeFence:"PLAY0163",UnclosedCodeBlock:"PLAY0164",DuplicateDeclaration:"PLAY0168",RepeatedSingularDeclarationAcrossFiles:"PLAY0172",RepeatedDeclarationAcrossFiles:"PLAY0173",ConflictingDescriptionAcrossFiles:"PLAY0174",UnexpectedTokenInAuthorize:"PLAY0184",UnclosedAuthorizeGroup:"PLAY0185",InvalidReadModelDeclaration:"PLAY0186",InvalidInvokesDeclaration:"PLAY0194",InvalidScopeDeclaration:"PLAY0199",DuplicateScope:"PLAY0200",InvalidIntervalTrigger:"PLAY0249",InvalidScheduleTrigger:"PLAY0250",DuplicateReactionTrigger:"PLAY0253",InvalidSpecificationEventSource:"PLAY0275",DuplicateSpecificationEventSource:"PLAY0276",InvalidProjectionVariantDeclaration:"PLAY0277",InvalidEntersOnDeclaration:"PLAY0279",NestedProjectionVariantNotAllowed:"PLAY0280",InvalidStructuredValue:"PLAY0291",DuplicateStructuredValueMember:"PLAY0294",ConflictingSpecificationActions:"PLAY0358",InvalidSpecificationEventOrder:"PLAY0359",InvalidValidationSeverity:"PLAY0368",VariantRequiresEnteringEvent:"PLAY0382",DuplicateProjectionVariant:"PLAY0384",DuplicateVariantEnteringEvent:"PLAY0385",InvalidSpecificationDenied:"PLAY0388",DuplicateAuthorizationAcrossFiles:"PLAY0394",FileConstraintOnlySupportsUniqueness:"PLAY0396",LegacyInlineCodeFence:"PLAY0397",InvalidEventGeneration:"PLAY0446",InvalidFileImport:"PLAY0454",FileImportMatchesNothing:"PLAY0455",ImportedFileNotFound:"PLAY0456",ConflictingImportPlacement:"PLAY0457",ImportCycle:"PLAY0458",ModuleInPlacedFile:"PLAY0459",UnexpectedInPlacedFile:"PLAY0460",InvalidSpecificationClock:"PLAY0461",InvalidSpecificationTrigger:"PLAY0462",InvalidSpecificationCapture:"PLAY0463",InvalidSpecificationQueryAction:"PLAY0464",InvalidSpecificationQuery:"PLAY0265",UnknownSpecificationQueryDirective:"PLAY0266",DuplicateSpecificationQueryArguments:"PLAY0267",InvalidAbsentReadModelStep:"PLAY0453",LegacyOptionalSuffix:"PLAY0479",InvalidOptionalModifierOrder:"PLAY0480",OptionalReadsNotSupported:"PLAY0481",InvalidSpecificationCaller:"PLAY0386",DuplicateSpecificationCallerOrDenied:"PLAY0387",GeneratedPropertyOutsideCommand:"PLAY0482",InvalidGeneratedType:"PLAY0483",InvalidGeneratedModifierOrder:"PLAY0484",GeneratedPropertySuppliedAsInput:"PLAY0485",InvalidCommandResponse:"PLAY0486",InvalidResponseSource:"PLAY0487",DuplicateResponseField:"PLAY0488",InvalidResponseShape:"PLAY0489",InvalidGeneratedFixture:"PLAY0490",InvalidReturnExpectation:"PLAY0491",InvalidImplementationBlock:"PLAY0492",InvalidImplementationHint:"PLAY0493",ConflictingImplementationSources:"PLAY0494",UnknownType:"PLAY0165",InvalidSystemDeclaration:"PLAY0495",InvalidOperationDeclaration:"PLAY0496",InvalidProductionReference:"PLAY0497",ProductionDeclarationCollision:"PLAY0498",OperationOutsideCommand:"PLAY0499",InvalidSystemReference:"PLAY0500",InvalidOperationMapping:"PLAY0501",InvalidOperationSpecification:"PLAY0502",InvalidCaptureDeclaration:"PLAY0078",UnknownCaptureDirective:"PLAY0079",InvalidMapEntry:"PLAY0080",InvalidTranslation:"PLAY0081",InvalidSplitDeclaration:"PLAY0082",InvalidSplitTarget:"PLAY0083",InvalidAppendDeclaration:"PLAY0084",UnknownAppendDirective:"PLAY0085",WhenWithoutTrigger:"PLAY0086",InvalidWhenClause:"PLAY0087",InvalidWhenTransitionClause:"PLAY0088",MixedWhenCombinators:"PLAY0089",WhenCombinatorWithoutProperty:"PLAY0090",UnknownCaptureBlockDirective:"PLAY0091",InvalidCompositeKeyPart:"PLAY0072",TemplateInCompositeKey:"PLAY0073",EmptyCompositeKey:"PLAY0074",InvalidProjectionMapping:"PLAY0075",ExpectedLiteralValue:"PLAY0150",InvalidExpression:"PLAY0152",UnterminatedInterpolation:"PLAY0157",UnterminatedTemplateExpression:"PLAY0156",ProjectionDocumentWithoutProjection:"PLAY0055",CaptureDocumentWithoutCapture:"PLAY0077",SpecificationDocumentWithoutSpecification:"PLAY0093",InvalidSeedDeclaration:"PLAY0128",InvalidSeedGroup:"PLAY0129",InvalidSeedEvent:"PLAY0130",InvalidSeedPropertyAssignment:"PLAY0131",InvalidPolicyDeclaration:"PLAY0112",UnknownPolicyDirective:"PLAY0113",PolicyWithoutRequirement:"PLAY0114",ExpectedRoleName:"PLAY0118",ExpectedClaimName:"PLAY0119",ExpectedClaimMatches:"PLAY0120",ExpectedClaimMatchTarget:"PLAY0121",MixedPolicyImplementation:"PLAY0440",RepeatedPolicyRequirement:"PLAY0441",UnexpectedTokenInPolicyCondition:"PLAY0115",ExpectedPolicyCondition:"PLAY0116",UnclosedPolicyConditionGroup:"PLAY0117",UnexpectedTokenInCondition:"PLAY0158",ExpectedCondition:"PLAY0159",ExpectedComparisonOperator:"PLAY0161",ExpectedComparisonValue:"PLAY0162",InvalidActionAlternative:"PLAY0341",GuardedActionWithoutAlternatives:"PLAY0342",MisplacedActionOtherwise:"PLAY0343",UnsupportedActionConditionOperand:"PLAY0344",InvalidInteractionArgument:"PLAY0319",UnclosedConditionGroup:"PLAY0160",InvalidNumericDirective:"PLAY0508",DuplicateNumericDirective:"PLAY0509",LateNumericDirective:"PLAY0510",InexactNumericLiteral:"PLAY0511",MixedNumericModes:"PLAY0512",IncompatibleNumericSource:"PLAY0513",EventFromLaterSlice:"PLAY0516",TimelineCycleGroup:"PLAY0517",InvalidSpecificationExample:"PLAY0518",DuplicateSpecificationAssignment:"PLAY0519",UnresolvedSpecificationExampleType:"PLAY0520",SpecificationExampleNameCollision:"PLAY0521",SpecificationExampleKindMismatch:"PLAY0522",InvalidSpecificationExampleValue:"PLAY0523",MissingSpecificationProperty:"PLAY0524",UnadmittedSpecificationExampleValue:"PLAY0525",InvalidSpecificationExampleBody:"PLAY0526",AmbiguousReference:"PLAY0198",InvalidSpecificationStream:"PLAY0547",SpecificationStreamOnCommand:"PLAY0548",InvalidSpecificationStreamRoute:"PLAY0549",InvalidSpecificationStreamEventSource:"PLAY0550",SpecificationStreamContradictsCommand:"PLAY0551",InvalidDependencyTarget:"PLAY0554",RepeatedDependencyDeclaration:"PLAY0555",UndeclaredDependency:"PLAY0552",UnusedDependencyDeclaration:"PLAY0553",MutualDependencyDeclarations:"PLAY0556",AuthorizationRefusalWithoutIdentity:"PLAY0557",InvalidDocumentation:"PLAY0558",ConflictingDocumentationAcrossFiles:"PLAY0559",InvalidEventSourceDeclaration:"PLAY0503",InvalidCommandStream:"PLAY0504",AmbiguousCommandStream:"PLAY0505",UnsupportedStreamIdType:"PLAY0506",RedundantSourceStreamId:"PLAY0507",UnknownEvent:"PLAY0166",UnknownReadModelProperty:"PLAY0514",PiiNotSupportedOnIdentifier:"PLAY0515",HandlerWithoutImplementation:"PLAY0045",UnknownHandlerDirective:"PLAY0046",CommandWithProducesAndHandler:"PLAY0035",AbsoluteFileReference:"PLAY0264",InvalidTriggerData:"PLAY0246"};var bi="\\p{L}\\p{Mn}\\p{Nd}\\p{Pc}",z="[\\u0009-\\u000d\\u0020\\u0085\\u00a0\\u1680\\u2000-\\u200a\\u2028\\u2029\\u202f\\u205f\\u3000]";function V(t){let e=`(?=[\\u0000-\\uFFFF])[${bi}]`,n=t.replace(/\[([^\]]*\\w[^\]]*)\]/g,(i,r)=>{let o=r.replaceAll("\\w","");return o===""?`(?:${e})`:`(?:${e}|[${o}])`});return new RegExp(n.replaceAll("\\w",`(?:${e})`),"u")}l(V,"nativePattern");function O(t){let e="",n=!1;for(let i=0;i<t.length;i++){let r=t[i];if(r==="\\"&&i+1<t.length){let o=t[i+1];i++,o==="w"?e+=n?bi:`[${bi}]`:o==="d"?e+="\\p{Nd}":e+=`\\${o}`;continue}r==="["&&!n?n=!0:r==="]"&&n&&(n=!1),e+=r}return new RegExp(e,"u")}l(O,"pattern");var ls=new RegExp(`^depends${z}+on(?:${z}|$)`,"u"),cs=new RegExp(`${z}+$`,"u");function ut(t,e=!1,n){let i=[],r=0,o=0;for(let s of t.split(`
14
- `)){r++;let a=s.endsWith("\r")?s.replace(/\r+$/,""):s,c=a.length-a.trimStart().length,d=ds(a.substring(c),e),m=ls.test(d)?d.replace(cs,""):d.trimEnd();i.push(n===void 0?{number:r,raw:a,indent:c,content:m,startOffset:o}:{number:r,raw:a,indent:c,content:m,path:n,startOffset:o}),o+=s.length+1}return i}l(ut,"splitLines");function Rt(t,e=!1){let n=!1,i=!1;for(let r=0;r<t.length;r++){let o=t[r];if(o==="\\"&&n&&r+1<t.length)r++;else if(o==='"'&&!i)n=!n;else if(o==="`"&&!n)i=!i;else if(!n&&!i&&(o==="/"&&r+1<t.length&&t[r+1]==="/"||e&&o==="#"))return r}return-1}l(Rt,"commentStart");function ds(t,e){let n=Rt(t,e);return n<0?t:t.substring(0,n)}l(ds,"stripComment");function se(t){return[...t.events,...t.commands.flatMap(e=>e.produces).flatMap(e=>e.inlineEvent===null?[]:[e.inlineEvent])]}l(se,"eventDeclarations");function ln(t){return[...t.operations??[],...t.commands.flatMap(e=>e.produces).flatMap(e=>e.inlineOperation==null?[]:[e.inlineOperation])]}l(ln,"operationDeclarations");var ee;(function(t){t.Event="event",t.Operation="operation",t.Unresolved="unresolved",t.Ambiguous="ambiguous"})(ee||(ee={}));var re=class{static{l(this,"AuthoringProductionResolver")}declarations=[];slices=[];byName=new Map;scopes=new Map;resolutions=new Map;constructor(e){let n=l((i,r)=>{for(let o of i){let s=[...r,o.name];for(let a of o.slices)this.slices.push({slice:a,scope:[...s,a.name]});n(o.features,s)}},"collect");e.modules.forEach(i=>n(i.features,[i.name]));for(let{slice:i,scope:r}of this.slices){this.scopes.set(i,r);let o=new Map;for(let a of se(i)){let c=o.get(a.name)??[];c.push(a),o.set(a.name,c)}let s=[...o.values()].flatMap(a=>new Set(a.map(c=>c.generation)).size!==a.length?a:[a.reduce((c,d)=>c.generation>=d.generation?c:d)]);this.declarations.push(...s.map(a=>({kind:ee.Event,name:a.name,node:a,scope:r})),...ln(i).map(a=>({kind:ee.Operation,name:a.name,node:a,scope:r})))}for(let i of this.declarations){let r=this.byName.get(i.name)??[];r.push(i),this.byName.set(i.name,r)}}resolve(e,n){let i=this.scopes.get(n);if(i===void 0)return{kind:ee.Unresolved,declaration:null,candidates:[]};let r=this.resolutions.get(n)??new Map,o=r.get(e);if(o!==void 0)return o;let s=this.candidates(e,i),a=s.length===1?{kind:s[0].kind,declaration:s[0],candidates:[]}:{kind:s.length===0?ee.Unresolved:ee.Ambiguous,declaration:null,candidates:s};return r.set(e,a),this.resolutions.set(n,r),a}isOperation(e,n){return e.inlineOperation!=null||this.resolve(e.event,n).kind===ee.Operation}isEventProduction(e,n){if(e.inlineOperation!=null)return!1;let i=this.resolve(e.event,n);return i.kind!==ee.Operation&&!(i.kind===ee.Ambiguous&&i.candidates.some(r=>r.kind===ee.Operation))}candidates(e,n){let i=e.split("."),r=this.byName.get(i.at(-1))??[],o=i.slice(0,-1);if(o.length>0)return r.filter(s=>o.length<=s.scope.length&&o.every((a,c)=>s.scope[s.scope.length-o.length+c]===a));for(let s=n.length;s>=0;s--){let a=r.filter(c=>s<=c.scope.length&&n.slice(0,s).every((d,m)=>c.scope[m]===d));if(a.length>0)return a}return[]}};function cn(t){let e=new re(t);return e.slices.flatMap(({slice:n})=>n.commands.flatMap(i=>{let r=i.properties.filter(o=>o.isIdentifier&&!o.type.isOptional&&!o.type.isCollection);return r.length!==1?[]:i.produces.filter(o=>e.isEventProduction(o,n)&&o.inlineEvent===null&&o.when===null&&o.for===null).map(o=>({severity:"information",code:p.OmittedProductionDestination,message:`Plain 'produces ${o.event}' omits its destination - use 'for ${r[0].name}' to explicitly select the command's identifier.`,location:o.location}))}))}l(cn,"productionDestinationDiagnostics");function dn(t,e){let n=new re(t).slices.map(r=>r.slice),i=n.flatMap(se);for(let r of n)for(let o of r.constraints.flatMap(s=>[s,...s.additionalRules])){if(o.kind!=="UniquePropertyConstraintSyntax")continue;let s=i.filter(a=>a.name===o.event);if(s.length!==0)for(let a of[o.property,...o.additionalProperties])a.includes(".")||s.some(c=>c.properties.some(d=>d.name===a))||e.error(p.UnknownConstraintProperty,`Constraint '${o.name}' names property '${a}', which event '${o.event}' does not declare.`,o.location)}}l(dn,"validateConstraintProperties");var qr=l((t,e)=>t.length===e.length&&t.every((n,i)=>n===e[i]),"same"),pn=l(t=>[...t.scope,t.name].join("."),"addressOf"),he=class{static{l(this,"DeclaredDependencyTargets")}static containersOf(e){let n=[],i=l((r,o)=>{n.push({name:r.name,scope:o}),r.features.forEach(s=>i(s,[...o,r.name]))},"inventory");for(let r of e.modules)n.push({name:r.name,scope:[]}),r.features.forEach(o=>i(o,[r.name]));return[...new Map(n.map(r=>[pn(r),r])).values()]}static candidates(e,n){let i=e.join(".");return n.flatMap(r=>{let o=pn(r);if(o===i||o.startsWith(i+".")||i.startsWith(o+"."))return[];let s=[...r.scope,r.name];for(let a=1;a<=s.length;a++){let c=s.slice(-a).join(".");if(this.resolve(c,e,n).resolved!==r)continue;let d=a===1?e.length-1-r.scope.length:"qualified";return[{container:r,reference:c,tier:d}]}return[]}).sort((r,o)=>(r.tier==="qualified"?e.length:r.tier)-(o.tier==="qualified"?e.length:o.tier))}static resolve(e,n,i){let r=e.split(".");if(r.length>1){let o=i.filter(s=>qr([...s.scope,s.name].slice(-r.length),r));return o.length===1?{resolved:o[0],ambiguous:[]}:{ambiguous:o}}for(let o=n.length-1;o>=0;o--){let s=i.filter(a=>a.name===e&&qr(a.scope,n.slice(0,o)));if(s.length>0)return s.length===1?{resolved:s[0],ambiguous:[]}:{ambiguous:s}}return{ambiguous:[]}}};function fn(t,e){let n=l(a=>(a.dependsOn?.length??0)>0||a.features.some(n),"hasDependencies");if(!t.modules.some(n))return t;let i=he.containersOf(t),r=new Map,o=l((a,c)=>{let d=[],m=c.join(".");r.has(m)||r.set(m,new Set);let u=r.get(m);for(let y of a){let h=he.resolve(y.target,c,i),v=h.resolved===void 0?void 0:pn(h.resolved),x=v===void 0?`text:${y.target}`:`resolved:${v}`;if(u.has(x)){e.warning(p.RepeatedDependencyDeclaration,`Dependency '${y.target}' is already declared on this container - this repeated declaration is ignored`,y.location);continue}u.add(x),d.push(y),h.ambiguous.length>0?e.warning(p.AmbiguousReference,`Ambiguous dependency target '${y.target}' - candidates: ${h.ambiguous.map(pn).join(", ")}`,y.location):(v===void 0||v===m||v.startsWith(m+".")||m.startsWith(v+"."))&&e.warning(p.InvalidDependencyTarget,`Invalid dependency target '${y.target}' on '${m}' - the target must resolve to another module or feature, not self, an ancestor, or a descendant`,y.location)}return d},"keep"),s=l((a,c)=>{let d=[...c,a.name];return{...a,dependsOn:o(a.dependsOn??[],d),features:a.features.map(m=>s(m,d))}},"normalize");return{...t,modules:t.modules.map(a=>({...a,dependsOn:o(a.dependsOn??[],[a.name]),features:a.features.map(c=>s(c,[a.name]))}))}}l(fn,"validateDependencyDeclarations");var lt=[],Dt=l(t=>t.length===0,"isDocumentPlacement");function un(t){return t.length===0?"the application":t.length===1?`module '${t[0]}'`:`feature '${t.join(".")}'`}l(un,"describePlacement");var mt=l((t,e,n)=>n===void 0?{line:t,column:e}:{line:t,column:e,path:n},"sourceLocation");var Ei=l(t=>t.content.length===0,"isBlank"),f=l(t=>mt(t.number,t.indent+(t.contentOffset??0)+1,t.path),"locationOf"),Br=l(t=>mt(t.number,1,t.path),"startOf");var ps=O("^(?:(?:or|and)\\s+)?[A-Za-z_(][\\w\\s()]*$"),fs=new RegExp(O("\\(|\\)|[A-Za-z_]\\w*").source,"gu"),us=O("^[A-Z]\\w*$");function _e(t,e){let n=e.content.substring(9);for(let a=t.peekChild(e.indent);a!==void 0&&ps.test(a.content);a=t.peekChild(e.indent))t.reader.takeSignificant(),n+=` ${a.content}`;let i=ms(n),r=f(e);if(i.length===0)return t.error(p.AuthorizeWithoutPolicy,"Expected at least one policy after 'authorize'",r),null;let s=new Ci(t,i,r).parse();return s===null?null:{kind:"AuthorizeSyntax",requirement:s,location:r}}l(_e,"parseAuthorize");function Re(t,e){return t===null?e:e===null?t:{kind:"AuthorizeSyntax",requirement:{kind:"LogicalPolicyRequirementSyntax",left:t.requirement,operator:"And",right:e.requirement,location:t.location},location:t.location}}l(Re,"combineAuthorize");function ms(t){let e=[];for(let n of t.match(fs)??[])e.length>0&&ys(e[e.length-1])&&hs(n)&&e.push("and"),e.push(n);return e}l(ms,"tokenize");var Fr=l(t=>t!=="("&&t!==")"&&t!=="and"&&t!=="or","isName"),ys=l(t=>t===")"||Fr(t),"isOperandEnd"),hs=l(t=>t==="("||Fr(t),"isOperandStart"),Ci=class{static{l(this,"RequirementParser")}context;tokens;location;#e=0;constructor(e,n,i){this.context=e,this.tokens=n,this.location=i}parse(){let e=this.#t();return e!==null&&this.#e<this.tokens.length&&this.context.error(p.UnexpectedTokenInAuthorize,`Unexpected '${this.tokens[this.#e]}' in authorize`,this.location),e}#t(){return this.#r("or","Or",()=>this.#o())}#o(){return this.#r("and","And",()=>this.#n())}#r(e,n,i){let r=i();for(;r!==null&&this.tokens[this.#e]===e;){this.#e++;let o=i();if(o===null)return null;r={kind:"LogicalPolicyRequirementSyntax",left:r,operator:n,right:o,location:this.location}}return r}#n(){if(this.tokens[this.#e]!=="(")return this.#i();this.#e++;let e=this.#t();return this.tokens[this.#e]===")"?this.#e++:this.context.error(p.UnclosedAuthorizeGroup,"Expected ')' in authorize",this.location),e}#i(){if(this.#e>=this.tokens.length)return this.context.error(p.AuthorizeWithoutPolicy,"Expected a policy name",this.location),null;let e=this.tokens[this.#e++];return us.test(e)?{kind:"PolicyReferenceSyntax",name:e,location:this.location}:(this.context.error(p.InvalidPolicyReference,`Invalid policy reference '${e}' - policy names are PascalCase identifiers`,this.location),null)}};var _='(?:[^"\\\\]|\\\\.)*',Ss={"\\":"\\",'"':'"',n:`
15
- `,r:"\r",t:" "};function H(t){if(!t.includes("\\"))return t;let e="";for(let n=0;n<t.length;n++){let i=n+1<t.length?Ss[t[n+1]]:void 0;t[n]==="\\"&&i!==void 0?(e+=i,n++):e+=t[n]}return e}l(H,"unescapeString");function yt(t,e,n,i=!1){let o=n.content.startsWith("```")?n:t.reader.peekSignificant(),s=e==="description"?"```text":`\`\`\`${e}`;if(o===void 0||o!==n&&o.indent<=n.indent||o.content!==s&&!(i&&e==="description"&&o.content==="```markdown")&&!(o.content==="```"&&o!==n))return t.error(p.ExpectedCodeFence,`Expected an opening \`\`\`${e==="description"?"text":e} fence after '${e}'`,f(n)),null;o!==n&&t.reader.takeSignificant(),e==="description"&&o.content==="```"&&t.warning(p.LegacyInlineCodeFence,"A bare description fence is deprecated - use '```text' instead",f(o));let a=[];for(;;){let c=t.reader.takeRaw();if(c===void 0){t.error(p.UnclosedCodeBlock,"Unclosed inline code block - expected a closing ``` line",f(o));break}if(c.raw.trim()==="```")break;let d=0;for(;d<o.indent&&d<c.raw.length&&c.raw[d]===" ";)d++;a.push(c.raw.substring(d))}return a.join(`
16
- `)}l(yt,"parseFencedText");var gs=O(`^description\\s+"(${_})"$`);function G(t,e,n,i,r=!1){if(e.content==="description"){let s=yt(t,"description",e,r);return s===null?n:s.trim().length===0?(t.error(p.EmptyDescription,`${i} declares an empty description - the fenced block must contain text`,f(e)),n):Yr(t,e,n,i,s)}let o=gs.exec(e.content);return o===null?(t.error(p.InvalidDescription,`Invalid description '${e.content}' - expected 'description "<text>"'`,f(e)),n):Yr(t,e,n,i,H(o[1]))}l(G,"parseDescription");function Yr(t,e,n,i,r){return n!==null?(t.error(p.DuplicateDescription,`${i} already declares a description - at most one is allowed`,f(e)),n):r}l(Yr,"keep");function ue(t,e,n,i,r=p.InvalidDocumentation){if(e.content!=="documentation"||t.peekChild(e.indent)?.content!=="```markdown")return t.error(r,`${i} documentation requires a fenced markdown block`,f(e)),t.skipOpaqueBlock(e.indent),n;let o=yt(t,"markdown",e);return o===null||o.trim().length===0||n!==null?(t.error(r,`${i} accepts one nonempty documentation block`,f(e)),n):o}l(ue,"parseDocumentation");var xs=V(`^depends${z}+on${z}+([A-Za-z_]\\w*(?:\\.[A-Za-z_]\\w*)*)$`);function mn(t,e,n,i){let r=xs.exec(e.content)?.[1];if(r===void 0){t.error(i,`Invalid dependency declaration '${e.content}' - expected 'depends on <Name>'`,f(e)),t.skipBlock(e.indent);return}if(n.some(o=>o.target===r)){t.warning(p.RepeatedDependencyDeclaration,`Dependency '${r}' is already declared on this container - this repeated declaration is ignored`,f(e));return}n.push({kind:"DependsOnSyntax",target:r,location:f(e)})}l(mn,"parseDependsOn");var vs=O('^import\\s+"([^"\\\\]+)"$'),$s=O('^import\\s+"'),Wr=l(t=>$s.test(t),"isFileImport");function Ur(t){let e=vs.exec(t.content);return e===null?void 0:{kind:"FileImportSyntax",pattern:e[1],location:f(t)}}l(Ur,"tryParseFileImport");function ht(t,e,n){let i=Ur(e);if(i!==void 0){n.push(i);return}t.error(p.InvalidFileImport,`Invalid import '${e.content}' - inside a module or feature, import names files: 'import "<path or glob>"'`,f(e)),t.skipBlock(e.indent)}l(ht,"parseFileImport");var R=l(t=>{let e=t.indexOf(" ");return e===-1?t:t.substring(0,e)},"firstWord"),X=l(t=>t.replaceAll("@",""),"unescapeIdentifier");function zr(t,e){let n=[],i=0,r=!1,o=!1;for(let s=0;s<t.length;s++){let a=t[s];a==="\\"&&r&&s+1<t.length?s++:a==='"'&&!o?r=!r:a==="`"&&!r?o=!o:a===e&&!r&&!o&&(n.push(t.substring(i,s)),i=s+1)}return n.push(t.substring(i)),n}l(zr,"splitTopLevel");var ks=O("^form\\s+[A-Za-z_]\\w*\\s+for\\s+([A-Za-z_]\\w*(?:\\.\\w+)*)$"),bs=O("^(execute|invokes)\\s+([A-Za-z_]\\w*(?:\\.\\w+)*)$"),Es=O("^field\\s+([\\w.]+)(?:\\s|$)"),Cs=O("^with\\s+([A-Za-z_]\\w*)\\s+from\\s+.+$"),Ps=O("^(@?[\\w.]+)\\s*=(?!=|>)\\s*.+$"),As=O("^parameter\\s+([A-Za-z_]\\w*)(?:\\s+([\\w.]+(?:\\[\\])?))?$"),ws=new Set(["refresh","navigate","open","close","set","notify","confirm","raise","on"]);function Pe(t,e){let n=[],i=new Set,r=[],o=R(e.content)==="behavior",s=l(a=>{for(;n.length>0&&n[n.length-1].indent>=a.indent;)n.pop();let c=o&&n.length===0?As.exec(a.content):null;c!==null&&i.add(c[1]);let d=ks.exec(a.content),m=bs.exec(a.content);if(d!==null)n.push({command:d[1],kind:"form",indent:a.indent});else if(m!==null)n.push({command:m[2],kind:m[1],indent:a.indent});else if(ws.has(R(a.content)))n.push({command:"",kind:"other",indent:a.indent});else{let u=n.at(-1);if(u===void 0||u.kind==="other")return;let y=(u.kind==="form"?Es:u.kind==="execute"?Cs:Ps).exec(a.content);y!==null&&r.push({command:u.command,property:X(y[1]),scope:t.scope,location:f(a)})}},"recognize");s(e);for(let a=t.peekChild(e.indent);a!==void 0;a=t.peekChild(e.indent))t.reader.takeSignificant(),a.content.startsWith("```")?t.skipFencedBody():s(a);for(let a of r)t.inputUses.push(i.has(a.command)?{...a,isParameter:!0}:a)}l(Pe,"collectInputUses");var Pi="79228162514264337593543950335";function qe(t){let e=Vr(t);if(e===void 0)return;let n=e.integer+e.fraction,i=0;for(;i<n.length&&n[i]==="0";)i++;if(i===n.length)return Object.freeze({literalType:"ExactNumber",value:"0"});let r=n.length;for(;n[r-1]==="0";)r--;let o=e.fraction.length-e.exponent-(n.length-r),s=o<0?-o:0;if(o>28||r-i+s>Pi.length)return;let a=n.substring(i,r)+"0".repeat(s);if(a.length===Pi.length&&a>Pi)return;let c=Math.max(0,o),d=c===0?a:a.length>c?`${a.substring(0,a.length-c)}.${a.substring(a.length-c)}`:`0.${"0".repeat(c-a.length)}${a}`;return Object.freeze({literalType:"ExactNumber",value:(e.negative?"-":"")+d})}l(qe,"parseExactNumber");function Mt(t){return Vr(t)!==void 0}l(Mt,"isExactNumberToken");function Vr(t){let e=t.startsWith("-"),n=e?1:0,i=n;for(;i<t.length&&Ai(t[i]);)i++;if(i===n)return;let r=t.substring(n,i),o="";if(t[i]==="."){let a=++i;for(;i<t.length&&Ai(t[i]);)i++;if(i===a)return;o=t.substring(a,i)}let s=0;if(t[i]==="e"||t[i]==="E"){i++;let a=t[i]==="-";(t[i]==="+"||t[i]==="-")&&i++;let c=i,d=t.length+29;for(;i<t.length&&Ai(t[i]);)s=Math.min(d,s*10+t.charCodeAt(i++)-48);if(i===c)return;a&&(s=-s)}return i===t.length?{negative:e,integer:r,fraction:o,exponent:s}:void 0}l(Vr,"scan");function Ai(t){return t>="0"&&t<="9"}l(Ai,"isDigit");var Qr=64,ge=class extends Error{static{l(this,"InvalidStructuredValue")}},yn=class{static{l(this,"StructuredValueParser")}text;start;context;#e=0;constructor(e,n,i){this.text=e,this.start=n,this.context=i}parse(){let e=this.#t(0);if(this.#s(),this.#e<this.text.length)throw new ge(`'${this.text[this.#e]}' is invalid after a single JSON value.`);return e}#t(e){this.#s();let n=this.#l(),i=this.text[this.#e];if(i==="["||i==="{"){if(e>=Qr)throw new ge(`The value nests deeper than ${Qr} levels.`);return i==="["?this.#o(e,n):this.#r(e,n)}if(i==='"')return{kind:"LiteralExpressionSyntax",value:this.#n(),location:n};for(let[r,o]of[["true",!0],["false",!1],["null",null]])if(this.text.startsWith(r,this.#e))return this.#e+=r.length,{kind:"LiteralExpressionSyntax",value:o,location:n};return this.#a(n)}#o(e,n){this.#e++;let i=[];if(this.#s(),this.#c("]"))return{kind:"ListExpressionSyntax",items:i,location:n};for(;;){if(i.push(this.#t(e+1)),this.#s(),this.#c("]"))return{kind:"ListExpressionSyntax",items:i,location:n};this.#d(",")}}#r(e,n){this.#e++;let i=[],r=new Set;if(this.#s(),this.#c("}"))return{kind:"ObjectExpressionSyntax",members:i,location:n};for(;;){this.#s();let o=this.#l();if(this.text[this.#e]!=='"')throw new ge("Expected a property name in double quotes.");let s=this.#n();this.#s(),this.#d(":");let a=this.#t(e+1);if(r.has(s)?this.context?.error(p.DuplicateStructuredValueMember,`Duplicate property '${s}' in structured value`,o):(r.add(s),i.push({kind:"ObjectMemberSyntax",name:s,value:a,location:o})),this.#s(),this.#c("}"))return{kind:"ObjectExpressionSyntax",members:i,location:n};this.#d(",")}}#n(){let e=this.#i(this.#e),n=this.text.substring(this.#e,e);this.#e=e;try{return JSON.parse(n)}catch{throw new ge(`${n} is not a valid JSON string.`)}}#i(e){for(let n=e+1;n<this.text.length;n++)if(this.text[n]==="\\")n++;else if(this.text[n]==='"')return n+1;throw new ge("A string is not closed.")}#a(e){let n=/^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/.exec(this.text.substring(this.#e));if(n===null)throw new ge(`'${this.text[this.#e]??""}' is an invalid start of a value.`);if(this.#e+=n[0].length,this.context?.sourceOptions.numericMode==="exact"){let r=qe(n[0]);return r===void 0?(this.context.error(p.InexactNumericLiteral,"Numeric literal is not exactly representable in the bounded Decimal domain.",e),{kind:"RawExpressionSyntax",text:n[0],location:e}):{kind:"LiteralExpressionSyntax",value:r,location:e}}let i=Number(n[0]);if(!Number.isFinite(i))throw new ge("JSON number is outside the finite Double range.");return{kind:"LiteralExpressionSyntax",value:i,location:e}}#l(){return{...this.start,column:this.start.column+this.#e}}#s(){for(;this.#e<this.text.length&&`
17
- \r`.includes(this.text[this.#e]);)this.#e++}#c(e){return this.text[this.#e]!==e?!1:(this.#e++,!0)}#d(e){if(!this.#c(e))throw new ge(`Expected '${e}' at position ${this.#e}.`)}};var Os=O("^@?[A-Za-z_]\\w*(\\.@?[A-Za-z_$]\\w*)*$"),Is=V("^@?[A-Za-z_]\\w*(\\.@?[A-Za-z_$]\\w*)*$"),Ts=O("^-?\\d+(\\.\\d+)?$"),Gr=["command","arguments","tenant","causedBy","causation","occurred","identity"],Kr=["subject","name","userName"],Zr=["id","name","userName","isAuthenticated","roles","claims"];function xe(t,e,n){return te(t,e,n,!0)}l(xe,"parseModeledMappingSource");function te(t,e,n,i=!1){if(t=t.trim(),t==="$refusal"||t.startsWith("$refusal."))return{kind:"RefusalExpressionSyntax",member:t==="$refusal"?"":t.substring(9),location:e};if(t.startsWith("$context.")){let o=t.substring(9);return Rs(o,e,n),{kind:"ContextExpressionSyntax",path:o,location:e}}if(t.startsWith("$env."))return{kind:"EnvironmentExpressionSyntax",name:t.substring(5),location:e};if(t.startsWith("$strings."))return{kind:"StringsExpressionSyntax",key:t.substring(9),location:e};if(t.startsWith("$."))return{kind:"SourceItemExpressionSyntax",path:t.substring(2),location:e};if(t.startsWith("{")||t.startsWith("["))try{return new yn(t,e,n).parse()}catch(o){if(!(o instanceof ge))throw o;return n?.error(p.InvalidStructuredValue,`Invalid inline structured value: ${o.message}`,e),{kind:"RawExpressionSyntax",text:t,location:e}}let r=n===void 0?Nt(t,e):Nt(t,e,n);return r!==void 0?r:(i||n?.sourceOptions.numericMode==="exact"?Is:Os).test(t)?{kind:"PathExpressionSyntax",path:t,location:e}:{kind:"RawExpressionSyntax",text:t,location:e}}l(te,"parseMappingSource");function Rs(t,e,n){let[i,r]=t.split(".");Gr.includes(i)?r!==void 0&&i==="causedBy"&&!Kr.includes(r)?n?.warning(p.UnknownContextCausedByProperty,`Unknown $context.causedBy property '${r}' - expected ${Kr.join(", ")}`,e):r!==void 0&&i==="identity"&&!Zr.includes(r)&&n?.warning(p.UnknownContextIdentityProperty,`Unknown $context.identity property '${r}' - expected ${Zr.join(", ")}`,e):n?.warning(p.UnknownContextPath,`Unknown $context path '${t}' - expected one of ${Gr.join(", ")}`,e)}l(Rs,"warnOnUnknownContextPath");function Nt(t,e,n){let i=l(o=>({kind:"LiteralExpressionSyntax",value:o,location:e}),"literal");switch(t){case"true":return i(!0);case"false":return i(!1);case"null":return i(null)}if(t.length>=2&&(t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'")))return i(H(t.substring(1,t.length-1)));if(n?.sourceOptions.numericMode==="exact"){if(!Mt(t))return;let o=qe(t);return o!==void 0?i(o):(n.error(p.InexactNumericLiteral,"Numeric literal is not exactly representable in the bounded Decimal domain.",e),{kind:"RawExpressionSyntax",text:t,location:e})}if(Ts.test(t)&&!Number.isNaN(Number(t)))return i(Number(t))}l(Nt,"parseLiteral");var wi=O("^then\\s+returns\\b"),hn=O("^generated\\s+(?=\\S)(?![=])"),Sn=O("^generated\\s+([a-z_]\\w*)\\s*=(?!=|>)\\s*(.+)$"),Ds=O("^([\\w.]+)\\s*=(?!=|>)\\s*(.+)$"),Ms=O(`^(?:"${_}"|'(?:[^'\\\\]|\\\\.)*')$`);function gn(t,e,n,i){if((e.startsWith('"')||e.startsWith("'"))&&!Ms.test(e))return t.error(i,"Expected exactly one concrete value.",n),null;let r=te(e,n,t);return!["LiteralExpressionSyntax","ObjectExpressionSyntax","ListExpressionSyntax"].includes(r.kind)||r.kind==="LiteralExpressionSyntax"&&typeof r.value=="number"&&!Number.isFinite(r.value)?(t.error(i,"Expected exactly one concrete literal or structured value, not an expression.",n),null):r}l(gn,"parseConcrete");function St(t,e,n,i){let r=n.exec(e.content);if(r===null)return t.error(i,"Expected a named fixture or assertion with exactly one concrete value.",f(e)),t.skipBlock(e.indent),null;let o=f(e),s=gn(t,r[2],{...o,column:o.column+e.content.indexOf(r[2],e.content.indexOf("=")+1)},i),a=t.peekChild(e.indent);return a!==void 0&&(t.error(i,"A fixture or return field cannot have child directives.",f(a)),t.skipBlock(e.indent)),s===null?null:{kind:"PropertyMappingSyntax",property:r[1],source:s,location:o}}l(St,"parseConcreteMapping");function _r(t,e){let n=wi.exec(e.content)[0].length,i=e.content.substring(n).trim(),r=f(e);if(i.length>0){let s=gn(t,i,{...r,column:r.column+e.content.indexOf(i,n)},p.InvalidReturnExpectation),a=t.peekChild(e.indent);return a!==void 0&&(t.error(p.InvalidReturnExpectation,"A scalar return expectation cannot have child assertions.",f(a)),t.skipBlock(e.indent)),s===null?null:{kind:"ScalarSpecificationReturnSyntax",value:s,location:r}}let o=[];for(let s=t.peekChild(e.indent);s!==void 0;s=t.peekChild(e.indent)){t.reader.takeSignificant();let a=St(t,s,Ds,p.InvalidReturnExpectation);a!==null&&o.push(a)}return{kind:"RecordSpecificationReturnSyntax",fields:o,location:r}}l(_r,"parseReturn");var Ns=V("^example\\s+([A-Z]\\w*)\\s*:\\s*([A-Z]\\w*(?:\\.\\w+)*)$".replaceAll("\\s",z)),js=V("^([\\w.]+)\\s*=(?!=|>)\\s*(.+)$".replaceAll("\\s",z));function Be(t,e){let n=Ns.exec(e.content);if(n===null)return t.error(p.InvalidSpecificationExample,`Invalid example declaration '${e.content}' - expected 'example <Name> : <EventOrCommandOrReadModel>'`,f(e)),t.skipOpaqueBlock(e.indent),{kind:"SpecificationExampleSyntax",name:"",type:"",values:[],generatedValues:[],for:null,description:null,location:f(e)};let i=Ls(t,e,void 0,!0,n[1]);return{kind:"SpecificationExampleSyntax",name:n[1],type:n[2],...i,location:f(e)}}l(Be,"parseExample");function xn(t,e,n,i){if(n?.groups?.property===void 0)return;let r=n.groups.property,o=n.groups.value,s=e.content.length-o.length,a=f(e),c=gn(t,o,{...a,column:a.column+s},p.InvalidSpecificationValue);c!==null&&i.push({kind:"PropertyMappingSyntax",property:r,source:c,location:{...a,column:a.column+e.content.lastIndexOf(r,e.content.indexOf("="))}})}l(xn,"addInlineValue");function jt(t,e,n,i=[]){if([...e,...i].some(r=>r.property===n.property)){t.error(p.DuplicateSpecificationAssignment,`Property '${n.property}' is assigned more than once in this fixture - assign it only once, inline or indented`,n.location);return}e.push(n)}l(jt,"addFixtureValue");function Ls(t,e,n,i=!1,r){let o=[],s=[],a=null,c=null;xn(t,e,n,o);for(let d=t.peekChild(e.indent);d!==void 0;d=t.peekChild(e.indent)){if(t.reader.takeSignificant(),r!==void 0&&R(d.content)==="description"){c=G(t,d,c,`Example '${r}'`);continue}if(i&&hn.test(d.content)){let u=St(t,d,Sn,p.InvalidGeneratedFixture);u!==null&&(r===void 0?s.push(u):jt(t,s,u,o));continue}let m=js.exec(d.content);if(r!==void 0&&(R(d.content)==="streamId"||R(d.content)==="stream"&&m===null||d.content.startsWith("no stream"))){t.error(p.InvalidSpecificationExampleBody,"An example cannot declare stream, streamId or no stream; state the route on the specification step.",f(d)),t.skipOpaqueBlock(d.indent);continue}if(m!==null)jt(t,o,{kind:"PropertyMappingSyntax",property:m[1],source:te(m[2],f(d),t),location:f(d)},s);else if(R(d.content)==="for"){let u=d.content.substring(3).trim();u.length===0?t.error(p.InvalidSpecificationEventSource,"Invalid event-source assertion 'for' - expected 'for <value>'",f(d)):a!==null?t.error(p.DuplicateSpecificationEventSource,"A specification step can declare its event-source assertion only once",f(d)):a=te(u,f(d),t)}else t.error(p.InvalidSpecificationValue,`Invalid property mapping '${d.content}' - expected '<property> = <value>'`,f(d))}return{values:o,for:a,generatedValues:s,description:c}}l(Ls,"parseFixtureBody");var Jr=["StateChange","StateView","Automation","Translate"];var Lt=["tag"];var qs=O(`^id\\s+"(${_})"$`),gt=class{static{l(this,"EventMetadataParser")}name;value={id:null,description:null,documentation:null};constructor(e){this.name=e}tryParse(e,n){let i=f(n);switch(R(n.content)){case"id":{let r=qs.exec(n.content),o=r===null?"":H(r[1]);return o.trim().length===0||this.value.id!==null?e.error(p.InvalidEventId,`Event '${this.name}' accepts one nonempty 'id "<old-name>"'`,i):(this.value.id=o,o===this.name&&e.information(p.RedundantEventId,`Event '${this.name}' already has this name as its identity - remove the redundant id`,i)),!0}case"description":return this.value.description=G(e,n,this.value.description,`Event '${this.name}'`,!0),!0;case"documentation":return this.value.documentation=ue(e,n,this.value.documentation,`Event '${this.name}'`,p.InvalidEventDocumentation),!0;default:return!1}}};var Bs=O("^[A-Za-z_]\\w*(?:\\[\\])?(?:\\?|\\s+optional)?$"),Hr=l(t=>R(t.content)==="file"?t.content.substring(4).trim():"","pathOf"),le=l(t=>Hr(t).length>0,"isFileDirective"),vn=l(t=>le(t)&&!Bs.test(Hr(t)),"isFileDirectiveAmongProperties");var Fs=O("^(@?[a-z_]\\w*)\\s+([\\w.]+(?:\\[\\])?(?:\\?|\\s+optional)?)(?:\\s+(generated))?(?:\\s+(identifier))?$"),Ys=O("^@?[a-z_]\\w*\\s+[\\w.]+(?:\\[\\])?\\??\\s+((?:optional|generated|identifier)(?:\\s+(?:optional|generated|identifier))*)$"),Ws=O("^@?[a-z_]\\w*\\s+[\\w.]+(?:\\[\\])?\\s+identifier\\s+optional(?:\\s*=.*)?$");function Je(t){let e=Fs.exec(t.content);if(e===null)return;let n=f(t);return{kind:"PropertySyntax",name:X(e[1]),type:ve(e[2],{...n,column:n.column+t.content.indexOf(e[2],e[1].length)}),isGenerated:e[3]!==void 0,nameWasEscaped:e[1].startsWith("@"),isIdentifier:e[4]!==void 0,location:n}}l(Je,"tryParseProperty");function ve(t,e){let n=t.endsWith("?"),i=/\soptional$/.test(t),r=n||i;r&&(t=t.substring(0,t.length-(n?1:8)).trimEnd());let o=t.endsWith("[]");return o&&(t=t.substring(0,t.length-2)),{kind:"TypeRefSyntax",name:t,isCollection:o,isOptional:r,location:e}}l(ve,"parseTypeRef");function De(t,e){let n=Je(e);return n!==void 0?Ae(t,n.type,e):$n(t,e),n}l(De,"parseProperty");function Ae(t,e,n){t.claimField(n);let i=e.name.length+(e.isCollection?2:0),r=e.location.column-n.indent-1+i;if(e.isOptional&&n.content[r]==="?"){let o=e.name+(e.isCollection?"[]":"");t.information(p.LegacyOptionalSuffix,`Write '${o} optional' instead of '${o}?'.`,e.location)}}l(Ae,"reportLegacyOptionalSuffix");function $n(t,e){if(Ws.test(e.content))return t.error(p.InvalidOptionalModifierOrder,"Write 'optional' before 'identifier': '<name> <Type> optional identifier'.",f(e)),!0;{let n=Ys.exec(e.content);if(n!==null&&n[1].split(/\s+/).some(i=>i==="generated"||i==="identifier"))return t.error(p.InvalidGeneratedModifierOrder,"Write each modifier once in order: '<name> <Type> optional generated identifier'.",f(e)),!0}return!1}l($n,"reportInvalidModifierOrder");var Us=O("^type\\s+([A-Za-z_]\\w*)$"),zs=O("^event\\s+([A-Za-z_]\\w*)(?:\\s+generation\\s+([0-9]+))?$"),Vs=O("^readmodel\\s+([A-Za-z_]\\w*)$"),Xr=4294967295,Qs=O("^[A-Z]\\w*(?:\\[\\])?(?:\\?|\\s+optional)?$"),Gs=O("^[A-Za-z_]\\w*$"),eo=l(t=>R(t.content)==="description"&&Je(t)===void 0,"isDescription");function Oi(t,e,n,i,r){return e.isIdentifier?(t.error(i,r,f(n)),{...e,isIdentifier:!1}):e}l(Oi,"withoutIdentifier");function to(t,e){let n=Us.exec(e.content)?.[1]??"";n===""&&t.error(p.InvalidTypeDeclaration,`Invalid type declaration '${e.content}' - expected 'type <Name>'`,f(e));let i=[],r=null;for(let o=t.peekChild(e.indent);o!==void 0;o=t.peekChild(e.indent)){if(t.reader.takeSignificant(),eo(o)){r=G(t,o,r,`Type '${n}'`);continue}if(vn(o))continue;let s=De(t,o);if(s===void 0){t.error(p.InvalidPropertyDeclaration,`Invalid property '${o.content}' - expected '<name> <Type>'`,f(o));continue}i.push(Oi(t,s,o,p.IdentifierOutsideCommand,`Property '${s.name}' of type '${n}' cannot be marked identifier - only a command property can be`))}return i.length===0&&t.error(p.TypeWithoutProperties,`Type '${n}' must declare at least one property`,f(e)),{kind:"TypeSyntax",name:n,properties:i,description:r,location:f(e)}}l(to,"parseType");function no(t,e){let n=zs.exec(e.content),i=n?.[1]??"";n===null&&t.error(p.InvalidEventDeclaration,`Invalid event declaration '${e.content}' - expected 'event <Name> [generation <N>]'`,f(e));let r=n?.[2]!==void 0,o=1;if(r){let d=Number(n[2]);!Number.isSafeInteger(d)||d===0||d>=Xr?t.error(p.InvalidEventGeneration,`Event '${i}' must declare a generation between 1 and ${Xr-1}`,f(e)):o=d}let s=[],a=[],c=new gt(i);for(let d=t.peekChild(e.indent);d!==void 0;d=t.peekChild(e.indent)){if(t.reader.takeSignificant(),vn(d))continue;if(Lt.includes(R(d.content))){let u=qt(t,d);u!==void 0&&a.push(u);continue}let m=De(t,d);if(m===void 0){c.tryParse(t,d)||t.error(p.InvalidPropertyDeclaration,`Invalid property '${d.content}' - expected '<name> <Type>'`,f(d));continue}s.push(Oi(t,m,d,p.IdentifierOnEventProperty,`Property '${m.name}' of event '${i}' cannot be marked identifier - an event never carries its event source id`))}return{kind:"EventSyntax",name:i,properties:s,tags:a,generation:o,hasGenerationMarker:r,...c.value,location:f(e)}}l(no,"parseEvent");function qt(t,e,n=!0){let i=e.content.substring(3).trim();if(n&&Qs.test(i)&&t.warning(p.TagPropertyReadAsTag,`'${e.content}' declares a static tag with the value '${i}', not a property named 'tag' - write 'tag "${i}"' for the tag, or '@${e.content}' for the property`,f(e)),i.length===0){t.error(p.TagWithoutValue,"Expected a value after 'tag' - an identifier, a string literal or a context expression",f(e));return}if(Gs.test(i))return{kind:"TagSyntax",value:{kind:"LiteralExpressionSyntax",value:i,location:f(e)},location:f(e)};let r=te(i,f(e),t);if(r.kind==="RawExpressionSyntax"){t.error(p.InvalidTagValue,`Invalid tag value '${i}' - expected an identifier, a string literal or a context expression`,f(e));return}return{kind:"TagSyntax",value:r,location:f(e)}}l(qt,"parseTag");function io(t,e){let n=Vs.exec(e.content)?.[1]??"";n===""&&t.error(p.InvalidReadModelDeclaration,`Invalid read model declaration '${e.content}' - expected 'readmodel <Name>'`,f(e));let i=[],r=null,o=null;for(let s=t.peekChild(e.indent);s!==void 0;s=t.peekChild(e.indent))if(t.reader.takeSignificant(),eo(s))r=G(t,s,r,`Read model '${n}'`);else if(R(s.content)==="documentation"&&Je(s)===void 0)o=ue(t,s,o,`Read model '${n}'`);else{if(vn(s))continue;{let a=De(t,s);if(a===void 0){t.error(p.InvalidPropertyDeclaration,`Invalid property '${s.content}' - expected '<name> <Type>'`,f(s));continue}i.push(Oi(t,a,s,p.IdentifierOutsideCommand,`Property '${a.name}' of read model '${n}' cannot be marked identifier - only a command property can be`))}}return{kind:"ReadModelSyntax",name:n,properties:i,description:r,documentation:o,location:f(e)}}l(io,"parseReadModel");var Ks=V("^@?[A-Za-z_]\\w*(\\.@?[A-Za-z_$]\\w*)*$");function ce(t,e,n){if(n=n.valueContext,t=t.trim(),t.startsWith("`")){let o=[];if(!t.endsWith("`")||t.length<2)return n.error(p.UnterminatedTemplateExpression,"Unterminated template expression - expected a closing backtick",e),{kind:"TemplateExpressionSyntax",parts:o,location:e};let s=t.substring(1,t.length-1),a=0;for(let c=0;c<s.length;c++){if(s[c]!=="$"||s[c+1]!=="{")continue;c>a&&o.push({kind:"TemplateTextSyntax",text:s.substring(a,c),location:e});let d=s.indexOf("}",c);if(d<0)return n.error(p.UnterminatedInterpolation,"Unterminated ${...} interpolation in template expression",e),{kind:"TemplateExpressionSyntax",parts:o,location:e};o.push({kind:"TemplateInterpolationSyntax",expression:ce(s.substring(c+2,d),e,n),location:e}),c=d,a=d+1}return a<s.length&&o.push({kind:"TemplateTextSyntax",text:s.substring(a),location:e}),{kind:"TemplateExpressionSyntax",parts:o,location:e}}let i=t.startsWith("literal ")?t.substring(8).trim():t;if(n.sourceOptions.numericMode==="exact"&&(i.startsWith("{")||i.startsWith("[")))return xe(i,e,n);if(t.startsWith("literal ")){let o=Nt(t.substring(8).trim(),e,n);return o!==void 0?o:(n.error(p.ExpectedLiteralValue,`Expected a literal value after 'literal', got '${t.substring(8).trim()}'`,e),{kind:"RawExpressionSyntax",text:t,location:e})}if(t==="$refusal"||t.startsWith("$refusal."))return{kind:"RefusalExpressionSyntax",member:t==="$refusal"?"":t.substring(9),location:e};if(t==="$eventSourceId")return{kind:"EventSourceIdExpressionSyntax",location:e};if(t.startsWith("$eventContext."))return{kind:"EventContextExpressionSyntax",path:t.substring(14),location:e};if(t==="$causedBy")return{kind:"CausedByExpressionSyntax",property:null,location:e};if(t.startsWith("$causedBy."))return{kind:"CausedByExpressionSyntax",property:t.substring(10),location:e};let r=Nt(t,e,n);return r!==void 0?r:Ks.test(t)?{kind:"PathExpressionSyntax",path:t.replaceAll("@",""),location:e}:(n.error(p.InvalidExpression,`Invalid expression '${t}'`,e),{kind:"RawExpressionSyntax",text:t,location:e})}l(ce,"parseProjectionExpression");var bn=l(t=>({legacy:O(t),native:V(t)}),"grammar"),Zs=bn("^capture\\s+([A-Za-z_]\\w*)$"),_s=bn("^append\\s+([A-Z]\\w*)$"),Js=bn("^children\\s+([a-z_]\\w*)\\s+identified\\s+by\\s+([\\w.]+)$"),Hs=bn("^nested\\s+([\\w.]+)$"),kn=l((t,e)=>t.sourceOptions.numericMode==="exact"?e.native:e.legacy,"select"),Xs=V("^(@?[\\w.]+)\\s*=(?!=|>)\\s*(.+)$"),el=V("^([a-z_]\\w*)\\s*=\\s*(.+)$"),tl=V(`^"(${_})"\\s*=>\\s*(\\w+)$`),nl=V(`^split\\s+(\\S+)\\s+by\\s+"(${_})"$`),il=new RegExp(V(`"${_}"|[\\w.]+`).source,"gu"),rl=V("^[\\w.]+$");function Ii(t,e){t=t.valueContext;let n=kn(t,Zs).exec(e.content)?.[1]??"";n===""&&t.sourceOptions.numericMode==="exact"&&t.error(p.InvalidCaptureDeclaration,`Invalid capture declaration '${e.content}' - expected 'capture <Name>'`,f(e));let i=null,r=null,o=[],s=[],a=[],c=[];for(let d=t.peekChild(e.indent);d!==void 0;d=t.peekChild(e.indent))switch(t.reader.takeSignificant(),R(d.content)){case"source":i=ol(t,d);break;case"key":r=d.content.substring(3).trim();break;case"map":o.push(...oo(t,d));break;case"append":ao(t,d,s);break;case"children":{let m=kn(t,Js).exec(d.content);if(m===null){t.error(p.InvalidChildrenDeclaration,`Invalid children declaration '${d.content}' - expected 'children <collection> identified by <key>'`,f(d)),t.skipOpaqueBlock(d.indent);break}let u=ro(t,d);m!==null&&a.push({kind:"CaptureChildrenSyntax",property:m[1],identifiedBy:m[2],...u,location:f(d)});break}case"nested":{let m=kn(t,Hs).exec(d.content);if(m===null){t.error(p.InvalidNestedDeclaration,`Invalid nested declaration '${d.content}' - expected 'nested <Property>'`,f(d)),t.skipOpaqueBlock(d.indent);break}let u=ro(t,d);m!==null&&c.push({kind:"CaptureNestedSyntax",property:m[1],...u,location:f(d)});break}default:t.error(p.UnknownCaptureDirective,`Unexpected '${d.content}' in capture body`,f(d)),t.skipOpaqueBlock(d.indent)}return{kind:"CaptureSyntax",sourceOptions:t.sourceOptions,name:n,source:i,key:r,map:o,appends:s,children:a,nested:c,location:f(e)}}l(Ii,"parseCapture");function ol(t,e){let n=[];for(let i=t.peekChild(e.indent);i!==void 0;i=t.peekChild(e.indent)){t.reader.takeSignificant();let r=R(i.content);n.push({kind:"CaptureSourceSettingSyntax",name:r,value:i.content.substring(r.length).trim(),location:f(i)})}return{kind:"CaptureSourceSyntax",syntaxKind:e.content.substring(6).trim(),settings:n,location:f(e)}}l(ol,"parseSource");function oo(t,e){let n=[];for(let i=t.peekChild(e.indent);i!==void 0;i=t.peekChild(e.indent)){t.reader.takeSignificant();let r=f(i);if(R(i.content)==="split"){let u=nl.exec(i.content);if(u===null){t.error(p.InvalidSplitDeclaration,`Invalid split operation '${i.content}' - expected 'split <property> by "<separator>"'`,r),t.skipOpaqueBlock(i.indent);continue}let y=[];for(let h=t.peekChild(i.indent);h!==void 0;h=t.peekChild(i.indent))t.reader.takeSignificant(),rl.test(h.content)?y.push(h.content):t.error(p.InvalidSplitTarget,`Invalid split target '${h.content}' - expected a property path`,f(h));u!==null&&n.push({kind:"CaptureSplitSyntax",source:ce(u[1],r,t),separator:H(u[2]),targets:y,location:r});continue}let o=el.exec(i.content);if(o===null){t.error(p.InvalidMapEntry,`Invalid map entry '${i.content}' - expected '<property> = <source> [translate]'`,r),t.skipOpaqueBlock(i.indent);continue}let s=o[2].trim(),a=s.startsWith("`")?s.indexOf("`",1):-1,c=s.startsWith("`")?a>=0&&s.substring(a+1).trim()==="translate":s.endsWith(" translate"),d=s.startsWith("`")&&a>=0&&(t.sourceOptions.numericMode!=="exact"||c||s.substring(a+1).trim()==="")?s.substring(0,a+1):c?s.substring(0,s.length-10).trimEnd():s,m=[];if(c)for(let u=t.peekChild(i.indent);u!==void 0;u=t.peekChild(i.indent)){t.reader.takeSignificant();let y=tl.exec(u.content);y!==null?m.push({kind:"CaptureTranslationSyntax",from:H(y[1]),to:y[2],location:f(u)}):t.error(p.InvalidTranslation,`Invalid translation '${u.content}' - expected '"<source>" => <target>'`,f(u))}n.push({kind:"CaptureMapEntrySyntax",property:o[1],source:ce(d,r,t),translations:m,location:r})}return n}l(oo,"parseMap");function ro(t,e){let n=[],i=[];for(let r=t.peekChild(e.indent);r!==void 0;r=t.peekChild(e.indent))t.reader.takeSignificant(),R(r.content)==="map"?n=oo(t,r):R(r.content)==="append"?ao(t,r,i):(t.error(p.UnknownCaptureBlockDirective,`Unexpected '${r.content}' in ${R(e.content)} block - expected 'map' or 'append <EventType>'`,f(r)),t.skipOpaqueBlock(r.indent));return{map:n,appends:i}}l(ro,"mapAndAppends");function ao(t,e,n){let i=kn(t,_s).exec(e.content);if(i===null){t.error(p.InvalidAppendDeclaration,`Invalid append declaration '${e.content}' - expected 'append <EventType>'`,f(e)),t.skipOpaqueBlock(e.indent);return}let r=[],o=[],s=null,a=l((c,d=!1)=>{let m=f(c);if(R(c.content)==="tag"){let y=qt(t.valueContext,c,!1);y!==void 0&&o.push(y);return}let u=Xs.exec(c.content);u!==null?r.push({kind:"PropertyMappingSyntax",property:X(u[1]),source:xe(u[2],m,t.valueContext),location:m}):t.error(d?p.InvalidPropertyMapping:p.UnknownAppendDirective,`Unexpected '${c.content}' in append body`,m)},"mapping");for(let c=t.peekChild(e.indent);c!==void 0;c=t.peekChild(e.indent))if(t.reader.takeSignificant(),R(c.content)==="when"){s=al(t,c);for(let d=t.peekChild(c.indent);d!==void 0;d=t.peekChild(c.indent))t.reader.takeSignificant(),a(d,!0)}else a(c);n.push({kind:"CaptureAppendSyntax",event:i[1],when:s,mappings:r,tags:o,location:f(e)})}l(ao,"pushAppend");function al(t,e){let n=e.content.substring(4).trim(),i=f(e),r=l((c,d=[],m=null,u=null,y=null)=>({kind:"CaptureWhenSyntax",syntaxKind:c,properties:d,fromValue:m,toValue:u,expression:y,location:i}),"value");if(n==="added")return r("Added");if(n==="removed")return r("Removed");if(n.startsWith("`"))return(!n.endsWith("`")||n.length<2)&&t.error(p.UnterminatedTemplateExpression,"Unterminated template expression in 'when' - expected a closing backtick",i),r("Expression",[],null,null,n);if(n.length===0)return t.error(p.WhenWithoutTrigger,"Expected a trigger after 'when'",i),null;let o=[...n.match(t.sourceOptions.numericMode==="exact"?new RegExp(`"${_}"|[^\\s]+`,"gu"):il)??[]],s=l(c=>c.startsWith('"')&&c.endsWith('"')?H(c.substring(1,c.length-1)):c,"unquote");if(o.length===0)return t.error(p.InvalidWhenClause,`Invalid 'when' clause '${e.content}'`,i),null;if(o.length===1)return r("PropertyChanged",[s(o[0])]);if(o[1]==="from")return o.length===5&&o[3]==="to"?r("ValueTransition",[s(o[0])],s(o[2]),s(o[4])):(t.error(p.InvalidWhenTransitionClause,`Invalid 'when ... from ... to ...' clause '${e.content}'`,i),null);if(o[1]!=="or"&&o[1]!=="and")return t.error(p.InvalidWhenClause,`Invalid 'when' clause '${e.content}'`,i),null;if(o.length%2===0)return t.error(p.WhenCombinatorWithoutProperty,`Expected a property after '${o[1]}'`,i),null;let a=[s(o[0])];for(let c=1;c<o.length-1;c+=2){if(o[c]!==o[1])return t.error(p.MixedWhenCombinators,`Cannot mix 'and' and 'or' in a single 'when' clause '${e.content}'`,i),null;a.push(s(o[c+1]))}return r(o[1]==="or"?"LogicalOr":"LogicalAnd",a)}l(al,"parseWhen");var Ti={"==":"Equal","!=":"NotEqual",">":"GreaterThan",">=":"GreaterThanOrEqual","<":"LessThan","<=":"LessThanOrEqual",contains:"Contains","starts with":"StartsWith"};function He(t,e,n,i=!1){i||(t=t.valueContext);let r=i?z:"\\s",o=t.sourceOptions.numericMode==="exact"?`-?[0-9]+(?:\\.[0-9]+)?(?:[eE][+-]?[0-9]+)?(?=$|${r}|[()])|`:"",s=t.sourceOptions.numericMode==="exact"&&!i?"[\\w.$-]+|[^\\s]":"[\\w.$-]+",a=new RegExp(V(`"${_}"|==|!=|>=|<=|>|<|\\(|\\)|${o}${s}`).source,"gu");if(i){let v=e.replace(a,"").replace(new RegExp(z,"gu"),"");if(v.length>0)return t.error(p.UnsupportedActionConditionOperand,`Guarded action conditions contain unsupported character '${v[0]}'`,n),null}let c=e.match(a)??[],d=0,m=l(()=>{if(c[d]==="("){d++;let C=y();return c[d]===")"?d++:(i||t.sourceOptions.numericMode==="exact")&&t.error(p.UnclosedConditionGroup,"Expected ')' in condition",n),C}let v=c[d++];if(i&&v===void 0)return t.error(p.ExpectedCondition,"Expected a condition",n),null;let x=c[d++];if(x==="starts"&&c[d]==="with"&&(x+=" with",d++),i&&!Object.hasOwn(Ti,x))return t.error(p.ExpectedComparisonOperator,`Expected a comparison operator after '${v}'`,n),null;let $=c[d++];return i&&$===void 0?(t.error(p.ExpectedComparisonValue,"Expected a value to compare against",n),null):v===void 0||$===void 0||Ti[x]===void 0?null:{kind:"ComparisonConditionSyntax",left:v,operator:Ti[x],right:xe($,n,t),location:n}},"group"),u=l(()=>{let v=m();for(;v!==null&&c[d]==="and";){d++;let x=m();if(x===null)return null;v={kind:"LogicalConditionSyntax",left:v,operator:"And",right:x,location:n}}return v},"and"),y=l(()=>{let v=u();for(;v!==null&&c[d]==="or";){d++;let x=u();if(x===null)return null;v={kind:"LogicalConditionSyntax",left:v,operator:"Or",right:x,location:n}}return v},"or"),h=y();return(i||t.sourceOptions.numericMode==="exact")&&(h===null&&!i?t.error(p.ExpectedCondition,"Expected a condition",n):h!==null&&d<c.length&&t.error(p.UnexpectedTokenInCondition,`Unexpected '${c[d]}' in condition`,n)),h}l(He,"parseCondition");function de(t){return O(`(?![\\s\\S]*[\\uD800-\\uDFFF\\u{10000}-\\u{10FFFF}])${t}`)}l(de,"sourceStreamPattern");var sl=de("^[A-Za-z_]\\w*(?![\\s\\S])"),ll=de("^[\\w.]+(?![\\s\\S])");function Ri(t){return typeof t=="string"&&sl.test(t)}l(Ri,"isSourceStreamName");function En(t){return typeof t=="string"&&ll.test(t)}l(En,"isSourceStreamTypeName");var cl=O(`^id\\s+"(${_})"$`),dl=de("^(identifier|streamId)\\s+([\\w.]+(?:\\[\\])?(?:\\?|\\s+optional)?)$"),pl=de("^eventsource\\s+([A-Za-z_]\\w*)$"),fl=de("^stream\\s+([A-Za-z_]\\w*)$");function so(t,e){let n=pl.exec(e.content)?.[1]??"";n===""&&Fe(t,e,"Expected 'eventsource <Name>'.");let i=[],r=null,o=null,s=null;for(let a=t.peekChild(e.indent);a!==void 0;a=t.peekChild(e.indent))switch(t.reader.takeSignificant(),R(a.content)){case"stream":i.push(ul(t,a));break;case"identifier":r=lo(t,a,"identifier",r);break;case"description":o=G(t,a,o,`Event source '${n}'`,!0);break;case"id":s=co(t,a,n,s);break;default:Fe(t,a,"An event source accepts description, id, identifier and stream declarations."),t.skipBlock(a.indent);break}return{kind:"EventSourceSyntax",name:n,streams:i,identifier:r,description:o,id:s,location:f(e)}}l(so,"parseEventSource");function ul(t,e){let n=fl.exec(e.content)?.[1]??"";n===""&&Fe(t,e,"Expected 'stream <Name>'.");let i=null,r=[],o=!1,s={},a=null,c=null;for(let d=t.peekChild(e.indent);d!==void 0;d=t.peekChild(e.indent))switch(t.reader.takeSignificant(),R(d.content)){case"streamId":o?(Fe(t,d,"Declare either one 'streamId <Type>' or one streamId part block."),t.skipBlock(d.indent)):d.content==="streamId"?(o=!0,s.streamId=f(d),r=ml(t,d)):(i=lo(t,d,"streamId",i),o=i!==null);break;case"description":a=G(t,d,a,`Stream '${n}'`,!0);break;case"id":c=co(t,d,n,c);break;default:Fe(t,d,"A stream accepts description, id and streamId declarations."),t.skipBlock(d.indent);break}return{kind:"EventStreamSyntax",name:n,streamId:i,streamIdParts:r,description:a,id:c,directiveLocations:s,location:f(e)}}l(ul,"parseEventStream");function lo(t,e,n,i){let r=dl.exec(e.content);return r===null||i!==null?Fe(t,e,`Declare at most one '${n} <Type>'.`):(i=ve(r[2],{...f(e),column:e.indent+1+e.content.indexOf(r[2],n.length)}),Ae(t,i,e)),Bt(t,e,p.InvalidEventSourceDeclaration),i}l(lo,"parseType");function co(t,e,n,i){let r=cl.exec(e.content),o=r===null?null:H(r[1]);return o===null||o.trim()===""||i!==null?Fe(t,e,`Declare at most one nonempty rename-only 'id "<old-name>"'.`):(i=o,o===n&&t.information(p.RedundantSourceStreamId,"The rename pin repeats the current name; omit it for a new declaration.",f(e))),Bt(t,e,p.InvalidEventSourceDeclaration),i}l(co,"parsePin");function po(t,e,n,i){let[r,o]=n.type.name.split("."),s={kind:"CommandStreamSyntax",eventSource:r,stream:o,streamId:null,streamIdParts:[],propertyCandidate:null,referenceLocation:n.type.location,referenceLength:n.type.name.length,location:f(e)};if(i)return t.error(p.AmbiguousCommandStream,`'${e.content}' has both a property type and a stream route interpretation; neither is selected.`,f(e)),{...s,propertyCandidate:n};let a=null,c=[],d=!1,m={};for(let u=t.peekChild(e.indent);u!==void 0;u=t.peekChild(e.indent)){if(t.reader.takeSignificant(),u.content==="streamId"){a!==null||d?(t.error(p.InvalidCommandStream,"Declare either one 'streamId = <source>' mapping or one streamId part block.",f(u)),t.skipBlock(u.indent)):(d=!0,m.streamId=f(u),c=Di(t,u,p.InvalidCommandStream));continue}let y=/^streamId\s*=\s*(.+)$/.exec(u.content);if(y===null||a!==null||d)t.error(p.InvalidCommandStream,"Declare either one 'streamId = <source>' mapping or one streamId part block.",f(u)),t.skipBlock(u.indent);else{let h={...f(u),column:u.indent+1+u.content.indexOf(y[1],u.content.indexOf("=")+1)};a={kind:"PropertyMappingSyntax",property:"streamId",source:te(y[1],h,t),location:f(u)},Bt(t,u,p.InvalidCommandStream)}}return{...s,streamId:a,streamIdParts:c,directiveLocations:m}}l(po,"parseCommandStream");function ml(t,e){let n=[],i=de("^([A-Za-z_]\\w*)\\s+([\\w.]+(?:\\[\\])?(?:\\?|\\s+optional)?)$");for(let r=t.peekChild(e.indent);r!==void 0;r=t.peekChild(e.indent)){t.reader.takeSignificant();let o=i.exec(r.content);if(o===null){Fe(t,r,"Expected '<part> <Type>' without modifiers in a streamId part block."),t.skipBlock(r.indent);continue}let s=ve(o[2],{...f(r),column:r.indent+1+r.content.indexOf(o[2],o[1].length)});Ae(t,s,r),n.push({kind:"EventStreamIdPartSyntax",name:o[1],type:s,location:f(r)}),Bt(t,r,p.InvalidEventSourceDeclaration)}return n.length===0&&Fe(t,e,"A streamId part block cannot be empty."),n}l(ml,"parseStreamIdParts");function Di(t,e,n){let i=[],r=de("^([A-Za-z_]\\w*)\\s*=(?!=|>)\\s*(.+)$");for(let o=t.peekChild(e.indent);o!==void 0;o=t.peekChild(e.indent)){t.reader.takeSignificant();let s=r.exec(o.content);if(s===null){t.error(n,"Expected '<part> = <source>' in a streamId part block.",f(o)),t.skipBlock(o.indent);continue}let a={...f(o),column:o.indent+1+o.content.indexOf(s[2],o.content.indexOf("=")+1)};i.push({kind:"PropertyMappingSyntax",property:s[1],source:te(s[2],a,t),location:f(o)}),Bt(t,o,n)}return i.length===0&&t.error(n,"A streamId part block cannot be empty.",f(e)),i}l(Di,"parseRouteParts");function Bt(t,e,n){let i=t.peekChild(e.indent);i!==void 0&&(t.error(n,"This directive cannot have children.",f(i)),t.skipBlock(e.indent))}l(Bt,"rejectChildren");function Fe(t,e,n){t.error(p.InvalidEventSourceDeclaration,n,f(e))}l(Fe,"invalid");var Mi=O("^returns\\s+(@?[A-Za-z_]\\w*)$"),yl=O("^(@?[a-z_]\\w*)(?:\\s+([\\w.]+(?:\\[\\])?(?:\\?|\\s+optional)?))?\\s*=(?!=|>)\\s*(@?[a-z_]\\w*)$");function Ni(t,e){let n=f(e);if(e.content!=="returns"){let r=Mi.exec(e.content);if(r===null)return t.error(p.InvalidCommandResponse,"Expected 'returns <property>' or an unconditional 'returns' block.",n),t.skipBlock(e.indent),null;let o=t.peekChild(e.indent);o!==void 0&&(t.error(p.InvalidCommandResponse,"A scalar response cannot have child directives.",f(o)),t.skipBlock(e.indent));let s=r.index+r[0].length-r[1].length;return{kind:"ScalarCommandResponseSyntax",source:{kind:"PropertyResponseSourceSyntax",property:X(r[1]),location:{...n,column:n.column+s}},location:n}}let i=[];for(let r=t.peekChild(e.indent);r!==void 0;r=t.peekChild(e.indent)){t.reader.takeSignificant();let o=yl.exec(r.content);if(o===null){t.error(p.InvalidCommandResponse,"Expected '<field> [<Type>] = <property>' in a response block.",f(r)),t.skipBlock(r.indent);continue}let s=f(r),a=o[2]===void 0?null:ve(o[2],{...s,column:s.column+r.content.indexOf(o[2],o[1].length)});a!==null&&Ae(t,a,r),i.push({kind:"ResponseFieldSyntax",name:X(o[1]),type:a,source:{kind:"PropertyResponseSourceSyntax",property:X(o[3]),location:{...s,column:s.column+r.content.lastIndexOf(o[3])}},location:s});let c=t.peekChild(r.indent);c!==void 0&&(t.error(p.InvalidCommandResponse,"A response field cannot have child directives.",f(c)),t.skipBlock(r.indent))}return{kind:"RecordCommandResponseSyntax",fields:i,location:n}}l(Ni,"parseCommandResponse");var hl=new Set([32,133,160,5760,8232,8233,8239,8287,12288]);function Cn(t){if(t===null)return!0;for(let e of t){let n=e.charCodeAt(0);if(!(n>=9&&n<=13||n>=8192&&n<=8202||hl.has(n)))return!1}return!0}l(Cn,"isBlankImplementationHint");var fo=new RegExp('^hint[\\u0009-\\u000d\\u0020\\u0085\\u00a0\\u1680\\u2000-\\u200a\\u2028\\u2029\\u202f\\u205f\\u3000]+"((?:[^"\\\\\\r\\n]|\\\\[^\\r\\n])*)"$'),xt=l(t=>R(t.content)==="file"&&t.content.substring(4).trim().length>0,"isFile"),Ft=l((t,e)=>e.content.startsWith("```")||t.languages.has(e.content),"isCode");function Xe(t,e){let n=e.content.substring(4).trim();return/^(?:[/\\]|[A-Za-z]:[/\\]|~[/\\])/.test(n)&&t.warning(p.AbsoluteFileReference,`'${n}' is an absolute path - a file reference is relative to the repository root, so it means the same thing on every machine`,f(e)),{kind:"FileReferenceSyntax",path:n,location:f(e)}}l(Xe,"parseFile");var ji=l(t=>t.raw.trim()==="```","isClosingCodeFence");function $e(t,e){let n=e.content.startsWith("```")?e.content.substring(3):e.content;if(!t.languages.has(n))return t.error(p.ExpectedCodeFence,`Expected a registered language on the opening fence, not '${e.content}'`,f(e)),null;let i=e;if(!e.content.startsWith("```")){t.warning(p.LegacyInlineCodeFence,`'${n}' on its own line is deprecated - use '\`\`\`${n}' instead`,f(e));let o=t.reader.peekSignificant();if(o===void 0||o.indent<=e.indent||o.content!=="```"&&o.content!==`\`\`\`${n}`)return t.error(p.ExpectedCodeFence,`Expected an opening \`\`\`${n} fence after '${n}'`,f(e)),null;i=t.reader.takeSignificant()}let r=[];for(;;){let o=t.reader.takeRaw();if(o===void 0){t.error(p.UnclosedCodeBlock,"Unclosed inline code block - expected a closing ``` line",f(i));break}if(ji(o))break;let s=0;for(;s<i.indent&&o.raw[s]===" ";)s++;r.push(o.raw.substring(s))}return{kind:"CodeBlockSyntax",language:n,code:r.join(`
18
- `),location:f(e)}}l($e,"parseCode");function uo(t,e){let n=t.peekChild(e.indent);if(n===void 0)return t.error(p.HandlerWithoutImplementation,"Expected a 'file' directive or an inline code block in the handler",f(e)),null;if(t.reader.takeSignificant(),R(n.content)==="implementation")return Sl(t,e,n);let i=xt(n)?Xe(t,n):null,r=i===null&&Ft(t,n)?$e(t,n):null;if(i!==null||r!==null){let o=t.peekChild(e.indent);return o!==void 0&&R(o.content)==="implementation"&&(t.error(p.ConflictingImplementationSources,"A handler cannot mix wrapped and direct sources.",f(o)),t.skipBlock(e.indent)),{kind:"HandlerSyntax",file:i,code:r,implementation:null,location:f(e)}}return t.error(p.UnknownHandlerDirective,`Unexpected '${n.content}' in handler - expected 'file <path>' or an inline code block`,f(n)),t.skipBlock(e.indent),null}l(uo,"parseHandler");function Sl(t,e,n){let i=Yt(t,n);for(let r=t.peekChild(e.indent);r!==void 0;r=t.peekChild(e.indent))t.reader.takeSignificant(),t.error(R(r.content)==="implementation"?p.InvalidImplementationBlock:p.ConflictingImplementationSources,"A handler has one implementation wrapper and cannot mix wrapped and direct sources.",f(r)),Ft(t,r)?$e(t,r):t.skipBlock(r.indent);return{kind:"HandlerSyntax",...i,location:f(e)}}l(Sl,"parseImplementation");function Yt(t,e){let n=[],i=null,r=null,o=!1;e.content!=="implementation"&&t.error(p.InvalidImplementationBlock,"Expected 'implementation' with no operand.",f(e));for(let s=t.peekChild(e.indent);s!==void 0;s=t.peekChild(e.indent))if(t.reader.takeSignificant(),R(s.content)==="hint"||fo.test(s.content)){let a=fo.exec(s.content),c=a===null?null:H(a[1]);Cn(c)?t.error(p.InvalidImplementationHint,"Expected 'hint' followed by one nonblank quoted string.",f(s)):n.push({kind:"ImplementationHintSyntax",text:c,location:f(s)});let d=t.peekChild(s.indent);d!==void 0&&(t.error(p.InvalidImplementationHint,"A hint cannot have children.",f(d)),t.skipBlock(s.indent))}else if(xt(s)||s.content.startsWith("```")){o&&t.error(p.ConflictingImplementationSources,"An implementation has at most one file or inline payload.",f(s));let a=xt(s)?Xe(t,s):null,c=a===null?$e(t,s):null;o||(i=a,r=c),o=!0;let d=t.peekChild(s.indent);a!==null&&d!==void 0&&(t.error(p.InvalidImplementationBlock,"A file directive cannot have children.",f(d)),t.skipBlock(s.indent))}else t.error(p.InvalidImplementationBlock,`Unexpected '${s.content}' in implementation - expected hint, file or a tagged fence.`,f(s)),t.skipBlock(s.indent);return{file:i,code:r,implementation:{kind:"ImplementationSyntax",hints:n,location:f(e)}}}l(Yt,"parseImplementationWrapper");var ie=class extends Error{static{l(this,"InvalidSyntaxJson")}};var ke=Object.freeze({numericMode:"legacy"}),Pn=Object.freeze({numericMode:"exact"}),mo=Object.freeze({numericMode:"invalid"});function vt(t){if(typeof t!="object"||t===null||Object.getPrototypeOf(t)!==Object.prototype&&Object.getPrototypeOf(t)!==null||Reflect.ownKeys(t).length!==1||!Object.hasOwn(t,"numericMode"))throw new ie("Malformed source numeric options.");let e=t.numericMode;if(e!=="legacy"&&e!=="exact")throw new ie("Malformed source numeric options.");return e==="exact"?Pn:ke}l(vt,"validatedSourceOptions");var yo=new WeakSet;function ho(t){yo.add(t)}l(ho,"recordAuthoredDocument");function So(t){return yo.has(t)}l(So,"isAuthoredDocument");var Se=class t{static{l(this,"ParserContext")}reader;path;#e=[];triggerData=[];inputUses=[];scope=[];languages;sourceOptions=ke;authoredDeclarations=!1;streamCandidates;get valueContext(){if(this.sourceOptions.numericMode==="exact")return this;let e=new t(this.reader,this.path,this.languages);return e.sourceOptions=this.sourceOptions,e}constructor(e,n,i=new Set(["csharp","typescript","react","html","sql"])){this.reader=e,this.path=n,this.languages=i}get start(){return mt(1,1,this.path)}get diagnostics(){return this.nestedNumericDirectives.size>0&&this.sourceOptions.numericMode!=="legacy"&&this.reader.atEnd&&(this.#e.push(...[...this.nestedNumericDirectives].sort((e,n)=>e[0]-n[0]).map(e=>e[1])),this.nestedNumericDirectives.clear()),this.#e}nestedNumericDirectives=new Map;claimField(e){this.nestedNumericDirectives.delete(e.number)}information(e,n,i){this.#e.push({severity:"information",code:e,message:n,location:i})}error(e,n,i){this.#e.push({severity:"error",code:e,message:n,location:i})}warning(e,n,i){this.#e.push({severity:"warning",code:e,message:n,location:i})}peekChild(e){let n=this.reader.peekSignificant();return n!==void 0&&n.indent>e?n:void 0}skipBlock(e){for(;this.peekChild(e)!==void 0;)this.reader.takeSignificant()}skipOpaqueBlock(e){let n=this.peekChild(e);for(;n!==void 0;)this.reader.takeSignificant(),n.content.startsWith("```")&&this.skipFencedBody(),n=this.peekChild(e)}skipFencedBody(){for(let e=this.reader.takeRaw();e!==void 0;e=this.reader.takeRaw())if(e.raw.trim()==="```")return}};var An=new WeakMap;var Ye=new WeakMap,we=l(t=>Ye.get(t)??{},"dependencySourcesOf");function wn(t){let e=V(`^reads${z}+([A-Z]\\w*)(?:${z}+as${z}+([a-z_]\\w*))?(?:${z}+by${z}+([a-z_]\\w*))?$`).exec(t.content);if(!(e===null||["as","by","reads"].includes(e[2])))return{kind:"ReadsSyntax",readModel:e[1],alias:e[2]??null,by:e[3]??null,location:f(t)}}l(wn,"captureReads");function go(t){return new Se(t.reader.fork(),t.path,t.languages)}l(go,"fork");function xo(t,e){if(e.content!=="concurrency")return;let n=go(t),i=!1,r={},o;for(let s=n.peekChild(e.indent);s!==void 0;s=n.peekChild(e.indent))switch(n.reader.takeSignificant(),R(s.content)){case"eventSource":s.content==="eventSource"&&(i=!0);break;case"sourceType":case"streamType":case"streamId":{let a=V(`^(sourceType|streamType|streamId)${z}+([A-Za-z_]\\w*)$`).exec(s.content);a!==null&&(r[a[1]]??=a[2]);break}case"events":{if(o!==void 0)break;let a=s.content.slice(6).split(",").map(c=>c.replace(new RegExp(`^${z}+|${z}+$`,"gu"),"")).filter(Boolean);a.length>0&&a.every(c=>V("^[A-Z]\\w*$").test(c))&&(o=a);break}default:n.skipBlock(s.indent);break}return{kind:"ConcurrencySyntax",eventSource:i,eventSourceType:r.sourceType??null,eventStreamType:r.streamType??null,eventStreamId:r.streamId??null,eventTypes:o??[],location:f(e)}}l(xo,"captureConcurrency");function vo(t,e){let n=V(`^reducer${z}+([A-Za-z_]\\w*)${z}*=>${z}*([A-Za-z_]\\w*)$`).exec(e.content),i=go(t),r=[];for(let o=i.peekChild(e.indent);o!==void 0;o=i.peekChild(e.indent)){if(i.reader.takeSignificant(),R(o.content)==="description"){G(i,o,null,"Reducer");continue}let s=V(`^on${z}+([A-Z]\\w*)$`).exec(o.content);s!==null&&r.push({kind:"ReducerRuleSyntax",event:s[1],file:null,code:null,description:null,location:f(o)}),i.skipOpaqueBlock(o.indent)}return{kind:"ReducerSyntax",name:n?.[1]??"",readModel:n?.[2]??"",rules:r,description:null,location:f(e)}}l(vo,"captureReducer");var gl=O("^system\\s+([A-Za-z_]\\w*)$"),xl=O("^operation\\s+([A-Za-z_]\\w*)$"),vl=O("^produces\\s+operation\\s+([A-Za-z_]\\w*)$"),Li=O("^uses\\s+([A-Za-z_]\\w*)$"),$l=O("^(.+?)\\s*=(?!=|>)\\s*(.+)$"),kl=new Set(["for","tag","generation","origin","documentation","namespace","sequence","correlation","causation","causedBy","occurred"]);function Wt(t,e,n,i){let r=t.peekChild(e.indent);r!==void 0&&(t.error(n,i,f(r)),t.skipBlock(e.indent))}l(Wt,"rejectOperationChildren");function $o(t,e){let n=gl.exec(e.content);n===null&&t.error(p.InvalidSystemDeclaration,"Expected 'system <Name>'.",f(e));let i=null;for(let r=t.peekChild(e.indent);r!==void 0;r=t.peekChild(e.indent))t.reader.takeSignificant(),R(r.content)==="description"?i=G(t,r,i,`System '${n?.[1]??""}'`):(t.error(p.InvalidSystemDeclaration,"A system accepts only a description; abilities are not supported.",f(r)),t.skipBlock(r.indent));return{kind:"SystemSyntax",name:n?.[1]??"",description:i,location:f(e)}}l($o,"parseSystem");function On(t,e,n=!1){let i=(n?vl:xl).exec(e.content),r=i?.[1]??"";i===null&&t.error(p.InvalidOperationDeclaration,"Expected an operation declaration with one name.",f(e));let o=null,s=null,a=f(e),c=null,d=null,m=[],u=[],y=new Set;for(let h=t.peekChild(e.indent);h!==void 0;h=t.peekChild(e.indent)){t.reader.takeSignificant();let v=$l.exec(h.content),x=n&&v!==null?{...h,content:v[1].trimEnd()}:h;if(v===null&&kl.has(R(h.content))){t.error(p.InvalidOperationDeclaration,"Operations cannot declare event routing or metadata; escape a keyword-named input with @.",f(h)),t.skipBlock(h.indent);continue}if(!Li.test(h.content)&&Je(x)!==void 0){let $=De(t,x);n&&v===null&&t.error(p.InvalidOperationMapping,"An inline operation input requires '<property> <Type> = <source>'.",f(h)),($.isIdentifier||$.isGenerated)&&t.error(p.InvalidOperationDeclaration,"Operation inputs cannot be identifier or generated properties.",f(h)),y.has($.name)&&t.error(p.DuplicateDeclaration,`Operation '${r}' already declares input '${$.name}'.`,f(h)),y.add($.name),m.push($),n&&v!==null&&u.push({kind:"PropertyMappingSyntax",property:$.name,source:te(v[2],{...f(h),column:h.indent+h.content.length-v[2].length+1},t),location:f(h)}),Wt(t,h,p.InvalidOperationDeclaration,"An operation input cannot have children.")}else if(R(h.content)==="description")o=G(t,h,o,`Operation '${r}'`);else if(Li.test(h.content))s!==null?t.error(p.InvalidSystemReference,"An operation declares exactly one 'uses <System>'.",f(h)):(s=Li.exec(h.content)[1],a={...f(h),column:f(h).column+h.content.indexOf(s,4)}),Wt(t,h,p.InvalidSystemReference,"A system reference cannot have children.");else if(h.content==="execute"||h.content==="compensate"){let $=bl(t,h);h.content==="execute"?c!==null?t.error(p.InvalidOperationDeclaration,"An operation declares execute at most once.",f(h)):c=$:d!==null?t.error(p.InvalidOperationDeclaration,"An operation declares compensate at most once.",f(h)):d=$}else t.error(p.InvalidOperationDeclaration,`Unexpected '${h.content}' in operation - expected uses, an input, description, execute or compensate.`,f(h)),t.skipBlock(h.indent)}return s===null&&t.error(p.InvalidSystemReference,"An operation requires exactly one 'uses <System>'.",f(e)),{operation:{kind:"OperationSyntax",name:r,uses:s??"",usesLocation:a,inputs:m,description:o,execute:c,compensate:d,location:f(e)},mappings:u}}l(On,"parseOperation");function bl(t,e){let n=null,i=null,r=null,o=null,s=!1;for(let a=t.peekChild(e.indent);a!==void 0;a=t.peekChild(e.indent)){if(t.reader.takeSignificant(),R(a.content)==="description"){n=G(t,a,n,`Operation phase '${e.content}'`);continue}if(R(a.content)==="implementation"){s&&t.error(p.ConflictingImplementationSources,"A phase cannot mix wrapped and direct sources or repeat its wrapper.",f(a));let c=Yt(t,a);s||(i=c.file,r=c.code,o=c.implementation),s=!0}else if(le(a)||a.content.startsWith("```")){s&&t.error(p.ConflictingImplementationSources,"A phase has at most one file or inline payload.",f(a));let c=le(a)?Xe(t,a):null,d=c===null?$e(t,a):null;s||(i=c,r=d),s=!0,c!==null&&Wt(t,a,p.InvalidImplementationBlock,"A file directive cannot have children.")}else t.error(p.InvalidOperationDeclaration,"A phase accepts description, file, a tagged fence or implementation.",f(a)),t.skipBlock(a.indent)}return{kind:"OperationPhaseSyntax",description:n,file:i,code:r,implementation:o,location:f(e)}}l(bl,"parseOperationPhase");var El=O("^produces\\s+operation(?:\\s|$)"),Cl=O("^produces\\s+event\\s+([A-Za-z_]\\w*)(?:\\s+(generation)(?:\\s+.*)?)?$"),Pl=O("^produces\\s+([A-Z]\\w*(?:\\.[A-Za-z_]\\w*)*)$"),ko=O("^produces\\s+when\\s+(.+)$"),Al=O("^[A-Z]\\w*(?:\\.[A-Za-z_]\\w*)*$"),wl=O("^for\\s+(\\S.*)$"),Ol=O("^(@?[\\w.]+)\\s*=(?!=|>)\\s*(.+)$"),Il=O("^(.+?)\\s*=(?!=|>)\\s*(.+)$"),Tl=new Set(["namespace","sequence","correlation","causation","causedBy","occurred"]);function Ut(t,e,n=!1){if(El.test(e.content)){if(!n){t.error(p.OperationOutsideCommand,"Operations can only be produced by commands.",f(e)),t.skipOpaqueBlock(e.indent);return}let v=On(t,e,!0);return{kind:"ProducesSyntax",when:null,event:v.operation.name,targetLocation:{...f(e),column:e.indent+e.content.match(/^produces\s+operation(?:\s+|$)/)[0].length+1},inlineEvent:null,inlineOperation:v.operation,mappings:v.mappings,for:null,tags:[],location:f(e)}}let i=Cl.exec(e.content),r=e,o=null,s,a;if(i!==null){if(!n){t.error(p.InlineEventOutsideCommand,"Inline events can only be declared inside commands",f(e)),t.skipOpaqueBlock(e.indent);return}i[2]!==void 0&&t.error(p.InlineEventGeneration,"Inline events are generation 1 - extract the event before declaring generations",f(e)),s=i[1],a=e.indent+e.content.match(/^produces\s+event\s+/)[0].length+1}else if(ko.test(e.content)){o=He(t,ko.exec(e.content)[1],f(e));let v=t.peekChild(e.indent);if(v===void 0||!Al.test(v.content)){t.error(p.ProducesWhenWithoutEvent,"Expected an event name on the line after 'produces when'",f(e)),t.skipOpaqueBlock(e.indent);return}t.reader.takeSignificant(),r=v,s=v.content,a=v.indent+1}else{let v=Pl.exec(e.content);if(v===null){t.error(p.InvalidProducesDeclaration,`Invalid produces declaration '${e.content}' - expected 'produces <EventType>' or 'produces when <condition>'`,f(e)),t.skipOpaqueBlock(e.indent);return}s=v[1],a=e.indent+e.content.match(/^produces\s+/)[0].length+1}let c=[],d=new Set,m=[],u=[],y=new gt(s),h=null;for(let v=t.peekChild(r.indent);v!==void 0;v=t.peekChild(r.indent)){t.reader.takeSignificant();let x=R(v.content),$=f(v);if(Tl.has(x)){t.error(p.ReservedProductionMetadata,`'${x}' is system-assigned production metadata and cannot be supplied here`,$),t.skipOpaqueBlock(v.indent);continue}if(i!==null&&(x==="generation"||x==="origin")){t.error(x==="generation"?p.InlineEventGeneration:p.ReservedProductionMetadata,x==="generation"?"Inline events are generation 1 - extract the event before declaring generations":"An inline event is local to its command and cannot declare origin",$),t.skipOpaqueBlock(v.indent);continue}if(x==="tag"){let A=qt(t,v,!1);A!==void 0&&u.push(A);continue}let C=wl.exec(v.content);if(C!==null){h!==null?t.error(p.DuplicateProducesTarget,`'${r.content}' already declares where it lands - an event is appended to one event source`,$):h=te(C[1],$,t);continue}let E=(i===null?Ol:Il).exec(v.content),P=E===null||i===null?void 0:De(t,{...v,content:E[1].trimEnd()});if(E!==null&&(i===null||P!==void 0)){if(P!==void 0){P.isIdentifier&&(t.error(p.IdentifierOnEventProperty,`Property '${P.name}' of event '${s}' cannot be marked identifier - an event never carries its event source id`,$),P={...P,isIdentifier:!1});let A=P.name;d.has(A)&&t.error(p.DuplicateDeclaration,`Event '${s}' already declares property '${P.name}'`,$),d.add(A),c.push(P)}m.push({kind:"PropertyMappingSyntax",property:P?.name??X(E[1]),source:te(E[2],{...$,column:v.indent+v.content.length-E[2].length+1},t),location:$})}else(i===null||!y.tryParse(t,v))&&t.error(p.InvalidPropertyMapping,`Invalid ${i===null?"":"inline "}property mapping '${v.content}' - expected '<property>${i===null?"":" <Type>"} = <source>'`,$)}return r!==e&&t.skipBlock(e.indent),{kind:"ProducesSyntax",when:o,event:s,targetLocation:{...f(r),column:a},inlineOperation:null,mappings:m,for:h,tags:i===null?u:[],location:f(e),inlineEvent:i===null?null:{kind:"EventSyntax",name:s,properties:c,tags:u,generation:1,hasGenerationMarker:!1,...y.value,location:f(e)}}}l(Ut,"parseProduces");var Rl=O("^command\\s+([A-Za-z_]\\w*)$"),Dl=de("^stream\\s+[A-Za-z_]\\w*\\.[A-Za-z_]\\w*$"),Ml=O("\\bseverity\\s+(\\S+)$"),Eo=O(`\\bmessage\\s+(?:"(${_})"|(\\$strings\\.\\S*))$`),Nl=O("^([\\w.]+)\\s+(.+)$"),jl=O("^(not empty|length ==|all >=|all >|matches|max|min|rule|>=|<=|==|!=|>|<)\\s*(.*)$"),Ll=de("^[A-Za-z_]\\w*$"),ql=O("^reads\\s+[A-Z]\\w*\\s+optional(?:\\s|$)"),Bl={max:"Max",min:"Min",">":"GreaterThan",">=":"GreaterThanOrEqual","<":"LessThan","<=":"LessThanOrEqual","==":"Equal","!=":"NotEqual","length ==":"Length",matches:"Matches","all >":"AllGreaterThan","all >=":"AllGreaterThanOrEqual"},Co={information:"Information",warning:"Warning",error:"Error"},Fl=new Set(["reads","concurrency"]),Yl=new Set(["description","documentation","handler","concurrency"]);function Po(t,e){let n=new Set,i=new Se(t.reader.fork(),t.path,t.languages);return i.sourceOptions=t.sourceOptions,i.streamCandidates=t.streamCandidates,bo(i,e,void 0,n),bo(t,e,n)}l(Po,"parseCommand");function bo(t,e,n,i){let r=Rl.exec(e.content)?.[1]??"";r===""&&t.error(p.InvalidCommandDeclaration,`Invalid command declaration '${e.content}' - expected 'command <Name>'`,f(e));let o=[],s=[],a,c=[],d=[],m=[],u=[],y,h=null,v=null,x=null,$=null,C=null,E=[];for(let b=t.peekChild(e.indent);b!==void 0;b=t.peekChild(e.indent)){t.reader.takeSignificant();let I=R(b.content),w=Je(b);if(w!==void 0&&(Yl.has(I)||I==="validate"&&b.content!=="validate csharp"))a=In(t,o,w,r,b,a);else if(I==="returns"){let D=Mi.exec(b.content);D!==null&&!D[1].startsWith("@")&&w!==void 0?n===void 0?(o.push(w),s.push({line:b,candidate:w,response:null})):n.has(w.type.name)?s.push({line:b,candidate:null,response:Ni(t,b)}):a=In(t,o,w,r,b,a):w!==void 0?a=In(t,o,w,r,b,a):$n(t,b)?t.skipBlock(b.indent):s.push({line:b,candidate:null,response:Ni(t,b)})}else if(I==="stream"&&Dl.test(b.content)&&w!==void 0&&t.streamCandidates?.hasSource(w.type.name.split(".")[0])===!0){let[D,N]=w.type.name.split("."),L=t.streamCandidates.hasPropertyType(w.type.name)&&t.streamCandidates.hasUniqueStream(D,N),q=po(t,b,w,L);(C!==null||E.length>0)&&t.error(p.InvalidCommandStream,"A command declares at most one stream route.",f(b)),L||C!==null?E.push(q):C=q}else if(I==="description")h=G(t,b,h,`Command '${r}'`);else if(I==="documentation")v=ue(t,b,v,`Command '${r}'`);else if(I==="authorize")x=Re(x,_e(t,b));else if(I==="validate"){let D=qi(t,b,"command");D!==void 0&&c.push(D)}else if(I==="produces"){let D=Ut(t,b,!0);D!==void 0&&d.push(D)}else if(I==="handler")$=uo(t,b);else if(Fl.has(I)){let D=wn(b);D!==void 0&&u.push(D),I==="concurrency"&&y===void 0&&(y=xo(t,b));let N=/^reads\s+([A-Z]\w*)(?:\s+as\s+([a-z_]\w*))?(?:\s+by\s+([a-z_]\w*))?$/.exec(b.content);N!==null&&m.push({readModel:N[1],alias:N[2]??null}),ql.test(b.content)&&t.error(p.OptionalReadsNotSupported,"Optional reads are not yet supported (see #308).",f(b)),t.skipOpaqueBlock(b.indent)}else w!==void 0?a=In(t,o,w,r,b,a):($n(t,b),t.error(p.UnknownCommandDirective,`Unexpected '${b.content}' in command body`,f(b)),t.skipBlock(b.indent))}let P=new Set(s.flatMap(b=>b.candidate===null?[]:[b.candidate])),A=new Set(o.filter(b=>!P.has(b)).map(b=>b.name));s.some(b=>b.candidate!==null&&!A.has(b.candidate.type.name)&&b.candidate.type.name!=="returns")&&A.add("returns");for(let b of A)i?.add(b);let g=null,S=new Set;for(let b of s){let I=b.response;if(b.candidate!==null){if(!A.has(b.candidate.type.name))continue;S.add(b.candidate),I={kind:"ScalarCommandResponseSyntax",source:{kind:"PropertyResponseSourceSyntax",property:b.candidate.type.name,location:b.candidate.type.location},location:f(b.line)}}I!==null&&(g!==null?t.error(p.InvalidCommandResponse,"A command declares at most one unconditional response.",f(b.line)):g=I)}$!==null&&d.length>0&&t.error(p.CommandWithProducesAndHandler,`Command '${r}' cannot declare both 'produces' and 'handler'`,f(e));let k={kind:"CommandSyntax",name:r,description:h,documentation:v,authorize:x,properties:o.filter(b=>!S.has(b)),validations:c,produces:d,handler:$,response:g,stream:C,streamCandidates:E,location:f(e)};return An.set(k,m),Ye.set(k,{reads:u,concurrency:y}),k}l(bo,"parseCommandBody");function In(t,e,n,i,r,o){return Ae(t,n.type,r),n.isIdentifier&&o!==void 0&&(t.error(p.DuplicateCommandIdentifier,`Command '${i}' already marks '${o.name}' as identifier - only one property can be the identifier`,n.location),n={...n,isIdentifier:!1}),e.push(n),o??(n.isIdentifier?n:void 0)}l(In,"addProperty");function qi(t,e,n){if(e.content==="validate"){let i=t.peekChild(e.indent);if(i!==void 0&&i.content.startsWith("```")){t.reader.takeSignificant();let a=$e(t.valueContext,i);return a===null&&t.skipFencedBody(),{kind:"CodeValidateSyntax",code:a,location:f(e)}}let r=[],o=[],s;for(let a=t.peekChild(e.indent);a!==void 0;a=t.peekChild(e.indent)){if(t.reader.takeSignificant(),n==="concept"){if(t.sourceOptions.numericMode==="legacy"&&a.content.startsWith("```")){t.skipFencedBody();continue}if(s!==void 0&&a.indent<=s&&(s=void 0),s!==void 0||R(a.content)==="implementation"){t.error(p.InvalidValidationRule,`Invalid validation rule '${a.content}'`,f(a)),s??=a.indent;continue}}if(R(a.content)==="require"){let d=He(n==="concept"?t.valueContext:t,a.content.substring(7).trim(),f(a)),m=null,u="Error",y=!1;for(let h=t.peekChild(a.indent);h!==void 0;h=t.peekChild(a.indent)){t.reader.takeSignificant();let v=Eo.exec(h.content);v!==null&&v.index===0?m=v[1]!==void 0?H(v[1]):v[2]:R(h.content)==="severity"?(y||(u=Co[h.content.substring(8).trim()]??"Error"),y=!0):t.skipOpaqueBlock(h.indent)}d!==null&&o.push({kind:"RequirementSyntax",condition:d,message:m,severity:u,location:f(a)});continue}let c=Wl(t,n==="concept"?{...a,content:`value ${a.content}`}:a,n);c!==void 0&&r.push(c)}return{kind:"DeclarativeValidateSyntax",rules:r,requirements:o,location:f(e)}}if(e.content==="validate csharp"){let i=$e(t.valueContext,{...e,content:"csharp"});return i===null&&t.skipOpaqueBlock(e.indent),{kind:"CodeValidateSyntax",code:i,location:f(e)}}t.error(p.InvalidValidateDeclaration,`Invalid validate declaration '${e.content}' - expected 'validate' or 'validate csharp'`,f(e)),t.skipBlock(e.indent)}l(qi,"parseValidate");function Wl(t,e,n){let i=n==="concept"?t.valueContext:t,{content:r,message:o}=zl(e.content),s=Vl(i,e,r);if(s===void 0)return;let a=Nl.exec(s.content);if(a===null){i.error(p.InvalidValidationRule,`Invalid validation rule '${e.content}'`,f(e));return}let c=Ql(i,a[2],e);if(c===void 0)return;let d=c.kind==="Rule"?Ul(t,e,n==="command"):{file:null,code:null,implementation:null};return{kind:"ValidationRuleSyntax",property:a[1],rule:c.kind,value:c.value,message:o,severity:s.severity,...d,location:f(e)}}l(Wl,"parseValidationRule");function Ul(t,e,n){let i=t.peekChild(e.indent);if(i===void 0)return{file:null,code:null,implementation:null};t.reader.takeSignificant();let r=n&&R(i.content)==="implementation",o=r?Yt(t,i):{file:xt(i)?Xe(t,i):null,code:!xt(i)&&Ft(t,i)?$e(t,i):null,implementation:null};!r&&o.file===null&&o.code===null&&(t.error(p.UnknownRuleImplementationDirective,`Unexpected '${i.content}' in rule implementation - expected 'file <path>' or an inline code block`,f(i)),t.skipBlock(i.indent));for(let s=t.peekChild(e.indent);s!==void 0&&(r||n&&R(s.content)==="implementation");s=t.peekChild(e.indent))t.reader.takeSignificant(),t.error(r&&R(s.content)==="implementation"?p.InvalidImplementationBlock:p.ConflictingImplementationSources,"A named rule has one implementation wrapper and cannot mix wrapped and direct sources.",f(s)),Ft(t,s)?$e(t,s):t.skipBlock(s.indent);return o}l(Ul,"parseRuleImplementation");function zl(t){let e=Eo.exec(t);if(e===null)return{content:t,message:null};let n=e[1]!==void 0?H(e[1]):e[2];return{content:t.substring(0,e.index).trimEnd(),message:n}}l(zl,"splitMessage");function Vl(t,e,n){let i=Ml.exec(n);if(i===null)return{content:n,severity:"Error"};let r=Co[i[1]];if(r===void 0){t.error(p.InvalidValidationSeverity,`Unknown validation severity '${i[1]}' - expected information, warning or error`,f(e));return}return{content:n.substring(0,i.index).trimEnd(),severity:r}}l(Vl,"splitSeverity");function Ql(t,e,n){if(e==="not empty")return{kind:"NotEmpty",value:null};let i=jl.exec(e);if(i===null){t.error(p.InvalidValidationRule,`Invalid validation rule '${n.content}'`,f(n));return}if(i[1]==="rule"){let r=i[2].trim();if(!Ll.test(r)){t.error(p.InvalidRuleName,`Invalid rule name '${r}' in '${n.content}' - expected 'rule <Name>' with an identifier`,f(n));return}return{kind:"Rule",value:{kind:"PathExpressionSyntax",path:r,location:f(n)}}}return{kind:Bl[i[1]],value:te(i[2],f(n),t)}}l(Ql,"parseRule");var Gl=O("^constraint\\s+([A-Za-z_]\\w*)$"),Kl=O("^unique\\s+event\\s+([A-Z]\\w*)$"),Zl=O("^unique\\s+([a-z_][\\w.]*(?:\\s*,\\s*[a-z_][\\w.]*)*)\\s+on\\s+([A-Z]\\w*)$"),_l=O("^released\\s+by\\s+([A-Z]\\w*)$"),Jl=O(`^message\\s+"(${_})"$`),Hl=l(t=>t.kind==="FileConstraintSyntax"?void 0:t.event,"targetOf");function Ao(t,e){let n=Gl.exec(e.content);n===null&&t.error(p.InvalidConstraintDeclaration,`Invalid constraint declaration '${e.content}' - expected 'constraint <Name>'`,f(e));let i=n?.[1]??R(e.content),r=[],o=[],s=new Set,a=new Set,c=null,d=!1;for(let m=t.peekChild(e.indent);m!==void 0;m=t.peekChild(e.indent)){t.reader.takeSignificant();let u=_l.exec(m.content),y=Jl.exec(m.content);u!==null?s.has(u[1])?t.error(p.DuplicateConstraintBody,`Constraint '${i}' already releases with event '${u[1]}'`,f(m)):(o.push(u[1]),s.add(u[1])):y!==null?c!==null?t.error(p.DuplicateConstraintBody,`Constraint '${i}' already has a message`,f(m)):c=H(y[1]):m.content==="ignore casing"?(d&&t.error(p.DuplicateConstraintBody,`Constraint '${i}' already ignores casing`,f(m)),d=!0):Xl(t,i,m,r,a)}for(let m of o.filter(u=>a.has(u)))t.error(p.DuplicateConstraintBody,`Constraint '${i}' cannot target and release event '${m}'`,f(e));return r.length===0&&(t.error(p.ConstraintWithoutRule,`Constraint '${i}' must declare 'unique ... on ...', 'unique event ...' or 'file ...'`,f(e)),r.push(Tn(i,f(e),{kind:"UniqueEventConstraintSyntax",event:""}))),r[0].kind==="FileConstraintSyntax"&&(o.length>0||c!==null||d)&&t.error(p.InvalidConstraintBody,`File constraint '${i}' cannot have declarative options`,f(e)),{...r[0],additionalRules:r.slice(1),releasedBy:o,message:c,ignoreCasing:d}}l(Ao,"parseConstraint");function Xl(t,e,n,i,r){let o=ec(t,e,n);if(o===void 0)return;if(i.length>0&&(o.kind==="FileConstraintSyntax"||i[0].kind==="FileConstraintSyntax"||o.kind==="UniqueEventConstraintSyntax"!=(i[0].kind==="UniqueEventConstraintSyntax"))){t.error(p.DuplicateConstraintBody,`Constraint '${e}' cannot mix constraint kinds`,f(n));return}let s=Hl(o);if(s!==void 0&&r.has(s)){t.error(p.DuplicateConstraintBody,`Constraint '${e}' already targets event '${s}'`,f(n));return}s!==void 0&&r.add(s),i.push(o)}l(Xl,"addRule");function ec(t,e,n){let i=f(n),r=Kl.exec(n.content);if(r!==null)return Tn(e,i,{kind:"UniqueEventConstraintSyntax",event:r[1]});let o=Zl.exec(n.content);if(o!==null){let s=o[1].split(",").map(a=>a.trim());if(new Set(s).size!==s.length){t.error(p.DuplicateConstraintBody,`Constraint '${e}' repeats a property in its composite key`,i);return}return Tn(e,i,{kind:"UniquePropertyConstraintSyntax",property:s[0],additionalProperties:s.slice(1),event:o[2]})}if(le(n)){t.warning(p.FileConstraintOnlySupportsUniqueness,"A file constraint can only declare unique constraints in Chronicle - declare them with 'unique ...' so they are portable; a rule that is not uniqueness belongs in command validation or a 'require' condition",i);let s=n.content.substring(4).trim();return Tn(e,i,{kind:"FileConstraintSyntax",file:{kind:"FileReferenceSyntax",path:s,location:i}})}t.error(p.InvalidConstraintBody,`Invalid constraint body '${n.content}'`,i)}l(ec,"parseRule");function Tn(t,e,n){return{...n,name:t,additionalRules:[],releasedBy:[],ignoreCasing:!1,message:null,location:e}}l(Tn,"rule");var tc=O("^projection\\s+(@?[\\w.]+)\\s*(?:=>\\s*([\\w.]+))?$"),nc=O("^(@?[\\w.]+)(?:\\s+key\\s+(.+))?$"),ic=O("^join\\s+(@?[\\w.]+)\\s+on\\s+(@?[\\w.]+)$"),rc=O("^with\\s+(@?[\\w.]+)$"),oc=O("^children\\s+(@?[\\w.]+)\\s+identified\\s+by\\s+(.+)$"),ac=O("^nested\\s+(@?[\\w.]+)$"),sc=O("^remove\\s+with\\s+(@?[\\w.]+)(?:\\s+key\\s+(.+))?$"),lc=O("^remove\\s+via\\s+join\\s+on\\s+(@?[\\w.]+)(?:\\s+key\\s+(.+))?$"),cc=O("^clear\\s+with\\s+(@?[\\w.]+)$"),dc=O("^variant\\s+(@?[\\w.]+)\\s*$"),pc=O("^enters\\s+on\\s+(@?[\\w.]+)(?:\\s+key\\s+(.+))?$"),fc=O("^(increment|decrement|count|clear)\\s+(@?[$\\w.]+)$"),uc=O("^(add|subtract)\\s+(@?[$\\w.]+)\\s+by\\s+(.+)$"),mc=O("^set\\s+(@?[$\\w.]+)\\s+(?:=|to)\\s+(.+)$"),wo=O("^(@?[$\\w.@]+)\\s*=(?!=|>)\\s*(.+)$"),yc={increment:"IncrementMappingSyntax",decrement:"DecrementMappingSyntax",clear:"ClearMappingSyntax",count:"CountMappingSyntax"};function Fi(t,e){let n=tc.exec(e.content);if(n===null)return t.error(p.InvalidProjectionDeclaration,`Invalid projection declaration '${e.content}' - expected 'projection <Name> [=> <ReadModel>]'`,f(e)),t.skipBlock(e.indent),{kind:"ProjectionSyntax",sourceOptions:t.sourceOptions,name:R(e.content),readModel:null,sequence:null,autoMap:"Inherit",blocks:[],location:f(e)};let i=n[1],r=null,o="Inherit",s=null,a=[];for(let c=t.peekChild(e.indent);c!==void 0;c=t.peekChild(e.indent)){if(t.reader.takeSignificant(),le(c))continue;let d=R(c.content);if(d==="sequence")r=c.content.substring(8).trim();else if(d==="automap")o="Enabled";else if(c.content==="no automap")o="Disabled";else if(d==="key")s=Io(t,c);else if(d==="variant")a.push(bc(t,c));else{let m=Yi(t,c,!1);m!==void 0&&a.push(m)}}return hc(t,a,i),a.length===0&&t.error(p.EmptyProjection,`Projection '${i}' must contain at least one directive`,f(e)),{kind:"ProjectionSyntax",sourceOptions:t.sourceOptions,name:i,readModel:n[2]??null,sequence:r,autoMap:o,key:s,blocks:a,location:f(e)}}l(Fi,"parseProjection");function hc(t,e,n){let i=e.filter(s=>s.kind==="ProjectionVariantSyntax"),r=new Map;i.forEach(s=>r.set(s.name,[...r.get(s.name)??[],s]));for(let s of[...r.values()].flatMap(a=>a.slice(1)))t.error(p.DuplicateProjectionVariant,`Duplicate variant '${s.name}' - a variant name is declared once`,s.location);let o=new Set;for(let s of e.flatMap(a=>a.kind==="ProjectionVariantSyntax"?a.entersOn:[]))s.event.length>0&&o.has(s.event)&&t.error(p.DuplicateVariantEnteringEvent,`Entering event '${s.event}' is claimed more than once in projection '${n}'`,s.location),o.add(s.event)}l(hc,"reportVariantConflicts");function Yi(t,e,n){let i=f(e);switch(R(e.content)){case"from":return Sc(t,e);case"every":{let r=!0,{autoMap:o,mappings:s}=Bi(t,e,a=>a.content!=="exclude children"?!1:(r=!1,!0));return{kind:"EverySyntax",includeChildren:r,autoMap:o,mappings:s,location:i}}case"all":{let{autoMap:r,mappings:o}=Bi(t,e);return{kind:"AllSyntax",autoMap:r,mappings:o,location:i}}case"join":return gc(t,e);case"children":return xc(t,e);case"nested":return vc(t,e);case"remove":return $c(t,e);case"clear":return n||t.error(p.ClearWithOutsideNestedBlock,"'clear with' is only valid inside a nested block",i),kc(t,e);default:t.error(p.UnknownProjectionDirective,`Unexpected '${R(e.content)}' in projection body`,i),t.skipBlock(e.indent);return}}l(Yi,"parseBlock");function Sc(t,e){let n=[];for(let s of zr(e.content.substring(4),",")){let a=s.trim();if(a.length===0){t.error(p.FromWithoutEvent,"Expected an event type after 'from'",f(e));continue}let c=nc.exec(a);if(c===null){t.error(p.InvalidEventReference,`Invalid event reference '${a}'`,f(e));continue}n.push({kind:"EventSpecSyntax",event:X(c[1]),key:c[2]===void 0?null:ce(c[2],f(e),t),location:f(e)})}let i=[],r=null,o=null;for(let s=t.peekChild(e.indent);s!==void 0;s=t.peekChild(e.indent)){t.reader.takeSignificant();let a=R(s.content);a==="key"?r=Io(t,s):a==="parent"?o=ce(s.content.substring(6),f(s),t):To(t,s,i)}return{kind:"FromSyntax",events:n,key:r,parentKey:o,mappings:i,location:f(e)}}l(Sc,"parseFrom");function gc(t,e){let n=ic.exec(e.content);if(n===null)return t.error(p.InvalidJoinDeclaration,`Invalid join declaration '${e.content}' - expected 'join <property> on <key>'`,f(e)),t.skipBlock(e.indent),{kind:"JoinSyntax",property:"",on:"",events:[],location:f(e)};let i=[];for(let r=t.peekChild(e.indent);r!==void 0;r=t.peekChild(e.indent)){t.reader.takeSignificant();let o=rc.exec(r.content);if(o===null){t.error(p.JoinWithoutEvent,`Expected 'with <EventType>' in join block, got '${r.content}'`,f(r)),t.skipBlock(r.indent);continue}let{autoMap:s,mappings:a}=Bi(t,r);i.push({kind:"JoinEventSyntax",event:X(o[1]),autoMap:s,mappings:a,location:f(r)})}return{kind:"JoinSyntax",property:X(n[1]),on:X(n[2]),events:i,location:f(e)}}l(gc,"parseJoin");function xc(t,e){let n=oc.exec(e.content);if(n===null)return t.error(p.InvalidChildrenDeclaration,`Invalid children declaration '${e.content}' - expected 'children <collection> identified by <key>'`,f(e)),t.skipBlock(e.indent),{kind:"ChildrenSyntax",property:"",autoMap:"Inherit",blocks:[],location:f(e)};let{autoMap:i,blocks:r}=Oo(t,e);return{kind:"ChildrenSyntax",property:X(n[1]),identifiedBy:ce(n[2],f(e),t),autoMap:i,blocks:r,location:f(e)}}l(xc,"parseChildren");function vc(t,e){let n=ac.exec(e.content);if(n===null)return t.error(p.InvalidNestedDeclaration,`Invalid nested declaration '${e.content}' - expected 'nested <property>'`,f(e)),t.skipBlock(e.indent),{kind:"NestedSyntax",property:"",autoMap:"Inherit",blocks:[],location:f(e)};let i=X(n[1]),{autoMap:r,blocks:o}=Oo(t,e);return o.some(s=>s.kind==="FromSyntax")||t.error(p.NestedBlockWithoutFrom,`Nested block '${i}' must contain at least one 'from' directive`,f(e)),{kind:"NestedSyntax",property:i,autoMap:r,blocks:o,location:f(e)}}l(vc,"parseNested");function Oo(t,e){let n=[],i="Inherit";for(let r=t.peekChild(e.indent);r!==void 0;r=t.peekChild(e.indent)){if(t.reader.takeSignificant(),r.content==="automap"){i="Enabled";continue}if(r.content==="no automap"){i="Disabled";continue}let o=Yi(t,r,!0);o!==void 0&&n.push(o)}return{autoMap:i,blocks:n}}l(Oo,"parseChildBlocks");function $c(t,e){let n=lc.exec(e.content);if(n!==null)return{kind:"RemoveViaJoinSyntax",event:X(n[1]),key:n[2]===void 0?null:ce(n[2],f(e),t),location:f(e)};let i=sc.exec(e.content);if(i===null){t.error(p.InvalidRemoveDeclaration,`Invalid remove declaration '${e.content}' - expected 'remove with <EventType>' or 'remove via join on <EventType>'`,f(e)),t.skipBlock(e.indent);return}let r=null;for(let o=t.peekChild(e.indent);o!==void 0;o=t.peekChild(e.indent))t.reader.takeSignificant(),R(o.content)==="parent"?r=ce(o.content.substring(6),f(o),t):t.error(p.UnknownRemoveDirective,`Unexpected '${o.content}' in remove block - only 'parent' is allowed`,f(o));return{kind:"RemoveWithSyntax",event:X(i[1]),key:i[2]===void 0?null:ce(i[2],f(e),t),parentKey:r,location:f(e)}}l($c,"parseRemove");function kc(t,e){let n=cc.exec(e.content);return n===null?(t.error(p.InvalidClearDeclaration,`Invalid clear declaration '${e.content}' - expected 'clear with <EventType>'`,f(e)),{kind:"ClearWithSyntax",event:"",location:f(e)}):{kind:"ClearWithSyntax",event:X(n[1]),location:f(e)}}l(kc,"parseClearWith");function bc(t,e){let n=dc.exec(e.content);if(n===null)return t.error(p.InvalidProjectionVariantDeclaration,`Invalid variant declaration '${e.content}' - expected 'variant <Name>'`,f(e)),t.skipBlock(e.indent),{kind:"ProjectionVariantSyntax",name:R(e.content),entersOn:[],blocks:[],location:f(e)};let i=X(n[1]),r=[],o=[];for(let s=t.peekChild(e.indent);s!==void 0;s=t.peekChild(e.indent)){t.reader.takeSignificant();let a=R(s.content);if(a==="enters")r.push(Ec(t,s));else if(a==="variant")t.error(p.NestedProjectionVariantNotAllowed,"A variant cannot be declared inside another variant",f(s)),t.skipBlock(s.indent);else{let c=Yi(t,s,!1);c!==void 0&&o.push(c)}}return r.length===0&&t.error(p.VariantRequiresEnteringEvent,`Variant '${i}' must declare at least one 'enters on' event`,f(e)),{kind:"ProjectionVariantSyntax",name:i,entersOn:r,blocks:o,location:f(e)}}l(bc,"parseVariant");function Ec(t,e){let n=pc.exec(e.content);return n===null?(t.error(p.InvalidEntersOnDeclaration,`Invalid 'enters on' declaration '${e.content}' - expected 'enters on <EventType> [key <expression>]'`,f(e)),t.skipBlock(e.indent),{kind:"ProjectionEntersOnSyntax",event:"",key:null,location:f(e)}):{kind:"ProjectionEntersOnSyntax",event:X(n[1]),key:n[2]===void 0?null:ce(n[2],f(e),t),location:f(e)}}l(Ec,"parseEntersOn");function Io(t,e){let n=e.content.substring(3).trim();if(t.peekChild(e.indent)===void 0)return{kind:"ExpressionKeySyntax",expression:ce(n,f(e),t),location:f(e)};let i=[];for(let o=t.peekChild(e.indent);o!==void 0;o=t.peekChild(e.indent)){if(t.reader.takeSignificant(),o.content==="}")continue;let s=wo.exec(o.content);if(s===null){t.sourceOptions.numericMode==="exact"&&t.error(p.InvalidCompositeKeyPart,`Invalid composite key part '${o.content}' - expected '<property> = <expression>'`,f(o));continue}let a=ce(s[2],f(o),t);t.sourceOptions.numericMode==="exact"&&a.kind==="TemplateExpressionSyntax"&&t.error(p.TemplateInCompositeKey,"Template expressions are not allowed in composite keys",f(o)),i.push({kind:"KeyPartSyntax",property:X(s[1]),expression:a,location:f(o)})}let r=t.reader.peekSignificant();return r!==void 0&&r.indent===e.indent&&r.content==="}"&&t.reader.takeSignificant(),t.sourceOptions.numericMode==="exact"&&i.length===0&&t.error(p.EmptyCompositeKey,"Composite keys must contain at least one part",f(e)),{kind:"CompositeKeySyntax",type:n.replace(/\{$/,"").trim(),parts:i,location:f(e)}}l(Io,"parseKey");function Bi(t,e,n=()=>!1){let i="Inherit",r=[];for(let o=t.peekChild(e.indent);o!==void 0;o=t.peekChild(e.indent))t.reader.takeSignificant(),o.content==="automap"?i="Enabled":o.content==="no automap"?i="Disabled":n(o)||To(t,o,r);return{autoMap:i,mappings:r}}l(Bi,"parseMappingBlock");function To(t,e,n){let i=f(e),r=fc.exec(e.content);if(r!==null){r[1]!=="clear"||r[2]!=="with"?n.push({kind:yc[r[1]],property:X(r[2]),location:i}):t.sourceOptions.numericMode==="exact"&&t.error(p.InvalidProjectionMapping,`Invalid mapping '${e.content}' - 'clear with' is a block directive and needs an event type; to clear a property named 'with', write 'clear @with'`,i);return}let o=uc.exec(e.content);if(o!==null){n.push({kind:o[1]==="add"?"AddMappingSyntax":"SubtractMappingSyntax",property:X(o[2]),value:ce(o[3],i,t),location:i});return}let s=mc.exec(e.content)??wo.exec(e.content);s!==null?n.push({kind:"SetMappingSyntax",property:X(s[1]),source:ce(s[2],i,t),location:i}):t.sourceOptions.numericMode==="exact"&&t.error(p.InvalidProjectionMapping,`Invalid mapping '${e.content}'`,i)}l(To,"pushMapping");var Cc=O("^query\\s+([A-Za-z_]\\w*)\\s*=>\\s*(observable\\s+)?([\\w.]+(?:\\[\\])?(?:\\?|\\s+optional)?)$"),Pc=O("^([a-z_]\\w*)\\s+([\\w.]+(?:\\[\\])?(?:\\?|\\s+optional)?)(?:\\s+from\\s+(.+))?$"),Ac=O("^scoped\\s+to\\s+([a-z_]\\w*)$"),wc=new Set(["performer"]);function Do(t,e){let n=Cc.exec(e.content);if(n===null)return t.error(p.InvalidQueryDeclaration,`Invalid query declaration '${e.content}' - expected 'query <Name> => [observable] <ReadModel>'`,f(e)),t.skipBlock(e.indent),{kind:"QuerySyntax",name:R(e.content),returnType:ve("",f(e)),by:null,filters:[],description:null,isObservable:!1,scope:null,authorize:null,location:f(e)};let i=n[1],r=ve(n[3],{...f(e),column:e.indent+1+n[0].length-n[3].length});n[2]===void 0&&r.name==="observable"&&r.isOptional&&!r.isCollection||Ae(t,r,e);let o=null,s=[],a=null,c=null,d=null;for(let m=t.peekChild(e.indent);m!==void 0;m=t.peekChild(e.indent)){t.reader.takeSignificant();let u=R(m.content);if(u==="description")a=G(t,m,a,`Query '${i}'`);else if(u==="by"){let y=Ro(t,m,"by");y!==void 0&&(o!==null&&t.error(p.InvalidQueryParameter,`Query '${i}' already declares 'by' - a query can have at most one key parameter`,f(m)),o=y)}else if(u==="filter"){let y=Ro(t,m,"filter");y!==void 0&&s.push(y)}else u==="authorize"?d=Re(d,_e(t,m)):u==="scoped"?c=Oc(t,m,c,i)??c:wc.has(u)?t.skipOpaqueBlock(m.indent):(t.error(p.UnknownQueryDirective,`Unexpected '${m.content}' in query body - expected description, by, filter, authorize, scoped or performer`,f(m)),t.skipBlock(m.indent))}return{kind:"QuerySyntax",name:i,returnType:r,by:o,filters:s,description:a,isObservable:n[2]!==void 0,scope:c,authorize:d,location:f(e)}}l(Do,"parseQuery");function Ro(t,e,n){let i=Pc.exec(e.content.substring(n.length).trim());if(i===null){t.error(p.InvalidQueryParameter,`Invalid '${n}' parameter '${e.content}' - expected '${n} <name> <Type> [from <source>]'`,f(e));return}let r=e.content.indexOf(i[1],n.length),o=ve(i[2],{...f(e),column:e.indent+1+e.content.indexOf(i[2],r+i[1].length)});return Ae(t,o,e),{kind:"QueryParameterSyntax",name:i[1],type:o,source:i[3]===void 0?null:te(i[3],f(e),t.valueContext),location:f(e)}}l(Ro,"parseParameter");function Oc(t,e,n,i){let r=Ac.exec(e.content);if(r===null){t.error(p.InvalidScopeDeclaration,`Invalid scope declaration '${e.content}' - expected 'scoped to <scope>'`,f(e));return}if(n!==null){t.error(p.DuplicateScope,`Query '${i}' already declares a scope - results are narrowed one way`,f(e));return}return r[1]}l(Oc,"parseScope");var Ic=O("^@?[a-z_]\\w*\\s+[\\w.]+");function Wi(t,e){let n=De(t,e);if(n!==void 0){n.isGenerated&&t.error(p.GeneratedPropertyOutsideCommand,"Generated properties can only be declared on commands.",n.location),t.triggerData.push(n);return}Ic.test(e.content)&&/\?|\boptional\b/.test(e.content)&&t.error(p.InvalidTriggerData,`Invalid trigger value '${e.content}' - expected '<name>' or '<name> <Type>'`,f(e)),t.skipOpaqueBlock(e.indent)}l(Wi,"parseTriggerData");function Mo(t,e){let n=t.triggerData.length;for(let i=t.peekChild(e.indent);i!==void 0;i=t.peekChild(e.indent))t.reader.takeSignificant(),R(i.content)==="description"?G(t,i,null,`Trigger '${e.content}'`):le(i)||Wi(t,i);return t.triggerData.slice(n)}l(Mo,"parseTriggerDeclaration");var Tc=O("^reaction\\s+([A-Za-z_]\\w*)$"),Rc=O("^when\\s+([A-Za-z_]\\w*)$"),Dc=O("^every\\s+(\\d+)\\s+(seconds?|minutes?|hours?|days?)$"),Mc=O("^at\\s+(\\d{2}:\\d{2})(?:\\s+on\\s+(?:(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday)|day\\s+(\\d{1,2})))?$"),Nc=new Set(["when","every","at"]),jc=O("^invokes\\s+([A-Z]\\w*)$"),Lc=V("^(@?[\\w.]+)\\s*=(?!=|>)\\s*(.+)$"),Ui=V("^on\\s+refused\\b(?=$|\\s+by\\b)"),qc=V("^on\\s+refused(?:\\s+by\\s+(validation|constraint|authorization)(?:\\s+([A-Za-z_]\\w*(?:\\.\\w+)*))?)?$"),Bc=O("^reads\\s+[A-Z]\\w*\\s+optional(?:\\s|$)");function No(t,e){let n=Tc.exec(e.content)?.[1]??"";n===""&&t.error(p.InvalidReactionDeclaration,`Invalid reaction declaration '${e.content}' - expected 'reaction <Name>'`,f(e));let i=null,r=null,o=null,s=[],a=new Set,c=!1;for(let d=t.peekChild(e.indent);d!==void 0;d=t.peekChild(e.indent)){t.reader.takeSignificant();let m=R(d.content);if(m==="description"){i=G(t,d,i,`Reaction '${n}'`);continue}if(m==="documentation"){r=ue(t,d,r,`Reaction '${n}'`);continue}if(m==="where"){o=He(t,d.content.substring(5).trim(),f(d));continue}if(Ui.test(d.content)){t.error(p.InvalidRefusalBranch,"A refusal branch belongs inside 'invokes <Command>'.",f(d)),t.skipBlock(d.indent),c=!0;continue}if(!Nc.has(m)){t.error(p.InvalidReactionTrigger,`Expected a trigger in reaction body, got '${d.content}' - a reaction is set off by 'when <Name>', 'every <n> <unit>' or 'at <HH:mm>'`,f(d)),t.skipBlock(d.indent),c=!0;continue}let u=Uc(t,d);if(u===void 0){c=!0;continue}let y=Wc(u);if(a.has(y)){t.error(p.DuplicateReactionTrigger,`Reaction '${n}' already declares '${d.content}' - a second says nothing the first did not`,f(d)),t.skipBlock(d.indent);continue}a.add(y),s.push(Fc(t,d,u))}return s.length===0&&!c&&t.error(p.ReactionWithoutTrigger,`Reaction '${n}' must declare at least one trigger - nothing sets it off`,f(e)),{kind:"ReactionSyntax",name:n,description:i,documentation:r,where:o,triggers:s,location:f(e)}}l(No,"parseReaction");function Fc(t,e,n){let i=null,r=[],o=[],s=[],a=[];for(let d=t.peekChild(e.indent);d!==void 0;d=t.peekChild(e.indent)){t.reader.takeSignificant();let m=R(d.content);if(m==="description")i=G(t,d,i,`Trigger '${d.content}'`);else if(m==="produces"){let u=Ut(t,d);u!==void 0&&r.push(u)}else if(m==="invokes"){let u=jc.exec(d.content);if(u===null)t.error(p.InvalidInvokesDeclaration,`Invalid invokes declaration '${d.content}' - expected 'invokes <Command>'`,f(d)),t.skipBlock(d.indent);else{let y=new Se(t.reader.fork(),t.path,t.languages);y.scope=t.scope,y.sourceOptions=t.sourceOptions,Pe(y,d),t.inputUses.push(...y.inputUses);let h=[],v=[];for(let x=t.peekChild(d.indent);x!==void 0;x=t.peekChild(d.indent)){if(t.reader.takeSignificant(),Ui.test(x.content)){let C=Yc(t,x);C!==void 0&&v.push(C);continue}let $=Lc.exec(x.content);$!==null?h.push({kind:"PropertyMappingSyntax",property:$[1].replaceAll("@",""),source:xe($[2],f(x),t.valueContext),location:f(x)}):t.error(p.InvalidPropertyMapping,`Invalid property mapping '${x.content}' - expected '<property> = <source>'`,f(x))}o.push({kind:"InvokesSyntax",command:u[1],mappings:h,onRefused:v,location:f(d)})}}else if(Ui.test(d.content))t.error(p.InvalidRefusalBranch,"A refusal branch belongs inside 'invokes <Command>'.",f(d)),t.skipBlock(d.indent);else if(m==="reads"||m==="file"||d.content==="csharp"||d.content.startsWith("```")){let u=wn(d);u!==void 0&&s.push(u),Bc.test(d.content)&&t.error(p.OptionalReadsNotSupported,"Optional reads are not yet supported (see #308).",f(d)),d.content.startsWith("```")&&t.skipFencedBody(),t.skipOpaqueBlock(d.indent)}else{let u=t.triggerData.length;Wi(t,d);for(let y of t.triggerData.slice(u))a.push({kind:"TriggerDataSyntax",name:y.name,type:y.type,location:y.location})}}let c={kind:"ReactionTriggerSyntax",source:n,description:i,produces:r,invokes:o,location:f(e)};return Ye.set(c,{reads:s,data:a}),c}l(Fc,"parseTrigger");function Yc(t,e){let n=qc.exec(e.content);if(n===null||n[2]!==void 0&&n[1]!=="constraint"){t.error(p.InvalidRefusalBranch,"Expected 'on refused [by validation | by constraint [<Name>] | by authorization]'.",f(e)),t.skipBlock(e.indent);return}let i=[],r=!1,o=!1;for(let s=t.peekChild(e.indent);s!==void 0;s=t.peekChild(e.indent))if(t.reader.takeSignificant(),s.content==="acknowledge")(r||i.length>0||t.peekChild(s.indent)!==void 0)&&(t.error(p.InvalidRefusalBranchBody,"A refusal branch contains 'acknowledge' alone or one or more 'produces' blocks.",f(s)),o=!0),r=!0,t.skipBlock(s.indent);else if(R(s.content)==="produces"){r&&(t.error(p.InvalidRefusalBranchBody,"A refusal branch cannot combine 'acknowledge' and 'produces'.",f(s)),o=!0);let a=Ut(t,s);a!==void 0?i.push(a):o=!0}else t.error(p.InvalidRefusalBranchBody,"Expected 'acknowledge' or 'produces <Event>' in a refusal branch.",f(s)),t.skipBlock(s.indent),o=!0;return!r&&i.length===0&&!o&&t.error(p.InvalidRefusalBranchBody,"A refusal branch must acknowledge or produce an event.",f(e)),{kind:"InvocationRefusalSyntax",selector:n[1]??"any",constraint:n[2]??null,acknowledge:r,produces:i,location:f(e)}}l(Yc,"parseRefusal");function Wc(t){switch(t.kind){case"NamedTriggerSourceSyntax":return JSON.stringify([t.kind,t.name]);case"IntervalTriggerSourceSyntax":return JSON.stringify([t.kind,t.amount,t.unit]);case"ScheduleTriggerSourceSyntax":return JSON.stringify([t.kind,t.time,t.dayOfWeek,t.dayOfMonth])}}l(Wc,"sourceKey");function Uc(t,e){let n=f(e);switch(R(e.content)){case"when":{let i=Rc.exec(e.content);if(i===null){t.error(p.InvalidReactionTrigger,`Invalid trigger '${e.content}' - expected 'when <Name>'`,n),t.skipBlock(e.indent);return}return{kind:"NamedTriggerSourceSyntax",name:i[1],location:n}}case"every":{let i=Dc.exec(e.content),r=i===null?NaN:Number(i[1]);if(i===null||!Number.isInteger(r)||r<1||r>2147483647){t.error(p.InvalidIntervalTrigger,`Invalid interval '${e.content}' - expected 'every <n> <seconds|minutes|hours|days>'`,n),t.skipBlock(e.indent);return}return{kind:"IntervalTriggerSourceSyntax",amount:r,unit:Qc(i[2]),location:n}}default:return zc(t,e)}}l(Uc,"parseTriggerSource");function zc(t,e){let n=f(e),i=Mc.exec(e.content),r=i===null?void 0:Vc(i[1]);if(i===null||r===void 0){t.error(p.InvalidScheduleTrigger,`Invalid schedule '${e.content}' - expected 'at <HH:mm>', optionally followed by 'on <Weekday>' or 'on day <n>'`,n),t.skipBlock(e.indent);return}if(i[3]!==void 0){let o=Number(i[3]);if(o<1||o>31){t.error(p.InvalidScheduleTrigger,`Invalid day of month '${o}' in '${e.content}' - a day of the month is between 1 and 31`,n),t.skipBlock(e.indent);return}return{kind:"ScheduleTriggerSourceSyntax",time:r,dayOfWeek:null,dayOfMonth:o,location:n}}return{kind:"ScheduleTriggerSourceSyntax",time:r,dayOfWeek:i[2]??null,dayOfMonth:null,location:n}}l(zc,"parseSchedule");function Vc(t){let[e,n]=t.split(":").map(Number);if(e>=0&&e<=23&&n>=0&&n<=59)return`${t}:00.0000000`}l(Vc,"timeOf");function Qc(t){switch(t.replace(/s+$/,"")){case"second":return"Seconds";case"minute":return"Minutes";case"hour":return"Hours";default:return"Days"}}l(Qc,"unitOf");var Gc=O(`^when${z}+([^\\n]+)${z}+execute${z}+([A-Za-z_]\\w*(?:\\.\\w+)*)$`),Kc=O(`^otherwise${z}+execute${z}+([A-Za-z_]\\w*(?:\\.\\w+)*)$`),Zc=O(`^with${z}+([A-Za-z_]\\w*)${z}+from${z}+([^\\n]+)$`),_c=O("^item\\.[A-Za-z_]\\w*(?:\\.[A-Za-z_]\\w*)*$"),Jc=new RegExp(`^${z}+|${z}+$`,"gu");function Lo(t,e,n,i){let r=[],o=null,s=null,a=!1;for(let c=t.peekChild(e.indent);c!==void 0;c=t.peekChild(e.indent)){t.reader.takeSignificant();let d=Gc.exec(c.content),m=Kc.exec(c.content);if(d!==null){a&&t.error(p.MisplacedActionOtherwise,"A 'when' alternative must precede 'otherwise'",f(c));let u=He(t,d[1],f(c),!0),y=jo(t,c);u!==null&&(zi(t,u),r.push({kind:"ScreenActionAlternativeSyntax",condition:u,command:d[2],arguments:y,location:f(c)}))}else if(c.content==="otherwise hidden"||m!==null)if(a&&t.error(p.MisplacedActionOtherwise,"A guarded action permits only one 'otherwise'",f(c)),a=!0,m!==null)o={kind:"ScreenActionOtherwiseSyntax",outcome:"Execute",command:m[1],arguments:jo(t,c),location:f(c)};else{o={kind:"ScreenActionOtherwiseSyntax",outcome:"Hidden",command:null,arguments:[],location:f(c)};for(let u=t.peekChild(c.indent);u!==void 0;u=t.peekChild(c.indent))t.reader.takeSignificant(),t.error(p.InvalidActionAlternative,"'otherwise hidden' cannot declare command arguments",f(u)),t.skipBlock(u.indent)}else if(R(c.content)==="navigate")s!==null&&t.error(p.InvalidActionAlternative,"A guarded action permits only one 'navigate to'",f(c)),s=i(t,c.content,c)??null;else{let u=R(c.content)==="label";t.error(u?p.UnknownActionDirective:p.InvalidActionAlternative,u?"A guarded action's header already supplies its label":`Unexpected '${c.content}' in guarded action - expected 'when <condition> execute <Command>', 'otherwise hidden', 'otherwise execute <Command>' or 'navigate to ...'`,f(c)),t.skipBlock(c.indent)}}return r.length===0&&t.error(p.GuardedActionWithoutAlternatives,"A guarded action must declare at least one 'when' alternative",f(e)),{kind:"ScreenGuardedActionSyntax",label:n,alternatives:r,otherwise:o,navigate:s,location:f(e)}}l(Lo,"parseGuardedAction");function jo(t,e){let n=[];for(let i=t.peekChild(e.indent);i!==void 0;i=t.peekChild(e.indent)){t.reader.takeSignificant();let r=Zc.exec(i.content);r!==null?n.push({kind:"InteractionArgumentSyntax",name:r[1],binding:r[2].replace(Jc,""),location:f(i)}):(t.error(p.InvalidInteractionArgument,`Invalid argument '${i.content}' - expected 'with <name> from <binding>'`,f(i)),t.skipBlock(i.indent))}return n}l(jo,"parseArguments");function zi(t,e){if(e.kind==="LogicalConditionSyntax"){zi(t,e.left),zi(t,e.right);return}let n=e.right.kind==="LiteralExpressionSyntax"?e.right.value:void 0,i=_c.test(e.left)&&e.right.kind==="LiteralExpressionSyntax";["GreaterThan","GreaterThanOrEqual","LessThan","LessThanOrEqual"].includes(e.operator)?i&&=typeof n=="number"||typeof n=="object"&&n!==null:["Contains","StartsWith"].includes(e.operator)&&(i&&=typeof n=="string"),i||t.error(p.UnsupportedActionConditionOperand,"Guarded action conditions compare 'item.<field>' with a literal; ordering requires a number and text operators require a string",e.location)}l(zi,"validateCondition");var Vt=`(?:"(${_})"|(\\$strings\\.\\w+(?:\\.\\w+)*))`,Hc=O("^screen\\s+([A-Za-z_]\\w*)$"),Xc=O("^data\\s+([\\w.]+(?:\\[\\])?)\\s+via\\s+query\\s+(\\w+(?:\\.\\w+)*)(?:\\s+by\\s+(\\w+))?$"),ed=O("^action\\s+([A-Za-z_]\\w*(?:\\.\\w+)*)$"),td=O(`^label\\s+${Vt}$`),nd=O(`^action\\s+${Vt}$`),id=O("^navigate\\s+to\\s+(\\w+(?:\\.\\w+)*)(?:\\s+by\\s+(\\w+))?$"),rd=O("^[a-z_]\\w*$"),od=O(`^title\\s+${Vt}$`),ad=O(`^column\\s+([\\w.]+)(?:\\s+label\\s+${Vt})?$`),sd=O("^on\\s+row-click\\s+(navigate\\s+to\\s+.+)$"),ld=O(`^field\\s+([\\w.]+)\\s+label\\s+${Vt}$`),zt=l((t,e)=>t[e]!==void 0?H(t[e]):t[e+1],"operandText"),cd=l(t=>["on","uses"].includes(R(t.content)),"isInteraction"),dd=l((t,e)=>e.content.startsWith("```")||t.languages.has(e.content),"isCodeLine");function qo(t,e){let n=Hc.exec(e.content);n===null&&t.error(p.InvalidScreenDeclaration,`Invalid screen declaration '${e.content}' - expected 'screen <Name>'`,f(e));let i=[];for(let r=t.peekChild(e.indent);r!==void 0;r=t.peekChild(e.indent))t.reader.takeSignificant(),le(r)||Bo(t,r,i);return{kind:"ScreenSyntax",name:n?.[1]??"",directives:i,location:f(e)}}l(qo,"parseScreen");function Bo(t,e,n){let i=pd(t,e);i!==void 0&&n.push(i)}l(Bo,"pushDirective");function Fo(t,e){let n=[];for(let i=t.peekChild(e.indent);i!==void 0;i=t.peekChild(e.indent))t.reader.takeSignificant(),Bo(t,i,n);return n}l(Fo,"parseDirectives");function pd(t,e){switch(R(e.content)){case"data":return fd(t,e);case"action":return ud(t,e);case"template":return md(t,e);case"section":return yd(t,e);case"title":return hd(t,e);case"table":return Sd(t,e);case"summary":return gd(t,e);case"navigate":return Rn(t,e.content,e);case"on":return Pe(t,e),{kind:"ScreenBehaviorSyntax",location:f(e)};case"uses":return t.skipOpaqueBlock(e.indent),{kind:"ScreenUsesBehaviorSyntax",location:f(e)};default:if(dd(t,e))return xd(t,e);t.error(p.UnknownScreenDirective,`Unexpected '${e.content}' in screen body`,f(e)),t.skipBlock(e.indent);return}}l(pd,"parseDirective");function fd(t,e){let n=Xc.exec(e.content);if(n===null){t.error(p.InvalidDataDirective,`Invalid data directive '${e.content}' - expected 'data <ReadModel> via query <Query> [by <param>]'`,f(e));return}return{kind:"ScreenDataSyntax",type:ve(n[1],f(e)),query:n[2],by:n[3]??null,location:f(e)}}l(fd,"parseData");function ud(t,e){let n=nd.exec(e.content);if(n!==null)return Lo(t,e,zt(n,1),Rn);let i=ed.exec(e.content);if(i===null){t.error(p.InvalidActionDirective,`Invalid action directive '${e.content}' - expected 'action <Command>'`,f(e)),t.skipBlock(e.indent);return}let r=null,o=null;for(let s=t.peekChild(e.indent);s!==void 0;s=t.peekChild(e.indent)){t.reader.takeSignificant();let a=td.exec(s.content);a!==null?r=zt(a,1):R(s.content)==="navigate"?o=Rn(t,s.content,s)??null:t.error(p.UnknownActionDirective,`Unexpected '${s.content}' in action - expected 'label "..."' or 'navigate to ...'`,f(s))}return{kind:"ScreenActionSyntax",command:i[1],label:r,navigate:o,location:f(e)}}l(ud,"parseAction");function Rn(t,e,n){let i=id.exec(e);if(i===null){t.error(p.InvalidNavigation,`Invalid navigation '${e}' - expected 'navigate to <Screen> [by <param>]'`,f(n));return}return{kind:"ScreenNavigateSyntax",screen:i[1],by:i[2]??null,location:f(n)}}l(Rn,"parseNavigate");function md(t,e){let n=e.content.substring(8).trim(),i=[];for(let r=t.peekChild(e.indent);r!==void 0;r=t.peekChild(e.indent)){if(t.reader.takeSignificant(),!rd.test(r.content)){t.error(p.InvalidScreenLayoutSlot,`Expected a slot name in template '${n}', got '${r.content}'`,f(r)),t.skipBlock(r.indent);continue}i.push({kind:"ScreenSlotSyntax",name:r.content,directives:Fo(t,r),location:f(r)})}return{kind:"ScreenTemplateReferenceSyntax",name:n,slots:i,location:f(e)}}l(md,"parseTemplateReference");function yd(t,e){return{kind:"ScreenSectionSyntax",name:e.content.substring(7).trim(),directives:Fo(t,e),location:f(e)}}l(yd,"parseSection");function hd(t,e){let n=od.exec(e.content);return n===null?(t.error(p.InvalidTitleDirective,`Invalid title directive '${e.content}' - expected 'title "..."'`,f(e)),{kind:"ScreenTitleSyntax",text:"",location:f(e)}):{kind:"ScreenTitleSyntax",text:zt(n,1),location:f(e)}}l(hd,"parseTitle");function Sd(t,e){let n=e.content.substring(5).trim(),i=[],r=null;for(let o=t.peekChild(e.indent);o!==void 0;o=t.peekChild(e.indent)){t.reader.takeSignificant();let s=ad.exec(o.content),a=sd.exec(o.content);if(s!==null){let c=s[2]!==void 0||s[3]!==void 0;i.push({kind:"ScreenColumnSyntax",property:s[1],label:c?zt(s,2):null,location:f(o)})}else a!==null?r=Rn(t,a[1],o)??null:R(o.content)==="on"?Pe(t,o):cd(o)?t.skipOpaqueBlock(o.indent):t.error(p.UnknownTableDirective,`Unexpected '${o.content}' in table - expected 'column ...', 'on row-click navigate to ...', 'on <trigger>' or 'uses <Behavior>'`,f(o))}return{kind:"ScreenTableSyntax",target:n,columns:i,rowClick:r,location:f(e)}}l(Sd,"parseTable");function gd(t,e){let n=e.content.substring(7).trim(),i=[];for(let r=t.peekChild(e.indent);r!==void 0;r=t.peekChild(e.indent)){t.reader.takeSignificant();let o=ld.exec(r.content);if(o===null){t.error(p.UnknownSummaryDirective,`Unexpected '${r.content}' in summary - expected 'field <property> label "..."'`,f(r));continue}i.push({kind:"ScreenFieldSyntax",property:o[1],label:zt(o,2),location:f(r)})}return{kind:"ScreenSummarySyntax",target:n,fields:i,location:f(e)}}l(gd,"parseSummary");function xd(t,e){let n=e.content.startsWith("```")?e.content.substring(3):e.content;if(!t.languages.has(n)){t.error(p.ExpectedCodeFence,`Expected a registered language on the opening fence, not '${e.content}'`,f(e));return}e.content.startsWith("```")||t.warning(p.LegacyInlineCodeFence,`'${n}' on its own line is deprecated - use '\`\`\`${n}' instead`,f(e));let i=yt(t,n,e);return i===null?void 0:{kind:"ScreenCodeSyntax",code:{kind:"CodeBlockSyntax",language:n,code:i,location:f(e)},location:f(e)}}l(xd,"parseCode");var vd=O("^(?:given\\s+operation|then\\s+(?:operation|compensated))(?:\\s|$)"),$d=O("^(given operation|then operation|then compensated)\\s+([A-Za-z_]\\w*(?:\\.[A-Za-z_]\\w*)*)(\\s+fails)?$"),kd=O("^specification\\s+([A-Za-z_]\\w*)$"),bd="([A-Z]\\w*(?:\\.\\w+)*)",Ed="(?:\\s+(?<property>[\\w.]+)\\s*=(?!=|>)\\s*(?<value>.+))?",$t=l((t,e="")=>V(`^${t}\\s+${bd}${e}${Ed}$`.replaceAll("\\s",z)),"stepPattern"),Cd=$t("given"),Pd=$t("when\\s+append"),Ad=$t("when"),wd=$t("then"),Od=O("^then\\s+query\\b"),Yo=O("^(?:given|then)\\s+readmodel\\b"),Id=$t("given\\s+readmodel"),Td=$t("then\\s+readmodel","(?<exactly>\\s+exactly)?"),Wo=O("^then\\s+no\\b"),Rd=O(`^then\\s+error\\s+"(${_})"$`),Gi=O("^([\\w.]+)\\s*=(?!=|>)\\s*(.+)$"),Dd=V("^([\\w.]+)\\s*=(?!=|>)\\s*(.+)$"),Md=O("^given\\s+clock\\b"),Nd=O("^given\\s+capture\\b"),jd=O("^when\\s+clock\\b"),Ld=O("^when\\s+trigger\\b"),qd=O("^when\\s+capture\\b"),Bd=O("^when\\s+query\\b"),Fd=O("^then\\s+result\\b"),Yd=O("^then\\s+no\\s+result\\b"),Wd=V("^when\\s+redelivered\\b"),Ud=V("^when\\s+redelivered\\s+([A-Za-z_]\\w*(?:\\.\\w+)*)\\s+to\\s+([A-Za-z_]\\w*(?:\\.\\w+)*)$"),zd=O("^then\\s+no\\s+events\\b"),Vd=O('^(given|when)\\s+clock\\s+"(\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(?::\\d{2}(?:\\.\\d+)?)?(?:Z|[+-]\\d{2}:\\d{2}))"$'),Qd=O("^when\\s+trigger\\s+([A-Za-z_]\\w*)$"),Gd=O("^(?:given|when)\\s+capture\\s+([A-Za-z_]\\w*)$"),Kd=O("^when\\s+query\\s+([A-Za-z_]\\w*(?:\\.\\w+)*)$"),Zd=O("^then\\s+result(\\s+exactly)?$"),Uo=V("^then\\s+no\\s+readmodel\\s+([A-Z]\\w*)\\s+for\\s+(.+)$"),_d=V(`^(?:"${_}"|'(?:[^'\\\\]|\\\\.)*')$`),Jd=V("^then\\s+query\\s+([A-Za-z_]\\w*(?:\\.\\w+)*)(\\s+exactly)?$");function Ki(t,e){let n=kd.exec(e.content)?.[1]??"";n===""&&t.error(p.InvalidSpecificationDeclaration,`Invalid specification declaration '${e.content}' - expected 'specification <Name>'`,f(e));let i=null,r={givenOperationFailures:[],thenOperations:[],thenCompensated:[],thenAbsentReadModels:[],thenQueries:[],given:[],givenReadModels:[],when:null,whenAppended:null,whenRedelivered:null,whenDeclared:!1,thenEvents:[],thenEventsInAnyOrder:!1,thenNoEvents:!1,thenReadModels:[],thenErrors:[],givenClock:null,givenCaptures:[],whenClock:null,whenTrigger:null,whenCapture:null,whenQuery:null,thenResults:[],thenNoResult:null,thenDenied:null,givenCaller:null,thenReturns:null};for(let c=t.peekChild(e.indent);c!==void 0;c=t.peekChild(e.indent)){if(t.reader.takeSignificant(),le(c)||Hd(t,c,r))continue;let d=Wo.test(c.content)?"then":R(c.content);d==="description"?i=G(t,c,i,`Specification '${n}'`):d==="given"?Xd(t,c,r):d==="when"?ip(t,c,r,n):d==="then"?rp(t,c,r):(t.error(p.UnknownSpecificationDirective,`Unexpected '${R(c.content)}' in specification body`,f(c)),t.skipBlock(c.indent))}r.noEventsLine!==void 0&&(r.whenAppended!==null||r.thenEvents.length>0||r.thenEventsInAnyOrder||r.thenErrors.length>0||r.thenDenied!==null)&&t.error(p.InvalidNoEventsExpectation,"'then no events' cannot follow 'when append' or accompany event, event-order, error or denial expectations.",f(r.noEventsLine));let{whenDeclared:o,noEventsLine:s,...a}=r;return{kind:"SpecificationSyntax",sourceOptions:t.sourceOptions,name:n,description:i,...a,location:f(e)}}l(Ki,"parseSpecification");function Hd(t,e,n){if(!vd.test(e.content))return!1;let i=$d.exec(e.content);if(i===null||i[1]==="given operation"!=(i[3]!==void 0))t.error(p.InvalidOperationSpecification,"Expected 'given operation <Name> fails', 'then operation <Name>' or 'then compensated <Name>'.",f(e)),pe(t,e.indent);else if(i[1]==="then operation"){let r=[];for(let o=t.peekChild(e.indent);o!==void 0;o=t.peekChild(e.indent)){t.reader.takeSignificant();let s=St(t,o,Gi,p.InvalidOperationSpecification);s!==null&&r.push(s)}n.thenOperations.push({kind:"SpecificationOperationSyntax",operation:i[2],values:r,location:f(e)})}else Wt(t,e,p.InvalidOperationSpecification,"Failure and compensation assertions cannot have children."),i[1]==="given operation"?n.givenOperationFailures.push({kind:"SpecificationOperationFailureSyntax",operation:i[2],location:f(e)}):n.thenCompensated.push({kind:"SpecificationCompensatedSyntax",operation:i[2],location:f(e)});return!0}l(Hd,"parseOperationStep");function Xd(t,e,n){if(Md.test(e.content))n.givenClock!==null?(t.error(p.InvalidSpecificationClock,"A specification states its clock at most once.",f(e)),pe(t,e.indent)):n.givenClock=zo(t,e,"given");else if(Nd.test(e.content)){let i=Vo(t,e,"given");i!==null&&n.givenCaptures.push(i)}else if(e.content.startsWith("given caller"))n.givenCaller!==null?(t.error(p.DuplicateSpecificationCallerOrDenied,"A specification has at most one 'given caller' block.",f(e)),t.skipBlock(e.indent)):n.givenCaller=np(t,e);else if(Yo.test(e.content)){let i=Qo(t,e,Id,"given");i!==void 0&&n.givenReadModels.push(i)}else{let i=Zi(t,e,Cd,"given");i!==void 0&&n.given.push(i)}}l(Xd,"parseGiven");var ep=O(`^role${z}+"(${_})"$`),tp=O(`^claim${z}+"(${_})"${z}*=${z}*"(${_})"$`);function np(t,e){if(e.content!=="given caller")return t.error(p.InvalidSpecificationCaller,"Expected exactly 'given caller'.",f(e)),t.skipBlock(e.indent),null;let n=!1,i=[],r=[];for(let o=t.peekChild(e.indent);o!==void 0;o=t.peekChild(e.indent)){t.reader.takeSignificant();let s=ep.exec(o.content),a=tp.exec(o.content);o.content==="authenticated"&&!n?n=!0:s!==null?i.push(H(s[1])):a!==null?r.push({kind:"SpecificationCallerClaimSyntax",type:H(a[1]),value:H(a[2]),location:f(o)}):t.error(p.InvalidSpecificationCaller,`Invalid caller fixture '${o.content}' - expected authenticated, role "...", or claim "..." = "...".`,f(o))}return{kind:"SpecificationCallerSyntax",authenticated:n,roles:i,claims:r,location:f(e)}}l(np,"parseCaller");function ip(t,e,n,i){let r=e.content.startsWith("when append");if(n.whenDeclared){let c=n.whenAppended!==null||r?p.ConflictingSpecificationActions:p.DuplicateSpecificationWhen;t.error(c,`Specification '${i}' already declares a 'when' - a specification can have at most one`,f(e)),pe(t,e.indent);return}if(n.whenDeclared=!0,r){n.whenAppended=Zi(t,e,Pd,"when append")??null;return}if(Wd.test(e.content)){let c=Ud.exec(e.content);c===null?(t.error(p.UnmatchedRedeliveredOccurrence,"Expected 'when redelivered <Event> to <Reaction>'.",f(e)),pe(t,e.indent)):n.whenRedelivered={kind:"SpecificationRedeliverySyntax",eventType:c[1],reaction:c[2],...Qi(t,e),location:f(e)};return}if(jd.test(e.content)){n.whenClock=zo(t,e,"when");return}if(Ld.test(e.content)){n.whenTrigger=Vi(t,e,Qd,p.InvalidSpecificationTrigger,"when trigger","when trigger <Trigger>",(c,d)=>({kind:"SpecificationTriggerSyntax",trigger:c,values:d,location:f(e)}));return}if(qd.test(e.content)){n.whenCapture=Vo(t,e,"when");return}if(Bd.test(e.content)){n.whenQuery=Vi(t,e,Kd,p.InvalidSpecificationQueryAction,"when query","when query <Query>",(c,d)=>({kind:"SpecificationWhenQuerySyntax",query:c,arguments:d,location:f(e)}));return}let o=Ad.exec(e.content);if(o===null){t.error(p.InvalidSpecificationWhen,`Invalid 'when' declaration '${e.content}' - expected 'when <CommandType>' or 'when append <EventType>'`,f(e)),pe(t,e.indent);return}let s=[],a=Qi(t,e,s,o);n.when={kind:"SpecificationCommandSyntax",commandType:o[1],...a,generatedValues:s,inlineProperty:o.groups?.property??null,location:f(e)}}l(ip,"parseWhen");function rp(t,e,n){if(zd.test(e.content)){e.content!=="then no events"||n.thenNoEvents?t.error(p.InvalidNoEventsExpectation,"Expected one 'then no events' directive.",f(e)):(n.thenNoEvents=!0,n.noEventsLine=e);let o=t.peekChild(e.indent);o!==void 0&&t.error(p.InvalidNoEventsExpectation,"'then no events' cannot have child mappings.",f(o)),pe(t,e.indent);return}if(wi.test(e.content)){let o=_r(t,e);n.thenReturns!==null?t.error(p.InvalidReturnExpectation,"A specification declares at most one return expectation.",f(e)):n.thenReturns=o;return}if(e.content.startsWith("then events")){e.content!=="then events in any order"||n.thenEventsInAnyOrder?t.error(p.InvalidSpecificationEventOrder,"Expected one 'then events in any order' directive.",f(e)):n.thenEventsInAnyOrder=!0,pe(t,e.indent);return}if(Fd.test(e.content)){ap(t,e,n);return}if(Yd.test(e.content)){e.content!=="then no result"||n.thenNoResult!==null?t.error(p.InvalidSpecificationQueryAction,"Expected one 'then no result' directive.",f(e)):n.thenNoResult={kind:"SpecificationNoResultSyntax",location:f(e)},pe(t,e.indent);return}if(e.content.startsWith("then denied")){e.content!=="then denied"?(t.error(p.InvalidSpecificationDenied,"Expected exactly 'then denied'.",f(e)),pe(t,e.indent)):n.thenDenied!==null?t.error(p.DuplicateSpecificationCallerOrDenied,"A specification has at most one 'then denied' outcome.",f(e)):n.thenDenied={kind:"SpecificationDeniedSyntax",location:f(e)};return}if(e.content==="then error"){n.thenErrors.push({kind:"SpecificationErrorSyntax",name:null,location:f(e)});return}let i=Rd.exec(e.content);if(i!==null){n.thenErrors.push({kind:"SpecificationErrorSyntax",name:H(i[1]),location:f(e)});return}if(R(e.content.substring(4).trim())==="error"){t.error(p.InvalidThenError,`Invalid 'then error' declaration '${e.content}' - expected 'then error' or 'then error "<reason>"'`,f(e)),pe(t,e.indent);return}if(Wo.test(e.content)){if(t.sourceOptions.numericMode==="exact"){let s=op(t,e);s!==null&&n.thenAbsentReadModels.push(s);return}let o=Uo.exec(e.content);if(o!==null&&!o[2].endsWith(" exactly")){let s=te(o[2].trim(),f(e),t.valueContext);(s.kind==="LiteralExpressionSyntax"||s.kind==="ObjectExpressionSyntax")&&n.thenAbsentReadModels.push({kind:"SpecificationAbsentReadModelSyntax",name:o[1],key:s,location:f(e)})}t.skipOpaqueBlock(e.indent);return}if(Od.test(e.content)){let o=t.sourceOptions.numericMode==="exact",s=l((u,y,h)=>{if(!o)return t.skipOpaqueBlock(h.indent);t.error(u,y,f(h)),t.skipBlock(h.indent)},"reject"),a=Jd.exec(e.content);if(a===null)return s(p.InvalidSpecificationQuery,`Invalid 'then query' declaration '${e.content}' - expected 'then query <Query> [exactly]'`,e);let c=[],d=[],m=!1;for(let u=t.peekChild(e.indent);u!==void 0;u=t.peekChild(e.indent))t.reader.takeSignificant(),u.content==="arguments"&&!m?c.push(...Qt(t.valueContext,u,!0)):u.content==="arguments"?s(p.DuplicateSpecificationQueryArguments,`Query assertion '${a[1]}' already declares arguments`,u):u.content==="result"?d.push({kind:"SpecificationQueryResultSyntax",properties:Qt(t.valueContext,u,!0),exactly:!1,location:f(u)}):s(p.UnknownSpecificationQueryDirective,`Unexpected '${R(u.content)}' in 'then query' body - expected arguments or result`,u),m||=u.content==="arguments";n.thenQueries.push({kind:"SpecificationQuerySyntax",query:a[1],arguments:c,results:d,exactly:a[2]!==void 0,location:f(e)});return}if(Yo.test(e.content)){let o=Qo(t,e,Td,"then");o!==void 0&&n.thenReadModels.push(o);return}let r=Zi(t,e,wd,"then");r!==void 0&&n.thenEvents.push(r)}l(rp,"parseThen");function op(t,e){let n=Uo.exec(e.content);if(n===null||n[2].endsWith(" exactly"))return t.error(p.InvalidAbsentReadModelStep,`Invalid absence assertion '${e.content}' - expected 'then no readmodel <ReadModelType> for <key>'`,f(e)),pe(t,e.indent),null;let i=n[2].trim(),o=!(i.startsWith('"')||i.startsWith("'"))||_d.test(i)?te(i,f(e),t.valueContext):null,s=o!==null&&(o.kind==="LiteralExpressionSyntax"||o.kind==="ObjectExpressionSyntax");s||t.error(p.InvalidAbsentReadModelStep,`Invalid absence key '${i}' - expected exactly one concrete value.`,f(e));let a=!1;for(let c=t.peekChild(e.indent);c!==void 0;c=t.peekChild(e.indent))t.reader.takeSignificant(),t.error(p.InvalidAbsentReadModelStep,"An absent read model assertion cannot have child mappings.",f(c)),a=!0;return a||!s?null:{kind:"SpecificationAbsentReadModelSyntax",name:n[1],key:o,location:f(e)}}l(op,"parseAbsentReadModel");function pe(t,e){if(t.sourceOptions.numericMode!=="exact")return t.skipBlock(e);t.skipOpaqueBlock(e)}l(pe,"skipBody");function zo(t,e,n){let i=Vd.exec(e.content);return pe(t,e.indent),i===null||i[1]!==n?(t.error(p.InvalidSpecificationClock,`Invalid '${n} clock' - expected '${n} clock "<ISO 8601 instant>"', such as '${n} clock "2026-10-05T08:00:00Z"'`,f(e)),null):{kind:"SpecificationClockSyntax",instant:i[2],location:f(e)}}l(zo,"parseClock");function Vo(t,e,n){return Vi(t,e,Gd,p.InvalidSpecificationCapture,`${n} capture`,`${n} capture <Capture>`,(i,r)=>({kind:"SpecificationCaptureSyntax",capture:i,record:r,location:f(e)}))}l(Vo,"parseCapture");function Vi(t,e,n,i,r,o,s){let a=n.exec(e.content);return a===null?(t.error(i,`Invalid '${r}' declaration '${e.content}' - expected '${o}'`,f(e)),pe(t,e.indent),null):s(a[1],Qt(t,e))}l(Vi,"parseNamedStep");function ap(t,e,n){let i=Zd.exec(e.content);if(i===null){t.error(p.InvalidSpecificationQueryAction,`Invalid 'then result' declaration '${e.content}' - expected 'then result [exactly]'`,f(e)),pe(t,e.indent);return}n.thenResults.push({kind:"SpecificationQueryResultSyntax",properties:Qt(t,e),exactly:i[1]!==void 0,location:f(e)})}l(ap,"parseResult");function Qo(t,e,n,i){let r=n.exec(e.content);if(r===null){t.error(p.InvalidReadModelStep,`Invalid '${i} readmodel' declaration '${e.content}' - expected '${i} readmodel <ReadModelType>'`,f(e)),pe(t,e.indent);return}return{kind:"SpecificationReadModelSyntax",name:r[1],properties:Qt(t,e,!1,r),exactly:i==="then"&&r.groups?.exactly!==void 0,inlineProperty:r.groups?.property??null,location:f(e)}}l(Qo,"parseReadModelStep");function Zi(t,e,n,i){let r=n.exec(e.content);if(r===null){t.error(p.InvalidEventStep,`Invalid '${i}' declaration '${e.content}' - expected '${i} <EventType>'`,f(e)),pe(t,e.indent);return}return{kind:"SpecificationEventSyntax",eventType:r[1],...Qi(t,e,void 0,r,i),inlineProperty:r.groups?.property??null,location:f(e)}}l(Zi,"parseEventStep");var sp=de("^stream\\s+([A-Za-z_]\\w*)\\.([A-Za-z_]\\w*)$"),lp=O("^streamId\\s*=(?!=|>)\\s*(.+)$");function Qi(t,e,n,i,r){let o=[];xn(t,e,i,o);let s=null,a,c,d=!1;for(let m=t.peekChild(e.indent);m!==void 0;m=t.peekChild(e.indent)){if(t.reader.takeSignificant(),n!==void 0&&hn.test(m.content)){let y=St(t,m,Sn,p.InvalidGeneratedFixture);y!==null&&n.push(y);continue}let u=Gi.exec(m.content);if(u!==null)jt(t,o,Ko(t,m,u));else if(R(m.content)==="stream"||m.content.startsWith("no stream")){if(r===void 0){t.error(p.SpecificationStreamOnCommand,"A command occurrence cannot declare a route; assert it on a then event.",f(m)),t.skipBlock(m.indent);continue}if(d){t.error(p.InvalidSpecificationStream,"An event occurrence declares at most one stream or no stream directive.",f(m)),t.skipBlock(m.indent);continue}let y=sp.exec(m.content);m.content==="no stream"&&r==="then"?(c={kind:"SpecificationNoStreamSyntax",location:f(m)},d=!0,Go(t,m)):y!==null?(a=cp(t,m,y),d=!0):(t.error(p.InvalidSpecificationStream,"Expected 'stream Source.Stream', or 'no stream' on a then event.",f(m)),t.skipBlock(m.indent))}else if(R(m.content)==="for"){let y=m.content.substring(3).trim();y.length===0?t.error(p.InvalidSpecificationEventSource,"Invalid event-source assertion 'for' - expected 'for <value>'",f(m)):s!==null?t.error(p.DuplicateSpecificationEventSource,"A specification step can declare its event-source assertion only once",f(m)):s=te(y,f(m),t)}else t.error(p.InvalidSpecificationValue,`Invalid property mapping '${m.content}' - expected '<property> = <value>'`,f(m))}return{values:o,for:s,...a===void 0?{}:{stream:a},...c===void 0?{}:{noStream:c}}}l(Qi,"parseValuesWithEventSource");function cp(t,e,n){let i=null,r=[],o=!1,s={};for(let a=t.peekChild(e.indent);a!==void 0;a=t.peekChild(e.indent)){if(t.reader.takeSignificant(),a.content==="streamId"){i!==null||o?(t.error(p.InvalidSpecificationStream,"Declare either one 'streamId = <literal>' mapping or one streamId part block.",f(a)),t.skipBlock(a.indent)):(o=!0,s.streamId=f(a),r=Di(t,a,p.InvalidSpecificationStream));continue}let c=lp.exec(a.content);if(c===null||i!==null||o){t.error(p.InvalidSpecificationStream,"Declare either one 'streamId = <literal>' mapping or one streamId part block.",f(a)),t.skipBlock(a.indent);continue}let d={...f(a),column:a.indent+1+a.content.indexOf(c[1],a.content.indexOf("=")+1)};i={kind:"PropertyMappingSyntax",property:"streamId",source:te(c[1],d,t),location:f(a)},Go(t,a)}return{kind:"SpecificationStreamSyntax",eventSource:n[1],stream:n[2],streamId:i,streamIdParts:r,directiveLocations:s,referenceLocation:{...f(e),column:e.indent+1+e.content.indexOf(n[1],6)},referenceLength:n[1].length+1+n[2].length,location:f(e)}}l(cp,"parseSpecificationStream");function Go(t,e){let n=t.peekChild(e.indent);n!==void 0&&(t.error(p.InvalidSpecificationStream,"This directive cannot have children.",f(n)),t.skipBlock(e.indent))}l(Go,"rejectSpecificationRouteChildren");function Qt(t,e,n=!1,i){let r=[];xn(t,e,i,r);for(let o=t.peekChild(e.indent);o!==void 0;o=t.peekChild(e.indent)){t.reader.takeSignificant();let s=(n||t.sourceOptions.numericMode==="exact"?Dd:Gi).exec(o.content);if(s===null){t.error(p.InvalidSpecificationValue,`Invalid property mapping '${o.content}' - expected '<property> = <value>'`,f(o));continue}jt(t,r,Ko(t,o,s,n))}return r}l(Qt,"parseValues");function Ko(t,e,n,i=!1){return{kind:"PropertyMappingSyntax",property:n[1],source:te(n[2],f(e),t,i),location:f(e)}}l(Ko,"mappingOf");var dp=O("^slice\\s+([A-Za-z]\\w*)\\s+([A-Za-z_]\\w*)$"),pp=new Set(["reducer"]);function Zo(t,e){let n=dp.exec(e.content),i="StateChange",r="";n===null?t.error(p.InvalidSliceDeclaration,`Invalid slice declaration '${e.content}' - expected 'slice <Type> <Name>'`,f(e)):(r=n[2],Jr.includes(n[1])?i=n[1]:t.error(p.UnknownSliceType,`Unknown slice type '${n[1]}' - expected StateChange, StateView, Automation or Translate`,f(e)));let o=t.scope;t.scope=[...o,r];let s=null,a=null,c=[],d=[],m=[],u=[],y=[],h=[],v=[],x=[],$=[],C=[],E=[],P=[],A=[];for(let S=t.peekChild(e.indent);S!==void 0;S=t.peekChild(e.indent)){if(t.reader.takeSignificant(),le(S))continue;let k=R(S.content);k==="description"?s=G(t,S,s,`Slice '${r}'`):k==="documentation"?a=ue(t,S,a,`Slice '${r}'`):k==="operation"?d.push(On(t,S).operation):k==="event"?c.push(no(t,S)):k==="command"?m.push(Po(t,S)):k==="query"?u.push(Do(t,S)):k==="projection"?y.push(Fi(t,S)):k==="capture"?v.push(Ii(t,S)):k==="reaction"?h.push(No(t,S)):k==="constraint"?x.push(Ao(t,S)):k==="example"?C.push(Be(t,S)):k==="specification"?$.push(Ki(t,S)):k==="readmodel"?E.push(io(t,S)):k==="screen"?P.push(qo(t,S)):pp.has(k)?(A.push(vo(t,S)),t.skipOpaqueBlock(S.indent)):(t.warning(p.UnknownSliceDirective,`Unknown construct '${k}' in slice '${r}'`,f(S)),t.skipBlock(S.indent))}t.scope=o;let g={kind:"SliceSyntax",type:i,name:r,description:s,documentation:a,examples:C,events:c,operations:d,commands:m,queries:u,projections:y,captures:v,reactions:h,constraints:x,specifications:$,readModels:E,screens:P,location:f(e)};return Ye.set(g,{reducers:A}),g}l(Zo,"parseSlice");var fp=O("^feature\\s+([A-Za-z_]\\w*)$"),up=new Set(["on","uses","contribute"]),_i="description, documentation, depends on <Name>, authorize, import, feature, slice, contribute, example, 'on <trigger>' or 'uses <Behavior>'",Gt=class{static{l(this,"FeatureBody")}name;#e=[];#t=[];#o=[];#r=[];#n=[];#i=null;#a=null;#l=null;constructor(e){this.name=e}tryParse(e,n){let i=R(n.content);switch(i){case"description":return this.#i=G(e,n,this.#i,`Feature '${this.name}'`),!0;case"documentation":return this.#a=ue(e,n,this.#a,`Feature '${this.name}'`),!0;case"depends":return mn(e,n,this.#n,p.UnknownFeatureDirective),!0;case"authorize":return this.#l=Re(this.#l,_e(e,n)),!0;case"import":return ht(e,n,this.#r),!0;case"feature":return this.#e.push(Dn(e,n)),!0;case"example":return this.#o.push(Be(e,n)),!0;case"slice":return this.#t.push(Zo(e,n)),!0;default:return up.has(i)?(Pe(e,n),!0):!1}}build(e,n=!1){return{kind:"FeatureSyntax",name:this.name,description:this.#i,documentation:this.#a,authorize:this.#l,dependsOn:this.#n,features:this.#e,slices:this.#t,examples:this.#o,fileImports:this.#r,isPlacement:n,location:e}}};function Dn(t,e){let n=fp.exec(e.content)?.[1]??"";n===""&&t.error(p.InvalidFeatureDeclaration,`Invalid feature declaration '${e.content}' - expected 'feature <Name>'`,f(e));let i=new Gt(n),r=t.scope;t.scope=[...r,n];for(let o=t.peekChild(e.indent);o!==void 0;o=t.peekChild(e.indent))t.reader.takeSignificant(),i.tryParse(t,o)||(t.error(p.UnknownFeatureDirective,`Unexpected '${R(o.content)}' in feature body - expected ${_i}`,f(o)),t.skipBlock(o.indent));return t.scope=r,i.build(f(e))}l(Dn,"parseFeature");var Ji=O("^module\\s+([A-Za-z_]\\w*)$"),mp=new Set(["on","uses","screen","dialog","form","contribute"]),Hi="description, documentation, depends on <Name>, authorize, import, screen template, dialog template, form, contribute, feature, example, 'on <trigger>' or 'uses <Behavior>'",Kt=class{static{l(this,"ModuleBody")}name;#e=[];#t=[];#o=[];#r=[];#n=null;#i=null;#a=null;constructor(e){this.name=e}tryParse(e,n){let i=R(n.content);switch(i){case"description":return this.#n=G(e,n,this.#n,`Module '${this.name}'`),!0;case"documentation":return this.#i=ue(e,n,this.#i,`Module '${this.name}'`),!0;case"depends":return mn(e,n,this.#r,p.UnknownModuleDirective),!0;case"authorize":return this.#a=Re(this.#a,_e(e,n)),!0;case"import":return ht(e,n,this.#o),!0;case"example":return this.#t.push(Be(e,n)),!0;case"feature":return this.#e.push(Dn(e,n)),!0;default:return mp.has(i)?(Pe(e,n),!0):!1}}parseChildren(e,n){for(let i=e.peekChild(n.indent);i!==void 0;i=e.peekChild(n.indent))e.reader.takeSignificant(),this.tryParse(e,i)||(e.error(p.UnknownModuleDirective,`Unexpected '${R(i.content)}' in module body - expected ${Hi}`,f(i)),e.skipBlock(i.indent))}build(e,n=!1){return{kind:"ModuleSyntax",name:this.name,description:this.#n,documentation:this.#i,authorize:this.#a,dependsOn:this.#r,features:this.#e,examples:this.#t,fileImports:this.#o,isPlacement:n,location:e}}};function Xi(t,e){let n=Ji.exec(e.content)?.[1]??"";n===""&&t.error(p.InvalidModuleDeclaration,`Invalid module declaration '${e.content}' - expected 'module <Name>'`,f(e));let i=new Kt(n),r=t.scope;return t.scope=[n],i.parseChildren(t,e),t.scope=r,i.build(f(e))}l(Xi,"parseModule");var Sp=new WeakMap,Oe=l(t=>JSON.stringify(t),"authoredOrderKey");function Zt(t){return Sp.get(t)??new Map}l(Zt,"authoredOrderOf");function Ho(t){let e=[],n=l((a,c)=>{for(let d of a??[])e.push({name:d.name,scope:c,example:d})},"examples"),i=l((a,c)=>{for(let d of a){let m=[...c,d.name];n(d.examples,m);for(let u of d.slices){let y=[...c,d.name,u.name];n(u.examples,y);for(let h of new Set(se(u).map(v=>v.name)))e.push({name:h,scope:y,kind:"event"});for(let h of u.commands)e.push({name:h.name,scope:y,kind:"command"});for(let h of u.readModels)e.push({name:h.name,scope:y,kind:"readmodel"})}i(d.features,m)}},"features");n(t.examples,[]);for(let a of[...t.concepts,...t.types])e.push({name:a.name,scope:[],kind:"type"});for(let a of t.modules)n(a.examples,[a.name]),i(a.features,[a.name]);let r=l((a,c)=>{let d=l(y=>{let h=y.split("."),v=e.filter($=>$.name===h.at(-1)),x=h.slice(0,-1);if(x.length)return v.filter($=>x.length<=$.scope.length&&x.every((C,E)=>$.scope[$.scope.length-x.length+E]===C));for(let $=c.length;$>=0;$--){let C=v.filter(E=>$<=E.scope.length&&c.slice(0,$).every((P,A)=>E.scope[A]===P));if(C.length)return C}return[]},"candidates"),m=d(a),u=t.imports.filter(y=>y.qualifiedName.split(".").at(-1)===a);return!m.length&&u.length===1&&(m=d(u[0].qualifiedName)),m.length===1?m[0]:void 0},"resolve"),o=l((a,c,d)=>{let m=r(a,d),u=m?.example;if(!u)return null;let y=r(u.type,m.scope);return y?.kind===c?{example:u,name:[...y.scope,y.name].join(".")}:null},"fixture"),s=l((a,c)=>[...a.filter(d=>!c.some(m=>m.property===d.property)),...c],"merge");return{command:l((a,c)=>{if(!a)return a;let d=o(a.commandType,"command",c);if(!d)return a;let{example:m,name:u}=d;return{...a,commandType:u,values:s(m.values,a.values),generatedValues:s(m.generatedValues,a.generatedValues??[]),for:a.for??m.for}},"command"),event:l((a,c)=>{let d=o(a.eventType,"event",c);return d?{...a,eventType:d.name,values:s(d.example.values,a.values),for:a.for??d.example.for}:a},"event"),readModel:l((a,c)=>{let d=o(a.name,"readmodel",c);return d?{...a,name:d.name,properties:s(d.example.values,a.properties)}:a},"readModel")}}l(Ho,"specificationExamples");function Mn(t){return Ho(t).command}l(Mn,"specificationCommandExamples");function Ue(t){let e=Ho(t),n=l((i,r)=>i.map(o=>{let s=[...r,o.name];return{...o,features:n(o.features,s),slices:o.slices.map(a=>{let c=[...r,o.name,a.name],d={...a,specifications:a.specifications.map(m=>({...m,given:m.given.map(u=>e.event(u,c)),givenReadModels:m.givenReadModels.map(u=>e.readModel(u,c)),when:e.command(m.when,c),whenAppended:m.whenAppended===null?null:e.event(m.whenAppended,c),thenEvents:m.thenEvents.map(u=>e.event(u,c)),thenReadModels:m.thenReadModels.map(u=>e.readModel(u,c))}))};return Ye.set(d,we(a)),d})}}),"features");return{...t,modules:t.modules.map(i=>({...i,features:n(i.features,[i.name])}))}}l(Ue,"expandSpecificationExamples");var et=["usesFactsFrom","reactsTo","decidesFrom","asks","shows","verifiedWith","outsideTheModel"];var ze=class extends Error{static{l(this,"InvalidDependencyQuery")}};var tt=class{static{l(this,"ScreenplaySyntaxWalker")}visitNode(e){}visitApplication(e){this.visitNode(e),e.domain!==null&&this.visitDomain(e.domain),e.imports.forEach(n=>this.visitImport(n)),e.fileImports.forEach(n=>this.visitFileImport(n)),e.systems?.forEach(n=>this.visitSystem(n)),e.eventSources?.forEach(n=>this.visitEventSource(n)),e.concepts.forEach(n=>this.visitConcept(n)),e.types.forEach(n=>this.visitType(n)),e.personas.forEach(n=>this.visitPersona(n)),e.policies?.forEach(n=>this.visitPolicy(n)),e.seeds?.forEach(n=>this.visitSeed(n)),e.modules.forEach(n=>this.visitModule(n)),e.examples?.forEach(n=>this.visitSpecificationExample(n))}visitPolicy(e){this.visitNode(e),e.condition!==null&&this.visitPolicyCondition(e.condition),e.code!==null&&this.visitCodeBlock(e.code),e.file!==null&&this.visitFileReference(e.file)}visitPolicyCondition(e){this.visitNode(e),e.kind==="ClaimConditionSyntax"&&e.matches!==null&&this.visitExpression(e.matches),e.kind==="NotPolicyConditionSyntax"&&this.visitPolicyCondition(e.operand),e.kind==="LogicalPolicyConditionSyntax"&&(this.visitPolicyCondition(e.left),this.visitPolicyCondition(e.right))}visitSeed(e){this.visitNode(e),e.groups.forEach(n=>{this.visitNode(n),n.events.forEach(i=>{this.visitNode(i),i.properties.forEach(r=>this.visitPropertyMapping(r))})})}visitPersona(e){this.visitNode(e)}visitAuthorize(e){this.visitNode(e),this.visitPolicyRequirement(e.requirement)}visitPolicyRequirement(e){this.visitNode(e),e.kind==="LogicalPolicyRequirementSyntax"&&(this.visitPolicyRequirement(e.left),this.visitPolicyRequirement(e.right))}visitDomain(e){this.visitNode(e)}visitImport(e){this.visitNode(e)}visitFileImport(e){this.visitNode(e)}visitConcept(e){this.visitNode(e),e.attributes.forEach(n=>this.visitNode(n)),e.validations?.forEach(n=>this.visitValidate(n))}visitType(e){this.visitNode(e),e.properties.forEach(n=>this.visitProperty(n))}visitDependsOn(e){this.visitNode(e)}visitModule(e){this.visitNode(e),e.examples?.forEach(n=>this.visitSpecificationExample(n)),e.dependsOn?.forEach(n=>this.visitDependsOn(n)),e.fileImports.forEach(n=>this.visitFileImport(n)),e.authorize!==null&&this.visitAuthorize(e.authorize),e.features.forEach(n=>this.visitFeature(n))}visitFeature(e){this.visitNode(e),e.examples?.forEach(n=>this.visitSpecificationExample(n)),e.dependsOn?.forEach(n=>this.visitDependsOn(n)),e.fileImports.forEach(n=>this.visitFileImport(n)),e.authorize!==null&&this.visitAuthorize(e.authorize),e.features.forEach(n=>this.visitFeature(n)),e.slices.forEach(n=>this.visitSlice(n))}visitSlice(e){this.visitNode(e),e.examples?.forEach(n=>this.visitSpecificationExample(n)),e.commands.forEach(n=>this.visitCommand(n)),e.operations?.forEach(n=>this.visitOperation(n)),e.events.forEach(n=>this.visitEvent(n)),e.constraints.forEach(n=>this.visitConstraint(n)),e.queries.forEach(n=>this.visitQuery(n)),e.projections.forEach(n=>this.visitProjection(n)),e.readModels.forEach(n=>this.visitReadModel(n)),e.captures.forEach(n=>this.visitCapture(n)),e.reactions.forEach(n=>this.visitReaction(n)),e.screens.forEach(n=>this.visitScreen(n)),e.specifications.forEach(n=>this.visitSpecification(n))}visitTriggerData(e){this.visitNode(e),e.type!==null&&this.visitTypeRef(e.type)}visitReads(e){this.visitNode(e)}visitConcurrency(e){this.visitNode(e)}visitReducer(e){this.visitNode(e),e.rules.forEach(n=>this.visitReducerRule(n))}visitReducerRule(e){this.visitNode(e),e.file!==null&&this.visitFileReference(e.file),e.code!==null&&this.visitCodeBlock(e.code)}visitForm(e){this.visitNode(e),e.populate!==null&&this.visitNode(e.populate),e.fields.forEach(n=>this.visitNode(n)),e.onSubmit!==null&&this.visitScreenDirective(e.onSubmit)}visitCommand(e){this.visitNode(e),e.properties.forEach(n=>this.visitProperty(n)),e.authorize!==null&&this.visitAuthorize(e.authorize),e.stream!=null&&this.visitCommandStream(e.stream),e.streamCandidates?.forEach(n=>this.visitCommandStream(n)),e.validations.forEach(n=>this.visitValidate(n)),e.produces.forEach(n=>this.visitProduces(n)),e.handler!=null&&this.visitHandler(e.handler),e.response!=null&&this.visitCommandResponse(e.response)}visitEventSource(e){this.visitNode(e),e.identifier!==null&&this.visitTypeRef(e.identifier),e.streams.forEach(n=>this.visitEventStream(n))}visitEventStream(e){this.visitNode(e),e.streamId!==null&&this.visitTypeRef(e.streamId),e.streamIdParts.forEach(n=>this.visitEventStreamIdPart(n))}visitEventStreamIdPart(e){this.visitNode(e),this.visitTypeRef(e.type)}visitCommandStream(e){this.visitNode(e),e.streamId!==null&&this.visitPropertyMapping(e.streamId),e.streamIdParts.forEach(n=>this.visitPropertyMapping(n)),e.propertyCandidate!==null&&this.visitProperty(e.propertyCandidate)}visitSystem(e){this.visitNode(e)}visitOperation(e){this.visitNode(e),e.inputs.forEach(n=>this.visitProperty(n)),e.execute!==null&&this.visitOperationPhase(e.execute),e.compensate!==null&&this.visitOperationPhase(e.compensate)}visitOperationPhase(e){this.visitNode(e),e.implementation!==null&&this.visitImplementation(e.implementation),e.file!==null&&this.visitFileReference(e.file),e.code!==null&&this.visitCodeBlock(e.code)}visitSpecificationOperationFailure(e){this.visitNode(e)}visitSpecificationCompensated(e){this.visitNode(e)}visitSpecificationOperation(e){this.visitNode(e),e.values.forEach(n=>this.visitPropertyMapping(n))}visitHandler(e){this.visitNode(e),e.implementation!=null&&this.visitImplementation(e.implementation),e.file!==null&&this.visitFileReference(e.file),e.code!==null&&this.visitCodeBlock(e.code)}visitImplementation(e){this.visitNode(e),e.hints.forEach(n=>this.visitImplementationHint(n))}visitImplementationHint(e){this.visitNode(e)}visitFileReference(e){this.visitNode(e)}visitCodeBlock(e){this.visitNode(e)}visitCommandResponse(e){e.kind==="ScalarCommandResponseSyntax"?this.visitScalarCommandResponse(e):this.visitRecordCommandResponse(e)}visitScalarCommandResponse(e){this.visitNode(e),this.visitPropertyResponseSource(e.source)}visitRecordCommandResponse(e){this.visitNode(e),e.fields.forEach(n=>this.visitResponseField(n))}visitResponseField(e){this.visitNode(e),e.type!==null&&this.visitTypeRef(e.type),this.visitPropertyResponseSource(e.source)}visitPropertyResponseSource(e){this.visitNode(e)}visitSpecificationReturn(e){e.kind==="ScalarSpecificationReturnSyntax"?this.visitScalarSpecificationReturn(e):this.visitRecordSpecificationReturn(e)}visitScalarSpecificationReturn(e){this.visitNode(e),this.visitExpression(e.value)}visitRecordSpecificationReturn(e){this.visitNode(e),e.fields.forEach(n=>this.visitPropertyMapping(n))}visitValidate(e){this.visitNode(e),e.kind==="DeclarativeValidateSyntax"?(e.rules.forEach(n=>this.visitValidationRule(n)),e.requirements?.forEach(n=>{this.visitNode(n),this.visitCondition(n.condition)})):e.code!=null&&this.visitCodeBlock(e.code)}visitValidationRule(e){this.visitNode(e),e.implementation!=null&&this.visitImplementation(e.implementation),e.value!==null&&this.visitExpression(e.value),e.file!==null&&this.visitFileReference(e.file),e.code!==null&&this.visitCodeBlock(e.code)}visitEvent(e){this.visitNode(e),e.properties.forEach(n=>this.visitProperty(n)),e.tags.forEach(n=>this.visitTag(n))}visitTag(e){this.visitNode(e),this.visitExpression(e.value)}visitReadModel(e){this.visitNode(e),e.properties.forEach(n=>this.visitProperty(n))}visitConstraint(e){this.visitNode(e),e.kind==="FileConstraintSyntax"&&this.visitNode(e.file),e.additionalRules.forEach(n=>this.visitConstraint(n))}visitQuery(e){this.visitNode(e),this.visitTypeRef(e.returnType),e.by!==null&&this.visitQueryParameter(e.by),e.filters.forEach(n=>this.visitQueryParameter(n)),e.authorize!==null&&this.visitAuthorize(e.authorize)}visitQueryParameter(e){this.visitNode(e),this.visitTypeRef(e.type),e.source!=null&&this.visitExpression(e.source)}visitKey(e){this.visitNode(e),e.kind==="ExpressionKeySyntax"?this.visitExpression(e.expression):e.parts.forEach(n=>{this.visitNode(n),this.visitExpression(n.expression)})}visitProjection(e){this.visitNode(e),e.key!=null&&this.visitKey(e.key),e.blocks.forEach(n=>this.visitProjectionBlock(n))}visitProjectionBlock(e){switch(this.visitNode(e),e.kind){case"FromSyntax":e.events.forEach(n=>{this.visitNode(n),n.key!=null&&this.visitExpression(n.key)}),e.key!=null&&this.visitKey(e.key),e.parentKey!=null&&this.visitExpression(e.parentKey),e.mappings.forEach(n=>this.visitMapping(n));break;case"EverySyntax":case"AllSyntax":e.mappings.forEach(n=>this.visitMapping(n));break;case"JoinSyntax":e.events.forEach(n=>this.visitJoinEvent(n));break;case"ProjectionVariantSyntax":e.entersOn.forEach(n=>{this.visitNode(n),n.key!=null&&this.visitExpression(n.key)}),e.blocks.forEach(n=>this.visitProjectionBlock(n));break;case"ChildrenSyntax":e.identifiedBy!==void 0&&this.visitExpression(e.identifiedBy),e.blocks.forEach(n=>this.visitProjectionBlock(n));break;case"NestedSyntax":e.blocks.forEach(n=>this.visitProjectionBlock(n));break;case"RemoveWithSyntax":e.parentKey!=null&&this.visitExpression(e.parentKey),e.key!=null&&this.visitExpression(e.key);break;case"RemoveViaJoinSyntax":e.key!=null&&this.visitExpression(e.key);break}}visitJoinEvent(e){this.visitNode(e),e.mappings.forEach(n=>this.visitMapping(n))}visitMapping(e){this.visitNode(e),e.source!==void 0&&this.visitExpression(e.source),e.value!==void 0&&this.visitExpression(e.value)}visitCondition(e){this.visitNode(e),e.kind==="ComparisonConditionSyntax"?this.visitExpression(e.right):(this.visitCondition(e.left),this.visitCondition(e.right))}visitReaction(e){this.visitNode(e),e.where!=null&&this.visitCondition(e.where),e.triggers.forEach(n=>this.visitReactionTrigger(n))}visitReactionTrigger(e){this.visitNode(e),this.visitTriggerSource(e.source),e.produces.forEach(n=>this.visitProduces(n)),e.invokes.forEach(n=>this.visitInvokes(n))}visitProduces(e){this.visitNode(e),e.when!=null&&this.visitCondition(e.when),e.inlineEvent!==null&&this.visitEvent(e.inlineEvent),e.inlineOperation!=null&&this.visitOperation(e.inlineOperation),e.for!==null&&this.visitExpression(e.for),e.mappings.forEach(n=>this.visitPropertyMapping(n)),e.tags.forEach(n=>this.visitTag(n))}visitInvokes(e){this.visitNode(e),e.mappings?.forEach(n=>this.visitPropertyMapping(n)),e.onRefused?.forEach(n=>this.visitInvocationRefusal(n))}visitInvocationRefusal(e){this.visitNode(e),e.produces.forEach(n=>this.visitProduces(n))}visitCapture(e){this.visitNode(e),e.source!==null&&this.visitCaptureSource(e.source),e.map?.forEach(n=>this.visitCaptureMap(n)),e.appends.forEach(n=>this.visitCaptureAppend(n)),e.children.forEach(n=>this.visitCaptureChildren(n)),e.nested.forEach(n=>this.visitCaptureNested(n))}visitCaptureSource(e){this.visitNode(e),e.settings.forEach(n=>this.visitCaptureSourceSetting(n))}visitCaptureSourceSetting(e){this.visitNode(e)}visitCaptureMap(e){this.visitNode(e),this.visitExpression(e.source),e.kind==="CaptureMapEntrySyntax"&&e.translations.forEach(n=>this.visitNode(n))}visitCaptureAppend(e){this.visitNode(e),e.when!=null&&this.visitNode(e.when),e.mappings?.forEach(n=>this.visitPropertyMapping(n)),e.tags?.forEach(n=>this.visitTag(n))}visitCaptureChildren(e){this.visitNode(e),e.map?.forEach(n=>this.visitCaptureMap(n)),e.appends.forEach(n=>this.visitCaptureAppend(n))}visitCaptureNested(e){this.visitNode(e),e.map?.forEach(n=>this.visitCaptureMap(n)),e.appends.forEach(n=>this.visitCaptureAppend(n))}visitTriggerSource(e){this.visitNode(e)}visitScreen(e){this.visitNode(e),e.directives.forEach(n=>this.visitScreenDirective(n))}visitScreenDirective(e){if(e.kind==="ScreenGuardedActionSyntax"){this.visitScreenGuardedAction(e);return}switch(this.visitNode(e),e.kind){case"ScreenDataSyntax":this.visitTypeRef(e.type);break;case"ScreenActionSyntax":e.navigate!==null&&this.visitScreenDirective(e.navigate);break;case"ScreenTemplateReferenceSyntax":e.slots.forEach(n=>{this.visitNode(n),n.directives.forEach(i=>this.visitScreenDirective(i))});break;case"ScreenSectionSyntax":e.directives.forEach(n=>this.visitScreenDirective(n));break;case"ScreenTableSyntax":e.columns.forEach(n=>this.visitNode(n)),e.rowClick!==null&&this.visitScreenDirective(e.rowClick);break;case"ScreenSummarySyntax":e.fields.forEach(n=>this.visitNode(n));break;case"ScreenCodeSyntax":this.visitNode(e.code);break}}visitScreenGuardedAction(e){this.visitNode(e),e.alternatives.forEach(n=>this.visitScreenActionAlternative(n)),e.otherwise!==null&&this.visitScreenActionOtherwise(e.otherwise),e.navigate!==null&&this.visitScreenDirective(e.navigate)}visitScreenActionAlternative(e){this.visitNode(e),this.visitCondition(e.condition),e.arguments.forEach(n=>this.visitInteractionArgument(n))}visitScreenActionOtherwise(e){this.visitNode(e),e.arguments.forEach(n=>this.visitInteractionArgument(n))}visitInteractionArgument(e){this.visitNode(e)}visitSpecification(e){this.visitNode(e),e.examples?.forEach(n=>this.visitSpecificationExample(n)),e.givenClock!==null&&this.visitSpecificationClock(e.givenClock),e.givenOperationFailures?.forEach(n=>this.visitSpecificationOperationFailure(n)),e.thenOperations?.forEach(n=>this.visitSpecificationOperation(n)),e.thenCompensated?.forEach(n=>this.visitSpecificationCompensated(n)),e.givenCaller!=null&&(this.visitNode(e.givenCaller),e.givenCaller.claims.forEach(n=>this.visitNode(n))),e.given.forEach(n=>this.visitSpecificationEvent(n)),e.givenReadModels.forEach(n=>this.visitSpecificationReadModel(n)),e.when!==null&&this.visitSpecificationCommand(e.when),e.givenCaptures.forEach(n=>this.visitSpecificationCapture(n)),e.whenAppended!==null&&this.visitSpecificationEvent(e.whenAppended),e.whenRedelivered!=null&&this.visitSpecificationRedelivery(e.whenRedelivered),e.whenClock!==null&&this.visitSpecificationClock(e.whenClock),e.whenTrigger!==null&&this.visitSpecificationTrigger(e.whenTrigger),e.whenCapture!==null&&this.visitSpecificationCapture(e.whenCapture),e.whenQuery!==null&&this.visitSpecificationWhenQuery(e.whenQuery),e.thenEvents.forEach(n=>this.visitSpecificationEvent(n)),e.thenReadModels.forEach(n=>this.visitSpecificationReadModel(n)),e.thenAbsentReadModels?.forEach(n=>{this.visitNode(n),this.visitExpression(n.key)}),e.thenQueries?.forEach(n=>{this.visitNode(n),n.arguments.forEach(i=>this.visitPropertyMapping(i)),n.results.forEach(i=>this.visitSpecificationQueryResult(i))}),e.thenResults.forEach(n=>this.visitSpecificationQueryResult(n)),e.thenNoResult!==null&&this.visitNode(e.thenNoResult),e.thenDenied!=null&&this.visitNode(e.thenDenied),e.thenReturns!=null&&this.visitSpecificationReturn(e.thenReturns),e.thenErrors.forEach(n=>this.visitNode(n))}visitSpecificationRedelivery(e){this.visitNode(e),e.values.forEach(n=>this.visitPropertyMapping(n)),e.for!==null&&this.visitExpression(e.for)}visitSpecificationClock(e){this.visitNode(e)}visitSpecificationTrigger(e){this.visitNode(e),e.values.forEach(n=>this.visitPropertyMapping(n))}visitSpecificationCapture(e){this.visitNode(e),e.record.forEach(n=>this.visitPropertyMapping(n))}visitSpecificationWhenQuery(e){this.visitNode(e),e.arguments.forEach(n=>this.visitPropertyMapping(n))}visitSpecificationQueryResult(e){this.visitNode(e),e.properties.forEach(n=>this.visitPropertyMapping(n))}visitSpecificationExample(e){this.visitNode(e),e.for!==null&&this.visitExpression(e.for),e.values.forEach(n=>this.visitPropertyMapping(n)),e.generatedValues.forEach(n=>this.visitPropertyMapping(n))}visitSpecificationEvent(e){this.visitNode(e),e.stream!=null&&this.visitSpecificationStream(e.stream),e.noStream!=null&&this.visitSpecificationNoStream(e.noStream),e.values.forEach(n=>this.visitPropertyMapping(n)),e.for!==null&&this.visitExpression(e.for)}visitSpecificationStream(e){this.visitNode(e),e.streamId!==null&&this.visitPropertyMapping(e.streamId),e.streamIdParts.forEach(n=>this.visitPropertyMapping(n))}visitSpecificationNoStream(e){this.visitNode(e)}visitSpecificationCommand(e){this.visitNode(e),(e.generatedValues??[]).forEach(n=>this.visitPropertyMapping(n)),e.values.forEach(n=>this.visitPropertyMapping(n)),e.for!==null&&this.visitExpression(e.for)}visitSpecificationReadModel(e){this.visitNode(e),e.properties.forEach(n=>this.visitPropertyMapping(n))}visitPropertyMapping(e){this.visitNode(e),this.visitExpression(e.source)}visitProperty(e){this.visitNode(e),this.visitTypeRef(e.type)}visitTypeRef(e){this.visitNode(e)}visitExpression(e){this.visitNode(e),e.kind==="ListExpressionSyntax"?e.items.forEach(n=>this.visitExpression(n)):e.kind==="ObjectExpressionSyntax"?e.members.forEach(n=>this.visitObjectMember(n)):e.kind==="TemplateExpressionSyntax"&&e.parts.forEach(n=>{this.visitNode(n),n.kind==="TemplateInterpolationSyntax"&&this.visitExpression(n.expression)})}visitObjectMember(e){this.visitNode(e),this.visitExpression(e.value)}};var gp={from:"usesFactsFrom",join:"usesFactsFrom",remove:"usesFactsFrom",removeViaJoin:"usesFactsFrom",clear:"usesFactsFrom",entersOn:"usesFactsFrom",reduces:"usesFactsFrom",uniqueEvent:"usesFactsFrom",uniqueProperty:"usesFactsFrom",concurrency:"usesFactsFrom",trigger:"reactsTo",reads:"decidesFrom",invokes:"asks",action:"asks",actionAlternative:"asks",actionOtherwise:"asks",formCommand:"asks",dataQuery:"shows",populate:"shows",navigate:"shows",whenRedeliveredEvent:"verifiedWith",redeliveryReaction:"verifiedWith",refusalConstraint:null,refusalProduces:null,specificationEvent:"verifiedWith",givenEvent:"verifiedWith",whenAppendedEvent:"verifiedWith",thenEvent:"verifiedWith",whenCommand:"verifiedWith",declares:null,uses:null,commandEventSource:null,commandStream:null,specificationEventSource:null,specificationStream:null,thenOperation:null,givenOperationFailure:null,thenCompensated:null,produces:null,authorizes:null,queryResult:null,dataReadModel:null,type:null,exampleType:null,contributes:null,template:null,specificationReadModel:null,thenAbsentReadModel:null,thenReadModel:null,givenReadModel:null,thenQuery:null,compositeKeyType:null,builds:null,buildsVariant:null,appends:null,seed:null};function jn(t){let e=new Nn;return e.visitSlice(t),{references:e.references.sort((n,i)=>n.location.line-i.location.line||n.location.column-i.location.column),shared:e.shared}}l(jn,"sliceReferences");function Xo(t,e){let n=new Nn(e);return t.projections.forEach(i=>n.visitProjection(i)),we(t).reducers?.filter(i=>i.readModel.toLowerCase()===e.toLowerCase()).forEach(i=>n.visitReducer(i)),n.references}l(Xo,"buildingReadModelReferences");function nr(t){return t.flatMap(e=>e.kind==="ProjectionVariantSyntax"?[e,...nr(e.blocks)]:e.kind==="ChildrenSyntax"||e.kind==="NestedSyntax"?nr(e.blocks):[])}l(nr,"variants");var Nn=class extends tt{static{l(this,"SliceReferenceCollector")}readModel;references=[];shared=[];specification;projection=!1;constructor(e){super(),this.readModel=e}matches(e){return e.toLowerCase()===this.readModel?.toLowerCase()}visitSlice(e){super.visitSlice(e),we(e).reducers?.forEach(i=>this.visitReducer(i))}visitCommand(e){let n=we(e);n.reads?.forEach(i=>this.visitReads(i)),n.concurrency!=null&&this.visitConcurrency(n.concurrency),super.visitCommand(e)}visitReactionTrigger(e){let n=we(e);n.data?.forEach(i=>this.visitTriggerData(i)),n.reads?.forEach(i=>this.visitReads(i)),super.visitReactionTrigger(e)}visitProjection(e){if(this.readModel!==void 0){let n=nr(e.blocks);if(n.length===0?!this.matches(e.readModel??e.name):!n.some(i=>this.matches(i.name)))return}this.projection=!0,super.visitProjection(e),this.projection=!1}visitSpecification(e){this.specification=e,super.visitSpecification(e),this.specification=void 0}visitNode(e){let n=l((i,r,o)=>{this.references.push({name:i,targetKind:r,role:o,kind:gp[o],location:e.location,timeline:this.projection||["trigger","reads","reduces"].includes(o)})},"add");switch(e.kind){case"TypeRefSyntax":{let i=e.name;["Uuid","String","Int","Decimal","Bool","Date","DateTime"].includes(i)||this.shared.push({kind:"type",name:i});break}case"PolicyReferenceSyntax":this.shared.push({kind:"policy",name:e.name});break;case"EventSpecSyntax":n(e.event,"Event","from");break;case"JoinEventSyntax":n(e.event,"Event","join");break;case"RemoveWithSyntax":n(e.event,"Event","remove");break;case"RemoveViaJoinSyntax":n(e.event,"Event","removeViaJoin");break;case"ClearWithSyntax":n(e.event,"Event","clear");break;case"ProjectionEntersOnSyntax":n(e.event,"Event","entersOn");break;case"ReducerRuleSyntax":n(e.event,"Event","reduces");break;case"UniqueEventConstraintSyntax":n(e.event,"Event","uniqueEvent");break;case"UniquePropertyConstraintSyntax":n(e.event,"Event","uniqueProperty");break;case"NamedTriggerSourceSyntax":n(e.name,"Event","trigger");break;case"ReadsSyntax":n(e.readModel,"ReadModel","reads");break;case"InvokesSyntax":n(e.command,"Command","invokes");break;case"ScreenActionSyntax":n(e.command,"Command","action");break;case"ScreenActionAlternativeSyntax":n(e.command,"Command","actionAlternative");break;case"ScreenActionOtherwiseSyntax":{let i=e.command;i!==null&&n(i,"Command","actionOtherwise");break}case"FormSyntax":n(e.for,"Command","formCommand");break;case"ScreenDataSyntax":n(e.query,"Query","dataQuery");break;case"FormPopulateViaQuerySyntax":n(e.query,"Query","populate");break;case"ScreenNavigateSyntax":n(e.screen,"Screen","navigate");break;case"SpecificationEventSyntax":n(e.eventType,"Event",this.specification?.given.includes(e)===!0?"givenEvent":this.specification?.whenAppended===e?"whenAppendedEvent":"thenEvent");break;case"SpecificationCommandSyntax":n(e.commandType,"Command","whenCommand");break;case"SpecificationRedeliverySyntax":{let i=e;n(i.eventType,"Event","whenRedeliveredEvent"),n(i.reaction,"Reaction","redeliveryReaction");break}case"ConcurrencySyntax":e.eventTypes.forEach(i=>n(i,"Event","concurrency"));break}}};function _t(t){let e=new Map,n=new Map,i=[],r=new Set,o=[],s=l(a=>{e.set(a,e.size),n.set(a,e.get(a)),i.push(a),r.add(a);for(let m of[...t.get(a)].sort())e.has(m)?r.has(m)&&n.set(a,Math.min(n.get(a),e.get(m))):(s(m),n.set(a,Math.min(n.get(a),n.get(m))));if(n.get(a)!==e.get(a))return;let c=[],d;do d=i.pop(),r.delete(d),c.push(d);while(d!==a);o.push(c.sort())},"visit");for(let a of[...t.keys()].sort())e.has(a)||s(a);return o}l(_t,"stronglyConnectedGroups");var ea=["usesFactsFrom","reactsTo","decidesFrom"],Me=l((t,e)=>t<e?-1:t>e?1:0,"ordinal"),ir=l((t,e)=>JSON.stringify([t,e.toLowerCase()]),"declarationKey"),rr=l((t,e,n,i)=>({kind:t,address:e,scope:n,rank:i,key:`${t}:${e}`}),"nodeOf"),ar=l((t,e)=>t.rank-e.rank||Me(t.key,e.key),"compareNodes"),Jt=l(t=>[...new Map([...t].map(e=>[e.key,e])).values()].sort(ar),"distinctNodes"),ta=l((t,e)=>t.consumer.rank-e.consumer.rank||t.location.line-e.location.line||t.location.column-e.location.column||et.indexOf(t.kind)-et.indexOf(e.kind)||t.producer.rank-e.producer.rank||Me(t.location.path??"",e.location.path??"")||Me(t.role,e.role)||Me(t.name,e.name),"compareEvidence");function sr(t){return t.flatMap(e=>e.kind==="ProjectionVariantSyntax"?[e,...sr(e.blocks)]:e.kind==="ChildrenSyntax"||e.kind==="NestedSyntax"?sr(e.blocks):[])}l(sr,"variants");var kt=class t{static{l(this,"DependencyGraph")}orderSource;edges;unresolved;excludedReferences;unusedImports;modelNodes=[];slices=[];children=new Map;byKey=new Map;parents=new Map;root=rr("application","",[],-1);static for(e,n=Zt(e)){return new t(e,n)}get nodes(){return this.modelNodes}constructor(e,n){e=Ue(e),this.orderSource=n.size>0?"authored":"syntax",this.children.set(this.root.key,[]);let i=l((E,P)=>E.map((A,g)=>({syntax:A,index:g,rank:n.get(Oe([...P.scope,A.name]))??Number.MAX_SAFE_INTEGER})).sort((A,g)=>A.rank-g.rank||A.index-g.index).map(A=>A.syntax),"ordered"),r=l((E,P)=>{let A=this.add("feature",E.name,P);for(let g of i(E.slices,A))this.slices.push({node:this.add("slice",g.name,A),syntax:g});for(let g of i(E.features,A))r(g,A)},"feature");for(let E of i(e.modules,this.root)){let P=this.add("module",E.name,this.root);for(let A of i(E.features,P))r(A,P)}let o=new Map,s=new Map,a=l((E,P,A,g)=>{let S=ir(P,A);E.has(S)||E.set(S,[]);let k=E.get(S);k.includes(g)||k.push(g);let b=ir(P,[...g.scope,A].join("."));E.has(b)||E.set(b,[]);let I=E.get(b);I.includes(g)||I.push(g)},"declare");for(let{node:E,syntax:P}of this.slices){for(let A of se(P))a(o,"Event",A.name,E);for(let A of P.commands)a(o,"Command",A.name,E);for(let A of P.reactions)a(o,"Reaction",A.name,E);for(let A of P.queries)a(o,"Query",A.name,E);for(let A of P.screens)a(o,"Screen",A.name,E);for(let A of P.readModels)a(o,"ReadModel",A.name,E);for(let A of P.projections){let g=sr(A.blocks);g.length===0&&a(s,"ReadModel",A.readModel??A.name,E);for(let S of g)a(s,"ReadModel",S.name,E)}for(let A of we(P).reducers??[])a(s,"ReadModel",A.readModel,E)}let c=new Set((e.declaredTriggers??[]).map(E=>E.name.toLowerCase())),d=new Set([...e.concepts,...e.types].map(E=>E.name.toLowerCase())),m=new Set((e.policies??[]).map(E=>E.name.toLowerCase())),u=e.imports.filter(E=>E.qualifiedName.includes(".")).slice().sort((E,P)=>Me(E.location.path??"",P.location.path??"")||E.location.line-P.location.line||E.location.column-P.location.column||Me(E.qualifiedName,P.qualifiedName)),y=new Map,h=[],v=[],x=new Set,$=0;for(let{node:E,syntax:P}of this.slices){let A=jn(P);$+=A.shared.filter(g=>(g.kind==="type"?d:m).has(g.name.toLowerCase())).length;for(let g of A.references){let S=ir(g.targetKind,g.name),b=(g.targetKind==="ReadModel"&&s.has(S)?s:o).get(S);if(b!==void 0&&b.length>0){let w=b[0];w!==E&&h.push({consumer:E,producer:w,kind:g.kind,role:g.role,name:g.name,ambiguous:b.length>1,alternatives:b.slice(1),location:g.location,testOnly:g.kind==="verifiedWith"});continue}let I=g.targetKind==="Event"?u.filter(w=>w.qualifiedName.slice(w.qualifiedName.lastIndexOf(".")+1).toLowerCase()===g.name.toLowerCase()):[];if(I.length>0){let w=[];for(let D of I){x.add(D.qualifiedName);let N=D.qualifiedName.slice(0,D.qualifiedName.lastIndexOf(".")),L=`context:${N}`;if(!y.has(L)){let j=rr("context",L,[N],this.modelNodes.length);this.modelNodes.push(j),y.set(L,j)}let q=y.get(L);w.includes(q)||w.push(q)}h.push({consumer:E,producer:w[0],kind:"outsideTheModel",role:g.role,name:g.name,ambiguous:w.length>1,alternatives:w.slice(1),location:g.location,testOnly:g.kind==="verifiedWith"});continue}if(g.role==="trigger"&&c.has(g.name.toLowerCase())){$++;continue}v.push({consumer:E,kind:g.kind,role:g.role,name:g.name,location:g.location})}}let C=new Map;for(let E of h.sort(ta)){let P=JSON.stringify([E.consumer.key,E.producer.key,E.kind]);C.has(P)||C.set(P,[]),C.get(P).push(E)}this.edges=[...C.values()].map(E=>({consumer:E[0].consumer,producer:E[0].producer,kind:E[0].kind,evidence:E})),this.unresolved=v.sort((E,P)=>E.consumer.rank-P.consumer.rank||E.location.line-P.location.line||E.location.column-P.location.column||et.indexOf(E.kind)-et.indexOf(P.kind)||Me(E.location.path??"",P.location.path??"")||Me(E.name,P.name)),this.excludedReferences=$,this.unusedImports=[...new Set(u.filter(E=>!x.has(E.qualifiedName)).map(E=>E.qualifiedName))]}implied(e,n,i,r=!1,o=3){if(!["slice","feature","module"].includes(e))throw new ze(`Unsupported source level '${e}'.`);if(!["slice","feature","module","context"].includes(n))throw new ze(`Unsupported target level '${n}'.`);if(o<0)throw new ze("Evidence limit must not be negative.");let s=new Map;for(let a of this.evidence(i,r))for(let c of this.at(a.consumer,e))for(let d of this.at(a.producer,n).filter(m=>this.disjoint(c,m))){let m=JSON.stringify([c.key,d.key]);s.has(m)||s.set(m,{source:c,target:d,evidence:[]}),s.get(m).evidence.push(a)}return[...s.values()].sort((a,c)=>a.source.rank-c.source.rank||a.target.rank-c.target.rank||Me(a.source.key,c.source.key)||Me(a.target.key,c.target.key)).map(a=>{let c=a.evidence.sort(ta),d={};for(let m of et){let u=c.filter(y=>y.kind===m).length;u>0&&(d[m]=u)}return{source:a.source,target:a.target,sliceEdges:new Set(c.map(m=>JSON.stringify([m.consumer.key,m.producer.key]))).size,references:c.length,byKind:d,consumers:Jt(c.map(m=>m.consumer)),producers:Jt(c.map(m=>m.producer)),evidence:c.slice(0,o),evidenceCount:c.length,evidenceTruncated:c.length>o}})}cycles(e,n){if(!["slice","feature","module"].includes(e))throw new ze(`Unsupported cycle level '${e}'.`);let i=this.implied(e,e,na(n)),r=Jt(i.flatMap(o=>[o.source,o.target]));return ia(or(r,i),r,null)}siblingGroups(e){let n=this.siblingEdges(e);return this.containers().flatMap(i=>{let r=this.children.get(i.key);return ia(or(r,n.filter(o=>o.container===i)),r,i)})}suggestedOrder(e){let n=this.siblingEdges(e),i=[];for(let a of this.containers()){let c=this.children.get(a.key),d=n.filter($=>$.container===a),m=new Map(c.map($=>[$.key,$])),u=_t(or(c,d)).map($=>$.map(C=>m.get(C)).sort(ar)).sort(($,C)=>$[0].rank-C[0].rank),y=new Map(u.flatMap(($,C)=>$.map(E=>[E.key,C]))),h=new Map(c.map($=>[$.key,new Set]));for(let $ of d)y.get($.source.key)!==y.get($.target.key)&&h.get($.source.key).add($.target.key);for(let $ of u)for(let C=1;C<$.length;C++)h.get($[C].key).add($[C-1].key);let v=new Set(c.map($=>$.key)),x=[];for(;v.size>0;){let $=[...v].filter(C=>h.get(C).size===0).sort((C,E)=>ar(m.get(C),m.get(E)))[0];x.push(m.get($)),v.delete($);for(let C of v)h.get(C).delete($)}i.push({container:a,children:x,changed:c.some(($,C)=>$!==x[C])})}let r=new Map(i.map(a=>[a.container.key,a.children])),o=[],s=l(a=>{if(a.kind==="slice")o.push(a);else for(let c of[...r.get(a.key)].sort((d,m)=>+(d.kind!=="slice")-+(m.kind!=="slice")))s(c)},"walk");return s(this.root),{containers:i,slices:o}}traverse(e,n,i,r=!1){if(n!=="incoming"&&n!=="outgoing")throw new ze(`Unsupported dependency direction '${n}'.`);let o=this.evidence(i,r).map(d=>n==="incoming"?{source:d.producer,target:d.consumer}:{source:d.consumer,target:d.producer}),s=new Set([e]),a=[e],c=[];for(let d=0;d<a.length;d++)for(let m of o.filter(u=>u.source.address===a[d]).sort((u,y)=>u.target.rank-y.target.rank))s.has(m.target.address)||(s.add(m.target.address),c.push(m.target),a.push(m.target.address));return Jt(c)}add(e,n,i){let r=[...i.scope,n],o=r.join("."),s=`${e}:${o}`,a=this.byKey.get(s);if(a!==void 0)return a;let c=rr(e,o,r,this.modelNodes.length);return this.modelNodes.push(c),this.byKey.set(s,c),this.parents.set(s,i),this.children.get(i.key).push(c),e!=="slice"&&this.children.set(s,[]),c}ancestors(e){let n=[];for(let i=this.parents.get(e.key);i!==void 0;i=this.parents.get(i.key))n.push(i);return n}disjoint(e,n){return e.key!==n.key&&!this.ancestors(e).includes(n)&&!this.ancestors(n).includes(e)}at(e,n){return[e,...this.ancestors(e)].filter(i=>i.kind===n)}containers(){return[this.root,...this.modelNodes.filter(e=>e.kind==="module"||e.kind==="feature")]}evidence(e,n){let i=ra(e);return this.edges.flatMap(r=>r.evidence).filter(r=>i.has(r.kind)&&(n||!r.testOnly))}path(e){return[...this.ancestors(e).reverse(),e].filter(n=>n!==this.root)}siblingEdges(e){let n=[];for(let i of this.evidence(na(e),!1)){let r=this.path(i.consumer),o=this.path(i.producer),s=0;for(;s<r.length&&s<o.length&&r[s].key===o[s].key;)s++;s===r.length||s===o.length||n.push({container:s===0?this.root:r[s-1],source:r[s],target:o[s]})}return n}};function ra(t){let e=new Set(t??et);if([...e].some(n=>!et.includes(n)))throw new ze("Unsupported dependency kind.");return e}l(ra,"selectedKinds");function na(t){return[...ra(t??ea)].filter(e=>ea.includes(e))}l(na,"selectedOrderingKinds");function or(t,e){let n=new Map(t.map(i=>[i.key,new Set]));for(let i of e)n.get(i.source.key).add(i.target.key);return n}l(or,"adjacency");function ia(t,e,n){let i=new Map(e.map(r=>[r.key,r]));return _t(t).filter(r=>r.length>1).map(r=>({container:n,members:Jt(r.map(o=>i.get(o)))})).sort((r,o)=>r.members[0].rank-o.members[0].rank)}l(ia,"groupsOf");var xp=["usesFactsFrom","reactsTo","decidesFrom","asks","shows"],Ne=l((t,e)=>e===t||e.startsWith(t+"."),"contains"),bt=l((t,e)=>t<e?-1:t>e?1:0,"ordinal"),vp=l((t,e)=>bt(t.location.path??"",e.location.path??"")||t.location.line-e.location.line||t.location.column-e.location.column||bt(t.kind,e.kind)||bt(t.consumer.address,e.consumer.address)||bt(t.producer.address,e.producer.address)||bt(t.role,e.role)||bt(t.name,e.name),"orderedEvidence"),Et=class{static{l(this,"DeclaredDependencies")}static for(e){let n=new Map,i=l((u,y)=>{let h=u.join(".");n.has(h)||n.set(h,{location:y.location,dependencies:[]}),n.get(h).dependencies.push(...y.dependsOn??[]),y.features.forEach(v=>i([...u,v.name],v))},"inventory");if(e.modules.forEach(u=>i([u.name],u)),![...n.values()].some(u=>u.dependencies.length))return{containers:[],diagnostics:[]};let r=kt.for(e,new Map),o=r.nodes.filter(u=>u.kind==="module"||u.kind==="feature"),s=he.containersOf(e),a=l((u,y)=>{let h=he.resolve(u,y,s).resolved;return h&&[...h.scope,h.name].join(".")},"resolve"),c=[],d=[],m=l((u,y,h,v)=>d.push({code:u,severity:y,message:h,location:v}),"finding");for(let u of o.filter(y=>n.get(y.address).dependencies.length)){let y=n.get(u.address),h=y.dependencies.map($=>{let C=a($.target,u.scope),E=C!==void 0&&!Ne(u.address,C)&&!Ne(C,u.address);return{syntax:$,resolved:C,status:E?"unused":"invalid"}}),v=[],x=new Map;for(let $ of r.edges.flatMap(C=>C.evidence).filter(C=>xp.includes(C.kind)&&Ne(u.address,C.consumer.address)).sort(vp)){let C=[$.producer,...$.alternatives].filter(A=>!Ne(u.address,A.address)&&!Ne(A.scope.slice(0,-1).join("."),u.address));if(!C.length)continue;let E=h.filter(A=>A.status!=="invalid"&&C.some(g=>Ne(A.resolved,g.address)));for(let A of E)A.status=$.ambiguous&&A.status!=="used"?"provisional":"used";let P=$.ambiguous?"provisional":E.length?"declared":"undeclared";if(v.push({evidence:$,status:P,coveringDeclarations:E.map(A=>A.syntax)}),P==="undeclared"){let A=$.producer.scope[0];x.has(A)||x.set(A,[]),x.get(A).push($)}}for(let $ of x.values()){let C=$[0].producer.scope.slice(0,-1),E=C.findIndex((S,k)=>$.some(b=>k>=b.producer.scope.length-1||b.producer.scope[k]!==S));E>=0&&(C=C.slice(0,E));let P=C.join("."),A=Ne(u.address,P)||Ne(P,u.address)?[...new Set($.map(S=>S.producer.scope.slice(0,-1).map((k,b)=>S.producer.scope.slice(0,b+1).join(".")).find(k=>!Ne(u.address,k)&&!Ne(k,u.address))))]:[P],g=$.map(S=>`${S.kind} ${S.role} '${S.name}' at ${S.location.path??""}:${S.location.line}:${S.location.column}`).join("; ");m(p.UndeclaredDependency,"warning",`Container '${u.address}' depends on '${A.join("', '")}' without declaring ${A.length===1?"it":"them"} - evidence: ${g}`,y.location)}for(let $ of h)$.status==="unused"&&m(p.UnusedDependencyDeclaration,"information",`Dependency '${$.syntax.target}' on '${u.address}' is not used by any counted explicit reference`,$.syntax.location),$.status!=="invalid"&&n.get($.resolved).dependencies.some(C=>a(C.target,$.resolved.split("."))===u.address)&&m(p.MutualDependencyDeclarations,"information",`Containers '${u.address}' and '${$.resolved}' declare each other`,$.syntax.location);c.push({container:u,location:y.location,declarations:h,edges:v})}return{containers:c,diagnostics:d}}static validate(e,n){for(let i of this.for(e).diagnostics)n[i.severity==="warning"?"warning":"information"](i.code,i.message,i.location)}};var lr=class extends Error{static{l(this,"InvalidExactNumber")}};function Ht(t){if(t.literalType!=="ExactNumber"||typeof t.value!="string"||qe(t.value)?.value!==t.value)throw new lr("Expected a canonical, bounded ExactNumber value.");return t.value}l(Ht,"canonicalExactText");function oa(t){return!Ht(t).includes(".")}l(oa,"exactIsIntegral");var $p=/^([0-9]{4})-([0-9]{2})-([0-9]{2})$/,kp=/^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(?:\.[0-9]{1,7})?(?:Z|[+-]([0-9]{2}):([0-9]{2}))$/;function cr(t,e){let n=(e?kp:$p).exec(t);if(n===null||n[0].length!==t.length)return!1;let i=Number(n[1]),r=Number(n[2]),o=Number(n[3]),a=[31,i%4===0&&(i%100!==0||i%400===0)?29:28,31,30,31,30,31,31,30,31,30,31];if(i<1||r<1||r>12||o<1||o>a[r-1])return!1;if(!e)return!0;if(Number(n[4])>23||Number(n[5])>59||Number(n[6])>59)return!1;if(n[7]===void 0)return!0;let c=Number(n[7]),d=Number(n[8]);return c<=14&&d<=59&&(c!==14||d===0)}l(cr,"responseDateValue");var Ln=new Set(["Uuid","String","Int","Decimal","Bool","Date","DateTime"]);function qn(t,e,n=e.inputUses){let i=Mn(t),r=[],o=l((g,S)=>{let k=[...S,g.name];g.slices.forEach(b=>r.push({slice:b,scope:[...k,b.name]})),g.features.forEach(b=>o(b,k))},"collect");t.modules.forEach(g=>g.features.forEach(S=>o(S,[g.name])));let s=new Map,a=new Map,c=new Map;for(let{slice:g,scope:S}of r)for(let k of g.commands){let b=s.get(k.name)??[];b.push({command:k,scope:S}),s.set(k.name,b),a.set(k,ne(k.properties)),k.response?.kind==="RecordCommandResponseSyntax"&&c.set(k,ne(k.response.fields))}let d=new Map;for(let g of t.imports){let S=g.qualifiedName.split(".").at(-1);d.set(S,[...d.get(S)??[],g.qualifiedName])}let m=new Map,u=l((g,S)=>{let k=`${S.join(".")}|${g}`;if(m.has(k))return m.get(k);let b=d.get(g)??[],D=((s.get(g.split(".").at(-1))??[]).length===0&&b.length===1?b[0]:g).split("."),N=s.get(D.at(-1))??[];if(D.length>1){let q=D.slice(0,-1);N=N.filter(j=>q.length<=j.scope.length&&q.every((F,U)=>j.scope[j.scope.length-q.length+U]===F))}else for(let q=S.length;q>=0;q--){let j=N.filter(F=>q<=F.scope.length&&S.slice(0,q).every((U,Y)=>F.scope[Y]===U));if(j.length>0){N=j;break}}let L=N.length===1?N[0].command:null;return m.set(k,L),L},"resolve"),y=ne(t.concepts),h=new Set(t.concepts.map(g=>g.name)),v=new Map([...ne(t.types)].map(([g,S])=>[g,ne(S.properties)])),x=new Set(r.flatMap(g=>g.slice.readModels.map(S=>S.name))),$=new Set([...a.keys()].flatMap(g=>[...g.properties])),C=l(g=>{for(let S of g)S.isGenerated&&!$.has(S)&&e.error(p.GeneratedPropertyOutsideCommand,"Generated properties can only be declared on commands.",S.location)},"checkDeclarations"),E=l(g=>{g.features.forEach(E);for(let S of g.slices){for(let k of S.commands)for(let b of k.produces)b.inlineEvent!==null&&C(b.inlineEvent.properties);S.events.forEach(k=>C(k.properties)),S.readModels.forEach(k=>C(k.properties));for(let k of S.reactions)for(let b of k.triggers)for(let I of b.produces)I.inlineEvent!==null&&C(I.inlineEvent.properties)}},"checkFeature");t.types.forEach(g=>C(g.properties)),t.modules.forEach(g=>g.features.forEach(E));let P=l((g,S,k)=>{let b=a.get(k).get(g.property);if(b===void 0){e.error(p.InvalidResponseSource,`Response source '${g.property}' must reference one direct command property.`,g.location);return}let I=b.type;(I.isCollection||x.has(I.name))&&e.error(p.InvalidResponseShape,"Collection and whole-read-model responses are not supported.",g.location),S!==null&&(S.name!==I.name||S.isCollection!==I.isCollection||S.isOptional!==I.isOptional)&&e.error(p.InvalidResponseShape,"An explicit response field type must match its source's declared type, collection shape and optionality.",S.location)},"validateSource");for(let g of a.keys()){for(let k of g.properties){if(!k.isGenerated)continue;let b=y.get(k.type.name);(k.type.isOptional||k.type.isCollection||(b===void 0?Ln.has(k.type.name)||v.has(k.type.name)||h.has(k.type.name)||x.has(k.type.name):b.type!=="Uuid"))&&e.error(p.InvalidGeneratedType,"A generated property must be a required, noncollection concept backed by Uuid.",k.location)}let S=g.response;if(S?.kind==="ScalarCommandResponseSyntax")P(S.source,null,g);else if(S?.kind==="RecordCommandResponseSyntax"){S.fields.length===0&&e.error(p.InvalidCommandResponse,"A response block requires at least one field.",S.location);let k=new Set;for(let b of S.fields)k.has(b.name)&&e.error(p.DuplicateResponseField,`Duplicate response field '${b.name}'.`,b.location),k.add(b.name),P(b.source,b.type,g)}}let A=l((g,S)=>{let k=i(g.when,S),b=k===null?null:u(k.commandType,S);if(k!==null&&b!==null){let N=a.get(b);for(let j of k.values)N.get(j.property.split(".")[0])?.isGenerated&&e.error(p.GeneratedPropertySuppliedAsInput,`Generated property '${j.property}' cannot be supplied as request or form input.`,j.location);let L=[...N.values()].filter(j=>j.isIdentifier);if(k.for!==null&&L.length===1&&L[0].isGenerated){let j=L[0].type;(Ln.has(j.name)||y.has(j.name)||v.has(j.name))&&(j.isOptional||j.isCollection||y.get(j.name)?.type!=="Uuid"||k.for.kind!=="LiteralExpressionSyntax"||typeof k.for.value!="string"||!aa(k.for.value))&&e.error(p.InvalidGeneratedFixture,"A generated identifier fixture must supply one compatible concrete UUID value through 'for'.",k.for.location)}let q=new Set;for(let j of k.generatedValues??[]){let F=N.get(j.property);(q.has(j.property)||F===void 0||!F.isGenerated||F.isIdentifier||!Ie(j.source,F.type,y,v))&&e.error(p.InvalidGeneratedFixture,"A generated fixture must uniquely supply a compatible value for a nonidentifier generated command property.",j.location),q.add(j.property)}}let I=g.thenReturns;if(I==null||((k===null||g.thenErrors.length>0||g.thenDenied!=null)&&e.error(p.InvalidReturnExpectation,"A return expectation requires a command action and cannot accompany an error or denial.",I.location),b===null))return;let w=b.response,D=a.get(b);if(I.kind==="ScalarSpecificationReturnSyntax"&&w?.kind==="ScalarCommandResponseSyntax"&&D.has(w.source.property))Ie(I.value,D.get(w.source.property).type,y,v)||e.error(p.InvalidReturnExpectation,"The expected return value must match the response source's type.",I.location);else if(I.kind==="RecordSpecificationReturnSyntax"&&w?.kind==="RecordCommandResponseSyntax"){I.fields.length===0&&e.error(p.InvalidReturnExpectation,"A record return expectation requires at least one field.",I.location);let N=c.get(b),L=new Set;for(let q of I.fields){let j=N.get(q.property),F=j===void 0?void 0:D.get(j.source.property);(L.has(q.property)||F===void 0||!Ie(q.source,F.type,y,v))&&e.error(p.InvalidReturnExpectation,"A return assertion must uniquely name a response field and supply a compatible concrete value.",q.location),L.add(q.property)}}else e.error(p.InvalidReturnExpectation,"The return expectation must match the command's scalar or record response shape.",I.location)},"validateSpecification");for(let{slice:g,scope:S}of r)g.specifications.forEach(k=>A(k,S));for(let g of n){if(g.isParameter===!0)continue;let S=u(g.command,g.scope);S!==null&&a.get(S).get(g.property.split(".")[0])?.isGenerated&&e.error(p.GeneratedPropertySuppliedAsInput,`Generated property '${g.property}' cannot be supplied as request or form input.`,g.location)}}l(qn,"validateResponses");function ne(t){let e=new Map,n=new Set;for(let i of t)e.has(i.name)&&n.add(i.name),e.set(i.name,i);return n.forEach(i=>e.delete(i)),e}l(ne,"uniqueByName");function Ie(t,e,n,i){if(t.kind==="LiteralExpressionSyntax"&&t.value===null)return e.isOptional;if(e.isCollection)return t.kind==="ListExpressionSyntax"&&t.items.every(a=>Ie(a,{...e,isCollection:!1,isOptional:!1},n,i));let r=i.get(e.name);if(r!==void 0)return t.kind==="ObjectExpressionSyntax"&&t.members.every(a=>{let c=r.get(a.name);return c!==void 0&&Ie(a.value,c.type,n,i)});let o=n.get(e.name),s=o?.type??e.name;if(o?.type==="Enum")return t.kind==="LiteralExpressionSyntax"&&typeof t.value=="string"&&o.values.includes(t.value);if(t.kind==="LiteralExpressionSyntax")switch(s){case"Uuid":return typeof t.value=="string"&&aa(t.value);case"String":return typeof t.value=="string";case"Bool":return typeof t.value=="boolean";case"Int":return typeof t.value=="number"?Number.isFinite(t.value)&&Number.isInteger(t.value):typeof t.value=="object"&&t.value!==null&&oa(t.value);case"Decimal":return typeof t.value=="number"?Number.isFinite(t.value):typeof t.value=="object"&&t.value!==null&&t.value.literalType==="ExactNumber";case"Date":return typeof t.value=="string"&&cr(t.value,!1);case"DateTime":return typeof t.value=="string"&&cr(t.value,!0);default:return!Ln.has(s)}return!Ln.has(s)&&o===void 0}l(Ie,"compatibleValue");var bp=/^(?:[0-9a-f]{32}|[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}|\{[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}\}|\([0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}\))(?![\s\S])/i;function aa(t){return bp.test(t)}l(aa,"uuidValue");var ct=class t{static{l(this,"LineReader")}lines;#e=0;constructor(e){this.lines=e}get atEnd(){return this.lines.slice(this.#e).every(Ei)}fork(){let e=new t(this.lines);return e.#e=this.#e,e}peekSignificant(){for(;this.#e<this.lines.length&&Ei(this.lines[this.#e]);)this.#e++;return this.#e<this.lines.length?this.lines[this.#e]:void 0}takeSignificant(){let e=this.peekSignificant();if(e===void 0)throw new Error("There is no significant line left to take");return this.#e++,e}takeRaw(){return this.#e<this.lines.length?this.lines[this.#e++]:void 0}};function Bn(t,e,n,i=!1){let r=[],o=[],s=ke,a=!1,c=!1,d=!1,m=new Map,u=new Se(new ct([]),e,n).languages;for(let h of t){let v=h;if(v.number===1&&v.raw.startsWith("\uFEFF")){let x=v.raw.substring(1),$=x.length-x.trimStart().length,C=Rt(x.substring($),i);v={...v,indent:$,contentOffset:1,content:(C<0?x.substring($):x.substring($,$+C)).trimEnd()}}if(d){ji(v)&&(d=!1),r.push(v);continue}if(v.content.startsWith("```")&&(["```","```text","```markdown"].includes(v.content)||u.has(v.content.substring(3)))&&(d=!0),!d&&v.indent===0&&R(v.content)==="numbers"){let x=v.content!=="numbers exact"?p.InvalidNumericDirective:a?p.DuplicateNumericDirective:c?p.LateNumericDirective:void 0;x!==void 0?(o.push({severity:"error",code:x,message:"Expected one 'numbers exact' preamble before domain, imports and declarations.",location:f(v)}),s=Object.freeze({numericMode:"invalid"})):s=Pn,a=!0,r.push({...v,content:""});continue}!d&&v.indent>0&&/^numbers(\s+(exact|legacy))?$/.test(v.content)&&m.set(v.number,{severity:"error",code:p.InvalidNumericDirective,message:"Expected 'numbers exact' only as the document preamble, not inside a body.",location:f(v)}),c||=v.content.trim().length>0,r.push(v)}let y=new Se(new ct(a?r:t),e,n);return y.sourceOptions=s,y.nestedNumericDirectives=m,o.forEach(h=>y.error(h.code,h.message,h.location)),y}l(Bn,"sourceContext");function sa(t,e){return t.produces.filter(n=>n.inlineOperation==null&&(e===void 0||e.resolver.isEventProduction(n,e.slice)))}l(sa,"eventProductions");function dr(t,e){let n=sa(t,e),i=t.properties.find(r=>r.isIdentifier)?.name;return n.some(r=>r.for!==null&&(r.for.kind!=="PathExpressionSyntax"||r.for.path!==i))||n.some(r=>r.inlineEvent!==null&&r.for===null)&&n.some(r=>r.inlineEvent===null&&r.for===null)}l(dr,"requiresExplicitDestinations");function la(t,e,n){let i=sa(t,n);if(e.inlineOperation!=null||n!==void 0&&!n.resolver.isEventProduction(e,n.slice)||e.for!==null||dr(t,n))return;if(e.inlineEvent===null)return i.some(o=>o.for!==null||o.inlineEvent!==null)?void 0:"new event source";let r=t.properties.filter(o=>o.isIdentifier&&!o.type.isOptional&&!o.type.isCollection);return r.length===1?r[0].name:void 0}l(la,"implicitDestination");function Fn(t,e){let n=[],i=l(a=>{n.push(...a.slices),a.features.forEach(i)},"inFeature");t.modules.forEach(a=>a.features.forEach(i));let r=new Map;for(let a of n.flatMap(se))r.set(a.name,(r.get(a.name)??0)+1);let o=new Set(t.imports.map(a=>a.qualifiedName.split(".").at(-1))),s=new re(t);for(let{slice:a,command:c}of n.flatMap(d=>d.commands.map(m=>({slice:d,command:m})))){let d=c.produces.filter(y=>s.isEventProduction(y,a)),m=c.properties.find(y=>y.isIdentifier)?.name,u=dr(c,{resolver:s,slice:a});for(let y of d){let h=y.inlineEvent;h!==null&&((r.get(h.name)??0)>1||o.has(h.name))&&e.error(p.InlineEventCollision,`Inline event '${h.name}' collides with another event declaration or import`,y.location),u&&y.for===null&&e.error(p.ExplicitProducesTargetsRequired,`Production '${y.event}' in command '${c.name}' must state 'for' explicitly - every production must state 'for' when destinations differ`,y.location);let v=y.for?.kind==="PathExpressionSyntax"?y.for.path:y.for===null&&h!==null?m:void 0;if(!(m===void 0||v!==m))for(let x of y.mappings.filter($=>$.source.kind==="PathExpressionSyntax"&&$.source.path===m)){let $=`Event '${y.event}' copies command identifier '${m}' into payload property '${x.property}' although it already identifies the event source`;h===null?e.information(p.EventSourceIdInPayload,$,x.location):e.warning(p.EventSourceIdInPayload,$,x.location)}}}}l(Fn,"validateInlineEvents");function Yn(t,e){let n=new re(t),i=Mn(t),r=ne(t.concepts),o=new Map([...ne(t.types)].map(([E,P])=>[E,ne(P.properties)])),s=new Set(["Uuid","String","Int","Decimal","Bool","Date","DateTime",...r.keys(),...o.keys()]),a=new Set(t.imports.map(E=>E.qualifiedName.split(".").at(-1))),c=new Map;for(let E of t.imports){let P=E.qualifiedName.split(".").at(-1);c.set(P,[...c.get(P)??[],E.qualifiedName])}let d=l(E=>{let P=new Map,A=new Map;for(let g of E){let S=P.get(g.name)??[];S.push(g),P.set(g.name,S)}return(g,S)=>{let k=JSON.stringify([g,S]);if(A.has(k))return A.get(k);let b=l(N=>{let L=N.split("."),q=P.get(L.at(-1))??[],j=L.slice(0,-1);if(j.length>0)return q.filter(F=>j.length<=F.scope.length&&j.every((U,Y)=>F.scope[F.scope.length-j.length+Y]===U));for(let F=S.length;F>=0;F--){let U=q.filter(Y=>F<=Y.scope.length&&S.slice(0,F).every((Q,oe)=>Y.scope[oe]===Q));if(U.length>0)return U}return[]},"candidates"),I=b(g),w=c.get(g)??[];I.length===0&&w.length===1&&(I=b(w[0]));let D=I.length===1?I[0].node:null;return A.set(k,D),D}},"scoped"),m=d(n.slices.flatMap(({slice:E,scope:P})=>E.readModels.map(A=>({name:A.name,scope:P,node:A})))),u=d(n.slices.flatMap(({slice:E,scope:P})=>E.commands.map(A=>({name:A.name,scope:P,node:{command:A,slice:E}})))),y=new Map;for(let E of t.systems??[])y.has(E.name)&&e.error(p.InvalidSystemDeclaration,`System '${E.name}' is declared more than once.`,E.location),y.set(E.name,(y.get(E.name)??0)+1);let h=l((E,P,A=!0)=>{let[g,...S]=P.split("."),k=E.filter(D=>D.name===g);if(k.length!==1)return{type:null,missing:k.length===0};let b=k[0].type;if(S.length===0)return{type:b,missing:!1};let I=o.get(b.name);if(I===void 0)return{type:null,missing:s.has(b.name)};let w=h([...I.values()],S.join("."),A);return w.type===null?w:{type:{...w.type,isOptional:A&&b.isOptional||w.type.isOptional,isCollection:b.isCollection||w.type.isCollection},missing:!1}},"pathType"),v=l((E,P,A,g,S=new Set)=>{if(A.has(P)||E.isOptional&&!g.has(P))return!0;if(E.isCollection||S.has(E.name))return!1;let k=o.get(E.name);return k===void 0?g.has(P)&&!s.has(E.name):[...k.values()].every(b=>v(b.type,`${P}.${b.name}`,A,g,new Set([...S,E.name])))},"covered"),x=l((E,P)=>{if(E.kind==="ListExpressionSyntax"&&P.isCollection)return E.items.every(g=>x(g,{...P,isCollection:!1,isOptional:!1}));let A=o.get(P.name);return E.kind!=="ObjectExpressionSyntax"||A===void 0?!0:[...A.values()].every(g=>(g.type.isOptional||E.members.some(S=>S.name===g.name))&&E.members.filter(S=>S.name===g.name).every(S=>x(S.value,g.type)))},"completeValue"),$=l(E=>E.kind==="LiteralExpressionSyntax"?typeof E.value!="number"||Number.isFinite(E.value):E.kind==="ObjectExpressionSyntax"?E.members.every(P=>$(P.value)):E.kind==="ListExpressionSyntax"&&E.items.every($),"concrete"),C=l((E,P,A,g,S)=>{let k=new Set,b=new Set(E.map(w=>w.property)),I=new Set;for(let w of E){let D=w.property.split(".");for(let N=1;N<=D.length;N++)I.add(D.slice(0,N).join("."))}for(let w of E){k.has(w.property)&&e.error(p.InvalidOperationMapping,`Duplicate operation input mapping '${w.property}'.`,w.location),k.add(w.property);let D=h(P.inputs,w.property,!1);if(D.missing&&e.error(p.InvalidOperationMapping,`Operation '${P.name}' declares no input '${w.property}'.`,w.location),D.type===null)continue;let N=w.property.split(".");for(let L=1;L<N.length;L++)b.has(N.slice(0,L).join("."))&&e.error(p.InvalidOperationMapping,`Operation input mapping '${w.property}' overlaps a whole input mapping.`,w.location);if(A!==null&&w.source.kind==="PathExpressionSyntax"){let L=h(A.properties,w.source.path),q=w.source.path.split("."),j=(An.get(A)??[]).filter(Y=>(Y.alias??Y.readModel)===q[0]);if(L.missing&&j.length>0){L={type:null,missing:!1};let Y=j.length===1?m(j[0].readModel,S):null;q.length>1&&Y!==null&&(L=h(Y.properties,q.slice(1).join(".")))}L.missing&&e.error(p.InvalidOperationMapping,`Command '${A.name}' declares no source '${w.source.path}'.`,w.source.location);let F=L.type,U=D.type;F!==null&&s.has(F.name)&&s.has(U.name)&&(F.name!==U.name||F.isCollection!==U.isCollection||F.isOptional&&!U.isOptional)&&e.error(p.InvalidOperationMapping,`Source '${w.source.path}' is incompatible with input '${w.property}' of operation '${P.name}'.`,w.source.location)}else["LiteralExpressionSyntax","ObjectExpressionSyntax","ListExpressionSyntax"].includes(w.source.kind)&&(!Ie(w.source,D.type,r,o)||g&&!x(w.source,D.type))&&e.error(p.InvalidOperationMapping,`Value is incompatible with input '${w.property}' of operation '${P.name}'.`,w.source.location)}if(g)for(let w of P.inputs)v(w.type,w.name,k,I)||e.error(p.InvalidOperationMapping,`Production of operation '${P.name}' supplies no value for required input '${w.name}'.`,P.location)},"validateMappings");for(let{slice:E,scope:P}of n.slices){let A=ln(E),g=new Set(se(E).map(S=>S.name));for(let S of A){g.has(S.name)&&e.error(p.ProductionDeclarationCollision,`Operation '${S.name}' collides with another event or operation in slice '${E.name}'.`,S.location),g.add(S.name),S.uses.length>0&&y.get(S.uses)!==1&&e.error(p.InvalidSystemReference,`Operation '${S.name}' must use one declared system; '${S.uses}' does not resolve uniquely.`,S.usesLocation??S.location);for(let k of S.inputs)!s.has(k.type.name)&&!a.has(k.type.name)&&e.warning(p.UnknownType,`Unknown type '${k.type.name}' on input '${k.name}' of operation '${S.name}'.`,k.type.location)}for(let S of E.commands)for(let k of S.produces){let b=n.resolve(k.event,E);b.kind===ee.Ambiguous&&b.candidates.some(I=>I.kind===ee.Operation)&&e.error(p.InvalidProductionReference,`Production '${k.event}' is ambiguous.`,k.location),k.event.includes(".")&&b.kind!==ee.Operation&&e.error(p.InvalidProductionReference,"Qualified productions are supported only for explicitly declared operations.",k.location),b.declaration?.node.kind==="OperationSyntax"&&((k.for!==null||k.tags.length>0)&&e.error(p.InvalidOperationDeclaration,"Operation productions cannot declare event destinations or tags.",k.location),C(k.mappings,b.declaration.node,S,!0,P))}for(let S of E.reactions.flatMap(k=>k.triggers).flatMap(k=>k.produces)){let k=n.resolve(S.event,E);k.kind===ee.Ambiguous&&k.candidates.some(b=>b.kind===ee.Operation)&&e.error(p.InvalidProductionReference,`Production '${S.event}' is ambiguous.`,S.location),S.event.includes(".")&&n.resolve(S.event,E).kind!==ee.Operation&&e.error(p.InvalidProductionReference,"Qualified productions are supported only for explicitly declared operations.",S.location),n.isOperation(S,E)&&e.error(p.OperationOutsideCommand,"Operations can only be produced by commands.",S.location)}for(let S of E.specifications){let k=[...S.givenOperationFailures??[],...S.thenOperations??[],...S.thenCompensated??[]];if(k.length===0)continue;let b=u(i(S.when,P)?.commandType??"",P);(b===null||S.whenAppended!==null||S.whenQuery!==null||S.whenTrigger!==null||S.whenClock!==null||S.whenCapture!==null)&&e.error(p.InvalidOperationSpecification,"Operation fixtures and assertions require a declared command action.",S.location);let I=new Map;for(let w of k){if(w.kind==="SpecificationOperationSyntax")for(let L of w.values)$(L.source)||e.error(p.InvalidOperationSpecification,"Operation assertions require concrete input values.",L.source.location);let D=n.resolve(w.operation,E).declaration?.node;if(D?.kind!=="OperationSyntax"){e.error(p.InvalidOperationSpecification,`'${w.operation}' does not resolve uniquely to a declared operation.`,w.location);continue}let N=I.get(D)??new Set;if(N.has(w.kind)&&e.error(p.InvalidOperationSpecification,`Duplicate operation step '${w.operation}'.`,w.location),N.add(w.kind),I.set(D,N),w.kind==="SpecificationCompensatedSyntax"&&D.compensate===null&&e.error(p.InvalidOperationSpecification,`Operation '${w.operation}' declares no compensation.`,w.location),b!==null&&b.command.handler==null){let L=b.command.produces.map(q=>n.resolve(q.event,b.slice));L.every(q=>q.kind===ee.Event||q.kind===ee.Operation)&&!L.some(q=>q.declaration?.node===D)&&e.error(p.InvalidOperationSpecification,`Command '${b.command.name}' does not produce operation '${w.operation}'.`,w.location)}w.kind==="SpecificationOperationSyntax"&&C(w.values,D,null,!1,P)}}}}l(Yn,"validateOperations");var Ep=V("^policy\\s+([A-Za-z_]\\w*)$");function ca(t,e){let n=t;t=t.valueContext;let i=Ep.exec(e.content)?.[1]??"";i===""&&t.error(p.InvalidPolicyDeclaration,`Invalid policy declaration '${e.content}' - expected 'policy <Name>'`,f(e));let r=null,o=null,s=null,a=!1;for(let c=t.peekChild(e.indent);c!==void 0;c=t.peekChild(e.indent))if(t.reader.takeSignificant(),R(c.content)==="require"){let d=c.content.substring(7).trim();for(let y=t.peekChild(c.indent);y!==void 0;y=t.peekChild(c.indent))t.reader.takeSignificant(),d+=` ${y.content}`;let m=Cp(t,d);m.includes("not")&&(t=n);let u=Pp(t,m,f(c));a?t.error(p.RepeatedPolicyRequirement,`Policy '${i}' has more than one require line; combine the conditions with and/or in one require`,f(c)):r=u,a=!0}else if(R(c.content)==="file"){let d=Xe(t,c);o===null&&s===null?s=d:t.error(p.UnknownPolicyDirective,`Policy '${i}' must have only one implementation - a file reference or an inline code block, not both`,f(c))}else if(c.content.startsWith("```")||t.languages.has(c.content)){let d=$e(t,c);o===null&&s===null?o=d:t.error(p.UnknownPolicyDirective,`Policy '${i}' must have only one implementation - a file reference or an inline code block, not both`,f(c))}else t.error(p.UnknownPolicyDirective,`Unexpected '${c.content}' in policy body - expected 'require ...', 'file <path>' or an inline code block`,f(c)),t.skipOpaqueBlock(c.indent);return r!==null&&(o!==null||s!==null)&&t.error(p.MixedPolicyImplementation,`Policy '${i}' cannot combine 'require' with a file or inline code block`,f(e)),r===null&&o===null&&s===null&&t.error(p.PolicyWithoutRequirement,`Policy '${i}' must declare a 'require' condition, a file reference or an inline code block`,f(e)),{kind:"PolicySyntax",name:i,condition:r,code:o,file:s,location:f(e)}}l(ca,"parsePolicy");function Cp(t,e){let n=t.sourceOptions.numericMode==="exact"?"-?[0-9]+(?:\\.[0-9]+)?(?:[eE][+-]?[0-9]+)?(?=$|[\\s()])|[\\w.$-]+|[^\\s]":"[\\w.$]+";return[...e.match(new RegExp(V(`"${_}"|\\(|\\)|${n}`).source,"gu"))??[]]}l(Cp,"tokenizePolicyCondition");function Pp(t,e,n){let i=t.sourceOptions.numericMode==="exact"||e.includes("not"),r=0,o=l(u=>u!==void 0&&u.startsWith('"')&&u.endsWith('"'),"quoted"),s=l(u=>H(u.substring(1,u.length-1)),"unquote"),a=l(()=>{if(e[r]==="not"){r++;let v=a();return v===null?null:{kind:"NotPolicyConditionSyntax",operand:v,location:n}}if(e[r]==="("){r++;let v=d();return e[r]===")"?r++:i&&t.error(p.UnclosedPolicyConditionGroup,"Expected ')' in policy condition",n),v}let u=e[r++];if(u==="authenticated")return{kind:"AuthenticatedConditionSyntax",location:n};if(u!=="role"&&u!=="claim")return t.error(u===void 0?p.ExpectedPolicyCondition:p.UnexpectedTokenInPolicyCondition,u===void 0?"Expected a policy condition":`Unexpected '${u}' in policy condition`,n),null;let y=e[r++];if(!o(y))return t.error(u==="role"?p.ExpectedRoleName:p.ExpectedClaimName,`Expected a quoted ${u} name after '${u}'`,n),null;if(u==="role")return{kind:"RoleConditionSyntax",role:s(y),location:n};if(e[r++]!=="matches")return t.error(p.ExpectedClaimMatches,"Expected 'matches' after the claim name",n),null;let h=e[r++];return h===void 0?(t.error(p.ExpectedClaimMatchTarget,"Expected 'subject' or a value after 'matches'",n),null):{kind:"ClaimConditionSyntax",claim:s(y),matchesSubject:h==="subject",matches:h==="subject"?null:xe(h,n,t),location:n}},"group"),c=l(()=>{let u=a();for(;u!==null&&e[r]==="and";){r++;let y=a();if(y===null)return null;u={kind:"LogicalPolicyConditionSyntax",left:u,operator:"And",right:y,location:n}}return u},"and"),d=l(()=>{let u=c();for(;u!==null&&e[r]==="or";){r++;let y=c();if(y===null)return null;u={kind:"LogicalPolicyConditionSyntax",left:u,operator:"Or",right:y,location:n}}return u},"or"),m=d();return i&&m!==null&&r<e.length&&t.error(p.UnexpectedTokenInPolicyCondition,`Unexpected '${e[r]}' in policy condition`,n),m}l(Pp,"parsePolicyCondition");var Ap=new RegExp(`^for\\s+"(${_})"$`,"u"),wp=V("^[A-Z]\\w*$"),Op=V("^([\\w.]+)\\s*=(?!=|>)\\s*(.+)$");function da(t,e){let n=[];if(t=t.valueContext,e.content!=="seed")return t.error(p.InvalidSeedDeclaration,`Invalid seed declaration '${e.content}' - expected 'seed'`,f(e)),t.skipOpaqueBlock(e.indent),{kind:"SeedSyntax",groups:n,location:f(e)};for(let i=t.peekChild(e.indent);i!==void 0;i=t.peekChild(e.indent)){t.reader.takeSignificant();let r=Ap.exec(i.content);if(r===null){t.error(p.InvalidSeedGroup,`Invalid seed group '${i.content}' - expected 'for "<event source id>"'`,f(i)),t.skipOpaqueBlock(i.indent);continue}let o=[];for(let s=t.peekChild(i.indent);s!==void 0;s=t.peekChild(i.indent)){if(t.reader.takeSignificant(),!wp.test(s.content)){t.error(p.InvalidSeedEvent,`Invalid seed event '${s.content}' - expected an event type name`,f(s)),t.skipOpaqueBlock(s.indent);continue}let a=[];for(let c=t.peekChild(s.indent);c!==void 0;c=t.peekChild(s.indent)){t.reader.takeSignificant();let d=Op.exec(c.content);d!==null?a.push({kind:"PropertyMappingSyntax",property:d[1],source:xe(d[2],f(c),t),location:f(c)}):t.error(p.InvalidSeedPropertyAssignment,`Invalid property assignment '${c.content}' - expected '<property> = <value>'`,f(c))}o.push({kind:"SeedEventSyntax",event:s.content,properties:a,location:f(s)})}n.push({kind:"SeedGroupSyntax",eventSourceId:H(r[1]),events:o,location:f(i)})}return{kind:"SeedSyntax",groups:n,location:f(e)}}l(da,"parseSeed");var Ip=O("^domain\\s+([A-Za-z_]\\w*(?:\\.[A-Za-z_]\\w*)*)$"),ua=O("^import\\s+([\\w.]+)$"),Tp=O("^concept\\s+(\\w+)\\s*:\\s*(\\w+)((?:\\s+@\\w+)*)$"),Rp=O("^@?[a-z_]\\w*$"),Dp=O(`^([a-z_]\\w*)\\s+reason\\s+"(${_})"$`),Mp=O("^persona\\s+([A-Za-z_]\\w*)$"),Np=O("^policy\\s+([A-Za-z_]\\w*)$"),jp=/^[ ]*\t/,pa=["Uuid","String","Int","Decimal","Bool","Date","DateTime"],ma=new Set(["policy","authentication","seed","ui","theme","trigger","layout","behavior"]),Lp=new Set(["slice","feature","description","documentation","authorize","screen","dialog","form","contribute","on","uses"]);function Wn(t,e,n=lt){Wp(t,e);let i=n.length===1?new Kt(n[0]):void 0,r=n.length>1?new Gt(n[n.length-1]):void 0,o=i??r,s=null,a=[],c=[],d=[],m=[],u=[],y=[],h=[],v=[],x=[],$=[],C=[],E=[],P=!1;for(let g=t.reader.peekSignificant();g!==void 0;g=t.reader.peekSignificant()){t.reader.takeSignificant();let S=R(g.content);if(S==="domain"){t.authoredDeclarations=!0,s=Yp(t,g,s,P);continue}if(P||=fa(S,g,n),t.authoredDeclarations||=S!=="import"&&fa(S,g,n),S==="import"&&Wr(g.content))o!==void 0?o.tryParse(t,g):ht(t,g,c);else if(S==="import"){let k=ua.exec(g.content);k===null?t.error(p.InvalidImportDeclaration,`Invalid import '${g.content}' - expected 'import <Qualified.Name>'`,f(g)):a.push({kind:"ImportSyntax",qualifiedName:k[1],location:f(g)})}else if(S==="example")o!==void 0?o.tryParse(t,g):C.push(Be(t,g));else if(S==="eventsource")y.push(so(t,g));else if(S==="system")u.push($o(t,g));else if(S==="concept")d.push(Up(t,g));else if(S==="type")m.push(to(t,g));else if(S==="module"&&!Dt(n))qp(t,g,n,i);else if(S==="module")h.push(Xi(t,g));else if(S==="persona")v.push(Vp(t,g));else if(S==="seed")$.push(da(t.valueContext,g));else if(S==="policy")x.push(ca(t,g));else if(S==="trigger"){let k=Mo(t,g),b=/^trigger\s+([A-Za-z_]\w*)$/.exec(g.content)?.[1];b!==void 0&&E.push({name:b,data:k})}else ma.has(S)?S==="behavior"||S==="layout"?Pe(t,g):t.skipOpaqueBlock(g.indent):o?.tryParse(t,g)!==!0&&Bp(t,g,n)}i!==void 0?h.unshift(i.build(t.start,!0)):r!==void 0&&h.unshift(Fp(n,r.build(t.start,!0),t.start));let A={kind:"ApplicationSyntax",sourceOptions:t.sourceOptions,domain:s,imports:a,concepts:d,types:m,systems:u,eventSources:y,examples:C,modules:h,personas:v,policies:x,seeds:$,declaredTriggers:E,fileImports:c,location:t.start};return t.authoredDeclarations&&ho(A),A}l(Wn,"parseApplication");function fa(t,e,n){return t==="import"?ua.test(e.content):t==="module"?Dt(n):t==="example"||t==="eventsource"||t==="system"||t==="concept"||t==="type"||t==="persona"||ma.has(t)}l(fa,"declaresConstruct");function qp(t,e,n,i){let r=Ji.exec(e.content)?.[1]??"";if(i!==void 0&&r===n[0]){t.authoredDeclarations=!0,i.parseChildren(t,e);return}t.error(p.ModuleInPlacedFile,`This file is imported into ${un(n)}, so it cannot declare module '${r}' - import it at the top level of a document instead`,f(e)),t.skipBlock(e.indent)}l(qp,"parseModuleInPlacedFile");function Bp(t,e,n){let i=R(e.content);if(Dt(n)){let r=Lp.has(i)?` - '${i}' belongs in a module or feature; wrap it in one, or import this file from inside one`:" - expected domain, import, concept, type, policy, persona, authentication, module, seed, trigger, behavior, ui profile, theme or layout";t.error(p.UnknownTopLevelConstruct,`Unexpected '${i}' at the top level${r}`,f(e))}else{let r=n.length===1?Hi:_i;t.error(p.UnexpectedInPlacedFile,`Unexpected '${i}' in a file imported into ${un(n)} - expected an application declaration or ${r}`,f(e))}t.skipBlock(e.indent)}l(Bp,"reportUnexpectedTopLevel");function Fp(t,e,n){let i=e;for(let r=t.length-2;r>=1;r--)i={kind:"FeatureSyntax",name:t[r],description:null,authorize:null,features:[i],slices:[],fileImports:[],isPlacement:!0,location:n};return{kind:"ModuleSyntax",name:t[0],description:null,authorize:null,features:[i],fileImports:[],isPlacement:!0,location:n}}l(Fp,"place");function Yp(t,e,n,i){let r=Ip.exec(e.content);return r===null?(t.error(p.InvalidDomainDeclaration,`Invalid domain declaration '${e.content}' - expected 'domain <Qualified.Name>'`,f(e)),n):n!==null?(t.error(p.DuplicateDomain,"The document already declares a domain - a document can have at most one",f(e)),n):(i&&t.error(p.DomainNotFirst,"'domain' must be declared before any other construct",f(e)),{kind:"DomainSyntax",name:r[1],location:f(e)})}l(Yp,"parseDomain");function Wp(t,e){let n=!1;for(let i of e){if(i.raw.trimStart().startsWith("```")){n=!n;continue}!n&&jp.test(i.raw)&&t.warning(p.TabIndentation,"Screenplay is indentation based - use spaces, not tabs",Br(i))}}l(Wp,"warnOnTabIndentation");function Up(t,e){let n=Tp.exec(e.content);if(n===null)return t.error(p.InvalidConceptDeclaration,`Invalid concept declaration '${e.content}' - expected 'concept <Name> : <Type>'`,f(e)),t.skipBlock(e.indent),{kind:"ConceptSyntax",name:R(e.content),type:"",attributes:[],values:[],location:f(e)};let[,i,r,o]=n,s=o.split(" ").filter(m=>m.length>0).map(m=>({kind:"ConceptAttributeSyntax",name:m.replace(/^@+/,""),reason:null,location:f(e)}));r!=="Enum"&&!pa.includes(r)&&t.error(p.UnknownPrimitiveType,`Unknown primitive type '${r}' - expected ${pa.join(", ")} or Enum`,f(e));let a=new Map;s.forEach((m,u)=>{a.has(m.name)||a.set(m.name,u)});let c=[],d=[];for(let m=t.peekChild(e.indent);m!==void 0;m=t.peekChild(e.indent)){t.reader.takeSignificant();let u=Dp.exec(m.content);if(!le(m))if(R(m.content)==="validate"){r==="Enum"&&m.content==="validate"&&t.peekChild(m.indent)===void 0&&t.warning(p.ValidateReadAsEnumerationBlock,`'validate' in enumeration concept '${i}' declares an empty validate block, not a value named 'validate' - write '@validate' for the value`,f(m));let y=qi(t,m,"concept");y!==void 0&&d.push(y)}else u!==null?zp(t,m,i,s,a,u[1],H(u[2])):r==="Enum"&&Rp.test(m.content)?c.push(X(m.content)):r==="Enum"?t.error(p.InvalidEnumerationValue,`Invalid enum value '${m.content}' - expected an identifier`,f(m)):(t.error(p.UnknownConceptDirective,`Unexpected '${m.content}' in concept body - expected validate, 'file <path>' or '<attribute> reason "<text>"'`,f(m)),t.skipBlock(m.indent))}return{kind:"ConceptSyntax",name:i,type:r,attributes:s,values:c,validations:d,location:f(e)}}l(Up,"parseConcept");function zp(t,e,n,i,r,o,s){let a=r.get(o);a===void 0?t.error(p.AttributeReasonWithoutAttribute,`Concept '${n}' declares a reason for '${o}' without the attribute - write 'concept ${n} : <Type> @${o}'`,f(e)):i[a].reason!==null?t.error(p.DuplicateAttributeReason,`Concept '${n}' already declares a reason for '${o}' - at most one is allowed`,f(e)):i[a]={...i[a],reason:s}}l(zp,"applyAttributeReason");function Vp(t,e){let n=Mp.exec(e.content)?.[1]??"";n===""&&t.error(p.InvalidPersonaDeclaration,`Invalid persona declaration '${e.content}' - expected 'persona <Name>'`,f(e));let i=null,r=[];for(let o=t.peekChild(e.indent);o!==void 0;o=t.peekChild(e.indent)){t.reader.takeSignificant();let s=R(o.content);if(s==="description")i=G(t,o,i,`Persona '${n}'`);else if(s==="policy"){let a=Np.exec(o.content);a===null?t.error(p.InvalidPersonaPolicyReference,`Invalid policy reference '${o.content}' - expected 'policy <Name>'`,f(o)):r.push(a[1])}else t.error(p.UnknownPersonaDirective,`Unexpected '${s}' in persona body - expected description or policy`,f(o)),t.skipBlock(o.indent)}return{kind:"PersonaSyntax",name:n,description:i,policies:r,location:f(e)}}l(Vp,"parsePersona");var Ct=class t{static{l(this,"CommandStreamCandidates")}sources;qualifiedTypes;constructor(e,n){this.sources=e,this.qualifiedTypes=n}hasSource(e){return this.sources.has(e)}hasPropertyType(e){return this.qualifiedTypes.has(e)}hasUniqueStream(e,n){let i=this.sources.get(e);return i?.length===1&&i[0].filter(r=>r===n).length===1}static capture(e,n=lt,i){return this.capturePlaced([...e].map(r=>({lines:r,placement:n})),i)}static capturePlaced(e,n){let i=new Map,r=new Set,o=new Set;for(let{lines:a,placement:c}of e){let d=Bn(a,a[0]?.path,n);d.scope=c;let m=Wn(d,a,c);for(let u of m.types)r.add(u.name);for(let u of m.concepts)r.add(u.name);for(let u of m.imports)o.add(u.qualifiedName);for(let u of m.eventSources??[])i.set(u.name,[...i.get(u.name)??[],u.streams.map(y=>y.name)])}let s=new Set([...o].filter(a=>r.has(a.substring(a.lastIndexOf(".")+1))));return new t(i,s)}};var fe;(function(t){t.Unique="unique",t.Ambiguous="ambiguous",t.NotFound="notFound",t.WrongKind="wrongKind"})(fe||(fe={}));var nt=class{static{l(this,"EventSourceCatalog")}sources=new Map;otherNames;constructor(e){for(let n of e.eventSources??[])this.sources.set(n.name,[...this.sources.get(n.name)??[],n]);this.otherNames=new Set([...e.concepts,...e.types].map(n=>n.name))}resolve(e,n){let i=this.sources.get(e)??[],r=i.flatMap(s=>s.streams).filter(s=>s.name===n),o;return i.length===0?o=this.otherNames.has(e)?fe.WrongKind:fe.NotFound:i.length>1||r.length>1?o=fe.Ambiguous:o=r.length===1?fe.Unique:fe.NotFound,{kind:o,sources:i,streams:r}}};function Un(t,e,n,i,r,o,s){if(n){o.error(r,"A composite stream requires a streamId part block, not a scalar mapping.",i);return}let a=t.streamIdParts;for(let d of a.filter(m=>!e.some(u=>u.property===m.name)))o.error(r,`Stream id part '${d.name}' requires a mapping.`,i);let c=new Set;for(let d of e){let m=a.find(u=>u.name===d.property);m===void 0?o.error(r,`Unknown stream id part '${d.property}'.`,d.location):c.has(d.property)?o.error(r,`Stream id part '${d.property}' is mapped more than once.`,d.location):(c.add(d.property),s(d,m.type))}}l(Un,"validateStreamIdParts");function ya(t,e){t=Ue(t);let n=new re(t);if(!n.slices.flatMap(v=>v.slice.specifications).some(v=>[...v.given,...v.thenEvents,...v.whenAppended===null?[]:[v.whenAppended]].some(x=>x.stream!=null||x.noStream!=null)))return;let i=new nt(t),r=ne(t.concepts),o=ne(t.types),s=new Map([...o].map(([v,x])=>[v,ne(x.properties)])),a=l((v,x)=>Ie(v,x,r,s),"compatible"),c=new Set(["String","Uuid","Int","Decimal","Bool","Date","DateTime",...r.keys(),...o.keys()]),d=l((v,x)=>c.has(v.name)&&c.has(x.name)?v.name===x.name&&v.isCollection===x.isCollection&&(!v.isOptional||x.isOptional):null,"nominallyCompatible"),m=l((v,x)=>{if(v?.kind!=="LiteralExpressionSyntax"||!a(v,x))return null;let $=r.get(x.name)?.type??x.name,C=v.value;if($==="String"&&typeof C=="string")return C;if($==="Uuid"&&typeof C=="string"){let E=C.replace(/[{}()-]/g,"").toLowerCase();return`${E.slice(0,8)}-${E.slice(8,12)}-${E.slice(12,16)}-${E.slice(16,20)}-${E.slice(20)}`}if($==="Int"){if(typeof C=="number")return BigInt(C).toString();if(typeof C=="object"&&C!==null&&C.literalType==="ExactNumber")return Ht(C)}return null},"formatStreamId"),u=l((v,x)=>{let $=v.properties,C=null,E=!1,P=!1;for(let A of x.split(".")){let g=$.filter(k=>k.name===A);if(g.length!==1)return null;let S=g[0].type;E||=S.isOptional,P||=S.isCollection,C={...S,isOptional:E,isCollection:P},$=o.get(S.name)?.properties??[]}return C},"pathType"),y=l((v,x)=>{let $=n.resolve(v,x).declaration;return $?.node.kind==="EventSyntax"?$.node:null},"eventOf"),h=[];for(let{slice:v}of n.slices){for(let x of v.commands)for(let $ of x.produces){if(!n.isEventProduction($,v))continue;let C=y($.event,v);if(C===null)continue;let E=$.for?.kind==="PathExpressionSyntax"?$.for.path:la(x,$,{resolver:n,slice:v}),P=E==="new event source"?{kind:"TypeRefSyntax",name:"Uuid",isOptional:!1,isCollection:!1,location:$.location}:E===void 0?null:u(x,E);h.push({event:C,command:x,type:P})}for(let x of v.reactions.flatMap($=>$.triggers).flatMap($=>$.produces)){let $=y(x.event,v);$!==null&&h.push({event:$,command:null,type:null})}for(let x of v.captures)for(let $ of[...x.appends,...x.children.flatMap(C=>C.appends),...x.nested.flatMap(C=>C.appends)]){let C=y($.event,v);C!==null&&h.push({event:C,command:null,type:null})}}for(let{slice:v,scope:x}of n.slices)for(let $ of v.specifications){let C=n.slices.flatMap(k=>k.slice.commands.map(b=>({command:b,scope:k.scope}))),E=$.when?.commandType.split(".")??[],P=E.slice(0,-1),A=C.filter(k=>k.command.name===E.at(-1)&&P.every((b,I)=>k.scope[k.scope.length-P.length+I]===b)),g=P.length>0&&A.length===1?A[0].command:null;for(let k=x.length;P.length===0&&k>=0&&g===null;k--){let b=A.filter(I=>x.slice(0,k).every((w,D)=>I.scope[D]===w));if(b.length>0){g=b.length===1?b[0].command:null;break}}let S=[...$.given.map(k=>({node:k,required:!0,expected:!1})),...$.whenAppended===null?[]:[{node:$.whenAppended,required:!0,expected:!1}],...$.thenEvents.map(k=>({node:k,required:!1,expected:!0}))];for(let{node:k,required:b,expected:I}of S){if(k.stream==null&&k.noStream==null)continue;b&&k.noStream!=null&&e.error(p.InvalidSpecificationStream,"Expected 'stream Source.Stream', or 'no stream' on a then event.",k.noStream.location);let w=null,D=y(k.eventType,v),N=h.filter(j=>j.event===D);if(k.stream!=null){let j=k.stream,F=i.resolve(j.eventSource,j.stream);if(F.kind!==fe.Unique){let oe={ambiguous:"Ambiguous",notFound:"NotFound",wrongKind:"WrongKind"}[F.kind];e.error(p.InvalidSpecificationStreamRoute,`Stream '${j.eventSource}.${j.stream}' is ${oe}; routing requires one physical source and stream.`,j.location);continue}let U=F.sources[0],Y=F.streams[0],Q=l((oe,Le)=>{let ae=oe.source;(ae.kind!=="LiteralExpressionSyntax"||ae.value===null||ae.value===""||Le!==null&&!a(ae,Le))&&e.error(p.InvalidSpecificationStreamRoute,"A specification stream id needs a nonempty concrete scalar literal compatible with the stream's declared type.",ae.location)},"validateLiteral");if(Y.streamIdParts.length>0?Un(Y,j.streamIdParts,j.streamId!==null,j.location,p.InvalidSpecificationStreamRoute,e,Q):j.streamIdParts.length>0?e.error(p.InvalidSpecificationStreamRoute,"A streamId part block requires a composite stream.",j.location):(Y.streamId===null!=(j.streamId===null)&&e.error(p.InvalidSpecificationStreamRoute,Y.streamId===null?"An unkeyed stream cannot take a streamId mapping.":"This keyed stream requires a streamId mapping.",j.location),j.streamId!==null&&Q(j.streamId,Y.streamId)),w=U.identifier,w===null){let oe=N.map(ae=>ae.type),Le=new Set(oe.filter(ae=>ae!==null).map(ae=>`${ae.name}:${ae.isOptional}:${ae.isCollection}`));oe.length===0||oe.some(ae=>ae===null)||Le.size!==1?e.error(p.InvalidSpecificationStreamEventSource,`Declare an identifier on source '${U.name}'; the event's producers do not supply one unambiguous destination type.`,j.location):w=oe[0]}b&&k.for===null?e.error(p.InvalidSpecificationStreamEventSource,"A routed given or when append event requires 'for <literal>'.",j.location):k.for!==null&&(k.for.kind!=="LiteralExpressionSyntax"||k.for.value===null||w!==null&&(w.isCollection||w.isOptional||!a(k.for,w)))&&e.error(p.InvalidSpecificationStreamEventSource,"A routed event's for value must be a concrete literal compatible with the source's identifier type.",k.for.location)}if(!I||g===null||N.length===0||N.some(j=>j.command!==g))continue;let L=g.stream?.propertyCandidate===null?g.stream:null,q=k.noStream!=null?L!=null:L==null||L.eventSource!==k.stream.eventSource||L.stream!==k.stream.stream;if(!q&&k.stream!=null&&L!=null){let j=i.resolve(k.stream.eventSource,k.stream.stream),F=j.kind===fe.Unique?j.streams[0]:null;if(F!==null&&F.streamIdParts.length>0){if(L.streamId===null&&k.stream.streamId===null&&L.streamIdParts.length>0&&k.stream.streamIdParts.length>0)for(let U of F.streamIdParts){let Y=L.streamIdParts.filter(ae=>ae.property===U.name),Q=k.stream.streamIdParts.filter(ae=>ae.property===U.name);if(Y.length!==1||Q.length!==1)continue;let oe=m(Y[0].source,U.type),Le=m(Q[0].source,U.type);oe!==null&&Le!==null&&oe!==Le&&(q=!0)}}else if(F?.streamId!=null&&L.streamIdParts.length===0&&k.stream.streamIdParts.length===0){let U=m(L.streamId?.source,F.streamId),Y=m(k.stream.streamId?.source,F.streamId);U!==null&&Y!==null&&U!==Y&&(q=!0)}}k.for?.kind==="LiteralExpressionSyntax"&&N.every(j=>j.type!==null&&(w!==null?d(j.type,w)===!1:!a(k.for,j.type)))&&(q=!0),q&&e.error(p.SpecificationStreamContradictsCommand,"The expected event route contradicts its only producer, the command under test.",(k.stream??k.noStream).location)}}}l(ya,"validateSpecificationStreams");var pr=new Set(["String","Uuid","Int","Decimal","Bool","Date","DateTime"]);function zn(t,e){let n=ne(t.concepts),i=ne(t.types),r=new Set([...pr,...n.keys(),...i.keys()]),o=new Map([...i].map(([u,y])=>[u,ne(y.properties)])),s=l((u,y)=>r.has(u.name)&&r.has(y.name)?u.name===y.name&&u.isCollection===y.isCollection&&(!u.isOptional||y.isOptional):null,"compatible"),a=l((u,y)=>{if(u===null)return;if(u.isOptional||u.isCollection||t.types.some(x=>x.name===u.name)){e.error(p.InvalidEventSourceDeclaration,"Identifier and streamId declarations require a nonoptional scalar value type.",u.location);return}let h=t.concepts.filter(x=>x.name===u.name),v=h.length===1?h[0].type:h.length===0&&pr.has(u.name)?u.name:null;y&&v!==null&&(!["String","Uuid","Int"].includes(v)||v==="Int"&&h.length===0||h.some(x=>x.values.length>0))&&e.error(p.UnsupportedStreamIdType,"Stream ids support text and UUID values and their nominal concepts, plus integer-backed concepts; other types need a future portable formatter.",u.location),v===null&&!t.imports.some(x=>x.qualifiedName===u.name||x.qualifiedName.split(".").at(-1)===u.name)&&e.warning(p.UnknownType,`Unknown type '${u.name}' in event source declaration.`,u.location)},"validateType"),c=new Set;for(let u of t.eventSources??[]){c.has(u.name)&&e.error(p.InvalidEventSourceDeclaration,`Event source '${u.name}' has multiple physical declarations.`,u.location),c.add(u.name),a(u.identifier,!1);let y=new Set;for(let h of u.streams){y.has(h.name)&&e.error(p.InvalidEventSourceDeclaration,`Stream '${u.name}.${h.name}' has multiple declarations under this source.`,h.location),y.add(h.name),a(h.streamId,!0);let v=h.streamIdParts;if(v.length>0){v.length<2&&e.error(p.InvalidEventSourceDeclaration,"A composite stream id requires at least two named parts.",h.directiveLocations?.streamId??h.location);for(let x of new Set(v.map($=>$.name)))for(let $ of v.filter(C=>C.name===x).slice(1))e.error(p.InvalidEventSourceDeclaration,`Stream id part '${$.name}' is declared more than once.`,$.location);for(let x of v)a(x.type,!0)}}}let d=l((u,y)=>{let[h,...v]=y.split(".");if(u===null)return{property:null,missing:!1};let x=u.filter(E=>E.name===h);if(x.length!==1)return{property:null,missing:x.length===0};let $=x[0];if(v.length===0)return{property:$,missing:!1};if(pr.has($.type.name)||n.has($.type.name)&&!i.has($.type.name))return{property:null,missing:!0};let C=d(i.get($.type.name)?.properties??null,v.join("."));return C.property===null?C:{property:{...C.property,type:{...C.property.type,isCollection:$.type.isCollection||C.property.type.isCollection,isOptional:$.type.isOptional||C.property.type.isOptional}},missing:!1}},"pathProperty"),m=new nt(t);for(let{slice:u}of new re(t).slices)for(let y of u.commands){let h=y.stream;if(h==null||h.propertyCandidate!==null)continue;let v=m.resolve(h.eventSource,h.stream);if(v.kind!==fe.Unique){let P={ambiguous:"Ambiguous",notFound:"NotFound",wrongKind:"WrongKind"}[v.kind];e.error(p.InvalidCommandStream,`Stream '${h.eventSource}.${h.stream}' is ${P}; routing requires one physical source and stream.`,h.location);continue}let x=v.sources[0],$=v.streams[0],C=y.properties.filter(P=>P.isIdentifier);x.identifier!==null&&C.length===1&&s(C[0].type,x.identifier)===!1&&e.warning(p.InvalidCommandStream,`Command identifier '${C[0].name}' does not have the source's nominal identifier type '${x.identifier.name}'. The stream does not supply a destination.`,C[0].location);let E=l((P,A)=>{let g=P.source;if(g.kind==="PathExpressionSyntax"){let S=d(y.properties,g.path);(S.missing||S.property!==null&&s(S.property.type,A)===!1)&&e.error(p.InvalidCommandStream,`Stream id source '${g.path}' is absent or incompatible with nominal type '${A.name}'.`,g.location)}else g.kind==="LiteralExpressionSyntax"&&!Ie(g,A,n,o)?e.error(p.InvalidCommandStream,`Stream id value is incompatible with nominal type '${A.name}'.`,g.location):(["RawExpressionSyntax","ObjectExpressionSyntax","ListExpressionSyntax"].includes(g.kind)||g.kind==="LiteralExpressionSyntax"&&g.value===null)&&e.error(p.InvalidCommandStream,"A stream id needs a scalar value source, not a raw expression, collection or absence.",g.location)},"validateMapping");if($.streamIdParts.length>0){Un($,h.streamIdParts,h.streamId!==null,h.location,p.InvalidCommandStream,e,(P,A)=>{E(P,A),P.source.kind==="LiteralExpressionSyntax"&&P.source.value===""&&e.error(p.InvalidCommandStream,"A composite stream id part cannot be empty text.",P.source.location)});continue}if(h.streamIdParts.length>0){e.error(p.InvalidCommandStream,"A streamId part block requires a composite stream.",h.location);continue}($.streamId===null&&h.streamId!==null||$.streamId!==null&&h.streamId===null)&&e.error(p.InvalidCommandStream,$.streamId===null?"An unkeyed stream cannot take a streamId mapping.":"This keyed stream requires a streamId mapping.",h.location),!($.streamId===null||h.streamId===null)&&E(h.streamId,$.streamId)}ya(t,e)}l(zn,"validateEventSources");function Vn(t,e){let n=new re(t),i=n.slices,r=new Set(t.imports.map(x=>x.qualifiedName)),o=new Set([...i.flatMap(({slice:x})=>se(x).map($=>$.name)),...t.imports.map(x=>x.qualifiedName.split(".").at(-1))]),s=ne(t.types),a=new Set(["Uuid","String","Int","Decimal","Bool","Date","DateTime",...t.concepts.map(x=>x.name)].filter(x=>!s.has(x))),c=l((x,$)=>{let[C,...E]=$.split(".");if(x===null)return{value:null,missing:!1};let P=x.filter(g=>g.name===C);if(P.length!==1)return{value:null,missing:P.length===0};let A=P[0];return E.length===0?{value:A,missing:!1}:a.has(A.type.name)?{value:null,missing:!0}:c(s.get(A.type.name)?.properties??null,E.join("."))},"property"),d=i.flatMap(({slice:x,scope:$})=>x.readModels.map(C=>({node:C,scope:$}))),m=l((x,$)=>{let C=l(A=>{let g=A.split("."),S=d.filter(b=>b.node.name===g.at(-1)),k=g.slice(0,-1);if(k.length>0)return S.filter(b=>k.length<=b.scope.length&&k.every((I,w)=>b.scope[b.scope.length-k.length+w]===I));for(let b=$.length;b>=0;b--){let I=S.filter(w=>b<=w.scope.length&&$.slice(0,b).every((D,N)=>w.scope[N]===D));if(I.length>0)return I}return[]},"candidates"),E=C(x),P=t.imports.filter(A=>A.qualifiedName.split(".").at(-1)===x);return E.length===0&&P.length===1&&(E=C(P[0].qualifiedName)),E.length===1?E[0].node.properties:null},"viewProperties"),u=l((x,$,C)=>{let E=n.resolve(x,C);o.has(x)||r.has(x)||E.declaration?.kind===ee.Event||E.candidates.some(A=>A.kind===ee.Event)||e.warning(p.UnknownEvent,`Unknown event '${x}' - declare it with 'event ${x}'`,$)},"unknownEvent"),y=l((x,$)=>{for(let C of x)(C.kind==="RemoveWithSyntax"||C.kind==="RemoveViaJoinSyntax")&&u(C.event,C.location,$),"blocks"in C&&y(C.blocks,$)},"removals"),h=new Set,v=l((x,$,C=!1,E=!1)=>{let P=l((g,S)=>{let k=c($,g),b=JSON.stringify([S.path,S.line,S.column]);return k.missing&&!h.has(b)&&(h.add(b),e.warning(p.UnknownReadModelProperty,`Projection target '${g}' is not a declared ${C?"element":"read-model"} property`,S)),k.value},"validate"),A=E||x.some(g=>g.kind==="FromSyntax"||g.kind==="JoinSyntax"||g.kind==="AllSyntax");for(let g of x){let S=g.kind==="EverySyntax"&&!A?[]:"mappings"in g?g.mappings:g.kind==="JoinSyntax"?g.events.flatMap(k=>k.mappings):[];for(let k of S)P(k.property,k.location);if(g.kind==="ChildrenSyntax"||g.kind==="NestedSyntax"){let k=P(g.property,g.location);v(g.blocks,k===null?null:s.get(k.type.name)?.properties??null,!0)}}},"walk");for(let{slice:x}of i){for(let $ of x.projections)y($.blocks,x);for(let $ of x.captures)for(let C of[...$.appends,...$.children.flatMap(E=>E.appends),...$.nested.flatMap(E=>E.appends)])u(C.event,C.location,x)}for(let{slice:x,scope:$}of i)for(let C of x.projections){let E=C.blocks.filter(P=>P.kind==="ProjectionVariantSyntax");E.length===0&&v(C.blocks,m(C.readModel??C.name,$));for(let P of E){let A=m(P.name,$);v(C.blocks.filter(S=>S.kind==="ChildrenSyntax"||S.kind==="NestedSyntax"),A);let g=P.entersOn.length>0||C.blocks.some(S=>S.kind==="FromSyntax"||S.kind==="JoinSyntax"||S.kind==="AllSyntax");v(P.blocks,A,!1,g)}}}l(Vn,"validateProjectionTargets");function Qn(t,e){let n=new Set(t.concepts.filter(u=>u.attributes.some(y=>y.name==="pii")).map(u=>u.name)),i=new Set(t.concepts.filter(u=>u.attributes.some(y=>y.name==="sensitive")).map(u=>u.name)),r=ne(t.types),o=new re(t),s=new Set(t.imports.map(u=>u.qualifiedName.split(".").at(-1))),a=new Map;for(let u of t.declaredTriggers??[]){let y=a.get(u.name)??[];y.push(u.data),a.set(u.name,y)}let c=l((u,y,h="an event source identifier")=>{if(n.has(u.name)||i.has(u.name)){let v=n.has(u.name)?"@pii":"@sensitive";e.error(p.PiiNotSupportedOnIdentifier,`Concept '${u.name}' is ${v} and cannot be ${h} - use a surrogate Uuid identifier and keep the ${v} value as a property`,y)}},"validate"),d=l((u,y)=>{let[h,...v]=y.split("."),x=u.filter(C=>C.name===h);if(x.length!==1)return null;let $=x[0];return v.length===0?$:d(r.get($.type.name)?.properties??[],v.join("."))},"property");for(let u of t.eventSources??[]){u.identifier!=null&&c(u.identifier,u.identifier.location);for(let y of u.streams){y.streamId!==null&&c(y.streamId,y.streamId.location,"a stream id");for(let h of y.streamIdParts)c(h.type,h.type.location,`a stream id part '${h.name}'`)}}let m=new nt(t);for(let{slice:u}of o.slices){for(let y of u.commands){for(let h of y.properties.filter(v=>v.isIdentifier))c(h.type,h.location);for(let h of[...y.stream?[y.stream]:[],...y.streamCandidates??[]].filter(v=>v.propertyCandidate===null)){let v=m.resolve(h.eventSource,h.stream),x=v.kind===fe.Unique?v.streams[0]:void 0,$=[...h.streamId===null?[]:[{mapping:h.streamId,target:x?.streamId}],...h.streamIdParts.map(C=>({mapping:C,target:x?.streamIdParts.find(E=>E.name===C.property)?.type}))];for(let{mapping:C,target:E}of $){if(C.source.kind!=="PathExpressionSyntax")continue;let P=d(y.properties,C.source.path);P!==null&&(P.type.name===E?.name&&(n.has(P.type.name)||i.has(P.type.name))||c(P.type,C.source.location,"a stream id route mapping"))}}for(let h of y.produces.filter(v=>o.isEventProduction(v,u))){if(h.for?.kind!=="PathExpressionSyntax")continue;let v=d(y.properties,h.for.path);v!==null&&!v.isIdentifier&&c(v.type,h.for.location)}}for(let y of u.reactions.flatMap(h=>h.triggers)){if(y.source.kind!=="NamedTriggerSourceSyntax")continue;let v=o.resolve(y.source.name,u).declaration?.node,x=(we(y).data??[]).flatMap(C=>C.type===null?[]:[{kind:"PropertySyntax",name:C.name,type:C.type,isIdentifier:!1,location:C.location}]),$=[v?.kind==="EventSyntax"?v.properties:[],x];v?.kind!=="EventSyntax"&&!s.has(y.source.name)&&$.push(...a.get(y.source.name)??[]);for(let C of y.produces.filter(E=>o.isEventProduction(E,u))){if(C.for?.kind!=="PathExpressionSyntax")continue;let E=C.for.path,P=$.map(A=>d(A,E)).find(A=>A!==null&&(n.has(A.type.name)||i.has(A.type.name)));P!=null&&c(P.type,C.for.location)}}}}l(Qn,"validateIdentifierCompliance");var ha=new Set(["String","Uuid","Int","Decimal","Bool","Date","DateTime"]),it=class{static{l(this,"RefusalDeclarations")}application;slices;types;concepts;events;knownTypes;constructor(e){this.application=e,this.slices=new re(e).slices,this.types=ne(e.types),this.concepts=ne(e.concepts),this.knownTypes=new Set([...ha,...e.types.map(n=>n.name),...e.concepts.map(n=>n.name)]),this.events=new Map(this.slices.map(({slice:n})=>{let i=new Map;for(let r of se(n))(!i.has(r.name)||i.get(r.name).generation<r.generation)&&i.set(r.name,r);return[n,[...i.values()]]}))}resolve(e,n,i){let r=this.slices.flatMap(({slice:c,scope:d})=>i(c).map(m=>({node:m,slice:c,scope:d}))),o=this.slices.find(c=>c.slice===n)?.scope??[],s=l(c=>{let d=c.split("."),m=r.filter(y=>y.node.name===d.at(-1)),u=d.slice(0,-1);if(u.length>0)return m.filter(y=>u.length<=y.scope.length&&u.every((h,v)=>y.scope[y.scope.length-u.length+v]===h));for(let y=o.length;y>=0;y--){let h=m.filter(v=>y<=v.scope.length&&o.slice(0,y).every((x,$)=>v.scope[$]===x));if(h.length>0)return h}return[]},"candidates"),a=s(e);if(a.length===0){let c=this.application.imports.filter(d=>d.qualifiedName.split(".").at(-1)===e);c.length===1&&(a=s(c[0].qualifiedName))}return a.length===1?a[0]:null}event(e,n){return this.resolve(e,n,i=>this.events.get(i)??[])?.node??null}property(e,n){let i=n.split(".");for(let[r,o]of i.entries()){let s=e?.filter(c=>c.name===o)??[];if(s.length!==1)return null;let a=s[0];if(r===i.length-1)return a;if(ha.has(a.type.name)||this.concepts.has(a.type.name)&&!this.application.types.some(c=>c.name===a.type.name))return null;e=this.types.get(a.type.name)?.properties??null}return null}compatible(e,n){return this.knownTypes.has(e.name)&&this.knownTypes.has(n.name)?e.name===n.name&&e.isCollection===n.isCollection&&(!e.isOptional||n.isOptional):null}};var Gn=class extends tt{static{l(this,"RefusalValueWalker")}declarations;context;slice=null;branch=null;properties=null;target=null;mapping=!1;constructor(e,n){super(),this.declarations=e,this.context=n}visitSlice(e){this.slice=e,super.visitSlice(e),this.slice=null}visitInvocationRefusal(e){this.branch=e,super.visitInvocationRefusal(e),this.branch=null}visitProduces(e){if(this.branch===null||this.slice===null){super.visitProduces(e);return}this.visitNode(e),e.for!==null&&this.visitExpression(e.for),e.when!=null&&this.visitCondition(e.when),e.tags.forEach(n=>this.visitTag(n)),this.properties=this.declarations.event(e.event,this.slice)?.properties??null,e.mappings.forEach(n=>this.visitPropertyMapping(n)),this.properties=null}visitPropertyMapping(e){this.mapping=this.branch!==null,this.target=this.declarations.property(this.properties,e.property)?.type??null,super.visitPropertyMapping(e),this.target=null,this.mapping=!1}visitObjectMember(e){let n=this.target;this.target=this.declarations.property(n===null?null:this.declarations.types.get(n.name)?.properties??null,e.name)?.type??null,super.visitObjectMember(e),this.target=n}visitExpression(e){e.kind==="RefusalExpressionSyntax"&&(!this.mapping||this.branch===null||!["reason","constraint","message"].includes(e.member)||e.member==="constraint"&&this.branch.selector!=="constraint"?this.context.error(p.InvalidRefusalValue,`'$refusal.${e.member}' is only available in a refusal branch's event mapping; constraint requires 'by constraint'.`,e.location):this.target!==null&&(this.target.isCollection||this.declarations.compatible({...this.target,name:"String",isOptional:!1,isCollection:!1},this.target)===!1&&!this.declarations.application.concepts.some(i=>i.name===this.target.name&&i.type==="String"))&&this.context.error(p.InvalidRefusalValue,`'$refusal.${e.member}' is a String value, incompatible with '${this.target.name}'.`,e.location));let n=this.target;e.kind==="ListExpressionSyntax"&&n!==null&&(this.target={...n,isCollection:!1}),super.visitExpression(e),this.target=n}};function Qp(){return!0}l(Qp,"invocationHasNoDeclaredIdentity");function Gp(t){let e=new Set,n=l((i,r)=>{let o=r||i.authorize!==null;o&&i.slices.forEach(s=>e.add(s)),i.features.forEach(s=>n(s,o))},"collect");return t.modules.forEach(i=>i.features.forEach(r=>n(r,i.authorize!==null))),e}l(Gp,"authorizationGatedSlices");function Kn(t,e){let n=new it(Ue(t));new Gn(n,e).visitApplication(n.application);let i=Gp(n.application);for(let{slice:r}of n.slices){let o=l(c=>n.resolve(c,r,d=>d.constraints),"constraintOf"),s=l((c,d)=>c===d||o(c)!==null&&o(c)?.node===o(d)?.node,"sameConstraint"),a=l((c,d)=>c.selector==="any"&&["any","validation","constraint"].includes(d.selector)||c.selector===d.selector&&(c.selector!=="constraint"||c.constraint===null||d.constraint!==null&&s(c.constraint,d.constraint)),"covers");for(let c of r.reactions.flatMap(d=>d.triggers).flatMap(d=>d.invokes)){let d=n.resolve(c.command,r,y=>y.commands),m=d!==null&&(d.node.authorize!==null||i.has(d.slice)),u=[];for(let y of c.onRefused??[]){if(u.some(C=>a(C,y))&&e.warning(p.UnreachableRefusalBranch,"This refusal selector is covered by an earlier branch; the first matching branch wins.",y.location),u.push(y),y.selector==="authorization"&&Qp()&&m&&e.warning(p.AuthorizationRefusalWithoutIdentity,`Command '${c.command}' is authorization-gated, but this invocation has no declared identity. This authorization refusal branch always fires in the reference runner because there is no caller; Arc runs reactor commands as the system. Declare an invoking identity once supported (#383).`,y.location),y.constraint===null)continue;let h=o(y.constraint);if(h===null){e.error(p.UnknownRefusalConstraint,`Unknown or ambiguous refusal constraint '${y.constraint}'.`,y.location);continue}if(d===null||d.node.handler!==null)continue;let v=[h.node,...h.node.additionalRules];if(v.some(C=>C.kind==="FileConstraintSyntax"))continue;let x=v.map(C=>C.kind==="FileConstraintSyntax"?null:n.event(C.event,h.slice)),$=d.node.produces.map(C=>n.event(C.event,d.slice));x.every(C=>C!==null)&&$.every(C=>C!==null)&&!x.some(C=>$.includes(C))&&e.warning(p.UnreachableRefusalBranch,`Constraint '${y.constraint}' targets none of the events produced by '${c.command}'.`,y.location)}}}}l(Kn,"validateReactionRefusals");function Zn(t,e,n){let i=e===null||e.isCollection?void 0:n.concepts.get(e.name),r=i!==void 0&&i.type==="Enum"?i:null,o=l(a=>r!==null&&a.startsWith(`${r.name}.`)?a.substring(r.name.length+1):a,"member");if(e?.isCollection&&t.kind==="ListExpressionSyntax"&&n.compatible({...e,isCollection:!1},{...e,isCollection:!1})===!0){let a=t.items.map(c=>Zn(c,{...e,isCollection:!1,isOptional:!1},n));return a.some(c=>c===void 0)?void 0:{canonical:`[${a.map(_n).join(",")}]`}}let s=e===null?void 0:n.types.get(e.name)?.properties;if(e!==null&&!e.isCollection&&t.kind==="ObjectExpressionSyntax"&&s!==void 0){let a=t.members.map(c=>{let d=n.property(s,c.name);return{name:c.name,value:d===null?void 0:Zn(c.value,d.type,n)}});return a.some(c=>c.value===void 0)?void 0:{canonical:`{${a.sort((c,d)=>c.name<d.name?-1:c.name>d.name?1:0).map(c=>`${JSON.stringify(c.name)}:${_n(c.value)}`).join(",")}}`}}if(t.kind==="LiteralExpressionSyntax")return r!==null&&typeof t.value=="string"?o(t.value):t.value;if(t.kind==="PathExpressionSyntax"&&r!==null)return o(t.path)}l(Zn,"redeliveryValue");function _n(t){return typeof t=="object"&&t!==null?"canonical"in t?t.canonical:Ht(t):JSON.stringify(t)}l(_n,"canonical");function fr(t,e,n,i){let r=Zn(t,n,i),o=Zn(e,n,i);return r===void 0||o===void 0?null:_n(r)===_n(o)}l(fr,"sameRedeliveryValue");function Jn(t,e){let n=new it(Ue(t));for(let{slice:i}of n.slices)for(let r of i.specifications){let o=r.whenRedelivered;if(o==null)continue;let s=n.event(o.eventType,i),a=n.resolve(o.reaction,i,m=>m.reactions);if(a===null||s===null||!a.node.triggers.some(m=>m.source.kind==="NamedTriggerSourceSyntax"&&n.event(m.source.name,a.slice)===s)){e.error(p.UnknownRedeliveryReaction,`Reaction '${o.reaction}' must resolve unambiguously and observe event '${o.eventType}'.`,o.location);continue}let c=r.given.filter(m=>n.event(m.eventType,i)===s).map(m=>Kp(m,o,s,n)),d=c.filter(m=>m===!0).length;d<2&&c.some(m=>m===null)?e.error(p.UnmatchedRedeliveredOccurrence,`Cannot locate redelivery of '${o.eventType}' uniquely: a given source or locator value is not decidable; state explicit concrete 'for' and values.`,o.location):d!==1&&e.error(p.UnmatchedRedeliveredOccurrence,`Redelivery of '${o.eventType}' matches ${d} given occurrences; use 'for' or values to identify exactly one.`,o.location)}}l(Jn,"validateSpecificationRedelivery");function Kp(t,e,n,i){let r=[];e.for!==null&&r.push(t.for===null?null:fr(e.for,t.for,null,i));for(let o of e.values){let s=t.values.filter(a=>a.property===o.property);r.push(s.length===1?fr(o.source,s[0].source,i.property(n.properties,o.property)?.type??null,i):null)}return r.includes(!1)?!1:r.includes(null)?null:!0}l(Kp,"matches");var Sa=64;function ga(t,e){let n=[];for(let i of t.alternatives){let r=ur(i.condition);r!==null&&(r.length>0&&r.every(o=>n.some(s=>[...s].every(a=>o.has(a))))&&e.warning(p.UnreachableActionAlternative,`Alternative executing '${i.command}' is shadowed by earlier alternatives in this action`,i.location),n.push(...r))}}l(ga,"validateGuardedActionShadowing");function ur(t){if(t.kind==="ComparisonConditionSyntax"){if(t.right.kind!=="LiteralExpressionSyntax")return null;let i=t.right.value,r=JSON.stringify([t.left,t.operator,typeof i,i!==null&&typeof i=="object"?i.value:typeof i=="number"?String(i):i]);return[new Set([r])]}let e=ur(t.left),n=ur(t.right);return e===null||n===null?null:t.operator==="Or"?e.length+n.length>Sa?null:[...e,...n]:e.length*n.length>Sa?null:e.flatMap(i=>n.map(r=>new Set([...i,...r])))}l(ur,"normalize");var Zp=new Set(["Uuid","String","Int","Decimal","Bool","Date","DateTime"]);function Hn(t,e){let n=new it(t);for(let{slice:i}of n.slices)for(let r of i.screens)mr(r.directives,[],i,n,e)}l(Hn,"validateGuardedActions");function mr(t,e,n,i,r){let o=t.filter(a=>a.kind==="ScreenDataSyntax"),s=o.length===0?e:o;for(let a of t)switch(a.kind){case"ScreenGuardedActionSyntax":_p(a,s,n,i,r);break;case"ScreenSectionSyntax":mr(a.directives,s,n,i,r);break;case"ScreenTemplateReferenceSyntax":for(let c of a.slots)mr(c.directives,s,n,i,r);break}}l(mr,"validateContainer");function va(t,e,n){return n.resolve(t,e,i=>i.readModels)?.node.properties??null}l(va,"viewProperties");function _p(t,e,n,i,r){let o=e.length===1?va(e[0].type.name,n,i):null;e.length!==1&&r.warning(p.UnresolvedActionSubject,"A guarded action requires exactly one nearest 'data' subject; no data or equally near data bindings leave 'item' unresolved",t.location);for(let s of t.alternatives){for(let a of yr(s.condition))$a(a.left,a.location,o,n,i,r);xa(s.command,s.arguments,o,n,i,r)}t.otherwise?.command!=null&&xa(t.otherwise.command,t.otherwise.arguments,o,n,i,r),ga(t,r)}l(_p,"validateAction");function xa(t,e,n,i,r,o){let s=r.resolve(t,i,a=>a.commands)?.node;for(let a of e){let c=s?.properties.filter(m=>m.name===a.name);c?.length===0&&o.warning(p.UnknownActionArgumentProperty,`Command '${t}' has no argument property '${a.name}'`,a.location);let d=$a(a.binding,a.location,n,i,r,o,!0);c?.length===1&&d!==null&&c[0].type.isCollection!==d.type.isCollection&&o.warning(p.UnknownActionArgumentProperty,`Command argument '${t}.${a.name}' and subject field '${a.binding}' must have matching collection cardinality`,a.location)}}l(xa,"validateArguments");function $a(t,e,n,i,r,o,s=!1){if(!t.startsWith("item.")||n===null)return null;let a=t.substring(5).split(".");for(let[c,d]of a.entries()){let m=n.filter(y=>y.name===d);if(m.length===0||m.length===1&&m[0].type.isCollection&&(!s||c<a.length-1))return o.warning(p.UnknownActionSubjectField,`Unknown or collection-valued subject field '${t}' - guarded actions require an item field path`,e),null;if(m.length!==1)return null;if(c===a.length-1)return m[0];let u=m[0].type;if(n=r.types.get(u.name)?.properties??va(u.name,i,r),n===null)return(Zp.has(u.name)||r.application.concepts.some(y=>y.name===u.name)&&!r.application.types.some(y=>y.name===u.name))&&o.warning(p.UnknownActionSubjectField,`Subject field '${t}' continues past scalar '${d}'`,e),null}return null}l($a,"validateItemPath");function yr(t){return t.kind==="ComparisonConditionSyntax"?[t]:[...yr(t.left),...yr(t.right)]}l(yr,"comparisons");function dt(t){return Array.from(t,e=>{if(e==="\u0131"||e==="\u017F")return e;let n=e.codePointAt(0);if(n>=8064&&n<=8071||n>=8080&&n<=8087||n>=8096&&n<=8103)return String.fromCodePoint(n+8);if(n===8115)return"\u1FBC";if(n===8131)return"\u1FCC";if(n===8179)return"\u1FFC";let i=e.toUpperCase();return Array.from(i).length===1?i:e}).join("")}l(dt,"ordinalIgnoreCaseKey");function hr(t){let e=Zt(t),n=l((h,v)=>h.map(x=>({syntax:x,rank:e.get(Oe([...v,x.name]))??Number.MAX_SAFE_INTEGER})).sort((x,$)=>x.rank-$.rank).map(x=>x.syntax),"ordered"),i=[],r=l((h,v)=>{let x=[...v,h.name];for(let $ of n(h.slices,x))i.push({syntax:$,scope:[...x,$.name],identity:[...x.map(C=>`container:${C}`),`slice:${$.name}`],index:i.length});for(let $ of n(h.features,x))r($,x)},"feature");for(let h of n(t.modules,[]))for(let v of n(h.features,[h.name]))r(v,[h.name]);let o=new Map(i.map(h=>[h,new Set([...se(h.syntax).map(v=>dt(v.name)),...h.syntax.commands.flatMap(v=>v.produces.map(x=>dt(x.event))),...h.syntax.reactions.flatMap(v=>v.triggers.flatMap(x=>x.produces.map($=>dt($.event))))])])),s=new Map;for(let h of i)for(let v of se(h.syntax)){let x=dt(v.name);s.has(x)||s.set(x,h)}let a=new Map;for(let h of i){let v=Oe(h.scope);a.has(v)||a.set(v,h)}let c=new Map;for(let h of kt.for(t,e).edges.filter(v=>v.kind==="decidesFrom"))for(let v of h.evidence){let x=Oe([...h.consumer.scope,v.name.toLowerCase()]);c.has(x)||c.set(x,a.get(Oe(h.producer.scope)))}let d=[];for(let h of i){let v=new Set,x=jn(h.syntax).references.filter($=>$.timeline).map($=>({event:$.name,location:$.location,readModel:$.targetKind==="ReadModel"}));for(let $ of x){let C=dt($.event),E=`${$.readModel?"ReadModel":"Event"}:${C}`;if(v.has(E))continue;v.add(E);let P=$.readModel?c.get(Oe([...h.scope,$.event.toLowerCase()])):s.get(C);if(P===void 0||P===h)continue;let A=0;for(;A<h.scope.length&&A<P.scope.length&&h.identity[A]===P.identity[A];)A++;if(!(A===h.scope.length||A===P.scope.length)){if($.readModel){let g=h.identity.slice(0,A+1),S=new Set(i.filter(k=>g.every((b,I)=>k.identity[I]===b)).flatMap(k=>[...o.get(k)]));if(Xo(P.syntax,$.event).some(k=>k.timeline&&k.kind==="usesFactsFrom"&&k.targetKind==="Event"&&S.has(dt(k.name))))continue}d.push({...$,consumer:h,producer:P,container:Oe(h.identity.slice(0,A)),left:h.identity[A],right:P.identity[A]})}}}let m=l((h,v)=>h.consumer.index-v.consumer.index||h.location.line-v.location.line||h.location.column-v.location.column,"compare"),u=new Set,y=[];for(let h of new Set(d.map(v=>v.container))){let v=d.filter($=>$.container===h),x=new Map;for(let $ of v)x.has($.left)||x.set($.left,new Set),x.has($.right)||x.set($.right,new Set),x.get($.left).add($.right);for(let $ of _t(x).filter(C=>C.length>1)){let C=new Set($),E=v.filter(g=>C.has(g.left)&&C.has(g.right));E.forEach(g=>u.add(g));let P=E.filter(g=>g.consumer.index<g.producer.index).sort(m)[0];if(P===void 0)continue;let A=l(g=>Math.min(...E.flatMap(S=>[S.consumer,S.producer]).filter(S=>{let k=JSON.parse(h);return S.identity[k.length]===g}).map(S=>S.index)),"memberIndex");$.sort((g,S)=>A(g)-A(S)),y.push({edge:P,diagnostic:{severity:"information",code:p.TimelineCycleGroup,message:`Timeline group ${$.map(g=>`${g.startsWith("slice:")?"slice":h===Oe([])?"module":"feature"} '${g.slice(g.indexOf(":")+1)}'`).join(", ")} depend on each other's events or read models; reordering these members cannot make every dependency flow left to right.`,location:P.location}})}}for(let h of d){if(h.consumer.index>=h.producer.index||u.has(h))continue;let v=h.consumer.scope.slice(0,-1),$=h.producer.scope.length>h.consumer.scope.length&&v.every((E,P)=>h.producer.scope[P]===E)?" The producer is in the consumer's own sub-feature; this cannot be fixed by reordering.":" Consider drawing the producer before the consumer.",C=h.readModel?`reads read model '${h.event}' built by`:`uses event '${h.event}' produced by`;y.push({edge:h,diagnostic:{severity:"information",code:p.EventFromLaterSlice,message:`Slice '${h.consumer.syntax.name}' ${C} slice '${h.producer.syntax.name}' drawn after it.${$}`,location:h.location}})}return y.sort((h,v)=>m(h.edge,v.edge)).map(h=>h.diagnostic)}l(hr,"timelineOrderDiagnostics");function We(t,e,n=lt,i=!0,r,o){let s=ut(t,!1,e),a=Bn(s,e,o);a.scope=n,a.streamCandidates=r??Ct.capture([s],n,o);let c=Wn(a,s,n);if(i){Fn(c,a),dn(c,a),Yn(c,a),qn(c,a),zn(c,a),Vn(c,a),Qn(c,a),Kn(c,a),Jn(c,a),Hn(c,a),c=fn(c,a),Et.validate(c,a);for(let d of cn(c))a.information(d.code,d.message,d.location);for(let d of hr(c))a.information(d.code,d.message,d.location)}return{value:c,diagnostics:a.diagnostics,triggerData:a.triggerData,inputUses:a.inputUses,success:!a.diagnostics.some(d=>d.severity==="error")}}l(We,"parseForAuthoring");function o0(t){return t===p.LegacyOptionalSuffix||t===p.RedundantEventId}l(o0,"isQuickFixDiagnostic");function Sr(t,e){return e.code!==p.LegacyOptionalSuffix?0:/^[\p{L}\p{Mn}\p{Nd}\p{Pc}.]+(?:\[\])?\?/u.exec(t.slice(e.location.column-1))?.[0].length??0}l(Sr,"legacyOptionalTypeLength");function a0(t,e={}){let n=We(t,void 0,e.placement);if(!n.success)return()=>[];let i=ut(t),r=new Map;new class extends tt{visitEvent(C){r.set(C.location.line,C)}}().visitApplication(n.value);let s=new Map,a=new Map,c=new Map,d;for(let C of i)d=r.get(C.number)??d,d!==void 0&&c.set(C.number,d);for(let C of n.diagnostics){s.set(C.code,(s.get(C.code)??0)+1);let E=i[C.location.line-1],P=Sr(E.raw,C);if(P>0)a.set(E.number,{line:E.number,fix:{diagnosticCode:C.code,title:"Use 'optional' instead of '?'",scope:"occurrence",edits:[{start:E.startOffset+C.location.column+P-2,length:1,text:" optional"}]}});else if(C.code===p.RedundantEventId&&Rt(E.raw)<0){let A=c.get(E.number);if(A?.id!==A?.name||A===void 0)continue;a.set(E.number,{line:E.number,fix:{diagnosticCode:C.code,title:"Remove the redundant event id",scope:"occurrence",edits:[{start:E.startOffset,length:(i[E.number]?.startOffset??t.length)-E.startOffset,text:""}]},change:{node:A,replacement:{...A,id:null}}})}}let m=[...a.values()].filter(C=>C.fix.diagnosticCode===p.LegacyOptionalSuffix),u=Xt(n),y=new Map,h,v=!1,x,$=l((C,E)=>{let P=ka(t,C.edits);if(P===void 0)return;let A=We(P,void 0,e.placement);if(!(!A.success||Xt(A)!==(E===void 0?u:Xt(n,[E]))))return A.diagnostics.filter(g=>g.code===C.diagnosticCode).length===(s.get(C.diagnosticCode)??0)-C.edits.length?C:void 0},"verify");return(C,E)=>{let P=typeof C=="number"||C===void 0?void 0:C,A=P===void 0?E===void 0||E===p.LegacyOptionalSuffix:P.some(b=>b.diagnosticCode===p.LegacyOptionalSuffix);if(A&&!v&&(m.length>0&&(x=$({diagnosticCode:p.LegacyOptionalSuffix,title:"Use 'optional' throughout this document",scope:"document",edits:m.flatMap(b=>b.fix.edits)})),v=!0),P!==void 0){if(h===void 0){h=new Map;let I=i.flatMap(N=>a.has(N.number)?[a.get(N.number)]:[]),w=I.flatMap(N=>N.fix.edits),D=ka(t,w);if(w.length>0&&D!==void 0){let N=We(D,void 0,e.placement),L=I.flatMap(q=>q.change===void 0?[]:[q.change]);if(N.success&&Xt(N)===Xt(n,L)){let q=new Map,j=new Map;for(let F of N.diagnostics)q.set(F.code,(q.get(F.code)??0)+1);for(let F of I)j.set(F.fix.diagnosticCode,(j.get(F.fix.diagnosticCode)??0)+F.fix.edits.length);if([...j].every(([F,U])=>(q.get(F)??0)===(s.get(F)??0)-U))for(let F of I)h.set(F.line,F.fix)}}}let b=new Map;for(let I of P){let w=h.get(I.line);w?.diagnosticCode===I.diagnosticCode&&b.set(I.line,w)}return[...b.values(),...A&&x!==void 0?[x]:[]]}let g=typeof C=="number"?C:void 0,S=g===void 0?void 0:a.get(g),k;return S!==void 0&&g!==void 0&&(E===void 0||S.fix.diagnosticCode===E)&&(y.has(g)||(y.size===32&&y.delete(y.keys().next().value),y.set(g,$(S.fix,S.change))),k=y.get(g)),[k,A?x:void 0].filter(b=>b!==void 0)}}l(a0,"prepareQuickFixes");function Xt(t,e=[]){let n=new Map(e.map(i=>[i.node,i.replacement]));return JSON.stringify([t.value,t.triggerData],(i,r)=>["location","usesLocation","targetLocation"].includes(i)?void 0:n.get(r)??r)}l(Xt,"verificationShape");function ka(t,e){let n=[],i=0;for(let r of e){if(r.start<i||r.start<0||r.length<0||r.start+r.length>t.length)return;n.push(t.slice(i,r.start),r.text),i=r.start+r.length}return n.push(t.slice(i)),n.join("")}l(ka,"applyQuickFixEdits");var Pt=class{static{l(this,"EventSourceReadConfidence")}complete;sources=new Map;constructor(e,n){this.complete=n;for(let i of e)this.sources.set(i.source.name,[...this.sources.get(i.source.name)??[],i])}static hasUnknownExtent(e){return e.some(n=>n.severity==="error"&&["PLAY0001","PLAY0503","PLAY0164"].includes(n.code))}resolve(e,n){let i=this.sources.get(e)??[],r=n===void 0?[]:i.flatMap(d=>d.source.streams).filter(d=>d.name===n),o=i.length>1||r.length>1,s=!this.complete||i.some(d=>!d.placementResolved),a=o?"ambiguous":s?"incomplete":i.length===1&&(n===void 0||r.length===1)?"unique":"notFound",c=[];return i.length>1&&c.push("Multiple physical parent sources claim the exact name."),r.length>1&&c.push("Multiple physical streams claim the exact parent and local name."),i.some(d=>!d.placementResolved)&&c.push("A physical parent has unresolved import placement."),this.complete||c.push("Physical source extent or placement is incomplete; missing declarations cannot be excluded."),{state:a,sources:i.map(d=>d.source),streams:r,reasons:c}}};var Jp=de("^[A-Za-z_]\\w*$"),je=l((t,e)=>typeof t=="object"&&t!==null&&!Array.isArray(t)&&t.kind===e,"hasKind"),K=l(t=>{throw new ie(t)},"refuse"),rt=l((t,e,n)=>{if(!Array.isArray(t))return K(n);for(let i=0;i<t.length;i++)je(t[i],e)||K(n)},"collection");function At(t){if(t.kind==="ConceptSyntax"){let e=t;for(let n of e.validations??[])n.kind==="DeclarativeValidateSyntax"&&n.rules.some(i=>i.implementation!=null)&&K("Implementation wrappers on named rules are supported only on commands.")}if(t.kind==="ValidationRuleSyntax"){let e=t;e.implementation!=null&&(je(e.implementation,"ImplementationSyntax")||K("A named rule requires an ImplementationSyntax wrapper."),(e.rule!=="Rule"||e.value?.kind!=="PathExpressionSyntax"||!je(e.value,"PathExpressionSyntax")||typeof e.value.path!="string"||Jp.exec(e.value.path)?.[0]!==e.value.path)&&K("An implementation wrapper requires a valid named rule."),e.file!=null&&e.code!=null&&K("A named rule has at most one file or inline payload."),e.file!=null&&(!je(e.file,"FileReferenceSyntax")||typeof e.file.path!="string")&&K("A named rule file requires a FileReferenceSyntax payload with a string path."),e.code!=null&&(!je(e.code,"CodeBlockSyntax")||typeof e.code.language!="string"||typeof e.code.code!="string")&&K("A named rule inline payload requires a CodeBlockSyntax with string language and code."),At(e.implementation))}if(t.kind==="ProducesSyntax"){let e=t,n=e.inlineOperation;if(n!=null){e.inlineEvent!=null&&K("A production cannot declare both an event and an operation."),(e.when!=null||e.event!==n.name||e.for!=null||(e.tags??[]).length>0)&&K("An inline operation requires a matching unconditional target without event metadata."),rt(n.inputs,"PropertySyntax","Operation inputs must be a collection of properties."),rt(e.mappings,"PropertyMappingSyntax","Production mappings must be a collection of mappings."),n.inputs.length!==e.mappings.length&&K("Inline operation inputs and mappings must correspond in order.");for(let i=0;i<n.inputs.length;i++)n.inputs[i].name!==e.mappings[i].property&&K("Inline operation inputs and mappings must correspond in order.")}}if(t.kind==="OperationPhaseSyntax"){let e=t;e.file!=null&&e.code!=null&&K("An operation phase has at most one file or inline payload."),e.implementation!=null&&At(e.implementation)}if(t.kind==="HandlerSyntax"){let e=t;e.implementation!=null&&e.file!=null&&e.code!=null&&K("A handler has at most one file or inline payload.")}if(t.kind==="ImplementationSyntax"){let e=t;rt(e.hints,"ImplementationHintSyntax","Implementation hints must be a collection of nonblank hints.");for(let n=0;n<e.hints.length;n++)At(e.hints[n])}if(t.kind==="ImplementationHintSyntax"){let e=t;(typeof e.text!="string"||Cn(e.text))&&K("An implementation hint must be nonblank.")}gr(t)}l(At,"validateSyntaxInvariants");function gr(t){let e=l(i=>{Ri(i)||K("Event source and stream names must be identifiers.")},"name"),n=l((i,r)=>{rt(r,"PropertyMappingSyntax","Stream id part mappings must be a collection."),i!==null&&r.length>0&&K("A route cannot map both scalar and composite stream ids."),r.forEach(o=>e(o.property))},"mappings");if(t.kind==="ApplicationSyntax"){let i=t.eventSources;i!==void 0&&rt(i,"EventSourceSyntax","Event sources must be a collection of event source nodes without null elements.")}if(t.kind==="EventSourceSyntax"||t.kind==="EventStreamSyntax"){let i=t;e(i.name),i.id!==null&&(typeof i.id!="string"||i.id.trim()==="")&&K("A rename pin must be nonempty.");let r=i.kind==="EventSourceSyntax"?i.identifier:i.streamId;r!==null&&!je(r,"TypeRefSyntax")&&K("Source identifiers and stream ids require type reference nodes."),r!==null&&(r.isCollection||r.isOptional)&&K("Source identifiers and stream ids require nonoptional scalar type references."),r!==null&&!En(r.name)&&K("Source identifiers and stream ids require an exact type reference name."),i.kind==="EventSourceSyntax"?rt(i.streams,"EventStreamSyntax","Event streams must contain event stream nodes without null elements."):(rt(i.streamIdParts,"EventStreamIdPartSyntax","Stream id parts must be a collection."),i.streamId!==null&&i.streamIdParts.length>0&&K("A stream cannot declare both scalar and composite stream ids."),i.streamIdParts.forEach(o=>gr(o)))}if(t.kind==="EventStreamIdPartSyntax"){let i=t;e(i.name),je(i.type,"TypeRefSyntax")||K("A stream id part requires a type."),(i.type.isOptional||i.type.isCollection)&&K("Source identifiers and stream ids require nonoptional scalar type references."),En(i.type.name)||K("Source identifiers and stream ids require an exact type reference name.")}if(t.kind==="CommandSyntax"){let i=t;i.stream?.propertyCandidate!=null&&K("The authoritative command stream cannot contain an ambiguous property candidate."),i.stream!=null&&!je(i.stream,"CommandStreamSyntax")&&K("The authoritative command stream must be a command stream node."),i.streamCandidates!==void 0&&rt(i.streamCandidates,"CommandStreamSyntax","Command stream candidates must be a collection without null elements.");let r=i.streamCandidates??[];for(let o=0;o<r.length;o++){let s=r[o];if(gr(s),s.propertyCandidate===null&&i.stream==null&&K("A duplicate route candidate requires an authoritative route."),s.propertyCandidate!==null)for(let a=0;a<i.properties.length;a++)i.properties[a]===s.propertyCandidate&&K("An ambiguous property is owned only by its stream candidate.")}}if(t.kind==="SpecificationEventSyntax"){let i=t;i.stream!=null&&i.noStream!=null&&K("An event occurrence cannot declare both stream and no stream."),i.stream!=null&&!je(i.stream,"SpecificationStreamSyntax")&&K("A specification stream requires a specification stream node."),i.noStream!=null&&!je(i.noStream,"SpecificationNoStreamSyntax")&&K("An unrouted expectation requires a specification no stream node.")}if(t.kind==="SpecificationStreamSyntax"){let i=t;e(i.eventSource),e(i.stream),i.streamId!==null&&i.streamId.property!=="streamId"&&K("A specification stream maps only streamId."),n(i.streamId,i.streamIdParts)}if(t.kind==="CommandStreamSyntax"){let i=t;e(i.eventSource),e(i.stream),i.streamId!==null&&i.streamId.property!=="streamId"&&K("A command stream maps only streamId."),n(i.streamId,i.streamIdParts);let r=i.propertyCandidate;r!==null&&(r.name!=="stream"||r.type.name!==`${i.eventSource}.${i.stream}`||r.type.isCollection||r.type.isOptional||r.isGenerated||r.isIdentifier||i.streamId!==null||i.streamIdParts.length>0)&&K("An ambiguous route must retain its exact unmodified property candidate, without selecting nested routing.")}}l(gr,"validateSourceStream");var Ve={kinds:["AddMappingSyntax","AllSyntax","ApplicationSyntax","ApplicationTriggerInteractionTriggerSyntax","ArrangementContainerSyntax","ArrangementOverrideSyntax","ArrangementSlotSyntax","ArrangementSyntax","AuthenticatedConditionSyntax","AuthenticationProviderSyntax","AuthenticationSyntax","AuthorizeSyntax","BehaviorArgumentSyntax","BehaviorParameterSyntax","BehaviorSyntax","BuiltInInteractionTriggerSyntax","CaptureAppendSyntax","CaptureChildrenSyntax","CaptureMapEntrySyntax","CaptureNestedSyntax","CaptureSourceSettingSyntax","CaptureSourceSyntax","CaptureSplitSyntax","CaptureSyntax","CaptureTranslationSyntax","CaptureWhenSyntax","CausedByExpressionSyntax","ChildrenSyntax","ClaimConditionSyntax","ClearMappingSyntax","ClearWithSyntax","CloseDialogActionSyntax","CodeBlockSyntax","CodeValidateSyntax","CommandSyntax","CommandStreamSyntax","ComparisonConditionSyntax","CompositeKeySyntax","ConceptAttributeSyntax","ConceptSyntax","ConcurrencySyntax","ConfirmActionSyntax","ContextExpressionSyntax","ContributionSyntax","CountMappingSyntax","DeclarativeValidateSyntax","DecrementMappingSyntax","DialogTemplateSyntax","DomainSyntax","EnvironmentExpressionSyntax","EventContextExpressionSyntax","EventInteractionTriggerSyntax","EventSourceIdExpressionSyntax","EventSourceSyntax","EventStreamIdPartSyntax","EventStreamSyntax","EventSpecSyntax","EventSyntax","EverySyntax","ExecuteCommandActionSyntax","ExpressionKeySyntax","FeatureSyntax","FileConstraintSyntax","FileImportSyntax","FileReferenceSyntax","FormFieldSyntax","FormPopulateFromItemSyntax","FormPopulateViaQuerySyntax","FormSyntax","FromSyntax","HandlerSyntax","ImplementationSyntax","ImplementationHintSyntax","SystemSyntax","OperationSyntax","OperationPhaseSyntax","SpecificationExampleSyntax","SpecificationOperationFailureSyntax","SpecificationOperationSyntax","SpecificationCompensatedSyntax","ImportSyntax","IncrementMappingSyntax","InteractionArgumentSyntax","InteractionBindingSyntax","IntervalInteractionTriggerSyntax","IntervalTriggerSourceSyntax","InvokesSyntax","InvocationRefusalSyntax","JoinEventSyntax","JoinSyntax","KeyPartSyntax","LayoutSyntax","ListExpressionSyntax","LiteralExpressionSyntax","LogicalConditionSyntax","LogicalPolicyConditionSyntax","LogicalPolicyRequirementSyntax","ModuleSyntax","NamedTriggerSourceSyntax","NavigateActionSyntax","NavigateBackActionSyntax","NestedSyntax","NotPolicyConditionSyntax","NotifyActionSyntax","OpenDialogActionSyntax","ObjectExpressionSyntax","ObjectMemberSyntax","PathExpressionSyntax","PerformerSyntax","PersonaSyntax","PlaceSyntax","PolicyReferenceSyntax","PolicySyntax","ProducesSyntax","ProjectionEntersOnSyntax","ProjectionSyntax","ProjectionVariantSyntax","PropertyMappingSyntax","PropertySyntax","PropertyResponseSourceSyntax","ResponseFieldSyntax","ScalarCommandResponseSyntax","RecordCommandResponseSyntax","ScalarSpecificationReturnSyntax","RecordSpecificationReturnSyntax","QueryParameterSyntax","QuerySyntax","RaiseTriggerActionSyntax","RawExpressionSyntax","ReactionSyntax","ReactionTriggerSyntax","RefusalExpressionSyntax","ReadModelSyntax","ReadsSyntax","ReducerRuleSyntax","ReducerSyntax","RefreshQueryActionSyntax","RemoveViaJoinSyntax","RemoveWithSyntax","RequirementSyntax","RoleConditionSyntax","ScheduleTriggerSourceSyntax","ScreenActionSyntax","ScreenGuardedActionSyntax","ScreenActionAlternativeSyntax","ScreenActionOtherwiseSyntax","ScreenBehaviorSyntax","ScreenCodeSyntax","ScreenColumnSyntax","ScreenDataSyntax","ScreenFieldSyntax","ScreenNavigateSyntax","ScreenSectionSyntax","ScreenSlotSyntax","ScreenSummarySyntax","ScreenSyntax","ScreenTableSyntax","ScreenTemplateReferenceSyntax","ScreenTemplateSyntax","ScreenTitleSyntax","ScreenUsesBehaviorSyntax","SeedEventSyntax","SeedGroupSyntax","SeedSyntax","SetMappingSyntax","SetStateActionSyntax","SliceSyntax","SlotSyntax","SourceItemExpressionSyntax","SpecificationAbsentReadModelSyntax","SpecificationCallerClaimSyntax","SpecificationCallerSyntax","SpecificationCaptureSyntax","SpecificationClockSyntax","SpecificationCommandSyntax","SpecificationDeniedSyntax","SpecificationErrorSyntax","SpecificationEventSyntax","SpecificationNoResultSyntax","SpecificationStreamSyntax","SpecificationNoStreamSyntax","SpecificationQueryResultSyntax","SpecificationQuerySyntax","SpecificationReadModelSyntax","SpecificationRedeliverySyntax","SpecificationSyntax","SpecificationTriggerSyntax","SpecificationWhenQuerySyntax","StringsExpressionSyntax","SubtractMappingSyntax","TagSyntax","TemplateExpressionSyntax","TemplateInterpolationSyntax","TemplateTextSyntax","ThemeSyntax","TriggerDataSyntax","TriggerSyntax","TypeRefSyntax","TypeSyntax","UiProfileSyntax","UniqueEventConstraintSyntax","UniquePropertyConstraintSyntax","DependsOnSyntax","UsesBehaviorSyntax","ValidationRuleSyntax","VariantSyntax"],names:["property","value","autoMap","mappings","authentication","behaviors","concepts","domain","eventSources","examples","fileImports","imports","layouts","modules","personas","policies","seeds","sourceOptions","numericMode","systems","themes","triggers","types","uiProfiles","triggerName","children","gap","syntaxKind","height","root","width","grow","name","span","mode","overrides","variants","alias","providers","requirement","type","bindings","description","file","order","parameters","event","tags","when","appends","identifiedBy","map","source","translations","settings","separator","targets","key","nested","from","to","expression","fromValue","properties","toValue","blocks","claim","matches","matchesSubject","arguments","onFailure","onResult","onSuccess","code","language","authorize","concurrency","documentation","handler","produces","reads","response","stream","streamCandidates","validations","eventSource","propertyCandidate","streamId","streamIdParts","left","operator","right","parts","reason","attributes","values","eventSourceType","eventStreamId","eventStreamType","eventTypes","message","messageIsLiteral","path","contributionPoint","label","navigate","requirements","rules","arrangement","slots","usedBehaviors","eventName","id","identifier","streams","generation","hasGenerationMarker","includeChildren","command","contributions","dependsOn","features","isPlacement","slices","additionalRules","ignoreCasing","releasedBy","pattern","composeUsing","by","query","fields","for","onSubmit","populate","events","parentKey","implementation","hints","text","compensate","execute","inputs","uses","generatedValues","operation","qualifiedName","binding","actions","condition","trigger","amount","unit","onRefused","acknowledge","constraint","selector","on","items","literalType","dialogTemplates","forms","screenTemplates","screen","operand","level","dialogTemplate","members","hidden","sizeHeight","sizeWidth","slotName","x","y","inlineEvent","inlineOperation","readModel","sequence","entersOn","isGenerated","isIdentifier","filters","isObservable","performer","returnType","scope","where","data","invokes","member","severity","role","dayOfMonth","dayOfWeek","time","alternatives","otherwise","outcome","behavior","directives","target","columns","rowClick","fitsSlot","eventSourceId","groups","captures","commands","constraints","operations","projections","queries","reactions","readModels","reducers","screens","specifications","contributes","authenticated","claims","roles","capture","record","instant","commandType","inlineProperty","eventType","noStream","exactly","results","reaction","given","givenCaller","givenCaptures","givenClock","givenOperationFailures","givenReadModels","thenAbsentReadModels","thenCompensated","thenDenied","thenErrors","thenEvents","thenEventsInAnyOrder","thenNoEvents","thenNoResult","thenOperations","thenQueries","thenReadModels","thenResults","thenReturns","whenAppended","whenCapture","whenClock","whenQuery","whenRedelivered","whenTrigger","compatibleWith","isCollection","isOptional","defaultSizeClass","layout","packages","platforms","theme","additionalProperties","rule","places"],rules:[["string"],["ref",26,42,49,50,52,92,93,105,107,128,131,168,188,191],["object",[[0,0,!0],[1,1,!0]]],["enum","Inherit","Disabled","Enabled"],["ref",0,29,44,46,81,164,189],["array",4],["object",[[2,3,!0],[3,5,!1]]],["ref",10],["null"],["union",7,8],["ref",14],["array",10],["ref",39],["array",12],["ref",48],["union",14,8],["ref",53],["array",16],["ref",76],["array",18],["ref",63],["array",20],["ref",80],["array",22],["ref",91],["array",24],["union",25,8],["ref",97],["array",27],["ref",109],["array",29],["union",30,8],["ref",112],["array",32],["ref",163],["array",34],["union",35,8],["enum","legacy","exact"],["object",[[18,37,!0]]],["ref",73],["array",39],["ref",194],["array",41],["union",42,8],["ref",196],["array",44],["union",45,8],["ref",198],["array",47],["union",48,8],["ref",199],["array",50],["union",51,8],["object",[[4,9,!1],[5,11,!1],[6,13,!1],[7,15,!1],[8,17,!1],[9,19,!1],[10,21,!1],[11,23,!1],[12,26,!1],[13,28,!1],[14,31,!1],[15,33,!1],[16,36,!1],[17,38,!1],[19,40,!1],[20,43,!1],[21,46,!1],[22,49,!1],[23,52,!1]]],["object",[[24,0,!0]]],["ref",4,6],["array",55],["integer",-2147483648,2147483647],["union",57,8],["enum","Flat","Row","Column","Grid"],["object",[[25,56,!1],[26,58,!1],[27,59,!0]]],["union",0,8],["object",[[28,61,!1],[29,55,!0],[30,61,!1]]],["boolean"],["object",[[31,63,!1],[28,58,!1],[32,0,!0],[33,58,!1],[30,58,!1]]],["enum","Flow","Freeform"],["ref",5],["array",66],["union",67,8],["union",55,8],["ref",205],["array",70],["union",71,8],["object",[[34,65,!0],[35,68,!1],[29,69,!1],[36,72,!1]]],["object",[]],["object",[[37,61,!1],[32,0,!0]]],["ref",9],["array",76],["object",[[38,77,!1]]],["ref",96,111],["object",[[39,79,!0]]],["object",[[32,0,!0],[1,0,!0]]],["ref",197],["union",82,8],["object",[[32,0,!0],[40,83,!1]]],["ref",83],["array",85],["ref",64],["union",87,8],["ref",13],["array",89],["object",[[41,86,!1],[42,61,!1],[43,88,!1],[32,61,!1],[44,58,!1],[45,90,!1]]],["enum","Click","DoubleClick","Select","Submit","Change","Load","Unload","Enter","Leave","Unknown"],["object",[[27,92,!0]]],["ref",117],["array",94],["ref",190],["array",96],["union",97,8],["ref",25],["union",99,8],["object",[[46,0,!0],[3,95,!1],[47,98,!1],[48,100,!1]]],["ref",16],["array",102],["ref",18,22],["array",104],["object",[[49,103,!1],[50,0,!0],[51,105,!1],[0,0,!0]]],["ref",24],["array",107],["object",[[0,0,!0],[52,1,!0],[53,108,!1]]],["object",[[49,103,!1],[51,105,!1],[0,0,!0]]],["ref",20],["array",111],["object",[[54,112,!1],[27,0,!0]]],["array",0],["object",[[55,0,!0],[52,1,!0],[56,114,!1]]],["ref",17],["array",116],["ref",19],["array",118],["ref",21],["union",120,8],["object",[[49,103,!1],[25,117,!1],[57,61,!1],[51,105,!1],[32,0,!0],[58,119,!1],[52,121,!1],[17,38,!1]]],["object",[[59,0,!0],[60,0,!0]]],["enum","PropertyChanged","Added","Removed","Changed","LogicalOr","LogicalAnd","ValueTransition","Expression"],["object",[[61,61,!1],[62,61,!1],[63,114,!1],[27,124,!0],[64,61,!1]]],["object",[[0,61,!1]]],["ref",1,27,30,58,69,89,101,116,137,138],["array",127],["object",[[2,3,!0],[65,128,!1],[50,1,!0],[0,0,!0]]],["union",1,8],["object",[[66,0,!0],[67,130,!1],[68,63,!0]]],["object",[[0,0,!0]]],["object",[[46,0,!0]]],["ref",82],["array",134],["ref",31,41,59,99,100,103,104,127,136,165],["array",136],["object",[[69,135,!1],[70,137,!1],[71,137,!1],[72,137,!1]]],["object",[[73,0,!0],[74,0,!0]]],["ref",32],["object",[[73,140,!0]]],["ref",11],["union",142,8],["ref",40],["union",144,8],["ref",70],["union",146,8],["ref",113],["array",148],["ref",118],["array",150],["ref",133],["array",152],["union",153,8],["ref",121,122],["union",155,8],["ref",35],["union",157,8],["array",157],["ref",33,45],["array",160],["object",[[75,143,!1],[76,145,!1],[42,61,!1],[77,61,!1],[78,147,!1],[32,0,!0],[79,149,!1],[63,151,!1],[80,154,!1],[81,156,!1],[82,158,!1],[83,159,!1],[84,161,!1]]],["union",150,8],["union",94,8],["object",[[85,0,!0],[86,163,!1],[82,0,!0],[87,164,!1],[88,95,!1]]],["enum","Equal","NotEqual","GreaterThan","GreaterThanOrEqual","LessThan","LessThanOrEqual","Contains","StartsWith"],["object",[[89,0,!0],[90,166,!0],[91,1,!0]]],["ref",90],["array",168],["object",[[92,169,!1],[40,0,!0]]],["object",[[32,0,!0],[93,61,!1]]],["ref",38],["array",172],["union",161,8],["object",[[94,173,!1],[43,88,!1],[32,0,!0],[40,0,!0],[84,174,!1],[95,114,!1]]],["object",[[85,63,!0],[96,61,!1],[97,61,!1],[98,61,!1],[99,114,!1]]],["object",[[69,135,!1],[100,0,!0],[101,63,!0],[70,137,!1],[71,137,!1],[72,137,!1]]],["object",[[102,0,!0]]],["ref",151],["union",179,8],["object",[[103,0,!0],[104,61,!1],[105,180,!1],[44,58,!1]]],["ref",139],["array",182],["union",183,8],["ref",204],["array",185],["object",[[106,184,!1],[107,186,!1]]],["ref",7],["union",188,8],["ref",167],["array",190],["ref",203],["array",192],["object",[[108,189,!1],[5,11,!1],[32,0,!0],[109,191,!1],[110,193,!1]]],["object",[[32,0,!0]]],["object",[[111,0,!0]]],["ref",55],["array",197],["object",[[42,61,!1],[112,61,!1],[113,83,!1],[32,0,!0],[114,198,!1]]],["object",[[32,0,!0],[40,82,!0]]],["ref",54],["array",201],["object",[[42,61,!1],[112,61,!1],[32,0,!0],[87,83,!1],[88,202,!1]]],["object",[[46,0,!0],[57,130,!1]]],["integer",0,4294967295],["object",[[42,61,!1],[77,61,!1],[43,88,!1],[115,205,!1],[116,63,!1],[112,61,!1],[32,0,!0],[63,151,!1],[47,98,!1]]],["object",[[2,3,!0],[117,63,!0],[3,5,!1]]],["object",[[69,135,!1],[118,0,!0],[70,137,!1],[71,137,!1],[72,137,!1]]],["object",[[61,1,!0]]],["ref",43],["array",210],["union",211,8],["ref",202],["array",213],["ref",61],["array",215],["ref",166],["array",217],["object",[[75,143,!1],[5,11,!1],[119,212,!1],[120,214,!1],[42,61,!1],[77,61,!1],[9,19,!1],[121,216,!1],[10,21,!1],[122,63,!0],[32,0,!0],[123,218,!1],[110,193,!1]]],["ref",62,200,201],["array",220],["object",[[124,221,!1],[43,87,!0],[125,63,!0],[100,61,!1],[32,0,!0],[126,114,!1]]],["object",[[127,0,!0]]],["object",[[128,61,!1],[59,61,!1],[104,61,!1],[0,0,!0]]],["object",[[129,61,!1],[130,0,!0]]],["ref",65],["array",226],["ref",66,67],["union",228,8],["object",[[5,11,!1],[131,227,!1],[132,0,!0],[32,0,!0],[133,180,!1],[134,229,!1],[110,193,!1]]],["ref",56],["array",231],["ref",37,60],["union",233,8],["object",[[135,232,!1],[57,234,!1],[3,5,!1],[136,130,!1]]],["union",140,8],["ref",71],["union",237,8],["object",[[73,236,!1],[43,88,!1],[137,238,!1]]],["ref",72],["array",240],["object",[[138,241,!1]]],["object",[[139,0,!0]]],["object",[[42,61,!1],[32,0,!0]]],["ref",75],["union",245,8],["object",[[140,246,!1],[42,61,!1],[141,246,!1],[142,151,!1],[32,0,!0],[143,0,!0]]],["object",[[73,236,!1],[42,61,!1],[43,88,!1],[137,238,!1]]],["object",[[42,61,!1],[132,130,!1],[144,95,!1],[32,0,!0],[40,0,!0],[95,95,!1]]],["object",[[145,0,!0]]],["object",[[145,0,!0],[95,95,!1]]],["object",[[146,0,!0]]],["object",[[147,0,!0],[32,0,!0]]],["ref",3,15,51,84],["object",[[148,137,!1],[149,61,!1],[150,254,!0]]],["enum","Seconds","Minutes","Hours","Days"],["object",[[151,57,!0],[152,256,!0]]],["ref",87],["array",258],["object",[[118,0,!0],[3,95,!1],[153,259,!1]]],["object",[[154,63,!0],[155,61,!1],[79,149,!1],[156,0,!0]]],["object",[[2,3,!0],[46,0,!0],[3,5,!1]]],["ref",88],["array",263],["object",[[135,264,!1],[157,0,!0],[0,0,!0]]],["object",[[61,1,!0],[0,0,!0]]],["array",1],["object",[[158,267,!1]]],["union",0,63,8],["number",-17976931348623157e292,17976931348623157e292],["enum","Int32","Int64","Decimal","Single"],["string","^-?[0-9]+(\\.[0-9]+)?([Ee][+-]?[0-9]+)?$"],["object",[[159,271,!0],[1,272,!0]]],["const","ExactNumber"],["string","^(?:0|-?(?:[1-9][0-9]{0,28}|(?:0|[1-9][0-9]{0,28})\\.[0-9]{0,27}[1-9]))$"],["object",[[159,274,!0],[1,275,!0]]],["union",269,270,273,276],["object",[[1,277,!1]]],["ref",36,94],["enum","And","Or"],["object",[[89,279,!0],[90,280,!0],[91,279,!0]]],["ref",8,28,95,102,140],["object",[[89,282,!0],[90,280,!0],[91,282,!0]]],["object",[[89,79,!0],[90,280,!0],[91,79,!0]]],["ref",47],["array",285],["union",286,8],["ref",68],["array",288],["union",289,8],["ref",158],["array",291],["object",[[75,143,!1],[5,11,!1],[119,212,!1],[120,214,!1],[42,61,!1],[160,287,!1],[77,61,!1],[9,19,!1],[121,216,!1],[10,21,!1],[161,290,!1],[122,63,!0],[32,0,!0],[162,292,!1],[110,193,!1]]],["object",[[69,135,!1],[70,137,!1],[71,137,!1],[72,137,!1],[163,0,!0]]],["object",[[2,3,!0],[65,128,!1],[0,0,!0]]],["object",[[164,282,!0]]],["enum","Info","Warning","Error","Unknown"],["object",[[69,135,!1],[165,297,!0],[100,0,!0],[101,63,!0],[70,137,!1],[71,137,!1],[72,137,!1]]],["object",[[69,135,!1],[166,0,!0],[70,137,!1],[71,137,!1],[72,137,!1]]],["ref",106],["array",300],["object",[[167,301,!1]]],["object",[[32,0,!0],[1,1,!0]]],["object",[[73,236,!1],[43,88,!1]]],["object",[[42,61,!1],[32,0,!0],[15,114,!1]]],["object",[[168,63,!1],[169,61,!1],[170,61,!1],[171,0,!0],[172,58,!1],[173,58,!1]]],["union",282,8],["object",[[73,236,!1],[149,307,!1],[43,88,!1],[32,0,!0]]],["ref",57],["union",309,8],["ref",74],["union",311,8],["union",279,8],["object",[[46,0,!0],[132,130,!1],[174,310,!1],[175,312,!1],[3,95,!1],[47,98,!1],[48,313,!1]]],["object",[[2,3,!0],[65,128,!1],[43,88,!1],[57,234,!1],[32,0,!0],[176,61,!1],[177,61,!1],[17,38,!1]]],["ref",114],["array",316],["object",[[65,128,!1],[178,317,!1],[32,0,!0]]],["object",[[0,0,!0],[52,1,!0]]],["object",[[179,63,!1],[180,63,!1],[32,0,!0],[40,82,!0]]],["ref",119],["object",[[32,0,!0],[52,321,!0],[40,83,!1]]],["object",[[52,321,!0]]],["ref",120],["array",324],["object",[[131,325,!1]]],["object",[[1,1,!0]]],["object",[[131,95,!1]]],["object",[[32,0,!0],[52,130,!1],[40,82,!0]]],["ref",125],["union",330,8],["array",330],["ref",108],["union",333,8],["object",[[75,143,!1],[129,331,!1],[42,61,!1],[181,332,!1],[182,63,!1],[32,0,!0],[183,334,!1],[184,82,!0],[185,61,!1]]],["object",[[69,135,!1],[70,137,!1],[71,137,!1],[72,137,!1],[150,0,!0]]],["ref",130],["array",337],["object",[[42,61,!1],[77,61,!1],[32,0,!0],[21,338,!1],[186,313,!1]]],["ref",195],["array",340],["ref",86],["array",342],["union",343,8],["union",149,8],["ref",85,98,141],["object",[[73,236,!1],[187,341,!1],[42,61,!1],[43,88,!1],[188,344,!1],[79,345,!1],[80,154,!1],[52,346,!0]]],["object",[[189,0,!0]]],["object",[[42,61,!1],[77,61,!1],[43,88,!1],[32,0,!0],[63,151,!1]]],["object",[[37,61,!1],[129,61,!1],[176,0,!0]]],["object",[[73,236,!1],[42,61,!1],[46,0,!0],[43,88,!1]]],["ref",134],["array",352],["object",[[42,61,!1],[32,0,!0],[176,0,!0],[107,353,!1]]],["object",[[69,135,!1],[70,137,!1],[71,137,!1],[72,137,!1],[130,0,!0]]],["object",[[46,0,!0],[57,130,!1],[136,130,!1]]],["enum","Error","Information","Warning"],["object",[[149,279,!0],[100,61,!1],[190,357,!0]]],["object",[[191,0,!0]]],["enum","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],["union",360,8],["string","^([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](\\.[0-9]{1,7})?$"],["object",[[192,58,!1],[193,361,!1],[194,362,!0]]],["object",[[118,0,!0],[104,61,!1],[105,180,!1]]],["ref",144],["array",365],["ref",145],["union",367,8],["object",[[195,366,!1],[104,0,!0],[105,180,!1],[196,368,!1]]],["object",[[69,135,!1],[118,0,!0],[149,279,!0]]],["enum","Hidden","Execute","Unknown"],["object",[[69,135,!1],[118,61,!1],[197,371,!0]]],["object",[[198,10,!0]]],["object",[[104,61,!1],[0,0,!0]]],["object",[[129,61,!1],[130,0,!0],[40,82,!0]]],["object",[[104,0,!0],[0,0,!0]]],["object",[[129,61,!1],[163,0,!0]]],["ref",142,143,146,147,149,151,152,153,154,156,157,159,160],["array",378],["object",[[199,379,!1],[32,0,!0]]],["ref",150],["array",381],["object",[[131,382,!1],[200,0,!0]]],["object",[[199,379,!1],[43,88,!1],[32,0,!0]]],["ref",148],["array",385],["object",[[5,11,!1],[201,386,!1],[202,180,!1],[200,0,!0],[110,193,!1]]],["ref",153],["array",388],["object",[[32,0,!0],[109,389,!1]]],["object",[[108,189,!1],[5,11,!1],[203,61,!1],[32,0,!0],[109,191,!1],[110,193,!1]]],["object",[[143,192,!0]]],["object",[[46,0,!0],[63,95,!1]]],["ref",161],["array",394],["object",[[204,0,!0],[135,395,!1]]],["ref",162],["array",397],["object",[[205,398,!1]]],["object",[[69,135,!1],[70,137,!1],[71,137,!1],[72,137,!1],[200,0,!0],[1,0,!0]]],["ref",23],["array",401],["ref",34],["array",403],["array",309],["array",311],["ref",115],["array",407],["ref",126],["array",409],["ref",129],["array",411],["ref",132],["array",413],["union",414,8],["ref",135],["array",416],["union",417,8],["ref",155],["array",419],["ref",185],["array",421],["enum","StateChange","StateView","Automation","Translate"],["object",[[206,402,!1],[207,404,!1],[208,221,!1],[42,61,!1],[77,61,!1],[135,405,!1],[9,19,!1],[43,88,!1],[32,0,!0],[209,406,!1],[210,408,!1],[211,410,!1],[212,412,!1],[213,415,!1],[214,418,!1],[215,420,!1],[216,422,!1],[40,423,!0]]],["object",[[217,61,!1],[32,0,!0]]],["object",[[57,1,!0],[32,0,!0]]],["object",[[40,0,!0],[1,0,!0]]],["ref",170],["array",428],["object",[[218,63,!0],[219,429,!1],[220,114,!1]]],["object",[[221,0,!0],[222,95,!1]]],["object",[[223,0,!0]]],["object",[[224,0,!0],[132,130,!1],[144,95,!1],[225,61,!1],[95,95,!1]]],["object",[[32,61,!1]]],["ref",180],["union",435,8],["ref",179],["union",437,8],["object",[[226,0,!0],[132,130,!1],[225,61,!1],[227,436,!1],[82,438,!1],[95,95,!1]]],["object",[[85,0,!0],[82,0,!0],[87,164,!1],[88,95,!1]]],["object",[[228,63,!0],[63,95,!1]]],["ref",181],["array",442],["object",[[69,95,!1],[228,63,!0],[130,0,!0],[229,443,!1]]],["object",[[228,63,!0],[225,61,!1],[32,0,!0],[63,95,!1]]],["object",[[226,0,!0],[132,130,!1],[230,0,!0],[95,95,!1]]],["ref",177],["array",447],["ref",171],["union",449,8],["ref",172],["array",451],["ref",173],["union",453,8],["ref",77],["array",455],["ref",183],["array",457],["union",458,8],["ref",169],["array",460],["ref",79],["array",462],["ref",175],["union",464,8],["ref",176],["array",466],["ref",178],["union",468,8],["ref",78],["array",470],["ref",182],["array",472],["ref",123,124],["union",474,8],["ref",174],["union",476,8],["union",447,8],["union",451,8],["ref",187],["union",480,8],["ref",184],["union",482,8],["ref",186],["union",484,8],["object",[[42,61,!1],[9,19,!1],[43,88,!1],[231,448,!1],[232,450,!1],[233,452,!1],[234,454,!1],[235,456,!1],[236,459,!1],[32,0,!0],[17,38,!1],[237,461,!1],[238,463,!1],[239,465,!1],[240,467,!1],[241,448,!1],[242,63,!0],[243,63,!1],[244,469,!1],[245,471,!1],[246,473,!1],[247,459,!1],[248,443,!1],[249,475,!1],[48,477,!1],[250,478,!1],[251,479,!1],[252,454,!1],[253,481,!1],[254,483,!1],[255,485,!1]]],["object",[[150,0,!0],[95,95,!1]]],["object",[[69,95,!1],[130,0,!0]]],["object",[[57,0,!0]]],["ref",192,193],["array",490],["object",[[92,491,!1]]],["object",[[256,114,!1],[32,0,!0]]],["object",[[187,341,!1],[42,61,!1],[43,88,!1],[32,0,!0]]],["object",[[257,63,!0],[258,63,!0],[32,0,!0]]],["object",[[42,61,!1],[43,88,!1],[32,0,!0],[63,151,!1]]],["object",[[259,61,!1],[260,61,!1],[32,0,!0],[261,114,!1],[262,114,!1],[263,61,!1]]],["object",[[124,221,!1],[46,0,!0],[125,63,!0],[100,61,!1],[32,0,!0],[126,114,!1]]],["object",[[264,114,!1],[124,221,!1],[46,0,!0],[125,63,!0],[100,61,!1],[32,0,!0],[0,0,!0],[126,114,!1]]],["object",[[200,0,!0]]],["ref",12],["array",501],["object",[[69,502,!1],[198,0,!0]]],["enum","NotEmpty","Max","Min","GreaterThan","GreaterThanOrEqual","LessThan","LessThanOrEqual","Equal","Length","Matches","AllGreaterThan","AllGreaterThanOrEqual","Rule","NotEqual"],["object",[[73,236,!1],[43,88,!1],[137,238,!1],[100,61,!1],[0,0,!0],[265,504,!0],[190,357,!0],[1,130,!1]]],["ref",110],["array",506],["object",[[28,0,!0],[266,507,!1],[30,0,!0]]]],contracts:[2,6,53,54,60,62,64,73,74,75,78,80,81,84,91,93,101,106,109,110,81,113,115,122,123,125,126,129,131,132,133,138,139,141,162,165,167,170,171,175,176,177,178,181,132,187,132,194,195,195,178,196,74,199,200,203,204,206,207,208,209,219,222,223,178,224,74,225,230,235,239,242,243,244,247,248,249,250,251,250,252,132,253,255,257,257,260,261,262,265,266,194,268,278,281,283,284,293,195,294,138,295,296,298,299,302,303,178,304,305,306,195,308,314,204,315,318,319,320,132,322,323,326,327,328,329,335,336,243,339,347,348,349,350,351,354,355,204,356,358,359,363,364,369,370,372,373,141,374,375,376,377,380,380,383,384,387,390,391,243,392,393,396,399,319,400,424,425,178,426,427,430,431,432,433,74,434,439,74,440,74,441,444,445,446,486,487,488,489,2,327,492,209,243,493,84,494,495,496,497,498,499,500,503,505,508]};var xr=Ve.rules,Hp=new Map(xr.flatMap(([t,e],n)=>t==="string"&&typeof e=="string"?[[n,new RegExp(e,"u")]]:[])),Ea=new Map(Ve.kinds.map((t,e)=>[t,xr[Ve.contracts[e]][1]])),Xp=new Map([...Ea].map(([t,e])=>[t,new Set(["kind",...e.map(([n])=>Ve.names[n])])])),ba=l(t=>typeof t=="object"&&t!==null&&!Array.isArray(t),"object");function vr(t){let e=Ea.get(t.kind);if(!Object.hasOwn(t,"kind")||e===void 0||!Ca(t,e))throw new ie(`Invalid typed members for syntax kind '${t.kind}'.`)}l(vr,"validateSyntaxMembers");function Xn(t,e){let n=ei(t.kind);for(let i of Object.keys(t))if(!n.has(i)&&!e.has(i))throw new ie(`Unknown member '${i}' for syntax kind '${t.kind}'.`)}l(Xn,"validateClosedSyntaxMembers");function ei(t){let e=Xp.get(t);if(e===void 0)throw new ie(`Unknown syntax kind '${t}'.`);return e}l(ei,"syntaxMemberNames");function Ca(t,e){return e.every(([n,i,r])=>Object.hasOwn(t,Ve.names[n])?$r(t[Ve.names[n]],i):!r)}l(Ca,"matchesMembers");function ef(t,e){for(let n=0;n<t.length;n++)if(!Object.hasOwn(t,n)||!$r(t[n],e))return!1;return!0}l(ef,"allIndicesMatch");function $r(t,e){let[n,...i]=xr[e];switch(n){case"ref":return ba(t)&&typeof t.kind=="string"&&i.some(r=>Ve.kinds[r]===t.kind);case"union":case"one":{let r=i.reduce((o,s)=>o+($r(t,s)?1:0),0);return n==="one"?r===1:r>0}case"const":return t===i[0];case"enum":return i.includes(t);case"null":return t===null;case"array":return Array.isArray(t)&&ef(t,i[0]);case"object":return ba(t)&&Object.keys(t).every(r=>i[0].some(([o])=>Ve.names[o]===r))&&Ca(t,i[0]);case"integer":case"number":return typeof t=="number"&&Number.isFinite(t)&&(n!=="integer"||Number.isInteger(t))&&(i.length===0||t>=i[0]&&t<=i[1]&&!(n==="integer"&&i[0]===0&&Object.is(t,-0)));case"string":return typeof t=="string"&&(i.length===0||Hp.get(e).test(t));default:return n==="boolean"&&typeof t=="boolean"}}l($r,"matches");var tf=Object.fromEntries("ApplicationSyntax:policies,seeds;ConceptSyntax:validations;DeclarativeValidateSyntax:requirements;CodeValidateSyntax:code;CaptureAppendSyntax:when,mappings,tags;CaptureChildrenSyntax:map;CaptureNestedSyntax:map;CaptureSyntax:map;EventSpecSyntax:key;FromSyntax:key,parentKey;ChildrenSyntax:identifiedBy;RemoveWithSyntax:key,parentKey;RemoveViaJoinSyntax:key;ProjectionEntersOnSyntax:key;ProjectionSyntax:key;QueryParameterSyntax:source;ProducesSyntax:when;InvokesSyntax:mappings;ReactionSyntax:where;SpecificationSyntax:thenAbsentReadModels,thenQueries".split(";").map(t=>t.split(":")).map(([t,e])=>[t,new Set(e.split(","))])),nf=/^(?:Set|Clear|Increment|Decrement|Count|Add|Subtract)MappingSyntax$/;function rf(t,e){return tf[t]?.has(e)===!0||nf.test(t)&&(e==="source"||e==="value")}l(rf,"isExactOnlyMember");function Pa(t,e){return t.kind==="SpecificationSyntax"&&e==="givenCaller"?t.givenCaller==null:rf(t.kind,e)||t.kind==="ValidationRuleSyntax"&&t.implementation==null&&(e==="code"||e==="file"||e==="implementation")}l(Pa,"isLegacyOmittedMember");var ni=l(t=>typeof t=="object"&&t!==null&&typeof t.kind=="string","isNode"),ti=new Set(["kind","location","targetLocation","referenceLocation","referenceLength","nameWasEscaped","declaredTriggers","directiveLocations"]),ii=new Set(["ApplicationSyntax","ProjectionSyntax","CaptureSyntax","SpecificationSyntax"]);function oi(t){let e=of(t);return kr(e,"legacy",0),ri(e)}l(oi,"toSyntaxJson");function of(t){let e=new WeakMap,n=[];function i(o){if(typeof o!="object"||o===null)return o;if(e.has(o))return e.get(o);if(Array.isArray(o)){let c=Aa();e.set(o,c);let d=o.length;for(let m=d-1;m>=0;m--)n.push(()=>{c[m]=i(Object.hasOwn(o,m)?o[m]:void 0)});return c}let s=Object.create(null);e.set(o,s);let a=Object.keys(o);!a.includes("kind")&&"kind"in o&&a.unshift("kind");for(let c=a.length-1;c>=0;c--)n.push(()=>{let d=a[c],m=o[d];d==="sourceOptions"&&n.push(()=>{typeof m=="object"&&m!==null&&(Object.getPrototypeOf(m)!==Object.prototype&&Object.getPrototypeOf(m)!==null||Reflect.ownKeys(m).length!==Object.keys(m).length)&&(s[d]=Object.assign(Object.create(null),{numericMode:"invalid"}))}),s[d]=i(m)});return s}l(i,"detach");let r=i(t);for(;n.length>0;)n.pop()();return r}l(of,"snapshot");function Aa(){let t=[];return Object.defineProperty(t,"toJSON",{value:void 0}),t}l(Aa,"dataArray");function ri(t,e="legacy",n=!1){if(Array.isArray(t)){let o=Aa();for(let s=0;s<t.length;s++)o.push(ri(t[s],e,n));return o}if(ni(t)){if(ii.has(t.kind)&&(e=vt(t.sourceOptions??ke).numericMode),At(t),(t.kind==="ImplementationSyntax"||t.kind==="ImplementationHintSyntax")&&Xn(t,ti),t.kind==="ValidationRuleSyntax"){let d=t;d.implementation!=null&&(d.file!=null&&Xn(d.file,ti),d.code!=null&&Xn(d.code,ti))}let o=Object.create(null);o.kind=t.kind;let s={...t};t.kind==="ApplicationSyntax"&&s.eventSources===void 0&&(s.eventSources=[]),t.kind==="CommandSyntax"&&s.stream===void 0&&(s.stream=null),t.kind==="CommandSyntax"&&s.streamCandidates===void 0&&(s.streamCandidates=[]);let a=e==="exact"?ei(t.kind):void 0,c=Object.keys(s).filter(d=>(a===void 0||a.has(d))&&!(e==="legacy"&&!n&&Pa(t,d))&&!ti.has(d)&&!(t.kind==="OperationSyntax"&&d==="usesLocation")).sort(af);for(let d of c){let m=s[d];d==="documentation"&&t.kind!=="EventSyntax"&&m==null||t.kind==="SpecificationSyntax"&&d==="description"&&m==null||d==="dependsOn"&&(t.kind==="ModuleSyntax"||t.kind==="FeatureSyntax")&&Array.isArray(m)&&m.length===0||d==="sourceOptions"&&m?.numericMode==="legacy"||d==="examples"&&Array.isArray(m)&&m.length===0||d==="inlineProperty"&&m==null||t.kind==="SpecificationSyntax"&&d==="thenNoEvents"&&m===!1||t.kind==="SpecificationSyntax"&&d==="whenRedelivered"&&m==null||t.kind==="InvokesSyntax"&&d==="onRefused"&&Array.isArray(m)&&m.length===0||(o[d]=ri(m,e,n))}return o}if(t===void 0)return null;if(typeof t!="object"||t===null)return t;let i=t,r=Object.create(null);if(i.literalType==="ExactNumber")return r.literalType="ExactNumber",r.value=i.value,r;for(let o of Object.keys(i))o!=="toJSON"&&i[o]!==void 0&&(r[o]=ri(i[o],e,n));return r}l(ri,"write");function kr(t,e,n){if(n>96&&e==="exact")throw new ie("Syntax nesting exceeds the supported depth of 96.");if(Array.isArray(t)){for(let o=0;o<t.length;o++)kr(t[o],e,n+1);return}if(typeof t!="object"||t===null)return;let i=t;if(ii.has(i.kind)||Object.hasOwn(i,"sourceOptions")){let o=Object.hasOwn(i,"sourceOptions")?vt(i.sourceOptions):ke;if(n>0&&e!==o.numericMode)throw new ie("Conflicting source numeric options.");e=o.numericMode}if(n===0&&e==="exact"&&!ii.has(i.kind))throw new ie("Exact syntax requires a complete source root.");if(e==="exact"&&ni(i)&&vr(i),i.kind==="RawExpressionSyntax"&&e==="exact"&&typeof i.text=="string"&&Mt(i.text))throw new ie("An exact numeric operand must be an explicit ExactNumber, not opaque numeric text.");if(i.kind==="LiteralExpressionSyntax"&&Object.hasOwn(i,"value")){if(e==="exact"&&(typeof i.value=="number"||i.value!==null&&!["string","boolean","object"].includes(typeof i.value)))throw new ie("Exact source requires supported primitive values or an explicit ExactNumber literal.");if(typeof i.value=="object"&&i.value!==null){let o=i.value;if(o.literalType==="ExactNumber"){if(e!=="exact"||typeof o.value!="string"||qe(o.value)?.value!==o.value||Object.keys(o).length!==2)throw new ie("Malformed or incompatible ExactNumber literal.")}else if(e==="exact")throw new ie("Exact source refuses old or plain object literal insertion.")}}let r=e==="exact"&&ni(i)?ei(i.kind):void 0;for(let[o,s]of Object.entries(i))(r===void 0||r.has(o)||ni(s)&&ii.has(s.kind))&&o!=="location"&&o!=="targetLocation"&&o!=="usesLocation"&&kr(s,e,n+1)}l(kr,"validateNumbers");function af(t,e){return t<e?-1:t>e?1:0}l(af,"ordinal");function wa(t){let e=[],n=t.map(x=>x.value),i=new Map,r=!1;for(let x of n)try{i.set(x,Object.hasOwn(x,"sourceOptions")?vt(x.sourceOptions):ke)}catch($){if(!($ instanceof ie))throw $;r=!0,e.push(si(p.IncompatibleNumericSource,$.message,x.location))}let o=n.filter(x=>i.get(x)?.numericMode==="exact"||sf(x)),s=i.get(o[0])??ke;for(let x of o.slice(1))i.get(x)?.numericMode!==s.numericMode&&(r=!0,e.push(si(p.MixedNumericModes,"Declaration-bearing documents and marked import barrels must independently select the same numeric mode.",x.location)));r&&(s=mo);let a=new Map,c=ai(n.flatMap(x=>x.concepts),"declaration of",e,void 0,a),d=ai(n.flatMap(x=>x.types),"declaration of",e,void 0,a),m=n.map(x=>x.domain).filter(x=>x!==null);for(let x of m.slice(1))e.push(si(p.RepeatedSingularDeclarationAcrossFiles,`The folder already declares a domain in '${en(m[0].location.path)}' - a folder compiles to one application, which can have at most one`,x.location));let u=lf(n.flatMap(x=>x.modules),e),y=ai(n.flatMap(x=>x.personas),"persona",e),h={kind:"ApplicationSyntax",sourceOptions:s,domain:m[0]??null,imports:cf(n.flatMap(x=>x.imports),x=>x.qualifiedName),concepts:c,types:d,examples:n.flatMap(x=>x.examples??[]),systems:n.flatMap(x=>x.systems??[]),eventSources:n.flatMap(x=>x.eventSources??[]),declaredTriggers:n.flatMap(x=>x.declaredTriggers??[]),modules:u,personas:y,policies:n.flatMap(x=>x.policies??[]),seeds:n.flatMap(x=>x.seeds??[]),fileImports:n.flatMap(x=>x.fileImports),location:n[0]?.location??{line:1,column:1}},v=[...t.flatMap(x=>x.diagnostics),...e];return{value:h,diagnostics:v,success:!v.some(x=>x.severity==="error")}}l(wa,"mergeDocuments");function sf(t){if(So(t)||t.domain!==null||t.concepts.length>0||t.types.length>0||t.personas.length>0||(t.policies?.length??0)>0||(t.seeds?.length??0)>0||(t.systems?.length??0)>0||(t.eventSources?.length??0)>0||(t.examples?.length??0)>0)return!0;let e=l(n=>!n.isPlacement||(n.examples?.length??0)>0||n.slices.length>0||n.features.some(e),"feature");return t.modules.some(n=>!n.isPlacement||(n.examples?.length??0)>0||n.features.some(e))}l(sf,"hasDeclarations");function lf(t,e){return Da(t).map(Ta).map(n=>n.length===1?{...n[0],isPlacement:!1,features:n[0].features.map(br)}:{...n[0],isPlacement:!1,fileImports:n.flatMap(i=>i.fileImports),examples:n.flatMap(i=>i.examples??[]),description:Na(n,`module '${n[0].name}'`,e),documentation:Ma(n,`module '${n[0].name}'`,e),authorize:Ra(n.map(i=>i.authorize),`module '${n[0].name}'`,e),dependsOn:Ia(n),features:Oa(n.flatMap(i=>i.features),e)})}l(lf,"mergeModules");function Oa(t,e){return Da(t).map(Ta).map(n=>n.length===1?br(n[0]):{...n[0],isPlacement:!1,fileImports:n.flatMap(i=>i.fileImports),examples:n.flatMap(i=>i.examples??[]),description:Na(n,`feature '${n[0].name}'`,e),documentation:Ma(n,`feature '${n[0].name}'`,e),authorize:Ra(n.map(i=>i.authorize),`feature '${n[0].name}'`,e),dependsOn:Ia(n),features:Oa(n.flatMap(i=>i.features),e),slices:ai(n.flatMap(i=>i.slices),"slice",e,`feature '${n[0].name}'`)})}l(Oa,"mergeFeatures");function Ia(t){return[...t].sort((e,n)=>(e.location.path??"")<(n.location.path??"")?-1:(e.location.path??"")>(n.location.path??"")?1:0).flatMap(e=>e.dependsOn??[])}l(Ia,"groupDependencies");function Ta(t){return[...t.filter(e=>!e.isPlacement),...t.filter(e=>e.isPlacement)]}l(Ta,"placedLast");function br(t){return{...t,isPlacement:!1,features:t.features.map(br)}}l(br,"unplaced");function Ra(t,e,n){let i=[];for(let r of t.filter(o=>o!==null)){let o=i.find(s=>s.location.path!==r.location.path&&JSON.stringify(oi(s))===JSON.stringify(oi(r)));if(o!==void 0){n.push(Er(p.DuplicateAuthorizationAcrossFiles,`An identical authorization is already declared on the ${e} in '${en(o.location.path)}' - this repeated gate is ignored`,r.location));continue}i.push(r)}return i.reduce((r,o)=>Re(r,o),null)}l(Ra,"combineAuthorization");function cf(t,e){let n=new Set;return t.filter(i=>!n.has(e(i))&&n.add(e(i))!==void 0)}l(cf,"firstOfEach");function Da(t){let e=new Map;for(let n of t)e.set(n.name,[...e.get(n.name)??[],n]);return[...e.values()]}l(Da,"groupByName");function Ma(t,e,n){let i=t.filter(r=>r.documentation!=null);for(let r of i.slice(1).filter(o=>o.documentation!==i[0].documentation))n.push(Er(p.ConflictingDocumentationAcrossFiles,`The ${e} is already documented in '${en(i[0].location.path)}' - keeping that documentation`,r.location));return i[0]?.documentation??null}l(Ma,"firstDocumentation");function Na(t,e,n){let i=t.filter(r=>r.description!==null);for(let r of i.slice(1).filter(o=>o.description!==i[0].description))n.push(Er(p.ConflictingDescriptionAcrossFiles,`The ${e} is already described in '${en(i[0].location.path)}' - keeping that description`,r.location));return i[0]?.description??null}l(Na,"firstDescription");function ai(t,e,n,i,r=new Map){let o=[];for(let s of t){let a=r.get(s.name);if(a!==void 0&&a.path!==s.location.path){n.push(si(p.RepeatedDeclarationAcrossFiles,`Duplicate ${e} '${s.name}'${i===void 0?"":` in ${i}`} - already declared in '${en(a.path)}'`,s.location));continue}a===void 0&&r.set(s.name,s.location),o.push(s)}return o}l(ai,"declaredInOneFile");var en=l(t=>t??"another file","describe"),si=l((t,e,n)=>({severity:"error",code:t,message:e,location:n}),"error"),Er=l((t,e,n)=>({severity:"warning",code:t,message:e,location:n}),"warning");function La(t,e){return ff(t,e).result}l(La,"parsePlacedDocuments");function ff(t,e){let n=Ct.capturePlaced(t.filter(h=>h.isPlacementResolved!==!1).map(h=>({lines:ut(h.source,!1,h.path),placement:h.placement})),e),i=t.map(h=>We(h.source,h.path,h.isPlacementResolved===!1?[]:h.placement,!1,n,e)),r=i.flatMap((h,v)=>(h.value.eventSources??[]).map(x=>({source:x,placementResolved:t[v].isPlacementResolved!==!1}))),o=t.every(h=>h.isPlacementResolved!==!1)&&i.every(h=>!Pt.hasUnknownExtent(h.diagnostics)),s=i.map((h,v)=>t[v].isPlacementResolved===!1?{...h,value:{...h.value,eventSources:[]}}:h),a=wa(s),c=new Se(new ct([]),void 0,e);a.value.sourceOptions!==void 0&&(c.sourceOptions=a.value.sourceOptions),zn(a.value,c),Yn(a.value,c),Fn(a.value,c),dn(a.value,c),qn(a.value,c,s.flatMap(h=>h.inputUses)),Vn(a.value,c),Qn(a.value,c),Kn(a.value,c),Jn(a.value,c),Hn(a.value,c);let d=fn(a.value,c);Et.validate(d,c);for(let h of cn(d))c.information(h.code,h.message,h.location);let m=a.diagnostics,u=new Set(m.map(ja)),y=[...m,...c.diagnostics.filter(h=>!u.has(ja(h)))];return{result:{...a,value:d,diagnostics:y,success:!y.some(h=>h.severity==="error"),physicalEventSources:r,sourceInventoryComplete:o},syntax:new Map(s.map((h,v)=>[t[v].path,h.value]))}}l(ff,"parsePlacedDocumentsWithSyntax");function ja(t){return JSON.stringify([t.code,t.location.path,t.location.line,t.location.column])}l(ja,"diagnosticKey");var qa=/[\p{L}\p{Mn}\p{Nd}\p{Pc}]/u,Ba=l(t=>`\\u${t.toString(16).padStart(4,"0")}`,"escape");function uf(){let t="";for(let e=0;e<=65535;e++){if(!qa.test(String.fromCharCode(e)))continue;let n=e;for(;e<65535&&qa.test(String.fromCharCode(e+1));)e++;t+=Ba(n)+(e>n?`-${Ba(e)}`:"")}return t}l(uf,"ranges");var li=uf();var mf=new RegExp(`^\\s*example\\s+[A-Z][${li}]*\\s*:\\s*([${li}.]*)$`),yf=new RegExp(`^\\s*(given|when|then)\\s+(?:(readmodel|append)\\s+)?([${li}.]*)$`);function Fa(t,e,n,i,r,o){let s=t,a=[],c=o.some(g=>g.severity==="error")?o.some(g=>g.code==="PLAY0519")?"**Invalid duplicate assignments; no effective values selected.**":"**Invalid source; no effective values selected.**":null,d=new Map,m=[],u=l((g,S)=>{if(g.location.path===e&&g.location.line>0)for(let k of i(g.location.line-1))d.set(k,S)},"own"),y=l((g,S)=>{for(let k of g??[])a.push({name:k.name,scope:S,example:k}),u(k,S)},"examples");y(s.examples,[]),a.push(...[...s.concepts,...s.types].map(g=>({name:g.name,scope:[]})));let h=l((g,S)=>{for(let k of g){let b=[...S,k.name];u(k,b),y(k.examples,b);for(let I of k.slices){let w=[...S,k.name,I.name];u(I,w),y(I.examples,w);let D=new Map;for(let N of se(I))D.set(N.name,[...D.get(N.name)??[],N]);for(let N of D.values()){let L=Math.max(...N.map(q=>q.generation));a.push(...N.filter(q=>q.generation===L).map(q=>({name:q.name,scope:w,fixtureKind:"event"})))}a.push(...I.commands.map(N=>({name:N.name,scope:w,fixtureKind:"command"})),...I.readModels.map(N=>({name:N.name,scope:w,fixtureKind:"readmodel"})));for(let N of I.specifications)m.push({node:N,scope:w}),u(N,w),y(N.examples,w)}h(k.features,b)}},"features");for(let g of s.modules)u(g,[g.name]),y(g.examples,[g.name]),h(g.features,[g.name]);let v=l((g,S)=>{let k=g.split("."),b=a.filter(w=>w.name===k.at(-1)),I=k.slice(0,-1);if(I.length)return b.filter(w=>I.length<=w.scope.length&&I.every((D,N)=>w.scope[w.scope.length-I.length+N]===D));for(let w=S.length;w>=0;w--){let D=b.filter(N=>w<=N.scope.length&&S.slice(0,w).every((L,q)=>N.scope[q]===L));if(D.length)return D}return[]},"candidates"),x=l((g,S)=>{let k=v(g,S);return k.length===1?k[0]:void 0},"unique"),$=l(g=>g.example?x(g.example.type,g.scope)?.fixtureKind:g.fixtureKind,"kind"),C=l(g=>[...g.scope.filter(S=>!r.has(S)),g.name].join("."),"display"),E=l((g,S,k=!1,b="")=>a.flatMap(I=>{let w=$(I);if(!w||S&&w!==S||k&&I.example)return[];let D=[...I.scope,I.name].join("."),N=x(I.name,g)===I?I.name:D;if(x(N,g)!==I)return[];let L=b.split(".").slice(0,-1).join(".");return L&&!D.endsWith(`${L}.${I.name}`)?[]:N===D&&I.scope.some(q=>r.has(q))&&x(I.name,g)!==I?[]:[{label:x(I.name,g)===I?I.name:C(I),insertText:L?I.name:N,documentation:I.example?`Example of ${I.example.type}. Step assignments override example values; no implicit defaults.`:`Declared ${w}.`}]}),"targets"),P=l((g,S,k,b)=>{if(c)return c;let I=l((L,q,j="")=>{if(new Set(L.map(U=>U.property)).size!==L.length||new Set(q.map(U=>U.property)).size!==q.length)return null;let F=new Map(L.map(U=>[U.property,{value:U,origin:"example",replaced:void 0}]));for(let U of q){let Y=F.get(U.property)?.value;F.delete(U.property),F.set(U.property,{value:U,origin:Y?"override":"authored",replaced:Y})}return[...F.values()].map(({value:U,origin:Y,replaced:Q})=>`${j}${U.property} = ${pt(U.source)} \u2014 ${Y}${Y==="example"?` ${g.name}`:""}${Q?` (replaces ${pt(Q.source)} from ${g.name})`:""}`)},"merge"),w=I(g?.values??[],S),D=I(g?.generatedValues??[],k,"generated ");if(!w||!D)return"**Invalid duplicate assignments; no effective values selected.**";let N=b??g?.for;return[...w,...D,...N?[`for ${pt(N)} \u2014 ${b?g?.for?`override (replaces ${pt(g.for)} from ${g.name})`:"authored":`example ${g.name}`}`]:[]].join(`
19
- `)},"effective"),A=new Map;for(let g of a.filter(S=>S.example?.location.path===e)){let S=g.example,k=S.location.line-1,b=Ee(n[k]??"").match(/^\s*example\s+/)?.[0];b&&A.set(k,{start:b.length+1,length:S.name.length,content:`**example ${C(g)} : ${S.type}**
20
-
21
- ${$(g)?P(S,[],[],null):"Unresolved or ambiguous type; no effective values selected."}`})}for(let{node:g,scope:S}of m){let k=[...g.given.map(b=>({step:b,name:b.eventType,expected:"event",values:b.values,generated:[],destination:b.for,prefix:/^\s*given\s+/})),...g.givenReadModels.map(b=>({step:b,name:b.name,expected:"readmodel",values:b.properties,generated:[],destination:null,prefix:/^\s*given\s+readmodel\s+/})),...g.when?[{step:g.when,name:g.when.commandType,expected:"command",values:g.when.values,generated:g.when.generatedValues??[],destination:g.when.for,prefix:/^\s*when\s+/}]:[],...g.whenAppended?[{step:g.whenAppended,name:g.whenAppended.eventType,expected:"event",values:g.whenAppended.values,generated:[],destination:g.whenAppended.for,prefix:/^\s*when\s+append\s+/}]:[],...g.thenEvents.map(b=>({step:b,name:b.eventType,expected:"event",values:b.values,generated:[],destination:b.for,prefix:/^\s*then\s+/})),...g.thenReadModels.map(b=>({step:b,name:b.name,expected:"readmodel",values:b.properties,generated:[],destination:null,prefix:/^\s*then\s+readmodel\s+/}))];for(let{step:b,name:I,expected:w,values:D,generated:N,destination:L,prefix:q}of k.filter(j=>j.step.location.path===e)){let j=x(I,S),F=v(I,S).some(oe=>oe.example);if(!j?.example&&(j||!F))continue;let U=b.location.line-1,Y=Ee(n[U]??"").match(q)?.[0].length;if(Y===void 0)continue;let Q=j?$(j)!==w?"**Example kind mismatch; no effective values selected.**":`**${w} ${j.example?.type??I}${j.example?` \u2014 example ${C(j)}`:""}**
22
-
23
- ${P(j.example,D,N,L)}
24
-
25
- Authored fixture values, not execution results. Matching is unchanged.`:"**Ambiguous example; no effective values selected.**";A.set(U,{start:Y+1,length:I.length,content:Q})}}return{completions(g,S){let k=d.get(g)??[],b=S.match(mf);if(b)return E(k,void 0,!0,b[1]);if(!m.some(({node:L})=>L.location.path===e&&i(L.location.line-1).includes(g)))return null;let w=S.match(yf);if(!w||["clock","caller","capture","trigger","query","result","error","denied","returns","no","operation","compensated"].includes(w[3]))return null;let D=w[2]==="readmodel"?"readmodel":w[2]==="append"||w[1]!=="when"?"event":"command",N=E(k,D,!1,w[3]);return N.length?w[2]?N:[...Lr[w[1]],...N]:null},hover(g,S,k){let b=A.get(g);return b&&S>=b.start&&k<=b.start+b.length?b.content:null}}}l(Fa,"exampleAnalysis");function pt(t){switch(t.kind){case"LiteralExpressionSyntax":return typeof t.value=="object"&&t.value!==null?t.value.value:JSON.stringify(t.value);case"ListExpressionSyntax":return`[${t.items.map(pt).join(", ")}]`;case"ObjectExpressionSyntax":return`{ ${t.members.map(e=>`${JSON.stringify(e.name)}: ${pt(e.value)}`).join(", ")} }`;case"RawExpressionSyntax":return t.text;case"PathExpressionSyntax":return t.path;case"ContextExpressionSyntax":return`$context.${t.path}`;case"EventContextExpressionSyntax":return`$eventContext.${t.path}`;case"RefusalExpressionSyntax":return`$refusal.${t.member}`;case"EventSourceIdExpressionSyntax":return"$eventSourceId";case"CausedByExpressionSyntax":return`$causedBy${t.property?`.${t.property}`:""}`;case"EnvironmentExpressionSyntax":return`$env.${t.name}`;case"StringsExpressionSyntax":return`$strings.${t.key}`;case"SourceItemExpressionSyntax":return`$.${t.path}`;case"TemplateExpressionSyntax":return"`"+t.parts.map(e=>e.kind==="TemplateTextSyntax"?e.text:"${"+pt(e.expression)+"}").join("")+"`"}}l(pt,"expressionText");function Ya(t,e,n,i,r){let o=t,s=e,a=he.containersOf(o).filter(u=>![...u.scope,u.name].some(y=>r.has(y))),c=new Map,d=new Map,m=l((u,y,h)=>{for(let v of u){let x=[...y,v.name];if(h){if(v.location.path===n&&v.location.line>0)for(let $ of i(v.location.line-1))c.set($,x)}else{let $=x.join(".");d.set($,[...d.get($)??[],...(v.dependsOn??[]).map(C=>({target:C.target,...C.location}))])}m(v.features,x,h)}},"inventory");return m(o.modules,[],!1),m(s.modules,[],!0),{completions(u,y,h){let v=c.get(u)??h;if(!v?.length||v.some($=>r.has($))||!a.some($=>[...$.scope,$.name].join(".")===v.join(".")))return[];let x=new Set((d.get(v.join("."))??[]).filter($=>$.path!==n||$.line!==u+1).map($=>he.resolve($.target,v,a).resolved));return he.candidates(v,a).flatMap(({container:$,reference:C,tier:E})=>{if(x.has($))return[];let P=[...$.scope,$.name].join(".");if(y&&(C=y+$.name,he.resolve(C,v,a).resolved!==$))return[];let A=$.scope.length===0?"module":E===0?"sibling feature":E!=="qualified"?`feature of ${$.scope.join(".")}`:`feature in ${$.scope.join(".")}`,g=a.indexOf($);return[{label:y?$.name:C,insertText:y?$.name:C,documentation:`${P} \u2014 ${A}.`,detail:A,sortText:`${String(E==="qualified"?v.length:E).padStart(6,"0")}:${String(g).padStart(6,"0")}`}]})}}}l(Ya,"dependencyTargetAnalysis");var XA="Executable as ESM v7. Generated values require fixtures in reference execution; other unadmitted constructs still prevent binding.",tn=new Map;function hf(t,e){let n=me(t),i=t.flatMap((u,y)=>!n[y]&&J(u)===0&&/^\w/.test(u)?[u.split(/\s+/)[0]]:[]);if(i.includes("module")||!i.some(u=>["feature","slice","command","event","operation","reaction","specification"].includes(u)))return{source:t.join(`
26
- `),locations:t.map((u,y)=>({line:y+1,column:0}))};let r=[],o=[],s=!1;t.forEach((u,y)=>{!n[y]&&J(u)===0&&/^\w/.test(u)&&(s=/^(?:concept|type|import|domain|system|eventsource)\b/.test(u)),(s?r:o).push(y)});let a=i.includes("feature")?1:i.includes("slice")?2:3,c=e.slice(0,a),d=[...r.map(u=>t[u]),...c,...o.map(u=>" ".repeat(a*2)+t[u])].join(`
27
- `),m=[...r.map(u=>({line:u+1,column:0})),...c.map(()=>({line:0,column:0})),...o.map(u=>({line:u+1,column:a*2}))];return{source:d,locations:m}}l(hf,"authoringSource");function Sf(t,e,n,i="current.play",r=!0){let o=e.map((T,M)=>typeof T=="string"?{path:`other-${M}.play`,source:T}:T).filter(T=>T.path!==i),s=[{path:i,source:t.join(`
28
- `),placement:n,isPlacementResolved:r},...o],a=new Set(s.flatMap(T=>[...T.source.matchAll(/\w+/g)].map(M=>M[0]).concat(T.placement??[]))),c=l(T=>{let M=T;for(let B=1;a.has(M);B++)M=`${T}${B}`;return a.add(M),M},"fresh"),d=c("EditorAuthoring"),m=c("FragmentFeature"),u=new Set([d,m]),y=s.map((T,M)=>{let B=M===0?t:T.source.split(`
29
- `),W=c(`Fragment${M}`);u.add(W);let Ge=T.placement?.length?{source:T.source,locations:B.map((ft,an)=>({line:an+1,column:0}))}:hf(B,[`module ${d}`,` feature ${m}`,` slice StateChange ${W}`]);return{...T,...Ge,placement:T.placement??[]}}),h=y[0],v=new Map(y.map(T=>[T.path,T.locations])),x=La([...y.slice(1),h]),$=new Map,C=new Map,E=new WeakSet,P=l(T=>{if(T===null||typeof T!="object"||E.has(T))return;if(E.add(T),Array.isArray(T)){T.forEach(P);return}let M=T;if(typeof M.path=="string"&&typeof M.line=="number"&&typeof M.column=="number"){let B=v.get(M.path)?.[M.line-1];B&&(M.line=B.line,M.column=Math.max(1,M.column-B.column));return}for(let B of Object.values(M))P(B);M.location?.path===i&&(M.kind==="CommandSyntax"&&$.set(M.location.line-1,T),M.kind==="SpecificationSyntax"&&C.set(M.location.line-1,T))},"walk");P(x.value),P(x.physicalEventSources);for(let T of x.diagnostics)P(T.location);let A=x.diagnostics.some(T=>{if(!["PLAY0022","PLAY0024","PLAY0029"].includes(T.code))return!1;let M=y.find(W=>W.path===T.location.path),B=s.find(W=>W.path===T.location.path)?.source.split(`
30
- `)[T.location.line-1];return M?.locations.some(W=>W.line===0)&&B!==void 0&&J(B)===0}),g=x.diagnostics.filter(T=>T.location.path===i).flatMap(T=>(P(T.location),T.location.line>0?[T]:[])),S=new re(x.value),k=new Set(S.slices.flatMap(({slice:T})=>[...T.commands.flatMap(M=>M.produces),...T.reactions.flatMap(M=>M.triggers).flatMap(M=>M.produces)].filter(M=>M.location.path===i&&!S.isEventProduction(M,T)).map(M=>M.location.line-1)));for(let T of g)T.code==="PLAY0499"&&k.add(T.location.line-1);let b=S.declarations.filter(T=>T.kind===ee.Operation).map(T=>({...T.node,scope:T.scope.filter(M=>!u.has(M))})),I=new Map,w=me(t),D=l(T=>{let M=[],B=J(t[T]);for(let W=T;W<t.length&&!(W>T&&!w[W]&&Ee(t[W]).trim()&&J(t[W])<=B);W++)M.push(W);return M},"range");for(let{slice:T,scope:M}of S.slices){if(T.location.path===i&&T.location.line>0)for(let B of D(T.location.line-1))I.set(B,{scope:M});for(let B of T.specifications.filter(W=>W.location.path===i&&W.location.line>0))for(let W of D(B.location.line-1))I.set(W,{scope:M});for(let B of T.commands.filter(W=>W.location.path===i&&W.location.line>0))for(let W of D(B.location.line-1))I.set(W,{scope:M,commandLine:B.location.line-1})}let N=new Map(S.declarations.map(T=>[T.node.location,T.scope]));for(let T of b.filter(M=>M.location.path===i)){let M=N.get(T.location);for(let B of D(T.location.line-1))I.set(B,{...I.get(B),scope:M,operation:T})}let L=new Map(b.map(T=>[T.location,T])),q=l((T,M)=>{let B=Ee(t[T.line-1]??""),W=B.slice(T.column-1).match(/^(?:given\s+operation|then\s+(?:operation|compensated))\s+/)?.[0];return W&&B.slice(T.column-1+W.length,T.column-1+W.length+M.length)===M?{...T,column:T.column+W.length}:T},"referenceLocation"),j=[];for(let{slice:T}of S.slices){for(let M of T.commands)for(let B of M.produces){if(B.location.path!==i)continue;let W=S.resolve(B.event,T),Ge=W.declaration?L.get(W.declaration.node.location)??null:null,ft={name:B.event,location:B.location,targetLocation:B.targetLocation??B.location,kind:W.kind,declaration:Ge,mappings:B.mappings};if(j.push(ft),W.kind===ee.Operation)for(let an of D(B.location.line-1)){let Rr=I.get(an);Rr&&I.set(an,{...Rr,production:ft})}}for(let M of T.specifications)for(let B of[...M.givenOperationFailures??[],...M.thenOperations??[],...M.thenCompensated??[]]){if(B.location.path!==i)continue;let W=S.resolve(B.operation,T);j.push({name:B.operation,location:B.location,targetLocation:q(B.location,B.operation),kind:W.kind,declaration:W.declaration?L.get(W.declaration.node.location)??null:null,mappings:[]})}}let F={declarations:b,systems:x.value.systems??[],references:j,contexts:I,types:x.value.types,concepts:x.value.concepts,targets:l(T=>{let M=S.slices.find(B=>B.scope.length===T.length&&B.scope.every((W,Ge)=>W===T[Ge]))?.slice;return M?b.flatMap(B=>{let W=S.resolve(B.name,M).declaration?.node.location===B.location?B.name:[...B.scope,B.name].join(".");return S.resolve(W,M).kind===ee.Operation&&S.resolve(W,M).declaration?.node.location===B.location?[{name:W,declaration:B}]:[]}):[]},"targets")},U=x.physicalEventSources.map(T=>T.source),Y=new Pt(x.physicalEventSources,x.sourceInventoryComplete&&!A),Q=new Map,oe=l((T,M)=>{let B=JSON.stringify([T,M]),W=Q.get(B);return W||(W=Y.resolve(T,M),Q.set(B,W)),{...W,source:W.state==="unique"?W.sources[0]:void 0,stream:W.state==="unique"?W.streams[0]:void 0}},"resolve"),Le=new Set(x.value.imports.map(T=>T.qualifiedName)),ae=U.flatMap(T=>T.streams.filter(M=>oe(T.name,M.name).state==="unique"&&!Le.has(`${T.name}.${M.name}`)).map(M=>({name:`${T.name}.${M.name}`,source:T,stream:M}))),Qe=new Map,pi=[];for(let T of $.values()){for(let M of D(T.location.line-1))Qe.set(M,{command:T});for(let M of[...T.produces,...T.validations,...T.handler?[T.handler]:[]])for(let B of D(M.location.line-1))Qe.delete(B);if(T.stream){pi.push(T.stream);for(let M of D(T.stream.location.line-1))Qe.set(M,{command:T,route:T.stream})}}for(let T of C.values())for(let M of[...T.given,...T.whenAppended?[T.whenAppended]:[],...T.thenEvents]){let B={event:M,expectation:T.thenEvents.includes(M)};for(let W of D(M.location.line-1))Qe.set(W,B);if(M.stream){pi.push(M.stream);for(let W of D(M.stream.location.line-1))Qe.set(W,{...B,route:M.stream})}}for(let T of U.filter(M=>M.location.path===i)){for(let M of D(T.location.line-1))Qe.set(M,{source:T});for(let M of T.streams)for(let B of D(M.location.line-1))Qe.set(B,{source:T,stream:M})}let Ga=[...$.values()].flatMap(T=>T.streamCandidates??[]).filter(T=>T.propertyCandidate!==null),Ka={declarations:U,routes:pi,ambiguousCandidates:Ga,contexts:Qe,targets:ae,resolve:oe},fi,Za={completions(T,M,B){if(fi===void 0){let W=We(h.source,i,h.placement,!1).value,Ge=l(ft=>{P(ft.location),ft.features.forEach(Ge)},"remapDependencyHeaders");W.modules.forEach(Ge),fi=Ya(x.value,W,i,D,u)}return fi.completions(T,M,B)}};return{commands:$,specifications:C,diagnostics:g,operationProductionLines:k,operations:F,eventSources:Ka,examples:Fa(x.value,i,t,D,u,x.diagnostics),dependencies:Za}}l(Sf,"analyze");function wt(t,e=[],n,i="current.play",r=!0){let o=JSON.stringify([t,e,n,i,r]),s=tn.get(o);return s===void 0&&(s=Sf(t,e,n,i,r),tn.size>=16&&tn.delete(tn.keys().next().value),tn.set(o,s)),s}l(wt,"responseAnalysis");var Cr="file",gf=/^[A-Za-z_]\w*(?:\[\])?(?:\?|\s+optional)?$/,xf=/^(?:[/\\]|[A-Za-z]:[/\\]|~[/\\])/;function iw(t){return xf.test(t)}l(iw,"isAbsoluteFileReferencePath");function vf(t){let e=!1,n=!1;for(let i=0;i<t.length;i++){let r=t[i];if(r==="\\"&&e&&i+1<t.length)i++;else if(r==='"'&&!n)e=!e;else if(r==="`"&&!e)n=!n;else if(!e&&!n&&r==="/"&&t[i+1]==="/")return t.slice(0,i)}return t}l(vf,"withoutComment");function Pr(t,e){let n=J(t),i=vf(t.slice(n)).trimEnd();if(Si(i)!==Cr)return;let r=i.slice(Cr.length),o=r.trim();if(o.length===0||gf.test(o))return;let s=r.length-r.trimStart().length,a=n+Cr.length+s+1;return{path:o,line:e,startColumn:a,endColumn:a+o.length}}l(Pr,"fileReferenceOn");function rw(t){let e=me(t),n=[];for(let i=0;i<t.length;i++){if(e[i])continue;let r=Pr(t[i],i);r&&n.push(r)}return n}l(rw,"fileReferences");function ot(t){let e=!1;return t.map(n=>{if(e)return n.trim()==="```"&&(e=!1),n;let i=Ee(n);return/^\s*```(?:[a-z]+)?\s*$/.test(i)&&(e=!0),i.trimEnd()})}l(ot,"eventAnalysisSource");var $f=/^concept\s+(\w+)\s*:\s*(\w+)((?:\s+@\w+)*)\s*$/,kf=/^\s*(@?[a-z_]\w*)\s+([\w.]+(?:\[\])?(?:\?|\s+optional)?)(\s+generated)?(\s+identifier)?\s*$/,Wa=/^([a-z_]\w*)\s+reason\s+"((?:[^"\\]|\\.)*)"\s*$/,bf=/^\s*reads\s+([A-Z]\w*)(?:\s+as\s+([a-z_]\w*))?(?:\s+by\s+([a-z_]\w*))?\s*$/,Ef=["authorize","produces","reads"],Cf=/^(?:(?:or|and)\s+)?[A-Za-z_(][\p{L}\p{Mn}\p{Nd}\p{Pc}\s()]*$/u,Pf=Lt,Af=["tag","for","generation","origin","namespace","sequence","correlation","causation","causedBy","occurred"],wf=/^\s*(?:by|filter)\s+([a-z_]\w*)\s+([\w.]+(?:\[\])?(?:\?|\s+optional)?)(?:\s+from\s+.+)?\s*$/;function at(t){return t.typeReference??It(t.type)}l(at,"propertyTypeReference");function Ar(t,e){let n=t.slice(e-1).match(/^[\p{L}\p{Mn}\p{Nd}\p{Pc}.]+(?:\[\])?(?:\?|\s+optional\b)?/u)?.[0]??"";return{text:n,startColumn:e,endColumn:e+n.length}}l(Ar,"sourceTypeAt");function wr(t,e,n){return e.map(i=>({index:i,match:t[i].match(kf)})).filter(i=>i.match!==null).filter(({match:i})=>i[1].startsWith("@")||i[1]==="as"||!n.includes(i[1])).map(({index:i,match:r})=>({name:r[1].replace(/^@/,""),type:r[2],typeReference:It(r[2]),sourceType:Ar(t[i],t[i].match(/^\s*\S+\s+/)[0].length+1),isIdentifier:r[4]!==void 0,...r[3]!==void 0?{isGenerated:!0}:{},line:i}))}l(wr,"propertiesIn");function rn(t,e,n,i){let r=[];for(let o=n+1;o<t.length;o++){if(e[o])continue;let s=t[o];if(s.trim().length!==0){if(J(s)<=i)break;r.push(o)}}return r}l(rn,"collectBody");function Ot(t,e,n,i){let r=rn(t,e,n,i).filter(a=>!e[a]&&!/^\s*(?:\/\/|#)/.test(t[a]));if(!/^\s*command\b/.test(t[n]))return r;let o,s=!1;return r.filter(a=>{let c=J(t[a]),d=t[a].trim();return o!==void 0&&c>o&&(!s||Cf.test(d))?!1:(o=d!=="validate csharp"&&wr(t,[a],Ef).length>0||/^description(?:\s|$)/.test(d)?void 0:c,s=/^authorize(?:\s|$)/.test(d),!0)})}l(Ot,"directBody");var nn=new Map;function on(t){let e=t.join(`
31
- `),n=nn.get(e);if(n)return n;let i=wt(t),r={authoringSources:[e],eventSources:i.eventSources.declarations,imports:[],concepts:[],types:[],policies:[],events:[],commands:[],queries:[],screens:[],triggers:[]};t=ot(t);let o=me(t),s=t,a=o,c=t.map(d=>d.replace(/\s*=(?!=|>).*/,""));for(let d=0;d<t.length;d++){if(o[d])continue;let m=t[d],u=m.trim(),y=J(m),h=s[d].trim().match(/^import\s+([\w.]+)\s*$/);if(h&&y===0){let S=h[1],k=S.split(".").pop()??S;r.imports.push({qualifiedName:S,shortName:k,line:d});continue}let v=u.match($f);if(v){let S=rn(t,o,d,y).map(I=>t[I].trim()),k={};for(let I of S){let w=I.match(Wa);w&&k[w[1]]===void 0&&(k[w[1]]=w[2])}let b=v[2]==="Enum"?S.filter(I=>!Wa.test(I)):[];r.concepts.push({name:v[1],primitive:v[2],attributes:v[3].trim().split(/\s+/).filter(Boolean),attributeReasons:k,enumValues:b,line:d});continue}let x=u.match(/^type\s+(\w+)\s*$/);if(x){r.types.push({name:x[1],properties:wr(t,rn(t,o,d,y),Dr),line:d});continue}let $=u.match(/^policy\s+(\w+)\s*$/);if($){let S=rn(t,o,d,y).filter(k=>!o[k]).map(k=>t[k].trim());r.policies.push({name:$[1],requires:S,line:d});continue}let C=s[d].trim().match(/^(?:produces\s+)?event\s+(\w+)(?:\s+generation\s+(\d+))?\s*$/);if(C){let S=u.startsWith("produces "),k=Ot(s,a,d,y),b=S?k:k.filter(I=>Pr(s[I],I)===void 0);r.events.push({name:C[1],...C[2]?{generation:Number(C[2])}:{},inline:S,properties:wr(S?c:s,b,S?Af:Pf),line:d});continue}let E=i.commands.get(d);if(E){let S=Ot(t,o,d,y),k=S.filter(b=>/^\s*produces\b/.test(t[b])&&!i.operationProductionLines?.has(b));r.commands.push({name:E.name,properties:E.properties.map(b=>({name:b.name,type:`${b.type.name}${b.type.isCollection?"[]":""}${b.type.isOptional?" optional":""}`,typeReference:{name:b.type.name,isCollection:b.type.isCollection,isOptional:b.type.isOptional},sourceType:Ar(t[b.type.location.line-1],b.type.location.column),isIdentifier:b.isIdentifier||/\sidentifier\s*$/.test(t[b.location.line-1]),...b.isGenerated?{isGenerated:!0}:{},line:b.location.line-1})),response:E.response,productionHeaders:k,produces:k.flatMap(b=>{let I=s[b].trim(),w=/^produces\s+event\b/.test(I),D=/^produces\s+when\b/.test(I),N=D?Ot(s,a,b,J(s[b]))[0]:b;if(N===void 0)return[];let L=D?s[N].trim():I.match(w?/^produces\s+event\s+([A-Za-z_]\w*)(?:\s+generation\s+\d+)?\s*$/:/^produces\s+([A-Z]\w*)\s*$/)?.[1];if(L===void 0||!/^[A-Za-z_]\w*$/.test(L))return[];let q=Ot(s,a,N,J(s[N])),j=q.map(Y=>s[Y].trim().match(/^for(?:\s+(.*))?$/)).filter(Y=>Y!==null),F=j.length===0?void 0:j.length===1?j[0][1]??"":"",U=q.flatMap(Y=>{let Q=s[Y].trim().match(w?/^(@?[a-z_]\w*)\s+[\w.]+(?:\[\])?(?:\?|\s+optional)?\s*=(?!=|>)\s*(.+)$/:/^(@?[\w.]+)\s*=(?!=|>)\s*(.+)$/);return Q===null?[]:[{name:Q[1].replace(/^@/,""),source:Q[2],line:Y}]});return[{name:L,inline:w,conditional:D,line:b,target:F,mappings:U}]}),reads:S.filter(b=>!o[b]).map(b=>({line:b,match:t[b].match(bf)})).filter(b=>b.match!==null).map(({line:b,match:I})=>({view:I[1],...I[2]?{alias:I[2]}:{},...I[3]?{by:I[3]}:{},line:b})),line:d});continue}let P=u.match(/^query\s+(\w+)\s*=>\s*(?:observable\s+)?([\w.]+(?:\[\])?(?:\?|\s+optional)?)\s*$/);if(P){let S=rn(t,o,d,y).map(k=>({index:k,match:t[k].match(wf)})).filter(k=>k.match!==null).map(({index:k,match:b})=>({name:b[1],type:b[2],typeReference:It(b[2]),sourceType:Ar(t[k],t[k].match(/^\s*(?:by|filter)\s+\S+\s+/)[0].length+1),isIdentifier:!1,line:k}));r.queries.push({name:P[1],returnType:P[2],returnTypeReference:It(P[2]),parameters:S,line:d});continue}let A=u.match(/^screen\s+(\w+)\s*$/);if(A){r.screens.push({name:A[1],line:d});continue}let g=u.match(/^trigger\s+(\w+)\s*$/);g&&y===0&&r.triggers.push({name:g[1],line:d})}return nn.size>=16&&nn.delete(nn.keys().next().value),nn.set(e,r),r}l(on,"scanDocument");function ci(...t){return{authoringSources:t.flatMap(e=>e.authoringSources??[]),...t.some(e=>e.authoringDocuments)?{authoringDocuments:t.flatMap(e=>e.authoringDocuments??[])}:{},eventSources:t.flatMap(e=>e.eventSources??[]),imports:t.flatMap(e=>e.imports),concepts:t.flatMap(e=>e.concepts),types:t.flatMap(e=>e.types),policies:t.flatMap(e=>e.policies),events:t.flatMap(e=>e.events),commands:t.flatMap(e=>e.commands),queries:t.flatMap(e=>e.queries),screens:t.flatMap(e=>e.screens),triggers:t.flatMap(e=>e.triggers)}}l(ci,"mergeSymbols");function Ua(t,e){let n=e?.authoringPath??"current.play",i=e?.authoringDocuments?.find(r=>r.path===n);return{...ci(on(t),e??ci()),authoringDocuments:e?.authoringDocuments,authoringPath:n,authoringPlacement:e?.authoringPlacement??i?.placement,authoringPlacementResolved:e?.authoringPlacementResolved??i?.isPlacementResolved}}l(Ua,"symbolsForBuffer");function di(t){return[...t.events.map(e=>e.name),...t.imports.map(e=>e.shortName)]}l(di,"knownEventNames");var Of=["Startup","Shutdown"];function xw(t){return[...di(t),...t.triggers.map(e=>e.name),...Of]}l(xw,"knownTriggerNames");function Or(t,e){return[...e,...t.concepts.map(n=>n.name),...t.types.map(n=>n.name),...t.imports.map(n=>n.shortName)]}l(Or,"knownTypeNames");function Ir(t){let e=t.properties.filter(o=>o.isIdentifier&&!at(o).isOptional&&!at(o).isCollection),n=e.length===1?e[0].name:void 0,i=t.produces??[],r=i.some(o=>o.target!==void 0&&o.target!==n)||i.some(o=>o.inline&&o.target===void 0)&&i.some(o=>!o.inline&&o.target===void 0);return{identifier:n,mixed:r}}l(Ir,"productionDestinations");function Aw(t,e){let n=wt(t,e?.authoringDocuments??e?.authoringSources,e?.authoringPlacement,e?.authoringPath),i=ot(t);return on(i).commands.map(r=>({...r,produces:r.produces?.filter(o=>!n.operationProductionLines?.has(o.line)&&n.operations.references.some(s=>s.location.line-1===o.line&&s.kind==="event")),productionHeaders:r.productionHeaders?.filter(o=>!n.operationProductionLines?.has(o))})).flatMap(r=>{let{identifier:o,mixed:s}=Ir(r);if(s||r.productionHeaders?.length!==r.produces?.length)return[];let a=r.produces?.some(c=>c.target!==void 0||c.inline);return(r.produces??[]).flatMap(c=>c.target!==void 0||c.inline&&(o===void 0||/\bgeneration\b/.test(i[c.line]))?[]:!c.inline&&a?[]:[{line:c.line,column:i[c.line].length+1,label:c.inline?`for ${o}`:"for <new event source>"}])})}l(Aw,"destinationHints");var Z={conflictingScreenDataBinding:"PLAY0530",screenDataQueryMismatch:"PLAY0531",actionWithoutInputSurface:"PLAY0532",commandWithoutInputSurface:"PLAY0533",readModelFieldWithoutOrigin:"PLAY0534",queryParameterNotHeldByView:"PLAY0535",unconsumedEvent:"PLAY0536",unreachableScreen:"PLAY0537",invalidActionAlternative:"PLAY0341",guardedActionWithoutAlternatives:"PLAY0342",misplacedActionOtherwise:"PLAY0343",unsupportedActionConditionOperand:"PLAY0344",unknownActionSubjectField:"PLAY0345",unresolvedActionSubject:"PLAY0346",unreachableActionAlternative:"PLAY0347",unknownActionArgumentProperty:"PLAY0348",invalidRefusalBranch:"PLAY0538",invalidRefusalBranchBody:"PLAY0539",unreachableRefusalBranch:"PLAY0540",invalidRefusalValue:"PLAY0541",unknownRefusalConstraint:"PLAY0542",unmatchedRedeliveredOccurrence:"PLAY0543",unknownRedeliveryReaction:"PLAY0544",invalidNoEventsExpectation:"PLAY0545",indeterminateNegatedClaimTarget:"PLAY0546",invalidAbsentReadModelStep:"PLAY0453",unknownConstraintProperty:"PLAY0391",invalidSpecificationExample:"PLAY0518",duplicateSpecificationAssignment:"PLAY0519",unknownReadModelProperty:"PLAY0514",piiNotSupportedOnIdentifier:"PLAY0515",invalidEventSourceDeclaration:"PLAY0503",invalidCommandStream:"PLAY0504",invalidSpecificationStream:"PLAY0547",specificationStreamOnCommand:"PLAY0548",invalidSpecificationStreamRoute:"PLAY0549",invalidSpecificationStreamEventSource:"PLAY0550",specificationStreamContradictsCommand:"PLAY0551",ambiguousCommandStream:"PLAY0505",unsupportedStreamIdType:"PLAY0506",redundantSourceStreamId:"PLAY0507",eventFromLaterSlice:"PLAY0516",timelineCycleGroup:"PLAY0517",invalidSpecificationExampleBody:"PLAY0526",undeclaredDependency:"PLAY0552",unusedDependencyDeclaration:"PLAY0553",invalidDependencyTarget:"PLAY0554",repeatedDependencyDeclaration:"PLAY0555",mutualDependencyDeclarations:"PLAY0556",authorizationRefusalWithoutIdentity:"PLAY0557",invalidDocumentation:"PLAY0558",conflictingDocumentationAcrossFiles:"PLAY0559",ambiguousReference:"PLAY0198",invalidImplementationBlock:"PLAY0492",invalidImplementationHint:"PLAY0493",conflictingImplementationSources:"PLAY0494",eventSourceIdInPayload:"PLAY0469",explicitProducesTargetsRequired:"PLAY0470",redundantEventId:"PLAY0471",invalidEventId:"PLAY0472",inlineEventCollision:"PLAY0473",inlineEventOutsideCommand:"PLAY0474",inlineEventGeneration:"PLAY0475",reservedProductionMetadata:"PLAY0476",invalidEventDocumentation:"PLAY0477",tabIndentation:"PLAY0006",unknownPrimitiveType:"PLAY0008",unknownSliceType:"PLAY0028",duplicateCommandIdentifier:"PLAY0036",unknownContextPath:"PLAY0153",unknownContextCausedByProperty:"PLAY0154",unknownContextIdentityProperty:"PLAY0155",unclosedCodeBlock:"PLAY0164",unknownType:"PLAY0165",unknownEvent:"PLAY0166",unknownPolicy:"PLAY0167",duplicateDeclaration:"PLAY0168",unknownEventContextMember:"PLAY0295",unknownEventContextPath:"PLAY0296",eventContextPathBelowCollection:"PLAY0297",missingEventContextPath:"PLAY0298",unresolvedDynamicKeySource:"PLAY0299",invalidFileImport:"PLAY0454",omittedProductionDestination:"PLAY0478",legacyOptionalSuffix:"PLAY0479",invalidOptionalModifierOrder:"PLAY0480",optionalReadsNotSupported:"PLAY0481",unavailableResponseExecution:"PLAY0268",generatedPropertyOutsideCommand:"PLAY0482",invalidGeneratedType:"PLAY0483",invalidGeneratedModifierOrder:"PLAY0484",generatedPropertyInput:"PLAY0485",invalidCommandResponse:"PLAY0486",invalidResponseSource:"PLAY0487",duplicateResponseField:"PLAY0488",invalidResponseShape:"PLAY0489",invalidGeneratedFixture:"PLAY0490",invalidReturnExpectation:"PLAY0491"};var If=/^import(\s+)"([^"\\]+)"\s*(?:\/\/.*)?$/,Tf=/^import\s+"/;function Va(t){return Tf.test(t.trim())}l(Va,"isFileImportLine");function Tr(t,e){let n=J(t),i=t.slice(n).match(If);if(!i)return;let r=n+6+i[1].length+2;return{pattern:i[2],line:e,startColumn:r,endColumn:r+i[2].length}}l(Tr,"fileImportOn");function Rw(t){let e=me(t),n=[];for(let i=0;i<t.length;i++){if(e[i])continue;let r=Tr(t[i],i);r&&n.push(r)}return n}l(Rw,"fileImports");var za=l(t=>t.split("/").slice(0,-1),"folderOf");function Rf(t,e){let n=e.split("/"),i=0;for(;i<t.length&&i<n.length-1&&t[i]===n[i];)i++;return[...t.slice(i).map(()=>".."),...n.slice(i)].join("/")}l(Rf,"relativeTo");function Dw(t,e){let n=za(t),i=new Set;for(let r of e.filter(o=>o!==t&&o.toLowerCase().endsWith(".play"))){let o=Rf(n,r),s=za(o);i.add(o),i.add([...s,"*.play"].join("/"));for(let a=0;a<=s.length;a++)i.add([...s.slice(0,a),"**","*.play"].join("/"))}return[...i].sort()}l(Dw,"importablePaths");var Df=new Set(["namespace","sequence","correlation","causation","causedBy","occurred"]),Mf=/^id\s+"((?:[^"\\]|\\.)*)"$/;function Qa(t,e,n,i=new Set){t=ot(t);let r=[],o=me(t),s=Nf(t,o),a=new Set(e.commands.flatMap(y=>y.productionHeaders??[])),c=new Map,d=new Set;for(let y of[e,n]){for(let h of y.events)c.set(h.name,(c.get(h.name)??0)+1);for(let h of y.imports)d.add(h.shortName)}let m=l((y,h,v,x="error")=>{r.push({line:y,startColumn:J(t[y])+1,endColumn:t[y].length+1,code:h,message:v,severity:x})},"report");for(let y of e.events){let h=Ot(t,o,y.line,J(t[y.line]));if(y.inline){let $=new Set;for(let C of y.properties)$.has(C.name)&&m(C.line,Z.duplicateDeclaration,`Event '${y.name}' already declares property '${C.name}'.`),$.add(C.name);a.has(y.line)||m(y.line,Z.inlineEventOutsideCommand,"Inline events can only be declared inside commands."),y.generation!==void 0&&m(y.line,Z.inlineEventGeneration,"Inline events are generation 1; extract the event before declaring generations."),((c.get(y.name)??0)>1||d.has(y.name))&&m(y.line,Z.inlineEventCollision,`Inline event '${y.name}' collides with another declaration or import.`)}let v=!1,x=!1;for(let $ of h){let C=t[$].trim(),E=C.split(/\s+/)[0];if(y.inline&&E==="generation"&&m($,Z.inlineEventGeneration,"Inline events are generation 1; extract the event before declaring generations."),y.inline&&E==="origin"&&m($,Z.reservedProductionMetadata,"An inline event is local to its command and cannot declare origin."),!/^(?:id|description|documentation)\s+[\w.]+(?:\[\])?(?:\?|\s+optional)?(?:\s*=.*)?$/.test(C)){if(E==="id"){let P=C.match(Mf);v||P===null||P[1].trim().length===0?m($,Z.invalidEventId,'Expected one nonempty id "<old-name>".'):P[1]===y.name&&m($,Z.redundantEventId,"This id repeats the event name; remove it.","information"),v=!0}if(E==="documentation"){let P=$+1;for(;P<t.length&&t[P].trim().length===0;)P++;(x||C!=="documentation"||t[P]?.trim()!=="```markdown"||J(t[P])<=J(t[$])||!s.has(P))&&m($,Z.invalidEventDocumentation,"Expected one nonempty fenced markdown documentation block."),x=!0}}}}let u=[];for(let y=0;y<t.length;y++){if(o[y]||t[y].trim().length===0)continue;let h=J(t[y]);for(;u.length>0&&u[u.length-1].indent>=h;)u.pop();let v=t[y].trim().split(/\s+/)[0];Df.has(v)&&u.at(-1)?.event&&m(y,Z.reservedProductionMetadata,`'${v}' is system-assigned production metadata.`),v==="produces"&&u.push({indent:h,event:!i.has(y)&&!/^\s*produces\s+operation\b/.test(t[y])})}for(let y of e.commands){let{identifier:h,mixed:v}=Ir(y);for(let x of y.produces??[]){v&&x.target===void 0&&m(x.line,Z.explicitProducesTargetsRequired,`Production '${x.name}' must state for explicitly when destinations differ.`);let $=x.target??(x.inline?h:void 0);if(!(h===void 0||$!==h))for(let C of x.mappings.filter(E=>E.source===h))m(C.line,Z.eventSourceIdInPayload,`The payload copies '${h}', which already identifies the event source.`,x.inline?"warning":"information")}}return r}l(Qa,"validateInlineEvents");function Nf(t,e){let n=new Set,i,r=!1;for(let o=0;o<t.length;o++){if(!e[o])continue;let s=t[o].trim();i===void 0?(i=o,r=!1):s==="```"?(r&&t[i].trim()==="```markdown"&&n.add(i),i=void 0):s.length>0&&(r=!0)}return n}l(Nf,"nonemptyMarkdownBlocks");function be(t,e,n,i,r,o){return{severity:t,message:r,line:e,startColumn:n,endColumn:n+i,code:o}}l(be,"issue");function Te(t,e,n,i,r,o){let s=n.indexOf(i)+1;return be(t,e,s,i.length,r,o)}l(Te,"tokenIssue");function jf(t,e,n){let i=[],r=new Set([...Or(e,sn),...Or(n,[])]),o=l((a,c)=>{for(let d of a.filter(m=>!r.has(at(m).name))){let m=at(d).name;i.push(be("warning",d.line,d.sourceType.startColumn,d.sourceType.text.length,m==="optional"?`Unknown type 'optional' on '${d.name}' of ${c} \u2014 did you forget the type before 'optional'?`:`Unknown type '${m}' on '${d.name}' of ${c} \u2014 declare it with 'concept ${m} : <Primitive>' or 'type ${m}'.`,Z.unknownType))}},"checkProperties");for(let a of e.types)o(a.properties,`type '${a.name}'`);for(let a of e.events)o(a.properties,`event '${a.name}'`);for(let a of e.queries)o(a.parameters,`query '${a.name}'`);for(let a of e.commands){o(a.properties,`command '${a.name}'`);let c=a.properties.filter(d=>d.isIdentifier);for(let d of c.slice(1))i.push(Te("error",d.line,t[d.line],"identifier",`Command '${a.name}' already marks '${c[0].name}' as identifier \u2014 only one property can be the identifier.`,Z.duplicateCommandIdentifier))}let s=new Map;for(let a of[...e.concepts,...e.types]){if(s.get(a.name)===void 0){s.set(a.name,a.line);continue}i.push(Te("error",a.line,t[a.line],a.name,`Duplicate declaration of '${a.name}' \u2014 concept and type names must be unique.`,Z.duplicateDeclaration))}return i}l(jf,"validateDeclarations");function oO(t,e={}){let n=me(t),i=on(t),r=e.application??ci(),o=Ua(t,{...r,authoringPath:e.path??r.authoringPath,authoringPlacement:e.placement??r.authoringPlacement}),s=wt(t,o.authoringDocuments??o.authoringSources?.filter(S=>S!==t.join(`
32
- `)),o.authoringPlacement,o.authoringPath,o.authoringPlacementResolved),a=new Set(s.eventSources.routes.map(S=>S.location.line-1)),c={...i,commands:i.commands.map(S=>({...S,properties:S.properties.filter(k=>!a.has(k.line)),produces:S.produces?.filter(k=>!s.operationProductionLines?.has(k.line)),productionHeaders:S.productionHeaders?.filter(k=>!s.operationProductionLines?.has(k))}))},d=new Set([...di(c),...di(r)]),m=new Set([...c.policies,...r.policies].map(S=>S.name)),u=jf(t,c,r);u.push(...Lf(t,c));let y=new Set([p.LegacyOptionalSuffix,p.InvalidOptionalModifierOrder,p.OptionalReadsNotSupported]),h=new Set([p.UnexpectedTokenInPolicyCondition,p.ExpectedPolicyCondition,p.UnclosedPolicyConditionGroup,p.ExpectedRoleName,p.ExpectedClaimName,p.ExpectedClaimMatches,p.ExpectedClaimMatchTarget]),v=new Set([p.UnknownEvent,p.UnknownReadModelProperty,p.PiiNotSupportedOnIdentifier]),x=new Set([p.EventFromLaterSlice,p.TimelineCycleGroup]),$=new Set([p.UndeclaredDependency,p.UnusedDependencyDeclaration,p.InvalidDependencyTarget,p.RepeatedDependencyDeclaration,p.MutualDependencyDeclarations,p.AmbiguousReference]),C=new Set([p.InvalidDocumentation,p.ConflictingDocumentationAcrossFiles,p.InvalidAbsentReadModelStep,p.UnknownConstraintProperty,p.OmittedProductionDestination,p.InvalidSpecificationExample,p.DuplicateSpecificationAssignment]),E=new Set;for(let S of e.compilerDiagnostics??s.diagnostics){if(!y.has(S.code)&&!h.has(S.code)&&!v.has(S.code)&&!x.has(S.code)&&!$.has(S.code)&&!C.has(S.code)&&S.code!==p.InvalidSpecificationExampleBody&&S.code!==p.UnknownRuleImplementationDirective&&S.code!==p.InvalidValidationRule&&S.code!==p.RepeatedDeclarationAcrossFiles&&!/^PLAY049[0-9]$|^PLAY050[0-7]$|^PLAY054[7-9]$|^PLAY055[01]$|^PLAY048[2-9]$|^PLAY004[56]$|^PLAY053[0-9]$|^PLAY054[0-6]$|^PLAY034[1-8]$|^PLAY0557$/.test(S.code))continue;let k=S.location.line-1;if(S.code===p.OmittedProductionDestination&&u.some(I=>I.code===S.code&&I.line===k))continue;S.code===p.UnknownEvent&&E.add(k);let b=Sr(t[k],S)||t[k].length-S.location.column+1;u.push(be(S.severity,k,S.location.column,b,S.message,S.code))}let P=l((S,k,b)=>{!d.has(b)&&!E.has(S)&&u.push(Te("warning",S,k,b,`Unknown event type '${b}' \u2014 declare it in a slice or import it.`,Z.unknownEvent))},"checkEvent"),A=-1;for(let S=0;S<t.length;S++){let k=t[S],b=k.trim();if(n[S]||b.length===0)continue;let I=k.match(/^[ ]*(\t+)/);if(I&&u.push(be("warning",S,I[0].length-I[1].length+1,I[1].length,"Screenplay is indentation-based \u2014 use spaces, not tabs.",Z.tabIndentation)),A>=0){if(J(k)>A&&/^(?:or\s+)?[A-Z]\w*(?:\s+or\s+[A-Z]\w*)*$/.test(b)){for(let Y of b.split(/\s+/).filter(Q=>Q!=="or"))m.has(Y)||u.push(Te("warning",S,k,Y,`Unknown policy '${Y}' \u2014 declare it with 'policy ${Y}'.`,Z.unknownPolicy));continue}A=-1}let w=qf(t,n,S);w&&u.push(w);let D=b.match(/^slice\s+(\w+)/);D&&!hi.includes(D[1])&&u.push(Te("error",S,k,D[1],`Unknown slice type '${D[1]}' \u2014 expected ${hi.join(", ")}.`,Z.unknownSliceType));let N=b.match(/^concept\s+\w+\s*:\s*(\w+)/);N&&N[1]!=="Enum"&&!sn.includes(N[1])&&u.push(Te("error",S,k,N[1],`Unknown primitive type '${N[1]}' \u2014 expected ${sn.join(", ")} or Enum.`,Z.unknownPrimitiveType));let L=b.match(/^authorize\s+(.*)$/);if(L){A=J(k);for(let Y of L[1].split(/\s+/).filter(Q=>Q!=="or"&&Q.length>0))m.has(Y)||u.push(Te("warning",S,k,Y,`Unknown policy '${Y}' \u2014 declare it with 'policy ${Y}'.`,Z.unknownPolicy))}let q=b.match(/^on\s+([A-Z]\w*)\s*$/);q&&P(S,k,q[1]);let j=b.match(/^produces\s+([A-Z]\w*)\s*$/);if(j&&!s.operationProductionLines?.has(S)&&P(S,k,j[1]),/^produces\s+when\b/.test(b)&&!s.operationProductionLines?.has(S))for(let Y=S+1;Y<t.length;Y++){let Q=t[Y];if(!(n[Y]||Q.trim().length===0)){if(J(Q)>J(k)){let oe=Q.trim().match(/^([A-Z]\w*)\s*$/);oe&&P(Y,Q,oe[1])}break}}let F=b.match(/^unique\s+event\s+([A-Z]\w*)/);F&&P(S,k,F[1]);let U=b.match(/^unique\s+[a-z_]\w*\s+on\s+([A-Z]\w*)/);U&&P(S,k,U[1]);for(let Y of k.match(/\$context\.[\w.]+/g)??[]){let Q=Y.substring(9).split(".");ui.includes(Q[0])?Q[0]==="causedBy"&&Q.length>1&&!mi.includes(Q[1])?u.push(Te("warning",S,k,Y,`Unknown $context.causedBy property '${Q[1]}' \u2014 expected ${mi.join(", ")}.`,Z.unknownContextCausedByProperty)):Q[0]==="identity"&&Q.length>1&&!yi.includes(Q[1])&&u.push(Te("warning",S,k,Y,`Unknown $context.identity property '${Q[1]}' \u2014 expected ${yi.join(", ")}.`,Z.unknownContextIdentityProperty)):u.push(Te("warning",S,k,Y,`Unknown $context path '${Q.join(".")}' \u2014 expected one of ${ui.join(", ")}.`,Z.unknownContextPath))}}u.push(...Ff(t,n)),u.push(...Qa(t,c,r,s.operationProductionLines));let g=t.map((S,k)=>({line:S,index:k})).filter(({line:S})=>/^\s*```(?:[a-z]+)?\s*$/.test(S));if(g.length%2===1){let S=g[g.length-1];u.push(be("error",S.index,1,S.line.length+1,"Unclosed inline code block \u2014 expected a closing ``` line.",Z.unclosedCodeBlock))}return u}l(oO,"validateLines");function Lf(t,e){let n=[];t=ot(t);for(let i of e.commands){let r=i.properties.filter(o=>o.isIdentifier&&!at(o).isOptional&&!at(o).isCollection);if(r.length===1)for(let o of i.produces??[]){if(o.inline||o.conditional||o.target!==void 0)continue;let s=o.line;n.push(be("information",s,J(t[s])+1,t[s].trim().length,`Plain 'produces ${o.name}' omits its destination \u2014 use 'for ${r[0].name}' to explicitly select the command's identifier.`,Z.omittedProductionDestination))}}return n}l(Lf,"validateProductionDestinations");function qf(t,e,n){let i=t[n],r=i.trim().replace(/\s*\/\/.*$/,"");if(!/^import\b/.test(r)||Tr(i,n))return;let o=J(i);if(!(!(o>0&&["module","feature"].includes(Mr(t,e,n,o)[0]))&&!Va(i)))return be("error",n,o+1,r.length,`Invalid import '${r}' \u2014 inside a module or feature, import names files: 'import "<path or glob>"'.`,Z.invalidFileImport)}l(qf,"validateImport");var Bf=/^(?:(?:increment|decrement|count|clear|add|subtract|set)\s+)?@?([$\w.]+)(?=\s|=|$)/;function Ff(t,e){let n=[],i=l(r=>r.map(o=>o.name).join(", "),"names");for(let r=0;r<t.length;r++){let o=t[r];if(e[r])continue;for(let c of o.matchAll(/(\.)?\$eventContext((?:\.(?:\w+(?:\(\))?)?)*)/g)){let d=c[0].substring(c[1]?.length??0),m=c[2];if(m.length===0){c[1]&&n.push(be("error",r,(c.index??0)+2,d.length,`'$eventContext' names no member - expected one of ${i($i("").expected)}.`,Z.missingEventContextPath));continue}let u=m.substring(1),y=$i(u),h=(c.index??0)+(c[1]?.length??0)+1;switch(y.status){case"missing":n.push(be("error",r,h,d.length,`'$eventContext.${u}' names no member - expected one of ${i(y.expected)}.`,Z.missingEventContextPath));break;case"unknownMember":n.push(be("warning",r,h,d.length,`Unknown event context member '${y.segment}' in '$eventContext.${u}' - expected one of ${i(y.expected)}.`,Z.unknownEventContextMember));break;case"unknownSubPath":{let v=y.expected.length===0?"no members to address":`members ${i(y.expected)}`;n.push(be("warning",r,h,d.length,`Unknown event context path '$eventContext.${u}' - '${y.member?.name}' (${y.member?.type}) has ${v}.`,Z.unknownEventContextPath));break}case"belowCollection":n.push(be("error",r,h,d.length,`'$eventContext.${u}' cannot resolve - '${y.member?.name}' is a collection (${y.member?.type}) and cannot be addressed below.`,Z.eventContextPathBelowCollection));break}}let s=o.trim().match(Bf)?.[1],a=s?.match(/\.\$(\w+)/)?.[1];s&&a&&a!=="eventContext"&&n.push(Te("warning",r,o,s,`Dynamic dictionary key '$${a}' in '${s}' is never resolved - only '$eventContext.<path>' is, so the literal text '$${a}' becomes the key.`,Z.unresolvedDynamicKeySource))}return n}l(Ff,"validateEventContextPaths");export{_a as a,Yf as b,Wf as c,Dr as d,Uf as e,ui as f,mi as g,hi as h,sn as i,zf as j,Ja as k,Vf as l,li as m,It as n,Gf as o,p,de as q,Ri as r,En as s,o0 as t,a0 as u,Ee as v,J as w,Si as x,me as y,Mr as z,_f as A,Jf as B,ot as C,gi as D,xi as E,vi as F,Ha as G,nu as H,iu as I,ru as J,Xa as K,es as L,pu as M,fu as N,uu as O,mu as P,yu as Q,hu as R,Su as S,gu as T,xu as U,vu as V,$u as W,ns as X,ku as Y,wu as Z,Ou as _,Iu as $,is as aa,Tu as ba,Ru as ca,Du as da,Mu as ea,rs as fa,Nu as ga,ju as ha,Lu as ia,qu as ja,Bu as ka,Fu as la,Yu as ma,Wu as na,Uu as oa,zu as pa,Vu as qa,Qu as ra,Gu as sa,Lr as ta,os as ua,Ku as va,Zu as wa,_u as xa,Ju as ya,Hu as za,as as Aa,Xu as Ba,em as Ca,tm as Da,nm as Ea,im as Fa,XA as Ga,wt as Ha,Cr as Ia,iw as Ja,Pr as Ka,rw as La,at as Ma,Ot as Na,on as Oa,ci as Pa,Ua as Qa,di as Ra,Of as Sa,xw as Ta,Or as Ua,Ir as Va,Aw as Wa,Z as Xa,Va as Ya,Tr as Za,Rw as _a,Dw as $a,oO as ab,Ff as bb};
33
- //# sourceMappingURL=chunk-XOAJQFSV.js.map