envio 3.15.0 → 3.16.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 (186) hide show
  1. package/README.md +40 -34
  2. package/evm.schema.json +11 -2
  3. package/fuel.schema.json +10 -1
  4. package/index.d.ts +6 -0
  5. package/licenses/README.md +1 -1
  6. package/package.json +10 -9
  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 +7 -0
  11. package/src/Bin.res.mjs +8 -0
  12. package/src/ChainFetching.res +450 -16
  13. package/src/ChainFetching.res.mjs +403 -32
  14. package/src/ChainState.res +124 -7
  15. package/src/ChainState.res.mjs +128 -67
  16. package/src/ChainState.resi +26 -0
  17. package/src/Clock.res +57 -0
  18. package/src/Clock.res.mjs +72 -0
  19. package/src/Config.res +31 -3
  20. package/src/Config.res.mjs +15 -4
  21. package/src/ContractRegisterContext.res +3 -6
  22. package/src/ContractRegisterContext.res.mjs +4 -2
  23. package/src/Core.res +95 -36
  24. package/src/Core.res.mjs +90 -1
  25. package/src/CrossChainState.res +12 -2
  26. package/src/CrossChainState.res.mjs +3 -3
  27. package/src/Ecosystem.res +7 -4
  28. package/src/Ecosystem.res.mjs +8 -8
  29. package/src/EffectCacheLookup.res +98 -0
  30. package/src/EffectCacheLookup.res.mjs +116 -0
  31. package/src/EffectState.res +10 -2
  32. package/src/EffectState.res.mjs +8 -4
  33. package/src/EffectState.resi +3 -1
  34. package/src/EntityId.res +2 -7
  35. package/src/EntityId.res.mjs +1 -8
  36. package/src/EntityTables.res +4 -1
  37. package/src/EntityTables.res.mjs +1 -1
  38. package/src/Env.res +20 -0
  39. package/src/Env.res.mjs +16 -0
  40. package/src/EventProcessing.res +38 -1
  41. package/src/EventProcessing.res.mjs +28 -1
  42. package/src/FetchState.res +408 -73
  43. package/src/FetchState.res.mjs +361 -91
  44. package/src/FinalizeBackfill.res +2 -4
  45. package/src/FinalizeBackfill.res.mjs +3 -4
  46. package/src/HandlerLoader.res +39 -15
  47. package/src/HandlerLoader.res.mjs +27 -8
  48. package/src/HandlerRegister.res +4 -0
  49. package/src/HandlerRegister.res.mjs +5 -2
  50. package/src/HandlerRegister.resi +2 -0
  51. package/src/InMemoryTable.res +17 -16
  52. package/src/InMemoryTable.res.mjs +14 -15
  53. package/src/IndexerState.res +28 -4
  54. package/src/IndexerState.res.mjs +19 -6
  55. package/src/IndexerState.resi +4 -0
  56. package/src/Internal.res +61 -49
  57. package/src/Internal.res.mjs +36 -80
  58. package/src/LoadLayer.res +54 -15
  59. package/src/LoadLayer.res.mjs +75 -45
  60. package/src/LoadLayer.resi +26 -0
  61. package/src/Main.res +14 -1
  62. package/src/Main.res.mjs +4 -3
  63. package/src/Persistence.res +3 -23
  64. package/src/Persistence.res.mjs +3 -3
  65. package/src/PreloadLookahead.res +202 -0
  66. package/src/PreloadLookahead.res.mjs +218 -0
  67. package/src/Rollback.res +0 -1
  68. package/src/Rollback.res.mjs +1 -1
  69. package/src/RunScope.res +3 -0
  70. package/src/SafeCheckpointTracking.res +4 -4
  71. package/src/SafeCheckpointTracking.res.mjs +1 -1
  72. package/src/SimulateItems.res +42 -26
  73. package/src/SimulateItems.res.mjs +40 -16
  74. package/src/StagedRows.res +106 -0
  75. package/src/StagedRows.res.mjs +102 -0
  76. package/src/Staging.res +32 -14
  77. package/src/Staging.res.mjs +17 -20
  78. package/src/Storage.res +303 -948
  79. package/src/Storage.res.mjs +229 -708
  80. package/src/SubgraphLog.res +19 -0
  81. package/src/SubgraphLog.res.mjs +26 -0
  82. package/src/Supervisor.res +75 -56
  83. package/src/Supervisor.res.mjs +55 -26
  84. package/src/SyncWrites.res +107 -0
  85. package/src/SyncWrites.res.mjs +98 -0
  86. package/src/TestIndexer.res +22 -27
  87. package/src/TestIndexer.res.mjs +20 -17
  88. package/src/Throttler.res +15 -8
  89. package/src/Throttler.res.mjs +9 -6
  90. package/src/Throttler.resi +1 -1
  91. package/src/UserContext.res +419 -46
  92. package/src/UserContext.res.mjs +318 -30
  93. package/src/Utils.res +17 -6
  94. package/src/Utils.res.mjs +12 -6
  95. package/src/Writing.res +0 -1
  96. package/src/Writing.res.mjs +1 -1
  97. package/src/bindings/ClickHouse.res +0 -322
  98. package/src/bindings/ClickHouse.res.mjs +0 -338
  99. package/src/bindings/StorageClient.res +108 -174
  100. package/src/bindings/StorageClient.res.mjs +19 -8
  101. package/src/bindings/Vitest.res +0 -26
  102. package/src/bindings/Vitest.res.mjs +0 -3
  103. package/src/db/Table.res +24 -150
  104. package/src/db/Table.res.mjs +38 -272
  105. package/src/sources/AddressSet.res +2 -0
  106. package/src/sources/AddressStore.res +3 -0
  107. package/src/sources/CallSource.res +274 -0
  108. package/src/sources/CallSource.res.mjs +196 -0
  109. package/src/sources/ChainSources.res +2 -0
  110. package/src/sources/ChainSources.res.mjs +2 -2
  111. package/src/sources/EvmChain.res +10 -1
  112. package/src/sources/EvmChain.res.mjs +6 -3
  113. package/src/sources/EvmHyperSyncSource.res +2 -2
  114. package/src/sources/EvmHyperSyncSource.res.mjs +1 -1
  115. package/src/sources/EvmRpcClient.res +13 -3
  116. package/src/sources/EvmRpcClient.res.mjs +4 -3
  117. package/src/sources/EvmRpcWs.res +4 -3
  118. package/src/sources/EvmRpcWs.res.mjs +2 -2
  119. package/src/sources/HeightFeed.res +31 -10
  120. package/src/sources/HeightFeed.res.mjs +10 -6
  121. package/src/sources/HeightStream.res +32 -17
  122. package/src/sources/HeightStream.res.mjs +10 -10
  123. package/src/sources/HyperSync.res +2 -1
  124. package/src/sources/HyperSync.res.mjs +2 -1
  125. package/src/sources/HyperSyncSSE.res +4 -6
  126. package/src/sources/HyperSyncSSE.res.mjs +2 -2
  127. package/src/sources/RpcSource.res +10 -1
  128. package/src/sources/RpcSource.res.mjs +4 -3
  129. package/src/sources/Source.res +3 -0
  130. package/src/sources/SourceManager.res +84 -77
  131. package/src/sources/SourceManager.res.mjs +17 -20
  132. package/src/sources/SourceManager.resi +3 -4
  133. package/src/sources/StartBlockResolver.res +1 -0
  134. package/src/sources/StartBlockResolver.res.mjs +3 -2
  135. package/src/sources/SvmHyperSyncSource.res +2 -2
  136. package/src/sources/SvmHyperSyncSource.res.mjs +1 -1
  137. package/src/subgraph/abi-types.ts +84 -0
  138. package/src/subgraph/aggregations.ts +745 -0
  139. package/src/subgraph/as-package.ts +143 -0
  140. package/src/subgraph/assemblyscript-regex.ts +67 -0
  141. package/src/subgraph/assemblyscript.ts +731 -0
  142. package/src/subgraph/blocks.ts +398 -0
  143. package/src/subgraph/calls-source.ts +702 -0
  144. package/src/subgraph/calls.ts +258 -0
  145. package/src/subgraph/conformance.ts +106 -0
  146. package/src/subgraph/errors.ts +85 -0
  147. package/src/subgraph/graft.ts +73 -0
  148. package/src/subgraph/graph-cli-worker.mjs +35 -0
  149. package/src/subgraph/graph-cli.ts +900 -0
  150. package/src/subgraph/graph-node-decimal.ts +199 -0
  151. package/src/subgraph/graph-ts-enums.ts +28 -0
  152. package/src/subgraph/graph-ts-types/VERSION +2 -0
  153. package/src/subgraph/graph-ts-types/chain/arweave.d.ts +70 -0
  154. package/src/subgraph/graph-ts-types/chain/cosmos.d.ts +327 -0
  155. package/src/subgraph/graph-ts-types/chain/ethereum.d.ts +233 -0
  156. package/src/subgraph/graph-ts-types/chain/near.d.ts +253 -0
  157. package/src/subgraph/graph-ts-types/chain/starknet.d.ts +32 -0
  158. package/src/subgraph/graph-ts-types/common/collections.d.ts +136 -0
  159. package/src/subgraph/graph-ts-types/common/conversion.d.ts +11 -0
  160. package/src/subgraph/graph-ts-types/common/datasource.d.ts +30 -0
  161. package/src/subgraph/graph-ts-types/common/eager-offset.d.ts +0 -0
  162. package/src/subgraph/graph-ts-types/common/json.d.ts +17 -0
  163. package/src/subgraph/graph-ts-types/common/numbers.d.ts +120 -0
  164. package/src/subgraph/graph-ts-types/common/value.d.ts +120 -0
  165. package/src/subgraph/graph-ts-types/common/yaml.d.ts +90 -0
  166. package/src/subgraph/graph-ts-types/global/global.d.ts +194 -0
  167. package/src/subgraph/graph-ts-types/helper-functions.d.ts +22 -0
  168. package/src/subgraph/graph-ts-types/index.d.ts +102 -0
  169. package/src/subgraph/graph-ts.ts +4339 -0
  170. package/src/subgraph/hosts.ts +554 -0
  171. package/src/subgraph/log.ts +28 -0
  172. package/src/subgraph/receipts.ts +184 -0
  173. package/src/subgraph/register-slots.ts +93 -0
  174. package/src/subgraph/rollup.ts +109 -0
  175. package/src/subgraph/rpc.ts +337 -0
  176. package/src/subgraph/runtime.ts +2059 -0
  177. package/src/subgraph/scope.ts +176 -0
  178. package/src/subgraph/stats.ts +42 -0
  179. package/src/subgraph/template-instances.ts +66 -0
  180. package/src/subgraph/toolchain.ts +327 -0
  181. package/src/subgraph/transient.ts +176 -0
  182. package/svm.schema.json +11 -2
  183. package/src/PgWriting.res +0 -36
  184. package/src/PgWriting.res.mjs +0 -34
  185. package/src/db/IndexDefinition.res +0 -47
  186. package/src/db/IndexDefinition.res.mjs +0 -67
@@ -1,8 +1,8 @@
1
1
  // Rows cross in arenas both ways. A write stages its rows into memory the addon
2
- // lends (`beginStage` to `commitStage`); a read lands its rows in a Rust-owned
3
- // arena that `lendResult` hands over and `releaseResult` takes back. Reading or
4
- // writing through a buffer after it has been handed back is what detaching
5
- // prevents — the rules are the ones at the top of
2
+ // lends (`beginChanges`/`beginRows` to `commitStage`); a read lands its rows in
3
+ // a Rust-owned arena that `lendResult` hands over and `releaseResult` takes
4
+ // back. Reading or writing through a buffer after it has been handed back is
5
+ // what detaching prevents — the rules are the ones at the top of
6
6
  // `packages/cli/src/columnar/mod.rs`.
7
7
 
8
8
  type t
@@ -19,6 +19,9 @@ type postgresOptions = {
19
19
  applicationName: string,
20
20
  pgSchema: string,
21
21
  isHasuraEnabled: bool,
22
+ // An `envio start --chain` process: builds and looks for a per-chain
23
+ // entity's indexes on its own chains' partitions only.
24
+ isolated: bool,
22
25
  }
23
26
 
24
27
  type clickHouseOptions = {
@@ -31,7 +34,6 @@ type clickHouseOptions = {
31
34
  }
32
35
 
33
36
  type options = {
34
- chainIdMode: string,
35
37
  postgres: postgresOptions,
36
38
  clickhouse?: clickHouseOptions,
37
39
  }
@@ -45,71 +47,31 @@ type queryResult = {
45
47
  rows: int,
46
48
  }
47
49
 
48
- // A ClickHouse column. The rows read back are keyed by `rowName`, the name the
49
- // read schemas parse every store's rows by.
50
- type clickHouseColumn = {
51
- name: string,
52
- rowName?: string,
53
- // The schema field, which `@storage(clickhouse: {...})` expressions name a
54
- // column by even when a rename is configured.
55
- fieldName?: string,
56
- fieldType: string,
57
- isNullable: bool,
58
- isArray: bool,
59
- precision?: int,
60
- scale?: int,
61
- enumVariants?: array<string>,
62
- }
63
-
64
- type skippingIndex = {
65
- name: string,
66
- expr: string,
67
- indexType: string,
68
- granularity?: int,
69
- }
50
+ type store = Postgres | ClickHouse
70
51
 
71
- type clickHouseTable = {
72
- name: string,
73
- historyTable: string,
74
- columns: array<clickHouseColumn>,
75
- chainIdColumn?: string,
76
- partitionBy?: string,
77
- orderBy?: array<string>,
78
- ttl?: string,
79
- skippingIndexes?: array<skippingIndex>,
80
- }
52
+ type stagedField = Staging.stagedField
81
53
 
82
- // A table described for every store that keeps it: an entity for each store its
83
- // schema names, the indexer's own tables for Postgres alone.
84
- type tableInput = {
54
+ type entityLayout = {
85
55
  name: string,
86
- postgres?: Core.pgTableInput,
87
- clickhouse?: clickHouseTable,
56
+ // The store the entity is read from; none when no configured store keeps it.
57
+ home?: store,
58
+ fields: array<stagedField>,
88
59
  }
89
60
 
90
- type postgresRegistered = {kinds?: array<int>}
91
-
92
- type clickHouseRegistered = {
93
- names: array<string>,
94
- kinds: array<int>,
95
- nullable: array<bool>,
61
+ // How every batch is laid out: an entity's change set is its fields, then each
62
+ // change's checkpoint and whether it deletes.
63
+ type layouts = {
64
+ // By entity index.
65
+ entities: array<entityLayout>,
66
+ rawEvents: array<stagedField>,
67
+ effectCache: array<stagedField>,
96
68
  }
97
69
 
98
- type store = Postgres | ClickHouse
99
-
100
- // What each store made of a table: present for the stores that keep it.
101
- type registeredTable = {
102
- handle: int,
103
- // The store the table is read from.
104
- home: store,
105
- postgres?: postgresRegistered,
106
- clickhouse?: clickHouseRegistered,
107
- }
70
+ type stagedTable = RawEvents | EffectCache
108
71
 
109
72
  type bounds = {
110
- sequence: CheckpointSequence.t,
111
73
  chainIds: array<ChainId.t>,
112
- checkpointIds: array<string>,
74
+ checkpointIds: array<bigint>,
113
75
  }
114
76
 
115
77
  type progress = {
@@ -146,35 +108,19 @@ type chainConfig = {
146
108
  maxReorgDepth: int,
147
109
  }
148
110
 
149
- type partition = {table: int, chainId: ChainId.t, name: string}
150
-
151
- type enum = {name: string, variants: array<string>}
152
-
153
111
  type initialize = {
154
- sequence: CheckpointSequence.t,
155
- tables: array<int>,
156
- partitions: array<partition>,
157
- enums: array<enum>,
158
112
  chains: array<chainConfig>,
159
113
  envioInfo: string,
160
114
  contractNames: array<string>,
161
115
  addresses: addresses,
116
+ keptEffectCaches?: array<string>,
162
117
  }
163
118
 
164
119
  type addChain = {
165
120
  chain: chainConfig,
166
- partitions: array<partition>,
167
121
  addresses: addresses,
168
122
  }
169
123
 
170
- type resume = {
171
- sequence: CheckpointSequence.t,
172
- // Every entity table.
173
- tables: array<int>,
174
- // The chains this run drives, which are the only ones trimmed.
175
- chainIds: array<ChainId.t>,
176
- }
177
-
178
124
  type storedChain = {
179
125
  id: float,
180
126
  ecosystem: string,
@@ -203,11 +149,11 @@ type resumedChain = {
203
149
  // Unix seconds.
204
150
  progressBlockTime?: float,
205
151
  sourceBlock: int,
206
- checkpointId: string,
152
+ checkpointId: bigint,
207
153
  }
208
154
 
209
155
  type reorgCheckpoint = {
210
- id: string,
156
+ id: bigint,
211
157
  chainId: float,
212
158
  blockNumber: int,
213
159
  blockHash: string,
@@ -227,57 +173,40 @@ type progressDiff = {
227
173
 
228
174
  type rollbackData = {removed: queryResult, restored: queryResult}
229
175
 
230
- type cacheTable = {tableName: string, rows: int}
231
-
232
- // An optional field is left out rather than null, both ways: the addon refuses
233
- // a null for one, and leaves out one it has no value for.
234
-
235
- // Rows of a batch: staged into an arena, or one rendered parameter per cell,
236
- // every row's first column first.
237
- type rows = {
238
- staged?: int,
239
- cells?: array<Null.t<string>>,
176
+ // `chainId` is left out for a cross-chain cache.
177
+ type storedEffectCache = {
178
+ effectName: string,
179
+ chainId?: ChainId.t,
180
+ tableName: string,
240
181
  rows: int,
241
182
  }
242
183
 
243
- type historyWrite = {
244
- backfill: array<string>,
245
- sets?: rows,
246
- setCheckpointIds: array<string>,
247
- deleteIds: array<string>,
248
- deleteCheckpointIds: array<string>,
249
- }
250
-
251
- type postgresEntityWrite = {
252
- sets?: rows,
253
- deletes: array<string>,
254
- history?: historyWrite,
255
- }
184
+ // An optional field is left out rather than null, both ways: the addon refuses
185
+ // a null for one, and leaves out one it has no value for.
256
186
 
257
- type entityWrite = {
258
- table: int,
187
+ // One entity's changes within one chain scope, staged.
188
+ type changes = {
189
+ entity: int,
259
190
  chainId?: ChainId.t,
260
- postgres?: postgresEntityWrite,
261
- // Every change as a history row, staged.
262
- clickhouse?: int,
191
+ keepsHistory: bool,
192
+ changes: int,
263
193
  }
264
194
 
265
195
  type diffCheckpoint = {
266
196
  chainId: ChainId.t,
267
- checkpointId: string,
197
+ checkpointId: bigint,
268
198
  blockNumber: int,
269
199
  }
270
200
 
271
201
  type rollbackWrite = {
272
202
  bounds: bounds,
273
- tables: array<int>,
274
203
  progress: array<progress>,
275
204
  removedAddresses: addresses,
276
205
  diffCheckpoints: array<diffCheckpoint>,
277
206
  }
278
207
 
279
208
  type checkpoints = {
280
- ids: array<string>,
209
+ ids: array<bigint>,
281
210
  chainIds: array<ChainId.t>,
282
211
  blockNumbers: array<int>,
283
212
  blockHashes: array<Null.t<string>>,
@@ -285,17 +214,15 @@ type checkpoints = {
285
214
  keepsHistory: array<bool>,
286
215
  }
287
216
 
288
- type frontier = {chainIds: array<ChainId.t>, checkpointIds: array<string>}
289
-
290
- type tableWrite = {table: int, rows: rows}
217
+ type frontier = {chainIds: array<ChainId.t>, checkpointIds: array<bigint>}
291
218
 
292
- type effectCacheWrite = {table: int, create: bool, rows: rows}
219
+ type effectCacheWrite = {table: string, create: bool, rows: int}
293
220
 
294
221
  type batch = {
295
222
  rollback?: rollbackWrite,
296
223
  progress: array<progress>,
297
- rawEvents?: tableWrite,
298
- entities: array<entityWrite>,
224
+ rawEvents?: int,
225
+ changes: array<changes>,
299
226
  chainMeta: array<chainMeta>,
300
227
  addresses: addresses,
301
228
  frontier: frontier,
@@ -305,37 +232,31 @@ type batch = {
305
232
 
306
233
  type writeTiming = {store: store, seconds: float}
307
234
 
308
- // What a build was for, which decides how much an existing index has to match.
309
- type indexPurpose = | @as("Query") Query | @as("Schema") Schema
310
-
311
- @tag("kind")
312
- type indexEvent =
313
- | Invalid({names: array<string>})
314
- | Planned({declared: int, missing: array<string>, rebuilt: array<string>})
315
- | Building({purpose: indexPurpose, name: string, tableName: string, isRebuild: bool})
316
- | Built({purpose: indexPurpose, name: string, seconds: float})
317
- | Failed({
318
- purpose: indexPurpose,
319
- name: string,
320
- tableName: string,
321
- columns: array<string>,
322
- error: string,
323
- code?: string,
324
- })
325
- | ResyncFailed({name: string, error: string, code?: string})
326
- | Committed({count: int, seconds: float})
327
-
328
- @send
329
- external classCreate: (Core.storageCtor, options, indexEvent => unit, string => unit) => t =
330
- "create"
331
-
332
- let make = (options, ~onIndexEvent, ~onWarning) =>
333
- Core.getAddon().storage->classCreate(options, onIndexEvent, onWarning)
334
-
335
- @send external registerTable: (t, tableInput) => registeredTable = "registerTable"
336
-
337
235
  @send
338
- external beginStage: (t, ~table: int, ~store: store, ~rows: int) => Staging.begun = "beginStage"
236
+ external classCreate: (
237
+ Core.storageCtor,
238
+ options,
239
+ Null.t<string>,
240
+ Logger.native,
241
+ array<string>,
242
+ ) => t = "create"
243
+
244
+ // The storage of the entities `configJson` declares — the config the CLI
245
+ // wrote — or of none. The addon logs through `logger` itself, with the fields
246
+ // bound to it.
247
+ let make = (options, ~configJson=?, ~logger: Logger.t) =>
248
+ Core.getAddon().storage->classCreate(
249
+ options,
250
+ configJson->Null.fromOption,
251
+ logger.output.native,
252
+ logger.boundFieldsJson,
253
+ )
254
+
255
+ @send external layouts: t => layouts = "layouts"
256
+
257
+ @send external beginChanges: (t, ~entity: int, ~rows: int) => Staging.begun = "beginChanges"
258
+
259
+ @send external beginRows: (t, ~table: stagedTable, ~rows: int) => Staging.begun = "beginRows"
339
260
 
340
261
  @send
341
262
  external growStage: (
@@ -353,8 +274,8 @@ external commitStage: (t, ~handle: int, ~buffers: array<ArrayBuffer.t>) => unit
353
274
 
354
275
  @send external discardStaged: (t, array<int>) => unit = "discardStaged"
355
276
 
356
- let arena = (client, ~store): Staging.arena => {
357
- beginStage: (~table, ~rows) => client->beginStage(~table, ~store, ~rows),
277
+ let arena = (client, begin): Staging.arena => {
278
+ beginStage: (~rows) => begin(~rows),
358
279
  growStage: (~handle, ~column, ~needed, ~stale) =>
359
280
  client->growStage(~handle, ~column, ~needed, ~stale),
360
281
  commitStage: (~handle, ~buffers) => client->commitStage(~handle, ~buffers),
@@ -391,13 +312,26 @@ let queryForTests = async (client, sql, ~params=[]) =>
391
312
  @send
392
313
  external loadWhereRaw: (t, int, array<LoadCondition.t>) => promise<queryResult> = "loadWhere"
393
314
 
394
- let loadWhere = async (client, ~table, ~conditions) =>
395
- client->read(await client->loadWhereRaw(table, conditions))
315
+ let loadWhere = async (client, ~entity, ~conditions) =>
316
+ client->read(await client->loadWhereRaw(entity, conditions))
317
+
318
+ @send
319
+ external loadEffectCacheRaw: (t, string, array<LoadCondition.t>) => promise<queryResult> =
320
+ "loadEffectCache"
321
+
322
+ let loadEffectCache = async (client, ~table, ~conditions) =>
323
+ client->read(await client->loadEffectCacheRaw(table, conditions))
324
+
325
+ @send
326
+ external clickHouseRowsForTestsRaw: (t, int) => promise<queryResult> = "clickhouseRowsForTests"
327
+
328
+ let clickHouseRowsForTests = async (client, ~entity) =>
329
+ client->read(await client->clickHouseRowsForTestsRaw(entity))
396
330
 
397
331
  @send external historyForTestsRaw: (t, int) => promise<queryResult> = "historyForTests"
398
332
 
399
- let historyForTests = async (client, ~table) =>
400
- client->read(await client->historyForTestsRaw(table))
333
+ let historyForTests = async (client, ~entity) =>
334
+ client->read(await client->historyForTestsRaw(entity))
401
335
 
402
336
  // What the storage holds before anything is initialized or resumed.
403
337
  type holding =
@@ -419,49 +353,49 @@ type holding =
419
353
 
420
354
  @send external readStoredConfig: t => promise<storedConfig> = "readStoredConfig"
421
355
 
422
- @send external resume: (t, resume) => promise<resumed> = "resume"
356
+ // Resumes the chains this run drives, the only ones ClickHouse trims.
357
+ @send external resume: (t, array<ChainId.t>) => promise<resumed> = "resume"
423
358
 
424
359
  @send external setChainMeta: (t, array<chainMeta>) => promise<unit> = "setChainMeta"
425
360
 
361
+ // Builds every index the schema promises for the chains, then stamps them
362
+ // ready at the given unix milliseconds.
426
363
  @send
427
- external finalizeBackfill: (t, array<Core.pgIndexInput>, array<ChainId.t>, float) => promise<unit> =
428
- "finalizeBackfill"
364
+ external finalizeBackfill: (t, array<ChainId.t>, float) => promise<unit> = "finalizeBackfill"
429
365
 
430
- @send
431
- external ensureSchemaIndexes: (t, array<Core.pgIndexInput>) => promise<unit> = "ensureSchemaIndexes"
366
+ @send external ensureSchemaIndexes: (t, array<ChainId.t>) => promise<unit> = "ensureSchemaIndexes"
432
367
 
433
368
  // Null when the indexes are already there, which is every call but the first,
434
- // and every call for a table no store builds query indexes for.
369
+ // and every call for an entity Postgres doesn't keep.
435
370
  @send
436
- external ensureQueryIndexes: (t, int, string, array<string>) => Null.t<promise<unit>> =
437
- "ensureQueryIndexes"
371
+ external ensureQueryIndexes: (
372
+ t,
373
+ ~entity: int,
374
+ ~chainId: Null.t<ChainId.t>,
375
+ ~columns: array<string>,
376
+ ) => Null.t<promise<unit>> = "ensureQueryIndexes"
438
377
 
439
378
  @send external pruneCheckpoints: (t, bounds) => promise<unit> = "pruneCheckpoints"
440
379
 
441
380
  @send external pruneHistory: (t, int, bounds) => promise<unit> = "pruneHistory"
442
381
 
443
382
  @send
444
- external rollbackTargetCheckpoint: (
445
- t,
446
- ChainId.t,
447
- int,
448
- CheckpointSequence.t,
449
- ) => promise<Nullable.t<string>> = "rollbackTargetCheckpoint"
383
+ external rollbackTargetCheckpoint: (t, ChainId.t, int) => promise<Nullable.t<bigint>> =
384
+ "rollbackTargetCheckpoint"
450
385
 
451
386
  @send
452
387
  external rollbackProgressDiff: (t, bounds) => promise<array<progressDiff>> = "rollbackProgressDiff"
453
388
 
454
389
  @send external rollbackData: (t, int, bounds) => promise<rollbackData> = "rollbackData"
455
390
 
456
- @send external effectCacheTables: t => promise<array<cacheTable>> = "effectCacheTables"
457
-
458
- type cacheUpload = {table: int, path: string}
459
-
460
- @send external uploadEffectCache: (t, array<cacheUpload>) => promise<unit> = "uploadEffectCache"
461
-
462
- type cacheDump = {tableName: string, path: string}
391
+ // Uploads the caches saved under the directory first when `upload` says to,
392
+ // logging how that went.
393
+ @send
394
+ external restoreEffectCache: (t, string, bool) => promise<array<storedEffectCache>> =
395
+ "restoreEffectCache"
463
396
 
464
- @send external dumpEffectCache: (t, array<cacheDump>) => promise<unit> = "dumpEffectCache"
397
+ // Never rejects: a dump that doesn't finish is logged.
398
+ @send external dumpEffectCache: (t, string) => promise<unit> = "dumpEffectCache"
465
399
 
466
400
  @send external reset: t => promise<unit> = "reset"
467
401
 
@@ -2,14 +2,15 @@
2
2
 
3
3
  import * as Core from "../Core.res.mjs";
4
4
  import * as Reading from "../Reading.res.mjs";
5
+ import * as Stdlib_Null from "@rescript/runtime/lib/es6/Stdlib_Null.js";
5
6
 
6
- function make(options, onIndexEvent, onWarning) {
7
- return Core.getAddon().Storage.create(options, onIndexEvent, onWarning);
7
+ function make(options, configJson, logger) {
8
+ return Core.getAddon().Storage.create(options, Stdlib_Null.fromOption(configJson), logger.output.native, logger.boundFieldsJson);
8
9
  }
9
10
 
10
- function arena(client, store) {
11
+ function arena(client, begin) {
11
12
  return {
12
- beginStage: (table, rows) => client.beginStage(table, store, rows),
13
+ beginStage: rows => begin(rows),
13
14
  growStage: (handle, column, needed, stale) => client.growStage(handle, column, needed, stale),
14
15
  commitStage: (handle, buffers) => {
15
16
  client.commitStage(handle, buffers);
@@ -39,12 +40,20 @@ async function queryForTests(client, sql, paramsOpt) {
39
40
  return read(client, await client.queryForTests(sql, params));
40
41
  }
41
42
 
42
- async function loadWhere(client, table, conditions) {
43
- return read(client, await client.loadWhere(table, conditions));
43
+ async function loadWhere(client, entity, conditions) {
44
+ return read(client, await client.loadWhere(entity, conditions));
44
45
  }
45
46
 
46
- async function historyForTests(client, table) {
47
- return read(client, await client.historyForTests(table));
47
+ async function loadEffectCache(client, table, conditions) {
48
+ return read(client, await client.loadEffectCache(table, conditions));
49
+ }
50
+
51
+ async function clickHouseRowsForTests(client, entity) {
52
+ return read(client, await client.clickhouseRowsForTests(entity));
53
+ }
54
+
55
+ async function historyForTests(client, entity) {
56
+ return read(client, await client.historyForTests(entity));
48
57
  }
49
58
 
50
59
  export {
@@ -53,6 +62,8 @@ export {
53
62
  read,
54
63
  queryForTests,
55
64
  loadWhere,
65
+ loadEffectCache,
66
+ clickHouseRowsForTests,
56
67
  historyForTests,
57
68
  }
58
69
  /* Core Not a pure module */
@@ -169,29 +169,3 @@ let messageOfThrown: (unit => 'a) => option<string> = %raw(`function (fn) {
169
169
  // happens to equal the placeholder.
170
170
  let toThrowErrorEqual = (t: testContext, fn: unit => 'a, ~message=?, expected: string) =>
171
171
  t.expect(fn->messageOfThrown, ~message?).toEqual(Some(expected))
172
-
173
- // ============================================================================
174
- // Fake timers
175
- // ============================================================================
176
-
177
- module Vi = {
178
- @module("vitest") @scope("vi")
179
- external useFakeTimers: unit => unit = "useFakeTimers"
180
-
181
- @module("vitest") @scope("vi")
182
- external useRealTimers: unit => unit = "useRealTimers"
183
-
184
- // Runs every timer that comes due within the window, awaiting the
185
- // microtasks each one queues before moving on.
186
- @module("vitest") @scope("vi")
187
- external advanceTimersByTimeAsync: int => promise<unit> = "advanceTimersByTimeAsync"
188
-
189
- @module("vitest") @scope("vi")
190
- external advanceTimersToNextTimerAsync: unit => promise<unit> = "advanceTimersToNextTimerAsync"
191
-
192
- @module("vitest") @scope("vi")
193
- external getTimerCount: unit => int = "getTimerCount"
194
-
195
- @module("vitest") @scope("vi")
196
- external clearAllTimers: unit => unit = "clearAllTimers"
197
- }
@@ -16,12 +16,9 @@ function toThrowErrorEqual(t, fn, message, expected) {
16
16
  t.expect(messageOfThrown(fn), message).toEqual(expected);
17
17
  }
18
18
 
19
- let Vi = {};
20
-
21
19
  export {
22
20
  Async,
23
21
  messageOfThrown,
24
22
  toThrowErrorEqual,
25
- Vi,
26
23
  }
27
24
  /* No side effect */