@cratis/screenplay-language 4.193.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 (30) hide show
  1. package/dist/bundles/compiler/Diagnostics/DiagnosticArgument.js +2 -0
  2. package/dist/bundles/compiler/Diagnostics/DiagnosticArgument.js.map +1 -0
  3. package/dist/bundles/compiler/Parsing/CaptureParser.js +1 -1
  4. package/dist/bundles/compiler/Parsing/CaptureParser.js.map +1 -1
  5. package/dist/bundles/compiler/Parsing/ParserContext.js +1 -1
  6. package/dist/bundles/compiler/Parsing/ParserContext.js.map +1 -1
  7. package/dist/bundles/compiler/Parsing/ProducesParser.js +1 -1
  8. package/dist/bundles/compiler/Parsing/ProducesParser.js.map +1 -1
  9. package/dist/bundles/compiler/Parsing/ProjectionParser.js +1 -1
  10. package/dist/bundles/compiler/Parsing/ProjectionParser.js.map +1 -1
  11. package/dist/bundles/compiler/Parsing/ProjectionTargetValidator.js +1 -1
  12. package/dist/bundles/compiler/Parsing/ProjectionTargetValidator.js.map +1 -1
  13. package/dist/bundles/compiler/Parsing/ReactionParser.js +1 -1
  14. package/dist/bundles/compiler/Parsing/ReactionParser.js.map +1 -1
  15. package/dist/bundles/compiler/Parsing/SpecificationCaseParser.js +1 -1
  16. package/dist/bundles/compiler/Parsing/SpecificationCaseParser.js.map +1 -1
  17. package/dist/bundles/compiler/Parsing/SpecificationCaseValidator.js +1 -1
  18. package/dist/bundles/compiler/Parsing/SpecificationCaseValidator.js.map +1 -1
  19. package/dist/bundles/compiler/Parsing/SpecificationCommandExamples.js +1 -1
  20. package/dist/bundles/compiler/Parsing/SpecificationCommandExamples.js.map +1 -1
  21. package/dist/bundles/compiler/Parsing/SpecificationExampleParser.js +1 -1
  22. package/dist/bundles/compiler/Parsing/SpecificationExampleParser.js.map +1 -1
  23. package/dist/bundles/compiler/Parsing/SpecificationParser.js +1 -1
  24. package/dist/bundles/compiler/Parsing/SpecificationParser.js.map +1 -1
  25. package/dist/bundles/compiler/Parsing/SpecificationResponseParser.js +1 -1
  26. package/dist/bundles/compiler/Parsing/SpecificationResponseParser.js.map +1 -1
  27. package/dist/bundles/compiler/Parsing/SpecificationStreamValidator.js +1 -1
  28. package/dist/bundles/compiler/Parsing/SpecificationStreamValidator.js.map +1 -1
  29. package/dist/bundles/compiler/index.js +1 -1
  30. package/package.json +1 -1
@@ -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,IAAM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AAM,SAAU,WAAY,GAAO,aAAc,GAAO,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,OA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AAC,EAAA,CAAG,KAAK,GAAY6D,EAAS,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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,KAAK,GAAGQ,EAAI,OAAQ,WAAY,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,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AAQlB,EAAK,OAAO,IAAI,GAASP,EAAM,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,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,EAAM,OAAO,IAAM,MAAO,CAC3C,IAAMb,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,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EAAQ,MAAMC,EAAgB,2BAA4B,uEAAwEC,EAAWsB,CAAK,CAAC,EACnJxB,EAAQ,gBAAgBwB,EAAM,MAAM,GAHpC,EAASY,EAAyBpC,EAASwB,EAAOS,CAAK,CAM/D,MACA,GAAInC,IAAU,KACV,gBAAgBE,EAASa,EAAQ,CAAE,KAAM,wBAAyB,SAAUf,EAAM,GAAI,OAAQL,EAAmBK,EAAM,GAAII,EAAWsB,CAAK,EAAGxB,CAAO,EAAG,SAAUE,EAAWsB,CAAK,CAAE,EAAGP,CAAe,OACnM,GAAIS,EAAUF,EAAM,OAAO,IAAM,MAAO,CAC3C,IAAMb,EAASa,EAAM,QAAQ,UAAU,CAAY,CAAC,CAAC,KAAK,EACtDb,EAAO,SAAW,EAAGX,EAAQ,MAAMC,EAAgB,gCAAiC,gEAAiEC,EAAWsB,CAAK,CAAC,EACjKN,IAAgB,KACpB,EAAczB,EAAmBkB,EAAQT,EAAWsB,CAAK,EAAGxB,CAAO,EADzCA,EAAQ,MAAMC,EAAgB,kCAAmC,wEAAyEC,EAAWsB,CAAK,CAAC,CAE9L,MACIxB,EAAQ,MAAMC,EAAgB,0BAA2B,6BAA6BuB,EAAM,QAAQ,qCAAsCtB,EAAWsB,CAAK,EAAGrB,EAAe,OAAQqB,EAAM,OAAO,CAAC,CAE1M,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,2 +1,2 @@
1
- import"../../_virtual/_virtual/_rolldown/runtime.js";import{DiagnosticCodes as e}from"../Diagnostics/DiagnosticCodes.js";import{stringBodyPattern as t,unescapeString as n}from"../Text/StringLiteral.js";import{dotNetWhitespace as r,nativePattern as i,pattern as a}from"../Text/patterns.js";import{locationOf as o}from"./SourceLine.js";import{firstWord as s}from"./LineText.js";import{generatedFixturePattern as c,generatedFixturePrefix as l,parseConcreteMapping as u,parseReturn as d,thenReturnsPrefix as f}from"./SpecificationResponseParser.js";import{containsCaseReference as p,parseCase as m,parseParameter as h,parseSpecificationValue as g,validateTable as ee}from"./SpecificationCaseParser.js";import{parseDescription as te}from"./DescriptionParser.js";import{sourceStreamPattern as _}from"../Text/SourceStreamNames.js";import{parseRouteParts as v}from"./EventSourceParser.js";import{isFileDirective as y}from"./FileReferences.js";import{rejectOperationChildren as ne}from"./OperationParser.js";import{addFixtureValue as b,addInlineValue as x}from"./SpecificationExampleParser.js";const S=a(`^(?:given\\s+operation|then\\s+(?:operation|compensated))(?:\\s|$)`),C=a(`^(given operation|then operation|then compensated)\\s+([A-Za-z_]\\w*(?:\\.[A-Za-z_]\\w*)*)(\\s+fails)?$`),w=a(`^specification\\s+([A-Za-z_]\\w*)$`),T=a(`^given caller as ([A-Za-z_]\\w*)$`),stepPattern=(e,t=``)=>i(`^${e}\\s+([A-Z]\\w*(?:\\.\\w+)*)${t}(?:\\s+(?<property>[\\w.]+)\\s*=(?!=|>)\\s*(?<value>.+))?$`.replaceAll(`\\s`,r)),E=stepPattern(`given`),D=stepPattern(`when\\s+append`),O=stepPattern(`when`),k=stepPattern(`then`),A=a(`^then\\s+query\\b`),j=a(`^(?:given|then)\\s+readmodel\\b`),M=stepPattern(`given\\s+readmodel`),N=stepPattern(`then\\s+readmodel`,`(?<exactly>\\s+exactly)?`),P=a(`^then\\s+no\\b`),F=a(`^then\\s+error\\s+"(${t})"$`),I=a(`^([\\w.]+)\\s*=(?!=|>)\\s*(.+)$`),L=i(`^([\\w.]+)\\s*=(?!=|>)\\s*(.+)$`),re=a(`^given\\s+clock\\b`),R=a(`^given\\s+capture\\b`),z=a(`^when\\s+clock\\b`),B=a(`^when\\s+trigger\\b`),V=a(`^when\\s+capture\\b`),H=a(`^when\\s+query\\b`),U=a(`^then\\s+result\\b`),W=a(`^then\\s+no\\s+result\\b`),G=i(`^when\\s+redelivered\\b`),K=i(`^when\\s+redelivered\\s+([A-Za-z_]\\w*(?:\\.\\w+)*)\\s+to\\s+([A-Za-z_]\\w*(?:\\.\\w+)*)$`),q=a(`^then\\s+no\\s+events\\b`),J=a(`^(given|when)\\s+clock\\s+"(\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(?::\\d{2}(?:\\.\\d+)?)?(?:Z|[+-]\\d{2}:\\d{2}))"$`),Y=a(`^when\\s+trigger\\s+([A-Za-z_]\\w*)$`),X=a(`^(?:given|when)\\s+capture\\s+([A-Za-z_]\\w*)$`),ie=a(`^when\\s+query\\s+([A-Za-z_]\\w*(?:\\.\\w+)*)$`),ae=a(`^then\\s+result(\\s+exactly)?$`),Z=i(`^then\\s+no\\s+readmodel\\s+([A-Z]\\w*)\\s+for\\s+(.+)$`),oe=i(`^(?:"${t}"|'(?:[^'\\\\]|\\\\.)*')$`),se=i(`^then\\s+query\\s+([A-Za-z_]\\w*(?:\\.\\w+)*)(\\s+exactly)?$`);function parseSpecification(t,n){let r=w.exec(n.content)?.[1]??``;r===``&&t.error(e.InvalidSpecificationDeclaration,`Invalid specification declaration '${n.content}' - expected 'specification <Name>'`,o(n));let i=null,a=[],c=[],l={givenOperationFailures:[],thenOperations:[],thenCompensated:[],thenAbsentReadModels:[],thenQueries:[],given:[],givenReadModels:[],when:null,whenAppended:null,whenRedelivered:null,whenDeclared:!1,thenEvents:[],thenEventsInAnyOrder:!1,thenNoEvents:!1,thenReadModels:[],thenErrors:[],givenClock:null,givenCaptures:[],whenClock:null,whenTrigger:null,whenCapture:null,whenQuery:null,thenResults:[],thenNoResult:null,thenDenied:null,givenCaller:null,thenReturns:null};for(let u=t.peekChild(n.indent);u!==void 0;u=t.peekChild(n.indent)){if(t.reader.takeSignificant(),y(u)||parseOperationStep(t,u,l))continue;let n=P.test(u.content)?`then`:s(u.content);if(n===`parameter`){let e=h(t,u);e!==null&&a.push(e)}else if(n===`case`){let e=m(t,u);e!==null&&c.push(e)}else n===`description`?i=te(t,u,i,`Specification '${r}'`):n===`given`?parseGiven(t,u,l):n===`when`?parseWhen(t,u,l,r):n===`then`?parseThen(t,u,l):(t.error(e.UnknownSpecificationDirective,`Unexpected '${s(u.content)}' in specification body`,o(u)),t.skipBlock(u.indent))}l.noEventsLine!==void 0&&(l.thenEvents.length>0||l.thenEventsInAnyOrder||l.thenErrors.length>0||l.thenDenied!==null)&&t.error(e.InvalidNoEventsExpectation,`'then no events' cannot accompany event, event-order, error or denial expectations.`,o(l.noEventsLine)),validateQueryRejection(t,n,l);let{whenDeclared:u,noEventsLine:d,...f}=l,p={kind:`SpecificationSyntax`,sourceOptions:t.sourceOptions,name:r,description:i,...f,...a.length===0?{}:{parameters:a},...c.length===0?{}:{cases:c},location:o(n)};return ee(p,t),p}function validateQueryRejection(t,n,r){isQueryRejectionCandidate(r)&&!isWellFormedQueryRejection(r)&&t.error(e.MismatchedSpecificationQueryResult,`A query rejection requires exactly one query and one 'then error', no action, and no other outcomes`,o(n))}function isQueryRejectionCandidate(e){return e.thenErrors.length>0&&queriedCallCount(e)>0&&(e.whenQuery!==null||!hasAction(e))}function isWellFormedQueryRejection(e){return!hasAction(e)&&hasOneQueryAndOneError(e)&&!hasOtherOutcome(e)}function hasOneQueryAndOneError(e){return queriedCallCount(e)===1&&e.thenErrors.length===1}function hasAction(e){return[e.when,e.whenAppended,e.whenClock,e.whenTrigger,e.whenCapture,e.whenRedelivered].some(e=>e!==null)}function queriedCallCount(e){return e.thenQueries.length+(e.whenQuery===null?0:1)}function hasOtherOutcome(e){return[e.thenResults.length>0,e.thenNoResult!==null,e.thenDenied!==null,e.thenEvents.length>0,e.thenNoEvents,e.thenEventsInAnyOrder,e.thenReadModels.length>0,e.thenAbsentReadModels.length>0,e.thenReturns!==null,e.thenQueries.some(e=>e.results.length>0)].some(e=>e)}function parseOperationStep(t,n,r){if(!S.test(n.content))return!1;let i=C.exec(n.content);if(i===null||i[1]===`given operation`!=(i[3]!==void 0))t.error(e.InvalidOperationSpecification,`Expected 'given operation <Name> fails', 'then operation <Name>' or 'then compensated <Name>'.`,o(n)),skipBody(t,n.indent);else if(i[1]===`then operation`){let a=[];for(let r=t.peekChild(n.indent);r!==void 0;r=t.peekChild(n.indent)){t.reader.takeSignificant();let n=u(t,r,I,e.InvalidOperationSpecification);n!==null&&a.push(n)}r.thenOperations.push({kind:`SpecificationOperationSyntax`,operation:i[2],values:a,location:o(n)})}else ne(t,n,e.InvalidOperationSpecification,`Failure and compensation assertions cannot have children.`),i[1]===`given operation`?r.givenOperationFailures.push({kind:`SpecificationOperationFailureSyntax`,operation:i[2],location:o(n)}):r.thenCompensated.push({kind:`SpecificationCompensatedSyntax`,operation:i[2],location:o(n)});return!0}function parseGiven(t,n,r){if(re.test(n.content))r.givenClock===null?r.givenClock=parseClock(t,n,`given`):(t.error(e.InvalidSpecificationClock,`A specification states its clock at most once.`,o(n)),skipBody(t,n.indent));else if(R.test(n.content)){let e=parseCapture(t,n,`given`);e!==null&&r.givenCaptures.push(e)}else if(n.content.startsWith(`given caller`)){if(r.givenCaller!==null||r.givenCallerPersona!==void 0)t.error(e.DuplicateSpecificationCallerOrDenied,`A specification has at most one 'given caller' block.`,o(n)),t.skipBlock(n.indent);else if(n.content.startsWith(`given caller as`)){let i=T.exec(n.content);i===null&&t.error(e.InvalidSpecificationCallerPersona,`Expected 'given caller as <Persona>'.`,o(n));let a=t.peekChild(n.indent);a!==void 0&&t.error(e.InvalidSpecificationCallerPersona,`'given caller as <Persona>' has no body; use an explicit 'given caller' for refinements.`,o(a)),skipBody(t,n.indent),i!==null&&(r.givenCallerPersona={kind:`SpecificationCallerPersonaSyntax`,name:i[1],location:o(n)})}else r.givenCaller=parseCaller(t,n)}else if(j.test(n.content)){let e=parseReadModelStep(t,n,M,`given`);e!==void 0&&r.givenReadModels.push(e)}else{let e=parseEventStep(t,n,E,`given`);e!==void 0&&r.given.push(e)}}const Q=a(`^role${r}+"(${t})"$`),ce=a(`^claim${r}+"(${t})"${r}*=${r}*"(${t})"$`);function parseCaller(t,r){if(r.content!==`given caller`)return t.error(e.InvalidSpecificationCaller,`Expected exactly 'given caller'.`,o(r)),t.skipBlock(r.indent),null;let i=!1,a=[],s=[];for(let c=t.peekChild(r.indent);c!==void 0;c=t.peekChild(r.indent)){t.reader.takeSignificant();let r=Q.exec(c.content),l=ce.exec(c.content);c.content===`authenticated`&&!i?i=!0:r===null?l===null?t.error(p(c.content)?e.InvalidSpecificationCaseReference:e.InvalidSpecificationCaller,`Invalid caller fixture '${c.content}' - expected authenticated, role "...", or claim "..." = "...".`,o(c)):s.push({kind:`SpecificationCallerClaimSyntax`,type:n(l[1]),value:n(l[2]),location:o(c)}):a.push(n(r[1]))}return{kind:`SpecificationCallerSyntax`,authenticated:i,roles:a,claims:s,location:o(r)}}function parseWhen(t,n,r,i){let a=n.content.startsWith(`when append`);if(r.whenDeclared){let s=r.whenAppended!==null||a?e.ConflictingSpecificationActions:e.DuplicateSpecificationWhen;t.error(s,`Specification '${i}' already declares a 'when' - a specification can have at most one`,o(n)),skipBody(t,n.indent);return}if(r.whenDeclared=!0,a){r.whenAppended=parseEventStep(t,n,D,`when append`)??null;return}if(G.test(n.content)){let i=K.exec(n.content);i===null?(t.error(e.UnmatchedRedeliveredOccurrence,`Expected 'when redelivered <Event> to <Reaction>'.`,o(n)),skipBody(t,n.indent)):r.whenRedelivered={kind:`SpecificationRedeliverySyntax`,eventType:i[1],reaction:i[2],...parseValuesWithEventSource(t,n,void 0,void 0,`when redelivered`),location:o(n)};return}if(z.test(n.content)){r.whenClock=parseClock(t,n,`when`);return}if(B.test(n.content)){r.whenTrigger=parseNamedStep(t,n,Y,e.InvalidSpecificationTrigger,`when trigger`,`when trigger <Trigger>`,(e,t)=>({kind:`SpecificationTriggerSyntax`,trigger:e,values:t,location:o(n)}));return}if(V.test(n.content)){r.whenCapture=parseCapture(t,n,`when`);return}if(H.test(n.content)){r.whenQuery=parseNamedStep(t,n,ie,e.InvalidSpecificationQueryAction,`when query`,`when query <Query>`,(e,t)=>({kind:`SpecificationWhenQuerySyntax`,query:e,arguments:t,location:o(n)}),!0);return}let s=O.exec(n.content);if(s===null){t.error(e.InvalidSpecificationWhen,`Invalid 'when' declaration '${n.content}' - expected 'when <CommandType>' or 'when append <EventType>'`,o(n)),skipBody(t,n.indent);return}let c=[],l=parseValuesWithEventSource(t,n,c,s);r.when={kind:`SpecificationCommandSyntax`,commandType:s[1],...l,generatedValues:c,inlineProperty:s.groups?.property??null,location:o(n)}}function parseThen(t,r,i){if(q.test(r.content)){r.content!==`then no events`||i.thenNoEvents?t.error(e.InvalidNoEventsExpectation,`Expected one 'then no events' directive.`,o(r)):(i.thenNoEvents=!0,i.noEventsLine=r);let n=t.peekChild(r.indent);n!==void 0&&t.error(e.InvalidNoEventsExpectation,`'then no events' cannot have child mappings.`,o(n)),skipBody(t,r.indent);return}if(f.test(r.content)){let n=d(t,r);i.thenReturns===null?i.thenReturns=n:t.error(e.InvalidReturnExpectation,`A specification declares at most one return expectation.`,o(r));return}if(r.content.startsWith(`then events`)){r.content!==`then events in any order`||i.thenEventsInAnyOrder?t.error(e.InvalidSpecificationEventOrder,`Expected one 'then events in any order' directive.`,o(r)):i.thenEventsInAnyOrder=!0,skipBody(t,r.indent);return}if(U.test(r.content)){parseResult(t,r,i);return}if(W.test(r.content)){r.content!==`then no result`||i.thenNoResult!==null?t.error(e.InvalidSpecificationQueryAction,`Expected one 'then no result' directive.`,o(r)):i.thenNoResult={kind:`SpecificationNoResultSyntax`,location:o(r)},skipBody(t,r.indent);return}if(r.content.startsWith(`then denied`)){r.content===`then denied`?i.thenDenied===null?i.thenDenied={kind:`SpecificationDeniedSyntax`,location:o(r)}:t.error(e.DuplicateSpecificationCallerOrDenied,`A specification has at most one 'then denied' outcome.`,o(r)):(t.error(e.InvalidSpecificationDenied,`Expected exactly 'then denied'.`,o(r)),skipBody(t,r.indent));return}if(r.content===`then error`){i.thenErrors.push({kind:`SpecificationErrorSyntax`,name:null,location:o(r)});return}if(r.content.startsWith(`then error case.`)){let e=g(r.content.substring(11),{...o(r),column:o(r).column+11},t);e.kind===`CaseValueExpressionSyntax`&&i.thenErrors.push({kind:`SpecificationErrorSyntax`,name:null,caseValue:e,location:o(r)});return}let a=F.exec(r.content);if(a!==null){i.thenErrors.push({kind:`SpecificationErrorSyntax`,name:n(a[1]),location:o(r)});return}if(s(r.content.substring(4).trim())===`error`){t.error(e.InvalidThenError,`Invalid 'then error' declaration '${r.content}' - expected 'then error' or 'then error "<reason>"'`,o(r)),skipBody(t,r.indent);return}if(P.test(r.content)){if(t.sourceOptions.numericMode===`exact`){let e=parseAbsentReadModel(t,r);e!==null&&i.thenAbsentReadModels.push(e);return}let e=Z.exec(r.content);if(e!==null&&!e[2].endsWith(` exactly`)){let n=g(e[2].trim(),o(r),t.valueContext);(n.kind===`LiteralExpressionSyntax`||n.kind===`ObjectExpressionSyntax`||n.kind===`CaseValueExpressionSyntax`)&&i.thenAbsentReadModels.push({kind:`SpecificationAbsentReadModelSyntax`,name:e[1],key:n,location:o(r)})}t.skipOpaqueBlock(r.indent);return}if(A.test(r.content)){let n=t.sourceOptions.numericMode===`exact`,reject=(e,r,i)=>{if(!n)return t.skipOpaqueBlock(i.indent);t.error(e,r,o(i)),t.skipBlock(i.indent)},a=se.exec(r.content);if(a===null)return reject(e.InvalidSpecificationQuery,`Invalid 'then query' declaration '${r.content}' - expected 'then query <Query> [exactly]'`,r);let c=[],l=[],u=!1;for(let n=t.peekChild(r.indent);n!==void 0;n=t.peekChild(r.indent))t.reader.takeSignificant(),n.content===`arguments`&&!u?c.push(...parseValues(t.valueContext,n,!0,void 0,t)):n.content===`arguments`?reject(e.DuplicateSpecificationQueryArguments,`Query assertion '${a[1]}' already declares arguments`,n):n.content===`result`?l.push({kind:`SpecificationQueryResultSyntax`,properties:parseValues(t.valueContext,n,!0),exactly:!1,location:o(n)}):reject(e.UnknownSpecificationQueryDirective,`Unexpected '${s(n.content)}' in 'then query' body - expected arguments or result`,n),u||=n.content===`arguments`;i.thenQueries.push({kind:`SpecificationQuerySyntax`,query:a[1],arguments:c,results:l,exactly:a[2]!==void 0,location:o(r)});return}if(j.test(r.content)){let e=parseReadModelStep(t,r,N,`then`);e!==void 0&&i.thenReadModels.push(e);return}let c=parseEventStep(t,r,k,`then`);c!==void 0&&i.thenEvents.push(c)}function parseAbsentReadModel(t,n){let r=Z.exec(n.content);if(r===null||r[2].endsWith(` exactly`))return t.error(e.InvalidAbsentReadModelStep,`Invalid absence assertion '${n.content}' - expected 'then no readmodel <ReadModelType> for <key>'`,o(n)),skipBody(t,n.indent),null;let i=r[2].trim(),a=!(i.startsWith(`"`)||i.startsWith(`'`))||oe.test(i)?g(i,o(n),t.valueContext):null,s=a!==null&&(a.kind===`LiteralExpressionSyntax`||a.kind===`ObjectExpressionSyntax`||a.kind===`CaseValueExpressionSyntax`);s||t.error(e.InvalidAbsentReadModelStep,`Invalid absence key '${i}' - expected exactly one concrete value.`,o(n));let c=!1;for(let r=t.peekChild(n.indent);r!==void 0;r=t.peekChild(n.indent))t.reader.takeSignificant(),t.error(e.InvalidAbsentReadModelStep,`An absent read model assertion cannot have child mappings.`,o(r)),c=!0;return c||!s?null:{kind:`SpecificationAbsentReadModelSyntax`,name:r[1],key:a,location:o(n)}}function skipBody(e,t){if(e.sourceOptions.numericMode!==`exact`)return e.skipBlock(t);e.skipOpaqueBlock(t)}function parseClock(t,n,r){let i=J.exec(n.content);return skipBody(t,n.indent),i===null||i[1]!==r?(t.error(p(n.content)?e.InvalidSpecificationCaseReference:e.InvalidSpecificationClock,`Invalid '${r} clock' - expected '${r} clock "<ISO 8601 instant>"', such as '${r} clock "2026-10-05T08:00:00Z"'`,o(n)),null):{kind:`SpecificationClockSyntax`,instant:i[2],location:o(n)}}function parseCapture(t,n,r){return parseNamedStep(t,n,X,e.InvalidSpecificationCapture,`${r} capture`,`${r} capture <Capture>`,(e,t)=>({kind:`SpecificationCaptureSyntax`,capture:e,record:t,location:o(n)}))}function parseNamedStep(e,t,n,r,i,a,s,c=!1){let l=n.exec(t.content);return l===null?(e.error(r,`Invalid '${i}' declaration '${t.content}' - expected '${a}'`,o(t)),skipBody(e,t.indent),null):s(l[1],parseValues(e,t,!1,void 0,c?e:void 0))}function parseResult(t,n,r){let i=ae.exec(n.content);i===null?(t.error(e.InvalidSpecificationQueryAction,`Invalid 'then result' declaration '${n.content}' - expected 'then result [exactly]'`,o(n)),skipBody(t,n.indent)):r.thenResults.push({kind:`SpecificationQueryResultSyntax`,properties:parseValues(t,n),exactly:i[1]!==void 0,location:o(n)})}function parseReadModelStep(t,n,r,i){let a=r.exec(n.content);if(a===null)t.error(e.InvalidReadModelStep,`Invalid '${i} readmodel' declaration '${n.content}' - expected '${i} readmodel <ReadModelType>'`,o(n)),skipBody(t,n.indent);else return{kind:`SpecificationReadModelSyntax`,name:a[1],properties:parseValues(t,n,!1,a),exactly:i===`then`&&a.groups?.exactly!==void 0,inlineProperty:a.groups?.property??null,location:o(n)}}function parseEventStep(t,n,r,i){let a=r.exec(n.content);if(a===null)t.error(e.InvalidEventStep,`Invalid '${i}' declaration '${n.content}' - expected '${i} <EventType>'`,o(n)),skipBody(t,n.indent);else return{kind:`SpecificationEventSyntax`,eventType:a[1],...parseValuesWithEventSource(t,n,void 0,a,i),inlineProperty:a.groups?.property??null,location:o(n)}}const $=_(`^stream\\s+([A-Za-z_]\\w*)\\.([A-Za-z_]\\w*)$`),le=a(`^streamId\\s*=(?!=|>)\\s*(.+)$`);function parseValuesWithEventSource(t,n,r,i,a){let d=[];x(t,n,i,d);let f=null,p,m,h=!1;for(let i=t.peekChild(n.indent);i!==void 0;i=t.peekChild(n.indent)){if(t.reader.takeSignificant(),r!==void 0&&l.test(i.content)){let n=u(t,i,c,e.InvalidGeneratedFixture);n!==null&&r.push(n);continue}let n=I.exec(i.content);if(n!==null)b(t,d,mappingOf(t,i,n));else if(s(i.content)===`stream`||i.content.startsWith(`no stream`)){if(a===void 0){t.error(e.SpecificationStreamOnCommand,`A command occurrence cannot declare a route; assert it on a then event.`,o(i)),t.skipBlock(i.indent);continue}if(h){t.error(e.InvalidSpecificationStream,`An event occurrence declares at most one stream or no stream directive.`,o(i)),t.skipBlock(i.indent);continue}let n=$.exec(i.content);i.content===`no stream`&&(a===`then`||a===`when redelivered`)?(m={kind:`SpecificationNoStreamSyntax`,location:o(i)},h=!0,rejectSpecificationRouteChildren(t,i)):n===null?(t.error(e.InvalidSpecificationStream,`Expected 'stream Source.Stream', or 'no stream' on a then event.`,o(i)),t.skipBlock(i.indent)):(p=parseSpecificationStream(t,i,n),h=!0)}else if(s(i.content)===`for`){let n=i.content.substring(3).trim();n.length===0?t.error(e.InvalidSpecificationEventSource,`Invalid event-source assertion 'for' - expected 'for <value>'`,o(i)):f===null?f=g(n,o(i),t):t.error(e.DuplicateSpecificationEventSource,`A specification step can declare its event-source assertion only once`,o(i))}else t.error(e.InvalidSpecificationValue,`Invalid property mapping '${i.content}' - expected '<property> = <value>'`,o(i))}return{values:d,for:f,...p===void 0?{}:{stream:p},...m===void 0?{}:{noStream:m}}}function parseSpecificationStream(t,n,r){let i=null,a=[],s=!1,c={};for(let r=t.peekChild(n.indent);r!==void 0;r=t.peekChild(n.indent)){if(t.reader.takeSignificant(),r.content===`streamId`){i!==null||s?(t.error(e.InvalidSpecificationStream,`Declare either one 'streamId = <literal>' mapping or one streamId part block.`,o(r)),t.skipBlock(r.indent)):(s=!0,c.streamId=o(r),a=v(t,r,e.InvalidSpecificationStream).map(e=>e.source.kind===`PathExpressionSyntax`&&e.source.path.startsWith(`case.`)?{...e,source:g(e.source.path,e.source.location,t)}:e));continue}let n=le.exec(r.content);if(n===null||i!==null||s){t.error(e.InvalidSpecificationStream,`Declare either one 'streamId = <literal>' mapping or one streamId part block.`,o(r)),t.skipBlock(r.indent);continue}let l={...o(r),column:r.indent+1+r.content.indexOf(n[1],r.content.indexOf(`=`)+1)};i={kind:`PropertyMappingSyntax`,property:`streamId`,source:g(n[1],l,t),location:o(r)},rejectSpecificationRouteChildren(t,r)}return{kind:`SpecificationStreamSyntax`,eventSource:r[1],stream:r[2],streamId:i,streamIdParts:a,directiveLocations:c,referenceLocation:{...o(n),column:n.indent+1+n.content.indexOf(r[1],6)},referenceLength:r[1].length+1+r[2].length,location:o(n)}}function rejectSpecificationRouteChildren(t,n){let r=t.peekChild(n.indent);r!==void 0&&(t.error(e.InvalidSpecificationStream,`This directive cannot have children.`,o(r)),t.skipBlock(n.indent))}function parseValues(t,n,r=!1,i,a){let s=[];x(t,n,i,s);for(let i=t.peekChild(n.indent);i!==void 0;i=t.peekChild(n.indent)){t.reader.takeSignificant();let n=(r||t.sourceOptions.numericMode===`exact`?L:I).exec(i.content);if(n===null){t.error(e.InvalidSpecificationValue,`Invalid property mapping '${i.content}' - expected '<property> = <value>'`,o(i));continue}let c=mappingOf(t,i,n,r);a===void 0?b(t,s,c):(s.some(e=>e.property===c.property)&&a.error(e.UnknownSpecificationQueryArgument,`Query argument '${c.property}' is repeated.`,c.location),s.push(c))}return s}function mappingOf(e,t,n,r=!1){return{kind:`PropertyMappingSyntax`,property:n[1],source:g(n[2],o(t),e,r),location:o(t)}}export{parseSpecification,parseSpecificationStream,rejectSpecificationRouteChildren,$ as specificationStream};
1
+ import"../../_virtual/_virtual/_rolldown/runtime.js";import{DiagnosticCodes as e}from"../Diagnostics/DiagnosticCodes.js";import{stringBodyPattern as t,unescapeString as n}from"../Text/StringLiteral.js";import{dotNetWhitespace as r,nativePattern as i,pattern as a}from"../Text/patterns.js";import{locationOf as o}from"./SourceLine.js";import{diagnosticText as s}from"../Diagnostics/DiagnosticArgument.js";import{firstWord as c}from"./LineText.js";import{generatedFixturePattern as l,generatedFixturePrefix as u,parseConcreteMapping as d,parseReturn as f,thenReturnsPrefix as p}from"./SpecificationResponseParser.js";import{containsCaseReference as m,parseCase as h,parseParameter as g,parseSpecificationValue as _,validateTable as ee}from"./SpecificationCaseParser.js";import{parseDescription as te}from"./DescriptionParser.js";import{sourceStreamPattern as v}from"../Text/SourceStreamNames.js";import{parseRouteParts as y}from"./EventSourceParser.js";import{isFileDirective as b}from"./FileReferences.js";import{rejectOperationChildren as ne}from"./OperationParser.js";import{addFixtureValue as x,addInlineValue as S}from"./SpecificationExampleParser.js";const C=a(`^(?:given\\s+operation|then\\s+(?:operation|compensated))(?:\\s|$)`),w=a(`^(given operation|then operation|then compensated)\\s+([A-Za-z_]\\w*(?:\\.[A-Za-z_]\\w*)*)(\\s+fails)?$`),T=a(`^specification\\s+([A-Za-z_]\\w*)$`),E=a(`^given caller as ([A-Za-z_]\\w*)$`),stepPattern=(e,t=``)=>i(`^${e}\\s+([A-Z]\\w*(?:\\.\\w+)*)${t}(?:\\s+(?<property>[\\w.]+)\\s*=(?!=|>)\\s*(?<value>.+))?$`.replaceAll(`\\s`,r)),D=stepPattern(`given`),O=stepPattern(`when\\s+append`),k=stepPattern(`when`),A=stepPattern(`then`),j=a(`^then\\s+query\\b`),M=a(`^(?:given|then)\\s+readmodel\\b`),N=stepPattern(`given\\s+readmodel`),P=stepPattern(`then\\s+readmodel`,`(?<exactly>\\s+exactly)?`),F=a(`^then\\s+no\\b`),I=a(`^then\\s+error\\s+"(${t})"$`),L=a(`^([\\w.]+)\\s*=(?!=|>)\\s*(.+)$`),R=i(`^([\\w.]+)\\s*=(?!=|>)\\s*(.+)$`),re=a(`^given\\s+clock\\b`),z=a(`^given\\s+capture\\b`),B=a(`^when\\s+clock\\b`),V=a(`^when\\s+trigger\\b`),H=a(`^when\\s+capture\\b`),U=a(`^when\\s+query\\b`),W=a(`^then\\s+result\\b`),G=a(`^then\\s+no\\s+result\\b`),K=i(`^when\\s+redelivered\\b`),q=i(`^when\\s+redelivered\\s+([A-Za-z_]\\w*(?:\\.\\w+)*)\\s+to\\s+([A-Za-z_]\\w*(?:\\.\\w+)*)$`),J=a(`^then\\s+no\\s+events\\b`),Y=a(`^(given|when)\\s+clock\\s+"(\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(?::\\d{2}(?:\\.\\d+)?)?(?:Z|[+-]\\d{2}:\\d{2}))"$`),X=a(`^when\\s+trigger\\s+([A-Za-z_]\\w*)$`),ie=a(`^(?:given|when)\\s+capture\\s+([A-Za-z_]\\w*)$`),ae=a(`^when\\s+query\\s+([A-Za-z_]\\w*(?:\\.\\w+)*)$`),oe=a(`^then\\s+result(\\s+exactly)?$`),Z=i(`^then\\s+no\\s+readmodel\\s+([A-Z]\\w*)\\s+for\\s+(.+)$`),se=i(`^(?:"${t}"|'(?:[^'\\\\]|\\\\.)*')$`),Q=i(`^then\\s+query\\s+([A-Za-z_]\\w*(?:\\.\\w+)*)(\\s+exactly)?$`);function parseSpecification(t,n){let r=T.exec(n.content)?.[1]??``;r===``&&t.error(e.InvalidSpecificationDeclaration,`Invalid specification declaration '${n.content}' - expected 'specification <Name>'`,o(n));let i=null,a=[],s=[],l={givenOperationFailures:[],thenOperations:[],thenCompensated:[],thenAbsentReadModels:[],thenQueries:[],given:[],givenReadModels:[],when:null,whenAppended:null,whenRedelivered:null,whenDeclared:!1,thenEvents:[],thenEventsInAnyOrder:!1,thenNoEvents:!1,thenReadModels:[],thenErrors:[],givenClock:null,givenCaptures:[],whenClock:null,whenTrigger:null,whenCapture:null,whenQuery:null,thenResults:[],thenNoResult:null,thenDenied:null,givenCaller:null,thenReturns:null};for(let u=t.peekChild(n.indent);u!==void 0;u=t.peekChild(n.indent)){if(t.reader.takeSignificant(),b(u)||parseOperationStep(t,u,l))continue;let n=F.test(u.content)?`then`:c(u.content);if(n===`parameter`){let e=g(t,u);e!==null&&a.push(e)}else if(n===`case`){let e=h(t,u);e!==null&&s.push(e)}else n===`description`?i=te(t,u,i,`Specification '${r}'`):n===`given`?parseGiven(t,u,l):n===`when`?parseWhen(t,u,l,r):n===`then`?parseThen(t,u,l):(t.error(e.UnknownSpecificationDirective,`Unexpected '${c(u.content)}' in specification body`,o(u)),t.skipBlock(u.indent))}l.noEventsLine!==void 0&&(l.thenEvents.length>0||l.thenEventsInAnyOrder||l.thenErrors.length>0||l.thenDenied!==null)&&t.error(e.InvalidNoEventsExpectation,`'then no events' cannot accompany event, event-order, error or denial expectations.`,o(l.noEventsLine)),validateQueryRejection(t,n,l);let{whenDeclared:u,noEventsLine:d,...f}=l,p={kind:`SpecificationSyntax`,sourceOptions:t.sourceOptions,name:r,description:i,...f,...a.length===0?{}:{parameters:a},...s.length===0?{}:{cases:s},location:o(n)};return ee(p,t),p}function validateQueryRejection(t,n,r){isQueryRejectionCandidate(r)&&!isWellFormedQueryRejection(r)&&t.error(e.MismatchedSpecificationQueryResult,`A query rejection requires exactly one query and one 'then error', no action, and no other outcomes`,o(n))}function isQueryRejectionCandidate(e){return e.thenErrors.length>0&&queriedCallCount(e)>0&&(e.whenQuery!==null||!hasAction(e))}function isWellFormedQueryRejection(e){return!hasAction(e)&&hasOneQueryAndOneError(e)&&!hasOtherOutcome(e)}function hasOneQueryAndOneError(e){return queriedCallCount(e)===1&&e.thenErrors.length===1}function hasAction(e){return[e.when,e.whenAppended,e.whenClock,e.whenTrigger,e.whenCapture,e.whenRedelivered].some(e=>e!==null)}function queriedCallCount(e){return e.thenQueries.length+(e.whenQuery===null?0:1)}function hasOtherOutcome(e){return[e.thenResults.length>0,e.thenNoResult!==null,e.thenDenied!==null,e.thenEvents.length>0,e.thenNoEvents,e.thenEventsInAnyOrder,e.thenReadModels.length>0,e.thenAbsentReadModels.length>0,e.thenReturns!==null,e.thenQueries.some(e=>e.results.length>0)].some(e=>e)}function parseOperationStep(t,n,r){if(!C.test(n.content))return!1;let i=w.exec(n.content);if(i===null||i[1]===`given operation`!=(i[3]!==void 0))t.error(e.InvalidOperationSpecification,`Expected 'given operation <Name> fails', 'then operation <Name>' or 'then compensated <Name>'.`,o(n)),skipBody(t,n.indent);else if(i[1]===`then operation`){let a=[];for(let r=t.peekChild(n.indent);r!==void 0;r=t.peekChild(n.indent)){t.reader.takeSignificant();let n=d(t,r,L,e.InvalidOperationSpecification);n!==null&&a.push(n)}r.thenOperations.push({kind:`SpecificationOperationSyntax`,operation:i[2],values:a,location:o(n)})}else ne(t,n,e.InvalidOperationSpecification,`Failure and compensation assertions cannot have children.`),i[1]===`given operation`?r.givenOperationFailures.push({kind:`SpecificationOperationFailureSyntax`,operation:i[2],location:o(n)}):r.thenCompensated.push({kind:`SpecificationCompensatedSyntax`,operation:i[2],location:o(n)});return!0}function parseGiven(t,n,r){if(re.test(n.content))r.givenClock===null?r.givenClock=parseClock(t,n,`given`):(t.error(e.InvalidSpecificationClock,`A specification states its clock at most once.`,o(n)),skipBody(t,n.indent));else if(z.test(n.content)){let e=parseCapture(t,n,`given`);e!==null&&r.givenCaptures.push(e)}else if(n.content.startsWith(`given caller`)){if(r.givenCaller!==null||r.givenCallerPersona!==void 0)t.error(e.DuplicateSpecificationCallerOrDenied,`A specification has at most one 'given caller' block.`,o(n)),t.skipBlock(n.indent);else if(n.content.startsWith(`given caller as`)){let i=E.exec(n.content);i===null&&t.error(e.InvalidSpecificationCallerPersona,`Expected 'given caller as <Persona>'.`,o(n));let a=t.peekChild(n.indent);a!==void 0&&t.error(e.InvalidSpecificationCallerPersona,`'given caller as <Persona>' has no body; use an explicit 'given caller' for refinements.`,o(a)),skipBody(t,n.indent),i!==null&&(r.givenCallerPersona={kind:`SpecificationCallerPersonaSyntax`,name:i[1],location:o(n)})}else r.givenCaller=parseCaller(t,n)}else if(M.test(n.content)){let e=parseReadModelStep(t,n,N,`given`);e!==void 0&&r.givenReadModels.push(e)}else{let e=parseEventStep(t,n,D,`given`);e!==void 0&&r.given.push(e)}}const ce=a(`^role${r}+"(${t})"$`),le=a(`^claim${r}+"(${t})"${r}*=${r}*"(${t})"$`);function parseCaller(t,r){if(r.content!==`given caller`)return t.error(e.InvalidSpecificationCaller,`Expected exactly 'given caller'.`,o(r)),t.skipBlock(r.indent),null;let i=!1,a=[],s=[];for(let c=t.peekChild(r.indent);c!==void 0;c=t.peekChild(r.indent)){t.reader.takeSignificant();let r=ce.exec(c.content),l=le.exec(c.content);c.content===`authenticated`&&!i?i=!0:r===null?l===null?t.error(m(c.content)?e.InvalidSpecificationCaseReference:e.InvalidSpecificationCaller,`Invalid caller fixture '${c.content}' - expected authenticated, role "...", or claim "..." = "...".`,o(c)):s.push({kind:`SpecificationCallerClaimSyntax`,type:n(l[1]),value:n(l[2]),location:o(c)}):a.push(n(r[1]))}return{kind:`SpecificationCallerSyntax`,authenticated:i,roles:a,claims:s,location:o(r)}}function parseWhen(t,n,r,i){let a=n.content.startsWith(`when append`);if(r.whenDeclared){let s=r.whenAppended!==null||a?e.ConflictingSpecificationActions:e.DuplicateSpecificationWhen;t.error(s,`Specification '${i}' already declares a 'when' - a specification can have at most one`,o(n)),skipBody(t,n.indent);return}if(r.whenDeclared=!0,a){r.whenAppended=parseEventStep(t,n,O,`when append`)??null;return}if(K.test(n.content)){let i=q.exec(n.content);i===null?(t.error(e.UnmatchedRedeliveredOccurrence,`Expected 'when redelivered <Event> to <Reaction>'.`,o(n)),skipBody(t,n.indent)):r.whenRedelivered={kind:`SpecificationRedeliverySyntax`,eventType:i[1],reaction:i[2],...parseValuesWithEventSource(t,n,void 0,void 0,`when redelivered`),location:o(n)};return}if(B.test(n.content)){r.whenClock=parseClock(t,n,`when`);return}if(V.test(n.content)){r.whenTrigger=parseNamedStep(t,n,X,e.InvalidSpecificationTrigger,`when trigger`,`when trigger <Trigger>`,(e,t)=>({kind:`SpecificationTriggerSyntax`,trigger:e,values:t,location:o(n)}));return}if(H.test(n.content)){r.whenCapture=parseCapture(t,n,`when`);return}if(U.test(n.content)){r.whenQuery=parseNamedStep(t,n,ae,e.InvalidSpecificationQueryAction,`when query`,`when query <Query>`,(e,t)=>({kind:`SpecificationWhenQuerySyntax`,query:e,arguments:t,location:o(n)}),!0);return}let s=k.exec(n.content);if(s===null){t.error(e.InvalidSpecificationWhen,`Invalid 'when' declaration '${n.content}' - expected 'when <CommandType>' or 'when append <EventType>'`,o(n)),skipBody(t,n.indent);return}let c=[],l=parseValuesWithEventSource(t,n,c,s);r.when={kind:`SpecificationCommandSyntax`,commandType:s[1],...l,generatedValues:c,inlineProperty:s.groups?.property??null,location:o(n)}}function parseThen(t,r,i){if(J.test(r.content)){r.content!==`then no events`||i.thenNoEvents?t.error(e.InvalidNoEventsExpectation,`Expected one 'then no events' directive.`,o(r)):(i.thenNoEvents=!0,i.noEventsLine=r);let n=t.peekChild(r.indent);n!==void 0&&t.error(e.InvalidNoEventsExpectation,`'then no events' cannot have child mappings.`,o(n)),skipBody(t,r.indent);return}if(p.test(r.content)){let n=f(t,r);i.thenReturns===null?i.thenReturns=n:t.error(e.InvalidReturnExpectation,`A specification declares at most one return expectation.`,o(r));return}if(r.content.startsWith(`then events`)){r.content!==`then events in any order`||i.thenEventsInAnyOrder?t.error(e.InvalidSpecificationEventOrder,`Expected one 'then events in any order' directive.`,o(r)):i.thenEventsInAnyOrder=!0,skipBody(t,r.indent);return}if(W.test(r.content)){parseResult(t,r,i);return}if(G.test(r.content)){r.content!==`then no result`||i.thenNoResult!==null?t.error(e.InvalidSpecificationQueryAction,`Expected one 'then no result' directive.`,o(r)):i.thenNoResult={kind:`SpecificationNoResultSyntax`,location:o(r)},skipBody(t,r.indent);return}if(r.content.startsWith(`then denied`)){r.content===`then denied`?i.thenDenied===null?i.thenDenied={kind:`SpecificationDeniedSyntax`,location:o(r)}:t.error(e.DuplicateSpecificationCallerOrDenied,`A specification has at most one 'then denied' outcome.`,o(r)):(t.error(e.InvalidSpecificationDenied,`Expected exactly 'then denied'.`,o(r)),skipBody(t,r.indent));return}if(r.content===`then error`){i.thenErrors.push({kind:`SpecificationErrorSyntax`,name:null,location:o(r)});return}if(r.content.startsWith(`then error case.`)){let e=_(r.content.substring(11),{...o(r),column:o(r).column+11},t);e.kind===`CaseValueExpressionSyntax`&&i.thenErrors.push({kind:`SpecificationErrorSyntax`,name:null,caseValue:e,location:o(r)});return}let a=I.exec(r.content);if(a!==null){i.thenErrors.push({kind:`SpecificationErrorSyntax`,name:n(a[1]),location:o(r)});return}if(c(r.content.substring(4).trim())===`error`){t.error(e.InvalidThenError,`Invalid 'then error' declaration '${r.content}' - expected 'then error' or 'then error "<reason>"'`,o(r)),skipBody(t,r.indent);return}if(F.test(r.content)){if(t.sourceOptions.numericMode===`exact`){let e=parseAbsentReadModel(t,r);e!==null&&i.thenAbsentReadModels.push(e);return}let e=Z.exec(r.content);if(e!==null&&!e[2].endsWith(` exactly`)){let n=_(e[2].trim(),o(r),t.valueContext);(n.kind===`LiteralExpressionSyntax`||n.kind===`ObjectExpressionSyntax`||n.kind===`CaseValueExpressionSyntax`)&&i.thenAbsentReadModels.push({kind:`SpecificationAbsentReadModelSyntax`,name:e[1],key:n,location:o(r)})}t.skipOpaqueBlock(r.indent);return}if(j.test(r.content)){let n=t.sourceOptions.numericMode===`exact`,reject=(e,r,i)=>{if(!n)return t.skipOpaqueBlock(i.indent);t.error(e,r,o(i)),t.skipBlock(i.indent)},a=Q.exec(r.content);if(a===null)return reject(e.InvalidSpecificationQuery,`Invalid 'then query' declaration '${r.content}' - expected 'then query <Query> [exactly]'`,r);let s=[],l=[],u=!1;for(let n=t.peekChild(r.indent);n!==void 0;n=t.peekChild(r.indent))t.reader.takeSignificant(),n.content===`arguments`&&!u?s.push(...parseValues(t.valueContext,n,!0,void 0,t)):n.content===`arguments`?reject(e.DuplicateSpecificationQueryArguments,`Query assertion '${a[1]}' already declares arguments`,n):n.content===`result`?l.push({kind:`SpecificationQueryResultSyntax`,properties:parseValues(t.valueContext,n,!0),exactly:!1,location:o(n)}):reject(e.UnknownSpecificationQueryDirective,`Unexpected '${c(n.content)}' in 'then query' body - expected arguments or result`,n),u||=n.content===`arguments`;i.thenQueries.push({kind:`SpecificationQuerySyntax`,query:a[1],arguments:s,results:l,exactly:a[2]!==void 0,location:o(r)});return}if(M.test(r.content)){let e=parseReadModelStep(t,r,P,`then`);e!==void 0&&i.thenReadModels.push(e);return}let s=parseEventStep(t,r,A,`then`);s!==void 0&&i.thenEvents.push(s)}function parseAbsentReadModel(t,n){let r=Z.exec(n.content);if(r===null||r[2].endsWith(` exactly`))return t.error(e.InvalidAbsentReadModelStep,`Invalid absence assertion '${n.content}' - expected 'then no readmodel <ReadModelType> for <key>'`,o(n)),skipBody(t,n.indent),null;let i=r[2].trim(),a=!(i.startsWith(`"`)||i.startsWith(`'`))||se.test(i)?_(i,o(n),t.valueContext):null,s=a!==null&&(a.kind===`LiteralExpressionSyntax`||a.kind===`ObjectExpressionSyntax`||a.kind===`CaseValueExpressionSyntax`);s||t.error(e.InvalidAbsentReadModelStep,`Invalid absence key '${i}' - expected exactly one concrete value.`,o(n));let c=!1;for(let r=t.peekChild(n.indent);r!==void 0;r=t.peekChild(n.indent))t.reader.takeSignificant(),t.error(e.InvalidAbsentReadModelStep,`An absent read model assertion cannot have child mappings.`,o(r)),c=!0;return c||!s?null:{kind:`SpecificationAbsentReadModelSyntax`,name:r[1],key:a,location:o(n)}}function skipBody(e,t){if(e.sourceOptions.numericMode!==`exact`)return e.skipBlock(t);e.skipOpaqueBlock(t)}function parseClock(t,n,r){let i=Y.exec(n.content);return skipBody(t,n.indent),i===null||i[1]!==r?(t.error(m(n.content)?e.InvalidSpecificationCaseReference:e.InvalidSpecificationClock,`Invalid '${r} clock' - expected '${r} clock "<ISO 8601 instant>"', such as '${r} clock "2026-10-05T08:00:00Z"'`,o(n)),null):{kind:`SpecificationClockSyntax`,instant:i[2],location:o(n)}}function parseCapture(t,n,r){return parseNamedStep(t,n,ie,e.InvalidSpecificationCapture,`${r} capture`,`${r} capture <Capture>`,(e,t)=>({kind:`SpecificationCaptureSyntax`,capture:e,record:t,location:o(n)}))}function parseNamedStep(e,t,n,r,i,a,s,c=!1){let l=n.exec(t.content);return l===null?(e.error(r,`Invalid '${i}' declaration '${t.content}' - expected '${a}'`,o(t)),skipBody(e,t.indent),null):s(l[1],parseValues(e,t,!1,void 0,c?e:void 0))}function parseResult(t,n,r){let i=oe.exec(n.content);i===null?(t.error(e.InvalidSpecificationQueryAction,`Invalid 'then result' declaration '${n.content}' - expected 'then result [exactly]'`,o(n)),skipBody(t,n.indent)):r.thenResults.push({kind:`SpecificationQueryResultSyntax`,properties:parseValues(t,n),exactly:i[1]!==void 0,location:o(n)})}function parseReadModelStep(t,n,r,i){let a=r.exec(n.content);if(a===null)t.error(e.InvalidReadModelStep,`Invalid '${i} readmodel' declaration '${n.content}' - expected '${i} readmodel <ReadModelType>'`,o(n)),skipBody(t,n.indent);else return{kind:`SpecificationReadModelSyntax`,name:a[1],properties:parseValues(t,n,!1,a),exactly:i===`then`&&a.groups?.exactly!==void 0,inlineProperty:a.groups?.property??null,location:o(n)}}function parseEventStep(t,n,r,i){let a=r.exec(n.content);if(a===null)t.error(e.InvalidEventStep,`Invalid '${i}' declaration '${n.content}' - expected '${i} <EventType>'`,o(n)),skipBody(t,n.indent);else return{kind:`SpecificationEventSyntax`,eventType:a[1],...parseValuesWithEventSource(t,n,void 0,a,i),inlineProperty:a.groups?.property??null,location:o(n)}}const $=v(`^stream\\s+([A-Za-z_]\\w*)\\.([A-Za-z_]\\w*)$`),ue=a(`^streamId\\s*=(?!=|>)\\s*(.+)$`);function parseValuesWithEventSource(t,n,r,i,a){let f=[];S(t,n,i,f);let p=null,m,h,g=!1;for(let i=t.peekChild(n.indent);i!==void 0;i=t.peekChild(n.indent)){if(t.reader.takeSignificant(),r!==void 0&&u.test(i.content)){let n=d(t,i,l,e.InvalidGeneratedFixture);n!==null&&r.push(n);continue}let n=L.exec(i.content);if(n!==null)x(t,f,mappingOf(t,i,n));else if(c(i.content)===`stream`||i.content.startsWith(`no stream`)){if(a===void 0){t.error(e.SpecificationStreamOnCommand,`A command occurrence cannot declare a route; assert it on a then event.`,o(i)),t.skipBlock(i.indent);continue}if(g){t.error(e.InvalidSpecificationStream,`An event occurrence declares at most one stream or no stream directive.`,o(i)),t.skipBlock(i.indent);continue}let n=$.exec(i.content);i.content===`no stream`&&(a===`then`||a===`when redelivered`)?(h={kind:`SpecificationNoStreamSyntax`,location:o(i)},g=!0,rejectSpecificationRouteChildren(t,i)):n===null?(t.error(e.InvalidSpecificationStream,`Expected 'stream Source.Stream', or 'no stream' on a then event.`,o(i)),t.skipBlock(i.indent)):(m=parseSpecificationStream(t,i,n),g=!0)}else if(c(i.content)===`for`){let n=i.content.substring(3).trim();n.length===0?t.error(e.InvalidSpecificationEventSource,`Invalid event-source assertion 'for' - expected 'for <value>'`,o(i)):p===null?p=_(n,o(i),t):t.error(e.DuplicateSpecificationEventSource,`A specification step can declare its event-source assertion only once`,o(i))}else t.error(e.InvalidSpecificationValue,`Invalid property mapping '${i.content}' - expected '<property> = <value>'`,o(i),s(`text`,i.content))}return{values:f,for:p,...m===void 0?{}:{stream:m},...h===void 0?{}:{noStream:h}}}function parseSpecificationStream(t,n,r){let i=null,a=[],s=!1,c={};for(let r=t.peekChild(n.indent);r!==void 0;r=t.peekChild(n.indent)){if(t.reader.takeSignificant(),r.content===`streamId`){i!==null||s?(t.error(e.InvalidSpecificationStream,`Declare either one 'streamId = <literal>' mapping or one streamId part block.`,o(r)),t.skipBlock(r.indent)):(s=!0,c.streamId=o(r),a=y(t,r,e.InvalidSpecificationStream).map(e=>e.source.kind===`PathExpressionSyntax`&&e.source.path.startsWith(`case.`)?{...e,source:_(e.source.path,e.source.location,t)}:e));continue}let n=ue.exec(r.content);if(n===null||i!==null||s){t.error(e.InvalidSpecificationStream,`Declare either one 'streamId = <literal>' mapping or one streamId part block.`,o(r)),t.skipBlock(r.indent);continue}let l={...o(r),column:r.indent+1+r.content.indexOf(n[1],r.content.indexOf(`=`)+1)};i={kind:`PropertyMappingSyntax`,property:`streamId`,source:_(n[1],l,t),location:o(r)},rejectSpecificationRouteChildren(t,r)}return{kind:`SpecificationStreamSyntax`,eventSource:r[1],stream:r[2],streamId:i,streamIdParts:a,directiveLocations:c,referenceLocation:{...o(n),column:n.indent+1+n.content.indexOf(r[1],6)},referenceLength:r[1].length+1+r[2].length,location:o(n)}}function rejectSpecificationRouteChildren(t,n){let r=t.peekChild(n.indent);r!==void 0&&(t.error(e.InvalidSpecificationStream,`This directive cannot have children.`,o(r)),t.skipBlock(n.indent))}function parseValues(t,n,r=!1,i,a){let c=[];S(t,n,i,c);for(let i=t.peekChild(n.indent);i!==void 0;i=t.peekChild(n.indent)){t.reader.takeSignificant();let n=(r||t.sourceOptions.numericMode===`exact`?R:L).exec(i.content);if(n===null){t.error(e.InvalidSpecificationValue,`Invalid property mapping '${i.content}' - expected '<property> = <value>'`,o(i),s(`text`,i.content));continue}let l=mappingOf(t,i,n,r);a===void 0?x(t,c,l):(c.some(e=>e.property===l.property)&&a.error(e.UnknownSpecificationQueryArgument,`Query argument '${l.property}' is repeated.`,l.location,s(`argument`,l.property)),c.push(l))}return c}function mappingOf(e,t,n,r=!1){return{kind:`PropertyMappingSyntax`,property:n[1],source:_(n[2],o(t),e,r),location:o(t)}}export{parseSpecification,parseSpecificationStream,rejectSpecificationRouteChildren,$ as specificationStream};
2
2
  //# sourceMappingURL=SpecificationParser.js.map