@cratis/screenplay-language 4.57.0 → 4.59.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.
- package/dist/OperationAnalysis.d.ts +81 -0
- package/dist/OperationAnalysis.d.ts.map +1 -0
- package/dist/ResponseAnalysis.d.ts +3 -0
- package/dist/ResponseAnalysis.d.ts.map +1 -1
- package/dist/bundles/chunk-AYDF3IFZ.js +2 -0
- package/dist/bundles/chunk-AYDF3IFZ.js.map +7 -0
- package/dist/bundles/chunk-UNPNNHWD.js +14 -0
- package/dist/bundles/chunk-UNPNNHWD.js.map +7 -0
- package/dist/bundles/index.js +56 -22
- package/dist/bundles/index.js.map +4 -4
- package/dist/bundles/sub-languages/capture/index.js +3 -3
- package/dist/bundles/sub-languages/capture/index.js.map +2 -2
- package/dist/bundles/sub-languages/projection/index.js +23 -23
- package/dist/bundles/sub-languages/projection/index.js.map +2 -2
- package/dist/completion-items.d.ts +3 -0
- package/dist/completion-items.d.ts.map +1 -1
- package/dist/completion-planner.d.ts.map +1 -1
- package/dist/completions.d.ts.map +1 -1
- package/dist/hover-content.d.ts +2 -1
- package/dist/hover-content.d.ts.map +1 -1
- package/dist/hover.d.ts +2 -1
- package/dist/hover.d.ts.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/inlay-hints.d.ts +2 -1
- package/dist/inlay-hints.d.ts.map +1 -1
- package/dist/inline-event-validation.d.ts +1 -1
- package/dist/inline-event-validation.d.ts.map +1 -1
- package/dist/language.d.ts.map +1 -1
- package/dist/operation-authoring.d.ts +11 -0
- package/dist/operation-authoring.d.ts.map +1 -0
- package/dist/production-destinations.d.ts +2 -2
- package/dist/production-destinations.d.ts.map +1 -1
- package/dist/response-analysis.d.ts +4 -1
- package/dist/response-analysis.d.ts.map +1 -1
- package/dist/response-tokens.d.ts.map +1 -1
- package/dist/symbols.d.ts +2 -0
- package/dist/symbols.d.ts.map +1 -1
- package/dist/tokens.d.ts.map +1 -1
- package/dist/validation.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/bundles/chunk-IZGYM33T.js +0 -14
- package/dist/bundles/chunk-IZGYM33T.js.map +0 -7
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import{a}from"./chunk-AYDF3IFZ.js";var Ei="screenplay",Qa={id:Ei,extensions:[".play"],aliases:["Screenplay","screenplay","play"],mimetypes:["text/x-screenplay"]},Ha=["domain","import","concept","type","policy","persona","authentication","module","layout","theme","ui","feature","slice","event","system","operation","command","query","projection","capture","reaction","reducer","trigger","screen","dialog","form","contribute","constraint","specification","seed","behavior"];var tt=["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"],Ja=["csharp","typescript","react","html","sql"],fn=["command","arguments","tenant","causedBy","causation","occurred","identity"],mn=["subject","name","userName"],hn=["id","name","userName","isAuthenticated","roles","claims"],vn=["StateChange","StateView","Automation","Translate"],Ye=["Uuid","String","Int","Decimal","Bool","Date","DateTime"],Ka=["@pii","@sensitive"],Xa={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 Pe(n){let e=/^([\w.]+)(\[\])?(\?|\s+optional)?$/.exec(n);return{name:e?.[1]??n,isCollection:e?.[2]!==void 0,isOptional:e?.[3]!==void 0}}a(Pe,"typeReferenceSymbol");function nc(n){return`${n.name}${n.isCollection?"[]":""}${n.isOptional?" optional":""}`}a(nc,"typeReferenceText");function pe(n){let e=!1,t=!1;for(let i=0;i<n.length;i++){let o=n[i];if(o==="\\"&&e&&i+1<n.length)i++;else if(o==='"'&&!t)e=!e;else if(o==="`"&&!e)t=!t;else if(!e&&!t&&o==="/"&&n[i+1]==="/")return n.slice(0,i)}return n}a(pe,"withoutComment");function z(n){return n.length-n.trimStart().length}a(z,"indentOf");function gn(n){return n.trim().split(/\s+/)[0]??""}a(gn,"firstWord");function H(n){let e=new Array(n.length).fill(!1),t=!1;for(let i=0;i<n.length;i++){if(/^\s*```(?:[a-z]+)?\s*$/.test(n[i])&&(!t||/^\s*```\s*$/.test(n[i]))){e[i]=!0,t=!t;continue}e[i]=t}return e}a(H,"fenceMap");function it(n,e,t,i){let o=[],r=i;for(let s=t-1;s>=0&&r>0;s--){if(e[s])continue;let c=pe(n[s]);if(c.trim().length===0)continue;let u=z(c);u<r&&(o.push(gn(c)),r=u)}return o}a(it,"enclosingChain");function oc(n,e,t,i){for(let o=t-1;o>=0&&i>0;o--){if(e[o])continue;let r=pe(n[o]);if(r.trim().length!==0&&z(r)<i)return r.trim()}}a(oc,"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",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",LegacyOptionalSuffix:"PLAY0479",InvalidOptionalModifierOrder:"PLAY0480",OptionalReadsNotSupported:"PLAY0481",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",HandlerWithoutImplementation:"PLAY0045",UnknownHandlerDirective:"PLAY0046",CommandWithProducesAndHandler:"PLAY0035",AbsoluteFileReference:"PLAY0264",InvalidTriggerData:"PLAY0246"};function Fe(n,e=!1,t){let i=[],o=0,r=0;for(let s of n.split(`
|
|
2
|
+
`)){o++;let c=s.endsWith("\r")?s.replace(/\r+$/,""):s,u=c.length-c.trimStart().length,p=Di(c.substring(u),e).trimEnd();i.push(t===void 0?{number:o,raw:c,indent:u,content:p,startOffset:r}:{number:o,raw:c,indent:u,content:p,path:t,startOffset:r}),r+=s.length+1}return i}a(Fe,"splitLines");function yn(n,e=!1){let t=!1,i=!1;for(let o=0;o<n.length;o++){let r=n[o];if(r==="\\"&&t&&o+1<n.length)o++;else if(r==='"'&&!i)t=!t;else if(r==="`"&&!t)i=!i;else if(!t&&!i&&(r==="/"&&o+1<n.length&&n[o+1]==="/"||e&&r==="#"))return o}return-1}a(yn,"commentStart");function Di(n,e){let t=yn(n,e);return t<0?n:n.substring(0,t)}a(Di,"stripComment");var he=[],Ie=a(n=>n.length===0,"isDocumentPlacement");function qe(n){return n.length===0?"the application":n.length===1?`module '${n[0]}'`:`feature '${n.join(".")}'`}a(qe,"describePlacement");var ot="\\p{L}\\p{Mn}\\p{Nd}\\p{Pc}";function f(n){let e="",t=!1;for(let i=0;i<n.length;i++){let o=n[i];if(o==="\\"&&i+1<n.length){let r=n[i+1];i++,r==="w"?e+=t?ot:`[${ot}]`:r==="d"?e+="\\p{Nd}":e+=`\\${r}`;continue}o==="["&&!t?t=!0:o==="]"&&t&&(t=!1),e+=o}return new RegExp(e,"u")}a(f,"pattern");var Ce=a((n,e,t)=>t===void 0?{line:n,column:e}:{line:n,column:e,path:t},"sourceLocation");var rt=a(n=>n.content.length===0,"isBlank"),l=a(n=>Ce(n.number,n.indent+1,n.path),"locationOf"),st=a(n=>Ce(n.number,1,n.path),"startOf");var Oi=f("^(?:(?:or|and)\\s+)?[A-Za-z_(][\\w\\s()]*$"),Ri=new RegExp(f("\\(|\\)|[A-Za-z_]\\w*").source,"gu"),Ti=f("^[A-Z]\\w*$");function re(n,e){let t=e.content.substring(9);for(let c=n.peekChild(e.indent);c!==void 0&&Oi.test(c.content);c=n.peekChild(e.indent))n.reader.takeSignificant(),t+=` ${c.content}`;let i=Mi(t),o=l(e);if(i.length===0)return n.error(d.AuthorizeWithoutPolicy,"Expected at least one policy after 'authorize'",o),null;let s=new kn(n,i,o).parse();return s===null?null:{kind:"AuthorizeSyntax",requirement:s,location:o}}a(re,"parseAuthorize");function ne(n,e){return n===null?e:e===null?n:{kind:"AuthorizeSyntax",requirement:{kind:"LogicalPolicyRequirementSyntax",left:n.requirement,operator:"And",right:e.requirement,location:n.location},location:n.location}}a(ne,"combineAuthorize");function Mi(n){let e=[];for(let t of n.match(Ri)??[])e.length>0&&Li(e[e.length-1])&&xi(t)&&e.push("and"),e.push(t);return e}a(Mi,"tokenize");var at=a(n=>n!=="("&&n!==")"&&n!=="and"&&n!=="or","isName"),Li=a(n=>n===")"||at(n),"isOperandEnd"),xi=a(n=>n==="("||at(n),"isOperandStart"),kn=class{static{a(this,"RequirementParser")}context;tokens;location;#e=0;constructor(e,t,i){this.context=e,this.tokens=t,this.location=i}parse(){let e=this.#n();return e!==null&&this.#e<this.tokens.length&&this.context.error(d.UnexpectedTokenInAuthorize,`Unexpected '${this.tokens[this.#e]}' in authorize`,this.location),e}#n(){return this.#t("or","Or",()=>this.#i())}#i(){return this.#t("and","And",()=>this.#o())}#t(e,t,i){let o=i();for(;o!==null&&this.tokens[this.#e]===e;){this.#e++;let r=i();if(r===null)return null;o={kind:"LogicalPolicyRequirementSyntax",left:o,operator:t,right:r,location:this.location}}return o}#o(){if(this.tokens[this.#e]!=="(")return this.#a();this.#e++;let e=this.#n();return this.tokens[this.#e]===")"?this.#e++:this.context.error(d.UnclosedAuthorizeGroup,"Expected ')' in authorize",this.location),e}#a(){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 Ti.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 _='(?:[^"\\\\]|\\\\.)*',Ni={"\\":"\\",'"':'"',n:`
|
|
3
|
+
`,r:"\r",t:" "};function V(n){if(!n.includes("\\"))return n;let e="";for(let t=0;t<n.length;t++){let i=t+1<n.length?Ni[n[t+1]]:void 0;n[t]==="\\"&&i!==void 0?(e+=i,t++):e+=n[t]}return e}a(V,"unescapeString");function ve(n,e,t,i=!1){let r=t.content.startsWith("```")?t:n.reader.peekSignificant(),s=e==="description"?"```text":`\`\`\`${e}`;if(r===void 0||r!==t&&r.indent<=t.indent||r.content!==s&&!(i&&e==="description"&&r.content==="```markdown")&&!(r.content==="```"&&r!==t))return n.error(d.ExpectedCodeFence,`Expected an opening \`\`\`${e==="description"?"text":e} fence after '${e}'`,l(t)),null;r!==t&&n.reader.takeSignificant(),e==="description"&&r.content==="```"&&n.warning(d.LegacyInlineCodeFence,"A bare description fence is deprecated - use '```text' instead",l(r));let c=[];for(;;){let u=n.reader.takeRaw();if(u===void 0){n.error(d.UnclosedCodeBlock,"Unclosed inline code block - expected a closing ``` line",l(r));break}if(u.raw.trim()==="```")break;let p=0;for(;p<r.indent&&p<u.raw.length&&u.raw[p]===" ";)p++;c.push(u.raw.substring(p))}return c.join(`
|
|
4
|
+
`)}a(ve,"parseFencedText");var Bi=f(`^description\\s+"(${_})"$`);function U(n,e,t,i,o=!1){if(e.content==="description"){let s=ve(n,"description",e,o);return s===null?t:s.trim().length===0?(n.error(d.EmptyDescription,`${i} declares an empty description - the fenced block must contain text`,l(e)),t):ct(n,e,t,i,s)}let r=Bi.exec(e.content);return r===null?(n.error(d.InvalidDescription,`Invalid description '${e.content}' - expected 'description "<text>"'`,l(e)),t):ct(n,e,t,i,V(r[1]))}a(U,"parseDescription");function ct(n,e,t,i,o){return t!==null?(n.error(d.DuplicateDescription,`${i} already declares a description - at most one is allowed`,l(e)),t):o}a(ct,"keep");var Yi=f('^import\\s+"([^"\\\\]+)"$'),Fi=f('^import\\s+"'),lt=a(n=>Fi.test(n),"isFileImport");function dt(n){let e=Yi.exec(n.content);return e===null?void 0:{kind:"FileImportSyntax",pattern:e[1],location:l(n)}}a(dt,"tryParseFileImport");function ge(n,e,t){let i=dt(e);if(i!==void 0){t.push(i);return}n.error(d.InvalidFileImport,`Invalid import '${e.content}' - inside a module or feature, import names files: 'import "<path or glob>"'`,l(e)),n.skipBlock(e.indent)}a(ge,"parseFileImport");var T=a(n=>{let e=n.indexOf(" ");return e===-1?n:n.substring(0,e)},"firstWord"),W=a(n=>n.replaceAll("@",""),"unescapeIdentifier");function pt(n,e){let t=[],i=0,o=!1,r=!1;for(let s=0;s<n.length;s++){let c=n[s];c==="\\"&&o&&s+1<n.length?s++:c==='"'&&!r?o=!o:c==="`"&&!o?r=!r:c===e&&!o&&!r&&(t.push(n.substring(i,s)),i=s+1)}return t.push(n.substring(i)),t}a(pt,"splitTopLevel");var qi=f("^form\\s+[A-Za-z_]\\w*\\s+for\\s+([A-Za-z_]\\w*(?:\\.\\w+)*)$"),zi=f("^(execute|invokes)\\s+([A-Za-z_]\\w*(?:\\.\\w+)*)$"),Wi=f("^field\\s+([\\w.]+)(?:\\s|$)"),Ui=f("^with\\s+([A-Za-z_]\\w*)\\s+from\\s+.+$"),ji=f("^(@?[\\w.]+)\\s*=(?!=|>)\\s*.+$"),Vi=f("^parameter\\s+([A-Za-z_]\\w*)(?:\\s+([\\w.]+(?:\\[\\])?))?$"),Zi=new Set(["refresh","navigate","open","close","set","notify","confirm","raise","on"]);function X(n,e){let t=[],i=new Set,o=[],r=T(e.content)==="behavior",s=a(c=>{for(;t.length>0&&t[t.length-1].indent>=c.indent;)t.pop();let u=r&&t.length===0?Vi.exec(c.content):null;u!==null&&i.add(u[1]);let p=qi.exec(c.content),I=zi.exec(c.content);if(p!==null)t.push({command:p[1],kind:"form",indent:c.indent});else if(I!==null)t.push({command:I[2],kind:I[1],indent:c.indent});else if(Zi.has(T(c.content)))t.push({command:"",kind:"other",indent:c.indent});else{let v=t.at(-1);if(v===void 0||v.kind==="other")return;let k=(v.kind==="form"?Wi:v.kind==="execute"?Ui:ji).exec(c.content);k!==null&&o.push({command:v.command,property:W(k[1]),scope:n.scope,location:l(c)})}},"recognize");s(e);for(let c=n.peekChild(e.indent);c!==void 0;c=n.peekChild(e.indent))n.reader.takeSignificant(),c.content.startsWith("```")?n.skipFencedBody():s(c);for(let c of o)n.inputUses.push(i.has(c.command)?{...c,isParameter:!0}:c)}a(X,"collectInputUses");var ut=["StateChange","StateView","Automation","Translate"];var _i=f("^capture\\s+([A-Za-z_]\\w*)$"),Gi=f("^append\\s+([A-Z]\\w*)$"),Qi=f("^children\\s+([a-z_]\\w*)\\s+identified\\s+by\\s+([\\w.]+)$"),Hi=f("^nested\\s+([\\w.]+)$");function mt(n,e){let t=_i.exec(e.content)?.[1]??"",i=null,o=null,r=[],s=[],c=[];for(let u=n.peekChild(e.indent);u!==void 0;u=n.peekChild(e.indent))switch(n.reader.takeSignificant(),T(u.content)){case"source":i=Ji(n,u);break;case"key":o=u.content.substring(3).trim();break;case"append":ht(n,u,r);break;case"children":{let p=Qi.exec(u.content),I=ft(n,u);p!==null&&s.push({kind:"CaptureChildrenSyntax",property:p[1],identifiedBy:p[2],appends:I,location:l(u)});break}case"nested":{let p=Hi.exec(u.content),I=ft(n,u);p!==null&&c.push({kind:"CaptureNestedSyntax",property:p[1],appends:I,location:l(u)});break}default:n.skipOpaqueBlock(u.indent)}return{kind:"CaptureSyntax",name:t,source:i,key:o,appends:r,children:s,nested:c,location:l(e)}}a(mt,"parseCapture");function Ji(n,e){let t=[];for(let i=n.peekChild(e.indent);i!==void 0;i=n.peekChild(e.indent)){n.reader.takeSignificant();let o=T(i.content);t.push({kind:"CaptureSourceSettingSyntax",name:o,value:i.content.substring(o.length).trim(),location:l(i)})}return{kind:"CaptureSourceSyntax",syntaxKind:e.content.substring(6).trim(),settings:t,location:l(e)}}a(Ji,"parseSource");function ft(n,e){let t=[];for(let i=n.peekChild(e.indent);i!==void 0;i=n.peekChild(e.indent))n.reader.takeSignificant(),T(i.content)==="append"?ht(n,i,t):n.skipOpaqueBlock(i.indent);return t}a(ft,"appendsOf");function ht(n,e,t){let i=Gi.exec(e.content);n.skipOpaqueBlock(e.indent),i!==null&&t.push({kind:"CaptureAppendSyntax",event:i[1],location:l(e)})}a(ht,"pushAppend");var Ki=f("^(@?[a-z_]\\w*)\\s+([\\w.]+(?:\\[\\])?(?:\\?|\\s+optional)?)(?:\\s+(generated))?(?:\\s+(identifier))?$"),Xi=f("^@?[a-z_]\\w*\\s+[\\w.]+(?:\\[\\])?\\??\\s+((?:optional|generated|identifier)(?:\\s+(?:optional|generated|identifier))*)$"),eo=f("^@?[a-z_]\\w*\\s+[\\w.]+(?:\\[\\])?\\s+identifier\\s+optional(?:\\s*=.*)?$");function ue(n){let e=Ki.exec(n.content);if(e===null)return;let t=l(n);return{kind:"PropertySyntax",name:W(e[1]),type:ie(e[2],{...t,column:t.column+n.content.indexOf(e[2],e[1].length)}),isGenerated:e[3]!==void 0,isIdentifier:e[4]!==void 0,location:t}}a(ue,"tryParseProperty");function ie(n,e){let t=n.endsWith("?"),i=/\soptional$/.test(n),o=t||i;o&&(n=n.substring(0,n.length-(t?1:8)).trimEnd());let r=n.endsWith("[]");return r&&(n=n.substring(0,n.length-2)),{kind:"TypeRefSyntax",name:n,isCollection:r,isOptional:o,location:e}}a(ie,"parseTypeRef");function te(n,e){let t=ue(e);return t!==void 0?se(n,t.type,e):ze(n,e),t}a(te,"parseProperty");function se(n,e,t){let i=e.name.length+(e.isCollection?2:0),o=e.location.column-t.indent-1+i;if(e.isOptional&&t.content[o]==="?"){let r=e.name+(e.isCollection?"[]":"");n.information(d.LegacyOptionalSuffix,`Write '${r} optional' instead of '${r}?'.`,e.location)}}a(se,"reportLegacyOptionalSuffix");function ze(n,e){if(eo.test(e.content))return n.error(d.InvalidOptionalModifierOrder,"Write 'optional' before 'identifier': '<name> <Type> optional identifier'.",l(e)),!0;{let t=Xi.exec(e.content);if(t!==null&&t[1].split(/\s+/).some(i=>i==="generated"||i==="identifier"))return n.error(d.InvalidGeneratedModifierOrder,"Write each modifier once in order: '<name> <Type> optional generated identifier'.",l(e)),!0}return!1}a(ze,"reportInvalidModifierOrder");var Sn=f("^returns\\s+(@?[A-Za-z_]\\w*)$"),no=f("^(@?[a-z_]\\w*)(?:\\s+([\\w.]+(?:\\[\\])?(?:\\?|\\s+optional)?))?\\s*=(?!=|>)\\s*(@?[a-z_]\\w*)$");function wn(n,e){let t=l(e);if(e.content!=="returns"){let o=Sn.exec(e.content);if(o===null)return n.error(d.InvalidCommandResponse,"Expected 'returns <property>' or an unconditional 'returns' block.",t),n.skipBlock(e.indent),null;let r=n.peekChild(e.indent);r!==void 0&&(n.error(d.InvalidCommandResponse,"A scalar response cannot have child directives.",l(r)),n.skipBlock(e.indent));let s=o.index+o[0].length-o[1].length;return{kind:"ScalarCommandResponseSyntax",source:{kind:"PropertyResponseSourceSyntax",property:W(o[1]),location:{...t,column:t.column+s}},location:t}}let i=[];for(let o=n.peekChild(e.indent);o!==void 0;o=n.peekChild(e.indent)){n.reader.takeSignificant();let r=no.exec(o.content);if(r===null){n.error(d.InvalidCommandResponse,"Expected '<field> [<Type>] = <property>' in a response block.",l(o)),n.skipBlock(o.indent);continue}let s=l(o),c=r[2]===void 0?null:ie(r[2],{...s,column:s.column+o.content.indexOf(r[2],r[1].length)});c!==null&&se(n,c,o),i.push({kind:"ResponseFieldSyntax",name:W(r[1]),type:c,source:{kind:"PropertyResponseSourceSyntax",property:W(r[3]),location:{...s,column:s.column+o.content.lastIndexOf(r[3])}},location:s});let u=n.peekChild(o.indent);u!==void 0&&(n.error(d.InvalidCommandResponse,"A response field cannot have child directives.",l(u)),n.skipBlock(o.indent))}return{kind:"RecordCommandResponseSyntax",fields:i,location:t}}a(wn,"parseCommandResponse");var to=new Set([32,133,160,5760,8232,8233,8239,8287,12288]);function We(n){if(n===null)return!0;for(let e of n){let t=e.charCodeAt(0);if(!(t>=9&&t<=13||t>=8192&&t<=8202||to.has(t)))return!1}return!0}a(We,"isBlankImplementationHint");var vt=new Set(["csharp","typescript","react","html","sql"]),io=new RegExp('^hint[\\u0009-\\u000d\\u0020\\u0085\\u00a0\\u1680\\u2000-\\u200a\\u2028\\u2029\\u202f\\u205f\\u3000]+"((?:[^"\\\\\\r\\n]|\\\\[^\\r\\n])*)"$'),bn=a(n=>T(n.content)==="file"&&n.content.substring(4).trim().length>0,"isFile"),gt=a(n=>n.content.startsWith("```")||vt.has(n.content),"isCode");function Ue(n,e){let t=e.content.substring(4).trim();return/^(?:[/\\]|[A-Za-z]:[/\\]|~[/\\])/.test(t)&&n.warning(d.AbsoluteFileReference,`'${t}' is an absolute path - a file reference is relative to the repository root, so it means the same thing on every machine`,l(e)),{kind:"FileReferenceSyntax",path:t,location:l(e)}}a(Ue,"parseFile");function $e(n,e){let t=e.content.startsWith("```")?e.content.substring(3):e.content;if(!vt.has(t))return n.error(d.ExpectedCodeFence,`Expected a registered language on the opening fence, not '${e.content}'`,l(e)),null;let i=e;if(!e.content.startsWith("```")){n.warning(d.LegacyInlineCodeFence,`'${t}' on its own line is deprecated - use '\`\`\`${t}' instead`,l(e));let r=n.reader.peekSignificant();if(r===void 0||r.indent<=e.indent||r.content!=="```"&&r.content!==`\`\`\`${t}`)return n.error(d.ExpectedCodeFence,`Expected an opening \`\`\`${t} fence after '${t}'`,l(e)),null;i=n.reader.takeSignificant()}let o=[];for(;;){let r=n.reader.takeRaw();if(r===void 0){n.error(d.UnclosedCodeBlock,"Unclosed inline code block - expected a closing ``` line",l(i));break}if(r.raw.trim()==="```")break;let s=0;for(;s<i.indent&&r.raw[s]===" ";)s++;o.push(r.raw.substring(s))}return{kind:"CodeBlockSyntax",language:t,code:o.join(`
|
|
5
|
+
`),location:l(e)}}a($e,"parseCode");function yt(n,e){let t=n.peekChild(e.indent);if(t===void 0)return n.error(d.HandlerWithoutImplementation,"Expected a 'file' directive or an inline code block in the handler",l(e)),null;if(n.reader.takeSignificant(),T(t.content)==="implementation")return oo(n,e,t);let i=bn(t)?Ue(n,t):null,o=i===null&>(t)?$e(n,t):null;if(i!==null||o!==null){let r=n.peekChild(e.indent);return r!==void 0&&T(r.content)==="implementation"&&(n.error(d.ConflictingImplementationSources,"A handler cannot mix wrapped and direct sources.",l(r)),n.skipBlock(e.indent)),{kind:"HandlerSyntax",file:i,code:o,implementation:null,location:l(e)}}return n.error(d.UnknownHandlerDirective,`Unexpected '${t.content}' in handler - expected 'file <path>' or an inline code block`,l(t)),n.skipBlock(e.indent),null}a(yt,"parseHandler");function oo(n,e,t){let i=Pn(n,t);for(let o=n.peekChild(e.indent);o!==void 0;o=n.peekChild(e.indent))n.reader.takeSignificant(),n.error(T(o.content)==="implementation"?d.InvalidImplementationBlock:d.ConflictingImplementationSources,"A handler has one implementation wrapper and cannot mix wrapped and direct sources.",l(o)),gt(o)?$e(n,o):n.skipBlock(o.indent);return{kind:"HandlerSyntax",...i,location:l(e)}}a(oo,"parseImplementation");function Pn(n,e){let t=[],i=null,o=null,r=!1;e.content!=="implementation"&&n.error(d.InvalidImplementationBlock,"Expected 'implementation' with no operand.",l(e));for(let s=n.peekChild(e.indent);s!==void 0;s=n.peekChild(e.indent))if(n.reader.takeSignificant(),T(s.content)==="hint"){let c=io.exec(s.content),u=c===null?null:V(c[1]);We(u)?n.error(d.InvalidImplementationHint,"Expected 'hint' followed by one nonblank quoted string.",l(s)):t.push({kind:"ImplementationHintSyntax",text:u,location:l(s)});let p=n.peekChild(s.indent);p!==void 0&&(n.error(d.InvalidImplementationHint,"A hint cannot have children.",l(p)),n.skipBlock(s.indent))}else if(bn(s)||s.content.startsWith("```")){r&&n.error(d.ConflictingImplementationSources,"An implementation has at most one file or inline payload.",l(s));let c=bn(s)?Ue(n,s):null,u=c===null?$e(n,s):null;r||(i=c,o=u),r=!0;let p=n.peekChild(s.indent);c!==null&&p!==void 0&&(n.error(d.InvalidImplementationBlock,"A file directive cannot have children.",l(p)),n.skipBlock(s.indent))}else n.error(d.InvalidImplementationBlock,`Unexpected '${s.content}' in implementation - expected hint, file or a tagged fence.`,l(s)),n.skipBlock(s.indent);return{file:i,code:o,implementation:{kind:"ImplementationSyntax",hints:t,location:l(e)}}}a(Pn,"parseImplementationWrapper");var kt=64,J=class extends Error{static{a(this,"InvalidStructuredValue")}},je=class{static{a(this,"StructuredValueParser")}text;start;context;#e=0;constructor(e,t,i){this.text=e,this.start=t,this.context=i}parse(){let e=this.#n(0);if(this.#r(),this.#e<this.text.length)throw new J(`'${this.text[this.#e]}' is invalid after a single JSON value.`);return e}#n(e){this.#r();let t=this.#l(),i=this.text[this.#e];if(i==="["||i==="{"){if(e>=kt)throw new J(`The value nests deeper than ${kt} levels.`);return i==="["?this.#i(e,t):this.#t(e,t)}if(i==='"')return{kind:"LiteralExpressionSyntax",value:this.#o(),location:t};for(let[o,r]of[["true",!0],["false",!1],["null",null]])if(this.text.startsWith(o,this.#e))return this.#e+=o.length,{kind:"LiteralExpressionSyntax",value:r,location:t};return{kind:"LiteralExpressionSyntax",value:this.#d(),location:t}}#i(e,t){this.#e++;let i=[];if(this.#r(),this.#s("]"))return{kind:"ListExpressionSyntax",items:i,location:t};for(;;){if(i.push(this.#n(e+1)),this.#r(),this.#s("]"))return{kind:"ListExpressionSyntax",items:i,location:t};this.#c(",")}}#t(e,t){this.#e++;let i=[],o=new Set;if(this.#r(),this.#s("}"))return{kind:"ObjectExpressionSyntax",members:i,location:t};for(;;){this.#r();let r=this.#l();if(this.text[this.#e]!=='"')throw new J("Expected a property name in double quotes.");let s=this.#o();this.#r(),this.#c(":");let c=this.#n(e+1);if(o.has(s)?this.context?.error(d.DuplicateStructuredValueMember,`Duplicate property '${s}' in structured value`,r):(o.add(s),i.push({kind:"ObjectMemberSyntax",name:s,value:c,location:r})),this.#r(),this.#s("}"))return{kind:"ObjectExpressionSyntax",members:i,location:t};this.#c(",")}}#o(){let e=this.#a(this.#e),t=this.text.substring(this.#e,e);this.#e=e;try{return JSON.parse(t)}catch{throw new J(`${t} is not a valid JSON string.`)}}#a(e){for(let t=e+1;t<this.text.length;t++)if(this.text[t]==="\\")t++;else if(this.text[t]==='"')return t+1;throw new J("A string is not closed.")}#d(){let e=/^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/.exec(this.text.substring(this.#e));if(e===null)throw new J(`'${this.text[this.#e]??""}' is an invalid start of a value.`);this.#e+=e[0].length;let t=Number(e[0]);if(!Number.isFinite(t))throw new J("JSON number is outside the finite Double range.");return t}#l(){return{...this.start,column:this.start.column+this.#e}}#r(){for(;this.#e<this.text.length&&`
|
|
6
|
+
\r`.includes(this.text[this.#e]);)this.#e++}#s(e){return this.text[this.#e]!==e?!1:(this.#e++,!0)}#c(e){if(!this.#s(e))throw new J(`Expected '${e}' at position ${this.#e}.`)}};var ro=f("^@?[A-Za-z_]\\w*(\\.@?[A-Za-z_$]\\w*)*$"),so=f("^-?\\d+(\\.\\d+)?$"),St=["command","arguments","tenant","causedBy","causation","occurred","identity"],wt=["subject","name","userName"],bt=["id","name","userName","isAuthenticated","roles","claims"];function Q(n,e,t){if(n=n.trim(),n.startsWith("$context.")){let o=n.substring(9);return ao(o,e,t),{kind:"ContextExpressionSyntax",path:o,location:e}}if(n.startsWith("$env."))return{kind:"EnvironmentExpressionSyntax",name:n.substring(5),location:e};if(n.startsWith("$strings."))return{kind:"StringsExpressionSyntax",key:n.substring(9),location:e};if(n.startsWith("$."))return{kind:"SourceItemExpressionSyntax",path:n.substring(2),location:e};if(n.startsWith("{")||n.startsWith("["))try{return new je(n,e,t).parse()}catch(o){if(!(o instanceof J))throw o;return t?.error(d.InvalidStructuredValue,`Invalid inline structured value: ${o.message}`,e),{kind:"RawExpressionSyntax",text:n,location:e}}let i=co(n,e);return i!==void 0?i:ro.test(n)?{kind:"PathExpressionSyntax",path:n,location:e}:{kind:"RawExpressionSyntax",text:n,location:e}}a(Q,"parseMappingSource");function ao(n,e,t){let[i,o]=n.split(".");St.includes(i)?o!==void 0&&i==="causedBy"&&!wt.includes(o)?t?.warning(d.UnknownContextCausedByProperty,`Unknown $context.causedBy property '${o}' - expected ${wt.join(", ")}`,e):o!==void 0&&i==="identity"&&!bt.includes(o)&&t?.warning(d.UnknownContextIdentityProperty,`Unknown $context.identity property '${o}' - expected ${bt.join(", ")}`,e):t?.warning(d.UnknownContextPath,`Unknown $context path '${n}' - expected one of ${St.join(", ")}`,e)}a(ao,"warnOnUnknownContextPath");function co(n,e){let t=a(o=>({kind:"LiteralExpressionSyntax",value:o,location:e}),"literal");switch(n){case"true":return t(!0);case"false":return t(!1);case"null":return t(null)}if(n.length>=2&&(n.startsWith('"')&&n.endsWith('"')||n.startsWith("'")&&n.endsWith("'")))return t(V(n.substring(1,n.length-1)));if(so.test(n)&&!Number.isNaN(Number(n)))return t(Number(n))}a(co,"parseLiteral");var ae=class{static{a(this,"ParserContext")}reader;path;#e=[];triggerData=[];inputUses=[];scope=[];constructor(e,t){this.reader=e,this.path=t}get start(){return Ce(1,1,this.path)}get diagnostics(){return this.#e}information(e,t,i){this.#e.push({severity:"information",code:e,message:t,location:i})}error(e,t,i){this.#e.push({severity:"error",code:e,message:t,location:i})}warning(e,t,i){this.#e.push({severity:"warning",code:e,message:t,location:i})}peekChild(e){let t=this.reader.peekSignificant();return t!==void 0&&t.indent>e?t:void 0}skipBlock(e){for(;this.peekChild(e)!==void 0;)this.reader.takeSignificant()}skipOpaqueBlock(e){let t=this.peekChild(e);for(;t!==void 0;)this.reader.takeSignificant(),t.content.startsWith("```")&&this.skipFencedBody(),t=this.peekChild(e)}skipFencedBody(){for(let e=this.reader.takeRaw();e!==void 0;e=this.reader.takeRaw())if(e.raw.trim()==="```")return}};var Ve=new WeakMap;var Ae=["tag"];var lo=f(`^id\\s+"(${_})"$`),ye=class{static{a(this,"EventMetadataParser")}name;value={id:null,description:null,documentation:null};constructor(e){this.name=e}tryParse(e,t){let i=l(t);switch(T(t.content)){case"id":{let o=lo.exec(t.content),r=o===null?"":V(o[1]);return r.trim().length===0||this.value.id!==null?e.error(d.InvalidEventId,`Event '${this.name}' accepts one nonempty 'id "<old-name>"'`,i):(this.value.id=r,r===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=U(e,t,this.value.description,`Event '${this.name}'`,!0),!0;case"documentation":{if(t.content!=="documentation"||e.peekChild(t.indent)?.content!=="```markdown")return e.error(d.InvalidEventDocumentation,`Event '${this.name}' documentation requires a fenced markdown block`,i),e.skipOpaqueBlock(t.indent),!0;let o=ve(e,"markdown",t);return o===null||o.trim().length===0||this.value.documentation!==null?e.error(d.InvalidEventDocumentation,`Event '${this.name}' accepts one nonempty documentation block`,i):this.value.documentation=o,!0}default:return!1}}};var po=f("^[A-Za-z_]\\w*(?:\\[\\])?(?:\\?|\\s+optional)?$"),Pt=a(n=>T(n.content)==="file"?n.content.substring(4).trim():"","pathOf"),Z=a(n=>Pt(n).length>0,"isFileDirective"),Ze=a(n=>Z(n)&&!po.test(Pt(n)),"isFileDirectiveAmongProperties");var uo=f("^type\\s+([A-Za-z_]\\w*)$"),fo=f("^event\\s+([A-Za-z_]\\w*)(?:\\s+generation\\s+([0-9]+))?$"),mo=f("^readmodel\\s+([A-Za-z_]\\w*)$"),It=4294967295,ho=f("^[A-Z]\\w*(?:\\[\\])?(?:\\?|\\s+optional)?$"),vo=f("^[A-Za-z_]\\w*$"),Ct=a(n=>T(n.content)==="description"&&ue(n)===void 0,"isDescription");function In(n,e,t,i,o){return e.isIdentifier?(n.error(i,o,l(t)),{...e,isIdentifier:!1}):e}a(In,"withoutIdentifier");function $t(n,e){let t=uo.exec(e.content)?.[1]??"";t===""&&n.error(d.InvalidTypeDeclaration,`Invalid type declaration '${e.content}' - expected 'type <Name>'`,l(e));let i=[],o=null;for(let r=n.peekChild(e.indent);r!==void 0;r=n.peekChild(e.indent)){if(n.reader.takeSignificant(),Ct(r)){o=U(n,r,o,`Type '${t}'`);continue}if(Ze(r))continue;let s=te(n,r);if(s===void 0){n.error(d.InvalidPropertyDeclaration,`Invalid property '${r.content}' - expected '<name> <Type>'`,l(r));continue}i.push(In(n,s,r,d.IdentifierOutsideCommand,`Property '${s.name}' of type '${t}' cannot be marked identifier - only a command property can be`))}return i.length===0&&n.error(d.TypeWithoutProperties,`Type '${t}' must declare at least one property`,l(e)),{kind:"TypeSyntax",name:t,properties:i,description:o,location:l(e)}}a($t,"parseType");function At(n,e){let t=fo.exec(e.content),i=t?.[1]??"";t===null&&n.error(d.InvalidEventDeclaration,`Invalid event declaration '${e.content}' - expected 'event <Name> [generation <N>]'`,l(e));let o=t?.[2]!==void 0,r=1;if(o){let p=Number(t[2]);!Number.isSafeInteger(p)||p===0||p>=It?n.error(d.InvalidEventGeneration,`Event '${i}' must declare a generation between 1 and ${It-1}`,l(e)):r=p}let s=[],c=[],u=new ye(i);for(let p=n.peekChild(e.indent);p!==void 0;p=n.peekChild(e.indent)){if(n.reader.takeSignificant(),Ze(p))continue;if(Ae.includes(T(p.content))){let v=Cn(n,p);v!==void 0&&c.push(v);continue}let I=te(n,p);if(I===void 0){u.tryParse(n,p)||n.error(d.InvalidPropertyDeclaration,`Invalid property '${p.content}' - expected '<name> <Type>'`,l(p));continue}s.push(In(n,I,p,d.IdentifierOnEventProperty,`Property '${I.name}' of event '${i}' cannot be marked identifier - an event never carries its event source id`))}return{kind:"EventSyntax",name:i,properties:s,tags:c,generation:r,hasGenerationMarker:o,...u.value,location:l(e)}}a(At,"parseEvent");function Cn(n,e,t=!0){let i=e.content.substring(3).trim();if(t&&ho.test(i)&&n.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`,l(e)),i.length===0){n.error(d.TagWithoutValue,"Expected a value after 'tag' - an identifier, a string literal or a context expression",l(e));return}if(vo.test(i))return{kind:"TagSyntax",value:{kind:"LiteralExpressionSyntax",value:i,location:l(e)},location:l(e)};let o=Q(i,l(e),n);if(o.kind==="RawExpressionSyntax"){n.error(d.InvalidTagValue,`Invalid tag value '${i}' - expected an identifier, a string literal or a context expression`,l(e));return}return{kind:"TagSyntax",value:o,location:l(e)}}a(Cn,"parseTag");function Et(n,e){let t=mo.exec(e.content)?.[1]??"";t===""&&n.error(d.InvalidReadModelDeclaration,`Invalid read model declaration '${e.content}' - expected 'readmodel <Name>'`,l(e));let i=[],o=null;for(let r=n.peekChild(e.indent);r!==void 0;r=n.peekChild(e.indent))if(n.reader.takeSignificant(),Ct(r))o=U(n,r,o,`Read model '${t}'`);else{if(Ze(r))continue;{let s=te(n,r);if(s===void 0){n.error(d.InvalidPropertyDeclaration,`Invalid property '${r.content}' - expected '<name> <Type>'`,l(r));continue}i.push(In(n,s,r,d.IdentifierOutsideCommand,`Property '${s.name}' of read model '${t}' cannot be marked identifier - only a command property can be`))}}return{kind:"ReadModelSyntax",name:t,properties:i,description:o,location:l(e)}}a(Et,"parseReadModel");var go=f("^system\\s+([A-Za-z_]\\w*)$"),yo=f("^operation\\s+([A-Za-z_]\\w*)$"),ko=f("^produces\\s+operation\\s+([A-Za-z_]\\w*)$"),$n=f("^uses\\s+([A-Za-z_]\\w*)$"),So=f("^(.+?)\\s*=(?!=|>)\\s*(.+)$"),wo=new Set(["for","tag","generation","origin","documentation","namespace","sequence","correlation","causation","causedBy","occurred"]);function Ee(n,e,t,i){let o=n.peekChild(e.indent);o!==void 0&&(n.error(t,i,l(o)),n.skipBlock(e.indent))}a(Ee,"rejectOperationChildren");function Dt(n,e){let t=go.exec(e.content);t===null&&n.error(d.InvalidSystemDeclaration,"Expected 'system <Name>'.",l(e));let i=null;for(let o=n.peekChild(e.indent);o!==void 0;o=n.peekChild(e.indent))n.reader.takeSignificant(),T(o.content)==="description"?i=U(n,o,i,`System '${t?.[1]??""}'`):(n.error(d.InvalidSystemDeclaration,"A system accepts only a description; abilities are not supported.",l(o)),n.skipBlock(o.indent));return{kind:"SystemSyntax",name:t?.[1]??"",description:i,location:l(e)}}a(Dt,"parseSystem");function _e(n,e,t=!1){let i=(t?ko:yo).exec(e.content),o=i?.[1]??"";i===null&&n.error(d.InvalidOperationDeclaration,"Expected an operation declaration with one name.",l(e));let r=null,s=null,c=l(e),u=null,p=null,I=[],v=[],k=new Set;for(let w=n.peekChild(e.indent);w!==void 0;w=n.peekChild(e.indent)){n.reader.takeSignificant();let P=So.exec(w.content),C=t&&P!==null?{...w,content:P[1].trimEnd()}:w;if(P===null&&wo.has(T(w.content))){n.error(d.InvalidOperationDeclaration,"Operations cannot declare event routing or metadata; escape a keyword-named input with @.",l(w)),n.skipBlock(w.indent);continue}if(!$n.test(w.content)&&ue(C)!==void 0){let D=te(n,C);t&&P===null&&n.error(d.InvalidOperationMapping,"An inline operation input requires '<property> <Type> = <source>'.",l(w)),(D.isIdentifier||D.isGenerated)&&n.error(d.InvalidOperationDeclaration,"Operation inputs cannot be identifier or generated properties.",l(w)),k.has(D.name)&&n.error(d.DuplicateDeclaration,`Operation '${o}' already declares input '${D.name}'.`,l(w)),k.add(D.name),I.push(D),t&&P!==null&&v.push({kind:"PropertyMappingSyntax",property:D.name,source:Q(P[2],{...l(w),column:w.indent+w.content.length-P[2].length+1},n),location:l(w)}),Ee(n,w,d.InvalidOperationDeclaration,"An operation input cannot have children.")}else if(T(w.content)==="description")r=U(n,w,r,`Operation '${o}'`);else if($n.test(w.content))s!==null?n.error(d.InvalidSystemReference,"An operation declares exactly one 'uses <System>'.",l(w)):(s=$n.exec(w.content)[1],c={...l(w),column:l(w).column+w.content.indexOf(s,4)}),Ee(n,w,d.InvalidSystemReference,"A system reference cannot have children.");else if(w.content==="execute"||w.content==="compensate"){let D=bo(n,w);w.content==="execute"?u!==null?n.error(d.InvalidOperationDeclaration,"An operation declares execute at most once.",l(w)):u=D:p!==null?n.error(d.InvalidOperationDeclaration,"An operation declares compensate at most once.",l(w)):p=D}else n.error(d.InvalidOperationDeclaration,`Unexpected '${w.content}' in operation - expected uses, an input, description, execute or compensate.`,l(w)),n.skipBlock(w.indent)}return s===null&&n.error(d.InvalidSystemReference,"An operation requires exactly one 'uses <System>'.",l(e)),{operation:{kind:"OperationSyntax",name:o,uses:s??"",usesLocation:c,inputs:I,description:r,execute:u,compensate:p,location:l(e)},mappings:v}}a(_e,"parseOperation");function bo(n,e){let t=null,i=null,o=null,r=null,s=!1;for(let c=n.peekChild(e.indent);c!==void 0;c=n.peekChild(e.indent)){if(n.reader.takeSignificant(),T(c.content)==="description"){t=U(n,c,t,`Operation phase '${e.content}'`);continue}if(T(c.content)==="implementation"){s&&n.error(d.ConflictingImplementationSources,"A phase cannot mix wrapped and direct sources or repeat its wrapper.",l(c));let u=Pn(n,c);s||(i=u.file,o=u.code,r=u.implementation),s=!0}else if(Z(c)||c.content.startsWith("```")){s&&n.error(d.ConflictingImplementationSources,"A phase has at most one file or inline payload.",l(c));let u=Z(c)?Ue(n,c):null,p=u===null?$e(n,c):null;s||(i=u,o=p),s=!0,u!==null&&Ee(n,c,d.InvalidImplementationBlock,"A file directive cannot have children.")}else n.error(d.InvalidOperationDeclaration,"A phase accepts description, file, a tagged fence or implementation.",l(c)),n.skipBlock(c.indent)}return{kind:"OperationPhaseSyntax",description:t,file:i,code:o,implementation:r,location:l(e)}}a(bo,"parseOperationPhase");var Po=f("^produces\\s+operation(?:\\s|$)"),Io=f("^produces\\s+event\\s+([A-Za-z_]\\w*)(?:\\s+(generation)(?:\\s+.*)?)?$"),Co=f("^produces\\s+([A-Z]\\w*(?:\\.[A-Za-z_]\\w*)*)$"),$o=f("^produces\\s+when\\s+(.+)$"),Ao=f("^[A-Z]\\w*(?:\\.[A-Za-z_]\\w*)*$"),Eo=f("^for\\s+(\\S.*)$"),Do=f("^(@?[\\w.]+)\\s*=(?!=|>)\\s*(.+)$"),Oo=f("^(.+?)\\s*=(?!=|>)\\s*(.+)$"),Ro=new Set(["namespace","sequence","correlation","causation","causedBy","occurred"]);function Ge(n,e,t=!1){if(Po.test(e.content)){if(!t){n.error(d.OperationOutsideCommand,"Operations can only be produced by commands.",l(e)),n.skipOpaqueBlock(e.indent);return}let w=_e(n,e,!0);return{kind:"ProducesSyntax",event:w.operation.name,targetLocation:{...l(e),column:e.indent+e.content.match(/^produces\s+operation(?:\s+|$)/)[0].length+1},inlineEvent:null,inlineOperation:w.operation,mappings:w.mappings,for:null,tags:[],location:l(e)}}let i=Io.exec(e.content),o=e,r,s;if(i!==null){if(!t){n.error(d.InlineEventOutsideCommand,"Inline events can only be declared inside commands",l(e)),n.skipOpaqueBlock(e.indent);return}i[2]!==void 0&&n.error(d.InlineEventGeneration,"Inline events are generation 1 - extract the event before declaring generations",l(e)),r=i[1],s=e.indent+e.content.match(/^produces\s+event\s+/)[0].length+1}else if($o.test(e.content)){let w=n.peekChild(e.indent);if(w===void 0||!Ao.test(w.content)){n.error(d.ProducesWhenWithoutEvent,"Expected an event name on the line after 'produces when'",l(e)),n.skipOpaqueBlock(e.indent);return}n.reader.takeSignificant(),o=w,r=w.content,s=w.indent+1}else{let w=Co.exec(e.content);if(w===null){n.error(d.InvalidProducesDeclaration,`Invalid produces declaration '${e.content}' - expected 'produces <EventType>' or 'produces when <condition>'`,l(e)),n.skipOpaqueBlock(e.indent);return}r=w[1],s=e.indent+e.content.match(/^produces\s+/)[0].length+1}let c=[],u=new Set,p=[],I=[],v=new ye(r),k=null;for(let w=n.peekChild(o.indent);w!==void 0;w=n.peekChild(o.indent)){n.reader.takeSignificant();let P=T(w.content),C=l(w);if(Ro.has(P)){n.error(d.ReservedProductionMetadata,`'${P}' is system-assigned production metadata and cannot be supplied here`,C),n.skipOpaqueBlock(w.indent);continue}if(i!==null&&(P==="generation"||P==="origin")){n.error(P==="generation"?d.InlineEventGeneration:d.ReservedProductionMetadata,P==="generation"?"Inline events are generation 1 - extract the event before declaring generations":"An inline event is local to its command and cannot declare origin",C),n.skipOpaqueBlock(w.indent);continue}if(P==="tag"){let m=Cn(n,w,!1);m!==void 0&&I.push(m);continue}let D=Eo.exec(w.content);if(D!==null){k!==null?n.error(d.DuplicateProducesTarget,`'${o.content}' already declares where it lands - an event is appended to one event source`,C):k=Q(D[1],C,n);continue}let S=(i===null?Do:Oo).exec(w.content),$=S===null||i===null?void 0:te(n,{...w,content:S[1].trimEnd()});if(S!==null&&(i===null||$!==void 0)){if($!==void 0){$.isIdentifier&&(n.error(d.IdentifierOnEventProperty,`Property '${$.name}' of event '${r}' cannot be marked identifier - an event never carries its event source id`,C),$={...$,isIdentifier:!1});let m=$.name;u.has(m)&&n.error(d.DuplicateDeclaration,`Event '${r}' already declares property '${$.name}'`,C),u.add(m),c.push($)}p.push({kind:"PropertyMappingSyntax",property:$?.name??W(S[1]),source:Q(S[2],{...C,column:w.indent+w.content.length-S[2].length+1},n),location:C})}else(i===null||!v.tryParse(n,w))&&n.error(d.InvalidPropertyMapping,`Invalid ${i===null?"":"inline "}property mapping '${w.content}' - expected '<property>${i===null?"":" <Type>"} = <source>'`,C)}return o!==e&&n.skipBlock(e.indent),{kind:"ProducesSyntax",event:r,targetLocation:{...l(o),column:s},inlineOperation:null,mappings:p,for:k,tags:i===null?I:[],location:l(e),inlineEvent:i===null?null:{kind:"EventSyntax",name:r,properties:c,tags:I,generation:1,hasGenerationMarker:!1,...v.value,location:l(e)}}}a(Ge,"parseProduces");var To=f("^command\\s+([A-Za-z_]\\w*)$"),Mo=f("\\bseverity\\s+(\\S+)$"),Lo=f(`\\bmessage\\s+(?:"(${_})"|(\\$strings\\.\\S*))$`),xo=f("^([\\w.]+)\\s+(.+)$"),No=f("^(not empty|length ==|all >=|all >|matches|max|min|rule|>=|<=|==|!=|>|<)\\s*(.*)$"),Bo=f("^[A-Za-z_]\\w*$"),Yo=f("^reads\\s+[A-Z]\\w*\\s+optional(?:\\s|$)"),Fo={max:"Max",min:"Min",">":"GreaterThan",">=":"GreaterThanOrEqual","<":"LessThan","<=":"LessThanOrEqual","==":"Equal","!=":"NotEqual","length ==":"Length",matches:"Matches","all >":"AllGreaterThan","all >=":"AllGreaterThanOrEqual"},qo={information:"Information",warning:"Warning",error:"Error"},zo=new Set(["reads","concurrency"]),Wo=new Set(["description","handler","concurrency"]);function Rt(n,e){let t=new Set;return Ot(new ae(n.reader.fork(),n.path),e,void 0,t),Ot(n,e,t)}a(Rt,"parseCommand");function Ot(n,e,t,i){let o=To.exec(e.content)?.[1]??"";o===""&&n.error(d.InvalidCommandDeclaration,`Invalid command declaration '${e.content}' - expected 'command <Name>'`,l(e));let r=[],s=[],c,u=[],p=[],I=[],v=null,k=null,w=null;for(let m=n.peekChild(e.indent);m!==void 0;m=n.peekChild(e.indent)){n.reader.takeSignificant();let g=T(m.content),y=ue(m);if(y!==void 0&&(Wo.has(g)||g==="validate"&&m.content!=="validate csharp"))c=Qe(n,r,y,o,m,c);else if(g==="returns"){let h=Sn.exec(m.content);h!==null&&!h[1].startsWith("@")&&y!==void 0?t===void 0?(r.push(y),s.push({line:m,candidate:y,response:null})):t.has(y.type.name)?s.push({line:m,candidate:null,response:wn(n,m)}):c=Qe(n,r,y,o,m,c):y!==void 0?c=Qe(n,r,y,o,m,c):ze(n,m)?n.skipBlock(m.indent):s.push({line:m,candidate:null,response:wn(n,m)})}else if(g==="description")v=U(n,m,v,`Command '${o}'`);else if(g==="authorize")k=ne(k,re(n,m));else if(g==="validate"){let h=Uo(n,m);h!==void 0&&u.push(h)}else if(g==="produces"){let h=Ge(n,m,!0);h!==void 0&&p.push(h)}else if(g==="handler")w=yt(n,m);else if(zo.has(g)){let h=/^reads\s+([A-Z]\w*)(?:\s+as\s+([a-z_]\w*))?(?:\s+by\s+([a-z_]\w*))?$/.exec(m.content);h!==null&&I.push({readModel:h[1],alias:h[2]??null}),Yo.test(m.content)&&n.error(d.OptionalReadsNotSupported,"Optional reads are not yet supported (see #308).",l(m)),n.skipOpaqueBlock(m.indent)}else y!==void 0?c=Qe(n,r,y,o,m,c):(ze(n,m),n.error(d.UnknownCommandDirective,`Unexpected '${m.content}' in command body`,l(m)),n.skipBlock(m.indent))}let P=new Set(s.flatMap(m=>m.candidate===null?[]:[m.candidate])),C=new Set(r.filter(m=>!P.has(m)).map(m=>m.name));s.some(m=>m.candidate!==null&&!C.has(m.candidate.type.name)&&m.candidate.type.name!=="returns")&&C.add("returns");for(let m of C)i?.add(m);let D=null,S=new Set;for(let m of s){let g=m.response;if(m.candidate!==null){if(!C.has(m.candidate.type.name))continue;S.add(m.candidate),g={kind:"ScalarCommandResponseSyntax",source:{kind:"PropertyResponseSourceSyntax",property:m.candidate.type.name,location:m.candidate.type.location},location:l(m.line)}}g!==null&&(D!==null?n.error(d.InvalidCommandResponse,"A command declares at most one unconditional response.",l(m.line)):D=g)}w!==null&&p.length>0&&n.error(d.CommandWithProducesAndHandler,`Command '${o}' cannot declare both 'produces' and 'handler'`,l(e));let $={kind:"CommandSyntax",name:o,description:v,authorize:k,properties:r.filter(m=>!S.has(m)),validations:u,produces:p,handler:w,response:D,location:l(e)};return Ve.set($,I),$}a(Ot,"parseCommandBody");function Qe(n,e,t,i,o,r){return se(n,t.type,o),t.isIdentifier&&r!==void 0&&(n.error(d.DuplicateCommandIdentifier,`Command '${i}' already marks '${r.name}' as identifier - only one property can be the identifier`,t.location),t={...t,isIdentifier:!1}),e.push(t),r??(t.isIdentifier?t:void 0)}a(Qe,"addProperty");function Uo(n,e){if(e.content==="validate"){let t=n.peekChild(e.indent);if(t!==void 0&&t.content.startsWith("```"))return n.reader.takeSignificant(),n.skipFencedBody(),{kind:"CodeValidateSyntax",location:l(e)};let i=[];for(let o=n.peekChild(e.indent);o!==void 0;o=n.peekChild(e.indent)){if(n.reader.takeSignificant(),T(o.content)==="require"){n.skipOpaqueBlock(o.indent);continue}let r=jo(n,o);r!==void 0&&i.push(r)}return{kind:"DeclarativeValidateSyntax",rules:i,location:l(e)}}if(e.content==="validate csharp")return n.skipOpaqueBlock(e.indent),{kind:"CodeValidateSyntax",location:l(e)};n.error(d.InvalidValidateDeclaration,`Invalid validate declaration '${e.content}' - expected 'validate' or 'validate csharp'`,l(e)),n.skipBlock(e.indent)}a(Uo,"parseValidate");function jo(n,e){let{content:t,message:i}=Vo(e.content),o=Zo(n,e,t);if(o===void 0)return;let r=xo.exec(o.content);if(r===null){n.error(d.InvalidValidationRule,`Invalid validation rule '${e.content}'`,l(e));return}let s=_o(n,r[2],e);if(s!==void 0)return s.kind==="Rule"&&n.skipOpaqueBlock(e.indent),{kind:"ValidationRuleSyntax",property:r[1],rule:s.kind,value:s.value,message:i,severity:o.severity,location:l(e)}}a(jo,"parseValidationRule");function Vo(n){let e=Lo.exec(n);if(e===null)return{content:n,message:null};let t=e[1]!==void 0?V(e[1]):e[2];return{content:n.substring(0,e.index).trimEnd(),message:t}}a(Vo,"splitMessage");function Zo(n,e,t){let i=Mo.exec(t);if(i===null)return{content:t,severity:"Error"};let o=qo[i[1]];if(o===void 0){n.error(d.InvalidValidationSeverity,`Unknown validation severity '${i[1]}' - expected information, warning or error`,l(e));return}return{content:t.substring(0,i.index).trimEnd(),severity:o}}a(Zo,"splitSeverity");function _o(n,e,t){if(e==="not empty")return{kind:"NotEmpty",value:null};let i=No.exec(e);if(i===null){n.error(d.InvalidValidationRule,`Invalid validation rule '${t.content}'`,l(t));return}if(i[1]==="rule"){let o=i[2].trim();if(!Bo.test(o)){n.error(d.InvalidRuleName,`Invalid rule name '${o}' in '${t.content}' - expected 'rule <Name>' with an identifier`,l(t));return}return{kind:"Rule",value:{kind:"PathExpressionSyntax",path:o,location:l(t)}}}return{kind:Fo[i[1]],value:Q(i[2],l(t),n)}}a(_o,"parseRule");var Go=f("^constraint\\s+([A-Za-z_]\\w*)$"),Qo=f("^unique\\s+event\\s+([A-Z]\\w*)$"),Ho=f("^unique\\s+([a-z_][\\w.]*(?:\\s*,\\s*[a-z_][\\w.]*)*)\\s+on\\s+([A-Z]\\w*)$"),Jo=f("^released\\s+by\\s+([A-Z]\\w*)$"),Ko=f(`^message\\s+"(${_})"$`),Xo=a(n=>n.kind==="FileConstraintSyntax"?void 0:n.event,"targetOf");function Tt(n,e){let t=Go.exec(e.content);t===null&&n.error(d.InvalidConstraintDeclaration,`Invalid constraint declaration '${e.content}' - expected 'constraint <Name>'`,l(e));let i=t?.[1]??T(e.content),o=[],r=[],s=new Set,c=new Set,u=null,p=!1;for(let I=n.peekChild(e.indent);I!==void 0;I=n.peekChild(e.indent)){n.reader.takeSignificant();let v=Jo.exec(I.content),k=Ko.exec(I.content);v!==null?s.has(v[1])?n.error(d.DuplicateConstraintBody,`Constraint '${i}' already releases with event '${v[1]}'`,l(I)):(r.push(v[1]),s.add(v[1])):k!==null?u!==null?n.error(d.DuplicateConstraintBody,`Constraint '${i}' already has a message`,l(I)):u=V(k[1]):I.content==="ignore casing"?(p&&n.error(d.DuplicateConstraintBody,`Constraint '${i}' already ignores casing`,l(I)),p=!0):er(n,i,I,o,c)}for(let I of r.filter(v=>c.has(v)))n.error(d.DuplicateConstraintBody,`Constraint '${i}' cannot target and release event '${I}'`,l(e));return o.length===0&&(n.error(d.ConstraintWithoutRule,`Constraint '${i}' must declare 'unique ... on ...', 'unique event ...' or 'file ...'`,l(e)),o.push(He(i,l(e),{kind:"UniqueEventConstraintSyntax",event:""}))),o[0].kind==="FileConstraintSyntax"&&(r.length>0||u!==null||p)&&n.error(d.InvalidConstraintBody,`File constraint '${i}' cannot have declarative options`,l(e)),{...o[0],additionalRules:o.slice(1),releasedBy:r,message:u,ignoreCasing:p}}a(Tt,"parseConstraint");function er(n,e,t,i,o){let r=nr(n,e,t);if(r===void 0)return;if(i.length>0&&(r.kind==="FileConstraintSyntax"||i[0].kind==="FileConstraintSyntax"||r.kind==="UniqueEventConstraintSyntax"!=(i[0].kind==="UniqueEventConstraintSyntax"))){n.error(d.DuplicateConstraintBody,`Constraint '${e}' cannot mix constraint kinds`,l(t));return}let s=Xo(r);if(s!==void 0&&o.has(s)){n.error(d.DuplicateConstraintBody,`Constraint '${e}' already targets event '${s}'`,l(t));return}s!==void 0&&o.add(s),i.push(r)}a(er,"addRule");function nr(n,e,t){let i=l(t),o=Qo.exec(t.content);if(o!==null)return He(e,i,{kind:"UniqueEventConstraintSyntax",event:o[1]});let r=Ho.exec(t.content);if(r!==null){let s=r[1].split(",").map(c=>c.trim());if(new Set(s).size!==s.length){n.error(d.DuplicateConstraintBody,`Constraint '${e}' repeats a property in its composite key`,i);return}return He(e,i,{kind:"UniquePropertyConstraintSyntax",property:s[0],additionalProperties:s.slice(1),event:r[2]})}if(Z(t)){n.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 s=t.content.substring(4).trim();return He(e,i,{kind:"FileConstraintSyntax",file:{kind:"FileReferenceSyntax",path:s,location:i}})}n.error(d.InvalidConstraintBody,`Invalid constraint body '${t.content}'`,i)}a(nr,"parseRule");function He(n,e,t){return{...t,name:n,additionalRules:[],releasedBy:[],ignoreCasing:!1,message:null,location:e}}a(He,"rule");var tr=f("^projection\\s+(@?[\\w.]+)\\s*(?:=>\\s*([\\w.]+))?$"),ir=f("^(@?[\\w.]+)(?:\\s+key\\s+(.+))?$"),or=f("^join\\s+(@?[\\w.]+)\\s+on\\s+(@?[\\w.]+)$"),rr=f("^with\\s+(@?[\\w.]+)$"),sr=f("^children\\s+(@?[\\w.]+)\\s+identified\\s+by\\s+(.+)$"),ar=f("^nested\\s+(@?[\\w.]+)$"),cr=f("^remove\\s+with\\s+(@?[\\w.]+)(?:\\s+key\\s+(.+))?$"),lr=f("^remove\\s+via\\s+join\\s+on\\s+(@?[\\w.]+)(?:\\s+key\\s+(.+))?$"),dr=f("^clear\\s+with\\s+(@?[\\w.]+)$"),pr=f("^variant\\s+(@?[\\w.]+)\\s*$"),ur=f("^enters\\s+on\\s+(@?[\\w.]+)(?:\\s+key\\s+(.+))?$"),fr=f("^(increment|decrement|count|clear)\\s+(@?[$\\w.]+)$"),mr=f("^(add|subtract)\\s+(@?[$\\w.]+)\\s+by\\s+(.+)$"),hr=f("^set\\s+(@?[$\\w.]+)\\s+(?:=|to)\\s+(.+)$"),vr=f("^(@?[$\\w.@]+)\\s*=(?!=|>)\\s*(.+)$"),gr={increment:"IncrementMappingSyntax",decrement:"DecrementMappingSyntax",clear:"ClearMappingSyntax",count:"CountMappingSyntax"};function Mt(n,e){let t=tr.exec(e.content);if(t===null)return n.error(d.InvalidProjectionDeclaration,`Invalid projection declaration '${e.content}' - expected 'projection <Name> [=> <ReadModel>]'`,l(e)),n.skipBlock(e.indent),{kind:"ProjectionSyntax",name:T(e.content),readModel:null,sequence:null,autoMap:"Inherit",blocks:[],location:l(e)};let i=t[1],o=null,r="Inherit",s=[];for(let c=n.peekChild(e.indent);c!==void 0;c=n.peekChild(e.indent)){if(n.reader.takeSignificant(),Z(c))continue;let u=T(c.content);if(u==="sequence")o=c.content.substring(8).trim();else if(u==="automap")r="Enabled";else if(c.content==="no automap")r="Disabled";else if(u==="key")xt(n,c);else if(u==="variant")s.push(Cr(n,c));else{let p=En(n,c,!1);p!==void 0&&s.push(p)}}return yr(n,s,i),s.length===0&&n.error(d.EmptyProjection,`Projection '${i}' must contain at least one directive`,l(e)),{kind:"ProjectionSyntax",name:i,readModel:t[2]??null,sequence:o,autoMap:r,blocks:s,location:l(e)}}a(Mt,"parseProjection");function yr(n,e,t){let i=e.filter(s=>s.kind==="ProjectionVariantSyntax"),o=new Map;i.forEach(s=>o.set(s.name,[...o.get(s.name)??[],s]));for(let s of[...o.values()].flatMap(c=>c.slice(1)))n.error(d.DuplicateProjectionVariant,`Duplicate variant '${s.name}' - a variant name is declared once`,s.location);let r=new Set;for(let s of e.flatMap(c=>c.kind==="ProjectionVariantSyntax"?c.entersOn:[]))s.event.length>0&&r.has(s.event)&&n.error(d.DuplicateVariantEnteringEvent,`Entering event '${s.event}' is claimed more than once in projection '${t}'`,s.location),r.add(s.event)}a(yr,"reportVariantConflicts");function En(n,e,t){let i=l(e);switch(T(e.content)){case"from":return kr(n,e);case"every":{let o=!0,{autoMap:r,mappings:s}=An(n,e,c=>c.content!=="exclude children"?!1:(o=!1,!0));return{kind:"EverySyntax",includeChildren:o,autoMap:r,mappings:s,location:i}}case"all":{let{autoMap:o,mappings:r}=An(n,e);return{kind:"AllSyntax",autoMap:o,mappings:r,location:i}}case"join":return Sr(n,e);case"children":return wr(n,e);case"nested":return br(n,e);case"remove":return Pr(n,e);case"clear":return t||n.error(d.ClearWithOutsideNestedBlock,"'clear with' is only valid inside a nested block",i),Ir(n,e);default:n.error(d.UnknownProjectionDirective,`Unexpected '${T(e.content)}' in projection body`,i),n.skipBlock(e.indent);return}}a(En,"parseBlock");function kr(n,e){let t=[];for(let o of pt(e.content.substring(4),",")){let r=o.trim();if(r.length===0){n.error(d.FromWithoutEvent,"Expected an event type after 'from'",l(e));continue}let s=ir.exec(r);if(s===null){n.error(d.InvalidEventReference,`Invalid event reference '${r}'`,l(e));continue}t.push({kind:"EventSpecSyntax",event:W(s[1]),location:l(e)})}let i=[];for(let o=n.peekChild(e.indent);o!==void 0;o=n.peekChild(e.indent)){n.reader.takeSignificant();let r=T(o.content);r==="key"?xt(n,o):r!=="parent"&&Nt(o,i)}return{kind:"FromSyntax",events:t,mappings:i,location:l(e)}}a(kr,"parseFrom");function Sr(n,e){let t=or.exec(e.content);if(t===null)return n.error(d.InvalidJoinDeclaration,`Invalid join declaration '${e.content}' - expected 'join <property> on <key>'`,l(e)),n.skipBlock(e.indent),{kind:"JoinSyntax",property:"",on:"",events:[],location:l(e)};let i=[];for(let o=n.peekChild(e.indent);o!==void 0;o=n.peekChild(e.indent)){n.reader.takeSignificant();let r=rr.exec(o.content);if(r===null){n.error(d.JoinWithoutEvent,`Expected 'with <EventType>' in join block, got '${o.content}'`,l(o)),n.skipBlock(o.indent);continue}let{autoMap:s,mappings:c}=An(n,o);i.push({kind:"JoinEventSyntax",event:W(r[1]),autoMap:s,mappings:c,location:l(o)})}return{kind:"JoinSyntax",property:W(t[1]),on:W(t[2]),events:i,location:l(e)}}a(Sr,"parseJoin");function wr(n,e){let t=sr.exec(e.content);if(t===null)return n.error(d.InvalidChildrenDeclaration,`Invalid children declaration '${e.content}' - expected 'children <collection> identified by <key>'`,l(e)),n.skipBlock(e.indent),{kind:"ChildrenSyntax",property:"",autoMap:"Inherit",blocks:[],location:l(e)};let{autoMap:i,blocks:o}=Lt(n,e);return{kind:"ChildrenSyntax",property:W(t[1]),autoMap:i,blocks:o,location:l(e)}}a(wr,"parseChildren");function br(n,e){let t=ar.exec(e.content);if(t===null)return n.error(d.InvalidNestedDeclaration,`Invalid nested declaration '${e.content}' - expected 'nested <property>'`,l(e)),n.skipBlock(e.indent),{kind:"NestedSyntax",property:"",autoMap:"Inherit",blocks:[],location:l(e)};let i=W(t[1]),{autoMap:o,blocks:r}=Lt(n,e);return r.some(s=>s.kind==="FromSyntax")||n.error(d.NestedBlockWithoutFrom,`Nested block '${i}' must contain at least one 'from' directive`,l(e)),{kind:"NestedSyntax",property:i,autoMap:o,blocks:r,location:l(e)}}a(br,"parseNested");function Lt(n,e){let t=[],i="Inherit";for(let o=n.peekChild(e.indent);o!==void 0;o=n.peekChild(e.indent)){if(n.reader.takeSignificant(),o.content==="automap"){i="Enabled";continue}if(o.content==="no automap"){i="Disabled";continue}let r=En(n,o,!0);r!==void 0&&t.push(r)}return{autoMap:i,blocks:t}}a(Lt,"parseChildBlocks");function Pr(n,e){let t=lr.exec(e.content);if(t!==null)return{kind:"RemoveViaJoinSyntax",event:W(t[1]),location:l(e)};let i=cr.exec(e.content);if(i===null){n.error(d.InvalidRemoveDeclaration,`Invalid remove declaration '${e.content}' - expected 'remove with <EventType>' or 'remove via join on <EventType>'`,l(e)),n.skipBlock(e.indent);return}for(let o=n.peekChild(e.indent);o!==void 0;o=n.peekChild(e.indent))n.reader.takeSignificant(),T(o.content)!=="parent"&&n.error(d.UnknownRemoveDirective,`Unexpected '${o.content}' in remove block - only 'parent' is allowed`,l(o));return{kind:"RemoveWithSyntax",event:W(i[1]),location:l(e)}}a(Pr,"parseRemove");function Ir(n,e){let t=dr.exec(e.content);return t===null?(n.error(d.InvalidClearDeclaration,`Invalid clear declaration '${e.content}' - expected 'clear with <EventType>'`,l(e)),{kind:"ClearWithSyntax",event:"",location:l(e)}):{kind:"ClearWithSyntax",event:W(t[1]),location:l(e)}}a(Ir,"parseClearWith");function Cr(n,e){let t=pr.exec(e.content);if(t===null)return n.error(d.InvalidProjectionVariantDeclaration,`Invalid variant declaration '${e.content}' - expected 'variant <Name>'`,l(e)),n.skipBlock(e.indent),{kind:"ProjectionVariantSyntax",name:T(e.content),entersOn:[],blocks:[],location:l(e)};let i=W(t[1]),o=[],r=[];for(let s=n.peekChild(e.indent);s!==void 0;s=n.peekChild(e.indent)){n.reader.takeSignificant();let c=T(s.content);if(c==="enters")o.push($r(n,s));else if(c==="variant")n.error(d.NestedProjectionVariantNotAllowed,"A variant cannot be declared inside another variant",l(s)),n.skipBlock(s.indent);else{let u=En(n,s,!1);u!==void 0&&r.push(u)}}return o.length===0&&n.error(d.VariantRequiresEnteringEvent,`Variant '${i}' must declare at least one 'enters on' event`,l(e)),{kind:"ProjectionVariantSyntax",name:i,entersOn:o,blocks:r,location:l(e)}}a(Cr,"parseVariant");function $r(n,e){let t=ur.exec(e.content);return t===null?(n.error(d.InvalidEntersOnDeclaration,`Invalid 'enters on' declaration '${e.content}' - expected 'enters on <EventType> [key <expression>]'`,l(e)),n.skipBlock(e.indent),{kind:"ProjectionEntersOnSyntax",event:"",location:l(e)}):{kind:"ProjectionEntersOnSyntax",event:W(t[1]),location:l(e)}}a($r,"parseEntersOn");function xt(n,e){if(n.peekChild(e.indent)===void 0)return;n.skipBlock(e.indent);let t=n.reader.peekSignificant();t!==void 0&&t.indent===e.indent&&t.content==="}"&&n.reader.takeSignificant()}a(xt,"skipKey");function An(n,e,t=()=>!1){let i="Inherit",o=[];for(let r=n.peekChild(e.indent);r!==void 0;r=n.peekChild(e.indent))n.reader.takeSignificant(),r.content==="automap"?i="Enabled":r.content==="no automap"?i="Disabled":t(r)||Nt(r,o);return{autoMap:i,mappings:o}}a(An,"parseMappingBlock");function Nt(n,e){let t=l(n),i=fr.exec(n.content);if(i!==null){(i[1]!=="clear"||i[2]!=="with")&&e.push({kind:gr[i[1]],property:W(i[2]),location:t});return}let o=mr.exec(n.content);if(o!==null){e.push({kind:o[1]==="add"?"AddMappingSyntax":"SubtractMappingSyntax",property:W(o[2]),location:t});return}let r=hr.exec(n.content)??vr.exec(n.content);r!==null&&e.push({kind:"SetMappingSyntax",property:W(r[1]),location:t})}a(Nt,"pushMapping");var Ar=f("^query\\s+([A-Za-z_]\\w*)\\s*=>\\s*(observable\\s+)?([\\w.]+(?:\\[\\])?(?:\\?|\\s+optional)?)$"),Er=f("^([a-z_]\\w*)\\s+([\\w.]+(?:\\[\\])?(?:\\?|\\s+optional)?)(?:\\s+from\\s+(.+))?$"),Dr=f("^scoped\\s+to\\s+([a-z_]\\w*)$"),Or=new Set(["performer"]);function Yt(n,e){let t=Ar.exec(e.content);if(t===null)return n.error(d.InvalidQueryDeclaration,`Invalid query declaration '${e.content}' - expected 'query <Name> => [observable] <ReadModel>'`,l(e)),n.skipBlock(e.indent),{kind:"QuerySyntax",name:T(e.content),returnType:ie("",l(e)),by:null,filters:[],description:null,isObservable:!1,scope:null,authorize:null,location:l(e)};let i=t[1],o=ie(t[3],{...l(e),column:e.indent+1+t[0].length-t[3].length});t[2]===void 0&&o.name==="observable"&&o.isOptional&&!o.isCollection||se(n,o,e);let r=null,s=[],c=null,u=null,p=null;for(let I=n.peekChild(e.indent);I!==void 0;I=n.peekChild(e.indent)){n.reader.takeSignificant();let v=T(I.content);if(v==="description")c=U(n,I,c,`Query '${i}'`);else if(v==="by"){let k=Bt(n,I,"by");k!==void 0&&(r!==null&&n.error(d.InvalidQueryParameter,`Query '${i}' already declares 'by' - a query can have at most one key parameter`,l(I)),r=k)}else if(v==="filter"){let k=Bt(n,I,"filter");k!==void 0&&s.push(k)}else v==="authorize"?p=ne(p,re(n,I)):v==="scoped"?u=Rr(n,I,u,i)??u:Or.has(v)?n.skipOpaqueBlock(I.indent):(n.error(d.UnknownQueryDirective,`Unexpected '${I.content}' in query body - expected description, by, filter, authorize, scoped or performer`,l(I)),n.skipBlock(I.indent))}return{kind:"QuerySyntax",name:i,returnType:o,by:r,filters:s,description:c,isObservable:t[2]!==void 0,scope:u,authorize:p,location:l(e)}}a(Yt,"parseQuery");function Bt(n,e,t){let i=Er.exec(e.content.substring(t.length).trim());if(i===null){n.error(d.InvalidQueryParameter,`Invalid '${t}' parameter '${e.content}' - expected '${t} <name> <Type> [from <source>]'`,l(e));return}let o=e.content.indexOf(i[1],t.length),r=ie(i[2],{...l(e),column:e.indent+1+e.content.indexOf(i[2],o+i[1].length)});return se(n,r,e),{kind:"QueryParameterSyntax",name:i[1],type:r,location:l(e)}}a(Bt,"parseParameter");function Rr(n,e,t,i){let o=Dr.exec(e.content);if(o===null){n.error(d.InvalidScopeDeclaration,`Invalid scope declaration '${e.content}' - expected 'scoped to <scope>'`,l(e));return}if(t!==null){n.error(d.DuplicateScope,`Query '${i}' already declares a scope - results are narrowed one way`,l(e));return}return o[1]}a(Rr,"parseScope");var Tr=f("^@?[a-z_]\\w*\\s+[\\w.]+");function Dn(n,e){let t=te(n,e);if(t!==void 0){t.isGenerated&&n.error(d.GeneratedPropertyOutsideCommand,"Generated properties can only be declared on commands.",t.location),n.triggerData.push(t);return}Tr.test(e.content)&&/\?|\boptional\b/.test(e.content)&&n.error(d.InvalidTriggerData,`Invalid trigger value '${e.content}' - expected '<name>' or '<name> <Type>'`,l(e)),n.skipOpaqueBlock(e.indent)}a(Dn,"parseTriggerData");function Ft(n,e){for(let t=n.peekChild(e.indent);t!==void 0;t=n.peekChild(e.indent))n.reader.takeSignificant(),T(t.content)==="description"?U(n,t,null,`Trigger '${e.content}'`):Z(t)||Dn(n,t)}a(Ft,"parseTriggerDeclaration");var Mr=f("^reaction\\s+([A-Za-z_]\\w*)$"),Lr=f("^when\\s+([A-Za-z_]\\w*)$"),xr=f("^every\\s+(\\d+)\\s+(seconds?|minutes?|hours?|days?)$"),Nr=f("^at\\s+(\\d{2}:\\d{2})(?:\\s+on\\s+(?:(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday)|day\\s+(\\d{1,2})))?$"),Br=new Set(["when","every","at"]),Yr=f("^invokes\\s+([A-Z]\\w*)$"),Fr=f("^reads\\s+[A-Z]\\w*\\s+optional(?:\\s|$)");function qt(n,e){let t=Mr.exec(e.content)?.[1]??"";t===""&&n.error(d.InvalidReactionDeclaration,`Invalid reaction declaration '${e.content}' - expected 'reaction <Name>'`,l(e));let i=null,o=[],r=new Set,s=!1;for(let c=n.peekChild(e.indent);c!==void 0;c=n.peekChild(e.indent)){n.reader.takeSignificant();let u=T(c.content);if(u==="description"){i=U(n,c,i,`Reaction '${t}'`);continue}if(u==="where")continue;if(!Br.has(u)){n.error(d.InvalidReactionTrigger,`Expected a trigger in reaction body, got '${c.content}' - a reaction is set off by 'when <Name>', 'every <n> <unit>' or 'at <HH:mm>'`,l(c)),n.skipBlock(c.indent),s=!0;continue}let p=Wr(n,c);if(p===void 0){s=!0;continue}let I=zr(p);if(r.has(I)){n.error(d.DuplicateReactionTrigger,`Reaction '${t}' already declares '${c.content}' - a second says nothing the first did not`,l(c)),n.skipBlock(c.indent);continue}r.add(I),o.push(qr(n,c,p))}return o.length===0&&!s&&n.error(d.ReactionWithoutTrigger,`Reaction '${t}' must declare at least one trigger - nothing sets it off`,l(e)),{kind:"ReactionSyntax",name:t,description:i,triggers:o,location:l(e)}}a(qt,"parseReaction");function qr(n,e,t){let i=null,o=[],r=[];for(let s=n.peekChild(e.indent);s!==void 0;s=n.peekChild(e.indent)){n.reader.takeSignificant();let c=T(s.content);if(c==="description")i=U(n,s,i,`Trigger '${s.content}'`);else if(c==="produces"){let u=Ge(n,s);u!==void 0&&o.push(u)}else if(c==="invokes"){let u=Yr.exec(s.content);u===null?(n.error(d.InvalidInvokesDeclaration,`Invalid invokes declaration '${s.content}' - expected 'invokes <Command>'`,l(s)),n.skipBlock(s.indent)):(r.push({kind:"InvokesSyntax",command:u[1],location:l(s)}),X(n,s))}else c==="reads"||c==="file"||s.content==="csharp"||s.content.startsWith("```")?(Fr.test(s.content)&&n.error(d.OptionalReadsNotSupported,"Optional reads are not yet supported (see #308).",l(s)),s.content.startsWith("```")&&n.skipFencedBody(),n.skipOpaqueBlock(s.indent)):Dn(n,s)}return{kind:"ReactionTriggerSyntax",source:t,description:i,produces:o,invokes:r,location:l(e)}}a(qr,"parseTrigger");function zr(n){switch(n.kind){case"NamedTriggerSourceSyntax":return JSON.stringify([n.kind,n.name]);case"IntervalTriggerSourceSyntax":return JSON.stringify([n.kind,n.amount,n.unit]);case"ScheduleTriggerSourceSyntax":return JSON.stringify([n.kind,n.time,n.dayOfWeek,n.dayOfMonth])}}a(zr,"sourceKey");function Wr(n,e){let t=l(e);switch(T(e.content)){case"when":{let i=Lr.exec(e.content);if(i===null){n.error(d.InvalidReactionTrigger,`Invalid trigger '${e.content}' - expected 'when <Name>'`,t),n.skipBlock(e.indent);return}return{kind:"NamedTriggerSourceSyntax",name:i[1],location:t}}case"every":{let i=xr.exec(e.content),o=i===null?NaN:Number(i[1]);if(i===null||!Number.isInteger(o)||o<1||o>2147483647){n.error(d.InvalidIntervalTrigger,`Invalid interval '${e.content}' - expected 'every <n> <seconds|minutes|hours|days>'`,t),n.skipBlock(e.indent);return}return{kind:"IntervalTriggerSourceSyntax",amount:o,unit:Vr(i[2]),location:t}}default:return Ur(n,e)}}a(Wr,"parseTriggerSource");function Ur(n,e){let t=l(e),i=Nr.exec(e.content),o=i===null?void 0:jr(i[1]);if(i===null||o===void 0){n.error(d.InvalidScheduleTrigger,`Invalid schedule '${e.content}' - expected 'at <HH:mm>', optionally followed by 'on <Weekday>' or 'on day <n>'`,t),n.skipBlock(e.indent);return}if(i[3]!==void 0){let r=Number(i[3]);if(r<1||r>31){n.error(d.InvalidScheduleTrigger,`Invalid day of month '${r}' in '${e.content}' - a day of the month is between 1 and 31`,t),n.skipBlock(e.indent);return}return{kind:"ScheduleTriggerSourceSyntax",time:o,dayOfWeek:null,dayOfMonth:r,location:t}}return{kind:"ScheduleTriggerSourceSyntax",time:o,dayOfWeek:i[2]??null,dayOfMonth:null,location:t}}a(Ur,"parseSchedule");function jr(n){let[e,t]=n.split(":").map(Number);if(e>=0&&e<=23&&t>=0&&t<=59)return`${n}:00.0000000`}a(jr,"timeOf");function Vr(n){switch(n.replace(/s+$/,"")){case"second":return"Seconds";case"minute":return"Minutes";case"hour":return"Hours";default:return"Days"}}a(Vr,"unitOf");var Je=`(?:"(${_})"|(\\$strings\\.\\w+(?:\\.\\w+)*))`,Zr=f("^screen\\s+([A-Za-z_]\\w*)$"),_r=f("^data\\s+([\\w.]+(?:\\[\\])?)\\s+via\\s+query\\s+(\\w+(?:\\.\\w+)*)(?:\\s+by\\s+(\\w+))?$"),Gr=f("^action\\s+([A-Za-z_]\\w*(?:\\.\\w+)*)$"),Qr=f(`^label\\s+${Je}$`),Hr=f("^navigate\\s+to\\s+(\\w+(?:\\.\\w+)*)(?:\\s+by\\s+(\\w+))?$"),Jr=f("^[a-z_]\\w*$"),Kr=f(`^title\\s+${Je}$`),Xr=f(`^column\\s+([\\w.]+)(?:\\s+label\\s+${Je})?$`),es=f("^on\\s+row-click\\s+(navigate\\s+to\\s+.+)$"),ns=f(`^field\\s+([\\w.]+)\\s+label\\s+${Je}$`),zt=new Set(["csharp","typescript","react","html","sql"]),Ke=a((n,e)=>n[e]!==void 0?V(n[e]):n[e+1],"operandText"),ts=a(n=>["on","uses"].includes(T(n.content)),"isInteraction"),is=a(n=>n.content.startsWith("```")||zt.has(n.content),"isCodeLine");function Wt(n,e){let t=Zr.exec(e.content);t===null&&n.error(d.InvalidScreenDeclaration,`Invalid screen declaration '${e.content}' - expected 'screen <Name>'`,l(e));let i=[];for(let o=n.peekChild(e.indent);o!==void 0;o=n.peekChild(e.indent))n.reader.takeSignificant(),Z(o)||Ut(n,o,i);return{kind:"ScreenSyntax",name:t?.[1]??"",directives:i,location:l(e)}}a(Wt,"parseScreen");function Ut(n,e,t){let i=os(n,e);i!==void 0&&t.push(i)}a(Ut,"pushDirective");function jt(n,e){let t=[];for(let i=n.peekChild(e.indent);i!==void 0;i=n.peekChild(e.indent))n.reader.takeSignificant(),Ut(n,i,t);return t}a(jt,"parseDirectives");function os(n,e){switch(T(e.content)){case"data":return rs(n,e);case"action":return ss(n,e);case"template":return as(n,e);case"section":return cs(n,e);case"title":return ls(n,e);case"table":return ds(n,e);case"summary":return ps(n,e);case"navigate":return On(n,e.content,e);case"on":return X(n,e),{kind:"ScreenBehaviorSyntax",location:l(e)};case"uses":return n.skipOpaqueBlock(e.indent),{kind:"ScreenUsesBehaviorSyntax",location:l(e)};default:if(is(e))return us(n,e);n.error(d.UnknownScreenDirective,`Unexpected '${e.content}' in screen body`,l(e)),n.skipBlock(e.indent);return}}a(os,"parseDirective");function rs(n,e){let t=_r.exec(e.content);if(t===null){n.error(d.InvalidDataDirective,`Invalid data directive '${e.content}' - expected 'data <ReadModel> via query <Query> [by <param>]'`,l(e));return}return{kind:"ScreenDataSyntax",type:ie(t[1],l(e)),query:t[2],by:t[3]??null,location:l(e)}}a(rs,"parseData");function ss(n,e){let t=Gr.exec(e.content);if(t===null){n.error(d.InvalidActionDirective,`Invalid action directive '${e.content}' - expected 'action <Command>'`,l(e)),n.skipBlock(e.indent);return}let i=null,o=null;for(let r=n.peekChild(e.indent);r!==void 0;r=n.peekChild(e.indent)){n.reader.takeSignificant();let s=Qr.exec(r.content);s!==null?i=Ke(s,1):T(r.content)==="navigate"?o=On(n,r.content,r)??null:n.error(d.UnknownActionDirective,`Unexpected '${r.content}' in action - expected 'label "..."' or 'navigate to ...'`,l(r))}return{kind:"ScreenActionSyntax",command:t[1],label:i,navigate:o,location:l(e)}}a(ss,"parseAction");function On(n,e,t){let i=Hr.exec(e);if(i===null){n.error(d.InvalidNavigation,`Invalid navigation '${e}' - expected 'navigate to <Screen> [by <param>]'`,l(t));return}return{kind:"ScreenNavigateSyntax",screen:i[1],by:i[2]??null,location:l(t)}}a(On,"parseNavigate");function as(n,e){let t=e.content.substring(8).trim(),i=[];for(let o=n.peekChild(e.indent);o!==void 0;o=n.peekChild(e.indent)){if(n.reader.takeSignificant(),!Jr.test(o.content)){n.error(d.InvalidScreenLayoutSlot,`Expected a slot name in template '${t}', got '${o.content}'`,l(o)),n.skipBlock(o.indent);continue}i.push({kind:"ScreenSlotSyntax",name:o.content,directives:jt(n,o),location:l(o)})}return{kind:"ScreenTemplateReferenceSyntax",name:t,slots:i,location:l(e)}}a(as,"parseTemplateReference");function cs(n,e){return{kind:"ScreenSectionSyntax",name:e.content.substring(7).trim(),directives:jt(n,e),location:l(e)}}a(cs,"parseSection");function ls(n,e){let t=Kr.exec(e.content);return t===null?(n.error(d.InvalidTitleDirective,`Invalid title directive '${e.content}' - expected 'title "..."'`,l(e)),{kind:"ScreenTitleSyntax",text:"",location:l(e)}):{kind:"ScreenTitleSyntax",text:Ke(t,1),location:l(e)}}a(ls,"parseTitle");function ds(n,e){let t=e.content.substring(5).trim(),i=[],o=null;for(let r=n.peekChild(e.indent);r!==void 0;r=n.peekChild(e.indent)){n.reader.takeSignificant();let s=Xr.exec(r.content),c=es.exec(r.content);if(s!==null){let u=s[2]!==void 0||s[3]!==void 0;i.push({kind:"ScreenColumnSyntax",property:s[1],label:u?Ke(s,2):null,location:l(r)})}else c!==null?o=On(n,c[1],r)??null:T(r.content)==="on"?X(n,r):ts(r)?n.skipOpaqueBlock(r.indent):n.error(d.UnknownTableDirective,`Unexpected '${r.content}' in table - expected 'column ...', 'on row-click navigate to ...', 'on <trigger>' or 'uses <Behavior>'`,l(r))}return{kind:"ScreenTableSyntax",target:t,columns:i,rowClick:o,location:l(e)}}a(ds,"parseTable");function ps(n,e){let t=e.content.substring(7).trim(),i=[];for(let o=n.peekChild(e.indent);o!==void 0;o=n.peekChild(e.indent)){n.reader.takeSignificant();let r=ns.exec(o.content);if(r===null){n.error(d.UnknownSummaryDirective,`Unexpected '${o.content}' in summary - expected 'field <property> label "..."'`,l(o));continue}i.push({kind:"ScreenFieldSyntax",property:r[1],label:Ke(r,2),location:l(o)})}return{kind:"ScreenSummarySyntax",target:t,fields:i,location:l(e)}}a(ps,"parseSummary");function us(n,e){let t=e.content.startsWith("```")?e.content.substring(3):e.content;if(!zt.has(t)){n.error(d.ExpectedCodeFence,`Expected a registered language on the opening fence, not '${e.content}'`,l(e));return}e.content.startsWith("```")||n.warning(d.LegacyInlineCodeFence,`'${t}' on its own line is deprecated - use '\`\`\`${t}' instead`,l(e));let i=ve(n,t,e);return i===null?void 0:{kind:"ScreenCodeSyntax",code:{kind:"CodeBlockSyntax",language:t,code:i,location:l(e)},location:l(e)}}a(us,"parseCode");var Rn=f("^then\\s+returns\\b"),Vt=f("^generated\\s+(?=\\S)(?![=])"),Zt=f("^generated\\s+([a-z_]\\w*)\\s*=(?!=|>)\\s*(.+)$"),fs=f("^([\\w.]+)\\s*=(?!=|>)\\s*(.+)$"),ms=f(`^(?:"${_}"|'(?:[^'\\\\]|\\\\.)*')$`);function _t(n,e,t,i){if((e.startsWith('"')||e.startsWith("'"))&&!ms.test(e))return n.error(i,"Expected exactly one concrete value.",t),null;let o=Q(e,t,n);return!["LiteralExpressionSyntax","ObjectExpressionSyntax","ListExpressionSyntax"].includes(o.kind)||o.kind==="LiteralExpressionSyntax"&&typeof o.value=="number"&&!Number.isFinite(o.value)?(n.error(i,"Expected exactly one concrete literal or structured value, not an expression.",t),null):o}a(_t,"parseConcrete");function Xe(n,e,t,i){let o=t.exec(e.content);if(o===null)return n.error(i,"Expected a named fixture or assertion with exactly one concrete value.",l(e)),n.skipBlock(e.indent),null;let r=l(e),s=_t(n,o[2],{...r,column:r.column+e.content.indexOf(o[2],e.content.indexOf("=")+1)},i),c=n.peekChild(e.indent);return c!==void 0&&(n.error(i,"A fixture or return field cannot have child directives.",l(c)),n.skipBlock(e.indent)),s===null?null:{kind:"PropertyMappingSyntax",property:o[1],source:s,location:r}}a(Xe,"parseConcreteMapping");function Gt(n,e){let t=Rn.exec(e.content)[0].length,i=e.content.substring(t).trim(),o=l(e);if(i.length>0){let s=_t(n,i,{...o,column:o.column+e.content.indexOf(i,t)},d.InvalidReturnExpectation),c=n.peekChild(e.indent);return c!==void 0&&(n.error(d.InvalidReturnExpectation,"A scalar return expectation cannot have child assertions.",l(c)),n.skipBlock(e.indent)),s===null?null:{kind:"ScalarSpecificationReturnSyntax",value:s,location:o}}let r=[];for(let s=n.peekChild(e.indent);s!==void 0;s=n.peekChild(e.indent)){n.reader.takeSignificant();let c=Xe(n,s,fs,d.InvalidReturnExpectation);c!==null&&r.push(c)}return{kind:"RecordSpecificationReturnSyntax",fields:r,location:o}}a(Gt,"parseReturn");var hs=f("^(?:given\\s+operation|then\\s+(?:operation|compensated))(?:\\s|$)"),vs=f("^(given operation|then operation|then compensated)\\s+([A-Za-z_]\\w*(?:\\.[A-Za-z_]\\w*)*)(\\s+fails)?$"),gs=f("^specification\\s+([A-Za-z_]\\w*)$"),ys=f("^given\\s+([A-Z]\\w*)$"),ks=f("^when\\s+append\\s+([A-Z]\\w*)$"),Ss=f("^when\\s+([A-Z]\\w*)$"),ws=f("^then\\s+([A-Z]\\w*)$"),bs=f("^then\\s+query\\b"),Qt=f("^(?:given|then)\\s+readmodel\\b"),Ps=f("^given\\s+readmodel\\s+([A-Z]\\w*)$"),Is=f("^then\\s+readmodel\\s+([A-Z]\\w*)(\\s+exactly)?$"),Ht=f("^then\\s+no\\b"),Cs=f(`^then\\s+error\\s+"(${_})"$`),Mn=f("^([\\w.]+)\\s*=(?!=|>)\\s*(.+)$"),$s=f("^given\\s+clock\\b"),As=f("^given\\s+capture\\b"),Es=f("^when\\s+clock\\b"),Ds=f("^when\\s+trigger\\b"),Os=f("^when\\s+capture\\b"),Rs=f("^when\\s+query\\b"),Ts=f("^then\\s+result\\b"),Ms=f("^then\\s+no\\s+result\\b"),Ls=f('^(given|when)\\s+clock\\s+"(\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(?::\\d{2}(?:\\.\\d+)?)?(?:Z|[+-]\\d{2}:\\d{2}))"$'),xs=f("^when\\s+trigger\\s+([A-Za-z_]\\w*)$"),Ns=f("^(?:given|when)\\s+capture\\s+([A-Za-z_]\\w*)$"),Bs=f("^when\\s+query\\s+([A-Za-z_]\\w*(?:\\.\\w+)*)$"),Ys=f("^then\\s+result(\\s+exactly)?$");function Jt(n,e){let t=gs.exec(e.content)?.[1]??"";t===""&&n.error(d.InvalidSpecificationDeclaration,`Invalid specification declaration '${e.content}' - expected 'specification <Name>'`,l(e));let i={givenOperationFailures:[],thenOperations:[],thenCompensated:[],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,thenReturns:null};for(let s=n.peekChild(e.indent);s!==void 0;s=n.peekChild(e.indent)){if(n.reader.takeSignificant(),Z(s)||Fs(n,s,i))continue;let c=Ht.test(s.content)?"then":T(s.content);c==="given"?qs(n,s,i):c==="when"?zs(n,s,i,t):c==="then"?Ws(n,s,i):(n.error(d.UnknownSpecificationDirective,`Unexpected '${T(s.content)}' in specification body`,l(s)),n.skipBlock(s.indent))}let{whenDeclared:o,...r}=i;return{kind:"SpecificationSyntax",name:t,...r,location:l(e)}}a(Jt,"parseSpecification");function Fs(n,e,t){if(!hs.test(e.content))return!1;let i=vs.exec(e.content);if(i===null||i[1]==="given operation"!=(i[3]!==void 0))n.error(d.InvalidOperationSpecification,"Expected 'given operation <Name> fails', 'then operation <Name>' or 'then compensated <Name>'.",l(e)),n.skipBlock(e.indent);else if(i[1]==="then operation"){let o=[];for(let r=n.peekChild(e.indent);r!==void 0;r=n.peekChild(e.indent)){n.reader.takeSignificant();let s=Xe(n,r,Mn,d.InvalidOperationSpecification);s!==null&&o.push(s)}t.thenOperations.push({kind:"SpecificationOperationSyntax",operation:i[2],values:o,location:l(e)})}else Ee(n,e,d.InvalidOperationSpecification,"Failure and compensation assertions cannot have children."),i[1]==="given operation"?t.givenOperationFailures.push({kind:"SpecificationOperationFailureSyntax",operation:i[2],location:l(e)}):t.thenCompensated.push({kind:"SpecificationCompensatedSyntax",operation:i[2],location:l(e)});return!0}a(Fs,"parseOperationStep");function qs(n,e,t){if($s.test(e.content))t.givenClock!==null?(n.error(d.InvalidSpecificationClock,"A specification states its clock at most once.",l(e)),n.skipBlock(e.indent)):t.givenClock=Kt(n,e,"given");else if(As.test(e.content)){let i=Xt(n,e,"given");i!==null&&t.givenCaptures.push(i)}else if(e.content.startsWith("given caller"))n.skipOpaqueBlock(e.indent);else if(Qt.test(e.content)){let i=ei(n,e,Ps,"given");i!==void 0&&t.givenReadModels.push(i)}else{let i=Ln(n,e,ys,"given");i!==void 0&&t.given.push(i)}}a(qs,"parseGiven");function zs(n,e,t,i){let o=e.content.startsWith("when append");if(t.whenDeclared){let u=t.whenAppended!==null||o?d.ConflictingSpecificationActions:d.DuplicateSpecificationWhen;n.error(u,`Specification '${i}' already declares a 'when' - a specification can have at most one`,l(e)),n.skipBlock(e.indent);return}if(t.whenDeclared=!0,o){t.whenAppended=Ln(n,e,ks,"when append")??null;return}if(Es.test(e.content)){t.whenClock=Kt(n,e,"when");return}if(Ds.test(e.content)){t.whenTrigger=Tn(n,e,xs,d.InvalidSpecificationTrigger,"when trigger","when trigger <Trigger>",(u,p)=>({kind:"SpecificationTriggerSyntax",trigger:u,values:p,location:l(e)}));return}if(Os.test(e.content)){t.whenCapture=Xt(n,e,"when");return}if(Rs.test(e.content)){t.whenQuery=Tn(n,e,Bs,d.InvalidSpecificationQueryAction,"when query","when query <Query>",(u,p)=>({kind:"SpecificationWhenQuerySyntax",query:u,arguments:p,location:l(e)}));return}let r=Ss.exec(e.content);if(r===null){n.error(d.InvalidSpecificationWhen,`Invalid 'when' declaration '${e.content}' - expected 'when <CommandType>' or 'when append <EventType>'`,l(e)),n.skipBlock(e.indent);return}let s=[],c=ni(n,e,s);t.when={kind:"SpecificationCommandSyntax",commandType:r[1],...c,generatedValues:s,location:l(e)}}a(zs,"parseWhen");function Ws(n,e,t){if(Rn.test(e.content)){let r=Gt(n,e);t.thenReturns!==null?n.error(d.InvalidReturnExpectation,"A specification declares at most one return expectation.",l(e)):t.thenReturns=r;return}if(e.content.startsWith("then events")){e.content!=="then events in any order"||t.thenEventsInAnyOrder?n.error(d.InvalidSpecificationEventOrder,"Expected one 'then events in any order' directive.",l(e)):t.thenEventsInAnyOrder=!0,n.skipBlock(e.indent);return}if(Ts.test(e.content)){Us(n,e,t);return}if(Ms.test(e.content)){e.content!=="then no result"||t.thenNoResult!==null?n.error(d.InvalidSpecificationQueryAction,"Expected one 'then no result' directive.",l(e)):t.thenNoResult={kind:"SpecificationNoResultSyntax",location:l(e)},n.skipBlock(e.indent);return}if(e.content.startsWith("then denied")){e.content!=="then denied"?(n.error(d.InvalidSpecificationDenied,"Expected exactly 'then denied'.",l(e)),n.skipBlock(e.indent)):t.thenDenied!==null?n.error(d.DuplicateSpecificationCallerOrDenied,"A specification has at most one 'then denied' outcome.",l(e)):t.thenDenied={kind:"SpecificationDeniedSyntax",location:l(e)};return}if(e.content==="then error"){t.thenErrors.push({kind:"SpecificationErrorSyntax",name:null,location:l(e)});return}let i=Cs.exec(e.content);if(i!==null){t.thenErrors.push({kind:"SpecificationErrorSyntax",name:V(i[1]),location:l(e)});return}if(T(e.content.substring(4).trim())==="error"){n.error(d.InvalidThenError,`Invalid 'then error' declaration '${e.content}' - expected 'then error' or 'then error "<reason>"'`,l(e)),n.skipBlock(e.indent);return}if(Ht.test(e.content)||bs.test(e.content)){n.skipOpaqueBlock(e.indent);return}if(Qt.test(e.content)){let r=ei(n,e,Is,"then");r!==void 0&&t.thenReadModels.push(r);return}let o=Ln(n,e,ws,"then");o!==void 0&&t.thenEvents.push(o)}a(Ws,"parseThen");function Kt(n,e,t){let i=Ls.exec(e.content);return n.skipBlock(e.indent),i===null||i[1]!==t?(n.error(d.InvalidSpecificationClock,`Invalid '${t} clock' - expected '${t} clock "<ISO 8601 instant>"', such as '${t} clock "2026-10-05T08:00:00Z"'`,l(e)),null):{kind:"SpecificationClockSyntax",instant:i[2],location:l(e)}}a(Kt,"parseClock");function Xt(n,e,t){return Tn(n,e,Ns,d.InvalidSpecificationCapture,`${t} capture`,`${t} capture <Capture>`,(i,o)=>({kind:"SpecificationCaptureSyntax",capture:i,record:o,location:l(e)}))}a(Xt,"parseCapture");function Tn(n,e,t,i,o,r,s){let c=t.exec(e.content);return c===null?(n.error(i,`Invalid '${o}' declaration '${e.content}' - expected '${r}'`,l(e)),n.skipBlock(e.indent),null):s(c[1],xn(n,e))}a(Tn,"parseNamedStep");function Us(n,e,t){let i=Ys.exec(e.content);if(i===null){n.error(d.InvalidSpecificationQueryAction,`Invalid 'then result' declaration '${e.content}' - expected 'then result [exactly]'`,l(e)),n.skipBlock(e.indent);return}t.thenResults.push({kind:"SpecificationQueryResultSyntax",properties:xn(n,e),exactly:i[1]!==void 0,location:l(e)})}a(Us,"parseResult");function ei(n,e,t,i){let o=t.exec(e.content);if(o===null){n.error(d.InvalidReadModelStep,`Invalid '${i} readmodel' declaration '${e.content}' - expected '${i} readmodel <ReadModelType>'`,l(e)),n.skipBlock(e.indent);return}return{kind:"SpecificationReadModelSyntax",name:o[1],properties:xn(n,e),exactly:i==="then"&&o[2]!==void 0,location:l(e)}}a(ei,"parseReadModelStep");function Ln(n,e,t,i){let o=t.exec(e.content);if(o===null){n.error(d.InvalidEventStep,`Invalid '${i}' declaration '${e.content}' - expected '${i} <EventType>'`,l(e)),n.skipBlock(e.indent);return}return{kind:"SpecificationEventSyntax",eventType:o[1],...ni(n,e),location:l(e)}}a(Ln,"parseEventStep");function ni(n,e,t){let i=[],o=null;for(let r=n.peekChild(e.indent);r!==void 0;r=n.peekChild(e.indent)){if(n.reader.takeSignificant(),t!==void 0&&Vt.test(r.content)){let c=Xe(n,r,Zt,d.InvalidGeneratedFixture);c!==null&&t.push(c);continue}let s=Mn.exec(r.content);if(s!==null)i.push(ti(n,r,s));else if(T(r.content)==="for"){let c=r.content.substring(3).trim();c.length===0?n.error(d.InvalidSpecificationEventSource,"Invalid event-source assertion 'for' - expected 'for <value>'",l(r)):o!==null?n.error(d.DuplicateSpecificationEventSource,"A specification step can declare its event-source assertion only once",l(r)):o=Q(c,l(r),n)}else n.error(d.InvalidSpecificationValue,`Invalid property mapping '${r.content}' - expected '<property> = <value>'`,l(r))}return{values:i,for:o}}a(ni,"parseValuesWithEventSource");function xn(n,e){let t=[];for(let i=n.peekChild(e.indent);i!==void 0;i=n.peekChild(e.indent)){n.reader.takeSignificant();let o=Mn.exec(i.content);if(o===null){n.error(d.InvalidSpecificationValue,`Invalid property mapping '${i.content}' - expected '<property> = <value>'`,l(i));continue}t.push(ti(n,i,o))}return t}a(xn,"parseValues");function ti(n,e,t){return{kind:"PropertyMappingSyntax",property:t[1],source:Q(t[2],l(e),n),location:l(e)}}a(ti,"mappingOf");var js=f("^slice\\s+([A-Za-z]\\w*)\\s+([A-Za-z_]\\w*)$"),Vs=new Set(["reducer"]);function ii(n,e){let t=js.exec(e.content),i="StateChange",o="";t===null?n.error(d.InvalidSliceDeclaration,`Invalid slice declaration '${e.content}' - expected 'slice <Type> <Name>'`,l(e)):(o=t[2],ut.includes(t[1])?i=t[1]:n.error(d.UnknownSliceType,`Unknown slice type '${t[1]}' - expected StateChange, StateView, Automation or Translate`,l(e)));let r=n.scope;n.scope=[...r,o];let s=null,c=[],u=[],p=[],I=[],v=[],k=[],w=[],P=[],C=[],D=[],S=[];for(let $=n.peekChild(e.indent);$!==void 0;$=n.peekChild(e.indent)){if(n.reader.takeSignificant(),Z($))continue;let m=T($.content);m==="description"?s=U(n,$,s,`Slice '${o}'`):m==="operation"?u.push(_e(n,$).operation):m==="event"?c.push(At(n,$)):m==="command"?p.push(Rt(n,$)):m==="query"?I.push(Yt(n,$)):m==="projection"?v.push(Mt(n,$)):m==="capture"?w.push(mt(n,$)):m==="reaction"?k.push(qt(n,$)):m==="constraint"?P.push(Tt(n,$)):m==="specification"?C.push(Jt(n,$)):m==="readmodel"?D.push(Et(n,$)):m==="screen"?S.push(Wt(n,$)):Vs.has(m)?n.skipOpaqueBlock($.indent):(n.warning(d.UnknownSliceDirective,`Unknown construct '${m}' in slice '${o}'`,l($)),n.skipBlock($.indent))}return n.scope=r,{kind:"SliceSyntax",type:i,name:o,description:s,events:c,operations:u,commands:p,queries:I,projections:v,captures:w,reactions:k,constraints:P,specifications:C,readModels:D,screens:S,location:l(e)}}a(ii,"parseSlice");var Zs=f("^feature\\s+([A-Za-z_]\\w*)$"),_s=new Set(["on","uses","contribute"]),Nn="description, authorize, import, feature, slice, contribute, 'on <trigger>' or 'uses <Behavior>'",De=class{static{a(this,"FeatureBody")}name;#e=[];#n=[];#i=[];#t=null;#o=null;constructor(e){this.name=e}tryParse(e,t){let i=T(t.content);switch(i){case"description":return this.#t=U(e,t,this.#t,`Feature '${this.name}'`),!0;case"authorize":return this.#o=ne(this.#o,re(e,t)),!0;case"import":return ge(e,t,this.#i),!0;case"feature":return this.#e.push(en(e,t)),!0;case"slice":return this.#n.push(ii(e,t)),!0;default:return _s.has(i)?(X(e,t),!0):!1}}build(e,t=!1){return{kind:"FeatureSyntax",name:this.name,description:this.#t,authorize:this.#o,features:this.#e,slices:this.#n,fileImports:this.#i,isPlacement:t,location:e}}};function en(n,e){let t=Zs.exec(e.content)?.[1]??"";t===""&&n.error(d.InvalidFeatureDeclaration,`Invalid feature declaration '${e.content}' - expected 'feature <Name>'`,l(e));let i=new De(t),o=n.scope;n.scope=[...o,t];for(let r=n.peekChild(e.indent);r!==void 0;r=n.peekChild(e.indent))n.reader.takeSignificant(),i.tryParse(n,r)||(n.error(d.UnknownFeatureDirective,`Unexpected '${T(r.content)}' in feature body - expected ${Nn}`,l(r)),n.skipBlock(r.indent));return n.scope=o,i.build(l(e))}a(en,"parseFeature");var Bn=f("^module\\s+([A-Za-z_]\\w*)$"),Gs=new Set(["on","uses","screen","dialog","form","contribute"]),Yn="description, authorize, import, screen template, dialog template, form, contribute, feature, 'on <trigger>' or 'uses <Behavior>'",Oe=class{static{a(this,"ModuleBody")}name;#e=[];#n=[];#i=null;#t=null;constructor(e){this.name=e}tryParse(e,t){let i=T(t.content);switch(i){case"description":return this.#i=U(e,t,this.#i,`Module '${this.name}'`),!0;case"authorize":return this.#t=ne(this.#t,re(e,t)),!0;case"import":return ge(e,t,this.#n),!0;case"feature":return this.#e.push(en(e,t)),!0;default:return Gs.has(i)?(X(e,t),!0):!1}}parseChildren(e,t){for(let i=e.peekChild(t.indent);i!==void 0;i=e.peekChild(t.indent))e.reader.takeSignificant(),this.tryParse(e,i)||(e.error(d.UnknownModuleDirective,`Unexpected '${T(i.content)}' in module body - expected ${Yn}`,l(i)),e.skipBlock(i.indent))}build(e,t=!1){return{kind:"ModuleSyntax",name:this.name,description:this.#i,authorize:this.#t,features:this.#e,fileImports:this.#n,isPlacement:t,location:e}}};function Fn(n,e){let t=Bn.exec(e.content)?.[1]??"";t===""&&n.error(d.InvalidModuleDeclaration,`Invalid module declaration '${e.content}' - expected 'module <Name>'`,l(e));let i=new Oe(t),o=n.scope;return n.scope=[t],i.parseChildren(n,e),n.scope=o,i.build(l(e))}a(Fn,"parseModule");var Qs=/^([0-9]{4})-([0-9]{2})-([0-9]{2})$/,Hs=/^([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 qn(n,e){let t=(e?Hs:Qs).exec(n);if(t===null||t[0].length!==n.length)return!1;let i=Number(t[1]),o=Number(t[2]),r=Number(t[3]),c=[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||o<1||o>12||r<1||r>c[o-1])return!1;if(!e)return!0;if(Number(t[4])>23||Number(t[5])>59||Number(t[6])>59)return!1;if(t[7]===void 0)return!0;let u=Number(t[7]),p=Number(t[8]);return u<=14&&p<=59&&(u!==14||p===0)}a(qn,"responseDateValue");var nn=new Set(["Uuid","String","Int","Decimal","Bool","Date","DateTime"]);function tn(n,e,t=e.inputUses){let i=[],o=a((g,y)=>{let h=[...y,g.name];g.slices.forEach(A=>i.push({slice:A,scope:[...h,A.name]})),g.features.forEach(A=>o(A,h))},"collect");n.modules.forEach(g=>g.features.forEach(y=>o(y,[g.name])));let r=new Map,s=new Map,c=new Map;for(let{slice:g,scope:y}of i)for(let h of g.commands){let A=r.get(h.name)??[];A.push({command:h,scope:y}),r.set(h.name,A),s.set(h,oe(h.properties)),h.response?.kind==="RecordCommandResponseSyntax"&&c.set(h,oe(h.response.fields))}let u=new Map;for(let g of n.imports){let y=g.qualifiedName.split(".").at(-1);u.set(y,[...u.get(y)??[],g.qualifiedName])}let p=new Map,I=a((g,y)=>{let h=`${y.join(".")}|${g}`;if(p.has(h))return p.get(h);let A=u.get(g)??[],L=((r.get(g.split(".").at(-1))??[]).length===0&&A.length===1?A[0]:g).split("."),x=r.get(L.at(-1))??[];if(L.length>1){let F=L.slice(0,-1);x=x.filter(N=>F.length<=N.scope.length&&F.every((b,O)=>N.scope[N.scope.length-F.length+O]===b))}else for(let F=y.length;F>=0;F--){let N=x.filter(b=>F<=b.scope.length&&y.slice(0,F).every((O,M)=>b.scope[M]===O));if(N.length>0){x=N;break}}let Y=x.length===1?x[0].command:null;return p.set(h,Y),Y},"resolve"),v=oe(n.concepts),k=new Set(n.concepts.map(g=>g.name)),w=new Map([...oe(n.types)].map(([g,y])=>[g,oe(y.properties)])),P=new Set(i.flatMap(g=>g.slice.readModels.map(y=>y.name))),C=new Set([...s.keys()].flatMap(g=>[...g.properties])),D=a(g=>{for(let y of g)y.isGenerated&&!C.has(y)&&e.error(d.GeneratedPropertyOutsideCommand,"Generated properties can only be declared on commands.",y.location)},"checkDeclarations"),S=a(g=>{g.features.forEach(S);for(let y of g.slices){for(let h of y.commands)for(let A of h.produces)A.inlineEvent!==null&&D(A.inlineEvent.properties);y.events.forEach(h=>D(h.properties)),y.readModels.forEach(h=>D(h.properties));for(let h of y.reactions)for(let A of h.triggers)for(let R of A.produces)R.inlineEvent!==null&&D(R.inlineEvent.properties)}},"checkFeature");n.types.forEach(g=>D(g.properties)),n.modules.forEach(g=>g.features.forEach(S));let $=a((g,y,h)=>{let A=s.get(h).get(g.property);if(A===void 0){e.error(d.InvalidResponseSource,`Response source '${g.property}' must reference one direct command property.`,g.location);return}let R=A.type;(R.isCollection||P.has(R.name))&&e.error(d.InvalidResponseShape,"Collection and whole-read-model responses are not supported.",g.location),y!==null&&(y.name!==R.name||y.isCollection!==R.isCollection||y.isOptional!==R.isOptional)&&e.error(d.InvalidResponseShape,"An explicit response field type must match its source's declared type, collection shape and optionality.",y.location)},"validateSource");for(let g of s.keys()){for(let h of g.properties){if(!h.isGenerated)continue;let A=v.get(h.type.name);(h.type.isOptional||h.type.isCollection||(A===void 0?nn.has(h.type.name)||w.has(h.type.name)||k.has(h.type.name)||P.has(h.type.name):A.type!=="Uuid"))&&e.error(d.InvalidGeneratedType,"A generated property must be a required, noncollection concept backed by Uuid.",h.location)}let y=g.response;if(y?.kind==="ScalarCommandResponseSyntax")$(y.source,null,g);else if(y?.kind==="RecordCommandResponseSyntax"){y.fields.length===0&&e.error(d.InvalidCommandResponse,"A response block requires at least one field.",y.location);let h=new Set;for(let A of y.fields)h.has(A.name)&&e.error(d.DuplicateResponseField,`Duplicate response field '${A.name}'.`,A.location),h.add(A.name),$(A.source,A.type,g)}}let m=a((g,y)=>{let h=g.when,A=h===null?null:I(h.commandType,y);if(h!==null&&A!==null){let x=s.get(A);for(let N of h.values)x.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 Y=[...x.values()].filter(N=>N.isIdentifier);if(h.for!==null&&Y.length===1&&Y[0].isGenerated){let N=Y[0].type;(nn.has(N.name)||v.has(N.name)||w.has(N.name))&&(N.isOptional||N.isCollection||v.get(N.name)?.type!=="Uuid"||h.for.kind!=="LiteralExpressionSyntax"||typeof h.for.value!="string"||!oi(h.for.value))&&e.error(d.InvalidGeneratedFixture,"A generated identifier fixture must supply one compatible concrete UUID value through 'for'.",h.for.location)}let F=new Set;for(let N of h.generatedValues??[]){let b=x.get(N.property);(F.has(N.property)||b===void 0||!b.isGenerated||b.isIdentifier||!fe(N.source,b.type,v,w))&&e.error(d.InvalidGeneratedFixture,"A generated fixture must uniquely supply a compatible value for a nonidentifier generated command property.",N.location),F.add(N.property)}}let R=g.thenReturns;if(R==null||((h===null||g.thenErrors.length>0||g.thenDenied!=null)&&e.error(d.InvalidReturnExpectation,"A return expectation requires a command action and cannot accompany an error or denial.",R.location),A===null))return;let E=A.response,L=s.get(A);if(R.kind==="ScalarSpecificationReturnSyntax"&&E?.kind==="ScalarCommandResponseSyntax"&&L.has(E.source.property))fe(R.value,L.get(E.source.property).type,v,w)||e.error(d.InvalidReturnExpectation,"The expected return value must match the response source's type.",R.location);else if(R.kind==="RecordSpecificationReturnSyntax"&&E?.kind==="RecordCommandResponseSyntax"){R.fields.length===0&&e.error(d.InvalidReturnExpectation,"A record return expectation requires at least one field.",R.location);let x=c.get(A),Y=new Set;for(let F of R.fields){let N=x.get(F.property),b=N===void 0?void 0:L.get(N.source.property);(Y.has(F.property)||b===void 0||!fe(F.source,b.type,v,w))&&e.error(d.InvalidReturnExpectation,"A return assertion must uniquely name a response field and supply a compatible concrete value.",F.location),Y.add(F.property)}}else e.error(d.InvalidReturnExpectation,"The return expectation must match the command's scalar or record response shape.",R.location)},"validateSpecification");for(let{slice:g,scope:y}of i)g.specifications.forEach(h=>m(h,y));for(let g of t){if(g.isParameter===!0)continue;let y=I(g.command,g.scope);y!==null&&s.get(y).get(g.property.split(".")[0])?.isGenerated&&e.error(d.GeneratedPropertySuppliedAsInput,`Generated property '${g.property}' cannot be supplied as request or form input.`,g.location)}}a(tn,"validateResponses");function oe(n){let e=new Map,t=new Set;for(let i of n)e.has(i.name)&&t.add(i.name),e.set(i.name,i);return t.forEach(i=>e.delete(i)),e}a(oe,"uniqueByName");function fe(n,e,t,i){if(n.kind==="LiteralExpressionSyntax"&&n.value===null)return e.isOptional;if(e.isCollection)return n.kind==="ListExpressionSyntax"&&n.items.every(c=>fe(c,{...e,isCollection:!1,isOptional:!1},t,i));let o=i.get(e.name);if(o!==void 0)return n.kind==="ObjectExpressionSyntax"&&n.members.every(c=>{let u=o.get(c.name);return u!==void 0&&fe(c.value,u.type,t,i)});let r=t.get(e.name),s=r?.type??e.name;if(r?.type==="Enum")return n.kind==="LiteralExpressionSyntax"&&typeof n.value=="string"&&r.values.includes(n.value);if(n.kind==="LiteralExpressionSyntax")switch(s){case"Uuid":return typeof n.value=="string"&&oi(n.value);case"String":return typeof n.value=="string";case"Bool":return typeof n.value=="boolean";case"Int":return typeof n.value=="number"&&Number.isFinite(n.value)&&Number.isInteger(n.value);case"Decimal":return typeof n.value=="number"&&Number.isFinite(n.value);case"Date":return typeof n.value=="string"&&qn(n.value,!1);case"DateTime":return typeof n.value=="string"&&qn(n.value,!0);default:return!nn.has(s)}return!nn.has(s)&&r===void 0}a(fe,"compatibleValue");var Js=/^(?:[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 oi(n){return Js.test(n)}a(oi,"uuidValue");var ke=class n{static{a(this,"LineReader")}lines;#e=0;constructor(e){this.lines=e}fork(){let e=new n(this.lines);return e.#e=this.#e,e}peekSignificant(){for(;this.#e<this.lines.length&&rt(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 Se(n){return[...n.events,...n.commands.flatMap(e=>e.produces).flatMap(e=>e.inlineEvent===null?[]:[e.inlineEvent])]}a(Se,"eventDeclarations");function on(n){return[...n.operations??[],...n.commands.flatMap(e=>e.produces).flatMap(e=>e.inlineOperation==null?[]:[e.inlineOperation])]}a(on,"operationDeclarations");var j;(function(n){n.Event="event",n.Operation="operation",n.Unresolved="unresolved",n.Ambiguous="ambiguous"})(j||(j={}));var ce=class{static{a(this,"AuthoringProductionResolver")}declarations=[];slices=[];byName=new Map;scopes=new Map;resolutions=new Map;constructor(e){let t=a((i,o)=>{for(let r of i){let s=[...o,r.name];for(let c of r.slices)this.slices.push({slice:c,scope:[...s,c.name]});t(r.features,s)}},"collect");e.modules.forEach(i=>t(i.features,[i.name]));for(let{slice:i,scope:o}of this.slices){this.scopes.set(i,o);let r=new Map;for(let c of Se(i)){let u=r.get(c.name)??[];u.push(c),r.set(c.name,u)}let s=[...r.values()].flatMap(c=>new Set(c.map(u=>u.generation)).size!==c.length?c:[c.reduce((u,p)=>u.generation>=p.generation?u:p)]);this.declarations.push(...s.map(c=>({kind:j.Event,name:c.name,node:c,scope:o})),...on(i).map(c=>({kind:j.Operation,name:c.name,node:c,scope:o})))}for(let i of this.declarations){let o=this.byName.get(i.name)??[];o.push(i),this.byName.set(i.name,o)}}resolve(e,t){let i=this.scopes.get(t);if(i===void 0)return{kind:j.Unresolved,declaration:null,candidates:[]};let o=this.resolutions.get(t)??new Map,r=o.get(e);if(r!==void 0)return r;let s=this.candidates(e,i),c=s.length===1?{kind:s[0].kind,declaration:s[0],candidates:[]}:{kind:s.length===0?j.Unresolved:j.Ambiguous,declaration:null,candidates:s};return o.set(e,c),this.resolutions.set(t,o),c}isOperation(e,t){return e.inlineOperation!=null||this.resolve(e.event,t).kind===j.Operation}isEventProduction(e,t){if(e.inlineOperation!=null)return!1;let i=this.resolve(e.event,t);return i.kind!==j.Operation&&!(i.kind===j.Ambiguous&&i.candidates.some(o=>o.kind===j.Operation))}candidates(e,t){let i=e.split("."),o=this.byName.get(i.at(-1))??[],r=i.slice(0,-1);if(r.length>0)return o.filter(s=>r.length<=s.scope.length&&r.every((c,u)=>s.scope[s.scope.length-r.length+u]===c));for(let s=t.length;s>=0;s--){let c=o.filter(u=>s<=u.scope.length&&t.slice(0,s).every((p,I)=>u.scope[I]===p));if(c.length>0)return c}return[]}};function Ks(n,e){return n.produces.filter(t=>t.inlineOperation==null&&(e===void 0||e.resolver.isEventProduction(t,e.slice)))}a(Ks,"eventProductions");function ri(n,e){let t=Ks(n,e),i=n.properties.find(o=>o.isIdentifier)?.name;return t.some(o=>o.for!==null&&(o.for.kind!=="PathExpressionSyntax"||o.for.path!==i))||t.some(o=>o.inlineEvent!==null&&o.for===null)&&t.some(o=>o.inlineEvent===null&&o.for===null)}a(ri,"requiresExplicitDestinations");function rn(n,e){let t=[],i=a(c=>{t.push(...c.slices),c.features.forEach(i)},"inFeature");n.modules.forEach(c=>c.features.forEach(i));let o=new Map;for(let c of t.flatMap(Se))o.set(c.name,(o.get(c.name)??0)+1);let r=new Set(n.imports.map(c=>c.qualifiedName.split(".").at(-1))),s=new ce(n);for(let{slice:c,command:u}of t.flatMap(p=>p.commands.map(I=>({slice:p,command:I})))){let p=u.produces.filter(k=>s.isEventProduction(k,c)),I=u.properties.find(k=>k.isIdentifier)?.name,v=ri(u,{resolver:s,slice:c});for(let k of p){let w=k.inlineEvent;w!==null&&((o.get(w.name)??0)>1||r.has(w.name))&&e.error(d.InlineEventCollision,`Inline event '${w.name}' collides with another event declaration or import`,k.location),v&&k.for===null&&e.error(d.ExplicitProducesTargetsRequired,`Production '${k.event}' in command '${u.name}' must state 'for' explicitly - every production must state 'for' when destinations differ`,k.location);let P=k.for?.kind==="PathExpressionSyntax"?k.for.path:k.for===null&&w!==null?I:void 0;if(!(I===void 0||P!==I))for(let C of k.mappings.filter(D=>D.source.kind==="PathExpressionSyntax"&&D.source.path===I)){let D=`Event '${k.event}' copies command identifier '${I}' into payload property '${C.property}' although it already identifies the event source`;w===null?e.information(d.EventSourceIdInPayload,D,C.location):e.warning(d.EventSourceIdInPayload,D,C.location)}}}}a(rn,"validateInlineEvents");function sn(n,e){let t=new ce(n),i=oe(n.concepts),o=new Map([...oe(n.types)].map(([S,$])=>[S,oe($.properties)])),r=new Set(["Uuid","String","Int","Decimal","Bool","Date","DateTime",...i.keys(),...o.keys()]),s=new Set(n.imports.map(S=>S.qualifiedName.split(".").at(-1))),c=new Map;for(let S of n.imports){let $=S.qualifiedName.split(".").at(-1);c.set($,[...c.get($)??[],S.qualifiedName])}let u=a(S=>{let $=new Map,m=new Map;for(let g of S){let y=$.get(g.name)??[];y.push(g),$.set(g.name,y)}return(g,y)=>{let h=JSON.stringify([g,y]);if(m.has(h))return m.get(h);let A=a(x=>{let Y=x.split("."),F=$.get(Y.at(-1))??[],N=Y.slice(0,-1);if(N.length>0)return F.filter(b=>N.length<=b.scope.length&&N.every((O,M)=>b.scope[b.scope.length-N.length+M]===O));for(let b=y.length;b>=0;b--){let O=F.filter(M=>b<=M.scope.length&&y.slice(0,b).every((B,K)=>M.scope[K]===B));if(O.length>0)return O}return[]},"candidates"),R=A(g),E=c.get(g)??[];R.length===0&&E.length===1&&(R=A(E[0]));let L=R.length===1?R[0].node:null;return m.set(h,L),L}},"scoped"),p=u(t.slices.flatMap(({slice:S,scope:$})=>S.readModels.map(m=>({name:m.name,scope:$,node:m})))),I=u(t.slices.flatMap(({slice:S,scope:$})=>S.commands.map(m=>({name:m.name,scope:$,node:{command:m,slice:S}})))),v=new Map;for(let S of n.systems??[])v.has(S.name)&&e.error(d.InvalidSystemDeclaration,`System '${S.name}' is declared more than once.`,S.location),v.set(S.name,(v.get(S.name)??0)+1);let k=a((S,$,m=!0)=>{let[g,...y]=$.split("."),h=S.filter(L=>L.name===g);if(h.length!==1)return{type:null,missing:h.length===0};let A=h[0].type;if(y.length===0)return{type:A,missing:!1};let R=o.get(A.name);if(R===void 0)return{type:null,missing:r.has(A.name)};let E=k([...R.values()],y.join("."),m);return E.type===null?E:{type:{...E.type,isOptional:m&&A.isOptional||E.type.isOptional,isCollection:A.isCollection||E.type.isCollection},missing:!1}},"pathType"),w=a((S,$,m,g,y=new Set)=>{if(m.has($)||S.isOptional&&!g.has($))return!0;if(S.isCollection||y.has(S.name))return!1;let h=o.get(S.name);return h===void 0?g.has($)&&!r.has(S.name):[...h.values()].every(A=>w(A.type,`${$}.${A.name}`,m,g,new Set([...y,S.name])))},"covered"),P=a((S,$)=>{if(S.kind==="ListExpressionSyntax"&&$.isCollection)return S.items.every(g=>P(g,{...$,isCollection:!1,isOptional:!1}));let m=o.get($.name);return S.kind!=="ObjectExpressionSyntax"||m===void 0?!0:[...m.values()].every(g=>(g.type.isOptional||S.members.some(y=>y.name===g.name))&&S.members.filter(y=>y.name===g.name).every(y=>P(y.value,g.type)))},"completeValue"),C=a(S=>S.kind==="LiteralExpressionSyntax"?typeof S.value!="number"||Number.isFinite(S.value):S.kind==="ObjectExpressionSyntax"?S.members.every($=>C($.value)):S.kind==="ListExpressionSyntax"&&S.items.every(C),"concrete"),D=a((S,$,m,g,y)=>{let h=new Set,A=new Set(S.map(E=>E.property)),R=new Set;for(let E of S){let L=E.property.split(".");for(let x=1;x<=L.length;x++)R.add(L.slice(0,x).join("."))}for(let E of S){h.has(E.property)&&e.error(d.InvalidOperationMapping,`Duplicate operation input mapping '${E.property}'.`,E.location),h.add(E.property);let L=k($.inputs,E.property,!1);if(L.missing&&e.error(d.InvalidOperationMapping,`Operation '${$.name}' declares no input '${E.property}'.`,E.location),L.type===null)continue;let x=E.property.split(".");for(let Y=1;Y<x.length;Y++)A.has(x.slice(0,Y).join("."))&&e.error(d.InvalidOperationMapping,`Operation input mapping '${E.property}' overlaps a whole input mapping.`,E.location);if(m!==null&&E.source.kind==="PathExpressionSyntax"){let Y=k(m.properties,E.source.path),F=E.source.path.split("."),N=(Ve.get(m)??[]).filter(M=>(M.alias??M.readModel)===F[0]);if(Y.missing&&N.length>0){Y={type:null,missing:!1};let M=N.length===1?p(N[0].readModel,y):null;F.length>1&&M!==null&&(Y=k(M.properties,F.slice(1).join(".")))}Y.missing&&e.error(d.InvalidOperationMapping,`Command '${m.name}' declares no source '${E.source.path}'.`,E.source.location);let b=Y.type,O=L.type;b!==null&&r.has(b.name)&&r.has(O.name)&&(b.name!==O.name||b.isCollection!==O.isCollection||b.isOptional&&!O.isOptional)&&e.error(d.InvalidOperationMapping,`Source '${E.source.path}' is incompatible with input '${E.property}' of operation '${$.name}'.`,E.source.location)}else["LiteralExpressionSyntax","ObjectExpressionSyntax","ListExpressionSyntax"].includes(E.source.kind)&&(!fe(E.source,L.type,i,o)||g&&!P(E.source,L.type))&&e.error(d.InvalidOperationMapping,`Value is incompatible with input '${E.property}' of operation '${$.name}'.`,E.source.location)}if(g)for(let E of $.inputs)w(E.type,E.name,h,R)||e.error(d.InvalidOperationMapping,`Production of operation '${$.name}' supplies no value for required input '${E.name}'.`,$.location)},"validateMappings");for(let{slice:S,scope:$}of t.slices){let m=on(S),g=new Set(Se(S).map(y=>y.name));for(let y of m){g.has(y.name)&&e.error(d.ProductionDeclarationCollision,`Operation '${y.name}' collides with another event or operation in slice '${S.name}'.`,y.location),g.add(y.name),y.uses.length>0&&v.get(y.uses)!==1&&e.error(d.InvalidSystemReference,`Operation '${y.name}' must use one declared system; '${y.uses}' does not resolve uniquely.`,y.usesLocation??y.location);for(let h of y.inputs)!r.has(h.type.name)&&!s.has(h.type.name)&&e.warning(d.UnknownType,`Unknown type '${h.type.name}' on input '${h.name}' of operation '${y.name}'.`,h.type.location)}for(let y of S.commands)for(let h of y.produces){let A=t.resolve(h.event,S);A.kind===j.Ambiguous&&A.candidates.some(R=>R.kind===j.Operation)&&e.error(d.InvalidProductionReference,`Production '${h.event}' is ambiguous.`,h.location),h.event.includes(".")&&A.kind!==j.Operation&&e.error(d.InvalidProductionReference,"Qualified productions are supported only for explicitly declared operations.",h.location),A.declaration?.node.kind==="OperationSyntax"&&((h.for!==null||h.tags.length>0)&&e.error(d.InvalidOperationDeclaration,"Operation productions cannot declare event destinations or tags.",h.location),D(h.mappings,A.declaration.node,y,!0,$))}for(let y of S.reactions.flatMap(h=>h.triggers).flatMap(h=>h.produces)){let h=t.resolve(y.event,S);h.kind===j.Ambiguous&&h.candidates.some(A=>A.kind===j.Operation)&&e.error(d.InvalidProductionReference,`Production '${y.event}' is ambiguous.`,y.location),y.event.includes(".")&&t.resolve(y.event,S).kind!==j.Operation&&e.error(d.InvalidProductionReference,"Qualified productions are supported only for explicitly declared operations.",y.location),t.isOperation(y,S)&&e.error(d.OperationOutsideCommand,"Operations can only be produced by commands.",y.location)}for(let y of S.specifications){let h=[...y.givenOperationFailures??[],...y.thenOperations??[],...y.thenCompensated??[]];if(h.length===0)continue;let A=I(y.when?.commandType??"",$);(A===null||y.whenAppended!==null||y.whenQuery!==null||y.whenTrigger!==null||y.whenClock!==null||y.whenCapture!==null)&&e.error(d.InvalidOperationSpecification,"Operation fixtures and assertions require a declared command action.",y.location);let R=new Map;for(let E of h){if(E.kind==="SpecificationOperationSyntax")for(let Y of E.values)C(Y.source)||e.error(d.InvalidOperationSpecification,"Operation assertions require concrete input values.",Y.source.location);let L=t.resolve(E.operation,S).declaration?.node;if(L?.kind!=="OperationSyntax"){e.error(d.InvalidOperationSpecification,`'${E.operation}' does not resolve uniquely to a declared operation.`,E.location);continue}let x=R.get(L)??new Set;if(x.has(E.kind)&&e.error(d.InvalidOperationSpecification,`Duplicate operation step '${E.operation}'.`,E.location),x.add(E.kind),R.set(L,x),E.kind==="SpecificationCompensatedSyntax"&&L.compensate===null&&e.error(d.InvalidOperationSpecification,`Operation '${E.operation}' declares no compensation.`,E.location),A!==null&&A.command.handler==null){let Y=A.command.produces.map(F=>t.resolve(F.event,A.slice));Y.every(F=>F.kind===j.Event||F.kind===j.Operation)&&!Y.some(F=>F.declaration?.node===L)&&e.error(d.InvalidOperationSpecification,`Command '${A.command.name}' does not produce operation '${E.operation}'.`,E.location)}E.kind==="SpecificationOperationSyntax"&&D(E.values,L,null,!1,$)}}}}a(sn,"validateOperations");var Xs=f("^domain\\s+([A-Za-z_]\\w*(?:\\.[A-Za-z_]\\w*)*)$"),ai=f("^import\\s+([\\w.]+)$"),ea=f("^concept\\s+(\\w+)\\s*:\\s*(\\w+)((?:\\s+@\\w+)*)$"),na=f("^@?[a-z_]\\w*$"),ta=f(`^([a-z_]\\w*)\\s+reason\\s+"(${_})"$`),ia=f("^persona\\s+([A-Za-z_]\\w*)$"),oa=f("^policy\\s+([A-Za-z_]\\w*)$"),ra=/^[ ]*\t/,si=["Uuid","String","Int","Decimal","Bool","Date","DateTime"],ci=new Set(["policy","authentication","seed","ui","theme","trigger","layout","behavior"]),sa=new Set(["slice","feature","description","authorize","screen","dialog","form","contribute","on","uses"]);function li(n,e,t=he){ua(n,e);let i=t.length===1?new Oe(t[0]):void 0,o=t.length>1?new De(t[t.length-1]):void 0,r=i??o,s=null,c=[],u=[],p=[],I=[],v=[],k=[],w=[],P=!1;for(let C=n.reader.peekSignificant();C!==void 0;C=n.reader.peekSignificant()){n.reader.takeSignificant();let D=T(C.content);if(D==="domain"){s=pa(n,C,s,P);continue}if(P||=aa(D,C,t),D==="import"&<(C.content))r!==void 0?r.tryParse(n,C):ge(n,C,u);else if(D==="import"){let S=ai.exec(C.content);S===null?n.error(d.InvalidImportDeclaration,`Invalid import '${C.content}' - expected 'import <Qualified.Name>'`,l(C)):c.push({kind:"ImportSyntax",qualifiedName:S[1],location:l(C)})}else D==="system"?v.push(Dt(n,C)):D==="concept"?p.push(fa(n,C)):D==="type"?I.push($t(n,C)):D==="module"&&!Ie(t)?ca(n,C,t,i):D==="module"?k.push(Fn(n,C)):D==="persona"?w.push(ha(n,C)):D==="trigger"?Ft(n,C):ci.has(D)?D==="behavior"||D==="layout"?X(n,C):n.skipOpaqueBlock(C.indent):r?.tryParse(n,C)!==!0&&la(n,C,t)}return i!==void 0?k.unshift(i.build(n.start,!0)):o!==void 0&&k.unshift(da(t,o.build(n.start,!0),n.start)),{kind:"ApplicationSyntax",domain:s,imports:c,concepts:p,types:I,systems:v,modules:k,personas:w,fileImports:u,location:n.start}}a(li,"parseApplication");function aa(n,e,t){return n==="import"?ai.test(e.content):n==="module"?Ie(t):n==="system"||n==="concept"||n==="type"||n==="persona"||ci.has(n)}a(aa,"declaresConstruct");function ca(n,e,t,i){let o=Bn.exec(e.content)?.[1]??"";if(i!==void 0&&o===t[0]){i.parseChildren(n,e);return}n.error(d.ModuleInPlacedFile,`This file is imported into ${qe(t)}, so it cannot declare module '${o}' - import it at the top level of a document instead`,l(e)),n.skipBlock(e.indent)}a(ca,"parseModuleInPlacedFile");function la(n,e,t){let i=T(e.content);if(Ie(t)){let o=sa.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";n.error(d.UnknownTopLevelConstruct,`Unexpected '${i}' at the top level${o}`,l(e))}else{let o=t.length===1?Yn:Nn;n.error(d.UnexpectedInPlacedFile,`Unexpected '${i}' in a file imported into ${qe(t)} - expected an application declaration or ${o}`,l(e))}n.skipBlock(e.indent)}a(la,"reportUnexpectedTopLevel");function da(n,e,t){let i=e;for(let o=n.length-2;o>=1;o--)i={kind:"FeatureSyntax",name:n[o],description:null,authorize:null,features:[i],slices:[],fileImports:[],isPlacement:!0,location:t};return{kind:"ModuleSyntax",name:n[0],description:null,authorize:null,features:[i],fileImports:[],isPlacement:!0,location:t}}a(da,"place");function pa(n,e,t,i){let o=Xs.exec(e.content);return o===null?(n.error(d.InvalidDomainDeclaration,`Invalid domain declaration '${e.content}' - expected 'domain <Qualified.Name>'`,l(e)),t):t!==null?(n.error(d.DuplicateDomain,"The document already declares a domain - a document can have at most one",l(e)),t):(i&&n.error(d.DomainNotFirst,"'domain' must be declared before any other construct",l(e)),{kind:"DomainSyntax",name:o[1],location:l(e)})}a(pa,"parseDomain");function ua(n,e){let t=!1;for(let i of e){if(i.raw.trimStart().startsWith("```")){t=!t;continue}!t&&ra.test(i.raw)&&n.warning(d.TabIndentation,"Screenplay is indentation based - use spaces, not tabs",st(i))}}a(ua,"warnOnTabIndentation");function fa(n,e){let t=ea.exec(e.content);if(t===null)return n.error(d.InvalidConceptDeclaration,`Invalid concept declaration '${e.content}' - expected 'concept <Name> : <Type>'`,l(e)),n.skipBlock(e.indent),{kind:"ConceptSyntax",name:T(e.content),type:"",attributes:[],values:[],location:l(e)};let[,i,o,r]=t,s=r.split(" ").filter(p=>p.length>0).map(p=>({kind:"ConceptAttributeSyntax",name:p.replace(/^@+/,""),reason:null,location:l(e)}));o!=="Enum"&&!si.includes(o)&&n.error(d.UnknownPrimitiveType,`Unknown primitive type '${o}' - expected ${si.join(", ")} or Enum`,l(e));let c=new Map;s.forEach((p,I)=>{c.has(p.name)||c.set(p.name,I)});let u=[];for(let p=n.peekChild(e.indent);p!==void 0;p=n.peekChild(e.indent)){n.reader.takeSignificant();let I=ta.exec(p.content);Z(p)||(T(p.content)==="validate"?(o==="Enum"&&p.content==="validate"&&n.peekChild(p.indent)===void 0&&n.warning(d.ValidateReadAsEnumerationBlock,`'validate' in enumeration concept '${i}' declares an empty validate block, not a value named 'validate' - write '@validate' for the value`,l(p)),n.skipOpaqueBlock(p.indent)):I!==null?ma(n,p,i,s,c,I[1],V(I[2])):o==="Enum"&&na.test(p.content)?u.push(W(p.content)):o==="Enum"?n.error(d.InvalidEnumerationValue,`Invalid enum value '${p.content}' - expected an identifier`,l(p)):(n.error(d.UnknownConceptDirective,`Unexpected '${p.content}' in concept body - expected validate, 'file <path>' or '<attribute> reason "<text>"'`,l(p)),n.skipBlock(p.indent)))}return{kind:"ConceptSyntax",name:i,type:o,attributes:s,values:u,location:l(e)}}a(fa,"parseConcept");function ma(n,e,t,i,o,r,s){let c=o.get(r);c===void 0?n.error(d.AttributeReasonWithoutAttribute,`Concept '${t}' declares a reason for '${r}' without the attribute - write 'concept ${t} : <Type> @${r}'`,l(e)):i[c].reason!==null?n.error(d.DuplicateAttributeReason,`Concept '${t}' already declares a reason for '${r}' - at most one is allowed`,l(e)):i[c]={...i[c],reason:s}}a(ma,"applyAttributeReason");function ha(n,e){let t=ia.exec(e.content)?.[1]??"";t===""&&n.error(d.InvalidPersonaDeclaration,`Invalid persona declaration '${e.content}' - expected 'persona <Name>'`,l(e));let i=null,o=[];for(let r=n.peekChild(e.indent);r!==void 0;r=n.peekChild(e.indent)){n.reader.takeSignificant();let s=T(r.content);if(s==="description")i=U(n,r,i,`Persona '${t}'`);else if(s==="policy"){let c=oa.exec(r.content);c===null?n.error(d.InvalidPersonaPolicyReference,`Invalid policy reference '${r.content}' - expected 'policy <Name>'`,l(r)):o.push(c[1])}else n.error(d.UnknownPersonaDirective,`Unexpected '${s}' in persona body - expected description or policy`,l(r)),n.skipBlock(r.indent)}return{kind:"PersonaSyntax",name:t,description:i,policies:o,location:l(e)}}a(ha,"parsePersona");function di(n,e,t=he){let{value:i,diagnostics:o,success:r}=me(n,e,t);return{value:i,diagnostics:o,success:r}}a(di,"parse");function me(n,e,t=he,i=!0){let o=Fe(n,!1,e),r=new ae(new ke(o),e);r.scope=t;let s=li(r,o,t);return i&&(rn(s,r),sn(s,r),tn(s,r)),{value:s,diagnostics:r.diagnostics,triggerData:r.triggerData,inputUses:r.inputUses,success:!r.diagnostics.some(c=>c.severity==="error")}}a(me,"parseForAuthoring");var an=class{static{a(this,"ScreenplaySyntaxWalker")}visitNode(e){}visitApplication(e){this.visitNode(e),e.domain!==null&&this.visitDomain(e.domain),e.imports.forEach(t=>this.visitImport(t)),e.fileImports.forEach(t=>this.visitFileImport(t)),e.systems?.forEach(t=>this.visitSystem(t)),e.concepts.forEach(t=>this.visitConcept(t)),e.types.forEach(t=>this.visitType(t)),e.personas.forEach(t=>this.visitPersona(t)),e.modules.forEach(t=>this.visitModule(t))}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(t=>this.visitNode(t))}visitType(e){this.visitNode(e),e.properties.forEach(t=>this.visitProperty(t))}visitModule(e){this.visitNode(e),e.fileImports.forEach(t=>this.visitFileImport(t)),e.authorize!==null&&this.visitAuthorize(e.authorize),e.features.forEach(t=>this.visitFeature(t))}visitFeature(e){this.visitNode(e),e.fileImports.forEach(t=>this.visitFileImport(t)),e.authorize!==null&&this.visitAuthorize(e.authorize),e.features.forEach(t=>this.visitFeature(t)),e.slices.forEach(t=>this.visitSlice(t))}visitSlice(e){this.visitNode(e),e.commands.forEach(t=>this.visitCommand(t)),e.operations?.forEach(t=>this.visitOperation(t)),e.events.forEach(t=>this.visitEvent(t)),e.constraints.forEach(t=>this.visitConstraint(t)),e.queries.forEach(t=>this.visitQuery(t)),e.projections.forEach(t=>this.visitProjection(t)),e.readModels.forEach(t=>this.visitReadModel(t)),e.captures.forEach(t=>this.visitCapture(t)),e.reactions.forEach(t=>this.visitReaction(t)),e.screens.forEach(t=>this.visitScreen(t)),e.specifications.forEach(t=>this.visitSpecification(t))}visitCommand(e){this.visitNode(e),e.properties.forEach(t=>this.visitProperty(t)),e.authorize!==null&&this.visitAuthorize(e.authorize),e.validations.forEach(t=>this.visitValidate(t)),e.produces.forEach(t=>this.visitProduces(t)),e.handler!=null&&this.visitHandler(e.handler),e.response!=null&&this.visitCommandResponse(e.response)}visitSystem(e){this.visitNode(e)}visitOperation(e){this.visitNode(e),e.inputs.forEach(t=>this.visitProperty(t)),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(t=>this.visitPropertyMapping(t))}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(t=>this.visitImplementationHint(t))}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(t=>this.visitResponseField(t))}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(t=>this.visitPropertyMapping(t))}visitValidate(e){this.visitNode(e),e.kind==="DeclarativeValidateSyntax"&&e.rules.forEach(t=>this.visitValidationRule(t))}visitValidationRule(e){this.visitNode(e),e.value!==null&&this.visitExpression(e.value)}visitEvent(e){this.visitNode(e),e.properties.forEach(t=>this.visitProperty(t)),e.tags.forEach(t=>this.visitTag(t))}visitTag(e){this.visitNode(e),this.visitExpression(e.value)}visitReadModel(e){this.visitNode(e),e.properties.forEach(t=>this.visitProperty(t))}visitConstraint(e){this.visitNode(e),e.kind==="FileConstraintSyntax"&&this.visitNode(e.file),e.additionalRules.forEach(t=>this.visitConstraint(t))}visitQuery(e){this.visitNode(e),this.visitTypeRef(e.returnType),e.by!==null&&this.visitQueryParameter(e.by),e.filters.forEach(t=>this.visitQueryParameter(t)),e.authorize!==null&&this.visitAuthorize(e.authorize)}visitQueryParameter(e){this.visitNode(e),this.visitTypeRef(e.type)}visitProjection(e){this.visitNode(e),e.blocks.forEach(t=>this.visitProjectionBlock(t))}visitProjectionBlock(e){switch(this.visitNode(e),e.kind){case"FromSyntax":e.events.forEach(t=>this.visitNode(t)),e.mappings.forEach(t=>this.visitMapping(t));break;case"EverySyntax":case"AllSyntax":e.mappings.forEach(t=>this.visitMapping(t));break;case"JoinSyntax":e.events.forEach(t=>this.visitJoinEvent(t));break;case"ProjectionVariantSyntax":e.entersOn.forEach(t=>this.visitNode(t)),e.blocks.forEach(t=>this.visitProjectionBlock(t));break;case"ChildrenSyntax":case"NestedSyntax":e.blocks.forEach(t=>this.visitProjectionBlock(t));break}}visitJoinEvent(e){this.visitNode(e),e.mappings.forEach(t=>this.visitMapping(t))}visitMapping(e){this.visitNode(e)}visitReaction(e){this.visitNode(e),e.triggers.forEach(t=>this.visitReactionTrigger(t))}visitReactionTrigger(e){this.visitNode(e),this.visitTriggerSource(e.source),e.produces.forEach(t=>this.visitProduces(t)),e.invokes.forEach(t=>this.visitInvokes(t))}visitProduces(e){this.visitNode(e),e.inlineEvent!==null&&this.visitEvent(e.inlineEvent),e.inlineOperation!=null&&this.visitOperation(e.inlineOperation),e.for!==null&&this.visitExpression(e.for),e.mappings.forEach(t=>this.visitPropertyMapping(t)),e.tags.forEach(t=>this.visitTag(t))}visitInvokes(e){this.visitNode(e)}visitCapture(e){this.visitNode(e),e.source!==null&&this.visitCaptureSource(e.source),e.appends.forEach(t=>this.visitCaptureAppend(t)),e.children.forEach(t=>this.visitCaptureChildren(t)),e.nested.forEach(t=>this.visitCaptureNested(t))}visitCaptureSource(e){this.visitNode(e),e.settings.forEach(t=>this.visitCaptureSourceSetting(t))}visitCaptureSourceSetting(e){this.visitNode(e)}visitCaptureAppend(e){this.visitNode(e)}visitCaptureChildren(e){this.visitNode(e),e.appends.forEach(t=>this.visitCaptureAppend(t))}visitCaptureNested(e){this.visitNode(e),e.appends.forEach(t=>this.visitCaptureAppend(t))}visitTriggerSource(e){this.visitNode(e)}visitScreen(e){this.visitNode(e),e.directives.forEach(t=>this.visitScreenDirective(t))}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(t=>{this.visitNode(t),t.directives.forEach(i=>this.visitScreenDirective(i))});break;case"ScreenSectionSyntax":e.directives.forEach(t=>this.visitScreenDirective(t));break;case"ScreenTableSyntax":e.columns.forEach(t=>this.visitNode(t)),e.rowClick!==null&&this.visitScreenDirective(e.rowClick);break;case"ScreenSummarySyntax":e.fields.forEach(t=>this.visitNode(t));break;case"ScreenCodeSyntax":this.visitNode(e.code);break}}visitSpecification(e){this.visitNode(e),e.givenClock!==null&&this.visitSpecificationClock(e.givenClock),e.givenOperationFailures?.forEach(t=>this.visitSpecificationOperationFailure(t)),e.thenOperations?.forEach(t=>this.visitSpecificationOperation(t)),e.thenCompensated?.forEach(t=>this.visitSpecificationCompensated(t)),e.given.forEach(t=>this.visitSpecificationEvent(t)),e.givenReadModels.forEach(t=>this.visitSpecificationReadModel(t)),e.when!==null&&this.visitSpecificationCommand(e.when),e.givenCaptures.forEach(t=>this.visitSpecificationCapture(t)),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(t=>this.visitSpecificationEvent(t)),e.thenReadModels.forEach(t=>this.visitSpecificationReadModel(t)),e.thenResults.forEach(t=>this.visitSpecificationQueryResult(t)),e.thenNoResult!==null&&this.visitNode(e.thenNoResult),e.thenDenied!=null&&this.visitNode(e.thenDenied),e.thenReturns!=null&&this.visitSpecificationReturn(e.thenReturns),e.thenErrors.forEach(t=>this.visitNode(t))}visitSpecificationClock(e){this.visitNode(e)}visitSpecificationTrigger(e){this.visitNode(e),e.values.forEach(t=>this.visitPropertyMapping(t))}visitSpecificationCapture(e){this.visitNode(e),e.record.forEach(t=>this.visitPropertyMapping(t))}visitSpecificationWhenQuery(e){this.visitNode(e),e.arguments.forEach(t=>this.visitPropertyMapping(t))}visitSpecificationQueryResult(e){this.visitNode(e),e.properties.forEach(t=>this.visitPropertyMapping(t))}visitSpecificationEvent(e){this.visitNode(e),e.values.forEach(t=>this.visitPropertyMapping(t)),e.for!==null&&this.visitExpression(e.for)}visitSpecificationCommand(e){this.visitNode(e),(e.generatedValues??[]).forEach(t=>this.visitPropertyMapping(t)),e.values.forEach(t=>this.visitPropertyMapping(t)),e.for!==null&&this.visitExpression(e.for)}visitSpecificationReadModel(e){this.visitNode(e),e.properties.forEach(t=>this.visitPropertyMapping(t))}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(t=>this.visitExpression(t)):e.kind==="ObjectExpressionSyntax"&&e.members.forEach(t=>this.visitObjectMember(t))}visitObjectMember(e){this.visitNode(e),this.visitExpression(e.value)}};function bm(n){return n===d.LegacyOptionalSuffix||n===d.RedundantEventId}a(bm,"isQuickFixDiagnostic");function zn(n,e){return e.code!==d.LegacyOptionalSuffix?0:/^[\p{L}\p{Mn}\p{Nd}\p{Pc}.]+(?:\[\])?\?/u.exec(n.slice(e.location.column-1))?.[0].length??0}a(zn,"legacyOptionalTypeLength");function Pm(n,e={}){let t=me(n,void 0,e.placement);if(!t.success)return()=>[];let i=Fe(n),o=new Map;new class extends an{visitEvent(S){o.set(S.location.line,S)}}().visitApplication(t.value);let s=new Map,c=new Map,u=new Map,p;for(let S of i)p=o.get(S.number)??p,p!==void 0&&u.set(S.number,p);for(let S of t.diagnostics){s.set(S.code,(s.get(S.code)??0)+1);let $=i[S.location.line-1],m=zn($.raw,S);if(m>0)c.set($.number,{line:$.number,fix:{diagnosticCode:S.code,title:"Use 'optional' instead of '?'",scope:"occurrence",edits:[{start:$.startOffset+S.location.column+m-2,length:1,text:" optional"}]}});else if(S.code===d.RedundantEventId&&yn($.raw)<0){let g=u.get($.number);if(g?.id!==g?.name||g===void 0)continue;c.set($.number,{line:$.number,fix:{diagnosticCode:S.code,title:"Remove the redundant event id",scope:"occurrence",edits:[{start:$.startOffset,length:(i[$.number]?.startOffset??n.length)-$.startOffset,text:""}]},change:{node:g,replacement:{...g,id:null}}})}}let I=[...c.values()].filter(S=>S.fix.diagnosticCode===d.LegacyOptionalSuffix),v=Re(t),k=new Map,w,P=!1,C,D=a((S,$)=>{let m=pi(n,S.edits);if(m===void 0)return;let g=me(m,void 0,e.placement);if(!(!g.success||Re(g)!==($===void 0?v:Re(t,[$]))))return g.diagnostics.filter(y=>y.code===S.diagnosticCode).length===(s.get(S.diagnosticCode)??0)-S.edits.length?S:void 0},"verify");return(S,$)=>{let m=typeof S=="number"||S===void 0?void 0:S,g=m===void 0?$===void 0||$===d.LegacyOptionalSuffix:m.some(R=>R.diagnosticCode===d.LegacyOptionalSuffix);if(g&&!P&&(I.length>0&&(C=D({diagnosticCode:d.LegacyOptionalSuffix,title:"Use 'optional' throughout this document",scope:"document",edits:I.flatMap(R=>R.fix.edits)})),P=!0),m!==void 0){if(w===void 0){w=new Map;let E=i.flatMap(Y=>c.has(Y.number)?[c.get(Y.number)]:[]),L=E.flatMap(Y=>Y.fix.edits),x=pi(n,L);if(L.length>0&&x!==void 0){let Y=me(x,void 0,e.placement),F=E.flatMap(N=>N.change===void 0?[]:[N.change]);if(Y.success&&Re(Y)===Re(t,F)){let N=new Map,b=new Map;for(let O of Y.diagnostics)N.set(O.code,(N.get(O.code)??0)+1);for(let O of E)b.set(O.fix.diagnosticCode,(b.get(O.fix.diagnosticCode)??0)+O.fix.edits.length);if([...b].every(([O,M])=>(N.get(O)??0)===(s.get(O)??0)-M))for(let O of E)w.set(O.line,O.fix)}}}let R=new Map;for(let E of m){let L=w.get(E.line);L?.diagnosticCode===E.diagnosticCode&&R.set(E.line,L)}return[...R.values(),...g&&C!==void 0?[C]:[]]}let y=typeof S=="number"?S:void 0,h=y===void 0?void 0:c.get(y),A;return h!==void 0&&y!==void 0&&($===void 0||h.fix.diagnosticCode===$)&&(k.has(y)||(k.size===32&&k.delete(k.keys().next().value),k.set(y,D(h.fix,h.change))),A=k.get(y)),[A,g?C:void 0].filter(R=>R!==void 0)}}a(Pm,"prepareQuickFixes");function Re(n,e=[]){let t=new Map(e.map(i=>[i.node,i.replacement]));return JSON.stringify([n.value,n.triggerData],(i,o)=>["location","usesLocation","targetLocation"].includes(i)?void 0:t.get(o)??o)}a(Re,"verificationShape");function pi(n,e){let t=[],i=0;for(let o of e){if(o.start<i||o.start<0||o.length<0||o.start+o.length>n.length)return;t.push(n.slice(i,o.start),o.text),i=o.start+o.length}return t.push(n.slice(i)),t.join("")}a(pi,"applyQuickFixEdits");var va=a(n=>typeof n=="object"&&n!==null&&typeof n.kind=="string","isNode");function Un(n){return Wn(n)}a(Un,"toSyntaxJson");function Wn(n){if(Array.isArray(n))return n.map(Wn);if(va(n)){ga(n);let e={kind:n.kind},t=Object.keys(n).filter(i=>i!=="kind"&&i!=="location"&&i!=="targetLocation"&&!(n.kind==="OperationSyntax"&&i==="usesLocation")).sort(ya);for(let i of t)e[i]=Wn(n[i]);return e}return n===void 0?null:n}a(Wn,"write");function ga(n){if(n.kind==="ProducesSyntax"){let e=n,t=e.inlineOperation;if(t!=null){if(e.inlineEvent!==null)throw new Error("A production cannot declare both an event and an operation.");if(e.event!==t.name||e.for!==null||e.tags.length>0)throw new Error("An inline operation requires a matching target without event metadata.");if(t.inputs.length!==e.mappings.length||t.inputs.some((i,o)=>i.name!==e.mappings[o].property))throw new Error("Inline operation inputs and mappings must correspond in order.")}}if(n.kind==="OperationPhaseSyntax"){let e=n;if(e.file!==null&&e.code!==null)throw new Error("An operation phase has at most one file or inline payload.");if(e.implementation!==null&&(!Array.isArray(e.implementation.hints)||e.implementation.hints.some(t=>t==null||We(t.text))))throw new Error("Implementation hints must be a collection of nonblank hints.")}}a(ga,"validateOperation");function ya(n,e){return n<e?-1:n>e?1:0}a(ya,"ordinal");function ui(n){let e=[],t=n.map(v=>v.value),i=new Map,o=cn(t.flatMap(v=>v.concepts),"declaration of",e,void 0,i),r=cn(t.flatMap(v=>v.types),"declaration of",e,void 0,i),s=t.map(v=>v.domain).filter(v=>v!==null);for(let v of s.slice(1))e.push(yi(d.RepeatedSingularDeclarationAcrossFiles,`The folder already declares a domain in '${ln(s[0].location.path)}' - a folder compiles to one application, which can have at most one`,v.location));let c=ka(t.flatMap(v=>v.modules),e),u=cn(t.flatMap(v=>v.personas),"persona",e),p={kind:"ApplicationSyntax",domain:s[0]??null,imports:Sa(t.flatMap(v=>v.imports),v=>v.qualifiedName),concepts:o,types:r,systems:t.flatMap(v=>v.systems??[]),modules:c,personas:u,fileImports:t.flatMap(v=>v.fileImports),location:t[0]?.location??{line:1,column:1}},I=[...n.flatMap(v=>v.diagnostics),...e];return{value:p,diagnostics:I,success:!I.some(v=>v.severity==="error")}}a(ui,"mergeDocuments");function ka(n,e){return vi(n).map(mi).map(t=>t.length===1?{...t[0],isPlacement:!1,features:t[0].features.map(jn)}:{...t[0],isPlacement:!1,fileImports:t.flatMap(i=>i.fileImports),description:gi(t,`module '${t[0].name}'`,e),authorize:hi(t.map(i=>i.authorize),`module '${t[0].name}'`,e),features:fi(t.flatMap(i=>i.features),e)})}a(ka,"mergeModules");function fi(n,e){return vi(n).map(mi).map(t=>t.length===1?jn(t[0]):{...t[0],isPlacement:!1,fileImports:t.flatMap(i=>i.fileImports),description:gi(t,`feature '${t[0].name}'`,e),authorize:hi(t.map(i=>i.authorize),`feature '${t[0].name}'`,e),features:fi(t.flatMap(i=>i.features),e),slices:cn(t.flatMap(i=>i.slices),"slice",e,`feature '${t[0].name}'`)})}a(fi,"mergeFeatures");function mi(n){return[...n.filter(e=>!e.isPlacement),...n.filter(e=>e.isPlacement)]}a(mi,"placedLast");function jn(n){return{...n,isPlacement:!1,features:n.features.map(jn)}}a(jn,"unplaced");function hi(n,e,t){let i=[];for(let o of n.filter(r=>r!==null)){let r=i.find(s=>s.location.path!==o.location.path&&JSON.stringify(Un(s))===JSON.stringify(Un(o)));if(r!==void 0){t.push(ki(d.DuplicateAuthorizationAcrossFiles,`An identical authorization is already declared on the ${e} in '${ln(r.location.path)}' - this repeated gate is ignored`,o.location));continue}i.push(o)}return i.reduce((o,r)=>ne(o,r),null)}a(hi,"combineAuthorization");function Sa(n,e){let t=new Set;return n.filter(i=>!t.has(e(i))&&t.add(e(i))!==void 0)}a(Sa,"firstOfEach");function vi(n){let e=new Map;for(let t of n)e.set(t.name,[...e.get(t.name)??[],t]);return[...e.values()]}a(vi,"groupByName");function gi(n,e,t){let i=n.filter(o=>o.description!==null);for(let o of i.slice(1).filter(r=>r.description!==i[0].description))t.push(ki(d.ConflictingDescriptionAcrossFiles,`The ${e} is already described in '${ln(i[0].location.path)}' - keeping that description`,o.location));return i[0]?.description??null}a(gi,"firstDescription");function cn(n,e,t,i,o=new Map){let r=[];for(let s of n){let c=o.get(s.name);if(c!==void 0&&c.path!==s.location.path){t.push(yi(d.RepeatedDeclarationAcrossFiles,`Duplicate ${e} '${s.name}'${i===void 0?"":` in ${i}`} - already declared in '${ln(c.path)}'`,s.location));continue}c===void 0&&o.set(s.name,s.location),r.push(s)}return r}a(cn,"declaredInOneFile");var ln=a(n=>n??"another file","describe"),yi=a((n,e,t)=>({severity:"error",code:n,message:e,location:t}),"error"),ki=a((n,e,t)=>({severity:"warning",code:n,message:e,location:t}),"warning");function wi(n){let e=n.map(c=>me(c.source,c.path,c.placement,!1)),t=ui(e),i=new ae(new ke([]));sn(t.value,i),rn(t.value,i),tn(t.value,i,e.flatMap(c=>c.inputUses));let o=t.diagnostics,r=new Set(o.map(Si)),s=[...o,...i.diagnostics.filter(c=>!r.has(Si(c)))];return{...t,diagnostics:s,success:!s.some(c=>c.severity==="error")}}a(wi,"parsePlacedDocuments");function Si(n){return JSON.stringify([n.code,n.location.path,n.location.line,n.location.column])}a(Si,"diagnosticKey");var Me="Syntax-only; execution unavailable until ESM v8 (PLAY0268). No response type is emitted.",Te=new Map;function ba(n,e){let t=H(n),i=n.flatMap((v,k)=>!t[k]&&z(v)===0&&/^\w/.test(v)?[v.split(/\s+/)[0]]:[]);if(i.includes("module")||!i.some(v=>["feature","slice","command","event","operation","reaction","specification"].includes(v)))return{source:n.join(`
|
|
7
|
+
`),locations:n.map((v,k)=>({line:k+1,column:0}))};let o=[],r=[],s=!1;n.forEach((v,k)=>{!t[k]&&z(v)===0&&/^\w/.test(v)&&(s=/^(?:concept|type|import|domain|system)\b/.test(v)),(s?o:r).push(k)});let c=i.includes("feature")?1:i.includes("slice")?2:3,u=e.slice(0,c),p=[...o.map(v=>n[v]),...u,...r.map(v=>" ".repeat(c*2)+n[v])].join(`
|
|
8
|
+
`),I=[...o.map(v=>({line:v+1,column:0})),...u.map(()=>({line:0,column:0})),...r.map(v=>({line:v+1,column:c*2}))];return{source:p,locations:I}}a(ba,"authoringSource");function Pa(n,e,t,i="current.play"){let o=e.map((b,O)=>typeof b=="string"?{path:`other-${O}.play`,source:b}:b).filter(b=>b.path!==i),r=[{path:i,source:n.join(`
|
|
9
|
+
`),placement:t},...o],s=new Set(r.flatMap(b=>[...b.source.matchAll(/\w+/g)].map(O=>O[0]).concat(b.placement??[]))),c=a(b=>{let O=b;for(let M=1;s.has(O);M++)O=`${b}${M}`;return s.add(O),O},"fresh"),u=c("EditorAuthoring"),p=c("FragmentFeature"),I=new Set([u,p]),v=r.map((b,O)=>{let M=O===0?n:b.source.split(`
|
|
10
|
+
`),B=c(`Fragment${O}`);I.add(B);let K=b.placement?.length?{source:b.source,locations:M.map((un,Be)=>({line:Be+1,column:0}))}:ba(M,[`module ${u}`,` feature ${p}`,` slice StateChange ${B}`]);return{...b,...K,placement:b.placement??[]}}),k=v[0],w=new Map(v.map(b=>[b.path,b.locations])),P=o.length===0?di(k.source,i,t):wi([...v.slice(1),k]),C=new Map,D=new Map,S=new WeakSet,$=a(b=>{if(b===null||typeof b!="object"||S.has(b))return;if(S.add(b),Array.isArray(b)){b.forEach($);return}let O=b;if(typeof O.path=="string"&&typeof O.line=="number"&&typeof O.column=="number"){let M=w.get(O.path)?.[O.line-1];M&&(O.line=M.line,O.column=Math.max(1,O.column-M.column));return}for(let M of Object.values(O))$(M);O.location?.path===i&&(O.kind==="CommandSyntax"&&C.set(O.location.line-1,b),O.kind==="SpecificationSyntax"&&D.set(O.location.line-1,b))},"walk");$(P.value);let m=P.diagnostics.filter(b=>b.location.path===i).flatMap(b=>($(b.location),b.location.line>0?[b]:[])),g=new ce(P.value),y=new Set(g.slices.flatMap(({slice:b})=>[...b.commands.flatMap(O=>O.produces),...b.reactions.flatMap(O=>O.triggers).flatMap(O=>O.produces)].filter(O=>O.location.path===i&&!g.isEventProduction(O,b)).map(O=>O.location.line-1)));for(let b of m)b.code==="PLAY0499"&&y.add(b.location.line-1);let h=g.declarations.filter(b=>b.kind===j.Operation).map(b=>({...b.node,scope:b.scope.filter(O=>!I.has(O))})),A=new Map,R=H(n),E=a(b=>{let O=[],M=z(n[b]);for(let B=b;B<n.length&&!(B>b&&!R[B]&&pe(n[B]).trim()&&z(n[B])<=M);B++)O.push(B);return O},"range");for(let{slice:b,scope:O}of g.slices){if(b.location.path===i&&b.location.line>0)for(let M of E(b.location.line-1))A.set(M,{scope:O});for(let M of b.specifications.filter(B=>B.location.path===i&&B.location.line>0))for(let B of E(M.location.line-1))A.set(B,{scope:O});for(let M of b.commands.filter(B=>B.location.path===i&&B.location.line>0))for(let B of E(M.location.line-1))A.set(B,{scope:O,commandLine:M.location.line-1})}let L=new Map(g.declarations.map(b=>[b.node.location,b.scope]));for(let b of h.filter(O=>O.location.path===i)){let O=L.get(b.location);for(let M of E(b.location.line-1))A.set(M,{...A.get(M),scope:O,operation:b})}let x=new Map(h.map(b=>[b.location,b])),Y=a((b,O)=>{let M=pe(n[b.line-1]??""),B=M.slice(b.column-1).match(/^(?:given\s+operation|then\s+(?:operation|compensated))\s+/)?.[0];return B&&M.slice(b.column-1+B.length,b.column-1+B.length+O.length)===O?{...b,column:b.column+B.length}:b},"referenceLocation"),F=[];for(let{slice:b}of g.slices){for(let O of b.commands)for(let M of O.produces){if(M.location.path!==i)continue;let B=g.resolve(M.event,b),K=B.declaration?x.get(B.declaration.node.location)??null:null,un={name:M.event,location:M.location,targetLocation:M.targetLocation??M.location,kind:B.kind,declaration:K,mappings:M.mappings};if(F.push(un),B.kind===j.Operation)for(let Be of E(M.location.line-1)){let nt=A.get(Be);nt&&A.set(Be,{...nt,production:un})}}for(let O of b.specifications)for(let M of[...O.givenOperationFailures??[],...O.thenOperations??[],...O.thenCompensated??[]]){if(M.location.path!==i)continue;let B=g.resolve(M.operation,b);F.push({name:M.operation,location:M.location,targetLocation:Y(M.location,M.operation),kind:B.kind,declaration:B.declaration?x.get(B.declaration.node.location)??null:null,mappings:[]})}}let N={declarations:h,systems:P.value.systems??[],references:F,contexts:A,types:P.value.types,concepts:P.value.concepts,targets:a(b=>{let O=g.slices.find(M=>M.scope.length===b.length&&M.scope.every((B,K)=>B===b[K]))?.slice;return O?h.flatMap(M=>{let B=g.resolve(M.name,O).declaration?.node.location===M.location?M.name:[...M.scope,M.name].join(".");return g.resolve(B,O).kind===j.Operation&&g.resolve(B,O).declaration?.node.location===M.location?[{name:B,declaration:M}]:[]}):[]},"targets")};return{commands:C,specifications:D,diagnostics:m,operationProductionLines:y,operations:N}}a(Pa,"analyze");function we(n,e=[],t,i="current.play"){let o=JSON.stringify([n,e,t,i]),r=Te.get(o);return r===void 0&&(r=Pa(n,e,t,i),Te.size>=16&&Te.delete(Te.keys().next().value),Te.set(o,r)),r}a(we,"responseAnalysis");var Vn="file",Ia=/^[A-Za-z_]\w*(?:\[\])?(?:\?|\s+optional)?$/,Ca=/^(?:[/\\]|[A-Za-z]:[/\\]|~[/\\])/;function cv(n){return Ca.test(n)}a(cv,"isAbsoluteFileReferencePath");function $a(n){let e=!1,t=!1;for(let i=0;i<n.length;i++){let o=n[i];if(o==="\\"&&e&&i+1<n.length)i++;else if(o==='"'&&!t)e=!e;else if(o==="`"&&!e)t=!t;else if(!e&&!t&&o==="/"&&n[i+1]==="/")return n.slice(0,i)}return n}a($a,"withoutComment");function Zn(n,e){let t=z(n),i=$a(n.slice(t)).trimEnd();if(gn(i)!==Vn)return;let o=i.slice(Vn.length),r=o.trim();if(r.length===0||Ia.test(r))return;let s=o.length-o.trimStart().length,c=t+Vn.length+s+1;return{path:r,line:e,startColumn:c,endColumn:c+r.length}}a(Zn,"fileReferenceOn");function lv(n){let e=H(n),t=[];for(let i=0;i<n.length;i++){if(e[i])continue;let o=Zn(n[i],i);o&&t.push(o)}return t}a(lv,"fileReferences");function le(n){let e=!1;return n.map(t=>{if(e)return t.trim()==="```"&&(e=!1),t;let i=pe(t);return/^\s*```(?:[a-z]+)?\s*$/.test(i)&&(e=!0),i.trimEnd()})}a(le,"eventAnalysisSource");var Aa=/^concept\s+(\w+)\s*:\s*(\w+)((?:\s+@\w+)*)\s*$/,Ea=/^\s*(@?[a-z_]\w*)\s+([\w.]+(?:\[\])?(?:\?|\s+optional)?)(\s+generated)?(\s+identifier)?\s*$/,bi=/^([a-z_]\w*)\s+reason\s+"((?:[^"\\]|\\.)*)"\s*$/,Da=/^\s*reads\s+([A-Z]\w*)(?:\s+as\s+([a-z_]\w*))?(?:\s+by\s+([a-z_]\w*))?\s*$/,Oa=["authorize","produces","reads"],Ra=/^(?:(?:or|and)\s+)?[A-Za-z_(][\p{L}\p{Mn}\p{Nd}\p{Pc}\s()]*$/u,Ta=Ae,Ma=["tag","for","generation","origin","namespace","sequence","correlation","causation","causedBy","occurred"],La=/^\s*(?:by|filter)\s+([a-z_]\w*)\s+([\w.]+(?:\[\])?(?:\?|\s+optional)?)(?:\s+from\s+.+)?\s*$/;function de(n){return n.typeReference??Pe(n.type)}a(de,"propertyTypeReference");function _n(n,e){let t=n.slice(e-1).match(/^[\p{L}\p{Mn}\p{Nd}\p{Pc}.]+(?:\[\])?(?:\?|\s+optional\b)?/u)?.[0]??"";return{text:t,startColumn:e,endColumn:e+t.length}}a(_n,"sourceTypeAt");function Gn(n,e,t){return e.map(i=>({index:i,match:n[i].match(Ea)})).filter(i=>i.match!==null).filter(({match:i})=>i[1].startsWith("@")||i[1]==="as"||!t.includes(i[1])).map(({index:i,match:o})=>({name:o[1].replace(/^@/,""),type:o[2],typeReference:Pe(o[2]),sourceType:_n(n[i],n[i].match(/^\s*\S+\s+/)[0].length+1),isIdentifier:o[4]!==void 0,...o[3]!==void 0?{isGenerated:!0}:{},line:i}))}a(Gn,"propertiesIn");function xe(n,e,t,i){let o=[];for(let r=t+1;r<n.length;r++){if(e[r])continue;let s=n[r];if(s.trim().length!==0){if(z(s)<=i)break;o.push(r)}}return o}a(xe,"collectBody");function be(n,e,t,i){let o=xe(n,e,t,i).filter(c=>!e[c]&&!/^\s*(?:\/\/|#)/.test(n[c]));if(!/^\s*command\b/.test(n[t]))return o;let r,s=!1;return o.filter(c=>{let u=z(n[c]),p=n[c].trim();return r!==void 0&&u>r&&(!s||Ra.test(p))?!1:(r=p!=="validate csharp"&&Gn(n,[c],Oa).length>0||/^description(?:\s|$)/.test(p)?void 0:u,s=/^authorize(?:\s|$)/.test(p),!0)})}a(be,"directBody");var Le=new Map;function dn(n){let e=n.join(`
|
|
11
|
+
`),t=Le.get(e);if(t)return t;let i=we(n),o={authoringSources:[e],imports:[],concepts:[],types:[],policies:[],events:[],commands:[],queries:[],screens:[],triggers:[]};n=le(n);let r=H(n),s=n,c=r,u=n.map(p=>p.replace(/\s*=(?!=|>).*/,""));for(let p=0;p<n.length;p++){if(r[p])continue;let I=n[p],v=I.trim(),k=z(I),w=s[p].trim().match(/^import\s+([\w.]+)\s*$/);if(w&&k===0){let h=w[1],A=h.split(".").pop()??h;o.imports.push({qualifiedName:h,shortName:A,line:p});continue}let P=v.match(Aa);if(P){let h=xe(n,r,p,k).map(E=>n[E].trim()),A={};for(let E of h){let L=E.match(bi);L&&A[L[1]]===void 0&&(A[L[1]]=L[2])}let R=P[2]==="Enum"?h.filter(E=>!bi.test(E)):[];o.concepts.push({name:P[1],primitive:P[2],attributes:P[3].trim().split(/\s+/).filter(Boolean),attributeReasons:A,enumValues:R,line:p});continue}let C=v.match(/^type\s+(\w+)\s*$/);if(C){o.types.push({name:C[1],properties:Gn(n,xe(n,r,p,k),tt),line:p});continue}let D=v.match(/^policy\s+(\w+)\s*$/);if(D){let h=xe(n,r,p,k).filter(A=>!r[A]).map(A=>n[A].trim());o.policies.push({name:D[1],requires:h,line:p});continue}let S=s[p].trim().match(/^(?:produces\s+)?event\s+(\w+)(?:\s+generation\s+(\d+))?\s*$/);if(S){let h=v.startsWith("produces "),A=be(s,c,p,k),R=h?A:A.filter(E=>Zn(s[E],E)===void 0);o.events.push({name:S[1],...S[2]?{generation:Number(S[2])}:{},inline:h,properties:Gn(h?u:s,R,h?Ma:Ta),line:p});continue}let $=i.commands.get(p);if($){let h=be(n,r,p,k),A=h.filter(R=>/^\s*produces\b/.test(n[R])&&!i.operationProductionLines?.has(R));o.commands.push({name:$.name,properties:$.properties.map(R=>({name:R.name,type:`${R.type.name}${R.type.isCollection?"[]":""}${R.type.isOptional?" optional":""}`,typeReference:{name:R.type.name,isCollection:R.type.isCollection,isOptional:R.type.isOptional},sourceType:_n(n[R.type.location.line-1],R.type.location.column),isIdentifier:R.isIdentifier||/\sidentifier\s*$/.test(n[R.location.line-1]),...R.isGenerated?{isGenerated:!0}:{},line:R.location.line-1})),response:$.response,productionHeaders:A,produces:A.flatMap(R=>{let E=s[R].trim(),L=/^produces\s+event\b/.test(E),x=/^produces\s+when\b/.test(E),Y=x?be(s,c,R,z(s[R]))[0]:R;if(Y===void 0)return[];let F=x?s[Y].trim():E.match(L?/^produces\s+event\s+([A-Za-z_]\w*)(?:\s+generation\s+\d+)?\s*$/:/^produces\s+([A-Z]\w*)\s*$/)?.[1];if(F===void 0||!/^[A-Za-z_]\w*$/.test(F))return[];let N=be(s,c,Y,z(s[Y])),b=N.map(B=>s[B].trim().match(/^for(?:\s+(.*))?$/)).filter(B=>B!==null),O=b.length===0?void 0:b.length===1?b[0][1]??"":"",M=N.flatMap(B=>{let K=s[B].trim().match(L?/^(@?[a-z_]\w*)\s+[\w.]+(?:\[\])?(?:\?|\s+optional)?\s*=(?!=|>)\s*(.+)$/:/^(@?[\w.]+)\s*=(?!=|>)\s*(.+)$/);return K===null?[]:[{name:K[1].replace(/^@/,""),source:K[2],line:B}]});return[{name:F,inline:L,conditional:x,line:R,target:O,mappings:M}]}),reads:h.filter(R=>!r[R]).map(R=>({line:R,match:n[R].match(Da)})).filter(R=>R.match!==null).map(({line:R,match:E})=>({view:E[1],...E[2]?{alias:E[2]}:{},...E[3]?{by:E[3]}:{},line:R})),line:p});continue}let m=v.match(/^query\s+(\w+)\s*=>\s*(?:observable\s+)?([\w.]+(?:\[\])?(?:\?|\s+optional)?)\s*$/);if(m){let h=xe(n,r,p,k).map(A=>({index:A,match:n[A].match(La)})).filter(A=>A.match!==null).map(({index:A,match:R})=>({name:R[1],type:R[2],typeReference:Pe(R[2]),sourceType:_n(n[A],n[A].match(/^\s*(?:by|filter)\s+\S+\s+/)[0].length+1),isIdentifier:!1,line:A}));o.queries.push({name:m[1],returnType:m[2],returnTypeReference:Pe(m[2]),parameters:h,line:p});continue}let g=v.match(/^screen\s+(\w+)\s*$/);if(g){o.screens.push({name:g[1],line:p});continue}let y=v.match(/^trigger\s+(\w+)\s*$/);y&&k===0&&o.triggers.push({name:y[1],line:p})}return Le.size>=16&&Le.delete(Le.keys().next().value),Le.set(e,o),o}a(dn,"scanDocument");function Pi(...n){return{authoringSources:n.flatMap(e=>e.authoringSources??[]),...n.some(e=>e.authoringDocuments)?{authoringDocuments:n.flatMap(e=>e.authoringDocuments??(e.authoringSources??[]).map((t,i)=>({path:`other-${i}.play`,source:t})))}:{},imports:n.flatMap(e=>e.imports),concepts:n.flatMap(e=>e.concepts),types:n.flatMap(e=>e.types),policies:n.flatMap(e=>e.policies),events:n.flatMap(e=>e.events),commands:n.flatMap(e=>e.commands),queries:n.flatMap(e=>e.queries),screens:n.flatMap(e=>e.screens),triggers:n.flatMap(e=>e.triggers)}}a(Pi,"mergeSymbols");function pn(n){return[...n.events.map(e=>e.name),...n.imports.map(e=>e.shortName)]}a(pn,"knownEventNames");var xa=["Startup","Shutdown"];function Iv(n){return[...pn(n),...n.triggers.map(e=>e.name),...xa]}a(Iv,"knownTriggerNames");function Qn(n,e){return[...e,...n.concepts.map(t=>t.name),...n.types.map(t=>t.name),...n.imports.map(t=>t.shortName)]}a(Qn,"knownTypeNames");var Ii="EventContext",Ne={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."}]},Na=[{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 Hn(n,e){if(n.kind==="function")return e===n.name||e===`${n.name}()`;let t=n.name[0].toUpperCase()+n.name.slice(1);return e===t||e.length>0&&e[0].toUpperCase()+e.slice(1)===t}a(Hn,"namesEventContextMember");var Jn=Ne[Ii];function Ba(n){let e=Jn;for(let t of n){let i=e.find(o=>Hn(o,t));if(!i||i.kind==="collection"||i.kind==="function")return;e=Ne[i.type]??[]}return e}a(Ba,"eventContextMembersAfter");function Dv(n){return n.length===0?void 0:Ba(n.slice(0,-1))?.find(t=>Hn(t,n[n.length-1]))}a(Dv,"eventContextMemberAt");function Kn(n){let e,t=Jn;for(let i of n.split(".")){if(i.length===0)return{status:"missing",member:e,expected:t};if(e?.kind==="collection")return{status:"belowCollection",member:e,segment:i,expected:[]};let o=t.find(r=>Hn(r,i));if(!o)return{status:e?"unknownSubPath":"unknownMember",member:e,segment:i,expected:t};e=o,t=o.kind==="function"?[]:Ne[o.type]??[]}return{status:"known",member:e,expected:[]}}a(Kn,"resolveEventContextPath");function Ov(){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:**",...Jn.map(n=>`- \`${n.name}\` (${n.type}) - ${n.description}`)].join(`
|
|
12
|
+
`)}a(Ov,"describeEventContext");function Rv(n,e){let t=e.kind==="collection"||e.kind==="function"?[]:Ne[e.type]??[],i=[`**$eventContext.${n}**: \`${e.type}\``,"",e.description];return t.length>0&&i.push("",`**Members:** ${t.map(o=>`\`${o.name}\``).join(", ")}`),i.join(`
|
|
13
|
+
`)}a(Rv,"describeEventContextMember");function Xn(n){let e=n.properties.filter(r=>r.isIdentifier&&!de(r).isOptional&&!de(r).isCollection),t=e.length===1?e[0].name:void 0,i=n.produces??[],o=i.some(r=>r.target!==void 0&&r.target!==t)||i.some(r=>r.inline&&r.target===void 0)&&i.some(r=>!r.inline&&r.target===void 0);return{identifier:t,mixed:o}}a(Xn,"productionDestinations");function Fv(n,e){let t=we(n,e?.authoringDocuments??e?.authoringSources,e?.authoringPlacement,e?.authoringPath),i=le(n);return dn(i).commands.map(o=>({...o,produces:o.produces?.filter(r=>!t.operationProductionLines?.has(r.line)&&t.operations.references.some(s=>s.location.line-1===r.line&&s.kind==="event")),productionHeaders:o.productionHeaders?.filter(r=>!t.operationProductionLines?.has(r))})).flatMap(o=>{let{identifier:r,mixed:s}=Xn(o);if(s||o.productionHeaders?.length!==o.produces?.length)return[];let c=o.produces?.some(u=>u.target!==void 0||u.inline);return(o.produces??[]).flatMap(u=>u.target!==void 0||u.inline&&(r===void 0||/\bgeneration\b/.test(i[u.line]))?[]:!u.inline&&c?[]:[{line:u.line,column:i[u.line].length+1,label:u.inline?`for ${r}`:"for <new event source>"}])})}a(Fv,"destinationHints");var q={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 Ya=/^import(\s+)"([^"\\]+)"\s*(?:\/\/.*)?$/,Fa=/^import\s+"/;function $i(n){return Fa.test(n.trim())}a($i,"isFileImportLine");function et(n,e){let t=z(n),i=n.slice(t).match(Ya);if(!i)return;let o=t+6+i[1].length+2;return{pattern:i[2],line:e,startColumn:o,endColumn:o+i[2].length}}a(et,"fileImportOn");function jv(n){let e=H(n),t=[];for(let i=0;i<n.length;i++){if(e[i])continue;let o=et(n[i],i);o&&t.push(o)}return t}a(jv,"fileImports");var Ci=a(n=>n.split("/").slice(0,-1),"folderOf");function qa(n,e){let t=e.split("/"),i=0;for(;i<n.length&&i<t.length-1&&n[i]===t[i];)i++;return[...n.slice(i).map(()=>".."),...t.slice(i)].join("/")}a(qa,"relativeTo");function Vv(n,e){let t=Ci(n),i=new Set;for(let o of e.filter(r=>r!==n&&r.toLowerCase().endsWith(".play"))){let r=qa(t,o),s=Ci(r);i.add(r),i.add([...s,"*.play"].join("/"));for(let c=0;c<=s.length;c++)i.add([...s.slice(0,c),"**","*.play"].join("/"))}return[...i].sort()}a(Vv,"importablePaths");var za=new Set(["namespace","sequence","correlation","causation","causedBy","occurred"]),Wa=/^id\s+"((?:[^"\\]|\\.)*)"$/;function Ai(n,e,t,i=new Set){n=le(n);let o=[],r=H(n),s=Ua(n,r),c=new Set(e.commands.flatMap(k=>k.productionHeaders??[])),u=new Map,p=new Set;for(let k of[e,t]){for(let w of k.events)u.set(w.name,(u.get(w.name)??0)+1);for(let w of k.imports)p.add(w.shortName)}let I=a((k,w,P,C="error")=>{o.push({line:k,startColumn:z(n[k])+1,endColumn:n[k].length+1,code:w,message:P,severity:C})},"report");for(let k of e.events){let w=be(n,r,k.line,z(n[k.line]));if(k.inline){let D=new Set;for(let S of k.properties)D.has(S.name)&&I(S.line,q.duplicateDeclaration,`Event '${k.name}' already declares property '${S.name}'.`),D.add(S.name);c.has(k.line)||I(k.line,q.inlineEventOutsideCommand,"Inline events can only be declared inside commands."),k.generation!==void 0&&I(k.line,q.inlineEventGeneration,"Inline events are generation 1; extract the event before declaring generations."),((u.get(k.name)??0)>1||p.has(k.name))&&I(k.line,q.inlineEventCollision,`Inline event '${k.name}' collides with another declaration or import.`)}let P=!1,C=!1;for(let D of w){let S=n[D].trim(),$=S.split(/\s+/)[0];if(k.inline&&$==="generation"&&I(D,q.inlineEventGeneration,"Inline events are generation 1; extract the event before declaring generations."),k.inline&&$==="origin"&&I(D,q.reservedProductionMetadata,"An inline event is local to its command and cannot declare origin."),!/^(?:id|description|documentation)\s+[\w.]+(?:\[\])?(?:\?|\s+optional)?(?:\s*=.*)?$/.test(S)){if($==="id"){let m=S.match(Wa);P||m===null||m[1].trim().length===0?I(D,q.invalidEventId,'Expected one nonempty id "<old-name>".'):m[1]===k.name&&I(D,q.redundantEventId,"This id repeats the event name; remove it.","information"),P=!0}if($==="documentation"){let m=D+1;for(;m<n.length&&n[m].trim().length===0;)m++;(C||S!=="documentation"||n[m]?.trim()!=="```markdown"||z(n[m])<=z(n[D])||!s.has(m))&&I(D,q.invalidEventDocumentation,"Expected one nonempty fenced markdown documentation block."),C=!0}}}}let v=[];for(let k=0;k<n.length;k++){if(r[k]||n[k].trim().length===0)continue;let w=z(n[k]);for(;v.length>0&&v[v.length-1].indent>=w;)v.pop();let P=n[k].trim().split(/\s+/)[0];za.has(P)&&v.at(-1)?.event&&I(k,q.reservedProductionMetadata,`'${P}' is system-assigned production metadata.`),P==="produces"&&v.push({indent:w,event:!i.has(k)&&!/^\s*produces\s+operation\b/.test(n[k])})}for(let k of e.commands){let{identifier:w,mixed:P}=Xn(k);for(let C of k.produces??[]){P&&C.target===void 0&&I(C.line,q.explicitProducesTargetsRequired,`Production '${C.name}' must state for explicitly when destinations differ.`);let D=C.target??(C.inline?w:void 0);if(!(w===void 0||D!==w))for(let S of C.mappings.filter($=>$.source===w))I(S.line,q.eventSourceIdInPayload,`The payload copies '${w}', which already identifies the event source.`,C.inline?"warning":"information")}}return o}a(Ai,"validateInlineEvents");function Ua(n,e){let t=new Set,i,o=!1;for(let r=0;r<n.length;r++){if(!e[r])continue;let s=n[r].trim();i===void 0?(i=r,o=!1):s==="```"?(o&&n[i].trim()==="```markdown"&&t.add(i),i=void 0):s.length>0&&(o=!0)}return t}a(Ua,"nonemptyMarkdownBlocks");function G(n,e,t,i,o,r){return{severity:n,message:o,line:e,startColumn:t,endColumn:t+i,code:r}}a(G,"issue");function ee(n,e,t,i,o,r){let s=t.indexOf(i)+1;return G(n,e,s,i.length,o,r)}a(ee,"tokenIssue");function ja(n,e,t){let i=[],o=new Set([...Qn(e,Ye),...Qn(t,[])]),r=a((c,u)=>{for(let p of c.filter(I=>!o.has(de(I).name))){let I=de(p).name;i.push(G("warning",p.line,p.sourceType.startColumn,p.sourceType.text.length,I==="optional"?`Unknown type 'optional' on '${p.name}' of ${u} \u2014 did you forget the type before 'optional'?`:`Unknown type '${I}' on '${p.name}' of ${u} \u2014 declare it with 'concept ${I} : <Primitive>' or 'type ${I}'.`,q.unknownType))}},"checkProperties");for(let c of e.types)r(c.properties,`type '${c.name}'`);for(let c of e.events)r(c.properties,`event '${c.name}'`);for(let c of e.queries)r(c.parameters,`query '${c.name}'`);for(let c of e.commands){r(c.properties,`command '${c.name}'`);let u=c.properties.filter(p=>p.isIdentifier);for(let p of u.slice(1))i.push(ee("error",p.line,n[p.line],"identifier",`Command '${c.name}' already marks '${u[0].name}' as identifier \u2014 only one property can be the identifier.`,q.duplicateCommandIdentifier))}let s=new Map;for(let c of[...e.concepts,...e.types]){if(s.get(c.name)===void 0){s.set(c.name,c.line);continue}i.push(ee("error",c.line,n[c.line],c.name,`Duplicate declaration of '${c.name}' \u2014 concept and type names must be unique.`,q.duplicateDeclaration))}return i}a(ja,"validateDeclarations");function gg(n,e={}){let t=H(n),i=dn(n),o=e.application??Pi(),r=we(n,o.authoringDocuments??o.authoringSources,e.placement,e.path),s={...i,commands:i.commands.map(P=>({...P,produces:P.produces?.filter(C=>!r.operationProductionLines?.has(C.line)),productionHeaders:P.productionHeaders?.filter(C=>!r.operationProductionLines?.has(C))}))},c=new Set([...pn(s),...pn(o)]),u=new Set([...s.policies,...o.policies].map(P=>P.name)),p=ja(n,s,o);p.push(...Va(n,s));let I=new Set([d.LegacyOptionalSuffix,d.InvalidOptionalModifierOrder,d.OptionalReadsNotSupported]);for(let P of e.compilerDiagnostics??r.diagnostics){if(!I.has(P.code)&&P.code!==d.RepeatedDeclarationAcrossFiles&&!/^PLAY049[0-9]$|^PLAY050[0-2]$|^PLAY048[2-9]$|^PLAY004[56]$/.test(P.code))continue;let C=P.location.line-1,D=zn(n[C],P)||n[C].length-P.location.column+1;p.push(G(P.severity,C,P.location.column,D,P.message,P.code))}for(let P of r.commands.values()){for(let C of P.properties.filter(D=>D.isGenerated))p.push(G("information",C.location.line-1,C.location.column,C.name.length,`Generated value '${C.name}' is not a request or form input. ${Me}`,q.unavailableResponseExecution));P.response&&p.push(G("information",P.response.location.line-1,P.response.location.column,7,Me,q.unavailableResponseExecution))}for(let P of r.specifications.values()){for(let C of P.when?.generatedValues??[])p.push(G("information",C.location.line-1,C.location.column,9,Me,q.unavailableResponseExecution));P.thenReturns&&p.push(G("information",P.thenReturns.location.line-1,P.thenReturns.location.column,12,Me,q.unavailableResponseExecution))}let v=a((P,C,D)=>{c.has(D)||p.push(ee("warning",P,C,D,`Unknown event type '${D}' \u2014 declare it in a slice or import it.`,q.unknownEvent))},"checkEvent"),k=-1;for(let P=0;P<n.length;P++){let C=n[P],D=C.trim();if(t[P]||D.length===0)continue;let S=C.match(/^[ ]*(\t+)/);if(S&&p.push(G("warning",P,S[0].length-S[1].length+1,S[1].length,"Screenplay is indentation-based \u2014 use spaces, not tabs.",q.tabIndentation)),k>=0){if(z(C)>k&&/^(?:or\s+)?[A-Z]\w*(?:\s+or\s+[A-Z]\w*)*$/.test(D)){for(let L of D.split(/\s+/).filter(x=>x!=="or"))u.has(L)||p.push(ee("warning",P,C,L,`Unknown policy '${L}' \u2014 declare it with 'policy ${L}'.`,q.unknownPolicy));continue}k=-1}let $=Za(n,t,P);$&&p.push($);let m=D.match(/^slice\s+(\w+)/);m&&!vn.includes(m[1])&&p.push(ee("error",P,C,m[1],`Unknown slice type '${m[1]}' \u2014 expected ${vn.join(", ")}.`,q.unknownSliceType));let g=D.match(/^concept\s+\w+\s*:\s*(\w+)/);g&&g[1]!=="Enum"&&!Ye.includes(g[1])&&p.push(ee("error",P,C,g[1],`Unknown primitive type '${g[1]}' \u2014 expected ${Ye.join(", ")} or Enum.`,q.unknownPrimitiveType));let y=D.match(/^authorize\s+(.*)$/);if(y){k=z(C);for(let L of y[1].split(/\s+/).filter(x=>x!=="or"&&x.length>0))u.has(L)||p.push(ee("warning",P,C,L,`Unknown policy '${L}' \u2014 declare it with 'policy ${L}'.`,q.unknownPolicy))}let h=D.match(/^on\s+([A-Z]\w*)\s*$/);h&&v(P,C,h[1]);let A=D.match(/^produces\s+([A-Z]\w*)\s*$/);if(A&&!r.operationProductionLines?.has(P)&&v(P,C,A[1]),/^produces\s+when\b/.test(D)&&!r.operationProductionLines?.has(P))for(let L=P+1;L<n.length;L++){let x=n[L];if(!(t[L]||x.trim().length===0)){if(z(x)>z(C)){let Y=x.trim().match(/^([A-Z]\w*)\s*$/);Y&&v(L,x,Y[1])}break}}let R=D.match(/^unique\s+event\s+([A-Z]\w*)/);R&&v(P,C,R[1]);let E=D.match(/^unique\s+[a-z_]\w*\s+on\s+([A-Z]\w*)/);E&&v(P,C,E[1]);for(let L of C.match(/\$context\.[\w.]+/g)??[]){let x=L.substring(9).split(".");fn.includes(x[0])?x[0]==="causedBy"&&x.length>1&&!mn.includes(x[1])?p.push(ee("warning",P,C,L,`Unknown $context.causedBy property '${x[1]}' \u2014 expected ${mn.join(", ")}.`,q.unknownContextCausedByProperty)):x[0]==="identity"&&x.length>1&&!hn.includes(x[1])&&p.push(ee("warning",P,C,L,`Unknown $context.identity property '${x[1]}' \u2014 expected ${hn.join(", ")}.`,q.unknownContextIdentityProperty)):p.push(ee("warning",P,C,L,`Unknown $context path '${x.join(".")}' \u2014 expected one of ${fn.join(", ")}.`,q.unknownContextPath))}}p.push(...Ga(n,t)),p.push(...Ai(n,s,o,r.operationProductionLines));let w=n.map((P,C)=>({line:P,index:C})).filter(({line:P})=>/^\s*```(?:[a-z]+)?\s*$/.test(P));if(w.length%2===1){let P=w[w.length-1];p.push(G("error",P.index,1,P.line.length+1,"Unclosed inline code block \u2014 expected a closing ``` line.",q.unclosedCodeBlock))}return p}a(gg,"validateLines");function Va(n,e){let t=[];n=le(n);for(let i of e.commands){let o=i.properties.filter(r=>r.isIdentifier&&!de(r).isOptional&&!de(r).isCollection);if(o.length===1)for(let r of i.produces??[]){if(r.inline||r.conditional||r.target!==void 0)continue;let s=r.line;t.push(G("information",s,z(n[s])+1,n[s].trim().length,`Plain 'produces ${r.name}' omits its destination \u2014 use 'for ${o[0].name}' to explicitly select the command's identifier.`,q.omittedProductionDestination))}}return t}a(Va,"validateProductionDestinations");function Za(n,e,t){let i=n[t],o=i.trim().replace(/\s*\/\/.*$/,"");if(!/^import\b/.test(o)||et(i,t))return;let r=z(i);if(!(!(r>0&&["module","feature"].includes(it(n,e,t,r)[0]))&&!$i(i)))return G("error",t,r+1,o.length,`Invalid import '${o}' \u2014 inside a module or feature, import names files: 'import "<path or glob>"'.`,q.invalidFileImport)}a(Za,"validateImport");var _a=/^(?:(?:increment|decrement|count|clear|add|subtract|set)\s+)?@?([$\w.]+)(?=\s|=|$)/;function Ga(n,e){let t=[],i=a(o=>o.map(r=>r.name).join(", "),"names");for(let o=0;o<n.length;o++){let r=n[o];if(e[o])continue;for(let u of r.matchAll(/(\.)?\$eventContext((?:\.(?:\w+(?:\(\))?)?)*)/g)){let p=u[0].substring(u[1]?.length??0),I=u[2];if(I.length===0){u[1]&&t.push(G("error",o,(u.index??0)+2,p.length,`'$eventContext' names no member - expected one of ${i(Kn("").expected)}.`,q.missingEventContextPath));continue}let v=I.substring(1),k=Kn(v),w=(u.index??0)+(u[1]?.length??0)+1;switch(k.status){case"missing":t.push(G("error",o,w,p.length,`'$eventContext.${v}' names no member - expected one of ${i(k.expected)}.`,q.missingEventContextPath));break;case"unknownMember":t.push(G("warning",o,w,p.length,`Unknown event context member '${k.segment}' in '$eventContext.${v}' - expected one of ${i(k.expected)}.`,q.unknownEventContextMember));break;case"unknownSubPath":{let P=k.expected.length===0?"no members to address":`members ${i(k.expected)}`;t.push(G("warning",o,w,p.length,`Unknown event context path '$eventContext.${v}' - '${k.member?.name}' (${k.member?.type}) has ${P}.`,q.unknownEventContextPath));break}case"belowCollection":t.push(G("error",o,w,p.length,`'$eventContext.${v}' cannot resolve - '${k.member?.name}' is a collection (${k.member?.type}) and cannot be addressed below.`,q.eventContextPathBelowCollection));break}}let s=r.trim().match(_a)?.[1],c=s?.match(/\.\$(\w+)/)?.[1];s&&c&&c!=="eventContext"&&t.push(ee("warning",o,r,s,`Dynamic dictionary key '$${c}' in '${s}' is never resolved - only '$eventContext.<path>' is, so the literal text '$${c}' becomes the key.`,q.unresolvedDynamicKeySource))}return t}a(Ga,"validateEventContextPaths");export{Ei as a,Qa as b,Ha as c,tt as d,Ja as e,fn as f,mn as g,vn as h,Ye as i,Ka as j,Xa as k,Pe as l,nc as m,d as n,bm as o,Pm as p,pe as q,z as r,gn as s,H as t,it as u,oc as v,le as w,Me as x,we as y,Vn as z,cv as A,Zn as B,lv as C,de as D,be as E,dn as F,Pi as G,pn as H,xa as I,Iv as J,Qn as K,Na as L,Hn as M,Jn as N,Ba as O,Dv as P,Ov as Q,Rv as R,Xn as S,Fv as T,q as U,$i as V,et as W,jv as X,Vv as Y,gg as Z,Ga as _};
|
|
14
|
+
//# sourceMappingURL=chunk-UNPNNHWD.js.map
|