@graphprotocol/graph-cli 0.23.0-alpha.0 → 0.24.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 (32) hide show
  1. package/README.md +83 -0
  2. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/.travis.yml +4 -0
  3. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/chain/ethereum.ts +10 -16
  4. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/chain/near.ts +402 -0
  5. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/common/collections.ts +125 -4
  6. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/common/eager_offset.ts +2 -1
  7. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/common/json.ts +14 -0
  8. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/common/numbers.ts +58 -16
  9. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/common/value.ts +2 -5
  10. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/global/global.ts +108 -0
  11. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/helper-functions.ts +5 -5
  12. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/index.ts +6 -15
  13. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/package.json +5 -2
  14. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/test/bigInt.ts +138 -108
  15. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/test/bytes.ts +31 -20
  16. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/test/test.js +120 -88
  17. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/tsconfig.json +2 -2
  18. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/types/tsconfig.base.json +3 -0
  19. package/examples/basic-event-handlers/package.json +1 -1
  20. package/examples/basic-event-handlers/yarn.lock +4 -4
  21. package/examples/example-subgraph/package.json +1 -1
  22. package/examples/example-subgraph/yarn.lock +4 -4
  23. package/jest.config.js +2 -2
  24. package/package.json +2 -6
  25. package/src/commands/init.js +31 -3
  26. package/src/commands/test.js +37 -27
  27. package/src/migrations/mapping_api_version_0_0_5.js +74 -0
  28. package/src/scaffold.js +18 -2
  29. package/tests/cli/globalSetup.js +6 -0
  30. package/tests/cli/globalTeardown.js +6 -0
  31. package/tests/cli/init.test.js +1 -1
  32. package/tests/cli/util.js +17 -8
@@ -1,5 +1,5 @@
1
1
  import { BigInt, BigDecimal } from './numbers'
2
- import { JSONValue, Value } from './value'
2
+ import { Value } from './value'
3
3
  import { typeConversion } from './conversion'
4
4
 
5
5
  /**
@@ -18,6 +18,50 @@ export class ByteArray extends Uint8Array {
18
18
  return self
19
19
  }
20
20
 
21
+ /**
22
+ * Returns bytes in little-endian order.
23
+ */
24
+ static fromU32(x: u32): ByteArray {
25
+ let self = new ByteArray(4)
26
+ self[0] = x as u8
27
+ self[1] = (x >> 8) as u8
28
+ self[2] = (x >> 16) as u8
29
+ self[3] = (x >> 24) as u8
30
+ return self
31
+ }
32
+
33
+ /**
34
+ * Returns bytes in little-endian order.
35
+ */
36
+ static fromI64(x: i64): ByteArray {
37
+ let self = new ByteArray(8)
38
+ self[0] = x as u8
39
+ self[1] = (x >> 8) as u8
40
+ self[2] = (x >> 16) as u8
41
+ self[3] = (x >> 24) as u8
42
+ self[4] = (x >> 32) as u8
43
+ self[5] = (x >> 40) as u8
44
+ self[6] = (x >> 48) as u8
45
+ self[7] = (x >> 56) as u8
46
+ return self
47
+ }
48
+
49
+ /**
50
+ * Returns bytes in little-endian order.
51
+ */
52
+ static fromU64(x: u64): ByteArray {
53
+ let self = new ByteArray(8)
54
+ self[0] = x as u8
55
+ self[1] = (x >> 8) as u8
56
+ self[2] = (x >> 16) as u8
57
+ self[3] = (x >> 24) as u8
58
+ self[4] = (x >> 32) as u8
59
+ self[5] = (x >> 40) as u8
60
+ self[6] = (x >> 48) as u8
61
+ self[7] = (x >> 56) as u8
62
+ return self
63
+ }
64
+
21
65
  static empty(): ByteArray {
22
66
  return ByteArray.fromI32(0)
23
67
  }
@@ -28,7 +72,7 @@ export class ByteArray extends Uint8Array {
28
72
  static fromHexString(hex: string): ByteArray {
29
73
  assert(hex.length % 2 == 0, 'input ' + hex + ' has odd length')
30
74
  // Skip possible `0x` prefix.
31
- if (hex.length >= 2 && hex[0] == '0' && hex[1] == 'x') {
75
+ if (hex.length >= 2 && hex.charAt(0) == '0' && hex.charAt(1) == 'x') {
32
76
  hex = hex.substr(2)
33
77
  }
34
78
  let output = new Bytes(hex.length / 2)
@@ -38,8 +82,7 @@ export class ByteArray extends Uint8Array {
38
82
  return output
39
83
  }
40
84
 
41
- static fromUTF8(str: String): ByteArray {
42
- // AssemblyScript counts a null terminator, we don't want that.
85
+ static fromUTF8(str: string): ByteArray {
43
86
  let utf8 = String.UTF8.encode(str)
44
87
  return changetype<ByteArray>(ByteArray.wrap(utf8))
45
88
  }
@@ -122,6 +165,80 @@ export class ByteArray extends Uint8Array {
122
165
  return x
123
166
  }
124
167
 
168
+ /**
169
+ * Interprets the byte array as a little-endian I64.
170
+ * Throws in case of overflow.
171
+ */
172
+
173
+ toI64(): i64 {
174
+ let isNeg = this.length > 0 && this[this.length - 1] >> 7 == 1
175
+ let padding = isNeg ? 255 : 0
176
+ for (let i = 8; i < this.length; i++) {
177
+ if (this[i] != padding) {
178
+ assert(false, 'overflow converting ' + this.toHexString() + ' to i64')
179
+ }
180
+ }
181
+ let paddedBytes = new Bytes(8)
182
+ paddedBytes[0] = padding
183
+ paddedBytes[1] = padding
184
+ paddedBytes[2] = padding
185
+ paddedBytes[3] = padding
186
+ paddedBytes[4] = padding
187
+ paddedBytes[5] = padding
188
+ paddedBytes[6] = padding
189
+ paddedBytes[7] = padding
190
+ let minLen = paddedBytes.length < this.length ? paddedBytes.length : this.length
191
+ for (let i = 0; i < minLen; i++) {
192
+ paddedBytes[i] = this[i]
193
+ }
194
+ let x: i64 = 0
195
+ x = (x | paddedBytes[7]) << 8
196
+ x = (x | paddedBytes[6]) << 8
197
+ x = (x | paddedBytes[5]) << 8
198
+ x = (x | paddedBytes[4]) << 8
199
+ x = (x | paddedBytes[3]) << 8
200
+ x = (x | paddedBytes[2]) << 8
201
+ x = (x | paddedBytes[1]) << 8
202
+ x = x | paddedBytes[0]
203
+ return x
204
+ }
205
+
206
+ /**
207
+ * Interprets the byte array as a little-endian U64.
208
+ * Throws in case of overflow.
209
+ */
210
+
211
+ toU64(): u64 {
212
+ for (let i = 8; i < this.length; i++) {
213
+ if (this[i] != 0) {
214
+ assert(false, 'overflow converting ' + this.toHexString() + ' to u64')
215
+ }
216
+ }
217
+ let paddedBytes = new Bytes(8)
218
+ paddedBytes[0] = 0
219
+ paddedBytes[1] = 0
220
+ paddedBytes[2] = 0
221
+ paddedBytes[3] = 0
222
+ paddedBytes[4] = 0
223
+ paddedBytes[5] = 0
224
+ paddedBytes[6] = 0
225
+ paddedBytes[7] = 0
226
+ let minLen = paddedBytes.length < this.length ? paddedBytes.length : this.length
227
+ for (let i = 0; i < minLen; i++) {
228
+ paddedBytes[i] = this[i]
229
+ }
230
+ let x: u64 = 0
231
+ x = (x | paddedBytes[7]) << 8
232
+ x = (x | paddedBytes[6]) << 8
233
+ x = (x | paddedBytes[5]) << 8
234
+ x = (x | paddedBytes[4]) << 8
235
+ x = (x | paddedBytes[3]) << 8
236
+ x = (x | paddedBytes[2]) << 8
237
+ x = (x | paddedBytes[1]) << 8
238
+ x = x | paddedBytes[0]
239
+ return x
240
+ }
241
+
125
242
  @operator('==')
126
243
  equals(other: ByteArray): boolean {
127
244
  if (this.length != other.length) {
@@ -151,6 +268,10 @@ export class Bytes extends ByteArray {
151
268
  return changetype<Bytes>(uint8Array)
152
269
  }
153
270
 
271
+ static fromUTF8(str: string): Bytes {
272
+ return Bytes.fromByteArray(ByteArray.fromUTF8(str))
273
+ }
274
+
154
275
  static empty(): Bytes {
155
276
  return changetype<Bytes>(ByteArray.empty())
156
277
  }
@@ -38,4 +38,5 @@
38
38
  // # Reference
39
39
  // - Runtimes in AS: https://www.assemblyscript.org/garbage-collection.html#runtime-variants
40
40
  // - `offset` variable in question: https://github.com/AssemblyScript/assemblyscript/blob/f4091b8f3b6b029d30cd917cf84d97421faadeeb/std/assembly/rt/stub.ts#L9
41
- __alloc(0);
41
+ // @ts-ignore We do not want to expose __alloc, hence why we just ignore the error
42
+ __alloc(0)
@@ -12,3 +12,17 @@ export declare namespace json {
12
12
  function toF64(decimal: string): f64
13
13
  function toBigInt(decimal: string): BigInt
14
14
  }
15
+
16
+ export namespace json {
17
+ function fromString(data: string): JSONValue {
18
+ let bytes = Bytes.fromUTF8(data)
19
+
20
+ return json.fromBytes(bytes)
21
+ }
22
+
23
+ function try_fromString(data: string): Result<JSONValue, boolean> {
24
+ let bytes = Bytes.fromUTF8(data)
25
+
26
+ return json.try_fromBytes(bytes)
27
+ }
28
+ }
@@ -53,6 +53,21 @@ export class BigInt extends Uint8Array {
53
53
  return BigInt.fromByteArray(byteArray)
54
54
  }
55
55
 
56
+ static fromU32(x: u32): BigInt {
57
+ let byteArray = ByteArray.fromU32(x)
58
+ return BigInt.fromUnsignedBytes(byteArray)
59
+ }
60
+
61
+ static fromI64(x: i64): BigInt {
62
+ let byteArray = ByteArray.fromI64(x)
63
+ return BigInt.fromByteArray(byteArray)
64
+ }
65
+
66
+ static fromU64(x: u64): BigInt {
67
+ let byteArray = ByteArray.fromU64(x)
68
+ return BigInt.fromUnsignedBytes(byteArray)
69
+ }
70
+
56
71
  static zero(): BigInt {
57
72
  return BigInt.fromI32(0)
58
73
  }
@@ -74,7 +89,7 @@ export class BigInt extends Uint8Array {
74
89
  * `bytes` assumed to be little-endian. If your input is big-endian, call `.reverse()` first.
75
90
  */
76
91
 
77
- static fromUnsignedBytes(bytes: Bytes): BigInt {
92
+ static fromUnsignedBytes(bytes: ByteArray): BigInt {
78
93
  let signedBytes = new BigInt(bytes.length + 1)
79
94
  for (let i = 0; i < bytes.length; i++) {
80
95
  signedBytes[i] = bytes[i]
@@ -105,6 +120,24 @@ export class BigInt extends Uint8Array {
105
120
  return byteArray.toI32()
106
121
  }
107
122
 
123
+ toU32(): u32 {
124
+ let uint8Array = changetype<Uint8Array>(this)
125
+ let byteArray = changetype<ByteArray>(uint8Array)
126
+ return byteArray.toU32()
127
+ }
128
+
129
+ toI64(): i64 {
130
+ let uint8Array = changetype<Uint8Array>(this)
131
+ let byteArray = changetype<ByteArray>(uint8Array)
132
+ return byteArray.toI64()
133
+ }
134
+
135
+ toU64(): u64 {
136
+ let uint8Array = changetype<Uint8Array>(this)
137
+ let byteArray = changetype<ByteArray>(uint8Array)
138
+ return byteArray.toU64()
139
+ }
140
+
108
141
  toBigDecimal(): BigDecimal {
109
142
  return new BigDecimal(this)
110
143
  }
@@ -118,11 +151,11 @@ export class BigInt extends Uint8Array {
118
151
  }
119
152
 
120
153
  abs(): BigInt {
121
- return this < BigInt.fromI32(0) ? -this : this
154
+ return this < BigInt.fromI32(0) ? this.neg() : this
122
155
  }
123
156
 
124
157
  sqrt(): BigInt {
125
- let x = this
158
+ let x: BigInt = this
126
159
  let z = x.plus(BigInt.fromI32(1)).div(BigInt.fromI32(2))
127
160
  let y = x
128
161
  while (z < y) {
@@ -137,25 +170,25 @@ export class BigInt extends Uint8Array {
137
170
 
138
171
  @operator('+')
139
172
  plus(other: BigInt): BigInt {
140
- assert(this !== null, "Failed to sum BigInts because left hand side is 'null'");
173
+ assert(this !== null, "Failed to sum BigInts because left hand side is 'null'")
141
174
  return bigInt.plus(this, other)
142
175
  }
143
176
 
144
177
  @operator('-')
145
178
  minus(other: BigInt): BigInt {
146
- assert(this !== null, "Failed to subtract BigInts because left hand side is 'null'");
179
+ assert(this !== null, "Failed to subtract BigInts because left hand side is 'null'")
147
180
  return bigInt.minus(this, other)
148
181
  }
149
182
 
150
183
  @operator('*')
151
184
  times(other: BigInt): BigInt {
152
- assert(this !== null, "Failed to multiply BigInts because left hand side is 'null'");
185
+ assert(this !== null, "Failed to multiply BigInts because left hand side is 'null'")
153
186
  return bigInt.times(this, other)
154
187
  }
155
188
 
156
189
  @operator('/')
157
190
  div(other: BigInt): BigInt {
158
- assert(this !== null, "Failed to divide BigInts because left hand side is 'null'");
191
+ assert(this !== null, "Failed to divide BigInts because left hand side is 'null'")
159
192
  return bigInt.dividedBy(this, other)
160
193
  }
161
194
 
@@ -165,7 +198,10 @@ export class BigInt extends Uint8Array {
165
198
 
166
199
  @operator('%')
167
200
  mod(other: BigInt): BigInt {
168
- assert(this !== null, "Failed to apply module to BigInt because left hand side is 'null'");
201
+ assert(
202
+ this !== null,
203
+ "Failed to apply module to BigInt because left hand side is 'null'",
204
+ )
169
205
  return bigInt.mod(this, other)
170
206
  }
171
207
 
@@ -201,7 +237,7 @@ export class BigInt extends Uint8Array {
201
237
 
202
238
  @operator.prefix('-')
203
239
  neg(): BigInt {
204
- return BigInt.fromI32(0) - this
240
+ return BigInt.fromI32(0).minus(this)
205
241
  }
206
242
 
207
243
  @operator('|')
@@ -324,25 +360,31 @@ export class BigDecimal {
324
360
 
325
361
  @operator('+')
326
362
  plus(other: BigDecimal): BigDecimal {
327
- assert(this !== null, "Failed to sum BigDecimals because left hand side is 'null'");
363
+ assert(this !== null, "Failed to sum BigDecimals because left hand side is 'null'")
328
364
  return bigDecimal.plus(this, other)
329
365
  }
330
366
 
331
367
  @operator('-')
332
368
  minus(other: BigDecimal): BigDecimal {
333
- assert(this !== null, "Failed to subtract BigDecimals because left hand side is 'null'");
369
+ assert(
370
+ this !== null,
371
+ "Failed to subtract BigDecimals because left hand side is 'null'",
372
+ )
334
373
  return bigDecimal.minus(this, other)
335
374
  }
336
375
 
337
376
  @operator('*')
338
377
  times(other: BigDecimal): BigDecimal {
339
- assert(this !== null, "Failed to multiply BigDecimals because left hand side is 'null'");
378
+ assert(
379
+ this !== null,
380
+ "Failed to multiply BigDecimals because left hand side is 'null'",
381
+ )
340
382
  return bigDecimal.times(this, other)
341
383
  }
342
384
 
343
385
  @operator('/')
344
386
  div(other: BigDecimal): BigDecimal {
345
- assert(this !== null, "Failed to divide BigDecimals because left hand side is 'null'");
387
+ assert(this !== null, "Failed to divide BigDecimals because left hand side is 'null'")
346
388
  return bigDecimal.dividedBy(this, other)
347
389
  }
348
390
 
@@ -378,15 +420,15 @@ export class BigDecimal {
378
420
 
379
421
  @operator.prefix('-')
380
422
  neg(): BigDecimal {
381
- assert(this !== null, "Failed to negate BigDecimal because the value of it is 'null'");
382
- return new BigDecimal(new BigInt(0)) - this
423
+ assert(this !== null, "Failed to negate BigDecimal because the value of it is 'null'")
424
+ return new BigDecimal(new BigInt(0)).minus(this)
383
425
  }
384
426
 
385
427
  /**
386
428
  * Returns −1 if a < b, 1 if a > b, and 0 if A == B
387
429
  */
388
430
  static compare(a: BigDecimal, b: BigDecimal): i32 {
389
- let diff = a - b
431
+ let diff = a.minus(b)
390
432
  if (diff.digits.isZero()) {
391
433
  return 0
392
434
  }
@@ -27,10 +27,7 @@ export type ValuePayload = u64
27
27
  * A dynamically typed value.
28
28
  */
29
29
  export class Value {
30
- constructor(
31
- public kind: ValueKind,
32
- public data: ValuePayload,
33
- ) {}
30
+ constructor(public kind: ValueKind, public data: ValuePayload) {}
34
31
 
35
32
  toAddress(): Address {
36
33
  assert(this.kind == ValueKind.BYTES, 'Value is not an address.')
@@ -196,7 +193,7 @@ export class Value {
196
193
  return new Value(ValueKind.BIGINT, changetype<u32>(n))
197
194
  }
198
195
 
199
- static fromBoolean(b: boolean): Value {
196
+ static fromBoolean(b: bool): Value {
200
197
  return new Value(ValueKind.BOOL, b ? 1 : 0)
201
198
  }
202
199
 
@@ -2,6 +2,7 @@ import { BigDecimal } from '../common/numbers'
2
2
  import { TypedMapEntry, Entity, TypedMap, Result, Wrapped } from '../common/collections'
3
3
  import { JSONValue, Value } from '../common/value'
4
4
  import { ethereum } from '../chain/ethereum'
5
+ import { near } from '../chain/near'
5
6
 
6
7
  export enum TypeId {
7
8
  String = 0,
@@ -56,6 +57,41 @@ export enum TypeId {
56
57
  ArrayF32 = 49,
57
58
  ArrayF64 = 50,
58
59
  ArrayBigDecimal = 51,
60
+ NearArrayDataReceiver = 52,
61
+ NearArrayCryptoHash = 53,
62
+ NearArrayActionValue = 54,
63
+ NearMerklePath = 55, // or NearArrayMerklePathItem
64
+ NearArrayValidatorStake = 56,
65
+ NearArraySlashedValidator = 57,
66
+ NearArraySignature = 58,
67
+ NearArrayChunkHeader = 59,
68
+ NearAccessKeyPermissionValue = 60,
69
+ NearActionValue = 61,
70
+ NearDirection = 62, // not used in graph-node, could be removed
71
+ NearPublicKey = 63,
72
+ NearSignature = 64,
73
+ NearFunctionCallPermission = 65,
74
+ NearFullAccessPermission = 66,
75
+ NearAccessKey = 67,
76
+ NearDataReceiver = 68,
77
+ NearCreateAccountAction = 69,
78
+ NearDeployContractAction = 70,
79
+ NearFunctionCallAction = 71,
80
+ NearTransferAction = 72,
81
+ NearStakeAction = 73,
82
+ NearAddKeyAction = 74,
83
+ NearDeleteKeyAction = 75,
84
+ NearDeleteAccountAction = 76,
85
+ NearActionReceipt = 77,
86
+ NearSuccessStatus = 78,
87
+ NearMerklePathItem = 79,
88
+ NearExecutionOutcome = 80,
89
+ NearSlashedValidator = 81,
90
+ NearBlockHeader = 82,
91
+ NearValidatorStake = 83,
92
+ NearChunkHeader = 84,
93
+ NearBlock = 85,
94
+ NearReceiptWithOutcome = 86,
59
95
  }
60
96
 
61
97
  export function id_of_type(typeId: TypeId): usize {
@@ -164,11 +200,83 @@ export function id_of_type(typeId: TypeId): usize {
164
200
  return idof<Array<f64>>()
165
201
  case TypeId.ArrayBigDecimal:
166
202
  return idof<Array<BigDecimal>>()
203
+ case TypeId.NearArrayDataReceiver:
204
+ return idof<Array<near.DataReceiver>>()
205
+ case TypeId.NearArrayCryptoHash:
206
+ return idof<Array<near.CryptoHash>>()
207
+ case TypeId.NearArrayActionValue:
208
+ return idof<Array<near.ActionValue>>()
209
+ case TypeId.NearMerklePath:
210
+ return idof<near.MerklePath>()
211
+ case TypeId.NearArrayValidatorStake:
212
+ return idof<Array<near.ValidatorStake>>()
213
+ case TypeId.NearArraySlashedValidator:
214
+ return idof<Array<near.SlashedValidator>>()
215
+ case TypeId.NearArraySignature:
216
+ return idof<Array<near.Signature>>()
217
+ case TypeId.NearArrayChunkHeader:
218
+ return idof<Array<near.ChunkHeader>>()
219
+ case TypeId.NearAccessKeyPermissionValue:
220
+ return idof<near.AccessKeyPermissionValue>()
221
+ case TypeId.NearActionValue:
222
+ return idof<near.ActionValue>()
223
+ // Commented out because it's an enum, there's no type_id
224
+ // case TypeId.NearDirection:
225
+ // return idof<near.Direction>()
226
+ case TypeId.NearPublicKey:
227
+ return idof<near.PublicKey>()
228
+ case TypeId.NearSignature:
229
+ return idof<near.Signature>()
230
+ case TypeId.NearFunctionCallPermission:
231
+ return idof<near.FunctionCallPermission>()
232
+ case TypeId.NearFullAccessPermission:
233
+ return idof<near.FullAccessPermission>()
234
+ case TypeId.NearAccessKey:
235
+ return idof<near.AccessKeyPermissionValue>()
236
+ case TypeId.NearDataReceiver:
237
+ return idof<near.DataReceiver>()
238
+ case TypeId.NearCreateAccountAction:
239
+ return idof<near.CreateAccountAction>()
240
+ case TypeId.NearDeployContractAction:
241
+ return idof<near.DeployContractAction>()
242
+ case TypeId.NearFunctionCallAction:
243
+ return idof<near.FunctionCallAction>()
244
+ case TypeId.NearTransferAction:
245
+ return idof<near.TransferAction>()
246
+ case TypeId.NearStakeAction:
247
+ return idof<near.StakeAction>()
248
+ case TypeId.NearAddKeyAction:
249
+ return idof<near.AddKeyAction>()
250
+ case TypeId.NearDeleteKeyAction:
251
+ return idof<near.DeleteKeyAction>()
252
+ case TypeId.NearDeleteAccountAction:
253
+ return idof<near.DeleteAccountAction>()
254
+ case TypeId.NearActionReceipt:
255
+ return idof<near.ActionReceipt>()
256
+ case TypeId.NearSuccessStatus:
257
+ return idof<near.SuccessStatus>()
258
+ case TypeId.NearMerklePathItem:
259
+ return idof<near.MerklePathItem>()
260
+ case TypeId.NearExecutionOutcome:
261
+ return idof<near.ExecutionOutcome>()
262
+ case TypeId.NearSlashedValidator:
263
+ return idof<near.SlashedValidator>()
264
+ case TypeId.NearBlockHeader:
265
+ return idof<near.BlockHeader>()
266
+ case TypeId.NearValidatorStake:
267
+ return idof<near.ValidatorStake>()
268
+ case TypeId.NearChunkHeader:
269
+ return idof<near.ChunkHeader>()
270
+ case TypeId.NearBlock:
271
+ return idof<near.Block>()
272
+ case TypeId.NearReceiptWithOutcome:
273
+ return idof<near.ReceiptWithOutcome>()
167
274
  default:
168
275
  return 0
169
276
  }
170
277
  }
171
278
 
172
279
  export function allocate(size: usize): usize {
280
+ // @ts-ignore We do not want to expose __alloc, hence why we just ignore the error
173
281
  return __alloc(size)
174
282
  }
@@ -1,4 +1,4 @@
1
- import { ByteArray, BigInt } from './index'
1
+ import { ByteArray } from './index'
2
2
 
3
3
  /**
4
4
  * Takes 2 ByteArrays and concatenates them
@@ -38,8 +38,8 @@ export function parseCSV(csv: string): Array<string> {
38
38
 
39
39
  for (let i: i32 = 0; i < csv.length; i++) {
40
40
  if (state == CSVState.BETWEEN) {
41
- if (csv[i] != ',') {
42
- if (csv[i] == '"') {
41
+ if (csv.charAt(i) != ',') {
42
+ if (csv.charAt(i) == '"') {
43
43
  state = CSVState.QUOTED_VALUE
44
44
  valueStart = i + 1
45
45
  } else {
@@ -48,12 +48,12 @@ export function parseCSV(csv: string): Array<string> {
48
48
  }
49
49
  }
50
50
  } else if (state == CSVState.UNQUOTED_VALUE) {
51
- if (csv[i] == ',') {
51
+ if (csv.charAt(i) == ',') {
52
52
  values.push(csv.substr(valueStart, i - valueStart))
53
53
  state = CSVState.BETWEEN
54
54
  }
55
55
  } else if (state == CSVState.QUOTED_VALUE) {
56
- if (csv[i] == '"') {
56
+ if (csv.charAt(i) == '"') {
57
57
  values.push(csv.substr(valueStart, i - valueStart))
58
58
  state = CSVState.BETWEEN
59
59
  }
@@ -2,6 +2,8 @@
2
2
  import './common/eager_offset'
3
3
  // Ethereum support
4
4
  export * from './chain/ethereum'
5
+ // NEAR support
6
+ export * from './chain/near'
5
7
  // Regular re-exports
6
8
  export * from './common/numbers'
7
9
  export * from './common/collections'
@@ -10,19 +12,8 @@ export * from './common/conversion'
10
12
  export * from './common/json'
11
13
  export * from './common/datasource'
12
14
 
13
- import {
14
- Address,
15
- BigInt,
16
- BigDecimal,
17
- } from './common/numbers'
18
- import {
19
- Bytes,
20
- ByteArray,
21
- Result,
22
- TypedMap,
23
- Entity,
24
- } from './common/collections'
25
- import { JSONValue, Value } from './common/value'
15
+ import { Bytes, ByteArray, Entity } from './common/collections'
16
+ import { Value } from './common/value'
26
17
 
27
18
  /**
28
19
  * Host store interface.
@@ -69,13 +60,13 @@ function format(fmt: string, args: string[]): string {
69
60
  fmt.charCodeAt(i + 1) == 0x7d /* '}' */
70
61
  ) {
71
62
  if (argIndex >= args.length) {
72
- throw Error('Too few arguments for format string: ' + fmt)
63
+ throw new Error('Too few arguments for format string: ' + fmt)
73
64
  } else {
74
65
  out += args[argIndex++]
75
66
  i++
76
67
  }
77
68
  } else {
78
- out += fmt[i]
69
+ out += fmt.charAt(i)
79
70
  }
80
71
  }
81
72
  return out
@@ -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.22.0",
4
+ "version": "0.23.1",
5
5
  "module": "index.ts",
6
6
  "types": "index.ts",
7
7
  "main": "index.ts",
@@ -9,9 +9,12 @@
9
9
  "assemblyscript": "0.19.10"
10
10
  },
11
11
  "devDependencies": {
12
- "glob": "^7.1.2"
12
+ "glob": "^7.1.2",
13
+ "prettier": "^2.4.1"
13
14
  },
14
15
  "scripts": {
16
+ "lint": "prettier -c **/*.{js,ts}",
17
+ "build": "asc --explicitStart --exportRuntime --runtime stub index.ts helper-functions.ts --lib graph-ts -b index.wasm",
15
18
  "test": "node test/test.js",
16
19
  "release:patch": "npm version patch && npm publish && git push origin master && git push --tags",
17
20
  "release:minor": "npm version minor && npm publish && git push origin master && git push --tags",