@graphprotocol/graph-cli 0.40.0 → 0.40.1-alpha-20230216174117-760a195

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.
@@ -26,88 +26,32 @@ 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 chalk_1 = __importDefault(require("chalk"));
29
+ const core_1 = require("@oclif/core");
30
+ const gluegun_1 = require("gluegun");
30
31
  const compiler_1 = require("../command-helpers/compiler");
31
32
  const DataSourcesExtractor = __importStar(require("../command-helpers/data-sources"));
32
- const gluegun_1 = require("../command-helpers/gluegun");
33
33
  const network_1 = require("../command-helpers/network");
34
34
  const debug_1 = __importDefault(require("../debug"));
35
35
  const protocols_1 = __importDefault(require("../protocols"));
36
36
  const buildDebug = (0, debug_1.default)('graph-cli:build');
37
- const HELP = `
38
- ${chalk_1.default.bold('graph build')} [options] ${chalk_1.default.bold('[<subgraph-manifest>]')}
39
-
40
- Options:
41
-
42
- -h, --help Show usage information
43
- -i, --ipfs <node> Upload build results to an IPFS node
44
- -o, --output-dir <path> Output directory for build results (default: build/)
45
- -t, --output-format <format> Output format for mappings (wasm, wast) (default: wasm)
46
- --skip-migrations Skip subgraph migrations (default: false)
47
- -w, --watch Regenerate types when subgraph files change (default: false)
48
- --network <name> Network configuration to use from the networks config file
49
- --network-file <path> Networks config file path (default: "./networks.json")
50
- `;
51
- exports.default = {
52
- description: 'Builds a subgraph and (optionally) uploads it to IPFS',
53
- run: async (toolbox) => {
54
- // Obtain tools
55
- const { filesystem, print } = toolbox;
56
- // Parse CLI parameters
57
- let { i, h, help, ipfs, o, outputDir, outputFormat, skipMigrations, t, w, watch, network, networkFile, } = toolbox.parameters.options;
58
- // Support both short and long option variants
59
- help || (help = h);
60
- ipfs || (ipfs = i);
61
- outputDir || (outputDir = o);
62
- outputFormat || (outputFormat = t);
63
- watch || (watch = w);
64
- let manifest;
65
- try {
66
- [manifest] = (0, gluegun_1.fixParameters)(toolbox.parameters, {
67
- h,
68
- help,
69
- w,
70
- watch,
71
- });
72
- }
73
- catch (e) {
74
- print.error(e.message);
75
- process.exitCode = 1;
76
- return;
77
- }
78
- // Fall back to default values for options / parameters
79
- outputFormat = outputFormat && ['wasm', 'wast'].includes(outputFormat) ? outputFormat : 'wasm';
80
- outputDir = outputDir && outputDir !== '' ? outputDir : filesystem.path('build');
81
- manifest =
82
- manifest !== undefined && manifest !== '' ? manifest : filesystem.resolve('subgraph.yaml');
83
- networkFile =
84
- networkFile !== undefined && networkFile !== ''
85
- ? networkFile
86
- : filesystem.resolve('networks.json');
87
- // Show help text if requested
88
- if (help) {
89
- print.info(HELP);
90
- return;
91
- }
37
+ class BuildCommand extends core_1.Command {
38
+ async run() {
39
+ const { args: { 'subgraph-manifest': manifest }, flags: { ipfs, 'output-dir': outputDir, 'output-format': outputFormat, 'skip-migrations': skipMigrations, watch, network, 'network-file': networkFile, }, } = await this.parse(BuildCommand);
92
40
  let protocol;
93
41
  try {
94
42
  const dataSourcesAndTemplates = await DataSourcesExtractor.fromFilePath(manifest);
95
43
  protocol = protocols_1.default.fromDataSources(dataSourcesAndTemplates);
96
44
  }
97
45
  catch (e) {
98
- print.error(e.message);
99
- process.exitCode = 1;
100
- return;
46
+ this.error(e, { exit: 1 });
101
47
  }
102
48
  buildDebug('Detected protocol "%s" (%o)', protocol.name, protocol);
103
- if (network && filesystem.exists(networkFile) !== 'file') {
104
- print.error(`Network file '${networkFile}' does not exists or is not a file!`);
105
- process.exitCode = 1;
106
- return;
49
+ if (network && gluegun_1.filesystem.exists(networkFile) !== 'file') {
50
+ this.error(`Network file '${networkFile}' does not exists or is not a file!`, { exit: 1 });
107
51
  }
108
52
  if (network) {
109
53
  const identifierName = protocol.getContract().identifierName();
110
- await (0, network_1.updateSubgraphNetwork)(toolbox, manifest, network, networkFile, identifierName);
54
+ await (0, network_1.updateSubgraphNetwork)(manifest, network, networkFile, identifierName);
111
55
  }
112
56
  const compiler = (0, compiler_1.createCompiler)(manifest, {
113
57
  ipfs,
@@ -118,7 +62,7 @@ exports.default = {
118
62
  });
119
63
  // Exit with an error code if the compiler couldn't be created
120
64
  if (!compiler) {
121
- process.exitCode = 1;
65
+ this.exit(1);
122
66
  return;
123
67
  }
124
68
  // Watch subgraph files for changes or additions, trigger
@@ -129,8 +73,47 @@ exports.default = {
129
73
  else {
130
74
  const result = await compiler.compile();
131
75
  if (result === false) {
132
- process.exitCode = 1;
76
+ this.exit(1);
133
77
  }
134
78
  }
135
- },
79
+ }
80
+ }
81
+ exports.default = BuildCommand;
82
+ BuildCommand.description = 'Builds a subgraph and (optionally) uploads it to IPFS.';
83
+ BuildCommand.args = {
84
+ 'subgraph-manifest': core_1.Args.string({
85
+ default: 'subgraph.yaml',
86
+ }),
87
+ };
88
+ BuildCommand.flags = {
89
+ ipfs: core_1.Flags.string({
90
+ summary: 'Upload build results to an IPFS node.',
91
+ char: 'i',
92
+ }),
93
+ 'output-dir': core_1.Flags.directory({
94
+ summary: 'Output directory for build results.',
95
+ char: 'o',
96
+ default: 'build/',
97
+ }),
98
+ 'output-format': core_1.Flags.string({
99
+ summary: 'Output format for mappings.',
100
+ char: 't',
101
+ options: ['wasm', 'wast'],
102
+ default: 'wasm',
103
+ }),
104
+ 'skip-migrations': core_1.Flags.boolean({
105
+ summary: 'Skip subgraph migrations.',
106
+ }),
107
+ watch: core_1.Flags.boolean({
108
+ summary: 'Regenerate types when subgraph files change.',
109
+ char: 'w',
110
+ }),
111
+ network: core_1.Flags.string({
112
+ summary: 'Network configuration to use from the networks config file.',
113
+ }),
114
+ // TODO: should be networksFile (with an "s"), or?
115
+ 'network-file': core_1.Flags.file({
116
+ summary: 'Networks config file path.',
117
+ default: 'networks.json',
118
+ }),
136
119
  };
@@ -27,69 +27,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  const path_1 = __importDefault(require("path"));
30
- const chalk_1 = __importDefault(require("chalk"));
30
+ const core_1 = require("@oclif/core");
31
31
  const DataSourcesExtractor = __importStar(require("../command-helpers/data-sources"));
32
- const gluegun_1 = require("../command-helpers/gluegun");
33
32
  const version_1 = require("../command-helpers/version");
34
33
  const debug_1 = __importDefault(require("../debug"));
35
34
  const protocols_1 = __importDefault(require("../protocols"));
36
35
  const type_generator_1 = __importDefault(require("../type-generator"));
37
- const HELP = `
38
- ${chalk_1.default.bold('graph codegen')} [options] ${chalk_1.default.bold('[<subgraph-manifest>]')}
39
- Options:
40
- -h, --help Show usage information
41
- -o, --output-dir <path> Output directory for generated types (default: generated/)
42
- --skip-migrations Skip subgraph migrations (default: false)
43
- -w, --watch Regenerate types when subgraph files change (default: false)
44
- -u, --uncrashable Generate Float Subgraph Uncrashable helper file
45
- -uc, --uncrashable-config <path> Directory for uncrashable config (default: ./uncrashable-config.yaml)
46
- `;
47
36
  const codegenDebug = (0, debug_1.default)('graph-cli:codegen');
48
- exports.default = {
49
- description: 'Generates AssemblyScript types for a subgraph',
50
- run: async (toolbox) => {
51
- // Obtain tools
52
- const { filesystem, print } = toolbox;
53
- // Read CLI parameters
54
- let { h, help, o, outputDir, skipMigrations, w, watch, u, uncrashable, uc, uncrashableConfig } = toolbox.parameters.options;
55
- // Support both long and short option variants
56
- help || (help = h);
57
- outputDir || (outputDir = o);
58
- watch || (watch = w);
59
- uncrashable || (uncrashable = u);
60
- let uncrashable_config = uncrashableConfig || uc;
61
- let manifest;
62
- try {
63
- [manifest] = (0, gluegun_1.fixParameters)(toolbox.parameters, {
64
- h,
65
- help,
66
- skipMigrations,
67
- w,
68
- watch,
69
- u,
70
- uncrashable,
71
- });
72
- }
73
- catch (e) {
74
- print.error(e.message);
75
- process.exitCode = 1;
76
- return;
77
- }
37
+ class CodegenCommand extends core_1.Command {
38
+ async run() {
39
+ const { args: { 'subgraph-manifest': manifest }, flags: { 'output-dir': outputDir, 'skip-migrations': skipMigrations, watch, uncrashable, 'uncrashable-config': uncrashableConfig, }, } = await this.parse(CodegenCommand);
78
40
  codegenDebug('Initialized codegen manifest: %o', manifest);
79
- // Fall back to default values for options / parameters
80
- outputDir =
81
- outputDir !== undefined && outputDir !== '' ? outputDir : filesystem.path('generated');
82
- manifest =
83
- manifest !== undefined && manifest !== '' ? manifest : filesystem.resolve('subgraph.yaml');
84
- uncrashable_config =
85
- uncrashable_config !== undefined && uncrashable_config !== ''
86
- ? uncrashable_config
87
- : filesystem.resolve('uncrashable-config.yaml');
88
- // Show help text if requested
89
- if (help) {
90
- print.info(HELP);
91
- return;
92
- }
93
41
  let protocol;
94
42
  try {
95
43
  // Checks to make sure codegen doesn't run against
@@ -104,9 +52,7 @@ exports.default = {
104
52
  protocol = protocols_1.default.fromDataSources(dataSourcesAndTemplates);
105
53
  }
106
54
  catch (e) {
107
- print.error(e.message);
108
- process.exitCode = 1;
109
- return;
55
+ this.error(e, { exit: 1 });
110
56
  }
111
57
  const generator = new type_generator_1.default({
112
58
  subgraphManifest: manifest,
@@ -114,7 +60,7 @@ exports.default = {
114
60
  skipMigrations,
115
61
  protocol,
116
62
  uncrashable,
117
- uncrashableConfig: uncrashable_config,
63
+ uncrashableConfig: uncrashableConfig || 'uncrashable-config.yaml',
118
64
  });
119
65
  // Watch working directory for file updates or additions, trigger
120
66
  // type generation (if watch argument specified)
@@ -124,5 +70,37 @@ exports.default = {
124
70
  else if (!(await generator.generateTypes())) {
125
71
  process.exitCode = 1;
126
72
  }
127
- },
73
+ }
74
+ }
75
+ exports.default = CodegenCommand;
76
+ CodegenCommand.description = 'Generates AssemblyScript types for a subgraph.';
77
+ CodegenCommand.args = {
78
+ 'subgraph-manifest': core_1.Args.string({
79
+ default: 'subgraph.yaml',
80
+ }),
81
+ };
82
+ CodegenCommand.flags = {
83
+ 'output-dir': core_1.Flags.directory({
84
+ summary: 'Output directory for generated types.',
85
+ char: 'o',
86
+ default: 'generated/',
87
+ }),
88
+ 'skip-migrations': core_1.Flags.boolean({
89
+ summary: 'Skip subgraph migrations.',
90
+ }),
91
+ watch: core_1.Flags.boolean({
92
+ summary: 'Regenerate types when subgraph files change.',
93
+ char: 'w',
94
+ }),
95
+ uncrashable: core_1.Flags.boolean({
96
+ summary: 'Generate Float Subgraph Uncrashable helper file.',
97
+ char: 'u',
98
+ }),
99
+ 'uncrashable-config': core_1.Flags.file({
100
+ summary: 'Directory for uncrashable config.',
101
+ aliases: ['uc'],
102
+ // TODO: using a default sets the value and therefore requires --uncrashable
103
+ // default: 'uncrashable-config.yaml',
104
+ dependsOn: ['uncrashable'],
105
+ }),
128
106
  };
@@ -1,59 +1,18 @@
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
3
  const url_1 = require("url");
7
- const chalk_1 = __importDefault(require("chalk"));
4
+ const core_1 = require("@oclif/core");
8
5
  const auth_1 = require("../command-helpers/auth");
9
6
  const jsonrpc_1 = require("../command-helpers/jsonrpc");
10
7
  const node_1 = require("../command-helpers/node");
11
- const HELP = `
12
- ${chalk_1.default.bold('graph create')} ${chalk_1.default.dim('[options]')} ${chalk_1.default.bold('<subgraph-name>')}
13
-
14
- ${chalk_1.default.dim('Options:')}
15
-
16
- --access-token <token> Graph access token
17
- -h, --help Show usage information
18
- -g, --node <url> Graph node to create the subgraph in
19
- `;
20
- exports.default = {
21
- description: 'Registers a subgraph name',
22
- run: async (toolbox) => {
23
- // Obtain tools
24
- const { print } = toolbox;
25
- // Read CLI parameters
26
- let { accessToken, g, h, help, node } = toolbox.parameters.options;
27
- const subgraphName = toolbox.parameters.first;
28
- // Support both long and short option variants
29
- node || (node = g);
30
- help || (help = h);
31
- // Show help text if requested
32
- if (help) {
33
- print.info(HELP);
34
- return;
35
- }
36
- // Validate the subgraph name
37
- if (!subgraphName) {
38
- print.error('No subgraph name provided');
39
- print.info(HELP);
40
- process.exitCode = 1;
41
- return;
42
- }
43
- // Validate node
44
- if (!node) {
45
- print.error(`No Graph node provided`);
46
- print.info(HELP);
47
- process.exitCode = 1;
48
- return;
49
- }
8
+ class CreateCommand extends core_1.Command {
9
+ async run() {
10
+ const { args: { 'subgraph-name': subgraphName }, flags: { 'access-token': accessTokenFlag, node }, } = await this.parse(CreateCommand);
50
11
  try {
51
12
  (0, node_1.validateNodeUrl)(node);
52
13
  }
53
14
  catch (e) {
54
- print.error(`Graph node "${node}" is invalid: ${e.message}`);
55
- process.exitCode = 1;
56
- return;
15
+ this.error(`Graph node "${node}" is invalid: ${e.message}`, { exit: 1 });
57
16
  }
58
17
  const requestUrl = new url_1.URL(node);
59
18
  const client = (0, jsonrpc_1.createJsonRpcClient)(requestUrl);
@@ -63,12 +22,12 @@ exports.default = {
63
22
  return;
64
23
  }
65
24
  // Use the access token, if one is set
66
- accessToken = await (0, auth_1.identifyDeployKey)(node, accessToken);
25
+ const accessToken = await (0, auth_1.identifyDeployKey)(node, accessTokenFlag);
67
26
  if (accessToken !== undefined && accessToken !== null) {
68
27
  // @ts-expect-error options property seems to exist
69
28
  client.options.headers = { Authorization: `Bearer ${accessToken}` };
70
29
  }
71
- const spinner = print.spin(`Creating subgraph in Graph node: ${requestUrl}`);
30
+ core_1.ux.action.start(`Creating subgraph in Graph node: ${requestUrl}`);
72
31
  client.request('subgraph_create', { name: subgraphName }, (
73
32
  // @ts-expect-error TODO: why are the arguments not typed?
74
33
  requestError,
@@ -78,17 +37,34 @@ exports.default = {
78
37
  // @ts-expect-error TODO: why are the arguments not typed?
79
38
  _res) => {
80
39
  if (jsonRpcError) {
81
- spinner.fail(`Error creating the subgraph: ${jsonRpcError.message}`);
82
- process.exitCode = 1;
40
+ core_1.ux.action.stop(`✖ Error creating the subgraph: ${jsonRpcError.message}`);
41
+ this.exit(1);
83
42
  }
84
43
  else if (requestError) {
85
- spinner.fail(`HTTP error creating the subgraph: ${requestError.code}`);
86
- process.exitCode = 1;
44
+ core_1.ux.action.stop(`✖ HTTP error creating the subgraph: ${requestError.code}`);
45
+ this.exit(1);
87
46
  }
88
47
  else {
89
- spinner.stop();
90
- print.success(`Created subgraph: ${subgraphName}`);
48
+ core_1.ux.action.stop('Subgraph created');
49
+ this.exit(1);
91
50
  }
92
51
  });
93
- },
52
+ }
53
+ }
54
+ exports.default = CreateCommand;
55
+ CreateCommand.description = 'Registers a subgraph name';
56
+ CreateCommand.args = {
57
+ 'subgraph-name': core_1.Args.string({
58
+ required: true,
59
+ }),
60
+ };
61
+ CreateCommand.flags = {
62
+ node: core_1.Flags.string({
63
+ summary: 'Graph node to create the subgraph in.',
64
+ char: 'g',
65
+ required: true,
66
+ }),
67
+ 'access-token': core_1.Flags.string({
68
+ summary: 'Graph access token.',
69
+ }),
94
70
  };