@graphprotocol/graph-cli 0.37.2 → 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 +7 -0
- package/babel.config.js +3 -0
- package/dist/bin.js +6 -0
- package/dist/cli.js +32 -0
- package/dist/codegen/schema.js +250 -0
- package/dist/codegen/schema.test.js +458 -0
- package/dist/codegen/template.js +65 -0
- package/dist/codegen/types/conversions.js +359 -0
- package/dist/codegen/types/index.js +71 -0
- package/dist/codegen/types/index.test.js +563 -0
- package/dist/codegen/typescript.js +200 -0
- package/dist/codegen/util.js +46 -0
- package/dist/codegen/util.test.js +93 -0
- package/dist/command-helpers/abi.js +78 -0
- package/dist/command-helpers/auth.js +77 -0
- package/dist/command-helpers/compiler.js +66 -0
- package/dist/command-helpers/data-sources.js +29 -0
- package/dist/command-helpers/fs.js +9 -0
- package/dist/command-helpers/gluegun.js +49 -0
- package/dist/command-helpers/ipfs.js +5 -0
- package/dist/command-helpers/jsonrpc.js +29 -0
- package/dist/command-helpers/network.js +93 -0
- package/dist/command-helpers/network.test.js +86 -0
- package/dist/command-helpers/node.js +40 -0
- package/dist/command-helpers/scaffold.js +112 -0
- package/dist/command-helpers/spinner.js +84 -0
- package/dist/command-helpers/studio.js +13 -0
- package/dist/command-helpers/studio.test.js +41 -0
- package/dist/command-helpers/subgraph.js +24 -0
- package/dist/command-helpers/version.js +74 -0
- package/dist/command-helpers/version.test.js +179 -0
- package/dist/commands/add.js +190 -0
- package/dist/commands/auth.js +127 -0
- package/dist/commands/build.js +140 -0
- package/dist/commands/codegen.js +135 -0
- package/dist/commands/create.js +86 -0
- package/dist/commands/deploy.js +334 -0
- package/dist/commands/init.js +788 -0
- package/dist/commands/local.js +387 -0
- package/dist/commands/remove.js +86 -0
- package/dist/commands/test.js +295 -0
- package/dist/compiler/asc.js +83 -0
- package/dist/compiler/index.js +474 -0
- package/dist/debug.js +16 -0
- package/dist/migrations/mapping_api_version_0_0_1.js +78 -0
- package/dist/migrations/mapping_api_version_0_0_2.js +76 -0
- package/dist/migrations/mapping_api_version_0_0_3.js +78 -0
- package/dist/migrations/mapping_api_version_0_0_4.js +80 -0
- package/dist/migrations/mapping_api_version_0_0_5.js +80 -0
- package/dist/migrations/spec_version_0_0_2.js +49 -0
- package/dist/migrations/spec_version_0_0_3.js +54 -0
- package/dist/migrations/util/load-manifest.js +18 -0
- package/dist/migrations/util/versions.js +29 -0
- package/dist/migrations.js +56 -0
- package/dist/protocols/arweave/manifest.graphql +57 -0
- package/dist/protocols/arweave/scaffold/manifest.js +18 -0
- package/dist/protocols/arweave/scaffold/mapping.js +52 -0
- package/dist/protocols/arweave/subgraph.js +23 -0
- package/dist/protocols/cosmos/manifest.graphql +76 -0
- package/dist/protocols/cosmos/scaffold/manifest.js +15 -0
- package/dist/protocols/cosmos/scaffold/mapping.js +38 -0
- package/dist/protocols/cosmos/subgraph.js +25 -0
- package/dist/protocols/ethereum/abi.js +140 -0
- package/dist/protocols/ethereum/codegen/abi.js +451 -0
- package/dist/protocols/ethereum/codegen/abi.test.js +328 -0
- package/dist/protocols/ethereum/codegen/template.js +50 -0
- package/dist/protocols/ethereum/contract.js +20 -0
- package/dist/protocols/ethereum/manifest.graphql +94 -0
- package/dist/protocols/ethereum/scaffold/manifest.js +32 -0
- package/dist/protocols/ethereum/scaffold/mapping.js +65 -0
- package/dist/protocols/ethereum/subgraph.js +171 -0
- package/dist/protocols/ethereum/type-generator.js +125 -0
- package/dist/protocols/index.js +268 -0
- package/dist/protocols/ipfs/codegen/file_template.js +50 -0
- package/dist/protocols/near/contract.js +41 -0
- package/dist/protocols/near/manifest.graphql +64 -0
- package/dist/protocols/near/scaffold/manifest.js +16 -0
- package/dist/protocols/near/scaffold/mapping.js +38 -0
- package/dist/protocols/near/subgraph.js +20 -0
- package/dist/protocols/subgraph.js +2 -0
- package/dist/protocols/substreams/manifest.graphql +45 -0
- package/dist/protocols/substreams/scaffold/manifest.js +12 -0
- package/dist/protocols/substreams/subgraph.js +23 -0
- package/dist/scaffold/cosmos.test.js +83 -0
- package/dist/scaffold/ethereum.test.js +505 -0
- package/dist/scaffold/index.js +128 -0
- package/dist/scaffold/mapping.js +61 -0
- package/dist/scaffold/near.test.js +86 -0
- package/dist/scaffold/schema.js +83 -0
- package/dist/scaffold/tests.js +175 -0
- package/dist/schema.js +54 -0
- package/dist/subgraph.js +249 -0
- package/dist/type-generator.js +224 -0
- package/dist/validation/contract.js +46 -0
- package/dist/validation/index.js +8 -0
- package/dist/validation/manifest.js +271 -0
- package/dist/validation/schema.js +796 -0
- package/dist/validation/schema.test.js +35 -0
- package/dist/watcher.js +79 -0
- package/jest.config.js +1 -1
- package/package.json +16 -9
- package/{bin/graph → src/bin.ts} +2 -1
- package/src/cli.ts +36 -0
- package/src/codegen/schema.js +23 -22
- package/src/codegen/schema.test.js +33 -27
- package/src/codegen/{template.js → template.ts} +8 -6
- package/src/codegen/types/conversions.ts +382 -0
- package/src/codegen/types/index.js +4 -7
- package/src/codegen/types/index.test.js +10 -4
- package/src/codegen/{typescript.js → typescript.ts} +44 -26
- package/src/codegen/util.js +1 -1
- package/src/codegen/util.test.js +5 -2
- package/src/command-helpers/abi.js +46 -30
- package/src/command-helpers/auth.js +6 -9
- package/src/command-helpers/compiler.js +4 -6
- package/src/command-helpers/data-sources.js +8 -11
- package/src/command-helpers/fs.ts +5 -0
- package/src/command-helpers/gluegun.js +2 -4
- package/src/command-helpers/ipfs.ts +3 -0
- package/src/command-helpers/{jsonrpc.js → jsonrpc.ts} +11 -16
- package/src/command-helpers/network.js +58 -44
- package/src/command-helpers/network.test.js +23 -19
- package/src/command-helpers/node.js +3 -7
- package/src/command-helpers/scaffold.js +34 -25
- package/src/command-helpers/{spinner.js → spinner.ts} +10 -10
- package/src/command-helpers/studio.test.js +61 -30
- package/src/command-helpers/studio.ts +20 -0
- package/src/command-helpers/{subgraph.js → subgraph.ts} +6 -6
- package/src/command-helpers/version.js +11 -16
- package/src/command-helpers/version.test.js +111 -82
- package/src/commands/add.js +49 -35
- package/src/commands/auth.js +13 -25
- package/src/commands/build.js +9 -9
- package/src/commands/codegen.js +12 -12
- package/src/commands/create.js +22 -22
- package/src/commands/deploy.js +39 -34
- package/src/commands/init.js +21 -24
- package/src/commands/local.js +15 -14
- package/src/commands/remove.js +22 -22
- package/src/commands/test.js +86 -70
- package/src/compiler/{asc.js → asc.ts} +29 -16
- package/src/compiler/index.js +18 -18
- package/src/{debug.js → debug.ts} +2 -2
- package/src/migrations/mapping_api_version_0_0_1.js +7 -7
- package/src/migrations/mapping_api_version_0_0_2.js +5 -5
- package/src/migrations/mapping_api_version_0_0_3.js +7 -7
- package/src/migrations/mapping_api_version_0_0_4.js +7 -7
- package/src/migrations/mapping_api_version_0_0_5.js +7 -7
- package/src/migrations/spec_version_0_0_2.js +5 -5
- package/src/migrations/spec_version_0_0_3.js +5 -5
- package/src/migrations/util/load-manifest.js +6 -9
- package/src/migrations/util/versions.js +5 -10
- package/src/{migrations.js → migrations.ts} +14 -15
- package/src/protocols/arweave/scaffold/manifest.js +1 -4
- package/src/protocols/arweave/scaffold/mapping.js +1 -3
- package/src/protocols/arweave/subgraph.ts +22 -0
- package/src/protocols/cosmos/scaffold/manifest.js +1 -4
- package/src/protocols/cosmos/scaffold/mapping.js +1 -3
- package/src/protocols/cosmos/subgraph.js +2 -2
- package/src/protocols/ethereum/abi.js +7 -13
- package/src/protocols/ethereum/codegen/abi.js +219 -222
- package/src/protocols/ethereum/codegen/abi.test.js +6 -6
- package/src/protocols/ethereum/codegen/template.js +3 -5
- package/src/protocols/ethereum/contract.js +3 -2
- package/src/protocols/ethereum/scaffold/manifest.js +4 -7
- package/src/protocols/ethereum/scaffold/mapping.js +4 -11
- package/src/protocols/ethereum/subgraph.js +21 -20
- package/src/protocols/ethereum/type-generator.js +24 -30
- package/src/protocols/{index.js → index.ts} +65 -46
- package/src/protocols/ipfs/codegen/file_template.js +2 -2
- package/src/protocols/near/{contract.js → contract.ts} +16 -12
- package/src/protocols/near/scaffold/manifest.js +2 -5
- package/src/protocols/near/scaffold/mapping.js +1 -3
- package/src/protocols/near/subgraph.js +3 -6
- package/src/protocols/subgraph.ts +12 -0
- package/src/protocols/substreams/scaffold/{manifest.js → manifest.ts} +2 -7
- package/src/protocols/substreams/subgraph.ts +22 -0
- package/src/scaffold/cosmos.test.js +3 -3
- package/src/scaffold/ethereum.test.js +4 -4
- package/src/scaffold/index.js +7 -7
- package/src/scaffold/mapping.js +3 -3
- package/src/scaffold/near.test.js +3 -3
- package/src/scaffold/schema.js +4 -4
- package/src/scaffold/tests.js +72 -58
- package/src/schema.ts +26 -0
- package/src/{subgraph.js → subgraph.ts} +80 -60
- package/src/type-generator.js +20 -20
- package/src/validation/contract.js +2 -6
- package/src/validation/index.js +1 -1
- package/src/validation/manifest.js +24 -22
- package/src/validation/schema.test.js +1 -1
- package/src/validation/{schema.js → schema.ts} +268 -221
- package/src/{watcher.js → watcher.ts} +23 -12
- package/tests/cli/globalSetup.js +2 -2
- package/tests/cli/globalTeardown.js +2 -2
- package/tests/cli/init.test.js +2 -2
- package/tests/cli/util.js +7 -13
- package/tsconfig.json +18 -0
- package/src/cli.js +0 -38
- package/src/codegen/types/conversions.js +0 -329
- package/src/command-helpers/fs.js +0 -8
- package/src/command-helpers/ipfs.js +0 -6
- package/src/command-helpers/studio.js +0 -15
- package/src/protocols/arweave/subgraph.js +0 -20
- package/src/protocols/substreams/subgraph.js +0 -17
- package/src/schema.js +0 -23
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import immutable from 'immutable'
|
|
2
|
+
import ABI from './abi'
|
|
3
|
+
import * as DataSourcesExtractor from '../../command-helpers/data-sources'
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
export default class EthereumSubgraph {
|
|
6
6
|
constructor(options = {}) {
|
|
7
7
|
this.manifest = options.manifest
|
|
8
8
|
this.resolveFile = options.resolveFile
|
|
@@ -16,7 +16,10 @@ module.exports = class EthereumSubgraph {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
validateAbis() {
|
|
19
|
-
const dataSourcesAndTemplates = DataSourcesExtractor.fromManifest(
|
|
19
|
+
const dataSourcesAndTemplates = DataSourcesExtractor.fromManifest(
|
|
20
|
+
this.manifest,
|
|
21
|
+
this.protocol,
|
|
22
|
+
)
|
|
20
23
|
|
|
21
24
|
return dataSourcesAndTemplates.reduce(
|
|
22
25
|
(errors, dataSourceOrTemplate) =>
|
|
@@ -71,17 +74,19 @@ ${abiNames
|
|
|
71
74
|
}
|
|
72
75
|
|
|
73
76
|
validateEvents() {
|
|
74
|
-
const dataSourcesAndTemplates = DataSourcesExtractor.fromManifest(
|
|
77
|
+
const dataSourcesAndTemplates = DataSourcesExtractor.fromManifest(
|
|
78
|
+
this.manifest,
|
|
79
|
+
this.protocol,
|
|
80
|
+
)
|
|
75
81
|
|
|
76
|
-
return dataSourcesAndTemplates
|
|
77
|
-
.
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}, immutable.List())
|
|
82
|
+
return dataSourcesAndTemplates.reduce((errors, dataSourceOrTemplate) => {
|
|
83
|
+
return errors.concat(
|
|
84
|
+
this.validateDataSourceEvents(
|
|
85
|
+
dataSourceOrTemplate.get('dataSource'),
|
|
86
|
+
dataSourceOrTemplate.get('path'),
|
|
87
|
+
),
|
|
88
|
+
)
|
|
89
|
+
}, immutable.List())
|
|
85
90
|
}
|
|
86
91
|
|
|
87
92
|
validateDataSourceEvents(dataSource, path) {
|
|
@@ -182,10 +187,6 @@ ${abiFunctions
|
|
|
182
187
|
}
|
|
183
188
|
|
|
184
189
|
handlerTypes() {
|
|
185
|
-
return immutable.List([
|
|
186
|
-
'blockHandlers',
|
|
187
|
-
'callHandlers',
|
|
188
|
-
'eventHandlers',
|
|
189
|
-
])
|
|
190
|
+
return immutable.List(['blockHandlers', 'callHandlers', 'eventHandlers'])
|
|
190
191
|
}
|
|
191
192
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import fs from 'fs-extra'
|
|
2
|
+
import path from 'path'
|
|
3
|
+
import immutable from 'immutable'
|
|
4
|
+
import prettier from 'prettier'
|
|
5
|
+
import ABI from './abi'
|
|
6
|
+
import { step, withSpinner } from '../../command-helpers/spinner'
|
|
7
|
+
import { GENERATED_FILE_NOTE } from '../../codegen/typescript'
|
|
8
|
+
import { displayPath } from '../../command-helpers/fs'
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
export default class EthereumTypeGenerator {
|
|
11
11
|
constructor(options = {}) {
|
|
12
12
|
this.sourceDir = options.sourceDir
|
|
13
13
|
this.outputDir = options.outputDir
|
|
@@ -24,20 +24,20 @@ module.exports = class EthereumTypeGenerator {
|
|
|
24
24
|
.get('dataSources')
|
|
25
25
|
.reduce(
|
|
26
26
|
(abis, dataSource) =>
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
27
|
+
dataSource
|
|
28
|
+
.getIn(['mapping', 'abis'])
|
|
29
|
+
.reduce(
|
|
30
|
+
(abis, abi) =>
|
|
31
|
+
abis.push(
|
|
32
|
+
this._loadABI(
|
|
33
|
+
dataSource,
|
|
34
|
+
abi.get('name'),
|
|
35
|
+
abi.get('file'),
|
|
36
|
+
spinner,
|
|
37
|
+
),
|
|
38
|
+
),
|
|
39
|
+
abis,
|
|
37
40
|
),
|
|
38
|
-
),
|
|
39
|
-
abis,
|
|
40
|
-
),
|
|
41
41
|
immutable.List(),
|
|
42
42
|
)
|
|
43
43
|
} catch (e) {
|
|
@@ -89,11 +89,7 @@ module.exports = class EthereumTypeGenerator {
|
|
|
89
89
|
try {
|
|
90
90
|
if (this.sourceDir) {
|
|
91
91
|
let absolutePath = path.resolve(this.sourceDir, maybeRelativePath)
|
|
92
|
-
step(
|
|
93
|
-
spinner,
|
|
94
|
-
`Load data source template ABI from`,
|
|
95
|
-
displayPath(absolutePath),
|
|
96
|
-
)
|
|
92
|
+
step(spinner, `Load data source template ABI from`, displayPath(absolutePath))
|
|
97
93
|
return { template, abi: ABI.load(name, absolutePath) }
|
|
98
94
|
} else {
|
|
99
95
|
return { template, abi: ABI.load(name, maybeRelativePath) }
|
|
@@ -170,9 +166,7 @@ module.exports = class EthereumTypeGenerator {
|
|
|
170
166
|
step(
|
|
171
167
|
spinner,
|
|
172
168
|
`Generate types for data source template ABI:`,
|
|
173
|
-
`${abi.template.get('name')} > ${abi.abi.name} (${displayPath(
|
|
174
|
-
abi.abi.file,
|
|
175
|
-
)})`,
|
|
169
|
+
`${abi.template.get('name')} > ${abi.abi.name} (${displayPath(abi.abi.file)})`,
|
|
176
170
|
)
|
|
177
171
|
|
|
178
172
|
let codeGenerator = abi.abi.codeGenerator()
|
|
@@ -1,35 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
1
|
+
import immutable from 'immutable'
|
|
2
|
+
import ArweaveSubgraph from './arweave/subgraph'
|
|
3
|
+
import EthereumTypeGenerator from './ethereum/type-generator'
|
|
4
|
+
import EthereumTemplateCodeGen from './ethereum/codegen/template'
|
|
5
|
+
import EthereumABI from './ethereum/abi'
|
|
6
|
+
import EthereumSubgraph from './ethereum/subgraph'
|
|
7
|
+
import NearSubgraph from './near/subgraph'
|
|
8
|
+
import CosmosSubgraph from './cosmos/subgraph'
|
|
9
|
+
import SubstreamsSubgraph from './substreams/subgraph'
|
|
10
|
+
import EthereumContract from './ethereum/contract'
|
|
11
|
+
import NearContract from './near/contract'
|
|
12
|
+
import * as ArweaveManifestScaffold from './arweave/scaffold/manifest'
|
|
13
|
+
import * as EthereumManifestScaffold from './ethereum/scaffold/manifest'
|
|
14
|
+
import * as NearManifestScaffold from './near/scaffold/manifest'
|
|
15
|
+
import * as CosmosManifestScaffold from './cosmos/scaffold/manifest'
|
|
16
|
+
import * as SubstreamsManifestScaffold from './substreams/scaffold/manifest'
|
|
17
|
+
import * as ArweaveMappingScaffold from './arweave/scaffold/mapping'
|
|
18
|
+
import * as EthereumMappingScaffold from './ethereum/scaffold/mapping'
|
|
19
|
+
import * as NearMappingScaffold from './near/scaffold/mapping'
|
|
20
|
+
import * as CosmosMappingScaffold from './cosmos/scaffold/mapping'
|
|
21
|
+
import debug from '../debug'
|
|
22
|
+
import Subgraph from '../subgraph'
|
|
23
|
+
import { SubgraphOptions } from './subgraph'
|
|
24
|
+
|
|
25
|
+
let protocolDebug = debug('graph-cli:protocol')
|
|
26
|
+
|
|
27
|
+
export default class Protocol {
|
|
28
|
+
static fromDataSources(dataSourcesAndTemplates: any) {
|
|
27
29
|
const firstDataSourceKind = dataSourcesAndTemplates[0].kind
|
|
28
30
|
return new Protocol(firstDataSourceKind)
|
|
29
31
|
}
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
|
|
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)!
|
|
33
40
|
|
|
34
41
|
switch (this.name) {
|
|
35
42
|
case 'arweave':
|
|
@@ -62,7 +69,7 @@ class Protocol {
|
|
|
62
69
|
near: ['near'],
|
|
63
70
|
cosmos: ['cosmos'],
|
|
64
71
|
substreams: ['substreams'],
|
|
65
|
-
})
|
|
72
|
+
}) as immutable.Collection<ProtocolName, string[]>
|
|
66
73
|
}
|
|
67
74
|
|
|
68
75
|
static availableNetworks() {
|
|
@@ -106,31 +113,31 @@ class Protocol {
|
|
|
106
113
|
'juno-1',
|
|
107
114
|
'uni-3', // Juno testnet
|
|
108
115
|
],
|
|
109
|
-
})
|
|
116
|
+
}) as immutable.Map<string, string[]>
|
|
110
117
|
|
|
111
|
-
let allNetworks = []
|
|
118
|
+
let allNetworks: string[] = []
|
|
112
119
|
networks.forEach(value => {
|
|
113
120
|
allNetworks.push(...value)
|
|
114
121
|
})
|
|
115
122
|
|
|
116
|
-
networks = networks.set('substreams',
|
|
123
|
+
networks = networks.set('substreams', allNetworks)
|
|
117
124
|
|
|
118
125
|
return networks
|
|
119
126
|
}
|
|
120
127
|
|
|
121
|
-
static normalizeName(name) {
|
|
128
|
+
static normalizeName(name: ProtocolName) {
|
|
122
129
|
return Protocol.availableProtocols().findKey(possibleNames => {
|
|
123
130
|
return possibleNames.includes(name)
|
|
124
|
-
})
|
|
131
|
+
})!
|
|
125
132
|
}
|
|
126
133
|
|
|
127
134
|
displayName() {
|
|
128
|
-
return this.config
|
|
135
|
+
return this.config?.displayName
|
|
129
136
|
}
|
|
130
137
|
|
|
131
138
|
// Receives a data source kind, and checks if it's valid
|
|
132
139
|
// for the given protocol instance (this).
|
|
133
|
-
isValidKindName(kind) {
|
|
140
|
+
isValidKindName(kind: string) {
|
|
134
141
|
return Protocol.availableProtocols()
|
|
135
142
|
.get(this.name, immutable.List())
|
|
136
143
|
.includes(kind)
|
|
@@ -156,10 +163,10 @@ class Protocol {
|
|
|
156
163
|
}
|
|
157
164
|
|
|
158
165
|
hasDataSourceMappingFile() {
|
|
159
|
-
return this.
|
|
166
|
+
return this.getMappingScaffold() != null
|
|
160
167
|
}
|
|
161
168
|
|
|
162
|
-
getTypeGenerator(options) {
|
|
169
|
+
getTypeGenerator(options: any) {
|
|
163
170
|
if (this.config == null || this.config.getTypeGenerator == null) {
|
|
164
171
|
return null
|
|
165
172
|
}
|
|
@@ -167,14 +174,14 @@ class Protocol {
|
|
|
167
174
|
return this.config.getTypeGenerator(options)
|
|
168
175
|
}
|
|
169
176
|
|
|
170
|
-
getTemplateCodeGen(template) {
|
|
177
|
+
getTemplateCodeGen(template: any) {
|
|
171
178
|
if (!this.hasTemplates()) {
|
|
172
179
|
throw new Error(
|
|
173
180
|
`Template data sources with kind '${this.name}' are not supported yet`,
|
|
174
181
|
)
|
|
175
182
|
}
|
|
176
183
|
|
|
177
|
-
return this.config.getTemplateCodeGen(template)
|
|
184
|
+
return this.config.getTemplateCodeGen?.(template)
|
|
178
185
|
}
|
|
179
186
|
|
|
180
187
|
getABI() {
|
|
@@ -198,7 +205,20 @@ class Protocol {
|
|
|
198
205
|
}
|
|
199
206
|
}
|
|
200
207
|
|
|
201
|
-
|
|
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 = {
|
|
202
222
|
displayName: 'Arweave',
|
|
203
223
|
abi: undefined,
|
|
204
224
|
contract: undefined,
|
|
@@ -211,7 +231,7 @@ const arweaveProtocol = {
|
|
|
211
231
|
mappingScaffold: ArweaveMappingScaffold,
|
|
212
232
|
}
|
|
213
233
|
|
|
214
|
-
const cosmosProtocol = {
|
|
234
|
+
const cosmosProtocol: ProtocolConfig = {
|
|
215
235
|
displayName: 'Cosmos',
|
|
216
236
|
abi: undefined,
|
|
217
237
|
contract: undefined,
|
|
@@ -224,7 +244,7 @@ const cosmosProtocol = {
|
|
|
224
244
|
mappingScaffold: CosmosMappingScaffold,
|
|
225
245
|
}
|
|
226
246
|
|
|
227
|
-
const ethereumProtocol = {
|
|
247
|
+
const ethereumProtocol: ProtocolConfig = {
|
|
228
248
|
displayName: 'Ethereum',
|
|
229
249
|
abi: EthereumABI,
|
|
230
250
|
contract: EthereumContract,
|
|
@@ -241,7 +261,7 @@ const ethereumProtocol = {
|
|
|
241
261
|
mappingScaffold: EthereumMappingScaffold,
|
|
242
262
|
}
|
|
243
263
|
|
|
244
|
-
const nearProtocol = {
|
|
264
|
+
const nearProtocol: ProtocolConfig = {
|
|
245
265
|
displayName: 'NEAR',
|
|
246
266
|
abi: undefined,
|
|
247
267
|
contract: NearContract,
|
|
@@ -254,7 +274,7 @@ const nearProtocol = {
|
|
|
254
274
|
mappingScaffold: NearMappingScaffold,
|
|
255
275
|
}
|
|
256
276
|
|
|
257
|
-
const substreamsProtocol = {
|
|
277
|
+
const substreamsProtocol: ProtocolConfig = {
|
|
258
278
|
displayName: 'Substreams',
|
|
259
279
|
abi: undefined,
|
|
260
280
|
contract: undefined,
|
|
@@ -268,4 +288,3 @@ const substreamsProtocol = {
|
|
|
268
288
|
}
|
|
269
289
|
|
|
270
290
|
protocolDebug('Available networks %M', Protocol.availableNetworks())
|
|
271
|
-
module.exports = Protocol
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import * as tsCodegen from '../../../codegen/typescript'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export default class IpfsFileTemplateCodeGen {
|
|
4
4
|
constructor(template) {
|
|
5
5
|
this.template = template
|
|
6
6
|
}
|
|
@@ -1,37 +1,41 @@
|
|
|
1
|
-
const MINIMUM_ACCOUNT_ID_LENGTH = 2
|
|
2
|
-
const MAXIMUM_ACCOUNT_ID_LENGTH = 64
|
|
1
|
+
const MINIMUM_ACCOUNT_ID_LENGTH = 2 as const
|
|
2
|
+
const MAXIMUM_ACCOUNT_ID_LENGTH = 64 as const
|
|
3
3
|
|
|
4
|
-
const RULES_URL = 'https://docs.near.org/docs/concepts/account#account-id-rules'
|
|
4
|
+
const RULES_URL = 'https://docs.near.org/docs/concepts/account#account-id-rules' as const
|
|
5
|
+
|
|
6
|
+
export default class NearContract {
|
|
7
|
+
private account: string
|
|
5
8
|
|
|
6
|
-
module.exports = class NearContract {
|
|
7
9
|
static identifierName() {
|
|
8
10
|
return 'account'
|
|
9
11
|
}
|
|
10
12
|
|
|
11
|
-
constructor(account) {
|
|
13
|
+
constructor(account: string) {
|
|
12
14
|
this.account = account
|
|
13
15
|
}
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
return
|
|
17
|
-
|
|
17
|
+
private validateLength(value: string) {
|
|
18
|
+
return (
|
|
19
|
+
value.length >= MINIMUM_ACCOUNT_ID_LENGTH &&
|
|
20
|
+
value.length <= MAXIMUM_ACCOUNT_ID_LENGTH
|
|
21
|
+
)
|
|
18
22
|
}
|
|
19
23
|
|
|
20
|
-
|
|
24
|
+
private validateFormat(value: string) {
|
|
21
25
|
const pattern = /^(([a-z\d]+[\-_])*[a-z\d]+\.)*([a-z\d]+[\-_])*[a-z\d]+$/
|
|
22
26
|
|
|
23
|
-
return pattern.test(
|
|
27
|
+
return pattern.test(value)
|
|
24
28
|
}
|
|
25
29
|
|
|
26
30
|
validate() {
|
|
27
|
-
if (!this.
|
|
31
|
+
if (!this.validateLength(this.account)) {
|
|
28
32
|
return {
|
|
29
33
|
valid: false,
|
|
30
34
|
error: `Account must be between '${MINIMUM_ACCOUNT_ID_LENGTH}' and '${MAXIMUM_ACCOUNT_ID_LENGTH}' characters, see ${RULES_URL}`,
|
|
31
35
|
}
|
|
32
36
|
}
|
|
33
37
|
|
|
34
|
-
if (!this.
|
|
38
|
+
if (!this.validateFormat(this.account)) {
|
|
35
39
|
return {
|
|
36
40
|
valid: false,
|
|
37
41
|
error: `Account must conform to the rules on ${RULES_URL}`,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { strings } from 'gluegun'
|
|
2
2
|
|
|
3
3
|
const source = ({ contract }) => `
|
|
4
4
|
account: '${contract}'`
|
|
@@ -12,7 +12,4 @@ const mapping = ({ contractName }) => `
|
|
|
12
12
|
- handler: handleReceipt
|
|
13
13
|
file: ./src/${strings.kebabCase(contractName)}.ts`
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
source,
|
|
17
|
-
mapping,
|
|
18
|
-
}
|
|
15
|
+
export { source, mapping }
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import immutable from 'immutable'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export default class NearSubgraph {
|
|
4
4
|
constructor(options = {}) {
|
|
5
5
|
this.manifest = options.manifest
|
|
6
6
|
this.resolveFile = options.resolveFile
|
|
@@ -12,9 +12,6 @@ module.exports = class NearSubgraph {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
handlerTypes() {
|
|
15
|
-
return immutable.List([
|
|
16
|
-
'blockHandlers',
|
|
17
|
-
'receiptHandlers',
|
|
18
|
-
])
|
|
15
|
+
return immutable.List(['blockHandlers', 'receiptHandlers'])
|
|
19
16
|
}
|
|
20
17
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import immutable from 'immutable'
|
|
2
|
+
|
|
3
|
+
export interface SubgraphOptions {
|
|
4
|
+
manifest?: any
|
|
5
|
+
resolveFile?: (path: string) => string
|
|
6
|
+
protocol?: any
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface Subgraph extends SubgraphOptions {
|
|
10
|
+
validateManifest(): immutable.List<any>
|
|
11
|
+
handlerTypes(): immutable.List<any>
|
|
12
|
+
}
|
|
@@ -1,13 +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
|
-
module.exports = {
|
|
11
|
-
source,
|
|
12
|
-
mapping,
|
|
13
|
-
}
|
|
@@ -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
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import ABI from '../protocols/ethereum/abi'
|
|
2
|
+
import immutable from 'immutable'
|
|
3
|
+
import Scaffold from './'
|
|
4
|
+
import Protocol from '../protocols'
|
|
5
5
|
|
|
6
6
|
const TEST_EVENT = {
|
|
7
7
|
name: 'ExampleEvent',
|
package/src/scaffold/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import prettier from 'prettier'
|
|
2
2
|
const pkginfo = require('pkginfo')(module)
|
|
3
|
-
|
|
3
|
+
import { strings } from 'gluegun'
|
|
4
4
|
|
|
5
5
|
const GRAPH_CLI_VERSION = process.env.GRAPH_CLI_TESTS
|
|
6
6
|
? // JSON.stringify should remove this key, we will install the local
|
|
@@ -9,12 +9,12 @@ const GRAPH_CLI_VERSION = process.env.GRAPH_CLI_TESTS
|
|
|
9
9
|
: // For scaffolding real subgraphs
|
|
10
10
|
`${module.exports.version}`
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
import { abiEvents, generateEventType, generateExampleEntityType } from './schema'
|
|
13
|
+
import { generateEventIndexingHandlers } from './mapping'
|
|
14
|
+
import { generateTestsFiles } from './tests'
|
|
15
|
+
import { getSubgraphBasename } from '../command-helpers/subgraph'
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
export default class Scaffold {
|
|
18
18
|
constructor(options = {}) {
|
|
19
19
|
this.protocol = options.protocol
|
|
20
20
|
this.abi = options.abi
|
package/src/scaffold/mapping.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import path from 'path'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import * as util from '../codegen/util'
|
|
4
4
|
|
|
5
5
|
const generateFieldAssignment = path =>
|
|
6
6
|
`entity.${path.join('_')} = event.params.${path.join('.')}`
|
|
@@ -46,7 +46,7 @@ const generateEventIndexingHandlers = (events, contractName) =>
|
|
|
46
46
|
.join('\n')}
|
|
47
47
|
`
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
export {
|
|
50
50
|
generateFieldAssignment,
|
|
51
51
|
generateFieldAssignments,
|
|
52
52
|
generateEventFieldAssignments,
|
package/src/scaffold/schema.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { ascTypeForProtocol, valueTypeForAsc } from '../codegen/types'
|
|
2
|
+
import * as util from '../codegen/util'
|
|
3
3
|
|
|
4
4
|
const abiEvents = abi =>
|
|
5
5
|
util.disambiguateNames({
|
|
@@ -41,7 +41,7 @@ const generateEventType = (event, protocolName) => `type ${
|
|
|
41
41
|
acc.concat(generateEventFields({ input, index, protocolName })),
|
|
42
42
|
[],
|
|
43
43
|
)
|
|
44
|
-
.join('\n')}
|
|
44
|
+
.join('\n')}
|
|
45
45
|
blockNumber: BigInt!
|
|
46
46
|
blockTimestamp: BigInt!
|
|
47
47
|
transactionHash: Bytes!
|
|
@@ -70,7 +70,7 @@ const generateExampleEntityType = (protocol, events) => {
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
export {
|
|
74
74
|
abiEvents,
|
|
75
75
|
protocolTypeToGraphQL,
|
|
76
76
|
generateField,
|