envio 3.9.0 → 3.10.0-subgraph

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 (143) hide show
  1. package/evm.schema.json +26 -0
  2. package/fuel.schema.json +26 -0
  3. package/index.d.ts +41 -8
  4. package/package.json +6 -7
  5. package/src/Batch.res +9 -0
  6. package/src/ChainState.res +35 -39
  7. package/src/ChainState.res.mjs +14 -11
  8. package/src/ChainState.resi +15 -7
  9. package/src/Config.res +61 -44
  10. package/src/Config.res.mjs +56 -19
  11. package/src/Core.res +19 -0
  12. package/src/Core.res.mjs +11 -0
  13. package/src/CrossChainState.res +15 -23
  14. package/src/CrossChainState.res.mjs +10 -18
  15. package/src/CrossChainState.resi +4 -1
  16. package/src/Ecosystem.res +7 -2
  17. package/src/Envio.res +6 -4
  18. package/src/EventConfigBuilder.res +169 -26
  19. package/src/EventConfigBuilder.res.mjs +124 -15
  20. package/src/EventProcessing.res +6 -6
  21. package/src/EventProcessing.res.mjs +8 -6
  22. package/src/HandlerLoader.res +20 -8
  23. package/src/HandlerLoader.res.mjs +11 -2
  24. package/src/HandlerRegister.res +21 -4
  25. package/src/HandlerRegister.res.mjs +24 -5
  26. package/src/InMemoryStore.res +9 -7
  27. package/src/InMemoryStore.res.mjs +3 -3
  28. package/src/IndexerState.res +43 -6
  29. package/src/IndexerState.res.mjs +36 -7
  30. package/src/IndexerState.resi +4 -4
  31. package/src/Internal.res +16 -17
  32. package/src/Metrics.res +72 -6
  33. package/src/Metrics.res.mjs +30 -2
  34. package/src/Persistence.res +36 -30
  35. package/src/Persistence.res.mjs +1 -20
  36. package/src/PgStorage.res +104 -56
  37. package/src/PgStorage.res.mjs +57 -35
  38. package/src/PruneStaleHistory.res +85 -52
  39. package/src/PruneStaleHistory.res.mjs +63 -37
  40. package/src/Rollback.res +68 -45
  41. package/src/Rollback.res.mjs +38 -19
  42. package/src/RollbackCommit.res +7 -9
  43. package/src/RollbackCommit.res.mjs +5 -6
  44. package/src/SafeCheckpointTracking.res +11 -11
  45. package/src/SafeCheckpointTracking.res.mjs +7 -6
  46. package/src/SimulateItems.res +33 -18
  47. package/src/SimulateItems.res.mjs +26 -22
  48. package/src/Sink.res +38 -26
  49. package/src/Sink.res.mjs +21 -16
  50. package/src/TestIndexer.res +5 -5
  51. package/src/TestIndexer.res.mjs +1 -1
  52. package/src/UserContext.res +358 -51
  53. package/src/UserContext.res.mjs +271 -35
  54. package/src/Utils.res +170 -0
  55. package/src/Utils.res.mjs +153 -0
  56. package/src/Writing.res +2 -2
  57. package/src/Writing.res.mjs +1 -1
  58. package/src/bindings/ClickHouse.res +366 -698
  59. package/src/bindings/ClickHouse.res.mjs +371 -421
  60. package/src/bindings/ClickHouseSink.res +337 -0
  61. package/src/bindings/ClickHouseSink.res.mjs +246 -0
  62. package/src/bindings/EventSource.res +8 -2
  63. package/src/bindings/NodeJs.res +6 -0
  64. package/src/bindings/Vitest.res +23 -0
  65. package/src/bindings/Vitest.res.mjs +3 -0
  66. package/src/bindings/WebSocket.res +9 -10
  67. package/src/db/CheckpointBounds.res +53 -0
  68. package/src/db/CheckpointBounds.res.mjs +44 -0
  69. package/src/db/EntityFilter.res +36 -17
  70. package/src/db/EntityFilter.res.mjs +25 -14
  71. package/src/db/EntityHistory.res +47 -22
  72. package/src/db/EntityHistory.res.mjs +19 -12
  73. package/src/db/InternalTable.res +84 -35
  74. package/src/db/InternalTable.res.mjs +56 -23
  75. package/src/db/RollbackFloors.res +55 -0
  76. package/src/db/RollbackFloors.res.mjs +92 -0
  77. package/src/db/Table.res +22 -4
  78. package/src/db/Table.res.mjs +30 -9
  79. package/src/sources/Evm.res +2 -0
  80. package/src/sources/Evm.res.mjs +2 -0
  81. package/src/sources/EvmHyperSyncSource.res +3 -3
  82. package/src/sources/EvmHyperSyncSource.res.mjs +3 -3
  83. package/src/sources/EvmRpcWs.res +124 -0
  84. package/src/sources/EvmRpcWs.res.mjs +117 -0
  85. package/src/sources/Fuel.res +2 -0
  86. package/src/sources/Fuel.res.mjs +2 -0
  87. package/src/sources/FuelHyperSyncSource.res +1 -1
  88. package/src/sources/FuelHyperSyncSource.res.mjs +2 -1
  89. package/src/sources/HeightFeed.res +568 -0
  90. package/src/sources/HeightFeed.res.mjs +452 -0
  91. package/src/sources/HeightStream.res +257 -0
  92. package/src/sources/HeightStream.res.mjs +194 -0
  93. package/src/sources/HyperSync.res +5 -0
  94. package/src/sources/HyperSync.res.mjs +3 -0
  95. package/src/sources/HyperSync.resi +4 -0
  96. package/src/sources/HyperSyncSSE.res +49 -0
  97. package/src/sources/HyperSyncSSE.res.mjs +79 -0
  98. package/src/sources/RpcSource.res +1 -1
  99. package/src/sources/RpcSource.res.mjs +2 -2
  100. package/src/sources/Source.res +54 -1
  101. package/src/sources/Source.res.mjs +25 -0
  102. package/src/sources/SourceManager.res +220 -227
  103. package/src/sources/SourceManager.res.mjs +139 -164
  104. package/src/sources/SourceManager.resi +8 -0
  105. package/src/sources/Svm.res +2 -0
  106. package/src/sources/Svm.res.mjs +2 -0
  107. package/src/sources/SvmHyperSyncClient.res +70 -127
  108. package/src/sources/SvmHyperSyncClient.res.mjs +51 -25
  109. package/src/sources/SvmHyperSyncSource.res +18 -15
  110. package/src/sources/SvmHyperSyncSource.res.mjs +5 -4
  111. package/src/subgraph/blocks.ts +176 -0
  112. package/src/subgraph/calls.ts +217 -0
  113. package/src/subgraph/conformance.ts +102 -0
  114. package/src/subgraph/division.ts +133 -0
  115. package/src/subgraph/errors.ts +90 -0
  116. package/src/subgraph/graph-ts-types/VERSION +2 -0
  117. package/src/subgraph/graph-ts-types/chain/arweave.d.ts +70 -0
  118. package/src/subgraph/graph-ts-types/chain/cosmos.d.ts +327 -0
  119. package/src/subgraph/graph-ts-types/chain/ethereum.d.ts +233 -0
  120. package/src/subgraph/graph-ts-types/chain/near.d.ts +253 -0
  121. package/src/subgraph/graph-ts-types/chain/starknet.d.ts +32 -0
  122. package/src/subgraph/graph-ts-types/common/collections.d.ts +136 -0
  123. package/src/subgraph/graph-ts-types/common/conversion.d.ts +11 -0
  124. package/src/subgraph/graph-ts-types/common/datasource.d.ts +30 -0
  125. package/src/subgraph/graph-ts-types/common/eager-offset.d.ts +0 -0
  126. package/src/subgraph/graph-ts-types/common/json.d.ts +17 -0
  127. package/src/subgraph/graph-ts-types/common/numbers.d.ts +120 -0
  128. package/src/subgraph/graph-ts-types/common/value.d.ts +120 -0
  129. package/src/subgraph/graph-ts-types/common/yaml.d.ts +90 -0
  130. package/src/subgraph/graph-ts-types/global/global.d.ts +194 -0
  131. package/src/subgraph/graph-ts-types/helper-functions.d.ts +22 -0
  132. package/src/subgraph/graph-ts-types/index.d.ts +102 -0
  133. package/src/subgraph/graph-ts.ts +1948 -0
  134. package/src/subgraph/hosts.ts +148 -0
  135. package/src/subgraph/runtime.ts +863 -0
  136. package/src/subgraph/scope.ts +66 -0
  137. package/svm.schema.json +6 -81
  138. package/src/MemoryStorage.res +0 -729
  139. package/src/MemoryStorage.res.mjs +0 -586
  140. package/src/sources/HyperSyncHeightStream.res +0 -129
  141. package/src/sources/HyperSyncHeightStream.res.mjs +0 -110
  142. package/src/sources/RpcWebSocketHeightStream.res +0 -175
  143. package/src/sources/RpcWebSocketHeightStream.res.mjs +0 -180
@@ -0,0 +1,66 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+
3
+ /** What a wrapper is doing when it runs the mapping. */
4
+ export type Mode = "handler" | "register";
5
+
6
+ export type SubgraphSchema = {
7
+ timestampFields: Record<string, string[]>;
8
+ bytesIdEntities: string[];
9
+ entityListFields: Record<string, string[]>;
10
+ entityFields: Record<string, string[]>;
11
+ entityRefFields: Record<string, string[]>;
12
+ /** Each field as the subgraph schema declares it, which is what a mapping reads. */
13
+ entityFieldTypes: Record<
14
+ string,
15
+ Record<string, { kind: string; target?: string; derivedFrom?: string; list: boolean }>
16
+ >;
17
+ };
18
+
19
+ export type Scope = {
20
+ /** envio's handler or contractRegister context. */
21
+ context: any;
22
+ event: any;
23
+ mode: Mode;
24
+ schema: SubgraphSchema;
25
+ dataSource: {
26
+ name: string;
27
+ address: string;
28
+ chainId: number;
29
+ network: string;
30
+ /** The manifest's `context` entries, as `dataSource.context()` serves them. */
31
+ context: Record<string, { type: string; data: string }>;
32
+ };
33
+ /** Addresses already registered this round, so replays stay idempotent. */
34
+ registered: Set<string>;
35
+ /**
36
+ * Host results the register pass has resolved, keyed by effect and input.
37
+ * The register pass has no envio context to run effects through, so it
38
+ * replays the mapping itself and answers from here (§5, register mode).
39
+ */
40
+ resolved?: Map<string, { value?: unknown; error?: unknown }>;
41
+ /** Lookups the current register round is waiting on. */
42
+ awaiting?: Promise<unknown>[];
43
+ /** The block a contract call is evaluated against, as graph-node does. */
44
+ blockNumber: number;
45
+ /** The mapping module, so `ipfs.map` can reach the callback it names. */
46
+ mappingExports: Record<string, any>;
47
+ };
48
+
49
+ const storage = new AsyncLocalStorage<Scope>();
50
+
51
+ export function runInScope<T>(scope: Scope, fn: () => T): T {
52
+ return storage.run(scope, fn);
53
+ }
54
+
55
+ export function currentScope(): Scope {
56
+ const scope = storage.getStore();
57
+ if (!scope) {
58
+ throw new Error(
59
+ "A graph-ts API was called outside of a mapping handler. Envio Subgraph " +
60
+ "runs mappings inside a scope that carries the event and the store; " +
61
+ "calling into graph-ts from module top-level or from a detached " +
62
+ "callback escapes it.",
63
+ );
64
+ }
65
+ return scope;
66
+ }
package/svm.schema.json CHANGED
@@ -352,14 +352,14 @@
352
352
  ]
353
353
  },
354
354
  "idl": {
355
- "description": "Optional path (relative to config.yaml) to an Anchor IDL JSON file. When present, codegen parses the IDL and derives `accounts`/`args` for every named instruction. Mutually exclusive with per-instruction `accounts`/`args` overrides.",
355
+ "description": "Optional path (relative to config.yaml) to an IDL JSON file (Anchor 0.30+, legacy Anchor, Shank, or Codama). When present, every usable instruction is in the catalog and `onInstruction` selects by name. Omit YAML `instructions` to take that catalog as-is. A YAML row overwrites the IDL instruction of the same name, or adds a name the IDL did not declare.",
356
356
  "type": [
357
357
  "string",
358
358
  "null"
359
359
  ]
360
360
  },
361
361
  "instructions": {
362
- "description": "A list of instructions that should be indexed on this program.",
362
+ "description": "Instructions to index. With `idl:`, omit this list to take the full usable IDL catalog. A YAML row overwrites the IDL instruction of the same name, or adds a new name to the catalog, and must set `discriminator` plus both `accounts` and `args`. Without `idl:`, omit `discriminator` to match every instruction of the program; set both `accounts` and `args`, or omit both.",
363
363
  "type": "array",
364
364
  "items": {
365
365
  "$ref": "#/$defs/Instruction"
@@ -369,8 +369,7 @@
369
369
  "additionalProperties": false,
370
370
  "required": [
371
371
  "name",
372
- "program_id",
373
- "instructions"
372
+ "program_id"
374
373
  ]
375
374
  },
376
375
  "Instruction": {
@@ -381,30 +380,12 @@
381
380
  "type": "string"
382
381
  },
383
382
  "discriminator": {
384
- "description": "Hex-encoded instruction-data prefix used as the discriminator (\"0x\" optional). Must be 1, 2, 4, or 8 bytes after decoding. An 8-byte value matches the standard Anchor discriminator.",
383
+ "description": "Hex-encoded instruction-data prefix used as the discriminator (\"0x\" optional), of any whole number of bytes; an 8-byte value matches the standard Anchor discriminator. With `idl:` on the program, this field is required on every YAML row. Without `idl:`, omit it to match every instruction of the program. Every instruction whose prefix an on-chain call carries receives it, so a program-wide entry fires alongside a keyed one, and two entries may share a prefix (say, the layouts before and after a program upgrade): each decodes with its own `args`, and one whose layout rejects the data is skipped for that call.",
385
384
  "type": [
386
385
  "string",
387
386
  "null"
388
387
  ]
389
388
  },
390
- "is_inner": {
391
- "description": "Filter on inner-vs-outer instructions. None / absent matches both.",
392
- "type": [
393
- "boolean",
394
- "null"
395
- ]
396
- },
397
- "account_filters": {
398
- "description": "Optional positional account filters. Two shapes are accepted: a flat list of `{position, values}` entries (AND across positions, OR within `values`); or `{any_of: [[...]] }`, a list of AND-groups that are OR-ed together. Positions must be in 0..=5; positions 6..=9 are reserved for a future extension.",
399
- "anyOf": [
400
- {
401
- "$ref": "#/$defs/AccountFilters"
402
- },
403
- {
404
- "type": "null"
405
- }
406
- ]
407
- },
408
389
  "accounts": {
409
390
  "description": "Optional positional account names. The Nth entry names account slot N on the dispatched instruction; surfaces as `instruction.accounts.<name>` when `fields.instruction` includes `accounts`.",
410
391
  "type": [
@@ -416,7 +397,7 @@
416
397
  }
417
398
  },
418
399
  "args": {
419
- "description": "Optional Borsh argument schema. Each entry names one arg and gives its type; the decoder walks the instruction data after the discriminator in declared order. Mutually exclusive with the program-level `idl` field.",
400
+ "description": "Optional Borsh argument schema. Each entry names one arg and gives its type; the decoder walks the instruction data after the discriminator in declared order. Must be set together with `accounts` when either is present.",
420
401
  "type": [
421
402
  "array",
422
403
  "null"
@@ -431,62 +412,6 @@
431
412
  "name"
432
413
  ]
433
414
  },
434
- "AccountFilters": {
435
- "anyOf": [
436
- {
437
- "type": "array",
438
- "items": {
439
- "$ref": "#/$defs/AccountFilter"
440
- }
441
- },
442
- {
443
- "$ref": "#/$defs/AnyOfAccountFilters"
444
- }
445
- ]
446
- },
447
- "AccountFilter": {
448
- "type": "object",
449
- "properties": {
450
- "position": {
451
- "description": "Account position within the instruction (0..=5).",
452
- "type": "integer",
453
- "format": "uint8",
454
- "minimum": 0,
455
- "maximum": 255
456
- },
457
- "values": {
458
- "description": "Allowed base58 pubkeys for this account position.",
459
- "type": "array",
460
- "items": {
461
- "type": "string"
462
- }
463
- }
464
- },
465
- "additionalProperties": false,
466
- "required": [
467
- "position",
468
- "values"
469
- ]
470
- },
471
- "AnyOfAccountFilters": {
472
- "type": "object",
473
- "properties": {
474
- "any_of": {
475
- "description": "A non-empty list of AND-groups. Each group is itself a non-empty list of `{position, values}` entries that must all match the same instruction. An instruction matches `any_of` when any one group matches.",
476
- "type": "array",
477
- "items": {
478
- "type": "array",
479
- "items": {
480
- "$ref": "#/$defs/AccountFilter"
481
- }
482
- }
483
- }
484
- },
485
- "additionalProperties": false,
486
- "required": [
487
- "any_of"
488
- ]
489
- },
490
415
  "ArgDef": {
491
416
  "description": "One named argument of an instruction. Mirrors\n`hypersync_client_solana::decode::NamedField`.",
492
417
  "type": "object",
@@ -591,7 +516,7 @@
591
516
  "additionalProperties": false
592
517
  },
593
518
  {
594
- "description": "Reference to a nominal type defined in the program-level\n`defined_types` registry (populated from an Anchor IDL `types:`\nblock or the bundled-Metaplex registry).",
519
+ "description": "Reference to a nominal type defined in the program-level\n`defined_types` registry (populated from an Anchor IDL `types:`\nblock).",
595
520
  "type": "object",
596
521
  "properties": {
597
522
  "defined": {