@reventlessdev/reventless-spec 3.0.0-alpha.61

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 (86) hide show
  1. package/CHANGELOG.md +625 -0
  2. package/LICENSE +202 -0
  3. package/README.md +114 -0
  4. package/package.json +34 -0
  5. package/rescript.json +25 -0
  6. package/run-generator.mjs +2 -0
  7. package/src/AnsiStyle.res +40 -0
  8. package/src/AnsiStyle.res.mjs +54 -0
  9. package/src/LogPrefix.res +168 -0
  10. package/src/LogPrefix.res.mjs +148 -0
  11. package/src/PackageVersion.res +73 -0
  12. package/src/PackageVersion.res.mjs +81 -0
  13. package/src/components/Aggregate.res +64 -0
  14. package/src/components/Aggregate.res.mjs +2 -0
  15. package/src/components/AutomationSlice.res +279 -0
  16. package/src/components/AutomationSlice.res.mjs +30 -0
  17. package/src/components/Counter.res +24 -0
  18. package/src/components/Counter.res.mjs +2 -0
  19. package/src/components/DcbDecode.res +128 -0
  20. package/src/components/DcbDecode.res.mjs +117 -0
  21. package/src/components/DcbTag.res +1256 -0
  22. package/src/components/DcbTag.res.mjs +869 -0
  23. package/src/components/DcbValidation.res +362 -0
  24. package/src/components/DcbValidation.res.mjs +360 -0
  25. package/src/components/DisplayName.res +40 -0
  26. package/src/components/DisplayName.res.mjs +26 -0
  27. package/src/components/ExtensionPoint.res +27 -0
  28. package/src/components/ExtensionPoint.res.mjs +2 -0
  29. package/src/components/InboundTranslationSlice.res +79 -0
  30. package/src/components/InboundTranslationSlice.res.mjs +2 -0
  31. package/src/components/OutboundTranslationSlice.res +108 -0
  32. package/src/components/OutboundTranslationSlice.res.mjs +2 -0
  33. package/src/components/Plugin.res +373 -0
  34. package/src/components/Plugin.res.mjs +249 -0
  35. package/src/components/ReadModel.res +199 -0
  36. package/src/components/ReadModel.res.mjs +18 -0
  37. package/src/components/Reference.res +51 -0
  38. package/src/components/Reference.res.mjs +37 -0
  39. package/src/components/StateAnnotations.res +65 -0
  40. package/src/components/StateAnnotations.res.mjs +15 -0
  41. package/src/components/StateChangeSlice.res +131 -0
  42. package/src/components/StateChangeSlice.res.mjs +2 -0
  43. package/src/components/StateViewSlice.res +99 -0
  44. package/src/components/StateViewSlice.res.mjs +2 -0
  45. package/src/components/Task.res +62 -0
  46. package/src/components/Task.res.mjs +2 -0
  47. package/src/generator/Codegen.res +703 -0
  48. package/src/generator/Codegen.res.mjs +485 -0
  49. package/src/generator/Config.res +85 -0
  50. package/src/generator/Config.res.mjs +78 -0
  51. package/src/generator/Discovery.res +204 -0
  52. package/src/generator/Discovery.res.mjs +213 -0
  53. package/src/generator/Generator_Node.res +49 -0
  54. package/src/generator/Generator_Node.res.mjs +18 -0
  55. package/src/generator/Pairing.res +386 -0
  56. package/src/generator/Pairing.res.mjs +353 -0
  57. package/src/generator/PluginGenerator.res +53 -0
  58. package/src/generator/PluginGenerator.res.mjs +70 -0
  59. package/src/types/Authorization.res +23 -0
  60. package/src/types/Authorization.res.mjs +33 -0
  61. package/src/types/Behavior.res +78 -0
  62. package/src/types/Behavior.res.mjs +2 -0
  63. package/src/types/EventMapping.res +100 -0
  64. package/src/types/EventMapping.res.mjs +15 -0
  65. package/src/types/Handler.res +30 -0
  66. package/src/types/Handler.res.mjs +2 -0
  67. package/src/types/Id.res +75 -0
  68. package/src/types/Id.res.mjs +37 -0
  69. package/src/types/Identity.res +46 -0
  70. package/src/types/Identity.res.mjs +51 -0
  71. package/src/types/Message.res +197 -0
  72. package/src/types/Message.res.mjs +108 -0
  73. package/src/types/Projection.res +220 -0
  74. package/src/types/Projection.res.mjs +44 -0
  75. package/src/types/QueryEngine.res +123 -0
  76. package/src/types/QueryEngine.res.mjs +12 -0
  77. package/src/types/ReadConsistency.res +38 -0
  78. package/src/types/ReadConsistency.res.mjs +29 -0
  79. package/src/types/Schedule.res +65 -0
  80. package/src/types/Schedule.res.mjs +68 -0
  81. package/src/types/SideEffect.res +45 -0
  82. package/src/types/SideEffect.res.mjs +2 -0
  83. package/src/types/StoredEvent.res +46 -0
  84. package/src/types/StoredEvent.res.mjs +32 -0
  85. package/src/types/Visibility.res +24 -0
  86. package/src/types/Visibility.res.mjs +25 -0
@@ -0,0 +1,485 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+
3
+ import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
4
+ import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
5
+ import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js";
6
+ import * as Pairing$Reventless from "./Pairing.res.mjs";
7
+
8
+ function stripSuffix(s, suffix) {
9
+ if (s.endsWith(suffix)) {
10
+ return s.slice(0, s.length - suffix.length | 0);
11
+ } else {
12
+ return s;
13
+ }
14
+ }
15
+
16
+ function epModuleName(mappingStem) {
17
+ return stripSuffix(mappingStem, "Mapping");
18
+ }
19
+
20
+ function renderSlices(platformFactory, suffix, implSuffix, stems) {
21
+ return stems.map(stem => " module " + stem + suffix + " = Platform." + platformFactory + ".Make(" + stem + ", " + stem + implSuffix + ")");
22
+ }
23
+
24
+ function renderStateChangeSlices(stems, asyncStems) {
25
+ return stems.map(stem => {
26
+ let match = asyncStems[stem];
27
+ let factory = match !== undefined && match ? "MakeAsync" : "Make";
28
+ return " module " + stem + "Slice = Platform.StateChangeSlice." + factory + "(" + stem + ", " + stem + Pairing$Reventless.implSuffixForStateChange + ")";
29
+ });
30
+ }
31
+
32
+ function renderAutomationSlices(stems) {
33
+ return stems.map(stem => " module " + stem + "Slice = Platform.AutomationSlice.Make(" + stem + ", " + stem + "_Automation)");
34
+ }
35
+
36
+ function renderAggregates(aggregates) {
37
+ return aggregates.flatMap(param => {
38
+ let spec = param.spec;
39
+ let em = Stdlib_Option.getOr(param.eventMappings, "ReventlessInfra.NoEventMappings.Make(" + spec + ")");
40
+ let factory = param.isAsync ? "MakeAsync" : "Make";
41
+ return [
42
+ " module " + spec + "Aggregate = Platform.Aggregate." + factory + "(",
43
+ " " + spec + ",",
44
+ " " + param.behavior + ",",
45
+ " " + em + ",",
46
+ " )"
47
+ ];
48
+ });
49
+ }
50
+
51
+ function renderReadModels(readModels) {
52
+ return readModels.flatMap(param => {
53
+ let readModel = param.readModel;
54
+ let wrapperName = readModel.endsWith("ReadModel") ? readModel : readModel + "ReadModel";
55
+ let factory = param.stream ? "Platform.ReadModelStream.Make" : "Platform.ReadModel.Make";
56
+ return [" module " + wrapperName + " = " + factory + "(" + readModel + ", " + param.projections + ")"];
57
+ });
58
+ }
59
+
60
+ function renderTasks(tasks) {
61
+ return tasks.map(stem => " module " + stem + "Task = Platform.Task.Make(" + stem + ")");
62
+ }
63
+
64
+ function renderExtensionPoints(extensionPoints) {
65
+ return extensionPoints.flatMap(param => {
66
+ let mappings = param.mappings;
67
+ let group = param.group;
68
+ let count = mappings.length;
69
+ let firstMapping = mappings[0];
70
+ let moduleName = group !== undefined ? group : stripSuffix(firstMapping, "Mapping");
71
+ switch (count) {
72
+ case 0 :
73
+ return [];
74
+ case 1 :
75
+ return [" module " + moduleName + " = Platform.ExtensionPoint.Make(" + firstMapping + ")"];
76
+ case 2 :
77
+ let m2 = mappings[1];
78
+ return [
79
+ " module " + moduleName + " = Platform.ExtensionPoint.Make2(",
80
+ " " + firstMapping + ",",
81
+ " " + m2 + ",",
82
+ " )"
83
+ ];
84
+ case 3 :
85
+ let m2$1 = mappings[1];
86
+ let m3 = mappings[2];
87
+ return [
88
+ " module " + moduleName + " = Platform.ExtensionPoint.Make3(",
89
+ " " + firstMapping + ",",
90
+ " " + m2$1 + ",",
91
+ " " + m3 + ",",
92
+ " )"
93
+ ];
94
+ default:
95
+ let mappingLines = mappings.map(m => " module(" + m + "),");
96
+ return [
97
+ [
98
+ " module " + moduleName + " = Platform.ExtensionPoint.MakeMulti({",
99
+ " module Spec = " + firstMapping + ".ExtensionPoint",
100
+ " module type Mapping = ReventlessInfra.ExtensionPointMapping.T with module ExtensionPoint := Spec",
101
+ " let name = Spec.name",
102
+ " let moduleUrl: string = %raw(`import.meta.url`)",
103
+ " let mappings: array<module(Mapping)> = ["
104
+ ],
105
+ mappingLines,
106
+ [
107
+ " ]",
108
+ " })"
109
+ ]
110
+ ].flat();
111
+ }
112
+ });
113
+ }
114
+
115
+ function renderExtensions(extensions) {
116
+ return extensions.map(stem => " module " + stem + " = Platform.Extension.Make(" + stem + ".Mapping)");
117
+ }
118
+
119
+ function renderMakeParam(param, items, moduleSuffix) {
120
+ if (items.length === 0) {
121
+ return;
122
+ }
123
+ let entries = items.map(s => "module(" + s + moduleSuffix + ")");
124
+ return " ~" + param + "=[" + entries.join(", ") + "],";
125
+ }
126
+
127
+ function renderStateViewSlicesMakeParam(slices, streamSlices) {
128
+ let entries = [
129
+ slices.map(s => "module(" + s + "Slice)"),
130
+ streamSlices.map(s => "module(" + s + "StreamSlice)")
131
+ ].flat();
132
+ if (entries.length === 0) {
133
+ return;
134
+ } else {
135
+ return " ~stateViewSlices=[" + entries.join(", ") + "],";
136
+ }
137
+ }
138
+
139
+ function renderReadModelMakeParam(readModels) {
140
+ if (readModels.length === 0) {
141
+ return;
142
+ }
143
+ let entries = readModels.map(param => {
144
+ let readModel = param.readModel;
145
+ let wrapperName = readModel.endsWith("ReadModel") ? readModel : readModel + "ReadModel";
146
+ return "module(" + wrapperName + ")";
147
+ });
148
+ return " ~readModels=[" + entries.join(", ") + "],";
149
+ }
150
+
151
+ function renderAggregateMakeParam(aggregates) {
152
+ if (aggregates.length === 0) {
153
+ return;
154
+ }
155
+ let entries = aggregates.map(param => "module(" + param.spec + "Aggregate)");
156
+ return " ~aggregates=[" + entries.join(", ") + "],";
157
+ }
158
+
159
+ function renderEpMakeParam(extensionPoints) {
160
+ if (extensionPoints.length === 0) {
161
+ return;
162
+ }
163
+ let entries = extensionPoints.map(param => {
164
+ let group = param.group;
165
+ let firstMapping = param.mappings[0];
166
+ let moduleName = group !== undefined ? group : stripSuffix(firstMapping, "Mapping");
167
+ return "module(" + moduleName + ")";
168
+ });
169
+ return " ~extensionPoints=[" + entries.join(", ") + "],";
170
+ }
171
+
172
+ function renderExtensionMakeParam(extensions) {
173
+ if (extensions.length === 0) {
174
+ return;
175
+ }
176
+ let entries = extensions.map(s => "module(" + s + ")");
177
+ return " ~extensions=[" + entries.join(", ") + "],";
178
+ }
179
+
180
+ function renderTaskMakeParam(tasks) {
181
+ if (tasks.length === 0) {
182
+ return;
183
+ }
184
+ let entries = tasks.map(s => "module(" + s + "Task)");
185
+ return " ~tasks=[" + entries.join(", ") + "],";
186
+ }
187
+
188
+ function renderPluginStructureCall(name, aggregates, readModels, stateViewSlices, stateViewSlicesStream, stateChangeSlices, automationSlices, outboundTranslationSlices, inboundTranslationSlices, extensions, extensionPoints) {
189
+ let epMappingStems = extensionPoints.flatMap(param => param.mappings);
190
+ let hasComponents = aggregates.length !== 0 || readModels.length !== 0 || stateViewSlices.length !== 0 || stateViewSlicesStream.length !== 0 || stateChangeSlices.length !== 0 || automationSlices.length !== 0 || outboundTranslationSlices.length !== 0 || inboundTranslationSlices.length !== 0 || extensions.length !== 0 || epMappingStems.length !== 0;
191
+ if (!hasComponents) {
192
+ return;
193
+ }
194
+ let ls = [];
195
+ ls.push(" let pluginStructure = Platform.Plugin.makePluginDefinition(");
196
+ ls.push(" ~name=\"" + name + "\",");
197
+ if (aggregates.length !== 0) {
198
+ let entries = aggregates.map(param => "module(" + param.spec + "Aggregate)");
199
+ ls.push(" ~aggregates=[" + entries.join(", ") + "],");
200
+ }
201
+ if (readModels.length !== 0) {
202
+ let entries$1 = readModels.map(param => {
203
+ let readModel = param.readModel;
204
+ let wrapperName = readModel.endsWith("ReadModel") ? readModel : readModel + "ReadModel";
205
+ return "module(" + wrapperName + ")";
206
+ });
207
+ ls.push(" ~readModels=[" + entries$1.join(", ") + "],");
208
+ }
209
+ let allStateViewEntries = [
210
+ stateViewSlices.map(s => "module(" + s + "Slice)"),
211
+ stateViewSlicesStream.map(s => "module(" + s + "StreamSlice)")
212
+ ].flat();
213
+ if (allStateViewEntries.length !== 0) {
214
+ ls.push(" ~stateViewSlices=[" + allStateViewEntries.join(", ") + "],");
215
+ }
216
+ if (stateChangeSlices.length !== 0) {
217
+ let entries$2 = stateChangeSlices.map(s => "module(" + s + "Slice)");
218
+ ls.push(" ~stateChangeSlices=[" + entries$2.join(", ") + "],");
219
+ }
220
+ if (automationSlices.length !== 0) {
221
+ let entries$3 = automationSlices.map(s => "module(" + s + "Slice)");
222
+ ls.push(" ~automationSlices=[" + entries$3.join(", ") + "],");
223
+ }
224
+ if (outboundTranslationSlices.length !== 0) {
225
+ let entries$4 = outboundTranslationSlices.map(s => "module(" + s + "Slice)");
226
+ ls.push(" ~outboundTranslationSlices=[" + entries$4.join(", ") + "],");
227
+ }
228
+ if (inboundTranslationSlices.length !== 0) {
229
+ let entries$5 = inboundTranslationSlices.map(s => "module(" + s + "Slice)");
230
+ ls.push(" ~inboundTranslationSlices=[" + entries$5.join(", ") + "],");
231
+ }
232
+ if (extensions.length !== 0) {
233
+ let entries$6 = extensions.map(s => "module(" + s + ")");
234
+ ls.push(" ~extensions=[" + entries$6.join(", ") + "],");
235
+ }
236
+ if (epMappingStems.length !== 0) {
237
+ let entries$7 = epMappingStems.map(s => "module(" + s + ")");
238
+ ls.push(" ~extensionPoints=[" + entries$7.join(", ") + "],");
239
+ }
240
+ ls.push(" )");
241
+ return ls;
242
+ }
243
+
244
+ function validateUniqueSpecStems(discovered) {
245
+ let byStem = {};
246
+ discovered.forEach(d => {
247
+ let existing = Stdlib_Option.getOr(byStem[d.stem], []);
248
+ existing.push(d.relPath);
249
+ byStem[d.stem] = existing;
250
+ });
251
+ Object.entries(byStem).forEach(param => {
252
+ let paths = param[1];
253
+ if (paths.length <= 1) {
254
+ return;
255
+ }
256
+ let pathList = paths.toSorted((a, b) => {
257
+ if (a < b) {
258
+ return -1.0;
259
+ } else if (a > b) {
260
+ return 1.0;
261
+ } else {
262
+ return 0.0;
263
+ }
264
+ }).join("\n - ");
265
+ Stdlib_JsError.throwWithMessage("Generator: stem `" + param[0] + "` is used by multiple files. Filename stems must be unique across a plugin so the generated module names don't collide:\n - " + pathList);
266
+ });
267
+ }
268
+
269
+ function validateSliceTargets(resolved) {
270
+ let knownReceivers = resolved.aggregates.map(param => param.spec).concat(resolved.stateChangeSlices);
271
+ let check = (kind, stem, target) => {
272
+ if (target !== undefined) {
273
+ if (!knownReceivers.includes(target)) {
274
+ return Stdlib_JsError.throwWithMessage("Generator: " + kind + " `" + stem + "` declares targetName = \"" + target + "\" but no such command receiver exists. Valid targets: " + knownReceivers.join(", "));
275
+ } else {
276
+ return;
277
+ }
278
+ } else {
279
+ return Stdlib_JsError.throwWithMessage("Generator: " + kind + " `" + stem + "` is missing `let targetName = \"...\"`. Valid targets: " + knownReceivers.join(", "));
280
+ }
281
+ };
282
+ resolved.automationSlices.forEach(stem => check("AutomationSlice", stem, Stdlib_Option.getOr(resolved.automationSliceTargets[stem], undefined)));
283
+ resolved.inboundTranslationSlices.forEach(stem => check("InboundTranslationSlice", stem, Stdlib_Option.getOr(resolved.inboundTranslationSliceTargets[stem], undefined)));
284
+ resolved.outboundTranslationSlices.forEach(stem => {
285
+ let t = Stdlib_Option.getOr(resolved.outboundTranslationSliceTargets[stem], undefined);
286
+ if (t !== undefined && !knownReceivers.includes(t)) {
287
+ return Stdlib_JsError.throwWithMessage("Generator: OutboundTranslationSlice `" + stem + "` declares targetName = Some(\"" + t + "\") but no such command receiver exists. Valid targets: " + knownReceivers.join(", "));
288
+ }
289
+ });
290
+ }
291
+
292
+ function renderMain(config) {
293
+ let name = config.name;
294
+ return [
295
+ "// AUTO-GENERATED — do not edit. Run `npm run generate` to update.",
296
+ "// " + name + " plugin — AWS deployment.",
297
+ "",
298
+ "module Platform = ReventlessAws.Platform.Make()",
299
+ "module " + name + " = Plugin.Make(Platform)",
300
+ "",
301
+ "let default = Platform.deployPlugin(",
302
+ " ~plugin=module(" + name + "),",
303
+ ")",
304
+ ""
305
+ ].join("\n");
306
+ }
307
+
308
+ function pluginNameToEnvBase(name) {
309
+ return name.split("").map((ch, i) => {
310
+ let isUpper = ch !== "" && ch === ch.toUpperCase() && ch !== ch.toLowerCase();
311
+ if (i > 0 && isUpper) {
312
+ return "_" + ch;
313
+ } else {
314
+ return ch;
315
+ }
316
+ }).join("").toUpperCase();
317
+ }
318
+
319
+ function renderAwsWrapper(compositionNamespace) {
320
+ return [
321
+ "// AUTO-GENERATED — do not edit. Run `npm run generate` to update.",
322
+ "",
323
+ "module Make = (",
324
+ " Platform: ReventlessInfra.Platform.T",
325
+ " with type api = ReventlessAws.Types.AppSync.api",
326
+ " and type role = ReventlessAws.Types.AppSync.role,",
327
+ ") => {",
328
+ " module Composition = " + compositionNamespace + ".Plugin.Make(Platform)",
329
+ " let make = () => Composition.make()",
330
+ "}",
331
+ ""
332
+ ].join("\n");
333
+ }
334
+
335
+ function renderComposition(config, resolved) {
336
+ let lines = [];
337
+ lines.push("// AUTO-GENERATED — do not edit. Run `npm run generate` to update.");
338
+ lines.push("");
339
+ lines.push("@val external uiBundleUrl: option<string> = \"process.env." + pluginNameToEnvBase(config.name) + "_UI_BUNDLE_URL\"");
340
+ lines.push("");
341
+ lines.push("module Make = (Platform: ReventlessInfra.Platform.T) => {");
342
+ let push = sectionLines => {
343
+ sectionLines.forEach(l => {
344
+ lines.push(l);
345
+ });
346
+ lines.push("");
347
+ };
348
+ if (resolved.stateChangeSlices.length !== 0) {
349
+ lines.push(" // StateChangeSlices");
350
+ push(renderStateChangeSlices(resolved.stateChangeSlices, resolved.asyncStateChangeSlices));
351
+ }
352
+ if (resolved.stateViewSlices.length !== 0) {
353
+ lines.push(" // StateViewSlices");
354
+ push(renderSlices("StateViewSlice", "Slice", Pairing$Reventless.implSuffixForStateView, resolved.stateViewSlices));
355
+ }
356
+ if (resolved.stateViewSlicesStream.length !== 0) {
357
+ lines.push(" // StateViewSliceStreams");
358
+ push(renderSlices("StateViewSliceStream", "StreamSlice", Pairing$Reventless.implSuffixForStateView, resolved.stateViewSlicesStream));
359
+ }
360
+ if (resolved.automationSlices.length !== 0) {
361
+ lines.push(" // AutomationSlices");
362
+ push(renderAutomationSlices(resolved.automationSlices));
363
+ }
364
+ if (resolved.outboundTranslationSlices.length !== 0) {
365
+ lines.push(" // OutboundTranslationSlices");
366
+ push(renderSlices("OutboundTranslationSlice", "Slice", Pairing$Reventless.implSuffixForTranslation, resolved.outboundTranslationSlices));
367
+ }
368
+ if (resolved.inboundTranslationSlices.length !== 0) {
369
+ lines.push(" // InboundTranslationSlices");
370
+ push(renderSlices("InboundTranslationSlice", "Slice", Pairing$Reventless.implSuffixForTranslation, resolved.inboundTranslationSlices));
371
+ }
372
+ if (resolved.aggregates.length !== 0) {
373
+ lines.push(" // Aggregates");
374
+ push(renderAggregates(resolved.aggregates));
375
+ }
376
+ if (resolved.readModels.length !== 0) {
377
+ lines.push(" // ReadModels");
378
+ push(renderReadModels(resolved.readModels));
379
+ }
380
+ if (resolved.tasks.length !== 0) {
381
+ lines.push(" // Tasks");
382
+ push(renderTasks(resolved.tasks));
383
+ }
384
+ if (resolved.extensionPoints.length !== 0) {
385
+ lines.push(" // ExtensionPoints");
386
+ push(renderExtensionPoints(resolved.extensionPoints));
387
+ }
388
+ if (resolved.extensions.length !== 0) {
389
+ lines.push(" // Extensions");
390
+ push(renderExtensions(resolved.extensions));
391
+ }
392
+ let pluginStructureLines = renderPluginStructureCall(config.name, resolved.aggregates, resolved.readModels, resolved.stateViewSlices, resolved.stateViewSlicesStream, resolved.stateChangeSlices, resolved.automationSlices, resolved.outboundTranslationSlices, resolved.inboundTranslationSlices, resolved.extensions, resolved.extensionPoints);
393
+ let hasPluginStructure = Stdlib_Option.isSome(pluginStructureLines);
394
+ if (pluginStructureLines !== undefined) {
395
+ pluginStructureLines.forEach(l => {
396
+ lines.push(l);
397
+ });
398
+ lines.push("");
399
+ }
400
+ lines.push(" let make = () =>");
401
+ lines.push(" Platform.Plugin.make(");
402
+ lines.push(" ~name=\"" + config.name + "\",");
403
+ lines.push(" ~heartbeatInterval=" + config.heartbeatInterval.toString() + ",");
404
+ let uiFragmentsParam;
405
+ if (hasPluginStructure) {
406
+ let ls = [];
407
+ ls.push(" ~uiFragments=?uiBundleUrl->Option.map(url =>");
408
+ ls.push(" Platform.Plugin.makeAutoUIManifest(");
409
+ ls.push(" ~remoteEntryUrl=url,");
410
+ ls.push(" ~name=\"" + config.name + "\",");
411
+ ls.push(" ~pluginStructure,");
412
+ ls.push(" ~readModelPositions=[\"platform-summary\"],");
413
+ ls.push(" ~aggregatePositions=[\"resource-detail\"],");
414
+ ls.push(" )");
415
+ ls.push(" ),");
416
+ uiFragmentsParam = ls;
417
+ } else {
418
+ uiFragmentsParam = undefined;
419
+ }
420
+ let makeParams = [
421
+ renderEpMakeParam(resolved.extensionPoints),
422
+ renderExtensionMakeParam(resolved.extensions),
423
+ renderAggregateMakeParam(resolved.aggregates),
424
+ renderReadModelMakeParam(resolved.readModels),
425
+ renderTaskMakeParam(resolved.tasks),
426
+ renderMakeParam("stateChangeSlices", resolved.stateChangeSlices, "Slice"),
427
+ renderStateViewSlicesMakeParam(resolved.stateViewSlices, resolved.stateViewSlicesStream),
428
+ renderMakeParam("automationSlices", resolved.automationSlices, "Slice"),
429
+ renderMakeParam("outboundTranslationSlices", resolved.outboundTranslationSlices, "Slice"),
430
+ renderMakeParam("inboundTranslationSlices", resolved.inboundTranslationSlices, "Slice"),
431
+ hasPluginStructure ? " ~pluginStructure=pluginStructure," : undefined
432
+ ];
433
+ Stdlib_Array.filterMap(makeParams, x => x).forEach(line => {
434
+ lines.push(line);
435
+ });
436
+ if (uiFragmentsParam !== undefined) {
437
+ uiFragmentsParam.forEach(line => {
438
+ lines.push(line);
439
+ });
440
+ }
441
+ lines.push(" )");
442
+ lines.push("}");
443
+ lines.push("");
444
+ return lines.join("\n");
445
+ }
446
+
447
+ function render(config, resolved, discovered) {
448
+ validateUniqueSpecStems(discovered);
449
+ validateSliceTargets(resolved);
450
+ let match = config.variant;
451
+ if (typeof match !== "object") {
452
+ return renderComposition(config, resolved);
453
+ } else {
454
+ return renderAwsWrapper(match.compositionNamespace);
455
+ }
456
+ }
457
+
458
+ export {
459
+ stripSuffix,
460
+ epModuleName,
461
+ renderSlices,
462
+ renderStateChangeSlices,
463
+ renderAutomationSlices,
464
+ renderAggregates,
465
+ renderReadModels,
466
+ renderTasks,
467
+ renderExtensionPoints,
468
+ renderExtensions,
469
+ renderMakeParam,
470
+ renderStateViewSlicesMakeParam,
471
+ renderReadModelMakeParam,
472
+ renderAggregateMakeParam,
473
+ renderEpMakeParam,
474
+ renderExtensionMakeParam,
475
+ renderTaskMakeParam,
476
+ renderPluginStructureCall,
477
+ validateUniqueSpecStems,
478
+ validateSliceTargets,
479
+ renderMain,
480
+ pluginNameToEnvBase,
481
+ renderAwsWrapper,
482
+ renderComposition,
483
+ render,
484
+ }
485
+ /* Pairing-Reventless Not a pure module */
@@ -0,0 +1,85 @@
1
+ // Plugin configuration reader.
2
+ // Reads plugin.json from srcDir (optional) and derives defaults from package.json.
3
+
4
+ type variant = Composition | Aws({compositionNamespace: string})
5
+
6
+ type config = {
7
+ name: string,
8
+ heartbeatInterval: int,
9
+ exclude: array<string>,
10
+ variant: variant,
11
+ }
12
+
13
+ // Convert npm package name to PascalCase plugin name.
14
+ // "@scope/my-catalog" → "MyCatalog", "online-shop" → "OnlineShop"
15
+ let packageNameToPluginName = (packageName: string): string => {
16
+ let base = switch packageName->String.split("/") {
17
+ | [_scope, local] => local
18
+ | [local] => local
19
+ | parts => parts->Array.getUnsafe(parts->Array.length - 1)
20
+ }
21
+ base
22
+ ->String.split("-")
23
+ ->Array.flatMap(part => part->String.split("_"))
24
+ ->Array.map(word =>
25
+ if word === "" {
26
+ ""
27
+ } else {
28
+ word->String.slice(~start=0, ~end=1)->String.toUpperCase ++
29
+ word->String.slice(~start=1, ~end=word->String.length)
30
+ }
31
+ )
32
+ ->Array.join("")
33
+ }
34
+
35
+ let readJson = (path: string): option<JSON.t> =>
36
+ try Some(Generator_Node.readFileSync(path)->JSON.parseOrThrow) catch {
37
+ | _ => None
38
+ }
39
+
40
+ let getStrField = (json: JSON.t, key: string): option<string> =>
41
+ json
42
+ ->JSON.Decode.object
43
+ ->Option.flatMap(d => d->Dict.get(key))
44
+ ->Option.flatMap(JSON.Decode.string)
45
+
46
+ let getIntField = (json: JSON.t, key: string): option<int> =>
47
+ json
48
+ ->JSON.Decode.object
49
+ ->Option.flatMap(d => d->Dict.get(key))
50
+ ->Option.flatMap(JSON.Decode.float)
51
+ ->Option.map(Float.toInt)
52
+
53
+ let getStrArrayField = (json: JSON.t, key: string): option<array<string>> =>
54
+ json
55
+ ->JSON.Decode.object
56
+ ->Option.flatMap(d => d->Dict.get(key))
57
+ ->Option.flatMap(JSON.Decode.array)
58
+ ->Option.map(arr => arr->Array.filterMap(JSON.Decode.string))
59
+
60
+ let read = (~srcDir: string): config => {
61
+ // Derive plugin name from package.json in parent of srcDir
62
+ let packageJsonPath = Generator_Node.join([Generator_Node.dirname(srcDir), "package.json"])
63
+ let derivedName =
64
+ readJson(packageJsonPath)
65
+ ->Option.flatMap(j => getStrField(j, "name"))
66
+ ->Option.map(packageNameToPluginName)
67
+ ->Option.getOr("Plugin")
68
+
69
+ // Read plugin.json from srcDir (optional)
70
+ let pluginJsonPath = Generator_Node.join([srcDir, "plugin.json"])
71
+ let pluginJson = if Generator_Node.existsSync(pluginJsonPath) {
72
+ readJson(pluginJsonPath)
73
+ } else {
74
+ None
75
+ }
76
+
77
+ {
78
+ name: pluginJson->Option.flatMap(j => getStrField(j, "name"))->Option.getOr(derivedName),
79
+ heartbeatInterval: pluginJson
80
+ ->Option.flatMap(j => getIntField(j, "heartbeatInterval"))
81
+ ->Option.getOr(5),
82
+ exclude: pluginJson->Option.flatMap(j => getStrArrayField(j, "exclude"))->Option.getOr([]),
83
+ variant: Composition,
84
+ }
85
+ }
@@ -0,0 +1,78 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+
3
+ import * as Nodefs from "node:fs";
4
+ import * as Nodepath from "node:path";
5
+ import * as Stdlib_JSON from "@rescript/runtime/lib/es6/Stdlib_JSON.js";
6
+ import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
7
+ import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
8
+
9
+ function packageNameToPluginName(packageName) {
10
+ let parts = packageName.split("/");
11
+ let len = parts.length;
12
+ let base;
13
+ if (len >= 3) {
14
+ base = parts[parts.length - 1 | 0];
15
+ } else {
16
+ switch (len) {
17
+ case 0 :
18
+ base = parts[parts.length - 1 | 0];
19
+ break;
20
+ case 1 :
21
+ base = parts[0];
22
+ break;
23
+ case 2 :
24
+ base = parts[1];
25
+ break;
26
+ }
27
+ }
28
+ return base.split("-").flatMap(part => part.split("_")).map(word => {
29
+ if (word === "") {
30
+ return "";
31
+ } else {
32
+ return word.slice(0, 1).toUpperCase() + word.slice(1, word.length);
33
+ }
34
+ }).join("");
35
+ }
36
+
37
+ function readJson(path) {
38
+ try {
39
+ return JSON.parse(Nodefs.readFileSync(path, "utf8"));
40
+ } catch (exn) {
41
+ return;
42
+ }
43
+ }
44
+
45
+ function getStrField(json, key) {
46
+ return Stdlib_Option.flatMap(Stdlib_Option.flatMap(Stdlib_JSON.Decode.object(json), d => d[key]), Stdlib_JSON.Decode.string);
47
+ }
48
+
49
+ function getIntField(json, key) {
50
+ return Stdlib_Option.map(Stdlib_Option.flatMap(Stdlib_Option.flatMap(Stdlib_JSON.Decode.object(json), d => d[key]), Stdlib_JSON.Decode.float), prim => prim | 0);
51
+ }
52
+
53
+ function getStrArrayField(json, key) {
54
+ return Stdlib_Option.map(Stdlib_Option.flatMap(Stdlib_Option.flatMap(Stdlib_JSON.Decode.object(json), d => d[key]), Stdlib_JSON.Decode.array), arr => Stdlib_Array.filterMap(arr, Stdlib_JSON.Decode.string));
55
+ }
56
+
57
+ function read(srcDir) {
58
+ let packageJsonPath = Nodepath.join(Nodepath.dirname(srcDir), "package.json");
59
+ let derivedName = Stdlib_Option.getOr(Stdlib_Option.map(Stdlib_Option.flatMap(readJson(packageJsonPath), j => getStrField(j, "name")), packageNameToPluginName), "Plugin");
60
+ let pluginJsonPath = Nodepath.join(srcDir, "plugin.json");
61
+ let pluginJson = Nodefs.existsSync(pluginJsonPath) ? readJson(pluginJsonPath) : undefined;
62
+ return {
63
+ name: Stdlib_Option.getOr(Stdlib_Option.flatMap(pluginJson, j => getStrField(j, "name")), derivedName),
64
+ heartbeatInterval: Stdlib_Option.getOr(Stdlib_Option.flatMap(pluginJson, j => getIntField(j, "heartbeatInterval")), 5),
65
+ exclude: Stdlib_Option.getOr(Stdlib_Option.flatMap(pluginJson, j => getStrArrayField(j, "exclude")), []),
66
+ variant: "Composition"
67
+ };
68
+ }
69
+
70
+ export {
71
+ packageNameToPluginName,
72
+ readJson,
73
+ getStrField,
74
+ getIntField,
75
+ getStrArrayField,
76
+ read,
77
+ }
78
+ /* node:fs Not a pure module */