UNPKG

7.59 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.Manifest = void 0;
4const zod_1 = require("zod");
5// https://github.com/graphprotocol/graph-node/blob/master/docs/subgraph-manifest.md#14-schema
6const Schema = zod_1.z.object({
7 file: zod_1.z.string().describe('The path of the GraphQL IDL file, either local or on IPFS.'),
8});
9// https://github.com/graphprotocol/graph-node/blob/master/docs/subgraph-manifest.md#151-ethereumcontractsource
10const EthereumContractSource = zod_1.z.object({
11 address: zod_1.z.string(),
12 abi: zod_1.z.string(),
13 startBlock: zod_1.z.union([zod_1.z.bigint(), zod_1.z.number()]).optional(),
14});
15// https://github.com/graphprotocol/graph-node/blob/master/docs/subgraph-manifest.md#151-ethereumcontractsource
16const EthereumTemplateContractSource = zod_1.z.object({
17 abi: zod_1.z.string(),
18 startBlock: zod_1.z.union([zod_1.z.bigint(), zod_1.z.number()]).optional(),
19});
20// https://github.com/graphprotocol/graph-node/blob/master/docs/subgraph-manifest.md#1522-eventhandler
21const EventHandler = zod_1.z.object({
22 event: zod_1.z
23 .string()
24 .describe('An identifier for an event that will be handled in the mapping script. For Ethereum contracts, this must be the full event signature to distinguish from events that may share the same name. No alias types can be used.'),
25 handler: zod_1.z
26 .string()
27 .describe('The name of an exported function in the mapping script that should handle the specified event.'),
28 topic0: zod_1.z
29 .string()
30 .optional()
31 .describe('A 0x prefixed hex string. If provided, events whose topic0 is equal to this value will be processed by the given handler. When topic0 is provided, only the topic0 value will be matched, and not the hash of the event signature. This is useful for processing anonymous events in Solidity, which can have their topic0 set to anything. By default, topic0 is equal to the hash of the event signature.'),
32});
33// https://github.com/graphprotocol/graph-node/blob/master/docs/subgraph-manifest.md#1523-callhandler
34const CallHandler = zod_1.z.object({
35 function: zod_1.z
36 .string()
37 .describe('An identifier for a function that will be handled in the mapping script. For Ethereum contracts, this is the normalized function signature to filter calls by.'),
38 handler: zod_1.z
39 .string()
40 .describe('The name of an exported function in the mapping script that should handle the specified event.'),
41});
42// https://github.com/graphprotocol/graph-node/blob/master/docs/subgraph-manifest.md#15241-blockhandlerfilter
43const BlockHandlerFilter = zod_1.z.object({
44 kind: zod_1.z.literal('call').describe('The selected block handler filter.'),
45});
46// https://github.com/graphprotocol/graph-node/blob/master/docs/subgraph-manifest.md#1524-blockhandler
47const BlockHandler = zod_1.z.object({
48 handler: zod_1.z
49 .string()
50 .describe('The name of an exported function in the mapping script that should handle the specified event.'),
51 filter: BlockHandlerFilter.optional().describe('Definition of the filter to apply. If none is supplied, the handler will be called on every block.'),
52});
53// https://github.com/graphprotocol/graph-node/blob/master/docs/subgraph-manifest.md#1521-ethereum-mapping
54const EthereumMapping = zod_1.z.object({
55 kind: zod_1.z
56 .literal('ethereum/events')
57 .describe('Must be "ethereum/events" for Ethereum Events Mapping.'),
58 apiVersion: zod_1.z
59 .string()
60 .describe('Semver string of the version of the Mappings API that will be used by the mapping script.'),
61 language: zod_1.z
62 .literal('wasm/assemblyscript')
63 .describe('The language of the runtime for the Mapping API.'),
64 entities: zod_1.z
65 .array(zod_1.z.string())
66 .describe('A list of entities that will be ingested as part of this mapping. Must correspond to names of entities in the GraphQL IDL.'),
67 eventHandlers: zod_1.z
68 .array(EventHandler)
69 .optional()
70 .describe('Handlers for specific events, which will be defined in the mapping script.'),
71 callHandlers: zod_1.z
72 .array(CallHandler)
73 .optional()
74 .describe('A list of functions that will trigger a handler and the name of the corresponding handlers in the mapping.'),
75 blockHandlers: zod_1.z
76 .array(BlockHandler)
77 .optional()
78 .describe('Defines block filters and handlers to process matching blocks.'),
79 file: zod_1.z.string().describe('The path of the mapping script.'),
80});
81// https://github.com/graphprotocol/graph-node/blob/master/docs/subgraph-manifest.md#152-mapping
82const Mapping = EthereumMapping;
83// https://github.com/graphprotocol/graph-node/blob/master/docs/subgraph-manifest.md#15-data-source
84const DataSource = zod_1.z.object({
85 kind: zod_1.z.string().describe('The type of data source. Possible values: ethereum/contract.'),
86 name: zod_1.z
87 .string()
88 .describe('The name of the source data. Will be used to generate APIs in the mapping and also for self-documentation purposes.'),
89 network: zod_1.z
90 .string()
91 .describe('For blockchains, this describes which network the subgraph targets'),
92 source: EthereumContractSource.describe('The source data on a blockchain such as Ethereum.'),
93 mapping: Mapping.describe('The mapping that defines how to ingest the data.'),
94});
95// https://github.com/graphprotocol/graph-node/blob/master/docs/subgraph-manifest.md#17-data-source-templates
96const TemplateSource = zod_1.z.object({
97 kind: zod_1.z.string().describe('The type of data source. Possible values: ethereum/contract.'),
98 name: zod_1.z
99 .string()
100 .describe('The name of the source data. Will be used to generate APIs in the mapping and also for self-documentation purposes.'),
101 network: zod_1.z
102 .string()
103 .describe('For blockchains, this describes which network the subgraph targets'),
104 source: EthereumTemplateContractSource.describe('The source data on a blockchain such as Ethereum.'),
105 mapping: Mapping.describe('The mapping that defines how to ingest the data.'),
106});
107// https://github.com/graphprotocol/graph-node/blob/master/docs/subgraph-manifest.md#18-graft-base
108const GraftBase = zod_1.z.object({
109 base: zod_1.z.string().describe('The subgraph ID of the base subgraph'),
110 block: zod_1.z.bigint().describe('The block number up to which to use data from the base subgraph'),
111});
112// https://github.com/graphprotocol/graph-node/blob/master/docs/subgraph-manifest.md#13-top-level-api
113exports.Manifest = zod_1.z.object({
114 specVersion: zod_1.z
115 .string()
116 .describe('A Semver version indicating which version of this API is being used.'),
117 schema: Schema.describe('The GraphQL schema of this subgraph.'),
118 description: zod_1.z.string().describe("An optional description of the subgraph's purpose.").optional(),
119 repository: zod_1.z.string().describe('An optional link to where the subgraph lives.').optional(),
120 graft: GraftBase.describe('An optional base to graft onto.').optional(),
121 dataSources: zod_1.z
122 .array(DataSource)
123 .describe("Each data source spec defines the data that will be ingested as well as the transformation logic to derive the state of the subgraph's entities based on the source data."),
124 templates: zod_1.z
125 .array(TemplateSource)
126 .optional()
127 .describe('Each data source template defines a data source that can be created dynamically from the mappings.'),
128});
129
\No newline at end of file