@graphprotocol/graph-cli 0.64.0-alpha-20231215205836-6d9a26b → 0.64.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 +1 -8
- package/dist/codegen/schema.test.js +28 -29
- package/dist/codegen/types/index.test.js +430 -431
- package/dist/codegen/util.test.js +10 -11
- package/dist/command-helpers/abi.test.js +3 -4
- package/dist/command-helpers/compiler.test.js +15 -16
- package/dist/command-helpers/network.test.js +15 -16
- package/dist/command-helpers/scaffold.d.ts +10 -10
- package/dist/command-helpers/scaffold.js +5 -5
- package/dist/command-helpers/version.test.js +52 -45
- package/dist/protocols/ethereum/codegen/abi.test.js +32 -33
- package/dist/protocols/ethereum/type-generator.js +3 -3
- package/dist/scaffold/cosmos.test.js +7 -8
- package/dist/scaffold/ethereum.test.js +19 -20
- package/dist/scaffold/index.d.ts +21 -21
- package/dist/scaffold/index.js +30 -31
- package/dist/scaffold/near.test.js +7 -8
- package/dist/scaffold/tests.d.ts +3 -3
- package/dist/scaffold/tests.js +3 -3
- package/dist/type-generator.js +2 -2
- package/dist/validation/schema.test.js +25 -26
- package/oclif.manifest.json +1 -1
- package/package.json +9 -8
|
@@ -67,7 +67,7 @@ class EthereumTypeGenerator {
|
|
|
67
67
|
throw Error(`Failed to load data source template ABI: ${e.message}`);
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
|
-
|
|
70
|
+
generateTypesForABIs(abis) {
|
|
71
71
|
return (0, spinner_1.withSpinner)(`Generate types for contract ABIs`, `Failed to generate types for contract ABIs`, `Warnings while generating types for contract ABIs`, async (spinner) => {
|
|
72
72
|
return await Promise.all(abis.map(async (abi) => await this._generateTypesForABI(abi, spinner)));
|
|
73
73
|
});
|
|
@@ -76,7 +76,7 @@ class EthereumTypeGenerator {
|
|
|
76
76
|
try {
|
|
77
77
|
(0, spinner_1.step)(spinner, `Generate types for contract ABI:`, `${abi.abi.name} (${(0, fs_1.displayPath)(abi.abi.file)})`);
|
|
78
78
|
const codeGenerator = abi.abi.codeGenerator();
|
|
79
|
-
const code =
|
|
79
|
+
const code = prettier_1.default.format([
|
|
80
80
|
typescript_1.GENERATED_FILE_NOTE,
|
|
81
81
|
...codeGenerator.generateModuleImports(),
|
|
82
82
|
...codeGenerator.generateTypes(),
|
|
@@ -101,7 +101,7 @@ class EthereumTypeGenerator {
|
|
|
101
101
|
try {
|
|
102
102
|
(0, spinner_1.step)(spinner, `Generate types for data source template ABI:`, `${abi.template.get('name')} > ${abi.abi.name} (${(0, fs_1.displayPath)(abi.abi.file)})`);
|
|
103
103
|
const codeGenerator = abi.abi.codeGenerator();
|
|
104
|
-
const code =
|
|
104
|
+
const code = prettier_1.default.format([
|
|
105
105
|
typescript_1.GENERATED_FILE_NOTE,
|
|
106
106
|
...codeGenerator.generateModuleImports(),
|
|
107
107
|
...codeGenerator.generateTypes(),
|
|
@@ -3,7 +3,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const vitest_1 = require("vitest");
|
|
7
6
|
const protocols_1 = __importDefault(require("../protocols"));
|
|
8
7
|
const index_1 = __importDefault(require("./index"));
|
|
9
8
|
const protocol = new protocols_1.default('cosmos');
|
|
@@ -13,9 +12,9 @@ const scaffoldOptions = {
|
|
|
13
12
|
contractName: 'CosmosHub',
|
|
14
13
|
};
|
|
15
14
|
const scaffold = new index_1.default(scaffoldOptions);
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
describe('Cosmos subgraph scaffolding', () => {
|
|
16
|
+
test('Manifest', () => {
|
|
17
|
+
expect(scaffold.generateManifest()).toEqual(`\
|
|
19
18
|
specVersion: 0.0.5
|
|
20
19
|
schema:
|
|
21
20
|
file: ./schema.graphql
|
|
@@ -35,8 +34,8 @@ dataSources:
|
|
|
35
34
|
file: ./src/contract.ts
|
|
36
35
|
`);
|
|
37
36
|
});
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
test('Schema (default)', () => {
|
|
38
|
+
expect(scaffold.generateSchema()).toEqual(`\
|
|
40
39
|
type ExampleEntity @entity {
|
|
41
40
|
id: ID!
|
|
42
41
|
block: Bytes!
|
|
@@ -44,8 +43,8 @@ type ExampleEntity @entity {
|
|
|
44
43
|
}
|
|
45
44
|
`);
|
|
46
45
|
});
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
test('Mapping (default)', () => {
|
|
47
|
+
expect(scaffold.generateMapping()).toEqual(`\
|
|
49
48
|
import { cosmos, BigInt } from "@graphprotocol/graph-ts"
|
|
50
49
|
import { ExampleEntity } from "../generated/schema"
|
|
51
50
|
|
|
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const immutable_1 = __importDefault(require("immutable"));
|
|
7
|
-
const vitest_1 = require("vitest");
|
|
8
7
|
const protocols_1 = __importDefault(require("../protocols"));
|
|
9
8
|
const abi_1 = __importDefault(require("../protocols/ethereum/abi"));
|
|
10
9
|
const index_1 = __importDefault(require("./index"));
|
|
@@ -70,9 +69,9 @@ const scaffoldWithIndexEvents = new index_1.default({
|
|
|
70
69
|
...scaffoldOptions,
|
|
71
70
|
indexEvents: true,
|
|
72
71
|
});
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
describe('Ethereum subgraph scaffolding', () => {
|
|
73
|
+
test('Manifest', () => {
|
|
74
|
+
expect(scaffold.generateManifest()).toEqual(`\
|
|
76
75
|
specVersion: 0.0.5
|
|
77
76
|
schema:
|
|
78
77
|
file: ./schema.graphql
|
|
@@ -102,8 +101,8 @@ dataSources:
|
|
|
102
101
|
file: ./src/contract.ts
|
|
103
102
|
`);
|
|
104
103
|
});
|
|
105
|
-
|
|
106
|
-
|
|
104
|
+
test('Schema (default)', () => {
|
|
105
|
+
expect(scaffold.generateSchema()).toEqual(`\
|
|
107
106
|
type ExampleEntity @entity {
|
|
108
107
|
id: Bytes!
|
|
109
108
|
count: BigInt!
|
|
@@ -112,8 +111,8 @@ type ExampleEntity @entity {
|
|
|
112
111
|
}
|
|
113
112
|
`);
|
|
114
113
|
});
|
|
115
|
-
|
|
116
|
-
|
|
114
|
+
test('Schema (for indexing events)', () => {
|
|
115
|
+
expect(scaffoldWithIndexEvents.generateSchema()).toEqual(`\
|
|
117
116
|
type ExampleEvent @entity(immutable: true) {
|
|
118
117
|
id: Bytes!
|
|
119
118
|
a: BigInt! # uint256
|
|
@@ -140,8 +139,8 @@ type ExampleEvent1 @entity(immutable: true) {
|
|
|
140
139
|
}
|
|
141
140
|
`);
|
|
142
141
|
});
|
|
143
|
-
|
|
144
|
-
|
|
142
|
+
test('Mapping (default)', () => {
|
|
143
|
+
expect(scaffold.generateMapping()).toEqual(`\
|
|
145
144
|
import { BigInt } from "@graphprotocol/graph-ts"
|
|
146
145
|
import {
|
|
147
146
|
Contract,
|
|
@@ -196,8 +195,8 @@ export function handleExampleEvent(event: ExampleEvent): void {
|
|
|
196
195
|
export function handleExampleEvent1(event: ExampleEvent1): void {}
|
|
197
196
|
`);
|
|
198
197
|
});
|
|
199
|
-
|
|
200
|
-
|
|
198
|
+
test('Mapping (for indexing events)', () => {
|
|
199
|
+
expect(scaffoldWithIndexEvents.generateMapping()).toEqual(`\
|
|
201
200
|
import {
|
|
202
201
|
ExampleEvent as ExampleEventEvent,
|
|
203
202
|
ExampleEvent1 as ExampleEvent1Event
|
|
@@ -240,11 +239,11 @@ export function handleExampleEvent1(event: ExampleEvent1Event): void {
|
|
|
240
239
|
}
|
|
241
240
|
`);
|
|
242
241
|
});
|
|
243
|
-
|
|
244
|
-
const files =
|
|
242
|
+
test('Test Files (default)', () => {
|
|
243
|
+
const files = scaffoldWithIndexEvents.generateTests();
|
|
245
244
|
const testFile = files?.['contract.test.ts'];
|
|
246
245
|
const utilsFile = files?.['contract-utils.ts'];
|
|
247
|
-
|
|
246
|
+
expect(testFile).toEqual(`\
|
|
248
247
|
import {
|
|
249
248
|
assert,
|
|
250
249
|
describe,
|
|
@@ -320,7 +319,7 @@ describe("Describe entity assertions", () => {
|
|
|
320
319
|
})
|
|
321
320
|
})
|
|
322
321
|
`);
|
|
323
|
-
|
|
322
|
+
expect(utilsFile).toEqual(`\
|
|
324
323
|
import { newMockEvent } from "matchstick-as"
|
|
325
324
|
import { ethereum, BigInt, Bytes } from "@graphprotocol/graph-ts"
|
|
326
325
|
import { ExampleEvent, ExampleEvent1 } from "../generated/Contract/Contract"
|
|
@@ -368,11 +367,11 @@ export function createExampleEvent1Event(a: Bytes): ExampleEvent1 {
|
|
|
368
367
|
}
|
|
369
368
|
`);
|
|
370
369
|
});
|
|
371
|
-
|
|
372
|
-
const files =
|
|
370
|
+
test('Test Files (for indexing events)', () => {
|
|
371
|
+
const files = scaffoldWithIndexEvents.generateTests();
|
|
373
372
|
const testFile = files?.['contract.test.ts'];
|
|
374
373
|
const utilsFile = files?.['contract-utils.ts'];
|
|
375
|
-
|
|
374
|
+
expect(testFile).toEqual(`\
|
|
376
375
|
import {
|
|
377
376
|
assert,
|
|
378
377
|
describe,
|
|
@@ -448,7 +447,7 @@ describe("Describe entity assertions", () => {
|
|
|
448
447
|
})
|
|
449
448
|
})
|
|
450
449
|
`);
|
|
451
|
-
|
|
450
|
+
expect(utilsFile).toEqual(`\
|
|
452
451
|
import { newMockEvent } from "matchstick-as"
|
|
453
452
|
import { ethereum, BigInt, Bytes } from "@graphprotocol/graph-ts"
|
|
454
453
|
import { ExampleEvent, ExampleEvent1 } from "../generated/Contract/Contract"
|
package/dist/scaffold/index.d.ts
CHANGED
|
@@ -29,37 +29,37 @@ export default class Scaffold {
|
|
|
29
29
|
generateManifest(): Promise<string>;
|
|
30
30
|
generateSchema(): Promise<string>;
|
|
31
31
|
generateTsConfig(): Promise<string>;
|
|
32
|
-
generateMappings():
|
|
33
|
-
[x: string]: string
|
|
34
|
-
} | undefined
|
|
32
|
+
generateMappings(): {
|
|
33
|
+
[x: string]: Promise<string>;
|
|
34
|
+
} | undefined;
|
|
35
35
|
generateMapping(): Promise<string>;
|
|
36
|
-
generateABIs():
|
|
37
|
-
[x: string]: string
|
|
38
|
-
} | undefined
|
|
39
|
-
generateTests():
|
|
40
|
-
[x: string]: string
|
|
41
|
-
} | undefined
|
|
42
|
-
generate():
|
|
43
|
-
'subgraph.yaml': string
|
|
44
|
-
'schema.graphql': string
|
|
45
|
-
'package.json': string
|
|
36
|
+
generateABIs(): {
|
|
37
|
+
[x: string]: Promise<string>;
|
|
38
|
+
} | undefined;
|
|
39
|
+
generateTests(): {
|
|
40
|
+
[x: string]: Promise<string>;
|
|
41
|
+
} | undefined;
|
|
42
|
+
generate(): {
|
|
43
|
+
'subgraph.yaml': Promise<string>;
|
|
44
|
+
'schema.graphql': Promise<string>;
|
|
45
|
+
'package.json': Promise<string>;
|
|
46
46
|
'tsconfig.json'?: undefined;
|
|
47
47
|
src?: undefined;
|
|
48
48
|
abis?: undefined;
|
|
49
49
|
tests?: undefined;
|
|
50
50
|
} | {
|
|
51
|
-
'package.json': string
|
|
52
|
-
'subgraph.yaml': string
|
|
53
|
-
'schema.graphql': string
|
|
54
|
-
'tsconfig.json': string
|
|
51
|
+
'package.json': Promise<string>;
|
|
52
|
+
'subgraph.yaml': Promise<string>;
|
|
53
|
+
'schema.graphql': Promise<string>;
|
|
54
|
+
'tsconfig.json': Promise<string>;
|
|
55
55
|
src: {
|
|
56
|
-
[x: string]: string
|
|
56
|
+
[x: string]: Promise<string>;
|
|
57
57
|
} | undefined;
|
|
58
58
|
abis: {
|
|
59
|
-
[x: string]: string
|
|
59
|
+
[x: string]: Promise<string>;
|
|
60
60
|
} | undefined;
|
|
61
61
|
tests: {
|
|
62
|
-
[x: string]: string
|
|
62
|
+
[x: string]: Promise<string>;
|
|
63
63
|
} | undefined;
|
|
64
|
-
}
|
|
64
|
+
};
|
|
65
65
|
}
|
package/dist/scaffold/index.js
CHANGED
|
@@ -29,8 +29,8 @@ class Scaffold {
|
|
|
29
29
|
this.node = options.node;
|
|
30
30
|
this.spkgPath = options.spkgPath;
|
|
31
31
|
}
|
|
32
|
-
|
|
33
|
-
return
|
|
32
|
+
generatePackageJson() {
|
|
33
|
+
return prettier_1.default.format(JSON.stringify({
|
|
34
34
|
name: (0, subgraph_1.getSubgraphBasename)(String(this.subgraphName)),
|
|
35
35
|
license: 'UNLICENSED',
|
|
36
36
|
scripts: {
|
|
@@ -52,8 +52,8 @@ class Scaffold {
|
|
|
52
52
|
devDependencies: this.protocol.hasEvents() ? { 'matchstick-as': `0.5.0` } : undefined,
|
|
53
53
|
}), { parser: 'json' });
|
|
54
54
|
}
|
|
55
|
-
|
|
56
|
-
return
|
|
55
|
+
generatePackageJsonForSubstreams() {
|
|
56
|
+
return prettier_1.default.format(JSON.stringify({
|
|
57
57
|
name: (0, subgraph_1.getSubgraphBasename)(String(this.subgraphName)),
|
|
58
58
|
license: 'UNLICENSED',
|
|
59
59
|
scripts: {
|
|
@@ -72,9 +72,9 @@ class Scaffold {
|
|
|
72
72
|
},
|
|
73
73
|
}), { parser: 'json' });
|
|
74
74
|
}
|
|
75
|
-
|
|
75
|
+
generateManifest() {
|
|
76
76
|
const protocolManifest = this.protocol.getManifestScaffold();
|
|
77
|
-
return
|
|
77
|
+
return prettier_1.default.format(`
|
|
78
78
|
specVersion: 0.0.5
|
|
79
79
|
schema:
|
|
80
80
|
file: ./schema.graphql
|
|
@@ -86,72 +86,71 @@ dataSources:
|
|
|
86
86
|
mapping: ${protocolManifest.mapping(this)}
|
|
87
87
|
`, { parser: 'yaml' });
|
|
88
88
|
}
|
|
89
|
-
|
|
89
|
+
generateSchema() {
|
|
90
90
|
const hasEvents = this.protocol.hasEvents();
|
|
91
91
|
const events = hasEvents ? (0, schema_1.abiEvents)(this.abi).toJS() : [];
|
|
92
|
-
return
|
|
92
|
+
return prettier_1.default.format(hasEvents && this.indexEvents
|
|
93
93
|
? events
|
|
94
94
|
.map((event) => (0, schema_1.generateEventType)(event, this.protocol.name, this.contractName))
|
|
95
95
|
.join('\n\n')
|
|
96
96
|
: (0, schema_1.generateExampleEntityType)(this.protocol, events), {
|
|
97
97
|
parser: 'graphql',
|
|
98
|
-
trailingComma: 'none',
|
|
99
98
|
});
|
|
100
99
|
}
|
|
101
|
-
|
|
102
|
-
return
|
|
100
|
+
generateTsConfig() {
|
|
101
|
+
return prettier_1.default.format(JSON.stringify({
|
|
103
102
|
extends: '@graphprotocol/graph-ts/types/tsconfig.base.json',
|
|
104
103
|
include: ['src', 'tests'],
|
|
105
104
|
}), { parser: 'json' });
|
|
106
105
|
}
|
|
107
|
-
|
|
106
|
+
generateMappings() {
|
|
108
107
|
return this.protocol.getMappingScaffold()
|
|
109
|
-
? { [`${gluegun_1.strings.kebabCase(this.contractName)}.ts`]:
|
|
108
|
+
? { [`${gluegun_1.strings.kebabCase(this.contractName)}.ts`]: this.generateMapping() }
|
|
110
109
|
: undefined;
|
|
111
110
|
}
|
|
112
|
-
|
|
111
|
+
generateMapping() {
|
|
113
112
|
const hasEvents = this.protocol.hasEvents();
|
|
114
113
|
const events = hasEvents ? (0, schema_1.abiEvents)(this.abi).toJS() : [];
|
|
115
114
|
const protocolMapping = this.protocol.getMappingScaffold();
|
|
116
|
-
return
|
|
115
|
+
return prettier_1.default.format(hasEvents && this.indexEvents
|
|
117
116
|
? (0, mapping_1.generateEventIndexingHandlers)(events, this.contractName)
|
|
118
117
|
: protocolMapping.generatePlaceholderHandlers({
|
|
119
118
|
...this,
|
|
120
119
|
events,
|
|
121
|
-
}), { parser: 'typescript', semi: false
|
|
120
|
+
}), { parser: 'typescript', semi: false });
|
|
122
121
|
}
|
|
123
|
-
|
|
122
|
+
generateABIs() {
|
|
124
123
|
return this.protocol.hasABIs()
|
|
125
124
|
? {
|
|
126
|
-
[`${this.contractName}.json`]:
|
|
125
|
+
[`${this.contractName}.json`]: prettier_1.default.format(JSON.stringify(this.abi?.data), {
|
|
127
126
|
parser: 'json',
|
|
128
127
|
}),
|
|
129
128
|
}
|
|
130
129
|
: undefined;
|
|
131
130
|
}
|
|
132
|
-
|
|
131
|
+
generateTests() {
|
|
133
132
|
const hasEvents = this.protocol.hasEvents();
|
|
134
133
|
const events = hasEvents ? (0, schema_1.abiEvents)(this.abi).toJS() : [];
|
|
135
134
|
return events.length > 0
|
|
136
|
-
?
|
|
135
|
+
? (0, tests_1.generateTestsFiles)(this.contractName, events, this.indexEvents)
|
|
137
136
|
: undefined;
|
|
138
137
|
}
|
|
139
|
-
|
|
138
|
+
generate() {
|
|
140
139
|
if (this.protocol.name === 'substreams') {
|
|
141
140
|
return {
|
|
142
|
-
'subgraph.yaml':
|
|
143
|
-
'schema.graphql':
|
|
144
|
-
'package.json':
|
|
141
|
+
'subgraph.yaml': this.generateManifest(),
|
|
142
|
+
'schema.graphql': this.generateSchema(),
|
|
143
|
+
'package.json': this.generatePackageJsonForSubstreams(),
|
|
145
144
|
};
|
|
146
145
|
}
|
|
147
146
|
return {
|
|
148
|
-
'package.json':
|
|
149
|
-
'subgraph.yaml':
|
|
150
|
-
'schema.graphql':
|
|
151
|
-
'tsconfig.json':
|
|
152
|
-
src:
|
|
153
|
-
abis:
|
|
154
|
-
tests:
|
|
147
|
+
'package.json': this.generatePackageJson(),
|
|
148
|
+
'subgraph.yaml': this.generateManifest(),
|
|
149
|
+
'schema.graphql': this.generateSchema(),
|
|
150
|
+
'tsconfig.json': this.generateTsConfig(),
|
|
151
|
+
src: this.generateMappings(),
|
|
152
|
+
abis: this.generateABIs(),
|
|
153
|
+
tests: this.generateTests(),
|
|
155
154
|
};
|
|
156
155
|
}
|
|
157
156
|
}
|
|
@@ -3,7 +3,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const vitest_1 = require("vitest");
|
|
7
6
|
const protocols_1 = __importDefault(require("../protocols"));
|
|
8
7
|
const index_1 = __importDefault(require("./index"));
|
|
9
8
|
const protocol = new protocols_1.default('near');
|
|
@@ -14,9 +13,9 @@ const scaffoldOptions = {
|
|
|
14
13
|
contractName: 'Contract',
|
|
15
14
|
};
|
|
16
15
|
const scaffold = new index_1.default(scaffoldOptions);
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
describe('NEAR subgraph scaffolding', () => {
|
|
17
|
+
test('Manifest', () => {
|
|
18
|
+
expect(scaffold.generateManifest()).toEqual(`\
|
|
20
19
|
specVersion: 0.0.5
|
|
21
20
|
schema:
|
|
22
21
|
file: ./schema.graphql
|
|
@@ -36,8 +35,8 @@ dataSources:
|
|
|
36
35
|
file: ./src/contract.ts
|
|
37
36
|
`);
|
|
38
37
|
});
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
test('Schema (default)', () => {
|
|
39
|
+
expect(scaffold.generateSchema()).toEqual(`\
|
|
41
40
|
type ExampleEntity @entity {
|
|
42
41
|
id: ID!
|
|
43
42
|
block: Bytes!
|
|
@@ -45,8 +44,8 @@ type ExampleEntity @entity {
|
|
|
45
44
|
}
|
|
46
45
|
`);
|
|
47
46
|
});
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
test('Mapping (default)', () => {
|
|
48
|
+
expect(scaffold.generateMapping()).toEqual(`\
|
|
50
49
|
import { near, BigInt } from "@graphprotocol/graph-ts"
|
|
51
50
|
import { ExampleEntity } from "../generated/schema"
|
|
52
51
|
|
package/dist/scaffold/tests.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const generateTestsFiles: (contract: any, events: any[], indexEvents?: boolean) =>
|
|
2
|
-
[x: string]: string
|
|
3
|
-
}
|
|
1
|
+
export declare const generateTestsFiles: (contract: any, events: any[], indexEvents?: boolean) => {
|
|
2
|
+
[x: string]: Promise<string>;
|
|
3
|
+
};
|
package/dist/scaffold/tests.js
CHANGED
|
@@ -15,7 +15,7 @@ const VARIABLES_VALUES = {
|
|
|
15
15
|
string: 'Example string value',
|
|
16
16
|
bool: true,
|
|
17
17
|
};
|
|
18
|
-
const generateTestsFiles =
|
|
18
|
+
const generateTestsFiles = (contract, events, indexEvents) => {
|
|
19
19
|
const eventsTypes = events
|
|
20
20
|
.flatMap(event => event.inputs.map((input) => {
|
|
21
21
|
// If the asc type is Array<T> we need to check if T is a native type or a custom graph-ts type
|
|
@@ -27,8 +27,8 @@ const generateTestsFiles = async (contract, events, indexEvents) => {
|
|
|
27
27
|
.filter(type => !type.startsWith('ethereum.') && !isNativeType(type));
|
|
28
28
|
const importTypes = [...new Set(eventsTypes)].join(', ');
|
|
29
29
|
return {
|
|
30
|
-
[`${gluegun_1.strings.kebabCase(contract)}.test.ts`]:
|
|
31
|
-
[`${gluegun_1.strings.kebabCase(contract)}-utils.ts`]:
|
|
30
|
+
[`${gluegun_1.strings.kebabCase(contract)}.test.ts`]: prettier_1.default.format(generateExampleTest(contract, events[0], indexEvents, importTypes), { parser: 'typescript', semi: false }),
|
|
31
|
+
[`${gluegun_1.strings.kebabCase(contract)}-utils.ts`]: prettier_1.default.format(generateTestHelper(contract, events, importTypes), { parser: 'typescript', semi: false }),
|
|
32
32
|
};
|
|
33
33
|
};
|
|
34
34
|
exports.generateTestsFiles = generateTestsFiles;
|
package/dist/type-generator.js
CHANGED
|
@@ -136,7 +136,7 @@ class TypeGenerator {
|
|
|
136
136
|
return await (0, spinner_1.withSpinner)(`Generate types for GraphQL schema`, `Failed to generate types for GraphQL schema`, `Warnings while generating types for GraphQL schema`, async (spinner) => {
|
|
137
137
|
// Generate TypeScript module from schema
|
|
138
138
|
const codeGenerator = schema.codeGenerator();
|
|
139
|
-
const code =
|
|
139
|
+
const code = prettier_1.default.format([
|
|
140
140
|
typescript_1.GENERATED_FILE_NOTE,
|
|
141
141
|
...codeGenerator.generateModuleImports(),
|
|
142
142
|
...codeGenerator.generateTypes(),
|
|
@@ -182,7 +182,7 @@ class TypeGenerator {
|
|
|
182
182
|
return acc;
|
|
183
183
|
}, []);
|
|
184
184
|
if (!codeSegments.isEmpty()) {
|
|
185
|
-
const code =
|
|
185
|
+
const code = prettier_1.default.format([typescript_1.GENERATED_FILE_NOTE, ...dedupeModulesImports, ...codeSegments].join('\n'), {
|
|
186
186
|
parser: 'typescript',
|
|
187
187
|
});
|
|
188
188
|
const outputFile = path_1.default.join(this.options.outputDir, 'templates.ts');
|
|
@@ -1,40 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const vitest_1 = require("vitest");
|
|
4
3
|
const schema_1 = require("./schema");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
4
|
+
describe('Schema validation', () => {
|
|
5
|
+
test('Type suggestions', () => {
|
|
6
|
+
expect((0, schema_1.typeSuggestion)('Address')).toEqual('Bytes');
|
|
7
|
+
expect((0, schema_1.typeSuggestion)('address')).toEqual('Bytes');
|
|
8
|
+
expect((0, schema_1.typeSuggestion)('bytes')).toEqual('Bytes');
|
|
9
|
+
expect((0, schema_1.typeSuggestion)('string')).toEqual('String');
|
|
10
|
+
expect((0, schema_1.typeSuggestion)('bool')).toEqual('Boolean');
|
|
11
|
+
expect((0, schema_1.typeSuggestion)('boolean')).toEqual('Boolean');
|
|
12
|
+
expect((0, schema_1.typeSuggestion)('float')).toEqual('BigDecimal');
|
|
13
|
+
expect((0, schema_1.typeSuggestion)('Float')).toEqual('BigDecimal');
|
|
14
|
+
expect((0, schema_1.typeSuggestion)(`int`)).toBe('Int');
|
|
15
|
+
expect((0, schema_1.typeSuggestion)(`uint`)).toBe('BigInt');
|
|
16
|
+
expect((0, schema_1.typeSuggestion)(`uint32`)).toBe('BigInt');
|
|
17
|
+
expect((0, schema_1.typeSuggestion)(`int8`)).toBe('Int8');
|
|
18
|
+
expect((0, schema_1.typeSuggestion)(`i8`)).toBe('Int8');
|
|
19
|
+
expect((0, schema_1.typeSuggestion)(`u8`)).toBe('Int8');
|
|
20
|
+
expect((0, schema_1.typeSuggestion)(`uint8`)).toBe('Int8');
|
|
22
21
|
// Test i16..i32, int17..int32
|
|
23
22
|
for (let i = 16; i <= 32; i += 8) {
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
expect((0, schema_1.typeSuggestion)(`i${i}`)).toBe('Int');
|
|
24
|
+
expect((0, schema_1.typeSuggestion)(`int${i}`)).toBe('Int');
|
|
26
25
|
}
|
|
27
26
|
// Test u16..u24, uint16..uint24
|
|
28
27
|
for (let i = 16; i <= 24; i += 8) {
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
expect((0, schema_1.typeSuggestion)(`u${i}`)).toBe('Int');
|
|
29
|
+
expect((0, schema_1.typeSuggestion)(`uint${i}`)).toBe('Int');
|
|
31
30
|
}
|
|
32
31
|
// Test i40..i256, int40..int256, u40..u256, uint40..uint256
|
|
33
32
|
for (let i = 40; i <= 256; i += 8) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
expect((0, schema_1.typeSuggestion)(`i${i}`)).toBe('BigInt');
|
|
34
|
+
expect((0, schema_1.typeSuggestion)(`int${i}`)).toBe('BigInt');
|
|
35
|
+
expect((0, schema_1.typeSuggestion)(`u${i}`)).toBe('BigInt');
|
|
36
|
+
expect((0, schema_1.typeSuggestion)(`uint${i}`)).toBe('BigInt');
|
|
38
37
|
}
|
|
39
38
|
});
|
|
40
39
|
});
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphprotocol/graph-cli",
|
|
3
|
-
"version": "0.64.0
|
|
3
|
+
"version": "0.64.0",
|
|
4
4
|
"description": "CLI for building for and deploying to The Graph",
|
|
5
5
|
"license": "(Apache-2.0 OR MIT)",
|
|
6
6
|
"engines": {
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"ipfs-http-client": "55.0.0",
|
|
40
40
|
"jayson": "4.0.0",
|
|
41
41
|
"js-yaml": "3.14.1",
|
|
42
|
-
"prettier": "
|
|
42
|
+
"prettier": "1.19.1",
|
|
43
43
|
"request": "2.88.2",
|
|
44
44
|
"semver": "7.4.0",
|
|
45
45
|
"sync-request": "6.1.0",
|
|
@@ -51,16 +51,17 @@
|
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@types/debug": "^4.1.7",
|
|
53
53
|
"@types/fs-extra": "^9.0.13",
|
|
54
|
+
"@types/jest": "^29.0.0",
|
|
54
55
|
"@types/js-yaml": "^3.12.7",
|
|
55
56
|
"@types/semver": "^7.3.13",
|
|
56
57
|
"@types/which": "^2.0.1",
|
|
57
58
|
"copyfiles": "^2.4.1",
|
|
59
|
+
"jest": "29.7.0",
|
|
58
60
|
"oclif": "3.8.1",
|
|
59
61
|
"spawn-command": "0.0.2-1",
|
|
60
62
|
"strip-ansi": "6.0.1",
|
|
61
63
|
"tern": "0.24.3",
|
|
62
|
-
"typescript": "^5.0.0"
|
|
63
|
-
"vitest": "^1.0.2"
|
|
64
|
+
"typescript": "^5.0.0"
|
|
64
65
|
},
|
|
65
66
|
"publishConfig": {
|
|
66
67
|
"access": "public"
|
|
@@ -82,10 +83,10 @@
|
|
|
82
83
|
"scripts": {
|
|
83
84
|
"build": "tsc -b tsconfig.build.json && oclif manifest && oclif readme && copyfiles -u 1 src/**/*.graphql dist/",
|
|
84
85
|
"oclif:pack": "npm pack && pnpm oclif pack tarballs --no-xz && node scripts/rename-tarballs.mjs",
|
|
85
|
-
"test": "
|
|
86
|
-
"test:add": "
|
|
87
|
-
"test:init": "
|
|
88
|
-
"test:validation": "
|
|
86
|
+
"test": "jest --verbose",
|
|
87
|
+
"test:add": "jest tests/cli/add.test.ts --verbose",
|
|
88
|
+
"test:init": "jest tests/cli/init.test.ts --verbose",
|
|
89
|
+
"test:validation": "jest tests/cli/validation.test.ts --verbose",
|
|
89
90
|
"type-check": "tsc --noEmit"
|
|
90
91
|
}
|
|
91
92
|
}
|