@graphprotocol/graph-cli 0.37.2 → 0.37.3-alpha-20230110163550-d64bef6

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.
Files changed (206) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/babel.config.js +3 -0
  3. package/dist/bin.js +6 -0
  4. package/dist/cli.js +32 -0
  5. package/dist/codegen/schema.js +250 -0
  6. package/dist/codegen/schema.test.js +458 -0
  7. package/dist/codegen/template.js +65 -0
  8. package/dist/codegen/types/conversions.js +359 -0
  9. package/dist/codegen/types/index.js +71 -0
  10. package/dist/codegen/types/index.test.js +563 -0
  11. package/dist/codegen/typescript.js +200 -0
  12. package/dist/codegen/util.js +46 -0
  13. package/dist/codegen/util.test.js +93 -0
  14. package/dist/command-helpers/abi.js +78 -0
  15. package/dist/command-helpers/auth.js +77 -0
  16. package/dist/command-helpers/compiler.js +66 -0
  17. package/dist/command-helpers/data-sources.js +29 -0
  18. package/dist/command-helpers/fs.js +9 -0
  19. package/dist/command-helpers/gluegun.js +49 -0
  20. package/dist/command-helpers/ipfs.js +5 -0
  21. package/dist/command-helpers/jsonrpc.js +29 -0
  22. package/dist/command-helpers/network.js +93 -0
  23. package/dist/command-helpers/network.test.js +86 -0
  24. package/dist/command-helpers/node.js +40 -0
  25. package/dist/command-helpers/scaffold.js +112 -0
  26. package/dist/command-helpers/spinner.js +84 -0
  27. package/dist/command-helpers/studio.js +13 -0
  28. package/dist/command-helpers/studio.test.js +41 -0
  29. package/dist/command-helpers/subgraph.js +24 -0
  30. package/dist/command-helpers/version.js +74 -0
  31. package/dist/command-helpers/version.test.js +179 -0
  32. package/dist/commands/add.js +190 -0
  33. package/dist/commands/auth.js +127 -0
  34. package/dist/commands/build.js +140 -0
  35. package/dist/commands/codegen.js +135 -0
  36. package/dist/commands/create.js +86 -0
  37. package/dist/commands/deploy.js +334 -0
  38. package/dist/commands/init.js +788 -0
  39. package/dist/commands/local.js +387 -0
  40. package/dist/commands/remove.js +86 -0
  41. package/dist/commands/test.js +295 -0
  42. package/dist/compiler/asc.js +83 -0
  43. package/dist/compiler/index.js +474 -0
  44. package/dist/debug.js +16 -0
  45. package/dist/migrations/mapping_api_version_0_0_1.js +78 -0
  46. package/dist/migrations/mapping_api_version_0_0_2.js +76 -0
  47. package/dist/migrations/mapping_api_version_0_0_3.js +78 -0
  48. package/dist/migrations/mapping_api_version_0_0_4.js +80 -0
  49. package/dist/migrations/mapping_api_version_0_0_5.js +80 -0
  50. package/dist/migrations/spec_version_0_0_2.js +49 -0
  51. package/dist/migrations/spec_version_0_0_3.js +54 -0
  52. package/dist/migrations/util/load-manifest.js +18 -0
  53. package/dist/migrations/util/versions.js +29 -0
  54. package/dist/migrations.js +56 -0
  55. package/dist/protocols/arweave/manifest.graphql +57 -0
  56. package/dist/protocols/arweave/scaffold/manifest.js +18 -0
  57. package/dist/protocols/arweave/scaffold/mapping.js +52 -0
  58. package/dist/protocols/arweave/subgraph.js +23 -0
  59. package/dist/protocols/cosmos/manifest.graphql +76 -0
  60. package/dist/protocols/cosmos/scaffold/manifest.js +15 -0
  61. package/dist/protocols/cosmos/scaffold/mapping.js +38 -0
  62. package/dist/protocols/cosmos/subgraph.js +25 -0
  63. package/dist/protocols/ethereum/abi.js +140 -0
  64. package/dist/protocols/ethereum/codegen/abi.js +451 -0
  65. package/dist/protocols/ethereum/codegen/abi.test.js +328 -0
  66. package/dist/protocols/ethereum/codegen/template.js +50 -0
  67. package/dist/protocols/ethereum/contract.js +20 -0
  68. package/dist/protocols/ethereum/manifest.graphql +94 -0
  69. package/dist/protocols/ethereum/scaffold/manifest.js +32 -0
  70. package/dist/protocols/ethereum/scaffold/mapping.js +65 -0
  71. package/dist/protocols/ethereum/subgraph.js +171 -0
  72. package/dist/protocols/ethereum/type-generator.js +125 -0
  73. package/dist/protocols/index.js +268 -0
  74. package/dist/protocols/ipfs/codegen/file_template.js +50 -0
  75. package/dist/protocols/near/contract.js +41 -0
  76. package/dist/protocols/near/manifest.graphql +64 -0
  77. package/dist/protocols/near/scaffold/manifest.js +16 -0
  78. package/dist/protocols/near/scaffold/mapping.js +38 -0
  79. package/dist/protocols/near/subgraph.js +20 -0
  80. package/dist/protocols/subgraph.js +2 -0
  81. package/dist/protocols/substreams/manifest.graphql +45 -0
  82. package/dist/protocols/substreams/scaffold/manifest.js +12 -0
  83. package/dist/protocols/substreams/subgraph.js +23 -0
  84. package/dist/scaffold/cosmos.test.js +83 -0
  85. package/dist/scaffold/ethereum.test.js +505 -0
  86. package/dist/scaffold/index.js +128 -0
  87. package/dist/scaffold/mapping.js +61 -0
  88. package/dist/scaffold/near.test.js +86 -0
  89. package/dist/scaffold/schema.js +83 -0
  90. package/dist/scaffold/tests.js +175 -0
  91. package/dist/schema.js +54 -0
  92. package/dist/subgraph.js +249 -0
  93. package/dist/type-generator.js +224 -0
  94. package/dist/validation/contract.js +46 -0
  95. package/dist/validation/index.js +8 -0
  96. package/dist/validation/manifest.js +271 -0
  97. package/dist/validation/schema.js +796 -0
  98. package/dist/validation/schema.test.js +35 -0
  99. package/dist/watcher.js +79 -0
  100. package/jest.config.js +1 -1
  101. package/package.json +16 -9
  102. package/{bin/graph → src/bin.ts} +2 -1
  103. package/src/cli.ts +36 -0
  104. package/src/codegen/schema.js +23 -22
  105. package/src/codegen/schema.test.js +33 -27
  106. package/src/codegen/{template.js → template.ts} +8 -6
  107. package/src/codegen/types/conversions.ts +382 -0
  108. package/src/codegen/types/index.js +4 -7
  109. package/src/codegen/types/index.test.js +10 -4
  110. package/src/codegen/{typescript.js → typescript.ts} +44 -26
  111. package/src/codegen/util.js +1 -1
  112. package/src/codegen/util.test.js +5 -2
  113. package/src/command-helpers/abi.js +46 -30
  114. package/src/command-helpers/auth.js +6 -9
  115. package/src/command-helpers/compiler.js +4 -6
  116. package/src/command-helpers/data-sources.js +8 -11
  117. package/src/command-helpers/fs.ts +5 -0
  118. package/src/command-helpers/gluegun.js +2 -4
  119. package/src/command-helpers/ipfs.ts +3 -0
  120. package/src/command-helpers/{jsonrpc.js → jsonrpc.ts} +11 -16
  121. package/src/command-helpers/network.js +58 -44
  122. package/src/command-helpers/network.test.js +23 -19
  123. package/src/command-helpers/node.js +3 -7
  124. package/src/command-helpers/scaffold.js +34 -25
  125. package/src/command-helpers/{spinner.js → spinner.ts} +10 -10
  126. package/src/command-helpers/studio.test.js +61 -30
  127. package/src/command-helpers/studio.ts +20 -0
  128. package/src/command-helpers/{subgraph.js → subgraph.ts} +6 -6
  129. package/src/command-helpers/version.js +11 -16
  130. package/src/command-helpers/version.test.js +111 -82
  131. package/src/commands/add.js +49 -35
  132. package/src/commands/auth.js +13 -25
  133. package/src/commands/build.js +9 -9
  134. package/src/commands/codegen.js +12 -12
  135. package/src/commands/create.js +22 -22
  136. package/src/commands/deploy.js +39 -34
  137. package/src/commands/init.js +21 -24
  138. package/src/commands/local.js +15 -14
  139. package/src/commands/remove.js +22 -22
  140. package/src/commands/test.js +86 -70
  141. package/src/compiler/{asc.js → asc.ts} +29 -16
  142. package/src/compiler/index.js +18 -18
  143. package/src/{debug.js → debug.ts} +2 -2
  144. package/src/migrations/mapping_api_version_0_0_1.js +7 -7
  145. package/src/migrations/mapping_api_version_0_0_2.js +5 -5
  146. package/src/migrations/mapping_api_version_0_0_3.js +7 -7
  147. package/src/migrations/mapping_api_version_0_0_4.js +7 -7
  148. package/src/migrations/mapping_api_version_0_0_5.js +7 -7
  149. package/src/migrations/spec_version_0_0_2.js +5 -5
  150. package/src/migrations/spec_version_0_0_3.js +5 -5
  151. package/src/migrations/util/load-manifest.js +6 -9
  152. package/src/migrations/util/versions.js +5 -10
  153. package/src/{migrations.js → migrations.ts} +14 -15
  154. package/src/protocols/arweave/scaffold/manifest.js +1 -4
  155. package/src/protocols/arweave/scaffold/mapping.js +1 -3
  156. package/src/protocols/arweave/subgraph.ts +22 -0
  157. package/src/protocols/cosmos/scaffold/manifest.js +1 -4
  158. package/src/protocols/cosmos/scaffold/mapping.js +1 -3
  159. package/src/protocols/cosmos/subgraph.js +2 -2
  160. package/src/protocols/ethereum/abi.js +7 -13
  161. package/src/protocols/ethereum/codegen/abi.js +219 -222
  162. package/src/protocols/ethereum/codegen/abi.test.js +6 -6
  163. package/src/protocols/ethereum/codegen/template.js +3 -5
  164. package/src/protocols/ethereum/contract.js +3 -2
  165. package/src/protocols/ethereum/scaffold/manifest.js +4 -7
  166. package/src/protocols/ethereum/scaffold/mapping.js +4 -11
  167. package/src/protocols/ethereum/subgraph.js +21 -20
  168. package/src/protocols/ethereum/type-generator.js +24 -30
  169. package/src/protocols/{index.js → index.ts} +65 -46
  170. package/src/protocols/ipfs/codegen/file_template.js +2 -2
  171. package/src/protocols/near/{contract.js → contract.ts} +16 -12
  172. package/src/protocols/near/scaffold/manifest.js +2 -5
  173. package/src/protocols/near/scaffold/mapping.js +1 -3
  174. package/src/protocols/near/subgraph.js +3 -6
  175. package/src/protocols/subgraph.ts +12 -0
  176. package/src/protocols/substreams/scaffold/{manifest.js → manifest.ts} +2 -7
  177. package/src/protocols/substreams/subgraph.ts +22 -0
  178. package/src/scaffold/cosmos.test.js +3 -3
  179. package/src/scaffold/ethereum.test.js +4 -4
  180. package/src/scaffold/index.js +7 -7
  181. package/src/scaffold/mapping.js +3 -3
  182. package/src/scaffold/near.test.js +3 -3
  183. package/src/scaffold/schema.js +4 -4
  184. package/src/scaffold/tests.js +72 -58
  185. package/src/schema.ts +26 -0
  186. package/src/{subgraph.js → subgraph.ts} +80 -60
  187. package/src/type-generator.js +20 -20
  188. package/src/validation/contract.js +2 -6
  189. package/src/validation/index.js +1 -1
  190. package/src/validation/manifest.js +24 -22
  191. package/src/validation/schema.test.js +1 -1
  192. package/src/validation/{schema.js → schema.ts} +268 -221
  193. package/src/{watcher.js → watcher.ts} +23 -12
  194. package/tests/cli/globalSetup.js +2 -2
  195. package/tests/cli/globalTeardown.js +2 -2
  196. package/tests/cli/init.test.js +2 -2
  197. package/tests/cli/util.js +7 -13
  198. package/tsconfig.json +18 -0
  199. package/src/cli.js +0 -38
  200. package/src/codegen/types/conversions.js +0 -329
  201. package/src/command-helpers/fs.js +0 -8
  202. package/src/command-helpers/ipfs.js +0 -6
  203. package/src/command-helpers/studio.js +0 -15
  204. package/src/protocols/arweave/subgraph.js +0 -20
  205. package/src/protocols/substreams/subgraph.js +0 -17
  206. package/src/schema.js +0 -23
@@ -1,8 +1,8 @@
1
- const URL = require('url').URL
2
- const chalk = require('chalk')
3
- const { validateNodeUrl } = require('../command-helpers/node')
4
- const { identifyDeployKey: identifyAccessToken } = require('../command-helpers/auth')
5
- const { createJsonRpcClient } = require('../command-helpers/jsonrpc')
1
+ import { URL } from 'url'
2
+ import chalk from 'chalk'
3
+ import { validateNodeUrl } from '../command-helpers/node'
4
+ import { identifyDeployKey as identifyAccessToken } from '../command-helpers/auth'
5
+ import { createJsonRpcClient } from '../command-helpers/jsonrpc'
6
6
 
7
7
  const HELP = `
8
8
  ${chalk.bold('graph remove')} ${chalk.dim('[options]')} ${chalk.bold('<subgraph-name>')}
@@ -14,7 +14,7 @@ ${chalk.dim('Options:')}
14
14
  -g, --node <url> Graph node to create the subgraph in
15
15
  `
16
16
 
17
- module.exports = {
17
+ export default {
18
18
  description: 'Unregisters a subgraph name',
19
19
  run: async toolbox => {
20
20
  // Obtain tools
@@ -73,21 +73,21 @@ module.exports = {
73
73
  }
74
74
 
75
75
  let spinner = print.spin(`Creating subgraph in Graph node: ${requestUrl}`)
76
- client.request('subgraph_remove', { name: subgraphName }, function(
77
- requestError,
78
- jsonRpcError,
79
- res
80
- ) {
81
- if (jsonRpcError) {
82
- spinner.fail(`Error removing the subgraph: ${jsonRpcError.message}`)
83
- process.exitCode = 1
84
- } else if (requestError) {
85
- spinner.fail(`HTTP error removing the subgraph: ${requestError.code}`)
86
- process.exitCode = 1
87
- } else {
88
- spinner.stop()
89
- print.success(`Removed subgraph: ${subgraphName}`)
90
- }
91
- })
76
+ client.request(
77
+ 'subgraph_remove',
78
+ { name: subgraphName },
79
+ function (requestError, jsonRpcError, res) {
80
+ if (jsonRpcError) {
81
+ spinner.fail(`Error removing the subgraph: ${jsonRpcError.message}`)
82
+ process.exitCode = 1
83
+ } else if (requestError) {
84
+ spinner.fail(`HTTP error removing the subgraph: ${requestError.code}`)
85
+ process.exitCode = 1
86
+ } else {
87
+ spinner.stop()
88
+ print.success(`Removed subgraph: ${subgraphName}`)
89
+ }
90
+ },
91
+ )
92
92
  },
93
93
  }
@@ -1,13 +1,13 @@
1
- const { Binary } = require('binary-install-raw')
2
- const os = require('os')
3
- const chalk = require('chalk')
4
- const fetch = require('node-fetch')
5
- const { filesystem, patching, print, system } = require('gluegun')
6
- const { fixParameters } = require('../command-helpers/gluegun')
7
- const path = require('path')
8
- const semver = require('semver')
9
- const { spawn, exec } = require('child_process')
10
- const yaml = require('js-yaml')
1
+ import { Binary } from 'binary-install-raw'
2
+ import os from 'os'
3
+ import chalk from 'chalk'
4
+ import fetch from 'node-fetch'
5
+ import { filesystem, patching, print, system } from 'gluegun'
6
+ import { fixParameters } from '../command-helpers/gluegun'
7
+ import path from 'path'
8
+ import semver from 'semver'
9
+ import { spawn, exec } from 'child_process'
10
+ import yaml from 'js-yaml'
11
11
 
12
12
  const HELP = `
13
13
  ${chalk.bold('graph test')} ${chalk.dim('[options]')} ${chalk.bold('<datasource>')}
@@ -22,26 +22,12 @@ ${chalk.dim('Options:')}
22
22
  -v, --version <tag> Choose the version of the rust binary that you want to be downloaded/used
23
23
  `
24
24
 
25
- module.exports = {
25
+ export default {
26
26
  description: 'Runs rust binary for subgraph testing',
27
27
  run: async toolbox => {
28
28
  // Read CLI parameters
29
- let {
30
- c,
31
- coverage,
32
- d,
33
- docker,
34
- f,
35
- force,
36
- h,
37
- help,
38
- l,
39
- logs,
40
- r,
41
- recompile,
42
- v,
43
- version,
44
- } = toolbox.parameters.options
29
+ let { c, coverage, d, docker, f, force, h, help, l, logs, r, recompile, v, version } =
30
+ toolbox.parameters.options
45
31
 
46
32
  let opts = {}
47
33
  // Support both long and short option variants
@@ -67,7 +53,7 @@ module.exports = {
67
53
  l,
68
54
  logs,
69
55
  r,
70
- recompile
56
+ recompile,
71
57
  })
72
58
  } catch (e) {
73
59
  print.error(e.message)
@@ -83,18 +69,20 @@ module.exports = {
83
69
  }
84
70
 
85
71
  // Check if matchstick.yaml config exists
86
- if(filesystem.exists('matchstick.yaml')) {
72
+ if (filesystem.exists('matchstick.yaml')) {
87
73
  try {
88
74
  // Load the config
89
75
  let config = await yaml.load(filesystem.read('matchstick.yaml', 'utf8'))
90
76
 
91
77
  // Check if matchstick.yaml and testsFolder not null
92
- if(config && config.testsFolder) {
78
+ if (config && config.testsFolder) {
93
79
  // assign test folder from matchstick.yaml if present
94
80
  opts.testsFolder = config.testsFolder
95
81
  }
96
82
  } catch (error) {
97
- print.info('A problem occurred while reading matchstick.yaml. Please attend to the errors below:')
83
+ print.info(
84
+ 'A problem occurred while reading matchstick.yaml. Please attend to the errors below:',
85
+ )
98
86
  print.error(error.message)
99
87
  process.exit(1)
100
88
  }
@@ -105,29 +93,31 @@ module.exports = {
105
93
 
106
94
  // Fetch the latest version tag if version is not specified with -v/--version or if the version is not cached
107
95
  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')
96
+ print.info('Fetching latest version tag')
97
+ let result = await fetch(
98
+ 'https://api.github.com/repos/LimeChain/matchstick/releases/latest',
99
+ )
110
100
  let json = await result.json()
111
101
  opts.latestVersion = json.tag_name
112
102
 
113
103
  filesystem.file(opts.cachePath, {
114
104
  content: {
115
105
  version: json.tag_name,
116
- timestamp: Date.now()
117
- }
106
+ timestamp: Date.now(),
107
+ },
118
108
  })
119
109
  }
120
110
 
121
- if(opts.docker) {
111
+ if (opts.docker) {
122
112
  runDocker(datasource, opts)
123
113
  } else {
124
114
  runBinary(datasource, opts)
125
115
  }
126
- }
116
+ },
127
117
  }
128
118
 
129
119
  async function setVersionFromCache(opts) {
130
- if(filesystem.exists(opts.cachePath) == 'file') {
120
+ if (filesystem.exists(opts.cachePath) == 'file') {
131
121
  let cached = filesystem.read(opts.cachePath, 'json')
132
122
  // Get the cache age in days
133
123
  let cacheAge = (Date.now() - cached.timestamp) / (1000 * 60 * 60 * 24)
@@ -148,7 +138,9 @@ async function runBinary(datasource, opts) {
148
138
 
149
139
  const platform = await getPlatform(logsOpt)
150
140
 
151
- const url = `https://github.com/LimeChain/matchstick/releases/download/${versionOpt || latestVersion}/${platform}`
141
+ const url = `https://github.com/LimeChain/matchstick/releases/download/${
142
+ versionOpt || latestVersion
143
+ }/${platform}`
152
144
 
153
145
  if (logsOpt) {
154
146
  print.info(`Download link: ${url}`)
@@ -168,14 +160,20 @@ async function getPlatform(logsOpt) {
168
160
  const type = os.type()
169
161
  const arch = os.arch()
170
162
  const cpuCore = os.cpus()[0]
171
- const isAppleSilicon = (arch === 'arm64' && /Apple (M1|M2|processor)/.test(cpuCore.model))
163
+ const isAppleSilicon = arch === 'arm64' && /Apple (M1|M2|processor)/.test(cpuCore.model)
172
164
  const linuxInfo = type === 'Linux' ? await getLinuxInfo() : {}
173
165
  const linuxDistro = linuxInfo.name
174
166
  const release = linuxInfo.version || os.release()
175
167
  const majorVersion = parseInt(linuxInfo.version, 10) || semver.major(release)
176
168
 
177
169
  if (logsOpt) {
178
- print.info(`OS type: ${linuxDistro || type}\nOS arch: ${arch}\nOS release: ${release}\nOS major version: ${majorVersion}\nCPU model: ${cpuCore.model}`)
170
+ print.info(
171
+ `OS type: ${
172
+ linuxDistro || type
173
+ }\nOS arch: ${arch}\nOS release: ${release}\nOS major version: ${majorVersion}\nCPU model: ${
174
+ cpuCore.model
175
+ }`,
176
+ )
179
177
  }
180
178
 
181
179
  if (arch === 'x64' || isAppleSilicon) {
@@ -189,7 +187,8 @@ async function getPlatform(logsOpt) {
189
187
  } else if (type === 'Linux') {
190
188
  if (majorVersion === 18) {
191
189
  return 'binary-linux-18'
192
- } if (majorVersion === 22) {
190
+ }
191
+ if (majorVersion === 22) {
193
192
  return 'binary-linux-22'
194
193
  } else {
195
194
  return 'binary-linux-20'
@@ -202,13 +201,18 @@ async function getPlatform(logsOpt) {
202
201
 
203
202
  async function getLinuxInfo() {
204
203
  try {
205
- let result = await system.run("cat /etc/*-release | grep -E '(^VERSION|^NAME)='", {trim: true})
206
- let infoArray = result.replace(/['"]+/g, '').split('\n').map(p => p.split('='))
204
+ let result = await system.run("cat /etc/*-release | grep -E '(^VERSION|^NAME)='", {
205
+ trim: true,
206
+ })
207
+ let infoArray = result
208
+ .replace(/['"]+/g, '')
209
+ .split('\n')
210
+ .map(p => p.split('='))
207
211
  let linuxInfo = {}
208
212
 
209
- infoArray.forEach((val) => {
213
+ infoArray.forEach(val => {
210
214
  linuxInfo[val[0].toLowerCase()] = val[1]
211
- });
215
+ })
212
216
 
213
217
  return linuxInfo
214
218
  } catch (error) {
@@ -239,7 +243,7 @@ async function runDocker(datasource, opts) {
239
243
 
240
244
  // Generate the Dockerfile only if it doesn't exists,
241
245
  // version flag and/or force flag is passed.
242
- if(!dockerfileExists || versionOpt || forceOpt) {
246
+ if (!dockerfileExists || versionOpt || forceOpt) {
243
247
  await dockerfile(dockerfilePath, versionOpt, latestVersion)
244
248
  }
245
249
 
@@ -252,9 +256,15 @@ async function runDocker(datasource, opts) {
252
256
  if (datasource) testArgs = testArgs + ' ' + datasource
253
257
 
254
258
  // Build the `docker run` command options and flags
255
- let dockerRunOpts = ['run', '-it', '--rm', '--mount', `type=bind,source=${current_folder},target=/matchstick`]
256
-
257
- if(testArgs !== '') {
259
+ let dockerRunOpts = [
260
+ 'run',
261
+ '-it',
262
+ '--rm',
263
+ '--mount',
264
+ `type=bind,source=${current_folder},target=/matchstick`,
265
+ ]
266
+
267
+ if (testArgs !== '') {
258
268
  dockerRunOpts.push('-e')
259
269
  dockerRunOpts.push(`ARGS=${testArgs.trim()}`)
260
270
  }
@@ -265,7 +275,7 @@ async function runDocker(datasource, opts) {
265
275
  // else it'll return the image ID. Skip `docker build` if an image already exists
266
276
  // Delete current image(if any) and rebuild.
267
277
  // Use spawn() and {stdio: 'inherit'} so we can see the logs in real time.
268
- if(!dockerfileExists || stdout === '' || versionOpt || forceOpt) {
278
+ if (!dockerfileExists || stdout === '' || versionOpt || forceOpt) {
269
279
  if (stdout !== '') {
270
280
  exec('docker image rm matchstick', (error, stdout, stderr) => {
271
281
  print.info(chalk.bold(`Removing matchstick image\n${stdout}`))
@@ -273,17 +283,15 @@ async function runDocker(datasource, opts) {
273
283
  }
274
284
  // Build a docker image. If the process has executed successfully
275
285
  // run a container from that image.
276
- spawn(
277
- 'docker',
278
- ['build', '-f', dockerfilePath, '-t', 'matchstick', '.'],
279
- { stdio: 'inherit' }
280
- ).on('close', code => {
286
+ spawn('docker', ['build', '-f', dockerfilePath, '-t', 'matchstick', '.'], {
287
+ stdio: 'inherit',
288
+ }).on('close', code => {
281
289
  if (code === 0) {
282
- spawn('docker', dockerRunOpts, { stdio: 'inherit' })
290
+ spawn('docker', dockerRunOpts, { stdio: 'inherit' })
283
291
  }
284
292
  })
285
293
  } else {
286
- print.info("Docker image already exists. Skipping `docker build` command.")
294
+ print.info('Docker image already exists. Skipping `docker build` command.')
287
295
  // Run the container from the existing matchstick docker image
288
296
  spawn('docker', dockerRunOpts, { stdio: 'inherit' })
289
297
  }
@@ -293,27 +301,35 @@ async function runDocker(datasource, opts) {
293
301
  // Downloads Dockerfile template from the demo-subgraph repo
294
302
  // Replaces the placeholders with their respective values
295
303
  async function dockerfile(dockerfilePath, versionOpt, latestVersion) {
296
- let spinner = print.spin("Generating Dockerfile...")
304
+ let spinner = print.spin('Generating Dockerfile...')
297
305
 
298
306
  try {
299
307
  // Fetch the Dockerfile template content from the demo-subgraph repo
300
- let content = await fetch('https://raw.githubusercontent.com/LimeChain/demo-subgraph/main/Dockerfile')
301
- .then((response) => {
302
- if (response.ok) {
303
- return response.text()
304
- } else {
305
- throw new Error(`Status Code: ${response.status}, with error: ${response.statusText}`);
306
- }
307
- })
308
+ let content = await fetch(
309
+ 'https://raw.githubusercontent.com/LimeChain/demo-subgraph/main/Dockerfile',
310
+ ).then(response => {
311
+ if (response.ok) {
312
+ return response.text()
313
+ } else {
314
+ throw new Error(
315
+ `Status Code: ${response.status}, with error: ${response.statusText}`,
316
+ )
317
+ }
318
+ })
308
319
 
309
320
  // Write the Dockerfile
310
321
  await filesystem.write(dockerfilePath, content)
311
322
 
312
323
  // Replaces the version placeholders
313
- await patching.replace(dockerfilePath, '<MATCHSTICK_VERSION>', versionOpt || latestVersion)
314
-
324
+ await patching.replace(
325
+ dockerfilePath,
326
+ '<MATCHSTICK_VERSION>',
327
+ versionOpt || latestVersion,
328
+ )
315
329
  } catch (error) {
316
- spinner.fail(`A problem occurred while generating the Dockerfile. Please attend to the errors below:\n ${error.message}`)
330
+ spinner.fail(
331
+ `A problem occurred while generating the Dockerfile. Please attend to the errors below:\n ${error.message}`,
332
+ )
317
333
  process.exit(1)
318
334
  }
319
335
 
@@ -1,6 +1,6 @@
1
- const asc = require('assemblyscript/cli/asc')
1
+ import * as asc from 'assemblyscript/cli/asc'
2
2
 
3
- const createExitHandler = inputFile => () => {
3
+ const createExitHandler = (inputFile: string) => () => {
4
4
  throw new Error(`The AssemblyScript compiler crashed when compiling this file: '${inputFile}'
5
5
  Suggestion: try to comment the whole file and uncomment it little by little while re-running the graph-cli until you isolate the line where the problem happens.
6
6
  Also, please contact us so we can make the CLI better by handling errors like this. You can reach out in any of these links:
@@ -8,17 +8,21 @@ Also, please contact us so we can make the CLI better by handling errors like th
8
8
  - Github issues: https://github.com/graphprotocol/graph-cli/issues`)
9
9
  }
10
10
 
11
- const setupExitHandler = exitHandler => process.addListener('exit', exitHandler)
11
+ const setupExitHandler = (exitHandler: (code: number) => void) =>
12
+ process.addListener('exit', exitHandler)
12
13
 
13
- const removeExitHandler = exitHandler => process.removeListener('exit', exitHandler)
14
+ const removeExitHandler = (exitHandler: (code: number) => void) =>
15
+ process.removeListener('exit', exitHandler)
14
16
 
15
17
  // Important note, the `asc.main` callback function parameter is synchronous,
16
18
  // that's why this function doesn't need to be `async` and the throw works properly.
17
- const assemblyScriptCompiler = (...args) => asc.main(...args, err => {
18
- if (err) {
19
- throw err
20
- }
21
- })
19
+ const assemblyScriptCompiler = (argv: string[], options: asc.APIOptions) =>
20
+ asc.main(argv, options, err => {
21
+ if (err) {
22
+ throw err
23
+ }
24
+ return 0
25
+ })
22
26
 
23
27
  const compilerDefaults = {
24
28
  stdout: process.stdout,
@@ -28,15 +32,29 @@ const compilerDefaults = {
28
32
  // You MUST call this function once before compiling anything.
29
33
  // Internally it just delegates to the AssemblyScript compiler
30
34
  // which just delegates to the binaryen lib.
31
- const ready = async () => {
35
+ export const ready = async () => {
32
36
  await asc.ready
33
37
  }
34
38
 
39
+ export interface CompileOptions {
40
+ inputFile: string
41
+ global: string
42
+ baseDir: string
43
+ libs: string
44
+ outputFile: string
45
+ }
46
+
35
47
  // For now this function doesn't check if `asc` is ready, because
36
48
  // it requires an asynchronous wait. Whenever you call this function,
37
49
  // it doesn't matter how many times, just make sure you call `ready`
38
50
  // once before everything..
39
- const compile = ({ inputFile, global, baseDir, libs, outputFile }) => {
51
+ export const compile = ({
52
+ inputFile,
53
+ global,
54
+ baseDir,
55
+ libs,
56
+ outputFile,
57
+ }: CompileOptions) => {
40
58
  const exitHandler = createExitHandler(inputFile)
41
59
 
42
60
  setupExitHandler(exitHandler)
@@ -63,8 +81,3 @@ const compile = ({ inputFile, global, baseDir, libs, outputFile }) => {
63
81
  // only if compiler succeded, that is, when the line above doesn't throw
64
82
  removeExitHandler(exitHandler)
65
83
  }
66
-
67
- module.exports = {
68
- ready,
69
- compile,
70
- }
@@ -1,19 +1,19 @@
1
- const chalk = require('chalk')
2
- const crypto = require('crypto')
3
- const fs = require('fs-extra')
4
- const immutable = require('immutable')
5
- const path = require('path')
6
- const yaml = require('js-yaml')
7
- const toolbox = require('gluegun/toolbox')
8
-
9
- const { step, withSpinner } = require('../command-helpers/spinner')
10
- const Subgraph = require('../subgraph')
11
- const Watcher = require('../watcher')
12
- const { applyMigrations } = require('../migrations')
13
- const asc = require('./asc')
14
- const SubstreamsSubgraph = require('../protocols/substreams/subgraph')
15
-
16
- let compilerDebug = require('../debug')('graph-cli:compiler')
1
+ import chalk from 'chalk'
2
+ import crypto from 'crypto'
3
+ import fs from 'fs-extra'
4
+ import immutable from 'immutable'
5
+ import path from 'path'
6
+ import yaml from 'js-yaml'
7
+ import * as toolbox from 'gluegun/toolbox'
8
+ import { step, withSpinner } from '../command-helpers/spinner'
9
+ import Subgraph from '../subgraph'
10
+ import Watcher from '../watcher'
11
+ import { applyMigrations } from '../migrations'
12
+ import * as asc from './asc'
13
+ import SubstreamsSubgraph from '../protocols/substreams/subgraph'
14
+ import debug from '../debug'
15
+
16
+ let compilerDebug = debug('graph-cli:compiler')
17
17
 
18
18
  class Compiler {
19
19
  constructor(options) {
@@ -59,7 +59,7 @@ class Compiler {
59
59
  this.protocol = this.options.protocol
60
60
  this.ABI = this.protocol.getABI()
61
61
 
62
- process.on('uncaughtException', function(e) {
62
+ process.on('uncaughtException', function (e) {
63
63
  toolbox.print.error(`UNCAUGHT EXCEPTION: ${e}`)
64
64
  })
65
65
  }
@@ -681,4 +681,4 @@ class Compiler {
681
681
  }
682
682
  }
683
683
 
684
- module.exports = Compiler
684
+ export default Compiler
@@ -1,4 +1,4 @@
1
- const debugFactory = require('debug')
1
+ import debugFactory from 'debug'
2
2
 
3
3
  debugFactory.formatters.L = immutableList => {
4
4
  return JSON.stringify(immutableList)
@@ -12,4 +12,4 @@ debugFactory.formatters.M = immutableMap => {
12
12
  return immutableMap
13
13
  }
14
14
 
15
- module.exports = debugFactory
15
+ export default debugFactory
@@ -1,12 +1,12 @@
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 { getGraphTsVersion } = require('./util/versions')
6
- const { loadManifest } = require('./util/load-manifest')
1
+ import fs from 'fs-extra'
2
+ import semver from 'semver'
3
+ import * as toolbox from 'gluegun/toolbox'
4
+ import yaml from 'js-yaml'
5
+ import { getGraphTsVersion } from './util/versions'
6
+ import { loadManifest } from './util/load-manifest'
7
7
 
8
8
  // If any of the manifest apiVersions are 0.0.1, replace them with 0.0.2
9
- module.exports = {
9
+ export default {
10
10
  name: 'Bump mapping apiVersion from 0.0.1 to 0.0.2',
11
11
  predicate: async ({ sourceDir, manifestFile }) => {
12
12
  // Obtain the graph-ts version, if possible
@@ -1,10 +1,10 @@
1
- const semver = require('semver')
2
- const toolbox = require('gluegun/toolbox')
3
- const { loadManifest } = require('./util/load-manifest')
4
- const { getGraphTsVersion } = require('./util/versions')
1
+ import semver from 'semver'
2
+ import * as toolbox from 'gluegun/toolbox'
3
+ import { loadManifest } from './util/load-manifest'
4
+ import { getGraphTsVersion } from './util/versions'
5
5
 
6
6
  // If any of the manifest apiVersions are 0.0.2, replace them with 0.0.3
7
- module.exports = {
7
+ export default {
8
8
  name: 'Bump mapping apiVersion from 0.0.2 to 0.0.3',
9
9
  predicate: async ({ sourceDir, manifestFile }) => {
10
10
  // Obtain the graph-ts version, if possible
@@ -1,12 +1,12 @@
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')
1
+ import fs from 'fs-extra'
2
+ import semver from 'semver'
3
+ import * as toolbox from 'gluegun/toolbox'
4
+ import yaml from 'js-yaml'
5
+ import { loadManifest } from './util/load-manifest'
6
+ import { getGraphTsVersion } from './util/versions'
7
7
 
8
8
  // If any of the manifest apiVersions are 0.0.3, replace them with 0.0.4
9
- module.exports = {
9
+ export default {
10
10
  name: 'Bump mapping apiVersion from 0.0.3 to 0.0.4',
11
11
  predicate: async ({ sourceDir, manifestFile }) => {
12
12
  // Obtain the graph-ts version, if possible
@@ -1,12 +1,12 @@
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')
1
+ import fs from 'fs-extra'
2
+ import semver from 'semver'
3
+ import * as toolbox from 'gluegun/toolbox'
4
+ import yaml from 'js-yaml'
5
+ import { loadManifest } from './util/load-manifest'
6
+ import { getGraphTsVersion } from './util/versions'
7
7
 
8
8
  // If any of the manifest apiVersions are 0.0.4, replace them with 0.0.5
9
- module.exports = {
9
+ export default {
10
10
  name: 'Bump mapping apiVersion from 0.0.4 to 0.0.5',
11
11
  predicate: async ({ sourceDir, manifestFile }) => {
12
12
  // Obtain the graph-ts version, if possible
@@ -1,12 +1,12 @@
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')
1
+ import fs from 'fs-extra'
2
+ import semver from 'semver'
3
+ import * as toolbox from 'gluegun/toolbox'
4
+ import yaml from 'js-yaml'
5
+ import { loadManifest } from './util/load-manifest'
6
+ import { getGraphTsVersion } from './util/versions'
7
7
 
8
8
  // If any of the manifest apiVersions are 0.0.5, replace them with 0.0.6
9
- module.exports = {
9
+ export default {
10
10
  name: 'Bump mapping apiVersion from 0.0.5 to 0.0.6',
11
11
  predicate: async ({ sourceDir, manifestFile }) => {
12
12
  // Obtain the graph-ts version, if possible
@@ -1,11 +1,11 @@
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')
1
+ import fs from 'fs-extra'
2
+ import * as toolbox from 'gluegun/toolbox'
3
+ import yaml from 'js-yaml'
4
+ import { loadManifest } from './util/load-manifest'
5
5
 
6
6
  // Spec version to 0.0.2 uses top level templates. graph-cli no longer supports
7
7
  // 0.0.1 which used nested templates.
8
- module.exports = {
8
+ export default {
9
9
  name: 'Bump manifest specVersion from 0.0.1 to 0.0.2',
10
10
  predicate: async ({ sourceDir, manifestFile }) => {
11
11
  let manifest = await loadManifest(manifestFile)
@@ -1,7 +1,7 @@
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')
1
+ import fs from 'fs-extra'
2
+ import * as toolbox from 'gluegun/toolbox'
3
+ import yaml from 'js-yaml'
4
+ import { loadManifest } from './util/load-manifest'
5
5
 
6
6
  // Spec version 0.0.4 uses feature management, but features are
7
7
  // detected and validated by the graph-node instance during subgraph
@@ -9,7 +9,7 @@ const { loadManifest } = require('./util/load-manifest')
9
9
  //
10
10
  // Also, we skip spec version 0.0.3, which is considered invalid and
11
11
  // non-canonical.
12
- module.exports = {
12
+ export default {
13
13
  name: 'Bump manifest specVersion from 0.0.2 to 0.0.4',
14
14
  predicate: async ({ sourceDir, manifestFile }) => {
15
15
  let manifest = await loadManifest(manifestFile)