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/vendored/Rest.res
CHANGED
|
@@ -16,7 +16,7 @@ module Exn = {
|
|
|
16
16
|
@new
|
|
17
17
|
external makeError: string => error = "Error"
|
|
18
18
|
|
|
19
|
-
let raiseAny = (any: 'any): 'a => any->Obj.magic->
|
|
19
|
+
let raiseAny = (any: 'any): 'a => any->Obj.magic->throw
|
|
20
20
|
|
|
21
21
|
let raiseError: error => 'a = raiseAny
|
|
22
22
|
}
|
|
@@ -25,25 +25,11 @@ module Obj = {
|
|
|
25
25
|
external magic: 'a => 'b = "%identity"
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
module Promise = {
|
|
29
|
-
type t<+'a> = promise<'a>
|
|
30
|
-
|
|
31
|
-
@send
|
|
32
|
-
external thenResolve: (t<'a>, 'a => 'b) => t<'b> = "then"
|
|
33
|
-
}
|
|
34
|
-
|
|
35
28
|
module Option = {
|
|
36
29
|
let unsafeSome: 'a => option<'a> = Obj.magic
|
|
37
30
|
let unsafeUnwrap: option<'a> => 'a = Obj.magic
|
|
38
31
|
}
|
|
39
32
|
|
|
40
|
-
module Dict = {
|
|
41
|
-
@inline
|
|
42
|
-
let has = (dict, key) => {
|
|
43
|
-
dict->Js.Dict.unsafeGet(key)->(Obj.magic: 'a => bool)
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
33
|
let panic = (message, ~params: option<{..}>=?) => {
|
|
48
34
|
let error = Exn.makeError(`[rescript-rest] ${message}`)
|
|
49
35
|
switch params {
|
|
@@ -78,15 +64,15 @@ module ApiFetcher = {
|
|
|
78
64
|
// Note: contentType might be null
|
|
79
65
|
if (
|
|
80
66
|
contentType->Obj.magic &&
|
|
81
|
-
contentType->
|
|
82
|
-
contentType->
|
|
67
|
+
contentType->String.includes("application/") &&
|
|
68
|
+
contentType->String.includes("json")
|
|
83
69
|
) {
|
|
84
70
|
{
|
|
85
71
|
status: result["status"],
|
|
86
72
|
data: await result["json"](),
|
|
87
73
|
headers: result["headers"],
|
|
88
74
|
}
|
|
89
|
-
} else if contentType->Obj.magic && contentType->
|
|
75
|
+
} else if contentType->Obj.magic && contentType->String.includes("text/") {
|
|
90
76
|
{
|
|
91
77
|
status: result["status"],
|
|
92
78
|
data: await result["text"](),
|
|
@@ -206,19 +192,19 @@ module Response = {
|
|
|
206
192
|
if map->Dict.has(key) {
|
|
207
193
|
panic(`Response for the "${key}" status registered multiple times`)
|
|
208
194
|
} else {
|
|
209
|
-
map->
|
|
195
|
+
map->Dict.set(key, builder->(Obj.magic: builder<'output> => t<'output>))
|
|
210
196
|
}
|
|
211
197
|
}
|
|
212
198
|
|
|
213
199
|
@inline
|
|
214
200
|
let find = (map: dict<t<'output>>, responseStatus: int): option<t<'output>> => {
|
|
215
201
|
(map
|
|
216
|
-
->
|
|
202
|
+
->Dict.getUnsafe(responseStatus->(Obj.magic: int => string))
|
|
217
203
|
->(Obj.magic: t<'output> => bool) ||
|
|
218
204
|
map
|
|
219
|
-
->
|
|
205
|
+
->Dict.getUnsafe((responseStatus / 100)->(Obj.magic: int => string) ++ "XX")
|
|
220
206
|
->(Obj.magic: t<'output> => bool) ||
|
|
221
|
-
map->
|
|
207
|
+
map->Dict.getUnsafe("default")->(Obj.magic: t<'output> => bool))
|
|
222
208
|
->(Obj.magic: bool => option<t<'output>>)
|
|
223
209
|
}
|
|
224
210
|
}
|
|
@@ -294,28 +280,28 @@ type route<'input, 'output> = unit => definition<'input, 'output>
|
|
|
294
280
|
|
|
295
281
|
let rec parsePath = (path: string, ~pathItems, ~pathParams) => {
|
|
296
282
|
if path !== "" {
|
|
297
|
-
switch path->
|
|
298
|
-
| -1 => pathItems->
|
|
283
|
+
switch path->String.indexOf("{") {
|
|
284
|
+
| -1 => pathItems->Array.push(Static(path))->ignore
|
|
299
285
|
| paramStartIdx =>
|
|
300
|
-
switch path->
|
|
286
|
+
switch path->String.indexOf("}") {
|
|
301
287
|
| -1 => panic("Path contains an unclosed parameter")
|
|
302
288
|
| paramEndIdx =>
|
|
303
289
|
if paramStartIdx > paramEndIdx {
|
|
304
290
|
panic("Path parameter is not enclosed in curly braces")
|
|
305
291
|
}
|
|
306
|
-
let paramName =
|
|
292
|
+
let paramName = String.slice(path, ~start=paramStartIdx + 1, ~end=paramEndIdx)
|
|
307
293
|
if paramName === "" {
|
|
308
294
|
panic("Path parameter name cannot be empty")
|
|
309
295
|
}
|
|
310
296
|
let param = {name: paramName}
|
|
311
297
|
|
|
312
298
|
pathItems
|
|
313
|
-
->
|
|
299
|
+
->Array.push(Static(String.slice(path, ~start=0, ~end=paramStartIdx)))
|
|
314
300
|
->ignore
|
|
315
|
-
pathItems->
|
|
316
|
-
pathParams->
|
|
301
|
+
pathItems->Array.push(Param(param))->ignore
|
|
302
|
+
pathParams->Dict.set(paramName, param)->ignore
|
|
317
303
|
|
|
318
|
-
parsePath(
|
|
304
|
+
parsePath(String.slice(path, ~start=paramEndIdx + 1), ~pathItems, ~pathParams)
|
|
319
305
|
}
|
|
320
306
|
}
|
|
321
307
|
}
|
|
@@ -342,7 +328,7 @@ let coerceSchema = schema => {
|
|
|
342
328
|
| Float => {
|
|
343
329
|
parser: unknown => {
|
|
344
330
|
let float = %raw(`+unknown`)
|
|
345
|
-
if
|
|
331
|
+
if Float.isNaN(float) {
|
|
346
332
|
unknown
|
|
347
333
|
} else {
|
|
348
334
|
float->Obj.magic
|
|
@@ -360,7 +346,7 @@ let coerceSchema = schema => {
|
|
|
360
346
|
|
|
361
347
|
let stripInPlace = schema => (schema->S.classify->Obj.magic)["unknownKeys"] = S.Strip
|
|
362
348
|
let getSchemaField = (schema, fieldName): option<S.item> =>
|
|
363
|
-
(schema->S.classify->Obj.magic)["fields"]->
|
|
349
|
+
(schema->S.classify->Obj.magic)["fields"]->Dict.getUnsafe(fieldName)
|
|
364
350
|
|
|
365
351
|
type typeValidation = (unknown, ~inputVar: string) => string
|
|
366
352
|
let removeTypeValidationInPlace = schema => (schema->Obj.magic)["f"] = ()
|
|
@@ -385,7 +371,7 @@ let bearerAuthSchema = S.string->S.transform(s => {
|
|
|
385
371
|
`Bearer ${token}`
|
|
386
372
|
},
|
|
387
373
|
parser: string => {
|
|
388
|
-
switch string->
|
|
374
|
+
switch string->String.split(" ") {
|
|
389
375
|
| ["Bearer", token] => token
|
|
390
376
|
| _ => s.fail("Invalid Bearer token")
|
|
391
377
|
}
|
|
@@ -397,7 +383,7 @@ let basicAuthSchema = S.string->S.transform(s => {
|
|
|
397
383
|
`Basic ${token}`
|
|
398
384
|
},
|
|
399
385
|
parser: string => {
|
|
400
|
-
switch string->
|
|
386
|
+
switch string->String.split(" ") {
|
|
401
387
|
| ["Basic", token] => token
|
|
402
388
|
| _ => s.fail("Invalid Basic token")
|
|
403
389
|
}
|
|
@@ -432,8 +418,8 @@ let params = route => {
|
|
|
432
418
|
emptyData: false,
|
|
433
419
|
schema: outputSchema,
|
|
434
420
|
}
|
|
435
|
-
let responsesMap =
|
|
436
|
-
responsesMap->
|
|
421
|
+
let responsesMap = Dict.make()
|
|
422
|
+
responsesMap->Dict.set("200", response)
|
|
437
423
|
{
|
|
438
424
|
method: Post,
|
|
439
425
|
path,
|
|
@@ -451,7 +437,7 @@ let params = route => {
|
|
|
451
437
|
}
|
|
452
438
|
} else {
|
|
453
439
|
let pathItems = []
|
|
454
|
-
let pathParams =
|
|
440
|
+
let pathParams = Dict.make()
|
|
455
441
|
parsePath(definition.path, ~pathItems, ~pathParams)
|
|
456
442
|
|
|
457
443
|
// Don't use ref, since it creates an unnecessary object
|
|
@@ -482,7 +468,7 @@ let params = route => {
|
|
|
482
468
|
s.field("body", schema)
|
|
483
469
|
},
|
|
484
470
|
header: (fieldName, schema) => {
|
|
485
|
-
s.nested("headers").field(fieldName->
|
|
471
|
+
s.nested("headers").field(fieldName->String.toLowerCase, coerceSchema(schema))
|
|
486
472
|
},
|
|
487
473
|
query: (fieldName, schema) => {
|
|
488
474
|
s.nested("query").field(fieldName, coerceSchema(schema))
|
|
@@ -525,9 +511,9 @@ let params = route => {
|
|
|
525
511
|
}
|
|
526
512
|
}
|
|
527
513
|
|
|
528
|
-
let responsesMap =
|
|
514
|
+
let responsesMap = Dict.make()
|
|
529
515
|
let responses = []
|
|
530
|
-
definition.responses->
|
|
516
|
+
definition.responses->Array.forEach(r => {
|
|
531
517
|
let builder: Response.builder<unknown> = {
|
|
532
518
|
emptyData: true,
|
|
533
519
|
}
|
|
@@ -539,7 +525,7 @@ let params = route => {
|
|
|
539
525
|
s.tag("status", status)
|
|
540
526
|
}
|
|
541
527
|
let header = (fieldName, schema) => {
|
|
542
|
-
s.nested("headers").field(fieldName->
|
|
528
|
+
s.nested("headers").field(fieldName->String.toLowerCase, coerceSchema(schema))
|
|
543
529
|
}
|
|
544
530
|
let definition = r({
|
|
545
531
|
status,
|
|
@@ -591,11 +577,11 @@ let params = route => {
|
|
|
591
577
|
}
|
|
592
578
|
builder.schema = Option.unsafeSome(schema)
|
|
593
579
|
responses
|
|
594
|
-
->
|
|
580
|
+
->Array.push(builder->(Obj.magic: Response.builder<unknown> => Response.t<unknown>))
|
|
595
581
|
->ignore
|
|
596
582
|
})
|
|
597
583
|
|
|
598
|
-
if responses->
|
|
584
|
+
if responses->Array.length === 0 {
|
|
599
585
|
panic("At least single response should be registered")
|
|
600
586
|
}
|
|
601
587
|
|
|
@@ -603,7 +589,7 @@ let params = route => {
|
|
|
603
589
|
method: definition.method,
|
|
604
590
|
path: definition.path,
|
|
605
591
|
inputSchema,
|
|
606
|
-
outputSchema: S.union(responses->
|
|
592
|
+
outputSchema: S.union(responses->Array.map(r => r.schema)),
|
|
607
593
|
responses,
|
|
608
594
|
pathItems,
|
|
609
595
|
responsesMap,
|
|
@@ -637,22 +623,22 @@ type client = {
|
|
|
637
623
|
* This should be fully compatible with the "qs" library, but more optimised and without the need to add a dependency
|
|
638
624
|
*/
|
|
639
625
|
let rec tokeniseValue = (key, value, ~append) => {
|
|
640
|
-
if
|
|
626
|
+
if Array.isArray(value) {
|
|
641
627
|
value
|
|
642
628
|
->(Obj.magic: unknown => array<unknown>)
|
|
643
|
-
->
|
|
644
|
-
tokeniseValue(`${key}[${idx->
|
|
629
|
+
->Array.forEachWithIndex((v, idx) => {
|
|
630
|
+
tokeniseValue(`${key}[${idx->Int.toString}]`, v, ~append)
|
|
645
631
|
})
|
|
646
632
|
} else if value === %raw(`null`) {
|
|
647
633
|
append(key, "")
|
|
648
634
|
} else if value === %raw(`void 0`) {
|
|
649
635
|
()
|
|
650
|
-
} else if
|
|
636
|
+
} else if typeof(value) === #object {
|
|
651
637
|
let dict = value->(Obj.magic: unknown => dict<unknown>)
|
|
652
638
|
dict
|
|
653
|
-
->
|
|
654
|
-
->
|
|
655
|
-
tokeniseValue(`${key}[${encodeURIComponent(k)}]`, dict->
|
|
639
|
+
->Dict.keysToArray
|
|
640
|
+
->Array.forEach(k => {
|
|
641
|
+
tokeniseValue(`${key}[${encodeURIComponent(k)}]`, dict->Dict.getUnsafe(k), ~append)
|
|
656
642
|
})
|
|
657
643
|
} else {
|
|
658
644
|
append(key, value->(Obj.magic: unknown => string))
|
|
@@ -663,12 +649,12 @@ let rec tokeniseValue = (key, value, ~append) => {
|
|
|
663
649
|
let getCompletePath = (~baseUrl, ~pathItems, ~maybeQuery, ~maybeParams, ~jsonQuery=false) => {
|
|
664
650
|
let path = ref(baseUrl)
|
|
665
651
|
|
|
666
|
-
for idx in 0 to pathItems->
|
|
667
|
-
let pathItem = pathItems->
|
|
652
|
+
for idx in 0 to pathItems->Array.length - 1 {
|
|
653
|
+
let pathItem = pathItems->Array.getUnsafe(idx)
|
|
668
654
|
switch pathItem {
|
|
669
655
|
| Static(static) => path := path.contents ++ static
|
|
670
656
|
| Param({name}) =>
|
|
671
|
-
switch (maybeParams->Obj.magic && maybeParams->
|
|
657
|
+
switch (maybeParams->Obj.magic && maybeParams->Dict.getUnsafe(name)->Obj.magic)
|
|
672
658
|
->(Obj.magic: bool => option<string>) {
|
|
673
659
|
| Some(param) => path := path.contents ++ param
|
|
674
660
|
| None => panic(`Path parameter "${name}" is not defined in input`)
|
|
@@ -682,13 +668,13 @@ let getCompletePath = (~baseUrl, ~pathItems, ~maybeQuery, ~maybeParams, ~jsonQue
|
|
|
682
668
|
let queryItems = []
|
|
683
669
|
|
|
684
670
|
let append = (key, value) => {
|
|
685
|
-
let _ = queryItems->
|
|
671
|
+
let _ = queryItems->Array.push(key ++ "=" ++ encodeURIComponent(value))
|
|
686
672
|
}
|
|
687
673
|
|
|
688
|
-
let queryNames = query->
|
|
689
|
-
for idx in 0 to queryNames->
|
|
690
|
-
let queryName = queryNames->
|
|
691
|
-
let value = query->
|
|
674
|
+
let queryNames = query->Dict.keysToArray
|
|
675
|
+
for idx in 0 to queryNames->Array.length - 1 {
|
|
676
|
+
let queryName = queryNames->Array.getUnsafe(idx)
|
|
677
|
+
let value = query->Dict.getUnsafe(queryName)
|
|
692
678
|
let key = encodeURIComponent(queryName)
|
|
693
679
|
if value !== %raw(`void 0`) {
|
|
694
680
|
switch jsonQuery {
|
|
@@ -699,17 +685,17 @@ let getCompletePath = (~baseUrl, ~pathItems, ~maybeQuery, ~maybeParams, ~jsonQue
|
|
|
699
685
|
append(
|
|
700
686
|
key,
|
|
701
687
|
if (
|
|
702
|
-
|
|
688
|
+
typeof(value) === #string && {
|
|
703
689
|
let value = value->(Obj.magic: unknown => string)
|
|
704
690
|
value !== "true" &&
|
|
705
691
|
value !== "false" &&
|
|
706
692
|
value !== "null" &&
|
|
707
|
-
|
|
693
|
+
Float.isNaN(Float.parseFloat(value))
|
|
708
694
|
}
|
|
709
695
|
) {
|
|
710
696
|
value->(Obj.magic: unknown => string)
|
|
711
697
|
} else {
|
|
712
|
-
value->(Obj.magic: unknown =>
|
|
698
|
+
value->(Obj.magic: unknown => JSON.t)->JSON.stringify
|
|
713
699
|
},
|
|
714
700
|
)
|
|
715
701
|
| false => tokeniseValue(key, value, ~append)
|
|
@@ -717,8 +703,8 @@ let getCompletePath = (~baseUrl, ~pathItems, ~maybeQuery, ~maybeParams, ~jsonQue
|
|
|
717
703
|
}
|
|
718
704
|
}
|
|
719
705
|
|
|
720
|
-
if queryItems->
|
|
721
|
-
path := path.contents ++ "?" ++ queryItems->
|
|
706
|
+
if queryItems->Array.length > 0 {
|
|
707
|
+
path := path.contents ++ "?" ++ queryItems->Array.joinUnsafe("&")
|
|
722
708
|
}
|
|
723
709
|
}
|
|
724
710
|
}
|
|
@@ -791,10 +777,10 @@ let fetch = (type input response, route: route<input, response>, input, ~client=
|
|
|
791
777
|
})->Promise.thenResolve(fetcherResponse => {
|
|
792
778
|
switch responsesMap->Response.find(fetcherResponse.status) {
|
|
793
779
|
| None =>
|
|
794
|
-
let error = ref(`Unexpected response status "${fetcherResponse.status->
|
|
780
|
+
let error = ref(`Unexpected response status "${fetcherResponse.status->Int.toString}"`)
|
|
795
781
|
if (
|
|
796
782
|
fetcherResponse.data->Obj.magic &&
|
|
797
|
-
|
|
783
|
+
typeof((fetcherResponse.data->Obj.magic)["message"]) === #string
|
|
798
784
|
) {
|
|
799
785
|
error :=
|
|
800
786
|
error.contents ++ ". Message: " ++ (fetcherResponse.data->Obj.magic)["message"]->Obj.magic
|