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.
Files changed (186) hide show
  1. package/README.md +40 -34
  2. package/evm.schema.json +3 -3
  3. package/fuel.schema.json +2 -2
  4. package/index.d.ts +3 -3
  5. package/licenses/README.md +1 -1
  6. package/package.json +9 -10
  7. package/src/Batch.res.mjs +5 -5
  8. package/src/BatchProcessing.res +1 -0
  9. package/src/BatchProcessing.res.mjs +1 -0
  10. package/src/Bin.res +0 -7
  11. package/src/Bin.res.mjs +0 -8
  12. package/src/ChainFetching.res +17 -456
  13. package/src/ChainFetching.res.mjs +33 -404
  14. package/src/ChainState.res +48 -83
  15. package/src/ChainState.res.mjs +83 -115
  16. package/src/ChainState.resi +0 -26
  17. package/src/Clock.res +57 -0
  18. package/src/Clock.res.mjs +72 -0
  19. package/src/Config.res +7 -16
  20. package/src/Config.res.mjs +4 -11
  21. package/src/ContractRegisterContext.res +6 -3
  22. package/src/ContractRegisterContext.res.mjs +2 -4
  23. package/src/Core.res +5 -136
  24. package/src/Core.res.mjs +1 -90
  25. package/src/CrossChainState.res +2 -8
  26. package/src/CrossChainState.res.mjs +3 -3
  27. package/src/Ecosystem.res +4 -7
  28. package/src/Ecosystem.res.mjs +8 -8
  29. package/src/EffectState.res +10 -2
  30. package/src/EffectState.res.mjs +8 -4
  31. package/src/EffectState.resi +3 -1
  32. package/src/EntityId.res +2 -7
  33. package/src/EntityId.res.mjs +1 -8
  34. package/src/EntityTables.res +4 -1
  35. package/src/EntityTables.res.mjs +1 -1
  36. package/src/Env.res +0 -16
  37. package/src/Env.res.mjs +0 -11
  38. package/src/EventProcessing.res +1 -38
  39. package/src/EventProcessing.res.mjs +1 -28
  40. package/src/FetchState.res +160 -319
  41. package/src/FetchState.res.mjs +182 -292
  42. package/src/FinalizeBackfill.res +2 -4
  43. package/src/FinalizeBackfill.res.mjs +3 -4
  44. package/src/HandlerLoader.res +15 -39
  45. package/src/HandlerLoader.res.mjs +8 -27
  46. package/src/HandlerRegister.res +0 -4
  47. package/src/HandlerRegister.res.mjs +2 -5
  48. package/src/HandlerRegister.resi +0 -2
  49. package/src/InMemoryTable.res +17 -16
  50. package/src/InMemoryTable.res.mjs +14 -15
  51. package/src/IndexerState.res +28 -4
  52. package/src/IndexerState.res.mjs +19 -6
  53. package/src/IndexerState.resi +4 -0
  54. package/src/Internal.res +0 -110
  55. package/src/Internal.res.mjs +1 -115
  56. package/src/LoadLayer.res +21 -47
  57. package/src/LoadLayer.res.mjs +47 -72
  58. package/src/LoadLayer.resi +0 -26
  59. package/src/Main.res +1 -14
  60. package/src/Main.res.mjs +3 -4
  61. package/src/Persistence.res +3 -23
  62. package/src/Persistence.res.mjs +3 -3
  63. package/src/Rollback.res +0 -1
  64. package/src/Rollback.res.mjs +1 -1
  65. package/src/RunScope.res +0 -3
  66. package/src/SafeCheckpointTracking.res +4 -4
  67. package/src/SafeCheckpointTracking.res.mjs +1 -1
  68. package/src/SimulateItems.res +26 -42
  69. package/src/SimulateItems.res.mjs +16 -40
  70. package/src/StagedRows.res +106 -0
  71. package/src/StagedRows.res.mjs +102 -0
  72. package/src/Staging.res +32 -14
  73. package/src/Staging.res.mjs +17 -20
  74. package/src/Storage.res +277 -998
  75. package/src/Storage.res.mjs +216 -731
  76. package/src/Supervisor.res +75 -56
  77. package/src/Supervisor.res.mjs +55 -26
  78. package/src/TestIndexer.res +22 -27
  79. package/src/TestIndexer.res.mjs +20 -17
  80. package/src/Throttler.res +15 -8
  81. package/src/Throttler.res.mjs +9 -6
  82. package/src/Throttler.resi +1 -1
  83. package/src/UserContext.res +46 -410
  84. package/src/UserContext.res.mjs +30 -318
  85. package/src/Utils.res +0 -23
  86. package/src/Utils.res.mjs +1 -17
  87. package/src/Writing.res +0 -1
  88. package/src/Writing.res.mjs +1 -1
  89. package/src/bindings/ClickHouse.res +0 -322
  90. package/src/bindings/ClickHouse.res.mjs +0 -338
  91. package/src/bindings/StorageClient.res +107 -175
  92. package/src/bindings/StorageClient.res.mjs +19 -8
  93. package/src/bindings/Vitest.res +0 -26
  94. package/src/bindings/Vitest.res.mjs +0 -3
  95. package/src/db/Table.res +24 -150
  96. package/src/db/Table.res.mjs +38 -272
  97. package/src/sources/AddressSet.res +0 -2
  98. package/src/sources/AddressStore.res +0 -3
  99. package/src/sources/ChainSources.res +2 -0
  100. package/src/sources/ChainSources.res.mjs +2 -2
  101. package/src/sources/EvmChain.res +4 -7
  102. package/src/sources/EvmChain.res.mjs +5 -4
  103. package/src/sources/EvmHyperSyncSource.res +2 -2
  104. package/src/sources/EvmHyperSyncSource.res.mjs +1 -1
  105. package/src/sources/EvmRpcClient.res +13 -3
  106. package/src/sources/EvmRpcClient.res.mjs +4 -3
  107. package/src/sources/EvmRpcWs.res +4 -3
  108. package/src/sources/EvmRpcWs.res.mjs +2 -2
  109. package/src/sources/HeightFeed.res +31 -10
  110. package/src/sources/HeightFeed.res.mjs +10 -6
  111. package/src/sources/HeightStream.res +32 -17
  112. package/src/sources/HeightStream.res.mjs +10 -10
  113. package/src/sources/HyperSync.res +1 -2
  114. package/src/sources/HyperSync.res.mjs +1 -2
  115. package/src/sources/HyperSyncSSE.res +4 -6
  116. package/src/sources/HyperSyncSSE.res.mjs +2 -2
  117. package/src/sources/RpcSource.res +10 -1
  118. package/src/sources/RpcSource.res.mjs +4 -3
  119. package/src/sources/Source.res +3 -0
  120. package/src/sources/SourceManager.res +85 -104
  121. package/src/sources/SourceManager.res.mjs +18 -37
  122. package/src/sources/SourceManager.resi +3 -5
  123. package/src/sources/StartBlockResolver.res +1 -0
  124. package/src/sources/StartBlockResolver.res.mjs +4 -3
  125. package/src/sources/SvmHyperSyncSource.res +2 -2
  126. package/src/sources/SvmHyperSyncSource.res.mjs +1 -1
  127. package/svm.schema.json +3 -3
  128. package/src/EffectCacheLookup.res +0 -98
  129. package/src/EffectCacheLookup.res.mjs +0 -116
  130. package/src/PgWriting.res +0 -36
  131. package/src/PgWriting.res.mjs +0 -34
  132. package/src/PreloadLookahead.res +0 -184
  133. package/src/PreloadLookahead.res.mjs +0 -197
  134. package/src/SubgraphLog.res +0 -19
  135. package/src/SubgraphLog.res.mjs +0 -26
  136. package/src/SyncWrites.res +0 -101
  137. package/src/SyncWrites.res.mjs +0 -98
  138. package/src/db/IndexDefinition.res +0 -47
  139. package/src/db/IndexDefinition.res.mjs +0 -60
  140. package/src/sources/CallSource.res +0 -274
  141. package/src/sources/CallSource.res.mjs +0 -196
  142. package/src/subgraph/abi-types.ts +0 -84
  143. package/src/subgraph/aggregations.ts +0 -745
  144. package/src/subgraph/as-package.ts +0 -143
  145. package/src/subgraph/assemblyscript-regex.ts +0 -67
  146. package/src/subgraph/assemblyscript.ts +0 -731
  147. package/src/subgraph/blocks.ts +0 -398
  148. package/src/subgraph/calls-source.ts +0 -702
  149. package/src/subgraph/calls.ts +0 -258
  150. package/src/subgraph/conformance.ts +0 -106
  151. package/src/subgraph/errors.ts +0 -85
  152. package/src/subgraph/graft.ts +0 -73
  153. package/src/subgraph/graph-cli-worker.mjs +0 -35
  154. package/src/subgraph/graph-cli.ts +0 -900
  155. package/src/subgraph/graph-node-decimal.ts +0 -199
  156. package/src/subgraph/graph-ts-enums.ts +0 -28
  157. package/src/subgraph/graph-ts-types/VERSION +0 -2
  158. package/src/subgraph/graph-ts-types/chain/arweave.d.ts +0 -70
  159. package/src/subgraph/graph-ts-types/chain/cosmos.d.ts +0 -327
  160. package/src/subgraph/graph-ts-types/chain/ethereum.d.ts +0 -233
  161. package/src/subgraph/graph-ts-types/chain/near.d.ts +0 -253
  162. package/src/subgraph/graph-ts-types/chain/starknet.d.ts +0 -32
  163. package/src/subgraph/graph-ts-types/common/collections.d.ts +0 -136
  164. package/src/subgraph/graph-ts-types/common/conversion.d.ts +0 -11
  165. package/src/subgraph/graph-ts-types/common/datasource.d.ts +0 -30
  166. package/src/subgraph/graph-ts-types/common/eager-offset.d.ts +0 -0
  167. package/src/subgraph/graph-ts-types/common/json.d.ts +0 -17
  168. package/src/subgraph/graph-ts-types/common/numbers.d.ts +0 -120
  169. package/src/subgraph/graph-ts-types/common/value.d.ts +0 -120
  170. package/src/subgraph/graph-ts-types/common/yaml.d.ts +0 -90
  171. package/src/subgraph/graph-ts-types/global/global.d.ts +0 -194
  172. package/src/subgraph/graph-ts-types/helper-functions.d.ts +0 -22
  173. package/src/subgraph/graph-ts-types/index.d.ts +0 -102
  174. package/src/subgraph/graph-ts.ts +0 -4280
  175. package/src/subgraph/hosts.ts +0 -554
  176. package/src/subgraph/log.ts +0 -28
  177. package/src/subgraph/receipts.ts +0 -184
  178. package/src/subgraph/register-slots.ts +0 -93
  179. package/src/subgraph/rollup.ts +0 -109
  180. package/src/subgraph/rpc.ts +0 -337
  181. package/src/subgraph/runtime.ts +0 -2060
  182. package/src/subgraph/scope.ts +0 -177
  183. package/src/subgraph/stats.ts +0 -42
  184. package/src/subgraph/template-instances.ts +0 -66
  185. package/src/subgraph/toolchain.ts +0 -327
  186. package/src/subgraph/transient.ts +0 -176
@@ -1,176 +0,0 @@
1
- /**
2
- * Every host op that leaves the process — contract calls, balances, block
3
- * timestamps, IPFS, Arweave, ENS — runs through `untilAnswered`.
4
- *
5
- * envio exits on a handler error; it has no batch retry. So a transient failure
6
- * that escaped a host op would stop the whole indexer on one rate-limited call,
7
- * where graph-node backs off and asks again. Only a deterministic answer — a
8
- * value, a revert, a definite miss — may reach the mapping or end the run.
9
- */
10
-
11
- import { warn } from "./log.ts";
12
-
13
- const MAX_BACKOFF_MS = 30_000;
14
-
15
- function positive(name: string, fallback: number): number {
16
- const value = Number(process.env[name]);
17
- return Number.isFinite(value) && value > 0 ? value : fallback;
18
- }
19
-
20
- /** Each attempt's deadline: a request that never answers is given up on. */
21
- export function requestTimeoutMs(): number {
22
- return positive("ENVIO_SUBGRAPH_REQUEST_TIMEOUT_MS", 30_000);
23
- }
24
-
25
- function firstBackoffMs(): number {
26
- return positive("ENVIO_SUBGRAPH_RETRY_BACKOFF_MS", 500);
27
- }
28
-
29
- /** A response status the endpoint answered with. */
30
- export class HttpStatusError extends Error {
31
- constructor(
32
- readonly url: string,
33
- readonly status: number,
34
- statusText: string,
35
- ) {
36
- super(`${url} answered ${status} ${statusText}`.trim());
37
- }
38
- }
39
-
40
- class AttemptTimeout extends Error {
41
- constructor(what: string, ms: number) {
42
- super(`${what} didn't answer within ${ms}ms`);
43
- }
44
- }
45
-
46
- const TRANSIENT_TEXT =
47
- /rate.?limit|too many requests|capacity|limit exceeded|exceeds? (the |its |defined )?limit|timed? ?out|timeout|header not found|ECONNRESET|ECONNREFUSED|EPIPE|ETIMEDOUT|EAI_AGAIN|ENOTFOUND|socket hang up|fetch failed|network|temporar|unavailable|overloaded|busy|try again/i;
48
-
49
- /**
50
- * JSON-RPC codes public endpoints send for "slow down": -32005 "limit
51
- * exceeded" (Infura, Tenderly), -32097 (blastapi), -32090 (Alchemy).
52
- */
53
- const RATE_LIMIT_CODES = new Set([-32005, -32097, -32090]);
54
-
55
- /**
56
- * The rate limits, and the node's own failure, -32603 "Internal error", which
57
- * the same request answers on the next try. graph-node asks again after every
58
- * eth_call error that isn't a revert (`interpret_eth_call_error`).
59
- */
60
- const TRANSIENT_CODES = new Set([...RATE_LIMIT_CODES, -32603]);
61
-
62
- function transientStatus(status: number): boolean {
63
- return status === 408 || status === 425 || status === 429 || status >= 500;
64
- }
65
-
66
- const RATE_LIMIT_TEXT = /rate.?limit|too many requests|request limit|limit exceeded/i;
67
-
68
- /**
69
- * The endpoint saying "slow down" — HTTP 429, or a JSON-RPC rate-limit error —
70
- * on an error or on a JSON-RPC error object, anywhere down its cause chain.
71
- */
72
- export function isRateLimit(error: unknown): boolean {
73
- let current: any = error;
74
- for (let depth = 0; current && depth < 10; depth++) {
75
- if (current.status === 429 || current.code === 429 || RATE_LIMIT_CODES.has(current.code)) return true;
76
- if (typeof current.message === "string" && RATE_LIMIT_TEXT.test(current.message)) return true;
77
- current = current.cause;
78
- }
79
- return false;
80
- }
81
-
82
- /**
83
- * Whether asking again could get a different answer. A status decides it when
84
- * there is one; otherwise the error's own words do, down its cause chain.
85
- */
86
- export function isTransient(error: unknown): boolean {
87
- let current: any = error;
88
- for (let depth = 0; current && depth < 10; depth++) {
89
- if (current instanceof AttemptTimeout) return true;
90
- if (current.name === "AbortError" || current.name === "TimeoutError") return true;
91
- if (typeof current.status === "number") return transientStatus(current.status);
92
- if (TRANSIENT_CODES.has(current.code)) return true;
93
- if (typeof current.message === "string" && TRANSIENT_TEXT.test(current.message)) return true;
94
- current = current.cause;
95
- }
96
- return false;
97
- }
98
-
99
- const sleep = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms));
100
-
101
- /**
102
- * One try, given `requestTimeoutMs`. The deadline holds even if the attempt
103
- * ignores its signal, so a hung request can't stall the handler waiting on it.
104
- */
105
- export async function withDeadline<T>(
106
- what: string,
107
- attempt: (signal: AbortSignal) => Promise<T>,
108
- ): Promise<T> {
109
- const timeout = requestTimeoutMs();
110
- const controller = new AbortController();
111
- let timer: ReturnType<typeof setTimeout> | undefined;
112
- const deadline = new Promise<never>((_, reject) => {
113
- timer = setTimeout(() => {
114
- const error = new AttemptTimeout(what, timeout);
115
- controller.abort(error);
116
- reject(error);
117
- }, timeout);
118
- });
119
- try {
120
- return await Promise.race([attempt(controller.signal), deadline]);
121
- } finally {
122
- clearTimeout(timer);
123
- }
124
- }
125
-
126
- /**
127
- * Tries `attempt` until it answers, backing off exponentially between transient
128
- * failures. With `maxTries`, the last transient failure is thrown once that
129
- * many attempts have failed; with `budgetMs`, once the next wait would end
130
- * past that long after the first attempt.
131
- */
132
- export async function untilAnswered<T>(
133
- what: string,
134
- attempt: (signal: AbortSignal) => Promise<T>,
135
- {
136
- maxTries = Infinity,
137
- // An attempt that goes through a gate (`rpc.ts`) gets its deadline there,
138
- // once it holds a slot: timed from here, a request still queued behind
139
- // the gate would time out unsent, be asked again, and be sent twice.
140
- deadline = true,
141
- budgetMs = Infinity,
142
- }: { maxTries?: number; deadline?: boolean; budgetMs?: number } = {},
143
- ): Promise<T> {
144
- const started = Date.now();
145
- for (let tries = 0; ; tries++) {
146
- try {
147
- return await (deadline ? withDeadline(what, attempt) : attempt(new AbortController().signal));
148
- } catch (error) {
149
- if (!isTransient(error) || tries + 1 >= maxTries) throw error;
150
- const wait = Math.min(firstBackoffMs() * 2 ** tries, MAX_BACKOFF_MS);
151
- if (Date.now() - started + wait > budgetMs) throw error;
152
- const reason = error instanceof Error ? error.message.split("\n")[0] : String(error);
153
- warn(`Envio Subgraph: ${what} failed (${reason}); asking again in ${wait}ms.`);
154
- await sleep(wait);
155
- }
156
- }
157
- }
158
-
159
- /**
160
- * A revert is data: the mapping's `try_` sees `{reverted: true}`, and every
161
- * node gives the same one. Geth says it in the message; Parity, OpenEthereum
162
- * and older Nethermind answer -32015 "VM execution error." and say it in the
163
- * error's data ("Reverted 0x…"), as graph-node reads them.
164
- */
165
- export function isRevert(error: unknown): boolean {
166
- let current: any = error;
167
- for (let depth = 0; current && depth < 10; depth++) {
168
- for (const text of [current.message, current.data]) {
169
- if (typeof text === "string" && REVERT_TEXT.test(text)) return true;
170
- }
171
- current = current.cause;
172
- }
173
- return false;
174
- }
175
-
176
- const REVERT_TEXT = /revert|invalid opcode|bad instruction|bad jump|out of gas/i;