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,21 +1,21 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
3
|
import * as Utils from "./Utils.res.mjs";
|
|
4
|
-
import * as Js_exn from "rescript/lib/es6/js_exn.js";
|
|
5
4
|
import * as Lodash from "./bindings/Lodash.res.mjs";
|
|
6
|
-
import * as
|
|
7
|
-
import * as
|
|
8
|
-
import * as Belt_Option from "rescript/lib/es6/belt_Option.js";
|
|
9
|
-
import * as Caml_option from "rescript/lib/es6/caml_option.js";
|
|
5
|
+
import * as Belt_Array from "@rescript/runtime/lib/es6/Belt_Array.js";
|
|
6
|
+
import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
|
|
10
7
|
import * as TableIndices from "./TableIndices.res.mjs";
|
|
11
8
|
import * as ErrorHandling from "./ErrorHandling.res.mjs";
|
|
12
|
-
import * as
|
|
9
|
+
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
10
|
+
import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js";
|
|
11
|
+
import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
|
|
12
|
+
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
|
|
13
13
|
|
|
14
14
|
function make(hash) {
|
|
15
15
|
return {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
dict: {},
|
|
17
|
+
hash: hash
|
|
18
|
+
};
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
function set(self, key, value) {
|
|
@@ -39,115 +39,116 @@ function get(self, key) {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
function values(self) {
|
|
42
|
-
return
|
|
42
|
+
return Object.values(self.dict);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
function clone(self) {
|
|
46
46
|
return {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
dict: Lodash.cloneDeep(self.dict),
|
|
48
|
+
hash: self.hash
|
|
49
|
+
};
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
let UnexpectedIdNotDefinedOnEntity = /* @__PURE__ */Primitive_exceptions.create("InMemoryTable.Entity.UnexpectedIdNotDefinedOnEntity");
|
|
53
53
|
|
|
54
54
|
function getEntityIdUnsafe(entity) {
|
|
55
|
-
|
|
55
|
+
let id = entity.id;
|
|
56
56
|
if (id !== undefined) {
|
|
57
57
|
return id;
|
|
58
58
|
} else {
|
|
59
59
|
return ErrorHandling.mkLogAndRaise(undefined, "Property 'id' does not exist on expected entity object", {
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
RE_EXN_ID: UnexpectedIdNotDefinedOnEntity
|
|
61
|
+
});
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
function makeIndicesSerializedToValue(index, relatedEntityIdsOpt) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
66
|
+
let relatedEntityIds = relatedEntityIdsOpt !== undefined ? Primitive_option.valFromOption(relatedEntityIdsOpt) : new Set();
|
|
67
|
+
let empty_dict = {};
|
|
68
|
+
let empty_hash = TableIndices.Index.toString;
|
|
69
|
+
let empty = {
|
|
70
70
|
dict: empty_dict,
|
|
71
71
|
hash: empty_hash
|
|
72
72
|
};
|
|
73
73
|
set(empty, index, [
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
index,
|
|
75
|
+
relatedEntityIds
|
|
76
|
+
]);
|
|
77
77
|
return empty;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
function make$1() {
|
|
81
81
|
return {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
};
|
|
82
|
+
table: {
|
|
83
|
+
dict: {},
|
|
84
|
+
hash: str => str
|
|
85
|
+
},
|
|
86
|
+
fieldNameIndices: {
|
|
87
|
+
dict: {},
|
|
88
|
+
hash: TableIndices.Index.getFieldName
|
|
89
|
+
}
|
|
90
|
+
};
|
|
93
91
|
}
|
|
94
92
|
|
|
95
|
-
|
|
93
|
+
let UndefinedKey = /* @__PURE__ */Primitive_exceptions.create("InMemoryTable.Entity.UndefinedKey");
|
|
96
94
|
|
|
97
95
|
function updateIndices(self, entity, entityIndices) {
|
|
98
|
-
entityIndices.forEach(
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
96
|
+
entityIndices.forEach(index => {
|
|
97
|
+
let fieldName = TableIndices.Index.getFieldName(index);
|
|
98
|
+
let fieldValue = entity[fieldName];
|
|
99
|
+
if (!TableIndices.Index.evaluate(index, fieldName, fieldValue)) {
|
|
100
|
+
entityIndices.delete(index);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
Object.keys(self.fieldNameIndices.dict).forEach(fieldName => {
|
|
105
|
+
let match = entity[fieldName];
|
|
106
|
+
let match$1 = self.fieldNameIndices.dict[fieldName];
|
|
107
|
+
if (match === undefined) {
|
|
108
|
+
return ErrorHandling.mkLogAndRaise(undefined, "Expected field name to exist on the referenced index and the provided entity", {
|
|
109
|
+
RE_EXN_ID: UndefinedKey,
|
|
110
|
+
_1: fieldName
|
|
106
111
|
});
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
});
|
|
127
|
-
}));
|
|
112
|
+
}
|
|
113
|
+
if (match$1 === undefined) {
|
|
114
|
+
return ErrorHandling.mkLogAndRaise(undefined, "Expected field name to exist on the referenced index and the provided entity", {
|
|
115
|
+
RE_EXN_ID: UndefinedKey,
|
|
116
|
+
_1: fieldName
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
let fieldValue = Primitive_option.valFromOption(match);
|
|
120
|
+
Object.values(match$1.dict).forEach(param => {
|
|
121
|
+
let relatedEntityIds = param[1];
|
|
122
|
+
let index = param[0];
|
|
123
|
+
if (TableIndices.Index.evaluate(index, fieldName, fieldValue)) {
|
|
124
|
+
relatedEntityIds.add(getEntityIdUnsafe(entity));
|
|
125
|
+
entityIndices.add(index);
|
|
126
|
+
} else {
|
|
127
|
+
relatedEntityIds.delete(getEntityIdUnsafe(entity));
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
});
|
|
128
131
|
}
|
|
129
132
|
|
|
130
133
|
function deleteEntityFromIndices(self, entityId, entityIndices) {
|
|
131
|
-
entityIndices.forEach(
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
entityIndices.delete(index);
|
|
139
|
-
});
|
|
134
|
+
entityIndices.forEach(index => {
|
|
135
|
+
let match = Stdlib_Option.flatMap(get(self.fieldNameIndices, index), __x => get(__x, index));
|
|
136
|
+
if (match !== undefined) {
|
|
137
|
+
match[1].delete(entityId);
|
|
138
|
+
}
|
|
139
|
+
entityIndices.delete(index);
|
|
140
|
+
});
|
|
140
141
|
}
|
|
141
142
|
|
|
142
143
|
function initValue(inMemTable, key, entity, allowOverWriteEntityOpt) {
|
|
143
|
-
|
|
144
|
-
|
|
144
|
+
let allowOverWriteEntity = allowOverWriteEntityOpt !== undefined ? allowOverWriteEntityOpt : false;
|
|
145
|
+
let shouldWriteEntity = allowOverWriteEntity || Stdlib_Option.isNone(inMemTable.table.dict[inMemTable.table.hash(key)]);
|
|
145
146
|
if (!shouldWriteEntity) {
|
|
146
|
-
return
|
|
147
|
+
return;
|
|
147
148
|
}
|
|
148
|
-
|
|
149
|
+
let entityIndices = new Set();
|
|
149
150
|
if (entity !== undefined) {
|
|
150
|
-
updateIndices(inMemTable,
|
|
151
|
+
updateIndices(inMemTable, Primitive_option.valFromOption(entity), entityIndices);
|
|
151
152
|
}
|
|
152
153
|
inMemTable.table.dict[inMemTable.table.hash(key)] = {
|
|
153
154
|
latest: entity,
|
|
@@ -157,14 +158,14 @@ function initValue(inMemTable, key, entity, allowOverWriteEntityOpt) {
|
|
|
157
158
|
}
|
|
158
159
|
|
|
159
160
|
function set$1(inMemTable, change, shouldSaveHistory, containsRollbackDiffChangeOpt) {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
latest = change.type === "SET" ?
|
|
163
|
-
|
|
164
|
-
|
|
161
|
+
let containsRollbackDiffChange = containsRollbackDiffChangeOpt !== undefined ? containsRollbackDiffChangeOpt : false;
|
|
162
|
+
let latest;
|
|
163
|
+
latest = change.type === "SET" ? Primitive_option.some(change.entity) : undefined;
|
|
164
|
+
let match = get(inMemTable.table, change.entityId);
|
|
165
|
+
let updatedEntityRecord;
|
|
165
166
|
if (match !== undefined) {
|
|
166
|
-
|
|
167
|
-
if (
|
|
167
|
+
let previous_values = match.status;
|
|
168
|
+
if (previous_values === "Loaded") {
|
|
168
169
|
updatedEntityRecord = {
|
|
169
170
|
latest: latest,
|
|
170
171
|
status: {
|
|
@@ -175,13 +176,13 @@ function set$1(inMemTable, change, shouldSaveHistory, containsRollbackDiffChange
|
|
|
175
176
|
entityIndices: match.entityIndices
|
|
176
177
|
};
|
|
177
178
|
} else {
|
|
178
|
-
|
|
179
|
+
let newStatus = {
|
|
179
180
|
latestChange: change,
|
|
180
181
|
history: shouldSaveHistory ? (
|
|
181
182
|
previous_values.latestChange.checkpointId === change.checkpointId ? Utils.$$Array.setIndexImmutable(previous_values.history, previous_values.history.length - 1 | 0, change) : Belt_Array.concatMany([
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
183
|
+
previous_values.history,
|
|
184
|
+
[change]
|
|
185
|
+
])
|
|
185
186
|
) : previous_values.history,
|
|
186
187
|
containsRollbackDiffChange: previous_values.containsRollbackDiffChange
|
|
187
188
|
};
|
|
@@ -215,125 +216,119 @@ function rowToEntity(row) {
|
|
|
215
216
|
}
|
|
216
217
|
|
|
217
218
|
function getUnsafe(inMemTable) {
|
|
218
|
-
return
|
|
219
|
-
return inMemTable.table.dict[key].latest;
|
|
220
|
-
};
|
|
219
|
+
return key => inMemTable.table.dict[key].latest;
|
|
221
220
|
}
|
|
222
221
|
|
|
223
222
|
function hasIndex(inMemTable, fieldName, operator) {
|
|
224
|
-
return
|
|
225
|
-
|
|
223
|
+
return fieldValueHash => {
|
|
224
|
+
let indicesSerializedToValue = inMemTable.fieldNameIndices.dict[fieldName];
|
|
226
225
|
if (indicesSerializedToValue === undefined) {
|
|
227
226
|
return false;
|
|
228
227
|
}
|
|
229
|
-
|
|
228
|
+
let key = fieldName + `:` + operator + `:` + fieldValueHash;
|
|
230
229
|
return indicesSerializedToValue.dict[key] !== undefined;
|
|
231
230
|
};
|
|
232
231
|
}
|
|
233
232
|
|
|
234
233
|
function getUnsafeOnIndex(inMemTable, fieldName, operator) {
|
|
235
|
-
|
|
236
|
-
return
|
|
237
|
-
|
|
234
|
+
let getEntity = getUnsafe(inMemTable);
|
|
235
|
+
return fieldValueHash => {
|
|
236
|
+
let indicesSerializedToValue = inMemTable.fieldNameIndices.dict[fieldName];
|
|
238
237
|
if (indicesSerializedToValue === undefined) {
|
|
239
|
-
return
|
|
238
|
+
return Stdlib_JsError.throwWithMessage(`Unexpected error. Must have an index on field ` + fieldName);
|
|
240
239
|
}
|
|
241
|
-
|
|
242
|
-
|
|
240
|
+
let key = fieldName + `:` + operator + `:` + fieldValueHash;
|
|
241
|
+
let match = indicesSerializedToValue.dict[key];
|
|
243
242
|
if (match !== undefined) {
|
|
244
|
-
return
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
}));
|
|
243
|
+
return Stdlib_Array.filterMap(Array.from(match[1]), entityId => {
|
|
244
|
+
if (hasByHash(inMemTable.table, entityId)) {
|
|
245
|
+
return getEntity(entityId);
|
|
246
|
+
}
|
|
247
|
+
});
|
|
250
248
|
} else {
|
|
251
|
-
return
|
|
249
|
+
return Stdlib_JsError.throwWithMessage(`Unexpected error. Must have an index for the value ` + fieldValueHash + ` on field ` + fieldName);
|
|
252
250
|
}
|
|
253
251
|
};
|
|
254
252
|
}
|
|
255
253
|
|
|
256
254
|
function addEmptyIndex(inMemTable, index) {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
var indicesSerializedToValue = get(inMemTable.fieldNameIndices, index);
|
|
255
|
+
let fieldName = TableIndices.Index.getFieldName(index);
|
|
256
|
+
let relatedEntityIds = new Set();
|
|
257
|
+
Object.values(inMemTable.table.dict).forEach(row => {
|
|
258
|
+
let entity = row.latest;
|
|
259
|
+
if (entity === undefined) {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
let entity$1 = Primitive_option.valFromOption(entity);
|
|
263
|
+
let fieldValue = entity$1[fieldName];
|
|
264
|
+
if (TableIndices.Index.evaluate(index, fieldName, fieldValue)) {
|
|
265
|
+
row.entityIndices.add(index);
|
|
266
|
+
relatedEntityIds.add(getEntityIdUnsafe(entity$1));
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
let indicesSerializedToValue = get(inMemTable.fieldNameIndices, index);
|
|
274
271
|
if (indicesSerializedToValue === undefined) {
|
|
275
|
-
return set(inMemTable.fieldNameIndices, index, makeIndicesSerializedToValue(index,
|
|
272
|
+
return set(inMemTable.fieldNameIndices, index, makeIndicesSerializedToValue(index, Primitive_option.some(relatedEntityIds)));
|
|
276
273
|
}
|
|
277
|
-
|
|
274
|
+
let match = get(indicesSerializedToValue, index);
|
|
278
275
|
if (match !== undefined) {
|
|
279
|
-
return
|
|
276
|
+
return;
|
|
280
277
|
} else {
|
|
281
278
|
return set(indicesSerializedToValue, index, [
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
279
|
+
index,
|
|
280
|
+
relatedEntityIds
|
|
281
|
+
]);
|
|
285
282
|
}
|
|
286
283
|
}
|
|
287
284
|
|
|
288
285
|
function addIdToIndex(inMemTable, index, entityId) {
|
|
289
|
-
|
|
286
|
+
let indicesSerializedToValue = get(inMemTable.fieldNameIndices, index);
|
|
290
287
|
if (indicesSerializedToValue === undefined) {
|
|
291
|
-
return set(inMemTable.fieldNameIndices, index, makeIndicesSerializedToValue(index,
|
|
288
|
+
return set(inMemTable.fieldNameIndices, index, makeIndicesSerializedToValue(index, Primitive_option.some(new Set().add(entityId))));
|
|
292
289
|
}
|
|
293
|
-
|
|
290
|
+
let match = get(indicesSerializedToValue, index);
|
|
294
291
|
if (match !== undefined) {
|
|
295
292
|
match[1].add(entityId);
|
|
296
|
-
return
|
|
293
|
+
return;
|
|
297
294
|
} else {
|
|
298
295
|
return set(indicesSerializedToValue, index, [
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
296
|
+
index,
|
|
297
|
+
new Set().add(entityId)
|
|
298
|
+
]);
|
|
302
299
|
}
|
|
303
300
|
}
|
|
304
301
|
|
|
305
302
|
function updates(inMemTable) {
|
|
306
|
-
return
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
303
|
+
return Stdlib_Array.filterMap(Object.values(inMemTable.table.dict), v => {
|
|
304
|
+
let update = v.status;
|
|
305
|
+
if (update === "Loaded") {
|
|
306
|
+
return;
|
|
307
|
+
} else {
|
|
308
|
+
return update;
|
|
309
|
+
}
|
|
310
|
+
});
|
|
314
311
|
}
|
|
315
312
|
|
|
316
313
|
function values$1(inMemTable) {
|
|
317
|
-
return
|
|
314
|
+
return Stdlib_Array.filterMap(Object.values(inMemTable.table.dict), rowToEntity);
|
|
318
315
|
}
|
|
319
316
|
|
|
320
317
|
function clone$1(param) {
|
|
321
|
-
|
|
318
|
+
let fieldNameIndices = param.fieldNameIndices;
|
|
322
319
|
return {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
}
|
|
333
|
-
};
|
|
320
|
+
table: clone(param.table),
|
|
321
|
+
fieldNameIndices: {
|
|
322
|
+
dict: Object.fromEntries(Object.entries(fieldNameIndices.dict).map(param => [
|
|
323
|
+
param[0],
|
|
324
|
+
clone(param[1])
|
|
325
|
+
])),
|
|
326
|
+
hash: fieldNameIndices.hash
|
|
327
|
+
}
|
|
328
|
+
};
|
|
334
329
|
}
|
|
335
330
|
|
|
336
|
-
|
|
331
|
+
let Entity = {
|
|
337
332
|
UnexpectedIdNotDefinedOnEntity: UnexpectedIdNotDefinedOnEntity,
|
|
338
333
|
getEntityIdUnsafe: getEntityIdUnsafe,
|
|
339
334
|
makeIndicesSerializedToValue: makeIndicesSerializedToValue,
|
|
@@ -357,14 +352,14 @@ var Entity = {
|
|
|
357
352
|
};
|
|
358
353
|
|
|
359
354
|
export {
|
|
360
|
-
make
|
|
361
|
-
set
|
|
362
|
-
setByHash
|
|
363
|
-
hasByHash
|
|
364
|
-
getUnsafeByHash
|
|
365
|
-
get
|
|
366
|
-
values
|
|
367
|
-
clone
|
|
368
|
-
Entity
|
|
355
|
+
make,
|
|
356
|
+
set,
|
|
357
|
+
setByHash,
|
|
358
|
+
hasByHash,
|
|
359
|
+
getUnsafeByHash,
|
|
360
|
+
get,
|
|
361
|
+
values,
|
|
362
|
+
clone,
|
|
363
|
+
Entity,
|
|
369
364
|
}
|
|
370
365
|
/* Utils Not a pure module */
|