envio 3.0.0-alpha.21 → 3.0.0-alpha.22

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 (219) hide show
  1. package/bin.mjs +2 -48
  2. package/evm.schema.json +67 -0
  3. package/fuel.schema.json +67 -0
  4. package/index.d.ts +822 -38
  5. package/index.js +5 -3
  6. package/package.json +10 -8
  7. package/rescript.json +5 -9
  8. package/src/Address.res +4 -5
  9. package/src/Address.res.mjs +9 -12
  10. package/src/Api.res +15 -0
  11. package/src/Api.res.mjs +20 -0
  12. package/src/Batch.res +32 -34
  13. package/src/Batch.res.mjs +172 -187
  14. package/src/Bin.res +89 -0
  15. package/src/Bin.res.mjs +97 -0
  16. package/src/ChainFetcher.res +33 -57
  17. package/src/ChainFetcher.res.mjs +197 -227
  18. package/src/ChainManager.res +6 -14
  19. package/src/ChainManager.res.mjs +74 -85
  20. package/src/ChainMap.res +14 -16
  21. package/src/ChainMap.res.mjs +38 -38
  22. package/src/Config.res +193 -135
  23. package/src/Config.res.mjs +566 -592
  24. package/src/Core.res +182 -0
  25. package/src/Core.res.mjs +207 -0
  26. package/src/Ecosystem.res +25 -4
  27. package/src/Ecosystem.res.mjs +12 -13
  28. package/src/Env.res +20 -13
  29. package/src/Env.res.mjs +124 -113
  30. package/src/EnvSafe.res +269 -0
  31. package/src/EnvSafe.res.mjs +296 -0
  32. package/src/EnvSafe.resi +18 -0
  33. package/src/Envio.res +37 -26
  34. package/src/Envio.res.mjs +59 -60
  35. package/src/ErrorHandling.res +2 -2
  36. package/src/ErrorHandling.res.mjs +15 -15
  37. package/src/EventConfigBuilder.res +219 -81
  38. package/src/EventConfigBuilder.res.mjs +259 -202
  39. package/src/EventProcessing.res +27 -38
  40. package/src/EventProcessing.res.mjs +165 -183
  41. package/src/EventUtils.res +11 -11
  42. package/src/EventUtils.res.mjs +21 -22
  43. package/src/EvmTypes.res +0 -1
  44. package/src/EvmTypes.res.mjs +5 -5
  45. package/src/FetchState.res +360 -256
  46. package/src/FetchState.res.mjs +958 -914
  47. package/src/GlobalState.res +365 -351
  48. package/src/GlobalState.res.mjs +958 -992
  49. package/src/GlobalStateManager.res +1 -2
  50. package/src/GlobalStateManager.res.mjs +36 -44
  51. package/src/HandlerLoader.res +107 -23
  52. package/src/HandlerLoader.res.mjs +128 -38
  53. package/src/HandlerRegister.res +127 -103
  54. package/src/HandlerRegister.res.mjs +164 -164
  55. package/src/HandlerRegister.resi +12 -4
  56. package/src/Hasura.res +35 -22
  57. package/src/Hasura.res.mjs +158 -167
  58. package/src/InMemoryStore.res +20 -27
  59. package/src/InMemoryStore.res.mjs +64 -80
  60. package/src/InMemoryTable.res +34 -39
  61. package/src/InMemoryTable.res.mjs +165 -170
  62. package/src/Internal.res +52 -33
  63. package/src/Internal.res.mjs +84 -81
  64. package/src/LazyLoader.res.mjs +55 -61
  65. package/src/LoadLayer.res +77 -78
  66. package/src/LoadLayer.res.mjs +160 -189
  67. package/src/LoadManager.res +16 -21
  68. package/src/LoadManager.res.mjs +79 -84
  69. package/src/LogSelection.res +236 -68
  70. package/src/LogSelection.res.mjs +211 -141
  71. package/src/Logging.res +13 -9
  72. package/src/Logging.res.mjs +130 -143
  73. package/src/Main.res +428 -51
  74. package/src/Main.res.mjs +528 -271
  75. package/src/Persistence.res +77 -84
  76. package/src/Persistence.res.mjs +131 -132
  77. package/src/PgStorage.res +291 -167
  78. package/src/PgStorage.res.mjs +797 -817
  79. package/src/Prometheus.res +50 -58
  80. package/src/Prometheus.res.mjs +345 -373
  81. package/src/ReorgDetection.res +22 -24
  82. package/src/ReorgDetection.res.mjs +100 -106
  83. package/src/SafeCheckpointTracking.res +7 -7
  84. package/src/SafeCheckpointTracking.res.mjs +40 -43
  85. package/src/SimulateItems.res +41 -49
  86. package/src/SimulateItems.res.mjs +257 -272
  87. package/src/Sink.res +2 -2
  88. package/src/Sink.res.mjs +22 -26
  89. package/src/TableIndices.res +1 -2
  90. package/src/TableIndices.res.mjs +42 -48
  91. package/src/TestIndexer.res +196 -189
  92. package/src/TestIndexer.res.mjs +536 -536
  93. package/src/TestIndexerProxyStorage.res +15 -16
  94. package/src/TestIndexerProxyStorage.res.mjs +98 -122
  95. package/src/TestIndexerWorker.res +4 -0
  96. package/src/TestIndexerWorker.res.mjs +7 -0
  97. package/src/Throttler.res +3 -3
  98. package/src/Throttler.res.mjs +23 -24
  99. package/src/Time.res +1 -1
  100. package/src/Time.res.mjs +18 -21
  101. package/src/TopicFilter.res +3 -3
  102. package/src/TopicFilter.res.mjs +29 -30
  103. package/src/UserContext.res +93 -54
  104. package/src/UserContext.res.mjs +197 -182
  105. package/src/Utils.res +141 -86
  106. package/src/Utils.res.mjs +334 -295
  107. package/src/bindings/BigDecimal.res +0 -2
  108. package/src/bindings/BigDecimal.res.mjs +19 -23
  109. package/src/bindings/ClickHouse.res +28 -27
  110. package/src/bindings/ClickHouse.res.mjs +243 -240
  111. package/src/bindings/DateFns.res +11 -11
  112. package/src/bindings/DateFns.res.mjs +7 -7
  113. package/src/bindings/EventSource.res.mjs +2 -2
  114. package/src/bindings/Express.res +2 -5
  115. package/src/bindings/Hrtime.res +2 -2
  116. package/src/bindings/Hrtime.res.mjs +30 -32
  117. package/src/bindings/Lodash.res.mjs +1 -1
  118. package/src/bindings/NodeJs.res +14 -9
  119. package/src/bindings/NodeJs.res.mjs +20 -20
  120. package/src/bindings/Pino.res +8 -10
  121. package/src/bindings/Pino.res.mjs +40 -43
  122. package/src/bindings/Postgres.res +2 -5
  123. package/src/bindings/Postgres.res.mjs +9 -9
  124. package/src/bindings/PromClient.res +17 -2
  125. package/src/bindings/PromClient.res.mjs +30 -7
  126. package/src/bindings/SDSL.res.mjs +2 -2
  127. package/src/bindings/Viem.res +4 -4
  128. package/src/bindings/Viem.res.mjs +20 -22
  129. package/src/bindings/Vitest.res +1 -1
  130. package/src/bindings/Vitest.res.mjs +2 -2
  131. package/src/bindings/WebSocket.res +1 -1
  132. package/src/db/EntityHistory.res +9 -3
  133. package/src/db/EntityHistory.res.mjs +84 -59
  134. package/src/db/InternalTable.res +62 -60
  135. package/src/db/InternalTable.res.mjs +271 -203
  136. package/src/db/Schema.res +1 -2
  137. package/src/db/Schema.res.mjs +28 -32
  138. package/src/db/Table.res +28 -27
  139. package/src/db/Table.res.mjs +276 -292
  140. package/src/sources/EventRouter.res +21 -16
  141. package/src/sources/EventRouter.res.mjs +55 -57
  142. package/src/sources/Evm.res +17 -1
  143. package/src/sources/Evm.res.mjs +16 -8
  144. package/src/sources/EvmChain.res +15 -17
  145. package/src/sources/EvmChain.res.mjs +40 -42
  146. package/src/sources/Fuel.res +14 -1
  147. package/src/sources/Fuel.res.mjs +16 -8
  148. package/src/sources/FuelSDK.res +1 -1
  149. package/src/sources/FuelSDK.res.mjs +6 -8
  150. package/src/sources/HyperFuel.res +8 -10
  151. package/src/sources/HyperFuel.res.mjs +113 -123
  152. package/src/sources/HyperFuelClient.res.mjs +6 -7
  153. package/src/sources/HyperFuelSource.res +19 -20
  154. package/src/sources/HyperFuelSource.res.mjs +339 -356
  155. package/src/sources/HyperSync.res +11 -13
  156. package/src/sources/HyperSync.res.mjs +206 -220
  157. package/src/sources/HyperSyncClient.res +5 -7
  158. package/src/sources/HyperSyncClient.res.mjs +70 -75
  159. package/src/sources/HyperSyncHeightStream.res +8 -9
  160. package/src/sources/HyperSyncHeightStream.res.mjs +78 -86
  161. package/src/sources/HyperSyncJsonApi.res +18 -15
  162. package/src/sources/HyperSyncJsonApi.res.mjs +201 -231
  163. package/src/sources/HyperSyncSource.res +17 -21
  164. package/src/sources/HyperSyncSource.res.mjs +268 -290
  165. package/src/sources/Rpc.res +5 -5
  166. package/src/sources/Rpc.res.mjs +168 -192
  167. package/src/sources/RpcSource.res +166 -167
  168. package/src/sources/RpcSource.res.mjs +972 -1046
  169. package/src/sources/RpcWebSocketHeightStream.res +10 -11
  170. package/src/sources/RpcWebSocketHeightStream.res.mjs +131 -145
  171. package/src/sources/SimulateSource.res +1 -1
  172. package/src/sources/SimulateSource.res.mjs +35 -38
  173. package/src/sources/Source.res +1 -1
  174. package/src/sources/Source.res.mjs +3 -3
  175. package/src/sources/SourceManager.res +39 -20
  176. package/src/sources/SourceManager.res.mjs +340 -371
  177. package/src/sources/SourceManager.resi +2 -1
  178. package/src/sources/Svm.res +12 -5
  179. package/src/sources/Svm.res.mjs +44 -41
  180. package/src/tui/Tui.res +23 -12
  181. package/src/tui/Tui.res.mjs +292 -290
  182. package/src/tui/bindings/Ink.res +2 -4
  183. package/src/tui/bindings/Ink.res.mjs +35 -41
  184. package/src/tui/components/BufferedProgressBar.res +7 -7
  185. package/src/tui/components/BufferedProgressBar.res.mjs +46 -46
  186. package/src/tui/components/CustomHooks.res +1 -2
  187. package/src/tui/components/CustomHooks.res.mjs +102 -122
  188. package/src/tui/components/Messages.res +1 -2
  189. package/src/tui/components/Messages.res.mjs +38 -42
  190. package/src/tui/components/SyncETA.res +10 -11
  191. package/src/tui/components/SyncETA.res.mjs +178 -196
  192. package/src/tui/components/TuiData.res +1 -1
  193. package/src/tui/components/TuiData.res.mjs +7 -6
  194. package/src/vendored/Rest.res +52 -66
  195. package/src/vendored/Rest.res.mjs +324 -364
  196. package/svm.schema.json +67 -0
  197. package/src/Address.gen.ts +0 -8
  198. package/src/Config.gen.ts +0 -19
  199. package/src/Envio.gen.ts +0 -55
  200. package/src/EvmTypes.gen.ts +0 -6
  201. package/src/InMemoryStore.gen.ts +0 -6
  202. package/src/Internal.gen.ts +0 -64
  203. package/src/PgStorage.gen.ts +0 -10
  204. package/src/PgStorage.res.d.mts +0 -5
  205. package/src/Types.ts +0 -56
  206. package/src/bindings/BigDecimal.gen.ts +0 -14
  207. package/src/bindings/BigDecimal.res.d.mts +0 -5
  208. package/src/bindings/BigInt.gen.ts +0 -10
  209. package/src/bindings/BigInt.res +0 -70
  210. package/src/bindings/BigInt.res.d.mts +0 -5
  211. package/src/bindings/BigInt.res.mjs +0 -154
  212. package/src/bindings/Ethers.res.d.mts +0 -5
  213. package/src/bindings/Pino.gen.ts +0 -17
  214. package/src/bindings/Postgres.gen.ts +0 -8
  215. package/src/bindings/Postgres.res.d.mts +0 -5
  216. package/src/bindings/Promise.res +0 -67
  217. package/src/bindings/Promise.res.mjs +0 -26
  218. package/src/db/InternalTable.gen.ts +0 -36
  219. package/src/sources/HyperSyncClient.gen.ts +0 -19
package/src/Utils.res CHANGED
@@ -10,12 +10,12 @@ external importPathWithJson: (
10
10
  string,
11
11
  @as(json`{with: {type: "json"}}`) _,
12
12
  ) => promise<{
13
- "default": Js.Json.t,
13
+ "default": JSON.t,
14
14
  }> = "import"
15
15
 
16
16
  let delay = milliseconds =>
17
- Js.Promise2.make((~resolve, ~reject as _) => {
18
- let _interval = Js.Global.setTimeout(_ => {
17
+ Promise.make((resolve, _) => {
18
+ let _interval = setTimeout(_ => {
19
19
  resolve()
20
20
  }, milliseconds)
21
21
  })
@@ -77,55 +77,51 @@ module Option = {
77
77
 
78
78
  let getExn = (opt, message) => {
79
79
  switch opt {
80
- | None => Js.Exn.raiseError(message)
80
+ | None => JsError.throwWithMessage(message)
81
81
  | Some(v) => v
82
82
  }
83
83
  }
84
84
  }
85
85
 
86
- module Tuple = {
87
- /**Access a tuple value by its index*/
88
- @warning("-27")
89
- let get = (tuple: 'a, index: int): option<'b> => %raw(`tuple[index]`)
90
- }
91
-
92
86
  module Dict = {
93
- @get_index
87
+ include Dict
88
+
94
89
  /**
95
90
  It's the same as `Js.Dict.get` but it doesn't have runtime overhead to check if the key exists.
96
91
  */
92
+ @get_index
97
93
  external dangerouslyGetNonOption: (dict<'a>, string) => option<'a> = ""
98
94
 
99
95
  let getOrInsertEmptyDict = (dict, key) => {
100
96
  switch dict->dangerouslyGetNonOption(key) {
101
97
  | Some(d) => d
102
98
  | None => {
103
- let d = Js.Dict.empty()
104
- dict->Js.Dict.set(key, d)
99
+ let d = Dict.make()
100
+ dict->Dict.set(key, d)
105
101
  d
106
102
  }
107
103
  }
108
104
  }
109
105
 
110
- @get_index
111
106
  /**
112
107
  It's the same as `Js.Dict.get` but it doesn't have runtime overhead to check if the key exists.
113
108
  */
109
+ @get_index
114
110
  external dangerouslyGetByIntNonOption: (dict<'a>, int) => option<'a> = ""
115
111
 
116
112
  let has: (dict<'a>, string) => bool = %raw(`(dict, key) => key in dict`)
117
113
 
118
114
  let push = (dict, key, value) => {
119
115
  switch dict->dangerouslyGetNonOption(key) {
120
- | Some(arr) => arr->Js.Array2.push(value)->ignore
121
- | None => dict->Js.Dict.set(key, [value])
116
+ | Some(arr) => arr->Array.push(value)
117
+ | None => dict->Dict.set(key, [value])
122
118
  }
123
119
  }
124
120
 
125
121
  let pushMany = (dict, key, values) => {
126
122
  switch dict->dangerouslyGetNonOption(key) {
127
- | Some(arr) => arr->Js.Array2.pushMany(values)->ignore
128
- | None => dict->Js.Dict.set(key, values)
123
+ | Some(arr) => arr->Array.pushMany(values)
124
+ | None => dict->Dict.set(key, values)
129
125
  }
130
126
  }
131
127
 
@@ -247,6 +243,8 @@ module UnsafeIntOperators = {
247
243
  type asyncIterator<'a>
248
244
 
249
245
  module Array = {
246
+ include Array
247
+
250
248
  let immutableEmpty: array<unknown> = []
251
249
 
252
250
  @send
@@ -266,18 +264,18 @@ module Array = {
266
264
 
267
265
  let rec loop = (i, j, k) => {
268
266
  if i < Array.length(xs) && j < Array.length(ys) {
269
- if f(xs[i], ys[j]) {
270
- result[k] = xs[i]
267
+ if f(xs->Belt.Array.getUnsafe(i), ys->Belt.Array.getUnsafe(j)) {
268
+ result->Belt.Array.setUnsafe(k, xs->Belt.Array.getUnsafe(i))
271
269
  loop(i + 1, j, k + 1)
272
270
  } else {
273
- result[k] = ys[j]
271
+ result->Belt.Array.setUnsafe(k, ys->Belt.Array.getUnsafe(j))
274
272
  loop(i, j + 1, k + 1)
275
273
  }
276
274
  } else if i < Array.length(xs) {
277
- result[k] = xs[i]
275
+ result->Belt.Array.setUnsafe(k, xs->Belt.Array.getUnsafe(i))
278
276
  loop(i + 1, j, k + 1)
279
277
  } else if j < Array.length(ys) {
280
- result[k] = ys[j]
278
+ result->Belt.Array.setUnsafe(k, ys->Belt.Array.getUnsafe(j))
281
279
  loop(i, j + 1, k + 1)
282
280
  }
283
281
  }
@@ -296,7 +294,7 @@ module Array = {
296
294
  */
297
295
  let setIndexImmutable = (arr: array<'a>, index: int, value: 'a): array<'a> => {
298
296
  let shallowCopy = arr->Belt.Array.copy
299
- shallowCopy->Js.Array2.unsafe_set(index, value)
297
+ shallowCopy->Array.setUnsafe(index, value)
300
298
  shallowCopy
301
299
  }
302
300
 
@@ -305,9 +303,9 @@ module Array = {
305
303
  if index >= Array.length(results) {
306
304
  Ok(output)
307
305
  } else {
308
- switch results->Js.Array2.unsafe_get(index) {
306
+ switch results->Array.getUnsafe(index) {
309
307
  | Ok(value) => {
310
- output[index] = value
308
+ output->Belt.Array.setUnsafe(index, value)
311
309
  loop(index + 1, output)
312
310
  }
313
311
  | Error(_) as err => err->(magic: result<'a, 'b> => result<array<'a>, 'b>)
@@ -315,14 +313,14 @@ module Array = {
315
313
  }
316
314
  }
317
315
 
318
- loop(0, Belt.Array.makeUninitializedUnsafe(results->Js.Array2.length))
316
+ loop(0, Belt.Array.makeUninitializedUnsafe(results->Array.length))
319
317
  }
320
318
 
321
319
  /**
322
320
  Helper to check if a value exists in an array
323
321
  */
324
322
  let includes = (arr: array<'a>, val: 'a) =>
325
- arr->Js.Array2.find(item => item == val)->Belt.Option.isSome
323
+ arr->Array.find(item => item == val)->Belt.Option.isSome
326
324
 
327
325
  let isEmpty = (arr: array<_>) =>
328
326
  switch arr {
@@ -338,7 +336,7 @@ Helper to check if a value exists in an array
338
336
 
339
337
  let awaitEach = async (arr: array<'a>, fn: 'a => promise<unit>) => {
340
338
  for i in 0 to arr->Array.length - 1 {
341
- let item = arr[i]
339
+ let item = arr->Belt.Array.getUnsafe(i)
342
340
  await item->fn
343
341
  }
344
342
  }
@@ -352,9 +350,7 @@ Helper to check if a value exists in an array
352
350
  if index < 0 {
353
351
  array->Array.copy
354
352
  } else {
355
- array
356
- ->Js.Array2.slice(~start=0, ~end_=index)
357
- ->Js.Array2.concat(array->Js.Array2.sliceFrom(index + 1))
353
+ array->Array.slice(~start=0, ~end=index)->Array.concat(array->Array.slice(~start=index + 1))
358
354
  }
359
355
  }
360
356
 
@@ -362,14 +358,14 @@ Helper to check if a value exists in an array
362
358
  let first = (arr: array<'a>): option<'a> => arr->Belt.Array.get(0)
363
359
 
364
360
  let lastUnsafe = (arr: array<'a>): 'a => arr->Belt.Array.getUnsafe(arr->Array.length - 1)
365
- let firstUnsafe = (arr: array<'a>): 'a => arr->Js.Array2.unsafe_get(0)
361
+ let firstUnsafe = (arr: array<'a>): 'a => arr->Array.getUnsafe(0)
366
362
 
367
363
  let findReverseWithIndex = (arr: array<'a>, fn: 'a => bool): option<('a, int)> => {
368
364
  let rec loop = (index: int) => {
369
365
  if index < 0 {
370
366
  None
371
367
  } else {
372
- let item = arr[index]
368
+ let item = arr->Belt.Array.getUnsafe(index)
373
369
  if fn(item) {
374
370
  Some((item, index))
375
371
  } else {
@@ -380,13 +376,6 @@ Helper to check if a value exists in an array
380
376
  loop(arr->Array.length - 1)
381
377
  }
382
378
 
383
- /**
384
- Currently a bug in rescript if you ignore the return value of spliceInPlace
385
- https://github.com/rescript-lang/rescript-compiler/issues/6991
386
- */
387
- @send
388
- external spliceInPlace: (array<'a>, ~pos: int, ~remove: int) => array<'a> = "splice"
389
-
390
379
  /**
391
380
  Interleaves an array with a separator
392
381
 
@@ -394,10 +383,10 @@ Helper to check if a value exists in an array
394
383
  */
395
384
  let interleave = (arr: array<'a>, separator: 'a) => {
396
385
  let interleaved = []
397
- arr->Js.Array2.forEachi((v, i) => {
398
- interleaved->Js.Array2.push(v)->ignore
386
+ arr->Array.forEachWithIndex((v, i) => {
387
+ interleaved->Array.push(v)
399
388
  if i < arr->Array.length - 1 {
400
- interleaved->Js.Array2.push(separator)->ignore
389
+ interleaved->Array.push(separator)
401
390
  }
402
391
  })
403
392
  interleaved
@@ -426,9 +415,10 @@ Helper to check if a value exists in an array
426
415
  }
427
416
 
428
417
  module String = {
418
+ include String
419
+
429
420
  let capitalize = str => {
430
- str->Js.String2.slice(~from=0, ~to_=1)->Js.String.toUpperCase ++
431
- str->Js.String2.sliceToEnd(~from=1)
421
+ str->String.slice(~start=0, ~end=1)->String.toUpperCase ++ str->String.slice(~start=1)
432
422
  }
433
423
 
434
424
  /**
@@ -459,12 +449,12 @@ module Url = {
459
449
  // - (https?:\/\/) : Required http:// or https:// (capturing group)
460
450
  // - ([^\/?]+) : Capture hostname (one or more characters that aren't / or ?)
461
451
  // - .* : Match rest of the string
462
- let regex = %re("/https?:\/\/([^\/?]+).*/")
463
- switch Js.Re.exec_(regex, url) {
452
+ let regex = /https?:\/\/([^\/?]+).*/
453
+ switch RegExp.exec(regex, url) {
464
454
  | Some(result) =>
465
- switch Js.Re.captures(result)->Belt.Array.get(1) {
466
- | Some(host) => host->Js.Nullable.toOption
467
- | None => None
455
+ switch RegExp.Result.matches(result)->Belt.Array.get(0) {
456
+ | Some(Some(host)) => Some(host)
457
+ | Some(None) | None => None
468
458
  }
469
459
  | None => None
470
460
  }
@@ -490,7 +480,7 @@ bet the actual underlying exn
490
480
  let unwrapResultExn = res =>
491
481
  switch res {
492
482
  | Ok(v) => v
493
- | Error(exn) => exn->raise
483
+ | Error(exn) => exn->throw
494
484
  }
495
485
 
496
486
  external queueMicrotask: (unit => unit) => unit = "queueMicrotask"
@@ -502,14 +492,14 @@ module Schema = {
502
492
  // In a nutshell, this is completely unsafe.
503
493
  let dbDate =
504
494
  S.json(~validate=false)
505
- ->(magic: S.t<Js.Json.t> => S.t<Js.Date.t>)
506
- ->S.preprocess(_ => {serializer: date => date->magic->Js.Date.toISOString})
495
+ ->(magic: S.t<JSON.t> => S.t<Date.t>)
496
+ ->S.preprocess(_ => {serializer: date => date->magic->Date.toISOString})
507
497
 
508
498
  // ClickHouse expects timestamps as numbers (milliseconds), not ISO strings
509
499
  let clickHouseDate =
510
500
  S.json(~validate=false)
511
- ->(magic: S.t<Js.Json.t> => S.t<Js.Date.t>)
512
- ->S.preprocess(_ => {serializer: date => date->magic->Js.Date.getTime})
501
+ ->(magic: S.t<JSON.t> => S.t<Date.t>)
502
+ ->S.preprocess(_ => {serializer: date => date->magic->Date.getTime})
513
503
 
514
504
  // When trying to serialize data to Json pg type, it will fail with
515
505
  // PostgresError: column "params" is of type json but expression is of type boolean
@@ -537,7 +527,7 @@ module Schema = {
537
527
  }
538
528
 
539
529
  let getVariantsTags = variants => {
540
- variants->Js.Array2.map(variant => variant->S.parseOrThrow(Schema.variantTag))
530
+ variants->Array.map(variant => variant->S.parseOrThrow(Schema.variantTag))
541
531
  }
542
532
 
543
533
  module Set = {
@@ -565,7 +555,7 @@ module Set = {
565
555
  @send
566
556
  external add: (t<'value>, 'value) => t<'value> = "add"
567
557
 
568
- let addMany = (set, values) => values->Js.Array2.forEach(value => set->add(value)->ignore)
558
+ let addMany = (set, values) => values->Array.forEach(value => set->add(value)->ignore)
569
559
 
570
560
  @ocaml.doc("Removes all elements from the `Set` object.") @send
571
561
  external clear: t<'value> => unit = "clear"
@@ -628,16 +618,16 @@ external entries: t<'value> => Js_iterator.t<('value, 'value)> = "entries"
628
618
  module Record = {
629
619
  type t<'key, 'value>
630
620
 
631
- external fromDict: Js.Dict.t<'value> => t<'key, 'value> = "%identity"
621
+ external fromDict: dict<'value> => t<'key, 'value> = "%identity"
632
622
  let fromArray: array<('key, 'value)> => t<'key, 'value> = pairs =>
633
- pairs->(magic: array<('key, 'value)> => array<(string, 'value)>)->Js.Dict.fromArray->fromDict
623
+ pairs->(magic: array<('key, 'value)> => array<(string, 'value)>)->Dict.fromArray->fromDict
634
624
 
635
625
  @get_index external getUnsafe: (t<'key, 'value>, 'key) => 'value = ""
636
626
  @get_index external get: (t<'key, 'value>, 'key) => option<'value> = ""
637
627
  }
638
628
 
639
629
  module WeakMap = {
640
- type t<'k, 'v> = Js.WeakMap.t<'k, 'v>
630
+ type t<'k, 'v> = WeakMap.t<'k, 'v>
641
631
 
642
632
  @new external make: unit => t<'k, 'v> = "WeakMap"
643
633
 
@@ -661,7 +651,7 @@ module WeakMap = {
661
651
  }
662
652
 
663
653
  module Map = {
664
- type t<'k, 'v> = Js.Map.t<'k, 'v>
654
+ type t<'k, 'v> = Map.t<'k, 'v>
665
655
 
666
656
  @new external make: unit => t<'k, 'v> = "Map"
667
657
 
@@ -673,7 +663,16 @@ module Map = {
673
663
  }
674
664
 
675
665
  module Proxy = {
676
- type traps<'a> = {get?: (~target: 'a, ~prop: unknown) => unknown}
666
+ type propertyDescriptor = {
667
+ value: unknown,
668
+ enumerable: bool,
669
+ configurable: bool,
670
+ }
671
+ type traps<'a> = {
672
+ get?: (~target: 'a, ~prop: unknown) => unknown,
673
+ ownKeys?: (~target: 'a) => array<string>,
674
+ getOwnPropertyDescriptor?: (~target: 'a, ~prop: unknown) => option<propertyDescriptor>,
675
+ }
677
676
 
678
677
  @new
679
678
  external make: ('a, traps<'a>) => 'a = "Proxy"
@@ -681,7 +680,7 @@ module Proxy = {
681
680
 
682
681
  module Hash = {
683
682
  let fail = name => {
684
- Js.Exn.raiseError(
683
+ JsError.throwWithMessage(
685
684
  `Failed to get hash for ${name}. If you're using a custom Sury schema make it based on the string type with a decoder: const myTypeSchema = S.transform(S.string, undefined, (yourType) => yourType.toString())`,
686
685
  )
687
686
  }
@@ -690,36 +689,36 @@ module Hash = {
690
689
  // just to stick to at least some sort of spec.
691
690
  // After Sury v11 is out we'll be able to do it with schema
692
691
  let rec makeOrThrow = (any: 'a): string => {
693
- switch any->Js.typeof {
694
- | "string" => `"${any->magic}"` // Ideally should escape here,
692
+ switch any->typeof {
693
+ | #string => `"${any->magic}"` // Ideally should escape here,
695
694
  // but since we don't parse it back, it's fine to keep it super simple
696
- | "number" => any->magic->Js.Int.toString
697
- | "bigint" => `"${any->magic->BigInt.toString}"`
698
- | "boolean" => any->magic ? "true" : "false"
699
- | "undefined" => "null"
700
- | "object" =>
695
+ | #number => any->magic->Int.toString
696
+ | #bigint => `"${any->magic->BigInt.toString}"`
697
+ | #boolean => any->magic ? "true" : "false"
698
+ | #undefined => "null"
699
+ | #object =>
701
700
  if any === %raw(`null`) {
702
701
  "null"
703
- } else if any->Js.Array2.isArray {
702
+ } else if any->Array.isArray {
704
703
  let any: array<'a> = any->magic
705
704
  let hash = ref("[")
706
- for i in 0 to any->Js.Array2.length - 1 {
705
+ for i in 0 to any->Array.length - 1 {
707
706
  if i !== 0 {
708
707
  hash := hash.contents ++ ","
709
708
  }
710
- hash := hash.contents ++ any->Js.Array2.unsafe_get(i)->makeOrThrow
709
+ hash := hash.contents ++ any->Array.getUnsafe(i)->makeOrThrow
711
710
  }
712
711
  hash.contents ++ "]"
713
712
  } else {
714
713
  let any: dict<'a> = any->magic
715
- let constructor = any->Js.Dict.unsafeGet("constructor")->magic
714
+ let constructor = any->Dict.getUnsafe("constructor")->magic
716
715
  if constructor === %raw(`Object`) {
717
716
  let hash = ref("{")
718
- let keys = any->Js.Dict.keys->Js.Array2.sortInPlace
717
+ let keys = any->Dict.keysToArray->Array.toSorted(String.compare)
719
718
  let isFirst = ref(true)
720
- for i in 0 to keys->Js.Array2.length - 1 {
721
- let key = keys->Js.Array2.unsafe_get(i)
722
- let value = any->Js.Dict.unsafeGet(key)
719
+ for i in 0 to keys->Array.length - 1 {
720
+ let key = keys->Array.getUnsafe(i)
721
+ let value = any->Dict.getUnsafe(key)
723
722
  if value !== %raw(`undefined`) {
724
723
  if isFirst.contents {
725
724
  isFirst := false
@@ -729,7 +728,7 @@ module Hash = {
729
728
  // Ideally should escape and wrap the key in double quotes
730
729
  // but since we don't need to decode the hash,
731
730
  // it's fine to keep it super simple
732
- hash := hash.contents ++ `"${key}":${any->Js.Dict.unsafeGet(key)->makeOrThrow}`
731
+ hash := hash.contents ++ `"${key}":${any->Dict.getUnsafe(key)->makeOrThrow}`
733
732
  }
734
733
  }
735
734
  hash.contents ++ "}"
@@ -739,17 +738,16 @@ module Hash = {
739
738
  fail((constructor->magic)["name"])
740
739
  }
741
740
  }
742
- | "symbol"
743
- | "function" =>
741
+ | #symbol
742
+ | #function =>
744
743
  (any->magic)["toString"]()
745
- | typeof => fail(typeof)
746
744
  }
747
745
  }
748
746
  }
749
747
 
750
748
  let prettifyExn = exn => {
751
- switch exn->Js.Exn.anyToExnInternal {
752
- | Js.Exn.Error(e) => e->(magic: Js.Exn.t => exn)
749
+ switch exn->JsExn.anyToExnInternal {
750
+ | JsExn(e) => e->(magic: JsExn.t => exn)
753
751
  | exn => exn
754
752
  }
755
753
  }
@@ -763,6 +761,63 @@ module EnvioPackage = {
763
761
  }),
764
762
  ) catch {
765
763
  | S.Raised(error) =>
766
- Js.Exn.raiseError(`Failed to get package.json in envio package: ${error->S.Error.message}`)
764
+ JsError.throwWithMessage(
765
+ `Failed to get package.json in envio package: ${error->S.Error.message}`,
766
+ )
767
767
  }
768
768
  }
769
+
770
+ module BigInt = {
771
+ let arrayToStringArray: array<bigint> => array<string> = %raw(`(arr) => {
772
+ const res = new Array(arr.length);
773
+ for (let i = 0; i < arr.length; i++) {
774
+ res[i] = arr[i].toString();
775
+ }
776
+ return res;
777
+ }`)
778
+
779
+ let schema =
780
+ S.string
781
+ ->S.setName("BigInt")
782
+ ->S.transform(s => {
783
+ parser: string =>
784
+ switch string->BigInt.fromString {
785
+ | Some(bigInt) => bigInt
786
+ | None => s.fail("The string is not valid BigInt")
787
+ },
788
+ serializer: bigint => bigint->BigInt.toString,
789
+ })
790
+ }
791
+
792
+ module Promise = {
793
+ // Async-callback variant of `Promise.make`. The stdlib only ships the
794
+ // sync variant, but we rely on the async one in a couple of places.
795
+ @new
796
+ external makeAsync: ((@uncurry ('a => unit), 'e => unit) => promise<unit>) => promise<'a> =
797
+ "Promise"
798
+
799
+ // `catch` that swallows rejections silently. Handy for fire-and-forget
800
+ // promises that must not take the process down on failure.
801
+ %%private(let noop = (() => ())->Obj.magic)
802
+ let silentCatch = (promise: promise<'a>): promise<'a> => {
803
+ promise->Promise.catch(_ => noop())
804
+ }
805
+
806
+ // Like `catch`, but the callback returns a plain value instead of a new
807
+ // promise. Used when the fallback is a ready-made default.
808
+ @send
809
+ external catchResolve: (promise<'a>, exn => 'a) => promise<'a> = "catch"
810
+
811
+ // Drop a promise's resolved value. We can't use `Promise.ignore` for this
812
+ // because that returns `unit`, not `promise<unit>`.
813
+ external ignoreValue: promise<'a> => promise<unit> = "%identity"
814
+
815
+ // Escape hatches for awaiting non-promise values / producing fake promises
816
+ // in type-directed contexts. Used by a handful of bindings that need to
817
+ // interoperate with raw JS values.
818
+ external unsafe_async: 'a => promise<'a> = "%identity"
819
+ external unsafe_await: promise<'a> => 'a = "?await"
820
+
821
+ // Detects Thenable-like values at runtime (anything with a `.catch` method).
822
+ let isCatchable: 'any => bool = %raw(`value => value && typeof value.catch === 'function'`)
823
+ }