@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.
Files changed (206) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/babel.config.js +3 -0
  3. package/dist/bin.js +6 -0
  4. package/dist/cli.js +32 -0
  5. package/dist/codegen/schema.js +250 -0
  6. package/dist/codegen/schema.test.js +458 -0
  7. package/dist/codegen/template.js +65 -0
  8. package/dist/codegen/types/conversions.js +359 -0
  9. package/dist/codegen/types/index.js +71 -0
  10. package/dist/codegen/types/index.test.js +563 -0
  11. package/dist/codegen/typescript.js +200 -0
  12. package/dist/codegen/util.js +46 -0
  13. package/dist/codegen/util.test.js +93 -0
  14. package/dist/command-helpers/abi.js +78 -0
  15. package/dist/command-helpers/auth.js +77 -0
  16. package/dist/command-helpers/compiler.js +66 -0
  17. package/dist/command-helpers/data-sources.js +29 -0
  18. package/dist/command-helpers/fs.js +9 -0
  19. package/dist/command-helpers/gluegun.js +49 -0
  20. package/dist/command-helpers/ipfs.js +5 -0
  21. package/dist/command-helpers/jsonrpc.js +29 -0
  22. package/dist/command-helpers/network.js +93 -0
  23. package/dist/command-helpers/network.test.js +86 -0
  24. package/dist/command-helpers/node.js +40 -0
  25. package/dist/command-helpers/scaffold.js +112 -0
  26. package/dist/command-helpers/spinner.js +84 -0
  27. package/dist/command-helpers/studio.js +13 -0
  28. package/dist/command-helpers/studio.test.js +41 -0
  29. package/dist/command-helpers/subgraph.js +24 -0
  30. package/dist/command-helpers/version.js +74 -0
  31. package/dist/command-helpers/version.test.js +179 -0
  32. package/dist/commands/add.js +190 -0
  33. package/dist/commands/auth.js +127 -0
  34. package/dist/commands/build.js +140 -0
  35. package/dist/commands/codegen.js +135 -0
  36. package/dist/commands/create.js +86 -0
  37. package/dist/commands/deploy.js +334 -0
  38. package/dist/commands/init.js +788 -0
  39. package/dist/commands/local.js +387 -0
  40. package/dist/commands/remove.js +86 -0
  41. package/dist/commands/test.js +295 -0
  42. package/dist/compiler/asc.js +83 -0
  43. package/dist/compiler/index.js +474 -0
  44. package/dist/debug.js +16 -0
  45. package/dist/migrations/mapping_api_version_0_0_1.js +78 -0
  46. package/dist/migrations/mapping_api_version_0_0_2.js +76 -0
  47. package/dist/migrations/mapping_api_version_0_0_3.js +78 -0
  48. package/dist/migrations/mapping_api_version_0_0_4.js +80 -0
  49. package/dist/migrations/mapping_api_version_0_0_5.js +80 -0
  50. package/dist/migrations/spec_version_0_0_2.js +49 -0
  51. package/dist/migrations/spec_version_0_0_3.js +54 -0
  52. package/dist/migrations/util/load-manifest.js +18 -0
  53. package/dist/migrations/util/versions.js +29 -0
  54. package/dist/migrations.js +56 -0
  55. package/dist/protocols/arweave/manifest.graphql +57 -0
  56. package/dist/protocols/arweave/scaffold/manifest.js +18 -0
  57. package/dist/protocols/arweave/scaffold/mapping.js +52 -0
  58. package/dist/protocols/arweave/subgraph.js +23 -0
  59. package/dist/protocols/cosmos/manifest.graphql +76 -0
  60. package/dist/protocols/cosmos/scaffold/manifest.js +15 -0
  61. package/dist/protocols/cosmos/scaffold/mapping.js +38 -0
  62. package/dist/protocols/cosmos/subgraph.js +25 -0
  63. package/dist/protocols/ethereum/abi.js +140 -0
  64. package/dist/protocols/ethereum/codegen/abi.js +451 -0
  65. package/dist/protocols/ethereum/codegen/abi.test.js +328 -0
  66. package/dist/protocols/ethereum/codegen/template.js +50 -0
  67. package/dist/protocols/ethereum/contract.js +20 -0
  68. package/dist/protocols/ethereum/manifest.graphql +94 -0
  69. package/dist/protocols/ethereum/scaffold/manifest.js +32 -0
  70. package/dist/protocols/ethereum/scaffold/mapping.js +65 -0
  71. package/dist/protocols/ethereum/subgraph.js +171 -0
  72. package/dist/protocols/ethereum/type-generator.js +125 -0
  73. package/dist/protocols/index.js +268 -0
  74. package/dist/protocols/ipfs/codegen/file_template.js +50 -0
  75. package/dist/protocols/near/contract.js +41 -0
  76. package/dist/protocols/near/manifest.graphql +64 -0
  77. package/dist/protocols/near/scaffold/manifest.js +16 -0
  78. package/dist/protocols/near/scaffold/mapping.js +38 -0
  79. package/dist/protocols/near/subgraph.js +20 -0
  80. package/dist/protocols/subgraph.js +2 -0
  81. package/dist/protocols/substreams/manifest.graphql +45 -0
  82. package/dist/protocols/substreams/scaffold/manifest.js +12 -0
  83. package/dist/protocols/substreams/subgraph.js +23 -0
  84. package/dist/scaffold/cosmos.test.js +83 -0
  85. package/dist/scaffold/ethereum.test.js +505 -0
  86. package/dist/scaffold/index.js +128 -0
  87. package/dist/scaffold/mapping.js +61 -0
  88. package/dist/scaffold/near.test.js +86 -0
  89. package/dist/scaffold/schema.js +83 -0
  90. package/dist/scaffold/tests.js +175 -0
  91. package/dist/schema.js +54 -0
  92. package/dist/subgraph.js +249 -0
  93. package/dist/type-generator.js +224 -0
  94. package/dist/validation/contract.js +46 -0
  95. package/dist/validation/index.js +8 -0
  96. package/dist/validation/manifest.js +271 -0
  97. package/dist/validation/schema.js +796 -0
  98. package/dist/validation/schema.test.js +35 -0
  99. package/dist/watcher.js +79 -0
  100. package/jest.config.js +1 -1
  101. package/package.json +16 -9
  102. package/{bin/graph → src/bin.ts} +2 -1
  103. package/src/cli.ts +36 -0
  104. package/src/codegen/schema.js +23 -22
  105. package/src/codegen/schema.test.js +33 -27
  106. package/src/codegen/{template.js → template.ts} +8 -6
  107. package/src/codegen/types/conversions.ts +382 -0
  108. package/src/codegen/types/index.js +4 -7
  109. package/src/codegen/types/index.test.js +10 -4
  110. package/src/codegen/{typescript.js → typescript.ts} +44 -26
  111. package/src/codegen/util.js +1 -1
  112. package/src/codegen/util.test.js +5 -2
  113. package/src/command-helpers/abi.js +46 -30
  114. package/src/command-helpers/auth.js +6 -9
  115. package/src/command-helpers/compiler.js +4 -6
  116. package/src/command-helpers/data-sources.js +8 -11
  117. package/src/command-helpers/fs.ts +5 -0
  118. package/src/command-helpers/gluegun.js +2 -4
  119. package/src/command-helpers/ipfs.ts +3 -0
  120. package/src/command-helpers/{jsonrpc.js → jsonrpc.ts} +11 -16
  121. package/src/command-helpers/network.js +58 -44
  122. package/src/command-helpers/network.test.js +23 -19
  123. package/src/command-helpers/node.js +3 -7
  124. package/src/command-helpers/scaffold.js +34 -25
  125. package/src/command-helpers/{spinner.js → spinner.ts} +10 -10
  126. package/src/command-helpers/studio.test.js +61 -30
  127. package/src/command-helpers/studio.ts +20 -0
  128. package/src/command-helpers/{subgraph.js → subgraph.ts} +6 -6
  129. package/src/command-helpers/version.js +11 -16
  130. package/src/command-helpers/version.test.js +111 -82
  131. package/src/commands/add.js +49 -35
  132. package/src/commands/auth.js +13 -25
  133. package/src/commands/build.js +9 -9
  134. package/src/commands/codegen.js +12 -12
  135. package/src/commands/create.js +22 -22
  136. package/src/commands/deploy.js +39 -34
  137. package/src/commands/init.js +21 -24
  138. package/src/commands/local.js +15 -14
  139. package/src/commands/remove.js +22 -22
  140. package/src/commands/test.js +86 -70
  141. package/src/compiler/{asc.js → asc.ts} +29 -16
  142. package/src/compiler/index.js +18 -18
  143. package/src/{debug.js → debug.ts} +2 -2
  144. package/src/migrations/mapping_api_version_0_0_1.js +7 -7
  145. package/src/migrations/mapping_api_version_0_0_2.js +5 -5
  146. package/src/migrations/mapping_api_version_0_0_3.js +7 -7
  147. package/src/migrations/mapping_api_version_0_0_4.js +7 -7
  148. package/src/migrations/mapping_api_version_0_0_5.js +7 -7
  149. package/src/migrations/spec_version_0_0_2.js +5 -5
  150. package/src/migrations/spec_version_0_0_3.js +5 -5
  151. package/src/migrations/util/load-manifest.js +6 -9
  152. package/src/migrations/util/versions.js +5 -10
  153. package/src/{migrations.js → migrations.ts} +14 -15
  154. package/src/protocols/arweave/scaffold/manifest.js +1 -4
  155. package/src/protocols/arweave/scaffold/mapping.js +1 -3
  156. package/src/protocols/arweave/subgraph.ts +22 -0
  157. package/src/protocols/cosmos/scaffold/manifest.js +1 -4
  158. package/src/protocols/cosmos/scaffold/mapping.js +1 -3
  159. package/src/protocols/cosmos/subgraph.js +2 -2
  160. package/src/protocols/ethereum/abi.js +7 -13
  161. package/src/protocols/ethereum/codegen/abi.js +219 -222
  162. package/src/protocols/ethereum/codegen/abi.test.js +6 -6
  163. package/src/protocols/ethereum/codegen/template.js +3 -5
  164. package/src/protocols/ethereum/contract.js +3 -2
  165. package/src/protocols/ethereum/scaffold/manifest.js +4 -7
  166. package/src/protocols/ethereum/scaffold/mapping.js +4 -11
  167. package/src/protocols/ethereum/subgraph.js +21 -20
  168. package/src/protocols/ethereum/type-generator.js +24 -30
  169. package/src/protocols/{index.js → index.ts} +65 -46
  170. package/src/protocols/ipfs/codegen/file_template.js +2 -2
  171. package/src/protocols/near/{contract.js → contract.ts} +16 -12
  172. package/src/protocols/near/scaffold/manifest.js +2 -5
  173. package/src/protocols/near/scaffold/mapping.js +1 -3
  174. package/src/protocols/near/subgraph.js +3 -6
  175. package/src/protocols/subgraph.ts +12 -0
  176. package/src/protocols/substreams/scaffold/{manifest.js → manifest.ts} +2 -7
  177. package/src/protocols/substreams/subgraph.ts +22 -0
  178. package/src/scaffold/cosmos.test.js +3 -3
  179. package/src/scaffold/ethereum.test.js +4 -4
  180. package/src/scaffold/index.js +7 -7
  181. package/src/scaffold/mapping.js +3 -3
  182. package/src/scaffold/near.test.js +3 -3
  183. package/src/scaffold/schema.js +4 -4
  184. package/src/scaffold/tests.js +72 -58
  185. package/src/schema.ts +26 -0
  186. package/src/{subgraph.js → subgraph.ts} +80 -60
  187. package/src/type-generator.js +20 -20
  188. package/src/validation/contract.js +2 -6
  189. package/src/validation/index.js +1 -1
  190. package/src/validation/manifest.js +24 -22
  191. package/src/validation/schema.test.js +1 -1
  192. package/src/validation/{schema.js → schema.ts} +268 -221
  193. package/src/{watcher.js → watcher.ts} +23 -12
  194. package/tests/cli/globalSetup.js +2 -2
  195. package/tests/cli/globalTeardown.js +2 -2
  196. package/tests/cli/init.test.js +2 -2
  197. package/tests/cli/util.js +7 -13
  198. package/tsconfig.json +18 -0
  199. package/src/cli.js +0 -38
  200. package/src/codegen/types/conversions.js +0 -329
  201. package/src/command-helpers/fs.js +0 -8
  202. package/src/command-helpers/ipfs.js +0 -6
  203. package/src/command-helpers/studio.js +0 -15
  204. package/src/protocols/arweave/subgraph.js +0 -20
  205. package/src/protocols/substreams/subgraph.js +0 -17
  206. package/src/schema.js +0 -23
@@ -1,8 +1,8 @@
1
- const immutable = require('immutable')
2
- const ABI = require('./abi')
3
- const DataSourcesExtractor = require('../../command-helpers/data-sources')
1
+ import immutable from 'immutable'
2
+ import ABI from './abi'
3
+ import * as DataSourcesExtractor from '../../command-helpers/data-sources'
4
4
 
5
- module.exports = class EthereumSubgraph {
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(this.manifest, this.protocol)
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(this.manifest, this.protocol)
77
+ const dataSourcesAndTemplates = DataSourcesExtractor.fromManifest(
78
+ this.manifest,
79
+ this.protocol,
80
+ )
75
81
 
76
- return dataSourcesAndTemplates
77
- .reduce((errors, dataSourceOrTemplate) => {
78
- return errors.concat(
79
- this.validateDataSourceEvents(
80
- dataSourceOrTemplate.get('dataSource'),
81
- dataSourceOrTemplate.get('path'),
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
- const fs = require('fs-extra')
2
- const path = require('path')
3
- const immutable = require('immutable')
4
- const prettier = require('prettier')
5
- const ABI = require('./abi')
6
- const { step, withSpinner } = require('../../command-helpers/spinner')
7
- const { GENERATED_FILE_NOTE } = require('../../codegen/typescript')
8
- const { displayPath } = require('../../command-helpers/fs')
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
- module.exports = class EthereumTypeGenerator {
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
- 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,
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
- const immutable = require('immutable')
2
- const ArweaveSubgraph = require('./arweave/subgraph')
3
- const EthereumTypeGenerator = require('./ethereum/type-generator')
4
- const EthereumTemplateCodeGen = require('./ethereum/codegen/template')
5
- const EthereumABI = require('./ethereum/abi')
6
- const EthereumSubgraph = require('./ethereum/subgraph')
7
- const NearSubgraph = require('./near/subgraph')
8
- const CosmosSubgraph = require('./cosmos/subgraph')
9
- const SubstreamsSubgraph = require('./substreams/subgraph')
10
- const EthereumContract = require('./ethereum/contract')
11
- const NearContract = require('./near/contract')
12
- const ArweaveManifestScaffold = require('./arweave/scaffold/manifest')
13
- const EthereumManifestScaffold = require('./ethereum/scaffold/manifest')
14
- const NearManifestScaffold = require('./near/scaffold/manifest')
15
- const CosmosManifestScaffold = require('./cosmos/scaffold/manifest')
16
- const SubstreamsManifestScaffold = require('./substreams/scaffold/manifest')
17
- const ArweaveMappingScaffold = require('./arweave/scaffold/mapping')
18
- const EthereumMappingScaffold = require('./ethereum/scaffold/mapping')
19
- const NearMappingScaffold = require('./near/scaffold/mapping')
20
- const CosmosMappingScaffold = require('./cosmos/scaffold/mapping')
21
- const { ThrowStatement } = require('assemblyscript')
22
-
23
- let protocolDebug = require('../debug')('graph-cli:protocol')
24
-
25
- class Protocol {
26
- static fromDataSources(dataSourcesAndTemplates) {
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
- constructor(name) {
32
- this.name = Protocol.normalizeName(name)
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', immutable.fromJS(allNetworks))
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.displayName
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.config.getMappingScaffold != null
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
- const arweaveProtocol = {
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
- const tsCodegen = require('../../../codegen/typescript')
1
+ import * as tsCodegen from '../../../codegen/typescript'
2
2
 
3
- module.exports = class IpfsFileTemplateCodeGen {
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
- _validateLength() {
16
- return this.account.length >= MINIMUM_ACCOUNT_ID_LENGTH &&
17
- this.account.length <= MAXIMUM_ACCOUNT_ID_LENGTH
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
- _validateFormat() {
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(this.account)
27
+ return pattern.test(value)
24
28
  }
25
29
 
26
30
  validate() {
27
- if (!this._validateLength(this.account)) {
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._validateFormat()) {
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
- const { strings } = require('gluegun')
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
- module.exports = {
16
- source,
17
- mapping,
18
- }
15
+ export { source, mapping }
@@ -34,6 +34,4 @@ const generatePlaceholderHandlers = () =>
34
34
  }
35
35
  `
36
36
 
37
- module.exports = {
38
- generatePlaceholderHandlers,
39
- }
37
+ export { generatePlaceholderHandlers }
@@ -1,6 +1,6 @@
1
- const immutable = require('immutable')
1
+ import immutable from 'immutable'
2
2
 
3
- module.exports = class NearSubgraph {
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,6 +1,6 @@
1
- const immutable = require('immutable')
2
- const Scaffold = require('./')
3
- const Protocol = require('../protocols')
1
+ import immutable from 'immutable'
2
+ import Scaffold from './'
3
+ import Protocol from '../protocols'
4
4
 
5
5
  const protocol = new Protocol('cosmos')
6
6
 
@@ -1,7 +1,7 @@
1
- const ABI = require('../protocols/ethereum/abi')
2
- const immutable = require('immutable')
3
- const Scaffold = require('./')
4
- const Protocol = require('../protocols')
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',
@@ -1,6 +1,6 @@
1
- const prettier = require('prettier')
1
+ import prettier from 'prettier'
2
2
  const pkginfo = require('pkginfo')(module)
3
- const { strings } = require('gluegun')
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
- const { abiEvents, generateEventType, generateExampleEntityType } = require('./schema')
13
- const { generateEventIndexingHandlers } = require('./mapping')
14
- const { generateTestsFiles } = require('./tests')
15
- const { getSubgraphBasename } = require('../command-helpers/subgraph')
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
- module.exports = class Scaffold {
17
+ export default class Scaffold {
18
18
  constructor(options = {}) {
19
19
  this.protocol = options.protocol
20
20
  this.abi = options.abi
@@ -1,6 +1,6 @@
1
- const path = require('path')
1
+ import path from 'path'
2
2
 
3
- const util = require('../codegen/util')
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
- module.exports = {
49
+ export {
50
50
  generateFieldAssignment,
51
51
  generateFieldAssignments,
52
52
  generateEventFieldAssignments,
@@ -1,6 +1,6 @@
1
- const immutable = require('immutable')
2
- const Scaffold = require('./')
3
- const Protocol = require('../protocols')
1
+ import immutable from 'immutable'
2
+ import Scaffold from './'
3
+ import Protocol from '../protocols'
4
4
 
5
5
  const protocol = new Protocol('near')
6
6
 
@@ -1,5 +1,5 @@
1
- const { ascTypeForProtocol, valueTypeForAsc } = require('../codegen/types')
2
- const util = require('../codegen/util')
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
- module.exports = {
73
+ export {
74
74
  abiEvents,
75
75
  protocolTypeToGraphQL,
76
76
  generateField,