@cratis/screenplay-language 4.78.0 → 4.80.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.
@@ -0,0 +1,16 @@
1
+ import{a as c}from"./chunk-AYDF3IFZ.js";var Ko="screenplay",ap={id:Ko,extensions:[".play"],aliases:["Screenplay","screenplay","play"],mimetypes:["text/x-screenplay"]},sp=["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","seed","behavior"];var Yi=["depends","description","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","execute","open","close","refresh","set","notify","confirm","raise","interval","success","failure","click","double","select","submit","change","load","unload","enter","leave","info","warning"],cp=["csharp","typescript","react","html","sql"],wn=["command","arguments","tenant","causedBy","causation","occurred","identity"],In=["subject","name","userName"],Rn=["id","name","userName","isAuthenticated","roles","claims"],Tn=["StateChange","StateView","Automation","Translate"],jt=["Uuid","String","Int","Decimal","Bool","Date","DateTime"],lp=["@pii","@sensitive"],_o=/^\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[^=]*$/,dp={comments:{lineComment:"//"},brackets:[["(",")"],["[","]"]],autoClosingPairs:[{open:"(",close:")"},{open:"[",close:"]"},{open:'"',close:'"'}],surroundingPairs:[{open:"(",close:")"},{open:"[",close:"]"},{open:'"',close:'"'}],folding:{offSide:!0},onEnterRules:[{beforeText:_o,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|concurrency|seed|for|when|then|arguments|result|every|at)\b.*$/,decreaseIndentPattern:/(?!)/}};function pt(t){let e=/^([\w.]+)(\[\])?(\?|\s+optional)?$/.exec(t);return{name:e?.[1]??t,isCollection:e?.[2]!==void 0,isOptional:e?.[3]!==void 0}}c(pt,"typeReferenceSymbol");function fp(t){return`${t.name}${t.isCollection?"[]":""}${t.isOptional?" optional":""}`}c(fp,"typeReferenceText");function Te(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}c(Te,"withoutComment");function V(t){return t.length-t.trimStart().length}c(V,"indentOf");function Dn(t){return t.trim().split(/\s+/)[0]??""}c(Dn,"firstWord");function de(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}c(de,"fenceMap");function Wi(t,e,n,i){let r=[],o=i;for(let a=n-1;a>=0&&o>0;a--){if(e[a])continue;let s=Te(t[a]);if(s.trim().length===0)continue;let d=V(s);d<o&&(r.push(Dn(s)),o=d)}return r}c(Wi,"enclosingChain");function yp(t,e,n,i){for(let r=n-1;r>=0&&i>0;r--){if(e[r])continue;let o=Te(t[r]);if(o.trim().length!==0&&V(o)<i)return o.trim()}}c(yp,"nearestEnclosingLine");function Sp(t,e,n,i){let r=[],o=i;for(let a=n-1;a>=0&&o>0;a--){if(e[a])continue;let s=Te(t[a]);if(s.trim().length===0)continue;let d=V(s);d<o&&(r.push(s.trim()),o=d)}return r}c(Sp,"enclosingHeaders");var l={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",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",UnclosedConditionGroup:"PLAY0160",InvalidNumericDirective:"PLAY0508",DuplicateNumericDirective:"PLAY0509",LateNumericDirective:"PLAY0510",InexactNumericLiteral:"PLAY0511",MixedNumericModes:"PLAY0512",IncompatibleNumericSource:"PLAY0513",EventFromLaterSlice:"PLAY0516",TimelineCycleGroup:"PLAY0517",AmbiguousReference:"PLAY0198",InvalidSpecificationStream:"PLAY0547",SpecificationStreamOnCommand:"PLAY0548",InvalidSpecificationStreamRoute:"PLAY0549",InvalidSpecificationStreamEventSource:"PLAY0550",SpecificationStreamContradictsCommand:"PLAY0551",InvalidDependencyTarget:"PLAY0554",RepeatedDependencyDeclaration:"PLAY0555",UndeclaredDependency:"PLAY0552",UnusedDependencyDeclaration:"PLAY0553",MutualDependencyDeclarations:"PLAY0556",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 Mn="\\p{L}\\p{Mn}\\p{Nd}\\p{Pc}",H="[\\u0009-\\u000d\\u0020\\u0085\\u00a0\\u1680\\u2000-\\u200a\\u2028\\u2029\\u202f\\u205f\\u3000]";function _(t){let e=`(?=[\\u0000-\\uFFFF])[${Mn}]`,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")}c(_,"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?Mn:`[${Mn}]`:o==="d"?e+="\\p{Nd}":e+=`\\${o}`;continue}r==="["&&!n?n=!0:r==="]"&&n&&(n=!1),e+=r}return new RegExp(e,"u")}c(O,"pattern");var Jo=new RegExp(`^depends${H}+on(?:${H}|$)`,"u"),Ho=new RegExp(`${H}+$`,"u");function Ue(t,e=!1,n){let i=[],r=0,o=0;for(let a of t.split(`
2
+ `)){r++;let s=a.endsWith("\r")?a.replace(/\r+$/,""):a,d=s.length-s.trimStart().length,f=Xo(s.substring(d),e),m=Jo.test(f)?f.replace(Ho,""):f.trimEnd();i.push(n===void 0?{number:r,raw:s,indent:d,content:m,startOffset:o}:{number:r,raw:s,indent:d,content:m,path:n,startOffset:o}),o+=a.length+1}return i}c(Ue,"splitLines");function ft(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}c(ft,"commentStart");function Xo(t,e){let n=ft(t,e);return n<0?t:t.substring(0,n)}c(Xo,"stripComment");var Ui=c((t,e)=>t.length===e.length&&t.every((n,i)=>n===e[i]),"same"),jn=c(t=>[...t.scope,t.name].join("."),"addressOf"),ut=class{static{c(this,"DeclaredDependencyTargets")}static resolve(e,n,i){let r=e.split(".");if(r.length>1){let o=i.filter(a=>Ui([...a.scope,a.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 a=i.filter(s=>s.name===e&&Ui(s.scope,n.slice(0,o)));if(a.length>0)return a.length===1?{resolved:a[0],ambiguous:[]}:{ambiguous:a}}return{ambiguous:[]}}};function Nt(t,e){let n=[],i=!1,r=c((d,f)=>{n.push({name:d.name,scope:f}),i||=(d.dependsOn?.length??0)>0,d.features.forEach(m=>r(m,[...f,d.name]))},"inventory");for(let d of t.modules)n.push({name:d.name,scope:[]}),i||=(d.dependsOn?.length??0)>0,d.features.forEach(f=>r(f,[d.name]));if(!i)return t;n=[...new Map(n.map(d=>[jn(d),d])).values()];let o=new Map,a=c((d,f)=>{let m=[],u=f.join(".");o.has(u)||o.set(u,new Set);let h=o.get(u);for(let g of d){let b=ut.resolve(g.target,f,n),x=b.resolved===void 0?void 0:jn(b.resolved),$=x===void 0?`text:${g.target}`:`resolved:${x}`;if(h.has($)){e.warning(l.RepeatedDependencyDeclaration,`Dependency '${g.target}' is already declared on this container - this repeated declaration is ignored`,g.location);continue}h.add($),m.push(g),b.ambiguous.length>0?e.warning(l.AmbiguousReference,`Ambiguous dependency target '${g.target}' - candidates: ${b.ambiguous.map(jn).join(", ")}`,g.location):(x===void 0||x===u||x.startsWith(u+".")||u.startsWith(x+"."))&&e.warning(l.InvalidDependencyTarget,`Invalid dependency target '${g.target}' on '${u}' - the target must resolve to another module or feature, not self, an ancestor, or a descendant`,g.location)}return m},"keep"),s=c((d,f)=>{let m=[...f,d.name];return{...d,dependsOn:a(d.dependsOn??[],m),features:d.features.map(u=>s(u,m))}},"normalize");return{...t,modules:t.modules.map(d=>({...d,dependsOn:a(d.dependsOn??[],[d.name]),features:d.features.map(f=>s(f,[d.name]))}))}}c(Nt,"validateDependencyDeclarations");var qe=[],mt=c(t=>t.length===0,"isDocumentPlacement");function Lt(t){return t.length===0?"the application":t.length===1?`module '${t[0]}'`:`feature '${t.join(".")}'`}c(Lt,"describePlacement");var ze=c((t,e,n)=>n===void 0?{line:t,column:e}:{line:t,column:e,path:n},"sourceLocation");var Nn=c(t=>t.content.length===0,"isBlank"),p=c(t=>ze(t.number,t.indent+(t.contentOffset??0)+1,t.path),"locationOf"),zi=c(t=>ze(t.number,1,t.path),"startOf");var ea=O("^(?:(?:or|and)\\s+)?[A-Za-z_(][\\w\\s()]*$"),ta=new RegExp(O("\\(|\\)|[A-Za-z_]\\w*").source,"gu"),na=O("^[A-Z]\\w*$");function De(t,e){let n=e.content.substring(9);for(let s=t.peekChild(e.indent);s!==void 0&&ea.test(s.content);s=t.peekChild(e.indent))t.reader.takeSignificant(),n+=` ${s.content}`;let i=ia(n),r=p(e);if(i.length===0)return t.error(l.AuthorizeWithoutPolicy,"Expected at least one policy after 'authorize'",r),null;let a=new Ln(t,i,r).parse();return a===null?null:{kind:"AuthorizeSyntax",requirement:a,location:r}}c(De,"parseAuthorize");function ke(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}}c(ke,"combineAuthorize");function ia(t){let e=[];for(let n of t.match(ta)??[])e.length>0&&ra(e[e.length-1])&&oa(n)&&e.push("and"),e.push(n);return e}c(ia,"tokenize");var Vi=c(t=>t!=="("&&t!==")"&&t!=="and"&&t!=="or","isName"),ra=c(t=>t===")"||Vi(t),"isOperandEnd"),oa=c(t=>t==="("||Vi(t),"isOperandStart"),Ln=class{static{c(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(l.UnexpectedTokenInAuthorize,`Unexpected '${this.tokens[this.#e]}' in authorize`,this.location),e}#t(){return this.#i("or","Or",()=>this.#r())}#r(){return this.#i("and","And",()=>this.#n())}#i(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.#a();this.#e++;let e=this.#t();return this.tokens[this.#e]===")"?this.#e++:this.context.error(l.UnclosedAuthorizeGroup,"Expected ')' in authorize",this.location),e}#a(){if(this.#e>=this.tokens.length)return this.context.error(l.AuthorizeWithoutPolicy,"Expected a policy name",this.location),null;let e=this.tokens[this.#e++];return na.test(e)?{kind:"PolicyReferenceSyntax",name:e,location:this.location}:(this.context.error(l.InvalidPolicyReference,`Invalid policy reference '${e}' - policy names are PascalCase identifiers`,this.location),null)}};var z='(?:[^"\\\\]|\\\\.)*',aa={"\\":"\\",'"':'"',n:`
3
+ `,r:"\r",t:" "};function Q(t){if(!t.includes("\\"))return t;let e="";for(let n=0;n<t.length;n++){let i=n+1<t.length?aa[t[n+1]]:void 0;t[n]==="\\"&&i!==void 0?(e+=i,n++):e+=t[n]}return e}c(Q,"unescapeString");function Ve(t,e,n,i=!1){let o=n.content.startsWith("```")?n:t.reader.peekSignificant(),a=e==="description"?"```text":`\`\`\`${e}`;if(o===void 0||o!==n&&o.indent<=n.indent||o.content!==a&&!(i&&e==="description"&&o.content==="```markdown")&&!(o.content==="```"&&o!==n))return t.error(l.ExpectedCodeFence,`Expected an opening \`\`\`${e==="description"?"text":e} fence after '${e}'`,p(n)),null;o!==n&&t.reader.takeSignificant(),e==="description"&&o.content==="```"&&t.warning(l.LegacyInlineCodeFence,"A bare description fence is deprecated - use '```text' instead",p(o));let s=[];for(;;){let d=t.reader.takeRaw();if(d===void 0){t.error(l.UnclosedCodeBlock,"Unclosed inline code block - expected a closing ``` line",p(o));break}if(d.raw.trim()==="```")break;let f=0;for(;f<o.indent&&f<d.raw.length&&d.raw[f]===" ";)f++;s.push(d.raw.substring(f))}return s.join(`
4
+ `)}c(Ve,"parseFencedText");var sa=O(`^description\\s+"(${z})"$`);function Z(t,e,n,i,r=!1){if(e.content==="description"){let a=Ve(t,"description",e,r);return a===null?n:a.trim().length===0?(t.error(l.EmptyDescription,`${i} declares an empty description - the fenced block must contain text`,p(e)),n):Qi(t,e,n,i,a)}let o=sa.exec(e.content);return o===null?(t.error(l.InvalidDescription,`Invalid description '${e.content}' - expected 'description "<text>"'`,p(e)),n):Qi(t,e,n,i,Q(o[1]))}c(Z,"parseDescription");function Qi(t,e,n,i,r){return n!==null?(t.error(l.DuplicateDescription,`${i} already declares a description - at most one is allowed`,p(e)),n):r}c(Qi,"keep");var ca=_(`^depends${H}+on${H}+([A-Za-z_]\\w*(?:\\.[A-Za-z_]\\w*)*)$`);function qt(t,e,n,i){let r=ca.exec(e.content)?.[1];if(r===void 0){t.error(i,`Invalid dependency declaration '${e.content}' - expected 'depends on <Name>'`,p(e)),t.skipBlock(e.indent);return}if(n.some(o=>o.target===r)){t.warning(l.RepeatedDependencyDeclaration,`Dependency '${r}' is already declared on this container - this repeated declaration is ignored`,p(e));return}n.push({kind:"DependsOnSyntax",target:r,location:p(e)})}c(qt,"parseDependsOn");var la=O('^import\\s+"([^"\\\\]+)"$'),da=O('^import\\s+"'),Zi=c(t=>da.test(t),"isFileImport");function Gi(t){let e=la.exec(t.content);return e===null?void 0:{kind:"FileImportSyntax",pattern:e[1],location:p(t)}}c(Gi,"tryParseFileImport");function Qe(t,e,n){let i=Gi(e);if(i!==void 0){n.push(i);return}t.error(l.InvalidFileImport,`Invalid import '${e.content}' - inside a module or feature, import names files: 'import "<path or glob>"'`,p(e)),t.skipBlock(e.indent)}c(Qe,"parseFileImport");var R=c(t=>{let e=t.indexOf(" ");return e===-1?t:t.substring(0,e)},"firstWord"),G=c(t=>t.replaceAll("@",""),"unescapeIdentifier");function Ki(t,e){let n=[],i=0,r=!1,o=!1;for(let a=0;a<t.length;a++){let s=t[a];s==="\\"&&r&&a+1<t.length?a++:s==='"'&&!o?r=!r:s==="`"&&!r?o=!o:s===e&&!r&&!o&&(n.push(t.substring(i,a)),i=a+1)}return n.push(t.substring(i)),n}c(Ki,"splitTopLevel");var pa=O("^form\\s+[A-Za-z_]\\w*\\s+for\\s+([A-Za-z_]\\w*(?:\\.\\w+)*)$"),fa=O("^(execute|invokes)\\s+([A-Za-z_]\\w*(?:\\.\\w+)*)$"),ua=O("^field\\s+([\\w.]+)(?:\\s|$)"),ma=O("^with\\s+([A-Za-z_]\\w*)\\s+from\\s+.+$"),ya=O("^(@?[\\w.]+)\\s*=(?!=|>)\\s*.+$"),Sa=O("^parameter\\s+([A-Za-z_]\\w*)(?:\\s+([\\w.]+(?:\\[\\])?))?$"),ha=new Set(["refresh","navigate","open","close","set","notify","confirm","raise","on"]);function ge(t,e){let n=[],i=new Set,r=[],o=R(e.content)==="behavior",a=c(s=>{for(;n.length>0&&n[n.length-1].indent>=s.indent;)n.pop();let d=o&&n.length===0?Sa.exec(s.content):null;d!==null&&i.add(d[1]);let f=pa.exec(s.content),m=fa.exec(s.content);if(f!==null)n.push({command:f[1],kind:"form",indent:s.indent});else if(m!==null)n.push({command:m[2],kind:m[1],indent:s.indent});else if(ha.has(R(s.content)))n.push({command:"",kind:"other",indent:s.indent});else{let u=n.at(-1);if(u===void 0||u.kind==="other")return;let h=(u.kind==="form"?ua:u.kind==="execute"?ma:ya).exec(s.content);h!==null&&r.push({command:u.command,property:G(h[1]),scope:t.scope,location:p(s)})}},"recognize");a(e);for(let s=t.peekChild(e.indent);s!==void 0;s=t.peekChild(e.indent))t.reader.takeSignificant(),s.content.startsWith("```")?t.skipFencedBody():a(s);for(let s of r)t.inputUses.push(i.has(s.command)?{...s,isParameter:!0}:s)}c(ge,"collectInputUses");var _i=["StateChange","StateView","Automation","Translate"];var yt=["tag"];var ga=O(`^id\\s+"(${z})"$`),Ze=class{static{c(this,"EventMetadataParser")}name;value={id:null,description:null,documentation:null};constructor(e){this.name=e}tryParse(e,n){let i=p(n);switch(R(n.content)){case"id":{let r=ga.exec(n.content),o=r===null?"":Q(r[1]);return o.trim().length===0||this.value.id!==null?e.error(l.InvalidEventId,`Event '${this.name}' accepts one nonempty 'id "<old-name>"'`,i):(this.value.id=o,o===this.name&&e.information(l.RedundantEventId,`Event '${this.name}' already has this name as its identity - remove the redundant id`,i)),!0}case"description":return this.value.description=Z(e,n,this.value.description,`Event '${this.name}'`,!0),!0;case"documentation":{if(n.content!=="documentation"||e.peekChild(n.indent)?.content!=="```markdown")return e.error(l.InvalidEventDocumentation,`Event '${this.name}' documentation requires a fenced markdown block`,i),e.skipOpaqueBlock(n.indent),!0;let r=Ve(e,"markdown",n);return r===null||r.trim().length===0||this.value.documentation!==null?e.error(l.InvalidEventDocumentation,`Event '${this.name}' accepts one nonempty documentation block`,i):this.value.documentation=r,!0}default:return!1}}};var qn="79228162514264337593543950335";function Oe(t){let e=Ji(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),a=o<0?-o:0;if(o>28||r-i+a>qn.length)return;let s=n.substring(i,r)+"0".repeat(a);if(s.length===qn.length&&s>qn)return;let d=Math.max(0,o),f=d===0?s:s.length>d?`${s.substring(0,s.length-d)}.${s.substring(s.length-d)}`:`0.${"0".repeat(d-s.length)}${s}`;return Object.freeze({literalType:"ExactNumber",value:(e.negative?"-":"")+f})}c(Oe,"parseExactNumber");function St(t){return Ji(t)!==void 0}c(St,"isExactNumberToken");function Ji(t){let e=t.startsWith("-"),n=e?1:0,i=n;for(;i<t.length&&Bn(t[i]);)i++;if(i===n)return;let r=t.substring(n,i),o="";if(t[i]==="."){let s=++i;for(;i<t.length&&Bn(t[i]);)i++;if(i===s)return;o=t.substring(s,i)}let a=0;if(t[i]==="e"||t[i]==="E"){i++;let s=t[i]==="-";(t[i]==="+"||t[i]==="-")&&i++;let d=i,f=t.length+29;for(;i<t.length&&Bn(t[i]);)a=Math.min(f,a*10+t.charCodeAt(i++)-48);if(i===d)return;s&&(a=-a)}return i===t.length?{negative:e,integer:r,fraction:o,exponent:a}:void 0}c(Ji,"scan");function Bn(t){return t>="0"&&t<="9"}c(Bn,"isDigit");var Hi=64,fe=class extends Error{static{c(this,"InvalidStructuredValue")}},Bt=class{static{c(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.#o(),this.#e<this.text.length)throw new fe(`'${this.text[this.#e]}' is invalid after a single JSON value.`);return e}#t(e){this.#o();let n=this.#l(),i=this.text[this.#e];if(i==="["||i==="{"){if(e>=Hi)throw new fe(`The value nests deeper than ${Hi} levels.`);return i==="["?this.#r(e,n):this.#i(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.#d(n)}#r(e,n){this.#e++;let i=[];if(this.#o(),this.#s("]"))return{kind:"ListExpressionSyntax",items:i,location:n};for(;;){if(i.push(this.#t(e+1)),this.#o(),this.#s("]"))return{kind:"ListExpressionSyntax",items:i,location:n};this.#c(",")}}#i(e,n){this.#e++;let i=[],r=new Set;if(this.#o(),this.#s("}"))return{kind:"ObjectExpressionSyntax",members:i,location:n};for(;;){this.#o();let o=this.#l();if(this.text[this.#e]!=='"')throw new fe("Expected a property name in double quotes.");let a=this.#n();this.#o(),this.#c(":");let s=this.#t(e+1);if(r.has(a)?this.context?.error(l.DuplicateStructuredValueMember,`Duplicate property '${a}' in structured value`,o):(r.add(a),i.push({kind:"ObjectMemberSyntax",name:a,value:s,location:o})),this.#o(),this.#s("}"))return{kind:"ObjectExpressionSyntax",members:i,location:n};this.#c(",")}}#n(){let e=this.#a(this.#e),n=this.text.substring(this.#e,e);this.#e=e;try{return JSON.parse(n)}catch{throw new fe(`${n} is not a valid JSON string.`)}}#a(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 fe("A string is not closed.")}#d(e){let n=/^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/.exec(this.text.substring(this.#e));if(n===null)throw new fe(`'${this.text[this.#e]??""}' is an invalid start of a value.`);if(this.#e+=n[0].length,this.context?.sourceOptions.numericMode==="exact"){let r=Oe(n[0]);return r===void 0?(this.context.error(l.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 fe("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}}#o(){for(;this.#e<this.text.length&&`
5
+ \r`.includes(this.text[this.#e]);)this.#e++}#s(e){return this.text[this.#e]!==e?!1:(this.#e++,!0)}#c(e){if(!this.#s(e))throw new fe(`Expected '${e}' at position ${this.#e}.`)}};var xa=O("^@?[A-Za-z_]\\w*(\\.@?[A-Za-z_$]\\w*)*$"),va=_("^@?[A-Za-z_]\\w*(\\.@?[A-Za-z_$]\\w*)*$"),$a=O("^-?\\d+(\\.\\d+)?$"),Xi=["command","arguments","tenant","causedBy","causation","occurred","identity"],er=["subject","name","userName"],tr=["id","name","userName","isAuthenticated","roles","claims"];function ue(t,e,n){return ee(t,e,n,!0)}c(ue,"parseModeledMappingSource");function ee(t,e,n,i=!1){if(t=t.trim(),t.startsWith("$context.")){let o=t.substring(9);return ka(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 Bt(t,e,n).parse()}catch(o){if(!(o instanceof fe))throw o;return n?.error(l.InvalidStructuredValue,`Invalid inline structured value: ${o.message}`,e),{kind:"RawExpressionSyntax",text:t,location:e}}let r=n===void 0?ht(t,e):ht(t,e,n);return r!==void 0?r:(i||n?.sourceOptions.numericMode==="exact"?va:xa).test(t)?{kind:"PathExpressionSyntax",path:t,location:e}:{kind:"RawExpressionSyntax",text:t,location:e}}c(ee,"parseMappingSource");function ka(t,e,n){let[i,r]=t.split(".");Xi.includes(i)?r!==void 0&&i==="causedBy"&&!er.includes(r)?n?.warning(l.UnknownContextCausedByProperty,`Unknown $context.causedBy property '${r}' - expected ${er.join(", ")}`,e):r!==void 0&&i==="identity"&&!tr.includes(r)&&n?.warning(l.UnknownContextIdentityProperty,`Unknown $context.identity property '${r}' - expected ${tr.join(", ")}`,e):n?.warning(l.UnknownContextPath,`Unknown $context path '${t}' - expected one of ${Xi.join(", ")}`,e)}c(ka,"warnOnUnknownContextPath");function ht(t,e,n){let i=c(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(Q(t.substring(1,t.length-1)));if(n?.sourceOptions.numericMode==="exact"){if(!St(t))return;let o=Oe(t);return o!==void 0?i(o):(n.error(l.InexactNumericLiteral,"Numeric literal is not exactly representable in the bounded Decimal domain.",e),{kind:"RawExpressionSyntax",text:t,location:e})}if($a.test(t)&&!Number.isNaN(Number(t)))return i(Number(t))}c(ht,"parseLiteral");var ba=O("^[A-Za-z_]\\w*(?:\\[\\])?(?:\\?|\\s+optional)?$"),nr=c(t=>R(t.content)==="file"?t.content.substring(4).trim():"","pathOf"),ie=c(t=>nr(t).length>0,"isFileDirective"),Ft=c(t=>ie(t)&&!ba.test(nr(t)),"isFileDirectiveAmongProperties");var Ca=O("^(@?[a-z_]\\w*)\\s+([\\w.]+(?:\\[\\])?(?:\\?|\\s+optional)?)(?:\\s+(generated))?(?:\\s+(identifier))?$"),Ea=O("^@?[a-z_]\\w*\\s+[\\w.]+(?:\\[\\])?\\??\\s+((?:optional|generated|identifier)(?:\\s+(?:optional|generated|identifier))*)$"),Pa=O("^@?[a-z_]\\w*\\s+[\\w.]+(?:\\[\\])?\\s+identifier\\s+optional(?:\\s*=.*)?$");function Be(t){let e=Ca.exec(t.content);if(e===null)return;let n=p(t);return{kind:"PropertySyntax",name:G(e[1]),type:xe(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}}c(Be,"tryParseProperty");function xe(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}}c(xe,"parseTypeRef");function be(t,e){let n=Be(e);return n!==void 0?Ce(t,n.type,e):Yt(t,e),n}c(be,"parseProperty");function Ce(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(l.LegacyOptionalSuffix,`Write '${o} optional' instead of '${o}?'.`,e.location)}}c(Ce,"reportLegacyOptionalSuffix");function Yt(t,e){if(Pa.test(e.content))return t.error(l.InvalidOptionalModifierOrder,"Write 'optional' before 'identifier': '<name> <Type> optional identifier'.",p(e)),!0;{let n=Ea.exec(e.content);if(n!==null&&n[1].split(/\s+/).some(i=>i==="generated"||i==="identifier"))return t.error(l.InvalidGeneratedModifierOrder,"Write each modifier once in order: '<name> <Type> optional generated identifier'.",p(e)),!0}return!1}c(Yt,"reportInvalidModifierOrder");var Oa=O("^type\\s+([A-Za-z_]\\w*)$"),Aa=O("^event\\s+([A-Za-z_]\\w*)(?:\\s+generation\\s+([0-9]+))?$"),wa=O("^readmodel\\s+([A-Za-z_]\\w*)$"),ir=4294967295,Ia=O("^[A-Z]\\w*(?:\\[\\])?(?:\\?|\\s+optional)?$"),Ra=O("^[A-Za-z_]\\w*$"),rr=c(t=>R(t.content)==="description"&&Be(t)===void 0,"isDescription");function Fn(t,e,n,i,r){return e.isIdentifier?(t.error(i,r,p(n)),{...e,isIdentifier:!1}):e}c(Fn,"withoutIdentifier");function or(t,e){let n=Oa.exec(e.content)?.[1]??"";n===""&&t.error(l.InvalidTypeDeclaration,`Invalid type declaration '${e.content}' - expected 'type <Name>'`,p(e));let i=[],r=null;for(let o=t.peekChild(e.indent);o!==void 0;o=t.peekChild(e.indent)){if(t.reader.takeSignificant(),rr(o)){r=Z(t,o,r,`Type '${n}'`);continue}if(Ft(o))continue;let a=be(t,o);if(a===void 0){t.error(l.InvalidPropertyDeclaration,`Invalid property '${o.content}' - expected '<name> <Type>'`,p(o));continue}i.push(Fn(t,a,o,l.IdentifierOutsideCommand,`Property '${a.name}' of type '${n}' cannot be marked identifier - only a command property can be`))}return i.length===0&&t.error(l.TypeWithoutProperties,`Type '${n}' must declare at least one property`,p(e)),{kind:"TypeSyntax",name:n,properties:i,description:r,location:p(e)}}c(or,"parseType");function ar(t,e){let n=Aa.exec(e.content),i=n?.[1]??"";n===null&&t.error(l.InvalidEventDeclaration,`Invalid event declaration '${e.content}' - expected 'event <Name> [generation <N>]'`,p(e));let r=n?.[2]!==void 0,o=1;if(r){let f=Number(n[2]);!Number.isSafeInteger(f)||f===0||f>=ir?t.error(l.InvalidEventGeneration,`Event '${i}' must declare a generation between 1 and ${ir-1}`,p(e)):o=f}let a=[],s=[],d=new Ze(i);for(let f=t.peekChild(e.indent);f!==void 0;f=t.peekChild(e.indent)){if(t.reader.takeSignificant(),Ft(f))continue;if(yt.includes(R(f.content))){let u=gt(t,f);u!==void 0&&s.push(u);continue}let m=be(t,f);if(m===void 0){d.tryParse(t,f)||t.error(l.InvalidPropertyDeclaration,`Invalid property '${f.content}' - expected '<name> <Type>'`,p(f));continue}a.push(Fn(t,m,f,l.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:a,tags:s,generation:o,hasGenerationMarker:r,...d.value,location:p(e)}}c(ar,"parseEvent");function gt(t,e,n=!0){let i=e.content.substring(3).trim();if(n&&Ia.test(i)&&t.warning(l.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`,p(e)),i.length===0){t.error(l.TagWithoutValue,"Expected a value after 'tag' - an identifier, a string literal or a context expression",p(e));return}if(Ra.test(i))return{kind:"TagSyntax",value:{kind:"LiteralExpressionSyntax",value:i,location:p(e)},location:p(e)};let r=ee(i,p(e),t);if(r.kind==="RawExpressionSyntax"){t.error(l.InvalidTagValue,`Invalid tag value '${i}' - expected an identifier, a string literal or a context expression`,p(e));return}return{kind:"TagSyntax",value:r,location:p(e)}}c(gt,"parseTag");function sr(t,e){let n=wa.exec(e.content)?.[1]??"";n===""&&t.error(l.InvalidReadModelDeclaration,`Invalid read model declaration '${e.content}' - expected 'readmodel <Name>'`,p(e));let i=[],r=null;for(let o=t.peekChild(e.indent);o!==void 0;o=t.peekChild(e.indent))if(t.reader.takeSignificant(),rr(o))r=Z(t,o,r,`Read model '${n}'`);else{if(Ft(o))continue;{let a=be(t,o);if(a===void 0){t.error(l.InvalidPropertyDeclaration,`Invalid property '${o.content}' - expected '<name> <Type>'`,p(o));continue}i.push(Fn(t,a,o,l.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,location:p(e)}}c(sr,"parseReadModel");var Ta=_("^@?[A-Za-z_]\\w*(\\.@?[A-Za-z_$]\\w*)*$");function re(t,e,n){if(n=n.valueContext,t=t.trim(),t.startsWith("`")){let o=[];if(!t.endsWith("`")||t.length<2)return n.error(l.UnterminatedTemplateExpression,"Unterminated template expression - expected a closing backtick",e),{kind:"TemplateExpressionSyntax",parts:o,location:e};let a=t.substring(1,t.length-1),s=0;for(let d=0;d<a.length;d++){if(a[d]!=="$"||a[d+1]!=="{")continue;d>s&&o.push({kind:"TemplateTextSyntax",text:a.substring(s,d),location:e});let f=a.indexOf("}",d);if(f<0)return n.error(l.UnterminatedInterpolation,"Unterminated ${...} interpolation in template expression",e),{kind:"TemplateExpressionSyntax",parts:o,location:e};o.push({kind:"TemplateInterpolationSyntax",expression:re(a.substring(d+2,f),e,n),location:e}),d=f,s=f+1}return s<a.length&&o.push({kind:"TemplateTextSyntax",text:a.substring(s),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 ue(i,e,n);if(t.startsWith("literal ")){let o=ht(t.substring(8).trim(),e,n);return o!==void 0?o:(n.error(l.ExpectedLiteralValue,`Expected a literal value after 'literal', got '${t.substring(8).trim()}'`,e),{kind:"RawExpressionSyntax",text:t,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=ht(t,e,n);return r!==void 0?r:Ta.test(t)?{kind:"PathExpressionSyntax",path:t.replaceAll("@",""),location:e}:(n.error(l.InvalidExpression,`Invalid expression '${t}'`,e),{kind:"RawExpressionSyntax",text:t,location:e})}c(re,"parseProjectionExpression");var Ut=c(t=>({legacy:O(t),native:_(t)}),"grammar"),Da=Ut("^capture\\s+([A-Za-z_]\\w*)$"),Ma=Ut("^append\\s+([A-Z]\\w*)$"),ja=Ut("^children\\s+([a-z_]\\w*)\\s+identified\\s+by\\s+([\\w.]+)$"),Na=Ut("^nested\\s+([\\w.]+)$"),Wt=c((t,e)=>t.sourceOptions.numericMode==="exact"?e.native:e.legacy,"select"),La=_("^(@?[\\w.]+)\\s*=(?!=|>)\\s*(.+)$"),qa=_("^([a-z_]\\w*)\\s*=\\s*(.+)$"),Ba=_(`^"(${z})"\\s*=>\\s*(\\w+)$`),Fa=_(`^split\\s+(\\S+)\\s+by\\s+"(${z})"$`),Ya=new RegExp(_(`"${z}"|[\\w.]+`).source,"gu"),Wa=_("^[\\w.]+$");function Yn(t,e){t=t.valueContext;let n=Wt(t,Da).exec(e.content)?.[1]??"";n===""&&t.sourceOptions.numericMode==="exact"&&t.error(l.InvalidCaptureDeclaration,`Invalid capture declaration '${e.content}' - expected 'capture <Name>'`,p(e));let i=null,r=null,o=[],a=[],s=[],d=[];for(let f=t.peekChild(e.indent);f!==void 0;f=t.peekChild(e.indent))switch(t.reader.takeSignificant(),R(f.content)){case"source":i=Ua(t,f);break;case"key":r=f.content.substring(3).trim();break;case"map":o.push(...lr(t,f));break;case"append":dr(t,f,a);break;case"children":{let m=Wt(t,ja).exec(f.content);if(m===null){t.error(l.InvalidChildrenDeclaration,`Invalid children declaration '${f.content}' - expected 'children <collection> identified by <key>'`,p(f)),t.skipOpaqueBlock(f.indent);break}let u=cr(t,f);m!==null&&s.push({kind:"CaptureChildrenSyntax",property:m[1],identifiedBy:m[2],...u,location:p(f)});break}case"nested":{let m=Wt(t,Na).exec(f.content);if(m===null){t.error(l.InvalidNestedDeclaration,`Invalid nested declaration '${f.content}' - expected 'nested <Property>'`,p(f)),t.skipOpaqueBlock(f.indent);break}let u=cr(t,f);m!==null&&d.push({kind:"CaptureNestedSyntax",property:m[1],...u,location:p(f)});break}default:t.error(l.UnknownCaptureDirective,`Unexpected '${f.content}' in capture body`,p(f)),t.skipOpaqueBlock(f.indent)}return{kind:"CaptureSyntax",sourceOptions:t.sourceOptions,name:n,source:i,key:r,map:o,appends:a,children:s,nested:d,location:p(e)}}c(Yn,"parseCapture");function Ua(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:p(i)})}return{kind:"CaptureSourceSyntax",syntaxKind:e.content.substring(6).trim(),settings:n,location:p(e)}}c(Ua,"parseSource");function lr(t,e){let n=[];for(let i=t.peekChild(e.indent);i!==void 0;i=t.peekChild(e.indent)){t.reader.takeSignificant();let r=p(i);if(R(i.content)==="split"){let u=Fa.exec(i.content);if(u===null){t.error(l.InvalidSplitDeclaration,`Invalid split operation '${i.content}' - expected 'split <property> by "<separator>"'`,r),t.skipOpaqueBlock(i.indent);continue}let h=[];for(let g=t.peekChild(i.indent);g!==void 0;g=t.peekChild(i.indent))t.reader.takeSignificant(),Wa.test(g.content)?h.push(g.content):t.error(l.InvalidSplitTarget,`Invalid split target '${g.content}' - expected a property path`,p(g));u!==null&&n.push({kind:"CaptureSplitSyntax",source:re(u[1],r,t),separator:Q(u[2]),targets:h,location:r});continue}let o=qa.exec(i.content);if(o===null){t.error(l.InvalidMapEntry,`Invalid map entry '${i.content}' - expected '<property> = <source> [translate]'`,r),t.skipOpaqueBlock(i.indent);continue}let a=o[2].trim(),s=a.startsWith("`")?a.indexOf("`",1):-1,d=a.startsWith("`")?s>=0&&a.substring(s+1).trim()==="translate":a.endsWith(" translate"),f=a.startsWith("`")&&s>=0&&(t.sourceOptions.numericMode!=="exact"||d||a.substring(s+1).trim()==="")?a.substring(0,s+1):d?a.substring(0,a.length-10).trimEnd():a,m=[];if(d)for(let u=t.peekChild(i.indent);u!==void 0;u=t.peekChild(i.indent)){t.reader.takeSignificant();let h=Ba.exec(u.content);h!==null?m.push({kind:"CaptureTranslationSyntax",from:Q(h[1]),to:h[2],location:p(u)}):t.error(l.InvalidTranslation,`Invalid translation '${u.content}' - expected '"<source>" => <target>'`,p(u))}n.push({kind:"CaptureMapEntrySyntax",property:o[1],source:re(f,r,t),translations:m,location:r})}return n}c(lr,"parseMap");function cr(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=lr(t,r):R(r.content)==="append"?dr(t,r,i):(t.error(l.UnknownCaptureBlockDirective,`Unexpected '${r.content}' in ${R(e.content)} block - expected 'map' or 'append <EventType>'`,p(r)),t.skipOpaqueBlock(r.indent));return{map:n,appends:i}}c(cr,"mapAndAppends");function dr(t,e,n){let i=Wt(t,Ma).exec(e.content);if(i===null){t.error(l.InvalidAppendDeclaration,`Invalid append declaration '${e.content}' - expected 'append <EventType>'`,p(e)),t.skipOpaqueBlock(e.indent);return}let r=[],o=[],a=null,s=c((d,f=!1)=>{let m=p(d);if(R(d.content)==="tag"){let h=gt(t.valueContext,d,!1);h!==void 0&&o.push(h);return}let u=La.exec(d.content);u!==null?r.push({kind:"PropertyMappingSyntax",property:G(u[1]),source:ue(u[2],m,t.valueContext),location:m}):t.error(f?l.InvalidPropertyMapping:l.UnknownAppendDirective,`Unexpected '${d.content}' in append body`,m)},"mapping");for(let d=t.peekChild(e.indent);d!==void 0;d=t.peekChild(e.indent))if(t.reader.takeSignificant(),R(d.content)==="when"){a=za(t,d);for(let f=t.peekChild(d.indent);f!==void 0;f=t.peekChild(d.indent))t.reader.takeSignificant(),s(f,!0)}else s(d);n.push({kind:"CaptureAppendSyntax",event:i[1],when:a,mappings:r,tags:o,location:p(e)})}c(dr,"pushAppend");function za(t,e){let n=e.content.substring(4).trim(),i=p(e),r=c((d,f=[],m=null,u=null,h=null)=>({kind:"CaptureWhenSyntax",syntaxKind:d,properties:f,fromValue:m,toValue:u,expression:h,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(l.UnterminatedTemplateExpression,"Unterminated template expression in 'when' - expected a closing backtick",i),r("Expression",[],null,null,n);if(n.length===0)return t.error(l.WhenWithoutTrigger,"Expected a trigger after 'when'",i),null;let o=[...n.match(t.sourceOptions.numericMode==="exact"?new RegExp(`"${z}"|[^\\s]+`,"gu"):Ya)??[]],a=c(d=>d.startsWith('"')&&d.endsWith('"')?Q(d.substring(1,d.length-1)):d,"unquote");if(o.length===0)return t.error(l.InvalidWhenClause,`Invalid 'when' clause '${e.content}'`,i),null;if(o.length===1)return r("PropertyChanged",[a(o[0])]);if(o[1]==="from")return o.length===5&&o[3]==="to"?r("ValueTransition",[a(o[0])],a(o[2]),a(o[4])):(t.error(l.InvalidWhenTransitionClause,`Invalid 'when ... from ... to ...' clause '${e.content}'`,i),null);if(o[1]!=="or"&&o[1]!=="and")return t.error(l.InvalidWhenClause,`Invalid 'when' clause '${e.content}'`,i),null;if(o.length%2===0)return t.error(l.WhenCombinatorWithoutProperty,`Expected a property after '${o[1]}'`,i),null;let s=[a(o[0])];for(let d=1;d<o.length-1;d+=2){if(o[d]!==o[1])return t.error(l.MixedWhenCombinators,`Cannot mix 'and' and 'or' in a single 'when' clause '${e.content}'`,i),null;s.push(a(o[d+1]))}return r(o[1]==="or"?"LogicalOr":"LogicalAnd",s)}c(za,"parseWhen");var pr={"==":"Equal","!=":"NotEqual",">":"GreaterThan",">=":"GreaterThanOrEqual","<":"LessThan","<=":"LessThanOrEqual",contains:"Contains","starts with":"StartsWith"};function Ge(t,e,n){t=t.valueContext;let i=t.sourceOptions.numericMode==="exact"?"-?[0-9]+(?:\\.[0-9]+)?(?:[eE][+-]?[0-9]+)?(?=$|[\\s()])|":"",r=t.sourceOptions.numericMode==="exact"?"[\\w.$-]+|[^\\s]":"[\\w.$-]+",o=e.match(new RegExp(_(`"${z}"|==|!=|>=|<=|>|<|\\(|\\)|${i}${r}`).source,"gu"))??[],a=0,s=c(()=>{if(o[a]==="("){a++;let b=f();return o[a]===")"?a++:t.sourceOptions.numericMode==="exact"&&t.error(l.UnclosedConditionGroup,"Expected ')' in condition",n),b}let u=o[a++],h=o[a++];h==="starts"&&o[a]==="with"&&(h+=" with",a++);let g=o[a++];return u===void 0||g===void 0||pr[h]===void 0?null:{kind:"ComparisonConditionSyntax",left:u,operator:pr[h],right:ue(g,n,t),location:n}},"group"),d=c(()=>{let u=s();for(;u!==null&&o[a]==="and";){a++;let h=s();if(h===null)return null;u={kind:"LogicalConditionSyntax",left:u,operator:"And",right:h,location:n}}return u},"and"),f=c(()=>{let u=d();for(;u!==null&&o[a]==="or";){a++;let h=d();if(h===null)return null;u={kind:"LogicalConditionSyntax",left:u,operator:"Or",right:h,location:n}}return u},"or"),m=f();return t.sourceOptions.numericMode==="exact"&&(m===null?t.error(l.ExpectedCondition,"Expected a condition",n):a<o.length&&t.error(l.UnexpectedTokenInCondition,`Unexpected '${o[a]}' in condition`,n)),m}c(Ge,"parseCondition");function se(t){return O(`(?![\\s\\S]*[\\uD800-\\uDFFF\\u{10000}-\\u{10FFFF}])${t}`)}c(se,"sourceStreamPattern");var Va=se("^[A-Za-z_]\\w*(?![\\s\\S])"),Qa=se("^[\\w.]+(?![\\s\\S])");function Wn(t){return typeof t=="string"&&Va.test(t)}c(Wn,"isSourceStreamName");function Un(t){return typeof t=="string"&&Qa.test(t)}c(Un,"isSourceStreamTypeName");var Za=O(`^id\\s+"(${z})"$`),Ga=se("^(identifier|streamId)\\s+([\\w.]+(?:\\[\\])?(?:\\?|\\s+optional)?)$"),Ka=se("^eventsource\\s+([A-Za-z_]\\w*)$"),_a=se("^stream\\s+([A-Za-z_]\\w*)$");function fr(t,e){let n=Ka.exec(e.content)?.[1]??"";n===""&&Ke(t,e,"Expected 'eventsource <Name>'.");let i=[],r=null,o=null,a=null;for(let s=t.peekChild(e.indent);s!==void 0;s=t.peekChild(e.indent))switch(t.reader.takeSignificant(),R(s.content)){case"stream":i.push(Ja(t,s));break;case"identifier":r=ur(t,s,"identifier",r);break;case"description":o=Z(t,s,o,`Event source '${n}'`,!0);break;case"id":a=mr(t,s,n,a);break;default:Ke(t,s,"An event source accepts description, id, identifier and stream declarations."),t.skipBlock(s.indent);break}return{kind:"EventSourceSyntax",name:n,streams:i,identifier:r,description:o,id:a,location:p(e)}}c(fr,"parseEventSource");function Ja(t,e){let n=_a.exec(e.content)?.[1]??"";n===""&&Ke(t,e,"Expected 'stream <Name>'.");let i=null,r=null,o=null;for(let a=t.peekChild(e.indent);a!==void 0;a=t.peekChild(e.indent))switch(t.reader.takeSignificant(),R(a.content)){case"streamId":i=ur(t,a,"streamId",i);break;case"description":r=Z(t,a,r,`Stream '${n}'`,!0);break;case"id":o=mr(t,a,n,o);break;default:Ke(t,a,"A stream accepts description, id and streamId declarations."),t.skipBlock(a.indent);break}return{kind:"EventStreamSyntax",name:n,streamId:i,description:r,id:o,location:p(e)}}c(Ja,"parseEventStream");function ur(t,e,n,i){let r=Ga.exec(e.content);return r===null||i!==null?Ke(t,e,`Declare at most one '${n} <Type>'.`):(i=xe(r[2],{...p(e),column:e.indent+1+e.content.indexOf(r[2],n.length)}),Ce(t,i,e)),zn(t,e,l.InvalidEventSourceDeclaration),i}c(ur,"parseType");function mr(t,e,n,i){let r=Za.exec(e.content),o=r===null?null:Q(r[1]);return o===null||o.trim()===""||i!==null?Ke(t,e,`Declare at most one nonempty rename-only 'id "<old-name>"'.`):(i=o,o===n&&t.information(l.RedundantSourceStreamId,"The rename pin repeats the current name; omit it for a new declaration.",p(e))),zn(t,e,l.InvalidEventSourceDeclaration),i}c(mr,"parsePin");function yr(t,e,n,i){let[r,o]=n.type.name.split("."),a={kind:"CommandStreamSyntax",eventSource:r,stream:o,streamId:null,propertyCandidate:null,referenceLocation:n.type.location,referenceLength:n.type.name.length,location:p(e)};if(i)return t.error(l.AmbiguousCommandStream,`'${e.content}' has both a property type and a stream route interpretation; neither is selected.`,p(e)),{...a,propertyCandidate:n};let s=null;for(let d=t.peekChild(e.indent);d!==void 0;d=t.peekChild(e.indent)){t.reader.takeSignificant();let f=/^streamId\s*=\s*(.+)$/.exec(d.content);if(f===null||s!==null)t.error(l.InvalidCommandStream,"A command stream accepts at most one 'streamId = <source>' mapping.",p(d)),t.skipBlock(d.indent);else{let m={...p(d),column:d.indent+1+d.content.indexOf(f[1],d.content.indexOf("=")+1)};s={kind:"PropertyMappingSyntax",property:"streamId",source:ee(f[1],m,t),location:p(d)},zn(t,d,l.InvalidCommandStream)}}return{...a,streamId:s}}c(yr,"parseCommandStream");function zn(t,e,n){let i=t.peekChild(e.indent);i!==void 0&&(t.error(n,"This directive cannot have children.",p(i)),t.skipBlock(e.indent))}c(zn,"rejectChildren");function Ke(t,e,n){t.error(l.InvalidEventSourceDeclaration,n,p(e))}c(Ke,"invalid");var Vn=O("^returns\\s+(@?[A-Za-z_]\\w*)$"),Ha=O("^(@?[a-z_]\\w*)(?:\\s+([\\w.]+(?:\\[\\])?(?:\\?|\\s+optional)?))?\\s*=(?!=|>)\\s*(@?[a-z_]\\w*)$");function Qn(t,e){let n=p(e);if(e.content!=="returns"){let r=Vn.exec(e.content);if(r===null)return t.error(l.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(l.InvalidCommandResponse,"A scalar response cannot have child directives.",p(o)),t.skipBlock(e.indent));let a=r.index+r[0].length-r[1].length;return{kind:"ScalarCommandResponseSyntax",source:{kind:"PropertyResponseSourceSyntax",property:G(r[1]),location:{...n,column:n.column+a}},location:n}}let i=[];for(let r=t.peekChild(e.indent);r!==void 0;r=t.peekChild(e.indent)){t.reader.takeSignificant();let o=Ha.exec(r.content);if(o===null){t.error(l.InvalidCommandResponse,"Expected '<field> [<Type>] = <property>' in a response block.",p(r)),t.skipBlock(r.indent);continue}let a=p(r),s=o[2]===void 0?null:xe(o[2],{...a,column:a.column+r.content.indexOf(o[2],o[1].length)});s!==null&&Ce(t,s,r),i.push({kind:"ResponseFieldSyntax",name:G(o[1]),type:s,source:{kind:"PropertyResponseSourceSyntax",property:G(o[3]),location:{...a,column:a.column+r.content.lastIndexOf(o[3])}},location:a});let d=t.peekChild(r.indent);d!==void 0&&(t.error(l.InvalidCommandResponse,"A response field cannot have child directives.",p(d)),t.skipBlock(r.indent))}return{kind:"RecordCommandResponseSyntax",fields:i,location:n}}c(Qn,"parseCommandResponse");var Xa=new Set([32,133,160,5760,8232,8233,8239,8287,12288]);function zt(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||Xa.has(n)))return!1}return!0}c(zt,"isBlankImplementationHint");var Sr=new RegExp('^hint[\\u0009-\\u000d\\u0020\\u0085\\u00a0\\u1680\\u2000-\\u200a\\u2028\\u2029\\u202f\\u205f\\u3000]+"((?:[^"\\\\\\r\\n]|\\\\[^\\r\\n])*)"$'),_e=c(t=>R(t.content)==="file"&&t.content.substring(4).trim().length>0,"isFile"),xt=c((t,e)=>e.content.startsWith("```")||t.languages.has(e.content),"isCode");function Me(t,e){let n=e.content.substring(4).trim();return/^(?:[/\\]|[A-Za-z]:[/\\]|~[/\\])/.test(n)&&t.warning(l.AbsoluteFileReference,`'${n}' is an absolute path - a file reference is relative to the repository root, so it means the same thing on every machine`,p(e)),{kind:"FileReferenceSyntax",path:n,location:p(e)}}c(Me,"parseFile");var Zn=c(t=>t.raw.trim()==="```","isClosingCodeFence");function me(t,e){let n=e.content.startsWith("```")?e.content.substring(3):e.content;if(!t.languages.has(n))return t.error(l.ExpectedCodeFence,`Expected a registered language on the opening fence, not '${e.content}'`,p(e)),null;let i=e;if(!e.content.startsWith("```")){t.warning(l.LegacyInlineCodeFence,`'${n}' on its own line is deprecated - use '\`\`\`${n}' instead`,p(e));let o=t.reader.peekSignificant();if(o===void 0||o.indent<=e.indent||o.content!=="```"&&o.content!==`\`\`\`${n}`)return t.error(l.ExpectedCodeFence,`Expected an opening \`\`\`${n} fence after '${n}'`,p(e)),null;i=t.reader.takeSignificant()}let r=[];for(;;){let o=t.reader.takeRaw();if(o===void 0){t.error(l.UnclosedCodeBlock,"Unclosed inline code block - expected a closing ``` line",p(i));break}if(Zn(o))break;let a=0;for(;a<i.indent&&o.raw[a]===" ";)a++;r.push(o.raw.substring(a))}return{kind:"CodeBlockSyntax",language:n,code:r.join(`
6
+ `),location:p(e)}}c(me,"parseCode");function hr(t,e){let n=t.peekChild(e.indent);if(n===void 0)return t.error(l.HandlerWithoutImplementation,"Expected a 'file' directive or an inline code block in the handler",p(e)),null;if(t.reader.takeSignificant(),R(n.content)==="implementation")return es(t,e,n);let i=_e(n)?Me(t,n):null,r=i===null&&xt(t,n)?me(t,n):null;if(i!==null||r!==null){let o=t.peekChild(e.indent);return o!==void 0&&R(o.content)==="implementation"&&(t.error(l.ConflictingImplementationSources,"A handler cannot mix wrapped and direct sources.",p(o)),t.skipBlock(e.indent)),{kind:"HandlerSyntax",file:i,code:r,implementation:null,location:p(e)}}return t.error(l.UnknownHandlerDirective,`Unexpected '${n.content}' in handler - expected 'file <path>' or an inline code block`,p(n)),t.skipBlock(e.indent),null}c(hr,"parseHandler");function es(t,e,n){let i=vt(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"?l.InvalidImplementationBlock:l.ConflictingImplementationSources,"A handler has one implementation wrapper and cannot mix wrapped and direct sources.",p(r)),xt(t,r)?me(t,r):t.skipBlock(r.indent);return{kind:"HandlerSyntax",...i,location:p(e)}}c(es,"parseImplementation");function vt(t,e){let n=[],i=null,r=null,o=!1;e.content!=="implementation"&&t.error(l.InvalidImplementationBlock,"Expected 'implementation' with no operand.",p(e));for(let a=t.peekChild(e.indent);a!==void 0;a=t.peekChild(e.indent))if(t.reader.takeSignificant(),R(a.content)==="hint"||Sr.test(a.content)){let s=Sr.exec(a.content),d=s===null?null:Q(s[1]);zt(d)?t.error(l.InvalidImplementationHint,"Expected 'hint' followed by one nonblank quoted string.",p(a)):n.push({kind:"ImplementationHintSyntax",text:d,location:p(a)});let f=t.peekChild(a.indent);f!==void 0&&(t.error(l.InvalidImplementationHint,"A hint cannot have children.",p(f)),t.skipBlock(a.indent))}else if(_e(a)||a.content.startsWith("```")){o&&t.error(l.ConflictingImplementationSources,"An implementation has at most one file or inline payload.",p(a));let s=_e(a)?Me(t,a):null,d=s===null?me(t,a):null;o||(i=s,r=d),o=!0;let f=t.peekChild(a.indent);s!==null&&f!==void 0&&(t.error(l.InvalidImplementationBlock,"A file directive cannot have children.",p(f)),t.skipBlock(a.indent))}else t.error(l.InvalidImplementationBlock,`Unexpected '${a.content}' in implementation - expected hint, file or a tagged fence.`,p(a)),t.skipBlock(a.indent);return{file:i,code:r,implementation:{kind:"ImplementationSyntax",hints:n,location:p(e)}}}c(vt,"parseImplementationWrapper");var X=class extends Error{static{c(this,"InvalidSyntaxJson")}};var ye=Object.freeze({numericMode:"legacy"}),Vt=Object.freeze({numericMode:"exact"}),gr=Object.freeze({numericMode:"invalid"});function Je(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 X("Malformed source numeric options.");let e=t.numericMode;if(e!=="legacy"&&e!=="exact")throw new X("Malformed source numeric options.");return e==="exact"?Vt:ye}c(Je,"validatedSourceOptions");var xr=new WeakSet;function vr(t){xr.add(t)}c(vr,"recordAuthoredDocument");function $r(t){return xr.has(t)}c($r,"isAuthoredDocument");var pe=class t{static{c(this,"ParserContext")}reader;path;#e=[];triggerData=[];inputUses=[];scope=[];languages;sourceOptions=ye;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 ze(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 Qt=new WeakMap;var Fe=new WeakMap,He=c(t=>Fe.get(t)??{},"dependencySourcesOf");function Zt(t){let e=O(`^reads${H}+([A-Z]\\w*)(?:${H}+as${H}+([a-z_]\\w*))?(?:${H}+by${H}+([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:p(t)}}c(Zt,"captureReads");function kr(t){return new pe(t.reader.fork(),t.path,t.languages)}c(kr,"fork");function br(t,e){if(e.content!=="concurrency")return;let n=kr(t),i=!1,r={},o;for(let a=n.peekChild(e.indent);a!==void 0;a=n.peekChild(e.indent))switch(n.reader.takeSignificant(),R(a.content)){case"eventSource":a.content==="eventSource"&&(i=!0);break;case"sourceType":case"streamType":case"streamId":{let s=O(`^(sourceType|streamType|streamId)${H}+([A-Za-z_]\\w*)$`).exec(a.content);s!==null&&(r[s[1]]??=s[2]);break}case"events":{if(o!==void 0)break;let s=a.content.slice(6).split(",").map(d=>d.replace(new RegExp(`^${H}+|${H}+$`,"gu"),"")).filter(Boolean);s.length>0&&s.every(d=>O("^[A-Z]\\w*$").test(d))&&(o=s);break}default:n.skipBlock(a.indent);break}return{kind:"ConcurrencySyntax",eventSource:i,eventSourceType:r.sourceType??null,eventStreamType:r.streamType??null,eventStreamId:r.streamId??null,eventTypes:o??[],location:p(e)}}c(br,"captureConcurrency");function Cr(t,e){let n=O(`^reducer${H}+([A-Za-z_]\\w*)${H}*=>${H}*([A-Za-z_]\\w*)$`).exec(e.content),i=kr(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"){Z(i,o,null,"Reducer");continue}let a=O(`^on${H}+([A-Z]\\w*)$`).exec(o.content);a!==null&&r.push({kind:"ReducerRuleSyntax",event:a[1],file:null,code:null,description:null,location:p(o)}),i.skipOpaqueBlock(o.indent)}return{kind:"ReducerSyntax",name:n?.[1]??"",readModel:n?.[2]??"",rules:r,description:null,location:p(e)}}c(Cr,"captureReducer");var ts=O("^system\\s+([A-Za-z_]\\w*)$"),ns=O("^operation\\s+([A-Za-z_]\\w*)$"),is=O("^produces\\s+operation\\s+([A-Za-z_]\\w*)$"),Gn=O("^uses\\s+([A-Za-z_]\\w*)$"),rs=O("^(.+?)\\s*=(?!=|>)\\s*(.+)$"),os=new Set(["for","tag","generation","origin","documentation","namespace","sequence","correlation","causation","causedBy","occurred"]);function $t(t,e,n,i){let r=t.peekChild(e.indent);r!==void 0&&(t.error(n,i,p(r)),t.skipBlock(e.indent))}c($t,"rejectOperationChildren");function Er(t,e){let n=ts.exec(e.content);n===null&&t.error(l.InvalidSystemDeclaration,"Expected 'system <Name>'.",p(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=Z(t,r,i,`System '${n?.[1]??""}'`):(t.error(l.InvalidSystemDeclaration,"A system accepts only a description; abilities are not supported.",p(r)),t.skipBlock(r.indent));return{kind:"SystemSyntax",name:n?.[1]??"",description:i,location:p(e)}}c(Er,"parseSystem");function Gt(t,e,n=!1){let i=(n?is:ns).exec(e.content),r=i?.[1]??"";i===null&&t.error(l.InvalidOperationDeclaration,"Expected an operation declaration with one name.",p(e));let o=null,a=null,s=p(e),d=null,f=null,m=[],u=[],h=new Set;for(let g=t.peekChild(e.indent);g!==void 0;g=t.peekChild(e.indent)){t.reader.takeSignificant();let b=rs.exec(g.content),x=n&&b!==null?{...g,content:b[1].trimEnd()}:g;if(b===null&&os.has(R(g.content))){t.error(l.InvalidOperationDeclaration,"Operations cannot declare event routing or metadata; escape a keyword-named input with @.",p(g)),t.skipBlock(g.indent);continue}if(!Gn.test(g.content)&&Be(x)!==void 0){let $=be(t,x);n&&b===null&&t.error(l.InvalidOperationMapping,"An inline operation input requires '<property> <Type> = <source>'.",p(g)),($.isIdentifier||$.isGenerated)&&t.error(l.InvalidOperationDeclaration,"Operation inputs cannot be identifier or generated properties.",p(g)),h.has($.name)&&t.error(l.DuplicateDeclaration,`Operation '${r}' already declares input '${$.name}'.`,p(g)),h.add($.name),m.push($),n&&b!==null&&u.push({kind:"PropertyMappingSyntax",property:$.name,source:ee(b[2],{...p(g),column:g.indent+g.content.length-b[2].length+1},t),location:p(g)}),$t(t,g,l.InvalidOperationDeclaration,"An operation input cannot have children.")}else if(R(g.content)==="description")o=Z(t,g,o,`Operation '${r}'`);else if(Gn.test(g.content))a!==null?t.error(l.InvalidSystemReference,"An operation declares exactly one 'uses <System>'.",p(g)):(a=Gn.exec(g.content)[1],s={...p(g),column:p(g).column+g.content.indexOf(a,4)}),$t(t,g,l.InvalidSystemReference,"A system reference cannot have children.");else if(g.content==="execute"||g.content==="compensate"){let $=as(t,g);g.content==="execute"?d!==null?t.error(l.InvalidOperationDeclaration,"An operation declares execute at most once.",p(g)):d=$:f!==null?t.error(l.InvalidOperationDeclaration,"An operation declares compensate at most once.",p(g)):f=$}else t.error(l.InvalidOperationDeclaration,`Unexpected '${g.content}' in operation - expected uses, an input, description, execute or compensate.`,p(g)),t.skipBlock(g.indent)}return a===null&&t.error(l.InvalidSystemReference,"An operation requires exactly one 'uses <System>'.",p(e)),{operation:{kind:"OperationSyntax",name:r,uses:a??"",usesLocation:s,inputs:m,description:o,execute:d,compensate:f,location:p(e)},mappings:u}}c(Gt,"parseOperation");function as(t,e){let n=null,i=null,r=null,o=null,a=!1;for(let s=t.peekChild(e.indent);s!==void 0;s=t.peekChild(e.indent)){if(t.reader.takeSignificant(),R(s.content)==="description"){n=Z(t,s,n,`Operation phase '${e.content}'`);continue}if(R(s.content)==="implementation"){a&&t.error(l.ConflictingImplementationSources,"A phase cannot mix wrapped and direct sources or repeat its wrapper.",p(s));let d=vt(t,s);a||(i=d.file,r=d.code,o=d.implementation),a=!0}else if(ie(s)||s.content.startsWith("```")){a&&t.error(l.ConflictingImplementationSources,"A phase has at most one file or inline payload.",p(s));let d=ie(s)?Me(t,s):null,f=d===null?me(t,s):null;a||(i=d,r=f),a=!0,d!==null&&$t(t,s,l.InvalidImplementationBlock,"A file directive cannot have children.")}else t.error(l.InvalidOperationDeclaration,"A phase accepts description, file, a tagged fence or implementation.",p(s)),t.skipBlock(s.indent)}return{kind:"OperationPhaseSyntax",description:n,file:i,code:r,implementation:o,location:p(e)}}c(as,"parseOperationPhase");var ss=O("^produces\\s+operation(?:\\s|$)"),cs=O("^produces\\s+event\\s+([A-Za-z_]\\w*)(?:\\s+(generation)(?:\\s+.*)?)?$"),ls=O("^produces\\s+([A-Z]\\w*(?:\\.[A-Za-z_]\\w*)*)$"),Pr=O("^produces\\s+when\\s+(.+)$"),ds=O("^[A-Z]\\w*(?:\\.[A-Za-z_]\\w*)*$"),ps=O("^for\\s+(\\S.*)$"),fs=O("^(@?[\\w.]+)\\s*=(?!=|>)\\s*(.+)$"),us=O("^(.+?)\\s*=(?!=|>)\\s*(.+)$"),ms=new Set(["namespace","sequence","correlation","causation","causedBy","occurred"]);function Kt(t,e,n=!1){if(ss.test(e.content)){if(!n){t.error(l.OperationOutsideCommand,"Operations can only be produced by commands.",p(e)),t.skipOpaqueBlock(e.indent);return}let b=Gt(t,e,!0);return{kind:"ProducesSyntax",when:null,event:b.operation.name,targetLocation:{...p(e),column:e.indent+e.content.match(/^produces\s+operation(?:\s+|$)/)[0].length+1},inlineEvent:null,inlineOperation:b.operation,mappings:b.mappings,for:null,tags:[],location:p(e)}}let i=cs.exec(e.content),r=e,o=null,a,s;if(i!==null){if(!n){t.error(l.InlineEventOutsideCommand,"Inline events can only be declared inside commands",p(e)),t.skipOpaqueBlock(e.indent);return}i[2]!==void 0&&t.error(l.InlineEventGeneration,"Inline events are generation 1 - extract the event before declaring generations",p(e)),a=i[1],s=e.indent+e.content.match(/^produces\s+event\s+/)[0].length+1}else if(Pr.test(e.content)){o=Ge(t,Pr.exec(e.content)[1],p(e));let b=t.peekChild(e.indent);if(b===void 0||!ds.test(b.content)){t.error(l.ProducesWhenWithoutEvent,"Expected an event name on the line after 'produces when'",p(e)),t.skipOpaqueBlock(e.indent);return}t.reader.takeSignificant(),r=b,a=b.content,s=b.indent+1}else{let b=ls.exec(e.content);if(b===null){t.error(l.InvalidProducesDeclaration,`Invalid produces declaration '${e.content}' - expected 'produces <EventType>' or 'produces when <condition>'`,p(e)),t.skipOpaqueBlock(e.indent);return}a=b[1],s=e.indent+e.content.match(/^produces\s+/)[0].length+1}let d=[],f=new Set,m=[],u=[],h=new Ze(a),g=null;for(let b=t.peekChild(r.indent);b!==void 0;b=t.peekChild(r.indent)){t.reader.takeSignificant();let x=R(b.content),$=p(b);if(ms.has(x)){t.error(l.ReservedProductionMetadata,`'${x}' is system-assigned production metadata and cannot be supplied here`,$),t.skipOpaqueBlock(b.indent);continue}if(i!==null&&(x==="generation"||x==="origin")){t.error(x==="generation"?l.InlineEventGeneration:l.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(b.indent);continue}if(x==="tag"){let S=gt(t,b,!1);S!==void 0&&u.push(S);continue}let v=ps.exec(b.content);if(v!==null){g!==null?t.error(l.DuplicateProducesTarget,`'${r.content}' already declares where it lands - an event is appended to one event source`,$):g=ee(v[1],$,t);continue}let k=(i===null?fs:us).exec(b.content),P=k===null||i===null?void 0:be(t,{...b,content:k[1].trimEnd()});if(k!==null&&(i===null||P!==void 0)){if(P!==void 0){P.isIdentifier&&(t.error(l.IdentifierOnEventProperty,`Property '${P.name}' of event '${a}' cannot be marked identifier - an event never carries its event source id`,$),P={...P,isIdentifier:!1});let S=P.name;f.has(S)&&t.error(l.DuplicateDeclaration,`Event '${a}' already declares property '${P.name}'`,$),f.add(S),d.push(P)}m.push({kind:"PropertyMappingSyntax",property:P?.name??G(k[1]),source:ee(k[2],{...$,column:b.indent+b.content.length-k[2].length+1},t),location:$})}else(i===null||!h.tryParse(t,b))&&t.error(l.InvalidPropertyMapping,`Invalid ${i===null?"":"inline "}property mapping '${b.content}' - expected '<property>${i===null?"":" <Type>"} = <source>'`,$)}return r!==e&&t.skipBlock(e.indent),{kind:"ProducesSyntax",when:o,event:a,targetLocation:{...p(r),column:s},inlineOperation:null,mappings:m,for:g,tags:i===null?u:[],location:p(e),inlineEvent:i===null?null:{kind:"EventSyntax",name:a,properties:d,tags:u,generation:1,hasGenerationMarker:!1,...h.value,location:p(e)}}}c(Kt,"parseProduces");var ys=O("^command\\s+([A-Za-z_]\\w*)$"),Ss=se("^stream\\s+[A-Za-z_]\\w*\\.[A-Za-z_]\\w*$"),hs=O("\\bseverity\\s+(\\S+)$"),Ar=O(`\\bmessage\\s+(?:"(${z})"|(\\$strings\\.\\S*))$`),gs=O("^([\\w.]+)\\s+(.+)$"),xs=O("^(not empty|length ==|all >=|all >|matches|max|min|rule|>=|<=|==|!=|>|<)\\s*(.*)$"),vs=se("^[A-Za-z_]\\w*$"),$s=O("^reads\\s+[A-Z]\\w*\\s+optional(?:\\s|$)"),ks={max:"Max",min:"Min",">":"GreaterThan",">=":"GreaterThanOrEqual","<":"LessThan","<=":"LessThanOrEqual","==":"Equal","!=":"NotEqual","length ==":"Length",matches:"Matches","all >":"AllGreaterThan","all >=":"AllGreaterThanOrEqual"},wr={information:"Information",warning:"Warning",error:"Error"},bs=new Set(["reads","concurrency"]),Cs=new Set(["description","handler","concurrency"]);function Ir(t,e){let n=new Set,i=new pe(t.reader.fork(),t.path,t.languages);return i.sourceOptions=t.sourceOptions,i.streamCandidates=t.streamCandidates,Or(i,e,void 0,n),Or(t,e,n)}c(Ir,"parseCommand");function Or(t,e,n,i){let r=ys.exec(e.content)?.[1]??"";r===""&&t.error(l.InvalidCommandDeclaration,`Invalid command declaration '${e.content}' - expected 'command <Name>'`,p(e));let o=[],a=[],s,d=[],f=[],m=[],u=[],h,g=null,b=null,x=null,$=null,v=[];for(let E=t.peekChild(e.indent);E!==void 0;E=t.peekChild(e.indent)){t.reader.takeSignificant();let A=R(E.content),w=Be(E);if(w!==void 0&&(Cs.has(A)||A==="validate"&&E.content!=="validate csharp"))s=_t(t,o,w,r,E,s);else if(A==="returns"){let D=Vn.exec(E.content);D!==null&&!D[1].startsWith("@")&&w!==void 0?n===void 0?(o.push(w),a.push({line:E,candidate:w,response:null})):n.has(w.type.name)?a.push({line:E,candidate:null,response:Qn(t,E)}):s=_t(t,o,w,r,E,s):w!==void 0?s=_t(t,o,w,r,E,s):Yt(t,E)?t.skipBlock(E.indent):a.push({line:E,candidate:null,response:Qn(t,E)})}else if(A==="stream"&&Ss.test(E.content)&&w!==void 0&&t.streamCandidates?.hasSource(w.type.name.split(".")[0])===!0){let[D,j]=w.type.name.split("."),q=t.streamCandidates.hasPropertyType(w.type.name)&&t.streamCandidates.hasUniqueStream(D,j),M=yr(t,E,w,q);($!==null||v.length>0)&&t.error(l.InvalidCommandStream,"A command declares at most one stream route.",p(E)),q||$!==null?v.push(M):$=M}else if(A==="description")g=Z(t,E,g,`Command '${r}'`);else if(A==="authorize")b=ke(b,De(t,E));else if(A==="validate"){let D=Kn(t,E,"command");D!==void 0&&d.push(D)}else if(A==="produces"){let D=Kt(t,E,!0);D!==void 0&&f.push(D)}else if(A==="handler")x=hr(t,E);else if(bs.has(A)){let D=Zt(E);D!==void 0&&u.push(D),A==="concurrency"&&h===void 0&&(h=br(t,E));let j=/^reads\s+([A-Z]\w*)(?:\s+as\s+([a-z_]\w*))?(?:\s+by\s+([a-z_]\w*))?$/.exec(E.content);j!==null&&m.push({readModel:j[1],alias:j[2]??null}),$s.test(E.content)&&t.error(l.OptionalReadsNotSupported,"Optional reads are not yet supported (see #308).",p(E)),t.skipOpaqueBlock(E.indent)}else w!==void 0?s=_t(t,o,w,r,E,s):(Yt(t,E),t.error(l.UnknownCommandDirective,`Unexpected '${E.content}' in command body`,p(E)),t.skipBlock(E.indent))}let k=new Set(a.flatMap(E=>E.candidate===null?[]:[E.candidate])),P=new Set(o.filter(E=>!k.has(E)).map(E=>E.name));a.some(E=>E.candidate!==null&&!P.has(E.candidate.type.name)&&E.candidate.type.name!=="returns")&&P.add("returns");for(let E of P)i?.add(E);let S=null,y=new Set;for(let E of a){let A=E.response;if(E.candidate!==null){if(!P.has(E.candidate.type.name))continue;y.add(E.candidate),A={kind:"ScalarCommandResponseSyntax",source:{kind:"PropertyResponseSourceSyntax",property:E.candidate.type.name,location:E.candidate.type.location},location:p(E.line)}}A!==null&&(S!==null?t.error(l.InvalidCommandResponse,"A command declares at most one unconditional response.",p(E.line)):S=A)}x!==null&&f.length>0&&t.error(l.CommandWithProducesAndHandler,`Command '${r}' cannot declare both 'produces' and 'handler'`,p(e));let C={kind:"CommandSyntax",name:r,description:g,authorize:b,properties:o.filter(E=>!y.has(E)),validations:d,produces:f,handler:x,response:S,stream:$,streamCandidates:v,location:p(e)};return Qt.set(C,m),Fe.set(C,{reads:u,concurrency:h}),C}c(Or,"parseCommandBody");function _t(t,e,n,i,r,o){return Ce(t,n.type,r),n.isIdentifier&&o!==void 0&&(t.error(l.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)}c(_t,"addProperty");function Kn(t,e,n){if(e.content==="validate"){let i=t.peekChild(e.indent);if(i!==void 0&&i.content.startsWith("```")){t.reader.takeSignificant();let s=me(t.valueContext,i);return s===null&&t.skipFencedBody(),{kind:"CodeValidateSyntax",code:s,location:p(e)}}let r=[],o=[],a;for(let s=t.peekChild(e.indent);s!==void 0;s=t.peekChild(e.indent)){if(t.reader.takeSignificant(),n==="concept"){if(t.sourceOptions.numericMode==="legacy"&&s.content.startsWith("```")){t.skipFencedBody();continue}if(a!==void 0&&s.indent<=a&&(a=void 0),a!==void 0||R(s.content)==="implementation"){t.error(l.InvalidValidationRule,`Invalid validation rule '${s.content}'`,p(s)),a??=s.indent;continue}}if(R(s.content)==="require"){let f=Ge(n==="concept"?t.valueContext:t,s.content.substring(7).trim(),p(s)),m=null,u="Error",h=!1;for(let g=t.peekChild(s.indent);g!==void 0;g=t.peekChild(s.indent)){t.reader.takeSignificant();let b=Ar.exec(g.content);b!==null&&b.index===0?m=b[1]!==void 0?Q(b[1]):b[2]:R(g.content)==="severity"?(h||(u=wr[g.content.substring(8).trim()]??"Error"),h=!0):t.skipOpaqueBlock(g.indent)}f!==null&&o.push({kind:"RequirementSyntax",condition:f,message:m,severity:u,location:p(s)});continue}let d=Es(t,n==="concept"?{...s,content:`value ${s.content}`}:s,n);d!==void 0&&r.push(d)}return{kind:"DeclarativeValidateSyntax",rules:r,requirements:o,location:p(e)}}if(e.content==="validate csharp"){let i=me(t.valueContext,{...e,content:"csharp"});return i===null&&t.skipOpaqueBlock(e.indent),{kind:"CodeValidateSyntax",code:i,location:p(e)}}t.error(l.InvalidValidateDeclaration,`Invalid validate declaration '${e.content}' - expected 'validate' or 'validate csharp'`,p(e)),t.skipBlock(e.indent)}c(Kn,"parseValidate");function Es(t,e,n){let i=n==="concept"?t.valueContext:t,{content:r,message:o}=Os(e.content),a=As(i,e,r);if(a===void 0)return;let s=gs.exec(a.content);if(s===null){i.error(l.InvalidValidationRule,`Invalid validation rule '${e.content}'`,p(e));return}let d=ws(i,s[2],e);if(d===void 0)return;let f=d.kind==="Rule"?Ps(t,e,n==="command"):{file:null,code:null,implementation:null};return{kind:"ValidationRuleSyntax",property:s[1],rule:d.kind,value:d.value,message:o,severity:a.severity,...f,location:p(e)}}c(Es,"parseValidationRule");function Ps(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?vt(t,i):{file:_e(i)?Me(t,i):null,code:!_e(i)&&xt(t,i)?me(t,i):null,implementation:null};!r&&o.file===null&&o.code===null&&(t.error(l.UnknownRuleImplementationDirective,`Unexpected '${i.content}' in rule implementation - expected 'file <path>' or an inline code block`,p(i)),t.skipBlock(i.indent));for(let a=t.peekChild(e.indent);a!==void 0&&(r||n&&R(a.content)==="implementation");a=t.peekChild(e.indent))t.reader.takeSignificant(),t.error(r&&R(a.content)==="implementation"?l.InvalidImplementationBlock:l.ConflictingImplementationSources,"A named rule has one implementation wrapper and cannot mix wrapped and direct sources.",p(a)),xt(t,a)?me(t,a):t.skipBlock(a.indent);return o}c(Ps,"parseRuleImplementation");function Os(t){let e=Ar.exec(t);if(e===null)return{content:t,message:null};let n=e[1]!==void 0?Q(e[1]):e[2];return{content:t.substring(0,e.index).trimEnd(),message:n}}c(Os,"splitMessage");function As(t,e,n){let i=hs.exec(n);if(i===null)return{content:n,severity:"Error"};let r=wr[i[1]];if(r===void 0){t.error(l.InvalidValidationSeverity,`Unknown validation severity '${i[1]}' - expected information, warning or error`,p(e));return}return{content:n.substring(0,i.index).trimEnd(),severity:r}}c(As,"splitSeverity");function ws(t,e,n){if(e==="not empty")return{kind:"NotEmpty",value:null};let i=xs.exec(e);if(i===null){t.error(l.InvalidValidationRule,`Invalid validation rule '${n.content}'`,p(n));return}if(i[1]==="rule"){let r=i[2].trim();if(!vs.test(r)){t.error(l.InvalidRuleName,`Invalid rule name '${r}' in '${n.content}' - expected 'rule <Name>' with an identifier`,p(n));return}return{kind:"Rule",value:{kind:"PathExpressionSyntax",path:r,location:p(n)}}}return{kind:ks[i[1]],value:ee(i[2],p(n),t)}}c(ws,"parseRule");var Is=O("^constraint\\s+([A-Za-z_]\\w*)$"),Rs=O("^unique\\s+event\\s+([A-Z]\\w*)$"),Ts=O("^unique\\s+([a-z_][\\w.]*(?:\\s*,\\s*[a-z_][\\w.]*)*)\\s+on\\s+([A-Z]\\w*)$"),Ds=O("^released\\s+by\\s+([A-Z]\\w*)$"),Ms=O(`^message\\s+"(${z})"$`),js=c(t=>t.kind==="FileConstraintSyntax"?void 0:t.event,"targetOf");function Rr(t,e){let n=Is.exec(e.content);n===null&&t.error(l.InvalidConstraintDeclaration,`Invalid constraint declaration '${e.content}' - expected 'constraint <Name>'`,p(e));let i=n?.[1]??R(e.content),r=[],o=[],a=new Set,s=new Set,d=null,f=!1;for(let m=t.peekChild(e.indent);m!==void 0;m=t.peekChild(e.indent)){t.reader.takeSignificant();let u=Ds.exec(m.content),h=Ms.exec(m.content);u!==null?a.has(u[1])?t.error(l.DuplicateConstraintBody,`Constraint '${i}' already releases with event '${u[1]}'`,p(m)):(o.push(u[1]),a.add(u[1])):h!==null?d!==null?t.error(l.DuplicateConstraintBody,`Constraint '${i}' already has a message`,p(m)):d=Q(h[1]):m.content==="ignore casing"?(f&&t.error(l.DuplicateConstraintBody,`Constraint '${i}' already ignores casing`,p(m)),f=!0):Ns(t,i,m,r,s)}for(let m of o.filter(u=>s.has(u)))t.error(l.DuplicateConstraintBody,`Constraint '${i}' cannot target and release event '${m}'`,p(e));return r.length===0&&(t.error(l.ConstraintWithoutRule,`Constraint '${i}' must declare 'unique ... on ...', 'unique event ...' or 'file ...'`,p(e)),r.push(Jt(i,p(e),{kind:"UniqueEventConstraintSyntax",event:""}))),r[0].kind==="FileConstraintSyntax"&&(o.length>0||d!==null||f)&&t.error(l.InvalidConstraintBody,`File constraint '${i}' cannot have declarative options`,p(e)),{...r[0],additionalRules:r.slice(1),releasedBy:o,message:d,ignoreCasing:f}}c(Rr,"parseConstraint");function Ns(t,e,n,i,r){let o=Ls(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(l.DuplicateConstraintBody,`Constraint '${e}' cannot mix constraint kinds`,p(n));return}let a=js(o);if(a!==void 0&&r.has(a)){t.error(l.DuplicateConstraintBody,`Constraint '${e}' already targets event '${a}'`,p(n));return}a!==void 0&&r.add(a),i.push(o)}c(Ns,"addRule");function Ls(t,e,n){let i=p(n),r=Rs.exec(n.content);if(r!==null)return Jt(e,i,{kind:"UniqueEventConstraintSyntax",event:r[1]});let o=Ts.exec(n.content);if(o!==null){let a=o[1].split(",").map(s=>s.trim());if(new Set(a).size!==a.length){t.error(l.DuplicateConstraintBody,`Constraint '${e}' repeats a property in its composite key`,i);return}return Jt(e,i,{kind:"UniquePropertyConstraintSyntax",property:a[0],additionalProperties:a.slice(1),event:o[2]})}if(ie(n)){t.warning(l.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 a=n.content.substring(4).trim();return Jt(e,i,{kind:"FileConstraintSyntax",file:{kind:"FileReferenceSyntax",path:a,location:i}})}t.error(l.InvalidConstraintBody,`Invalid constraint body '${n.content}'`,i)}c(Ls,"parseRule");function Jt(t,e,n){return{...n,name:t,additionalRules:[],releasedBy:[],ignoreCasing:!1,message:null,location:e}}c(Jt,"rule");var qs=O("^projection\\s+(@?[\\w.]+)\\s*(?:=>\\s*([\\w.]+))?$"),Bs=O("^(@?[\\w.]+)(?:\\s+key\\s+(.+))?$"),Fs=O("^join\\s+(@?[\\w.]+)\\s+on\\s+(@?[\\w.]+)$"),Ys=O("^with\\s+(@?[\\w.]+)$"),Ws=O("^children\\s+(@?[\\w.]+)\\s+identified\\s+by\\s+(.+)$"),Us=O("^nested\\s+(@?[\\w.]+)$"),zs=O("^remove\\s+with\\s+(@?[\\w.]+)(?:\\s+key\\s+(.+))?$"),Vs=O("^remove\\s+via\\s+join\\s+on\\s+(@?[\\w.]+)(?:\\s+key\\s+(.+))?$"),Qs=O("^clear\\s+with\\s+(@?[\\w.]+)$"),Zs=O("^variant\\s+(@?[\\w.]+)\\s*$"),Gs=O("^enters\\s+on\\s+(@?[\\w.]+)(?:\\s+key\\s+(.+))?$"),Ks=O("^(increment|decrement|count|clear)\\s+(@?[$\\w.]+)$"),_s=O("^(add|subtract)\\s+(@?[$\\w.]+)\\s+by\\s+(.+)$"),Js=O("^set\\s+(@?[$\\w.]+)\\s+(?:=|to)\\s+(.+)$"),Tr=O("^(@?[$\\w.@]+)\\s*=(?!=|>)\\s*(.+)$"),Hs={increment:"IncrementMappingSyntax",decrement:"DecrementMappingSyntax",clear:"ClearMappingSyntax",count:"CountMappingSyntax"};function Jn(t,e){let n=qs.exec(e.content);if(n===null)return t.error(l.InvalidProjectionDeclaration,`Invalid projection declaration '${e.content}' - expected 'projection <Name> [=> <ReadModel>]'`,p(e)),t.skipBlock(e.indent),{kind:"ProjectionSyntax",sourceOptions:t.sourceOptions,name:R(e.content),readModel:null,sequence:null,autoMap:"Inherit",blocks:[],location:p(e)};let i=n[1],r=null,o="Inherit",a=null,s=[];for(let d=t.peekChild(e.indent);d!==void 0;d=t.peekChild(e.indent)){if(t.reader.takeSignificant(),ie(d))continue;let f=R(d.content);if(f==="sequence")r=d.content.substring(8).trim();else if(f==="automap")o="Enabled";else if(d.content==="no automap")o="Disabled";else if(f==="key")a=Mr(t,d);else if(f==="variant")s.push(ac(t,d));else{let m=Hn(t,d,!1);m!==void 0&&s.push(m)}}return Xs(t,s,i),s.length===0&&t.error(l.EmptyProjection,`Projection '${i}' must contain at least one directive`,p(e)),{kind:"ProjectionSyntax",sourceOptions:t.sourceOptions,name:i,readModel:n[2]??null,sequence:r,autoMap:o,key:a,blocks:s,location:p(e)}}c(Jn,"parseProjection");function Xs(t,e,n){let i=e.filter(a=>a.kind==="ProjectionVariantSyntax"),r=new Map;i.forEach(a=>r.set(a.name,[...r.get(a.name)??[],a]));for(let a of[...r.values()].flatMap(s=>s.slice(1)))t.error(l.DuplicateProjectionVariant,`Duplicate variant '${a.name}' - a variant name is declared once`,a.location);let o=new Set;for(let a of e.flatMap(s=>s.kind==="ProjectionVariantSyntax"?s.entersOn:[]))a.event.length>0&&o.has(a.event)&&t.error(l.DuplicateVariantEnteringEvent,`Entering event '${a.event}' is claimed more than once in projection '${n}'`,a.location),o.add(a.event)}c(Xs,"reportVariantConflicts");function Hn(t,e,n){let i=p(e);switch(R(e.content)){case"from":return ec(t,e);case"every":{let r=!0,{autoMap:o,mappings:a}=_n(t,e,s=>s.content!=="exclude children"?!1:(r=!1,!0));return{kind:"EverySyntax",includeChildren:r,autoMap:o,mappings:a,location:i}}case"all":{let{autoMap:r,mappings:o}=_n(t,e);return{kind:"AllSyntax",autoMap:r,mappings:o,location:i}}case"join":return tc(t,e);case"children":return nc(t,e);case"nested":return ic(t,e);case"remove":return rc(t,e);case"clear":return n||t.error(l.ClearWithOutsideNestedBlock,"'clear with' is only valid inside a nested block",i),oc(t,e);default:t.error(l.UnknownProjectionDirective,`Unexpected '${R(e.content)}' in projection body`,i),t.skipBlock(e.indent);return}}c(Hn,"parseBlock");function ec(t,e){let n=[];for(let a of Ki(e.content.substring(4),",")){let s=a.trim();if(s.length===0){t.error(l.FromWithoutEvent,"Expected an event type after 'from'",p(e));continue}let d=Bs.exec(s);if(d===null){t.error(l.InvalidEventReference,`Invalid event reference '${s}'`,p(e));continue}n.push({kind:"EventSpecSyntax",event:G(d[1]),key:d[2]===void 0?null:re(d[2],p(e),t),location:p(e)})}let i=[],r=null,o=null;for(let a=t.peekChild(e.indent);a!==void 0;a=t.peekChild(e.indent)){t.reader.takeSignificant();let s=R(a.content);s==="key"?r=Mr(t,a):s==="parent"?o=re(a.content.substring(6),p(a),t):jr(t,a,i)}return{kind:"FromSyntax",events:n,key:r,parentKey:o,mappings:i,location:p(e)}}c(ec,"parseFrom");function tc(t,e){let n=Fs.exec(e.content);if(n===null)return t.error(l.InvalidJoinDeclaration,`Invalid join declaration '${e.content}' - expected 'join <property> on <key>'`,p(e)),t.skipBlock(e.indent),{kind:"JoinSyntax",property:"",on:"",events:[],location:p(e)};let i=[];for(let r=t.peekChild(e.indent);r!==void 0;r=t.peekChild(e.indent)){t.reader.takeSignificant();let o=Ys.exec(r.content);if(o===null){t.error(l.JoinWithoutEvent,`Expected 'with <EventType>' in join block, got '${r.content}'`,p(r)),t.skipBlock(r.indent);continue}let{autoMap:a,mappings:s}=_n(t,r);i.push({kind:"JoinEventSyntax",event:G(o[1]),autoMap:a,mappings:s,location:p(r)})}return{kind:"JoinSyntax",property:G(n[1]),on:G(n[2]),events:i,location:p(e)}}c(tc,"parseJoin");function nc(t,e){let n=Ws.exec(e.content);if(n===null)return t.error(l.InvalidChildrenDeclaration,`Invalid children declaration '${e.content}' - expected 'children <collection> identified by <key>'`,p(e)),t.skipBlock(e.indent),{kind:"ChildrenSyntax",property:"",autoMap:"Inherit",blocks:[],location:p(e)};let{autoMap:i,blocks:r}=Dr(t,e);return{kind:"ChildrenSyntax",property:G(n[1]),identifiedBy:re(n[2],p(e),t),autoMap:i,blocks:r,location:p(e)}}c(nc,"parseChildren");function ic(t,e){let n=Us.exec(e.content);if(n===null)return t.error(l.InvalidNestedDeclaration,`Invalid nested declaration '${e.content}' - expected 'nested <property>'`,p(e)),t.skipBlock(e.indent),{kind:"NestedSyntax",property:"",autoMap:"Inherit",blocks:[],location:p(e)};let i=G(n[1]),{autoMap:r,blocks:o}=Dr(t,e);return o.some(a=>a.kind==="FromSyntax")||t.error(l.NestedBlockWithoutFrom,`Nested block '${i}' must contain at least one 'from' directive`,p(e)),{kind:"NestedSyntax",property:i,autoMap:r,blocks:o,location:p(e)}}c(ic,"parseNested");function Dr(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=Hn(t,r,!0);o!==void 0&&n.push(o)}return{autoMap:i,blocks:n}}c(Dr,"parseChildBlocks");function rc(t,e){let n=Vs.exec(e.content);if(n!==null)return{kind:"RemoveViaJoinSyntax",event:G(n[1]),key:n[2]===void 0?null:re(n[2],p(e),t),location:p(e)};let i=zs.exec(e.content);if(i===null){t.error(l.InvalidRemoveDeclaration,`Invalid remove declaration '${e.content}' - expected 'remove with <EventType>' or 'remove via join on <EventType>'`,p(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=re(o.content.substring(6),p(o),t):t.error(l.UnknownRemoveDirective,`Unexpected '${o.content}' in remove block - only 'parent' is allowed`,p(o));return{kind:"RemoveWithSyntax",event:G(i[1]),key:i[2]===void 0?null:re(i[2],p(e),t),parentKey:r,location:p(e)}}c(rc,"parseRemove");function oc(t,e){let n=Qs.exec(e.content);return n===null?(t.error(l.InvalidClearDeclaration,`Invalid clear declaration '${e.content}' - expected 'clear with <EventType>'`,p(e)),{kind:"ClearWithSyntax",event:"",location:p(e)}):{kind:"ClearWithSyntax",event:G(n[1]),location:p(e)}}c(oc,"parseClearWith");function ac(t,e){let n=Zs.exec(e.content);if(n===null)return t.error(l.InvalidProjectionVariantDeclaration,`Invalid variant declaration '${e.content}' - expected 'variant <Name>'`,p(e)),t.skipBlock(e.indent),{kind:"ProjectionVariantSyntax",name:R(e.content),entersOn:[],blocks:[],location:p(e)};let i=G(n[1]),r=[],o=[];for(let a=t.peekChild(e.indent);a!==void 0;a=t.peekChild(e.indent)){t.reader.takeSignificant();let s=R(a.content);if(s==="enters")r.push(sc(t,a));else if(s==="variant")t.error(l.NestedProjectionVariantNotAllowed,"A variant cannot be declared inside another variant",p(a)),t.skipBlock(a.indent);else{let d=Hn(t,a,!1);d!==void 0&&o.push(d)}}return r.length===0&&t.error(l.VariantRequiresEnteringEvent,`Variant '${i}' must declare at least one 'enters on' event`,p(e)),{kind:"ProjectionVariantSyntax",name:i,entersOn:r,blocks:o,location:p(e)}}c(ac,"parseVariant");function sc(t,e){let n=Gs.exec(e.content);return n===null?(t.error(l.InvalidEntersOnDeclaration,`Invalid 'enters on' declaration '${e.content}' - expected 'enters on <EventType> [key <expression>]'`,p(e)),t.skipBlock(e.indent),{kind:"ProjectionEntersOnSyntax",event:"",key:null,location:p(e)}):{kind:"ProjectionEntersOnSyntax",event:G(n[1]),key:n[2]===void 0?null:re(n[2],p(e),t),location:p(e)}}c(sc,"parseEntersOn");function Mr(t,e){let n=e.content.substring(3).trim();if(t.peekChild(e.indent)===void 0)return{kind:"ExpressionKeySyntax",expression:re(n,p(e),t),location:p(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 a=Tr.exec(o.content);if(a===null){t.sourceOptions.numericMode==="exact"&&t.error(l.InvalidCompositeKeyPart,`Invalid composite key part '${o.content}' - expected '<property> = <expression>'`,p(o));continue}let s=re(a[2],p(o),t);t.sourceOptions.numericMode==="exact"&&s.kind==="TemplateExpressionSyntax"&&t.error(l.TemplateInCompositeKey,"Template expressions are not allowed in composite keys",p(o)),i.push({kind:"KeyPartSyntax",property:G(a[1]),expression:s,location:p(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(l.EmptyCompositeKey,"Composite keys must contain at least one part",p(e)),{kind:"CompositeKeySyntax",type:n.replace(/\{$/,"").trim(),parts:i,location:p(e)}}c(Mr,"parseKey");function _n(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)||jr(t,o,r);return{autoMap:i,mappings:r}}c(_n,"parseMappingBlock");function jr(t,e,n){let i=p(e),r=Ks.exec(e.content);if(r!==null){r[1]!=="clear"||r[2]!=="with"?n.push({kind:Hs[r[1]],property:G(r[2]),location:i}):t.sourceOptions.numericMode==="exact"&&t.error(l.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=_s.exec(e.content);if(o!==null){n.push({kind:o[1]==="add"?"AddMappingSyntax":"SubtractMappingSyntax",property:G(o[2]),value:re(o[3],i,t),location:i});return}let a=Js.exec(e.content)??Tr.exec(e.content);a!==null?n.push({kind:"SetMappingSyntax",property:G(a[1]),source:re(a[2],i,t),location:i}):t.sourceOptions.numericMode==="exact"&&t.error(l.InvalidProjectionMapping,`Invalid mapping '${e.content}'`,i)}c(jr,"pushMapping");var cc=O("^query\\s+([A-Za-z_]\\w*)\\s*=>\\s*(observable\\s+)?([\\w.]+(?:\\[\\])?(?:\\?|\\s+optional)?)$"),lc=O("^([a-z_]\\w*)\\s+([\\w.]+(?:\\[\\])?(?:\\?|\\s+optional)?)(?:\\s+from\\s+(.+))?$"),dc=O("^scoped\\s+to\\s+([a-z_]\\w*)$"),pc=new Set(["performer"]);function Lr(t,e){let n=cc.exec(e.content);if(n===null)return t.error(l.InvalidQueryDeclaration,`Invalid query declaration '${e.content}' - expected 'query <Name> => [observable] <ReadModel>'`,p(e)),t.skipBlock(e.indent),{kind:"QuerySyntax",name:R(e.content),returnType:xe("",p(e)),by:null,filters:[],description:null,isObservable:!1,scope:null,authorize:null,location:p(e)};let i=n[1],r=xe(n[3],{...p(e),column:e.indent+1+n[0].length-n[3].length});n[2]===void 0&&r.name==="observable"&&r.isOptional&&!r.isCollection||Ce(t,r,e);let o=null,a=[],s=null,d=null,f=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")s=Z(t,m,s,`Query '${i}'`);else if(u==="by"){let h=Nr(t,m,"by");h!==void 0&&(o!==null&&t.error(l.InvalidQueryParameter,`Query '${i}' already declares 'by' - a query can have at most one key parameter`,p(m)),o=h)}else if(u==="filter"){let h=Nr(t,m,"filter");h!==void 0&&a.push(h)}else u==="authorize"?f=ke(f,De(t,m)):u==="scoped"?d=fc(t,m,d,i)??d:pc.has(u)?t.skipOpaqueBlock(m.indent):(t.error(l.UnknownQueryDirective,`Unexpected '${m.content}' in query body - expected description, by, filter, authorize, scoped or performer`,p(m)),t.skipBlock(m.indent))}return{kind:"QuerySyntax",name:i,returnType:r,by:o,filters:a,description:s,isObservable:n[2]!==void 0,scope:d,authorize:f,location:p(e)}}c(Lr,"parseQuery");function Nr(t,e,n){let i=lc.exec(e.content.substring(n.length).trim());if(i===null){t.error(l.InvalidQueryParameter,`Invalid '${n}' parameter '${e.content}' - expected '${n} <name> <Type> [from <source>]'`,p(e));return}let r=e.content.indexOf(i[1],n.length),o=xe(i[2],{...p(e),column:e.indent+1+e.content.indexOf(i[2],r+i[1].length)});return Ce(t,o,e),{kind:"QueryParameterSyntax",name:i[1],type:o,source:i[3]===void 0?null:ee(i[3],p(e),t.valueContext),location:p(e)}}c(Nr,"parseParameter");function fc(t,e,n,i){let r=dc.exec(e.content);if(r===null){t.error(l.InvalidScopeDeclaration,`Invalid scope declaration '${e.content}' - expected 'scoped to <scope>'`,p(e));return}if(n!==null){t.error(l.DuplicateScope,`Query '${i}' already declares a scope - results are narrowed one way`,p(e));return}return r[1]}c(fc,"parseScope");var uc=O("^@?[a-z_]\\w*\\s+[\\w.]+");function Xn(t,e){let n=be(t,e);if(n!==void 0){n.isGenerated&&t.error(l.GeneratedPropertyOutsideCommand,"Generated properties can only be declared on commands.",n.location),t.triggerData.push(n);return}uc.test(e.content)&&/\?|\boptional\b/.test(e.content)&&t.error(l.InvalidTriggerData,`Invalid trigger value '${e.content}' - expected '<name>' or '<name> <Type>'`,p(e)),t.skipOpaqueBlock(e.indent)}c(Xn,"parseTriggerData");function qr(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"?Z(t,i,null,`Trigger '${e.content}'`):ie(i)||Xn(t,i);return t.triggerData.slice(n)}c(qr,"parseTriggerDeclaration");var mc=O("^reaction\\s+([A-Za-z_]\\w*)$"),yc=O("^when\\s+([A-Za-z_]\\w*)$"),Sc=O("^every\\s+(\\d+)\\s+(seconds?|minutes?|hours?|days?)$"),hc=O("^at\\s+(\\d{2}:\\d{2})(?:\\s+on\\s+(?:(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday)|day\\s+(\\d{1,2})))?$"),gc=new Set(["when","every","at"]),xc=O("^invokes\\s+([A-Z]\\w*)$"),vc=_("^(@?[\\w.]+)\\s*=(?!=|>)\\s*(.+)$"),$c=O("^reads\\s+[A-Z]\\w*\\s+optional(?:\\s|$)");function Br(t,e){let n=mc.exec(e.content)?.[1]??"";n===""&&t.error(l.InvalidReactionDeclaration,`Invalid reaction declaration '${e.content}' - expected 'reaction <Name>'`,p(e));let i=null,r=null,o=[],a=new Set,s=!1;for(let d=t.peekChild(e.indent);d!==void 0;d=t.peekChild(e.indent)){t.reader.takeSignificant();let f=R(d.content);if(f==="description"){i=Z(t,d,i,`Reaction '${n}'`);continue}if(f==="where"){r=Ge(t,d.content.substring(5).trim(),p(d));continue}if(!gc.has(f)){t.error(l.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>'`,p(d)),t.skipBlock(d.indent),s=!0;continue}let m=Cc(t,d);if(m===void 0){s=!0;continue}let u=bc(m);if(a.has(u)){t.error(l.DuplicateReactionTrigger,`Reaction '${n}' already declares '${d.content}' - a second says nothing the first did not`,p(d)),t.skipBlock(d.indent);continue}a.add(u),o.push(kc(t,d,m))}return o.length===0&&!s&&t.error(l.ReactionWithoutTrigger,`Reaction '${n}' must declare at least one trigger - nothing sets it off`,p(e)),{kind:"ReactionSyntax",name:n,description:i,where:r,triggers:o,location:p(e)}}c(Br,"parseReaction");function kc(t,e,n){let i=null,r=[],o=[],a=[],s=[];for(let f=t.peekChild(e.indent);f!==void 0;f=t.peekChild(e.indent)){t.reader.takeSignificant();let m=R(f.content);if(m==="description")i=Z(t,f,i,`Trigger '${f.content}'`);else if(m==="produces"){let u=Kt(t,f);u!==void 0&&r.push(u)}else if(m==="invokes"){let u=xc.exec(f.content);if(u===null)t.error(l.InvalidInvokesDeclaration,`Invalid invokes declaration '${f.content}' - expected 'invokes <Command>'`,p(f)),t.skipBlock(f.indent);else{let h=new pe(t.reader.fork(),t.path,t.languages);h.scope=t.scope,h.sourceOptions=t.sourceOptions,ge(h,f),t.inputUses.push(...h.inputUses);let g=[];for(let b=t.peekChild(f.indent);b!==void 0;b=t.peekChild(f.indent)){t.reader.takeSignificant();let x=vc.exec(b.content);x!==null?g.push({kind:"PropertyMappingSyntax",property:x[1].replaceAll("@",""),source:ue(x[2],p(b),t.valueContext),location:p(b)}):t.skipOpaqueBlock(b.indent)}o.push({kind:"InvokesSyntax",command:u[1],mappings:g,location:p(f)})}}else if(m==="reads"||m==="file"||f.content==="csharp"||f.content.startsWith("```")){let u=Zt(f);u!==void 0&&a.push(u),$c.test(f.content)&&t.error(l.OptionalReadsNotSupported,"Optional reads are not yet supported (see #308).",p(f)),f.content.startsWith("```")&&t.skipFencedBody(),t.skipOpaqueBlock(f.indent)}else{let u=t.triggerData.length;Xn(t,f);for(let h of t.triggerData.slice(u))s.push({kind:"TriggerDataSyntax",name:h.name,type:h.type,location:h.location})}}let d={kind:"ReactionTriggerSyntax",source:n,description:i,produces:r,invokes:o,location:p(e)};return Fe.set(d,{reads:a,data:s}),d}c(kc,"parseTrigger");function bc(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])}}c(bc,"sourceKey");function Cc(t,e){let n=p(e);switch(R(e.content)){case"when":{let i=yc.exec(e.content);if(i===null){t.error(l.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=Sc.exec(e.content),r=i===null?NaN:Number(i[1]);if(i===null||!Number.isInteger(r)||r<1||r>2147483647){t.error(l.InvalidIntervalTrigger,`Invalid interval '${e.content}' - expected 'every <n> <seconds|minutes|hours|days>'`,n),t.skipBlock(e.indent);return}return{kind:"IntervalTriggerSourceSyntax",amount:r,unit:Oc(i[2]),location:n}}default:return Ec(t,e)}}c(Cc,"parseTriggerSource");function Ec(t,e){let n=p(e),i=hc.exec(e.content),r=i===null?void 0:Pc(i[1]);if(i===null||r===void 0){t.error(l.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(l.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}}c(Ec,"parseSchedule");function Pc(t){let[e,n]=t.split(":").map(Number);if(e>=0&&e<=23&&n>=0&&n<=59)return`${t}:00.0000000`}c(Pc,"timeOf");function Oc(t){switch(t.replace(/s+$/,"")){case"second":return"Seconds";case"minute":return"Minutes";case"hour":return"Hours";default:return"Days"}}c(Oc,"unitOf");var Ht=`(?:"(${z})"|(\\$strings\\.\\w+(?:\\.\\w+)*))`,Ac=O("^screen\\s+([A-Za-z_]\\w*)$"),wc=O("^data\\s+([\\w.]+(?:\\[\\])?)\\s+via\\s+query\\s+(\\w+(?:\\.\\w+)*)(?:\\s+by\\s+(\\w+))?$"),Ic=O("^action\\s+([A-Za-z_]\\w*(?:\\.\\w+)*)$"),Rc=O(`^label\\s+${Ht}$`),Tc=O("^navigate\\s+to\\s+(\\w+(?:\\.\\w+)*)(?:\\s+by\\s+(\\w+))?$"),Dc=O("^[a-z_]\\w*$"),Mc=O(`^title\\s+${Ht}$`),jc=O(`^column\\s+([\\w.]+)(?:\\s+label\\s+${Ht})?$`),Nc=O("^on\\s+row-click\\s+(navigate\\s+to\\s+.+)$"),Lc=O(`^field\\s+([\\w.]+)\\s+label\\s+${Ht}$`),Xt=c((t,e)=>t[e]!==void 0?Q(t[e]):t[e+1],"operandText"),qc=c(t=>["on","uses"].includes(R(t.content)),"isInteraction"),Bc=c((t,e)=>e.content.startsWith("```")||t.languages.has(e.content),"isCodeLine");function Fr(t,e){let n=Ac.exec(e.content);n===null&&t.error(l.InvalidScreenDeclaration,`Invalid screen declaration '${e.content}' - expected 'screen <Name>'`,p(e));let i=[];for(let r=t.peekChild(e.indent);r!==void 0;r=t.peekChild(e.indent))t.reader.takeSignificant(),ie(r)||Yr(t,r,i);return{kind:"ScreenSyntax",name:n?.[1]??"",directives:i,location:p(e)}}c(Fr,"parseScreen");function Yr(t,e,n){let i=Fc(t,e);i!==void 0&&n.push(i)}c(Yr,"pushDirective");function Wr(t,e){let n=[];for(let i=t.peekChild(e.indent);i!==void 0;i=t.peekChild(e.indent))t.reader.takeSignificant(),Yr(t,i,n);return n}c(Wr,"parseDirectives");function Fc(t,e){switch(R(e.content)){case"data":return Yc(t,e);case"action":return Wc(t,e);case"template":return Uc(t,e);case"section":return zc(t,e);case"title":return Vc(t,e);case"table":return Qc(t,e);case"summary":return Zc(t,e);case"navigate":return ei(t,e.content,e);case"on":return ge(t,e),{kind:"ScreenBehaviorSyntax",location:p(e)};case"uses":return t.skipOpaqueBlock(e.indent),{kind:"ScreenUsesBehaviorSyntax",location:p(e)};default:if(Bc(t,e))return Gc(t,e);t.error(l.UnknownScreenDirective,`Unexpected '${e.content}' in screen body`,p(e)),t.skipBlock(e.indent);return}}c(Fc,"parseDirective");function Yc(t,e){let n=wc.exec(e.content);if(n===null){t.error(l.InvalidDataDirective,`Invalid data directive '${e.content}' - expected 'data <ReadModel> via query <Query> [by <param>]'`,p(e));return}return{kind:"ScreenDataSyntax",type:xe(n[1],p(e)),query:n[2],by:n[3]??null,location:p(e)}}c(Yc,"parseData");function Wc(t,e){let n=Ic.exec(e.content);if(n===null){t.error(l.InvalidActionDirective,`Invalid action directive '${e.content}' - expected 'action <Command>'`,p(e)),t.skipBlock(e.indent);return}let i=null,r=null;for(let o=t.peekChild(e.indent);o!==void 0;o=t.peekChild(e.indent)){t.reader.takeSignificant();let a=Rc.exec(o.content);a!==null?i=Xt(a,1):R(o.content)==="navigate"?r=ei(t,o.content,o)??null:t.error(l.UnknownActionDirective,`Unexpected '${o.content}' in action - expected 'label "..."' or 'navigate to ...'`,p(o))}return{kind:"ScreenActionSyntax",command:n[1],label:i,navigate:r,location:p(e)}}c(Wc,"parseAction");function ei(t,e,n){let i=Tc.exec(e);if(i===null){t.error(l.InvalidNavigation,`Invalid navigation '${e}' - expected 'navigate to <Screen> [by <param>]'`,p(n));return}return{kind:"ScreenNavigateSyntax",screen:i[1],by:i[2]??null,location:p(n)}}c(ei,"parseNavigate");function Uc(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(),!Dc.test(r.content)){t.error(l.InvalidScreenLayoutSlot,`Expected a slot name in template '${n}', got '${r.content}'`,p(r)),t.skipBlock(r.indent);continue}i.push({kind:"ScreenSlotSyntax",name:r.content,directives:Wr(t,r),location:p(r)})}return{kind:"ScreenTemplateReferenceSyntax",name:n,slots:i,location:p(e)}}c(Uc,"parseTemplateReference");function zc(t,e){return{kind:"ScreenSectionSyntax",name:e.content.substring(7).trim(),directives:Wr(t,e),location:p(e)}}c(zc,"parseSection");function Vc(t,e){let n=Mc.exec(e.content);return n===null?(t.error(l.InvalidTitleDirective,`Invalid title directive '${e.content}' - expected 'title "..."'`,p(e)),{kind:"ScreenTitleSyntax",text:"",location:p(e)}):{kind:"ScreenTitleSyntax",text:Xt(n,1),location:p(e)}}c(Vc,"parseTitle");function Qc(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 a=jc.exec(o.content),s=Nc.exec(o.content);if(a!==null){let d=a[2]!==void 0||a[3]!==void 0;i.push({kind:"ScreenColumnSyntax",property:a[1],label:d?Xt(a,2):null,location:p(o)})}else s!==null?r=ei(t,s[1],o)??null:R(o.content)==="on"?ge(t,o):qc(o)?t.skipOpaqueBlock(o.indent):t.error(l.UnknownTableDirective,`Unexpected '${o.content}' in table - expected 'column ...', 'on row-click navigate to ...', 'on <trigger>' or 'uses <Behavior>'`,p(o))}return{kind:"ScreenTableSyntax",target:n,columns:i,rowClick:r,location:p(e)}}c(Qc,"parseTable");function Zc(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=Lc.exec(r.content);if(o===null){t.error(l.UnknownSummaryDirective,`Unexpected '${r.content}' in summary - expected 'field <property> label "..."'`,p(r));continue}i.push({kind:"ScreenFieldSyntax",property:o[1],label:Xt(o,2),location:p(r)})}return{kind:"ScreenSummarySyntax",target:n,fields:i,location:p(e)}}c(Zc,"parseSummary");function Gc(t,e){let n=e.content.startsWith("```")?e.content.substring(3):e.content;if(!t.languages.has(n)){t.error(l.ExpectedCodeFence,`Expected a registered language on the opening fence, not '${e.content}'`,p(e));return}e.content.startsWith("```")||t.warning(l.LegacyInlineCodeFence,`'${n}' on its own line is deprecated - use '\`\`\`${n}' instead`,p(e));let i=Ve(t,n,e);return i===null?void 0:{kind:"ScreenCodeSyntax",code:{kind:"CodeBlockSyntax",language:n,code:i,location:p(e)},location:p(e)}}c(Gc,"parseCode");var ti=O("^then\\s+returns\\b"),Ur=O("^generated\\s+(?=\\S)(?![=])"),zr=O("^generated\\s+([a-z_]\\w*)\\s*=(?!=|>)\\s*(.+)$"),Kc=O("^([\\w.]+)\\s*=(?!=|>)\\s*(.+)$"),_c=O(`^(?:"${z}"|'(?:[^'\\\\]|\\\\.)*')$`);function Vr(t,e,n,i){if((e.startsWith('"')||e.startsWith("'"))&&!_c.test(e))return t.error(i,"Expected exactly one concrete value.",n),null;let r=ee(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}c(Vr,"parseConcrete");function en(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.",p(e)),t.skipBlock(e.indent),null;let o=p(e),a=Vr(t,r[2],{...o,column:o.column+e.content.indexOf(r[2],e.content.indexOf("=")+1)},i),s=t.peekChild(e.indent);return s!==void 0&&(t.error(i,"A fixture or return field cannot have child directives.",p(s)),t.skipBlock(e.indent)),a===null?null:{kind:"PropertyMappingSyntax",property:r[1],source:a,location:o}}c(en,"parseConcreteMapping");function Qr(t,e){let n=ti.exec(e.content)[0].length,i=e.content.substring(n).trim(),r=p(e);if(i.length>0){let a=Vr(t,i,{...r,column:r.column+e.content.indexOf(i,n)},l.InvalidReturnExpectation),s=t.peekChild(e.indent);return s!==void 0&&(t.error(l.InvalidReturnExpectation,"A scalar return expectation cannot have child assertions.",p(s)),t.skipBlock(e.indent)),a===null?null:{kind:"ScalarSpecificationReturnSyntax",value:a,location:r}}let o=[];for(let a=t.peekChild(e.indent);a!==void 0;a=t.peekChild(e.indent)){t.reader.takeSignificant();let s=en(t,a,Kc,l.InvalidReturnExpectation);s!==null&&o.push(s)}return{kind:"RecordSpecificationReturnSyntax",fields:o,location:r}}c(Qr,"parseReturn");var Jc=O("^(?:given\\s+operation|then\\s+(?:operation|compensated))(?:\\s|$)"),Hc=O("^(given operation|then operation|then compensated)\\s+([A-Za-z_]\\w*(?:\\.[A-Za-z_]\\w*)*)(\\s+fails)?$"),Xc=O("^specification\\s+([A-Za-z_]\\w*)$"),el=O("^given\\s+([A-Z]\\w*)$"),tl=O("^when\\s+append\\s+([A-Z]\\w*)$"),nl=O("^when\\s+([A-Z]\\w*)$"),il=O("^then\\s+([A-Z]\\w*)$"),rl=O("^then\\s+query\\b"),Zr=O("^(?:given|then)\\s+readmodel\\b"),ol=O("^given\\s+readmodel\\s+([A-Z]\\w*)$"),al=O("^then\\s+readmodel\\s+([A-Z]\\w*)(\\s+exactly)?$"),Gr=O("^then\\s+no\\b"),sl=O(`^then\\s+error\\s+"(${z})"$`),ii=O("^([\\w.]+)\\s*=(?!=|>)\\s*(.+)$"),cl=_("^([\\w.]+)\\s*=(?!=|>)\\s*(.+)$"),ll=O("^given\\s+clock\\b"),dl=O("^given\\s+capture\\b"),pl=O("^when\\s+clock\\b"),fl=O("^when\\s+trigger\\b"),ul=O("^when\\s+capture\\b"),ml=O("^when\\s+query\\b"),yl=O("^then\\s+result\\b"),Sl=O("^then\\s+no\\s+result\\b"),hl=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}))"$'),gl=O("^when\\s+trigger\\s+([A-Za-z_]\\w*)$"),xl=O("^(?:given|when)\\s+capture\\s+([A-Za-z_]\\w*)$"),vl=O("^when\\s+query\\s+([A-Za-z_]\\w*(?:\\.\\w+)*)$"),$l=O("^then\\s+result(\\s+exactly)?$"),Kr=_("^then\\s+no\\s+readmodel\\s+([A-Z]\\w*)\\s+for\\s+(.+)$"),kl=_(`^(?:"${z}"|'(?:[^'\\\\]|\\\\.)*')$`),bl=_("^then\\s+query\\s+([A-Za-z_]\\w*(?:\\.\\w+)*)(\\s+exactly)?$");function ri(t,e){let n=Xc.exec(e.content)?.[1]??"";n===""&&t.error(l.InvalidSpecificationDeclaration,`Invalid specification declaration '${e.content}' - expected 'specification <Name>'`,p(e));let i={givenOperationFailures:[],thenOperations:[],thenCompensated:[],thenAbsentReadModels:[],thenQueries:[],given:[],givenReadModels:[],when:null,whenAppended:null,whenDeclared:!1,thenEvents:[],thenEventsInAnyOrder:!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 a=t.peekChild(e.indent);a!==void 0;a=t.peekChild(e.indent)){if(t.reader.takeSignificant(),ie(a)||Cl(t,a,i))continue;let s=Gr.test(a.content)?"then":R(a.content);s==="given"?El(t,a,i):s==="when"?wl(t,a,i,n):s==="then"?Il(t,a,i):(t.error(l.UnknownSpecificationDirective,`Unexpected '${R(a.content)}' in specification body`,p(a)),t.skipBlock(a.indent))}let{whenDeclared:r,...o}=i;return{kind:"SpecificationSyntax",sourceOptions:t.sourceOptions,name:n,...o,location:p(e)}}c(ri,"parseSpecification");function Cl(t,e,n){if(!Jc.test(e.content))return!1;let i=Hc.exec(e.content);if(i===null||i[1]==="given operation"!=(i[3]!==void 0))t.error(l.InvalidOperationSpecification,"Expected 'given operation <Name> fails', 'then operation <Name>' or 'then compensated <Name>'.",p(e)),ce(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 a=en(t,o,ii,l.InvalidOperationSpecification);a!==null&&r.push(a)}n.thenOperations.push({kind:"SpecificationOperationSyntax",operation:i[2],values:r,location:p(e)})}else $t(t,e,l.InvalidOperationSpecification,"Failure and compensation assertions cannot have children."),i[1]==="given operation"?n.givenOperationFailures.push({kind:"SpecificationOperationFailureSyntax",operation:i[2],location:p(e)}):n.thenCompensated.push({kind:"SpecificationCompensatedSyntax",operation:i[2],location:p(e)});return!0}c(Cl,"parseOperationStep");function El(t,e,n){if(ll.test(e.content))n.givenClock!==null?(t.error(l.InvalidSpecificationClock,"A specification states its clock at most once.",p(e)),ce(t,e.indent)):n.givenClock=_r(t,e,"given");else if(dl.test(e.content)){let i=Jr(t,e,"given");i!==null&&n.givenCaptures.push(i)}else if(e.content.startsWith("given caller"))n.givenCaller!==null?(t.error(l.DuplicateSpecificationCallerOrDenied,"A specification has at most one 'given caller' block.",p(e)),t.skipBlock(e.indent)):n.givenCaller=Al(t,e);else if(Zr.test(e.content)){let i=Hr(t,e,ol,"given");i!==void 0&&n.givenReadModels.push(i)}else{let i=oi(t,e,el,"given");i!==void 0&&n.given.push(i)}}c(El,"parseGiven");var Pl=O(`^role${H}+"(${z})"$`),Ol=O(`^claim${H}+"(${z})"${H}*=${H}*"(${z})"$`);function Al(t,e){if(e.content!=="given caller")return t.error(l.InvalidSpecificationCaller,"Expected exactly 'given caller'.",p(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 a=Pl.exec(o.content),s=Ol.exec(o.content);o.content==="authenticated"&&!n?n=!0:a!==null?i.push(Q(a[1])):s!==null?r.push({kind:"SpecificationCallerClaimSyntax",type:Q(s[1]),value:Q(s[2]),location:p(o)}):t.error(l.InvalidSpecificationCaller,`Invalid caller fixture '${o.content}' - expected authenticated, role "...", or claim "..." = "...".`,p(o))}return{kind:"SpecificationCallerSyntax",authenticated:n,roles:i,claims:r,location:p(e)}}c(Al,"parseCaller");function wl(t,e,n,i){let r=e.content.startsWith("when append");if(n.whenDeclared){let d=n.whenAppended!==null||r?l.ConflictingSpecificationActions:l.DuplicateSpecificationWhen;t.error(d,`Specification '${i}' already declares a 'when' - a specification can have at most one`,p(e)),ce(t,e.indent);return}if(n.whenDeclared=!0,r){n.whenAppended=oi(t,e,tl,"when append")??null;return}if(pl.test(e.content)){n.whenClock=_r(t,e,"when");return}if(fl.test(e.content)){n.whenTrigger=ni(t,e,gl,l.InvalidSpecificationTrigger,"when trigger","when trigger <Trigger>",(d,f)=>({kind:"SpecificationTriggerSyntax",trigger:d,values:f,location:p(e)}));return}if(ul.test(e.content)){n.whenCapture=Jr(t,e,"when");return}if(ml.test(e.content)){n.whenQuery=ni(t,e,vl,l.InvalidSpecificationQueryAction,"when query","when query <Query>",(d,f)=>({kind:"SpecificationWhenQuerySyntax",query:d,arguments:f,location:p(e)}));return}let o=nl.exec(e.content);if(o===null){t.error(l.InvalidSpecificationWhen,`Invalid 'when' declaration '${e.content}' - expected 'when <CommandType>' or 'when append <EventType>'`,p(e)),ce(t,e.indent);return}let a=[],s=Xr(t,e,a);n.when={kind:"SpecificationCommandSyntax",commandType:o[1],...s,generatedValues:a,location:p(e)}}c(wl,"parseWhen");function Il(t,e,n){if(ti.test(e.content)){let o=Qr(t,e);n.thenReturns!==null?t.error(l.InvalidReturnExpectation,"A specification declares at most one return expectation.",p(e)):n.thenReturns=o;return}if(e.content.startsWith("then events")){e.content!=="then events in any order"||n.thenEventsInAnyOrder?t.error(l.InvalidSpecificationEventOrder,"Expected one 'then events in any order' directive.",p(e)):n.thenEventsInAnyOrder=!0,ce(t,e.indent);return}if(yl.test(e.content)){Tl(t,e,n);return}if(Sl.test(e.content)){e.content!=="then no result"||n.thenNoResult!==null?t.error(l.InvalidSpecificationQueryAction,"Expected one 'then no result' directive.",p(e)):n.thenNoResult={kind:"SpecificationNoResultSyntax",location:p(e)},ce(t,e.indent);return}if(e.content.startsWith("then denied")){e.content!=="then denied"?(t.error(l.InvalidSpecificationDenied,"Expected exactly 'then denied'.",p(e)),ce(t,e.indent)):n.thenDenied!==null?t.error(l.DuplicateSpecificationCallerOrDenied,"A specification has at most one 'then denied' outcome.",p(e)):n.thenDenied={kind:"SpecificationDeniedSyntax",location:p(e)};return}if(e.content==="then error"){n.thenErrors.push({kind:"SpecificationErrorSyntax",name:null,location:p(e)});return}let i=sl.exec(e.content);if(i!==null){n.thenErrors.push({kind:"SpecificationErrorSyntax",name:Q(i[1]),location:p(e)});return}if(R(e.content.substring(4).trim())==="error"){t.error(l.InvalidThenError,`Invalid 'then error' declaration '${e.content}' - expected 'then error' or 'then error "<reason>"'`,p(e)),ce(t,e.indent);return}if(Gr.test(e.content)){if(t.sourceOptions.numericMode==="exact"){let a=Rl(t,e);a!==null&&n.thenAbsentReadModels.push(a);return}let o=Kr.exec(e.content);if(o!==null&&!o[2].endsWith(" exactly")){let a=ee(o[2].trim(),p(e),t.valueContext);(a.kind==="LiteralExpressionSyntax"||a.kind==="ObjectExpressionSyntax")&&n.thenAbsentReadModels.push({kind:"SpecificationAbsentReadModelSyntax",name:o[1],key:a,location:p(e)})}t.skipOpaqueBlock(e.indent);return}if(rl.test(e.content)){let o=t.sourceOptions.numericMode==="exact",a=c((u,h,g)=>{if(!o)return t.skipOpaqueBlock(g.indent);t.error(u,h,p(g)),t.skipBlock(g.indent)},"reject"),s=bl.exec(e.content);if(s===null)return a(l.InvalidSpecificationQuery,`Invalid 'then query' declaration '${e.content}' - expected 'then query <Query> [exactly]'`,e);let d=[],f=[],m=!1;for(let u=t.peekChild(e.indent);u!==void 0;u=t.peekChild(e.indent))t.reader.takeSignificant(),u.content==="arguments"&&!m?d.push(...kt(t.valueContext,u,!0)):u.content==="arguments"?a(l.DuplicateSpecificationQueryArguments,`Query assertion '${s[1]}' already declares arguments`,u):u.content==="result"?f.push({kind:"SpecificationQueryResultSyntax",properties:kt(t.valueContext,u,!0),exactly:!1,location:p(u)}):a(l.UnknownSpecificationQueryDirective,`Unexpected '${R(u.content)}' in 'then query' body - expected arguments or result`,u),m||=u.content==="arguments";n.thenQueries.push({kind:"SpecificationQuerySyntax",query:s[1],arguments:d,results:f,exactly:s[2]!==void 0,location:p(e)});return}if(Zr.test(e.content)){let o=Hr(t,e,al,"then");o!==void 0&&n.thenReadModels.push(o);return}let r=oi(t,e,il,"then");r!==void 0&&n.thenEvents.push(r)}c(Il,"parseThen");function Rl(t,e){let n=Kr.exec(e.content);if(n===null||n[2].endsWith(" exactly"))return t.error(l.InvalidAbsentReadModelStep,`Invalid absence assertion '${e.content}' - expected 'then no readmodel <ReadModelType> for <key>'`,p(e)),ce(t,e.indent),null;let i=n[2].trim(),o=!(i.startsWith('"')||i.startsWith("'"))||kl.test(i)?ee(i,p(e),t.valueContext):null,a=o!==null&&(o.kind==="LiteralExpressionSyntax"||o.kind==="ObjectExpressionSyntax");a||t.error(l.InvalidAbsentReadModelStep,`Invalid absence key '${i}' - expected exactly one concrete value.`,p(e));let s=!1;for(let d=t.peekChild(e.indent);d!==void 0;d=t.peekChild(e.indent))t.reader.takeSignificant(),t.error(l.InvalidAbsentReadModelStep,"An absent read model assertion cannot have child mappings.",p(d)),s=!0;return s||!a?null:{kind:"SpecificationAbsentReadModelSyntax",name:n[1],key:o,location:p(e)}}c(Rl,"parseAbsentReadModel");function ce(t,e){if(t.sourceOptions.numericMode!=="exact")return t.skipBlock(e);t.skipOpaqueBlock(e)}c(ce,"skipBody");function _r(t,e,n){let i=hl.exec(e.content);return ce(t,e.indent),i===null||i[1]!==n?(t.error(l.InvalidSpecificationClock,`Invalid '${n} clock' - expected '${n} clock "<ISO 8601 instant>"', such as '${n} clock "2026-10-05T08:00:00Z"'`,p(e)),null):{kind:"SpecificationClockSyntax",instant:i[2],location:p(e)}}c(_r,"parseClock");function Jr(t,e,n){return ni(t,e,xl,l.InvalidSpecificationCapture,`${n} capture`,`${n} capture <Capture>`,(i,r)=>({kind:"SpecificationCaptureSyntax",capture:i,record:r,location:p(e)}))}c(Jr,"parseCapture");function ni(t,e,n,i,r,o,a){let s=n.exec(e.content);return s===null?(t.error(i,`Invalid '${r}' declaration '${e.content}' - expected '${o}'`,p(e)),ce(t,e.indent),null):a(s[1],kt(t,e))}c(ni,"parseNamedStep");function Tl(t,e,n){let i=$l.exec(e.content);if(i===null){t.error(l.InvalidSpecificationQueryAction,`Invalid 'then result' declaration '${e.content}' - expected 'then result [exactly]'`,p(e)),ce(t,e.indent);return}n.thenResults.push({kind:"SpecificationQueryResultSyntax",properties:kt(t,e),exactly:i[1]!==void 0,location:p(e)})}c(Tl,"parseResult");function Hr(t,e,n,i){let r=n.exec(e.content);if(r===null){t.error(l.InvalidReadModelStep,`Invalid '${i} readmodel' declaration '${e.content}' - expected '${i} readmodel <ReadModelType>'`,p(e)),ce(t,e.indent);return}return{kind:"SpecificationReadModelSyntax",name:r[1],properties:kt(t,e),exactly:i==="then"&&r[2]!==void 0,location:p(e)}}c(Hr,"parseReadModelStep");function oi(t,e,n,i){let r=n.exec(e.content);if(r===null){t.error(l.InvalidEventStep,`Invalid '${i}' declaration '${e.content}' - expected '${i} <EventType>'`,p(e)),ce(t,e.indent);return}return{kind:"SpecificationEventSyntax",eventType:r[1],...Xr(t,e,void 0,i),location:p(e)}}c(oi,"parseEventStep");var Dl=se("^stream\\s+([A-Za-z_]\\w*)\\.([A-Za-z_]\\w*)$"),Ml=O("^streamId\\s*=(?!=|>)\\s*(.+)$");function Xr(t,e,n,i){let r=[],o=null,a,s,d=!1;for(let f=t.peekChild(e.indent);f!==void 0;f=t.peekChild(e.indent)){if(t.reader.takeSignificant(),n!==void 0&&Ur.test(f.content)){let u=en(t,f,zr,l.InvalidGeneratedFixture);u!==null&&n.push(u);continue}let m=ii.exec(f.content);if(m!==null)r.push(to(t,f,m));else if(R(f.content)==="stream"||f.content.startsWith("no stream")){if(i===void 0){t.error(l.SpecificationStreamOnCommand,"A command occurrence cannot declare a route; assert it on a then event.",p(f)),t.skipBlock(f.indent);continue}if(d){t.error(l.InvalidSpecificationStream,"An event occurrence declares at most one stream or no stream directive.",p(f)),t.skipBlock(f.indent);continue}let u=Dl.exec(f.content);f.content==="no stream"&&i==="then"?(s={kind:"SpecificationNoStreamSyntax",location:p(f)},d=!0,eo(t,f)):u!==null?(a=jl(t,f,u),d=!0):(t.error(l.InvalidSpecificationStream,"Expected 'stream Source.Stream', or 'no stream' on a then event.",p(f)),t.skipBlock(f.indent))}else if(R(f.content)==="for"){let u=f.content.substring(3).trim();u.length===0?t.error(l.InvalidSpecificationEventSource,"Invalid event-source assertion 'for' - expected 'for <value>'",p(f)):o!==null?t.error(l.DuplicateSpecificationEventSource,"A specification step can declare its event-source assertion only once",p(f)):o=ee(u,p(f),t)}else t.error(l.InvalidSpecificationValue,`Invalid property mapping '${f.content}' - expected '<property> = <value>'`,p(f))}return{values:r,for:o,...a===void 0?{}:{stream:a},...s===void 0?{}:{noStream:s}}}c(Xr,"parseValuesWithEventSource");function jl(t,e,n){let i=null;for(let r=t.peekChild(e.indent);r!==void 0;r=t.peekChild(e.indent)){t.reader.takeSignificant();let o=Ml.exec(r.content);if(o===null||i!==null){t.error(l.InvalidSpecificationStream,"A specification stream accepts at most one 'streamId = <literal>' mapping.",p(r)),t.skipBlock(r.indent);continue}let a={...p(r),column:r.indent+1+r.content.indexOf(o[1],r.content.indexOf("=")+1)};i={kind:"PropertyMappingSyntax",property:"streamId",source:ee(o[1],a,t),location:p(r)},eo(t,r)}return{kind:"SpecificationStreamSyntax",eventSource:n[1],stream:n[2],streamId:i,referenceLocation:{...p(e),column:e.indent+1+e.content.indexOf(n[1],6)},referenceLength:n[1].length+1+n[2].length,location:p(e)}}c(jl,"parseSpecificationStream");function eo(t,e){let n=t.peekChild(e.indent);n!==void 0&&(t.error(l.InvalidSpecificationStream,"This directive cannot have children.",p(n)),t.skipBlock(e.indent))}c(eo,"rejectSpecificationRouteChildren");function kt(t,e,n=!1){let i=[];for(let r=t.peekChild(e.indent);r!==void 0;r=t.peekChild(e.indent)){t.reader.takeSignificant();let o=(n||t.sourceOptions.numericMode==="exact"?cl:ii).exec(r.content);if(o===null){t.error(l.InvalidSpecificationValue,`Invalid property mapping '${r.content}' - expected '<property> = <value>'`,p(r));continue}i.push(to(t,r,o,n))}return i}c(kt,"parseValues");function to(t,e,n,i=!1){return{kind:"PropertyMappingSyntax",property:n[1],source:ee(n[2],p(e),t,i),location:p(e)}}c(to,"mappingOf");var Nl=O("^slice\\s+([A-Za-z]\\w*)\\s+([A-Za-z_]\\w*)$"),Ll=new Set(["reducer"]);function no(t,e){let n=Nl.exec(e.content),i="StateChange",r="";n===null?t.error(l.InvalidSliceDeclaration,`Invalid slice declaration '${e.content}' - expected 'slice <Type> <Name>'`,p(e)):(r=n[2],_i.includes(n[1])?i=n[1]:t.error(l.UnknownSliceType,`Unknown slice type '${n[1]}' - expected StateChange, StateView, Automation or Translate`,p(e)));let o=t.scope;t.scope=[...o,r];let a=null,s=[],d=[],f=[],m=[],u=[],h=[],g=[],b=[],x=[],$=[],v=[],k=[];for(let S=t.peekChild(e.indent);S!==void 0;S=t.peekChild(e.indent)){if(t.reader.takeSignificant(),ie(S))continue;let y=R(S.content);y==="description"?a=Z(t,S,a,`Slice '${r}'`):y==="operation"?d.push(Gt(t,S).operation):y==="event"?s.push(ar(t,S)):y==="command"?f.push(Ir(t,S)):y==="query"?m.push(Lr(t,S)):y==="projection"?u.push(Jn(t,S)):y==="capture"?g.push(Yn(t,S)):y==="reaction"?h.push(Br(t,S)):y==="constraint"?b.push(Rr(t,S)):y==="specification"?x.push(ri(t,S)):y==="readmodel"?$.push(sr(t,S)):y==="screen"?v.push(Fr(t,S)):Ll.has(y)?(k.push(Cr(t,S)),t.skipOpaqueBlock(S.indent)):(t.warning(l.UnknownSliceDirective,`Unknown construct '${y}' in slice '${r}'`,p(S)),t.skipBlock(S.indent))}t.scope=o;let P={kind:"SliceSyntax",type:i,name:r,description:a,events:s,operations:d,commands:f,queries:m,projections:u,captures:g,reactions:h,constraints:b,specifications:x,readModels:$,screens:v,location:p(e)};return Fe.set(P,{reducers:k}),P}c(no,"parseSlice");var ql=O("^feature\\s+([A-Za-z_]\\w*)$"),Bl=new Set(["on","uses","contribute"]),ai="description, depends on <Name>, authorize, import, feature, slice, contribute, 'on <trigger>' or 'uses <Behavior>'",bt=class{static{c(this,"FeatureBody")}name;#e=[];#t=[];#r=[];#i=[];#n=null;#a=null;constructor(e){this.name=e}tryParse(e,n){let i=R(n.content);switch(i){case"description":return this.#n=Z(e,n,this.#n,`Feature '${this.name}'`),!0;case"depends":return qt(e,n,this.#i,l.UnknownFeatureDirective),!0;case"authorize":return this.#a=ke(this.#a,De(e,n)),!0;case"import":return Qe(e,n,this.#r),!0;case"feature":return this.#e.push(tn(e,n)),!0;case"slice":return this.#t.push(no(e,n)),!0;default:return Bl.has(i)?(ge(e,n),!0):!1}}build(e,n=!1){return{kind:"FeatureSyntax",name:this.name,description:this.#n,authorize:this.#a,dependsOn:this.#i,features:this.#e,slices:this.#t,fileImports:this.#r,isPlacement:n,location:e}}};function tn(t,e){let n=ql.exec(e.content)?.[1]??"";n===""&&t.error(l.InvalidFeatureDeclaration,`Invalid feature declaration '${e.content}' - expected 'feature <Name>'`,p(e));let i=new bt(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(l.UnknownFeatureDirective,`Unexpected '${R(o.content)}' in feature body - expected ${ai}`,p(o)),t.skipBlock(o.indent));return t.scope=r,i.build(p(e))}c(tn,"parseFeature");var si=O("^module\\s+([A-Za-z_]\\w*)$"),Fl=new Set(["on","uses","screen","dialog","form","contribute"]),ci="description, depends on <Name>, authorize, import, screen template, dialog template, form, contribute, feature, 'on <trigger>' or 'uses <Behavior>'",Ct=class{static{c(this,"ModuleBody")}name;#e=[];#t=[];#r=[];#i=null;#n=null;constructor(e){this.name=e}tryParse(e,n){let i=R(n.content);switch(i){case"description":return this.#i=Z(e,n,this.#i,`Module '${this.name}'`),!0;case"depends":return qt(e,n,this.#r,l.UnknownModuleDirective),!0;case"authorize":return this.#n=ke(this.#n,De(e,n)),!0;case"import":return Qe(e,n,this.#t),!0;case"feature":return this.#e.push(tn(e,n)),!0;default:return Fl.has(i)?(ge(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(l.UnknownModuleDirective,`Unexpected '${R(i.content)}' in module body - expected ${ci}`,p(i)),e.skipBlock(i.indent))}build(e,n=!1){return{kind:"ModuleSyntax",name:this.name,description:this.#i,authorize:this.#n,dependsOn:this.#r,features:this.#e,fileImports:this.#t,isPlacement:n,location:e}}};function li(t,e){let n=si.exec(e.content)?.[1]??"";n===""&&t.error(l.InvalidModuleDeclaration,`Invalid module declaration '${e.content}' - expected 'module <Name>'`,p(e));let i=new Ct(n),r=t.scope;return t.scope=[n],i.parseChildren(t,e),t.scope=r,i.build(p(e))}c(li,"parseModule");var Ul=new WeakMap,Xe=c(t=>JSON.stringify(t),"authoredOrderKey");function Et(t){return Ul.get(t)??new Map}c(Et,"authoredOrderOf");function Se(t){return[...t.events,...t.commands.flatMap(e=>e.produces).flatMap(e=>e.inlineEvent===null?[]:[e.inlineEvent])]}c(Se,"eventDeclarations");var je=["usesFactsFrom","reactsTo","decidesFrom","asks","shows","verifiedWith","outsideTheModel"];var Ae=class extends Error{static{c(this,"InvalidDependencyQuery")}};var et=class{static{c(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))}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==="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.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.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.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)}visitCommandStream(e){this.visitNode(e),e.streamId!==null&&this.visitPropertyMapping(e.streamId),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))}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){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}}visitSpecification(e){this.visitNode(e),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.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))}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))}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)}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 zl={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",formCommand:"asks",dataQuery:"shows",populate:"shows",navigate:"shows",specificationEvent:"verifiedWith",givenEvent:"verifiedWith",whenAppendedEvent:"verifiedWith",thenEvent:"verifiedWith",whenCommand:"verifiedWith",declares:null,uses:null,commandEventSource:null,commandStream:null,thenOperation:null,givenOperationFailure:null,thenCompensated:null,produces:null,authorizes:null,queryResult:null,dataReadModel:null,type: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 nn(t){let e=new fi;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}}c(nn,"sliceReferences");var fi=class extends et{static{c(this,"SliceReferenceCollector")}references=[];shared=[];specification;projection=!1;visitSlice(e){super.visitSlice(e),He(e).reducers?.forEach(i=>this.visitReducer(i))}visitCommand(e){let n=He(e);n.reads?.forEach(i=>this.visitReads(i)),n.concurrency!=null&&this.visitConcurrency(n.concurrency),super.visitCommand(e)}visitReactionTrigger(e){let n=He(e);n.data?.forEach(i=>this.visitTriggerData(i)),n.reads?.forEach(i=>this.visitReads(i)),super.visitReactionTrigger(e)}visitProjection(e){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=c((i,r,o)=>{this.references.push({name:i,targetKind:r,role:o,kind:zl[o],location:e.location,timeline:this.projection||o==="trigger"})},"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"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"ConcurrencySyntax":e.eventTypes.forEach(i=>n(i,"Event","concurrency"));break}}};function Pt(t){let e=new Map,n=new Map,i=[],r=new Set,o=[],a=c(s=>{e.set(s,e.size),n.set(s,e.get(s)),i.push(s),r.add(s);for(let m of[...t.get(s)].sort())e.has(m)?r.has(m)&&n.set(s,Math.min(n.get(s),e.get(m))):(a(m),n.set(s,Math.min(n.get(s),n.get(m))));if(n.get(s)!==e.get(s))return;let d=[],f;do f=i.pop(),r.delete(f),d.push(f);while(f!==s);o.push(d.sort())},"visit");for(let s of[...t.keys()].sort())e.has(s)||a(s);return o}c(Pt,"stronglyConnectedGroups");var oo=["usesFactsFrom","reactsTo","decidesFrom"],Ee=c((t,e)=>t<e?-1:t>e?1:0,"ordinal"),ao=c((t,e)=>JSON.stringify([t,e.toLowerCase()]),"declarationKey"),ui=c((t,e,n,i)=>({kind:t,address:e,scope:n,rank:i,key:`${t}:${e}`}),"nodeOf"),yi=c((t,e)=>t.rank-e.rank||Ee(t.key,e.key),"compareNodes"),Ot=c(t=>[...new Map([...t].map(e=>[e.key,e])).values()].sort(yi),"distinctNodes"),so=c((t,e)=>t.consumer.rank-e.consumer.rank||t.location.line-e.location.line||t.location.column-e.location.column||je.indexOf(t.kind)-je.indexOf(e.kind)||t.producer.rank-e.producer.rank||Ee(t.location.path??"",e.location.path??"")||Ee(t.role,e.role)||Ee(t.name,e.name),"compareEvidence");function Si(t){return t.flatMap(e=>e.kind==="ProjectionVariantSyntax"?[e,...Si(e.blocks)]:e.kind==="ChildrenSyntax"||e.kind==="NestedSyntax"?Si(e.blocks):[])}c(Si,"variants");var rn=class t{static{c(this,"DependencyGraph")}orderSource;edges;unresolved;excludedReferences;unusedImports;modelNodes=[];slices=[];children=new Map;byKey=new Map;parents=new Map;root=ui("application","",[],-1);static for(e,n=Et(e)){return new t(e,n)}get nodes(){return this.modelNodes}constructor(e,n){this.orderSource=n.size>0?"authored":"syntax",this.children.set(this.root.key,[]);let i=c((k,P)=>k.map((S,y)=>({syntax:S,index:y,rank:n.get(Xe([...P.scope,S.name]))??Number.MAX_SAFE_INTEGER})).sort((S,y)=>S.rank-y.rank||S.index-y.index).map(S=>S.syntax),"ordered"),r=c((k,P)=>{let S=this.add("feature",k.name,P);for(let y of i(k.slices,S))this.slices.push({node:this.add("slice",y.name,S),syntax:y});for(let y of i(k.features,S))r(y,S)},"feature");for(let k of i(e.modules,this.root)){let P=this.add("module",k.name,this.root);for(let S of i(k.features,P))r(S,P)}let o=new Map,a=new Map,s=c((k,P,S,y)=>{let C=ao(P,S);k.has(C)||k.set(C,[]);let E=k.get(C);E.includes(y)||E.push(y)},"declare");for(let{node:k,syntax:P}of this.slices){for(let S of Se(P))s(o,"Event",S.name,k);for(let S of P.commands)s(o,"Command",S.name,k);for(let S of P.queries)s(o,"Query",S.name,k);for(let S of P.screens)s(o,"Screen",S.name,k);for(let S of P.readModels)s(o,"ReadModel",S.name,k);for(let S of P.projections){let y=Si(S.blocks);y.length===0&&s(a,"ReadModel",S.readModel??S.name,k);for(let C of y)s(a,"ReadModel",C.name,k)}for(let S of He(P).reducers??[])s(a,"ReadModel",S.readModel,k)}let d=new Set((e.declaredTriggers??[]).map(k=>k.name.toLowerCase())),f=new Set([...e.concepts,...e.types].map(k=>k.name.toLowerCase())),m=new Set((e.policies??[]).map(k=>k.name.toLowerCase())),u=e.imports.filter(k=>k.qualifiedName.includes(".")).slice().sort((k,P)=>Ee(k.location.path??"",P.location.path??"")||k.location.line-P.location.line||k.location.column-P.location.column||Ee(k.qualifiedName,P.qualifiedName)),h=new Map,g=[],b=[],x=new Set,$=0;for(let{node:k,syntax:P}of this.slices){let S=nn(P);$+=S.shared.filter(y=>(y.kind==="type"?f:m).has(y.name.toLowerCase())).length;for(let y of S.references){let C=ao(y.targetKind,y.name),A=(y.targetKind==="ReadModel"&&a.has(C)?a:o).get(C);if(A!==void 0&&A.length>0){let D=A[0];D!==k&&g.push({consumer:k,producer:D,kind:y.kind,role:y.role,name:y.name,ambiguous:A.length>1,alternatives:A.slice(1),location:y.location,testOnly:y.kind==="verifiedWith"});continue}if(y.role==="trigger"&&d.has(y.name.toLowerCase())){$++;continue}let w=y.targetKind==="Event"?u.filter(D=>D.qualifiedName.slice(D.qualifiedName.lastIndexOf(".")+1).toLowerCase()===y.name.toLowerCase()):[];if(w.length>0){let D=[];for(let j of w){x.add(j.qualifiedName);let q=j.qualifiedName.slice(0,j.qualifiedName.lastIndexOf(".")),M=`context:${q}`;if(!h.has(M)){let W=ui("context",M,[q],this.modelNodes.length);this.modelNodes.push(W),h.set(M,W)}let L=h.get(M);D.includes(L)||D.push(L)}g.push({consumer:k,producer:D[0],kind:"outsideTheModel",role:y.role,name:y.name,ambiguous:D.length>1,alternatives:D.slice(1),location:y.location,testOnly:y.kind==="verifiedWith"});continue}b.push({consumer:k,kind:y.kind,role:y.role,name:y.name,location:y.location})}}let v=new Map;for(let k of g.sort(so)){let P=JSON.stringify([k.consumer.key,k.producer.key,k.kind]);v.has(P)||v.set(P,[]),v.get(P).push(k)}this.edges=[...v.values()].map(k=>({consumer:k[0].consumer,producer:k[0].producer,kind:k[0].kind,evidence:k})),this.unresolved=b.sort((k,P)=>k.consumer.rank-P.consumer.rank||k.location.line-P.location.line||k.location.column-P.location.column||je.indexOf(k.kind)-je.indexOf(P.kind)||Ee(k.location.path??"",P.location.path??"")||Ee(k.name,P.name)),this.excludedReferences=$,this.unusedImports=[...new Set(u.filter(k=>!x.has(k.qualifiedName)).map(k=>k.qualifiedName))]}implied(e,n,i,r=!1,o=3){if(!["slice","feature","module"].includes(e))throw new Ae(`Unsupported source level '${e}'.`);if(!["slice","feature","module","context"].includes(n))throw new Ae(`Unsupported target level '${n}'.`);if(o<0)throw new Ae("Evidence limit must not be negative.");let a=new Map;for(let s of this.evidence(i,r))for(let d of this.at(s.consumer,e))for(let f of this.at(s.producer,n).filter(m=>this.disjoint(d,m))){let m=JSON.stringify([d.key,f.key]);a.has(m)||a.set(m,{source:d,target:f,evidence:[]}),a.get(m).evidence.push(s)}return[...a.values()].sort((s,d)=>s.source.rank-d.source.rank||s.target.rank-d.target.rank||Ee(s.source.key,d.source.key)||Ee(s.target.key,d.target.key)).map(s=>{let d=s.evidence.sort(so),f={};for(let m of je){let u=d.filter(h=>h.kind===m).length;u>0&&(f[m]=u)}return{source:s.source,target:s.target,sliceEdges:new Set(d.map(m=>JSON.stringify([m.consumer.key,m.producer.key]))).size,references:d.length,byKind:f,consumers:Ot(d.map(m=>m.consumer)),producers:Ot(d.map(m=>m.producer)),evidence:d.slice(0,o),evidenceCount:d.length,evidenceTruncated:d.length>o}})}cycles(e,n){if(!["slice","feature","module"].includes(e))throw new Ae(`Unsupported cycle level '${e}'.`);let i=this.implied(e,e,co(n)),r=Ot(i.flatMap(o=>[o.source,o.target]));return lo(mi(r,i),r,null)}siblingGroups(e){let n=this.siblingEdges(e);return this.containers().flatMap(i=>{let r=this.children.get(i.key);return lo(mi(r,n.filter(o=>o.container===i)),r,i)})}suggestedOrder(e){let n=this.siblingEdges(e),i=[];for(let s of this.containers()){let d=this.children.get(s.key),f=n.filter($=>$.container===s),m=new Map(d.map($=>[$.key,$])),u=Pt(mi(d,f)).map($=>$.map(v=>m.get(v)).sort(yi)).sort(($,v)=>$[0].rank-v[0].rank),h=new Map(u.flatMap(($,v)=>$.map(k=>[k.key,v]))),g=new Map(d.map($=>[$.key,new Set]));for(let $ of f)h.get($.source.key)!==h.get($.target.key)&&g.get($.source.key).add($.target.key);for(let $ of u)for(let v=1;v<$.length;v++)g.get($[v].key).add($[v-1].key);let b=new Set(d.map($=>$.key)),x=[];for(;b.size>0;){let $=[...b].filter(v=>g.get(v).size===0).sort((v,k)=>yi(m.get(v),m.get(k)))[0];x.push(m.get($)),b.delete($);for(let v of b)g.get(v).delete($)}i.push({container:s,children:x,changed:d.some(($,v)=>$!==x[v])})}let r=new Map(i.map(s=>[s.container.key,s.children])),o=[],a=c(s=>{if(s.kind==="slice")o.push(s);else for(let d of[...r.get(s.key)].sort((f,m)=>+(f.kind!=="slice")-+(m.kind!=="slice")))a(d)},"walk");return a(this.root),{containers:i,slices:o}}traverse(e,n,i,r=!1){if(n!=="incoming"&&n!=="outgoing")throw new Ae(`Unsupported dependency direction '${n}'.`);let o=this.evidence(i,r).map(f=>n==="incoming"?{source:f.producer,target:f.consumer}:{source:f.consumer,target:f.producer}),a=new Set([e]),s=[e],d=[];for(let f=0;f<s.length;f++)for(let m of o.filter(u=>u.source.address===s[f]).sort((u,h)=>u.target.rank-h.target.rank))a.has(m.target.address)||(a.add(m.target.address),d.push(m.target),s.push(m.target.address));return Ot(d)}add(e,n,i){let r=[...i.scope,n],o=r.join("."),a=`${e}:${o}`,s=this.byKey.get(a);if(s!==void 0)return s;let d=ui(e,o,r,this.modelNodes.length);return this.modelNodes.push(d),this.byKey.set(a,d),this.parents.set(a,i),this.children.get(i.key).push(d),e!=="slice"&&this.children.set(a,[]),d}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=po(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(co(e),!1)){let r=this.path(i.consumer),o=this.path(i.producer),a=0;for(;a<r.length&&a<o.length&&r[a].key===o[a].key;)a++;a===r.length||a===o.length||n.push({container:a===0?this.root:r[a-1],source:r[a],target:o[a]})}return n}};function po(t){let e=new Set(t??je);if([...e].some(n=>!je.includes(n)))throw new Ae("Unsupported dependency kind.");return e}c(po,"selectedKinds");function co(t){return[...po(t??oo)].filter(e=>oo.includes(e))}c(co,"selectedOrderingKinds");function mi(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}c(mi,"adjacency");function lo(t,e,n){let i=new Map(e.map(r=>[r.key,r]));return Pt(t).filter(r=>r.length>1).map(r=>({container:n,members:Ot(r.map(o=>i.get(o)))})).sort((r,o)=>r.members[0].rank-o.members[0].rank)}c(lo,"groupsOf");var Vl=["usesFactsFrom","reactsTo","decidesFrom","asks","shows"],Pe=c((t,e)=>e===t||e.startsWith(t+"."),"contains"),tt=c((t,e)=>t<e?-1:t>e?1:0,"ordinal"),Ql=c((t,e)=>tt(t.location.path??"",e.location.path??"")||t.location.line-e.location.line||t.location.column-e.location.column||tt(t.kind,e.kind)||tt(t.consumer.address,e.consumer.address)||tt(t.producer.address,e.producer.address)||tt(t.role,e.role)||tt(t.name,e.name),"orderedEvidence"),nt=class{static{c(this,"DeclaredDependencies")}static for(e){let n=new Map,i=c((u,h)=>{let g=u.join(".");n.has(g)||n.set(g,{location:h.location,dependencies:[]}),n.get(g).dependencies.push(...h.dependsOn??[]),h.features.forEach(b=>i([...u,b.name],b))},"inventory");if(e.modules.forEach(u=>i([u.name],u)),![...n.values()].some(u=>u.dependencies.length))return{containers:[],diagnostics:[]};let r=rn.for(e,new Map),o=r.nodes.filter(u=>u.kind==="module"||u.kind==="feature"),a=o.map(u=>({name:u.scope.at(-1),scope:u.scope.slice(0,-1)})),s=c((u,h)=>{let g=ut.resolve(u,h,a).resolved;return g&&[...g.scope,g.name].join(".")},"resolve"),d=[],f=[],m=c((u,h,g,b)=>f.push({code:u,severity:h,message:g,location:b}),"finding");for(let u of o.filter(h=>n.get(h.address).dependencies.length)){let h=n.get(u.address),g=h.dependencies.map($=>{let v=s($.target,u.scope),k=v!==void 0&&!Pe(u.address,v)&&!Pe(v,u.address);return{syntax:$,resolved:v,status:k?"unused":"invalid"}}),b=[],x=new Map;for(let $ of r.edges.flatMap(v=>v.evidence).filter(v=>Vl.includes(v.kind)&&Pe(u.address,v.consumer.address)).sort(Ql)){let v=[$.producer,...$.alternatives].filter(S=>!Pe(u.address,S.address)&&!Pe(S.scope.slice(0,-1).join("."),u.address));if(!v.length)continue;let k=g.filter(S=>S.status!=="invalid"&&v.some(y=>Pe(S.resolved,y.address)));for(let S of k)S.status=$.ambiguous&&S.status!=="used"?"provisional":"used";let P=$.ambiguous?"provisional":k.length?"declared":"undeclared";if(b.push({evidence:$,status:P,coveringDeclarations:k.map(S=>S.syntax)}),P==="undeclared"){let S=$.producer.scope[0];x.has(S)||x.set(S,[]),x.get(S).push($)}}for(let $ of x.values()){let v=$[0].producer.scope.slice(0,-1),k=v.findIndex((C,E)=>$.some(A=>E>=A.producer.scope.length-1||A.producer.scope[E]!==C));k>=0&&(v=v.slice(0,k));let P=v.join("."),S=Pe(u.address,P)||Pe(P,u.address)?[...new Set($.map(C=>C.producer.scope.slice(0,-1).map((E,A)=>C.producer.scope.slice(0,A+1).join(".")).find(E=>!Pe(u.address,E)&&!Pe(E,u.address))))]:[P],y=$.map(C=>`${C.kind} ${C.role} '${C.name}' at ${C.location.path??""}:${C.location.line}:${C.location.column}`).join("; ");m(l.UndeclaredDependency,"warning",`Container '${u.address}' depends on '${S.join("', '")}' without declaring ${S.length===1?"it":"them"} - evidence: ${y}`,h.location)}for(let $ of g)$.status==="unused"&&m(l.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(v=>s(v.target,$.resolved.split("."))===u.address)&&m(l.MutualDependencyDeclarations,"information",`Containers '${u.address}' and '${$.resolved}' declare each other`,$.syntax.location);d.push({container:u,location:h.location,declarations:g,edges:b})}return{containers:d,diagnostics:f}}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 hi=class extends Error{static{c(this,"InvalidExactNumber")}};function gi(t){if(t.literalType!=="ExactNumber"||typeof t.value!="string"||Oe(t.value)?.value!==t.value)throw new hi("Expected a canonical, bounded ExactNumber value.");return t.value}c(gi,"canonicalExactText");function fo(t){return!gi(t).includes(".")}c(fo,"exactIsIntegral");var Zl=/^([0-9]{4})-([0-9]{2})-([0-9]{2})$/,Gl=/^([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 xi(t,e){let n=(e?Gl:Zl).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]),s=[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>s[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 d=Number(n[7]),f=Number(n[8]);return d<=14&&f<=59&&(d!==14||f===0)}c(xi,"responseDateValue");var on=new Set(["Uuid","String","Int","Decimal","Bool","Date","DateTime"]);function an(t,e,n=e.inputUses){let i=[],r=c((S,y)=>{let C=[...y,S.name];S.slices.forEach(E=>i.push({slice:E,scope:[...C,E.name]})),S.features.forEach(E=>r(E,C))},"collect");t.modules.forEach(S=>S.features.forEach(y=>r(y,[S.name])));let o=new Map,a=new Map,s=new Map;for(let{slice:S,scope:y}of i)for(let C of S.commands){let E=o.get(C.name)??[];E.push({command:C,scope:y}),o.set(C.name,E),a.set(C,te(C.properties)),C.response?.kind==="RecordCommandResponseSyntax"&&s.set(C,te(C.response.fields))}let d=new Map;for(let S of t.imports){let y=S.qualifiedName.split(".").at(-1);d.set(y,[...d.get(y)??[],S.qualifiedName])}let f=new Map,m=c((S,y)=>{let C=`${y.join(".")}|${S}`;if(f.has(C))return f.get(C);let E=d.get(S)??[],D=((o.get(S.split(".").at(-1))??[]).length===0&&E.length===1?E[0]:S).split("."),j=o.get(D.at(-1))??[];if(D.length>1){let M=D.slice(0,-1);j=j.filter(L=>M.length<=L.scope.length&&M.every((W,B)=>L.scope[L.scope.length-M.length+B]===W))}else for(let M=y.length;M>=0;M--){let L=j.filter(W=>M<=W.scope.length&&y.slice(0,M).every((B,Y)=>W.scope[Y]===B));if(L.length>0){j=L;break}}let q=j.length===1?j[0].command:null;return f.set(C,q),q},"resolve"),u=te(t.concepts),h=new Set(t.concepts.map(S=>S.name)),g=new Map([...te(t.types)].map(([S,y])=>[S,te(y.properties)])),b=new Set(i.flatMap(S=>S.slice.readModels.map(y=>y.name))),x=new Set([...a.keys()].flatMap(S=>[...S.properties])),$=c(S=>{for(let y of S)y.isGenerated&&!x.has(y)&&e.error(l.GeneratedPropertyOutsideCommand,"Generated properties can only be declared on commands.",y.location)},"checkDeclarations"),v=c(S=>{S.features.forEach(v);for(let y of S.slices){for(let C of y.commands)for(let E of C.produces)E.inlineEvent!==null&&$(E.inlineEvent.properties);y.events.forEach(C=>$(C.properties)),y.readModels.forEach(C=>$(C.properties));for(let C of y.reactions)for(let E of C.triggers)for(let A of E.produces)A.inlineEvent!==null&&$(A.inlineEvent.properties)}},"checkFeature");t.types.forEach(S=>$(S.properties)),t.modules.forEach(S=>S.features.forEach(v));let k=c((S,y,C)=>{let E=a.get(C).get(S.property);if(E===void 0){e.error(l.InvalidResponseSource,`Response source '${S.property}' must reference one direct command property.`,S.location);return}let A=E.type;(A.isCollection||b.has(A.name))&&e.error(l.InvalidResponseShape,"Collection and whole-read-model responses are not supported.",S.location),y!==null&&(y.name!==A.name||y.isCollection!==A.isCollection||y.isOptional!==A.isOptional)&&e.error(l.InvalidResponseShape,"An explicit response field type must match its source's declared type, collection shape and optionality.",y.location)},"validateSource");for(let S of a.keys()){for(let C of S.properties){if(!C.isGenerated)continue;let E=u.get(C.type.name);(C.type.isOptional||C.type.isCollection||(E===void 0?on.has(C.type.name)||g.has(C.type.name)||h.has(C.type.name)||b.has(C.type.name):E.type!=="Uuid"))&&e.error(l.InvalidGeneratedType,"A generated property must be a required, noncollection concept backed by Uuid.",C.location)}let y=S.response;if(y?.kind==="ScalarCommandResponseSyntax")k(y.source,null,S);else if(y?.kind==="RecordCommandResponseSyntax"){y.fields.length===0&&e.error(l.InvalidCommandResponse,"A response block requires at least one field.",y.location);let C=new Set;for(let E of y.fields)C.has(E.name)&&e.error(l.DuplicateResponseField,`Duplicate response field '${E.name}'.`,E.location),C.add(E.name),k(E.source,E.type,S)}}let P=c((S,y)=>{let C=S.when,E=C===null?null:m(C.commandType,y);if(C!==null&&E!==null){let j=a.get(E);for(let L of C.values)j.get(L.property.split(".")[0])?.isGenerated&&e.error(l.GeneratedPropertySuppliedAsInput,`Generated property '${L.property}' cannot be supplied as request or form input.`,L.location);let q=[...j.values()].filter(L=>L.isIdentifier);if(C.for!==null&&q.length===1&&q[0].isGenerated){let L=q[0].type;(on.has(L.name)||u.has(L.name)||g.has(L.name))&&(L.isOptional||L.isCollection||u.get(L.name)?.type!=="Uuid"||C.for.kind!=="LiteralExpressionSyntax"||typeof C.for.value!="string"||!uo(C.for.value))&&e.error(l.InvalidGeneratedFixture,"A generated identifier fixture must supply one compatible concrete UUID value through 'for'.",C.for.location)}let M=new Set;for(let L of C.generatedValues??[]){let W=j.get(L.property);(M.has(L.property)||W===void 0||!W.isGenerated||W.isIdentifier||!ve(L.source,W.type,u,g))&&e.error(l.InvalidGeneratedFixture,"A generated fixture must uniquely supply a compatible value for a nonidentifier generated command property.",L.location),M.add(L.property)}}let A=S.thenReturns;if(A==null||((C===null||S.thenErrors.length>0||S.thenDenied!=null)&&e.error(l.InvalidReturnExpectation,"A return expectation requires a command action and cannot accompany an error or denial.",A.location),E===null))return;let w=E.response,D=a.get(E);if(A.kind==="ScalarSpecificationReturnSyntax"&&w?.kind==="ScalarCommandResponseSyntax"&&D.has(w.source.property))ve(A.value,D.get(w.source.property).type,u,g)||e.error(l.InvalidReturnExpectation,"The expected return value must match the response source's type.",A.location);else if(A.kind==="RecordSpecificationReturnSyntax"&&w?.kind==="RecordCommandResponseSyntax"){A.fields.length===0&&e.error(l.InvalidReturnExpectation,"A record return expectation requires at least one field.",A.location);let j=s.get(E),q=new Set;for(let M of A.fields){let L=j.get(M.property),W=L===void 0?void 0:D.get(L.source.property);(q.has(M.property)||W===void 0||!ve(M.source,W.type,u,g))&&e.error(l.InvalidReturnExpectation,"A return assertion must uniquely name a response field and supply a compatible concrete value.",M.location),q.add(M.property)}}else e.error(l.InvalidReturnExpectation,"The return expectation must match the command's scalar or record response shape.",A.location)},"validateSpecification");for(let{slice:S,scope:y}of i)S.specifications.forEach(C=>P(C,y));for(let S of n){if(S.isParameter===!0)continue;let y=m(S.command,S.scope);y!==null&&a.get(y).get(S.property.split(".")[0])?.isGenerated&&e.error(l.GeneratedPropertySuppliedAsInput,`Generated property '${S.property}' cannot be supplied as request or form input.`,S.location)}}c(an,"validateResponses");function te(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}c(te,"uniqueByName");function ve(t,e,n,i){if(t.kind==="LiteralExpressionSyntax"&&t.value===null)return e.isOptional;if(e.isCollection)return t.kind==="ListExpressionSyntax"&&t.items.every(s=>ve(s,{...e,isCollection:!1,isOptional:!1},n,i));let r=i.get(e.name);if(r!==void 0)return t.kind==="ObjectExpressionSyntax"&&t.members.every(s=>{let d=r.get(s.name);return d!==void 0&&ve(s.value,d.type,n,i)});let o=n.get(e.name),a=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(a){case"Uuid":return typeof t.value=="string"&&uo(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&&fo(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"&&xi(t.value,!1);case"DateTime":return typeof t.value=="string"&&xi(t.value,!0);default:return!on.has(a)}return!on.has(a)&&o===void 0}c(ve,"compatibleValue");var Kl=/^(?:[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 uo(t){return Kl.test(t)}c(uo,"uuidValue");var We=class t{static{c(this,"LineReader")}lines;#e=0;constructor(e){this.lines=e}get atEnd(){return this.lines.slice(this.#e).every(Nn)}fork(){let e=new t(this.lines);return e.#e=this.#e,e}peekSignificant(){for(;this.#e<this.lines.length&&Nn(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 sn(t,e,n,i=!1){let r=[],o=[],a=ye,s=!1,d=!1,f=!1,m=new Map,u=new pe(new We([]),e,n).languages;for(let g of t){let b=g;if(b.number===1&&b.raw.startsWith("\uFEFF")){let x=b.raw.substring(1),$=x.length-x.trimStart().length,v=ft(x.substring($),i);b={...b,indent:$,contentOffset:1,content:(v<0?x.substring($):x.substring($,$+v)).trimEnd()}}if(f){Zn(b)&&(f=!1),r.push(b);continue}if(b.content.startsWith("```")&&(["```","```text","```markdown"].includes(b.content)||u.has(b.content.substring(3)))&&(f=!0),!f&&b.indent===0&&R(b.content)==="numbers"){let x=b.content!=="numbers exact"?l.InvalidNumericDirective:s?l.DuplicateNumericDirective:d?l.LateNumericDirective:void 0;x!==void 0?(o.push({severity:"error",code:x,message:"Expected one 'numbers exact' preamble before domain, imports and declarations.",location:p(b)}),a=Object.freeze({numericMode:"invalid"})):a=Vt,s=!0,r.push({...b,content:""});continue}!f&&b.indent>0&&/^numbers(\s+(exact|legacy))?$/.test(b.content)&&m.set(b.number,{severity:"error",code:l.InvalidNumericDirective,message:"Expected 'numbers exact' only as the document preamble, not inside a body.",location:p(b)}),d||=b.content.trim().length>0,r.push(b)}let h=new pe(new We(s?r:t),e,n);return h.sourceOptions=a,h.nestedNumericDirectives=m,o.forEach(g=>h.error(g.code,g.message,g.location)),h}c(sn,"sourceContext");function cn(t){return[...t.operations??[],...t.commands.flatMap(e=>e.produces).flatMap(e=>e.inlineOperation==null?[]:[e.inlineOperation])]}c(cn,"operationDeclarations");var J;(function(t){t.Event="event",t.Operation="operation",t.Unresolved="unresolved",t.Ambiguous="ambiguous"})(J||(J={}));var oe=class{static{c(this,"AuthoringProductionResolver")}declarations=[];slices=[];byName=new Map;scopes=new Map;resolutions=new Map;constructor(e){let n=c((i,r)=>{for(let o of i){let a=[...r,o.name];for(let s of o.slices)this.slices.push({slice:s,scope:[...a,s.name]});n(o.features,a)}},"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 s of Se(i)){let d=o.get(s.name)??[];d.push(s),o.set(s.name,d)}let a=[...o.values()].flatMap(s=>new Set(s.map(d=>d.generation)).size!==s.length?s:[s.reduce((d,f)=>d.generation>=f.generation?d:f)]);this.declarations.push(...a.map(s=>({kind:J.Event,name:s.name,node:s,scope:r})),...cn(i).map(s=>({kind:J.Operation,name:s.name,node:s,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:J.Unresolved,declaration:null,candidates:[]};let r=this.resolutions.get(n)??new Map,o=r.get(e);if(o!==void 0)return o;let a=this.candidates(e,i),s=a.length===1?{kind:a[0].kind,declaration:a[0],candidates:[]}:{kind:a.length===0?J.Unresolved:J.Ambiguous,declaration:null,candidates:a};return r.set(e,s),this.resolutions.set(n,r),s}isOperation(e,n){return e.inlineOperation!=null||this.resolve(e.event,n).kind===J.Operation}isEventProduction(e,n){if(e.inlineOperation!=null)return!1;let i=this.resolve(e.event,n);return i.kind!==J.Operation&&!(i.kind===J.Ambiguous&&i.candidates.some(r=>r.kind===J.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(a=>o.length<=a.scope.length&&o.every((s,d)=>a.scope[a.scope.length-o.length+d]===s));for(let a=n.length;a>=0;a--){let s=r.filter(d=>a<=d.scope.length&&n.slice(0,a).every((f,m)=>d.scope[m]===f));if(s.length>0)return s}return[]}};function mo(t,e){return t.produces.filter(n=>n.inlineOperation==null&&(e===void 0||e.resolver.isEventProduction(n,e.slice)))}c(mo,"eventProductions");function vi(t,e){let n=mo(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)}c(vi,"requiresExplicitDestinations");function yo(t,e,n){let i=mo(t,n);if(e.inlineOperation!=null||n!==void 0&&!n.resolver.isEventProduction(e,n.slice)||e.for!==null||vi(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}c(yo,"implicitDestination");function ln(t,e){let n=[],i=c(s=>{n.push(...s.slices),s.features.forEach(i)},"inFeature");t.modules.forEach(s=>s.features.forEach(i));let r=new Map;for(let s of n.flatMap(Se))r.set(s.name,(r.get(s.name)??0)+1);let o=new Set(t.imports.map(s=>s.qualifiedName.split(".").at(-1))),a=new oe(t);for(let{slice:s,command:d}of n.flatMap(f=>f.commands.map(m=>({slice:f,command:m})))){let f=d.produces.filter(h=>a.isEventProduction(h,s)),m=d.properties.find(h=>h.isIdentifier)?.name,u=vi(d,{resolver:a,slice:s});for(let h of f){let g=h.inlineEvent;g!==null&&((r.get(g.name)??0)>1||o.has(g.name))&&e.error(l.InlineEventCollision,`Inline event '${g.name}' collides with another event declaration or import`,h.location),u&&h.for===null&&e.error(l.ExplicitProducesTargetsRequired,`Production '${h.event}' in command '${d.name}' must state 'for' explicitly - every production must state 'for' when destinations differ`,h.location);let b=h.for?.kind==="PathExpressionSyntax"?h.for.path:h.for===null&&g!==null?m:void 0;if(!(m===void 0||b!==m))for(let x of h.mappings.filter($=>$.source.kind==="PathExpressionSyntax"&&$.source.path===m)){let $=`Event '${h.event}' copies command identifier '${m}' into payload property '${x.property}' although it already identifies the event source`;g===null?e.information(l.EventSourceIdInPayload,$,x.location):e.warning(l.EventSourceIdInPayload,$,x.location)}}}}c(ln,"validateInlineEvents");function dn(t,e){let n=new oe(t),i=te(t.concepts),r=new Map([...te(t.types)].map(([v,k])=>[v,te(k.properties)])),o=new Set(["Uuid","String","Int","Decimal","Bool","Date","DateTime",...i.keys(),...r.keys()]),a=new Set(t.imports.map(v=>v.qualifiedName.split(".").at(-1))),s=new Map;for(let v of t.imports){let k=v.qualifiedName.split(".").at(-1);s.set(k,[...s.get(k)??[],v.qualifiedName])}let d=c(v=>{let k=new Map,P=new Map;for(let S of v){let y=k.get(S.name)??[];y.push(S),k.set(S.name,y)}return(S,y)=>{let C=JSON.stringify([S,y]);if(P.has(C))return P.get(C);let E=c(j=>{let q=j.split("."),M=k.get(q.at(-1))??[],L=q.slice(0,-1);if(L.length>0)return M.filter(W=>L.length<=W.scope.length&&L.every((B,Y)=>W.scope[W.scope.length-L.length+Y]===B));for(let W=y.length;W>=0;W--){let B=M.filter(Y=>W<=Y.scope.length&&y.slice(0,W).every((ae,ne)=>Y.scope[ne]===ae));if(B.length>0)return B}return[]},"candidates"),A=E(S),w=s.get(S)??[];A.length===0&&w.length===1&&(A=E(w[0]));let D=A.length===1?A[0].node:null;return P.set(C,D),D}},"scoped"),f=d(n.slices.flatMap(({slice:v,scope:k})=>v.readModels.map(P=>({name:P.name,scope:k,node:P})))),m=d(n.slices.flatMap(({slice:v,scope:k})=>v.commands.map(P=>({name:P.name,scope:k,node:{command:P,slice:v}})))),u=new Map;for(let v of t.systems??[])u.has(v.name)&&e.error(l.InvalidSystemDeclaration,`System '${v.name}' is declared more than once.`,v.location),u.set(v.name,(u.get(v.name)??0)+1);let h=c((v,k,P=!0)=>{let[S,...y]=k.split("."),C=v.filter(D=>D.name===S);if(C.length!==1)return{type:null,missing:C.length===0};let E=C[0].type;if(y.length===0)return{type:E,missing:!1};let A=r.get(E.name);if(A===void 0)return{type:null,missing:o.has(E.name)};let w=h([...A.values()],y.join("."),P);return w.type===null?w:{type:{...w.type,isOptional:P&&E.isOptional||w.type.isOptional,isCollection:E.isCollection||w.type.isCollection},missing:!1}},"pathType"),g=c((v,k,P,S,y=new Set)=>{if(P.has(k)||v.isOptional&&!S.has(k))return!0;if(v.isCollection||y.has(v.name))return!1;let C=r.get(v.name);return C===void 0?S.has(k)&&!o.has(v.name):[...C.values()].every(E=>g(E.type,`${k}.${E.name}`,P,S,new Set([...y,v.name])))},"covered"),b=c((v,k)=>{if(v.kind==="ListExpressionSyntax"&&k.isCollection)return v.items.every(S=>b(S,{...k,isCollection:!1,isOptional:!1}));let P=r.get(k.name);return v.kind!=="ObjectExpressionSyntax"||P===void 0?!0:[...P.values()].every(S=>(S.type.isOptional||v.members.some(y=>y.name===S.name))&&v.members.filter(y=>y.name===S.name).every(y=>b(y.value,S.type)))},"completeValue"),x=c(v=>v.kind==="LiteralExpressionSyntax"?typeof v.value!="number"||Number.isFinite(v.value):v.kind==="ObjectExpressionSyntax"?v.members.every(k=>x(k.value)):v.kind==="ListExpressionSyntax"&&v.items.every(x),"concrete"),$=c((v,k,P,S,y)=>{let C=new Set,E=new Set(v.map(w=>w.property)),A=new Set;for(let w of v){let D=w.property.split(".");for(let j=1;j<=D.length;j++)A.add(D.slice(0,j).join("."))}for(let w of v){C.has(w.property)&&e.error(l.InvalidOperationMapping,`Duplicate operation input mapping '${w.property}'.`,w.location),C.add(w.property);let D=h(k.inputs,w.property,!1);if(D.missing&&e.error(l.InvalidOperationMapping,`Operation '${k.name}' declares no input '${w.property}'.`,w.location),D.type===null)continue;let j=w.property.split(".");for(let q=1;q<j.length;q++)E.has(j.slice(0,q).join("."))&&e.error(l.InvalidOperationMapping,`Operation input mapping '${w.property}' overlaps a whole input mapping.`,w.location);if(P!==null&&w.source.kind==="PathExpressionSyntax"){let q=h(P.properties,w.source.path),M=w.source.path.split("."),L=(Qt.get(P)??[]).filter(Y=>(Y.alias??Y.readModel)===M[0]);if(q.missing&&L.length>0){q={type:null,missing:!1};let Y=L.length===1?f(L[0].readModel,y):null;M.length>1&&Y!==null&&(q=h(Y.properties,M.slice(1).join(".")))}q.missing&&e.error(l.InvalidOperationMapping,`Command '${P.name}' declares no source '${w.source.path}'.`,w.source.location);let W=q.type,B=D.type;W!==null&&o.has(W.name)&&o.has(B.name)&&(W.name!==B.name||W.isCollection!==B.isCollection||W.isOptional&&!B.isOptional)&&e.error(l.InvalidOperationMapping,`Source '${w.source.path}' is incompatible with input '${w.property}' of operation '${k.name}'.`,w.source.location)}else["LiteralExpressionSyntax","ObjectExpressionSyntax","ListExpressionSyntax"].includes(w.source.kind)&&(!ve(w.source,D.type,i,r)||S&&!b(w.source,D.type))&&e.error(l.InvalidOperationMapping,`Value is incompatible with input '${w.property}' of operation '${k.name}'.`,w.source.location)}if(S)for(let w of k.inputs)g(w.type,w.name,C,A)||e.error(l.InvalidOperationMapping,`Production of operation '${k.name}' supplies no value for required input '${w.name}'.`,k.location)},"validateMappings");for(let{slice:v,scope:k}of n.slices){let P=cn(v),S=new Set(Se(v).map(y=>y.name));for(let y of P){S.has(y.name)&&e.error(l.ProductionDeclarationCollision,`Operation '${y.name}' collides with another event or operation in slice '${v.name}'.`,y.location),S.add(y.name),y.uses.length>0&&u.get(y.uses)!==1&&e.error(l.InvalidSystemReference,`Operation '${y.name}' must use one declared system; '${y.uses}' does not resolve uniquely.`,y.usesLocation??y.location);for(let C of y.inputs)!o.has(C.type.name)&&!a.has(C.type.name)&&e.warning(l.UnknownType,`Unknown type '${C.type.name}' on input '${C.name}' of operation '${y.name}'.`,C.type.location)}for(let y of v.commands)for(let C of y.produces){let E=n.resolve(C.event,v);E.kind===J.Ambiguous&&E.candidates.some(A=>A.kind===J.Operation)&&e.error(l.InvalidProductionReference,`Production '${C.event}' is ambiguous.`,C.location),C.event.includes(".")&&E.kind!==J.Operation&&e.error(l.InvalidProductionReference,"Qualified productions are supported only for explicitly declared operations.",C.location),E.declaration?.node.kind==="OperationSyntax"&&((C.for!==null||C.tags.length>0)&&e.error(l.InvalidOperationDeclaration,"Operation productions cannot declare event destinations or tags.",C.location),$(C.mappings,E.declaration.node,y,!0,k))}for(let y of v.reactions.flatMap(C=>C.triggers).flatMap(C=>C.produces)){let C=n.resolve(y.event,v);C.kind===J.Ambiguous&&C.candidates.some(E=>E.kind===J.Operation)&&e.error(l.InvalidProductionReference,`Production '${y.event}' is ambiguous.`,y.location),y.event.includes(".")&&n.resolve(y.event,v).kind!==J.Operation&&e.error(l.InvalidProductionReference,"Qualified productions are supported only for explicitly declared operations.",y.location),n.isOperation(y,v)&&e.error(l.OperationOutsideCommand,"Operations can only be produced by commands.",y.location)}for(let y of v.specifications){let C=[...y.givenOperationFailures??[],...y.thenOperations??[],...y.thenCompensated??[]];if(C.length===0)continue;let E=m(y.when?.commandType??"",k);(E===null||y.whenAppended!==null||y.whenQuery!==null||y.whenTrigger!==null||y.whenClock!==null||y.whenCapture!==null)&&e.error(l.InvalidOperationSpecification,"Operation fixtures and assertions require a declared command action.",y.location);let A=new Map;for(let w of C){if(w.kind==="SpecificationOperationSyntax")for(let q of w.values)x(q.source)||e.error(l.InvalidOperationSpecification,"Operation assertions require concrete input values.",q.source.location);let D=n.resolve(w.operation,v).declaration?.node;if(D?.kind!=="OperationSyntax"){e.error(l.InvalidOperationSpecification,`'${w.operation}' does not resolve uniquely to a declared operation.`,w.location);continue}let j=A.get(D)??new Set;if(j.has(w.kind)&&e.error(l.InvalidOperationSpecification,`Duplicate operation step '${w.operation}'.`,w.location),j.add(w.kind),A.set(D,j),w.kind==="SpecificationCompensatedSyntax"&&D.compensate===null&&e.error(l.InvalidOperationSpecification,`Operation '${w.operation}' declares no compensation.`,w.location),E!==null&&E.command.handler==null){let q=E.command.produces.map(M=>n.resolve(M.event,E.slice));q.every(M=>M.kind===J.Event||M.kind===J.Operation)&&!q.some(M=>M.declaration?.node===D)&&e.error(l.InvalidOperationSpecification,`Command '${E.command.name}' does not produce operation '${w.operation}'.`,w.location)}w.kind==="SpecificationOperationSyntax"&&$(w.values,D,null,!1,k)}}}}c(dn,"validateOperations");var _l=_("^policy\\s+([A-Za-z_]\\w*)$");function So(t,e){t=t.valueContext;let n=_l.exec(e.content)?.[1]??"";n===""&&t.error(l.InvalidPolicyDeclaration,`Invalid policy declaration '${e.content}' - expected 'policy <Name>'`,p(e));let i=null,r=null,o=null,a=!1;for(let s=t.peekChild(e.indent);s!==void 0;s=t.peekChild(e.indent))if(t.reader.takeSignificant(),R(s.content)==="require"){let d=s.content.substring(7).trim();for(let m=t.peekChild(s.indent);m!==void 0;m=t.peekChild(s.indent))t.reader.takeSignificant(),d+=` ${m.content}`;let f=Jl(t,d,p(s));a?t.error(l.RepeatedPolicyRequirement,`Policy '${n}' has more than one require line; combine the conditions with and/or in one require`,p(s)):i=f,a=!0}else if(R(s.content)==="file"){let d=Me(t,s);r===null&&o===null?o=d:t.error(l.UnknownPolicyDirective,`Policy '${n}' must have only one implementation - a file reference or an inline code block, not both`,p(s))}else if(s.content.startsWith("```")||t.languages.has(s.content)){let d=me(t,s);r===null&&o===null?r=d:t.error(l.UnknownPolicyDirective,`Policy '${n}' must have only one implementation - a file reference or an inline code block, not both`,p(s))}else t.error(l.UnknownPolicyDirective,`Unexpected '${s.content}' in policy body - expected 'require ...', 'file <path>' or an inline code block`,p(s)),t.skipOpaqueBlock(s.indent);return i!==null&&(r!==null||o!==null)&&t.error(l.MixedPolicyImplementation,`Policy '${n}' cannot combine 'require' with a file or inline code block`,p(e)),i===null&&r===null&&o===null&&t.error(l.PolicyWithoutRequirement,`Policy '${n}' must declare a 'require' condition, a file reference or an inline code block`,p(e)),{kind:"PolicySyntax",name:n,condition:i,code:r,file:o,location:p(e)}}c(So,"parsePolicy");function Jl(t,e,n){let i=t.sourceOptions.numericMode==="exact"?"-?[0-9]+(?:\\.[0-9]+)?(?:[eE][+-]?[0-9]+)?(?=$|[\\s()])|[\\w.$-]+|[^\\s]":"[\\w.$]+",r=[...e.match(new RegExp(_(`"${z}"|\\(|\\)|${i}`).source,"gu"))??[]],o=0,a=c(h=>h!==void 0&&h.startsWith('"')&&h.endsWith('"'),"quoted"),s=c(h=>Q(h.substring(1,h.length-1)),"unquote"),d=c(()=>{if(r[o]==="("){o++;let x=m();return r[o]===")"?o++:t.sourceOptions.numericMode==="exact"&&t.error(l.UnclosedPolicyConditionGroup,"Expected ')' in policy condition",n),x}let h=r[o++];if(h==="authenticated")return{kind:"AuthenticatedConditionSyntax",location:n};if(h!=="role"&&h!=="claim")return t.error(h===void 0?l.ExpectedPolicyCondition:l.UnexpectedTokenInPolicyCondition,h===void 0?"Expected a policy condition":`Unexpected '${h}' in policy condition`,n),null;let g=r[o++];if(!a(g))return t.error(h==="role"?l.ExpectedRoleName:l.ExpectedClaimName,`Expected a quoted ${h} name after '${h}'`,n),null;if(h==="role")return{kind:"RoleConditionSyntax",role:s(g),location:n};if(r[o++]!=="matches")return t.error(l.ExpectedClaimMatches,"Expected 'matches' after the claim name",n),null;let b=r[o++];return b===void 0?(t.error(l.ExpectedClaimMatchTarget,"Expected 'subject' or a value after 'matches'",n),null):{kind:"ClaimConditionSyntax",claim:s(g),matchesSubject:b==="subject",matches:b==="subject"?null:ue(b,n,t),location:n}},"group"),f=c(()=>{let h=d();for(;h!==null&&r[o]==="and";){o++;let g=d();if(g===null)return null;h={kind:"LogicalPolicyConditionSyntax",left:h,operator:"And",right:g,location:n}}return h},"and"),m=c(()=>{let h=f();for(;h!==null&&r[o]==="or";){o++;let g=f();if(g===null)return null;h={kind:"LogicalPolicyConditionSyntax",left:h,operator:"Or",right:g,location:n}}return h},"or"),u=m();return t.sourceOptions.numericMode==="exact"&&u!==null&&o<r.length&&t.error(l.UnexpectedTokenInPolicyCondition,`Unexpected '${r[o]}' in policy condition`,n),u}c(Jl,"parsePolicyCondition");var Hl=new RegExp(`^for\\s+"(${z})"$`,"u"),Xl=_("^[A-Z]\\w*$"),ed=_("^([\\w.]+)\\s*=(?!=|>)\\s*(.+)$");function ho(t,e){let n=[];if(t=t.valueContext,e.content!=="seed")return t.error(l.InvalidSeedDeclaration,`Invalid seed declaration '${e.content}' - expected 'seed'`,p(e)),t.skipOpaqueBlock(e.indent),{kind:"SeedSyntax",groups:n,location:p(e)};for(let i=t.peekChild(e.indent);i!==void 0;i=t.peekChild(e.indent)){t.reader.takeSignificant();let r=Hl.exec(i.content);if(r===null){t.error(l.InvalidSeedGroup,`Invalid seed group '${i.content}' - expected 'for "<event source id>"'`,p(i)),t.skipOpaqueBlock(i.indent);continue}let o=[];for(let a=t.peekChild(i.indent);a!==void 0;a=t.peekChild(i.indent)){if(t.reader.takeSignificant(),!Xl.test(a.content)){t.error(l.InvalidSeedEvent,`Invalid seed event '${a.content}' - expected an event type name`,p(a)),t.skipOpaqueBlock(a.indent);continue}let s=[];for(let d=t.peekChild(a.indent);d!==void 0;d=t.peekChild(a.indent)){t.reader.takeSignificant();let f=ed.exec(d.content);f!==null?s.push({kind:"PropertyMappingSyntax",property:f[1],source:ue(f[2],p(d),t),location:p(d)}):t.error(l.InvalidSeedPropertyAssignment,`Invalid property assignment '${d.content}' - expected '<property> = <value>'`,p(d))}o.push({kind:"SeedEventSyntax",event:a.content,properties:s,location:p(a)})}n.push({kind:"SeedGroupSyntax",eventSourceId:Q(r[1]),events:o,location:p(i)})}return{kind:"SeedSyntax",groups:n,location:p(e)}}c(ho,"parseSeed");var td=O("^domain\\s+([A-Za-z_]\\w*(?:\\.[A-Za-z_]\\w*)*)$"),vo=O("^import\\s+([\\w.]+)$"),nd=O("^concept\\s+(\\w+)\\s*:\\s*(\\w+)((?:\\s+@\\w+)*)$"),id=O("^@?[a-z_]\\w*$"),rd=O(`^([a-z_]\\w*)\\s+reason\\s+"(${z})"$`),od=O("^persona\\s+([A-Za-z_]\\w*)$"),ad=O("^policy\\s+([A-Za-z_]\\w*)$"),sd=/^[ ]*\t/,go=["Uuid","String","Int","Decimal","Bool","Date","DateTime"],$o=new Set(["policy","authentication","seed","ui","theme","trigger","layout","behavior"]),cd=new Set(["slice","feature","description","authorize","screen","dialog","form","contribute","on","uses"]);function pn(t,e,n=qe){ud(t,e);let i=n.length===1?new Ct(n[0]):void 0,r=n.length>1?new bt(n[n.length-1]):void 0,o=i??r,a=null,s=[],d=[],f=[],m=[],u=[],h=[],g=[],b=[],x=[],$=[],v=[],k=!1;for(let S=t.reader.peekSignificant();S!==void 0;S=t.reader.peekSignificant()){t.reader.takeSignificant();let y=R(S.content);if(y==="domain"){t.authoredDeclarations=!0,a=fd(t,S,a,k);continue}if(k||=xo(y,S,n),t.authoredDeclarations||=y!=="import"&&xo(y,S,n),y==="import"&&Zi(S.content))o!==void 0?o.tryParse(t,S):Qe(t,S,d);else if(y==="import"){let C=vo.exec(S.content);C===null?t.error(l.InvalidImportDeclaration,`Invalid import '${S.content}' - expected 'import <Qualified.Name>'`,p(S)):s.push({kind:"ImportSyntax",qualifiedName:C[1],location:p(S)})}else if(y==="eventsource")h.push(fr(t,S));else if(y==="system")u.push(Er(t,S));else if(y==="concept")f.push(md(t,S));else if(y==="type")m.push(or(t,S));else if(y==="module"&&!mt(n))ld(t,S,n,i);else if(y==="module")g.push(li(t,S));else if(y==="persona")b.push(Sd(t,S));else if(y==="seed")$.push(ho(t.valueContext,S));else if(y==="policy")x.push(So(t.valueContext,S));else if(y==="trigger"){let C=qr(t,S),E=/^trigger\s+([A-Za-z_]\w*)$/.exec(S.content)?.[1];E!==void 0&&v.push({name:E,data:C})}else $o.has(y)?y==="behavior"||y==="layout"?ge(t,S):t.skipOpaqueBlock(S.indent):o?.tryParse(t,S)!==!0&&dd(t,S,n)}i!==void 0?g.unshift(i.build(t.start,!0)):r!==void 0&&g.unshift(pd(n,r.build(t.start,!0),t.start));let P={kind:"ApplicationSyntax",sourceOptions:t.sourceOptions,domain:a,imports:s,concepts:f,types:m,systems:u,eventSources:h,modules:g,personas:b,policies:x,seeds:$,declaredTriggers:v,fileImports:d,location:t.start};return t.authoredDeclarations&&vr(P),P}c(pn,"parseApplication");function xo(t,e,n){return t==="import"?vo.test(e.content):t==="module"?mt(n):t==="eventsource"||t==="system"||t==="concept"||t==="type"||t==="persona"||$o.has(t)}c(xo,"declaresConstruct");function ld(t,e,n,i){let r=si.exec(e.content)?.[1]??"";if(i!==void 0&&r===n[0]){t.authoredDeclarations=!0,i.parseChildren(t,e);return}t.error(l.ModuleInPlacedFile,`This file is imported into ${Lt(n)}, so it cannot declare module '${r}' - import it at the top level of a document instead`,p(e)),t.skipBlock(e.indent)}c(ld,"parseModuleInPlacedFile");function dd(t,e,n){let i=R(e.content);if(mt(n)){let r=cd.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(l.UnknownTopLevelConstruct,`Unexpected '${i}' at the top level${r}`,p(e))}else{let r=n.length===1?ci:ai;t.error(l.UnexpectedInPlacedFile,`Unexpected '${i}' in a file imported into ${Lt(n)} - expected an application declaration or ${r}`,p(e))}t.skipBlock(e.indent)}c(dd,"reportUnexpectedTopLevel");function pd(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}}c(pd,"place");function fd(t,e,n,i){let r=td.exec(e.content);return r===null?(t.error(l.InvalidDomainDeclaration,`Invalid domain declaration '${e.content}' - expected 'domain <Qualified.Name>'`,p(e)),n):n!==null?(t.error(l.DuplicateDomain,"The document already declares a domain - a document can have at most one",p(e)),n):(i&&t.error(l.DomainNotFirst,"'domain' must be declared before any other construct",p(e)),{kind:"DomainSyntax",name:r[1],location:p(e)})}c(fd,"parseDomain");function ud(t,e){let n=!1;for(let i of e){if(i.raw.trimStart().startsWith("```")){n=!n;continue}!n&&sd.test(i.raw)&&t.warning(l.TabIndentation,"Screenplay is indentation based - use spaces, not tabs",zi(i))}}c(ud,"warnOnTabIndentation");function md(t,e){let n=nd.exec(e.content);if(n===null)return t.error(l.InvalidConceptDeclaration,`Invalid concept declaration '${e.content}' - expected 'concept <Name> : <Type>'`,p(e)),t.skipBlock(e.indent),{kind:"ConceptSyntax",name:R(e.content),type:"",attributes:[],values:[],location:p(e)};let[,i,r,o]=n,a=o.split(" ").filter(m=>m.length>0).map(m=>({kind:"ConceptAttributeSyntax",name:m.replace(/^@+/,""),reason:null,location:p(e)}));r!=="Enum"&&!go.includes(r)&&t.error(l.UnknownPrimitiveType,`Unknown primitive type '${r}' - expected ${go.join(", ")} or Enum`,p(e));let s=new Map;a.forEach((m,u)=>{s.has(m.name)||s.set(m.name,u)});let d=[],f=[];for(let m=t.peekChild(e.indent);m!==void 0;m=t.peekChild(e.indent)){t.reader.takeSignificant();let u=rd.exec(m.content);if(!ie(m))if(R(m.content)==="validate"){r==="Enum"&&m.content==="validate"&&t.peekChild(m.indent)===void 0&&t.warning(l.ValidateReadAsEnumerationBlock,`'validate' in enumeration concept '${i}' declares an empty validate block, not a value named 'validate' - write '@validate' for the value`,p(m));let h=Kn(t,m,"concept");h!==void 0&&f.push(h)}else u!==null?yd(t,m,i,a,s,u[1],Q(u[2])):r==="Enum"&&id.test(m.content)?d.push(G(m.content)):r==="Enum"?t.error(l.InvalidEnumerationValue,`Invalid enum value '${m.content}' - expected an identifier`,p(m)):(t.error(l.UnknownConceptDirective,`Unexpected '${m.content}' in concept body - expected validate, 'file <path>' or '<attribute> reason "<text>"'`,p(m)),t.skipBlock(m.indent))}return{kind:"ConceptSyntax",name:i,type:r,attributes:a,values:d,validations:f,location:p(e)}}c(md,"parseConcept");function yd(t,e,n,i,r,o,a){let s=r.get(o);s===void 0?t.error(l.AttributeReasonWithoutAttribute,`Concept '${n}' declares a reason for '${o}' without the attribute - write 'concept ${n} : <Type> @${o}'`,p(e)):i[s].reason!==null?t.error(l.DuplicateAttributeReason,`Concept '${n}' already declares a reason for '${o}' - at most one is allowed`,p(e)):i[s]={...i[s],reason:a}}c(yd,"applyAttributeReason");function Sd(t,e){let n=od.exec(e.content)?.[1]??"";n===""&&t.error(l.InvalidPersonaDeclaration,`Invalid persona declaration '${e.content}' - expected 'persona <Name>'`,p(e));let i=null,r=[];for(let o=t.peekChild(e.indent);o!==void 0;o=t.peekChild(e.indent)){t.reader.takeSignificant();let a=R(o.content);if(a==="description")i=Z(t,o,i,`Persona '${n}'`);else if(a==="policy"){let s=ad.exec(o.content);s===null?t.error(l.InvalidPersonaPolicyReference,`Invalid policy reference '${o.content}' - expected 'policy <Name>'`,p(o)):r.push(s[1])}else t.error(l.UnknownPersonaDirective,`Unexpected '${a}' in persona body - expected description or policy`,p(o)),t.skipBlock(o.indent)}return{kind:"PersonaSyntax",name:n,description:i,policies:r,location:p(e)}}c(Sd,"parsePersona");var it=class t{static{c(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=qe,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:s,placement:d}of e){let f=sn(s,s[0]?.path,n);f.scope=d;let m=pn(f,s,d);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(h=>h.name)])}let a=new Set([...o].filter(s=>r.has(s.substring(s.lastIndexOf(".")+1))));return new t(i,a)}};var le;(function(t){t.Unique="unique",t.Ambiguous="ambiguous",t.NotFound="notFound",t.WrongKind="wrongKind"})(le||(le={}));var rt=class{static{c(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(a=>a.streams).filter(a=>a.name===n),o;return i.length===0?o=this.otherNames.has(e)?le.WrongKind:le.NotFound:i.length>1||r.length>1?o=le.Ambiguous:o=r.length===1?le.Unique:le.NotFound,{kind:o,sources:i,streams:r}}};function ko(t,e){let n=new oe(t);if(!n.slices.flatMap(b=>b.slice.specifications).some(b=>[...b.given,...b.thenEvents,...b.whenAppended===null?[]:[b.whenAppended]].some(x=>x.stream!=null||x.noStream!=null)))return;let i=new rt(t),r=te(t.concepts),o=te(t.types),a=new Map([...o].map(([b,x])=>[b,te(x.properties)])),s=c((b,x)=>ve(b,x,r,a),"compatible"),d=new Set(["String","Uuid","Int","Decimal","Bool","Date","DateTime",...r.keys(),...o.keys()]),f=c((b,x)=>d.has(b.name)&&d.has(x.name)?b.name===x.name&&b.isCollection===x.isCollection&&(!b.isOptional||x.isOptional):null,"nominallyCompatible"),m=c((b,x)=>{if(b?.kind!=="LiteralExpressionSyntax"||!s(b,x))return null;let $=r.get(x.name)?.type??x.name,v=b.value;if($==="String"&&typeof v=="string")return v;if($==="Uuid"&&typeof v=="string"){let k=v.replace(/[{}()-]/g,"").toLowerCase();return`${k.slice(0,8)}-${k.slice(8,12)}-${k.slice(12,16)}-${k.slice(16,20)}-${k.slice(20)}`}if($==="Int"){if(typeof v=="number")return BigInt(v).toString();if(typeof v=="object"&&v!==null&&v.literalType==="ExactNumber")return gi(v)}return null},"formatStreamId"),u=c((b,x)=>{let $=b.properties,v=null,k=!1,P=!1;for(let S of x.split(".")){let y=$.filter(E=>E.name===S);if(y.length!==1)return null;let C=y[0].type;k||=C.isOptional,P||=C.isCollection,v={...C,isOptional:k,isCollection:P},$=o.get(C.name)?.properties??[]}return v},"pathType"),h=c((b,x)=>{let $=n.resolve(b,x).declaration;return $?.node.kind==="EventSyntax"?$.node:null},"eventOf"),g=[];for(let{slice:b}of n.slices){for(let x of b.commands)for(let $ of x.produces){if(!n.isEventProduction($,b))continue;let v=h($.event,b);if(v===null)continue;let k=$.for?.kind==="PathExpressionSyntax"?$.for.path:yo(x,$,{resolver:n,slice:b}),P=k==="new event source"?{kind:"TypeRefSyntax",name:"Uuid",isOptional:!1,isCollection:!1,location:$.location}:k===void 0?null:u(x,k);g.push({event:v,command:x,type:P})}for(let x of b.reactions.flatMap($=>$.triggers).flatMap($=>$.produces)){let $=h(x.event,b);$!==null&&g.push({event:$,command:null,type:null})}for(let x of b.captures)for(let $ of[...x.appends,...x.children.flatMap(v=>v.appends),...x.nested.flatMap(v=>v.appends)]){let v=h($.event,b);v!==null&&g.push({event:v,command:null,type:null})}}for(let{slice:b,scope:x}of n.slices)for(let $ of b.specifications){let v=n.slices.flatMap(y=>y.slice.commands.map(C=>({command:C,scope:y.scope}))),k=$.when===null?[]:v.filter(y=>y.command.name===$.when.commandType),P=null;for(let y=x.length;y>=0&&P===null;y--){let C=k.filter(E=>x.slice(0,y).every((A,w)=>E.scope[w]===A));if(C.length>0){P=C.length===1?C[0].command:null;break}}let S=[...$.given.map(y=>({node:y,required:!0,expected:!1})),...$.whenAppended===null?[]:[{node:$.whenAppended,required:!0,expected:!1}],...$.thenEvents.map(y=>({node:y,required:!1,expected:!0}))];for(let{node:y,required:C,expected:E}of S){if(y.stream==null&&y.noStream==null)continue;C&&y.noStream!=null&&e.error(l.InvalidSpecificationStream,"Expected 'stream Source.Stream', or 'no stream' on a then event.",y.noStream.location);let A=null,w=h(y.eventType,b),D=g.filter(M=>M.event===w);if(y.stream!=null){let M=y.stream,L=i.resolve(M.eventSource,M.stream);if(L.kind!==le.Unique){let Y={ambiguous:"Ambiguous",notFound:"NotFound",wrongKind:"WrongKind"}[L.kind];e.error(l.InvalidSpecificationStreamRoute,`Stream '${M.eventSource}.${M.stream}' is ${Y}; routing requires one physical source and stream.`,M.location);continue}let W=L.sources[0],B=L.streams[0];if(B.streamId===null!=(M.streamId===null)&&e.error(l.InvalidSpecificationStreamRoute,B.streamId===null?"An unkeyed stream cannot take a streamId mapping.":"This keyed stream requires a streamId mapping.",M.location),M.streamId!==null){let Y=M.streamId.source;(Y.kind!=="LiteralExpressionSyntax"||Y.value===null||Y.value===""||B.streamId!==null&&!s(Y,B.streamId))&&e.error(l.InvalidSpecificationStreamRoute,"A specification stream id needs a nonempty concrete scalar literal compatible with the stream's declared type.",Y.location)}if(A=W.identifier,A===null){let Y=D.map(ne=>ne.type),ae=new Set(Y.filter(ne=>ne!==null).map(ne=>`${ne.name}:${ne.isOptional}:${ne.isCollection}`));Y.length===0||Y.some(ne=>ne===null)||ae.size!==1?e.error(l.InvalidSpecificationStreamEventSource,`Declare an identifier on source '${W.name}'; the event's producers do not supply one unambiguous destination type.`,M.location):A=Y[0]}C&&y.for===null?e.error(l.InvalidSpecificationStreamEventSource,"A routed given or when append event requires 'for <literal>'.",M.location):y.for!==null&&(y.for.kind!=="LiteralExpressionSyntax"||y.for.value===null||A!==null&&(A.isCollection||A.isOptional||!s(y.for,A)))&&e.error(l.InvalidSpecificationStreamEventSource,"A routed event's for value must be a concrete literal compatible with the source's identifier type.",y.for.location)}if(!E||P===null||D.length===0||D.some(M=>M.command!==P))continue;let j=P.stream?.propertyCandidate===null?P.stream:null,q=y.noStream!=null?j!=null:j==null||j.eventSource!==y.stream.eventSource||j.stream!==y.stream.stream;if(!q&&y.stream!=null&&j!=null){let M=i.resolve(y.stream.eventSource,y.stream.stream),L=M.kind===le.Unique?M.streams[0].streamId:null;if(L!==null){let W=m(j.streamId?.source,L),B=m(y.stream.streamId?.source,L);W!==null&&B!==null&&W!==B&&(q=!0)}}y.for?.kind==="LiteralExpressionSyntax"&&D.every(M=>M.type!==null&&(A!==null?f(M.type,A)===!1:!s(y.for,M.type)))&&(q=!0),q&&e.error(l.SpecificationStreamContradictsCommand,"The expected event route contradicts its only producer, the command under test.",(y.stream??y.noStream).location)}}}c(ko,"validateSpecificationStreams");var $i=new Set(["String","Uuid","Int","Decimal","Bool","Date","DateTime"]);function fn(t,e){let n=te(t.concepts),i=te(t.types),r=new Set([...$i,...n.keys(),...i.keys()]),o=new Map([...i].map(([u,h])=>[u,te(h.properties)])),a=c((u,h)=>r.has(u.name)&&r.has(h.name)?u.name===h.name&&u.isCollection===h.isCollection&&(!u.isOptional||h.isOptional):null,"compatible"),s=c((u,h)=>{if(u===null)return;if(u.isOptional||u.isCollection||t.types.some(x=>x.name===u.name)){e.error(l.InvalidEventSourceDeclaration,"Identifier and streamId declarations require a nonoptional scalar value type.",u.location);return}let g=t.concepts.filter(x=>x.name===u.name),b=g.length===1?g[0].type:g.length===0&&$i.has(u.name)?u.name:null;h&&b!==null&&(!["String","Uuid","Int"].includes(b)||b==="Int"&&g.length===0||g.some(x=>x.values.length>0))&&e.error(l.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),b===null&&!t.imports.some(x=>x.qualifiedName===u.name||x.qualifiedName.split(".").at(-1)===u.name)&&e.warning(l.UnknownType,`Unknown type '${u.name}' in event source declaration.`,u.location)},"validateType"),d=new Set;for(let u of t.eventSources??[]){d.has(u.name)&&e.error(l.InvalidEventSourceDeclaration,`Event source '${u.name}' has multiple physical declarations.`,u.location),d.add(u.name),s(u.identifier,!1);let h=new Set;for(let g of u.streams)h.has(g.name)&&e.error(l.InvalidEventSourceDeclaration,`Stream '${u.name}.${g.name}' has multiple declarations under this source.`,g.location),h.add(g.name),s(g.streamId,!0)}let f=c((u,h)=>{let[g,...b]=h.split(".");if(u===null)return{property:null,missing:!1};let x=u.filter(k=>k.name===g);if(x.length!==1)return{property:null,missing:x.length===0};let $=x[0];if(b.length===0)return{property:$,missing:!1};if($i.has($.type.name)||n.has($.type.name)&&!i.has($.type.name))return{property:null,missing:!0};let v=f(i.get($.type.name)?.properties??null,b.join("."));return v.property===null?v:{property:{...v.property,type:{...v.property.type,isCollection:$.type.isCollection||v.property.type.isCollection,isOptional:$.type.isOptional||v.property.type.isOptional}},missing:!1}},"pathProperty"),m=new rt(t);for(let{slice:u}of new oe(t).slices)for(let h of u.commands){let g=h.stream;if(g==null||g.propertyCandidate!==null)continue;let b=m.resolve(g.eventSource,g.stream);if(b.kind!==le.Unique){let P={ambiguous:"Ambiguous",notFound:"NotFound",wrongKind:"WrongKind"}[b.kind];e.error(l.InvalidCommandStream,`Stream '${g.eventSource}.${g.stream}' is ${P}; routing requires one physical source and stream.`,g.location);continue}let x=b.sources[0],$=b.streams[0],v=h.properties.filter(P=>P.isIdentifier);if(x.identifier!==null&&v.length===1&&a(v[0].type,x.identifier)===!1&&e.warning(l.InvalidCommandStream,`Command identifier '${v[0].name}' does not have the source's nominal identifier type '${x.identifier.name}'. The stream does not supply a destination.`,v[0].location),($.streamId===null&&g.streamId!==null||$.streamId!==null&&g.streamId===null)&&e.error(l.InvalidCommandStream,$.streamId===null?"An unkeyed stream cannot take a streamId mapping.":"This keyed stream requires a streamId mapping.",g.location),$.streamId===null||g.streamId===null)continue;let k=g.streamId.source;if(k.kind==="PathExpressionSyntax"){let P=f(h.properties,k.path);(P.missing||P.property!==null&&a(P.property.type,$.streamId)===!1)&&e.error(l.InvalidCommandStream,`Stream id source '${k.path}' is absent or incompatible with nominal type '${$.streamId.name}'.`,k.location)}else k.kind==="LiteralExpressionSyntax"&&!ve(k,$.streamId,n,o)?e.error(l.InvalidCommandStream,`Stream id value is incompatible with nominal type '${$.streamId.name}'.`,k.location):(["RawExpressionSyntax","ObjectExpressionSyntax","ListExpressionSyntax"].includes(k.kind)||k.kind==="LiteralExpressionSyntax"&&k.value===null)&&e.error(l.InvalidCommandStream,"A stream id needs a scalar value source, not a raw expression, collection or absence.",k.location)}ko(t,e)}c(fn,"validateEventSources");function un(t,e){let n=new oe(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))]),a=te(t.types),s=new Set(["Uuid","String","Int","Decimal","Bool","Date","DateTime",...t.concepts.map(x=>x.name)].filter(x=>!a.has(x))),d=c((x,$)=>{let[v,...k]=$.split(".");if(x===null)return{value:null,missing:!1};let P=x.filter(y=>y.name===v);if(P.length!==1)return{value:null,missing:P.length===0};let S=P[0];return k.length===0?{value:S,missing:!1}:s.has(S.type.name)?{value:null,missing:!0}:d(a.get(S.type.name)?.properties??null,k.join("."))},"property"),f=i.flatMap(({slice:x,scope:$})=>x.readModels.map(v=>({node:v,scope:$}))),m=c((x,$)=>{let v=c(S=>{let y=S.split("."),C=f.filter(A=>A.node.name===y.at(-1)),E=y.slice(0,-1);if(E.length>0)return C.filter(A=>E.length<=A.scope.length&&E.every((w,D)=>A.scope[A.scope.length-E.length+D]===w));for(let A=$.length;A>=0;A--){let w=C.filter(D=>A<=D.scope.length&&$.slice(0,A).every((j,q)=>D.scope[q]===j));if(w.length>0)return w}return[]},"candidates"),k=v(x),P=t.imports.filter(S=>S.qualifiedName.split(".").at(-1)===x);return k.length===0&&P.length===1&&(k=v(P[0].qualifiedName)),k.length===1?k[0].node.properties:null},"viewProperties"),u=c((x,$,v)=>{let k=n.resolve(x,v);o.has(x)||r.has(x)||k.declaration?.kind===J.Event||k.candidates.some(S=>S.kind===J.Event)||e.warning(l.UnknownEvent,`Unknown event '${x}' - declare it with 'event ${x}'`,$)},"unknownEvent"),h=c((x,$)=>{for(let v of x)(v.kind==="RemoveWithSyntax"||v.kind==="RemoveViaJoinSyntax")&&u(v.event,v.location,$),"blocks"in v&&h(v.blocks,$)},"removals"),g=new Set,b=c((x,$,v=!1,k=!1)=>{let P=c((y,C)=>{let E=d($,y),A=JSON.stringify([C.path,C.line,C.column]);return E.missing&&!g.has(A)&&(g.add(A),e.warning(l.UnknownReadModelProperty,`Projection target '${y}' is not a declared ${v?"element":"read-model"} property`,C)),E.value},"validate"),S=k||x.some(y=>y.kind==="FromSyntax"||y.kind==="JoinSyntax"||y.kind==="AllSyntax");for(let y of x){let C=y.kind==="EverySyntax"&&!S?[]:"mappings"in y?y.mappings:y.kind==="JoinSyntax"?y.events.flatMap(E=>E.mappings):[];for(let E of C)P(E.property,E.location);if(y.kind==="ChildrenSyntax"||y.kind==="NestedSyntax"){let E=P(y.property,y.location);b(y.blocks,E===null?null:a.get(E.type.name)?.properties??null,!0)}}},"walk");for(let{slice:x}of i){for(let $ of x.projections)h($.blocks,x);for(let $ of x.captures)for(let v of[...$.appends,...$.children.flatMap(k=>k.appends),...$.nested.flatMap(k=>k.appends)])u(v.event,v.location,x)}for(let{slice:x,scope:$}of i)for(let v of x.projections){let k=v.blocks.filter(P=>P.kind==="ProjectionVariantSyntax");k.length===0&&b(v.blocks,m(v.readModel??v.name,$));for(let P of k){let S=m(P.name,$);b(v.blocks.filter(C=>C.kind==="ChildrenSyntax"||C.kind==="NestedSyntax"),S);let y=P.entersOn.length>0||v.blocks.some(C=>C.kind==="FromSyntax"||C.kind==="JoinSyntax"||C.kind==="AllSyntax");b(P.blocks,S,!1,y)}}}c(un,"validateProjectionTargets");function mn(t,e){let n=new Set(t.concepts.filter(d=>d.attributes.some(f=>f.name==="pii")).map(d=>d.name)),i=te(t.types),r=new oe(t),o=new Map;for(let d of t.declaredTriggers??[]){let f=o.get(d.name)??[];f.push(d.data),o.set(d.name,f)}let a=c((d,f)=>{n.has(d.name)&&e.error(l.PiiNotSupportedOnIdentifier,`Concept '${d.name}' is @pii and cannot be an event source identifier - use a surrogate Uuid identifier and keep the @pii value as a property`,f)},"validate"),s=c((d,f)=>{let[m,...u]=f.split("."),h=d.filter(b=>b.name===m);if(h.length!==1)return null;let g=h[0];return u.length===0?g:s(i.get(g.type.name)?.properties??[],u.join("."))},"property");for(let d of t.eventSources??[])d.identifier!=null&&a(d.identifier,d.identifier.location);for(let{slice:d}of r.slices){for(let f of d.commands){for(let m of f.properties.filter(u=>u.isIdentifier))a(m.type,m.location);for(let m of f.produces.filter(u=>r.isEventProduction(u,d))){if(m.for?.kind!=="PathExpressionSyntax")continue;let u=s(f.properties,m.for.path);u!==null&&!u.isIdentifier&&a(u.type,m.for.location)}}for(let f of d.reactions.flatMap(m=>m.triggers)){if(f.source.kind!=="NamedTriggerSourceSyntax")continue;let u=r.resolve(f.source.name,d).declaration?.node,h=[u?.kind==="EventSyntax"?u.properties:[],...o.get(f.source.name)??[]];for(let g of f.produces.filter(b=>r.isEventProduction(b,d))){if(g.for?.kind!=="PathExpressionSyntax")continue;let b=g.for.path,x=h.map($=>s($,b)).find($=>$!==null&&n.has($.type.name));x!=null&&a(x.type,g.for.location)}}}}c(mn,"validateIdentifierCompliance");function ki(t){let e=Et(t),n=c((m,u)=>m.map(h=>({syntax:h,rank:e.get(Xe([...u,h.name]))??Number.MAX_SAFE_INTEGER})).sort((h,g)=>h.rank-g.rank).map(h=>h.syntax),"ordered"),i=[],r=c((m,u)=>{let h=[...u,m.name];for(let g of n(m.slices,h))i.push({syntax:g,scope:[...h,g.name],identity:[...h.map(b=>`container:${b}`),`slice:${g.name}`],index:i.length});for(let g of n(m.features,h))r(g,h)},"feature");for(let m of n(t.modules,[]))for(let u of n(m.features,[m.name]))r(u,[m.name]);let o=new Map;for(let m of i)for(let u of Se(m.syntax))o.has(u.name.toLowerCase())||o.set(u.name.toLowerCase(),m);let a=[];for(let m of i){let u=new Set,h=nn(m.syntax).references.filter(g=>g.timeline).map(g=>({event:g.name,location:g.location}));for(let g of h){let b=g.event.toLowerCase();if(u.has(b))continue;u.add(b);let x=o.get(b);if(x===void 0||x===m)continue;let $=0;for(;$<m.scope.length&&$<x.scope.length&&m.identity[$]===x.identity[$];)$++;$===m.scope.length||$===x.scope.length||a.push({...g,consumer:m,producer:x,container:Xe(m.identity.slice(0,$)),left:m.identity[$],right:x.identity[$]})}}let s=c((m,u)=>m.consumer.index-u.consumer.index||m.location.line-u.location.line||m.location.column-u.location.column,"compare"),d=new Set,f=[];for(let m of new Set(a.map(u=>u.container))){let u=a.filter(g=>g.container===m),h=new Map;for(let g of u)h.has(g.left)||h.set(g.left,new Set),h.has(g.right)||h.set(g.right,new Set),h.get(g.left).add(g.right);for(let g of Pt(h).filter(b=>b.length>1)){let b=new Set(g),x=u.filter(k=>b.has(k.left)&&b.has(k.right));x.forEach(k=>d.add(k));let $=x.filter(k=>k.consumer.index<k.producer.index).sort(s)[0];if($===void 0)continue;let v=c(k=>Math.min(...x.flatMap(P=>[P.consumer,P.producer]).filter(P=>{let S=JSON.parse(m);return P.identity[S.length]===k}).map(P=>P.index)),"memberIndex");g.sort((k,P)=>v(k)-v(P)),f.push({edge:$,diagnostic:{severity:"information",code:l.TimelineCycleGroup,message:`Timeline group ${g.map(k=>`'${k.slice(k.indexOf(":")+1)}'`).join(", ")} uses each other's events; reordering these members cannot make every event flow left to right.`,location:$.location}})}}for(let m of a){if(m.consumer.index>=m.producer.index||d.has(m))continue;let u=m.consumer.scope.slice(0,-1),g=m.producer.scope.length>m.consumer.scope.length&&u.every((b,x)=>m.producer.scope[x]===b)?" The producer is in the consumer's own sub-feature; this cannot be fixed by reordering.":" Consider drawing the producer before the consumer.";f.push({edge:m,diagnostic:{severity:"information",code:l.EventFromLaterSlice,message:`Slice '${m.consumer.syntax.name}' uses event '${m.event}' produced by slice '${m.producer.syntax.name}' drawn after it.${g}`,location:m.location}})}return f.sort((m,u)=>s(m.edge,u.edge)).map(m=>m.diagnostic)}c(ki,"timelineOrderDiagnostics");function Ye(t,e,n=qe,i=!0,r,o){let a=Ue(t,!1,e),s=sn(a,e,o);s.scope=n,s.streamCandidates=r??it.capture([a],n,o);let d=pn(s,a,n);if(i){ln(d,s),dn(d,s),an(d,s),fn(d,s),un(d,s),mn(d,s),d=Nt(d,s),nt.validate(d,s);for(let f of ki(d))s.information(f.code,f.message,f.location)}return{value:d,diagnostics:s.diagnostics,triggerData:s.triggerData,inputUses:s.inputUses,success:!s.diagnostics.some(f=>f.severity==="error")}}c(Ye,"parseForAuthoring");function k$(t){return t===l.LegacyOptionalSuffix||t===l.RedundantEventId}c(k$,"isQuickFixDiagnostic");function bi(t,e){return e.code!==l.LegacyOptionalSuffix?0:/^[\p{L}\p{Mn}\p{Nd}\p{Pc}.]+(?:\[\])?\?/u.exec(t.slice(e.location.column-1))?.[0].length??0}c(bi,"legacyOptionalTypeLength");function b$(t,e={}){let n=Ye(t,void 0,e.placement);if(!n.success)return()=>[];let i=Ue(t),r=new Map;new class extends et{visitEvent(v){r.set(v.location.line,v)}}().visitApplication(n.value);let a=new Map,s=new Map,d=new Map,f;for(let v of i)f=r.get(v.number)??f,f!==void 0&&d.set(v.number,f);for(let v of n.diagnostics){a.set(v.code,(a.get(v.code)??0)+1);let k=i[v.location.line-1],P=bi(k.raw,v);if(P>0)s.set(k.number,{line:k.number,fix:{diagnosticCode:v.code,title:"Use 'optional' instead of '?'",scope:"occurrence",edits:[{start:k.startOffset+v.location.column+P-2,length:1,text:" optional"}]}});else if(v.code===l.RedundantEventId&&ft(k.raw)<0){let S=d.get(k.number);if(S?.id!==S?.name||S===void 0)continue;s.set(k.number,{line:k.number,fix:{diagnosticCode:v.code,title:"Remove the redundant event id",scope:"occurrence",edits:[{start:k.startOffset,length:(i[k.number]?.startOffset??t.length)-k.startOffset,text:""}]},change:{node:S,replacement:{...S,id:null}}})}}let m=[...s.values()].filter(v=>v.fix.diagnosticCode===l.LegacyOptionalSuffix),u=At(n),h=new Map,g,b=!1,x,$=c((v,k)=>{let P=bo(t,v.edits);if(P===void 0)return;let S=Ye(P,void 0,e.placement);if(!(!S.success||At(S)!==(k===void 0?u:At(n,[k]))))return S.diagnostics.filter(y=>y.code===v.diagnosticCode).length===(a.get(v.diagnosticCode)??0)-v.edits.length?v:void 0},"verify");return(v,k)=>{let P=typeof v=="number"||v===void 0?void 0:v,S=P===void 0?k===void 0||k===l.LegacyOptionalSuffix:P.some(A=>A.diagnosticCode===l.LegacyOptionalSuffix);if(S&&!b&&(m.length>0&&(x=$({diagnosticCode:l.LegacyOptionalSuffix,title:"Use 'optional' throughout this document",scope:"document",edits:m.flatMap(A=>A.fix.edits)})),b=!0),P!==void 0){if(g===void 0){g=new Map;let w=i.flatMap(q=>s.has(q.number)?[s.get(q.number)]:[]),D=w.flatMap(q=>q.fix.edits),j=bo(t,D);if(D.length>0&&j!==void 0){let q=Ye(j,void 0,e.placement),M=w.flatMap(L=>L.change===void 0?[]:[L.change]);if(q.success&&At(q)===At(n,M)){let L=new Map,W=new Map;for(let B of q.diagnostics)L.set(B.code,(L.get(B.code)??0)+1);for(let B of w)W.set(B.fix.diagnosticCode,(W.get(B.fix.diagnosticCode)??0)+B.fix.edits.length);if([...W].every(([B,Y])=>(L.get(B)??0)===(a.get(B)??0)-Y))for(let B of w)g.set(B.line,B.fix)}}}let A=new Map;for(let w of P){let D=g.get(w.line);D?.diagnosticCode===w.diagnosticCode&&A.set(w.line,D)}return[...A.values(),...S&&x!==void 0?[x]:[]]}let y=typeof v=="number"?v:void 0,C=y===void 0?void 0:s.get(y),E;return C!==void 0&&y!==void 0&&(k===void 0||C.fix.diagnosticCode===k)&&(h.has(y)||(h.size===32&&h.delete(h.keys().next().value),h.set(y,$(C.fix,C.change))),E=h.get(y)),[E,S?x:void 0].filter(A=>A!==void 0)}}c(b$,"prepareQuickFixes");function At(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)}c(At,"verificationShape");function bo(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("")}c(bo,"applyQuickFixEdits");var ot=class{static{c(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(f=>f.source.streams).filter(f=>f.name===n),o=i.length>1||r.length>1,a=!this.complete||i.some(f=>!f.placementResolved),s=o?"ambiguous":a?"incomplete":i.length===1&&(n===void 0||r.length===1)?"unique":"notFound",d=[];return i.length>1&&d.push("Multiple physical parent sources claim the exact name."),r.length>1&&d.push("Multiple physical streams claim the exact parent and local name."),i.some(f=>!f.placementResolved)&&d.push("A physical parent has unresolved import placement."),this.complete||d.push("Physical source extent or placement is incomplete; missing declarations cannot be excluded."),{state:s,sources:i.map(f=>f.source),streams:r,reasons:d}}};var hd=se("^[A-Za-z_]\\w*$"),we=c((t,e)=>typeof t=="object"&&t!==null&&!Array.isArray(t)&&t.kind===e,"hasKind"),K=c(t=>{throw new X(t)},"refuse"),at=c((t,e,n)=>{if(!Array.isArray(t))return K(n);for(let i=0;i<t.length;i++)we(t[i],e)||K(n)},"collection");function st(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&&(we(e.implementation,"ImplementationSyntax")||K("A named rule requires an ImplementationSyntax wrapper."),(e.rule!=="Rule"||e.value?.kind!=="PathExpressionSyntax"||!we(e.value,"PathExpressionSyntax")||typeof e.value.path!="string"||hd.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&&(!we(e.file,"FileReferenceSyntax")||typeof e.file.path!="string")&&K("A named rule file requires a FileReferenceSyntax payload with a string path."),e.code!=null&&(!we(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."),st(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."),at(n.inputs,"PropertySyntax","Operation inputs must be a collection of properties."),at(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&&st(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;at(e.hints,"ImplementationHintSyntax","Implementation hints must be a collection of nonblank hints.");for(let n=0;n<e.hints.length;n++)st(e.hints[n])}if(t.kind==="ImplementationHintSyntax"){let e=t;(typeof e.text!="string"||zt(e.text))&&K("An implementation hint must be nonblank.")}Co(t)}c(st,"validateSyntaxInvariants");function Co(t){let e=c(n=>{Wn(n)||K("Event source and stream names must be identifiers.")},"name");if(t.kind==="ApplicationSyntax"){let n=t.eventSources;n!==void 0&&at(n,"EventSourceSyntax","Event sources must be a collection of event source nodes without null elements.")}if(t.kind==="EventSourceSyntax"||t.kind==="EventStreamSyntax"){let n=t;e(n.name),n.id!==null&&(typeof n.id!="string"||n.id.trim()==="")&&K("A rename pin must be nonempty.");let i=n.kind==="EventSourceSyntax"?n.identifier:n.streamId;i!==null&&!we(i,"TypeRefSyntax")&&K("Source identifiers and stream ids require type reference nodes."),i!==null&&(i.isCollection||i.isOptional)&&K("Source identifiers and stream ids require nonoptional scalar type references."),i!==null&&!Un(i.name)&&K("Source identifiers and stream ids require an exact type reference name."),n.kind==="EventSourceSyntax"&&at(n.streams,"EventStreamSyntax","Event streams must contain event stream nodes without null elements.")}if(t.kind==="CommandSyntax"){let n=t;n.stream?.propertyCandidate!=null&&K("The authoritative command stream cannot contain an ambiguous property candidate."),n.stream!=null&&!we(n.stream,"CommandStreamSyntax")&&K("The authoritative command stream must be a command stream node."),n.streamCandidates!==void 0&&at(n.streamCandidates,"CommandStreamSyntax","Command stream candidates must be a collection without null elements.");let i=n.streamCandidates??[];for(let r=0;r<i.length;r++){let o=i[r];if(Co(o),o.propertyCandidate===null&&n.stream==null&&K("A duplicate route candidate requires an authoritative route."),o.propertyCandidate!==null)for(let a=0;a<n.properties.length;a++)n.properties[a]===o.propertyCandidate&&K("An ambiguous property is owned only by its stream candidate.")}}if(t.kind==="SpecificationEventSyntax"){let n=t;n.stream!=null&&n.noStream!=null&&K("An event occurrence cannot declare both stream and no stream."),n.stream!=null&&!we(n.stream,"SpecificationStreamSyntax")&&K("A specification stream requires a specification stream node."),n.noStream!=null&&!we(n.noStream,"SpecificationNoStreamSyntax")&&K("An unrouted expectation requires a specification no stream node.")}if(t.kind==="SpecificationStreamSyntax"){let n=t;e(n.eventSource),e(n.stream),n.streamId!==null&&n.streamId.property!=="streamId"&&K("A specification stream maps only streamId.")}if(t.kind==="CommandStreamSyntax"){let n=t;e(n.eventSource),e(n.stream),n.streamId!==null&&n.streamId.property!=="streamId"&&K("A command stream maps only streamId.");let i=n.propertyCandidate;i!==null&&(i.name!=="stream"||i.type.name!==`${n.eventSource}.${n.stream}`||i.type.isCollection||i.type.isOptional||i.isGenerated||i.isIdentifier||n.streamId!==null)&&K("An ambiguous route must retain its exact unmodified property candidate, without selecting nested routing.")}}c(Co,"validateSourceStream");var Ie={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","EventStreamSyntax","EventSpecSyntax","EventSyntax","EverySyntax","ExecuteCommandActionSyntax","ExpressionKeySyntax","FeatureSyntax","FileConstraintSyntax","FileImportSyntax","FileReferenceSyntax","FormFieldSyntax","FormPopulateFromItemSyntax","FormPopulateViaQuerySyntax","FormSyntax","FromSyntax","HandlerSyntax","ImplementationSyntax","ImplementationHintSyntax","SystemSyntax","OperationSyntax","OperationPhaseSyntax","SpecificationOperationFailureSyntax","SpecificationOperationSyntax","SpecificationCompensatedSyntax","ImportSyntax","IncrementMappingSyntax","InteractionArgumentSyntax","InteractionBindingSyntax","IntervalInteractionTriggerSyntax","IntervalTriggerSourceSyntax","InvokesSyntax","JoinEventSyntax","JoinSyntax","KeyPartSyntax","LayoutSyntax","ListExpressionSyntax","LiteralExpressionSyntax","LogicalConditionSyntax","LogicalPolicyConditionSyntax","LogicalPolicyRequirementSyntax","ModuleSyntax","NamedTriggerSourceSyntax","NavigateActionSyntax","NavigateBackActionSyntax","NestedSyntax","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","ReadModelSyntax","ReadsSyntax","ReducerRuleSyntax","ReducerSyntax","RefreshQueryActionSyntax","RemoveViaJoinSyntax","RemoveWithSyntax","RequirementSyntax","RoleConditionSyntax","ScheduleTriggerSourceSyntax","ScreenActionSyntax","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","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","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","handler","produces","reads","response","stream","streamCandidates","validations","eventSource","propertyCandidate","streamId","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","documentation","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","operation","qualifiedName","binding","actions","condition","trigger","amount","unit","on","items","literalType","dialogTemplates","forms","screenTemplates","screen","level","dialogTemplate","members","hidden","sizeHeight","sizeWidth","slotName","x","y","inlineEvent","inlineOperation","readModel","sequence","entersOn","isGenerated","isIdentifier","filters","isObservable","performer","returnType","scope","where","data","invokes","severity","role","dayOfMonth","dayOfWeek","time","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","generatedValues","eventType","noStream","exactly","results","given","givenCaller","givenCaptures","givenClock","givenOperationFailures","givenReadModels","thenAbsentReadModels","thenCompensated","thenDenied","thenErrors","thenEvents","thenEventsInAnyOrder","thenNoResult","thenOperations","thenQueries","thenReadModels","thenResults","thenReturns","whenAppended","whenCapture","whenClock","whenQuery","whenTrigger","compatibleWith","isCollection","isOptional","defaultSizeClass","layout","packages","platforms","theme","additionalProperties","rule","places"],rules:[["string"],["ref",26,42,49,50,52,89,90,101,103,124,160,179,182],["object",[[0,0,!0],[1,1,!0]]],["enum","Inherit","Disabled","Enabled"],["ref",0,29,44,46,79,156,180],["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",62],["array",18],["ref",78],["array",20],["ref",88],["array",22],["union",23,8],["ref",94],["array",25],["ref",105],["array",27],["union",28,8],["ref",108],["array",30],["ref",155],["array",32],["union",33,8],["enum","legacy","exact"],["object",[[17,35,!0]]],["ref",72],["array",37],["ref",185],["array",39],["union",40,8],["ref",187],["array",42],["union",43,8],["ref",189],["array",45],["union",46,8],["ref",190],["array",48],["union",49,8],["object",[[4,9,!1],[5,11,!1],[6,13,!1],[7,15,!1],[8,17,!1],[9,19,!1],[10,21,!1],[11,24,!1],[12,26,!1],[13,29,!1],[14,31,!1],[15,34,!1],[16,36,!1],[18,38,!1],[19,41,!1],[20,44,!1],[21,47,!1],[22,50,!1]]],["object",[[23,0,!0]]],["ref",4,6],["array",53],["integer",-2147483648,2147483647],["union",55,8],["enum","Flat","Row","Column","Grid"],["object",[[24,54,!1],[25,56,!1],[26,57,!0]]],["union",0,8],["object",[[27,59,!1],[28,53,!0],[29,59,!1]]],["boolean"],["object",[[30,61,!1],[27,56,!1],[31,0,!0],[32,56,!1],[29,56,!1]]],["enum","Flow","Freeform"],["ref",5],["array",64],["union",65,8],["union",53,8],["ref",196],["array",68],["union",69,8],["object",[[33,63,!0],[34,66,!1],[28,67,!1],[35,70,!1]]],["object",[]],["object",[[36,59,!1],[31,0,!0]]],["ref",9],["array",74],["object",[[37,75,!1]]],["ref",93,107],["object",[[38,77,!0]]],["object",[[31,0,!0],[1,0,!0]]],["ref",188],["union",80,8],["object",[[31,0,!0],[39,81,!1]]],["ref",81],["array",83],["ref",63],["union",85,8],["ref",13],["array",87],["object",[[40,84,!1],[41,59,!1],[42,86,!1],[31,59,!1],[43,56,!1],[44,88,!1]]],["enum","Click","DoubleClick","Select","Submit","Change","Load","Unload","Enter","Leave","Unknown"],["object",[[26,90,!0]]],["ref",113],["array",92],["ref",181],["array",94],["union",95,8],["ref",25],["union",97,8],["object",[[45,0,!0],[3,93,!1],[46,96,!1],[47,98,!1]]],["ref",16],["array",100],["ref",18,22],["array",102],["object",[[48,101,!1],[49,0,!0],[50,103,!1],[0,0,!0]]],["ref",24],["array",105],["object",[[0,0,!0],[51,1,!0],[52,106,!1]]],["object",[[48,101,!1],[50,103,!1],[0,0,!0]]],["ref",20],["array",109],["object",[[53,110,!1],[26,0,!0]]],["array",0],["object",[[54,0,!0],[51,1,!0],[55,112,!1]]],["ref",17],["array",114],["ref",19],["array",116],["ref",21],["union",118,8],["object",[[48,101,!1],[24,115,!1],[56,59,!1],[50,103,!1],[31,0,!0],[57,117,!1],[51,119,!1],[16,36,!1]]],["object",[[58,0,!0],[59,0,!0]]],["enum","PropertyChanged","Added","Removed","Changed","LogicalOr","LogicalAnd","ValueTransition","Expression"],["object",[[60,59,!1],[61,59,!1],[62,112,!1],[26,122,!0],[63,59,!1]]],["object",[[0,59,!1]]],["ref",1,27,30,57,68,86,98,112,132,133],["array",125],["object",[[2,3,!0],[64,126,!1],[49,1,!0],[0,0,!0]]],["union",1,8],["object",[[65,0,!0],[66,128,!1],[67,61,!0]]],["object",[[0,0,!0]]],["object",[[45,0,!0]]],["ref",80],["array",132],["ref",31,41,58,96,97,99,100,123,131,157],["array",134],["object",[[68,133,!1],[69,135,!1],[70,135,!1],[71,135,!1]]],["object",[[72,0,!0],[73,0,!0]]],["ref",32],["object",[[72,138,!0]]],["ref",11],["union",140,8],["ref",40],["union",142,8],["ref",69],["union",144,8],["ref",109],["array",146],["ref",114],["array",148],["ref",128],["array",150],["union",151,8],["ref",117,118],["union",153,8],["ref",35],["union",155,8],["array",155],["ref",33,45],["array",158],["object",[[74,141,!1],[75,143,!1],[41,59,!1],[76,145,!1],[31,0,!0],[77,147,!1],[62,149,!1],[78,152,!1],[79,154,!1],[80,156,!1],[81,157,!1],[82,159,!1]]],["union",148,8],["union",92,8],["object",[[83,0,!0],[84,161,!1],[80,0,!0],[85,162,!1]]],["enum","Equal","NotEqual","GreaterThan","GreaterThanOrEqual","LessThan","LessThanOrEqual","Contains","StartsWith"],["object",[[86,0,!0],[87,164,!0],[88,1,!0]]],["ref",87],["array",166],["object",[[89,167,!1],[39,0,!0]]],["object",[[31,0,!0],[90,59,!1]]],["ref",38],["array",170],["union",159,8],["object",[[91,171,!1],[42,86,!1],[31,0,!0],[39,0,!0],[82,172,!1],[92,112,!1]]],["object",[[83,61,!0],[93,59,!1],[94,59,!1],[95,59,!1],[96,112,!1]]],["object",[[68,133,!1],[97,0,!0],[98,61,!0],[69,135,!1],[70,135,!1],[71,135,!1]]],["object",[[99,0,!0]]],["ref",143],["union",177,8],["object",[[100,0,!0],[101,59,!1],[102,178,!1],[43,56,!1]]],["ref",134],["array",180],["union",181,8],["ref",195],["array",183],["object",[[103,182,!1],[104,184,!1]]],["ref",7],["union",186,8],["ref",159],["array",188],["ref",194],["array",190],["object",[[105,187,!1],[5,11,!1],[31,0,!0],[106,189,!1],[107,191,!1]]],["object",[[31,0,!0]]],["object",[[108,0,!0]]],["ref",54],["array",195],["object",[[41,59,!1],[109,59,!1],[110,81,!1],[31,0,!0],[111,196,!1]]],["object",[[41,59,!1],[109,59,!1],[31,0,!0],[85,81,!1]]],["object",[[45,0,!0],[56,128,!1]]],["integer",0,4294967295],["object",[[41,59,!1],[112,59,!1],[42,86,!1],[113,200,!1],[114,61,!1],[109,59,!1],[31,0,!0],[62,149,!1],[46,96,!1]]],["object",[[2,3,!0],[115,61,!0],[3,5,!1]]],["object",[[68,133,!1],[116,0,!0],[69,135,!1],[70,135,!1],[71,135,!1]]],["object",[[60,1,!0]]],["ref",43],["array",205],["union",206,8],["ref",193],["array",208],["ref",60],["array",210],["ref",158],["array",212],["object",[[74,141,!1],[5,11,!1],[117,207,!1],[118,209,!1],[41,59,!1],[119,211,!1],[9,19,!1],[120,61,!0],[31,0,!0],[121,213,!1],[107,191,!1]]],["ref",61,191,192],["array",215],["object",[[122,216,!1],[42,85,!0],[123,61,!0],[97,59,!1],[31,0,!0],[124,112,!1]]],["object",[[125,0,!0]]],["object",[[126,59,!1],[58,59,!1],[101,59,!1],[0,0,!0]]],["object",[[127,59,!1],[128,0,!0]]],["ref",64],["array",221],["ref",65,66],["union",223,8],["object",[[5,11,!1],[129,222,!1],[130,0,!0],[31,0,!0],[131,178,!1],[132,224,!1],[107,191,!1]]],["ref",55],["array",226],["ref",37,59],["union",228,8],["object",[[133,227,!1],[56,229,!1],[3,5,!1],[134,128,!1]]],["union",138,8],["ref",70],["union",232,8],["object",[[72,231,!1],[42,86,!1],[135,233,!1]]],["ref",71],["array",235],["object",[[136,236,!1]]],["object",[[137,0,!0]]],["object",[[41,59,!1],[31,0,!0]]],["ref",74],["union",240,8],["object",[[138,241,!1],[41,59,!1],[139,241,!1],[140,149,!1],[31,0,!0],[141,0,!0]]],["object",[[72,231,!1],[41,59,!1],[42,86,!1],[135,233,!1]]],["object",[[142,0,!0]]],["object",[[142,0,!0],[92,93,!1]]],["object",[[143,0,!0]]],["object",[[144,0,!0],[31,0,!0]]],["ref",3,15,51,82],["object",[[145,135,!1],[146,59,!1],[147,248,!0]]],["enum","Seconds","Minutes","Hours","Days"],["object",[[148,55,!0],[149,250,!0]]],["object",[[116,0,!0],[3,93,!1]]],["object",[[2,3,!0],[45,0,!0],[3,5,!1]]],["ref",85],["array",254],["object",[[133,255,!1],[150,0,!0],[0,0,!0]]],["object",[[60,1,!0],[0,0,!0]]],["array",1],["object",[[151,258,!1]]],["union",0,61,8],["number",-17976931348623157e292,17976931348623157e292],["enum","Int32","Int64","Decimal","Single"],["string","^-?[0-9]+(\\.[0-9]+)?([Ee][+-]?[0-9]+)?$"],["object",[[152,262,!0],[1,263,!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",[[152,265,!0],[1,266,!0]]],["union",260,261,264,267],["object",[[1,268,!1]]],["ref",36,91],["enum","And","Or"],["object",[[86,270,!0],[87,271,!0],[88,270,!0]]],["ref",8,28,92,135],["object",[[86,273,!0],[87,271,!0],[88,273,!0]]],["object",[[86,77,!0],[87,271,!0],[88,77,!0]]],["ref",47],["array",276],["union",277,8],["ref",67],["array",279],["union",280,8],["ref",150],["array",282],["object",[[74,141,!1],[5,11,!1],[117,207,!1],[118,209,!1],[41,59,!1],[153,278,!1],[119,211,!1],[9,19,!1],[154,281,!1],[120,61,!0],[31,0,!0],[155,283,!1],[107,191,!1]]],["object",[[68,133,!1],[69,135,!1],[70,135,!1],[71,135,!1],[156,0,!0]]],["object",[[2,3,!0],[64,126,!1],[0,0,!0]]],["enum","Info","Warning","Error","Unknown"],["object",[[68,133,!1],[157,287,!0],[97,0,!0],[98,61,!0],[69,135,!1],[70,135,!1],[71,135,!1]]],["object",[[68,133,!1],[158,0,!0],[69,135,!1],[70,135,!1],[71,135,!1]]],["ref",102],["array",290],["object",[[159,291,!1]]],["object",[[31,0,!0],[1,1,!0]]],["object",[[72,231,!1],[42,86,!1]]],["object",[[41,59,!1],[31,0,!0],[14,112,!1]]],["object",[[160,61,!1],[161,59,!1],[162,59,!1],[163,0,!0],[164,56,!1],[165,56,!1]]],["union",273,8],["object",[[72,231,!1],[146,297,!1],[42,86,!1],[31,0,!0]]],["ref",56],["union",299,8],["ref",73],["union",301,8],["union",270,8],["object",[[45,0,!0],[130,128,!1],[166,300,!1],[167,302,!1],[3,93,!1],[46,96,!1],[47,303,!1]]],["object",[[2,3,!0],[64,126,!1],[42,86,!1],[56,229,!1],[31,0,!0],[168,59,!1],[169,59,!1],[16,36,!1]]],["ref",110],["array",306],["object",[[64,126,!1],[170,307,!1],[31,0,!0]]],["object",[[0,0,!0],[51,1,!0]]],["object",[[171,61,!1],[172,61,!1],[31,0,!0],[39,80,!0]]],["ref",115],["object",[[31,0,!0],[51,311,!0],[39,81,!1]]],["object",[[51,311,!0]]],["ref",116],["array",314],["object",[[129,315,!1]]],["object",[[1,1,!0]]],["object",[[129,93,!1]]],["object",[[31,0,!0],[51,128,!1],[39,80,!0]]],["ref",121],["union",320,8],["array",320],["ref",104],["union",323,8],["object",[[74,141,!1],[127,321,!1],[41,59,!1],[173,322,!1],[174,61,!1],[31,0,!0],[175,324,!1],[176,80,!0],[177,59,!1]]],["object",[[68,133,!1],[69,135,!1],[70,135,!1],[71,135,!1],[147,0,!0]]],["ref",126],["array",327],["object",[[41,59,!1],[31,0,!0],[20,328,!1],[178,303,!1]]],["ref",186],["array",330],["ref",84],["array",332],["union",333,8],["union",147,8],["ref",83,95,136],["object",[[72,231,!1],[179,331,!1],[41,59,!1],[42,86,!1],[180,334,!1],[77,335,!1],[78,152,!1],[51,336,!0]]],["object",[[41,59,!1],[42,86,!1],[31,0,!0],[62,149,!1]]],["object",[[36,59,!1],[127,59,!1],[168,0,!0]]],["object",[[72,231,!1],[41,59,!1],[45,0,!0],[42,86,!1]]],["ref",129],["array",341],["object",[[41,59,!1],[31,0,!0],[168,0,!0],[104,342,!1]]],["object",[[68,133,!1],[69,135,!1],[70,135,!1],[71,135,!1],[128,0,!0]]],["object",[[45,0,!0],[56,128,!1],[134,128,!1]]],["enum","Error","Information","Warning"],["object",[[146,270,!0],[97,59,!1],[181,346,!0]]],["object",[[182,0,!0]]],["enum","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],["union",349,8],["string","^([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](\\.[0-9]{1,7})?$"],["object",[[183,56,!1],[184,350,!1],[185,351,!0]]],["object",[[116,0,!0],[101,59,!1],[102,178,!1]]],["object",[[186,10,!0]]],["object",[[101,59,!1],[0,0,!0]]],["object",[[127,59,!1],[128,0,!0],[39,80,!0]]],["object",[[101,0,!0],[0,0,!0]]],["object",[[127,59,!1],[156,0,!0]]],["ref",137,138,139,141,143,144,145,146,148,149,151,152],["array",359],["object",[[187,360,!1],[31,0,!0]]],["ref",142],["array",362],["object",[[129,363,!1],[188,0,!0]]],["object",[[187,360,!1],[42,86,!1],[31,0,!0]]],["ref",140],["array",366],["object",[[5,11,!1],[189,367,!1],[190,178,!1],[188,0,!0],[107,191,!1]]],["ref",145],["array",369],["object",[[31,0,!0],[106,370,!1]]],["object",[[105,187,!1],[5,11,!1],[191,59,!1],[31,0,!0],[106,189,!1],[107,191,!1]]],["object",[[141,190,!0]]],["object",[[45,0,!0],[62,93,!1]]],["ref",153],["array",375],["object",[[192,0,!0],[133,376,!1]]],["ref",154],["array",378],["object",[[193,379,!1]]],["object",[[68,133,!1],[69,135,!1],[70,135,!1],[71,135,!1],[188,0,!0],[1,0,!0]]],["ref",23],["array",382],["ref",34],["array",384],["array",299],["array",301],["ref",111],["array",388],["ref",122],["array",390],["ref",125],["array",392],["ref",127],["array",394],["union",395,8],["ref",130],["array",397],["union",398,8],["ref",147],["array",400],["ref",176],["array",402],["enum","StateChange","StateView","Automation","Translate"],["object",[[194,383,!1],[195,385,!1],[196,216,!1],[41,59,!1],[133,386,!1],[42,86,!1],[31,0,!0],[197,387,!1],[198,389,!1],[199,391,!1],[200,393,!1],[201,396,!1],[202,399,!1],[203,401,!1],[204,403,!1],[39,404,!0]]],["object",[[205,59,!1],[31,0,!0]]],["object",[[56,1,!0],[31,0,!0]]],["object",[[39,0,!0],[1,0,!0]]],["ref",162],["array",409],["object",[[206,61,!0],[207,410,!1],[208,112,!1]]],["object",[[209,0,!0],[210,93,!1]]],["object",[[211,0,!0]]],["object",[[212,0,!0],[130,128,!1],[213,93,!1],[92,93,!1]]],["object",[[31,59,!1]]],["ref",172],["union",416,8],["ref",171],["union",418,8],["object",[[214,0,!0],[130,128,!1],[215,417,!1],[80,419,!1],[92,93,!1]]],["object",[[83,0,!0],[80,0,!0],[85,162,!1]]],["object",[[216,61,!0],[62,93,!1]]],["ref",173],["array",423],["object",[[68,93,!1],[216,61,!0],[128,0,!0],[217,424,!1]]],["object",[[216,61,!0],[31,0,!0],[62,93,!1]]],["ref",169],["array",427],["ref",163],["union",429,8],["ref",164],["array",431],["ref",165],["union",433,8],["ref",75],["array",435],["ref",175],["array",437],["union",438,8],["ref",161],["array",440],["ref",77],["array",442],["ref",167],["union",444,8],["ref",168],["array",446],["ref",170],["union",448,8],["ref",76],["array",450],["ref",174],["array",452],["ref",119,120],["union",454,8],["ref",166],["union",456,8],["union",427,8],["union",431,8],["ref",178],["union",460,8],["ref",177],["union",462,8],["object",[[42,86,!1],[218,428,!1],[219,430,!1],[220,432,!1],[221,434,!1],[222,436,!1],[223,439,!1],[31,0,!0],[16,36,!1],[224,441,!1],[225,443,!1],[226,445,!1],[227,447,!1],[228,428,!1],[229,61,!0],[230,449,!1],[231,451,!1],[232,453,!1],[233,439,!1],[234,424,!1],[235,455,!1],[47,457,!1],[236,458,!1],[237,459,!1],[238,434,!1],[239,461,!1],[240,463,!1]]],["object",[[147,0,!0],[92,93,!1]]],["object",[[68,93,!1],[128,0,!0]]],["object",[[56,0,!0]]],["ref",183,184],["array",468],["object",[[89,469,!1]]],["object",[[241,112,!1],[31,0,!0]]],["object",[[179,331,!1],[41,59,!1],[42,86,!1],[31,0,!0]]],["object",[[242,61,!0],[243,61,!0],[31,0,!0]]],["object",[[244,59,!1],[245,59,!1],[31,0,!0],[246,112,!1],[247,112,!1],[248,59,!1]]],["object",[[122,216,!1],[45,0,!0],[123,61,!0],[97,59,!1],[31,0,!0],[124,112,!1]]],["object",[[249,112,!1],[122,216,!1],[45,0,!0],[123,61,!0],[97,59,!1],[31,0,!0],[0,0,!0],[124,112,!1]]],["object",[[188,0,!0]]],["ref",12],["array",478],["object",[[68,479,!1],[186,0,!0]]],["enum","NotEmpty","Max","Min","GreaterThan","GreaterThanOrEqual","LessThan","LessThanOrEqual","Equal","Length","Matches","AllGreaterThan","AllGreaterThanOrEqual","Rule","NotEqual"],["object",[[72,231,!1],[42,86,!1],[135,233,!1],[97,59,!1],[0,0,!0],[250,481,!0],[181,346,!0],[1,128,!1]]],["ref",106],["array",483],["object",[[27,0,!0],[251,484,!1],[29,0,!0]]]],contracts:[2,6,51,52,58,60,62,71,72,73,76,78,79,82,89,91,99,104,107,108,79,111,113,120,121,123,124,127,129,130,131,136,137,139,160,163,165,168,169,173,174,175,176,179,130,185,130,192,193,193,176,194,72,197,198,199,201,202,203,204,214,217,218,176,219,72,220,225,230,234,237,238,239,242,243,244,245,244,246,130,247,249,251,251,252,253,256,257,192,259,269,272,274,275,284,193,285,136,286,288,289,292,293,176,294,295,296,193,298,304,199,305,308,309,310,130,312,313,316,317,318,319,325,326,238,329,337,338,339,340,343,344,199,345,347,348,352,353,354,139,355,356,357,358,361,361,364,365,368,371,372,238,373,374,377,380,309,381,405,406,176,407,408,411,412,413,414,72,415,420,72,421,72,422,425,426,464,465,466,467,2,317,470,204,238,471,82,472,473,338,474,475,476,477,480,482,485]};var Ci=Ie.rules,gd=new Map(Ci.flatMap(([t,e],n)=>t==="string"&&typeof e=="string"?[[n,new RegExp(e,"u")]]:[])),Po=new Map(Ie.kinds.map((t,e)=>[t,Ci[Ie.contracts[e]][1]])),xd=new Map([...Po].map(([t,e])=>[t,new Set(["kind",...e.map(([n])=>Ie.names[n])])])),Eo=c(t=>typeof t=="object"&&t!==null&&!Array.isArray(t),"object");function Ei(t){let e=Po.get(t.kind);if(!Object.hasOwn(t,"kind")||e===void 0||!Oo(t,e))throw new X(`Invalid typed members for syntax kind '${t.kind}'.`)}c(Ei,"validateSyntaxMembers");function yn(t,e){let n=Sn(t.kind);for(let i of Object.keys(t))if(!n.has(i)&&!e.has(i))throw new X(`Unknown member '${i}' for syntax kind '${t.kind}'.`)}c(yn,"validateClosedSyntaxMembers");function Sn(t){let e=xd.get(t);if(e===void 0)throw new X(`Unknown syntax kind '${t}'.`);return e}c(Sn,"syntaxMemberNames");function Oo(t,e){return e.every(([n,i,r])=>Object.hasOwn(t,Ie.names[n])?Pi(t[Ie.names[n]],i):!r)}c(Oo,"matchesMembers");function vd(t,e){for(let n=0;n<t.length;n++)if(!Object.hasOwn(t,n)||!Pi(t[n],e))return!1;return!0}c(vd,"allIndicesMatch");function Pi(t,e){let[n,...i]=Ci[e];switch(n){case"ref":return Eo(t)&&typeof t.kind=="string"&&i.some(r=>Ie.kinds[r]===t.kind);case"union":case"one":{let r=i.reduce((o,a)=>o+(Pi(t,a)?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)&&vd(t,i[0]);case"object":return Eo(t)&&Object.keys(t).every(r=>i[0].some(([o])=>Ie.names[o]===r))&&Oo(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||gd.get(e).test(t));default:return n==="boolean"&&typeof t=="boolean"}}c(Pi,"matches");var $d=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(","))])),kd=/^(?:Set|Clear|Increment|Decrement|Count|Add|Subtract)MappingSyntax$/;function bd(t,e){return $d[t]?.has(e)===!0||kd.test(t)&&(e==="source"||e==="value")}c(bd,"isExactOnlyMember");function Ao(t,e){return t.kind==="SpecificationSyntax"&&e==="givenCaller"?t.givenCaller==null:bd(t.kind,e)||t.kind==="ValidationRuleSyntax"&&t.implementation==null&&(e==="code"||e==="file"||e==="implementation")}c(Ao,"isLegacyOmittedMember");var gn=c(t=>typeof t=="object"&&t!==null&&typeof t.kind=="string","isNode"),hn=new Set(["kind","location","targetLocation","referenceLocation","referenceLength","nameWasEscaped","declaredTriggers"]),xn=new Set(["ApplicationSyntax","ProjectionSyntax","CaptureSyntax","SpecificationSyntax"]);function $n(t){let e=Cd(t);return Oi(e,"legacy",0),vn(e)}c($n,"toSyntaxJson");function Cd(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 d=wo();e.set(o,d);let f=o.length;for(let m=f-1;m>=0;m--)n.push(()=>{d[m]=i(Object.hasOwn(o,m)?o[m]:void 0)});return d}let a=Object.create(null);e.set(o,a);let s=Object.keys(o);!s.includes("kind")&&"kind"in o&&s.unshift("kind");for(let d=s.length-1;d>=0;d--)n.push(()=>{let f=s[d],m=o[f];f==="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)&&(a[f]=Object.assign(Object.create(null),{numericMode:"invalid"}))}),a[f]=i(m)});return a}c(i,"detach");let r=i(t);for(;n.length>0;)n.pop()();return r}c(Cd,"snapshot");function wo(){let t=[];return Object.defineProperty(t,"toJSON",{value:void 0}),t}c(wo,"dataArray");function vn(t,e="legacy",n=!1){if(Array.isArray(t)){let o=wo();for(let a=0;a<t.length;a++)o.push(vn(t[a],e,n));return o}if(gn(t)){if(xn.has(t.kind)&&(e=Je(t.sourceOptions??ye).numericMode),st(t),(t.kind==="ImplementationSyntax"||t.kind==="ImplementationHintSyntax")&&yn(t,hn),t.kind==="ValidationRuleSyntax"){let f=t;f.implementation!=null&&(f.file!=null&&yn(f.file,hn),f.code!=null&&yn(f.code,hn))}let o=Object.create(null);o.kind=t.kind;let a={...t};t.kind==="ApplicationSyntax"&&a.eventSources===void 0&&(a.eventSources=[]),t.kind==="CommandSyntax"&&a.stream===void 0&&(a.stream=null),t.kind==="CommandSyntax"&&a.streamCandidates===void 0&&(a.streamCandidates=[]);let s=e==="exact"?Sn(t.kind):void 0,d=Object.keys(a).filter(f=>(s===void 0||s.has(f))&&!(e==="legacy"&&!n&&Ao(t,f))&&!hn.has(f)&&!(t.kind==="OperationSyntax"&&f==="usesLocation")).sort(Ed);for(let f of d){let m=a[f];f==="dependsOn"&&(t.kind==="ModuleSyntax"||t.kind==="FeatureSyntax")&&Array.isArray(m)&&m.length===0||f==="sourceOptions"&&m?.numericMode==="legacy"||(o[f]=vn(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]=vn(i[o],e,n));return r}c(vn,"write");function Oi(t,e,n){if(n>96&&e==="exact")throw new X("Syntax nesting exceeds the supported depth of 96.");if(Array.isArray(t)){for(let o=0;o<t.length;o++)Oi(t[o],e,n+1);return}if(typeof t!="object"||t===null)return;let i=t;if(xn.has(i.kind)||Object.hasOwn(i,"sourceOptions")){let o=Object.hasOwn(i,"sourceOptions")?Je(i.sourceOptions):ye;if(n>0&&e!==o.numericMode)throw new X("Conflicting source numeric options.");e=o.numericMode}if(n===0&&e==="exact"&&!xn.has(i.kind))throw new X("Exact syntax requires a complete source root.");if(e==="exact"&&gn(i)&&Ei(i),i.kind==="RawExpressionSyntax"&&e==="exact"&&typeof i.text=="string"&&St(i.text))throw new X("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 X("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"||Oe(o.value)?.value!==o.value||Object.keys(o).length!==2)throw new X("Malformed or incompatible ExactNumber literal.")}else if(e==="exact")throw new X("Exact source refuses old or plain object literal insertion.")}}let r=e==="exact"&&gn(i)?Sn(i.kind):void 0;for(let[o,a]of Object.entries(i))(r===void 0||r.has(o)||gn(a)&&xn.has(a.kind))&&o!=="location"&&o!=="targetLocation"&&o!=="usesLocation"&&Oi(a,e,n+1)}c(Oi,"validateNumbers");function Ed(t,e){return t<e?-1:t>e?1:0}c(Ed,"ordinal");function Io(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")?Je(x.sourceOptions):ye)}catch($){if(!($ instanceof X))throw $;r=!0,e.push(bn(l.IncompatibleNumericSource,$.message,x.location))}let o=n.filter(x=>i.get(x)?.numericMode==="exact"||Pd(x)),a=i.get(o[0])??ye;for(let x of o.slice(1))i.get(x)?.numericMode!==a.numericMode&&(r=!0,e.push(bn(l.MixedNumericModes,"Declaration-bearing documents and marked import barrels must independently select the same numeric mode.",x.location)));r&&(a=gr);let s=new Map,d=kn(n.flatMap(x=>x.concepts),"declaration of",e,void 0,s),f=kn(n.flatMap(x=>x.types),"declaration of",e,void 0,s),m=n.map(x=>x.domain).filter(x=>x!==null);for(let x of m.slice(1))e.push(bn(l.RepeatedSingularDeclarationAcrossFiles,`The folder already declares a domain in '${Cn(m[0].location.path)}' - a folder compiles to one application, which can have at most one`,x.location));let u=Od(n.flatMap(x=>x.modules),e),h=kn(n.flatMap(x=>x.personas),"persona",e),g={kind:"ApplicationSyntax",sourceOptions:a,domain:m[0]??null,imports:Ad(n.flatMap(x=>x.imports),x=>x.qualifiedName),concepts:d,types:f,systems:n.flatMap(x=>x.systems??[]),eventSources:n.flatMap(x=>x.eventSources??[]),declaredTriggers:n.flatMap(x=>x.declaredTriggers??[]),modules:u,personas:h,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}},b=[...t.flatMap(x=>x.diagnostics),...e];return{value:g,diagnostics:b,success:!b.some(x=>x.severity==="error")}}c(Io,"mergeDocuments");function Pd(t){if($r(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)return!0;let e=c(n=>!n.isPlacement||n.slices.length>0||n.features.some(e),"feature");return t.modules.some(n=>!n.isPlacement||n.features.some(e))}c(Pd,"hasDeclarations");function Od(t,e){return jo(t).map(Do).map(n=>n.length===1?{...n[0],isPlacement:!1,features:n[0].features.map(Ai)}:{...n[0],isPlacement:!1,fileImports:n.flatMap(i=>i.fileImports),description:No(n,`module '${n[0].name}'`,e),authorize:Mo(n.map(i=>i.authorize),`module '${n[0].name}'`,e),dependsOn:To(n),features:Ro(n.flatMap(i=>i.features),e)})}c(Od,"mergeModules");function Ro(t,e){return jo(t).map(Do).map(n=>n.length===1?Ai(n[0]):{...n[0],isPlacement:!1,fileImports:n.flatMap(i=>i.fileImports),description:No(n,`feature '${n[0].name}'`,e),authorize:Mo(n.map(i=>i.authorize),`feature '${n[0].name}'`,e),dependsOn:To(n),features:Ro(n.flatMap(i=>i.features),e),slices:kn(n.flatMap(i=>i.slices),"slice",e,`feature '${n[0].name}'`)})}c(Ro,"mergeFeatures");function To(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??[])}c(To,"groupDependencies");function Do(t){return[...t.filter(e=>!e.isPlacement),...t.filter(e=>e.isPlacement)]}c(Do,"placedLast");function Ai(t){return{...t,isPlacement:!1,features:t.features.map(Ai)}}c(Ai,"unplaced");function Mo(t,e,n){let i=[];for(let r of t.filter(o=>o!==null)){let o=i.find(a=>a.location.path!==r.location.path&&JSON.stringify($n(a))===JSON.stringify($n(r)));if(o!==void 0){n.push(Lo(l.DuplicateAuthorizationAcrossFiles,`An identical authorization is already declared on the ${e} in '${Cn(o.location.path)}' - this repeated gate is ignored`,r.location));continue}i.push(r)}return i.reduce((r,o)=>ke(r,o),null)}c(Mo,"combineAuthorization");function Ad(t,e){let n=new Set;return t.filter(i=>!n.has(e(i))&&n.add(e(i))!==void 0)}c(Ad,"firstOfEach");function jo(t){let e=new Map;for(let n of t)e.set(n.name,[...e.get(n.name)??[],n]);return[...e.values()]}c(jo,"groupByName");function No(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(Lo(l.ConflictingDescriptionAcrossFiles,`The ${e} is already described in '${Cn(i[0].location.path)}' - keeping that description`,r.location));return i[0]?.description??null}c(No,"firstDescription");function kn(t,e,n,i,r=new Map){let o=[];for(let a of t){let s=r.get(a.name);if(s!==void 0&&s.path!==a.location.path){n.push(bn(l.RepeatedDeclarationAcrossFiles,`Duplicate ${e} '${a.name}'${i===void 0?"":` in ${i}`} - already declared in '${Cn(s.path)}'`,a.location));continue}s===void 0&&r.set(a.name,a.location),o.push(a)}return o}c(kn,"declaredInOneFile");var Cn=c(t=>t??"another file","describe"),bn=c((t,e,n)=>({severity:"error",code:t,message:e,location:n}),"error"),Lo=c((t,e,n)=>({severity:"warning",code:t,message:e,location:n}),"warning");function Bo(t,e){return Rd(t,e).result}c(Bo,"parsePlacedDocuments");function Rd(t,e){let n=it.capturePlaced(t.filter(g=>g.isPlacementResolved!==!1).map(g=>({lines:Ue(g.source,!1,g.path),placement:g.placement})),e),i=t.map(g=>Ye(g.source,g.path,g.isPlacementResolved===!1?[]:g.placement,!1,n,e)),r=i.flatMap((g,b)=>(g.value.eventSources??[]).map(x=>({source:x,placementResolved:t[b].isPlacementResolved!==!1}))),o=t.every(g=>g.isPlacementResolved!==!1)&&i.every(g=>!ot.hasUnknownExtent(g.diagnostics)),a=i.map((g,b)=>t[b].isPlacementResolved===!1?{...g,value:{...g.value,eventSources:[]}}:g),s=Io(a),d=new pe(new We([]),void 0,e);s.value.sourceOptions!==void 0&&(d.sourceOptions=s.value.sourceOptions),fn(s.value,d),dn(s.value,d),ln(s.value,d),an(s.value,d,a.flatMap(g=>g.inputUses)),un(s.value,d),mn(s.value,d);let f=Nt(s.value,d);nt.validate(f,d);let m=s.diagnostics,u=new Set(m.map(qo)),h=[...m,...d.diagnostics.filter(g=>!u.has(qo(g)))];return{result:{...s,value:f,diagnostics:h,success:!h.some(g=>g.severity==="error"),physicalEventSources:r,sourceInventoryComplete:o},syntax:new Map(a.map((g,b)=>[t[b].path,g.value]))}}c(Rd,"parsePlacedDocumentsWithSyntax");function qo(t){return JSON.stringify([t.code,t.location.path,t.location.line,t.location.column])}c(qo,"diagnosticKey");var N1="Executable as ESM v7. Generated values require fixtures in reference execution; other unadmitted constructs still prevent binding.",wt=new Map;function Td(t,e){let n=de(t),i=t.flatMap((u,h)=>!n[h]&&V(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(`
7
+ `),locations:t.map((u,h)=>({line:h+1,column:0}))};let r=[],o=[],a=!1;t.forEach((u,h)=>{!n[h]&&V(u)===0&&/^\w/.test(u)&&(a=/^(?:concept|type|import|domain|system|eventsource)\b/.test(u)),(a?r:o).push(h)});let s=i.includes("feature")?1:i.includes("slice")?2:3,d=e.slice(0,s),f=[...r.map(u=>t[u]),...d,...o.map(u=>" ".repeat(s*2)+t[u])].join(`
8
+ `),m=[...r.map(u=>({line:u+1,column:0})),...d.map(()=>({line:0,column:0})),...o.map(u=>({line:u+1,column:s*2}))];return{source:f,locations:m}}c(Td,"authoringSource");function Dd(t,e,n,i="current.play",r=!0){let o=e.map((I,T)=>typeof I=="string"?{path:`other-${T}.play`,source:I}:I).filter(I=>I.path!==i),a=[{path:i,source:t.join(`
9
+ `),placement:n,isPlacementResolved:r},...o],s=new Set(a.flatMap(I=>[...I.source.matchAll(/\w+/g)].map(T=>T[0]).concat(I.placement??[]))),d=c(I=>{let T=I;for(let N=1;s.has(T);N++)T=`${I}${N}`;return s.add(T),T},"fresh"),f=d("EditorAuthoring"),m=d("FragmentFeature"),u=new Set([f,m]),h=a.map((I,T)=>{let N=T===0?t:I.source.split(`
10
+ `),F=d(`Fragment${T}`);u.add(F);let dt=I.placement?.length?{source:I.source,locations:N.map((An,Mt)=>({line:Mt+1,column:0}))}:Td(N,[`module ${f}`,` feature ${m}`,` slice StateChange ${F}`]);return{...I,...dt,placement:I.placement??[]}}),g=h[0],b=new Map(h.map(I=>[I.path,I.locations])),x=Bo([...h.slice(1),g]),$=new Map,v=new Map,k=new WeakSet,P=c(I=>{if(I===null||typeof I!="object"||k.has(I))return;if(k.add(I),Array.isArray(I)){I.forEach(P);return}let T=I;if(typeof T.path=="string"&&typeof T.line=="number"&&typeof T.column=="number"){let N=b.get(T.path)?.[T.line-1];N&&(T.line=N.line,T.column=Math.max(1,T.column-N.column));return}for(let N of Object.values(T))P(N);T.location?.path===i&&(T.kind==="CommandSyntax"&&$.set(T.location.line-1,I),T.kind==="SpecificationSyntax"&&v.set(T.location.line-1,I))},"walk");P(x.value),P(x.physicalEventSources);for(let I of x.diagnostics)P(I.location);let S=x.diagnostics.some(I=>{if(!["PLAY0022","PLAY0024","PLAY0029"].includes(I.code))return!1;let T=h.find(F=>F.path===I.location.path),N=a.find(F=>F.path===I.location.path)?.source.split(`
11
+ `)[I.location.line-1];return T?.locations.some(F=>F.line===0)&&N!==void 0&&V(N)===0}),y=x.diagnostics.filter(I=>I.location.path===i).flatMap(I=>(P(I.location),I.location.line>0?[I]:[])),C=new oe(x.value),E=new Set(C.slices.flatMap(({slice:I})=>[...I.commands.flatMap(T=>T.produces),...I.reactions.flatMap(T=>T.triggers).flatMap(T=>T.produces)].filter(T=>T.location.path===i&&!C.isEventProduction(T,I)).map(T=>T.location.line-1)));for(let I of y)I.code==="PLAY0499"&&E.add(I.location.line-1);let A=C.declarations.filter(I=>I.kind===J.Operation).map(I=>({...I.node,scope:I.scope.filter(T=>!u.has(T))})),w=new Map,D=de(t),j=c(I=>{let T=[],N=V(t[I]);for(let F=I;F<t.length&&!(F>I&&!D[F]&&Te(t[F]).trim()&&V(t[F])<=N);F++)T.push(F);return T},"range");for(let{slice:I,scope:T}of C.slices){if(I.location.path===i&&I.location.line>0)for(let N of j(I.location.line-1))w.set(N,{scope:T});for(let N of I.specifications.filter(F=>F.location.path===i&&F.location.line>0))for(let F of j(N.location.line-1))w.set(F,{scope:T});for(let N of I.commands.filter(F=>F.location.path===i&&F.location.line>0))for(let F of j(N.location.line-1))w.set(F,{scope:T,commandLine:N.location.line-1})}let q=new Map(C.declarations.map(I=>[I.node.location,I.scope]));for(let I of A.filter(T=>T.location.path===i)){let T=q.get(I.location);for(let N of j(I.location.line-1))w.set(N,{...w.get(N),scope:T,operation:I})}let M=new Map(A.map(I=>[I.location,I])),L=c((I,T)=>{let N=Te(t[I.line-1]??""),F=N.slice(I.column-1).match(/^(?:given\s+operation|then\s+(?:operation|compensated))\s+/)?.[0];return F&&N.slice(I.column-1+F.length,I.column-1+F.length+T.length)===T?{...I,column:I.column+F.length}:I},"referenceLocation"),W=[];for(let{slice:I}of C.slices){for(let T of I.commands)for(let N of T.produces){if(N.location.path!==i)continue;let F=C.resolve(N.event,I),dt=F.declaration?M.get(F.declaration.node.location)??null:null,An={name:N.event,location:N.location,targetLocation:N.targetLocation??N.location,kind:F.kind,declaration:dt,mappings:N.mappings};if(W.push(An),F.kind===J.Operation)for(let Mt of j(N.location.line-1)){let Fi=w.get(Mt);Fi&&w.set(Mt,{...Fi,production:An})}}for(let T of I.specifications)for(let N of[...T.givenOperationFailures??[],...T.thenOperations??[],...T.thenCompensated??[]]){if(N.location.path!==i)continue;let F=C.resolve(N.operation,I);W.push({name:N.operation,location:N.location,targetLocation:L(N.location,N.operation),kind:F.kind,declaration:F.declaration?M.get(F.declaration.node.location)??null:null,mappings:[]})}}let B={declarations:A,systems:x.value.systems??[],references:W,contexts:w,types:x.value.types,concepts:x.value.concepts,targets:c(I=>{let T=C.slices.find(N=>N.scope.length===I.length&&N.scope.every((F,dt)=>F===I[dt]))?.slice;return T?A.flatMap(N=>{let F=C.resolve(N.name,T).declaration?.node.location===N.location?N.name:[...N.scope,N.name].join(".");return C.resolve(F,T).kind===J.Operation&&C.resolve(F,T).declaration?.node.location===N.location?[{name:F,declaration:N}]:[]}):[]},"targets")},Y=x.physicalEventSources.map(I=>I.source),ae=new ot(x.physicalEventSources,x.sourceInventoryComplete&&!S),ne=new Map,Bi=c((I,T)=>{let N=JSON.stringify([I,T]),F=ne.get(N);return F||(F=ae.resolve(I,T),ne.set(N,F)),{...F,source:F.state==="unique"?F.sources[0]:void 0,stream:F.state==="unique"?F.streams[0]:void 0}},"resolve"),Qo=new Set(x.value.imports.map(I=>I.qualifiedName)),Zo=Y.flatMap(I=>I.streams.filter(T=>Bi(I.name,T.name).state==="unique"&&!Qo.has(`${I.name}.${T.name}`)).map(T=>({name:`${I.name}.${T.name}`,source:I,stream:T}))),Re=new Map,On=[];for(let I of $.values()){for(let T of j(I.location.line-1))Re.set(T,{command:I});for(let T of[...I.produces,...I.validations,...I.handler?[I.handler]:[]])for(let N of j(T.location.line-1))Re.delete(N);if(I.stream){On.push(I.stream);for(let T of j(I.stream.location.line-1))Re.set(T,{command:I,route:I.stream})}}for(let I of v.values())for(let T of[...I.given,...I.whenAppended?[I.whenAppended]:[],...I.thenEvents]){let N={event:T,expectation:I.thenEvents.includes(T)};for(let F of j(T.location.line-1))Re.set(F,N);if(T.stream){On.push(T.stream);for(let F of j(T.stream.location.line-1))Re.set(F,{...N,route:T.stream})}}for(let I of Y.filter(T=>T.location.path===i)){for(let T of j(I.location.line-1))Re.set(T,{source:I});for(let T of I.streams)for(let N of j(T.location.line-1))Re.set(N,{source:I,stream:T})}let Go=[...$.values()].flatMap(I=>I.streamCandidates??[]).filter(I=>I.propertyCandidate!==null);return{commands:$,specifications:v,diagnostics:y,operationProductionLines:E,operations:B,eventSources:{declarations:Y,routes:On,ambiguousCandidates:Go,contexts:Re,targets:Zo,resolve:Bi}}}c(Dd,"analyze");function ct(t,e=[],n,i="current.play",r=!0){let o=JSON.stringify([t,e,n,i,r]),a=wt.get(o);return a===void 0&&(a=Dd(t,e,n,i,r),wt.size>=16&&wt.delete(wt.keys().next().value),wt.set(o,a)),a}c(ct,"responseAnalysis");var wi="file",Md=/^[A-Za-z_]\w*(?:\[\])?(?:\?|\s+optional)?$/,jd=/^(?:[/\\]|[A-Za-z]:[/\\]|~[/\\])/;function F1(t){return jd.test(t)}c(F1,"isAbsoluteFileReferencePath");function Nd(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}c(Nd,"withoutComment");function Ii(t,e){let n=V(t),i=Nd(t.slice(n)).trimEnd();if(Dn(i)!==wi)return;let r=i.slice(wi.length),o=r.trim();if(o.length===0||Md.test(o))return;let a=r.length-r.trimStart().length,s=n+wi.length+a+1;return{path:o,line:e,startColumn:s,endColumn:s+o.length}}c(Ii,"fileReferenceOn");function Y1(t){let e=de(t),n=[];for(let i=0;i<t.length;i++){if(e[i])continue;let r=Ii(t[i],i);r&&n.push(r)}return n}c(Y1,"fileReferences");function Ne(t){let e=!1;return t.map(n=>{if(e)return n.trim()==="```"&&(e=!1),n;let i=Te(n);return/^\s*```(?:[a-z]+)?\s*$/.test(i)&&(e=!0),i.trimEnd()})}c(Ne,"eventAnalysisSource");var Ld=/^concept\s+(\w+)\s*:\s*(\w+)((?:\s+@\w+)*)\s*$/,qd=/^\s*(@?[a-z_]\w*)\s+([\w.]+(?:\[\])?(?:\?|\s+optional)?)(\s+generated)?(\s+identifier)?\s*$/,Fo=/^([a-z_]\w*)\s+reason\s+"((?:[^"\\]|\\.)*)"\s*$/,Bd=/^\s*reads\s+([A-Z]\w*)(?:\s+as\s+([a-z_]\w*))?(?:\s+by\s+([a-z_]\w*))?\s*$/,Fd=["authorize","produces","reads"],Yd=/^(?:(?:or|and)\s+)?[A-Za-z_(][\p{L}\p{Mn}\p{Nd}\p{Pc}\s()]*$/u,Wd=yt,Ud=["tag","for","generation","origin","namespace","sequence","correlation","causation","causedBy","occurred"],zd=/^\s*(?:by|filter)\s+([a-z_]\w*)\s+([\w.]+(?:\[\])?(?:\?|\s+optional)?)(?:\s+from\s+.+)?\s*$/;function Le(t){return t.typeReference??pt(t.type)}c(Le,"propertyTypeReference");function Ri(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}}c(Ri,"sourceTypeAt");function Ti(t,e,n){return e.map(i=>({index:i,match:t[i].match(qd)})).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:pt(r[2]),sourceType:Ri(t[i],t[i].match(/^\s*\S+\s+/)[0].length+1),isIdentifier:r[4]!==void 0,...r[3]!==void 0?{isGenerated:!0}:{},line:i}))}c(Ti,"propertiesIn");function Rt(t,e,n,i){let r=[];for(let o=n+1;o<t.length;o++){if(e[o])continue;let a=t[o];if(a.trim().length!==0){if(V(a)<=i)break;r.push(o)}}return r}c(Rt,"collectBody");function lt(t,e,n,i){let r=Rt(t,e,n,i).filter(s=>!e[s]&&!/^\s*(?:\/\/|#)/.test(t[s]));if(!/^\s*command\b/.test(t[n]))return r;let o,a=!1;return r.filter(s=>{let d=V(t[s]),f=t[s].trim();return o!==void 0&&d>o&&(!a||Yd.test(f))?!1:(o=f!=="validate csharp"&&Ti(t,[s],Fd).length>0||/^description(?:\s|$)/.test(f)?void 0:d,a=/^authorize(?:\s|$)/.test(f),!0)})}c(lt,"directBody");var It=new Map;function Tt(t){let e=t.join(`
12
+ `),n=It.get(e);if(n)return n;let i=ct(t),r={authoringSources:[e],eventSources:i.eventSources.declarations,imports:[],concepts:[],types:[],policies:[],events:[],commands:[],queries:[],screens:[],triggers:[]};t=Ne(t);let o=de(t),a=t,s=o,d=t.map(f=>f.replace(/\s*=(?!=|>).*/,""));for(let f=0;f<t.length;f++){if(o[f])continue;let m=t[f],u=m.trim(),h=V(m),g=a[f].trim().match(/^import\s+([\w.]+)\s*$/);if(g&&h===0){let C=g[1],E=C.split(".").pop()??C;r.imports.push({qualifiedName:C,shortName:E,line:f});continue}let b=u.match(Ld);if(b){let C=Rt(t,o,f,h).map(w=>t[w].trim()),E={};for(let w of C){let D=w.match(Fo);D&&E[D[1]]===void 0&&(E[D[1]]=D[2])}let A=b[2]==="Enum"?C.filter(w=>!Fo.test(w)):[];r.concepts.push({name:b[1],primitive:b[2],attributes:b[3].trim().split(/\s+/).filter(Boolean),attributeReasons:E,enumValues:A,line:f});continue}let x=u.match(/^type\s+(\w+)\s*$/);if(x){r.types.push({name:x[1],properties:Ti(t,Rt(t,o,f,h),Yi),line:f});continue}let $=u.match(/^policy\s+(\w+)\s*$/);if($){let C=Rt(t,o,f,h).filter(E=>!o[E]).map(E=>t[E].trim());r.policies.push({name:$[1],requires:C,line:f});continue}let v=a[f].trim().match(/^(?:produces\s+)?event\s+(\w+)(?:\s+generation\s+(\d+))?\s*$/);if(v){let C=u.startsWith("produces "),E=lt(a,s,f,h),A=C?E:E.filter(w=>Ii(a[w],w)===void 0);r.events.push({name:v[1],...v[2]?{generation:Number(v[2])}:{},inline:C,properties:Ti(C?d:a,A,C?Ud:Wd),line:f});continue}let k=i.commands.get(f);if(k){let C=lt(t,o,f,h),E=C.filter(A=>/^\s*produces\b/.test(t[A])&&!i.operationProductionLines?.has(A));r.commands.push({name:k.name,properties:k.properties.map(A=>({name:A.name,type:`${A.type.name}${A.type.isCollection?"[]":""}${A.type.isOptional?" optional":""}`,typeReference:{name:A.type.name,isCollection:A.type.isCollection,isOptional:A.type.isOptional},sourceType:Ri(t[A.type.location.line-1],A.type.location.column),isIdentifier:A.isIdentifier||/\sidentifier\s*$/.test(t[A.location.line-1]),...A.isGenerated?{isGenerated:!0}:{},line:A.location.line-1})),response:k.response,productionHeaders:E,produces:E.flatMap(A=>{let w=a[A].trim(),D=/^produces\s+event\b/.test(w),j=/^produces\s+when\b/.test(w),q=j?lt(a,s,A,V(a[A]))[0]:A;if(q===void 0)return[];let M=j?a[q].trim():w.match(D?/^produces\s+event\s+([A-Za-z_]\w*)(?:\s+generation\s+\d+)?\s*$/:/^produces\s+([A-Z]\w*)\s*$/)?.[1];if(M===void 0||!/^[A-Za-z_]\w*$/.test(M))return[];let L=lt(a,s,q,V(a[q])),W=L.map(ae=>a[ae].trim().match(/^for(?:\s+(.*))?$/)).filter(ae=>ae!==null),B=W.length===0?void 0:W.length===1?W[0][1]??"":"",Y=L.flatMap(ae=>{let ne=a[ae].trim().match(D?/^(@?[a-z_]\w*)\s+[\w.]+(?:\[\])?(?:\?|\s+optional)?\s*=(?!=|>)\s*(.+)$/:/^(@?[\w.]+)\s*=(?!=|>)\s*(.+)$/);return ne===null?[]:[{name:ne[1].replace(/^@/,""),source:ne[2],line:ae}]});return[{name:M,inline:D,conditional:j,line:A,target:B,mappings:Y}]}),reads:C.filter(A=>!o[A]).map(A=>({line:A,match:t[A].match(Bd)})).filter(A=>A.match!==null).map(({line:A,match:w})=>({view:w[1],...w[2]?{alias:w[2]}:{},...w[3]?{by:w[3]}:{},line:A})),line:f});continue}let P=u.match(/^query\s+(\w+)\s*=>\s*(?:observable\s+)?([\w.]+(?:\[\])?(?:\?|\s+optional)?)\s*$/);if(P){let C=Rt(t,o,f,h).map(E=>({index:E,match:t[E].match(zd)})).filter(E=>E.match!==null).map(({index:E,match:A})=>({name:A[1],type:A[2],typeReference:pt(A[2]),sourceType:Ri(t[E],t[E].match(/^\s*(?:by|filter)\s+\S+\s+/)[0].length+1),isIdentifier:!1,line:E}));r.queries.push({name:P[1],returnType:P[2],returnTypeReference:pt(P[2]),parameters:C,line:f});continue}let S=u.match(/^screen\s+(\w+)\s*$/);if(S){r.screens.push({name:S[1],line:f});continue}let y=u.match(/^trigger\s+(\w+)\s*$/);y&&h===0&&r.triggers.push({name:y[1],line:f})}return It.size>=16&&It.delete(It.keys().next().value),It.set(e,r),r}c(Tt,"scanDocument");function En(...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)}}c(En,"mergeSymbols");function Yo(t,e){let n=e?.authoringPath??"current.play",i=e?.authoringDocuments?.find(r=>r.path===n);return{...En(Tt(t),e??En()),authoringDocuments:e?.authoringDocuments,authoringPath:n,authoringPlacement:e?.authoringPlacement??i?.placement,authoringPlacementResolved:e?.authoringPlacementResolved??i?.isPlacementResolved}}c(Yo,"symbolsForBuffer");function Pn(t){return[...t.events.map(e=>e.name),...t.imports.map(e=>e.shortName)]}c(Pn,"knownEventNames");var Vd=["Startup","Shutdown"];function nC(t){return[...Pn(t),...t.triggers.map(e=>e.name),...Vd]}c(nC,"knownTriggerNames");function Di(t,e){return[...e,...t.concepts.map(n=>n.name),...t.types.map(n=>n.name),...t.imports.map(n=>n.shortName)]}c(Di,"knownTypeNames");var Wo="EventContext",Dt={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."}]},Qd=[{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 Mi(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}c(Mi,"namesEventContextMember");var ji=Dt[Wo];function Zd(t){let e=ji;for(let n of t){let i=e.find(r=>Mi(r,n));if(!i||i.kind==="collection"||i.kind==="function")return;e=Dt[i.type]??[]}return e}c(Zd,"eventContextMembersAfter");function sC(t){return t.length===0?void 0:Zd(t.slice(0,-1))?.find(n=>Mi(n,t[t.length-1]))}c(sC,"eventContextMemberAt");function Ni(t){let e,n=ji;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=>Mi(o,i));if(!r)return{status:e?"unknownSubPath":"unknownMember",member:e,segment:i,expected:n};e=r,n=r.kind==="function"?[]:Dt[r.type]??[]}return{status:"known",member:e,expected:[]}}c(Ni,"resolveEventContextPath");function cC(){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:**",...ji.map(t=>`- \`${t.name}\` (${t.type}) - ${t.description}`)].join(`
13
+ `)}c(cC,"describeEventContext");function lC(t,e){let n=e.kind==="collection"||e.kind==="function"?[]:Dt[e.type]??[],i=[`**$eventContext.${t}**: \`${e.type}\``,"",e.description];return n.length>0&&i.push("",`**Members:** ${n.map(r=>`\`${r.name}\``).join(", ")}`),i.join(`
14
+ `)}c(lC,"describeEventContextMember");function Li(t){let e=t.properties.filter(o=>o.isIdentifier&&!Le(o).isOptional&&!Le(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}}c(Li,"productionDestinations");function hC(t,e){let n=ct(t,e?.authoringDocuments??e?.authoringSources,e?.authoringPlacement,e?.authoringPath),i=Ne(t);return Tt(i).commands.map(r=>({...r,produces:r.produces?.filter(o=>!n.operationProductionLines?.has(o.line)&&n.operations.references.some(a=>a.location.line-1===o.line&&a.kind==="event")),productionHeaders:r.productionHeaders?.filter(o=>!n.operationProductionLines?.has(o))})).flatMap(r=>{let{identifier:o,mixed:a}=Li(r);if(a||r.productionHeaders?.length!==r.produces?.length)return[];let s=r.produces?.some(d=>d.target!==void 0||d.inline);return(r.produces??[]).flatMap(d=>d.target!==void 0||d.inline&&(o===void 0||/\bgeneration\b/.test(i[d.line]))?[]:!d.inline&&s?[]:[{line:d.line,column:i[d.line].length+1,label:d.inline?`for ${o}`:"for <new event source>"}])})}c(hC,"destinationHints");var U={invalidEventSourceDeclaration:"PLAY0503",invalidCommandStream:"PLAY0504",invalidSpecificationStream:"PLAY0547",specificationStreamOnCommand:"PLAY0548",invalidSpecificationStreamRoute:"PLAY0549",invalidSpecificationStreamEventSource:"PLAY0550",specificationStreamContradictsCommand:"PLAY0551",ambiguousCommandStream:"PLAY0505",unsupportedStreamIdType:"PLAY0506",redundantSourceStreamId:"PLAY0507",eventFromLaterSlice:"PLAY0516",timelineCycleGroup:"PLAY0517",undeclaredDependency:"PLAY0552",unusedDependencyDeclaration:"PLAY0553",invalidDependencyTarget:"PLAY0554",repeatedDependencyDeclaration:"PLAY0555",mutualDependencyDeclarations:"PLAY0556",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 Gd=/^import(\s+)"([^"\\]+)"\s*(?:\/\/.*)?$/,Kd=/^import\s+"/;function zo(t){return Kd.test(t.trim())}c(zo,"isFileImportLine");function qi(t,e){let n=V(t),i=t.slice(n).match(Gd);if(!i)return;let r=n+6+i[1].length+2;return{pattern:i[2],line:e,startColumn:r,endColumn:r+i[2].length}}c(qi,"fileImportOn");function kC(t){let e=de(t),n=[];for(let i=0;i<t.length;i++){if(e[i])continue;let r=qi(t[i],i);r&&n.push(r)}return n}c(kC,"fileImports");var Uo=c(t=>t.split("/").slice(0,-1),"folderOf");function _d(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("/")}c(_d,"relativeTo");function bC(t,e){let n=Uo(t),i=new Set;for(let r of e.filter(o=>o!==t&&o.toLowerCase().endsWith(".play"))){let o=_d(n,r),a=Uo(o);i.add(o),i.add([...a,"*.play"].join("/"));for(let s=0;s<=a.length;s++)i.add([...a.slice(0,s),"**","*.play"].join("/"))}return[...i].sort()}c(bC,"importablePaths");var Jd=new Set(["namespace","sequence","correlation","causation","causedBy","occurred"]),Hd=/^id\s+"((?:[^"\\]|\\.)*)"$/;function Vo(t,e,n,i=new Set){t=Ne(t);let r=[],o=de(t),a=Xd(t,o),s=new Set(e.commands.flatMap(h=>h.productionHeaders??[])),d=new Map,f=new Set;for(let h of[e,n]){for(let g of h.events)d.set(g.name,(d.get(g.name)??0)+1);for(let g of h.imports)f.add(g.shortName)}let m=c((h,g,b,x="error")=>{r.push({line:h,startColumn:V(t[h])+1,endColumn:t[h].length+1,code:g,message:b,severity:x})},"report");for(let h of e.events){let g=lt(t,o,h.line,V(t[h.line]));if(h.inline){let $=new Set;for(let v of h.properties)$.has(v.name)&&m(v.line,U.duplicateDeclaration,`Event '${h.name}' already declares property '${v.name}'.`),$.add(v.name);s.has(h.line)||m(h.line,U.inlineEventOutsideCommand,"Inline events can only be declared inside commands."),h.generation!==void 0&&m(h.line,U.inlineEventGeneration,"Inline events are generation 1; extract the event before declaring generations."),((d.get(h.name)??0)>1||f.has(h.name))&&m(h.line,U.inlineEventCollision,`Inline event '${h.name}' collides with another declaration or import.`)}let b=!1,x=!1;for(let $ of g){let v=t[$].trim(),k=v.split(/\s+/)[0];if(h.inline&&k==="generation"&&m($,U.inlineEventGeneration,"Inline events are generation 1; extract the event before declaring generations."),h.inline&&k==="origin"&&m($,U.reservedProductionMetadata,"An inline event is local to its command and cannot declare origin."),!/^(?:id|description|documentation)\s+[\w.]+(?:\[\])?(?:\?|\s+optional)?(?:\s*=.*)?$/.test(v)){if(k==="id"){let P=v.match(Hd);b||P===null||P[1].trim().length===0?m($,U.invalidEventId,'Expected one nonempty id "<old-name>".'):P[1]===h.name&&m($,U.redundantEventId,"This id repeats the event name; remove it.","information"),b=!0}if(k==="documentation"){let P=$+1;for(;P<t.length&&t[P].trim().length===0;)P++;(x||v!=="documentation"||t[P]?.trim()!=="```markdown"||V(t[P])<=V(t[$])||!a.has(P))&&m($,U.invalidEventDocumentation,"Expected one nonempty fenced markdown documentation block."),x=!0}}}}let u=[];for(let h=0;h<t.length;h++){if(o[h]||t[h].trim().length===0)continue;let g=V(t[h]);for(;u.length>0&&u[u.length-1].indent>=g;)u.pop();let b=t[h].trim().split(/\s+/)[0];Jd.has(b)&&u.at(-1)?.event&&m(h,U.reservedProductionMetadata,`'${b}' is system-assigned production metadata.`),b==="produces"&&u.push({indent:g,event:!i.has(h)&&!/^\s*produces\s+operation\b/.test(t[h])})}for(let h of e.commands){let{identifier:g,mixed:b}=Li(h);for(let x of h.produces??[]){b&&x.target===void 0&&m(x.line,U.explicitProducesTargetsRequired,`Production '${x.name}' must state for explicitly when destinations differ.`);let $=x.target??(x.inline?g:void 0);if(!(g===void 0||$!==g))for(let v of x.mappings.filter(k=>k.source===g))m(v.line,U.eventSourceIdInPayload,`The payload copies '${g}', which already identifies the event source.`,x.inline?"warning":"information")}}return r}c(Vo,"validateInlineEvents");function Xd(t,e){let n=new Set,i,r=!1;for(let o=0;o<t.length;o++){if(!e[o])continue;let a=t[o].trim();i===void 0?(i=o,r=!1):a==="```"?(r&&t[i].trim()==="```markdown"&&n.add(i),i=void 0):a.length>0&&(r=!0)}return n}c(Xd,"nonemptyMarkdownBlocks");function he(t,e,n,i,r,o){return{severity:t,message:r,line:e,startColumn:n,endColumn:n+i,code:o}}c(he,"issue");function $e(t,e,n,i,r,o){let a=n.indexOf(i)+1;return he(t,e,a,i.length,r,o)}c($e,"tokenIssue");function ep(t,e,n){let i=[],r=new Set([...Di(e,jt),...Di(n,[])]),o=c((s,d)=>{for(let f of s.filter(m=>!r.has(Le(m).name))){let m=Le(f).name;i.push(he("warning",f.line,f.sourceType.startColumn,f.sourceType.text.length,m==="optional"?`Unknown type 'optional' on '${f.name}' of ${d} \u2014 did you forget the type before 'optional'?`:`Unknown type '${m}' on '${f.name}' of ${d} \u2014 declare it with 'concept ${m} : <Primitive>' or 'type ${m}'.`,U.unknownType))}},"checkProperties");for(let s of e.types)o(s.properties,`type '${s.name}'`);for(let s of e.events)o(s.properties,`event '${s.name}'`);for(let s of e.queries)o(s.parameters,`query '${s.name}'`);for(let s of e.commands){o(s.properties,`command '${s.name}'`);let d=s.properties.filter(f=>f.isIdentifier);for(let f of d.slice(1))i.push($e("error",f.line,t[f.line],"identifier",`Command '${s.name}' already marks '${d[0].name}' as identifier \u2014 only one property can be the identifier.`,U.duplicateCommandIdentifier))}let a=new Map;for(let s of[...e.concepts,...e.types]){if(a.get(s.name)===void 0){a.set(s.name,s.line);continue}i.push($e("error",s.line,t[s.line],s.name,`Duplicate declaration of '${s.name}' \u2014 concept and type names must be unique.`,U.duplicateDeclaration))}return i}c(ep,"validateDeclarations");function KC(t,e={}){let n=de(t),i=Tt(t),r=e.application??En(),o=Yo(t,{...r,authoringPath:e.path??r.authoringPath,authoringPlacement:e.placement??r.authoringPlacement}),a=ct(t,o.authoringDocuments??o.authoringSources?.filter(S=>S!==t.join(`
15
+ `)),o.authoringPlacement,o.authoringPath,o.authoringPlacementResolved),s=new Set(a.eventSources.routes.map(S=>S.location.line-1)),d={...i,commands:i.commands.map(S=>({...S,properties:S.properties.filter(y=>!s.has(y.line)),produces:S.produces?.filter(y=>!a.operationProductionLines?.has(y.line)),productionHeaders:S.productionHeaders?.filter(y=>!a.operationProductionLines?.has(y))}))},f=new Set([...Pn(d),...Pn(r)]),m=new Set([...d.policies,...r.policies].map(S=>S.name)),u=ep(t,d,r);u.push(...tp(t,d));let h=new Set([l.LegacyOptionalSuffix,l.InvalidOptionalModifierOrder,l.OptionalReadsNotSupported]),g=new Set([l.UnknownEvent,l.UnknownReadModelProperty,l.PiiNotSupportedOnIdentifier]),b=new Set([l.EventFromLaterSlice,l.TimelineCycleGroup]),x=new Set([l.UndeclaredDependency,l.UnusedDependencyDeclaration,l.InvalidDependencyTarget,l.RepeatedDependencyDeclaration,l.MutualDependencyDeclarations,l.AmbiguousReference]),$=new Set;for(let S of e.compilerDiagnostics??a.diagnostics){if(!h.has(S.code)&&!g.has(S.code)&&!b.has(S.code)&&!x.has(S.code)&&S.code!==l.UnknownRuleImplementationDirective&&S.code!==l.InvalidValidationRule&&S.code!==l.RepeatedDeclarationAcrossFiles&&!/^PLAY049[0-9]$|^PLAY050[0-7]$|^PLAY054[7-9]$|^PLAY055[01]$|^PLAY048[2-9]$|^PLAY004[56]$/.test(S.code))continue;let y=S.location.line-1;S.code===l.UnknownEvent&&$.add(y);let C=bi(t[y],S)||t[y].length-S.location.column+1;u.push(he(S.severity,y,S.location.column,C,S.message,S.code))}let v=c((S,y,C)=>{!f.has(C)&&!$.has(S)&&u.push($e("warning",S,y,C,`Unknown event type '${C}' \u2014 declare it in a slice or import it.`,U.unknownEvent))},"checkEvent"),k=-1;for(let S=0;S<t.length;S++){let y=t[S],C=y.trim();if(n[S]||C.length===0)continue;let E=y.match(/^[ ]*(\t+)/);if(E&&u.push(he("warning",S,E[0].length-E[1].length+1,E[1].length,"Screenplay is indentation-based \u2014 use spaces, not tabs.",U.tabIndentation)),k>=0){if(V(y)>k&&/^(?:or\s+)?[A-Z]\w*(?:\s+or\s+[A-Z]\w*)*$/.test(C)){for(let B of C.split(/\s+/).filter(Y=>Y!=="or"))m.has(B)||u.push($e("warning",S,y,B,`Unknown policy '${B}' \u2014 declare it with 'policy ${B}'.`,U.unknownPolicy));continue}k=-1}let A=np(t,n,S);A&&u.push(A);let w=C.match(/^slice\s+(\w+)/);w&&!Tn.includes(w[1])&&u.push($e("error",S,y,w[1],`Unknown slice type '${w[1]}' \u2014 expected ${Tn.join(", ")}.`,U.unknownSliceType));let D=C.match(/^concept\s+\w+\s*:\s*(\w+)/);D&&D[1]!=="Enum"&&!jt.includes(D[1])&&u.push($e("error",S,y,D[1],`Unknown primitive type '${D[1]}' \u2014 expected ${jt.join(", ")} or Enum.`,U.unknownPrimitiveType));let j=C.match(/^authorize\s+(.*)$/);if(j){k=V(y);for(let B of j[1].split(/\s+/).filter(Y=>Y!=="or"&&Y.length>0))m.has(B)||u.push($e("warning",S,y,B,`Unknown policy '${B}' \u2014 declare it with 'policy ${B}'.`,U.unknownPolicy))}let q=C.match(/^on\s+([A-Z]\w*)\s*$/);q&&v(S,y,q[1]);let M=C.match(/^produces\s+([A-Z]\w*)\s*$/);if(M&&!a.operationProductionLines?.has(S)&&v(S,y,M[1]),/^produces\s+when\b/.test(C)&&!a.operationProductionLines?.has(S))for(let B=S+1;B<t.length;B++){let Y=t[B];if(!(n[B]||Y.trim().length===0)){if(V(Y)>V(y)){let ae=Y.trim().match(/^([A-Z]\w*)\s*$/);ae&&v(B,Y,ae[1])}break}}let L=C.match(/^unique\s+event\s+([A-Z]\w*)/);L&&v(S,y,L[1]);let W=C.match(/^unique\s+[a-z_]\w*\s+on\s+([A-Z]\w*)/);W&&v(S,y,W[1]);for(let B of y.match(/\$context\.[\w.]+/g)??[]){let Y=B.substring(9).split(".");wn.includes(Y[0])?Y[0]==="causedBy"&&Y.length>1&&!In.includes(Y[1])?u.push($e("warning",S,y,B,`Unknown $context.causedBy property '${Y[1]}' \u2014 expected ${In.join(", ")}.`,U.unknownContextCausedByProperty)):Y[0]==="identity"&&Y.length>1&&!Rn.includes(Y[1])&&u.push($e("warning",S,y,B,`Unknown $context.identity property '${Y[1]}' \u2014 expected ${Rn.join(", ")}.`,U.unknownContextIdentityProperty)):u.push($e("warning",S,y,B,`Unknown $context path '${Y.join(".")}' \u2014 expected one of ${wn.join(", ")}.`,U.unknownContextPath))}}u.push(...rp(t,n)),u.push(...Vo(t,d,r,a.operationProductionLines));let P=t.map((S,y)=>({line:S,index:y})).filter(({line:S})=>/^\s*```(?:[a-z]+)?\s*$/.test(S));if(P.length%2===1){let S=P[P.length-1];u.push(he("error",S.index,1,S.line.length+1,"Unclosed inline code block \u2014 expected a closing ``` line.",U.unclosedCodeBlock))}return u}c(KC,"validateLines");function tp(t,e){let n=[];t=Ne(t);for(let i of e.commands){let r=i.properties.filter(o=>o.isIdentifier&&!Le(o).isOptional&&!Le(o).isCollection);if(r.length===1)for(let o of i.produces??[]){if(o.inline||o.conditional||o.target!==void 0)continue;let a=o.line;n.push(he("information",a,V(t[a])+1,t[a].trim().length,`Plain 'produces ${o.name}' omits its destination \u2014 use 'for ${r[0].name}' to explicitly select the command's identifier.`,U.omittedProductionDestination))}}return n}c(tp,"validateProductionDestinations");function np(t,e,n){let i=t[n],r=i.trim().replace(/\s*\/\/.*$/,"");if(!/^import\b/.test(r)||qi(i,n))return;let o=V(i);if(!(!(o>0&&["module","feature"].includes(Wi(t,e,n,o)[0]))&&!zo(i)))return he("error",n,o+1,r.length,`Invalid import '${r}' \u2014 inside a module or feature, import names files: 'import "<path or glob>"'.`,U.invalidFileImport)}c(np,"validateImport");var ip=/^(?:(?:increment|decrement|count|clear|add|subtract|set)\s+)?@?([$\w.]+)(?=\s|=|$)/;function rp(t,e){let n=[],i=c(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 d of o.matchAll(/(\.)?\$eventContext((?:\.(?:\w+(?:\(\))?)?)*)/g)){let f=d[0].substring(d[1]?.length??0),m=d[2];if(m.length===0){d[1]&&n.push(he("error",r,(d.index??0)+2,f.length,`'$eventContext' names no member - expected one of ${i(Ni("").expected)}.`,U.missingEventContextPath));continue}let u=m.substring(1),h=Ni(u),g=(d.index??0)+(d[1]?.length??0)+1;switch(h.status){case"missing":n.push(he("error",r,g,f.length,`'$eventContext.${u}' names no member - expected one of ${i(h.expected)}.`,U.missingEventContextPath));break;case"unknownMember":n.push(he("warning",r,g,f.length,`Unknown event context member '${h.segment}' in '$eventContext.${u}' - expected one of ${i(h.expected)}.`,U.unknownEventContextMember));break;case"unknownSubPath":{let b=h.expected.length===0?"no members to address":`members ${i(h.expected)}`;n.push(he("warning",r,g,f.length,`Unknown event context path '$eventContext.${u}' - '${h.member?.name}' (${h.member?.type}) has ${b}.`,U.unknownEventContextPath));break}case"belowCollection":n.push(he("error",r,g,f.length,`'$eventContext.${u}' cannot resolve - '${h.member?.name}' is a collection (${h.member?.type}) and cannot be addressed below.`,U.eventContextPathBelowCollection));break}}let a=o.trim().match(ip)?.[1],s=a?.match(/\.\$(\w+)/)?.[1];a&&s&&s!=="eventContext"&&n.push($e("warning",r,o,a,`Dynamic dictionary key '$${s}' in '${a}' is never resolved - only '$eventContext.<path>' is, so the literal text '$${s}' becomes the key.`,U.unresolvedDynamicKeySource))}return n}c(rp,"validateEventContextPaths");export{Ko as a,ap as b,sp as c,Yi as d,cp as e,wn as f,In as g,Tn as h,jt as i,lp as j,_o as k,dp as l,pt as m,fp as n,l as o,se as p,Wn as q,Un as r,k$ as s,b$ as t,Te as u,V as v,Dn as w,de as x,Wi as y,yp as z,Sp as A,Ne as B,N1 as C,ct as D,wi as E,F1 as F,Ii as G,Y1 as H,Le as I,lt as J,Tt as K,En as L,Yo as M,Pn as N,Vd as O,nC as P,Di as Q,Qd as R,Mi as S,ji as T,Zd as U,sC as V,cC as W,lC as X,Li as Y,hC as Z,U as _,zo as $,qi as aa,kC as ba,bC as ca,KC as da,rp as ea};
16
+ //# sourceMappingURL=chunk-WIBDNFQK.js.map