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.
Files changed (220) hide show
  1. package/README.md +3 -3
  2. package/bin.mjs +2 -48
  3. package/evm.schema.json +67 -0
  4. package/fuel.schema.json +67 -0
  5. package/index.d.ts +822 -38
  6. package/index.js +5 -3
  7. package/package.json +10 -8
  8. package/rescript.json +5 -9
  9. package/src/Address.res +4 -5
  10. package/src/Address.res.mjs +9 -12
  11. package/src/Api.res +15 -0
  12. package/src/Api.res.mjs +20 -0
  13. package/src/Batch.res +32 -34
  14. package/src/Batch.res.mjs +172 -187
  15. package/src/Bin.res +89 -0
  16. package/src/Bin.res.mjs +97 -0
  17. package/src/ChainFetcher.res +33 -57
  18. package/src/ChainFetcher.res.mjs +197 -227
  19. package/src/ChainManager.res +6 -14
  20. package/src/ChainManager.res.mjs +74 -85
  21. package/src/ChainMap.res +14 -16
  22. package/src/ChainMap.res.mjs +38 -38
  23. package/src/Config.res +193 -135
  24. package/src/Config.res.mjs +566 -592
  25. package/src/Core.res +182 -0
  26. package/src/Core.res.mjs +207 -0
  27. package/src/Ecosystem.res +25 -4
  28. package/src/Ecosystem.res.mjs +12 -13
  29. package/src/Env.res +20 -13
  30. package/src/Env.res.mjs +124 -113
  31. package/src/EnvSafe.res +269 -0
  32. package/src/EnvSafe.res.mjs +296 -0
  33. package/src/EnvSafe.resi +18 -0
  34. package/src/Envio.res +37 -26
  35. package/src/Envio.res.mjs +59 -60
  36. package/src/ErrorHandling.res +2 -2
  37. package/src/ErrorHandling.res.mjs +15 -15
  38. package/src/EventConfigBuilder.res +219 -81
  39. package/src/EventConfigBuilder.res.mjs +259 -202
  40. package/src/EventProcessing.res +27 -38
  41. package/src/EventProcessing.res.mjs +165 -183
  42. package/src/EventUtils.res +11 -11
  43. package/src/EventUtils.res.mjs +21 -22
  44. package/src/EvmTypes.res +0 -1
  45. package/src/EvmTypes.res.mjs +5 -5
  46. package/src/FetchState.res +360 -256
  47. package/src/FetchState.res.mjs +958 -914
  48. package/src/GlobalState.res +365 -351
  49. package/src/GlobalState.res.mjs +958 -992
  50. package/src/GlobalStateManager.res +1 -2
  51. package/src/GlobalStateManager.res.mjs +36 -44
  52. package/src/HandlerLoader.res +107 -23
  53. package/src/HandlerLoader.res.mjs +128 -38
  54. package/src/HandlerRegister.res +127 -103
  55. package/src/HandlerRegister.res.mjs +164 -164
  56. package/src/HandlerRegister.resi +12 -4
  57. package/src/Hasura.res +35 -22
  58. package/src/Hasura.res.mjs +158 -167
  59. package/src/InMemoryStore.res +20 -27
  60. package/src/InMemoryStore.res.mjs +64 -80
  61. package/src/InMemoryTable.res +34 -39
  62. package/src/InMemoryTable.res.mjs +165 -170
  63. package/src/Internal.res +52 -33
  64. package/src/Internal.res.mjs +84 -81
  65. package/src/LazyLoader.res.mjs +55 -61
  66. package/src/LoadLayer.res +77 -78
  67. package/src/LoadLayer.res.mjs +160 -189
  68. package/src/LoadManager.res +16 -21
  69. package/src/LoadManager.res.mjs +79 -84
  70. package/src/LogSelection.res +236 -68
  71. package/src/LogSelection.res.mjs +211 -141
  72. package/src/Logging.res +13 -9
  73. package/src/Logging.res.mjs +130 -143
  74. package/src/Main.res +430 -51
  75. package/src/Main.res.mjs +530 -271
  76. package/src/Persistence.res +80 -84
  77. package/src/Persistence.res.mjs +131 -132
  78. package/src/PgStorage.res +294 -167
  79. package/src/PgStorage.res.mjs +799 -817
  80. package/src/Prometheus.res +50 -58
  81. package/src/Prometheus.res.mjs +345 -373
  82. package/src/ReorgDetection.res +22 -24
  83. package/src/ReorgDetection.res.mjs +100 -106
  84. package/src/SafeCheckpointTracking.res +7 -7
  85. package/src/SafeCheckpointTracking.res.mjs +40 -43
  86. package/src/SimulateItems.res +41 -49
  87. package/src/SimulateItems.res.mjs +257 -272
  88. package/src/Sink.res +2 -2
  89. package/src/Sink.res.mjs +22 -26
  90. package/src/TableIndices.res +1 -2
  91. package/src/TableIndices.res.mjs +42 -48
  92. package/src/TestIndexer.res +196 -189
  93. package/src/TestIndexer.res.mjs +536 -536
  94. package/src/TestIndexerProxyStorage.res +16 -16
  95. package/src/TestIndexerProxyStorage.res.mjs +99 -122
  96. package/src/TestIndexerWorker.res +4 -0
  97. package/src/TestIndexerWorker.res.mjs +7 -0
  98. package/src/Throttler.res +3 -3
  99. package/src/Throttler.res.mjs +23 -24
  100. package/src/Time.res +1 -1
  101. package/src/Time.res.mjs +18 -21
  102. package/src/TopicFilter.res +3 -3
  103. package/src/TopicFilter.res.mjs +29 -30
  104. package/src/UserContext.res +93 -54
  105. package/src/UserContext.res.mjs +197 -182
  106. package/src/Utils.res +141 -86
  107. package/src/Utils.res.mjs +334 -295
  108. package/src/bindings/BigDecimal.res +0 -2
  109. package/src/bindings/BigDecimal.res.mjs +19 -23
  110. package/src/bindings/ClickHouse.res +28 -27
  111. package/src/bindings/ClickHouse.res.mjs +243 -240
  112. package/src/bindings/DateFns.res +11 -11
  113. package/src/bindings/DateFns.res.mjs +7 -7
  114. package/src/bindings/EventSource.res.mjs +2 -2
  115. package/src/bindings/Express.res +2 -5
  116. package/src/bindings/Hrtime.res +2 -2
  117. package/src/bindings/Hrtime.res.mjs +30 -32
  118. package/src/bindings/Lodash.res.mjs +1 -1
  119. package/src/bindings/NodeJs.res +14 -9
  120. package/src/bindings/NodeJs.res.mjs +20 -20
  121. package/src/bindings/Pino.res +8 -10
  122. package/src/bindings/Pino.res.mjs +40 -43
  123. package/src/bindings/Postgres.res +7 -5
  124. package/src/bindings/Postgres.res.mjs +9 -9
  125. package/src/bindings/PromClient.res +17 -2
  126. package/src/bindings/PromClient.res.mjs +30 -7
  127. package/src/bindings/SDSL.res.mjs +2 -2
  128. package/src/bindings/Viem.res +4 -4
  129. package/src/bindings/Viem.res.mjs +20 -22
  130. package/src/bindings/Vitest.res +1 -1
  131. package/src/bindings/Vitest.res.mjs +2 -2
  132. package/src/bindings/WebSocket.res +1 -1
  133. package/src/db/EntityHistory.res +9 -3
  134. package/src/db/EntityHistory.res.mjs +84 -59
  135. package/src/db/InternalTable.res +62 -60
  136. package/src/db/InternalTable.res.mjs +271 -203
  137. package/src/db/Schema.res +1 -2
  138. package/src/db/Schema.res.mjs +28 -32
  139. package/src/db/Table.res +28 -27
  140. package/src/db/Table.res.mjs +276 -292
  141. package/src/sources/EventRouter.res +21 -16
  142. package/src/sources/EventRouter.res.mjs +55 -57
  143. package/src/sources/Evm.res +17 -1
  144. package/src/sources/Evm.res.mjs +16 -8
  145. package/src/sources/EvmChain.res +15 -17
  146. package/src/sources/EvmChain.res.mjs +40 -42
  147. package/src/sources/Fuel.res +14 -1
  148. package/src/sources/Fuel.res.mjs +16 -8
  149. package/src/sources/FuelSDK.res +1 -1
  150. package/src/sources/FuelSDK.res.mjs +6 -8
  151. package/src/sources/HyperFuel.res +8 -10
  152. package/src/sources/HyperFuel.res.mjs +113 -123
  153. package/src/sources/HyperFuelClient.res.mjs +6 -7
  154. package/src/sources/HyperFuelSource.res +19 -20
  155. package/src/sources/HyperFuelSource.res.mjs +339 -356
  156. package/src/sources/HyperSync.res +11 -13
  157. package/src/sources/HyperSync.res.mjs +206 -220
  158. package/src/sources/HyperSyncClient.res +5 -7
  159. package/src/sources/HyperSyncClient.res.mjs +70 -75
  160. package/src/sources/HyperSyncHeightStream.res +8 -9
  161. package/src/sources/HyperSyncHeightStream.res.mjs +78 -86
  162. package/src/sources/HyperSyncJsonApi.res +18 -15
  163. package/src/sources/HyperSyncJsonApi.res.mjs +201 -231
  164. package/src/sources/HyperSyncSource.res +17 -21
  165. package/src/sources/HyperSyncSource.res.mjs +268 -290
  166. package/src/sources/Rpc.res +5 -5
  167. package/src/sources/Rpc.res.mjs +168 -192
  168. package/src/sources/RpcSource.res +166 -167
  169. package/src/sources/RpcSource.res.mjs +972 -1046
  170. package/src/sources/RpcWebSocketHeightStream.res +10 -11
  171. package/src/sources/RpcWebSocketHeightStream.res.mjs +131 -145
  172. package/src/sources/SimulateSource.res +1 -1
  173. package/src/sources/SimulateSource.res.mjs +35 -38
  174. package/src/sources/Source.res +1 -1
  175. package/src/sources/Source.res.mjs +3 -3
  176. package/src/sources/SourceManager.res +39 -20
  177. package/src/sources/SourceManager.res.mjs +340 -371
  178. package/src/sources/SourceManager.resi +2 -1
  179. package/src/sources/Svm.res +12 -5
  180. package/src/sources/Svm.res.mjs +44 -41
  181. package/src/tui/Tui.res +23 -12
  182. package/src/tui/Tui.res.mjs +292 -290
  183. package/src/tui/bindings/Ink.res +2 -4
  184. package/src/tui/bindings/Ink.res.mjs +35 -41
  185. package/src/tui/components/BufferedProgressBar.res +7 -7
  186. package/src/tui/components/BufferedProgressBar.res.mjs +46 -46
  187. package/src/tui/components/CustomHooks.res +1 -2
  188. package/src/tui/components/CustomHooks.res.mjs +102 -122
  189. package/src/tui/components/Messages.res +1 -2
  190. package/src/tui/components/Messages.res.mjs +38 -42
  191. package/src/tui/components/SyncETA.res +10 -11
  192. package/src/tui/components/SyncETA.res.mjs +178 -196
  193. package/src/tui/components/TuiData.res +1 -1
  194. package/src/tui/components/TuiData.res.mjs +7 -6
  195. package/src/vendored/Rest.res +52 -66
  196. package/src/vendored/Rest.res.mjs +324 -364
  197. package/svm.schema.json +67 -0
  198. package/src/Address.gen.ts +0 -8
  199. package/src/Config.gen.ts +0 -19
  200. package/src/Envio.gen.ts +0 -55
  201. package/src/EvmTypes.gen.ts +0 -6
  202. package/src/InMemoryStore.gen.ts +0 -6
  203. package/src/Internal.gen.ts +0 -64
  204. package/src/PgStorage.gen.ts +0 -10
  205. package/src/PgStorage.res.d.mts +0 -5
  206. package/src/Types.ts +0 -56
  207. package/src/bindings/BigDecimal.gen.ts +0 -14
  208. package/src/bindings/BigDecimal.res.d.mts +0 -5
  209. package/src/bindings/BigInt.gen.ts +0 -10
  210. package/src/bindings/BigInt.res +0 -70
  211. package/src/bindings/BigInt.res.d.mts +0 -5
  212. package/src/bindings/BigInt.res.mjs +0 -154
  213. package/src/bindings/Ethers.res.d.mts +0 -5
  214. package/src/bindings/Pino.gen.ts +0 -17
  215. package/src/bindings/Postgres.gen.ts +0 -8
  216. package/src/bindings/Postgres.res.d.mts +0 -5
  217. package/src/bindings/Promise.res +0 -67
  218. package/src/bindings/Promise.res.mjs +0 -26
  219. package/src/db/InternalTable.gen.ts +0 -36
  220. package/src/sources/HyperSyncClient.gen.ts +0 -19
@@ -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<Internal.eventFilters>>,
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
- let eventRegistrations: Js.Dict.t<eventRegistration> = Js.Dict.empty()
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->Js.Dict.set(getKey(~contractName, ~eventName), registration)
77
+ eventRegistrations->Dict.set(getKey(~contractName, ~eventName), registration)
26
78
  }
27
79
 
28
- type registrations = {onBlockByChainId: dict<array<Internal.onBlockConfig>>}
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
- Js.Exn.raiseError(
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: Js.Dict.empty(),
110
+ onBlockByChainId: Dict.make(),
68
111
  },
69
112
  finished: false,
70
113
  }
71
114
  activeRegistration.contents = Some(r)
72
- while preRegistered->Js.Array2.length > 0 {
115
+ while preRegistered->Array.length > 0 {
73
116
  // Loop + cleanup in one go
74
- switch preRegistered->Js.Array2.pop {
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
- Js.Exn.raiseError("The indexer has not started registering handlers, so can't finish it.")
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
- let onBlockOptionsSchema = S.schema(s =>
100
- {
101
- "name": s.matches(S.string),
102
- "chain": s.matches(S.int),
103
- "interval": s.matches(S.option(S.int->S.intMin(1))->S.Option.getOr(1)),
104
- "startBlock": s.matches(S.option(S.int)),
105
- "endBlock": s.matches(S.option(S.int)),
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 onBlock = (rawOptions: unknown, handler: Internal.onBlockArgs => promise<unit>) => {
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
- Js.Exn.raiseError(
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
- switch onBlockByChainId->Utils.Dict.dangerouslyGetNonOption(chainId->Belt.Int.toString) {
132
- | None =>
133
- onBlockByChainId->Utils.Dict.setByInt(
134
- chainId,
135
- [
136
- (
137
- {
138
- index: 0,
139
- name: options["name"],
140
- startBlock: options["startBlock"],
141
- endBlock: options["endBlock"],
142
- interval: options["interval"],
143
- chainId,
144
- handler,
145
- }: Internal.onBlockConfig
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 getEventFilters = (~contractName, ~eventName) =>
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
- Js.Exn.raiseError(fullMsg)
221
+ JsError.throwWithMessage(fullMsg)
193
222
  }
194
223
 
195
- let eventFiltersMatch = (a: option<Internal.eventFilters>, b: option<Internal.eventFilters>) => {
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(Static(a)), Some(Static(b))) => a == b
199
- | (Some(Dynamic(a)), Some(Dynamic(b))) => a === b
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<Internal.eventFilters>>,
206
- incoming: option<Internal.eventOptions<Internal.eventFilters>>,
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, eventFilters)",
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, eventFilters)",
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, eventFilters)",
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
  }