@cratis/screenplay-language 4.69.0 → 4.70.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,16 +0,0 @@
1
- import{a as l}from"./chunk-AYDF3IFZ.js";var co="screenplay",yd={id:co,extensions:[".play"],aliases:["Screenplay","screenplay","play"],mimetypes:["text/x-screenplay"]},md=["domain","import","concept","type","policy","persona","authentication","module","layout","theme","ui","feature","slice","event","system","eventsource","operation","command","query","projection","capture","reaction","reducer","trigger","screen","dialog","form","contribute","constraint","specification","seed","behavior"];var Si=["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"],Sd=["csharp","typescript","react","html","sql"],cn=["command","arguments","tenant","causedBy","causation","occurred","identity"],dn=["subject","name","userName"],pn=["id","name","userName","isAuthenticated","roles","claims"],fn=["StateChange","StateView","Automation","Translate"],$t=["Uuid","String","Int","Decimal","Bool","Date","DateTime"],hd=["@pii","@sensitive"],gd={comments:{lineComment:"//"},brackets:[["(",")"],["[","]"]],autoClosingPairs:[{open:"(",close:")"},{open:"[",close:"]"},{open:'"',close:'"'}],surroundingPairs:[{open:"(",close:")"},{open:"[",close:"]"},{open:'"',close:'"'}],folding:{offSide:!0},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 Xe(t){let e=/^([\w.]+)(\[\])?(\?|\s+optional)?$/.exec(t);return{name:e?.[1]??t,isCollection:e?.[2]!==void 0,isOptional:e?.[3]!==void 0}}l(Xe,"typeReferenceSymbol");function $d(t){return`${t.name}${t.isCollection?"[]":""}${t.isOptional?" optional":""}`}l($d,"typeReferenceText");function Ie(t){let e=!1,n=!1;for(let i=0;i<t.length;i++){let r=t[i];if(r==="\\"&&e&&i+1<t.length)i++;else if(r==='"'&&!n)e=!e;else if(r==="`"&&!e)n=!n;else if(!e&&!n&&r==="/"&&t[i+1]==="/")return t.slice(0,i)}return t}l(Ie,"withoutComment");function z(t){return t.length-t.trimStart().length}l(z,"indentOf");function un(t){return t.trim().split(/\s+/)[0]??""}l(un,"firstWord");function ie(t){let e=new Array(t.length).fill(!1),n=!1;for(let i=0;i<t.length;i++){if(/^\s*```(?:[a-z]+)?\s*$/.test(t[i])&&(!n||/^\s*```\s*$/.test(t[i]))){e[i]=!0,n=!n;continue}e[i]=n}return e}l(ie,"fenceMap");function hi(t,e,n,i){let r=[],o=i;for(let a=n-1;a>=0&&o>0;a--){if(e[a])continue;let s=Ie(t[a]);if(s.trim().length===0)continue;let p=z(s);p<o&&(r.push(un(s)),o=p)}return r}l(hi,"enclosingChain");function bd(t,e,n,i){for(let r=n-1;r>=0&&i>0;r--){if(e[r])continue;let o=Ie(t[r]);if(o.trim().length!==0&&z(o)<i)return o.trim()}}l(bd,"nearestEnclosingLine");var d={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",InvalidEventSourceDeclaration:"PLAY0503",InvalidCommandStream:"PLAY0504",AmbiguousCommandStream:"PLAY0505",UnsupportedStreamIdType:"PLAY0506",RedundantSourceStreamId:"PLAY0507",HandlerWithoutImplementation:"PLAY0045",UnknownHandlerDirective:"PLAY0046",CommandWithProducesAndHandler:"PLAY0035",AbsoluteFileReference:"PLAY0264",InvalidTriggerData:"PLAY0246"};function Ne(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,p=s.length-s.trimStart().length,f=po(s.substring(p),e).trimEnd();i.push(n===void 0?{number:r,raw:s,indent:p,content:f,startOffset:o}:{number:r,raw:s,indent:p,content:f,path:n,startOffset:o}),o+=a.length+1}return i}l(Ne,"splitLines");function et(t,e=!1){let n=!1,i=!1;for(let r=0;r<t.length;r++){let o=t[r];if(o==="\\"&&n&&r+1<t.length)r++;else if(o==='"'&&!i)n=!n;else if(o==="`"&&!n)i=!i;else if(!n&&!i&&(o==="/"&&r+1<t.length&&t[r+1]==="/"||e&&o==="#"))return r}return-1}l(et,"commentStart");function po(t,e){let n=et(t,e);return n<0?t:t.substring(0,n)}l(po,"stripComment");var Re=[],tt=l(t=>t.length===0,"isDocumentPlacement");function vt(t){return t.length===0?"the application":t.length===1?`module '${t[0]}'`:`feature '${t.join(".")}'`}l(vt,"describePlacement");var yn="\\p{L}\\p{Mn}\\p{Nd}\\p{Pc}",nt="[\\u0009-\\u000d\\u0020\\u0085\\u00a0\\u1680\\u2000-\\u200a\\u2028\\u2029\\u202f\\u205f\\u3000]";function Z(t){let e=`(?=[\\u0000-\\uFFFF])[${yn}]`,n=t.replace(/\[([^\]]*\\w[^\]]*)\]/g,(i,r)=>{let o=r.replaceAll("\\w","");return o===""?`(?:${e})`:`(?:${e}|[${o}])`});return new RegExp(n.replaceAll("\\w",`(?:${e})`),"u")}l(Z,"nativePattern");function $(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?yn:`[${yn}]`:o==="d"?e+="\\p{Nd}":e+=`\\${o}`;continue}r==="["&&!n?n=!0:r==="]"&&n&&(n=!1),e+=r}return new RegExp(e,"u")}l($,"pattern");var qe=l((t,e,n)=>n===void 0?{line:t,column:e}:{line:t,column:e,path:n},"sourceLocation");var mn=l(t=>t.content.length===0,"isBlank"),c=l(t=>qe(t.number,t.indent+(t.contentOffset??0)+1,t.path),"locationOf"),gi=l(t=>qe(t.number,1,t.path),"startOf");var fo=$("^(?:(?:or|and)\\s+)?[A-Za-z_(][\\w\\s()]*$"),uo=new RegExp($("\\(|\\)|[A-Za-z_]\\w*").source,"gu"),yo=$("^[A-Z]\\w*$");function Ee(t,e){let n=e.content.substring(9);for(let s=t.peekChild(e.indent);s!==void 0&&fo.test(s.content);s=t.peekChild(e.indent))t.reader.takeSignificant(),n+=` ${s.content}`;let i=mo(n),r=c(e);if(i.length===0)return t.error(d.AuthorizeWithoutPolicy,"Expected at least one policy after 'authorize'",r),null;let a=new Sn(t,i,r).parse();return a===null?null:{kind:"AuthorizeSyntax",requirement:a,location:r}}l(Ee,"parseAuthorize");function he(t,e){return t===null?e:e===null?t:{kind:"AuthorizeSyntax",requirement:{kind:"LogicalPolicyRequirementSyntax",left:t.requirement,operator:"And",right:e.requirement,location:t.location},location:t.location}}l(he,"combineAuthorize");function mo(t){let e=[];for(let n of t.match(uo)??[])e.length>0&&So(e[e.length-1])&&ho(n)&&e.push("and"),e.push(n);return e}l(mo,"tokenize");var xi=l(t=>t!=="("&&t!==")"&&t!=="and"&&t!=="or","isName"),So=l(t=>t===")"||xi(t),"isOperandEnd"),ho=l(t=>t==="("||xi(t),"isOperandStart"),Sn=class{static{l(this,"RequirementParser")}context;tokens;location;#e=0;constructor(e,n,i){this.context=e,this.tokens=n,this.location=i}parse(){let e=this.#t();return e!==null&&this.#e<this.tokens.length&&this.context.error(d.UnexpectedTokenInAuthorize,`Unexpected '${this.tokens[this.#e]}' in authorize`,this.location),e}#t(){return this.#n("or","Or",()=>this.#i())}#i(){return this.#n("and","And",()=>this.#r())}#n(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}#r(){if(this.tokens[this.#e]!=="(")return this.#s();this.#e++;let e=this.#t();return this.tokens[this.#e]===")"?this.#e++:this.context.error(d.UnclosedAuthorizeGroup,"Expected ')' in authorize",this.location),e}#s(){if(this.#e>=this.tokens.length)return this.context.error(d.AuthorizeWithoutPolicy,"Expected a policy name",this.location),null;let e=this.tokens[this.#e++];return yo.test(e)?{kind:"PolicyReferenceSyntax",name:e,location:this.location}:(this.context.error(d.InvalidPolicyReference,`Invalid policy reference '${e}' - policy names are PascalCase identifiers`,this.location),null)}};var W='(?:[^"\\\\]|\\\\.)*',go={"\\":"\\",'"':'"',n:`
3
- `,r:"\r",t:" "};function U(t){if(!t.includes("\\"))return t;let e="";for(let n=0;n<t.length;n++){let i=n+1<t.length?go[t[n+1]]:void 0;t[n]==="\\"&&i!==void 0?(e+=i,n++):e+=t[n]}return e}l(U,"unescapeString");function Be(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(d.ExpectedCodeFence,`Expected an opening \`\`\`${e==="description"?"text":e} fence after '${e}'`,c(n)),null;o!==n&&t.reader.takeSignificant(),e==="description"&&o.content==="```"&&t.warning(d.LegacyInlineCodeFence,"A bare description fence is deprecated - use '```text' instead",c(o));let s=[];for(;;){let p=t.reader.takeRaw();if(p===void 0){t.error(d.UnclosedCodeBlock,"Unclosed inline code block - expected a closing ``` line",c(o));break}if(p.raw.trim()==="```")break;let f=0;for(;f<o.indent&&f<p.raw.length&&p.raw[f]===" ";)f++;s.push(p.raw.substring(f))}return s.join(`
4
- `)}l(Be,"parseFencedText");var xo=$(`^description\\s+"(${W})"$`);function G(t,e,n,i,r=!1){if(e.content==="description"){let a=Be(t,"description",e,r);return a===null?n:a.trim().length===0?(t.error(d.EmptyDescription,`${i} declares an empty description - the fenced block must contain text`,c(e)),n):$i(t,e,n,i,a)}let o=xo.exec(e.content);return o===null?(t.error(d.InvalidDescription,`Invalid description '${e.content}' - expected 'description "<text>"'`,c(e)),n):$i(t,e,n,i,U(o[1]))}l(G,"parseDescription");function $i(t,e,n,i,r){return n!==null?(t.error(d.DuplicateDescription,`${i} already declares a description - at most one is allowed`,c(e)),n):r}l($i,"keep");var $o=$('^import\\s+"([^"\\\\]+)"$'),vo=$('^import\\s+"'),vi=l(t=>vo.test(t),"isFileImport");function ki(t){let e=$o.exec(t.content);return e===null?void 0:{kind:"FileImportSyntax",pattern:e[1],location:c(t)}}l(ki,"tryParseFileImport");function Fe(t,e,n){let i=ki(e);if(i!==void 0){n.push(i);return}t.error(d.InvalidFileImport,`Invalid import '${e.content}' - inside a module or feature, import names files: 'import "<path or glob>"'`,c(e)),t.skipBlock(e.indent)}l(Fe,"parseFileImport");var R=l(t=>{let e=t.indexOf(" ");return e===-1?t:t.substring(0,e)},"firstWord"),Q=l(t=>t.replaceAll("@",""),"unescapeIdentifier");function bi(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}l(bi,"splitTopLevel");var ko=$("^form\\s+[A-Za-z_]\\w*\\s+for\\s+([A-Za-z_]\\w*(?:\\.\\w+)*)$"),bo=$("^(execute|invokes)\\s+([A-Za-z_]\\w*(?:\\.\\w+)*)$"),Co=$("^field\\s+([\\w.]+)(?:\\s|$)"),Eo=$("^with\\s+([A-Za-z_]\\w*)\\s+from\\s+.+$"),Po=$("^(@?[\\w.]+)\\s*=(?!=|>)\\s*.+$"),Oo=$("^parameter\\s+([A-Za-z_]\\w*)(?:\\s+([\\w.]+(?:\\[\\])?))?$"),Ao=new Set(["refresh","navigate","open","close","set","notify","confirm","raise","on"]);function pe(t,e){let n=[],i=new Set,r=[],o=R(e.content)==="behavior",a=l(s=>{for(;n.length>0&&n[n.length-1].indent>=s.indent;)n.pop();let p=o&&n.length===0?Oo.exec(s.content):null;p!==null&&i.add(p[1]);let f=ko.exec(s.content),m=bo.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(Ao.has(R(s.content)))n.push({command:"",kind:"other",indent:s.indent});else{let y=n.at(-1);if(y===void 0||y.kind==="other")return;let u=(y.kind==="form"?Co:y.kind==="execute"?Eo:Po).exec(s.content);u!==null&&r.push({command:y.command,property:Q(u[1]),scope:t.scope,location:c(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)}l(pe,"collectInputUses");var Ci=["StateChange","StateView","Automation","Translate"];var it=["tag"];var wo=$(`^id\\s+"(${W})"$`),Ye=class{static{l(this,"EventMetadataParser")}name;value={id:null,description:null,documentation:null};constructor(e){this.name=e}tryParse(e,n){let i=c(n);switch(R(n.content)){case"id":{let r=wo.exec(n.content),o=r===null?"":U(r[1]);return o.trim().length===0||this.value.id!==null?e.error(d.InvalidEventId,`Event '${this.name}' accepts one nonempty 'id "<old-name>"'`,i):(this.value.id=o,o===this.name&&e.information(d.RedundantEventId,`Event '${this.name}' already has this name as its identity - remove the redundant id`,i)),!0}case"description":return this.value.description=G(e,n,this.value.description,`Event '${this.name}'`,!0),!0;case"documentation":{if(n.content!=="documentation"||e.peekChild(n.indent)?.content!=="```markdown")return e.error(d.InvalidEventDocumentation,`Event '${this.name}' documentation requires a fenced markdown block`,i),e.skipOpaqueBlock(n.indent),!0;let r=Be(e,"markdown",n);return r===null||r.trim().length===0||this.value.documentation!==null?e.error(d.InvalidEventDocumentation,`Event '${this.name}' accepts one nonempty documentation block`,i):this.value.documentation=r,!0}default:return!1}}};var hn="79228162514264337593543950335";function ve(t){let e=Ei(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>hn.length)return;let s=n.substring(i,r)+"0".repeat(a);if(s.length===hn.length&&s>hn)return;let p=Math.max(0,o),f=p===0?s:s.length>p?`${s.substring(0,s.length-p)}.${s.substring(s.length-p)}`:`0.${"0".repeat(p-s.length)}${s}`;return Object.freeze({literalType:"ExactNumber",value:(e.negative?"-":"")+f})}l(ve,"parseExactNumber");function rt(t){return Ei(t)!==void 0}l(rt,"isExactNumberToken");function Ei(t){let e=t.startsWith("-"),n=e?1:0,i=n;for(;i<t.length&&gn(t[i]);)i++;if(i===n)return;let r=t.substring(n,i),o="";if(t[i]==="."){let s=++i;for(;i<t.length&&gn(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 p=i,f=t.length+29;for(;i<t.length&&gn(t[i]);)a=Math.min(f,a*10+t.charCodeAt(i++)-48);if(i===p)return;s&&(a=-a)}return i===t.length?{negative:e,integer:r,fraction:o,exponent:a}:void 0}l(Ei,"scan");function gn(t){return t>="0"&&t<="9"}l(gn,"isDigit");var Pi=64,oe=class extends Error{static{l(this,"InvalidStructuredValue")}},kt=class{static{l(this,"StructuredValueParser")}text;start;context;#e=0;constructor(e,n,i){this.text=e,this.start=n,this.context=i}parse(){let e=this.#t(0);if(this.#o(),this.#e<this.text.length)throw new oe(`'${this.text[this.#e]}' is invalid after a single JSON value.`);return e}#t(e){this.#o();let n=this.#c(),i=this.text[this.#e];if(i==="["||i==="{"){if(e>=Pi)throw new oe(`The value nests deeper than ${Pi} levels.`);return i==="["?this.#i(e,n):this.#n(e,n)}if(i==='"')return{kind:"LiteralExpressionSyntax",value:this.#r(),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)}#i(e,n){this.#e++;let i=[];if(this.#o(),this.#a("]"))return{kind:"ListExpressionSyntax",items:i,location:n};for(;;){if(i.push(this.#t(e+1)),this.#o(),this.#a("]"))return{kind:"ListExpressionSyntax",items:i,location:n};this.#l(",")}}#n(e,n){this.#e++;let i=[],r=new Set;if(this.#o(),this.#a("}"))return{kind:"ObjectExpressionSyntax",members:i,location:n};for(;;){this.#o();let o=this.#c();if(this.text[this.#e]!=='"')throw new oe("Expected a property name in double quotes.");let a=this.#r();this.#o(),this.#l(":");let s=this.#t(e+1);if(r.has(a)?this.context?.error(d.DuplicateStructuredValueMember,`Duplicate property '${a}' in structured value`,o):(r.add(a),i.push({kind:"ObjectMemberSyntax",name:a,value:s,location:o})),this.#o(),this.#a("}"))return{kind:"ObjectExpressionSyntax",members:i,location:n};this.#l(",")}}#r(){let e=this.#s(this.#e),n=this.text.substring(this.#e,e);this.#e=e;try{return JSON.parse(n)}catch{throw new oe(`${n} is not a valid JSON string.`)}}#s(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 oe("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 oe(`'${this.text[this.#e]??""}' is an invalid start of a value.`);if(this.#e+=n[0].length,this.context?.sourceOptions.numericMode==="exact"){let r=ve(n[0]);return r===void 0?(this.context.error(d.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 oe("JSON number is outside the finite Double range.");return{kind:"LiteralExpressionSyntax",value:i,location:e}}#c(){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++}#a(e){return this.text[this.#e]!==e?!1:(this.#e++,!0)}#l(e){if(!this.#a(e))throw new oe(`Expected '${e}' at position ${this.#e}.`)}};var Io=$("^@?[A-Za-z_]\\w*(\\.@?[A-Za-z_$]\\w*)*$"),Ro=Z("^@?[A-Za-z_]\\w*(\\.@?[A-Za-z_$]\\w*)*$"),To=$("^-?\\d+(\\.\\d+)?$"),Oi=["command","arguments","tenant","causedBy","causation","occurred","identity"],Ai=["subject","name","userName"],wi=["id","name","userName","isAuthenticated","roles","claims"];function ae(t,e,n){return H(t,e,n,!0)}l(ae,"parseModeledMappingSource");function H(t,e,n,i=!1){if(t=t.trim(),t.startsWith("$context.")){let o=t.substring(9);return Mo(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 kt(t,e,n).parse()}catch(o){if(!(o instanceof oe))throw o;return n?.error(d.InvalidStructuredValue,`Invalid inline structured value: ${o.message}`,e),{kind:"RawExpressionSyntax",text:t,location:e}}let r=n===void 0?ot(t,e):ot(t,e,n);return r!==void 0?r:(i||n?.sourceOptions.numericMode==="exact"?Ro:Io).test(t)?{kind:"PathExpressionSyntax",path:t,location:e}:{kind:"RawExpressionSyntax",text:t,location:e}}l(H,"parseMappingSource");function Mo(t,e,n){let[i,r]=t.split(".");Oi.includes(i)?r!==void 0&&i==="causedBy"&&!Ai.includes(r)?n?.warning(d.UnknownContextCausedByProperty,`Unknown $context.causedBy property '${r}' - expected ${Ai.join(", ")}`,e):r!==void 0&&i==="identity"&&!wi.includes(r)&&n?.warning(d.UnknownContextIdentityProperty,`Unknown $context.identity property '${r}' - expected ${wi.join(", ")}`,e):n?.warning(d.UnknownContextPath,`Unknown $context path '${t}' - expected one of ${Oi.join(", ")}`,e)}l(Mo,"warnOnUnknownContextPath");function ot(t,e,n){let i=l(o=>({kind:"LiteralExpressionSyntax",value:o,location:e}),"literal");switch(t){case"true":return i(!0);case"false":return i(!1);case"null":return i(null)}if(t.length>=2&&(t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'")))return i(U(t.substring(1,t.length-1)));if(n?.sourceOptions.numericMode==="exact"){if(!rt(t))return;let o=ve(t);return o!==void 0?i(o):(n.error(d.InexactNumericLiteral,"Numeric literal is not exactly representable in the bounded Decimal domain.",e),{kind:"RawExpressionSyntax",text:t,location:e})}if(To.test(t)&&!Number.isNaN(Number(t)))return i(Number(t))}l(ot,"parseLiteral");var Do=$("^[A-Za-z_]\\w*(?:\\[\\])?(?:\\?|\\s+optional)?$"),Ii=l(t=>R(t.content)==="file"?t.content.substring(4).trim():"","pathOf"),ee=l(t=>Ii(t).length>0,"isFileDirective"),bt=l(t=>ee(t)&&!Do.test(Ii(t)),"isFileDirectiveAmongProperties");var jo=$("^(@?[a-z_]\\w*)\\s+([\\w.]+(?:\\[\\])?(?:\\?|\\s+optional)?)(?:\\s+(generated))?(?:\\s+(identifier))?$"),Lo=$("^@?[a-z_]\\w*\\s+[\\w.]+(?:\\[\\])?\\??\\s+((?:optional|generated|identifier)(?:\\s+(?:optional|generated|identifier))*)$"),No=$("^@?[a-z_]\\w*\\s+[\\w.]+(?:\\[\\])?\\s+identifier\\s+optional(?:\\s*=.*)?$");function Te(t){let e=jo.exec(t.content);if(e===null)return;let n=c(t);return{kind:"PropertySyntax",name:Q(e[1]),type:fe(e[2],{...n,column:n.column+t.content.indexOf(e[2],e[1].length)}),isGenerated:e[3]!==void 0,nameWasEscaped:e[1].startsWith("@"),isIdentifier:e[4]!==void 0,location:n}}l(Te,"tryParseProperty");function fe(t,e){let n=t.endsWith("?"),i=/\soptional$/.test(t),r=n||i;r&&(t=t.substring(0,t.length-(n?1:8)).trimEnd());let o=t.endsWith("[]");return o&&(t=t.substring(0,t.length-2)),{kind:"TypeRefSyntax",name:t,isCollection:o,isOptional:r,location:e}}l(fe,"parseTypeRef");function ge(t,e){let n=Te(e);return n!==void 0?xe(t,n.type,e):Ct(t,e),n}l(ge,"parseProperty");function xe(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(d.LegacyOptionalSuffix,`Write '${o} optional' instead of '${o}?'.`,e.location)}}l(xe,"reportLegacyOptionalSuffix");function Ct(t,e){if(No.test(e.content))return t.error(d.InvalidOptionalModifierOrder,"Write 'optional' before 'identifier': '<name> <Type> optional identifier'.",c(e)),!0;{let n=Lo.exec(e.content);if(n!==null&&n[1].split(/\s+/).some(i=>i==="generated"||i==="identifier"))return t.error(d.InvalidGeneratedModifierOrder,"Write each modifier once in order: '<name> <Type> optional generated identifier'.",c(e)),!0}return!1}l(Ct,"reportInvalidModifierOrder");var qo=$("^type\\s+([A-Za-z_]\\w*)$"),Bo=$("^event\\s+([A-Za-z_]\\w*)(?:\\s+generation\\s+([0-9]+))?$"),Fo=$("^readmodel\\s+([A-Za-z_]\\w*)$"),Ri=4294967295,Yo=$("^[A-Z]\\w*(?:\\[\\])?(?:\\?|\\s+optional)?$"),Wo=$("^[A-Za-z_]\\w*$"),Ti=l(t=>R(t.content)==="description"&&Te(t)===void 0,"isDescription");function xn(t,e,n,i,r){return e.isIdentifier?(t.error(i,r,c(n)),{...e,isIdentifier:!1}):e}l(xn,"withoutIdentifier");function Mi(t,e){let n=qo.exec(e.content)?.[1]??"";n===""&&t.error(d.InvalidTypeDeclaration,`Invalid type declaration '${e.content}' - expected 'type <Name>'`,c(e));let i=[],r=null;for(let o=t.peekChild(e.indent);o!==void 0;o=t.peekChild(e.indent)){if(t.reader.takeSignificant(),Ti(o)){r=G(t,o,r,`Type '${n}'`);continue}if(bt(o))continue;let a=ge(t,o);if(a===void 0){t.error(d.InvalidPropertyDeclaration,`Invalid property '${o.content}' - expected '<name> <Type>'`,c(o));continue}i.push(xn(t,a,o,d.IdentifierOutsideCommand,`Property '${a.name}' of type '${n}' cannot be marked identifier - only a command property can be`))}return i.length===0&&t.error(d.TypeWithoutProperties,`Type '${n}' must declare at least one property`,c(e)),{kind:"TypeSyntax",name:n,properties:i,description:r,location:c(e)}}l(Mi,"parseType");function Di(t,e){let n=Bo.exec(e.content),i=n?.[1]??"";n===null&&t.error(d.InvalidEventDeclaration,`Invalid event declaration '${e.content}' - expected 'event <Name> [generation <N>]'`,c(e));let r=n?.[2]!==void 0,o=1;if(r){let f=Number(n[2]);!Number.isSafeInteger(f)||f===0||f>=Ri?t.error(d.InvalidEventGeneration,`Event '${i}' must declare a generation between 1 and ${Ri-1}`,c(e)):o=f}let a=[],s=[],p=new Ye(i);for(let f=t.peekChild(e.indent);f!==void 0;f=t.peekChild(e.indent)){if(t.reader.takeSignificant(),bt(f))continue;if(it.includes(R(f.content))){let y=at(t,f);y!==void 0&&s.push(y);continue}let m=ge(t,f);if(m===void 0){p.tryParse(t,f)||t.error(d.InvalidPropertyDeclaration,`Invalid property '${f.content}' - expected '<name> <Type>'`,c(f));continue}a.push(xn(t,m,f,d.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,...p.value,location:c(e)}}l(Di,"parseEvent");function at(t,e,n=!0){let i=e.content.substring(3).trim();if(n&&Yo.test(i)&&t.warning(d.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`,c(e)),i.length===0){t.error(d.TagWithoutValue,"Expected a value after 'tag' - an identifier, a string literal or a context expression",c(e));return}if(Wo.test(i))return{kind:"TagSyntax",value:{kind:"LiteralExpressionSyntax",value:i,location:c(e)},location:c(e)};let r=H(i,c(e),t);if(r.kind==="RawExpressionSyntax"){t.error(d.InvalidTagValue,`Invalid tag value '${i}' - expected an identifier, a string literal or a context expression`,c(e));return}return{kind:"TagSyntax",value:r,location:c(e)}}l(at,"parseTag");function ji(t,e){let n=Fo.exec(e.content)?.[1]??"";n===""&&t.error(d.InvalidReadModelDeclaration,`Invalid read model declaration '${e.content}' - expected 'readmodel <Name>'`,c(e));let i=[],r=null;for(let o=t.peekChild(e.indent);o!==void 0;o=t.peekChild(e.indent))if(t.reader.takeSignificant(),Ti(o))r=G(t,o,r,`Read model '${n}'`);else{if(bt(o))continue;{let a=ge(t,o);if(a===void 0){t.error(d.InvalidPropertyDeclaration,`Invalid property '${o.content}' - expected '<name> <Type>'`,c(o));continue}i.push(xn(t,a,o,d.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:c(e)}}l(ji,"parseReadModel");var Uo=Z("^@?[A-Za-z_]\\w*(\\.@?[A-Za-z_$]\\w*)*$");function te(t,e,n){if(n=n.valueContext,t=t.trim(),t.startsWith("`")){let o=[];if(!t.endsWith("`")||t.length<2)return n.error(d.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 p=0;p<a.length;p++){if(a[p]!=="$"||a[p+1]!=="{")continue;p>s&&o.push({kind:"TemplateTextSyntax",text:a.substring(s,p),location:e});let f=a.indexOf("}",p);if(f<0)return n.error(d.UnterminatedInterpolation,"Unterminated ${...} interpolation in template expression",e),{kind:"TemplateExpressionSyntax",parts:o,location:e};o.push({kind:"TemplateInterpolationSyntax",expression:te(a.substring(p+2,f),e,n),location:e}),p=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 ae(i,e,n);if(t.startsWith("literal ")){let o=ot(t.substring(8).trim(),e,n);return o!==void 0?o:(n.error(d.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=ot(t,e,n);return r!==void 0?r:Uo.test(t)?{kind:"PathExpressionSyntax",path:t.replaceAll("@",""),location:e}:(n.error(d.InvalidExpression,`Invalid expression '${t}'`,e),{kind:"RawExpressionSyntax",text:t,location:e})}l(te,"parseProjectionExpression");var Pt=l(t=>({legacy:$(t),native:Z(t)}),"grammar"),zo=Pt("^capture\\s+([A-Za-z_]\\w*)$"),Vo=Pt("^append\\s+([A-Z]\\w*)$"),Qo=Pt("^children\\s+([a-z_]\\w*)\\s+identified\\s+by\\s+([\\w.]+)$"),Go=Pt("^nested\\s+([\\w.]+)$"),Et=l((t,e)=>t.sourceOptions.numericMode==="exact"?e.native:e.legacy,"select"),Zo=Z("^(@?[\\w.]+)\\s*=(?!=|>)\\s*(.+)$"),_o=Z("^([a-z_]\\w*)\\s*=\\s*(.+)$"),Ko=Z(`^"(${W})"\\s*=>\\s*(\\w+)$`),Jo=Z(`^split\\s+(\\S+)\\s+by\\s+"(${W})"$`),Ho=new RegExp(Z(`"${W}"|[\\w.]+`).source,"gu"),Xo=Z("^[\\w.]+$");function $n(t,e){t=t.valueContext;let n=Et(t,zo).exec(e.content)?.[1]??"";n===""&&t.sourceOptions.numericMode==="exact"&&t.error(d.InvalidCaptureDeclaration,`Invalid capture declaration '${e.content}' - expected 'capture <Name>'`,c(e));let i=null,r=null,o=[],a=[],s=[],p=[];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=ea(t,f);break;case"key":r=f.content.substring(3).trim();break;case"map":o.push(...Ni(t,f));break;case"append":qi(t,f,a);break;case"children":{let m=Et(t,Qo).exec(f.content);if(m===null){t.error(d.InvalidChildrenDeclaration,`Invalid children declaration '${f.content}' - expected 'children <collection> identified by <key>'`,c(f)),t.skipOpaqueBlock(f.indent);break}let y=Li(t,f);m!==null&&s.push({kind:"CaptureChildrenSyntax",property:m[1],identifiedBy:m[2],...y,location:c(f)});break}case"nested":{let m=Et(t,Go).exec(f.content);if(m===null){t.error(d.InvalidNestedDeclaration,`Invalid nested declaration '${f.content}' - expected 'nested <Property>'`,c(f)),t.skipOpaqueBlock(f.indent);break}let y=Li(t,f);m!==null&&p.push({kind:"CaptureNestedSyntax",property:m[1],...y,location:c(f)});break}default:t.error(d.UnknownCaptureDirective,`Unexpected '${f.content}' in capture body`,c(f)),t.skipOpaqueBlock(f.indent)}return{kind:"CaptureSyntax",sourceOptions:t.sourceOptions,name:n,source:i,key:r,map:o,appends:a,children:s,nested:p,location:c(e)}}l($n,"parseCapture");function ea(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:c(i)})}return{kind:"CaptureSourceSyntax",syntaxKind:e.content.substring(6).trim(),settings:n,location:c(e)}}l(ea,"parseSource");function Ni(t,e){let n=[];for(let i=t.peekChild(e.indent);i!==void 0;i=t.peekChild(e.indent)){t.reader.takeSignificant();let r=c(i);if(R(i.content)==="split"){let y=Jo.exec(i.content);if(y===null){t.error(d.InvalidSplitDeclaration,`Invalid split operation '${i.content}' - expected 'split <property> by "<separator>"'`,r),t.skipOpaqueBlock(i.indent);continue}let u=[];for(let S=t.peekChild(i.indent);S!==void 0;S=t.peekChild(i.indent))t.reader.takeSignificant(),Xo.test(S.content)?u.push(S.content):t.error(d.InvalidSplitTarget,`Invalid split target '${S.content}' - expected a property path`,c(S));y!==null&&n.push({kind:"CaptureSplitSyntax",source:te(y[1],r,t),separator:U(y[2]),targets:u,location:r});continue}let o=_o.exec(i.content);if(o===null){t.error(d.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,p=a.startsWith("`")?s>=0&&a.substring(s+1).trim()==="translate":a.endsWith(" translate"),f=a.startsWith("`")&&s>=0&&(t.sourceOptions.numericMode!=="exact"||p||a.substring(s+1).trim()==="")?a.substring(0,s+1):p?a.substring(0,a.length-10).trimEnd():a,m=[];if(p)for(let y=t.peekChild(i.indent);y!==void 0;y=t.peekChild(i.indent)){t.reader.takeSignificant();let u=Ko.exec(y.content);u!==null?m.push({kind:"CaptureTranslationSyntax",from:U(u[1]),to:u[2],location:c(y)}):t.error(d.InvalidTranslation,`Invalid translation '${y.content}' - expected '"<source>" => <target>'`,c(y))}n.push({kind:"CaptureMapEntrySyntax",property:o[1],source:te(f,r,t),translations:m,location:r})}return n}l(Ni,"parseMap");function Li(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=Ni(t,r):R(r.content)==="append"?qi(t,r,i):(t.error(d.UnknownCaptureBlockDirective,`Unexpected '${r.content}' in ${R(e.content)} block - expected 'map' or 'append <EventType>'`,c(r)),t.skipOpaqueBlock(r.indent));return{map:n,appends:i}}l(Li,"mapAndAppends");function qi(t,e,n){let i=Et(t,Vo).exec(e.content);if(i===null){t.error(d.InvalidAppendDeclaration,`Invalid append declaration '${e.content}' - expected 'append <EventType>'`,c(e)),t.skipOpaqueBlock(e.indent);return}let r=[],o=[],a=null,s=l((p,f=!1)=>{let m=c(p);if(R(p.content)==="tag"){let u=at(t.valueContext,p,!1);u!==void 0&&o.push(u);return}let y=Zo.exec(p.content);y!==null?r.push({kind:"PropertyMappingSyntax",property:Q(y[1]),source:ae(y[2],m,t.valueContext),location:m}):t.error(f?d.InvalidPropertyMapping:d.UnknownAppendDirective,`Unexpected '${p.content}' in append body`,m)},"mapping");for(let p=t.peekChild(e.indent);p!==void 0;p=t.peekChild(e.indent))if(t.reader.takeSignificant(),R(p.content)==="when"){a=ta(t,p);for(let f=t.peekChild(p.indent);f!==void 0;f=t.peekChild(p.indent))t.reader.takeSignificant(),s(f,!0)}else s(p);n.push({kind:"CaptureAppendSyntax",event:i[1],when:a,mappings:r,tags:o,location:c(e)})}l(qi,"pushAppend");function ta(t,e){let n=e.content.substring(4).trim(),i=c(e),r=l((p,f=[],m=null,y=null,u=null)=>({kind:"CaptureWhenSyntax",syntaxKind:p,properties:f,fromValue:m,toValue:y,expression:u,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(d.UnterminatedTemplateExpression,"Unterminated template expression in 'when' - expected a closing backtick",i),r("Expression",[],null,null,n);if(n.length===0)return t.error(d.WhenWithoutTrigger,"Expected a trigger after 'when'",i),null;let o=[...n.match(t.sourceOptions.numericMode==="exact"?new RegExp(`"${W}"|[^\\s]+`,"gu"):Ho)??[]],a=l(p=>p.startsWith('"')&&p.endsWith('"')?U(p.substring(1,p.length-1)):p,"unquote");if(o.length===0)return t.error(d.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(d.InvalidWhenTransitionClause,`Invalid 'when ... from ... to ...' clause '${e.content}'`,i),null);if(o[1]!=="or"&&o[1]!=="and")return t.error(d.InvalidWhenClause,`Invalid 'when' clause '${e.content}'`,i),null;if(o.length%2===0)return t.error(d.WhenCombinatorWithoutProperty,`Expected a property after '${o[1]}'`,i),null;let s=[a(o[0])];for(let p=1;p<o.length-1;p+=2){if(o[p]!==o[1])return t.error(d.MixedWhenCombinators,`Cannot mix 'and' and 'or' in a single 'when' clause '${e.content}'`,i),null;s.push(a(o[p+1]))}return r(o[1]==="or"?"LogicalOr":"LogicalAnd",s)}l(ta,"parseWhen");var Bi={"==":"Equal","!=":"NotEqual",">":"GreaterThan",">=":"GreaterThanOrEqual","<":"LessThan","<=":"LessThanOrEqual",contains:"Contains","starts with":"StartsWith"};function We(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(`"${W}"|==|!=|>=|<=|>|<|\\(|\\)|${i}${r}`).source,"gu"))??[],a=0,s=l(()=>{if(o[a]==="("){a++;let b=f();return o[a]===")"?a++:t.sourceOptions.numericMode==="exact"&&t.error(d.UnclosedConditionGroup,"Expected ')' in condition",n),b}let y=o[a++],u=o[a++];u==="starts"&&o[a]==="with"&&(u+=" with",a++);let S=o[a++];return y===void 0||S===void 0||Bi[u]===void 0?null:{kind:"ComparisonConditionSyntax",left:y,operator:Bi[u],right:ae(S,n,t),location:n}},"group"),p=l(()=>{let y=s();for(;y!==null&&o[a]==="and";){a++;let u=s();if(u===null)return null;y={kind:"LogicalConditionSyntax",left:y,operator:"And",right:u,location:n}}return y},"and"),f=l(()=>{let y=p();for(;y!==null&&o[a]==="or";){a++;let u=p();if(u===null)return null;y={kind:"LogicalConditionSyntax",left:y,operator:"Or",right:u,location:n}}return y},"or"),m=f();return t.sourceOptions.numericMode==="exact"&&(m===null?t.error(d.ExpectedCondition,"Expected a condition",n):a<o.length&&t.error(d.UnexpectedTokenInCondition,`Unexpected '${o[a]}' in condition`,n)),m}l(We,"parseCondition");function se(t){return $(`(?![\\s\\S]*[\\uD800-\\uDFFF\\u{10000}-\\u{10FFFF}])${t}`)}l(se,"sourceStreamPattern");var na=se("^[A-Za-z_]\\w*(?![\\s\\S])"),ia=se("^[\\w.]+(?![\\s\\S])");function vn(t){return typeof t=="string"&&na.test(t)}l(vn,"isSourceStreamName");function kn(t){return typeof t=="string"&&ia.test(t)}l(kn,"isSourceStreamTypeName");var ra=$(`^id\\s+"(${W})"$`),oa=se("^(identifier|streamId)\\s+([\\w.]+(?:\\[\\])?(?:\\?|\\s+optional)?)$"),aa=se("^eventsource\\s+([A-Za-z_]\\w*)$"),sa=se("^stream\\s+([A-Za-z_]\\w*)$");function Fi(t,e){let n=aa.exec(e.content)?.[1]??"";n===""&&Ue(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(la(t,s));break;case"identifier":r=Yi(t,s,"identifier",r);break;case"description":o=G(t,s,o,`Event source '${n}'`,!0);break;case"id":a=Wi(t,s,n,a);break;default:Ue(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:c(e)}}l(Fi,"parseEventSource");function la(t,e){let n=sa.exec(e.content)?.[1]??"";n===""&&Ue(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=Yi(t,a,"streamId",i);break;case"description":r=G(t,a,r,`Stream '${n}'`,!0);break;case"id":o=Wi(t,a,n,o);break;default:Ue(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:c(e)}}l(la,"parseEventStream");function Yi(t,e,n,i){let r=oa.exec(e.content);return r===null||i!==null?Ue(t,e,`Declare at most one '${n} <Type>'.`):(i=fe(r[2],{...c(e),column:e.indent+1+e.content.indexOf(r[2],n.length)}),xe(t,i,e)),bn(t,e,d.InvalidEventSourceDeclaration),i}l(Yi,"parseType");function Wi(t,e,n,i){let r=ra.exec(e.content),o=r===null?null:U(r[1]);return o===null||o.trim()===""||i!==null?Ue(t,e,`Declare at most one nonempty rename-only 'id "<old-name>"'.`):(i=o,o===n&&t.information(d.RedundantSourceStreamId,"The rename pin repeats the current name; omit it for a new declaration.",c(e))),bn(t,e,d.InvalidEventSourceDeclaration),i}l(Wi,"parsePin");function Ui(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:c(e)};if(i)return t.error(d.AmbiguousCommandStream,`'${e.content}' has both a property type and a stream route interpretation; neither is selected.`,c(e)),{...a,propertyCandidate:n};let s=null;for(let p=t.peekChild(e.indent);p!==void 0;p=t.peekChild(e.indent)){t.reader.takeSignificant();let f=/^streamId\s*=\s*(.+)$/.exec(p.content);if(f===null||s!==null)t.error(d.InvalidCommandStream,"A command stream accepts at most one 'streamId = <source>' mapping.",c(p)),t.skipBlock(p.indent);else{let m={...c(p),column:p.indent+1+p.content.indexOf(f[1],p.content.indexOf("=")+1)};s={kind:"PropertyMappingSyntax",property:"streamId",source:H(f[1],m,t),location:c(p)},bn(t,p,d.InvalidCommandStream)}}return{...a,streamId:s}}l(Ui,"parseCommandStream");function bn(t,e,n){let i=t.peekChild(e.indent);i!==void 0&&(t.error(n,"This directive cannot have children.",c(i)),t.skipBlock(e.indent))}l(bn,"rejectChildren");function Ue(t,e,n){t.error(d.InvalidEventSourceDeclaration,n,c(e))}l(Ue,"invalid");var Cn=$("^returns\\s+(@?[A-Za-z_]\\w*)$"),ca=$("^(@?[a-z_]\\w*)(?:\\s+([\\w.]+(?:\\[\\])?(?:\\?|\\s+optional)?))?\\s*=(?!=|>)\\s*(@?[a-z_]\\w*)$");function En(t,e){let n=c(e);if(e.content!=="returns"){let r=Cn.exec(e.content);if(r===null)return t.error(d.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(d.InvalidCommandResponse,"A scalar response cannot have child directives.",c(o)),t.skipBlock(e.indent));let a=r.index+r[0].length-r[1].length;return{kind:"ScalarCommandResponseSyntax",source:{kind:"PropertyResponseSourceSyntax",property:Q(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=ca.exec(r.content);if(o===null){t.error(d.InvalidCommandResponse,"Expected '<field> [<Type>] = <property>' in a response block.",c(r)),t.skipBlock(r.indent);continue}let a=c(r),s=o[2]===void 0?null:fe(o[2],{...a,column:a.column+r.content.indexOf(o[2],o[1].length)});s!==null&&xe(t,s,r),i.push({kind:"ResponseFieldSyntax",name:Q(o[1]),type:s,source:{kind:"PropertyResponseSourceSyntax",property:Q(o[3]),location:{...a,column:a.column+r.content.lastIndexOf(o[3])}},location:a});let p=t.peekChild(r.indent);p!==void 0&&(t.error(d.InvalidCommandResponse,"A response field cannot have child directives.",c(p)),t.skipBlock(r.indent))}return{kind:"RecordCommandResponseSyntax",fields:i,location:n}}l(En,"parseCommandResponse");var da=new Set([32,133,160,5760,8232,8233,8239,8287,12288]);function Ot(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||da.has(n)))return!1}return!0}l(Ot,"isBlankImplementationHint");var zi=new RegExp('^hint[\\u0009-\\u000d\\u0020\\u0085\\u00a0\\u1680\\u2000-\\u200a\\u2028\\u2029\\u202f\\u205f\\u3000]+"((?:[^"\\\\\\r\\n]|\\\\[^\\r\\n])*)"$'),ze=l(t=>R(t.content)==="file"&&t.content.substring(4).trim().length>0,"isFile"),st=l((t,e)=>e.content.startsWith("```")||t.languages.has(e.content),"isCode");function Pe(t,e){let n=e.content.substring(4).trim();return/^(?:[/\\]|[A-Za-z]:[/\\]|~[/\\])/.test(n)&&t.warning(d.AbsoluteFileReference,`'${n}' is an absolute path - a file reference is relative to the repository root, so it means the same thing on every machine`,c(e)),{kind:"FileReferenceSyntax",path:n,location:c(e)}}l(Pe,"parseFile");var Pn=l(t=>t.raw.trim()==="```","isClosingCodeFence");function le(t,e){let n=e.content.startsWith("```")?e.content.substring(3):e.content;if(!t.languages.has(n))return t.error(d.ExpectedCodeFence,`Expected a registered language on the opening fence, not '${e.content}'`,c(e)),null;let i=e;if(!e.content.startsWith("```")){t.warning(d.LegacyInlineCodeFence,`'${n}' on its own line is deprecated - use '\`\`\`${n}' instead`,c(e));let o=t.reader.peekSignificant();if(o===void 0||o.indent<=e.indent||o.content!=="```"&&o.content!==`\`\`\`${n}`)return t.error(d.ExpectedCodeFence,`Expected an opening \`\`\`${n} fence after '${n}'`,c(e)),null;i=t.reader.takeSignificant()}let r=[];for(;;){let o=t.reader.takeRaw();if(o===void 0){t.error(d.UnclosedCodeBlock,"Unclosed inline code block - expected a closing ``` line",c(i));break}if(Pn(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:c(e)}}l(le,"parseCode");function Vi(t,e){let n=t.peekChild(e.indent);if(n===void 0)return t.error(d.HandlerWithoutImplementation,"Expected a 'file' directive or an inline code block in the handler",c(e)),null;if(t.reader.takeSignificant(),R(n.content)==="implementation")return pa(t,e,n);let i=ze(n)?Pe(t,n):null,r=i===null&&st(t,n)?le(t,n):null;if(i!==null||r!==null){let o=t.peekChild(e.indent);return o!==void 0&&R(o.content)==="implementation"&&(t.error(d.ConflictingImplementationSources,"A handler cannot mix wrapped and direct sources.",c(o)),t.skipBlock(e.indent)),{kind:"HandlerSyntax",file:i,code:r,implementation:null,location:c(e)}}return t.error(d.UnknownHandlerDirective,`Unexpected '${n.content}' in handler - expected 'file <path>' or an inline code block`,c(n)),t.skipBlock(e.indent),null}l(Vi,"parseHandler");function pa(t,e,n){let i=lt(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"?d.InvalidImplementationBlock:d.ConflictingImplementationSources,"A handler has one implementation wrapper and cannot mix wrapped and direct sources.",c(r)),st(t,r)?le(t,r):t.skipBlock(r.indent);return{kind:"HandlerSyntax",...i,location:c(e)}}l(pa,"parseImplementation");function lt(t,e){let n=[],i=null,r=null,o=!1;e.content!=="implementation"&&t.error(d.InvalidImplementationBlock,"Expected 'implementation' with no operand.",c(e));for(let a=t.peekChild(e.indent);a!==void 0;a=t.peekChild(e.indent))if(t.reader.takeSignificant(),R(a.content)==="hint"||zi.test(a.content)){let s=zi.exec(a.content),p=s===null?null:U(s[1]);Ot(p)?t.error(d.InvalidImplementationHint,"Expected 'hint' followed by one nonblank quoted string.",c(a)):n.push({kind:"ImplementationHintSyntax",text:p,location:c(a)});let f=t.peekChild(a.indent);f!==void 0&&(t.error(d.InvalidImplementationHint,"A hint cannot have children.",c(f)),t.skipBlock(a.indent))}else if(ze(a)||a.content.startsWith("```")){o&&t.error(d.ConflictingImplementationSources,"An implementation has at most one file or inline payload.",c(a));let s=ze(a)?Pe(t,a):null,p=s===null?le(t,a):null;o||(i=s,r=p),o=!0;let f=t.peekChild(a.indent);s!==null&&f!==void 0&&(t.error(d.InvalidImplementationBlock,"A file directive cannot have children.",c(f)),t.skipBlock(a.indent))}else t.error(d.InvalidImplementationBlock,`Unexpected '${a.content}' in implementation - expected hint, file or a tagged fence.`,c(a)),t.skipBlock(a.indent);return{file:i,code:r,implementation:{kind:"ImplementationSyntax",hints:n,location:c(e)}}}l(lt,"parseImplementationWrapper");var J=class extends Error{static{l(this,"InvalidSyntaxJson")}};var ce=Object.freeze({numericMode:"legacy"}),At=Object.freeze({numericMode:"exact"}),Qi=Object.freeze({numericMode:"invalid"});function Ve(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 J("Malformed source numeric options.");let e=t.numericMode;if(e!=="legacy"&&e!=="exact")throw new J("Malformed source numeric options.");return e==="exact"?At:ce}l(Ve,"validatedSourceOptions");var Gi=new WeakSet;function Zi(t){Gi.add(t)}l(Zi,"recordAuthoredDocument");function _i(t){return Gi.has(t)}l(_i,"isAuthoredDocument");var ue=class t{static{l(this,"ParserContext")}reader;path;#e=[];triggerData=[];inputUses=[];scope=[];languages;sourceOptions=ce;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 qe(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 wt=new WeakMap;var fa=$("^system\\s+([A-Za-z_]\\w*)$"),ua=$("^operation\\s+([A-Za-z_]\\w*)$"),ya=$("^produces\\s+operation\\s+([A-Za-z_]\\w*)$"),On=$("^uses\\s+([A-Za-z_]\\w*)$"),ma=$("^(.+?)\\s*=(?!=|>)\\s*(.+)$"),Sa=new Set(["for","tag","generation","origin","documentation","namespace","sequence","correlation","causation","causedBy","occurred"]);function ct(t,e,n,i){let r=t.peekChild(e.indent);r!==void 0&&(t.error(n,i,c(r)),t.skipBlock(e.indent))}l(ct,"rejectOperationChildren");function Ki(t,e){let n=fa.exec(e.content);n===null&&t.error(d.InvalidSystemDeclaration,"Expected 'system <Name>'.",c(e));let i=null;for(let r=t.peekChild(e.indent);r!==void 0;r=t.peekChild(e.indent))t.reader.takeSignificant(),R(r.content)==="description"?i=G(t,r,i,`System '${n?.[1]??""}'`):(t.error(d.InvalidSystemDeclaration,"A system accepts only a description; abilities are not supported.",c(r)),t.skipBlock(r.indent));return{kind:"SystemSyntax",name:n?.[1]??"",description:i,location:c(e)}}l(Ki,"parseSystem");function It(t,e,n=!1){let i=(n?ya:ua).exec(e.content),r=i?.[1]??"";i===null&&t.error(d.InvalidOperationDeclaration,"Expected an operation declaration with one name.",c(e));let o=null,a=null,s=c(e),p=null,f=null,m=[],y=[],u=new Set;for(let S=t.peekChild(e.indent);S!==void 0;S=t.peekChild(e.indent)){t.reader.takeSignificant();let b=ma.exec(S.content),v=n&&b!==null?{...S,content:b[1].trimEnd()}:S;if(b===null&&Sa.has(R(S.content))){t.error(d.InvalidOperationDeclaration,"Operations cannot declare event routing or metadata; escape a keyword-named input with @.",c(S)),t.skipBlock(S.indent);continue}if(!On.test(S.content)&&Te(v)!==void 0){let x=ge(t,v);n&&b===null&&t.error(d.InvalidOperationMapping,"An inline operation input requires '<property> <Type> = <source>'.",c(S)),(x.isIdentifier||x.isGenerated)&&t.error(d.InvalidOperationDeclaration,"Operation inputs cannot be identifier or generated properties.",c(S)),u.has(x.name)&&t.error(d.DuplicateDeclaration,`Operation '${r}' already declares input '${x.name}'.`,c(S)),u.add(x.name),m.push(x),n&&b!==null&&y.push({kind:"PropertyMappingSyntax",property:x.name,source:H(b[2],{...c(S),column:S.indent+S.content.length-b[2].length+1},t),location:c(S)}),ct(t,S,d.InvalidOperationDeclaration,"An operation input cannot have children.")}else if(R(S.content)==="description")o=G(t,S,o,`Operation '${r}'`);else if(On.test(S.content))a!==null?t.error(d.InvalidSystemReference,"An operation declares exactly one 'uses <System>'.",c(S)):(a=On.exec(S.content)[1],s={...c(S),column:c(S).column+S.content.indexOf(a,4)}),ct(t,S,d.InvalidSystemReference,"A system reference cannot have children.");else if(S.content==="execute"||S.content==="compensate"){let x=ha(t,S);S.content==="execute"?p!==null?t.error(d.InvalidOperationDeclaration,"An operation declares execute at most once.",c(S)):p=x:f!==null?t.error(d.InvalidOperationDeclaration,"An operation declares compensate at most once.",c(S)):f=x}else t.error(d.InvalidOperationDeclaration,`Unexpected '${S.content}' in operation - expected uses, an input, description, execute or compensate.`,c(S)),t.skipBlock(S.indent)}return a===null&&t.error(d.InvalidSystemReference,"An operation requires exactly one 'uses <System>'.",c(e)),{operation:{kind:"OperationSyntax",name:r,uses:a??"",usesLocation:s,inputs:m,description:o,execute:p,compensate:f,location:c(e)},mappings:y}}l(It,"parseOperation");function ha(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=G(t,s,n,`Operation phase '${e.content}'`);continue}if(R(s.content)==="implementation"){a&&t.error(d.ConflictingImplementationSources,"A phase cannot mix wrapped and direct sources or repeat its wrapper.",c(s));let p=lt(t,s);a||(i=p.file,r=p.code,o=p.implementation),a=!0}else if(ee(s)||s.content.startsWith("```")){a&&t.error(d.ConflictingImplementationSources,"A phase has at most one file or inline payload.",c(s));let p=ee(s)?Pe(t,s):null,f=p===null?le(t,s):null;a||(i=p,r=f),a=!0,p!==null&&ct(t,s,d.InvalidImplementationBlock,"A file directive cannot have children.")}else t.error(d.InvalidOperationDeclaration,"A phase accepts description, file, a tagged fence or implementation.",c(s)),t.skipBlock(s.indent)}return{kind:"OperationPhaseSyntax",description:n,file:i,code:r,implementation:o,location:c(e)}}l(ha,"parseOperationPhase");var ga=$("^produces\\s+operation(?:\\s|$)"),xa=$("^produces\\s+event\\s+([A-Za-z_]\\w*)(?:\\s+(generation)(?:\\s+.*)?)?$"),$a=$("^produces\\s+([A-Z]\\w*(?:\\.[A-Za-z_]\\w*)*)$"),Ji=$("^produces\\s+when\\s+(.+)$"),va=$("^[A-Z]\\w*(?:\\.[A-Za-z_]\\w*)*$"),ka=$("^for\\s+(\\S.*)$"),ba=$("^(@?[\\w.]+)\\s*=(?!=|>)\\s*(.+)$"),Ca=$("^(.+?)\\s*=(?!=|>)\\s*(.+)$"),Ea=new Set(["namespace","sequence","correlation","causation","causedBy","occurred"]);function Rt(t,e,n=!1){if(ga.test(e.content)){if(!n){t.error(d.OperationOutsideCommand,"Operations can only be produced by commands.",c(e)),t.skipOpaqueBlock(e.indent);return}let b=It(t,e,!0);return{kind:"ProducesSyntax",when:null,event:b.operation.name,targetLocation:{...c(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:c(e)}}let i=xa.exec(e.content),r=e,o=null,a,s;if(i!==null){if(!n){t.error(d.InlineEventOutsideCommand,"Inline events can only be declared inside commands",c(e)),t.skipOpaqueBlock(e.indent);return}i[2]!==void 0&&t.error(d.InlineEventGeneration,"Inline events are generation 1 - extract the event before declaring generations",c(e)),a=i[1],s=e.indent+e.content.match(/^produces\s+event\s+/)[0].length+1}else if(Ji.test(e.content)){o=We(t,Ji.exec(e.content)[1],c(e));let b=t.peekChild(e.indent);if(b===void 0||!va.test(b.content)){t.error(d.ProducesWhenWithoutEvent,"Expected an event name on the line after 'produces when'",c(e)),t.skipOpaqueBlock(e.indent);return}t.reader.takeSignificant(),r=b,a=b.content,s=b.indent+1}else{let b=$a.exec(e.content);if(b===null){t.error(d.InvalidProducesDeclaration,`Invalid produces declaration '${e.content}' - expected 'produces <EventType>' or 'produces when <condition>'`,c(e)),t.skipOpaqueBlock(e.indent);return}a=b[1],s=e.indent+e.content.match(/^produces\s+/)[0].length+1}let p=[],f=new Set,m=[],y=[],u=new Ye(a),S=null;for(let b=t.peekChild(r.indent);b!==void 0;b=t.peekChild(r.indent)){t.reader.takeSignificant();let v=R(b.content),x=c(b);if(Ea.has(v)){t.error(d.ReservedProductionMetadata,`'${v}' is system-assigned production metadata and cannot be supplied here`,x),t.skipOpaqueBlock(b.indent);continue}if(i!==null&&(v==="generation"||v==="origin")){t.error(v==="generation"?d.InlineEventGeneration:d.ReservedProductionMetadata,v==="generation"?"Inline events are generation 1 - extract the event before declaring generations":"An inline event is local to its command and cannot declare origin",x),t.skipOpaqueBlock(b.indent);continue}if(v==="tag"){let P=at(t,b,!1);P!==void 0&&y.push(P);continue}let g=ka.exec(b.content);if(g!==null){S!==null?t.error(d.DuplicateProducesTarget,`'${r.content}' already declares where it lands - an event is appended to one event source`,x):S=H(g[1],x,t);continue}let k=(i===null?ba:Ca).exec(b.content),E=k===null||i===null?void 0:ge(t,{...b,content:k[1].trimEnd()});if(k!==null&&(i===null||E!==void 0)){if(E!==void 0){E.isIdentifier&&(t.error(d.IdentifierOnEventProperty,`Property '${E.name}' of event '${a}' cannot be marked identifier - an event never carries its event source id`,x),E={...E,isIdentifier:!1});let P=E.name;f.has(P)&&t.error(d.DuplicateDeclaration,`Event '${a}' already declares property '${E.name}'`,x),f.add(P),p.push(E)}m.push({kind:"PropertyMappingSyntax",property:E?.name??Q(k[1]),source:H(k[2],{...x,column:b.indent+b.content.length-k[2].length+1},t),location:x})}else(i===null||!u.tryParse(t,b))&&t.error(d.InvalidPropertyMapping,`Invalid ${i===null?"":"inline "}property mapping '${b.content}' - expected '<property>${i===null?"":" <Type>"} = <source>'`,x)}return r!==e&&t.skipBlock(e.indent),{kind:"ProducesSyntax",when:o,event:a,targetLocation:{...c(r),column:s},inlineOperation:null,mappings:m,for:S,tags:i===null?y:[],location:c(e),inlineEvent:i===null?null:{kind:"EventSyntax",name:a,properties:p,tags:y,generation:1,hasGenerationMarker:!1,...u.value,location:c(e)}}}l(Rt,"parseProduces");var Pa=$("^command\\s+([A-Za-z_]\\w*)$"),Oa=se("^stream\\s+[A-Za-z_]\\w*\\.[A-Za-z_]\\w*$"),Aa=$("\\bseverity\\s+(\\S+)$"),Xi=$(`\\bmessage\\s+(?:"(${W})"|(\\$strings\\.\\S*))$`),wa=$("^([\\w.]+)\\s+(.+)$"),Ia=$("^(not empty|length ==|all >=|all >|matches|max|min|rule|>=|<=|==|!=|>|<)\\s*(.*)$"),Ra=se("^[A-Za-z_]\\w*$"),Ta=$("^reads\\s+[A-Z]\\w*\\s+optional(?:\\s|$)"),Ma={max:"Max",min:"Min",">":"GreaterThan",">=":"GreaterThanOrEqual","<":"LessThan","<=":"LessThanOrEqual","==":"Equal","!=":"NotEqual","length ==":"Length",matches:"Matches","all >":"AllGreaterThan","all >=":"AllGreaterThanOrEqual"},er={information:"Information",warning:"Warning",error:"Error"},Da=new Set(["reads","concurrency"]),ja=new Set(["description","handler","concurrency"]);function tr(t,e){let n=new Set,i=new ue(t.reader.fork(),t.path,t.languages);return i.sourceOptions=t.sourceOptions,i.streamCandidates=t.streamCandidates,Hi(i,e,void 0,n),Hi(t,e,n)}l(tr,"parseCommand");function Hi(t,e,n,i){let r=Pa.exec(e.content)?.[1]??"";r===""&&t.error(d.InvalidCommandDeclaration,`Invalid command declaration '${e.content}' - expected 'command <Name>'`,c(e));let o=[],a=[],s,p=[],f=[],m=[],y=null,u=null,S=null,b=null,v=[];for(let h=t.peekChild(e.indent);h!==void 0;h=t.peekChild(e.indent)){t.reader.takeSignificant();let C=R(h.content),A=Te(h);if(A!==void 0&&(ja.has(C)||C==="validate"&&h.content!=="validate csharp"))s=Tt(t,o,A,r,h,s);else if(C==="returns"){let w=Cn.exec(h.content);w!==null&&!w[1].startsWith("@")&&A!==void 0?n===void 0?(o.push(A),a.push({line:h,candidate:A,response:null})):n.has(A.type.name)?a.push({line:h,candidate:null,response:En(t,h)}):s=Tt(t,o,A,r,h,s):A!==void 0?s=Tt(t,o,A,r,h,s):Ct(t,h)?t.skipBlock(h.indent):a.push({line:h,candidate:null,response:En(t,h)})}else if(C==="stream"&&Oa.test(h.content)&&A!==void 0&&t.streamCandidates?.hasSource(A.type.name.split(".")[0])===!0){let[w,I]=A.type.name.split("."),q=t.streamCandidates.hasPropertyType(A.type.name)&&t.streamCandidates.hasUniqueStream(w,I),B=Ui(t,h,A,q);(b!==null||v.length>0)&&t.error(d.InvalidCommandStream,"A command declares at most one stream route.",c(h)),q||b!==null?v.push(B):b=B}else if(C==="description")y=G(t,h,y,`Command '${r}'`);else if(C==="authorize")u=he(u,Ee(t,h));else if(C==="validate"){let w=An(t,h,"command");w!==void 0&&p.push(w)}else if(C==="produces"){let w=Rt(t,h,!0);w!==void 0&&f.push(w)}else if(C==="handler")S=Vi(t,h);else if(Da.has(C)){let w=/^reads\s+([A-Z]\w*)(?:\s+as\s+([a-z_]\w*))?(?:\s+by\s+([a-z_]\w*))?$/.exec(h.content);w!==null&&m.push({readModel:w[1],alias:w[2]??null}),Ta.test(h.content)&&t.error(d.OptionalReadsNotSupported,"Optional reads are not yet supported (see #308).",c(h)),t.skipOpaqueBlock(h.indent)}else A!==void 0?s=Tt(t,o,A,r,h,s):(Ct(t,h),t.error(d.UnknownCommandDirective,`Unexpected '${h.content}' in command body`,c(h)),t.skipBlock(h.indent))}let x=new Set(a.flatMap(h=>h.candidate===null?[]:[h.candidate])),g=new Set(o.filter(h=>!x.has(h)).map(h=>h.name));a.some(h=>h.candidate!==null&&!g.has(h.candidate.type.name)&&h.candidate.type.name!=="returns")&&g.add("returns");for(let h of g)i?.add(h);let k=null,E=new Set;for(let h of a){let C=h.response;if(h.candidate!==null){if(!g.has(h.candidate.type.name))continue;E.add(h.candidate),C={kind:"ScalarCommandResponseSyntax",source:{kind:"PropertyResponseSourceSyntax",property:h.candidate.type.name,location:h.candidate.type.location},location:c(h.line)}}C!==null&&(k!==null?t.error(d.InvalidCommandResponse,"A command declares at most one unconditional response.",c(h.line)):k=C)}S!==null&&f.length>0&&t.error(d.CommandWithProducesAndHandler,`Command '${r}' cannot declare both 'produces' and 'handler'`,c(e));let P={kind:"CommandSyntax",name:r,description:y,authorize:u,properties:o.filter(h=>!E.has(h)),validations:p,produces:f,handler:S,response:k,stream:b,streamCandidates:v,location:c(e)};return wt.set(P,m),P}l(Hi,"parseCommandBody");function Tt(t,e,n,i,r,o){return xe(t,n.type,r),n.isIdentifier&&o!==void 0&&(t.error(d.DuplicateCommandIdentifier,`Command '${i}' already marks '${o.name}' as identifier - only one property can be the identifier`,n.location),n={...n,isIdentifier:!1}),e.push(n),o??(n.isIdentifier?n:void 0)}l(Tt,"addProperty");function An(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=le(t.valueContext,i);return s===null&&t.skipFencedBody(),{kind:"CodeValidateSyntax",code:s,location:c(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(d.InvalidValidationRule,`Invalid validation rule '${s.content}'`,c(s)),a??=s.indent;continue}}if(R(s.content)==="require"){let f=We(n==="concept"?t.valueContext:t,s.content.substring(7).trim(),c(s)),m=null,y="Error",u=!1;for(let S=t.peekChild(s.indent);S!==void 0;S=t.peekChild(s.indent)){t.reader.takeSignificant();let b=Xi.exec(S.content);b!==null&&b.index===0?m=b[1]!==void 0?U(b[1]):b[2]:R(S.content)==="severity"?(u||(y=er[S.content.substring(8).trim()]??"Error"),u=!0):t.skipOpaqueBlock(S.indent)}f!==null&&o.push({kind:"RequirementSyntax",condition:f,message:m,severity:y,location:c(s)});continue}let p=La(t,n==="concept"?{...s,content:`value ${s.content}`}:s,n);p!==void 0&&r.push(p)}return{kind:"DeclarativeValidateSyntax",rules:r,requirements:o,location:c(e)}}if(e.content==="validate csharp"){let i=le(t.valueContext,{...e,content:"csharp"});return i===null&&t.skipOpaqueBlock(e.indent),{kind:"CodeValidateSyntax",code:i,location:c(e)}}t.error(d.InvalidValidateDeclaration,`Invalid validate declaration '${e.content}' - expected 'validate' or 'validate csharp'`,c(e)),t.skipBlock(e.indent)}l(An,"parseValidate");function La(t,e,n){let i=n==="concept"?t.valueContext:t,{content:r,message:o}=qa(e.content),a=Ba(i,e,r);if(a===void 0)return;let s=wa.exec(a.content);if(s===null){i.error(d.InvalidValidationRule,`Invalid validation rule '${e.content}'`,c(e));return}let p=Fa(i,s[2],e);if(p===void 0)return;let f=p.kind==="Rule"?Na(t,e,n==="command"):{file:null,code:null,implementation:null};return{kind:"ValidationRuleSyntax",property:s[1],rule:p.kind,value:p.value,message:o,severity:a.severity,...f,location:c(e)}}l(La,"parseValidationRule");function Na(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?lt(t,i):{file:ze(i)?Pe(t,i):null,code:!ze(i)&&st(t,i)?le(t,i):null,implementation:null};!r&&o.file===null&&o.code===null&&(t.error(d.UnknownRuleImplementationDirective,`Unexpected '${i.content}' in rule implementation - expected 'file <path>' or an inline code block`,c(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"?d.InvalidImplementationBlock:d.ConflictingImplementationSources,"A named rule has one implementation wrapper and cannot mix wrapped and direct sources.",c(a)),st(t,a)?le(t,a):t.skipBlock(a.indent);return o}l(Na,"parseRuleImplementation");function qa(t){let e=Xi.exec(t);if(e===null)return{content:t,message:null};let n=e[1]!==void 0?U(e[1]):e[2];return{content:t.substring(0,e.index).trimEnd(),message:n}}l(qa,"splitMessage");function Ba(t,e,n){let i=Aa.exec(n);if(i===null)return{content:n,severity:"Error"};let r=er[i[1]];if(r===void 0){t.error(d.InvalidValidationSeverity,`Unknown validation severity '${i[1]}' - expected information, warning or error`,c(e));return}return{content:n.substring(0,i.index).trimEnd(),severity:r}}l(Ba,"splitSeverity");function Fa(t,e,n){if(e==="not empty")return{kind:"NotEmpty",value:null};let i=Ia.exec(e);if(i===null){t.error(d.InvalidValidationRule,`Invalid validation rule '${n.content}'`,c(n));return}if(i[1]==="rule"){let r=i[2].trim();if(!Ra.test(r)){t.error(d.InvalidRuleName,`Invalid rule name '${r}' in '${n.content}' - expected 'rule <Name>' with an identifier`,c(n));return}return{kind:"Rule",value:{kind:"PathExpressionSyntax",path:r,location:c(n)}}}return{kind:Ma[i[1]],value:H(i[2],c(n),t)}}l(Fa,"parseRule");var Ya=$("^constraint\\s+([A-Za-z_]\\w*)$"),Wa=$("^unique\\s+event\\s+([A-Z]\\w*)$"),Ua=$("^unique\\s+([a-z_][\\w.]*(?:\\s*,\\s*[a-z_][\\w.]*)*)\\s+on\\s+([A-Z]\\w*)$"),za=$("^released\\s+by\\s+([A-Z]\\w*)$"),Va=$(`^message\\s+"(${W})"$`),Qa=l(t=>t.kind==="FileConstraintSyntax"?void 0:t.event,"targetOf");function nr(t,e){let n=Ya.exec(e.content);n===null&&t.error(d.InvalidConstraintDeclaration,`Invalid constraint declaration '${e.content}' - expected 'constraint <Name>'`,c(e));let i=n?.[1]??R(e.content),r=[],o=[],a=new Set,s=new Set,p=null,f=!1;for(let m=t.peekChild(e.indent);m!==void 0;m=t.peekChild(e.indent)){t.reader.takeSignificant();let y=za.exec(m.content),u=Va.exec(m.content);y!==null?a.has(y[1])?t.error(d.DuplicateConstraintBody,`Constraint '${i}' already releases with event '${y[1]}'`,c(m)):(o.push(y[1]),a.add(y[1])):u!==null?p!==null?t.error(d.DuplicateConstraintBody,`Constraint '${i}' already has a message`,c(m)):p=U(u[1]):m.content==="ignore casing"?(f&&t.error(d.DuplicateConstraintBody,`Constraint '${i}' already ignores casing`,c(m)),f=!0):Ga(t,i,m,r,s)}for(let m of o.filter(y=>s.has(y)))t.error(d.DuplicateConstraintBody,`Constraint '${i}' cannot target and release event '${m}'`,c(e));return r.length===0&&(t.error(d.ConstraintWithoutRule,`Constraint '${i}' must declare 'unique ... on ...', 'unique event ...' or 'file ...'`,c(e)),r.push(Mt(i,c(e),{kind:"UniqueEventConstraintSyntax",event:""}))),r[0].kind==="FileConstraintSyntax"&&(o.length>0||p!==null||f)&&t.error(d.InvalidConstraintBody,`File constraint '${i}' cannot have declarative options`,c(e)),{...r[0],additionalRules:r.slice(1),releasedBy:o,message:p,ignoreCasing:f}}l(nr,"parseConstraint");function Ga(t,e,n,i,r){let o=Za(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(d.DuplicateConstraintBody,`Constraint '${e}' cannot mix constraint kinds`,c(n));return}let a=Qa(o);if(a!==void 0&&r.has(a)){t.error(d.DuplicateConstraintBody,`Constraint '${e}' already targets event '${a}'`,c(n));return}a!==void 0&&r.add(a),i.push(o)}l(Ga,"addRule");function Za(t,e,n){let i=c(n),r=Wa.exec(n.content);if(r!==null)return Mt(e,i,{kind:"UniqueEventConstraintSyntax",event:r[1]});let o=Ua.exec(n.content);if(o!==null){let a=o[1].split(",").map(s=>s.trim());if(new Set(a).size!==a.length){t.error(d.DuplicateConstraintBody,`Constraint '${e}' repeats a property in its composite key`,i);return}return Mt(e,i,{kind:"UniquePropertyConstraintSyntax",property:a[0],additionalProperties:a.slice(1),event:o[2]})}if(ee(n)){t.warning(d.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 Mt(e,i,{kind:"FileConstraintSyntax",file:{kind:"FileReferenceSyntax",path:a,location:i}})}t.error(d.InvalidConstraintBody,`Invalid constraint body '${n.content}'`,i)}l(Za,"parseRule");function Mt(t,e,n){return{...n,name:t,additionalRules:[],releasedBy:[],ignoreCasing:!1,message:null,location:e}}l(Mt,"rule");var _a=$("^projection\\s+(@?[\\w.]+)\\s*(?:=>\\s*([\\w.]+))?$"),Ka=$("^(@?[\\w.]+)(?:\\s+key\\s+(.+))?$"),Ja=$("^join\\s+(@?[\\w.]+)\\s+on\\s+(@?[\\w.]+)$"),Ha=$("^with\\s+(@?[\\w.]+)$"),Xa=$("^children\\s+(@?[\\w.]+)\\s+identified\\s+by\\s+(.+)$"),es=$("^nested\\s+(@?[\\w.]+)$"),ts=$("^remove\\s+with\\s+(@?[\\w.]+)(?:\\s+key\\s+(.+))?$"),ns=$("^remove\\s+via\\s+join\\s+on\\s+(@?[\\w.]+)(?:\\s+key\\s+(.+))?$"),is=$("^clear\\s+with\\s+(@?[\\w.]+)$"),rs=$("^variant\\s+(@?[\\w.]+)\\s*$"),os=$("^enters\\s+on\\s+(@?[\\w.]+)(?:\\s+key\\s+(.+))?$"),as=$("^(increment|decrement|count|clear)\\s+(@?[$\\w.]+)$"),ss=$("^(add|subtract)\\s+(@?[$\\w.]+)\\s+by\\s+(.+)$"),ls=$("^set\\s+(@?[$\\w.]+)\\s+(?:=|to)\\s+(.+)$"),ir=$("^(@?[$\\w.@]+)\\s*=(?!=|>)\\s*(.+)$"),cs={increment:"IncrementMappingSyntax",decrement:"DecrementMappingSyntax",clear:"ClearMappingSyntax",count:"CountMappingSyntax"};function In(t,e){let n=_a.exec(e.content);if(n===null)return t.error(d.InvalidProjectionDeclaration,`Invalid projection declaration '${e.content}' - expected 'projection <Name> [=> <ReadModel>]'`,c(e)),t.skipBlock(e.indent),{kind:"ProjectionSyntax",sourceOptions:t.sourceOptions,name:R(e.content),readModel:null,sequence:null,autoMap:"Inherit",blocks:[],location:c(e)};let i=n[1],r=null,o="Inherit",a=null,s=[];for(let p=t.peekChild(e.indent);p!==void 0;p=t.peekChild(e.indent)){if(t.reader.takeSignificant(),ee(p))continue;let f=R(p.content);if(f==="sequence")r=p.content.substring(8).trim();else if(f==="automap")o="Enabled";else if(p.content==="no automap")o="Disabled";else if(f==="key")a=or(t,p);else if(f==="variant")s.push(hs(t,p));else{let m=Rn(t,p,!1);m!==void 0&&s.push(m)}}return ds(t,s,i),s.length===0&&t.error(d.EmptyProjection,`Projection '${i}' must contain at least one directive`,c(e)),{kind:"ProjectionSyntax",sourceOptions:t.sourceOptions,name:i,readModel:n[2]??null,sequence:r,autoMap:o,key:a,blocks:s,location:c(e)}}l(In,"parseProjection");function ds(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(d.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(d.DuplicateVariantEnteringEvent,`Entering event '${a.event}' is claimed more than once in projection '${n}'`,a.location),o.add(a.event)}l(ds,"reportVariantConflicts");function Rn(t,e,n){let i=c(e);switch(R(e.content)){case"from":return ps(t,e);case"every":{let r=!0,{autoMap:o,mappings:a}=wn(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}=wn(t,e);return{kind:"AllSyntax",autoMap:r,mappings:o,location:i}}case"join":return fs(t,e);case"children":return us(t,e);case"nested":return ys(t,e);case"remove":return ms(t,e);case"clear":return n||t.error(d.ClearWithOutsideNestedBlock,"'clear with' is only valid inside a nested block",i),Ss(t,e);default:t.error(d.UnknownProjectionDirective,`Unexpected '${R(e.content)}' in projection body`,i),t.skipBlock(e.indent);return}}l(Rn,"parseBlock");function ps(t,e){let n=[];for(let a of bi(e.content.substring(4),",")){let s=a.trim();if(s.length===0){t.error(d.FromWithoutEvent,"Expected an event type after 'from'",c(e));continue}let p=Ka.exec(s);if(p===null){t.error(d.InvalidEventReference,`Invalid event reference '${s}'`,c(e));continue}n.push({kind:"EventSpecSyntax",event:Q(p[1]),key:p[2]===void 0?null:te(p[2],c(e),t),location:c(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=or(t,a):s==="parent"?o=te(a.content.substring(6),c(a),t):ar(t,a,i)}return{kind:"FromSyntax",events:n,key:r,parentKey:o,mappings:i,location:c(e)}}l(ps,"parseFrom");function fs(t,e){let n=Ja.exec(e.content);if(n===null)return t.error(d.InvalidJoinDeclaration,`Invalid join declaration '${e.content}' - expected 'join <property> on <key>'`,c(e)),t.skipBlock(e.indent),{kind:"JoinSyntax",property:"",on:"",events:[],location:c(e)};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(d.JoinWithoutEvent,`Expected 'with <EventType>' in join block, got '${r.content}'`,c(r)),t.skipBlock(r.indent);continue}let{autoMap:a,mappings:s}=wn(t,r);i.push({kind:"JoinEventSyntax",event:Q(o[1]),autoMap:a,mappings:s,location:c(r)})}return{kind:"JoinSyntax",property:Q(n[1]),on:Q(n[2]),events:i,location:c(e)}}l(fs,"parseJoin");function us(t,e){let n=Xa.exec(e.content);if(n===null)return t.error(d.InvalidChildrenDeclaration,`Invalid children declaration '${e.content}' - expected 'children <collection> identified by <key>'`,c(e)),t.skipBlock(e.indent),{kind:"ChildrenSyntax",property:"",autoMap:"Inherit",blocks:[],location:c(e)};let{autoMap:i,blocks:r}=rr(t,e);return{kind:"ChildrenSyntax",property:Q(n[1]),identifiedBy:te(n[2],c(e),t),autoMap:i,blocks:r,location:c(e)}}l(us,"parseChildren");function ys(t,e){let n=es.exec(e.content);if(n===null)return t.error(d.InvalidNestedDeclaration,`Invalid nested declaration '${e.content}' - expected 'nested <property>'`,c(e)),t.skipBlock(e.indent),{kind:"NestedSyntax",property:"",autoMap:"Inherit",blocks:[],location:c(e)};let i=Q(n[1]),{autoMap:r,blocks:o}=rr(t,e);return o.some(a=>a.kind==="FromSyntax")||t.error(d.NestedBlockWithoutFrom,`Nested block '${i}' must contain at least one 'from' directive`,c(e)),{kind:"NestedSyntax",property:i,autoMap:r,blocks:o,location:c(e)}}l(ys,"parseNested");function rr(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=Rn(t,r,!0);o!==void 0&&n.push(o)}return{autoMap:i,blocks:n}}l(rr,"parseChildBlocks");function ms(t,e){let n=ns.exec(e.content);if(n!==null)return{kind:"RemoveViaJoinSyntax",event:Q(n[1]),key:n[2]===void 0?null:te(n[2],c(e),t),location:c(e)};let i=ts.exec(e.content);if(i===null){t.error(d.InvalidRemoveDeclaration,`Invalid remove declaration '${e.content}' - expected 'remove with <EventType>' or 'remove via join on <EventType>'`,c(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=te(o.content.substring(6),c(o),t):t.error(d.UnknownRemoveDirective,`Unexpected '${o.content}' in remove block - only 'parent' is allowed`,c(o));return{kind:"RemoveWithSyntax",event:Q(i[1]),key:i[2]===void 0?null:te(i[2],c(e),t),parentKey:r,location:c(e)}}l(ms,"parseRemove");function Ss(t,e){let n=is.exec(e.content);return n===null?(t.error(d.InvalidClearDeclaration,`Invalid clear declaration '${e.content}' - expected 'clear with <EventType>'`,c(e)),{kind:"ClearWithSyntax",event:"",location:c(e)}):{kind:"ClearWithSyntax",event:Q(n[1]),location:c(e)}}l(Ss,"parseClearWith");function hs(t,e){let n=rs.exec(e.content);if(n===null)return t.error(d.InvalidProjectionVariantDeclaration,`Invalid variant declaration '${e.content}' - expected 'variant <Name>'`,c(e)),t.skipBlock(e.indent),{kind:"ProjectionVariantSyntax",name:R(e.content),entersOn:[],blocks:[],location:c(e)};let i=Q(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(gs(t,a));else if(s==="variant")t.error(d.NestedProjectionVariantNotAllowed,"A variant cannot be declared inside another variant",c(a)),t.skipBlock(a.indent);else{let p=Rn(t,a,!1);p!==void 0&&o.push(p)}}return r.length===0&&t.error(d.VariantRequiresEnteringEvent,`Variant '${i}' must declare at least one 'enters on' event`,c(e)),{kind:"ProjectionVariantSyntax",name:i,entersOn:r,blocks:o,location:c(e)}}l(hs,"parseVariant");function gs(t,e){let n=os.exec(e.content);return n===null?(t.error(d.InvalidEntersOnDeclaration,`Invalid 'enters on' declaration '${e.content}' - expected 'enters on <EventType> [key <expression>]'`,c(e)),t.skipBlock(e.indent),{kind:"ProjectionEntersOnSyntax",event:"",key:null,location:c(e)}):{kind:"ProjectionEntersOnSyntax",event:Q(n[1]),key:n[2]===void 0?null:te(n[2],c(e),t),location:c(e)}}l(gs,"parseEntersOn");function or(t,e){let n=e.content.substring(3).trim();if(t.peekChild(e.indent)===void 0)return{kind:"ExpressionKeySyntax",expression:te(n,c(e),t),location:c(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=ir.exec(o.content);if(a===null){t.sourceOptions.numericMode==="exact"&&t.error(d.InvalidCompositeKeyPart,`Invalid composite key part '${o.content}' - expected '<property> = <expression>'`,c(o));continue}let s=te(a[2],c(o),t);t.sourceOptions.numericMode==="exact"&&s.kind==="TemplateExpressionSyntax"&&t.error(d.TemplateInCompositeKey,"Template expressions are not allowed in composite keys",c(o)),i.push({kind:"KeyPartSyntax",property:Q(a[1]),expression:s,location:c(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(d.EmptyCompositeKey,"Composite keys must contain at least one part",c(e)),{kind:"CompositeKeySyntax",type:n.replace(/\{$/,"").trim(),parts:i,location:c(e)}}l(or,"parseKey");function wn(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)||ar(t,o,r);return{autoMap:i,mappings:r}}l(wn,"parseMappingBlock");function ar(t,e,n){let i=c(e),r=as.exec(e.content);if(r!==null){r[1]!=="clear"||r[2]!=="with"?n.push({kind:cs[r[1]],property:Q(r[2]),location:i}):t.sourceOptions.numericMode==="exact"&&t.error(d.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=ss.exec(e.content);if(o!==null){n.push({kind:o[1]==="add"?"AddMappingSyntax":"SubtractMappingSyntax",property:Q(o[2]),value:te(o[3],i,t),location:i});return}let a=ls.exec(e.content)??ir.exec(e.content);a!==null?n.push({kind:"SetMappingSyntax",property:Q(a[1]),source:te(a[2],i,t),location:i}):t.sourceOptions.numericMode==="exact"&&t.error(d.InvalidProjectionMapping,`Invalid mapping '${e.content}'`,i)}l(ar,"pushMapping");var xs=$("^query\\s+([A-Za-z_]\\w*)\\s*=>\\s*(observable\\s+)?([\\w.]+(?:\\[\\])?(?:\\?|\\s+optional)?)$"),$s=$("^([a-z_]\\w*)\\s+([\\w.]+(?:\\[\\])?(?:\\?|\\s+optional)?)(?:\\s+from\\s+(.+))?$"),vs=$("^scoped\\s+to\\s+([a-z_]\\w*)$"),ks=new Set(["performer"]);function lr(t,e){let n=xs.exec(e.content);if(n===null)return t.error(d.InvalidQueryDeclaration,`Invalid query declaration '${e.content}' - expected 'query <Name> => [observable] <ReadModel>'`,c(e)),t.skipBlock(e.indent),{kind:"QuerySyntax",name:R(e.content),returnType:fe("",c(e)),by:null,filters:[],description:null,isObservable:!1,scope:null,authorize:null,location:c(e)};let i=n[1],r=fe(n[3],{...c(e),column:e.indent+1+n[0].length-n[3].length});n[2]===void 0&&r.name==="observable"&&r.isOptional&&!r.isCollection||xe(t,r,e);let o=null,a=[],s=null,p=null,f=null;for(let m=t.peekChild(e.indent);m!==void 0;m=t.peekChild(e.indent)){t.reader.takeSignificant();let y=R(m.content);if(y==="description")s=G(t,m,s,`Query '${i}'`);else if(y==="by"){let u=sr(t,m,"by");u!==void 0&&(o!==null&&t.error(d.InvalidQueryParameter,`Query '${i}' already declares 'by' - a query can have at most one key parameter`,c(m)),o=u)}else if(y==="filter"){let u=sr(t,m,"filter");u!==void 0&&a.push(u)}else y==="authorize"?f=he(f,Ee(t,m)):y==="scoped"?p=bs(t,m,p,i)??p:ks.has(y)?t.skipOpaqueBlock(m.indent):(t.error(d.UnknownQueryDirective,`Unexpected '${m.content}' in query body - expected description, by, filter, authorize, scoped or performer`,c(m)),t.skipBlock(m.indent))}return{kind:"QuerySyntax",name:i,returnType:r,by:o,filters:a,description:s,isObservable:n[2]!==void 0,scope:p,authorize:f,location:c(e)}}l(lr,"parseQuery");function sr(t,e,n){let i=$s.exec(e.content.substring(n.length).trim());if(i===null){t.error(d.InvalidQueryParameter,`Invalid '${n}' parameter '${e.content}' - expected '${n} <name> <Type> [from <source>]'`,c(e));return}let r=e.content.indexOf(i[1],n.length),o=fe(i[2],{...c(e),column:e.indent+1+e.content.indexOf(i[2],r+i[1].length)});return xe(t,o,e),{kind:"QueryParameterSyntax",name:i[1],type:o,source:i[3]===void 0?null:H(i[3],c(e),t.valueContext),location:c(e)}}l(sr,"parseParameter");function bs(t,e,n,i){let r=vs.exec(e.content);if(r===null){t.error(d.InvalidScopeDeclaration,`Invalid scope declaration '${e.content}' - expected 'scoped to <scope>'`,c(e));return}if(n!==null){t.error(d.DuplicateScope,`Query '${i}' already declares a scope - results are narrowed one way`,c(e));return}return r[1]}l(bs,"parseScope");var Cs=$("^@?[a-z_]\\w*\\s+[\\w.]+");function Tn(t,e){let n=ge(t,e);if(n!==void 0){n.isGenerated&&t.error(d.GeneratedPropertyOutsideCommand,"Generated properties can only be declared on commands.",n.location),t.triggerData.push(n);return}Cs.test(e.content)&&/\?|\boptional\b/.test(e.content)&&t.error(d.InvalidTriggerData,`Invalid trigger value '${e.content}' - expected '<name>' or '<name> <Type>'`,c(e)),t.skipOpaqueBlock(e.indent)}l(Tn,"parseTriggerData");function cr(t,e){for(let n=t.peekChild(e.indent);n!==void 0;n=t.peekChild(e.indent))t.reader.takeSignificant(),R(n.content)==="description"?G(t,n,null,`Trigger '${e.content}'`):ee(n)||Tn(t,n)}l(cr,"parseTriggerDeclaration");var Es=$("^reaction\\s+([A-Za-z_]\\w*)$"),Ps=$("^when\\s+([A-Za-z_]\\w*)$"),Os=$("^every\\s+(\\d+)\\s+(seconds?|minutes?|hours?|days?)$"),As=$("^at\\s+(\\d{2}:\\d{2})(?:\\s+on\\s+(?:(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday)|day\\s+(\\d{1,2})))?$"),ws=new Set(["when","every","at"]),Is=$("^invokes\\s+([A-Z]\\w*)$"),Rs=Z("^(@?[\\w.]+)\\s*=(?!=|>)\\s*(.+)$"),Ts=$("^reads\\s+[A-Z]\\w*\\s+optional(?:\\s|$)");function dr(t,e){let n=Es.exec(e.content)?.[1]??"";n===""&&t.error(d.InvalidReactionDeclaration,`Invalid reaction declaration '${e.content}' - expected 'reaction <Name>'`,c(e));let i=null,r=null,o=[],a=new Set,s=!1;for(let p=t.peekChild(e.indent);p!==void 0;p=t.peekChild(e.indent)){t.reader.takeSignificant();let f=R(p.content);if(f==="description"){i=G(t,p,i,`Reaction '${n}'`);continue}if(f==="where"){r=We(t,p.content.substring(5).trim(),c(p));continue}if(!ws.has(f)){t.error(d.InvalidReactionTrigger,`Expected a trigger in reaction body, got '${p.content}' - a reaction is set off by 'when <Name>', 'every <n> <unit>' or 'at <HH:mm>'`,c(p)),t.skipBlock(p.indent),s=!0;continue}let m=js(t,p);if(m===void 0){s=!0;continue}let y=Ds(m);if(a.has(y)){t.error(d.DuplicateReactionTrigger,`Reaction '${n}' already declares '${p.content}' - a second says nothing the first did not`,c(p)),t.skipBlock(p.indent);continue}a.add(y),o.push(Ms(t,p,m))}return o.length===0&&!s&&t.error(d.ReactionWithoutTrigger,`Reaction '${n}' must declare at least one trigger - nothing sets it off`,c(e)),{kind:"ReactionSyntax",name:n,description:i,where:r,triggers:o,location:c(e)}}l(dr,"parseReaction");function Ms(t,e,n){let i=null,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==="description")i=G(t,a,i,`Trigger '${a.content}'`);else if(s==="produces"){let p=Rt(t,a);p!==void 0&&r.push(p)}else if(s==="invokes"){let p=Is.exec(a.content);if(p===null)t.error(d.InvalidInvokesDeclaration,`Invalid invokes declaration '${a.content}' - expected 'invokes <Command>'`,c(a)),t.skipBlock(a.indent);else{let f=new ue(t.reader.fork(),t.path,t.languages);f.scope=t.scope,f.sourceOptions=t.sourceOptions,pe(f,a),t.inputUses.push(...f.inputUses);let m=[];for(let y=t.peekChild(a.indent);y!==void 0;y=t.peekChild(a.indent)){t.reader.takeSignificant();let u=Rs.exec(y.content);u!==null?m.push({kind:"PropertyMappingSyntax",property:u[1].replaceAll("@",""),source:ae(u[2],c(y),t.valueContext),location:c(y)}):t.skipOpaqueBlock(y.indent)}o.push({kind:"InvokesSyntax",command:p[1],mappings:m,location:c(a)})}}else s==="reads"||s==="file"||a.content==="csharp"||a.content.startsWith("```")?(Ts.test(a.content)&&t.error(d.OptionalReadsNotSupported,"Optional reads are not yet supported (see #308).",c(a)),a.content.startsWith("```")&&t.skipFencedBody(),t.skipOpaqueBlock(a.indent)):Tn(t,a)}return{kind:"ReactionTriggerSyntax",source:n,description:i,produces:r,invokes:o,location:c(e)}}l(Ms,"parseTrigger");function Ds(t){switch(t.kind){case"NamedTriggerSourceSyntax":return JSON.stringify([t.kind,t.name]);case"IntervalTriggerSourceSyntax":return JSON.stringify([t.kind,t.amount,t.unit]);case"ScheduleTriggerSourceSyntax":return JSON.stringify([t.kind,t.time,t.dayOfWeek,t.dayOfMonth])}}l(Ds,"sourceKey");function js(t,e){let n=c(e);switch(R(e.content)){case"when":{let i=Ps.exec(e.content);if(i===null){t.error(d.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=Os.exec(e.content),r=i===null?NaN:Number(i[1]);if(i===null||!Number.isInteger(r)||r<1||r>2147483647){t.error(d.InvalidIntervalTrigger,`Invalid interval '${e.content}' - expected 'every <n> <seconds|minutes|hours|days>'`,n),t.skipBlock(e.indent);return}return{kind:"IntervalTriggerSourceSyntax",amount:r,unit:qs(i[2]),location:n}}default:return Ls(t,e)}}l(js,"parseTriggerSource");function Ls(t,e){let n=c(e),i=As.exec(e.content),r=i===null?void 0:Ns(i[1]);if(i===null||r===void 0){t.error(d.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(d.InvalidScheduleTrigger,`Invalid day of month '${o}' in '${e.content}' - a day of the month is between 1 and 31`,n),t.skipBlock(e.indent);return}return{kind:"ScheduleTriggerSourceSyntax",time:r,dayOfWeek:null,dayOfMonth:o,location:n}}return{kind:"ScheduleTriggerSourceSyntax",time:r,dayOfWeek:i[2]??null,dayOfMonth:null,location:n}}l(Ls,"parseSchedule");function Ns(t){let[e,n]=t.split(":").map(Number);if(e>=0&&e<=23&&n>=0&&n<=59)return`${t}:00.0000000`}l(Ns,"timeOf");function qs(t){switch(t.replace(/s+$/,"")){case"second":return"Seconds";case"minute":return"Minutes";case"hour":return"Hours";default:return"Days"}}l(qs,"unitOf");var Dt=`(?:"(${W})"|(\\$strings\\.\\w+(?:\\.\\w+)*))`,Bs=$("^screen\\s+([A-Za-z_]\\w*)$"),Fs=$("^data\\s+([\\w.]+(?:\\[\\])?)\\s+via\\s+query\\s+(\\w+(?:\\.\\w+)*)(?:\\s+by\\s+(\\w+))?$"),Ys=$("^action\\s+([A-Za-z_]\\w*(?:\\.\\w+)*)$"),Ws=$(`^label\\s+${Dt}$`),Us=$("^navigate\\s+to\\s+(\\w+(?:\\.\\w+)*)(?:\\s+by\\s+(\\w+))?$"),zs=$("^[a-z_]\\w*$"),Vs=$(`^title\\s+${Dt}$`),Qs=$(`^column\\s+([\\w.]+)(?:\\s+label\\s+${Dt})?$`),Gs=$("^on\\s+row-click\\s+(navigate\\s+to\\s+.+)$"),Zs=$(`^field\\s+([\\w.]+)\\s+label\\s+${Dt}$`),jt=l((t,e)=>t[e]!==void 0?U(t[e]):t[e+1],"operandText"),_s=l(t=>["on","uses"].includes(R(t.content)),"isInteraction"),Ks=l((t,e)=>e.content.startsWith("```")||t.languages.has(e.content),"isCodeLine");function pr(t,e){let n=Bs.exec(e.content);n===null&&t.error(d.InvalidScreenDeclaration,`Invalid screen declaration '${e.content}' - expected 'screen <Name>'`,c(e));let i=[];for(let r=t.peekChild(e.indent);r!==void 0;r=t.peekChild(e.indent))t.reader.takeSignificant(),ee(r)||fr(t,r,i);return{kind:"ScreenSyntax",name:n?.[1]??"",directives:i,location:c(e)}}l(pr,"parseScreen");function fr(t,e,n){let i=Js(t,e);i!==void 0&&n.push(i)}l(fr,"pushDirective");function ur(t,e){let n=[];for(let i=t.peekChild(e.indent);i!==void 0;i=t.peekChild(e.indent))t.reader.takeSignificant(),fr(t,i,n);return n}l(ur,"parseDirectives");function Js(t,e){switch(R(e.content)){case"data":return Hs(t,e);case"action":return Xs(t,e);case"template":return el(t,e);case"section":return tl(t,e);case"title":return nl(t,e);case"table":return il(t,e);case"summary":return rl(t,e);case"navigate":return Mn(t,e.content,e);case"on":return pe(t,e),{kind:"ScreenBehaviorSyntax",location:c(e)};case"uses":return t.skipOpaqueBlock(e.indent),{kind:"ScreenUsesBehaviorSyntax",location:c(e)};default:if(Ks(t,e))return ol(t,e);t.error(d.UnknownScreenDirective,`Unexpected '${e.content}' in screen body`,c(e)),t.skipBlock(e.indent);return}}l(Js,"parseDirective");function Hs(t,e){let n=Fs.exec(e.content);if(n===null){t.error(d.InvalidDataDirective,`Invalid data directive '${e.content}' - expected 'data <ReadModel> via query <Query> [by <param>]'`,c(e));return}return{kind:"ScreenDataSyntax",type:fe(n[1],c(e)),query:n[2],by:n[3]??null,location:c(e)}}l(Hs,"parseData");function Xs(t,e){let n=Ys.exec(e.content);if(n===null){t.error(d.InvalidActionDirective,`Invalid action directive '${e.content}' - expected 'action <Command>'`,c(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=Ws.exec(o.content);a!==null?i=jt(a,1):R(o.content)==="navigate"?r=Mn(t,o.content,o)??null:t.error(d.UnknownActionDirective,`Unexpected '${o.content}' in action - expected 'label "..."' or 'navigate to ...'`,c(o))}return{kind:"ScreenActionSyntax",command:n[1],label:i,navigate:r,location:c(e)}}l(Xs,"parseAction");function Mn(t,e,n){let i=Us.exec(e);if(i===null){t.error(d.InvalidNavigation,`Invalid navigation '${e}' - expected 'navigate to <Screen> [by <param>]'`,c(n));return}return{kind:"ScreenNavigateSyntax",screen:i[1],by:i[2]??null,location:c(n)}}l(Mn,"parseNavigate");function el(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(),!zs.test(r.content)){t.error(d.InvalidScreenLayoutSlot,`Expected a slot name in template '${n}', got '${r.content}'`,c(r)),t.skipBlock(r.indent);continue}i.push({kind:"ScreenSlotSyntax",name:r.content,directives:ur(t,r),location:c(r)})}return{kind:"ScreenTemplateReferenceSyntax",name:n,slots:i,location:c(e)}}l(el,"parseTemplateReference");function tl(t,e){return{kind:"ScreenSectionSyntax",name:e.content.substring(7).trim(),directives:ur(t,e),location:c(e)}}l(tl,"parseSection");function nl(t,e){let n=Vs.exec(e.content);return n===null?(t.error(d.InvalidTitleDirective,`Invalid title directive '${e.content}' - expected 'title "..."'`,c(e)),{kind:"ScreenTitleSyntax",text:"",location:c(e)}):{kind:"ScreenTitleSyntax",text:jt(n,1),location:c(e)}}l(nl,"parseTitle");function il(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=Qs.exec(o.content),s=Gs.exec(o.content);if(a!==null){let p=a[2]!==void 0||a[3]!==void 0;i.push({kind:"ScreenColumnSyntax",property:a[1],label:p?jt(a,2):null,location:c(o)})}else s!==null?r=Mn(t,s[1],o)??null:R(o.content)==="on"?pe(t,o):_s(o)?t.skipOpaqueBlock(o.indent):t.error(d.UnknownTableDirective,`Unexpected '${o.content}' in table - expected 'column ...', 'on row-click navigate to ...', 'on <trigger>' or 'uses <Behavior>'`,c(o))}return{kind:"ScreenTableSyntax",target:n,columns:i,rowClick:r,location:c(e)}}l(il,"parseTable");function rl(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=Zs.exec(r.content);if(o===null){t.error(d.UnknownSummaryDirective,`Unexpected '${r.content}' in summary - expected 'field <property> label "..."'`,c(r));continue}i.push({kind:"ScreenFieldSyntax",property:o[1],label:jt(o,2),location:c(r)})}return{kind:"ScreenSummarySyntax",target:n,fields:i,location:c(e)}}l(rl,"parseSummary");function ol(t,e){let n=e.content.startsWith("```")?e.content.substring(3):e.content;if(!t.languages.has(n)){t.error(d.ExpectedCodeFence,`Expected a registered language on the opening fence, not '${e.content}'`,c(e));return}e.content.startsWith("```")||t.warning(d.LegacyInlineCodeFence,`'${n}' on its own line is deprecated - use '\`\`\`${n}' instead`,c(e));let i=Be(t,n,e);return i===null?void 0:{kind:"ScreenCodeSyntax",code:{kind:"CodeBlockSyntax",language:n,code:i,location:c(e)},location:c(e)}}l(ol,"parseCode");var Dn=$("^then\\s+returns\\b"),yr=$("^generated\\s+(?=\\S)(?![=])"),mr=$("^generated\\s+([a-z_]\\w*)\\s*=(?!=|>)\\s*(.+)$"),al=$("^([\\w.]+)\\s*=(?!=|>)\\s*(.+)$"),sl=$(`^(?:"${W}"|'(?:[^'\\\\]|\\\\.)*')$`);function Sr(t,e,n,i){if((e.startsWith('"')||e.startsWith("'"))&&!sl.test(e))return t.error(i,"Expected exactly one concrete value.",n),null;let r=H(e,n,t);return!["LiteralExpressionSyntax","ObjectExpressionSyntax","ListExpressionSyntax"].includes(r.kind)||r.kind==="LiteralExpressionSyntax"&&typeof r.value=="number"&&!Number.isFinite(r.value)?(t.error(i,"Expected exactly one concrete literal or structured value, not an expression.",n),null):r}l(Sr,"parseConcrete");function Lt(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.",c(e)),t.skipBlock(e.indent),null;let o=c(e),a=Sr(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.",c(s)),t.skipBlock(e.indent)),a===null?null:{kind:"PropertyMappingSyntax",property:r[1],source:a,location:o}}l(Lt,"parseConcreteMapping");function hr(t,e){let n=Dn.exec(e.content)[0].length,i=e.content.substring(n).trim(),r=c(e);if(i.length>0){let a=Sr(t,i,{...r,column:r.column+e.content.indexOf(i,n)},d.InvalidReturnExpectation),s=t.peekChild(e.indent);return s!==void 0&&(t.error(d.InvalidReturnExpectation,"A scalar return expectation cannot have child assertions.",c(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=Lt(t,a,al,d.InvalidReturnExpectation);s!==null&&o.push(s)}return{kind:"RecordSpecificationReturnSyntax",fields:o,location:r}}l(hr,"parseReturn");var ll=$("^(?:given\\s+operation|then\\s+(?:operation|compensated))(?:\\s|$)"),cl=$("^(given operation|then operation|then compensated)\\s+([A-Za-z_]\\w*(?:\\.[A-Za-z_]\\w*)*)(\\s+fails)?$"),dl=$("^specification\\s+([A-Za-z_]\\w*)$"),pl=$("^given\\s+([A-Z]\\w*)$"),fl=$("^when\\s+append\\s+([A-Z]\\w*)$"),ul=$("^when\\s+([A-Z]\\w*)$"),yl=$("^then\\s+([A-Z]\\w*)$"),ml=$("^then\\s+query\\b"),gr=$("^(?:given|then)\\s+readmodel\\b"),Sl=$("^given\\s+readmodel\\s+([A-Z]\\w*)$"),hl=$("^then\\s+readmodel\\s+([A-Z]\\w*)(\\s+exactly)?$"),xr=$("^then\\s+no\\b"),gl=$(`^then\\s+error\\s+"(${W})"$`),Ln=$("^([\\w.]+)\\s*=(?!=|>)\\s*(.+)$"),xl=Z("^([\\w.]+)\\s*=(?!=|>)\\s*(.+)$"),$l=$("^given\\s+clock\\b"),vl=$("^given\\s+capture\\b"),kl=$("^when\\s+clock\\b"),bl=$("^when\\s+trigger\\b"),Cl=$("^when\\s+capture\\b"),El=$("^when\\s+query\\b"),Pl=$("^then\\s+result\\b"),Ol=$("^then\\s+no\\s+result\\b"),Al=$('^(given|when)\\s+clock\\s+"(\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(?::\\d{2}(?:\\.\\d+)?)?(?:Z|[+-]\\d{2}:\\d{2}))"$'),wl=$("^when\\s+trigger\\s+([A-Za-z_]\\w*)$"),Il=$("^(?:given|when)\\s+capture\\s+([A-Za-z_]\\w*)$"),Rl=$("^when\\s+query\\s+([A-Za-z_]\\w*(?:\\.\\w+)*)$"),Tl=$("^then\\s+result(\\s+exactly)?$"),$r=Z("^then\\s+no\\s+readmodel\\s+([A-Z]\\w*)\\s+for\\s+(.+)$"),Ml=Z(`^(?:"${W}"|'(?:[^'\\\\]|\\\\.)*')$`),Dl=Z("^then\\s+query\\s+([A-Za-z_]\\w*(?:\\.\\w+)*)(\\s+exactly)?$");function Nn(t,e){let n=dl.exec(e.content)?.[1]??"";n===""&&t.error(d.InvalidSpecificationDeclaration,`Invalid specification declaration '${e.content}' - expected 'specification <Name>'`,c(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(),ee(a)||jl(t,a,i))continue;let s=xr.test(a.content)?"then":R(a.content);s==="given"?Ll(t,a,i):s==="when"?Fl(t,a,i,n):s==="then"?Yl(t,a,i):(t.error(d.UnknownSpecificationDirective,`Unexpected '${R(a.content)}' in specification body`,c(a)),t.skipBlock(a.indent))}let{whenDeclared:r,...o}=i;return{kind:"SpecificationSyntax",sourceOptions:t.sourceOptions,name:n,...o,location:c(e)}}l(Nn,"parseSpecification");function jl(t,e,n){if(!ll.test(e.content))return!1;let i=cl.exec(e.content);if(i===null||i[1]==="given operation"!=(i[3]!==void 0))t.error(d.InvalidOperationSpecification,"Expected 'given operation <Name> fails', 'then operation <Name>' or 'then compensated <Name>'.",c(e)),ne(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=Lt(t,o,Ln,d.InvalidOperationSpecification);a!==null&&r.push(a)}n.thenOperations.push({kind:"SpecificationOperationSyntax",operation:i[2],values:r,location:c(e)})}else ct(t,e,d.InvalidOperationSpecification,"Failure and compensation assertions cannot have children."),i[1]==="given operation"?n.givenOperationFailures.push({kind:"SpecificationOperationFailureSyntax",operation:i[2],location:c(e)}):n.thenCompensated.push({kind:"SpecificationCompensatedSyntax",operation:i[2],location:c(e)});return!0}l(jl,"parseOperationStep");function Ll(t,e,n){if($l.test(e.content))n.givenClock!==null?(t.error(d.InvalidSpecificationClock,"A specification states its clock at most once.",c(e)),ne(t,e.indent)):n.givenClock=vr(t,e,"given");else if(vl.test(e.content)){let i=kr(t,e,"given");i!==null&&n.givenCaptures.push(i)}else if(e.content.startsWith("given caller"))n.givenCaller!==null?(t.error(d.DuplicateSpecificationCallerOrDenied,"A specification has at most one 'given caller' block.",c(e)),t.skipBlock(e.indent)):n.givenCaller=Bl(t,e);else if(gr.test(e.content)){let i=br(t,e,Sl,"given");i!==void 0&&n.givenReadModels.push(i)}else{let i=qn(t,e,pl,"given");i!==void 0&&n.given.push(i)}}l(Ll,"parseGiven");var Nl=$(`^role${nt}+"(${W})"$`),ql=$(`^claim${nt}+"(${W})"${nt}*=${nt}*"(${W})"$`);function Bl(t,e){if(e.content!=="given caller")return t.error(d.InvalidSpecificationCaller,"Expected exactly 'given caller'.",c(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=Nl.exec(o.content),s=ql.exec(o.content);o.content==="authenticated"&&!n?n=!0:a!==null?i.push(U(a[1])):s!==null?r.push({kind:"SpecificationCallerClaimSyntax",type:U(s[1]),value:U(s[2]),location:c(o)}):t.error(d.InvalidSpecificationCaller,`Invalid caller fixture '${o.content}' - expected authenticated, role "...", or claim "..." = "...".`,c(o))}return{kind:"SpecificationCallerSyntax",authenticated:n,roles:i,claims:r,location:c(e)}}l(Bl,"parseCaller");function Fl(t,e,n,i){let r=e.content.startsWith("when append");if(n.whenDeclared){let p=n.whenAppended!==null||r?d.ConflictingSpecificationActions:d.DuplicateSpecificationWhen;t.error(p,`Specification '${i}' already declares a 'when' - a specification can have at most one`,c(e)),ne(t,e.indent);return}if(n.whenDeclared=!0,r){n.whenAppended=qn(t,e,fl,"when append")??null;return}if(kl.test(e.content)){n.whenClock=vr(t,e,"when");return}if(bl.test(e.content)){n.whenTrigger=jn(t,e,wl,d.InvalidSpecificationTrigger,"when trigger","when trigger <Trigger>",(p,f)=>({kind:"SpecificationTriggerSyntax",trigger:p,values:f,location:c(e)}));return}if(Cl.test(e.content)){n.whenCapture=kr(t,e,"when");return}if(El.test(e.content)){n.whenQuery=jn(t,e,Rl,d.InvalidSpecificationQueryAction,"when query","when query <Query>",(p,f)=>({kind:"SpecificationWhenQuerySyntax",query:p,arguments:f,location:c(e)}));return}let o=ul.exec(e.content);if(o===null){t.error(d.InvalidSpecificationWhen,`Invalid 'when' declaration '${e.content}' - expected 'when <CommandType>' or 'when append <EventType>'`,c(e)),ne(t,e.indent);return}let a=[],s=Cr(t,e,a);n.when={kind:"SpecificationCommandSyntax",commandType:o[1],...s,generatedValues:a,location:c(e)}}l(Fl,"parseWhen");function Yl(t,e,n){if(Dn.test(e.content)){let o=hr(t,e);n.thenReturns!==null?t.error(d.InvalidReturnExpectation,"A specification declares at most one return expectation.",c(e)):n.thenReturns=o;return}if(e.content.startsWith("then events")){e.content!=="then events in any order"||n.thenEventsInAnyOrder?t.error(d.InvalidSpecificationEventOrder,"Expected one 'then events in any order' directive.",c(e)):n.thenEventsInAnyOrder=!0,ne(t,e.indent);return}if(Pl.test(e.content)){Ul(t,e,n);return}if(Ol.test(e.content)){e.content!=="then no result"||n.thenNoResult!==null?t.error(d.InvalidSpecificationQueryAction,"Expected one 'then no result' directive.",c(e)):n.thenNoResult={kind:"SpecificationNoResultSyntax",location:c(e)},ne(t,e.indent);return}if(e.content.startsWith("then denied")){e.content!=="then denied"?(t.error(d.InvalidSpecificationDenied,"Expected exactly 'then denied'.",c(e)),ne(t,e.indent)):n.thenDenied!==null?t.error(d.DuplicateSpecificationCallerOrDenied,"A specification has at most one 'then denied' outcome.",c(e)):n.thenDenied={kind:"SpecificationDeniedSyntax",location:c(e)};return}if(e.content==="then error"){n.thenErrors.push({kind:"SpecificationErrorSyntax",name:null,location:c(e)});return}let i=gl.exec(e.content);if(i!==null){n.thenErrors.push({kind:"SpecificationErrorSyntax",name:U(i[1]),location:c(e)});return}if(R(e.content.substring(4).trim())==="error"){t.error(d.InvalidThenError,`Invalid 'then error' declaration '${e.content}' - expected 'then error' or 'then error "<reason>"'`,c(e)),ne(t,e.indent);return}if(xr.test(e.content)){if(t.sourceOptions.numericMode==="exact"){let a=Wl(t,e);a!==null&&n.thenAbsentReadModels.push(a);return}let o=$r.exec(e.content);if(o!==null&&!o[2].endsWith(" exactly")){let a=H(o[2].trim(),c(e),t.valueContext);(a.kind==="LiteralExpressionSyntax"||a.kind==="ObjectExpressionSyntax")&&n.thenAbsentReadModels.push({kind:"SpecificationAbsentReadModelSyntax",name:o[1],key:a,location:c(e)})}t.skipOpaqueBlock(e.indent);return}if(ml.test(e.content)){let o=t.sourceOptions.numericMode==="exact",a=l((y,u,S)=>{if(!o)return t.skipOpaqueBlock(S.indent);t.error(y,u,c(S)),t.skipBlock(S.indent)},"reject"),s=Dl.exec(e.content);if(s===null)return a(d.InvalidSpecificationQuery,`Invalid 'then query' declaration '${e.content}' - expected 'then query <Query> [exactly]'`,e);let p=[],f=[],m=!1;for(let y=t.peekChild(e.indent);y!==void 0;y=t.peekChild(e.indent))t.reader.takeSignificant(),y.content==="arguments"&&!m?p.push(...dt(t.valueContext,y,!0)):y.content==="arguments"?a(d.DuplicateSpecificationQueryArguments,`Query assertion '${s[1]}' already declares arguments`,y):y.content==="result"?f.push({kind:"SpecificationQueryResultSyntax",properties:dt(t.valueContext,y,!0),exactly:!1,location:c(y)}):a(d.UnknownSpecificationQueryDirective,`Unexpected '${R(y.content)}' in 'then query' body - expected arguments or result`,y),m||=y.content==="arguments";n.thenQueries.push({kind:"SpecificationQuerySyntax",query:s[1],arguments:p,results:f,exactly:s[2]!==void 0,location:c(e)});return}if(gr.test(e.content)){let o=br(t,e,hl,"then");o!==void 0&&n.thenReadModels.push(o);return}let r=qn(t,e,yl,"then");r!==void 0&&n.thenEvents.push(r)}l(Yl,"parseThen");function Wl(t,e){let n=$r.exec(e.content);if(n===null||n[2].endsWith(" exactly"))return t.error(d.InvalidAbsentReadModelStep,`Invalid absence assertion '${e.content}' - expected 'then no readmodel <ReadModelType> for <key>'`,c(e)),ne(t,e.indent),null;let i=n[2].trim(),o=!(i.startsWith('"')||i.startsWith("'"))||Ml.test(i)?H(i,c(e),t.valueContext):null,a=o!==null&&(o.kind==="LiteralExpressionSyntax"||o.kind==="ObjectExpressionSyntax");a||t.error(d.InvalidAbsentReadModelStep,`Invalid absence key '${i}' - expected exactly one concrete value.`,c(e));let s=!1;for(let p=t.peekChild(e.indent);p!==void 0;p=t.peekChild(e.indent))t.reader.takeSignificant(),t.error(d.InvalidAbsentReadModelStep,"An absent read model assertion cannot have child mappings.",c(p)),s=!0;return s||!a?null:{kind:"SpecificationAbsentReadModelSyntax",name:n[1],key:o,location:c(e)}}l(Wl,"parseAbsentReadModel");function ne(t,e){if(t.sourceOptions.numericMode!=="exact")return t.skipBlock(e);t.skipOpaqueBlock(e)}l(ne,"skipBody");function vr(t,e,n){let i=Al.exec(e.content);return ne(t,e.indent),i===null||i[1]!==n?(t.error(d.InvalidSpecificationClock,`Invalid '${n} clock' - expected '${n} clock "<ISO 8601 instant>"', such as '${n} clock "2026-10-05T08:00:00Z"'`,c(e)),null):{kind:"SpecificationClockSyntax",instant:i[2],location:c(e)}}l(vr,"parseClock");function kr(t,e,n){return jn(t,e,Il,d.InvalidSpecificationCapture,`${n} capture`,`${n} capture <Capture>`,(i,r)=>({kind:"SpecificationCaptureSyntax",capture:i,record:r,location:c(e)}))}l(kr,"parseCapture");function jn(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}'`,c(e)),ne(t,e.indent),null):a(s[1],dt(t,e))}l(jn,"parseNamedStep");function Ul(t,e,n){let i=Tl.exec(e.content);if(i===null){t.error(d.InvalidSpecificationQueryAction,`Invalid 'then result' declaration '${e.content}' - expected 'then result [exactly]'`,c(e)),ne(t,e.indent);return}n.thenResults.push({kind:"SpecificationQueryResultSyntax",properties:dt(t,e),exactly:i[1]!==void 0,location:c(e)})}l(Ul,"parseResult");function br(t,e,n,i){let r=n.exec(e.content);if(r===null){t.error(d.InvalidReadModelStep,`Invalid '${i} readmodel' declaration '${e.content}' - expected '${i} readmodel <ReadModelType>'`,c(e)),ne(t,e.indent);return}return{kind:"SpecificationReadModelSyntax",name:r[1],properties:dt(t,e),exactly:i==="then"&&r[2]!==void 0,location:c(e)}}l(br,"parseReadModelStep");function qn(t,e,n,i){let r=n.exec(e.content);if(r===null){t.error(d.InvalidEventStep,`Invalid '${i}' declaration '${e.content}' - expected '${i} <EventType>'`,c(e)),ne(t,e.indent);return}return{kind:"SpecificationEventSyntax",eventType:r[1],...Cr(t,e),location:c(e)}}l(qn,"parseEventStep");function Cr(t,e,n){let i=[],r=null;for(let o=t.peekChild(e.indent);o!==void 0;o=t.peekChild(e.indent)){if(t.reader.takeSignificant(),n!==void 0&&yr.test(o.content)){let s=Lt(t,o,mr,d.InvalidGeneratedFixture);s!==null&&n.push(s);continue}let a=Ln.exec(o.content);if(a!==null)i.push(Er(t,o,a));else if(R(o.content)==="for"){let s=o.content.substring(3).trim();s.length===0?t.error(d.InvalidSpecificationEventSource,"Invalid event-source assertion 'for' - expected 'for <value>'",c(o)):r!==null?t.error(d.DuplicateSpecificationEventSource,"A specification step can declare its event-source assertion only once",c(o)):r=H(s,c(o),t)}else t.error(d.InvalidSpecificationValue,`Invalid property mapping '${o.content}' - expected '<property> = <value>'`,c(o))}return{values:i,for:r}}l(Cr,"parseValuesWithEventSource");function dt(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"?xl:Ln).exec(r.content);if(o===null){t.error(d.InvalidSpecificationValue,`Invalid property mapping '${r.content}' - expected '<property> = <value>'`,c(r));continue}i.push(Er(t,r,o,n))}return i}l(dt,"parseValues");function Er(t,e,n,i=!1){return{kind:"PropertyMappingSyntax",property:n[1],source:H(n[2],c(e),t,i),location:c(e)}}l(Er,"mappingOf");var zl=$("^slice\\s+([A-Za-z]\\w*)\\s+([A-Za-z_]\\w*)$"),Vl=new Set(["reducer"]);function Pr(t,e){let n=zl.exec(e.content),i="StateChange",r="";n===null?t.error(d.InvalidSliceDeclaration,`Invalid slice declaration '${e.content}' - expected 'slice <Type> <Name>'`,c(e)):(r=n[2],Ci.includes(n[1])?i=n[1]:t.error(d.UnknownSliceType,`Unknown slice type '${n[1]}' - expected StateChange, StateView, Automation or Translate`,c(e)));let o=t.scope;t.scope=[...o,r];let a=null,s=[],p=[],f=[],m=[],y=[],u=[],S=[],b=[],v=[],x=[],g=[];for(let k=t.peekChild(e.indent);k!==void 0;k=t.peekChild(e.indent)){if(t.reader.takeSignificant(),ee(k))continue;let E=R(k.content);E==="description"?a=G(t,k,a,`Slice '${r}'`):E==="operation"?p.push(It(t,k).operation):E==="event"?s.push(Di(t,k)):E==="command"?f.push(tr(t,k)):E==="query"?m.push(lr(t,k)):E==="projection"?y.push(In(t,k)):E==="capture"?S.push($n(t,k)):E==="reaction"?u.push(dr(t,k)):E==="constraint"?b.push(nr(t,k)):E==="specification"?v.push(Nn(t,k)):E==="readmodel"?x.push(ji(t,k)):E==="screen"?g.push(pr(t,k)):Vl.has(E)?t.skipOpaqueBlock(k.indent):(t.warning(d.UnknownSliceDirective,`Unknown construct '${E}' in slice '${r}'`,c(k)),t.skipBlock(k.indent))}return t.scope=o,{kind:"SliceSyntax",type:i,name:r,description:a,events:s,operations:p,commands:f,queries:m,projections:y,captures:S,reactions:u,constraints:b,specifications:v,readModels:x,screens:g,location:c(e)}}l(Pr,"parseSlice");var Ql=$("^feature\\s+([A-Za-z_]\\w*)$"),Gl=new Set(["on","uses","contribute"]),Bn="description, authorize, import, feature, slice, contribute, 'on <trigger>' or 'uses <Behavior>'",pt=class{static{l(this,"FeatureBody")}name;#e=[];#t=[];#i=[];#n=null;#r=null;constructor(e){this.name=e}tryParse(e,n){let i=R(n.content);switch(i){case"description":return this.#n=G(e,n,this.#n,`Feature '${this.name}'`),!0;case"authorize":return this.#r=he(this.#r,Ee(e,n)),!0;case"import":return Fe(e,n,this.#i),!0;case"feature":return this.#e.push(Nt(e,n)),!0;case"slice":return this.#t.push(Pr(e,n)),!0;default:return Gl.has(i)?(pe(e,n),!0):!1}}build(e,n=!1){return{kind:"FeatureSyntax",name:this.name,description:this.#n,authorize:this.#r,features:this.#e,slices:this.#t,fileImports:this.#i,isPlacement:n,location:e}}};function Nt(t,e){let n=Ql.exec(e.content)?.[1]??"";n===""&&t.error(d.InvalidFeatureDeclaration,`Invalid feature declaration '${e.content}' - expected 'feature <Name>'`,c(e));let i=new pt(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(d.UnknownFeatureDirective,`Unexpected '${R(o.content)}' in feature body - expected ${Bn}`,c(o)),t.skipBlock(o.indent));return t.scope=r,i.build(c(e))}l(Nt,"parseFeature");var Fn=$("^module\\s+([A-Za-z_]\\w*)$"),Zl=new Set(["on","uses","screen","dialog","form","contribute"]),Yn="description, authorize, import, screen template, dialog template, form, contribute, feature, 'on <trigger>' or 'uses <Behavior>'",ft=class{static{l(this,"ModuleBody")}name;#e=[];#t=[];#i=null;#n=null;constructor(e){this.name=e}tryParse(e,n){let i=R(n.content);switch(i){case"description":return this.#i=G(e,n,this.#i,`Module '${this.name}'`),!0;case"authorize":return this.#n=he(this.#n,Ee(e,n)),!0;case"import":return Fe(e,n,this.#t),!0;case"feature":return this.#e.push(Nt(e,n)),!0;default:return Zl.has(i)?(pe(e,n),!0):!1}}parseChildren(e,n){for(let i=e.peekChild(n.indent);i!==void 0;i=e.peekChild(n.indent))e.reader.takeSignificant(),this.tryParse(e,i)||(e.error(d.UnknownModuleDirective,`Unexpected '${R(i.content)}' in module body - expected ${Yn}`,c(i)),e.skipBlock(i.indent))}build(e,n=!1){return{kind:"ModuleSyntax",name:this.name,description:this.#i,authorize:this.#n,features:this.#e,fileImports:this.#t,isPlacement:n,location:e}}};function Wn(t,e){let n=Fn.exec(e.content)?.[1]??"";n===""&&t.error(d.InvalidModuleDeclaration,`Invalid module declaration '${e.content}' - expected 'module <Name>'`,c(e));let i=new ft(n),r=t.scope;return t.scope=[n],i.parseChildren(t,e),t.scope=r,i.build(c(e))}l(Wn,"parseModule");var Un=class extends Error{static{l(this,"InvalidExactNumber")}};function _l(t){if(t.literalType!=="ExactNumber"||typeof t.value!="string"||ve(t.value)?.value!==t.value)throw new Un("Expected a canonical, bounded ExactNumber value.");return t.value}l(_l,"canonicalExactText");function Or(t){return!_l(t).includes(".")}l(Or,"exactIsIntegral");var Kl=/^([0-9]{4})-([0-9]{2})-([0-9]{2})$/,Jl=/^([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 zn(t,e){let n=(e?Jl:Kl).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 p=Number(n[7]),f=Number(n[8]);return p<=14&&f<=59&&(p!==14||f===0)}l(zn,"responseDateValue");var qt=new Set(["Uuid","String","Int","Decimal","Bool","Date","DateTime"]);function Bt(t,e,n=e.inputUses){let i=[],r=l((P,h)=>{let C=[...h,P.name];P.slices.forEach(A=>i.push({slice:A,scope:[...C,A.name]})),P.features.forEach(A=>r(A,C))},"collect");t.modules.forEach(P=>P.features.forEach(h=>r(h,[P.name])));let o=new Map,a=new Map,s=new Map;for(let{slice:P,scope:h}of i)for(let C of P.commands){let A=o.get(C.name)??[];A.push({command:C,scope:h}),o.set(C.name,A),a.set(C,re(C.properties)),C.response?.kind==="RecordCommandResponseSyntax"&&s.set(C,re(C.response.fields))}let p=new Map;for(let P of t.imports){let h=P.qualifiedName.split(".").at(-1);p.set(h,[...p.get(h)??[],P.qualifiedName])}let f=new Map,m=l((P,h)=>{let C=`${h.join(".")}|${P}`;if(f.has(C))return f.get(C);let A=p.get(P)??[],q=((o.get(P.split(".").at(-1))??[]).length===0&&A.length===1?A[0]:P).split("."),B=o.get(q.at(-1))??[];if(q.length>1){let j=q.slice(0,-1);B=B.filter(N=>j.length<=N.scope.length&&j.every((F,V)=>N.scope[N.scope.length-j.length+V]===F))}else for(let j=h.length;j>=0;j--){let N=B.filter(F=>j<=F.scope.length&&h.slice(0,j).every((V,X)=>F.scope[X]===V));if(N.length>0){B=N;break}}let M=B.length===1?B[0].command:null;return f.set(C,M),M},"resolve"),y=re(t.concepts),u=new Set(t.concepts.map(P=>P.name)),S=new Map([...re(t.types)].map(([P,h])=>[P,re(h.properties)])),b=new Set(i.flatMap(P=>P.slice.readModels.map(h=>h.name))),v=new Set([...a.keys()].flatMap(P=>[...P.properties])),x=l(P=>{for(let h of P)h.isGenerated&&!v.has(h)&&e.error(d.GeneratedPropertyOutsideCommand,"Generated properties can only be declared on commands.",h.location)},"checkDeclarations"),g=l(P=>{P.features.forEach(g);for(let h of P.slices){for(let C of h.commands)for(let A of C.produces)A.inlineEvent!==null&&x(A.inlineEvent.properties);h.events.forEach(C=>x(C.properties)),h.readModels.forEach(C=>x(C.properties));for(let C of h.reactions)for(let A of C.triggers)for(let w of A.produces)w.inlineEvent!==null&&x(w.inlineEvent.properties)}},"checkFeature");t.types.forEach(P=>x(P.properties)),t.modules.forEach(P=>P.features.forEach(g));let k=l((P,h,C)=>{let A=a.get(C).get(P.property);if(A===void 0){e.error(d.InvalidResponseSource,`Response source '${P.property}' must reference one direct command property.`,P.location);return}let w=A.type;(w.isCollection||b.has(w.name))&&e.error(d.InvalidResponseShape,"Collection and whole-read-model responses are not supported.",P.location),h!==null&&(h.name!==w.name||h.isCollection!==w.isCollection||h.isOptional!==w.isOptional)&&e.error(d.InvalidResponseShape,"An explicit response field type must match its source's declared type, collection shape and optionality.",h.location)},"validateSource");for(let P of a.keys()){for(let C of P.properties){if(!C.isGenerated)continue;let A=y.get(C.type.name);(C.type.isOptional||C.type.isCollection||(A===void 0?qt.has(C.type.name)||S.has(C.type.name)||u.has(C.type.name)||b.has(C.type.name):A.type!=="Uuid"))&&e.error(d.InvalidGeneratedType,"A generated property must be a required, noncollection concept backed by Uuid.",C.location)}let h=P.response;if(h?.kind==="ScalarCommandResponseSyntax")k(h.source,null,P);else if(h?.kind==="RecordCommandResponseSyntax"){h.fields.length===0&&e.error(d.InvalidCommandResponse,"A response block requires at least one field.",h.location);let C=new Set;for(let A of h.fields)C.has(A.name)&&e.error(d.DuplicateResponseField,`Duplicate response field '${A.name}'.`,A.location),C.add(A.name),k(A.source,A.type,P)}}let E=l((P,h)=>{let C=P.when,A=C===null?null:m(C.commandType,h);if(C!==null&&A!==null){let B=a.get(A);for(let N of C.values)B.get(N.property.split(".")[0])?.isGenerated&&e.error(d.GeneratedPropertySuppliedAsInput,`Generated property '${N.property}' cannot be supplied as request or form input.`,N.location);let M=[...B.values()].filter(N=>N.isIdentifier);if(C.for!==null&&M.length===1&&M[0].isGenerated){let N=M[0].type;(qt.has(N.name)||y.has(N.name)||S.has(N.name))&&(N.isOptional||N.isCollection||y.get(N.name)?.type!=="Uuid"||C.for.kind!=="LiteralExpressionSyntax"||typeof C.for.value!="string"||!Ar(C.for.value))&&e.error(d.InvalidGeneratedFixture,"A generated identifier fixture must supply one compatible concrete UUID value through 'for'.",C.for.location)}let j=new Set;for(let N of C.generatedValues??[]){let F=B.get(N.property);(j.has(N.property)||F===void 0||!F.isGenerated||F.isIdentifier||!ke(N.source,F.type,y,S))&&e.error(d.InvalidGeneratedFixture,"A generated fixture must uniquely supply a compatible value for a nonidentifier generated command property.",N.location),j.add(N.property)}}let w=P.thenReturns;if(w==null||((C===null||P.thenErrors.length>0||P.thenDenied!=null)&&e.error(d.InvalidReturnExpectation,"A return expectation requires a command action and cannot accompany an error or denial.",w.location),A===null))return;let I=A.response,q=a.get(A);if(w.kind==="ScalarSpecificationReturnSyntax"&&I?.kind==="ScalarCommandResponseSyntax"&&q.has(I.source.property))ke(w.value,q.get(I.source.property).type,y,S)||e.error(d.InvalidReturnExpectation,"The expected return value must match the response source's type.",w.location);else if(w.kind==="RecordSpecificationReturnSyntax"&&I?.kind==="RecordCommandResponseSyntax"){w.fields.length===0&&e.error(d.InvalidReturnExpectation,"A record return expectation requires at least one field.",w.location);let B=s.get(A),M=new Set;for(let j of w.fields){let N=B.get(j.property),F=N===void 0?void 0:q.get(N.source.property);(M.has(j.property)||F===void 0||!ke(j.source,F.type,y,S))&&e.error(d.InvalidReturnExpectation,"A return assertion must uniquely name a response field and supply a compatible concrete value.",j.location),M.add(j.property)}}else e.error(d.InvalidReturnExpectation,"The return expectation must match the command's scalar or record response shape.",w.location)},"validateSpecification");for(let{slice:P,scope:h}of i)P.specifications.forEach(C=>E(C,h));for(let P of n){if(P.isParameter===!0)continue;let h=m(P.command,P.scope);h!==null&&a.get(h).get(P.property.split(".")[0])?.isGenerated&&e.error(d.GeneratedPropertySuppliedAsInput,`Generated property '${P.property}' cannot be supplied as request or form input.`,P.location)}}l(Bt,"validateResponses");function re(t){let e=new Map,n=new Set;for(let i of t)e.has(i.name)&&n.add(i.name),e.set(i.name,i);return n.forEach(i=>e.delete(i)),e}l(re,"uniqueByName");function ke(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=>ke(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 p=r.get(s.name);return p!==void 0&&ke(s.value,p.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"&&Ar(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&&Or(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"&&zn(t.value,!1);case"DateTime":return typeof t.value=="string"&&zn(t.value,!0);default:return!qt.has(a)}return!qt.has(a)&&o===void 0}l(ke,"compatibleValue");var Hl=/^(?:[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 Ar(t){return Hl.test(t)}l(Ar,"uuidValue");var Me=class t{static{l(this,"LineReader")}lines;#e=0;constructor(e){this.lines=e}get atEnd(){return this.lines.slice(this.#e).every(mn)}fork(){let e=new t(this.lines);return e.#e=this.#e,e}peekSignificant(){for(;this.#e<this.lines.length&&mn(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 Ft(t,e,n,i=!1){let r=[],o=[],a=ce,s=!1,p=!1,f=!1,m=new Map,y=new ue(new Me([]),e,n).languages;for(let S of t){let b=S;if(b.number===1&&b.raw.startsWith("\uFEFF")){let v=b.raw.substring(1),x=v.length-v.trimStart().length,g=et(v.substring(x),i);b={...b,indent:x,contentOffset:1,content:(g<0?v.substring(x):v.substring(x,x+g)).trimEnd()}}if(f){Pn(b)&&(f=!1),r.push(b);continue}if(b.content.startsWith("```")&&(["```","```text","```markdown"].includes(b.content)||y.has(b.content.substring(3)))&&(f=!0),!f&&b.indent===0&&R(b.content)==="numbers"){let v=b.content!=="numbers exact"?d.InvalidNumericDirective:s?d.DuplicateNumericDirective:p?d.LateNumericDirective:void 0;v!==void 0?(o.push({severity:"error",code:v,message:"Expected one 'numbers exact' preamble before domain, imports and declarations.",location:c(b)}),a=Object.freeze({numericMode:"invalid"})):a=At,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:d.InvalidNumericDirective,message:"Expected 'numbers exact' only as the document preamble, not inside a body.",location:c(b)}),p||=b.content.trim().length>0,r.push(b)}let u=new ue(new Me(s?r:t),e,n);return u.sourceOptions=a,u.nestedNumericDirectives=m,o.forEach(S=>u.error(S.code,S.message,S.location)),u}l(Ft,"sourceContext");function Oe(t){return[...t.events,...t.commands.flatMap(e=>e.produces).flatMap(e=>e.inlineEvent===null?[]:[e.inlineEvent])]}l(Oe,"eventDeclarations");function Yt(t){return[...t.operations??[],...t.commands.flatMap(e=>e.produces).flatMap(e=>e.inlineOperation==null?[]:[e.inlineOperation])]}l(Yt,"operationDeclarations");var _;(function(t){t.Event="event",t.Operation="operation",t.Unresolved="unresolved",t.Ambiguous="ambiguous"})(_||(_={}));var $e=class{static{l(this,"AuthoringProductionResolver")}declarations=[];slices=[];byName=new Map;scopes=new Map;resolutions=new Map;constructor(e){let n=l((i,r)=>{for(let o of i){let 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 Oe(i)){let p=o.get(s.name)??[];p.push(s),o.set(s.name,p)}let a=[...o.values()].flatMap(s=>new Set(s.map(p=>p.generation)).size!==s.length?s:[s.reduce((p,f)=>p.generation>=f.generation?p:f)]);this.declarations.push(...a.map(s=>({kind:_.Event,name:s.name,node:s,scope:r})),...Yt(i).map(s=>({kind:_.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:_.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?_.Unresolved:_.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===_.Operation}isEventProduction(e,n){if(e.inlineOperation!=null)return!1;let i=this.resolve(e.event,n);return i.kind!==_.Operation&&!(i.kind===_.Ambiguous&&i.candidates.some(r=>r.kind===_.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,p)=>a.scope[a.scope.length-o.length+p]===s));for(let a=n.length;a>=0;a--){let s=r.filter(p=>a<=p.scope.length&&n.slice(0,a).every((f,m)=>p.scope[m]===f));if(s.length>0)return s}return[]}};function Xl(t,e){return t.produces.filter(n=>n.inlineOperation==null&&(e===void 0||e.resolver.isEventProduction(n,e.slice)))}l(Xl,"eventProductions");function wr(t,e){let n=Xl(t,e),i=t.properties.find(r=>r.isIdentifier)?.name;return n.some(r=>r.for!==null&&(r.for.kind!=="PathExpressionSyntax"||r.for.path!==i))||n.some(r=>r.inlineEvent!==null&&r.for===null)&&n.some(r=>r.inlineEvent===null&&r.for===null)}l(wr,"requiresExplicitDestinations");function Wt(t,e){let n=[],i=l(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(Oe))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 $e(t);for(let{slice:s,command:p}of n.flatMap(f=>f.commands.map(m=>({slice:f,command:m})))){let f=p.produces.filter(u=>a.isEventProduction(u,s)),m=p.properties.find(u=>u.isIdentifier)?.name,y=wr(p,{resolver:a,slice:s});for(let u of f){let S=u.inlineEvent;S!==null&&((r.get(S.name)??0)>1||o.has(S.name))&&e.error(d.InlineEventCollision,`Inline event '${S.name}' collides with another event declaration or import`,u.location),y&&u.for===null&&e.error(d.ExplicitProducesTargetsRequired,`Production '${u.event}' in command '${p.name}' must state 'for' explicitly - every production must state 'for' when destinations differ`,u.location);let b=u.for?.kind==="PathExpressionSyntax"?u.for.path:u.for===null&&S!==null?m:void 0;if(!(m===void 0||b!==m))for(let v of u.mappings.filter(x=>x.source.kind==="PathExpressionSyntax"&&x.source.path===m)){let x=`Event '${u.event}' copies command identifier '${m}' into payload property '${v.property}' although it already identifies the event source`;S===null?e.information(d.EventSourceIdInPayload,x,v.location):e.warning(d.EventSourceIdInPayload,x,v.location)}}}}l(Wt,"validateInlineEvents");function Ut(t,e){let n=new $e(t),i=re(t.concepts),r=new Map([...re(t.types)].map(([g,k])=>[g,re(k.properties)])),o=new Set(["Uuid","String","Int","Decimal","Bool","Date","DateTime",...i.keys(),...r.keys()]),a=new Set(t.imports.map(g=>g.qualifiedName.split(".").at(-1))),s=new Map;for(let g of t.imports){let k=g.qualifiedName.split(".").at(-1);s.set(k,[...s.get(k)??[],g.qualifiedName])}let p=l(g=>{let k=new Map,E=new Map;for(let P of g){let h=k.get(P.name)??[];h.push(P),k.set(P.name,h)}return(P,h)=>{let C=JSON.stringify([P,h]);if(E.has(C))return E.get(C);let A=l(B=>{let M=B.split("."),j=k.get(M.at(-1))??[],N=M.slice(0,-1);if(N.length>0)return j.filter(F=>N.length<=F.scope.length&&N.every((V,X)=>F.scope[F.scope.length-N.length+X]===V));for(let F=h.length;F>=0;F--){let V=j.filter(X=>F<=X.scope.length&&h.slice(0,F).every((Se,Ce)=>X.scope[Ce]===Se));if(V.length>0)return V}return[]},"candidates"),w=A(P),I=s.get(P)??[];w.length===0&&I.length===1&&(w=A(I[0]));let q=w.length===1?w[0].node:null;return E.set(C,q),q}},"scoped"),f=p(n.slices.flatMap(({slice:g,scope:k})=>g.readModels.map(E=>({name:E.name,scope:k,node:E})))),m=p(n.slices.flatMap(({slice:g,scope:k})=>g.commands.map(E=>({name:E.name,scope:k,node:{command:E,slice:g}})))),y=new Map;for(let g of t.systems??[])y.has(g.name)&&e.error(d.InvalidSystemDeclaration,`System '${g.name}' is declared more than once.`,g.location),y.set(g.name,(y.get(g.name)??0)+1);let u=l((g,k,E=!0)=>{let[P,...h]=k.split("."),C=g.filter(q=>q.name===P);if(C.length!==1)return{type:null,missing:C.length===0};let A=C[0].type;if(h.length===0)return{type:A,missing:!1};let w=r.get(A.name);if(w===void 0)return{type:null,missing:o.has(A.name)};let I=u([...w.values()],h.join("."),E);return I.type===null?I:{type:{...I.type,isOptional:E&&A.isOptional||I.type.isOptional,isCollection:A.isCollection||I.type.isCollection},missing:!1}},"pathType"),S=l((g,k,E,P,h=new Set)=>{if(E.has(k)||g.isOptional&&!P.has(k))return!0;if(g.isCollection||h.has(g.name))return!1;let C=r.get(g.name);return C===void 0?P.has(k)&&!o.has(g.name):[...C.values()].every(A=>S(A.type,`${k}.${A.name}`,E,P,new Set([...h,g.name])))},"covered"),b=l((g,k)=>{if(g.kind==="ListExpressionSyntax"&&k.isCollection)return g.items.every(P=>b(P,{...k,isCollection:!1,isOptional:!1}));let E=r.get(k.name);return g.kind!=="ObjectExpressionSyntax"||E===void 0?!0:[...E.values()].every(P=>(P.type.isOptional||g.members.some(h=>h.name===P.name))&&g.members.filter(h=>h.name===P.name).every(h=>b(h.value,P.type)))},"completeValue"),v=l(g=>g.kind==="LiteralExpressionSyntax"?typeof g.value!="number"||Number.isFinite(g.value):g.kind==="ObjectExpressionSyntax"?g.members.every(k=>v(k.value)):g.kind==="ListExpressionSyntax"&&g.items.every(v),"concrete"),x=l((g,k,E,P,h)=>{let C=new Set,A=new Set(g.map(I=>I.property)),w=new Set;for(let I of g){let q=I.property.split(".");for(let B=1;B<=q.length;B++)w.add(q.slice(0,B).join("."))}for(let I of g){C.has(I.property)&&e.error(d.InvalidOperationMapping,`Duplicate operation input mapping '${I.property}'.`,I.location),C.add(I.property);let q=u(k.inputs,I.property,!1);if(q.missing&&e.error(d.InvalidOperationMapping,`Operation '${k.name}' declares no input '${I.property}'.`,I.location),q.type===null)continue;let B=I.property.split(".");for(let M=1;M<B.length;M++)A.has(B.slice(0,M).join("."))&&e.error(d.InvalidOperationMapping,`Operation input mapping '${I.property}' overlaps a whole input mapping.`,I.location);if(E!==null&&I.source.kind==="PathExpressionSyntax"){let M=u(E.properties,I.source.path),j=I.source.path.split("."),N=(wt.get(E)??[]).filter(X=>(X.alias??X.readModel)===j[0]);if(M.missing&&N.length>0){M={type:null,missing:!1};let X=N.length===1?f(N[0].readModel,h):null;j.length>1&&X!==null&&(M=u(X.properties,j.slice(1).join(".")))}M.missing&&e.error(d.InvalidOperationMapping,`Command '${E.name}' declares no source '${I.source.path}'.`,I.source.location);let F=M.type,V=q.type;F!==null&&o.has(F.name)&&o.has(V.name)&&(F.name!==V.name||F.isCollection!==V.isCollection||F.isOptional&&!V.isOptional)&&e.error(d.InvalidOperationMapping,`Source '${I.source.path}' is incompatible with input '${I.property}' of operation '${k.name}'.`,I.source.location)}else["LiteralExpressionSyntax","ObjectExpressionSyntax","ListExpressionSyntax"].includes(I.source.kind)&&(!ke(I.source,q.type,i,r)||P&&!b(I.source,q.type))&&e.error(d.InvalidOperationMapping,`Value is incompatible with input '${I.property}' of operation '${k.name}'.`,I.source.location)}if(P)for(let I of k.inputs)S(I.type,I.name,C,w)||e.error(d.InvalidOperationMapping,`Production of operation '${k.name}' supplies no value for required input '${I.name}'.`,k.location)},"validateMappings");for(let{slice:g,scope:k}of n.slices){let E=Yt(g),P=new Set(Oe(g).map(h=>h.name));for(let h of E){P.has(h.name)&&e.error(d.ProductionDeclarationCollision,`Operation '${h.name}' collides with another event or operation in slice '${g.name}'.`,h.location),P.add(h.name),h.uses.length>0&&y.get(h.uses)!==1&&e.error(d.InvalidSystemReference,`Operation '${h.name}' must use one declared system; '${h.uses}' does not resolve uniquely.`,h.usesLocation??h.location);for(let C of h.inputs)!o.has(C.type.name)&&!a.has(C.type.name)&&e.warning(d.UnknownType,`Unknown type '${C.type.name}' on input '${C.name}' of operation '${h.name}'.`,C.type.location)}for(let h of g.commands)for(let C of h.produces){let A=n.resolve(C.event,g);A.kind===_.Ambiguous&&A.candidates.some(w=>w.kind===_.Operation)&&e.error(d.InvalidProductionReference,`Production '${C.event}' is ambiguous.`,C.location),C.event.includes(".")&&A.kind!==_.Operation&&e.error(d.InvalidProductionReference,"Qualified productions are supported only for explicitly declared operations.",C.location),A.declaration?.node.kind==="OperationSyntax"&&((C.for!==null||C.tags.length>0)&&e.error(d.InvalidOperationDeclaration,"Operation productions cannot declare event destinations or tags.",C.location),x(C.mappings,A.declaration.node,h,!0,k))}for(let h of g.reactions.flatMap(C=>C.triggers).flatMap(C=>C.produces)){let C=n.resolve(h.event,g);C.kind===_.Ambiguous&&C.candidates.some(A=>A.kind===_.Operation)&&e.error(d.InvalidProductionReference,`Production '${h.event}' is ambiguous.`,h.location),h.event.includes(".")&&n.resolve(h.event,g).kind!==_.Operation&&e.error(d.InvalidProductionReference,"Qualified productions are supported only for explicitly declared operations.",h.location),n.isOperation(h,g)&&e.error(d.OperationOutsideCommand,"Operations can only be produced by commands.",h.location)}for(let h of g.specifications){let C=[...h.givenOperationFailures??[],...h.thenOperations??[],...h.thenCompensated??[]];if(C.length===0)continue;let A=m(h.when?.commandType??"",k);(A===null||h.whenAppended!==null||h.whenQuery!==null||h.whenTrigger!==null||h.whenClock!==null||h.whenCapture!==null)&&e.error(d.InvalidOperationSpecification,"Operation fixtures and assertions require a declared command action.",h.location);let w=new Map;for(let I of C){if(I.kind==="SpecificationOperationSyntax")for(let M of I.values)v(M.source)||e.error(d.InvalidOperationSpecification,"Operation assertions require concrete input values.",M.source.location);let q=n.resolve(I.operation,g).declaration?.node;if(q?.kind!=="OperationSyntax"){e.error(d.InvalidOperationSpecification,`'${I.operation}' does not resolve uniquely to a declared operation.`,I.location);continue}let B=w.get(q)??new Set;if(B.has(I.kind)&&e.error(d.InvalidOperationSpecification,`Duplicate operation step '${I.operation}'.`,I.location),B.add(I.kind),w.set(q,B),I.kind==="SpecificationCompensatedSyntax"&&q.compensate===null&&e.error(d.InvalidOperationSpecification,`Operation '${I.operation}' declares no compensation.`,I.location),A!==null&&A.command.handler==null){let M=A.command.produces.map(j=>n.resolve(j.event,A.slice));M.every(j=>j.kind===_.Event||j.kind===_.Operation)&&!M.some(j=>j.declaration?.node===q)&&e.error(d.InvalidOperationSpecification,`Command '${A.command.name}' does not produce operation '${I.operation}'.`,I.location)}I.kind==="SpecificationOperationSyntax"&&x(I.values,q,null,!1,k)}}}}l(Ut,"validateOperations");var ec=Z("^policy\\s+([A-Za-z_]\\w*)$");function Ir(t,e){t=t.valueContext;let n=ec.exec(e.content)?.[1]??"";n===""&&t.error(d.InvalidPolicyDeclaration,`Invalid policy declaration '${e.content}' - expected 'policy <Name>'`,c(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 p=s.content.substring(7).trim();for(let m=t.peekChild(s.indent);m!==void 0;m=t.peekChild(s.indent))t.reader.takeSignificant(),p+=` ${m.content}`;let f=tc(t,p,c(s));a?t.error(d.RepeatedPolicyRequirement,`Policy '${n}' has more than one require line; combine the conditions with and/or in one require`,c(s)):i=f,a=!0}else if(R(s.content)==="file"){let p=Pe(t,s);r===null&&o===null?o=p:t.error(d.UnknownPolicyDirective,`Policy '${n}' must have only one implementation - a file reference or an inline code block, not both`,c(s))}else if(s.content.startsWith("```")||t.languages.has(s.content)){let p=le(t,s);r===null&&o===null?r=p:t.error(d.UnknownPolicyDirective,`Policy '${n}' must have only one implementation - a file reference or an inline code block, not both`,c(s))}else t.error(d.UnknownPolicyDirective,`Unexpected '${s.content}' in policy body - expected 'require ...', 'file <path>' or an inline code block`,c(s)),t.skipOpaqueBlock(s.indent);return i!==null&&(r!==null||o!==null)&&t.error(d.MixedPolicyImplementation,`Policy '${n}' cannot combine 'require' with a file or inline code block`,c(e)),i===null&&r===null&&o===null&&t.error(d.PolicyWithoutRequirement,`Policy '${n}' must declare a 'require' condition, a file reference or an inline code block`,c(e)),{kind:"PolicySyntax",name:n,condition:i,code:r,file:o,location:c(e)}}l(Ir,"parsePolicy");function tc(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(`"${W}"|\\(|\\)|${i}`).source,"gu"))??[]],o=0,a=l(u=>u!==void 0&&u.startsWith('"')&&u.endsWith('"'),"quoted"),s=l(u=>U(u.substring(1,u.length-1)),"unquote"),p=l(()=>{if(r[o]==="("){o++;let v=m();return r[o]===")"?o++:t.sourceOptions.numericMode==="exact"&&t.error(d.UnclosedPolicyConditionGroup,"Expected ')' in policy condition",n),v}let u=r[o++];if(u==="authenticated")return{kind:"AuthenticatedConditionSyntax",location:n};if(u!=="role"&&u!=="claim")return t.error(u===void 0?d.ExpectedPolicyCondition:d.UnexpectedTokenInPolicyCondition,u===void 0?"Expected a policy condition":`Unexpected '${u}' in policy condition`,n),null;let S=r[o++];if(!a(S))return t.error(u==="role"?d.ExpectedRoleName:d.ExpectedClaimName,`Expected a quoted ${u} name after '${u}'`,n),null;if(u==="role")return{kind:"RoleConditionSyntax",role:s(S),location:n};if(r[o++]!=="matches")return t.error(d.ExpectedClaimMatches,"Expected 'matches' after the claim name",n),null;let b=r[o++];return b===void 0?(t.error(d.ExpectedClaimMatchTarget,"Expected 'subject' or a value after 'matches'",n),null):{kind:"ClaimConditionSyntax",claim:s(S),matchesSubject:b==="subject",matches:b==="subject"?null:ae(b,n,t),location:n}},"group"),f=l(()=>{let u=p();for(;u!==null&&r[o]==="and";){o++;let S=p();if(S===null)return null;u={kind:"LogicalPolicyConditionSyntax",left:u,operator:"And",right:S,location:n}}return u},"and"),m=l(()=>{let u=f();for(;u!==null&&r[o]==="or";){o++;let S=f();if(S===null)return null;u={kind:"LogicalPolicyConditionSyntax",left:u,operator:"Or",right:S,location:n}}return u},"or"),y=m();return t.sourceOptions.numericMode==="exact"&&y!==null&&o<r.length&&t.error(d.UnexpectedTokenInPolicyCondition,`Unexpected '${r[o]}' in policy condition`,n),y}l(tc,"parsePolicyCondition");var nc=new RegExp(`^for\\s+"(${W})"$`,"u"),ic=Z("^[A-Z]\\w*$"),rc=Z("^([\\w.]+)\\s*=(?!=|>)\\s*(.+)$");function Rr(t,e){let n=[];if(t=t.valueContext,e.content!=="seed")return t.error(d.InvalidSeedDeclaration,`Invalid seed declaration '${e.content}' - expected 'seed'`,c(e)),t.skipOpaqueBlock(e.indent),{kind:"SeedSyntax",groups:n,location:c(e)};for(let i=t.peekChild(e.indent);i!==void 0;i=t.peekChild(e.indent)){t.reader.takeSignificant();let r=nc.exec(i.content);if(r===null){t.error(d.InvalidSeedGroup,`Invalid seed group '${i.content}' - expected 'for "<event source id>"'`,c(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(),!ic.test(a.content)){t.error(d.InvalidSeedEvent,`Invalid seed event '${a.content}' - expected an event type name`,c(a)),t.skipOpaqueBlock(a.indent);continue}let s=[];for(let p=t.peekChild(a.indent);p!==void 0;p=t.peekChild(a.indent)){t.reader.takeSignificant();let f=rc.exec(p.content);f!==null?s.push({kind:"PropertyMappingSyntax",property:f[1],source:ae(f[2],c(p),t),location:c(p)}):t.error(d.InvalidSeedPropertyAssignment,`Invalid property assignment '${p.content}' - expected '<property> = <value>'`,c(p))}o.push({kind:"SeedEventSyntax",event:a.content,properties:s,location:c(a)})}n.push({kind:"SeedGroupSyntax",eventSourceId:U(r[1]),events:o,location:c(i)})}return{kind:"SeedSyntax",groups:n,location:c(e)}}l(Rr,"parseSeed");var oc=$("^domain\\s+([A-Za-z_]\\w*(?:\\.[A-Za-z_]\\w*)*)$"),Dr=$("^import\\s+([\\w.]+)$"),ac=$("^concept\\s+(\\w+)\\s*:\\s*(\\w+)((?:\\s+@\\w+)*)$"),sc=$("^@?[a-z_]\\w*$"),lc=$(`^([a-z_]\\w*)\\s+reason\\s+"(${W})"$`),cc=$("^persona\\s+([A-Za-z_]\\w*)$"),dc=$("^policy\\s+([A-Za-z_]\\w*)$"),pc=/^[ ]*\t/,Tr=["Uuid","String","Int","Decimal","Bool","Date","DateTime"],jr=new Set(["policy","authentication","seed","ui","theme","trigger","layout","behavior"]),fc=new Set(["slice","feature","description","authorize","screen","dialog","form","contribute","on","uses"]);function zt(t,e,n=Re){hc(t,e);let i=n.length===1?new ft(n[0]):void 0,r=n.length>1?new pt(n[n.length-1]):void 0,o=i??r,a=null,s=[],p=[],f=[],m=[],y=[],u=[],S=[],b=[],v=[],x=[],g=!1;for(let E=t.reader.peekSignificant();E!==void 0;E=t.reader.peekSignificant()){t.reader.takeSignificant();let P=R(E.content);if(P==="domain"){t.authoredDeclarations=!0,a=Sc(t,E,a,g);continue}if(g||=Mr(P,E,n),t.authoredDeclarations||=P!=="import"&&Mr(P,E,n),P==="import"&&vi(E.content))o!==void 0?o.tryParse(t,E):Fe(t,E,p);else if(P==="import"){let h=Dr.exec(E.content);h===null?t.error(d.InvalidImportDeclaration,`Invalid import '${E.content}' - expected 'import <Qualified.Name>'`,c(E)):s.push({kind:"ImportSyntax",qualifiedName:h[1],location:c(E)})}else P==="eventsource"?u.push(Fi(t,E)):P==="system"?y.push(Ki(t,E)):P==="concept"?f.push(gc(t,E)):P==="type"?m.push(Mi(t,E)):P==="module"&&!tt(n)?uc(t,E,n,i):P==="module"?S.push(Wn(t,E)):P==="persona"?b.push($c(t,E)):P==="seed"?x.push(Rr(t.valueContext,E)):P==="policy"?v.push(Ir(t.valueContext,E)):P==="trigger"?cr(t,E):jr.has(P)?P==="behavior"||P==="layout"?pe(t,E):t.skipOpaqueBlock(E.indent):o?.tryParse(t,E)!==!0&&yc(t,E,n)}i!==void 0?S.unshift(i.build(t.start,!0)):r!==void 0&&S.unshift(mc(n,r.build(t.start,!0),t.start));let k={kind:"ApplicationSyntax",sourceOptions:t.sourceOptions,domain:a,imports:s,concepts:f,types:m,systems:y,eventSources:u,modules:S,personas:b,policies:v,seeds:x,fileImports:p,location:t.start};return t.authoredDeclarations&&Zi(k),k}l(zt,"parseApplication");function Mr(t,e,n){return t==="import"?Dr.test(e.content):t==="module"?tt(n):t==="eventsource"||t==="system"||t==="concept"||t==="type"||t==="persona"||jr.has(t)}l(Mr,"declaresConstruct");function uc(t,e,n,i){let r=Fn.exec(e.content)?.[1]??"";if(i!==void 0&&r===n[0]){t.authoredDeclarations=!0,i.parseChildren(t,e);return}t.error(d.ModuleInPlacedFile,`This file is imported into ${vt(n)}, so it cannot declare module '${r}' - import it at the top level of a document instead`,c(e)),t.skipBlock(e.indent)}l(uc,"parseModuleInPlacedFile");function yc(t,e,n){let i=R(e.content);if(tt(n)){let r=fc.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(d.UnknownTopLevelConstruct,`Unexpected '${i}' at the top level${r}`,c(e))}else{let r=n.length===1?Yn:Bn;t.error(d.UnexpectedInPlacedFile,`Unexpected '${i}' in a file imported into ${vt(n)} - expected an application declaration or ${r}`,c(e))}t.skipBlock(e.indent)}l(yc,"reportUnexpectedTopLevel");function mc(t,e,n){let i=e;for(let r=t.length-2;r>=1;r--)i={kind:"FeatureSyntax",name:t[r],description:null,authorize:null,features:[i],slices:[],fileImports:[],isPlacement:!0,location:n};return{kind:"ModuleSyntax",name:t[0],description:null,authorize:null,features:[i],fileImports:[],isPlacement:!0,location:n}}l(mc,"place");function Sc(t,e,n,i){let r=oc.exec(e.content);return r===null?(t.error(d.InvalidDomainDeclaration,`Invalid domain declaration '${e.content}' - expected 'domain <Qualified.Name>'`,c(e)),n):n!==null?(t.error(d.DuplicateDomain,"The document already declares a domain - a document can have at most one",c(e)),n):(i&&t.error(d.DomainNotFirst,"'domain' must be declared before any other construct",c(e)),{kind:"DomainSyntax",name:r[1],location:c(e)})}l(Sc,"parseDomain");function hc(t,e){let n=!1;for(let i of e){if(i.raw.trimStart().startsWith("```")){n=!n;continue}!n&&pc.test(i.raw)&&t.warning(d.TabIndentation,"Screenplay is indentation based - use spaces, not tabs",gi(i))}}l(hc,"warnOnTabIndentation");function gc(t,e){let n=ac.exec(e.content);if(n===null)return t.error(d.InvalidConceptDeclaration,`Invalid concept declaration '${e.content}' - expected 'concept <Name> : <Type>'`,c(e)),t.skipBlock(e.indent),{kind:"ConceptSyntax",name:R(e.content),type:"",attributes:[],values:[],location:c(e)};let[,i,r,o]=n,a=o.split(" ").filter(m=>m.length>0).map(m=>({kind:"ConceptAttributeSyntax",name:m.replace(/^@+/,""),reason:null,location:c(e)}));r!=="Enum"&&!Tr.includes(r)&&t.error(d.UnknownPrimitiveType,`Unknown primitive type '${r}' - expected ${Tr.join(", ")} or Enum`,c(e));let s=new Map;a.forEach((m,y)=>{s.has(m.name)||s.set(m.name,y)});let p=[],f=[];for(let m=t.peekChild(e.indent);m!==void 0;m=t.peekChild(e.indent)){t.reader.takeSignificant();let y=lc.exec(m.content);if(!ee(m))if(R(m.content)==="validate"){r==="Enum"&&m.content==="validate"&&t.peekChild(m.indent)===void 0&&t.warning(d.ValidateReadAsEnumerationBlock,`'validate' in enumeration concept '${i}' declares an empty validate block, not a value named 'validate' - write '@validate' for the value`,c(m));let u=An(t,m,"concept");u!==void 0&&f.push(u)}else y!==null?xc(t,m,i,a,s,y[1],U(y[2])):r==="Enum"&&sc.test(m.content)?p.push(Q(m.content)):r==="Enum"?t.error(d.InvalidEnumerationValue,`Invalid enum value '${m.content}' - expected an identifier`,c(m)):(t.error(d.UnknownConceptDirective,`Unexpected '${m.content}' in concept body - expected validate, 'file <path>' or '<attribute> reason "<text>"'`,c(m)),t.skipBlock(m.indent))}return{kind:"ConceptSyntax",name:i,type:r,attributes:a,values:p,validations:f,location:c(e)}}l(gc,"parseConcept");function xc(t,e,n,i,r,o,a){let s=r.get(o);s===void 0?t.error(d.AttributeReasonWithoutAttribute,`Concept '${n}' declares a reason for '${o}' without the attribute - write 'concept ${n} : <Type> @${o}'`,c(e)):i[s].reason!==null?t.error(d.DuplicateAttributeReason,`Concept '${n}' already declares a reason for '${o}' - at most one is allowed`,c(e)):i[s]={...i[s],reason:a}}l(xc,"applyAttributeReason");function $c(t,e){let n=cc.exec(e.content)?.[1]??"";n===""&&t.error(d.InvalidPersonaDeclaration,`Invalid persona declaration '${e.content}' - expected 'persona <Name>'`,c(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=G(t,o,i,`Persona '${n}'`);else if(a==="policy"){let s=dc.exec(o.content);s===null?t.error(d.InvalidPersonaPolicyReference,`Invalid policy reference '${o.content}' - expected 'policy <Name>'`,c(o)):r.push(s[1])}else t.error(d.UnknownPersonaDirective,`Unexpected '${a}' in persona body - expected description or policy`,c(o)),t.skipBlock(o.indent)}return{kind:"PersonaSyntax",name:n,description:i,policies:r,location:c(e)}}l($c,"parsePersona");var Qe=class t{static{l(this,"CommandStreamCandidates")}sources;qualifiedTypes;constructor(e,n){this.sources=e,this.qualifiedTypes=n}hasSource(e){return this.sources.has(e)}hasPropertyType(e){return this.qualifiedTypes.has(e)}hasUniqueStream(e,n){let i=this.sources.get(e);return i?.length===1&&i[0].filter(r=>r===n).length===1}static capture(e,n=Re,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:p}of e){let f=Ft(s,s[0]?.path,n);f.scope=p;let m=zt(f,s,p);for(let y of m.types)r.add(y.name);for(let y of m.concepts)r.add(y.name);for(let y of m.imports)o.add(y.qualifiedName);for(let y of m.eventSources??[])i.set(y.name,[...i.get(y.name)??[],y.streams.map(u=>u.name)])}let a=new Set([...o].filter(s=>r.has(s.substring(s.lastIndexOf(".")+1))));return new t(i,a)}};var ye;(function(t){t.Unique="unique",t.Ambiguous="ambiguous",t.NotFound="notFound",t.WrongKind="wrongKind"})(ye||(ye={}));var Vt=class{static{l(this,"EventSourceCatalog")}sources=new Map;otherNames;constructor(e){for(let n of e.eventSources??[])this.sources.set(n.name,[...this.sources.get(n.name)??[],n]);this.otherNames=new Set([...e.concepts,...e.types].map(n=>n.name))}resolve(e,n){let i=this.sources.get(e)??[],r=i.flatMap(a=>a.streams).filter(a=>a.name===n),o;return i.length===0?o=this.otherNames.has(e)?ye.WrongKind:ye.NotFound:i.length>1||r.length>1?o=ye.Ambiguous:o=r.length===1?ye.Unique:ye.NotFound,{kind:o,sources:i,streams:r}}};var Vn=new Set(["String","Uuid","Int","Decimal","Bool","Date","DateTime"]);function Qt(t,e){let n=re(t.concepts),i=re(t.types),r=new Set([...Vn,...n.keys(),...i.keys()]),o=new Map([...i].map(([y,u])=>[y,re(u.properties)])),a=l((y,u)=>r.has(y.name)&&r.has(u.name)?y.name===u.name&&y.isCollection===u.isCollection&&(!y.isOptional||u.isOptional):null,"compatible"),s=l((y,u)=>{if(y===null)return;if(y.isOptional||y.isCollection||t.types.some(v=>v.name===y.name)){e.error(d.InvalidEventSourceDeclaration,"Identifier and streamId declarations require a nonoptional scalar value type.",y.location);return}let S=t.concepts.filter(v=>v.name===y.name),b=S.length===1?S[0].type:S.length===0&&Vn.has(y.name)?y.name:null;u&&b!==null&&(!["String","Uuid","Int"].includes(b)||b==="Int"&&S.length===0||S.some(v=>v.values.length>0))&&e.error(d.UnsupportedStreamIdType,"Stream ids support text and UUID values and their nominal concepts, plus integer-backed concepts; other types need a future portable formatter.",y.location),b===null&&!t.imports.some(v=>v.qualifiedName===y.name||v.qualifiedName.split(".").at(-1)===y.name)&&e.warning(d.UnknownType,`Unknown type '${y.name}' in event source declaration.`,y.location)},"validateType"),p=new Set;for(let y of t.eventSources??[]){p.has(y.name)&&e.error(d.InvalidEventSourceDeclaration,`Event source '${y.name}' has multiple physical declarations.`,y.location),p.add(y.name),s(y.identifier,!1);let u=new Set;for(let S of y.streams)u.has(S.name)&&e.error(d.InvalidEventSourceDeclaration,`Stream '${y.name}.${S.name}' has multiple declarations under this source.`,S.location),u.add(S.name),s(S.streamId,!0)}let f=l((y,u)=>{let[S,...b]=u.split(".");if(y===null)return{property:null,missing:!1};let v=y.filter(k=>k.name===S);if(v.length!==1)return{property:null,missing:v.length===0};let x=v[0];if(b.length===0)return{property:x,missing:!1};if(Vn.has(x.type.name)||n.has(x.type.name)&&!i.has(x.type.name))return{property:null,missing:!0};let g=f(i.get(x.type.name)?.properties??null,b.join("."));return g.property===null?g:{property:{...g.property,type:{...g.property.type,isCollection:x.type.isCollection||g.property.type.isCollection,isOptional:x.type.isOptional||g.property.type.isOptional}},missing:!1}},"pathProperty"),m=new Vt(t);for(let{slice:y}of new $e(t).slices)for(let u of y.commands){let S=u.stream;if(S==null||S.propertyCandidate!==null)continue;let b=m.resolve(S.eventSource,S.stream);if(b.kind!==ye.Unique){let E={ambiguous:"Ambiguous",notFound:"NotFound",wrongKind:"WrongKind"}[b.kind];e.error(d.InvalidCommandStream,`Stream '${S.eventSource}.${S.stream}' is ${E}; routing requires one physical source and stream.`,S.location);continue}let v=b.sources[0],x=b.streams[0],g=u.properties.filter(E=>E.isIdentifier);if(v.identifier!==null&&g.length===1&&a(g[0].type,v.identifier)===!1&&e.warning(d.InvalidCommandStream,`Command identifier '${g[0].name}' does not have the source's nominal identifier type '${v.identifier.name}'. The stream does not supply a destination.`,g[0].location),(x.streamId===null&&S.streamId!==null||x.streamId!==null&&S.streamId===null)&&e.error(d.InvalidCommandStream,x.streamId===null?"An unkeyed stream cannot take a streamId mapping.":"This keyed stream requires a streamId mapping.",S.location),x.streamId===null||S.streamId===null)continue;let k=S.streamId.source;if(k.kind==="PathExpressionSyntax"){let E=f(u.properties,k.path);(E.missing||E.property!==null&&a(E.property.type,x.streamId)===!1)&&e.error(d.InvalidCommandStream,`Stream id source '${k.path}' is absent or incompatible with nominal type '${x.streamId.name}'.`,k.location)}else k.kind==="LiteralExpressionSyntax"&&!ke(k,x.streamId,n,o)?e.error(d.InvalidCommandStream,`Stream id value is incompatible with nominal type '${x.streamId.name}'.`,k.location):(["RawExpressionSyntax","ObjectExpressionSyntax","ListExpressionSyntax"].includes(k.kind)||k.kind==="LiteralExpressionSyntax"&&k.value===null)&&e.error(d.InvalidCommandStream,"A stream id needs a scalar value source, not a raw expression, collection or absence.",k.location)}}l(Qt,"validateEventSources");var bc=new WeakMap,Gt=l(t=>JSON.stringify(t),"authoredOrderKey");function Gn(t){return bc.get(t)??new Map}l(Gn,"authoredOrderOf");function Kn(t){let e=Gn(t),n=l((m,y)=>m.map(u=>({syntax:u,rank:e.get(Gt([...y,u.name]))??Number.MAX_SAFE_INTEGER})).sort((u,S)=>u.rank-S.rank).map(u=>u.syntax),"ordered"),i=[],r=l((m,y)=>{let u=[...y,m.name];for(let S of n(m.slices,u))i.push({syntax:S,scope:[...u,S.name],identity:[...u.map(b=>`container:${b}`),`slice:${S.name}`],index:i.length});for(let S of n(m.features,u))r(S,u)},"feature");for(let m of n(t.modules,[]))for(let y of n(m.features,[m.name]))r(y,[m.name]);let o=new Map;for(let m of i)for(let y of Oe(m.syntax))o.has(y.name.toLowerCase())||o.set(y.name.toLowerCase(),m);let a=[];for(let m of i){let y=new Set,u=[...m.syntax.projections.flatMap(S=>S.blocks.flatMap(_n)),...m.syntax.reactions.flatMap(S=>S.triggers).flatMap(S=>S.source.kind==="NamedTriggerSourceSyntax"?[{event:S.source.name,location:S.source.location}]:[])].sort((S,b)=>S.location.line-b.location.line||S.location.column-b.location.column);for(let S of u){let b=S.event.toLowerCase();if(y.has(b))continue;y.add(b);let v=o.get(b);if(v===void 0||v===m)continue;let x=0;for(;x<m.scope.length&&x<v.scope.length&&m.identity[x]===v.identity[x];)x++;x===m.scope.length||x===v.scope.length||a.push({...S,consumer:m,producer:v,container:Gt(m.identity.slice(0,x)),left:m.identity[x],right:v.identity[x]})}}let s=l((m,y)=>m.consumer.index-y.consumer.index||m.location.line-y.location.line||m.location.column-y.location.column,"compare"),p=new Set,f=[];for(let m of new Set(a.map(y=>y.container))){let y=a.filter(S=>S.container===m),u=new Map;for(let S of y)u.has(S.left)||u.set(S.left,new Set),u.has(S.right)||u.set(S.right,new Set),u.get(S.left).add(S.right);for(let S of Cc(u).filter(b=>b.length>1)){let b=new Set(S),v=y.filter(k=>b.has(k.left)&&b.has(k.right));v.forEach(k=>p.add(k));let x=v.filter(k=>k.consumer.index<k.producer.index).sort(s)[0];if(x===void 0)continue;let g=l(k=>Math.min(...v.flatMap(E=>[E.consumer,E.producer]).filter(E=>{let P=JSON.parse(m);return E.identity[P.length]===k}).map(E=>E.index)),"memberIndex");S.sort((k,E)=>g(k)-g(E)),f.push({edge:x,diagnostic:{severity:"information",code:d.TimelineCycleGroup,message:`Timeline group ${S.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:x.location}})}}for(let m of a){if(m.consumer.index>=m.producer.index||p.has(m))continue;let y=m.consumer.scope.slice(0,-1),S=m.producer.scope.length>m.consumer.scope.length&&y.every((b,v)=>m.producer.scope[v]===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:d.EventFromLaterSlice,message:`Slice '${m.consumer.syntax.name}' uses event '${m.event}' produced by slice '${m.producer.syntax.name}' drawn after it.${S}`,location:m.location}})}return f.sort((m,y)=>s(m.edge,y.edge)).map(m=>m.diagnostic)}l(Kn,"timelineOrderDiagnostics");function _n(t){switch(t.kind){case"FromSyntax":case"JoinSyntax":return t.events.map(e=>({event:e.event,location:e.location}));case"ChildrenSyntax":case"NestedSyntax":return t.blocks.flatMap(_n);case"ProjectionVariantSyntax":return[...t.entersOn.map(e=>({event:e.event,location:e.location})),...t.blocks.flatMap(_n)];case"RemoveWithSyntax":case"RemoveViaJoinSyntax":case"ClearWithSyntax":return[{event:t.event,location:t.location}];default:return[]}}l(_n,"eventsOf");function Cc(t){let e=new Map,n=new Map,i=[],r=new Set,o=[],a=l(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))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 p=[],f;do f=i.pop(),r.delete(f),p.push(f);while(f!==s);o.push(p)},"visit");for(let s of t.keys())e.has(s)||a(s);return o}l(Cc,"stronglyConnected");function De(t,e,n=Re,i=!0,r,o){let a=Ne(t,!1,e),s=Ft(a,e,o);s.scope=n,s.streamCandidates=r??Qe.capture([a],n,o);let p=zt(s,a,n);if(i){Wt(p,s),Ut(p,s),Bt(p,s),Qt(p,s);for(let f of Kn(p))s.information(f.code,f.message,f.location)}return{value:p,diagnostics:s.diagnostics,triggerData:s.triggerData,inputUses:s.inputUses,success:!s.diagnostics.some(f=>f.severity==="error")}}l(De,"parseForAuthoring");var Zt=class{static{l(this,"ScreenplaySyntaxWalker")}visitNode(e){}visitApplication(e){this.visitNode(e),e.domain!==null&&this.visitDomain(e.domain),e.imports.forEach(n=>this.visitImport(n)),e.fileImports.forEach(n=>this.visitFileImport(n)),e.systems?.forEach(n=>this.visitSystem(n)),e.eventSources?.forEach(n=>this.visitEventSource(n)),e.concepts.forEach(n=>this.visitConcept(n)),e.types.forEach(n=>this.visitType(n)),e.personas.forEach(n=>this.visitPersona(n)),e.policies?.forEach(n=>this.visitPolicy(n)),e.seeds?.forEach(n=>this.visitSeed(n)),e.modules.forEach(n=>this.visitModule(n))}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))}visitModule(e){this.visitNode(e),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.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))}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.values.forEach(n=>this.visitPropertyMapping(n)),e.for!==null&&this.visitExpression(e.for)}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)}};function ax(t){return t===d.LegacyOptionalSuffix||t===d.RedundantEventId}l(ax,"isQuickFixDiagnostic");function Jn(t,e){return e.code!==d.LegacyOptionalSuffix?0:/^[\p{L}\p{Mn}\p{Nd}\p{Pc}.]+(?:\[\])?\?/u.exec(t.slice(e.location.column-1))?.[0].length??0}l(Jn,"legacyOptionalTypeLength");function sx(t,e={}){let n=De(t,void 0,e.placement);if(!n.success)return()=>[];let i=Ne(t),r=new Map;new class extends Zt{visitEvent(g){r.set(g.location.line,g)}}().visitApplication(n.value);let a=new Map,s=new Map,p=new Map,f;for(let g of i)f=r.get(g.number)??f,f!==void 0&&p.set(g.number,f);for(let g of n.diagnostics){a.set(g.code,(a.get(g.code)??0)+1);let k=i[g.location.line-1],E=Jn(k.raw,g);if(E>0)s.set(k.number,{line:k.number,fix:{diagnosticCode:g.code,title:"Use 'optional' instead of '?'",scope:"occurrence",edits:[{start:k.startOffset+g.location.column+E-2,length:1,text:" optional"}]}});else if(g.code===d.RedundantEventId&&et(k.raw)<0){let P=p.get(k.number);if(P?.id!==P?.name||P===void 0)continue;s.set(k.number,{line:k.number,fix:{diagnosticCode:g.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:P,replacement:{...P,id:null}}})}}let m=[...s.values()].filter(g=>g.fix.diagnosticCode===d.LegacyOptionalSuffix),y=ut(n),u=new Map,S,b=!1,v,x=l((g,k)=>{let E=qr(t,g.edits);if(E===void 0)return;let P=De(E,void 0,e.placement);if(!(!P.success||ut(P)!==(k===void 0?y:ut(n,[k]))))return P.diagnostics.filter(h=>h.code===g.diagnosticCode).length===(a.get(g.diagnosticCode)??0)-g.edits.length?g:void 0},"verify");return(g,k)=>{let E=typeof g=="number"||g===void 0?void 0:g,P=E===void 0?k===void 0||k===d.LegacyOptionalSuffix:E.some(w=>w.diagnosticCode===d.LegacyOptionalSuffix);if(P&&!b&&(m.length>0&&(v=x({diagnosticCode:d.LegacyOptionalSuffix,title:"Use 'optional' throughout this document",scope:"document",edits:m.flatMap(w=>w.fix.edits)})),b=!0),E!==void 0){if(S===void 0){S=new Map;let I=i.flatMap(M=>s.has(M.number)?[s.get(M.number)]:[]),q=I.flatMap(M=>M.fix.edits),B=qr(t,q);if(q.length>0&&B!==void 0){let M=De(B,void 0,e.placement),j=I.flatMap(N=>N.change===void 0?[]:[N.change]);if(M.success&&ut(M)===ut(n,j)){let N=new Map,F=new Map;for(let V of M.diagnostics)N.set(V.code,(N.get(V.code)??0)+1);for(let V of I)F.set(V.fix.diagnosticCode,(F.get(V.fix.diagnosticCode)??0)+V.fix.edits.length);if([...F].every(([V,X])=>(N.get(V)??0)===(a.get(V)??0)-X))for(let V of I)S.set(V.line,V.fix)}}}let w=new Map;for(let I of E){let q=S.get(I.line);q?.diagnosticCode===I.diagnosticCode&&w.set(I.line,q)}return[...w.values(),...P&&v!==void 0?[v]:[]]}let h=typeof g=="number"?g:void 0,C=h===void 0?void 0:s.get(h),A;return C!==void 0&&h!==void 0&&(k===void 0||C.fix.diagnosticCode===k)&&(u.has(h)||(u.size===32&&u.delete(u.keys().next().value),u.set(h,x(C.fix,C.change))),A=u.get(h)),[A,P?v:void 0].filter(w=>w!==void 0)}}l(sx,"prepareQuickFixes");function ut(t,e=[]){let n=new Map(e.map(i=>[i.node,i.replacement]));return JSON.stringify([t.value,t.triggerData],(i,r)=>["location","usesLocation","targetLocation"].includes(i)?void 0:n.get(r)??r)}l(ut,"verificationShape");function qr(t,e){let n=[],i=0;for(let r of e){if(r.start<i||r.start<0||r.length<0||r.start+r.length>t.length)return;n.push(t.slice(i,r.start),r.text),i=r.start+r.length}return n.push(t.slice(i)),n.join("")}l(qr,"applyQuickFixEdits");var Ge=class{static{l(this,"EventSourceReadConfidence")}complete;sources=new Map;constructor(e,n){this.complete=n;for(let i of e)this.sources.set(i.source.name,[...this.sources.get(i.source.name)??[],i])}static hasUnknownExtent(e){return e.some(n=>n.severity==="error"&&["PLAY0001","PLAY0503","PLAY0164"].includes(n.code))}resolve(e,n){let i=this.sources.get(e)??[],r=n===void 0?[]:i.flatMap(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",p=[];return i.length>1&&p.push("Multiple physical parent sources claim the exact name."),r.length>1&&p.push("Multiple physical streams claim the exact parent and local name."),i.some(f=>!f.placementResolved)&&p.push("A physical parent has unresolved import placement."),this.complete||p.push("Physical source extent or placement is incomplete; missing declarations cannot be excluded."),{state:s,sources:i.map(f=>f.source),streams:r,reasons:p}}};var Ec=se("^[A-Za-z_]\\w*$"),je=l((t,e)=>typeof t=="object"&&t!==null&&!Array.isArray(t)&&t.kind===e,"hasKind"),K=l(t=>{throw new J(t)},"refuse"),Ze=l((t,e,n)=>{if(!Array.isArray(t))return K(n);for(let i=0;i<t.length;i++)je(t[i],e)||K(n)},"collection");function _e(t){if(t.kind==="ConceptSyntax"){let e=t;for(let n of e.validations??[])n.kind==="DeclarativeValidateSyntax"&&n.rules.some(i=>i.implementation!=null)&&K("Implementation wrappers on named rules are supported only on commands.")}if(t.kind==="ValidationRuleSyntax"){let e=t;e.implementation!=null&&(je(e.implementation,"ImplementationSyntax")||K("A named rule requires an ImplementationSyntax wrapper."),(e.rule!=="Rule"||e.value?.kind!=="PathExpressionSyntax"||!je(e.value,"PathExpressionSyntax")||typeof e.value.path!="string"||Ec.exec(e.value.path)?.[0]!==e.value.path)&&K("An implementation wrapper requires a valid named rule."),e.file!=null&&e.code!=null&&K("A named rule has at most one file or inline payload."),e.file!=null&&(!je(e.file,"FileReferenceSyntax")||typeof e.file.path!="string")&&K("A named rule file requires a FileReferenceSyntax payload with a string path."),e.code!=null&&(!je(e.code,"CodeBlockSyntax")||typeof e.code.language!="string"||typeof e.code.code!="string")&&K("A named rule inline payload requires a CodeBlockSyntax with string language and code."),_e(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."),Ze(n.inputs,"PropertySyntax","Operation inputs must be a collection of properties."),Ze(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&&_e(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;Ze(e.hints,"ImplementationHintSyntax","Implementation hints must be a collection of nonblank hints.");for(let n=0;n<e.hints.length;n++)_e(e.hints[n])}if(t.kind==="ImplementationHintSyntax"){let e=t;(typeof e.text!="string"||Ot(e.text))&&K("An implementation hint must be nonblank.")}Br(t)}l(_e,"validateSyntaxInvariants");function Br(t){let e=l(n=>{vn(n)||K("Event source and stream names must be identifiers.")},"name");if(t.kind==="ApplicationSyntax"){let n=t.eventSources;n!==void 0&&Ze(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&&!je(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&&!kn(i.name)&&K("Source identifiers and stream ids require an exact type reference name."),n.kind==="EventSourceSyntax"&&Ze(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&&!je(n.stream,"CommandStreamSyntax")&&K("The authoritative command stream must be a command stream node."),n.streamCandidates!==void 0&&Ze(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(Br(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==="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.")}}l(Br,"validateSourceStream");var be={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","SpecificationQueryResultSyntax","SpecificationQuerySyntax","SpecificationReadModelSyntax","SpecificationSyntax","SpecificationTriggerSyntax","SpecificationWhenQuerySyntax","StringsExpressionSyntax","SubtractMappingSyntax","TagSyntax","TemplateExpressionSyntax","TemplateInterpolationSyntax","TemplateTextSyntax","ThemeSyntax","TriggerDataSyntax","TriggerSyntax","TypeRefSyntax","TypeSyntax","UiProfileSyntax","UniqueEventConstraintSyntax","UniquePropertyConstraintSyntax","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","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","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,177,180],["object",[[0,0,!0],[1,1,!0]]],["enum","Inherit","Disabled","Enabled"],["ref",0,29,44,46,79,156,178],["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",183],["array",39],["union",40,8],["ref",185],["array",42],["union",43,8],["ref",187],["array",45],["union",46,8],["ref",188],["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",193],["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",186],["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",179],["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",192],["array",183],["object",[[103,182,!1],[104,184,!1]]],["ref",7],["union",186,8],["ref",159],["array",188],["ref",191],["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",60],["array",208],["ref",158],["array",210],["object",[[74,141,!1],[5,11,!1],[117,207,!1],[41,59,!1],[118,209,!1],[9,19,!1],[119,61,!0],[31,0,!0],[120,211,!1],[107,191,!1]]],["ref",61,189,190],["array",213],["object",[[121,214,!1],[42,85,!0],[122,61,!0],[97,59,!1],[31,0,!0],[123,112,!1]]],["object",[[124,0,!0]]],["object",[[125,59,!1],[58,59,!1],[101,59,!1],[0,0,!0]]],["object",[[126,59,!1],[127,0,!0]]],["ref",64],["array",219],["ref",65,66],["union",221,8],["object",[[5,11,!1],[128,220,!1],[129,0,!0],[31,0,!0],[130,178,!1],[131,222,!1],[107,191,!1]]],["ref",55],["array",224],["ref",37,59],["union",226,8],["object",[[132,225,!1],[56,227,!1],[3,5,!1],[133,128,!1]]],["union",138,8],["ref",70],["union",230,8],["object",[[72,229,!1],[42,86,!1],[134,231,!1]]],["ref",71],["array",233],["object",[[135,234,!1]]],["object",[[136,0,!0]]],["object",[[41,59,!1],[31,0,!0]]],["ref",74],["union",238,8],["object",[[137,239,!1],[41,59,!1],[138,239,!1],[139,149,!1],[31,0,!0],[140,0,!0]]],["object",[[72,229,!1],[41,59,!1],[42,86,!1],[134,231,!1]]],["object",[[141,0,!0]]],["object",[[141,0,!0],[92,93,!1]]],["object",[[142,0,!0]]],["object",[[143,0,!0],[31,0,!0]]],["ref",3,15,51,82],["object",[[144,135,!1],[145,59,!1],[146,246,!0]]],["enum","Seconds","Minutes","Hours","Days"],["object",[[147,55,!0],[148,248,!0]]],["object",[[116,0,!0],[3,93,!1]]],["object",[[2,3,!0],[45,0,!0],[3,5,!1]]],["ref",85],["array",252],["object",[[132,253,!1],[149,0,!0],[0,0,!0]]],["object",[[60,1,!0],[0,0,!0]]],["array",1],["object",[[150,256,!1]]],["union",0,61,8],["number",-17976931348623157e292,17976931348623157e292],["enum","Int32","Int64","Decimal","Single"],["string","^-?[0-9]+(\\.[0-9]+)?([Ee][+-]?[0-9]+)?$"],["object",[[151,260,!0],[1,261,!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",[[151,263,!0],[1,264,!0]]],["union",258,259,262,265],["object",[[1,266,!1]]],["ref",36,91],["enum","And","Or"],["object",[[86,268,!0],[87,269,!0],[88,268,!0]]],["ref",8,28,92,135],["object",[[86,271,!0],[87,269,!0],[88,271,!0]]],["object",[[86,77,!0],[87,269,!0],[88,77,!0]]],["ref",47],["array",274],["union",275,8],["ref",67],["array",277],["union",278,8],["ref",150],["array",280],["object",[[74,141,!1],[5,11,!1],[117,207,!1],[41,59,!1],[152,276,!1],[118,209,!1],[9,19,!1],[153,279,!1],[119,61,!0],[31,0,!0],[154,281,!1],[107,191,!1]]],["object",[[68,133,!1],[69,135,!1],[70,135,!1],[71,135,!1],[155,0,!0]]],["object",[[2,3,!0],[64,126,!1],[0,0,!0]]],["enum","Info","Warning","Error","Unknown"],["object",[[68,133,!1],[156,285,!0],[97,0,!0],[98,61,!0],[69,135,!1],[70,135,!1],[71,135,!1]]],["object",[[68,133,!1],[157,0,!0],[69,135,!1],[70,135,!1],[71,135,!1]]],["ref",102],["array",288],["object",[[158,289,!1]]],["object",[[31,0,!0],[1,1,!0]]],["object",[[72,229,!1],[42,86,!1]]],["object",[[41,59,!1],[31,0,!0],[14,112,!1]]],["object",[[159,61,!1],[160,59,!1],[161,59,!1],[162,0,!0],[163,56,!1],[164,56,!1]]],["union",271,8],["object",[[72,229,!1],[145,295,!1],[42,86,!1],[31,0,!0]]],["ref",56],["union",297,8],["ref",73],["union",299,8],["union",268,8],["object",[[45,0,!0],[129,128,!1],[165,298,!1],[166,300,!1],[3,93,!1],[46,96,!1],[47,301,!1]]],["object",[[2,3,!0],[64,126,!1],[42,86,!1],[56,227,!1],[31,0,!0],[167,59,!1],[168,59,!1],[16,36,!1]]],["ref",110],["array",304],["object",[[64,126,!1],[169,305,!1],[31,0,!0]]],["object",[[0,0,!0],[51,1,!0]]],["object",[[170,61,!1],[171,61,!1],[31,0,!0],[39,80,!0]]],["ref",115],["object",[[31,0,!0],[51,309,!0],[39,81,!1]]],["object",[[51,309,!0]]],["ref",116],["array",312],["object",[[128,313,!1]]],["object",[[1,1,!0]]],["object",[[128,93,!1]]],["object",[[31,0,!0],[51,128,!1],[39,80,!0]]],["ref",121],["union",318,8],["array",318],["ref",104],["union",321,8],["object",[[74,141,!1],[126,319,!1],[41,59,!1],[172,320,!1],[173,61,!1],[31,0,!0],[174,322,!1],[175,80,!0],[176,59,!1]]],["object",[[68,133,!1],[69,135,!1],[70,135,!1],[71,135,!1],[146,0,!0]]],["ref",126],["array",325],["object",[[41,59,!1],[31,0,!0],[20,326,!1],[177,301,!1]]],["ref",184],["array",328],["ref",84],["array",330],["union",331,8],["union",147,8],["ref",83,95,136],["object",[[72,229,!1],[178,329,!1],[41,59,!1],[42,86,!1],[179,332,!1],[77,333,!1],[78,152,!1],[51,334,!0]]],["object",[[41,59,!1],[42,86,!1],[31,0,!0],[62,149,!1]]],["object",[[36,59,!1],[126,59,!1],[167,0,!0]]],["object",[[72,229,!1],[41,59,!1],[45,0,!0],[42,86,!1]]],["ref",129],["array",339],["object",[[41,59,!1],[31,0,!0],[167,0,!0],[104,340,!1]]],["object",[[68,133,!1],[69,135,!1],[70,135,!1],[71,135,!1],[127,0,!0]]],["object",[[45,0,!0],[56,128,!1],[133,128,!1]]],["enum","Error","Information","Warning"],["object",[[145,268,!0],[97,59,!1],[180,344,!0]]],["object",[[181,0,!0]]],["enum","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],["union",347,8],["string","^([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](\\.[0-9]{1,7})?$"],["object",[[182,56,!1],[183,348,!1],[184,349,!0]]],["object",[[116,0,!0],[101,59,!1],[102,178,!1]]],["object",[[185,10,!0]]],["object",[[101,59,!1],[0,0,!0]]],["object",[[126,59,!1],[127,0,!0],[39,80,!0]]],["object",[[101,0,!0],[0,0,!0]]],["object",[[126,59,!1],[155,0,!0]]],["ref",137,138,139,141,143,144,145,146,148,149,151,152],["array",357],["object",[[186,358,!1],[31,0,!0]]],["ref",142],["array",360],["object",[[128,361,!1],[187,0,!0]]],["object",[[186,358,!1],[42,86,!1],[31,0,!0]]],["ref",140],["array",364],["object",[[5,11,!1],[188,365,!1],[189,178,!1],[187,0,!0],[107,191,!1]]],["ref",145],["array",367],["object",[[31,0,!0],[106,368,!1]]],["object",[[105,187,!1],[5,11,!1],[190,59,!1],[31,0,!0],[106,189,!1],[107,191,!1]]],["object",[[140,190,!0]]],["object",[[45,0,!0],[62,93,!1]]],["ref",153],["array",373],["object",[[191,0,!0],[132,374,!1]]],["ref",154],["array",376],["object",[[192,377,!1]]],["object",[[68,133,!1],[69,135,!1],[70,135,!1],[71,135,!1],[187,0,!0],[1,0,!0]]],["ref",23],["array",380],["ref",34],["array",382],["array",297],["array",299],["ref",111],["array",386],["ref",122],["array",388],["ref",125],["array",390],["ref",127],["array",392],["union",393,8],["ref",130],["array",395],["union",396,8],["ref",147],["array",398],["ref",174],["array",400],["enum","StateChange","StateView","Automation","Translate"],["object",[[193,381,!1],[194,383,!1],[195,214,!1],[41,59,!1],[132,384,!1],[42,86,!1],[31,0,!0],[196,385,!1],[197,387,!1],[198,389,!1],[199,391,!1],[200,394,!1],[201,397,!1],[202,399,!1],[203,401,!1],[39,402,!0]]],["object",[[204,59,!1],[31,0,!0]]],["object",[[56,1,!0],[31,0,!0]]],["object",[[39,0,!0],[1,0,!0]]],["ref",162],["array",407],["object",[[205,61,!0],[206,408,!1],[207,112,!1]]],["object",[[208,0,!0],[209,93,!1]]],["object",[[210,0,!0]]],["object",[[211,0,!0],[129,128,!1],[212,93,!1],[92,93,!1]]],["object",[[31,59,!1]]],["object",[[213,0,!0],[129,128,!1],[92,93,!1]]],["object",[[214,61,!0],[62,93,!1]]],["ref",171],["array",416],["object",[[68,93,!1],[214,61,!0],[127,0,!0],[215,417,!1]]],["object",[[214,61,!0],[31,0,!0],[62,93,!1]]],["ref",169],["array",420],["ref",163],["union",422,8],["ref",164],["array",424],["ref",165],["union",426,8],["ref",75],["array",428],["ref",173],["array",430],["union",431,8],["ref",161],["array",433],["ref",77],["array",435],["ref",167],["union",437,8],["ref",168],["array",439],["ref",170],["union",441,8],["ref",76],["array",443],["ref",172],["array",445],["ref",119,120],["union",447,8],["ref",166],["union",449,8],["union",420,8],["union",424,8],["ref",176],["union",453,8],["ref",175],["union",455,8],["object",[[42,86,!1],[216,421,!1],[217,423,!1],[218,425,!1],[219,427,!1],[220,429,!1],[221,432,!1],[31,0,!0],[16,36,!1],[222,434,!1],[223,436,!1],[224,438,!1],[225,440,!1],[226,421,!1],[227,61,!0],[228,442,!1],[229,444,!1],[230,446,!1],[231,432,!1],[232,417,!1],[233,448,!1],[47,450,!1],[234,451,!1],[235,452,!1],[236,427,!1],[237,454,!1],[238,456,!1]]],["object",[[146,0,!0],[92,93,!1]]],["object",[[68,93,!1],[127,0,!0]]],["object",[[56,0,!0]]],["ref",181,182],["array",461],["object",[[89,462,!1]]],["object",[[239,112,!1],[31,0,!0]]],["object",[[178,329,!1],[41,59,!1],[42,86,!1],[31,0,!0]]],["object",[[240,61,!0],[241,61,!0],[31,0,!0]]],["object",[[242,59,!1],[243,59,!1],[31,0,!0],[244,112,!1],[245,112,!1],[246,59,!1]]],["object",[[121,214,!1],[45,0,!0],[122,61,!0],[97,59,!1],[31,0,!0],[123,112,!1]]],["object",[[247,112,!1],[121,214,!1],[45,0,!0],[122,61,!0],[97,59,!1],[31,0,!0],[0,0,!0],[123,112,!1]]],["ref",12],["array",470],["object",[[68,471,!1],[185,0,!0]]],["enum","NotEmpty","Max","Min","GreaterThan","GreaterThanOrEqual","LessThan","LessThanOrEqual","Equal","Length","Matches","AllGreaterThan","AllGreaterThanOrEqual","Rule","NotEqual"],["object",[[72,229,!1],[42,86,!1],[134,231,!1],[97,59,!1],[0,0,!0],[248,473,!0],[180,344,!0],[1,128,!1]]],["ref",106],["array",475],["object",[[27,0,!0],[249,476,!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,212,215,216,176,217,72,218,223,228,232,235,236,237,240,241,242,243,242,244,130,245,247,249,249,250,251,254,255,192,257,267,270,272,273,282,193,283,136,284,286,287,290,291,176,292,293,294,193,296,302,199,303,306,307,308,130,310,311,314,315,316,317,323,324,236,327,335,336,337,338,341,342,199,343,345,346,350,351,352,139,353,354,355,356,359,359,362,363,366,369,370,236,371,372,375,378,307,379,403,404,176,405,406,409,410,411,412,72,413,414,72,415,418,419,457,458,459,460,2,315,463,204,236,464,82,465,466,336,467,468,469,472,474,477]};var Hn=be.rules,Pc=new Map(Hn.flatMap(([t,e],n)=>t==="string"&&typeof e=="string"?[[n,new RegExp(e,"u")]]:[])),Yr=new Map(be.kinds.map((t,e)=>[t,Hn[be.contracts[e]][1]])),Oc=new Map([...Yr].map(([t,e])=>[t,new Set(["kind",...e.map(([n])=>be.names[n])])])),Fr=l(t=>typeof t=="object"&&t!==null&&!Array.isArray(t),"object");function Xn(t){let e=Yr.get(t.kind);if(!Object.hasOwn(t,"kind")||e===void 0||!Wr(t,e))throw new J(`Invalid typed members for syntax kind '${t.kind}'.`)}l(Xn,"validateSyntaxMembers");function _t(t,e){let n=Kt(t.kind);for(let i of Object.keys(t))if(!n.has(i)&&!e.has(i))throw new J(`Unknown member '${i}' for syntax kind '${t.kind}'.`)}l(_t,"validateClosedSyntaxMembers");function Kt(t){let e=Oc.get(t);if(e===void 0)throw new J(`Unknown syntax kind '${t}'.`);return e}l(Kt,"syntaxMemberNames");function Wr(t,e){return e.every(([n,i,r])=>Object.hasOwn(t,be.names[n])?ei(t[be.names[n]],i):!r)}l(Wr,"matchesMembers");function Ac(t,e){for(let n=0;n<t.length;n++)if(!Object.hasOwn(t,n)||!ei(t[n],e))return!1;return!0}l(Ac,"allIndicesMatch");function ei(t,e){let[n,...i]=Hn[e];switch(n){case"ref":return Fr(t)&&typeof t.kind=="string"&&i.some(r=>be.kinds[r]===t.kind);case"union":case"one":{let r=i.reduce((o,a)=>o+(ei(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)&&Ac(t,i[0]);case"object":return Fr(t)&&Object.keys(t).every(r=>i[0].some(([o])=>be.names[o]===r))&&Wr(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||Pc.get(e).test(t));default:return n==="boolean"&&typeof t=="boolean"}}l(ei,"matches");var wc=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(","))])),Ic=/^(?:Set|Clear|Increment|Decrement|Count|Add|Subtract)MappingSyntax$/;function Rc(t,e){return wc[t]?.has(e)===!0||Ic.test(t)&&(e==="source"||e==="value")}l(Rc,"isExactOnlyMember");function Ur(t,e){return t.kind==="SpecificationSyntax"&&e==="givenCaller"?t.givenCaller==null:Rc(t.kind,e)||t.kind==="ValidationRuleSyntax"&&t.implementation==null&&(e==="code"||e==="file"||e==="implementation")}l(Ur,"isLegacyOmittedMember");var Ht=l(t=>typeof t=="object"&&t!==null&&typeof t.kind=="string","isNode"),Jt=new Set(["kind","location","targetLocation","referenceLocation","referenceLength","nameWasEscaped"]),Xt=new Set(["ApplicationSyntax","ProjectionSyntax","CaptureSyntax","SpecificationSyntax"]);function tn(t){let e=Tc(t);return ti(e,"legacy",0),en(e)}l(tn,"toSyntaxJson");function Tc(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 p=zr();e.set(o,p);let f=o.length;for(let m=f-1;m>=0;m--)n.push(()=>{p[m]=i(Object.hasOwn(o,m)?o[m]:void 0)});return p}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 p=s.length-1;p>=0;p--)n.push(()=>{let f=s[p],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}l(i,"detach");let r=i(t);for(;n.length>0;)n.pop()();return r}l(Tc,"snapshot");function zr(){let t=[];return Object.defineProperty(t,"toJSON",{value:void 0}),t}l(zr,"dataArray");function en(t,e="legacy",n=!1){if(Array.isArray(t)){let o=zr();for(let a=0;a<t.length;a++)o.push(en(t[a],e,n));return o}if(Ht(t)){if(Xt.has(t.kind)&&(e=Ve(t.sourceOptions??ce).numericMode),_e(t),(t.kind==="ImplementationSyntax"||t.kind==="ImplementationHintSyntax")&&_t(t,Jt),t.kind==="ValidationRuleSyntax"){let f=t;f.implementation!=null&&(f.file!=null&&_t(f.file,Jt),f.code!=null&&_t(f.code,Jt))}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"?Kt(t.kind):void 0,p=Object.keys(a).filter(f=>(s===void 0||s.has(f))&&!(e==="legacy"&&!n&&Ur(t,f))&&!Jt.has(f)&&!(t.kind==="OperationSyntax"&&f==="usesLocation")).sort(Mc);for(let f of p){let m=a[f];f==="sourceOptions"&&m?.numericMode==="legacy"||(o[f]=en(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]=en(i[o],e,n));return r}l(en,"write");function ti(t,e,n){if(n>96&&e==="exact")throw new J("Syntax nesting exceeds the supported depth of 96.");if(Array.isArray(t)){for(let o=0;o<t.length;o++)ti(t[o],e,n+1);return}if(typeof t!="object"||t===null)return;let i=t;if(Xt.has(i.kind)||Object.hasOwn(i,"sourceOptions")){let o=Object.hasOwn(i,"sourceOptions")?Ve(i.sourceOptions):ce;if(n>0&&e!==o.numericMode)throw new J("Conflicting source numeric options.");e=o.numericMode}if(n===0&&e==="exact"&&!Xt.has(i.kind))throw new J("Exact syntax requires a complete source root.");if(e==="exact"&&Ht(i)&&Xn(i),i.kind==="RawExpressionSyntax"&&e==="exact"&&typeof i.text=="string"&&rt(i.text))throw new J("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 J("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"||ve(o.value)?.value!==o.value||Object.keys(o).length!==2)throw new J("Malformed or incompatible ExactNumber literal.")}else if(e==="exact")throw new J("Exact source refuses old or plain object literal insertion.")}}let r=e==="exact"&&Ht(i)?Kt(i.kind):void 0;for(let[o,a]of Object.entries(i))(r===void 0||r.has(o)||Ht(a)&&Xt.has(a.kind))&&o!=="location"&&o!=="targetLocation"&&o!=="usesLocation"&&ti(a,e,n+1)}l(ti,"validateNumbers");function Mc(t,e){return t<e?-1:t>e?1:0}l(Mc,"ordinal");function Vr(t){let e=[],n=t.map(v=>v.value),i=new Map,r=!1;for(let v of n)try{i.set(v,Object.hasOwn(v,"sourceOptions")?Ve(v.sourceOptions):ce)}catch(x){if(!(x instanceof J))throw x;r=!0,e.push(rn(d.IncompatibleNumericSource,x.message,v.location))}let o=n.filter(v=>i.get(v)?.numericMode==="exact"||Dc(v)),a=i.get(o[0])??ce;for(let v of o.slice(1))i.get(v)?.numericMode!==a.numericMode&&(r=!0,e.push(rn(d.MixedNumericModes,"Declaration-bearing documents and marked import barrels must independently select the same numeric mode.",v.location)));r&&(a=Qi);let s=new Map,p=nn(n.flatMap(v=>v.concepts),"declaration of",e,void 0,s),f=nn(n.flatMap(v=>v.types),"declaration of",e,void 0,s),m=n.map(v=>v.domain).filter(v=>v!==null);for(let v of m.slice(1))e.push(rn(d.RepeatedSingularDeclarationAcrossFiles,`The folder already declares a domain in '${on(m[0].location.path)}' - a folder compiles to one application, which can have at most one`,v.location));let y=jc(n.flatMap(v=>v.modules),e),u=nn(n.flatMap(v=>v.personas),"persona",e),S={kind:"ApplicationSyntax",sourceOptions:a,domain:m[0]??null,imports:Lc(n.flatMap(v=>v.imports),v=>v.qualifiedName),concepts:p,types:f,systems:n.flatMap(v=>v.systems??[]),eventSources:n.flatMap(v=>v.eventSources??[]),modules:y,personas:u,policies:n.flatMap(v=>v.policies??[]),seeds:n.flatMap(v=>v.seeds??[]),fileImports:n.flatMap(v=>v.fileImports),location:n[0]?.location??{line:1,column:1}},b=[...t.flatMap(v=>v.diagnostics),...e];return{value:S,diagnostics:b,success:!b.some(v=>v.severity==="error")}}l(Vr,"mergeDocuments");function Dc(t){if(_i(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=l(n=>!n.isPlacement||n.slices.length>0||n.features.some(e),"feature");return t.modules.some(n=>!n.isPlacement||n.features.some(e))}l(Dc,"hasDeclarations");function jc(t,e){return _r(t).map(Gr).map(n=>n.length===1?{...n[0],isPlacement:!1,features:n[0].features.map(ni)}:{...n[0],isPlacement:!1,fileImports:n.flatMap(i=>i.fileImports),description:Kr(n,`module '${n[0].name}'`,e),authorize:Zr(n.map(i=>i.authorize),`module '${n[0].name}'`,e),features:Qr(n.flatMap(i=>i.features),e)})}l(jc,"mergeModules");function Qr(t,e){return _r(t).map(Gr).map(n=>n.length===1?ni(n[0]):{...n[0],isPlacement:!1,fileImports:n.flatMap(i=>i.fileImports),description:Kr(n,`feature '${n[0].name}'`,e),authorize:Zr(n.map(i=>i.authorize),`feature '${n[0].name}'`,e),features:Qr(n.flatMap(i=>i.features),e),slices:nn(n.flatMap(i=>i.slices),"slice",e,`feature '${n[0].name}'`)})}l(Qr,"mergeFeatures");function Gr(t){return[...t.filter(e=>!e.isPlacement),...t.filter(e=>e.isPlacement)]}l(Gr,"placedLast");function ni(t){return{...t,isPlacement:!1,features:t.features.map(ni)}}l(ni,"unplaced");function Zr(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(tn(a))===JSON.stringify(tn(r)));if(o!==void 0){n.push(Jr(d.DuplicateAuthorizationAcrossFiles,`An identical authorization is already declared on the ${e} in '${on(o.location.path)}' - this repeated gate is ignored`,r.location));continue}i.push(r)}return i.reduce((r,o)=>he(r,o),null)}l(Zr,"combineAuthorization");function Lc(t,e){let n=new Set;return t.filter(i=>!n.has(e(i))&&n.add(e(i))!==void 0)}l(Lc,"firstOfEach");function _r(t){let e=new Map;for(let n of t)e.set(n.name,[...e.get(n.name)??[],n]);return[...e.values()]}l(_r,"groupByName");function Kr(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(Jr(d.ConflictingDescriptionAcrossFiles,`The ${e} is already described in '${on(i[0].location.path)}' - keeping that description`,r.location));return i[0]?.description??null}l(Kr,"firstDescription");function nn(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(rn(d.RepeatedDeclarationAcrossFiles,`Duplicate ${e} '${a.name}'${i===void 0?"":` in ${i}`} - already declared in '${on(s.path)}'`,a.location));continue}s===void 0&&r.set(a.name,a.location),o.push(a)}return o}l(nn,"declaredInOneFile");var on=l(t=>t??"another file","describe"),rn=l((t,e,n)=>({severity:"error",code:t,message:e,location:n}),"error"),Jr=l((t,e,n)=>({severity:"warning",code:t,message:e,location:n}),"warning");function Xr(t,e){return Bc(t,e).result}l(Xr,"parsePlacedDocuments");function Bc(t,e){let n=Qe.capturePlaced(t.filter(u=>u.isPlacementResolved!==!1).map(u=>({lines:Ne(u.source,!1,u.path),placement:u.placement})),e),i=t.map(u=>De(u.source,u.path,u.isPlacementResolved===!1?[]:u.placement,!1,n,e)),r=i.flatMap((u,S)=>(u.value.eventSources??[]).map(b=>({source:b,placementResolved:t[S].isPlacementResolved!==!1}))),o=t.every(u=>u.isPlacementResolved!==!1)&&i.every(u=>!Ge.hasUnknownExtent(u.diagnostics)),a=i.map((u,S)=>t[S].isPlacementResolved===!1?{...u,value:{...u.value,eventSources:[]}}:u),s=Vr(a),p=new ue(new Me([]),void 0,e);s.value.sourceOptions!==void 0&&(p.sourceOptions=s.value.sourceOptions),Qt(s.value,p),Ut(s.value,p),Wt(s.value,p),Bt(s.value,p,a.flatMap(u=>u.inputUses));let f=s.diagnostics,m=new Set(f.map(Hr)),y=[...f,...p.diagnostics.filter(u=>!m.has(Hr(u)))];return{result:{...s,diagnostics:y,success:!y.some(u=>u.severity==="error"),physicalEventSources:r,sourceInventoryComplete:o},syntax:new Map(a.map((u,S)=>[t[S].path,u.value]))}}l(Bc,"parsePlacedDocumentsWithSyntax");function Hr(t){return JSON.stringify([t.code,t.location.path,t.location.line,t.location.column])}l(Hr,"diagnosticKey");var Yv="Executable as ESM v7. Generated values require fixtures in reference execution; other unadmitted constructs still prevent binding.",yt=new Map;function Fc(t,e){let n=ie(t),i=t.flatMap((y,u)=>!n[u]&&z(y)===0&&/^\w/.test(y)?[y.split(/\s+/)[0]]:[]);if(i.includes("module")||!i.some(y=>["feature","slice","command","event","operation","reaction","specification"].includes(y)))return{source:t.join(`
7
- `),locations:t.map((y,u)=>({line:u+1,column:0}))};let r=[],o=[],a=!1;t.forEach((y,u)=>{!n[u]&&z(y)===0&&/^\w/.test(y)&&(a=/^(?:concept|type|import|domain|system|eventsource)\b/.test(y)),(a?r:o).push(u)});let s=i.includes("feature")?1:i.includes("slice")?2:3,p=e.slice(0,s),f=[...r.map(y=>t[y]),...p,...o.map(y=>" ".repeat(s*2)+t[y])].join(`
8
- `),m=[...r.map(y=>({line:y+1,column:0})),...p.map(()=>({line:0,column:0})),...o.map(y=>({line:y+1,column:s*2}))];return{source:f,locations:m}}l(Fc,"authoringSource");function Yc(t,e,n,i="current.play",r=!0){let o=e.map((O,T)=>typeof O=="string"?{path:`other-${T}.play`,source:O}:O).filter(O=>O.path!==i),a=[{path:i,source:t.join(`
9
- `),placement:n,isPlacementResolved:r},...o],s=new Set(a.flatMap(O=>[...O.source.matchAll(/\w+/g)].map(T=>T[0]).concat(O.placement??[]))),p=l(O=>{let T=O;for(let D=1;s.has(T);D++)T=`${O}${D}`;return s.add(T),T},"fresh"),f=p("EditorAuthoring"),m=p("FragmentFeature"),y=new Set([f,m]),u=a.map((O,T)=>{let D=T===0?t:O.source.split(`
10
- `),L=p(`Fragment${T}`);y.add(L);let He=O.placement?.length?{source:O.source,locations:D.map((ln,xt)=>({line:xt+1,column:0}))}:Fc(D,[`module ${f}`,` feature ${m}`,` slice StateChange ${L}`]);return{...O,...He,placement:O.placement??[]}}),S=u[0],b=new Map(u.map(O=>[O.path,O.locations])),v=Xr([...u.slice(1),S]),x=new Map,g=new Map,k=new WeakSet,E=l(O=>{if(O===null||typeof O!="object"||k.has(O))return;if(k.add(O),Array.isArray(O)){O.forEach(E);return}let T=O;if(typeof T.path=="string"&&typeof T.line=="number"&&typeof T.column=="number"){let D=b.get(T.path)?.[T.line-1];D&&(T.line=D.line,T.column=Math.max(1,T.column-D.column));return}for(let D of Object.values(T))E(D);T.location?.path===i&&(T.kind==="CommandSyntax"&&x.set(T.location.line-1,O),T.kind==="SpecificationSyntax"&&g.set(T.location.line-1,O))},"walk");E(v.value),E(v.physicalEventSources);for(let O of v.diagnostics)E(O.location);let P=v.diagnostics.some(O=>{if(!["PLAY0022","PLAY0024","PLAY0029"].includes(O.code))return!1;let T=u.find(L=>L.path===O.location.path),D=a.find(L=>L.path===O.location.path)?.source.split(`
11
- `)[O.location.line-1];return T?.locations.some(L=>L.line===0)&&D!==void 0&&z(D)===0}),h=v.diagnostics.filter(O=>O.location.path===i).flatMap(O=>(E(O.location),O.location.line>0?[O]:[])),C=new $e(v.value),A=new Set(C.slices.flatMap(({slice:O})=>[...O.commands.flatMap(T=>T.produces),...O.reactions.flatMap(T=>T.triggers).flatMap(T=>T.produces)].filter(T=>T.location.path===i&&!C.isEventProduction(T,O)).map(T=>T.location.line-1)));for(let O of h)O.code==="PLAY0499"&&A.add(O.location.line-1);let w=C.declarations.filter(O=>O.kind===_.Operation).map(O=>({...O.node,scope:O.scope.filter(T=>!y.has(T))})),I=new Map,q=ie(t),B=l(O=>{let T=[],D=z(t[O]);for(let L=O;L<t.length&&!(L>O&&!q[L]&&Ie(t[L]).trim()&&z(t[L])<=D);L++)T.push(L);return T},"range");for(let{slice:O,scope:T}of C.slices){if(O.location.path===i&&O.location.line>0)for(let D of B(O.location.line-1))I.set(D,{scope:T});for(let D of O.specifications.filter(L=>L.location.path===i&&L.location.line>0))for(let L of B(D.location.line-1))I.set(L,{scope:T});for(let D of O.commands.filter(L=>L.location.path===i&&L.location.line>0))for(let L of B(D.location.line-1))I.set(L,{scope:T,commandLine:D.location.line-1})}let M=new Map(C.declarations.map(O=>[O.node.location,O.scope]));for(let O of w.filter(T=>T.location.path===i)){let T=M.get(O.location);for(let D of B(O.location.line-1))I.set(D,{...I.get(D),scope:T,operation:O})}let j=new Map(w.map(O=>[O.location,O])),N=l((O,T)=>{let D=Ie(t[O.line-1]??""),L=D.slice(O.column-1).match(/^(?:given\s+operation|then\s+(?:operation|compensated))\s+/)?.[0];return L&&D.slice(O.column-1+L.length,O.column-1+L.length+T.length)===T?{...O,column:O.column+L.length}:O},"referenceLocation"),F=[];for(let{slice:O}of C.slices){for(let T of O.commands)for(let D of T.produces){if(D.location.path!==i)continue;let L=C.resolve(D.event,O),He=L.declaration?j.get(L.declaration.node.location)??null:null,ln={name:D.event,location:D.location,targetLocation:D.targetLocation??D.location,kind:L.kind,declaration:He,mappings:D.mappings};if(F.push(ln),L.kind===_.Operation)for(let xt of B(D.location.line-1)){let mi=I.get(xt);mi&&I.set(xt,{...mi,production:ln})}}for(let T of O.specifications)for(let D of[...T.givenOperationFailures??[],...T.thenOperations??[],...T.thenCompensated??[]]){if(D.location.path!==i)continue;let L=C.resolve(D.operation,O);F.push({name:D.operation,location:D.location,targetLocation:N(D.location,D.operation),kind:L.kind,declaration:L.declaration?j.get(L.declaration.node.location)??null:null,mappings:[]})}}let V={declarations:w,systems:v.value.systems??[],references:F,contexts:I,types:v.value.types,concepts:v.value.concepts,targets:l(O=>{let T=C.slices.find(D=>D.scope.length===O.length&&D.scope.every((L,He)=>L===O[He]))?.slice;return T?w.flatMap(D=>{let L=C.resolve(D.name,T).declaration?.node.location===D.location?D.name:[...D.scope,D.name].join(".");return C.resolve(L,T).kind===_.Operation&&C.resolve(L,T).declaration?.node.location===D.location?[{name:L,declaration:D}]:[]}):[]},"targets")},X=v.physicalEventSources.map(O=>O.source),Se=new Ge(v.physicalEventSources,v.sourceInventoryComplete&&!P),Ce=new Map,ui=l((O,T)=>{let D=JSON.stringify([O,T]),L=Ce.get(D);return L||(L=Se.resolve(O,T),Ce.set(D,L)),{...L,source:L.state==="unique"?L.sources[0]:void 0,stream:L.state==="unique"?L.streams[0]:void 0}},"resolve"),ao=new Set(v.value.imports.map(O=>O.qualifiedName)),so=X.flatMap(O=>O.streams.filter(T=>ui(O.name,T.name).state==="unique"&&!ao.has(`${O.name}.${T.name}`)).map(T=>({name:`${O.name}.${T.name}`,source:O,stream:T}))),Le=new Map,yi=[];for(let O of x.values()){for(let T of B(O.location.line-1))Le.set(T,{command:O});for(let T of[...O.produces,...O.validations,...O.handler?[O.handler]:[]])for(let D of B(T.location.line-1))Le.delete(D);if(O.stream){yi.push(O.stream);for(let T of B(O.stream.location.line-1))Le.set(T,{command:O,route:O.stream})}}for(let O of X.filter(T=>T.location.path===i)){for(let T of B(O.location.line-1))Le.set(T,{source:O});for(let T of O.streams)for(let D of B(T.location.line-1))Le.set(D,{source:O,stream:T})}let lo=[...x.values()].flatMap(O=>O.streamCandidates??[]).filter(O=>O.propertyCandidate!==null);return{commands:x,specifications:g,diagnostics:h,operationProductionLines:A,operations:V,eventSources:{declarations:X,routes:yi,ambiguousCandidates:lo,contexts:Le,targets:so,resolve:ui}}}l(Yc,"analyze");function Ke(t,e=[],n,i="current.play",r=!0){let o=JSON.stringify([t,e,n,i,r]),a=yt.get(o);return a===void 0&&(a=Yc(t,e,n,i,r),yt.size>=16&&yt.delete(yt.keys().next().value),yt.set(o,a)),a}l(Ke,"responseAnalysis");var ii="file",Wc=/^[A-Za-z_]\w*(?:\[\])?(?:\?|\s+optional)?$/,Uc=/^(?:[/\\]|[A-Za-z]:[/\\]|~[/\\])/;function Vv(t){return Uc.test(t)}l(Vv,"isAbsoluteFileReferencePath");function zc(t){let e=!1,n=!1;for(let i=0;i<t.length;i++){let r=t[i];if(r==="\\"&&e&&i+1<t.length)i++;else if(r==='"'&&!n)e=!e;else if(r==="`"&&!e)n=!n;else if(!e&&!n&&r==="/"&&t[i+1]==="/")return t.slice(0,i)}return t}l(zc,"withoutComment");function ri(t,e){let n=z(t),i=zc(t.slice(n)).trimEnd();if(un(i)!==ii)return;let r=i.slice(ii.length),o=r.trim();if(o.length===0||Wc.test(o))return;let a=r.length-r.trimStart().length,s=n+ii.length+a+1;return{path:o,line:e,startColumn:s,endColumn:s+o.length}}l(ri,"fileReferenceOn");function Qv(t){let e=ie(t),n=[];for(let i=0;i<t.length;i++){if(e[i])continue;let r=ri(t[i],i);r&&n.push(r)}return n}l(Qv,"fileReferences");function Ae(t){let e=!1;return t.map(n=>{if(e)return n.trim()==="```"&&(e=!1),n;let i=Ie(n);return/^\s*```(?:[a-z]+)?\s*$/.test(i)&&(e=!0),i.trimEnd()})}l(Ae,"eventAnalysisSource");var Vc=/^concept\s+(\w+)\s*:\s*(\w+)((?:\s+@\w+)*)\s*$/,Qc=/^\s*(@?[a-z_]\w*)\s+([\w.]+(?:\[\])?(?:\?|\s+optional)?)(\s+generated)?(\s+identifier)?\s*$/,eo=/^([a-z_]\w*)\s+reason\s+"((?:[^"\\]|\\.)*)"\s*$/,Gc=/^\s*reads\s+([A-Z]\w*)(?:\s+as\s+([a-z_]\w*))?(?:\s+by\s+([a-z_]\w*))?\s*$/,Zc=["authorize","produces","reads"],_c=/^(?:(?:or|and)\s+)?[A-Za-z_(][\p{L}\p{Mn}\p{Nd}\p{Pc}\s()]*$/u,Kc=it,Jc=["tag","for","generation","origin","namespace","sequence","correlation","causation","causedBy","occurred"],Hc=/^\s*(?:by|filter)\s+([a-z_]\w*)\s+([\w.]+(?:\[\])?(?:\?|\s+optional)?)(?:\s+from\s+.+)?\s*$/;function we(t){return t.typeReference??Xe(t.type)}l(we,"propertyTypeReference");function oi(t,e){let n=t.slice(e-1).match(/^[\p{L}\p{Mn}\p{Nd}\p{Pc}.]+(?:\[\])?(?:\?|\s+optional\b)?/u)?.[0]??"";return{text:n,startColumn:e,endColumn:e+n.length}}l(oi,"sourceTypeAt");function ai(t,e,n){return e.map(i=>({index:i,match:t[i].match(Qc)})).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:Xe(r[2]),sourceType:oi(t[i],t[i].match(/^\s*\S+\s+/)[0].length+1),isIdentifier:r[4]!==void 0,...r[3]!==void 0?{isGenerated:!0}:{},line:i}))}l(ai,"propertiesIn");function St(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(z(a)<=i)break;r.push(o)}}return r}l(St,"collectBody");function Je(t,e,n,i){let r=St(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 p=z(t[s]),f=t[s].trim();return o!==void 0&&p>o&&(!a||_c.test(f))?!1:(o=f!=="validate csharp"&&ai(t,[s],Zc).length>0||/^description(?:\s|$)/.test(f)?void 0:p,a=/^authorize(?:\s|$)/.test(f),!0)})}l(Je,"directBody");var mt=new Map;function ht(t){let e=t.join(`
12
- `),n=mt.get(e);if(n)return n;let i=Ke(t),r={authoringSources:[e],eventSources:i.eventSources.declarations,imports:[],concepts:[],types:[],policies:[],events:[],commands:[],queries:[],screens:[],triggers:[]};t=Ae(t);let o=ie(t),a=t,s=o,p=t.map(f=>f.replace(/\s*=(?!=|>).*/,""));for(let f=0;f<t.length;f++){if(o[f])continue;let m=t[f],y=m.trim(),u=z(m),S=a[f].trim().match(/^import\s+([\w.]+)\s*$/);if(S&&u===0){let C=S[1],A=C.split(".").pop()??C;r.imports.push({qualifiedName:C,shortName:A,line:f});continue}let b=y.match(Vc);if(b){let C=St(t,o,f,u).map(I=>t[I].trim()),A={};for(let I of C){let q=I.match(eo);q&&A[q[1]]===void 0&&(A[q[1]]=q[2])}let w=b[2]==="Enum"?C.filter(I=>!eo.test(I)):[];r.concepts.push({name:b[1],primitive:b[2],attributes:b[3].trim().split(/\s+/).filter(Boolean),attributeReasons:A,enumValues:w,line:f});continue}let v=y.match(/^type\s+(\w+)\s*$/);if(v){r.types.push({name:v[1],properties:ai(t,St(t,o,f,u),Si),line:f});continue}let x=y.match(/^policy\s+(\w+)\s*$/);if(x){let C=St(t,o,f,u).filter(A=>!o[A]).map(A=>t[A].trim());r.policies.push({name:x[1],requires:C,line:f});continue}let g=a[f].trim().match(/^(?:produces\s+)?event\s+(\w+)(?:\s+generation\s+(\d+))?\s*$/);if(g){let C=y.startsWith("produces "),A=Je(a,s,f,u),w=C?A:A.filter(I=>ri(a[I],I)===void 0);r.events.push({name:g[1],...g[2]?{generation:Number(g[2])}:{},inline:C,properties:ai(C?p:a,w,C?Jc:Kc),line:f});continue}let k=i.commands.get(f);if(k){let C=Je(t,o,f,u),A=C.filter(w=>/^\s*produces\b/.test(t[w])&&!i.operationProductionLines?.has(w));r.commands.push({name:k.name,properties:k.properties.map(w=>({name:w.name,type:`${w.type.name}${w.type.isCollection?"[]":""}${w.type.isOptional?" optional":""}`,typeReference:{name:w.type.name,isCollection:w.type.isCollection,isOptional:w.type.isOptional},sourceType:oi(t[w.type.location.line-1],w.type.location.column),isIdentifier:w.isIdentifier||/\sidentifier\s*$/.test(t[w.location.line-1]),...w.isGenerated?{isGenerated:!0}:{},line:w.location.line-1})),response:k.response,productionHeaders:A,produces:A.flatMap(w=>{let I=a[w].trim(),q=/^produces\s+event\b/.test(I),B=/^produces\s+when\b/.test(I),M=B?Je(a,s,w,z(a[w]))[0]:w;if(M===void 0)return[];let j=B?a[M].trim():I.match(q?/^produces\s+event\s+([A-Za-z_]\w*)(?:\s+generation\s+\d+)?\s*$/:/^produces\s+([A-Z]\w*)\s*$/)?.[1];if(j===void 0||!/^[A-Za-z_]\w*$/.test(j))return[];let N=Je(a,s,M,z(a[M])),F=N.map(Se=>a[Se].trim().match(/^for(?:\s+(.*))?$/)).filter(Se=>Se!==null),V=F.length===0?void 0:F.length===1?F[0][1]??"":"",X=N.flatMap(Se=>{let Ce=a[Se].trim().match(q?/^(@?[a-z_]\w*)\s+[\w.]+(?:\[\])?(?:\?|\s+optional)?\s*=(?!=|>)\s*(.+)$/:/^(@?[\w.]+)\s*=(?!=|>)\s*(.+)$/);return Ce===null?[]:[{name:Ce[1].replace(/^@/,""),source:Ce[2],line:Se}]});return[{name:j,inline:q,conditional:B,line:w,target:V,mappings:X}]}),reads:C.filter(w=>!o[w]).map(w=>({line:w,match:t[w].match(Gc)})).filter(w=>w.match!==null).map(({line:w,match:I})=>({view:I[1],...I[2]?{alias:I[2]}:{},...I[3]?{by:I[3]}:{},line:w})),line:f});continue}let E=y.match(/^query\s+(\w+)\s*=>\s*(?:observable\s+)?([\w.]+(?:\[\])?(?:\?|\s+optional)?)\s*$/);if(E){let C=St(t,o,f,u).map(A=>({index:A,match:t[A].match(Hc)})).filter(A=>A.match!==null).map(({index:A,match:w})=>({name:w[1],type:w[2],typeReference:Xe(w[2]),sourceType:oi(t[A],t[A].match(/^\s*(?:by|filter)\s+\S+\s+/)[0].length+1),isIdentifier:!1,line:A}));r.queries.push({name:E[1],returnType:E[2],returnTypeReference:Xe(E[2]),parameters:C,line:f});continue}let P=y.match(/^screen\s+(\w+)\s*$/);if(P){r.screens.push({name:P[1],line:f});continue}let h=y.match(/^trigger\s+(\w+)\s*$/);h&&u===0&&r.triggers.push({name:h[1],line:f})}return mt.size>=16&&mt.delete(mt.keys().next().value),mt.set(e,r),r}l(ht,"scanDocument");function an(...t){return{authoringSources:t.flatMap(e=>e.authoringSources??[]),...t.some(e=>e.authoringDocuments)?{authoringDocuments:t.flatMap(e=>e.authoringDocuments??[])}:{},eventSources:t.flatMap(e=>e.eventSources??[]),imports:t.flatMap(e=>e.imports),concepts:t.flatMap(e=>e.concepts),types:t.flatMap(e=>e.types),policies:t.flatMap(e=>e.policies),events:t.flatMap(e=>e.events),commands:t.flatMap(e=>e.commands),queries:t.flatMap(e=>e.queries),screens:t.flatMap(e=>e.screens),triggers:t.flatMap(e=>e.triggers)}}l(an,"mergeSymbols");function to(t,e){let n=e?.authoringPath??"current.play",i=e?.authoringDocuments?.find(r=>r.path===n);return{...an(ht(t),e??an()),authoringDocuments:e?.authoringDocuments,authoringPath:n,authoringPlacement:e?.authoringPlacement??i?.placement,authoringPlacementResolved:e?.authoringPlacementResolved??i?.isPlacementResolved}}l(to,"symbolsForBuffer");function sn(t){return[...t.events.map(e=>e.name),...t.imports.map(e=>e.shortName)]}l(sn,"knownEventNames");var Xc=["Startup","Shutdown"];function sk(t){return[...sn(t),...t.triggers.map(e=>e.name),...Xc]}l(sk,"knownTriggerNames");function si(t,e){return[...e,...t.concepts.map(n=>n.name),...t.types.map(n=>n.name),...t.imports.map(n=>n.shortName)]}l(si,"knownTypeNames");var no="EventContext",gt={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."}]},ed=[{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 li(t,e){if(t.kind==="function")return e===t.name||e===`${t.name}()`;let n=t.name[0].toUpperCase()+t.name.slice(1);return e===n||e.length>0&&e[0].toUpperCase()+e.slice(1)===n}l(li,"namesEventContextMember");var ci=gt[no];function td(t){let e=ci;for(let n of t){let i=e.find(r=>li(r,n));if(!i||i.kind==="collection"||i.kind==="function")return;e=gt[i.type]??[]}return e}l(td,"eventContextMembersAfter");function fk(t){return t.length===0?void 0:td(t.slice(0,-1))?.find(n=>li(n,t[t.length-1]))}l(fk,"eventContextMemberAt");function di(t){let e,n=ci;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=>li(o,i));if(!r)return{status:e?"unknownSubPath":"unknownMember",member:e,segment:i,expected:n};e=r,n=r.kind==="function"?[]:gt[r.type]??[]}return{status:"known",member:e,expected:[]}}l(di,"resolveEventContextPath");function uk(){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:**",...ci.map(t=>`- \`${t.name}\` (${t.type}) - ${t.description}`)].join(`
13
- `)}l(uk,"describeEventContext");function yk(t,e){let n=e.kind==="collection"||e.kind==="function"?[]:gt[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
- `)}l(yk,"describeEventContextMember");function pi(t){let e=t.properties.filter(o=>o.isIdentifier&&!we(o).isOptional&&!we(o).isCollection),n=e.length===1?e[0].name:void 0,i=t.produces??[],r=i.some(o=>o.target!==void 0&&o.target!==n)||i.some(o=>o.inline&&o.target===void 0)&&i.some(o=>!o.inline&&o.target===void 0);return{identifier:n,mixed:r}}l(pi,"productionDestinations");function kk(t,e){let n=Ke(t,e?.authoringDocuments??e?.authoringSources,e?.authoringPlacement,e?.authoringPath),i=Ae(t);return ht(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}=pi(r);if(a||r.productionHeaders?.length!==r.produces?.length)return[];let s=r.produces?.some(p=>p.target!==void 0||p.inline);return(r.produces??[]).flatMap(p=>p.target!==void 0||p.inline&&(o===void 0||/\bgeneration\b/.test(i[p.line]))?[]:!p.inline&&s?[]:[{line:p.line,column:i[p.line].length+1,label:p.inline?`for ${o}`:"for <new event source>"}])})}l(kk,"destinationHints");var Y={invalidEventSourceDeclaration:"PLAY0503",invalidCommandStream:"PLAY0504",ambiguousCommandStream:"PLAY0505",unsupportedStreamIdType:"PLAY0506",redundantSourceStreamId:"PLAY0507",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 nd=/^import(\s+)"([^"\\]+)"\s*(?:\/\/.*)?$/,id=/^import\s+"/;function ro(t){return id.test(t.trim())}l(ro,"isFileImportLine");function fi(t,e){let n=z(t),i=t.slice(n).match(nd);if(!i)return;let r=n+6+i[1].length+2;return{pattern:i[2],line:e,startColumn:r,endColumn:r+i[2].length}}l(fi,"fileImportOn");function Ok(t){let e=ie(t),n=[];for(let i=0;i<t.length;i++){if(e[i])continue;let r=fi(t[i],i);r&&n.push(r)}return n}l(Ok,"fileImports");var io=l(t=>t.split("/").slice(0,-1),"folderOf");function rd(t,e){let n=e.split("/"),i=0;for(;i<t.length&&i<n.length-1&&t[i]===n[i];)i++;return[...t.slice(i).map(()=>".."),...n.slice(i)].join("/")}l(rd,"relativeTo");function Ak(t,e){let n=io(t),i=new Set;for(let r of e.filter(o=>o!==t&&o.toLowerCase().endsWith(".play"))){let o=rd(n,r),a=io(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()}l(Ak,"importablePaths");var od=new Set(["namespace","sequence","correlation","causation","causedBy","occurred"]),ad=/^id\s+"((?:[^"\\]|\\.)*)"$/;function oo(t,e,n,i=new Set){t=Ae(t);let r=[],o=ie(t),a=sd(t,o),s=new Set(e.commands.flatMap(u=>u.productionHeaders??[])),p=new Map,f=new Set;for(let u of[e,n]){for(let S of u.events)p.set(S.name,(p.get(S.name)??0)+1);for(let S of u.imports)f.add(S.shortName)}let m=l((u,S,b,v="error")=>{r.push({line:u,startColumn:z(t[u])+1,endColumn:t[u].length+1,code:S,message:b,severity:v})},"report");for(let u of e.events){let S=Je(t,o,u.line,z(t[u.line]));if(u.inline){let x=new Set;for(let g of u.properties)x.has(g.name)&&m(g.line,Y.duplicateDeclaration,`Event '${u.name}' already declares property '${g.name}'.`),x.add(g.name);s.has(u.line)||m(u.line,Y.inlineEventOutsideCommand,"Inline events can only be declared inside commands."),u.generation!==void 0&&m(u.line,Y.inlineEventGeneration,"Inline events are generation 1; extract the event before declaring generations."),((p.get(u.name)??0)>1||f.has(u.name))&&m(u.line,Y.inlineEventCollision,`Inline event '${u.name}' collides with another declaration or import.`)}let b=!1,v=!1;for(let x of S){let g=t[x].trim(),k=g.split(/\s+/)[0];if(u.inline&&k==="generation"&&m(x,Y.inlineEventGeneration,"Inline events are generation 1; extract the event before declaring generations."),u.inline&&k==="origin"&&m(x,Y.reservedProductionMetadata,"An inline event is local to its command and cannot declare origin."),!/^(?:id|description|documentation)\s+[\w.]+(?:\[\])?(?:\?|\s+optional)?(?:\s*=.*)?$/.test(g)){if(k==="id"){let E=g.match(ad);b||E===null||E[1].trim().length===0?m(x,Y.invalidEventId,'Expected one nonempty id "<old-name>".'):E[1]===u.name&&m(x,Y.redundantEventId,"This id repeats the event name; remove it.","information"),b=!0}if(k==="documentation"){let E=x+1;for(;E<t.length&&t[E].trim().length===0;)E++;(v||g!=="documentation"||t[E]?.trim()!=="```markdown"||z(t[E])<=z(t[x])||!a.has(E))&&m(x,Y.invalidEventDocumentation,"Expected one nonempty fenced markdown documentation block."),v=!0}}}}let y=[];for(let u=0;u<t.length;u++){if(o[u]||t[u].trim().length===0)continue;let S=z(t[u]);for(;y.length>0&&y[y.length-1].indent>=S;)y.pop();let b=t[u].trim().split(/\s+/)[0];od.has(b)&&y.at(-1)?.event&&m(u,Y.reservedProductionMetadata,`'${b}' is system-assigned production metadata.`),b==="produces"&&y.push({indent:S,event:!i.has(u)&&!/^\s*produces\s+operation\b/.test(t[u])})}for(let u of e.commands){let{identifier:S,mixed:b}=pi(u);for(let v of u.produces??[]){b&&v.target===void 0&&m(v.line,Y.explicitProducesTargetsRequired,`Production '${v.name}' must state for explicitly when destinations differ.`);let x=v.target??(v.inline?S:void 0);if(!(S===void 0||x!==S))for(let g of v.mappings.filter(k=>k.source===S))m(g.line,Y.eventSourceIdInPayload,`The payload copies '${S}', which already identifies the event source.`,v.inline?"warning":"information")}}return r}l(oo,"validateInlineEvents");function sd(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}l(sd,"nonemptyMarkdownBlocks");function de(t,e,n,i,r,o){return{severity:t,message:r,line:e,startColumn:n,endColumn:n+i,code:o}}l(de,"issue");function me(t,e,n,i,r,o){let a=n.indexOf(i)+1;return de(t,e,a,i.length,r,o)}l(me,"tokenIssue");function ld(t,e,n){let i=[],r=new Set([...si(e,$t),...si(n,[])]),o=l((s,p)=>{for(let f of s.filter(m=>!r.has(we(m).name))){let m=we(f).name;i.push(de("warning",f.line,f.sourceType.startColumn,f.sourceType.text.length,m==="optional"?`Unknown type 'optional' on '${f.name}' of ${p} \u2014 did you forget the type before 'optional'?`:`Unknown type '${m}' on '${f.name}' of ${p} \u2014 declare it with 'concept ${m} : <Primitive>' or 'type ${m}'.`,Y.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 p=s.properties.filter(f=>f.isIdentifier);for(let f of p.slice(1))i.push(me("error",f.line,t[f.line],"identifier",`Command '${s.name}' already marks '${p[0].name}' as identifier \u2014 only one property can be the identifier.`,Y.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(me("error",s.line,t[s.line],s.name,`Duplicate declaration of '${s.name}' \u2014 concept and type names must be unique.`,Y.duplicateDeclaration))}return i}l(ld,"validateDeclarations");function eb(t,e={}){let n=ie(t),i=ht(t),r=e.application??an(),o=to(t,{...r,authoringPath:e.path??r.authoringPath,authoringPlacement:e.placement??r.authoringPlacement}),a=Ke(t,o.authoringDocuments??o.authoringSources?.filter(x=>x!==t.join(`
15
- `)),o.authoringPlacement,o.authoringPath,o.authoringPlacementResolved),s=new Set(a.eventSources.routes.map(x=>x.location.line-1)),p={...i,commands:i.commands.map(x=>({...x,properties:x.properties.filter(g=>!s.has(g.line)),produces:x.produces?.filter(g=>!a.operationProductionLines?.has(g.line)),productionHeaders:x.productionHeaders?.filter(g=>!a.operationProductionLines?.has(g))}))},f=new Set([...sn(p),...sn(r)]),m=new Set([...p.policies,...r.policies].map(x=>x.name)),y=ld(t,p,r);y.push(...cd(t,p));let u=new Set([d.LegacyOptionalSuffix,d.InvalidOptionalModifierOrder,d.OptionalReadsNotSupported]);for(let x of e.compilerDiagnostics??a.diagnostics){if(!u.has(x.code)&&x.code!==d.UnknownRuleImplementationDirective&&x.code!==d.InvalidValidationRule&&x.code!==d.RepeatedDeclarationAcrossFiles&&!/^PLAY049[0-9]$|^PLAY050[0-7]$|^PLAY048[2-9]$|^PLAY004[56]$/.test(x.code))continue;let g=x.location.line-1,k=Jn(t[g],x)||t[g].length-x.location.column+1;y.push(de(x.severity,g,x.location.column,k,x.message,x.code))}let S=l((x,g,k)=>{f.has(k)||y.push(me("warning",x,g,k,`Unknown event type '${k}' \u2014 declare it in a slice or import it.`,Y.unknownEvent))},"checkEvent"),b=-1;for(let x=0;x<t.length;x++){let g=t[x],k=g.trim();if(n[x]||k.length===0)continue;let E=g.match(/^[ ]*(\t+)/);if(E&&y.push(de("warning",x,E[0].length-E[1].length+1,E[1].length,"Screenplay is indentation-based \u2014 use spaces, not tabs.",Y.tabIndentation)),b>=0){if(z(g)>b&&/^(?:or\s+)?[A-Z]\w*(?:\s+or\s+[A-Z]\w*)*$/.test(k)){for(let M of k.split(/\s+/).filter(j=>j!=="or"))m.has(M)||y.push(me("warning",x,g,M,`Unknown policy '${M}' \u2014 declare it with 'policy ${M}'.`,Y.unknownPolicy));continue}b=-1}let P=dd(t,n,x);P&&y.push(P);let h=k.match(/^slice\s+(\w+)/);h&&!fn.includes(h[1])&&y.push(me("error",x,g,h[1],`Unknown slice type '${h[1]}' \u2014 expected ${fn.join(", ")}.`,Y.unknownSliceType));let C=k.match(/^concept\s+\w+\s*:\s*(\w+)/);C&&C[1]!=="Enum"&&!$t.includes(C[1])&&y.push(me("error",x,g,C[1],`Unknown primitive type '${C[1]}' \u2014 expected ${$t.join(", ")} or Enum.`,Y.unknownPrimitiveType));let A=k.match(/^authorize\s+(.*)$/);if(A){b=z(g);for(let M of A[1].split(/\s+/).filter(j=>j!=="or"&&j.length>0))m.has(M)||y.push(me("warning",x,g,M,`Unknown policy '${M}' \u2014 declare it with 'policy ${M}'.`,Y.unknownPolicy))}let w=k.match(/^on\s+([A-Z]\w*)\s*$/);w&&S(x,g,w[1]);let I=k.match(/^produces\s+([A-Z]\w*)\s*$/);if(I&&!a.operationProductionLines?.has(x)&&S(x,g,I[1]),/^produces\s+when\b/.test(k)&&!a.operationProductionLines?.has(x))for(let M=x+1;M<t.length;M++){let j=t[M];if(!(n[M]||j.trim().length===0)){if(z(j)>z(g)){let N=j.trim().match(/^([A-Z]\w*)\s*$/);N&&S(M,j,N[1])}break}}let q=k.match(/^unique\s+event\s+([A-Z]\w*)/);q&&S(x,g,q[1]);let B=k.match(/^unique\s+[a-z_]\w*\s+on\s+([A-Z]\w*)/);B&&S(x,g,B[1]);for(let M of g.match(/\$context\.[\w.]+/g)??[]){let j=M.substring(9).split(".");cn.includes(j[0])?j[0]==="causedBy"&&j.length>1&&!dn.includes(j[1])?y.push(me("warning",x,g,M,`Unknown $context.causedBy property '${j[1]}' \u2014 expected ${dn.join(", ")}.`,Y.unknownContextCausedByProperty)):j[0]==="identity"&&j.length>1&&!pn.includes(j[1])&&y.push(me("warning",x,g,M,`Unknown $context.identity property '${j[1]}' \u2014 expected ${pn.join(", ")}.`,Y.unknownContextIdentityProperty)):y.push(me("warning",x,g,M,`Unknown $context path '${j.join(".")}' \u2014 expected one of ${cn.join(", ")}.`,Y.unknownContextPath))}}y.push(...fd(t,n)),y.push(...oo(t,p,r,a.operationProductionLines));let v=t.map((x,g)=>({line:x,index:g})).filter(({line:x})=>/^\s*```(?:[a-z]+)?\s*$/.test(x));if(v.length%2===1){let x=v[v.length-1];y.push(de("error",x.index,1,x.line.length+1,"Unclosed inline code block \u2014 expected a closing ``` line.",Y.unclosedCodeBlock))}return y}l(eb,"validateLines");function cd(t,e){let n=[];t=Ae(t);for(let i of e.commands){let r=i.properties.filter(o=>o.isIdentifier&&!we(o).isOptional&&!we(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(de("information",a,z(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.`,Y.omittedProductionDestination))}}return n}l(cd,"validateProductionDestinations");function dd(t,e,n){let i=t[n],r=i.trim().replace(/\s*\/\/.*$/,"");if(!/^import\b/.test(r)||fi(i,n))return;let o=z(i);if(!(!(o>0&&["module","feature"].includes(hi(t,e,n,o)[0]))&&!ro(i)))return de("error",n,o+1,r.length,`Invalid import '${r}' \u2014 inside a module or feature, import names files: 'import "<path or glob>"'.`,Y.invalidFileImport)}l(dd,"validateImport");var pd=/^(?:(?:increment|decrement|count|clear|add|subtract|set)\s+)?@?([$\w.]+)(?=\s|=|$)/;function fd(t,e){let n=[],i=l(r=>r.map(o=>o.name).join(", "),"names");for(let r=0;r<t.length;r++){let o=t[r];if(e[r])continue;for(let p of o.matchAll(/(\.)?\$eventContext((?:\.(?:\w+(?:\(\))?)?)*)/g)){let f=p[0].substring(p[1]?.length??0),m=p[2];if(m.length===0){p[1]&&n.push(de("error",r,(p.index??0)+2,f.length,`'$eventContext' names no member - expected one of ${i(di("").expected)}.`,Y.missingEventContextPath));continue}let y=m.substring(1),u=di(y),S=(p.index??0)+(p[1]?.length??0)+1;switch(u.status){case"missing":n.push(de("error",r,S,f.length,`'$eventContext.${y}' names no member - expected one of ${i(u.expected)}.`,Y.missingEventContextPath));break;case"unknownMember":n.push(de("warning",r,S,f.length,`Unknown event context member '${u.segment}' in '$eventContext.${y}' - expected one of ${i(u.expected)}.`,Y.unknownEventContextMember));break;case"unknownSubPath":{let b=u.expected.length===0?"no members to address":`members ${i(u.expected)}`;n.push(de("warning",r,S,f.length,`Unknown event context path '$eventContext.${y}' - '${u.member?.name}' (${u.member?.type}) has ${b}.`,Y.unknownEventContextPath));break}case"belowCollection":n.push(de("error",r,S,f.length,`'$eventContext.${y}' cannot resolve - '${u.member?.name}' is a collection (${u.member?.type}) and cannot be addressed below.`,Y.eventContextPathBelowCollection));break}}let a=o.trim().match(pd)?.[1],s=a?.match(/\.\$(\w+)/)?.[1];a&&s&&s!=="eventContext"&&n.push(me("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.`,Y.unresolvedDynamicKeySource))}return n}l(fd,"validateEventContextPaths");export{co as a,yd as b,md as c,Si as d,Sd as e,cn as f,dn as g,fn as h,$t as i,hd as j,gd as k,Xe as l,$d as m,d as n,se as o,vn as p,kn as q,ax as r,sx as s,Ie as t,z as u,un as v,ie as w,hi as x,bd as y,Ae as z,Yv as A,Ke as B,ii as C,Vv as D,ri as E,Qv as F,we as G,Je as H,ht as I,an as J,to as K,sn as L,Xc as M,sk as N,si as O,ed as P,li as Q,ci as R,td as S,fk as T,uk as U,yk as V,pi as W,kk as X,Y,ro as Z,fi as _,Ok as $,Ak as aa,eb as ba,fd as ca};
16
- //# sourceMappingURL=chunk-ODSHRAAO.js.map