@graphprotocol/graph-cli 0.91.1 → 0.92.0-alpha-20241209150634-4f2ab935596be92b5d147871fedff09f4d8766df

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.
Files changed (158) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/bin/run.js +4 -0
  3. package/dist/codegen/schema.d.ts +3 -3
  4. package/dist/codegen/schema.js +9 -36
  5. package/dist/codegen/schema.test.js +89 -117
  6. package/dist/codegen/template.d.ts +2 -2
  7. package/dist/codegen/template.js +8 -35
  8. package/dist/codegen/types/conversions.d.ts +1 -1
  9. package/dist/codegen/types/conversions.js +3 -8
  10. package/dist/codegen/types/index.js +13 -28
  11. package/dist/codegen/types/index.test.js +432 -457
  12. package/dist/codegen/typescript.js +30 -22
  13. package/dist/codegen/util.d.ts +1 -1
  14. package/dist/codegen/util.js +7 -16
  15. package/dist/codegen/util.test.js +12 -14
  16. package/dist/command-helpers/abi.d.ts +1 -1
  17. package/dist/command-helpers/abi.js +26 -41
  18. package/dist/command-helpers/abi.test.js +17 -19
  19. package/dist/command-helpers/auth.js +13 -44
  20. package/dist/command-helpers/compiler.d.ts +4 -5
  21. package/dist/command-helpers/compiler.js +11 -42
  22. package/dist/command-helpers/compiler.test.js +17 -19
  23. package/dist/command-helpers/data-sources.d.ts +1 -1
  24. package/dist/command-helpers/data-sources.js +11 -20
  25. package/dist/command-helpers/fs.js +3 -9
  26. package/dist/command-helpers/ipfs.js +1 -4
  27. package/dist/command-helpers/jsonrpc.js +8 -15
  28. package/dist/command-helpers/network.js +19 -28
  29. package/dist/command-helpers/network.test.js +25 -53
  30. package/dist/command-helpers/node.d.ts +1 -2
  31. package/dist/command-helpers/node.js +9 -15
  32. package/dist/command-helpers/scaffold.d.ts +9 -9
  33. package/dist/command-helpers/scaffold.js +58 -59
  34. package/dist/command-helpers/sort.js +1 -4
  35. package/dist/command-helpers/sort.test.js +18 -20
  36. package/dist/command-helpers/spinner.js +6 -11
  37. package/dist/command-helpers/subgraph.js +1 -5
  38. package/dist/command-helpers/version.js +8 -39
  39. package/dist/command-helpers/version.test.js +46 -71
  40. package/dist/commands/add.d.ts +8 -8
  41. package/dist/commands/add.js +74 -104
  42. package/dist/commands/auth.d.ts +2 -2
  43. package/dist/commands/auth.js +30 -31
  44. package/dist/commands/build.d.ts +9 -9
  45. package/dist/commands/build.js +54 -83
  46. package/dist/commands/clean.d.ts +3 -3
  47. package/dist/commands/clean.js +21 -24
  48. package/dist/commands/codegen.d.ts +8 -8
  49. package/dist/commands/codegen.js +54 -83
  50. package/dist/commands/create.d.ts +5 -5
  51. package/dist/commands/create.js +38 -42
  52. package/dist/commands/deploy.d.ts +16 -16
  53. package/dist/commands/deploy.js +117 -138
  54. package/dist/commands/init.d.ts +17 -17
  55. package/dist/commands/init.js +212 -248
  56. package/dist/commands/local.d.ts +13 -13
  57. package/dist/commands/local.js +102 -110
  58. package/dist/commands/publish.d.ts +8 -8
  59. package/dist/commands/publish.js +66 -90
  60. package/dist/commands/remove.d.ts +5 -5
  61. package/dist/commands/remove.js +38 -42
  62. package/dist/commands/test.d.ts +8 -8
  63. package/dist/commands/test.js +74 -80
  64. package/dist/compiler/asc.d.ts +0 -1
  65. package/dist/compiler/asc.js +3 -44
  66. package/dist/compiler/index.d.ts +3 -4
  67. package/dist/compiler/index.js +106 -124
  68. package/dist/constants.js +3 -6
  69. package/dist/debug.js +4 -9
  70. package/dist/fetch.js +5 -8
  71. package/dist/index.js +1 -5
  72. package/dist/migrations/mapping_api_version_0_0_1.js +8 -36
  73. package/dist/migrations/mapping_api_version_0_0_2.js +8 -36
  74. package/dist/migrations/mapping_api_version_0_0_3.js +8 -36
  75. package/dist/migrations/mapping_api_version_0_0_4.js +8 -36
  76. package/dist/migrations/mapping_api_version_0_0_5.js +8 -36
  77. package/dist/migrations/spec_version_0_0_2.js +4 -29
  78. package/dist/migrations/spec_version_0_0_3.js +4 -29
  79. package/dist/migrations/util/load-manifest.js +6 -13
  80. package/dist/migrations/util/versions.js +9 -16
  81. package/dist/migrations.js +12 -39
  82. package/dist/protocols/arweave/scaffold/manifest.js +2 -7
  83. package/dist/protocols/arweave/scaffold/mapping.js +1 -5
  84. package/dist/protocols/arweave/subgraph.d.ts +1 -1
  85. package/dist/protocols/arweave/subgraph.js +7 -10
  86. package/dist/protocols/contract.js +1 -2
  87. package/dist/protocols/cosmos/scaffold/manifest.js +2 -7
  88. package/dist/protocols/cosmos/scaffold/mapping.js +1 -5
  89. package/dist/protocols/cosmos/subgraph.d.ts +1 -1
  90. package/dist/protocols/cosmos/subgraph.js +7 -10
  91. package/dist/protocols/ethereum/abi.d.ts +1 -1
  92. package/dist/protocols/ethereum/abi.js +15 -18
  93. package/dist/protocols/ethereum/codegen/abi.d.ts +4 -4
  94. package/dist/protocols/ethereum/codegen/abi.js +28 -59
  95. package/dist/protocols/ethereum/codegen/abi.test.js +60 -88
  96. package/dist/protocols/ethereum/codegen/template.d.ts +1 -1
  97. package/dist/protocols/ethereum/codegen/template.js +3 -28
  98. package/dist/protocols/ethereum/contract.d.ts +1 -1
  99. package/dist/protocols/ethereum/contract.js +2 -4
  100. package/dist/protocols/ethereum/scaffold/manifest.d.ts +2 -2
  101. package/dist/protocols/ethereum/scaffold/manifest.js +9 -17
  102. package/dist/protocols/ethereum/scaffold/mapping.d.ts +1 -1
  103. package/dist/protocols/ethereum/scaffold/mapping.js +3 -7
  104. package/dist/protocols/ethereum/subgraph.d.ts +2 -2
  105. package/dist/protocols/ethereum/subgraph.js +24 -50
  106. package/dist/protocols/ethereum/type-generator.d.ts +3 -3
  107. package/dist/protocols/ethereum/type-generator.js +42 -46
  108. package/dist/protocols/file_template.d.ts +1 -1
  109. package/dist/protocols/file_template.js +3 -28
  110. package/dist/protocols/index.d.ts +5 -5
  111. package/dist/protocols/index.js +48 -74
  112. package/dist/protocols/near/contract.d.ts +1 -1
  113. package/dist/protocols/near/contract.js +2 -4
  114. package/dist/protocols/near/scaffold/manifest.js +4 -9
  115. package/dist/protocols/near/scaffold/mapping.js +1 -5
  116. package/dist/protocols/near/subgraph.d.ts +1 -1
  117. package/dist/protocols/near/subgraph.js +7 -10
  118. package/dist/protocols/subgraph/scaffold/manifest.js +2 -7
  119. package/dist/protocols/subgraph/scaffold/mapping.js +1 -5
  120. package/dist/protocols/subgraph/subgraph.js +7 -10
  121. package/dist/protocols/subgraph.js +1 -2
  122. package/dist/protocols/substreams/scaffold/manifest.d.ts +1 -1
  123. package/dist/protocols/substreams/scaffold/manifest.js +2 -7
  124. package/dist/protocols/substreams/subgraph.d.ts +1 -1
  125. package/dist/protocols/substreams/subgraph.js +7 -10
  126. package/dist/scaffold/cosmos.test.js +12 -17
  127. package/dist/scaffold/ethereum.test.js +26 -31
  128. package/dist/scaffold/get-docker-file.js +1 -5
  129. package/dist/scaffold/get-git-ignore.js +1 -5
  130. package/dist/scaffold/index.d.ts +2 -2
  131. package/dist/scaffold/index.js +47 -38
  132. package/dist/scaffold/mapping.js +14 -45
  133. package/dist/scaffold/near.test.js +12 -17
  134. package/dist/scaffold/schema.d.ts +1 -1
  135. package/dist/scaffold/schema.js +17 -49
  136. package/dist/scaffold/tests.js +15 -22
  137. package/dist/schema.d.ts +2 -2
  138. package/dist/schema.js +9 -35
  139. package/dist/subgraph.d.ts +1 -1
  140. package/dist/subgraph.js +38 -71
  141. package/dist/tsconfig.build.tsbuildinfo +1 -0
  142. package/dist/type-generator.d.ts +2 -2
  143. package/dist/type-generator.js +67 -95
  144. package/dist/utils.d.ts +2 -1
  145. package/dist/utils.js +6 -11
  146. package/dist/validation/contract.d.ts +2 -2
  147. package/dist/validation/contract.js +6 -14
  148. package/dist/validation/index.d.ts +3 -3
  149. package/dist/validation/index.js +3 -10
  150. package/dist/validation/manifest.d.ts +1 -1
  151. package/dist/validation/manifest.js +31 -38
  152. package/dist/validation/schema.js +60 -93
  153. package/dist/validation/schema.test.js +27 -29
  154. package/dist/version.js +5 -11
  155. package/dist/watcher.js +12 -13
  156. package/oclif.manifest.json +563 -404
  157. package/package.json +39 -41
  158. package/bin/run +0 -6
@@ -1,36 +1,41 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.writeTestsFiles = exports.writeMapping = exports.writeSchema = exports.writeABI = exports.writeScaffold = exports.generateScaffold = exports.generateDataSource = void 0;
7
- const path_1 = __importDefault(require("path"));
8
- const fs_extra_1 = __importDefault(require("fs-extra"));
9
- const gluegun_1 = require("gluegun");
10
- const immutable_1 = require("immutable");
11
- const prettier_1 = __importDefault(require("prettier"));
12
- const yaml_1 = __importDefault(require("yaml"));
13
- const scaffold_1 = __importDefault(require("../scaffold"));
14
- const mapping_1 = require("../scaffold/mapping");
15
- const schema_1 = require("../scaffold/schema");
16
- const tests_1 = require("../scaffold/tests");
17
- const spinner_1 = require("./spinner");
18
- const generateDataSource = async (protocol, contractName, network, contractAddress, abi, startBlock) => {
1
+ import path from 'node:path';
2
+ import fs from 'fs-extra';
3
+ import { strings } from 'gluegun';
4
+ import { Map } from 'immutable';
5
+ import prettier from 'prettier';
6
+ import yaml from 'yaml';
7
+ import Scaffold from '../scaffold/index.js';
8
+ import { generateEventIndexingHandlers } from '../scaffold/mapping.js';
9
+ import { abiEvents, generateEventType } from '../scaffold/schema.js';
10
+ import { generateTestsFiles } from '../scaffold/tests.js';
11
+ import { step } from './spinner.js';
12
+ export const generateDataSource = async (protocol, contractName, network, contractAddress, abi, startBlock) => {
19
13
  const protocolManifest = protocol.getManifestScaffold();
20
- return immutable_1.Map.of('kind', protocol.name, 'name', contractName, 'network', network, 'source', yaml_1.default.parse(await prettier_1.default.format(protocolManifest.source({
21
- contract: contractAddress,
22
- contractName,
23
- startBlock,
24
- }), {
25
- parser: 'yaml',
26
- })), 'mapping', yaml_1.default.parse(await prettier_1.default.format(protocolManifest.mapping({ abi, contractName }), {
27
- parser: 'yaml',
28
- }))).asMutable();
14
+ return Map([
15
+ ['kind', protocol.name],
16
+ ['name', contractName],
17
+ ['network', network],
18
+ [
19
+ 'source',
20
+ yaml.parse(await prettier.format(protocolManifest.source({
21
+ contract: contractAddress,
22
+ contractName,
23
+ startBlock,
24
+ }), {
25
+ parser: 'yaml',
26
+ })),
27
+ ],
28
+ [
29
+ 'mapping',
30
+ yaml.parse(await prettier.format(protocolManifest.mapping({ abi, contractName }), {
31
+ parser: 'yaml',
32
+ })),
33
+ ],
34
+ ]).asMutable();
29
35
  };
30
- exports.generateDataSource = generateDataSource;
31
- const generateScaffold = async ({ protocolInstance, abi, source, network, subgraphName, indexEvents, contractName = 'Contract', startBlock, node, spkgPath, entities, }, spinner) => {
32
- (0, spinner_1.step)(spinner, 'Generate subgraph');
33
- const scaffold = new scaffold_1.default({
36
+ export const generateScaffold = async ({ protocolInstance, abi, source, network, subgraphName, indexEvents, contractName = 'Contract', startBlock, node, spkgPath, entities, }, spinner) => {
37
+ step(spinner, 'Generate subgraph');
38
+ const scaffold = new Scaffold({
34
39
  protocol: protocolInstance,
35
40
  abi,
36
41
  indexEvents,
@@ -45,73 +50,67 @@ const generateScaffold = async ({ protocolInstance, abi, source, network, subgra
45
50
  });
46
51
  return await scaffold.generate();
47
52
  };
48
- exports.generateScaffold = generateScaffold;
49
53
  const writeScaffoldDirectory = async (scaffold, directory, spinner) => {
50
54
  // Create directory itself
51
- await fs_extra_1.default.mkdirs(directory);
55
+ await fs.mkdirs(directory);
52
56
  const promises = Object.keys(scaffold).map(async (basename) => {
53
57
  const content = scaffold[basename];
54
- const filename = path_1.default.join(directory, basename);
58
+ const filename = path.join(directory, basename);
55
59
  // Write file or recurse into subdirectory
56
60
  if (typeof content === 'string') {
57
- await fs_extra_1.default.writeFile(filename, content, 'utf-8');
61
+ await fs.writeFile(filename, content, 'utf-8');
58
62
  }
59
63
  else if (content == null) {
60
64
  return; // continue loop
61
65
  }
62
66
  else {
63
- writeScaffoldDirectory(content, path_1.default.join(directory, basename), spinner);
67
+ writeScaffoldDirectory(content, path.join(directory, basename), spinner);
64
68
  }
65
69
  });
66
70
  await Promise.all(promises);
67
71
  };
68
- const writeScaffold = async (scaffold, directory, spinner) => {
69
- (0, spinner_1.step)(spinner, `Write subgraph to directory`);
72
+ export const writeScaffold = async (scaffold, directory, spinner) => {
73
+ step(spinner, `Write subgraph to directory`);
70
74
  await writeScaffoldDirectory(scaffold, directory, spinner);
71
75
  };
72
- exports.writeScaffold = writeScaffold;
73
- const writeABI = async (abi, contractName) => {
74
- const data = await prettier_1.default.format(JSON.stringify(abi.data), {
76
+ export const writeABI = async (abi, contractName) => {
77
+ const data = await prettier.format(JSON.stringify(abi.data), {
75
78
  parser: 'json',
76
79
  });
77
- await fs_extra_1.default.writeFile(`./abis/${contractName}.json`, data, 'utf-8');
80
+ await fs.writeFile(`./abis/${contractName}.json`, data, 'utf-8');
78
81
  };
79
- exports.writeABI = writeABI;
80
- const writeSchema = async (abi, protocol, schemaPath, entities, contractName) => {
82
+ export const writeSchema = async (abi, protocol, schemaPath, entities, contractName) => {
81
83
  const events = protocol.hasEvents()
82
- ? (0, schema_1.abiEvents)(abi)
84
+ ? abiEvents(abi)
83
85
  .filter(event => !entities.includes(event.get('name')))
84
86
  .toJS()
85
87
  : [];
86
- const data = await prettier_1.default.format(events.map(event => (0, schema_1.generateEventType)(event, protocol.name, contractName)).join('\n\n'), {
88
+ const data = await prettier.format(events.map(event => generateEventType(event, protocol.name, contractName)).join('\n\n'), {
87
89
  parser: 'graphql',
88
90
  });
89
- await fs_extra_1.default.appendFile(schemaPath, data, { encoding: 'utf-8' });
91
+ await fs.appendFile(schemaPath, data, { encoding: 'utf-8' });
90
92
  };
91
- exports.writeSchema = writeSchema;
92
- const writeMapping = async (abi, protocol, contractName, entities) => {
93
+ export const writeMapping = async (abi, protocol, contractName, entities) => {
93
94
  const events = protocol.hasEvents()
94
- ? (0, schema_1.abiEvents)(abi)
95
+ ? abiEvents(abi)
95
96
  .filter(event => !entities.includes(event.get('name')))
96
97
  .toJS()
97
98
  : [];
98
- const mapping = await prettier_1.default.format((0, mapping_1.generateEventIndexingHandlers)(events, contractName), {
99
+ const mapping = await prettier.format(generateEventIndexingHandlers(events, contractName), {
99
100
  parser: 'typescript',
100
101
  semi: false,
101
102
  });
102
- await fs_extra_1.default.writeFile(`./src/${gluegun_1.strings.kebabCase(contractName)}.ts`, mapping, 'utf-8');
103
+ await fs.writeFile(`./src/${strings.kebabCase(contractName)}.ts`, mapping, 'utf-8');
103
104
  };
104
- exports.writeMapping = writeMapping;
105
- const writeTestsFiles = async (abi, protocol, contractName) => {
105
+ export const writeTestsFiles = async (abi, protocol, contractName) => {
106
106
  const hasEvents = protocol.hasEvents();
107
- const events = hasEvents ? (0, schema_1.abiEvents)(abi).toJS() : [];
107
+ const events = hasEvents ? abiEvents(abi).toJS() : [];
108
108
  if (events.length > 0) {
109
109
  // If a contract is added to a subgraph that has no tests folder
110
- await fs_extra_1.default.ensureDir('./tests/');
111
- const testsFiles = await (0, tests_1.generateTestsFiles)(contractName, events, true);
110
+ await fs.ensureDir('./tests/');
111
+ const testsFiles = await generateTestsFiles(contractName, events, true);
112
112
  for (const [fileName, content] of Object.entries(testsFiles)) {
113
- await fs_extra_1.default.writeFile(`./tests/${fileName}`, content, 'utf-8');
113
+ await fs.writeFile(`./tests/${fileName}`, content, 'utf-8');
114
114
  }
115
115
  }
116
116
  };
117
- exports.writeTestsFiles = writeTestsFiles;
@@ -1,6 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sortWithPriority = void 0;
4
1
  /**
5
2
  * Sorts an array with specified elements given priority.
6
3
  * Use a predicate function, or provide an array to prioritise elements.
@@ -38,4 +35,4 @@ function sortWithPriority(array, prioritySpecifier, compareFunction) {
38
35
  }
39
36
  return priorityArray.concat(regularArray);
40
37
  }
41
- exports.sortWithPriority = sortWithPriority;
38
+ export { sortWithPriority };
@@ -1,33 +1,31 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const vitest_1 = require("vitest");
4
- const sort_1 = require("./sort"); // adjust the import based on your file structure
5
- (0, vitest_1.describe)('sortWithPriority', () => {
6
- (0, vitest_1.it)('should sort numbers with specific priority elements', () => {
1
+ import { describe, expect, it } from 'vitest';
2
+ import { sortWithPriority } from './sort.js'; // adjust the import based on your file structure
3
+ describe('sortWithPriority', () => {
4
+ it('should sort numbers with specific priority elements', () => {
7
5
  const numbers = [5, 3, 9, 1, 4];
8
6
  const priorityNumbers = [9, 1];
9
- const result = (0, sort_1.sortWithPriority)(numbers, priorityNumbers);
10
- (0, vitest_1.expect)(result).toEqual([1, 9, 3, 4, 5]);
7
+ const result = sortWithPriority(numbers, priorityNumbers);
8
+ expect(result).toEqual([1, 9, 3, 4, 5]);
11
9
  });
12
- (0, vitest_1.it)('should default sort numbers if no priority specifier', () => {
10
+ it('should default sort numbers if no priority specifier', () => {
13
11
  const numbers = [5, 3, 9, 1, 4];
14
- const result = (0, sort_1.sortWithPriority)(numbers);
15
- (0, vitest_1.expect)(result).toEqual([1, 3, 4, 5, 9]);
12
+ const result = sortWithPriority(numbers);
13
+ expect(result).toEqual([1, 3, 4, 5, 9]);
16
14
  });
17
- (0, vitest_1.it)('should sort strings with priority determined by a function', () => {
15
+ it('should sort strings with priority determined by a function', () => {
18
16
  const fruits = ['apple', 'orange', 'banana', 'mango', 'kiwi', 'melon'];
19
- const sortedFruits = (0, sort_1.sortWithPriority)(fruits, fruit => fruit.startsWith('m'));
20
- (0, vitest_1.expect)(sortedFruits).toEqual(['mango', 'melon', 'apple', 'banana', 'kiwi', 'orange']);
17
+ const sortedFruits = sortWithPriority(fruits, fruit => fruit.startsWith('m'));
18
+ expect(sortedFruits).toEqual(['mango', 'melon', 'apple', 'banana', 'kiwi', 'orange']);
21
19
  });
22
- (0, vitest_1.it)('should handle an empty array', () => {
20
+ it('should handle an empty array', () => {
23
21
  const emptyArray = [];
24
- const result = (0, sort_1.sortWithPriority)(emptyArray, x => x > 3);
25
- (0, vitest_1.expect)(result).toEqual([]);
22
+ const result = sortWithPriority(emptyArray, x => x > 3);
23
+ expect(result).toEqual([]);
26
24
  });
27
- (0, vitest_1.it)('should sort using a custom compare function', () => {
25
+ it('should sort using a custom compare function', () => {
28
26
  const numbers = [5, 3, 9, 1, 4];
29
27
  const priorityNumbers = [9, 1];
30
- const result = (0, sort_1.sortWithPriority)(numbers, priorityNumbers, (a, b) => a - b);
31
- (0, vitest_1.expect)(result).toEqual([1, 9, 3, 4, 5]);
28
+ const result = sortWithPriority(numbers, priorityNumbers, (a, b) => a - b);
29
+ expect(result).toEqual([1, 9, 3, 4, 5]);
32
30
  });
33
31
  });
@@ -1,20 +1,16 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.withSpinner = exports.step = void 0;
4
- const gluegun_1 = require("gluegun");
5
- const step = (spinner, subject, text) => {
1
+ import { print } from 'gluegun';
2
+ export const step = (spinner, subject, text) => {
6
3
  if (text) {
7
4
  spinner.stopAndPersist({
8
- text: gluegun_1.print.colors.muted(`${subject} ${text}`),
5
+ text: print.colors.muted(`${subject} ${text}`),
9
6
  });
10
7
  }
11
8
  else {
12
- spinner.stopAndPersist({ text: gluegun_1.print.colors.muted(subject) });
9
+ spinner.stopAndPersist({ text: print.colors.muted(subject) });
13
10
  }
14
11
  spinner.start();
15
12
  return spinner;
16
13
  };
17
- exports.step = step;
18
14
  // Executes the function `f` in a command-line spinner, using the
19
15
  // provided captions for in-progress, error and failed messages.
20
16
  //
@@ -24,8 +20,8 @@ exports.step = step;
24
20
  // spinner stops with the warning message and returns the `result` value.
25
21
  // Otherwise the spinner prints the in-progress message with a check mark
26
22
  // and simply returns the value returned by `f`.
27
- const withSpinner = async (text, errorText, warningText, f) => {
28
- const spinner = gluegun_1.print.spin(text);
23
+ export const withSpinner = async (text, errorText, warningText, f) => {
24
+ const spinner = print.spin(text);
29
25
  try {
30
26
  const result = await f(spinner);
31
27
  if (typeof result === 'object') {
@@ -54,4 +50,3 @@ const withSpinner = async (text, errorText, warningText, f) => {
54
50
  throw e;
55
51
  }
56
52
  };
57
- exports.withSpinner = withSpinner;
@@ -1,8 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getSubgraphBasename = void 0;
4
- const getSubgraphBasename = (name) => {
1
+ export const getSubgraphBasename = (name) => {
5
2
  const segments = name.split('/', 2);
6
3
  return segments[segments.length - 1];
7
4
  };
8
- exports.getSubgraphBasename = getSubgraphBasename;
@@ -1,53 +1,23 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.assertGraphTsVersion = exports.assertManifestApiVersion = void 0;
30
- const semver_1 = __importDefault(require("semver"));
31
- const manifestUtil = __importStar(require("../migrations/util/load-manifest"));
32
- const graphTsUtil = __importStar(require("../migrations/util/versions"));
33
- const assertManifestApiVersion = async (manifestPath, minimumApiVersion) => {
1
+ import semver from 'semver';
2
+ import * as manifestUtil from '../migrations/util/load-manifest.js';
3
+ import * as graphTsUtil from '../migrations/util/versions.js';
4
+ export const assertManifestApiVersion = async (manifestPath, minimumApiVersion) => {
34
5
  const manifest = await manifestUtil.loadManifest(manifestPath);
35
- const lessThanMinimumVersion = (manifestApiVersion) => semver_1.default.lt(manifestApiVersion, minimumApiVersion);
6
+ const lessThanMinimumVersion = (manifestApiVersion) => semver.lt(manifestApiVersion, minimumApiVersion);
36
7
  let isLessThanMinimumVersion = false;
37
8
  if (manifest) {
38
9
  if (manifest.dataSources && Array.isArray(manifest.dataSources)) {
39
10
  isLessThanMinimumVersion = manifest.dataSources.some((dataSource) => dataSource?.mapping?.apiVersion && lessThanMinimumVersion(dataSource.mapping.apiVersion));
40
11
  }
41
12
  if (manifest.templates && Array.isArray(manifest.templates)) {
42
- isLessThanMinimumVersion || (isLessThanMinimumVersion = manifest.templates.some((template) => template?.mapping?.apiVersion && lessThanMinimumVersion(template.mapping.apiVersion)));
13
+ isLessThanMinimumVersion ||= manifest.templates.some((template) => template?.mapping?.apiVersion && lessThanMinimumVersion(template.mapping.apiVersion));
43
14
  }
44
15
  }
45
16
  if (isLessThanMinimumVersion) {
46
17
  throw new Error(`The current version of graph-cli can't be used with mappings on apiVersion less than '${minimumApiVersion}'`);
47
18
  }
48
19
  };
49
- exports.assertManifestApiVersion = assertManifestApiVersion;
50
- const assertGraphTsVersion = async (sourceDir, minimumGraphTsVersion) => {
20
+ export const assertGraphTsVersion = async (sourceDir, minimumGraphTsVersion) => {
51
21
  let graphTsVersion;
52
22
  try {
53
23
  graphTsVersion = await graphTsUtil.getGraphTsVersion(sourceDir);
@@ -58,9 +28,8 @@ const assertGraphTsVersion = async (sourceDir, minimumGraphTsVersion) => {
58
28
  // Coerce needed because we may be dealing with an alpha version
59
29
  // and in the `semver` library, this would return true when comparing
60
30
  // the same version.
61
- if (graphTsVersion && semver_1.default.lt(semver_1.default.coerce(graphTsVersion), minimumGraphTsVersion)) {
31
+ if (graphTsVersion && semver.lt(semver.coerce(graphTsVersion), minimumGraphTsVersion)) {
62
32
  throw new Error(`To use this version of the graph-cli you must upgrade the graph-ts dependency to a version greater than or equal to ${minimumGraphTsVersion}
63
33
  Also, you'll probably need to take a look at our AssemblyScript migration guide because of language breaking changes: https://thegraph.com/docs/developer/assemblyscript-migration-guide`);
64
34
  }
65
35
  };
66
- exports.assertGraphTsVersion = assertGraphTsVersion;
@@ -1,75 +1,50 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- const vitest_1 = require("vitest");
27
- const loadManifestUtils = __importStar(require("../migrations/util/load-manifest"));
28
- const graphTsUtil = __importStar(require("../migrations/util/versions"));
29
- const version_1 = require("./version");
30
- vitest_1.describe.concurrent('Version Command Helpers', () => {
31
- (0, vitest_1.beforeEach)(() => {
32
- vitest_1.vi.resetModules();
1
+ import { beforeEach, describe, expect, test, vi } from 'vitest';
2
+ import * as loadManifestUtils from '../migrations/util/load-manifest.js';
3
+ import * as graphTsUtil from '../migrations/util/versions.js';
4
+ import { assertGraphTsVersion, assertManifestApiVersion } from './version.js';
5
+ describe.concurrent('Version Command Helpers', () => {
6
+ beforeEach(() => {
7
+ vi.resetModules();
33
8
  });
34
- (0, vitest_1.describe)('assertManifestApiVersion', () => {
9
+ describe('assertManifestApiVersion', () => {
35
10
  const fakeManifestPath = 'fake/manifest/path';
36
11
  const minimumApiVersion = '0.0.5';
37
- (0, vitest_1.describe)('With just dataSources', () => {
38
- (0, vitest_1.test)('When all of them are less than minimum apiVersion', async () => {
39
- vitest_1.vi.spyOn(loadManifestUtils, 'loadManifest').mockImplementation(() => Promise.resolve({
12
+ describe('With just dataSources', () => {
13
+ test('When all of them are less than minimum apiVersion', async () => {
14
+ vi.spyOn(loadManifestUtils, 'loadManifest').mockImplementation(() => Promise.resolve({
40
15
  dataSources: [
41
16
  { mapping: { apiVersion: '0.0.1' } },
42
17
  { mapping: { apiVersion: '0.0.2' } },
43
18
  { mapping: { apiVersion: '0.0.3' } },
44
19
  ],
45
20
  }));
46
- await (0, vitest_1.expect)((0, version_1.assertManifestApiVersion)(fakeManifestPath, minimumApiVersion)).rejects.toThrow(new Error(`The current version of graph-cli can't be used with mappings on apiVersion less than '${minimumApiVersion}'`));
21
+ await expect(assertManifestApiVersion(fakeManifestPath, minimumApiVersion)).rejects.toThrow(new Error(`The current version of graph-cli can't be used with mappings on apiVersion less than '${minimumApiVersion}'`));
47
22
  });
48
- (0, vitest_1.test)('When one of them is less than minimum apiVersion', async () => {
49
- vitest_1.vi.spyOn(loadManifestUtils, 'loadManifest').mockImplementation(() => Promise.resolve({
23
+ test('When one of them is less than minimum apiVersion', async () => {
24
+ vi.spyOn(loadManifestUtils, 'loadManifest').mockImplementation(() => Promise.resolve({
50
25
  dataSources: [
51
26
  { mapping: { apiVersion: '0.0.5' } },
52
27
  { mapping: { apiVersion: '0.0.2' } },
53
28
  { mapping: { apiVersion: '0.0.5' } },
54
29
  ],
55
30
  }));
56
- await (0, vitest_1.expect)((0, version_1.assertManifestApiVersion)(fakeManifestPath, minimumApiVersion)).rejects.toThrow(new Error(`The current version of graph-cli can't be used with mappings on apiVersion less than '${minimumApiVersion}'`));
31
+ await expect(assertManifestApiVersion(fakeManifestPath, minimumApiVersion)).rejects.toThrow(new Error(`The current version of graph-cli can't be used with mappings on apiVersion less than '${minimumApiVersion}'`));
57
32
  });
58
- (0, vitest_1.test)('When none of them are less than minimum apiVersion', async () => {
59
- vitest_1.vi.spyOn(loadManifestUtils, 'loadManifest').mockImplementation(() => Promise.resolve({
33
+ test('When none of them are less than minimum apiVersion', async () => {
34
+ vi.spyOn(loadManifestUtils, 'loadManifest').mockImplementation(() => Promise.resolve({
60
35
  dataSources: [
61
36
  { mapping: { apiVersion: '0.0.5' } },
62
37
  { mapping: { apiVersion: '0.0.6' } },
63
38
  { mapping: { apiVersion: '0.0.5' } },
64
39
  ],
65
40
  }));
66
- await (0, vitest_1.expect)((0, version_1.assertManifestApiVersion)(fakeManifestPath, minimumApiVersion)).resolves.toBe(undefined);
41
+ await expect(assertManifestApiVersion(fakeManifestPath, minimumApiVersion)).resolves.toBe(undefined);
67
42
  });
68
43
  });
69
- (0, vitest_1.describe)('With dataSources and templates', () => {
70
- (0, vitest_1.describe)('And the dataSources have a lower apiVersion', () => {
71
- (0, vitest_1.test)('When all of the templates are less than minimum apiVersion', async () => {
72
- vitest_1.vi.spyOn(loadManifestUtils, 'loadManifest').mockImplementation(() => Promise.resolve({
44
+ describe('With dataSources and templates', () => {
45
+ describe('And the dataSources have a lower apiVersion', () => {
46
+ test('When all of the templates are less than minimum apiVersion', async () => {
47
+ vi.spyOn(loadManifestUtils, 'loadManifest').mockImplementation(() => Promise.resolve({
73
48
  dataSources: [
74
49
  { mapping: { apiVersion: '0.0.5' } },
75
50
  { mapping: { apiVersion: '0.0.5' } },
@@ -81,10 +56,10 @@ vitest_1.describe.concurrent('Version Command Helpers', () => {
81
56
  { mapping: { apiVersion: '0.0.3' } },
82
57
  ],
83
58
  }));
84
- await (0, vitest_1.expect)((0, version_1.assertManifestApiVersion)(fakeManifestPath, minimumApiVersion)).rejects.toThrow(new Error(`The current version of graph-cli can't be used with mappings on apiVersion less than '${minimumApiVersion}'`));
59
+ await expect(assertManifestApiVersion(fakeManifestPath, minimumApiVersion)).rejects.toThrow(new Error(`The current version of graph-cli can't be used with mappings on apiVersion less than '${minimumApiVersion}'`));
85
60
  });
86
- (0, vitest_1.test)('When one of the templates is less than minimum apiVersion', async () => {
87
- vitest_1.vi.spyOn(loadManifestUtils, 'loadManifest').mockImplementation(() => Promise.resolve({
61
+ test('When one of the templates is less than minimum apiVersion', async () => {
62
+ vi.spyOn(loadManifestUtils, 'loadManifest').mockImplementation(() => Promise.resolve({
88
63
  dataSources: [
89
64
  { mapping: { apiVersion: '0.0.5' } },
90
65
  { mapping: { apiVersion: '0.0.5' } },
@@ -96,10 +71,10 @@ vitest_1.describe.concurrent('Version Command Helpers', () => {
96
71
  { mapping: { apiVersion: '0.0.5' } },
97
72
  ],
98
73
  }));
99
- await (0, vitest_1.expect)((0, version_1.assertManifestApiVersion)(fakeManifestPath, minimumApiVersion)).rejects.toThrow(new Error(`The current version of graph-cli can't be used with mappings on apiVersion less than '${minimumApiVersion}'`));
74
+ await expect(assertManifestApiVersion(fakeManifestPath, minimumApiVersion)).rejects.toThrow(new Error(`The current version of graph-cli can't be used with mappings on apiVersion less than '${minimumApiVersion}'`));
100
75
  });
101
- (0, vitest_1.test)('When none of the templates are less than minimum apiVersion', async () => {
102
- vitest_1.vi.spyOn(loadManifestUtils, 'loadManifest').mockImplementation(() => Promise.resolve({
76
+ test('When none of the templates are less than minimum apiVersion', async () => {
77
+ vi.spyOn(loadManifestUtils, 'loadManifest').mockImplementation(() => Promise.resolve({
103
78
  dataSources: [
104
79
  { mapping: { apiVersion: '0.0.5' } },
105
80
  { mapping: { apiVersion: '0.0.5' } },
@@ -111,12 +86,12 @@ vitest_1.describe.concurrent('Version Command Helpers', () => {
111
86
  { mapping: { apiVersion: '0.0.5' } },
112
87
  ],
113
88
  }));
114
- await (0, vitest_1.expect)((0, version_1.assertManifestApiVersion)(fakeManifestPath, minimumApiVersion)).rejects.toThrow(new Error(`The current version of graph-cli can't be used with mappings on apiVersion less than '${minimumApiVersion}'`));
89
+ await expect(assertManifestApiVersion(fakeManifestPath, minimumApiVersion)).rejects.toThrow(new Error(`The current version of graph-cli can't be used with mappings on apiVersion less than '${minimumApiVersion}'`));
115
90
  });
116
91
  });
117
- (0, vitest_1.describe)('And the dataSources do NOT have a lower apiVersion', () => {
118
- (0, vitest_1.test)('When all of the templates are less than minimum apiVersion', async () => {
119
- vitest_1.vi.spyOn(loadManifestUtils, 'loadManifest').mockImplementation(() => Promise.resolve({
92
+ describe('And the dataSources do NOT have a lower apiVersion', () => {
93
+ test('When all of the templates are less than minimum apiVersion', async () => {
94
+ vi.spyOn(loadManifestUtils, 'loadManifest').mockImplementation(() => Promise.resolve({
120
95
  dataSources: [
121
96
  { mapping: { apiVersion: '0.0.5' } },
122
97
  { mapping: { apiVersion: '0.0.5' } },
@@ -128,10 +103,10 @@ vitest_1.describe.concurrent('Version Command Helpers', () => {
128
103
  { mapping: { apiVersion: '0.0.3' } },
129
104
  ],
130
105
  }));
131
- await (0, vitest_1.expect)((0, version_1.assertManifestApiVersion)(fakeManifestPath, minimumApiVersion)).rejects.toThrow(new Error(`The current version of graph-cli can't be used with mappings on apiVersion less than '${minimumApiVersion}'`));
106
+ await expect(assertManifestApiVersion(fakeManifestPath, minimumApiVersion)).rejects.toThrow(new Error(`The current version of graph-cli can't be used with mappings on apiVersion less than '${minimumApiVersion}'`));
132
107
  });
133
- (0, vitest_1.test)('When one of the templates is less than minimum apiVersion', async () => {
134
- vitest_1.vi.spyOn(loadManifestUtils, 'loadManifest').mockImplementation(() => Promise.resolve({
108
+ test('When one of the templates is less than minimum apiVersion', async () => {
109
+ vi.spyOn(loadManifestUtils, 'loadManifest').mockImplementation(() => Promise.resolve({
135
110
  dataSources: [
136
111
  { mapping: { apiVersion: '0.0.5' } },
137
112
  { mapping: { apiVersion: '0.0.5' } },
@@ -143,10 +118,10 @@ vitest_1.describe.concurrent('Version Command Helpers', () => {
143
118
  { mapping: { apiVersion: '0.0.5' } },
144
119
  ],
145
120
  }));
146
- await (0, vitest_1.expect)((0, version_1.assertManifestApiVersion)(fakeManifestPath, minimumApiVersion)).rejects.toThrow(new Error(`The current version of graph-cli can't be used with mappings on apiVersion less than '${minimumApiVersion}'`));
121
+ await expect(assertManifestApiVersion(fakeManifestPath, minimumApiVersion)).rejects.toThrow(new Error(`The current version of graph-cli can't be used with mappings on apiVersion less than '${minimumApiVersion}'`));
147
122
  });
148
- (0, vitest_1.test)('When none of the templates are less than minimum apiVersion', async () => {
149
- vitest_1.vi.spyOn(loadManifestUtils, 'loadManifest').mockImplementation(() => Promise.resolve({
123
+ test('When none of the templates are less than minimum apiVersion', async () => {
124
+ vi.spyOn(loadManifestUtils, 'loadManifest').mockImplementation(() => Promise.resolve({
150
125
  dataSources: [
151
126
  { mapping: { apiVersion: '0.0.5' } },
152
127
  { mapping: { apiVersion: '0.0.5' } },
@@ -158,22 +133,22 @@ vitest_1.describe.concurrent('Version Command Helpers', () => {
158
133
  { mapping: { apiVersion: '0.0.5' } },
159
134
  ],
160
135
  }));
161
- await (0, vitest_1.expect)((0, version_1.assertManifestApiVersion)(fakeManifestPath, minimumApiVersion)).resolves.toBe(undefined);
136
+ await expect(assertManifestApiVersion(fakeManifestPath, minimumApiVersion)).resolves.toBe(undefined);
162
137
  });
163
138
  });
164
139
  });
165
140
  });
166
- (0, vitest_1.describe)('assertGraphTsVersion', () => {
141
+ describe('assertGraphTsVersion', () => {
167
142
  const fakeNodeModulesDir = 'fake/path/to/node/modules';
168
143
  const minimumGraphTsVersion = '0.22.0';
169
- (0, vitest_1.test)("When the installed graph-ts version is less than what's supported", async () => {
170
- vitest_1.vi.spyOn(graphTsUtil, 'getGraphTsVersion').mockImplementation(() => Promise.resolve('0.19.0'));
171
- await (0, vitest_1.expect)((0, version_1.assertGraphTsVersion)(fakeNodeModulesDir, minimumGraphTsVersion)).rejects.toThrow(new Error(`To use this version of the graph-cli you must upgrade the graph-ts dependency to a version greater than or equal to ${minimumGraphTsVersion}
144
+ test("When the installed graph-ts version is less than what's supported", async () => {
145
+ vi.spyOn(graphTsUtil, 'getGraphTsVersion').mockImplementation(() => Promise.resolve('0.19.0'));
146
+ await expect(assertGraphTsVersion(fakeNodeModulesDir, minimumGraphTsVersion)).rejects.toThrow(new Error(`To use this version of the graph-cli you must upgrade the graph-ts dependency to a version greater than or equal to ${minimumGraphTsVersion}
172
147
  Also, you'll probably need to take a look at our AssemblyScript migration guide because of language breaking changes: https://thegraph.com/docs/developer/assemblyscript-migration-guide`));
173
148
  });
174
- (0, vitest_1.test)('When the installed graph-ts version is a supported one', async () => {
175
- vitest_1.vi.spyOn(graphTsUtil, 'getGraphTsVersion').mockImplementation(() => Promise.resolve('0.22.0'));
176
- await (0, vitest_1.expect)((0, version_1.assertGraphTsVersion)(fakeNodeModulesDir, minimumGraphTsVersion)).resolves.toBe(undefined);
149
+ test('When the installed graph-ts version is a supported one', async () => {
150
+ vi.spyOn(graphTsUtil, 'getGraphTsVersion').mockImplementation(() => Promise.resolve('0.22.0'));
151
+ await expect(assertGraphTsVersion(fakeNodeModulesDir, minimumGraphTsVersion)).resolves.toBe(undefined);
177
152
  });
178
153
  });
179
154
  });
@@ -2,16 +2,16 @@ import { Command } from '@oclif/core';
2
2
  export default class AddCommand extends Command {
3
3
  static description: string;
4
4
  static args: {
5
- address: import("@oclif/core/lib/interfaces/parser").Arg<string, Record<string, unknown>>;
6
- 'subgraph-manifest': import("@oclif/core/lib/interfaces/parser").Arg<string, Record<string, unknown>>;
5
+ address: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
6
+ 'subgraph-manifest': import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
7
7
  };
8
8
  static flags: {
9
- help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
10
- abi: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
11
- 'start-block': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
12
- 'contract-name': import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
13
- 'merge-entities': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
14
- 'network-file': import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
9
+ help: import("@oclif/core/interfaces").BooleanFlag<void>;
10
+ abi: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
+ 'start-block': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
+ 'contract-name': import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
13
+ 'merge-entities': import("@oclif/core/interfaces").BooleanFlag<boolean>;
14
+ 'network-file': import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
15
15
  };
16
16
  run(): Promise<void>;
17
17
  }