@graphprotocol/graph-cli 0.29.2 → 0.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/chain/arweave.ts +76 -0
  2. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/chain/cosmos.ts +341 -0
  3. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/chain/ethereum.ts +39 -0
  4. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/global/global.ts +286 -142
  5. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/index.ts +4 -2
  6. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/package.json +2 -1
  7. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/test/test.js +4 -2
  8. package/examples/basic-event-handlers/node_modules/keccak/build/config.gypi +300 -125
  9. package/examples/basic-event-handlers/node_modules/websocket/build/config.gypi +292 -15
  10. package/examples/basic-event-handlers/package.json +1 -1
  11. package/examples/basic-event-handlers/yarn.lock +4 -4
  12. package/examples/example-subgraph/package.json +1 -1
  13. package/examples/example-subgraph/yarn.lock +4 -4
  14. package/package.json +1 -1
  15. package/resources/test/docker-compose.yml +4 -2
  16. package/src/codegen/schema.js +5 -1
  17. package/src/codegen/schema.test.js +102 -0
  18. package/src/command-helpers/abi.js +69 -0
  19. package/src/command-helpers/scaffold.js +67 -0
  20. package/src/commands/add.js +198 -0
  21. package/src/commands/deploy.js +0 -5
  22. package/src/commands/init.js +25 -71
  23. package/src/migrations/mapping_api_version_0_0_5.js +1 -1
  24. package/src/migrations/mapping_api_version_0_0_6.js +74 -0
  25. package/src/migrations/spec_version_0_0_2.js +1 -1
  26. package/src/migrations/spec_version_0_0_3.js +29 -0
  27. package/src/migrations/spec_version_0_0_4.js +25 -0
  28. package/src/migrations.js +4 -0
  29. package/src/protocols/arweave/manifest.graphql +57 -0
  30. package/src/protocols/arweave/scaffold/manifest.js +19 -0
  31. package/src/protocols/arweave/scaffold/mapping.js +53 -0
  32. package/src/protocols/arweave/subgraph.js +20 -0
  33. package/src/protocols/{tendermint → cosmos}/manifest.graphql +6 -0
  34. package/src/protocols/cosmos/scaffold/manifest.js +16 -0
  35. package/src/protocols/cosmos/scaffold/mapping.js +39 -0
  36. package/src/protocols/{tendermint → cosmos}/subgraph.js +2 -1
  37. package/src/protocols/ethereum/codegen/abi.js +12 -0
  38. package/src/protocols/ethereum/manifest.graphql +2 -0
  39. package/src/protocols/ethereum/scaffold/manifest.js +2 -1
  40. package/src/protocols/index.js +53 -20
  41. package/src/protocols/near/manifest.graphql +1 -0
  42. package/src/protocols/near/scaffold/manifest.js +4 -2
  43. package/src/scaffold/cosmos.test.js +86 -0
  44. package/src/scaffold/ethereum.test.js +2 -1
  45. package/src/scaffold/index.js +5 -3
  46. package/src/scaffold/near.test.js +2 -1
  47. package/src/validation/manifest.js +64 -12
  48. package/src/validation/schema.js +2 -0
  49. package/tests/cli/validation/conflicting-protocol-names/Abi.json +7 -0
  50. package/tests/cli/validation/conflicting-protocol-names/mapping.ts +0 -0
  51. package/tests/cli/validation/conflicting-protocol-names/schema.graphql +3 -0
  52. package/tests/cli/validation/conflicting-protocol-names/subgraph.yaml +41 -0
  53. package/tests/cli/validation/conflicting-protocol-names.stderr +10 -0
  54. package/tests/cli/validation.test.js +9 -0
  55. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/chain/tendermint.ts +0 -554
  56. package/examples/basic-event-handlers/node_modules/keccak/build/Makefile +0 -342
  57. package/examples/basic-event-handlers/node_modules/keccak/build/Release/.deps/Release/obj.target/keccak/src/addon.o.d.raw +0 -27
  58. package/examples/basic-event-handlers/node_modules/keccak/build/binding.Makefile +0 -6
  59. package/examples/basic-event-handlers/node_modules/keccak/build/gyp-mac-tool +0 -615
  60. package/examples/basic-event-handlers/node_modules/keccak/build/keccak.target.mk +0 -209
  61. package/examples/basic-event-handlers/node_modules/websocket/build/Makefile +0 -347
  62. package/examples/basic-event-handlers/node_modules/websocket/build/Release/.deps/Release/obj.target/bufferutil/src/bufferutil.o.d.raw +0 -25
  63. package/examples/basic-event-handlers/node_modules/websocket/build/binding.Makefile +0 -6
  64. package/examples/basic-event-handlers/node_modules/websocket/build/bufferutil.target.mk +0 -192
  65. package/examples/basic-event-handlers/node_modules/websocket/build/gyp-mac-tool +0 -615
  66. package/examples/basic-event-handlers/node_modules/websocket/build/validation.target.mk +0 -192
  67. package/src/codegen/types/defaults.js +0 -34
  68. package/tests/cli/init/ethereum/from-example/.gitattributes +0 -1
  69. package/tests/cli/init/ethereum/from-example/LICENSE +0 -21
  70. package/tests/cli/init/ethereum/from-example/README.md +0 -3
  71. package/tests/cli/init/ethereum/from-example/abis/Gravity.json +0 -1
  72. package/tests/cli/init/ethereum/from-example/bin/Counter.bin +0 -1
  73. package/tests/cli/init/ethereum/from-example/contracts/Gravity.sol +0 -63
  74. package/tests/cli/init/ethereum/from-example/contracts/Migrations.sol +0 -23
  75. package/tests/cli/init/ethereum/from-example/docker-compose.yml +0 -39
  76. package/tests/cli/init/ethereum/from-example/migrations/1_initial_migration.js +0 -5
  77. package/tests/cli/init/ethereum/from-example/migrations/2_deploy_contract.js +0 -5
  78. package/tests/cli/init/ethereum/from-example/migrations/3_create_gravatars.js +0 -15
  79. package/tests/cli/init/ethereum/from-example/networks.json +0 -7
  80. package/tests/cli/init/ethereum/from-example/package.json +0 -23
  81. package/tests/cli/init/ethereum/from-example/schema.graphql +0 -6
  82. package/tests/cli/init/ethereum/from-example/src/mapping.ts +0 -22
  83. package/tests/cli/init/ethereum/from-example/subgraph.yaml +0 -27
  84. package/tests/cli/init/ethereum/from-example/truffle.js +0 -27
  85. package/tests/cli/init/ethereum/from-example/yarn.lock +0 -5977
@@ -1,5 +1,6 @@
1
1
  const prettier = require('prettier')
2
2
  const pkginfo = require('pkginfo')(module)
3
+ const { strings } = require('gluegun')
3
4
 
4
5
  const GRAPH_CLI_VERSION = process.env.GRAPH_CLI_TESTS
5
6
  // JSON.stringify should remove this key, we will install the local
@@ -25,6 +26,7 @@ module.exports = class Scaffold {
25
26
  this.network = options.network
26
27
  this.contractName = options.contractName
27
28
  this.subgraphName = options.subgraphName
29
+ this.dataSourceName = options.dataSourceName
28
30
  this.node = options.node
29
31
  }
30
32
 
@@ -50,7 +52,7 @@ module.exports = class Scaffold {
50
52
  },
51
53
  dependencies: {
52
54
  '@graphprotocol/graph-cli': GRAPH_CLI_VERSION,
53
- '@graphprotocol/graph-ts': `0.26.0`,
55
+ '@graphprotocol/graph-ts': `0.27.0`,
54
56
  },
55
57
  }),
56
58
  { parser: 'json' },
@@ -66,7 +68,7 @@ schema:
66
68
  file: ./schema.graphql
67
69
  dataSources:
68
70
  - kind: ${this.protocol.name}
69
- name: ${this.contractName}
71
+ name: ${this.dataSourceName}
70
72
  network: ${this.network}
71
73
  source: ${protocolManifest.source(this)}
72
74
  mapping: ${protocolManifest.mapping(this)}
@@ -142,7 +144,7 @@ dataSources:
142
144
  'subgraph.yaml': this.generateManifest(),
143
145
  'schema.graphql': this.generateSchema(),
144
146
  'tsconfig.json': this.generateTsConfig(),
145
- src: { 'mapping.ts': this.generateMapping() },
147
+ src: { [`${strings.kebabCase(this.contractName)}.ts`]: this.generateMapping() },
146
148
  abis: this.generateABIs(),
147
149
  }
148
150
  }
@@ -9,6 +9,7 @@ const scaffoldOptions = {
9
9
  contract: 'abc.def.near',
10
10
  network: 'near-mainnet',
11
11
  contractName: 'Contract',
12
+ dataSourceName: 'Contract'
12
13
  }
13
14
 
14
15
  const scaffold = new Scaffold(scaffoldOptions)
@@ -34,7 +35,7 @@ dataSources:
34
35
  - ExampleEntity
35
36
  receiptHandlers:
36
37
  - handler: handleReceipt
37
- file: ./src/mapping.ts
38
+ file: ./src/contract.ts
38
39
  `)
39
40
  })
40
41
 
@@ -2,6 +2,8 @@ const immutable = require('immutable')
2
2
  const yaml = require('js-yaml')
3
3
  const path = require('path')
4
4
 
5
+ const Protocol = require('../protocols')
6
+
5
7
  const List = immutable.List
6
8
  const Map = immutable.Map
7
9
 
@@ -204,6 +206,18 @@ const validators = immutable.fromJS({
204
206
  message: `Expected filename, found ${typeName(value)}:\n${value}`,
205
207
  },
206
208
  ]),
209
+
210
+ Boolean: (value, ctx) =>
211
+ typeof value === 'boolean'
212
+ ? List()
213
+ : immutable.fromJS([
214
+ {
215
+ path: ctx.get('path'),
216
+ message: `Expected true or false, found ${typeName(value)}:\n${toYAML(
217
+ value,
218
+ )}`,
219
+ },
220
+ ]),
207
221
  })
208
222
 
209
223
  const validateValue = (value, ctx) => {
@@ -229,23 +243,61 @@ const validateValue = (value, ctx) => {
229
243
  }
230
244
  }
231
245
 
232
- const validateDataSourceForNetwork = (dataSources, protocol) =>
246
+ // Transforms list of data sources like this:
247
+ // [
248
+ // { name: 'contract0', kind: 'ethereum/contract', network: 'mainnet' },
249
+ // { name: 'contract1', kind: 'ethereum', network: 'mainnet' },
250
+ // { name: 'contract2', kind: 'ethereum/contract', network: 'xdai' },
251
+ // { name: 'contract3', kind: 'near', network: 'near-mainnet' },
252
+ // ]
253
+ //
254
+ // Into Immutable JS structure like this (protocol kind is normalized):
255
+ // {
256
+ // ethereum: {
257
+ // mainnet: ['contract0', 'contract1'],
258
+ // xdai: ['contract2'],
259
+ // },
260
+ // near: {
261
+ // 'near-mainnet': ['contract3'],
262
+ // },
263
+ // }
264
+ const dataSourceListToMap = dataSources =>
233
265
  dataSources
234
- .filter(dataSource => protocol.isValidKindName(dataSource.kind))
235
266
  .reduce(
236
- (networks, dataSource) =>
237
- networks.update(dataSource.network, dataSources =>
238
- (dataSources || immutable.OrderedSet()).add(dataSource.name),
267
+ (protocolKinds, dataSource) =>
268
+ protocolKinds.update(Protocol.normalizeName(dataSource.kind), networks =>
269
+ (networks || immutable.OrderedMap()).update(dataSource.network, dataSourceNames =>
270
+ (dataSourceNames || immutable.OrderedSet()).add(dataSource.name)),
239
271
  ),
240
272
  immutable.OrderedMap(),
241
273
  )
242
274
 
243
- const validateDataSourceNetworks = (value, protocol) => {
275
+ const validateDataSourceProtocolAndNetworks = value => {
244
276
  const dataSources = [...value.dataSources, ...(value.templates || [])]
245
277
 
246
- // Networks found valid for a protocol.
247
- // By searching through all data sources and templates.
248
- const networks = validateDataSourceForNetwork(dataSources, protocol)
278
+ const protocolNetworkMap = dataSourceListToMap(dataSources)
279
+
280
+ if (protocolNetworkMap.size > 1) {
281
+ return immutable.fromJS([
282
+ {
283
+ path: [],
284
+ message: `Conflicting protocol kinds used in data sources and templates:
285
+ ${protocolNetworkMap
286
+ .map(
287
+ (dataSourceNames, protocolKind) =>
288
+ ` ${
289
+ protocolKind === undefined
290
+ ? 'Data sources and templates having no protocol kind set'
291
+ : `Data sources and templates using '${protocolKind}'`
292
+ }:\n${dataSourceNames.valueSeq().flatten().map(ds => ` - ${ds}`).join('\n')}`,
293
+ )
294
+ .join('\n')}
295
+ Recommendation: Make all data sources and templates use the same protocol kind.`,
296
+ },
297
+ ])
298
+ }
299
+
300
+ const networks = protocolNetworkMap.first()
249
301
 
250
302
  if (networks.size > 1) {
251
303
  return immutable.fromJS([
@@ -298,9 +350,9 @@ const validateManifest = (value, type, schema, protocol, { resolveFile }) => {
298
350
  return errors
299
351
  }
300
352
 
301
- // Validate that all data sources are for the same `network` (this includes
302
- // _no_ network at all)
303
- return validateDataSourceNetworks(value, protocol)
353
+ // Validate that all data sources are for the same `network` and `protocol` (kind)
354
+ // (this includes _no_ network/protocol at all)
355
+ return validateDataSourceProtocolAndNetworks(value)
304
356
  }
305
357
 
306
358
  module.exports = {
@@ -35,6 +35,8 @@ const TYPE_SUGGESTIONS = [
35
35
  ['Float', 'BigDecimal'],
36
36
  ['int', 'Int'],
37
37
  ['uint', 'BigInt'],
38
+ ['owner', 'String'],
39
+ ['Owner', 'String'],
38
40
  [/^(u|uint)(8|16|24)$/, 'Int'],
39
41
  [/^(i|int)(8|16|24|32)$/, 'Int'],
40
42
  [/^(u|uint)32$/, 'BigInt'],
@@ -0,0 +1,7 @@
1
+ [
2
+ {
3
+ "type": "event",
4
+ "name": "ExampleEvent",
5
+ "inputs": [{ "type": "string" }]
6
+ }
7
+ ]
@@ -0,0 +1,3 @@
1
+ type MyEntity @entity {
2
+ id: ID!
3
+ }
@@ -0,0 +1,41 @@
1
+ specVersion: 0.0.1
2
+ schema:
3
+ file: ./schema.graphql
4
+ dataSources:
5
+ - kind: ethereum/contract
6
+ name: ExampleSubgraph
7
+ network: mainnet
8
+ source:
9
+ address: 22843e74c59580b3eaf6c233fa67d8b7c561a835
10
+ abi: ExampleContract
11
+ mapping:
12
+ kind: ethereum/events
13
+ apiVersion: 0.0.5
14
+ language: wasm/assemblyscript
15
+ file: ./mapping.ts
16
+ entities:
17
+ - ExampleEntity
18
+ abis:
19
+ - name: ExampleContract
20
+ file: ./Abi.json
21
+ eventHandlers:
22
+ - event: ExampleEvent(string)
23
+ handler: handleExampleEvent
24
+ templates:
25
+ - kind: near
26
+ name: ExampleTemplate
27
+ source:
28
+ abi: ExampleContract
29
+ mapping:
30
+ kind: ethereum/events
31
+ apiVersion: 0.0.5
32
+ language: wasm/assemblyscript
33
+ file: ./mapping.ts
34
+ entities:
35
+ - ExampleEntity
36
+ abis:
37
+ - name: ExampleContract
38
+ file: ./Abi.json
39
+ eventHandlers:
40
+ - event: ExampleEvent(string)
41
+ handler: handleExampleEvent
@@ -0,0 +1,10 @@
1
+ - Load subgraph from subgraph.yaml
2
+ ✖ Failed to load subgraph from subgraph.yaml: Error in subgraph.yaml:
3
+
4
+ Path: /
5
+ Conflicting protocol kinds used in data sources and templates:
6
+ Data sources and templates using 'ethereum':
7
+ - ExampleSubgraph
8
+ Data sources and templates using 'near':
9
+ - ExampleTemplate
10
+ Recommendation: Make all data sources and templates use the same protocol kind.
@@ -205,6 +205,15 @@ describe('Validation', () => {
205
205
  },
206
206
  )
207
207
 
208
+ cliTest(
209
+ 'Conflicting protocol names',
210
+ ['codegen', '--skip-migrations'],
211
+ 'validation/conflicting-protocol-names',
212
+ {
213
+ exitCode: 1,
214
+ },
215
+ )
216
+
208
217
  cliTest(
209
218
  'Invalid @fulltext directive',
210
219
  ['codegen', '--skip-migrations'],