@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,6 +1,6 @@
1
- const { withSpinner } = require('./spinner')
2
- const fetch = require('node-fetch')
3
- const immutable = require('immutable')
1
+ import { withSpinner } from './spinner'
2
+ import fetch from 'node-fetch'
3
+ import immutable from 'immutable'
4
4
 
5
5
  const loadAbiFromEtherscan = async (ABI, network, address) =>
6
6
  await withSpinner(
@@ -8,7 +8,7 @@ const loadAbiFromEtherscan = async (ABI, network, address) =>
8
8
  `Failed to fetch ABI from Etherscan`,
9
9
  `Warnings while fetching ABI from Etherscan`,
10
10
  async spinner => {
11
- const scanApiUrl = getEtherscanLikeAPIUrl(network);
11
+ const scanApiUrl = getEtherscanLikeAPIUrl(network)
12
12
  let result = await fetch(
13
13
  `${scanApiUrl}?module=contract&action=getabi&address=${address}`,
14
14
  )
@@ -32,9 +32,10 @@ const loadAbiFromBlockScout = async (ABI, network, address) =>
32
32
  `Warnings while fetching ABI from BlockScout`,
33
33
  async spinner => {
34
34
  let result = await fetch(
35
- `https://blockscout.com/${
36
- network.replace('-', '/')
37
- }/api?module=contract&action=getabi&address=${address}`,
35
+ `https://blockscout.com/${network.replace(
36
+ '-',
37
+ '/',
38
+ )}/api?module=contract&action=getabi&address=${address}`,
38
39
  )
39
40
  let json = await result.json()
40
41
 
@@ -49,30 +50,45 @@ const loadAbiFromBlockScout = async (ABI, network, address) =>
49
50
  },
50
51
  )
51
52
 
52
- const getEtherscanLikeAPIUrl = (network) => {
53
+ const getEtherscanLikeAPIUrl = network => {
53
54
  switch (network) {
54
- case "mainnet": return `https://api.etherscan.io/api`
55
- case "arbitrum-one": return `https://api.arbiscan.io/api`
56
- case "bsc": return `https://api.bscscan.com/api`
57
- case "matic": return `https://api.polygonscan.com/api`
58
- case "mumbai": return `https://api-testnet.polygonscan.com/api`
59
- case "aurora": return `https://api.aurorascan.dev/api`
60
- case "aurora-testnet": return `https://api-testnet.aurorascan.dev/api`
61
- case "optimism-kovan": return `https://api-kovan-optimistic.etherscan.io/api`
62
- case "optimism": return `https://api-optimistic.etherscan.io/api`
63
- case "moonbeam": return `https://api-moonbeam.moonscan.io/api`
64
- case "moonriver": return `https://api-moonriver.moonscan.io/api`
65
- case "mbase": return `https://api-moonbase.moonscan.io/api`
66
- case "avalanche": return `https://api.snowtrace.io/api`;
67
- case "fuji": return `https://api-testnet.snowtrace.io/api`;
68
- case "gnosis": return `https://api.gnosisscan.io/api`;
69
- case "fantom": return `https://api.ftmscan.com/api`;
70
- case "fantom-testnet": return `https://api-testnet.ftmscan.com/api`;
71
- default: return `https://api-${network}.etherscan.io/api`
55
+ case 'mainnet':
56
+ return `https://api.etherscan.io/api`
57
+ case 'arbitrum-one':
58
+ return `https://api.arbiscan.io/api`
59
+ case 'bsc':
60
+ return `https://api.bscscan.com/api`
61
+ case 'matic':
62
+ return `https://api.polygonscan.com/api`
63
+ case 'mumbai':
64
+ return `https://api-testnet.polygonscan.com/api`
65
+ case 'aurora':
66
+ return `https://api.aurorascan.dev/api`
67
+ case 'aurora-testnet':
68
+ return `https://api-testnet.aurorascan.dev/api`
69
+ case 'optimism-kovan':
70
+ return `https://api-kovan-optimistic.etherscan.io/api`
71
+ case 'optimism':
72
+ return `https://api-optimistic.etherscan.io/api`
73
+ case 'moonbeam':
74
+ return `https://api-moonbeam.moonscan.io/api`
75
+ case 'moonriver':
76
+ return `https://api-moonriver.moonscan.io/api`
77
+ case 'mbase':
78
+ return `https://api-moonbase.moonscan.io/api`
79
+ case 'avalanche':
80
+ return `https://api.snowtrace.io/api`
81
+ case 'fuji':
82
+ return `https://api-testnet.snowtrace.io/api`
83
+ case 'gnosis':
84
+ return `https://api.gnosisscan.io/api`
85
+ case 'fantom':
86
+ return `https://api.ftmscan.com/api`
87
+ case 'fantom-testnet':
88
+ return `https://api-testnet.ftmscan.com/api`
89
+ default:
90
+ return `https://api-${network}.etherscan.io/api`
72
91
  }
73
92
  }
74
93
 
75
- module.exports = {
76
- loadAbiFromEtherscan,
77
- loadAbiFromBlockScout,
78
- }
94
+ export { loadAbiFromEtherscan, loadAbiFromBlockScout }
@@ -1,8 +1,8 @@
1
- const toolbox = require('gluegun/toolbox')
2
- const { normalizeNodeUrl } = require('./node')
1
+ import * as toolbox from 'gluegun/toolbox'
2
+ import { normalizeNodeUrl } from './node'
3
3
 
4
- const fs = require('fs')
5
- const path = require('path')
4
+ import fs from 'fs'
5
+ import path from 'path'
6
6
  const homedir = require('os').homedir()
7
7
 
8
8
  const CONFIG_PATH = path.join(homedir, '/.graph-cli.json')
@@ -14,7 +14,7 @@ const getConfig = () => {
14
14
  config = {}
15
15
  }
16
16
  return config
17
- }
17
+ }
18
18
 
19
19
  const identifyDeployKey = async (node, deployKey) => {
20
20
  // Determine the deploy key to use, if any:
@@ -45,7 +45,4 @@ const saveDeployKey = async (node, deployKey) => {
45
45
  }
46
46
  }
47
47
 
48
- module.exports = {
49
- identifyDeployKey,
50
- saveDeployKey,
51
- }
48
+ export { identifyDeployKey, saveDeployKey }
@@ -1,7 +1,7 @@
1
1
  const URL = require('url').URL
2
- const ipfsHttpClient = require('ipfs-http-client')
3
- const toolbox = require('gluegun/toolbox')
4
- const Compiler = require('../compiler')
2
+ import ipfsHttpClient from 'ipfs-http-client'
3
+ import * as toolbox from 'gluegun/toolbox'
4
+ import Compiler from '../compiler'
5
5
 
6
6
  // Helper function to construct a subgraph compiler
7
7
  const createCompiler = (
@@ -40,6 +40,4 @@ The IPFS URL must be of the following format: http(s)://host[:port]/[path]`)
40
40
  })
41
41
  }
42
42
 
43
- module.exports = {
44
- createCompiler,
45
- }
43
+ export { createCompiler }
@@ -1,5 +1,5 @@
1
- const immutable = require('immutable')
2
- const { loadManifest } = require('../migrations/util/load-manifest')
1
+ import immutable from 'immutable'
2
+ import { loadManifest } from '../migrations/util/load-manifest'
3
3
 
4
4
  // Loads manifest from file path and returns all:
5
5
  // - data sources
@@ -16,11 +16,11 @@ const extractDataSourceByType = (manifest, dataSourceType, protocol) =>
16
16
  .get(dataSourceType, immutable.List())
17
17
  .reduce(
18
18
  (dataSources, dataSource, dataSourceIndex) =>
19
- protocol.isValidKindName(dataSource.get('kind'))
20
- ? dataSources.push(
21
- immutable.Map({ path: [dataSourceType, dataSourceIndex], dataSource }),
22
- )
23
- : dataSources,
19
+ protocol.isValidKindName(dataSource.get('kind'))
20
+ ? dataSources.push(
21
+ immutable.Map({ path: [dataSourceType, dataSourceIndex], dataSource }),
22
+ )
23
+ : dataSources,
24
24
  immutable.List(),
25
25
  )
26
26
 
@@ -32,7 +32,4 @@ const fromManifest = (manifest, protocol) => {
32
32
  return dataSources.concat(templates)
33
33
  }
34
34
 
35
- module.exports = {
36
- fromFilePath,
37
- fromManifest,
38
- }
35
+ export { fromFilePath, fromManifest }
@@ -0,0 +1,5 @@
1
+ import path from 'path'
2
+
3
+ const displayPath = (p: string) => path.relative(process.cwd(), p)
4
+
5
+ export { displayPath }
@@ -35,7 +35,7 @@ const fixParameters = (parameters, booleanOptions) => {
35
35
 
36
36
  if (unexpectedStringOptions.length > 1) {
37
37
  throw new Error(
38
- `Unexpected value provided for one or more of ${optionNames}. See --help for more information.`
38
+ `Unexpected value provided for one or more of ${optionNames}. See --help for more information.`,
39
39
  )
40
40
  } else if (unexpectedStringOptions.length == 1) {
41
41
  let params = parameters.array
@@ -46,6 +46,4 @@ const fixParameters = (parameters, booleanOptions) => {
46
46
  }
47
47
  }
48
48
 
49
- module.exports = {
50
- fixParameters,
51
- }
49
+ export { fixParameters }
@@ -0,0 +1,3 @@
1
+ const DEFAULT_IPFS_URL = 'https://api.thegraph.com/ipfs/' as const
2
+
3
+ export { DEFAULT_IPFS_URL }
@@ -1,16 +1,13 @@
1
- const jayson = require('jayson')
2
- const toolbox = require('gluegun/toolbox')
1
+ import jayson from 'jayson'
2
+ import { print } from 'gluegun'
3
3
 
4
- const createJsonRpcClient = url => {
5
- let params = {
4
+ const createJsonRpcClient = (url: URL) => {
5
+ const params = {
6
6
  host: url.hostname,
7
7
  port: url.port,
8
8
  path: url.pathname,
9
- }
10
-
11
- // username may be empty
12
- if (url.password) {
13
- params.auth = `${url.username}:${url.password}`
9
+ // username may be empty
10
+ auth: url.password ? `${url.username}:${url.password}` : undefined,
14
11
  }
15
12
 
16
13
  if (url.protocol === 'https:') {
@@ -18,16 +15,14 @@ const createJsonRpcClient = url => {
18
15
  } else if (url.protocol === 'http:') {
19
16
  return jayson.Client.http(params)
20
17
  } else {
21
- toolbox.print.error(
22
- `Unsupported protocol: ${url.protocol.substring(0, url.protocol.length - 1)}`
18
+ print.error(
19
+ `Unsupported protocol: ${url.protocol.substring(0, url.protocol.length - 1)}`,
23
20
  )
24
- toolbox.print.error(
25
- 'The Graph Node URL must be of the following format: http(s)://host[:port]/[path]'
21
+ print.error(
22
+ 'The Graph Node URL must be of the following format: http(s)://host[:port]/[path]',
26
23
  )
27
24
  return null
28
25
  }
29
26
  }
30
27
 
31
- module.exports = {
32
- createJsonRpcClient,
33
- }
28
+ export { createJsonRpcClient }
@@ -1,8 +1,14 @@
1
- const path = require('path')
2
- const yaml = require('yaml')
3
- const { step, withSpinner } = require('../command-helpers/spinner')
4
-
5
- const updateSubgraphNetwork = async (toolbox, manifest, network, networksFile, identifierName) =>
1
+ import path from 'path'
2
+ import yaml from 'yaml'
3
+ import { step, withSpinner } from '../command-helpers/spinner'
4
+
5
+ const updateSubgraphNetwork = async (
6
+ toolbox,
7
+ manifest,
8
+ network,
9
+ networksFile,
10
+ identifierName,
11
+ ) =>
6
12
  await withSpinner(
7
13
  `Update sources network`,
8
14
  `Failed to update sources network`,
@@ -11,41 +17,42 @@ const updateSubgraphNetwork = async (toolbox, manifest, network, networksFile, i
11
17
  let allNetworks
12
18
 
13
19
  step(spinner, `Reading networks config`)
14
- allNetworks = await toolbox.filesystem.read(networksFile, "json")
20
+ allNetworks = await toolbox.filesystem.read(networksFile, 'json')
15
21
  let networkConfig = allNetworks[network]
16
22
 
17
23
  // Exit if the network passed with --network does not exits in networks.json
18
- if(!networkConfig) {
24
+ if (!networkConfig) {
19
25
  throw new Error(`Network '${network}' was not found in '${networksFile}'`)
20
26
  }
21
27
 
22
28
  await toolbox.patching.update(manifest, content => {
23
29
  let subgraph = yaml.parse(content)
24
30
  let networkSources = Object.keys(networkConfig)
25
- let subgraphSources = subgraph.dataSources.map(value => value.name);
31
+ let subgraphSources = subgraph.dataSources.map(value => value.name)
26
32
 
27
33
  // Update the dataSources network config
28
34
  subgraph.dataSources = subgraph.dataSources.map(source => {
29
- if (!networkSources.includes(source.name)) {
30
- throw new Error(`'${source.name}' was not found in the '${network}' configuration, please update!`)
31
- }
32
-
33
- if (hasChanges(identifierName, network, networkConfig[source.name], source)) {
34
- step(spinner, `Update '${source.name}' network configuration`)
35
- source.network = network
36
- source.source = source.source.abi ? { abi: source.source.abi } : {}
37
- Object.assign(source.source, networkConfig[source.name])
38
- } else {
39
- step(spinner, `Skip '${source.name}': No changes to network configuration`)
40
- }
41
-
42
- return source
35
+ if (!networkSources.includes(source.name)) {
36
+ throw new Error(
37
+ `'${source.name}' was not found in the '${network}' configuration, please update!`,
38
+ )
39
+ }
40
+
41
+ if (hasChanges(identifierName, network, networkConfig[source.name], source)) {
42
+ step(spinner, `Update '${source.name}' network configuration`)
43
+ source.network = network
44
+ source.source = source.source.abi ? { abi: source.source.abi } : {}
45
+ Object.assign(source.source, networkConfig[source.name])
46
+ } else {
47
+ step(spinner, `Skip '${source.name}': No changes to network configuration`)
43
48
  }
44
- )
49
+
50
+ return source
51
+ })
45
52
 
46
53
  // All data sources shoud be on the same network,
47
54
  // so we have to update the network of all templates too.
48
- if(subgraph.templates) {
55
+ if (subgraph.templates) {
49
56
  subgraph.templates = subgraph.templates.map(template => ({
50
57
  ...template,
51
58
  network,
@@ -55,37 +62,42 @@ const updateSubgraphNetwork = async (toolbox, manifest, network, networksFile, i
55
62
  let unsusedSources = networkSources.filter(x => !subgraphSources.includes(x))
56
63
 
57
64
  unsusedSources.forEach(source => {
58
- step(spinner, `dataSource '${source}' from '${networksFile}' not found in ${manifest}`)
65
+ step(
66
+ spinner,
67
+ `dataSource '${source}' from '${networksFile}' not found in ${manifest}`,
68
+ )
59
69
  })
60
70
 
61
71
  let yaml_doc = new yaml.Document()
62
72
  yaml_doc.contents = subgraph
63
73
  return yaml_doc.toString()
64
74
  })
65
- })
75
+ },
76
+ )
66
77
 
67
- const initNetworksConfig = async(toolbox, directory, identifierName) =>
78
+ const initNetworksConfig = async (toolbox, directory, identifierName) =>
68
79
  await withSpinner(
69
80
  `Initialize networks config`,
70
81
  `Failed to initialize networks config`,
71
82
  `Warnings while initializing networks config`,
72
83
  async spinner => {
73
- let subgraphStr = await toolbox.filesystem.read(path.join(directory, 'subgraph.yaml'))
84
+ let subgraphStr = await toolbox.filesystem.read(
85
+ path.join(directory, 'subgraph.yaml'),
86
+ )
74
87
  let subgraph = yaml.parse(subgraphStr)
75
88
 
76
- const networks = subgraph.dataSources.reduce((acc, source) =>
77
- Object.assign(
78
- acc,
79
- {
89
+ const networks = subgraph.dataSources.reduce(
90
+ (acc, source) =>
91
+ Object.assign(acc, {
80
92
  [source.network]: {
81
93
  [source.name]: {
82
94
  [identifierName]: source.source.address,
83
95
  startBlock: source.source.startBlock,
84
96
  },
85
97
  },
86
- }
87
- )
88
- , {})
98
+ }),
99
+ {},
100
+ )
89
101
 
90
102
  await toolbox.filesystem.write(`${directory}/networks.json`, networks)
91
103
 
@@ -107,19 +119,21 @@ function hasChanges(identifierName, network, networkConfig, dataSource) {
107
119
  return networkChanged || addressChanged || startBlockChanged
108
120
  }
109
121
 
110
- const updateNetworksFile = async (toolbox, network, dataSource, address, networksFile) => {
111
- await toolbox.patching.update(networksFile, (config) => {
112
- if(Object.keys(config).includes(network)) {
122
+ const updateNetworksFile = async (
123
+ toolbox,
124
+ network,
125
+ dataSource,
126
+ address,
127
+ networksFile,
128
+ ) => {
129
+ await toolbox.patching.update(networksFile, config => {
130
+ if (Object.keys(config).includes(network)) {
113
131
  Object.assign(config[network], { [dataSource]: { address } })
114
132
  } else {
115
- Object.assign(config, { [network]: { [dataSource]: { address } }})
133
+ Object.assign(config, { [network]: { [dataSource]: { address } } })
116
134
  }
117
135
  return config
118
136
  })
119
137
  }
120
138
 
121
- module.exports = {
122
- updateSubgraphNetwork,
123
- initNetworksConfig,
124
- updateNetworksFile
125
- }
139
+ export { updateSubgraphNetwork, initNetworksConfig, updateNetworksFile }
@@ -1,9 +1,17 @@
1
- const { initNetworksConfig, updateSubgraphNetwork } = require('../command-helpers/network')
2
- const toolbox = require('gluegun/toolbox')
3
- const yaml = require('yaml')
4
- const path = require('path')
5
-
6
- const SUBGRAPH_PATH_BASE = path.join(__dirname,'..','..','..','..','examples','example-subgraph')
1
+ import { initNetworksConfig, updateSubgraphNetwork } from '../command-helpers/network'
2
+ import * as toolbox from 'gluegun/toolbox'
3
+ import yaml from 'yaml'
4
+ import path from 'path'
5
+
6
+ const SUBGRAPH_PATH_BASE = path.join(
7
+ __dirname,
8
+ '..',
9
+ '..',
10
+ '..',
11
+ '..',
12
+ 'examples',
13
+ 'example-subgraph',
14
+ )
7
15
 
8
16
  describe('initNetworksConfig', () => {
9
17
  beforeAll(async () => {
@@ -23,8 +31,8 @@ describe('initNetworksConfig', () => {
23
31
 
24
32
  let expected = {
25
33
  mainnet: {
26
- ExampleSubgraph: { address: '0x22843e74c59580b3eaf6c233fa67d8b7c561a835' }
27
- }
34
+ ExampleSubgraph: { address: '0x22843e74c59580b3eaf6c233fa67d8b7c561a835' },
35
+ },
28
36
  }
29
37
 
30
38
  expect(networks).toStrictEqual(expected)
@@ -35,12 +43,15 @@ describe('updateSubgraphNetwork', () => {
35
43
  beforeAll(async () => {
36
44
  let content = {
37
45
  optimism: {
38
- ExampleSubgraph: { address: '0x12345...' }
39
- }
46
+ ExampleSubgraph: { address: '0x12345...' },
47
+ },
40
48
  }
41
49
 
42
50
  await toolbox.filesystem.write(`${SUBGRAPH_PATH_BASE}/networks.json`, content)
43
- await toolbox.filesystem.copy(`${SUBGRAPH_PATH_BASE}/subgraph.yaml`, `${SUBGRAPH_PATH_BASE}/subgraph_copy.yaml`)
51
+ await toolbox.filesystem.copy(
52
+ `${SUBGRAPH_PATH_BASE}/subgraph.yaml`,
53
+ `${SUBGRAPH_PATH_BASE}/subgraph_copy.yaml`,
54
+ )
44
55
  })
45
56
 
46
57
  afterAll(async () => {
@@ -60,13 +71,7 @@ describe('updateSubgraphNetwork', () => {
60
71
  expect(network).toBe('mainnet')
61
72
  expect(address).toBe('0x22843e74c59580b3eaf6c233fa67d8b7c561a835')
62
73
 
63
- await updateSubgraphNetwork(
64
- toolbox,
65
- manifest,
66
- 'optimism',
67
- networksFie,
68
- 'address'
69
- )
74
+ await updateSubgraphNetwork(toolbox, manifest, 'optimism', networksFie, 'address')
70
75
 
71
76
  subgraph = await toolbox.filesystem.read(manifest)
72
77
  subgraphObj = yaml.parse(subgraph)
@@ -77,5 +82,4 @@ describe('updateSubgraphNetwork', () => {
77
82
  expect(network).toBe('optimism')
78
83
  expect(address).toBe('0x12345...')
79
84
  })
80
-
81
85
  })
@@ -1,5 +1,5 @@
1
1
  const URL = require('url').URL
2
- const { print } = require('gluegun/toolbox')
2
+ import { print } from 'gluegun/toolbox'
3
3
 
4
4
  const SUBGRAPH_STUDIO_URL = 'https://api.studio.thegraph.com/deploy/'
5
5
  const HOSTED_SERVICE_URL = 'https://api.thegraph.com/deploy/'
@@ -8,7 +8,7 @@ const validateNodeUrl = node => new URL(node)
8
8
 
9
9
  const normalizeNodeUrl = node => new URL(node).toString()
10
10
 
11
- function chooseNodeUrl ({ product, studio, node, allowSimpleName }) {
11
+ function chooseNodeUrl({ product, studio, node, allowSimpleName }) {
12
12
  if (node) {
13
13
  try {
14
14
  validateNodeUrl(node)
@@ -35,8 +35,4 @@ function chooseNodeUrl ({ product, studio, node, allowSimpleName }) {
35
35
  return { node, allowSimpleName }
36
36
  }
37
37
 
38
- module.exports = {
39
- validateNodeUrl,
40
- normalizeNodeUrl,
41
- chooseNodeUrl
42
- }
38
+ export { validateNodeUrl, normalizeNodeUrl, chooseNodeUrl }
@@ -1,15 +1,15 @@
1
- const fs = require('fs-extra')
2
- const path = require('path')
3
- const prettier = require('prettier')
4
- const yaml = require('yaml')
5
-
6
- const { step } = require('./spinner')
7
- const Scaffold = require('../scaffold')
8
- const { generateEventIndexingHandlers } = require('../scaffold/mapping')
9
- const { generateEventType, abiEvents } = require('../scaffold/schema')
10
- const { generateTestsFiles } = require('../scaffold/tests')
11
- const { strings } = require('gluegun')
12
- const { Map } = require('immutable')
1
+ import fs from 'fs-extra'
2
+ import path from 'path'
3
+ import prettier from 'prettier'
4
+ import yaml from 'yaml'
5
+
6
+ import { step } from './spinner'
7
+ import Scaffold from '../scaffold'
8
+ import { generateEventIndexingHandlers } from '../scaffold/mapping'
9
+ import { generateEventType, abiEvents } from '../scaffold/schema'
10
+ import { generateTestsFiles } from '../scaffold/tests'
11
+ import { strings } from 'gluegun'
12
+ import { Map } from 'immutable'
13
13
 
14
14
  const generateDataSource = async (
15
15
  protocol,
@@ -21,13 +21,25 @@ const generateDataSource = async (
21
21
  const protocolManifest = protocol.getManifestScaffold()
22
22
 
23
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'}))
24
+ 'kind',
25
+ protocol.name,
26
+ 'name',
27
+ contractName,
28
+ 'network',
29
+ network,
30
+ 'source',
31
+ yaml.parse(
32
+ prettier.format(
33
+ protocolManifest.source({ contract: contractAddress, contractName }),
34
+ { parser: 'yaml' },
35
+ ),
36
+ ),
37
+ 'mapping',
38
+ yaml.parse(
39
+ prettier.format(protocolManifest.mapping({ abi, contractName }), {
40
+ parser: 'yaml',
41
+ }),
42
+ ),
31
43
  ).asMutable()
32
44
  }
33
45
 
@@ -130,11 +142,9 @@ const writeMapping = async (abi, protocol, contractName, entities) => {
130
142
 
131
143
  const writeTestsFiles = async (abi, protocol, contractName) => {
132
144
  const hasEvents = protocol.hasEvents()
133
- const events = hasEvents
134
- ? abiEvents(abi).toJS()
135
- : []
145
+ const events = hasEvents ? abiEvents(abi).toJS() : []
136
146
 
137
- if(events.length > 0) {
147
+ if (events.length > 0) {
138
148
  // If a contract is added to a subgraph that has no tests folder
139
149
  await fs.ensureDir('./tests/')
140
150
 
@@ -148,8 +158,7 @@ const writeTestsFiles = async (abi, protocol, contractName) => {
148
158
  }
149
159
  }
150
160
 
151
- module.exports = {
152
- ...module.exports,
161
+ export {
153
162
  generateScaffold,
154
163
  writeScaffold,
155
164
  generateDataSource,
@@ -1,8 +1,8 @@
1
- const chalk = require('chalk')
2
- const immutable = require('immutable')
3
- const toolbox = require('gluegun/toolbox')
1
+ import * as toolbox from 'gluegun'
4
2
 
5
- const step = (spinner, subject, text) => {
3
+ export type Spinner = ReturnType<toolbox.GluegunPrint['spin']>
4
+
5
+ export const step = (spinner: Spinner, subject: string, text: string) => {
6
6
  if (text) {
7
7
  spinner.stopAndPersist({
8
8
  text: toolbox.print.colors.muted(`${subject} ${text}`),
@@ -23,7 +23,12 @@ const step = (spinner, subject, text) => {
23
23
  // spinner stops with the warning message and returns the `result` value.
24
24
  // Otherwise the spinner prints the in-progress message with a check mark
25
25
  // and simply returns the value returned by `f`.
26
- const withSpinner = async (text, errorText, warningText, f) => {
26
+ export const withSpinner = async (
27
+ text: string,
28
+ errorText: string,
29
+ warningText: string,
30
+ f: (spinner: Spinner) => Promise<any> | any, // TODO: type result
31
+ ) => {
27
32
  let spinner = toolbox.print.spin(text)
28
33
  try {
29
34
  let result = await f(spinner)
@@ -55,8 +60,3 @@ const withSpinner = async (text, errorText, warningText, f) => {
55
60
  throw e
56
61
  }
57
62
  }
58
-
59
- module.exports = {
60
- step,
61
- withSpinner,
62
- }