@graphprotocol/graph-cli 0.37.2-alpha-20221219142030-0cf2a37 → 0.37.2

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.
@@ -1,3 +1,4 @@
1
+ const immutable = require('immutable')
1
2
  const ABI = require('./abi')
2
3
  const DataSourcesExtractor = require('../../command-helpers/data-sources')
3
4
 
@@ -15,10 +16,7 @@ module.exports = class EthereumSubgraph {
15
16
  }
16
17
 
17
18
  validateAbis() {
18
- const dataSourcesAndTemplates = DataSourcesExtractor.fromManifest(
19
- this.manifest,
20
- this.protocol,
21
- )
19
+ const dataSourcesAndTemplates = DataSourcesExtractor.fromManifest(this.manifest, this.protocol)
22
20
 
23
21
  return dataSourcesAndTemplates.reduce(
24
22
  (errors, dataSourceOrTemplate) =>
@@ -28,18 +26,18 @@ module.exports = class EthereumSubgraph {
28
26
  dataSourceOrTemplate.get('path'),
29
27
  ),
30
28
  ),
31
- [],
29
+ immutable.List(),
32
30
  )
33
31
  }
34
32
 
35
33
  validateDataSourceAbis(dataSource, path) {
36
34
  // Validate that the the "source > abi" reference of all data sources
37
35
  // points to an existing ABI in the data source ABIs
38
- let abiName = dataSource.source?.abi
39
- let abiNames = dataSource.mapping?.abis.map(abi => abi.get('name'))
36
+ let abiName = dataSource.getIn(['source', 'abi'])
37
+ let abiNames = dataSource.getIn(['mapping', 'abis']).map(abi => abi.get('name'))
40
38
  let nameErrors = abiNames.includes(abiName)
41
- ? []
42
- : [
39
+ ? immutable.List()
40
+ : immutable.fromJS([
43
41
  {
44
42
  path: [...path, 'source', 'abi'],
45
43
  message: `\
@@ -50,57 +48,61 @@ ${abiNames
50
48
  .map(name => `- ${name}`)
51
49
  .join('\n')}`,
52
50
  },
53
- ]
51
+ ])
54
52
 
55
53
  // Validate that all ABI files are valid
56
- let fileErrors = dataSource.mapping?.abis.reduce((errors, abi, abiIndex) => {
57
- try {
58
- ABI.load(abi.get('name'), this.resolveFile(abi.get('file')))
59
- return errors
60
- } catch (e) {
61
- return errors.push({
62
- path: [...path, 'mapping', 'abis', abiIndex, 'file'],
63
- message: e.message,
64
- })
65
- }
66
- }, [])
54
+ let fileErrors = dataSource
55
+ .getIn(['mapping', 'abis'])
56
+ .reduce((errors, abi, abiIndex) => {
57
+ try {
58
+ ABI.load(abi.get('name'), this.resolveFile(abi.get('file')))
59
+ return errors
60
+ } catch (e) {
61
+ return errors.push(
62
+ immutable.fromJS({
63
+ path: [...path, 'mapping', 'abis', abiIndex, 'file'],
64
+ message: e.message,
65
+ }),
66
+ )
67
+ }
68
+ }, immutable.List())
67
69
 
68
70
  return nameErrors.concat(fileErrors)
69
71
  }
70
72
 
71
73
  validateEvents() {
72
- const dataSourcesAndTemplates = DataSourcesExtractor.fromManifest(
73
- this.manifest,
74
- this.protocol,
75
- )
74
+ const dataSourcesAndTemplates = DataSourcesExtractor.fromManifest(this.manifest, this.protocol)
76
75
 
77
- return dataSourcesAndTemplates.reduce((errors, dataSourceOrTemplate) => {
78
- return errors.concat(
79
- this.validateDataSourceEvents(
80
- dataSourceOrTemplate.get('dataSource'),
81
- dataSourceOrTemplate.get('path'),
82
- ),
83
- )
84
- }, [])
76
+ return dataSourcesAndTemplates
77
+ .reduce((errors, dataSourceOrTemplate) => {
78
+ return errors.concat(
79
+ this.validateDataSourceEvents(
80
+ dataSourceOrTemplate.get('dataSource'),
81
+ dataSourceOrTemplate.get('path'),
82
+ ),
83
+ )
84
+ }, immutable.List())
85
85
  }
86
86
 
87
87
  validateDataSourceEvents(dataSource, path) {
88
88
  let abi
89
89
  try {
90
90
  // Resolve the source ABI name into a real ABI object
91
- let abiName = dataSource.source?.abi
92
- let abiEntry = dataSource.mapping?.abis.find(abi => abi.get('name') === abiName)
91
+ let abiName = dataSource.getIn(['source', 'abi'])
92
+ let abiEntry = dataSource
93
+ .getIn(['mapping', 'abis'])
94
+ .find(abi => abi.get('name') === abiName)
93
95
  abi = ABI.load(abiEntry.get('name'), this.resolveFile(abiEntry.get('file')))
94
96
  } catch (_) {
95
97
  // Ignore errors silently; we can't really say anything about
96
98
  // the events if the ABI can't even be loaded
97
- return []
99
+ return immutable.List()
98
100
  }
99
101
 
100
102
  // Obtain event signatures from the mapping
101
- let manifestEvents = (dataSource.mapping?.eventHandlers || []).map(handler =>
102
- handler.get('event'),
103
- )
103
+ let manifestEvents = dataSource
104
+ .getIn(['mapping', 'eventHandlers'], immutable.List())
105
+ .map(handler => handler.get('event'))
104
106
 
105
107
  // Obtain event signatures from the ABI
106
108
  let abiEvents = abi.eventSignatures()
@@ -111,17 +113,19 @@ ${abiNames
111
113
  (errors, manifestEvent, index) =>
112
114
  abiEvents.includes(manifestEvent)
113
115
  ? errors
114
- : errors.push({
115
- path: [...path, 'eventHandlers', index],
116
- message: `\
116
+ : errors.push(
117
+ immutable.fromJS({
118
+ path: [...path, 'eventHandlers', index],
119
+ message: `\
117
120
  Event with signature '${manifestEvent}' not present in ABI '${abi.name}'.
118
121
  Available events:
119
122
  ${abiEvents
120
123
  .sort()
121
124
  .map(event => `- ${event}`)
122
125
  .join('\n')}`,
123
- }),
124
- [],
126
+ }),
127
+ ),
128
+ immutable.List(),
125
129
  )
126
130
  }
127
131
 
@@ -135,8 +139,10 @@ ${abiEvents
135
139
  let abi
136
140
  try {
137
141
  // Resolve the source ABI name into a real ABI object
138
- let abiName = dataSource.source?.abi
139
- let abiEntry = dataSource.mapping?.abis.find(abi => abi.get('name') === abiName)
142
+ let abiName = dataSource.getIn(['source', 'abi'])
143
+ let abiEntry = dataSource
144
+ .getIn(['mapping', 'abis'])
145
+ .find(abi => abi.get('name') === abiName)
140
146
  abi = ABI.load(abiEntry.get('name'), this.resolveFile(abiEntry.get('file')))
141
147
  } catch (e) {
142
148
  // Ignore errors silently; we can't really say anything about
@@ -145,9 +151,9 @@ ${abiEvents
145
151
  }
146
152
 
147
153
  // Obtain event signatures from the mapping
148
- let manifestFunctions = (dataSource.mapping?.callHandlers || []).map(handler =>
149
- handler.get('function'),
150
- )
154
+ let manifestFunctions = dataSource
155
+ .getIn(['mapping', 'callHandlers'], immutable.List())
156
+ .map(handler => handler.get('function'))
151
157
 
152
158
  // Obtain event signatures from the ABI
153
159
  let abiFunctions = abi.callFunctionSignatures()
@@ -158,22 +164,28 @@ ${abiEvents
158
164
  (errors, manifestFunction, index) =>
159
165
  abiFunctions.includes(manifestFunction)
160
166
  ? errors
161
- : errors.push({
162
- path: [...path, index],
163
- message: `\
167
+ : errors.push(
168
+ immutable.fromJS({
169
+ path: [...path, index],
170
+ message: `\
164
171
  Call function with signature '${manifestFunction}' not present in ABI '${abi.name}'.
165
172
  Available call functions:
166
173
  ${abiFunctions
167
174
  .sort()
168
175
  .map(tx => `- ${tx}`)
169
176
  .join('\n')}`,
170
- }),
177
+ }),
178
+ ),
171
179
  errors,
172
180
  )
173
- }, [])
181
+ }, immutable.List())
174
182
  }
175
183
 
176
184
  handlerTypes() {
177
- return ['blockHandlers', 'callHandlers', 'eventHandlers']
185
+ return immutable.List([
186
+ 'blockHandlers',
187
+ 'callHandlers',
188
+ 'eventHandlers',
189
+ ])
178
190
  }
179
191
  }
@@ -1,5 +1,6 @@
1
1
  const fs = require('fs-extra')
2
2
  const path = require('path')
3
+ const immutable = require('immutable')
3
4
  const prettier = require('prettier')
4
5
  const ABI = require('./abi')
5
6
  const { step, withSpinner } = require('../../command-helpers/spinner')
@@ -23,19 +24,21 @@ module.exports = class EthereumTypeGenerator {
23
24
  .get('dataSources')
24
25
  .reduce(
25
26
  (abis, dataSource) =>
26
- dataSource.mapping?.abis.reduce(
27
- (abis, abi) =>
28
- abis.push(
29
- this._loadABI(
30
- dataSource,
31
- abi.get('name'),
32
- abi.get('file'),
33
- spinner,
34
- ),
35
- ),
36
- abis,
27
+ dataSource
28
+ .getIn(['mapping', 'abis'])
29
+ .reduce(
30
+ (abis, abi) =>
31
+ abis.push(
32
+ this._loadABI(
33
+ dataSource,
34
+ abi.get('name'),
35
+ abi.get('file'),
36
+ spinner,
37
+ ),
37
38
  ),
38
- [],
39
+ abis,
40
+ ),
41
+ immutable.List(),
39
42
  )
40
43
  } catch (e) {
41
44
  throw Error(`Failed to load contract ABIs: ${e.message}`)
@@ -65,8 +68,8 @@ module.exports = class EthereumTypeGenerator {
65
68
  `Warnings while loading data source template ABIs`,
66
69
  async spinner => {
67
70
  let abis = []
68
- for (let template of subgraph.get('templates', [])) {
69
- for (let abi of template.mapping?.abis) {
71
+ for (let template of subgraph.get('templates', immutable.List())) {
72
+ for (let abi of template.getIn(['mapping', 'abis'])) {
70
73
  abis.push(
71
74
  this._loadDataSourceTemplateABI(
72
75
  template,
@@ -86,7 +89,11 @@ module.exports = class EthereumTypeGenerator {
86
89
  try {
87
90
  if (this.sourceDir) {
88
91
  let absolutePath = path.resolve(this.sourceDir, maybeRelativePath)
89
- step(spinner, `Load data source template ABI from`, displayPath(absolutePath))
92
+ step(
93
+ spinner,
94
+ `Load data source template ABI from`,
95
+ displayPath(absolutePath),
96
+ )
90
97
  return { template, abi: ABI.load(name, absolutePath) }
91
98
  } else {
92
99
  return { template, abi: ABI.load(name, maybeRelativePath) }
@@ -163,7 +170,9 @@ module.exports = class EthereumTypeGenerator {
163
170
  step(
164
171
  spinner,
165
172
  `Generate types for data source template ABI:`,
166
- `${abi.template.get('name')} > ${abi.abi.name} (${displayPath(abi.abi.file)})`,
173
+ `${abi.template.get('name')} > ${abi.abi.name} (${displayPath(
174
+ abi.abi.file,
175
+ )})`,
167
176
  )
168
177
 
169
178
  let codeGenerator = abi.abi.codeGenerator()
@@ -1,3 +1,4 @@
1
+ const immutable = require('immutable')
1
2
  const ArweaveSubgraph = require('./arweave/subgraph')
2
3
  const EthereumTypeGenerator = require('./ethereum/type-generator')
3
4
  const EthereumTemplateCodeGen = require('./ethereum/codegen/template')
@@ -53,7 +54,7 @@ class Protocol {
53
54
  }
54
55
 
55
56
  static availableProtocols() {
56
- return Object.freeze({
57
+ return immutable.fromJS({
57
58
  // `ethereum/contract` is kept for backwards compatibility.
58
59
  // New networks (or protocol perhaps) shouldn't have the `/contract` anymore (unless a new case makes use of it).
59
60
  arweave: ['arweave'],
@@ -65,7 +66,7 @@ class Protocol {
65
66
  }
66
67
 
67
68
  static availableNetworks() {
68
- let networks = {
69
+ let networks = immutable.fromJS({
69
70
  arweave: ['arweave-mainnet'],
70
71
  ethereum: [
71
72
  'mainnet',
@@ -105,14 +106,14 @@ class Protocol {
105
106
  'juno-1',
106
107
  'uni-3', // Juno testnet
107
108
  ],
108
- }
109
+ })
109
110
 
110
111
  let allNetworks = []
111
112
  networks.forEach(value => {
112
113
  allNetworks.push(...value)
113
114
  })
114
115
 
115
- networks['substreams'] = allNetworks
116
+ networks = networks.set('substreams', immutable.fromJS(allNetworks))
116
117
 
117
118
  return networks
118
119
  }
@@ -131,7 +132,7 @@ class Protocol {
131
132
  // for the given protocol instance (this).
132
133
  isValidKindName(kind) {
133
134
  return Protocol.availableProtocols()
134
- .get(this.name, [])
135
+ .get(this.name, immutable.List())
135
136
  .includes(kind)
136
137
  }
137
138
 
@@ -1,3 +1,5 @@
1
+ const immutable = require('immutable')
2
+
1
3
  module.exports = class NearSubgraph {
2
4
  constructor(options = {}) {
3
5
  this.manifest = options.manifest
@@ -6,13 +8,13 @@ module.exports = class NearSubgraph {
6
8
  }
7
9
 
8
10
  validateManifest() {
9
- return []
11
+ return immutable.List()
10
12
  }
11
13
 
12
14
  handlerTypes() {
13
- return [
15
+ return immutable.List([
14
16
  'blockHandlers',
15
17
  'receiptHandlers',
16
- ]
18
+ ])
17
19
  }
18
20
  }
@@ -1,3 +1,5 @@
1
+ const immutable = require('immutable')
2
+
1
3
  module.exports = class SubstreamsSubgraph {
2
4
  constructor(options = {}) {
3
5
  this.manifest = options.manifest
@@ -6,10 +8,10 @@ module.exports = class SubstreamsSubgraph {
6
8
  }
7
9
 
8
10
  validateManifest() {
9
- return []
11
+ return immutable.List()
10
12
  }
11
13
 
12
14
  handlerTypes() {
13
- return []
15
+ return immutable.List([])
14
16
  }
15
17
  }
@@ -1,3 +1,4 @@
1
+ const immutable = require('immutable')
1
2
  const Scaffold = require('./')
2
3
  const Protocol = require('../protocols')
3
4
 
@@ -1,4 +1,5 @@
1
1
  const ABI = require('../protocols/ethereum/abi')
2
+ const immutable = require('immutable')
2
3
  const Scaffold = require('./')
3
4
  const Protocol = require('../protocols')
4
5
 
@@ -60,12 +61,12 @@ const TEST_CALLABLE_FUNCTIONS = [
60
61
  const TEST_ABI = new ABI(
61
62
  'Contract',
62
63
  undefined,
63
- [
64
+ immutable.fromJS([
64
65
  TEST_EVENT,
65
66
  OVERLOADED_EVENT,
66
67
  TEST_CONTRACT,
67
68
  ...TEST_CALLABLE_FUNCTIONS,
68
- ],
69
+ ]),
69
70
  )
70
71
 
71
72
  const protocol = new Protocol('ethereum')
@@ -46,7 +46,7 @@ module.exports = class Scaffold {
46
46
  },
47
47
  dependencies: {
48
48
  '@graphprotocol/graph-cli': GRAPH_CLI_VERSION,
49
- '@graphprotocol/graph-ts': `0.28.1`,
49
+ '@graphprotocol/graph-ts': `0.29.1`,
50
50
  },
51
51
  devDependencies: this.protocol.hasEvents()
52
52
  ? { 'matchstick-as': `0.5.0` }
@@ -1,3 +1,4 @@
1
+ const immutable = require('immutable')
1
2
  const Scaffold = require('./')
2
3
  const Protocol = require('../protocols')
3
4
 
package/src/schema.js CHANGED
@@ -1,5 +1,6 @@
1
1
  let fs = require('fs-extra')
2
2
  let graphql = require('graphql/language')
3
+ let immutable = require('immutable')
3
4
 
4
5
  let SchemaCodeGenerator = require('./codegen/schema')
5
6
 
@@ -17,6 +18,6 @@ module.exports = class Schema {
17
18
  static async load(filename) {
18
19
  let document = await fs.readFile(filename, 'utf-8')
19
20
  let ast = graphql.parse(document)
20
- return new Schema(filename, document, ast)
21
+ return new Schema(filename, document, immutable.fromJS(ast))
21
22
  }
22
23
  }
package/src/subgraph.js CHANGED
@@ -1,4 +1,5 @@
1
1
  let fs = require('fs-extra')
2
+ let immutable = require('immutable')
2
3
  let path = require('path')
3
4
  let yaml = require('yaml')
4
5
  let { strOptions } = require('yaml/types')
@@ -42,12 +43,12 @@ module.exports = class Subgraph {
42
43
  static async validate(data, protocol, { resolveFile }) {
43
44
  subgraphDebug(`Validating Subgraph with protocol "%s"`, protocol)
44
45
  if (protocol.name == null) {
45
- return [
46
+ return immutable.fromJS([
46
47
  {
47
48
  path: [],
48
49
  message: `Unable to determine for which protocol manifest file is built for. Ensure you have at least one 'dataSources' and/or 'templates' elements defined in your subgraph.`,
49
50
  },
50
- ]
51
+ ])
51
52
  }
52
53
 
53
54
  // Parse the default subgraph schema
@@ -68,7 +69,7 @@ module.exports = class Subgraph {
68
69
  }
69
70
 
70
71
  static validateSchema(manifest, { resolveFile }) {
71
- let filename = resolveFile(manifest.schema?.file)
72
+ let filename = resolveFile(manifest.getIn(['schema', 'file']))
72
73
  let errors = validation.validateSchema(filename)
73
74
 
74
75
  if (errors.size > 0) {
@@ -105,29 +106,29 @@ module.exports = class Subgraph {
105
106
  const repository = manifest.get('repository')
106
107
 
107
108
  return /^https:\/\/github\.com\/graphprotocol\/example-subgraphs?$/.test(repository)
108
- ? [
109
- {
109
+ ? immutable.List().push(
110
+ immutable.fromJS({
110
111
  path: ['repository'],
111
112
  message: `\
112
113
  The repository is still set to ${repository}.
113
114
  Please replace it with a link to your subgraph source code.`,
114
- },
115
- ]
116
- : []
115
+ }),
116
+ )
117
+ : immutable.List()
117
118
  }
118
119
 
119
120
  static validateDescription(manifest, { resolveFile }) {
120
121
  // TODO: Maybe implement this in the future for each protocol example description
121
122
  return manifest.get('description', '').startsWith('Gravatar for ')
122
- ? [
123
- {
123
+ ? immutable.List().push(
124
+ immutable.fromJS({
124
125
  path: ['description'],
125
126
  message: `\
126
127
  The description is still the one from the example subgraph.
127
128
  Please update it to tell users more about your subgraph.`,
128
- },
129
- ]
130
- : []
129
+ }),
130
+ )
131
+ : immutable.List()
131
132
  }
132
133
 
133
134
  static validateHandlers(manifest, protocol, protocolSubgraph) {
@@ -150,25 +151,27 @@ Please update it to tell users more about your subgraph.`,
150
151
  }
151
152
 
152
153
  const areAllHandlersEmpty = handlerTypes
153
- .map(handlerType => mapping.get(handlerType, []))
154
+ .map(handlerType => mapping.get(handlerType, immutable.List()))
154
155
  .every(handlers => handlers.isEmpty())
155
156
 
156
157
  const handlerNamesWithoutLast = handlerTypes.pop().join(', ')
157
158
 
158
159
  return areAllHandlersEmpty
159
- ? errors.push({
160
- path: path,
161
- message: `\
160
+ ? errors.push(
161
+ immutable.fromJS({
162
+ path: path,
163
+ message: `\
162
164
  Mapping has no ${handlerNamesWithoutLast} or ${handlerTypes.get(-1)}.
163
165
  At least one such handler must be defined.`,
164
- })
166
+ }),
167
+ )
165
168
  : errors
166
- }, [])
169
+ }, immutable.List())
167
170
  }
168
171
 
169
172
  static validateContractValues(manifest, protocol) {
170
173
  if (!protocol.hasContract()) {
171
- return []
174
+ return immutable.List()
172
175
  }
173
176
 
174
177
  return validation.validateContractValues(manifest, protocol)
@@ -181,32 +184,38 @@ At least one such handler must be defined.`,
181
184
  let path = ['dataSources', dataSourceIndex, 'name']
182
185
  let name = dataSource.get('name')
183
186
  if (names.includes(name)) {
184
- errors = errors.push({
185
- path,
186
- message: `\
187
+ errors = errors.push(
188
+ immutable.fromJS({
189
+ path,
190
+ message: `\
187
191
  More than one data source named '${name}', data source names must be unique.`,
188
- })
192
+ }),
193
+ )
189
194
  }
190
195
  names.push(name)
191
196
  return errors
192
- }, [])
197
+ }, immutable.List())
193
198
  }
194
199
 
195
200
  static validateUniqueTemplateNames(manifest) {
196
201
  let names = []
197
- return manifest.get('templates', []).reduce((errors, template, templateIndex) => {
198
- let path = ['templates', templateIndex, 'name']
199
- let name = template.get('name')
200
- if (names.includes(name)) {
201
- errors = errors.push({
202
- path,
203
- message: `\
202
+ return manifest
203
+ .get('templates', immutable.List())
204
+ .reduce((errors, template, templateIndex) => {
205
+ let path = ['templates', templateIndex, 'name']
206
+ let name = template.get('name')
207
+ if (names.includes(name)) {
208
+ errors = errors.push(
209
+ immutable.fromJS({
210
+ path,
211
+ message: `\
204
212
  More than one template named '${name}', template names must be unique.`,
205
- })
206
- }
207
- names.push(name)
208
- return errors
209
- }, [])
213
+ }),
214
+ )
215
+ }
216
+ names.push(name)
217
+ return errors
218
+ }, immutable.List())
210
219
  }
211
220
 
212
221
  static dump(manifest) {
@@ -241,7 +250,7 @@ More than one template named '${name}', template names must be unique.`,
241
250
  }
242
251
  }
243
252
 
244
- let manifest = data
253
+ let manifest = immutable.fromJS(data)
245
254
 
246
255
  // Validate the schema
247
256
  Subgraph.validateSchema(manifest, { resolveFile })
@@ -253,14 +262,14 @@ More than one template named '${name}', template names must be unique.`,
253
262
  })
254
263
 
255
264
  let errors = skipValidation
256
- ? []
257
- : [
265
+ ? immutable.List()
266
+ : immutable.List.of(
258
267
  ...protocolSubgraph.validateManifest(),
259
268
  ...Subgraph.validateContractValues(manifest, protocol),
260
269
  ...Subgraph.validateUniqueDataSourceNames(manifest),
261
270
  ...Subgraph.validateUniqueTemplateNames(manifest),
262
271
  ...Subgraph.validateHandlers(manifest, protocol, protocolSubgraph),
263
- ]
272
+ )
264
273
 
265
274
  if (errors.size > 0) {
266
275
  throwCombinedError(filename, errors)
@@ -268,11 +277,11 @@ More than one template named '${name}', template names must be unique.`,
268
277
 
269
278
  // Perform warning validations
270
279
  let warnings = skipValidation
271
- ? []
272
- : [
280
+ ? immutable.List()
281
+ : immutable.List.of(
273
282
  ...Subgraph.validateRepository(manifest, { resolveFile }),
274
283
  ...Subgraph.validateDescription(manifest, { resolveFile }),
275
- ]
284
+ )
276
285
 
277
286
  return {
278
287
  result: manifest,