@graphprotocol/graph-cli 0.62.0-alpha-20231113201404-b050447 → 0.62.0-alpha-20231115143846-eca7ecc

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,13 +1,37 @@
1
1
  # @graphprotocol/graph-cli
2
2
 
3
- ## 0.62.0-alpha-20231113201404-b050447
3
+ ## 0.62.0-alpha-20231115143846-eca7ecc
4
4
 
5
5
  ### Minor Changes
6
6
 
7
7
  - [#1500](https://github.com/graphprotocol/graph-tooling/pull/1500)
8
- [`fe8cce4`](https://github.com/graphprotocol/graph-tooling/commit/fe8cce423e28adf88669d02340e29eeb08adce5f)
8
+ [`4b92a5e`](https://github.com/graphprotocol/graph-tooling/commit/4b92a5ef87661a39021d5945a427d32d3a2873b2)
9
9
  Thanks [@saihaj](https://github.com/saihaj)! - upgrade to Node 20
10
10
 
11
+ ### Patch Changes
12
+
13
+ - [#1461](https://github.com/graphprotocol/graph-tooling/pull/1461)
14
+ [`cbbb0fc`](https://github.com/graphprotocol/graph-tooling/commit/cbbb0fc2050019c705f25f59a2bbb6a8ff9b7c32)
15
+ Thanks [@saihaj](https://github.com/saihaj)! - include user agent for CLI fetch calls
16
+
17
+ - [#1461](https://github.com/graphprotocol/graph-tooling/pull/1461)
18
+ [`cbbb0fc`](https://github.com/graphprotocol/graph-tooling/commit/cbbb0fc2050019c705f25f59a2bbb6a8ff9b7c32)
19
+ Thanks [@saihaj](https://github.com/saihaj)! - send graph cli version as user agent for all third
20
+ party API calls
21
+
22
+ - [#1461](https://github.com/graphprotocol/graph-tooling/pull/1461)
23
+ [`cbbb0fc`](https://github.com/graphprotocol/graph-tooling/commit/cbbb0fc2050019c705f25f59a2bbb6a8ff9b7c32)
24
+ Thanks [@saihaj](https://github.com/saihaj)! - send graph cli version as user agent for all ipfs
25
+ requests
26
+
27
+ - [#1503](https://github.com/graphprotocol/graph-tooling/pull/1503)
28
+ [`4fa0ace`](https://github.com/graphprotocol/graph-tooling/commit/4fa0ace140b5d03cae9419c8b9eba529bb33cb41)
29
+ Thanks [@saihaj](https://github.com/saihaj)! - sanitize special characters in codegeneration
30
+
31
+ - [#1504](https://github.com/graphprotocol/graph-tooling/pull/1504)
32
+ [`8b509ec`](https://github.com/graphprotocol/graph-tooling/commit/8b509ecd6d7cc28888eb054c03ae7de56ba8c288)
33
+ Thanks [@saihaj](https://github.com/saihaj)! - dedupe imports in codegen
34
+
11
35
  ## 0.61.0
12
36
 
13
37
  ### Minor Changes
@@ -5,11 +5,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.loadAbiFromBlockScout = exports.getStartBlockForContract = exports.fetchTransactionByHashFromRPC = exports.fetchContractCreationHashWithRetry = exports.fetchDeployContractTransactionFromEtherscan = exports.loadStartBlockForContract = exports.loadAbiFromEtherscan = void 0;
7
7
  const immutable_1 = __importDefault(require("immutable"));
8
- const fetch_1 = require("@whatwg-node/fetch");
8
+ const constants_1 = require("../constants");
9
+ const fetch_1 = __importDefault(require("../fetch"));
9
10
  const spinner_1 = require("./spinner");
10
11
  const loadAbiFromEtherscan = async (ABICtor, network, address) => await (0, spinner_1.withSpinner)(`Fetching ABI from Etherscan`, `Failed to fetch ABI from Etherscan`, `Warnings while fetching ABI from Etherscan`, async () => {
11
12
  const scanApiUrl = getEtherscanLikeAPIUrl(network);
12
- const result = await (0, fetch_1.fetch)(`${scanApiUrl}?module=contract&action=getabi&address=${address}`);
13
+ const result = await (0, fetch_1.default)(`${scanApiUrl}?module=contract&action=getabi&address=${address}`);
13
14
  const json = await result.json();
14
15
  // Etherscan returns a JSON object that has a `status`, a `message` and
15
16
  // a `result` field. The `status` is '0' in case of errors and '1' in
@@ -37,7 +38,7 @@ const fetchContractCreationHashWithRetry = async (url, retryCount) => {
37
38
  let json;
38
39
  for (let i = 0; i < retryCount; i++) {
39
40
  try {
40
- const result = await (0, fetch_1.fetch)(url);
41
+ const result = await (0, fetch_1.default)(url);
41
42
  json = await result.json();
42
43
  if (json.status !== '0') {
43
44
  return json;
@@ -56,10 +57,11 @@ const fetchTransactionByHashFromRPC = async (network, transactionHash) => {
56
57
  const RPCURL = getPublicRPCEndpoint(network);
57
58
  if (!RPCURL)
58
59
  throw new Error(`Unable to fetch RPC URL for ${network}`);
59
- const result = await (0, fetch_1.fetch)(String(RPCURL), {
60
+ const result = await (0, fetch_1.default)(String(RPCURL), {
60
61
  method: 'POST',
61
62
  headers: {
62
63
  'Content-Type': 'application/json',
64
+ ...constants_1.GRAPH_CLI_SHARED_HEADERS,
63
65
  },
64
66
  body: JSON.stringify({
65
67
  jsonrpc: '2.0',
@@ -88,7 +90,7 @@ const getStartBlockForContract = async (network, address) => {
88
90
  };
89
91
  exports.getStartBlockForContract = getStartBlockForContract;
90
92
  const loadAbiFromBlockScout = async (ABICtor, network, address) => await (0, spinner_1.withSpinner)(`Fetching ABI from BlockScout`, `Failed to fetch ABI from BlockScout`, `Warnings while fetching ABI from BlockScout`, async () => {
91
- const result = await (0, fetch_1.fetch)(`https://blockscout.com/${network.replace('-', '/')}/api?module=contract&action=getabi&address=${address}`);
93
+ const result = await (0, fetch_1.default)(`https://blockscout.com/${network.replace('-', '/')}/api?module=contract&action=getabi&address=${address}`);
92
94
  const json = await result.json();
93
95
  // BlockScout returns a JSON object that has a `status`, a `message` and
94
96
  // a `result` field. The `status` is '0' in case of errors and '1' in
@@ -31,6 +31,7 @@ const url_1 = require("url");
31
31
  const toolbox = __importStar(require("gluegun"));
32
32
  const ipfs_http_client_1 = require("ipfs-http-client");
33
33
  const compiler_1 = __importDefault(require("../compiler"));
34
+ const constants_1 = require("../constants");
34
35
  /**
35
36
  * Appends /api/v0 to the end of a The Graph IPFS URL
36
37
  */
@@ -61,7 +62,13 @@ The IPFS URL must be of the following format: http(s)://host[:port]/[path]`);
61
62
  }
62
63
  // Connect to the IPFS node (if a node address was provided)
63
64
  const ipfsClient = ipfs
64
- ? (0, ipfs_http_client_1.create)({ url: appendApiVersionForGraph(ipfs.toString()), headers })
65
+ ? (0, ipfs_http_client_1.create)({
66
+ url: appendApiVersionForGraph(ipfs.toString()),
67
+ headers: {
68
+ ...headers,
69
+ ...constants_1.GRAPH_CLI_SHARED_HEADERS,
70
+ },
71
+ })
65
72
  : undefined;
66
73
  return new compiler_1.default({
67
74
  ipfs: ipfsClient,
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getHostedServiceSubgraphId = exports.chooseNodeUrl = exports.normalizeNodeUrl = exports.validateNodeUrl = void 0;
4
4
  const url_1 = require("url");
5
5
  const gluegun_1 = require("gluegun");
6
+ const constants_1 = require("../constants");
6
7
  const SUBGRAPH_STUDIO_URL = 'https://api.studio.thegraph.com/deploy/';
7
8
  const HOSTED_SERVICE_URL = 'https://api.thegraph.com/deploy/';
8
9
  const HOSTED_SERVICE_INDEX_NODE_URL = 'https://api.thegraph.com/index-node/graphql';
@@ -58,7 +59,7 @@ async function getHostedServiceSubgraphId({ subgraphName, }) {
58
59
  }),
59
60
  headers: {
60
61
  'content-type': 'application/json',
61
- 'User-Agent': '@graphprotocol/graph-cli',
62
+ ...constants_1.GRAPH_CLI_SHARED_HEADERS,
62
63
  },
63
64
  });
64
65
  const { data, errors } = await response.json();
@@ -6,6 +6,7 @@ const core_1 = require("@oclif/core");
6
6
  const auth_1 = require("../command-helpers/auth");
7
7
  const jsonrpc_1 = require("../command-helpers/jsonrpc");
8
8
  const node_1 = require("../command-helpers/node");
9
+ const constants_1 = require("../constants");
9
10
  class CreateCommand extends core_1.Command {
10
11
  async run() {
11
12
  const { args: { 'subgraph-name': subgraphName }, flags: { 'access-token': accessTokenFlag, node }, } = await this.parse(CreateCommand);
@@ -26,7 +27,10 @@ class CreateCommand extends core_1.Command {
26
27
  const accessToken = await (0, auth_1.identifyDeployKey)(node, accessTokenFlag);
27
28
  if (accessToken !== undefined && accessToken !== null) {
28
29
  // @ts-expect-error options property seems to exist
29
- client.options.headers = { Authorization: `Bearer ${accessToken}` };
30
+ client.options.headers = {
31
+ ...constants_1.GRAPH_CLI_SHARED_HEADERS,
32
+ Authorization: `Bearer ${accessToken}`,
33
+ };
30
34
  }
31
35
  const spinner = gluegun_1.print.spin(`Creating subgraph in Graph node: ${requestUrl}`);
32
36
  client.request('subgraph_create', { name: subgraphName }, (
@@ -40,6 +40,7 @@ const network_1 = require("../command-helpers/network");
40
40
  const node_1 = require("../command-helpers/node");
41
41
  const studio_1 = require("../command-helpers/studio");
42
42
  const version_1 = require("../command-helpers/version");
43
+ const constants_1 = require("../constants");
43
44
  const protocols_1 = __importDefault(require("../protocols"));
44
45
  const headersFlag = core_1.Flags.custom({
45
46
  summary: 'Add custom headers that will be used by the IPFS HTTP client.',
@@ -86,7 +87,10 @@ class DeployCommand extends core_1.Command {
86
87
  this.error('No deploy key available');
87
88
  }
88
89
  // @ts-expect-error options property seems to exist
89
- client.options.headers = { Authorization: 'Bearer ' + deployKey };
90
+ client.options.headers = {
91
+ ...constants_1.GRAPH_CLI_SHARED_HEADERS,
92
+ Authorization: 'Bearer ' + deployKey,
93
+ };
90
94
  const subgraphName = await core_1.ux.prompt('What is the name of the subgraph you want to deploy?', {
91
95
  required: true,
92
96
  });
@@ -194,7 +198,10 @@ class DeployCommand extends core_1.Command {
194
198
  deployKey = await (0, auth_1.identifyDeployKey)(node, deployKey);
195
199
  if (deployKey !== undefined && deployKey !== null) {
196
200
  // @ts-expect-error options property seems to exist
197
- client.options.headers = { Authorization: 'Bearer ' + deployKey };
201
+ client.options.headers = {
202
+ ...constants_1.GRAPH_CLI_SHARED_HEADERS,
203
+ Authorization: 'Bearer ' + deployKey,
204
+ };
198
205
  }
199
206
  // Ask for label if not on hosted service
200
207
  let versionLabel = versionLabelFlag;
@@ -271,7 +278,10 @@ class DeployCommand extends core_1.Command {
271
278
  // Connect to the IPFS node (if a node address was provided)
272
279
  const ipfsClient = (0, ipfs_http_client_1.create)({
273
280
  url: (0, compiler_1.appendApiVersionForGraph)(ipfs.toString()),
274
- headers,
281
+ headers: {
282
+ ...headers,
283
+ ...constants_1.GRAPH_CLI_SHARED_HEADERS,
284
+ },
275
285
  });
276
286
  // Fetch the manifest from IPFS
277
287
  const manifestBuffer = ipfsClient.cat(ipfsHash);
@@ -6,6 +6,7 @@ const core_1 = require("@oclif/core");
6
6
  const auth_1 = require("../command-helpers/auth");
7
7
  const jsonrpc_1 = require("../command-helpers/jsonrpc");
8
8
  const node_1 = require("../command-helpers/node");
9
+ const constants_1 = require("../constants");
9
10
  class RemoveCommand extends core_1.Command {
10
11
  async run() {
11
12
  const { args: { 'subgraph-name': subgraphName }, flags: { 'access-token': accessTokenFlag, node }, } = await this.parse(RemoveCommand);
@@ -26,7 +27,10 @@ class RemoveCommand extends core_1.Command {
26
27
  const accessToken = await (0, auth_1.identifyDeployKey)(node, accessTokenFlag);
27
28
  if (accessToken !== undefined && accessToken !== null) {
28
29
  // @ts-expect-error options property seems to exist
29
- client.options.headers = { Authorization: `Bearer ${accessToken}` };
30
+ client.options.headers = {
31
+ ...constants_1.GRAPH_CLI_SHARED_HEADERS,
32
+ Authorization: `Bearer ${accessToken}`,
33
+ };
30
34
  }
31
35
  const spinner = gluegun_1.print.spin(`Creating subgraph in Graph node: ${requestUrl}`);
32
36
  client.request('subgraph_remove', { name: subgraphName }, (
@@ -11,7 +11,8 @@ const gluegun_1 = require("gluegun");
11
11
  const js_yaml_1 = __importDefault(require("js-yaml"));
12
12
  const semver_1 = __importDefault(require("semver"));
13
13
  const core_1 = require("@oclif/core");
14
- const fetch_1 = require("@whatwg-node/fetch");
14
+ const constants_1 = require("../constants");
15
+ const fetch_1 = __importDefault(require("../fetch"));
15
16
  class TestCommand extends core_1.Command {
16
17
  async run() {
17
18
  const { args: { datasource }, flags: { coverage, docker, force, logs, recompile, version }, } = await this.parse(TestCommand);
@@ -48,9 +49,9 @@ class TestCommand extends core_1.Command {
48
49
  // Fetch the latest version tag if version is not specified with -v/--version or if the version is not cached
49
50
  if (opts.force || (!opts.version && !opts.latestVersion)) {
50
51
  this.log('Fetching latest version tag...');
51
- const result = await (0, fetch_1.fetch)('https://api.github.com/repos/LimeChain/matchstick/releases/latest', {
52
+ const result = await (0, fetch_1.default)('https://api.github.com/repos/LimeChain/matchstick/releases/latest', {
52
53
  headers: {
53
- 'User-Agent': '@graphprotocol/graph-cli',
54
+ ...constants_1.GRAPH_CLI_SHARED_HEADERS,
54
55
  },
55
56
  });
56
57
  const json = await result.json();
@@ -281,7 +282,7 @@ async function dockerfile(dockerfilePath, versionOpt, latestVersion) {
281
282
  const spinner = gluegun_1.print.spin('Generating Dockerfile...');
282
283
  try {
283
284
  // Fetch the Dockerfile template content from the demo-subgraph repo
284
- const content = await (0, fetch_1.fetch)('https://raw.githubusercontent.com/LimeChain/demo-subgraph/main/Dockerfile').then(response => {
285
+ const content = await (0, fetch_1.default)('https://raw.githubusercontent.com/LimeChain/demo-subgraph/main/Dockerfile').then(response => {
285
286
  if (response.ok) {
286
287
  return response.text();
287
288
  }
@@ -0,0 +1,3 @@
1
+ export declare const GRAPH_CLI_SHARED_HEADERS: {
2
+ 'User-Agent': `@graphprotocol/graph-cli@${string}`;
3
+ };
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GRAPH_CLI_SHARED_HEADERS = void 0;
4
+ const version_1 = require("./version");
5
+ exports.GRAPH_CLI_SHARED_HEADERS = {
6
+ 'User-Agent': `@graphprotocol/graph-cli@${version_1.version}`,
7
+ };
@@ -0,0 +1,2 @@
1
+ import { fetch } from '@whatwg-node/fetch';
2
+ export default function fetchWrapper(input: Parameters<typeof fetch>[0], init?: Parameters<typeof fetch>[1]): Promise<Response>;
package/dist/fetch.js ADDED
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // eslint-disable-next-line no-restricted-imports
4
+ const fetch_1 = require("@whatwg-node/fetch");
5
+ const constants_1 = require("./constants");
6
+ function fetchWrapper(input, init) {
7
+ return (0, fetch_1.fetch)(input, {
8
+ ...init,
9
+ headers: {
10
+ ...init?.headers,
11
+ ...constants_1.GRAPH_CLI_SHARED_HEADERS,
12
+ },
13
+ });
14
+ }
15
+ exports.default = fetchWrapper;
@@ -40,6 +40,8 @@ class AbiCodeGenerator {
40
40
  constructor(abi) {
41
41
  this.abi = abi;
42
42
  this.abi = abi;
43
+ // Sanitize the name of the ABI to make it a valid class name
44
+ this.abi.name = abi.name.replace(/[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?]+/g, '_');
43
45
  }
44
46
  generateModuleImports() {
45
47
  const imports = [
@@ -151,6 +151,7 @@ class TypeGenerator {
151
151
  });
152
152
  }
153
153
  async generateTypesForDataSourceTemplates(subgraph) {
154
+ const moduleImports = [];
154
155
  return await (0, spinner_1.withSpinner)(`Generate types for data source templates`, `Failed to generate types for data source templates`, `Warnings while generating types for data source templates`, async (spinner) => {
155
156
  // Combine the generated code for all templates
156
157
  const codeSegments = subgraph
@@ -158,15 +159,30 @@ class TypeGenerator {
158
159
  .reduce((codeSegments, template) => {
159
160
  (0, spinner_1.step)(spinner, 'Generate types for data source template', String(template.get('name')));
160
161
  const codeGenerator = new template_1.default(template, this.protocol);
161
- // Only generate module imports once, because they are identical for
162
- // all types generated for data source templates.
163
- if (codeSegments.isEmpty()) {
164
- codeSegments = codeSegments.concat(codeGenerator.generateModuleImports());
165
- }
162
+ // we want to get all the imports from the templates
163
+ moduleImports.push(...codeGenerator.generateModuleImports());
166
164
  return codeSegments.concat(codeGenerator.generateTypes());
167
165
  }, immutable_1.default.List());
166
+ // we want to dedupe the imports from the templates
167
+ const dedupeModulesImports = moduleImports.reduce((acc, curr) => {
168
+ const found = acc.find(item => item.module === curr.module);
169
+ if (found) {
170
+ const foundNames = Array.isArray(found.nameOrNames)
171
+ ? found.nameOrNames
172
+ : [found.nameOrNames];
173
+ const currNames = Array.isArray(curr.nameOrNames)
174
+ ? curr.nameOrNames
175
+ : [curr.nameOrNames];
176
+ const names = new Set([...foundNames, ...currNames]);
177
+ found.nameOrNames = Array.from(names);
178
+ }
179
+ else {
180
+ acc.push(curr);
181
+ }
182
+ return acc;
183
+ }, []);
168
184
  if (!codeSegments.isEmpty()) {
169
- const code = prettier_1.default.format([typescript_1.GENERATED_FILE_NOTE, ...codeSegments].join('\n'), {
185
+ const code = prettier_1.default.format([typescript_1.GENERATED_FILE_NOTE, ...dedupeModulesImports, ...codeSegments].join('\n'), {
170
186
  parser: 'typescript',
171
187
  });
172
188
  const outputFile = path_1.default.join(this.options.outputDir, 'templates.ts');
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.62.0-alpha-20231113201404-b050447",
2
+ "version": "0.62.0-alpha-20231115143846-eca7ecc",
3
3
  "commands": {
4
4
  "add": {
5
5
  "id": "add",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphprotocol/graph-cli",
3
- "version": "0.62.0-alpha-20231113201404-b050447",
3
+ "version": "0.62.0-alpha-20231115143846-eca7ecc",
4
4
  "description": "CLI for building for and deploying to The Graph",
5
5
  "license": "(Apache-2.0 OR MIT)",
6
6
  "engines": {
@@ -23,7 +23,7 @@
23
23
  "@oclif/core": "2.8.6",
24
24
  "@oclif/plugin-autocomplete": "^2.3.6",
25
25
  "@oclif/plugin-not-found": "^2.4.0",
26
- "@whatwg-node/fetch": "^0.8.4",
26
+ "@whatwg-node/fetch": "^0.9.0",
27
27
  "assemblyscript": "0.19.23",
28
28
  "binary-install-raw": "0.0.13",
29
29
  "chalk": "3.0.0",