@graphprotocol/graph-cli 0.32.0 → 0.34.0-alpha.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 (42) hide show
  1. package/README.md +2 -2
  2. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/README.md +1 -1
  3. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/chain/ethereum.ts +200 -0
  4. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/global/global.ts +28 -28
  5. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/methods.txt +18 -0
  6. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/package.json +1 -1
  7. package/examples/basic-event-handlers/node_modules/keccak/build/Makefile +342 -0
  8. package/examples/basic-event-handlers/node_modules/keccak/build/Release/.deps/Release/obj.target/keccak/src/addon.o.d.raw +69 -0
  9. package/examples/basic-event-handlers/node_modules/keccak/build/binding.Makefile +6 -0
  10. package/examples/basic-event-handlers/node_modules/keccak/build/config.gypi +27 -11
  11. package/examples/basic-event-handlers/node_modules/keccak/build/gyp-mac-tool +772 -0
  12. package/examples/basic-event-handlers/node_modules/keccak/build/keccak.target.mk +207 -0
  13. package/examples/basic-event-handlers/node_modules/websocket/build/Makefile +347 -0
  14. package/examples/basic-event-handlers/node_modules/websocket/build/Release/.deps/Release/obj.target/bufferutil/src/bufferutil.o.d.raw +67 -0
  15. package/examples/basic-event-handlers/node_modules/websocket/build/binding.Makefile +6 -0
  16. package/examples/basic-event-handlers/node_modules/websocket/build/bufferutil.target.mk +190 -0
  17. package/examples/basic-event-handlers/node_modules/websocket/build/config.gypi +23 -7
  18. package/examples/basic-event-handlers/node_modules/websocket/build/gyp-mac-tool +772 -0
  19. package/examples/basic-event-handlers/node_modules/websocket/build/validation.target.mk +190 -0
  20. package/examples/basic-event-handlers/package.json +1 -1
  21. package/examples/basic-event-handlers/yarn.lock +4 -4
  22. package/examples/example-subgraph/package.json +1 -1
  23. package/examples/example-subgraph/yarn.lock +4 -4
  24. package/package.json +1 -1
  25. package/src/codegen/template.js +8 -1
  26. package/src/codegen/types/conversions.js +103 -2
  27. package/src/codegen/types/index.test.js +347 -0
  28. package/src/command-helpers/abi.js +3 -0
  29. package/src/command-helpers/jsonrpc.js +5 -1
  30. package/src/command-helpers/scaffold.js +43 -14
  31. package/src/command-helpers/studio.js +1 -1
  32. package/src/commands/add.js +2 -1
  33. package/src/commands/init.js +6 -6
  34. package/src/commands/test.js +5 -9
  35. package/src/migrations/mapping_api_version_0_0_4.js +1 -1
  36. package/src/migrations/mapping_api_version_0_0_5.js +1 -1
  37. package/src/protocols/index.js +4 -4
  38. package/src/protocols/ipfs/codegen/file_template.js +40 -0
  39. package/src/scaffold/ethereum.test.js +259 -0
  40. package/src/scaffold/index.js +16 -1
  41. package/src/scaffold/tests.js +196 -0
  42. package/src/subgraph.js +10 -4
package/README.md CHANGED
@@ -50,9 +50,9 @@ yarn global add @graphprotocol/graph-cli
50
50
 
51
51
  ## Getting Started
52
52
 
53
- The Graph CLI can be used with a local or self-hosted [Graph Node](https://github.com/graphprotocol/graph-node) or with the [Hosted Service](https://thegraph.com/explorer/). To help you get going, there are [quick start guides](https://thegraph.com/docs/quick-start) available for both.
53
+ The Graph CLI can be used with a local or self-hosted [Graph Node](https://github.com/graphprotocol/graph-node) or with the [Hosted Service](https://thegraph.com/explorer/). To help you get going, there are [quick start guides](https://thegraph.com/docs/en/developer/quick-start/) available for both.
54
54
 
55
- If you are ready to dive into the details of building a subgraph from scratch, there is a [detailed walkthrough](https://thegraph.com/docs/define-a-subgraph) for that as well, along with API documentation for the [AssemblyScript API](https://thegraph.com/docs/assemblyscript-api).
55
+ If you are ready to dive into the details of building a subgraph from scratch, there is a [detailed walkthrough](https://thegraph.com/docs/en/developer/create-subgraph-hosted/) for that as well, along with API documentation for the [AssemblyScript API](https://thegraph.com/docs/en/developer/assemblyscript-api/).
56
56
 
57
57
  ## Release process
58
58
 
@@ -59,7 +59,7 @@ Refer to the `helper-functions.ts` file in this repository for a few common func
59
59
 
60
60
  ## API
61
61
 
62
- Documentation on the API can be found [here](https://thegraph.com/docs/assemblyscript-api#api-reference).
62
+ Documentation on the API can be found [here](https://thegraph.com/docs/en/developer/assemblyscript-api/).
63
63
 
64
64
  For examples of `graph-ts` in use take a look at one of the following subgraphs:
65
65
  * https://github.com/graphprotocol/ens-subgraph
@@ -22,6 +22,7 @@ export namespace ethereum {
22
22
  FIXED_ARRAY = 7,
23
23
  ARRAY = 8,
24
24
  TUPLE = 9,
25
+ MATRIX = 10,
25
26
  }
26
27
 
27
28
  /**
@@ -102,6 +103,11 @@ export namespace ethereum {
102
103
  return changetype<Tuple>(this.data as u32)
103
104
  }
104
105
 
106
+ toMatrix(): Array<Array<Value>> {
107
+ assert(this.kind == ValueKind.MATRIX, 'Ethereum value is not a matrix.')
108
+ return changetype<Array<Array<Value>>>(this.data as u32)
109
+ }
110
+
105
111
  toTupleArray<T extends Tuple>(): Array<T> {
106
112
  assert(
107
113
  this.kind == ValueKind.ARRAY || this.kind == ValueKind.FIXED_ARRAY,
@@ -115,6 +121,19 @@ export namespace ethereum {
115
121
  return out
116
122
  }
117
123
 
124
+ toTupleMatrix<T extends Tuple>(): Array<Array<T>> {
125
+ assert(this.kind == ValueKind.MATRIX, 'Ethereum value is not a matrix.')
126
+ let valueMatrix = this.toMatrix()
127
+ let out = new Array<Array<T>>(valueMatrix.length)
128
+ for (let i: i32 = 0; i < valueMatrix.length; i++) {
129
+ out[i] = new Array<T>(valueMatrix[i].length)
130
+ for (let j: i32 = 0; j < valueMatrix[i].length; j++) {
131
+ out[i][j] = changetype<T>(valueMatrix[i][j].toTuple())
132
+ }
133
+ }
134
+ return out
135
+ }
136
+
118
137
  toBooleanArray(): Array<boolean> {
119
138
  assert(
120
139
  this.kind == ValueKind.ARRAY || this.kind == ValueKind.FIXED_ARRAY,
@@ -193,6 +212,84 @@ export namespace ethereum {
193
212
  return out
194
213
  }
195
214
 
215
+ toBooleanMatrix(): Array<Array<boolean>> {
216
+ assert(this.kind == ValueKind.MATRIX, 'Ethereum value is not a matrix.')
217
+ let valueMatrix = this.toMatrix()
218
+ let out = new Array<Array<boolean>>(valueMatrix.length)
219
+ for (let i: i32 = 0; i < valueMatrix.length; i++) {
220
+ out[i] = new Array<boolean>(valueMatrix[i].length)
221
+ for (let j: i32 = 0; j < valueMatrix[i].length; j++) {
222
+ out[i][j] = valueMatrix[i][j].toBoolean()
223
+ }
224
+ }
225
+ return out
226
+ }
227
+
228
+ toBytesMatrix(): Array<Array<Bytes>> {
229
+ assert(this.kind == ValueKind.MATRIX, 'Ethereum value is not a matrix.')
230
+ let valueMatrix = this.toMatrix()
231
+ let out = new Array<Array<Bytes>>(valueMatrix.length)
232
+ for (let i: i32 = 0; i < valueMatrix.length; i++) {
233
+ out[i] = new Array<Bytes>(valueMatrix[i].length)
234
+ for (let j: i32 = 0; j < valueMatrix[i].length; j++) {
235
+ out[i][j] = valueMatrix[i][j].toBytes()
236
+ }
237
+ }
238
+ return out
239
+ }
240
+
241
+ toAddressMatrix(): Array<Array<Address>> {
242
+ assert(this.kind == ValueKind.MATRIX, 'Ethereum value is not a matrix.')
243
+ let valueMatrix = this.toMatrix()
244
+ let out = new Array<Array<Address>>(valueMatrix.length)
245
+ for (let i: i32 = 0; i < valueMatrix.length; i++) {
246
+ out[i] = new Array<Address>(valueMatrix[i].length)
247
+ for (let j: i32 = 0; j < valueMatrix[i].length; j++) {
248
+ out[i][j] = valueMatrix[i][j].toAddress()
249
+ }
250
+ }
251
+ return out
252
+ }
253
+
254
+ toStringMatrix(): Array<Array<string>> {
255
+ assert(this.kind == ValueKind.MATRIX, 'Ethereum value is not a matrix.')
256
+ let valueMatrix = this.toMatrix()
257
+ let out = new Array<Array<string>>(valueMatrix.length)
258
+ for (let i: i32 = 0; i < valueMatrix.length; i++) {
259
+ out[i] = new Array<string>(valueMatrix[i].length)
260
+ for (let j: i32 = 0; j < valueMatrix[i].length; j++) {
261
+ out[i][j] = valueMatrix[i][j].toString()
262
+ }
263
+ }
264
+ return out
265
+ }
266
+
267
+ toI32Matrix(): Array<Array<i32>> {
268
+ assert(this.kind == ValueKind.MATRIX, 'Ethereum value is not a matrix.')
269
+ let valueMatrix = this.toMatrix()
270
+ let out = new Array<Array<i32>>(valueMatrix.length)
271
+ for (let i: i32 = 0; i < valueMatrix.length; i++) {
272
+ out[i] = new Array<i32>(valueMatrix[i].length)
273
+ for (let j: i32 = 0; j < valueMatrix[i].length; j++) {
274
+ out[i][j] = valueMatrix[i][j].toI32()
275
+ }
276
+ }
277
+ return out
278
+ }
279
+
280
+ toBigIntMatrix(): Array<Array<BigInt>> {
281
+ assert(this.kind == ValueKind.MATRIX, 'Ethereum value is not a matrix.')
282
+ let valueMatrix = this.toMatrix()
283
+ let out = new Array<Array<BigInt>>(valueMatrix.length)
284
+ for (let i: i32 = 0; i < valueMatrix.length; i++) {
285
+ out[i] = new Array<BigInt>(valueMatrix[i].length)
286
+ for (let j: i32 = 0; j < valueMatrix[i].length; j++) {
287
+ out[i][j] = valueMatrix[i][j].toBigInt()
288
+ }
289
+ }
290
+ return out
291
+ }
292
+
196
293
  static fromAddress(address: Address): Value {
197
294
  assert(address.length == 20, 'Address must contain exactly 20 bytes')
198
295
  return new Value(ValueKind.ADDRESS, changetype<u32>(address))
@@ -238,6 +335,10 @@ export namespace ethereum {
238
335
  return new Value(ValueKind.TUPLE, changetype<u32>(values))
239
336
  }
240
337
 
338
+ static fromMatrix(values: Array<Array<Value>>): Value {
339
+ return new Value(ValueKind.MATRIX, changetype<u32>(values))
340
+ }
341
+
241
342
  static fromTupleArray(values: Array<Tuple>): Value {
242
343
  let out = new Array<Value>(values.length)
243
344
  for (let i: i32 = 0; i < values.length; i++) {
@@ -246,6 +347,17 @@ export namespace ethereum {
246
347
  return Value.fromArray(out)
247
348
  }
248
349
 
350
+ static fromTupleMatrix(values: Array<Array<Tuple>>): Value {
351
+ let out = new Array<Array<Value>>(values.length)
352
+ for (let i: i32 = 0; i < values.length; i++) {
353
+ out[i] = new Array<Value>(values[i].length)
354
+ for (let j: i32 = 0; j < values[i].length; j++) {
355
+ out[i][j] = Value.fromTuple(values[i][j])
356
+ }
357
+ }
358
+ return Value.fromMatrix(out)
359
+ }
360
+
249
361
  static fromBooleanArray(values: Array<boolean>): Value {
250
362
  let out = new Array<Value>(values.length)
251
363
  for (let i: i32 = 0; i < values.length; i++) {
@@ -309,6 +421,94 @@ export namespace ethereum {
309
421
  }
310
422
  return Value.fromArray(out)
311
423
  }
424
+
425
+ static fromBooleanMatrix(values: Array<Array<boolean>>): Value {
426
+ let out = new Array<Array<Value>>(values.length)
427
+ for (let i: i32 = 0; i < values.length; i++) {
428
+ out[i] = new Array<Value>(values[i].length)
429
+ for (let j: i32 = 0; j < values[i].length; j++) {
430
+ out[i][j] = Value.fromBoolean(values[i][j])
431
+ }
432
+ }
433
+ return Value.fromMatrix(out)
434
+ }
435
+
436
+ static fromBytesMatrix(values: Array<Array<Bytes>>): Value {
437
+ let out = new Array<Array<Value>>(values.length)
438
+ for (let i: i32 = 0; i < values.length; i++) {
439
+ out[i] = new Array<Value>(values[i].length)
440
+ for (let j: i32 = 0; j < values[i].length; j++) {
441
+ out[i][j] = Value.fromBytes(values[i][j])
442
+ }
443
+ }
444
+ return Value.fromMatrix(out)
445
+ }
446
+
447
+ static fromFixedBytesMatrix(values: Array<Array<Bytes>>): Value {
448
+ let out = new Array<Array<Value>>(values.length)
449
+ for (let i: i32 = 0; i < values.length; i++) {
450
+ out[i] = new Array<Value>(values[i].length)
451
+ for (let j: i32 = 0; j < values[i].length; j++) {
452
+ out[i][j] = Value.fromFixedBytes(values[i][j])
453
+ }
454
+ }
455
+ return Value.fromMatrix(out)
456
+ }
457
+
458
+ static fromAddressMatrix(values: Array<Array<Address>>): Value {
459
+ let out = new Array<Array<Value>>(values.length)
460
+ for (let i: i32 = 0; i < values.length; i++) {
461
+ out[i] = new Array<Value>(values[i].length)
462
+ for (let j: i32 = 0; j < values[i].length; j++) {
463
+ out[i][j] = Value.fromAddress(values[i][j])
464
+ }
465
+ }
466
+ return Value.fromMatrix(out)
467
+ }
468
+
469
+ static fromStringMatrix(values: Array<Array<string>>): Value {
470
+ let out = new Array<Array<Value>>(values.length)
471
+ for (let i: i32 = 0; i < values.length; i++) {
472
+ out[i] = new Array<Value>(values[i].length)
473
+ for (let j: i32 = 0; j < values[i].length; j++) {
474
+ out[i][j] = Value.fromString(values[i][j])
475
+ }
476
+ }
477
+ return Value.fromMatrix(out)
478
+ }
479
+
480
+ static fromI32Matrix(values: Array<Array<i32>>): Value {
481
+ let out = new Array<Array<Value>>(values.length)
482
+ for (let i: i32 = 0; i < values.length; i++) {
483
+ out[i] = new Array<Value>(values[i].length)
484
+ for (let j: i32 = 0; j < values[i].length; j++) {
485
+ out[i][j] = Value.fromI32(values[i][j])
486
+ }
487
+ }
488
+ return Value.fromMatrix(out)
489
+ }
490
+
491
+ static fromSignedBigIntMatrix(values: Array<Array<BigInt>>): Value {
492
+ let out = new Array<Array<Value>>(values.length)
493
+ for (let i: i32 = 0; i < values.length; i++) {
494
+ out[i] = new Array<Value>(values[i].length)
495
+ for (let j: i32 = 0; j < values[i].length; j++) {
496
+ out[i][j] = Value.fromSignedBigInt(values[i][j])
497
+ }
498
+ }
499
+ return Value.fromMatrix(out)
500
+ }
501
+
502
+ static fromUnsignedBigIntMatrix(values: Array<Array<BigInt>>): Value {
503
+ let out = new Array<Array<Value>>(values.length)
504
+ for (let i: i32 = 0; i < values.length; i++) {
505
+ out[i] = new Array<Value>(values[i].length)
506
+ for (let j: i32 = 0; j < values[i].length; j++) {
507
+ out[i][j] = Value.fromUnsignedBigInt(values[i][j])
508
+ }
509
+ }
510
+ return Value.fromMatrix(out)
511
+ }
312
512
  }
313
513
 
314
514
  /**
@@ -146,22 +146,22 @@ export enum TypeId {
146
146
 
147
147
  // Reserved discriminant space for Cosmos type IDs: [1,500, 2,499]
148
148
  CosmosAny = 1500,
149
- CosmosArrayAny = 1501,
150
- CosmosArrayBytes = 1502,
151
- CosmosArrayCoin = 1503,
152
- CosmosArrayCommitSig = 1504,
153
- CosmosArrayEvent = 1505,
154
- CosmosArrayEventAttribute = 1506,
155
- CosmosArrayEvidence = 1507,
156
- CosmosArrayModeInfo = 1508,
157
- CosmosArraySignerInfo = 1509,
158
- CosmosArrayTxResult = 1510,
159
- CosmosArrayValidator = 1511,
160
- CosmosArrayValidatorUpdate = 1512,
149
+ CosmosAnyArray = 1501,
150
+ CosmosBytesArray = 1502,
151
+ CosmosCoinArray = 1503,
152
+ CosmosCommitSigArray = 1504,
153
+ CosmosEventArray = 1505,
154
+ CosmosEventAttributeArray = 1506,
155
+ CosmosEvidenceArray = 1507,
156
+ CosmosModeInfoArray = 1508,
157
+ CosmosSignerInfoArray = 1509,
158
+ CosmosTxResultArray = 1510,
159
+ CosmosValidatorArray = 1511,
160
+ CosmosValidatorUpdateArray = 1512,
161
161
  CosmosAuthInfo = 1513,
162
162
  CosmosBlock = 1514,
163
- CosmosBlockID = 1515,
164
- CosmosBlockIDFlagEnum = 1516,
163
+ CosmosBlockId = 1515,
164
+ CosmosBlockIdFlagEnum = 1516,
165
165
  CosmosBlockParams = 1517,
166
166
  CosmosCoin = 1518,
167
167
  CosmosCommit = 1519,
@@ -425,37 +425,37 @@ export function id_of_type(typeId: TypeId): usize {
425
425
  return idof<Array<ethereum.Log>>()
426
426
  case TypeId.CosmosAny:
427
427
  return idof<cosmos.Any>()
428
- case TypeId.CosmosArrayAny:
428
+ case TypeId.CosmosAnyArray:
429
429
  return idof<Array<cosmos.Any>>()
430
- case TypeId.CosmosArrayBytes:
430
+ case TypeId.CosmosBytesArray:
431
431
  return idof<Array<Bytes>>()
432
- case TypeId.CosmosArrayCoin:
432
+ case TypeId.CosmosCoinArray:
433
433
  return idof<Array<cosmos.Coin>>()
434
- case TypeId.CosmosArrayCommitSig:
434
+ case TypeId.CosmosCommitSigArray:
435
435
  return idof<Array<cosmos.CommitSig>>()
436
- case TypeId.CosmosArrayEvent:
436
+ case TypeId.CosmosEventArray:
437
437
  return idof<Array<cosmos.Event>>()
438
- case TypeId.CosmosArrayEventAttribute:
438
+ case TypeId.CosmosEventAttributeArray:
439
439
  return idof<Array<cosmos.EventAttribute>>()
440
- case TypeId.CosmosArrayEvidence:
440
+ case TypeId.CosmosEvidenceArray:
441
441
  return idof<Array<cosmos.Evidence>>()
442
- case TypeId.CosmosArrayModeInfo:
442
+ case TypeId.CosmosModeInfoArray:
443
443
  return idof<Array<cosmos.ModeInfo>>()
444
- case TypeId.CosmosArraySignerInfo:
444
+ case TypeId.CosmosSignerInfoArray:
445
445
  return idof<Array<cosmos.SignerInfo>>()
446
- case TypeId.CosmosArrayTxResult:
446
+ case TypeId.CosmosTxResultArray:
447
447
  return idof<Array<cosmos.TxResult>>()
448
- case TypeId.CosmosArrayValidator:
448
+ case TypeId.CosmosValidatorArray:
449
449
  return idof<Array<cosmos.Validator>>()
450
- case TypeId.CosmosArrayValidatorUpdate:
450
+ case TypeId.CosmosValidatorUpdateArray:
451
451
  return idof<Array<cosmos.ValidatorUpdate>>()
452
452
  case TypeId.CosmosAuthInfo:
453
453
  return idof<cosmos.AuthInfo>()
454
454
  case TypeId.CosmosBlock:
455
455
  return idof<cosmos.Block>()
456
- case TypeId.CosmosBlockID:
456
+ case TypeId.CosmosBlockId:
457
457
  return idof<cosmos.BlockID>()
458
- case TypeId.CosmosBlockIDFlagEnum:
458
+ case TypeId.CosmosBlockIdFlagEnum:
459
459
  return idof<Array<cosmos.BlockIDFlag>>()
460
460
  case TypeId.CosmosBlockParams:
461
461
  return idof<cosmos.BlockParams>()
@@ -0,0 +1,18 @@
1
+ toAddressMatrix
2
+ toBooleanMatrix
3
+ toBytesMatrix
4
+ toI32Matrix
5
+ toBigIntMatrix
6
+ toStringMatrix
7
+
8
+ fromAddressMatrix
9
+ fromBooleanMatrix
10
+ fromFixedBytesMatrix
11
+ fromBytesMatrix
12
+ fromI32Matrix
13
+ fromSignedBigIntMatrix
14
+ fromUnsignedBigIntMatrix
15
+ fromStringMatrix
16
+
17
+ fromBigIntMatrix
18
+ fromBigDecimalMatrix
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@graphprotocol/graph-ts",
3
3
  "description": "TypeScript/AssemblyScript library for writing subgraph mappings for The Graph",
4
- "version": "0.27.0",
4
+ "version": "0.28.0-alpha.0",
5
5
  "module": "index.ts",
6
6
  "types": "index.ts",
7
7
  "main": "index.ts",