@cratis/screenplay-language 4.51.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
@@ -0,0 +1,677 @@
1
+ // sub-languages/capture/language.ts
2
+ var languageId = "cdl";
3
+ var KEYWORDS = [
4
+ "capture",
5
+ "source",
6
+ "key",
7
+ "map",
8
+ "append",
9
+ "when",
10
+ "nested",
11
+ "children",
12
+ "identified",
13
+ "by",
14
+ "api",
15
+ "webhook",
16
+ "message",
17
+ "route",
18
+ "poll",
19
+ "path",
20
+ "topic",
21
+ "from",
22
+ "to",
23
+ "or",
24
+ "and",
25
+ "added",
26
+ "removed",
27
+ "translate",
28
+ "split"
29
+ ];
30
+ var BUILTINS = [
31
+ "$context",
32
+ "$previous",
33
+ "$env"
34
+ ];
35
+ var OPERATORS = ["=", "=>", "."];
36
+ var languageConfiguration = {
37
+ comments: {
38
+ lineComment: "#"
39
+ },
40
+ brackets: [
41
+ ["{", "}"],
42
+ ["[", "]"],
43
+ ["(", ")"]
44
+ ],
45
+ autoClosingPairs: [
46
+ { open: "{", close: "}" },
47
+ { open: "[", close: "]" },
48
+ { open: "(", close: ")" },
49
+ { open: '"', close: '"' },
50
+ { open: "'", close: "'" },
51
+ { open: "`", close: "`" }
52
+ ],
53
+ surroundingPairs: [
54
+ { open: "{", close: "}" },
55
+ { open: "[", close: "]" },
56
+ { open: "(", close: ")" },
57
+ { open: '"', close: '"' },
58
+ { open: "'", close: "'" },
59
+ { open: "`", close: "`" }
60
+ ],
61
+ indentationRules: {
62
+ increaseIndentPattern: /^.*(\bcapture\b\s+\S+|\bsource\b(?:\s+\w+)?|\bmap\b|\bappend\b\s+\S+|\bnested\b\s+\S+|\bchildren\b\s+\S+.*|\btranslate\b|\bsplit\b.*)\s*$/,
63
+ decreaseIndentPattern: /^.*\}.*$/
64
+ },
65
+ folding: {
66
+ offSide: true,
67
+ markers: {
68
+ start: /^\s*(capture|source|map|append|nested|children|translate|split)/,
69
+ end: /^\s*$/
70
+ }
71
+ },
72
+ wordPattern: /[$]?[a-zA-Z_][\w$-]*/
73
+ };
74
+ var monarchLanguage = {
75
+ defaultToken: "",
76
+ tokenPostfix: ".cdl",
77
+ keywords: KEYWORDS,
78
+ builtins: BUILTINS,
79
+ operators: OPERATORS,
80
+ symbols: /[=><!~?:&|+\-*/^%]+/,
81
+ escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
82
+ tokenizer: {
83
+ root: [
84
+ { include: "@whitespace" },
85
+ [/`/, { token: "string.template", next: "@templateString" }],
86
+ [/\$\.(?:[a-zA-Z_]\w*(?:\.[a-zA-Z_]\w*)*)?/, "variable"],
87
+ [/\$previous(?:\.[a-zA-Z_]\w*(?:\.[a-zA-Z_]\w*)*)?/, "variable.predefined"],
88
+ [/\$context(?:\.(?:occurred|eventSourceId))?/, "variable.predefined"],
89
+ [/\$env(?:\.[A-Z_][A-Z0-9_]*)?/, "variable.predefined"],
90
+ [/@[a-zA-Z_$][\w$]*/, "identifier.escape"],
91
+ [
92
+ /[A-Z][a-zA-Z_$][\w$]*/,
93
+ {
94
+ cases: {
95
+ "@keywords": "invalid",
96
+ "@default": "identifier"
97
+ }
98
+ }
99
+ ],
100
+ [
101
+ /[a-z_$][\w$]*/,
102
+ {
103
+ cases: {
104
+ "@keywords": "keyword",
105
+ "@builtins": "variable.predefined",
106
+ "@default": "identifier"
107
+ }
108
+ }
109
+ ],
110
+ [/[{}()[\]]/, "@brackets"],
111
+ [/=>/, "operator.arrow"],
112
+ [
113
+ /@symbols/,
114
+ {
115
+ cases: {
116
+ "@operators": "operator",
117
+ "@default": ""
118
+ }
119
+ }
120
+ ],
121
+ [/\d*\.\d+([eE][-+]?\d+)?/, "number.float"],
122
+ [/0[xX][0-9a-fA-F]+/, "number.hex"],
123
+ [/\d+/, "number"],
124
+ [/[;,.]/, "delimiter"],
125
+ [/"([^"\\]|\\.)*$/, "string.invalid"],
126
+ [/"/, { token: "string.quote", next: "@string" }]
127
+ ],
128
+ whitespace: [
129
+ [/[ \t\r\n]+/, ""],
130
+ [/#.*$/, "comment"]
131
+ ],
132
+ templateString: [
133
+ [/\$\{/, { token: "delimiter.bracket", next: "@templateExpression" }],
134
+ [/[^\\`$]+/, "string.template"],
135
+ [/@escapes/, "string.template.escape"],
136
+ [/\\./, "string.template.escape.invalid"],
137
+ [/`/, { token: "string.template", next: "@pop" }]
138
+ ],
139
+ templateExpression: [
140
+ [/\}/, { token: "delimiter.bracket", next: "@pop" }],
141
+ { include: "@root" }
142
+ ],
143
+ string: [
144
+ [/[^\\"]+/, "string"],
145
+ [/@escapes/, "string.escape"],
146
+ [/\\./, "string.escape.invalid"],
147
+ [/"/, { token: "string.quote", next: "@pop" }]
148
+ ]
149
+ }
150
+ };
151
+
152
+ // sub-languages/capture/CompletionProvider.ts
153
+ import { languages } from "monaco-editor";
154
+ var commonPropertyPaths = [
155
+ "id",
156
+ "status",
157
+ "firstName",
158
+ "lastName",
159
+ "fullName",
160
+ "address.street",
161
+ "address.city",
162
+ "lineItems",
163
+ "lineItems.quantity",
164
+ "lineNumber",
165
+ "quantity"
166
+ ];
167
+ var CompletionProvider = class {
168
+ triggerCharacters = [".", " ", "=", "$"];
169
+ provideCompletionItems(model, position) {
170
+ const context = this.buildContext(model, position);
171
+ const suggestions = [];
172
+ if (context.lineNumber === 1) {
173
+ this.addCaptureLineCompletions(suggestions, context);
174
+ } else if (this.isAfterKeyword(context, "capture")) {
175
+ this.addCaptureNameCompletions(suggestions, context);
176
+ } else if (this.isAfterKeyword(context, "source")) {
177
+ this.addSourceTypeCompletions(suggestions, context);
178
+ } else if (this.isAfterAppendKeyword(context)) {
179
+ this.addAppendNameCompletions(suggestions, context);
180
+ } else if (this.isAfterWhenKeyword(context)) {
181
+ this.addWhenCompletions(suggestions, context);
182
+ } else if (this.isAfterWhenFrom(context)) {
183
+ this.addFromValueCompletions(suggestions, context);
184
+ } else if (this.isAfterWhenTo(context)) {
185
+ this.addToValueCompletions(suggestions, context);
186
+ } else if (this.isAfterContextPrefix(context, "$.")) {
187
+ this.addPathCompletions(suggestions, context, "$.");
188
+ } else if (this.isAfterContextPrefix(context, "$previous.")) {
189
+ this.addPathCompletions(suggestions, context, "$previous.");
190
+ } else if (this.isAfterContextPrefix(context, "$context.")) {
191
+ this.addContextCompletions(suggestions, context);
192
+ } else if (this.isAfterContextPrefix(context, "$env.")) {
193
+ this.addEnvironmentCompletions(suggestions, context);
194
+ } else if (this.isAfterAssignment(context)) {
195
+ this.addAssignmentValueCompletions(suggestions, context);
196
+ } else if ((this.isStartOfLine(context) || this.isAfterIndent(context)) && context.indentLevel === 1) {
197
+ this.addTopLevelStatementCompletions(suggestions, context);
198
+ } else if ((this.isStartOfLine(context) || this.isAfterIndent(context)) && context.indentLevel >= 2) {
199
+ this.addSourceBlockCompletions(suggestions, context, this.getCurrentSourceType(model, position.lineNumber));
200
+ }
201
+ return { suggestions };
202
+ }
203
+ buildContext(model, position) {
204
+ const lineContent = model.getLineContent(position.lineNumber);
205
+ const textBeforeCursor = lineContent.substring(0, position.column - 1);
206
+ const word = model.getWordUntilPosition(position);
207
+ return {
208
+ textBeforeCursor,
209
+ currentWord: word.word || "",
210
+ indentLevel: this.getIndentLevel(textBeforeCursor),
211
+ lineNumber: position.lineNumber,
212
+ wordStartColumn: word.startColumn,
213
+ wordEndColumn: word.endColumn
214
+ };
215
+ }
216
+ getIndentLevel(text) {
217
+ const match = text.match(/^(\s*)/);
218
+ return match ? Math.floor(match[1].length / 2) : 0;
219
+ }
220
+ isStartOfLine(context) {
221
+ return context.textBeforeCursor.trim() === "";
222
+ }
223
+ isAfterIndent(context) {
224
+ return /^\s+$/.test(context.textBeforeCursor);
225
+ }
226
+ isAfterKeyword(context, keyword) {
227
+ const pattern = new RegExp(`\\b${keyword}\\s+\\w*$`);
228
+ return pattern.test(context.textBeforeCursor);
229
+ }
230
+ isAfterAppendKeyword(context) {
231
+ return /\bappend\s+[\w.]*$/.test(context.textBeforeCursor);
232
+ }
233
+ isAfterWhenKeyword(context) {
234
+ return /\bwhen\s+[\w.]*$/.test(context.textBeforeCursor);
235
+ }
236
+ isAfterWhenFrom(context) {
237
+ return /\bwhen\s+[\w.]+\s+from\s+[^\s]*$/.test(context.textBeforeCursor);
238
+ }
239
+ isAfterWhenTo(context) {
240
+ return /\bwhen\s+[\w.]+\s+from\s+\S+\s+to\s+[^\s]*$/.test(context.textBeforeCursor);
241
+ }
242
+ isAfterAssignment(context) {
243
+ return /=\s*([$\w.]*)$/.test(context.textBeforeCursor);
244
+ }
245
+ isAfterContextPrefix(context, prefix) {
246
+ return context.textBeforeCursor.endsWith(prefix);
247
+ }
248
+ addCaptureLineCompletions(suggestions, context) {
249
+ const trimmed = context.textBeforeCursor.trim();
250
+ if (trimmed === "" || "capture".startsWith(trimmed)) {
251
+ suggestions.push({
252
+ label: "capture",
253
+ kind: languages.CompletionItemKind.Keyword,
254
+ insertText: "capture ",
255
+ documentation: "Define a capture declaration",
256
+ detail: "capture <Name>",
257
+ range: this.getRangeForWord(context)
258
+ });
259
+ }
260
+ if (trimmed.startsWith("capture ")) {
261
+ this.addCaptureNameCompletions(suggestions, context);
262
+ }
263
+ }
264
+ addCaptureNameCompletions(suggestions, context) {
265
+ suggestions.push({
266
+ label: "CaptureDefinition",
267
+ kind: languages.CompletionItemKind.Class,
268
+ insertText: "CaptureDefinition",
269
+ documentation: "A descriptive name for this capture declaration",
270
+ detail: "Capture name",
271
+ range: this.getRangeForWord(context)
272
+ });
273
+ }
274
+ addSourceTypeCompletions(suggestions, context) {
275
+ [
276
+ { label: "api", detail: "source api", documentation: "Capture data by polling an HTTP API" },
277
+ { label: "webhook", detail: "source webhook", documentation: "Capture data from incoming webhook requests" },
278
+ { label: "message", detail: "source message", documentation: "Capture data from a message topic" }
279
+ ].forEach((source) => {
280
+ suggestions.push({
281
+ label: source.label,
282
+ kind: languages.CompletionItemKind.Keyword,
283
+ insertText: source.label,
284
+ documentation: source.documentation,
285
+ detail: source.detail,
286
+ range: this.getRangeForWord(context)
287
+ });
288
+ });
289
+ }
290
+ // Per source type — no `auth`/`bearer`/`url`: an API source references a named
291
+ // External Service (`api <ServiceName>`) for base URL and auth; a webhook source's
292
+ // authentication is configured on the source builder, not in CDL text.
293
+ addSourceBlockCompletions(suggestions, context, sourceType) {
294
+ const options = {
295
+ api: [
296
+ { label: "api", detail: "api <ServiceName>", documentation: "References a configured External Service by name for the base URL and authentication" },
297
+ { label: "route", detail: "route <path>", documentation: "Optional path appended to the External Service base URL; if omitted, the base URL is used as-is" },
298
+ { label: "poll", detail: "poll <interval>", documentation: "The polling interval, for example 5m" }
299
+ ],
300
+ webhook: [
301
+ { label: "path", detail: "path <route>", documentation: "The inbound path this webhook listens on" }
302
+ ],
303
+ message: [
304
+ { label: "topic", detail: "topic <name>", documentation: "The topic or subject to subscribe to" }
305
+ ]
306
+ };
307
+ (sourceType ? options[sourceType] ?? [] : []).forEach((option) => {
308
+ suggestions.push({
309
+ label: option.label,
310
+ kind: languages.CompletionItemKind.Keyword,
311
+ insertText: `${option.label} `,
312
+ documentation: option.documentation,
313
+ detail: option.detail,
314
+ range: this.getRangeForWord(context)
315
+ });
316
+ });
317
+ }
318
+ addTopLevelStatementCompletions(suggestions, context) {
319
+ [
320
+ { label: "key", insertText: "key ", detail: "key <property>", documentation: "Identify the captured entity" },
321
+ { label: "map", insertText: "map", detail: "map", documentation: "Map captured fields into a normalized shape" },
322
+ { label: "append", insertText: "append ", detail: "append <EventName>", documentation: "Append an event when a condition matches" },
323
+ { label: "nested", insertText: "nested ", detail: "nested <property>", documentation: "Create a nested mapping scope" },
324
+ { label: "children", insertText: "children ", detail: "children <collection> identified by <property>", documentation: "Handle child collections independently" }
325
+ ].forEach((statement) => {
326
+ suggestions.push({
327
+ label: statement.label,
328
+ kind: languages.CompletionItemKind.Keyword,
329
+ insertText: statement.insertText,
330
+ documentation: statement.documentation,
331
+ detail: statement.detail,
332
+ range: this.getRangeForWord(context)
333
+ });
334
+ });
335
+ }
336
+ addAppendNameCompletions(suggestions, context) {
337
+ suggestions.push({
338
+ label: "ItemChanged",
339
+ kind: languages.CompletionItemKind.Class,
340
+ insertText: "ItemChanged",
341
+ documentation: "A generic event name for the appended event",
342
+ detail: "Event name",
343
+ range: this.getRangeForWord(context)
344
+ });
345
+ }
346
+ addWhenCompletions(suggestions, context) {
347
+ [
348
+ { label: "added", insertText: "added", detail: "when added", documentation: "Append when a child item was added" },
349
+ { label: "removed", insertText: "removed", detail: "when removed", documentation: "Append when a child item was removed" },
350
+ { label: "status", insertText: "status", detail: "when <property>", documentation: "Append when a property changed" },
351
+ { label: "status transition", insertText: "status from inactive to active", detail: "when <property> from <value> to <value>", documentation: "Append when a property changed between two values" },
352
+ { label: "quantity", insertText: "quantity", detail: "when <property>", documentation: "Append when a property changed" },
353
+ { label: "lineNumber", insertText: "lineNumber", detail: "when <property>", documentation: "Append when a specific property changed" }
354
+ ].forEach((option) => {
355
+ suggestions.push({
356
+ label: option.label,
357
+ kind: languages.CompletionItemKind.Keyword,
358
+ insertText: option.insertText,
359
+ documentation: option.documentation,
360
+ detail: option.detail,
361
+ range: this.getRangeForWord(context)
362
+ });
363
+ });
364
+ }
365
+ addFromValueCompletions(suggestions, context) {
366
+ [
367
+ { label: "*", insertText: "*", detail: "Wildcard", documentation: "Match any previous value" },
368
+ { label: "inactive", insertText: "inactive", detail: "Common value", documentation: "A common previous state value" },
369
+ { label: "active", insertText: "active", detail: "Common value", documentation: "A common previous state value" },
370
+ { label: "true", insertText: "true", detail: "Boolean value", documentation: "Boolean true" },
371
+ { label: "false", insertText: "false", detail: "Boolean value", documentation: "Boolean false" }
372
+ ].forEach((option) => {
373
+ suggestions.push({
374
+ label: option.label,
375
+ kind: languages.CompletionItemKind.Value,
376
+ insertText: option.insertText,
377
+ documentation: option.documentation,
378
+ detail: option.detail,
379
+ range: this.getRangeForWord(context)
380
+ });
381
+ });
382
+ }
383
+ addToValueCompletions(suggestions, context) {
384
+ ["active", "inactive", "pending", "true", "false"].forEach((value) => {
385
+ suggestions.push({
386
+ label: value,
387
+ kind: languages.CompletionItemKind.Value,
388
+ insertText: value,
389
+ documentation: `Common target value: ${value}`,
390
+ detail: "Target value",
391
+ range: this.getRangeForWord(context)
392
+ });
393
+ });
394
+ }
395
+ addAssignmentValueCompletions(suggestions, context) {
396
+ [
397
+ { label: "$.", insertText: "$.", detail: "Current captured value", documentation: "Reference the current captured payload" },
398
+ { label: "$previous.", insertText: "$previous.", detail: "Previous captured value", documentation: "Reference the previous state of the payload" },
399
+ { label: "$context.occurred", insertText: "$context.occurred", detail: "Occurred timestamp", documentation: "When the capture source produced the current data" },
400
+ { label: "$context.eventSourceId", insertText: "$context.eventSourceId", detail: "Event source identifier", documentation: "The resolved event source identifier for the append operation" },
401
+ { label: "$env.", insertText: "$env.", detail: "Environment variable", documentation: "Read an environment variable" }
402
+ ].forEach((option) => {
403
+ suggestions.push({
404
+ label: option.label,
405
+ kind: languages.CompletionItemKind.Variable,
406
+ insertText: option.insertText,
407
+ documentation: option.documentation,
408
+ detail: option.detail,
409
+ range: this.getRangeForWord(context)
410
+ });
411
+ });
412
+ }
413
+ addPathCompletions(suggestions, context, prefix) {
414
+ commonPropertyPaths.forEach((path) => {
415
+ suggestions.push({
416
+ label: path,
417
+ kind: languages.CompletionItemKind.Property,
418
+ insertText: `${prefix}${path}`,
419
+ documentation: `Common property path: ${prefix}${path}`,
420
+ detail: prefix === "$." ? "Current value path" : "Previous value path",
421
+ range: this.getRangeForWord(context)
422
+ });
423
+ });
424
+ }
425
+ addContextCompletions(suggestions, context) {
426
+ [
427
+ { label: "occurred", insertText: "$context.occurred", detail: "When the event occurred", documentation: "Timestamp for when the append event happened" },
428
+ { label: "eventSourceId", insertText: "$context.eventSourceId", detail: "Event source identifier", documentation: "The event source identifier used for the appended event" }
429
+ ].forEach((option) => {
430
+ suggestions.push({
431
+ label: option.label,
432
+ kind: languages.CompletionItemKind.Property,
433
+ insertText: option.insertText,
434
+ documentation: option.documentation,
435
+ detail: option.detail,
436
+ range: this.getRangeForWord(context)
437
+ });
438
+ });
439
+ }
440
+ addEnvironmentCompletions(suggestions, context) {
441
+ suggestions.push({
442
+ label: "API_TOKEN",
443
+ kind: languages.CompletionItemKind.Variable,
444
+ insertText: "$env.API_TOKEN",
445
+ documentation: "Placeholder environment variable reference",
446
+ detail: "Environment variable",
447
+ range: this.getRangeForWord(context)
448
+ });
449
+ }
450
+ getCurrentSourceType(model, lineNumber) {
451
+ for (let index = lineNumber; index >= 1; index--) {
452
+ const line = model.getLineContent(index).trim();
453
+ const match = line.match(/^source\s+(api|webhook|message)\b/);
454
+ if (match) {
455
+ return match[1];
456
+ }
457
+ }
458
+ return null;
459
+ }
460
+ getRangeForWord(context) {
461
+ return {
462
+ startLineNumber: context.lineNumber,
463
+ endLineNumber: context.lineNumber,
464
+ startColumn: context.wordStartColumn,
465
+ endColumn: context.wordEndColumn
466
+ };
467
+ }
468
+ };
469
+
470
+ // sub-languages/capture/HoverProvider.ts
471
+ var HoverProvider = class {
472
+ provideHover(model, position) {
473
+ const token = this.getTokenAtPosition(model, position);
474
+ if (!token) {
475
+ return null;
476
+ }
477
+ const keywordInfo = this.getKeywordInfo(token.word);
478
+ if (keywordInfo) {
479
+ return {
480
+ contents: [{ value: keywordInfo }],
481
+ range: token.range
482
+ };
483
+ }
484
+ const expressionInfo = this.getExpressionInfo(token.word);
485
+ if (expressionInfo) {
486
+ return {
487
+ contents: [{ value: expressionInfo }],
488
+ range: token.range
489
+ };
490
+ }
491
+ return null;
492
+ }
493
+ getTokenAtPosition(model, position) {
494
+ const lineContent = model.getLineContent(position.lineNumber);
495
+ const tokens = [...lineContent.matchAll(/\$context|\$previous|\$env|[a-zA-Z_][\w-]*/g)];
496
+ const column = position.column - 1;
497
+ for (const token of tokens) {
498
+ const startIndex = token.index ?? 0;
499
+ const endIndex = startIndex + token[0].length;
500
+ if (column >= startIndex && column <= endIndex) {
501
+ return {
502
+ word: token[0],
503
+ range: {
504
+ startLineNumber: position.lineNumber,
505
+ endLineNumber: position.lineNumber,
506
+ startColumn: startIndex + 1,
507
+ endColumn: endIndex + 1
508
+ }
509
+ };
510
+ }
511
+ }
512
+ return null;
513
+ }
514
+ // No `auth`/`bearer`/`url` — removed with the grammar. `api`, `route`, `path`, and
515
+ // `topic` reflect the current source-property meanings (see grammar.md).
516
+ getKeywordInfo(word) {
517
+ const keywords = {
518
+ capture: "**capture** *<Name>*\n\nDeclares a capture and gives it a unique name.",
519
+ source: "**source** *<type>*\n\nDefines where the capture reads input from.",
520
+ key: "**key** *<property>*\n\nSelects the property used to identify each captured item.",
521
+ map: "**map**\n\nMaps source fields into a normalized shape for later append blocks.",
522
+ append: "**append** *<EventName>*\n\nDeclares an event to append when the `when` clause matches.",
523
+ when: "**when** *<condition>*\n\nSpecifies when an append block should fire.",
524
+ nested: "**nested** *<property>*\n\nCreates a nested mapping scope for an object property.",
525
+ children: "**children** *<collection>* **identified by** *<property>*\n\nCreates a scope for child collection items.",
526
+ identified: "**identified**\n\nUsed with `children` to declare how child items are identified.",
527
+ by: "**by**\n\nUsed in `children ... identified by`, `split ... by`, and similar clauses.",
528
+ api: "**api**\n\nAs a source type (`source api`): polls an HTTP API for changes.\n\nAs a source property (`api <ServiceName>`): references a configured External Service by name for the base URL and authentication.",
529
+ webhook: "**webhook**\n\nA source type for receiving webhook payloads.",
530
+ message: "**message**\n\nA source type for consuming messages from a topic.",
531
+ route: "**route** *<path>*\n\nOptional path appended to an API source's External Service base URL. If omitted, the base URL is used as-is.",
532
+ poll: "**poll** *<interval>*\n\nSets the polling interval for an API source.",
533
+ path: "**path** *<route>*\n\nThe inbound path a webhook source listens on.",
534
+ topic: "**topic** *<name>*\n\nConfigures the topic for a message source.",
535
+ from: "**from** *<value>*\n\nUsed in a `when` clause to match the previous value.",
536
+ to: "**to** *<value>*\n\nUsed in a `when` clause to match the new value.",
537
+ or: "**or**\n\nCombines multiple `when` conditions.",
538
+ and: "**and**\n\nCombines multiple `when` conditions that must all match.",
539
+ added: "**added**\n\nMatches when a child item was added.",
540
+ removed: "**removed**\n\nMatches when a child item was removed.",
541
+ translate: "**translate**\n\nMaps source values to new values inside a `map` block.",
542
+ split: "**split** *<value>* **by** *<separator>*\n\nSplits a string into multiple mapped fields."
543
+ };
544
+ return keywords[word] || null;
545
+ }
546
+ getExpressionInfo(word) {
547
+ const expressions = {
548
+ "$context": "**$context**\n\nCapture execution context.\n\n**Properties:**\n- `occurred` - When the current event should be considered to have occurred\n- `eventSourceId` - The resolved event source identifier",
549
+ "$previous": "**$previous**\n\nThe previous state for the captured item. Use dot notation such as `$previous.status`.",
550
+ "$env": "**$env**\n\nEnvironment variables. Use dot notation such as `$env.API_TOKEN`."
551
+ };
552
+ return expressions[word] || null;
553
+ }
554
+ };
555
+
556
+ // sub-languages/capture/Validator.ts
557
+ var Validator = class {
558
+ validate(lines) {
559
+ const issues = [];
560
+ let firstNonEmptyLineIndex = -1;
561
+ let firstLine = "";
562
+ for (let index = 0; index < lines.length; index++) {
563
+ const trimmed = lines[index].trim();
564
+ if (trimmed && !trimmed.startsWith("#")) {
565
+ firstNonEmptyLineIndex = index;
566
+ firstLine = trimmed;
567
+ break;
568
+ }
569
+ }
570
+ if (!firstLine) {
571
+ return issues;
572
+ }
573
+ const captureMatch = firstLine.match(/^capture\s+([\w.]+)\s*$/);
574
+ if (!captureMatch) {
575
+ issues.push(this.error(firstNonEmptyLineIndex, 1, firstLine.length + 1, 'Capture definition must start with "capture <Name>"'));
576
+ return issues;
577
+ }
578
+ const meaningfulLines = lines.map((line, index) => ({
579
+ line,
580
+ trimmed: line.trim(),
581
+ lineNumber: index,
582
+ indent: line.search(/\S/)
583
+ })).filter((entry) => entry.trimmed && !entry.trimmed.startsWith("#"));
584
+ const hasSource = meaningfulLines.some((entry) => entry.trimmed.startsWith("source "));
585
+ if (!hasSource) {
586
+ issues.push(this.error(firstNonEmptyLineIndex, 1, firstLine.length + 1, 'Capture definition must include a "source" block'));
587
+ }
588
+ const hasKey = meaningfulLines.some((entry) => entry.trimmed.startsWith("key "));
589
+ if (!hasKey) {
590
+ issues.push(this.error(firstNonEmptyLineIndex, 1, firstLine.length + 1, 'Capture definition must include a "key" declaration'));
591
+ }
592
+ for (let index = 0; index < meaningfulLines.length; index++) {
593
+ const current = meaningfulLines[index];
594
+ if (!current.trimmed.startsWith("append ")) {
595
+ continue;
596
+ }
597
+ let hasWhenClause = false;
598
+ for (let next = index + 1; next < meaningfulLines.length; next++) {
599
+ const candidate = meaningfulLines[next];
600
+ if (candidate.indent <= current.indent) {
601
+ break;
602
+ }
603
+ if (candidate.trimmed.startsWith("when ")) {
604
+ hasWhenClause = true;
605
+ break;
606
+ }
607
+ }
608
+ if (!hasWhenClause) {
609
+ const eventName = current.trimmed.substring("append ".length).trim() || "unnamed append block";
610
+ const startColumn = current.line.indexOf(eventName) + 1;
611
+ issues.push(this.error(
612
+ current.lineNumber,
613
+ startColumn > 0 ? startColumn : 1,
614
+ startColumn > 0 ? startColumn + eventName.length : current.line.length + 1,
615
+ `Append block '${eventName}' must include a "when" clause`
616
+ ));
617
+ }
618
+ }
619
+ return issues;
620
+ }
621
+ error(line, startColumn, endColumn, message) {
622
+ return { severity: "error", line, startColumn, endColumn, message };
623
+ }
624
+ };
625
+
626
+ // sub-languages/capture/index.ts
627
+ var markerOwner = "cdl-validator";
628
+ var disposersByMonaco = /* @__PURE__ */ new Map();
629
+ function toMarkers(monaco, validator, model) {
630
+ return validator.validate(model.getLinesContent()).map((issue) => ({
631
+ severity: issue.severity === "error" ? monaco.MarkerSeverity.Error : monaco.MarkerSeverity.Warning,
632
+ message: issue.message,
633
+ startLineNumber: issue.line + 1,
634
+ startColumn: issue.startColumn,
635
+ endLineNumber: issue.line + 1,
636
+ endColumn: issue.endColumn
637
+ }));
638
+ }
639
+ function registerCaptureLanguage(monaco) {
640
+ const existing = disposersByMonaco.get(monaco);
641
+ if (existing) {
642
+ return { dispose: existing };
643
+ }
644
+ monaco.languages.register({ id: languageId });
645
+ monaco.languages.setLanguageConfiguration(languageId, languageConfiguration);
646
+ monaco.languages.setMonarchTokensProvider(languageId, monarchLanguage);
647
+ const validator = new Validator();
648
+ const disposables = [];
649
+ disposables.push(monaco.languages.registerCompletionItemProvider(languageId, new CompletionProvider()));
650
+ disposables.push(monaco.languages.registerHoverProvider(languageId, new HoverProvider()));
651
+ const validateModel = (model) => {
652
+ if (model.isDisposed() || model.getLanguageId() !== languageId) {
653
+ return;
654
+ }
655
+ monaco.editor.setModelMarkers(model, markerOwner, toMarkers(monaco, validator, model));
656
+ };
657
+ disposables.push(monaco.editor.onDidCreateModel((model) => {
658
+ if (model.getLanguageId() !== languageId) {
659
+ return;
660
+ }
661
+ validateModel(model);
662
+ disposables.push(model.onDidChangeContent(() => validateModel(model)));
663
+ }));
664
+ monaco.editor.getModels().forEach((model) => validateModel(model));
665
+ const dispose = () => {
666
+ disposables.forEach((disposable) => disposable.dispose());
667
+ disposables.length = 0;
668
+ disposersByMonaco.delete(monaco);
669
+ };
670
+ disposersByMonaco.set(monaco, dispose);
671
+ return { dispose };
672
+ }
673
+ export {
674
+ languageId,
675
+ registerCaptureLanguage
676
+ };
677
+ //# sourceMappingURL=index.js.map