@graphprotocol/graph-cli 0.37.3-alpha-20230110160324-f11ef4f → 0.37.3-alpha-20230110163550-d64bef6
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 -1
- package/dist/protocols/index.js +11 -7
- package/dist/protocols/substreams/subgraph.js +3 -0
- package/dist/subgraph.js +9 -11
- package/package.json +1 -1
- package/src/protocols/{index.js → index.ts} +44 -24
- package/src/protocols/substreams/scaffold/{manifest.js → manifest.ts} +2 -4
- package/src/protocols/substreams/subgraph.ts +22 -0
- package/src/subgraph.ts +14 -15
- package/src/protocols/substreams/subgraph.js +0 -17
package/CHANGELOG.md
CHANGED
package/dist/protocols/index.js
CHANGED
|
@@ -46,7 +46,6 @@ const ArweaveMappingScaffold = __importStar(require("./arweave/scaffold/mapping"
|
|
|
46
46
|
const EthereumMappingScaffold = __importStar(require("./ethereum/scaffold/mapping"));
|
|
47
47
|
const NearMappingScaffold = __importStar(require("./near/scaffold/mapping"));
|
|
48
48
|
const CosmosMappingScaffold = __importStar(require("./cosmos/scaffold/mapping"));
|
|
49
|
-
const assemblyscript_1 = require("assemblyscript");
|
|
50
49
|
const debug_1 = __importDefault(require("../debug"));
|
|
51
50
|
let protocolDebug = (0, debug_1.default)('graph-cli:protocol');
|
|
52
51
|
class Protocol {
|
|
@@ -54,6 +53,9 @@ class Protocol {
|
|
|
54
53
|
const firstDataSourceKind = dataSourcesAndTemplates[0].kind;
|
|
55
54
|
return new Protocol(firstDataSourceKind);
|
|
56
55
|
}
|
|
56
|
+
name;
|
|
57
|
+
// TODO: should assert non null? see the constructor switch default case comment
|
|
58
|
+
config;
|
|
57
59
|
constructor(name) {
|
|
58
60
|
this.name = Protocol.normalizeName(name);
|
|
59
61
|
switch (this.name) {
|
|
@@ -134,7 +136,7 @@ class Protocol {
|
|
|
134
136
|
networks.forEach(value => {
|
|
135
137
|
allNetworks.push(...value);
|
|
136
138
|
});
|
|
137
|
-
networks = networks.set('substreams',
|
|
139
|
+
networks = networks.set('substreams', allNetworks);
|
|
138
140
|
return networks;
|
|
139
141
|
}
|
|
140
142
|
static normalizeName(name) {
|
|
@@ -143,12 +145,14 @@ class Protocol {
|
|
|
143
145
|
});
|
|
144
146
|
}
|
|
145
147
|
displayName() {
|
|
146
|
-
return this.config
|
|
148
|
+
return this.config?.displayName;
|
|
147
149
|
}
|
|
148
150
|
// Receives a data source kind, and checks if it's valid
|
|
149
151
|
// for the given protocol instance (this).
|
|
150
152
|
isValidKindName(kind) {
|
|
151
|
-
return Protocol.availableProtocols()
|
|
153
|
+
return Protocol.availableProtocols()
|
|
154
|
+
.get(this.name, immutable_1.default.List())
|
|
155
|
+
.includes(kind);
|
|
152
156
|
}
|
|
153
157
|
hasABIs() {
|
|
154
158
|
return this.config.abi != null;
|
|
@@ -166,7 +170,7 @@ class Protocol {
|
|
|
166
170
|
return this.config.getTemplateCodeGen != null;
|
|
167
171
|
}
|
|
168
172
|
hasDataSourceMappingFile() {
|
|
169
|
-
return this.
|
|
173
|
+
return this.getMappingScaffold() != null;
|
|
170
174
|
}
|
|
171
175
|
getTypeGenerator(options) {
|
|
172
176
|
if (this.config == null || this.config.getTypeGenerator == null) {
|
|
@@ -178,7 +182,7 @@ class Protocol {
|
|
|
178
182
|
if (!this.hasTemplates()) {
|
|
179
183
|
throw new Error(`Template data sources with kind '${this.name}' are not supported yet`);
|
|
180
184
|
}
|
|
181
|
-
return this.config.getTemplateCodeGen(template);
|
|
185
|
+
return this.config.getTemplateCodeGen?.(template);
|
|
182
186
|
}
|
|
183
187
|
getABI() {
|
|
184
188
|
return this.config.abi;
|
|
@@ -196,6 +200,7 @@ class Protocol {
|
|
|
196
200
|
return this.config.mappingScaffold;
|
|
197
201
|
}
|
|
198
202
|
}
|
|
203
|
+
exports.default = Protocol;
|
|
199
204
|
const arweaveProtocol = {
|
|
200
205
|
displayName: 'Arweave',
|
|
201
206
|
abi: undefined,
|
|
@@ -261,4 +266,3 @@ const substreamsProtocol = {
|
|
|
261
266
|
mappingScaffold: undefined,
|
|
262
267
|
};
|
|
263
268
|
protocolDebug('Available networks %M', Protocol.availableNetworks());
|
|
264
|
-
exports.default = Protocol;
|
|
@@ -5,6 +5,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const immutable_1 = __importDefault(require("immutable"));
|
|
7
7
|
class SubstreamsSubgraph {
|
|
8
|
+
manifest;
|
|
9
|
+
resolveFile;
|
|
10
|
+
protocol;
|
|
8
11
|
constructor(options = {}) {
|
|
9
12
|
this.manifest = options.manifest;
|
|
10
13
|
this.resolveFile = options.resolveFile;
|
package/dist/subgraph.js
CHANGED
|
@@ -76,17 +76,15 @@ class Subgraph {
|
|
|
76
76
|
}
|
|
77
77
|
static validateSchema(manifest, { resolveFile }) {
|
|
78
78
|
let filename = resolveFile(manifest.getIn(['schema', 'file']));
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
: ''}
|
|
89
|
-
${groupedErrors
|
|
79
|
+
const validationErrors = validation_1.default.validateSchema(filename);
|
|
80
|
+
let errors;
|
|
81
|
+
if (validationErrors.size > 0) {
|
|
82
|
+
errors = validationErrors.groupBy(error => error.get('entity')).sort();
|
|
83
|
+
let msg = errors.reduce((msg, errors, entity) => {
|
|
84
|
+
errors = errors.groupBy((error) => error.get('directive'));
|
|
85
|
+
let inner_msgs = errors.reduce((msg, errors, directive) => {
|
|
86
|
+
return `${msg}${directive ? `${directive}:` : ''}
|
|
87
|
+
${errors
|
|
90
88
|
.map(error => error
|
|
91
89
|
.get('message')
|
|
92
90
|
.split('\n')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphprotocol/graph-cli",
|
|
3
|
-
"version": "0.37.3-alpha-
|
|
3
|
+
"version": "0.37.3-alpha-20230110163550-d64bef6",
|
|
4
4
|
"license": "(Apache-2.0 OR MIT)",
|
|
5
5
|
"description": "CLI for building for and deploying to The Graph",
|
|
6
6
|
"main": "dist/cli.js",
|
|
@@ -18,19 +18,25 @@ import * as ArweaveMappingScaffold from './arweave/scaffold/mapping'
|
|
|
18
18
|
import * as EthereumMappingScaffold from './ethereum/scaffold/mapping'
|
|
19
19
|
import * as NearMappingScaffold from './near/scaffold/mapping'
|
|
20
20
|
import * as CosmosMappingScaffold from './cosmos/scaffold/mapping'
|
|
21
|
-
import { ThrowStatement } from 'assemblyscript'
|
|
22
21
|
import debug from '../debug'
|
|
22
|
+
import Subgraph from '../subgraph'
|
|
23
|
+
import { SubgraphOptions } from './subgraph'
|
|
23
24
|
|
|
24
25
|
let protocolDebug = debug('graph-cli:protocol')
|
|
25
26
|
|
|
26
|
-
class Protocol {
|
|
27
|
-
static fromDataSources(dataSourcesAndTemplates) {
|
|
27
|
+
export default class Protocol {
|
|
28
|
+
static fromDataSources(dataSourcesAndTemplates: any) {
|
|
28
29
|
const firstDataSourceKind = dataSourcesAndTemplates[0].kind
|
|
29
30
|
return new Protocol(firstDataSourceKind)
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
name: ProtocolName
|
|
34
|
+
|
|
35
|
+
// TODO: should assert non null? see the constructor switch default case comment
|
|
36
|
+
config!: ProtocolConfig
|
|
37
|
+
|
|
38
|
+
constructor(name: ProtocolName) {
|
|
39
|
+
this.name = Protocol.normalizeName(name)!
|
|
34
40
|
|
|
35
41
|
switch (this.name) {
|
|
36
42
|
case 'arweave':
|
|
@@ -63,7 +69,7 @@ class Protocol {
|
|
|
63
69
|
near: ['near'],
|
|
64
70
|
cosmos: ['cosmos'],
|
|
65
71
|
substreams: ['substreams'],
|
|
66
|
-
})
|
|
72
|
+
}) as immutable.Collection<ProtocolName, string[]>
|
|
67
73
|
}
|
|
68
74
|
|
|
69
75
|
static availableNetworks() {
|
|
@@ -107,32 +113,34 @@ class Protocol {
|
|
|
107
113
|
'juno-1',
|
|
108
114
|
'uni-3', // Juno testnet
|
|
109
115
|
],
|
|
110
|
-
})
|
|
116
|
+
}) as immutable.Map<string, string[]>
|
|
111
117
|
|
|
112
|
-
let allNetworks = []
|
|
118
|
+
let allNetworks: string[] = []
|
|
113
119
|
networks.forEach(value => {
|
|
114
120
|
allNetworks.push(...value)
|
|
115
121
|
})
|
|
116
122
|
|
|
117
|
-
networks = networks.set('substreams',
|
|
123
|
+
networks = networks.set('substreams', allNetworks)
|
|
118
124
|
|
|
119
125
|
return networks
|
|
120
126
|
}
|
|
121
127
|
|
|
122
|
-
static normalizeName(name) {
|
|
128
|
+
static normalizeName(name: ProtocolName) {
|
|
123
129
|
return Protocol.availableProtocols().findKey(possibleNames => {
|
|
124
130
|
return possibleNames.includes(name)
|
|
125
|
-
})
|
|
131
|
+
})!
|
|
126
132
|
}
|
|
127
133
|
|
|
128
134
|
displayName() {
|
|
129
|
-
return this.config
|
|
135
|
+
return this.config?.displayName
|
|
130
136
|
}
|
|
131
137
|
|
|
132
138
|
// Receives a data source kind, and checks if it's valid
|
|
133
139
|
// for the given protocol instance (this).
|
|
134
|
-
isValidKindName(kind) {
|
|
135
|
-
return Protocol.availableProtocols()
|
|
140
|
+
isValidKindName(kind: string) {
|
|
141
|
+
return Protocol.availableProtocols()
|
|
142
|
+
.get(this.name, immutable.List())
|
|
143
|
+
.includes(kind)
|
|
136
144
|
}
|
|
137
145
|
|
|
138
146
|
hasABIs() {
|
|
@@ -155,10 +163,10 @@ class Protocol {
|
|
|
155
163
|
}
|
|
156
164
|
|
|
157
165
|
hasDataSourceMappingFile() {
|
|
158
|
-
return this.
|
|
166
|
+
return this.getMappingScaffold() != null
|
|
159
167
|
}
|
|
160
168
|
|
|
161
|
-
getTypeGenerator(options) {
|
|
169
|
+
getTypeGenerator(options: any) {
|
|
162
170
|
if (this.config == null || this.config.getTypeGenerator == null) {
|
|
163
171
|
return null
|
|
164
172
|
}
|
|
@@ -166,14 +174,14 @@ class Protocol {
|
|
|
166
174
|
return this.config.getTypeGenerator(options)
|
|
167
175
|
}
|
|
168
176
|
|
|
169
|
-
getTemplateCodeGen(template) {
|
|
177
|
+
getTemplateCodeGen(template: any) {
|
|
170
178
|
if (!this.hasTemplates()) {
|
|
171
179
|
throw new Error(
|
|
172
180
|
`Template data sources with kind '${this.name}' are not supported yet`,
|
|
173
181
|
)
|
|
174
182
|
}
|
|
175
183
|
|
|
176
|
-
return this.config.getTemplateCodeGen(template)
|
|
184
|
+
return this.config.getTemplateCodeGen?.(template)
|
|
177
185
|
}
|
|
178
186
|
|
|
179
187
|
getABI() {
|
|
@@ -197,7 +205,20 @@ class Protocol {
|
|
|
197
205
|
}
|
|
198
206
|
}
|
|
199
207
|
|
|
200
|
-
|
|
208
|
+
type ProtocolName = 'arweave' | 'ethereum' | 'near' | 'cosmos' | 'substreams'
|
|
209
|
+
|
|
210
|
+
interface ProtocolConfig {
|
|
211
|
+
displayName: string
|
|
212
|
+
abi?: any
|
|
213
|
+
contract?: any
|
|
214
|
+
getTemplateCodeGen?: (template: any) => any
|
|
215
|
+
getTypeGenerator?: (options: any) => any
|
|
216
|
+
getSubgraph(options: SubgraphOptions): Subgraph
|
|
217
|
+
manifestScaffold: any
|
|
218
|
+
mappingScaffold: any
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const arweaveProtocol: ProtocolConfig = {
|
|
201
222
|
displayName: 'Arweave',
|
|
202
223
|
abi: undefined,
|
|
203
224
|
contract: undefined,
|
|
@@ -210,7 +231,7 @@ const arweaveProtocol = {
|
|
|
210
231
|
mappingScaffold: ArweaveMappingScaffold,
|
|
211
232
|
}
|
|
212
233
|
|
|
213
|
-
const cosmosProtocol = {
|
|
234
|
+
const cosmosProtocol: ProtocolConfig = {
|
|
214
235
|
displayName: 'Cosmos',
|
|
215
236
|
abi: undefined,
|
|
216
237
|
contract: undefined,
|
|
@@ -223,7 +244,7 @@ const cosmosProtocol = {
|
|
|
223
244
|
mappingScaffold: CosmosMappingScaffold,
|
|
224
245
|
}
|
|
225
246
|
|
|
226
|
-
const ethereumProtocol = {
|
|
247
|
+
const ethereumProtocol: ProtocolConfig = {
|
|
227
248
|
displayName: 'Ethereum',
|
|
228
249
|
abi: EthereumABI,
|
|
229
250
|
contract: EthereumContract,
|
|
@@ -240,7 +261,7 @@ const ethereumProtocol = {
|
|
|
240
261
|
mappingScaffold: EthereumMappingScaffold,
|
|
241
262
|
}
|
|
242
263
|
|
|
243
|
-
const nearProtocol = {
|
|
264
|
+
const nearProtocol: ProtocolConfig = {
|
|
244
265
|
displayName: 'NEAR',
|
|
245
266
|
abi: undefined,
|
|
246
267
|
contract: NearContract,
|
|
@@ -253,7 +274,7 @@ const nearProtocol = {
|
|
|
253
274
|
mappingScaffold: NearMappingScaffold,
|
|
254
275
|
}
|
|
255
276
|
|
|
256
|
-
const substreamsProtocol = {
|
|
277
|
+
const substreamsProtocol: ProtocolConfig = {
|
|
257
278
|
displayName: 'Substreams',
|
|
258
279
|
abi: undefined,
|
|
259
280
|
contract: undefined,
|
|
@@ -267,4 +288,3 @@ const substreamsProtocol = {
|
|
|
267
288
|
}
|
|
268
289
|
|
|
269
290
|
protocolDebug('Available networks %M', Protocol.availableNetworks())
|
|
270
|
-
export default Protocol
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
const source = () => `
|
|
1
|
+
export const source = () => `
|
|
2
2
|
package:
|
|
3
3
|
moduleName: graph_out
|
|
4
4
|
file: substreams-eth-block-meta-v0.1.0.spkg`
|
|
5
5
|
|
|
6
|
-
const mapping = () => `
|
|
6
|
+
export const mapping = () => `
|
|
7
7
|
apiVersion: 0.0.5
|
|
8
8
|
kind: substreams/graph-entities`
|
|
9
|
-
|
|
10
|
-
export { source, mapping }
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import immutable from 'immutable'
|
|
2
|
+
import { Subgraph, SubgraphOptions } from '../subgraph'
|
|
3
|
+
|
|
4
|
+
export default class SubstreamsSubgraph implements Subgraph {
|
|
5
|
+
manifest: SubgraphOptions['manifest']
|
|
6
|
+
resolveFile: SubgraphOptions['resolveFile']
|
|
7
|
+
protocol: SubgraphOptions['protocol']
|
|
8
|
+
|
|
9
|
+
constructor(options: SubgraphOptions = {}) {
|
|
10
|
+
this.manifest = options.manifest
|
|
11
|
+
this.resolveFile = options.resolveFile
|
|
12
|
+
this.protocol = options.protocol
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
validateManifest() {
|
|
16
|
+
return immutable.List()
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
handlerTypes() {
|
|
20
|
+
return immutable.List([])
|
|
21
|
+
}
|
|
22
|
+
}
|
package/src/subgraph.ts
CHANGED
|
@@ -79,20 +79,17 @@ export default class Subgraph {
|
|
|
79
79
|
|
|
80
80
|
static validateSchema(manifest: any, { resolveFile }: { resolveFile: ResolveFile }) {
|
|
81
81
|
let filename = resolveFile(manifest.getIn(['schema', 'file']))
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
: ''
|
|
94
|
-
}
|
|
95
|
-
${groupedErrors
|
|
82
|
+
const validationErrors = validation.validateSchema(filename)
|
|
83
|
+
let errors: immutable.Collection<any, any>
|
|
84
|
+
|
|
85
|
+
if (validationErrors.size > 0) {
|
|
86
|
+
errors = validationErrors.groupBy(error => error.get('entity')).sort()
|
|
87
|
+
let msg = errors.reduce((msg, errors, entity) => {
|
|
88
|
+
errors = errors.groupBy((error: any) => error.get('directive'))
|
|
89
|
+
let inner_msgs = errors.reduce(
|
|
90
|
+
(msg: string, errors: any[], directive: string) => {
|
|
91
|
+
return `${msg}${directive ? `${directive}:` : ''}
|
|
92
|
+
${errors
|
|
96
93
|
.map(error =>
|
|
97
94
|
error
|
|
98
95
|
.get('message')
|
|
@@ -101,7 +98,9 @@ export default class Subgraph {
|
|
|
101
98
|
)
|
|
102
99
|
.map(msg => `${directive ? ' ' : ''}- ${msg}`)
|
|
103
100
|
.join('\n ')}`
|
|
104
|
-
|
|
101
|
+
},
|
|
102
|
+
``,
|
|
103
|
+
)
|
|
105
104
|
return `${msg}
|
|
106
105
|
|
|
107
106
|
${entity}:${inner_msgs}`
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import immutable from 'immutable'
|
|
2
|
-
|
|
3
|
-
export default class SubstreamsSubgraph {
|
|
4
|
-
constructor(options = {}) {
|
|
5
|
-
this.manifest = options.manifest
|
|
6
|
-
this.resolveFile = options.resolveFile
|
|
7
|
-
this.protocol = options.protocol
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
validateManifest() {
|
|
11
|
-
return immutable.List()
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
handlerTypes() {
|
|
15
|
-
return immutable.List([])
|
|
16
|
-
}
|
|
17
|
-
}
|