envio 3.0.0-alpha.2 → 3.0.0-alpha.21
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 +164 -30
- package/bin.mjs +49 -0
- package/evm.schema.json +79 -169
- package/fuel.schema.json +50 -21
- package/index.d.ts +578 -1
- package/index.js +4 -0
- package/package.json +47 -31
- package/rescript.json +4 -1
- package/src/Batch.res +11 -8
- package/src/Batch.res.mjs +11 -9
- package/src/ChainFetcher.res +531 -0
- package/src/ChainFetcher.res.mjs +339 -0
- package/src/ChainManager.res +190 -0
- package/src/ChainManager.res.mjs +166 -0
- package/src/Change.res +3 -3
- package/src/Config.gen.ts +19 -0
- package/src/Config.res +725 -25
- package/src/Config.res.mjs +692 -26
- package/src/{Indexer.res → Ctx.res} +1 -1
- package/src/Ecosystem.res +9 -124
- package/src/Ecosystem.res.mjs +19 -160
- package/src/Env.res +33 -73
- package/src/Env.res.mjs +29 -85
- package/src/Envio.gen.ts +3 -1
- package/src/Envio.res +77 -9
- package/src/Envio.res.mjs +39 -1
- package/src/EventConfigBuilder.res +408 -0
- package/src/EventConfigBuilder.res.mjs +376 -0
- package/src/EventProcessing.res +469 -0
- package/src/EventProcessing.res.mjs +337 -0
- package/src/EvmTypes.gen.ts +6 -0
- package/src/EvmTypes.res +1 -0
- package/src/FetchState.res +1256 -639
- package/src/FetchState.res.mjs +1135 -612
- package/src/GlobalState.res +1224 -0
- package/src/GlobalState.res.mjs +1291 -0
- package/src/GlobalStateManager.res +68 -0
- package/src/GlobalStateManager.res.mjs +75 -0
- package/src/GlobalStateManager.resi +7 -0
- package/src/HandlerLoader.res +89 -0
- package/src/HandlerLoader.res.mjs +79 -0
- package/src/HandlerRegister.res +357 -0
- package/src/HandlerRegister.res.mjs +299 -0
- package/src/HandlerRegister.resi +30 -0
- package/src/Hasura.res +111 -175
- package/src/Hasura.res.mjs +88 -150
- package/src/InMemoryStore.res +1 -1
- package/src/InMemoryStore.res.mjs +3 -3
- package/src/InMemoryTable.res +1 -1
- package/src/InMemoryTable.res.mjs +1 -1
- package/src/Internal.gen.ts +6 -0
- package/src/Internal.res +265 -12
- package/src/Internal.res.mjs +115 -1
- package/src/LoadLayer.res +444 -0
- package/src/LoadLayer.res.mjs +296 -0
- package/src/LoadLayer.resi +32 -0
- package/src/LogSelection.res +33 -27
- package/src/LogSelection.res.mjs +6 -0
- package/src/Logging.res +21 -7
- package/src/Logging.res.mjs +16 -8
- package/src/Main.res +390 -0
- package/src/Main.res.mjs +341 -0
- package/src/Persistence.res +7 -21
- package/src/Persistence.res.mjs +3 -3
- package/src/PgStorage.gen.ts +10 -0
- package/src/PgStorage.res +116 -69
- package/src/PgStorage.res.d.mts +5 -0
- package/src/PgStorage.res.mjs +93 -50
- package/src/Prometheus.res +294 -224
- package/src/Prometheus.res.mjs +353 -340
- package/src/ReorgDetection.res +6 -10
- package/src/ReorgDetection.res.mjs +6 -6
- package/src/SafeCheckpointTracking.res +4 -4
- package/src/SafeCheckpointTracking.res.mjs +2 -2
- package/src/SimulateItems.res +353 -0
- package/src/SimulateItems.res.mjs +335 -0
- package/src/Sink.res +4 -2
- package/src/Sink.res.mjs +2 -1
- package/src/TableIndices.res +0 -1
- package/src/TestIndexer.res +913 -0
- package/src/TestIndexer.res.mjs +698 -0
- package/src/TestIndexerProxyStorage.res +205 -0
- package/src/TestIndexerProxyStorage.res.mjs +151 -0
- package/src/TopicFilter.res +1 -1
- package/src/Types.ts +1 -1
- package/src/UserContext.res +424 -0
- package/src/UserContext.res.mjs +279 -0
- package/src/Utils.res +97 -26
- package/src/Utils.res.mjs +91 -44
- package/src/bindings/BigInt.res +10 -0
- package/src/bindings/BigInt.res.mjs +15 -0
- package/src/bindings/ClickHouse.res +120 -23
- package/src/bindings/ClickHouse.res.mjs +118 -28
- package/src/bindings/DateFns.res +74 -0
- package/src/bindings/DateFns.res.mjs +22 -0
- package/src/bindings/EventSource.res +11 -2
- package/src/bindings/EventSource.res.mjs +8 -1
- package/src/bindings/Express.res +1 -0
- package/src/bindings/Hrtime.res +14 -1
- package/src/bindings/Hrtime.res.mjs +22 -2
- package/src/bindings/Hrtime.resi +4 -0
- package/src/bindings/Lodash.res +0 -1
- package/src/bindings/NodeJs.res +49 -3
- package/src/bindings/NodeJs.res.mjs +11 -3
- package/src/bindings/Pino.res +24 -10
- package/src/bindings/Pino.res.mjs +14 -8
- package/src/bindings/Postgres.gen.ts +8 -0
- package/src/bindings/Postgres.res +5 -1
- package/src/bindings/Postgres.res.d.mts +5 -0
- package/src/bindings/PromClient.res +0 -10
- package/src/bindings/PromClient.res.mjs +0 -3
- package/src/bindings/Vitest.res +144 -0
- package/src/bindings/Vitest.res.mjs +9 -0
- package/src/bindings/WebSocket.res +27 -0
- package/src/bindings/WebSocket.res.mjs +2 -0
- package/src/bindings/Yargs.res +8 -0
- package/src/bindings/Yargs.res.mjs +2 -0
- package/src/db/EntityHistory.res +7 -7
- package/src/db/EntityHistory.res.mjs +9 -9
- package/src/db/InternalTable.res +59 -111
- package/src/db/InternalTable.res.mjs +73 -104
- package/src/db/Table.res +27 -8
- package/src/db/Table.res.mjs +25 -14
- package/src/sources/Evm.res +84 -0
- package/src/sources/Evm.res.mjs +105 -0
- package/src/sources/EvmChain.res +94 -0
- package/src/sources/EvmChain.res.mjs +60 -0
- package/src/sources/Fuel.res +19 -34
- package/src/sources/Fuel.res.mjs +34 -16
- package/src/sources/FuelSDK.res +38 -0
- package/src/sources/FuelSDK.res.mjs +29 -0
- package/src/sources/HyperFuel.res +2 -2
- package/src/sources/HyperFuel.resi +1 -1
- package/src/sources/HyperFuelClient.res +2 -2
- package/src/sources/HyperFuelSource.res +35 -13
- package/src/sources/HyperFuelSource.res.mjs +26 -16
- package/src/sources/HyperSync.res +61 -60
- package/src/sources/HyperSync.res.mjs +53 -67
- package/src/sources/HyperSync.resi +6 -4
- package/src/sources/HyperSyncClient.res +29 -2
- package/src/sources/HyperSyncClient.res.mjs +9 -0
- package/src/sources/HyperSyncHeightStream.res +76 -118
- package/src/sources/HyperSyncHeightStream.res.mjs +68 -75
- package/src/sources/HyperSyncSource.res +122 -143
- package/src/sources/HyperSyncSource.res.mjs +106 -121
- package/src/sources/Rpc.res +86 -14
- package/src/sources/Rpc.res.mjs +101 -9
- package/src/sources/RpcSource.res +731 -364
- package/src/sources/RpcSource.res.mjs +845 -410
- package/src/sources/RpcWebSocketHeightStream.res +181 -0
- package/src/sources/RpcWebSocketHeightStream.res.mjs +196 -0
- package/src/sources/SimulateSource.res +59 -0
- package/src/sources/SimulateSource.res.mjs +50 -0
- package/src/sources/Source.res +7 -5
- package/src/sources/SourceManager.res +358 -221
- package/src/sources/SourceManager.res.mjs +346 -171
- package/src/sources/SourceManager.resi +17 -6
- package/src/sources/Svm.res +81 -0
- package/src/sources/Svm.res.mjs +90 -0
- package/src/tui/Tui.res +247 -0
- package/src/tui/Tui.res.mjs +337 -0
- package/src/tui/bindings/Ink.res +371 -0
- package/src/tui/bindings/Ink.res.mjs +72 -0
- package/src/tui/bindings/Style.res +123 -0
- package/src/tui/bindings/Style.res.mjs +2 -0
- package/src/tui/components/BufferedProgressBar.res +40 -0
- package/src/tui/components/BufferedProgressBar.res.mjs +57 -0
- package/src/tui/components/CustomHooks.res +122 -0
- package/src/tui/components/CustomHooks.res.mjs +179 -0
- package/src/tui/components/Messages.res +41 -0
- package/src/tui/components/Messages.res.mjs +75 -0
- package/src/tui/components/SyncETA.res +174 -0
- package/src/tui/components/SyncETA.res.mjs +263 -0
- package/src/tui/components/TuiData.res +47 -0
- package/src/tui/components/TuiData.res.mjs +34 -0
- package/svm.schema.json +112 -0
- package/bin.js +0 -48
- package/src/EventRegister.res +0 -241
- package/src/EventRegister.res.mjs +0 -240
- package/src/EventRegister.resi +0 -30
- package/src/bindings/Ethers.gen.ts +0 -14
- package/src/bindings/Ethers.res +0 -204
- package/src/bindings/Ethers.res.mjs +0 -130
- /package/src/{Indexer.res.mjs → Ctx.res.mjs} +0 -0
package/index.d.ts
CHANGED
|
@@ -8,10 +8,57 @@ export type {
|
|
|
8
8
|
rateLimit as RateLimit,
|
|
9
9
|
blockEvent as BlockEvent,
|
|
10
10
|
fuelBlockEvent as FuelBlockEvent,
|
|
11
|
+
svmOnBlockArgs as SvmOnBlockArgs,
|
|
11
12
|
onBlockArgs as OnBlockArgs,
|
|
12
13
|
onBlockOptions as OnBlockOptions,
|
|
13
14
|
} from "./src/Envio.gen.ts";
|
|
14
|
-
|
|
15
|
+
import type { Address } from "./src/Types.ts";
|
|
16
|
+
export type { EffectCaller, Address } from "./src/Types.ts";
|
|
17
|
+
|
|
18
|
+
export const TestHelpers: {
|
|
19
|
+
Addresses: {
|
|
20
|
+
readonly mockAddresses: readonly [
|
|
21
|
+
Address, Address, Address, Address, Address,
|
|
22
|
+
Address, Address, Address, Address, Address,
|
|
23
|
+
Address, Address, Address, Address, Address,
|
|
24
|
+
Address, Address, Address, Address, Address,
|
|
25
|
+
];
|
|
26
|
+
readonly defaultAddress: Address;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/** Utility type to expand/flatten complex types for better IDE display. */
|
|
31
|
+
export type Prettify<T> = { [K in keyof T]: T[K] } & {};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Operator for filtering entity fields in getWhere queries.
|
|
35
|
+
* Only fields with `@index` in the schema can be queried at runtime.
|
|
36
|
+
*/
|
|
37
|
+
export type WhereOperator<T> = {
|
|
38
|
+
/** Matches entities where the field equals the given value. */
|
|
39
|
+
readonly _eq?: T;
|
|
40
|
+
/** Matches entities where the field is greater than the given value. */
|
|
41
|
+
readonly _gt?: T;
|
|
42
|
+
/** Matches entities where the field is less than the given value. */
|
|
43
|
+
readonly _lt?: T;
|
|
44
|
+
/** Matches entities where the field is greater than or equal to the given value. */
|
|
45
|
+
readonly _gte?: T;
|
|
46
|
+
/** Matches entities where the field is less than or equal to the given value. */
|
|
47
|
+
readonly _lte?: T;
|
|
48
|
+
/** Matches entities where the field equals any of the given values. */
|
|
49
|
+
readonly _in?: readonly T[];
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Constructs a getWhere filter type from an entity type.
|
|
54
|
+
* Each field can be filtered using {@link WhereOperator} (`_eq`, `_gt`, `_lt`, `_gte`, `_lte`, `_in`).
|
|
55
|
+
*
|
|
56
|
+
* Note: only fields with `@index` in the schema can be queried at runtime.
|
|
57
|
+
* Attempting to filter on a non-indexed field will throw a descriptive error.
|
|
58
|
+
*/
|
|
59
|
+
export type GetWhereFilter<E> = {
|
|
60
|
+
[K in keyof E]?: WhereOperator<E[K]>;
|
|
61
|
+
};
|
|
15
62
|
|
|
16
63
|
import type {
|
|
17
64
|
effect as Effect,
|
|
@@ -108,6 +155,10 @@ export declare namespace S {
|
|
|
108
155
|
export type Input<T> = Sury.Input<T>;
|
|
109
156
|
export type Schema<Output, Input = unknown> = Sury.Schema<Output, Input>;
|
|
110
157
|
export const string: typeof Sury.string;
|
|
158
|
+
export const address: Sury.Schema<Address, Address>;
|
|
159
|
+
// export const evmChainId: Sury.Schema<EvmChainId, EvmChainId>;
|
|
160
|
+
// export const fuelChainId: Sury.Schema<FuelChainId, FuelChainId>;
|
|
161
|
+
// export const svmChainId: Sury.Schema<SvmChainId, SvmChainId>;
|
|
111
162
|
export const jsonString: typeof Sury.jsonString;
|
|
112
163
|
export const boolean: typeof Sury.boolean;
|
|
113
164
|
export const int32: typeof Sury.int32;
|
|
@@ -137,3 +188,529 @@ export declare namespace S {
|
|
|
137
188
|
export const assertOrThrow: typeof Sury.assertOrThrow;
|
|
138
189
|
export const parseOrThrow: typeof Sury.parseOrThrow;
|
|
139
190
|
}
|
|
191
|
+
|
|
192
|
+
// ============== Indexer Config (Module Augmentation) ==============
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Configuration interface for the indexer.
|
|
196
|
+
* This interface is augmented by generated/envio.d.ts with project-specific config using typeof config.
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* // In generated/envio.d.ts:
|
|
200
|
+
* declare module "envio" {
|
|
201
|
+
* interface Global {
|
|
202
|
+
* config: typeof config;
|
|
203
|
+
* }
|
|
204
|
+
* }
|
|
205
|
+
*/
|
|
206
|
+
export interface Global {}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Shape of the indexer configuration.
|
|
210
|
+
* Will be used internally for defineConfig.
|
|
211
|
+
* Currently should match the internal.config.json structure.
|
|
212
|
+
*/
|
|
213
|
+
type IndexerConfig = {
|
|
214
|
+
/** The indexer name. */
|
|
215
|
+
name: string;
|
|
216
|
+
/** The indexer description. */
|
|
217
|
+
description?: string;
|
|
218
|
+
/** Path to handlers directory for auto-loading (default: "src/handlers"). */
|
|
219
|
+
handlers?: string;
|
|
220
|
+
/** Multichain mode: ordered or unordered (default: "unordered"). */
|
|
221
|
+
multichain?: "ordered" | "unordered";
|
|
222
|
+
/** Target batch size for event processing (default: 5000). */
|
|
223
|
+
fullBatchSize?: number;
|
|
224
|
+
/** Whether to rollback on chain reorg (default: true). */
|
|
225
|
+
rollbackOnReorg?: boolean;
|
|
226
|
+
/** Whether to save full entity history (default: false). */
|
|
227
|
+
saveFullHistory?: boolean;
|
|
228
|
+
/** Whether raw events are enabled (default: false). */
|
|
229
|
+
rawEvents?: boolean;
|
|
230
|
+
/** EVM ecosystem configuration. */
|
|
231
|
+
evm?: {
|
|
232
|
+
/** Chain configurations keyed by chain name. */
|
|
233
|
+
chains: Record<string, EvmChainConfig>;
|
|
234
|
+
/** Contract configurations keyed by contract name. */
|
|
235
|
+
contracts?: Record<string, EvmContractConfig>;
|
|
236
|
+
/** Address format (default: "checksum"). */
|
|
237
|
+
addressFormat?: "lowercase" | "checksum";
|
|
238
|
+
};
|
|
239
|
+
/** Fuel ecosystem configuration. */
|
|
240
|
+
fuel?: {
|
|
241
|
+
/** Chain configurations keyed by chain name. */
|
|
242
|
+
chains: Record<string, FuelChainConfig>;
|
|
243
|
+
/** Contract configurations keyed by contract name. */
|
|
244
|
+
contracts?: Record<string, FuelContractConfig>;
|
|
245
|
+
};
|
|
246
|
+
/** SVM ecosystem configuration. */
|
|
247
|
+
svm?: {
|
|
248
|
+
/** Chain configurations keyed by chain name. */
|
|
249
|
+
chains: Record<string, SvmChainConfig>;
|
|
250
|
+
};
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
// ============== Contract Types ==============
|
|
254
|
+
|
|
255
|
+
/** EVM contract configuration. */
|
|
256
|
+
type EvmContractConfig = {
|
|
257
|
+
/** The contract ABI. */
|
|
258
|
+
readonly abi: unknown;
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
/** Fuel contract configuration. */
|
|
262
|
+
type FuelContractConfig = {
|
|
263
|
+
/** The contract ABI. */
|
|
264
|
+
readonly abi: unknown;
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
// ============== EVM Types ==============
|
|
268
|
+
|
|
269
|
+
/** EVM chain configuration (for IndexerConfig). */
|
|
270
|
+
type EvmChainConfig<Id extends number = number> = {
|
|
271
|
+
/** The chain ID. */
|
|
272
|
+
readonly id: Id;
|
|
273
|
+
/** The block number indexing starts from. */
|
|
274
|
+
readonly startBlock: number;
|
|
275
|
+
/** The block number indexing stops at (if configured). */
|
|
276
|
+
readonly endBlock?: number;
|
|
277
|
+
/** Number of blocks to keep for reorg handling (default: 200). */
|
|
278
|
+
readonly maxReorgDepth?: number;
|
|
279
|
+
/** Number of blocks behind the chain head to lag (default: 0). */
|
|
280
|
+
readonly blockLag?: number;
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
/** EVM chain value (for runtime Indexer). */
|
|
284
|
+
type EvmChain<
|
|
285
|
+
Id extends number = number,
|
|
286
|
+
ContractName extends string = never
|
|
287
|
+
> = {
|
|
288
|
+
/** The chain ID. */
|
|
289
|
+
readonly id: Id;
|
|
290
|
+
/** The chain name. */
|
|
291
|
+
readonly name: string;
|
|
292
|
+
/** The block number indexing starts from. */
|
|
293
|
+
readonly startBlock: number;
|
|
294
|
+
/** The block number indexing stops at (if configured). */
|
|
295
|
+
readonly endBlock: number | undefined;
|
|
296
|
+
/** Whether the chain has completed initial sync and is processing live events. */
|
|
297
|
+
readonly isLive: boolean;
|
|
298
|
+
} & {
|
|
299
|
+
readonly [K in ContractName]: EvmContract<K>;
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
/** EVM contract (for runtime Indexer). */
|
|
303
|
+
type EvmContract<Name extends string = string> = {
|
|
304
|
+
/** The contract name. */
|
|
305
|
+
readonly name: Name;
|
|
306
|
+
/** The contract ABI. */
|
|
307
|
+
readonly abi: readonly unknown[];
|
|
308
|
+
/** The contract addresses. */
|
|
309
|
+
readonly addresses: readonly Address[];
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
/** Fuel contract (for runtime Indexer). */
|
|
313
|
+
type FuelContract<Name extends string = string> = {
|
|
314
|
+
/** The contract name. */
|
|
315
|
+
readonly name: Name;
|
|
316
|
+
/** The contract ABI. */
|
|
317
|
+
readonly abi: unknown;
|
|
318
|
+
/** The contract addresses. */
|
|
319
|
+
readonly addresses: readonly Address[];
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
// ============== Fuel Types ==============
|
|
323
|
+
|
|
324
|
+
/** Fuel chain configuration (for IndexerConfig). */
|
|
325
|
+
type FuelChainConfig<Id extends number = number> = {
|
|
326
|
+
/** The chain ID. */
|
|
327
|
+
readonly id: Id;
|
|
328
|
+
/** The block number indexing starts from. */
|
|
329
|
+
readonly startBlock: number;
|
|
330
|
+
/** The block number indexing stops at (if configured). */
|
|
331
|
+
readonly endBlock?: number;
|
|
332
|
+
/** Number of blocks to keep for reorg handling (default: 200). */
|
|
333
|
+
readonly maxReorgDepth?: number;
|
|
334
|
+
/** Number of blocks behind the chain head to lag (default: 0). */
|
|
335
|
+
readonly blockLag?: number;
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
/** Fuel chain value (for runtime Indexer). */
|
|
339
|
+
type FuelChain<
|
|
340
|
+
Id extends number = number,
|
|
341
|
+
ContractName extends string = never
|
|
342
|
+
> = {
|
|
343
|
+
/** The chain ID. */
|
|
344
|
+
readonly id: Id;
|
|
345
|
+
/** The chain name. */
|
|
346
|
+
readonly name: string;
|
|
347
|
+
/** The block number indexing starts from. */
|
|
348
|
+
readonly startBlock: number;
|
|
349
|
+
/** The block number indexing stops at (if configured). */
|
|
350
|
+
readonly endBlock: number | undefined;
|
|
351
|
+
/** Whether the chain has completed initial sync and is processing live events. */
|
|
352
|
+
readonly isLive: boolean;
|
|
353
|
+
} & {
|
|
354
|
+
readonly [K in ContractName]: FuelContract<K>;
|
|
355
|
+
};
|
|
356
|
+
|
|
357
|
+
// ============== SVM (Solana) Types ==============
|
|
358
|
+
|
|
359
|
+
/** SVM chain configuration (for IndexerConfig). */
|
|
360
|
+
type SvmChainConfig<Id extends number = number> = {
|
|
361
|
+
/** The chain ID. */
|
|
362
|
+
readonly id: Id;
|
|
363
|
+
/** The block number indexing starts from. */
|
|
364
|
+
readonly startBlock: number;
|
|
365
|
+
/** The block number indexing stops at (if configured). */
|
|
366
|
+
readonly endBlock?: number;
|
|
367
|
+
/** Number of blocks to keep for reorg handling (default: 200). */
|
|
368
|
+
readonly maxReorgDepth?: number;
|
|
369
|
+
/** Number of blocks behind the chain head to lag (default: 0). */
|
|
370
|
+
readonly blockLag?: number;
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
/** SVM chain value (for runtime Indexer). */
|
|
374
|
+
type SvmChain<Id extends number = number> = {
|
|
375
|
+
/** The chain ID. */
|
|
376
|
+
readonly id: Id;
|
|
377
|
+
/** The chain name. */
|
|
378
|
+
readonly name: string;
|
|
379
|
+
/** The block number indexing starts from. */
|
|
380
|
+
readonly startBlock: number;
|
|
381
|
+
/** The block number indexing stops at (if configured). */
|
|
382
|
+
readonly endBlock: number | undefined;
|
|
383
|
+
/** Whether the chain has completed initial sync and is processing live events. */
|
|
384
|
+
readonly isLive: boolean;
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
// ============== Indexer Type ==============
|
|
388
|
+
|
|
389
|
+
/** Minimal type constraint for IndexerFromConfig to allow usage without full IndexerConfig. */
|
|
390
|
+
type IndexerConfigTypes = {
|
|
391
|
+
evm?: {
|
|
392
|
+
chains: Record<string, { id: number }>;
|
|
393
|
+
contracts?: Record<string, Record<string, { eventName: string }>>;
|
|
394
|
+
};
|
|
395
|
+
fuel?: {
|
|
396
|
+
chains: Record<string, { id: number }>;
|
|
397
|
+
contracts?: Record<string, Record<string, { eventName: string }>>;
|
|
398
|
+
};
|
|
399
|
+
svm?: { chains: Record<string, { id: number }> };
|
|
400
|
+
entities?: Record<string, object>;
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
// Helper: Check if ecosystem is configured in a given config
|
|
404
|
+
type HasEvm<Config> = "evm" extends keyof Config ? true : false;
|
|
405
|
+
type HasFuel<Config> = "fuel" extends keyof Config ? true : false;
|
|
406
|
+
type HasSvm<Config> = "svm" extends keyof Config ? true : false;
|
|
407
|
+
|
|
408
|
+
// Count ecosystems using tuple length
|
|
409
|
+
type BoolToNum<B extends boolean> = B extends true ? 1 : 0;
|
|
410
|
+
type EcosystemTuple<Config> = [
|
|
411
|
+
...([BoolToNum<HasEvm<Config>>] extends [1] ? [1] : []),
|
|
412
|
+
...([BoolToNum<HasFuel<Config>>] extends [1] ? [1] : []),
|
|
413
|
+
...([BoolToNum<HasSvm<Config>>] extends [1] ? [1] : [])
|
|
414
|
+
];
|
|
415
|
+
type EcosystemCount<Config> = EcosystemTuple<Config>["length"];
|
|
416
|
+
|
|
417
|
+
// EVM ecosystem type
|
|
418
|
+
type EvmEcosystem<Config extends IndexerConfigTypes> =
|
|
419
|
+
"evm" extends keyof Config
|
|
420
|
+
? Config["evm"] extends {
|
|
421
|
+
chains: infer Chains;
|
|
422
|
+
contracts?: Record<infer ContractName, any>;
|
|
423
|
+
}
|
|
424
|
+
? Chains extends Record<string, { id: number }>
|
|
425
|
+
? {
|
|
426
|
+
/** Array of all EVM chain IDs. */
|
|
427
|
+
readonly chainIds: readonly Chains[keyof Chains]["id"][];
|
|
428
|
+
/** Per-chain configuration keyed by chain name or ID. */
|
|
429
|
+
readonly chains: {
|
|
430
|
+
readonly [K in Chains[keyof Chains]["id"]]: EvmChain<
|
|
431
|
+
K,
|
|
432
|
+
ContractName extends string ? ContractName : never
|
|
433
|
+
>;
|
|
434
|
+
} & {
|
|
435
|
+
readonly [K in keyof Chains]: EvmChain<
|
|
436
|
+
Chains[K]["id"],
|
|
437
|
+
ContractName extends string ? ContractName : never
|
|
438
|
+
>;
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
: never
|
|
442
|
+
: never
|
|
443
|
+
: never;
|
|
444
|
+
|
|
445
|
+
// Fuel ecosystem type
|
|
446
|
+
type FuelEcosystem<Config extends IndexerConfigTypes> =
|
|
447
|
+
"fuel" extends keyof Config
|
|
448
|
+
? Config["fuel"] extends {
|
|
449
|
+
chains: infer Chains;
|
|
450
|
+
contracts?: Record<infer ContractName, any>;
|
|
451
|
+
}
|
|
452
|
+
? Chains extends Record<string, { id: number }>
|
|
453
|
+
? {
|
|
454
|
+
/** Array of all Fuel chain IDs. */
|
|
455
|
+
readonly chainIds: readonly Chains[keyof Chains]["id"][];
|
|
456
|
+
/** Per-chain configuration keyed by chain name or ID. */
|
|
457
|
+
readonly chains: {
|
|
458
|
+
readonly [K in Chains[keyof Chains]["id"]]: FuelChain<
|
|
459
|
+
K,
|
|
460
|
+
ContractName extends string ? ContractName : never
|
|
461
|
+
>;
|
|
462
|
+
} & {
|
|
463
|
+
readonly [K in keyof Chains]: FuelChain<
|
|
464
|
+
Chains[K]["id"],
|
|
465
|
+
ContractName extends string ? ContractName : never
|
|
466
|
+
>;
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
: never
|
|
470
|
+
: never
|
|
471
|
+
: never;
|
|
472
|
+
|
|
473
|
+
// SVM ecosystem type
|
|
474
|
+
type SvmEcosystem<Config extends IndexerConfigTypes> =
|
|
475
|
+
"svm" extends keyof Config
|
|
476
|
+
? Config["svm"] extends { chains: infer Chains }
|
|
477
|
+
? Chains extends Record<string, { id: number }>
|
|
478
|
+
? {
|
|
479
|
+
/** Array of all SVM chain IDs. */
|
|
480
|
+
readonly chainIds: readonly Chains[keyof Chains]["id"][];
|
|
481
|
+
/** Per-chain configuration keyed by chain name or ID. */
|
|
482
|
+
readonly chains: {
|
|
483
|
+
readonly [K in Chains[keyof Chains]["id"]]: SvmChain<K>;
|
|
484
|
+
} & {
|
|
485
|
+
readonly [K in keyof Chains]: SvmChain<Chains[K]["id"]>;
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
: never
|
|
489
|
+
: never
|
|
490
|
+
: never;
|
|
491
|
+
|
|
492
|
+
// Single ecosystem chains (flattened at root level)
|
|
493
|
+
type SingleEcosystemChains<Config extends IndexerConfigTypes> =
|
|
494
|
+
HasEvm<Config> extends true
|
|
495
|
+
? EvmEcosystem<Config>
|
|
496
|
+
: HasFuel<Config> extends true
|
|
497
|
+
? FuelEcosystem<Config>
|
|
498
|
+
: HasSvm<Config> extends true
|
|
499
|
+
? SvmEcosystem<Config>
|
|
500
|
+
: {};
|
|
501
|
+
|
|
502
|
+
// Multi-ecosystem chains (namespaced by ecosystem)
|
|
503
|
+
type MultiEcosystemChains<Config extends IndexerConfigTypes> =
|
|
504
|
+
(HasEvm<Config> extends true
|
|
505
|
+
? {
|
|
506
|
+
/** EVM ecosystem configuration. */
|
|
507
|
+
readonly evm: EvmEcosystem<Config>;
|
|
508
|
+
}
|
|
509
|
+
: {}) &
|
|
510
|
+
(HasFuel<Config> extends true
|
|
511
|
+
? {
|
|
512
|
+
/** Fuel ecosystem configuration. */
|
|
513
|
+
readonly fuel: FuelEcosystem<Config>;
|
|
514
|
+
}
|
|
515
|
+
: {}) &
|
|
516
|
+
(HasSvm<Config> extends true
|
|
517
|
+
? {
|
|
518
|
+
/** SVM ecosystem configuration. */
|
|
519
|
+
readonly svm: SvmEcosystem<Config>;
|
|
520
|
+
}
|
|
521
|
+
: {});
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* Indexer type resolved from config, adapting chain properties based on configured ecosystems.
|
|
525
|
+
* - Single ecosystem: chains are at the root level.
|
|
526
|
+
* - Multiple ecosystems: chains are namespaced by ecosystem (evm, fuel, svm).
|
|
527
|
+
*/
|
|
528
|
+
export type IndexerFromConfig<Config extends IndexerConfigTypes> = Prettify<
|
|
529
|
+
{
|
|
530
|
+
/** The indexer name from config.yaml. */
|
|
531
|
+
readonly name: string;
|
|
532
|
+
/** The indexer description from config.yaml. */
|
|
533
|
+
readonly description: string | undefined;
|
|
534
|
+
} & (EcosystemCount<Config> extends 1
|
|
535
|
+
? SingleEcosystemChains<Config>
|
|
536
|
+
: MultiEcosystemChains<Config>)
|
|
537
|
+
>;
|
|
538
|
+
|
|
539
|
+
// ============== Test Indexer Types ==============
|
|
540
|
+
|
|
541
|
+
/** Simulate item type for EVM ecosystem. */
|
|
542
|
+
type EvmSimulateItem<Config extends IndexerConfigTypes> =
|
|
543
|
+
Config["evm"] extends { contracts: infer Contracts extends Record<string, Record<string, any>> }
|
|
544
|
+
? {
|
|
545
|
+
[C in keyof Contracts]: {
|
|
546
|
+
[E in keyof Contracts[C]]: {
|
|
547
|
+
/** The contract name as defined in config.yaml. */
|
|
548
|
+
contract: C;
|
|
549
|
+
/** The event name as defined in the contract ABI. */
|
|
550
|
+
event: E;
|
|
551
|
+
/** Override the source address. Defaults to the first contract address. */
|
|
552
|
+
srcAddress?: Address;
|
|
553
|
+
/** Override the log index. Auto-increments by default. */
|
|
554
|
+
logIndex?: number;
|
|
555
|
+
/** Override block fields. */
|
|
556
|
+
block?: Partial<Contracts[C][E]["block"]>;
|
|
557
|
+
/** Override transaction fields. */
|
|
558
|
+
transaction?: Partial<Contracts[C][E]["transaction"]>;
|
|
559
|
+
/** Event parameters. Keys match the event's parameter names. */
|
|
560
|
+
params?: Partial<Contracts[C][E]["params"]>;
|
|
561
|
+
};
|
|
562
|
+
}[keyof Contracts[C]];
|
|
563
|
+
}[keyof Contracts]
|
|
564
|
+
: never;
|
|
565
|
+
|
|
566
|
+
/** Simulate item type for Fuel ecosystem. */
|
|
567
|
+
type FuelSimulateItem<Config extends IndexerConfigTypes> =
|
|
568
|
+
Config["fuel"] extends { contracts: infer Contracts extends Record<string, Record<string, any>> }
|
|
569
|
+
? {
|
|
570
|
+
[C in keyof Contracts]: {
|
|
571
|
+
[E in keyof Contracts[C]]: {
|
|
572
|
+
/** The contract name as defined in config.yaml. */
|
|
573
|
+
contract: C;
|
|
574
|
+
/** The event name as defined in the contract ABI. */
|
|
575
|
+
event: E;
|
|
576
|
+
/** Override the source address. Defaults to the first contract address. */
|
|
577
|
+
srcAddress?: Address;
|
|
578
|
+
/** Override the log index. Auto-increments by default. */
|
|
579
|
+
logIndex?: number;
|
|
580
|
+
/** Override block fields. */
|
|
581
|
+
block?: Partial<Contracts[C][E]["block"]>;
|
|
582
|
+
/** Override transaction fields. */
|
|
583
|
+
transaction?: Partial<Contracts[C][E]["transaction"]>;
|
|
584
|
+
/** Event parameters. Keys match the event's parameter names. */
|
|
585
|
+
params: Contracts[C][E]["params"];
|
|
586
|
+
};
|
|
587
|
+
}[keyof Contracts[C]];
|
|
588
|
+
}[keyof Contracts]
|
|
589
|
+
: never;
|
|
590
|
+
|
|
591
|
+
/** Configuration for a single EVM chain in the test indexer. */
|
|
592
|
+
type EvmTestIndexerChainConfig<Config extends IndexerConfigTypes> = {
|
|
593
|
+
/** The block number to start processing from. Defaults to config startBlock or progressBlock+1. */
|
|
594
|
+
startBlock?: number;
|
|
595
|
+
/** The block number to stop processing at. Defaults to max simulate block number when simulate is provided. */
|
|
596
|
+
endBlock?: number;
|
|
597
|
+
/** Simulate items to process instead of fetching from real sources. */
|
|
598
|
+
simulate?: EvmSimulateItem<Config>[];
|
|
599
|
+
};
|
|
600
|
+
|
|
601
|
+
/** Configuration for a single Fuel chain in the test indexer. */
|
|
602
|
+
type FuelTestIndexerChainConfig<Config extends IndexerConfigTypes> = {
|
|
603
|
+
/** The block number to start processing from. Defaults to config startBlock or progressBlock+1. */
|
|
604
|
+
startBlock?: number;
|
|
605
|
+
/** The block number to stop processing at. Defaults to max simulate block height when simulate is provided. */
|
|
606
|
+
endBlock?: number;
|
|
607
|
+
/** Simulate items to process instead of fetching from real sources. */
|
|
608
|
+
simulate?: FuelSimulateItem<Config>[];
|
|
609
|
+
};
|
|
610
|
+
|
|
611
|
+
/** Entity change value containing sets and/or deleted IDs. */
|
|
612
|
+
type EntityChangeValue<Entity> = {
|
|
613
|
+
/** Entities that were created or updated. */
|
|
614
|
+
readonly sets?: readonly Entity[];
|
|
615
|
+
/** IDs of entities that were deleted. */
|
|
616
|
+
readonly deleted?: readonly string[];
|
|
617
|
+
};
|
|
618
|
+
|
|
619
|
+
/** A dynamic contract address registration. */
|
|
620
|
+
type AddressRegistration = {
|
|
621
|
+
/** The contract address. */
|
|
622
|
+
readonly address: Address;
|
|
623
|
+
/** The contract name. */
|
|
624
|
+
readonly contract: string;
|
|
625
|
+
};
|
|
626
|
+
|
|
627
|
+
/** Extract entities from config. */
|
|
628
|
+
type ConfigEntities<Config extends IndexerConfigTypes> =
|
|
629
|
+
Config["entities"] extends Record<string, object> ? Config["entities"] : {};
|
|
630
|
+
|
|
631
|
+
/** Entity operations available on test indexer for direct entity manipulation. */
|
|
632
|
+
type TestIndexerEntityOperations<Entity> = {
|
|
633
|
+
/** Get an entity by ID. Returns undefined if not found. */
|
|
634
|
+
readonly get: (id: string) => Promise<Entity | undefined>;
|
|
635
|
+
/** Get an entity by ID or throw if not found. */
|
|
636
|
+
readonly getOrThrow: (id: string, message?: string) => Promise<Entity>;
|
|
637
|
+
/** Get all entities. */
|
|
638
|
+
readonly getAll: () => Promise<Entity[]>;
|
|
639
|
+
/** Set (create or update) an entity. */
|
|
640
|
+
readonly set: (entity: Entity) => void;
|
|
641
|
+
};
|
|
642
|
+
|
|
643
|
+
/** A single change representing entity modifications at a specific block. */
|
|
644
|
+
type EntityChange<Config extends IndexerConfigTypes> = {
|
|
645
|
+
/** The block where the changes occurred. */
|
|
646
|
+
readonly block: number;
|
|
647
|
+
/** The chain ID. */
|
|
648
|
+
readonly chainId: number;
|
|
649
|
+
/** Number of events processed in this block. */
|
|
650
|
+
readonly eventsProcessed: number;
|
|
651
|
+
/** Dynamic contract address registrations for this block. */
|
|
652
|
+
readonly addresses?: {
|
|
653
|
+
readonly sets?: readonly AddressRegistration[];
|
|
654
|
+
};
|
|
655
|
+
} & {
|
|
656
|
+
readonly [K in keyof ConfigEntities<Config>]?: EntityChangeValue<
|
|
657
|
+
ConfigEntities<Config>[K]
|
|
658
|
+
>;
|
|
659
|
+
};
|
|
660
|
+
|
|
661
|
+
|
|
662
|
+
// Helper to extract chain IDs per ecosystem
|
|
663
|
+
type EvmChainIds<Config extends IndexerConfigTypes> =
|
|
664
|
+
Config["evm"] extends { chains: infer Chains }
|
|
665
|
+
? Chains extends Record<string, { id: number }>
|
|
666
|
+
? Chains[keyof Chains]["id"]
|
|
667
|
+
: never
|
|
668
|
+
: never;
|
|
669
|
+
|
|
670
|
+
type FuelChainIds<Config extends IndexerConfigTypes> =
|
|
671
|
+
Config["fuel"] extends { chains: infer Chains }
|
|
672
|
+
? Chains extends Record<string, { id: number }>
|
|
673
|
+
? Chains[keyof Chains]["id"]
|
|
674
|
+
: never
|
|
675
|
+
: never;
|
|
676
|
+
|
|
677
|
+
// Per-ecosystem chain config mappings
|
|
678
|
+
type EvmTestChains<Config extends IndexerConfigTypes> =
|
|
679
|
+
HasEvm<Config> extends true
|
|
680
|
+
? { [K in EvmChainIds<Config>]?: EvmTestIndexerChainConfig<Config> }
|
|
681
|
+
: {};
|
|
682
|
+
|
|
683
|
+
type FuelTestChains<Config extends IndexerConfigTypes> =
|
|
684
|
+
HasFuel<Config> extends true
|
|
685
|
+
? { [K in FuelChainIds<Config>]?: FuelTestIndexerChainConfig<Config> }
|
|
686
|
+
: {};
|
|
687
|
+
|
|
688
|
+
/** Process configuration for the test indexer, with chains keyed by chain ID. */
|
|
689
|
+
export type TestIndexerProcessConfig<Config extends IndexerConfigTypes> = {
|
|
690
|
+
/** Chain configurations keyed by chain ID. Each chain specifies start and end blocks. */
|
|
691
|
+
chains: Prettify<
|
|
692
|
+
EvmTestChains<Config> &
|
|
693
|
+
FuelTestChains<Config>
|
|
694
|
+
>;
|
|
695
|
+
};
|
|
696
|
+
|
|
697
|
+
/**
|
|
698
|
+
* Test indexer type resolved from config.
|
|
699
|
+
* Allows running the indexer for specific block ranges and inspecting results.
|
|
700
|
+
*/
|
|
701
|
+
export type TestIndexerFromConfig<Config extends IndexerConfigTypes> = {
|
|
702
|
+
/** Process blocks for the specified chains and return progress with checkpoints and changes. */
|
|
703
|
+
process: (
|
|
704
|
+
config: Prettify<TestIndexerProcessConfig<Config>>
|
|
705
|
+
) => Promise<{
|
|
706
|
+
/** Changes happened during the processing. */
|
|
707
|
+
readonly changes: readonly EntityChange<Config>[];
|
|
708
|
+
}>;
|
|
709
|
+
} & (EcosystemCount<Config> extends 1
|
|
710
|
+
? SingleEcosystemChains<Config>
|
|
711
|
+
: MultiEcosystemChains<Config>) & {
|
|
712
|
+
/** Entity operations for direct manipulation outside of handlers. */
|
|
713
|
+
readonly [K in keyof ConfigEntities<Config>]: TestIndexerEntityOperations<
|
|
714
|
+
ConfigEntities<Config>[K]
|
|
715
|
+
>;
|
|
716
|
+
};
|
package/index.js
CHANGED
|
@@ -12,6 +12,10 @@ export * from "./src/Envio.res.mjs";
|
|
|
12
12
|
// Important! Should match the index.d.ts file
|
|
13
13
|
export const S = {
|
|
14
14
|
string: Sury.string,
|
|
15
|
+
address: Sury.string,
|
|
16
|
+
evmChainId: Sury.number,
|
|
17
|
+
fuelChainId: Sury.number,
|
|
18
|
+
svmChainId: Sury.number,
|
|
15
19
|
jsonString: Sury.jsonString,
|
|
16
20
|
boolean: Sury.boolean,
|
|
17
21
|
int32: Sury.int32,
|