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