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.
- package/README.md +40 -34
- package/evm.schema.json +11 -2
- package/fuel.schema.json +10 -1
- package/index.d.ts +6 -0
- package/licenses/README.md +1 -1
- package/package.json +10 -9
- package/src/Batch.res.mjs +5 -5
- package/src/BatchProcessing.res +1 -0
- package/src/BatchProcessing.res.mjs +1 -0
- package/src/Bin.res +7 -0
- package/src/Bin.res.mjs +8 -0
- package/src/ChainFetching.res +450 -16
- package/src/ChainFetching.res.mjs +403 -32
- package/src/ChainState.res +124 -7
- package/src/ChainState.res.mjs +128 -67
- package/src/ChainState.resi +26 -0
- package/src/Clock.res +57 -0
- package/src/Clock.res.mjs +72 -0
- package/src/Config.res +31 -3
- package/src/Config.res.mjs +15 -4
- package/src/ContractRegisterContext.res +3 -6
- package/src/ContractRegisterContext.res.mjs +4 -2
- package/src/Core.res +95 -36
- package/src/Core.res.mjs +90 -1
- package/src/CrossChainState.res +12 -2
- package/src/CrossChainState.res.mjs +3 -3
- package/src/Ecosystem.res +7 -4
- package/src/Ecosystem.res.mjs +8 -8
- package/src/EffectCacheLookup.res +98 -0
- package/src/EffectCacheLookup.res.mjs +116 -0
- package/src/EffectState.res +10 -2
- package/src/EffectState.res.mjs +8 -4
- package/src/EffectState.resi +3 -1
- package/src/EntityId.res +2 -7
- package/src/EntityId.res.mjs +1 -8
- package/src/EntityTables.res +4 -1
- package/src/EntityTables.res.mjs +1 -1
- package/src/Env.res +20 -0
- package/src/Env.res.mjs +16 -0
- package/src/EventProcessing.res +38 -1
- package/src/EventProcessing.res.mjs +28 -1
- package/src/FetchState.res +408 -73
- package/src/FetchState.res.mjs +361 -91
- package/src/FinalizeBackfill.res +2 -4
- package/src/FinalizeBackfill.res.mjs +3 -4
- package/src/HandlerLoader.res +39 -15
- package/src/HandlerLoader.res.mjs +27 -8
- package/src/HandlerRegister.res +4 -0
- package/src/HandlerRegister.res.mjs +5 -2
- package/src/HandlerRegister.resi +2 -0
- package/src/InMemoryTable.res +17 -16
- package/src/InMemoryTable.res.mjs +14 -15
- package/src/IndexerState.res +28 -4
- package/src/IndexerState.res.mjs +19 -6
- package/src/IndexerState.resi +4 -0
- package/src/Internal.res +61 -49
- package/src/Internal.res.mjs +36 -80
- package/src/LoadLayer.res +54 -15
- package/src/LoadLayer.res.mjs +75 -45
- package/src/LoadLayer.resi +26 -0
- package/src/Main.res +14 -1
- package/src/Main.res.mjs +4 -3
- package/src/Persistence.res +3 -23
- package/src/Persistence.res.mjs +3 -3
- package/src/PreloadLookahead.res +202 -0
- package/src/PreloadLookahead.res.mjs +218 -0
- package/src/Rollback.res +0 -1
- package/src/Rollback.res.mjs +1 -1
- package/src/RunScope.res +3 -0
- package/src/SafeCheckpointTracking.res +4 -4
- package/src/SafeCheckpointTracking.res.mjs +1 -1
- package/src/SimulateItems.res +42 -26
- package/src/SimulateItems.res.mjs +40 -16
- package/src/StagedRows.res +106 -0
- package/src/StagedRows.res.mjs +102 -0
- package/src/Staging.res +32 -14
- package/src/Staging.res.mjs +17 -20
- package/src/Storage.res +303 -948
- package/src/Storage.res.mjs +229 -708
- package/src/SubgraphLog.res +19 -0
- package/src/SubgraphLog.res.mjs +26 -0
- package/src/Supervisor.res +75 -56
- package/src/Supervisor.res.mjs +55 -26
- package/src/SyncWrites.res +107 -0
- package/src/SyncWrites.res.mjs +98 -0
- package/src/TestIndexer.res +22 -27
- package/src/TestIndexer.res.mjs +20 -17
- package/src/Throttler.res +15 -8
- package/src/Throttler.res.mjs +9 -6
- package/src/Throttler.resi +1 -1
- package/src/UserContext.res +419 -46
- package/src/UserContext.res.mjs +318 -30
- package/src/Utils.res +17 -6
- package/src/Utils.res.mjs +12 -6
- package/src/Writing.res +0 -1
- package/src/Writing.res.mjs +1 -1
- package/src/bindings/ClickHouse.res +0 -322
- package/src/bindings/ClickHouse.res.mjs +0 -338
- package/src/bindings/StorageClient.res +108 -174
- package/src/bindings/StorageClient.res.mjs +19 -8
- package/src/bindings/Vitest.res +0 -26
- package/src/bindings/Vitest.res.mjs +0 -3
- package/src/db/Table.res +24 -150
- package/src/db/Table.res.mjs +38 -272
- package/src/sources/AddressSet.res +2 -0
- package/src/sources/AddressStore.res +3 -0
- package/src/sources/CallSource.res +274 -0
- package/src/sources/CallSource.res.mjs +196 -0
- package/src/sources/ChainSources.res +2 -0
- package/src/sources/ChainSources.res.mjs +2 -2
- package/src/sources/EvmChain.res +10 -1
- package/src/sources/EvmChain.res.mjs +6 -3
- package/src/sources/EvmHyperSyncSource.res +2 -2
- package/src/sources/EvmHyperSyncSource.res.mjs +1 -1
- package/src/sources/EvmRpcClient.res +13 -3
- package/src/sources/EvmRpcClient.res.mjs +4 -3
- package/src/sources/EvmRpcWs.res +4 -3
- package/src/sources/EvmRpcWs.res.mjs +2 -2
- package/src/sources/HeightFeed.res +31 -10
- package/src/sources/HeightFeed.res.mjs +10 -6
- package/src/sources/HeightStream.res +32 -17
- package/src/sources/HeightStream.res.mjs +10 -10
- package/src/sources/HyperSync.res +2 -1
- package/src/sources/HyperSync.res.mjs +2 -1
- package/src/sources/HyperSyncSSE.res +4 -6
- package/src/sources/HyperSyncSSE.res.mjs +2 -2
- package/src/sources/RpcSource.res +10 -1
- package/src/sources/RpcSource.res.mjs +4 -3
- package/src/sources/Source.res +3 -0
- package/src/sources/SourceManager.res +84 -77
- package/src/sources/SourceManager.res.mjs +17 -20
- package/src/sources/SourceManager.resi +3 -4
- package/src/sources/StartBlockResolver.res +1 -0
- package/src/sources/StartBlockResolver.res.mjs +3 -2
- package/src/sources/SvmHyperSyncSource.res +2 -2
- package/src/sources/SvmHyperSyncSource.res.mjs +1 -1
- package/src/subgraph/abi-types.ts +84 -0
- package/src/subgraph/aggregations.ts +745 -0
- package/src/subgraph/as-package.ts +143 -0
- package/src/subgraph/assemblyscript-regex.ts +67 -0
- package/src/subgraph/assemblyscript.ts +731 -0
- package/src/subgraph/blocks.ts +398 -0
- package/src/subgraph/calls-source.ts +702 -0
- package/src/subgraph/calls.ts +258 -0
- package/src/subgraph/conformance.ts +106 -0
- package/src/subgraph/errors.ts +85 -0
- package/src/subgraph/graft.ts +73 -0
- package/src/subgraph/graph-cli-worker.mjs +35 -0
- package/src/subgraph/graph-cli.ts +900 -0
- package/src/subgraph/graph-node-decimal.ts +199 -0
- package/src/subgraph/graph-ts-enums.ts +28 -0
- package/src/subgraph/graph-ts-types/VERSION +2 -0
- package/src/subgraph/graph-ts-types/chain/arweave.d.ts +70 -0
- package/src/subgraph/graph-ts-types/chain/cosmos.d.ts +327 -0
- package/src/subgraph/graph-ts-types/chain/ethereum.d.ts +233 -0
- package/src/subgraph/graph-ts-types/chain/near.d.ts +253 -0
- package/src/subgraph/graph-ts-types/chain/starknet.d.ts +32 -0
- package/src/subgraph/graph-ts-types/common/collections.d.ts +136 -0
- package/src/subgraph/graph-ts-types/common/conversion.d.ts +11 -0
- package/src/subgraph/graph-ts-types/common/datasource.d.ts +30 -0
- package/src/subgraph/graph-ts-types/common/eager-offset.d.ts +0 -0
- package/src/subgraph/graph-ts-types/common/json.d.ts +17 -0
- package/src/subgraph/graph-ts-types/common/numbers.d.ts +120 -0
- package/src/subgraph/graph-ts-types/common/value.d.ts +120 -0
- package/src/subgraph/graph-ts-types/common/yaml.d.ts +90 -0
- package/src/subgraph/graph-ts-types/global/global.d.ts +194 -0
- package/src/subgraph/graph-ts-types/helper-functions.d.ts +22 -0
- package/src/subgraph/graph-ts-types/index.d.ts +102 -0
- package/src/subgraph/graph-ts.ts +4339 -0
- package/src/subgraph/hosts.ts +554 -0
- package/src/subgraph/log.ts +28 -0
- package/src/subgraph/receipts.ts +184 -0
- package/src/subgraph/register-slots.ts +93 -0
- package/src/subgraph/rollup.ts +109 -0
- package/src/subgraph/rpc.ts +337 -0
- package/src/subgraph/runtime.ts +2059 -0
- package/src/subgraph/scope.ts +176 -0
- package/src/subgraph/stats.ts +42 -0
- package/src/subgraph/template-instances.ts +66 -0
- package/src/subgraph/toolchain.ts +327 -0
- package/src/subgraph/transient.ts +176 -0
- package/svm.schema.json +11 -2
- package/src/PgWriting.res +0 -36
- package/src/PgWriting.res.mjs +0 -34
- package/src/db/IndexDefinition.res +0 -47
- package/src/db/IndexDefinition.res.mjs +0 -67
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
|
-
}
|
package/src/db/Table.res.mjs
CHANGED
|
@@ -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
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
|
-
|
|
212
|
-
|
|
213
|
-
|
|
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
|
-
|
|
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
|
-
/*
|
|
339
|
+
/* fieldsByApiName Not a pure module */
|
|
@@ -10,6 +10,8 @@ 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
|
+
|
|
13
15
|
@send external startBlockGroups: t => array<startBlockGroup> = "startBlockGroups"
|
|
14
16
|
|
|
15
17
|
@send external slice: (t, ~offset: int, ~limit: option<int>) => t = "slice"
|
|
@@ -7,6 +7,9 @@ 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,
|
|
10
13
|
}
|
|
11
14
|
|
|
12
15
|
type verdict =
|