@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.
- package/CHANGELOG.md +8 -0
- package/bin/run.js +4 -0
- package/dist/codegen/schema.d.ts +3 -3
- package/dist/codegen/schema.js +9 -36
- package/dist/codegen/schema.test.js +89 -117
- package/dist/codegen/template.d.ts +2 -2
- package/dist/codegen/template.js +8 -35
- package/dist/codegen/types/conversions.d.ts +1 -1
- package/dist/codegen/types/conversions.js +3 -8
- package/dist/codegen/types/index.js +13 -28
- package/dist/codegen/types/index.test.js +432 -457
- package/dist/codegen/typescript.js +30 -22
- package/dist/codegen/util.d.ts +1 -1
- package/dist/codegen/util.js +7 -16
- package/dist/codegen/util.test.js +12 -14
- package/dist/command-helpers/abi.d.ts +1 -1
- package/dist/command-helpers/abi.js +26 -41
- package/dist/command-helpers/abi.test.js +17 -19
- package/dist/command-helpers/auth.js +13 -44
- package/dist/command-helpers/compiler.d.ts +4 -5
- package/dist/command-helpers/compiler.js +11 -42
- package/dist/command-helpers/compiler.test.js +17 -19
- package/dist/command-helpers/data-sources.d.ts +1 -1
- package/dist/command-helpers/data-sources.js +11 -20
- package/dist/command-helpers/fs.js +3 -9
- package/dist/command-helpers/ipfs.js +1 -4
- package/dist/command-helpers/jsonrpc.js +8 -15
- package/dist/command-helpers/network.js +19 -28
- package/dist/command-helpers/network.test.js +25 -53
- package/dist/command-helpers/node.d.ts +1 -2
- package/dist/command-helpers/node.js +9 -15
- package/dist/command-helpers/scaffold.d.ts +9 -9
- package/dist/command-helpers/scaffold.js +58 -59
- package/dist/command-helpers/sort.js +1 -4
- package/dist/command-helpers/sort.test.js +18 -20
- package/dist/command-helpers/spinner.js +6 -11
- package/dist/command-helpers/subgraph.js +1 -5
- package/dist/command-helpers/version.js +8 -39
- package/dist/command-helpers/version.test.js +46 -71
- package/dist/commands/add.d.ts +8 -8
- package/dist/commands/add.js +74 -104
- package/dist/commands/auth.d.ts +2 -2
- package/dist/commands/auth.js +30 -31
- package/dist/commands/build.d.ts +9 -9
- package/dist/commands/build.js +54 -83
- package/dist/commands/clean.d.ts +3 -3
- package/dist/commands/clean.js +21 -24
- package/dist/commands/codegen.d.ts +8 -8
- package/dist/commands/codegen.js +54 -83
- package/dist/commands/create.d.ts +5 -5
- package/dist/commands/create.js +38 -42
- package/dist/commands/deploy.d.ts +16 -16
- package/dist/commands/deploy.js +117 -138
- package/dist/commands/init.d.ts +17 -17
- package/dist/commands/init.js +212 -248
- package/dist/commands/local.d.ts +13 -13
- package/dist/commands/local.js +102 -110
- package/dist/commands/publish.d.ts +8 -8
- package/dist/commands/publish.js +66 -90
- package/dist/commands/remove.d.ts +5 -5
- package/dist/commands/remove.js +38 -42
- package/dist/commands/test.d.ts +8 -8
- package/dist/commands/test.js +74 -80
- package/dist/compiler/asc.d.ts +0 -1
- package/dist/compiler/asc.js +3 -44
- package/dist/compiler/index.d.ts +3 -4
- package/dist/compiler/index.js +106 -124
- package/dist/constants.js +3 -6
- package/dist/debug.js +4 -9
- package/dist/fetch.js +5 -8
- package/dist/index.js +1 -5
- package/dist/migrations/mapping_api_version_0_0_1.js +8 -36
- package/dist/migrations/mapping_api_version_0_0_2.js +8 -36
- package/dist/migrations/mapping_api_version_0_0_3.js +8 -36
- package/dist/migrations/mapping_api_version_0_0_4.js +8 -36
- package/dist/migrations/mapping_api_version_0_0_5.js +8 -36
- package/dist/migrations/spec_version_0_0_2.js +4 -29
- package/dist/migrations/spec_version_0_0_3.js +4 -29
- package/dist/migrations/util/load-manifest.js +6 -13
- package/dist/migrations/util/versions.js +9 -16
- package/dist/migrations.js +12 -39
- package/dist/protocols/arweave/scaffold/manifest.js +2 -7
- package/dist/protocols/arweave/scaffold/mapping.js +1 -5
- package/dist/protocols/arweave/subgraph.d.ts +1 -1
- package/dist/protocols/arweave/subgraph.js +7 -10
- package/dist/protocols/contract.js +1 -2
- package/dist/protocols/cosmos/scaffold/manifest.js +2 -7
- package/dist/protocols/cosmos/scaffold/mapping.js +1 -5
- package/dist/protocols/cosmos/subgraph.d.ts +1 -1
- package/dist/protocols/cosmos/subgraph.js +7 -10
- package/dist/protocols/ethereum/abi.d.ts +1 -1
- package/dist/protocols/ethereum/abi.js +15 -18
- package/dist/protocols/ethereum/codegen/abi.d.ts +4 -4
- package/dist/protocols/ethereum/codegen/abi.js +28 -59
- package/dist/protocols/ethereum/codegen/abi.test.js +60 -88
- package/dist/protocols/ethereum/codegen/template.d.ts +1 -1
- package/dist/protocols/ethereum/codegen/template.js +3 -28
- package/dist/protocols/ethereum/contract.d.ts +1 -1
- package/dist/protocols/ethereum/contract.js +2 -4
- package/dist/protocols/ethereum/scaffold/manifest.d.ts +2 -2
- package/dist/protocols/ethereum/scaffold/manifest.js +9 -17
- package/dist/protocols/ethereum/scaffold/mapping.d.ts +1 -1
- package/dist/protocols/ethereum/scaffold/mapping.js +3 -7
- package/dist/protocols/ethereum/subgraph.d.ts +2 -2
- package/dist/protocols/ethereum/subgraph.js +24 -50
- package/dist/protocols/ethereum/type-generator.d.ts +3 -3
- package/dist/protocols/ethereum/type-generator.js +42 -46
- package/dist/protocols/file_template.d.ts +1 -1
- package/dist/protocols/file_template.js +3 -28
- package/dist/protocols/index.d.ts +5 -5
- package/dist/protocols/index.js +48 -74
- package/dist/protocols/near/contract.d.ts +1 -1
- package/dist/protocols/near/contract.js +2 -4
- package/dist/protocols/near/scaffold/manifest.js +4 -9
- package/dist/protocols/near/scaffold/mapping.js +1 -5
- package/dist/protocols/near/subgraph.d.ts +1 -1
- package/dist/protocols/near/subgraph.js +7 -10
- package/dist/protocols/subgraph/scaffold/manifest.js +2 -7
- package/dist/protocols/subgraph/scaffold/mapping.js +1 -5
- package/dist/protocols/subgraph/subgraph.js +7 -10
- package/dist/protocols/subgraph.js +1 -2
- package/dist/protocols/substreams/scaffold/manifest.d.ts +1 -1
- package/dist/protocols/substreams/scaffold/manifest.js +2 -7
- package/dist/protocols/substreams/subgraph.d.ts +1 -1
- package/dist/protocols/substreams/subgraph.js +7 -10
- package/dist/scaffold/cosmos.test.js +12 -17
- package/dist/scaffold/ethereum.test.js +26 -31
- package/dist/scaffold/get-docker-file.js +1 -5
- package/dist/scaffold/get-git-ignore.js +1 -5
- package/dist/scaffold/index.d.ts +2 -2
- package/dist/scaffold/index.js +47 -38
- package/dist/scaffold/mapping.js +14 -45
- package/dist/scaffold/near.test.js +12 -17
- package/dist/scaffold/schema.d.ts +1 -1
- package/dist/scaffold/schema.js +17 -49
- package/dist/scaffold/tests.js +15 -22
- package/dist/schema.d.ts +2 -2
- package/dist/schema.js +9 -35
- package/dist/subgraph.d.ts +1 -1
- package/dist/subgraph.js +38 -71
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/type-generator.d.ts +2 -2
- package/dist/type-generator.js +67 -95
- package/dist/utils.d.ts +2 -1
- package/dist/utils.js +6 -11
- package/dist/validation/contract.d.ts +2 -2
- package/dist/validation/contract.js +6 -14
- package/dist/validation/index.d.ts +3 -3
- package/dist/validation/index.js +3 -10
- package/dist/validation/manifest.d.ts +1 -1
- package/dist/validation/manifest.js +31 -38
- package/dist/validation/schema.js +60 -93
- package/dist/validation/schema.test.js +27 -29
- package/dist/version.js +5 -11
- package/dist/watcher.js +12 -13
- package/oclif.manifest.json +563 -404
- package/package.json +39 -41
- package/bin/run +0 -6
|
@@ -1,36 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
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
|
|
21
|
-
|
|
22
|
-
contractName,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
|
55
|
+
await fs.mkdirs(directory);
|
|
52
56
|
const promises = Object.keys(scaffold).map(async (basename) => {
|
|
53
57
|
const content = scaffold[basename];
|
|
54
|
-
const filename =
|
|
58
|
+
const filename = path.join(directory, basename);
|
|
55
59
|
// Write file or recurse into subdirectory
|
|
56
60
|
if (typeof content === 'string') {
|
|
57
|
-
await
|
|
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,
|
|
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
|
-
|
|
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
|
-
|
|
73
|
-
const
|
|
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
|
|
80
|
+
await fs.writeFile(`./abis/${contractName}.json`, data, 'utf-8');
|
|
78
81
|
};
|
|
79
|
-
|
|
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
|
-
?
|
|
84
|
+
? abiEvents(abi)
|
|
83
85
|
.filter(event => !entities.includes(event.get('name')))
|
|
84
86
|
.toJS()
|
|
85
87
|
: [];
|
|
86
|
-
const data = await
|
|
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
|
|
91
|
+
await fs.appendFile(schemaPath, data, { encoding: 'utf-8' });
|
|
90
92
|
};
|
|
91
|
-
|
|
92
|
-
const writeMapping = async (abi, protocol, contractName, entities) => {
|
|
93
|
+
export const writeMapping = async (abi, protocol, contractName, entities) => {
|
|
93
94
|
const events = protocol.hasEvents()
|
|
94
|
-
?
|
|
95
|
+
? abiEvents(abi)
|
|
95
96
|
.filter(event => !entities.includes(event.get('name')))
|
|
96
97
|
.toJS()
|
|
97
98
|
: [];
|
|
98
|
-
const mapping = await
|
|
99
|
+
const mapping = await prettier.format(generateEventIndexingHandlers(events, contractName), {
|
|
99
100
|
parser: 'typescript',
|
|
100
101
|
semi: false,
|
|
101
102
|
});
|
|
102
|
-
await
|
|
103
|
+
await fs.writeFile(`./src/${strings.kebabCase(contractName)}.ts`, mapping, 'utf-8');
|
|
103
104
|
};
|
|
104
|
-
|
|
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 ?
|
|
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
|
|
111
|
-
const testsFiles = await
|
|
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
|
|
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
|
-
|
|
38
|
+
export { sortWithPriority };
|
|
@@ -1,33 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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 =
|
|
10
|
-
|
|
7
|
+
const result = sortWithPriority(numbers, priorityNumbers);
|
|
8
|
+
expect(result).toEqual([1, 9, 3, 4, 5]);
|
|
11
9
|
});
|
|
12
|
-
|
|
10
|
+
it('should default sort numbers if no priority specifier', () => {
|
|
13
11
|
const numbers = [5, 3, 9, 1, 4];
|
|
14
|
-
const result =
|
|
15
|
-
|
|
12
|
+
const result = sortWithPriority(numbers);
|
|
13
|
+
expect(result).toEqual([1, 3, 4, 5, 9]);
|
|
16
14
|
});
|
|
17
|
-
|
|
15
|
+
it('should sort strings with priority determined by a function', () => {
|
|
18
16
|
const fruits = ['apple', 'orange', 'banana', 'mango', 'kiwi', 'melon'];
|
|
19
|
-
const sortedFruits =
|
|
20
|
-
|
|
17
|
+
const sortedFruits = sortWithPriority(fruits, fruit => fruit.startsWith('m'));
|
|
18
|
+
expect(sortedFruits).toEqual(['mango', 'melon', 'apple', 'banana', 'kiwi', 'orange']);
|
|
21
19
|
});
|
|
22
|
-
|
|
20
|
+
it('should handle an empty array', () => {
|
|
23
21
|
const emptyArray = [];
|
|
24
|
-
const result =
|
|
25
|
-
|
|
22
|
+
const result = sortWithPriority(emptyArray, x => x > 3);
|
|
23
|
+
expect(result).toEqual([]);
|
|
26
24
|
});
|
|
27
|
-
|
|
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 =
|
|
31
|
-
|
|
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
|
-
|
|
2
|
-
|
|
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:
|
|
5
|
+
text: print.colors.muted(`${subject} ${text}`),
|
|
9
6
|
});
|
|
10
7
|
}
|
|
11
8
|
else {
|
|
12
|
-
spinner.stopAndPersist({ text:
|
|
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 =
|
|
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
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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) =>
|
|
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
|
|
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
|
-
|
|
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 &&
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
9
|
+
describe('assertManifestApiVersion', () => {
|
|
35
10
|
const fakeManifestPath = 'fake/manifest/path';
|
|
36
11
|
const minimumApiVersion = '0.0.5';
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
|
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
|
-
|
|
49
|
-
|
|
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
|
|
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
|
-
|
|
59
|
-
|
|
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
|
|
41
|
+
await expect(assertManifestApiVersion(fakeManifestPath, minimumApiVersion)).resolves.toBe(undefined);
|
|
67
42
|
});
|
|
68
43
|
});
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
|
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
|
-
|
|
87
|
-
|
|
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
|
|
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
|
-
|
|
102
|
-
|
|
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
|
|
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
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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
|
|
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
|
-
|
|
134
|
-
|
|
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
|
|
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
|
-
|
|
149
|
-
|
|
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
|
|
136
|
+
await expect(assertManifestApiVersion(fakeManifestPath, minimumApiVersion)).resolves.toBe(undefined);
|
|
162
137
|
});
|
|
163
138
|
});
|
|
164
139
|
});
|
|
165
140
|
});
|
|
166
|
-
|
|
141
|
+
describe('assertGraphTsVersion', () => {
|
|
167
142
|
const fakeNodeModulesDir = 'fake/path/to/node/modules';
|
|
168
143
|
const minimumGraphTsVersion = '0.22.0';
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
await
|
|
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
|
-
|
|
175
|
-
|
|
176
|
-
await
|
|
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
|
});
|
package/dist/commands/add.d.ts
CHANGED
|
@@ -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/
|
|
6
|
-
'subgraph-manifest': import("@oclif/core/
|
|
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/
|
|
10
|
-
abi: import("@oclif/core/
|
|
11
|
-
'start-block': import("@oclif/core/
|
|
12
|
-
'contract-name': import("@oclif/core/
|
|
13
|
-
'merge-entities': import("@oclif/core/
|
|
14
|
-
'network-file': import("@oclif/core/
|
|
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
|
}
|