@graphprotocol/graph-cli 0.37.3-alpha-20230111112917-acbc0ae → 0.37.3-alpha-20230111114838-482aa51

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-20230111112917-acbc0ae
3
+ ## 0.37.3-alpha-20230111114838-482aa51
4
4
 
5
5
  ### Patch Changes
6
6
 
@@ -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;
@@ -1,8 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const schema_1 = require("./schema");
4
+ const manifest_1 = require("./manifest");
5
+ const contract_1 = require("./contract");
3
6
  exports.default = {
4
- validateSchema: require('./schema').validateSchema,
5
- validateManifest: require('./manifest').validateManifest,
6
- validateContractValues: require('./contract').validateContractValues,
7
- validateContract: require('./contract').validateContract,
7
+ validateSchema: schema_1.validateSchema,
8
+ validateManifest: manifest_1.validateManifest,
9
+ validateContractValues: contract_1.validateContractValues,
10
+ validateContract: contract_1.validateContract,
8
11
  };
@@ -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-20230111112917-acbc0ae",
3
+ "version": "0.37.3-alpha-20230111114838-482aa51",
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",
@@ -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 }
@@ -0,0 +1,10 @@
1
+ import { validateSchema } from './schema'
2
+ import { validateManifest } from './manifest'
3
+ import { validateContractValues, validateContract } from './contract'
4
+
5
+ export default {
6
+ validateSchema,
7
+ validateManifest,
8
+ validateContractValues,
9
+ validateContract,
10
+ }
@@ -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 }
@@ -1,6 +0,0 @@
1
- export default {
2
- validateSchema: require('./schema').validateSchema,
3
- validateManifest: require('./manifest').validateManifest,
4
- validateContractValues: require('./contract').validateContractValues,
5
- validateContract: require('./contract').validateContract,
6
- }