@cratis/screenplay-language 4.52.0 → 4.53.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 (190) hide show
  1. package/dist/TypeReferenceSymbol.d.ts +8 -0
  2. package/dist/TypeReferenceSymbol.d.ts.map +1 -0
  3. package/dist/bundles/chunk-7WJEZ72S.js +4463 -0
  4. package/dist/bundles/chunk-7WJEZ72S.js.map +7 -0
  5. package/dist/bundles/index.js +1410 -0
  6. package/dist/bundles/index.js.map +7 -0
  7. package/dist/bundles/sub-languages/capture/index.js +677 -0
  8. package/dist/bundles/sub-languages/capture/index.js.map +7 -0
  9. package/dist/bundles/sub-languages/projection/index.js +1647 -0
  10. package/dist/bundles/sub-languages/projection/index.js.map +7 -0
  11. package/dist/code-actions.d.ts +3 -0
  12. package/dist/code-actions.d.ts.map +1 -0
  13. package/dist/completion-items.d.ts +1 -0
  14. package/dist/completion-items.d.ts.map +1 -1
  15. package/dist/completion-planner.d.ts.map +1 -1
  16. package/dist/completions.d.ts.map +1 -1
  17. package/dist/diagnostic-codes.d.ts +3 -0
  18. package/dist/diagnostic-codes.d.ts.map +1 -1
  19. package/dist/diagnostics.d.ts.map +1 -1
  20. package/dist/hover-content.d.ts.map +1 -1
  21. package/dist/index.d.ts +3 -0
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/keyword-docs.d.ts.map +1 -1
  24. package/dist/language.d.ts +1 -0
  25. package/dist/language.d.ts.map +1 -1
  26. package/dist/production-destinations.d.ts.map +1 -1
  27. package/dist/symbols.d.ts +4 -0
  28. package/dist/symbols.d.ts.map +1 -1
  29. package/dist/tokens.d.ts.map +1 -1
  30. package/dist/validation.d.ts +1 -0
  31. package/dist/validation.d.ts.map +1 -1
  32. package/package.json +13 -9
  33. package/DestinationHint.ts +0 -8
  34. package/ProductionSymbol.ts +0 -11
  35. package/completion-items.ts +0 -261
  36. package/completion-planner.ts +0 -167
  37. package/completions.ts +0 -156
  38. package/diagnostic-codes.ts +0 -43
  39. package/diagnostics.ts +0 -55
  40. package/dist/DestinationHint.js +0 -4
  41. package/dist/DestinationHint.js.map +0 -1
  42. package/dist/ProductionSymbol.js +0 -4
  43. package/dist/ProductionSymbol.js.map +0 -1
  44. package/dist/completion-items.js +0 -228
  45. package/dist/completion-items.js.map +0 -1
  46. package/dist/completion-planner.js +0 -143
  47. package/dist/completion-planner.js.map +0 -1
  48. package/dist/completions.js +0 -101
  49. package/dist/completions.js.map +0 -1
  50. package/dist/diagnostic-codes.js +0 -41
  51. package/dist/diagnostic-codes.js.map +0 -1
  52. package/dist/diagnostics.js +0 -50
  53. package/dist/diagnostics.js.map +0 -1
  54. package/dist/document-context.js +0 -85
  55. package/dist/document-context.js.map +0 -1
  56. package/dist/event-analysis-source.js +0 -19
  57. package/dist/event-analysis-source.js.map +0 -1
  58. package/dist/event-context-catalog.js +0 -116
  59. package/dist/event-context-catalog.js.map +0 -1
  60. package/dist/event-context.js +0 -88
  61. package/dist/event-context.js.map +0 -1
  62. package/dist/file-imports.js +0 -58
  63. package/dist/file-imports.js.map +0 -1
  64. package/dist/file-references.js +0 -70
  65. package/dist/file-references.js.map +0 -1
  66. package/dist/hover-content.js +0 -98
  67. package/dist/hover-content.js.map +0 -1
  68. package/dist/hover.js +0 -15
  69. package/dist/hover.js.map +0 -1
  70. package/dist/index.js +0 -61
  71. package/dist/index.js.map +0 -1
  72. package/dist/inlay-hints.js +0 -15
  73. package/dist/inlay-hints.js.map +0 -1
  74. package/dist/inline-event-validation.js +0 -131
  75. package/dist/inline-event-validation.js.map +0 -1
  76. package/dist/keyword-docs.js +0 -148
  77. package/dist/keyword-docs.js.map +0 -1
  78. package/dist/language.js +0 -196
  79. package/dist/language.js.map +0 -1
  80. package/dist/production-destinations.js +0 -32
  81. package/dist/production-destinations.js.map +0 -1
  82. package/dist/sub-language-registry.js +0 -18
  83. package/dist/sub-language-registry.js.map +0 -1
  84. package/dist/sub-languages/capture/CompletionProvider.js +0 -332
  85. package/dist/sub-languages/capture/CompletionProvider.js.map +0 -1
  86. package/dist/sub-languages/capture/HoverProvider.js +0 -87
  87. package/dist/sub-languages/capture/HoverProvider.js.map +0 -1
  88. package/dist/sub-languages/capture/Validator.js +0 -72
  89. package/dist/sub-languages/capture/Validator.js.map +0 -1
  90. package/dist/sub-languages/capture/index.js +0 -58
  91. package/dist/sub-languages/capture/index.js.map +0 -1
  92. package/dist/sub-languages/capture/language.js +0 -160
  93. package/dist/sub-languages/capture/language.js.map +0 -1
  94. package/dist/sub-languages/cdl.js +0 -74
  95. package/dist/sub-languages/cdl.js.map +0 -1
  96. package/dist/sub-languages/pdl.js +0 -73
  97. package/dist/sub-languages/pdl.js.map +0 -1
  98. package/dist/sub-languages/projection/CodeActionProvider.js +0 -93
  99. package/dist/sub-languages/projection/CodeActionProvider.js.map +0 -1
  100. package/dist/sub-languages/projection/CompletionProvider.js +0 -595
  101. package/dist/sub-languages/projection/CompletionProvider.js.map +0 -1
  102. package/dist/sub-languages/projection/HoverProvider.js +0 -333
  103. package/dist/sub-languages/projection/HoverProvider.js.map +0 -1
  104. package/dist/sub-languages/projection/Validator.js +0 -388
  105. package/dist/sub-languages/projection/Validator.js.map +0 -1
  106. package/dist/sub-languages/projection/index.js +0 -160
  107. package/dist/sub-languages/projection/index.js.map +0 -1
  108. package/dist/sub-languages/projection/language.js +0 -171
  109. package/dist/sub-languages/projection/language.js.map +0 -1
  110. package/dist/symbols.js +0 -275
  111. package/dist/symbols.js.map +0 -1
  112. package/dist/themes/screenplay-dark.js +0 -30
  113. package/dist/themes/screenplay-dark.js.map +0 -1
  114. package/dist/themes/screenplay-light.js +0 -30
  115. package/dist/themes/screenplay-light.js.map +0 -1
  116. package/dist/tokens.js +0 -147
  117. package/dist/tokens.js.map +0 -1
  118. package/dist/validation.js +0 -248
  119. package/dist/validation.js.map +0 -1
  120. package/document-context.ts +0 -93
  121. package/event-analysis-source.ts +0 -18
  122. package/event-context-catalog.ts +0 -135
  123. package/event-context.ts +0 -119
  124. package/file-imports.ts +0 -70
  125. package/file-references.ts +0 -87
  126. package/for_documentContext/when_stripping_comments.ts +0 -32
  127. package/for_eventContext/when_resolving_generated_catalog_vectors.ts +0 -15
  128. package/for_eventGenerations/when_editing_event_generations.ts +0 -57
  129. package/for_fileImports/when_finding_file_imports.ts +0 -38
  130. package/for_fileReferences/when_recognizing_an_absolute_path/with_paths_of_every_shape.ts +0 -26
  131. package/for_fileReferences/when_scanning_a_document/inside_a_code_fence.ts +0 -26
  132. package/for_fileReferences/when_scanning_a_document/with_a_bare_file_keyword.ts +0 -19
  133. package/for_fileReferences/when_scanning_a_document/with_a_file_directive.ts +0 -30
  134. package/for_fileReferences/when_scanning_a_document/with_a_property_named_file.ts +0 -25
  135. package/for_fileReferences/when_scanning_a_document/with_a_trailing_comment.ts +0 -25
  136. package/for_fileReferences/when_scanning_a_document/with_directives_on_several_constructs.ts +0 -41
  137. package/for_importablePaths/when_listing_what_a_document_can_import.ts +0 -34
  138. package/for_inlineEvents/when_analyzing_many_inline_events.ts +0 -59
  139. package/for_inlineEvents/when_authoring_inline_events.ts +0 -149
  140. package/for_inlineEvents/when_completing_many_events.ts +0 -49
  141. package/for_inlineEvents/when_indexing_command_production_ownership.ts +0 -79
  142. package/for_planCompletions/when_completing_a_file_import.ts +0 -26
  143. package/for_planCompletions/when_completing_a_specification_query.ts +0 -24
  144. package/for_planCompletions/when_completing_a_specification_step.ts +0 -42
  145. package/for_planCompletions/when_completing_an_absent_read_model.ts +0 -14
  146. package/for_planCompletions/when_completing_reaction_reads.ts +0 -36
  147. package/for_projectionCompletionProvider/when_completing_an_event_context_path.ts +0 -102
  148. package/for_projectionHoverProvider/when_hovering_an_event_context_path.ts +0 -44
  149. package/for_projectionValidator/when_validating_a_projection_with_variants.ts +0 -128
  150. package/for_projectionValidator/when_validating_event_context_paths.ts +0 -31
  151. package/for_scanDocument/when_scanning_a_query/with_a_dotted_return_type.ts +0 -34
  152. package/for_scanDocument/when_scanning_aliased_reads.ts +0 -33
  153. package/for_scanDocument/when_scanning_many_commands.ts +0 -47
  154. package/for_tokens/when_highlighting_a_file_import.ts +0 -18
  155. package/for_tokens/when_highlighting_event_metadata.ts +0 -63
  156. package/for_tokens/when_highlighting_specification_steps.ts +0 -28
  157. package/for_validateLines/when_validating_a_document/with_a_problem_of_every_coded_kind.ts +0 -77
  158. package/for_validateLines/when_validating_a_document/with_an_unknown_policy.ts +0 -33
  159. package/for_validateLines/when_validating_a_file_placed_by_an_import/with_names_declared_in_other_files.ts +0 -43
  160. package/for_validateLines/when_validating_event_context_paths/in_a_projection.ts +0 -97
  161. package/for_validateLines/when_validating_file_imports/at_every_level.ts +0 -36
  162. package/for_validateLines/when_validating_production_destinations/with_an_available_identifier.ts +0 -120
  163. package/hover-content.ts +0 -117
  164. package/hover.ts +0 -23
  165. package/index.ts +0 -125
  166. package/inlay-hints.ts +0 -17
  167. package/inline-event-validation.ts +0 -115
  168. package/keyword-docs.ts +0 -152
  169. package/language.ts +0 -212
  170. package/production-destinations.ts +0 -32
  171. package/sub-language-registry.ts +0 -42
  172. package/sub-languages/capture/CompletionProvider.ts +0 -365
  173. package/sub-languages/capture/HoverProvider.ts +0 -99
  174. package/sub-languages/capture/Validator.ts +0 -97
  175. package/sub-languages/capture/index.ts +0 -72
  176. package/sub-languages/capture/language.ts +0 -176
  177. package/sub-languages/cdl.ts +0 -76
  178. package/sub-languages/pdl.ts +0 -75
  179. package/sub-languages/projection/CodeActionProvider.ts +0 -123
  180. package/sub-languages/projection/CompletionProvider.ts +0 -660
  181. package/sub-languages/projection/HoverProvider.ts +0 -377
  182. package/sub-languages/projection/Validator.ts +0 -441
  183. package/sub-languages/projection/index.ts +0 -223
  184. package/sub-languages/projection/language.ts +0 -193
  185. package/symbols.ts +0 -374
  186. package/themes/screenplay-dark.ts +0 -33
  187. package/themes/screenplay-light.ts +0 -33
  188. package/tokens.ts +0 -174
  189. package/validation.ts +0 -443
  190. package/vitest.setup.ts +0 -5
@@ -1,115 +0,0 @@
1
- // Copyright (c) Cratis. All rights reserved.
2
- // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
-
4
- import { DiagnosticCode, diagnosticCodes } from './diagnostic-codes';
5
- import { fenceMap, indentOf } from './document-context';
6
- import { productionDestinations } from './production-destinations';
7
- import { eventAnalysisSource } from './event-analysis-source';
8
- import { directBody, DocumentSymbols } from './symbols';
9
- import type { ValidationIssue, ValidationSeverity } from './validation';
10
-
11
- const reserved = new Set(['namespace', 'sequence', 'correlation', 'causation', 'causedBy', 'occurred']);
12
- const quotedId = /^id\s+"((?:[^"\\]|\\.)*)"$/;
13
-
14
- export function validateInlineEvents(lines: string[], symbols: DocumentSymbols, application: DocumentSymbols): ValidationIssue[] {
15
- lines = eventAnalysisSource(lines);
16
- const issues: ValidationIssue[] = [];
17
- const fences = fenceMap(lines);
18
- const documentationBlocks = nonemptyMarkdownBlocks(lines, fences);
19
- const commandProductions = new Set(symbols.commands.flatMap(command => command.productionHeaders ?? []));
20
- const eventCounts = new Map<string, number>();
21
- const importedNames = new Set<string>();
22
- for (const document of [symbols, application]) {
23
- for (const event of document.events) eventCounts.set(event.name, (eventCounts.get(event.name) ?? 0) + 1);
24
- for (const imported of document.imports) importedNames.add(imported.shortName);
25
- }
26
- const report = (line: number, code: DiagnosticCode, message: string, severity: ValidationSeverity = 'error') => {
27
- issues.push({ line, startColumn: indentOf(lines[line]) + 1, endColumn: lines[line].length + 1, code, message, severity });
28
- };
29
- for (const event of symbols.events) {
30
- const body = directBody(lines, fences, event.line, indentOf(lines[event.line]));
31
- if (event.inline) {
32
- const properties = new Set<string>();
33
- for (const property of event.properties) {
34
- if (properties.has(property.name)) report(property.line, diagnosticCodes.duplicateDeclaration, `Event '${event.name}' already declares property '${property.name}'.`);
35
- properties.add(property.name);
36
- }
37
- if (!commandProductions.has(event.line)) report(event.line, diagnosticCodes.inlineEventOutsideCommand, 'Inline events can only be declared inside commands.');
38
- if (event.generation !== undefined) report(event.line, diagnosticCodes.inlineEventGeneration, 'Inline events are generation 1; extract the event before declaring generations.');
39
- if ((eventCounts.get(event.name) ?? 0) > 1 || importedNames.has(event.name)) {
40
- report(event.line, diagnosticCodes.inlineEventCollision, `Inline event '${event.name}' collides with another declaration or import.`);
41
- }
42
- }
43
- let hasId = false;
44
- let hasDocumentation = false;
45
- for (const index of body) {
46
- const text = lines[index].trim();
47
- const keyword = text.split(/\s+/)[0];
48
- if (event.inline && keyword === 'generation') report(index, diagnosticCodes.inlineEventGeneration, 'Inline events are generation 1; extract the event before declaring generations.');
49
- if (event.inline && keyword === 'origin') report(index, diagnosticCodes.reservedProductionMetadata, 'An inline event is local to its command and cannot declare origin.');
50
- // Property-shaped metadata names stay properties, whether standalone or typed mappings.
51
- if (/^(?:id|description|documentation)\s+[\w.]+(?:\[\])?\??(?:\s*=.*)?$/.test(text)) continue;
52
- if (keyword === 'id') {
53
- const match = text.match(quotedId);
54
- if (hasId || match === null || match[1].trim().length === 0) report(index, diagnosticCodes.invalidEventId, 'Expected one nonempty id "<old-name>".');
55
- else if (match[1] === event.name) report(index, diagnosticCodes.redundantEventId, 'This id repeats the event name; remove it.', 'information');
56
- hasId = true;
57
- }
58
- if (keyword === 'documentation') {
59
- let next = index + 1;
60
- while (next < lines.length && lines[next].trim().length === 0) next++;
61
- if (hasDocumentation || text !== 'documentation' || lines[next]?.trim() !== '```markdown' || indentOf(lines[next]) <= indentOf(lines[index]) ||
62
- !documentationBlocks.has(next)) {
63
- report(index, diagnosticCodes.invalidEventDocumentation, 'Expected one nonempty fenced markdown documentation block.');
64
- }
65
- hasDocumentation = true;
66
- }
67
- }
68
- }
69
- // Also cover reaction productions without a backward ancestry walk per metadata line.
70
- const productionIndents: number[] = [];
71
- for (let index = 0; index < lines.length; index++) {
72
- if (fences[index] || lines[index].trim().length === 0) continue;
73
- const indent = indentOf(lines[index]);
74
- while (productionIndents.length > 0 && productionIndents[productionIndents.length - 1] >= indent) productionIndents.pop();
75
- const keyword = lines[index].trim().split(/\s+/)[0];
76
- if (reserved.has(keyword) && productionIndents.length > 0) {
77
- report(index, diagnosticCodes.reservedProductionMetadata, `'${keyword}' is system-assigned production metadata.`);
78
- }
79
- if (keyword === 'produces') productionIndents.push(indent);
80
- }
81
- for (const command of symbols.commands) {
82
- const { identifier, mixed } = productionDestinations(command);
83
- for (const production of command.produces ?? []) {
84
- if (mixed && production.target === undefined) report(production.line, diagnosticCodes.explicitProducesTargetsRequired, `Production '${production.name}' must state for explicitly when destinations differ.`);
85
- const destination = production.target ?? (production.inline ? identifier : undefined);
86
- if (identifier === undefined || destination !== identifier) continue;
87
- for (const mapping of production.mappings.filter(mapping => mapping.source === identifier)) {
88
- report(mapping.line, diagnosticCodes.eventSourceIdInPayload, `The payload copies '${identifier}', which already identifies the event source.`, production.inline ? 'warning' : 'information');
89
- }
90
- }
91
- }
92
- return issues;
93
- }
94
-
95
- // Record complete, nonempty Markdown fences once. Validation must not scan a suffix
96
- // for every documentation directive, especially while its opener is still being typed.
97
- function nonemptyMarkdownBlocks(lines: string[], fences: boolean[]): Set<number> {
98
- const blocks = new Set<number>();
99
- let opening: number | undefined;
100
- let content = false;
101
- for (let index = 0; index < lines.length; index++) {
102
- if (!fences[index]) continue;
103
- const text = lines[index].trim();
104
- if (opening === undefined) {
105
- opening = index;
106
- content = false;
107
- } else if (text === '```') {
108
- if (content && lines[opening].trim() === '```markdown') blocks.add(opening);
109
- opening = undefined;
110
- } else if (text.length > 0) {
111
- content = true;
112
- }
113
- }
114
- return blocks;
115
- }
package/keyword-docs.ts DELETED
@@ -1,152 +0,0 @@
1
- // Copyright (c) Cratis. All rights reserved.
2
- // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
-
4
- import { eventContextPaths } from './event-context';
5
-
6
- export const keywordDocs: Record<string, string> = {
7
- domain: 'The domain the file belongs to — optional, at most one per file, before everything else.',
8
- import: 'Imports a type from another module by its qualified name — `import Module.Type` — making it available by its short name; or, quoted, other `.play` files by path or glob — `import "Orders/**/*.play"`, relative to this file\'s folder. Written inside a module or feature, a file import places the imported files there: their top level is that module\'s or feature\'s body.',
9
- concept: 'A formalized value type wrapping a primitive. Attributes such as `@pii` travel with every usage, optionally with a `<attribute> reason "..."` line saying why.',
10
- type: 'A composite value type — a named shape built from several properties, referenced by events, commands and other types the same way a concept is.',
11
- reason: 'Records why a concept attribute applies — the purpose, the lawful basis, whose subject the value lives under. Written as `pii reason "..."` in the concept body.',
12
- identifier: 'Marks the command property a runtime resolves the event source id from. At most one per command; without it a new Uuid is generated.',
13
- policy: 'A named authorization rule referenced by commands and queries. Multiple policies AND together.',
14
- persona: 'A named role interacting with the application, with an optional description and its associated policies.',
15
- authentication: 'Declares the identity providers of the application — at most one block per file.',
16
- provider: 'A named identity provider within `authentication`, with free-form `name value` settings.',
17
- description: 'A human-readable description of a module, feature, slice, persona, or command — the first body line, as a quoted single line or a fenced ```text block for multiple lines.',
18
- module: 'The top-level namespace — maps to a bounded context.',
19
- layout: 'A reusable screen template with named slots.',
20
- template: 'Declares the named slots of a layout.',
21
- feature: 'A vertical slice grouping. Features nest arbitrarily deep.',
22
- slice: 'The atomic unit of behavior, aligned with Event Modeling. Has a type and a name.',
23
- event: 'An immutable, past-tense fact. Declare it in a slice or inline with `produces event <Name>` in a command. Inline properties are typed mappings; inline tags belong to the event type.',
24
- documentation: 'Authoring-only event documentation in a fenced ```markdown block. It does not change executable model bytes.',
25
- id: 'Preserves the previous persisted event name after a rename. Leave absent on new events; repeating the current name is redundant.',
26
- command: 'An imperative intent. Declares authorization, validation, and what events it produces — declaratively, or via a full handler.',
27
- query: 'A read-side entry point mapping to a return type, with an optional description, parameters and performer.',
28
- observable: 'Qualifies a query return type as a live read — `query <Name> => observable <ReadModel>` keeps pushing as the read model changes, instead of answering once.',
29
- performer: 'The code that performs a query — a `file <Path>` reference or an inline `csharp`/`sql` block. The query\'s counterpart to a command handler.',
30
- from: 'Fills a query parameter from the query context instead of the caller, as in `filter tenantId TenantId from $context.tenant`.',
31
- projection: 'Declares how events project into a read model, using the embedded Projection Declaration Language (PDL).',
32
- capture: 'Converts external data into events, using the embedded Change Data Capture Language (CDL).',
33
- reaction: 'Behavior that runs when something happens. Lives inside Automation slices. A trigger with no body states intent on its own — `file`/code is optional realization metadata.',
34
- trigger: 'Declares a kind of occurrence a reaction can respond to, and the values it hands the reaction. What makes one occur belongs to whoever provides it, never to the compiler.',
35
- where: 'Narrows which occurrences actually run the reaction.',
36
- contains: 'Text comparison — true when the left string holds the right one anywhere.',
37
- every: 'Runs a reaction on an interval — `every 15 minutes`, `every 1 day`.',
38
- invokes: 'A command a reaction hands on. A command is asked for, not produced — it may still be rejected.',
39
- screen: 'A UI declaration. Supports intent, structure, and layout-with-code levels, or a full file reference.',
40
- constraint: 'A server-side rule enforced in the Chronicle kernel before events are committed.',
41
- authorize: 'References the policies that must all pass for the construct to execute.',
42
- validate: 'Declarative validation rules, or `validate` followed by ```csharp for imperative rules — on commands and concepts.',
43
- produces: 'References a declared event with `produces <Name>`, or declares one inline with `produces event <Name>`. An inline omitted `for` uses the command identifier only when all destinations are the same source; legacy plain omission allocates an identity.',
44
- reads: 'Declares a view consulted by a command or reaction trigger: `reads <View> [as <alias>] [by <value>]`. A reaction `by` names a value taken by its trigger; clock triggers cannot use `by`. Repeated views require unique aliases. Runtime binding is not yet supported for command or reaction reads.',
45
- as: 'Names an instance of a view in a command or reaction trigger reads declaration, for example `reads Account as source by sourceId`.',
46
- handler: 'A fully imperative command implementation — a `file <Path>` reference or an inline `csharp` block, instead of `produces`.',
47
- when: 'Guards a produced event or a capture append with a condition.',
48
- rule: 'Names a predicate. Bare, it states that a constraint exists without expressing what it computes — nothing resolves the name. Optionally followed by an indented `file <Path>` reference or inline `csharp` block giving it a body.',
49
- require: 'A policy condition: `authenticated`, `role "..."`, or `claim "..." matches ...`.',
50
- authenticated: 'Requires an authenticated caller.',
51
- role: 'Requires the caller to have the given role.',
52
- claim: 'Requires a claim on the caller to match a subject or value.',
53
- subject: 'The subject (identity) of the caller.',
54
- data: 'Binds a read model to a screen through a query.',
55
- action: 'Makes a command available as an action on a screen.',
56
- navigate: 'Navigates to a screen, optionally passing a parameter with `by`.',
57
- section: 'A named structural section of a screen.',
58
- table: 'A table widget over a read model or child collection.',
59
- summary: 'A summary widget showing labeled fields.',
60
- column: 'A table column bound to a property.',
61
- field: 'A summary field bound to a property.',
62
- title: 'The display title of a screen or section.',
63
- label: 'The display label of an action, column, or field.',
64
- unique: 'A uniqueness constraint — `unique <property> on <EventType>` or `unique event <EventType>`.',
65
- concurrency: 'The concurrency scope enforced when the command appends events — dimensions: `eventSource`, `sourceType`, `streamType`, `streamId`, `events`.',
66
- eventSource: 'Concurrency dimension — scope the check to the event source id of the command.',
67
- sourceType: 'Concurrency dimension — scope the check to an event source type.',
68
- streamType: 'Concurrency dimension — scope the check to an event stream type.',
69
- streamId: 'Concurrency dimension — scope the check to an event stream id.',
70
- tag: 'Attaches a tag to appended events — a static identifier or string, or a `$context.` expression resolved at append time.',
71
- seed: 'Declares events to seed into the event store per event source id — multiple blocks accumulate.',
72
- for: 'Names the event source of a production or seed group. Inside `produces event`, omission uses the command identifier unless another production targets a different source.',
73
- readmodel: 'Read model state in a specification — `given readmodel` establishes it, `then readmodel` asserts it, `then no readmodel <View> for <key>` asserts keyed absence.',
74
- no: 'A keyed absence assertion: `then no readmodel <View> for <key>`.',
75
- arguments: 'The values supplied to a query asserted by `then query`.',
76
- result: 'One expected result - `then result [exactly]` after `when query`, or a `result` block inside `then query`. Repeat it to assert several results in authored order.',
77
- clock: 'The instant a specification happens at - `given clock "2026-10-05T08:00:00Z"` fixes when everything occurs; `when clock "<instant>"` is the clock reaching it, as the action.',
78
- exactly: 'Requires every property to match, rather than only the ones asserted - on `then readmodel`, `then query` and `then result`.',
79
- file: 'Delegates the implementation to an external file; the Screenplay contract stays visible.',
80
- by: 'Introduces the identifying parameter.',
81
- via: 'Connects screen data to the query that supplies it.',
82
- filter: 'An optional query filter parameter.',
83
- on: 'The event a constraint applies to, the day a schedule narrows to, or a widget interaction such as `on row-click`.',
84
- message: 'The validation message reported when the rule fails.',
85
- matches: 'Matches a value against a regular expression or a named pattern such as `email`.',
86
- all: 'Applies a comparison to every element of a collection.',
87
- max: 'Maximum length or value.',
88
- min: 'Minimum length or value.',
89
- length: 'Constrains the exact length of a value.',
90
- today: 'The current date.',
91
- empty: 'Used with `not empty` — the value must be present.',
92
- not: 'Negates a validation condition, as in `not empty`.',
93
- and: 'Both conditions must hold.',
94
- or: 'Either condition may hold.',
95
- csharp: 'An inline C# block whose opening fence is ```csharp.',
96
- sql: 'An inline SQL block between triple backticks — a query performer written against a relational store.',
97
- typescript: 'An inline TypeScript block between triple backticks.',
98
- react: 'An inline React/TSX block; receives the surrounding data contract as `Props`.',
99
- html: 'An inline static HTML block.',
100
- StateChange: 'Slice type — a command → events flow; something that changes the system.',
101
- StateView: 'Slice type — a query + projection + screen; something that reads the system.',
102
- Automation: 'Slice type — a reaction or reducer; something that runs when something happens.',
103
- Translate: 'Slice type — a capture; converts external data into events.',
104
- Uuid: 'Primitive type — a universally unique identifier.',
105
- String: 'Primitive type — a string of characters.',
106
- Int: 'Primitive type — an integer number.',
107
- Decimal: 'Primitive type — a decimal number.',
108
- Bool: 'Primitive type — true or false.',
109
- Date: 'Primitive type — a date without time.',
110
- DateTime: 'Primitive type — a date and time.',
111
- Enum: 'An enumeration concept with a fixed set of values.',
112
- };
113
-
114
- // What the words of a specification's steps mean there - where 'trigger', 'capture' and 'query' name what the
115
- // scenario exercises rather than declare one.
116
- export const specificationKeywordDocs: Record<string, string> = {
117
- clock: keywordDocs.clock,
118
- trigger: '`when trigger <Trigger>` - an application trigger fires, as the action, with the values on the lines beneath it.',
119
- capture: '`given capture <Capture>` - a record the capture\'s source held before; `when capture <Capture>` - the record it sees now, as the action. The fields go on the lines beneath.',
120
- query: '`when query <Query>` - the query is performed, as the action, with its arguments on the lines beneath; assert what it returns with `then result` or `then no result`. `then query` instead asserts a query after another action.',
121
- result: '`then result [exactly]` - one result the query performed by `when query` returns, in order; `then no result` - it returns nothing.',
122
- };
123
-
124
- export const attributeDocs: Record<string, string> = {
125
- pii: '`@pii` — the value is personally identifiable information; Chronicle manages and erases it automatically wherever the concept is used. Add `pii reason "..."` in the concept body to record why.',
126
- sensitive: '`@sensitive` — the value is sensitive; Chronicle applies its sensitivity rules automatically wherever the concept is used. Add `sensitive reason "..."` in the concept body to record why.',
127
- };
128
-
129
- export const contextVariableDocs: Record<string, string> = {
130
- '$context.occurred': 'When the command or query was received.',
131
- '$context.tenant': 'The tenant the command or query is executing for.',
132
- '$context.command': 'The command being handled, shaped by its `command` declaration.',
133
- '$context.arguments': 'The arguments of the query being performed.',
134
- '$context.causedBy': 'The identity that caused the command or query — `subject`, `name`, `userName`.',
135
- '$context.causedBy.subject': 'The subject of the identity that caused the command or query.',
136
- '$context.causedBy.name': 'The display name of the identity that caused the command or query.',
137
- '$context.causedBy.userName': 'The user name of the identity that caused the command or query.',
138
- '$context.causation': 'What caused the command or query — `type`, `occurred`, `properties`.',
139
- '$context.causation.type': 'What caused the command or query — a command, a reactor, a schedule.',
140
- '$context.identity': 'The caller a decision is made about — `id`, `name`, `userName`, `isAuthenticated`, `roles`, `claims`.',
141
- '$context.identity.id': 'The identifier of the caller from the auth token.',
142
- '$context.identity.name': 'The display name of the caller.',
143
- '$context.identity.userName': 'The user name of the caller.',
144
- '$context.identity.isAuthenticated': 'Whether the caller is authenticated.',
145
- '$context.identity.roles': 'The roles the caller holds.',
146
- '$context.identity.claims': 'The claims the caller carries — `$context.identity.claims.<name>` reads one.',
147
- '$env': 'An environment variable, e.g. `$env.SERVICE_NAME`.',
148
- '$secrets': 'An encrypted secret resolved at runtime, e.g. `$secrets.azureAdClientId` — stays symbolic in the compiled tree.',
149
- '$strings': 'A localized string resolved from the `.strings` file of the active locale, e.g. `$strings.invoices.title`.',
150
- // Every $eventContext path the event-context catalog lists, for projections.
151
- ...Object.fromEntries(eventContextPaths.map((path) => [`$eventContext.${path.path}`, path.description])),
152
- };
package/language.ts DELETED
@@ -1,212 +0,0 @@
1
- // Copyright (c) Cratis. All rights reserved.
2
- // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
-
4
- import type { languages } from 'monaco-editor';
5
-
6
- export type Monaco = typeof import('monaco-editor');
7
-
8
- export const languageId = 'screenplay';
9
-
10
- export const languageExtensionPoint: languages.ILanguageExtensionPoint = {
11
- id: languageId,
12
- extensions: ['.play'],
13
- aliases: ['Screenplay', 'screenplay', 'play'],
14
- mimetypes: ['text/x-screenplay'],
15
- };
16
-
17
- // Every word the parser dispatches on at the top level, inside a module, or inside a slice.
18
- // `for_LanguageService.when_comparing_keywords_against_the_parsers` derives that set from
19
- // ScreenplayParser and SliceParser and fails when this list has drifted from it, so a construct
20
- // added to the compiler cannot silently lose its highlighting and completion.
21
- export const constructKeywords = [
22
- 'domain',
23
- 'import',
24
- 'concept',
25
- 'type',
26
- 'policy',
27
- 'persona',
28
- 'authentication',
29
- 'module',
30
- 'layout',
31
- 'theme',
32
- 'ui',
33
- 'feature',
34
- 'slice',
35
- 'event',
36
- 'command',
37
- 'query',
38
- 'projection',
39
- 'capture',
40
- 'reaction',
41
- 'reducer',
42
- 'trigger',
43
- 'screen',
44
- 'dialog',
45
- 'form',
46
- 'contribute',
47
- 'constraint',
48
- 'specification',
49
- 'seed',
50
- 'behavior',
51
- ];
52
-
53
- export const clauseKeywords = [
54
- 'description',
55
- 'template',
56
- 'profile',
57
- 'require',
58
- 'authenticated',
59
- 'role',
60
- 'claim',
61
- 'subject',
62
- 'authorize',
63
- 'validate',
64
- 'produces',
65
- 'reads', // A clause in command bodies and reaction trigger bodies; @reads remains a value.
66
- 'as',
67
- 'handler',
68
- 'performer',
69
- 'observable',
70
- 'identifier',
71
- 'reason',
72
- 'from',
73
- 'when',
74
- 'given',
75
- 'then',
76
- 'arguments',
77
- 'result',
78
- 'clock', // A specification step - 'given clock' and 'when clock' state an instant.
79
- 'exactly',
80
- 'error',
81
- 'message',
82
- 'not',
83
- 'empty',
84
- 'rule',
85
- 'matches',
86
- 'all',
87
- 'max',
88
- 'min',
89
- 'length',
90
- 'today',
91
- 'true',
92
- 'false',
93
- 'and',
94
- 'or',
95
- 'by',
96
- 'filter',
97
- 'data',
98
- 'via',
99
- 'action',
100
- 'navigate',
101
- 'to',
102
- 'label',
103
- 'section',
104
- 'table',
105
- 'summary',
106
- 'title',
107
- 'column',
108
- 'field',
109
- 'on',
110
- 'unique',
111
- 'file',
112
- 'concurrency',
113
- 'eventSource',
114
- 'sourceType',
115
- 'streamType',
116
- 'streamId',
117
- 'tag',
118
- 'for',
119
- 'readmodel',
120
- 'no',
121
- 'when',
122
- 'every',
123
- 'at',
124
- 'where',
125
- 'invokes',
126
- 'contains',
127
- 'starts',
128
- 'with',
129
- 'provider',
130
- // Interaction: the words a behavior body uses. The built-in interaction kinds ('click', 'submit', and
131
- // friends) are only reserved inside an `on` clause, so they are clause words rather than constructs -
132
- // an identifier of the same name elsewhere in a document remains an identifier.
133
- 'uses',
134
- 'parameter',
135
- 'order',
136
- 'execute',
137
- 'open',
138
- 'close',
139
- 'refresh',
140
- 'set',
141
- 'notify',
142
- 'confirm',
143
- 'raise',
144
- 'interval',
145
- 'success',
146
- 'failure',
147
- 'click',
148
- 'double',
149
- 'select',
150
- 'submit',
151
- 'change',
152
- 'load',
153
- 'unload',
154
- 'enter',
155
- 'leave',
156
- 'info',
157
- 'warning',
158
- ];
159
-
160
- export const codeBlockTags = ['csharp', 'typescript', 'react', 'html', 'sql'];
161
-
162
- // The roots a `$context.` path can start with — the members of CommandContext and QueryContext.
163
- export const contextRoots = [
164
- 'command',
165
- 'arguments',
166
- 'tenant',
167
- 'causedBy',
168
- 'causation',
169
- 'occurred',
170
- 'identity',
171
- ];
172
-
173
- export const causedByProperties = ['subject', 'name', 'userName'];
174
-
175
- // The properties a `$context.identity.` path can name — the members of Identity. Everything after
176
- // `claims.` is the name of a claim rather than a member, so it is never checked.
177
- export const identityProperties = ['id', 'name', 'userName', 'isAuthenticated', 'roles', 'claims'];
178
-
179
- export const sliceTypes = ['StateChange', 'StateView', 'Automation', 'Translate'];
180
-
181
- export const primitiveTypes = ['Uuid', 'String', 'Int', 'Decimal', 'Bool', 'Date', 'DateTime'];
182
-
183
- export const conceptAttributes = ['@pii', '@sensitive'];
184
-
185
- export const languageConfiguration: languages.LanguageConfiguration = {
186
- comments: {
187
- lineComment: '//',
188
- },
189
- brackets: [
190
- ['(', ')'],
191
- ['[', ']'],
192
- ],
193
- autoClosingPairs: [
194
- { open: '(', close: ')' },
195
- { open: '[', close: ']' },
196
- { open: '"', close: '"' },
197
- ],
198
- surroundingPairs: [
199
- { open: '(', close: ')' },
200
- { open: '[', close: ']' },
201
- { open: '"', close: '"' },
202
- ],
203
- folding: {
204
- offSide: true,
205
- },
206
- indentationRules: {
207
- increaseIndentPattern:
208
- /^\s*(module|feature|slice|policy|persona|authentication|provider|event|command|query|type|screen|projection|capture|reaction|trigger|constraint|specification|layout|template|validate|produces|handler|performer|rule|section|concurrency|seed|for|when|then|arguments|result|every|at)\b.*$/,
209
- // Dedents are always explicit in an offside language — never auto-dedent.
210
- decreaseIndentPattern: /(?!)/,
211
- },
212
- };
@@ -1,32 +0,0 @@
1
- // Copyright (c) Cratis. All rights reserved.
2
- // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
-
4
- import { DestinationHint } from './DestinationHint';
5
- import { eventAnalysisSource } from './event-analysis-source';
6
- import { CommandSymbol, scanDocument } from './symbols';
7
-
8
- export function productionDestinations(command: CommandSymbol): { identifier?: string; mixed: boolean } {
9
- const identifiers = command.properties.filter(property => property.isIdentifier && !property.type.includes('?') && !property.type.includes('[]'));
10
- const identifier = identifiers.length === 1 ? identifiers[0].name : undefined;
11
- const productions = command.produces ?? [];
12
- const mixed = productions.some(production => production.target !== undefined && production.target !== identifier) ||
13
- (productions.some(production => production.inline && production.target === undefined) &&
14
- productions.some(production => !production.inline && production.target === undefined));
15
- return { identifier, mixed };
16
- }
17
-
18
- // Shared by both editor adapters. Never suggest that a legacy allocated source is the command identifier.
19
- export function destinationHints(lines: string[]): DestinationHint[] {
20
- const source = eventAnalysisSource(lines);
21
- return scanDocument(source).commands.flatMap(command => {
22
- const { identifier, mixed } = productionDestinations(command);
23
- if (mixed || command.productionHeaders?.length !== command.produces?.length) return [];
24
- const hasPromotedDestination = command.produces?.some(sibling => sibling.target !== undefined || sibling.inline);
25
- return (command.produces ?? []).flatMap(production => {
26
- if (production.target !== undefined || (production.inline && (identifier === undefined || /\bgeneration\b/.test(source[production.line])))) return [];
27
- // A sibling destination can promote the command default in the legacy binder.
28
- if (!production.inline && hasPromotedDestination) return [];
29
- return [{ line: production.line, column: source[production.line].length + 1, label: production.inline ? `for ${identifier}` : 'for <new event source>' }];
30
- });
31
- });
32
- }
@@ -1,42 +0,0 @@
1
- // Copyright (c) Cratis. All rights reserved.
2
- // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
-
4
- import type { languages } from 'monaco-editor';
5
-
6
- export type MonarchTokenRules = languages.IMonarchLanguage['tokenizer'][string];
7
-
8
- export interface SubLanguageCompletion {
9
- label: string;
10
- insertText: string;
11
- documentation: string;
12
- }
13
-
14
- export interface SubLanguageDefinition {
15
- tokens: MonarchTokenRules;
16
- completions?: SubLanguageCompletion[];
17
- hovers?: Record<string, string>;
18
- }
19
-
20
- export interface SubLanguage extends SubLanguageDefinition {
21
- keyword: string;
22
- }
23
-
24
- const subLanguages = new Map<string, SubLanguage>();
25
- const listeners = new Set<() => void>();
26
-
27
- export function registerSubLanguage(keyword: string, definition: SubLanguageDefinition): void {
28
- subLanguages.set(keyword, { keyword, ...definition });
29
- listeners.forEach((listener) => listener());
30
- }
31
-
32
- export function getSubLanguages(): SubLanguage[] {
33
- return [...subLanguages.values()];
34
- }
35
-
36
- export function getSubLanguage(keyword: string): SubLanguage | undefined {
37
- return subLanguages.get(keyword);
38
- }
39
-
40
- export function onSubLanguagesChanged(listener: () => void): void {
41
- listeners.add(listener);
42
- }