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
package/src/db/Table.res CHANGED
@@ -160,34 +160,6 @@ let fitPgTableName = (fullName, ~uniqueSuffix) =>
160
160
  fullName
161
161
  }
162
162
 
163
- // The variant's name and whichever of precision, scale and enum name it
164
- // carries. They travel to the addon separately because napi has no tagged
165
- // union of its own.
166
- let pgFieldTypeParts = (fieldType: fieldType) =>
167
- switch fieldType {
168
- | String => ("String", None, None, None)
169
- | Boolean => ("Boolean", None, None, None)
170
- | Uint32 => ("Uint32", None, None, None)
171
- | UInt52 => ("UInt52", None, None, None)
172
- | SmallInt => ("SmallInt", None, None, None)
173
- | Bytea => ("Bytea", None, None, None)
174
- | UInt64 => ("UInt64", None, None, None)
175
- | Int32 => ("Int32", None, None, None)
176
- | ChainId => ("ChainId", None, None, None)
177
- | Number => ("Number", None, None, None)
178
- | BigInt({?precision}) => ("BigInt", precision, None, None)
179
- | BigDecimal({?config}) =>
180
- switch config {
181
- | Some((precision, scale)) => ("BigDecimal", Some(precision), Some(scale), None)
182
- | None => ("BigDecimal", None, None, None)
183
- }
184
- | Serial => ("Serial", None, None, None)
185
- | BigSerial => ("BigSerial", None, None, None)
186
- | Json => ("Json", None, None, None)
187
- | Date => ("Date", None, None, None)
188
- | Enum({config}) => ("Enum", None, None, Some(config.name))
189
- }
190
-
191
163
  type indexFieldDirection = Asc | Desc
192
164
 
193
165
  type compositeIndexField = {
@@ -200,13 +172,37 @@ type table = {
200
172
  fields: array<fieldOrDerived>,
201
173
  compositeIndexes: array<array<compositeIndexField>>,
202
174
  description: option<string>,
175
+ // The string an id keys a dict or Set by, picked from the id column's type
176
+ // so a string id, the common case, is its own key.
177
+ entityIdToKey: EntityId.t => string,
203
178
  }
204
179
 
180
+ let stringEntityIdToKey = (Utils.magic: EntityId.t => string)
181
+ // Always a string, never the raw number: a Set tells 7 from "7".
182
+ let numericEntityIdToKey = (String.make: EntityId.t => string)
183
+ // Hex rather than `String`, which decodes a Buffer as UTF-8 and so collides
184
+ // distinct byte sequences.
185
+ let bytesEntityIdToKey =
186
+ Utils.Bytes.toHex->(Utils.magic: (Uint8Array.t => string) => EntityId.t => string)
187
+
188
+ let entityIdToKeyFor = (fields: array<fieldOrDerived>) =>
189
+ switch fields->Array.findMap(field =>
190
+ switch field {
191
+ | Field({fieldName, fieldType}) if fieldName === idFieldName => Some(fieldType)
192
+ | _ => None
193
+ }
194
+ ) {
195
+ | Some(Bytea) => bytesEntityIdToKey
196
+ | Some(String) | None => stringEntityIdToKey
197
+ | Some(_) => numericEntityIdToKey
198
+ }
199
+
205
200
  let mkTable = (tableName, ~compositeIndexes=[], ~fields, ~description=?) => {
206
201
  tableName,
207
202
  fields,
208
203
  compositeIndexes,
209
204
  description,
205
+ entityIdToKey: entityIdToKeyFor(fields),
210
206
  }
211
207
 
212
208
  let getFields = table =>
@@ -275,15 +271,6 @@ let getIdFieldOrThrow = (table): field =>
275
271
  let getIdSchema = (table): S.t<EntityId.t> =>
276
272
  (table->getIdFieldOrThrow).fieldSchema->(Utils.magic: S.t<unknown> => S.t<EntityId.t>)
277
273
 
278
- // Serializes an array of ids to the JSON form the SQL layer binds. The array
279
- // schema is memoized per table so its serializer compiles once, not on every
280
- // (high-frequency) delete/history write.
281
- let idsArraySchema: table => S.t<array<EntityId.t>> = Utils.WeakMap.memoize(table =>
282
- S.array(table->getIdSchema)
283
- )
284
- let encodeIdsToJson = (table, ids: array<EntityId.t>): JSON.t =>
285
- ids->S.reverseConvertToJsonOrThrow(table->idsArraySchema)
286
-
287
274
  // TODO: Test whether it should be passed via args and match the column type
288
275
 
289
276
  // Resolved once per table, because a getWhere looks up every field it filters
@@ -368,116 +355,3 @@ let pgEntityRowsSchema: table => S.t<array<unknown>> = Utils.WeakMap.memoize(tab
368
355
  )
369
356
 
370
357
  exception NonExistingTableField(string)
371
-
372
- /*
373
- Gets all composite indexes (whether they are single indexes or not)
374
- And maps the fields defined to their actual db name (some have _id suffix)
375
- */
376
- let getUnfilteredCompositeIndexesUnsafe = (table): array<array<compositeIndexField>> => {
377
- table.compositeIndexes->Array.map(compositeIndex =>
378
- compositeIndex->Array.map(indexField => {
379
- let dbFieldName = switch table->getFieldByName(indexField.fieldName) {
380
- | Some(field) => field->getPgFieldName
381
- | None => throw(NonExistingTableField(indexField.fieldName)) //Unexpected should be validated in schema parser
382
- }
383
- {fieldName: dbFieldName, direction: indexField.direction}
384
- })
385
- )
386
- }
387
-
388
- // The table's fields in the order the schema names them, which is the order an
389
- // insert names its columns and binds its values.
390
- //
391
- // A `@derivedFrom` field is not one of them: it is resolved from the other side
392
- // of the relationship rather than stored, so no row schema carries one and
393
- // there is no column for it to be.
394
- let schemaOrderedFields = (table: table, ~schema): array<field> =>
395
- switch schema->S.classify {
396
- | Object({items}) =>
397
- items->Array.map(({location}) =>
398
- switch table->getFieldByApiName(location) {
399
- | Some(Field(field)) => field
400
- | Some(DerivedFrom(_)) | None => throw(NonExistingTableField(location))
401
- }
402
- )
403
- | _ =>
404
- JsError.throwWithMessage(
405
- `Failed reading the columns of "${table.tableName}". Expected an object schema for a table.`,
406
- )
407
- }
408
-
409
- let toDbSchema = (table: table, ~schema): S.t<'entity> => {
410
- let dbSchema: S.t<dict<unknown>> = S.schema(s =>
411
- switch schema->S.classify {
412
- | Object({items}) =>
413
- let dict = Dict.make()
414
- items->Array.forEach(({location, schema}) => {
415
- let rec coerceSchema = schema =>
416
- switch schema->S.classify {
417
- | BigInt => Utils.BigInt.schema->S.toUnknown
418
- | Option(child)
419
- | Null(child) =>
420
- Utils.Schema.nullTolerant(child->coerceSchema)->S.toUnknown
421
- | Array(child) => S.array(child->coerceSchema)->S.toUnknown
422
- | Bool =>
423
- // Booleans travel as 1/0; the insert casts them back.
424
- S.union([
425
- S.literal(1)->S.shape(_ => true),
426
- S.literal(0)->S.shape(_ => false),
427
- ])->S.toUnknown
428
- | _ => schema
429
- }
430
-
431
- if table->getFieldByApiName(location)->Option.isNone {
432
- throw(NonExistingTableField(location))
433
- }
434
-
435
- dict->Dict.set(location, s.matches(schema->coerceSchema))
436
- })
437
- dict
438
- | _ =>
439
- JsError.throwWithMessage("Failed creating db schema. Expected an object schema for table")
440
- }
441
- )
442
-
443
- dbSchema->(Utils.magic: S.t<dict<unknown>> => S.t<'entity>)
444
- }
445
-
446
- /*
447
- Gets all single indexes
448
- And maps the fields defined to their actual db name (some have _id suffix)
449
- */
450
- let getSingleIndexes = (table): array<string> => {
451
- let indexFields = table.fields->Array.filterMap(field =>
452
- switch field {
453
- | Field(field) if field.isIndex => Some(field->getPgDbFieldName)
454
- | _ => None
455
- }
456
- )
457
-
458
- table
459
- ->getUnfilteredCompositeIndexesUnsafe
460
- //get all composite indexes with only 1 field defined
461
- //this is still a single index
462
- ->Array.filterMap(cidx =>
463
- switch cidx {
464
- | [{fieldName}] => Some([fieldName])
465
- | _ => None
466
- }
467
- )
468
- ->Array.concat([indexFields])
469
- ->Array.flat
470
- ->Set.fromArray
471
- ->Set.toArray
472
- ->Array.toSorted(String.compare)
473
- }
474
-
475
- /*
476
- Gets all composite indexes
477
- And maps the fields defined to their actual db name (some have _id suffix)
478
- */
479
- let getCompositeIndexes = (table): array<array<compositeIndexField>> => {
480
- table
481
- ->getUnfilteredCompositeIndexesUnsafe
482
- ->Array.filter(ind => ind->Array.length > 1)
483
- }
@@ -3,8 +3,6 @@
3
3
  import * as Utils from "../Utils.res.mjs";
4
4
  import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
5
5
  import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
6
- import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js";
7
- import * as Primitive_string from "@rescript/runtime/lib/es6/Primitive_string.js";
8
6
  import * as S$RescriptSchema from "rescript-schema/src/S.res.mjs";
9
7
  import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
10
8
 
@@ -106,142 +104,39 @@ function fitPgTableName(fullName, uniqueSuffix) {
106
104
  }
107
105
  }
108
106
 
109
- function pgFieldTypeParts(fieldType) {
110
- if (typeof fieldType !== "object") {
111
- switch (fieldType) {
112
- case "String" :
113
- return [
114
- "String",
115
- undefined,
116
- undefined,
117
- undefined
118
- ];
119
- case "Boolean" :
120
- return [
121
- "Boolean",
122
- undefined,
123
- undefined,
124
- undefined
125
- ];
126
- case "Uint32" :
127
- return [
128
- "Uint32",
129
- undefined,
130
- undefined,
131
- undefined
132
- ];
133
- case "UInt52" :
134
- return [
135
- "UInt52",
136
- undefined,
137
- undefined,
138
- undefined
139
- ];
140
- case "SmallInt" :
141
- return [
142
- "SmallInt",
143
- undefined,
144
- undefined,
145
- undefined
146
- ];
147
- case "Bytea" :
148
- return [
149
- "Bytea",
150
- undefined,
151
- undefined,
152
- undefined
153
- ];
154
- case "UInt64" :
155
- return [
156
- "UInt64",
157
- undefined,
158
- undefined,
159
- undefined
160
- ];
161
- case "Int32" :
162
- return [
163
- "Int32",
164
- undefined,
165
- undefined,
166
- undefined
167
- ];
168
- case "ChainId" :
169
- return [
170
- "ChainId",
171
- undefined,
172
- undefined,
173
- undefined
174
- ];
175
- case "Number" :
176
- return [
177
- "Number",
178
- undefined,
179
- undefined,
180
- undefined
181
- ];
182
- case "Serial" :
183
- return [
184
- "Serial",
185
- undefined,
186
- undefined,
187
- undefined
188
- ];
189
- case "BigSerial" :
190
- return [
191
- "BigSerial",
192
- undefined,
193
- undefined,
194
- undefined
195
- ];
196
- case "Json" :
197
- return [
198
- "Json",
199
- undefined,
200
- undefined,
201
- undefined
202
- ];
203
- case "Date" :
204
- return [
205
- "Date",
206
- undefined,
207
- undefined,
208
- undefined
209
- ];
107
+ function stringEntityIdToKey(prim) {
108
+ return prim;
109
+ }
110
+
111
+ function numericEntityIdToKey(prim) {
112
+ return String(prim);
113
+ }
114
+
115
+ let bytesEntityIdToKey = Utils.Bytes.toHex;
116
+
117
+ function entityIdToKeyFor(fields) {
118
+ let match = Stdlib_Array.findMap(fields, field => {
119
+ if (field.TAG !== "Field") {
120
+ return;
210
121
  }
211
- } else {
212
- switch (fieldType.type) {
213
- case "BigInt" :
214
- return [
215
- "BigInt",
216
- fieldType.precision,
217
- undefined,
218
- undefined
219
- ];
220
- case "BigDecimal" :
221
- let config = fieldType.config;
222
- if (config !== undefined) {
223
- return [
224
- "BigDecimal",
225
- config[0],
226
- config[1],
227
- undefined
228
- ];
229
- } else {
230
- return [
231
- "BigDecimal",
232
- undefined,
233
- undefined,
234
- undefined
235
- ];
236
- }
237
- case "Enum" :
238
- return [
239
- "Enum",
240
- undefined,
241
- undefined,
242
- fieldType.config.name
243
- ];
122
+ let match = field._0;
123
+ if (match.fieldName === idFieldName) {
124
+ return match.fieldType;
244
125
  }
126
+ });
127
+ if (match === undefined) {
128
+ return stringEntityIdToKey;
129
+ }
130
+ if (typeof match === "object") {
131
+ return numericEntityIdToKey;
132
+ }
133
+ switch (match) {
134
+ case "String" :
135
+ return stringEntityIdToKey;
136
+ case "Bytea" :
137
+ return bytesEntityIdToKey;
138
+ default:
139
+ return numericEntityIdToKey;
245
140
  }
246
141
  }
247
142
 
@@ -251,7 +146,8 @@ function mkTable(tableName, compositeIndexesOpt, fields, description) {
251
146
  tableName: tableName,
252
147
  fields: fields,
253
148
  compositeIndexes: compositeIndexes,
254
- description: description
149
+ description: description,
150
+ entityIdToKey: entityIdToKeyFor(fields)
255
151
  };
256
152
  }
257
153
 
@@ -346,12 +242,6 @@ function getIdSchema(table) {
346
242
  return getIdFieldOrThrow(table).fieldSchema;
347
243
  }
348
244
 
349
- let idsArraySchema = Utils.$$WeakMap.memoize(table => S$RescriptSchema.array(getIdFieldOrThrow(table).fieldSchema));
350
-
351
- function encodeIdsToJson(table, ids) {
352
- return S$RescriptSchema.reverseConvertToJsonOrThrow(ids, idsArraySchema(table));
353
- }
354
-
355
245
  let fieldsByApiName = Utils.$$WeakMap.memoize(table => {
356
246
  let byApiName = {};
357
247
  table.fields.forEach(field => {
@@ -408,126 +298,6 @@ let pgEntityRowsSchema = Utils.$$WeakMap.memoize(table => makeRowsSchema(table,
408
298
 
409
299
  let NonExistingTableField = /* @__PURE__ */Primitive_exceptions.create("Table.NonExistingTableField");
410
300
 
411
- function getUnfilteredCompositeIndexesUnsafe(table) {
412
- return table.compositeIndexes.map(compositeIndex => compositeIndex.map(indexField => {
413
- let field = getFieldByName(table, indexField.fieldName);
414
- let dbFieldName;
415
- if (field !== undefined) {
416
- dbFieldName = getPgFieldName(field);
417
- } else {
418
- throw {
419
- RE_EXN_ID: NonExistingTableField,
420
- _1: indexField.fieldName,
421
- Error: new Error()
422
- };
423
- }
424
- return {
425
- fieldName: dbFieldName,
426
- direction: indexField.direction
427
- };
428
- }));
429
- }
430
-
431
- function schemaOrderedFields(table, schema) {
432
- let match = schema.t;
433
- if (typeof match === "object" && match.TAG === "object") {
434
- return match.items.map(param => {
435
- let location = param.location;
436
- let match = fieldsByApiName(table)[location];
437
- if (match !== undefined) {
438
- if (match.TAG === "Field") {
439
- return match._0;
440
- }
441
- throw {
442
- RE_EXN_ID: NonExistingTableField,
443
- _1: location,
444
- Error: new Error()
445
- };
446
- }
447
- throw {
448
- RE_EXN_ID: NonExistingTableField,
449
- _1: location,
450
- Error: new Error()
451
- };
452
- });
453
- }
454
- return Stdlib_JsError.throwWithMessage(`Failed reading the columns of "` + table.tableName + `". Expected an object schema for a table.`);
455
- }
456
-
457
- function toDbSchema(table, schema) {
458
- return S$RescriptSchema.schema(s => {
459
- let match = schema.t;
460
- if (typeof match !== "object") {
461
- return Stdlib_JsError.throwWithMessage("Failed creating db schema. Expected an object schema for table");
462
- }
463
- if (match.TAG !== "object") {
464
- return Stdlib_JsError.throwWithMessage("Failed creating db schema. Expected an object schema for table");
465
- }
466
- let dict = {};
467
- match.items.forEach(param => {
468
- let location = param.location;
469
- let coerceSchema = schema => {
470
- let child = schema.t;
471
- if (typeof child !== "object") {
472
- switch (child) {
473
- case "bigint" :
474
- return Utils.$$BigInt.schema;
475
- case "boolean" :
476
- return S$RescriptSchema.union([
477
- S$RescriptSchema.shape(S$RescriptSchema.literal(1), param => true),
478
- S$RescriptSchema.shape(S$RescriptSchema.literal(0), param => false)
479
- ]);
480
- default:
481
- return schema;
482
- }
483
- } else {
484
- switch (child.TAG) {
485
- case "option" :
486
- case "null" :
487
- return Utils.Schema.nullTolerant(coerceSchema(child._0));
488
- case "array" :
489
- return S$RescriptSchema.array(coerceSchema(child._0));
490
- default:
491
- return schema;
492
- }
493
- }
494
- };
495
- if (Stdlib_Option.isNone(fieldsByApiName(table)[location])) {
496
- throw {
497
- RE_EXN_ID: NonExistingTableField,
498
- _1: location,
499
- Error: new Error()
500
- };
501
- }
502
- dict[location] = s.m(coerceSchema(param.schema));
503
- });
504
- return dict;
505
- });
506
- }
507
-
508
- function getSingleIndexes(table) {
509
- let indexFields = Stdlib_Array.filterMap(table.fields, field => {
510
- if (field.TAG !== "Field") {
511
- return;
512
- }
513
- let field$1 = field._0;
514
- if (field$1.isIndex) {
515
- return getPgDbFieldName(field$1);
516
- }
517
- });
518
- return Array.from(new Set(Stdlib_Array.filterMap(getUnfilteredCompositeIndexesUnsafe(table), cidx => {
519
- if (cidx.length !== 1) {
520
- return;
521
- }
522
- let match = cidx[0];
523
- return [match.fieldName];
524
- }).concat([indexFields]).flat())).toSorted(Primitive_string.compare);
525
- }
526
-
527
- function getCompositeIndexes(table) {
528
- return getUnfilteredCompositeIndexesUnsafe(table).filter(ind => ind.length > 1);
529
- }
530
-
531
301
  let maxPgTableNameLength = 63;
532
302
 
533
303
  export {
@@ -543,7 +313,10 @@ export {
543
313
  idFieldName,
544
314
  maxPgTableNameLength,
545
315
  fitPgTableName,
546
- pgFieldTypeParts,
316
+ stringEntityIdToKey,
317
+ numericEntityIdToKey,
318
+ bytesEntityIdToKey,
319
+ entityIdToKeyFor,
547
320
  mkTable,
548
321
  getFields,
549
322
  getNonDefaultFields,
@@ -555,8 +328,6 @@ export {
555
328
  NoIdField,
556
329
  getIdFieldOrThrow,
557
330
  getIdSchema,
558
- idsArraySchema,
559
- encodeIdsToJson,
560
331
  fieldsByApiName,
561
332
  getFieldByApiName,
562
333
  queryFields,
@@ -564,10 +335,5 @@ export {
564
335
  pgRowsSchema,
565
336
  pgEntityRowsSchema,
566
337
  NonExistingTableField,
567
- getUnfilteredCompositeIndexesUnsafe,
568
- schemaOrderedFields,
569
- toDbSchema,
570
- getSingleIndexes,
571
- getCompositeIndexes,
572
338
  }
573
- /* idsArraySchema Not a pure module */
339
+ /* fieldsByApiName Not a pure module */
@@ -10,8 +10,6 @@ type startBlockGroup = {startBlock: int, count: int}
10
10
 
11
11
  @send external contractNames: t => array<string> = "contractNames"
12
12
 
13
- @send external addressesOf: (t, string) => array<Address.t> = "addressesOf"
14
-
15
13
  @send external startBlockGroups: t => array<startBlockGroup> = "startBlockGroups"
16
14
 
17
15
  @send external slice: (t, ~offset: int, ~limit: option<int>) => t = "slice"
@@ -7,9 +7,6 @@ type registration = {
7
7
  contractName: string,
8
8
  // -1 for a config address.
9
9
  registrationBlock: int,
10
- // Subgraph mode: the round (see `Internal.getItemCreationRound`) the
11
- // registering handler ran in, plus one. Not part of the addon's registration.
12
- creationRound?: int,
13
10
  }
14
11
 
15
12
  type verdict =
@@ -10,6 +10,7 @@ let make = (
10
10
  ~blockStore: BlockStore.t,
11
11
  ~transactionStore: TransactionStore.t,
12
12
  ~logger: Logger.t,
13
+ ~maxAddressesPerRequest: int,
13
14
  ): array<Source.t> => {
14
15
  let chainId = chainConfig.id
15
16
  switch chainConfig.sourceConfig {
@@ -39,6 +40,7 @@ let make = (
39
40
  ~blockStore,
40
41
  ~transactionStore,
41
42
  ~logger,
43
+ ~maxAddressesPerRequest,
42
44
  )
43
45
  | Config.FuelSourceConfig({hypersync}) => [
44
46
  FuelHyperSyncSource.make({
@@ -7,7 +7,7 @@ import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js
7
7
  import * as SvmHyperSyncSource from "./SvmHyperSyncSource.res.mjs";
8
8
  import * as FuelHyperSyncSource from "./FuelHyperSyncSource.res.mjs";
9
9
 
10
- function make(chainConfig, onEventRegistrations, onBlockRegistrationsOpt, addressStore, lowercaseAddresses, blockStore, transactionStore, logger) {
10
+ function make(chainConfig, onEventRegistrations, onBlockRegistrationsOpt, addressStore, lowercaseAddresses, blockStore, transactionStore, logger, maxAddressesPerRequest) {
11
11
  let onBlockRegistrations = onBlockRegistrationsOpt !== undefined ? onBlockRegistrationsOpt : [];
12
12
  let chainId = chainConfig.id;
13
13
  let sources = chainConfig.sourceConfig;
@@ -25,7 +25,7 @@ function make(chainConfig, onEventRegistrations, onBlockRegistrationsOpt, addres
25
25
  headers: headers
26
26
  };
27
27
  });
28
- return EvmChain.makeSources(chainId, onEventRegistrations, onBlockRegistrations, sources.hypersync, evmRpcs, lowercaseAddresses, addressStore, blockStore, transactionStore, logger);
28
+ return EvmChain.makeSources(chainId, onEventRegistrations, onBlockRegistrations, sources.hypersync, evmRpcs, lowercaseAddresses, addressStore, blockStore, transactionStore, logger, maxAddressesPerRequest);
29
29
  case "FuelSourceConfig" :
30
30
  return [FuelHyperSyncSource.make({
31
31
  chainId: chainId,
@@ -50,6 +50,7 @@ let makeSources = (
50
50
  ~blockStore,
51
51
  ~transactionStore,
52
52
  ~logger,
53
+ ~maxAddressesPerRequest,
53
54
  ) => {
54
55
  let sources = switch hyperSync {
55
56
  | Some(endpointUrl) => [
@@ -84,15 +85,11 @@ let makeSources = (
84
85
  transactionStore,
85
86
  ?ws,
86
87
  ?headers,
88
+ maxAddressesPerRequest,
89
+ logger,
87
90
  })
88
91
  let _ = sources->Array.push(source)
89
92
  })
90
93
 
91
- sources->CallSource.wrapSources(
92
- ~onEventRegistrations=onEventRegistrations->(
93
- Utils.magic: array<Internal.evmOnEventRegistration> => array<Internal.onEventRegistration>
94
- ),
95
- ~addressStore,
96
- ~ecosystem=Evm,
97
- )
94
+ sources
98
95
  }
@@ -2,7 +2,6 @@
2
2
 
3
3
  import * as Env from "../Env.res.mjs";
4
4
  import * as RpcSource from "./RpcSource.res.mjs";
5
- import * as CallSource from "./CallSource.res.mjs";
6
5
  import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
7
6
  import * as EvmHyperSyncSource from "./EvmHyperSyncSource.res.mjs";
8
7
 
@@ -20,7 +19,7 @@ function getSyncConfig(param) {
20
19
  };
21
20
  }
22
21
 
23
- function makeSources(chainId, onEventRegistrations, onBlockRegistrations, hyperSync, rpcs, lowercaseAddresses, addressStore, blockStore, transactionStore, logger) {
22
+ function makeSources(chainId, onEventRegistrations, onBlockRegistrations, hyperSync, rpcs, lowercaseAddresses, addressStore, blockStore, transactionStore, logger, maxAddressesPerRequest) {
24
23
  let sources = hyperSync !== undefined ? [EvmHyperSyncSource.make({
25
24
  chainId: chainId,
26
25
  endpointUrl: hyperSync,
@@ -48,11 +47,13 @@ function makeSources(chainId, onEventRegistrations, onBlockRegistrations, hyperS
48
47
  blockStore: blockStore,
49
48
  transactionStore: transactionStore,
50
49
  ws: param.ws,
51
- headers: param.headers
50
+ headers: param.headers,
51
+ maxAddressesPerRequest: maxAddressesPerRequest,
52
+ logger: logger
52
53
  });
53
54
  sources.push(source);
54
55
  });
55
- return CallSource.wrapSources(sources, onEventRegistrations, addressStore, "evm");
56
+ return sources;
56
57
  }
57
58
 
58
59
  export {
@@ -202,7 +202,7 @@ let make = (
202
202
  {height, requestStats: [{method: "getHeight", seconds}]}
203
203
  },
204
204
  getItemsOrThrow,
205
- createHeightSubscription: (~onHeight, ~onStatus) =>
206
- HyperSyncSSE.subscribe(~hyperSyncUrl=endpointUrl, ~apiToken, ~onHeight, ~onStatus),
205
+ createHeightSubscription: (~clock, ~onHeight, ~onStatus) =>
206
+ HyperSyncSSE.subscribe(~clock, ~hyperSyncUrl=endpointUrl, ~apiToken, ~onHeight, ~onStatus),
207
207
  }
208
208
  }