@graphprotocol/graph-cli 0.30.0 → 0.30.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphprotocol/graph-cli",
3
- "version": "0.30.0",
3
+ "version": "0.30.3",
4
4
  "license": "(Apache-2.0 OR MIT)",
5
5
  "description": "CLI for building for and deploying to The Graph",
6
6
  "dependencies": {
@@ -33,7 +33,6 @@ const generateScaffold = async (
33
33
  subgraphName,
34
34
  indexEvents,
35
35
  contractName = 'Contract',
36
- dataSourceName,
37
36
  node,
38
37
  },
39
38
  spinner,
@@ -48,7 +47,6 @@ const generateScaffold = async (
48
47
  network,
49
48
  contractName,
50
49
  subgraphName,
51
- dataSourceName,
52
50
  node,
53
51
  })
54
52
 
@@ -81,12 +79,12 @@ const writeScaffold = async (scaffold, directory, spinner) => {
81
79
  await writeScaffoldDirectory(scaffold, directory, spinner)
82
80
  }
83
81
 
84
- const writeABI = async (abi, contractName, abiPath = `./abis/${contractName}.json`) => {
82
+ const writeABI = async (abi, contractName) => {
85
83
  let data = prettier.format(JSON.stringify(abi.data), {
86
84
  parser: 'json',
87
85
  })
88
86
 
89
- await fs.writeFile(abiPath, data, { encoding: 'utf-8' })
87
+ await fs.writeFile(`./abis/${contractName}.json`, data, { encoding: 'utf-8' })
90
88
  }
91
89
 
92
90
  const writeSchema = async (abi, protocol, schemaPath, entities) => {
@@ -95,7 +95,7 @@ module.exports = {
95
95
  let { collisionEntities, onlyCollisions, abiData } = updateEventNamesOnCollision(ethabi, entities, contractName, mergeEntities)
96
96
  ethabi.data = abiData
97
97
 
98
- await writeABI(ethabi, contractName, abi)
98
+ await writeABI(ethabi, contractName)
99
99
  await writeSchema(ethabi, protocol, result.getIn(['schema', 'file']), collisionEntities)
100
100
  await writeMapping(ethabi, protocol, contractName, collisionEntities)
101
101
 
@@ -179,7 +179,7 @@ const processInitForm = async (
179
179
  //
180
180
  // protocols that don't support contract
181
181
  // - arweave
182
- // - tendermint
182
+ // - cosmos
183
183
  {
184
184
  type: 'input',
185
185
  name: 'contract',
@@ -718,7 +718,6 @@ const initSubgraphFromContract = async (
718
718
  contract,
719
719
  indexEvents,
720
720
  contractName,
721
- dataSourceName,
722
721
  node,
723
722
  studio,
724
723
  product,
@@ -773,7 +772,6 @@ const initSubgraphFromContract = async (
773
772
  contract,
774
773
  indexEvents,
775
774
  contractName,
776
- dataSourceName,
777
775
  node,
778
776
  },
779
777
  spinner,
@@ -13,12 +13,12 @@ const HELP = `
13
13
  ${chalk.bold('graph test')} ${chalk.dim('[options]')} ${chalk.bold('<datasource>')}
14
14
 
15
15
  ${chalk.dim('Options:')}
16
- -c, --coverage Run the tests in coverage mode. Works with v0.2.1 and above
16
+ -c, --coverage Run the tests in coverage mode
17
17
  -d, --docker Run the tests in a docker container(Note: Please execute from the root folder of the subgraph)
18
18
  -f --force Binary - overwrites folder + file when downloading. Docker - rebuilds the docker image
19
19
  -h, --help Show usage information
20
20
  -l, --logs Logs to the console information about the OS, CPU model and download url (debugging purposes)
21
- -r, --recompile Force-recompile tests (Not available in 0.2.2 and earlier versions)
21
+ -r, --recompile Force-recompile tests
22
22
  -v, --version <tag> Choose the version of the rust binary that you want to be downloaded/used
23
23
  `
24
24
 
@@ -43,16 +43,16 @@ module.exports = {
43
43
  version,
44
44
  } = toolbox.parameters.options
45
45
 
46
- let opts = new Map()
46
+ let opts = {}
47
47
  // Support both long and short option variants
48
- opts.set("coverage", coverage || c)
49
- opts.set("docker", docker || d)
50
- opts.set("force", force || f)
51
- opts.set("help", help || h)
52
- opts.set("logs", logs || l)
53
- opts.set("recompile", recompile || r)
54
- opts.set("version", version || v)
55
-
48
+ opts.coverage = coverage || c
49
+ opts.docker = docker || d
50
+ opts.force = force || f
51
+ opts.help = help || h
52
+ opts.logs = logs || l
53
+ opts.recompile = recompile || r
54
+ opts.version = version || v
55
+ opts.testsFolder = './tests'
56
56
  // Fix if a boolean flag (e.g -c, --coverage) has an argument
57
57
  try {
58
58
  fixParameters(toolbox.parameters, {
@@ -76,18 +76,49 @@ module.exports = {
76
76
  }
77
77
 
78
78
  let datasource = toolbox.parameters.first || toolbox.parameters.array[0]
79
-
80
79
  // Show help text if requested
81
- if (opts.get("help")) {
80
+ if (opts.help) {
82
81
  print.info(HELP)
83
82
  return
84
83
  }
85
84
 
86
- let result = await fetch('https://api.github.com/repos/LimeChain/matchstick/releases/latest')
87
- let json = await result.json()
88
- opts.set("latestVersion", json.tag_name)
85
+ // Check if matchstick.yaml config exists
86
+ if(filesystem.exists('matchstick.yaml')) {
87
+ try {
88
+ // Load the config
89
+ let config = await yaml.load(filesystem.read('matchstick.yaml', 'utf8'))
90
+
91
+ // Check if matchstick.yaml and testsFolder not null
92
+ if(config && config.testsFolder) {
93
+ // assign test folder from matchstick.yaml if present
94
+ opts.testsFolder = config.testsFolder
95
+ }
96
+ } catch (error) {
97
+ print.info('A problem occurred while reading matchstick.yaml. Please attend to the errors below:')
98
+ print.error(error.message)
99
+ process.exit(1)
100
+ }
101
+ }
102
+
103
+ opts.cachePath = path.join(opts.testsFolder, '.latest.json')
104
+ setVersionFromCache(opts)
105
+
106
+ // Fetch the latest version tag if version is not specified with -v/--version or if the version is not cached
107
+ if (opts.force || (!opts.version && !opts.latestVersion)) {
108
+ print.info("Fetching latest version tag")
109
+ let result = await fetch('https://api.github.com/repos/LimeChain/matchstick/releases/latest')
110
+ let json = await result.json()
111
+ opts.latestVersion = json.tag_name
112
+
113
+ filesystem.file(opts.cachePath, {
114
+ content: {
115
+ version: json.tag_name,
116
+ timestamp: Date.now()
117
+ }
118
+ })
119
+ }
89
120
 
90
- if(opts.get("docker")) {
121
+ if(opts.docker) {
91
122
  runDocker(datasource, opts)
92
123
  } else {
93
124
  runBinary(datasource, opts)
@@ -95,13 +126,25 @@ module.exports = {
95
126
  }
96
127
  }
97
128
 
129
+ async function setVersionFromCache(opts) {
130
+ if(filesystem.exists(opts.cachePath) == 'file') {
131
+ let cached = filesystem.read(opts.cachePath, 'json')
132
+ // Get the cache age in days
133
+ let cacheAge = (Date.now() - cached.timestamp) / (1000 * 60 * 60 * 24)
134
+ // If cache age is less than 1 day, use the cached version
135
+ if (cacheAge < 1) {
136
+ opts.latestVersion = cached.version
137
+ }
138
+ }
139
+ }
140
+
98
141
  async function runBinary(datasource, opts) {
99
- let coverageOpt = opts.get("coverage")
100
- let forceOpt = opts.get("force")
101
- let logsOpt = opts.get("logs")
102
- let versionOpt = opts.get("version")
103
- let latestVersion = opts.get("latestVersion")
104
- let recompileOpt = opts.get("recompile")
142
+ let coverageOpt = opts.coverage
143
+ let forceOpt = opts.force
144
+ let logsOpt = opts.logs
145
+ let versionOpt = opts.version
146
+ let latestVersion = opts.latestVersion
147
+ let recompileOpt = opts.recompile
105
148
 
106
149
  const platform = await getPlatform(logsOpt)
107
150
 
@@ -126,10 +169,10 @@ async function getPlatform(logsOpt) {
126
169
  const arch = os.arch()
127
170
  const cpuCore = os.cpus()[0]
128
171
  const isM1 = (arch === 'arm64' && /Apple (M1|processor)/.test(cpuCore.model))
129
- const linuxInfo = type === 'Linux' ? await getLinuxInfo() : new Map()
130
- const linuxDistro = linuxInfo.get('name')
131
- const release = linuxInfo.get('version') || os.release()
132
- const majorVersion = parseInt(linuxInfo.get('version'), 10) || semver.major(release)
172
+ const linuxInfo = type === 'Linux' ? await getLinuxInfo() : {}
173
+ const linuxDistro = linuxInfo.name
174
+ const release = linuxInfo.version || os.release()
175
+ const majorVersion = parseInt(linuxInfo.version, 10) || semver.major(release)
133
176
 
134
177
  if (logsOpt) {
135
178
  print.info(`OS type: ${linuxDistro || type}\nOS arch: ${arch}\nOS release: ${release}\nOS major version: ${majorVersion}\nCPU model: ${cpuCore.model}`)
@@ -148,6 +191,8 @@ async function getPlatform(logsOpt) {
148
191
  } else if (type === 'Linux') {
149
192
  if (majorVersion === 18) {
150
193
  return 'binary-linux-18'
194
+ } if (majorVersion === 22) {
195
+ return 'binary-linux-22'
151
196
  } else {
152
197
  return 'binary-linux-20'
153
198
  }
@@ -163,13 +208,13 @@ async function getLinuxInfo() {
163
208
  try {
164
209
  let result = await system.run("cat /etc/*-release | grep -E '(^VERSION|^NAME)='", {trim: true})
165
210
  let infoArray = result.replace(/['"]+/g, '').split('\n').map(p => p.split('='))
166
- let infoMap = new Map();
211
+ let linuxInfo = {}
167
212
 
168
213
  infoArray.forEach((val) => {
169
- infoMap.set(val[0].toLowerCase(), val[1])
214
+ linuxInfo[val[0].toLowerCase()] = val[1]
170
215
  });
171
216
 
172
- return infoMap
217
+ return linuxInfo
173
218
  } catch (error) {
174
219
  print.error(`Error fetching the Linux version:\n ${error}`)
175
220
  process.exit(1)
@@ -177,39 +222,21 @@ async function getLinuxInfo() {
177
222
  }
178
223
 
179
224
  async function runDocker(datasource, opts) {
180
- let coverageOpt = opts.get("coverage")
181
- let forceOpt = opts.get("force")
182
- let versionOpt = opts.get("version")
183
- let latestVersion = opts.get("latestVersion")
184
- let recompileOpt = opts.get("recompile")
225
+ let coverageOpt = opts.coverage
226
+ let forceOpt = opts.force
227
+ let versionOpt = opts.version
228
+ let latestVersion = opts.latestVersion
229
+ let recompileOpt = opts.recompile
185
230
 
186
231
  // Remove binary-install-raw binaries, because docker has permission issues
187
232
  // when building the docker images
188
- await filesystem.remove("./node_modules/binary-install-raw/bin")
233
+ await filesystem.remove('./node_modules/binary-install-raw/bin')
189
234
 
190
235
  // Get current working directory
191
236
  let current_folder = await filesystem.cwd()
192
237
 
193
238
  // Declate dockerfilePath with default location
194
- let dockerfilePath = "./tests/.docker/Dockerfile"
195
-
196
- // Check if matchstick.yaml config exists
197
- if(filesystem.exists('matchstick.yaml')) {
198
- try {
199
- // Load the config
200
- let config = await yaml.load(filesystem.read('matchstick.yaml', 'utf8'))
201
-
202
- // Check if matchstick.yaml is not empty
203
- if(config != null) {
204
- // If a custom tests folder is declared update dockerfilePath
205
- dockerfilePath = path.join(config.testsFolder || 'tests', '.docker/Dockerfile')
206
- }
207
- } catch (error) {
208
- print.info('A problem occurred while reading matchstick.yaml. Please attend to the errors below:')
209
- print.error(error.message)
210
- process.exit(1)
211
- }
212
- }
239
+ let dockerfilePath = path.join(opts.testsFolder || 'tests', '.docker/Dockerfile')
213
240
 
214
241
  // Check if the Dockerfil already exists
215
242
  let dockerfileExists = filesystem.exists(dockerfilePath)
package/src/migrations.js CHANGED
@@ -6,10 +6,8 @@ const MIGRATIONS = [
6
6
  require('./migrations/mapping_api_version_0_0_3'),
7
7
  require('./migrations/mapping_api_version_0_0_4'),
8
8
  require('./migrations/mapping_api_version_0_0_5'),
9
- require('./migrations/mapping_api_version_0_0_6'),
10
9
  require('./migrations/spec_version_0_0_2'),
11
10
  require('./migrations/spec_version_0_0_3'),
12
- require('./migrations/spec_version_0_0_4'),
13
11
  ]
14
12
 
15
13
  const applyMigrations = async options =>
@@ -8,7 +8,7 @@ const mapping = () => `
8
8
  - ExampleEntity
9
9
  blockHandlers:
10
10
  - handler: handleBlock
11
- file: ./src/mapping.ts`
11
+ file: ./src/contract.ts`
12
12
 
13
13
  module.exports = {
14
14
  source,
@@ -7,7 +7,7 @@ const protocol = new Protocol('cosmos')
7
7
  const scaffoldOptions = {
8
8
  protocol,
9
9
  network: 'cosmoshub-4',
10
- dataSourceName: 'CosmosHub'
10
+ contractName: 'CosmosHub'
11
11
  }
12
12
 
13
13
  const scaffold = new Scaffold(scaffoldOptions)
@@ -33,7 +33,7 @@ dataSources:
33
33
  - ExampleEntity
34
34
  blockHandlers:
35
35
  - handler: handleBlock
36
- file: ./src/mapping.ts
36
+ file: ./src/contract.ts
37
37
  `)
38
38
  })
39
39
 
@@ -76,8 +76,7 @@ const scaffoldOptions = {
76
76
  abi: TEST_ABI,
77
77
  contract: '0xf87e31492faf9a91b02ee0deaad50d51d56d5d4d',
78
78
  network: 'kovan',
79
- contractName: 'Contract',
80
- dataSourceName: 'Contract'
79
+ contractName: 'Contract'
81
80
  }
82
81
 
83
82
  const scaffold = new Scaffold(scaffoldOptions)
@@ -26,7 +26,6 @@ module.exports = class Scaffold {
26
26
  this.network = options.network
27
27
  this.contractName = options.contractName
28
28
  this.subgraphName = options.subgraphName
29
- this.dataSourceName = options.dataSourceName
30
29
  this.node = options.node
31
30
  }
32
31
 
@@ -68,7 +67,7 @@ schema:
68
67
  file: ./schema.graphql
69
68
  dataSources:
70
69
  - kind: ${this.protocol.name}
71
- name: ${this.dataSourceName}
70
+ name: ${this.contractName}
72
71
  network: ${this.network}
73
72
  source: ${protocolManifest.source(this)}
74
73
  mapping: ${protocolManifest.mapping(this)}
@@ -8,8 +8,7 @@ const scaffoldOptions = {
8
8
  protocol,
9
9
  contract: 'abc.def.near',
10
10
  network: 'near-mainnet',
11
- contractName: 'Contract',
12
- dataSourceName: 'Contract'
11
+ contractName: 'Contract'
13
12
  }
14
13
 
15
14
  const scaffold = new Scaffold(scaffoldOptions)
@@ -1,74 +0,0 @@
1
- const fs = require('fs-extra')
2
- const semver = require('semver')
3
- const toolbox = require('gluegun/toolbox')
4
- const yaml = require('js-yaml')
5
- const { loadManifest } = require('./util/load-manifest')
6
- const { getGraphTsVersion } = require('./util/versions')
7
-
8
- // If any of the manifest apiVersions are 0.0.6, replace them with 0.0.7
9
- module.exports = {
10
- name: 'Bump mapping apiVersion from 0.0.6 to 0.0.7',
11
- predicate: async ({ sourceDir, manifestFile }) => {
12
- // Obtain the graph-ts version, if possible
13
- let graphTsVersion
14
- try {
15
- graphTsVersion = await getGraphTsVersion(sourceDir)
16
- } catch (_) {
17
- // If we cannot obtain the version, return a hint that the graph-ts
18
- // hasn't been installed yet
19
- return 'graph-ts dependency not installed yet'
20
- }
21
-
22
- let manifest = loadManifest(manifestFile)
23
- return (
24
- // Only migrate if the graph-ts version is >= 0.27.0...
25
- // Coerce needed because we may be dealing with an alpha version
26
- // and in the `semver` library this would not return true on equality.
27
- semver.gte(semver.coerce(graphTsVersion), '0.27.0') &&
28
- // ...and we have a manifest with mapping > apiVersion = 0.0.6
29
- manifest &&
30
- typeof manifest === 'object' &&
31
- Array.isArray(manifest.dataSources) &&
32
- (manifest.dataSources.reduce(
33
- (hasOldMappings, dataSource) =>
34
- hasOldMappings ||
35
- (typeof dataSource === 'object' &&
36
- dataSource.mapping &&
37
- typeof dataSource.mapping === 'object' &&
38
- dataSource.mapping.apiVersion === '0.0.6'),
39
- false,
40
- ) ||
41
- (Array.isArray(manifest.templates) &&
42
- manifest.templates.reduce(
43
- (hasOldMappings, template) =>
44
- hasOldMappings ||
45
- (typeof template === 'object' &&
46
- template.mapping &&
47
- typeof template.mapping === 'object' &&
48
- template.mapping.apiVersion === '0.0.6'),
49
- false,
50
- )))
51
- )
52
- },
53
- apply: async ({ manifestFile }) => {
54
- // Make sure we catch all variants; we could load the manifest
55
- // and replace the values in the data structures here; unfortunately
56
- // writing that back to the file messes with the formatting more than
57
- // we'd like; that's why for now, we use a simple patching approach
58
- await toolbox.patching.replace(
59
- manifestFile,
60
- new RegExp('apiVersion: 0.0.6', 'g'),
61
- 'apiVersion: 0.0.7',
62
- )
63
- await toolbox.patching.replace(
64
- manifestFile,
65
- new RegExp("apiVersion: '0.0.6'", 'g'),
66
- "apiVersion: '0.0.7'",
67
- )
68
- await toolbox.patching.replace(
69
- manifestFile,
70
- new RegExp('apiVersion: "0.0.6"', 'g'),
71
- 'apiVersion: "0.0.7"',
72
- )
73
- },
74
- }
@@ -1,25 +0,0 @@
1
- const fs = require('fs-extra')
2
- const toolbox = require('gluegun/toolbox')
3
- const yaml = require('js-yaml')
4
- const { loadManifest } = require('./util/load-manifest')
5
-
6
- // Spec version 0.0.5 let event handlers require transaction receipt
7
- // data to be accessed in the runtime.
8
- module.exports = {
9
- name: 'Bump manifest specVersion from 0.0.4 to 0.0.5',
10
- predicate: async ({ sourceDir, manifestFile }) => {
11
- let manifest = await loadManifest(manifestFile)
12
- return (
13
- manifest &&
14
- typeof manifest === 'object' &&
15
- manifest.specVersion &&
16
- manifest.specVersion === '0.0.4'
17
- )
18
- },
19
- apply: async ({ manifestFile }) => {
20
- await toolbox.patching.patch(manifestFile, {
21
- insert: 'specVersion: 0.0.5',
22
- replace: new RegExp(`specVersion: ['"]?0.0.4['"]?`),
23
- })
24
- },
25
- }