@graphprotocol/graph-cli 0.23.0-alpha.0 → 0.24.0-alpha.0
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/README.md +83 -0
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/.travis.yml +4 -0
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/chain/ethereum.ts +10 -16
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/chain/near.ts +402 -0
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/common/collections.ts +125 -4
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/common/eager_offset.ts +2 -1
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/common/json.ts +14 -0
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/common/numbers.ts +58 -16
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/common/value.ts +2 -5
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/global/global.ts +108 -0
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/helper-functions.ts +5 -5
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/index.ts +6 -15
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/package.json +5 -2
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/test/bigInt.ts +138 -108
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/test/bytes.ts +31 -20
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/test/test.js +120 -88
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/tsconfig.json +2 -2
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/types/tsconfig.base.json +3 -0
- package/examples/basic-event-handlers/package.json +1 -1
- package/examples/basic-event-handlers/yarn.lock +4 -4
- package/examples/example-subgraph/package.json +1 -1
- package/examples/example-subgraph/yarn.lock +4 -4
- package/jest.config.js +2 -2
- package/package.json +2 -6
- package/src/commands/init.js +31 -3
- package/src/commands/test.js +37 -27
- package/src/migrations/mapping_api_version_0_0_5.js +74 -0
- package/src/scaffold.js +18 -2
- package/tests/cli/globalSetup.js +6 -0
- package/tests/cli/globalTeardown.js +6 -0
- package/tests/cli/init.test.js +1 -1
- package/tests/cli/util.js +17 -8
package/src/commands/init.js
CHANGED
|
@@ -257,16 +257,25 @@ const loadAbiFromBlockScout = async (network, address) =>
|
|
|
257
257
|
},
|
|
258
258
|
)
|
|
259
259
|
|
|
260
|
+
const getEtherscanLikeAPIUrl = (network) => {
|
|
261
|
+
switch(network){
|
|
262
|
+
case "mainnet": return `https://api.etherscan.io/api`;
|
|
263
|
+
case "bsc": return `https://api.bscscan.com/api`;
|
|
264
|
+
case "matic": return `https://api.polygonscan.com/api`;
|
|
265
|
+
case "mumbai": return `https://api-testnet.polygonscan.com/api`;
|
|
266
|
+
default: return `https://api-${network}.etherscan.io/api`;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
260
270
|
const loadAbiFromEtherscan = async (network, address) =>
|
|
261
271
|
await withSpinner(
|
|
262
272
|
`Fetching ABI from Etherscan`,
|
|
263
273
|
`Failed to fetch ABI from Etherscan`,
|
|
264
274
|
`Warnings while fetching ABI from Etherscan`,
|
|
265
275
|
async spinner => {
|
|
276
|
+
const scanApiUrl = getEtherscanLikeAPIUrl(network);
|
|
266
277
|
let result = await fetch(
|
|
267
|
-
|
|
268
|
-
network === 'mainnet' ? 'api' : `api-${network}`
|
|
269
|
-
}.etherscan.io/api?module=contract&action=getabi&address=${address}`,
|
|
278
|
+
`${scanApiUrl}?module=contract&action=getabi&address=${address}`,
|
|
270
279
|
)
|
|
271
280
|
let json = await result.json()
|
|
272
281
|
|
|
@@ -530,12 +539,26 @@ const initRepository = async (toolbox, directory) =>
|
|
|
530
539
|
},
|
|
531
540
|
)
|
|
532
541
|
|
|
542
|
+
// Only used for local testing / continuous integration.
|
|
543
|
+
//
|
|
544
|
+
// This requires that the command `npm link` is called
|
|
545
|
+
// on the root directory of this repository, as described here:
|
|
546
|
+
// https://docs.npmjs.com/cli/v7/commands/npm-link.
|
|
547
|
+
const npmLinkToLocalCli = async (toolbox, directory) => {
|
|
548
|
+
if (process.env.GRAPH_CLI_TESTS) {
|
|
549
|
+
await toolbox.system.run('npm link @graphprotocol/graph-cli', { cwd: directory })
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
|
|
533
553
|
const installDependencies = async (toolbox, directory, installCommand) =>
|
|
534
554
|
await withSpinner(
|
|
535
555
|
`Install dependencies with ${toolbox.print.colors.muted(installCommand)}`,
|
|
536
556
|
`Failed to install dependencies`,
|
|
537
557
|
`Warnings while installing dependencies`,
|
|
538
558
|
async spinner => {
|
|
559
|
+
// Links to local graph-cli if we're running the automated tests
|
|
560
|
+
await npmLinkToLocalCli(toolbox, directory)
|
|
561
|
+
|
|
539
562
|
await toolbox.system.run(installCommand, { cwd: directory })
|
|
540
563
|
return true
|
|
541
564
|
},
|
|
@@ -643,6 +666,11 @@ const initSubgraphFromExample = async (
|
|
|
643
666
|
delete pkgJson['license']
|
|
644
667
|
delete pkgJson['repository']
|
|
645
668
|
|
|
669
|
+
// Remove example's cli in favor of the local one (added via `npm link`)
|
|
670
|
+
if (process.env.GRAPH_CLI_TESTS) {
|
|
671
|
+
delete pkgJson['devDependencies']['@graphprotocol/graph-cli']
|
|
672
|
+
}
|
|
673
|
+
|
|
646
674
|
// Write package.json
|
|
647
675
|
await filesystem.write(pkgJsonFilename, pkgJson, { jsonIndent: 2 })
|
|
648
676
|
return true
|
package/src/commands/test.js
CHANGED
|
@@ -11,6 +11,7 @@ ${chalk.dim('Options:')}
|
|
|
11
11
|
|
|
12
12
|
-f --force Overwrite folder + file when downloading
|
|
13
13
|
-h, --help Show usage information
|
|
14
|
+
-l, --logs Logs to the console information about the OS, CPU model and download url (debugging purposes)
|
|
14
15
|
-v, --version <tag> Choose the version of the rust binary that you want to be downloaded/used
|
|
15
16
|
`
|
|
16
17
|
|
|
@@ -21,12 +22,13 @@ module.exports = {
|
|
|
21
22
|
let { print } = toolbox
|
|
22
23
|
|
|
23
24
|
// Read CLI parameters
|
|
24
|
-
let { f, force, h, help, v, version } = toolbox.parameters.options
|
|
25
|
+
let { f, force, h, help, l, logs, v, version } = toolbox.parameters.options
|
|
25
26
|
let datasource = toolbox.parameters.first
|
|
26
27
|
|
|
27
28
|
// Support both long and short option variants
|
|
28
29
|
force = force || f
|
|
29
30
|
help = help || h
|
|
31
|
+
logs = logs || l
|
|
30
32
|
version = version || v
|
|
31
33
|
|
|
32
34
|
// Show help text if requested
|
|
@@ -35,48 +37,56 @@ module.exports = {
|
|
|
35
37
|
return
|
|
36
38
|
}
|
|
37
39
|
|
|
38
|
-
const platform = getPlatform()
|
|
40
|
+
const platform = getPlatform(logs)
|
|
39
41
|
if (!version) {
|
|
40
|
-
let result = await fetch('https://api.github.com/repos/LimeChain/matchstick/releases/latest')
|
|
41
|
-
let json = await result.json()
|
|
42
|
-
version = json.tag_name
|
|
42
|
+
let result = await fetch('https://api.github.com/repos/LimeChain/matchstick/releases/latest')
|
|
43
|
+
let json = await result.json()
|
|
44
|
+
version = json.tag_name
|
|
43
45
|
}
|
|
44
46
|
|
|
45
|
-
const url = `https://github.com/LimeChain/matchstick/releases/download/${version}/${platform}
|
|
47
|
+
const url = `https://github.com/LimeChain/matchstick/releases/download/${version}/${platform}`
|
|
46
48
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
if (logs) {
|
|
50
|
+
console.log(`Download link: ${url}`)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
let binary = new Binary(platform, url, version)
|
|
54
|
+
await binary.install(force)
|
|
55
|
+
datasource ? binary.run(datasource) : binary.run()
|
|
50
56
|
}
|
|
51
57
|
}
|
|
52
58
|
|
|
53
|
-
function getPlatform() {
|
|
54
|
-
const type = os.type()
|
|
55
|
-
const arch = os.arch()
|
|
56
|
-
const release = os.release()
|
|
57
|
-
const cpuCore = os.cpus()[0]
|
|
58
|
-
const majorVersion = semver.major(release)
|
|
59
|
-
const isM1 = cpuCore.model.includes("Apple M1")
|
|
59
|
+
function getPlatform(logs) {
|
|
60
|
+
const type = os.type()
|
|
61
|
+
const arch = os.arch()
|
|
62
|
+
const release = os.release()
|
|
63
|
+
const cpuCore = os.cpus()[0]
|
|
64
|
+
const majorVersion = semver.major(release)
|
|
65
|
+
const isM1 = cpuCore.model.includes("Apple M1")
|
|
66
|
+
|
|
67
|
+
if (logs) {
|
|
68
|
+
console.log(`OS type: ${type}\nOS arch: ${arch}\nOS release: ${release}\nOS major version: ${majorVersion}\nCPU model: ${cpuCore.model}`)
|
|
69
|
+
}
|
|
60
70
|
|
|
61
71
|
if (arch === 'x64' || (arch === 'arm64' && isM1)) {
|
|
62
72
|
if (type === 'Darwin') {
|
|
63
|
-
if (majorVersion ===
|
|
64
|
-
return 'binary-macos-10.15'
|
|
65
|
-
} else if (majorVersion ===
|
|
66
|
-
return 'binary-macos-10.14'
|
|
73
|
+
if (majorVersion === 19) {
|
|
74
|
+
return 'binary-macos-10.15'
|
|
75
|
+
} else if (majorVersion === 18) {
|
|
76
|
+
return 'binary-macos-10.14'
|
|
67
77
|
} else if (isM1) {
|
|
68
|
-
return 'binary-macos-11-m1'
|
|
78
|
+
return 'binary-macos-11-m1'
|
|
69
79
|
}
|
|
70
|
-
return 'binary-macos-11'
|
|
80
|
+
return 'binary-macos-11'
|
|
71
81
|
} else if (type === 'Linux') {
|
|
72
|
-
if (majorVersion ===
|
|
73
|
-
return 'binary-linux-18'
|
|
82
|
+
if (majorVersion === 18) {
|
|
83
|
+
return 'binary-linux-18'
|
|
74
84
|
}
|
|
75
|
-
return 'binary-linux-20'
|
|
85
|
+
return 'binary-linux-20'
|
|
76
86
|
} else if (type === 'Windows_NT') {
|
|
77
|
-
return 'binary-windows'
|
|
87
|
+
return 'binary-windows'
|
|
78
88
|
}
|
|
79
89
|
}
|
|
80
90
|
|
|
81
|
-
throw new Error(`Unsupported platform: ${type} ${arch} ${majorVersion}`)
|
|
91
|
+
throw new Error(`Unsupported platform: ${type} ${arch} ${majorVersion}`)
|
|
82
92
|
}
|
|
@@ -0,0 +1,74 @@
|
|
|
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.5, replace them with 0.0.6
|
|
9
|
+
module.exports = {
|
|
10
|
+
name: 'Bump mapping apiVersion from 0.0.5 to 0.0.6',
|
|
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.23.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.24.0') &&
|
|
28
|
+
// ...and we have a manifest with mapping > apiVersion = 0.0.5
|
|
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.5'),
|
|
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.5'),
|
|
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.5', 'g'),
|
|
61
|
+
'apiVersion: 0.0.6',
|
|
62
|
+
)
|
|
63
|
+
await toolbox.patching.replace(
|
|
64
|
+
manifestFile,
|
|
65
|
+
new RegExp("apiVersion: '0.0.5'", 'g'),
|
|
66
|
+
"apiVersion: '0.0.6'",
|
|
67
|
+
)
|
|
68
|
+
await toolbox.patching.replace(
|
|
69
|
+
manifestFile,
|
|
70
|
+
new RegExp('apiVersion: "0.0.5"', 'g'),
|
|
71
|
+
'apiVersion: "0.0.6"',
|
|
72
|
+
)
|
|
73
|
+
},
|
|
74
|
+
}
|
package/src/scaffold.js
CHANGED
|
@@ -18,6 +18,13 @@ const abiEvents = abi =>
|
|
|
18
18
|
setName: (event, name) => event.set('_alias', name),
|
|
19
19
|
})
|
|
20
20
|
|
|
21
|
+
const graphCliVersion = process.env.GRAPH_CLI_TESTS
|
|
22
|
+
// JSON.stringify should remove this key, we will install the local
|
|
23
|
+
// graph-cli for the tests using `npm link` instead of fetching from npm.
|
|
24
|
+
? undefined
|
|
25
|
+
// For scaffolding real subgraphs
|
|
26
|
+
: `${module.exports.version}`
|
|
27
|
+
|
|
21
28
|
// package.json
|
|
22
29
|
|
|
23
30
|
const generatePackageJson = ({ subgraphName, node }) =>
|
|
@@ -41,8 +48,8 @@ const generatePackageJson = ({ subgraphName, node }) =>
|
|
|
41
48
|
subgraphName,
|
|
42
49
|
},
|
|
43
50
|
dependencies: {
|
|
44
|
-
'@graphprotocol/graph-cli':
|
|
45
|
-
'@graphprotocol/graph-ts': `0.
|
|
51
|
+
'@graphprotocol/graph-cli': graphCliVersion,
|
|
52
|
+
'@graphprotocol/graph-ts': `0.24.0-alpha.0`,
|
|
46
53
|
},
|
|
47
54
|
}),
|
|
48
55
|
{ parser: 'json' },
|
|
@@ -145,6 +152,14 @@ const generateSchema = ({ abi, indexEvents }) => {
|
|
|
145
152
|
)
|
|
146
153
|
}
|
|
147
154
|
|
|
155
|
+
const tsConfig = prettier.format(
|
|
156
|
+
JSON.stringify({
|
|
157
|
+
extends: '@graphprotocol/graph-ts/types/tsconfig.base.json',
|
|
158
|
+
include: ['src'],
|
|
159
|
+
}),
|
|
160
|
+
{ parser: 'json' },
|
|
161
|
+
)
|
|
162
|
+
|
|
148
163
|
// Mapping
|
|
149
164
|
|
|
150
165
|
const generateTupleFieldAssignments = ({ keyPath, index, component }) => {
|
|
@@ -303,6 +318,7 @@ const generateScaffold = async (
|
|
|
303
318
|
'package.json': packageJson,
|
|
304
319
|
'subgraph.yaml': manifest,
|
|
305
320
|
'schema.graphql': schema,
|
|
321
|
+
'tsconfig.json': tsConfig,
|
|
306
322
|
src: { 'mapping.ts': mapping },
|
|
307
323
|
abis: {
|
|
308
324
|
[`${contractName}.json`]: prettier.format(JSON.stringify(abi.data), {
|
package/tests/cli/init.test.js
CHANGED
package/tests/cli/util.js
CHANGED
|
@@ -13,7 +13,7 @@ const cliTest = (title, args, testPath, options) => {
|
|
|
13
13
|
let cwd =
|
|
14
14
|
options !== undefined && options.cwd ? options.cwd : resolvePath(`./${testPath}`)
|
|
15
15
|
|
|
16
|
-
let [exitCode, stdout, stderr] = await
|
|
16
|
+
let [exitCode, stdout, stderr] = await runGraphCli(args, cwd)
|
|
17
17
|
|
|
18
18
|
let expectedExitCode = undefined
|
|
19
19
|
if (options !== undefined && options.exitCode !== undefined) {
|
|
@@ -55,18 +55,14 @@ const cliTest = (title, args, testPath, options) => {
|
|
|
55
55
|
)
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
const
|
|
59
|
-
// Resolve the path to graph.js
|
|
60
|
-
let graphCli = path.join(__dirname, '..', '..', 'bin', 'graph')
|
|
61
|
-
|
|
58
|
+
const runCommand = async (command, args = [], cwd = process.cwd()) => {
|
|
62
59
|
// Make sure to set an absolute working directory
|
|
63
60
|
cwd = cwd[0] !== '/' ? path.resolve(__dirname, cwd) : cwd
|
|
64
61
|
|
|
65
62
|
return new Promise((resolve, reject) => {
|
|
66
63
|
let stdout = ''
|
|
67
64
|
let stderr = ''
|
|
68
|
-
const
|
|
69
|
-
const child = spawn(command, { cwd })
|
|
65
|
+
const child = spawn(`${command} ${args.join(' ')}`, { cwd })
|
|
70
66
|
|
|
71
67
|
child.on('error', error => {
|
|
72
68
|
reject(error)
|
|
@@ -86,7 +82,20 @@ const runCli = async (args = [], cwd = process.cwd()) => {
|
|
|
86
82
|
})
|
|
87
83
|
}
|
|
88
84
|
|
|
85
|
+
const runGraphCli = async (args, cwd) => {
|
|
86
|
+
// Resolve the path to graph.js
|
|
87
|
+
let graphCli = path.join(__dirname, '..', '..', 'bin', 'graph')
|
|
88
|
+
|
|
89
|
+
return await runCommand(graphCli, args, cwd)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const npmLinkCli = () => runCommand('npm', ['link'])
|
|
93
|
+
|
|
94
|
+
const npmUnlinkCli = () => runCommand('npm', ['unlink'])
|
|
95
|
+
|
|
89
96
|
module.exports = {
|
|
90
97
|
cliTest,
|
|
91
|
-
|
|
98
|
+
npmLinkCli,
|
|
99
|
+
npmUnlinkCli,
|
|
100
|
+
runGraphCli,
|
|
92
101
|
}
|