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
@@ -0,0 +1,296 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+
3
+ import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
4
+ import * as S$RescriptSchema from "rescript-schema/src/S.res.mjs";
5
+ import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
6
+
7
+ function alert(message) {
8
+ if ((typeof window !== 'undefined' && window.alert)) {
9
+ return (window.alert(message));
10
+ }
11
+ }
12
+
13
+ function mixinMissingIssue(envSafe, issue) {
14
+ let missingIssues = envSafe.maybeMissingIssues;
15
+ if (missingIssues !== undefined) {
16
+ missingIssues.push(issue);
17
+ } else {
18
+ envSafe.maybeMissingIssues = [issue];
19
+ }
20
+ }
21
+
22
+ function mixinInvalidIssue(envSafe, issue) {
23
+ let invalidIssues = envSafe.maybeInvalidIssues;
24
+ if (invalidIssues !== undefined) {
25
+ invalidIssues.push(issue);
26
+ } else {
27
+ envSafe.maybeInvalidIssues = [issue];
28
+ }
29
+ }
30
+
31
+ function make(envOpt) {
32
+ let env = envOpt !== undefined ? envOpt : process.env;
33
+ return {
34
+ env: env,
35
+ isLocked: false,
36
+ maybeMissingIssues: undefined,
37
+ maybeInvalidIssues: undefined
38
+ };
39
+ }
40
+
41
+ function close(envSafe) {
42
+ if (envSafe.isLocked) {
43
+ throw new Error(`[rescript-envsafe] ` + "EnvSafe is already closed.");
44
+ }
45
+ envSafe.isLocked = true;
46
+ let match = envSafe.maybeMissingIssues;
47
+ let match$1 = envSafe.maybeInvalidIssues;
48
+ if (match === undefined && match$1 === undefined) {
49
+ return;
50
+ }
51
+ let line = "========================================";
52
+ let output = [line];
53
+ if (match$1 !== undefined) {
54
+ let invalidIssues = Primitive_option.valFromOption(match$1);
55
+ output.push("❌ Invalid environment variables:");
56
+ invalidIssues.forEach(issue => {
57
+ output.push(` ` + issue.name + `: ` + S$RescriptSchema.$$Error.message(issue.error));
58
+ });
59
+ }
60
+ if (match !== undefined) {
61
+ let missingIssues = Primitive_option.valFromOption(match);
62
+ output.push("💨 Missing environment variables:");
63
+ missingIssues.forEach(issue => {
64
+ let match = issue.input;
65
+ let tmp;
66
+ tmp = match === "" ? "Disallowed empty string" : "Missing value";
67
+ output.push(` ` + issue.name + `: ` + tmp);
68
+ });
69
+ }
70
+ output.push(line);
71
+ let text = output.join("\n");
72
+ console.error(text);
73
+ alert(text);
74
+ throw new TypeError(text);
75
+ }
76
+
77
+ function boolCoerce(string) {
78
+ switch (string) {
79
+ case "0" :
80
+ case "f" :
81
+ case "false" :
82
+ return false;
83
+ case "1" :
84
+ case "t" :
85
+ case "true" :
86
+ return true;
87
+ default:
88
+ return string;
89
+ }
90
+ }
91
+
92
+ function numberCoerce(string) {
93
+ let float = (+string);
94
+ if (Number.isNaN(float)) {
95
+ return string;
96
+ } else {
97
+ return float;
98
+ }
99
+ }
100
+
101
+ function bigintCoerce(string) {
102
+ try {
103
+ return BigInt(string);
104
+ } catch (exn) {
105
+ return string;
106
+ }
107
+ }
108
+
109
+ function jsonCoerce(string) {
110
+ try {
111
+ return JSON.parse(string);
112
+ } catch (exn) {
113
+ return string;
114
+ }
115
+ }
116
+
117
+ function get(envSafe, name, schema, allowEmptyOpt, maybeFallback, maybeDevFallback, maybeInlinedInput) {
118
+ let allowEmpty = allowEmptyOpt !== undefined ? allowEmptyOpt : false;
119
+ if (envSafe.isLocked) {
120
+ throw new Error(`[rescript-envsafe] ` + "EnvSafe is closed. Make a new one to get access to environment variables.");
121
+ }
122
+ let input = maybeInlinedInput !== undefined ? Primitive_option.valFromOption(maybeInlinedInput) : envSafe.env[name];
123
+ let isMissing = input !== undefined ? (
124
+ input === "" ? !allowEmpty : false
125
+ ) : true;
126
+ let match = schema.t;
127
+ let isOptional;
128
+ isOptional = typeof match !== "object" ? false : match.TAG === "option";
129
+ if (isMissing && !isOptional) {
130
+ if (maybeDevFallback !== undefined && envSafe.env["NODE_ENV"] !== "production") {
131
+ return Primitive_option.valFromOption(maybeDevFallback);
132
+ }
133
+ if (maybeFallback !== undefined) {
134
+ return Primitive_option.valFromOption(maybeFallback);
135
+ } else {
136
+ mixinMissingIssue(envSafe, {
137
+ name: name,
138
+ input: input
139
+ });
140
+ return undefined;
141
+ }
142
+ }
143
+ let optionalSchema = schema.t;
144
+ let tagged;
145
+ tagged = typeof optionalSchema !== "object" || optionalSchema.TAG !== "option" ? optionalSchema : optionalSchema._0.t;
146
+ let input$1;
147
+ if (input !== undefined) {
148
+ let exit = 0;
149
+ if (input === "" && !allowEmpty) {
150
+ input$1 = undefined;
151
+ } else {
152
+ exit = 1;
153
+ }
154
+ if (exit === 1) {
155
+ let tmp;
156
+ if (typeof tagged !== "object") {
157
+ switch (tagged) {
158
+ case "never" :
159
+ case "string" :
160
+ tmp = input;
161
+ break;
162
+ case "int32" :
163
+ case "number" :
164
+ tmp = numberCoerce(input);
165
+ break;
166
+ case "bigint" :
167
+ tmp = bigintCoerce(input);
168
+ break;
169
+ case "boolean" :
170
+ tmp = boolCoerce(input);
171
+ break;
172
+ default:
173
+ tmp = jsonCoerce(input);
174
+ }
175
+ } else {
176
+ switch (tagged.TAG) {
177
+ case "literal" :
178
+ switch (tagged._0.kind) {
179
+ case "String" :
180
+ tmp = input;
181
+ break;
182
+ case "Number" :
183
+ tmp = numberCoerce(input);
184
+ break;
185
+ case "Boolean" :
186
+ tmp = boolCoerce(input);
187
+ break;
188
+ case "BigInt" :
189
+ tmp = bigintCoerce(input);
190
+ break;
191
+ default:
192
+ tmp = jsonCoerce(input);
193
+ }
194
+ break;
195
+ case "union" :
196
+ tmp = input;
197
+ break;
198
+ default:
199
+ tmp = jsonCoerce(input);
200
+ }
201
+ }
202
+ input$1 = tmp;
203
+ }
204
+ } else {
205
+ input$1 = undefined;
206
+ }
207
+ let schema$1;
208
+ schema$1 = typeof tagged !== "object" || tagged.TAG !== "union" ? schema : S$RescriptSchema.preprocess(schema, s => {
209
+ let optionalSchema = s.schema.t;
210
+ let tagged;
211
+ tagged = typeof optionalSchema !== "object" || optionalSchema.TAG !== "option" ? optionalSchema : optionalSchema._0.t;
212
+ let exit = 0;
213
+ if (typeof tagged !== "object") {
214
+ switch (tagged) {
215
+ case "never" :
216
+ case "string" :
217
+ return {};
218
+ case "int32" :
219
+ case "number" :
220
+ exit = 4;
221
+ break;
222
+ case "bigint" :
223
+ exit = 3;
224
+ break;
225
+ case "boolean" :
226
+ exit = 2;
227
+ break;
228
+ default:
229
+ exit = 1;
230
+ }
231
+ } else {
232
+ switch (tagged.TAG) {
233
+ case "literal" :
234
+ switch (tagged._0.kind) {
235
+ case "String" :
236
+ return {};
237
+ case "Number" :
238
+ exit = 4;
239
+ break;
240
+ case "Boolean" :
241
+ exit = 2;
242
+ break;
243
+ case "BigInt" :
244
+ exit = 3;
245
+ break;
246
+ default:
247
+ exit = 1;
248
+ }
249
+ break;
250
+ case "union" :
251
+ return {};
252
+ default:
253
+ exit = 1;
254
+ }
255
+ }
256
+ switch (exit) {
257
+ case 1 :
258
+ return {
259
+ p: jsonCoerce
260
+ };
261
+ case 2 :
262
+ return {
263
+ p: boolCoerce
264
+ };
265
+ case 3 :
266
+ return {
267
+ p: bigintCoerce
268
+ };
269
+ case 4 :
270
+ return {
271
+ p: numberCoerce
272
+ };
273
+ }
274
+ });
275
+ try {
276
+ return S$RescriptSchema.parseOrThrow(input$1, schema$1);
277
+ } catch (raw_error) {
278
+ let error = Primitive_exceptions.internalToException(raw_error);
279
+ if (error.RE_EXN_ID === S$RescriptSchema.Raised) {
280
+ mixinInvalidIssue(envSafe, {
281
+ name: name,
282
+ error: error._1,
283
+ input: input$1
284
+ });
285
+ return undefined;
286
+ }
287
+ throw error;
288
+ }
289
+ }
290
+
291
+ export {
292
+ make,
293
+ close,
294
+ get,
295
+ }
296
+ /* S-RescriptSchema Not a pure module */
@@ -0,0 +1,18 @@
1
+ @@uncurried
2
+
3
+ type env
4
+ type t
5
+
6
+ let make: (~env: env=?) => t
7
+
8
+ let close: t => unit
9
+
10
+ let get: (
11
+ t,
12
+ string,
13
+ S.t<'value>,
14
+ ~allowEmpty: bool=?,
15
+ ~fallback: 'value=?,
16
+ ~devFallback: 'value=?,
17
+ ~input: option<string>=?,
18
+ ) => 'value
package/src/Envio.res CHANGED
@@ -2,28 +2,38 @@
2
2
  // Should be an entry point after we get rid of the generated project.
3
3
  // Don't forget to keep index.d.ts in sync with this file.
4
4
 
5
- @genType
6
- type blockEvent = {number: int}
7
-
8
- @genType
9
- type fuelBlockEvent = {height: int}
5
+ // Ecosystem-scoped argument records for `indexer.onBlock` / `indexer.onSlot`
6
+ // handlers. Mirror the TypeScript shapes in `packages/envio/index.d.ts`
7
+ // (`EvmOnBlockHandlerArgs`, `FuelOnBlockHandlerArgs`, `SvmOnSlotHandlerArgs`).
8
+ type evmOnBlockArgs<'context> = {
9
+ block: {number: int},
10
+ context: 'context,
11
+ }
10
12
 
11
- @genType
12
- type svmOnBlockArgs<'context> = {slot: int, context: 'context}
13
+ type fuelOnBlockArgs<'context> = {
14
+ block: {height: int},
15
+ context: 'context,
16
+ }
13
17
 
14
- @genType
15
- type onBlockArgs<'block, 'context> = {
16
- block: 'block,
18
+ type svmOnSlotArgs<'context> = {
19
+ slot: int,
17
20
  context: 'context,
18
21
  }
19
22
 
20
- @genType
23
+ // Internal-only type for the `indexer.onBlock` (and SVM `onSlot`) `where`
24
+ // callback argument. The canonical TypeScript shape lives in
25
+ // `packages/envio/index.d.ts`; the ReScript declaration here is free to
26
+ // diverge.
27
+ type onBlockWhereArgs<'chain> = {chain: 'chain}
28
+
29
+ // `where` returns a value interpreted at runtime by `Main.res::onBlockHandlerFn`:
30
+ // - `false` → skip this chain
31
+ // - `true` / omit → register on this chain with no extra filter
32
+ // - a filter object whose shape is ecosystem-specific (see the `Evm*` /
33
+ // `Fuel*` / `Svm*` `OnBlock`/`OnSlot` types in `packages/envio/index.d.ts`)
21
34
  type onBlockOptions<'chain> = {
22
35
  name: string,
23
- chain: 'chain,
24
- interval?: int,
25
- startBlock?: int,
26
- endBlock?: int,
36
+ where?: onBlockWhereArgs<'chain> => unknown,
27
37
  }
28
38
 
29
39
  type whereOperator<'fieldType> = {
@@ -41,7 +51,6 @@ type whereOperator<'fieldType> = {
41
51
  _in?: array<'fieldType>,
42
52
  }
43
53
 
44
- @genType.import(("./Types.ts", "Logger"))
45
54
  type logger = {
46
55
  debug: 'params. (string, ~params: {..} as 'params=?) => unit,
47
56
  info: 'params. (string, ~params: {..} as 'params=?) => unit,
@@ -51,18 +60,16 @@ type logger = {
51
60
  }
52
61
 
53
62
  @@warning("-30") // Duplicated type names (input)
54
- @genType.import(("./Types.ts", "Effect"))
55
63
  type rec effect<'input, 'output>
56
- @genType @unboxed
64
+ @unboxed
57
65
  and rateLimitDuration =
58
66
  | @as("second") Second
59
67
  | @as("minute") Minute
60
68
  | Milliseconds(int)
61
- @genType @unboxed
69
+ @unboxed
62
70
  and rateLimit =
63
71
  | @as(false) Disable
64
72
  | Enable({calls: int, per: rateLimitDuration})
65
- @genType
66
73
  and effectOptions<'input, 'output> = {
67
74
  /** The name of the effect. Used for logging and debugging. */
68
75
  name: string,
@@ -75,13 +82,11 @@ and effectOptions<'input, 'output> = {
75
82
  /** Whether the effect should be cached. */
76
83
  cache?: bool,
77
84
  }
78
- @genType.import(("./Types.ts", "EffectContext"))
79
85
  and effectContext = {
80
86
  log: logger,
81
87
  effect: 'input 'output. (effect<'input, 'output>, 'input) => promise<'output>,
82
88
  mutable cache: bool,
83
89
  }
84
- @genType
85
90
  and effectArgs<'input> = {
86
91
  input: 'input,
87
92
  context: effectContext,
@@ -138,7 +143,7 @@ let createEffect = (
138
143
  callsPerDuration: calls,
139
144
  durationMs: per->durationToMs,
140
145
  availableCalls: calls,
141
- windowStartTime: Js.Date.now(),
146
+ windowStartTime: Date.now(),
142
147
  queueCount: 0,
143
148
  nextWindowPromise: None,
144
149
  })
@@ -157,7 +162,7 @@ type fuelTransactionInput = {id?: string}
157
162
  type evmSimulateItem = {
158
163
  contract: string,
159
164
  event: string,
160
- params?: Js.Json.t,
165
+ params?: JSON.t,
161
166
  srcAddress?: Address.t,
162
167
  logIndex?: int,
163
168
  block?: Internal.evmBlockInput,
@@ -167,13 +172,19 @@ type evmSimulateItem = {
167
172
  type fuelSimulateItem = {
168
173
  contract: string,
169
174
  event: string,
170
- params: Js.Json.t,
175
+ params: JSON.t,
171
176
  srcAddress?: Address.t,
172
177
  logIndex?: int,
173
178
  block?: fuelBlockInput,
174
179
  transaction?: fuelTransactionInput,
175
180
  }
176
181
 
182
+ // Read at call time, not as a module-level binding. `Bin.res::applyEnv`
183
+ // populates `process.env.ENVIO_DEV_MODE` *after* the JS bundle has loaded,
184
+ // so a top-level `envSafe->EnvSafe.get(...)` in Env.res would always
185
+ // snapshot the pre-applyEnv value (undefined → false).
186
+ let isDevMode = () => NodeJs.Process.process.env->Dict.get("ENVIO_DEV_MODE") === Some("true")
187
+
177
188
  module TestHelpers = {
178
189
  module Addresses = {
179
190
  let mockAddresses =
@@ -199,6 +210,6 @@ module TestHelpers = {
199
210
  "0xdD2FD4581271e230360230F9337D5c0430Bf44C0",
200
211
  "0x8626f6940E2eb28930eFb4CeF49B2d1F2C9C1199",
201
212
  ]->Belt.Array.map(Address.Evm.fromStringOrThrow)
202
- let defaultAddress = mockAddresses[0]
213
+ let defaultAddress = mockAddresses->Belt.Array.getUnsafe(0)
203
214
  }
204
215
  }
package/src/Envio.res.mjs CHANGED
@@ -1,9 +1,9 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
2
 
3
3
  import * as Address from "./Address.res.mjs";
4
+ import * as Process from "process";
4
5
  import * as Internal from "./Internal.res.mjs";
5
- import * as Belt_Array from "rescript/lib/es6/belt_Array.js";
6
- import * as Caml_array from "rescript/lib/es6/caml_array.js";
6
+ import * as Belt_Array from "@rescript/runtime/lib/es6/Belt_Array.js";
7
7
  import * as S$RescriptSchema from "rescript-schema/src/S.res.mjs";
8
8
 
9
9
  function durationToMs(duration) {
@@ -19,22 +19,18 @@ function durationToMs(duration) {
19
19
  }
20
20
 
21
21
  function createEffect(options, handler) {
22
- var outputSchema = S$RescriptSchema.schema(function (param) {
23
- return options.output;
24
- });
25
- var itemSchema = S$RescriptSchema.schema(function (s) {
26
- return {
27
- id: s.m(S$RescriptSchema.string),
28
- output: s.m(outputSchema)
29
- };
30
- });
31
- var match = options.cache;
32
- var match$1 = options.rateLimit;
33
- var tmp;
34
- if (typeof match$1 !== "object") {
22
+ let outputSchema = S$RescriptSchema.schema(param => options.output);
23
+ let itemSchema = S$RescriptSchema.schema(s => ({
24
+ id: s.m(S$RescriptSchema.string),
25
+ output: s.m(outputSchema)
26
+ }));
27
+ let match = options.cache;
28
+ let match$1 = options.rateLimit;
29
+ let tmp;
30
+ if (match$1 === false) {
35
31
  tmp = undefined;
36
32
  } else {
37
- var calls = match$1.calls;
33
+ let calls = match$1.calls;
38
34
  tmp = {
39
35
  callsPerDuration: calls,
40
36
  durationMs: durationToMs(match$1.per),
@@ -45,61 +41,64 @@ function createEffect(options, handler) {
45
41
  };
46
42
  }
47
43
  return {
48
- name: options.name,
49
- handler: handler,
50
- storageMeta: {
51
- itemSchema: itemSchema,
52
- outputSchema: outputSchema,
53
- table: Internal.makeCacheTable(options.name)
54
- },
55
- defaultShouldCache: match !== undefined && match ? true : false,
56
- output: outputSchema,
57
- input: S$RescriptSchema.schema(function (param) {
58
- return options.input;
59
- }),
60
- activeCallsCount: 0,
61
- prevCallStartTimerRef: null,
62
- rateLimit: tmp
63
- };
44
+ name: options.name,
45
+ handler: handler,
46
+ storageMeta: {
47
+ itemSchema: itemSchema,
48
+ outputSchema: outputSchema,
49
+ table: Internal.makeCacheTable(options.name)
50
+ },
51
+ defaultShouldCache: match !== undefined ? match : false,
52
+ output: outputSchema,
53
+ input: S$RescriptSchema.schema(param => options.input),
54
+ activeCallsCount: 0,
55
+ prevCallStartTimerRef: null,
56
+ rateLimit: tmp
57
+ };
64
58
  }
65
59
 
66
- var mockAddresses = Belt_Array.map([
67
- "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
68
- "0x70997970C51812dc3A010C7d01b50e0d17dc79C8",
69
- "0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC",
70
- "0x90F79bf6EB2c4f870365E785982E1f101E93b906",
71
- "0x15d34AAf54267DB7D7c367839AAf71A00a2C6A65",
72
- "0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc",
73
- "0x976EA74026E726554dB657fA54763abd0C3a0aa9",
74
- "0x14dC79964da2C08b23698B3D3cc7Ca32193d9955",
75
- "0x23618e81E3f5cdF7f54C3d65f7FBc0aBf5B21E8f",
76
- "0xa0Ee7A142d267C1f36714E4a8F75612F20a79720",
77
- "0xBcd4042DE499D14e55001CcbB24a551F3b954096",
78
- "0x71bE63f3384f5fb98995898A86B02Fb2426c5788",
79
- "0xFABB0ac9d68B0B445fB7357272Ff202C5651694a",
80
- "0x1CBd3b2770909D4e10f157cABC84C7264073C9Ec",
81
- "0xdF3e18d64BC6A983f673Ab319CCaE4f1a57C7097",
82
- "0xcd3B766CCDd6AE721141F452C550Ca635964ce71",
83
- "0x2546BcD3c84621e976D8185a91A922aE77ECEc30",
84
- "0xbDA5747bFD65F08deb54cb465eB87D40e51B197E",
85
- "0xdD2FD4581271e230360230F9337D5c0430Bf44C0",
86
- "0x8626f6940E2eb28930eFb4CeF49B2d1F2C9C1199"
87
- ], Address.Evm.fromStringOrThrow);
60
+ function isDevMode() {
61
+ return Process.env["ENVIO_DEV_MODE"] === "true";
62
+ }
63
+
64
+ let mockAddresses = Belt_Array.map([
65
+ "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
66
+ "0x70997970C51812dc3A010C7d01b50e0d17dc79C8",
67
+ "0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC",
68
+ "0x90F79bf6EB2c4f870365E785982E1f101E93b906",
69
+ "0x15d34AAf54267DB7D7c367839AAf71A00a2C6A65",
70
+ "0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc",
71
+ "0x976EA74026E726554dB657fA54763abd0C3a0aa9",
72
+ "0x14dC79964da2C08b23698B3D3cc7Ca32193d9955",
73
+ "0x23618e81E3f5cdF7f54C3d65f7FBc0aBf5B21E8f",
74
+ "0xa0Ee7A142d267C1f36714E4a8F75612F20a79720",
75
+ "0xBcd4042DE499D14e55001CcbB24a551F3b954096",
76
+ "0x71bE63f3384f5fb98995898A86B02Fb2426c5788",
77
+ "0xFABB0ac9d68B0B445fB7357272Ff202C5651694a",
78
+ "0x1CBd3b2770909D4e10f157cABC84C7264073C9Ec",
79
+ "0xdF3e18d64BC6A983f673Ab319CCaE4f1a57C7097",
80
+ "0xcd3B766CCDd6AE721141F452C550Ca635964ce71",
81
+ "0x2546BcD3c84621e976D8185a91A922aE77ECEc30",
82
+ "0xbDA5747bFD65F08deb54cb465eB87D40e51B197E",
83
+ "0xdD2FD4581271e230360230F9337D5c0430Bf44C0",
84
+ "0x8626f6940E2eb28930eFb4CeF49B2d1F2C9C1199"
85
+ ], Address.Evm.fromStringOrThrow);
88
86
 
89
- var defaultAddress = Caml_array.get(mockAddresses, 0);
87
+ let defaultAddress = mockAddresses[0];
90
88
 
91
- var Addresses = {
89
+ let Addresses = {
92
90
  mockAddresses: mockAddresses,
93
91
  defaultAddress: defaultAddress
94
92
  };
95
93
 
96
- var TestHelpers = {
94
+ let TestHelpers = {
97
95
  Addresses: Addresses
98
96
  };
99
97
 
100
98
  export {
101
- durationToMs ,
102
- createEffect ,
103
- TestHelpers ,
99
+ durationToMs,
100
+ createEffect,
101
+ isDevMode,
102
+ TestHelpers,
104
103
  }
105
104
  /* mockAddresses Not a pure module */
@@ -12,13 +12,13 @@ let log = (self: t) => {
12
12
  }
13
13
 
14
14
  let raiseExn = (self: t) => {
15
- self.exn->Utils.prettifyExn->raise
15
+ self.exn->Utils.prettifyExn->throw
16
16
  }
17
17
 
18
18
  let mkLogAndRaise = (~logger=?, ~msg=?, exn) => {
19
19
  let exn = exn->Utils.prettifyExn
20
20
  exn->make(~logger?, ~msg?)->log
21
- exn->raise
21
+ exn->throw
22
22
  }
23
23
 
24
24
  let unwrapLogAndRaise = (~logger=?, ~msg=?, result) => {
@@ -4,18 +4,18 @@ import * as Utils from "./Utils.res.mjs";
4
4
  import * as Logging from "./Logging.res.mjs";
5
5
 
6
6
  function make(exn, loggerOpt, msg) {
7
- var logger = loggerOpt !== undefined ? loggerOpt : Logging.getLogger();
7
+ let logger = loggerOpt !== undefined ? loggerOpt : Logging.getLogger();
8
8
  return {
9
- logger: logger,
10
- exn: exn,
11
- msg: msg
12
- };
9
+ logger: logger,
10
+ exn: exn,
11
+ msg: msg
12
+ };
13
13
  }
14
14
 
15
15
  function log(self) {
16
- var msg = self.msg;
17
- var exn = self.exn;
18
- var logger = self.logger;
16
+ let msg = self.msg;
17
+ let exn = self.exn;
18
+ let logger = self.logger;
19
19
  if (msg !== undefined) {
20
20
  return Logging.childErrorWithExn(logger, Utils.prettifyExn(exn), msg);
21
21
  } else {
@@ -28,7 +28,7 @@ function raiseExn(self) {
28
28
  }
29
29
 
30
30
  function mkLogAndRaise(logger, msg, exn) {
31
- var exn$1 = Utils.prettifyExn(exn);
31
+ let exn$1 = Utils.prettifyExn(exn);
32
32
  log(make(exn$1, logger, msg));
33
33
  throw exn$1;
34
34
  }
@@ -47,11 +47,11 @@ function logAndRaise(self) {
47
47
  }
48
48
 
49
49
  export {
50
- make ,
51
- log ,
52
- raiseExn ,
53
- mkLogAndRaise ,
54
- unwrapLogAndRaise ,
55
- logAndRaise ,
50
+ make,
51
+ log,
52
+ raiseExn,
53
+ mkLogAndRaise,
54
+ unwrapLogAndRaise,
55
+ logAndRaise,
56
56
  }
57
57
  /* Utils Not a pure module */