@graphprotocol/graph-cli 0.45.0-alpha-20230404134925-bfd3b8e → 0.45.0-alpha-20230404223012-053932b
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @graphprotocol/graph-cli
|
|
2
2
|
|
|
3
|
-
## 0.45.0-alpha-
|
|
3
|
+
## 0.45.0-alpha-20230404223012-053932b
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
@@ -9,6 +9,11 @@
|
|
|
9
9
|
Thanks [@saihaj](https://github.com/saihaj)! - When the contract has an `id` event, the CLI
|
|
10
10
|
renames the `id` entity to `{contractName}_id` and map it to `{contractName}_id` in the mapping.
|
|
11
11
|
|
|
12
|
+
- [#1258](https://github.com/graphprotocol/graph-tooling/pull/1258)
|
|
13
|
+
[`053932b`](https://github.com/graphprotocol/graph-tooling/commit/053932bfad78e583867d9ef9c2f89b7cff1005e2)
|
|
14
|
+
Thanks [@saihaj](https://github.com/saihaj)! - validate existence for handlers specified in
|
|
15
|
+
manifest during build
|
|
16
|
+
|
|
12
17
|
- [#1209](https://github.com/graphprotocol/graph-tooling/pull/1209)
|
|
13
18
|
[`f26398e`](https://github.com/graphprotocol/graph-tooling/commit/f26398e054c556f414a1b45e92b7e4007a9b5a79)
|
|
14
19
|
Thanks [@kalloc](https://github.com/kalloc)! - Support `ts` typing in tests folder
|
|
@@ -110,6 +115,12 @@
|
|
|
110
115
|
- Updated dependency [`glob@9.3.4` ↗︎](https://www.npmjs.com/package/glob/v/9.3.4) (from `7.1.6`,
|
|
111
116
|
in `dependencies`)
|
|
112
117
|
|
|
118
|
+
- [#1246](https://github.com/graphprotocol/graph-tooling/pull/1246)
|
|
119
|
+
[`8e1409f`](https://github.com/graphprotocol/graph-tooling/commit/8e1409fbd04fa9e34fbc7d49160d9888ef74aebb)
|
|
120
|
+
Thanks [@dimitrovmaksim](https://github.com/dimitrovmaksim)! - Fixes `graph add` overwriting the
|
|
121
|
+
event names in `subgraph.yaml` and the ABI file when existing contracts have events with the same
|
|
122
|
+
name.
|
|
123
|
+
|
|
113
124
|
- [#1207](https://github.com/graphprotocol/graph-tooling/pull/1207)
|
|
114
125
|
[`ad275b3`](https://github.com/graphprotocol/graph-tooling/commit/ad275b31e635dab03cfefda00617ef9f612b01c0)
|
|
115
126
|
Thanks [@saihaj](https://github.com/saihaj)! - bring back short hand for version and help
|
package/dist/commands/add.js
CHANGED
|
@@ -69,9 +69,9 @@ class AddCommand extends core_1.Command {
|
|
|
69
69
|
// If we can't get the start block, we'll just leave it out of the manifest
|
|
70
70
|
// TODO: Ask the user for the start block
|
|
71
71
|
}
|
|
72
|
+
await (0, scaffold_1.writeABI)(ethabi, contractName);
|
|
72
73
|
const { collisionEntities, onlyCollisions, abiData } = updateEventNamesOnCollision(ethabi, entities, contractName, mergeEntities);
|
|
73
74
|
ethabi.data = abiData;
|
|
74
|
-
await (0, scaffold_1.writeABI)(ethabi, contractName);
|
|
75
75
|
await (0, scaffold_1.writeSchema)(ethabi, protocol, result.getIn(['schema', 'file']), collisionEntities, contractName);
|
|
76
76
|
await (0, scaffold_1.writeMapping)(ethabi, protocol, contractName, collisionEntities);
|
|
77
77
|
await (0, scaffold_1.writeTestsFiles)(ethabi, protocol, contractName);
|
|
@@ -168,7 +168,7 @@ const updateEventNamesOnCollision = (ethabi, entities, contractName, mergeEntiti
|
|
|
168
168
|
continue;
|
|
169
169
|
}
|
|
170
170
|
else {
|
|
171
|
-
dataRow.set('
|
|
171
|
+
dataRow.set('collision', true);
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
174
|
else {
|
package/dist/compiler/index.js
CHANGED
|
@@ -205,6 +205,45 @@ class Compiler {
|
|
|
205
205
|
return subgraph;
|
|
206
206
|
});
|
|
207
207
|
}
|
|
208
|
+
/**
|
|
209
|
+
* Validate that the compiled WASM has all the handlers that are defined in the subgraph manifest
|
|
210
|
+
*
|
|
211
|
+
* @returns a list of handlers that are missing from the compiled WASM
|
|
212
|
+
*
|
|
213
|
+
* This is a temporary solution to validate that the compiled WASM has all the event handlers.
|
|
214
|
+
* A better way would be if we can do this even before compiling
|
|
215
|
+
* but requires a larger refactor so we are running additional validations before compilation
|
|
216
|
+
*/
|
|
217
|
+
_validateHandlersInWasm({ pathToWasm, dataSource, }) {
|
|
218
|
+
const getHandlerNames = (handlerName) => dataSource
|
|
219
|
+
.getIn(['mapping', handlerName])
|
|
220
|
+
// if there is no handler, it will be undefined
|
|
221
|
+
?.toJS()
|
|
222
|
+
?.map((e) => e.handler) || [];
|
|
223
|
+
// Load the compiled WASM file
|
|
224
|
+
const buffer = fs_extra_1.default.readFileSync(pathToWasm);
|
|
225
|
+
const wasmMod = new WebAssembly.Module(buffer);
|
|
226
|
+
// Apologies to TS gods for `any` usage
|
|
227
|
+
// Yet another reason to refactor out immutable.js
|
|
228
|
+
const handlerNamesFromDataSources = [
|
|
229
|
+
// TODO: this is hacky, better is figuring out how to utilize the `protocol.getSubgraph().handlerTypes()`
|
|
230
|
+
...getHandlerNames('eventHandlers'),
|
|
231
|
+
...getHandlerNames('callHandlers'),
|
|
232
|
+
...getHandlerNames('blockHandlers'),
|
|
233
|
+
...getHandlerNames('transactionHandlers'),
|
|
234
|
+
...getHandlerNames('messageHandlers'),
|
|
235
|
+
...getHandlerNames('receiptHandlers'),
|
|
236
|
+
];
|
|
237
|
+
// We can check the WASM module for the exported functions
|
|
238
|
+
// https://developer.mozilla.org/en-US/docs/WebAssembly/JavaScript_interface/Module/exports
|
|
239
|
+
// Using a Set to avoid duplicates and makes it easier to check if a value is present
|
|
240
|
+
const handlerNamesFromWasm = new Set(WebAssembly.Module.exports(wasmMod)
|
|
241
|
+
.filter(e => e.kind === 'function')
|
|
242
|
+
.map(e => e.name));
|
|
243
|
+
// Figure out which handlers are missing
|
|
244
|
+
const missingHandlers = handlerNamesFromDataSources.filter((handler) => !handlerNamesFromWasm.has(handler));
|
|
245
|
+
return missingHandlers;
|
|
246
|
+
}
|
|
208
247
|
_compileDataSourceMapping(protocol, dataSource, mappingPath, compiledFiles, spinner) {
|
|
209
248
|
if (protocol.name == 'substreams') {
|
|
210
249
|
return;
|
|
@@ -241,6 +280,13 @@ class Compiler {
|
|
|
241
280
|
libs,
|
|
242
281
|
outputFile,
|
|
243
282
|
});
|
|
283
|
+
const missingHandlers = this._validateHandlersInWasm({
|
|
284
|
+
pathToWasm: outFile,
|
|
285
|
+
dataSource,
|
|
286
|
+
});
|
|
287
|
+
if (missingHandlers.length > 0) {
|
|
288
|
+
throw Error(`\n\tMissing handlers in WASM: ${missingHandlers.join(', ')}`);
|
|
289
|
+
}
|
|
244
290
|
// Remember the output file to avoid compiling the same file again
|
|
245
291
|
compiledFiles.set(inputCacheKey, outFile);
|
|
246
292
|
return outFile;
|
|
@@ -22,7 +22,9 @@ const mapping = ({ abi, contractName }) => `
|
|
|
22
22
|
language: wasm/assemblyscript
|
|
23
23
|
entities:
|
|
24
24
|
${(0, schema_1.abiEvents)(abi)
|
|
25
|
-
.map(event => `- ${event.get('
|
|
25
|
+
.map(event => `- ${event.get('collision')
|
|
26
|
+
? `${contractName}${event.get('_alias')}`
|
|
27
|
+
: event.get('_alias')}`)
|
|
26
28
|
.join('\n ')}
|
|
27
29
|
abis:
|
|
28
30
|
- name: ${contractName}
|
package/dist/scaffold/schema.js
CHANGED
|
@@ -63,13 +63,13 @@ const generateEventFields = ({ index, input, protocolName, }) => input.type == '
|
|
|
63
63
|
}),
|
|
64
64
|
];
|
|
65
65
|
exports.generateEventFields = generateEventFields;
|
|
66
|
-
const generateEventType = (event, protocolName,
|
|
67
|
-
return `type ${event._alias} @entity(immutable: true) {
|
|
66
|
+
const generateEventType = (event, protocolName, contractName) => {
|
|
67
|
+
return `type ${event.collision ? `${contractName}${event._alias}` : event._alias} @entity(immutable: true) {
|
|
68
68
|
id: Bytes!
|
|
69
69
|
${event.inputs
|
|
70
70
|
.reduce((acc, input, index) => {
|
|
71
71
|
if (Object.values(mapping_1.INPUT_NAMES_BLACKLIST).includes(input.name)) {
|
|
72
|
-
input.name = (0, mapping_1.renameInput)(input.name,
|
|
72
|
+
input.name = (0, mapping_1.renameInput)(input.name, contractName ?? 'contract');
|
|
73
73
|
}
|
|
74
74
|
return acc.concat((0, exports.generateEventFields)({ input, index, protocolName }));
|
|
75
75
|
}, [])
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphprotocol/graph-cli",
|
|
3
|
-
"version": "0.45.0-alpha-
|
|
3
|
+
"version": "0.45.0-alpha-20230404223012-053932b",
|
|
4
4
|
"description": "CLI for building for and deploying to The Graph",
|
|
5
5
|
"license": "(Apache-2.0 OR MIT)",
|
|
6
6
|
"engines": {
|
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
"main": "dist/index.js",
|
|
13
13
|
"files": [
|
|
14
14
|
"CHANGELOG.md",
|
|
15
|
-
"bin",
|
|
16
15
|
"dist",
|
|
17
16
|
"oclif.manifest.json",
|
|
18
17
|
"README.md"
|
|
@@ -74,9 +73,9 @@
|
|
|
74
73
|
]
|
|
75
74
|
},
|
|
76
75
|
"scripts": {
|
|
77
|
-
"build": "tsc -b tsconfig.build.json && oclif manifest &&
|
|
78
|
-
"oclif:pack": "npm pack && pnpm oclif pack tarballs --no-xz",
|
|
76
|
+
"build": "tsc -b tsconfig.build.json && oclif manifest && copyfiles -u 1 src/**/*.graphql dist/ && chmod +x ./dist/bin.js",
|
|
79
77
|
"test": "jest --verbose",
|
|
78
|
+
"test:add": "jest tests/cli/add.test.ts --verbose",
|
|
80
79
|
"test:init": "jest tests/cli/init.test.ts --verbose",
|
|
81
80
|
"test:validation": "jest tests/cli/validation.test.ts --verbose",
|
|
82
81
|
"type-check": "tsc --noEmit"
|
package/bin/graph.cmd
DELETED