@graphprotocol/graph-cli 0.37.4 → 0.37.5
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/dist/bin.js +6 -0
- package/dist/cli.js +26 -0
- package/dist/codegen/schema.js +244 -0
- package/dist/codegen/schema.test.js +455 -0
- package/dist/codegen/template.js +66 -0
- package/dist/codegen/types/conversions.js +335 -0
- package/dist/codegen/types/index.js +71 -0
- package/dist/codegen/types/index.test.js +563 -0
- package/dist/codegen/typescript.js +200 -0
- package/dist/codegen/util.js +40 -0
- package/dist/codegen/util.test.js +93 -0
- package/dist/command-helpers/abi.js +76 -0
- package/dist/command-helpers/auth.js +76 -0
- package/dist/command-helpers/compiler.js +66 -0
- package/dist/command-helpers/data-sources.js +29 -0
- package/dist/command-helpers/fs.js +9 -0
- package/dist/command-helpers/gluegun.js +48 -0
- package/dist/command-helpers/ipfs.js +5 -0
- package/dist/command-helpers/jsonrpc.js +27 -0
- package/dist/command-helpers/network.js +90 -0
- package/dist/command-helpers/network.test.js +86 -0
- package/dist/command-helpers/node.js +40 -0
- package/dist/command-helpers/scaffold.js +110 -0
- package/dist/command-helpers/spinner.js +80 -0
- package/dist/command-helpers/studio.js +14 -0
- package/dist/command-helpers/studio.test.js +41 -0
- package/dist/command-helpers/subgraph.js +22 -0
- package/dist/command-helpers/version.js +66 -0
- package/dist/command-helpers/version.test.js +186 -0
- package/dist/commands/add.js +187 -0
- package/dist/commands/auth.js +122 -0
- package/dist/commands/build.js +136 -0
- package/dist/commands/codegen.js +128 -0
- package/dist/commands/create.js +94 -0
- package/dist/commands/deploy.js +335 -0
- package/dist/commands/init.js +800 -0
- package/dist/commands/local.js +380 -0
- package/dist/commands/remove.js +95 -0
- package/dist/commands/test.js +293 -0
- package/dist/compiler/asc.js +83 -0
- package/dist/compiler/index.js +466 -0
- package/dist/debug.js +16 -0
- package/dist/migrations/mapping_api_version_0_0_1.js +83 -0
- package/dist/migrations/mapping_api_version_0_0_2.js +83 -0
- package/dist/migrations/mapping_api_version_0_0_3.js +83 -0
- package/dist/migrations/mapping_api_version_0_0_4.js +85 -0
- package/dist/migrations/mapping_api_version_0_0_5.js +85 -0
- package/dist/migrations/spec_version_0_0_2.js +45 -0
- package/dist/migrations/spec_version_0_0_3.js +50 -0
- package/dist/migrations/util/load-manifest.js +16 -0
- package/dist/migrations/util/versions.js +28 -0
- package/dist/migrations.js +54 -0
- package/dist/protocols/arweave/manifest.graphql +57 -0
- package/dist/protocols/arweave/scaffold/manifest.js +18 -0
- package/dist/protocols/arweave/scaffold/mapping.js +52 -0
- package/dist/protocols/arweave/subgraph.js +23 -0
- package/dist/protocols/contract.js +2 -0
- package/dist/protocols/cosmos/manifest.graphql +76 -0
- package/dist/protocols/cosmos/scaffold/manifest.js +15 -0
- package/dist/protocols/cosmos/scaffold/mapping.js +38 -0
- package/dist/protocols/cosmos/subgraph.js +28 -0
- package/dist/protocols/ethereum/abi.js +138 -0
- package/dist/protocols/ethereum/codegen/abi.js +474 -0
- package/dist/protocols/ethereum/codegen/abi.test.js +325 -0
- package/dist/protocols/ethereum/codegen/template.js +52 -0
- package/dist/protocols/ethereum/contract.js +22 -0
- package/dist/protocols/ethereum/manifest.graphql +94 -0
- package/dist/protocols/ethereum/scaffold/manifest.js +32 -0
- package/dist/protocols/ethereum/scaffold/mapping.js +65 -0
- package/dist/protocols/ethereum/subgraph.js +172 -0
- package/dist/protocols/ethereum/type-generator.js +123 -0
- package/dist/protocols/index.js +266 -0
- package/dist/protocols/ipfs/codegen/file_template.js +53 -0
- package/dist/protocols/near/contract.js +41 -0
- package/dist/protocols/near/manifest.graphql +64 -0
- package/dist/protocols/near/scaffold/manifest.js +16 -0
- package/dist/protocols/near/scaffold/mapping.js +38 -0
- package/dist/protocols/near/subgraph.js +23 -0
- package/dist/protocols/subgraph.js +2 -0
- package/dist/protocols/substreams/manifest.graphql +45 -0
- package/dist/protocols/substreams/scaffold/manifest.js +12 -0
- package/dist/protocols/substreams/subgraph.js +23 -0
- package/dist/scaffold/cosmos.test.js +82 -0
- package/dist/scaffold/ethereum.test.js +496 -0
- package/dist/scaffold/index.js +133 -0
- package/dist/scaffold/mapping.js +57 -0
- package/dist/scaffold/near.test.js +85 -0
- package/dist/scaffold/schema.js +86 -0
- package/dist/scaffold/tests.js +179 -0
- package/dist/schema.js +54 -0
- package/dist/subgraph.js +243 -0
- package/dist/type-generator.js +225 -0
- package/dist/validation/contract.js +44 -0
- package/dist/validation/index.js +10 -0
- package/dist/validation/manifest.js +266 -0
- package/dist/validation/schema.js +768 -0
- package/dist/validation/schema.test.js +35 -0
- package/dist/watcher.js +79 -0
- package/package.json +1 -1
|
@@ -0,0 +1,186 @@
|
|
|
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 loadManifestUtil = __importStar(require("../migrations/util/load-manifest"));
|
|
27
|
+
const graphTsUtil = __importStar(require("../migrations/util/versions"));
|
|
28
|
+
const version_1 = require("./version");
|
|
29
|
+
describe('Version Command Helpers', () => {
|
|
30
|
+
describe('assertManifestApiVersion', () => {
|
|
31
|
+
const fakeManifestPath = 'fake/manifest/path';
|
|
32
|
+
const minimumApiVersion = '0.0.5';
|
|
33
|
+
describe('With just dataSources', () => {
|
|
34
|
+
test('When all of them are less than minimum apiVersion', async () => {
|
|
35
|
+
// @ts-expect-error TODO: dont pollute the globals
|
|
36
|
+
loadManifestUtil.loadManifest = jest.fn().mockImplementation(() => Promise.resolve({
|
|
37
|
+
dataSources: [
|
|
38
|
+
{ mapping: { apiVersion: '0.0.1' } },
|
|
39
|
+
{ mapping: { apiVersion: '0.0.2' } },
|
|
40
|
+
{ mapping: { apiVersion: '0.0.3' } },
|
|
41
|
+
],
|
|
42
|
+
}));
|
|
43
|
+
await 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}'`));
|
|
44
|
+
});
|
|
45
|
+
test('When one of them is less than minimum apiVersion', async () => {
|
|
46
|
+
// @ts-expect-error TODO: dont pollute the globals
|
|
47
|
+
loadManifestUtil.loadManifest = jest.fn().mockImplementation(() => Promise.resolve({
|
|
48
|
+
dataSources: [
|
|
49
|
+
{ mapping: { apiVersion: '0.0.5' } },
|
|
50
|
+
{ mapping: { apiVersion: '0.0.2' } },
|
|
51
|
+
{ mapping: { apiVersion: '0.0.5' } },
|
|
52
|
+
],
|
|
53
|
+
}));
|
|
54
|
+
await 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}'`));
|
|
55
|
+
});
|
|
56
|
+
test('When none of them are less than minimum apiVersion', async () => {
|
|
57
|
+
// @ts-expect-error TODO: dont pollute the globals
|
|
58
|
+
loadManifestUtil.loadManifest = jest.fn().mockImplementation(() => Promise.resolve({
|
|
59
|
+
dataSources: [
|
|
60
|
+
{ mapping: { apiVersion: '0.0.5' } },
|
|
61
|
+
{ mapping: { apiVersion: '0.0.6' } },
|
|
62
|
+
{ mapping: { apiVersion: '0.0.5' } },
|
|
63
|
+
],
|
|
64
|
+
}));
|
|
65
|
+
await expect((0, version_1.assertManifestApiVersion)(fakeManifestPath, minimumApiVersion)).resolves.toBe(undefined);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
describe('With dataSources and templates', () => {
|
|
69
|
+
describe('And the dataSources have a lower apiVersion', () => {
|
|
70
|
+
test('When all of the templates are less than minimum apiVersion', async () => {
|
|
71
|
+
// @ts-expect-error TODO: dont pollute the globals
|
|
72
|
+
loadManifestUtil.loadManifest = jest.fn().mockImplementation(() => Promise.resolve({
|
|
73
|
+
dataSources: [
|
|
74
|
+
{ mapping: { apiVersion: '0.0.5' } },
|
|
75
|
+
{ mapping: { apiVersion: '0.0.5' } },
|
|
76
|
+
{ mapping: { apiVersion: '0.0.3' } },
|
|
77
|
+
],
|
|
78
|
+
templates: [
|
|
79
|
+
{ mapping: { apiVersion: '0.0.1' } },
|
|
80
|
+
{ mapping: { apiVersion: '0.0.2' } },
|
|
81
|
+
{ mapping: { apiVersion: '0.0.3' } },
|
|
82
|
+
],
|
|
83
|
+
}));
|
|
84
|
+
await 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}'`));
|
|
85
|
+
});
|
|
86
|
+
test('When one of the templates is less than minimum apiVersion', async () => {
|
|
87
|
+
// @ts-expect-error TODO: dont pollute the globals
|
|
88
|
+
loadManifestUtil.loadManifest = jest.fn().mockImplementation(() => Promise.resolve({
|
|
89
|
+
dataSources: [
|
|
90
|
+
{ mapping: { apiVersion: '0.0.5' } },
|
|
91
|
+
{ mapping: { apiVersion: '0.0.5' } },
|
|
92
|
+
{ mapping: { apiVersion: '0.0.3' } },
|
|
93
|
+
],
|
|
94
|
+
templates: [
|
|
95
|
+
{ mapping: { apiVersion: '0.0.5' } },
|
|
96
|
+
{ mapping: { apiVersion: '0.0.2' } },
|
|
97
|
+
{ mapping: { apiVersion: '0.0.5' } },
|
|
98
|
+
],
|
|
99
|
+
}));
|
|
100
|
+
await 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}'`));
|
|
101
|
+
});
|
|
102
|
+
test('When none of the templates are less than minimum apiVersion', async () => {
|
|
103
|
+
// @ts-expect-error TODO: dont pollute the globals
|
|
104
|
+
loadManifestUtil.loadManifest = jest.fn().mockImplementation(() => Promise.resolve({
|
|
105
|
+
dataSources: [
|
|
106
|
+
{ mapping: { apiVersion: '0.0.5' } },
|
|
107
|
+
{ mapping: { apiVersion: '0.0.5' } },
|
|
108
|
+
{ mapping: { apiVersion: '0.0.3' } },
|
|
109
|
+
],
|
|
110
|
+
templates: [
|
|
111
|
+
{ mapping: { apiVersion: '0.0.5' } },
|
|
112
|
+
{ mapping: { apiVersion: '0.0.6' } },
|
|
113
|
+
{ mapping: { apiVersion: '0.0.5' } },
|
|
114
|
+
],
|
|
115
|
+
}));
|
|
116
|
+
await 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}'`));
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
describe('And the dataSources do NOT have a lower apiVersion', () => {
|
|
120
|
+
test('When all of the templates are less than minimum apiVersion', async () => {
|
|
121
|
+
// @ts-expect-error TODO: dont pollute the globals
|
|
122
|
+
loadManifestUtil.loadManifest = jest.fn().mockImplementation(() => Promise.resolve({
|
|
123
|
+
dataSources: [
|
|
124
|
+
{ mapping: { apiVersion: '0.0.5' } },
|
|
125
|
+
{ mapping: { apiVersion: '0.0.5' } },
|
|
126
|
+
{ mapping: { apiVersion: '0.0.6' } },
|
|
127
|
+
],
|
|
128
|
+
templates: [
|
|
129
|
+
{ mapping: { apiVersion: '0.0.1' } },
|
|
130
|
+
{ mapping: { apiVersion: '0.0.2' } },
|
|
131
|
+
{ mapping: { apiVersion: '0.0.3' } },
|
|
132
|
+
],
|
|
133
|
+
}));
|
|
134
|
+
await 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}'`));
|
|
135
|
+
});
|
|
136
|
+
test('When one of the templates is less than minimum apiVersion', async () => {
|
|
137
|
+
// @ts-expect-error TODO: dont pollute the globals
|
|
138
|
+
loadManifestUtil.loadManifest = jest.fn().mockImplementation(() => Promise.resolve({
|
|
139
|
+
dataSources: [
|
|
140
|
+
{ mapping: { apiVersion: '0.0.5' } },
|
|
141
|
+
{ mapping: { apiVersion: '0.0.5' } },
|
|
142
|
+
{ mapping: { apiVersion: '0.0.6' } },
|
|
143
|
+
],
|
|
144
|
+
templates: [
|
|
145
|
+
{ mapping: { apiVersion: '0.0.5' } },
|
|
146
|
+
{ mapping: { apiVersion: '0.0.2' } },
|
|
147
|
+
{ mapping: { apiVersion: '0.0.5' } },
|
|
148
|
+
],
|
|
149
|
+
}));
|
|
150
|
+
await 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}'`));
|
|
151
|
+
});
|
|
152
|
+
test('When none of the templates are less than minimum apiVersion', async () => {
|
|
153
|
+
// @ts-expect-error TODO: dont pollute the globals
|
|
154
|
+
loadManifestUtil.loadManifest = jest.fn().mockImplementation(() => Promise.resolve({
|
|
155
|
+
dataSources: [
|
|
156
|
+
{ mapping: { apiVersion: '0.0.5' } },
|
|
157
|
+
{ mapping: { apiVersion: '0.0.5' } },
|
|
158
|
+
{ mapping: { apiVersion: '0.0.6' } },
|
|
159
|
+
],
|
|
160
|
+
templates: [
|
|
161
|
+
{ mapping: { apiVersion: '0.0.5' } },
|
|
162
|
+
{ mapping: { apiVersion: '0.0.6' } },
|
|
163
|
+
{ mapping: { apiVersion: '0.0.5' } },
|
|
164
|
+
],
|
|
165
|
+
}));
|
|
166
|
+
await expect((0, version_1.assertManifestApiVersion)(fakeManifestPath, minimumApiVersion)).resolves.toBe(undefined);
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
describe('assertGraphTsVersion', () => {
|
|
172
|
+
const fakeNodeModulesDir = 'fake/path/to/node/modules';
|
|
173
|
+
const minimumGraphTsVersion = '0.22.0';
|
|
174
|
+
test("When the installed graph-ts version is less than what's supported", async () => {
|
|
175
|
+
// @ts-expect-error TODO: dont pollute the globals
|
|
176
|
+
graphTsUtil.getGraphTsVersion = jest.fn().mockImplementation(() => Promise.resolve('0.19.0'));
|
|
177
|
+
await 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}
|
|
178
|
+
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`));
|
|
179
|
+
});
|
|
180
|
+
test('When the installed graph-ts version is a supported one', async () => {
|
|
181
|
+
// @ts-expect-error TODO: dont pollute the globals
|
|
182
|
+
graphTsUtil.getGraphTsVersion = jest.fn().mockImplementation(() => Promise.resolve('0.22.0'));
|
|
183
|
+
await expect((0, version_1.assertGraphTsVersion)(fakeNodeModulesDir, minimumGraphTsVersion)).resolves.toBe(undefined);
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
});
|
|
@@ -0,0 +1,187 @@
|
|
|
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
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
30
|
+
const immutable_1 = __importDefault(require("immutable"));
|
|
31
|
+
const abi_1 = require("../command-helpers/abi");
|
|
32
|
+
const DataSourcesExtractor = __importStar(require("../command-helpers/data-sources"));
|
|
33
|
+
const gluegun_1 = require("../command-helpers/gluegun");
|
|
34
|
+
const network_1 = require("../command-helpers/network");
|
|
35
|
+
const scaffold_1 = require("../command-helpers/scaffold");
|
|
36
|
+
const spinner_1 = require("../command-helpers/spinner");
|
|
37
|
+
const protocols_1 = __importDefault(require("../protocols"));
|
|
38
|
+
const abi_2 = __importDefault(require("../protocols/ethereum/abi"));
|
|
39
|
+
const subgraph_1 = __importDefault(require("../subgraph"));
|
|
40
|
+
const HELP = `
|
|
41
|
+
${chalk_1.default.bold('graph add')} <address> [<subgraph-manifest default: "./subgraph.yaml">]
|
|
42
|
+
|
|
43
|
+
${chalk_1.default.dim('Options:')}
|
|
44
|
+
|
|
45
|
+
--abi <path> Path to the contract ABI (default: download from Etherscan)
|
|
46
|
+
--contract-name Name of the contract (default: Contract)
|
|
47
|
+
--merge-entities Whether to merge entities with the same name (default: false)
|
|
48
|
+
--network-file <path> Networks config file path (default: "./networks.json")
|
|
49
|
+
-h, --help Show usage information
|
|
50
|
+
`;
|
|
51
|
+
exports.default = {
|
|
52
|
+
description: 'Adds a new datasource to a subgraph',
|
|
53
|
+
run: async (toolbox) => {
|
|
54
|
+
// Obtain tools
|
|
55
|
+
const { print, system } = toolbox;
|
|
56
|
+
// Read CLI parameters
|
|
57
|
+
let { abi, contractName, h, help, mergeEntities, networkFile } = toolbox.parameters.options;
|
|
58
|
+
contractName ||= 'Contract';
|
|
59
|
+
try {
|
|
60
|
+
(0, gluegun_1.fixParameters)(toolbox.parameters, {
|
|
61
|
+
h,
|
|
62
|
+
help,
|
|
63
|
+
mergeEntities,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
67
|
+
print.error(e.message);
|
|
68
|
+
process.exitCode = 1;
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const address = toolbox.parameters.first || toolbox.parameters.array?.[0];
|
|
72
|
+
const manifestPath = toolbox.parameters.second || toolbox.parameters.array?.[1] || './subgraph.yaml';
|
|
73
|
+
// Show help text if requested
|
|
74
|
+
if (help || h) {
|
|
75
|
+
print.info(HELP);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
// Validate the address
|
|
79
|
+
if (!address) {
|
|
80
|
+
print.error('No contract address provided');
|
|
81
|
+
process.exitCode = 1;
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const dataSourcesAndTemplates = await DataSourcesExtractor.fromFilePath(manifestPath);
|
|
85
|
+
const protocol = protocols_1.default.fromDataSources(dataSourcesAndTemplates);
|
|
86
|
+
const manifest = await subgraph_1.default.load(manifestPath, { protocol });
|
|
87
|
+
const network = manifest.result.getIn(['dataSources', 0, 'network']);
|
|
88
|
+
const result = manifest.result.asMutable();
|
|
89
|
+
const entities = getEntities(manifest);
|
|
90
|
+
const contractNames = getContractNames(manifest);
|
|
91
|
+
if (contractNames.includes(contractName)) {
|
|
92
|
+
print.error(`Datasource or template with name ${contractName} already exists, please choose a different name`);
|
|
93
|
+
process.exitCode = 1;
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
let ethabi = null;
|
|
97
|
+
if (abi) {
|
|
98
|
+
ethabi = abi_2.default.load(contractName, abi);
|
|
99
|
+
}
|
|
100
|
+
else if (network === 'poa-core') {
|
|
101
|
+
ethabi = await (0, abi_1.loadAbiFromBlockScout)(abi_2.default, network, address);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
ethabi = await (0, abi_1.loadAbiFromEtherscan)(abi_2.default, network, address);
|
|
105
|
+
}
|
|
106
|
+
const { collisionEntities, onlyCollisions, abiData } = updateEventNamesOnCollision(toolbox, ethabi, entities, contractName, mergeEntities);
|
|
107
|
+
ethabi.data = abiData;
|
|
108
|
+
await (0, scaffold_1.writeABI)(ethabi, contractName);
|
|
109
|
+
await (0, scaffold_1.writeSchema)(ethabi, protocol, result.getIn(['schema', 'file']), collisionEntities);
|
|
110
|
+
await (0, scaffold_1.writeMapping)(ethabi, protocol, contractName, collisionEntities);
|
|
111
|
+
await (0, scaffold_1.writeTestsFiles)(ethabi, protocol, contractName);
|
|
112
|
+
const dataSources = result.get('dataSources');
|
|
113
|
+
const dataSource = await (0, scaffold_1.generateDataSource)(protocol, contractName, network, address, ethabi);
|
|
114
|
+
// Handle the collisions edge case by copying another data source yaml data
|
|
115
|
+
if (mergeEntities && onlyCollisions) {
|
|
116
|
+
const firstDataSource = dataSources.get(0);
|
|
117
|
+
const source = dataSource.get('source');
|
|
118
|
+
const mapping = firstDataSource.get('mapping').asMutable();
|
|
119
|
+
// Save the address of the new data source
|
|
120
|
+
source.abi = firstDataSource.get('source').get('abi');
|
|
121
|
+
dataSource.set('mapping', mapping);
|
|
122
|
+
dataSource.set('source', source);
|
|
123
|
+
}
|
|
124
|
+
result.set('dataSources', dataSources.push(dataSource));
|
|
125
|
+
await subgraph_1.default.write(result, manifestPath);
|
|
126
|
+
// Update networks.json
|
|
127
|
+
const networksFile = networkFile || './networks.json';
|
|
128
|
+
await (0, network_1.updateNetworksFile)(toolbox, network, contractName, address, networksFile);
|
|
129
|
+
// Detect Yarn and/or NPM
|
|
130
|
+
const yarn = system.which('yarn');
|
|
131
|
+
const npm = system.which('npm');
|
|
132
|
+
if (!yarn && !npm) {
|
|
133
|
+
print.error(`Neither Yarn nor NPM were found on your system. Please install one of them.`);
|
|
134
|
+
process.exitCode = 1;
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
await (0, spinner_1.withSpinner)('Running codegen', 'Failed to run codegen', 'Warning during codegen', async () => {
|
|
138
|
+
await system.run(yarn ? 'yarn codegen' : 'npm run codegen');
|
|
139
|
+
});
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
const getEntities = (manifest) => {
|
|
143
|
+
const dataSources = manifest.result.get('dataSources', immutable_1.default.List());
|
|
144
|
+
const templates = manifest.result.get('templates', immutable_1.default.List());
|
|
145
|
+
return dataSources
|
|
146
|
+
.concat(templates)
|
|
147
|
+
.map((dataSource) => dataSource.getIn(['mapping', 'entities']))
|
|
148
|
+
.flatten();
|
|
149
|
+
};
|
|
150
|
+
const getContractNames = (manifest) => {
|
|
151
|
+
const dataSources = manifest.result.get('dataSources', immutable_1.default.List());
|
|
152
|
+
const templates = manifest.result.get('templates', immutable_1.default.List());
|
|
153
|
+
return dataSources.concat(templates).map((dataSource) => dataSource.get('name'));
|
|
154
|
+
};
|
|
155
|
+
const updateEventNamesOnCollision = (toolbox, ethabi, entities, contractName, mergeEntities) => {
|
|
156
|
+
let abiData = ethabi.data;
|
|
157
|
+
const { print } = toolbox;
|
|
158
|
+
const collisionEntities = [];
|
|
159
|
+
let onlyCollisions = true;
|
|
160
|
+
for (let i = 0; i < abiData.size; i++) {
|
|
161
|
+
const dataRow = abiData.get(i).asMutable();
|
|
162
|
+
if (dataRow.get('type') === 'event') {
|
|
163
|
+
if (entities.includes(dataRow.get('name'))) {
|
|
164
|
+
if (entities.includes(`${contractName}${dataRow.get('name')}`)) {
|
|
165
|
+
print.error(`Contract name ('${contractName}')
|
|
166
|
+
+ event name ('${dataRow.get('name')}') entity already exists.`);
|
|
167
|
+
process.exitCode = 1;
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
if (mergeEntities) {
|
|
171
|
+
collisionEntities.push(dataRow.get('name'));
|
|
172
|
+
abiData = abiData.asImmutable().delete(i); // needs to be immutable when deleting, yes you read that right - https://github.com/immutable-js/immutable-js/issues/1901
|
|
173
|
+
i--; // deletion also shifts values to the left
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
dataRow.set('name', `${contractName}${dataRow.get('name')}`);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
onlyCollisions = false;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
abiData = abiData.asMutable().set(i, dataRow);
|
|
185
|
+
}
|
|
186
|
+
return { abiData, collisionEntities, onlyCollisions };
|
|
187
|
+
};
|
|
@@ -0,0 +1,122 @@
|
|
|
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
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
7
|
+
const auth_1 = require("../command-helpers/auth");
|
|
8
|
+
const gluegun_1 = require("../command-helpers/gluegun");
|
|
9
|
+
const node_1 = require("../command-helpers/node");
|
|
10
|
+
const HELP = `
|
|
11
|
+
${chalk_1.default.bold('graph auth')} [options] ${chalk_1.default.bold('<node>')} ${chalk_1.default.bold('<deploy-key>')}
|
|
12
|
+
|
|
13
|
+
${chalk_1.default.dim('Options:')}
|
|
14
|
+
|
|
15
|
+
--product <subgraph-studio|hosted-service>
|
|
16
|
+
Selects the product for which to authenticate
|
|
17
|
+
--studio Shortcut for --product subgraph-studio
|
|
18
|
+
-h, --help Show usage information
|
|
19
|
+
`;
|
|
20
|
+
const processForm = async (toolbox, { product, studio, node, deployKey }) => {
|
|
21
|
+
const questions = [
|
|
22
|
+
{
|
|
23
|
+
type: 'select',
|
|
24
|
+
name: 'product',
|
|
25
|
+
message: 'Product for which to initialize',
|
|
26
|
+
choices: ['subgraph-studio', 'hosted-service'],
|
|
27
|
+
skip: product === 'subgraph-studio' ||
|
|
28
|
+
product === 'hosted-service' ||
|
|
29
|
+
studio !== undefined ||
|
|
30
|
+
node !== undefined,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
type: 'password',
|
|
34
|
+
name: 'deployKey',
|
|
35
|
+
message: 'Deploy key',
|
|
36
|
+
skip: deployKey !== undefined,
|
|
37
|
+
},
|
|
38
|
+
];
|
|
39
|
+
try {
|
|
40
|
+
const answers = await toolbox.prompt.ask(questions);
|
|
41
|
+
return answers;
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
exports.default = {
|
|
48
|
+
description: 'Sets the deploy key to use when deploying to a Graph node',
|
|
49
|
+
run: async (toolbox) => {
|
|
50
|
+
// Obtain tools
|
|
51
|
+
const { print } = toolbox;
|
|
52
|
+
// Read CLI parameters
|
|
53
|
+
const { product, studio, h, help } = toolbox.parameters.options;
|
|
54
|
+
// Show help text if requested
|
|
55
|
+
if (help || h) {
|
|
56
|
+
print.info(HELP);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
let firstParam, secondParam;
|
|
60
|
+
try {
|
|
61
|
+
[firstParam, secondParam] = (0, gluegun_1.fixParameters)(toolbox.parameters, {
|
|
62
|
+
h,
|
|
63
|
+
help,
|
|
64
|
+
studio,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
catch (e) {
|
|
68
|
+
print.error(e.message);
|
|
69
|
+
process.exitCode = 1;
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
// if user specifies --product or --studio then deployKey is the first parameter
|
|
73
|
+
let node;
|
|
74
|
+
let deployKey;
|
|
75
|
+
if (product || studio) {
|
|
76
|
+
({ node } = (0, node_1.chooseNodeUrl)({ product, studio, node }));
|
|
77
|
+
deployKey = firstParam;
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
node = firstParam;
|
|
81
|
+
deployKey = secondParam;
|
|
82
|
+
}
|
|
83
|
+
if (!node || !deployKey) {
|
|
84
|
+
const inputs = await processForm(toolbox, {
|
|
85
|
+
product,
|
|
86
|
+
studio,
|
|
87
|
+
node,
|
|
88
|
+
deployKey,
|
|
89
|
+
});
|
|
90
|
+
if (inputs === undefined) {
|
|
91
|
+
process.exit(1);
|
|
92
|
+
}
|
|
93
|
+
if (!node) {
|
|
94
|
+
({ node } = (0, node_1.chooseNodeUrl)({
|
|
95
|
+
product: inputs.product,
|
|
96
|
+
studio,
|
|
97
|
+
node,
|
|
98
|
+
}));
|
|
99
|
+
}
|
|
100
|
+
deployKey ||= inputs.deployKey;
|
|
101
|
+
}
|
|
102
|
+
if (!deployKey) {
|
|
103
|
+
print.error(`No deploy key provided`);
|
|
104
|
+
print.info(HELP);
|
|
105
|
+
process.exitCode = 1;
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (deployKey.length > 200) {
|
|
109
|
+
print.error(`Deploy key must not exceed 200 characters`);
|
|
110
|
+
process.exitCode = 1;
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
try {
|
|
114
|
+
await (0, auth_1.saveDeployKey)(node, deployKey);
|
|
115
|
+
print.success(`Deploy key set for ${node}`);
|
|
116
|
+
}
|
|
117
|
+
catch (e) {
|
|
118
|
+
print.error(e);
|
|
119
|
+
process.exitCode = 1;
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
};
|
|
@@ -0,0 +1,136 @@
|
|
|
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
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
30
|
+
const compiler_1 = require("../command-helpers/compiler");
|
|
31
|
+
const DataSourcesExtractor = __importStar(require("../command-helpers/data-sources"));
|
|
32
|
+
const gluegun_1 = require("../command-helpers/gluegun");
|
|
33
|
+
const network_1 = require("../command-helpers/network");
|
|
34
|
+
const debug_1 = __importDefault(require("../debug"));
|
|
35
|
+
const protocols_1 = __importDefault(require("../protocols"));
|
|
36
|
+
const buildDebug = (0, debug_1.default)('graph-cli:build');
|
|
37
|
+
const HELP = `
|
|
38
|
+
${chalk_1.default.bold('graph build')} [options] ${chalk_1.default.bold('[<subgraph-manifest>]')}
|
|
39
|
+
|
|
40
|
+
Options:
|
|
41
|
+
|
|
42
|
+
-h, --help Show usage information
|
|
43
|
+
-i, --ipfs <node> Upload build results to an IPFS node
|
|
44
|
+
-o, --output-dir <path> Output directory for build results (default: build/)
|
|
45
|
+
-t, --output-format <format> Output format for mappings (wasm, wast) (default: wasm)
|
|
46
|
+
--skip-migrations Skip subgraph migrations (default: false)
|
|
47
|
+
-w, --watch Regenerate types when subgraph files change (default: false)
|
|
48
|
+
--network <name> Network configuration to use from the networks config file
|
|
49
|
+
--network-file <path> Networks config file path (default: "./networks.json")
|
|
50
|
+
`;
|
|
51
|
+
exports.default = {
|
|
52
|
+
description: 'Builds a subgraph and (optionally) uploads it to IPFS',
|
|
53
|
+
run: async (toolbox) => {
|
|
54
|
+
// Obtain tools
|
|
55
|
+
const { filesystem, print } = toolbox;
|
|
56
|
+
// Parse CLI parameters
|
|
57
|
+
let { i, h, help, ipfs, o, outputDir, outputFormat, skipMigrations, t, w, watch, network, networkFile, } = toolbox.parameters.options;
|
|
58
|
+
// Support both short and long option variants
|
|
59
|
+
help ||= h;
|
|
60
|
+
ipfs ||= i;
|
|
61
|
+
outputDir ||= o;
|
|
62
|
+
outputFormat ||= t;
|
|
63
|
+
watch ||= w;
|
|
64
|
+
let manifest;
|
|
65
|
+
try {
|
|
66
|
+
[manifest] = (0, gluegun_1.fixParameters)(toolbox.parameters, {
|
|
67
|
+
h,
|
|
68
|
+
help,
|
|
69
|
+
w,
|
|
70
|
+
watch,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
catch (e) {
|
|
74
|
+
print.error(e.message);
|
|
75
|
+
process.exitCode = 1;
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
// Fall back to default values for options / parameters
|
|
79
|
+
outputFormat = outputFormat && ['wasm', 'wast'].includes(outputFormat) ? outputFormat : 'wasm';
|
|
80
|
+
outputDir = outputDir && outputDir !== '' ? outputDir : filesystem.path('build');
|
|
81
|
+
manifest =
|
|
82
|
+
manifest !== undefined && manifest !== '' ? manifest : filesystem.resolve('subgraph.yaml');
|
|
83
|
+
networkFile =
|
|
84
|
+
networkFile !== undefined && networkFile !== ''
|
|
85
|
+
? networkFile
|
|
86
|
+
: filesystem.resolve('networks.json');
|
|
87
|
+
// Show help text if requested
|
|
88
|
+
if (help) {
|
|
89
|
+
print.info(HELP);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
let protocol;
|
|
93
|
+
try {
|
|
94
|
+
const dataSourcesAndTemplates = await DataSourcesExtractor.fromFilePath(manifest);
|
|
95
|
+
protocol = protocols_1.default.fromDataSources(dataSourcesAndTemplates);
|
|
96
|
+
}
|
|
97
|
+
catch (e) {
|
|
98
|
+
print.error(e.message);
|
|
99
|
+
process.exitCode = 1;
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
buildDebug('Detected protocol "%s" (%o)', protocol.name, protocol);
|
|
103
|
+
if (network && filesystem.exists(networkFile) !== 'file') {
|
|
104
|
+
print.error(`Network file '${networkFile}' does not exists or is not a file!`);
|
|
105
|
+
process.exitCode = 1;
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (network) {
|
|
109
|
+
const identifierName = protocol.getContract().identifierName();
|
|
110
|
+
await (0, network_1.updateSubgraphNetwork)(toolbox, manifest, network, networkFile, identifierName);
|
|
111
|
+
}
|
|
112
|
+
const compiler = (0, compiler_1.createCompiler)(manifest, {
|
|
113
|
+
ipfs,
|
|
114
|
+
outputDir,
|
|
115
|
+
outputFormat,
|
|
116
|
+
skipMigrations,
|
|
117
|
+
protocol,
|
|
118
|
+
});
|
|
119
|
+
// Exit with an error code if the compiler couldn't be created
|
|
120
|
+
if (!compiler) {
|
|
121
|
+
process.exitCode = 1;
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
// Watch subgraph files for changes or additions, trigger
|
|
125
|
+
// compile (if watch argument specified)
|
|
126
|
+
if (watch) {
|
|
127
|
+
await compiler.watchAndCompile();
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
const result = await compiler.compile();
|
|
131
|
+
if (result === false) {
|
|
132
|
+
process.exitCode = 1;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
};
|