@graphprotocol/graph-cli 0.37.4 → 0.37.5

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 (100) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/bin.js +6 -0
  3. package/dist/cli.js +26 -0
  4. package/dist/codegen/schema.js +244 -0
  5. package/dist/codegen/schema.test.js +455 -0
  6. package/dist/codegen/template.js +66 -0
  7. package/dist/codegen/types/conversions.js +335 -0
  8. package/dist/codegen/types/index.js +71 -0
  9. package/dist/codegen/types/index.test.js +563 -0
  10. package/dist/codegen/typescript.js +200 -0
  11. package/dist/codegen/util.js +40 -0
  12. package/dist/codegen/util.test.js +93 -0
  13. package/dist/command-helpers/abi.js +76 -0
  14. package/dist/command-helpers/auth.js +76 -0
  15. package/dist/command-helpers/compiler.js +66 -0
  16. package/dist/command-helpers/data-sources.js +29 -0
  17. package/dist/command-helpers/fs.js +9 -0
  18. package/dist/command-helpers/gluegun.js +48 -0
  19. package/dist/command-helpers/ipfs.js +5 -0
  20. package/dist/command-helpers/jsonrpc.js +27 -0
  21. package/dist/command-helpers/network.js +90 -0
  22. package/dist/command-helpers/network.test.js +86 -0
  23. package/dist/command-helpers/node.js +40 -0
  24. package/dist/command-helpers/scaffold.js +110 -0
  25. package/dist/command-helpers/spinner.js +80 -0
  26. package/dist/command-helpers/studio.js +14 -0
  27. package/dist/command-helpers/studio.test.js +41 -0
  28. package/dist/command-helpers/subgraph.js +22 -0
  29. package/dist/command-helpers/version.js +66 -0
  30. package/dist/command-helpers/version.test.js +186 -0
  31. package/dist/commands/add.js +187 -0
  32. package/dist/commands/auth.js +122 -0
  33. package/dist/commands/build.js +136 -0
  34. package/dist/commands/codegen.js +128 -0
  35. package/dist/commands/create.js +94 -0
  36. package/dist/commands/deploy.js +335 -0
  37. package/dist/commands/init.js +800 -0
  38. package/dist/commands/local.js +380 -0
  39. package/dist/commands/remove.js +95 -0
  40. package/dist/commands/test.js +293 -0
  41. package/dist/compiler/asc.js +83 -0
  42. package/dist/compiler/index.js +466 -0
  43. package/dist/debug.js +16 -0
  44. package/dist/migrations/mapping_api_version_0_0_1.js +83 -0
  45. package/dist/migrations/mapping_api_version_0_0_2.js +83 -0
  46. package/dist/migrations/mapping_api_version_0_0_3.js +83 -0
  47. package/dist/migrations/mapping_api_version_0_0_4.js +85 -0
  48. package/dist/migrations/mapping_api_version_0_0_5.js +85 -0
  49. package/dist/migrations/spec_version_0_0_2.js +45 -0
  50. package/dist/migrations/spec_version_0_0_3.js +50 -0
  51. package/dist/migrations/util/load-manifest.js +16 -0
  52. package/dist/migrations/util/versions.js +28 -0
  53. package/dist/migrations.js +54 -0
  54. package/dist/protocols/arweave/manifest.graphql +57 -0
  55. package/dist/protocols/arweave/scaffold/manifest.js +18 -0
  56. package/dist/protocols/arweave/scaffold/mapping.js +52 -0
  57. package/dist/protocols/arweave/subgraph.js +23 -0
  58. package/dist/protocols/contract.js +2 -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 +28 -0
  63. package/dist/protocols/ethereum/abi.js +138 -0
  64. package/dist/protocols/ethereum/codegen/abi.js +474 -0
  65. package/dist/protocols/ethereum/codegen/abi.test.js +325 -0
  66. package/dist/protocols/ethereum/codegen/template.js +52 -0
  67. package/dist/protocols/ethereum/contract.js +22 -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 +172 -0
  72. package/dist/protocols/ethereum/type-generator.js +123 -0
  73. package/dist/protocols/index.js +266 -0
  74. package/dist/protocols/ipfs/codegen/file_template.js +53 -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 +23 -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 +82 -0
  85. package/dist/scaffold/ethereum.test.js +496 -0
  86. package/dist/scaffold/index.js +133 -0
  87. package/dist/scaffold/mapping.js +57 -0
  88. package/dist/scaffold/near.test.js +85 -0
  89. package/dist/scaffold/schema.js +86 -0
  90. package/dist/scaffold/tests.js +179 -0
  91. package/dist/schema.js +54 -0
  92. package/dist/subgraph.js +243 -0
  93. package/dist/type-generator.js +225 -0
  94. package/dist/validation/contract.js +44 -0
  95. package/dist/validation/index.js +10 -0
  96. package/dist/validation/manifest.js +266 -0
  97. package/dist/validation/schema.js +768 -0
  98. package/dist/validation/schema.test.js +35 -0
  99. package/dist/watcher.js +79 -0
  100. package/package.json +1 -1
@@ -0,0 +1,335 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const immutable_1 = __importDefault(require("immutable"));
7
+ /**
8
+ * ethereum.Value -> AssemblyScript conversions
9
+ */
10
+ const ETHEREUM_VALUE_TO_ASSEMBLYSCRIPT = [
11
+ // Scalar values
12
+ ['address', 'Address', (code) => `${code}.toAddress()`],
13
+ ['bool', 'boolean', (code) => `${code}.toBoolean()`],
14
+ ['byte', 'Bytes', (code) => `${code}.toBytes()`],
15
+ [
16
+ /^bytes(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|27|28|29|30|31|32)?$/,
17
+ 'Bytes',
18
+ (code) => `${code}.toBytes()`,
19
+ ],
20
+ [/^int(8|16|24|32)$/, 'i32', (code) => `${code}.toI32()`],
21
+ [/^uint(8|16|24)$/, 'i32', (code) => `${code}.toI32()`],
22
+ ['uint32', 'BigInt', (code) => `${code}.toBigInt()`],
23
+ [
24
+ /^u?int(40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)$/,
25
+ 'BigInt',
26
+ (code) => `${code}.toBigInt()`,
27
+ ],
28
+ ['string', 'string', (code) => `${code}.toString()`],
29
+ // Arrays
30
+ [/^address\[([0-9]+)?\]$/, 'Array<Address>', (code) => `${code}.toAddressArray()`],
31
+ [/^bool\[([0-9]+)?\]$/, 'Array<boolean>', (code) => `${code}.toBooleanArray()`],
32
+ [/^byte\[([0-9]+)?\]$/, 'Array<Bytes>', (code) => `${code}.toBytesArray()`],
33
+ [
34
+ /^bytes(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|27|28|29|30|31|32)?\[([0-9]+)?\]$/,
35
+ 'Array<Bytes>',
36
+ (code) => `${code}.toBytesArray()`,
37
+ ],
38
+ [/^int(8|16|24|32)\[([0-9]+)?\]$/, 'Array<i32>', (code) => `${code}.toI32Array()`],
39
+ [/^uint(8|16|24)\[([0-9]+)?\]$/, 'Array<i32>', (code) => `${code}.toI32Array()`],
40
+ [/^uint32\[([0-9]+)?\]$/, 'Array<BigInt>', (code) => `${code}.toBigIntArray()`],
41
+ [
42
+ /^u?int(40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)\[([0-9]+)?\]$/,
43
+ 'Array<BigInt>',
44
+ (code) => `${code}.toBigIntArray()`,
45
+ ],
46
+ [/^string\[([0-9]+)?\]$/, 'Array<string>', (code) => `${code}.toStringArray()`],
47
+ // Tuples
48
+ ['tuple', 'ethereum.Tuple', (code) => `${code}.toTuple()`],
49
+ [
50
+ /^tuple\[([0-9]+)?\]$/,
51
+ 'Array<ethereum.Tuple>',
52
+ (code, type) => `${code}.toTupleArray<${type}>()`,
53
+ ],
54
+ // Multi dimensional arrays
55
+ [
56
+ /^address\[([0-9]+)?\]\[([0-9]+)?\]$/,
57
+ 'Array<Array<Address>>',
58
+ (code) => `${code}.toAddressMatrix()`,
59
+ ],
60
+ [
61
+ /^bool\[([0-9]+)?\]\[([0-9]+)?\]$/,
62
+ 'Array<Array<boolean>>',
63
+ (code) => `${code}.toBooleanMatrix()`,
64
+ ],
65
+ [
66
+ /^byte\[([0-9]+)?\]\[([0-9]+)?\]$/,
67
+ 'Array<Array<Bytes>>',
68
+ (code) => `${code}.toBytesMatrix()`,
69
+ ],
70
+ [
71
+ /^bytes(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|27|28|29|30|31|32)?\[([0-9]+)?\]\[([0-9]+)?\]$/,
72
+ 'Array<Array<Bytes>>',
73
+ (code) => `${code}.toBytesMatrix()`,
74
+ ],
75
+ [
76
+ /^int(8|16|24|32)\[([0-9]+)?\]\[([0-9]+)?\]$/,
77
+ 'Array<Array<i32>>',
78
+ (code) => `${code}.toI32Matrix()`,
79
+ ],
80
+ [
81
+ /^uint(8|16|24)\[([0-9]+)?\]\[([0-9]+)?\]$/,
82
+ 'Array<Array<i32>>',
83
+ (code) => `${code}.toI32Matrix()`,
84
+ ],
85
+ [
86
+ /^uint32\[([0-9]+)?\]\[([0-9]+)?\]$/,
87
+ 'Array<Array<BigInt>>',
88
+ (code) => `${code}.toBigIntMatrix()`,
89
+ ],
90
+ [
91
+ /^u?int(40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)\[([0-9]+)?\]\[([0-9]+)?\]$/,
92
+ 'Array<Array<BigInt>>',
93
+ (code) => `${code}.toBigIntMatrix()`,
94
+ ],
95
+ [
96
+ /^string\[([0-9]+)?\]\[([0-9]+)?\]$/,
97
+ 'Array<Array<string>>',
98
+ (code) => `${code}.toStringMatrix()`,
99
+ ],
100
+ [
101
+ /^tuple\[([0-9]+)?\]\[([0-9]+)?\]$/,
102
+ 'Array<Array<ethereum.Tuple>>',
103
+ (code, type) => `${code}.toTupleMatrix<${type}>()`,
104
+ ],
105
+ ];
106
+ /**
107
+ * AssemblyScript -> ethereum.Value conversions
108
+ *
109
+ * Note: The order and patterns for conversions in this direction differ slightly
110
+ * from ethereum.Value -> AssemblyScript, which is why there is a separate table
111
+ * for them.
112
+ */
113
+ const ASSEMBLYSCRIPT_TO_ETHEREUM_VALUE = [
114
+ // Scalar values
115
+ ['Address', 'address', (code) => `ethereum.Value.fromAddress(${code})`],
116
+ ['boolean', 'bool', (code) => `ethereum.Value.fromBoolean(${code})`],
117
+ ['Bytes', 'byte', (code) => `ethereum.Value.fromFixedBytes(${code})`],
118
+ ['Bytes', 'bytes', (code) => `ethereum.Value.fromBytes(${code})`],
119
+ [
120
+ 'Bytes',
121
+ /^bytes(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|27|28|29|30|31|32)$/,
122
+ (code) => `ethereum.Value.fromFixedBytes(${code})`,
123
+ ],
124
+ ['i32', /^int(8|16|24|32)$/, (code) => `ethereum.Value.fromI32(${code})`],
125
+ [
126
+ 'i32',
127
+ /^uint(8|16|24)$/,
128
+ (code) => `ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(${code}))`,
129
+ ],
130
+ [
131
+ 'BigInt',
132
+ /^int(40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)$/,
133
+ (code) => `ethereum.Value.fromSignedBigInt(${code})`,
134
+ ],
135
+ [
136
+ 'BigInt',
137
+ /^uint(32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)$/,
138
+ (code) => `ethereum.Value.fromUnsignedBigInt(${code})`,
139
+ ],
140
+ ['string', 'string', (code) => `ethereum.Value.fromString(${code})`],
141
+ // Arrays
142
+ [
143
+ 'Array<Address>',
144
+ /^address\[([0-9]+)?\]$/,
145
+ (code) => `ethereum.Value.fromAddressArray(${code})`,
146
+ ],
147
+ [
148
+ 'Array<boolean>',
149
+ /^bool\[([0-9]+)?\]$/,
150
+ (code) => `ethereum.Value.fromBooleanArray(${code})`,
151
+ ],
152
+ [
153
+ 'Array<Bytes>',
154
+ /^byte\[([0-9]+)?\]$/,
155
+ (code) => `ethereum.Value.fromFixedBytesArray(${code})`,
156
+ ],
157
+ ['Array<Bytes>', /bytes\[([0-9]+)?\]$/, (code) => `ethereum.Value.fromBytesArray(${code})`],
158
+ [
159
+ 'Array<Bytes>',
160
+ /^bytes(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|27|28|29|30|31|32)\[([0-9]+)?\]$/,
161
+ (code) => `ethereum.Value.fromFixedBytesArray(${code})`,
162
+ ],
163
+ [
164
+ 'Array<i32>',
165
+ /^int(8|16|24|32)\[([0-9]+)?\]$/,
166
+ (code) => `ethereum.Value.fromI32Array(${code})`,
167
+ ],
168
+ [
169
+ 'Array<i32>',
170
+ /^uint(8|16|24)\[([0-9]+)?\]$/,
171
+ (code) => `ethereum.Value.fromI32Array(${code})`,
172
+ ],
173
+ [
174
+ 'Array<BigInt>',
175
+ /^int(40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)\[([0-9]+)?\]$/,
176
+ (code) => `ethereum.Value.fromSignedBigIntArray(${code})`,
177
+ ],
178
+ [
179
+ 'Array<BigInt>',
180
+ /^uint(32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)\[([0-9]+)?\]$/,
181
+ (code) => `ethereum.Value.fromUnsignedBigIntArray(${code})`,
182
+ ],
183
+ [
184
+ 'Array<string>',
185
+ /^string\[([0-9]+)?\]$/,
186
+ (code) => `ethereum.Value.fromStringArray(${code})`,
187
+ ],
188
+ // Tuples
189
+ ['ethereum.Tuple', 'tuple', (code) => `ethereum.Value.fromTuple(${code})`],
190
+ [
191
+ 'Array<ethereum.Tuple>',
192
+ /^tuple\[([0-9]+)?\]$/,
193
+ (code) => `ethereum.Value.fromTupleArray(${code})`,
194
+ ],
195
+ // Multi dimentional arrays
196
+ [
197
+ 'Array<Array<Address>>',
198
+ /^address\[([0-9]+)?\]\[([0-9]+)?\]$/,
199
+ (code) => `ethereum.Value.fromAddressMatrix(${code})`,
200
+ ],
201
+ [
202
+ 'Array<Array<boolean>>',
203
+ /^bool\[([0-9]+)?\]\[([0-9]+)?\]$/,
204
+ (code) => `ethereum.Value.fromBooleanMatrix(${code})`,
205
+ ],
206
+ [
207
+ 'Array<Array<Bytes>>',
208
+ /^byte\[([0-9]+)?\]\[([0-9]+)?\]$/,
209
+ (code) => `ethereum.Value.fromFixedBytesMatrix(${code})`,
210
+ ],
211
+ [
212
+ 'Array<Array<Bytes>>',
213
+ /bytes\[([0-9]+)?\]\[([0-9]+)?\]$/,
214
+ (code) => `ethereum.Value.fromBytesMatrix(${code})`,
215
+ ],
216
+ [
217
+ 'Array<Array<Bytes>>',
218
+ /^bytes(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|27|28|29|30|31|32)\[([0-9]+)?\]\[([0-9]+)?\]$/,
219
+ (code) => `ethereum.Value.fromFixedBytesMatrix(${code})`,
220
+ ],
221
+ [
222
+ 'Array<Array<i32>>',
223
+ /^int(8|16|24|32)\[([0-9]+)?\]\[([0-9]+)?\]$/,
224
+ (code) => `ethereum.Value.fromI32Matrix(${code})`,
225
+ ],
226
+ [
227
+ 'Array<Array<i32>>',
228
+ /^uint(8|16|24)\[([0-9]+)?\]\[([0-9]+)?\]$/,
229
+ (code) => `ethereum.Value.fromI32Matrix(${code})`,
230
+ ],
231
+ [
232
+ 'Array<Array<BigInt>>',
233
+ /^int(40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)\[([0-9]+)?\]\[([0-9]+)?\]$/,
234
+ (code) => `ethereum.Value.fromSignedBigIntMatrix(${code})`,
235
+ ],
236
+ [
237
+ 'Array<Array<BigInt>>',
238
+ /^uint(32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)\[([0-9]+)?\]\[([0-9]+)?\]$/,
239
+ (code) => `ethereum.Value.fromUnsignedBigIntMatrix(${code})`,
240
+ ],
241
+ [
242
+ 'Array<Array<string>>',
243
+ /^string\[([0-9]+)?\]\[([0-9]+)?\]$/,
244
+ (code) => `ethereum.Value.fromStringMatrix(${code})`,
245
+ ],
246
+ [
247
+ 'Array<Array<ethereum.Tuple>>',
248
+ /^tuple\[([0-9]+)?\]\[([0-9]+)?\]$/,
249
+ (code) => `ethereum.Value.fromTupleMatrix(${code})`,
250
+ ],
251
+ ];
252
+ /**
253
+ * Value -> AssemblyScript conversions
254
+ */
255
+ const VALUE_TO_ASSEMBLYSCRIPT = [
256
+ // Arrays
257
+ ['[Bytes]', 'Array<Bytes>', (code) => `${code}.toBytesArray()`],
258
+ ['[Boolean]', 'Array<boolean>', (code) => `${code}.toBooleanArray()`],
259
+ ['[Int]', 'Array<i32>', (code) => `${code}.toI32Array()`],
260
+ ['[BigInt]', 'Array<BigInt>', (code) => `${code}.toBigIntArray()`],
261
+ ['[ID]', 'Array<string>', (code) => `${code}.toStringArray()`],
262
+ ['[String]', 'Array<string>', (code) => `${code}.toStringArray()`],
263
+ ['[BigDecimal]', 'Array<BigDecimal>', (code) => `${code}.toBigDecimalArray()`],
264
+ [/\[.*\]/, 'Array<string>', (code) => `${code}.toStringArray()`],
265
+ // Scalar values
266
+ ['Bytes', 'Bytes', (code) => `${code}.toBytes()`],
267
+ ['Boolean', 'boolean', (code) => `${code}.toBoolean()`],
268
+ ['Int', 'i32', (code) => `${code}.toI32()`],
269
+ ['BigInt', 'BigInt', (code) => `${code}.toBigInt()`],
270
+ ['ID', 'string', (code) => `${code}.toString()`],
271
+ ['String', 'string', (code) => `${code}.toString()`],
272
+ ['BigDecimal', 'BigDecimal', (code) => `${code}.toBigDecimal()`],
273
+ [/.*/, 'string', (code) => `${code}.toString()`],
274
+ ];
275
+ /**
276
+ * AssemblyScript -> Value conversions
277
+ *
278
+ * Note: The order and patterns for conversions in this direction differ slightly
279
+ * from Value -> AssemblyScript, which is why there is a separate table
280
+ * for them.
281
+ */
282
+ const ASSEMBLYSCRIPT_TO_VALUE = [
283
+ // Matrices
284
+ ['Array<Array<Address>>', '[[Bytes]]', (code) => `Value.fromBytesMatrix(${code})`],
285
+ ['Array<Array<Bytes>>', '[[Bytes]]', (code) => `Value.fromBytesMatrix(${code})`],
286
+ ['Array<Array<boolean>>', '[[Boolean]]', (code) => `Value.fromBooleanMatrix(${code})`],
287
+ ['Array<Array<i32>>', '[[Int]]', (code) => `Value.fromI32Matrix(${code})`],
288
+ ['Array<Array<BigInt>>', '[[BigInt]]', (code) => `Value.fromBigIntMatrix(${code})`],
289
+ ['Array<Array<string>>', '[[String]]', (code) => `Value.fromStringMatrix(${code})`],
290
+ ['Array<Array<string>>', '[[ID]]', (code) => `Value.fromStringMatrix(${code})`],
291
+ [
292
+ 'Array<Array<BigDecimal>>',
293
+ '[[BigDecimal]]',
294
+ (code) => `Value.fromBigDecimalMatrix(${code})`,
295
+ ],
296
+ ['Array<Array<string>>', /\[\[.*\]\]/, (code) => `Value.fromStringMatrix(${code})`],
297
+ ['Array<Array<string | null>>', null, (code) => `Value.fromStringMatrix(${code})`],
298
+ // Arrays
299
+ ['Array<Address>', '[Bytes]', (code) => `Value.fromBytesArray(${code})`],
300
+ ['Array<Bytes>', '[Bytes]', (code) => `Value.fromBytesArray(${code})`],
301
+ ['Array<boolean>', '[Boolean]', (code) => `Value.fromBooleanArray(${code})`],
302
+ ['Array<i32>', '[Int]', (code) => `Value.fromI32Array(${code})`],
303
+ ['Array<BigInt>', '[BigInt]', (code) => `Value.fromBigIntArray(${code})`],
304
+ ['Array<string>', '[String]', (code) => `Value.fromStringArray(${code})`],
305
+ ['Array<string>', '[ID]', (code) => `Value.fromStringArray(${code})`],
306
+ ['Array<BigDecimal>', '[BigDecimal]', (code) => `Value.fromBigDecimalArray(${code})`],
307
+ ['Array<string>', /\[.*\]/, (code) => `Value.fromStringArray(${code})`],
308
+ ['Array<string | null>', null, (code) => `Value.fromStringArray(${code})`],
309
+ // Scalar values
310
+ ['Address', 'Bytes', (code) => `Value.fromBytes(${code})`],
311
+ ['Bytes', 'Bytes', (code) => `Value.fromBytes(${code})`],
312
+ ['boolean', 'Boolean', (code) => `Value.fromBoolean(${code})`],
313
+ ['i32', 'Int', (code) => `Value.fromI32(${code})`],
314
+ ['BigInt', 'BigInt', (code) => `Value.fromBigInt(${code})`],
315
+ ['string', 'String', (code) => `Value.fromString(${code})`],
316
+ ['string', 'ID', (code) => `Value.fromString(${code})`],
317
+ ['BigDecimal', 'BigDecimal', (code) => `Value.fromBigDecimal(${code})`],
318
+ ['string', /.*/, (code) => `Value.fromString(${code})`],
319
+ ];
320
+ const CONVERSIONS = {
321
+ ethereum: {
322
+ AssemblyScript: ETHEREUM_VALUE_TO_ASSEMBLYSCRIPT,
323
+ },
324
+ AssemblyScript: {
325
+ ethereum: ASSEMBLYSCRIPT_TO_ETHEREUM_VALUE,
326
+ Value: ASSEMBLYSCRIPT_TO_VALUE,
327
+ },
328
+ Value: {
329
+ AssemblyScript: VALUE_TO_ASSEMBLYSCRIPT,
330
+ },
331
+ };
332
+ /**
333
+ * Type conversions
334
+ */
335
+ exports.default = immutable_1.default.fromJS(CONVERSIONS);
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.valueFromAsc = exports.valueToAsc = exports.valueTypeForAsc = exports.ascTypeForValue = exports.ethereumFromAsc = exports.ethereumToAsc = exports.ethereumTypeForAsc = exports.ascTypeForEthereum = exports.ascTypeForProtocol = void 0;
7
+ const immutable_1 = __importDefault(require("immutable"));
8
+ const conversions_1 = __importDefault(require("./conversions"));
9
+ // Conversion utilities
10
+ const conversionsForTypeSystems = (fromTypeSystem, toTypeSystem) => {
11
+ const conversions = conversions_1.default.getIn([fromTypeSystem, toTypeSystem]);
12
+ if (conversions === undefined) {
13
+ throw new Error(`Conversions from '${fromTypeSystem}' to '${toTypeSystem}' are not supported`);
14
+ }
15
+ return conversions;
16
+ };
17
+ const objectifyConversion = (fromTypeSystem, toTypeSystem, conversion) => {
18
+ return immutable_1.default.fromJS({
19
+ from: {
20
+ typeSystem: fromTypeSystem,
21
+ type: conversion.get(0),
22
+ },
23
+ to: {
24
+ typeSystem: toTypeSystem,
25
+ type: conversion.get(1),
26
+ },
27
+ convert: conversion.get(2),
28
+ });
29
+ };
30
+ const findConversionFromType = (fromTypeSystem, toTypeSystem, fromType) => {
31
+ const conversions = conversionsForTypeSystems(fromTypeSystem, toTypeSystem);
32
+ const conversion = conversions.find(conversion => typeof conversion.get(0) === 'string'
33
+ ? conversion.get(0) === fromType
34
+ : !!fromType.match(conversion.get(0)));
35
+ if (conversion === undefined) {
36
+ throw new Error(`Conversion from '${fromTypeSystem}' to '${toTypeSystem}' for ` +
37
+ `source type '${fromType}' is not supported`);
38
+ }
39
+ return objectifyConversion(fromTypeSystem, toTypeSystem, conversion);
40
+ };
41
+ const findConversionToType = (fromTypeSystem, toTypeSystem, toType) => {
42
+ const conversions = conversionsForTypeSystems(fromTypeSystem, toTypeSystem);
43
+ const conversion = conversions.find(conversion => typeof conversion.get(1) === 'string'
44
+ ? conversion.get(1) === toType
45
+ : !!toType.match(conversion.get(1)));
46
+ if (conversion === undefined) {
47
+ throw new Error(`Conversion from '${fromTypeSystem}' to '${toTypeSystem}' for ` +
48
+ `target type '${toType}' is not supported`);
49
+ }
50
+ return objectifyConversion(fromTypeSystem, toTypeSystem, conversion);
51
+ };
52
+ // High-level type system API
53
+ const ascTypeForProtocol = (protocol, protocolType) => findConversionFromType(protocol, 'AssemblyScript', protocolType).getIn(['to', 'type']);
54
+ exports.ascTypeForProtocol = ascTypeForProtocol;
55
+ // TODO: this can be removed/replaced by the function above
56
+ const ascTypeForEthereum = (ethereumType) => (0, exports.ascTypeForProtocol)('ethereum', ethereumType);
57
+ exports.ascTypeForEthereum = ascTypeForEthereum;
58
+ const ethereumTypeForAsc = (ascType) => findConversionFromType('AssemblyScript', 'ethereum', ascType).getIn(['to', 'type']);
59
+ exports.ethereumTypeForAsc = ethereumTypeForAsc;
60
+ const ethereumToAsc = (code, ethereumType, internalType) => findConversionFromType('ethereum', 'AssemblyScript', ethereumType).get('convert')(code, internalType);
61
+ exports.ethereumToAsc = ethereumToAsc;
62
+ const ethereumFromAsc = (code, ethereumType) => findConversionToType('AssemblyScript', 'ethereum', ethereumType).get('convert')(code);
63
+ exports.ethereumFromAsc = ethereumFromAsc;
64
+ const ascTypeForValue = (valueType) => findConversionFromType('Value', 'AssemblyScript', valueType).getIn(['to', 'type']);
65
+ exports.ascTypeForValue = ascTypeForValue;
66
+ const valueTypeForAsc = (ascType) => findConversionFromType('AssemblyScript', 'Value', ascType).getIn(['to', 'type']);
67
+ exports.valueTypeForAsc = valueTypeForAsc;
68
+ const valueToAsc = (code, valueType) => findConversionFromType('Value', 'AssemblyScript', valueType).get('convert')(code);
69
+ exports.valueToAsc = valueToAsc;
70
+ const valueFromAsc = (code, valueType) => findConversionToType('AssemblyScript', 'Value', valueType).get('convert')(code);
71
+ exports.valueFromAsc = valueFromAsc;