@graphprotocol/graph-cli 0.37.3-alpha-20230110164921-a0dbdfc → 0.37.3-alpha-20230111114757-a72d102

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/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @graphprotocol/graph-cli
2
2
 
3
- ## 0.37.3-alpha-20230110164921-a0dbdfc
3
+ ## 0.37.3-alpha-20230111114757-a72d102
4
4
 
5
5
  ### Patch Changes
6
6
 
@@ -31,8 +31,7 @@ const immutable_1 = __importDefault(require("immutable"));
31
31
  const path_1 = __importDefault(require("path"));
32
32
  const prettier_1 = __importDefault(require("prettier"));
33
33
  const graphql = __importStar(require("graphql/language"));
34
- const chalk_1 = __importDefault(require("chalk"));
35
- const toolbox = __importStar(require("gluegun/toolbox"));
34
+ const toolbox = __importStar(require("gluegun"));
36
35
  const schema_1 = __importDefault(require("./schema"));
37
36
  const subgraph_1 = __importDefault(require("./subgraph"));
38
37
  const template_1 = __importDefault(require("./codegen/template"));
@@ -41,15 +40,20 @@ const spinner_1 = require("./command-helpers/spinner");
41
40
  const migrations_1 = require("./migrations");
42
41
  const typescript_1 = require("./codegen/typescript");
43
42
  const fs_1 = require("./command-helpers/fs");
43
+ // @ts-expect-error TODO: type out if necessary
44
44
  const Index_bs_js_1 = __importDefault(require("@float-capital/float-subgraph-uncrashable/src/Index.bs.js"));
45
45
  class TypeGenerator {
46
+ sourceDir;
47
+ options;
48
+ protocol;
49
+ protocolTypeGenerator;
46
50
  constructor(options) {
47
- this.options = options || {};
51
+ this.options = options;
48
52
  this.sourceDir =
49
53
  this.options.sourceDir ||
50
54
  (this.options.subgraphManifest && path_1.default.dirname(this.options.subgraphManifest));
51
55
  this.protocol = this.options.protocol;
52
- this.protocolTypeGenerator = this.protocol.getTypeGenerator({
56
+ this.protocolTypeGenerator = this.protocol?.getTypeGenerator?.({
53
57
  sourceDir: this.sourceDir,
54
58
  outputDir: this.options.outputDir,
55
59
  });
@@ -104,11 +108,11 @@ class TypeGenerator {
104
108
  if (quiet) {
105
109
  return this.options.subgraph
106
110
  ? this.options.subgraph
107
- : subgraph_1.default.load(this.options.subgraphManifest, subgraphLoadOptions).result;
111
+ : (await subgraph_1.default.load(this.options.subgraphManifest, subgraphLoadOptions)).result;
108
112
  }
109
113
  else {
110
114
  const manifestPath = (0, fs_1.displayPath)(this.options.subgraphManifest);
111
- return await (0, spinner_1.withSpinner)(`Load subgraph from ${manifestPath}`, `Failed to load subgraph from ${manifestPath}`, `Warnings while loading subgraph from ${manifestPath}`, async (spinner) => {
115
+ return await (0, spinner_1.withSpinner)(`Load subgraph from ${manifestPath}`, `Failed to load subgraph from ${manifestPath}`, `Warnings while loading subgraph from ${manifestPath}`, async (_spinner) => {
112
116
  return this.options.subgraph
113
117
  ? this.options.subgraph
114
118
  : subgraph_1.default.load(this.options.subgraphManifest, subgraphLoadOptions);
@@ -118,8 +122,7 @@ class TypeGenerator {
118
122
  async loadSchema(subgraph) {
119
123
  let maybeRelativePath = subgraph.getIn(['schema', 'file']);
120
124
  let absolutePath = path_1.default.resolve(this.sourceDir, maybeRelativePath);
121
- return await (0, spinner_1.withSpinner)(`Load GraphQL schema from ${(0, fs_1.displayPath)(absolutePath)}`, `Failed to load GraphQL schema from ${(0, fs_1.displayPath)(absolutePath)}`, `Warnings while loading GraphQL schema from ${(0, fs_1.displayPath)(absolutePath)}`, async (spinner) => {
122
- let maybeRelativePath = subgraph.getIn(['schema', 'file']);
125
+ return await (0, spinner_1.withSpinner)(`Load GraphQL schema from ${(0, fs_1.displayPath)(absolutePath)}`, `Failed to load GraphQL schema from ${(0, fs_1.displayPath)(absolutePath)}`, `Warnings while loading GraphQL schema from ${(0, fs_1.displayPath)(absolutePath)}`, async (_spinner) => {
123
126
  let absolutePath = path_1.default.resolve(this.sourceDir, maybeRelativePath);
124
127
  return schema_1.default.load(absolutePath);
125
128
  });
@@ -176,8 +179,8 @@ class TypeGenerator {
176
179
  // Add the GraphQL schema to the watched files
177
180
  files.push(subgraph.getIn(['schema', 'file']));
178
181
  // Add all file paths specified in manifest
179
- subgraph.get('dataSources').map(dataSource => {
180
- dataSource.getIn(['mapping', 'abis']).map(abi => {
182
+ subgraph.get('dataSources').map((dataSource) => {
183
+ dataSource.getIn(['mapping', 'abis']).map((abi) => {
181
184
  files.push(abi.get('file'));
182
185
  });
183
186
  });
@@ -22,7 +22,7 @@ const validateContractValues = (manifest, protocol) => {
22
22
  const fieldName = ProtocolContract.identifierName();
23
23
  return manifest
24
24
  .get('dataSources')
25
- .filter(dataSource => protocol.isValidKindName(dataSource.get('kind')))
25
+ .filter((dataSource) => protocol.isValidKindName(dataSource.get('kind')))
26
26
  .reduce((errors, dataSource, dataSourceIndex) => {
27
27
  let path = ['dataSources', dataSourceIndex, 'source', fieldName];
28
28
  // No need to validate if the source has no contract field
@@ -30,7 +30,7 @@ const validateContractValues = (manifest, protocol) => {
30
30
  return errors;
31
31
  }
32
32
  let contractValue = dataSource.getIn(['source', fieldName]);
33
- const { valid, error } = validateContract(contractValue, ProtocolContract);
33
+ const { valid, error } = (0, exports.validateContract)(contractValue, ProtocolContract);
34
34
  // Validate whether the contract is valid for the protocol
35
35
  if (valid) {
36
36
  return errors;
@@ -13,11 +13,11 @@ const Map = immutable_1.default.Map;
13
13
  /**
14
14
  * Returns a user-friendly type name for a value.
15
15
  */
16
- const typeName = value => List.isList(value) ? 'list' : Map.isMap(value) ? 'map' : typeof value;
16
+ const typeName = (value) => List.isList(value) ? 'list' : Map.isMap(value) ? 'map' : typeof value;
17
17
  /**
18
18
  * Converts an immutable or plain JavaScript value to a YAML string.
19
19
  */
20
- const toYAML = x => js_yaml_1.default
20
+ const toYAML = (x) => js_yaml_1.default
21
21
  .safeDump(typeName(x) === 'list' || typeName(x) === 'map' ? x.toJS() : x, {
22
22
  indent: 2,
23
23
  })
@@ -28,7 +28,7 @@ const toYAML = x => js_yaml_1.default
28
28
  const getFieldType = (type, fieldName) => {
29
29
  let fieldDef = type
30
30
  .get('fields')
31
- .find(field => field.getIn(['name', 'value']) === fieldName);
31
+ .find((field) => field.getIn(['name', 'value']) === fieldName);
32
32
  return fieldDef !== undefined ? fieldDef.get('type') : undefined;
33
33
  };
34
34
  /**
@@ -39,7 +39,7 @@ const resolveType = (schema, type) => type.has('type')
39
39
  : type.get('kind') === 'NamedType'
40
40
  ? schema
41
41
  .get('definitions')
42
- .find(def => def.getIn(['name', 'value']) === type.getIn(['name', 'value']))
42
+ .find((def) => def.getIn(['name', 'value']) === type.getIn(['name', 'value']))
43
43
  : 'resolveType: unimplemented';
44
44
  /**
45
45
  * A map of supported validators.
@@ -58,7 +58,7 @@ const validators = immutable_1.default.fromJS({
58
58
  errors = errors.push(variantErrors);
59
59
  }
60
60
  // Return errors from variant that matched the most
61
- return List(errors.minBy(variantErrors => variantErrors.count()));
61
+ return List(errors.minBy((variantErrors) => variantErrors.count()));
62
62
  },
63
63
  NamedType: (value, ctx) => validateValue(value, ctx.update('type', type => resolveType(ctx.get('schema'), type))),
64
64
  NonNullType: (value, ctx) => value !== null && value !== undefined
@@ -83,12 +83,12 @@ const validators = immutable_1.default.fromJS({
83
83
  return Map.isMap(value)
84
84
  ? ctx
85
85
  .getIn(['type', 'fields'])
86
- .map(fieldDef => fieldDef.getIn(['name', 'value']))
86
+ .map((fieldDef) => fieldDef.getIn(['name', 'value']))
87
87
  .concat(value.keySeq())
88
88
  .toSet()
89
89
  .reduce((errors, key) => getFieldType(ctx.get('type'), key)
90
90
  ? errors.concat(validateValue(value.get(key), ctx
91
- .update('path', path => path.push(key))
91
+ .update('path', (path) => path.push(key))
92
92
  .set('type', getFieldType(ctx.get('type'), key))))
93
93
  : errors.push(key == 'templates' && ctx.get('protocol').hasTemplates()
94
94
  ? immutable_1.default.fromJS({
@@ -109,7 +109,7 @@ const validators = immutable_1.default.fromJS({
109
109
  ]);
110
110
  },
111
111
  EnumTypeDefinition: (value, ctx) => {
112
- const enumValues = ctx.getIn(['type', 'values']).map(v => {
112
+ const enumValues = ctx.getIn(['type', 'values']).map((v) => {
113
113
  return v.getIn(['name', 'value']);
114
114
  });
115
115
  const allowedValues = enumValues.toArray().join(', ');
@@ -203,8 +203,8 @@ const validateValue = (value, ctx) => {
203
203
  // 'near-mainnet': ['contract3'],
204
204
  // },
205
205
  // }
206
- const dataSourceListToMap = dataSources => dataSources.reduce((protocolKinds, dataSource) => protocolKinds.update(protocols_1.default.normalizeName(dataSource.kind), networks => (networks || immutable_1.default.OrderedMap()).update(dataSource.network, dataSourceNames => (dataSourceNames || immutable_1.default.OrderedSet()).add(dataSource.name))), immutable_1.default.OrderedMap());
207
- const validateDataSourceProtocolAndNetworks = value => {
206
+ const dataSourceListToMap = (dataSources) => dataSources.reduce((protocolKinds, dataSource) => protocolKinds.update(protocols_1.default.normalizeName(dataSource.kind), (networks) => (networks || immutable_1.default.OrderedMap()).update(dataSource.network, (dataSourceNames) => (dataSourceNames || immutable_1.default.OrderedSet()).add(dataSource.name))), immutable_1.default.OrderedMap());
207
+ const validateDataSourceProtocolAndNetworks = (value) => {
208
208
  const dataSources = [...value.dataSources, ...(value.templates || [])];
209
209
  const protocolNetworkMap = dataSourceListToMap(dataSources);
210
210
  if (protocolNetworkMap.size > 1) {
@@ -218,7 +218,7 @@ ${protocolNetworkMap
218
218
  : `Data sources and templates using '${protocolKind}'`}:\n${dataSourceNames
219
219
  .valueSeq()
220
220
  .flatten()
221
- .map(ds => ` - ${ds}`)
221
+ .map((ds) => ` - ${ds}`)
222
222
  .join('\n')}`)
223
223
  .join('\n')}
224
224
  Recommendation: Make all data sources and templates use the same protocol kind.`,
@@ -234,7 +234,7 @@ Recommendation: Make all data sources and templates use the same protocol kind.`
234
234
  ${networks
235
235
  .map((dataSources, network) => ` ${network === undefined
236
236
  ? 'Data sources and templates having no network set'
237
- : `Data sources and templates using '${network}'`}:\n${dataSources.map(ds => ` - ${ds}`).join('\n')}`)
237
+ : `Data sources and templates using '${network}'`}:\n${dataSources.map((ds) => ` - ${ds}`).join('\n')}`)
238
238
  .join('\n')}
239
239
  Recommendation: Make all data sources and templates use the same network name.`,
240
240
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphprotocol/graph-cli",
3
- "version": "0.37.3-alpha-20230110164921-a0dbdfc",
3
+ "version": "0.37.3-alpha-20230111114757-a72d102",
4
4
  "license": "(Apache-2.0 OR MIT)",
5
5
  "description": "CLI for building for and deploying to The Graph",
6
6
  "main": "dist/cli.js",
@@ -38,6 +38,7 @@
38
38
  "devDependencies": {
39
39
  "@types/debug": "^4.1.7",
40
40
  "@types/fs-extra": "^9.0.13",
41
+ "@types/js-yaml": "^3.12.7",
41
42
  "@types/which": "^2.0.1",
42
43
  "copyfiles": "^2.4.1",
43
44
  "jest": "26.0.0",
@@ -205,9 +205,9 @@ export default class Protocol {
205
205
  }
206
206
  }
207
207
 
208
- type ProtocolName = 'arweave' | 'ethereum' | 'near' | 'cosmos' | 'substreams'
208
+ export type ProtocolName = 'arweave' | 'ethereum' | 'near' | 'cosmos' | 'substreams'
209
209
 
210
- interface ProtocolConfig {
210
+ export interface ProtocolConfig {
211
211
  displayName: string
212
212
  abi?: any
213
213
  contract?: any
@@ -3,33 +3,51 @@ import immutable from 'immutable'
3
3
  import path from 'path'
4
4
  import prettier from 'prettier'
5
5
  import * as graphql from 'graphql/language'
6
- import chalk from 'chalk'
7
- import * as toolbox from 'gluegun/toolbox'
6
+ import * as toolbox from 'gluegun'
8
7
 
9
8
  import Schema from './schema'
10
9
  import Subgraph from './subgraph'
11
10
  import DataSourceTemplateCodeGenerator from './codegen/template'
12
11
  import Watcher from './watcher'
13
- import { step, withSpinner } from './command-helpers/spinner'
12
+ import { Spinner, step, withSpinner } from './command-helpers/spinner'
14
13
  import { applyMigrations } from './migrations'
15
14
  import { GENERATED_FILE_NOTE } from './codegen/typescript'
16
15
  import { displayPath } from './command-helpers/fs'
16
+ import Protocol from './protocols'
17
+
18
+ // @ts-expect-error TODO: type out if necessary
17
19
  import uncrashable from '@float-capital/float-subgraph-uncrashable/src/Index.bs.js'
18
20
 
21
+ interface TypeGeneratorOptions {
22
+ sourceDir?: string
23
+ subgraphManifest: string
24
+ subgraph?: string
25
+ protocol: Protocol
26
+ outputDir: string
27
+ skipMigrations?: boolean
28
+ uncrashable: any
29
+ uncrashableConfig: boolean
30
+ }
31
+
19
32
  export default class TypeGenerator {
20
- constructor(options) {
21
- this.options = options || {}
33
+ private sourceDir: string
34
+ private options: TypeGeneratorOptions
35
+ private protocol: Protocol
36
+ private protocolTypeGenerator: any
37
+
38
+ constructor(options: TypeGeneratorOptions) {
39
+ this.options = options
22
40
  this.sourceDir =
23
41
  this.options.sourceDir ||
24
42
  (this.options.subgraphManifest && path.dirname(this.options.subgraphManifest))
25
43
 
26
44
  this.protocol = this.options.protocol
27
- this.protocolTypeGenerator = this.protocol.getTypeGenerator({
45
+ this.protocolTypeGenerator = this.protocol?.getTypeGenerator?.({
28
46
  sourceDir: this.sourceDir,
29
47
  outputDir: this.options.outputDir,
30
48
  })
31
49
 
32
- process.on('uncaughtException', function (e) {
50
+ process.on('uncaughtException', function(e) {
33
51
  toolbox.print.error(`UNCAUGHT EXCEPTION: ${e}`)
34
52
  })
35
53
  }
@@ -77,7 +95,7 @@ export default class TypeGenerator {
77
95
  }
78
96
  }
79
97
 
80
- async generateUncrashableEntities(graphSchema) {
98
+ async generateUncrashableEntities(graphSchema: any) {
81
99
  let ast = graphql.parse(graphSchema.document)
82
100
  let entityDefinitions = ast['definitions']
83
101
  return await withSpinner(
@@ -102,7 +120,7 @@ export default class TypeGenerator {
102
120
  if (quiet) {
103
121
  return this.options.subgraph
104
122
  ? this.options.subgraph
105
- : Subgraph.load(this.options.subgraphManifest, subgraphLoadOptions).result
123
+ : (await Subgraph.load(this.options.subgraphManifest, subgraphLoadOptions)).result
106
124
  } else {
107
125
  const manifestPath = displayPath(this.options.subgraphManifest)
108
126
 
@@ -110,7 +128,7 @@ export default class TypeGenerator {
110
128
  `Load subgraph from ${manifestPath}`,
111
129
  `Failed to load subgraph from ${manifestPath}`,
112
130
  `Warnings while loading subgraph from ${manifestPath}`,
113
- async spinner => {
131
+ async _spinner => {
114
132
  return this.options.subgraph
115
133
  ? this.options.subgraph
116
134
  : Subgraph.load(this.options.subgraphManifest, subgraphLoadOptions)
@@ -119,22 +137,21 @@ export default class TypeGenerator {
119
137
  }
120
138
  }
121
139
 
122
- async loadSchema(subgraph) {
123
- let maybeRelativePath = subgraph.getIn(['schema', 'file'])
140
+ async loadSchema(subgraph: immutable.Map<any, any>) {
141
+ let maybeRelativePath = subgraph.getIn(['schema', 'file']) as string
124
142
  let absolutePath = path.resolve(this.sourceDir, maybeRelativePath)
125
143
  return await withSpinner(
126
144
  `Load GraphQL schema from ${displayPath(absolutePath)}`,
127
145
  `Failed to load GraphQL schema from ${displayPath(absolutePath)}`,
128
146
  `Warnings while loading GraphQL schema from ${displayPath(absolutePath)}`,
129
- async spinner => {
130
- let maybeRelativePath = subgraph.getIn(['schema', 'file'])
147
+ async _spinner => {
131
148
  let absolutePath = path.resolve(this.sourceDir, maybeRelativePath)
132
149
  return Schema.load(absolutePath)
133
150
  },
134
151
  )
135
152
  }
136
153
 
137
- async generateTypesForSchema(schema) {
154
+ async generateTypesForSchema(schema: any) {
138
155
  return await withSpinner(
139
156
  `Generate types for GraphQL schema`,
140
157
  `Failed to generate types for GraphQL schema`,
@@ -161,7 +178,7 @@ export default class TypeGenerator {
161
178
  )
162
179
  }
163
180
 
164
- async generateTypesForDataSourceTemplates(subgraph) {
181
+ async generateTypesForDataSourceTemplates(subgraph: immutable.Map<any, any>) {
165
182
  return await withSpinner(
166
183
  `Generate types for data source templates`,
167
184
  `Failed to generate types for data source templates`,
@@ -170,7 +187,7 @@ export default class TypeGenerator {
170
187
  // Combine the generated code for all templates
171
188
  let codeSegments = subgraph
172
189
  .get('templates', immutable.List())
173
- .reduce((codeSegments, template) => {
190
+ .reduce((codeSegments: any, template: any) => {
174
191
  step(
175
192
  spinner,
176
193
  'Generate types for data source template',
@@ -217,8 +234,8 @@ export default class TypeGenerator {
217
234
  files.push(subgraph.getIn(['schema', 'file']))
218
235
 
219
236
  // Add all file paths specified in manifest
220
- subgraph.get('dataSources').map(dataSource => {
221
- dataSource.getIn(['mapping', 'abis']).map(abi => {
237
+ subgraph.get('dataSources').map((dataSource: any) => {
238
+ dataSource.getIn(['mapping', 'abis']).map((abi: any) => {
222
239
  files.push(abi.get('file'))
223
240
  })
224
241
  })
@@ -232,7 +249,7 @@ export default class TypeGenerator {
232
249
 
233
250
  async watchAndGenerateTypes() {
234
251
  let generator = this
235
- let spinner
252
+ let spinner: Spinner
236
253
 
237
254
  // Create watcher and generate types once and then on every change to a watched file
238
255
  let watcher = new Watcher({
@@ -1,6 +1,7 @@
1
1
  import immutable from 'immutable'
2
+ import Protocol from '../protocols'
2
3
 
3
- const validateContract = (value, ProtocolContract) => {
4
+ export const validateContract = (value: any, ProtocolContract: any) => {
4
5
  const contract = new ProtocolContract(value)
5
6
 
6
7
  const { valid, error } = contract.validate()
@@ -15,15 +16,18 @@ const validateContract = (value, ProtocolContract) => {
15
16
  return { valid, error }
16
17
  }
17
18
 
18
- const validateContractValues = (manifest, protocol) => {
19
+ export const validateContractValues = (
20
+ manifest: immutable.Map<any, any>,
21
+ protocol: Protocol,
22
+ ) => {
19
23
  const ProtocolContract = protocol.getContract()
20
24
 
21
25
  const fieldName = ProtocolContract.identifierName()
22
26
 
23
27
  return manifest
24
28
  .get('dataSources')
25
- .filter(dataSource => protocol.isValidKindName(dataSource.get('kind')))
26
- .reduce((errors, dataSource, dataSourceIndex) => {
29
+ .filter((dataSource: any) => protocol.isValidKindName(dataSource.get('kind')))
30
+ .reduce((errors: any[], dataSource: any, dataSourceIndex: number) => {
27
31
  let path = ['dataSources', dataSourceIndex, 'source', fieldName]
28
32
 
29
33
  // No need to validate if the source has no contract field
@@ -48,5 +52,3 @@ const validateContractValues = (manifest, protocol) => {
48
52
  }
49
53
  }, immutable.List())
50
54
  }
51
-
52
- export { validateContract, validateContractValues }
@@ -10,13 +10,13 @@ const Map = immutable.Map
10
10
  /**
11
11
  * Returns a user-friendly type name for a value.
12
12
  */
13
- const typeName = value =>
13
+ const typeName = (value: immutable.Collection<unknown, unknown>) =>
14
14
  List.isList(value) ? 'list' : Map.isMap(value) ? 'map' : typeof value
15
15
 
16
16
  /**
17
17
  * Converts an immutable or plain JavaScript value to a YAML string.
18
18
  */
19
- const toYAML = x =>
19
+ const toYAML = (x: immutable.Collection<unknown, unknown>) =>
20
20
  yaml
21
21
  .safeDump(typeName(x) === 'list' || typeName(x) === 'map' ? x.toJS() : x, {
22
22
  indent: 2,
@@ -26,10 +26,10 @@ const toYAML = x =>
26
26
  /**
27
27
  * Looks up the type of a field in a GraphQL object type.
28
28
  */
29
- const getFieldType = (type, fieldName) => {
29
+ const getFieldType = (type: immutable.Map<any, any>, fieldName: string) => {
30
30
  let fieldDef = type
31
31
  .get('fields')
32
- .find(field => field.getIn(['name', 'value']) === fieldName)
32
+ .find((field: any) => field.getIn(['name', 'value']) === fieldName)
33
33
 
34
34
  return fieldDef !== undefined ? fieldDef.get('type') : undefined
35
35
  }
@@ -37,24 +37,29 @@ const getFieldType = (type, fieldName) => {
37
37
  /**
38
38
  * Resolves a type in the GraphQL schema.
39
39
  */
40
- const resolveType = (schema, type) =>
40
+ const resolveType = (
41
+ schema: immutable.Map<any, any>,
42
+ type: immutable.Map<any, any>,
43
+ ): any =>
41
44
  type.has('type')
42
45
  ? resolveType(schema, type.get('type'))
43
46
  : type.get('kind') === 'NamedType'
44
47
  ? schema
45
48
  .get('definitions')
46
- .find(def => def.getIn(['name', 'value']) === type.getIn(['name', 'value']))
49
+ .find(
50
+ (def: any) => def.getIn(['name', 'value']) === type.getIn(['name', 'value']),
51
+ )
47
52
  : 'resolveType: unimplemented'
48
53
 
49
54
  /**
50
55
  * A map of supported validators.
51
56
  */
52
57
  const validators = immutable.fromJS({
53
- ScalarTypeDefinition: (value, ctx) =>
54
- validators.get(ctx.getIn(['type', 'name', 'value']))(value, ctx),
58
+ ScalarTypeDefinition: (value: any, ctx: immutable.Map<any, any>) =>
59
+ (validators.get(ctx.getIn(['type', 'name', 'value'])) as any)(value, ctx),
55
60
 
56
- UnionTypeDefinition: (value, ctx) => {
57
- const unionVariants = ctx.getIn(['type', 'types'])
61
+ UnionTypeDefinition: (value: any, ctx: immutable.Map<any, any>) => {
62
+ const unionVariants = ctx.getIn(['type', 'types']) as any[]
58
63
 
59
64
  let errors = List()
60
65
 
@@ -68,16 +73,16 @@ const validators = immutable.fromJS({
68
73
  }
69
74
 
70
75
  // Return errors from variant that matched the most
71
- return List(errors.minBy(variantErrors => variantErrors.count()))
76
+ return List(errors.minBy((variantErrors: any) => variantErrors.count()) as any)
72
77
  },
73
78
 
74
- NamedType: (value, ctx) =>
79
+ NamedType: (value: any, ctx: immutable.Map<any, any>) =>
75
80
  validateValue(
76
81
  value,
77
82
  ctx.update('type', type => resolveType(ctx.get('schema'), type)),
78
83
  ),
79
84
 
80
- NonNullType: (value, ctx) =>
85
+ NonNullType: (value: any, ctx: immutable.Map<any, any>) =>
81
86
  value !== null && value !== undefined
82
87
  ? validateValue(
83
88
  value,
@@ -90,7 +95,7 @@ const validators = immutable.fromJS({
90
95
  },
91
96
  ]),
92
97
 
93
- ListType: (value, ctx) =>
98
+ ListType: (value: any, ctx: immutable.Map<any, any>) =>
94
99
  List.isList(value)
95
100
  ? value.reduce(
96
101
  (errors, value, i) =>
@@ -111,21 +116,21 @@ const validators = immutable.fromJS({
111
116
  },
112
117
  ]),
113
118
 
114
- ObjectTypeDefinition: (value, ctx) => {
119
+ ObjectTypeDefinition: (value: any, ctx: any) => {
115
120
  return Map.isMap(value)
116
121
  ? ctx
117
122
  .getIn(['type', 'fields'])
118
- .map(fieldDef => fieldDef.getIn(['name', 'value']))
123
+ .map((fieldDef: any) => fieldDef.getIn(['name', 'value']))
119
124
  .concat(value.keySeq())
120
125
  .toSet()
121
126
  .reduce(
122
- (errors, key) =>
127
+ (errors: any[], key: string) =>
123
128
  getFieldType(ctx.get('type'), key)
124
129
  ? errors.concat(
125
130
  validateValue(
126
131
  value.get(key),
127
132
  ctx
128
- .update('path', path => path.push(key))
133
+ .update('path', (path: string[]) => path.push(key))
129
134
  .set('type', getFieldType(ctx.get('type'), key)),
130
135
  ),
131
136
  )
@@ -153,8 +158,8 @@ const validators = immutable.fromJS({
153
158
  ])
154
159
  },
155
160
 
156
- EnumTypeDefinition: (value, ctx) => {
157
- const enumValues = ctx.getIn(['type', 'values']).map(v => {
161
+ EnumTypeDefinition: (value: any, ctx: immutable.Map<any, any>) => {
162
+ const enumValues = (ctx.getIn(['type', 'values']) as any).map((v: any) => {
158
163
  return v.getIn(['name', 'value'])
159
164
  })
160
165
 
@@ -170,7 +175,7 @@ const validators = immutable.fromJS({
170
175
  ])
171
176
  },
172
177
 
173
- String: (value, ctx) =>
178
+ String: (value: any, ctx: immutable.Map<any, any>) =>
174
179
  typeof value === 'string'
175
180
  ? List()
176
181
  : immutable.fromJS([
@@ -180,7 +185,7 @@ const validators = immutable.fromJS({
180
185
  },
181
186
  ]),
182
187
 
183
- BigInt: (value, ctx) =>
188
+ BigInt: (value: any, ctx: immutable.Map<any, any>) =>
184
189
  typeof value === 'number'
185
190
  ? List()
186
191
  : immutable.fromJS([
@@ -190,7 +195,7 @@ const validators = immutable.fromJS({
190
195
  },
191
196
  ]),
192
197
 
193
- File: (value, ctx) =>
198
+ File: (value: any, ctx: immutable.Map<any, any>) =>
194
199
  typeof value === 'string'
195
200
  ? require('fs').existsSync(ctx.get('resolveFile')(value))
196
201
  ? List()
@@ -207,7 +212,7 @@ const validators = immutable.fromJS({
207
212
  },
208
213
  ]),
209
214
 
210
- Boolean: (value, ctx) =>
215
+ Boolean: (value: any, ctx: immutable.Map<any, any>) =>
211
216
  typeof value === 'boolean'
212
217
  ? List()
213
218
  : immutable.fromJS([
@@ -220,9 +225,9 @@ const validators = immutable.fromJS({
220
225
  ]),
221
226
  })
222
227
 
223
- const validateValue = (value, ctx) => {
228
+ const validateValue = (value: any, ctx: immutable.Collection<any, any>) => {
224
229
  let kind = ctx.getIn(['type', 'kind'])
225
- let validator = validators.get(kind)
230
+ let validator = validators.get(kind) as any
226
231
 
227
232
  if (validator !== undefined) {
228
233
  // If the type is nullable, accept undefined and null; if the nullable
@@ -261,18 +266,20 @@ const validateValue = (value, ctx) => {
261
266
  // 'near-mainnet': ['contract3'],
262
267
  // },
263
268
  // }
264
- const dataSourceListToMap = dataSources =>
269
+ const dataSourceListToMap = (dataSources: any[]) =>
265
270
  dataSources.reduce(
266
271
  (protocolKinds, dataSource) =>
267
- protocolKinds.update(Protocol.normalizeName(dataSource.kind), networks =>
268
- (networks || immutable.OrderedMap()).update(dataSource.network, dataSourceNames =>
269
- (dataSourceNames || immutable.OrderedSet()).add(dataSource.name),
272
+ protocolKinds.update(Protocol.normalizeName(dataSource.kind), (networks: any) =>
273
+ (networks || immutable.OrderedMap()).update(
274
+ dataSource.network,
275
+ (dataSourceNames: any) =>
276
+ (dataSourceNames || immutable.OrderedSet()).add(dataSource.name),
270
277
  ),
271
278
  ),
272
279
  immutable.OrderedMap(),
273
280
  )
274
281
 
275
- const validateDataSourceProtocolAndNetworks = value => {
282
+ const validateDataSourceProtocolAndNetworks = (value: any) => {
276
283
  const dataSources = [...value.dataSources, ...(value.templates || [])]
277
284
 
278
285
  const protocolNetworkMap = dataSourceListToMap(dataSources)
@@ -284,7 +291,7 @@ const validateDataSourceProtocolAndNetworks = value => {
284
291
  message: `Conflicting protocol kinds used in data sources and templates:
285
292
  ${protocolNetworkMap
286
293
  .map(
287
- (dataSourceNames, protocolKind) =>
294
+ (dataSourceNames: any, protocolKind: string | undefined) =>
288
295
  ` ${
289
296
  protocolKind === undefined
290
297
  ? 'Data sources and templates having no protocol kind set'
@@ -292,7 +299,7 @@ ${protocolNetworkMap
292
299
  }:\n${dataSourceNames
293
300
  .valueSeq()
294
301
  .flatten()
295
- .map(ds => ` - ${ds}`)
302
+ .map((ds: string) => ` - ${ds}`)
296
303
  .join('\n')}`,
297
304
  )
298
305
  .join('\n')}
@@ -310,12 +317,12 @@ Recommendation: Make all data sources and templates use the same protocol kind.`
310
317
  message: `Conflicting networks used in data sources and templates:
311
318
  ${networks
312
319
  .map(
313
- (dataSources, network) =>
320
+ (dataSources: any, network: string | undefined) =>
314
321
  ` ${
315
322
  network === undefined
316
323
  ? 'Data sources and templates having no network set'
317
324
  : `Data sources and templates using '${network}'`
318
- }:\n${dataSources.map(ds => ` - ${ds}`).join('\n')}`,
325
+ }:\n${dataSources.map((ds: string) => ` - ${ds}`).join('\n')}`,
319
326
  )
320
327
  .join('\n')}
321
328
  Recommendation: Make all data sources and templates use the same network name.`,
@@ -326,7 +333,13 @@ Recommendation: Make all data sources and templates use the same network name.`,
326
333
  return List()
327
334
  }
328
335
 
329
- const validateManifest = (value, type, schema, protocol, { resolveFile }) => {
336
+ export const validateManifest = (
337
+ value: any,
338
+ type: any,
339
+ schema: any,
340
+ protocol: Protocol,
341
+ { resolveFile }: { resolveFile: (path: string) => string },
342
+ ) => {
330
343
  // Validate manifest using the GraphQL schema that defines its structure
331
344
  let errors =
332
345
  value !== null && value !== undefined
@@ -358,5 +371,3 @@ const validateManifest = (value, type, schema, protocol, { resolveFile }) => {
358
371
  // (this includes _no_ network/protocol at all)
359
372
  return validateDataSourceProtocolAndNetworks(value)
360
373
  }
361
-
362
- export { validateManifest }