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.
- package/README.md +3 -3
- 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 +430 -51
- package/src/Main.res.mjs +530 -271
- package/src/Persistence.res +80 -84
- package/src/Persistence.res.mjs +131 -132
- package/src/PgStorage.res +294 -167
- package/src/PgStorage.res.mjs +799 -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 +16 -16
- package/src/TestIndexerProxyStorage.res.mjs +99 -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 +7 -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
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
open Belt
|
|
2
|
-
|
|
3
1
|
// Message types for communication between worker and main thread
|
|
4
2
|
type requestId = int
|
|
5
3
|
|
|
6
4
|
// Serializable change with entity as JSON (for worker thread messaging)
|
|
7
5
|
@tag("type")
|
|
8
6
|
type serializableChange =
|
|
9
|
-
| @as("SET") Set({entityId: string, entity:
|
|
7
|
+
| @as("SET") Set({entityId: string, entity: JSON.t, checkpointId: bigint})
|
|
10
8
|
| @as("DELETE") Delete({entityId: string, checkpointId: bigint})
|
|
11
9
|
|
|
12
10
|
type serializableEntityUpdate = {
|
|
@@ -28,7 +26,7 @@ type workerPayload =
|
|
|
28
26
|
LoadByField({
|
|
29
27
|
tableName: string,
|
|
30
28
|
fieldName: string,
|
|
31
|
-
fieldValue:
|
|
29
|
+
fieldValue: JSON.t,
|
|
32
30
|
operator: Persistence.operator,
|
|
33
31
|
})
|
|
34
32
|
| @as("writeBatch")
|
|
@@ -37,14 +35,14 @@ type workerPayload =
|
|
|
37
35
|
checkpointIds: array<bigint>,
|
|
38
36
|
checkpointChainIds: array<int>,
|
|
39
37
|
checkpointBlockNumbers: array<int>,
|
|
40
|
-
checkpointBlockHashes: array<
|
|
38
|
+
checkpointBlockHashes: array<Null.t<string>>,
|
|
41
39
|
checkpointEventsProcessed: array<int>,
|
|
42
40
|
})
|
|
43
41
|
|
|
44
42
|
// Main thread -> Worker payloads
|
|
45
43
|
@tag("type")
|
|
46
44
|
type mainPayload =
|
|
47
|
-
| @as("response") Response({data:
|
|
45
|
+
| @as("response") Response({data: JSON.t})
|
|
48
46
|
| @as("error") Error({message: string})
|
|
49
47
|
|
|
50
48
|
// Message wrapper with id
|
|
@@ -54,7 +52,7 @@ type mainMessage = message<mainPayload>
|
|
|
54
52
|
|
|
55
53
|
// Pending request tracker
|
|
56
54
|
type pendingRequest = {
|
|
57
|
-
resolve:
|
|
55
|
+
resolve: JSON.t => unit,
|
|
58
56
|
reject: exn => unit,
|
|
59
57
|
}
|
|
60
58
|
|
|
@@ -69,7 +67,7 @@ let make = (~parentPort, ~initialState): t => {
|
|
|
69
67
|
let proxy = {
|
|
70
68
|
parentPort,
|
|
71
69
|
initialState,
|
|
72
|
-
pendingRequests:
|
|
70
|
+
pendingRequests: Dict.make(),
|
|
73
71
|
requestCounter: 0,
|
|
74
72
|
}
|
|
75
73
|
|
|
@@ -80,9 +78,9 @@ let make = (~parentPort, ~initialState): t => {
|
|
|
80
78
|
idStr,
|
|
81
79
|
) {
|
|
82
80
|
| Some(pending) => pending
|
|
83
|
-
| None =>
|
|
81
|
+
| None => JsError.throwWithMessage(`TestIndexer: No pending request found for id ${idStr}`)
|
|
84
82
|
}
|
|
85
|
-
|
|
83
|
+
Dict.delete(proxy.pendingRequests->Obj.magic, idStr)
|
|
86
84
|
|
|
87
85
|
switch msg.payload {
|
|
88
86
|
| Response({data}) => resolve(data)
|
|
@@ -98,18 +96,19 @@ let nextRequestId = (proxy: t): requestId => {
|
|
|
98
96
|
proxy.requestCounter
|
|
99
97
|
}
|
|
100
98
|
|
|
101
|
-
let sendRequest = (proxy: t, ~payload: workerPayload): promise<
|
|
99
|
+
let sendRequest = (proxy: t, ~payload: workerPayload): promise<JSON.t> => {
|
|
102
100
|
Promise.make((resolve, reject) => {
|
|
103
101
|
let id = proxy->nextRequestId
|
|
104
|
-
proxy.pendingRequests->
|
|
102
|
+
proxy.pendingRequests->Dict.set(id->Int.toString, {resolve, reject})
|
|
105
103
|
proxy.parentPort->NodeJs.WorkerThreads.postMessage({id, payload})
|
|
106
104
|
})
|
|
107
105
|
}
|
|
108
106
|
|
|
109
107
|
let makeStorage = (proxy: t): Persistence.storage => {
|
|
108
|
+
name: "test-proxy",
|
|
110
109
|
isInitialized: async () => true,
|
|
111
110
|
initialize: async (~chainConfigs as _=?, ~entities as _=?, ~enums as _=?) => {
|
|
112
|
-
|
|
111
|
+
JsError.throwWithMessage(
|
|
113
112
|
"TestIndexer: initialize should not be called. Use resumeInitialState instead.",
|
|
114
113
|
)
|
|
115
114
|
},
|
|
@@ -188,18 +187,19 @@ let makeStorage = (proxy: t): Persistence.storage => {
|
|
|
188
187
|
pruneStaleEntityHistory: async (~entityName as _, ~entityIndex as _, ~safeCheckpointId as _) =>
|
|
189
188
|
(),
|
|
190
189
|
getRollbackTargetCheckpoint: async (~reorgChainId as _, ~lastKnownValidBlockNumber as _) => {
|
|
191
|
-
|
|
190
|
+
JsError.throwWithMessage(
|
|
192
191
|
"TestIndexer: Rollback is not supported. Set rollbackOnReorg to false in config.",
|
|
193
192
|
)
|
|
194
193
|
},
|
|
195
194
|
getRollbackProgressDiff: async (~rollbackTargetCheckpointId as _) => {
|
|
196
|
-
|
|
195
|
+
JsError.throwWithMessage(
|
|
197
196
|
"TestIndexer: Rollback is not supported. Set rollbackOnReorg to false in config.",
|
|
198
197
|
)
|
|
199
198
|
},
|
|
200
199
|
getRollbackData: async (~entityConfig as _, ~rollbackTargetCheckpointId as _) => {
|
|
201
|
-
|
|
200
|
+
JsError.throwWithMessage(
|
|
202
201
|
"TestIndexer: Rollback is not supported. Set rollbackOnReorg to false in config.",
|
|
203
202
|
)
|
|
204
203
|
},
|
|
204
|
+
close: async () => (),
|
|
205
205
|
}
|
|
@@ -1,29 +1,28 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
|
-
import * as
|
|
4
|
-
import * as
|
|
5
|
-
import * as Belt_Array from "rescript/lib/es6/belt_Array.js";
|
|
3
|
+
import * as Stdlib_Dict from "@rescript/runtime/lib/es6/Stdlib_Dict.js";
|
|
4
|
+
import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js";
|
|
6
5
|
import * as S$RescriptSchema from "rescript-schema/src/S.res.mjs";
|
|
7
6
|
|
|
8
7
|
function make(parentPort, initialState) {
|
|
9
|
-
|
|
8
|
+
let proxy = {
|
|
10
9
|
parentPort: parentPort,
|
|
11
10
|
initialState: initialState,
|
|
12
11
|
pendingRequests: {},
|
|
13
12
|
requestCounter: 0
|
|
14
13
|
};
|
|
15
|
-
parentPort.on("message",
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
14
|
+
parentPort.on("message", msg => {
|
|
15
|
+
let idStr = msg.id.toString();
|
|
16
|
+
let pending = proxy.pendingRequests[idStr];
|
|
17
|
+
let match = pending !== undefined ? pending : Stdlib_JsError.throwWithMessage(`TestIndexer: No pending request found for id ` + idStr);
|
|
18
|
+
Stdlib_Dict.$$delete(proxy.pendingRequests, idStr);
|
|
19
|
+
let match$1 = msg.payload;
|
|
20
|
+
if (match$1.type === "response") {
|
|
21
|
+
return match.resolve(match$1.data);
|
|
22
|
+
} else {
|
|
23
|
+
return match.reject(new Error(match$1.message));
|
|
24
|
+
}
|
|
25
|
+
});
|
|
27
26
|
return proxy;
|
|
28
27
|
}
|
|
29
28
|
|
|
@@ -33,119 +32,97 @@ function nextRequestId(proxy) {
|
|
|
33
32
|
}
|
|
34
33
|
|
|
35
34
|
function sendRequest(proxy, payload) {
|
|
36
|
-
return new Promise((
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
35
|
+
return new Promise((resolve, reject) => {
|
|
36
|
+
let id = nextRequestId(proxy);
|
|
37
|
+
proxy.pendingRequests[id.toString()] = {
|
|
38
|
+
resolve: resolve,
|
|
39
|
+
reject: reject
|
|
40
|
+
};
|
|
41
|
+
proxy.parentPort.postMessage({
|
|
42
|
+
id: id,
|
|
43
|
+
payload: payload
|
|
44
|
+
});
|
|
45
|
+
});
|
|
47
46
|
}
|
|
48
47
|
|
|
49
48
|
function makeStorage(proxy) {
|
|
50
49
|
return {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
return {
|
|
108
|
-
type: "SET",
|
|
109
|
-
entityId: change.entityId,
|
|
110
|
-
entity: S$RescriptSchema.reverseConvertToJsonOrThrow(change.entity, entityConfig.schema),
|
|
111
|
-
checkpointId: change.checkpointId
|
|
112
|
-
};
|
|
113
|
-
} else {
|
|
114
|
-
return {
|
|
115
|
-
type: "DELETE",
|
|
116
|
-
entityId: change.entityId,
|
|
117
|
-
checkpointId: change.checkpointId
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
return {
|
|
122
|
-
entityName: entityConfig.name,
|
|
123
|
-
updates: Belt_Array.map(param.updates, (function (update) {
|
|
124
|
-
return {
|
|
125
|
-
latestChange: encodeChange(update.latestChange),
|
|
126
|
-
history: Belt_Array.map(update.history, encodeChange),
|
|
127
|
-
containsRollbackDiffChange: update.containsRollbackDiffChange
|
|
128
|
-
};
|
|
129
|
-
}))
|
|
130
|
-
};
|
|
131
|
-
}));
|
|
132
|
-
await sendRequest(proxy, {
|
|
133
|
-
type: "writeBatch",
|
|
134
|
-
updatedEntities: serializableEntities,
|
|
135
|
-
checkpointIds: batch.checkpointIds,
|
|
136
|
-
checkpointChainIds: batch.checkpointChainIds,
|
|
137
|
-
checkpointBlockNumbers: batch.checkpointBlockNumbers,
|
|
138
|
-
checkpointBlockHashes: batch.checkpointBlockHashes,
|
|
139
|
-
checkpointEventsProcessed: batch.checkpointEventsProcessed
|
|
140
|
-
});
|
|
141
|
-
})
|
|
50
|
+
name: "test-proxy",
|
|
51
|
+
isInitialized: async () => true,
|
|
52
|
+
initialize: async (param, param$1, param$2) => Stdlib_JsError.throwWithMessage("TestIndexer: initialize should not be called. Use resumeInitialState instead."),
|
|
53
|
+
resumeInitialState: async () => proxy.initialState,
|
|
54
|
+
loadByIdsOrThrow: async (ids, table, rowsSchema) => {
|
|
55
|
+
let response = await sendRequest(proxy, {
|
|
56
|
+
type: "loadByIds",
|
|
57
|
+
tableName: table.tableName,
|
|
58
|
+
ids: ids
|
|
59
|
+
});
|
|
60
|
+
return S$RescriptSchema.parseOrThrow(response, rowsSchema);
|
|
61
|
+
},
|
|
62
|
+
loadByFieldOrThrow: async (fieldName, fieldSchema, fieldValue, operator, table, rowsSchema) => {
|
|
63
|
+
let response = await sendRequest(proxy, {
|
|
64
|
+
type: "loadByField",
|
|
65
|
+
tableName: table.tableName,
|
|
66
|
+
fieldName: fieldName,
|
|
67
|
+
fieldValue: S$RescriptSchema.reverseConvertToJsonOrThrow(fieldValue, fieldSchema),
|
|
68
|
+
operator: operator
|
|
69
|
+
});
|
|
70
|
+
return S$RescriptSchema.parseOrThrow(response, rowsSchema);
|
|
71
|
+
},
|
|
72
|
+
dumpEffectCache: async () => {},
|
|
73
|
+
reset: async () => {},
|
|
74
|
+
setChainMeta: async param => {},
|
|
75
|
+
pruneStaleCheckpoints: async param => {},
|
|
76
|
+
pruneStaleEntityHistory: async (param, param$1, param$2) => {},
|
|
77
|
+
getRollbackTargetCheckpoint: async (param, param$1) => Stdlib_JsError.throwWithMessage("TestIndexer: Rollback is not supported. Set rollbackOnReorg to false in config."),
|
|
78
|
+
getRollbackProgressDiff: async param => Stdlib_JsError.throwWithMessage("TestIndexer: Rollback is not supported. Set rollbackOnReorg to false in config."),
|
|
79
|
+
getRollbackData: async (param, param$1) => Stdlib_JsError.throwWithMessage("TestIndexer: Rollback is not supported. Set rollbackOnReorg to false in config."),
|
|
80
|
+
writeBatch: async (batch, param, param$1, param$2, param$3, param$4, param$5, updatedEntities) => {
|
|
81
|
+
let serializableEntities = updatedEntities.map(param => {
|
|
82
|
+
let entityConfig = param.entityConfig;
|
|
83
|
+
let encodeChange = change => {
|
|
84
|
+
if (change.type === "SET") {
|
|
85
|
+
return {
|
|
86
|
+
type: "SET",
|
|
87
|
+
entityId: change.entityId,
|
|
88
|
+
entity: S$RescriptSchema.reverseConvertToJsonOrThrow(change.entity, entityConfig.schema),
|
|
89
|
+
checkpointId: change.checkpointId
|
|
90
|
+
};
|
|
91
|
+
} else {
|
|
92
|
+
return {
|
|
93
|
+
type: "DELETE",
|
|
94
|
+
entityId: change.entityId,
|
|
95
|
+
checkpointId: change.checkpointId
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
return {
|
|
100
|
+
entityName: entityConfig.name,
|
|
101
|
+
updates: param.updates.map(update => ({
|
|
102
|
+
latestChange: encodeChange(update.latestChange),
|
|
103
|
+
history: update.history.map(encodeChange),
|
|
104
|
+
containsRollbackDiffChange: update.containsRollbackDiffChange
|
|
105
|
+
}))
|
|
142
106
|
};
|
|
107
|
+
});
|
|
108
|
+
await sendRequest(proxy, {
|
|
109
|
+
type: "writeBatch",
|
|
110
|
+
updatedEntities: serializableEntities,
|
|
111
|
+
checkpointIds: batch.checkpointIds,
|
|
112
|
+
checkpointChainIds: batch.checkpointChainIds,
|
|
113
|
+
checkpointBlockNumbers: batch.checkpointBlockNumbers,
|
|
114
|
+
checkpointBlockHashes: batch.checkpointBlockHashes,
|
|
115
|
+
checkpointEventsProcessed: batch.checkpointEventsProcessed
|
|
116
|
+
});
|
|
117
|
+
},
|
|
118
|
+
close: async () => {}
|
|
119
|
+
};
|
|
143
120
|
}
|
|
144
121
|
|
|
145
122
|
export {
|
|
146
|
-
make
|
|
147
|
-
nextRequestId
|
|
148
|
-
sendRequest
|
|
149
|
-
makeStorage
|
|
123
|
+
make,
|
|
124
|
+
nextRequestId,
|
|
125
|
+
sendRequest,
|
|
126
|
+
makeStorage,
|
|
150
127
|
}
|
|
151
128
|
/* S-RescriptSchema Not a pure module */
|
package/src/Throttler.res
CHANGED
|
@@ -19,13 +19,13 @@ let make = (~intervalMillis: int, ~logger) => {
|
|
|
19
19
|
let rec startInternal = async (throttler: t) => {
|
|
20
20
|
switch throttler {
|
|
21
21
|
| {scheduled: Some(fn), isRunning: false, isAwaitingInterval: false} =>
|
|
22
|
-
let timeSinceLastRun =
|
|
22
|
+
let timeSinceLastRun = Date.now() -. throttler.lastRunTimeMillis
|
|
23
23
|
|
|
24
24
|
//Only execute if we are passed the interval
|
|
25
25
|
if timeSinceLastRun >= throttler.intervalMillis {
|
|
26
26
|
throttler.isRunning = true
|
|
27
27
|
throttler.scheduled = None
|
|
28
|
-
throttler.lastRunTimeMillis =
|
|
28
|
+
throttler.lastRunTimeMillis = Date.now()
|
|
29
29
|
|
|
30
30
|
switch await fn() {
|
|
31
31
|
| exception exn =>
|
|
@@ -43,7 +43,7 @@ let rec startInternal = async (throttler: t) => {
|
|
|
43
43
|
} else {
|
|
44
44
|
//Store isAwaitingInterval in state so that timers don't continuously get created
|
|
45
45
|
throttler.isAwaitingInterval = true
|
|
46
|
-
let _ =
|
|
46
|
+
let _ = setTimeout(() => {
|
|
47
47
|
throttler.isAwaitingInterval = false
|
|
48
48
|
throttler->startInternal->ignore
|
|
49
49
|
}, Belt.Int.fromFloat(throttler.intervalMillis -. timeSinceLastRun))
|
package/src/Throttler.res.mjs
CHANGED
|
@@ -2,52 +2,51 @@
|
|
|
2
2
|
|
|
3
3
|
import * as Pino from "./bindings/Pino.res.mjs";
|
|
4
4
|
import * as Utils from "./Utils.res.mjs";
|
|
5
|
-
import * as
|
|
5
|
+
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
|
|
6
6
|
|
|
7
7
|
function make(intervalMillis, logger) {
|
|
8
8
|
return {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
lastRunTimeMillis: 0,
|
|
10
|
+
isRunning: false,
|
|
11
|
+
isAwaitingInterval: false,
|
|
12
|
+
scheduled: undefined,
|
|
13
|
+
intervalMillis: intervalMillis,
|
|
14
|
+
logger: logger
|
|
15
|
+
};
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
async function startInternal(throttler) {
|
|
19
|
-
|
|
19
|
+
let match = throttler.isRunning;
|
|
20
20
|
if (match) {
|
|
21
|
-
return
|
|
21
|
+
return;
|
|
22
22
|
}
|
|
23
|
-
|
|
23
|
+
let match$1 = throttler.isAwaitingInterval;
|
|
24
24
|
if (match$1) {
|
|
25
|
-
return
|
|
25
|
+
return;
|
|
26
26
|
}
|
|
27
|
-
|
|
27
|
+
let fn = throttler.scheduled;
|
|
28
28
|
if (fn === undefined) {
|
|
29
|
-
return
|
|
29
|
+
return;
|
|
30
30
|
}
|
|
31
|
-
|
|
31
|
+
let timeSinceLastRun = Date.now() - throttler.lastRunTimeMillis;
|
|
32
32
|
if (timeSinceLastRun >= throttler.intervalMillis) {
|
|
33
33
|
throttler.isRunning = true;
|
|
34
34
|
throttler.scheduled = undefined;
|
|
35
35
|
throttler.lastRunTimeMillis = Date.now();
|
|
36
36
|
try {
|
|
37
37
|
await fn();
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
|
|
38
|
+
} catch (raw_exn) {
|
|
39
|
+
let exn = Primitive_exceptions.internalToException(raw_exn);
|
|
41
40
|
throttler.logger.error(Pino.createPinoMessageWithError("Scheduled action failed in throttler", Utils.prettifyExn(exn)));
|
|
42
41
|
}
|
|
43
42
|
throttler.isRunning = false;
|
|
44
43
|
return await startInternal(throttler);
|
|
45
44
|
}
|
|
46
45
|
throttler.isAwaitingInterval = true;
|
|
47
|
-
setTimeout((
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
setTimeout(() => {
|
|
47
|
+
throttler.isAwaitingInterval = false;
|
|
48
|
+
startInternal(throttler);
|
|
49
|
+
}, throttler.intervalMillis - timeSinceLastRun | 0);
|
|
51
50
|
}
|
|
52
51
|
|
|
53
52
|
function schedule(throttler, fn) {
|
|
@@ -56,7 +55,7 @@ function schedule(throttler, fn) {
|
|
|
56
55
|
}
|
|
57
56
|
|
|
58
57
|
export {
|
|
59
|
-
make
|
|
60
|
-
schedule
|
|
58
|
+
make,
|
|
59
|
+
schedule,
|
|
61
60
|
}
|
|
62
61
|
/* Pino Not a pure module */
|
package/src/Time.res
CHANGED
|
@@ -35,7 +35,7 @@ let rec retryAsyncWithExponentialBackOff = async (
|
|
|
35
35
|
~msg=`Failure. Max retries ${retryCount->Belt.Int.toString}/${maxRetries->Belt.Int.toString} exceeded`,
|
|
36
36
|
)
|
|
37
37
|
->ErrorHandling.log
|
|
38
|
-
await Promise.reject(exn->
|
|
38
|
+
await Promise.reject(exn->JsExn.anyToExnInternal)
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
}
|
package/src/Time.res.mjs
CHANGED
|
@@ -3,39 +3,36 @@
|
|
|
3
3
|
import * as Utils from "./Utils.res.mjs";
|
|
4
4
|
import * as Logging from "./Logging.res.mjs";
|
|
5
5
|
import * as ErrorHandling from "./ErrorHandling.res.mjs";
|
|
6
|
-
import * as
|
|
6
|
+
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
return Utils.delay(delayMilliseconds);
|
|
10
|
-
}
|
|
8
|
+
let resolvePromiseAfterDelay = Utils.delay;
|
|
11
9
|
|
|
12
10
|
async function retryAsyncWithExponentialBackOff(backOffMillisOpt, multiplicativeOpt, retryCountOpt, maxRetriesOpt, logger, f) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
let backOffMillis = backOffMillisOpt !== undefined ? backOffMillisOpt : 100;
|
|
12
|
+
let multiplicative = multiplicativeOpt !== undefined ? multiplicativeOpt : 4;
|
|
13
|
+
let retryCount = retryCountOpt !== undefined ? retryCountOpt : 0;
|
|
14
|
+
let maxRetries = maxRetriesOpt !== undefined ? maxRetriesOpt : 5;
|
|
17
15
|
try {
|
|
18
16
|
return await f();
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
|
|
17
|
+
} catch (raw_exn) {
|
|
18
|
+
let exn = Primitive_exceptions.internalToException(raw_exn);
|
|
22
19
|
if (retryCount < maxRetries) {
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
let nextRetryCount = retryCount + 1 | 0;
|
|
21
|
+
let log = retryCount === 0 ? Logging.childTrace : Logging.childWarn;
|
|
25
22
|
log(logger, {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
msg: `Retrying query ` + String(nextRetryCount) + `/` + String(maxRetries) + ` in ` + String(backOffMillis) + `ms - waiting for correct result.`,
|
|
24
|
+
err: Utils.prettifyExn(exn)
|
|
25
|
+
});
|
|
29
26
|
await Utils.delay(backOffMillis);
|
|
30
|
-
return await retryAsyncWithExponentialBackOff(
|
|
27
|
+
return await retryAsyncWithExponentialBackOff(backOffMillis * multiplicative | 0, multiplicative, nextRetryCount, maxRetries, logger, f);
|
|
31
28
|
}
|
|
32
|
-
ErrorHandling.log(ErrorHandling.make(exn, logger,
|
|
33
|
-
return await Promise.reject(
|
|
29
|
+
ErrorHandling.log(ErrorHandling.make(exn, logger, `Failure. Max retries ` + String(retryCount) + `/` + String(maxRetries) + ` exceeded`));
|
|
30
|
+
return await Promise.reject(Primitive_exceptions.internalToException(exn));
|
|
34
31
|
}
|
|
35
32
|
}
|
|
36
33
|
|
|
37
34
|
export {
|
|
38
|
-
resolvePromiseAfterDelay
|
|
39
|
-
retryAsyncWithExponentialBackOff
|
|
35
|
+
resolvePromiseAfterDelay,
|
|
36
|
+
retryAsyncWithExponentialBackOff,
|
|
40
37
|
}
|
|
41
38
|
/* Utils Not a pure module */
|
package/src/TopicFilter.res
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
let toTwosComplement = (num: bigint, ~bytesLen: int) => {
|
|
2
|
-
let maxValue = 1n->BigInt.
|
|
2
|
+
let maxValue = 1n->BigInt.shiftLeft(BigInt.fromInt(bytesLen * 8))
|
|
3
3
|
let mask = maxValue->BigInt.sub(1n)
|
|
4
|
-
num->BigInt.add(maxValue)->BigInt.
|
|
4
|
+
num->BigInt.add(maxValue)->BigInt.bitwiseAnd(mask)
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
let fromSignedBigInt = val => {
|
|
@@ -23,5 +23,5 @@ let fromString: string => hex = val => val->Viem.stringToHex(~options={size: 32}
|
|
|
23
23
|
let fromAddress: Address.t => hex = addr => addr->(Utils.magic: Address.t => hex)->Viem.pad
|
|
24
24
|
let fromDynamicBytes: bytesHex => hex = bytes => bytes->(Utils.magic: bytesHex => hex)->keccak256
|
|
25
25
|
let fromBytes: bytesHex => hex = bytes =>
|
|
26
|
-
bytes->(Utils.magic: bytesHex =>
|
|
26
|
+
bytes->(Utils.magic: bytesHex => Uint8Array.t)->Viem.bytesToHex(~options={size: 32})
|
|
27
27
|
let fromBool: bool => hex = b => b->Viem.boolToHex(~options={size: 32})
|