@graphprotocol/graph-cli 0.63.0-alpha-20231207223433-7216e44 → 0.63.0
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 +17 -1
- package/dist/compiler/index.d.ts +1 -0
- package/dist/compiler/index.js +43 -1
- package/oclif.manifest.json +1 -1
- package/package.json +8 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @graphprotocol/graph-cli
|
|
2
2
|
|
|
3
|
-
## 0.63.0
|
|
3
|
+
## 0.63.0
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
@@ -12,6 +12,10 @@
|
|
|
12
12
|
[`95eb9d0`](https://github.com/graphprotocol/graph-tooling/commit/95eb9d0244a99fdfb7a4750963c1a982d024dd87)
|
|
13
13
|
Thanks [@mangas](https://github.com/mangas)! - substreams based triggers support
|
|
14
14
|
|
|
15
|
+
- [#1535](https://github.com/graphprotocol/graph-tooling/pull/1535)
|
|
16
|
+
[`7d5c818`](https://github.com/graphprotocol/graph-tooling/commit/7d5c818fc832cf824421957b02ff3198bcf25a22)
|
|
17
|
+
Thanks [@saihaj](https://github.com/saihaj)! - add validation for handlers from subgraph manifest
|
|
18
|
+
|
|
15
19
|
- [#1524](https://github.com/graphprotocol/graph-tooling/pull/1524)
|
|
16
20
|
[`086a2da`](https://github.com/graphprotocol/graph-tooling/commit/086a2da03a4388277b69b6db541a0673dc9505bb)
|
|
17
21
|
Thanks [@pedropregueiro](https://github.com/pedropregueiro)! - Add support for M3 apple silicon
|
|
@@ -19,6 +23,18 @@
|
|
|
19
23
|
|
|
20
24
|
### Patch Changes
|
|
21
25
|
|
|
26
|
+
- [#1535](https://github.com/graphprotocol/graph-tooling/pull/1535)
|
|
27
|
+
[`7d5c818`](https://github.com/graphprotocol/graph-tooling/commit/7d5c818fc832cf824421957b02ff3198bcf25a22)
|
|
28
|
+
Thanks [@saihaj](https://github.com/saihaj)! - dependencies updates:
|
|
29
|
+
|
|
30
|
+
- Added dependency [`@babel/core@^7.20.5` ↗︎](https://www.npmjs.com/package/@babel/core/v/7.20.5)
|
|
31
|
+
(to `dependencies`)
|
|
32
|
+
- Added dependency
|
|
33
|
+
[`@babel/preset-typescript@^7.18.6` ↗︎](https://www.npmjs.com/package/@babel/preset-typescript/v/7.18.6)
|
|
34
|
+
(to `dependencies`)
|
|
35
|
+
- Added dependency [`memoizee@^0.4.15` ↗︎](https://www.npmjs.com/package/memoizee/v/0.4.15) (to
|
|
36
|
+
`dependencies`)
|
|
37
|
+
|
|
22
38
|
- [#1521](https://github.com/graphprotocol/graph-tooling/pull/1521)
|
|
23
39
|
[`3571a57`](https://github.com/graphprotocol/graph-tooling/commit/3571a571b2a094f41932e7cbc91b605c7ba0962c)
|
|
24
40
|
Thanks [@saihaj](https://github.com/saihaj)! - remove studio network validation checks
|
package/dist/compiler/index.d.ts
CHANGED
|
@@ -59,6 +59,7 @@ export default class Compiler {
|
|
|
59
59
|
_compileDataSourceMapping(protocol: Protocol, dataSource: immutable.Map<any, any>, mappingPath: string, compiledFiles: Map<any, any>, spinner: Spinner, validate?: boolean): any;
|
|
60
60
|
_compileTemplateMapping(template: immutable.Collection<any, any>, mappingPath: string, compiledFiles: Map<any, any>, spinner: Spinner): any;
|
|
61
61
|
_validateMappingContent(filePath: string): void;
|
|
62
|
+
_validateHandler(filePath: string, handlerName: string): void;
|
|
62
63
|
writeSubgraphToOutputDirectory(protocol: Protocol, subgraph: immutable.Map<any, any>): Promise<any>;
|
|
63
64
|
uploadSubgraphToIPFS(subgraph: immutable.Map<any, any>): Promise<any>;
|
|
64
65
|
_uploadFileToIPFS(maybeRelativeFile: string, uploadedFiles: Map<any, any>, spinner: Spinner): Promise<immutable.Collection<unknown, unknown>>;
|
package/dist/compiler/index.js
CHANGED
|
@@ -33,6 +33,8 @@ const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
|
33
33
|
const toolbox = __importStar(require("gluegun"));
|
|
34
34
|
const immutable_1 = __importDefault(require("immutable"));
|
|
35
35
|
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
36
|
+
const memoizee_1 = __importDefault(require("memoizee"));
|
|
37
|
+
const core_1 = require("@babel/core");
|
|
36
38
|
const spinner_1 = require("../command-helpers/spinner");
|
|
37
39
|
const debug_1 = __importDefault(require("../debug"));
|
|
38
40
|
const migrations_1 = require("../migrations");
|
|
@@ -40,6 +42,16 @@ const subgraph_1 = __importDefault(require("../subgraph"));
|
|
|
40
42
|
const watcher_1 = __importDefault(require("../watcher"));
|
|
41
43
|
const asc = __importStar(require("./asc"));
|
|
42
44
|
const compilerDebug = (0, debug_1.default)('graph-cli:compiler');
|
|
45
|
+
/** memoize the reading of the file so we don't have to read it every time */
|
|
46
|
+
const readFile = (0, memoizee_1.default)((filename) => fs_extra_1.default.readFileSync(filename, 'utf-8'));
|
|
47
|
+
/** Memoized parser for Babel, so we can simply just read from cache */
|
|
48
|
+
const babelAst = (0, memoizee_1.default)((filename) => {
|
|
49
|
+
const data = readFile(filename);
|
|
50
|
+
return (0, core_1.parseSync)(data, {
|
|
51
|
+
presets: ['@babel/preset-typescript'],
|
|
52
|
+
filename,
|
|
53
|
+
});
|
|
54
|
+
});
|
|
43
55
|
class Compiler {
|
|
44
56
|
constructor(options) {
|
|
45
57
|
this.options = options;
|
|
@@ -254,6 +266,12 @@ class Compiler {
|
|
|
254
266
|
const absoluteMappingPath = path_1.default.resolve(baseDir, mappingPath);
|
|
255
267
|
const inputFile = path_1.default.relative(baseDir, absoluteMappingPath);
|
|
256
268
|
this._validateMappingContent(absoluteMappingPath);
|
|
269
|
+
const eventHandlers = dataSource.getIn(['mapping', 'eventHandlers']);
|
|
270
|
+
// TODO: improve the types
|
|
271
|
+
for (const eventHandler of eventHandlers.toJS()) {
|
|
272
|
+
compilerDebug('Validating Event Handler %s', eventHandler.handler);
|
|
273
|
+
this._validateHandler(absoluteMappingPath, eventHandler.handler);
|
|
274
|
+
}
|
|
257
275
|
// If the file has already been compiled elsewhere, just use that output
|
|
258
276
|
// file and return early
|
|
259
277
|
const inputCacheKey = this.cacheKeyForFile(absoluteMappingPath);
|
|
@@ -304,6 +322,12 @@ class Compiler {
|
|
|
304
322
|
const absoluteMappingPath = path_1.default.resolve(baseDir, mappingPath);
|
|
305
323
|
const inputFile = path_1.default.relative(baseDir, absoluteMappingPath);
|
|
306
324
|
this._validateMappingContent(absoluteMappingPath);
|
|
325
|
+
const eventHandlers = templateName.getIn(['mapping', 'eventHandlers']);
|
|
326
|
+
// TODO: improve the types
|
|
327
|
+
for (const eventHandler of eventHandlers.toJS()) {
|
|
328
|
+
compilerDebug('Validating Template handler %s', eventHandler.handler);
|
|
329
|
+
this._validateHandler(absoluteMappingPath, eventHandler.handler);
|
|
330
|
+
}
|
|
307
331
|
// If the file has already been compiled elsewhere, just use that output
|
|
308
332
|
// file and return early
|
|
309
333
|
const inputCacheKey = this.cacheKeyForFile(absoluteMappingPath);
|
|
@@ -339,7 +363,7 @@ class Compiler {
|
|
|
339
363
|
}
|
|
340
364
|
}
|
|
341
365
|
_validateMappingContent(filePath) {
|
|
342
|
-
const data =
|
|
366
|
+
const data = readFile(filePath);
|
|
343
367
|
if (this.blockIpfsMethods && (data.includes('ipfs.cat') || data.includes('ipfs.map'))) {
|
|
344
368
|
throw Error(`
|
|
345
369
|
Subgraph Studio does not support mappings with ipfs methods.
|
|
@@ -348,6 +372,24 @@ class Compiler {
|
|
|
348
372
|
`);
|
|
349
373
|
}
|
|
350
374
|
}
|
|
375
|
+
_validateHandler(filePath, handlerName) {
|
|
376
|
+
const baselAst = babelAst(filePath);
|
|
377
|
+
const body = baselAst?.program.body;
|
|
378
|
+
if (!body) {
|
|
379
|
+
throw Error(`Could not parse ${filePath}`);
|
|
380
|
+
}
|
|
381
|
+
const exportedFunctionNames = body
|
|
382
|
+
.map(statement => {
|
|
383
|
+
if (statement.type === 'ExportNamedDeclaration' &&
|
|
384
|
+
statement?.declaration?.type === 'FunctionDeclaration') {
|
|
385
|
+
return statement.declaration.id?.name;
|
|
386
|
+
}
|
|
387
|
+
})
|
|
388
|
+
.filter(Boolean);
|
|
389
|
+
if (!exportedFunctionNames.includes(handlerName)) {
|
|
390
|
+
throw Error(`Could not find handler '${handlerName}' in ${filePath}`);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
351
393
|
async writeSubgraphToOutputDirectory(protocol, subgraph) {
|
|
352
394
|
const displayDir = `${this.displayPath(this.options.outputDir)}${toolbox.filesystem.separator}`;
|
|
353
395
|
// ensure that the output directory exists
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphprotocol/graph-cli",
|
|
3
|
-
"version": "0.63.0
|
|
3
|
+
"version": "0.63.0",
|
|
4
4
|
"description": "CLI for building for and deploying to The Graph",
|
|
5
5
|
"license": "(Apache-2.0 OR MIT)",
|
|
6
6
|
"engines": {
|
|
@@ -19,6 +19,8 @@
|
|
|
19
19
|
"!dist/*.tar.gz"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
+
"@babel/core": "^7.20.5",
|
|
23
|
+
"@babel/preset-typescript": "^7.18.6",
|
|
22
24
|
"@float-capital/float-subgraph-uncrashable": "^0.0.0-alpha.4",
|
|
23
25
|
"@oclif/core": "2.8.6",
|
|
24
26
|
"@oclif/plugin-autocomplete": "^2.3.6",
|
|
@@ -39,6 +41,7 @@
|
|
|
39
41
|
"ipfs-http-client": "55.0.0",
|
|
40
42
|
"jayson": "4.0.0",
|
|
41
43
|
"js-yaml": "3.14.1",
|
|
44
|
+
"memoizee": "^0.4.15",
|
|
42
45
|
"prettier": "1.19.1",
|
|
43
46
|
"request": "2.88.2",
|
|
44
47
|
"semver": "7.4.0",
|
|
@@ -49,10 +52,12 @@
|
|
|
49
52
|
"yaml": "1.10.2"
|
|
50
53
|
},
|
|
51
54
|
"devDependencies": {
|
|
55
|
+
"@types/babel__core": "^7.20.5",
|
|
52
56
|
"@types/debug": "^4.1.7",
|
|
53
57
|
"@types/fs-extra": "^9.0.13",
|
|
54
58
|
"@types/jest": "^29.0.0",
|
|
55
59
|
"@types/js-yaml": "^3.12.7",
|
|
60
|
+
"@types/memoizee": "^0.4.11",
|
|
56
61
|
"@types/semver": "^7.3.13",
|
|
57
62
|
"@types/which": "^2.0.1",
|
|
58
63
|
"copyfiles": "^2.4.1",
|
|
@@ -61,8 +66,7 @@
|
|
|
61
66
|
"spawn-command": "0.0.2-1",
|
|
62
67
|
"strip-ansi": "6.0.1",
|
|
63
68
|
"tern": "0.24.3",
|
|
64
|
-
"typescript": "^5.0.0"
|
|
65
|
-
"vitest": "^1.0.2"
|
|
69
|
+
"typescript": "^5.0.0"
|
|
66
70
|
},
|
|
67
71
|
"publishConfig": {
|
|
68
72
|
"access": "public"
|
|
@@ -88,7 +92,6 @@
|
|
|
88
92
|
"test:add": "jest tests/cli/add.test.ts --verbose",
|
|
89
93
|
"test:init": "jest tests/cli/init.test.ts --verbose",
|
|
90
94
|
"test:validation": "jest tests/cli/validation.test.ts --verbose",
|
|
91
|
-
"type-check": "tsc --noEmit"
|
|
92
|
-
"vitest:validation": "vitest tests/cli/validation.test.ts"
|
|
95
|
+
"type-check": "tsc --noEmit"
|
|
93
96
|
}
|
|
94
97
|
}
|