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
|
@@ -1,51 +1,48 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
|
-
import * as $$Array from "rescript/lib/es6/array.js";
|
|
4
3
|
import * as Utils from "./Utils.res.mjs";
|
|
5
4
|
import * as Config from "./Config.res.mjs";
|
|
6
|
-
import * as
|
|
7
|
-
import * as Belt_Array from "rescript/lib/es6/belt_Array.js";
|
|
5
|
+
import * as Belt_Array from "@rescript/runtime/lib/es6/Belt_Array.js";
|
|
8
6
|
import * as EventUtils from "./EventUtils.res.mjs";
|
|
7
|
+
import * as Stdlib_Dict from "@rescript/runtime/lib/es6/Stdlib_Dict.js";
|
|
9
8
|
import * as ErrorHandling from "./ErrorHandling.res.mjs";
|
|
10
9
|
import * as InMemoryTable from "./InMemoryTable.res.mjs";
|
|
11
|
-
import * as
|
|
10
|
+
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
|
|
12
11
|
|
|
13
12
|
function hashRawEventsKey(key) {
|
|
14
13
|
return EventUtils.getEventIdKeyString(key.chainId, key.eventId);
|
|
15
14
|
}
|
|
16
15
|
|
|
17
|
-
|
|
16
|
+
let UndefinedEntity = /* @__PURE__ */Primitive_exceptions.create("InMemoryStore.EntityTables.UndefinedEntity");
|
|
18
17
|
|
|
19
18
|
function make(entities) {
|
|
20
|
-
|
|
21
|
-
Belt_Array.forEach(entities,
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
let init = {};
|
|
20
|
+
Belt_Array.forEach(entities, entityConfig => {
|
|
21
|
+
init[entityConfig.name] = InMemoryTable.Entity.make();
|
|
22
|
+
});
|
|
24
23
|
return init;
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
function get(self, entityName) {
|
|
28
|
-
|
|
27
|
+
let table = self[entityName];
|
|
29
28
|
if (table !== undefined) {
|
|
30
29
|
return table;
|
|
31
30
|
} else {
|
|
32
31
|
return ErrorHandling.mkLogAndRaise(undefined, "Unexpected, entity InMemoryTable is undefined", {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
RE_EXN_ID: UndefinedEntity,
|
|
33
|
+
entityName: entityName
|
|
34
|
+
});
|
|
36
35
|
}
|
|
37
36
|
}
|
|
38
37
|
|
|
39
38
|
function clone(self) {
|
|
40
|
-
return
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
];
|
|
45
|
-
})));
|
|
39
|
+
return Object.fromEntries(Belt_Array.map(Object.entries(self), param => [
|
|
40
|
+
param[0],
|
|
41
|
+
InMemoryTable.Entity.clone(param[1])
|
|
42
|
+
]));
|
|
46
43
|
}
|
|
47
44
|
|
|
48
|
-
|
|
45
|
+
let EntityTables = {
|
|
49
46
|
UndefinedEntity: UndefinedEntity,
|
|
50
47
|
make: make,
|
|
51
48
|
get: get,
|
|
@@ -54,36 +51,34 @@ var EntityTables = {
|
|
|
54
51
|
|
|
55
52
|
function make$1(entities, rollbackTargetCheckpointId) {
|
|
56
53
|
return {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
54
|
+
rawEvents: InMemoryTable.make(hashRawEventsKey),
|
|
55
|
+
entities: make(entities),
|
|
56
|
+
effects: {},
|
|
57
|
+
rollbackTargetCheckpointId: rollbackTargetCheckpointId
|
|
58
|
+
};
|
|
62
59
|
}
|
|
63
60
|
|
|
64
61
|
function clone$1(self) {
|
|
65
62
|
return {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
rollbackTargetCheckpointId: self.rollbackTargetCheckpointId
|
|
77
|
-
};
|
|
63
|
+
rawEvents: InMemoryTable.clone(self.rawEvents),
|
|
64
|
+
entities: clone(self.entities),
|
|
65
|
+
effects: Stdlib_Dict.mapValues(self.effects, table => ({
|
|
66
|
+
idsToStore: table.idsToStore.slice(),
|
|
67
|
+
invalidationsCount: table.invalidationsCount,
|
|
68
|
+
dict: Utils.Dict.shallowCopy(table.dict),
|
|
69
|
+
effect: table.effect
|
|
70
|
+
})),
|
|
71
|
+
rollbackTargetCheckpointId: self.rollbackTargetCheckpointId
|
|
72
|
+
};
|
|
78
73
|
}
|
|
79
74
|
|
|
80
75
|
function getEffectInMemTable(inMemoryStore, effect) {
|
|
81
|
-
|
|
82
|
-
|
|
76
|
+
let key = effect.name;
|
|
77
|
+
let table = inMemoryStore.effects[key];
|
|
83
78
|
if (table !== undefined) {
|
|
84
79
|
return table;
|
|
85
80
|
}
|
|
86
|
-
|
|
81
|
+
let table$1 = {
|
|
87
82
|
idsToStore: [],
|
|
88
83
|
invalidationsCount: 0,
|
|
89
84
|
dict: {},
|
|
@@ -102,61 +97,50 @@ function isRollingBack(inMemoryStore) {
|
|
|
102
97
|
}
|
|
103
98
|
|
|
104
99
|
function setBatchDcs(inMemoryStore, batch, shouldSaveHistory) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
for(
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
for(
|
|
112
|
-
|
|
113
|
-
|
|
100
|
+
let inMemTable = getInMemTable(inMemoryStore, Config.EnvioAddresses.entityConfig);
|
|
101
|
+
let itemIdx = 0;
|
|
102
|
+
for (let checkpoint = 0, checkpoint_finish = batch.checkpointIds.length; checkpoint < checkpoint_finish; ++checkpoint) {
|
|
103
|
+
let checkpointId = batch.checkpointIds[checkpoint];
|
|
104
|
+
let chainId = batch.checkpointChainIds[checkpoint];
|
|
105
|
+
let checkpointEventsProcessed = batch.checkpointEventsProcessed[checkpoint];
|
|
106
|
+
for (let idx = 0; idx < checkpointEventsProcessed; ++idx) {
|
|
107
|
+
let item = batch.items[itemIdx + idx | 0];
|
|
108
|
+
let dcs = item.dcs;
|
|
114
109
|
if (dcs !== undefined) {
|
|
115
|
-
for(
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
var entity_registering_event_name = item.eventConfig.name;
|
|
123
|
-
var entity_registering_event_src_address = item.event.srcAddress;
|
|
124
|
-
var entity_contract_address = dc.address;
|
|
125
|
-
var entity_contract_name = dc.contractName;
|
|
126
|
-
var entity = {
|
|
110
|
+
for (let dcIdx = 0, dcIdx_finish = dcs.length; dcIdx < dcIdx_finish; ++dcIdx) {
|
|
111
|
+
let dc = dcs[dcIdx];
|
|
112
|
+
let entity_id = Config.EnvioAddresses.makeId(chainId, dc.address);
|
|
113
|
+
let entity_registration_block = item.blockNumber;
|
|
114
|
+
let entity_registration_log_index = item.logIndex;
|
|
115
|
+
let entity_contract_name = dc.contractName;
|
|
116
|
+
let entity = {
|
|
127
117
|
id: entity_id,
|
|
128
118
|
chain_id: chainId,
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
registering_event_block_timestamp: entity_registering_event_block_timestamp,
|
|
132
|
-
registering_event_contract_name: entity_registering_event_contract_name,
|
|
133
|
-
registering_event_name: entity_registering_event_name,
|
|
134
|
-
registering_event_src_address: entity_registering_event_src_address,
|
|
135
|
-
contract_address: entity_contract_address,
|
|
119
|
+
registration_block: entity_registration_block,
|
|
120
|
+
registration_log_index: entity_registration_log_index,
|
|
136
121
|
contract_name: entity_contract_name
|
|
137
122
|
};
|
|
138
123
|
InMemoryTable.Entity.set(inMemTable, {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
124
|
+
type: "SET",
|
|
125
|
+
entityId: entity_id,
|
|
126
|
+
entity: entity,
|
|
127
|
+
checkpointId: checkpointId
|
|
128
|
+
}, shouldSaveHistory, undefined);
|
|
144
129
|
}
|
|
145
130
|
}
|
|
146
|
-
|
|
147
131
|
}
|
|
148
132
|
itemIdx = itemIdx + checkpointEventsProcessed | 0;
|
|
149
133
|
}
|
|
150
134
|
}
|
|
151
135
|
|
|
152
136
|
export {
|
|
153
|
-
hashRawEventsKey
|
|
154
|
-
EntityTables
|
|
137
|
+
hashRawEventsKey,
|
|
138
|
+
EntityTables,
|
|
155
139
|
make$1 as make,
|
|
156
140
|
clone$1 as clone,
|
|
157
|
-
getEffectInMemTable
|
|
158
|
-
getInMemTable
|
|
159
|
-
isRollingBack
|
|
160
|
-
setBatchDcs
|
|
141
|
+
getEffectInMemTable,
|
|
142
|
+
getInMemTable,
|
|
143
|
+
isRollingBack,
|
|
144
|
+
setBatchDcs,
|
|
161
145
|
}
|
|
162
146
|
/* Utils Not a pure module */
|
package/src/InMemoryTable.res
CHANGED
|
@@ -1,31 +1,29 @@
|
|
|
1
|
-
open Belt
|
|
2
|
-
|
|
3
1
|
type t<'key, 'val> = {
|
|
4
2
|
dict: dict<'val>,
|
|
5
3
|
hash: 'key => string,
|
|
6
4
|
}
|
|
7
5
|
|
|
8
6
|
let make = (~hash): t<'key, 'val> => {
|
|
9
|
-
dict:
|
|
7
|
+
dict: Dict.make(),
|
|
10
8
|
hash,
|
|
11
9
|
}
|
|
12
10
|
|
|
13
|
-
let set = (self: t<'key, 'val>, key, value) => self.dict->
|
|
11
|
+
let set = (self: t<'key, 'val>, key, value) => self.dict->Dict.set(key->self.hash, value)
|
|
14
12
|
|
|
15
|
-
let setByHash = (self: t<'key, 'val>, hash, value) => self.dict->
|
|
13
|
+
let setByHash = (self: t<'key, 'val>, hash, value) => self.dict->Dict.set(hash, value)
|
|
16
14
|
|
|
17
15
|
let hasByHash = (self: t<'key, 'val>, hash) => {
|
|
18
16
|
self.dict->Utils.Dict.has(hash)
|
|
19
17
|
}
|
|
20
18
|
|
|
21
19
|
let getUnsafeByHash = (self: t<'key, 'val>, hash) => {
|
|
22
|
-
self.dict->
|
|
20
|
+
self.dict->Dict.getUnsafe(hash)
|
|
23
21
|
}
|
|
24
22
|
|
|
25
23
|
let get = (self: t<'key, 'val>, key: 'key) =>
|
|
26
24
|
self.dict->Utils.Dict.dangerouslyGetNonOption(key->self.hash)
|
|
27
25
|
|
|
28
|
-
let values = (self: t<'key, 'val>) => self.dict->
|
|
26
|
+
let values = (self: t<'key, 'val>) => self.dict->Dict.valuesToArray
|
|
29
27
|
|
|
30
28
|
let clone = (self: t<'key, 'val>) => {
|
|
31
29
|
...self,
|
|
@@ -85,7 +83,7 @@ module Entity = {
|
|
|
85
83
|
let fieldValue =
|
|
86
84
|
entity
|
|
87
85
|
->(Utils.magic: 'entity => dict<TableIndices.FieldValue.t>)
|
|
88
|
-
->
|
|
86
|
+
->Dict.get(fieldName)
|
|
89
87
|
->Option.getUnsafe
|
|
90
88
|
if !(index->TableIndices.Index.evaluate(~fieldName, ~fieldValue)) {
|
|
91
89
|
entityIndices->Utils.Set.delete(index)->ignore
|
|
@@ -93,13 +91,11 @@ module Entity = {
|
|
|
93
91
|
})
|
|
94
92
|
|
|
95
93
|
self.fieldNameIndices.dict
|
|
96
|
-
->
|
|
94
|
+
->Dict.keysToArray
|
|
97
95
|
->Array.forEach(fieldName => {
|
|
98
96
|
switch (
|
|
99
|
-
entity
|
|
100
|
-
|
|
101
|
-
->Js.Dict.get(fieldName),
|
|
102
|
-
self.fieldNameIndices.dict->Js.Dict.get(fieldName),
|
|
97
|
+
entity->(Utils.magic: 'entity => dict<TableIndices.FieldValue.t>)->Dict.get(fieldName),
|
|
98
|
+
self.fieldNameIndices.dict->Dict.get(fieldName),
|
|
103
99
|
) {
|
|
104
100
|
| (Some(fieldValue), Some(indices)) =>
|
|
105
101
|
indices
|
|
@@ -142,7 +138,7 @@ module Entity = {
|
|
|
142
138
|
) => {
|
|
143
139
|
let shouldWriteEntity =
|
|
144
140
|
allowOverWriteEntity ||
|
|
145
|
-
inMemTable.table.dict->
|
|
141
|
+
inMemTable.table.dict->Dict.get(key->inMemTable.table.hash)->Option.isNone
|
|
146
142
|
|
|
147
143
|
//Only initialize a row in the case where it is none
|
|
148
144
|
//or if allowOverWriteEntity is true (used for mockDb in test helpers)
|
|
@@ -155,7 +151,7 @@ module Entity = {
|
|
|
155
151
|
inMemTable->updateIndices(~entity, ~entityIndices)
|
|
156
152
|
| None => ()
|
|
157
153
|
}
|
|
158
|
-
inMemTable.table.dict->
|
|
154
|
+
inMemTable.table.dict->Dict.set(
|
|
159
155
|
key->inMemTable.table.hash,
|
|
160
156
|
{
|
|
161
157
|
latest: entity,
|
|
@@ -234,25 +230,23 @@ module Entity = {
|
|
|
234
230
|
that the entity is not set to the in memory store,
|
|
235
231
|
and the second option means that the entity doesn't esist/deleted.
|
|
236
232
|
It's needed to prevent an additional round trips to the database for deleted entities. */
|
|
237
|
-
let getUnsafe = (inMemTable: t<'entity>) =>
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
233
|
+
let getUnsafe = (inMemTable: t<'entity>) =>
|
|
234
|
+
(key: string) =>
|
|
235
|
+
inMemTable.table.dict
|
|
236
|
+
->Dict.getUnsafe(key)
|
|
237
|
+
->rowToEntity
|
|
241
238
|
|
|
242
|
-
let hasIndex = (
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
let key = `${fieldName}:${(operator :> string)}:${fieldValueHash}`
|
|
252
|
-
indicesSerializedToValue.dict->Utils.Dict.dangerouslyGetNonOption(key) !== None
|
|
239
|
+
let hasIndex = (inMemTable: t<'entity>, ~fieldName, ~operator: TableIndices.Operator.t) =>
|
|
240
|
+
fieldValueHash => {
|
|
241
|
+
switch inMemTable.fieldNameIndices.dict->Utils.Dict.dangerouslyGetNonOption(fieldName) {
|
|
242
|
+
| None => false
|
|
243
|
+
| Some(indicesSerializedToValue) => {
|
|
244
|
+
// Should match TableIndices.toString logic
|
|
245
|
+
let key = `${fieldName}:${(operator :> string)}:${fieldValueHash}`
|
|
246
|
+
indicesSerializedToValue.dict->Utils.Dict.dangerouslyGetNonOption(key) !== None
|
|
247
|
+
}
|
|
253
248
|
}
|
|
254
249
|
}
|
|
255
|
-
}
|
|
256
250
|
|
|
257
251
|
let getUnsafeOnIndex = (
|
|
258
252
|
inMemTable: t<'entity>,
|
|
@@ -262,20 +256,21 @@ module Entity = {
|
|
|
262
256
|
let getEntity = inMemTable->getUnsafe
|
|
263
257
|
fieldValueHash => {
|
|
264
258
|
switch inMemTable.fieldNameIndices.dict->Utils.Dict.dangerouslyGetNonOption(fieldName) {
|
|
265
|
-
| None =>
|
|
259
|
+
| None =>
|
|
260
|
+
JsError.throwWithMessage(`Unexpected error. Must have an index on field ${fieldName}`)
|
|
266
261
|
| Some(indicesSerializedToValue) => {
|
|
267
262
|
// Should match TableIndices.toString logic
|
|
268
263
|
let key = `${fieldName}:${(operator :> string)}:${fieldValueHash}`
|
|
269
264
|
switch indicesSerializedToValue.dict->Utils.Dict.dangerouslyGetNonOption(key) {
|
|
270
265
|
| None =>
|
|
271
|
-
|
|
266
|
+
JsError.throwWithMessage(
|
|
272
267
|
`Unexpected error. Must have an index for the value ${fieldValueHash} on field ${fieldName}`,
|
|
273
268
|
)
|
|
274
269
|
| Some((_index, relatedEntityIds)) => {
|
|
275
270
|
let res =
|
|
276
271
|
relatedEntityIds
|
|
277
272
|
->Utils.Set.toArray
|
|
278
|
-
->Array.
|
|
273
|
+
->Array.filterMap(entityId => {
|
|
279
274
|
switch hasByHash(inMemTable.table, entityId) {
|
|
280
275
|
| true => getEntity(entityId)
|
|
281
276
|
| false => None
|
|
@@ -301,7 +296,7 @@ module Entity = {
|
|
|
301
296
|
let fieldValue =
|
|
302
297
|
entity
|
|
303
298
|
->(Utils.magic: 'entity => dict<TableIndices.FieldValue.t>)
|
|
304
|
-
->
|
|
299
|
+
->Dict.getUnsafe(fieldName)
|
|
305
300
|
if index->TableIndices.Index.evaluate(~fieldName, ~fieldValue) {
|
|
306
301
|
let _ = row.entityIndices->Utils.Set.add(index)
|
|
307
302
|
let _ = relatedEntityIds->Utils.Set.add(entity->getEntityIdUnsafe)
|
|
@@ -344,7 +339,7 @@ module Entity = {
|
|
|
344
339
|
let updates = (inMemTable: t<'entity>) => {
|
|
345
340
|
inMemTable.table
|
|
346
341
|
->values
|
|
347
|
-
->Array.
|
|
342
|
+
->Array.filterMap(v =>
|
|
348
343
|
switch v.status {
|
|
349
344
|
| Updated(update) => Some(update)
|
|
350
345
|
| Loaded => None
|
|
@@ -355,7 +350,7 @@ module Entity = {
|
|
|
355
350
|
let values = (inMemTable: t<'entity>) => {
|
|
356
351
|
inMemTable.table
|
|
357
352
|
->values
|
|
358
|
-
->Array.
|
|
353
|
+
->Array.filterMap(rowToEntity)
|
|
359
354
|
}
|
|
360
355
|
|
|
361
356
|
let clone = ({table, fieldNameIndices}: t<'entity>) => {
|
|
@@ -363,9 +358,9 @@ module Entity = {
|
|
|
363
358
|
fieldNameIndices: {
|
|
364
359
|
...fieldNameIndices,
|
|
365
360
|
dict: fieldNameIndices.dict
|
|
366
|
-
->
|
|
361
|
+
->Dict.toArray
|
|
367
362
|
->Array.map(((k, v)) => (k, v->clone))
|
|
368
|
-
->
|
|
363
|
+
->Dict.fromArray,
|
|
369
364
|
},
|
|
370
365
|
}
|
|
371
366
|
}
|