@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.
- package/CHANGELOG.md +7 -0
- package/babel.config.js +3 -0
- package/dist/bin.js +6 -0
- package/dist/cli.js +32 -0
- package/dist/codegen/schema.js +250 -0
- package/dist/codegen/schema.test.js +458 -0
- package/dist/codegen/template.js +65 -0
- package/dist/codegen/types/conversions.js +359 -0
- package/dist/codegen/types/index.js +71 -0
- package/dist/codegen/types/index.test.js +563 -0
- package/dist/codegen/typescript.js +200 -0
- package/dist/codegen/util.js +46 -0
- package/dist/codegen/util.test.js +93 -0
- package/dist/command-helpers/abi.js +78 -0
- package/dist/command-helpers/auth.js +77 -0
- package/dist/command-helpers/compiler.js +66 -0
- package/dist/command-helpers/data-sources.js +29 -0
- package/dist/command-helpers/fs.js +9 -0
- package/dist/command-helpers/gluegun.js +49 -0
- package/dist/command-helpers/ipfs.js +5 -0
- package/dist/command-helpers/jsonrpc.js +29 -0
- package/dist/command-helpers/network.js +93 -0
- package/dist/command-helpers/network.test.js +86 -0
- package/dist/command-helpers/node.js +40 -0
- package/dist/command-helpers/scaffold.js +112 -0
- package/dist/command-helpers/spinner.js +84 -0
- package/dist/command-helpers/studio.js +13 -0
- package/dist/command-helpers/studio.test.js +41 -0
- package/dist/command-helpers/subgraph.js +24 -0
- package/dist/command-helpers/version.js +74 -0
- package/dist/command-helpers/version.test.js +179 -0
- package/dist/commands/add.js +190 -0
- package/dist/commands/auth.js +127 -0
- package/dist/commands/build.js +140 -0
- package/dist/commands/codegen.js +135 -0
- package/dist/commands/create.js +86 -0
- package/dist/commands/deploy.js +334 -0
- package/dist/commands/init.js +788 -0
- package/dist/commands/local.js +387 -0
- package/dist/commands/remove.js +86 -0
- package/dist/commands/test.js +295 -0
- package/dist/compiler/asc.js +83 -0
- package/dist/compiler/index.js +474 -0
- package/dist/debug.js +16 -0
- package/dist/migrations/mapping_api_version_0_0_1.js +78 -0
- package/dist/migrations/mapping_api_version_0_0_2.js +76 -0
- package/dist/migrations/mapping_api_version_0_0_3.js +78 -0
- package/dist/migrations/mapping_api_version_0_0_4.js +80 -0
- package/dist/migrations/mapping_api_version_0_0_5.js +80 -0
- package/dist/migrations/spec_version_0_0_2.js +49 -0
- package/dist/migrations/spec_version_0_0_3.js +54 -0
- package/dist/migrations/util/load-manifest.js +18 -0
- package/dist/migrations/util/versions.js +29 -0
- package/dist/migrations.js +56 -0
- package/dist/protocols/arweave/manifest.graphql +57 -0
- package/dist/protocols/arweave/scaffold/manifest.js +18 -0
- package/dist/protocols/arweave/scaffold/mapping.js +52 -0
- package/dist/protocols/arweave/subgraph.js +23 -0
- package/dist/protocols/cosmos/manifest.graphql +76 -0
- package/dist/protocols/cosmos/scaffold/manifest.js +15 -0
- package/dist/protocols/cosmos/scaffold/mapping.js +38 -0
- package/dist/protocols/cosmos/subgraph.js +25 -0
- package/dist/protocols/ethereum/abi.js +140 -0
- package/dist/protocols/ethereum/codegen/abi.js +451 -0
- package/dist/protocols/ethereum/codegen/abi.test.js +328 -0
- package/dist/protocols/ethereum/codegen/template.js +50 -0
- package/dist/protocols/ethereum/contract.js +20 -0
- package/dist/protocols/ethereum/manifest.graphql +94 -0
- package/dist/protocols/ethereum/scaffold/manifest.js +32 -0
- package/dist/protocols/ethereum/scaffold/mapping.js +65 -0
- package/dist/protocols/ethereum/subgraph.js +171 -0
- package/dist/protocols/ethereum/type-generator.js +125 -0
- package/dist/protocols/index.js +268 -0
- package/dist/protocols/ipfs/codegen/file_template.js +50 -0
- package/dist/protocols/near/contract.js +41 -0
- package/dist/protocols/near/manifest.graphql +64 -0
- package/dist/protocols/near/scaffold/manifest.js +16 -0
- package/dist/protocols/near/scaffold/mapping.js +38 -0
- package/dist/protocols/near/subgraph.js +20 -0
- package/dist/protocols/subgraph.js +2 -0
- package/dist/protocols/substreams/manifest.graphql +45 -0
- package/dist/protocols/substreams/scaffold/manifest.js +12 -0
- package/dist/protocols/substreams/subgraph.js +23 -0
- package/dist/scaffold/cosmos.test.js +83 -0
- package/dist/scaffold/ethereum.test.js +505 -0
- package/dist/scaffold/index.js +128 -0
- package/dist/scaffold/mapping.js +61 -0
- package/dist/scaffold/near.test.js +86 -0
- package/dist/scaffold/schema.js +83 -0
- package/dist/scaffold/tests.js +175 -0
- package/dist/schema.js +54 -0
- package/dist/subgraph.js +249 -0
- package/dist/type-generator.js +224 -0
- package/dist/validation/contract.js +46 -0
- package/dist/validation/index.js +8 -0
- package/dist/validation/manifest.js +271 -0
- package/dist/validation/schema.js +796 -0
- package/dist/validation/schema.test.js +35 -0
- package/dist/watcher.js +79 -0
- package/jest.config.js +1 -1
- package/package.json +16 -9
- package/{bin/graph → src/bin.ts} +2 -1
- package/src/cli.ts +36 -0
- package/src/codegen/schema.js +23 -22
- package/src/codegen/schema.test.js +33 -27
- package/src/codegen/{template.js → template.ts} +8 -6
- package/src/codegen/types/conversions.ts +382 -0
- package/src/codegen/types/index.js +4 -7
- package/src/codegen/types/index.test.js +10 -4
- package/src/codegen/{typescript.js → typescript.ts} +44 -26
- package/src/codegen/util.js +1 -1
- package/src/codegen/util.test.js +5 -2
- package/src/command-helpers/abi.js +46 -30
- package/src/command-helpers/auth.js +6 -9
- package/src/command-helpers/compiler.js +4 -6
- package/src/command-helpers/data-sources.js +8 -11
- package/src/command-helpers/fs.ts +5 -0
- package/src/command-helpers/gluegun.js +2 -4
- package/src/command-helpers/ipfs.ts +3 -0
- package/src/command-helpers/{jsonrpc.js → jsonrpc.ts} +11 -16
- package/src/command-helpers/network.js +58 -44
- package/src/command-helpers/network.test.js +23 -19
- package/src/command-helpers/node.js +3 -7
- package/src/command-helpers/scaffold.js +34 -25
- package/src/command-helpers/{spinner.js → spinner.ts} +10 -10
- package/src/command-helpers/studio.test.js +61 -30
- package/src/command-helpers/studio.ts +20 -0
- package/src/command-helpers/{subgraph.js → subgraph.ts} +6 -6
- package/src/command-helpers/version.js +11 -16
- package/src/command-helpers/version.test.js +111 -82
- package/src/commands/add.js +49 -35
- package/src/commands/auth.js +13 -25
- package/src/commands/build.js +9 -9
- package/src/commands/codegen.js +12 -12
- package/src/commands/create.js +22 -22
- package/src/commands/deploy.js +39 -34
- package/src/commands/init.js +21 -24
- package/src/commands/local.js +15 -14
- package/src/commands/remove.js +22 -22
- package/src/commands/test.js +86 -70
- package/src/compiler/{asc.js → asc.ts} +29 -16
- package/src/compiler/index.js +18 -18
- package/src/{debug.js → debug.ts} +2 -2
- package/src/migrations/mapping_api_version_0_0_1.js +7 -7
- package/src/migrations/mapping_api_version_0_0_2.js +5 -5
- package/src/migrations/mapping_api_version_0_0_3.js +7 -7
- package/src/migrations/mapping_api_version_0_0_4.js +7 -7
- package/src/migrations/mapping_api_version_0_0_5.js +7 -7
- package/src/migrations/spec_version_0_0_2.js +5 -5
- package/src/migrations/spec_version_0_0_3.js +5 -5
- package/src/migrations/util/load-manifest.js +6 -9
- package/src/migrations/util/versions.js +5 -10
- package/src/{migrations.js → migrations.ts} +14 -15
- package/src/protocols/arweave/scaffold/manifest.js +1 -4
- package/src/protocols/arweave/scaffold/mapping.js +1 -3
- package/src/protocols/arweave/subgraph.ts +22 -0
- package/src/protocols/cosmos/scaffold/manifest.js +1 -4
- package/src/protocols/cosmos/scaffold/mapping.js +1 -3
- package/src/protocols/cosmos/subgraph.js +2 -2
- package/src/protocols/ethereum/abi.js +7 -13
- package/src/protocols/ethereum/codegen/abi.js +219 -222
- package/src/protocols/ethereum/codegen/abi.test.js +6 -6
- package/src/protocols/ethereum/codegen/template.js +3 -5
- package/src/protocols/ethereum/contract.js +3 -2
- package/src/protocols/ethereum/scaffold/manifest.js +4 -7
- package/src/protocols/ethereum/scaffold/mapping.js +4 -11
- package/src/protocols/ethereum/subgraph.js +21 -20
- package/src/protocols/ethereum/type-generator.js +24 -30
- package/src/protocols/{index.js → index.ts} +65 -46
- package/src/protocols/ipfs/codegen/file_template.js +2 -2
- package/src/protocols/near/{contract.js → contract.ts} +16 -12
- package/src/protocols/near/scaffold/manifest.js +2 -5
- package/src/protocols/near/scaffold/mapping.js +1 -3
- package/src/protocols/near/subgraph.js +3 -6
- package/src/protocols/subgraph.ts +12 -0
- package/src/protocols/substreams/scaffold/{manifest.js → manifest.ts} +2 -7
- package/src/protocols/substreams/subgraph.ts +22 -0
- package/src/scaffold/cosmos.test.js +3 -3
- package/src/scaffold/ethereum.test.js +4 -4
- package/src/scaffold/index.js +7 -7
- package/src/scaffold/mapping.js +3 -3
- package/src/scaffold/near.test.js +3 -3
- package/src/scaffold/schema.js +4 -4
- package/src/scaffold/tests.js +72 -58
- package/src/schema.ts +26 -0
- package/src/{subgraph.js → subgraph.ts} +80 -60
- package/src/type-generator.js +20 -20
- package/src/validation/contract.js +2 -6
- package/src/validation/index.js +1 -1
- package/src/validation/manifest.js +24 -22
- package/src/validation/schema.test.js +1 -1
- package/src/validation/{schema.js → schema.ts} +268 -221
- package/src/{watcher.js → watcher.ts} +23 -12
- package/tests/cli/globalSetup.js +2 -2
- package/tests/cli/globalTeardown.js +2 -2
- package/tests/cli/init.test.js +2 -2
- package/tests/cli/util.js +7 -13
- package/tsconfig.json +18 -0
- package/src/cli.js +0 -38
- package/src/codegen/types/conversions.js +0 -329
- package/src/command-helpers/fs.js +0 -8
- package/src/command-helpers/ipfs.js +0 -6
- package/src/command-helpers/studio.js +0 -15
- package/src/protocols/arweave/subgraph.js +0 -20
- package/src/protocols/substreams/subgraph.js +0 -17
- package/src/schema.js +0 -23
package/src/commands/remove.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
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(
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
res
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
}
|
package/src/commands/test.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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(
|
|
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(
|
|
109
|
-
let result = await fetch(
|
|
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/${
|
|
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 =
|
|
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(
|
|
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
|
-
}
|
|
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)='", {
|
|
206
|
-
|
|
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(
|
|
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 = [
|
|
256
|
-
|
|
257
|
-
|
|
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
|
-
'
|
|
278
|
-
|
|
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
|
-
|
|
290
|
+
spawn('docker', dockerRunOpts, { stdio: 'inherit' })
|
|
283
291
|
}
|
|
284
292
|
})
|
|
285
293
|
} else {
|
|
286
|
-
print.info(
|
|
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(
|
|
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(
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
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(
|
|
314
|
-
|
|
324
|
+
await patching.replace(
|
|
325
|
+
dockerfilePath,
|
|
326
|
+
'<MATCHSTICK_VERSION>',
|
|
327
|
+
versionOpt || latestVersion,
|
|
328
|
+
)
|
|
315
329
|
} catch (error) {
|
|
316
|
-
spinner.fail(
|
|
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
|
-
|
|
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 =>
|
|
11
|
+
const setupExitHandler = (exitHandler: (code: number) => void) =>
|
|
12
|
+
process.addListener('exit', exitHandler)
|
|
12
13
|
|
|
13
|
-
const removeExitHandler = 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 = (
|
|
18
|
-
|
|
19
|
-
|
|
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 = ({
|
|
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
|
-
}
|
package/src/compiler/index.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
let compilerDebug =
|
|
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
|
-
|
|
684
|
+
export default Compiler
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
15
|
+
export default debugFactory
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
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)
|