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
@@ -0,0 +1,72 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+
3
+ import * as Performance from "./bindings/Performance.res.mjs";
4
+ import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js";
5
+ import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
6
+
7
+ let refuseReal = {
8
+ contents: false
9
+ };
10
+
11
+ function refused(what) {
12
+ return Stdlib_JsError.throwWithMessage(`Clock.real ` + what + ` on virtual time. Use the clock the code was given, so advanceTime can see and move it.`);
13
+ }
14
+
15
+ function real_now() {
16
+ if (refuseReal.contents) {
17
+ return refused("read the time");
18
+ } else {
19
+ return Performance.now();
20
+ }
21
+ }
22
+
23
+ function real_setTimeout(label, callback, millis) {
24
+ if (refuseReal.contents && millis > 0) {
25
+ return refused(`armed "` + label + `"`);
26
+ } else {
27
+ return setTimeout(callback, millis);
28
+ }
29
+ }
30
+
31
+ function real_clearTimeout(timer) {
32
+ clearTimeout(timer);
33
+ }
34
+
35
+ function real_random(prim) {
36
+ return Math.random();
37
+ }
38
+
39
+ let real = {
40
+ now: real_now,
41
+ setTimeout: real_setTimeout,
42
+ clearTimeout: real_clearTimeout,
43
+ random: real_random
44
+ };
45
+
46
+ function delay(clock, label, millis) {
47
+ return new Promise((resolve, _reject) => {
48
+ clock.setTimeout(label, () => resolve(), millis);
49
+ });
50
+ }
51
+
52
+ function jitter(clock, delay) {
53
+ return (delay / 2 | 0) + (clock.random() * (delay / 2 | 0) | 0) | 0;
54
+ }
55
+
56
+ function clearRef(clock, timer) {
57
+ let timer$1 = timer.contents;
58
+ if (timer$1 !== undefined) {
59
+ clock.clearTimeout(Primitive_option.valFromOption(timer$1));
60
+ }
61
+ timer.contents = undefined;
62
+ }
63
+
64
+ export {
65
+ refuseReal,
66
+ refused,
67
+ real,
68
+ delay,
69
+ jitter,
70
+ clearRef,
71
+ }
72
+ /* No side effect */
package/src/Config.res CHANGED
@@ -155,9 +155,6 @@ type t = {
155
155
  // reach, so its checkpoints have to be comparable across chains.
156
156
  checkpointSequence: CheckpointSequence.t,
157
157
  envioInfo: JSON.t,
158
- // Set only in subgraph mode: the translated manifest, which is what makes
159
- // the subgraph runtime take over handler registration.
160
- subgraph: option<JSON.t>,
161
158
  }
162
159
 
163
160
  type rpcSourceFor = | @as("sync") Sync | @as("fallback") Fallback | @as("realtime") Realtime
@@ -621,7 +618,6 @@ let publicConfigSchema = S.schema(s =>
621
618
  "svm": s.matches(S.option(publicConfigEcosystemSchema)),
622
619
  "enums": s.matches(S.option(S.dict(S.array(S.string)))),
623
620
  "entities": s.matches(S.option(S.array(entityJsonSchema))),
624
- "subgraph": s.matches(S.option(S.json(~validate=false))),
625
621
  }
626
622
  )
627
623
 
@@ -704,10 +700,6 @@ let toEnvioInfo = (publicConfigJson: JSON.t): JSON.t => {
704
700
  switch envioInfo {
705
701
  | Object(obj) => {
706
702
  commandFields->Array.forEach(field => obj->Utils.Dict.deleteInPlace(field))
707
- // The subgraph blob is how the runtime finds mappings. None of it
708
- // describes stored data — that's already in `evm` / `entities` — so a
709
- // specVersion bump or a mapping-path edit must not force a reset.
710
- obj->Utils.Dict.deleteInPlace("subgraph")
711
703
  ecosystemFields->Array.forEach(ecosystem =>
712
704
  switch obj->Dict.get(ecosystem) {
713
705
  | Some(Object(ecosystemDict)) => ecosystemDict->Utils.Dict.deleteInPlace("chains")
@@ -1079,15 +1071,19 @@ let fromPublic = (publicConfigJson: JSON.t) => {
1079
1071
  startBlock: publicChainConfig["startBlock"],
1080
1072
  endBlock: ?publicChainConfig["endBlock"],
1081
1073
  maxReorgDepth: switch ecosystemName {
1082
- | Ecosystem.Evm => publicChainConfig["maxReorgDepth"]->Option.getOr(200)
1074
+ // One less than the 200 blocks behind the head a source checks for a
1075
+ // lagging node, so the backfill, which stops one block below the window,
1076
+ // ends exactly where those checks begin.
1077
+ | Ecosystem.Evm => publicChainConfig["maxReorgDepth"]->Option.getOr(199)
1083
1078
  // Tower BFT roots a block once 32 votes lock it in (MAX_LOCKOUT_HISTORY
1084
1079
  // is 31, plus the slot itself), which is what `finalized` waits for — so
1085
1080
  // 32 is the protocol's own bound on how far a fork can be replaced. That
1086
1081
  // bound counts *blocks* while the threshold here is measured in slot
1087
1082
  // numbers, and skipped slots make the slot distance the larger of the
1088
1083
  // two, so the default keeps a wide margin over it. Slots are ~0.4s, so
1089
- // even this spans well under two minutes of chain.
1090
- | Ecosystem.Svm => publicChainConfig["maxReorgDepth"]->Option.getOr(200)
1084
+ // even this spans well under two minutes of chain. One less than 200
1085
+ // for the same reason as EVM: the backfill stops one slot below it.
1086
+ | Ecosystem.Svm => publicChainConfig["maxReorgDepth"]->Option.getOr(199)
1091
1087
  | Ecosystem.Fuel => 0
1092
1088
  },
1093
1089
  blockLag: publicChainConfig["blockLag"]->Option.getOr(0),
@@ -1156,10 +1152,6 @@ let fromPublic = (publicConfigJson: JSON.t) => {
1156
1152
  | None => []
1157
1153
  }
1158
1154
 
1159
- if publicConfig["subgraph"]->Option.isSome {
1160
- Env.subgraphMode := true
1161
- }
1162
-
1163
1155
  let config = {
1164
1156
  name: publicConfig["name"],
1165
1157
  description: publicConfig["description"],
@@ -1188,7 +1180,6 @@ let fromPublic = (publicConfigJson: JSON.t) => {
1188
1180
  allEnums,
1189
1181
  checkpointSequence: CheckpointSequence.fromEntities(userEntities),
1190
1182
  envioInfo: publicConfigJson->toEnvioInfo,
1191
- subgraph: publicConfig["subgraph"],
1192
1183
  }
1193
1184
 
1194
1185
  switch publicConfig["isolatedChains"] {
@@ -449,8 +449,7 @@ let publicConfigSchema = S$RescriptSchema.schema(s => ({
449
449
  fuel: s.m(S$RescriptSchema.option(publicConfigEcosystemSchema)),
450
450
  svm: s.m(S$RescriptSchema.option(publicConfigEcosystemSchema)),
451
451
  enums: s.m(S$RescriptSchema.option(S$RescriptSchema.dict(S$RescriptSchema.array(S$RescriptSchema.string)))),
452
- entities: s.m(S$RescriptSchema.option(S$RescriptSchema.array(entityJsonSchema))),
453
- subgraph: s.m(S$RescriptSchema.option(S$RescriptSchema.json(false)))
452
+ entities: s.m(S$RescriptSchema.option(S$RescriptSchema.array(entityJsonSchema)))
454
453
  }));
455
454
 
456
455
  function contractMappingOf(chainConfigs) {
@@ -520,7 +519,6 @@ function toEnvioInfo(publicConfigJson) {
520
519
  let envioInfo = JSON.parse(JSON.stringify(publicConfigJson));
521
520
  if (typeof envioInfo === "object" && envioInfo !== null && !Array.isArray(envioInfo)) {
522
521
  commandFields.forEach(field => Utils.Dict.deleteInPlace(envioInfo, field));
523
- Utils.Dict.deleteInPlace(envioInfo, "subgraph");
524
522
  ecosystemFields.forEach(ecosystem => {
525
523
  let match = envioInfo[ecosystem];
526
524
  if (typeof match === "object" && match !== null && !Array.isArray(match)) {
@@ -765,7 +763,7 @@ function fromPublic(publicConfigJson) {
765
763
  break;
766
764
  case "evm" :
767
765
  case "svm" :
768
- tmp = Stdlib_Option.getOr(publicChainConfig.maxReorgDepth, 200);
766
+ tmp = Stdlib_Option.getOr(publicChainConfig.maxReorgDepth, 199);
769
767
  break;
770
768
  }
771
769
  return {
@@ -810,9 +808,6 @@ function fromPublic(publicConfigJson) {
810
808
  name: Utils.$$String.capitalize(param[0]),
811
809
  handler: param[1].handler
812
810
  })) : [];
813
- if (Stdlib_Option.isSome(publicConfig.subgraph)) {
814
- Env.subgraphMode.contents = true;
815
- }
816
811
  let config_name = publicConfig.name;
817
812
  let config_description = publicConfig.description;
818
813
  let config_handlers = Stdlib_Option.getOr(publicConfig.handlers, "src/handlers");
@@ -827,7 +822,6 @@ function fromPublic(publicConfigJson) {
827
822
  let config_projectFlags = Stdlib_Option.getOr(publicConfig.projectFlags, "");
828
823
  let config_checkpointSequence = CheckpointSequence.fromEntities(userEntities);
829
824
  let config_envioInfo = toEnvioInfo(publicConfigJson);
830
- let config_subgraph = publicConfig.subgraph;
831
825
  let config = {
832
826
  name: config_name,
833
827
  description: config_description,
@@ -855,8 +849,7 @@ function fromPublic(publicConfigJson) {
855
849
  userEntities: userEntities,
856
850
  allEnums: allEnums,
857
851
  checkpointSequence: config_checkpointSequence,
858
- envioInfo: config_envioInfo,
859
- subgraph: config_subgraph
852
+ envioInfo: config_envioInfo
860
853
  };
861
854
  let chainIds = publicConfig.isolatedChains;
862
855
  if (chainIds !== undefined) {
@@ -981,7 +974,7 @@ function diffPaths(stored, current) {
981
974
  }
982
975
  return;
983
976
  }
984
- } else {
977
+ } else if (s !== null) {
985
978
  switch (typeof s) {
986
979
  case "object" :
987
980
  if (typeof c === "object" && c !== null && !Array.isArray(c)) {
@@ -20,7 +20,11 @@ let make = (~config: Config.t): Internal.contractRegisterContext => {
20
20
  {
21
21
  enumerable: true,
22
22
  get: () =>
23
- RunScope.currentContractRegisterRunOrThrow(~prop="chain").item->Internal.getItemChainId,
23
+ (
24
+ RunScope.currentContractRegisterRunOrThrow(
25
+ ~prop="chain",
26
+ ).item->Internal.castUnsafeEventItem
27
+ ).chainId,
24
28
  },
25
29
  )
26
30
  ->ignore
@@ -45,8 +49,7 @@ let make = (~config: Config.t): Internal.contractRegisterContext => {
45
49
  // The value is passed from user-land, so validate and checksum/lowercase it.
46
50
  address: config->Config.normalizeUserAddress(contractAddress),
47
51
  contractName,
48
- registrationBlock: run.item->Internal.getItemBlockNumber,
49
- creationRound: ?run.creationRound,
52
+ registrationBlock: (run.item->Internal.castUnsafeEventItem).blockNumber,
50
53
  })
51
54
  ->ignore
52
55
  },
@@ -4,7 +4,6 @@ import * as Utils from "./Utils.res.mjs";
4
4
  import * as Config from "./Config.res.mjs";
5
5
  import * as Logger from "./Logger.res.mjs";
6
6
  import * as ChainMap from "./ChainMap.res.mjs";
7
- import * as Internal from "./Internal.res.mjs";
8
7
  import * as RunScope from "./RunScope.res.mjs";
9
8
  import * as EntityFilter from "./db/EntityFilter.res.mjs";
10
9
  import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js";
@@ -13,7 +12,7 @@ function make(config) {
13
12
  let chain = Object.create(Utils.StrictObject.makePrototype(prop => Stdlib_JsError.throwWithMessage(`Invalid contract name '` + prop + `' on context.chain. ` + EntityFilter.codegenHelpMessage)));
14
13
  Object.defineProperty(chain, "id", {
15
14
  enumerable: true,
16
- get: () => Internal.getItemChainId(RunScope.currentContractRegisterRunOrThrow("chain").item)
15
+ get: () => RunScope.currentContractRegisterRunOrThrow("chain").item.chainId
17
16
  });
18
17
  let contractNames = new Set();
19
18
  ChainMap.values(config.chainMap).forEach(chainConfig => {
@@ -30,8 +29,7 @@ function make(config) {
30
29
  run.registrations.push({
31
30
  address: Config.normalizeUserAddress(config, contractAddress),
32
31
  contractName: contractName,
33
- registrationBlock: run.item.blockNumber,
34
- creationRound: run.creationRound
32
+ registrationBlock: run.item.blockNumber
35
33
  });
36
34
  }
37
35
  }
package/src/Core.res CHANGED
@@ -18,6 +18,8 @@ type loggerCtor
18
18
  type mockHyperSyncServerCtor
19
19
  // Test-only: the ledger behind envio-tests' MockSource.
20
20
  type mockSourceCtor
21
+ // Test-only: the virtual clock a scenario's source layer runs on.
22
+ type virtualClockCtor
21
23
  type fromUserApiOptions = {
22
24
  schema?: string,
23
25
  env?: dict<string>,
@@ -31,83 +33,8 @@ type fromUserApiResult = {
31
33
  indexerCode: Null.t<string>,
32
34
  }
33
35
 
34
- type fromSubgraphOptions = {
35
- name?: string,
36
- env?: dict<string>,
37
- files?: dict<string>,
38
- root?: string,
39
- }
40
-
41
- type bundledCodegenResult = {outputDir: string, files: array<string>}
42
-
43
- type filledGeneratedFile = {
44
- file: string,
45
- source: string,
46
- abiName?: string,
47
- renamedFrom?: string,
48
- undeclared: bool,
49
- }
50
-
51
- // One column of a Postgres table, flattened for the boundary: napi carries no
52
- // tagged union, so the field type arrives as its name plus whichever of the
53
- // modifiers it takes.
54
- type pgColumnInput = {
55
- // The database column name, renames already resolved.
56
- name: string,
57
- fieldType: string,
58
- isArray: bool,
59
- isNullable: bool,
60
- isPrimaryKey: bool,
61
- defaultValue?: string,
62
- precision?: int,
63
- scale?: int,
64
- enumName?: string,
65
- }
66
-
67
- type pgTableInput = {
68
- // In the order the table declares them.
69
- columns: array<pgColumnInput>,
70
- // The columns a batch's rows carry, in the order they are laid out.
71
- writeColumns: array<string>,
72
- partitionByColumn?: string,
73
- appendOnly: bool,
74
- // An entity's history table, and the column its chain is in when it is
75
- // per-chain.
76
- historyTable?: string,
77
- chainIdColumn?: string,
78
- }
79
-
80
- type pgIndexColumnInput = {
81
- name: string,
82
- direction: string,
83
- }
84
-
85
- type pgIndexInput = {
86
- tableName: string,
87
- columns: array<pgIndexColumnInput>,
88
- method: string,
89
- }
90
-
91
36
  type addon = {
92
- getConfigJson: (
93
- ~configPath: Null.t<string>,
94
- ~directory: Null.t<string>,
95
- ~portsServedHere: array<int>,
96
- ) => string,
97
- fromSubgraph: (string, string, fromSubgraphOptions) => fromUserApiResult,
98
- subgraphFileToJavascript: (string, string, bool) => string,
99
- subgraphRegisterHandlers: (array<string>, array<array<string>>) => array<array<string>>,
100
- subgraphSureCreates: (string, array<string>, array<string>) => array<array<string>>,
101
- subgraphKeccak256: Uint8Array.t => Uint8Array.t,
102
- subgraphAbiDecode: (string, Uint8Array.t, bool) => unknown,
103
- subgraphAbiEncodeCall: (string, string, JSON.t) => string,
104
- subgraphBundledCodegen: (string, Null.t<string>) => bundledCodegenResult,
105
- subgraphBundledCodegenCurrent: (string, string) => bool,
106
- subgraphMissingGraphCliMessage: string => string,
107
- subgraphFillGenerated: (string, string, string, array<string>) => array<filledGeneratedFile>,
108
- subgraphWorkspacePackages: string => dict<string>,
109
- subgraphWorkspaceRoot: string => Null.t<string>,
110
- subgraphScriptsWriting: (string, string) => array<array<string>>,
37
+ getConfigJson: (~configPath: Null.t<string>, ~directory: Null.t<string>) => string,
111
38
  encodeIndexedTopic: (~abiType: string, ~value: unknown) => EvmTypes.Hex.t,
112
39
  isSvmPubkey: (~value: string) => bool,
113
40
  fromUserApi: (string, fromUserApiOptions) => fromUserApiResult,
@@ -142,6 +69,8 @@ type addon = {
142
69
  mockHyperSyncServer: mockHyperSyncServerCtor,
143
70
  @as("MockSource")
144
71
  mockSource: mockSourceCtor,
72
+ @as("VirtualClock")
73
+ virtualClock: virtualClockCtor,
145
74
  encodeAddresses: (~ecosystem: string, ~addresses: array<Address.t>) => array<NodeJs.Buffer.t>,
146
75
  normalizeEvmAddress: (~address: string, ~shouldChecksum: bool) => Null.t<Address.t>,
147
76
  renderAddresses: (
@@ -365,24 +294,11 @@ let getAddon = () =>
365
294
  }
366
295
  }
367
296
 
368
- // The ports servers in this process listen on. Node has no public list of
369
- // them; `_getActiveHandles` has held them since its first releases, and
370
- // without it nothing is reported.
371
- let portsServedHere: unit => array<int> = %raw(`() =>
372
- typeof process._getActiveHandles !== "function"
373
- ? []
374
- : process
375
- ._getActiveHandles()
376
- .map((handle) => (handle?.listening === true && typeof handle.address === "function" ? handle.address() : null))
377
- .filter((address) => typeof address?.port === "number")
378
- .map((address) => address.port)`)
379
-
380
297
  let getConfigJson = (~configPath=?, ~directory=?) => {
381
298
  let addon = getAddon()
382
299
  addon.getConfigJson(
383
300
  ~configPath=configPath->Null.fromOption,
384
301
  ~directory=directory->Null.fromOption,
385
- ~portsServedHere=portsServedHere(),
386
302
  )
387
303
  }
388
304
 
@@ -404,53 +320,6 @@ let fromUserApi = (~schema=?, ~env=?, ~files=?, ~withIndexerTypes=false, yaml) =
404
320
  )
405
321
  }
406
322
 
407
- /// Parses a subgraph project without touching the filesystem: subgraph.yaml and
408
- /// its schema inline, ABI bodies through `files`.
409
- let fromSubgraph = (~name=?, ~env=?, ~files=?, ~root=?, ~manifest, ~schema) => {
410
- let addon = getAddon()
411
- addon.fromSubgraph(manifest, schema, {?name, ?env, ?files, ?root})
412
- }
413
-
414
- let subgraphFileToJavascript = (~source, ~path, ~legacyNulls) => {
415
- let addon = getAddon()
416
- addon.subgraphFileToJavascript(source, path, legacyNulls)
417
- }
418
-
419
- let subgraphRegisterHandlers = (~mappingFiles, ~handlers) => {
420
- let addon = getAddon()
421
- addon.subgraphRegisterHandlers(mappingFiles, handlers)
422
- }
423
-
424
- let subgraphSureCreates = (~mappingFile, ~handlers, ~templates) =>
425
- getAddon().subgraphSureCreates(mappingFile, handlers, templates)
426
-
427
- let subgraphKeccak256 = bytes => getAddon().subgraphKeccak256(bytes)
428
-
429
- let subgraphAbiDecode = (ty, data, params) => getAddon().subgraphAbiDecode(ty, data, params)
430
-
431
- let subgraphAbiEncodeCall = (name, inputs, args) =>
432
- getAddon().subgraphAbiEncodeCall(name, inputs, args)
433
-
434
- let subgraphBundledCodegen = (~manifestFile, ~outputDir: option<string>) => {
435
- let addon = getAddon()
436
- addon.subgraphBundledCodegen(manifestFile, outputDir->Null.fromOption)
437
- }
438
-
439
- let subgraphBundledCodegenCurrent = (~manifestFile, ~outputDir) =>
440
- getAddon().subgraphBundledCodegenCurrent(manifestFile, outputDir)
441
-
442
- let subgraphMissingGraphCliMessage = generated =>
443
- getAddon().subgraphMissingGraphCliMessage(generated)
444
-
445
- let subgraphFillGenerated = (~root, ~manifestFile, ~outputDir, ~wanted) =>
446
- getAddon().subgraphFillGenerated(root, manifestFile, outputDir, wanted)
447
-
448
- let subgraphWorkspacePackages = root => getAddon().subgraphWorkspacePackages(root)
449
-
450
- let subgraphWorkspaceRoot = root => getAddon().subgraphWorkspaceRoot(root)
451
-
452
- let subgraphScriptsWriting = (~dir, ~needle) => getAddon().subgraphScriptsWriting(dir, needle)
453
-
454
323
  let runCli = args => {
455
324
  let addon = getAddon()
456
325
  addon.runCli(~args, ~envioPackageDir=Null.make(envioPackageDir))
package/src/Core.res.mjs CHANGED
@@ -216,18 +216,9 @@ function getAddon() {
216
216
  return a$1;
217
217
  }
218
218
 
219
- let portsServedHere = (() =>
220
- typeof process._getActiveHandles !== "function"
221
- ? []
222
- : process
223
- ._getActiveHandles()
224
- .map((handle) => (handle?.listening === true && typeof handle.address === "function" ? handle.address() : null))
225
- .filter((address) => typeof address?.port === "number")
226
- .map((address) => address.port));
227
-
228
219
  function getConfigJson(configPath, directory) {
229
220
  let addon = getAddon();
230
- return addon.getConfigJson(Stdlib_Null.fromOption(configPath), Stdlib_Null.fromOption(directory), portsServedHere());
221
+ return addon.getConfigJson(Stdlib_Null.fromOption(configPath), Stdlib_Null.fromOption(directory));
231
222
  }
232
223
 
233
224
  function fromUserApi(schema, env, files, withIndexerTypesOpt, yaml) {
@@ -241,71 +232,6 @@ function fromUserApi(schema, env, files, withIndexerTypesOpt, yaml) {
241
232
  });
242
233
  }
243
234
 
244
- function fromSubgraph(name, env, files, root, manifest, schema) {
245
- let addon = getAddon();
246
- return addon.fromSubgraph(manifest, schema, {
247
- name: name,
248
- env: env,
249
- files: files,
250
- root: root
251
- });
252
- }
253
-
254
- function subgraphFileToJavascript(source, path, legacyNulls) {
255
- let addon = getAddon();
256
- return addon.subgraphFileToJavascript(source, path, legacyNulls);
257
- }
258
-
259
- function subgraphRegisterHandlers(mappingFiles, handlers) {
260
- let addon = getAddon();
261
- return addon.subgraphRegisterHandlers(mappingFiles, handlers);
262
- }
263
-
264
- function subgraphSureCreates(mappingFile, handlers, templates) {
265
- return getAddon().subgraphSureCreates(mappingFile, handlers, templates);
266
- }
267
-
268
- function subgraphKeccak256(bytes) {
269
- return getAddon().subgraphKeccak256(bytes);
270
- }
271
-
272
- function subgraphAbiDecode(ty, data, params) {
273
- return getAddon().subgraphAbiDecode(ty, data, params);
274
- }
275
-
276
- function subgraphAbiEncodeCall(name, inputs, args) {
277
- return getAddon().subgraphAbiEncodeCall(name, inputs, args);
278
- }
279
-
280
- function subgraphBundledCodegen(manifestFile, outputDir) {
281
- let addon = getAddon();
282
- return addon.subgraphBundledCodegen(manifestFile, Stdlib_Null.fromOption(outputDir));
283
- }
284
-
285
- function subgraphBundledCodegenCurrent(manifestFile, outputDir) {
286
- return getAddon().subgraphBundledCodegenCurrent(manifestFile, outputDir);
287
- }
288
-
289
- function subgraphMissingGraphCliMessage(generated) {
290
- return getAddon().subgraphMissingGraphCliMessage(generated);
291
- }
292
-
293
- function subgraphFillGenerated(root, manifestFile, outputDir, wanted) {
294
- return getAddon().subgraphFillGenerated(root, manifestFile, outputDir, wanted);
295
- }
296
-
297
- function subgraphWorkspacePackages(root) {
298
- return getAddon().subgraphWorkspacePackages(root);
299
- }
300
-
301
- function subgraphWorkspaceRoot(root) {
302
- return getAddon().subgraphWorkspaceRoot(root);
303
- }
304
-
305
- function subgraphScriptsWriting(dir, needle) {
306
- return getAddon().subgraphScriptsWriting(dir, needle);
307
- }
308
-
309
235
  function runCli(args) {
310
236
  let addon = getAddon();
311
237
  return addon.runCli(args, envioPackageDir);
@@ -325,23 +251,8 @@ export {
325
251
  loadAddon,
326
252
  addonRef,
327
253
  getAddon,
328
- portsServedHere,
329
254
  getConfigJson,
330
255
  fromUserApi,
331
- fromSubgraph,
332
- subgraphFileToJavascript,
333
- subgraphRegisterHandlers,
334
- subgraphSureCreates,
335
- subgraphKeccak256,
336
- subgraphAbiDecode,
337
- subgraphAbiEncodeCall,
338
- subgraphBundledCodegen,
339
- subgraphBundledCodegenCurrent,
340
- subgraphMissingGraphCliMessage,
341
- subgraphFillGenerated,
342
- subgraphWorkspacePackages,
343
- subgraphWorkspaceRoot,
344
- subgraphScriptsWriting,
345
256
  runCli,
346
257
  }
347
258
  /* envioPackageDir Not a pure module */
@@ -24,17 +24,11 @@ type t = {
24
24
  mutable holdRealtime: bool,
25
25
  }
26
26
 
27
- // The whole-indexer fetch buffer pool, independent of chain count. A subgraph
28
- // run keeps far more per fetched event than a handler run does: the payload
29
- // with its transaction and block fields, a register pass with its pending
30
- // contract calls, and (for a chain kept open by a template) responses well past
31
- // the block the handlers are at. Venus on BSC held 100k of them and its heap
32
- // passed 4 GB, so the default there is a tenth of that.
33
- let defaultSubgraphTargetBufferSize = 10_000
27
+ // The whole-indexer fetch buffer pool, independent of chain count.
34
28
  let calculateTargetBufferSize = () =>
35
29
  switch Env.targetBufferSize {
36
30
  | Some(size) => size
37
- | None => Env.subgraphMode.contents ? defaultSubgraphTargetBufferSize : 100_000
31
+ | None => 100_000
38
32
  }
39
33
 
40
34
  let make = (
@@ -15,15 +15,15 @@ import * as SafeCheckpointTracking from "./SafeCheckpointTracking.res.mjs";
15
15
  function calculateTargetBufferSize() {
16
16
  if (Env.targetBufferSize !== undefined) {
17
17
  return Env.targetBufferSize;
18
- } else if (Env.subgraphMode.contents) {
19
- return 10000;
20
18
  } else {
21
19
  return 100000;
22
20
  }
23
21
  }
24
22
 
25
23
  function make(chainStates, isRealtime, targetBufferSizeOpt, holdRealtimeOpt) {
26
- let targetBufferSize = targetBufferSizeOpt !== undefined ? targetBufferSizeOpt : calculateTargetBufferSize();
24
+ let targetBufferSize = targetBufferSizeOpt !== undefined ? targetBufferSizeOpt : (
25
+ Env.targetBufferSize !== undefined ? Env.targetBufferSize : 100000
26
+ );
27
27
  let holdRealtime = holdRealtimeOpt !== undefined ? holdRealtimeOpt : false;
28
28
  return {
29
29
  chainStates: chainStates,
package/src/Ecosystem.res CHANGED
@@ -85,12 +85,6 @@ let loggerForItem = (item: Internal.item, ~ecosystem: t, ~logger: Logger.t): Log
85
85
  )
86
86
  }
87
87
 
88
- let makeKeyOnlyBlock = (~blockNumber: int, ~ecosystem: t): Internal.eventBlock => {
89
- let keyOnly = Dict.make()
90
- keyOnly->Dict.set(ecosystem.blockNumberName, blockNumber->(Utils.magic: int => unknown))
91
- keyOnly->(Utils.magic: dict<unknown> => Internal.eventBlock)
92
- }
93
-
94
88
  // `block` is the item's materialised selection, which already carries the key;
95
89
  // without one the handler selected nothing but the key.
96
90
  let makeOnBlockArgs = (
@@ -104,7 +98,10 @@ let makeOnBlockArgs = (
104
98
  | Evm | Fuel =>
105
99
  let block = switch block {
106
100
  | Some(block) => block
107
- | None => makeKeyOnlyBlock(~blockNumber, ~ecosystem)
101
+ | None =>
102
+ let keyOnly = Dict.make()
103
+ keyOnly->Dict.set(ecosystem.blockNumberName, blockNumber->(Utils.magic: int => unknown))
104
+ keyOnly->(Utils.magic: dict<unknown> => Internal.eventBlock)
108
105
  }
109
106
  {block, context}
110
107
  }
@@ -23,12 +23,6 @@ function loggerForItem(item, ecosystem, logger) {
23
23
  }
24
24
  }
25
25
 
26
- function makeKeyOnlyBlock(blockNumber, ecosystem) {
27
- let keyOnly = {};
28
- keyOnly[ecosystem.blockNumberName] = blockNumber;
29
- return keyOnly;
30
- }
31
-
32
26
  function makeOnBlockArgs(blockNumber, block, ecosystem, context) {
33
27
  let match = ecosystem.name;
34
28
  switch (match) {
@@ -42,7 +36,14 @@ function makeOnBlockArgs(blockNumber, block, ecosystem, context) {
42
36
  context: context
43
37
  };
44
38
  }
45
- let block$1 = block !== undefined ? Primitive_option.valFromOption(block) : makeKeyOnlyBlock(blockNumber, ecosystem);
39
+ let block$1;
40
+ if (block !== undefined) {
41
+ block$1 = Primitive_option.valFromOption(block);
42
+ } else {
43
+ let keyOnly = {};
44
+ keyOnly[ecosystem.blockNumberName] = blockNumber;
45
+ block$1 = keyOnly;
46
+ }
46
47
  return {
47
48
  block: Primitive_option.some(block$1),
48
49
  context: context
@@ -52,7 +53,6 @@ function makeOnBlockArgs(blockNumber, block, ecosystem, context) {
52
53
  export {
53
54
  getItemEvent,
54
55
  loggerForItem,
55
- makeKeyOnlyBlock,
56
56
  makeOnBlockArgs,
57
57
  }
58
58
  /* Logger Not a pure module */