envio 3.15.0-subgraph → 3.16.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/README.md +40 -34
- package/evm.schema.json +3 -3
- package/fuel.schema.json +2 -2
- package/index.d.ts +3 -3
- package/licenses/README.md +1 -1
- package/package.json +9 -10
- package/src/Batch.res.mjs +5 -5
- package/src/BatchProcessing.res +1 -0
- package/src/BatchProcessing.res.mjs +1 -0
- package/src/Bin.res +0 -7
- package/src/Bin.res.mjs +0 -8
- package/src/ChainFetching.res +17 -456
- package/src/ChainFetching.res.mjs +33 -404
- package/src/ChainState.res +48 -83
- package/src/ChainState.res.mjs +83 -115
- package/src/ChainState.resi +0 -26
- package/src/Clock.res +57 -0
- package/src/Clock.res.mjs +72 -0
- package/src/Config.res +7 -16
- package/src/Config.res.mjs +4 -11
- package/src/ContractRegisterContext.res +6 -3
- package/src/ContractRegisterContext.res.mjs +2 -4
- package/src/Core.res +5 -136
- package/src/Core.res.mjs +1 -90
- package/src/CrossChainState.res +2 -8
- package/src/CrossChainState.res.mjs +3 -3
- package/src/Ecosystem.res +4 -7
- package/src/Ecosystem.res.mjs +8 -8
- package/src/EffectState.res +10 -2
- package/src/EffectState.res.mjs +8 -4
- package/src/EffectState.resi +3 -1
- package/src/EntityId.res +2 -7
- package/src/EntityId.res.mjs +1 -8
- package/src/EntityTables.res +4 -1
- package/src/EntityTables.res.mjs +1 -1
- package/src/Env.res +0 -16
- package/src/Env.res.mjs +0 -11
- package/src/EventProcessing.res +1 -38
- package/src/EventProcessing.res.mjs +1 -28
- package/src/FetchState.res +160 -319
- package/src/FetchState.res.mjs +182 -292
- package/src/FinalizeBackfill.res +2 -4
- package/src/FinalizeBackfill.res.mjs +3 -4
- package/src/HandlerLoader.res +15 -39
- package/src/HandlerLoader.res.mjs +8 -27
- package/src/HandlerRegister.res +0 -4
- package/src/HandlerRegister.res.mjs +2 -5
- package/src/HandlerRegister.resi +0 -2
- package/src/InMemoryTable.res +17 -16
- package/src/InMemoryTable.res.mjs +14 -15
- package/src/IndexerState.res +28 -4
- package/src/IndexerState.res.mjs +19 -6
- package/src/IndexerState.resi +4 -0
- package/src/Internal.res +0 -110
- package/src/Internal.res.mjs +1 -115
- package/src/LoadLayer.res +21 -47
- package/src/LoadLayer.res.mjs +47 -72
- package/src/LoadLayer.resi +0 -26
- package/src/Main.res +1 -14
- package/src/Main.res.mjs +3 -4
- package/src/Persistence.res +3 -23
- package/src/Persistence.res.mjs +3 -3
- package/src/Rollback.res +0 -1
- package/src/Rollback.res.mjs +1 -1
- package/src/RunScope.res +0 -3
- package/src/SafeCheckpointTracking.res +4 -4
- package/src/SafeCheckpointTracking.res.mjs +1 -1
- package/src/SimulateItems.res +26 -42
- package/src/SimulateItems.res.mjs +16 -40
- package/src/StagedRows.res +106 -0
- package/src/StagedRows.res.mjs +102 -0
- package/src/Staging.res +32 -14
- package/src/Staging.res.mjs +17 -20
- package/src/Storage.res +277 -998
- package/src/Storage.res.mjs +216 -731
- package/src/Supervisor.res +75 -56
- package/src/Supervisor.res.mjs +55 -26
- package/src/TestIndexer.res +22 -27
- package/src/TestIndexer.res.mjs +20 -17
- package/src/Throttler.res +15 -8
- package/src/Throttler.res.mjs +9 -6
- package/src/Throttler.resi +1 -1
- package/src/UserContext.res +46 -410
- package/src/UserContext.res.mjs +30 -318
- package/src/Utils.res +0 -23
- package/src/Utils.res.mjs +1 -17
- package/src/Writing.res +0 -1
- package/src/Writing.res.mjs +1 -1
- package/src/bindings/ClickHouse.res +0 -322
- package/src/bindings/ClickHouse.res.mjs +0 -338
- package/src/bindings/StorageClient.res +107 -175
- package/src/bindings/StorageClient.res.mjs +19 -8
- package/src/bindings/Vitest.res +0 -26
- package/src/bindings/Vitest.res.mjs +0 -3
- package/src/db/Table.res +24 -150
- package/src/db/Table.res.mjs +38 -272
- package/src/sources/AddressSet.res +0 -2
- package/src/sources/AddressStore.res +0 -3
- package/src/sources/ChainSources.res +2 -0
- package/src/sources/ChainSources.res.mjs +2 -2
- package/src/sources/EvmChain.res +4 -7
- package/src/sources/EvmChain.res.mjs +5 -4
- package/src/sources/EvmHyperSyncSource.res +2 -2
- package/src/sources/EvmHyperSyncSource.res.mjs +1 -1
- package/src/sources/EvmRpcClient.res +13 -3
- package/src/sources/EvmRpcClient.res.mjs +4 -3
- package/src/sources/EvmRpcWs.res +4 -3
- package/src/sources/EvmRpcWs.res.mjs +2 -2
- package/src/sources/HeightFeed.res +31 -10
- package/src/sources/HeightFeed.res.mjs +10 -6
- package/src/sources/HeightStream.res +32 -17
- package/src/sources/HeightStream.res.mjs +10 -10
- package/src/sources/HyperSync.res +1 -2
- package/src/sources/HyperSync.res.mjs +1 -2
- package/src/sources/HyperSyncSSE.res +4 -6
- package/src/sources/HyperSyncSSE.res.mjs +2 -2
- package/src/sources/RpcSource.res +10 -1
- package/src/sources/RpcSource.res.mjs +4 -3
- package/src/sources/Source.res +3 -0
- package/src/sources/SourceManager.res +85 -104
- package/src/sources/SourceManager.res.mjs +18 -37
- package/src/sources/SourceManager.resi +3 -5
- package/src/sources/StartBlockResolver.res +1 -0
- package/src/sources/StartBlockResolver.res.mjs +4 -3
- package/src/sources/SvmHyperSyncSource.res +2 -2
- package/src/sources/SvmHyperSyncSource.res.mjs +1 -1
- package/svm.schema.json +3 -3
- package/src/EffectCacheLookup.res +0 -98
- package/src/EffectCacheLookup.res.mjs +0 -116
- package/src/PgWriting.res +0 -36
- package/src/PgWriting.res.mjs +0 -34
- package/src/PreloadLookahead.res +0 -184
- package/src/PreloadLookahead.res.mjs +0 -197
- package/src/SubgraphLog.res +0 -19
- package/src/SubgraphLog.res.mjs +0 -26
- package/src/SyncWrites.res +0 -101
- package/src/SyncWrites.res.mjs +0 -98
- package/src/db/IndexDefinition.res +0 -47
- package/src/db/IndexDefinition.res.mjs +0 -60
- package/src/sources/CallSource.res +0 -274
- package/src/sources/CallSource.res.mjs +0 -196
- package/src/subgraph/abi-types.ts +0 -84
- package/src/subgraph/aggregations.ts +0 -745
- package/src/subgraph/as-package.ts +0 -143
- package/src/subgraph/assemblyscript-regex.ts +0 -67
- package/src/subgraph/assemblyscript.ts +0 -731
- package/src/subgraph/blocks.ts +0 -398
- package/src/subgraph/calls-source.ts +0 -702
- package/src/subgraph/calls.ts +0 -258
- package/src/subgraph/conformance.ts +0 -106
- package/src/subgraph/errors.ts +0 -85
- package/src/subgraph/graft.ts +0 -73
- package/src/subgraph/graph-cli-worker.mjs +0 -35
- package/src/subgraph/graph-cli.ts +0 -900
- package/src/subgraph/graph-node-decimal.ts +0 -199
- package/src/subgraph/graph-ts-enums.ts +0 -28
- package/src/subgraph/graph-ts-types/VERSION +0 -2
- package/src/subgraph/graph-ts-types/chain/arweave.d.ts +0 -70
- package/src/subgraph/graph-ts-types/chain/cosmos.d.ts +0 -327
- package/src/subgraph/graph-ts-types/chain/ethereum.d.ts +0 -233
- package/src/subgraph/graph-ts-types/chain/near.d.ts +0 -253
- package/src/subgraph/graph-ts-types/chain/starknet.d.ts +0 -32
- package/src/subgraph/graph-ts-types/common/collections.d.ts +0 -136
- package/src/subgraph/graph-ts-types/common/conversion.d.ts +0 -11
- package/src/subgraph/graph-ts-types/common/datasource.d.ts +0 -30
- package/src/subgraph/graph-ts-types/common/eager-offset.d.ts +0 -0
- package/src/subgraph/graph-ts-types/common/json.d.ts +0 -17
- package/src/subgraph/graph-ts-types/common/numbers.d.ts +0 -120
- package/src/subgraph/graph-ts-types/common/value.d.ts +0 -120
- package/src/subgraph/graph-ts-types/common/yaml.d.ts +0 -90
- package/src/subgraph/graph-ts-types/global/global.d.ts +0 -194
- package/src/subgraph/graph-ts-types/helper-functions.d.ts +0 -22
- package/src/subgraph/graph-ts-types/index.d.ts +0 -102
- package/src/subgraph/graph-ts.ts +0 -4280
- package/src/subgraph/hosts.ts +0 -554
- package/src/subgraph/log.ts +0 -28
- package/src/subgraph/receipts.ts +0 -184
- package/src/subgraph/register-slots.ts +0 -93
- package/src/subgraph/rollup.ts +0 -109
- package/src/subgraph/rpc.ts +0 -337
- package/src/subgraph/runtime.ts +0 -2060
- package/src/subgraph/scope.ts +0 -177
- package/src/subgraph/stats.ts +0 -42
- package/src/subgraph/template-instances.ts +0 -66
- package/src/subgraph/toolchain.ts +0 -327
- package/src/subgraph/transient.ts +0 -176
package/src/UserContext.res.mjs
CHANGED
|
@@ -1,85 +1,18 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
|
-
import * as Env from "./Env.res.mjs";
|
|
4
3
|
import * as Utils from "./Utils.res.mjs";
|
|
5
4
|
import * as Logger from "./Logger.res.mjs";
|
|
6
|
-
import * as ChainId from "./ChainId.res.mjs";
|
|
7
|
-
import * as EntityId from "./EntityId.res.mjs";
|
|
8
5
|
import * as Internal from "./Internal.res.mjs";
|
|
9
6
|
import * as RunScope from "./RunScope.res.mjs";
|
|
10
7
|
import * as LoadLayer from "./LoadLayer.res.mjs";
|
|
11
|
-
import * as SyncWrites from "./SyncWrites.res.mjs";
|
|
12
8
|
import * as EntityFilter from "./db/EntityFilter.res.mjs";
|
|
9
|
+
import * as IndexerState from "./IndexerState.res.mjs";
|
|
13
10
|
import * as InMemoryStore from "./InMemoryStore.res.mjs";
|
|
14
11
|
import * as InMemoryTable from "./InMemoryTable.res.mjs";
|
|
15
12
|
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
16
13
|
import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js";
|
|
17
|
-
import * as Stdlib_Promise from "@rescript/runtime/lib/es6/Stdlib_Promise.js";
|
|
18
|
-
import * as PreloadLookahead from "./PreloadLookahead.res.mjs";
|
|
19
14
|
import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
|
|
20
15
|
import * as S$RescriptSchema from "rescript-schema/src/S.res.mjs";
|
|
21
|
-
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
|
|
22
|
-
|
|
23
|
-
let Suspend = /* @__PURE__ */Primitive_exceptions.create("UserContext.Suspend");
|
|
24
|
-
|
|
25
|
-
function isSuspend(exn) {
|
|
26
|
-
return exn.RE_EXN_ID === Suspend;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
let suspend = {
|
|
30
|
-
RE_EXN_ID: Suspend
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
let currentSync = {
|
|
34
|
-
contents: undefined
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
function syncOf(run) {
|
|
38
|
-
let sync = currentSync.contents;
|
|
39
|
-
if (sync !== undefined && sync.run === run) {
|
|
40
|
-
return sync;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function currentRunOrThrow(prop) {
|
|
45
|
-
let run = RunScope.currentHandlerRunOrThrow(prop);
|
|
46
|
-
let match = syncOf(run);
|
|
47
|
-
if (match !== undefined) {
|
|
48
|
-
let exn = match.status;
|
|
49
|
-
if (typeof exn === "object") {
|
|
50
|
-
throw exn._0;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return run;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function syncOrThrow(run, prop) {
|
|
57
|
-
let sync = syncOf(run);
|
|
58
|
-
if (sync !== undefined) {
|
|
59
|
-
return sync;
|
|
60
|
-
} else {
|
|
61
|
-
return Stdlib_JsError.throwWithMessage(`context.` + prop + ` is only available inside context.runSync.`);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function scheduleAndSuspend(sync, promise) {
|
|
66
|
-
sync.pending.push(promise);
|
|
67
|
-
sync.status = {
|
|
68
|
-
TAG: "Aborted",
|
|
69
|
-
_0: suspend
|
|
70
|
-
};
|
|
71
|
-
throw suspend;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function missOrSuspend(sync, promise, absent) {
|
|
75
|
-
if (sync.run.isPreload && sync.speculated < 32) {
|
|
76
|
-
sync.pending.push(promise);
|
|
77
|
-
sync.speculated = sync.speculated + 1 | 0;
|
|
78
|
-
return absent;
|
|
79
|
-
} else {
|
|
80
|
-
return scheduleAndSuspend(sync, promise);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
16
|
|
|
84
17
|
let effectContextPrototype = (Object.create(null));
|
|
85
18
|
|
|
@@ -113,7 +46,7 @@ function isCrossChain(params, effect) {
|
|
|
113
46
|
return Stdlib_Option.getOr(effect.crossChain, params.config.defaultCrossChain);
|
|
114
47
|
}
|
|
115
48
|
|
|
116
|
-
function
|
|
49
|
+
function callEffect(params, run, caller, effect, input) {
|
|
117
50
|
let handlerChainId = Internal.getItemChainId(run.item);
|
|
118
51
|
let scope = isCrossChain(params, effect) ? "crossChain" : handlerChainId;
|
|
119
52
|
if (caller !== undefined && scope !== "crossChain") {
|
|
@@ -128,59 +61,13 @@ function prepareEffectCall(params, run, caller, effect, input) {
|
|
|
128
61
|
caller: run,
|
|
129
62
|
effectName: effect.name
|
|
130
63
|
});
|
|
131
|
-
|
|
132
|
-
let effectArgs_checkpointId = run.checkpointId;
|
|
133
|
-
let effectArgs = {
|
|
64
|
+
return LoadLayer.loadEffect(params.loadManager, params.persistence, effect, {
|
|
134
65
|
input: input,
|
|
135
66
|
context: effectContext,
|
|
136
|
-
cacheKey:
|
|
67
|
+
cacheKey: Utils.Hash.makeOrThrow(S$RescriptSchema.reverseConvertOrThrow(input, effect.input)),
|
|
137
68
|
chainId: handlerChainId,
|
|
138
|
-
checkpointId:
|
|
139
|
-
};
|
|
140
|
-
return [
|
|
141
|
-
scope,
|
|
142
|
-
effectArgs
|
|
143
|
-
];
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
function callEffect(params, run, caller, effect, input) {
|
|
147
|
-
let match = prepareEffectCall(params, run, caller, effect, input);
|
|
148
|
-
return LoadLayer.loadEffect(params.loadManager, params.persistence, effect, match[1], match[0], params.indexerState, run.isPreload);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
function effectMemoKey(effect, scope, cacheKey) {
|
|
152
|
-
if (scope === "crossChain") {
|
|
153
|
-
return effect.name + `.` + cacheKey;
|
|
154
|
-
} else {
|
|
155
|
-
return effect.name + `.` + ChainId.toString(scope) + `.` + cacheKey;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
function effectSync(params, effect, input) {
|
|
160
|
-
let run = currentRunOrThrow("effectSync");
|
|
161
|
-
let sync = syncOrThrow(run, "effectSync");
|
|
162
|
-
let match = prepareEffectCall(params, run, undefined, effect, input);
|
|
163
|
-
let effectArgs = match[1];
|
|
164
|
-
let scope = match[0];
|
|
165
|
-
let memoKey = effectMemoKey(effect, scope, effectArgs.cacheKey);
|
|
166
|
-
let output = sync.memo[memoKey];
|
|
167
|
-
if (output !== undefined) {
|
|
168
|
-
return Primitive_option.valFromOption(output);
|
|
169
|
-
}
|
|
170
|
-
let inMemTable = InMemoryStore.getEffectInMemTable(params.indexerState, effect, scope);
|
|
171
|
-
if (InMemoryStore.hasEffectOutput(inMemTable, effectArgs.cacheKey)) {
|
|
172
|
-
let output$1 = InMemoryStore.getEffectOutputUnsafe(inMemTable, effectArgs.cacheKey);
|
|
173
|
-
sync.memo[memoKey] = output$1;
|
|
174
|
-
return output$1;
|
|
175
|
-
}
|
|
176
|
-
if (sync.speculated <= 0) {
|
|
177
|
-
return scheduleAndSuspend(sync, LoadLayer.loadEffect(params.loadManager, params.persistence, effect, effectArgs, scope, params.indexerState, run.isPreload));
|
|
178
|
-
}
|
|
179
|
-
sync.status = {
|
|
180
|
-
TAG: "Aborted",
|
|
181
|
-
_0: suspend
|
|
182
|
-
};
|
|
183
|
-
throw suspend;
|
|
69
|
+
checkpointId: run.checkpointId
|
|
70
|
+
}, scope, params.indexerState, run.isPreload);
|
|
184
71
|
}
|
|
185
72
|
|
|
186
73
|
function expiresUnread(entityConfig) {
|
|
@@ -198,43 +85,35 @@ function throwExpiresUnread(entityConfig, op) {
|
|
|
198
85
|
|
|
199
86
|
function makeEntityContext(params, entityConfig) {
|
|
200
87
|
let prop = entityConfig.name;
|
|
201
|
-
let entityName = entityConfig.name;
|
|
202
88
|
let scopeOf = run => InMemoryStore.entityScope(entityConfig, Internal.getItemChainId(run.item));
|
|
203
89
|
let loadById = entityId => {
|
|
204
|
-
let run =
|
|
90
|
+
let run = RunScope.currentHandlerRunOrThrow(prop);
|
|
205
91
|
return LoadLayer.loadById(params.loadManager, params.persistence, entityConfig, scopeOf(run), params.indexerState, run.isPreload, entityId);
|
|
206
92
|
};
|
|
207
93
|
let write = (run, change) => {
|
|
208
|
-
let
|
|
209
|
-
|
|
210
|
-
if (match !== undefined) {
|
|
211
|
-
if (match$1 && !PreloadLookahead.isActive()) {
|
|
212
|
-
return;
|
|
213
|
-
} else {
|
|
214
|
-
return SyncWrites.record(match.writes, entityConfig, scopeOf(run), change);
|
|
215
|
-
}
|
|
216
|
-
} else if (match$1) {
|
|
217
|
-
return;
|
|
218
|
-
} else {
|
|
219
|
-
return SyncWrites.write(params.indexerState, entityConfig, scopeOf(run), change);
|
|
220
|
-
}
|
|
94
|
+
let scope = scopeOf(run);
|
|
95
|
+
InMemoryTable.Entity.set(InMemoryStore.getInMemTable(params.indexerState, entityConfig, scope), IndexerState.committedCheckpointIdFor(params.indexerState, scope), change);
|
|
221
96
|
};
|
|
222
97
|
let set = entity => {
|
|
223
|
-
let run =
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
98
|
+
let run = RunScope.currentHandlerRunOrThrow(prop);
|
|
99
|
+
if (!run.isPreload) {
|
|
100
|
+
return write(run, {
|
|
101
|
+
type: "SET",
|
|
102
|
+
entityId: entity.id,
|
|
103
|
+
entity: entity,
|
|
104
|
+
checkpointId: run.checkpointId
|
|
105
|
+
});
|
|
106
|
+
}
|
|
230
107
|
};
|
|
231
108
|
let deleteUnsafe = entityId => {
|
|
232
|
-
let run =
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
109
|
+
let run = RunScope.currentHandlerRunOrThrow(prop);
|
|
110
|
+
if (!run.isPreload) {
|
|
111
|
+
return write(run, {
|
|
112
|
+
type: "DELETE",
|
|
113
|
+
entityId: entityId,
|
|
114
|
+
checkpointId: run.checkpointId
|
|
115
|
+
});
|
|
116
|
+
}
|
|
238
117
|
};
|
|
239
118
|
let entityContext = expiresUnread(entityConfig) ? ({
|
|
240
119
|
get: param => throwExpiresUnread(entityConfig, "get"),
|
|
@@ -246,7 +125,7 @@ function makeEntityContext(params, entityConfig) {
|
|
|
246
125
|
}) : ({
|
|
247
126
|
get: loadById,
|
|
248
127
|
getWhere: filter => {
|
|
249
|
-
let run =
|
|
128
|
+
let run = RunScope.currentHandlerRunOrThrow(prop);
|
|
250
129
|
return LoadLayer.loadByFilter(params.loadManager, params.persistence, entityConfig, scopeOf(run), params.indexerState, run.isPreload, filter);
|
|
251
130
|
},
|
|
252
131
|
getOrThrow: (entityId, message) => loadById(entityId).then(entity => {
|
|
@@ -267,135 +146,7 @@ function makeEntityContext(params, entityConfig) {
|
|
|
267
146
|
set: set,
|
|
268
147
|
deleteUnsafe: deleteUnsafe
|
|
269
148
|
});
|
|
270
|
-
|
|
271
|
-
if (!Env.subgraphMode.contents) {
|
|
272
|
-
return object;
|
|
273
|
-
}
|
|
274
|
-
let syncEntityContext_getSync = entityId => {
|
|
275
|
-
let run = currentRunOrThrow(prop);
|
|
276
|
-
let sync = syncOrThrow(run, prop + `.getSync`);
|
|
277
|
-
let scope = scopeOf(run);
|
|
278
|
-
let entity = SyncWrites.getById(sync.writes, entityConfig, entityId);
|
|
279
|
-
if (entity !== undefined) {
|
|
280
|
-
return Primitive_option.valFromOption(entity);
|
|
281
|
-
}
|
|
282
|
-
let entity$1 = run.isPreload ? PreloadLookahead.overlayGet(run.item, entityName, scope, entityId) : undefined;
|
|
283
|
-
if (entity$1 !== undefined) {
|
|
284
|
-
return Primitive_option.valFromOption(entity$1);
|
|
285
|
-
}
|
|
286
|
-
let entity$2 = LoadLayer.getByIdInMemory(entityConfig, scope, params.indexerState, entityId);
|
|
287
|
-
if (entity$2 === undefined) {
|
|
288
|
-
return missOrSuspend(sync, LoadLayer.loadById(params.loadManager, params.persistence, entityConfig, scope, params.indexerState, run.isPreload, entityId), undefined);
|
|
289
|
-
}
|
|
290
|
-
let entity$3 = Primitive_option.valFromOption(entity$2);
|
|
291
|
-
if (run.isPreload && Stdlib_Option.isNone(entity$3)) {
|
|
292
|
-
PreloadLookahead.recordAbsent(run.item, entityName, scope, entityId);
|
|
293
|
-
}
|
|
294
|
-
return entity$3;
|
|
295
|
-
};
|
|
296
|
-
let syncEntityContext_getWhereSync = filter => {
|
|
297
|
-
let run = currentRunOrThrow(prop);
|
|
298
|
-
let sync = syncOrThrow(run, prop + `.getWhereSync`);
|
|
299
|
-
let scope = scopeOf(run);
|
|
300
|
-
let filter$1 = EntityFilter.parseOrThrow(filter, entityName, entityConfig.table);
|
|
301
|
-
let entities = LoadLayer.getByFilterInMemory(entityConfig, scope, params.indexerState, filter$1);
|
|
302
|
-
if (entities !== undefined) {
|
|
303
|
-
return SyncWrites.overlayFilter(sync.writes, entities, entityConfig, filter$1);
|
|
304
|
-
} else {
|
|
305
|
-
return missOrSuspend(sync, LoadLayer.loadByParsedFilter(params.loadManager, params.persistence, entityConfig, scope, params.indexerState, run.isPreload, filter$1), []);
|
|
306
|
-
}
|
|
307
|
-
};
|
|
308
|
-
let syncEntityContext_getInBlockSync = entityId => {
|
|
309
|
-
let run = currentRunOrThrow(prop);
|
|
310
|
-
let sync = syncOrThrow(run, prop + `.getInBlockSync`);
|
|
311
|
-
let entity = SyncWrites.getById(sync.writes, entityConfig, entityId);
|
|
312
|
-
if (entity !== undefined) {
|
|
313
|
-
return Primitive_option.valFromOption(entity);
|
|
314
|
-
}
|
|
315
|
-
let inMemTable = InMemoryStore.getInMemTable(params.indexerState, entityConfig, scopeOf(run));
|
|
316
|
-
let change = inMemTable.latestEntityChangeById[entityId];
|
|
317
|
-
if (change !== undefined && change.checkpointId === run.checkpointId) {
|
|
318
|
-
return InMemoryTable.Entity.mapChangeToEntity(change);
|
|
319
|
-
}
|
|
320
|
-
};
|
|
321
|
-
let syncEntityContext = {
|
|
322
|
-
getSync: syncEntityContext_getSync,
|
|
323
|
-
getWhereSync: syncEntityContext_getWhereSync,
|
|
324
|
-
getInBlockSync: syncEntityContext_getInBlockSync
|
|
325
|
-
};
|
|
326
|
-
return Object.assign(object, syncEntityContext);
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
async function runSyncRound(params, sync, fn, round) {
|
|
330
|
-
if (round > 10000) {
|
|
331
|
-
Stdlib_JsError.throwWithMessage(`The handler suspended on a synchronous read too many times: gave up after ` + (10000).toString() + ` rounds. This usually means the code isn't deterministic across reruns.`);
|
|
332
|
-
}
|
|
333
|
-
let run = sync.run;
|
|
334
|
-
sync.status = "Active";
|
|
335
|
-
sync.pending = [];
|
|
336
|
-
sync.speculated = 0;
|
|
337
|
-
sync.writes = SyncWrites.make();
|
|
338
|
-
let startedAt = PreloadLookahead.roundStarted(run.isPreload);
|
|
339
|
-
let previous = currentSync.contents;
|
|
340
|
-
currentSync.contents = sync;
|
|
341
|
-
let outcome;
|
|
342
|
-
try {
|
|
343
|
-
fn();
|
|
344
|
-
outcome = {
|
|
345
|
-
TAG: "Ok",
|
|
346
|
-
_0: undefined
|
|
347
|
-
};
|
|
348
|
-
} catch (raw_exn) {
|
|
349
|
-
let exn = Primitive_exceptions.internalToException(raw_exn);
|
|
350
|
-
outcome = {
|
|
351
|
-
TAG: "Error",
|
|
352
|
-
_0: exn
|
|
353
|
-
};
|
|
354
|
-
}
|
|
355
|
-
currentSync.contents = previous;
|
|
356
|
-
PreloadLookahead.roundEnded(run.item, startedAt);
|
|
357
|
-
let writes = sync.writes;
|
|
358
|
-
sync.writes = SyncWrites.make();
|
|
359
|
-
let suspended;
|
|
360
|
-
if (outcome.TAG === "Ok") {
|
|
361
|
-
let match = sync.status;
|
|
362
|
-
if (typeof match !== "object" && sync.speculated <= 0) {
|
|
363
|
-
if (run.isPreload) {
|
|
364
|
-
SyncWrites.forEachChange(writes, (entityConfig, scope, change) => PreloadLookahead.overlaySet(run.item, entityConfig.name, scope, EntityId.toKey(change.entityId), InMemoryTable.Entity.mapChangeToEntity(change)));
|
|
365
|
-
} else {
|
|
366
|
-
SyncWrites.commit(writes, params.indexerState);
|
|
367
|
-
}
|
|
368
|
-
suspended = false;
|
|
369
|
-
} else {
|
|
370
|
-
suspended = true;
|
|
371
|
-
}
|
|
372
|
-
} else {
|
|
373
|
-
let exn$1 = outcome._0;
|
|
374
|
-
if (exn$1.RE_EXN_ID === Suspend || sync.speculated > 0) {
|
|
375
|
-
suspended = true;
|
|
376
|
-
} else {
|
|
377
|
-
sync.pending.forEach(promise => {
|
|
378
|
-
promise.catch(param => {});
|
|
379
|
-
});
|
|
380
|
-
sync.pending = [];
|
|
381
|
-
throw exn$1;
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
if (!suspended) {
|
|
385
|
-
return;
|
|
386
|
-
}
|
|
387
|
-
let pending = sync.pending;
|
|
388
|
-
sync.pending = [];
|
|
389
|
-
let errors = [];
|
|
390
|
-
await Promise.all(pending.map(promise => Stdlib_Promise.$$catch(promise, exn => {
|
|
391
|
-
errors.push(exn);
|
|
392
|
-
return Promise.resolve();
|
|
393
|
-
})));
|
|
394
|
-
let exn$2 = errors[0];
|
|
395
|
-
if (exn$2 !== undefined) {
|
|
396
|
-
throw exn$2;
|
|
397
|
-
}
|
|
398
|
-
return await runSyncRound(params, sync, fn, round + 1 | 0);
|
|
149
|
+
return Object.assign(Object.create(Utils.StrictObject.makePrototype(op => Stdlib_JsError.throwWithMessage(`Invalid context.` + entityConfig.name + `.` + op + ` operation.`))), entityContext);
|
|
399
150
|
}
|
|
400
151
|
|
|
401
152
|
function makeHandlerContext(params) {
|
|
@@ -403,7 +154,7 @@ function makeHandlerContext(params) {
|
|
|
403
154
|
let define = (name, get) => {
|
|
404
155
|
Object.defineProperty(context, name, {
|
|
405
156
|
enumerable: true,
|
|
406
|
-
get: () => get(
|
|
157
|
+
get: () => get(RunScope.currentHandlerRunOrThrow(name))
|
|
407
158
|
});
|
|
408
159
|
};
|
|
409
160
|
define("log", run => {
|
|
@@ -413,31 +164,11 @@ function makeHandlerContext(params) {
|
|
|
413
164
|
return Logger.asContextLog(RunScope.handlerLogger(run));
|
|
414
165
|
}
|
|
415
166
|
});
|
|
416
|
-
let effect = (effect$1, input) => callEffect(params,
|
|
167
|
+
let effect = (effect$1, input) => callEffect(params, RunScope.currentHandlerRunOrThrow("effect"), undefined, effect$1, input);
|
|
417
168
|
Object.defineProperty(context, "effect", {
|
|
418
169
|
enumerable: true,
|
|
419
170
|
value: effect
|
|
420
171
|
});
|
|
421
|
-
if (Env.subgraphMode.contents) {
|
|
422
|
-
Object.defineProperty(context, "effectSync", {
|
|
423
|
-
enumerable: true,
|
|
424
|
-
value: (effect, input) => effectSync(params, effect, input)
|
|
425
|
-
});
|
|
426
|
-
Object.defineProperty(context, "runSync", {
|
|
427
|
-
enumerable: true,
|
|
428
|
-
value: fn => {
|
|
429
|
-
let run = currentRunOrThrow("runSync");
|
|
430
|
-
return runSyncRound(params, {
|
|
431
|
-
run: run,
|
|
432
|
-
status: "Active",
|
|
433
|
-
pending: [],
|
|
434
|
-
memo: {},
|
|
435
|
-
writes: SyncWrites.make(),
|
|
436
|
-
speculated: 0
|
|
437
|
-
}, fn, 1);
|
|
438
|
-
}
|
|
439
|
-
});
|
|
440
|
-
}
|
|
441
172
|
define("isPreload", run => run.isPreload);
|
|
442
173
|
define("chain", run => params.chains[Internal.getItemChainId(run.item)]);
|
|
443
174
|
Utils.Dict.forEachWithKey(params.config.userEntitiesByName, (entityConfig, name) => {
|
|
@@ -447,32 +178,13 @@ function makeHandlerContext(params) {
|
|
|
447
178
|
return context;
|
|
448
179
|
}
|
|
449
180
|
|
|
450
|
-
let maxSpeculatedReads = 32;
|
|
451
|
-
|
|
452
|
-
let maxSyncRounds = 10000;
|
|
453
|
-
|
|
454
181
|
export {
|
|
455
|
-
Suspend,
|
|
456
|
-
isSuspend,
|
|
457
|
-
suspend,
|
|
458
|
-
currentSync,
|
|
459
|
-
syncOf,
|
|
460
|
-
currentRunOrThrow,
|
|
461
|
-
syncOrThrow,
|
|
462
|
-
scheduleAndSuspend,
|
|
463
|
-
maxSpeculatedReads,
|
|
464
|
-
missOrSuspend,
|
|
465
182
|
effectContextPrototype,
|
|
466
183
|
isCrossChain,
|
|
467
|
-
prepareEffectCall,
|
|
468
184
|
callEffect,
|
|
469
|
-
effectMemoKey,
|
|
470
|
-
effectSync,
|
|
471
185
|
expiresUnread,
|
|
472
186
|
throwExpiresUnread,
|
|
473
187
|
makeEntityContext,
|
|
474
|
-
maxSyncRounds,
|
|
475
|
-
runSyncRound,
|
|
476
188
|
makeHandlerContext,
|
|
477
189
|
}
|
|
478
190
|
/* effectContextPrototype Not a pure module */
|
package/src/Utils.res
CHANGED
|
@@ -10,12 +10,6 @@ external toMethod: 'a => 'a = "%unsafe_to_method"
|
|
|
10
10
|
|
|
11
11
|
@val external importPath: string => promise<unknown> = "import"
|
|
12
12
|
|
|
13
|
-
// Half the delay fixed, half spread across it. Every indexer pointed at one
|
|
14
|
-
// provider loses its stream, or gives up on a quiet chain, in the same instant
|
|
15
|
-
// that provider blinks, and putting them all back on the same schedule is how a
|
|
16
|
-
// blip becomes a stampede.
|
|
17
|
-
let jitter = delay => delay / 2 + (Math.random() *. (delay / 2)->Int.toFloat)->Float.toInt
|
|
18
|
-
|
|
19
13
|
// Clearing a pending timer and forgetting it are one action. A ref left holding
|
|
20
14
|
// a spent id reads as a timer still pending, and the next clear looks like it
|
|
21
15
|
// did something.
|
|
@@ -887,23 +881,6 @@ module Hash = {
|
|
|
887
881
|
(any->magic)["toString"]()
|
|
888
882
|
}
|
|
889
883
|
}
|
|
890
|
-
|
|
891
|
-
type sha256
|
|
892
|
-
@module("node:crypto") external createSha256: (@as("sha256") _, unit) => sha256 = "createHash"
|
|
893
|
-
@send external update: (sha256, string) => sha256 = "update"
|
|
894
|
-
@send external digestHex: (sha256, @as("hex") _) => string = "digest"
|
|
895
|
-
@val @scope("Buffer") external byteLength: string => int = "byteLength"
|
|
896
|
-
|
|
897
|
-
// A cache row is keyed by its effect's input, and a Postgres btree key takes
|
|
898
|
-
// at most 2704 bytes: a contract call with a large argument (calldata of a
|
|
899
|
-
// few kB) failed the batch write. Such inputs are keyed by their sha256;
|
|
900
|
-
// every shorter input keeps the key it always had.
|
|
901
|
-
let maxRawCacheKeyBytes = 2000
|
|
902
|
-
|
|
903
|
-
let boundCacheKey = (key: string) =>
|
|
904
|
-
key->byteLength > maxRawCacheKeyBytes
|
|
905
|
-
? "sha256:" ++ createSha256()->update(key)->digestHex
|
|
906
|
-
: key
|
|
907
884
|
}
|
|
908
885
|
|
|
909
886
|
let prettifyExn = exn => {
|
package/src/Utils.res.mjs
CHANGED
|
@@ -2,7 +2,6 @@ import packageJson from '../package.json' with { type: 'json' }
|
|
|
2
2
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
3
3
|
|
|
4
4
|
import * as Stdlib_Dict from "@rescript/runtime/lib/es6/Stdlib_Dict.js";
|
|
5
|
-
import * as Nodecrypto from "node:crypto";
|
|
6
5
|
import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
|
|
7
6
|
import * as Stdlib_JsExn from "@rescript/runtime/lib/es6/Stdlib_JsExn.js";
|
|
8
7
|
import * as Primitive_int from "@rescript/runtime/lib/es6/Primitive_int.js";
|
|
@@ -14,10 +13,6 @@ import * as Primitive_string from "@rescript/runtime/lib/es6/Primitive_string.js
|
|
|
14
13
|
import * as S$RescriptSchema from "rescript-schema/src/S.res.mjs";
|
|
15
14
|
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
|
|
16
15
|
|
|
17
|
-
function jitter(delay) {
|
|
18
|
-
return (delay / 2 | 0) + (Math.random() * (delay / 2 | 0) | 0) | 0;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
16
|
function clearTimeoutRef(timeoutId) {
|
|
22
17
|
let id = timeoutId.contents;
|
|
23
18
|
if (id !== undefined) {
|
|
@@ -749,19 +744,9 @@ function makeOrThrow(any) {
|
|
|
749
744
|
return hash$1 + "}";
|
|
750
745
|
}
|
|
751
746
|
|
|
752
|
-
function boundCacheKey(key) {
|
|
753
|
-
if (Buffer.byteLength(key) > 2000) {
|
|
754
|
-
return "sha256:" + Nodecrypto.createHash("sha256").update(key).digest("hex");
|
|
755
|
-
} else {
|
|
756
|
-
return key;
|
|
757
|
-
}
|
|
758
|
-
}
|
|
759
|
-
|
|
760
747
|
let Hash = {
|
|
761
748
|
fail: fail,
|
|
762
|
-
makeOrThrow: makeOrThrow
|
|
763
|
-
maxRawCacheKeyBytes: 2000,
|
|
764
|
-
boundCacheKey: boundCacheKey
|
|
749
|
+
makeOrThrow: makeOrThrow
|
|
765
750
|
};
|
|
766
751
|
|
|
767
752
|
function prettifyExn(exn) {
|
|
@@ -824,7 +809,6 @@ function replaceLoneSurrogateEscapes(json) {
|
|
|
824
809
|
let maxBackoffExponent = 20;
|
|
825
810
|
|
|
826
811
|
export {
|
|
827
|
-
jitter,
|
|
828
812
|
clearTimeoutRef,
|
|
829
813
|
maxBackoffExponent,
|
|
830
814
|
expBackoff,
|
package/src/Writing.res
CHANGED
package/src/Writing.res.mjs
CHANGED
|
@@ -121,7 +121,7 @@ async function runOneWrite(state) {
|
|
|
121
121
|
});
|
|
122
122
|
let pruneTargets = PruneStaleHistory.select(state, writtenEntityNames, Stdlib_Option.isSome(rollback));
|
|
123
123
|
await Promise.all([
|
|
124
|
-
persistence.storage.writeBatch(batch, rollback, config,
|
|
124
|
+
persistence.storage.writeBatch(batch, rollback, config, updatedEffectsCache, updatedEntities, registeredAddresses, chainMetaData, (storage, timeSeconds) => IndexerState.recordStorageWrite(state, storage, timeSeconds)),
|
|
125
125
|
PruneStaleHistory.runConcurrent(state, pruneTargets)
|
|
126
126
|
]);
|
|
127
127
|
IndexerState.markCommitted(state, writtenFrontier);
|