@cratis/screenplay-language 4.256.0 → 4.257.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/bundles/compiler/Authoring/QuickFixes.js +2 -2
- package/dist/bundles/compiler/Authoring/QuickFixes.js.map +1 -1
- package/dist/bundles/compiler/Diagnostics/DiagnosticCodes.js +1 -1
- package/dist/bundles/compiler/Diagnostics/DiagnosticCodes.js.map +1 -1
- package/dist/bundles/compiler/Files/PlayFolderMerge.js +1 -1
- package/dist/bundles/compiler/Parsing/AuthorizeParser.js +1 -1
- package/dist/bundles/compiler/Parsing/AuthorizeParser.js.map +1 -1
- package/dist/bundles/compiler/Parsing/CommandParser.js +1 -1
- package/dist/bundles/compiler/Parsing/CommandParser.js.map +1 -1
- package/dist/bundles/compiler/Parsing/FeatureBody.js +1 -1
- package/dist/bundles/compiler/Parsing/ModuleBody.js +1 -1
- package/dist/bundles/compiler/Parsing/ProjectionParser.js +1 -1
- package/dist/bundles/compiler/Parsing/ProjectionParser.js.map +1 -1
- package/dist/bundles/compiler/Parsing/QueryParser.js +1 -1
- package/dist/bundles/compiler/Parsing/ScreenParser.js +1 -1
- package/dist/bundles/compiler/index.js +1 -1
- package/dist/bundles/validation.js +1 -1
- package/dist/bundles/validation.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthorizeParser.js","names":["continuationPattern","pattern","tokenPattern","namePattern","text","line","child","context","tokens","location","locationOf","DiagnosticCodes","requirement","first","next","token","#or","#position","#chain","#and","#groupOrReference","left","operand","right","#reference"],"sources":["../../../../../../Compiler/Parsing/AuthorizeParser.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { DiagnosticCodes } from '../Diagnostics/DiagnosticCodes';\nimport { SourceLocation } from '../Diagnostics/SourceLocation';\nimport { AuthorizeSyntax, LogicalOperator, PolicyRequirementSyntax } from '../Syntax/Authorization';\nimport { pattern } from '../Text/patterns';\nimport { ParserContext } from './ParserContext';\nimport { locationOf, SourceLine } from './SourceLine';\n\nconst continuationPattern = pattern('^(?:(?:or|and)\\\\s+)?[A-Za-z_(][\\\\w\\\\s()]*$');\nconst tokenPattern = new RegExp(pattern('\\\\(|\\\\)|[A-Za-z_]\\\\w*').source, 'gu');\nconst namePattern = pattern('^[A-Z]\\\\w*$');\n\n// The port of the C# AuthorizeParser: the requirement may continue on the lines below the 'authorize', and\n// two operands written side by side are joined by an implicit 'and'.\nexport function parseAuthorize(context: ParserContext, line: SourceLine): AuthorizeSyntax | null {\n let text = line.content.substring('authorize'.length);\n for (let child = context.peekChild(line.indent); child !== undefined && continuationPattern.test(child.content); child = context.peekChild(line.indent)) {\n context.reader.takeSignificant();\n text += ` ${child.content}`;\n }\n const tokens = tokenize(text);\n const location = locationOf(line);\n if (tokens.length === 0) {\n context.error(DiagnosticCodes.AuthorizeWithoutPolicy, 'Expected at least one policy after \\'authorize\\'', location);\n return null;\n }\n const parser = new RequirementParser(context, tokens, location);\n const requirement = parser.parse();\n return requirement === null ? null : { kind: 'AuthorizeSyntax', requirement, location };\n}\n\n// Several 'authorize' lines on one construct all have to hold, so they combine with 'and'.\nexport function combineAuthorize(first: AuthorizeSyntax | null, next: AuthorizeSyntax | null): AuthorizeSyntax | null {\n if (first === null) return next;\n if (next === null) return first;\n return {\n kind: 'AuthorizeSyntax',\n requirement: { kind: 'LogicalPolicyRequirementSyntax', left: first.requirement, operator: 'And', right: next.requirement, location: first.location },\n location: first.location,\n };\n}\n\nfunction tokenize(text: string): string[] {\n const tokens: string[] = [];\n for (const token of text.match(tokenPattern) ?? []) {\n if (tokens.length > 0 && isOperandEnd(tokens[tokens.length - 1]) && isOperandStart(token)) {\n tokens.push('and');\n }\n tokens.push(token);\n }\n return tokens;\n}\n\nconst isName = (token: string): boolean => token !== '(' && token !== ')' && token !== 'and' && token !== 'or';\nconst isOperandEnd = (token: string): boolean => token === ')' || isName(token);\nconst isOperandStart = (token: string): boolean => token === '(' || isName(token);\n\n// The port of the C# LogicalConditionParser: 'or' over 'and' over a group or a policy name.\nclass RequirementParser {\n #position = 0;\n\n constructor(private readonly context: ParserContext, private readonly tokens: readonly string[], private readonly location: SourceLocation) {}\n\n parse(): PolicyRequirementSyntax | null {\n const requirement = this.#or();\n if (requirement !== null && this.#position < this.tokens.length) {\n this.context.error(DiagnosticCodes.UnexpectedTokenInAuthorize, `Unexpected '${this.tokens[this.#position]}' in authorize`, this.location);\n }\n return requirement;\n }\n\n #or(): PolicyRequirementSyntax | null {\n return this.#chain('or', 'Or', () => this.#and());\n }\n\n #and(): PolicyRequirementSyntax | null {\n return this.#chain('and', 'And', () => this.#groupOrReference());\n }\n\n #chain(token: string, operator: LogicalOperator, operand: () => PolicyRequirementSyntax | null): PolicyRequirementSyntax | null {\n let left = operand();\n while (left !== null && this.tokens[this.#position] === token) {\n this.#position++;\n const right = operand();\n if (right === null) {\n return null;\n }\n left = { kind: 'LogicalPolicyRequirementSyntax', left, operator, right, location: this.location };\n }\n return left;\n }\n\n #groupOrReference(): PolicyRequirementSyntax | null {\n if (this.tokens[this.#position] !== '(') {\n return this.#reference();\n }\n this.#position++;\n const requirement = this.#or();\n if (this.tokens[this.#position] === ')') {\n this.#position++;\n } else {\n this.context.error(DiagnosticCodes.UnclosedAuthorizeGroup, 'Expected \\')\\' in authorize', this.location);\n }\n return requirement;\n }\n\n #reference(): PolicyRequirementSyntax | null {\n if (this.#position >= this.tokens.length) {\n this.context.error(DiagnosticCodes.AuthorizeWithoutPolicy, 'Expected a policy name', this.location);\n return null;\n }\n const token = this.tokens[this.#position++];\n if (!namePattern.test(token)) {\n this.context.error(DiagnosticCodes.InvalidPolicyReference, `Invalid policy reference '${token}' - policy names are PascalCase identifiers`, this.location);\n return null;\n }\n return { kind: 'PolicyReferenceSyntax', name: token, location: this.location };\n }\n}\n"],"mappings":"oNAUA,MAAMA,EAAsBC,EAAQ,4CAA4C,EAC1EC,EAAe,IAAI,OAAOD,EAAQ,uBAAuB,CAAC,CAAC,OAAQ,IAAI,EACvEE,EAAcF,EAAQ,aAAa,EAIzC,SAAgB,eAAe,EAAwB,EAA0C,CAC7F,IAAIG,EAAOC,EAAK,QAAQ,UAAU,CAAkB,EACpD,IAAK,IAAIC,EAAQC,EAAQ,UAAUF,EAAK,MAAM,EAAGC,IAAU,IAAA,IAAaN,EAAoB,KAAKM,EAAM,OAAO,EAAG,EAAQC,EAAQ,UAAUF,EAAK,MAAM,EAClJE,EAAQ,OAAO,gBAAgB,EAC/B,GAAQ,IAAID,EAAM,UAEtB,IAAME,EAAS,SAASJ,CAAI,EACtBK,EAAWC,EAAWL,CAAI,EAChC,GAAIG,EAAO,SAAW,EAElB,OADAD,EAAQ,MAAMI,EAAgB,uBAAwB,iDAAoDF,CAAQ,EAC3G,
|
|
1
|
+
{"version":3,"file":"AuthorizeParser.js","names":["continuationPattern","pattern","tokenPattern","namePattern","text","line","child","context","tokens","location","locationOf","DiagnosticCodes","requirement","first","next","token","content","match","previous","#or","#position","#chain","#and","#groupOrReference","left","operand","right","#reference"],"sources":["../../../../../../Compiler/Parsing/AuthorizeParser.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { DiagnosticCodes } from '../Diagnostics/DiagnosticCodes';\nimport { SourceLocation } from '../Diagnostics/SourceLocation';\nimport { AuthorizeSyntax, LogicalOperator, PolicyRequirementSyntax } from '../Syntax/Authorization';\nimport { pattern } from '../Text/patterns';\nimport { ParserContext } from './ParserContext';\nimport { locationOf, SourceLine } from './SourceLine';\n\nconst continuationPattern = pattern('^(?:(?:or|and)\\\\s+)?[A-Za-z_(][\\\\w\\\\s()]*$');\nconst tokenPattern = new RegExp(pattern('\\\\(|\\\\)|[A-Za-z_]\\\\w*').source, 'gu');\nconst namePattern = pattern('^[A-Z]\\\\w*$');\n\n// The port of the C# AuthorizeParser: the requirement may continue on the lines below the 'authorize', and\n// two operands written side by side are joined by an implicit 'and'.\nexport function parseAuthorize(context: ParserContext, line: SourceLine): AuthorizeSyntax | null {\n let text = line.content.substring('authorize'.length);\n for (let child = context.peekChild(line.indent); child !== undefined && continuationPattern.test(child.content); child = context.peekChild(line.indent)) {\n context.reader.takeSignificant();\n text += ` ${child.content}`;\n }\n const tokens = tokenize(text);\n const location = locationOf(line);\n if (tokens.length === 0) {\n context.error(DiagnosticCodes.AuthorizeWithoutPolicy, 'Expected at least one policy after \\'authorize\\'', location);\n return null;\n }\n if (hasImplicitConjunction(text)) context.information(DiagnosticCodes.ImplicitAuthorizationConjunction, 'Write \\'and\\' between adjacent policies in \\'authorize\\'.', location);\n const parser = new RequirementParser(context, tokens, location);\n const requirement = parser.parse();\n return requirement === null ? null : { kind: 'AuthorizeSyntax', requirement, location };\n}\n\n// Several 'authorize' lines on one construct all have to hold, so they combine with 'and'.\nexport function combineAuthorize(first: AuthorizeSyntax | null, next: AuthorizeSyntax | null): AuthorizeSyntax | null {\n if (first === null) return next;\n if (next === null) return first;\n return {\n kind: 'AuthorizeSyntax',\n requirement: { kind: 'LogicalPolicyRequirementSyntax', left: first.requirement, operator: 'And', right: next.requirement, location: first.location },\n location: first.location,\n };\n}\n\nfunction tokenize(text: string): string[] {\n const tokens: string[] = [];\n for (const token of text.match(tokenPattern) ?? []) {\n if (tokens.length > 0 && isOperandEnd(tokens[tokens.length - 1]) && isOperandStart(token)) {\n tokens.push('and');\n }\n tokens.push(token);\n }\n return tokens;\n}\n\nexport function isAuthorizeContinuation(content: string): boolean {\n return continuationPattern.test(content);\n}\n\n/** Finds each operand of one authorize line that sits directly after another operand, so an 'and' belongs before it. */\nexport function implicitConjunctionTokens(text: string, previous: string | undefined): { readonly tokens: readonly { readonly index: number; readonly length: number }[]; readonly previous: string | undefined } {\n const tokens: { index: number; length: number }[] = [];\n for (const match of text.matchAll(tokenPattern)) {\n if (previous !== undefined && isOperandEnd(previous) && isOperandStart(match[0])) tokens.push({ index: match.index, length: match[0].length });\n previous = match[0];\n }\n return { tokens, previous };\n}\n\nfunction hasImplicitConjunction(text: string): boolean {\n return implicitConjunctionTokens(text, undefined).tokens.length > 0;\n}\n\nconst isName = (token: string): boolean => token !== '(' && token !== ')' && token !== 'and' && token !== 'or';\nconst isOperandEnd = (token: string): boolean => token === ')' || isName(token);\nconst isOperandStart = (token: string): boolean => token === '(' || isName(token);\n\n// The port of the C# LogicalConditionParser: 'or' over 'and' over a group or a policy name.\nclass RequirementParser {\n #position = 0;\n\n constructor(private readonly context: ParserContext, private readonly tokens: readonly string[], private readonly location: SourceLocation) {}\n\n parse(): PolicyRequirementSyntax | null {\n const requirement = this.#or();\n if (requirement !== null && this.#position < this.tokens.length) {\n this.context.error(DiagnosticCodes.UnexpectedTokenInAuthorize, `Unexpected '${this.tokens[this.#position]}' in authorize`, this.location);\n }\n return requirement;\n }\n\n #or(): PolicyRequirementSyntax | null {\n return this.#chain('or', 'Or', () => this.#and());\n }\n\n #and(): PolicyRequirementSyntax | null {\n return this.#chain('and', 'And', () => this.#groupOrReference());\n }\n\n #chain(token: string, operator: LogicalOperator, operand: () => PolicyRequirementSyntax | null): PolicyRequirementSyntax | null {\n let left = operand();\n while (left !== null && this.tokens[this.#position] === token) {\n this.#position++;\n const right = operand();\n if (right === null) {\n return null;\n }\n left = { kind: 'LogicalPolicyRequirementSyntax', left, operator, right, location: this.location };\n }\n return left;\n }\n\n #groupOrReference(): PolicyRequirementSyntax | null {\n if (this.tokens[this.#position] !== '(') {\n return this.#reference();\n }\n this.#position++;\n const requirement = this.#or();\n if (this.tokens[this.#position] === ')') {\n this.#position++;\n } else {\n this.context.error(DiagnosticCodes.UnclosedAuthorizeGroup, 'Expected \\')\\' in authorize', this.location);\n }\n return requirement;\n }\n\n #reference(): PolicyRequirementSyntax | null {\n if (this.#position >= this.tokens.length) {\n this.context.error(DiagnosticCodes.AuthorizeWithoutPolicy, 'Expected a policy name', this.location);\n return null;\n }\n const token = this.tokens[this.#position++];\n if (!namePattern.test(token)) {\n this.context.error(DiagnosticCodes.InvalidPolicyReference, `Invalid policy reference '${token}' - policy names are PascalCase identifiers`, this.location);\n return null;\n }\n return { kind: 'PolicyReferenceSyntax', name: token, location: this.location };\n }\n}\n"],"mappings":"oNAUA,MAAMA,EAAsBC,EAAQ,4CAA4C,EAC1EC,EAAe,IAAI,OAAOD,EAAQ,uBAAuB,CAAC,CAAC,OAAQ,IAAI,EACvEE,EAAcF,EAAQ,aAAa,EAIzC,SAAgB,eAAe,EAAwB,EAA0C,CAC7F,IAAIG,EAAOC,EAAK,QAAQ,UAAU,CAAkB,EACpD,IAAK,IAAIC,EAAQC,EAAQ,UAAUF,EAAK,MAAM,EAAGC,IAAU,IAAA,IAAaN,EAAoB,KAAKM,EAAM,OAAO,EAAG,EAAQC,EAAQ,UAAUF,EAAK,MAAM,EAClJE,EAAQ,OAAO,gBAAgB,EAC/B,GAAQ,IAAID,EAAM,UAEtB,IAAME,EAAS,SAASJ,CAAI,EACtBK,EAAWC,EAAWL,CAAI,EAChC,GAAIG,EAAO,SAAW,EAElB,OADAD,EAAQ,MAAMI,EAAgB,uBAAwB,iDAAoDF,CAAQ,EAC3G,KAEP,uBAAuBL,CAAI,GAAGG,EAAQ,YAAYI,EAAgB,iCAAkC,wDAA6DF,CAAQ,EAE7K,IAAMG,EAAc,IADD,kBAAkBL,EAASC,EAAQC,CAC7B,CAAC,CAAC,MAAM,EACjC,OAAOG,IAAgB,KAAO,KAAO,CAAE,KAAM,kBAAmB,cAAa,UAAS,CAC1F,CAGA,SAAgB,iBAAiB,EAA+B,EAAsD,CAGlH,OAFIC,IAAU,KAAaC,EACvBA,IAAS,KAAaD,EACnB,CACH,KAAM,kBACN,YAAa,CAAE,KAAM,iCAAkC,KAAMA,EAAM,YAAa,SAAU,MAAO,MAAOC,EAAK,YAAa,SAAUD,EAAM,QAAS,EACnJ,SAAUA,EAAM,QACpB,CACJ,CAEA,SAAS,SAAS,EAAwB,CACt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AQ,EAErIR,CACX,CAEA,IAAsC,CAClC,OAAO,KAAKS,GAAO,KAAM,SAAY,KAAKC,GAAK,CAAC,CACpD,CAEA,IAAuC,CACnC,OAAO,KAAKD,GAAO,MAAO,UAAa,KAAKE,GAAkB,CAAC,CACnE,CAEA,GAAO,EAAe,EAA2B,EAA+E,CAC5H,IAAIC,EAAOC,EAAQ,EACnB,KAAOD,IAAS,MAAQ,KAAK,OAAO,KAAKJ,MAAeL,GAAO,CAC3D,KAAKK,KACL,IAAMM,EAAQD,EAAQ,EACtB,GAAIC,IAAU,KACV,OAAO,KAEX,EAAO,CAAE,KAAM,iCAAkC,OAAM,WAAU,QAAO,SAAU,KAAK,QAAS,CACpG,CACA,OAAOF,CACX,CAEA,IAAoD,CAChD,GAAI,KAAK,OAAO,KAAKJ,MAAe,IAChC,OAAO,KAAKO,GAAW,EAE3B,KAAKP,KACL,IAAMR,EAAc,KAAKO,GAAI,EAM7B,OALI,KAAK,OAAO,KAAKC,MAAe,IAChC,KAAKA,KAEL,KAAK,QAAQ,MAAMT,EAAgB,uBAAwB,4BAA+B,KAAK,QAAQ,EAEpGC,CACX,CAEA,IAA6C,CACzC,GAAI,KAAKQ,IAAa,KAAK,OAAO,OAE9B,OADA,KAAK,QAAQ,MAAMT,EAAgB,uBAAwB,yBAA0B,KAAK,QAAQ,EAC3F,KAEX,IAAMI,EAAQ,KAAK,OAAO,KAAKK,MAK/B,OAJKjB,EAAY,KAAKY,CAAK,EAIpB,CAAE,KAAM,wBAAyB,KAAMA,EAAO,SAAU,KAAK,QAAS,GAHzE,KAAK,QAAQ,MAAMJ,EAAgB,uBAAwB,6BAA6BI,EAAM,6CAA8C,KAAK,QAAQ,EAClJ,KAGf,CACJ"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import"../../_virtual/_virtual/_rolldown/runtime.js";import{DiagnosticCodes as e}from"../Diagnostics/DiagnosticCodes.js";import{stringBodyPattern as t,unescapeString as n}from"../Text/StringLiteral.js";import{pattern as r}from"../Text/patterns.js";import{locationOf as i}from"./SourceLine.js";import{dependencySources as a}from"../Syntax/DependencySources.js";import{parseMappingSource as o}from"./ExpressionParser.js";import{validateHandlerContracts as s}from"./CommandHandlerValidator.js";import{firstWord as c}from"./LineText.js";import{reportInvalidModifierOrder as l,reportLegacyOptionalSuffix as u,tryParseProperty as d}from"./PropertyLineParser.js";import{combineAuthorize as f,parseAuthorize as p}from"./AuthorizeParser.js";import{parseDescription as m}from"./DescriptionParser.js";import{parseDocumentation as h}from"./DocumentationParser.js";import{parseCondition as g}from"./ConditionParser.js";import{ParserContext as _}from"./ParserContext.js";import{isReactionIdentityLine as v,misplacedReactionIdentity as y}from"./ReactionIdentityParser.js";import{sourceStreamPattern as b}from"../Text/SourceStreamNames.js";import{parseCommandStream as x}from"./EventSourceParser.js";import{isFileDirectiveAmongProperties as S}from"./FileReferences.js";import{isCode as C,isFile as w,parseCode as T,parseFile as E,parseHandler as D,parseImplementationWrapper as O}from"./ImplementationParser.js";import{parseCommandResponse as k,scalarResponsePattern as A}from"./CommandResponseParser.js";import{matchSubject as j,validateMatchOperand as M}from"./MatchOperandValidation.js";import{commandReadSources as N}from"./CommandReadSources.js";import{captureConcurrency as P}from"./DependencySourceParser.js";import{parseReads as F}from"./ReadsParser.js";import{parseProduces as I}from"./ProducesParser.js";const L=r(`^command\\s+([A-Za-z_]\\w*)$`),R=b(`^stream\\s+[A-Za-z_]\\w*\\.[A-Za-z_]\\w*$`),z=r(`^calendar\\s+(?:"|from\\s+\\$context\\.)`),B=r(`^calendar\\s+(?:"(${t})"|from\\s+\\$context\\.([A-Za-z_][A-Za-z0-9_]*(?:\\.[A-Za-z_][A-Za-z0-9_]*)*))$`),V=r(`\\bseverity\\s+(\\S+)$`),H=r(`\\bmessage\\s+(?:"(${t})"|(\\$strings\\.\\S*))$`),U=r(`^([\\w.]+)\\s+(.+)$`),W=r(`^(?:(not empty|matches|not contains|contains|starts with|ends with|max|min|rule)(?:\\s+|$)|(length ==|decimals <=|all >=|all >|>=|<=|==|!=|>|<)\\s*)(.*)$`),G=b(`^[A-Za-z_]\\w*$`),K=r(`^reads\\s+[A-Z]\\w*\\s+optional(?:\\s|$)`),q={max:`Max`,min:`Min`,">":`GreaterThan`,">=":`GreaterThanOrEqual`,"<":`LessThan`,"<=":`LessThanOrEqual`,"==":`Equal`,"!=":`NotEqual`,"length ==":`Length`,"decimals <=":`DecimalPlaces`,matches:`Matches`,contains:`Contains`,"not contains":`NotContains`,"starts with":`StartsWith`,"ends with":`EndsWith`,"all >":`AllGreaterThan`,"all >=":`AllGreaterThanOrEqual`},J={information:`Information`,warning:`Warning`,error:`Error`},Y=/* @__PURE__ */ new Set([`reads`,`concurrency`]),ee=/* @__PURE__ */ new Set([`description`,`documentation`,`handler`,`concurrency`]);function parseCommand(e,t){let n=/* @__PURE__ */ new Set,r=new _(e.reader.fork(),e.path,e.languages);return r.sourceOptions=e.sourceOptions,r.streamCandidates=e.streamCandidates,parseCommandBody(r,t,void 0,n),parseCommandBody(e,t,n)}function parseCommandBody(t,r,o,u){let g=L.exec(r.content)?.[1]??``;g===``&&t.error(e.InvalidCommandDeclaration,`Invalid command declaration '${r.content}' - expected 'command <Name>'`,i(r));let _=[],b=[],S,C=[],w=[],T=[],E=[],O,j=null,M=null,V=null,H=null,U=[],W=null,G=[],q=null;for(let a=t.peekChild(r.indent);a!==void 0;a=t.peekChild(r.indent)){t.reader.takeSignificant();let r=c(a.content),s=d(a);if(r===`calendar`&&z.test(a.content)){let r=B.exec(a.content);q!==null||r===null?t.error(e.InvalidCommandCalendar,`A command declares at most one 'calendar "<id>"' or 'calendar from $context.<member>'.`,i(a)):q={kind:`CommandCalendarSyntax`,id:r[1]===void 0?null:n(r[1]),contextMember:r[2]??null,location:i(a)}}else if(s!==void 0&&(ee.has(r)||r===`validate`&&a.content!==`validate csharp`))S=addProperty(t,_,s,g,a,S);else if(r===`returns`){let e=A.exec(a.content);e!==null&&!e[1].startsWith(`@`)&&s!==void 0?o===void 0?(_.push(s),b.push({line:a,candidate:s,response:null})):o.has(s.type.name)?b.push({line:a,candidate:null,response:k(t,a)}):S=addProperty(t,_,s,g,a,S):s===void 0?l(t,a)?t.skipBlock(a.indent):b.push({line:a,candidate:null,response:k(t,a)}):S=addProperty(t,_,s,g,a,S)}else if(r===`stream`&&R.test(a.content)&&s!==void 0&&t.streamCandidates?.hasSource(s.type.name.split(`.`)[0])===!0){let[n,r]=s.type.name.split(`.`),o=t.streamCandidates.hasPropertyType(s.type.name)&&t.streamCandidates.hasUniqueStream(n,r),c=x(t,a,s,o);(W!==null||G.length>0)&&t.error(e.InvalidCommandStream,`A command declares at most one stream route.`,i(a)),o||W!==null?G.push(c):W=c}else if(r===`runs`&&v(a))y(t,a);else if(r===`description`)j=m(t,a,j,`Command '${g}'`);else if(r===`documentation`)M=h(t,a,M,`Command '${g}'`);else if(r===`authorize`)V=f(V,p(t,a));else if(r===`validate`){let e=parseValidate(t,a,`command`,g);e!==void 0&&C.push(e)}else if(r===`produces`){let e=I(t,a,!0);e!==void 0&&w.push(e)}else if(r===`handler`)H=D(t,a),U.push({handler:H,location:i(a)});else if(Y.has(r)){let n=r===`reads`?F(t,a):void 0;n!==void 0&&E.push(n),r===`concurrency`&&O===void 0&&(O=P(t,a));let o=/^reads\s+([A-Z]\w*)(?:\s+as\s+([a-z_]\w*))?(?:\s+by\s+([a-z_]\w*))?$/.exec(a.content);o!==null&&T.push({readModel:o[1],alias:o[2]??null}),K.test(a.content)&&t.error(e.OptionalReadsNotSupported,`Optional reads are not yet supported (see #308).`,i(a)),t.skipOpaqueBlock(a.indent)}else s===void 0?(l(t,a),t.error(e.UnknownCommandDirective,`Unexpected '${a.content}' in command body`,i(a)),t.skipBlock(a.indent)):S=addProperty(t,_,s,g,a,S)}let J=new Set(b.flatMap(e=>e.candidate===null?[]:[e.candidate])),X=new Set(_.filter(e=>!J.has(e)).map(e=>e.name));b.some(e=>e.candidate!==null&&!X.has(e.candidate.type.name)&&e.candidate.type.name!==`returns`)&&X.add(`returns`);for(let e of X)u?.add(e);let Z=null,Q=/* @__PURE__ */ new Set;for(let n of b){let r=n.response;if(n.candidate!==null){if(!X.has(n.candidate.type.name))continue;Q.add(n.candidate),r={kind:`ScalarCommandResponseSyntax`,source:{kind:`PropertyResponseSourceSyntax`,property:n.candidate.type.name,location:n.candidate.type.location},location:i(n.line)}}r!==null&&(Z===null?Z=r:t.error(e.InvalidCommandResponse,`A command declares at most one unconditional response.`,i(n.line)))}s(U,H,w.length>0,t);let $={kind:`CommandSyntax`,name:g,description:j,documentation:M,authorize:V,properties:_.filter(e=>!Q.has(e)),validations:C,produces:w,handler:H,response:Z,stream:W,streamCandidates:G,...q===null?{}:{calendar:q},location:i(r)};return N.set($,T),a.set($,{reads:E,concurrency:O}),$}function addProperty(t,n,r,i,a,o){return u(t,r.type,a),r.isIdentifier&&o!==void 0&&(t.error(e.DuplicateCommandIdentifier,`Command '${i}' already marks '${o.name}' as identifier - only one property can be the identifier`,r.location),r={...r,isIdentifier:!1}),n.push(r),o??(r.isIdentifier?r:void 0)}function parseValidationFile(e,t,n){let r=E(e,n);return r===void 0?void 0:{kind:`FileValidateSyntax`,file:r,location:i(t)}}function hasValidationOperand(e){let t=U.exec(e.content);if(t===null)return!1;let n=t[2];return c(n)===`not`&&c(n.substring(3).trimStart())===`empty`||c(n)===`checksum`||W.test(n)}function isValidationFileBody(e,t,n){if(!S(n)||hasValidationOperand(n))return!1;let r=e.reader.fork();r.takeSignificant();let i=r.peekSignificant();return i===void 0||i.indent<=t.indent}function parseValidate(t,r,a,o){if(r.content===`validate`){let s=t.peekChild(r.indent);if(s!==void 0&&isValidationFileBody(t,r,s))return t.reader.takeSignificant(),parseValidationFile(t,r,s);if(s!==void 0&&s.content.startsWith("```")){t.reader.takeSignificant();let e=T(t.valueContext,s);return e===null&&t.skipFencedBody(),{kind:`CodeValidateSyntax`,code:e,location:i(r)}}let l=[],u=[],d;for(let s=t.peekChild(r.indent);s!==void 0;s=t.peekChild(r.indent)){if(t.reader.takeSignificant(),a===`concept`){if(t.sourceOptions.numericMode===`legacy`&&s.content.startsWith("```")){t.skipFencedBody();continue}if(d!==void 0&&s.indent<=d&&(d=void 0),d!==void 0||c(s.content)===`implementation`){t.error(e.InvalidValidationRule,`Invalid validation rule '${s.content}'`,i(s)),d??=s.indent;continue}}if(c(s.content)===`require`){let e=g(a===`concept`?t.valueContext:t,s.content.substring(7).trim(),i(s)),r=null,o=`Error`,l=!1;for(let e=t.peekChild(s.indent);e!==void 0;e=t.peekChild(s.indent)){t.reader.takeSignificant();let i=H.exec(e.content);i!==null&&i.index===0?r=i[1]===void 0?i[2]:n(i[1]):c(e.content)===`severity`?(l||(o=J[e.content.substring(8).trim()]??`Error`),l=!0):t.skipOpaqueBlock(e.indent)}e!==null&&u.push({kind:`RequirementSyntax`,condition:e,message:r,severity:o,location:i(s)});continue}let r=parseValidationRule(t,a===`concept`?{...s,content:`value ${s.content}`}:s,a,o);r!==void 0&&l.push(r)}return{kind:`DeclarativeValidateSyntax`,rules:l,requirements:u,location:i(r)}}if(a===`concept`&&c(r.content.substring(8).trimStart())===`checksum`){let e=parseValidationRule(t,{...r,content:`value ${r.content.substring(8).trimStart()}`},a,o);return e===void 0?void 0:{kind:`DeclarativeValidateSyntax`,rules:[e],requirements:[],location:i(r)}}if(r.content===`validate csharp`){let e=T(t.valueContext,{...r,content:`csharp`});return e===null&&t.skipOpaqueBlock(r.indent),{kind:`CodeValidateSyntax`,code:e,location:i(r)}}t.error(e.InvalidValidateDeclaration,`Invalid validate declaration '${r.content}' - expected 'validate' or 'validate csharp'`,i(r)),t.skipBlock(r.indent)}function parseValidationRule(t,n,r,a){let o=c(U.exec(n.content)?.[2]??``)===`checksum`,s=r===`concept`&&!o?t.valueContext:t,{content:l,message:u}=splitMessage(n.content),d=splitSeverity(s,n,l);if(d===void 0)return;let f=U.exec(d.content);if(f===null){s.error(e.InvalidValidationRule,`Invalid validation rule '${n.content}'`,i(n));return}let p=parseRule(s,f[2],n);if(p===void 0)return;p.kind===`Matches`&&p.value!==null&&M(t,p.value,i(n),n.raw,j(t,r,a,f[1]));let m=p.kind===`Rule`?parseRuleImplementation(t,n,r===`command`):{file:null,code:null,implementation:null};return{kind:`ValidationRuleSyntax`,property:f[1],rule:p.kind,value:p.value,message:u,severity:d.severity,...m,location:i(n)}}function parseRuleImplementation(t,n,r){let a=t.peekChild(n.indent);if(a===void 0)return{file:null,code:null,implementation:null};t.reader.takeSignificant();let o=r&&c(a.content)===`implementation`,s=o?O(t,a):{file:w(a)?E(t,a):null,code:!w(a)&&C(t,a)?T(t,a):null,implementation:null};!o&&s.file===null&&s.code===null&&(t.error(e.UnknownRuleImplementationDirective,`Unexpected '${a.content}' in rule implementation - expected 'file <path>' or an inline code block`,i(a)),t.skipBlock(a.indent));for(let a=t.peekChild(n.indent);a!==void 0&&(o||r&&c(a.content)===`implementation`);a=t.peekChild(n.indent))t.reader.takeSignificant(),t.error(o&&c(a.content)===`implementation`?e.InvalidImplementationBlock:e.ConflictingImplementationSources,`A named rule has one implementation wrapper and cannot mix wrapped and direct sources.`,i(a)),C(t,a)?T(t,a):t.skipBlock(a.indent);return s}function splitMessage(e){let t=H.exec(e);if(t===null)return{content:e,message:null};let r=t[1]===void 0?t[2]:n(t[1]);return{content:e.substring(0,t.index).trimEnd(),message:r}}function splitSeverity(t,n,r){let a=V.exec(r);if(a===null)return{content:r,severity:`Error`};let o=J[a[1]];if(o===void 0)t.error(e.InvalidValidationSeverity,`Unknown validation severity '${a[1]}' - expected information, warning or error`,i(n));else return{content:r.substring(0,a.index).trimEnd(),severity:o}}function parseRule(t,n,r){if(n===`not empty`)return{kind:`NotEmpty`,value:null};if(c(n)===`checksum`){let a=n.substring(8).trim();if(a!==`luhn`&&a!==`mod11`&&a!==`mod97`){t.error(e.InvalidGenerationArgument,`Checksum validation requires luhn, mod11 or mod97.`,i(r));return}return{kind:`Checksum`,value:{kind:`LiteralExpressionSyntax`,value:a,location:i(r)}}}let a=W.exec(n);if(a===null){t.error(e.InvalidValidationRule,`Invalid validation rule '${r.content}'`,i(r));return}let s=a[1]??a[2];if(s===`rule`){let n=a[3].trim();if(!G.test(n)){t.error(e.InvalidRuleName,`Invalid rule name '${n}' in '${r.content}' - expected 'rule <Name>' with an identifier`,i(r));return}return{kind:`Rule`,value:{kind:`PathExpressionSyntax`,path:n,location:i(r)}}}return{kind:q[s],value:o(a[3],i(r),t)}}export{parseCommand,parseValidate};
|
|
1
|
+
import"../../_virtual/_virtual/_rolldown/runtime.js";import{DiagnosticCodes as e}from"../Diagnostics/DiagnosticCodes.js";import{stringBodyPattern as t,unescapeString as n}from"../Text/StringLiteral.js";import{pattern as r}from"../Text/patterns.js";import{locationOf as i}from"./SourceLine.js";import{combineAuthorize as a,parseAuthorize as o}from"./AuthorizeParser.js";import{dependencySources as s}from"../Syntax/DependencySources.js";import{parseMappingSource as c}from"./ExpressionParser.js";import{validateHandlerContracts as l}from"./CommandHandlerValidator.js";import{firstWord as u}from"./LineText.js";import{reportInvalidModifierOrder as d,reportLegacyOptionalSuffix as f,tryParseProperty as p}from"./PropertyLineParser.js";import{parseDescription as m}from"./DescriptionParser.js";import{parseDocumentation as h}from"./DocumentationParser.js";import{parseCondition as g}from"./ConditionParser.js";import{ParserContext as _}from"./ParserContext.js";import{isReactionIdentityLine as v,misplacedReactionIdentity as y}from"./ReactionIdentityParser.js";import{sourceStreamPattern as b}from"../Text/SourceStreamNames.js";import{parseCommandStream as x}from"./EventSourceParser.js";import{isFileDirectiveAmongProperties as S}from"./FileReferences.js";import{isCode as C,isFile as w,parseCode as T,parseFile as E,parseHandler as D,parseImplementationWrapper as O}from"./ImplementationParser.js";import{parseCommandResponse as k,scalarResponsePattern as A}from"./CommandResponseParser.js";import{matchSubject as j,validateMatchOperand as M}from"./MatchOperandValidation.js";import{commandReadSources as N}from"./CommandReadSources.js";import{captureConcurrency as P}from"./DependencySourceParser.js";import{parseReads as F}from"./ReadsParser.js";import{parseProduces as I}from"./ProducesParser.js";const L=r(`^command\\s+([A-Za-z_]\\w*)$`),R=b(`^stream\\s+[A-Za-z_]\\w*\\.[A-Za-z_]\\w*$`),ee=r(`^calendar\\s+(?:"|from\\s+\\$context\\.)`),z=r(`^calendar\\s+(?:"(${t})"|from\\s+\\$context\\.([A-Za-z_][A-Za-z0-9_]*(?:\\.[A-Za-z_][A-Za-z0-9_]*)*))$`),B=r(`\\bseverity\\s+(\\S+)$`),V=r(`\\bmessage\\s+(?:"(${t})"|(\\$strings\\.\\S*))$`),H=r(`^([\\w.]+)\\s+(.+)$`),U=r(`^(?:(not empty|matches|not contains|contains|starts with|ends with|max|min|rule)(?:\\s+|$)|(length ==|decimals <=|all >=|all >|>=|<=|==|!=|>|<)\\s*)(.*)$`),W=b(`^[A-Za-z_]\\w*$`),G=r(`^reads\\s+[A-Z]\\w*\\s+optional(?:\\s|$)`),K={max:`Max`,min:`Min`,">":`GreaterThan`,">=":`GreaterThanOrEqual`,"<":`LessThan`,"<=":`LessThanOrEqual`,"==":`Equal`,"!=":`NotEqual`,"length ==":`Length`,"decimals <=":`DecimalPlaces`,matches:`Matches`,contains:`Contains`,"not contains":`NotContains`,"starts with":`StartsWith`,"ends with":`EndsWith`,"all >":`AllGreaterThan`,"all >=":`AllGreaterThanOrEqual`},q={information:`Information`,warning:`Warning`,error:`Error`},J=/* @__PURE__ */ new Set([`reads`,`concurrency`]),Y=/* @__PURE__ */ new Set([`description`,`documentation`,`handler`,`concurrency`]);function parseCommand(e,t){let n=/* @__PURE__ */ new Set,r=new _(e.reader.fork(),e.path,e.languages);return r.sourceOptions=e.sourceOptions,r.streamCandidates=e.streamCandidates,parseCommandBody(r,t,void 0,n),parseCommandBody(e,t,n)}function parseCommandBody(t,r,c,f){let g=L.exec(r.content)?.[1]??``;g===``&&t.error(e.InvalidCommandDeclaration,`Invalid command declaration '${r.content}' - expected 'command <Name>'`,i(r));let _=[],b=[],S,C=[],w=[],T=[],E=[],O,j=null,M=null,B=null,V=null,H=[],U=null,W=[],K=null;for(let s=t.peekChild(r.indent);s!==void 0;s=t.peekChild(r.indent)){t.reader.takeSignificant();let r=u(s.content),l=p(s);if(r===`calendar`&&ee.test(s.content)){let r=z.exec(s.content);K!==null||r===null?t.error(e.InvalidCommandCalendar,`A command declares at most one 'calendar "<id>"' or 'calendar from $context.<member>'.`,i(s)):K={kind:`CommandCalendarSyntax`,id:r[1]===void 0?null:n(r[1]),contextMember:r[2]??null,location:i(s)}}else if(l!==void 0&&(Y.has(r)||r===`validate`&&s.content!==`validate csharp`))S=addProperty(t,_,l,g,s,S);else if(r===`returns`){let e=A.exec(s.content);e!==null&&!e[1].startsWith(`@`)&&l!==void 0?c===void 0?(_.push(l),b.push({line:s,candidate:l,response:null})):c.has(l.type.name)?b.push({line:s,candidate:null,response:k(t,s)}):S=addProperty(t,_,l,g,s,S):l===void 0?d(t,s)?t.skipBlock(s.indent):b.push({line:s,candidate:null,response:k(t,s)}):S=addProperty(t,_,l,g,s,S)}else if(r===`stream`&&R.test(s.content)&&l!==void 0&&t.streamCandidates?.hasSource(l.type.name.split(`.`)[0])===!0){let[n,r]=l.type.name.split(`.`),a=t.streamCandidates.hasPropertyType(l.type.name)&&t.streamCandidates.hasUniqueStream(n,r),o=x(t,s,l,a);(U!==null||W.length>0)&&t.error(e.InvalidCommandStream,`A command declares at most one stream route.`,i(s)),a||U!==null?W.push(o):U=o}else if(r===`runs`&&v(s))y(t,s);else if(r===`description`)j=m(t,s,j,`Command '${g}'`);else if(r===`documentation`)M=h(t,s,M,`Command '${g}'`);else if(r===`authorize`)B=a(B,o(t,s));else if(r===`validate`){let e=parseValidate(t,s,`command`,g);e!==void 0&&C.push(e)}else if(r===`produces`){let e=I(t,s,!0);e!==void 0&&w.push(e)}else if(r===`handler`)V=D(t,s),H.push({handler:V,location:i(s)});else if(J.has(r)){let n=r===`reads`?F(t,s):void 0;n!==void 0&&E.push(n),r===`concurrency`&&O===void 0&&(O=P(t,s));let a=/^reads\s+([A-Z]\w*)(?:\s+as\s+([a-z_]\w*))?(?:\s+by\s+([a-z_]\w*))?$/.exec(s.content);a!==null&&T.push({readModel:a[1],alias:a[2]??null}),G.test(s.content)&&t.error(e.OptionalReadsNotSupported,`Optional reads are not yet supported (see #308).`,i(s)),t.skipOpaqueBlock(s.indent)}else l===void 0?(d(t,s),t.error(e.UnknownCommandDirective,`Unexpected '${s.content}' in command body`,i(s)),t.skipBlock(s.indent)):S=addProperty(t,_,l,g,s,S)}let q=new Set(b.flatMap(e=>e.candidate===null?[]:[e.candidate])),X=new Set(_.filter(e=>!q.has(e)).map(e=>e.name));b.some(e=>e.candidate!==null&&!X.has(e.candidate.type.name)&&e.candidate.type.name!==`returns`)&&X.add(`returns`);for(let e of X)f?.add(e);let Z=null,Q=/* @__PURE__ */ new Set;for(let n of b){let r=n.response;if(n.candidate!==null){if(!X.has(n.candidate.type.name))continue;Q.add(n.candidate),r={kind:`ScalarCommandResponseSyntax`,source:{kind:`PropertyResponseSourceSyntax`,property:n.candidate.type.name,location:n.candidate.type.location},location:i(n.line)}}r!==null&&(Z===null?Z=r:t.error(e.InvalidCommandResponse,`A command declares at most one unconditional response.`,i(n.line)))}l(H,V,w.length>0,t);let $={kind:`CommandSyntax`,name:g,description:j,documentation:M,authorize:B,properties:_.filter(e=>!Q.has(e)),validations:C,produces:w,handler:V,response:Z,stream:U,streamCandidates:W,...K===null?{}:{calendar:K},location:i(r)};return N.set($,T),s.set($,{reads:E,concurrency:O}),$}function addProperty(t,n,r,i,a,o){return f(t,r.type,a),r.isIdentifier&&o!==void 0&&(t.error(e.DuplicateCommandIdentifier,`Command '${i}' already marks '${o.name}' as identifier - only one property can be the identifier`,r.location),r={...r,isIdentifier:!1}),n.push(r),o??(r.isIdentifier?r:void 0)}function parseValidationFile(e,t,n){let r=E(e,n);return r===void 0?void 0:{kind:`FileValidateSyntax`,file:r,location:i(t)}}function hasValidationOperand(e){let t=H.exec(e.content);if(t===null)return!1;let n=t[2];return u(n)===`not`&&u(n.substring(3).trimStart())===`empty`||u(n)===`checksum`||U.test(n)}function isValidationFileBody(e,t,n){if(!S(n)||hasValidationOperand(n))return!1;let r=e.reader.fork();r.takeSignificant();let i=r.peekSignificant();return i===void 0||i.indent<=t.indent}function parseValidate(t,r,a,o){if(r.content===`validate`){let s=t.peekChild(r.indent);if(s!==void 0&&isValidationFileBody(t,r,s))return t.reader.takeSignificant(),parseValidationFile(t,r,s);if(s!==void 0&&s.content.startsWith("```")){t.reader.takeSignificant();let e=T(t.valueContext,s);return e===null&&t.skipFencedBody(),{kind:`CodeValidateSyntax`,code:e,location:i(r)}}let c=[],l=[],d;for(let s=t.peekChild(r.indent);s!==void 0;s=t.peekChild(r.indent)){if(t.reader.takeSignificant(),a===`concept`){if(t.sourceOptions.numericMode===`legacy`&&s.content.startsWith("```")){t.skipFencedBody();continue}if(d!==void 0&&s.indent<=d&&(d=void 0),d!==void 0||u(s.content)===`implementation`){t.error(e.InvalidValidationRule,`Invalid validation rule '${s.content}'`,i(s)),d??=s.indent;continue}}if(u(s.content)===`require`){let e=g(a===`concept`?t.valueContext:t,s.content.substring(7).trim(),i(s)),r=null,o=`Error`,c=!1;for(let e=t.peekChild(s.indent);e!==void 0;e=t.peekChild(s.indent)){t.reader.takeSignificant();let i=V.exec(e.content);i!==null&&i.index===0?r=i[1]===void 0?i[2]:n(i[1]):u(e.content)===`severity`?(c||(o=q[e.content.substring(8).trim()]??`Error`),c=!0):t.skipOpaqueBlock(e.indent)}e!==null&&l.push({kind:`RequirementSyntax`,condition:e,message:r,severity:o,location:i(s)});continue}let r=parseValidationRule(t,a===`concept`?{...s,content:`value ${s.content}`}:s,a,o);r!==void 0&&c.push(r)}return{kind:`DeclarativeValidateSyntax`,rules:c,requirements:l,location:i(r)}}if(a===`concept`&&u(r.content.substring(8).trimStart())===`checksum`){let e=parseValidationRule(t,{...r,content:`value ${r.content.substring(8).trimStart()}`},a,o);return e===void 0?void 0:{kind:`DeclarativeValidateSyntax`,rules:[e],requirements:[],location:i(r)}}if(r.content===`validate csharp`){let e=T(t.valueContext,{...r,content:`csharp`});return e===null&&t.skipOpaqueBlock(r.indent),{kind:`CodeValidateSyntax`,code:e,location:i(r)}}t.error(e.InvalidValidateDeclaration,`Invalid validate declaration '${r.content}' - expected 'validate' or 'validate csharp'`,i(r)),t.skipBlock(r.indent)}function parseValidationRule(t,n,r,a){let o=u(H.exec(n.content)?.[2]??``)===`checksum`,s=r===`concept`&&!o?t.valueContext:t,{content:c,message:l}=splitMessage(n.content),d=splitSeverity(s,n,c);if(d===void 0)return;let f=H.exec(d.content);if(f===null){s.error(e.InvalidValidationRule,`Invalid validation rule '${n.content}'`,i(n));return}let p=parseRule(s,f[2],n);if(p===void 0)return;p.kind===`Matches`&&p.value!==null&&M(t,p.value,i(n),n.raw,j(t,r,a,f[1]));let m=p.kind===`Rule`?parseRuleImplementation(t,n,r===`command`):{file:null,code:null,implementation:null};return{kind:`ValidationRuleSyntax`,property:f[1],rule:p.kind,value:p.value,message:l,severity:d.severity,...m,location:i(n)}}function parseRuleImplementation(t,n,r){let a=t.peekChild(n.indent);if(a===void 0)return{file:null,code:null,implementation:null};t.reader.takeSignificant();let o=r&&u(a.content)===`implementation`,s=o?O(t,a):{file:w(a)?E(t,a):null,code:!w(a)&&C(t,a)?T(t,a):null,implementation:null};!o&&s.file===null&&s.code===null&&(t.error(e.UnknownRuleImplementationDirective,`Unexpected '${a.content}' in rule implementation - expected 'file <path>' or an inline code block`,i(a)),t.skipBlock(a.indent));for(let a=t.peekChild(n.indent);a!==void 0&&(o||r&&u(a.content)===`implementation`);a=t.peekChild(n.indent))t.reader.takeSignificant(),t.error(o&&u(a.content)===`implementation`?e.InvalidImplementationBlock:e.ConflictingImplementationSources,`A named rule has one implementation wrapper and cannot mix wrapped and direct sources.`,i(a)),C(t,a)?T(t,a):t.skipBlock(a.indent);return s}function splitMessage(e){let t=V.exec(e);if(t===null)return{content:e,message:null};let r=t[1]===void 0?t[2]:n(t[1]);return{content:e.substring(0,t.index).trimEnd(),message:r}}function splitSeverity(t,n,r){let a=B.exec(r);if(a===null)return{content:r,severity:`Error`};let o=q[a[1]];if(o===void 0)t.error(e.InvalidValidationSeverity,`Unknown validation severity '${a[1]}' - expected information, warning or error`,i(n));else return{content:r.substring(0,a.index).trimEnd(),severity:o}}function parseRule(t,n,r){if(n===`not empty`)return{kind:`NotEmpty`,value:null};if(u(n)===`checksum`){let a=n.substring(8).trim();if(a!==`luhn`&&a!==`mod11`&&a!==`mod97`){t.error(e.InvalidGenerationArgument,`Checksum validation requires luhn, mod11 or mod97.`,i(r));return}return{kind:`Checksum`,value:{kind:`LiteralExpressionSyntax`,value:a,location:i(r)}}}let a=U.exec(n);if(a===null){t.error(e.InvalidValidationRule,`Invalid validation rule '${r.content}'`,i(r));return}let o=a[1]??a[2];if(o===`rule`){let n=a[3].trim();if(!W.test(n)){t.error(e.InvalidRuleName,`Invalid rule name '${n}' in '${r.content}' - expected 'rule <Name>' with an identifier`,i(r));return}return{kind:`Rule`,value:{kind:`PathExpressionSyntax`,path:n,location:i(r)}}}return{kind:K[o],value:c(a[3],i(r),t)}}export{parseCommand,parseValidate};
|
|
2
2
|
//# sourceMappingURL=CommandParser.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandParser.js","names":["header","pattern","routeHeader","sourceStreamPattern","calendarPrefix","calendarPattern","stringBodyPattern","severityPattern","messagePattern","rulePattern","operandPattern","ruleNamePattern","optionalReads","operandKinds","severities","opaqueDirectives","propertyShapedDirectives","names","lookahead","ParserContext","context","line","name","DiagnosticCodes","locationOf","properties","responses","identifier","validations","produces","reads","referenceReads","concurrency","description","documentation","authorize","handler","handlers","stream","streamCandidates","calendar","child","keyword","firstWord","asProperty","tryParseProperty","match","unescapeString","scalar","scalarResponsePattern","responseNames","parseCommandResponse","reportInvalidModifierOrder","source","streamName","ambiguous","route","parseCommandStream","isReactionIdentityLine","misplacedReactionIdentity","parseDescription","parseDocumentation","combineAuthorize","parseAuthorize","validate","production","parseProduces","parseHandler","reference","parseReads","captureConcurrency","read","candidates","entry","property","discoveredNames","response","removed","parsed","validateHandlerContracts","syntax","commandReadSources","dependencySources","reportLegacyOptionalSuffix","commandName","file","parseFile","body","rule","isFileDirectiveAmongProperties","next","fence","code","parseCode","rules","requirements","wrapperIndent","owner","condition","parseCondition","message","severity","hasSeverity","directive","matched","ownerName","checksum","valueContext","withSeverity","validateMatchOperand","matchSubject","wrapped","commandOwner","parseImplementationWrapper","isFile","isCode","extra","content","text","algorithm","operand","operator","parseMappingSource"],"sources":["../../../../../../Compiler/Parsing/CommandParser.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { DiagnosticCodes } from '../Diagnostics/DiagnosticCodes';\nimport { validateHandlerContracts } from './CommandHandlerValidator';\nimport { SourceLocation } from '../Diagnostics/SourceLocation';\nimport { RequirementSyntax } from '../Syntax/Conditions';\nimport { parseCondition } from './ConditionParser';\nimport { AuthorizeSyntax } from '../Syntax/Authorization';\nimport { CommandSyntax, ValidateSyntax, ValidationRuleKind, ValidationRuleSyntax, ValidationSeverity } from '../Syntax/Commands';\nimport { PropertySyntax } from '../Syntax/Declarations';\nimport { CommandCalendarSyntax } from '../Syntax/Calendar';\nimport { CommandStreamSyntax } from '../Syntax/EventSources';\nimport { parseCommandStream } from './EventSourceParser';\nimport { ExpressionSyntax } from '../Syntax/Expressions';\nimport { ProducesSyntax } from '../Syntax/Reactions';\nimport { CommandResponseSyntax } from '../Syntax/Responses';\nimport { pattern } from '../Text/patterns';\nimport { sourceStreamPattern } from '../Text/SourceStreamNames';\nimport { stringBodyPattern, unescapeString } from '../Text/StringLiteral';\nimport { combineAuthorize, parseAuthorize } from './AuthorizeParser';\nimport { parseCommandResponse, scalarResponsePattern } from './CommandResponseParser';\nimport { parseDescription } from './DescriptionParser';\nimport { parseDocumentation } from './DocumentationParser';\nimport { isCode, isFile, parseCode, parseFile, parseHandler, parseImplementationWrapper } from './ImplementationParser';\nimport { CodeBlockSyntax, FileReferenceSyntax, HandlerSyntax, ImplementationSyntax } from '../Syntax/Implementations';\nimport { parseMappingSource } from './ExpressionParser';\nimport { firstWord } from './LineText';\nimport { ParserContext } from './ParserContext';\nimport { matchSubject, validateMatchOperand } from './MatchOperandValidation';\nimport { isReactionIdentityLine, misplacedReactionIdentity } from './ReactionIdentityParser';\nimport { commandReadSources } from './CommandReadSources';\nimport { dependencySources, ReadsSyntax, ConcurrencySyntax } from '../Syntax/DependencySources';\nimport { captureConcurrency } from './DependencySourceParser';\nimport { parseReads } from './ReadsParser';\nimport { parseProduces } from './ProducesParser';\nimport { reportInvalidModifierOrder, reportLegacyOptionalSuffix, tryParseProperty } from './PropertyLineParser';\nimport { locationOf, SourceLine } from './SourceLine';\nimport { isFileDirectiveAmongProperties } from './FileReferences';\n\nconst header = pattern('^command\\\\s+([A-Za-z_]\\\\w*)$');\nconst routeHeader = sourceStreamPattern('^stream\\\\s+[A-Za-z_]\\\\w*\\\\.[A-Za-z_]\\\\w*$');\nconst calendarPrefix = pattern('^calendar\\\\s+(?:\"|from\\\\s+\\\\$context\\\\.)');\nconst calendarPattern = pattern(`^calendar\\\\s+(?:\"(${stringBodyPattern})\"|from\\\\s+\\\\$context\\\\.([A-Za-z_][A-Za-z0-9_]*(?:\\\\.[A-Za-z_][A-Za-z0-9_]*)*))$`);\nconst severityPattern = pattern('\\\\bseverity\\\\s+(\\\\S+)$');\nconst messagePattern = pattern(`\\\\bmessage\\\\s+(?:\"(${stringBodyPattern})\"|(\\\\$strings\\\\.\\\\S*))$`);\nconst rulePattern = pattern('^([\\\\w.]+)\\\\s+(.+)$');\nconst operandPattern = pattern('^(?:(not empty|matches|not contains|contains|starts with|ends with|max|min|rule)(?:\\\\s+|$)|(length ==|decimals <=|all >=|all >|>=|<=|==|!=|>|<)\\\\s*)(.*)$');\nconst ruleNamePattern = sourceStreamPattern('^[A-Za-z_]\\\\w*$');\nconst optionalReads = pattern('^reads\\\\s+[A-Z]\\\\w*\\\\s+optional(?:\\\\s|$)');\n\n// Every operand the pattern matches has a kind, so an operand never goes unrecognized here.\nconst operandKinds: Record<string, ValidationRuleKind> = {\n max: 'Max',\n min: 'Min',\n '>': 'GreaterThan',\n '>=': 'GreaterThanOrEqual',\n '<': 'LessThan',\n '<=': 'LessThanOrEqual',\n '==': 'Equal',\n '!=': 'NotEqual',\n 'length ==': 'Length',\n 'decimals <=': 'DecimalPlaces',\n matches: 'Matches',\n contains: 'Contains',\n 'not contains': 'NotContains',\n 'starts with': 'StartsWith',\n 'ends with': 'EndsWith',\n 'all >': 'AllGreaterThan',\n 'all >=': 'AllGreaterThanOrEqual',\n};\n\nconst severities: Record<string, ValidationSeverity> = { information: 'Information', warning: 'Warning', error: 'Error' };\n\n// Command directives this compiler does not model. They are skipped whole.\nconst opaqueDirectives = new Set(['reads', 'concurrency']);\n\n// The bare directives cannot take a type reference, so a line with property shape is a property whatever\n// keyword it starts with - 'description String' declares a property called description.\nconst propertyShapedDirectives = new Set(['description', 'documentation', 'handler', 'concurrency']);\n\nexport function parseCommand(context: ParserContext, line: SourceLine): CommandSyntax {\n // Properties are leaves, not indentation owners. Resolve ambiguous returns spelling\n // before the committed pass decides whether its deeper lines belong to a response.\n const names = new Set<string>();\n const lookahead = new ParserContext(context.reader.fork(), context.path, context.languages);\n lookahead.sourceOptions = context.sourceOptions;\n lookahead.streamCandidates = context.streamCandidates;\n parseCommandBody(lookahead, line, undefined, names);\n return parseCommandBody(context, line, names);\n}\n\nfunction parseCommandBody(context: ParserContext, line: SourceLine, responseNames?: ReadonlySet<string>, discoveredNames?: Set<string>): CommandSyntax {\n const name = header.exec(line.content)?.[1] ?? '';\n if (name === '') {\n context.error(DiagnosticCodes.InvalidCommandDeclaration, `Invalid command declaration '${line.content}' - expected 'command <Name>'`, locationOf(line));\n }\n const properties: PropertySyntax[] = [];\n const responses: { line: SourceLine; candidate: PropertySyntax | null; response: CommandResponseSyntax | null }[] = [];\n let identifier: PropertySyntax | undefined;\n const validations: ValidateSyntax[] = [];\n const produces: ProducesSyntax[] = [];\n const reads: { readModel: string; alias: string | null }[] = [];\n const referenceReads: ReadsSyntax[] = [];\n let concurrency: ConcurrencySyntax | undefined;\n let description: string | null = null;\n let documentation: string | null = null;\n let authorize: AuthorizeSyntax | null = null;\n let handler: HandlerSyntax | null = null;\n const handlers: { handler: HandlerSyntax | null; location: SourceLocation }[] = [];\n let stream: CommandStreamSyntax | null = null;\n const streamCandidates: CommandStreamSyntax[] = [];\n let calendar: CommandCalendarSyntax | null = null;\n for (let child = context.peekChild(line.indent); child !== undefined; child = context.peekChild(line.indent)) {\n context.reader.takeSignificant();\n const keyword = firstWord(child.content);\n const asProperty = tryParseProperty(child);\n if (keyword === 'calendar' && calendarPrefix.test(child.content)) {\n const match = calendarPattern.exec(child.content);\n if (calendar !== null || match === null) {\n context.error(DiagnosticCodes.InvalidCommandCalendar, 'A command declares at most one \\'calendar \"<id>\"\\' or \\'calendar from $context.<member>\\'.', locationOf(child));\n } else {\n calendar = { kind: 'CommandCalendarSyntax', id: match[1] === undefined ? null : unescapeString(match[1]), contextMember: match[2] ?? null, location: locationOf(child) };\n }\n } else if (asProperty !== undefined && (propertyShapedDirectives.has(keyword) || (keyword === 'validate' && child.content !== 'validate csharp'))) {\n identifier = addProperty(context, properties, asProperty, name, child, identifier);\n } else if (keyword === 'returns') {\n const scalar = scalarResponsePattern.exec(child.content);\n if (scalar !== null && !scalar[1].startsWith('@') && asProperty !== undefined) {\n if (responseNames === undefined) {\n properties.push(asProperty);\n responses.push({ line: child, candidate: asProperty, response: null });\n } else if (responseNames.has(asProperty.type.name)) {\n responses.push({ line: child, candidate: null, response: parseCommandResponse(context, child) });\n } else {\n identifier = addProperty(context, properties, asProperty, name, child, identifier);\n }\n } else if (asProperty !== undefined) {\n identifier = addProperty(context, properties, asProperty, name, child, identifier);\n } else if (reportInvalidModifierOrder(context, child)) {\n context.skipBlock(child.indent);\n } else {\n responses.push({ line: child, candidate: null, response: parseCommandResponse(context, child) });\n }\n } else if (keyword === 'stream' && routeHeader.test(child.content) && asProperty !== undefined && context.streamCandidates?.hasSource(asProperty.type.name.split('.')[0]) === true) {\n const [source, streamName] = asProperty.type.name.split('.');\n const ambiguous = context.streamCandidates.hasPropertyType(asProperty.type.name) && context.streamCandidates.hasUniqueStream(source, streamName);\n const route = parseCommandStream(context, child, asProperty, ambiguous);\n if (stream !== null || streamCandidates.length > 0) context.error(DiagnosticCodes.InvalidCommandStream, 'A command declares at most one stream route.', locationOf(child));\n if (ambiguous || stream !== null) streamCandidates.push(route);\n else stream = route;\n } else if (keyword === 'runs' && isReactionIdentityLine(child)) {\n misplacedReactionIdentity(context, child);\n } else if (keyword === 'description') {\n description = parseDescription(context, child, description, `Command '${name}'`);\n } else if (keyword === 'documentation') {\n documentation = parseDocumentation(context, child, documentation, `Command '${name}'`);\n } else if (keyword === 'authorize') {\n authorize = combineAuthorize(authorize, parseAuthorize(context, child));\n } else if (keyword === 'validate') {\n const validate = parseValidate(context, child, 'command', name);\n if (validate !== undefined) {\n validations.push(validate);\n }\n } else if (keyword === 'produces') {\n const production = parseProduces(context, child, true);\n if (production !== undefined) produces.push(production);\n } else if (keyword === 'handler') {\n handler = parseHandler(context, child);\n handlers.push({ handler, location: locationOf(child) });\n } else if (opaqueDirectives.has(keyword)) {\n const reference = keyword === 'reads' ? parseReads(context, child) : undefined;\n if (reference !== undefined) referenceReads.push(reference);\n if (keyword === 'concurrency' && concurrency === undefined) concurrency = captureConcurrency(context, child);\n const read = /^reads\\s+([A-Z]\\w*)(?:\\s+as\\s+([a-z_]\\w*))?(?:\\s+by\\s+([a-z_]\\w*))?$/.exec(child.content);\n if (read !== null) reads.push({ readModel: read[1], alias: read[2] ?? null });\n if (optionalReads.test(child.content)) {\n context.error(DiagnosticCodes.OptionalReadsNotSupported, 'Optional reads are not yet supported (see #308).', locationOf(child));\n }\n context.skipOpaqueBlock(child.indent);\n } else if (asProperty !== undefined) {\n identifier = addProperty(context, properties, asProperty, name, child, identifier);\n } else {\n reportInvalidModifierOrder(context, child);\n context.error(DiagnosticCodes.UnknownCommandDirective, `Unexpected '${child.content}' in command body`, locationOf(child));\n context.skipBlock(child.indent);\n }\n }\n const candidates = new Set(responses.flatMap(entry => entry.candidate === null ? [] : [entry.candidate]));\n const names = new Set(properties.filter(property => !candidates.has(property)).map(property => property.name));\n if (responses.some(entry => entry.candidate !== null && !names.has(entry.candidate.type.name) && entry.candidate.type.name !== 'returns')) names.add('returns');\n for (const name of names) discoveredNames?.add(name);\n let response: CommandResponseSyntax | null = null;\n const removed = new Set<PropertySyntax>();\n for (const entry of responses) {\n let parsed = entry.response;\n if (entry.candidate !== null) {\n if (!names.has(entry.candidate.type.name)) continue;\n removed.add(entry.candidate);\n parsed = { kind: 'ScalarCommandResponseSyntax', source: { kind: 'PropertyResponseSourceSyntax', property: entry.candidate.type.name, location: entry.candidate.type.location }, location: locationOf(entry.line) };\n }\n if (parsed === null) continue;\n if (response !== null) {\n context.error(DiagnosticCodes.InvalidCommandResponse, 'A command declares at most one unconditional response.', locationOf(entry.line));\n } else {\n response = parsed;\n }\n }\n validateHandlerContracts(handlers, handler, produces.length > 0, context);\n const syntax: CommandSyntax = { kind: 'CommandSyntax', name, description, documentation, authorize, properties: properties.filter(property => !removed.has(property)), validations, produces, handler, response, stream, streamCandidates, ...(calendar === null ? {} : { calendar }), location: locationOf(line) };\n commandReadSources.set(syntax, reads);\n dependencySources.set(syntax, { reads: referenceReads, concurrency });\n return syntax;\n}\n\nfunction addProperty(context: ParserContext, properties: PropertySyntax[], property: PropertySyntax, commandName: string, line: SourceLine, identifier: PropertySyntax | undefined): PropertySyntax | undefined {\n reportLegacyOptionalSuffix(context, property.type, line);\n if (property.isIdentifier && identifier !== undefined) {\n context.error(DiagnosticCodes.DuplicateCommandIdentifier, `Command '${commandName}' already marks '${identifier.name}' as identifier - only one property can be the identifier`, property.location);\n property = { ...property, isIdentifier: false };\n }\n properties.push(property);\n return identifier ?? (property.isIdentifier ? property : undefined);\n}\n\nfunction parseValidationFile(context: ParserContext, header: SourceLine, body: SourceLine): ValidateSyntax | undefined {\n const file = parseFile(context, body);\n return file === undefined ? undefined : { kind: 'FileValidateSyntax', file, location: locationOf(header) };\n}\n\nfunction hasValidationOperand(line: SourceLine): boolean {\n const match = rulePattern.exec(line.content);\n if (match === null) return false;\n const rule = match[2];\n return (firstWord(rule) === 'not' && firstWord(rule.substring('not'.length).trimStart()) === 'empty') ||\n firstWord(rule) === 'checksum' || operandPattern.test(rule);\n}\n\nfunction isValidationFileBody(context: ParserContext, header: SourceLine, body: SourceLine): boolean {\n if (!isFileDirectiveAmongProperties(body) || hasValidationOperand(body)) return false;\n const lookahead = context.reader.fork();\n lookahead.takeSignificant();\n const next = lookahead.peekSignificant();\n return next === undefined || next.indent <= header.indent;\n}\n\n// Reads a 'validate' block: declarative rules, or code - which is recognized but not modeled.\nexport function parseValidate(context: ParserContext, line: SourceLine, owner: 'command' | 'concept', ownerName: string): ValidateSyntax | undefined {\n if (line.content === 'validate') {\n const fence = context.peekChild(line.indent);\n if (fence !== undefined && isValidationFileBody(context, line, fence)) {\n context.reader.takeSignificant();\n return parseValidationFile(context, line, fence);\n }\n if (fence !== undefined && fence.content.startsWith('```')) {\n context.reader.takeSignificant();\n const code = parseCode(context.valueContext, fence);\n if (code === null) context.skipFencedBody();\n return { kind: 'CodeValidateSyntax', code, location: locationOf(line) };\n }\n const rules: ValidationRuleSyntax[] = [];\n const requirements: RequirementSyntax[] = [];\n let wrapperIndent: number | undefined;\n for (let child = context.peekChild(line.indent); child !== undefined; child = context.peekChild(line.indent)) {\n context.reader.takeSignificant();\n if (owner === 'concept') {\n if (context.sourceOptions.numericMode === 'legacy' && child.content.startsWith('```')) { context.skipFencedBody(); continue; }\n if (wrapperIndent !== undefined && child.indent <= wrapperIndent) wrapperIndent = undefined;\n if (wrapperIndent !== undefined || firstWord(child.content) === 'implementation') {\n context.error(DiagnosticCodes.InvalidValidationRule, `Invalid validation rule '${child.content}'`, locationOf(child));\n wrapperIndent ??= child.indent;\n continue;\n }\n }\n if (firstWord(child.content) === 'require') {\n const condition = parseCondition(owner === 'concept' ? context.valueContext : context, child.content.substring('require'.length).trim(), locationOf(child));\n let message: string | null = null;\n let severity: ValidationSeverity = 'Error';\n let hasSeverity = false;\n for (let directive = context.peekChild(child.indent); directive !== undefined; directive = context.peekChild(child.indent)) {\n context.reader.takeSignificant();\n const matched = messagePattern.exec(directive.content);\n if (matched !== null && matched.index === 0) message = matched[1] !== undefined ? unescapeString(matched[1]) : matched[2];\n else if (firstWord(directive.content) === 'severity') {\n if (!hasSeverity) severity = severities[directive.content.substring('severity'.length).trim()] ?? 'Error';\n hasSeverity = true;\n } else context.skipOpaqueBlock(directive.indent);\n }\n if (condition !== null) requirements.push({ kind: 'RequirementSyntax', condition, message, severity, location: locationOf(child) });\n continue;\n }\n const rule = parseValidationRule(context, owner === 'concept' ? { ...child, content: `value ${child.content}` } : child, owner, ownerName);\n if (rule !== undefined) {\n rules.push(rule);\n }\n }\n return { kind: 'DeclarativeValidateSyntax', rules, requirements, location: locationOf(line) };\n }\n if (owner === 'concept' && firstWord(line.content.substring('validate'.length).trimStart()) === 'checksum') {\n const ruleLine = { ...line, content: `value ${line.content.substring('validate'.length).trimStart()}` };\n const rule = parseValidationRule(context, ruleLine, owner, ownerName);\n return rule === undefined ? undefined : { kind: 'DeclarativeValidateSyntax', rules: [rule], requirements: [], location: locationOf(line) };\n }\n if (line.content === 'validate csharp') {\n const code = parseCode(context.valueContext, { ...line, content: 'csharp' });\n if (code === null) context.skipOpaqueBlock(line.indent);\n return { kind: 'CodeValidateSyntax', code, location: locationOf(line) };\n }\n context.error(DiagnosticCodes.InvalidValidateDeclaration, `Invalid validate declaration '${line.content}' - expected 'validate' or 'validate csharp'`, locationOf(line));\n context.skipBlock(line.indent);\n return undefined;\n}\n\nfunction parseValidationRule(context: ParserContext, line: SourceLine, owner: 'command' | 'concept', ownerName: string): ValidationRuleSyntax | undefined {\n // Checksum is a new declaration, not enrichment of a formerly opaque Legacy rule.\n const checksum = firstWord(rulePattern.exec(line.content)?.[2] ?? '') === 'checksum';\n const valueContext = owner === 'concept' && !checksum ? context.valueContext : context;\n const { content: withSeverity, message } = splitMessage(line.content);\n const severity = splitSeverity(valueContext, line, withSeverity);\n if (severity === undefined) {\n return undefined;\n }\n const match = rulePattern.exec(severity.content);\n if (match === null) {\n valueContext.error(DiagnosticCodes.InvalidValidationRule, `Invalid validation rule '${line.content}'`, locationOf(line));\n return undefined;\n }\n const parsed = parseRule(valueContext, match[2], line);\n if (parsed === undefined) {\n return undefined;\n }\n if (parsed.kind === 'Matches' && parsed.value !== null) validateMatchOperand(context, parsed.value, locationOf(line), line.raw, matchSubject(context, owner, ownerName, match[1]));\n const source = parsed.kind === 'Rule' ? parseRuleImplementation(context, line, owner === 'command') : { file: null, code: null, implementation: null };\n return {\n kind: 'ValidationRuleSyntax',\n property: match[1],\n rule: parsed.kind,\n value: parsed.value,\n message,\n severity: severity.severity,\n ...source,\n location: locationOf(line),\n };\n}\n\nfunction parseRuleImplementation(context: ParserContext, rule: SourceLine, commandOwner: boolean): { file: FileReferenceSyntax | null; code: CodeBlockSyntax | null; implementation: ImplementationSyntax | null } {\n const body = context.peekChild(rule.indent);\n if (body === undefined) return { file: null, code: null, implementation: null };\n context.reader.takeSignificant();\n const wrapped = commandOwner && firstWord(body.content) === 'implementation';\n const source = wrapped ? parseImplementationWrapper(context, body) : {\n file: isFile(body) ? parseFile(context, body) : null,\n code: !isFile(body) && isCode(context, body) ? parseCode(context, body) : null,\n implementation: null,\n };\n if (!wrapped && source.file === null && source.code === null) {\n context.error(DiagnosticCodes.UnknownRuleImplementationDirective, `Unexpected '${body.content}' in rule implementation - expected 'file <path>' or an inline code block`, locationOf(body));\n context.skipBlock(body.indent);\n }\n for (let extra = context.peekChild(rule.indent); extra !== undefined && (wrapped || (commandOwner && firstWord(extra.content) === 'implementation')); extra = context.peekChild(rule.indent)) {\n context.reader.takeSignificant();\n context.error(wrapped && firstWord(extra.content) === 'implementation' ? DiagnosticCodes.InvalidImplementationBlock : DiagnosticCodes.ConflictingImplementationSources,\n 'A named rule has one implementation wrapper and cannot mix wrapped and direct sources.', locationOf(extra));\n if (isCode(context, extra)) parseCode(context, extra);\n else context.skipBlock(extra.indent);\n }\n return source;\n}\n\nfunction splitMessage(content: string): { content: string; message: string | null } {\n const match = messagePattern.exec(content);\n if (match === null) {\n return { content, message: null };\n }\n const message = match[1] !== undefined ? unescapeString(match[1]) : match[2];\n return { content: content.substring(0, match.index).trimEnd(), message };\n}\n\nfunction splitSeverity(context: ParserContext, line: SourceLine, text: string): { content: string; severity: ValidationSeverity } | undefined {\n const match = severityPattern.exec(text);\n if (match === null) {\n return { content: text, severity: 'Error' };\n }\n const severity = severities[match[1]];\n if (severity === undefined) {\n context.error(DiagnosticCodes.InvalidValidationSeverity, `Unknown validation severity '${match[1]}' - expected information, warning or error`, locationOf(line));\n return undefined;\n }\n return { content: text.substring(0, match.index).trimEnd(), severity };\n}\n\nfunction parseRule(context: ParserContext, rule: string, line: SourceLine): { kind: ValidationRuleKind; value: ExpressionSyntax | null } | undefined {\n if (rule === 'not empty') {\n return { kind: 'NotEmpty', value: null };\n }\n if (firstWord(rule) === 'checksum') {\n const algorithm = rule.substring('checksum'.length).trim();\n if (algorithm !== 'luhn' && algorithm !== 'mod11' && algorithm !== 'mod97') {\n context.error(DiagnosticCodes.InvalidGenerationArgument, 'Checksum validation requires luhn, mod11 or mod97.', locationOf(line));\n return undefined;\n }\n return { kind: 'Checksum', value: { kind: 'LiteralExpressionSyntax', value: algorithm, location: locationOf(line) } };\n }\n const operand = operandPattern.exec(rule);\n if (operand === null) {\n context.error(DiagnosticCodes.InvalidValidationRule, `Invalid validation rule '${line.content}'`, locationOf(line));\n return undefined;\n }\n const operator = operand[1] ?? operand[2];\n if (operator === 'rule') {\n const name = operand[3].trim();\n if (!ruleNamePattern.test(name)) {\n context.error(DiagnosticCodes.InvalidRuleName, `Invalid rule name '${name}' in '${line.content}' - expected 'rule <Name>' with an identifier`, locationOf(line));\n return undefined;\n }\n return { kind: 'Rule', value: { kind: 'PathExpressionSyntax', path: name, location: locationOf(line) } };\n }\n return { kind: operandKinds[operator], value: parseMappingSource(operand[3], locationOf(line), context) };\n}\n"],"mappings":"swDAwCA,MAAMA,EAASC,EAAQ,8BAA8B,EAC/CC,EAAcC,EAAoB,2CAA2C,EAC7EC,EAAiBH,EAAQ,0CAA0C,EACnEI,EAAkBJ,EAAQ,qBAAqBK,EAAkB,iFAAiF,EAClJC,EAAkBN,EAAQ,wBAAwB,EAClDO,EAAiBP,EAAQ,sBAAsBK,EAAkB,yBAAyB,EAC1FG,EAAcR,EAAQ,qBAAqB,EAC3CS,EAAiBT,EAAQ,2JAA2J,EACpLU,EAAkBR,EAAoB,iBAAiB,EACvDS,EAAgBX,EAAQ,0CAA0C,EAGlEY,EAAmD,CACrD,IAAK,MACL,IAAK,MACL,IAAK,cACL,KAAM,qBACN,IAAK,WACL,KAAM,kBACN,KAAM,QACN,KAAM,WACN,YAAa,SACb,cAAe,gBACf,QAAS,UACT,SAAU,WACV,eAAgB,cAChB,cAAe,aACf,YAAa,WACb,QAAS,iBACT,SAAU,uBACd,EAEMC,EAAiD,CAAE,YAAa,cAAe,QAAS,UAAW,MAAO,OAAQ,EAGlHC,kBAAmB,IAAI,IAAI,CAAC,QAAS,aAAa,CAAC,EAInDC,mBAA2B,IAAI,IAAI,CAAC,cAAe,gBAAiB,UAAW,aAAa,CAAC,EAEnG,SAAgB,aAAa,EAAwB,EAAiC,CAGlF,IAAMC,kBAAQ,IAAI,IACZC,EAAY,IAAIC,EAAcC,EAAQ,OAAO,KAAK,EAAGA,EAAQ,KAAMA,EAAQ,SAAS,EAI1F,MAHA,GAAU,cAAgBA,EAAQ,cAClC,EAAU,iBAAmBA,EAAQ,iBACrC,iBAAiBF,EAAWG,EAAM,IAAA,GAAWJ,CAAK,EAC3C,iBAAiBG,EAASC,EAAMJ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
+
{"version":3,"file":"CommandParser.js","names":["header","pattern","routeHeader","sourceStreamPattern","calendarPrefix","calendarPattern","stringBodyPattern","severityPattern","messagePattern","rulePattern","operandPattern","ruleNamePattern","optionalReads","operandKinds","severities","opaqueDirectives","propertyShapedDirectives","names","lookahead","ParserContext","context","line","name","DiagnosticCodes","locationOf","properties","responses","identifier","validations","produces","reads","referenceReads","concurrency","description","documentation","authorize","handler","handlers","stream","streamCandidates","calendar","child","keyword","firstWord","asProperty","tryParseProperty","match","unescapeString","scalar","scalarResponsePattern","responseNames","parseCommandResponse","reportInvalidModifierOrder","source","streamName","ambiguous","route","parseCommandStream","isReactionIdentityLine","misplacedReactionIdentity","parseDescription","parseDocumentation","combineAuthorize","parseAuthorize","validate","production","parseProduces","parseHandler","reference","parseReads","captureConcurrency","read","candidates","entry","property","discoveredNames","response","removed","parsed","validateHandlerContracts","syntax","commandReadSources","dependencySources","reportLegacyOptionalSuffix","commandName","file","parseFile","body","rule","isFileDirectiveAmongProperties","next","fence","code","parseCode","rules","requirements","wrapperIndent","owner","condition","parseCondition","message","severity","hasSeverity","directive","matched","ownerName","checksum","valueContext","withSeverity","validateMatchOperand","matchSubject","wrapped","commandOwner","parseImplementationWrapper","isFile","isCode","extra","content","text","algorithm","operand","operator","parseMappingSource"],"sources":["../../../../../../Compiler/Parsing/CommandParser.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { DiagnosticCodes } from '../Diagnostics/DiagnosticCodes';\nimport { validateHandlerContracts } from './CommandHandlerValidator';\nimport { SourceLocation } from '../Diagnostics/SourceLocation';\nimport { RequirementSyntax } from '../Syntax/Conditions';\nimport { parseCondition } from './ConditionParser';\nimport { AuthorizeSyntax } from '../Syntax/Authorization';\nimport { CommandSyntax, ValidateSyntax, ValidationRuleKind, ValidationRuleSyntax, ValidationSeverity } from '../Syntax/Commands';\nimport { PropertySyntax } from '../Syntax/Declarations';\nimport { CommandCalendarSyntax } from '../Syntax/Calendar';\nimport { CommandStreamSyntax } from '../Syntax/EventSources';\nimport { parseCommandStream } from './EventSourceParser';\nimport { ExpressionSyntax } from '../Syntax/Expressions';\nimport { ProducesSyntax } from '../Syntax/Reactions';\nimport { CommandResponseSyntax } from '../Syntax/Responses';\nimport { pattern } from '../Text/patterns';\nimport { sourceStreamPattern } from '../Text/SourceStreamNames';\nimport { stringBodyPattern, unescapeString } from '../Text/StringLiteral';\nimport { combineAuthorize, parseAuthorize } from './AuthorizeParser';\nimport { parseCommandResponse, scalarResponsePattern } from './CommandResponseParser';\nimport { parseDescription } from './DescriptionParser';\nimport { parseDocumentation } from './DocumentationParser';\nimport { isCode, isFile, parseCode, parseFile, parseHandler, parseImplementationWrapper } from './ImplementationParser';\nimport { CodeBlockSyntax, FileReferenceSyntax, HandlerSyntax, ImplementationSyntax } from '../Syntax/Implementations';\nimport { parseMappingSource } from './ExpressionParser';\nimport { firstWord } from './LineText';\nimport { ParserContext } from './ParserContext';\nimport { matchSubject, validateMatchOperand } from './MatchOperandValidation';\nimport { isReactionIdentityLine, misplacedReactionIdentity } from './ReactionIdentityParser';\nimport { commandReadSources } from './CommandReadSources';\nimport { dependencySources, ReadsSyntax, ConcurrencySyntax } from '../Syntax/DependencySources';\nimport { captureConcurrency } from './DependencySourceParser';\nimport { parseReads } from './ReadsParser';\nimport { parseProduces } from './ProducesParser';\nimport { reportInvalidModifierOrder, reportLegacyOptionalSuffix, tryParseProperty } from './PropertyLineParser';\nimport { locationOf, SourceLine } from './SourceLine';\nimport { isFileDirectiveAmongProperties } from './FileReferences';\n\nconst header = pattern('^command\\\\s+([A-Za-z_]\\\\w*)$');\nconst routeHeader = sourceStreamPattern('^stream\\\\s+[A-Za-z_]\\\\w*\\\\.[A-Za-z_]\\\\w*$');\nconst calendarPrefix = pattern('^calendar\\\\s+(?:\"|from\\\\s+\\\\$context\\\\.)');\nconst calendarPattern = pattern(`^calendar\\\\s+(?:\"(${stringBodyPattern})\"|from\\\\s+\\\\$context\\\\.([A-Za-z_][A-Za-z0-9_]*(?:\\\\.[A-Za-z_][A-Za-z0-9_]*)*))$`);\nconst severityPattern = pattern('\\\\bseverity\\\\s+(\\\\S+)$');\nconst messagePattern = pattern(`\\\\bmessage\\\\s+(?:\"(${stringBodyPattern})\"|(\\\\$strings\\\\.\\\\S*))$`);\nconst rulePattern = pattern('^([\\\\w.]+)\\\\s+(.+)$');\nconst operandPattern = pattern('^(?:(not empty|matches|not contains|contains|starts with|ends with|max|min|rule)(?:\\\\s+|$)|(length ==|decimals <=|all >=|all >|>=|<=|==|!=|>|<)\\\\s*)(.*)$');\nconst ruleNamePattern = sourceStreamPattern('^[A-Za-z_]\\\\w*$');\nconst optionalReads = pattern('^reads\\\\s+[A-Z]\\\\w*\\\\s+optional(?:\\\\s|$)');\n\n// Every operand the pattern matches has a kind, so an operand never goes unrecognized here.\nconst operandKinds: Record<string, ValidationRuleKind> = {\n max: 'Max',\n min: 'Min',\n '>': 'GreaterThan',\n '>=': 'GreaterThanOrEqual',\n '<': 'LessThan',\n '<=': 'LessThanOrEqual',\n '==': 'Equal',\n '!=': 'NotEqual',\n 'length ==': 'Length',\n 'decimals <=': 'DecimalPlaces',\n matches: 'Matches',\n contains: 'Contains',\n 'not contains': 'NotContains',\n 'starts with': 'StartsWith',\n 'ends with': 'EndsWith',\n 'all >': 'AllGreaterThan',\n 'all >=': 'AllGreaterThanOrEqual',\n};\n\nconst severities: Record<string, ValidationSeverity> = { information: 'Information', warning: 'Warning', error: 'Error' };\n\n// Command directives this compiler does not model. They are skipped whole.\nconst opaqueDirectives = new Set(['reads', 'concurrency']);\n\n// The bare directives cannot take a type reference, so a line with property shape is a property whatever\n// keyword it starts with - 'description String' declares a property called description.\nconst propertyShapedDirectives = new Set(['description', 'documentation', 'handler', 'concurrency']);\n\nexport function parseCommand(context: ParserContext, line: SourceLine): CommandSyntax {\n // Properties are leaves, not indentation owners. Resolve ambiguous returns spelling\n // before the committed pass decides whether its deeper lines belong to a response.\n const names = new Set<string>();\n const lookahead = new ParserContext(context.reader.fork(), context.path, context.languages);\n lookahead.sourceOptions = context.sourceOptions;\n lookahead.streamCandidates = context.streamCandidates;\n parseCommandBody(lookahead, line, undefined, names);\n return parseCommandBody(context, line, names);\n}\n\nfunction parseCommandBody(context: ParserContext, line: SourceLine, responseNames?: ReadonlySet<string>, discoveredNames?: Set<string>): CommandSyntax {\n const name = header.exec(line.content)?.[1] ?? '';\n if (name === '') {\n context.error(DiagnosticCodes.InvalidCommandDeclaration, `Invalid command declaration '${line.content}' - expected 'command <Name>'`, locationOf(line));\n }\n const properties: PropertySyntax[] = [];\n const responses: { line: SourceLine; candidate: PropertySyntax | null; response: CommandResponseSyntax | null }[] = [];\n let identifier: PropertySyntax | undefined;\n const validations: ValidateSyntax[] = [];\n const produces: ProducesSyntax[] = [];\n const reads: { readModel: string; alias: string | null }[] = [];\n const referenceReads: ReadsSyntax[] = [];\n let concurrency: ConcurrencySyntax | undefined;\n let description: string | null = null;\n let documentation: string | null = null;\n let authorize: AuthorizeSyntax | null = null;\n let handler: HandlerSyntax | null = null;\n const handlers: { handler: HandlerSyntax | null; location: SourceLocation }[] = [];\n let stream: CommandStreamSyntax | null = null;\n const streamCandidates: CommandStreamSyntax[] = [];\n let calendar: CommandCalendarSyntax | null = null;\n for (let child = context.peekChild(line.indent); child !== undefined; child = context.peekChild(line.indent)) {\n context.reader.takeSignificant();\n const keyword = firstWord(child.content);\n const asProperty = tryParseProperty(child);\n if (keyword === 'calendar' && calendarPrefix.test(child.content)) {\n const match = calendarPattern.exec(child.content);\n if (calendar !== null || match === null) {\n context.error(DiagnosticCodes.InvalidCommandCalendar, 'A command declares at most one \\'calendar \"<id>\"\\' or \\'calendar from $context.<member>\\'.', locationOf(child));\n } else {\n calendar = { kind: 'CommandCalendarSyntax', id: match[1] === undefined ? null : unescapeString(match[1]), contextMember: match[2] ?? null, location: locationOf(child) };\n }\n } else if (asProperty !== undefined && (propertyShapedDirectives.has(keyword) || (keyword === 'validate' && child.content !== 'validate csharp'))) {\n identifier = addProperty(context, properties, asProperty, name, child, identifier);\n } else if (keyword === 'returns') {\n const scalar = scalarResponsePattern.exec(child.content);\n if (scalar !== null && !scalar[1].startsWith('@') && asProperty !== undefined) {\n if (responseNames === undefined) {\n properties.push(asProperty);\n responses.push({ line: child, candidate: asProperty, response: null });\n } else if (responseNames.has(asProperty.type.name)) {\n responses.push({ line: child, candidate: null, response: parseCommandResponse(context, child) });\n } else {\n identifier = addProperty(context, properties, asProperty, name, child, identifier);\n }\n } else if (asProperty !== undefined) {\n identifier = addProperty(context, properties, asProperty, name, child, identifier);\n } else if (reportInvalidModifierOrder(context, child)) {\n context.skipBlock(child.indent);\n } else {\n responses.push({ line: child, candidate: null, response: parseCommandResponse(context, child) });\n }\n } else if (keyword === 'stream' && routeHeader.test(child.content) && asProperty !== undefined && context.streamCandidates?.hasSource(asProperty.type.name.split('.')[0]) === true) {\n const [source, streamName] = asProperty.type.name.split('.');\n const ambiguous = context.streamCandidates.hasPropertyType(asProperty.type.name) && context.streamCandidates.hasUniqueStream(source, streamName);\n const route = parseCommandStream(context, child, asProperty, ambiguous);\n if (stream !== null || streamCandidates.length > 0) context.error(DiagnosticCodes.InvalidCommandStream, 'A command declares at most one stream route.', locationOf(child));\n if (ambiguous || stream !== null) streamCandidates.push(route);\n else stream = route;\n } else if (keyword === 'runs' && isReactionIdentityLine(child)) {\n misplacedReactionIdentity(context, child);\n } else if (keyword === 'description') {\n description = parseDescription(context, child, description, `Command '${name}'`);\n } else if (keyword === 'documentation') {\n documentation = parseDocumentation(context, child, documentation, `Command '${name}'`);\n } else if (keyword === 'authorize') {\n authorize = combineAuthorize(authorize, parseAuthorize(context, child));\n } else if (keyword === 'validate') {\n const validate = parseValidate(context, child, 'command', name);\n if (validate !== undefined) {\n validations.push(validate);\n }\n } else if (keyword === 'produces') {\n const production = parseProduces(context, child, true);\n if (production !== undefined) produces.push(production);\n } else if (keyword === 'handler') {\n handler = parseHandler(context, child);\n handlers.push({ handler, location: locationOf(child) });\n } else if (opaqueDirectives.has(keyword)) {\n const reference = keyword === 'reads' ? parseReads(context, child) : undefined;\n if (reference !== undefined) referenceReads.push(reference);\n if (keyword === 'concurrency' && concurrency === undefined) concurrency = captureConcurrency(context, child);\n const read = /^reads\\s+([A-Z]\\w*)(?:\\s+as\\s+([a-z_]\\w*))?(?:\\s+by\\s+([a-z_]\\w*))?$/.exec(child.content);\n if (read !== null) reads.push({ readModel: read[1], alias: read[2] ?? null });\n if (optionalReads.test(child.content)) {\n context.error(DiagnosticCodes.OptionalReadsNotSupported, 'Optional reads are not yet supported (see #308).', locationOf(child));\n }\n context.skipOpaqueBlock(child.indent);\n } else if (asProperty !== undefined) {\n identifier = addProperty(context, properties, asProperty, name, child, identifier);\n } else {\n reportInvalidModifierOrder(context, child);\n context.error(DiagnosticCodes.UnknownCommandDirective, `Unexpected '${child.content}' in command body`, locationOf(child));\n context.skipBlock(child.indent);\n }\n }\n const candidates = new Set(responses.flatMap(entry => entry.candidate === null ? [] : [entry.candidate]));\n const names = new Set(properties.filter(property => !candidates.has(property)).map(property => property.name));\n if (responses.some(entry => entry.candidate !== null && !names.has(entry.candidate.type.name) && entry.candidate.type.name !== 'returns')) names.add('returns');\n for (const name of names) discoveredNames?.add(name);\n let response: CommandResponseSyntax | null = null;\n const removed = new Set<PropertySyntax>();\n for (const entry of responses) {\n let parsed = entry.response;\n if (entry.candidate !== null) {\n if (!names.has(entry.candidate.type.name)) continue;\n removed.add(entry.candidate);\n parsed = { kind: 'ScalarCommandResponseSyntax', source: { kind: 'PropertyResponseSourceSyntax', property: entry.candidate.type.name, location: entry.candidate.type.location }, location: locationOf(entry.line) };\n }\n if (parsed === null) continue;\n if (response !== null) {\n context.error(DiagnosticCodes.InvalidCommandResponse, 'A command declares at most one unconditional response.', locationOf(entry.line));\n } else {\n response = parsed;\n }\n }\n validateHandlerContracts(handlers, handler, produces.length > 0, context);\n const syntax: CommandSyntax = { kind: 'CommandSyntax', name, description, documentation, authorize, properties: properties.filter(property => !removed.has(property)), validations, produces, handler, response, stream, streamCandidates, ...(calendar === null ? {} : { calendar }), location: locationOf(line) };\n commandReadSources.set(syntax, reads);\n dependencySources.set(syntax, { reads: referenceReads, concurrency });\n return syntax;\n}\n\nfunction addProperty(context: ParserContext, properties: PropertySyntax[], property: PropertySyntax, commandName: string, line: SourceLine, identifier: PropertySyntax | undefined): PropertySyntax | undefined {\n reportLegacyOptionalSuffix(context, property.type, line);\n if (property.isIdentifier && identifier !== undefined) {\n context.error(DiagnosticCodes.DuplicateCommandIdentifier, `Command '${commandName}' already marks '${identifier.name}' as identifier - only one property can be the identifier`, property.location);\n property = { ...property, isIdentifier: false };\n }\n properties.push(property);\n return identifier ?? (property.isIdentifier ? property : undefined);\n}\n\nfunction parseValidationFile(context: ParserContext, header: SourceLine, body: SourceLine): ValidateSyntax | undefined {\n const file = parseFile(context, body);\n return file === undefined ? undefined : { kind: 'FileValidateSyntax', file, location: locationOf(header) };\n}\n\nfunction hasValidationOperand(line: SourceLine): boolean {\n const match = rulePattern.exec(line.content);\n if (match === null) return false;\n const rule = match[2];\n return (firstWord(rule) === 'not' && firstWord(rule.substring('not'.length).trimStart()) === 'empty') ||\n firstWord(rule) === 'checksum' || operandPattern.test(rule);\n}\n\nfunction isValidationFileBody(context: ParserContext, header: SourceLine, body: SourceLine): boolean {\n if (!isFileDirectiveAmongProperties(body) || hasValidationOperand(body)) return false;\n const lookahead = context.reader.fork();\n lookahead.takeSignificant();\n const next = lookahead.peekSignificant();\n return next === undefined || next.indent <= header.indent;\n}\n\n// Reads a 'validate' block: declarative rules, or code - which is recognized but not modeled.\nexport function parseValidate(context: ParserContext, line: SourceLine, owner: 'command' | 'concept', ownerName: string): ValidateSyntax | undefined {\n if (line.content === 'validate') {\n const fence = context.peekChild(line.indent);\n if (fence !== undefined && isValidationFileBody(context, line, fence)) {\n context.reader.takeSignificant();\n return parseValidationFile(context, line, fence);\n }\n if (fence !== undefined && fence.content.startsWith('```')) {\n context.reader.takeSignificant();\n const code = parseCode(context.valueContext, fence);\n if (code === null) context.skipFencedBody();\n return { kind: 'CodeValidateSyntax', code, location: locationOf(line) };\n }\n const rules: ValidationRuleSyntax[] = [];\n const requirements: RequirementSyntax[] = [];\n let wrapperIndent: number | undefined;\n for (let child = context.peekChild(line.indent); child !== undefined; child = context.peekChild(line.indent)) {\n context.reader.takeSignificant();\n if (owner === 'concept') {\n if (context.sourceOptions.numericMode === 'legacy' && child.content.startsWith('```')) { context.skipFencedBody(); continue; }\n if (wrapperIndent !== undefined && child.indent <= wrapperIndent) wrapperIndent = undefined;\n if (wrapperIndent !== undefined || firstWord(child.content) === 'implementation') {\n context.error(DiagnosticCodes.InvalidValidationRule, `Invalid validation rule '${child.content}'`, locationOf(child));\n wrapperIndent ??= child.indent;\n continue;\n }\n }\n if (firstWord(child.content) === 'require') {\n const condition = parseCondition(owner === 'concept' ? context.valueContext : context, child.content.substring('require'.length).trim(), locationOf(child));\n let message: string | null = null;\n let severity: ValidationSeverity = 'Error';\n let hasSeverity = false;\n for (let directive = context.peekChild(child.indent); directive !== undefined; directive = context.peekChild(child.indent)) {\n context.reader.takeSignificant();\n const matched = messagePattern.exec(directive.content);\n if (matched !== null && matched.index === 0) message = matched[1] !== undefined ? unescapeString(matched[1]) : matched[2];\n else if (firstWord(directive.content) === 'severity') {\n if (!hasSeverity) severity = severities[directive.content.substring('severity'.length).trim()] ?? 'Error';\n hasSeverity = true;\n } else context.skipOpaqueBlock(directive.indent);\n }\n if (condition !== null) requirements.push({ kind: 'RequirementSyntax', condition, message, severity, location: locationOf(child) });\n continue;\n }\n const rule = parseValidationRule(context, owner === 'concept' ? { ...child, content: `value ${child.content}` } : child, owner, ownerName);\n if (rule !== undefined) {\n rules.push(rule);\n }\n }\n return { kind: 'DeclarativeValidateSyntax', rules, requirements, location: locationOf(line) };\n }\n if (owner === 'concept' && firstWord(line.content.substring('validate'.length).trimStart()) === 'checksum') {\n const ruleLine = { ...line, content: `value ${line.content.substring('validate'.length).trimStart()}` };\n const rule = parseValidationRule(context, ruleLine, owner, ownerName);\n return rule === undefined ? undefined : { kind: 'DeclarativeValidateSyntax', rules: [rule], requirements: [], location: locationOf(line) };\n }\n if (line.content === 'validate csharp') {\n const code = parseCode(context.valueContext, { ...line, content: 'csharp' });\n if (code === null) context.skipOpaqueBlock(line.indent);\n return { kind: 'CodeValidateSyntax', code, location: locationOf(line) };\n }\n context.error(DiagnosticCodes.InvalidValidateDeclaration, `Invalid validate declaration '${line.content}' - expected 'validate' or 'validate csharp'`, locationOf(line));\n context.skipBlock(line.indent);\n return undefined;\n}\n\nfunction parseValidationRule(context: ParserContext, line: SourceLine, owner: 'command' | 'concept', ownerName: string): ValidationRuleSyntax | undefined {\n // Checksum is a new declaration, not enrichment of a formerly opaque Legacy rule.\n const checksum = firstWord(rulePattern.exec(line.content)?.[2] ?? '') === 'checksum';\n const valueContext = owner === 'concept' && !checksum ? context.valueContext : context;\n const { content: withSeverity, message } = splitMessage(line.content);\n const severity = splitSeverity(valueContext, line, withSeverity);\n if (severity === undefined) {\n return undefined;\n }\n const match = rulePattern.exec(severity.content);\n if (match === null) {\n valueContext.error(DiagnosticCodes.InvalidValidationRule, `Invalid validation rule '${line.content}'`, locationOf(line));\n return undefined;\n }\n const parsed = parseRule(valueContext, match[2], line);\n if (parsed === undefined) {\n return undefined;\n }\n if (parsed.kind === 'Matches' && parsed.value !== null) validateMatchOperand(context, parsed.value, locationOf(line), line.raw, matchSubject(context, owner, ownerName, match[1]));\n const source = parsed.kind === 'Rule' ? parseRuleImplementation(context, line, owner === 'command') : { file: null, code: null, implementation: null };\n return {\n kind: 'ValidationRuleSyntax',\n property: match[1],\n rule: parsed.kind,\n value: parsed.value,\n message,\n severity: severity.severity,\n ...source,\n location: locationOf(line),\n };\n}\n\nfunction parseRuleImplementation(context: ParserContext, rule: SourceLine, commandOwner: boolean): { file: FileReferenceSyntax | null; code: CodeBlockSyntax | null; implementation: ImplementationSyntax | null } {\n const body = context.peekChild(rule.indent);\n if (body === undefined) return { file: null, code: null, implementation: null };\n context.reader.takeSignificant();\n const wrapped = commandOwner && firstWord(body.content) === 'implementation';\n const source = wrapped ? parseImplementationWrapper(context, body) : {\n file: isFile(body) ? parseFile(context, body) : null,\n code: !isFile(body) && isCode(context, body) ? parseCode(context, body) : null,\n implementation: null,\n };\n if (!wrapped && source.file === null && source.code === null) {\n context.error(DiagnosticCodes.UnknownRuleImplementationDirective, `Unexpected '${body.content}' in rule implementation - expected 'file <path>' or an inline code block`, locationOf(body));\n context.skipBlock(body.indent);\n }\n for (let extra = context.peekChild(rule.indent); extra !== undefined && (wrapped || (commandOwner && firstWord(extra.content) === 'implementation')); extra = context.peekChild(rule.indent)) {\n context.reader.takeSignificant();\n context.error(wrapped && firstWord(extra.content) === 'implementation' ? DiagnosticCodes.InvalidImplementationBlock : DiagnosticCodes.ConflictingImplementationSources,\n 'A named rule has one implementation wrapper and cannot mix wrapped and direct sources.', locationOf(extra));\n if (isCode(context, extra)) parseCode(context, extra);\n else context.skipBlock(extra.indent);\n }\n return source;\n}\n\nfunction splitMessage(content: string): { content: string; message: string | null } {\n const match = messagePattern.exec(content);\n if (match === null) {\n return { content, message: null };\n }\n const message = match[1] !== undefined ? unescapeString(match[1]) : match[2];\n return { content: content.substring(0, match.index).trimEnd(), message };\n}\n\nfunction splitSeverity(context: ParserContext, line: SourceLine, text: string): { content: string; severity: ValidationSeverity } | undefined {\n const match = severityPattern.exec(text);\n if (match === null) {\n return { content: text, severity: 'Error' };\n }\n const severity = severities[match[1]];\n if (severity === undefined) {\n context.error(DiagnosticCodes.InvalidValidationSeverity, `Unknown validation severity '${match[1]}' - expected information, warning or error`, locationOf(line));\n return undefined;\n }\n return { content: text.substring(0, match.index).trimEnd(), severity };\n}\n\nfunction parseRule(context: ParserContext, rule: string, line: SourceLine): { kind: ValidationRuleKind; value: ExpressionSyntax | null } | undefined {\n if (rule === 'not empty') {\n return { kind: 'NotEmpty', value: null };\n }\n if (firstWord(rule) === 'checksum') {\n const algorithm = rule.substring('checksum'.length).trim();\n if (algorithm !== 'luhn' && algorithm !== 'mod11' && algorithm !== 'mod97') {\n context.error(DiagnosticCodes.InvalidGenerationArgument, 'Checksum validation requires luhn, mod11 or mod97.', locationOf(line));\n return undefined;\n }\n return { kind: 'Checksum', value: { kind: 'LiteralExpressionSyntax', value: algorithm, location: locationOf(line) } };\n }\n const operand = operandPattern.exec(rule);\n if (operand === null) {\n context.error(DiagnosticCodes.InvalidValidationRule, `Invalid validation rule '${line.content}'`, locationOf(line));\n return undefined;\n }\n const operator = operand[1] ?? operand[2];\n if (operator === 'rule') {\n const name = operand[3].trim();\n if (!ruleNamePattern.test(name)) {\n context.error(DiagnosticCodes.InvalidRuleName, `Invalid rule name '${name}' in '${line.content}' - expected 'rule <Name>' with an identifier`, locationOf(line));\n return undefined;\n }\n return { kind: 'Rule', value: { kind: 'PathExpressionSyntax', path: name, location: locationOf(line) } };\n }\n return { kind: operandKinds[operator], value: parseMappingSource(operand[3], locationOf(line), context) };\n}\n"],"mappings":"swDAwCA,MAAMA,EAASC,EAAQ,8BAA8B,EAC/CC,EAAcC,EAAoB,2CAA2C,EAC7EC,GAAiBH,EAAQ,0CAA0C,EACnEI,EAAkBJ,EAAQ,qBAAqBK,EAAkB,iFAAiF,EAClJC,EAAkBN,EAAQ,wBAAwB,EAClDO,EAAiBP,EAAQ,sBAAsBK,EAAkB,yBAAyB,EAC1FG,EAAcR,EAAQ,qBAAqB,EAC3CS,EAAiBT,EAAQ,2JAA2J,EACpLU,EAAkBR,EAAoB,iBAAiB,EACvDS,EAAgBX,EAAQ,0CAA0C,EAGlEY,EAAmD,CACrD,IAAK,MACL,IAAK,MACL,IAAK,cACL,KAAM,qBACN,IAAK,WACL,KAAM,kBACN,KAAM,QACN,KAAM,WACN,YAAa,SACb,cAAe,gBACf,QAAS,UACT,SAAU,WACV,eAAgB,cAChB,cAAe,aACf,YAAa,WACb,QAAS,iBACT,SAAU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Q,GACvC,GAAIC,IAAa,OAAQ,CACrB,IAAMnG,EAAOkG,EAAQ,EAAE,CAAC,KAAK,EAC7B,GAAI,CAAC7G,EAAgB,KAAKW,CAAI,EAAG,CAC7BF,EAAQ,MAAMG,EAAgB,gBAAiB,sBAAsBD,EAAK,QAAQD,EAAK,QAAQ,+CAAgDG,EAAWH,CAAI,CAAC,EAC/J,MACJ,CACA,MAAO,CAAE,KAAM,OAAQ,MAAO,CAAE,KAAM,uBAAwB,KAAMC,EAAM,SAAUE,EAAWH,CAAI,CAAE,CAAE,CAC3G,CACA,MAAO,CAAE,KAAMR,EAAa4G,GAAW,MAAOC,EAAmBF,EAAQ,GAAIhG,EAAWH,CAAI,EAAGD,CAAO,CAAE,CAC5G"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import"../../_virtual/_virtual/_rolldown/runtime.js";import{DiagnosticCodes as e}from"../Diagnostics/DiagnosticCodes.js";import{pattern as t}from"../Text/patterns.js";import{locationOf as n}from"./SourceLine.js";import{
|
|
1
|
+
import"../../_virtual/_virtual/_rolldown/runtime.js";import{DiagnosticCodes as e}from"../Diagnostics/DiagnosticCodes.js";import{pattern as t}from"../Text/patterns.js";import{locationOf as n}from"./SourceLine.js";import{combineAuthorize as r,parseAuthorize as i}from"./AuthorizeParser.js";import{firstWord as a}from"./LineText.js";import{parseDescription as o}from"./DescriptionParser.js";import{parsePurposeReference as s}from"./PurposeParser.js";import{parseDocumentation as c}from"./DocumentationParser.js";import{parseDependsOn as l}from"./DependsOnParser.js";import{parseFileImport as u}from"./FileImportParser.js";import{collectInputUses as d}from"./InputUses.js";import{misplacedReactionIdentity as f}from"./ReactionIdentityParser.js";import{parseExample as p}from"./SpecificationExampleParser.js";import{parseToolbar as m}from"./ScreenParser.js";import{parseSlice as h}from"./SliceParser.js";const g=t(`^feature\\s+([A-Za-z_]\\w*)$`),_=/* @__PURE__ */ new Set([`on`,`uses`,`contribute`,`template`]),v=`description, documentation, depends on <Name>, authorize, import, feature, slice, contribute, toolbar, example, 'on <trigger>' or 'uses <Behavior>'`;var FeatureBody=class{name;#e=[];#t=[];#n=[];#r=[];#i=[];#a=[];#o=[];#s=null;#c=null;#l=null;constructor(e){this.name=e}tryParse(t,n){let g=a(n.content);switch(g){case`runs`:return f(t,n),!0;case`description`:return this.#s=o(t,n,this.#s,`Feature '${this.name}'`),!0;case`documentation`:return this.#c=c(t,n,this.#c,`Feature '${this.name}'`),!0;case`depends`:return l(t,n,this.#i,e.UnknownFeatureDirective),!0;case`purpose`:return s(t,n,this.#a),!0;case`authorize`:return this.#l=r(this.#l,i(t,n)),!0;case`import`:return u(t,n,this.#r),!0;case`toolbar`:return this.#o.push(m(t,n)),!0;case`feature`:return this.#e.push(parseFeature(t,n)),!0;case`example`:return this.#n.push(p(t,n)),!0;case`slice`:return this.#t.push(h(t,n)),!0;default:return _.has(g)?(d(t,n),!0):!1}}build(e,t=!1){return{kind:`FeatureSyntax`,name:this.name,description:this.#s,documentation:this.#c,authorize:this.#l,dependsOn:this.#i,purposes:this.#a,...this.#o.length>0?{toolbars:this.#o}:{},features:this.#e,slices:this.#t,examples:this.#n,fileImports:this.#r,isPlacement:t,location:e}}};function parseFeature(t,r){let i=g.exec(r.content)?.[1]??``;i===``&&t.error(e.InvalidFeatureDeclaration,`Invalid feature declaration '${r.content}' - expected 'feature <Name>'`,n(r));let o=new FeatureBody(i),s=t.scope;t.scope=[...s,i];for(let i=t.peekChild(r.indent);i!==void 0;i=t.peekChild(r.indent))t.reader.takeSignificant(),o.tryParse(t,i)||(t.error(e.UnknownFeatureDirective,`Unexpected '${a(i.content)}' in feature body - expected ${v}`,n(i)),t.skipBlock(i.indent));return t.scope=s,o.build(n(r))}export{FeatureBody,v as featureBodyExpected,parseFeature};
|
|
2
2
|
//# sourceMappingURL=FeatureBody.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import"../../_virtual/_virtual/_rolldown/runtime.js";import{DiagnosticCodes as e}from"../Diagnostics/DiagnosticCodes.js";import{pattern as t}from"../Text/patterns.js";import{locationOf as n}from"./SourceLine.js";import{
|
|
1
|
+
import"../../_virtual/_virtual/_rolldown/runtime.js";import{DiagnosticCodes as e}from"../Diagnostics/DiagnosticCodes.js";import{pattern as t}from"../Text/patterns.js";import{locationOf as n}from"./SourceLine.js";import{combineAuthorize as r,parseAuthorize as i}from"./AuthorizeParser.js";import{firstWord as a}from"./LineText.js";import{parseDescription as o}from"./DescriptionParser.js";import{parsePurposeReference as s}from"./PurposeParser.js";import{parseDocumentation as c}from"./DocumentationParser.js";import{parseDependsOn as l}from"./DependsOnParser.js";import{parseFileImport as u}from"./FileImportParser.js";import{collectInputUses as d}from"./InputUses.js";import{misplacedReactionIdentity as f}from"./ReactionIdentityParser.js";import{parseExample as p}from"./SpecificationExampleParser.js";import{parseToolbar as m}from"./ScreenParser.js";import{parseFeature as h}from"./FeatureBody.js";const g=t(`^module\\s+([A-Za-z_]\\w*)$`),_=/* @__PURE__ */ new Set([`on`,`uses`,`screen`,`dialog`,`form`,`contribute`,`navigation`,`template`]),v=`description, documentation, depends on <Name>, authorize, import, screen template, dialog template, form, contribute, toolbar, navigation, feature, example, 'on <trigger>' or 'uses <Behavior>'`;var ModuleBody=class{name;#e=[];#t=[];#n=[];#r=[];#i=[];#a=[];#o=null;#s=null;#c=null;constructor(e){this.name=e}tryParse(t,n){let g=a(n.content);switch(g){case`runs`:return f(t,n),!0;case`description`:return this.#o=o(t,n,this.#o,`Module '${this.name}'`),!0;case`documentation`:return this.#s=c(t,n,this.#s,`Module '${this.name}'`),!0;case`depends`:return l(t,n,this.#r,e.UnknownModuleDirective),!0;case`purpose`:return s(t,n,this.#i),!0;case`authorize`:return this.#c=r(this.#c,i(t,n)),!0;case`import`:return u(t,n,this.#n),!0;case`example`:return this.#t.push(p(t,n)),!0;case`toolbar`:return this.#a.push(m(t,n)),!0;case`feature`:return this.#e.push(h(t,n)),!0;default:return _.has(g)?(d(t,n),!0):!1}}parseChildren(t,r){for(let i=t.peekChild(r.indent);i!==void 0;i=t.peekChild(r.indent))t.reader.takeSignificant(),this.tryParse(t,i)||(t.error(e.UnknownModuleDirective,`Unexpected '${a(i.content)}' in module body - expected ${v}`,n(i)),t.skipBlock(i.indent))}build(e,t=!1){return{kind:`ModuleSyntax`,name:this.name,description:this.#o,documentation:this.#s,authorize:this.#c,dependsOn:this.#r,purposes:this.#i,...this.#a.length>0?{toolbars:this.#a}:{},features:this.#e,examples:this.#t,fileImports:this.#n,isPlacement:t,location:e}}};function parseModule(t,r){let i=g.exec(r.content)?.[1]??``;i===``&&t.error(e.InvalidModuleDeclaration,`Invalid module declaration '${r.content}' - expected 'module <Name>'`,n(r));let a=new ModuleBody(i),o=t.scope;return t.scope=[i],a.parseChildren(t,r),t.scope=o,a.build(n(r))}export{ModuleBody,v as moduleBodyExpected,g as modulePattern,parseModule};
|
|
2
2
|
//# sourceMappingURL=ModuleBody.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import"../../_virtual/_virtual/_rolldown/runtime.js";import{DiagnosticCodes as e}from"../Diagnostics/DiagnosticCodes.js";import{pattern as t}from"../Text/patterns.js";import{locationOf as n}from"./SourceLine.js";import{diagnosticText as r}from"../Diagnostics/DiagnosticArgument.js";import{firstWord as i,splitTopLevel as a,unescapeIdentifier as o}from"./LineText.js";import{parseDescription as s}from"./DescriptionParser.js";import{isFileDirective as c}from"./FileReferences.js";import{parseProjectionExpression as l}from"./ProjectionExpressionParser.js";import{validateProjectionEventScopes as u}from"./ProjectionEventScopeValidator.js";const d=t(`^projection\\s+(@?[\\w.]+)\\s*(?:=>\\s*([\\w.]+))?$`),f=t(`^(@?[\\w.]+)(?:\\s+key\\s+(.+))?$`),p=t(`^join\\s+(@?[\\w.]+)\\s+on\\s+(@?[\\w.]+)$`),m=t(`^with\\s+(@?[\\w.]+)$`),h=t(`^children\\s+(@?[\\w.]+)\\s+identified\\s+by\\s+(.+)$`),g=t(`^nested\\s+(@?[\\w.]+)$`),_=t(`^remove\\s+with\\s+(@?[\\w.]+)(?:\\s+key\\s+(.+))?$`),v=t(`^remove\\s+via\\s+join\\s+on\\s+(@?[\\w.]+)(?:\\s+key\\s+(.+))?$`),y=t(`^clear\\s+with\\s+(@?[\\w.]+)$`),b=t(`^variant\\s+(@?[\\w.]+)\\s*$`),x=t(`^enters\\s+on\\s+(@?[\\w.]+)(?:\\s+key\\s+(.+))?$`),S=t(`^(increment|decrement|count|clear)\\s+(@?[$\\w.]+)$`),C=t(`^(add|subtract)\\s+(@?[$\\w.]+)\\s+by\\s+(.+?)(?:\\s+\\*\\s+(.+))?$`),w=t(`^set\\s+(@?[$\\w.]+)\\s+(?:=|to)\\s+(.+)$`),T=t(`^(@?[$\\w.@]+)\\s*=(?!=|>)\\s*(.+)$`),E={increment:`IncrementMappingSyntax`,decrement:`DecrementMappingSyntax`,clear:`ClearMappingSyntax`,count:`CountMappingSyntax`};function parseProjection(t,r){let a=d.exec(r.content);if(a===null)return t.error(e.InvalidProjectionDeclaration,`Invalid projection declaration '${r.content}' - expected 'projection <Name> [=> <ReadModel>]'`,n(r)),t.skipBlock(r.indent),{kind:`ProjectionSyntax`,sourceOptions:t.sourceOptions,name:i(r.content),readModel:null,sequence:null,autoMap:`Inherit`,blocks:[],location:n(r)};let o=a[1],l=null,f=null,p=`Inherit`,m=null,h=[];for(let e=t.peekChild(r.indent);e!==void 0;e=t.peekChild(r.indent)){if(t.reader.takeSignificant(),c(e))continue;let n=i(e.content);if(n===`description`)f=s(t,e,f,`Projection '${o}'`);else if(n===`sequence`)l=e.content.substring(8).trim();else if(n===`automap`)p=`Enabled`;else if(e.content===`no automap`)p=`Disabled`;else if(n===`key`)m=parseKey(t,e);else if(n===`variant`)h.push(parseVariant(t,e));else{let n=parseBlock(t,e,!1);n!==void 0&&h.push(n)}}return reportVariantConflicts(t,h,o),u(t,o,h),h.length===0&&t.error(e.EmptyProjection,`Projection '${o}' must contain at least one directive`,n(r)),{kind:`ProjectionSyntax`,sourceOptions:t.sourceOptions,name:o,readModel:a[2]??null,sequence:l,autoMap:p,key:m,blocks:h,description:f,location:n(r)}}function reportVariantConflicts(t,n,r){let i=n.filter(e=>e.kind===`ProjectionVariantSyntax`),a=/* @__PURE__ */ new Map;i.forEach(e=>a.set(e.name,[...a.get(e.name)??[],e]));for(let n of[...a.values()].flatMap(e=>e.slice(1)))t.error(e.DuplicateProjectionVariant,`Duplicate variant '${n.name}' - a variant name is declared once`,n.location);let o=/* @__PURE__ */ new Set;for(let i of n.flatMap(e=>e.kind===`ProjectionVariantSyntax`?e.entersOn:[]))i.event.length>0&&o.has(i.event)&&t.error(e.DuplicateVariantEnteringEvent,`Entering event '${i.event}' is claimed more than once in projection '${r}'`,i.location),o.add(i.event)}function parseBlock(t,r,a){let o=n(r);switch(i(r.content)){case`from`:return parseFrom(t,r);case`every`:{let e=!0,{autoMap:n,mappings:i}=parseMappingBlock(t,r,t=>t.content===`exclude children`&&(e=!1,!0));return{kind:`EverySyntax`,includeChildren:e,autoMap:n,mappings:i,location:o}}case`all`:{let{autoMap:e,mappings:n}=parseMappingBlock(t,r);return{kind:`AllSyntax`,autoMap:e,mappings:n,location:o}}case`join`:return parseJoin(t,r);case`children`:return parseChildren(t,r);case`nested`:return parseNested(t,r);case`remove`:return parseRemove(t,r);case`clear`:return a||t.error(e.ClearWithOutsideNestedBlock,`'clear with' is only valid inside a nested block`,o),parseClearWith(t,r);default:t.error(e.UnknownProjectionDirective,`Unexpected '${i(r.content)}' in projection body`,o),t.skipBlock(r.indent);return}}function parseFrom(t,r){let s=[];for(let i of a(r.content.substring(4),`,`)){let a=i.trim();if(a.length===0){t.error(e.FromWithoutEvent,`Expected an event type after 'from'`,n(r));continue}let c=f.exec(a);c===null?t.error(e.InvalidEventReference,`Invalid event reference '${a}'`,n(r)):s.push({kind:`EventSpecSyntax`,event:o(c[1]),key:c[2]===void 0?null:l(c[2],n(r),t),location:n(r)})}let c=[],u=null,d=null;for(let e=t.peekChild(r.indent);e!==void 0;e=t.peekChild(r.indent)){t.reader.takeSignificant();let r=i(e.content);r===`key`?u=parseKey(t,e):r===`parent`?d=l(e.content.substring(6),n(e),t):pushMapping(t,e,c)}return{kind:`FromSyntax`,events:s,key:u,parentKey:d,mappings:c,location:n(r)}}function parseJoin(t,r){let i=p.exec(r.content);if(i===null)return t.error(e.InvalidJoinDeclaration,`Invalid join declaration '${r.content}' - expected 'join <property> on <key>'`,n(r)),t.skipBlock(r.indent),{kind:`JoinSyntax`,property:``,on:``,events:[],location:n(r)};let a=[];for(let i=t.peekChild(r.indent);i!==void 0;i=t.peekChild(r.indent)){t.reader.takeSignificant();let r=m.exec(i.content);if(r===null){t.error(e.JoinWithoutEvent,`Expected 'with <EventType>' in join block, got '${i.content}'`,n(i)),t.skipBlock(i.indent);continue}let{autoMap:s,mappings:c}=parseMappingBlock(t,i);a.push({kind:`JoinEventSyntax`,event:o(r[1]),autoMap:s,mappings:c,location:n(i)})}return{kind:`JoinSyntax`,property:o(i[1]),on:o(i[2]),events:a,location:n(r)}}function parseChildren(t,r){let i=h.exec(r.content);if(i===null)return t.error(e.InvalidChildrenDeclaration,`Invalid children declaration '${r.content}' - expected 'children <collection> identified by <key>'`,n(r)),t.skipBlock(r.indent),{kind:`ChildrenSyntax`,property:``,autoMap:`Inherit`,blocks:[],location:n(r)};let{autoMap:a,blocks:s}=parseChildBlocks(t,r);return{kind:`ChildrenSyntax`,property:o(i[1]),identifiedBy:l(i[2],n(r),t),autoMap:a,blocks:s,location:n(r)}}function parseNested(t,r){let i=g.exec(r.content);if(i===null)return t.error(e.InvalidNestedDeclaration,`Invalid nested declaration '${r.content}' - expected 'nested <property>'`,n(r)),t.skipBlock(r.indent),{kind:`NestedSyntax`,property:``,autoMap:`Inherit`,blocks:[],location:n(r)};let a=o(i[1]),{autoMap:s,blocks:c}=parseChildBlocks(t,r);return c.some(e=>e.kind===`FromSyntax`)||t.error(e.NestedBlockWithoutFrom,`Nested block '${a}' must contain at least one 'from' directive`,n(r)),{kind:`NestedSyntax`,property:a,autoMap:s,blocks:c,location:n(r)}}function parseChildBlocks(e,t){let n=[],r=`Inherit`;for(let i=e.peekChild(t.indent);i!==void 0;i=e.peekChild(t.indent)){if(e.reader.takeSignificant(),i.content===`automap`){r=`Enabled`;continue}if(i.content===`no automap`){r=`Disabled`;continue}let t=parseBlock(e,i,!0);t!==void 0&&n.push(t)}return{autoMap:r,blocks:n}}function parseRemove(t,r){let a=v.exec(r.content);if(a!==null)return{kind:`RemoveViaJoinSyntax`,event:o(a[1]),key:a[2]===void 0?null:l(a[2],n(r),t),location:n(r)};let s=_.exec(r.content);if(s===null){t.error(e.InvalidRemoveDeclaration,`Invalid remove declaration '${r.content}' - expected 'remove with <EventType>' or 'remove via join on <EventType>'`,n(r)),t.skipBlock(r.indent);return}let c=s[2]===void 0?null:l(s[2],n(r),t),u=null,d=null;for(let a=t.peekChild(r.indent);a!==void 0;a=t.peekChild(r.indent))if(t.reader.takeSignificant(),i(a.content)===`parent`)d=l(a.content.substring(6),n(a),t);else if(i(a.content)===`key`){(c!==null||u!==null)&&t.error(e.InvalidReadModelKeyLookup,`A removal can only declare one key.`,n(a));let r=parseKey(t,a);r.kind===`CompositeKeySyntax`?u=r:c=r.expression}else t.error(e.UnknownRemoveDirective,`Unexpected '${a.content}' in remove block - only 'parent' or 'key' is allowed`,n(a));return{kind:`RemoveWithSyntax`,event:o(s[1]),key:c,...u===null?{}:{partsKey:u},parentKey:d,location:n(r)}}function parseClearWith(t,r){let i=y.exec(r.content);return i===null?(t.error(e.InvalidClearDeclaration,`Invalid clear declaration '${r.content}' - expected 'clear with <EventType>'`,n(r)),{kind:`ClearWithSyntax`,event:``,location:n(r)}):{kind:`ClearWithSyntax`,event:o(i[1]),location:n(r)}}function parseVariant(t,r){let a=b.exec(r.content);if(a===null)return t.error(e.InvalidProjectionVariantDeclaration,`Invalid variant declaration '${r.content}' - expected 'variant <Name>'`,n(r)),t.skipBlock(r.indent),{kind:`ProjectionVariantSyntax`,name:i(r.content),entersOn:[],blocks:[],location:n(r)};let s=o(a[1]),c=[],l=[];for(let a=t.peekChild(r.indent);a!==void 0;a=t.peekChild(r.indent)){t.reader.takeSignificant();let r=i(a.content);if(r===`enters`)c.push(parseEntersOn(t,a));else if(r===`variant`)t.error(e.NestedProjectionVariantNotAllowed,`A variant cannot be declared inside another variant`,n(a)),t.skipBlock(a.indent);else{let e=parseBlock(t,a,!1);e!==void 0&&l.push(e)}}return c.length===0&&t.error(e.VariantRequiresEnteringEvent,`Variant '${s}' must declare at least one 'enters on' event`,n(r)),{kind:`ProjectionVariantSyntax`,name:s,entersOn:c,blocks:l,location:n(r)}}function parseEntersOn(t,r){let i=x.exec(r.content);return i===null?(t.error(e.InvalidEntersOnDeclaration,`Invalid 'enters on' declaration '${r.content}' - expected 'enters on <EventType> [key <expression>]'`,n(r)),t.skipBlock(r.indent),{kind:`ProjectionEntersOnSyntax`,event:``,key:null,location:n(r)}):{kind:`ProjectionEntersOnSyntax`,event:o(i[1]),key:i[2]===void 0?null:l(i[2],n(r),t),location:n(r)}}function parseKey(t,r){let i=r.content.substring(3).trim();if(t.peekChild(r.indent)===void 0)return{kind:`ExpressionKeySyntax`,expression:l(i,n(r),t),location:n(r)};let a=[];for(let s=t.peekChild(r.indent);s!==void 0;s=t.peekChild(r.indent)){if(t.reader.takeSignificant(),s.content===`}`)continue;let r=T.exec(s.content);if(r===null){t.sourceOptions.numericMode===`exact`&&t.error(e.InvalidCompositeKeyPart,`Invalid composite key part '${s.content}' - expected '<property> = <expression>'`,n(s));continue}let c=l(r[2],n(s),t);t.sourceOptions.numericMode===`exact`&&i.replace(/\{$/,``).trim().length>0&&c.kind===`TemplateExpressionSyntax`&&t.error(e.TemplateInCompositeKey,`Template expressions are not allowed in composite keys`,n(s)),a.push({kind:`KeyPartSyntax`,property:o(r[1]),expression:c,location:n(s)})}let s=t.reader.peekSignificant();return s!==void 0&&s.indent===r.indent&&s.content===`}`&&t.reader.takeSignificant(),t.sourceOptions.numericMode===`exact`&&a.length===0&&t.error(e.EmptyCompositeKey,`Composite keys must contain at least one part`,n(r)),{kind:`CompositeKeySyntax`,type:i.replace(/\{$/,``).trim(),parts:a,location:n(r)}}function parseMappingBlock(e,t,n=()=>!1){let r=`Inherit`,i=[];for(let a=e.peekChild(t.indent);a!==void 0;a=e.peekChild(t.indent))e.reader.takeSignificant(),a.content===`automap`?r=`Enabled`:a.content===`no automap`?r=`Disabled`:n(a)||pushMapping(e,a,i);return{autoMap:r,mappings:i}}function pushMapping(t,i,a){let s=n(i),c=S.exec(i.content);if(c!==null){c[1]!==`clear`||c[2]!==`with`?a.push({kind:E[c[1]],property:o(c[2]),location:s}):t.sourceOptions.numericMode===`exact`&&t.error(e.InvalidProjectionMapping,`Invalid mapping '${i.content}' - 'clear with' is a block directive and needs an event type; to clear a property named 'with', write 'clear @with'`,s,r(`text`,i.content));return}let u=C.exec(i.content);if(u!==null){a.push({kind:u[1]===`add`?`AddMappingSyntax`:`SubtractMappingSyntax`,property:o(u[2]),value:l(u[3],s,t),...u[4]===void 0?{}:{factor:l(u[4],s,t)},location:s});return}let d=w.exec(i.content)??T.exec(i.content);d===null?t.sourceOptions.numericMode===`exact`&&t.error(e.InvalidProjectionMapping,`Invalid mapping '${i.content}'`,s,r(`text`,i.content)):a.push({kind:`SetMappingSyntax`,property:o(d[1]),source:l(d[2],s,t),location:s})}export{parseProjection};
|
|
1
|
+
import"../../_virtual/_virtual/_rolldown/runtime.js";import{DiagnosticCodes as e}from"../Diagnostics/DiagnosticCodes.js";import{pattern as t}from"../Text/patterns.js";import{locationOf as n}from"./SourceLine.js";import{diagnosticText as r}from"../Diagnostics/DiagnosticArgument.js";import{firstWord as i,splitTopLevel as a,unescapeIdentifier as o}from"./LineText.js";import{parseDescription as s}from"./DescriptionParser.js";import{isFileDirective as c}from"./FileReferences.js";import{parseProjectionExpression as l}from"./ProjectionExpressionParser.js";import{validateProjectionEventScopes as u}from"./ProjectionEventScopeValidator.js";const d=t(`^projection\\s+(@?[\\w.]+)\\s*(?:=>\\s*([\\w.]+))?$`),f=t(`^(@?[\\w.]+)(?:\\s+key\\s+(.+))?$`),p=t(`^join\\s+(@?[\\w.]+)\\s+on\\s+(@?[\\w.]+)$`),m=t(`^with\\s+(@?[\\w.]+)$`),h=t(`^children\\s+(@?[\\w.]+)\\s+identified\\s+by\\s+(.+)$`),g=t(`^nested\\s+(@?[\\w.]+)$`),_=t(`^remove\\s+with\\s+(@?[\\w.]+)(?:\\s+key\\s+(.+))?$`),v=t(`^remove\\s+via\\s+join\\s+on\\s+(@?[\\w.]+)(?:\\s+key\\s+(.+))?$`),y=t(`^clear\\s+with\\s+(@?[\\w.]+)$`),b=t(`^variant\\s+(@?[\\w.]+)\\s*$`),x=t(`^enters\\s+on\\s+(@?[\\w.]+)(?:\\s+key\\s+(.+))?$`),S=t(`^(increment|decrement|count|clear)\\s+(@?[$\\w.]+)$`),C=t(`^(add|subtract)\\s+(@?[$\\w.]+)\\s+by\\s+(.+?)(?:\\s+\\*\\s+(.+))?$`),w=t(`^set\\s+(@?[$\\w.]+)\\s+(?:=|to)\\s+(.+)$`),T=t(`^(@?[$\\w.@]+)\\s*=(?!=|>)\\s*(.+)$`),E={increment:`IncrementMappingSyntax`,decrement:`DecrementMappingSyntax`,clear:`ClearMappingSyntax`,count:`CountMappingSyntax`};function parseProjection(t,r){let a=d.exec(r.content);if(a===null)return t.error(e.InvalidProjectionDeclaration,`Invalid projection declaration '${r.content}' - expected 'projection <Name> [=> <ReadModel>]'`,n(r)),t.skipBlock(r.indent),{kind:`ProjectionSyntax`,sourceOptions:t.sourceOptions,name:i(r.content),readModel:null,sequence:null,autoMap:`Inherit`,blocks:[],location:n(r)};let o=a[1],l=null,f=null,p=`Inherit`,m=null,h=[];for(let e=t.peekChild(r.indent);e!==void 0;e=t.peekChild(r.indent)){if(t.reader.takeSignificant(),c(e))continue;let n=i(e.content);if(n===`description`)f=s(t,e,f,`Projection '${o}'`);else if(n===`sequence`)l=e.content.substring(8).trim();else if(n===`automap`)p=`Enabled`;else if(e.content===`no automap`)p=`Disabled`;else if(n===`key`)m=parseKey(t,e);else if(n===`variant`)h.push(parseVariant(t,e));else{let n=parseBlock(t,e,!1);n!==void 0&&h.push(n)}}return reportVariantConflicts(t,h,o),u(t,o,h),h.length===0&&t.error(e.EmptyProjection,`Projection '${o}' must contain at least one directive`,n(r)),{kind:`ProjectionSyntax`,sourceOptions:t.sourceOptions,name:o,readModel:a[2]??null,sequence:l,autoMap:p,key:m,blocks:h,description:f,location:n(r)}}function reportVariantConflicts(t,n,r){let i=n.filter(e=>e.kind===`ProjectionVariantSyntax`),a=/* @__PURE__ */ new Map;i.forEach(e=>a.set(e.name,[...a.get(e.name)??[],e]));for(let n of[...a.values()].flatMap(e=>e.slice(1)))t.error(e.DuplicateProjectionVariant,`Duplicate variant '${n.name}' - a variant name is declared once`,n.location);let o=/* @__PURE__ */ new Set;for(let i of n.flatMap(e=>e.kind===`ProjectionVariantSyntax`?e.entersOn:[]))i.event.length>0&&o.has(i.event)&&t.error(e.DuplicateVariantEnteringEvent,`Entering event '${i.event}' is claimed more than once in projection '${r}'`,i.location),o.add(i.event)}function parseBlock(t,r,a){let o=n(r);switch(i(r.content)){case`from`:return parseFrom(t,r);case`every`:{let e=!0,{autoMap:n,mappings:i}=parseMappingBlock(t,r,t=>t.content===`exclude children`&&(e=!1,!0));return{kind:`EverySyntax`,includeChildren:e,autoMap:n,mappings:i,location:o}}case`all`:{let{autoMap:e,mappings:n}=parseMappingBlock(t,r);return{kind:`AllSyntax`,autoMap:e,mappings:n,location:o}}case`join`:return parseJoin(t,r);case`children`:return parseChildren(t,r);case`nested`:return parseNested(t,r);case`remove`:return parseRemove(t,r);case`clear`:return a||t.error(e.ClearWithOutsideNestedBlock,`'clear with' is only valid inside a nested block`,o),parseClearWith(t,r);default:t.error(e.UnknownProjectionDirective,`Unexpected '${i(r.content)}' in projection body`,o),t.skipBlock(r.indent);return}}function parseFrom(t,r){let s=[];for(let i of a(r.content.substring(4),`,`)){let a=i.trim();if(a.length===0){t.error(e.FromWithoutEvent,`Expected an event type after 'from'`,n(r));continue}let c=f.exec(a);c===null?t.error(e.InvalidEventReference,`Invalid event reference '${a}'`,n(r)):s.push({kind:`EventSpecSyntax`,event:o(c[1]),key:c[2]===void 0?null:l(c[2],n(r),t),location:n(r)})}let c=[],u=null,d=null;for(let e=t.peekChild(r.indent);e!==void 0;e=t.peekChild(r.indent)){t.reader.takeSignificant();let r=i(e.content);r===`key`?u=parseKey(t,e):r===`parent`?d=l(e.content.substring(6),n(e),t):pushMapping(t,e,c)}return{kind:`FromSyntax`,events:s,key:u,parentKey:d,mappings:c,location:n(r)}}function parseJoin(t,r){let i=p.exec(r.content);if(i===null)return t.error(e.InvalidJoinDeclaration,`Invalid join declaration '${r.content}' - expected 'join <property> on <key>'`,n(r)),t.skipBlock(r.indent),{kind:`JoinSyntax`,property:``,on:``,events:[],location:n(r)};let a=[];for(let i=t.peekChild(r.indent);i!==void 0;i=t.peekChild(r.indent)){t.reader.takeSignificant();let r=m.exec(i.content);if(r===null){t.error(e.JoinWithoutEvent,`Expected 'with <EventType>' in join block, got '${i.content}'`,n(i)),t.skipBlock(i.indent);continue}let{autoMap:s,mappings:c}=parseMappingBlock(t,i);a.push({kind:`JoinEventSyntax`,event:o(r[1]),autoMap:s,mappings:c,location:n(i)})}return{kind:`JoinSyntax`,property:o(i[1]),on:o(i[2]),events:a,location:n(r)}}function parseChildren(t,r){let i=h.exec(r.content);if(i===null)return t.error(e.InvalidChildrenDeclaration,`Invalid children declaration '${r.content}' - expected 'children <collection> identified by <key>'`,n(r)),t.skipBlock(r.indent),{kind:`ChildrenSyntax`,property:``,autoMap:`Inherit`,blocks:[],location:n(r)};let{autoMap:a,blocks:s}=parseChildBlocks(t,r);return{kind:`ChildrenSyntax`,property:o(i[1]),identifiedBy:l(i[2],n(r),t),autoMap:a,blocks:s,location:n(r)}}function parseNested(t,r){let i=g.exec(r.content);if(i===null)return t.error(e.InvalidNestedDeclaration,`Invalid nested declaration '${r.content}' - expected 'nested <property>'`,n(r)),t.skipBlock(r.indent),{kind:`NestedSyntax`,property:``,autoMap:`Inherit`,blocks:[],location:n(r)};let a=o(i[1]),{autoMap:s,blocks:c}=parseChildBlocks(t,r);return c.some(e=>e.kind===`FromSyntax`)||t.error(e.NestedBlockWithoutFrom,`Nested block '${a}' must contain at least one 'from' directive`,n(r)),{kind:`NestedSyntax`,property:a,autoMap:s,blocks:c,location:n(r)}}function parseChildBlocks(e,t){let n=[],r=`Inherit`;for(let i=e.peekChild(t.indent);i!==void 0;i=e.peekChild(t.indent)){if(e.reader.takeSignificant(),i.content===`automap`){r=`Enabled`;continue}if(i.content===`no automap`){r=`Disabled`;continue}let t=parseBlock(e,i,!0);t!==void 0&&n.push(t)}return{autoMap:r,blocks:n}}function parseRemove(t,r){let a=v.exec(r.content);if(a!==null)return{kind:`RemoveViaJoinSyntax`,event:o(a[1]),key:a[2]===void 0?null:l(a[2],n(r),t),location:n(r)};let s=_.exec(r.content);if(s===null){t.error(e.InvalidRemoveDeclaration,`Invalid remove declaration '${r.content}' - expected 'remove with <EventType>' or 'remove via join on <EventType>'`,n(r)),t.skipBlock(r.indent);return}let c=s[2]===void 0?null:l(s[2],n(r),t),u=null,d=null;for(let a=t.peekChild(r.indent);a!==void 0;a=t.peekChild(r.indent))if(t.reader.takeSignificant(),i(a.content)===`parent`)d=l(a.content.substring(6),n(a),t);else if(i(a.content)===`key`){(c!==null||u!==null)&&t.error(e.InvalidReadModelKeyLookup,`A removal can only declare one key.`,n(a));let r=parseKey(t,a);r.kind===`CompositeKeySyntax`?u=r:c=r.expression}else t.error(e.UnknownRemoveDirective,`Unexpected '${a.content}' in remove block - only 'parent' or 'key' is allowed`,n(a));return{kind:`RemoveWithSyntax`,event:o(s[1]),key:c,...u===null?{}:{partsKey:u},parentKey:d,location:n(r)}}function parseClearWith(t,r){let i=y.exec(r.content);return i===null?(t.error(e.InvalidClearDeclaration,`Invalid clear declaration '${r.content}' - expected 'clear with <EventType>'`,n(r)),{kind:`ClearWithSyntax`,event:``,location:n(r)}):{kind:`ClearWithSyntax`,event:o(i[1]),location:n(r)}}function parseVariant(t,r){let a=b.exec(r.content);if(a===null)return t.error(e.InvalidProjectionVariantDeclaration,`Invalid variant declaration '${r.content}' - expected 'variant <Name>'`,n(r)),t.skipBlock(r.indent),{kind:`ProjectionVariantSyntax`,name:i(r.content),entersOn:[],blocks:[],location:n(r)};let s=o(a[1]),c=[],l=[];for(let a=t.peekChild(r.indent);a!==void 0;a=t.peekChild(r.indent)){t.reader.takeSignificant();let r=i(a.content);if(r===`enters`)c.push(parseEntersOn(t,a));else if(r===`variant`)t.error(e.NestedProjectionVariantNotAllowed,`A variant cannot be declared inside another variant`,n(a)),t.skipBlock(a.indent);else{let e=parseBlock(t,a,!1);e!==void 0&&l.push(e)}}return c.length===0&&t.error(e.VariantRequiresEnteringEvent,`Variant '${s}' must declare at least one 'enters on' event`,n(r)),{kind:`ProjectionVariantSyntax`,name:s,entersOn:c,blocks:l,location:n(r)}}function parseEntersOn(t,r){let i=x.exec(r.content);return i===null?(t.error(e.InvalidEntersOnDeclaration,`Invalid 'enters on' declaration '${r.content}' - expected 'enters on <EventType> [key <expression>]'`,n(r)),t.skipBlock(r.indent),{kind:`ProjectionEntersOnSyntax`,event:``,key:null,location:n(r)}):{kind:`ProjectionEntersOnSyntax`,event:o(i[1]),key:i[2]===void 0?null:l(i[2],n(r),t),location:n(r)}}function parseKey(t,r){let i=r.content.substring(3).trim();if(t.peekChild(r.indent)===void 0)return{kind:`ExpressionKeySyntax`,expression:l(i,n(r),t),location:n(r)};i.endsWith(`{`)&&t.information(e.RedundantCompositeKeyBraces,`Write the composite key without braces; the indented parts already belong to the key.`,n(r));let a=[];for(let s=t.peekChild(r.indent);s!==void 0;s=t.peekChild(r.indent)){if(t.reader.takeSignificant(),s.content===`}`)continue;let r=T.exec(s.content);if(r===null){t.sourceOptions.numericMode===`exact`&&t.error(e.InvalidCompositeKeyPart,`Invalid composite key part '${s.content}' - expected '<property> = <expression>'`,n(s));continue}let c=l(r[2],n(s),t);t.sourceOptions.numericMode===`exact`&&i.replace(/\{$/,``).trim().length>0&&c.kind===`TemplateExpressionSyntax`&&t.error(e.TemplateInCompositeKey,`Template expressions are not allowed in composite keys`,n(s)),a.push({kind:`KeyPartSyntax`,property:o(r[1]),expression:c,location:n(s)})}let s=t.reader.peekSignificant();return s!==void 0&&s.indent===r.indent&&s.content===`}`&&t.reader.takeSignificant(),t.sourceOptions.numericMode===`exact`&&a.length===0&&t.error(e.EmptyCompositeKey,`Composite keys must contain at least one part`,n(r)),{kind:`CompositeKeySyntax`,type:i.replace(/\{$/,``).trim(),parts:a,location:n(r)}}function parseMappingBlock(e,t,n=()=>!1){let r=`Inherit`,i=[];for(let a=e.peekChild(t.indent);a!==void 0;a=e.peekChild(t.indent))e.reader.takeSignificant(),a.content===`automap`?r=`Enabled`:a.content===`no automap`?r=`Disabled`:n(a)||pushMapping(e,a,i);return{autoMap:r,mappings:i}}function pushMapping(t,i,a){let s=n(i),c=S.exec(i.content);if(c!==null){c[1]!==`clear`||c[2]!==`with`?a.push({kind:E[c[1]],property:o(c[2]),location:s}):t.sourceOptions.numericMode===`exact`&&t.error(e.InvalidProjectionMapping,`Invalid mapping '${i.content}' - 'clear with' is a block directive and needs an event type; to clear a property named 'with', write 'clear @with'`,s,r(`text`,i.content));return}let u=C.exec(i.content);if(u!==null){a.push({kind:u[1]===`add`?`AddMappingSyntax`:`SubtractMappingSyntax`,property:o(u[2]),value:l(u[3],s,t),...u[4]===void 0?{}:{factor:l(u[4],s,t)},location:s});return}let d=w.exec(i.content)??T.exec(i.content);d===null?t.sourceOptions.numericMode===`exact`&&t.error(e.InvalidProjectionMapping,`Invalid mapping '${i.content}'`,s,r(`text`,i.content)):a.push({kind:`SetMappingSyntax`,property:o(d[1]),source:l(d[2],s,t),location:s})}export{parseProjection};
|
|
2
2
|
//# sourceMappingURL=ProjectionParser.js.map
|