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.
- 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 +428 -51
- package/src/Main.res.mjs +528 -271
- package/src/Persistence.res +77 -84
- package/src/Persistence.res.mjs +131 -132
- package/src/PgStorage.res +291 -167
- package/src/PgStorage.res.mjs +797 -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 +15 -16
- package/src/TestIndexerProxyStorage.res.mjs +98 -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 +2 -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/Utils.res
CHANGED
|
@@ -10,12 +10,12 @@ external importPathWithJson: (
|
|
|
10
10
|
string,
|
|
11
11
|
@as(json`{with: {type: "json"}}`) _,
|
|
12
12
|
) => promise<{
|
|
13
|
-
"default":
|
|
13
|
+
"default": JSON.t,
|
|
14
14
|
}> = "import"
|
|
15
15
|
|
|
16
16
|
let delay = milliseconds =>
|
|
17
|
-
|
|
18
|
-
let _interval =
|
|
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 =>
|
|
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
|
-
|
|
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 =
|
|
104
|
-
dict->
|
|
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->
|
|
121
|
-
| None => dict->
|
|
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->
|
|
128
|
-
| None => dict->
|
|
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
|
|
270
|
-
result
|
|
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
|
|
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
|
|
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
|
|
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->
|
|
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->
|
|
306
|
+
switch results->Array.getUnsafe(index) {
|
|
309
307
|
| Ok(value) => {
|
|
310
|
-
output
|
|
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->
|
|
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->
|
|
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
|
|
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->
|
|
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
|
|
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->
|
|
398
|
-
interleaved->
|
|
386
|
+
arr->Array.forEachWithIndex((v, i) => {
|
|
387
|
+
interleaved->Array.push(v)
|
|
399
388
|
if i < arr->Array.length - 1 {
|
|
400
|
-
interleaved->
|
|
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->
|
|
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 =
|
|
463
|
-
switch
|
|
452
|
+
let regex = /https?:\/\/([^\/?]+).*/
|
|
453
|
+
switch RegExp.exec(regex, url) {
|
|
464
454
|
| Some(result) =>
|
|
465
|
-
switch
|
|
466
|
-
| Some(host) => host
|
|
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->
|
|
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<
|
|
506
|
-
->S.preprocess(_ => {serializer: date => date->magic->
|
|
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<
|
|
512
|
-
->S.preprocess(_ => {serializer: date => date->magic->
|
|
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->
|
|
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->
|
|
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:
|
|
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)>)->
|
|
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> =
|
|
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> =
|
|
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
|
|
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
|
-
|
|
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->
|
|
694
|
-
|
|
|
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
|
-
|
|
|
697
|
-
|
|
|
698
|
-
|
|
|
699
|
-
|
|
|
700
|
-
|
|
|
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->
|
|
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->
|
|
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->
|
|
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->
|
|
714
|
+
let constructor = any->Dict.getUnsafe("constructor")->magic
|
|
716
715
|
if constructor === %raw(`Object`) {
|
|
717
716
|
let hash = ref("{")
|
|
718
|
-
let keys = any->
|
|
717
|
+
let keys = any->Dict.keysToArray->Array.toSorted(String.compare)
|
|
719
718
|
let isFirst = ref(true)
|
|
720
|
-
for i in 0 to keys->
|
|
721
|
-
let key = keys->
|
|
722
|
-
let value = any->
|
|
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->
|
|
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
|
-
|
|
|
743
|
-
|
|
|
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->
|
|
752
|
-
|
|
|
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
|
-
|
|
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
|
+
}
|