@graphprotocol/graph-cli 0.37.2 → 0.37.3-alpha-20230110163550-d64bef6

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 (206) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/babel.config.js +3 -0
  3. package/dist/bin.js +6 -0
  4. package/dist/cli.js +32 -0
  5. package/dist/codegen/schema.js +250 -0
  6. package/dist/codegen/schema.test.js +458 -0
  7. package/dist/codegen/template.js +65 -0
  8. package/dist/codegen/types/conversions.js +359 -0
  9. package/dist/codegen/types/index.js +71 -0
  10. package/dist/codegen/types/index.test.js +563 -0
  11. package/dist/codegen/typescript.js +200 -0
  12. package/dist/codegen/util.js +46 -0
  13. package/dist/codegen/util.test.js +93 -0
  14. package/dist/command-helpers/abi.js +78 -0
  15. package/dist/command-helpers/auth.js +77 -0
  16. package/dist/command-helpers/compiler.js +66 -0
  17. package/dist/command-helpers/data-sources.js +29 -0
  18. package/dist/command-helpers/fs.js +9 -0
  19. package/dist/command-helpers/gluegun.js +49 -0
  20. package/dist/command-helpers/ipfs.js +5 -0
  21. package/dist/command-helpers/jsonrpc.js +29 -0
  22. package/dist/command-helpers/network.js +93 -0
  23. package/dist/command-helpers/network.test.js +86 -0
  24. package/dist/command-helpers/node.js +40 -0
  25. package/dist/command-helpers/scaffold.js +112 -0
  26. package/dist/command-helpers/spinner.js +84 -0
  27. package/dist/command-helpers/studio.js +13 -0
  28. package/dist/command-helpers/studio.test.js +41 -0
  29. package/dist/command-helpers/subgraph.js +24 -0
  30. package/dist/command-helpers/version.js +74 -0
  31. package/dist/command-helpers/version.test.js +179 -0
  32. package/dist/commands/add.js +190 -0
  33. package/dist/commands/auth.js +127 -0
  34. package/dist/commands/build.js +140 -0
  35. package/dist/commands/codegen.js +135 -0
  36. package/dist/commands/create.js +86 -0
  37. package/dist/commands/deploy.js +334 -0
  38. package/dist/commands/init.js +788 -0
  39. package/dist/commands/local.js +387 -0
  40. package/dist/commands/remove.js +86 -0
  41. package/dist/commands/test.js +295 -0
  42. package/dist/compiler/asc.js +83 -0
  43. package/dist/compiler/index.js +474 -0
  44. package/dist/debug.js +16 -0
  45. package/dist/migrations/mapping_api_version_0_0_1.js +78 -0
  46. package/dist/migrations/mapping_api_version_0_0_2.js +76 -0
  47. package/dist/migrations/mapping_api_version_0_0_3.js +78 -0
  48. package/dist/migrations/mapping_api_version_0_0_4.js +80 -0
  49. package/dist/migrations/mapping_api_version_0_0_5.js +80 -0
  50. package/dist/migrations/spec_version_0_0_2.js +49 -0
  51. package/dist/migrations/spec_version_0_0_3.js +54 -0
  52. package/dist/migrations/util/load-manifest.js +18 -0
  53. package/dist/migrations/util/versions.js +29 -0
  54. package/dist/migrations.js +56 -0
  55. package/dist/protocols/arweave/manifest.graphql +57 -0
  56. package/dist/protocols/arweave/scaffold/manifest.js +18 -0
  57. package/dist/protocols/arweave/scaffold/mapping.js +52 -0
  58. package/dist/protocols/arweave/subgraph.js +23 -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 +25 -0
  63. package/dist/protocols/ethereum/abi.js +140 -0
  64. package/dist/protocols/ethereum/codegen/abi.js +451 -0
  65. package/dist/protocols/ethereum/codegen/abi.test.js +328 -0
  66. package/dist/protocols/ethereum/codegen/template.js +50 -0
  67. package/dist/protocols/ethereum/contract.js +20 -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 +171 -0
  72. package/dist/protocols/ethereum/type-generator.js +125 -0
  73. package/dist/protocols/index.js +268 -0
  74. package/dist/protocols/ipfs/codegen/file_template.js +50 -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 +20 -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 +83 -0
  85. package/dist/scaffold/ethereum.test.js +505 -0
  86. package/dist/scaffold/index.js +128 -0
  87. package/dist/scaffold/mapping.js +61 -0
  88. package/dist/scaffold/near.test.js +86 -0
  89. package/dist/scaffold/schema.js +83 -0
  90. package/dist/scaffold/tests.js +175 -0
  91. package/dist/schema.js +54 -0
  92. package/dist/subgraph.js +249 -0
  93. package/dist/type-generator.js +224 -0
  94. package/dist/validation/contract.js +46 -0
  95. package/dist/validation/index.js +8 -0
  96. package/dist/validation/manifest.js +271 -0
  97. package/dist/validation/schema.js +796 -0
  98. package/dist/validation/schema.test.js +35 -0
  99. package/dist/watcher.js +79 -0
  100. package/jest.config.js +1 -1
  101. package/package.json +16 -9
  102. package/{bin/graph → src/bin.ts} +2 -1
  103. package/src/cli.ts +36 -0
  104. package/src/codegen/schema.js +23 -22
  105. package/src/codegen/schema.test.js +33 -27
  106. package/src/codegen/{template.js → template.ts} +8 -6
  107. package/src/codegen/types/conversions.ts +382 -0
  108. package/src/codegen/types/index.js +4 -7
  109. package/src/codegen/types/index.test.js +10 -4
  110. package/src/codegen/{typescript.js → typescript.ts} +44 -26
  111. package/src/codegen/util.js +1 -1
  112. package/src/codegen/util.test.js +5 -2
  113. package/src/command-helpers/abi.js +46 -30
  114. package/src/command-helpers/auth.js +6 -9
  115. package/src/command-helpers/compiler.js +4 -6
  116. package/src/command-helpers/data-sources.js +8 -11
  117. package/src/command-helpers/fs.ts +5 -0
  118. package/src/command-helpers/gluegun.js +2 -4
  119. package/src/command-helpers/ipfs.ts +3 -0
  120. package/src/command-helpers/{jsonrpc.js → jsonrpc.ts} +11 -16
  121. package/src/command-helpers/network.js +58 -44
  122. package/src/command-helpers/network.test.js +23 -19
  123. package/src/command-helpers/node.js +3 -7
  124. package/src/command-helpers/scaffold.js +34 -25
  125. package/src/command-helpers/{spinner.js → spinner.ts} +10 -10
  126. package/src/command-helpers/studio.test.js +61 -30
  127. package/src/command-helpers/studio.ts +20 -0
  128. package/src/command-helpers/{subgraph.js → subgraph.ts} +6 -6
  129. package/src/command-helpers/version.js +11 -16
  130. package/src/command-helpers/version.test.js +111 -82
  131. package/src/commands/add.js +49 -35
  132. package/src/commands/auth.js +13 -25
  133. package/src/commands/build.js +9 -9
  134. package/src/commands/codegen.js +12 -12
  135. package/src/commands/create.js +22 -22
  136. package/src/commands/deploy.js +39 -34
  137. package/src/commands/init.js +21 -24
  138. package/src/commands/local.js +15 -14
  139. package/src/commands/remove.js +22 -22
  140. package/src/commands/test.js +86 -70
  141. package/src/compiler/{asc.js → asc.ts} +29 -16
  142. package/src/compiler/index.js +18 -18
  143. package/src/{debug.js → debug.ts} +2 -2
  144. package/src/migrations/mapping_api_version_0_0_1.js +7 -7
  145. package/src/migrations/mapping_api_version_0_0_2.js +5 -5
  146. package/src/migrations/mapping_api_version_0_0_3.js +7 -7
  147. package/src/migrations/mapping_api_version_0_0_4.js +7 -7
  148. package/src/migrations/mapping_api_version_0_0_5.js +7 -7
  149. package/src/migrations/spec_version_0_0_2.js +5 -5
  150. package/src/migrations/spec_version_0_0_3.js +5 -5
  151. package/src/migrations/util/load-manifest.js +6 -9
  152. package/src/migrations/util/versions.js +5 -10
  153. package/src/{migrations.js → migrations.ts} +14 -15
  154. package/src/protocols/arweave/scaffold/manifest.js +1 -4
  155. package/src/protocols/arweave/scaffold/mapping.js +1 -3
  156. package/src/protocols/arweave/subgraph.ts +22 -0
  157. package/src/protocols/cosmos/scaffold/manifest.js +1 -4
  158. package/src/protocols/cosmos/scaffold/mapping.js +1 -3
  159. package/src/protocols/cosmos/subgraph.js +2 -2
  160. package/src/protocols/ethereum/abi.js +7 -13
  161. package/src/protocols/ethereum/codegen/abi.js +219 -222
  162. package/src/protocols/ethereum/codegen/abi.test.js +6 -6
  163. package/src/protocols/ethereum/codegen/template.js +3 -5
  164. package/src/protocols/ethereum/contract.js +3 -2
  165. package/src/protocols/ethereum/scaffold/manifest.js +4 -7
  166. package/src/protocols/ethereum/scaffold/mapping.js +4 -11
  167. package/src/protocols/ethereum/subgraph.js +21 -20
  168. package/src/protocols/ethereum/type-generator.js +24 -30
  169. package/src/protocols/{index.js → index.ts} +65 -46
  170. package/src/protocols/ipfs/codegen/file_template.js +2 -2
  171. package/src/protocols/near/{contract.js → contract.ts} +16 -12
  172. package/src/protocols/near/scaffold/manifest.js +2 -5
  173. package/src/protocols/near/scaffold/mapping.js +1 -3
  174. package/src/protocols/near/subgraph.js +3 -6
  175. package/src/protocols/subgraph.ts +12 -0
  176. package/src/protocols/substreams/scaffold/{manifest.js → manifest.ts} +2 -7
  177. package/src/protocols/substreams/subgraph.ts +22 -0
  178. package/src/scaffold/cosmos.test.js +3 -3
  179. package/src/scaffold/ethereum.test.js +4 -4
  180. package/src/scaffold/index.js +7 -7
  181. package/src/scaffold/mapping.js +3 -3
  182. package/src/scaffold/near.test.js +3 -3
  183. package/src/scaffold/schema.js +4 -4
  184. package/src/scaffold/tests.js +72 -58
  185. package/src/schema.ts +26 -0
  186. package/src/{subgraph.js → subgraph.ts} +80 -60
  187. package/src/type-generator.js +20 -20
  188. package/src/validation/contract.js +2 -6
  189. package/src/validation/index.js +1 -1
  190. package/src/validation/manifest.js +24 -22
  191. package/src/validation/schema.test.js +1 -1
  192. package/src/validation/{schema.js → schema.ts} +268 -221
  193. package/src/{watcher.js → watcher.ts} +23 -12
  194. package/tests/cli/globalSetup.js +2 -2
  195. package/tests/cli/globalTeardown.js +2 -2
  196. package/tests/cli/init.test.js +2 -2
  197. package/tests/cli/util.js +7 -13
  198. package/tsconfig.json +18 -0
  199. package/src/cli.js +0 -38
  200. package/src/codegen/types/conversions.js +0 -329
  201. package/src/command-helpers/fs.js +0 -8
  202. package/src/command-helpers/ipfs.js +0 -6
  203. package/src/command-helpers/studio.js +0 -15
  204. package/src/protocols/arweave/subgraph.js +0 -20
  205. package/src/protocols/substreams/subgraph.js +0 -17
  206. package/src/schema.js +0 -23
@@ -0,0 +1,359 @@
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
+ [
158
+ 'Array<Bytes>',
159
+ /bytes\[([0-9]+)?\]$/,
160
+ (code) => `ethereum.Value.fromBytesArray(${code})`,
161
+ ],
162
+ [
163
+ 'Array<Bytes>',
164
+ /^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]+)?\]$/,
165
+ (code) => `ethereum.Value.fromFixedBytesArray(${code})`,
166
+ ],
167
+ [
168
+ 'Array<i32>',
169
+ /^int(8|16|24|32)\[([0-9]+)?\]$/,
170
+ (code) => `ethereum.Value.fromI32Array(${code})`,
171
+ ],
172
+ [
173
+ 'Array<i32>',
174
+ /^uint(8|16|24)\[([0-9]+)?\]$/,
175
+ (code) => `ethereum.Value.fromI32Array(${code})`,
176
+ ],
177
+ [
178
+ 'Array<BigInt>',
179
+ /^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]+)?\]$/,
180
+ (code) => `ethereum.Value.fromSignedBigIntArray(${code})`,
181
+ ],
182
+ [
183
+ 'Array<BigInt>',
184
+ /^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]+)?\]$/,
185
+ (code) => `ethereum.Value.fromUnsignedBigIntArray(${code})`,
186
+ ],
187
+ [
188
+ 'Array<string>',
189
+ /^string\[([0-9]+)?\]$/,
190
+ (code) => `ethereum.Value.fromStringArray(${code})`,
191
+ ],
192
+ // Tuples
193
+ ['ethereum.Tuple', 'tuple', (code) => `ethereum.Value.fromTuple(${code})`],
194
+ [
195
+ 'Array<ethereum.Tuple>',
196
+ /^tuple\[([0-9]+)?\]$/,
197
+ (code) => `ethereum.Value.fromTupleArray(${code})`,
198
+ ],
199
+ // Multi dimentional arrays
200
+ [
201
+ 'Array<Array<Address>>',
202
+ /^address\[([0-9]+)?\]\[([0-9]+)?\]$/,
203
+ (code) => `ethereum.Value.fromAddressMatrix(${code})`,
204
+ ],
205
+ [
206
+ 'Array<Array<boolean>>',
207
+ /^bool\[([0-9]+)?\]\[([0-9]+)?\]$/,
208
+ (code) => `ethereum.Value.fromBooleanMatrix(${code})`,
209
+ ],
210
+ [
211
+ 'Array<Array<Bytes>>',
212
+ /^byte\[([0-9]+)?\]\[([0-9]+)?\]$/,
213
+ (code) => `ethereum.Value.fromFixedBytesMatrix(${code})`,
214
+ ],
215
+ [
216
+ 'Array<Array<Bytes>>',
217
+ /bytes\[([0-9]+)?\]\[([0-9]+)?\]$/,
218
+ (code) => `ethereum.Value.fromBytesMatrix(${code})`,
219
+ ],
220
+ [
221
+ 'Array<Array<Bytes>>',
222
+ /^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]+)?\]$/,
223
+ (code) => `ethereum.Value.fromFixedBytesMatrix(${code})`,
224
+ ],
225
+ [
226
+ 'Array<Array<i32>>',
227
+ /^int(8|16|24|32)\[([0-9]+)?\]\[([0-9]+)?\]$/,
228
+ (code) => `ethereum.Value.fromI32Matrix(${code})`,
229
+ ],
230
+ [
231
+ 'Array<Array<i32>>',
232
+ /^uint(8|16|24)\[([0-9]+)?\]\[([0-9]+)?\]$/,
233
+ (code) => `ethereum.Value.fromI32Matrix(${code})`,
234
+ ],
235
+ [
236
+ 'Array<Array<BigInt>>',
237
+ /^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]+)?\]$/,
238
+ (code) => `ethereum.Value.fromSignedBigIntMatrix(${code})`,
239
+ ],
240
+ [
241
+ 'Array<Array<BigInt>>',
242
+ /^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]+)?\]$/,
243
+ (code) => `ethereum.Value.fromUnsignedBigIntMatrix(${code})`,
244
+ ],
245
+ [
246
+ 'Array<Array<string>>',
247
+ /^string\[([0-9]+)?\]\[([0-9]+)?\]$/,
248
+ (code) => `ethereum.Value.fromStringMatrix(${code})`,
249
+ ],
250
+ [
251
+ 'Array<Array<ethereum.Tuple>>',
252
+ /^tuple\[([0-9]+)?\]\[([0-9]+)?\]$/,
253
+ (code) => `ethereum.Value.fromTupleMatrix(${code})`,
254
+ ],
255
+ ];
256
+ /**
257
+ * Value -> AssemblyScript conversions
258
+ */
259
+ const VALUE_TO_ASSEMBLYSCRIPT = [
260
+ // Arrays
261
+ ['[Bytes]', 'Array<Bytes>', (code) => `${code}.toBytesArray()`],
262
+ ['[Boolean]', 'Array<boolean>', (code) => `${code}.toBooleanArray()`],
263
+ ['[Int]', 'Array<i32>', (code) => `${code}.toI32Array()`],
264
+ ['[BigInt]', 'Array<BigInt>', (code) => `${code}.toBigIntArray()`],
265
+ ['[ID]', 'Array<string>', (code) => `${code}.toStringArray()`],
266
+ ['[String]', 'Array<string>', (code) => `${code}.toStringArray()`],
267
+ ['[BigDecimal]', 'Array<BigDecimal>', (code) => `${code}.toBigDecimalArray()`],
268
+ [/\[.*\]/, 'Array<string>', (code) => `${code}.toStringArray()`],
269
+ // Scalar values
270
+ ['Bytes', 'Bytes', (code) => `${code}.toBytes()`],
271
+ ['Boolean', 'boolean', (code) => `${code}.toBoolean()`],
272
+ ['Int', 'i32', (code) => `${code}.toI32()`],
273
+ ['BigInt', 'BigInt', (code) => `${code}.toBigInt()`],
274
+ ['ID', 'string', (code) => `${code}.toString()`],
275
+ ['String', 'string', (code) => `${code}.toString()`],
276
+ ['BigDecimal', 'BigDecimal', (code) => `${code}.toBigDecimal()`],
277
+ [/.*/, 'string', (code) => `${code}.toString()`],
278
+ ];
279
+ /**
280
+ * AssemblyScript -> Value conversions
281
+ *
282
+ * Note: The order and patterns for conversions in this direction differ slightly
283
+ * from Value -> AssemblyScript, which is why there is a separate table
284
+ * for them.
285
+ */
286
+ const ASSEMBLYSCRIPT_TO_VALUE = [
287
+ // Matrices
288
+ ['Array<Array<Address>>', '[[Bytes]]', (code) => `Value.fromBytesMatrix(${code})`],
289
+ ['Array<Array<Bytes>>', '[[Bytes]]', (code) => `Value.fromBytesMatrix(${code})`],
290
+ [
291
+ 'Array<Array<boolean>>',
292
+ '[[Boolean]]',
293
+ (code) => `Value.fromBooleanMatrix(${code})`,
294
+ ],
295
+ ['Array<Array<i32>>', '[[Int]]', (code) => `Value.fromI32Matrix(${code})`],
296
+ [
297
+ 'Array<Array<BigInt>>',
298
+ '[[BigInt]]',
299
+ (code) => `Value.fromBigIntMatrix(${code})`,
300
+ ],
301
+ [
302
+ 'Array<Array<string>>',
303
+ '[[String]]',
304
+ (code) => `Value.fromStringMatrix(${code})`,
305
+ ],
306
+ ['Array<Array<string>>', '[[ID]]', (code) => `Value.fromStringMatrix(${code})`],
307
+ [
308
+ 'Array<Array<BigDecimal>>',
309
+ '[[BigDecimal]]',
310
+ (code) => `Value.fromBigDecimalMatrix(${code})`,
311
+ ],
312
+ [
313
+ 'Array<Array<string>>',
314
+ /\[\[.*\]\]/,
315
+ (code) => `Value.fromStringMatrix(${code})`,
316
+ ],
317
+ ['Array<Array<string | null>>', null, (code) => `Value.fromStringMatrix(${code})`],
318
+ // Arrays
319
+ ['Array<Address>', '[Bytes]', (code) => `Value.fromBytesArray(${code})`],
320
+ ['Array<Bytes>', '[Bytes]', (code) => `Value.fromBytesArray(${code})`],
321
+ ['Array<boolean>', '[Boolean]', (code) => `Value.fromBooleanArray(${code})`],
322
+ ['Array<i32>', '[Int]', (code) => `Value.fromI32Array(${code})`],
323
+ ['Array<BigInt>', '[BigInt]', (code) => `Value.fromBigIntArray(${code})`],
324
+ ['Array<string>', '[String]', (code) => `Value.fromStringArray(${code})`],
325
+ ['Array<string>', '[ID]', (code) => `Value.fromStringArray(${code})`],
326
+ [
327
+ 'Array<BigDecimal>',
328
+ '[BigDecimal]',
329
+ (code) => `Value.fromBigDecimalArray(${code})`,
330
+ ],
331
+ ['Array<string>', /\[.*\]/, (code) => `Value.fromStringArray(${code})`],
332
+ ['Array<string | null>', null, (code) => `Value.fromStringArray(${code})`],
333
+ // Scalar values
334
+ ['Address', 'Bytes', (code) => `Value.fromBytes(${code})`],
335
+ ['Bytes', 'Bytes', (code) => `Value.fromBytes(${code})`],
336
+ ['boolean', 'Boolean', (code) => `Value.fromBoolean(${code})`],
337
+ ['i32', 'Int', (code) => `Value.fromI32(${code})`],
338
+ ['BigInt', 'BigInt', (code) => `Value.fromBigInt(${code})`],
339
+ ['string', 'String', (code) => `Value.fromString(${code})`],
340
+ ['string', 'ID', (code) => `Value.fromString(${code})`],
341
+ ['BigDecimal', 'BigDecimal', (code) => `Value.fromBigDecimal(${code})`],
342
+ ['string', /.*/, (code) => `Value.fromString(${code})`],
343
+ ];
344
+ const CONVERSIONS = {
345
+ ethereum: {
346
+ AssemblyScript: ETHEREUM_VALUE_TO_ASSEMBLYSCRIPT,
347
+ },
348
+ AssemblyScript: {
349
+ ethereum: ASSEMBLYSCRIPT_TO_ETHEREUM_VALUE,
350
+ Value: ASSEMBLYSCRIPT_TO_VALUE,
351
+ },
352
+ Value: {
353
+ AssemblyScript: VALUE_TO_ASSEMBLYSCRIPT,
354
+ },
355
+ };
356
+ /**
357
+ * Type conversions
358
+ */
359
+ 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
+ let 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
+ let conversions = conversionsForTypeSystems(fromTypeSystem, toTypeSystem);
32
+ let 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
+ let conversions = conversionsForTypeSystems(fromTypeSystem, toTypeSystem);
43
+ let 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 => 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;