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

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,6 +1,5 @@
1
1
  const { withSpinner } = require('./spinner')
2
2
  const fetch = require('node-fetch')
3
- const immutable = require('immutable')
4
3
 
5
4
  const loadAbiFromEtherscan = async (ABI, network, address) =>
6
5
  await withSpinner(
@@ -18,7 +17,7 @@ const loadAbiFromEtherscan = async (ABI, network, address) =>
18
17
  // a `result` field. The `status` is '0' in case of errors and '1' in
19
18
  // case of success
20
19
  if (json.status === '1') {
21
- return new ABI('Contract', undefined, immutable.fromJS(JSON.parse(json.result)))
20
+ return new ABI('Contract', undefined, JSON.parse(json.result))
22
21
  } else {
23
22
  throw new Error('ABI not found, try loading it from a local file')
24
23
  }
@@ -42,7 +41,7 @@ const loadAbiFromBlockScout = async (ABI, network, address) =>
42
41
  // a `result` field. The `status` is '0' in case of errors and '1' in
43
42
  // case of success
44
43
  if (json.status === '1') {
45
- return new ABI('Contract', undefined, immutable.fromJS(JSON.parse(json.result)))
44
+ return new ABI('Contract', undefined, JSON.parse(json.result))
46
45
  } else {
47
46
  throw new Error('ABI not found, try loading it from a local file')
48
47
  }
@@ -1,4 +1,3 @@
1
- const immutable = require('immutable')
2
1
  const { loadManifest } = require('../migrations/util/load-manifest')
3
2
 
4
3
  // Loads manifest from file path and returns all:
@@ -13,15 +12,15 @@ const fromFilePath = async manifestPath => {
13
12
 
14
13
  const extractDataSourceByType = (manifest, dataSourceType, protocol) =>
15
14
  manifest
16
- .get(dataSourceType, immutable.List())
15
+ .get(dataSourceType, [])
17
16
  .reduce(
18
17
  (dataSources, dataSource, dataSourceIndex) =>
19
18
  protocol.isValidKindName(dataSource.get('kind'))
20
19
  ? dataSources.push(
21
- immutable.Map({ path: [dataSourceType, dataSourceIndex], dataSource }),
20
+ { path: [dataSourceType, dataSourceIndex], dataSource },
22
21
  )
23
22
  : dataSources,
24
- immutable.List(),
23
+ []
25
24
  )
26
25
 
27
26
  // Extracts data sources and templates from a immutable manifest data structure
@@ -9,7 +9,6 @@ const { generateEventIndexingHandlers } = require('../scaffold/mapping')
9
9
  const { generateEventType, abiEvents } = require('../scaffold/schema')
10
10
  const { generateTestsFiles } = require('../scaffold/tests')
11
11
  const { strings } = require('gluegun')
12
- const { Map } = require('immutable')
13
12
 
14
13
  const generateDataSource = async (
15
14
  protocol,
@@ -20,15 +19,22 @@ const generateDataSource = async (
20
19
  ) => {
21
20
  const protocolManifest = protocol.getManifestScaffold()
22
21
 
23
- return Map.of(
24
- 'kind', protocol.name,
25
- 'name', contractName,
26
- 'network', network,
27
- 'source', yaml.parse(prettier.format(protocolManifest.source({contract: contractAddress, contractName}),
28
- {parser: 'yaml'})),
29
- 'mapping', yaml.parse(prettier.format(protocolManifest.mapping({abi, contractName}),
30
- {parser: 'yaml'}))
31
- ).asMutable()
22
+ return {
23
+ kind: protocol.name,
24
+ name: contractName,
25
+ network: network,
26
+ source: yaml.parse(
27
+ prettier.format(
28
+ protocolManifest.source({ contract: contractAddress, contractName }),
29
+ { parser: 'yaml' },
30
+ ),
31
+ ),
32
+ mapping: yaml.parse(
33
+ prettier.format(protocolManifest.mapping({ abi, contractName }), {
34
+ parser: 'yaml',
35
+ }),
36
+ ),
37
+ }
32
38
  }
33
39
 
34
40
  const generateScaffold = async (
@@ -130,11 +136,9 @@ const writeMapping = async (abi, protocol, contractName, entities) => {
130
136
 
131
137
  const writeTestsFiles = async (abi, protocol, contractName) => {
132
138
  const hasEvents = protocol.hasEvents()
133
- const events = hasEvents
134
- ? abiEvents(abi).toJS()
135
- : []
139
+ const events = hasEvents ? abiEvents(abi).toJS() : []
136
140
 
137
- if(events.length > 0) {
141
+ if (events.length > 0) {
138
142
  // If a contract is added to a subgraph that has no tests folder
139
143
  await fs.ensureDir('./tests/')
140
144
 
@@ -1,5 +1,4 @@
1
1
  const chalk = require('chalk')
2
- const immutable = require('immutable')
3
2
  const toolbox = require('gluegun/toolbox')
4
3
 
5
4
  const step = (spinner, subject, text) => {
@@ -1,11 +1,16 @@
1
1
  const chalk = require('chalk')
2
2
  const toolbox = require('gluegun/toolbox')
3
- const immutable = require('immutable')
4
3
  const { withSpinner } = require('../command-helpers/spinner')
5
4
  const Subgraph = require('../subgraph')
6
5
  const Protocol = require('../protocols')
7
6
  const DataSourcesExtractor = require('../command-helpers/data-sources')
8
- const { generateDataSource, writeABI, writeSchema, writeMapping, writeTestsFiles } = require('../command-helpers/scaffold')
7
+ const {
8
+ generateDataSource,
9
+ writeABI,
10
+ writeSchema,
11
+ writeMapping,
12
+ writeTestsFiles,
13
+ } = require('../command-helpers/scaffold')
9
14
  const { loadAbiFromEtherscan, loadAbiFromBlockScout } = require('../command-helpers/abi')
10
15
  const EthereumABI = require('../protocols/ethereum/abi')
11
16
  const { fixParameters } = require('../command-helpers/gluegun')
@@ -36,7 +41,7 @@ module.exports = {
36
41
  h,
37
42
  help,
38
43
  mergeEntities,
39
- networkFile
44
+ networkFile,
40
45
  } = toolbox.parameters.options
41
46
 
42
47
  contractName = contractName || 'Contract'
@@ -54,7 +59,8 @@ module.exports = {
54
59
  }
55
60
 
56
61
  let address = toolbox.parameters.first || toolbox.parameters.array[0]
57
- let manifestPath = toolbox.parameters.second || toolbox.parameters.array[1] || './subgraph.yaml'
62
+ let manifestPath =
63
+ toolbox.parameters.second || toolbox.parameters.array[1] || './subgraph.yaml'
58
64
 
59
65
  // Show help text if requested
60
66
  if (help || h) {
@@ -72,7 +78,10 @@ module.exports = {
72
78
  const dataSourcesAndTemplates = await DataSourcesExtractor.fromFilePath(manifestPath)
73
79
  let protocol = Protocol.fromDataSources(dataSourcesAndTemplates)
74
80
  let manifest = await Subgraph.load(manifestPath, { protocol })
75
- let network = manifest.result.get('dataSources').get(0).get('network')
81
+ let network = manifest.result
82
+ .get('dataSources')
83
+ .get(0)
84
+ .get('network')
76
85
  let result = manifest.result.asMutable()
77
86
 
78
87
  let entities = getEntities(manifest)
@@ -96,17 +105,27 @@ module.exports = {
96
105
  }
97
106
  }
98
107
 
99
- let { collisionEntities, onlyCollisions, abiData } = updateEventNamesOnCollision(ethabi, entities, contractName, mergeEntities)
108
+ let { collisionEntities, onlyCollisions, abiData } = updateEventNamesOnCollision(
109
+ ethabi,
110
+ entities,
111
+ contractName,
112
+ mergeEntities,
113
+ )
100
114
  ethabi.data = abiData
101
115
 
102
116
  await writeABI(ethabi, contractName)
103
- await writeSchema(ethabi, protocol, result.getIn(['schema', 'file']), collisionEntities)
117
+ await writeSchema(ethabi, protocol, result.schema?.file, collisionEntities)
104
118
  await writeMapping(ethabi, protocol, contractName, collisionEntities)
105
119
  await writeTestsFiles(ethabi, protocol, contractName)
106
120
 
107
121
  let dataSources = result.get('dataSources')
108
- let dataSource = await generateDataSource(protocol,
109
- contractName, network, address, ethabi)
122
+ let dataSource = await generateDataSource(
123
+ protocol,
124
+ contractName,
125
+ network,
126
+ address,
127
+ ethabi,
128
+ )
110
129
 
111
130
  // Handle the collisions edge case by copying another data source yaml data
112
131
  if (mergeEntities && onlyCollisions) {
@@ -126,7 +145,7 @@ module.exports = {
126
145
  await Subgraph.write(result, manifestPath)
127
146
 
128
147
  // Update networks.json
129
- const networksFile = networkFile || "./networks.json"
148
+ const networksFile = networkFile || './networks.json'
130
149
  await updateNetworksFile(toolbox, network, contractName, address, networksFile)
131
150
 
132
151
  // Detect Yarn and/or NPM
@@ -146,28 +165,26 @@ module.exports = {
146
165
  'Warning during codegen',
147
166
  async spinner => {
148
167
  await system.run(yarn ? 'yarn codegen' : 'npm run codegen')
149
- }
168
+ },
150
169
  )
151
- }
170
+ },
152
171
  }
153
172
 
154
- const getEntities = (manifest) => {
155
- let dataSources = manifest.result.get('dataSources', immutable.List())
156
- let templates = manifest.result.get('templates', immutable.List())
173
+ const getEntities = manifest => {
174
+ let dataSources = manifest.result.get('dataSources', [])
175
+ let templates = manifest.result.get('templates', [])
157
176
 
158
177
  return dataSources
159
178
  .concat(templates)
160
- .map(dataSource => dataSource.getIn(['mapping', 'entities']))
179
+ .map(dataSource => dataSource.mapping?.entities)
161
180
  .flatten()
162
181
  }
163
182
 
164
- const getContractNames = (manifest) => {
165
- let dataSources = manifest.result.get('dataSources', immutable.List())
166
- let templates = manifest.result.get('templates', immutable.List())
183
+ const getContractNames = manifest => {
184
+ let dataSources = manifest.result.get('dataSources', [])
185
+ let templates = manifest.result.get('templates', [])
167
186
 
168
- return dataSources
169
- .concat(templates)
170
- .map(dataSource => dataSource.get('name'))
187
+ return dataSources.concat(templates).map(dataSource => dataSource.get('name'))
171
188
  }
172
189
 
173
190
  const updateEventNamesOnCollision = (ethabi, entities, contractName, mergeEntities) => {
@@ -179,7 +196,7 @@ const updateEventNamesOnCollision = (ethabi, entities, contractName, mergeEntiti
179
196
  for (let i = 0; i < abiData.size; i++) {
180
197
  let dataRow = abiData.get(i).asMutable()
181
198
 
182
- if (dataRow.get('type') === 'event'){
199
+ if (dataRow.get('type') === 'event') {
183
200
  if (entities.indexOf(dataRow.get('name')) !== -1) {
184
201
  if (entities.indexOf(`${contractName}${dataRow.get('name')}`) !== -1) {
185
202
  print.error(`Contract name ('${contractName}')
@@ -190,7 +207,7 @@ const updateEventNamesOnCollision = (ethabi, entities, contractName, mergeEntiti
190
207
 
191
208
  if (mergeEntities) {
192
209
  collisionEntities.push(dataRow.get('name'))
193
- abiData = abiData.asImmutable().delete(i) // needs to be immutable when deleting, yes you read that right - https://github.com/immutable-js/immutable-js/issues/1901
210
+ abiData = abiData.delete(i)
194
211
  i-- // deletion also shifts values to the left
195
212
  continue
196
213
  } else {
@@ -200,7 +217,7 @@ const updateEventNamesOnCollision = (ethabi, entities, contractName, mergeEntiti
200
217
  onlyCollisions = false
201
218
  }
202
219
  }
203
- abiData = abiData.asMutable().set(i, dataRow)
220
+ abiData = abiData.set(i, dataRow)
204
221
  }
205
222
 
206
223
  return { abiData, collisionEntities, onlyCollisions }
@@ -1,7 +1,6 @@
1
1
  const chalk = require('chalk')
2
2
  const crypto = require('crypto')
3
3
  const fs = require('fs-extra')
4
- const immutable = require('immutable')
5
4
  const path = require('path')
6
5
  const yaml = require('js-yaml')
7
6
  const toolbox = require('gluegun/toolbox')
@@ -141,12 +140,12 @@ class Compiler {
141
140
  files.push(this.options.subgraphManifest)
142
141
 
143
142
  // Add all file paths specified in manifest
144
- files.push(path.resolve(subgraph.getIn(['schema', 'file'])))
143
+ files.push(path.resolve(subgraph.schema?.file))
145
144
  subgraph.get('dataSources').map(dataSource => {
146
- files.push(dataSource.getIn(['mapping', 'file']))
145
+ files.push(dataSource.mapping?.file)
147
146
  // Only watch ABI related files if the target protocol has support/need for them.
148
147
  if (this.protocol.hasABIs()) {
149
- dataSource.getIn(['mapping', 'abis']).map(abi => {
148
+ dataSource.mapping?.abis.map(abi => {
150
149
  files.push(abi.get('file'))
151
150
  })
152
151
  }
@@ -258,7 +257,7 @@ class Compiler {
258
257
  }
259
258
 
260
259
  try {
261
- let dataSourceName = dataSource.getIn(['name'])
260
+ let dataSourceName = dataSource.name
262
261
 
263
262
  let baseDir = this.sourceDir
264
263
  let absoluteMappingPath = path.resolve(baseDir, mappingPath)
@@ -552,7 +551,7 @@ class Compiler {
552
551
  updates.push({
553
552
  keyPath: ['schema', 'file'],
554
553
  value: await this._uploadFileToIPFS(
555
- subgraph.getIn(['schema', 'file']),
554
+ subgraph.schema?.file,
556
555
  uploadedFiles,
557
556
  spinner,
558
557
  ),
@@ -560,7 +559,7 @@ class Compiler {
560
559
 
561
560
  if (this.protocol.hasABIs()) {
562
561
  for (let [i, dataSource] of subgraph.get('dataSources').entries()) {
563
- for (let [j, abi] of dataSource.getIn(['mapping', 'abis']).entries()) {
562
+ for (let [j, abi] of dataSource.mapping?.abis.entries()) {
564
563
  updates.push({
565
564
  keyPath: ['dataSources', i, 'mapping', 'abis', j, 'file'],
566
565
  value: await this._uploadFileToIPFS(
@@ -579,7 +578,7 @@ class Compiler {
579
578
  updates.push({
580
579
  keyPath: ['dataSources', i, 'mapping', 'file'],
581
580
  value: await this._uploadFileToIPFS(
582
- dataSource.getIn(['mapping', 'file']),
581
+ dataSource.mapping?.file,
583
582
  uploadedFiles,
584
583
  spinner,
585
584
  ),
@@ -590,7 +589,7 @@ class Compiler {
590
589
  updates.push({
591
590
  keyPath: ['dataSources', i, 'source', 'package', 'file'],
592
591
  value: await this._uploadFileToIPFS(
593
- dataSource.getIn(['source', 'package', 'file']),
592
+ dataSource.source', 'package?.file,
594
593
  uploadedFiles,
595
594
  spinner,
596
595
  ),
@@ -598,9 +597,9 @@ class Compiler {
598
597
  }
599
598
  }
600
599
 
601
- for (let [i, template] of subgraph.get('templates', immutable.List()).entries()) {
600
+ for (let [i, template] of subgraph.get('templates', []).entries()) {
602
601
  if (this.protocol.hasABIs()) {
603
- for (let [j, abi] of template.getIn(['mapping', 'abis']).entries()) {
602
+ for (let [j, abi] of template.mapping?.abis.entries()) {
604
603
  updates.push({
605
604
  keyPath: ['templates', i, 'mapping', 'abis', j, 'file'],
606
605
  value: await this._uploadFileToIPFS(
@@ -615,7 +614,7 @@ class Compiler {
615
614
  updates.push({
616
615
  keyPath: ['templates', i, 'mapping', 'file'],
617
616
  value: await this._uploadFileToIPFS(
618
- template.getIn(['mapping', 'file']),
617
+ template.mapping?.file,
619
618
  uploadedFiles,
620
619
  spinner,
621
620
  ),
@@ -661,7 +660,7 @@ class Compiler {
661
660
  ' ..',
662
661
  `${hash}${alreadyUploaded ? ' (already uploaded)' : ''}`,
663
662
  )
664
- return immutable.fromJS({ '/': `/ipfs/${hash}` })
663
+ return { '/': `/ipfs/${hash}` }
665
664
  }
666
665
 
667
666
  async _uploadSubgraphDefinitionToIPFS(subgraph) {
@@ -1,5 +1,3 @@
1
- const immutable = require('immutable')
2
-
3
1
  module.exports = class ArweaveSubgraph {
4
2
  constructor(options = {}) {
5
3
  this.manifest = options.manifest
@@ -8,13 +6,10 @@ module.exports = class ArweaveSubgraph {
8
6
  }
9
7
 
10
8
  validateManifest() {
11
- return immutable.List()
9
+ return []
12
10
  }
13
11
 
14
12
  handlerTypes() {
15
- return immutable.List([
16
- 'blockHandlers',
17
- 'transactionHandlers',
18
- ])
13
+ return ['blockHandlers', 'transactionHandlers']
19
14
  }
20
15
  }
@@ -1,5 +1,3 @@
1
- const immutable = require('immutable')
2
-
3
1
  module.exports = class CosmosSubgraph {
4
2
  constructor(options = {}) {
5
3
  this.manifest = options.manifest
@@ -8,15 +6,10 @@ module.exports = class CosmosSubgraph {
8
6
  }
9
7
 
10
8
  validateManifest() {
11
- return immutable.List()
9
+ return []
12
10
  }
13
11
 
14
12
  handlerTypes() {
15
- return immutable.List([
16
- 'blockHandlers',
17
- 'eventHandlers',
18
- 'transactionHandlers',
19
- 'messageHandlers',
20
- ])
13
+ return ['blockHandlers', 'eventHandlers', 'transactionHandlers', 'messageHandlers']
21
14
  }
22
15
  }
@@ -1,5 +1,4 @@
1
1
  const fs = require('fs-extra')
2
- const immutable = require('immutable')
3
2
  const path = require('path')
4
3
 
5
4
  const AbiCodeGenerator = require('./codegen/abi')
@@ -104,17 +103,17 @@ module.exports = class ABI {
104
103
  callFunctions() {
105
104
  // An entry is a function if its type is not set or if it is one of
106
105
  // 'constructor', 'function' or 'fallback'
107
- let functionTypes = immutable.Set(['constructor', 'function', 'fallback'])
106
+ let functionTypes = new Set(['constructor', 'function', 'fallback'])
108
107
  let functions = this.data.filter(
109
- entry => !entry.has('type') || functionTypes.includes(entry.get('type')),
108
+ entry => !entry.has('type') || functionTypes.has(entry.get('type')),
110
109
  )
111
110
 
112
111
  // A function is a call function if it is nonpayable, payable or
113
112
  // not constant
114
- let mutabilityTypes = immutable.Set(['nonpayable', 'payable'])
113
+ let mutabilityTypes =new Set(['nonpayable', 'payable'])
115
114
  return functions.filter(
116
115
  entry =>
117
- mutabilityTypes.includes(entry.get('stateMutability')) ||
116
+ mutabilityTypes.has(entry.get('stateMutability')) ||
118
117
  entry.get('constant') === false,
119
118
  )
120
119
  }
@@ -125,7 +124,7 @@ module.exports = class ABI {
125
124
  .map(entry => {
126
125
  const name = entry.get('name', '<default>')
127
126
  const inputs = entry
128
- .get('inputs', immutable.List())
127
+ .get('inputs', [])
129
128
  .map(input => buildSignatureParameter(input))
130
129
 
131
130
  return `${name}(${inputs.join(',')})`
@@ -155,6 +154,6 @@ module.exports = class ABI {
155
154
  throw Error(`No valid ABI in file: ${path.relative(process.cwd(), file)}`)
156
155
  }
157
156
 
158
- return new ABI(name, file, immutable.fromJS(abi))
157
+ return new ABI(name, file, abi)
159
158
  }
160
159
  }