@reventlessdev/reventless-aws 3.0.0-alpha.231 → 3.0.0-alpha.233

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 (104) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/package.json +7 -7
  3. package/src/adapter/Api/AppSyncEventsSigner_Ops.res +137 -0
  4. package/src/adapter/Api/AppSyncEventsSigner_Ops.res.mjs +121 -0
  5. package/src/adapter/Api/Platform_AdminScan_Ops.res +136 -0
  6. package/src/adapter/Api/Platform_AdminScan_Ops.res.mjs +98 -0
  7. package/src/adapter/Api/Platform_ComponentDefinitions_Lambda.res +12 -90
  8. package/src/adapter/Api/Platform_ComponentDefinitions_Lambda.res.mjs +11 -84
  9. package/src/adapter/Api/Platform_ComponentDefinitions_Lambda_Ops.res +86 -0
  10. package/src/adapter/Api/Platform_ComponentDefinitions_Lambda_Ops.res.mjs +79 -0
  11. package/src/adapter/Api/Platform_UIFragments_Lambda.res +9 -79
  12. package/src/adapter/Api/Platform_UIFragments_Lambda.res.mjs +7 -143
  13. package/src/adapter/Api/Platform_UIFragments_Lambda_Ops.res +48 -0
  14. package/src/adapter/Api/Platform_UIFragments_Lambda_Ops.res.mjs +63 -0
  15. package/src/adapter/EventLogSubscription/EventLogSubscription_AppSync.res +21 -80
  16. package/src/adapter/EventLogSubscription/EventLogSubscription_AppSync.res.mjs +23 -68
  17. package/src/adapter/EventLogSubscription/EventLogSubscription_AppSync_Ops.res +70 -0
  18. package/src/adapter/EventLogSubscription/EventLogSubscription_AppSync_Ops.res.mjs +68 -0
  19. package/src/adapter/Postgres/PgChangeFeedRelay_Builder.res +1 -1
  20. package/src/adapter/Postgres/PgChangeFeedRelay_Builder.res.mjs +1 -1
  21. package/src/adapter/Postgres/PgMigration_Builder.res +1 -1
  22. package/src/adapter/Postgres/PgMigration_Builder.res.mjs +1 -1
  23. package/src/adapter/Runtime/AutomationSliceEntryPoint.mjs +42 -126
  24. package/src/adapter/Runtime/AutomationSliceEntryPoint_Ops.res +246 -0
  25. package/src/adapter/Runtime/AutomationSliceEntryPoint_Ops.res.mjs +145 -0
  26. package/src/adapter/Runtime/AutomationSliceRuntime_Builder_Single.res +27 -2
  27. package/src/adapter/Runtime/AutomationSliceRuntime_Builder_Single.res.mjs +10 -3
  28. package/src/adapter/Runtime/CounterEntryPoint.mjs +19 -73
  29. package/src/adapter/Runtime/CounterEntryPoint_Ops.res +145 -0
  30. package/src/adapter/Runtime/CounterEntryPoint_Ops.res.mjs +129 -0
  31. package/src/adapter/Runtime/DcbCommandTopicEntryPoint_Ops.res +16 -3
  32. package/src/adapter/Runtime/DcbCommandTopicEntryPoint_Ops.res.mjs +11 -6
  33. package/src/adapter/Runtime/EventCollectorEntryPoint.mjs +52 -510
  34. package/src/adapter/Runtime/EventCollectorEntryPoint_Ops.res +816 -0
  35. package/src/adapter/Runtime/EventCollectorEntryPoint_Ops.res.mjs +651 -0
  36. package/src/adapter/Runtime/EventMapperEntryPoint.mjs +23 -67
  37. package/src/adapter/Runtime/EventMapperEntryPoint_Ops.res +126 -0
  38. package/src/adapter/Runtime/EventMapperEntryPoint_Ops.res.mjs +83 -0
  39. package/src/adapter/Runtime/ExtensionPointEntryPoint.mjs +16 -63
  40. package/src/adapter/Runtime/ExtensionPointEntryPoint_Ops.res +150 -0
  41. package/src/adapter/Runtime/ExtensionPointEntryPoint_Ops.res.mjs +111 -0
  42. package/src/adapter/Runtime/PgChangeFeedRelayEntryPoint.res +96 -0
  43. package/src/adapter/Runtime/PgChangeFeedRelayEntryPoint.res.mjs +70 -0
  44. package/src/adapter/Runtime/PgMigrationEntryPoint.res +54 -0
  45. package/src/adapter/Runtime/PgMigrationEntryPoint.res.mjs +37 -0
  46. package/src/adapter/Runtime/PgQueryResolverEntryPoint.mjs +20 -55
  47. package/src/adapter/Runtime/PgQueryResolverEntryPoint_Ops.res +155 -0
  48. package/src/adapter/Runtime/PgQueryResolverEntryPoint_Ops.res.mjs +94 -0
  49. package/src/adapter/Runtime/ProjectionEntryPoint_Ops.res +80 -0
  50. package/src/adapter/Runtime/ProjectionEntryPoint_Ops.res.mjs +39 -0
  51. package/src/adapter/Runtime/QueryDbEntryPoint_Ops.res +4 -4
  52. package/src/adapter/Runtime/ReadModelEntryPoint.mjs +34 -153
  53. package/src/adapter/Runtime/ReadModelEntryPoint_Ops.res +114 -0
  54. package/src/adapter/Runtime/ReadModelEntryPoint_Ops.res.mjs +83 -0
  55. package/src/adapter/Runtime/SideEffectEntryPoint.mjs +23 -64
  56. package/src/adapter/Runtime/SideEffectEntryPoint_Ops.res +71 -0
  57. package/src/adapter/Runtime/SideEffectEntryPoint_Ops.res.mjs +57 -0
  58. package/src/adapter/Runtime/StateViewSliceEntryPoint.mjs +34 -165
  59. package/src/adapter/Runtime/StateViewSliceEntryPoint_Ops.res +206 -0
  60. package/src/adapter/Runtime/StateViewSliceEntryPoint_Ops.res.mjs +105 -0
  61. package/src/adapter/Runtime/StreamRoutedEntryPoint_Ops.res +156 -0
  62. package/src/adapter/Runtime/StreamRoutedEntryPoint_Ops.res.mjs +123 -0
  63. package/src/adapter/Runtime/TaskBucketEntryPoint.mjs +18 -138
  64. package/src/adapter/Runtime/TaskBucketEntryPoint_Ops.res +198 -0
  65. package/src/adapter/Runtime/TaskBucketEntryPoint_Ops.res.mjs +155 -0
  66. package/src/adapter/StateTopic/StateTopic_AppSync.res +12 -170
  67. package/src/adapter/StateTopic/StateTopic_AppSync.res.mjs +7 -167
  68. package/src/adapter/StateTopic/StateTopic_AppSync_Ops.res +208 -0
  69. package/src/adapter/StateTopic/StateTopic_AppSync_Ops.res.mjs +183 -0
  70. package/src/components/AutomationSlice_Builder.res +2 -0
  71. package/src/components/AutomationSlice_Builder.res.mjs +1 -1
  72. package/src/components/OutboundTranslationSlice_Builder.res +1 -0
  73. package/src/components/OutboundTranslationSlice_Builder.res.mjs +1 -1
  74. package/tests/AppSyncEventsSigner_OpsTest.res +75 -0
  75. package/tests/AppSyncEventsSigner_OpsTest.res.mjs +44 -0
  76. package/tests/AppSyncEventsSigner_ParityFixture.mjs +36 -0
  77. package/tests/AutomationSliceEntryPoint_OpsTest.res +165 -0
  78. package/tests/AutomationSliceEntryPoint_OpsTest.res.mjs +280 -0
  79. package/tests/CounterEntryPoint_OpsTest.res +115 -0
  80. package/tests/CounterEntryPoint_OpsTest.res.mjs +150 -0
  81. package/tests/EventCollectorEntryPoint_OpsTest.res +216 -0
  82. package/tests/EventCollectorEntryPoint_OpsTest.res.mjs +339 -0
  83. package/tests/EventMapperEntryPoint_OpsTest.res +103 -0
  84. package/tests/EventMapperEntryPoint_OpsTest.res.mjs +120 -0
  85. package/tests/ExtensionPointEntryPoint_OpsTest.res +57 -0
  86. package/tests/ExtensionPointEntryPoint_OpsTest.res.mjs +54 -0
  87. package/tests/PgMigrationEntryPoint_IntegrationTest.res +22 -31
  88. package/tests/PgMigrationEntryPoint_IntegrationTest.res.mjs +20 -23
  89. package/tests/PgQueryResolverEntryPoint_OpsTest.res +38 -0
  90. package/tests/PgQueryResolverEntryPoint_OpsTest.res.mjs +31 -0
  91. package/tests/Platform_AdminScan_OpsTest.res +80 -0
  92. package/tests/Platform_AdminScan_OpsTest.res.mjs +127 -0
  93. package/tests/ReadModelEntryPoint_OpsTest.res +141 -0
  94. package/tests/ReadModelEntryPoint_OpsTest.res.mjs +267 -0
  95. package/tests/SideEffectEntryPoint_OpsTest.res +79 -0
  96. package/tests/SideEffectEntryPoint_OpsTest.res.mjs +105 -0
  97. package/tests/StateViewSliceEntryPoint_OpsTest.res +167 -0
  98. package/tests/StateViewSliceEntryPoint_OpsTest.res.mjs +296 -0
  99. package/tests/TaskBucketEntryPoint_OpsTest.res +117 -0
  100. package/tests/TaskBucketEntryPoint_OpsTest.res.mjs +165 -0
  101. package/tests/integration/StateViewSliceEntryPoint_IntegrationTest.res +42 -13
  102. package/tests/integration/StateViewSliceEntryPoint_IntegrationTest.res.mjs +29 -6
  103. package/src/adapter/Runtime/PgChangeFeedRelayEntryPoint.mjs +0 -57
  104. package/src/adapter/Runtime/PgMigrationEntryPoint.mjs +0 -40
@@ -0,0 +1,651 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+
3
+ import * as Nodefs from "node:fs";
4
+ import * as Stdlib_JSON from "@rescript/runtime/lib/es6/Stdlib_JSON.js";
5
+ import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
6
+ import * as Stdlib_JsExn from "@rescript/runtime/lib/es6/Stdlib_JsExn.js";
7
+ import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
8
+ import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js";
9
+ import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
10
+ import * as SNS_Helpers$AwsSdk from "@reventlessdev/rescript-aws-sdk/src/SNS_Helpers.res.mjs";
11
+ import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
12
+ import * as HandlerFactoryHelpersMjs from "./HandlerFactoryHelpers.mjs";
13
+ import * as Plugin_Callback$ReventlessCore from "@reventlessdev/reventless-core/src/plugin/component/Plugin_Callback.res.mjs";
14
+ import * as Util_PluginMessage_Runtime$ReventlessAws from "../../plugin/runtime/Util_PluginMessage_Runtime.res.mjs";
15
+ import * as CommandTopicChannel_SQS_Runtime$ReventlessAws from "../CommandTopic/CommandTopicChannel_SQS_Runtime.res.mjs";
16
+ import * as EventTopicPublisher_SNS_Runtime$ReventlessAws from "../EventTopic/EventTopicPublisher_SNS_Runtime.res.mjs";
17
+ import * as EventCollectorChannel_SQS_Runtime$ReventlessAws from "../EventCollector/EventCollectorChannel_SQS_Runtime.res.mjs";
18
+ import * as ScheduledPublisher_CloudWatchEvents_Runtime$ReventlessAws from "../ScheduledPublisher/ScheduledPublisher_CloudWatchEvents_Runtime.res.mjs";
19
+
20
+ function setRequestId(prim) {
21
+ HandlerFactoryHelpersMjs.setRequestId(prim);
22
+ }
23
+
24
+ function runEffect(prim0, prim1) {
25
+ return HandlerFactoryHelpersMjs.runEffect(prim0, prim1);
26
+ }
27
+
28
+ function extractMetaField(prim0, prim1) {
29
+ return HandlerFactoryHelpersMjs.extractMetaField(prim0, prim1);
30
+ }
31
+
32
+ function extractSentTimestamp(prim) {
33
+ return HandlerFactoryHelpersMjs.extractSentTimestamp(prim);
34
+ }
35
+
36
+ function extractRetryCount(prim) {
37
+ return HandlerFactoryHelpersMjs.extractRetryCount(prim);
38
+ }
39
+
40
+ function logDebug(prim0, prim1) {
41
+ HandlerFactoryHelpersMjs.log.debug(prim0, prim1);
42
+ }
43
+
44
+ function logInfo(prim0, prim1) {
45
+ HandlerFactoryHelpersMjs.log.info(prim0, prim1);
46
+ }
47
+
48
+ function logWarn(prim0, prim1) {
49
+ HandlerFactoryHelpersMjs.log.warn(prim0, prim1);
50
+ }
51
+
52
+ function logError(prim0, prim1) {
53
+ HandlerFactoryHelpersMjs.log.error(prim0, prim1);
54
+ }
55
+
56
+ function scanByTableName(prim0, prim1, prim2) {
57
+ return HandlerFactoryHelpersMjs.scanByTableName(prim0, prim1, prim2);
58
+ }
59
+
60
+ function exnMessage(exn) {
61
+ return Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(exn), Stdlib_JsExn.message), "unknown error");
62
+ }
63
+
64
+ function jsOption(v) {
65
+ if (v == null) {
66
+ return;
67
+ } else {
68
+ return Primitive_option.some(v);
69
+ }
70
+ }
71
+
72
+ function strOf(obj, key) {
73
+ return Stdlib_Option.flatMap(obj[key], Stdlib_JSON.Decode.string);
74
+ }
75
+
76
+ function strArrOf(obj, key) {
77
+ return Stdlib_Array.filterMap(Stdlib_Option.getOr(Stdlib_Option.flatMap(obj[key], Stdlib_JSON.Decode.array), []), Stdlib_JSON.Decode.string);
78
+ }
79
+
80
+ function strDictOf(obj, key) {
81
+ return Object.fromEntries(Stdlib_Array.filterMap(Object.entries(Stdlib_Option.getOr(Stdlib_Option.flatMap(obj[key], Stdlib_JSON.Decode.object), {})), param => {
82
+ let k = param[0];
83
+ return Stdlib_Option.map(Stdlib_JSON.Decode.string(param[1]), s => [
84
+ k,
85
+ s
86
+ ]);
87
+ }));
88
+ }
89
+
90
+ function parseHandlerConfig(rawJson) {
91
+ if (rawJson === "") {
92
+ Stdlib_JsError.throwWithMessage("HANDLER_CONFIG env var is empty");
93
+ }
94
+ let json;
95
+ try {
96
+ json = JSON.parse(rawJson);
97
+ } catch (raw_exn) {
98
+ let exn = Primitive_exceptions.internalToException(raw_exn);
99
+ json = Stdlib_JsError.throwWithMessage("HANDLER_CONFIG JSON parse error: " + exnMessage(exn));
100
+ }
101
+ let o = Stdlib_JSON.Decode.object(json);
102
+ let obj = o !== undefined ? o : Stdlib_JsError.throwWithMessage("HANDLER_CONFIG is not a JSON object");
103
+ [
104
+ "queueUrl",
105
+ "pluginExtensionPointCmdTopicUrl",
106
+ "eventTopicArn",
107
+ "pluginReadModelTableName",
108
+ "appSyncApiId",
109
+ "schedulerRoleArn",
110
+ "schedulerQueueArn",
111
+ "schedulerQueueName",
112
+ "extensionPoints",
113
+ "extensions",
114
+ "publishToAggregates"
115
+ ].forEach(k => {
116
+ if (Stdlib_Option.isNone(obj[k])) {
117
+ return Stdlib_JsError.throwWithMessage("HANDLER_CONFIG missing required field: " + k);
118
+ }
119
+ });
120
+ let items = Stdlib_Option.flatMap(obj["extensionPoints"], Stdlib_JSON.Decode.array);
121
+ let extensionPoints = items !== undefined ? Stdlib_Array.filterMap(items, item => Stdlib_Option.map(Stdlib_JSON.Decode.object(item), ep => ({
122
+ specModule: Stdlib_Option.getOr(strOf(ep, "specModule"), ""),
123
+ mappingsModule: Stdlib_Option.getOr(strOf(ep, "mappingsModule"), ""),
124
+ eventTopicArn: Stdlib_Option.getOr(strOf(ep, "eventTopicArn"), ""),
125
+ aggregateNames: strArrOf(ep, "aggregateNames")
126
+ }))) : Stdlib_JsError.throwWithMessage("HANDLER_CONFIG.extensionPoints must be an array");
127
+ let items$1 = Stdlib_Option.flatMap(obj["extensions"], Stdlib_JSON.Decode.array);
128
+ let extensions = items$1 !== undefined ? Stdlib_Array.filterMap(items$1, item => Stdlib_Option.map(Stdlib_JSON.Decode.object(item), ext => {
129
+ let extensionPointName = Stdlib_Option.getOr(strOf(ext, "extensionPointName"), "");
130
+ return {
131
+ name: Stdlib_Option.getOr(strOf(ext, "name"), extensionPointName === "" ? "unknown" : extensionPointName),
132
+ specModule: Stdlib_Option.getOr(strOf(ext, "specModule"), ""),
133
+ mappingsModule: Stdlib_Option.getOr(strOf(ext, "mappingsModule"), ""),
134
+ delegateModule: Stdlib_Option.getOr(strOf(ext, "delegateModule"), ""),
135
+ extensionPointName: extensionPointName,
136
+ aggregateNames: strArrOf(ext, "aggregateNames"),
137
+ readModelNames: strArrOf(ext, "readModelNames")
138
+ };
139
+ })) : Stdlib_JsError.throwWithMessage("HANDLER_CONFIG.extensions must be an array");
140
+ let connectExtension = Stdlib_Option.map(Stdlib_Option.flatMap(obj["connectExtension"], Stdlib_JSON.Decode.object), ce => ({
141
+ specModule: Stdlib_Option.getOr(strOf(ce, "specModule"), ""),
142
+ mappingsModule: Stdlib_Option.getOr(strOf(ce, "mappingsModule"), ""),
143
+ extensionPointName: Stdlib_Option.getOr(strOf(ce, "extensionPointName"), "")
144
+ }));
145
+ let readModelNamesForSourceName = Object.fromEntries(Object.entries(Stdlib_Option.getOr(Stdlib_Option.flatMap(obj["readModelNamesForSourceName"], Stdlib_JSON.Decode.object), {})).map(param => [
146
+ param[0],
147
+ Stdlib_Array.filterMap(Stdlib_Option.getOr(Stdlib_JSON.Decode.array(param[1]), []), Stdlib_JSON.Decode.string)
148
+ ]));
149
+ return {
150
+ queueUrl: Stdlib_Option.getOr(strOf(obj, "queueUrl"), ""),
151
+ pluginExtensionPointCmdTopicUrl: Stdlib_Option.getOr(strOf(obj, "pluginExtensionPointCmdTopicUrl"), ""),
152
+ eventTopicArn: Stdlib_Option.getOr(strOf(obj, "eventTopicArn"), ""),
153
+ pluginReadModelTableName: Stdlib_Option.getOr(strOf(obj, "pluginReadModelTableName"), ""),
154
+ appSyncApiId: Stdlib_Option.getOr(strOf(obj, "appSyncApiId"), ""),
155
+ schedulerRoleArn: Stdlib_Option.getOr(strOf(obj, "schedulerRoleArn"), ""),
156
+ schedulerQueueArn: Stdlib_Option.getOr(strOf(obj, "schedulerQueueArn"), ""),
157
+ schedulerQueueName: Stdlib_Option.getOr(strOf(obj, "schedulerQueueName"), ""),
158
+ extensionPoints: extensionPoints,
159
+ connectExtension: connectExtension,
160
+ extensions: extensions,
161
+ publishToAggregates: strDictOf(obj, "publishToAggregates"),
162
+ readModelQueueUrls: strDictOf(obj, "readModelQueueUrls"),
163
+ readModelNamesForSourceName: readModelNamesForSourceName
164
+ };
165
+ }
166
+
167
+ function projectPluginRow(row) {
168
+ let obj = Stdlib_JSON.Decode.object(row);
169
+ if (obj === undefined) {
170
+ return;
171
+ }
172
+ let match = strOf(obj, "id");
173
+ let match$1 = strOf(obj, "status");
174
+ if (match === undefined) {
175
+ return;
176
+ }
177
+ if (match$1 === undefined) {
178
+ return;
179
+ }
180
+ let dcbEventLog = Stdlib_Option.flatMap(Stdlib_Option.flatMap(obj["dcbEventLog"], Stdlib_JSON.Decode.object), d => {
181
+ let match = strOf(d, "name");
182
+ let match$1 = strOf(d, "eventTopicArn");
183
+ if (match !== undefined && match$1 !== undefined) {
184
+ return {
185
+ name: match,
186
+ eventTopicArn: match$1
187
+ };
188
+ }
189
+ });
190
+ let extensions = Stdlib_Array.filterMap(Stdlib_Option.getOr(Stdlib_Option.flatMap(obj["extensions"], Stdlib_JSON.Decode.array), []), e => Stdlib_Option.flatMap(Stdlib_JSON.Decode.object(e), eo => Stdlib_Option.map(strOf(eo, "extensionPointName"), extensionPointName => ({
191
+ name: Stdlib_Option.getOr(strOf(eo, "name"), ""),
192
+ extensionPointName: extensionPointName,
193
+ dcbSources: strArrOf(eo, "dcbSources")
194
+ }))));
195
+ let extensionPoints = Stdlib_Array.filterMap(Stdlib_Option.getOr(Stdlib_Option.flatMap(obj["extensionPoints"], Stdlib_JSON.Decode.array), []), ep => Stdlib_Option.flatMap(Stdlib_JSON.Decode.object(ep), epo => {
196
+ let match = strOf(epo, "name");
197
+ let match$1 = strOf(epo, "eventTopic");
198
+ if (match !== undefined && match$1 !== undefined) {
199
+ return {
200
+ name: match,
201
+ commandTopic: Stdlib_Option.getOr(strOf(epo, "commandTopic"), ""),
202
+ eventTopic: match$1
203
+ };
204
+ }
205
+ }));
206
+ return {
207
+ id: match,
208
+ status: match$1,
209
+ eventCollector: Stdlib_Option.getOr(strOf(obj, "eventCollector"), ""),
210
+ extensions: extensions,
211
+ extensionPoints: extensionPoints,
212
+ dcbEventLog: dcbEventLog
213
+ };
214
+ }
215
+
216
+ function projectionOfDefinition(d) {
217
+ return {
218
+ id: d.id,
219
+ status: "",
220
+ eventCollector: d.eventCollector,
221
+ extensions: d.extensions,
222
+ extensionPoints: d.extensionPoints,
223
+ dcbEventLog: Primitive_option.fromNullable(d.dcbEventLog)
224
+ };
225
+ }
226
+
227
+ function pluginNameOfId(id) {
228
+ return Stdlib_Option.getOr(id.split("@")[0], "");
229
+ }
230
+
231
+ async function trySubscribe(queueArn, topicArn, label) {
232
+ if (queueArn === "" || topicArn === "") {
233
+ return;
234
+ }
235
+ try {
236
+ await SNS_Helpers$AwsSdk.subscribeQueueToTopic(queueArn, topicArn);
237
+ HandlerFactoryHelpersMjs.log.info(`subscribed ` + label + `: ` + topicArn + ` -> ` + queueArn, {
238
+ comp: "manageSubscriptions"
239
+ });
240
+ return;
241
+ } catch (raw_exn) {
242
+ let exn = Primitive_exceptions.internalToException(raw_exn);
243
+ let prim1_comp = "manageSubscriptions";
244
+ let prim1_detail = exnMessage(exn);
245
+ let prim1 = {
246
+ comp: prim1_comp,
247
+ detail: prim1_detail
248
+ };
249
+ HandlerFactoryHelpersMjs.log.error(`subscribe failed ` + label + `: ` + topicArn + ` -> ` + queueArn, prim1);
250
+ return;
251
+ }
252
+ }
253
+
254
+ async function tryUnsubscribe(queueArn, topicArn, label) {
255
+ if (queueArn === "" || topicArn === "") {
256
+ return;
257
+ }
258
+ try {
259
+ await SNS_Helpers$AwsSdk.unsubscribeQueueFromTopic(queueArn, topicArn);
260
+ HandlerFactoryHelpersMjs.log.info(`unsubscribed ` + label + `: ` + topicArn + ` -> ` + queueArn, {
261
+ comp: "manageSubscriptions"
262
+ });
263
+ return;
264
+ } catch (raw_exn) {
265
+ let exn = Primitive_exceptions.internalToException(raw_exn);
266
+ let prim1_comp = "manageSubscriptions";
267
+ let prim1_detail = exnMessage(exn);
268
+ let prim1 = {
269
+ comp: prim1_comp,
270
+ detail: prim1_detail
271
+ };
272
+ HandlerFactoryHelpersMjs.log.error(`unsubscribe failed ` + label + `: ` + topicArn + ` -> ` + queueArn, prim1);
273
+ return;
274
+ }
275
+ }
276
+
277
+ let connectedFilter = [[
278
+ "status",
279
+ "Contains",
280
+ {
281
+ TAG: "String",
282
+ _0: "Connected"
283
+ }
284
+ ]];
285
+
286
+ async function scanConnectedPeers(tableName, excludeId) {
287
+ let rows = await HandlerFactoryHelpersMjs.scanByTableName(tableName, connectedFilter, 1000);
288
+ return Stdlib_Array.filterMap(rows, projectPluginRow).filter(state => state.id !== excludeId);
289
+ }
290
+
291
+ function makeManageSubscriptions(tableName) {
292
+ if (tableName === "" || tableName === "NOT_AVAILABLE") {
293
+ return;
294
+ } else {
295
+ return async (pluginDef, action) => {
296
+ let isConnect = action === "connect";
297
+ let op = isConnect ? trySubscribe : tryUnsubscribe;
298
+ let peers = await scanConnectedPeers(tableName, pluginDef.id);
299
+ let skip;
300
+ if (isConnect) {
301
+ skip = false;
302
+ } else {
303
+ let myName = pluginNameOfId(pluginDef.id);
304
+ let sibling = peers.find(p => pluginNameOfId(p.id) === myName);
305
+ if (sibling !== undefined) {
306
+ HandlerFactoryHelpersMjs.log.info(`disconnect skipped for ` + pluginDef.id + `: sibling version ` + sibling.id + ` still Connected and shares the same EC queue / EP topics`, {
307
+ comp: "manageSubscriptions"
308
+ });
309
+ skip = true;
310
+ } else {
311
+ skip = false;
312
+ }
313
+ }
314
+ if (skip) {
315
+ return;
316
+ }
317
+ for (let i = 0, i_finish = pluginDef.extensions.length; i < i_finish; ++i) {
318
+ let ext = pluginDef.extensions[i];
319
+ for (let j = 0, j_finish = peers.length; j < j_finish; ++j) {
320
+ let peer = peers[j];
321
+ let peerEp = peer.extensionPoints.find(ep => ep.name === ext.extensionPointName);
322
+ if (peerEp !== undefined) {
323
+ await op(pluginDef.eventCollector, peerEp.eventTopic, ext.extensionPointName + ` -> ` + pluginDef.id);
324
+ }
325
+ }
326
+ }
327
+ for (let i$1 = 0, i_finish$1 = pluginDef.extensionPoints.length; i$1 < i_finish$1; ++i$1) {
328
+ let ep = pluginDef.extensionPoints[i$1];
329
+ for (let j$1 = 0, j_finish$1 = peers.length; j$1 < j_finish$1; ++j$1) {
330
+ let peer$1 = peers[j$1];
331
+ let match = peer$1.extensions.find(e => e.extensionPointName === ep.name);
332
+ if (match !== undefined) {
333
+ await op(peer$1.eventCollector, ep.eventTopic, ep.name + ` -> ` + peer$1.id);
334
+ }
335
+ }
336
+ }
337
+ for (let i$2 = 0, i_finish$2 = pluginDef.extensions.length; i$2 < i_finish$2; ++i$2) {
338
+ let ext$1 = pluginDef.extensions[i$2];
339
+ for (let j$2 = 0, j_finish$2 = ext$1.dcbSources.length; j$2 < j_finish$2; ++j$2) {
340
+ let dcbSourceName = ext$1.dcbSources[j$2];
341
+ let peer$2 = peers.find(p => {
342
+ let l = p.dcbEventLog;
343
+ if (l !== undefined) {
344
+ return l.name === dcbSourceName;
345
+ } else {
346
+ return false;
347
+ }
348
+ });
349
+ if (peer$2 !== undefined) {
350
+ let l = peer$2.dcbEventLog;
351
+ if (l !== undefined) {
352
+ await op(pluginDef.eventCollector, l.eventTopicArn, `dcb ` + dcbSourceName + ` -> ` + pluginDef.id);
353
+ }
354
+ }
355
+ }
356
+ }
357
+ let myDcb = pluginDef.dcbEventLog;
358
+ if (myDcb === undefined) {
359
+ return;
360
+ }
361
+ for (let j$3 = 0, j_finish$3 = peers.length; j$3 < j_finish$3; ++j$3) {
362
+ let peer$3 = peers[j$3];
363
+ let consuming = peer$3.extensions.some(e => e.dcbSources.includes(myDcb.name));
364
+ if (consuming) {
365
+ await op(peer$3.eventCollector, myDcb.eventTopicArn, `dcb ` + myDcb.name + ` -> ` + peer$3.id);
366
+ }
367
+ }
368
+ };
369
+ }
370
+ }
371
+
372
+ function manageForDefinition(manage) {
373
+ return Stdlib_Option.map(manage, m => ((d, a) => m(projectionOfDefinition(d), a)));
374
+ }
375
+
376
+ async function reconcileSubscriptionsOnce(tableName, manage) {
377
+ if (manage === undefined) {
378
+ return;
379
+ }
380
+ if (tableName === "" || tableName === "NOT_AVAILABLE") {
381
+ return;
382
+ }
383
+ try {
384
+ let rows = await HandlerFactoryHelpersMjs.scanByTableName(tableName, connectedFilter, 1000);
385
+ for (let i = 0, i_finish = rows.length; i < i_finish; ++i) {
386
+ let state = projectPluginRow(rows[i]);
387
+ if (state !== undefined) {
388
+ try {
389
+ await manage(state, "connect");
390
+ } catch (raw_exn) {
391
+ let exn = Primitive_exceptions.internalToException(raw_exn);
392
+ let prim1_comp = "reconcileSubscriptions";
393
+ let prim1_detail = exnMessage(exn);
394
+ let prim1 = {
395
+ comp: prim1_comp,
396
+ detail: prim1_detail
397
+ };
398
+ HandlerFactoryHelpersMjs.log.warn("manageSubscriptions failed", prim1);
399
+ }
400
+ }
401
+ }
402
+ return;
403
+ } catch (raw_exn$1) {
404
+ let exn$1 = Primitive_exceptions.internalToException(raw_exn$1);
405
+ let prim1_comp$1 = "reconcileSubscriptions";
406
+ let prim1_detail$1 = exnMessage(exn$1);
407
+ let prim1$1 = {
408
+ comp: prim1_comp$1,
409
+ detail: prim1_detail$1
410
+ };
411
+ HandlerFactoryHelpersMjs.log.warn("scan failed", prim1$1);
412
+ return;
413
+ }
414
+ }
415
+
416
+ let environment = Stdlib_Option.getOr(process.env["Environment"], "unknown");
417
+
418
+ let runtimeOps = {
419
+ messagePublish: {
420
+ sendMessageToChannel: Util_PluginMessage_Runtime$ReventlessAws.sendMessage
421
+ }
422
+ };
423
+
424
+ let invalidNameChars = /[^.\-_a-zA-Z0-9]/g;
425
+
426
+ function resourceNaming_validateName(n) {
427
+ return n.replace(invalidNameChars, "_");
428
+ }
429
+
430
+ function resourceNaming_urnName(arn) {
431
+ return Stdlib_Option.getOr(Stdlib_Option.filter(arn.split(":")[5], s => s !== ""), "unknown");
432
+ }
433
+
434
+ let resourceNaming = {
435
+ validateName: resourceNaming_validateName,
436
+ urnName: resourceNaming_urnName
437
+ };
438
+
439
+ function makeQueryEngine(pluginReadModelTableName) {
440
+ return {
441
+ scan: (param, filterConfigs, limit) => HandlerFactoryHelpersMjs.scanByTableName(pluginReadModelTableName, filterConfigs, limit),
442
+ query: async (param, param$1, param$2, param$3, param$4, param$5, param$6) => Stdlib_JsError.throwWithMessage("QueryEngine.query not available in bundled Plugin EventCollector")
443
+ };
444
+ }
445
+
446
+ function makeScheduler(schedulerRoleArn) {
447
+ return {
448
+ createSchedule: ScheduledPublisher_CloudWatchEvents_Runtime$ReventlessAws.createSchedule(schedulerRoleArn),
449
+ deleteSchedule: ScheduledPublisher_CloudWatchEvents_Runtime$ReventlessAws.deleteSchedule
450
+ };
451
+ }
452
+
453
+ function makeCommandTopicResources(config) {
454
+ if (config.schedulerQueueArn === "") {
455
+ return [];
456
+ } else {
457
+ return [{
458
+ name: config.schedulerQueueName,
459
+ id: config.schedulerQueueName,
460
+ urn: config.schedulerQueueArn,
461
+ resourceInfo: "NoInfo",
462
+ service: "unknown",
463
+ role: "",
464
+ region: "",
465
+ resourceType: "",
466
+ configuration: {},
467
+ tags: {}
468
+ }];
469
+ }
470
+ }
471
+
472
+ function makePublishToEventTopic(eventTopicArn) {
473
+ let topic = {
474
+ id: eventTopicArn,
475
+ name: eventTopicArn,
476
+ arn: eventTopicArn
477
+ };
478
+ return (id, meta, json) => EventTopicPublisher_SNS_Runtime$ReventlessAws.publish(topic, id, meta, json);
479
+ }
480
+
481
+ function makePublishJsons(queueUrl) {
482
+ let queue = {
483
+ id: queueUrl,
484
+ name: queueUrl,
485
+ arn: ""
486
+ };
487
+ return CommandTopicChannel_SQS_Runtime$ReventlessAws.publishJsons(queue, "SQS_FIFO");
488
+ }
489
+
490
+ function buildPublishToAggregates(map) {
491
+ return Object.fromEntries(Object.entries(map).map(param => [
492
+ param[0],
493
+ makePublishJsons(Stdlib_Option.getOr(process.env[param[1]], ""))
494
+ ]));
495
+ }
496
+
497
+ function extensionPublishDicts(config, ext) {
498
+ let resolve = (names, envVarNames) => Object.fromEntries(Stdlib_Array.filterMap(names, name => Stdlib_Option.map(Stdlib_Option.filter(Stdlib_Option.flatMap(envVarNames[name], envVarName => process.env[envVarName]), queueUrl => queueUrl !== ""), queueUrl => [
499
+ name,
500
+ makePublishJsons(queueUrl)
501
+ ])));
502
+ return {
503
+ publishToAggregates: resolve(ext.aggregateNames, config.publishToAggregates),
504
+ publishToReadModels: resolve(ext.readModelNames, config.readModelQueueUrls),
505
+ readModelNamesForSourceName: Object.fromEntries([[
506
+ ext.extensionPointName,
507
+ Stdlib_Option.getOr(config.readModelNamesForSourceName[ext.extensionPointName], [])
508
+ ]])
509
+ };
510
+ }
511
+
512
+ function warnSkippedExtension(ext) {
513
+ HandlerFactoryHelpersMjs.log.warn(`extension '` + ext.name + `' missing module specifier(s); skipping. specModule=` + ext.specModule + `, mappingsModule=` + ext.mappingsModule + `, delegateModule=` + ext.delegateModule, {
514
+ comp: "EventCollectorEntryPoint"
515
+ });
516
+ }
517
+
518
+ function loadPluginDefinition() {
519
+ try {
520
+ return JSON.parse(Nodefs.readFileSync(new URL("./pluginDefinition.json", `file://` + process.cwd() + `/`), "utf-8"));
521
+ } catch (raw_exn) {
522
+ let exn = Primitive_exceptions.internalToException(raw_exn);
523
+ return Stdlib_JsError.throwWithMessage("Failed to load pluginDefinition.json from asset zip: " + exnMessage(exn));
524
+ }
525
+ }
526
+
527
+ function loadUiFragments() {
528
+ try {
529
+ let json = JSON.parse(Nodefs.readFileSync(new URL("./uiFragments.json", `file://` + process.cwd() + `/`), "utf-8"));
530
+ if (json === null) {
531
+ return;
532
+ } else {
533
+ return json;
534
+ }
535
+ } catch (exn) {
536
+ return;
537
+ }
538
+ }
539
+
540
+ function pushHandler(d, key, h) {
541
+ let arr = d[key];
542
+ if (arr !== undefined) {
543
+ arr.push(h);
544
+ } else {
545
+ d[key] = [h];
546
+ }
547
+ }
548
+
549
+ function makeSqsHandlerBundle(input) {
550
+ let outgoingExtensionPointEventHandlers = {};
551
+ input.epHandlers.forEach(eph => {
552
+ eph.aggregateNames.forEach(k => pushHandler(outgoingExtensionPointEventHandlers, k, eph.outgoingHandler));
553
+ });
554
+ let c = input.connectExtensionHandler;
555
+ let incomingConnectExtensionEventHandlers = c !== undefined ? Object.fromEntries([[
556
+ c.extensionPointName,
557
+ [c.incomingHandler]
558
+ ]]) : ({});
559
+ let outgoingExtensionEventHandlers = {};
560
+ let incomingExtensionEventHandlers = {};
561
+ input.extensionHandlers.forEach(eh => {
562
+ eh.aggregateNames.forEach(k => pushHandler(outgoingExtensionEventHandlers, k, eh.outgoingHandler));
563
+ pushHandler(incomingExtensionEventHandlers, eh.extensionPointName, eh.incomingHandler);
564
+ });
565
+ let pluginDefinition = input.pluginDefinition;
566
+ let Callback = Plugin_Callback$ReventlessCore.Make({
567
+ pluginDefinition: pluginDefinition,
568
+ incomingConnectExtensionEventHandlers: incomingConnectExtensionEventHandlers,
569
+ outgoingExtensionPointEventHandlers: outgoingExtensionPointEventHandlers,
570
+ outgoingExtensionEventHandlers: outgoingExtensionEventHandlers,
571
+ incomingExtensionEventHandlers: incomingExtensionEventHandlers
572
+ });
573
+ let queue_id = input.queueUrl;
574
+ let queue_name = input.queueUrl;
575
+ let queue = {
576
+ id: queue_id,
577
+ name: queue_name,
578
+ arn: ""
579
+ };
580
+ return {
581
+ sqsHandler: EventCollectorChannel_SQS_Runtime$ReventlessAws.handleDynamoDbOrSqsEvent(queue, Callback.handleJsonEvents),
582
+ comp: `Plugin(` + input.pluginDefinition.id + `)`
583
+ };
584
+ }
585
+
586
+ function makeHandler(bundlePromise) {
587
+ return async (event, context) => {
588
+ HandlerFactoryHelpersMjs.setRequestId(context.awsRequestId);
589
+ let records = event.Records;
590
+ let prim0 = `processing ` + records.length.toString() + ` record(s)`;
591
+ HandlerFactoryHelpersMjs.log.debug(prim0, {
592
+ comp: "PluginEventCollectorRuntime"
593
+ });
594
+ let bundle = await bundlePromise;
595
+ await HandlerFactoryHelpersMjs.runEffect(bundle.sqsHandler(event, context), {
596
+ correlationId: HandlerFactoryHelpersMjs.extractMetaField(records, "correlationId"),
597
+ causationId: HandlerFactoryHelpersMjs.extractMetaField(records, "causationId"),
598
+ comp: bundle.comp,
599
+ timestamp: HandlerFactoryHelpersMjs.extractSentTimestamp(records),
600
+ retryCount: HandlerFactoryHelpersMjs.extractRetryCount(records)
601
+ });
602
+ return "";
603
+ };
604
+ }
605
+
606
+ export {
607
+ setRequestId,
608
+ runEffect,
609
+ extractMetaField,
610
+ extractSentTimestamp,
611
+ extractRetryCount,
612
+ logDebug,
613
+ logInfo,
614
+ logWarn,
615
+ logError,
616
+ scanByTableName,
617
+ exnMessage,
618
+ jsOption,
619
+ strOf,
620
+ strArrOf,
621
+ strDictOf,
622
+ parseHandlerConfig,
623
+ projectPluginRow,
624
+ projectionOfDefinition,
625
+ pluginNameOfId,
626
+ trySubscribe,
627
+ tryUnsubscribe,
628
+ connectedFilter,
629
+ scanConnectedPeers,
630
+ makeManageSubscriptions,
631
+ manageForDefinition,
632
+ reconcileSubscriptionsOnce,
633
+ environment,
634
+ runtimeOps,
635
+ invalidNameChars,
636
+ resourceNaming,
637
+ makeQueryEngine,
638
+ makeScheduler,
639
+ makeCommandTopicResources,
640
+ makePublishToEventTopic,
641
+ makePublishJsons,
642
+ buildPublishToAggregates,
643
+ extensionPublishDicts,
644
+ warnSkippedExtension,
645
+ loadPluginDefinition,
646
+ loadUiFragments,
647
+ pushHandler,
648
+ makeSqsHandlerBundle,
649
+ makeHandler,
650
+ }
651
+ /* environment Not a pure module */