@cratis/screenplay-language 4.192.0 → 4.194.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.
Files changed (68) hide show
  1. package/dist/bundles/command-read-completions.js +5 -0
  2. package/dist/bundles/command-read-completions.js.map +1 -0
  3. package/dist/bundles/compiler/Diagnostics/DiagnosticArgument.js +2 -0
  4. package/dist/bundles/compiler/Diagnostics/DiagnosticArgument.js.map +1 -0
  5. package/dist/bundles/compiler/Diagnostics/DiagnosticCodes.js +1 -1
  6. package/dist/bundles/compiler/Diagnostics/DiagnosticCodes.js.map +1 -1
  7. package/dist/bundles/compiler/Files/PlayFolderMerge.js +1 -1
  8. package/dist/bundles/compiler/Files/PlayFolderMerge.js.map +1 -1
  9. package/dist/bundles/compiler/Parsing/CaptureParser.js +1 -1
  10. package/dist/bundles/compiler/Parsing/CaptureParser.js.map +1 -1
  11. package/dist/bundles/compiler/Parsing/ParserContext.js +1 -1
  12. package/dist/bundles/compiler/Parsing/ParserContext.js.map +1 -1
  13. package/dist/bundles/compiler/Parsing/ProducesParser.js +1 -1
  14. package/dist/bundles/compiler/Parsing/ProducesParser.js.map +1 -1
  15. package/dist/bundles/compiler/Parsing/ProjectionParser.js +1 -1
  16. package/dist/bundles/compiler/Parsing/ProjectionParser.js.map +1 -1
  17. package/dist/bundles/compiler/Parsing/ProjectionTargetValidator.js +1 -1
  18. package/dist/bundles/compiler/Parsing/ProjectionTargetValidator.js.map +1 -1
  19. package/dist/bundles/compiler/Parsing/ReactionParser.js +1 -1
  20. package/dist/bundles/compiler/Parsing/ReactionParser.js.map +1 -1
  21. package/dist/bundles/compiler/Parsing/ScreenplayParser.js +1 -1
  22. package/dist/bundles/compiler/Parsing/ScreenplayParser.js.map +1 -1
  23. package/dist/bundles/compiler/Parsing/SpecificationCaseParser.js +1 -1
  24. package/dist/bundles/compiler/Parsing/SpecificationCaseParser.js.map +1 -1
  25. package/dist/bundles/compiler/Parsing/SpecificationCaseValidator.js +1 -1
  26. package/dist/bundles/compiler/Parsing/SpecificationCaseValidator.js.map +1 -1
  27. package/dist/bundles/compiler/Parsing/SpecificationCommandExamples.js +1 -1
  28. package/dist/bundles/compiler/Parsing/SpecificationCommandExamples.js.map +1 -1
  29. package/dist/bundles/compiler/Parsing/SpecificationExampleParser.js +1 -1
  30. package/dist/bundles/compiler/Parsing/SpecificationExampleParser.js.map +1 -1
  31. package/dist/bundles/compiler/Parsing/SpecificationParser.js +1 -1
  32. package/dist/bundles/compiler/Parsing/SpecificationParser.js.map +1 -1
  33. package/dist/bundles/compiler/Parsing/SpecificationResponseParser.js +1 -1
  34. package/dist/bundles/compiler/Parsing/SpecificationResponseParser.js.map +1 -1
  35. package/dist/bundles/compiler/Parsing/SpecificationStreamValidator.js +1 -1
  36. package/dist/bundles/compiler/Parsing/SpecificationStreamValidator.js.map +1 -1
  37. package/dist/bundles/compiler/Syntax/Structure.js.map +1 -1
  38. package/dist/bundles/compiler/Syntax/SyntaxCollections.js +1 -1
  39. package/dist/bundles/compiler/Syntax/SyntaxCollections.js.map +1 -1
  40. package/dist/bundles/compiler/Syntax/SyntaxJson.js +1 -1
  41. package/dist/bundles/compiler/Syntax/SyntaxJson.js.map +1 -1
  42. package/dist/bundles/compiler/index.js +1 -1
  43. package/dist/bundles/completion-items.js +1 -1
  44. package/dist/bundles/completion-items.js.map +1 -1
  45. package/dist/bundles/completion-planner.js +2 -2
  46. package/dist/bundles/completion-planner.js.map +1 -1
  47. package/dist/bundles/diagnostic-codes.js +1 -1
  48. package/dist/bundles/diagnostic-codes.js.map +1 -1
  49. package/dist/bundles/keyword-docs.js +1 -1
  50. package/dist/bundles/keyword-docs.js.map +1 -1
  51. package/dist/bundles/language.js +1 -1
  52. package/dist/bundles/language.js.map +1 -1
  53. package/dist/bundles/response-analysis.js +2 -2
  54. package/dist/bundles/response-analysis.js.map +1 -1
  55. package/dist/bundles/tokens.js +1 -1
  56. package/dist/bundles/tokens.js.map +1 -1
  57. package/dist/bundles/validation.js +1 -1
  58. package/dist/bundles/validation.js.map +1 -1
  59. package/dist/command-read-completions.d.ts +4 -0
  60. package/dist/command-read-completions.d.ts.map +1 -0
  61. package/dist/completion-items.d.ts.map +1 -1
  62. package/dist/completion-planner.d.ts.map +1 -1
  63. package/dist/diagnostic-codes.d.ts +1 -0
  64. package/dist/diagnostic-codes.d.ts.map +1 -1
  65. package/dist/keyword-docs.d.ts.map +1 -1
  66. package/dist/language.d.ts.map +1 -1
  67. package/dist/tokens.d.ts.map +1 -1
  68. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"SpecificationCaseParser.js","names":["caseHeader","pattern","assignment","reference","text","context","DiagnosticCodes","location","parseMappingSource","nativeIdentifiers","match","offset","line","property","parseProperty","locationOf","child","values","owner","valueLocation","source","parseConcrete","value","nested","parameters","specification","cases","index","prior","parameter","row","references","copies","result","item","key"],"sources":["../../../../../../Compiler/Parsing/SpecificationCaseParser.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 { CaseValueExpressionSyntax, ExpressionSyntax, PropertyMappingSyntax } from '../Syntax/Expressions';\nimport { SpecificationCaseSyntax, SpecificationParameterSyntax, SpecificationSyntax } from '../Syntax/Specifications';\nimport { pattern } from '../Text/patterns';\nimport { parseMappingSource } from './ExpressionParser';\nimport { ParserContext } from './ParserContext';\nimport { parseProperty } from './PropertyLineParser';\nimport { locationOf, SourceLine } from './SourceLine';\nimport { parseConcrete } from './SpecificationResponseParser';\n\nconst caseHeader = new RegExp(pattern('^case\\\\s+([A-Za-z_]\\\\w*)(?:\\\\s+(?<property>[\\\\w.]+)\\\\s*=(?!=|>)\\\\s*(?<value>.+))?$').source, 'du');\nconst assignment = pattern('^([\\\\w.]+)\\\\s*=(?!=|>)\\\\s*(.+)$');\nconst reference = pattern('^case\\\\.([a-z_]\\\\w*)$');\n\nexport function containsCaseReference(text: string): boolean {\n return /\\bcase\\.[a-z_]\\w*/.test(text.replace(/\"(?:[^\"\\\\]|\\\\.)*\"|'(?:[^'\\\\]|\\\\.)*'/g, ''));\n}\n\nexport function parseSpecificationValue(text: string, location: SourceLocation, context: ParserContext, nativeIdentifiers = false): ExpressionSyntax {\n if (!text.startsWith('case.')) {\n if (containsCaseReference(text)) context.error(DiagnosticCodes.InvalidSpecificationCaseReference, 'A case reference fills a whole value position; it cannot occur inside a structured value or expression.', location);\n return parseMappingSource(text, location, context, nativeIdentifiers);\n }\n const match = reference.exec(text);\n if (match === null) context.error(DiagnosticCodes.InvalidSpecificationCaseReference, \"A case reference fills a whole value position: 'case.<parameter>'.\", location);\n return { kind: 'CaseValueExpressionSyntax', parameter: match?.[1] ?? text.substring(5), location };\n}\n\nexport function parseParameter(context: ParserContext, line: SourceLine): SpecificationParameterSyntax | null {\n const offset = line.content.indexOf(' ') + 1;\n const property = offset > 0 ? parseProperty(context, { ...line, content: line.content.substring(offset), indent: line.indent + offset }) : undefined;\n if (property === undefined || property.isGenerated || property.isIdentifier) {\n context.error(DiagnosticCodes.InvalidSpecificationParameter, \"Expected 'parameter <name> <Type>', with optional collection and optional modifiers.\", locationOf(line));\n context.skipOpaqueBlock(line.indent);\n return null;\n }\n const child = context.peekChild(line.indent);\n if (child !== undefined) {\n context.error(DiagnosticCodes.InvalidSpecificationParameter, 'A parameter has no body or default.', locationOf(child));\n context.skipOpaqueBlock(line.indent);\n }\n return { kind: 'SpecificationParameterSyntax', name: property.name, type: property.type, location: locationOf(line) };\n}\n\nexport function parseCase(context: ParserContext, line: SourceLine): SpecificationCaseSyntax | null {\n const match = caseHeader.exec(line.content);\n if (match === null) {\n context.error(DiagnosticCodes.InvalidSpecificationCase, \"Expected 'case <Name>' with at most one inline parameter assignment.\", locationOf(line));\n context.skipOpaqueBlock(line.indent);\n return null;\n }\n const values: PropertyMappingSyntax[] = [];\n const add = (property: string, text: string, owner: SourceLine) => {\n const location = locationOf(owner);\n const valueLocation = { ...location, column: location.column + owner.content.indexOf(text, owner.content.indexOf('=') + 1) };\n if (text.startsWith('case.')) {\n context.error(DiagnosticCodes.InvalidSpecificationCaseValue, 'A case assigns concrete values, not case references.', valueLocation);\n return;\n }\n const source = parseConcrete(context, text, valueLocation, DiagnosticCodes.InvalidSpecificationCaseValue);\n if (source !== null) values.push({ kind: 'PropertyMappingSyntax', property, source, location: owner === line ? { ...location, column: location.column + match.indices!.groups!.property[0] } : location });\n };\n if (match.groups?.property !== undefined) add(match.groups.property, match.groups.value, line);\n for (let child = context.peekChild(line.indent); child !== undefined; child = context.peekChild(line.indent)) {\n context.reader.takeSignificant();\n const value = assignment.exec(child.content);\n if (value === null) {\n context.error(DiagnosticCodes.InvalidSpecificationCaseAssignment, \"Expected '<parameter> = <concrete value>' in a case.\", locationOf(child));\n context.skipOpaqueBlock(child.indent);\n continue;\n }\n add(value[1], value[2], child);\n const nested = context.peekChild(child.indent);\n if (nested !== undefined) {\n context.error(DiagnosticCodes.InvalidSpecificationCaseValue, 'A case value must fit on one line.', locationOf(nested));\n context.skipOpaqueBlock(child.indent);\n }\n }\n return { kind: 'SpecificationCaseSyntax', name: match[1], values, location: locationOf(line) };\n}\n\nexport function caseReferences(value: unknown): CaseValueExpressionSyntax[] {\n if (Array.isArray(value)) return value.flatMap(caseReferences);\n if (value === null || typeof value !== 'object') return [];\n if ('kind' in value && value.kind === 'CaseValueExpressionSyntax') return [value as CaseValueExpressionSyntax];\n return Object.values(value).flatMap(caseReferences);\n}\n\nexport function validateTable(specification: SpecificationSyntax, context: ParserContext): void {\n const parameters = specification.parameters ?? [];\n const cases = specification.cases ?? [];\n if ((parameters.length === 0) !== (cases.length === 0)) context.error(DiagnosticCodes.IncompleteSpecificationTable, 'A specification table requires parameters and at least one case.', specification.location);\n parameters.forEach((parameter, index) => {\n if (parameters.slice(0, index).some(prior => prior.name === parameter.name)) context.error(DiagnosticCodes.DuplicateSpecificationParameter, `Parameter '${parameter.name}' is declared more than once.`, parameter.location);\n });\n cases.forEach((row, index) => {\n if (cases.slice(0, index).some(prior => prior.name === row.name)) context.error(DiagnosticCodes.DuplicateSpecificationCase, `Case '${row.name}' is declared more than once.`, row.location);\n for (const value of row.values.filter(value => !parameters.some(parameter => parameter.name === value.property))) context.error(DiagnosticCodes.InvalidSpecificationCaseAssignment, `Case '${row.name}' assigns undeclared parameter '${value.property}'.`, value.location);\n for (const parameter of parameters.filter(parameter => row.values.filter(value => value.property === parameter.name).length !== 1)) context.error(DiagnosticCodes.InvalidSpecificationCaseAssignment, `Case '${row.name}' must assign parameter '${parameter.name}' exactly once.`, row.location);\n });\n const references = caseReferences(specification);\n for (const value of references) {\n if (cases.length === 0 || !parameters.some(parameter => parameter.name === value.parameter)) context.error(DiagnosticCodes.InvalidSpecificationCaseReference, `Case reference '${value.parameter}' requires a declared parameter in a specification table.`, value.location);\n }\n for (const parameter of parameters.filter(parameter => !references.some(value => value.parameter === parameter.name))) context.warning(DiagnosticCodes.UnusedSpecificationParameter, `Parameter '${parameter.name}' is never referenced.`, parameter.location);\n for (const value of caseReferences(specification.whenRedelivered)) context.error(DiagnosticCodes.InvalidSpecificationCaseReference, 'Case references are not permitted in redelivery locators.', value.location);\n}\n\nexport function substituteCase<T>(value: T, row: SpecificationCaseSyntax, copies = new WeakMap<object, unknown>()): T {\n if (value !== null && typeof value === 'object' && copies.has(value)) return copies.get(value) as T;\n if (Array.isArray(value)) {\n const result = value.map(item => substituteCase(item, row, copies));\n copies.set(value, result);\n return result as T;\n }\n if (value === null || typeof value !== 'object' || !('kind' in value)) return value;\n if (value.kind === 'CaseValueExpressionSyntax') {\n const parameter = (value as unknown as CaseValueExpressionSyntax).parameter;\n return (row.values.find(value => value.property === parameter)?.source ?? value) as T;\n }\n const result = Object.fromEntries(Object.entries(value).map(([key, item]) => [key, substituteCase(item, row, copies)]));\n if (value.kind === 'SpecificationErrorSyntax' && 'caseValue' in value && value.caseValue !== undefined) {\n const source = result.caseValue as ExpressionSyntax;\n result.name = source.kind === 'LiteralExpressionSyntax' ? source.value : null;\n delete result.caseValue;\n }\n copies.set(value, result);\n return result as T;\n}\n"],"mappings":"wYAcA,MAAMA,EAAa,IAAI,OAAOC,EAAQ,oFAAoF,CAAC,CAAC,OAAQ,IAAI,EAClIC,EAAaD,EAAQ,iCAAiC,EACtDE,EAAYF,EAAQ,uBAAuB,EAEjD,SAAgB,sBAAsB,EAAuB,CACzD,MAAO,oBAAoB,KAAKG,EAAK,QAAQ,uCAAwC,EAAE,CAAC,CAC5F,CAEA,SAAgB,wBAAwB,EAAc,EAA0B,EAAwB,EAAoB,GAAyB,CACjJ,GAAI,CAACA,EAAK,WAAW,OAAO,EAExB,OADI,sBAAsBA,CAAI,GAAGC,EAAQ,MAAMC,EAAgB,kCAAmC,0GAA2GC,CAAQ,EAC9MC,EAAmBJ,EAAMG,EAAUF,EAASI,CAAiB,EAExE,IAAMC,EAAQP,EAAU,KAAKC,CAAI,EAEjC,OADIM,IAAU,MAAML,EAAQ,MAAMC,EAAgB,kCAAmC,qEAAsEC,CAAQ,EAC5J,CAAE,KAAM,4BAA6B,UAAWG,IAAQ,IAAMN,EAAK,UAAU,CAAC,EAAG,UAAS,CACrG,CAEA,SAAgB,eAAe,EAAwB,EAAuD,CAC1G,IAAMO,EAASC,EAAK,QAAQ,QAAQ,GAAG,EAAI,EACrCC,EAAWF,EAAS,EAAIG,EAAcT,EAAS,CAAE,GAAGO,EAAM,QAASA,EAAK,QAAQ,UAAUD,CAAM,EAAG,OAAQC,EAAK,OAASD,CAAO,CAAC,EAAI,IAAA,GAC3I,GAAIE,IAAa,IAAA,IAAaA,EAAS,aAAeA,EAAS,aAG3D,OAFAR,EAAQ,MAAMC,EAAgB,8BAA+B,uFAAwFS,EAAWH,CAAI,CAAC,EACrKP,EAAQ,gBAAgBO,EAAK,MAAM,EAC5B,KAEX,IAAMI,EAAQX,EAAQ,UAAUO,EAAK,MAAM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,CAAK,EAC7F,GAAI,MAAM,QAAQA,CAAK,EAAG,CACtB,IAAMW,EAASX,EAAM,IAAI,GAAQ,eAAeY,EAAMJ,EAAKE,CAAM,CAAC,EAElE,OADAA,EAAO,IAAIV,EAAOW,CAAM,EACjBA,CACX,CACA,GAAsB,OAAOX,GAAU,WAAnCA,GAA+C,EAAE,SAAUA,GAAQ,OAAOA,EAC9E,GAAIA,EAAM,OAAS,4BAA6B,CAC5C,IAAMO,EAAaP,EAA+C,UAClE,OAAQQ,EAAI,OAAO,KAAK,GAASR,EAAM,WAAaO,CAAS,CAAC,EAAE,QAAUP,CAC9E,CACA,IAAMW,EAAS,OAAO,YAAY,OAAO,QAAQX,CAAK,CAAC,CAAC,KAAK,CAACa,EAAKD,KAAU,CAACC,EAAK,eAAeD,EAAMJ,EAAKE,CAAM,CAAC,CAAC,CAAC,EACtH,GAAIV,EAAM,OAAS,4BAA8B,cAAeA,GAASA,EAAM,YAAc,IAAA,GAAW,CACpG,IAAMF,EAASa,EAAO,UACtB,EAAO,KAAOb,EAAO,OAAS,0BAA4BA,EAAO,MAAQ,KACzE,OAAOa,EAAO,SAClB,CAEA,OADAD,EAAO,IAAIV,EAAOW,CAAM,EACjBA,CACX"}
1
+ {"version":3,"file":"SpecificationCaseParser.js","names":["caseHeader","pattern","assignment","reference","text","context","DiagnosticCodes","location","parseMappingSource","nativeIdentifiers","match","offset","line","property","parseProperty","locationOf","child","values","owner","valueLocation","diagnosticText","source","parseConcrete","value","nested","parameters","specification","cases","index","prior","parameter","row","references","copies","result","item","key"],"sources":["../../../../../../Compiler/Parsing/SpecificationCaseParser.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 { diagnosticText } from '../Diagnostics/DiagnosticArgument';\nimport { DiagnosticCodes } from '../Diagnostics/DiagnosticCodes';\nimport { SourceLocation } from '../Diagnostics/SourceLocation';\nimport { CaseValueExpressionSyntax, ExpressionSyntax, PropertyMappingSyntax } from '../Syntax/Expressions';\nimport { SpecificationCaseSyntax, SpecificationParameterSyntax, SpecificationSyntax } from '../Syntax/Specifications';\nimport { pattern } from '../Text/patterns';\nimport { parseMappingSource } from './ExpressionParser';\nimport { ParserContext } from './ParserContext';\nimport { parseProperty } from './PropertyLineParser';\nimport { locationOf, SourceLine } from './SourceLine';\nimport { parseConcrete } from './SpecificationResponseParser';\n\nconst caseHeader = new RegExp(pattern('^case\\\\s+([A-Za-z_]\\\\w*)(?:\\\\s+(?<property>[\\\\w.]+)\\\\s*=(?!=|>)\\\\s*(?<value>.+))?$').source, 'du');\nconst assignment = pattern('^([\\\\w.]+)\\\\s*=(?!=|>)\\\\s*(.+)$');\nconst reference = pattern('^case\\\\.([a-z_]\\\\w*)$');\n\nexport function containsCaseReference(text: string): boolean {\n return /\\bcase\\.[a-z_]\\w*/.test(text.replace(/\"(?:[^\"\\\\]|\\\\.)*\"|'(?:[^'\\\\]|\\\\.)*'/g, ''));\n}\n\nexport function parseSpecificationValue(text: string, location: SourceLocation, context: ParserContext, nativeIdentifiers = false): ExpressionSyntax {\n if (!text.startsWith('case.')) {\n if (containsCaseReference(text)) context.error(DiagnosticCodes.InvalidSpecificationCaseReference, 'A case reference fills a whole value position; it cannot occur inside a structured value or expression.', location);\n return parseMappingSource(text, location, context, nativeIdentifiers);\n }\n const match = reference.exec(text);\n if (match === null) context.error(DiagnosticCodes.InvalidSpecificationCaseReference, \"A case reference fills a whole value position: 'case.<parameter>'.\", location);\n return { kind: 'CaseValueExpressionSyntax', parameter: match?.[1] ?? text.substring(5), location };\n}\n\nexport function parseParameter(context: ParserContext, line: SourceLine): SpecificationParameterSyntax | null {\n const offset = line.content.indexOf(' ') + 1;\n const property = offset > 0 ? parseProperty(context, { ...line, content: line.content.substring(offset), indent: line.indent + offset }) : undefined;\n if (property === undefined || property.isGenerated || property.isIdentifier) {\n context.error(DiagnosticCodes.InvalidSpecificationParameter, \"Expected 'parameter <name> <Type>', with optional collection and optional modifiers.\", locationOf(line));\n context.skipOpaqueBlock(line.indent);\n return null;\n }\n const child = context.peekChild(line.indent);\n if (child !== undefined) {\n context.error(DiagnosticCodes.InvalidSpecificationParameter, 'A parameter has no body or default.', locationOf(child));\n context.skipOpaqueBlock(line.indent);\n }\n return { kind: 'SpecificationParameterSyntax', name: property.name, type: property.type, location: locationOf(line) };\n}\n\nexport function parseCase(context: ParserContext, line: SourceLine): SpecificationCaseSyntax | null {\n const match = caseHeader.exec(line.content);\n if (match === null) {\n context.error(DiagnosticCodes.InvalidSpecificationCase, \"Expected 'case <Name>' with at most one inline parameter assignment.\", locationOf(line));\n context.skipOpaqueBlock(line.indent);\n return null;\n }\n const values: PropertyMappingSyntax[] = [];\n const add = (property: string, text: string, owner: SourceLine) => {\n const location = locationOf(owner);\n const valueLocation = { ...location, column: location.column + owner.content.indexOf(text, owner.content.indexOf('=') + 1) };\n if (text.startsWith('case.')) {\n context.error(DiagnosticCodes.InvalidSpecificationCaseValue, 'A case assigns concrete values, not case references.', valueLocation, diagnosticText('text', text));\n return;\n }\n const source = parseConcrete(context, text, valueLocation, DiagnosticCodes.InvalidSpecificationCaseValue);\n if (source !== null) values.push({ kind: 'PropertyMappingSyntax', property, source, location: owner === line ? { ...location, column: location.column + match.indices!.groups!.property[0] } : location });\n };\n if (match.groups?.property !== undefined) add(match.groups.property, match.groups.value, line);\n for (let child = context.peekChild(line.indent); child !== undefined; child = context.peekChild(line.indent)) {\n context.reader.takeSignificant();\n const value = assignment.exec(child.content);\n if (value === null) {\n context.error(DiagnosticCodes.InvalidSpecificationCaseAssignment, \"Expected '<parameter> = <concrete value>' in a case.\", locationOf(child));\n context.skipOpaqueBlock(child.indent);\n continue;\n }\n add(value[1], value[2], child);\n const nested = context.peekChild(child.indent);\n if (nested !== undefined) {\n context.error(DiagnosticCodes.InvalidSpecificationCaseValue, 'A case value must fit on one line.', locationOf(nested), { ...diagnosticText('case', match[1]), ...diagnosticText('parameter', value[1]), ...diagnosticText('text', nested.content) });\n context.skipOpaqueBlock(child.indent);\n }\n }\n return { kind: 'SpecificationCaseSyntax', name: match[1], values, location: locationOf(line) };\n}\n\nexport function caseReferences(value: unknown): CaseValueExpressionSyntax[] {\n if (Array.isArray(value)) return value.flatMap(caseReferences);\n if (value === null || typeof value !== 'object') return [];\n if ('kind' in value && value.kind === 'CaseValueExpressionSyntax') return [value as CaseValueExpressionSyntax];\n return Object.values(value).flatMap(caseReferences);\n}\n\nexport function validateTable(specification: SpecificationSyntax, context: ParserContext): void {\n const parameters = specification.parameters ?? [];\n const cases = specification.cases ?? [];\n if ((parameters.length === 0) !== (cases.length === 0)) context.error(DiagnosticCodes.IncompleteSpecificationTable, 'A specification table requires parameters and at least one case.', specification.location);\n parameters.forEach((parameter, index) => {\n if (parameters.slice(0, index).some(prior => prior.name === parameter.name)) context.error(DiagnosticCodes.DuplicateSpecificationParameter, `Parameter '${parameter.name}' is declared more than once.`, parameter.location);\n });\n cases.forEach((row, index) => {\n if (cases.slice(0, index).some(prior => prior.name === row.name)) context.error(DiagnosticCodes.DuplicateSpecificationCase, `Case '${row.name}' is declared more than once.`, row.location);\n for (const value of row.values.filter(value => !parameters.some(parameter => parameter.name === value.property))) context.error(DiagnosticCodes.InvalidSpecificationCaseAssignment, `Case '${row.name}' assigns undeclared parameter '${value.property}'.`, value.location);\n for (const parameter of parameters.filter(parameter => row.values.filter(value => value.property === parameter.name).length !== 1)) context.error(DiagnosticCodes.InvalidSpecificationCaseAssignment, `Case '${row.name}' must assign parameter '${parameter.name}' exactly once.`, row.location);\n });\n const references = caseReferences(specification);\n for (const value of references) {\n if (cases.length === 0 || !parameters.some(parameter => parameter.name === value.parameter)) context.error(DiagnosticCodes.InvalidSpecificationCaseReference, `Case reference '${value.parameter}' requires a declared parameter in a specification table.`, value.location);\n }\n for (const parameter of parameters.filter(parameter => !references.some(value => value.parameter === parameter.name))) context.warning(DiagnosticCodes.UnusedSpecificationParameter, `Parameter '${parameter.name}' is never referenced.`, parameter.location);\n for (const value of caseReferences(specification.whenRedelivered)) context.error(DiagnosticCodes.InvalidSpecificationCaseReference, 'Case references are not permitted in redelivery locators.', value.location);\n}\n\nexport function substituteCase<T>(value: T, row: SpecificationCaseSyntax, copies = new WeakMap<object, unknown>()): T {\n if (value !== null && typeof value === 'object' && copies.has(value)) return copies.get(value) as T;\n if (Array.isArray(value)) {\n const result = value.map(item => substituteCase(item, row, copies));\n copies.set(value, result);\n return result as T;\n }\n if (value === null || typeof value !== 'object' || !('kind' in value)) return value;\n if (value.kind === 'CaseValueExpressionSyntax') {\n const parameter = (value as unknown as CaseValueExpressionSyntax).parameter;\n return (row.values.find(value => value.property === parameter)?.source ?? value) as T;\n }\n const result = Object.fromEntries(Object.entries(value).map(([key, item]) => [key, substituteCase(item, row, copies)]));\n if (value.kind === 'SpecificationErrorSyntax' && 'caseValue' in value && value.caseValue !== undefined) {\n const source = result.caseValue as ExpressionSyntax;\n result.name = source.kind === 'LiteralExpressionSyntax' ? source.value : null;\n delete result.caseValue;\n }\n copies.set(value, result);\n return result as T;\n}\n"],"mappings":"8cAeA,MAAMA,EAAa,IAAI,OAAOC,EAAQ,oFAAoF,CAAC,CAAC,OAAQ,IAAI,EAClIC,EAAaD,EAAQ,iCAAiC,EACtDE,EAAYF,EAAQ,uBAAuB,EAEjD,SAAgB,sBAAsB,EAAuB,CACzD,MAAO,oBAAoB,KAAKG,EAAK,QAAQ,uCAAwC,EAAE,CAAC,CAC5F,CAEA,SAAgB,wBAAwB,EAAc,EAA0B,EAAwB,EAAoB,GAAyB,CACjJ,GAAI,CAACA,EAAK,WAAW,OAAO,EAExB,OADI,sBAAsBA,CAAI,GAAGC,EAAQ,MAAMC,EAAgB,kCAAmC,0GAA2GC,CAAQ,EAC9MC,EAAmBJ,EAAMG,EAAUF,EAASI,CAAiB,EAExE,IAAMC,EAAQP,EAAU,KAAKC,CAAI,EAEjC,OADIM,IAAU,MAAML,EAAQ,MAAMC,EAAgB,kCAAmC,qEAAsEC,CAAQ,EAC5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AM,OAAS,4BAA8B,cAAeA,GAASA,EAAM,YAAc,IAAA,GAAW,CACpG,IAAMF,EAASa,EAAO,UACtB,EAAO,KAAOb,EAAO,OAAS,0BAA4BA,EAAO,MAAQ,KACzE,OAAOa,EAAO,SAClB,CAEA,OADAD,EAAO,IAAIV,EAAOW,CAAM,EACjBA,CACX"}
@@ -1,2 +1,2 @@
1
- import"../../_virtual/_virtual/_rolldown/runtime.js";import{DiagnosticCodes as e}from"../Diagnostics/DiagnosticCodes.js";import{AuthoringProductionResolver as t}from"../Syntax/AuthoringProductionResolver.js";import{EventSourceCatalog as n}from"../Syntax/EventSourceCatalog.js";import{specificationExamples as r}from"./SpecificationCommandExamples.js";import{compatibleValue as i}from"./ResponseValidator.js";import{commandDestinationType as a}from"./CommandDestinationTypes.js";import{RefusalDeclarations as o}from"./RefusalDeclarations.js";const s=/* @__PURE__ */ new Set([`Uuid`,`String`,`Int`,`Decimal`,`Bool`,`Date`,`DateTime`]);function validateSpecificationCases(t,a,c){let l=new o(t),u=r(t),knownType=e=>s.has(e)||l.concepts.has(e)||l.types.has(e),d=new Map([...l.types].map(([e,t])=>[e,new Map(t.properties.map(e=>[e.name,e]))])),f=c===void 0?l.slices:[{scope:[],slice:{kind:`SliceSyntax`,type:`StateChange`,name:``,description:null,location:t.location,events:[],commands:[],queries:[],projections:[],captures:[],reactions:[],constraints:[],readModels:[],screens:[],specifications:c}}];for(let{slice:r,scope:o}of f){let s=/* @__PURE__ */ new Map;for(let e of r.specifications){let t=(e.cases?.length??0)===0?[e.name]:e.cases.map(t=>`${e.name}_${t.name}`);for(let e of t)s.set(e,(s.get(e)??0)+1);(e.cases?.length??0)>0&&s.set(e.name,(s.get(e.name)??0)+1)}for(let f of r.specifications){for(let t of f.cases??[])(s.get(`${f.name}_${t.name}`)??0)>1&&a.error(e.SpecificationCaseNameCollision,`Case '${t.name}' derives specification '${f.name}_${t.name}', which collides in this ${c===void 0?`slice`:`document`}.`,t.location);for(let t of f.parameters??[]){c===void 0&&!knownType(t.type.name)&&a.error(e.IncompatibleSpecificationParameterType,`Parameter '${t.name}' has unknown type '${t.type.name}'.`,t.type.location);for(let n of f.cases??[])for(let r of n.values.filter(e=>e.property===t.name))i(r.source,t.type,l.concepts,d)||a.error(e.InvalidSpecificationCaseValue,`Case '${n.name}' parameter '${t.name}' requires a concrete value of type '${t.type.name}'.`,r.source.location)}let check=(t,n,r)=>{if(t?.kind!==`CaseValueExpressionSyntax`||n===void 0)return;let i=f.parameters?.find(e=>e.name===t.parameter);if(i===void 0||(i.type.isOptional&&!n.isOptional&&a.error(e.OptionalSpecificationParameterTarget,`Optional parameter '${i.name}' cannot supply required target '${r}'.`,t.location),c!==void 0&&(!knownType(i.type.name)||!knownType(n.name))))return;let o=l.concepts.get(i.type.name),s=l.concepts.get(n.name);(!(i.type.name===n.name||o?.type!==`Enum`&&o?.type===n.name||s?.type!==`Enum`&&s?.type===i.type.name)||i.type.isCollection!==n.isCollection)&&a.error(e.IncompatibleSpecificationParameterType,`Parameter '${i.name}' type '${i.type.name}' is incompatible with target '${r}' type '${n.name}'.`,t.location)},assignments=(e,t)=>{for(let n of e)check(n.source,l.property(t,n.property)?.type,n.property)},p=u.command(f.when,o);if(p!==null){let e=l.resolve(p.commandType,r,e=>e.commands)?.node.properties??null;assignments(p.values,e),assignments(p.generatedValues??[],e),check(p.for,e?.find(e=>e.isIdentifier)?.type,`for`)}if(p!==null&&f.thenReturns!=null){let e=l.resolve(p.commandType,r,e=>e.commands)?.node,t=e?.response;if(f.thenReturns.kind===`ScalarSpecificationReturnSyntax`&&t?.kind===`ScalarCommandResponseSyntax`&&check(f.thenReturns.value,e?.properties.find(e=>e.name===t.source.property)?.type,`value`),f.thenReturns.kind===`RecordSpecificationReturnSyntax`&&t?.kind===`RecordCommandResponseSyntax`)for(let n of f.thenReturns.fields){let r=t.fields.find(e=>e.name===n.property);check(n.source,r?.type??e?.properties.find(e=>e.name===r?.source.property)?.type,n.property)}}for(let e of[...f.given,...f.thenEvents,...f.whenAppended===null?[]:[f.whenAppended]]){let i=u.eventStep(e,`given`,o).effective;assignments(i.values,l.event(i.eventType,r)?.properties??null);let a=i.stream==null?null:new n(t).resolve(i.stream.eventSource,i.stream.stream),s=a?.kind===`unique`?a.sources[0]:void 0,c=a?.kind===`unique`?a.streams[0]:void 0;check(i.for,i.stream!=null&&s===void 0?void 0:s?.identifier??eventDestinationType(i.eventType,r,t,l),`for`),i.stream?.streamId!=null&&check(i.stream.streamId.source,c?.streamId??void 0,`streamId`);for(let e of i.stream?.streamIdParts??[])check(e.source,c?.streamIdParts.find(t=>t.name===e.property)?.type,e.property)}for(let e of[...f.givenReadModels,...f.thenReadModels]){let t=u.readModel(e,o);assignments(t.properties,l.resolve(t.name,r,e=>e.readModels)?.node.properties??null)}if(f.whenTrigger!=null){let e=(t.declaredTriggers??[]).find(e=>e.name===f.whenTrigger.trigger);for(let t of f.whenTrigger.values)check(t.source,e?.data.find(e=>e.name===t.property)?.type,t.property)}for(let e of f.thenErrors)check(e.caseValue??null,{kind:`TypeRefSyntax`,name:`String`,isOptional:!1,isCollection:!1,location:e.location},`message`);for(let e of f.thenAbsentReadModels??[]){let t=l.resolve(e.name,r,e=>e.readModels)?.node,n=l.slices.flatMap(({slice:e})=>e.queries.filter(n=>n.by!==null&&l.resolve(n.returnType.name,e,e=>e.readModels)?.node===t));check(e.key,t!==void 0&&n.length===1?n[0].by.type:void 0,`for`)}for(let e of[...f.thenQueries??[],...f.whenQuery===null?[]:[f.whenQuery]]){let t=l.resolve(e.query,r,e=>e.queries),n=t===null?[]:[...t.node.by===null?[]:[t.node.by],...t.node.filters].map(e=>({...e,kind:`PropertySyntax`,isIdentifier:!1}));assignments(e.arguments,n);let i=t===null?null:l.resolve(t.node.returnType.name,t.slice,e=>e.readModels)?.node.properties??null,a=e.kind===`SpecificationQuerySyntax`?e.results:f.thenResults;for(let e of a)assignments(e.properties,i)}}}}function uniqueDestinationType(e){let t=new Map(e.map(e=>[JSON.stringify([e.name,e.isOptional,e.isCollection]),e]));return t.size===1?[...t.values()][0]:void 0}function eventDestinationType(e,n,r,i){let o=new t(r),s=i.event(e,n);if(s===null)return;let commandTypes=(e,t=i.slices)=>t.flatMap(({slice:t})=>t.commands.flatMap(n=>n.produces.filter(n=>o.isEventProduction(n,t)&&i.event(n.event,t)===e).map(e=>a(n,e,r,{resolver:o,slice:t})).filter(e=>e!==null))),producerTypes=(e,t)=>{if(t.has(e))return[];t.add(e);let n=commandTypes(e);for(let{slice:a}of i.slices){for(let o of a.reactions.flatMap(e=>e.triggers)){let s=o.source.kind===`NamedTriggerSourceSyntax`?o.source.name:void 0,c=s===void 0?null:i.event(s,a);for(let l of o.produces.filter(t=>i.event(t.event,a)===e))if(l.for?.kind===`PathExpressionSyntax`){let e=l.for.path,t=i.property(c?.properties??null,e)?.type??(s===void 0?void 0:(r.declaredTriggers??[]).find(e=>e.name===s)?.data.find(t=>t.name===e)?.type);t!==void 0&&n.push(t)}else l.for?.kind===`LiteralExpressionSyntax`?n.push({kind:`TypeRefSyntax`,name:`String`,isOptional:!1,isCollection:!1,location:l.location}):l.for===null&&c!==null&&n.push(...producerTypes(c,t))}a.captures.flatMap(e=>[...e.appends,...e.children.flatMap(e=>e.appends),...e.nested.flatMap(e=>e.appends)]).some(t=>i.event(t.event,a)===e)&&n.push(uniqueDestinationType(commandTypes(e))??{kind:`TypeRefSyntax`,name:`String`,isOptional:!1,isCollection:!1,location:e.location})}return n};return uniqueDestinationType(commandTypes(s,i.slices.filter(e=>e.slice===n)))??uniqueDestinationType(commandTypes(s))??uniqueDestinationType(producerTypes(s,/* @__PURE__ */ new Set))}export{validateSpecificationCases};
1
+ import"../../_virtual/_virtual/_rolldown/runtime.js";import{DiagnosticCodes as e}from"../Diagnostics/DiagnosticCodes.js";import{AuthoringProductionResolver as t}from"../Syntax/AuthoringProductionResolver.js";import{diagnosticText as n}from"../Diagnostics/DiagnosticArgument.js";import{EventSourceCatalog as r}from"../Syntax/EventSourceCatalog.js";import{specificationExamples as i}from"./SpecificationCommandExamples.js";import{compatibleValue as a}from"./ResponseValidator.js";import{commandDestinationType as o}from"./CommandDestinationTypes.js";import{RefusalDeclarations as s}from"./RefusalDeclarations.js";const c=/* @__PURE__ */ new Set([`Uuid`,`String`,`Int`,`Decimal`,`Bool`,`Date`,`DateTime`]);function validateSpecificationCases(t,o,l){let u=new s(t),d=i(t),knownType=e=>c.has(e)||u.concepts.has(e)||u.types.has(e),f=new Map([...u.types].map(([e,t])=>[e,new Map(t.properties.map(e=>[e.name,e]))])),p=l===void 0?u.slices:[{scope:[],slice:{kind:`SliceSyntax`,type:`StateChange`,name:``,description:null,location:t.location,events:[],commands:[],queries:[],projections:[],captures:[],reactions:[],constraints:[],readModels:[],screens:[],specifications:l}}];for(let{slice:i,scope:s}of p){let c=/* @__PURE__ */ new Map;for(let e of i.specifications){let t=(e.cases?.length??0)===0?[e.name]:e.cases.map(t=>`${e.name}_${t.name}`);for(let e of t)c.set(e,(c.get(e)??0)+1);(e.cases?.length??0)>0&&c.set(e.name,(c.get(e.name)??0)+1)}for(let p of i.specifications){for(let t of p.cases??[])(c.get(`${p.name}_${t.name}`)??0)>1&&o.error(e.SpecificationCaseNameCollision,`Case '${t.name}' derives specification '${p.name}_${t.name}', which collides in this ${l===void 0?`slice`:`document`}.`,t.location);for(let t of p.parameters??[]){l===void 0&&!knownType(t.type.name)&&o.error(e.IncompatibleSpecificationParameterType,`Parameter '${t.name}' has unknown type '${t.type.name}'.`,t.type.location);for(let r of p.cases??[])for(let i of r.values.filter(e=>e.property===t.name))a(i.source,t.type,u.concepts,f)||o.error(e.InvalidSpecificationCaseValue,`Case '${r.name}' parameter '${t.name}' requires a concrete value of type '${t.type.name}'.`,i.source.location,{...n(`case`,r.name),...n(`parameter`,t.name),...n(`type`,t.type.name)})}let check=(t,n,r)=>{if(t?.kind!==`CaseValueExpressionSyntax`||n===void 0)return;let i=p.parameters?.find(e=>e.name===t.parameter);if(i===void 0||(i.type.isOptional&&!n.isOptional&&o.error(e.OptionalSpecificationParameterTarget,`Optional parameter '${i.name}' cannot supply required target '${r}'.`,t.location),l!==void 0&&(!knownType(i.type.name)||!knownType(n.name))))return;let a=u.concepts.get(i.type.name),s=u.concepts.get(n.name);(!(i.type.name===n.name||a?.type!==`Enum`&&a?.type===n.name||s?.type!==`Enum`&&s?.type===i.type.name)||i.type.isCollection!==n.isCollection)&&o.error(e.IncompatibleSpecificationParameterType,`Parameter '${i.name}' type '${i.type.name}' is incompatible with target '${r}' type '${n.name}'.`,t.location)},assignments=(e,t)=>{for(let n of e)check(n.source,u.property(t,n.property)?.type,n.property)},m=d.command(p.when,s);if(m!==null){let e=u.resolve(m.commandType,i,e=>e.commands)?.node.properties??null;assignments(m.values,e),assignments(m.generatedValues??[],e),check(m.for,e?.find(e=>e.isIdentifier)?.type,`for`)}if(m!==null&&p.thenReturns!=null){let e=u.resolve(m.commandType,i,e=>e.commands)?.node,t=e?.response;if(p.thenReturns.kind===`ScalarSpecificationReturnSyntax`&&t?.kind===`ScalarCommandResponseSyntax`&&check(p.thenReturns.value,e?.properties.find(e=>e.name===t.source.property)?.type,`value`),p.thenReturns.kind===`RecordSpecificationReturnSyntax`&&t?.kind===`RecordCommandResponseSyntax`)for(let n of p.thenReturns.fields){let r=t.fields.find(e=>e.name===n.property);check(n.source,r?.type??e?.properties.find(e=>e.name===r?.source.property)?.type,n.property)}}for(let e of[...p.given,...p.thenEvents,...p.whenAppended===null?[]:[p.whenAppended]]){let n=d.eventStep(e,`given`,s).effective;assignments(n.values,u.event(n.eventType,i)?.properties??null);let a=n.stream==null?null:new r(t).resolve(n.stream.eventSource,n.stream.stream),o=a?.kind===`unique`?a.sources[0]:void 0,c=a?.kind===`unique`?a.streams[0]:void 0;check(n.for,n.stream!=null&&o===void 0?void 0:o?.identifier??eventDestinationType(n.eventType,i,t,u),`for`),n.stream?.streamId!=null&&check(n.stream.streamId.source,c?.streamId??void 0,`streamId`);for(let e of n.stream?.streamIdParts??[])check(e.source,c?.streamIdParts.find(t=>t.name===e.property)?.type,e.property)}for(let e of[...p.givenReadModels,...p.thenReadModels]){let t=d.readModel(e,s);assignments(t.properties,u.resolve(t.name,i,e=>e.readModels)?.node.properties??null)}if(p.whenTrigger!=null){let e=(t.declaredTriggers??[]).find(e=>e.name===p.whenTrigger.trigger);for(let t of p.whenTrigger.values)check(t.source,e?.data.find(e=>e.name===t.property)?.type,t.property)}for(let e of p.thenErrors)check(e.caseValue??null,{kind:`TypeRefSyntax`,name:`String`,isOptional:!1,isCollection:!1,location:e.location},`message`);for(let e of p.thenAbsentReadModels??[]){let t=u.resolve(e.name,i,e=>e.readModels)?.node,n=u.slices.flatMap(({slice:e})=>e.queries.filter(n=>n.by!==null&&u.resolve(n.returnType.name,e,e=>e.readModels)?.node===t));check(e.key,t!==void 0&&n.length===1?n[0].by.type:void 0,`for`)}for(let e of[...p.thenQueries??[],...p.whenQuery===null?[]:[p.whenQuery]]){let t=u.resolve(e.query,i,e=>e.queries),n=t===null?[]:[...t.node.by===null?[]:[t.node.by],...t.node.filters].map(e=>({...e,kind:`PropertySyntax`,isIdentifier:!1}));assignments(e.arguments,n);let r=t===null?null:u.resolve(t.node.returnType.name,t.slice,e=>e.readModels)?.node.properties??null,a=e.kind===`SpecificationQuerySyntax`?e.results:p.thenResults;for(let e of a)assignments(e.properties,r)}}}}function uniqueDestinationType(e){let t=new Map(e.map(e=>[JSON.stringify([e.name,e.isOptional,e.isCollection]),e]));return t.size===1?[...t.values()][0]:void 0}function eventDestinationType(e,n,r,i){let a=new t(r),s=i.event(e,n);if(s===null)return;let commandTypes=(e,t=i.slices)=>t.flatMap(({slice:t})=>t.commands.flatMap(n=>n.produces.filter(n=>a.isEventProduction(n,t)&&i.event(n.event,t)===e).map(e=>o(n,e,r,{resolver:a,slice:t})).filter(e=>e!==null))),producerTypes=(e,t)=>{if(t.has(e))return[];t.add(e);let n=commandTypes(e);for(let{slice:a}of i.slices){for(let o of a.reactions.flatMap(e=>e.triggers)){let s=o.source.kind===`NamedTriggerSourceSyntax`?o.source.name:void 0,c=s===void 0?null:i.event(s,a);for(let l of o.produces.filter(t=>i.event(t.event,a)===e))if(l.for?.kind===`PathExpressionSyntax`){let e=l.for.path,t=i.property(c?.properties??null,e)?.type??(s===void 0?void 0:(r.declaredTriggers??[]).find(e=>e.name===s)?.data.find(t=>t.name===e)?.type);t!==void 0&&n.push(t)}else l.for?.kind===`LiteralExpressionSyntax`?n.push({kind:`TypeRefSyntax`,name:`String`,isOptional:!1,isCollection:!1,location:l.location}):l.for===null&&c!==null&&n.push(...producerTypes(c,t))}a.captures.flatMap(e=>[...e.appends,...e.children.flatMap(e=>e.appends),...e.nested.flatMap(e=>e.appends)]).some(t=>i.event(t.event,a)===e)&&n.push(uniqueDestinationType(commandTypes(e))??{kind:`TypeRefSyntax`,name:`String`,isOptional:!1,isCollection:!1,location:e.location})}return n};return uniqueDestinationType(commandTypes(s,i.slices.filter(e=>e.slice===n)))??uniqueDestinationType(commandTypes(s))??uniqueDestinationType(producerTypes(s,/* @__PURE__ */ new Set))}export{validateSpecificationCases};
2
2
  //# sourceMappingURL=SpecificationCaseValidator.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SpecificationCaseValidator.js","names":["primitives","declarations","RefusalDeclarations","application","examples","specificationExamples","name","composites","type","property","owners","standaloneSpecifications","names","specification","slice","expandedNames","row","context","DiagnosticCodes","parameter","assignment","value","compatibleValue","expression","target","sourceConcept","targetConcept","values","properties","command","scope","declaration","response","field","authored","event","route","EventSourceCatalog","source","stream","part","model","trigger","error","absent","keyed","owner","query","parameters","results","result","distinct","types","resolver","AuthoringProductionResolver","reference","local","produced","commandDestinationType","visited","reaction","sourceName","path","declared","capture","child","nested","append"],"sources":["../../../../../../Compiler/Parsing/SpecificationCaseValidator.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 { EventSyntax, PropertySyntax, TypeRefSyntax } from '../Syntax/Declarations';\nimport { AuthoringProductionResolver } from '../Syntax/AuthoringProductionResolver';\nimport { EventSourceCatalog } from '../Syntax/EventSourceCatalog';\nimport { EventSourceResolutionKind } from '../Syntax/EventSources';\nimport { SpecificationSyntax } from '../Syntax/Specifications';\nimport { commandDestinationType } from './CommandDestinationTypes';\nimport { ExpressionSyntax, PropertyMappingSyntax } from '../Syntax/Expressions';\nimport { ApplicationSyntax, SliceSyntax } from '../Syntax/Structure';\nimport { ParserContext } from './ParserContext';\nimport { RefusalDeclarations } from './RefusalDeclarations';\nimport { compatibleValue } from './ResponseValidator';\nimport { specificationExamples } from './SpecificationCommandExamples';\n\nconst primitives = new Set(['Uuid', 'String', 'Int', 'Decimal', 'Bool', 'Date', 'DateTime']);\n\nexport function validateSpecificationCases(application: ApplicationSyntax, context: ParserContext, standaloneSpecifications?: readonly SpecificationSyntax[]): void {\n const declarations = new RefusalDeclarations(application);\n const examples = specificationExamples(application);\n const knownType = (name: string) => primitives.has(name) || declarations.concepts.has(name) || declarations.types.has(name);\n const composites = new Map([...declarations.types].map(([name, type]) => [name, new Map(type.properties.map(property => [property.name, property]))]));\n const owners = standaloneSpecifications === undefined ? declarations.slices : [{ scope: [], slice: {\n kind: 'SliceSyntax' as const, type: 'StateChange' as const, name: '', description: null, location: application.location,\n events: [], commands: [], queries: [], projections: [], captures: [], reactions: [], constraints: [], readModels: [], screens: [], specifications: standaloneSpecifications,\n } }];\n for (const { slice, scope } of owners) {\n const names = new Map<string, number>();\n for (const specification of slice.specifications) {\n const expandedNames = (specification.cases?.length ?? 0) === 0 ? [specification.name] : specification.cases!.map(row => `${specification.name}_${row.name}`);\n for (const name of expandedNames) names.set(name, (names.get(name) ?? 0) + 1);\n if ((specification.cases?.length ?? 0) > 0) names.set(specification.name, (names.get(specification.name) ?? 0) + 1);\n }\n for (const specification of slice.specifications) {\n for (const row of specification.cases ?? []) {\n if ((names.get(`${specification.name}_${row.name}`) ?? 0) > 1) context.error(DiagnosticCodes.SpecificationCaseNameCollision, `Case '${row.name}' derives specification '${specification.name}_${row.name}', which collides in this ${standaloneSpecifications === undefined ? 'slice' : 'document'}.`, row.location);\n }\n for (const parameter of specification.parameters ?? []) {\n if (standaloneSpecifications === undefined && !knownType(parameter.type.name)) context.error(DiagnosticCodes.IncompatibleSpecificationParameterType, `Parameter '${parameter.name}' has unknown type '${parameter.type.name}'.`, parameter.type.location);\n for (const row of specification.cases ?? []) {\n for (const assignment of row.values.filter(value => value.property === parameter.name)) {\n if (!compatibleValue(assignment.source, parameter.type, declarations.concepts, composites)) context.error(DiagnosticCodes.InvalidSpecificationCaseValue, `Case '${row.name}' parameter '${parameter.name}' requires a concrete value of type '${parameter.type.name}'.`, assignment.source.location);\n }\n }\n }\n const check = (expression: ExpressionSyntax | null, target: TypeRefSyntax | undefined, property: string) => {\n if (expression?.kind !== 'CaseValueExpressionSyntax' || target === undefined) return;\n const parameter = specification.parameters?.find(parameter => parameter.name === expression.parameter);\n if (parameter === undefined) return;\n if (parameter.type.isOptional && !target.isOptional) context.error(DiagnosticCodes.OptionalSpecificationParameterTarget, `Optional parameter '${parameter.name}' cannot supply required target '${property}'.`, expression.location);\n if (standaloneSpecifications !== undefined && (!knownType(parameter.type.name) || !knownType(target.name))) return;\n const sourceConcept = declarations.concepts.get(parameter.type.name);\n const targetConcept = declarations.concepts.get(target.name);\n const compatible = parameter.type.name === target.name || sourceConcept?.type !== 'Enum' && sourceConcept?.type === target.name || targetConcept?.type !== 'Enum' && targetConcept?.type === parameter.type.name;\n if (!compatible || parameter.type.isCollection !== target.isCollection) context.error(DiagnosticCodes.IncompatibleSpecificationParameterType, `Parameter '${parameter.name}' type '${parameter.type.name}' is incompatible with target '${property}' type '${target.name}'.`, expression.location);\n };\n const assignments = (values: readonly PropertyMappingSyntax[], properties: readonly PropertySyntax[] | null) => {\n for (const value of values) check(value.source, declarations.property(properties, value.property)?.type, value.property);\n };\n const command = examples.command(specification.when, scope);\n if (command !== null) {\n const properties = declarations.resolve(command.commandType, slice, slice => slice.commands)?.node.properties ?? null;\n assignments(command.values, properties);\n assignments(command.generatedValues ?? [], properties);\n check(command.for, properties?.find(property => property.isIdentifier)?.type, 'for');\n }\n if (command !== null && specification.thenReturns != null) {\n const declaration = declarations.resolve(command.commandType, slice, slice => slice.commands)?.node;\n const response = declaration?.response;\n if (specification.thenReturns.kind === 'ScalarSpecificationReturnSyntax' && response?.kind === 'ScalarCommandResponseSyntax') check(specification.thenReturns.value, declaration?.properties.find(property => property.name === response.source.property)?.type, 'value');\n if (specification.thenReturns.kind === 'RecordSpecificationReturnSyntax' && response?.kind === 'RecordCommandResponseSyntax') {\n for (const value of specification.thenReturns.fields) {\n const field = response.fields.find(field => field.name === value.property);\n check(value.source, field?.type ?? declaration?.properties.find(property => property.name === field?.source.property)?.type, value.property);\n }\n }\n }\n for (const authored of [...specification.given, ...specification.thenEvents, ...(specification.whenAppended === null ? [] : [specification.whenAppended])]) {\n const event = examples.eventStep(authored, 'given', scope).effective as typeof authored;\n assignments(event.values, declarations.event(event.eventType, slice)?.properties ?? null);\n const route = event.stream == null ? null : new EventSourceCatalog(application).resolve(event.stream.eventSource, event.stream.stream);\n const source = route?.kind === EventSourceResolutionKind.Unique ? route.sources[0] : undefined;\n const stream = route?.kind === EventSourceResolutionKind.Unique ? route.streams[0] : undefined;\n check(event.for, event.stream != null && source === undefined ? undefined : source?.identifier ?? eventDestinationType(event.eventType, slice, application, declarations), 'for');\n if (event.stream?.streamId != null) check(event.stream.streamId.source, stream?.streamId ?? undefined, 'streamId');\n for (const part of event.stream?.streamIdParts ?? []) check(part.source, stream?.streamIdParts.find(declaration => declaration.name === part.property)?.type, part.property);\n }\n for (const authored of [...specification.givenReadModels, ...specification.thenReadModels]) {\n const model = examples.readModel(authored, scope);\n assignments(model.properties, declarations.resolve(model.name, slice, slice => slice.readModels)?.node.properties ?? null);\n }\n if (specification.whenTrigger != null) {\n const trigger = (application.declaredTriggers ?? []).find(trigger => trigger.name === specification.whenTrigger!.trigger);\n for (const value of specification.whenTrigger.values) check(value.source, trigger?.data.find(property => property.name === value.property)?.type, value.property);\n }\n for (const error of specification.thenErrors) check(error.caseValue ?? null, { kind: 'TypeRefSyntax', name: 'String', isOptional: false, isCollection: false, location: error.location }, 'message');\n for (const absent of specification.thenAbsentReadModels ?? []) {\n const model = declarations.resolve(absent.name, slice, slice => slice.readModels)?.node;\n const keyed = declarations.slices.flatMap(({ slice: owner }) => owner.queries.filter(query => query.by !== null && declarations.resolve(query.returnType.name, owner, slice => slice.readModels)?.node === model));\n check(absent.key, model !== undefined && keyed.length === 1 ? keyed[0].by!.type : undefined, 'for');\n }\n for (const query of [...(specification.thenQueries ?? []), ...(specification.whenQuery === null ? [] : [specification.whenQuery])]) {\n const declaration = declarations.resolve(query.query, slice, slice => slice.queries);\n const parameters = declaration === null ? [] : [...(declaration.node.by === null ? [] : [declaration.node.by]), ...declaration.node.filters].map(parameter => ({ ...parameter, kind: 'PropertySyntax' as const, isIdentifier: false }));\n assignments(query.arguments, parameters);\n const properties = declaration === null ? null : declarations.resolve(declaration.node.returnType.name, declaration.slice, slice => slice.readModels)?.node.properties ?? null;\n const results = query.kind === 'SpecificationQuerySyntax' ? query.results : specification.thenResults;\n for (const result of results) assignments(result.properties, properties);\n }\n }\n }\n}\n\nfunction uniqueDestinationType(types: readonly TypeRefSyntax[]): TypeRefSyntax | undefined {\n const distinct = new Map(types.map(type => [JSON.stringify([type.name, type.isOptional, type.isCollection]), type]));\n return distinct.size === 1 ? [...distinct.values()][0] : undefined;\n}\n\nfunction eventDestinationType(reference: string, local: SliceSyntax, application: ApplicationSyntax, declarations: RefusalDeclarations): TypeRefSyntax | undefined {\n const resolver = new AuthoringProductionResolver(application);\n const event = declarations.event(reference, local);\n if (event === null) return undefined;\n const commandTypes = (event: EventSyntax, owners = declarations.slices): TypeRefSyntax[] => owners.flatMap(({ slice }) => slice.commands.flatMap(command => command.produces\n .filter(produced => resolver.isEventProduction(produced, slice) && declarations.event(produced.event, slice) === event)\n .map(produced => commandDestinationType(command, produced, application, { resolver, slice })).filter((type): type is TypeRefSyntax => type !== null)));\n const producerTypes = (event: EventSyntax, visited: Set<EventSyntax>): TypeRefSyntax[] => {\n if (visited.has(event)) return [];\n visited.add(event);\n const types = commandTypes(event);\n for (const { slice } of declarations.slices) {\n for (const trigger of slice.reactions.flatMap(reaction => reaction.triggers)) {\n const sourceName = trigger.source.kind === 'NamedTriggerSourceSyntax' ? trigger.source.name : undefined;\n const source = sourceName === undefined ? null : declarations.event(sourceName, slice);\n for (const produced of trigger.produces.filter(produced => declarations.event(produced.event, slice) === event)) {\n if (produced.for?.kind === 'PathExpressionSyntax') {\n const path = produced.for.path;\n const type = declarations.property(source?.properties ?? null, path)?.type ?? (sourceName === undefined ? undefined\n : (application.declaredTriggers ?? []).find(declared => declared.name === sourceName)?.data.find(property => property.name === path)?.type);\n if (type !== undefined) types.push(type);\n } else if (produced.for?.kind === 'LiteralExpressionSyntax') types.push({ kind: 'TypeRefSyntax', name: 'String', isOptional: false, isCollection: false, location: produced.location });\n else if (produced.for === null && source !== null) types.push(...producerTypes(source, visited));\n }\n }\n if (slice.captures.flatMap(capture => [...capture.appends, ...capture.children.flatMap(child => child.appends), ...capture.nested.flatMap(nested => nested.appends)]).some(append => declarations.event(append.event, slice) === event))\n types.push(uniqueDestinationType(commandTypes(event)) ?? { kind: 'TypeRefSyntax', name: 'String', isOptional: false, isCollection: false, location: event.location });\n }\n return types;\n };\n return uniqueDestinationType(commandTypes(event, declarations.slices.filter(owner => owner.slice === local))) ?? uniqueDestinationType(commandTypes(event)) ?? uniqueDestinationType(producerTypes(event, new Set()));\n}\n"],"mappings":"6hBAiBA,MAAMA,kBAAa,IAAI,IAAI,CAAC,OAAQ,SAAU,MAAO,UAAW,OAAQ,OAAQ,UAAU,CAAC,EAE3F,SAAgB,2BAA2B,EAAgC,EAAwB,EAAiE,CAChK,IAAMC,EAAe,IAAIC,EAAoBC,CAAW,EACl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,SAAUK,EAAS,QAAS,CAAC,EAC7KA,EAAS,MAAQ,MAAQnB,IAAW,MAAMc,EAAM,KAAK,GAAG,cAAcd,EAAQqB,CAAO,CAAC,CAEvG,CACI7C,EAAM,SAAS,QAAQ,GAAW,CAAC,GAAGkD,EAAQ,QAAS,GAAGA,EAAQ,SAAS,QAAQ,GAASC,EAAM,OAAO,EAAG,GAAGD,EAAQ,OAAO,QAAQ,GAAUE,EAAO,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,GAAUjE,EAAa,MAAMkE,EAAO,MAAOrD,CAAK,IAAMqB,CAAK,GAClOiB,EAAM,KAAK,sBAAsB,aAAajB,CAAK,CAAC,GAAK,CAAE,KAAM,gBAAiB,KAAM,SAAU,WAAY,GAAO,aAAc,GAAO,SAAUA,EAAM,QAAS,CAAC,CAC5K,CACA,OAAOiB,CACX,EACA,OAAO,sBAAsB,aAAajB,EAAOlC,EAAa,OAAO,OAAO,GAAS6C,EAAM,QAAUU,CAAK,CAAC,CAAC,GAAK,sBAAsB,aAAarB,CAAK,CAAC,GAAK,sBAAsB,cAAcA,kBAAO,IAAI,GAAK,CAAC,CACxN"}
1
+ {"version":3,"file":"SpecificationCaseValidator.js","names":["primitives","declarations","RefusalDeclarations","application","examples","specificationExamples","name","composites","type","property","owners","standaloneSpecifications","names","specification","slice","expandedNames","row","context","DiagnosticCodes","parameter","assignment","value","compatibleValue","diagnosticText","expression","target","sourceConcept","targetConcept","values","properties","command","scope","declaration","response","field","authored","event","route","EventSourceCatalog","source","stream","part","model","trigger","error","absent","keyed","owner","query","parameters","results","result","distinct","types","resolver","AuthoringProductionResolver","reference","local","produced","commandDestinationType","visited","reaction","sourceName","path","declared","capture","child","nested","append"],"sources":["../../../../../../Compiler/Parsing/SpecificationCaseValidator.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 { diagnosticText } from '../Diagnostics/DiagnosticArgument';\nimport { DiagnosticCodes } from '../Diagnostics/DiagnosticCodes';\nimport { EventSyntax, PropertySyntax, TypeRefSyntax } from '../Syntax/Declarations';\nimport { AuthoringProductionResolver } from '../Syntax/AuthoringProductionResolver';\nimport { EventSourceCatalog } from '../Syntax/EventSourceCatalog';\nimport { EventSourceResolutionKind } from '../Syntax/EventSources';\nimport { SpecificationSyntax } from '../Syntax/Specifications';\nimport { commandDestinationType } from './CommandDestinationTypes';\nimport { ExpressionSyntax, PropertyMappingSyntax } from '../Syntax/Expressions';\nimport { ApplicationSyntax, SliceSyntax } from '../Syntax/Structure';\nimport { ParserContext } from './ParserContext';\nimport { RefusalDeclarations } from './RefusalDeclarations';\nimport { compatibleValue } from './ResponseValidator';\nimport { specificationExamples } from './SpecificationCommandExamples';\n\nconst primitives = new Set(['Uuid', 'String', 'Int', 'Decimal', 'Bool', 'Date', 'DateTime']);\n\nexport function validateSpecificationCases(application: ApplicationSyntax, context: ParserContext, standaloneSpecifications?: readonly SpecificationSyntax[]): void {\n const declarations = new RefusalDeclarations(application);\n const examples = specificationExamples(application);\n const knownType = (name: string) => primitives.has(name) || declarations.concepts.has(name) || declarations.types.has(name);\n const composites = new Map([...declarations.types].map(([name, type]) => [name, new Map(type.properties.map(property => [property.name, property]))]));\n const owners = standaloneSpecifications === undefined ? declarations.slices : [{ scope: [], slice: {\n kind: 'SliceSyntax' as const, type: 'StateChange' as const, name: '', description: null, location: application.location,\n events: [], commands: [], queries: [], projections: [], captures: [], reactions: [], constraints: [], readModels: [], screens: [], specifications: standaloneSpecifications,\n } }];\n for (const { slice, scope } of owners) {\n const names = new Map<string, number>();\n for (const specification of slice.specifications) {\n const expandedNames = (specification.cases?.length ?? 0) === 0 ? [specification.name] : specification.cases!.map(row => `${specification.name}_${row.name}`);\n for (const name of expandedNames) names.set(name, (names.get(name) ?? 0) + 1);\n if ((specification.cases?.length ?? 0) > 0) names.set(specification.name, (names.get(specification.name) ?? 0) + 1);\n }\n for (const specification of slice.specifications) {\n for (const row of specification.cases ?? []) {\n if ((names.get(`${specification.name}_${row.name}`) ?? 0) > 1) context.error(DiagnosticCodes.SpecificationCaseNameCollision, `Case '${row.name}' derives specification '${specification.name}_${row.name}', which collides in this ${standaloneSpecifications === undefined ? 'slice' : 'document'}.`, row.location);\n }\n for (const parameter of specification.parameters ?? []) {\n if (standaloneSpecifications === undefined && !knownType(parameter.type.name)) context.error(DiagnosticCodes.IncompatibleSpecificationParameterType, `Parameter '${parameter.name}' has unknown type '${parameter.type.name}'.`, parameter.type.location);\n for (const row of specification.cases ?? []) {\n for (const assignment of row.values.filter(value => value.property === parameter.name)) {\n if (!compatibleValue(assignment.source, parameter.type, declarations.concepts, composites)) context.error(DiagnosticCodes.InvalidSpecificationCaseValue, `Case '${row.name}' parameter '${parameter.name}' requires a concrete value of type '${parameter.type.name}'.`, assignment.source.location, { ...diagnosticText('case', row.name), ...diagnosticText('parameter', parameter.name), ...diagnosticText('type', parameter.type.name) });\n }\n }\n }\n const check = (expression: ExpressionSyntax | null, target: TypeRefSyntax | undefined, property: string) => {\n if (expression?.kind !== 'CaseValueExpressionSyntax' || target === undefined) return;\n const parameter = specification.parameters?.find(parameter => parameter.name === expression.parameter);\n if (parameter === undefined) return;\n if (parameter.type.isOptional && !target.isOptional) context.error(DiagnosticCodes.OptionalSpecificationParameterTarget, `Optional parameter '${parameter.name}' cannot supply required target '${property}'.`, expression.location);\n if (standaloneSpecifications !== undefined && (!knownType(parameter.type.name) || !knownType(target.name))) return;\n const sourceConcept = declarations.concepts.get(parameter.type.name);\n const targetConcept = declarations.concepts.get(target.name);\n const compatible = parameter.type.name === target.name || sourceConcept?.type !== 'Enum' && sourceConcept?.type === target.name || targetConcept?.type !== 'Enum' && targetConcept?.type === parameter.type.name;\n if (!compatible || parameter.type.isCollection !== target.isCollection) context.error(DiagnosticCodes.IncompatibleSpecificationParameterType, `Parameter '${parameter.name}' type '${parameter.type.name}' is incompatible with target '${property}' type '${target.name}'.`, expression.location);\n };\n const assignments = (values: readonly PropertyMappingSyntax[], properties: readonly PropertySyntax[] | null) => {\n for (const value of values) check(value.source, declarations.property(properties, value.property)?.type, value.property);\n };\n const command = examples.command(specification.when, scope);\n if (command !== null) {\n const properties = declarations.resolve(command.commandType, slice, slice => slice.commands)?.node.properties ?? null;\n assignments(command.values, properties);\n assignments(command.generatedValues ?? [], properties);\n check(command.for, properties?.find(property => property.isIdentifier)?.type, 'for');\n }\n if (command !== null && specification.thenReturns != null) {\n const declaration = declarations.resolve(command.commandType, slice, slice => slice.commands)?.node;\n const response = declaration?.response;\n if (specification.thenReturns.kind === 'ScalarSpecificationReturnSyntax' && response?.kind === 'ScalarCommandResponseSyntax') check(specification.thenReturns.value, declaration?.properties.find(property => property.name === response.source.property)?.type, 'value');\n if (specification.thenReturns.kind === 'RecordSpecificationReturnSyntax' && response?.kind === 'RecordCommandResponseSyntax') {\n for (const value of specification.thenReturns.fields) {\n const field = response.fields.find(field => field.name === value.property);\n check(value.source, field?.type ?? declaration?.properties.find(property => property.name === field?.source.property)?.type, value.property);\n }\n }\n }\n for (const authored of [...specification.given, ...specification.thenEvents, ...(specification.whenAppended === null ? [] : [specification.whenAppended])]) {\n const event = examples.eventStep(authored, 'given', scope).effective as typeof authored;\n assignments(event.values, declarations.event(event.eventType, slice)?.properties ?? null);\n const route = event.stream == null ? null : new EventSourceCatalog(application).resolve(event.stream.eventSource, event.stream.stream);\n const source = route?.kind === EventSourceResolutionKind.Unique ? route.sources[0] : undefined;\n const stream = route?.kind === EventSourceResolutionKind.Unique ? route.streams[0] : undefined;\n check(event.for, event.stream != null && source === undefined ? undefined : source?.identifier ?? eventDestinationType(event.eventType, slice, application, declarations), 'for');\n if (event.stream?.streamId != null) check(event.stream.streamId.source, stream?.streamId ?? undefined, 'streamId');\n for (const part of event.stream?.streamIdParts ?? []) check(part.source, stream?.streamIdParts.find(declaration => declaration.name === part.property)?.type, part.property);\n }\n for (const authored of [...specification.givenReadModels, ...specification.thenReadModels]) {\n const model = examples.readModel(authored, scope);\n assignments(model.properties, declarations.resolve(model.name, slice, slice => slice.readModels)?.node.properties ?? null);\n }\n if (specification.whenTrigger != null) {\n const trigger = (application.declaredTriggers ?? []).find(trigger => trigger.name === specification.whenTrigger!.trigger);\n for (const value of specification.whenTrigger.values) check(value.source, trigger?.data.find(property => property.name === value.property)?.type, value.property);\n }\n for (const error of specification.thenErrors) check(error.caseValue ?? null, { kind: 'TypeRefSyntax', name: 'String', isOptional: false, isCollection: false, location: error.location }, 'message');\n for (const absent of specification.thenAbsentReadModels ?? []) {\n const model = declarations.resolve(absent.name, slice, slice => slice.readModels)?.node;\n const keyed = declarations.slices.flatMap(({ slice: owner }) => owner.queries.filter(query => query.by !== null && declarations.resolve(query.returnType.name, owner, slice => slice.readModels)?.node === model));\n check(absent.key, model !== undefined && keyed.length === 1 ? keyed[0].by!.type : undefined, 'for');\n }\n for (const query of [...(specification.thenQueries ?? []), ...(specification.whenQuery === null ? [] : [specification.whenQuery])]) {\n const declaration = declarations.resolve(query.query, slice, slice => slice.queries);\n const parameters = declaration === null ? [] : [...(declaration.node.by === null ? [] : [declaration.node.by]), ...declaration.node.filters].map(parameter => ({ ...parameter, kind: 'PropertySyntax' as const, isIdentifier: false }));\n assignments(query.arguments, parameters);\n const properties = declaration === null ? null : declarations.resolve(declaration.node.returnType.name, declaration.slice, slice => slice.readModels)?.node.properties ?? null;\n const results = query.kind === 'SpecificationQuerySyntax' ? query.results : specification.thenResults;\n for (const result of results) assignments(result.properties, properties);\n }\n }\n }\n}\n\nfunction uniqueDestinationType(types: readonly TypeRefSyntax[]): TypeRefSyntax | undefined {\n const distinct = new Map(types.map(type => [JSON.stringify([type.name, type.isOptional, type.isCollection]), type]));\n return distinct.size === 1 ? [...distinct.values()][0] : undefined;\n}\n\nfunction eventDestinationType(reference: string, local: SliceSyntax, application: ApplicationSyntax, declarations: RefusalDeclarations): TypeRefSyntax | undefined {\n const resolver = new AuthoringProductionResolver(application);\n const event = declarations.event(reference, local);\n if (event === null) return undefined;\n const commandTypes = (event: EventSyntax, owners = declarations.slices): TypeRefSyntax[] => owners.flatMap(({ slice }) => slice.commands.flatMap(command => command.produces\n .filter(produced => resolver.isEventProduction(produced, slice) && declarations.event(produced.event, slice) === event)\n .map(produced => commandDestinationType(command, produced, application, { resolver, slice })).filter((type): type is TypeRefSyntax => type !== null)));\n const producerTypes = (event: EventSyntax, visited: Set<EventSyntax>): TypeRefSyntax[] => {\n if (visited.has(event)) return [];\n visited.add(event);\n const types = commandTypes(event);\n for (const { slice } of declarations.slices) {\n for (const trigger of slice.reactions.flatMap(reaction => reaction.triggers)) {\n const sourceName = trigger.source.kind === 'NamedTriggerSourceSyntax' ? trigger.source.name : undefined;\n const source = sourceName === undefined ? null : declarations.event(sourceName, slice);\n for (const produced of trigger.produces.filter(produced => declarations.event(produced.event, slice) === event)) {\n if (produced.for?.kind === 'PathExpressionSyntax') {\n const path = produced.for.path;\n const type = declarations.property(source?.properties ?? null, path)?.type ?? (sourceName === undefined ? undefined\n : (application.declaredTriggers ?? []).find(declared => declared.name === sourceName)?.data.find(property => property.name === path)?.type);\n if (type !== undefined) types.push(type);\n } else if (produced.for?.kind === 'LiteralExpressionSyntax') types.push({ kind: 'TypeRefSyntax', name: 'String', isOptional: false, isCollection: false, location: produced.location });\n else if (produced.for === null && source !== null) types.push(...producerTypes(source, visited));\n }\n }\n if (slice.captures.flatMap(capture => [...capture.appends, ...capture.children.flatMap(child => child.appends), ...capture.nested.flatMap(nested => nested.appends)]).some(append => declarations.event(append.event, slice) === event))\n types.push(uniqueDestinationType(commandTypes(event)) ?? { kind: 'TypeRefSyntax', name: 'String', isOptional: false, isCollection: false, location: event.location });\n }\n return types;\n };\n return uniqueDestinationType(commandTypes(event, declarations.slices.filter(owner => owner.slice === local))) ?? uniqueDestinationType(commandTypes(event)) ?? uniqueDestinationType(producerTypes(event, new Set()));\n}\n"],"mappings":"mmBAkBA,MAAMA,kBAAa,IAAI,IAAI,CAAC,OAAQ,SAAU,MAAO,UAAW,OAAQ,OAA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AS,OAASF,CAAU,CAAC,EAAE,KAAK,KAAK,GAAYrD,EAAS,OAASsD,CAAI,CAAC,EAAE,MACtIvD,IAAS,IAAA,IAAW6C,EAAM,KAAK7C,CAAI,CAC3C,MAAWkD,EAAS,KAAK,OAAS,0BAA2BL,EAAM,KAAK,CAAE,KAAM,gBAAiB,KAAM,SAAU,WAAY,GAAO,aAAc,GAAO,SAAUK,EAAS,QAAS,CAAC,EAC7KA,EAAS,MAAQ,MAAQnB,IAAW,MAAMc,EAAM,KAAK,GAAG,cAAcd,EAAQqB,CAAO,CAAC,CAEvG,CACI9C,EAAM,SAAS,QAAQ,GAAW,CAAC,GAAGmD,EAAQ,QAAS,GAAGA,EAAQ,SAAS,QAAQ,GAASC,EAAM,OAAO,EAAG,GAAGD,EAAQ,OAAO,QAAQ,GAAUE,EAAO,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,GAAUlE,EAAa,MAAMmE,EAAO,MAAOtD,CAAK,IAAMsB,CAAK,GAClOiB,EAAM,KAAK,sBAAsB,aAAajB,CAAK,CAAC,GAAK,CAAE,KAAM,gBAAiB,KAAM,SAAU,WAAY,GAAO,aAAc,GAAO,SAAUA,EAAM,QAAS,CAAC,CAC5K,CACA,OAAOiB,CACX,EACA,OAAO,sBAAsB,aAAajB,EAAOnC,EAAa,OAAO,OAAO,GAAS8C,EAAM,QAAUU,CAAK,CAAC,CAAC,GAAK,sBAAsB,aAAarB,CAAK,CAAC,GAAK,sBAAsB,cAAcA,kBAAO,IAAI,GAAK,CAAC,CACxN"}
@@ -1,2 +1,2 @@
1
- import"../../_virtual/_virtual/_rolldown/runtime.js";import{DiagnosticCodes as e}from"../Diagnostics/DiagnosticCodes.js";import{eventDeclarations as t}from"../Syntax/EventDeclarations.js";import{dependencySources as n,dependencySourcesOf as r}from"../Syntax/DependencySources.js";import{synthesizePersonaCaller as i}from"../Syntax/PersonaCallers.js";import{specificationCaseOrigins as a}from"../Syntax/SpecificationCaseOrigin.js";import{substituteCase as o}from"./SpecificationCaseParser.js";function specificationExamples(n){let r=[],examples=(e,t)=>{for(let n of e??[])r.push({name:n.name,scope:t,example:n})},features=(e,n)=>{for(let i of e){let e=[...n,i.name];examples(i.examples,e);for(let e of i.slices){let a=[...n,i.name,e.name];examples(e.examples,a);for(let n of new Set(t(e).map(e=>e.name)))r.push({name:n,scope:a,kind:`event`});for(let t of e.commands)r.push({name:t.name,scope:a,kind:`command`});for(let t of e.readModels)r.push({name:t.name,scope:a,kind:`readmodel`})}features(i.features,e)}};examples(n.examples,[]);for(let e of n.concepts)r.push({name:e.name,scope:[],kind:`concept`});for(let e of n.types)r.push({name:e.name,scope:[],kind:`type`});for(let e of n.modules)examples(e.examples,[e.name]),features(e.features,[e.name]);let resolveCandidates=(e,t)=>{let candidates=e=>{let n=e.split(`.`),i=r.filter(e=>e.name===n.at(-1)),a=n.slice(0,-1);if(a.length)return i.filter(e=>a.length<=e.scope.length&&a.every((t,n)=>e.scope[e.scope.length-a.length+n]===t));for(let e=t.length;e>=0;e--){let n=i.filter(n=>e<=n.scope.length&&t.slice(0,e).every((e,t)=>n.scope[t]===e));if(n.length)return n}return[]},i=candidates(e),a=n.imports.filter(t=>t.qualifiedName.split(`.`).at(-1)===e);return!i.length&&a.length===1&&(i=candidates(a[0].qualifiedName)),i},resolve=(e,t)=>{let n=resolveCandidates(e,t);return n.length===1?n[0]:void 0},fixture=(e,t,n)=>{let r=resolve(e,n),i=r?.example;if(!i)return null;let a=resolve(i.type,r.scope);return a?.kind===t?{example:i,name:[...a.scope,a.name].join(`.`)}:null},merge=(e,t)=>[...e.filter(e=>!t.some(t=>t.property===e.property)),...t];return{validateTypes:(t,i)=>{for(let a of r){let r=a.example;if(r===void 0||r.type===``)continue;let o=resolveCandidates(r.type,a.scope),s=o.length===1?o[0]:void 0;if(s===void 0){let s=n.imports.filter(e=>e.qualifiedName===r.type||e.qualifiedName.split(`.`).at(-1)===r.type);if(i&&o.length===0&&s.length===1&&resolveCandidates(s[0].qualifiedName,a.scope).length===0)continue;t.error(e.UnresolvedSpecificationExampleType,`Example '${r.name}' type '${r.type}' is unknown or ambiguous; qualify a declared event, command, or read model.`,r.location)}else s.kind!==`event`&&s.kind!==`command`&&s.kind!==`readmodel`&&t.error(e.UnresolvedSpecificationExampleType,`Example '${r.name}' must name an event, command, or read model, not a ${s.kind??`example`}; example inheritance is not supported.`,r.location)}},resolvedExamples:r.filter(e=>e.example!==void 0).flatMap(e=>{let t=resolve(e.example.type,e.scope);return t?.kind===void 0?[]:[{example:e.example,kind:t.kind,name:[...t.scope,t.name].join(`.`),scope:t.scope}]}),eventStep:(e,t,n)=>{let r=fixture(e.eventType,`event`,n),i=r?.example??null,a=i?.stream??i?.noStream??null,o=e.stream??e.noStream??null,s=o??a,c=r===null?e:{...e,eventType:r.name,values:merge(i.values,e.values),for:e.for??i.for,stream:s?.kind===`SpecificationStreamSyntax`?s:null,noStream:s?.kind===`SpecificationNoStreamSyntax`?s:null},l=c.values.map(t=>{let n=i?.values.find(e=>e.property===t.property),r=e.values.includes(t);return{property:t.property,value:t.source,origin:r?n===void 0?`authored`:`override`:`example`,overriddenValue:r?n?.source??null:null}});return c.for!==null&&l.push({property:`for`,value:c.for,origin:e.for===null?`example`:i?.for==null?`authored`:`override`,overriddenValue:e.for===null?null:i?.for??null}),{role:t,authored:e,effective:c,example:i,values:l,route:s===null?null:{value:s,origin:o===null?`example`:a===null?`authored`:`override`,overriddenValue:o===null?null:a}}},command:(e,t)=>{if(!e)return e;let n=fixture(e.commandType,`command`,t);if(!n)return e;let{example:r,name:i}=n;return{...e,commandType:i,values:merge(r.values,e.values),generatedValues:merge(r.generatedValues,e.generatedValues??[]),for:e.for??r.for}},readModel:(e,t)=>{let n=fixture(e.name,`readmodel`,t);return n?{...e,name:n.name,properties:merge(n.example.values,e.properties)}:e}}}function validateSpecificationExampleTypes(e,t,n=!1){specificationExamples(e).validateTypes(t,n)}function specificationCommandExamples(e){return specificationExamples(e).command}function expandSpecificationExamples(e){return expandEffectiveSpecificationExamples(e).application}function expandEffectiveSpecificationExamples(e){let t=specificationExamples(e),s=[],features=(c,l)=>c.map(c=>{let u=[...l,c.name];return{...c,features:features(c.features,u),slices:c.slices.map(u=>{let d=[...l,c.name,u.name],f={...u,specifications:u.specifications.flatMap(n=>{let r=[],event=(e,n)=>{let i=t.eventStep(e,n,d);return r.push(i),i.effective},c=e.personas.find(e=>e.name===n.givenCallerPersona?.name),l=c===void 0?null:i(c,e),u=l?.caller==null?null:{...l.caller,location:n.givenCallerPersona.location};u!==null&&r.push({role:`given caller`,authored:n.givenCallerPersona,effective:u,example:null,route:null,values:l.contributions.map(e=>({property:e.type??e.kind,value:{kind:`LiteralExpressionSyntax`,value:e.kind===`authenticated`||e.value,location:e.location},origin:`persona`,overriddenValue:null,persona:c.name,policy:e.policy}))});let f={...n,...u===null?{}:{givenCaller:u,givenCallerPersona:void 0},given:n.given.map(e=>event(e,`given`)),givenReadModels:n.givenReadModels.map(e=>t.readModel(e,d)),when:t.command(n.when,d),whenAppended:n.whenAppended===null?null:event(n.whenAppended,`when append`),thenEvents:n.thenEvents.map(e=>event(e,`then`)),thenReadModels:n.thenReadModels.map(e=>t.readModel(e,d))};return(n.cases?.length??0)===0?(s.push({authored:n,effective:f,steps:r}),[f]):n.cases.map(e=>{let t=/* @__PURE__ */ new WeakMap,i={...o(f,e,t),name:`${n.name}_${e.name}`,parameters:[],cases:[]};return a.set(i,{table:n.name,case:e.name}),s.push({authored:n,effective:i,table:n.name,case:e.name,steps:r.map(n=>({...n,effective:o(n.effective,e,t),values:n.values.map(n=>n.value.kind===`CaseValueExpressionSyntax`?{...n,value:o(n.value,e,t),origin:`case`,caseParameter:n.value.parameter}:n),route:n.route===null?null:{...n.route,value:o(n.route.value,e,t)}}))}),i})})};return n.set(f,r(u)),f})}});return{application:{...e,modules:e.modules.map(e=>({...e,features:features(e.features,[e.name])}))},specifications:s}}export{expandEffectiveSpecificationExamples,expandSpecificationExamples,specificationCommandExamples,specificationExamples,validateSpecificationExampleTypes};
1
+ import"../../_virtual/_virtual/_rolldown/runtime.js";import{DiagnosticCodes as e}from"../Diagnostics/DiagnosticCodes.js";import{eventDeclarations as t}from"../Syntax/EventDeclarations.js";import{dependencySources as n,dependencySourcesOf as r}from"../Syntax/DependencySources.js";import{diagnosticKeyword as i,diagnosticText as a}from"../Diagnostics/DiagnosticArgument.js";import{synthesizePersonaCaller as o}from"../Syntax/PersonaCallers.js";import{specificationCaseOrigins as s}from"../Syntax/SpecificationCaseOrigin.js";import{substituteCase as c}from"./SpecificationCaseParser.js";function specificationExamples(n){let r=[],examples=(e,t)=>{for(let n of e??[])r.push({name:n.name,scope:t,example:n})},features=(e,n)=>{for(let i of e){let e=[...n,i.name];examples(i.examples,e);for(let e of i.slices){let a=[...n,i.name,e.name];examples(e.examples,a);for(let n of new Set(t(e).map(e=>e.name)))r.push({name:n,scope:a,kind:`event`});for(let t of e.commands)r.push({name:t.name,scope:a,kind:`command`});for(let t of e.readModels)r.push({name:t.name,scope:a,kind:`readmodel`})}features(i.features,e)}};examples(n.examples,[]);for(let e of n.concepts)r.push({name:e.name,scope:[],kind:`concept`});for(let e of n.types)r.push({name:e.name,scope:[],kind:`type`});for(let e of n.modules)examples(e.examples,[e.name]),features(e.features,[e.name]);let resolveCandidates=(e,t)=>{let candidates=e=>{let n=e.split(`.`),i=r.filter(e=>e.name===n.at(-1)),a=n.slice(0,-1);if(a.length)return i.filter(e=>a.length<=e.scope.length&&a.every((t,n)=>e.scope[e.scope.length-a.length+n]===t));for(let e=t.length;e>=0;e--){let n=i.filter(n=>e<=n.scope.length&&t.slice(0,e).every((e,t)=>n.scope[t]===e));if(n.length)return n}return[]},i=candidates(e),a=n.imports.filter(t=>t.qualifiedName.split(`.`).at(-1)===e);return!i.length&&a.length===1&&(i=candidates(a[0].qualifiedName)),i},resolve=(e,t)=>{let n=resolveCandidates(e,t);return n.length===1?n[0]:void 0},fixture=(e,t,n)=>{let r=resolve(e,n),i=r?.example;if(!i)return null;let a=resolve(i.type,r.scope);return a?.kind===t?{example:i,name:[...a.scope,a.name].join(`.`)}:null},merge=(e,t)=>[...e.filter(e=>!t.some(t=>t.property===e.property)),...t];return{validateTypes:(t,o)=>{for(let s of r){let r=s.example;if(r===void 0||r.type===``)continue;let c=resolveCandidates(r.type,s.scope),l=c.length===1?c[0]:void 0;if(l===void 0){let i=n.imports.filter(e=>e.qualifiedName===r.type||e.qualifiedName.split(`.`).at(-1)===r.type);if(o&&c.length===0&&i.length===1&&resolveCandidates(i[0].qualifiedName,s.scope).length===0)continue;t.error(e.UnresolvedSpecificationExampleType,`Example '${r.name}' type '${r.type}' is unknown or ambiguous; qualify a declared event, command, or read model.`,r.location,{...a(`example`,r.name),...a(`type`,r.type)})}else l.kind!==`event`&&l.kind!==`command`&&l.kind!==`readmodel`&&t.error(e.UnresolvedSpecificationExampleType,`Example '${r.name}' must name an event, command, or read model, not a ${l.kind??`example`}; example inheritance is not supported.`,r.location,{...a(`example`,r.name),...a(`type`,r.type),...i(`kind`,l.kind??`example`)})}},resolvedExamples:r.filter(e=>e.example!==void 0).flatMap(e=>{let t=resolve(e.example.type,e.scope);return t?.kind===void 0?[]:[{example:e.example,kind:t.kind,name:[...t.scope,t.name].join(`.`),scope:t.scope}]}),eventStep:(e,t,n)=>{let r=fixture(e.eventType,`event`,n),i=r?.example??null,a=i?.stream??i?.noStream??null,o=e.stream??e.noStream??null,s=o??a,c=r===null?e:{...e,eventType:r.name,values:merge(i.values,e.values),for:e.for??i.for,stream:s?.kind===`SpecificationStreamSyntax`?s:null,noStream:s?.kind===`SpecificationNoStreamSyntax`?s:null},l=c.values.map(t=>{let n=i?.values.find(e=>e.property===t.property),r=e.values.includes(t);return{property:t.property,value:t.source,origin:r?n===void 0?`authored`:`override`:`example`,overriddenValue:r?n?.source??null:null}});return c.for!==null&&l.push({property:`for`,value:c.for,origin:e.for===null?`example`:i?.for==null?`authored`:`override`,overriddenValue:e.for===null?null:i?.for??null}),{role:t,authored:e,effective:c,example:i,values:l,route:s===null?null:{value:s,origin:o===null?`example`:a===null?`authored`:`override`,overriddenValue:o===null?null:a}}},command:(e,t)=>{if(!e)return e;let n=fixture(e.commandType,`command`,t);if(!n)return e;let{example:r,name:i}=n;return{...e,commandType:i,values:merge(r.values,e.values),generatedValues:merge(r.generatedValues,e.generatedValues??[]),for:e.for??r.for}},readModel:(e,t)=>{let n=fixture(e.name,`readmodel`,t);return n?{...e,name:n.name,properties:merge(n.example.values,e.properties)}:e}}}function validateSpecificationExampleTypes(e,t,n=!1){specificationExamples(e).validateTypes(t,n)}function specificationCommandExamples(e){return specificationExamples(e).command}function expandSpecificationExamples(e){return expandEffectiveSpecificationExamples(e).application}function expandEffectiveSpecificationExamples(e){let t=specificationExamples(e),i=[],features=(a,l)=>a.map(a=>{let u=[...l,a.name];return{...a,features:features(a.features,u),slices:a.slices.map(u=>{let d=[...l,a.name,u.name],f={...u,specifications:u.specifications.flatMap(n=>{let r=[],event=(e,n)=>{let i=t.eventStep(e,n,d);return r.push(i),i.effective},a=e.personas.find(e=>e.name===n.givenCallerPersona?.name),l=a===void 0?null:o(a,e),u=l?.caller==null?null:{...l.caller,location:n.givenCallerPersona.location};u!==null&&r.push({role:`given caller`,authored:n.givenCallerPersona,effective:u,example:null,route:null,values:l.contributions.map(e=>({property:e.type??e.kind,value:{kind:`LiteralExpressionSyntax`,value:e.kind===`authenticated`||e.value,location:e.location},origin:`persona`,overriddenValue:null,persona:a.name,policy:e.policy}))});let f={...n,...u===null?{}:{givenCaller:u,givenCallerPersona:void 0},given:n.given.map(e=>event(e,`given`)),givenReadModels:n.givenReadModels.map(e=>t.readModel(e,d)),when:t.command(n.when,d),whenAppended:n.whenAppended===null?null:event(n.whenAppended,`when append`),thenEvents:n.thenEvents.map(e=>event(e,`then`)),thenReadModels:n.thenReadModels.map(e=>t.readModel(e,d))};return(n.cases?.length??0)===0?(i.push({authored:n,effective:f,steps:r}),[f]):n.cases.map(e=>{let t=/* @__PURE__ */ new WeakMap,a={...c(f,e,t),name:`${n.name}_${e.name}`,parameters:[],cases:[]};return s.set(a,{table:n.name,case:e.name}),i.push({authored:n,effective:a,table:n.name,case:e.name,steps:r.map(n=>({...n,effective:c(n.effective,e,t),values:n.values.map(n=>n.value.kind===`CaseValueExpressionSyntax`?{...n,value:c(n.value,e,t),origin:`case`,caseParameter:n.value.parameter}:n),route:n.route===null?null:{...n.route,value:c(n.route.value,e,t)}}))}),a})})};return n.set(f,r(u)),f})}});return{application:{...e,modules:e.modules.map(e=>({...e,features:features(e.features,[e.name])}))},specifications:i}}export{expandEffectiveSpecificationExamples,expandSpecificationExamples,specificationCommandExamples,specificationExamples,validateSpecificationExampleTypes};
2
2
  //# sourceMappingURL=SpecificationCommandExamples.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SpecificationCommandExamples.js","names":["entries","example","nodes","feature","scope","parent","slice","name","eventDeclarations","event","command","model","application","node","module","parts","reference","named","entry","qualifiers","index","part","depth","visible","matches","imported","declaration","type","kind","inherited","authored","replacement","value","deferImportedTypes","context","DiagnosticCodes","resolved","step","route","effective","values","prior","action","specifications","expanded","steps","pair","role","persona","specification","caller","synthesizePersonaCaller","synthesizedCaller","atom","result","copies","substituteCase","row","specificationCaseOrigins","dependencySources","dependencySourcesOf"],"sources":["../../../../../../Compiler/Parsing/SpecificationCommandExamples.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 { ParserContext } from './ParserContext';\nimport { synthesizePersonaCaller } from '../Syntax/PersonaCallers';\nimport { specificationCaseOrigins } from '../Syntax/SpecificationCaseOrigin';\nimport { substituteCase } from './SpecificationCaseParser';\nimport { dependencySources, dependencySourcesOf } from '../Syntax/DependencySources';\nimport { eventDeclarations } from '../Syntax/EventDeclarations';\nimport { EffectiveSpecification, EffectiveSpecificationStep, EffectiveSpecificationValue, EffectiveSpecificationApplication } from '../Syntax/EffectiveSpecification';\nimport { PropertyMappingSyntax } from '../Syntax/Expressions';\nimport { SpecificationCommandSyntax, SpecificationEventSyntax, SpecificationReadModelSyntax } from '../Syntax/Specifications';\nimport { SpecificationExampleSyntax } from '../Syntax/SpecificationExampleSyntax';\nimport { ApplicationSyntax, FeatureSyntax } from '../Syntax/Structure';\n\n// Validators consume effective fixtures without changing the authored syntax.\n// Resolve the example at its use site, then its type at the declaration site.\nexport function specificationExamples(application: ApplicationSyntax) {\n const entries: { name: string; scope: readonly string[]; example?: SpecificationExampleSyntax; kind?: string }[] = [];\n const examples = (nodes: readonly SpecificationExampleSyntax[] | undefined, scope: readonly string[]) => {\n for (const example of nodes ?? []) entries.push({ name: example.name, scope, example });\n };\n const features = (nodes: readonly FeatureSyntax[], parent: readonly string[]) => {\n for (const feature of nodes) {\n const scope = [...parent, feature.name];\n examples(feature.examples, scope);\n for (const slice of feature.slices) {\n const scope = [...parent, feature.name, slice.name];\n examples(slice.examples, scope);\n for (const name of new Set(eventDeclarations(slice).map(event => event.name))) entries.push({ name, scope, kind: 'event' });\n for (const command of slice.commands) entries.push({ name: command.name, scope, kind: 'command' });\n for (const model of slice.readModels) entries.push({ name: model.name, scope, kind: 'readmodel' });\n }\n features(feature.features, scope);\n }\n };\n examples(application.examples, []);\n for (const node of application.concepts) entries.push({ name: node.name, scope: [], kind: 'concept' });\n for (const node of application.types) entries.push({ name: node.name, scope: [], kind: 'type' });\n for (const module of application.modules) { examples(module.examples, [module.name]); features(module.features, [module.name]); }\n const resolveCandidates = (reference: string, scope: readonly string[]) => {\n const candidates = (reference: string) => {\n const parts = reference.split('.');\n const named = entries.filter(entry => entry.name === parts.at(-1));\n const qualifiers = parts.slice(0, -1);\n if (qualifiers.length) return named.filter(entry => qualifiers.length <= entry.scope.length && qualifiers.every((part, index) => entry.scope[entry.scope.length - qualifiers.length + index] === part));\n for (let depth = scope.length; depth >= 0; depth--) {\n const visible = named.filter(entry => depth <= entry.scope.length && scope.slice(0, depth).every((part, index) => entry.scope[index] === part));\n if (visible.length) return visible;\n }\n return [];\n };\n let matches = candidates(reference);\n const imported = application.imports.filter(entry => entry.qualifiedName.split('.').at(-1) === reference);\n if (!matches.length && imported.length === 1) matches = candidates(imported[0].qualifiedName);\n return matches;\n };\n const resolve = (reference: string, scope: readonly string[]) => {\n const matches = resolveCandidates(reference, scope);\n return matches.length === 1 ? matches[0] : undefined;\n };\n const fixture = (reference: string, kind: string, scope: readonly string[]) => {\n const declaration = resolve(reference, scope);\n const example = declaration?.example;\n if (!example) return null;\n const type = resolve(example.type, declaration.scope);\n return type?.kind === kind ? { example, name: [...type.scope, type.name].join('.') } : null;\n };\n const merge = (inherited: readonly PropertyMappingSyntax[], authored: readonly PropertyMappingSyntax[]) => [...inherited.filter(value => !authored.some(replacement => replacement.property === value.property)), ...authored];\n return {\n validateTypes: (context: ParserContext, deferImportedTypes: boolean) => {\n for (const entry of entries) {\n const example = entry.example;\n if (example === undefined || example.type === '') continue;\n const matches = resolveCandidates(example.type, entry.scope);\n const type = matches.length === 1 ? matches[0] : undefined;\n if (type === undefined) {\n const imported = application.imports.filter(imported => imported.qualifiedName === example.type || imported.qualifiedName.split('.').at(-1) === example.type);\n if (deferImportedTypes && matches.length === 0 && imported.length === 1 && resolveCandidates(imported[0].qualifiedName, entry.scope).length === 0) continue;\n context.error(DiagnosticCodes.UnresolvedSpecificationExampleType, `Example '${example.name}' type '${example.type}' is unknown or ambiguous; qualify a declared event, command, or read model.`, example.location);\n } else if (type.kind !== 'event' && type.kind !== 'command' && type.kind !== 'readmodel') {\n context.error(DiagnosticCodes.UnresolvedSpecificationExampleType, `Example '${example.name}' must name an event, command, or read model, not a ${type.kind ?? 'example'}; example inheritance is not supported.`, example.location);\n }\n }\n },\n resolvedExamples: entries.filter(entry => entry.example !== undefined).flatMap(entry => {\n const type = resolve(entry.example!.type, entry.scope);\n return type?.kind === undefined ? [] : [{ example: entry.example!, kind: type.kind, name: [...type.scope, type.name].join('.'), scope: type.scope }];\n }),\n eventStep: (step: SpecificationEventSyntax, role: string, scope: readonly string[]): EffectiveSpecificationStep => {\n const resolved = fixture(step.eventType, 'event', scope);\n const example = resolved?.example ?? null;\n const inherited = example?.stream ?? example?.noStream ?? null;\n const authored = step.stream ?? step.noStream ?? null;\n const route = authored ?? inherited;\n const effective = resolved === null ? step : { ...step, eventType: resolved.name, values: merge(example!.values, step.values), for: step.for ?? example!.for, stream: route?.kind === 'SpecificationStreamSyntax' ? route : null, noStream: route?.kind === 'SpecificationNoStreamSyntax' ? route : null };\n const values: EffectiveSpecificationValue[] = effective.values.map(value => {\n const prior = example?.values.find(prior => prior.property === value.property);\n const replacement = step.values.includes(value);\n return { property: value.property, value: value.source, origin: replacement ? prior === undefined ? 'authored' : 'override' : 'example', overriddenValue: replacement ? prior?.source ?? null : null };\n });\n if (effective.for !== null) values.push({ property: 'for', value: effective.for, origin: step.for === null ? 'example' : example?.for == null ? 'authored' : 'override', overriddenValue: step.for === null ? null : example?.for ?? null });\n return { role, authored: step, effective, example, values, route: route === null ? null : { value: route, origin: authored === null ? 'example' : inherited === null ? 'authored' : 'override', overriddenValue: authored === null ? null : inherited } };\n },\n command: (action: SpecificationCommandSyntax | null, scope: readonly string[]): SpecificationCommandSyntax | null => {\n if (!action) return action;\n const effective = fixture(action.commandType, 'command', scope);\n if (!effective) return action;\n const { example, name } = effective;\n return { ...action, commandType: name, values: merge(example.values, action.values), generatedValues: merge(example.generatedValues, action.generatedValues ?? []), for: action.for ?? example.for };\n },\n readModel: (step: SpecificationReadModelSyntax, scope: readonly string[]): SpecificationReadModelSyntax => {\n const effective = fixture(step.name, 'readmodel', scope);\n if (!effective) return step;\n return { ...step, name: effective.name, properties: merge(effective.example.values, step.properties) };\n },\n };\n}\n\nexport function validateSpecificationExampleTypes(application: ApplicationSyntax, context: ParserContext, deferImportedTypes = false): void {\n specificationExamples(application).validateTypes(context, deferImportedTypes);\n}\n\nexport function specificationCommandExamples(application: ApplicationSyntax): (action: SpecificationCommandSyntax | null, scope: readonly string[]) => SpecificationCommandSyntax | null {\n return specificationExamples(application).command;\n}\n\nexport function expandSpecificationExamples(application: ApplicationSyntax): ApplicationSyntax {\n return expandEffectiveSpecificationExamples(application).application;\n}\n\nexport function expandEffectiveSpecificationExamples(application: ApplicationSyntax): EffectiveSpecificationApplication {\n const effective = specificationExamples(application);\n const specifications: EffectiveSpecification[] = [];\n const features = (nodes: readonly FeatureSyntax[], parent: readonly string[]): FeatureSyntax[] => nodes.map(feature => {\n const scope = [...parent, feature.name];\n return {\n ...feature,\n features: features(feature.features, scope),\n slices: feature.slices.map(slice => {\n const scope = [...parent, feature.name, slice.name];\n const expanded = { ...slice, specifications: slice.specifications.flatMap(specification => {\n const steps: EffectiveSpecificationStep[] = [];\n const event = (step: SpecificationEventSyntax, role: string): SpecificationEventSyntax => {\n const pair = effective.eventStep(step, role, scope);\n steps.push(pair);\n return pair.effective as SpecificationEventSyntax;\n };\n const persona = application.personas.find(persona => persona.name === specification.givenCallerPersona?.name);\n const caller = persona === undefined ? null : synthesizePersonaCaller(persona, application);\n const synthesizedCaller = caller?.caller == null ? null : { ...caller.caller, location: specification.givenCallerPersona!.location };\n if (synthesizedCaller !== null) {\n steps.push({ role: 'given caller', authored: specification.givenCallerPersona!, effective: synthesizedCaller, example: null, route: null,\n values: caller!.contributions.map(atom => ({ property: atom.type ?? atom.kind, value: { kind: 'LiteralExpressionSyntax', value: atom.kind === 'authenticated' ? true : atom.value, location: atom.location }, origin: 'persona', overriddenValue: null, persona: persona!.name, policy: atom.policy })) });\n }\n const result = {\n ...specification,\n ...(synthesizedCaller === null ? {} : { givenCaller: synthesizedCaller, givenCallerPersona: undefined }),\n given: specification.given.map(step => event(step, 'given')),\n givenReadModels: specification.givenReadModels.map(step => effective.readModel(step, scope)),\n when: effective.command(specification.when, scope),\n whenAppended: specification.whenAppended === null ? null : event(specification.whenAppended, 'when append'),\n thenEvents: specification.thenEvents.map(step => event(step, 'then')),\n thenReadModels: specification.thenReadModels.map(step => effective.readModel(step, scope)),\n };\n if ((specification.cases?.length ?? 0) === 0) {\n specifications.push({ authored: specification, effective: result, steps });\n return [result];\n }\n return specification.cases!.map(row => {\n const copies = new WeakMap<object, unknown>();\n const expanded = { ...substituteCase(result, row, copies), name: `${specification.name}_${row.name}`, parameters: [], cases: [] };\n specificationCaseOrigins.set(expanded, { table: specification.name, case: row.name });\n specifications.push({ authored: specification, effective: expanded, table: specification.name, case: row.name,\n steps: steps.map(step => ({ ...step, effective: substituteCase(step.effective, row, copies),\n values: step.values.map(value => value.value.kind === 'CaseValueExpressionSyntax'\n ? { ...value, value: substituteCase(value.value, row, copies), origin: 'case', caseParameter: value.value.parameter } : value),\n route: step.route === null ? null : { ...step.route, value: substituteCase(step.route.value, row, copies) } })) });\n return expanded;\n });\n }) };\n dependencySources.set(expanded, dependencySourcesOf(slice));\n return expanded;\n }),\n };\n });\n return { application: { ...application, modules: application.modules.map(module => ({ ...module, features: features(module.features, [module.name]) })) }, specifications };\n}\n"],"mappings":"4eAkBA,SAAgB,sBAAsB,EAAgC,CAClE,IAAMA,EAA6G,CAAC,EAC9G,UAAY,EAA0D,IAA6B,CACrG,IAAK,IAAMC,KAAWC,GAAS,CAAC,EAAGF,EAAQ,KAAK,CAAE,KAAMC,EAAQ,KAAM,QAAO,SAAQ,CAAC,CAC1F,EACM,UAAY,EAAiC,IAA8B,CAC7E,IAAK,IAAME,KAAWD,EAAO,CACzB,IAAME,EAAQ,CAAC,GAAGC,EAAQF,EAAQ,IAAI,EACtC,SAASA,EAAQ,SAAUC,CAAK,EAChC,IAAK,IAAME,KAASH,EAAQ,OAAQ,CAChC,IAAMC,EAAQ,CAAC,GAAGC,EAAQF,EAAQ,KAAMG,EAAM,IAAI,EAClD,SAASA,EAAM,SAAUF,CAAK,EAC9B,IAAK,IAAMG,KAAQ,IAAI,IAAIC,EAAkBF,CAAK,CAAC,CAAC,IAAI,GAASG,EAAM,IAAI,CAAC,EAAGT,EAAQ,KAAK,CAAE,OAAM,QAAO,K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,CAAC,EAAG,MAAO,CAAC,CAAE,EAOhI,OANAC,EAAyB,IAAId,EAAU,CAAE,MAAOK,EAAc,KAAM,KAAMQ,EAAI,IAAK,CAAC,EACpFd,EAAe,KAAK,CAAE,SAAUM,EAAe,UAAWL,EAAU,MAAOK,EAAc,KAAM,KAAMQ,EAAI,KACrG,MAAOZ,EAAM,IAAI,IAAS,CAAE,GAAGR,EAAM,UAAWmB,EAAenB,EAAK,UAAWoB,EAAKF,CAAM,EACtF,OAAQlB,EAAK,OAAO,IAAI,GAASL,EAAM,MAAM,OAAS,4BAChD,CAAE,GAAGA,EAAO,MAAOwB,EAAexB,EAAM,MAAOyB,EAAKF,CAAM,EAAG,OAAQ,OAAQ,cAAevB,EAAM,MAAM,SAAU,EAAIA,CAAK,EACjI,MAAOK,EAAK,QAAU,KAAO,KAAO,CAAE,GAAGA,EAAK,MAAO,MAAOmB,EAAenB,EAAK,MAAM,MAAOoB,EAAKF,CAAM,CAAE,CAAE,EAAE,CAAE,CAAC,EAClHX,CACX,CAAC,CACL,CAAC,CAAE,EAEH,OADAe,EAAkB,IAAIf,EAAUgB,EAAoBtD,CAAK,CAAC,EACnDsC,CACX,CAAC,CACL,CACJ,CAAC,EACD,MAAO,CAAE,YAAa,CAAE,GAAGhC,EAAa,QAASA,EAAY,QAAQ,IAAI,IAAW,CAAE,GAAGE,EAAQ,SAAU,SAASA,EAAO,SAAU,CAACA,EAAO,IAAI,CAAC,CAAE,EAAE,CAAE,EAAG,gBAAe,CAC9K"}
1
+ {"version":3,"file":"SpecificationCommandExamples.js","names":["entries","example","nodes","feature","scope","parent","slice","name","eventDeclarations","event","command","model","application","node","module","parts","reference","named","entry","qualifiers","index","part","depth","visible","matches","imported","declaration","type","kind","inherited","authored","replacement","value","deferImportedTypes","context","DiagnosticCodes","diagnosticText","diagnosticKeyword","resolved","step","route","effective","values","prior","action","specifications","expanded","steps","pair","role","persona","specification","caller","synthesizePersonaCaller","synthesizedCaller","atom","result","copies","substituteCase","row","specificationCaseOrigins","dependencySources","dependencySourcesOf"],"sources":["../../../../../../Compiler/Parsing/SpecificationCommandExamples.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 { diagnosticKeyword, diagnosticText } from '../Diagnostics/DiagnosticArgument';\nimport { DiagnosticCodes } from '../Diagnostics/DiagnosticCodes';\nimport { ParserContext } from './ParserContext';\nimport { synthesizePersonaCaller } from '../Syntax/PersonaCallers';\nimport { specificationCaseOrigins } from '../Syntax/SpecificationCaseOrigin';\nimport { substituteCase } from './SpecificationCaseParser';\nimport { dependencySources, dependencySourcesOf } from '../Syntax/DependencySources';\nimport { eventDeclarations } from '../Syntax/EventDeclarations';\nimport { EffectiveSpecification, EffectiveSpecificationStep, EffectiveSpecificationValue, EffectiveSpecificationApplication } from '../Syntax/EffectiveSpecification';\nimport { PropertyMappingSyntax } from '../Syntax/Expressions';\nimport { SpecificationCommandSyntax, SpecificationEventSyntax, SpecificationReadModelSyntax } from '../Syntax/Specifications';\nimport { SpecificationExampleSyntax } from '../Syntax/SpecificationExampleSyntax';\nimport { ApplicationSyntax, FeatureSyntax } from '../Syntax/Structure';\n\n// Validators consume effective fixtures without changing the authored syntax.\n// Resolve the example at its use site, then its type at the declaration site.\nexport function specificationExamples(application: ApplicationSyntax) {\n const entries: { name: string; scope: readonly string[]; example?: SpecificationExampleSyntax; kind?: string }[] = [];\n const examples = (nodes: readonly SpecificationExampleSyntax[] | undefined, scope: readonly string[]) => {\n for (const example of nodes ?? []) entries.push({ name: example.name, scope, example });\n };\n const features = (nodes: readonly FeatureSyntax[], parent: readonly string[]) => {\n for (const feature of nodes) {\n const scope = [...parent, feature.name];\n examples(feature.examples, scope);\n for (const slice of feature.slices) {\n const scope = [...parent, feature.name, slice.name];\n examples(slice.examples, scope);\n for (const name of new Set(eventDeclarations(slice).map(event => event.name))) entries.push({ name, scope, kind: 'event' });\n for (const command of slice.commands) entries.push({ name: command.name, scope, kind: 'command' });\n for (const model of slice.readModels) entries.push({ name: model.name, scope, kind: 'readmodel' });\n }\n features(feature.features, scope);\n }\n };\n examples(application.examples, []);\n for (const node of application.concepts) entries.push({ name: node.name, scope: [], kind: 'concept' });\n for (const node of application.types) entries.push({ name: node.name, scope: [], kind: 'type' });\n for (const module of application.modules) { examples(module.examples, [module.name]); features(module.features, [module.name]); }\n const resolveCandidates = (reference: string, scope: readonly string[]) => {\n const candidates = (reference: string) => {\n const parts = reference.split('.');\n const named = entries.filter(entry => entry.name === parts.at(-1));\n const qualifiers = parts.slice(0, -1);\n if (qualifiers.length) return named.filter(entry => qualifiers.length <= entry.scope.length && qualifiers.every((part, index) => entry.scope[entry.scope.length - qualifiers.length + index] === part));\n for (let depth = scope.length; depth >= 0; depth--) {\n const visible = named.filter(entry => depth <= entry.scope.length && scope.slice(0, depth).every((part, index) => entry.scope[index] === part));\n if (visible.length) return visible;\n }\n return [];\n };\n let matches = candidates(reference);\n const imported = application.imports.filter(entry => entry.qualifiedName.split('.').at(-1) === reference);\n if (!matches.length && imported.length === 1) matches = candidates(imported[0].qualifiedName);\n return matches;\n };\n const resolve = (reference: string, scope: readonly string[]) => {\n const matches = resolveCandidates(reference, scope);\n return matches.length === 1 ? matches[0] : undefined;\n };\n const fixture = (reference: string, kind: string, scope: readonly string[]) => {\n const declaration = resolve(reference, scope);\n const example = declaration?.example;\n if (!example) return null;\n const type = resolve(example.type, declaration.scope);\n return type?.kind === kind ? { example, name: [...type.scope, type.name].join('.') } : null;\n };\n const merge = (inherited: readonly PropertyMappingSyntax[], authored: readonly PropertyMappingSyntax[]) => [...inherited.filter(value => !authored.some(replacement => replacement.property === value.property)), ...authored];\n return {\n validateTypes: (context: ParserContext, deferImportedTypes: boolean) => {\n for (const entry of entries) {\n const example = entry.example;\n if (example === undefined || example.type === '') continue;\n const matches = resolveCandidates(example.type, entry.scope);\n const type = matches.length === 1 ? matches[0] : undefined;\n if (type === undefined) {\n const imported = application.imports.filter(imported => imported.qualifiedName === example.type || imported.qualifiedName.split('.').at(-1) === example.type);\n if (deferImportedTypes && matches.length === 0 && imported.length === 1 && resolveCandidates(imported[0].qualifiedName, entry.scope).length === 0) continue;\n context.error(DiagnosticCodes.UnresolvedSpecificationExampleType, `Example '${example.name}' type '${example.type}' is unknown or ambiguous; qualify a declared event, command, or read model.`, example.location, { ...diagnosticText('example', example.name), ...diagnosticText('type', example.type) });\n } else if (type.kind !== 'event' && type.kind !== 'command' && type.kind !== 'readmodel') {\n context.error(DiagnosticCodes.UnresolvedSpecificationExampleType, `Example '${example.name}' must name an event, command, or read model, not a ${type.kind ?? 'example'}; example inheritance is not supported.`, example.location, { ...diagnosticText('example', example.name), ...diagnosticText('type', example.type), ...diagnosticKeyword('kind', type.kind ?? 'example') });\n }\n }\n },\n resolvedExamples: entries.filter(entry => entry.example !== undefined).flatMap(entry => {\n const type = resolve(entry.example!.type, entry.scope);\n return type?.kind === undefined ? [] : [{ example: entry.example!, kind: type.kind, name: [...type.scope, type.name].join('.'), scope: type.scope }];\n }),\n eventStep: (step: SpecificationEventSyntax, role: string, scope: readonly string[]): EffectiveSpecificationStep => {\n const resolved = fixture(step.eventType, 'event', scope);\n const example = resolved?.example ?? null;\n const inherited = example?.stream ?? example?.noStream ?? null;\n const authored = step.stream ?? step.noStream ?? null;\n const route = authored ?? inherited;\n const effective = resolved === null ? step : { ...step, eventType: resolved.name, values: merge(example!.values, step.values), for: step.for ?? example!.for, stream: route?.kind === 'SpecificationStreamSyntax' ? route : null, noStream: route?.kind === 'SpecificationNoStreamSyntax' ? route : null };\n const values: EffectiveSpecificationValue[] = effective.values.map(value => {\n const prior = example?.values.find(prior => prior.property === value.property);\n const replacement = step.values.includes(value);\n return { property: value.property, value: value.source, origin: replacement ? prior === undefined ? 'authored' : 'override' : 'example', overriddenValue: replacement ? prior?.source ?? null : null };\n });\n if (effective.for !== null) values.push({ property: 'for', value: effective.for, origin: step.for === null ? 'example' : example?.for == null ? 'authored' : 'override', overriddenValue: step.for === null ? null : example?.for ?? null });\n return { role, authored: step, effective, example, values, route: route === null ? null : { value: route, origin: authored === null ? 'example' : inherited === null ? 'authored' : 'override', overriddenValue: authored === null ? null : inherited } };\n },\n command: (action: SpecificationCommandSyntax | null, scope: readonly string[]): SpecificationCommandSyntax | null => {\n if (!action) return action;\n const effective = fixture(action.commandType, 'command', scope);\n if (!effective) return action;\n const { example, name } = effective;\n return { ...action, commandType: name, values: merge(example.values, action.values), generatedValues: merge(example.generatedValues, action.generatedValues ?? []), for: action.for ?? example.for };\n },\n readModel: (step: SpecificationReadModelSyntax, scope: readonly string[]): SpecificationReadModelSyntax => {\n const effective = fixture(step.name, 'readmodel', scope);\n if (!effective) return step;\n return { ...step, name: effective.name, properties: merge(effective.example.values, step.properties) };\n },\n };\n}\n\nexport function validateSpecificationExampleTypes(application: ApplicationSyntax, context: ParserContext, deferImportedTypes = false): void {\n specificationExamples(application).validateTypes(context, deferImportedTypes);\n}\n\nexport function specificationCommandExamples(application: ApplicationSyntax): (action: SpecificationCommandSyntax | null, scope: readonly string[]) => SpecificationCommandSyntax | null {\n return specificationExamples(application).command;\n}\n\nexport function expandSpecificationExamples(application: ApplicationSyntax): ApplicationSyntax {\n return expandEffectiveSpecificationExamples(application).application;\n}\n\nexport function expandEffectiveSpecificationExamples(application: ApplicationSyntax): EffectiveSpecificationApplication {\n const effective = specificationExamples(application);\n const specifications: EffectiveSpecification[] = [];\n const features = (nodes: readonly FeatureSyntax[], parent: readonly string[]): FeatureSyntax[] => nodes.map(feature => {\n const scope = [...parent, feature.name];\n return {\n ...feature,\n features: features(feature.features, scope),\n slices: feature.slices.map(slice => {\n const scope = [...parent, feature.name, slice.name];\n const expanded = { ...slice, specifications: slice.specifications.flatMap(specification => {\n const steps: EffectiveSpecificationStep[] = [];\n const event = (step: SpecificationEventSyntax, role: string): SpecificationEventSyntax => {\n const pair = effective.eventStep(step, role, scope);\n steps.push(pair);\n return pair.effective as SpecificationEventSyntax;\n };\n const persona = application.personas.find(persona => persona.name === specification.givenCallerPersona?.name);\n const caller = persona === undefined ? null : synthesizePersonaCaller(persona, application);\n const synthesizedCaller = caller?.caller == null ? null : { ...caller.caller, location: specification.givenCallerPersona!.location };\n if (synthesizedCaller !== null) {\n steps.push({ role: 'given caller', authored: specification.givenCallerPersona!, effective: synthesizedCaller, example: null, route: null,\n values: caller!.contributions.map(atom => ({ property: atom.type ?? atom.kind, value: { kind: 'LiteralExpressionSyntax', value: atom.kind === 'authenticated' ? true : atom.value, location: atom.location }, origin: 'persona', overriddenValue: null, persona: persona!.name, policy: atom.policy })) });\n }\n const result = {\n ...specification,\n ...(synthesizedCaller === null ? {} : { givenCaller: synthesizedCaller, givenCallerPersona: undefined }),\n given: specification.given.map(step => event(step, 'given')),\n givenReadModels: specification.givenReadModels.map(step => effective.readModel(step, scope)),\n when: effective.command(specification.when, scope),\n whenAppended: specification.whenAppended === null ? null : event(specification.whenAppended, 'when append'),\n thenEvents: specification.thenEvents.map(step => event(step, 'then')),\n thenReadModels: specification.thenReadModels.map(step => effective.readModel(step, scope)),\n };\n if ((specification.cases?.length ?? 0) === 0) {\n specifications.push({ authored: specification, effective: result, steps });\n return [result];\n }\n return specification.cases!.map(row => {\n const copies = new WeakMap<object, unknown>();\n const expanded = { ...substituteCase(result, row, copies), name: `${specification.name}_${row.name}`, parameters: [], cases: [] };\n specificationCaseOrigins.set(expanded, { table: specification.name, case: row.name });\n specifications.push({ authored: specification, effective: expanded, table: specification.name, case: row.name,\n steps: steps.map(step => ({ ...step, effective: substituteCase(step.effective, row, copies),\n values: step.values.map(value => value.value.kind === 'CaseValueExpressionSyntax'\n ? { ...value, value: substituteCase(value.value, row, copies), origin: 'case', caseParameter: value.value.parameter } : value),\n route: step.route === null ? null : { ...step.route, value: substituteCase(step.route.value, row, copies) } })) });\n return expanded;\n });\n }) };\n dependencySources.set(expanded, dependencySourcesOf(slice));\n return expanded;\n }),\n };\n });\n return { application: { ...application, modules: application.modules.map(module => ({ ...module, features: features(module.features, [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AM,MAAM,OAAS,4BAChD,CAAE,GAAGA,EAAO,MAAO0B,EAAe1B,EAAM,MAAO2B,EAAKF,CAAM,EAAG,OAAQ,OAAQ,cAAezB,EAAM,MAAM,SAAU,EAAIA,CAAK,EACjI,MAAOO,EAAK,QAAU,KAAO,KAAO,CAAE,GAAGA,EAAK,MAAO,MAAOmB,EAAenB,EAAK,MAAM,MAAOoB,EAAKF,CAAM,CAAE,CAAE,EAAE,CAAE,CAAC,EAClHX,CACX,CAAC,CACL,CAAC,CAAE,EAEH,OADAe,EAAkB,IAAIf,EAAUgB,EAAoBxD,CAAK,CAAC,EACnDwC,CACX,CAAC,CACL,CACJ,CAAC,EACD,MAAO,CAAE,YAAa,CAAE,GAAGlC,EAAa,QAASA,EAAY,QAAQ,IAAI,IAAW,CAAE,GAAGE,EAAQ,SAAU,SAASA,EAAO,SAAU,CAACA,EAAO,IAAI,CAAC,CAAE,EAAE,CAAE,EAAG,gBAAe,CAC9K"}
@@ -1,2 +1,2 @@
1
- import"../../_virtual/_virtual/_rolldown/runtime.js";import{DiagnosticCodes as e}from"../Diagnostics/DiagnosticCodes.js";import{dotNetWhitespace as t,nativePattern as n}from"../Text/patterns.js";import{locationOf as r}from"./SourceLine.js";import{firstWord as i}from"./LineText.js";import{generatedFixturePattern as a,generatedFixturePrefix as o,parseConcrete as s,parseConcreteMapping as c}from"./SpecificationResponseParser.js";import{caseReferences as l,parseSpecificationValue as u}from"./SpecificationCaseParser.js";import{parseDescription as d}from"./DescriptionParser.js";import{parseSpecificationStream as f,rejectSpecificationRouteChildren as p,specificationStream as m}from"./SpecificationParser.js";const h=n(`^example\\s+([A-Z]\\w*)\\s*:\\s*([A-Z]\\w*(?:\\.\\w+)*)$`.replaceAll(`\\s`,t)),g=n(`^([\\w.]+)\\s*=(?!=|>)\\s*(.+)$`.replaceAll(`\\s`,t));function parseExample(t,n){let i=h.exec(n.content);if(i===null)return t.error(e.InvalidSpecificationExample,`Invalid example declaration '${n.content}' - expected 'example <Name> : <EventOrCommandOrReadModel>'`,r(n)),t.skipOpaqueBlock(n.indent),{kind:`SpecificationExampleSyntax`,name:``,type:``,values:[],generatedValues:[],for:null,description:null,location:r(n)};let a=parseFixtureBody(t,n,void 0,!0,i[1]);for(let n of l(a))t.error(e.InvalidSpecificationCaseReference,`Case references are not permitted in example bodies.`,n.location);return{kind:`SpecificationExampleSyntax`,name:i[1],type:i[2],...a,location:r(n)}}function addInlineValue(t,n,i,a){if(i?.groups?.property===void 0)return;let o=i.groups.property,c=i.groups.value,l=n.content.length-c.length,u=r(n),d=s(t,c,{...u,column:u.column+l},e.InvalidSpecificationValue);d!==null&&a.push({kind:`PropertyMappingSyntax`,property:o,source:d,location:{...u,column:u.column+n.content.lastIndexOf(o,n.content.indexOf(`=`))}})}function addFixtureValue(t,n,r,i=[]){[...n,...i].some(e=>e.property===r.property)?t.error(e.DuplicateSpecificationAssignment,`Property '${r.property}' is assigned more than once in this fixture - assign it only once, inline or indented`,r.location):n.push(r)}function parseFixtureBody(t,n,s,l=!1,h){let _=[],v=[],y=null,b=null,x,S;addInlineValue(t,n,s,_);for(let s=t.peekChild(n.indent);s!==void 0;s=t.peekChild(n.indent)){if(t.reader.takeSignificant(),h!==void 0&&i(s.content)===`description`){b=d(t,s,b,`Example '${h}'`);continue}if(l&&o.test(s.content)){let n=c(t,s,a,e.InvalidGeneratedFixture);n!==null&&(h===void 0?v.push(n):addFixtureValue(t,v,n,_));continue}let n=g.exec(s.content);if(h!==void 0&&n===null&&(i(s.content)===`stream`||s.content.startsWith(`no stream`))){let n=m.exec(s.content);x!==void 0||S!==void 0?(t.error(e.InvalidSpecificationStream,`An event occurrence declares at most one stream or no stream directive.`,r(s)),t.skipOpaqueBlock(s.indent)):s.content===`no stream`?(S={kind:`SpecificationNoStreamSyntax`,location:r(s)},p(t,s)):n===null?(t.error(e.InvalidSpecificationStream,`Expected 'stream Source.Stream', or 'no stream' on an event example.`,r(s)),t.skipOpaqueBlock(s.indent)):x=f(t,s,n)}else if(n!==null)addFixtureValue(t,_,{kind:`PropertyMappingSyntax`,property:n[1],source:u(n[2],r(s),t),location:r(s)},v);else if(i(s.content)===`for`){let n=s.content.substring(3).trim();n.length===0?t.error(e.InvalidSpecificationEventSource,`Invalid event-source assertion 'for' - expected 'for <value>'`,r(s)):y===null?y=u(n,r(s),t):t.error(e.DuplicateSpecificationEventSource,`A specification step can declare its event-source assertion only once`,r(s))}else t.error(e.InvalidSpecificationValue,`Invalid property mapping '${s.content}' - expected '<property> = <value>'`,r(s))}return{values:_,for:y,generatedValues:v,description:b,...x===void 0?{}:{stream:x},...S===void 0?{}:{noStream:S}}}export{addFixtureValue,addInlineValue,parseExample,parseFixtureBody};
1
+ import"../../_virtual/_virtual/_rolldown/runtime.js";import{DiagnosticCodes as e}from"../Diagnostics/DiagnosticCodes.js";import{dotNetWhitespace as t,nativePattern as n}from"../Text/patterns.js";import{locationOf as r}from"./SourceLine.js";import{diagnosticText as i}from"../Diagnostics/DiagnosticArgument.js";import{firstWord as a}from"./LineText.js";import{generatedFixturePattern as o,generatedFixturePrefix as s,parseConcrete as c,parseConcreteMapping as l}from"./SpecificationResponseParser.js";import{caseReferences as u,parseSpecificationValue as d}from"./SpecificationCaseParser.js";import{parseDescription as f}from"./DescriptionParser.js";import{parseSpecificationStream as p,rejectSpecificationRouteChildren as m,specificationStream as h}from"./SpecificationParser.js";const g=n(`^example\\s+([A-Z]\\w*)\\s*:\\s*([A-Z]\\w*(?:\\.\\w+)*)$`.replaceAll(`\\s`,t)),_=n(`^([\\w.]+)\\s*=(?!=|>)\\s*(.+)$`.replaceAll(`\\s`,t));function parseExample(t,n){let a=g.exec(n.content);if(a===null)return t.error(e.InvalidSpecificationExample,`Invalid example declaration '${n.content}' - expected 'example <Name> : <EventOrCommandOrReadModel>'`,r(n),i(`text`,n.content)),t.skipOpaqueBlock(n.indent),{kind:`SpecificationExampleSyntax`,name:``,type:``,values:[],generatedValues:[],for:null,description:null,location:r(n)};let o=parseFixtureBody(t,n,void 0,!0,a[1]);for(let n of u(o))t.error(e.InvalidSpecificationCaseReference,`Case references are not permitted in example bodies.`,n.location);return{kind:`SpecificationExampleSyntax`,name:a[1],type:a[2],...o,location:r(n)}}function addInlineValue(t,n,i,a){if(i?.groups?.property===void 0)return;let o=i.groups.property,s=i.groups.value,l=n.content.length-s.length,u=r(n),d=c(t,s,{...u,column:u.column+l},e.InvalidSpecificationValue);d!==null&&a.push({kind:`PropertyMappingSyntax`,property:o,source:d,location:{...u,column:u.column+n.content.lastIndexOf(o,n.content.indexOf(`=`))}})}function addFixtureValue(t,n,r,a=[]){[...n,...a].some(e=>e.property===r.property)?t.error(e.DuplicateSpecificationAssignment,`Property '${r.property}' is assigned more than once in this fixture - assign it only once, inline or indented`,r.location,i(`property`,r.property)):n.push(r)}function parseFixtureBody(t,n,c,u=!1,g){let v=[],y=[],b=null,x=null,S,C;addInlineValue(t,n,c,v);for(let c=t.peekChild(n.indent);c!==void 0;c=t.peekChild(n.indent)){if(t.reader.takeSignificant(),g!==void 0&&a(c.content)===`description`){x=f(t,c,x,`Example '${g}'`);continue}if(u&&s.test(c.content)){let n=l(t,c,o,e.InvalidGeneratedFixture);n!==null&&(g===void 0?y.push(n):addFixtureValue(t,y,n,v));continue}let n=_.exec(c.content);if(g!==void 0&&n===null&&(a(c.content)===`stream`||c.content.startsWith(`no stream`))){let n=h.exec(c.content);S!==void 0||C!==void 0?(t.error(e.InvalidSpecificationStream,`An event occurrence declares at most one stream or no stream directive.`,r(c)),t.skipOpaqueBlock(c.indent)):c.content===`no stream`?(C={kind:`SpecificationNoStreamSyntax`,location:r(c)},m(t,c)):n===null?(t.error(e.InvalidSpecificationStream,`Expected 'stream Source.Stream', or 'no stream' on an event example.`,r(c)),t.skipOpaqueBlock(c.indent)):S=p(t,c,n)}else if(n!==null)addFixtureValue(t,v,{kind:`PropertyMappingSyntax`,property:n[1],source:d(n[2],r(c),t),location:r(c)},y);else if(a(c.content)===`for`){let n=c.content.substring(3).trim();n.length===0?t.error(e.InvalidSpecificationEventSource,`Invalid event-source assertion 'for' - expected 'for <value>'`,r(c)):b===null?b=d(n,r(c),t):t.error(e.DuplicateSpecificationEventSource,`A specification step can declare its event-source assertion only once`,r(c))}else t.error(e.InvalidSpecificationValue,`Invalid property mapping '${c.content}' - expected '<property> = <value>'`,r(c),i(`text`,c.content))}return{values:v,for:b,generatedValues:y,description:x,...S===void 0?{}:{stream:S},...C===void 0?{}:{noStream:C}}}export{addFixtureValue,addInlineValue,parseExample,parseFixtureBody};
2
2
  //# sourceMappingURL=SpecificationExampleParser.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SpecificationExampleParser.js","names":["parseMappingSource","header","nativePattern","dotNetWhitespace","mapping","match","line","context","DiagnosticCodes","locationOf","body","reference","caseReferences","property","text","offset","location","source","parseConcrete","values","other","existing","value","generatedValues","eventSource","description","stream","noStream","parent","inline","child","example","firstWord","parseDescription","allowGenerated","generatedFixturePrefix","fixture","parseConcreteMapping","generatedFixturePattern","route","specificationStream","rejectSpecificationRouteChildren","parseSpecificationStream","parseSpecificationValue"],"sources":["../../../../../../Compiler/Parsing/SpecificationExampleParser.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 { ExpressionSyntax, PropertyMappingSyntax } from '../Syntax/Expressions';\nimport { SpecificationNoStreamSyntax, SpecificationStreamSyntax, SpecificationExampleSyntax } from '../Syntax/Specifications';\nimport { dotNetWhitespace, nativePattern } from '../Text/patterns';\nimport { parseSpecificationStream, rejectSpecificationRouteChildren, specificationStream } from './SpecificationParser';\nimport { parseDescription } from './DescriptionParser';\nimport { caseReferences, parseSpecificationValue as parseMappingSource } from './SpecificationCaseParser';\nimport { firstWord } from './LineText';\nimport { ParserContext } from './ParserContext';\nimport { locationOf, SourceLine } from './SourceLine';\nimport { generatedFixturePattern, generatedFixturePrefix, parseConcrete, parseConcreteMapping } from './SpecificationResponseParser';\n\nconst header = nativePattern('^example\\\\s+([A-Z]\\\\w*)\\\\s*:\\\\s*([A-Z]\\\\w*(?:\\\\.\\\\w+)*)$'.replaceAll('\\\\s', dotNetWhitespace));\nconst mapping = nativePattern('^([\\\\w.]+)\\\\s*=(?!=|>)\\\\s*(.+)$'.replaceAll('\\\\s', dotNetWhitespace));\n\nexport function parseExample(context: ParserContext, line: SourceLine): SpecificationExampleSyntax {\n const match = header.exec(line.content);\n if (match === null) {\n context.error(DiagnosticCodes.InvalidSpecificationExample, `Invalid example declaration '${line.content}' - expected 'example <Name> : <EventOrCommandOrReadModel>'`, locationOf(line));\n context.skipOpaqueBlock(line.indent);\n return { kind: 'SpecificationExampleSyntax', name: '', type: '', values: [], generatedValues: [], for: null, description: null, location: locationOf(line) };\n }\n const body = parseFixtureBody(context, line, undefined, true, match[1]);\n for (const reference of caseReferences(body)) context.error(DiagnosticCodes.InvalidSpecificationCaseReference, 'Case references are not permitted in example bodies.', reference.location);\n return { kind: 'SpecificationExampleSyntax', name: match[1], type: match[2], ...body, location: locationOf(line) };\n}\n\nexport function addInlineValue(context: ParserContext, line: SourceLine, match: RegExpExecArray | undefined, values: PropertyMappingSyntax[]): void {\n if (match?.groups?.property === undefined) return;\n const property = match.groups.property;\n const text = match.groups.value;\n const offset = line.content.length - text.length;\n const location = locationOf(line);\n const source = parseConcrete(context, text, { ...location, column: location.column + offset }, DiagnosticCodes.InvalidSpecificationValue);\n if (source !== null) values.push({ kind: 'PropertyMappingSyntax', property, source, location: { ...location, column: location.column + line.content.lastIndexOf(property, line.content.indexOf('=')) } });\n}\n\nexport function addFixtureValue(context: ParserContext, values: PropertyMappingSyntax[], value: PropertyMappingSyntax, other: readonly PropertyMappingSyntax[] = []): void {\n if ([...values, ...other].some(existing => existing.property === value.property)) {\n context.error(DiagnosticCodes.DuplicateSpecificationAssignment, `Property '${value.property}' is assigned more than once in this fixture - assign it only once, inline or indented`, value.location);\n return;\n }\n values.push(value);\n}\n\nexport function parseFixtureBody(context: ParserContext, parent: SourceLine, inline?: RegExpExecArray, allowGenerated = false, example?: string): {\n values: PropertyMappingSyntax[]; for: ExpressionSyntax | null; generatedValues: PropertyMappingSyntax[]; description: string | null;\n stream?: SpecificationStreamSyntax; noStream?: SpecificationNoStreamSyntax;\n} {\n const values: PropertyMappingSyntax[] = [];\n const generatedValues: PropertyMappingSyntax[] = [];\n let eventSource: ExpressionSyntax | null = null;\n let description: string | null = null;\n let stream: SpecificationStreamSyntax | undefined;\n let noStream: SpecificationNoStreamSyntax | undefined;\n addInlineValue(context, parent, inline, values);\n for (let child = context.peekChild(parent.indent); child !== undefined; child = context.peekChild(parent.indent)) {\n context.reader.takeSignificant();\n if (example !== undefined && firstWord(child.content) === 'description') {\n description = parseDescription(context, child, description, `Example '${example}'`);\n continue;\n }\n if (allowGenerated && generatedFixturePrefix.test(child.content)) {\n const fixture = parseConcreteMapping(context, child, generatedFixturePattern, DiagnosticCodes.InvalidGeneratedFixture);\n if (fixture !== null) {\n // Preserve validator-owned PLAY0490 for existing generated step fixtures.\n if (example === undefined) generatedValues.push(fixture);\n else addFixtureValue(context, generatedValues, fixture, values);\n }\n continue;\n }\n const match = mapping.exec(child.content);\n if (example !== undefined && match === null && (firstWord(child.content) === 'stream' || child.content.startsWith('no stream'))) {\n const route = specificationStream.exec(child.content);\n if (stream !== undefined || noStream !== undefined) {\n context.error(DiagnosticCodes.InvalidSpecificationStream, 'An event occurrence declares at most one stream or no stream directive.', locationOf(child));\n context.skipOpaqueBlock(child.indent);\n } else if (child.content === 'no stream') {\n noStream = { kind: 'SpecificationNoStreamSyntax', location: locationOf(child) };\n rejectSpecificationRouteChildren(context, child);\n } else if (route !== null) {\n stream = parseSpecificationStream(context, child, route);\n } else {\n context.error(DiagnosticCodes.InvalidSpecificationStream, \"Expected 'stream Source.Stream', or 'no stream' on an event example.\", locationOf(child));\n context.skipOpaqueBlock(child.indent);\n }\n continue;\n }\n if (match !== null) {\n addFixtureValue(context, values, { kind: 'PropertyMappingSyntax', property: match[1], source: parseMappingSource(match[2], locationOf(child), context), location: locationOf(child) }, generatedValues);\n } else if (firstWord(child.content) === 'for') {\n const source = child.content.substring('for'.length).trim();\n if (source.length === 0) context.error(DiagnosticCodes.InvalidSpecificationEventSource, \"Invalid event-source assertion 'for' - expected 'for <value>'\", locationOf(child));\n else if (eventSource !== null) context.error(DiagnosticCodes.DuplicateSpecificationEventSource, 'A specification step can declare its event-source assertion only once', locationOf(child));\n else eventSource = parseMappingSource(source, locationOf(child), context);\n } else {\n context.error(DiagnosticCodes.InvalidSpecificationValue, `Invalid property mapping '${child.content}' - expected '<property> = <value>'`, locationOf(child));\n }\n }\n return { values, for: eventSource, generatedValues, description, ...(stream === undefined ? {} : { stream }), ...(noStream === undefined ? {} : { noStream }) };\n}\n"],"mappings":"ssBAeA,MAAMC,EAASC,EAAc,2DAA2D,WAAW,MAAOC,CAAgB,CAAC,EACrHC,EAAUF,EAAc,kCAAkC,WAAW,MAAOC,CAAgB,CAAC,EAEnG,SAAgB,aAAa,EAAwB,EAA8C,CAC/F,IAAME,EAAQJ,EAAO,KAAKK,EAAK,OAAO,EACtC,GAAID,IAAU,KAGV,OAFAE,EAAQ,MAAMC,EAAgB,4BAA6B,gCAAgCF,EAAK,QAAQ,6DAA8DG,EAAWH,CAAI,CAAC,EACtLC,EAAQ,gBAAgBD,EAAK,MAAM,EAC5B,CAAE,KAAM,6BAA8B,KAAM,GAAI,KAAM,GAAI,OAAQ,CAAC,EAAG,gBAAiB,CAAC,EAAG,IAAK,KAAM,YAAa,KAAM,SAAUG,EAAWH,CAAI,CAAE,EAE/J,IAAMI,EAAO,iBAAiBH,EAASD,EAAM,IAAA,GAAW,GAAMD,EAAM,EAAE,EACtE,IAAK,IAAMM,KAAaC,EAAeF,CAAI,EAAGH,EAAQ,MAAMC,EAAgB,kCAAmC,uDAAwDG,EAAU,QAAQ,EACzL,MAAO,CAAE,KAAM,6BAA8B,KAAMN,EAAM,GAAI,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AAMb,EAASa,EAAM,QAAQ,UAAU,CAAY,CAAC,CAAC,KAAK,EACtDb,EAAO,SAAW,EAAGV,EAAQ,MAAMC,EAAgB,gCAAiC,gEAAiEC,EAAWqB,CAAK,CAAC,EACjKN,IAAgB,KACpB,EAAcxB,EAAmBiB,EAAQR,EAAWqB,CAAK,EAAGvB,CAAO,EADzCA,EAAQ,MAAMC,EAAgB,kCAAmC,wEAAyEC,EAAWqB,CAAK,CAAC,CAE9L,MACIvB,EAAQ,MAAMC,EAAgB,0BAA2B,6BAA6BsB,EAAM,QAAQ,qCAAsCrB,EAAWqB,CAAK,CAAC,CAEnK,CACA,MAAO,CAAE,SAAQ,IAAKN,EAAa,kBAAiB,cAAa,GAAIE,IAAW,IAAA,GAAY,CAAC,EAAI,CAAE,QAAO,EAAI,GAAIC,IAAa,IAAA,GAAY,CAAC,EAAI,CAAE,UAAS,CAAG,CAClK"}
1
+ {"version":3,"file":"SpecificationExampleParser.js","names":["parseMappingSource","header","nativePattern","dotNetWhitespace","mapping","match","line","context","DiagnosticCodes","locationOf","diagnosticText","body","reference","caseReferences","property","text","offset","location","source","parseConcrete","values","other","existing","value","generatedValues","eventSource","description","stream","noStream","parent","inline","child","example","firstWord","parseDescription","allowGenerated","generatedFixturePrefix","fixture","parseConcreteMapping","generatedFixturePattern","route","specificationStream","rejectSpecificationRouteChildren","parseSpecificationStream","parseSpecificationValue"],"sources":["../../../../../../Compiler/Parsing/SpecificationExampleParser.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 { diagnosticText } from '../Diagnostics/DiagnosticArgument';\nimport { DiagnosticCodes } from '../Diagnostics/DiagnosticCodes';\nimport { ExpressionSyntax, PropertyMappingSyntax } from '../Syntax/Expressions';\nimport { SpecificationNoStreamSyntax, SpecificationStreamSyntax, SpecificationExampleSyntax } from '../Syntax/Specifications';\nimport { dotNetWhitespace, nativePattern } from '../Text/patterns';\nimport { parseSpecificationStream, rejectSpecificationRouteChildren, specificationStream } from './SpecificationParser';\nimport { parseDescription } from './DescriptionParser';\nimport { caseReferences, parseSpecificationValue as parseMappingSource } from './SpecificationCaseParser';\nimport { firstWord } from './LineText';\nimport { ParserContext } from './ParserContext';\nimport { locationOf, SourceLine } from './SourceLine';\nimport { generatedFixturePattern, generatedFixturePrefix, parseConcrete, parseConcreteMapping } from './SpecificationResponseParser';\n\nconst header = nativePattern('^example\\\\s+([A-Z]\\\\w*)\\\\s*:\\\\s*([A-Z]\\\\w*(?:\\\\.\\\\w+)*)$'.replaceAll('\\\\s', dotNetWhitespace));\nconst mapping = nativePattern('^([\\\\w.]+)\\\\s*=(?!=|>)\\\\s*(.+)$'.replaceAll('\\\\s', dotNetWhitespace));\n\nexport function parseExample(context: ParserContext, line: SourceLine): SpecificationExampleSyntax {\n const match = header.exec(line.content);\n if (match === null) {\n context.error(DiagnosticCodes.InvalidSpecificationExample, `Invalid example declaration '${line.content}' - expected 'example <Name> : <EventOrCommandOrReadModel>'`, locationOf(line), diagnosticText('text', line.content));\n context.skipOpaqueBlock(line.indent);\n return { kind: 'SpecificationExampleSyntax', name: '', type: '', values: [], generatedValues: [], for: null, description: null, location: locationOf(line) };\n }\n const body = parseFixtureBody(context, line, undefined, true, match[1]);\n for (const reference of caseReferences(body)) context.error(DiagnosticCodes.InvalidSpecificationCaseReference, 'Case references are not permitted in example bodies.', reference.location);\n return { kind: 'SpecificationExampleSyntax', name: match[1], type: match[2], ...body, location: locationOf(line) };\n}\n\nexport function addInlineValue(context: ParserContext, line: SourceLine, match: RegExpExecArray | undefined, values: PropertyMappingSyntax[]): void {\n if (match?.groups?.property === undefined) return;\n const property = match.groups.property;\n const text = match.groups.value;\n const offset = line.content.length - text.length;\n const location = locationOf(line);\n const source = parseConcrete(context, text, { ...location, column: location.column + offset }, DiagnosticCodes.InvalidSpecificationValue);\n if (source !== null) values.push({ kind: 'PropertyMappingSyntax', property, source, location: { ...location, column: location.column + line.content.lastIndexOf(property, line.content.indexOf('=')) } });\n}\n\nexport function addFixtureValue(context: ParserContext, values: PropertyMappingSyntax[], value: PropertyMappingSyntax, other: readonly PropertyMappingSyntax[] = []): void {\n if ([...values, ...other].some(existing => existing.property === value.property)) {\n context.error(DiagnosticCodes.DuplicateSpecificationAssignment, `Property '${value.property}' is assigned more than once in this fixture - assign it only once, inline or indented`, value.location, diagnosticText('property', value.property));\n return;\n }\n values.push(value);\n}\n\nexport function parseFixtureBody(context: ParserContext, parent: SourceLine, inline?: RegExpExecArray, allowGenerated = false, example?: string): {\n values: PropertyMappingSyntax[]; for: ExpressionSyntax | null; generatedValues: PropertyMappingSyntax[]; description: string | null;\n stream?: SpecificationStreamSyntax; noStream?: SpecificationNoStreamSyntax;\n} {\n const values: PropertyMappingSyntax[] = [];\n const generatedValues: PropertyMappingSyntax[] = [];\n let eventSource: ExpressionSyntax | null = null;\n let description: string | null = null;\n let stream: SpecificationStreamSyntax | undefined;\n let noStream: SpecificationNoStreamSyntax | undefined;\n addInlineValue(context, parent, inline, values);\n for (let child = context.peekChild(parent.indent); child !== undefined; child = context.peekChild(parent.indent)) {\n context.reader.takeSignificant();\n if (example !== undefined && firstWord(child.content) === 'description') {\n description = parseDescription(context, child, description, `Example '${example}'`);\n continue;\n }\n if (allowGenerated && generatedFixturePrefix.test(child.content)) {\n const fixture = parseConcreteMapping(context, child, generatedFixturePattern, DiagnosticCodes.InvalidGeneratedFixture);\n if (fixture !== null) {\n // Preserve validator-owned PLAY0490 for existing generated step fixtures.\n if (example === undefined) generatedValues.push(fixture);\n else addFixtureValue(context, generatedValues, fixture, values);\n }\n continue;\n }\n const match = mapping.exec(child.content);\n if (example !== undefined && match === null && (firstWord(child.content) === 'stream' || child.content.startsWith('no stream'))) {\n const route = specificationStream.exec(child.content);\n if (stream !== undefined || noStream !== undefined) {\n context.error(DiagnosticCodes.InvalidSpecificationStream, 'An event occurrence declares at most one stream or no stream directive.', locationOf(child));\n context.skipOpaqueBlock(child.indent);\n } else if (child.content === 'no stream') {\n noStream = { kind: 'SpecificationNoStreamSyntax', location: locationOf(child) };\n rejectSpecificationRouteChildren(context, child);\n } else if (route !== null) {\n stream = parseSpecificationStream(context, child, route);\n } else {\n context.error(DiagnosticCodes.InvalidSpecificationStream, \"Expected 'stream Source.Stream', or 'no stream' on an event example.\", locationOf(child));\n context.skipOpaqueBlock(child.indent);\n }\n continue;\n }\n if (match !== null) {\n addFixtureValue(context, values, { kind: 'PropertyMappingSyntax', property: match[1], source: parseMappingSource(match[2], locationOf(child), context), location: locationOf(child) }, generatedValues);\n } else if (firstWord(child.content) === 'for') {\n const source = child.content.substring('for'.length).trim();\n if (source.length === 0) context.error(DiagnosticCodes.InvalidSpecificationEventSource, \"Invalid event-source assertion 'for' - expected 'for <value>'\", locationOf(child));\n else if (eventSource !== null) context.error(DiagnosticCodes.DuplicateSpecificationEventSource, 'A specification step can declare its event-source assertion only once', locationOf(child));\n else eventSource = parseMappingSource(source, locationOf(child), context);\n } else {\n context.error(DiagnosticCodes.InvalidSpecificationValue, `Invalid property mapping '${child.content}' - expected '<property> = <value>'`, locationOf(child), diagnosticText('text', child.content));\n }\n }\n return { values, for: eventSource, generatedValues, description, ...(stream === undefined ? {} : { stream }), ...(noStream === undefined ? {} : { noStream }) };\n}\n"],"mappings":"4wBAgBA,MAAMC,EAASC,EAAc,2DAA2D,WAAW,MAAOC,CAAgB,CAAC,EACrHC,EAAUF,EAAc,kCAAkC,WAAW,MAAOC,CAAgB,CAAC,EAEnG,SAAgB,aAAa,EAAwB,EAA8C,CAC/F,IAAME,EAAQJ,EAAO,KAAKK,EAAK,OAAO,EACtC,GAAID,IAAU,KAGV,OAFAE,EAAQ,MAAMC,EAAgB,4BAA6B,gCAAgCF,EAAK,QAAQ,6DAA8DG,EAAWH,CAAI,EAAGI,EAAe,OAAQJ,EAAK,OAAO,CAAC,EAC5NC,EAAQ,gBAAgBD,EAAK,MAAM,EAC5B,CAAE,KAAM,6BAA8B,KAAM,GAAI,KAAM,G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