envio 3.0.0-alpha.21 → 3.0.0-alpha.23
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/README.md +3 -3
- package/bin.mjs +2 -48
- package/evm.schema.json +67 -0
- package/fuel.schema.json +67 -0
- package/index.d.ts +822 -38
- package/index.js +5 -3
- package/package.json +10 -8
- package/rescript.json +5 -9
- package/src/Address.res +4 -5
- package/src/Address.res.mjs +9 -12
- package/src/Api.res +15 -0
- package/src/Api.res.mjs +20 -0
- package/src/Batch.res +32 -34
- package/src/Batch.res.mjs +172 -187
- package/src/Bin.res +89 -0
- package/src/Bin.res.mjs +97 -0
- package/src/ChainFetcher.res +33 -57
- package/src/ChainFetcher.res.mjs +197 -227
- package/src/ChainManager.res +6 -14
- package/src/ChainManager.res.mjs +74 -85
- package/src/ChainMap.res +14 -16
- package/src/ChainMap.res.mjs +38 -38
- package/src/Config.res +193 -135
- package/src/Config.res.mjs +566 -592
- package/src/Core.res +182 -0
- package/src/Core.res.mjs +207 -0
- package/src/Ecosystem.res +25 -4
- package/src/Ecosystem.res.mjs +12 -13
- package/src/Env.res +20 -13
- package/src/Env.res.mjs +124 -113
- package/src/EnvSafe.res +269 -0
- package/src/EnvSafe.res.mjs +296 -0
- package/src/EnvSafe.resi +18 -0
- package/src/Envio.res +37 -26
- package/src/Envio.res.mjs +59 -60
- package/src/ErrorHandling.res +2 -2
- package/src/ErrorHandling.res.mjs +15 -15
- package/src/EventConfigBuilder.res +219 -81
- package/src/EventConfigBuilder.res.mjs +259 -202
- package/src/EventProcessing.res +27 -38
- package/src/EventProcessing.res.mjs +165 -183
- package/src/EventUtils.res +11 -11
- package/src/EventUtils.res.mjs +21 -22
- package/src/EvmTypes.res +0 -1
- package/src/EvmTypes.res.mjs +5 -5
- package/src/FetchState.res +360 -256
- package/src/FetchState.res.mjs +958 -914
- package/src/GlobalState.res +365 -351
- package/src/GlobalState.res.mjs +958 -992
- package/src/GlobalStateManager.res +1 -2
- package/src/GlobalStateManager.res.mjs +36 -44
- package/src/HandlerLoader.res +107 -23
- package/src/HandlerLoader.res.mjs +128 -38
- package/src/HandlerRegister.res +127 -103
- package/src/HandlerRegister.res.mjs +164 -164
- package/src/HandlerRegister.resi +12 -4
- package/src/Hasura.res +35 -22
- package/src/Hasura.res.mjs +158 -167
- package/src/InMemoryStore.res +20 -27
- package/src/InMemoryStore.res.mjs +64 -80
- package/src/InMemoryTable.res +34 -39
- package/src/InMemoryTable.res.mjs +165 -170
- package/src/Internal.res +52 -33
- package/src/Internal.res.mjs +84 -81
- package/src/LazyLoader.res.mjs +55 -61
- package/src/LoadLayer.res +77 -78
- package/src/LoadLayer.res.mjs +160 -189
- package/src/LoadManager.res +16 -21
- package/src/LoadManager.res.mjs +79 -84
- package/src/LogSelection.res +236 -68
- package/src/LogSelection.res.mjs +211 -141
- package/src/Logging.res +13 -9
- package/src/Logging.res.mjs +130 -143
- package/src/Main.res +430 -51
- package/src/Main.res.mjs +530 -271
- package/src/Persistence.res +80 -84
- package/src/Persistence.res.mjs +131 -132
- package/src/PgStorage.res +294 -167
- package/src/PgStorage.res.mjs +799 -817
- package/src/Prometheus.res +50 -58
- package/src/Prometheus.res.mjs +345 -373
- package/src/ReorgDetection.res +22 -24
- package/src/ReorgDetection.res.mjs +100 -106
- package/src/SafeCheckpointTracking.res +7 -7
- package/src/SafeCheckpointTracking.res.mjs +40 -43
- package/src/SimulateItems.res +41 -49
- package/src/SimulateItems.res.mjs +257 -272
- package/src/Sink.res +2 -2
- package/src/Sink.res.mjs +22 -26
- package/src/TableIndices.res +1 -2
- package/src/TableIndices.res.mjs +42 -48
- package/src/TestIndexer.res +196 -189
- package/src/TestIndexer.res.mjs +536 -536
- package/src/TestIndexerProxyStorage.res +16 -16
- package/src/TestIndexerProxyStorage.res.mjs +99 -122
- package/src/TestIndexerWorker.res +4 -0
- package/src/TestIndexerWorker.res.mjs +7 -0
- package/src/Throttler.res +3 -3
- package/src/Throttler.res.mjs +23 -24
- package/src/Time.res +1 -1
- package/src/Time.res.mjs +18 -21
- package/src/TopicFilter.res +3 -3
- package/src/TopicFilter.res.mjs +29 -30
- package/src/UserContext.res +93 -54
- package/src/UserContext.res.mjs +197 -182
- package/src/Utils.res +141 -86
- package/src/Utils.res.mjs +334 -295
- package/src/bindings/BigDecimal.res +0 -2
- package/src/bindings/BigDecimal.res.mjs +19 -23
- package/src/bindings/ClickHouse.res +28 -27
- package/src/bindings/ClickHouse.res.mjs +243 -240
- package/src/bindings/DateFns.res +11 -11
- package/src/bindings/DateFns.res.mjs +7 -7
- package/src/bindings/EventSource.res.mjs +2 -2
- package/src/bindings/Express.res +2 -5
- package/src/bindings/Hrtime.res +2 -2
- package/src/bindings/Hrtime.res.mjs +30 -32
- package/src/bindings/Lodash.res.mjs +1 -1
- package/src/bindings/NodeJs.res +14 -9
- package/src/bindings/NodeJs.res.mjs +20 -20
- package/src/bindings/Pino.res +8 -10
- package/src/bindings/Pino.res.mjs +40 -43
- package/src/bindings/Postgres.res +7 -5
- package/src/bindings/Postgres.res.mjs +9 -9
- package/src/bindings/PromClient.res +17 -2
- package/src/bindings/PromClient.res.mjs +30 -7
- package/src/bindings/SDSL.res.mjs +2 -2
- package/src/bindings/Viem.res +4 -4
- package/src/bindings/Viem.res.mjs +20 -22
- package/src/bindings/Vitest.res +1 -1
- package/src/bindings/Vitest.res.mjs +2 -2
- package/src/bindings/WebSocket.res +1 -1
- package/src/db/EntityHistory.res +9 -3
- package/src/db/EntityHistory.res.mjs +84 -59
- package/src/db/InternalTable.res +62 -60
- package/src/db/InternalTable.res.mjs +271 -203
- package/src/db/Schema.res +1 -2
- package/src/db/Schema.res.mjs +28 -32
- package/src/db/Table.res +28 -27
- package/src/db/Table.res.mjs +276 -292
- package/src/sources/EventRouter.res +21 -16
- package/src/sources/EventRouter.res.mjs +55 -57
- package/src/sources/Evm.res +17 -1
- package/src/sources/Evm.res.mjs +16 -8
- package/src/sources/EvmChain.res +15 -17
- package/src/sources/EvmChain.res.mjs +40 -42
- package/src/sources/Fuel.res +14 -1
- package/src/sources/Fuel.res.mjs +16 -8
- package/src/sources/FuelSDK.res +1 -1
- package/src/sources/FuelSDK.res.mjs +6 -8
- package/src/sources/HyperFuel.res +8 -10
- package/src/sources/HyperFuel.res.mjs +113 -123
- package/src/sources/HyperFuelClient.res.mjs +6 -7
- package/src/sources/HyperFuelSource.res +19 -20
- package/src/sources/HyperFuelSource.res.mjs +339 -356
- package/src/sources/HyperSync.res +11 -13
- package/src/sources/HyperSync.res.mjs +206 -220
- package/src/sources/HyperSyncClient.res +5 -7
- package/src/sources/HyperSyncClient.res.mjs +70 -75
- package/src/sources/HyperSyncHeightStream.res +8 -9
- package/src/sources/HyperSyncHeightStream.res.mjs +78 -86
- package/src/sources/HyperSyncJsonApi.res +18 -15
- package/src/sources/HyperSyncJsonApi.res.mjs +201 -231
- package/src/sources/HyperSyncSource.res +17 -21
- package/src/sources/HyperSyncSource.res.mjs +268 -290
- package/src/sources/Rpc.res +5 -5
- package/src/sources/Rpc.res.mjs +168 -192
- package/src/sources/RpcSource.res +166 -167
- package/src/sources/RpcSource.res.mjs +972 -1046
- package/src/sources/RpcWebSocketHeightStream.res +10 -11
- package/src/sources/RpcWebSocketHeightStream.res.mjs +131 -145
- package/src/sources/SimulateSource.res +1 -1
- package/src/sources/SimulateSource.res.mjs +35 -38
- package/src/sources/Source.res +1 -1
- package/src/sources/Source.res.mjs +3 -3
- package/src/sources/SourceManager.res +39 -20
- package/src/sources/SourceManager.res.mjs +340 -371
- package/src/sources/SourceManager.resi +2 -1
- package/src/sources/Svm.res +12 -5
- package/src/sources/Svm.res.mjs +44 -41
- package/src/tui/Tui.res +23 -12
- package/src/tui/Tui.res.mjs +292 -290
- package/src/tui/bindings/Ink.res +2 -4
- package/src/tui/bindings/Ink.res.mjs +35 -41
- package/src/tui/components/BufferedProgressBar.res +7 -7
- package/src/tui/components/BufferedProgressBar.res.mjs +46 -46
- package/src/tui/components/CustomHooks.res +1 -2
- package/src/tui/components/CustomHooks.res.mjs +102 -122
- package/src/tui/components/Messages.res +1 -2
- package/src/tui/components/Messages.res.mjs +38 -42
- package/src/tui/components/SyncETA.res +10 -11
- package/src/tui/components/SyncETA.res.mjs +178 -196
- package/src/tui/components/TuiData.res +1 -1
- package/src/tui/components/TuiData.res.mjs +7 -6
- package/src/vendored/Rest.res +52 -66
- package/src/vendored/Rest.res.mjs +324 -364
- package/svm.schema.json +67 -0
- package/src/Address.gen.ts +0 -8
- package/src/Config.gen.ts +0 -19
- package/src/Envio.gen.ts +0 -55
- package/src/EvmTypes.gen.ts +0 -6
- package/src/InMemoryStore.gen.ts +0 -6
- package/src/Internal.gen.ts +0 -64
- package/src/PgStorage.gen.ts +0 -10
- package/src/PgStorage.res.d.mts +0 -5
- package/src/Types.ts +0 -56
- package/src/bindings/BigDecimal.gen.ts +0 -14
- package/src/bindings/BigDecimal.res.d.mts +0 -5
- package/src/bindings/BigInt.gen.ts +0 -10
- package/src/bindings/BigInt.res +0 -70
- package/src/bindings/BigInt.res.d.mts +0 -5
- package/src/bindings/BigInt.res.mjs +0 -154
- package/src/bindings/Ethers.res.d.mts +0 -5
- package/src/bindings/Pino.gen.ts +0 -17
- package/src/bindings/Postgres.gen.ts +0 -8
- package/src/bindings/Postgres.res.d.mts +0 -5
- package/src/bindings/Promise.res +0 -67
- package/src/bindings/Promise.res.mjs +0 -26
- package/src/db/InternalTable.gen.ts +0 -36
- package/src/sources/HyperSyncClient.gen.ts +0 -19
package/src/HandlerRegister.res
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
type eventRegistration = {
|
|
2
2
|
handler: option<Internal.handler>,
|
|
3
3
|
contractRegister: option<Internal.contractRegister>,
|
|
4
|
-
eventOptions: option<Internal.eventOptions<
|
|
4
|
+
eventOptions: option<Internal.eventOptions<JSON.t>>,
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
let empty = {
|
|
@@ -10,7 +10,59 @@ let empty = {
|
|
|
10
10
|
eventOptions: None,
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
type registrations = {onBlockByChainId: dict<array<Internal.onBlockConfig>>}
|
|
14
|
+
|
|
15
|
+
type activeRegistration = {
|
|
16
|
+
ecosystem: Ecosystem.t,
|
|
17
|
+
multichain: Internal.multichain,
|
|
18
|
+
registrations: registrations,
|
|
19
|
+
mutable finished: bool,
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Stashed on `globalThis` so a duplicate envio module instance — e.g. when the
|
|
23
|
+
// CLI's `bin.mjs` resolves envio from one path but the user's handlers resolve
|
|
24
|
+
// it from `node_modules/envio` — shares one registry. Without this, each copy
|
|
25
|
+
// keeps its own dict and `applyRegistrations` reads empty state.
|
|
26
|
+
//
|
|
27
|
+
// Version-gated: the record shapes below can evolve between envio versions,
|
|
28
|
+
// so the guard uses strict full-version equality. On mismatch we throw with
|
|
29
|
+
// a deduplication hint instead of silently mixing shapes across builds.
|
|
30
|
+
type registryShape = {
|
|
31
|
+
version: string,
|
|
32
|
+
eventRegistrations: dict<eventRegistration>,
|
|
33
|
+
activeRegistration: ref<option<activeRegistration>>,
|
|
34
|
+
preRegistered: array<activeRegistration => unit>,
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Record type with `mutable` so assignment typechecks; ReScript keeps the
|
|
38
|
+
// field name verbatim in the generated JS so the globalThis slot is
|
|
39
|
+
// `__envioRegistry`.
|
|
40
|
+
type globalThis = {mutable __envioRegistry: Nullable.t<registryShape>}
|
|
41
|
+
@val external globalThis: globalThis = "globalThis"
|
|
42
|
+
|
|
43
|
+
%%private(
|
|
44
|
+
let registry: registryShape = {
|
|
45
|
+
let version = Utils.EnvioPackage.value.version
|
|
46
|
+
switch globalThis.__envioRegistry->Nullable.toOption {
|
|
47
|
+
| Some(existing) if existing.version === version => existing
|
|
48
|
+
| Some(existing) =>
|
|
49
|
+
JsError.throwWithMessage(
|
|
50
|
+
`Multiple incompatible envio versions loaded in the same process: ${existing.version} and ${version}. Deduplicate the 'envio' dependency in your project.`,
|
|
51
|
+
)
|
|
52
|
+
| None =>
|
|
53
|
+
let fresh = {
|
|
54
|
+
version,
|
|
55
|
+
eventRegistrations: Dict.make(),
|
|
56
|
+
activeRegistration: ref(None),
|
|
57
|
+
preRegistered: [],
|
|
58
|
+
}
|
|
59
|
+
globalThis.__envioRegistry = Nullable.make(fresh)
|
|
60
|
+
fresh
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
let eventRegistrations = registry.eventRegistrations
|
|
14
66
|
|
|
15
67
|
let getKey = (~contractName, ~eventName) => contractName ++ "." ++ eventName
|
|
16
68
|
|
|
@@ -22,19 +74,10 @@ let get = (~contractName, ~eventName) => {
|
|
|
22
74
|
}
|
|
23
75
|
|
|
24
76
|
let set = (~contractName, ~eventName, registration) => {
|
|
25
|
-
eventRegistrations->
|
|
77
|
+
eventRegistrations->Dict.set(getKey(~contractName, ~eventName), registration)
|
|
26
78
|
}
|
|
27
79
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
type activeRegistration = {
|
|
31
|
-
ecosystem: Ecosystem.t,
|
|
32
|
-
multichain: Internal.multichain,
|
|
33
|
-
registrations: registrations,
|
|
34
|
-
mutable finished: bool,
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
let activeRegistration = ref(None)
|
|
80
|
+
let activeRegistration = registry.activeRegistration
|
|
38
81
|
|
|
39
82
|
// Might happen for tests when the handler file
|
|
40
83
|
// is imported by a non-envio process (eg mocha)
|
|
@@ -43,14 +86,14 @@ let activeRegistration = ref(None)
|
|
|
43
86
|
// Theoretically we could keep preRegistration without an explicit start
|
|
44
87
|
// but I want it to be this way, so for the actual indexer run
|
|
45
88
|
// an error is thrown with the exact stack trace where the handler was registered.
|
|
46
|
-
let preRegistered =
|
|
89
|
+
let preRegistered = registry.preRegistered
|
|
47
90
|
|
|
48
91
|
let withRegistration = (fn: activeRegistration => unit) => {
|
|
49
92
|
switch activeRegistration.contents {
|
|
50
93
|
| None => preRegistered->Belt.Array.push(fn)
|
|
51
94
|
| Some(r) =>
|
|
52
95
|
if r.finished {
|
|
53
|
-
|
|
96
|
+
JsError.throwWithMessage(
|
|
54
97
|
"The indexer finished initializing, so no more handlers can be registered. Make sure the handlers are registered on the top level of the file.",
|
|
55
98
|
)
|
|
56
99
|
} else {
|
|
@@ -64,14 +107,14 @@ let startRegistration = (~ecosystem, ~multichain) => {
|
|
|
64
107
|
ecosystem,
|
|
65
108
|
multichain,
|
|
66
109
|
registrations: {
|
|
67
|
-
onBlockByChainId:
|
|
110
|
+
onBlockByChainId: Dict.make(),
|
|
68
111
|
},
|
|
69
112
|
finished: false,
|
|
70
113
|
}
|
|
71
114
|
activeRegistration.contents = Some(r)
|
|
72
|
-
while preRegistered->
|
|
115
|
+
while preRegistered->Array.length > 0 {
|
|
73
116
|
// Loop + cleanup in one go
|
|
74
|
-
switch preRegistered->
|
|
117
|
+
switch preRegistered->Array.pop {
|
|
75
118
|
| Some(fn) => fn(r)
|
|
76
119
|
| None => ()
|
|
77
120
|
}
|
|
@@ -85,7 +128,9 @@ let finishRegistration = () => {
|
|
|
85
128
|
r.registrations
|
|
86
129
|
}
|
|
87
130
|
| None =>
|
|
88
|
-
|
|
131
|
+
JsError.throwWithMessage(
|
|
132
|
+
"The indexer has not started registering handlers, so can't finish it.",
|
|
133
|
+
)
|
|
89
134
|
}
|
|
90
135
|
}
|
|
91
136
|
|
|
@@ -96,71 +141,57 @@ let isPendingRegistration = () => {
|
|
|
96
141
|
}
|
|
97
142
|
}
|
|
98
143
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
144
|
+
// Early guard called from `indexer.onEvent` / `.contractRegister` / `.onBlock` /
|
|
145
|
+
// `.onSlot` so the user sees a method-specific error at the call site, instead
|
|
146
|
+
// of hitting the generic `withRegistration` throw deep inside `setHandler` etc.
|
|
147
|
+
let throwIfFinishedRegistration = (~methodName) => {
|
|
148
|
+
switch activeRegistration.contents {
|
|
149
|
+
| Some({finished: true}) =>
|
|
150
|
+
JsError.throwWithMessage(
|
|
151
|
+
`Cannot call \`indexer.${methodName}\` after the indexer has started. Make sure all handlers are registered at the top level of your handler module.`,
|
|
152
|
+
)
|
|
153
|
+
| _ => ()
|
|
106
154
|
}
|
|
107
|
-
|
|
155
|
+
}
|
|
108
156
|
|
|
109
|
-
let
|
|
157
|
+
let registerOnBlock = (
|
|
158
|
+
~name,
|
|
159
|
+
~chainId,
|
|
160
|
+
~interval,
|
|
161
|
+
~startBlock,
|
|
162
|
+
~endBlock,
|
|
163
|
+
~handler: Internal.onBlockArgs => promise<unit>,
|
|
164
|
+
) => {
|
|
110
165
|
withRegistration(registration => {
|
|
111
166
|
// We need to get timestamp for ordered multichain mode
|
|
112
167
|
switch registration.multichain {
|
|
113
168
|
| Unordered => ()
|
|
114
169
|
| Ordered =>
|
|
115
|
-
|
|
170
|
+
JsError.throwWithMessage(
|
|
116
171
|
"Block Handlers are not supported for ordered multichain mode. Please reach out to the Envio team if you need this feature. Or enable unordered multichain mode by removing `multichain: ordered` from the config.yaml file.",
|
|
117
172
|
)
|
|
118
173
|
}
|
|
119
174
|
|
|
120
|
-
let options = rawOptions->S.parseOrThrow(onBlockOptionsSchema)
|
|
121
|
-
let chainId = switch options["chain"] {
|
|
122
|
-
| chainId => chainId
|
|
123
|
-
// Dmitry: I want to add names for chains in the future
|
|
124
|
-
// and to be able to use them as a lookup.
|
|
125
|
-
// To do so, we'll need to pass a config during reigstration
|
|
126
|
-
// instead of isInitialized check.
|
|
127
|
-
}
|
|
128
|
-
|
|
129
175
|
let onBlockByChainId = registration.registrations.onBlockByChainId
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
| Some(onBlockConfigs) =>
|
|
150
|
-
onBlockConfigs->Belt.Array.push(
|
|
151
|
-
(
|
|
152
|
-
{
|
|
153
|
-
index: onBlockConfigs->Belt.Array.length,
|
|
154
|
-
name: options["name"],
|
|
155
|
-
startBlock: options["startBlock"],
|
|
156
|
-
endBlock: options["endBlock"],
|
|
157
|
-
interval: options["interval"],
|
|
158
|
-
chainId,
|
|
159
|
-
handler,
|
|
160
|
-
}: Internal.onBlockConfig
|
|
161
|
-
),
|
|
162
|
-
)
|
|
163
|
-
}
|
|
176
|
+
let key = chainId->Belt.Int.toString
|
|
177
|
+
let index =
|
|
178
|
+
onBlockByChainId
|
|
179
|
+
->Utils.Dict.dangerouslyGetNonOption(key)
|
|
180
|
+
->Belt.Option.mapWithDefault(0, configs => configs->Belt.Array.length)
|
|
181
|
+
onBlockByChainId->Utils.Dict.push(
|
|
182
|
+
key,
|
|
183
|
+
(
|
|
184
|
+
{
|
|
185
|
+
index,
|
|
186
|
+
name,
|
|
187
|
+
startBlock,
|
|
188
|
+
endBlock,
|
|
189
|
+
interval,
|
|
190
|
+
chainId,
|
|
191
|
+
handler,
|
|
192
|
+
}: Internal.onBlockConfig
|
|
193
|
+
),
|
|
194
|
+
)
|
|
164
195
|
})
|
|
165
196
|
}
|
|
166
197
|
|
|
@@ -169,10 +200,8 @@ let getHandler = (~contractName, ~eventName) => get(~contractName, ~eventName).h
|
|
|
169
200
|
let getContractRegister = (~contractName, ~eventName) =>
|
|
170
201
|
get(~contractName, ~eventName).contractRegister
|
|
171
202
|
|
|
172
|
-
let
|
|
173
|
-
get(~contractName, ~eventName).eventOptions
|
|
174
|
-
->Belt.Option.flatMap(value => value.eventFilters)
|
|
175
|
-
->(Utils.magic: option<Internal.eventFilters> => option<Js.Json.t>)
|
|
203
|
+
let getOnEventWhere = (~contractName, ~eventName) =>
|
|
204
|
+
get(~contractName, ~eventName).eventOptions->Belt.Option.flatMap(value => value.where)
|
|
176
205
|
|
|
177
206
|
let isWildcard = (~contractName, ~eventName) =>
|
|
178
207
|
get(~contractName, ~eventName).eventOptions
|
|
@@ -189,26 +218,34 @@ type eventNamespace = {contractName: string, eventName: string}
|
|
|
189
218
|
let raiseDuplicateRegistration = (~contractName, ~eventName, ~msg, ~logger) => {
|
|
190
219
|
let fullMsg = msg ++ " for " ++ contractName ++ "." ++ eventName
|
|
191
220
|
Logging.createChildFrom(~logger, ~params={contractName, eventName})->Logging.childError(fullMsg)
|
|
192
|
-
|
|
221
|
+
JsError.throwWithMessage(fullMsg)
|
|
193
222
|
}
|
|
194
223
|
|
|
195
|
-
|
|
224
|
+
// Compare two raw `where` configs as the user passed them (object/array/bool/function).
|
|
225
|
+
// At registration time we haven't parsed the config into `Internal.eventFilters` yet,
|
|
226
|
+
// so structural equality on the raw JSON shape is what users actually wrote. For a
|
|
227
|
+
// dynamic callback (a function value) structural equality is meaningless, so fall
|
|
228
|
+
// back to referential equality on the function reference.
|
|
229
|
+
let whereMatch = (a: option<JSON.t>, b: option<JSON.t>) => {
|
|
196
230
|
switch (a, b) {
|
|
197
231
|
| (None, None) => true
|
|
198
|
-
| (Some(
|
|
199
|
-
|
|
232
|
+
| (Some(a), Some(b)) =>
|
|
233
|
+
if typeof(a) === #function || typeof(b) === #function {
|
|
234
|
+
a === b
|
|
235
|
+
} else {
|
|
236
|
+
a == b
|
|
237
|
+
}
|
|
200
238
|
| _ => false
|
|
201
239
|
}
|
|
202
240
|
}
|
|
203
241
|
|
|
204
242
|
let eventOptionsMatch = (
|
|
205
|
-
existing: option<Internal.eventOptions<
|
|
206
|
-
incoming: option<Internal.eventOptions<
|
|
243
|
+
existing: option<Internal.eventOptions<JSON.t>>,
|
|
244
|
+
incoming: option<Internal.eventOptions<JSON.t>>,
|
|
207
245
|
) => {
|
|
208
246
|
switch (existing, incoming) {
|
|
209
247
|
| (None, None) => true
|
|
210
|
-
| (Some(a), Some(b)) =>
|
|
211
|
-
a.wildcard === b.wildcard && eventFiltersMatch(a.eventFilters, b.eventFilters)
|
|
248
|
+
| (Some(a), Some(b)) => a.wildcard === b.wildcard && whereMatch(a.where, b.where)
|
|
212
249
|
| _ => false
|
|
213
250
|
}
|
|
214
251
|
}
|
|
@@ -216,12 +253,7 @@ let eventOptionsMatch = (
|
|
|
216
253
|
let setEventOptions = (~contractName, ~eventName, ~eventOptions, ~logger=Logging.getLogger()) => {
|
|
217
254
|
switch eventOptions {
|
|
218
255
|
| Some(value) =>
|
|
219
|
-
let value =
|
|
220
|
-
value->(
|
|
221
|
-
Utils.magic: Internal.eventOptions<'eventFilters> => Internal.eventOptions<
|
|
222
|
-
Internal.eventFilters,
|
|
223
|
-
>
|
|
224
|
-
)
|
|
256
|
+
let value = value->(Utils.magic: Internal.eventOptions<'where> => Internal.eventOptions<JSON.t>)
|
|
225
257
|
let t = get(~contractName, ~eventName)
|
|
226
258
|
switch t.eventOptions {
|
|
227
259
|
| None => set(~contractName, ~eventName, {...t, eventOptions: Some(value)})
|
|
@@ -230,7 +262,7 @@ let setEventOptions = (~contractName, ~eventName, ~eventOptions, ~logger=Logging
|
|
|
230
262
|
raiseDuplicateRegistration(
|
|
231
263
|
~contractName,
|
|
232
264
|
~eventName,
|
|
233
|
-
~msg="Cannot register handler with different options. Make sure all handlers for the same event use identical options (wildcard,
|
|
265
|
+
~msg="Cannot register handler with different options. Make sure all handlers for the same event use identical options (wildcard, where)",
|
|
234
266
|
~logger,
|
|
235
267
|
)
|
|
236
268
|
}
|
|
@@ -264,11 +296,7 @@ let setHandler = (
|
|
|
264
296
|
| Some(prevHandler) =>
|
|
265
297
|
let incomingEventOptions =
|
|
266
298
|
eventOptions->Belt.Option.map(v =>
|
|
267
|
-
v->(
|
|
268
|
-
Utils.magic: Internal.eventOptions<'eventFilters> => Internal.eventOptions<
|
|
269
|
-
Internal.eventFilters,
|
|
270
|
-
>
|
|
271
|
-
)
|
|
299
|
+
v->(Utils.magic: Internal.eventOptions<'where> => Internal.eventOptions<JSON.t>)
|
|
272
300
|
)
|
|
273
301
|
if eventOptionsMatch(t.eventOptions, incomingEventOptions) {
|
|
274
302
|
let composedHandler: Internal.handler = async args => {
|
|
@@ -287,7 +315,7 @@ let setHandler = (
|
|
|
287
315
|
raiseDuplicateRegistration(
|
|
288
316
|
~contractName,
|
|
289
317
|
~eventName,
|
|
290
|
-
~msg="Cannot register a second handler with different options. Make sure all handlers for the same event use identical options (wildcard,
|
|
318
|
+
~msg="Cannot register a second handler with different options. Make sure all handlers for the same event use identical options (wildcard, where)",
|
|
291
319
|
~logger,
|
|
292
320
|
)
|
|
293
321
|
}
|
|
@@ -325,11 +353,7 @@ let setContractRegister = (
|
|
|
325
353
|
| Some(prevContractRegister) =>
|
|
326
354
|
let incomingEventOptions =
|
|
327
355
|
eventOptions->Belt.Option.map(v =>
|
|
328
|
-
v->(
|
|
329
|
-
Utils.magic: Internal.eventOptions<'eventFilters> => Internal.eventOptions<
|
|
330
|
-
Internal.eventFilters,
|
|
331
|
-
>
|
|
332
|
-
)
|
|
356
|
+
v->(Utils.magic: Internal.eventOptions<'where> => Internal.eventOptions<JSON.t>)
|
|
333
357
|
)
|
|
334
358
|
if eventOptionsMatch(t.eventOptions, incomingEventOptions) {
|
|
335
359
|
let composedContractRegister: Internal.contractRegister = async args => {
|
|
@@ -348,7 +372,7 @@ let setContractRegister = (
|
|
|
348
372
|
raiseDuplicateRegistration(
|
|
349
373
|
~contractName,
|
|
350
374
|
~eventName,
|
|
351
|
-
~msg="Cannot register a second contractRegister with different options. Make sure all handlers for the same event use identical options (wildcard,
|
|
375
|
+
~msg="Cannot register a second contractRegister with different options. Make sure all handlers for the same event use identical options (wildcard, where)",
|
|
352
376
|
~logger,
|
|
353
377
|
)
|
|
354
378
|
}
|