@graphprotocol/graph-cli 0.37.3-alpha-20230113140726-64762bb → 0.37.3

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 (131) hide show
  1. package/CHANGELOG.md +5 -1
  2. package/package.json +1 -1
  3. package/src/cli.ts +1 -1
  4. package/src/command-helpers/abi.ts +2 -0
  5. package/src/command-helpers/auth.ts +3 -3
  6. package/src/command-helpers/compiler.ts +1 -1
  7. package/src/command-helpers/fs.ts +1 -1
  8. package/src/command-helpers/network.test.ts +1 -1
  9. package/src/command-helpers/network.ts +1 -1
  10. package/src/command-helpers/node.ts +1 -1
  11. package/src/command-helpers/scaffold.ts +1 -1
  12. package/src/commands/codegen.ts +1 -1
  13. package/src/commands/create.ts +1 -1
  14. package/src/commands/deploy.ts +2 -2
  15. package/src/commands/init.ts +3 -3
  16. package/src/commands/local.ts +4 -4
  17. package/src/commands/remove.ts +1 -1
  18. package/src/commands/test.ts +3 -3
  19. package/src/compiler/index.ts +2 -2
  20. package/src/migrations/util/load-manifest.ts +1 -1
  21. package/src/migrations/util/versions.ts +1 -1
  22. package/src/protocols/ethereum/abi.ts +1 -1
  23. package/src/protocols/ethereum/codegen/abi.test.ts +1 -1
  24. package/src/protocols/ethereum/codegen/abi.ts +1 -1
  25. package/src/protocols/ethereum/type-generator.ts +1 -1
  26. package/src/subgraph.ts +1 -1
  27. package/src/type-generator.ts +1 -1
  28. package/src/validation/manifest.ts +2 -2
  29. package/src/validation/schema.ts +1 -1
  30. package/src/watcher.ts +1 -1
  31. package/tests/cli/init.test.ts +1 -1
  32. package/tests/cli/spawn-command.d.ts +1 -1
  33. package/tests/cli/util.ts +1 -1
  34. package/dist/bin.js +0 -6
  35. package/dist/cli.js +0 -26
  36. package/dist/codegen/schema.js +0 -244
  37. package/dist/codegen/schema.test.js +0 -455
  38. package/dist/codegen/template.js +0 -66
  39. package/dist/codegen/types/conversions.js +0 -335
  40. package/dist/codegen/types/index.js +0 -71
  41. package/dist/codegen/types/index.test.js +0 -563
  42. package/dist/codegen/typescript.js +0 -200
  43. package/dist/codegen/util.js +0 -40
  44. package/dist/codegen/util.test.js +0 -93
  45. package/dist/command-helpers/abi.js +0 -74
  46. package/dist/command-helpers/auth.js +0 -76
  47. package/dist/command-helpers/compiler.js +0 -66
  48. package/dist/command-helpers/data-sources.js +0 -29
  49. package/dist/command-helpers/fs.js +0 -9
  50. package/dist/command-helpers/gluegun.js +0 -48
  51. package/dist/command-helpers/ipfs.js +0 -5
  52. package/dist/command-helpers/jsonrpc.js +0 -27
  53. package/dist/command-helpers/network.js +0 -90
  54. package/dist/command-helpers/network.test.js +0 -86
  55. package/dist/command-helpers/node.js +0 -40
  56. package/dist/command-helpers/scaffold.js +0 -110
  57. package/dist/command-helpers/spinner.js +0 -80
  58. package/dist/command-helpers/studio.js +0 -14
  59. package/dist/command-helpers/studio.test.js +0 -41
  60. package/dist/command-helpers/subgraph.js +0 -22
  61. package/dist/command-helpers/version.js +0 -66
  62. package/dist/command-helpers/version.test.js +0 -186
  63. package/dist/commands/add.js +0 -187
  64. package/dist/commands/auth.js +0 -122
  65. package/dist/commands/build.js +0 -136
  66. package/dist/commands/codegen.js +0 -128
  67. package/dist/commands/create.js +0 -94
  68. package/dist/commands/deploy.js +0 -335
  69. package/dist/commands/init.js +0 -800
  70. package/dist/commands/local.js +0 -380
  71. package/dist/commands/remove.js +0 -95
  72. package/dist/commands/test.js +0 -293
  73. package/dist/compiler/asc.js +0 -83
  74. package/dist/compiler/index.js +0 -466
  75. package/dist/debug.js +0 -16
  76. package/dist/migrations/mapping_api_version_0_0_1.js +0 -83
  77. package/dist/migrations/mapping_api_version_0_0_2.js +0 -83
  78. package/dist/migrations/mapping_api_version_0_0_3.js +0 -83
  79. package/dist/migrations/mapping_api_version_0_0_4.js +0 -85
  80. package/dist/migrations/mapping_api_version_0_0_5.js +0 -85
  81. package/dist/migrations/spec_version_0_0_2.js +0 -45
  82. package/dist/migrations/spec_version_0_0_3.js +0 -50
  83. package/dist/migrations/util/load-manifest.js +0 -16
  84. package/dist/migrations/util/versions.js +0 -28
  85. package/dist/migrations.js +0 -54
  86. package/dist/protocols/arweave/manifest.graphql +0 -57
  87. package/dist/protocols/arweave/scaffold/manifest.js +0 -18
  88. package/dist/protocols/arweave/scaffold/mapping.js +0 -52
  89. package/dist/protocols/arweave/subgraph.js +0 -23
  90. package/dist/protocols/contract.js +0 -2
  91. package/dist/protocols/cosmos/manifest.graphql +0 -76
  92. package/dist/protocols/cosmos/scaffold/manifest.js +0 -15
  93. package/dist/protocols/cosmos/scaffold/mapping.js +0 -38
  94. package/dist/protocols/cosmos/subgraph.js +0 -28
  95. package/dist/protocols/ethereum/abi.js +0 -138
  96. package/dist/protocols/ethereum/codegen/abi.js +0 -474
  97. package/dist/protocols/ethereum/codegen/abi.test.js +0 -325
  98. package/dist/protocols/ethereum/codegen/template.js +0 -52
  99. package/dist/protocols/ethereum/contract.js +0 -22
  100. package/dist/protocols/ethereum/manifest.graphql +0 -94
  101. package/dist/protocols/ethereum/scaffold/manifest.js +0 -32
  102. package/dist/protocols/ethereum/scaffold/mapping.js +0 -65
  103. package/dist/protocols/ethereum/subgraph.js +0 -172
  104. package/dist/protocols/ethereum/type-generator.js +0 -123
  105. package/dist/protocols/index.js +0 -266
  106. package/dist/protocols/ipfs/codegen/file_template.js +0 -53
  107. package/dist/protocols/near/contract.js +0 -41
  108. package/dist/protocols/near/manifest.graphql +0 -64
  109. package/dist/protocols/near/scaffold/manifest.js +0 -16
  110. package/dist/protocols/near/scaffold/mapping.js +0 -38
  111. package/dist/protocols/near/subgraph.js +0 -23
  112. package/dist/protocols/subgraph.js +0 -2
  113. package/dist/protocols/substreams/manifest.graphql +0 -45
  114. package/dist/protocols/substreams/scaffold/manifest.js +0 -12
  115. package/dist/protocols/substreams/subgraph.js +0 -23
  116. package/dist/scaffold/cosmos.test.js +0 -82
  117. package/dist/scaffold/ethereum.test.js +0 -496
  118. package/dist/scaffold/index.js +0 -133
  119. package/dist/scaffold/mapping.js +0 -57
  120. package/dist/scaffold/near.test.js +0 -85
  121. package/dist/scaffold/schema.js +0 -86
  122. package/dist/scaffold/tests.js +0 -179
  123. package/dist/schema.js +0 -54
  124. package/dist/subgraph.js +0 -243
  125. package/dist/type-generator.js +0 -225
  126. package/dist/validation/contract.js +0 -44
  127. package/dist/validation/index.js +0 -10
  128. package/dist/validation/manifest.js +0 -266
  129. package/dist/validation/schema.js +0 -768
  130. package/dist/validation/schema.test.js +0 -35
  131. package/dist/watcher.js +0 -79
@@ -1,335 +0,0 @@
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);
@@ -1,71 +0,0 @@
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;