@graphprotocol/graph-cli 0.77.0 → 0.78.1-alpha-20240716210753-d878dfa

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,5 +1,21 @@
1
1
  # @graphprotocol/graph-cli
2
2
 
3
+ ## 0.78.1-alpha-20240716210753-d878dfa
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1549](https://github.com/graphprotocol/graph-tooling/pull/1549)
8
+ [`c7fb38a`](https://github.com/graphprotocol/graph-tooling/commit/c7fb38a55b7a0a355aa94c243f2dc99882023077)
9
+ Thanks [@YassinEldeeb](https://github.com/YassinEldeeb)! - testing napi bindings
10
+
11
+ ## 0.78.0
12
+
13
+ ### Minor Changes
14
+
15
+ - [#1692](https://github.com/graphprotocol/graph-tooling/pull/1692)
16
+ [`6f84e7a`](https://github.com/graphprotocol/graph-tooling/commit/6f84e7ade5c51232abefcb9a6fb7406e375ad125)
17
+ Thanks [@yash251](https://github.com/yash251)! - add iotex urls
18
+
3
19
  ## 0.77.0
4
20
 
5
21
  ### Minor Changes
package/README.md CHANGED
@@ -18,8 +18,7 @@ As of today, the command line interface supports the following commands:
18
18
  the system's keychain.
19
19
  - `graph local` — Runs tests against a [Graph Node](https://github.com/graphprotocol/graph-node)
20
20
  test environment (using Ganache by default).
21
- - `graph test` — Downloads and runs the [Matchstick](https://github.com/LimeChain/matchstick) rust
22
- binary in order to test a subgraph.
21
+ - `graph test` — Runs tests against the subgraph.
23
22
  - `graph add` - Adds a new datasource to the yaml file and writes the necessary changes to other
24
23
  files - schema.graphql, abi and mapping.
25
24
  - `graph publish` - Publishes the subgraph to the Graph Network.
@@ -239,6 +239,8 @@ const getEtherscanLikeAPIUrl = (network) => {
239
239
  return `https://seitrace.com/pacific-1/api`;
240
240
  case 'rootstock':
241
241
  return 'https://rootstock.blockscout.com/api';
242
+ case 'iotex':
243
+ return 'https://index.iotexscan.io/api';
242
244
  default:
243
245
  return `https://api-${network}.etherscan.io/api`;
244
246
  }
@@ -353,6 +355,8 @@ const getPublicRPCEndpoint = (network) => {
353
355
  return `https://evm-rpc.sei-apis.com`;
354
356
  case 'rootstock':
355
357
  return 'https://public-node.rsk.co';
358
+ case 'iotex':
359
+ return 'https://iotexrpc.com';
356
360
  default:
357
361
  throw new Error(`Unknown network: ${network}`);
358
362
  }
@@ -7,7 +7,6 @@ export default class TestCommand extends Command {
7
7
  static flags: {
8
8
  help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
9
9
  coverage: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
10
- docker: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
11
10
  force: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
12
11
  logs: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
13
12
  recompile: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
@@ -3,19 +3,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const child_process_1 = require("child_process");
7
- const os_1 = __importDefault(require("os"));
8
6
  const path_1 = __importDefault(require("path"));
9
- const binary_install_raw_1 = require("binary-install-raw");
10
7
  const gluegun_1 = require("gluegun");
11
8
  const js_yaml_1 = __importDefault(require("js-yaml"));
12
- const semver_1 = __importDefault(require("semver"));
9
+ // This'd import the N-API bindings based on the OS and architecture
10
+ const testing_1 = require("@graphprotocol/graph-tooling-napi-utils/mod/testing");
13
11
  const core_1 = require("@oclif/core");
14
- const constants_1 = require("../constants");
15
- const fetch_1 = __importDefault(require("../fetch"));
16
12
  class TestCommand extends core_1.Command {
17
13
  async run() {
18
- const { args: { datasource }, flags: { coverage, docker, force, logs, recompile, version }, } = await this.parse(TestCommand);
14
+ const { args: { datasource }, flags: { coverage, force, logs, recompile, version }, } = await this.parse(TestCommand);
19
15
  let testsDir = './tests';
20
16
  // Check if matchstick.yaml config exists
21
17
  if (gluegun_1.filesystem.exists('matchstick.yaml')) {
@@ -39,36 +35,13 @@ class TestCommand extends core_1.Command {
39
35
  testsDir,
40
36
  cachePath,
41
37
  coverage,
42
- docker,
43
38
  force,
44
39
  logs,
45
40
  recompile,
46
41
  version,
47
42
  latestVersion: getLatestVersionFromCache(cachePath),
48
43
  };
49
- // Fetch the latest version tag if version is not specified with -v/--version or if the version is not cached
50
- if (opts.force || (!opts.version && !opts.latestVersion)) {
51
- this.log('Fetching latest version tag...');
52
- const result = await (0, fetch_1.default)('https://api.github.com/repos/LimeChain/matchstick/releases/latest', {
53
- headers: {
54
- ...constants_1.GRAPH_CLI_SHARED_HEADERS,
55
- },
56
- });
57
- const json = await result.json();
58
- opts.latestVersion = json.tag_name;
59
- gluegun_1.filesystem.file(opts.cachePath, {
60
- content: {
61
- version: json.tag_name,
62
- timestamp: Date.now(),
63
- },
64
- });
65
- }
66
- if (opts.docker) {
67
- runDocker.bind(this)(datasource, opts);
68
- }
69
- else {
70
- runBinary.bind(this)(datasource, opts);
71
- }
44
+ runNapi.bind(this)(datasource, opts);
72
45
  }
73
46
  }
74
47
  TestCommand.description = 'Runs rust binary for subgraph testing.';
@@ -83,12 +56,8 @@ TestCommand.flags = {
83
56
  summary: 'Run the tests in coverage mode.',
84
57
  char: 'c',
85
58
  }),
86
- docker: core_1.Flags.boolean({
87
- summary: 'Run the tests in a docker container (Note: Please execute from the root folder of the subgraph).',
88
- char: 'd',
89
- }),
90
59
  force: core_1.Flags.boolean({
91
- summary: 'Binary - overwrites folder + file when downloading. Docker - rebuilds the docker image.',
60
+ summary: 'Binary - overwrites folder + file when downloading.',
92
61
  char: 'f',
93
62
  }),
94
63
  logs: core_1.Flags.boolean({
@@ -117,186 +86,21 @@ function getLatestVersionFromCache(cachePath) {
117
86
  }
118
87
  return null;
119
88
  }
120
- async function runBinary(datasource, opts) {
121
- const coverageOpt = opts.coverage;
122
- const forceOpt = opts.force;
123
- const logsOpt = opts.logs;
124
- const versionOpt = opts.version;
125
- const latestVersion = opts.latestVersion;
126
- const recompileOpt = opts.recompile;
127
- const platform = await getPlatform.bind(this)(versionOpt || latestVersion, logsOpt);
128
- const url = `https://github.com/LimeChain/matchstick/releases/download/${versionOpt || latestVersion}/${platform}`;
129
- if (logsOpt) {
130
- this.log(`Download link: ${url}`);
131
- }
132
- const binary = new binary_install_raw_1.Binary(platform, url, versionOpt || latestVersion);
133
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
134
- forceOpt ? await binary.install(true) : await binary.install(false);
89
+ async function runNapi(datasource, opts) {
135
90
  const args = [];
136
- if (coverageOpt)
137
- args.push('-c');
138
- if (recompileOpt)
139
- args.push('-r');
91
+ if (opts.coverage)
92
+ args.push('--coverage');
93
+ if (opts.recompile)
94
+ args.push('--recompile');
140
95
  if (datasource)
141
96
  args.push(datasource);
142
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
143
- args.length > 0 ? binary.run(...args) : binary.run();
144
- }
145
- async function getPlatform(matchstickVersion, logsOpt) {
146
- const type = os_1.default.type();
147
- const arch = os_1.default.arch();
148
- const cpuCore = os_1.default.cpus()[0];
149
- const isAppleSilicon = arch === 'arm64' && /Apple (M1|M2|M3|processor)/.test(cpuCore.model);
150
- const linuxInfo = type === 'Linux' ? await getLinuxInfo.bind(this)() : {};
151
- const linuxDistro = linuxInfo.name;
152
- const release = linuxInfo.version || os_1.default.release();
153
- const majorVersion = parseInt(linuxInfo.version || '', 10) || semver_1.default.major(release);
154
- if (logsOpt) {
155
- this.log(`OS type: ${linuxDistro || type}\nOS arch: ${arch}\nOS release: ${release}\nOS major version: ${majorVersion}\nCPU model: ${cpuCore.model}`);
156
- }
157
- if (arch === 'x64' || isAppleSilicon) {
158
- if (semver_1.default.gt(matchstickVersion, '0.5.4')) {
159
- if (type === 'Darwin') {
160
- if (isAppleSilicon) {
161
- return 'binary-macos-12-m1';
162
- }
163
- return 'binary-macos-12';
164
- }
165
- if (type === 'Linux' && majorVersion === 22) {
166
- return 'binary-linux-22';
167
- }
168
- }
169
- else {
170
- if (type === 'Darwin') {
171
- if (majorVersion === 18 || majorVersion === 19) {
172
- return 'binary-macos-10.15';
173
- }
174
- if (isAppleSilicon) {
175
- return 'binary-macos-11-m1';
176
- }
177
- return 'binary-macos-11';
178
- }
179
- if (type === 'Linux') {
180
- return majorVersion === 18
181
- ? 'binary-linux-18'
182
- : majorVersion === 22
183
- ? 'binary-linux-22'
184
- : 'binary-linux-20';
185
- }
186
- }
187
- }
188
- throw new Error(`Unsupported platform: ${type} ${arch} ${majorVersion}`);
189
- }
190
- async function getLinuxInfo() {
191
97
  try {
192
- const result = await gluegun_1.system.run("cat /etc/*-release | grep -E '(^VERSION|^NAME)='", {
193
- trim: true,
194
- });
195
- const infoArray = result
196
- .replace(/['"]+/g, '')
197
- .split('\n')
198
- .map(p => p.split('='));
199
- const linuxInfo = {};
200
- for (const val of infoArray) {
201
- linuxInfo[val[0].toLowerCase()] = val[1];
202
- }
203
- return linuxInfo;
204
- }
205
- catch (error) {
206
- this.error(`Error fetching the Linux version:\n${error}`, { exit: 1 });
207
- }
208
- }
209
- async function runDocker(datasource, opts) {
210
- const coverageOpt = opts.coverage;
211
- const forceOpt = opts.force;
212
- const versionOpt = opts.version;
213
- const latestVersion = opts.latestVersion;
214
- const recompileOpt = opts.recompile;
215
- // Remove binary-install-raw binaries, because docker has permission issues
216
- // when building the docker images
217
- gluegun_1.filesystem.remove('./node_modules/binary-install-raw/bin');
218
- // Get current working directory
219
- const current_folder = gluegun_1.filesystem.cwd();
220
- // Declate dockerfilePath with default location
221
- const dockerfilePath = path_1.default.join(opts.testsDir, '.docker/Dockerfile');
222
- // Check if the Dockerfil already exists
223
- const dockerfileExists = gluegun_1.filesystem.exists(dockerfilePath);
224
- // Generate the Dockerfile only if it doesn't exists,
225
- // version flag and/or force flag is passed.
226
- if (!dockerfileExists || versionOpt || forceOpt) {
227
- await dockerfile.bind(this)(dockerfilePath, versionOpt, latestVersion);
228
- }
229
- // Run a command to check if matchstick image already exists
230
- (0, child_process_1.exec)('docker images -q matchstick', (_error, stdout, _stderr) => {
231
- // Collect all(if any) flags and options that have to be passed to the matchstick binary
232
- let testArgs = '';
233
- if (coverageOpt)
234
- testArgs = testArgs + ' -c';
235
- if (recompileOpt)
236
- testArgs = testArgs + ' -r';
237
- if (datasource)
238
- testArgs = testArgs + ' ' + datasource;
239
- // Build the `docker run` command options and flags
240
- const dockerRunOpts = [
241
- 'run',
242
- '-it',
243
- '--rm',
244
- '--mount',
245
- `type=bind,source=${current_folder},target=/matchstick`,
246
- ];
247
- if (testArgs !== '') {
248
- dockerRunOpts.push('-e');
249
- dockerRunOpts.push(`ARGS=${testArgs.trim()}`);
250
- }
251
- dockerRunOpts.push('matchstick');
252
- // If a matchstick image does not exists, the command returns an empty string,
253
- // else it'll return the image ID. Skip `docker build` if an image already exists
254
- // Delete current image(if any) and rebuild.
255
- // Use spawn() and {stdio: 'inherit'} so we can see the logs in real time.
256
- if (!dockerfileExists || stdout === '' || versionOpt || forceOpt) {
257
- if (stdout !== '') {
258
- (0, child_process_1.exec)('docker image rm matchstick', (_error, stdout, _stderr) => {
259
- this.log(`Remove matchstick image result:\n${stdout}`);
260
- });
261
- }
262
- // Build a docker image. If the process has executed successfully
263
- // run a container from that image.
264
- (0, child_process_1.spawn)('docker', ['build', '-f', dockerfilePath, '-t', 'matchstick', '.'], {
265
- stdio: 'inherit',
266
- }).on('close', code => {
267
- if (code === 0) {
268
- (0, child_process_1.spawn)('docker', dockerRunOpts, { stdio: 'inherit' });
269
- }
270
- });
271
- }
272
- else {
273
- this.log('Docker image already exists. Skipping `docker build` command...');
274
- // Run the container from the existing matchstick docker image
275
- (0, child_process_1.spawn)('docker', dockerRunOpts, { stdio: 'inherit' });
276
- }
277
- });
278
- }
279
- // Downloads Dockerfile template from the demo-subgraph repo
280
- // Replaces the placeholders with their respective values
281
- async function dockerfile(dockerfilePath, versionOpt, latestVersion) {
282
- const spinner = gluegun_1.print.spin('Generating Dockerfile...');
283
- try {
284
- // Fetch the Dockerfile template content from the demo-subgraph repo
285
- const content = await (0, fetch_1.default)('https://raw.githubusercontent.com/LimeChain/demo-subgraph/main/Dockerfile').then(response => {
286
- if (response.ok) {
287
- return response.text();
288
- }
289
- throw new Error(`Status Code: ${response.status}, with error: ${response.statusText}`);
290
- });
291
- // Write the Dockerfile
292
- gluegun_1.filesystem.write(dockerfilePath, content);
293
- // Replaces the version placeholders
294
- await gluegun_1.patching.replace(dockerfilePath, '<MATCHSTICK_VERSION>', versionOpt || latestVersion || 'unknown');
98
+ // Call the N-API function
99
+ (0, testing_1.runTests)(args);
295
100
  }
296
101
  catch (error) {
297
- this.error(`A problem occurred while generating the Dockerfile:\n${error.message}`, {
102
+ this.error(`Error running tests:\n${error.message}`, {
298
103
  exit: 1,
299
104
  });
300
105
  }
301
- spinner.succeed('Successfully generated Dockerfile.');
302
106
  }
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.77.0",
2
+ "version": "0.78.1-alpha-20240716210753-d878dfa",
3
3
  "commands": {
4
4
  "add": {
5
5
  "id": "add",
@@ -880,18 +880,11 @@
880
880
  "summary": "Run the tests in coverage mode.",
881
881
  "allowNo": false
882
882
  },
883
- "docker": {
884
- "name": "docker",
885
- "type": "boolean",
886
- "char": "d",
887
- "summary": "Run the tests in a docker container (Note: Please execute from the root folder of the subgraph).",
888
- "allowNo": false
889
- },
890
883
  "force": {
891
884
  "name": "force",
892
885
  "type": "boolean",
893
886
  "char": "f",
894
- "summary": "Binary - overwrites folder + file when downloading. Docker - rebuilds the docker image.",
887
+ "summary": "Binary - overwrites folder + file when downloading.",
895
888
  "allowNo": false
896
889
  },
897
890
  "logs": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphprotocol/graph-cli",
3
- "version": "0.77.0",
3
+ "version": "0.78.1-alpha-20240716210753-d878dfa",
4
4
  "description": "CLI for building for and deploying to The Graph",
5
5
  "license": "(Apache-2.0 OR MIT)",
6
6
  "engines": {
@@ -46,7 +46,8 @@
46
46
  "tmp-promise": "3.0.3",
47
47
  "web3-eth-abi": "1.7.0",
48
48
  "which": "2.0.2",
49
- "yaml": "1.10.2"
49
+ "yaml": "1.10.2",
50
+ "@graphprotocol/graph-tooling-napi-utils": "0.0.1"
50
51
  },
51
52
  "devDependencies": {
52
53
  "@types/debug": "^4.1.7",