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
package/src/Hasura.res.mjs
CHANGED
|
@@ -6,93 +6,90 @@ import * as Table from "./db/Table.res.mjs";
|
|
|
6
6
|
import * as Utils from "./Utils.res.mjs";
|
|
7
7
|
import * as Schema from "./db/Schema.res.mjs";
|
|
8
8
|
import * as Logging from "./Logging.res.mjs";
|
|
9
|
-
import * as Belt_Array from "rescript/lib/es6/
|
|
9
|
+
import * as Belt_Array from "@rescript/runtime/lib/es6/Belt_Array.js";
|
|
10
10
|
import * as InternalTable from "./db/InternalTable.res.mjs";
|
|
11
11
|
import * as S$RescriptSchema from "rescript-schema/src/S.res.mjs";
|
|
12
|
-
import * as
|
|
12
|
+
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
|
|
13
13
|
|
|
14
14
|
function auth(s) {
|
|
15
15
|
return {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
role: s.header("X-Hasura-Role", S$RescriptSchema.string),
|
|
17
|
+
secret: s.header("X-Hasura-Admin-Secret", S$RescriptSchema.string)
|
|
18
|
+
};
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
21
|
+
let responses = [
|
|
22
|
+
s => {
|
|
23
|
+
s.status(200);
|
|
24
|
+
s.data(S$RescriptSchema.unknown);
|
|
25
|
+
return "QuerySucceeded";
|
|
26
|
+
},
|
|
27
|
+
s => {
|
|
28
|
+
s.field("code", S$RescriptSchema.$$enum([
|
|
29
|
+
"already-exists",
|
|
30
|
+
"already-tracked"
|
|
31
|
+
]));
|
|
32
|
+
return "AlreadyDone";
|
|
33
|
+
}
|
|
34
34
|
];
|
|
35
35
|
|
|
36
36
|
function clearMetadataRoute() {
|
|
37
37
|
return {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
38
|
+
method: "POST",
|
|
39
|
+
path: "",
|
|
40
|
+
input: s => {
|
|
41
|
+
s.field("type", S$RescriptSchema.literal("clear_metadata"));
|
|
42
|
+
s.field("args", S$RescriptSchema.literal({}));
|
|
43
|
+
return auth(s);
|
|
44
|
+
},
|
|
45
|
+
responses: responses
|
|
46
|
+
};
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
function trackTablesRoute() {
|
|
50
50
|
return {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
51
|
+
method: "POST",
|
|
52
|
+
path: "",
|
|
53
|
+
input: s => {
|
|
54
|
+
s.field("type", S$RescriptSchema.literal("pg_track_tables"));
|
|
55
|
+
return {
|
|
56
|
+
args: s.field("args", S$RescriptSchema.json(false)),
|
|
57
|
+
auth: auth(s)
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
responses: responses
|
|
61
|
+
};
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
function rawBodyRoute() {
|
|
65
65
|
return {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
responses: responses
|
|
75
|
-
};
|
|
66
|
+
method: "POST",
|
|
67
|
+
path: "",
|
|
68
|
+
input: s => ({
|
|
69
|
+
bodyString: s.rawBody(S$RescriptSchema.string),
|
|
70
|
+
auth: auth(s)
|
|
71
|
+
}),
|
|
72
|
+
responses: responses
|
|
73
|
+
};
|
|
76
74
|
}
|
|
77
75
|
|
|
78
76
|
async function sendOperation(endpoint, auth, operation) {
|
|
79
|
-
|
|
77
|
+
let retry = async attempt => {
|
|
80
78
|
try {
|
|
81
|
-
await Rest
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
return
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
|
|
79
|
+
await Rest.fetch(rawBodyRoute, {
|
|
80
|
+
bodyString: JSON.stringify(operation),
|
|
81
|
+
auth: auth
|
|
82
|
+
}, Rest.client(endpoint, undefined));
|
|
83
|
+
return;
|
|
84
|
+
} catch (raw_exn) {
|
|
85
|
+
let exn = Primitive_exceptions.internalToException(raw_exn);
|
|
89
86
|
if (attempt >= 3) {
|
|
90
87
|
return Logging.warn({
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
88
|
+
msg: "Hasura configuration request failed. Indexing will still work - but you may have issues querying data via GraphQL.",
|
|
89
|
+
err: Utils.prettifyExn(exn)
|
|
90
|
+
});
|
|
94
91
|
}
|
|
95
|
-
|
|
92
|
+
let backoffMs = (Math.pow(2.0, attempt) | 0) * 1000 | 0;
|
|
96
93
|
await Time.resolvePromiseAfterDelay(backoffMs);
|
|
97
94
|
return await retry(attempt + 1 | 0);
|
|
98
95
|
}
|
|
@@ -102,134 +99,128 @@ async function sendOperation(endpoint, auth, operation) {
|
|
|
102
99
|
|
|
103
100
|
async function clearHasuraMetadata(endpoint, auth) {
|
|
104
101
|
try {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
return Logging.trace(
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
|
|
102
|
+
let result = await Rest.fetch(clearMetadataRoute, auth, Rest.client(endpoint, undefined));
|
|
103
|
+
let tmp;
|
|
104
|
+
tmp = result === "QuerySucceeded" ? "Hasura metadata cleared" : "Hasura metadata already cleared";
|
|
105
|
+
return Logging.trace(tmp);
|
|
106
|
+
} catch (raw_exn) {
|
|
107
|
+
let exn = Primitive_exceptions.internalToException(raw_exn);
|
|
112
108
|
return Logging.error({
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
109
|
+
msg: `There was an issue clearing metadata in hasura - indexing may still work - but you may have issues querying the data in hasura.`,
|
|
110
|
+
err: Utils.prettifyExn(exn)
|
|
111
|
+
});
|
|
116
112
|
}
|
|
117
113
|
}
|
|
118
114
|
|
|
119
115
|
async function trackTables(endpoint, auth, pgSchema, tableNames) {
|
|
120
116
|
try {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
custom_name: tableName
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
})
|
|
117
|
+
let result = await Rest.fetch(trackTablesRoute, {
|
|
118
|
+
auth: auth,
|
|
119
|
+
args: {
|
|
120
|
+
allow_warnings: false,
|
|
121
|
+
tables: tableNames.map(tableName => ({
|
|
122
|
+
table: {
|
|
123
|
+
name: tableName,
|
|
124
|
+
schema: pgSchema
|
|
125
|
+
},
|
|
126
|
+
configuration: {
|
|
127
|
+
custom_name: tableName
|
|
136
128
|
}
|
|
137
|
-
}
|
|
138
|
-
|
|
129
|
+
}))
|
|
130
|
+
}
|
|
131
|
+
}, Rest.client(endpoint, undefined));
|
|
132
|
+
let msg;
|
|
139
133
|
msg = result === "QuerySucceeded" ? "Hasura finished tracking tables" : "Hasura tables already tracked";
|
|
140
134
|
return Logging.trace({
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
|
|
135
|
+
msg: msg,
|
|
136
|
+
tableNames: tableNames
|
|
137
|
+
});
|
|
138
|
+
} catch (raw_exn) {
|
|
139
|
+
let exn = Primitive_exceptions.internalToException(raw_exn);
|
|
147
140
|
return Logging.error({
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
141
|
+
msg: `There was an issue tracking tables in hasura - indexing may still work - but you may have issues querying the data in hasura.`,
|
|
142
|
+
tableNames: tableNames,
|
|
143
|
+
err: Utils.prettifyExn(exn)
|
|
144
|
+
});
|
|
152
145
|
}
|
|
153
146
|
}
|
|
154
147
|
|
|
155
148
|
async function createSelectPermission(endpoint, auth, tableName, pgSchema, responseLimit, aggregateEntities) {
|
|
156
149
|
return await sendOperation(endpoint, auth, {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
150
|
+
type: "pg_create_select_permission",
|
|
151
|
+
args: {
|
|
152
|
+
table: {
|
|
153
|
+
schema: pgSchema,
|
|
154
|
+
name: tableName
|
|
155
|
+
},
|
|
156
|
+
role: "public",
|
|
157
|
+
source: "default",
|
|
158
|
+
permission: {
|
|
159
|
+
columns: "*",
|
|
160
|
+
filter: {},
|
|
161
|
+
limit: responseLimit,
|
|
162
|
+
allow_aggregations: aggregateEntities.includes(tableName)
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
});
|
|
173
166
|
}
|
|
174
167
|
|
|
175
168
|
async function createEntityRelationship(endpoint, auth, pgSchema, tableName, relationshipType, relationalKey, objectName, mappedEntity, isDerivedFrom) {
|
|
176
|
-
|
|
169
|
+
let derivedFromTo = isDerivedFrom ? `"id": "` + relationalKey + `"` : `"` + relationalKey + `_id" : "id"`;
|
|
177
170
|
return await sendOperation(endpoint, auth, {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
171
|
+
type: `pg_create_` + relationshipType + `_relationship`,
|
|
172
|
+
args: {
|
|
173
|
+
table: {
|
|
174
|
+
schema: pgSchema,
|
|
175
|
+
name: tableName
|
|
176
|
+
},
|
|
177
|
+
name: objectName,
|
|
178
|
+
source: "default",
|
|
179
|
+
using: {
|
|
180
|
+
manual_configuration: {
|
|
181
|
+
remote_table: {
|
|
182
|
+
schema: pgSchema,
|
|
183
|
+
name: mappedEntity
|
|
184
|
+
},
|
|
185
|
+
column_mapping: JSON.parse(`{` + derivedFromTo + `}`)
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
});
|
|
197
190
|
}
|
|
198
191
|
|
|
199
192
|
async function trackDatabase(endpoint, auth, pgSchema, userEntities, aggregateEntities, responseLimit, schema) {
|
|
200
|
-
|
|
193
|
+
let exposedInternalTableNames = [
|
|
201
194
|
InternalTable.RawEvents.table.tableName,
|
|
202
195
|
InternalTable.Views.metaViewName,
|
|
203
196
|
InternalTable.Views.chainMetadataViewName
|
|
204
197
|
];
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
userTableNames
|
|
211
|
-
]);
|
|
198
|
+
let userTableNames = userEntities.map(entity => entity.table.tableName);
|
|
199
|
+
let tableNames = Belt_Array.concatMany([
|
|
200
|
+
exposedInternalTableNames,
|
|
201
|
+
userTableNames
|
|
202
|
+
]);
|
|
212
203
|
Logging.info("Tracking tables in Hasura");
|
|
213
204
|
await clearHasuraMetadata(endpoint, auth);
|
|
214
205
|
await trackTables(endpoint, auth, pgSchema, tableNames);
|
|
215
|
-
for(
|
|
216
|
-
|
|
206
|
+
for (let i = 0, i_finish = tableNames.length; i < i_finish; ++i) {
|
|
207
|
+
let tableName = tableNames[i];
|
|
217
208
|
await createSelectPermission(endpoint, auth, tableName, pgSchema, responseLimit, aggregateEntities);
|
|
218
209
|
}
|
|
219
|
-
for(
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
for(
|
|
225
|
-
|
|
226
|
-
|
|
210
|
+
for (let i$1 = 0, i_finish$1 = userEntities.length; i$1 < i_finish$1; ++i$1) {
|
|
211
|
+
let entityConfig = userEntities[i$1];
|
|
212
|
+
let match = entityConfig.table;
|
|
213
|
+
let tableName$1 = match.tableName;
|
|
214
|
+
let derivedFromFields = Table.getDerivedFromFields(entityConfig.table);
|
|
215
|
+
for (let j = 0, j_finish = derivedFromFields.length; j < j_finish; ++j) {
|
|
216
|
+
let derivedFromField = derivedFromFields[j];
|
|
217
|
+
let relationalFieldName = Utils.unwrapResultExn(Schema.getDerivedFromFieldName(schema, derivedFromField));
|
|
227
218
|
await createEntityRelationship(endpoint, auth, pgSchema, tableName$1, "array", relationalFieldName, derivedFromField.fieldName, derivedFromField.derivedFromEntity, true);
|
|
228
219
|
}
|
|
229
|
-
|
|
230
|
-
for(
|
|
231
|
-
|
|
232
|
-
|
|
220
|
+
let linkedEntityFields = Table.getLinkedEntityFields(entityConfig.table);
|
|
221
|
+
for (let j$1 = 0, j_finish$1 = linkedEntityFields.length; j$1 < j_finish$1; ++j$1) {
|
|
222
|
+
let match$1 = linkedEntityFields[j$1];
|
|
223
|
+
let field = match$1[0];
|
|
233
224
|
await createEntityRelationship(endpoint, auth, pgSchema, tableName$1, "object", field.fieldName, field.fieldName, match$1[1], false);
|
|
234
225
|
}
|
|
235
226
|
}
|
|
@@ -237,16 +228,16 @@ async function trackDatabase(endpoint, auth, pgSchema, userEntities, aggregateEn
|
|
|
237
228
|
}
|
|
238
229
|
|
|
239
230
|
export {
|
|
240
|
-
auth
|
|
241
|
-
responses
|
|
242
|
-
clearMetadataRoute
|
|
243
|
-
trackTablesRoute
|
|
244
|
-
rawBodyRoute
|
|
245
|
-
sendOperation
|
|
246
|
-
clearHasuraMetadata
|
|
247
|
-
trackTables
|
|
248
|
-
createSelectPermission
|
|
249
|
-
createEntityRelationship
|
|
250
|
-
trackDatabase
|
|
231
|
+
auth,
|
|
232
|
+
responses,
|
|
233
|
+
clearMetadataRoute,
|
|
234
|
+
trackTablesRoute,
|
|
235
|
+
rawBodyRoute,
|
|
236
|
+
sendOperation,
|
|
237
|
+
clearHasuraMetadata,
|
|
238
|
+
trackTables,
|
|
239
|
+
createSelectPermission,
|
|
240
|
+
createEntityRelationship,
|
|
241
|
+
trackDatabase,
|
|
251
242
|
}
|
|
252
243
|
/* Rest Not a pure module */
|
package/src/InMemoryStore.res
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
@genType
|
|
2
1
|
type rawEventsKey = {
|
|
3
2
|
chainId: int,
|
|
4
3
|
eventId: string,
|
|
@@ -11,9 +10,9 @@ module EntityTables = {
|
|
|
11
10
|
type t = dict<InMemoryTable.Entity.t<Internal.entity>>
|
|
12
11
|
exception UndefinedEntity({entityName: string})
|
|
13
12
|
let make = (entities: array<Internal.entityConfig>): t => {
|
|
14
|
-
let init =
|
|
13
|
+
let init = Dict.make()
|
|
15
14
|
entities->Belt.Array.forEach(entityConfig => {
|
|
16
|
-
init->
|
|
15
|
+
init->Dict.set((entityConfig.name :> string), InMemoryTable.Entity.make())
|
|
17
16
|
})
|
|
18
17
|
init
|
|
19
18
|
}
|
|
@@ -34,9 +33,9 @@ module EntityTables = {
|
|
|
34
33
|
|
|
35
34
|
let clone = (self: t) => {
|
|
36
35
|
self
|
|
37
|
-
->
|
|
36
|
+
->Dict.toArray
|
|
38
37
|
->Belt.Array.map(((k, v)) => (k, v->InMemoryTable.Entity.clone))
|
|
39
|
-
->
|
|
38
|
+
->Dict.fromArray
|
|
40
39
|
}
|
|
41
40
|
}
|
|
42
41
|
|
|
@@ -57,19 +56,19 @@ type t = {
|
|
|
57
56
|
let make = (~entities: array<Internal.entityConfig>, ~rollbackTargetCheckpointId=?): t => {
|
|
58
57
|
rawEvents: InMemoryTable.make(~hash=hashRawEventsKey),
|
|
59
58
|
entities: EntityTables.make(entities),
|
|
60
|
-
effects:
|
|
59
|
+
effects: Dict.make(),
|
|
61
60
|
rollbackTargetCheckpointId,
|
|
62
61
|
}
|
|
63
62
|
|
|
64
63
|
let clone = (self: t) => {
|
|
65
64
|
rawEvents: self.rawEvents->InMemoryTable.clone,
|
|
66
65
|
entities: self.entities->EntityTables.clone,
|
|
67
|
-
effects:
|
|
66
|
+
effects: Dict.mapValues(self.effects, table => {
|
|
68
67
|
idsToStore: table.idsToStore->Array.copy,
|
|
69
68
|
invalidationsCount: table.invalidationsCount,
|
|
70
69
|
dict: table.dict->Utils.Dict.shallowCopy,
|
|
71
70
|
effect: table.effect,
|
|
72
|
-
}
|
|
71
|
+
}),
|
|
73
72
|
rollbackTargetCheckpointId: self.rollbackTargetCheckpointId,
|
|
74
73
|
}
|
|
75
74
|
|
|
@@ -80,11 +79,11 @@ let getEffectInMemTable = (inMemoryStore: t, ~effect: Internal.effect) => {
|
|
|
80
79
|
| None =>
|
|
81
80
|
let table = {
|
|
82
81
|
idsToStore: [],
|
|
83
|
-
dict:
|
|
82
|
+
dict: Dict.make(),
|
|
84
83
|
invalidationsCount: 0,
|
|
85
84
|
effect,
|
|
86
85
|
}
|
|
87
|
-
inMemoryStore.effects->
|
|
86
|
+
inMemoryStore.effects->Dict.set(key, table)
|
|
88
87
|
table
|
|
89
88
|
}
|
|
90
89
|
}
|
|
@@ -100,43 +99,37 @@ let isRollingBack = (inMemoryStore: t) => inMemoryStore.rollbackTargetCheckpoint
|
|
|
100
99
|
|
|
101
100
|
let setBatchDcs = (inMemoryStore: t, ~batch: Batch.t, ~shouldSaveHistory) => {
|
|
102
101
|
let inMemTable =
|
|
103
|
-
inMemoryStore->getInMemTable(~entityConfig=InternalTable.
|
|
102
|
+
inMemoryStore->getInMemTable(~entityConfig=InternalTable.EnvioAddresses.entityConfig)
|
|
104
103
|
|
|
105
104
|
let itemIdx = ref(0)
|
|
106
105
|
|
|
107
106
|
for checkpoint in 0 to batch.checkpointIds->Array.length - 1 {
|
|
108
|
-
let checkpointId = batch.checkpointIds->
|
|
109
|
-
let chainId = batch.checkpointChainIds->
|
|
110
|
-
let checkpointEventsProcessed =
|
|
111
|
-
batch.checkpointEventsProcessed->Js.Array2.unsafe_get(checkpoint)
|
|
107
|
+
let checkpointId = batch.checkpointIds->Array.getUnsafe(checkpoint)
|
|
108
|
+
let chainId = batch.checkpointChainIds->Array.getUnsafe(checkpoint)
|
|
109
|
+
let checkpointEventsProcessed = batch.checkpointEventsProcessed->Array.getUnsafe(checkpoint)
|
|
112
110
|
|
|
113
111
|
for idx in 0 to checkpointEventsProcessed - 1 {
|
|
114
|
-
let item = batch.items->
|
|
112
|
+
let item = batch.items->Array.getUnsafe(itemIdx.contents + idx)
|
|
115
113
|
switch item->Internal.getItemDcs {
|
|
116
114
|
| None => ()
|
|
117
115
|
| Some(dcs) =>
|
|
118
116
|
// Currently only events support contract registration, so we can cast to event item
|
|
119
117
|
let eventItem = item->Internal.castUnsafeEventItem
|
|
120
118
|
for dcIdx in 0 to dcs->Array.length - 1 {
|
|
121
|
-
let dc = dcs->
|
|
122
|
-
let entity: InternalTable.
|
|
123
|
-
id: InternalTable.
|
|
119
|
+
let dc = dcs->Array.getUnsafe(dcIdx)
|
|
120
|
+
let entity: InternalTable.EnvioAddresses.t = {
|
|
121
|
+
id: InternalTable.EnvioAddresses.makeId(~chainId, ~address=dc.address),
|
|
124
122
|
chainId,
|
|
125
|
-
contractAddress: dc.address,
|
|
126
123
|
contractName: dc.contractName,
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
registeringEventBlockTimestamp: eventItem.timestamp,
|
|
130
|
-
registeringEventContractName: eventItem.eventConfig.contractName,
|
|
131
|
-
registeringEventName: eventItem.eventConfig.name,
|
|
132
|
-
registeringEventSrcAddress: eventItem.event.srcAddress,
|
|
124
|
+
registrationBlock: eventItem.blockNumber,
|
|
125
|
+
registrationLogIndex: eventItem.logIndex,
|
|
133
126
|
}
|
|
134
127
|
|
|
135
128
|
inMemTable->InMemoryTable.Entity.set(
|
|
136
129
|
Set({
|
|
137
130
|
entityId: entity.id,
|
|
138
131
|
checkpointId,
|
|
139
|
-
entity: entity->InternalTable.
|
|
132
|
+
entity: entity->InternalTable.EnvioAddresses.castToInternal,
|
|
140
133
|
}),
|
|
141
134
|
~shouldSaveHistory,
|
|
142
135
|
)
|