@reventlessdev/reventless-local 3.0.0-alpha.249 → 3.0.0-alpha.251
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 +30 -0
- package/package.json +13 -13
- package/src/BakedManifest.res +5 -6
- package/src/EmitCapabilities.res +3 -1
- package/src/LocalPlatformRegistry.res +3 -1
- package/src/LocalPlatformStart.res +7 -6
- package/src/LocalSeedTarget.res +3 -1
- package/src/Platform.res +291 -215
- package/src/ShellConfig.res +10 -17
- package/src/UiHints.res +8 -14
- package/src/UiSlots.res +10 -17
- package/src/adapter/Api/LocalEvents_Server.res +5 -3
- package/src/adapter/Api/LocalGraphQL_Adapter.res +4 -4
- package/src/adapter/Auth/LocalAuth.res +12 -16
- package/src/adapter/Auth/LocalAuth.res.mjs +2 -1
- package/src/adapter/Auth/UserStore.res +13 -40
- package/src/adapter/Auth/UserStore.res.mjs +11 -67
- package/src/adapter/Backend.res +1 -2
- package/src/adapter/CommandGenerator/CommandGeneratorResolvers_GraphQL.res +42 -26
- package/src/adapter/CommandGenerator/InboundTranslationResolvers_GraphQL.res +13 -3
- package/src/adapter/CommandTopic/LocalCommandTopicChannel.res +15 -17
- package/src/adapter/CommandTopic/LocalCommandTopicRemoteChannel.res +18 -22
- package/src/adapter/Counter/LocalCounterHandler.res +1 -1
- package/src/adapter/DcbEventLog/DcbEventLogStorage_InMemory.res +33 -22
- package/src/adapter/DcbEventLog/DcbEventLogStorage_Sqlite.res +57 -57
- package/src/adapter/DomainGraphQL_Server.res +35 -34
- package/src/adapter/DomainMCP_Server.res +45 -41
- package/src/adapter/EventCollector/LocalEventCollectorChannel.res +47 -36
- package/src/adapter/EventHistory/EventHistoryResolvers_GraphQL.res +15 -12
- package/src/adapter/EventLog/EventLogStorage_InMemory.res +9 -4
- package/src/adapter/EventLog/EventLogStorage_Sqlite.res +36 -24
- package/src/adapter/EventTopic/LocalEventTopicPublisher.res +9 -3
- package/src/adapter/Heartbeat/LocalHeartbeatRunner.res +9 -14
- package/src/adapter/LocalBus.res +12 -12
- package/src/adapter/LocalCapabilities.res +6 -0
- package/src/adapter/LocalCapabilities.res.mjs +5 -2
- package/src/adapter/LocalGeocodeResolvers.res +1 -4
- package/src/adapter/LocalSideEffectHandler.res +1 -1
- package/src/adapter/LocalStateChangeDescriptor.res +2 -1
- package/src/adapter/MCP_ServerInstance.res +51 -39
- package/src/adapter/ObjectStore/LocalObjectStore.res +5 -2
- package/src/adapter/ObjectStore/ObjectStoreStorage_FileSystem.res +1 -2
- package/src/adapter/PlatformGraphQL_Server.res +10 -6
- package/src/adapter/PlatformGraphQL_Server.res.mjs +2 -1
- package/src/adapter/ProjectionCheckpoint.res +8 -1
- package/src/adapter/ProjectionPending.res +1 -3
- package/src/adapter/QueryDb/LocalQueryDbStorage.res +2 -1
- package/src/adapter/QueryDb/QueryDbResolvers_GraphQL.res +367 -269
- package/src/adapter/QueryDb/QueryDbStorage_InMemory.res +5 -3
- package/src/adapter/QueryDb/QueryDbStorage_Sqlite.res +63 -40
- package/src/adapter/QueryDb/SortKey_Filter.res +14 -6
- package/src/adapter/Runtime/LocalAggregateRuntime_Builder.res +12 -10
- package/src/adapter/Runtime/LocalEventCollectorRuntime_Builder.res +8 -2
- package/src/adapter/Runtime/LocalPluginRuntime_Builder.res +1 -4
- package/src/adapter/Scheduler/LocalScheduledPublisher.res +12 -12
- package/src/adapter/SqliteDriver.res +16 -4
- package/src/adapter/Task/TaskBucket_Sqlite.res +5 -6
- package/src/components/Aggregate_Builder.res +6 -1
- package/src/components/Counter_Builder.res +1 -5
- package/src/components/DcbEventLog_Builder.res +5 -3
- package/src/components/ExtensionPoint_Builder.res +13 -15
- package/src/components/InboundTranslationSlice_Builder.res +3 -2
- package/src/components/OutboundTranslationSlice_Builder.res +3 -2
- package/src/components/ReadModel_Builder.res +18 -20
- package/src/components/StateViewSlice_Builder.res +3 -2
- package/src/components/Task_Builder.res +12 -13
- package/src/reset/LocalSeedReset.res +2 -5
- package/src/test/Mocks/MockDcbEventLogStorage.res +5 -1
- package/src/test/Mocks/MockEventLogStorage.res +8 -3
- package/src/test/Mocks/MockQueryDbStorage.res +3 -2
- package/src/test/TestRunner.res +1 -1
- package/tests/BakedManifestFilesTest.res +7 -10
- package/tests/LocalEventTapTest.res +26 -21
- package/tests/LocalPlatformStartTest.res +33 -28
- package/tests/PluginEventDecodeTest.res +3 -3
- package/tests/ShellConfigTest.res +30 -21
- package/tests/SplitApiFixtures.res +34 -10
- package/tests/SplitApiTest.res +92 -62
- package/tests/adapter/BackendParityTest.res +180 -130
- package/tests/adapter/CollectNEventsTest.res +6 -4
- package/tests/adapter/CommandAuthorizationTest.res +47 -41
- package/tests/adapter/CommandTopicChannelTest.res +163 -139
- package/tests/adapter/CounterHandlerTest.res +95 -77
- package/tests/adapter/DcbEventLogStorageSqliteTest.res +171 -168
- package/tests/adapter/DcbEventLogStorageTest.res +264 -207
- package/tests/adapter/DomainGraphQL_ServerTest.res +53 -43
- package/tests/adapter/EventCollectorChannelTest.res +153 -124
- package/tests/adapter/EventHistoryResolverTest.res +46 -18
- package/tests/adapter/EventLogSnapshotParityTest.res +57 -45
- package/tests/adapter/EventLogStorageSqliteTest.res +9 -10
- package/tests/adapter/EventTapTest.res +37 -20
- package/tests/adapter/EventTopicPublisherTest.res +74 -50
- package/tests/adapter/GraphQLSubscriptionBridgeTest.res +4 -3
- package/tests/adapter/GraphQL_SchemaInspectorTest.res +666 -568
- package/tests/adapter/GraphQL_SubscriptionResolversTest.res +105 -96
- package/tests/adapter/HeartbeatRunnerTest.res +99 -81
- package/tests/adapter/InboundTranslationMutationTest.res +4 -1
- package/tests/adapter/LocalAuthHttpTest.res +79 -85
- package/tests/adapter/LocalAuthLoginTest.res +42 -50
- package/tests/adapter/LocalAuthTest.res +8 -16
- package/tests/adapter/LocalAuthUserStoreTest.res +2 -7
- package/tests/adapter/LocalBusBoundedTest.res +187 -117
- package/tests/adapter/LocalBusPubSubTest.res +118 -76
- package/tests/adapter/LocalDispatchContextTest.res +1 -2
- package/tests/adapter/LocalEvents_ServerTest.res +242 -187
- package/tests/adapter/PgProjectionCatchupTest.res +44 -10
- package/tests/adapter/ProjectionCheckpointTest.res +261 -206
- package/tests/adapter/QueryDbGsiTtlTest.res +123 -83
- package/tests/adapter/QueryDbListPushdownParityTest.res +107 -67
- package/tests/adapter/QueryDbListResolverTest.res +225 -208
- package/tests/adapter/QueryDbResolvedFieldsTest.res +17 -14
- package/tests/adapter/QueryDbStorageSqliteTest.res +33 -49
- package/tests/adapter/QueryDbStorageTest.res +163 -117
- package/tests/adapter/QueryDbUnionRoundTripTest.res +8 -10
- package/tests/adapter/QueryEngineTest.res +179 -126
- package/tests/adapter/ScheduledPublisherTest.res +171 -135
- package/tests/adapter/ServedBucketHttpTest.res +65 -59
- package/tests/adapter/SortKey_FilterTest.res +19 -3
- package/tests/adapter/SqliteDriverTest.res +13 -10
- package/tests/adapter/TaskBucketTest.res +94 -80
- package/tests/components/aggregate/AggregateTest.res +31 -18
- package/tests/components/automationslice/AutomationSliceCallbackTest.res +259 -222
- package/tests/components/automationslice/AutomationSliceFixtures.res +4 -2
- package/tests/components/automationslice/AutomationSliceSelfDeadlockFixtures.res +38 -38
- package/tests/components/automationslice/MixedSourceAutomationSliceFixtures.res +12 -14
- package/tests/components/automationslice/MixedSourceAutomationSliceTest.res +8 -32
- package/tests/components/commandgenerator/CommandGeneratorFixtures.res +7 -5
- package/tests/components/commandgenerator/CommandGeneratorTest.res +40 -31
- package/tests/components/commandtopic/CommandTopicFixtures.res +3 -4
- package/tests/components/commandtopic/CommandTopicStreamFixtures.res +7 -5
- package/tests/components/commandtopic/CommandTopicTest.res +24 -15
- package/tests/components/counter/CounterFixtures.res +6 -8
- package/tests/components/dcb/DcbCrossPartitionFixtures.res +8 -2
- package/tests/components/dcb/DcbCrossPartitionReadTest.res +20 -13
- package/tests/components/dcb/DcbEventLogAppendStreamTest.res +12 -8
- package/tests/components/dcb/DcbEventLogStreamTest.res +88 -61
- package/tests/components/dcb/DcbFixtures.res +4 -1
- package/tests/components/dcb/DcbTest.res +9 -6
- package/tests/components/eventcollector/EventCollectorFixtures.res +0 -1
- package/tests/components/eventcollector/EventCollectorTest.res +6 -3
- package/tests/components/eventlog/EventLogAppendStreamTest.res +88 -68
- package/tests/components/eventlog/EventLogConflictTest.res +8 -4
- package/tests/components/eventlog/EventLogFixtures.res +3 -3
- package/tests/components/eventlog/EventLogProvisioningSeamTest.res +26 -13
- package/tests/components/eventlog/EventLogStreamTest.res +119 -56
- package/tests/components/eventlog/EventLogTest.res +20 -4
- package/tests/components/eventtopic/EventTopicFixtures.res +3 -3
- package/tests/components/eventtopic/EventTopicStreamFixtures.res +1 -2
- package/tests/components/eventtopic/EventTopicStreamTest.res +7 -1
- package/tests/components/extensionpoint/ExtensionPointFixtures.res +14 -9
- package/tests/components/extensionpoint/ExtensionPointTest.res +3 -2
- package/tests/components/heartbeat/HeartbeatFixtures.res +5 -6
- package/tests/components/heartbeat/HeartbeatTest.res +56 -47
- package/tests/components/inboundtranslationslice/InboundTranslationSliceCallbackTest.res +271 -249
- package/tests/components/inboundtranslationslice/InboundTranslationSliceFixtures.res +3 -2
- package/tests/components/outboundtranslationslice/OutboundTranslationSliceCallbackTest.res +361 -276
- package/tests/components/outboundtranslationslice/OutboundTranslationSliceFixtures.res +8 -10
- package/tests/components/outboundtranslationslice/OutboundTranslationSlicePlatformFixtures.res +37 -43
- package/tests/components/querydb/QueryDbFixtures.res +1 -5
- package/tests/components/querydb/QueryDbTest.res +2 -4
- package/tests/components/readmodel/DcbReadModelE2EFixtures.res +15 -18
- package/tests/components/readmodel/MixedSourceReadModelFixtures.res +5 -7
- package/tests/components/readmodel/ReadModelFixtures.res +8 -8
- package/tests/components/scheduler/SchedulerTest.res +76 -58
- package/tests/components/sideeffecthandler/SideEffectHandlerFixtures.res +4 -4
- package/tests/components/stateviewslice/StateViewSliceDisplayNameFixtures.res +5 -7
- package/tests/components/stateviewslice/StateViewSliceFixtures.res +8 -6
- package/tests/components/stateviewslice/StateViewSliceSubIdFixtures.res +17 -11
- package/tests/components/stateviewslice/StateViewSliceSubIdTest.res +12 -2
- package/tests/components/task/TaskFixtures.res +5 -5
- package/tests/components/task/TaskTest.res +95 -80
- package/tests/plugin/PluginsProjection_GWT.res +3 -1
- package/tests/plugin/UiFragments_GWT.res +6 -1
- package/tests/reset/LocalSeedResetTest.res +1 -0
|
@@ -30,65 +30,69 @@ let appendErrMsg = e =>
|
|
|
30
30
|
|
|
31
31
|
describe("DcbEventLogStorage_Sqlite", () => {
|
|
32
32
|
testPromise("append + read round-trips events with tags", async () => {
|
|
33
|
-
await runUnderSqlite(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
33
|
+
await runUnderSqlite(
|
|
34
|
+
async () => {
|
|
35
|
+
module TestBus = LocalBus.Make()
|
|
36
|
+
module Storage = LocalDcbEventLogStorage.Make(TestBus)
|
|
37
|
+
let s = Storage.make(
|
|
38
|
+
~name="dcb-rt",
|
|
39
|
+
~indexes=[],
|
|
40
|
+
~partitionTag=Reventless.DcbTag.Simple({key: "k"}),
|
|
41
|
+
~opts,
|
|
42
|
+
)
|
|
43
|
+
let ops = await s.operations->TestRunner.resolve
|
|
43
44
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
45
|
+
let tag1: Reventless.DcbTag.tag = {key: "itemId", value: "x1"}
|
|
46
|
+
let e1 = stored(
|
|
47
|
+
"ItemAdded",
|
|
48
|
+
[tag1],
|
|
49
|
+
JSON.Encode.object(Dict.fromArray([("name", JSON.Encode.string("widget"))])),
|
|
50
|
+
)
|
|
51
|
+
let result = await ops.append([e1])
|
|
52
|
+
switch result {
|
|
53
|
+
| Ok(_) => expect(true)->toBe(true)
|
|
54
|
+
| Error(e) => expect(appendErrMsg(e))->toBe("Ok")
|
|
55
|
+
}
|
|
55
56
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
57
|
+
let read = await ops.read(~query=[])
|
|
58
|
+
expect(read.events->Array.length)->toBe(1)
|
|
59
|
+
let first = read.events->Array.getUnsafe(0)
|
|
60
|
+
expect(first.eventType)->toBe("ItemAdded")
|
|
61
|
+
expect(first.tags->Array.length)->toBe(1)
|
|
62
|
+
expect((first.tags->Array.getUnsafe(0)).key)->toBe("itemId")
|
|
63
|
+
expect((first.tags->Array.getUnsafe(0)).value)->toBe("x1")
|
|
64
|
+
},
|
|
65
|
+
)
|
|
64
66
|
})
|
|
65
67
|
|
|
66
68
|
testPromise("read filters by tag", async () => {
|
|
67
|
-
await runUnderSqlite(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
let ops = await s.operations->TestRunner.resolve
|
|
77
|
-
|
|
78
|
-
let mk = (id, name) =>
|
|
79
|
-
stored(
|
|
80
|
-
"ItemAdded",
|
|
81
|
-
[{key: "itemId", value: id}],
|
|
82
|
-
JSON.Encode.object(Dict.fromArray([("name", JSON.Encode.string(name))])),
|
|
69
|
+
await runUnderSqlite(
|
|
70
|
+
async () => {
|
|
71
|
+
module TestBus = LocalBus.Make()
|
|
72
|
+
module Storage = LocalDcbEventLogStorage.Make(TestBus)
|
|
73
|
+
let s = Storage.make(
|
|
74
|
+
~name="dcb-tagfilter",
|
|
75
|
+
~indexes=[],
|
|
76
|
+
~partitionTag=Reventless.DcbTag.Simple({key: "k"}),
|
|
77
|
+
~opts,
|
|
83
78
|
)
|
|
79
|
+
let ops = await s.operations->TestRunner.resolve
|
|
84
80
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
81
|
+
let mk = (id, name) =>
|
|
82
|
+
stored(
|
|
83
|
+
"ItemAdded",
|
|
84
|
+
[{key: "itemId", value: id}],
|
|
85
|
+
JSON.Encode.object(Dict.fromArray([("name", JSON.Encode.string(name))])),
|
|
86
|
+
)
|
|
88
87
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
88
|
+
let _ = await ops.append([mk("a1", "alpha")])
|
|
89
|
+
let _ = await ops.append([mk("b1", "beta")])
|
|
90
|
+
let _ = await ops.append([mk("a1", "again")])
|
|
91
|
+
|
|
92
|
+
let read = await ops.read(~query=[{tags: [{key: "itemId", value: "a1"}]}])
|
|
93
|
+
expect(read.events->Array.length)->toBe(2)
|
|
94
|
+
},
|
|
95
|
+
)
|
|
92
96
|
})
|
|
93
97
|
|
|
94
98
|
// Backend contract: an empty tag value (an absent composite-partition member) is
|
|
@@ -96,135 +100,138 @@ describe("DcbEventLogStorage_Sqlite", () => {
|
|
|
96
100
|
// the partition read and a composite read. Held identically by the in-memory and
|
|
97
101
|
// DynamoDB backends. See docs/plans/done/dcb-empty-tag-values-break-append.md.
|
|
98
102
|
testPromise("an empty tag value appends and stays readable", async () => {
|
|
99
|
-
await runUnderSqlite(
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
103
|
+
await runUnderSqlite(
|
|
104
|
+
async () => {
|
|
105
|
+
module TestBus = LocalBus.Make()
|
|
106
|
+
module Storage = LocalDcbEventLogStorage.Make(TestBus)
|
|
107
|
+
let s = Storage.make(
|
|
108
|
+
~name="dcb-emptytag",
|
|
109
|
+
~indexes=[],
|
|
110
|
+
~partitionTag=Reventless.DcbTag.Simple({key: "itemId"}),
|
|
111
|
+
~opts,
|
|
112
|
+
)
|
|
113
|
+
let ops = await s.operations->TestRunner.resolve
|
|
109
114
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
115
|
+
let tags = [{Reventless.DcbTag.key: "itemId", value: "i1"}, {key: "variantId", value: ""}]
|
|
116
|
+
let result = await ops.append([stored("ItemAdded", tags, JSON.Encode.string("x"))])
|
|
117
|
+
switch result {
|
|
118
|
+
| Ok(_) => expect(true)->toBe(true)
|
|
119
|
+
| Error(e) => expect(appendErrMsg(e))->toBe("Ok")
|
|
120
|
+
}
|
|
116
121
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
122
|
+
let byPartition = await ops.read(~query=[{tags: [{key: "itemId", value: "i1"}]}])
|
|
123
|
+
expect(byPartition.events->Array.length)->toBe(1)
|
|
124
|
+
expect(
|
|
125
|
+
(byPartition.events->Array.getUnsafe(0)).tags->Array.map(t => (t.key, t.value)),
|
|
126
|
+
)->toEqual([("itemId", "i1"), ("variantId", "")])
|
|
121
127
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
128
|
+
let byComposite = await ops.read(~query=[{tags: tags}])
|
|
129
|
+
expect(byComposite.events->Array.length)->toBe(1)
|
|
130
|
+
},
|
|
131
|
+
)
|
|
125
132
|
})
|
|
126
133
|
|
|
127
134
|
testPromise("batched tag hydration preserves per-event tags and order", async () => {
|
|
128
|
-
await runUnderSqlite(
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
135
|
+
await runUnderSqlite(
|
|
136
|
+
async () => {
|
|
137
|
+
module TestBus = LocalBus.Make()
|
|
138
|
+
module Storage = LocalDcbEventLogStorage.Make(TestBus)
|
|
139
|
+
let s = Storage.make(
|
|
140
|
+
~name="dcb-multitag",
|
|
141
|
+
~indexes=[],
|
|
142
|
+
~partitionTag=Reventless.DcbTag.Simple({key: "k"}),
|
|
143
|
+
~opts,
|
|
144
|
+
)
|
|
145
|
+
let ops = await s.operations->TestRunner.resolve
|
|
138
146
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
],
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
let e3 = stored("None", [], JSON.Encode.string("third"))
|
|
151
|
-
let _ = await ops.append([e1])
|
|
152
|
-
let _ = await ops.append([e2])
|
|
153
|
-
let _ = await ops.append([e3])
|
|
147
|
+
// e1 carries three tags (declaration order matters); e2 carries one; e3 none.
|
|
148
|
+
let e1 = stored(
|
|
149
|
+
"Multi",
|
|
150
|
+
[{key: "a", value: "1"}, {key: "b", value: "2"}, {key: "c", value: "3"}],
|
|
151
|
+
JSON.Encode.string("first"),
|
|
152
|
+
)
|
|
153
|
+
let e2 = stored("Single", [{key: "only", value: "z"}], JSON.Encode.string("second"))
|
|
154
|
+
let e3 = stored("None", [], JSON.Encode.string("third"))
|
|
155
|
+
let _ = await ops.append([e1])
|
|
156
|
+
let _ = await ops.append([e2])
|
|
157
|
+
let _ = await ops.append([e3])
|
|
154
158
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
159
|
+
let read = await ops.read(~query=[])
|
|
160
|
+
expect(read.events->Array.length)->toBe(3)
|
|
161
|
+
let first = read.events->Array.getUnsafe(0)
|
|
162
|
+
// Order and grouping survive the single batched IN query.
|
|
163
|
+
expect(first.tags->Array.map(t => t.key))->toEqual(["a", "b", "c"])
|
|
164
|
+
expect(first.tags->Array.map(t => t.value))->toEqual(["1", "2", "3"])
|
|
165
|
+
let second = read.events->Array.getUnsafe(1)
|
|
166
|
+
expect(second.tags->Array.length)->toBe(1)
|
|
167
|
+
expect((second.tags->Array.getUnsafe(0)).key)->toBe("only")
|
|
168
|
+
let third = read.events->Array.getUnsafe(2)
|
|
169
|
+
expect(third.tags->Array.length)->toBe(0)
|
|
170
|
+
},
|
|
171
|
+
)
|
|
167
172
|
})
|
|
168
173
|
|
|
169
174
|
testPromise("append with a non-conflicting condition succeeds", async () => {
|
|
170
|
-
await runUnderSqlite(
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
175
|
+
await runUnderSqlite(
|
|
176
|
+
async () => {
|
|
177
|
+
module TestBus = LocalBus.Make()
|
|
178
|
+
module Storage = LocalDcbEventLogStorage.Make(TestBus)
|
|
179
|
+
let s = Storage.make(
|
|
180
|
+
~name="dcb-noconflict",
|
|
181
|
+
~indexes=[],
|
|
182
|
+
~partitionTag=Reventless.DcbTag.Simple({key: "k"}),
|
|
183
|
+
~opts,
|
|
184
|
+
)
|
|
185
|
+
let ops = await s.operations->TestRunner.resolve
|
|
180
186
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
187
|
+
let _ = await ops.append([
|
|
188
|
+
stored("Created", [{key: "id", value: "x"}], JSON.Encode.string("a")),
|
|
189
|
+
])
|
|
190
|
+
// Condition queries a tag value that does not exist → anyMatch is false →
|
|
191
|
+
// the append is allowed.
|
|
192
|
+
let cond: Reventless.DcbTag.appendCondition = {
|
|
193
|
+
query: [{tags: [{key: "id", value: "other"}]}],
|
|
194
|
+
}
|
|
195
|
+
let result = await ops.append(
|
|
196
|
+
[stored("Created", [{key: "id", value: "other"}], JSON.Encode.string("b"))],
|
|
197
|
+
~condition=cond,
|
|
198
|
+
)
|
|
199
|
+
switch result {
|
|
200
|
+
| Ok(_) => expect(true)->toBe(true)
|
|
201
|
+
| Error(e) => expect(appendErrMsg(e))->toBe("Ok")
|
|
202
|
+
}
|
|
203
|
+
let read = await ops.read(~query=[])
|
|
204
|
+
expect(read.events->Array.length)->toBe(2)
|
|
205
|
+
},
|
|
206
|
+
)
|
|
198
207
|
})
|
|
199
208
|
|
|
200
209
|
testPromise("append with conflicting condition returns Error", async () => {
|
|
201
|
-
await runUnderSqlite(
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
210
|
+
await runUnderSqlite(
|
|
211
|
+
async () => {
|
|
212
|
+
module TestBus = LocalBus.Make()
|
|
213
|
+
module Storage = LocalDcbEventLogStorage.Make(TestBus)
|
|
214
|
+
let s = Storage.make(
|
|
215
|
+
~name="dcb-conflict",
|
|
216
|
+
~indexes=[],
|
|
217
|
+
~partitionTag=Reventless.DcbTag.Simple({key: "k"}),
|
|
218
|
+
~opts,
|
|
219
|
+
)
|
|
220
|
+
let ops = await s.operations->TestRunner.resolve
|
|
211
221
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
[{key: "id", value: "x"}],
|
|
215
|
-
JSON.Encode.string("first"),
|
|
216
|
-
)
|
|
217
|
-
let _ = await ops.append([e])
|
|
222
|
+
let e = stored("Created", [{key: "id", value: "x"}], JSON.Encode.string("first"))
|
|
223
|
+
let _ = await ops.append([e])
|
|
218
224
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
225
|
+
let cond: Reventless.DcbTag.appendCondition = {
|
|
226
|
+
query: [{tags: [{key: "id", value: "x"}]}],
|
|
227
|
+
}
|
|
228
|
+
let result = await ops.append([e], ~condition=cond)
|
|
229
|
+
switch result {
|
|
230
|
+
| Error(_) => expect(true)->toBe(true)
|
|
231
|
+
| Ok(_) => expect("expected conflict")->toBe("got Ok")
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
)
|
|
228
235
|
})
|
|
229
236
|
|
|
230
237
|
testPromise("events persist across a file reopen", async () => {
|
|
@@ -242,11 +249,7 @@ describe("DcbEventLogStorage_Sqlite", () => {
|
|
|
242
249
|
~opts,
|
|
243
250
|
)
|
|
244
251
|
let ops = await s.operations->TestRunner.resolve
|
|
245
|
-
let e = stored(
|
|
246
|
-
"Created",
|
|
247
|
-
[{key: "id", value: "p"}],
|
|
248
|
-
JSON.Encode.int(1),
|
|
249
|
-
)
|
|
252
|
+
let e = stored("Created", [{key: "id", value: "p"}], JSON.Encode.int(1))
|
|
250
253
|
let _ = await ops.append([e])
|
|
251
254
|
db->SqliteDriver.close
|
|
252
255
|
BackendState.setMemory()
|