@graphprotocol/graph-cli 0.37.3-alpha-20230112182505-4508b8d → 0.37.3-alpha-20230112190020-19838fd

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # @graphprotocol/graph-cli
2
2
 
3
- ## 0.37.3-alpha-20230112182505-4508b8d
3
+ ## 0.37.3-alpha-20230112190020-19838fd
4
4
 
5
5
  ### Patch Changes
6
6
 
@@ -1,6 +1,4 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fixParameters = void 0;
4
2
  // Workaround for https://github.com/infinitered/gluegun/pull/464.
5
3
  //
6
4
  // There is currently no way in Gluegun to define command-line options
@@ -26,7 +24,8 @@ exports.fixParameters = void 0;
26
24
  // The `fixParameters` function checks if any of the provided boolean
27
25
  // options has a string value; if so, it pushes it to the front of the
28
26
  // parameters array and returns the result of that.
29
- //
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ exports.fixParameters = void 0;
30
29
  const fixParameters = (parameters, booleanOptions) => {
31
30
  let unexpectedStringOptions = Object.keys(booleanOptions)
32
31
  .filter(key => typeof booleanOptions[key] === 'string')
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.createJsonRpcClient = void 0;
7
7
  const jayson_1 = __importDefault(require("jayson"));
8
8
  const gluegun_1 = require("gluegun");
9
- const createJsonRpcClient = (url) => {
9
+ function createJsonRpcClient(url) {
10
10
  const params = {
11
11
  host: url.hostname,
12
12
  port: url.port,
@@ -25,5 +25,5 @@ const createJsonRpcClient = (url) => {
25
25
  gluegun_1.print.error('The Graph Node URL must be of the following format: http(s)://host[:port]/[path]');
26
26
  return null;
27
27
  }
28
- };
28
+ }
29
29
  exports.createJsonRpcClient = createJsonRpcClient;
@@ -27,7 +27,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  const chalk_1 = __importDefault(require("chalk"));
30
- const toolbox = __importStar(require("gluegun/toolbox"));
30
+ const toolbox = __importStar(require("gluegun"));
31
31
  const immutable_1 = __importDefault(require("immutable"));
32
32
  const spinner_1 = require("../command-helpers/spinner");
33
33
  const subgraph_1 = __importDefault(require("../subgraph"));
@@ -55,7 +55,7 @@ exports.default = {
55
55
  // Obtain tools
56
56
  let { print, system } = toolbox;
57
57
  // Read CLI parameters
58
- let { abi, contractName, h, help, mergeEntities, networkFile } = toolbox.parameters.options;
58
+ let { abi, contractName, h, help, mergeEntities, networkFile, } = toolbox.parameters.options;
59
59
  contractName = contractName || 'Contract';
60
60
  try {
61
61
  (0, gluegun_1.fixParameters)(toolbox.parameters, {
@@ -69,8 +69,8 @@ exports.default = {
69
69
  process.exitCode = 1;
70
70
  return;
71
71
  }
72
- let address = toolbox.parameters.first || toolbox.parameters.array[0];
73
- let manifestPath = toolbox.parameters.second || toolbox.parameters.array[1] || './subgraph.yaml';
72
+ let address = toolbox.parameters.first || toolbox.parameters.array?.[0];
73
+ let manifestPath = toolbox.parameters.second || toolbox.parameters.array?.[1] || './subgraph.yaml';
74
74
  // Show help text if requested
75
75
  if (help || h) {
76
76
  print.info(HELP);
@@ -85,7 +85,7 @@ exports.default = {
85
85
  const dataSourcesAndTemplates = await DataSourcesExtractor.fromFilePath(manifestPath);
86
86
  let protocol = protocols_1.default.fromDataSources(dataSourcesAndTemplates);
87
87
  let manifest = await subgraph_1.default.load(manifestPath, { protocol });
88
- let network = manifest.result.get('dataSources').get(0).get('network');
88
+ let network = manifest.result.getIn(['dataSources', 0, 'network']);
89
89
  let result = manifest.result.asMutable();
90
90
  let entities = getEntities(manifest);
91
91
  let contractNames = getContractNames(manifest);
@@ -130,30 +130,30 @@ exports.default = {
130
130
  const networksFile = networkFile || './networks.json';
131
131
  await (0, network_1.updateNetworksFile)(toolbox, network, contractName, address, networksFile);
132
132
  // Detect Yarn and/or NPM
133
- let yarn = await system.which('yarn');
134
- let npm = await system.which('npm');
133
+ let yarn = system.which('yarn');
134
+ let npm = system.which('npm');
135
135
  if (!yarn && !npm) {
136
136
  print.error(`Neither Yarn nor NPM were found on your system. Please install one of them.`);
137
137
  process.exitCode = 1;
138
138
  return;
139
139
  }
140
- await (0, spinner_1.withSpinner)('Running codegen', 'Failed to run codegen', 'Warning during codegen', async (spinner) => {
140
+ await (0, spinner_1.withSpinner)('Running codegen', 'Failed to run codegen', 'Warning during codegen', async () => {
141
141
  await system.run(yarn ? 'yarn codegen' : 'npm run codegen');
142
142
  });
143
143
  },
144
144
  };
145
- const getEntities = manifest => {
145
+ const getEntities = (manifest) => {
146
146
  let dataSources = manifest.result.get('dataSources', immutable_1.default.List());
147
147
  let templates = manifest.result.get('templates', immutable_1.default.List());
148
148
  return dataSources
149
149
  .concat(templates)
150
- .map(dataSource => dataSource.getIn(['mapping', 'entities']))
150
+ .map((dataSource) => dataSource.getIn(['mapping', 'entities']))
151
151
  .flatten();
152
152
  };
153
- const getContractNames = manifest => {
153
+ const getContractNames = (manifest) => {
154
154
  let dataSources = manifest.result.get('dataSources', immutable_1.default.List());
155
155
  let templates = manifest.result.get('templates', immutable_1.default.List());
156
- return dataSources.concat(templates).map(dataSource => dataSource.get('name'));
156
+ return dataSources.concat(templates).map((dataSource) => dataSource.get('name'));
157
157
  };
158
158
  const updateEventNamesOnCollision = (ethabi, entities, contractName, mergeEntities) => {
159
159
  let abiData = ethabi.data;
@@ -168,7 +168,7 @@ const updateEventNamesOnCollision = (ethabi, entities, contractName, mergeEntiti
168
168
  print.error(`Contract name ('${contractName}')
169
169
  + event name ('${dataRow.get('name')}') entity already exists.`);
170
170
  process.exitCode = 1;
171
- return;
171
+ break;
172
172
  }
173
173
  if (mergeEntities) {
174
174
  collisionEntities.push(dataRow.get('name'));
@@ -48,9 +48,9 @@ exports.default = {
48
48
  description: 'Sets the deploy key to use when deploying to a Graph node',
49
49
  run: async (toolbox) => {
50
50
  // Obtain tools
51
- let { filesystem, print, system } = toolbox;
51
+ const { print } = toolbox;
52
52
  // Read CLI parameters
53
- let { product, studio, h, help } = toolbox.parameters.options;
53
+ const { product, studio, h, help } = toolbox.parameters.options;
54
54
  // Show help text if requested
55
55
  if (help || h) {
56
56
  print.info(HELP);
@@ -21,7 +21,7 @@ exports.default = {
21
21
  description: 'Registers a subgraph name',
22
22
  run: async (toolbox) => {
23
23
  // Obtain tools
24
- let { filesystem, print, system } = toolbox;
24
+ const { print } = toolbox;
25
25
  // Read CLI parameters
26
26
  let { accessToken, g, h, help, node } = toolbox.parameters.options;
27
27
  let subgraphName = toolbox.parameters.first;
@@ -65,10 +65,15 @@ exports.default = {
65
65
  // Use the access token, if one is set
66
66
  accessToken = await (0, auth_1.identifyDeployKey)(node, accessToken);
67
67
  if (accessToken !== undefined && accessToken !== null) {
68
+ // @ts-expect-error options property seems to exist
68
69
  client.options.headers = { Authorization: `Bearer ${accessToken}` };
69
70
  }
70
71
  let spinner = print.spin(`Creating subgraph in Graph node: ${requestUrl}`);
71
- client.request('subgraph_create', { name: subgraphName }, function (requestError, jsonRpcError, res) {
72
+ client.request('subgraph_create', { name: subgraphName }, function (
73
+ // @ts-expect-error TODO: why are the arguments not typed?
74
+ requestError,
75
+ // @ts-expect-error TODO: why are the arguments not typed?
76
+ jsonRpcError) {
72
77
  if (jsonRpcError) {
73
78
  spinner.fail(`Error creating the subgraph: ${jsonRpcError.message}`);
74
79
  process.exitCode = 1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphprotocol/graph-cli",
3
- "version": "0.37.3-alpha-20230112182505-4508b8d",
3
+ "version": "0.37.3-alpha-20230112190020-19838fd",
4
4
  "license": "(Apache-2.0 OR MIT)",
5
5
  "description": "CLI for building for and deploying to The Graph",
6
6
  "main": "dist/cli.js",
@@ -23,8 +23,13 @@
23
23
  // The `fixParameters` function checks if any of the provided boolean
24
24
  // options has a string value; if so, it pushes it to the front of the
25
25
  // parameters array and returns the result of that.
26
- //
27
- export const fixParameters = (parameters: any, booleanOptions: any) => {
26
+
27
+ import { GluegunParameters } from 'gluegun'
28
+
29
+ export const fixParameters = (
30
+ parameters: GluegunParameters,
31
+ booleanOptions: Record<string, string>,
32
+ ) => {
28
33
  let unexpectedStringOptions = Object.keys(booleanOptions)
29
34
  .filter(key => typeof booleanOptions[key] === 'string')
30
35
  .map(key => ({ key, value: booleanOptions[key] }))
@@ -39,9 +44,9 @@ export const fixParameters = (parameters: any, booleanOptions: any) => {
39
44
  )
40
45
  } else if (unexpectedStringOptions.length == 1) {
41
46
  let params = parameters.array
42
- params.unshift(unexpectedStringOptions[0].value)
43
- return params
47
+ params!.unshift(unexpectedStringOptions[0].value)
48
+ return params!
44
49
  } else {
45
- return parameters.array
50
+ return parameters.array!
46
51
  }
47
52
  }
@@ -1,7 +1,7 @@
1
1
  import jayson from 'jayson'
2
2
  import { print } from 'gluegun'
3
3
 
4
- const createJsonRpcClient = (url: URL) => {
4
+ export function createJsonRpcClient(url: URL): jayson.Client | null {
5
5
  const params = {
6
6
  host: url.hostname,
7
7
  port: url.port,
@@ -24,5 +24,3 @@ const createJsonRpcClient = (url: URL) => {
24
24
  return null
25
25
  }
26
26
  }
27
-
28
- export { createJsonRpcClient }
@@ -16,8 +16,8 @@ export function chooseNodeUrl({
16
16
  }: {
17
17
  product: string
18
18
  studio: string
19
- node: string
20
- allowSimpleName: boolean
19
+ node?: string
20
+ allowSimpleName?: boolean
21
21
  }) {
22
22
  if (node) {
23
23
  try {
@@ -1,5 +1,5 @@
1
1
  import chalk from 'chalk'
2
- import * as toolbox from 'gluegun/toolbox'
2
+ import * as toolbox from 'gluegun'
3
3
  import immutable from 'immutable'
4
4
  import { withSpinner } from '../command-helpers/spinner'
5
5
  import Subgraph from '../subgraph'
@@ -29,15 +29,29 @@ ${chalk.dim('Options:')}
29
29
  -h, --help Show usage information
30
30
  `
31
31
 
32
+ export interface AddOptions {
33
+ abi?: string
34
+ contractName?: string
35
+ mergeEntities?: boolean
36
+ networkFile?: string
37
+ help?: boolean
38
+ }
39
+
32
40
  export default {
33
41
  description: 'Adds a new datasource to a subgraph',
34
- run: async toolbox => {
42
+ run: async (toolbox: toolbox.GluegunToolbox) => {
35
43
  // Obtain tools
36
44
  let { print, system } = toolbox
37
45
 
38
46
  // Read CLI parameters
39
- let { abi, contractName, h, help, mergeEntities, networkFile } =
40
- toolbox.parameters.options
47
+ let {
48
+ abi,
49
+ contractName,
50
+ h,
51
+ help,
52
+ mergeEntities,
53
+ networkFile,
54
+ } = toolbox.parameters.options
41
55
 
42
56
  contractName = contractName || 'Contract'
43
57
 
@@ -53,9 +67,9 @@ export default {
53
67
  return
54
68
  }
55
69
 
56
- let address = toolbox.parameters.first || toolbox.parameters.array[0]
70
+ let address = toolbox.parameters.first || toolbox.parameters.array?.[0]
57
71
  let manifestPath =
58
- toolbox.parameters.second || toolbox.parameters.array[1] || './subgraph.yaml'
72
+ toolbox.parameters.second || toolbox.parameters.array?.[1] || './subgraph.yaml'
59
73
 
60
74
  // Show help text if requested
61
75
  if (help || h) {
@@ -73,7 +87,7 @@ export default {
73
87
  const dataSourcesAndTemplates = await DataSourcesExtractor.fromFilePath(manifestPath)
74
88
  let protocol = Protocol.fromDataSources(dataSourcesAndTemplates)
75
89
  let manifest = await Subgraph.load(manifestPath, { protocol })
76
- let network = manifest.result.get('dataSources').get(0).get('network')
90
+ let network = manifest.result.getIn(['dataSources', 0, 'network']) as any
77
91
  let result = manifest.result.asMutable()
78
92
 
79
93
  let entities = getEntities(manifest)
@@ -109,7 +123,7 @@ export default {
109
123
  await writeSchema(
110
124
  ethabi,
111
125
  protocol,
112
- result.getIn(['schema', 'file']),
126
+ result.getIn(['schema', 'file']) as any,
113
127
  collisionEntities,
114
128
  )
115
129
  await writeMapping(ethabi, protocol, contractName, collisionEntities)
@@ -127,7 +141,7 @@ export default {
127
141
  // Handle the collisions edge case by copying another data source yaml data
128
142
  if (mergeEntities && onlyCollisions) {
129
143
  let firstDataSource = dataSources.get(0)
130
- let source = dataSource.get('source')
144
+ let source = dataSource.get('source') as any
131
145
  let mapping = firstDataSource.get('mapping').asMutable()
132
146
 
133
147
  // Save the address of the new data source
@@ -146,8 +160,8 @@ export default {
146
160
  await updateNetworksFile(toolbox, network, contractName, address, networksFile)
147
161
 
148
162
  // Detect Yarn and/or NPM
149
- let yarn = await system.which('yarn')
150
- let npm = await system.which('npm')
163
+ let yarn = system.which('yarn')
164
+ let npm = system.which('npm')
151
165
  if (!yarn && !npm) {
152
166
  print.error(
153
167
  `Neither Yarn nor NPM were found on your system. Please install one of them.`,
@@ -160,31 +174,36 @@ export default {
160
174
  'Running codegen',
161
175
  'Failed to run codegen',
162
176
  'Warning during codegen',
163
- async spinner => {
177
+ async () => {
164
178
  await system.run(yarn ? 'yarn codegen' : 'npm run codegen')
165
179
  },
166
180
  )
167
181
  },
168
182
  }
169
183
 
170
- const getEntities = manifest => {
184
+ const getEntities = (manifest: any) => {
171
185
  let dataSources = manifest.result.get('dataSources', immutable.List())
172
186
  let templates = manifest.result.get('templates', immutable.List())
173
187
 
174
188
  return dataSources
175
189
  .concat(templates)
176
- .map(dataSource => dataSource.getIn(['mapping', 'entities']))
190
+ .map((dataSource: any) => dataSource.getIn(['mapping', 'entities']))
177
191
  .flatten()
178
192
  }
179
193
 
180
- const getContractNames = manifest => {
194
+ const getContractNames = (manifest: any) => {
181
195
  let dataSources = manifest.result.get('dataSources', immutable.List())
182
196
  let templates = manifest.result.get('templates', immutable.List())
183
197
 
184
- return dataSources.concat(templates).map(dataSource => dataSource.get('name'))
198
+ return dataSources.concat(templates).map((dataSource: any) => dataSource.get('name'))
185
199
  }
186
200
 
187
- const updateEventNamesOnCollision = (ethabi, entities, contractName, mergeEntities) => {
201
+ const updateEventNamesOnCollision = (
202
+ ethabi: any,
203
+ entities: any,
204
+ contractName: string,
205
+ mergeEntities: boolean,
206
+ ) => {
188
207
  let abiData = ethabi.data
189
208
  let { print } = toolbox
190
209
  let collisionEntities = []
@@ -199,7 +218,7 @@ const updateEventNamesOnCollision = (ethabi, entities, contractName, mergeEntiti
199
218
  print.error(`Contract name ('${contractName}')
200
219
  + event name ('${dataRow.get('name')}') entity already exists.`)
201
220
  process.exitCode = 1
202
- return
221
+ break
203
222
  }
204
223
 
205
224
  if (mergeEntities) {
@@ -1,4 +1,5 @@
1
1
  import chalk from 'chalk'
2
+ import { GluegunToolbox } from 'gluegun'
2
3
  import { saveDeployKey } from '../command-helpers/auth'
3
4
  import { chooseNodeUrl } from '../command-helpers/node'
4
5
  import { fixParameters } from '../command-helpers/gluegun'
@@ -16,7 +17,19 @@ ${chalk.dim('Options:')}
16
17
  -h, --help Show usage information
17
18
  `
18
19
 
19
- const processForm = async (toolbox, { product, studio, node, deployKey }) => {
20
+ export interface AuthOptions {
21
+ product?: 'subgraph-studio' | 'hosted-service'
22
+ studio?: string
23
+ help?: boolean
24
+ // not a cli arg
25
+ node?: string
26
+ deployKey?: string
27
+ }
28
+
29
+ const processForm = async (
30
+ toolbox: GluegunToolbox,
31
+ { product, studio, node, deployKey }: AuthOptions,
32
+ ) => {
20
33
  const questions = [
21
34
  {
22
35
  type: 'select',
@@ -47,12 +60,12 @@ const processForm = async (toolbox, { product, studio, node, deployKey }) => {
47
60
 
48
61
  export default {
49
62
  description: 'Sets the deploy key to use when deploying to a Graph node',
50
- run: async toolbox => {
63
+ run: async (toolbox: GluegunToolbox) => {
51
64
  // Obtain tools
52
- let { filesystem, print, system } = toolbox
65
+ const { print } = toolbox
53
66
 
54
67
  // Read CLI parameters
55
- let { product, studio, h, help } = toolbox.parameters.options
68
+ const { product, studio, h, help } = toolbox.parameters.options
56
69
 
57
70
  // Show help text if requested
58
71
  if (help || h) {
@@ -60,7 +73,7 @@ export default {
60
73
  return
61
74
  }
62
75
 
63
- let firstParam, secondParam
76
+ let firstParam: string, secondParam: string
64
77
  try {
65
78
  ;[firstParam, secondParam] = fixParameters(toolbox.parameters, {
66
79
  h,
@@ -74,7 +87,7 @@ export default {
74
87
  }
75
88
 
76
89
  // if user specifies --product or --studio then deployKey is the first parameter
77
- let node
90
+ let node: string | undefined
78
91
  let deployKey
79
92
  if (product || studio) {
80
93
  ;({ node } = chooseNodeUrl({ product, studio, node }))
@@ -119,7 +132,7 @@ export default {
119
132
  }
120
133
 
121
134
  try {
122
- await saveDeployKey(node, deployKey)
135
+ await saveDeployKey(node!, deployKey)
123
136
  print.success(`Deploy key set for ${node}`)
124
137
  } catch (e) {
125
138
  print.error(e)
@@ -1,5 +1,6 @@
1
1
  import { URL } from 'url'
2
2
  import chalk from 'chalk'
3
+ import * as toolbox from 'gluegun'
3
4
  import { validateNodeUrl } from '../command-helpers/node'
4
5
  import { identifyDeployKey as identifyAccessToken } from '../command-helpers/auth'
5
6
  import { createJsonRpcClient } from '../command-helpers/jsonrpc'
@@ -14,11 +15,17 @@ ${chalk.dim('Options:')}
14
15
  -g, --node <url> Graph node to create the subgraph in
15
16
  `
16
17
 
18
+ export interface AddOptions {
19
+ accessToken?: string
20
+ help?: boolean
21
+ node?: string
22
+ }
23
+
17
24
  export default {
18
25
  description: 'Registers a subgraph name',
19
- run: async toolbox => {
26
+ run: async (toolbox: toolbox.GluegunToolbox) => {
20
27
  // Obtain tools
21
- let { filesystem, print, system } = toolbox
28
+ const { print } = toolbox
22
29
 
23
30
  // Read CLI parameters
24
31
  let { accessToken, g, h, help, node } = toolbox.parameters.options
@@ -69,25 +76,27 @@ export default {
69
76
  // Use the access token, if one is set
70
77
  accessToken = await identifyAccessToken(node, accessToken)
71
78
  if (accessToken !== undefined && accessToken !== null) {
79
+ // @ts-expect-error options property seems to exist
72
80
  client.options.headers = { Authorization: `Bearer ${accessToken}` }
73
81
  }
74
82
 
75
83
  let spinner = print.spin(`Creating subgraph in Graph node: ${requestUrl}`)
76
- client.request(
77
- 'subgraph_create',
78
- { name: subgraphName },
79
- function (requestError, jsonRpcError, res) {
80
- if (jsonRpcError) {
81
- spinner.fail(`Error creating the subgraph: ${jsonRpcError.message}`)
82
- process.exitCode = 1
83
- } else if (requestError) {
84
- spinner.fail(`HTTP error creating the subgraph: ${requestError.code}`)
85
- process.exitCode = 1
86
- } else {
87
- spinner.stop()
88
- print.success(`Created subgraph: ${subgraphName}`)
89
- }
90
- },
91
- )
84
+ client.request('subgraph_create', { name: subgraphName }, function(
85
+ // @ts-expect-error TODO: why are the arguments not typed?
86
+ requestError,
87
+ // @ts-expect-error TODO: why are the arguments not typed?
88
+ jsonRpcError,
89
+ ) {
90
+ if (jsonRpcError) {
91
+ spinner.fail(`Error creating the subgraph: ${jsonRpcError.message}`)
92
+ process.exitCode = 1
93
+ } else if (requestError) {
94
+ spinner.fail(`HTTP error creating the subgraph: ${requestError.code}`)
95
+ process.exitCode = 1
96
+ } else {
97
+ spinner.stop()
98
+ print.success(`Created subgraph: ${subgraphName}`)
99
+ }
100
+ })
92
101
  },
93
102
  }
package/src/subgraph.ts CHANGED
@@ -275,7 +275,7 @@ More than one template named '${name}', template names must be unique.`,
275
275
  }
276
276
  }
277
277
 
278
- let manifest = immutable.fromJS(data)
278
+ let manifest = immutable.fromJS(data) as immutable.Map<any, any>
279
279
 
280
280
  // Validate the schema
281
281
  Subgraph.validateSchema(manifest, { resolveFile })