@graphprotocol/graph-cli 0.49.0-alpha-20230503100511-80612fa → 0.49.0-alpha-20230504000723-2c6e265

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.49.0-alpha-20230503100511-80612fa
3
+ ## 0.49.0-alpha-20230504000723-2c6e265
4
4
 
5
5
  ### Minor Changes
6
6
 
@@ -39,12 +39,10 @@ const scaffold_1 = require("../command-helpers/scaffold");
39
39
  const spinner_1 = require("../command-helpers/spinner");
40
40
  const studio_1 = require("../command-helpers/studio");
41
41
  const subgraph_1 = require("../command-helpers/subgraph");
42
- const debug_1 = __importDefault(require("../debug"));
43
42
  const protocols_1 = __importDefault(require("../protocols"));
44
43
  const schema_1 = require("../scaffold/schema");
45
44
  const validation_1 = require("../validation");
46
45
  const add_1 = __importDefault(require("./add"));
47
- const initDebug = (0, debug_1.default)('graph-cli:init');
48
46
  const protocolChoices = Array.from(protocols_1.default.availableProtocols().keys());
49
47
  const availableNetworks = protocols_1.default.availableNetworks();
50
48
  const DEFAULT_EXAMPLE_SUBGRAPH = 'ethereum/gravatar';
@@ -265,227 +263,222 @@ InitCommand.flags = {
265
263
  }),
266
264
  };
267
265
  exports.default = InitCommand;
268
- async function processInitForm({ protocol, product, studio, node, abi, allowSimpleName, directory, contract, indexEvents, fromExample, network, subgraphName, contractName, startBlock, }) {
266
+ async function processInitForm({ protocol: initProtocol, product: initProduct, studio: initStudio, node: initNode, abi: initAbi, directory: initDirectory, contract: initContract, indexEvents: initIndexEvents, fromExample: initFromExample, network: initNetwork, subgraphName: initSubgraphName, contractName: initContractName, startBlock: initStartBlock, allowSimpleName: initAllowSimpleName, }) {
269
267
  let abiFromEtherscan = undefined;
270
- let abiFromFile = undefined;
271
- let protocolInstance;
272
- let ProtocolContract;
273
- let ABI;
274
- const questions = [
275
- {
268
+ try {
269
+ const { protocol } = await gluegun_1.prompt.ask({
276
270
  type: 'select',
277
271
  name: 'protocol',
278
272
  message: 'Protocol',
279
273
  choices: protocolChoices,
280
- skip: protocolChoices.includes(String(protocol)),
281
- result: (value) => {
282
- // eslint-disable-next-line -- prettier has problems with ||=
283
- protocol = protocol || value;
284
- protocolInstance = new protocols_1.default(protocol);
285
- return protocol;
286
- },
287
- },
288
- {
289
- type: 'select',
290
- name: 'product',
291
- message: 'Product for which to initialize',
292
- choices: ['subgraph-studio', 'hosted-service'],
293
- skip: () => protocol === 'arweave' ||
294
- protocol === 'cosmos' ||
295
- protocol === 'near' ||
296
- product === 'subgraph-studio' ||
297
- product === 'hosted-service' ||
298
- studio !== undefined ||
299
- node !== undefined,
300
- result: (value) => {
301
- // For now we only support NEAR subgraphs in the Hosted Service
302
- if (protocol === 'near') {
303
- // Can be overwritten because the question will be skipped (product === undefined)
304
- product = 'hosted-service';
305
- return product;
306
- }
307
- if (value == 'subgraph-studio') {
308
- allowSimpleName = true;
309
- }
310
- product = value;
311
- return value;
274
+ skip: protocolChoices.includes(String(initProtocol)),
275
+ });
276
+ const protocolInstance = new protocols_1.default(protocol);
277
+ const { product } = await gluegun_1.prompt.ask([
278
+ {
279
+ type: 'select',
280
+ name: 'product',
281
+ message: 'Product for which to initialize',
282
+ choices: ['subgraph-studio', 'hosted-service'],
283
+ skip: protocol === 'arweave' ||
284
+ protocol === 'cosmos' ||
285
+ protocol === 'near' ||
286
+ initProduct === 'subgraph-studio' ||
287
+ initProduct === 'hosted-service' ||
288
+ initStudio !== undefined ||
289
+ initNode !== undefined,
290
+ result: value => {
291
+ if (initProduct)
292
+ return initProduct;
293
+ if (initStudio)
294
+ return 'subgraph-studio';
295
+ // For now we only support NEAR subgraphs in the Hosted Service
296
+ if (protocol === 'near') {
297
+ return 'hosted-service';
298
+ }
299
+ if (value == 'subgraph-studio') {
300
+ initAllowSimpleName = true;
301
+ }
302
+ return value;
303
+ },
312
304
  },
313
- },
314
- {
315
- type: 'input',
316
- name: 'subgraphName',
317
- message: () => (product == 'subgraph-studio' || studio ? 'Subgraph slug' : 'Subgraph name'),
318
- initial: subgraphName,
319
- validate: (name) => {
320
- try {
321
- (0, subgraph_1.validateSubgraphName)(name, { allowSimpleName });
322
- return true;
323
- }
324
- catch (e) {
325
- return `${e.message}
305
+ ]);
306
+ const { subgraphName } = await gluegun_1.prompt.ask([
307
+ {
308
+ type: 'input',
309
+ name: 'subgraphName',
310
+ message: () => (product == 'subgraph-studio' ? 'Subgraph slug' : 'Subgraph name'),
311
+ initial: initSubgraphName,
312
+ validate: name => {
313
+ try {
314
+ (0, subgraph_1.validateSubgraphName)(name, { allowSimpleName: initAllowSimpleName });
315
+ return true;
316
+ }
317
+ catch (e) {
318
+ return `${e.message}
326
319
 
327
- Examples:
320
+ Examples:
328
321
 
329
- $ graph init ${os_1.default.userInfo().username}/${name}
330
- $ graph init ${name} --allow-simple-name`;
331
- }
322
+ $ graph init ${os_1.default.userInfo().username}/${name}
323
+ $ graph init ${name} --allow-simple-name`;
324
+ }
325
+ },
332
326
  },
333
- result: (value) => {
334
- subgraphName = value;
335
- return value;
327
+ ]);
328
+ const { directory } = await gluegun_1.prompt.ask([
329
+ {
330
+ type: 'input',
331
+ name: 'directory',
332
+ message: 'Directory to create the subgraph in',
333
+ initial: () => initDirectory || (0, subgraph_1.getSubgraphBasename)(subgraphName),
334
+ validate: value => gluegun_1.filesystem.exists(value || initDirectory || (0, subgraph_1.getSubgraphBasename)(subgraphName))
335
+ ? 'Directory already exists'
336
+ : true,
336
337
  },
337
- },
338
- {
339
- type: 'input',
340
- name: 'directory',
341
- message: 'Directory to create the subgraph in',
342
- initial: () => directory ||
343
- (0, subgraph_1.getSubgraphBasename)(
344
- // @ts-expect-error will be set by previous question
345
- subgraphName),
346
- validate: (value) => gluegun_1.filesystem.exists(value ||
347
- directory ||
348
- (0, subgraph_1.getSubgraphBasename)(
349
- // @ts-expect-error will be set by previous question
350
- subgraphName))
351
- ? 'Directory already exists'
352
- : true,
353
- },
354
- {
355
- type: 'select',
356
- name: 'network',
357
- message: () => `${protocolInstance.displayName()} network`,
358
- choices: () => {
359
- initDebug('Generating list of available networks for protocol "%s" (%M)', protocol, availableNetworks.get(protocol));
360
- return (
361
- // @ts-expect-error TODO: wait what?
362
- availableNetworks
338
+ ]);
339
+ const { network } = await gluegun_1.prompt.ask([
340
+ {
341
+ type: 'select',
342
+ name: 'network',
343
+ message: () => `${protocolInstance.displayName()} network`,
344
+ choices: availableNetworks
363
345
  .get(protocol) // Get networks related to the chosen protocol.
364
- .toArray()); // Needed because of gluegun. It can't even receive a JS iterable.
365
- },
366
- skip: fromExample !== undefined,
367
- initial: network || 'mainnet',
368
- result: (value) => {
369
- network = value;
370
- return value;
371
- },
372
- },
373
- // TODO:
374
- //
375
- // protocols that don't support contract
376
- // - arweave
377
- // - cosmos
378
- {
379
- type: 'input',
380
- name: 'contract',
381
- message: () => {
382
- ProtocolContract = protocolInstance.getContract();
383
- return `Contract ${ProtocolContract.identifierName()}`;
384
- },
385
- skip: () => fromExample !== undefined || !protocolInstance.hasContract(),
386
- initial: contract,
387
- validate: async (value) => {
388
- if (fromExample !== undefined || !protocolInstance.hasContract()) {
389
- return true;
390
- }
391
- // Validate whether the contract is valid
392
- const { valid, error } = (0, validation_1.validateContract)(value, ProtocolContract);
393
- return valid ? true : error;
394
- },
395
- result: async (value) => {
396
- if (fromExample !== undefined) {
346
+ ?.toArray() || ['mainnet'],
347
+ skip: initFromExample !== undefined,
348
+ result: value => {
349
+ if (initNetwork)
350
+ return initNetwork;
397
351
  return value;
398
- }
399
- ABI = protocolInstance.getABI();
400
- // Try loading the ABI from Etherscan, if none was provided
401
- if (protocolInstance.hasABIs() && !abi) {
402
- try {
403
- if (network === 'poa-core') {
404
- // TODO: this variable is never used anywhere, what happens?
405
- // abiFromBlockScout = await loadAbiFromBlockScout(ABI, network, value)
352
+ },
353
+ },
354
+ ]);
355
+ const { contract } = await gluegun_1.prompt.ask([
356
+ // TODO:
357
+ // protocols that don't support contract
358
+ // - arweave
359
+ // - cosmos
360
+ {
361
+ type: 'input',
362
+ name: 'contract',
363
+ message: `Contract ${protocolInstance.getContract()?.identifierName()}`,
364
+ skip: () => initFromExample !== undefined || !protocolInstance.hasContract(),
365
+ initial: initContract,
366
+ validate: async (value) => {
367
+ if (initFromExample !== undefined || !protocolInstance.hasContract()) {
368
+ return true;
369
+ }
370
+ const protocolContract = protocolInstance.getContract();
371
+ if (!protocolContract) {
372
+ return 'Contract not found.';
373
+ }
374
+ // Validate whether the contract is valid
375
+ const { valid, error } = (0, validation_1.validateContract)(value, protocolContract);
376
+ return valid ? true : error;
377
+ },
378
+ result: async (value) => {
379
+ if (initFromExample !== undefined) {
380
+ return value;
381
+ }
382
+ const ABI = protocolInstance.getABI();
383
+ // Try loading the ABI from Etherscan, if none was provided
384
+ if (protocolInstance.hasABIs() && !initAbi) {
385
+ try {
386
+ if (network === 'poa-core') {
387
+ // TODO: this variable is never used anywhere, what happens?
388
+ // abiFromBlockScout = await loadAbiFromBlockScout(ABI, network, value)
389
+ }
390
+ else {
391
+ abiFromEtherscan = await (0, abi_1.loadAbiFromEtherscan)(ABI, network, value);
392
+ }
406
393
  }
407
- else {
408
- abiFromEtherscan = await (0, abi_1.loadAbiFromEtherscan)(ABI, network, value);
394
+ catch (e) {
395
+ // noop
409
396
  }
410
397
  }
411
- catch (e) {
412
- // noop
398
+ // If startBlock is not set, try to load it.
399
+ if (!initStartBlock) {
400
+ try {
401
+ // Load startBlock for this contract
402
+ initStartBlock = Number(await (0, abi_1.loadStartBlockForContract)(network, value)).toString();
403
+ }
404
+ catch (error) {
405
+ // noop
406
+ }
413
407
  }
414
- }
415
- // If startBlock is not set, try to load it.
416
- if (!startBlock) {
408
+ return value;
409
+ },
410
+ },
411
+ ]);
412
+ const { abi: abiFromFile } = await gluegun_1.prompt.ask([
413
+ {
414
+ type: 'input',
415
+ name: 'abi',
416
+ message: 'ABI file (path)',
417
+ initial: initAbi,
418
+ skip: () => !protocolInstance.hasABIs() ||
419
+ initFromExample !== undefined ||
420
+ abiFromEtherscan !== undefined,
421
+ validate: async (value) => {
422
+ if (initFromExample || abiFromEtherscan || !protocolInstance.hasABIs()) {
423
+ return true;
424
+ }
425
+ const ABI = protocolInstance.getABI();
417
426
  try {
418
- // Load startBlock for this contract
419
- startBlock = Number(await (0, abi_1.loadStartBlockForContract)(network, value)).toString();
427
+ return loadAbiFromFile(ABI, value);
420
428
  }
421
- catch (error) {
422
- // noop
429
+ catch (e) {
430
+ return e.message;
423
431
  }
424
- }
425
- return value;
426
- },
427
- },
428
- {
429
- type: 'input',
430
- name: 'abi',
431
- message: 'ABI file (path)',
432
- initial: abi,
433
- skip: () => !protocolInstance.hasABIs() || fromExample !== undefined || abiFromEtherscan !== undefined,
434
- validate: async (value) => {
435
- if (fromExample || abiFromEtherscan || !protocolInstance.hasABIs()) {
436
- return true;
437
- }
438
- try {
439
- abiFromFile = loadAbiFromFile(ABI, value);
440
- return true;
441
- }
442
- catch (e) {
443
- return e.message;
444
- }
432
+ },
445
433
  },
446
- },
447
- {
448
- type: 'input',
449
- name: 'startBlock',
450
- message: 'Start Block',
451
- initial: () => startBlock || '0',
452
- skip: () => fromExample !== undefined,
453
- validate: (value) => parseInt(value) >= 0,
454
- result: (value) => {
455
- startBlock = value;
456
- return value;
434
+ ]);
435
+ const { startBlock } = await gluegun_1.prompt.ask([
436
+ {
437
+ type: 'input',
438
+ name: 'startBlock',
439
+ message: 'Start Block',
440
+ initial: initStartBlock || '0',
441
+ skip: () => initFromExample !== undefined,
442
+ validate: value => parseInt(value) >= 0,
443
+ result(value) {
444
+ if (initStartBlock)
445
+ return initStartBlock;
446
+ return value;
447
+ },
457
448
  },
458
- },
459
- {
460
- type: 'input',
461
- name: 'contractName',
462
- message: 'Contract Name',
463
- initial: contractName || 'Contract',
464
- skip: () => fromExample !== undefined || !protocolInstance.hasContract(),
465
- validate: (value) => value && value.length > 0,
466
- result: (value) => {
467
- contractName = value;
468
- return value;
449
+ ]);
450
+ const { contractName } = await gluegun_1.prompt.ask([
451
+ {
452
+ type: 'input',
453
+ name: 'contractName',
454
+ message: 'Contract Name',
455
+ initial: initContractName || 'Contract',
456
+ skip: () => initFromExample !== undefined || !protocolInstance.hasContract(),
457
+ validate: value => value && value.length > 0,
469
458
  },
470
- },
471
- {
472
- type: 'confirm',
473
- name: 'indexEvents',
474
- message: 'Index contract events as entities',
475
- initial: true,
476
- skip: () => !!indexEvents,
477
- result: (value) => {
478
- indexEvents = value;
479
- return value;
459
+ ]);
460
+ const { indexEvents } = await gluegun_1.prompt.ask([
461
+ {
462
+ type: 'confirm',
463
+ name: 'indexEvents',
464
+ message: 'Index contract events as entities',
465
+ initial: true,
466
+ skip: () => !!initIndexEvents,
480
467
  },
481
- },
482
- ];
483
- try {
484
- const answers = await gluegun_1.prompt.ask(questions);
468
+ ]);
485
469
  return {
486
- ...answers,
487
470
  abi: abiFromEtherscan || abiFromFile,
488
471
  protocolInstance,
472
+ subgraphName,
473
+ directory,
474
+ studio: product === 'subgraph-studio',
475
+ startBlock,
476
+ fromExample: !!initFromExample,
477
+ product,
478
+ network,
479
+ contractName,
480
+ contract,
481
+ indexEvents,
489
482
  };
490
483
  }
491
484
  catch (e) {
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.49.0-alpha-20230503100511-80612fa",
2
+ "version": "0.49.0-alpha-20230504000723-2c6e265",
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.49.0-alpha-20230503100511-80612fa",
3
+ "version": "0.49.0-alpha-20230504000723-2c6e265",
4
4
  "description": "CLI for building for and deploying to The Graph",
5
5
  "license": "(Apache-2.0 OR MIT)",
6
6
  "engines": {
@@ -31,7 +31,7 @@
31
31
  "dockerode": "2.5.8",
32
32
  "fs-extra": "9.1.0",
33
33
  "glob": "9.3.5",
34
- "gluegun": "https://github.com/edgeandnode/gluegun#v4.3.1-pin-colors-dep",
34
+ "gluegun": "5.1.2",
35
35
  "graphql": "15.5.0",
36
36
  "immutable": "4.2.1",
37
37
  "ipfs-http-client": "55.0.0",