@reventlessdev/reventless-core 3.0.0-alpha.333 → 3.0.0-alpha.334

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 CHANGED
@@ -3,6 +3,13 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # 3.0.0-alpha.334 (2026-11-08)
7
+
8
+ ### Bug Fixes
9
+
10
+ * **dcb:** a query clause with no event type matches nothing in every store, and a slice that consumes nothing records without a read ([962fd6a](https://github.com/ReventlessDev/reventless-core/commit/962fd6afd68e22142ae8f47d2603b25d4191fe02))
11
+
12
+
6
13
  # 3.0.0-alpha.333 (2026-11-07)
7
14
 
8
15
  **Note:** Version bump only for package @reventlessdev/reventless-core
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reventlessdev/reventless-core",
3
- "version": "3.0.0-alpha.333",
3
+ "version": "3.0.0-alpha.334",
4
4
  "description": "Core package for Reventless framework",
5
5
  "license": "Apache-2.0",
6
6
  "jest": {
@@ -29,16 +29,16 @@
29
29
  "sury": "11.1.0",
30
30
  "uuid": "^13.0.0",
31
31
  "@reventlessdev/rescript-effect": "1.0.0-alpha.3",
32
+ "@reventlessdev/rescript-fast-csv": "2.0.0-alpha.26",
32
33
  "@reventlessdev/rescript-hash-object": "1.2.0-alpha.15",
33
34
  "@reventlessdev/rescript-jest": "1.0.0-alpha.13",
34
35
  "@reventlessdev/rescript-node": "2.0.0-alpha.26",
35
- "@reventlessdev/rescript-fast-csv": "2.0.0-alpha.26",
36
36
  "@reventlessdev/rescript-pulumi-pulumi": "3.0.0-alpha.0",
37
37
  "@reventlessdev/rescript-ssh2": "2.0.0-alpha.27",
38
38
  "@reventlessdev/rescript-uuid": "2.0.0-alpha.1",
39
- "@reventlessdev/reventless-infra": "3.0.0-alpha.226",
40
- "@reventlessdev/reventless-spec": "3.0.0-alpha.195",
41
- "@reventlessdev/reventless-interop": "3.0.0-alpha.43"
39
+ "@reventlessdev/reventless-infra": "3.0.0-alpha.227",
40
+ "@reventlessdev/reventless-interop": "3.0.0-alpha.43",
41
+ "@reventlessdev/reventless-spec": "3.0.0-alpha.196"
42
42
  },
43
43
  "devDependencies": {
44
44
  "rescript": "12.3.1",
@@ -413,7 +413,14 @@ module Make = (
413
413
  | AlwaysEventual => false
414
414
  }
415
415
 
416
- dcbEventLog.readStream(~query, ~after=?afterPos, ~strongConsistency)
416
+ // A slice that consumes nothing (`consumedEvent = unit`) reads nothing: the store is
417
+ // not asked at all.
418
+
419
+ (
420
+ Reventless.DcbTag.readsNothing(query)
421
+ ? Stream.empty
422
+ : dcbEventLog.readStream(~query, ~after=?afterPos, ~strongConsistency)
423
+ )
417
424
  ->Stream.mapEffect(openRaw)
418
425
  // The head accumulator starts at `afterPos` (the seeded head), not `None`,
419
426
  // so an empty delta read keeps the cached head — the append must condition
@@ -589,7 +596,14 @@ module Make = (
589
596
  `produced ${eventCount} event(s): [${eventDetails}]`,
590
597
  )
591
598
  ->Effect.flatMap(
592
- _ => Effect.promise(() => dcbEventLog.append(rawEvents, ~condition)),
599
+ _ =>
600
+ Effect.promise(
601
+ () =>
602
+ // What it did not read cannot have changed under it: no condition.
603
+ Reventless.DcbTag.readsNothing(query)
604
+ ? dcbEventLog.append(rawEvents)
605
+ : dcbEventLog.append(rawEvents, ~condition),
606
+ ),
593
607
  )
594
608
  ->Effect.flatMap(
595
609
  appendResult =>
@@ -266,7 +266,7 @@ function Make(Spec) {
266
266
  strongConsistency = false;
267
267
  break;
268
268
  }
269
- return Effect$1.flatMap(Effect$1.tap(Stream.runFold(Stream.mapEffect(dcbEventLog.readStream(query, afterPos, strongConsistency), openRaw), [
269
+ return Effect$1.flatMap(Effect$1.tap(Stream.runFold(Stream.mapEffect(DcbTag$Reventless.readsNothing(query) ? Stream$1.empty : dcbEventLog.readStream(query, afterPos, strongConsistency), openRaw), [
270
270
  match$1[0],
271
271
  afterPos,
272
272
  [],
@@ -392,7 +392,13 @@ function Make(Spec) {
392
392
  query: query,
393
393
  after: headPosition
394
394
  };
395
- return Effect$1.flatMap(Effect$1.flatMap(EffectLogger$ReventlessCore.logInfo(comp, eventJsons, ids, `produced ` + eventCount + ` event(s): [` + eventDetails + `]`), () => Effect$1.promise(() => dcbEventLog.append(rawEvents, condition))), appendResult => {
395
+ return Effect$1.flatMap(Effect$1.flatMap(EffectLogger$ReventlessCore.logInfo(comp, eventJsons, ids, `produced ` + eventCount + ` event(s): [` + eventDetails + `]`), () => Effect$1.promise(() => {
396
+ if (DcbTag$Reventless.readsNothing(query)) {
397
+ return dcbEventLog.append(rawEvents, undefined);
398
+ } else {
399
+ return dcbEventLog.append(rawEvents, condition);
400
+ }
401
+ })), appendResult => {
396
402
  if (appendResult.TAG === "Ok") {
397
403
  cachePut([
398
404
  state,
@@ -0,0 +1,111 @@
1
+ // A slice whose `consumedEvent` is `unit` decides from nothing: it records each command without
2
+ // asking the event log to read, and appends without a condition.
3
+
4
+ open JestGlobals
5
+
6
+ let mock = DcbFixtures.makeMockStorage()
7
+
8
+ module LogOps = DcbEventLog_Operations.Make({
9
+ let name = "ReadsNothingLog"
10
+ let serviceName = "ReadsNothingLog"
11
+ let storage = mock.operations
12
+ let publishJson = mock.mockPublishJson
13
+ })
14
+
15
+ // The event log, with every read and every append's condition noted.
16
+ let reads = ref(0)
17
+ let conditions: ref<array<option<Reventless.DcbTag.appendCondition>>> = ref([])
18
+ let eventLog: DcbEventLog.operations = {
19
+ read: LogOps.read,
20
+ readStream: (~query, ~after=?, ~strongConsistency=?) => {
21
+ reads := reads.contents + 1
22
+ LogOps.readStream(~query, ~after?, ~strongConsistency?)
23
+ },
24
+ append: (events, ~condition=?) => {
25
+ conditions := conditions.contents->Array.concat([condition])
26
+ LogOps.append(events, ~condition?)
27
+ },
28
+ appendStream: LogOps.appendStream,
29
+ }
30
+
31
+ module NoteSpec = {
32
+ let name = "NoteFault"
33
+ module Id = Reventless.Id.String
34
+ let moduleUrl: string = %raw(`import.meta.url`)
35
+
36
+ @schema
37
+ type event = FaultNoted({chargerId: @s.matches(Reventless.DcbTag.string) string})
38
+
39
+ @schema
40
+ type consumedEvent = unit
41
+
42
+ @schema
43
+ type command = NoteFault({chargerId: @s.matches(Reventless.DcbTag.string) string})
44
+
45
+ @schema
46
+ type error = unit
47
+ }
48
+
49
+ module NoteDecision = {
50
+ type state = unit
51
+ let initialState = ()
52
+ let moduleUrl = NoteSpec.moduleUrl
53
+ let evolve = (state, _event) => state
54
+ let decide = (_state, command: NoteSpec.command): result<array<NoteSpec.event>, NoteSpec.error> =>
55
+ switch command {
56
+ | NoteFault({chargerId}) => Ok([FaultNoted({chargerId: chargerId})])
57
+ }
58
+ }
59
+
60
+ module NoteHandler = StateChangeSlice_Callback.Make(NoteSpec, NoteDecision)
61
+
62
+ let note = reference =>
63
+ NoteHandler.handleCommands(
64
+ eventLog,
65
+ Stream.fromIterable([
66
+ {
67
+ ReventlessInfra.CommandTopic.command: {
68
+ Message.id: Reventless.Id.String.makeFromString("cmd-" ++ reference),
69
+ meta: DcbFixtures.testMeta,
70
+ command: NoteSpec.NoteFault({chargerId: "charger-1"}),
71
+ },
72
+ reference,
73
+ },
74
+ ]),
75
+ )->Effect.runPromise
76
+
77
+ let _ = beforeEach(() => {
78
+ mock.reset()
79
+ NoteHandler.resetCache()
80
+ reads := 0
81
+ conditions := []
82
+ })
83
+
84
+ describe("a slice that consumes nothing", () => {
85
+ testPromise("records each command without a read and without a condition", async () => {
86
+ let first = await note("ref-1")
87
+ let second = await note("ref-2")
88
+ expect((
89
+ first,
90
+ second,
91
+ mock.getEvents()->Array.length,
92
+ reads.contents,
93
+ conditions.contents,
94
+ ))->toEqual(([Ok("ref-1")], [Ok("ref-2")], 2, 0, [None, None]))
95
+ })
96
+ })
97
+
98
+ describe("DcbTag.readsNothing", () => {
99
+ testSync("a query of clauses with no event type reads nothing", () =>
100
+ expect((
101
+ Reventless.DcbTag.readsNothing([{eventTypes: [], tags: [{key: "chargerId", value: "c1"}]}]),
102
+ Reventless.DcbTag.readsNothing([
103
+ {eventTypes: []},
104
+ {eventTypes: ["FaultNoted"], tags: [{key: "chargerId", value: "c1"}]},
105
+ ]),
106
+ // An empty query keeps its meaning: every event.
107
+ Reventless.DcbTag.readsNothing([]),
108
+ Reventless.DcbTag.readsNothing([{tags: [{key: "chargerId", value: "c1"}]}]),
109
+ ))->toEqual((true, false, false, false))
110
+ )
111
+ })
@@ -0,0 +1,234 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+
3
+ import * as Sury from "sury";
4
+ import * as Effect from "@reventlessdev/rescript-effect/src/Effect.res.mjs";
5
+ import * as Id$Reventless from "@reventlessdev/reventless-spec/src/types/Id.res.mjs";
6
+ import * as Stream from "effect/Stream";
7
+ import * as DcbTag$Reventless from "@reventlessdev/reventless-spec/src/components/DcbTag.res.mjs";
8
+ import * as DcbFixtures$ReventlessCore from "./DcbFixtures.res.mjs";
9
+ import * as DcbEventLog_Operations$ReventlessCore from "../../src/components/DcbEventLog/DcbEventLog_Operations.res.mjs";
10
+ import * as StateChangeSlice_Callback$ReventlessCore from "../../src/components/StateChangeSlice/StateChangeSlice_Callback.res.mjs";
11
+
12
+ let mock = DcbFixtures$ReventlessCore.makeMockStorage();
13
+
14
+ let storage = mock.operations;
15
+
16
+ let publishJson = mock.mockPublishJson;
17
+
18
+ let LogOps = DcbEventLog_Operations$ReventlessCore.Make({
19
+ name: "ReadsNothingLog",
20
+ serviceName: "ReadsNothingLog",
21
+ storage: storage,
22
+ publishJson: publishJson
23
+ });
24
+
25
+ let reads = {
26
+ contents: 0
27
+ };
28
+
29
+ let conditions = {
30
+ contents: []
31
+ };
32
+
33
+ let eventLog_read = LogOps.read;
34
+
35
+ function eventLog_append(events, condition) {
36
+ conditions.contents = conditions.contents.concat([condition]);
37
+ return LogOps.append(events, condition);
38
+ }
39
+
40
+ function eventLog_readStream(query, after, strongConsistency) {
41
+ reads.contents = reads.contents + 1 | 0;
42
+ return LogOps.readStream(query, after, strongConsistency);
43
+ }
44
+
45
+ let eventLog_appendStream = LogOps.appendStream;
46
+
47
+ let eventLog = {
48
+ read: eventLog_read,
49
+ append: eventLog_append,
50
+ readStream: eventLog_readStream,
51
+ appendStream: eventLog_appendStream
52
+ };
53
+
54
+ let name = "NoteFault";
55
+
56
+ let moduleUrl = import.meta.url;
57
+
58
+ let eventSchema = Sury.$schema(s => ({
59
+ TAG: "FaultNoted",
60
+ chargerId: s.m(DcbTag$Reventless.string)
61
+ }));
62
+
63
+ let consumedEventSchema = Sury.$unit;
64
+
65
+ let commandSchema = Sury.$schema(s => ({
66
+ TAG: "NoteFault",
67
+ chargerId: s.m(DcbTag$Reventless.string)
68
+ }));
69
+
70
+ let errorSchema = Sury.$unit;
71
+
72
+ function authorizationOf(param) {
73
+ return "AllowAuthenticated";
74
+ }
75
+
76
+ function commandTransition(param) {
77
+ return "Undeclared";
78
+ }
79
+
80
+ let traits = [];
81
+
82
+ let NoteSpec = {
83
+ name: name,
84
+ Id: undefined,
85
+ moduleUrl: moduleUrl,
86
+ eventSchema: eventSchema,
87
+ consumedEventSchema: consumedEventSchema,
88
+ commandSchema: commandSchema,
89
+ errorSchema: errorSchema,
90
+ authorizationOf: authorizationOf,
91
+ commandTransition: commandTransition,
92
+ traits: traits,
93
+ readConsistency: "EscalateOnRetry"
94
+ };
95
+
96
+ function evolve(state, _event) {
97
+ return state;
98
+ }
99
+
100
+ function decide(_state, command) {
101
+ return {
102
+ TAG: "Ok",
103
+ _0: [{
104
+ TAG: "FaultNoted",
105
+ chargerId: command.chargerId
106
+ }]
107
+ };
108
+ }
109
+
110
+ let NoteDecision = {
111
+ initialState: undefined,
112
+ moduleUrl: moduleUrl,
113
+ evolve: evolve,
114
+ decide: decide
115
+ };
116
+
117
+ let NoteHandler = StateChangeSlice_Callback$ReventlessCore.Make({
118
+ name: name,
119
+ moduleUrl: moduleUrl,
120
+ consumedEventSchema: consumedEventSchema,
121
+ errorSchema: errorSchema,
122
+ eventSchema: eventSchema,
123
+ commandSchema: commandSchema,
124
+ authorizationOf: authorizationOf,
125
+ commandTransition: commandTransition,
126
+ traits: traits,
127
+ readConsistency: "EscalateOnRetry"
128
+ })({
129
+ initialState: undefined,
130
+ evolve: evolve,
131
+ decide: decide,
132
+ moduleUrl: moduleUrl
133
+ });
134
+
135
+ function note(reference) {
136
+ return Effect.runPromise(NoteHandler.handleCommands(undefined, undefined, undefined, eventLog, Stream.fromIterable([{
137
+ command: {
138
+ id: Id$Reventless.$$String.makeFromString("cmd-" + reference),
139
+ meta: DcbFixtures$ReventlessCore.testMeta,
140
+ command: {
141
+ TAG: "NoteFault",
142
+ chargerId: "charger-1"
143
+ }
144
+ },
145
+ reference: reference
146
+ }])));
147
+ }
148
+
149
+ globalThis.beforeEach(() => {
150
+ mock.reset();
151
+ NoteHandler.resetCache();
152
+ reads.contents = 0;
153
+ conditions.contents = [];
154
+ });
155
+
156
+ globalThis.describe("a slice that consumes nothing", () => {
157
+ globalThis.test("records each command without a read and without a condition", async () => {
158
+ let first = await note("ref-1");
159
+ let second = await note("ref-2");
160
+ globalThis.expect([
161
+ first,
162
+ second,
163
+ mock.getEvents().length,
164
+ reads.contents,
165
+ conditions.contents
166
+ ]).toEqual([
167
+ [{
168
+ TAG: "Ok",
169
+ _0: "ref-1"
170
+ }],
171
+ [{
172
+ TAG: "Ok",
173
+ _0: "ref-2"
174
+ }],
175
+ 2,
176
+ 0,
177
+ [
178
+ undefined,
179
+ undefined
180
+ ]
181
+ ]);
182
+ });
183
+ });
184
+
185
+ globalThis.describe("DcbTag.readsNothing", () => {
186
+ globalThis.test("a query of clauses with no event type reads nothing", () => {
187
+ globalThis.expect([
188
+ DcbTag$Reventless.readsNothing([{
189
+ eventTypes: [],
190
+ tags: [{
191
+ key: "chargerId",
192
+ value: "c1"
193
+ }]
194
+ }]),
195
+ DcbTag$Reventless.readsNothing([
196
+ {
197
+ eventTypes: []
198
+ },
199
+ {
200
+ eventTypes: ["FaultNoted"],
201
+ tags: [{
202
+ key: "chargerId",
203
+ value: "c1"
204
+ }]
205
+ }
206
+ ]),
207
+ DcbTag$Reventless.readsNothing([]),
208
+ DcbTag$Reventless.readsNothing([{
209
+ tags: [{
210
+ key: "chargerId",
211
+ value: "c1"
212
+ }]
213
+ }])
214
+ ]).toEqual([
215
+ true,
216
+ false,
217
+ false,
218
+ false
219
+ ]);
220
+ });
221
+ });
222
+
223
+ export {
224
+ mock,
225
+ LogOps,
226
+ reads,
227
+ conditions,
228
+ eventLog,
229
+ NoteSpec,
230
+ NoteDecision,
231
+ NoteHandler,
232
+ note,
233
+ }
234
+ /* mock Not a pure module */