@reventlessdev/reventless-core 3.0.0-alpha.213 → 3.0.0-alpha.215

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.
@@ -0,0 +1,111 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+
3
+ import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js";
4
+ import * as RuntimeExtension$ReventlessCore from "../../src/adapter/RuntimeExtension/RuntimeExtension.res.mjs";
5
+
6
+ function recorderNamed(label, into) {
7
+ let moduleUrl = `file:///pkg/` + label + `.res.mjs`;
8
+ let onColdStart = (runtimeKind, component, plugin, platform) => {
9
+ into.push([
10
+ label,
11
+ {
12
+ runtimeKind: runtimeKind,
13
+ component: component,
14
+ plugin: plugin,
15
+ platform: platform
16
+ }
17
+ ]);
18
+ };
19
+ return {
20
+ moduleUrl: moduleUrl,
21
+ onColdStart: onColdStart
22
+ };
23
+ }
24
+
25
+ function fireAggregate() {
26
+ RuntimeExtension$ReventlessCore.notifyColdStart("Aggregate", "AllAggregatesCmdHandler", "Catalog", "Shop");
27
+ }
28
+
29
+ globalThis.describe("RuntimeExtension", () => {
30
+ globalThis.beforeEach(() => RuntimeExtension$ReventlessCore.reset());
31
+ globalThis.test("empty registry is the default and notifyColdStart is silent", () => {
32
+ globalThis.expect(RuntimeExtension$ReventlessCore.isEmpty()).toBe(true);
33
+ globalThis.expect(RuntimeExtension$ReventlessCore.moduleUrls()).toEqual([]);
34
+ fireAggregate();
35
+ globalThis.expect(true).toBe(true);
36
+ });
37
+ globalThis.test("a registered extension receives the runtime's full identity", () => {
38
+ let calls = [];
39
+ RuntimeExtension$ReventlessCore.use(recorderNamed("tracing", calls));
40
+ fireAggregate();
41
+ globalThis.expect(calls).toEqual([[
42
+ "tracing",
43
+ {
44
+ runtimeKind: "Aggregate",
45
+ component: "AllAggregatesCmdHandler",
46
+ plugin: "Catalog",
47
+ platform: "Shop"
48
+ }
49
+ ]]);
50
+ });
51
+ globalThis.test("several extensions compose, in registration order", () => {
52
+ let calls = [];
53
+ RuntimeExtension$ReventlessCore.use(recorderNamed("tracing", calls));
54
+ RuntimeExtension$ReventlessCore.use(recorderNamed("accounting", calls));
55
+ fireAggregate();
56
+ globalThis.expect(calls.map(param => param[0])).toEqual([
57
+ "tracing",
58
+ "accounting"
59
+ ]);
60
+ });
61
+ globalThis.test("moduleUrls reports every registration, in order", () => {
62
+ let calls = [];
63
+ RuntimeExtension$ReventlessCore.use(recorderNamed("tracing", calls));
64
+ RuntimeExtension$ReventlessCore.use(recorderNamed("accounting", calls));
65
+ globalThis.expect(RuntimeExtension$ReventlessCore.isEmpty()).toBe(false);
66
+ globalThis.expect(RuntimeExtension$ReventlessCore.moduleUrls()).toEqual([
67
+ "file:///pkg/tracing.res.mjs",
68
+ "file:///pkg/accounting.res.mjs"
69
+ ]);
70
+ });
71
+ globalThis.test("a throwing extension is skipped; the runtime and its siblings survive", () => {
72
+ let calls = [];
73
+ let onColdStart = (param, param$1, param$2, param$3) => Stdlib_JsError.throwWithMessage("extension blew up");
74
+ let Broken = {
75
+ moduleUrl: "file:///pkg/broken.res.mjs",
76
+ onColdStart: onColdStart
77
+ };
78
+ RuntimeExtension$ReventlessCore.use(Broken);
79
+ RuntimeExtension$ReventlessCore.use(recorderNamed("accounting", calls));
80
+ fireAggregate();
81
+ globalThis.expect(calls.map(param => param[0])).toEqual(["accounting"]);
82
+ });
83
+ globalThis.test("notifyColdStartHooks fires loose hooks — the deployed runtime's path", () => {
84
+ let seen = [];
85
+ let hook = label => ((param, component, param$1, param$2) => {
86
+ seen.push(label + `:` + component);
87
+ });
88
+ RuntimeExtension$ReventlessCore.notifyColdStartHooks([
89
+ hook("a"),
90
+ hook("b")
91
+ ], "ReadModel", "AllReadModels", undefined, undefined);
92
+ globalThis.expect(seen).toEqual([
93
+ "a:AllReadModels",
94
+ "b:AllReadModels"
95
+ ]);
96
+ });
97
+ globalThis.test("reset clears the registry", () => {
98
+ let calls = [];
99
+ RuntimeExtension$ReventlessCore.use(recorderNamed("tracing", calls));
100
+ RuntimeExtension$ReventlessCore.reset();
101
+ fireAggregate();
102
+ globalThis.expect(RuntimeExtension$ReventlessCore.isEmpty()).toBe(true);
103
+ globalThis.expect(calls).toEqual([]);
104
+ });
105
+ });
106
+
107
+ export {
108
+ recorderNamed,
109
+ fireAggregate,
110
+ }
111
+ /* Not a pure module */