envio 3.0.0-alpha-main-clickhouse-sink → 3.0.0-alpha.1

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 (100) hide show
  1. package/bin.js +5 -3
  2. package/evm.schema.json +23 -6
  3. package/fuel.schema.json +17 -5
  4. package/index.d.ts +0 -27
  5. package/index.js +9 -6
  6. package/package.json +11 -7
  7. package/rescript.json +4 -3
  8. package/src/{Address.res.js → Address.res.mjs} +7 -6
  9. package/src/{Batch.res.js → Batch.res.mjs} +19 -18
  10. package/src/{ChainMap.res.js → ChainMap.res.mjs} +20 -19
  11. package/src/{Config.res.js → Config.res.mjs} +11 -10
  12. package/src/Envio.gen.ts +2 -15
  13. package/src/Envio.res +0 -36
  14. package/src/{Envio.res.js → Envio.res.mjs} +5 -16
  15. package/src/{ErrorHandling.res.js → ErrorHandling.res.mjs} +10 -9
  16. package/src/EventRegister.res +7 -0
  17. package/src/{EventRegister.res.js → EventRegister.res.mjs} +29 -18
  18. package/src/EventRegister.resi +1 -0
  19. package/src/{EventUtils.res.js → EventUtils.res.mjs} +10 -9
  20. package/src/{EvmTypes.res.js → EvmTypes.res.mjs} +5 -4
  21. package/src/{FetchState.res.js → FetchState.res.mjs} +44 -43
  22. package/src/{Hasura.res.js → Hasura.res.mjs} +25 -24
  23. package/src/{InMemoryStore.res.js → InMemoryStore.res.mjs} +19 -18
  24. package/src/{InMemoryTable.res.js → InMemoryTable.res.mjs} +21 -20
  25. package/src/Internal.gen.ts +1 -3
  26. package/src/Internal.res +9 -2
  27. package/src/{Internal.res.js → Internal.res.mjs} +21 -11
  28. package/src/{LazyLoader.res.js → LazyLoader.res.mjs} +14 -13
  29. package/src/{LoadManager.res.js → LoadManager.res.mjs} +11 -10
  30. package/src/{LogSelection.res.js → LogSelection.res.mjs} +14 -13
  31. package/src/{Logging.res.js → Logging.res.mjs} +37 -36
  32. package/src/{Persistence.res.js → Persistence.res.mjs} +22 -21
  33. package/src/{PgStorage.res.js → PgStorage.res.mjs} +58 -57
  34. package/src/Platform.res +4 -5
  35. package/src/{Platform.res.js → Platform.res.mjs} +10 -10
  36. package/src/{Prometheus.res.js → Prometheus.res.mjs} +66 -65
  37. package/src/{ReorgDetection.res.js → ReorgDetection.res.mjs} +12 -11
  38. package/src/{SafeCheckpointTracking.res.js → SafeCheckpointTracking.res.mjs} +6 -5
  39. package/src/{Sink.res.js → Sink.res.mjs} +6 -5
  40. package/src/{TableIndices.res.js → TableIndices.res.mjs} +8 -7
  41. package/src/{Throttler.res.js → Throttler.res.mjs} +7 -6
  42. package/src/{Time.res.js → Time.res.mjs} +8 -7
  43. package/src/{TopicFilter.res.js → TopicFilter.res.mjs} +18 -17
  44. package/src/Utils.res +40 -0
  45. package/src/{Utils.res.js → Utils.res.mjs} +68 -34
  46. package/src/bindings/BigDecimal.gen.ts +2 -2
  47. package/src/bindings/BigDecimal.res +5 -5
  48. package/src/bindings/BigDecimal.res.d.mts +5 -0
  49. package/src/bindings/{BigDecimal.res.js → BigDecimal.res.mjs} +10 -9
  50. package/src/bindings/BigInt.gen.ts +2 -2
  51. package/src/bindings/BigInt.res.d.mts +5 -0
  52. package/src/bindings/{BigInt.res.js → BigInt.res.mjs} +25 -24
  53. package/src/bindings/ClickHouse.res +2 -2
  54. package/src/bindings/{ClickHouse.res.js → ClickHouse.res.mjs} +22 -21
  55. package/src/bindings/Ethers.gen.ts +2 -2
  56. package/src/bindings/Ethers.res.d.mts +5 -0
  57. package/src/bindings/{Ethers.res.js → Ethers.res.mjs} +18 -17
  58. package/src/bindings/{Hrtime.res.js → Hrtime.res.mjs} +13 -12
  59. package/src/bindings/{Lodash.res.js → Lodash.res.mjs} +4 -3
  60. package/src/bindings/NodeJs.res +13 -1
  61. package/src/bindings/NodeJs.res.mjs +48 -0
  62. package/src/bindings/Pino.res +6 -6
  63. package/src/bindings/{Pino.res.js → Pino.res.mjs} +16 -15
  64. package/src/bindings/Postgres.res +2 -2
  65. package/src/bindings/{Postgres.res.js → Postgres.res.mjs} +4 -3
  66. package/src/bindings/{PromClient.res.js → PromClient.res.mjs} +6 -5
  67. package/src/bindings/{Promise.res.js → Promise.res.mjs} +6 -5
  68. package/src/bindings/{SDSL.res.js → SDSL.res.mjs} +3 -2
  69. package/src/bindings/{Viem.res.js → Viem.res.mjs} +9 -8
  70. package/src/bindings/vendored-lodash-fns.js +3 -35
  71. package/src/db/{EntityHistory.res.js → EntityHistory.res.mjs} +21 -20
  72. package/src/db/InternalTable.gen.ts +2 -2
  73. package/src/db/InternalTable.res +0 -2
  74. package/src/db/{InternalTable.res.js → InternalTable.res.mjs} +19 -19
  75. package/src/db/{Schema.res.js → Schema.res.mjs} +10 -9
  76. package/src/db/{Table.res.js → Table.res.mjs} +34 -33
  77. package/src/sources/{EventRouter.res.js → EventRouter.res.mjs} +17 -16
  78. package/src/sources/{Fuel.res.js → Fuel.res.mjs} +6 -5
  79. package/src/sources/{HyperFuel.res.js → HyperFuel.res.mjs} +14 -13
  80. package/src/sources/{HyperFuelClient.res.js → HyperFuelClient.res.mjs} +7 -6
  81. package/src/sources/{HyperFuelSource.res.js → HyperFuelSource.res.mjs} +28 -27
  82. package/src/sources/{HyperSync.res.js → HyperSync.res.mjs} +21 -20
  83. package/src/sources/HyperSyncClient.gen.ts +1 -1
  84. package/src/sources/HyperSyncClient.res +78 -20
  85. package/src/sources/{HyperSyncClient.res.js → HyperSyncClient.res.mjs} +32 -15
  86. package/src/sources/{HyperSyncJsonApi.res.js → HyperSyncJsonApi.res.mjs} +10 -9
  87. package/src/sources/HyperSyncSource.res +77 -9
  88. package/src/sources/{HyperSyncSource.res.js → HyperSyncSource.res.mjs} +99 -38
  89. package/src/sources/{Rpc.res.js → Rpc.res.mjs} +16 -15
  90. package/src/sources/{RpcSource.res.js → RpcSource.res.mjs} +40 -39
  91. package/src/sources/Source.res +1 -1
  92. package/src/sources/{Source.res.js → Source.res.mjs} +4 -3
  93. package/src/sources/SourceManager.res +12 -1
  94. package/src/sources/{SourceManager.res.js → SourceManager.res.mjs} +32 -21
  95. package/src/sources/vendored-fuel-abi-coder.js +94 -149
  96. package/src/vendored/{Rest.res.js → Rest.res.mjs} +12 -11
  97. package/src/bindings/NodeJs.res.js +0 -35
  98. /package/src/{Change.res.js → Change.res.mjs} +0 -0
  99. /package/src/{Indexer.res.js → Indexer.res.mjs} +0 -0
  100. /package/src/bindings/{Express.res.js → Express.res.mjs} +0 -0
@@ -1,24 +1,21 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
- 'use strict';
3
2
 
4
- var Rest = require("../vendored/Rest.res.js");
5
- var Viem = require("../bindings/Viem.res.js");
6
- var Utils = require("../Utils.res.js");
7
- var Hrtime = require("../bindings/Hrtime.res.js");
8
- var Js_exn = require("rescript/lib/js/js_exn.js");
9
- var Source = require("./Source.res.js");
10
- var Logging = require("../Logging.res.js");
11
- var HyperSync = require("./HyperSync.res.js");
12
- var Belt_Array = require("rescript/lib/js/belt_Array.js");
13
- var Belt_Option = require("rescript/lib/js/belt_Option.js");
14
- var EventRouter = require("./EventRouter.res.js");
15
- var LogSelection = require("../LogSelection.res.js");
16
- var ErrorHandling = require("../ErrorHandling.res.js");
17
- var Caml_exceptions = require("rescript/lib/js/caml_exceptions.js");
18
- var HyperSyncClient = require("./HyperSyncClient.res.js");
19
- var Caml_splice_call = require("rescript/lib/js/caml_splice_call.js");
20
- var HyperSyncJsonApi = require("./HyperSyncJsonApi.res.js");
21
- var Caml_js_exceptions = require("rescript/lib/js/caml_js_exceptions.js");
3
+ import * as Viem from "../bindings/Viem.res.mjs";
4
+ import * as Utils from "../Utils.res.mjs";
5
+ import * as Hrtime from "../bindings/Hrtime.res.mjs";
6
+ import * as Js_exn from "rescript/lib/es6/js_exn.js";
7
+ import * as Source from "./Source.res.mjs";
8
+ import * as Logging from "../Logging.res.mjs";
9
+ import * as HyperSync from "./HyperSync.res.mjs";
10
+ import * as Belt_Array from "rescript/lib/es6/belt_Array.js";
11
+ import * as Belt_Option from "rescript/lib/es6/belt_Option.js";
12
+ import * as EventRouter from "./EventRouter.res.mjs";
13
+ import * as LogSelection from "../LogSelection.res.mjs";
14
+ import * as ErrorHandling from "../ErrorHandling.res.mjs";
15
+ import * as Caml_exceptions from "rescript/lib/es6/caml_exceptions.js";
16
+ import * as HyperSyncClient from "./HyperSyncClient.res.mjs";
17
+ import * as Caml_splice_call from "rescript/lib/es6/caml_splice_call.js";
18
+ import * as Caml_js_exceptions from "rescript/lib/es6/caml_js_exceptions.js";
22
19
 
23
20
  function getSelectionConfig(selection, chain) {
24
21
  var nonOptionalBlockFieldNames = new Set();
@@ -123,7 +120,62 @@ function memoGetSelectionConfig(chain) {
123
120
  };
124
121
  }
125
122
 
126
- function make(param) {
123
+ async function makeInternal(client) {
124
+ return {
125
+ heightStream: await client.streamHeight(),
126
+ currentHeight: 0,
127
+ errMessage: undefined
128
+ };
129
+ }
130
+
131
+ async function start(state, chainId) {
132
+ while(true) {
133
+ var height = await state.heightStream.recv();
134
+ if (typeof height !== "object") {
135
+ Logging.trace({
136
+ msg: "HyperSync height stream is connected",
137
+ chainId: chainId
138
+ });
139
+ state.errMessage = undefined;
140
+ } else if (height.type === "Height") {
141
+ state.currentHeight = height.height;
142
+ } else {
143
+ var errorMsg = height.errorMsg;
144
+ Logging.trace({
145
+ msg: "HyperSync height stream is reconnecting",
146
+ err: errorMsg,
147
+ delayMillis: height.delayMillis,
148
+ chainId: chainId
149
+ });
150
+ state.errMessage = errorMsg;
151
+ }
152
+ };
153
+ }
154
+
155
+ async function make(client, chainId) {
156
+ var state = await makeInternal(client);
157
+ start(state, chainId);
158
+ return state;
159
+ }
160
+
161
+ async function getHeight(state) {
162
+ while(state.currentHeight === 0 && Belt_Option.isNone(state.errMessage)) {
163
+ await Utils.delay(200);
164
+ };
165
+ var errMessage = state.errMessage;
166
+ if (errMessage !== undefined) {
167
+ return Js_exn.raiseError(errMessage);
168
+ } else {
169
+ return state.currentHeight;
170
+ }
171
+ }
172
+
173
+ var HeightState = {
174
+ make: make,
175
+ getHeight: getHeight
176
+ };
177
+
178
+ function make$1(param) {
127
179
  var lowercaseAddresses = param.lowercaseAddresses;
128
180
  var eventRouter = param.eventRouter;
129
181
  var shouldUseHypersyncClientDecoder = param.shouldUseHypersyncClientDecoder;
@@ -132,7 +184,7 @@ function make(param) {
132
184
  var chain = param.chain;
133
185
  var getSelectionConfig = memoGetSelectionConfig(chain);
134
186
  var apiToken = Belt_Option.getWithDefault(param.apiToken, "3dc856dd-b0ea-494f-b27e-017b8b6b7e07");
135
- var client = HyperSyncClient.make(endpointUrl, apiToken, param.clientTimeoutMillis, param.clientMaxRetries, !lowercaseAddresses);
187
+ var client = HyperSyncClient.make(endpointUrl, apiToken, param.clientTimeoutMillis, param.clientMaxRetries, !lowercaseAddresses, param.serializationFormat, param.enableQueryCaching, undefined, undefined, undefined);
136
188
  var hscDecoder = {
137
189
  contents: undefined
138
190
  };
@@ -385,33 +437,42 @@ function make(param) {
385
437
  var getBlockHashes = function (blockNumbers, logger) {
386
438
  return HyperSync.queryBlockDataMulti(endpointUrl, apiToken, blockNumbers, logger).then(HyperSync.mapExn);
387
439
  };
388
- var jsonApiClient = Rest.client(endpointUrl, undefined);
440
+ var heightStatePromise = make(client, chain);
389
441
  return {
390
442
  name: "HyperSync",
391
443
  sourceFor: "Sync",
392
444
  chain: chain,
393
445
  poweredByHyperSync: true,
394
- pollingInterval: 100,
446
+ pollingInterval: 32,
395
447
  getBlockHashes: getBlockHashes,
396
448
  getHeightOrThrow: (async function () {
397
- var height = await Rest.$$fetch(HyperSyncJsonApi.heightRoute, apiToken, jsonApiClient);
398
- if (typeof height === "number") {
399
- return height;
400
- } else if (height === "Your token is malformed. For more info: https://docs.envio.dev/docs/HyperSync/api-tokens.") {
401
- Logging.error("Your ENVIO_API_TOKEN is malformed. The indexer will not be able to fetch events. Update the token and restart the indexer using 'pnpm envio start'. For more info: https://docs.envio.dev/docs/HyperSync/api-tokens");
402
- await new Promise((function (param, param$1) {
403
-
404
- }));
405
- return 0;
406
- } else {
407
- return Js_exn.raiseError(height);
449
+ var heightState = await heightStatePromise;
450
+ try {
451
+ return await getHeight(heightState);
452
+ }
453
+ catch (raw_exn){
454
+ var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
455
+ if (exn.RE_EXN_ID === Js_exn.$$Error) {
456
+ if (Belt_Option.getWithDefault(exn._1.message, "").includes("Your token is malformed. For more info: https://docs.envio.dev/docs/HyperSync/api-tokens.")) {
457
+ Logging.error("Your ENVIO_API_TOKEN is malformed. The indexer will not be able to fetch events. Update the token and restart the indexer using 'pnpm envio start'. For more info: https://docs.envio.dev/docs/HyperSync/api-tokens");
458
+ await new Promise((function (param, param$1) {
459
+
460
+ }));
461
+ return 0;
462
+ }
463
+ throw exn;
464
+ }
465
+ throw exn;
408
466
  }
409
467
  }),
410
468
  getItemsOrThrow: getItemsOrThrow
411
469
  };
412
470
  }
413
471
 
414
- exports.getSelectionConfig = getSelectionConfig;
415
- exports.memoGetSelectionConfig = memoGetSelectionConfig;
416
- exports.make = make;
417
- /* Rest Not a pure module */
472
+ export {
473
+ getSelectionConfig ,
474
+ memoGetSelectionConfig ,
475
+ HeightState ,
476
+ make$1 as make,
477
+ }
478
+ /* Viem Not a pure module */
@@ -1,13 +1,12 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
- 'use strict';
3
2
 
4
- var Viem = require("viem");
5
- var Utils = require("../Utils.res.js");
6
- var $$BigInt = require("../bindings/BigInt.res.js");
7
- var Address = require("../Address.res.js");
8
- var Belt_Array = require("rescript/lib/js/belt_Array.js");
9
- var Caml_option = require("rescript/lib/js/caml_option.js");
10
- var S$RescriptSchema = require("rescript-schema/src/S.res.js");
3
+ import * as Viem from "viem";
4
+ import * as Utils from "../Utils.res.mjs";
5
+ import * as $$BigInt from "../bindings/BigInt.res.mjs";
6
+ import * as Address from "../Address.res.mjs";
7
+ import * as Belt_Array from "rescript/lib/es6/belt_Array.js";
8
+ import * as Caml_option from "rescript/lib/es6/caml_option.js";
9
+ import * as S$RescriptSchema from "rescript-schema/src/S.res.mjs";
11
10
 
12
11
  function makeRpcRoute(method, paramsSchema, resultSchema) {
13
12
  var idSchema = S$RescriptSchema.literal(1);
@@ -188,11 +187,13 @@ var GetBlockHeight = {
188
187
  route: route$2
189
188
  };
190
189
 
191
- exports.makeRpcRoute = makeRpcRoute;
192
- exports.makeHexSchema = makeHexSchema;
193
- exports.hexBigintSchema = hexBigintSchema;
194
- exports.hexIntSchema = hexIntSchema;
195
- exports.GetLogs = GetLogs;
196
- exports.GetBlockByNumber = GetBlockByNumber;
197
- exports.GetBlockHeight = GetBlockHeight;
190
+ export {
191
+ makeRpcRoute ,
192
+ makeHexSchema ,
193
+ hexBigintSchema ,
194
+ hexIntSchema ,
195
+ GetLogs ,
196
+ GetBlockByNumber ,
197
+ GetBlockHeight ,
198
+ }
198
199
  /* hexBigintSchema Not a pure module */
@@ -1,32 +1,31 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
- 'use strict';
3
2
 
4
- var Rpc = require("./Rpc.res.js");
5
- var Caml = require("rescript/lib/js/caml.js");
6
- var Rest = require("../vendored/Rest.res.js");
7
- var Time = require("../Time.res.js");
8
- var Viem = require("../bindings/Viem.res.js");
9
- var Utils = require("../Utils.res.js");
10
- var Ethers = require("../bindings/Ethers.res.js");
11
- var Hrtime = require("../bindings/Hrtime.res.js");
12
- var Js_exn = require("rescript/lib/js/js_exn.js");
13
- var Source = require("./Source.res.js");
14
- var Address = require("../Address.res.js");
15
- var Logging = require("../Logging.res.js");
16
- var $$Promise = require("../bindings/Promise.res.js");
17
- var Belt_Int = require("rescript/lib/js/belt_Int.js");
18
- var Belt_Array = require("rescript/lib/js/belt_Array.js");
19
- var FetchState = require("../FetchState.res.js");
20
- var LazyLoader = require("../LazyLoader.res.js");
21
- var Belt_Option = require("rescript/lib/js/belt_Option.js");
22
- var Caml_option = require("rescript/lib/js/caml_option.js");
23
- var EventRouter = require("./EventRouter.res.js");
24
- var LogSelection = require("../LogSelection.res.js");
25
- var Caml_exceptions = require("rescript/lib/js/caml_exceptions.js");
26
- var HyperSyncClient = require("./HyperSyncClient.res.js");
27
- var Caml_splice_call = require("rescript/lib/js/caml_splice_call.js");
28
- var S$RescriptSchema = require("rescript-schema/src/S.res.js");
29
- var Caml_js_exceptions = require("rescript/lib/js/caml_js_exceptions.js");
3
+ import * as Rpc from "./Rpc.res.mjs";
4
+ import * as Caml from "rescript/lib/es6/caml.js";
5
+ import * as Rest from "../vendored/Rest.res.mjs";
6
+ import * as Time from "../Time.res.mjs";
7
+ import * as Viem from "../bindings/Viem.res.mjs";
8
+ import * as Utils from "../Utils.res.mjs";
9
+ import * as Ethers from "../bindings/Ethers.res.mjs";
10
+ import * as Hrtime from "../bindings/Hrtime.res.mjs";
11
+ import * as Js_exn from "rescript/lib/es6/js_exn.js";
12
+ import * as Source from "./Source.res.mjs";
13
+ import * as Address from "../Address.res.mjs";
14
+ import * as Logging from "../Logging.res.mjs";
15
+ import * as $$Promise from "../bindings/Promise.res.mjs";
16
+ import * as Belt_Int from "rescript/lib/es6/belt_Int.js";
17
+ import * as Belt_Array from "rescript/lib/es6/belt_Array.js";
18
+ import * as FetchState from "../FetchState.res.mjs";
19
+ import * as LazyLoader from "../LazyLoader.res.mjs";
20
+ import * as Belt_Option from "rescript/lib/es6/belt_Option.js";
21
+ import * as Caml_option from "rescript/lib/es6/caml_option.js";
22
+ import * as EventRouter from "./EventRouter.res.mjs";
23
+ import * as LogSelection from "../LogSelection.res.mjs";
24
+ import * as Caml_exceptions from "rescript/lib/es6/caml_exceptions.js";
25
+ import * as HyperSyncClient from "./HyperSyncClient.res.mjs";
26
+ import * as Caml_splice_call from "rescript/lib/es6/caml_splice_call.js";
27
+ import * as S$RescriptSchema from "rescript-schema/src/S.res.mjs";
28
+ import * as Caml_js_exceptions from "rescript/lib/es6/caml_js_exceptions.js";
30
29
 
31
30
  var QueryTimout = /* @__PURE__ */Caml_exceptions.create("RpcSource.QueryTimout");
32
31
 
@@ -835,16 +834,18 @@ function make(param) {
835
834
  };
836
835
  }
837
836
 
838
- exports.QueryTimout = QueryTimout;
839
- exports.getKnownBlock = getKnownBlock;
840
- exports.getKnownBlockWithBackoff = getKnownBlockWithBackoff;
841
- exports.getSuggestedBlockIntervalFromExn = getSuggestedBlockIntervalFromExn;
842
- exports.maxSuggestedBlockIntervalKey = maxSuggestedBlockIntervalKey;
843
- exports.getNextPage = getNextPage;
844
- exports.getSelectionConfig = getSelectionConfig;
845
- exports.memoGetSelectionConfig = memoGetSelectionConfig;
846
- exports.makeThrowingGetEventBlock = makeThrowingGetEventBlock;
847
- exports.makeThrowingGetEventTransaction = makeThrowingGetEventTransaction;
848
- exports.sanitizeUrl = sanitizeUrl;
849
- exports.make = make;
837
+ export {
838
+ QueryTimout ,
839
+ getKnownBlock ,
840
+ getKnownBlockWithBackoff ,
841
+ getSuggestedBlockIntervalFromExn ,
842
+ maxSuggestedBlockIntervalKey ,
843
+ getNextPage ,
844
+ getSelectionConfig ,
845
+ memoGetSelectionConfig ,
846
+ makeThrowingGetEventBlock ,
847
+ makeThrowingGetEventTransaction ,
848
+ sanitizeUrl ,
849
+ make ,
850
+ }
850
851
  /* Rpc Not a pure module */
@@ -32,7 +32,7 @@ type getItemsError =
32
32
 
33
33
  exception GetItemsError(getItemsError)
34
34
 
35
- type sourceFor = Sync | Fallback
35
+ type sourceFor = Sync | Fallback | Live
36
36
  type t = {
37
37
  name: string,
38
38
  sourceFor: sourceFor,
@@ -1,9 +1,10 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
- 'use strict';
3
2
 
4
- var Caml_exceptions = require("rescript/lib/js/caml_exceptions.js");
3
+ import * as Caml_exceptions from "rescript/lib/es6/caml_exceptions.js";
5
4
 
6
5
  var GetItemsError = /* @__PURE__ */Caml_exceptions.create("Source.GetItemsError");
7
6
 
8
- exports.GetItemsError = GetItemsError;
7
+ export {
8
+ GetItemsError ,
9
+ }
9
10
  /* No side effect */
@@ -222,11 +222,20 @@ let waitForNewBlock = async (sourceManager: t, ~currentBlockHeight) => {
222
222
  )
223
223
  logger->Logging.childTrace("Initiating check for new blocks.")
224
224
 
225
+ // Only include Live sources if we've actually synced some blocks
226
+ // (currentBlockHeight > 0 means we've fetched at least one batch)
227
+ // This prevents Live RPC from winning the initial height race and
228
+ // becoming activeSource, which would bypass HyperSync's smart block detection
229
+ let isInitialHeightFetch = currentBlockHeight === 0
230
+
225
231
  let syncSources = []
226
232
  let fallbackSources = []
227
233
  sources->Utils.Set.forEach(source => {
228
234
  if (
229
235
  source.sourceFor === Sync ||
236
+ // Include Live sources only after initial sync has started
237
+ // Live sources are optimized for real-time indexing with lower latency
238
+ (source.sourceFor === Live && !isInitialHeightFetch) ||
230
239
  // Even if the active source is a fallback, still include
231
240
  // it to the list. So we don't wait for a timeout again
232
241
  // if all main sync sources are still not valid
@@ -321,7 +330,9 @@ let getNextSyncSource = (
321
330
  } else if (
322
331
  switch source.sourceFor {
323
332
  | Sync => true
324
- | Fallback => attemptFallbacks || source === initialSource
333
+ // Live sources should NOT be used for historical sync rotation
334
+ // They are only meant for real-time indexing once synced
335
+ | Live | Fallback => attemptFallbacks || source === initialSource
325
336
  }
326
337
  ) {
327
338
  (hasActive.contents ? after : before)->Array.push(source)
@@ -1,18 +1,17 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
- 'use strict';
3
2
 
4
- var Caml = require("rescript/lib/js/caml.js");
5
- var Utils = require("../Utils.res.js");
6
- var Hrtime = require("../bindings/Hrtime.res.js");
7
- var Js_exn = require("rescript/lib/js/js_exn.js");
8
- var Source = require("./Source.res.js");
9
- var Logging = require("../Logging.res.js");
10
- var Belt_Array = require("rescript/lib/js/belt_Array.js");
11
- var FetchState = require("../FetchState.res.js");
12
- var Prometheus = require("../Prometheus.res.js");
13
- var Belt_Option = require("rescript/lib/js/belt_Option.js");
14
- var ErrorHandling = require("../ErrorHandling.res.js");
15
- var Caml_js_exceptions = require("rescript/lib/js/caml_js_exceptions.js");
3
+ import * as Caml from "rescript/lib/es6/caml.js";
4
+ import * as Utils from "../Utils.res.mjs";
5
+ import * as Hrtime from "../bindings/Hrtime.res.mjs";
6
+ import * as Js_exn from "rescript/lib/es6/js_exn.js";
7
+ import * as Source from "./Source.res.mjs";
8
+ import * as Logging from "../Logging.res.mjs";
9
+ import * as Belt_Array from "rescript/lib/es6/belt_Array.js";
10
+ import * as FetchState from "../FetchState.res.mjs";
11
+ import * as Prometheus from "../Prometheus.res.mjs";
12
+ import * as Belt_Option from "rescript/lib/es6/belt_Option.js";
13
+ import * as ErrorHandling from "../ErrorHandling.res.mjs";
14
+ import * as Caml_js_exceptions from "rescript/lib/es6/caml_js_exceptions.js";
16
15
 
17
16
  function getActiveSource(sourceManager) {
18
17
  return sourceManager.activeSource;
@@ -157,10 +156,11 @@ async function waitForNewBlock(sourceManager, currentBlockHeight) {
157
156
  currentBlockHeight: currentBlockHeight
158
157
  });
159
158
  Logging.childTrace(logger, "Initiating check for new blocks.");
159
+ var isInitialHeightFetch = currentBlockHeight === 0;
160
160
  var syncSources = [];
161
161
  var fallbackSources = [];
162
162
  sourceManager.sources.forEach(function (source) {
163
- if (source.sourceFor === "Sync" || source === sourceManager.activeSource) {
163
+ if (source.sourceFor === "Sync" || source.sourceFor === "Live" && !isInitialHeightFetch || source === sourceManager.activeSource) {
164
164
  syncSources.push(source);
165
165
  } else {
166
166
  fallbackSources.push(source);
@@ -217,7 +217,16 @@ function getNextSyncSource(sourceManager, initialSource, currentSource, attemptF
217
217
  }
218
218
  var match = source.sourceFor;
219
219
  var tmp;
220
- tmp = match === "Sync" ? true : attemptFallbacks || source === initialSource;
220
+ switch (match) {
221
+ case "Sync" :
222
+ tmp = true;
223
+ break;
224
+ case "Fallback" :
225
+ case "Live" :
226
+ tmp = attemptFallbacks || source === initialSource;
227
+ break;
228
+
229
+ }
221
230
  if (tmp) {
222
231
  (
223
232
  hasActive.contents ? after : before
@@ -391,10 +400,12 @@ async function executeQuery(sourceManager, query, currentBlockHeight) {
391
400
  return responseRef;
392
401
  }
393
402
 
394
- exports.make = make;
395
- exports.getActiveSource = getActiveSource;
396
- exports.fetchNext = fetchNext;
397
- exports.waitForNewBlock = waitForNewBlock;
398
- exports.executeQuery = executeQuery;
399
- exports.makeGetHeightRetryInterval = makeGetHeightRetryInterval;
403
+ export {
404
+ make ,
405
+ getActiveSource ,
406
+ fetchNext ,
407
+ waitForNewBlock ,
408
+ executeQuery ,
409
+ makeGetHeightRetryInterval ,
410
+ }
400
411
  /* Utils Not a pure module */