envio 3.12.0 → 3.13.0-alpha.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 (84) hide show
  1. package/package.json +6 -6
  2. package/src/BatchProcessing.res +9 -9
  3. package/src/BatchProcessing.res.mjs +5 -5
  4. package/src/Bin.res +24 -17
  5. package/src/Bin.res.mjs +5 -0
  6. package/src/ChainFetching.res +31 -13
  7. package/src/ChainFetching.res.mjs +9 -4
  8. package/src/ChainState.res +55 -3
  9. package/src/ChainState.res.mjs +46 -3
  10. package/src/ChainState.resi +3 -1
  11. package/src/Config.res +35 -0
  12. package/src/Config.res.mjs +39 -0
  13. package/src/Core.res +4 -0
  14. package/src/Core.res.mjs +4 -0
  15. package/src/CrossChainState.res +61 -4
  16. package/src/CrossChainState.res.mjs +39 -5
  17. package/src/CrossChainState.resi +10 -1
  18. package/src/Env.res +4 -0
  19. package/src/FetchState.res +51 -46
  20. package/src/FetchState.res.mjs +54 -36
  21. package/src/InMemoryTable.res +155 -67
  22. package/src/InMemoryTable.res.mjs +151 -60
  23. package/src/IndexerLoop.res +2 -0
  24. package/src/IndexerLoop.res.mjs +1 -0
  25. package/src/IndexerState.res +41 -1
  26. package/src/IndexerState.res.mjs +43 -4
  27. package/src/IndexerState.resi +10 -0
  28. package/src/LoadLayer.res +57 -34
  29. package/src/LoadLayer.res.mjs +45 -62
  30. package/src/LoadLayer.resi +1 -1
  31. package/src/Logging.res +38 -6
  32. package/src/Logging.res.mjs +32 -5
  33. package/src/Main.res +131 -268
  34. package/src/Main.res.mjs +28 -152
  35. package/src/Metrics.res +263 -102
  36. package/src/Metrics.res.mjs +227 -48
  37. package/src/Persistence.res +27 -2
  38. package/src/Persistence.res.mjs +9 -2
  39. package/src/PgStorage.res +109 -71
  40. package/src/PgStorage.res.mjs +88 -58
  41. package/src/Server.res +181 -0
  42. package/src/Server.res.mjs +143 -0
  43. package/src/Supervisor.res +415 -0
  44. package/src/Supervisor.res.mjs +325 -0
  45. package/src/TestIndexer.res +9 -25
  46. package/src/TestIndexer.res.mjs +5 -4
  47. package/src/UserContext.res +13 -32
  48. package/src/UserContext.res.mjs +1 -7
  49. package/src/Utils.res +1 -4
  50. package/src/Utils.res.mjs +7 -16
  51. package/src/Worker.res +95 -0
  52. package/src/Worker.res.mjs +80 -0
  53. package/src/bindings/NodeJs.res +41 -0
  54. package/src/db/EntityFilter.res +487 -275
  55. package/src/db/EntityFilter.res.mjs +557 -309
  56. package/src/db/InternalTable.res +8 -1
  57. package/src/db/InternalTable.res.mjs +5 -1
  58. package/src/db/Table.res +21 -6
  59. package/src/db/Table.res.mjs +13 -4
  60. package/src/sources/BlockStore.res +7 -2
  61. package/src/sources/EvmHyperSyncSource.res +2 -0
  62. package/src/sources/EvmHyperSyncSource.res.mjs +2 -2
  63. package/src/sources/FuelHyperSyncSource.res +1 -0
  64. package/src/sources/FuelHyperSyncSource.res.mjs +1 -1
  65. package/src/sources/HyperSync.res +4 -0
  66. package/src/sources/HyperSync.res.mjs +4 -2
  67. package/src/sources/HyperSync.resi +1 -0
  68. package/src/sources/HyperSyncClient.res +3 -0
  69. package/src/sources/HyperSyncSSE.res +1 -1
  70. package/src/sources/HyperSyncSSE.res.mjs +4 -10
  71. package/src/sources/RpcSource.res +1 -0
  72. package/src/sources/RpcSource.res.mjs +1 -1
  73. package/src/sources/SimulateSource.res +1 -0
  74. package/src/sources/SimulateSource.res.mjs +1 -1
  75. package/src/sources/Source.res +7 -0
  76. package/src/sources/SourceManager.res +4 -3
  77. package/src/sources/SourceManager.res.mjs +2 -2
  78. package/src/sources/SvmHyperSyncClient.res +5 -0
  79. package/src/sources/SvmHyperSyncSource.res +3 -0
  80. package/src/sources/SvmHyperSyncSource.res.mjs +4 -2
  81. package/src/tui/Tui.res +24 -0
  82. package/src/tui/Tui.res.mjs +18 -0
  83. package/src/tui/components/SyncETA.res +12 -6
  84. package/src/tui/components/SyncETA.res.mjs +12 -8
@@ -0,0 +1,80 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+
3
+ import * as ChainId from "./ChainId.res.mjs";
4
+ import * as Logging from "./Logging.res.mjs";
5
+ import * as Metrics from "./Metrics.res.mjs";
6
+ import * as Process from "process";
7
+ import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
8
+ import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js";
9
+ import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
10
+ import * as S$RescriptSchema from "rescript-schema/src/S.res.mjs";
11
+ import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
12
+
13
+ let envVar = "ENVIO_INTERNAL_WORKER";
14
+
15
+ let configSchema = S$RescriptSchema.object(s => ({
16
+ chainIds: s.f("chainIds", S$RescriptSchema.array(ChainId.schema)),
17
+ holdRealtime: s.fieldOr("holdRealtime", S$RescriptSchema.bool, false)
18
+ }));
19
+
20
+ function detect(env, hasChannel) {
21
+ let match = env[envVar];
22
+ if (!hasChannel) {
23
+ return;
24
+ }
25
+ if (match === undefined) {
26
+ return;
27
+ }
28
+ let config;
29
+ try {
30
+ config = S$RescriptSchema.parseJsonStringOrThrow(match, configSchema);
31
+ } catch (raw_error) {
32
+ let error = Primitive_exceptions.internalToException(raw_error);
33
+ if (error.RE_EXN_ID === S$RescriptSchema.Raised) {
34
+ return Stdlib_JsError.throwWithMessage(`Invalid ` + envVar + `: ` + S$RescriptSchema.$$Error.message(error._1) + `. It is set by an indexer supervisor for the processes it forks, and isn't meant to be set by hand.`);
35
+ }
36
+ throw error;
37
+ }
38
+ return config;
39
+ }
40
+
41
+ let config = detect(Process.env, Stdlib_Option.isSome(Primitive_option.fromNullable(process.channel)));
42
+
43
+ let isEnabled = Stdlib_Option.isSome(config);
44
+
45
+ function bindToSupervisor() {
46
+ process.on("SIGINT", () => {});
47
+ process.on("disconnect", () => {
48
+ Logging.error("The indexer supervisor is gone. Stopping this chain's process.");
49
+ Process.exit(1);
50
+ });
51
+ }
52
+
53
+ function bindRun(getMetrics, onReleaseRealtime) {
54
+ if (isEnabled) {
55
+ Metrics.startRuntimeCollectors();
56
+ setInterval(() => {
57
+ let message_0 = getMetrics();
58
+ let message_1 = Metrics.sampleRuntime();
59
+ let message = {
60
+ kind: "snapshot",
61
+ metrics: message_0,
62
+ runtime: message_1
63
+ };
64
+ process.send(message);
65
+ }, 500);
66
+ process.on("message", message => onReleaseRealtime());
67
+ return;
68
+ }
69
+ }
70
+
71
+ export {
72
+ envVar,
73
+ configSchema,
74
+ detect,
75
+ config,
76
+ isEnabled,
77
+ bindToSupervisor,
78
+ bindRun,
79
+ }
80
+ /* configSchema Not a pure module */
@@ -64,6 +64,21 @@ module Process = {
64
64
  @module("process") external version: string = "version"
65
65
  @module("process")
66
66
  external getActiveResourcesInfo: unit => array<string> = "getActiveResourcesInfo"
67
+
68
+ // Only a process forked with an IPC channel has these. Called through
69
+ // `process` rather than off a namespace import, which would drop the
70
+ // receiver Node's own implementations read.
71
+ @val @scope("process") external sendToParent: 'msg => bool = "send"
72
+ @val @scope("process")
73
+ external onMessage: (@as("message") _, 'msg => unit) => unit = "on"
74
+ @val @scope("process") external onSignal: (string, unit => unit) => unit = "on"
75
+ // Present only in a process forked with an IPC channel.
76
+ @val @scope("process") external channel: Nullable.t<unknown> = "channel"
77
+ @val @scope("process")
78
+ external onDisconnect: (@as("disconnect") _, unit => unit) => unit = "on"
79
+ @val @scope("process") external argv: array<string> = "argv"
80
+ @val @scope("process")
81
+ external emitMessage: (@as("message") _, 'msg) => bool = "emit"
67
82
  }
68
83
 
69
84
  module Buffer = {
@@ -141,6 +156,32 @@ module ChildProcess = {
141
156
 
142
157
  @module("child_process")
143
158
  external execWithOptions: (string, execOptions, callback) => unit = "exec"
159
+
160
+ type child
161
+ type forkOptions = {
162
+ cwd?: string,
163
+ env?: dict<string>,
164
+ // "advanced" uses the structured clone algorithm, so a message keeps the
165
+ // Date values a metrics snapshot carries instead of stringifying them.
166
+ serialization?: string,
167
+ stdio?: array<string>,
168
+ }
169
+ @module("child_process")
170
+ external fork: (string, array<string>, forkOptions) => child = "fork"
171
+ @send external send: (child, 'msg) => bool = "send"
172
+ @send external onMessage: (child, @as("message") _, 'msg => unit) => unit = "on"
173
+ @send
174
+ external onExit: (child, @as("exit") _, (Null.t<int>, Null.t<string>) => unit) => unit = "on"
175
+ @send external onChildError: (child, @as("error") _, exn => unit) => unit = "on"
176
+ @send external kill: (child, string) => bool = "kill"
177
+
178
+ // Present only for a stdio slot the parent asked to pipe.
179
+ type stdioStream
180
+ @get external stdout: child => Null.t<stdioStream> = "stdout"
181
+ @get external stderr: child => Null.t<stdioStream> = "stderr"
182
+ @send external setEncoding: (stdioStream, string) => unit = "setEncoding"
183
+ @send external onData: (stdioStream, @as("data") _, string => unit) => unit = "on"
184
+ @send external onEnd: (stdioStream, @as("end") _, unit => unit) => unit = "on"
144
185
  }
145
186
 
146
187
  module Url = {