envio 3.0.0-alpha.2 → 3.0.0-alpha.20

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.
Files changed (175) hide show
  1. package/README.md +164 -30
  2. package/bin.mjs +49 -0
  3. package/evm.schema.json +79 -169
  4. package/fuel.schema.json +50 -21
  5. package/index.d.ts +497 -1
  6. package/index.js +4 -0
  7. package/package.json +42 -31
  8. package/rescript.json +4 -1
  9. package/src/Batch.res +11 -8
  10. package/src/Batch.res.mjs +11 -9
  11. package/src/ChainFetcher.res +531 -0
  12. package/src/ChainFetcher.res.mjs +339 -0
  13. package/src/ChainManager.res +190 -0
  14. package/src/ChainManager.res.mjs +166 -0
  15. package/src/Change.res +3 -3
  16. package/src/Config.gen.ts +19 -0
  17. package/src/Config.res +737 -22
  18. package/src/Config.res.mjs +703 -26
  19. package/src/{Indexer.res → Ctx.res} +1 -1
  20. package/src/Ecosystem.res +9 -124
  21. package/src/Ecosystem.res.mjs +19 -160
  22. package/src/Env.res +30 -74
  23. package/src/Env.res.mjs +25 -87
  24. package/src/Envio.gen.ts +3 -1
  25. package/src/Envio.res +20 -9
  26. package/src/EventProcessing.res +469 -0
  27. package/src/EventProcessing.res.mjs +337 -0
  28. package/src/EvmTypes.gen.ts +6 -0
  29. package/src/EvmTypes.res +1 -0
  30. package/src/FetchState.res +1256 -639
  31. package/src/FetchState.res.mjs +1135 -612
  32. package/src/GlobalState.res +1190 -0
  33. package/src/GlobalState.res.mjs +1183 -0
  34. package/src/GlobalStateManager.res +68 -0
  35. package/src/GlobalStateManager.res.mjs +75 -0
  36. package/src/GlobalStateManager.resi +7 -0
  37. package/src/HandlerLoader.res +89 -0
  38. package/src/HandlerLoader.res.mjs +79 -0
  39. package/src/HandlerRegister.res +357 -0
  40. package/src/HandlerRegister.res.mjs +299 -0
  41. package/src/{EventRegister.resi → HandlerRegister.resi} +13 -13
  42. package/src/Hasura.res +111 -175
  43. package/src/Hasura.res.mjs +88 -150
  44. package/src/InMemoryStore.res +1 -1
  45. package/src/InMemoryStore.res.mjs +3 -3
  46. package/src/InMemoryTable.res +1 -1
  47. package/src/InMemoryTable.res.mjs +1 -1
  48. package/src/Internal.gen.ts +4 -0
  49. package/src/Internal.res +230 -12
  50. package/src/Internal.res.mjs +115 -1
  51. package/src/LoadLayer.res +444 -0
  52. package/src/LoadLayer.res.mjs +296 -0
  53. package/src/LoadLayer.resi +32 -0
  54. package/src/LogSelection.res +33 -27
  55. package/src/LogSelection.res.mjs +6 -0
  56. package/src/Logging.res +21 -7
  57. package/src/Logging.res.mjs +16 -8
  58. package/src/Main.res +377 -0
  59. package/src/Main.res.mjs +339 -0
  60. package/src/Persistence.res +7 -21
  61. package/src/Persistence.res.mjs +3 -3
  62. package/src/PgStorage.gen.ts +10 -0
  63. package/src/PgStorage.res +116 -69
  64. package/src/PgStorage.res.d.mts +5 -0
  65. package/src/PgStorage.res.mjs +93 -50
  66. package/src/Prometheus.res +294 -224
  67. package/src/Prometheus.res.mjs +353 -340
  68. package/src/ReorgDetection.res +6 -10
  69. package/src/ReorgDetection.res.mjs +6 -6
  70. package/src/SafeCheckpointTracking.res +4 -4
  71. package/src/SafeCheckpointTracking.res.mjs +2 -2
  72. package/src/Sink.res +4 -2
  73. package/src/Sink.res.mjs +2 -1
  74. package/src/TableIndices.res +0 -1
  75. package/src/TestIndexer.res +692 -0
  76. package/src/TestIndexer.res.mjs +527 -0
  77. package/src/TestIndexerProxyStorage.res +205 -0
  78. package/src/TestIndexerProxyStorage.res.mjs +151 -0
  79. package/src/TopicFilter.res +1 -1
  80. package/src/Types.ts +1 -1
  81. package/src/UserContext.res +424 -0
  82. package/src/UserContext.res.mjs +279 -0
  83. package/src/Utils.res +97 -26
  84. package/src/Utils.res.mjs +91 -44
  85. package/src/bindings/BigInt.res +10 -0
  86. package/src/bindings/BigInt.res.mjs +15 -0
  87. package/src/bindings/ClickHouse.res +120 -23
  88. package/src/bindings/ClickHouse.res.mjs +118 -28
  89. package/src/bindings/DateFns.res +74 -0
  90. package/src/bindings/DateFns.res.mjs +22 -0
  91. package/src/bindings/EventSource.res +8 -1
  92. package/src/bindings/EventSource.res.mjs +8 -1
  93. package/src/bindings/Express.res +1 -0
  94. package/src/bindings/Hrtime.res +14 -1
  95. package/src/bindings/Hrtime.res.mjs +22 -2
  96. package/src/bindings/Hrtime.resi +4 -0
  97. package/src/bindings/Lodash.res +0 -1
  98. package/src/bindings/NodeJs.res +49 -3
  99. package/src/bindings/NodeJs.res.mjs +11 -3
  100. package/src/bindings/Pino.res +24 -10
  101. package/src/bindings/Pino.res.mjs +14 -8
  102. package/src/bindings/Postgres.gen.ts +8 -0
  103. package/src/bindings/Postgres.res +5 -1
  104. package/src/bindings/Postgres.res.d.mts +5 -0
  105. package/src/bindings/PromClient.res +0 -10
  106. package/src/bindings/PromClient.res.mjs +0 -3
  107. package/src/bindings/Vitest.res +142 -0
  108. package/src/bindings/Vitest.res.mjs +9 -0
  109. package/src/bindings/WebSocket.res +27 -0
  110. package/src/bindings/WebSocket.res.mjs +2 -0
  111. package/src/bindings/Yargs.res +8 -0
  112. package/src/bindings/Yargs.res.mjs +2 -0
  113. package/src/db/EntityHistory.res +7 -7
  114. package/src/db/EntityHistory.res.mjs +9 -9
  115. package/src/db/InternalTable.res +59 -111
  116. package/src/db/InternalTable.res.mjs +73 -104
  117. package/src/db/Table.res +27 -8
  118. package/src/db/Table.res.mjs +25 -14
  119. package/src/sources/Evm.res +84 -0
  120. package/src/sources/Evm.res.mjs +105 -0
  121. package/src/sources/EvmChain.res +94 -0
  122. package/src/sources/EvmChain.res.mjs +60 -0
  123. package/src/sources/Fuel.res +19 -34
  124. package/src/sources/Fuel.res.mjs +34 -16
  125. package/src/sources/FuelSDK.res +38 -0
  126. package/src/sources/FuelSDK.res.mjs +29 -0
  127. package/src/sources/HyperFuel.res +2 -2
  128. package/src/sources/HyperFuel.resi +1 -1
  129. package/src/sources/HyperFuelClient.res +2 -2
  130. package/src/sources/HyperFuelSource.res +33 -13
  131. package/src/sources/HyperFuelSource.res.mjs +24 -16
  132. package/src/sources/HyperSync.res +36 -6
  133. package/src/sources/HyperSync.res.mjs +9 -7
  134. package/src/sources/HyperSync.resi +4 -0
  135. package/src/sources/HyperSyncClient.res +1 -1
  136. package/src/sources/HyperSyncHeightStream.res +47 -116
  137. package/src/sources/HyperSyncHeightStream.res.mjs +46 -73
  138. package/src/sources/HyperSyncSource.res +118 -139
  139. package/src/sources/HyperSyncSource.res.mjs +104 -121
  140. package/src/sources/Rpc.res +86 -14
  141. package/src/sources/Rpc.res.mjs +101 -9
  142. package/src/sources/RpcSource.res +621 -364
  143. package/src/sources/RpcSource.res.mjs +843 -410
  144. package/src/sources/RpcWebSocketHeightStream.res +181 -0
  145. package/src/sources/RpcWebSocketHeightStream.res.mjs +196 -0
  146. package/src/sources/Source.res +7 -5
  147. package/src/sources/SourceManager.res +325 -225
  148. package/src/sources/SourceManager.res.mjs +314 -171
  149. package/src/sources/SourceManager.resi +17 -6
  150. package/src/sources/Svm.res +81 -0
  151. package/src/sources/Svm.res.mjs +90 -0
  152. package/src/tui/Tui.res +247 -0
  153. package/src/tui/Tui.res.mjs +337 -0
  154. package/src/tui/bindings/Ink.res +371 -0
  155. package/src/tui/bindings/Ink.res.mjs +72 -0
  156. package/src/tui/bindings/Style.res +123 -0
  157. package/src/tui/bindings/Style.res.mjs +2 -0
  158. package/src/tui/components/BufferedProgressBar.res +40 -0
  159. package/src/tui/components/BufferedProgressBar.res.mjs +57 -0
  160. package/src/tui/components/CustomHooks.res +122 -0
  161. package/src/tui/components/CustomHooks.res.mjs +179 -0
  162. package/src/tui/components/Messages.res +41 -0
  163. package/src/tui/components/Messages.res.mjs +75 -0
  164. package/src/tui/components/SyncETA.res +174 -0
  165. package/src/tui/components/SyncETA.res.mjs +263 -0
  166. package/src/tui/components/TuiData.res +47 -0
  167. package/src/tui/components/TuiData.res.mjs +34 -0
  168. package/svm.schema.json +112 -0
  169. package/bin.js +0 -48
  170. package/src/EventRegister.res +0 -241
  171. package/src/EventRegister.res.mjs +0 -240
  172. package/src/bindings/Ethers.gen.ts +0 -14
  173. package/src/bindings/Ethers.res +0 -204
  174. package/src/bindings/Ethers.res.mjs +0 -130
  175. /package/src/{Indexer.res.mjs → Ctx.res.mjs} +0 -0
package/fuel.schema.json CHANGED
@@ -15,10 +15,6 @@
15
15
  "description": "Name of the project",
16
16
  "type": "string"
17
17
  },
18
- "ecosystem": {
19
- "description": "Ecosystem of the project.",
20
- "$ref": "#/$defs/EcosystemTag"
21
- },
22
18
  "schema": {
23
19
  "description": "Custom path to schema.graphql file",
24
20
  "type": [
@@ -33,6 +29,26 @@
33
29
  "null"
34
30
  ]
35
31
  },
32
+ "handlers": {
33
+ "description": "Optional relative path to handlers directory for auto-loading. Defaults to 'src/handlers' if not specified.",
34
+ "type": [
35
+ "string",
36
+ "null"
37
+ ]
38
+ },
39
+ "full_batch_size": {
40
+ "description": "Target number of events to be processed per batch. Set it to smaller number if you have many Effect API calls which are slow to resolve and can't be batched. (Default: 5000)",
41
+ "type": [
42
+ "integer",
43
+ "null"
44
+ ],
45
+ "format": "uint64",
46
+ "minimum": 0
47
+ },
48
+ "ecosystem": {
49
+ "description": "Ecosystem of the project.",
50
+ "$ref": "#/$defs/EcosystemTag"
51
+ },
36
52
  "contracts": {
37
53
  "description": "Global contract definitions that must contain all definitions except addresses. You can share a single handler/abi/event definitions for contracts across multiple chains.",
38
54
  "type": [
@@ -47,7 +63,7 @@
47
63
  "description": "Configuration of the blockchain chains that the project is deployed on.",
48
64
  "type": "array",
49
65
  "items": {
50
- "$ref": "#/$defs/Network"
66
+ "$ref": "#/$defs/Chain"
51
67
  }
52
68
  },
53
69
  "raw_events": {
@@ -56,13 +72,6 @@
56
72
  "boolean",
57
73
  "null"
58
74
  ]
59
- },
60
- "handlers": {
61
- "description": "Optional relative path to handlers directory for auto-loading. Defaults to 'src/handlers' if not specified.",
62
- "type": [
63
- "string",
64
- "null"
65
- ]
66
75
  }
67
76
  },
68
77
  "additionalProperties": false,
@@ -152,11 +161,11 @@
152
161
  "call"
153
162
  ]
154
163
  },
155
- "Network": {
164
+ "Chain": {
156
165
  "type": "object",
157
166
  "properties": {
158
167
  "id": {
159
- "description": "Public chain/network id",
168
+ "description": "Public chain id",
160
169
  "type": "integer",
161
170
  "format": "uint64",
162
171
  "minimum": 0
@@ -187,19 +196,39 @@
187
196
  }
188
197
  ]
189
198
  },
199
+ "max_reorg_depth": {
200
+ "description": "The number of blocks from the head that the indexer should account for in case of reorgs.",
201
+ "type": [
202
+ "integer",
203
+ "null"
204
+ ],
205
+ "format": "uint32",
206
+ "minimum": 0
207
+ },
208
+ "block_lag": {
209
+ "description": "The number of blocks behind the chain head that the indexer should lag. Useful for avoiding reorg issues by indexing slightly behind the tip.",
210
+ "type": [
211
+ "integer",
212
+ "null"
213
+ ],
214
+ "format": "uint32",
215
+ "minimum": 0
216
+ },
190
217
  "contracts": {
191
- "description": "All the contracts that should be indexed on the given network",
192
- "type": "array",
218
+ "description": "All the contracts that should be indexed on the given chain",
219
+ "type": [
220
+ "array",
221
+ "null"
222
+ ],
193
223
  "items": {
194
- "$ref": "#/$defs/NetworkContract_for_ContractConfig"
224
+ "$ref": "#/$defs/ChainContract_for_ContractConfig"
195
225
  }
196
226
  }
197
227
  },
198
228
  "additionalProperties": false,
199
229
  "required": [
200
230
  "id",
201
- "start_block",
202
- "contracts"
231
+ "start_block"
203
232
  ]
204
233
  },
205
234
  "HyperfuelConfig": {
@@ -215,7 +244,7 @@
215
244
  "url"
216
245
  ]
217
246
  },
218
- "NetworkContract_for_ContractConfig": {
247
+ "ChainContract_for_ContractConfig": {
219
248
  "type": "object",
220
249
  "properties": {
221
250
  "name": {
@@ -227,7 +256,7 @@
227
256
  "$ref": "#/$defs/Addresses"
228
257
  },
229
258
  "start_block": {
230
- "description": "The block at which the indexer should start ingesting data for this specific contract. If not specified, uses the network start_block. Can be greater than the network start_block for more specific indexing.",
259
+ "description": "The block at which the indexer should start ingesting data for this specific contract. If not specified, uses the chain start_block. Can be greater than the chain start_block for more specific indexing.",
231
260
  "type": [
232
261
  "integer",
233
262
  "null"
package/index.d.ts CHANGED
@@ -8,10 +8,45 @@ 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
- export type { EffectCaller } from "./src/Types.ts";
15
+ import type { Address } from "./src/Types.ts";
16
+ export type { EffectCaller, Address } from "./src/Types.ts";
17
+
18
+ /** Utility type to expand/flatten complex types for better IDE display. */
19
+ export type Prettify<T> = { [K in keyof T]: T[K] } & {};
20
+
21
+ /**
22
+ * Operator for filtering entity fields in getWhere queries.
23
+ * Only fields with `@index` in the schema can be queried at runtime.
24
+ */
25
+ export type WhereOperator<T> = {
26
+ /** Matches entities where the field equals the given value. */
27
+ readonly _eq?: T;
28
+ /** Matches entities where the field is greater than the given value. */
29
+ readonly _gt?: T;
30
+ /** Matches entities where the field is less than the given value. */
31
+ readonly _lt?: T;
32
+ /** Matches entities where the field is greater than or equal to the given value. */
33
+ readonly _gte?: T;
34
+ /** Matches entities where the field is less than or equal to the given value. */
35
+ readonly _lte?: T;
36
+ /** Matches entities where the field equals any of the given values. */
37
+ readonly _in?: readonly T[];
38
+ };
39
+
40
+ /**
41
+ * Constructs a getWhere filter type from an entity type.
42
+ * Each field can be filtered using {@link WhereOperator} (`_eq`, `_gt`, `_lt`, `_gte`, `_lte`, `_in`).
43
+ *
44
+ * Note: only fields with `@index` in the schema can be queried at runtime.
45
+ * Attempting to filter on a non-indexed field will throw a descriptive error.
46
+ */
47
+ export type GetWhereFilter<E> = {
48
+ [K in keyof E]?: WhereOperator<E[K]>;
49
+ };
15
50
 
16
51
  import type {
17
52
  effect as Effect,
@@ -108,6 +143,10 @@ export declare namespace S {
108
143
  export type Input<T> = Sury.Input<T>;
109
144
  export type Schema<Output, Input = unknown> = Sury.Schema<Output, Input>;
110
145
  export const string: typeof Sury.string;
146
+ export const address: Sury.Schema<Address, Address>;
147
+ // export const evmChainId: Sury.Schema<EvmChainId, EvmChainId>;
148
+ // export const fuelChainId: Sury.Schema<FuelChainId, FuelChainId>;
149
+ // export const svmChainId: Sury.Schema<SvmChainId, SvmChainId>;
111
150
  export const jsonString: typeof Sury.jsonString;
112
151
  export const boolean: typeof Sury.boolean;
113
152
  export const int32: typeof Sury.int32;
@@ -137,3 +176,460 @@ export declare namespace S {
137
176
  export const assertOrThrow: typeof Sury.assertOrThrow;
138
177
  export const parseOrThrow: typeof Sury.parseOrThrow;
139
178
  }
179
+
180
+ // ============== Indexer Config (Module Augmentation) ==============
181
+
182
+ /**
183
+ * Configuration interface for the indexer.
184
+ * This interface is augmented by generated/envio.d.ts with project-specific config using typeof config.
185
+ *
186
+ * @example
187
+ * // In generated/envio.d.ts:
188
+ * declare module "envio" {
189
+ * interface Global {
190
+ * config: typeof config;
191
+ * }
192
+ * }
193
+ */
194
+ export interface Global {}
195
+
196
+ /**
197
+ * Shape of the indexer configuration.
198
+ * Will be used internally for defineConfig.
199
+ * Currently should match the internal.config.json structure.
200
+ */
201
+ type IndexerConfig = {
202
+ /** The indexer name. */
203
+ name: string;
204
+ /** The indexer description. */
205
+ description?: string;
206
+ /** Path to handlers directory for auto-loading (default: "src/handlers"). */
207
+ handlers?: string;
208
+ /** Multichain mode: ordered or unordered (default: "unordered"). */
209
+ multichain?: "ordered" | "unordered";
210
+ /** Target batch size for event processing (default: 5000). */
211
+ fullBatchSize?: number;
212
+ /** Whether to rollback on chain reorg (default: true). */
213
+ rollbackOnReorg?: boolean;
214
+ /** Whether to save full entity history (default: false). */
215
+ saveFullHistory?: boolean;
216
+ /** Whether raw events are enabled (default: false). */
217
+ rawEvents?: boolean;
218
+ /** EVM ecosystem configuration. */
219
+ evm?: {
220
+ /** Chain configurations keyed by chain name. */
221
+ chains: Record<string, EvmChainConfig>;
222
+ /** Contract configurations keyed by contract name. */
223
+ contracts?: Record<string, EvmContractConfig>;
224
+ /** Address format (default: "checksum"). */
225
+ addressFormat?: "lowercase" | "checksum";
226
+ };
227
+ /** Fuel ecosystem configuration. */
228
+ fuel?: {
229
+ /** Chain configurations keyed by chain name. */
230
+ chains: Record<string, FuelChainConfig>;
231
+ /** Contract configurations keyed by contract name. */
232
+ contracts?: Record<string, FuelContractConfig>;
233
+ };
234
+ /** SVM ecosystem configuration. */
235
+ svm?: {
236
+ /** Chain configurations keyed by chain name. */
237
+ chains: Record<string, SvmChainConfig>;
238
+ };
239
+ };
240
+
241
+ // ============== Contract Types ==============
242
+
243
+ /** EVM contract configuration. */
244
+ type EvmContractConfig = {
245
+ /** The contract ABI. */
246
+ readonly abi: unknown;
247
+ };
248
+
249
+ /** Fuel contract configuration. */
250
+ type FuelContractConfig = {
251
+ /** The contract ABI. */
252
+ readonly abi: unknown;
253
+ };
254
+
255
+ // ============== EVM Types ==============
256
+
257
+ /** EVM chain configuration (for IndexerConfig). */
258
+ type EvmChainConfig<Id extends number = number> = {
259
+ /** The chain ID. */
260
+ readonly id: Id;
261
+ /** The block number indexing starts from. */
262
+ readonly startBlock: number;
263
+ /** The block number indexing stops at (if configured). */
264
+ readonly endBlock?: number;
265
+ /** Number of blocks to keep for reorg handling (default: 200). */
266
+ readonly maxReorgDepth?: number;
267
+ /** Number of blocks behind the chain head to lag (default: 0). */
268
+ readonly blockLag?: number;
269
+ };
270
+
271
+ /** EVM chain value (for runtime Indexer). */
272
+ type EvmChain<
273
+ Id extends number = number,
274
+ ContractName extends string = never
275
+ > = {
276
+ /** The chain ID. */
277
+ readonly id: Id;
278
+ /** The chain name. */
279
+ readonly name: string;
280
+ /** The block number indexing starts from. */
281
+ readonly startBlock: number;
282
+ /** The block number indexing stops at (if configured). */
283
+ readonly endBlock: number | undefined;
284
+ /** Whether the chain has completed initial sync and is processing live events. */
285
+ readonly isLive: boolean;
286
+ } & {
287
+ readonly [K in ContractName]: EvmContract<K>;
288
+ };
289
+
290
+ /** EVM contract (for runtime Indexer). */
291
+ type EvmContract<Name extends string = string> = {
292
+ /** The contract name. */
293
+ readonly name: Name;
294
+ /** The contract ABI. */
295
+ readonly abi: readonly unknown[];
296
+ /** The contract addresses. */
297
+ readonly addresses: readonly Address[];
298
+ };
299
+
300
+ /** Fuel contract (for runtime Indexer). */
301
+ type FuelContract<Name extends string = string> = {
302
+ /** The contract name. */
303
+ readonly name: Name;
304
+ /** The contract ABI. */
305
+ readonly abi: unknown;
306
+ /** The contract addresses. */
307
+ readonly addresses: readonly Address[];
308
+ };
309
+
310
+ // ============== Fuel Types ==============
311
+
312
+ /** Fuel chain configuration (for IndexerConfig). */
313
+ type FuelChainConfig<Id extends number = number> = {
314
+ /** The chain ID. */
315
+ readonly id: Id;
316
+ /** The block number indexing starts from. */
317
+ readonly startBlock: number;
318
+ /** The block number indexing stops at (if configured). */
319
+ readonly endBlock?: number;
320
+ /** Number of blocks to keep for reorg handling (default: 200). */
321
+ readonly maxReorgDepth?: number;
322
+ /** Number of blocks behind the chain head to lag (default: 0). */
323
+ readonly blockLag?: number;
324
+ };
325
+
326
+ /** Fuel chain value (for runtime Indexer). */
327
+ type FuelChain<
328
+ Id extends number = number,
329
+ ContractName extends string = never
330
+ > = {
331
+ /** The chain ID. */
332
+ readonly id: Id;
333
+ /** The chain name. */
334
+ readonly name: string;
335
+ /** The block number indexing starts from. */
336
+ readonly startBlock: number;
337
+ /** The block number indexing stops at (if configured). */
338
+ readonly endBlock: number | undefined;
339
+ /** Whether the chain has completed initial sync and is processing live events. */
340
+ readonly isLive: boolean;
341
+ } & {
342
+ readonly [K in ContractName]: FuelContract<K>;
343
+ };
344
+
345
+ // ============== SVM (Solana) Types ==============
346
+
347
+ /** SVM chain configuration (for IndexerConfig). */
348
+ type SvmChainConfig<Id extends number = number> = {
349
+ /** The chain ID. */
350
+ readonly id: Id;
351
+ /** The block number indexing starts from. */
352
+ readonly startBlock: number;
353
+ /** The block number indexing stops at (if configured). */
354
+ readonly endBlock?: number;
355
+ /** Number of blocks to keep for reorg handling (default: 200). */
356
+ readonly maxReorgDepth?: number;
357
+ /** Number of blocks behind the chain head to lag (default: 0). */
358
+ readonly blockLag?: number;
359
+ };
360
+
361
+ /** SVM chain value (for runtime Indexer). */
362
+ type SvmChain<Id extends number = number> = {
363
+ /** The chain ID. */
364
+ readonly id: Id;
365
+ /** The chain name. */
366
+ readonly name: string;
367
+ /** The block number indexing starts from. */
368
+ readonly startBlock: number;
369
+ /** The block number indexing stops at (if configured). */
370
+ readonly endBlock: number | undefined;
371
+ /** Whether the chain has completed initial sync and is processing live events. */
372
+ readonly isLive: boolean;
373
+ };
374
+
375
+ // ============== Indexer Type ==============
376
+
377
+ /** Minimal type constraint for IndexerFromConfig to allow usage without full IndexerConfig. */
378
+ type IndexerConfigTypes = {
379
+ evm?: {
380
+ chains: Record<string, { id: number }>;
381
+ contracts?: Record<string, {}>;
382
+ };
383
+ fuel?: {
384
+ chains: Record<string, { id: number }>;
385
+ contracts?: Record<string, {}>;
386
+ };
387
+ svm?: { chains: Record<string, { id: number }> };
388
+ entities?: Record<string, object>;
389
+ };
390
+
391
+ // Helper: Check if ecosystem is configured in a given config
392
+ type HasEvm<Config> = "evm" extends keyof Config ? true : false;
393
+ type HasFuel<Config> = "fuel" extends keyof Config ? true : false;
394
+ type HasSvm<Config> = "svm" extends keyof Config ? true : false;
395
+
396
+ // Count ecosystems using tuple length
397
+ type BoolToNum<B extends boolean> = B extends true ? 1 : 0;
398
+ type EcosystemTuple<Config> = [
399
+ ...([BoolToNum<HasEvm<Config>>] extends [1] ? [1] : []),
400
+ ...([BoolToNum<HasFuel<Config>>] extends [1] ? [1] : []),
401
+ ...([BoolToNum<HasSvm<Config>>] extends [1] ? [1] : [])
402
+ ];
403
+ type EcosystemCount<Config> = EcosystemTuple<Config>["length"];
404
+
405
+ // EVM ecosystem type
406
+ type EvmEcosystem<Config extends IndexerConfigTypes> =
407
+ "evm" extends keyof Config
408
+ ? Config["evm"] extends {
409
+ chains: infer Chains;
410
+ contracts?: Record<infer ContractName, any>;
411
+ }
412
+ ? Chains extends Record<string, { id: number }>
413
+ ? {
414
+ /** Array of all EVM chain IDs. */
415
+ readonly chainIds: readonly Chains[keyof Chains]["id"][];
416
+ /** Per-chain configuration keyed by chain name or ID. */
417
+ readonly chains: {
418
+ readonly [K in Chains[keyof Chains]["id"]]: EvmChain<
419
+ K,
420
+ ContractName extends string ? ContractName : never
421
+ >;
422
+ } & {
423
+ readonly [K in keyof Chains]: EvmChain<
424
+ Chains[K]["id"],
425
+ ContractName extends string ? ContractName : never
426
+ >;
427
+ };
428
+ }
429
+ : never
430
+ : never
431
+ : never;
432
+
433
+ // Fuel ecosystem type
434
+ type FuelEcosystem<Config extends IndexerConfigTypes> =
435
+ "fuel" extends keyof Config
436
+ ? Config["fuel"] extends {
437
+ chains: infer Chains;
438
+ contracts?: Record<infer ContractName, any>;
439
+ }
440
+ ? Chains extends Record<string, { id: number }>
441
+ ? {
442
+ /** Array of all Fuel chain IDs. */
443
+ readonly chainIds: readonly Chains[keyof Chains]["id"][];
444
+ /** Per-chain configuration keyed by chain name or ID. */
445
+ readonly chains: {
446
+ readonly [K in Chains[keyof Chains]["id"]]: FuelChain<
447
+ K,
448
+ ContractName extends string ? ContractName : never
449
+ >;
450
+ } & {
451
+ readonly [K in keyof Chains]: FuelChain<
452
+ Chains[K]["id"],
453
+ ContractName extends string ? ContractName : never
454
+ >;
455
+ };
456
+ }
457
+ : never
458
+ : never
459
+ : never;
460
+
461
+ // SVM ecosystem type
462
+ type SvmEcosystem<Config extends IndexerConfigTypes> =
463
+ "svm" extends keyof Config
464
+ ? Config["svm"] extends { chains: infer Chains }
465
+ ? Chains extends Record<string, { id: number }>
466
+ ? {
467
+ /** Array of all SVM chain IDs. */
468
+ readonly chainIds: readonly Chains[keyof Chains]["id"][];
469
+ /** Per-chain configuration keyed by chain name or ID. */
470
+ readonly chains: {
471
+ readonly [K in Chains[keyof Chains]["id"]]: SvmChain<K>;
472
+ } & {
473
+ readonly [K in keyof Chains]: SvmChain<Chains[K]["id"]>;
474
+ };
475
+ }
476
+ : never
477
+ : never
478
+ : never;
479
+
480
+ // Single ecosystem chains (flattened at root level)
481
+ type SingleEcosystemChains<Config extends IndexerConfigTypes> =
482
+ HasEvm<Config> extends true
483
+ ? EvmEcosystem<Config>
484
+ : HasFuel<Config> extends true
485
+ ? FuelEcosystem<Config>
486
+ : HasSvm<Config> extends true
487
+ ? SvmEcosystem<Config>
488
+ : {};
489
+
490
+ // Multi-ecosystem chains (namespaced by ecosystem)
491
+ type MultiEcosystemChains<Config extends IndexerConfigTypes> =
492
+ (HasEvm<Config> extends true
493
+ ? {
494
+ /** EVM ecosystem configuration. */
495
+ readonly evm: EvmEcosystem<Config>;
496
+ }
497
+ : {}) &
498
+ (HasFuel<Config> extends true
499
+ ? {
500
+ /** Fuel ecosystem configuration. */
501
+ readonly fuel: FuelEcosystem<Config>;
502
+ }
503
+ : {}) &
504
+ (HasSvm<Config> extends true
505
+ ? {
506
+ /** SVM ecosystem configuration. */
507
+ readonly svm: SvmEcosystem<Config>;
508
+ }
509
+ : {});
510
+
511
+ /**
512
+ * Indexer type resolved from config, adapting chain properties based on configured ecosystems.
513
+ * - Single ecosystem: chains are at the root level.
514
+ * - Multiple ecosystems: chains are namespaced by ecosystem (evm, fuel, svm).
515
+ */
516
+ export type IndexerFromConfig<Config extends IndexerConfigTypes> = Prettify<
517
+ {
518
+ /** The indexer name from config.yaml. */
519
+ readonly name: string;
520
+ /** The indexer description from config.yaml. */
521
+ readonly description: string | undefined;
522
+ } & (EcosystemCount<Config> extends 1
523
+ ? SingleEcosystemChains<Config>
524
+ : MultiEcosystemChains<Config>)
525
+ >;
526
+
527
+ // ============== Test Indexer Types ==============
528
+
529
+ /** Configuration for a single chain in the test indexer. */
530
+ export type TestIndexerChainConfig = {
531
+ /** The block number to start processing from. */
532
+ startBlock: number;
533
+ /** The block number to stop processing at. */
534
+ endBlock: number;
535
+ };
536
+
537
+ /** Entity change value containing sets and/or deleted IDs. */
538
+ type EntityChangeValue<Entity> = {
539
+ /** Entities that were created or updated. */
540
+ readonly sets?: readonly Entity[];
541
+ /** IDs of entities that were deleted. */
542
+ readonly deleted?: readonly string[];
543
+ };
544
+
545
+ /** A dynamic contract address registration. */
546
+ type AddressRegistration = {
547
+ /** The contract address. */
548
+ readonly address: Address;
549
+ /** The contract name. */
550
+ readonly contract: string;
551
+ };
552
+
553
+ /** Extract entities from config. */
554
+ type ConfigEntities<Config extends IndexerConfigTypes> =
555
+ Config["entities"] extends Record<string, object> ? Config["entities"] : {};
556
+
557
+ /** Entity operations available on test indexer for direct entity manipulation. */
558
+ type EntityOps<Entity> = {
559
+ /** Get an entity by ID. Returns undefined if not found. */
560
+ readonly get: (id: string) => Promise<Entity | undefined>;
561
+ /** Set (create or update) an entity. */
562
+ readonly set: (entity: Entity) => void;
563
+ };
564
+
565
+ /** A single change representing entity modifications at a specific block. */
566
+ type EntityChange<Config extends IndexerConfigTypes> = {
567
+ /** The block where the changes occurred. */
568
+ readonly block: number;
569
+ /** The block hash (if available). */
570
+ readonly blockHash?: string;
571
+ /** The chain ID. */
572
+ readonly chainId: number;
573
+ /** Number of events processed in this block. */
574
+ readonly eventsProcessed: number;
575
+ /** Dynamic contract address registrations for this block. */
576
+ readonly addresses?: {
577
+ readonly sets?: readonly AddressRegistration[];
578
+ };
579
+ } & {
580
+ readonly [K in keyof ConfigEntities<Config>]?: EntityChangeValue<
581
+ ConfigEntities<Config>[K]
582
+ >;
583
+ };
584
+
585
+
586
+ // Helper to extract chain IDs from config for test indexer
587
+ type TestIndexerChainIds<Config extends IndexerConfigTypes> =
588
+ HasEvm<Config> extends true
589
+ ? Config["evm"] extends { chains: infer Chains }
590
+ ? Chains extends Record<string, { id: number }>
591
+ ? Chains[keyof Chains]["id"]
592
+ : never
593
+ : never
594
+ : HasFuel<Config> extends true
595
+ ? Config["fuel"] extends { chains: infer Chains }
596
+ ? Chains extends Record<string, { id: number }>
597
+ ? Chains[keyof Chains]["id"]
598
+ : never
599
+ : never
600
+ : HasSvm<Config> extends true
601
+ ? Config["svm"] extends { chains: infer Chains }
602
+ ? Chains extends Record<string, { id: number }>
603
+ ? Chains[keyof Chains]["id"]
604
+ : never
605
+ : never
606
+ : never;
607
+
608
+ /** Process configuration for the test indexer, with chains keyed by chain ID. */
609
+ export type TestIndexerProcessConfig<Config extends IndexerConfigTypes> = {
610
+ /** Chain configurations keyed by chain ID. Each chain specifies start and end blocks. */
611
+ chains: {
612
+ [K in TestIndexerChainIds<Config>]?: TestIndexerChainConfig;
613
+ };
614
+ };
615
+
616
+ /**
617
+ * Test indexer type resolved from config.
618
+ * Allows running the indexer for specific block ranges and inspecting results.
619
+ */
620
+ export type TestIndexerFromConfig<Config extends IndexerConfigTypes> = {
621
+ /** Process blocks for the specified chains and return progress with checkpoints and changes. */
622
+ process: (
623
+ config: Prettify<TestIndexerProcessConfig<Config>>
624
+ ) => Promise<{
625
+ /** Changes happened during the processing. */
626
+ readonly changes: readonly EntityChange<Config>[];
627
+ }>;
628
+ } & (EcosystemCount<Config> extends 1
629
+ ? SingleEcosystemChains<Config>
630
+ : MultiEcosystemChains<Config>) & {
631
+ /** Entity operations for direct manipulation outside of handlers. */
632
+ readonly [K in keyof ConfigEntities<Config>]: EntityOps<
633
+ ConfigEntities<Config>[K]
634
+ >;
635
+ };
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,