@graphprotocol/graph-cli 0.49.1-alpha-20230510040157-fe90ff7 → 0.50.0-alpha-20230511200812-4eb8560

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,9 +1,53 @@
1
1
  # @graphprotocol/graph-cli
2
2
 
3
- ## 0.49.1-alpha-20230510040157-fe90ff7
3
+ ## 0.50.0-alpha-20230511200812-4eb8560
4
+
5
+ ### Minor Changes
6
+
7
+ - [#1335](https://github.com/graphprotocol/graph-tooling/pull/1335)
8
+ [`7343f50`](https://github.com/graphprotocol/graph-tooling/commit/7343f50c0e2b767de04909e6020b88fea97ae3cd)
9
+ Thanks [@saihaj](https://github.com/saihaj)! - For substreams generate the directory tree as
10
+ follows
11
+
12
+ ```
13
+ .
14
+ ├── package.json
15
+ ├── schema.graphql
16
+ └── subgraph.yaml
17
+ ```
18
+
19
+ In the `package.json` we only depend on the CLI since that is what developer will use to deploy
20
+ the subgraph. The `schema.graphql` is the schema of the subgraph and the `subgraph.yaml` is the
21
+ manifest file for the subgraph.
22
+
23
+ - [#1335](https://github.com/graphprotocol/graph-tooling/pull/1335)
24
+ [`7343f50`](https://github.com/graphprotocol/graph-tooling/commit/7343f50c0e2b767de04909e6020b88fea97ae3cd)
25
+ Thanks [@saihaj](https://github.com/saihaj)! - respect --abi flag instead of loading from
26
+ etherscan
27
+
28
+ - [#1335](https://github.com/graphprotocol/graph-tooling/pull/1335)
29
+ [`7343f50`](https://github.com/graphprotocol/graph-tooling/commit/7343f50c0e2b767de04909e6020b88fea97ae3cd)
30
+ Thanks [@saihaj](https://github.com/saihaj)! - remove index events as entities for substreams
31
+
32
+ - [#1335](https://github.com/graphprotocol/graph-tooling/pull/1335)
33
+ [`7343f50`](https://github.com/graphprotocol/graph-tooling/commit/7343f50c0e2b767de04909e6020b88fea97ae3cd)
34
+ Thanks [@saihaj](https://github.com/saihaj)! - remove start block selection for substreams
35
+
36
+ - [#1343](https://github.com/graphprotocol/graph-tooling/pull/1343)
37
+ [`032d703`](https://github.com/graphprotocol/graph-tooling/commit/032d7039fbfec7505d9c3bbefe43a76a8f2895de)
38
+ Thanks [@saihaj](https://github.com/saihaj)! - add SPK input for substreams protocol
4
39
 
5
40
  ### Patch Changes
6
41
 
42
+ - [#1335](https://github.com/graphprotocol/graph-tooling/pull/1335)
43
+ [`7343f50`](https://github.com/graphprotocol/graph-tooling/commit/7343f50c0e2b767de04909e6020b88fea97ae3cd)
44
+ Thanks [@saihaj](https://github.com/saihaj)! - dependencies updates:
45
+
46
+ - Updated dependency [`@oclif/core@2.8.4` ↗︎](https://www.npmjs.com/package/@oclif/core/v/2.8.4)
47
+ (from `2.8.2`, in `dependencies`)
48
+ - Updated dependency [`gluegun@5.1.2` ↗︎](https://www.npmjs.com/package/gluegun/v/5.1.2) (from
49
+ `https://github.com/edgeandnode/gluegun#v4.3.1-pin-colors-dep`, in `dependencies`)
50
+
7
51
  - [#1329](https://github.com/graphprotocol/graph-tooling/pull/1329)
8
52
  [`7309799`](https://github.com/graphprotocol/graph-tooling/commit/73097990312d41c290edafc375610d6497c39710)
9
53
  Thanks [@saihaj](https://github.com/saihaj)! - Point to new examples repo instead of old
@@ -3,7 +3,7 @@ import Protocol from '../protocols';
3
3
  import ABI from '../protocols/ethereum/abi';
4
4
  import { Spinner } from './spinner';
5
5
  export declare const generateDataSource: (protocol: Protocol, contractName: string, network: string, contractAddress: string, abi: ABI, startBlock?: string) => Promise<Map<unknown, unknown>>;
6
- export declare const generateScaffold: ({ protocolInstance, abi, contract, network, subgraphName, indexEvents, contractName, startBlock, node, }: {
6
+ export declare const generateScaffold: ({ protocolInstance, abi, contract, network, subgraphName, indexEvents, contractName, startBlock, node, spkgPath, }: {
7
7
  protocolInstance: Protocol;
8
8
  abi: ABI;
9
9
  contract: string;
@@ -13,7 +13,16 @@ export declare const generateScaffold: ({ protocolInstance, abi, contract, netwo
13
13
  contractName?: string | undefined;
14
14
  startBlock?: string | undefined;
15
15
  node?: string | undefined;
16
+ spkgPath?: string | undefined;
16
17
  }, spinner: Spinner) => Promise<{
18
+ 'subgraph.yaml': string;
19
+ 'schema.graphql': string;
20
+ 'package.json': string;
21
+ 'tsconfig.json'?: undefined;
22
+ src?: undefined;
23
+ abis?: undefined;
24
+ tests?: undefined;
25
+ } | {
17
26
  'package.json': string;
18
27
  'subgraph.yaml': string;
19
28
  'schema.graphql': string;
@@ -24,7 +24,7 @@ const generateDataSource = async (protocol, contractName, network, contractAddre
24
24
  }))).asMutable();
25
25
  };
26
26
  exports.generateDataSource = generateDataSource;
27
- const generateScaffold = async ({ protocolInstance, abi, contract, network, subgraphName, indexEvents, contractName = 'Contract', startBlock, node, }, spinner) => {
27
+ const generateScaffold = async ({ protocolInstance, abi, contract, network, subgraphName, indexEvents, contractName = 'Contract', startBlock, node, spkgPath, }, spinner) => {
28
28
  (0, spinner_1.step)(spinner, 'Generate subgraph');
29
29
  const scaffold = new scaffold_1.default({
30
30
  protocol: protocolInstance,
@@ -36,6 +36,7 @@ const generateScaffold = async ({ protocolInstance, abi, contract, network, subg
36
36
  startBlock,
37
37
  subgraphName,
38
38
  node,
39
+ spkgPath,
39
40
  });
40
41
  return scaffold.generate();
41
42
  };
@@ -18,6 +18,7 @@ export default class InitCommand extends Command {
18
18
  'index-events': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
19
19
  'start-block': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
20
20
  abi: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
21
+ spkg: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
21
22
  network: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
22
23
  };
23
24
  run(): Promise<void>;
@@ -39,18 +39,16 @@ 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';
51
49
  class InitCommand extends core_1.Command {
52
50
  async run() {
53
- const { args: { subgraphName, directory }, flags: { protocol, product, studio, node: nodeFlag, 'allow-simple-name': allowSimpleNameFlag, 'from-contract': fromContract, 'contract-name': contractName, 'from-example': fromExample, 'index-events': indexEvents, network, abi: abiPath, 'start-block': startBlock, }, } = await this.parse(InitCommand);
51
+ const { args: { subgraphName, directory }, flags: { protocol, product, studio, node: nodeFlag, 'allow-simple-name': allowSimpleNameFlag, 'from-contract': fromContract, 'contract-name': contractName, 'from-example': fromExample, 'index-events': indexEvents, network, abi: abiPath, 'start-block': startBlock, spkg: spkgPath, }, } = await this.parse(InitCommand);
54
52
  let { node, allowSimpleName } = (0, node_1.chooseNodeUrl)({
55
53
  product,
56
54
  studio,
@@ -85,8 +83,18 @@ class InitCommand extends core_1.Command {
85
83
  };
86
84
  // If all parameters are provided from the command-line,
87
85
  // go straight to creating the subgraph from the example
88
- if (fromExample && subgraphName && directory) {
89
- return await initSubgraphFromExample.bind(this)({ fromExample, allowSimpleName, directory, subgraphName, studio, product }, { commands });
86
+ if (fromExample && subgraphName && directory && protocol) {
87
+ await initSubgraphFromExample.bind(this)({
88
+ fromExample,
89
+ allowSimpleName,
90
+ directory,
91
+ subgraphName,
92
+ studio,
93
+ product,
94
+ protocolInstance: new protocols_1.default(protocol),
95
+ }, { commands });
96
+ // Exit with success
97
+ return this.exit(0);
90
98
  }
91
99
  // Will be assigned below if ethereum
92
100
  let abi;
@@ -122,7 +130,7 @@ class InitCommand extends core_1.Command {
122
130
  }
123
131
  }
124
132
  }
125
- return await initSubgraphFromContract.bind(this)({
133
+ await initSubgraphFromContract.bind(this)({
126
134
  protocolInstance,
127
135
  abi,
128
136
  allowSimpleName,
@@ -136,7 +144,10 @@ class InitCommand extends core_1.Command {
136
144
  studio,
137
145
  product,
138
146
  startBlock,
147
+ spkgPath,
139
148
  }, { commands, addContract: false });
149
+ // Exit with success
150
+ return this.exit(0);
140
151
  }
141
152
  // Otherwise, take the user through the interactive form
142
153
  const answers = await processInitForm.bind(this)({
@@ -145,6 +156,7 @@ class InitCommand extends core_1.Command {
145
156
  studio,
146
157
  node,
147
158
  abi,
159
+ abiPath,
148
160
  allowSimpleName,
149
161
  directory,
150
162
  contract: fromContract,
@@ -154,6 +166,7 @@ class InitCommand extends core_1.Command {
154
166
  subgraphName,
155
167
  contractName,
156
168
  startBlock,
169
+ spkgPath,
157
170
  });
158
171
  if (!answers) {
159
172
  this.exit(1);
@@ -166,6 +179,7 @@ class InitCommand extends core_1.Command {
166
179
  directory: answers.directory,
167
180
  studio: answers.studio,
168
181
  product: answers.product,
182
+ protocolInstance: answers.protocolInstance,
169
183
  }, { commands });
170
184
  }
171
185
  else {
@@ -189,8 +203,11 @@ class InitCommand extends core_1.Command {
189
203
  studio: answers.studio,
190
204
  product: answers.product,
191
205
  startBlock: answers.startBlock,
206
+ spkgPath: answers.spkgPath,
192
207
  }, { commands, addContract: true });
193
208
  }
209
+ // Exit with success
210
+ this.exit(0);
194
211
  }
195
212
  }
196
213
  InitCommand.description = 'Creates a new subgraph with basic scaffolding.';
@@ -254,6 +271,9 @@ InitCommand.flags = {
254
271
  // default: '*Download from Etherscan*',
255
272
  dependsOn: ['from-contract'],
256
273
  }),
274
+ spkg: core_1.Flags.string({
275
+ summary: 'Path to the SPKG file',
276
+ }),
257
277
  network: core_1.Flags.string({
258
278
  summary: 'Network the contract is deployed to.',
259
279
  dependsOn: ['from-contract'],
@@ -265,227 +285,266 @@ InitCommand.flags = {
265
285
  }),
266
286
  };
267
287
  exports.default = InitCommand;
268
- async function processInitForm({ protocol, product, studio, node, abi, allowSimpleName, directory, contract, indexEvents, fromExample, network, subgraphName, contractName, startBlock, }) {
288
+ async function processInitForm({ protocol: initProtocol, product: initProduct, studio: initStudio, node: initNode, abi: initAbi, abiPath: initAbiPath, directory: initDirectory, contract: initContract, indexEvents: initIndexEvents, fromExample: initFromExample, network: initNetwork, subgraphName: initSubgraphName, contractName: initContractName, startBlock: initStartBlock, allowSimpleName: initAllowSimpleName, spkgPath: initSpkgPath, }) {
269
289
  let abiFromEtherscan = undefined;
270
- let abiFromFile = undefined;
271
- let protocolInstance;
272
- let ProtocolContract;
273
- let ABI;
274
- const questions = [
275
- {
290
+ try {
291
+ const { protocol } = await gluegun_1.prompt.ask({
276
292
  type: 'select',
277
293
  name: 'protocol',
278
294
  message: 'Protocol',
279
295
  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;
296
+ skip: protocolChoices.includes(String(initProtocol)),
297
+ });
298
+ const protocolInstance = new protocols_1.default(protocol);
299
+ const isSubstreams = protocol === 'substreams';
300
+ const { product } = await gluegun_1.prompt.ask([
301
+ {
302
+ type: 'select',
303
+ name: 'product',
304
+ message: 'Product for which to initialize',
305
+ choices: ['subgraph-studio', 'hosted-service'],
306
+ skip: protocol === 'arweave' ||
307
+ protocol === 'cosmos' ||
308
+ protocol === 'near' ||
309
+ initProduct === 'subgraph-studio' ||
310
+ initProduct === 'hosted-service' ||
311
+ initStudio !== undefined ||
312
+ initNode !== undefined,
313
+ result: value => {
314
+ if (initProduct)
315
+ return initProduct;
316
+ if (initStudio)
317
+ return 'subgraph-studio';
318
+ // For now we only support NEAR subgraphs in the Hosted Service
319
+ if (protocol === 'near') {
320
+ return 'hosted-service';
321
+ }
322
+ if (value == 'subgraph-studio') {
323
+ initAllowSimpleName = true;
324
+ }
325
+ return value;
326
+ },
312
327
  },
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}
328
+ ]);
329
+ const { subgraphName } = await gluegun_1.prompt.ask([
330
+ {
331
+ type: 'input',
332
+ name: 'subgraphName',
333
+ message: () => (product == 'subgraph-studio' ? 'Subgraph slug' : 'Subgraph name'),
334
+ initial: initSubgraphName,
335
+ validate: name => {
336
+ try {
337
+ (0, subgraph_1.validateSubgraphName)(name, { allowSimpleName: initAllowSimpleName });
338
+ return true;
339
+ }
340
+ catch (e) {
341
+ return `${e.message}
326
342
 
327
- Examples:
343
+ Examples:
328
344
 
329
- $ graph init ${os_1.default.userInfo().username}/${name}
330
- $ graph init ${name} --allow-simple-name`;
331
- }
345
+ $ graph init ${os_1.default.userInfo().username}/${name}
346
+ $ graph init ${name} --allow-simple-name`;
347
+ }
348
+ },
332
349
  },
333
- result: (value) => {
334
- subgraphName = value;
335
- return value;
350
+ ]);
351
+ const { directory } = await gluegun_1.prompt.ask([
352
+ {
353
+ type: 'input',
354
+ name: 'directory',
355
+ message: 'Directory to create the subgraph in',
356
+ initial: () => initDirectory || (0, subgraph_1.getSubgraphBasename)(subgraphName),
357
+ validate: value => gluegun_1.filesystem.exists(value || initDirectory || (0, subgraph_1.getSubgraphBasename)(subgraphName))
358
+ ? 'Directory already exists'
359
+ : true,
336
360
  },
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
361
+ ]);
362
+ const { network } = await gluegun_1.prompt.ask([
363
+ {
364
+ type: 'select',
365
+ name: 'network',
366
+ message: () => `${protocolInstance.displayName()} network`,
367
+ choices: availableNetworks
363
368
  .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;
369
+ ?.toArray() || ['mainnet'],
370
+ skip: initFromExample !== undefined,
371
+ result: value => {
372
+ if (initNetwork)
373
+ return initNetwork;
374
+ return value;
375
+ },
371
376
  },
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()}`;
377
+ ]);
378
+ const { contract } = await gluegun_1.prompt.ask([
379
+ // TODO:
380
+ // protocols that don't support contract
381
+ // - arweave
382
+ // - cosmos
383
+ {
384
+ type: 'input',
385
+ name: 'contract',
386
+ message: `Contract ${protocolInstance.getContract()?.identifierName()}`,
387
+ skip: () => initFromExample !== undefined || !protocolInstance.hasContract() || isSubstreams,
388
+ initial: initContract,
389
+ validate: async (value) => {
390
+ if (initFromExample !== undefined || !protocolInstance.hasContract()) {
391
+ return true;
392
+ }
393
+ const protocolContract = protocolInstance.getContract();
394
+ if (!protocolContract) {
395
+ return 'Contract not found.';
396
+ }
397
+ // Validate whether the contract is valid
398
+ const { valid, error } = (0, validation_1.validateContract)(value, protocolContract);
399
+ return valid ? true : error;
400
+ },
401
+ result: async (value) => {
402
+ if (initFromExample !== undefined || isSubstreams || initAbiPath) {
403
+ return value;
404
+ }
405
+ const ABI = protocolInstance.getABI();
406
+ // Try loading the ABI from Etherscan, if none was provided
407
+ if (protocolInstance.hasABIs() && !initAbi) {
408
+ try {
409
+ if (network === 'poa-core') {
410
+ // TODO: this variable is never used anywhere, what happens?
411
+ // abiFromBlockScout = await loadAbiFromBlockScout(ABI, network, value)
412
+ }
413
+ else {
414
+ abiFromEtherscan = await (0, abi_1.loadAbiFromEtherscan)(ABI, network, value);
415
+ }
416
+ }
417
+ catch (e) {
418
+ // noop
419
+ }
420
+ }
421
+ // If startBlock is not set, try to load it.
422
+ if (!initStartBlock) {
423
+ try {
424
+ // Load startBlock for this contract
425
+ initStartBlock = Number(await (0, abi_1.loadStartBlockForContract)(network, value)).toString();
426
+ }
427
+ catch (error) {
428
+ // noop
429
+ }
430
+ }
431
+ return value;
432
+ },
384
433
  },
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;
434
+ ]);
435
+ const { spkg } = await gluegun_1.prompt.ask([
436
+ {
437
+ type: 'input',
438
+ name: 'spkg',
439
+ message: 'SPKG file (path)',
440
+ initial: () => initSpkgPath,
441
+ skip: () => !isSubstreams || !!initSpkgPath,
442
+ validate: value => gluegun_1.filesystem.exists(initSpkgPath || value) ? true : 'SPKG file does not exist',
394
443
  },
395
- result: async (value) => {
396
- if (fromExample !== undefined) {
397
- 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)
444
+ ]);
445
+ const { abi: abiFromFile } = await gluegun_1.prompt.ask([
446
+ {
447
+ type: 'input',
448
+ name: 'abi',
449
+ message: 'ABI file (path)',
450
+ initial: initAbi,
451
+ skip: () => !protocolInstance.hasABIs() ||
452
+ initFromExample !== undefined ||
453
+ abiFromEtherscan !== undefined ||
454
+ isSubstreams ||
455
+ !!initAbiPath,
456
+ validate: async (value) => {
457
+ if (initFromExample || abiFromEtherscan || !protocolInstance.hasABIs()) {
458
+ return true;
459
+ }
460
+ const ABI = protocolInstance.getABI();
461
+ if (initAbiPath) {
462
+ try {
463
+ loadAbiFromFile(ABI, initAbiPath);
464
+ return true;
406
465
  }
407
- else {
408
- abiFromEtherscan = await (0, abi_1.loadAbiFromEtherscan)(ABI, network, value);
466
+ catch (e) {
467
+ this.error(e.message);
409
468
  }
410
469
  }
470
+ try {
471
+ loadAbiFromFile(ABI, value);
472
+ return true;
473
+ }
411
474
  catch (e) {
412
- // noop
475
+ this.error(e.message);
476
+ }
477
+ },
478
+ result: async (value) => {
479
+ if (initFromExample || abiFromEtherscan || !protocolInstance.hasABIs()) {
480
+ return null;
481
+ }
482
+ const ABI = protocolInstance.getABI();
483
+ if (initAbiPath) {
484
+ try {
485
+ return loadAbiFromFile(ABI, initAbiPath);
486
+ }
487
+ catch (e) {
488
+ return e.message;
489
+ }
413
490
  }
414
- }
415
- // If startBlock is not set, try to load it.
416
- if (!startBlock) {
417
491
  try {
418
- // Load startBlock for this contract
419
- startBlock = Number(await (0, abi_1.loadStartBlockForContract)(network, value)).toString();
492
+ return loadAbiFromFile(ABI, value);
420
493
  }
421
- catch (error) {
422
- // noop
494
+ catch (e) {
495
+ return e.message;
423
496
  }
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
- }
497
+ },
445
498
  },
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;
499
+ ]);
500
+ const { startBlock } = await gluegun_1.prompt.ask([
501
+ {
502
+ type: 'input',
503
+ name: 'startBlock',
504
+ message: 'Start Block',
505
+ initial: initStartBlock || '0',
506
+ skip: () => initFromExample !== undefined || isSubstreams,
507
+ validate: value => parseInt(value) >= 0,
508
+ result(value) {
509
+ if (initStartBlock)
510
+ return initStartBlock;
511
+ return value;
512
+ },
457
513
  },
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;
514
+ ]);
515
+ const { contractName } = await gluegun_1.prompt.ask([
516
+ {
517
+ type: 'input',
518
+ name: 'contractName',
519
+ message: 'Contract Name',
520
+ initial: initContractName || 'Contract' || isSubstreams,
521
+ skip: () => initFromExample !== undefined || !protocolInstance.hasContract(),
522
+ validate: value => value && value.length > 0,
469
523
  },
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;
524
+ ]);
525
+ const { indexEvents } = await gluegun_1.prompt.ask([
526
+ {
527
+ type: 'confirm',
528
+ name: 'indexEvents',
529
+ message: 'Index contract events as entities',
530
+ initial: true,
531
+ skip: () => !!initIndexEvents || isSubstreams,
480
532
  },
481
- },
482
- ];
483
- try {
484
- const answers = await gluegun_1.prompt.ask(questions);
533
+ ]);
485
534
  return {
486
- ...answers,
487
535
  abi: abiFromEtherscan || abiFromFile,
488
536
  protocolInstance,
537
+ subgraphName,
538
+ directory,
539
+ studio: product === 'subgraph-studio',
540
+ startBlock,
541
+ fromExample: !!initFromExample,
542
+ product,
543
+ network,
544
+ contractName,
545
+ contract,
546
+ indexEvents,
547
+ spkgPath: spkg,
489
548
  };
490
549
  }
491
550
  catch (e) {
@@ -563,7 +622,8 @@ Subgraph ${subgraphName} created in ${relativeDir}
563
622
 
564
623
  Make sure to visit the documentation on https://thegraph.com/docs/ for further information.`);
565
624
  }
566
- async function initSubgraphFromExample({ fromExample, allowSimpleName, subgraphName, directory, studio, product, }, { commands, }) {
625
+ async function initSubgraphFromExample({ protocolInstance, fromExample, allowSimpleName, subgraphName, directory, studio, product, }, { commands, }) {
626
+ const isSubstreams = protocolInstance.name === 'substreams';
567
627
  // Fail if the subgraph name is invalid
568
628
  if (!revalidateSubgraphName.bind(this)(subgraphName, { allowSimpleName })) {
569
629
  process.exitCode = 1;
@@ -589,7 +649,6 @@ async function initSubgraphFromExample({ fromExample, allowSimpleName, subgraphN
589
649
  fromExample = DEFAULT_EXAMPLE_SUBGRAPH;
590
650
  }
591
651
  const exampleSubgraphPath = path_1.default.join(tmpDir, 'examples', String(fromExample));
592
- console.log('exampleSubgraphPath', exampleSubgraphPath);
593
652
  if (!gluegun_1.filesystem.exists(exampleSubgraphPath)) {
594
653
  return { result: false, error: `Example not found: ${fromExample}` };
595
654
  }
@@ -661,15 +720,18 @@ async function initSubgraphFromExample({ fromExample, allowSimpleName, subgraphN
661
720
  this.exit(1);
662
721
  return;
663
722
  }
664
- // Run code-generation
665
- const codegen = await runCodegen(directory, commands.codegen);
666
- if (codegen !== true) {
667
- this.exit(1);
668
- return;
723
+ if (!isSubstreams) {
724
+ // Run code-generation
725
+ const codegen = await runCodegen(directory, commands.codegen);
726
+ if (codegen !== true) {
727
+ this.exit(1);
728
+ return;
729
+ }
669
730
  }
670
731
  printNextSteps.bind(this)({ subgraphName, directory }, { commands });
671
732
  }
672
- async function initSubgraphFromContract({ protocolInstance, allowSimpleName, subgraphName, directory, abi, network, contract, indexEvents, contractName, node, studio, product, startBlock, }, { commands, addContract, }) {
733
+ async function initSubgraphFromContract({ protocolInstance, allowSimpleName, subgraphName, directory, abi, network, contract, indexEvents, contractName, node, studio, product, startBlock, spkgPath, }, { commands, addContract, }) {
734
+ const isSubstreams = protocolInstance.name === 'substreams';
673
735
  // Fail if the subgraph name is invalid
674
736
  if (!revalidateSubgraphName.bind(this)(subgraphName, { allowSimpleName })) {
675
737
  this.exit(1);
@@ -707,6 +769,7 @@ async function initSubgraphFromContract({ protocolInstance, allowSimpleName, sub
707
769
  contractName,
708
770
  startBlock,
709
771
  node,
772
+ spkgPath,
710
773
  }, spinner);
711
774
  await (0, scaffold_1.writeScaffold)(scaffold, directory, spinner);
712
775
  return true;
@@ -735,14 +798,17 @@ async function initSubgraphFromContract({ protocolInstance, allowSimpleName, sub
735
798
  this.exit(1);
736
799
  return;
737
800
  }
738
- // Run code-generation
739
- const codegen = await runCodegen(directory, commands.codegen);
740
- if (codegen !== true) {
741
- this.exit(1);
742
- return;
743
- }
744
- while (addContract) {
745
- addContract = await addAnotherContract.bind(this)({ protocolInstance, directory });
801
+ // Substreams we have nothing to install or generate
802
+ if (!isSubstreams) {
803
+ // Run code-generation
804
+ const codegen = await runCodegen(directory, commands.codegen);
805
+ if (codegen !== true) {
806
+ this.exit(1);
807
+ return;
808
+ }
809
+ while (addContract) {
810
+ addContract = await addAnotherContract.bind(this)({ protocolInstance, directory });
811
+ }
746
812
  }
747
813
  printNextSteps.bind(this)({ subgraphName, directory }, { commands });
748
814
  }
@@ -1,2 +1,4 @@
1
- export declare const source: () => string;
1
+ export declare const source: ({ spkgPath }: {
2
+ spkgPath?: string | undefined;
3
+ }) => string;
2
4
  export declare const mapping: () => string;
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.mapping = exports.source = void 0;
4
- const source = () => `
4
+ const source = ({ spkgPath }) => `
5
5
  package:
6
6
  moduleName: graph_out
7
- file: substreams-eth-block-meta-v0.1.0.spkg`;
7
+ file: ${spkgPath || 'substreams-eth-block-meta-v0.1.0.spkg'}`;
8
8
  exports.source = source;
9
9
  const mapping = () => `
10
10
  apiVersion: 0.0.5
@@ -10,6 +10,7 @@ export interface ScaffoldOptions {
10
10
  startBlock?: string;
11
11
  subgraphName?: string;
12
12
  node?: string;
13
+ spkgPath?: string;
13
14
  }
14
15
  export default class Scaffold {
15
16
  protocol: Protocol;
@@ -21,8 +22,10 @@ export default class Scaffold {
21
22
  subgraphName?: string;
22
23
  node?: string;
23
24
  startBlock?: string;
25
+ spkgPath?: string;
24
26
  constructor(options: ScaffoldOptions);
25
27
  generatePackageJson(): string;
28
+ generatePackageJsonForSubstreams(): string;
26
29
  generateManifest(): string;
27
30
  generateSchema(): string;
28
31
  generateTsConfig(): string;
@@ -37,6 +40,14 @@ export default class Scaffold {
37
40
  [x: string]: string;
38
41
  } | undefined;
39
42
  generate(): {
43
+ 'subgraph.yaml': string;
44
+ 'schema.graphql': string;
45
+ 'package.json': string;
46
+ 'tsconfig.json'?: undefined;
47
+ src?: undefined;
48
+ abis?: undefined;
49
+ tests?: undefined;
50
+ } | {
40
51
  'package.json': string;
41
52
  'subgraph.yaml': string;
42
53
  'schema.graphql': string;
@@ -27,6 +27,7 @@ class Scaffold {
27
27
  this.subgraphName = options.subgraphName;
28
28
  this.startBlock = options.startBlock;
29
29
  this.node = options.node;
30
+ this.spkgPath = options.spkgPath;
30
31
  }
31
32
  generatePackageJson() {
32
33
  return prettier_1.default.format(JSON.stringify({
@@ -51,6 +52,26 @@ class Scaffold {
51
52
  devDependencies: this.protocol.hasEvents() ? { 'matchstick-as': `0.5.0` } : undefined,
52
53
  }), { parser: 'json' });
53
54
  }
55
+ generatePackageJsonForSubstreams() {
56
+ return prettier_1.default.format(JSON.stringify({
57
+ name: (0, subgraph_1.getSubgraphBasename)(String(this.subgraphName)),
58
+ license: 'UNLICENSED',
59
+ scripts: {
60
+ build: 'graph build',
61
+ deploy: `graph deploy ` + `--node ${this.node} ` + this.subgraphName,
62
+ 'create-local': `graph create --node http://localhost:8020/ ${this.subgraphName}`,
63
+ 'remove-local': `graph remove --node http://localhost:8020/ ${this.subgraphName}`,
64
+ 'deploy-local': `graph deploy ` +
65
+ `--node http://localhost:8020/ ` +
66
+ `--ipfs http://localhost:5001 ` +
67
+ this.subgraphName,
68
+ test: 'graph test',
69
+ },
70
+ dependencies: {
71
+ '@graphprotocol/graph-cli': GRAPH_CLI_VERSION,
72
+ },
73
+ }), { parser: 'json' });
74
+ }
54
75
  generateManifest() {
55
76
  const protocolManifest = this.protocol.getManifestScaffold();
56
77
  return prettier_1.default.format(`
@@ -115,6 +136,13 @@ dataSources:
115
136
  : undefined;
116
137
  }
117
138
  generate() {
139
+ if (this.protocol.name === 'substreams') {
140
+ return {
141
+ 'subgraph.yaml': this.generateManifest(),
142
+ 'schema.graphql': this.generateSchema(),
143
+ 'package.json': this.generatePackageJsonForSubstreams(),
144
+ };
145
+ }
118
146
  return {
119
147
  'package.json': this.generatePackageJson(),
120
148
  'subgraph.yaml': this.generateManifest(),
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.49.1-alpha-20230510040157-fe90ff7",
2
+ "version": "0.50.0-alpha-20230511200812-4eb8560",
3
3
  "commands": {
4
4
  "add": {
5
5
  "id": "add",
@@ -540,6 +540,12 @@
540
540
  "from-contract"
541
541
  ]
542
542
  },
543
+ "spkg": {
544
+ "name": "spkg",
545
+ "type": "option",
546
+ "summary": "Path to the SPKG file",
547
+ "multiple": false
548
+ },
543
549
  "network": {
544
550
  "name": "network",
545
551
  "type": "option",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphprotocol/graph-cli",
3
- "version": "0.49.1-alpha-20230510040157-fe90ff7",
3
+ "version": "0.50.0-alpha-20230511200812-4eb8560",
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",