envio 2.32.3 → 3.0.0-alpha.0
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.js +5 -3
- package/evm.schema.json +23 -6
- package/fuel.schema.json +17 -5
- package/index.d.ts +1 -27
- package/index.js +9 -6
- package/package.json +12 -7
- package/rescript.json +4 -3
- package/src/{Address.res.js → Address.res.mjs} +7 -6
- package/src/Batch.res +4 -4
- package/src/{Batch.res.js → Batch.res.mjs} +19 -18
- package/src/{ChainMap.res.js → ChainMap.res.mjs} +20 -19
- package/src/Change.res +9 -0
- package/src/Config.res +5 -5
- package/src/{Config.res.js → Config.res.mjs} +13 -10
- package/src/Envio.gen.ts +4 -17
- package/src/Envio.res +13 -38
- package/src/{Envio.res.js → Envio.res.mjs} +5 -16
- package/src/{ErrorHandling.res.js → ErrorHandling.res.mjs} +10 -9
- package/src/EventRegister.res +10 -11
- package/src/{EventRegister.res.js → EventRegister.res.mjs} +33 -26
- package/src/EventRegister.resi +2 -1
- package/src/{EventUtils.res.js → EventUtils.res.mjs} +10 -9
- package/src/{EvmTypes.res.js → EvmTypes.res.mjs} +5 -4
- package/src/{FetchState.res.js → FetchState.res.mjs} +44 -43
- package/src/{Hasura.res.js → Hasura.res.mjs} +25 -24
- package/src/InMemoryStore.res +7 -15
- package/src/{InMemoryStore.res.js → InMemoryStore.res.mjs} +21 -22
- package/src/InMemoryTable.res +50 -35
- package/src/{InMemoryTable.res.js → InMemoryTable.res.mjs} +73 -104
- package/src/Internal.gen.ts +1 -5
- package/src/Internal.res +29 -40
- package/src/Internal.res.mjs +58 -0
- package/src/{LazyLoader.res.js → LazyLoader.res.mjs} +14 -13
- package/src/{LoadManager.res.js → LoadManager.res.mjs} +11 -10
- package/src/{LogSelection.res.js → LogSelection.res.mjs} +14 -13
- package/src/{Logging.res.js → Logging.res.mjs} +37 -36
- package/src/Persistence.res +190 -38
- package/src/Persistence.res.mjs +213 -0
- package/src/PgStorage.res +700 -14
- package/src/{PgStorage.res.js → PgStorage.res.mjs} +478 -65
- package/src/Platform.res +140 -0
- package/src/Platform.res.mjs +170 -0
- package/src/Prometheus.res +41 -0
- package/src/{Prometheus.res.js → Prometheus.res.mjs} +106 -60
- package/src/{ReorgDetection.res.js → ReorgDetection.res.mjs} +12 -11
- package/src/SafeCheckpointTracking.res +5 -4
- package/src/{SafeCheckpointTracking.res.js → SafeCheckpointTracking.res.mjs} +6 -5
- package/src/Sink.res +47 -0
- package/src/Sink.res.mjs +37 -0
- package/src/{TableIndices.res.js → TableIndices.res.mjs} +8 -7
- package/src/{Throttler.res.js → Throttler.res.mjs} +7 -6
- package/src/{Time.res.js → Time.res.mjs} +8 -7
- package/src/{TopicFilter.res.js → TopicFilter.res.mjs} +18 -17
- package/src/Utils.res +42 -0
- package/src/{Utils.res.js → Utils.res.mjs} +71 -34
- package/src/bindings/BigDecimal.gen.ts +2 -2
- package/src/bindings/BigDecimal.res +5 -5
- package/src/bindings/BigDecimal.res.d.mts +5 -0
- package/src/bindings/{BigDecimal.res.js → BigDecimal.res.mjs} +10 -9
- package/src/bindings/BigInt.gen.ts +2 -2
- package/src/bindings/BigInt.res.d.mts +5 -0
- package/src/bindings/{BigInt.res.js → BigInt.res.mjs} +25 -24
- package/src/bindings/ClickHouse.res +387 -0
- package/src/bindings/ClickHouse.res.mjs +275 -0
- package/src/bindings/Ethers.gen.ts +2 -2
- package/src/bindings/Ethers.res.d.mts +5 -0
- package/src/bindings/{Ethers.res.js → Ethers.res.mjs} +18 -17
- package/src/bindings/Express.res.mjs +2 -0
- package/src/bindings/{Hrtime.res.js → Hrtime.res.mjs} +13 -12
- package/src/bindings/{Lodash.res.js → Lodash.res.mjs} +4 -3
- package/src/bindings/NodeJs.res +13 -1
- package/src/bindings/NodeJs.res.mjs +48 -0
- package/src/bindings/Pino.res +4 -4
- package/src/bindings/{Pino.res.js → Pino.res.mjs} +16 -15
- package/src/bindings/Postgres.res +17 -2
- package/src/bindings/{Postgres.res.js → Postgres.res.mjs} +4 -3
- package/src/bindings/{PromClient.res.js → PromClient.res.mjs} +6 -5
- package/src/bindings/{Promise.res.js → Promise.res.mjs} +6 -5
- package/src/bindings/{SDSL.res.js → SDSL.res.mjs} +3 -2
- package/src/bindings/{Viem.res.js → Viem.res.mjs} +9 -8
- package/src/bindings/vendored-lodash-fns.js +3 -35
- package/src/db/EntityHistory.res +33 -156
- package/src/db/EntityHistory.res.mjs +121 -0
- package/src/db/InternalTable.gen.ts +2 -2
- package/src/db/InternalTable.res +55 -56
- package/src/db/{InternalTable.res.js → InternalTable.res.mjs} +68 -71
- package/src/db/{Schema.res.js → Schema.res.mjs} +10 -9
- package/src/db/Table.res +86 -22
- package/src/db/{Table.res.js → Table.res.mjs} +108 -40
- package/src/sources/{EventRouter.res.js → EventRouter.res.mjs} +17 -16
- package/src/sources/{Fuel.res.js → Fuel.res.mjs} +6 -5
- package/src/sources/{HyperFuel.res.js → HyperFuel.res.mjs} +14 -13
- package/src/sources/{HyperFuelClient.res.js → HyperFuelClient.res.mjs} +7 -6
- package/src/sources/{HyperFuelSource.res.js → HyperFuelSource.res.mjs} +28 -27
- package/src/sources/{HyperSync.res.js → HyperSync.res.mjs} +21 -20
- package/src/sources/HyperSyncClient.gen.ts +1 -1
- package/src/sources/HyperSyncClient.res +78 -20
- package/src/sources/{HyperSyncClient.res.js → HyperSyncClient.res.mjs} +32 -15
- package/src/sources/{HyperSyncJsonApi.res.js → HyperSyncJsonApi.res.mjs} +10 -9
- package/src/sources/HyperSyncSource.res +77 -9
- package/src/sources/{HyperSyncSource.res.js → HyperSyncSource.res.mjs} +99 -38
- package/src/sources/{Rpc.res.js → Rpc.res.mjs} +16 -15
- package/src/sources/{RpcSource.res.js → RpcSource.res.mjs} +40 -39
- package/src/sources/Source.res +1 -1
- package/src/sources/{Source.res.js → Source.res.mjs} +4 -3
- package/src/sources/SourceManager.res +12 -1
- package/src/sources/{SourceManager.res.js → SourceManager.res.mjs} +32 -21
- package/src/sources/vendored-fuel-abi-coder.js +94 -149
- package/src/vendored/{Rest.res.js → Rest.res.mjs} +12 -11
- package/src/Internal.res.js +0 -62
- package/src/Persistence.res.js +0 -159
- package/src/bindings/NodeJs.res.js +0 -35
- package/src/db/EntityHistory.res.js +0 -195
- /package/src/{Indexer.res.js → Change.res.mjs} +0 -0
- /package/src/{bindings/Express.res.js → Indexer.res.mjs} +0 -0
package/src/InMemoryTable.res
CHANGED
|
@@ -39,7 +39,8 @@ module Entity = {
|
|
|
39
39
|
type indexFieldNameToIndices = t<TableIndices.Index.t, indicesSerializedToValue>
|
|
40
40
|
|
|
41
41
|
type entityWithIndices<'entity> = {
|
|
42
|
-
|
|
42
|
+
latest: option<'entity>,
|
|
43
|
+
status: Internal.inMemoryStoreEntityStatus<'entity>,
|
|
43
44
|
entityIndices: Utils.Set.t<TableIndices.Index.t>,
|
|
44
45
|
}
|
|
45
46
|
type t<'entity> = {
|
|
@@ -147,18 +148,20 @@ module Entity = {
|
|
|
147
148
|
//or if allowOverWriteEntity is true (used for mockDb in test helpers)
|
|
148
149
|
if shouldWriteEntity {
|
|
149
150
|
let entityIndices = Utils.Set.make()
|
|
150
|
-
|
|
151
|
+
switch entity {
|
|
151
152
|
| Some(entity) =>
|
|
152
153
|
//update table indices in the case where there
|
|
153
154
|
//is an already set entity
|
|
154
155
|
inMemTable->updateIndices(~entity, ~entityIndices)
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
| None => InitialReadFromDb(NotSet)
|
|
156
|
+
| None => ()
|
|
158
157
|
}
|
|
159
158
|
inMemTable.table.dict->Js.Dict.set(
|
|
160
159
|
key->inMemTable.table.hash,
|
|
161
|
-
{
|
|
160
|
+
{
|
|
161
|
+
latest: entity,
|
|
162
|
+
status: Loaded,
|
|
163
|
+
entityIndices,
|
|
164
|
+
},
|
|
162
165
|
)
|
|
163
166
|
}
|
|
164
167
|
}
|
|
@@ -166,56 +169,64 @@ module Entity = {
|
|
|
166
169
|
let setRow = set
|
|
167
170
|
let set = (
|
|
168
171
|
inMemTable: t<'entity>,
|
|
169
|
-
|
|
172
|
+
change: Change.t<'entity>,
|
|
170
173
|
~shouldSaveHistory,
|
|
171
174
|
~containsRollbackDiffChange=false,
|
|
172
175
|
) => {
|
|
173
176
|
//New entity row with only the latest update
|
|
174
177
|
@inline
|
|
175
|
-
let
|
|
176
|
-
|
|
177
|
-
history: shouldSaveHistory
|
|
178
|
+
let newStatus = () => Internal.Updated({
|
|
179
|
+
latestChange: change,
|
|
180
|
+
history: shouldSaveHistory
|
|
181
|
+
? [change]
|
|
182
|
+
: Utils.Array.immutableEmpty->(Utils.magic: array<unknown> => array<Change.t<'entity>>),
|
|
178
183
|
containsRollbackDiffChange,
|
|
179
184
|
})
|
|
185
|
+
let latest = switch change {
|
|
186
|
+
| Set({entity}) => Some(entity)
|
|
187
|
+
| Delete(_) => None
|
|
188
|
+
}
|
|
180
189
|
|
|
181
|
-
let
|
|
182
|
-
| None => {
|
|
183
|
-
| Some({
|
|
184
|
-
|
|
190
|
+
let updatedEntityRecord = switch inMemTable.table->get(change->Change.getEntityId) {
|
|
191
|
+
| None => {latest, status: newStatus(), entityIndices: Utils.Set.make()}
|
|
192
|
+
| Some({status: Loaded, entityIndices}) => {
|
|
193
|
+
latest,
|
|
194
|
+
status: newStatus(),
|
|
185
195
|
entityIndices,
|
|
186
196
|
}
|
|
187
|
-
| Some({
|
|
188
|
-
let
|
|
189
|
-
|
|
197
|
+
| Some({status: Updated(previous_values), entityIndices}) =>
|
|
198
|
+
let newStatus = Internal.Updated({
|
|
199
|
+
latestChange: change,
|
|
190
200
|
history: switch shouldSaveHistory {
|
|
191
201
|
// This prevents two db actions in the same event on the same entity from being recorded to the history table.
|
|
192
|
-
| true
|
|
202
|
+
| true
|
|
203
|
+
if previous_values.latestChange->Change.getCheckpointId ===
|
|
204
|
+
change->Change.getCheckpointId =>
|
|
193
205
|
previous_values.history->Utils.Array.setIndexImmutable(
|
|
194
206
|
previous_values.history->Array.length - 1,
|
|
195
|
-
|
|
207
|
+
change,
|
|
196
208
|
)
|
|
197
|
-
| true => [...previous_values.history,
|
|
209
|
+
| true => [...previous_values.history, change]
|
|
198
210
|
| false => previous_values.history
|
|
199
211
|
},
|
|
200
212
|
containsRollbackDiffChange: previous_values.containsRollbackDiffChange,
|
|
201
213
|
})
|
|
202
|
-
{
|
|
214
|
+
{latest, status: newStatus, entityIndices}
|
|
203
215
|
}
|
|
204
216
|
|
|
205
|
-
switch
|
|
206
|
-
| Set(entity) =>
|
|
207
|
-
|
|
217
|
+
switch change {
|
|
218
|
+
| Set({entity}) =>
|
|
219
|
+
inMemTable->updateIndices(~entity, ~entityIndices=updatedEntityRecord.entityIndices)
|
|
220
|
+
| Delete({entityId}) =>
|
|
221
|
+
inMemTable->deleteEntityFromIndices(
|
|
222
|
+
~entityId,
|
|
223
|
+
~entityIndices=updatedEntityRecord.entityIndices,
|
|
224
|
+
)
|
|
208
225
|
}
|
|
209
|
-
inMemTable.table->setRow(
|
|
226
|
+
inMemTable.table->setRow(change->Change.getEntityId, updatedEntityRecord)
|
|
210
227
|
}
|
|
211
228
|
|
|
212
|
-
let rowToEntity = row =>
|
|
213
|
-
switch row.entityRow {
|
|
214
|
-
| Internal.Updated({latest: {entityUpdateAction: Set(entity)}}) => Some(entity)
|
|
215
|
-
| Updated({latest: {entityUpdateAction: Delete}}) => None
|
|
216
|
-
| InitialReadFromDb(AlreadySet(entity)) => Some(entity)
|
|
217
|
-
| InitialReadFromDb(NotSet) => None
|
|
218
|
-
}
|
|
229
|
+
let rowToEntity = row => row.latest
|
|
219
230
|
|
|
220
231
|
let getRow = get
|
|
221
232
|
|
|
@@ -330,10 +341,15 @@ module Entity = {
|
|
|
330
341
|
}
|
|
331
342
|
}
|
|
332
343
|
|
|
333
|
-
let
|
|
344
|
+
let updates = (inMemTable: t<'entity>) => {
|
|
334
345
|
inMemTable.table
|
|
335
346
|
->values
|
|
336
|
-
->Array.
|
|
347
|
+
->Array.keepMapU(v =>
|
|
348
|
+
switch v.status {
|
|
349
|
+
| Updated(update) => Some(update)
|
|
350
|
+
| Loaded => None
|
|
351
|
+
}
|
|
352
|
+
)
|
|
337
353
|
}
|
|
338
354
|
|
|
339
355
|
let values = (inMemTable: t<'entity>) => {
|
|
@@ -353,4 +369,3 @@ module Entity = {
|
|
|
353
369
|
},
|
|
354
370
|
}
|
|
355
371
|
}
|
|
356
|
-
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
-
'use strict';
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
3
|
+
import * as Utils from "./Utils.res.mjs";
|
|
4
|
+
import * as Js_exn from "rescript/lib/es6/js_exn.js";
|
|
5
|
+
import * as Lodash from "./bindings/Lodash.res.mjs";
|
|
6
|
+
import * as Js_dict from "rescript/lib/es6/js_dict.js";
|
|
7
|
+
import * as Belt_Array from "rescript/lib/es6/belt_Array.js";
|
|
8
|
+
import * as Belt_Option from "rescript/lib/es6/belt_Option.js";
|
|
9
|
+
import * as Caml_option from "rescript/lib/es6/caml_option.js";
|
|
10
|
+
import * as TableIndices from "./TableIndices.res.mjs";
|
|
11
|
+
import * as ErrorHandling from "./ErrorHandling.res.mjs";
|
|
12
|
+
import * as Caml_exceptions from "rescript/lib/es6/caml_exceptions.js";
|
|
14
13
|
|
|
15
14
|
function make(hash) {
|
|
16
15
|
return {
|
|
@@ -147,114 +146,77 @@ function initValue(inMemTable, key, entity, allowOverWriteEntityOpt) {
|
|
|
147
146
|
return ;
|
|
148
147
|
}
|
|
149
148
|
var entityIndices = new Set();
|
|
150
|
-
var initialStoreRow;
|
|
151
149
|
if (entity !== undefined) {
|
|
152
|
-
|
|
153
|
-
updateIndices(inMemTable, entity$1, entityIndices);
|
|
154
|
-
initialStoreRow = {
|
|
155
|
-
TAG: "InitialReadFromDb",
|
|
156
|
-
_0: {
|
|
157
|
-
TAG: "AlreadySet",
|
|
158
|
-
_0: entity$1
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
} else {
|
|
162
|
-
initialStoreRow = {
|
|
163
|
-
TAG: "InitialReadFromDb",
|
|
164
|
-
_0: "NotSet"
|
|
165
|
-
};
|
|
150
|
+
updateIndices(inMemTable, Caml_option.valFromOption(entity), entityIndices);
|
|
166
151
|
}
|
|
167
152
|
inMemTable.table.dict[inMemTable.table.hash(key)] = {
|
|
168
|
-
|
|
153
|
+
latest: entity,
|
|
154
|
+
status: "Loaded",
|
|
169
155
|
entityIndices: entityIndices
|
|
170
156
|
};
|
|
171
157
|
}
|
|
172
158
|
|
|
173
|
-
function set$1(inMemTable,
|
|
159
|
+
function set$1(inMemTable, change, shouldSaveHistory, containsRollbackDiffChangeOpt) {
|
|
174
160
|
var containsRollbackDiffChange = containsRollbackDiffChangeOpt !== undefined ? containsRollbackDiffChangeOpt : false;
|
|
175
|
-
var
|
|
176
|
-
|
|
161
|
+
var latest;
|
|
162
|
+
latest = change.type === "SET" ? Caml_option.some(change.entity) : undefined;
|
|
163
|
+
var match = get(inMemTable.table, change.entityId);
|
|
164
|
+
var updatedEntityRecord;
|
|
177
165
|
if (match !== undefined) {
|
|
178
|
-
var previous_values = match.
|
|
179
|
-
if (previous_values
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
previous_values$1.history,
|
|
188
|
-
[entityUpdate]
|
|
189
|
-
])
|
|
190
|
-
) : previous_values$1.history,
|
|
191
|
-
containsRollbackDiffChange: previous_values$1.containsRollbackDiffChange
|
|
192
|
-
}
|
|
193
|
-
};
|
|
194
|
-
match$1 = {
|
|
195
|
-
entityRow: entityRow,
|
|
166
|
+
var previous_values = match.status;
|
|
167
|
+
if (typeof previous_values !== "object") {
|
|
168
|
+
updatedEntityRecord = {
|
|
169
|
+
latest: latest,
|
|
170
|
+
status: {
|
|
171
|
+
latestChange: change,
|
|
172
|
+
history: shouldSaveHistory ? [change] : Utils.$$Array.immutableEmpty,
|
|
173
|
+
containsRollbackDiffChange: containsRollbackDiffChange
|
|
174
|
+
},
|
|
196
175
|
entityIndices: match.entityIndices
|
|
197
176
|
};
|
|
198
177
|
} else {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
178
|
+
var newStatus = {
|
|
179
|
+
latestChange: change,
|
|
180
|
+
history: shouldSaveHistory ? (
|
|
181
|
+
previous_values.latestChange.checkpointId === change.checkpointId ? Utils.$$Array.setIndexImmutable(previous_values.history, previous_values.history.length - 1 | 0, change) : Belt_Array.concatMany([
|
|
182
|
+
previous_values.history,
|
|
183
|
+
[change]
|
|
184
|
+
])
|
|
185
|
+
) : previous_values.history,
|
|
186
|
+
containsRollbackDiffChange: previous_values.containsRollbackDiffChange
|
|
187
|
+
};
|
|
188
|
+
updatedEntityRecord = {
|
|
189
|
+
latest: latest,
|
|
190
|
+
status: newStatus,
|
|
208
191
|
entityIndices: match.entityIndices
|
|
209
192
|
};
|
|
210
193
|
}
|
|
211
194
|
} else {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
containsRollbackDiffChange: containsRollbackDiffChange
|
|
219
|
-
}
|
|
195
|
+
updatedEntityRecord = {
|
|
196
|
+
latest: latest,
|
|
197
|
+
status: {
|
|
198
|
+
latestChange: change,
|
|
199
|
+
history: shouldSaveHistory ? [change] : Utils.$$Array.immutableEmpty,
|
|
200
|
+
containsRollbackDiffChange: containsRollbackDiffChange
|
|
220
201
|
},
|
|
221
202
|
entityIndices: new Set()
|
|
222
203
|
};
|
|
223
204
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
if (typeof entity !== "object") {
|
|
227
|
-
deleteEntityFromIndices(inMemTable, entityUpdate.entityId, entityIndices);
|
|
205
|
+
if (change.type === "SET") {
|
|
206
|
+
updateIndices(inMemTable, change.entity, updatedEntityRecord.entityIndices);
|
|
228
207
|
} else {
|
|
229
|
-
|
|
208
|
+
deleteEntityFromIndices(inMemTable, change.entityId, updatedEntityRecord.entityIndices);
|
|
230
209
|
}
|
|
231
|
-
set(inMemTable.table,
|
|
232
|
-
entityRow: match$1.entityRow,
|
|
233
|
-
entityIndices: entityIndices
|
|
234
|
-
});
|
|
210
|
+
set(inMemTable.table, change.entityId, updatedEntityRecord);
|
|
235
211
|
}
|
|
236
212
|
|
|
237
213
|
function rowToEntity(row) {
|
|
238
|
-
|
|
239
|
-
if (match.TAG === "Updated") {
|
|
240
|
-
var entity = match._0.latest.entityUpdateAction;
|
|
241
|
-
if (typeof entity !== "object") {
|
|
242
|
-
return ;
|
|
243
|
-
} else {
|
|
244
|
-
return Caml_option.some(entity._0);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
var entity$1 = match._0;
|
|
248
|
-
if (typeof entity$1 !== "object") {
|
|
249
|
-
return ;
|
|
250
|
-
} else {
|
|
251
|
-
return Caml_option.some(entity$1._0);
|
|
252
|
-
}
|
|
214
|
+
return row.latest;
|
|
253
215
|
}
|
|
254
216
|
|
|
255
217
|
function getUnsafe(inMemTable) {
|
|
256
218
|
return function (key) {
|
|
257
|
-
return
|
|
219
|
+
return inMemTable.table.dict[key].latest;
|
|
258
220
|
};
|
|
259
221
|
}
|
|
260
222
|
|
|
@@ -295,7 +257,7 @@ function addEmptyIndex(inMemTable, index) {
|
|
|
295
257
|
var fieldName = TableIndices.Index.getFieldName(index);
|
|
296
258
|
var relatedEntityIds = new Set();
|
|
297
259
|
Belt_Array.forEach(Js_dict.values(inMemTable.table.dict), (function (row) {
|
|
298
|
-
var entity =
|
|
260
|
+
var entity = row.latest;
|
|
299
261
|
if (entity === undefined) {
|
|
300
262
|
return ;
|
|
301
263
|
}
|
|
@@ -340,9 +302,14 @@ function addIdToIndex(inMemTable, index, entityId) {
|
|
|
340
302
|
}
|
|
341
303
|
}
|
|
342
304
|
|
|
343
|
-
function
|
|
344
|
-
return Belt_Array.
|
|
345
|
-
|
|
305
|
+
function updates(inMemTable) {
|
|
306
|
+
return Belt_Array.keepMapU(Js_dict.values(inMemTable.table.dict), (function (v) {
|
|
307
|
+
var update = v.status;
|
|
308
|
+
if (typeof update !== "object") {
|
|
309
|
+
return ;
|
|
310
|
+
} else {
|
|
311
|
+
return update;
|
|
312
|
+
}
|
|
346
313
|
}));
|
|
347
314
|
}
|
|
348
315
|
|
|
@@ -384,18 +351,20 @@ var Entity = {
|
|
|
384
351
|
getUnsafeOnIndex: getUnsafeOnIndex,
|
|
385
352
|
addEmptyIndex: addEmptyIndex,
|
|
386
353
|
addIdToIndex: addIdToIndex,
|
|
387
|
-
|
|
354
|
+
updates: updates,
|
|
388
355
|
values: values$1,
|
|
389
356
|
clone: clone$1
|
|
390
357
|
};
|
|
391
358
|
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
359
|
+
export {
|
|
360
|
+
make ,
|
|
361
|
+
set ,
|
|
362
|
+
setByHash ,
|
|
363
|
+
hasByHash ,
|
|
364
|
+
getUnsafeByHash ,
|
|
365
|
+
get ,
|
|
366
|
+
values ,
|
|
367
|
+
clone ,
|
|
368
|
+
Entity ,
|
|
369
|
+
}
|
|
401
370
|
/* Utils Not a pure module */
|
package/src/Internal.gen.ts
CHANGED
|
@@ -7,7 +7,7 @@ import type {GenericContractRegister as $$genericContractRegister} from './Types
|
|
|
7
7
|
|
|
8
8
|
import type {Invalid as $$noEventFilters} from './Types.ts';
|
|
9
9
|
|
|
10
|
-
import type {t as Address_t} from './Address.gen';
|
|
10
|
+
import type {t as Address_t} from './Address.gen.js';
|
|
11
11
|
|
|
12
12
|
export type genericEvent<params,block,transaction> = {
|
|
13
13
|
readonly params: params;
|
|
@@ -42,8 +42,6 @@ export type entityHandlerContext<entity> = {
|
|
|
42
42
|
readonly deleteUnsafe: (_1:string) => void
|
|
43
43
|
};
|
|
44
44
|
|
|
45
|
-
export type chainInfo = { readonly isReady: boolean };
|
|
46
|
-
|
|
47
45
|
export type genericHandlerWithLoader<loader,handler,eventFilters> = {
|
|
48
46
|
readonly loader: loader;
|
|
49
47
|
readonly handler: handler;
|
|
@@ -53,8 +51,6 @@ export type genericHandlerWithLoader<loader,handler,eventFilters> = {
|
|
|
53
51
|
readonly preRegisterDynamicContracts?: boolean
|
|
54
52
|
};
|
|
55
53
|
|
|
56
|
-
export type blockEvent = { readonly number: number; readonly chainId: number };
|
|
57
|
-
|
|
58
54
|
export type eventOptions<eventFilters> = {
|
|
59
55
|
readonly wildcard?: boolean;
|
|
60
56
|
readonly eventFilters?: eventFilters;
|
package/src/Internal.res
CHANGED
|
@@ -54,11 +54,11 @@ type entityHandlerContext<'entity> = {
|
|
|
54
54
|
deleteUnsafe: string => unit,
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
@genType
|
|
58
57
|
type chainInfo = {
|
|
58
|
+
id: int,
|
|
59
59
|
// true when the chain has completed initial sync and is processing live events
|
|
60
60
|
// false during historical synchronization
|
|
61
|
-
|
|
61
|
+
isLive: bool,
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
type chains = dict<chainInfo>
|
|
@@ -67,6 +67,7 @@ type loaderReturn
|
|
|
67
67
|
type handlerContext = private {
|
|
68
68
|
isPreload: bool,
|
|
69
69
|
chains: chains,
|
|
70
|
+
chain: chainInfo,
|
|
70
71
|
}
|
|
71
72
|
type handlerArgs = {
|
|
72
73
|
event: event,
|
|
@@ -169,11 +170,8 @@ type eventItem = private {
|
|
|
169
170
|
event: event,
|
|
170
171
|
}
|
|
171
172
|
|
|
172
|
-
|
|
173
|
-
type blockEvent
|
|
174
|
-
number: int,
|
|
175
|
-
chainId: int,
|
|
176
|
-
}
|
|
173
|
+
// Opaque type to support both EVM and Fuel platforms
|
|
174
|
+
type blockEvent
|
|
177
175
|
|
|
178
176
|
type onBlockArgs = {
|
|
179
177
|
block: blockEvent,
|
|
@@ -212,6 +210,12 @@ external getItemBlockNumber: item => int = "blockNumber"
|
|
|
212
210
|
@get
|
|
213
211
|
external getItemLogIndex: item => int = "logIndex"
|
|
214
212
|
|
|
213
|
+
let getItemChainId = item =>
|
|
214
|
+
switch item {
|
|
215
|
+
| Event({chain}) => chain->ChainMap.Chain.toChainId
|
|
216
|
+
| Block({onBlockConfig: {chainId}}) => chainId
|
|
217
|
+
}
|
|
218
|
+
|
|
215
219
|
@get
|
|
216
220
|
external getItemDcs: item => option<dcs> = "dcs"
|
|
217
221
|
@set
|
|
@@ -249,36 +253,22 @@ let fuelTransferParamsSchema = S.schema(s => {
|
|
|
249
253
|
})
|
|
250
254
|
|
|
251
255
|
type entity = private {id: string}
|
|
256
|
+
type clickHouseSetUpdatesCache = {
|
|
257
|
+
tableName: string,
|
|
258
|
+
convertOrThrow: Change.t<entity> => Js.Json.t,
|
|
259
|
+
}
|
|
252
260
|
type genericEntityConfig<'entity> = {
|
|
253
261
|
name: string,
|
|
254
262
|
index: int,
|
|
255
263
|
schema: S.t<'entity>,
|
|
256
264
|
rowsSchema: S.t<array<'entity>>,
|
|
257
265
|
table: Table.table,
|
|
258
|
-
|
|
266
|
+
mutable clickHouseSetUpdatesCache?: clickHouseSetUpdatesCache,
|
|
267
|
+
mutable pgEntityHistoryCache?: EntityHistory.pgEntityHistory<'entity>,
|
|
259
268
|
}
|
|
260
269
|
type entityConfig = genericEntityConfig<entity>
|
|
261
270
|
external fromGenericEntityConfig: genericEntityConfig<'entity> => entityConfig = "%identity"
|
|
262
271
|
|
|
263
|
-
type enum
|
|
264
|
-
type enumConfig<'enum> = {
|
|
265
|
-
name: string,
|
|
266
|
-
variants: array<'enum>,
|
|
267
|
-
schema: S.t<'enum>,
|
|
268
|
-
default: 'enum,
|
|
269
|
-
}
|
|
270
|
-
external fromGenericEnumConfig: enumConfig<'enum> => enumConfig<enum> = "%identity"
|
|
271
|
-
|
|
272
|
-
let makeEnumConfig = (~name, ~variants) => {
|
|
273
|
-
name,
|
|
274
|
-
variants,
|
|
275
|
-
schema: S.enum(variants),
|
|
276
|
-
default: switch variants->Belt.Array.get(0) {
|
|
277
|
-
| Some(v) => v
|
|
278
|
-
| None => Js.Exn.raiseError("No variants defined for enum " ++ name)
|
|
279
|
-
},
|
|
280
|
-
}
|
|
281
|
-
|
|
282
272
|
type effectInput
|
|
283
273
|
type effectOutput
|
|
284
274
|
type effectContext = private {mutable cache: bool}
|
|
@@ -322,8 +312,8 @@ let makeCacheTable = (~effectName) => {
|
|
|
322
312
|
Table.mkTable(
|
|
323
313
|
cacheTablePrefix ++ effectName,
|
|
324
314
|
~fields=[
|
|
325
|
-
Table.mkField("id",
|
|
326
|
-
Table.mkField("output",
|
|
315
|
+
Table.mkField("id", String, ~fieldSchema=S.string, ~isPrimaryKey=true),
|
|
316
|
+
Table.mkField("output", Json, ~fieldSchema=cacheOutputSchema, ~isNullable=true),
|
|
327
317
|
],
|
|
328
318
|
)
|
|
329
319
|
}
|
|
@@ -331,9 +321,11 @@ let makeCacheTable = (~effectName) => {
|
|
|
331
321
|
@genType.import(("./Types.ts", "Invalid"))
|
|
332
322
|
type noEventFilters
|
|
333
323
|
|
|
324
|
+
type checkpointId = float
|
|
325
|
+
|
|
334
326
|
type reorgCheckpoint = {
|
|
335
327
|
@as("id")
|
|
336
|
-
checkpointId:
|
|
328
|
+
checkpointId: float,
|
|
337
329
|
@as("chain_id")
|
|
338
330
|
chainId: int,
|
|
339
331
|
@as("block_number")
|
|
@@ -342,13 +334,9 @@ type reorgCheckpoint = {
|
|
|
342
334
|
blockHash: string,
|
|
343
335
|
}
|
|
344
336
|
|
|
345
|
-
type
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
type updatedValue<'entityType> = {
|
|
350
|
-
latest: EntityHistory.entityUpdate<'entityType>,
|
|
351
|
-
history: array<EntityHistory.entityUpdate<'entityType>>,
|
|
337
|
+
type inMemoryStoreEntityUpdate<'entity> = {
|
|
338
|
+
latestChange: Change.t<'entity>,
|
|
339
|
+
history: array<Change.t<'entity>>,
|
|
352
340
|
// In the event of a rollback, some entity updates may have been
|
|
353
341
|
// been affected by a rollback diff. If there was no rollback diff
|
|
354
342
|
// this will always be false.
|
|
@@ -359,6 +347,7 @@ type updatedValue<'entityType> = {
|
|
|
359
347
|
containsRollbackDiffChange: bool,
|
|
360
348
|
}
|
|
361
349
|
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
|
350
|
+
@unboxed
|
|
351
|
+
type inMemoryStoreEntityStatus<'entity> =
|
|
352
|
+
| Updated(inMemoryStoreEntityUpdate<'entity>)
|
|
353
|
+
| Loaded // This means there is no change from the db.
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
import * as Table from "./db/Table.res.mjs";
|
|
4
|
+
import * as $$BigInt from "./bindings/BigInt.res.mjs";
|
|
5
|
+
import * as Address from "./Address.res.mjs";
|
|
6
|
+
import * as S$RescriptSchema from "rescript-schema/src/S.res.mjs";
|
|
7
|
+
|
|
8
|
+
function getItemChainId(item) {
|
|
9
|
+
if (item.kind === 0) {
|
|
10
|
+
return item.chain;
|
|
11
|
+
} else {
|
|
12
|
+
return item.onBlockConfig.chainId;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
var fuelSupplyParamsSchema = S$RescriptSchema.schema(function (s) {
|
|
17
|
+
return {
|
|
18
|
+
subId: s.m(S$RescriptSchema.string),
|
|
19
|
+
amount: s.m($$BigInt.schema)
|
|
20
|
+
};
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
var fuelTransferParamsSchema = S$RescriptSchema.schema(function (s) {
|
|
24
|
+
return {
|
|
25
|
+
to: s.m(Address.schema),
|
|
26
|
+
assetId: s.m(S$RescriptSchema.string),
|
|
27
|
+
amount: s.m($$BigInt.schema)
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
var cacheTablePrefix = "envio_effect_";
|
|
32
|
+
|
|
33
|
+
var cacheOutputSchema = S$RescriptSchema.json(false);
|
|
34
|
+
|
|
35
|
+
var effectCacheItemRowsSchema = S$RescriptSchema.array(S$RescriptSchema.schema(function (s) {
|
|
36
|
+
return {
|
|
37
|
+
id: s.m(S$RescriptSchema.string),
|
|
38
|
+
output: s.m(cacheOutputSchema)
|
|
39
|
+
};
|
|
40
|
+
}));
|
|
41
|
+
|
|
42
|
+
function makeCacheTable(effectName) {
|
|
43
|
+
return Table.mkTable(cacheTablePrefix + effectName, undefined, [
|
|
44
|
+
Table.mkField("id", "String", S$RescriptSchema.string, undefined, undefined, undefined, true, undefined, undefined),
|
|
45
|
+
Table.mkField("output", "Json", cacheOutputSchema, undefined, undefined, true, undefined, undefined, undefined)
|
|
46
|
+
]);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export {
|
|
50
|
+
getItemChainId ,
|
|
51
|
+
fuelSupplyParamsSchema ,
|
|
52
|
+
fuelTransferParamsSchema ,
|
|
53
|
+
cacheTablePrefix ,
|
|
54
|
+
cacheOutputSchema ,
|
|
55
|
+
effectCacheItemRowsSchema ,
|
|
56
|
+
makeCacheTable ,
|
|
57
|
+
}
|
|
58
|
+
/* fuelSupplyParamsSchema Not a pure module */
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
-
'use strict';
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
import * as Utils from "./Utils.res.mjs";
|
|
4
|
+
import * as JsSdsl from "js-sdsl";
|
|
5
|
+
import * as Belt_Option from "rescript/lib/es6/belt_Option.js";
|
|
6
|
+
import * as Caml_option from "rescript/lib/es6/caml_option.js";
|
|
7
|
+
import * as Caml_exceptions from "rescript/lib/es6/caml_exceptions.js";
|
|
8
|
+
import * as Caml_js_exceptions from "rescript/lib/es6/caml_js_exceptions.js";
|
|
10
9
|
|
|
11
10
|
var LoaderTimeout = /* @__PURE__ */Caml_exceptions.create("LazyLoader.LoaderTimeout");
|
|
12
11
|
|
|
@@ -108,10 +107,12 @@ function get(am, k) {
|
|
|
108
107
|
return promise;
|
|
109
108
|
}
|
|
110
109
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
110
|
+
export {
|
|
111
|
+
LoaderTimeout ,
|
|
112
|
+
make ,
|
|
113
|
+
deleteKey ,
|
|
114
|
+
timeoutAfter ,
|
|
115
|
+
loadNext ,
|
|
116
|
+
get ,
|
|
117
|
+
}
|
|
117
118
|
/* Utils Not a pure module */
|