@graphprotocol/graph-cli 0.40.0 → 0.40.1-alpha-20230216170945-963badb
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 +10 -0
- package/dist/bin.js +31 -3
- package/dist/command-helpers/network.js +20 -13
- package/dist/command-helpers/network.test.js +2 -2
- package/dist/command-helpers/spinner.js +37 -1
- package/dist/commands/add.js +48 -67
- package/dist/commands/auth.js +40 -102
- package/dist/commands/build.js +51 -68
- package/dist/commands/codegen.js +38 -61
- package/dist/commands/create.js +31 -55
- package/dist/commands/deploy.js +112 -174
- package/dist/commands/init.js +526 -512
- package/dist/commands/local.js +93 -103
- package/dist/commands/remove.js +32 -56
- package/dist/commands/test.js +81 -88
- package/dist/index.js +5 -0
- package/oclif.manifest.json +726 -0
- package/package.json +10 -3
- package/dist/cli.js +0 -26
- package/dist/command-helpers/gluegun.js +0 -48
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @graphprotocol/graph-cli
|
|
2
2
|
|
|
3
|
+
## 0.40.1-alpha-20230216170945-963badb
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#1055](https://github.com/graphprotocol/graph-tooling/pull/1055)
|
|
8
|
+
[`6d6f25b`](https://github.com/graphprotocol/graph-tooling/commit/6d6f25bca2fc6929a750af56b3c10a8cc8a72689)
|
|
9
|
+
Thanks [@enisdenjo](https://github.com/enisdenjo)! - dependencies updates:
|
|
10
|
+
- Added dependency [`@oclif/core@2.0.7` ↗︎](https://www.npmjs.com/package/@oclif/core/v/2.0.7) (to
|
|
11
|
+
`dependencies`)
|
|
12
|
+
|
|
3
13
|
## 0.40.0
|
|
4
14
|
|
|
5
15
|
### Minor Changes
|
package/dist/bin.js
CHANGED
|
@@ -1,6 +1,34 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
20
|
+
if (mod && mod.__esModule) return mod;
|
|
21
|
+
var result = {};
|
|
22
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
23
|
+
__setModuleDefault(result, mod);
|
|
24
|
+
return result;
|
|
25
|
+
};
|
|
26
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
27
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
28
|
+
};
|
|
3
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
30
|
+
const oclif = __importStar(require("@oclif/core"));
|
|
31
|
+
const flush_1 = __importDefault(require("@oclif/core/flush"));
|
|
32
|
+
// @ts-expect-error Handle is a pure JS file
|
|
33
|
+
const handle_1 = __importDefault(require("@oclif/core/handle"));
|
|
34
|
+
oclif.run().then(flush_1.default).catch(handle_1.default);
|
|
@@ -5,17 +5,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.updateNetworksFile = exports.initNetworksConfig = exports.updateSubgraphNetwork = void 0;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const gluegun_1 = require("gluegun");
|
|
8
9
|
const yaml_1 = __importDefault(require("yaml"));
|
|
9
10
|
const spinner_1 = require("./spinner");
|
|
10
|
-
const updateSubgraphNetwork = async (
|
|
11
|
+
const updateSubgraphNetwork = async (manifest, network, networksFile, identifierName) =>
|
|
12
|
+
// TODO: use useSpinner
|
|
13
|
+
await (0, spinner_1.withSpinner)(`Update sources network`, `Failed to update sources network`, `Warnings while updating sources network`, async (spinner) => {
|
|
11
14
|
(0, spinner_1.step)(spinner, `Reading networks config`);
|
|
12
|
-
const allNetworks = await
|
|
15
|
+
const allNetworks = await gluegun_1.filesystem.read(networksFile, 'json');
|
|
13
16
|
const networkConfig = allNetworks[network];
|
|
14
17
|
// Exit if the network passed with --network does not exits in networks.json
|
|
15
18
|
if (!networkConfig) {
|
|
16
19
|
throw new Error(`Network '${network}' was not found in '${networksFile}'`);
|
|
17
20
|
}
|
|
18
|
-
await
|
|
21
|
+
await gluegun_1.patching.update(manifest, content => {
|
|
19
22
|
const subgraph = yaml_1.default.parse(content);
|
|
20
23
|
const networkSources = Object.keys(networkConfig);
|
|
21
24
|
const subgraphSources = subgraph.dataSources.map((value) => value.name);
|
|
@@ -37,10 +40,12 @@ const updateSubgraphNetwork = async (toolbox, manifest, network, networksFile, i
|
|
|
37
40
|
});
|
|
38
41
|
// All data sources shoud be on the same network,
|
|
39
42
|
// so we have to update the network of all templates too.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
// eslint-disable-next-line -- prettier has problems with &&=
|
|
44
|
+
subgraph.templates &&
|
|
45
|
+
(subgraph.templates = subgraph.templates.map((template) => ({
|
|
46
|
+
...template,
|
|
47
|
+
network,
|
|
48
|
+
})));
|
|
44
49
|
const unsusedSources = networkSources.filter(x => !subgraphSources.includes(x));
|
|
45
50
|
unsusedSources.forEach(source => {
|
|
46
51
|
(0, spinner_1.step)(spinner, `dataSource '${source}' from '${networksFile}' not found in ${manifest}`);
|
|
@@ -51,8 +56,10 @@ const updateSubgraphNetwork = async (toolbox, manifest, network, networksFile, i
|
|
|
51
56
|
});
|
|
52
57
|
});
|
|
53
58
|
exports.updateSubgraphNetwork = updateSubgraphNetwork;
|
|
54
|
-
const initNetworksConfig = async (
|
|
55
|
-
|
|
59
|
+
const initNetworksConfig = async (directory, identifierName) =>
|
|
60
|
+
// TODO: use useSpinner
|
|
61
|
+
await (0, spinner_1.withSpinner)(`Initialize networks config`, `Failed to initialize networks config`, `Warnings while initializing networks config`, async () => {
|
|
62
|
+
const subgraphStr = gluegun_1.filesystem.read(path_1.default.join(directory, 'subgraph.yaml'));
|
|
56
63
|
const subgraph = yaml_1.default.parse(subgraphStr);
|
|
57
64
|
const networks = subgraph.dataSources.reduce((acc, source) => Object.assign(acc, {
|
|
58
65
|
[source.network]: {
|
|
@@ -62,7 +69,7 @@ const initNetworksConfig = async (toolbox, directory, identifierName) => await (
|
|
|
62
69
|
},
|
|
63
70
|
},
|
|
64
71
|
}), {});
|
|
65
|
-
|
|
72
|
+
gluegun_1.filesystem.write(`${directory}/networks.json`, networks);
|
|
66
73
|
return true;
|
|
67
74
|
});
|
|
68
75
|
exports.initNetworksConfig = initNetworksConfig;
|
|
@@ -76,8 +83,8 @@ function hasChanges(identifierName, network, networkConfig, dataSource) {
|
|
|
76
83
|
const startBlockChanged = networkConfig.startBlock !== dataSource.source.startBlock;
|
|
77
84
|
return networkChanged || addressChanged || startBlockChanged;
|
|
78
85
|
}
|
|
79
|
-
|
|
80
|
-
await
|
|
86
|
+
async function updateNetworksFile(network, dataSource, address, networksFile) {
|
|
87
|
+
await gluegun_1.patching.update(networksFile, config => {
|
|
81
88
|
if (Object.keys(config).includes(network)) {
|
|
82
89
|
Object.assign(config[network], { [dataSource]: { address } });
|
|
83
90
|
}
|
|
@@ -86,5 +93,5 @@ const updateNetworksFile = async (toolbox, network, dataSource, address, network
|
|
|
86
93
|
}
|
|
87
94
|
return config;
|
|
88
95
|
});
|
|
89
|
-
}
|
|
96
|
+
}
|
|
90
97
|
exports.updateNetworksFile = updateNetworksFile;
|
|
@@ -33,7 +33,7 @@ const network_1 = require("./network");
|
|
|
33
33
|
const SUBGRAPH_PATH_BASE = path_1.default.join(__dirname, '..', '..', '..', '..', 'examples', 'example-subgraph');
|
|
34
34
|
describe('initNetworksConfig', () => {
|
|
35
35
|
beforeAll(async () => {
|
|
36
|
-
await (0, network_1.initNetworksConfig)(
|
|
36
|
+
await (0, network_1.initNetworksConfig)(SUBGRAPH_PATH_BASE, 'address');
|
|
37
37
|
});
|
|
38
38
|
afterAll(async () => {
|
|
39
39
|
toolbox.filesystem.remove(`${SUBGRAPH_PATH_BASE}/networks.json`);
|
|
@@ -75,7 +75,7 @@ describe('updateSubgraphNetwork', () => {
|
|
|
75
75
|
let address = subgraphObj.dataSources[0].source.address;
|
|
76
76
|
expect(network).toBe('mainnet');
|
|
77
77
|
expect(address).toBe('0x22843e74c59580b3eaf6c233fa67d8b7c561a835');
|
|
78
|
-
await (0, network_1.updateSubgraphNetwork)(
|
|
78
|
+
await (0, network_1.updateSubgraphNetwork)(manifest, 'optimism', networksFie, 'address');
|
|
79
79
|
subgraph = toolbox.filesystem.read(manifest);
|
|
80
80
|
subgraphObj = yaml_1.default.parse(subgraph);
|
|
81
81
|
network = subgraphObj.dataSources[0].network;
|
|
@@ -23,8 +23,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.withSpinner = exports.step = void 0;
|
|
26
|
+
exports.useSpinner = exports.withSpinner = exports.step = void 0;
|
|
27
27
|
const toolbox = __importStar(require("gluegun"));
|
|
28
|
+
const core_1 = require("@oclif/core");
|
|
28
29
|
const step = (spinner, subject, text) => {
|
|
29
30
|
if (text) {
|
|
30
31
|
spinner.stopAndPersist({
|
|
@@ -47,6 +48,8 @@ exports.step = step;
|
|
|
47
48
|
// spinner stops with the warning message and returns the `result` value.
|
|
48
49
|
// Otherwise the spinner prints the in-progress message with a check mark
|
|
49
50
|
// and simply returns the value returned by `f`.
|
|
51
|
+
//
|
|
52
|
+
// @deprecated
|
|
50
53
|
const withSpinner = async (text, errorText, warningText, f) => {
|
|
51
54
|
const spinner = toolbox.print.spin(text);
|
|
52
55
|
try {
|
|
@@ -78,3 +81,36 @@ const withSpinner = async (text, errorText, warningText, f) => {
|
|
|
78
81
|
}
|
|
79
82
|
};
|
|
80
83
|
exports.withSpinner = withSpinner;
|
|
84
|
+
// Executes the function `f` while displaying a command-line spinner.
|
|
85
|
+
async function useSpinner(text, errorText, warningText, f) {
|
|
86
|
+
const { action } = core_1.ux;
|
|
87
|
+
action.start(text);
|
|
88
|
+
try {
|
|
89
|
+
const result = await f(action);
|
|
90
|
+
if (result && typeof result === 'object') {
|
|
91
|
+
const hasError = 'error' in result;
|
|
92
|
+
const hasWarning = 'warning' in result;
|
|
93
|
+
const hasResult = 'result' in result;
|
|
94
|
+
if (hasError) {
|
|
95
|
+
action.stop(`✖ ${errorText}: ${result.error}`);
|
|
96
|
+
return (hasResult ? result.result : result);
|
|
97
|
+
}
|
|
98
|
+
if (hasWarning && hasResult) {
|
|
99
|
+
if (result.warning !== null) {
|
|
100
|
+
action.stop(`⚠️ ${warningText}: ${result.warning}`);
|
|
101
|
+
}
|
|
102
|
+
action.stop('✔');
|
|
103
|
+
return result.result;
|
|
104
|
+
}
|
|
105
|
+
action.stop('✔');
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
108
|
+
action.stop('✔');
|
|
109
|
+
return result;
|
|
110
|
+
}
|
|
111
|
+
catch (e) {
|
|
112
|
+
action.stop(`✖ ${errorText}: ${e.message}`);
|
|
113
|
+
throw e;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
exports.useSpinner = useSpinner;
|
package/dist/commands/add.js
CHANGED
|
@@ -26,61 +26,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
const
|
|
29
|
+
const core_1 = require("@oclif/core");
|
|
30
|
+
const errors_1 = require("@oclif/core/lib/errors");
|
|
31
|
+
const gluegun_1 = require("gluegun");
|
|
30
32
|
const immutable_1 = __importDefault(require("immutable"));
|
|
31
33
|
const abi_1 = require("../command-helpers/abi");
|
|
32
34
|
const DataSourcesExtractor = __importStar(require("../command-helpers/data-sources"));
|
|
33
|
-
const gluegun_1 = require("../command-helpers/gluegun");
|
|
34
35
|
const network_1 = require("../command-helpers/network");
|
|
35
36
|
const scaffold_1 = require("../command-helpers/scaffold");
|
|
36
37
|
const spinner_1 = require("../command-helpers/spinner");
|
|
37
38
|
const protocols_1 = __importDefault(require("../protocols"));
|
|
38
39
|
const abi_2 = __importDefault(require("../protocols/ethereum/abi"));
|
|
39
40
|
const subgraph_1 = __importDefault(require("../subgraph"));
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
${chalk_1.default.dim('Options:')}
|
|
44
|
-
|
|
45
|
-
--abi <path> Path to the contract ABI (default: download from Etherscan)
|
|
46
|
-
--contract-name Name of the contract (default: Contract)
|
|
47
|
-
--merge-entities Whether to merge entities with the same name (default: false)
|
|
48
|
-
--network-file <path> Networks config file path (default: "./networks.json")
|
|
49
|
-
-h, --help Show usage information
|
|
50
|
-
`;
|
|
51
|
-
exports.default = {
|
|
52
|
-
description: 'Adds a new datasource to a subgraph',
|
|
53
|
-
run: async (toolbox) => {
|
|
54
|
-
// Obtain tools
|
|
55
|
-
const { print, system } = toolbox;
|
|
56
|
-
// Read CLI parameters
|
|
57
|
-
let { abi, contractName, h, help, mergeEntities, networkFile } = toolbox.parameters.options;
|
|
58
|
-
contractName || (contractName = 'Contract');
|
|
59
|
-
try {
|
|
60
|
-
(0, gluegun_1.fixParameters)(toolbox.parameters, {
|
|
61
|
-
h,
|
|
62
|
-
help,
|
|
63
|
-
mergeEntities,
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
catch (e) {
|
|
67
|
-
print.error(e.message);
|
|
68
|
-
process.exitCode = 1;
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
const address = toolbox.parameters.first || toolbox.parameters.array?.[0];
|
|
72
|
-
const manifestPath = toolbox.parameters.second || toolbox.parameters.array?.[1] || './subgraph.yaml';
|
|
73
|
-
// Show help text if requested
|
|
74
|
-
if (help || h) {
|
|
75
|
-
print.info(HELP);
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
// Validate the address
|
|
79
|
-
if (!address) {
|
|
80
|
-
print.error('No contract address provided');
|
|
81
|
-
process.exitCode = 1;
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
41
|
+
class AddCommand extends core_1.Command {
|
|
42
|
+
async run() {
|
|
43
|
+
const { args: { address, subgraphManifest: manifestPath }, flags: { abi, contractName, mergeEntities, networkFile: networksFile }, } = await this.parse(AddCommand);
|
|
84
44
|
const dataSourcesAndTemplates = await DataSourcesExtractor.fromFilePath(manifestPath);
|
|
85
45
|
const protocol = protocols_1.default.fromDataSources(dataSourcesAndTemplates);
|
|
86
46
|
const manifest = await subgraph_1.default.load(manifestPath, { protocol });
|
|
@@ -89,9 +49,7 @@ exports.default = {
|
|
|
89
49
|
const entities = getEntities(manifest);
|
|
90
50
|
const contractNames = getContractNames(manifest);
|
|
91
51
|
if (contractNames.includes(contractName)) {
|
|
92
|
-
|
|
93
|
-
process.exitCode = 1;
|
|
94
|
-
return;
|
|
52
|
+
this.error(`Datasource or template with name ${contractName} already exists, please choose a different name.`, { exit: 1 });
|
|
95
53
|
}
|
|
96
54
|
let ethabi = null;
|
|
97
55
|
if (abi) {
|
|
@@ -103,7 +61,7 @@ exports.default = {
|
|
|
103
61
|
else {
|
|
104
62
|
ethabi = await (0, abi_1.loadAbiFromEtherscan)(abi_2.default, network, address);
|
|
105
63
|
}
|
|
106
|
-
const { collisionEntities, onlyCollisions, abiData } = updateEventNamesOnCollision(
|
|
64
|
+
const { collisionEntities, onlyCollisions, abiData } = updateEventNamesOnCollision(ethabi, entities, contractName, mergeEntities);
|
|
107
65
|
ethabi.data = abiData;
|
|
108
66
|
await (0, scaffold_1.writeABI)(ethabi, contractName);
|
|
109
67
|
await (0, scaffold_1.writeSchema)(ethabi, protocol, result.getIn(['schema', 'file']), collisionEntities);
|
|
@@ -124,20 +82,47 @@ exports.default = {
|
|
|
124
82
|
result.set('dataSources', dataSources.push(dataSource));
|
|
125
83
|
await subgraph_1.default.write(result, manifestPath);
|
|
126
84
|
// Update networks.json
|
|
127
|
-
|
|
128
|
-
await (0, network_1.updateNetworksFile)(toolbox, network, contractName, address, networksFile);
|
|
85
|
+
await (0, network_1.updateNetworksFile)(network, contractName, address, networksFile);
|
|
129
86
|
// Detect Yarn and/or NPM
|
|
130
|
-
const yarn = system.which('yarn');
|
|
131
|
-
const npm = system.which('npm');
|
|
87
|
+
const yarn = gluegun_1.system.which('yarn');
|
|
88
|
+
const npm = gluegun_1.system.which('npm');
|
|
132
89
|
if (!yarn && !npm) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
90
|
+
this.error('Neither Yarn nor NPM were found on your system. Please install one of them.', {
|
|
91
|
+
exit: 1,
|
|
92
|
+
});
|
|
136
93
|
}
|
|
137
|
-
await (0, spinner_1.
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
94
|
+
await (0, spinner_1.useSpinner)('Running codegen', 'Failed to run codegen', 'Warning during codegen', () => gluegun_1.system.run(yarn ? 'yarn codegen' : 'npm run codegen'));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
exports.default = AddCommand;
|
|
98
|
+
AddCommand.description = 'Adds a new datasource to a subgraph.';
|
|
99
|
+
AddCommand.args = {
|
|
100
|
+
address: core_1.Args.string({
|
|
101
|
+
description: 'The contract address',
|
|
102
|
+
required: true,
|
|
103
|
+
}),
|
|
104
|
+
subgraphManifest: core_1.Args.string({
|
|
105
|
+
default: 'subgraph.yaml',
|
|
106
|
+
}),
|
|
107
|
+
};
|
|
108
|
+
AddCommand.flags = {
|
|
109
|
+
abi: core_1.Flags.string({
|
|
110
|
+
summary: 'Path to the contract ABI.',
|
|
111
|
+
default: '*Download from Etherscan*',
|
|
112
|
+
}),
|
|
113
|
+
contractName: core_1.Flags.string({
|
|
114
|
+
summary: 'Name of the contract.',
|
|
115
|
+
default: 'Contract',
|
|
116
|
+
}),
|
|
117
|
+
mergeEntities: core_1.Flags.boolean({
|
|
118
|
+
summary: 'Whether to merge entities with the same name.',
|
|
119
|
+
default: false,
|
|
120
|
+
}),
|
|
121
|
+
// TODO: should be networksFile (with an "s"), or?
|
|
122
|
+
networkFile: core_1.Flags.file({
|
|
123
|
+
summary: 'Networks config file path.',
|
|
124
|
+
default: 'networks.json',
|
|
125
|
+
}),
|
|
141
126
|
};
|
|
142
127
|
const getEntities = (manifest) => {
|
|
143
128
|
const dataSources = manifest.result.get('dataSources', immutable_1.default.List());
|
|
@@ -152,9 +137,8 @@ const getContractNames = (manifest) => {
|
|
|
152
137
|
const templates = manifest.result.get('templates', immutable_1.default.List());
|
|
153
138
|
return dataSources.concat(templates).map((dataSource) => dataSource.get('name'));
|
|
154
139
|
};
|
|
155
|
-
const updateEventNamesOnCollision = (
|
|
140
|
+
const updateEventNamesOnCollision = (ethabi, entities, contractName, mergeEntities) => {
|
|
156
141
|
let abiData = ethabi.data;
|
|
157
|
-
const { print } = toolbox;
|
|
158
142
|
const collisionEntities = [];
|
|
159
143
|
let onlyCollisions = true;
|
|
160
144
|
for (let i = 0; i < abiData.size; i++) {
|
|
@@ -162,10 +146,7 @@ const updateEventNamesOnCollision = (toolbox, ethabi, entities, contractName, me
|
|
|
162
146
|
if (dataRow.get('type') === 'event') {
|
|
163
147
|
if (entities.includes(dataRow.get('name'))) {
|
|
164
148
|
if (entities.includes(`${contractName}${dataRow.get('name')}`)) {
|
|
165
|
-
|
|
166
|
-
+ event name ('${dataRow.get('name')}') entity already exists.`);
|
|
167
|
-
process.exitCode = 1;
|
|
168
|
-
break;
|
|
149
|
+
throw new errors_1.CLIError(`Contract name ('${contractName}') + event name ('${dataRow.get('name')}') entity already exists.`, { exit: 1 });
|
|
169
150
|
}
|
|
170
151
|
if (mergeEntities) {
|
|
171
152
|
collisionEntities.push(dataRow.get('name'));
|
package/dist/commands/auth.js
CHANGED
|
@@ -1,122 +1,60 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
3
|
+
const core_1 = require("@oclif/core");
|
|
7
4
|
const auth_1 = require("../command-helpers/auth");
|
|
8
|
-
const gluegun_1 = require("../command-helpers/gluegun");
|
|
9
5
|
const node_1 = require("../command-helpers/node");
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
${chalk_1.default.dim('Options:')}
|
|
14
|
-
|
|
15
|
-
--product <subgraph-studio|hosted-service>
|
|
16
|
-
Selects the product for which to authenticate
|
|
17
|
-
--studio Shortcut for --product subgraph-studio
|
|
18
|
-
-h, --help Show usage information
|
|
19
|
-
`;
|
|
20
|
-
const processForm = async (toolbox, { product, studio, node, deployKey }) => {
|
|
21
|
-
const questions = [
|
|
22
|
-
{
|
|
23
|
-
type: 'select',
|
|
24
|
-
name: 'product',
|
|
25
|
-
message: 'Product for which to initialize',
|
|
26
|
-
choices: ['subgraph-studio', 'hosted-service'],
|
|
27
|
-
skip: product === 'subgraph-studio' ||
|
|
28
|
-
product === 'hosted-service' ||
|
|
29
|
-
studio !== undefined ||
|
|
30
|
-
node !== undefined,
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
type: 'password',
|
|
34
|
-
name: 'deployKey',
|
|
35
|
-
message: 'Deploy key',
|
|
36
|
-
skip: deployKey !== undefined,
|
|
37
|
-
},
|
|
38
|
-
];
|
|
39
|
-
try {
|
|
40
|
-
const answers = await toolbox.prompt.ask(questions);
|
|
41
|
-
return answers;
|
|
42
|
-
}
|
|
43
|
-
catch (e) {
|
|
44
|
-
return undefined;
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
exports.default = {
|
|
48
|
-
description: 'Sets the deploy key to use when deploying to a Graph node',
|
|
49
|
-
run: async (toolbox) => {
|
|
50
|
-
// Obtain tools
|
|
51
|
-
const { print } = toolbox;
|
|
52
|
-
// Read CLI parameters
|
|
53
|
-
const { product, studio, h, help } = toolbox.parameters.options;
|
|
54
|
-
// Show help text if requested
|
|
55
|
-
if (help || h) {
|
|
56
|
-
print.info(HELP);
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
let firstParam, secondParam;
|
|
60
|
-
try {
|
|
61
|
-
[firstParam, secondParam] = (0, gluegun_1.fixParameters)(toolbox.parameters, {
|
|
62
|
-
h,
|
|
63
|
-
help,
|
|
64
|
-
studio,
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
catch (e) {
|
|
68
|
-
print.error(e.message);
|
|
69
|
-
process.exitCode = 1;
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
6
|
+
class AuthCommand extends core_1.Command {
|
|
7
|
+
async run() {
|
|
8
|
+
const { args: { node: nodeOrDeployKey, 'deploy-key': deployKeyFlag }, flags: { product, studio }, } = await this.parse(AuthCommand);
|
|
72
9
|
// if user specifies --product or --studio then deployKey is the first parameter
|
|
73
10
|
let node;
|
|
74
|
-
let deployKey;
|
|
11
|
+
let deployKey = deployKeyFlag;
|
|
75
12
|
if (product || studio) {
|
|
76
13
|
({ node } = (0, node_1.chooseNodeUrl)({ product, studio, node }));
|
|
77
|
-
deployKey =
|
|
14
|
+
deployKey = nodeOrDeployKey;
|
|
78
15
|
}
|
|
79
16
|
else {
|
|
80
|
-
node =
|
|
81
|
-
deployKey = secondParam;
|
|
17
|
+
node = nodeOrDeployKey;
|
|
82
18
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
product: inputs.product,
|
|
96
|
-
studio,
|
|
97
|
-
node,
|
|
19
|
+
// eslint-disable-next-line -- prettier has problems with ||=
|
|
20
|
+
node =
|
|
21
|
+
node ||
|
|
22
|
+
(await core_1.ux.prompt('Which product to initialize?', {
|
|
23
|
+
required: true,
|
|
24
|
+
}));
|
|
25
|
+
// eslint-disable-next-line -- prettier has problems with ||=
|
|
26
|
+
deployKey =
|
|
27
|
+
deployKey ||
|
|
28
|
+
(await core_1.ux.prompt('What is the deploy key?', {
|
|
29
|
+
required: true,
|
|
30
|
+
type: 'mask',
|
|
98
31
|
}));
|
|
99
|
-
}
|
|
100
|
-
deployKey || (deployKey = inputs.deployKey);
|
|
101
|
-
}
|
|
102
|
-
if (!deployKey) {
|
|
103
|
-
print.error(`No deploy key provided`);
|
|
104
|
-
print.info(HELP);
|
|
105
|
-
process.exitCode = 1;
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
32
|
if (deployKey.length > 200) {
|
|
109
|
-
|
|
110
|
-
process.exitCode = 1;
|
|
111
|
-
return;
|
|
33
|
+
this.error('✖ Deploy key must not exceed 200 characters', { exit: 1 });
|
|
112
34
|
}
|
|
35
|
+
core_1.ux.action.start(`Setting deploy key for "${node}"`);
|
|
113
36
|
try {
|
|
114
37
|
await (0, auth_1.saveDeployKey)(node, deployKey);
|
|
115
|
-
|
|
38
|
+
core_1.ux.action.stop(`✔ Deploy key set for "${node}"`);
|
|
116
39
|
}
|
|
117
40
|
catch (e) {
|
|
118
|
-
|
|
119
|
-
process.exitCode = 1;
|
|
41
|
+
this.error(e, { exit: 1 });
|
|
120
42
|
}
|
|
121
|
-
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.default = AuthCommand;
|
|
46
|
+
AuthCommand.description = 'Sets the deploy key to use when deploying to a Graph node.';
|
|
47
|
+
AuthCommand.args = {
|
|
48
|
+
node: core_1.Args.string(),
|
|
49
|
+
'deploy-key': core_1.Args.string(),
|
|
50
|
+
};
|
|
51
|
+
AuthCommand.flags = {
|
|
52
|
+
product: core_1.Flags.string({
|
|
53
|
+
summary: 'Select a product for which to authenticate.',
|
|
54
|
+
options: ['subgraph-studio', 'hosted-service'],
|
|
55
|
+
}),
|
|
56
|
+
studio: core_1.Flags.boolean({
|
|
57
|
+
summary: 'Shortcut for "--product subgraph-studio".',
|
|
58
|
+
exclusive: ['product'],
|
|
59
|
+
}),
|
|
122
60
|
};
|