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
package/src/Utils.res.mjs CHANGED
@@ -3,6 +3,8 @@ import packageJson from '../package.json' with { type: 'json' }
3
3
 
4
4
  import * as Stdlib_Dict from "@rescript/runtime/lib/es6/Stdlib_Dict.js";
5
5
  import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
6
+ import * as Stdlib_JsExn from "@rescript/runtime/lib/es6/Stdlib_JsExn.js";
7
+ import * as Primitive_int from "@rescript/runtime/lib/es6/Primitive_int.js";
6
8
  import * as Stdlib_BigInt from "@rescript/runtime/lib/es6/Stdlib_BigInt.js";
7
9
  import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
8
10
  import * as Stdlib_String from "@rescript/runtime/lib/es6/Stdlib_String.js";
@@ -14,6 +16,22 @@ import * as Primitive_string from "@rescript/runtime/lib/es6/Primitive_string.js
14
16
  import * as S$RescriptSchema from "rescript-schema/src/S.res.mjs";
15
17
  import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
16
18
 
19
+ function jitter(delay) {
20
+ return (delay / 2 | 0) + (Math.random() * (delay / 2 | 0) | 0) | 0;
21
+ }
22
+
23
+ function clearTimeoutRef(timeoutId) {
24
+ let id = timeoutId.contents;
25
+ if (id !== undefined) {
26
+ clearTimeout(Primitive_option.valFromOption(id));
27
+ }
28
+ timeoutId.contents = undefined;
29
+ }
30
+
31
+ function expBackoff(base, exp, maxMillis) {
32
+ return Primitive_int.min(base * (Math.pow(2.0, Primitive_int.min(exp, 20)) | 0) | 0, maxMillis);
33
+ }
34
+
17
35
  function delay(milliseconds) {
18
36
  return new Promise((resolve, param) => {
19
37
  setTimeout(() => resolve(), milliseconds);
@@ -61,6 +79,11 @@ let Option = {
61
79
  getExn: getExn
62
80
  };
63
81
 
82
+ function incrementBy(dict, key, count) {
83
+ let current = dict[key];
84
+ dict[key] = current !== undefined ? current + count | 0 : count;
85
+ }
86
+
64
87
  function getOrInsertEmptyDict(dict, key) {
65
88
  let d = dict[key];
66
89
  if (d !== undefined) {
@@ -169,6 +192,7 @@ let shallowCopy = ((dict) => ({...dict}));
169
192
 
170
193
  let Dict = {
171
194
  $$delete: Stdlib_Dict.$$delete,
195
+ incrementBy: incrementBy,
172
196
  getOrInsertEmptyDict: getOrInsertEmptyDict,
173
197
  push: push,
174
198
  pushMany: pushMany,
@@ -211,6 +235,10 @@ let UnsafeIntOperators = {};
211
235
 
212
236
  let immutableEmpty = [];
213
237
 
238
+ function quotedJoin(names) {
239
+ return names.map(name => `"` + name + `"`).join(", ");
240
+ }
241
+
214
242
  function mergeSorted(f, xs, ys) {
215
243
  if (xs.length === 0) {
216
244
  return ys;
@@ -393,6 +421,7 @@ let $$Array$1 = {
393
421
  partition: Stdlib_Array.partition,
394
422
  unzip: Stdlib_Array.unzip,
395
423
  immutableEmpty: immutableEmpty,
424
+ quotedJoin: quotedJoin,
396
425
  mergeSorted: mergeSorted,
397
426
  clearInPlace: clearInPlace$1,
398
427
  setIndexImmutable: setIndexImmutable,
@@ -462,15 +491,120 @@ function unwrapResultExn(res) {
462
491
  throw res._0;
463
492
  }
464
493
 
494
+ let asUint8Array = ((value) =>
495
+ value instanceof Uint8Array
496
+ ? value.constructor === Uint8Array
497
+ ? value
498
+ : new Uint8Array(value.buffer, value.byteOffset, value.byteLength)
499
+ : undefined);
500
+
501
+ function toHex(bytes) {
502
+ return Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength).toString("hex");
503
+ }
504
+
505
+ function toPgArrayLiteral(values) {
506
+ return "{" + values.map(value => {
507
+ if (value == null) {
508
+ return "NULL";
509
+ }
510
+ let bytes = asUint8Array(value);
511
+ if (bytes !== undefined) {
512
+ return `"\\\\x` + toHex(bytes) + `"`;
513
+ } else if (Array.isArray(value)) {
514
+ return toPgArrayLiteral(value);
515
+ } else {
516
+ return Stdlib_JsError.throwWithMessage("Expected Uint8Array");
517
+ }
518
+ }).join(",") + "}";
519
+ }
520
+
521
+ function compare(a, b) {
522
+ let aLength = a.length;
523
+ let bLength = b.length;
524
+ let _index = 0;
525
+ while (true) {
526
+ let index = _index;
527
+ if (index === aLength || index === bLength) {
528
+ return Primitive_int.compare(aLength, bLength);
529
+ }
530
+ let order = Primitive_int.compare(a[index], b[index]);
531
+ if (order !== 0) {
532
+ return order;
533
+ }
534
+ _index = index + 1 | 0;
535
+ continue;
536
+ };
537
+ }
538
+
539
+ let Bytes = {
540
+ asUint8Array: asUint8Array,
541
+ toHex: toHex,
542
+ toPgArrayLiteral: toPgArrayLiteral,
543
+ compare: compare
544
+ };
545
+
465
546
  let variantTag = S$RescriptSchema.union([
466
547
  S$RescriptSchema.string,
467
548
  S$RescriptSchema.object(s => s.f("TAG", S$RescriptSchema.string))
468
549
  ]);
469
550
 
551
+ function nullTolerant(schema) {
552
+ return S$RescriptSchema.transform(S$RescriptSchema.$$null(schema), param => ({
553
+ p: value => value,
554
+ s: value => {
555
+ if (value == null) {
556
+ return;
557
+ } else {
558
+ return Primitive_option.some(value);
559
+ }
560
+ }
561
+ }));
562
+ }
563
+
564
+ let bytes = S$RescriptSchema.custom("Bytes", s => ({
565
+ p: unknown => {
566
+ let bytes = asUint8Array(unknown);
567
+ if (bytes !== undefined) {
568
+ return bytes;
569
+ } else {
570
+ return s.fail("Expected Uint8Array", undefined);
571
+ }
572
+ },
573
+ s: bytes => bytes
574
+ }));
575
+
576
+ let bytesArray = S$RescriptSchema.custom("BytesArray", s => ({
577
+ p: unknown => {
578
+ if (Array.isArray(unknown)) {
579
+ return unknown.map(item => {
580
+ let bytes = asUint8Array(item);
581
+ if (bytes !== undefined) {
582
+ return bytes;
583
+ } else {
584
+ return s.fail("Expected Uint8Array", undefined);
585
+ }
586
+ });
587
+ } else {
588
+ return s.fail("Expected array of Uint8Array", undefined);
589
+ }
590
+ },
591
+ s: toPgArrayLiteral
592
+ }));
593
+
470
594
  let dbDate = S$RescriptSchema.preprocess(S$RescriptSchema.json(false), param => ({
471
595
  s: date => date.toISOString()
472
596
  }));
473
597
 
598
+ let clickHouseJson = S$RescriptSchema.preprocess(S$RescriptSchema.json(false), param => ({
599
+ s: value => {
600
+ if (value == null) {
601
+ return "null";
602
+ } else {
603
+ return value;
604
+ }
605
+ }
606
+ }));
607
+
474
608
  let clickHouseDate = S$RescriptSchema.preprocess(S$RescriptSchema.json(false), param => ({
475
609
  s: date => date.getTime()
476
610
  }));
@@ -506,7 +640,11 @@ function coerceToJsonPgType(schema) {
506
640
 
507
641
  let Schema = {
508
642
  variantTag: variantTag,
643
+ nullTolerant: nullTolerant,
644
+ bytes: bytes,
645
+ bytesArray: bytesArray,
509
646
  dbDate: dbDate,
647
+ clickHouseJson: clickHouseJson,
510
648
  clickHouseDate: clickHouseDate,
511
649
  coerceToJsonPgType: coerceToJsonPgType
512
650
  };
@@ -640,6 +778,13 @@ function prettifyExn(exn) {
640
778
  }
641
779
  }
642
780
 
781
+ function exnMessage(exn) {
782
+ let jsExn = Primitive_exceptions.internalToException(exn);
783
+ if (jsExn.RE_EXN_ID === "JsExn") {
784
+ return Stdlib_JsExn.message(jsExn._1);
785
+ }
786
+ }
787
+
643
788
  let value;
644
789
 
645
790
  try {
@@ -695,7 +840,13 @@ let $$Promise$1 = {
695
840
  isCatchable: isCatchable
696
841
  };
697
842
 
843
+ let maxBackoffExponent = 20;
844
+
698
845
  export {
846
+ jitter,
847
+ clearTimeoutRef,
848
+ maxBackoffExponent,
849
+ expBackoff,
699
850
  delay,
700
851
  $$Object,
701
852
  $$Error,
@@ -708,6 +859,7 @@ export {
708
859
  Url,
709
860
  Result,
710
861
  unwrapResultExn,
862
+ Bytes,
711
863
  Schema,
712
864
  getVariantsTags,
713
865
  $$Set,
@@ -717,6 +869,7 @@ export {
717
869
  $$Proxy,
718
870
  Hash,
719
871
  prettifyExn,
872
+ exnMessage,
720
873
  EnvioPackage,
721
874
  $$BigInt,
722
875
  $$Promise$1 as $$Promise,
package/src/Writing.res CHANGED
@@ -158,8 +158,8 @@ let runOneWrite = async (state: IndexerState.t) => {
158
158
  state->IndexerState.markCommitted(~upToCheckpointId)
159
159
 
160
160
  switch rollback {
161
- | Some({progressBlockNumberByChainId}) if RollbackCommit.callbacks->Utils.Array.notEmpty =>
162
- await RollbackCommit.fire(~progressBlockNumberByChainId)
161
+ | Some({progressedChains}) if RollbackCommit.callbacks->Utils.Array.notEmpty =>
162
+ await RollbackCommit.fire(~progressedChains)
163
163
  | _ => ()
164
164
  }
165
165
 
@@ -130,7 +130,7 @@ async function runOneWrite(state) {
130
130
  ]);
131
131
  IndexerState.markCommitted(state, upToCheckpointId);
132
132
  if (rollback !== undefined && Utils.$$Array.notEmpty(RollbackCommit.callbacks)) {
133
- await RollbackCommit.fire(rollback.progressBlockNumberByChainId);
133
+ await RollbackCommit.fire(rollback.progressedChains);
134
134
  }
135
135
  return await PruneStaleHistory.runForced(state, pruneTargets);
136
136
  }