envio 3.9.0-resolvers.0 → 3.10.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.
- package/evm.schema.json +26 -7
- package/fuel.schema.json +26 -7
- package/index.d.ts +8 -246
- package/index.js +0 -10
- package/package.json +6 -6
- package/src/Bin.res +0 -47
- package/src/Bin.res.mjs +1 -34
- package/src/Config.res +45 -17
- package/src/Config.res.mjs +40 -8
- package/src/CrossChainState.res +15 -23
- package/src/CrossChainState.res.mjs +10 -18
- package/src/CrossChainState.resi +4 -1
- package/src/Env.res +1 -128
- package/src/Env.res.mjs +1 -123
- package/src/Envio.res +6 -4
- package/src/HandlerRegister.res +15 -0
- package/src/HandlerRegister.res.mjs +16 -0
- package/src/InMemoryStore.res +7 -8
- package/src/InMemoryStore.res.mjs +3 -3
- package/src/IndexerState.res +26 -6
- package/src/IndexerState.res.mjs +16 -7
- package/src/IndexerState.resi +2 -4
- package/src/Metrics.res +72 -6
- package/src/Metrics.res.mjs +30 -2
- package/src/Persistence.res +29 -32
- package/src/Persistence.res.mjs +1 -20
- package/src/PgStorage.res +81 -69
- package/src/PgStorage.res.mjs +50 -36
- package/src/PruneStaleHistory.res +85 -52
- package/src/PruneStaleHistory.res.mjs +63 -37
- package/src/Rollback.res +36 -30
- package/src/Rollback.res.mjs +15 -36
- package/src/SafeCheckpointTracking.res +11 -11
- package/src/SafeCheckpointTracking.res.mjs +7 -6
- package/src/SimulateItems.res +33 -18
- package/src/SimulateItems.res.mjs +26 -22
- package/src/Sink.res +6 -3
- package/src/Sink.res.mjs +3 -2
- package/src/TestIndexer.res +5 -5
- package/src/TestIndexer.res.mjs +3 -3
- package/src/Utils.res +139 -0
- package/src/Utils.res.mjs +123 -0
- package/src/bindings/ClickHouse.res +146 -100
- package/src/bindings/ClickHouse.res.mjs +155 -79
- package/src/bindings/ClickHouseSink.res +51 -17
- package/src/bindings/ClickHouseSink.res.mjs +35 -5
- package/src/bindings/EventSource.res +8 -2
- package/src/bindings/NodeJs.res +6 -0
- package/src/bindings/Vitest.res +23 -0
- package/src/bindings/Vitest.res.mjs +3 -0
- package/src/bindings/WebSocket.res +9 -10
- package/src/db/CheckpointBounds.res +53 -0
- package/src/db/CheckpointBounds.res.mjs +44 -0
- package/src/db/EntityFilter.res +36 -17
- package/src/db/EntityFilter.res.mjs +25 -14
- package/src/db/EntityHistory.res +33 -19
- package/src/db/EntityHistory.res.mjs +14 -10
- package/src/db/InternalTable.res +23 -32
- package/src/db/InternalTable.res.mjs +21 -16
- package/src/db/RollbackFloors.res +55 -0
- package/src/db/RollbackFloors.res.mjs +92 -0
- package/src/db/Table.res +18 -3
- package/src/db/Table.res.mjs +24 -8
- package/src/sources/EvmHyperSyncSource.res +3 -3
- package/src/sources/EvmHyperSyncSource.res.mjs +3 -3
- package/src/sources/EvmRpcWs.res +124 -0
- package/src/sources/EvmRpcWs.res.mjs +117 -0
- package/src/sources/FuelHyperSyncSource.res +1 -1
- package/src/sources/FuelHyperSyncSource.res.mjs +2 -1
- package/src/sources/HeightFeed.res +568 -0
- package/src/sources/HeightFeed.res.mjs +452 -0
- package/src/sources/HeightStream.res +257 -0
- package/src/sources/HeightStream.res.mjs +194 -0
- package/src/sources/HyperSync.res +5 -0
- package/src/sources/HyperSync.res.mjs +3 -0
- package/src/sources/HyperSync.resi +4 -0
- package/src/sources/HyperSyncSSE.res +49 -0
- package/src/sources/HyperSyncSSE.res.mjs +79 -0
- package/src/sources/RpcSource.res +1 -1
- package/src/sources/RpcSource.res.mjs +2 -2
- package/src/sources/Source.res +54 -1
- package/src/sources/Source.res.mjs +25 -0
- package/src/sources/SourceManager.res +220 -227
- package/src/sources/SourceManager.res.mjs +139 -164
- package/src/sources/SourceManager.resi +8 -0
- package/src/sources/SvmHyperSyncClient.res +69 -36
- package/src/sources/SvmHyperSyncClient.res.mjs +49 -20
- package/src/sources/SvmHyperSyncSource.res +17 -14
- package/src/sources/SvmHyperSyncSource.res.mjs +5 -4
- package/src/tui/Tui.res +1 -1
- package/src/tui/Tui.res.mjs +1 -1
- package/svm.schema.json +1 -8
- package/src/db/RollbackScope.res +0 -29
- package/src/db/RollbackScope.res.mjs +0 -31
- package/src/resolvers/ResolverProcess.res +0 -809
- package/src/resolvers/ResolverProcess.res.mjs +0 -667
- package/src/resolvers/ResolverQuery.res +0 -317
- package/src/resolvers/ResolverQuery.res.mjs +0 -220
- package/src/resolvers/collisions.js +0 -108
- package/src/resolvers/db.js +0 -363
- package/src/resolvers/dispatch.js +0 -165
- package/src/resolvers/errors.js +0 -30
- package/src/resolvers/graphqlSelection.js +0 -292
- package/src/resolvers/hasuraAction.js +0 -84
- package/src/resolvers/hasuraApply.js +0 -323
- package/src/resolvers/hasuraMetadata.js +0 -119
- package/src/resolvers/index.js +0 -95
- package/src/resolvers/manifest.js +0 -370
- package/src/resolvers/server.js +0 -270
- package/src/sources/HyperSyncHeightStream.res +0 -129
- package/src/sources/HyperSyncHeightStream.res.mjs +0 -110
- package/src/sources/RpcWebSocketHeightStream.res +0 -175
- package/src/sources/RpcWebSocketHeightStream.res.mjs +0 -180
package/evm.schema.json
CHANGED
|
@@ -29,13 +29,6 @@
|
|
|
29
29
|
"null"
|
|
30
30
|
]
|
|
31
31
|
},
|
|
32
|
-
"resolvers": {
|
|
33
|
-
"description": "Optional relative path to the custom GraphQL resolvers, either a single module (e.g. 'src/Resolvers.ts') or a directory (e.g. 'src/resolvers'), in which case every .js/.mjs/.ts file beneath it is loaded, tests excluded. The resolvers they export are served as additional root fields on the indexer's GraphQL endpoint.",
|
|
34
|
-
"type": [
|
|
35
|
-
"string",
|
|
36
|
-
"null"
|
|
37
|
-
]
|
|
38
|
-
},
|
|
39
32
|
"full_batch_size": {
|
|
40
33
|
"description": "Target number of events to be processed per batch. Set it to smaller number if you have many Effect API calls which are slow to resolve and can't be batched. (Default: 5000)",
|
|
41
34
|
"type": [
|
|
@@ -133,6 +126,17 @@
|
|
|
133
126
|
"type": "null"
|
|
134
127
|
}
|
|
135
128
|
]
|
|
129
|
+
},
|
|
130
|
+
"bytes_type": {
|
|
131
|
+
"description": "How the `Bytes` scalar in schema.graphql is represented. `hex` keeps 0x-prefixed hex strings stored as text, `uint8array` exposes `Uint8Array` values in handlers and stores raw bytes (BYTEA in Postgres, String in ClickHouse). (default: hex)",
|
|
132
|
+
"anyOf": [
|
|
133
|
+
{
|
|
134
|
+
"$ref": "#/$defs/BytesType"
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
"type": "null"
|
|
138
|
+
}
|
|
139
|
+
]
|
|
136
140
|
}
|
|
137
141
|
},
|
|
138
142
|
"additionalProperties": false,
|
|
@@ -765,6 +769,21 @@
|
|
|
765
769
|
"checksum",
|
|
766
770
|
"lowercase"
|
|
767
771
|
]
|
|
772
|
+
},
|
|
773
|
+
"BytesType": {
|
|
774
|
+
"description": "How the schema.graphql `Bytes` scalar reaches handlers and storage.",
|
|
775
|
+
"oneOf": [
|
|
776
|
+
{
|
|
777
|
+
"description": "`0x`-prefixed hex strings, stored as text.",
|
|
778
|
+
"type": "string",
|
|
779
|
+
"const": "hex"
|
|
780
|
+
},
|
|
781
|
+
{
|
|
782
|
+
"description": "`Uint8Array` values, stored as raw bytes (`BYTEA` in Postgres, `String` in ClickHouse).",
|
|
783
|
+
"type": "string",
|
|
784
|
+
"const": "uint8array"
|
|
785
|
+
}
|
|
786
|
+
]
|
|
768
787
|
}
|
|
769
788
|
}
|
|
770
789
|
}
|
package/fuel.schema.json
CHANGED
|
@@ -29,13 +29,6 @@
|
|
|
29
29
|
"null"
|
|
30
30
|
]
|
|
31
31
|
},
|
|
32
|
-
"resolvers": {
|
|
33
|
-
"description": "Optional relative path to the custom GraphQL resolvers, either a single module (e.g. 'src/Resolvers.ts') or a directory (e.g. 'src/resolvers'), in which case every .js/.mjs/.ts file beneath it is loaded, tests excluded. The resolvers they export are served as additional root fields on the indexer's GraphQL endpoint.",
|
|
34
|
-
"type": [
|
|
35
|
-
"string",
|
|
36
|
-
"null"
|
|
37
|
-
]
|
|
38
|
-
},
|
|
39
32
|
"full_batch_size": {
|
|
40
33
|
"description": "Target number of events to be processed per batch. Set it to smaller number if you have many Effect API calls which are slow to resolve and can't be batched. (Default: 5000)",
|
|
41
34
|
"type": [
|
|
@@ -90,6 +83,17 @@
|
|
|
90
83
|
"boolean",
|
|
91
84
|
"null"
|
|
92
85
|
]
|
|
86
|
+
},
|
|
87
|
+
"bytes_type": {
|
|
88
|
+
"description": "How the `Bytes` scalar in schema.graphql is represented. `hex` keeps 0x-prefixed hex strings stored as text, `uint8array` exposes `Uint8Array` values in handlers and stores raw bytes (BYTEA in Postgres, String in ClickHouse). (default: hex)",
|
|
89
|
+
"anyOf": [
|
|
90
|
+
{
|
|
91
|
+
"$ref": "#/$defs/BytesType"
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
"type": "null"
|
|
95
|
+
}
|
|
96
|
+
]
|
|
93
97
|
}
|
|
94
98
|
},
|
|
95
99
|
"additionalProperties": false,
|
|
@@ -471,6 +475,21 @@
|
|
|
471
475
|
}
|
|
472
476
|
}
|
|
473
477
|
]
|
|
478
|
+
},
|
|
479
|
+
"BytesType": {
|
|
480
|
+
"description": "How the schema.graphql `Bytes` scalar reaches handlers and storage.",
|
|
481
|
+
"oneOf": [
|
|
482
|
+
{
|
|
483
|
+
"description": "`0x`-prefixed hex strings, stored as text.",
|
|
484
|
+
"type": "string",
|
|
485
|
+
"const": "hex"
|
|
486
|
+
},
|
|
487
|
+
{
|
|
488
|
+
"description": "`Uint8Array` values, stored as raw bytes (`BYTEA` in Postgres, `String` in ClickHouse).",
|
|
489
|
+
"type": "string",
|
|
490
|
+
"const": "uint8array"
|
|
491
|
+
}
|
|
492
|
+
]
|
|
474
493
|
}
|
|
475
494
|
}
|
|
476
495
|
}
|
package/index.d.ts
CHANGED
|
@@ -1423,7 +1423,7 @@ type SvmSelectedInstruction<Fields extends SvmFieldsSelection, ProgInstr> = {
|
|
|
1423
1423
|
readonly instructionName: string;
|
|
1424
1424
|
readonly discriminator: string;
|
|
1425
1425
|
readonly programId: SvmInstrField<Fields, "programId", string>;
|
|
1426
|
-
readonly data: SvmInstrField<Fields, "data",
|
|
1426
|
+
readonly data: SvmInstrField<Fields, "data", Uint8Array>;
|
|
1427
1427
|
readonly path: SvmInstrField<Fields, "path", readonly number[]>;
|
|
1428
1428
|
readonly isInner: SvmInstrField<Fields, "isInner", boolean>;
|
|
1429
1429
|
readonly args: SvmInstrField<
|
|
@@ -1937,8 +1937,8 @@ type SvmSimulateItem<Config extends IndexerConfigTypes = GlobalConfig> =
|
|
|
1937
1937
|
path?: readonly number[];
|
|
1938
1938
|
/** Override the program id. Defaults to the configured `program_id`. */
|
|
1939
1939
|
programId?: string;
|
|
1940
|
-
/** Raw instruction data
|
|
1941
|
-
data?:
|
|
1940
|
+
/** Raw instruction data. Defaults to the configured discriminator bytes. */
|
|
1941
|
+
data?: Uint8Array;
|
|
1942
1942
|
/** Whether this is a CPI-invoked inner instruction. */
|
|
1943
1943
|
isInner?: boolean;
|
|
1944
1944
|
/** Decoded args. Keys match the instruction's arg names. */
|
|
@@ -2012,10 +2012,10 @@ type ConfigEntities<Config extends IndexerConfigTypes = GlobalConfig> =
|
|
|
2012
2012
|
type PerChainEntityNames<Config extends IndexerConfigTypes = GlobalConfig> =
|
|
2013
2013
|
Config extends { perChainEntities: infer Names extends string } ? Names : never;
|
|
2014
2014
|
|
|
2015
|
-
/** The row shape chain-agnostic
|
|
2016
|
-
* only identified together with its chain, so the
|
|
2017
|
-
* the entity fields. */
|
|
2018
|
-
type
|
|
2015
|
+
/** The row shape the chain-agnostic test-indexer operations exchange. A
|
|
2016
|
+
* per-chain entity's row is only identified together with its chain, so the
|
|
2017
|
+
* chain id travels alongside the entity fields. */
|
|
2018
|
+
type TestIndexerEntityRow<
|
|
2019
2019
|
Config extends IndexerConfigTypes,
|
|
2020
2020
|
Name,
|
|
2021
2021
|
Entity
|
|
@@ -2209,7 +2209,7 @@ export type TestIndexerFromConfig<Config extends IndexerConfigTypes = GlobalConf
|
|
|
2209
2209
|
} & SingleEcosystemTestChains<Config> & {
|
|
2210
2210
|
/** Entity operations for direct manipulation outside of handlers. */
|
|
2211
2211
|
readonly [K in keyof ConfigEntities<Config>]: TestIndexerEntityOperations<
|
|
2212
|
-
|
|
2212
|
+
TestIndexerEntityRow<Config, K, ConfigEntities<Config>[K]>
|
|
2213
2213
|
>;
|
|
2214
2214
|
};
|
|
2215
2215
|
|
|
@@ -2283,244 +2283,6 @@ export type EnumName = keyof EnumsT & string;
|
|
|
2283
2283
|
/** Lookup an enum value type by name (e.g. `Enum<"AccountType">`). */
|
|
2284
2284
|
export type Enum<TName extends EnumName> = EnumsT[TName];
|
|
2285
2285
|
|
|
2286
|
-
// ============== Custom Resolver Types ==============
|
|
2287
|
-
|
|
2288
|
-
/** Handle for a custom GraphQL resolver created via {@link createResolver}. */
|
|
2289
|
-
export declare abstract class Resolver<Args, Output> {
|
|
2290
|
-
protected opaque: Args | Output;
|
|
2291
|
-
}
|
|
2292
|
-
|
|
2293
|
-
/** The selection the caller asked for: field names and their nesting, with
|
|
2294
|
-
* aliases and fragments already resolved away. A resolver may use it to skip
|
|
2295
|
-
* work it wasn't asked for — the response is projected against the declared
|
|
2296
|
-
* schema either way, so correctness never depends on honouring it. */
|
|
2297
|
-
export type ResolverSelection = { readonly [field: string]: ResolverSelection };
|
|
2298
|
-
|
|
2299
|
-
/** Request metadata, forwarded by envio-serve. */
|
|
2300
|
-
export type ResolverContext = {
|
|
2301
|
-
/** The role the operation was executed under. `admin: true` resolvers are
|
|
2302
|
-
* only reachable as `"admin"`. */
|
|
2303
|
-
readonly role: "public" | "admin";
|
|
2304
|
-
/** Correlates this field's work with the operation it belongs to. */
|
|
2305
|
-
readonly requestId: string;
|
|
2306
|
-
/** W3C trace context of the incoming request, when the caller sent one. */
|
|
2307
|
-
readonly traceparent?: string;
|
|
2308
|
-
};
|
|
2309
|
-
|
|
2310
|
-
/** How far a chain has been indexed. Read it to refuse to answer from a stale
|
|
2311
|
-
* index — `sourceBlock - progressBlock` is how far behind the head the
|
|
2312
|
-
* indexer is. */
|
|
2313
|
-
export type ChainHeight = {
|
|
2314
|
-
readonly chainId: number;
|
|
2315
|
-
/** `"evm"`, `"fuel"` or `"svm"`. Chain ids are only unique within one. */
|
|
2316
|
-
readonly ecosystem: string;
|
|
2317
|
-
readonly startBlock: number;
|
|
2318
|
-
readonly endBlock: number | null;
|
|
2319
|
-
/** The latest block seen on the chain. */
|
|
2320
|
-
readonly sourceBlock: number;
|
|
2321
|
-
/** The latest block fetched from the source. */
|
|
2322
|
-
readonly bufferBlock: number;
|
|
2323
|
-
/** The latest block whose events have been processed and committed. */
|
|
2324
|
-
readonly progressBlock: number;
|
|
2325
|
-
/** When the chain first caught up to the head, or null while it hasn't. */
|
|
2326
|
-
readonly readyAt: Date | null;
|
|
2327
|
-
readonly isReady: boolean;
|
|
2328
|
-
};
|
|
2329
|
-
|
|
2330
|
-
/** Raw SQL, run under the resolver's `statement_timeout` and against its
|
|
2331
|
-
* bounded pool. */
|
|
2332
|
-
export type ResolverSql = {
|
|
2333
|
-
/** ``db.sql`select 1` `` */
|
|
2334
|
-
<Row = Record<string, unknown>>(
|
|
2335
|
-
strings: TemplateStringsArray,
|
|
2336
|
-
...values: readonly unknown[]
|
|
2337
|
-
): Promise<Row[]>;
|
|
2338
|
-
/** `db.sql.unsafe(text, params)` — the direct lift for a query built as a
|
|
2339
|
-
* string with positional parameters. */
|
|
2340
|
-
unsafe<Row = Record<string, unknown>>(
|
|
2341
|
-
text: string,
|
|
2342
|
-
params?: readonly unknown[],
|
|
2343
|
-
options?: { readonly prepare?: boolean }
|
|
2344
|
-
): Promise<Row[]>;
|
|
2345
|
-
};
|
|
2346
|
-
|
|
2347
|
-
/** Options accepted by `db.find`. */
|
|
2348
|
-
export type ResolverFindOptions<Entity> = {
|
|
2349
|
-
/** Filter by field, with the same operators as `context.<Entity>.getWhere`.
|
|
2350
|
-
* Unlike `getWhere`, any field can be filtered on here — it is a query
|
|
2351
|
-
* against the table, so an unindexed field is a slow one, not an error. */
|
|
2352
|
-
readonly where?: GetWhereFilter<Entity>;
|
|
2353
|
-
readonly orderBy?: readonly {
|
|
2354
|
-
readonly field: keyof Entity & string;
|
|
2355
|
-
readonly direction: "asc" | "desc";
|
|
2356
|
-
}[];
|
|
2357
|
-
readonly limit?: number;
|
|
2358
|
-
readonly offset?: number;
|
|
2359
|
-
};
|
|
2360
|
-
|
|
2361
|
-
/** The database a resolver reads through. Every query it runs carries the
|
|
2362
|
-
* resolver's `timeoutMs` as a `statement_timeout` and takes one of the
|
|
2363
|
-
* process's bounded connections. */
|
|
2364
|
-
export type ResolverDb<Config extends IndexerConfigTypes = GlobalConfig> = {
|
|
2365
|
-
/** Entities matching `where`, decoded exactly as a handler sees them. */
|
|
2366
|
-
readonly find: <Name extends keyof ConfigEntities<Config> & string>(
|
|
2367
|
-
entityName: Name,
|
|
2368
|
-
options?: ResolverFindOptions<
|
|
2369
|
-
ChainScopedEntityRow<Config, Name, ConfigEntities<Config>[Name]>
|
|
2370
|
-
>
|
|
2371
|
-
) => Promise<
|
|
2372
|
-
ChainScopedEntityRow<Config, Name, ConfigEntities<Config>[Name]>[]
|
|
2373
|
-
>;
|
|
2374
|
-
/** One entity by id, or null. Not available for per-chain entities, whose
|
|
2375
|
-
* key is the id together with a chain — use {@link ResolverDb.find}. */
|
|
2376
|
-
readonly get: <
|
|
2377
|
-
Name extends Exclude<
|
|
2378
|
-
keyof ConfigEntities<Config> & string,
|
|
2379
|
-
PerChainEntityNames<Config>
|
|
2380
|
-
>
|
|
2381
|
-
>(
|
|
2382
|
-
entityName: Name,
|
|
2383
|
-
id: EntityId<ConfigEntities<Config>[Name]>
|
|
2384
|
-
) => Promise<ConfigEntities<Config>[Name] | null>;
|
|
2385
|
-
/** Raw SQL, for what the loaders don't express. */
|
|
2386
|
-
readonly sql: ResolverSql;
|
|
2387
|
-
/** The Postgres schema the indexer's tables live in. Raw SQL has to qualify
|
|
2388
|
-
* table names with it — it is not `"public"` on a hosted deployment. */
|
|
2389
|
-
readonly pgSchema: string;
|
|
2390
|
-
/** Several queries on one connection, under one timeout. */
|
|
2391
|
-
readonly transaction: <T>(work: (sql: ResolverSql) => Promise<T>) => Promise<T>;
|
|
2392
|
-
/** How far each chain has been indexed, keyed by chain id. */
|
|
2393
|
-
readonly chainHeights: () => Promise<Record<string, ChainHeight>>;
|
|
2394
|
-
};
|
|
2395
|
-
|
|
2396
|
-
/** Arguments passed to a {@link Resolver}'s handler. */
|
|
2397
|
-
export type ResolverHandlerArgs<
|
|
2398
|
-
Args,
|
|
2399
|
-
Config extends IndexerConfigTypes = GlobalConfig
|
|
2400
|
-
> = {
|
|
2401
|
-
/** Coerced and validated against the declared arg schemas before the
|
|
2402
|
-
* resolver is reached. */
|
|
2403
|
-
readonly args: Args;
|
|
2404
|
-
readonly db: ResolverDb<Config>;
|
|
2405
|
-
readonly selection: ResolverSelection;
|
|
2406
|
-
readonly ctx: ResolverContext;
|
|
2407
|
-
};
|
|
2408
|
-
|
|
2409
|
-
/**
|
|
2410
|
-
* Declares a custom GraphQL resolver: a root query field served alongside the
|
|
2411
|
-
* generated entity fields, backed by TypeScript in this project.
|
|
2412
|
-
*
|
|
2413
|
-
* Arguments and result are declared with the same `S` schemas effects use, and
|
|
2414
|
-
* the GraphQL types are derived from them. A field is non-null unless its
|
|
2415
|
-
* schema is optional. Object types must be named with {@link defineType} —
|
|
2416
|
-
* GraphQL has no anonymous types.
|
|
2417
|
-
*
|
|
2418
|
-
* ```ts
|
|
2419
|
-
* export const marketsAprByPeriod = createResolver({
|
|
2420
|
-
* name: "marketsAprByPeriod",
|
|
2421
|
-
* args: { periodStart: S.int32, periodEnd: S.int32 },
|
|
2422
|
-
* output: S.array(defineType("MarketApr", { marketAddress: S.string })),
|
|
2423
|
-
* timeoutMs: 30_000,
|
|
2424
|
-
* handler: async ({ args, db }) => db.find("MarketInfo"),
|
|
2425
|
-
* });
|
|
2426
|
-
* ```
|
|
2427
|
-
*/
|
|
2428
|
-
export function createResolver<
|
|
2429
|
-
// Both are schemas at runtime: `createResolver` reads `output.t` and walks
|
|
2430
|
-
// every argument with `toGraphQLType` while the module is being imported, so
|
|
2431
|
-
// anything else fails at indexer startup rather than in the editor.
|
|
2432
|
-
AS extends Record<string, Sury.Schema<unknown>>,
|
|
2433
|
-
OS extends Sury.Schema<unknown>,
|
|
2434
|
-
A = UnknownToOutput<AS>,
|
|
2435
|
-
O = UnknownToOutput<OS>,
|
|
2436
|
-
// A hack to enforce that the inferred return type matches the output schema.
|
|
2437
|
-
R extends O = O
|
|
2438
|
-
>(options: {
|
|
2439
|
-
/** The GraphQL field name. Must not collide with a generated one. */
|
|
2440
|
-
readonly name: string;
|
|
2441
|
-
/** Shown in the schema, for the people querying it. */
|
|
2442
|
-
readonly description?: string;
|
|
2443
|
-
/** Argument schemas, keyed by argument name. */
|
|
2444
|
-
readonly args?: AS;
|
|
2445
|
-
/** The result schema. Determines the field's GraphQL type. */
|
|
2446
|
-
readonly output: OS;
|
|
2447
|
-
/** Register the field on the admin schema only: it stays out of public
|
|
2448
|
-
* introspection and is unexecutable without the admin secret. */
|
|
2449
|
-
readonly admin?: boolean;
|
|
2450
|
-
/** The `statement_timeout` every query this resolver runs is bounded by.
|
|
2451
|
-
* Required: it is the only thing bounding a runaway query. */
|
|
2452
|
-
readonly timeoutMs: number;
|
|
2453
|
-
readonly handler: (args: ResolverHandlerArgs<A>) => Promise<R>;
|
|
2454
|
-
}): Resolver<A, O>;
|
|
2455
|
-
|
|
2456
|
-
/**
|
|
2457
|
-
* Thrown by a resolver to put a specific error on the client's response.
|
|
2458
|
-
*
|
|
2459
|
-
* Anything else a handler throws is reported as an internal failure with its
|
|
2460
|
-
* message withheld — a driver error can carry a connection string, and the
|
|
2461
|
-
* caller is the public internet — so this is how a resolver says more than
|
|
2462
|
-
* that. envio-serve carries the extensions through unchanged.
|
|
2463
|
-
*
|
|
2464
|
-
* ```ts
|
|
2465
|
-
* throw new ResolverError("Service is syncing", {
|
|
2466
|
-
* code: "SERVICE_UNAVAILABLE",
|
|
2467
|
-
* httpStatus: 503,
|
|
2468
|
-
* });
|
|
2469
|
-
* ```
|
|
2470
|
-
*/
|
|
2471
|
-
export declare class ResolverError extends Error {
|
|
2472
|
-
constructor(
|
|
2473
|
-
message: string,
|
|
2474
|
-
options?: {
|
|
2475
|
-
/** Becomes `extensions.code`. Defaults to `"INTERNAL_SERVER_ERROR"`. */
|
|
2476
|
-
readonly code?: string;
|
|
2477
|
-
/** Becomes `extensions.http.status`. */
|
|
2478
|
-
readonly httpStatus?: number;
|
|
2479
|
-
/** Merged into `extensions` alongside `code`. */
|
|
2480
|
-
readonly extensions?: Record<string, unknown>;
|
|
2481
|
-
}
|
|
2482
|
-
);
|
|
2483
|
-
readonly code: string;
|
|
2484
|
-
readonly httpStatus?: number;
|
|
2485
|
-
readonly extensions?: Record<string, unknown>;
|
|
2486
|
-
}
|
|
2487
|
-
|
|
2488
|
-
/** Names a schema so it can appear in the GraphQL schema as an object type. */
|
|
2489
|
-
export function defineType<F extends Record<string, unknown>>(
|
|
2490
|
-
name: string,
|
|
2491
|
-
fields: F
|
|
2492
|
-
): Sury.Schema<UnknownToOutput<F>>;
|
|
2493
|
-
|
|
2494
|
-
/**
|
|
2495
|
-
* Names a schema that appears in an argument.
|
|
2496
|
-
*
|
|
2497
|
-
* GraphQL keeps input and output types in a separate namespace from object
|
|
2498
|
-
* types, so a `where` argument is declared with this rather than with
|
|
2499
|
-
* {@link defineType}.
|
|
2500
|
-
*/
|
|
2501
|
-
export function defineInput<F extends Record<string, unknown>>(
|
|
2502
|
-
name: string,
|
|
2503
|
-
fields: F
|
|
2504
|
-
): Sury.Schema<UnknownToOutput<F>>;
|
|
2505
|
-
|
|
2506
|
-
/** Every resolver declared so far, in declaration order. */
|
|
2507
|
-
export function getRegisteredResolvers(): readonly Resolver<unknown, unknown>[];
|
|
2508
|
-
|
|
2509
|
-
/** The manifest and SDL for everything declared so far. */
|
|
2510
|
-
export function buildRegisteredManifest(): { manifest: unknown; sdl: string };
|
|
2511
|
-
|
|
2512
|
-
/** Names a schema representing a GraphQL enum. */
|
|
2513
|
-
export function defineEnum<const V extends readonly string[]>(
|
|
2514
|
-
name: string,
|
|
2515
|
-
values: V
|
|
2516
|
-
): Sury.Schema<V[number]>;
|
|
2517
|
-
|
|
2518
|
-
/** Names a schema representing a custom GraphQL scalar, such as `BigInt`. */
|
|
2519
|
-
export function defineScalar<T>(
|
|
2520
|
-
name: string,
|
|
2521
|
-
schema: Sury.Schema<T>
|
|
2522
|
-
): Sury.Schema<T>;
|
|
2523
|
-
|
|
2524
2286
|
// ============== Runtime values ==============
|
|
2525
2287
|
|
|
2526
2288
|
/** The indexer instance. Register handlers with `indexer.onEvent`,
|
package/index.js
CHANGED
|
@@ -9,16 +9,6 @@ import { schema as bigDecimalSchema } from "./src/bindings/BigDecimal.res.mjs";
|
|
|
9
9
|
|
|
10
10
|
export * from "./src/Envio.res.mjs";
|
|
11
11
|
export { indexer, createTestIndexer } from "./src/Api.res.mjs";
|
|
12
|
-
export {
|
|
13
|
-
createResolver,
|
|
14
|
-
defineType,
|
|
15
|
-
defineInput,
|
|
16
|
-
defineEnum,
|
|
17
|
-
defineScalar,
|
|
18
|
-
getRegisteredResolvers,
|
|
19
|
-
buildRegisteredManifest,
|
|
20
|
-
ResolverError,
|
|
21
|
-
} from "./src/resolvers/index.js";
|
|
22
12
|
export { default as BigDecimal } from "bignumber.js";
|
|
23
13
|
|
|
24
14
|
// Important! Should match the index.d.ts file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "envio",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.10.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A latency and sync speed optimized, developer friendly blockchain data indexer.",
|
|
6
6
|
"bin": "./bin.mjs",
|
|
@@ -68,10 +68,10 @@
|
|
|
68
68
|
"tsx": "4.21.0"
|
|
69
69
|
},
|
|
70
70
|
"optionalDependencies": {
|
|
71
|
-
"envio-linux-x64": "3.
|
|
72
|
-
"envio-linux-x64-musl": "3.
|
|
73
|
-
"envio-linux-arm64": "3.
|
|
74
|
-
"envio-darwin-x64": "3.
|
|
75
|
-
"envio-darwin-arm64": "3.
|
|
71
|
+
"envio-linux-x64": "3.10.0",
|
|
72
|
+
"envio-linux-x64-musl": "3.10.0",
|
|
73
|
+
"envio-linux-arm64": "3.10.0",
|
|
74
|
+
"envio-darwin-x64": "3.10.0",
|
|
75
|
+
"envio-darwin-arm64": "3.10.0"
|
|
76
76
|
}
|
|
77
77
|
}
|
package/src/Bin.res
CHANGED
|
@@ -18,13 +18,11 @@ type startCmd = {
|
|
|
18
18
|
}
|
|
19
19
|
type migrateCmd = {reset: bool, config: JSON.t}
|
|
20
20
|
type dropSchemaCmd = {config: JSON.t}
|
|
21
|
-
type resolversCmd = {mode: string, cwd: string, env: dict<JSON.t>, config: JSON.t}
|
|
22
21
|
|
|
23
22
|
type command =
|
|
24
23
|
| Start(startCmd)
|
|
25
24
|
| Migrate(migrateCmd)
|
|
26
25
|
| DropSchema(dropSchemaCmd)
|
|
27
|
-
| Resolvers(resolversCmd)
|
|
28
26
|
|
|
29
27
|
let decodeCommand = (json: JSON.t): command => {
|
|
30
28
|
let obj = switch json->JSON.Decode.object {
|
|
@@ -39,7 +37,6 @@ let decodeCommand = (json: JSON.t): command => {
|
|
|
39
37
|
| "start" => Start(json->(Utils.magic: JSON.t => startCmd))
|
|
40
38
|
| "migrate" => Migrate(json->(Utils.magic: JSON.t => migrateCmd))
|
|
41
39
|
| "drop-schema" => DropSchema(json->(Utils.magic: JSON.t => dropSchemaCmd))
|
|
42
|
-
| "resolvers" => Resolvers(json->(Utils.magic: JSON.t => resolversCmd))
|
|
43
40
|
| other => JsError.throwWithMessage(`Unknown command kind: ${other}`)
|
|
44
41
|
}
|
|
45
42
|
}
|
|
@@ -64,12 +61,6 @@ let run = async args => {
|
|
|
64
61
|
Config.prime(config)
|
|
65
62
|
processChdir(cwd)
|
|
66
63
|
applyEnv(env)
|
|
67
|
-
// `envio dev` only — see ResolverProcess.startForDev. A deployment
|
|
68
|
-
// runs the resolvers as their own Deployment, never from here.
|
|
69
|
-
let loaded = Config.load()
|
|
70
|
-
if loaded.isDev {
|
|
71
|
-
let _ = await ResolverProcess.startForDev(~config=loaded, ~projectRoot=cwd)
|
|
72
|
-
}
|
|
73
64
|
await Main.start(~reset)
|
|
74
65
|
| Migrate({reset, config}) =>
|
|
75
66
|
Config.prime(config)
|
|
@@ -77,44 +68,6 @@ let run = async args => {
|
|
|
77
68
|
| DropSchema({config}) =>
|
|
78
69
|
Config.prime(config)
|
|
79
70
|
await Main.dropSchema()
|
|
80
|
-
| Resolvers({mode, cwd, env, config}) =>
|
|
81
|
-
Config.prime(config)
|
|
82
|
-
processChdir(cwd)
|
|
83
|
-
applyEnv(env)
|
|
84
|
-
switch mode {
|
|
85
|
-
| "manifest" => await ResolverProcess.writeManifest(~config=Config.load(), ~projectRoot=cwd)
|
|
86
|
-
| "metadata" =>
|
|
87
|
-
let handlerUrl = switch Env.Resolvers.publicUrl() {
|
|
88
|
-
| Some(url) => url
|
|
89
|
-
| None =>
|
|
90
|
-
JsError.throwWithMessage(
|
|
91
|
-
"ENVIO_RESOLVERS_PUBLIC_URL is not set. It is the URL Hasura posts to and is baked into every action, so the metadata cannot be printed without it.",
|
|
92
|
-
)
|
|
93
|
-
}
|
|
94
|
-
let metadata = await ResolverProcess.metadataJson(
|
|
95
|
-
~config=Config.load(),
|
|
96
|
-
~projectRoot=cwd,
|
|
97
|
-
~handlerUrl,
|
|
98
|
-
)
|
|
99
|
-
// stdout, so it pipes into `hasura metadata apply` or `jq` rather
|
|
100
|
-
// than being buried in the log stream.
|
|
101
|
-
Console.log(JSON.stringify(metadata, ~space=2))
|
|
102
|
-
| "migrate" =>
|
|
103
|
-
let {applied, reasons} = await ResolverProcess.migrate(
|
|
104
|
-
~config=Config.load(),
|
|
105
|
-
~projectRoot=cwd,
|
|
106
|
-
)
|
|
107
|
-
Logging.info(
|
|
108
|
-
applied
|
|
109
|
-
? `Updated Hasura to match these resolvers: ${reasons->Array.join("; ")}`
|
|
110
|
-
: "Hasura already matches these resolvers; nothing to update",
|
|
111
|
-
)
|
|
112
|
-
// Serving keeps the event loop alive on its own, so returning here
|
|
113
|
-
// leaves the process running rather than exiting.
|
|
114
|
-
| _ =>
|
|
115
|
-
let running = await ResolverProcess.serve(~config=Config.load(), ~projectRoot=cwd)
|
|
116
|
-
running->ResolverProcess.handleSignals
|
|
117
|
-
}
|
|
118
71
|
}
|
|
119
72
|
}
|
|
120
73
|
} catch {
|
package/src/Bin.res.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
|
-
import * as Env from "./Env.res.mjs";
|
|
4
3
|
import * as Core from "./Core.res.mjs";
|
|
5
4
|
import * as Main from "./Main.res.mjs";
|
|
6
5
|
import * as Utils from "./Utils.res.mjs";
|
|
@@ -12,7 +11,6 @@ import * as Stdlib_JSON from "@rescript/runtime/lib/es6/Stdlib_JSON.js";
|
|
|
12
11
|
import * as Stdlib_JsExn from "@rescript/runtime/lib/es6/Stdlib_JsExn.js";
|
|
13
12
|
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
14
13
|
import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js";
|
|
15
|
-
import * as ResolverProcess from "./resolvers/ResolverProcess.res.mjs";
|
|
16
14
|
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
|
|
17
15
|
|
|
18
16
|
let setEnvVar = ((k, v) => { process.env[k] = v; });
|
|
@@ -38,11 +36,6 @@ function decodeCommand(json) {
|
|
|
38
36
|
TAG: "Migrate",
|
|
39
37
|
_0: json
|
|
40
38
|
};
|
|
41
|
-
case "resolvers" :
|
|
42
|
-
return {
|
|
43
|
-
TAG: "Resolvers",
|
|
44
|
-
_0: json
|
|
45
|
-
};
|
|
46
39
|
case "start" :
|
|
47
40
|
return {
|
|
48
41
|
TAG: "Start",
|
|
@@ -72,14 +65,9 @@ async function run(args) {
|
|
|
72
65
|
switch (match.TAG) {
|
|
73
66
|
case "Start" :
|
|
74
67
|
let match$1 = match._0;
|
|
75
|
-
let cwd = match$1.cwd;
|
|
76
68
|
Config.prime(match$1.config);
|
|
77
|
-
process.chdir(cwd);
|
|
69
|
+
process.chdir(match$1.cwd);
|
|
78
70
|
applyEnv(match$1.env);
|
|
79
|
-
let loaded = Config.load();
|
|
80
|
-
if (loaded.isDev) {
|
|
81
|
-
await ResolverProcess.startForDev(loaded, cwd);
|
|
82
|
-
}
|
|
83
71
|
return await Main.start(undefined, match$1.reset, undefined, undefined, undefined);
|
|
84
72
|
case "Migrate" :
|
|
85
73
|
let match$2 = match._0;
|
|
@@ -88,27 +76,6 @@ async function run(args) {
|
|
|
88
76
|
case "DropSchema" :
|
|
89
77
|
Config.prime(match._0.config);
|
|
90
78
|
return await Main.dropSchema();
|
|
91
|
-
case "Resolvers" :
|
|
92
|
-
let match$3 = match._0;
|
|
93
|
-
let cwd$1 = match$3.cwd;
|
|
94
|
-
Config.prime(match$3.config);
|
|
95
|
-
process.chdir(cwd$1);
|
|
96
|
-
applyEnv(match$3.env);
|
|
97
|
-
switch (match$3.mode) {
|
|
98
|
-
case "manifest" :
|
|
99
|
-
return await ResolverProcess.writeManifest(Config.load(), cwd$1);
|
|
100
|
-
case "metadata" :
|
|
101
|
-
let url = Env.Resolvers.publicUrl();
|
|
102
|
-
let handlerUrl = url !== undefined ? url : Stdlib_JsError.throwWithMessage("ENVIO_RESOLVERS_PUBLIC_URL is not set. It is the URL Hasura posts to and is baked into every action, so the metadata cannot be printed without it.");
|
|
103
|
-
let metadata = await ResolverProcess.metadataJson(Config.load(), cwd$1, handlerUrl);
|
|
104
|
-
console.log(JSON.stringify(metadata, undefined, 2));
|
|
105
|
-
return;
|
|
106
|
-
case "migrate" :
|
|
107
|
-
let match$4 = await ResolverProcess.migrate(Config.load(), cwd$1);
|
|
108
|
-
return Logging.info(match$4.applied ? `Updated Hasura to match these resolvers: ` + match$4.reasons.join("; ") : "Hasura already matches these resolvers; nothing to update");
|
|
109
|
-
default:
|
|
110
|
-
return ResolverProcess.handleSignals(await ResolverProcess.serve(Config.load(), cwd$1, undefined, undefined, undefined, undefined));
|
|
111
|
-
}
|
|
112
79
|
}
|
|
113
80
|
} catch (raw_exn) {
|
|
114
81
|
let exn = Primitive_exceptions.internalToException(raw_exn);
|