@reventlessdev/reventless-core 3.0.0-alpha.321 → 3.0.0-alpha.323
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.
- package/CHANGELOG.md +14 -0
- package/package.json +6 -6
- package/src/components/Aggregate/Aggregate_Callback.res +1 -1
- package/src/components/Aggregate/Aggregate_Callback.res.mjs +1 -1
- package/src/components/AutomationSlice/AutomationSlice_Builder.res +12 -2
- package/src/components/AutomationSlice/AutomationSlice_Builder.res.mjs +4 -4
- package/src/components/AutomationSlice/AutomationSlice_Callback.res +179 -53
- package/src/components/AutomationSlice/AutomationSlice_Callback.res.mjs +221 -102
- package/src/components/EventLog/EventLog.res +5 -3
- package/src/components/EventLog/EventLog_Builder.res +2 -2
- package/src/components/EventLog/EventLog_Builder.res.mjs +1 -1
- package/src/components/EventLog/EventLog_Operations.res +2 -2
- package/src/components/EventLog/EventLog_Operations.res.mjs +2 -2
- package/tests/aggregate/AggregateCacheTest.res +2 -2
- package/tests/aggregate/AggregateCacheTest.res.mjs +2 -2
- package/tests/aggregate/AggregateConflictTest.res +2 -2
- package/tests/aggregate/AggregateConflictTest.res.mjs +2 -2
- package/tests/aggregate/AggregateFixtures.res +2 -2
- package/tests/aggregate/AggregateFixtures.res.mjs +2 -2
- package/tests/aggregate/AggregateRepeatTest.res +2 -2
- package/tests/aggregate/AggregateRepeatTest.res.mjs +2 -2
- package/tests/aggregate/AggregateSnapshotTest.res +2 -2
- package/tests/aggregate/AggregateSnapshotTest.res.mjs +6 -6
- package/tests/commandgenerator/OwnerActingTest.res +2 -2
- package/tests/commandgenerator/OwnerActingTest.res.mjs +2 -2
- package/tests/pii/PiiMember.res +5 -0
- package/tests/pii/PiiMember.res.mjs +6 -0
- package/tests/pii/PiiPpxTest.res +8 -0
- package/tests/pii/PiiPpxTest.res.mjs +10 -0
|
@@ -3,13 +3,14 @@
|
|
|
3
3
|
import * as Sury from "sury";
|
|
4
4
|
import * as Stdlib_Dict from "@rescript/runtime/lib/es6/Stdlib_Dict.js";
|
|
5
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
6
|
import * as Stdlib_JsExn from "@rescript/runtime/lib/es6/Stdlib_JsExn.js";
|
|
8
7
|
import * as Clock from "effect/Clock";
|
|
9
8
|
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
9
|
+
import * as Stdlib_Result from "@rescript/runtime/lib/es6/Stdlib_Result.js";
|
|
10
10
|
import * as Effect from "effect/Effect";
|
|
11
|
+
import * as Pii$Reventless from "@reventlessdev/reventless-spec/src/components/Pii.res.mjs";
|
|
11
12
|
import * as Clock$Reventless from "@reventlessdev/reventless-spec/src/components/Clock.res.mjs";
|
|
12
|
-
import * as
|
|
13
|
+
import * as Primitive_object from "@rescript/runtime/lib/es6/Primitive_object.js";
|
|
13
14
|
import * as Message$Reventless from "@reventlessdev/reventless-spec/src/types/Message.res.mjs";
|
|
14
15
|
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
|
|
15
16
|
import * as Util_Sury$Reventless from "@reventlessdev/reventless-spec/src/util/Util_Sury.res.mjs";
|
|
@@ -84,6 +85,98 @@ function Make(Spec) {
|
|
|
84
85
|
};
|
|
85
86
|
let readsClock = Automation.mappings.some(M => M.sourceName === Clock$Reventless.name);
|
|
86
87
|
let makeMeta = () => Message$ReventlessCore.generateMeta(Spec.targetName, undefined, undefined, undefined, undefined, undefined, undefined);
|
|
88
|
+
let personalFields = Pii$Reventless.recordFields(Spec.todoItemSchema);
|
|
89
|
+
let keyField = "$key";
|
|
90
|
+
let fingerprintPurpose = `automationWorkItem:` + Spec.name;
|
|
91
|
+
let warnedUnkeyed = {
|
|
92
|
+
contents: false
|
|
93
|
+
};
|
|
94
|
+
let storedKey = (key, capabilities) => {
|
|
95
|
+
if (Primitive_object.equal(personalFields, [])) {
|
|
96
|
+
return key;
|
|
97
|
+
}
|
|
98
|
+
let fingerprint = capabilities.secrets.fingerprint(fingerprintPurpose, key);
|
|
99
|
+
if (fingerprint.TAG === "Ok") {
|
|
100
|
+
return fingerprint._0;
|
|
101
|
+
}
|
|
102
|
+
let why = fingerprint._0._0;
|
|
103
|
+
if (Pii$Reventless.Provider.isRequired()) {
|
|
104
|
+
Effect.runSync(EffectLogger$ReventlessCore.logError(`AutomationSlice(` + Spec.name + `)`, undefined, `a work item was not stored: its row id cannot be fingerprinted (` + why + `)`));
|
|
105
|
+
return;
|
|
106
|
+
} else {
|
|
107
|
+
if (!warnedUnkeyed.contents) {
|
|
108
|
+
warnedUnkeyed.contents = true;
|
|
109
|
+
Effect.runSync(EffectLogger$ReventlessCore.logWarn(`AutomationSlice(` + Spec.name + `)`, undefined, `work items carrying personal data are keyed in the clear: no key to fingerprint them with (` + why + `)`));
|
|
110
|
+
}
|
|
111
|
+
return key;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
let storedItem = async (key, item) => {
|
|
115
|
+
let json = Util_Sury$Reventless.toJson(item, Spec.todoItemSchema);
|
|
116
|
+
let match = personalFields[0];
|
|
117
|
+
if (match === undefined) {
|
|
118
|
+
return {
|
|
119
|
+
TAG: "Ok",
|
|
120
|
+
_0: json
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
if (typeof json !== "object" || json === null || Array.isArray(json)) {
|
|
124
|
+
return {
|
|
125
|
+
TAG: "Ok",
|
|
126
|
+
_0: json
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
let data = Object.assign({}, json);
|
|
130
|
+
data[keyField] = key;
|
|
131
|
+
return Stdlib_Result.mapError(Stdlib_Result.map(await Pii$Reventless.sealFields(personalFields.concat([[
|
|
132
|
+
keyField,
|
|
133
|
+
match[1]
|
|
134
|
+
]]), Spec.name, undefined, true, data), d => (d)), Pii$Reventless.errorMessage);
|
|
135
|
+
};
|
|
136
|
+
let openRow = async (id, row) => {
|
|
137
|
+
let decode = (json, key) => {
|
|
138
|
+
let item;
|
|
139
|
+
try {
|
|
140
|
+
item = Util_Sury$Reventless.fromJson(json, Spec.todoItemSchema);
|
|
141
|
+
} catch (raw_exn) {
|
|
142
|
+
let exn = Primitive_exceptions.internalToException(raw_exn);
|
|
143
|
+
return {
|
|
144
|
+
TAG: "Unopened",
|
|
145
|
+
_0: Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(exn), Stdlib_JsExn.message), "unknown")
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
return {
|
|
149
|
+
TAG: "Open",
|
|
150
|
+
key: key,
|
|
151
|
+
item: item
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
let data = row.item;
|
|
155
|
+
if (typeof data !== "object" || data === null || Array.isArray(data)) {
|
|
156
|
+
return decode(data, id);
|
|
157
|
+
}
|
|
158
|
+
if (!Primitive_object.notequal(personalFields, [])) {
|
|
159
|
+
return decode(data, id);
|
|
160
|
+
}
|
|
161
|
+
let e = await Pii$Reventless.openFields(personalFields.map(param => param[0]).concat([keyField]), data);
|
|
162
|
+
if (e.TAG !== "Ok") {
|
|
163
|
+
return {
|
|
164
|
+
TAG: "Unopened",
|
|
165
|
+
_0: Pii$Reventless.errorMessage(e._0)
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
let data$1 = e._0;
|
|
169
|
+
let field = Pii$Reventless.goneField(Spec.todoItemSchema, data$1);
|
|
170
|
+
if (field !== undefined) {
|
|
171
|
+
return {
|
|
172
|
+
TAG: "Gone",
|
|
173
|
+
_0: field
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
let key = Stdlib_Option.getOr(Stdlib_Option.flatMap(data$1[keyField], Stdlib_JSON.Decode.string), id);
|
|
177
|
+
Stdlib_Dict.$$delete(data$1, keyField);
|
|
178
|
+
return decode(data$1, key);
|
|
179
|
+
};
|
|
87
180
|
let processingTimeoutMs = 15 * 60 * 1000;
|
|
88
181
|
let afterFailedAttempt = row => {
|
|
89
182
|
let retryCount = row.retryCount + 1 | 0;
|
|
@@ -92,6 +185,31 @@ function Make(Spec) {
|
|
|
92
185
|
newrecord.status = retryCount >= Spec.maxRetries ? "Abandoned" : "Failed";
|
|
93
186
|
return newrecord;
|
|
94
187
|
};
|
|
188
|
+
let abandonmentCommand = async (id, row) => {
|
|
189
|
+
let match = await openRow(id, row);
|
|
190
|
+
switch (match.TAG) {
|
|
191
|
+
case "Open" :
|
|
192
|
+
return Stdlib_Option.flatMap(Automation.onExhausted(match.key, match.item), param => {
|
|
193
|
+
let commandJson;
|
|
194
|
+
try {
|
|
195
|
+
commandJson = Util_Sury$Reventless.toJson(param[1], Spec.commandSchema);
|
|
196
|
+
} catch (exn) {
|
|
197
|
+
Effect.runSync(EffectLogger$ReventlessCore.logError(`AutomationSlice(` + Spec.name + `)`, undefined, `retries exhausted for ` + id + `, and the abandonment command could not be encoded`));
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
return {
|
|
201
|
+
id: param[0],
|
|
202
|
+
meta: makeMeta(),
|
|
203
|
+
commandJson: commandJson
|
|
204
|
+
};
|
|
205
|
+
});
|
|
206
|
+
case "Gone" :
|
|
207
|
+
return;
|
|
208
|
+
case "Unopened" :
|
|
209
|
+
Effect.runSync(EffectLogger$ReventlessCore.logError(`AutomationSlice(` + Spec.name + `)`, undefined, `retries exhausted for ` + id + `, and its item could not be decoded to announce it`));
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
};
|
|
95
213
|
let Route = AutomationSlice_Route$ReventlessCore.Make(Spec)(Automation);
|
|
96
214
|
let recordedAtOf = time => {
|
|
97
215
|
let millis = new Date(time).getTime();
|
|
@@ -101,26 +219,32 @@ function Make(Spec) {
|
|
|
101
219
|
return millis;
|
|
102
220
|
}
|
|
103
221
|
};
|
|
104
|
-
let apply = param => {
|
|
105
|
-
param.collected
|
|
106
|
-
|
|
107
|
-
let match =
|
|
108
|
-
|
|
109
|
-
|
|
222
|
+
let apply = async (param, capabilities) => {
|
|
223
|
+
let collected = param.collected;
|
|
224
|
+
for (let i = 0, i_finish = collected.length; i < i_finish; ++i) {
|
|
225
|
+
let match = collected[i];
|
|
226
|
+
let key = match[0];
|
|
227
|
+
let id = storedKey(key, capabilities);
|
|
228
|
+
if (id !== undefined && !Stdlib_Option.isSome(todoItems[id])) {
|
|
229
|
+
let why = await storedItem(key, match[1]);
|
|
230
|
+
if (why.TAG === "Ok") {
|
|
231
|
+
let row_item = why._0;
|
|
232
|
+
let row_createdAt = new Date().toISOString();
|
|
233
|
+
let row_maxRetries = Spec.maxRetries;
|
|
234
|
+
let row = {
|
|
235
|
+
item: row_item,
|
|
236
|
+
status: "Pending",
|
|
237
|
+
createdAt: row_createdAt,
|
|
238
|
+
retryCount: 0,
|
|
239
|
+
maxRetries: row_maxRetries
|
|
240
|
+
};
|
|
241
|
+
todoItems[id] = row;
|
|
242
|
+
} else {
|
|
243
|
+
Effect.runSync(EffectLogger$ReventlessCore.logError(`AutomationSlice(` + Spec.name + `)`, undefined, `a work item was not stored: ` + why._0));
|
|
244
|
+
}
|
|
110
245
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
let row_maxRetries = Spec.maxRetries;
|
|
114
|
-
let row = {
|
|
115
|
-
item: row_item,
|
|
116
|
-
status: "Pending",
|
|
117
|
-
createdAt: row_createdAt,
|
|
118
|
-
retryCount: 0,
|
|
119
|
-
maxRetries: row_maxRetries
|
|
120
|
-
};
|
|
121
|
-
todoItems[id] = row;
|
|
122
|
-
});
|
|
123
|
-
Stdlib_Option.forEach(param.resolved, id => Stdlib_Option.forEach(todoItems[id], row => {
|
|
246
|
+
}
|
|
247
|
+
return Stdlib_Option.forEach(Stdlib_Option.flatMap(param.resolved, key => storedKey(key, capabilities)), id => Stdlib_Option.forEach(todoItems[id], row => {
|
|
124
248
|
let newrecord = {...row};
|
|
125
249
|
newrecord.completedAt = new Date().toISOString();
|
|
126
250
|
newrecord.status = "Completed";
|
|
@@ -143,8 +267,9 @@ function Make(Spec) {
|
|
|
143
267
|
});
|
|
144
268
|
});
|
|
145
269
|
};
|
|
146
|
-
let phase1 = (events, sliceCtx) => {
|
|
147
|
-
events.
|
|
270
|
+
let phase1 = async (events, sliceCtx, capabilities) => {
|
|
271
|
+
for (let i = 0, i_finish = events.length; i < i_finish; ++i) {
|
|
272
|
+
let json = events[i];
|
|
148
273
|
let context = Message$ReventlessCore.decode(json, Message$Reventless.contextSchema);
|
|
149
274
|
let recordedAt = recordedAtOf(context.meta.time);
|
|
150
275
|
let ctx;
|
|
@@ -159,12 +284,14 @@ function Make(Spec) {
|
|
|
159
284
|
let dict = Stdlib_JSON.Decode.object(json);
|
|
160
285
|
let eventPayload = dict !== undefined ? Stdlib_Option.getOr(dict["event"], json) : json;
|
|
161
286
|
let routed = Route.route(eventPayload, sourceName, context.id, ctx);
|
|
162
|
-
routed.
|
|
287
|
+
for (let j = 0, j_finish = routed.length; j < j_finish; ++j) {
|
|
288
|
+
await apply(routed[j], capabilities);
|
|
289
|
+
}
|
|
163
290
|
reschedule(routed, context.meta.msgId, Stdlib_Option.getOr(ctx.recordedAt, Date.now()));
|
|
164
291
|
if (sourceName === Clock$Reventless.name) {
|
|
165
|
-
|
|
292
|
+
AutomationSlice_Schedules$ReventlessCore.fired(schedules, context.id);
|
|
166
293
|
}
|
|
167
|
-
}
|
|
294
|
+
}
|
|
168
295
|
};
|
|
169
296
|
let rebuildSchedules = events => {
|
|
170
297
|
Object.keys(schedules).forEach(key => Stdlib_Dict.$$delete(schedules, key));
|
|
@@ -229,60 +356,64 @@ function Make(Spec) {
|
|
|
229
356
|
}
|
|
230
357
|
});
|
|
231
358
|
let commands = [];
|
|
232
|
-
pending.
|
|
233
|
-
let
|
|
234
|
-
let
|
|
235
|
-
let
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
359
|
+
for (let i = 0, i_finish = pending.length; i < i_finish; ++i) {
|
|
360
|
+
let match = pending[i];
|
|
361
|
+
let row = match[1];
|
|
362
|
+
let id = match[0];
|
|
363
|
+
let field = await openRow(id, row);
|
|
364
|
+
switch (field.TAG) {
|
|
365
|
+
case "Open" :
|
|
366
|
+
let match$1 = Automation.process(field.key, field.item, currentTime);
|
|
367
|
+
if (match$1 !== undefined) {
|
|
368
|
+
let targetId = match$1[0];
|
|
369
|
+
let newrecord = {...row};
|
|
370
|
+
newrecord.processedAt = new Date().toISOString();
|
|
371
|
+
newrecord.status = "Processing";
|
|
372
|
+
todoItems[id] = newrecord;
|
|
373
|
+
let commandJson;
|
|
374
|
+
try {
|
|
375
|
+
commandJson = Util_Sury$Reventless.toJson(match$1[1], Spec.commandSchema);
|
|
376
|
+
} catch (raw_exn) {
|
|
377
|
+
let exn = Primitive_exceptions.internalToException(raw_exn);
|
|
378
|
+
let errMsg = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(exn), Stdlib_JsExn.message), "unknown");
|
|
379
|
+
Effect.runSync(EffectLogger$ReventlessCore.logError(`AutomationSlice(` + Spec.name + `)`, undefined, `failed to encode command: ` + errMsg));
|
|
380
|
+
let updated = afterFailedAttempt(row);
|
|
381
|
+
todoItems[id] = updated;
|
|
382
|
+
if (updated.status === "Abandoned") {
|
|
383
|
+
newlyAbandoned.push(id);
|
|
384
|
+
}
|
|
385
|
+
commandJson = undefined;
|
|
386
|
+
}
|
|
387
|
+
Stdlib_Option.forEach(commandJson, commandJson => {
|
|
388
|
+
let msg_meta = makeMeta();
|
|
389
|
+
let msg = {
|
|
390
|
+
id: targetId,
|
|
391
|
+
meta: msg_meta,
|
|
392
|
+
commandJson: commandJson
|
|
393
|
+
};
|
|
394
|
+
commands.push(msg);
|
|
395
|
+
});
|
|
265
396
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
let
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
}
|
|
278
|
-
}
|
|
397
|
+
break;
|
|
398
|
+
case "Gone" :
|
|
399
|
+
Effect.runSync(EffectLogger$ReventlessCore.logInfo(`AutomationSlice(` + Spec.name + `)`, undefined, id + `: its ` + field._0 + ` was erased; nothing to do`));
|
|
400
|
+
let newrecord$1 = {...row};
|
|
401
|
+
newrecord$1.completedAt = new Date().toISOString();
|
|
402
|
+
newrecord$1.status = "Completed";
|
|
403
|
+
todoItems[id] = newrecord$1;
|
|
404
|
+
break;
|
|
405
|
+
case "Unopened" :
|
|
406
|
+
Effect.runSync(EffectLogger$ReventlessCore.logError(`AutomationSlice(` + Spec.name + `)`, undefined, `failed to decode todoItem: ` + field._0));
|
|
407
|
+
break;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
279
410
|
if (commands.length !== 0) {
|
|
280
411
|
try {
|
|
281
412
|
await publishJsons(commands);
|
|
282
|
-
} catch (raw_exn) {
|
|
283
|
-
let exn = Primitive_exceptions.internalToException(raw_exn);
|
|
284
|
-
let errMsg = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(exn), Stdlib_JsExn.message), "unknown");
|
|
285
|
-
Effect.runSync(EffectLogger$ReventlessCore.logError(`AutomationSlice(` + Spec.name + `)`, undefined, `failed to publish commands: ` + errMsg));
|
|
413
|
+
} catch (raw_exn$1) {
|
|
414
|
+
let exn$1 = Primitive_exceptions.internalToException(raw_exn$1);
|
|
415
|
+
let errMsg$1 = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(exn$1), Stdlib_JsExn.message), "unknown");
|
|
416
|
+
Effect.runSync(EffectLogger$ReventlessCore.logError(`AutomationSlice(` + Spec.name + `)`, undefined, `failed to publish commands: ` + errMsg$1));
|
|
286
417
|
pending.forEach(param => {
|
|
287
418
|
let id = param[0];
|
|
288
419
|
let current = todoItems[id];
|
|
@@ -301,38 +432,26 @@ function Make(Spec) {
|
|
|
301
432
|
});
|
|
302
433
|
}
|
|
303
434
|
}
|
|
304
|
-
let abandonmentCommands =
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
return Stdlib_Option.flatMap(Automation.onExhausted(id, item), param => {
|
|
313
|
-
let commandJson;
|
|
314
|
-
try {
|
|
315
|
-
commandJson = Util_Sury$Reventless.toJson(param[1], Spec.commandSchema);
|
|
316
|
-
} catch (exn) {
|
|
317
|
-
Effect.runSync(EffectLogger$ReventlessCore.logError(`AutomationSlice(` + Spec.name + `)`, undefined, `retries exhausted for ` + id + `, and the abandonment command could not be encoded`));
|
|
318
|
-
return;
|
|
435
|
+
let abandonmentCommands = [];
|
|
436
|
+
for (let i$1 = 0, i_finish$1 = newlyAbandoned.length; i$1 < i_finish$1; ++i$1) {
|
|
437
|
+
let id$1 = newlyAbandoned[i$1];
|
|
438
|
+
let row$1 = todoItems[id$1];
|
|
439
|
+
if (row$1 !== undefined) {
|
|
440
|
+
let command = await abandonmentCommand(id$1, row$1);
|
|
441
|
+
if (command !== undefined) {
|
|
442
|
+
abandonmentCommands.push(command);
|
|
319
443
|
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
meta: makeMeta(),
|
|
323
|
-
commandJson: commandJson
|
|
324
|
-
};
|
|
325
|
-
});
|
|
326
|
-
}));
|
|
444
|
+
}
|
|
445
|
+
}
|
|
327
446
|
if (abandonmentCommands.length === 0) {
|
|
328
447
|
return;
|
|
329
448
|
}
|
|
330
449
|
try {
|
|
331
450
|
return await publishJsons(abandonmentCommands);
|
|
332
|
-
} catch (raw_exn$
|
|
333
|
-
let exn$
|
|
334
|
-
let errMsg$
|
|
335
|
-
return Effect.runSync(EffectLogger$ReventlessCore.logError(`AutomationSlice(` + Spec.name + `)`, undefined, `failed to publish abandonment commands: ` + errMsg$
|
|
451
|
+
} catch (raw_exn$2) {
|
|
452
|
+
let exn$2 = Primitive_exceptions.internalToException(raw_exn$2);
|
|
453
|
+
let errMsg$2 = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(exn$2), Stdlib_JsExn.message), "unknown");
|
|
454
|
+
return Effect.runSync(EffectLogger$ReventlessCore.logError(`AutomationSlice(` + Spec.name + `)`, undefined, `failed to publish abandonment commands: ` + errMsg$2));
|
|
336
455
|
}
|
|
337
456
|
};
|
|
338
457
|
return {
|
|
@@ -34,8 +34,10 @@ type replay<'id, 'event> = 'id => promise<array<'event>>
|
|
|
34
34
|
// the delta read after seeding from a snapshot at seqNr = fromSeq.
|
|
35
35
|
type replayStream<'id, 'event> = ('id, ~fromSeq: int=?) => Stream.t<'event, string, unit>
|
|
36
36
|
// The same replay as envelopes, meta included — for a reader that needs to know
|
|
37
|
-
// which command caused each event, not only what happened.
|
|
38
|
-
|
|
37
|
+
// which command caused each event, not only what happened. No prime in the name:
|
|
38
|
+
// the AWS shell passes the compiled operations module as this record, so each
|
|
39
|
+
// field must spell the same as its export (`x'` exports as `x$p`).
|
|
40
|
+
type replayEnvelopes<'id, 'event> = (
|
|
39
41
|
'id,
|
|
40
42
|
~fromSeq: int=?,
|
|
41
43
|
) => Stream.t<Message.event'<'id, 'event>, string, unit>
|
|
@@ -58,7 +60,7 @@ module type T = {
|
|
|
58
60
|
append: append<Spec.Id.t, Message.event'<Spec.Id.t, Spec.event>>,
|
|
59
61
|
replay: replay<Spec.Id.t, Spec.event>,
|
|
60
62
|
replayStream: replayStream<Spec.Id.t, Spec.event>,
|
|
61
|
-
|
|
63
|
+
replayEnvelopes: replayEnvelopes<Spec.Id.t, Spec.event>,
|
|
62
64
|
appendStream: appendStream<Spec.Id.t, Spec.event>,
|
|
63
65
|
latestSnapshot: latestSnapshot<Spec.Id.t>,
|
|
64
66
|
writeSnapshot: writeSnapshot<Spec.Id.t>,
|
|
@@ -9,7 +9,7 @@ module Make = (
|
|
|
9
9
|
append: EventLog.append<Spec.Id.t, Message.event'<Spec.Id.t, Spec.event>>,
|
|
10
10
|
replay: EventLog.replay<Spec.Id.t, Spec.event>,
|
|
11
11
|
replayStream: EventLog.replayStream<Spec.Id.t, Spec.event>,
|
|
12
|
-
|
|
12
|
+
replayEnvelopes: EventLog.replayEnvelopes<Spec.Id.t, Spec.event>,
|
|
13
13
|
appendStream: EventLog.appendStream<Spec.Id.t, Spec.event>,
|
|
14
14
|
latestSnapshot: EventLog.latestSnapshot<Spec.Id.t>,
|
|
15
15
|
writeSnapshot: EventLog.writeSnapshot<Spec.Id.t>,
|
|
@@ -59,7 +59,7 @@ module Make = (
|
|
|
59
59
|
append: Ops.append,
|
|
60
60
|
replay: Ops.replay,
|
|
61
61
|
replayStream: Ops.replayStream,
|
|
62
|
-
|
|
62
|
+
replayEnvelopes: Ops.replayEnvelopes,
|
|
63
63
|
appendStream: Ops.appendStream,
|
|
64
64
|
latestSnapshot: Ops.latestSnapshot,
|
|
65
65
|
writeSnapshot: Ops.writeSnapshot,
|
|
@@ -35,7 +35,7 @@ function Make(Spec) {
|
|
|
35
35
|
append: Ops.append,
|
|
36
36
|
replay: Ops.replay,
|
|
37
37
|
replayStream: Ops.replayStream,
|
|
38
|
-
|
|
38
|
+
replayEnvelopes: Ops.replayEnvelopes,
|
|
39
39
|
appendStream: Ops.appendStream,
|
|
40
40
|
latestSnapshot: Ops.latestSnapshot,
|
|
41
41
|
writeSnapshot: Ops.writeSnapshot
|
|
@@ -10,7 +10,7 @@ module type T = {
|
|
|
10
10
|
let append: EventLog.append<Spec.Id.t, Message.event'<Spec.Id.t, Spec.event>>
|
|
11
11
|
let replay: EventLog.replay<Spec.Id.t, Spec.event>
|
|
12
12
|
let replayStream: EventLog.replayStream<Spec.Id.t, Spec.event>
|
|
13
|
-
let
|
|
13
|
+
let replayEnvelopes: EventLog.replayEnvelopes<Spec.Id.t, Spec.event>
|
|
14
14
|
let appendStream: EventLog.appendStream<Spec.Id.t, Spec.event>
|
|
15
15
|
let latestSnapshot: EventLog.latestSnapshot<Spec.Id.t>
|
|
16
16
|
let writeSnapshot: EventLog.writeSnapshot<Spec.Id.t>
|
|
@@ -329,7 +329,7 @@ module Make = (Spec: ReventlessInfra.EventLog.T, Ops: Ops with module Spec = Spe
|
|
|
329
329
|
)
|
|
330
330
|
}
|
|
331
331
|
|
|
332
|
-
let
|
|
332
|
+
let replayEnvelopes = (id, ~fromSeq=?) => {
|
|
333
333
|
let idStr = id->Spec.Id.toString
|
|
334
334
|
Ops.storage.replayStream(idStr, ~fromSeq?)->Stream.mapEffect(json =>
|
|
335
335
|
openAndDecode(idStr, json)->Effect.map(event => {
|
|
@@ -305,7 +305,7 @@ function Make(Spec) {
|
|
|
305
305
|
return Stdlib_JsError.throwWithMessage(`EventLog.replay: Error: id:` + id + `: Couldn't decode the event's meta: ` + Util_Sury$Reventless.exnMessage(exn, undefined));
|
|
306
306
|
}
|
|
307
307
|
};
|
|
308
|
-
let
|
|
308
|
+
let replayEnvelopes = (id, fromSeq) => {
|
|
309
309
|
let idStr = Spec.Id.toString(id);
|
|
310
310
|
return Stream.mapEffect(Ops.storage.replayStream(idStr, fromSeq), json => Effect$1.map(openAndDecode(idStr, json), event => ({
|
|
311
311
|
id: id,
|
|
@@ -337,7 +337,7 @@ function Make(Spec) {
|
|
|
337
337
|
append: append,
|
|
338
338
|
replay: replay,
|
|
339
339
|
replayStream: replayStream,
|
|
340
|
-
|
|
340
|
+
replayEnvelopes: replayEnvelopes,
|
|
341
341
|
appendStream: appendStream,
|
|
342
342
|
latestSnapshot: latestSnapshot,
|
|
343
343
|
writeSnapshot: writeSnapshot
|
|
@@ -154,7 +154,7 @@ module TestOps = {
|
|
|
154
154
|
) => promise<result<unit, EventLog.appendError>>,
|
|
155
155
|
replay: string => promise<array<AggSpec.event>>,
|
|
156
156
|
replayStream: (string, ~fromSeq: int=?) => Stream.t<AggSpec.event, string, unit>,
|
|
157
|
-
|
|
157
|
+
replayEnvelopes: (
|
|
158
158
|
string,
|
|
159
159
|
~fromSeq: int=?,
|
|
160
160
|
) => Stream.t<Message.event'<string, AggSpec.event>, string, unit>,
|
|
@@ -174,7 +174,7 @@ module TestOps = {
|
|
|
174
174
|
append: mock.appendFn,
|
|
175
175
|
replay: mock.replayFn,
|
|
176
176
|
replayStream: (id, ~fromSeq as _=?) => mock.replayStreamFn(id),
|
|
177
|
-
|
|
177
|
+
replayEnvelopes: (id, ~fromSeq as _=?) =>
|
|
178
178
|
mock.getAll()->Array.filter(e => e.id == id)->Stream.fromIterable,
|
|
179
179
|
appendStream: (_startingSeqNr, _id, stream) => stream->Stream.runDrain,
|
|
180
180
|
latestSnapshot: async _ => Ok(None),
|
|
@@ -199,7 +199,7 @@ function eventLog_replayStream(id, param) {
|
|
|
199
199
|
return mock.replayStreamFn(id);
|
|
200
200
|
}
|
|
201
201
|
|
|
202
|
-
function
|
|
202
|
+
function eventLog_replayEnvelopes(id, param) {
|
|
203
203
|
return Stream.fromIterable(mock.getAll().filter(e => e.id === id));
|
|
204
204
|
}
|
|
205
205
|
|
|
@@ -225,7 +225,7 @@ let eventLog = {
|
|
|
225
225
|
append: eventLog_append,
|
|
226
226
|
replay: eventLog_replay,
|
|
227
227
|
replayStream: eventLog_replayStream,
|
|
228
|
-
|
|
228
|
+
replayEnvelopes: eventLog_replayEnvelopes,
|
|
229
229
|
appendStream: eventLog_appendStream,
|
|
230
230
|
latestSnapshot: eventLog_latestSnapshot,
|
|
231
231
|
writeSnapshot: eventLog_writeSnapshot
|
|
@@ -130,7 +130,7 @@ module TestOps = {
|
|
|
130
130
|
) => promise<result<unit, EventLog.appendError>>,
|
|
131
131
|
replay: string => promise<array<AggSpec.event>>,
|
|
132
132
|
replayStream: (string, ~fromSeq: int=?) => Stream.t<AggSpec.event, string, unit>,
|
|
133
|
-
|
|
133
|
+
replayEnvelopes: (
|
|
134
134
|
string,
|
|
135
135
|
~fromSeq: int=?,
|
|
136
136
|
) => Stream.t<Message.event'<string, AggSpec.event>, string, unit>,
|
|
@@ -149,7 +149,7 @@ module TestOps = {
|
|
|
149
149
|
append: mock.appendFn,
|
|
150
150
|
replay: mock.replayFn,
|
|
151
151
|
replayStream: (id, ~fromSeq as _=?) => mock.replayStreamFn(id),
|
|
152
|
-
|
|
152
|
+
replayEnvelopes: (id, ~fromSeq as _=?) =>
|
|
153
153
|
mock.getAll()->Array.filter(e => e.id == id)->Stream.fromIterable,
|
|
154
154
|
appendStream: (_startingSeqNr, _id, stream) => stream->Stream.runDrain,
|
|
155
155
|
latestSnapshot: async _ => Ok(None),
|
|
@@ -156,7 +156,7 @@ function eventLog_replayStream(id, param) {
|
|
|
156
156
|
return mock.replayStreamFn(id);
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
-
function
|
|
159
|
+
function eventLog_replayEnvelopes(id, param) {
|
|
160
160
|
return Stream.fromIterable(mock.getAll().filter(e => e.id === id));
|
|
161
161
|
}
|
|
162
162
|
|
|
@@ -182,7 +182,7 @@ let eventLog = {
|
|
|
182
182
|
append: eventLog_append,
|
|
183
183
|
replay: eventLog_replay,
|
|
184
184
|
replayStream: eventLog_replayStream,
|
|
185
|
-
|
|
185
|
+
replayEnvelopes: eventLog_replayEnvelopes,
|
|
186
186
|
appendStream: eventLog_appendStream,
|
|
187
187
|
latestSnapshot: eventLog_latestSnapshot,
|
|
188
188
|
writeSnapshot: eventLog_writeSnapshot
|
|
@@ -141,7 +141,7 @@ module TestOps = {
|
|
|
141
141
|
) => promise<result<unit, EventLog.appendError>>,
|
|
142
142
|
replay: string => promise<array<AggSpec.event>>,
|
|
143
143
|
replayStream: (string, ~fromSeq: int=?) => Stream.t<AggSpec.event, string, unit>,
|
|
144
|
-
|
|
144
|
+
replayEnvelopes: (
|
|
145
145
|
string,
|
|
146
146
|
~fromSeq: int=?,
|
|
147
147
|
) => Stream.t<Message.event'<string, AggSpec.event>, string, unit>,
|
|
@@ -161,7 +161,7 @@ module TestOps = {
|
|
|
161
161
|
append: mock.appendFn,
|
|
162
162
|
replay: mock.replayFn,
|
|
163
163
|
replayStream: (id, ~fromSeq as _=?) => mock.replayStreamFn(id),
|
|
164
|
-
|
|
164
|
+
replayEnvelopes: (id, ~fromSeq as _=?) =>
|
|
165
165
|
mock.getAll()->Array.filter(e => e.id == id)->Stream.fromIterable,
|
|
166
166
|
appendStream: (_startingSeqNr, _id, stream) => stream->Stream.runDrain,
|
|
167
167
|
latestSnapshot: async _ => Ok(None),
|
|
@@ -191,7 +191,7 @@ function eventLog_replayStream(id, param) {
|
|
|
191
191
|
return mock.replayStreamFn(id);
|
|
192
192
|
}
|
|
193
193
|
|
|
194
|
-
function
|
|
194
|
+
function eventLog_replayEnvelopes(id, param) {
|
|
195
195
|
return Stream.fromIterable(mock.getAll().filter(e => e.id === id));
|
|
196
196
|
}
|
|
197
197
|
|
|
@@ -217,7 +217,7 @@ let eventLog = {
|
|
|
217
217
|
append: eventLog_append,
|
|
218
218
|
replay: eventLog_replay,
|
|
219
219
|
replayStream: eventLog_replayStream,
|
|
220
|
-
|
|
220
|
+
replayEnvelopes: eventLog_replayEnvelopes,
|
|
221
221
|
appendStream: eventLog_appendStream,
|
|
222
222
|
latestSnapshot: eventLog_latestSnapshot,
|
|
223
223
|
writeSnapshot: eventLog_writeSnapshot
|
|
@@ -67,7 +67,7 @@ module TestOps = {
|
|
|
67
67
|
) => promise<result<unit, EventLog.appendError>>,
|
|
68
68
|
replay: string => promise<array<AggSpec.event>>,
|
|
69
69
|
replayStream: (string, ~fromSeq: int=?) => Stream.t<AggSpec.event, string, unit>,
|
|
70
|
-
|
|
70
|
+
replayEnvelopes: (
|
|
71
71
|
string,
|
|
72
72
|
~fromSeq: int=?,
|
|
73
73
|
) => Stream.t<Message.event'<string, AggSpec.event>, string, unit>,
|
|
@@ -93,7 +93,7 @@ module TestOps = {
|
|
|
93
93
|
replay: async id => eventsFor(id)->Array.map(e => e.event),
|
|
94
94
|
replayStream: (id, ~fromSeq=0) =>
|
|
95
95
|
eventsFor(id)->Array.map(e => e.event)->Array.slice(~start=fromSeq)->Stream.fromIterable,
|
|
96
|
-
|
|
96
|
+
replayEnvelopes: (id, ~fromSeq=0) =>
|
|
97
97
|
eventsFor(id)->Array.slice(~start=fromSeq)->Stream.fromIterable,
|
|
98
98
|
appendStream: (_seqNr, _id, stream) => stream->Stream.runDrain,
|
|
99
99
|
latestSnapshot: async _ => Ok(None),
|
|
@@ -125,7 +125,7 @@ function eventLog_replayStream(id, fromSeqOpt) {
|
|
|
125
125
|
return Stream.fromIterable(eventsFor(id).map(e => e.event).slice(fromSeq));
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
-
function
|
|
128
|
+
function eventLog_replayEnvelopes(id, fromSeqOpt) {
|
|
129
129
|
let fromSeq = fromSeqOpt !== undefined ? fromSeqOpt : 0;
|
|
130
130
|
return Stream.fromIterable(eventsFor(id).slice(fromSeq));
|
|
131
131
|
}
|
|
@@ -152,7 +152,7 @@ let eventLog = {
|
|
|
152
152
|
append: eventLog_append,
|
|
153
153
|
replay: eventLog_replay,
|
|
154
154
|
replayStream: eventLog_replayStream,
|
|
155
|
-
|
|
155
|
+
replayEnvelopes: eventLog_replayEnvelopes,
|
|
156
156
|
appendStream: eventLog_appendStream,
|
|
157
157
|
latestSnapshot: eventLog_latestSnapshot,
|
|
158
158
|
writeSnapshot: eventLog_writeSnapshot
|