@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.
- package/CHANGELOG.md +7 -0
- package/babel.config.js +3 -0
- package/dist/bin.js +6 -0
- package/dist/cli.js +32 -0
- package/dist/codegen/schema.js +250 -0
- package/dist/codegen/schema.test.js +458 -0
- package/dist/codegen/template.js +65 -0
- package/dist/codegen/types/conversions.js +359 -0
- package/dist/codegen/types/index.js +71 -0
- package/dist/codegen/types/index.test.js +563 -0
- package/dist/codegen/typescript.js +200 -0
- package/dist/codegen/util.js +46 -0
- package/dist/codegen/util.test.js +93 -0
- package/dist/command-helpers/abi.js +78 -0
- package/dist/command-helpers/auth.js +77 -0
- package/dist/command-helpers/compiler.js +66 -0
- package/dist/command-helpers/data-sources.js +29 -0
- package/dist/command-helpers/fs.js +9 -0
- package/dist/command-helpers/gluegun.js +49 -0
- package/dist/command-helpers/ipfs.js +5 -0
- package/dist/command-helpers/jsonrpc.js +29 -0
- package/dist/command-helpers/network.js +93 -0
- package/dist/command-helpers/network.test.js +86 -0
- package/dist/command-helpers/node.js +40 -0
- package/dist/command-helpers/scaffold.js +112 -0
- package/dist/command-helpers/spinner.js +84 -0
- package/dist/command-helpers/studio.js +13 -0
- package/dist/command-helpers/studio.test.js +41 -0
- package/dist/command-helpers/subgraph.js +24 -0
- package/dist/command-helpers/version.js +74 -0
- package/dist/command-helpers/version.test.js +179 -0
- package/dist/commands/add.js +190 -0
- package/dist/commands/auth.js +127 -0
- package/dist/commands/build.js +140 -0
- package/dist/commands/codegen.js +135 -0
- package/dist/commands/create.js +86 -0
- package/dist/commands/deploy.js +334 -0
- package/dist/commands/init.js +788 -0
- package/dist/commands/local.js +387 -0
- package/dist/commands/remove.js +86 -0
- package/dist/commands/test.js +295 -0
- package/dist/compiler/asc.js +83 -0
- package/dist/compiler/index.js +474 -0
- package/dist/debug.js +16 -0
- package/dist/migrations/mapping_api_version_0_0_1.js +78 -0
- package/dist/migrations/mapping_api_version_0_0_2.js +76 -0
- package/dist/migrations/mapping_api_version_0_0_3.js +78 -0
- package/dist/migrations/mapping_api_version_0_0_4.js +80 -0
- package/dist/migrations/mapping_api_version_0_0_5.js +80 -0
- package/dist/migrations/spec_version_0_0_2.js +49 -0
- package/dist/migrations/spec_version_0_0_3.js +54 -0
- package/dist/migrations/util/load-manifest.js +18 -0
- package/dist/migrations/util/versions.js +29 -0
- package/dist/migrations.js +56 -0
- package/dist/protocols/arweave/manifest.graphql +57 -0
- package/dist/protocols/arweave/scaffold/manifest.js +18 -0
- package/dist/protocols/arweave/scaffold/mapping.js +52 -0
- package/dist/protocols/arweave/subgraph.js +23 -0
- package/dist/protocols/cosmos/manifest.graphql +76 -0
- package/dist/protocols/cosmos/scaffold/manifest.js +15 -0
- package/dist/protocols/cosmos/scaffold/mapping.js +38 -0
- package/dist/protocols/cosmos/subgraph.js +25 -0
- package/dist/protocols/ethereum/abi.js +140 -0
- package/dist/protocols/ethereum/codegen/abi.js +451 -0
- package/dist/protocols/ethereum/codegen/abi.test.js +328 -0
- package/dist/protocols/ethereum/codegen/template.js +50 -0
- package/dist/protocols/ethereum/contract.js +20 -0
- package/dist/protocols/ethereum/manifest.graphql +94 -0
- package/dist/protocols/ethereum/scaffold/manifest.js +32 -0
- package/dist/protocols/ethereum/scaffold/mapping.js +65 -0
- package/dist/protocols/ethereum/subgraph.js +171 -0
- package/dist/protocols/ethereum/type-generator.js +125 -0
- package/dist/protocols/index.js +268 -0
- package/dist/protocols/ipfs/codegen/file_template.js +50 -0
- package/dist/protocols/near/contract.js +41 -0
- package/dist/protocols/near/manifest.graphql +64 -0
- package/dist/protocols/near/scaffold/manifest.js +16 -0
- package/dist/protocols/near/scaffold/mapping.js +38 -0
- package/dist/protocols/near/subgraph.js +20 -0
- package/dist/protocols/subgraph.js +2 -0
- package/dist/protocols/substreams/manifest.graphql +45 -0
- package/dist/protocols/substreams/scaffold/manifest.js +12 -0
- package/dist/protocols/substreams/subgraph.js +23 -0
- package/dist/scaffold/cosmos.test.js +83 -0
- package/dist/scaffold/ethereum.test.js +505 -0
- package/dist/scaffold/index.js +128 -0
- package/dist/scaffold/mapping.js +61 -0
- package/dist/scaffold/near.test.js +86 -0
- package/dist/scaffold/schema.js +83 -0
- package/dist/scaffold/tests.js +175 -0
- package/dist/schema.js +54 -0
- package/dist/subgraph.js +249 -0
- package/dist/type-generator.js +224 -0
- package/dist/validation/contract.js +46 -0
- package/dist/validation/index.js +8 -0
- package/dist/validation/manifest.js +271 -0
- package/dist/validation/schema.js +796 -0
- package/dist/validation/schema.test.js +35 -0
- package/dist/watcher.js +79 -0
- package/jest.config.js +1 -1
- package/package.json +16 -9
- package/{bin/graph → src/bin.ts} +2 -1
- package/src/cli.ts +36 -0
- package/src/codegen/schema.js +23 -22
- package/src/codegen/schema.test.js +33 -27
- package/src/codegen/{template.js → template.ts} +8 -6
- package/src/codegen/types/conversions.ts +382 -0
- package/src/codegen/types/index.js +4 -7
- package/src/codegen/types/index.test.js +10 -4
- package/src/codegen/{typescript.js → typescript.ts} +44 -26
- package/src/codegen/util.js +1 -1
- package/src/codegen/util.test.js +5 -2
- package/src/command-helpers/abi.js +46 -30
- package/src/command-helpers/auth.js +6 -9
- package/src/command-helpers/compiler.js +4 -6
- package/src/command-helpers/data-sources.js +8 -11
- package/src/command-helpers/fs.ts +5 -0
- package/src/command-helpers/gluegun.js +2 -4
- package/src/command-helpers/ipfs.ts +3 -0
- package/src/command-helpers/{jsonrpc.js → jsonrpc.ts} +11 -16
- package/src/command-helpers/network.js +58 -44
- package/src/command-helpers/network.test.js +23 -19
- package/src/command-helpers/node.js +3 -7
- package/src/command-helpers/scaffold.js +34 -25
- package/src/command-helpers/{spinner.js → spinner.ts} +10 -10
- package/src/command-helpers/studio.test.js +61 -30
- package/src/command-helpers/studio.ts +20 -0
- package/src/command-helpers/{subgraph.js → subgraph.ts} +6 -6
- package/src/command-helpers/version.js +11 -16
- package/src/command-helpers/version.test.js +111 -82
- package/src/commands/add.js +49 -35
- package/src/commands/auth.js +13 -25
- package/src/commands/build.js +9 -9
- package/src/commands/codegen.js +12 -12
- package/src/commands/create.js +22 -22
- package/src/commands/deploy.js +39 -34
- package/src/commands/init.js +21 -24
- package/src/commands/local.js +15 -14
- package/src/commands/remove.js +22 -22
- package/src/commands/test.js +86 -70
- package/src/compiler/{asc.js → asc.ts} +29 -16
- package/src/compiler/index.js +18 -18
- package/src/{debug.js → debug.ts} +2 -2
- package/src/migrations/mapping_api_version_0_0_1.js +7 -7
- package/src/migrations/mapping_api_version_0_0_2.js +5 -5
- package/src/migrations/mapping_api_version_0_0_3.js +7 -7
- package/src/migrations/mapping_api_version_0_0_4.js +7 -7
- package/src/migrations/mapping_api_version_0_0_5.js +7 -7
- package/src/migrations/spec_version_0_0_2.js +5 -5
- package/src/migrations/spec_version_0_0_3.js +5 -5
- package/src/migrations/util/load-manifest.js +6 -9
- package/src/migrations/util/versions.js +5 -10
- package/src/{migrations.js → migrations.ts} +14 -15
- package/src/protocols/arweave/scaffold/manifest.js +1 -4
- package/src/protocols/arweave/scaffold/mapping.js +1 -3
- package/src/protocols/arweave/subgraph.ts +22 -0
- package/src/protocols/cosmos/scaffold/manifest.js +1 -4
- package/src/protocols/cosmos/scaffold/mapping.js +1 -3
- package/src/protocols/cosmos/subgraph.js +2 -2
- package/src/protocols/ethereum/abi.js +7 -13
- package/src/protocols/ethereum/codegen/abi.js +219 -222
- package/src/protocols/ethereum/codegen/abi.test.js +6 -6
- package/src/protocols/ethereum/codegen/template.js +3 -5
- package/src/protocols/ethereum/contract.js +3 -2
- package/src/protocols/ethereum/scaffold/manifest.js +4 -7
- package/src/protocols/ethereum/scaffold/mapping.js +4 -11
- package/src/protocols/ethereum/subgraph.js +21 -20
- package/src/protocols/ethereum/type-generator.js +24 -30
- package/src/protocols/{index.js → index.ts} +65 -46
- package/src/protocols/ipfs/codegen/file_template.js +2 -2
- package/src/protocols/near/{contract.js → contract.ts} +16 -12
- package/src/protocols/near/scaffold/manifest.js +2 -5
- package/src/protocols/near/scaffold/mapping.js +1 -3
- package/src/protocols/near/subgraph.js +3 -6
- package/src/protocols/subgraph.ts +12 -0
- package/src/protocols/substreams/scaffold/{manifest.js → manifest.ts} +2 -7
- package/src/protocols/substreams/subgraph.ts +22 -0
- package/src/scaffold/cosmos.test.js +3 -3
- package/src/scaffold/ethereum.test.js +4 -4
- package/src/scaffold/index.js +7 -7
- package/src/scaffold/mapping.js +3 -3
- package/src/scaffold/near.test.js +3 -3
- package/src/scaffold/schema.js +4 -4
- package/src/scaffold/tests.js +72 -58
- package/src/schema.ts +26 -0
- package/src/{subgraph.js → subgraph.ts} +80 -60
- package/src/type-generator.js +20 -20
- package/src/validation/contract.js +2 -6
- package/src/validation/index.js +1 -1
- package/src/validation/manifest.js +24 -22
- package/src/validation/schema.test.js +1 -1
- package/src/validation/{schema.js → schema.ts} +268 -221
- package/src/{watcher.js → watcher.ts} +23 -12
- package/tests/cli/globalSetup.js +2 -2
- package/tests/cli/globalTeardown.js +2 -2
- package/tests/cli/init.test.js +2 -2
- package/tests/cli/util.js +7 -13
- package/tsconfig.json +18 -0
- package/src/cli.js +0 -38
- package/src/codegen/types/conversions.js +0 -329
- package/src/command-helpers/fs.js +0 -8
- package/src/command-helpers/ipfs.js +0 -6
- package/src/command-helpers/studio.js +0 -15
- package/src/protocols/arweave/subgraph.js +0 -20
- package/src/protocols/substreams/subgraph.js +0 -17
- package/src/schema.js +0 -23
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
import immutable from 'immutable'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* ethereum.Value -> AssemblyScript conversions
|
|
5
|
+
*/
|
|
6
|
+
const ETHEREUM_VALUE_TO_ASSEMBLYSCRIPT = [
|
|
7
|
+
// Scalar values
|
|
8
|
+
|
|
9
|
+
['address', 'Address', (code: any) => `${code}.toAddress()`],
|
|
10
|
+
['bool', 'boolean', (code: any) => `${code}.toBoolean()`],
|
|
11
|
+
['byte', 'Bytes', (code: any) => `${code}.toBytes()`],
|
|
12
|
+
[
|
|
13
|
+
/^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)?$/,
|
|
14
|
+
'Bytes',
|
|
15
|
+
(code: any) => `${code}.toBytes()`,
|
|
16
|
+
],
|
|
17
|
+
[/^int(8|16|24|32)$/, 'i32', (code: any) => `${code}.toI32()`],
|
|
18
|
+
[/^uint(8|16|24)$/, 'i32', (code: any) => `${code}.toI32()`],
|
|
19
|
+
['uint32', 'BigInt', (code: any) => `${code}.toBigInt()`],
|
|
20
|
+
[
|
|
21
|
+
/^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)$/,
|
|
22
|
+
'BigInt',
|
|
23
|
+
(code: any) => `${code}.toBigInt()`,
|
|
24
|
+
],
|
|
25
|
+
['string', 'string', (code: any) => `${code}.toString()`],
|
|
26
|
+
|
|
27
|
+
// Arrays
|
|
28
|
+
|
|
29
|
+
[/^address\[([0-9]+)?\]$/, 'Array<Address>', (code: any) => `${code}.toAddressArray()`],
|
|
30
|
+
[/^bool\[([0-9]+)?\]$/, 'Array<boolean>', (code: any) => `${code}.toBooleanArray()`],
|
|
31
|
+
[/^byte\[([0-9]+)?\]$/, 'Array<Bytes>', (code: any) => `${code}.toBytesArray()`],
|
|
32
|
+
[
|
|
33
|
+
/^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]+)?\]$/,
|
|
34
|
+
'Array<Bytes>',
|
|
35
|
+
(code: any) => `${code}.toBytesArray()`,
|
|
36
|
+
],
|
|
37
|
+
[/^int(8|16|24|32)\[([0-9]+)?\]$/, 'Array<i32>', (code: any) => `${code}.toI32Array()`],
|
|
38
|
+
[/^uint(8|16|24)\[([0-9]+)?\]$/, 'Array<i32>', (code: any) => `${code}.toI32Array()`],
|
|
39
|
+
[/^uint32\[([0-9]+)?\]$/, 'Array<BigInt>', (code: any) => `${code}.toBigIntArray()`],
|
|
40
|
+
[
|
|
41
|
+
/^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]+)?\]$/,
|
|
42
|
+
'Array<BigInt>',
|
|
43
|
+
(code: any) => `${code}.toBigIntArray()`,
|
|
44
|
+
],
|
|
45
|
+
[/^string\[([0-9]+)?\]$/, 'Array<string>', (code: any) => `${code}.toStringArray()`],
|
|
46
|
+
|
|
47
|
+
// Tuples
|
|
48
|
+
|
|
49
|
+
['tuple', 'ethereum.Tuple', (code: any) => `${code}.toTuple()`],
|
|
50
|
+
[
|
|
51
|
+
/^tuple\[([0-9]+)?\]$/,
|
|
52
|
+
'Array<ethereum.Tuple>',
|
|
53
|
+
(code: any, type: any) => `${code}.toTupleArray<${type}>()`,
|
|
54
|
+
],
|
|
55
|
+
|
|
56
|
+
// Multi dimensional arrays
|
|
57
|
+
|
|
58
|
+
[
|
|
59
|
+
/^address\[([0-9]+)?\]\[([0-9]+)?\]$/,
|
|
60
|
+
'Array<Array<Address>>',
|
|
61
|
+
(code: any) => `${code}.toAddressMatrix()`,
|
|
62
|
+
],
|
|
63
|
+
[
|
|
64
|
+
/^bool\[([0-9]+)?\]\[([0-9]+)?\]$/,
|
|
65
|
+
'Array<Array<boolean>>',
|
|
66
|
+
(code: any) => `${code}.toBooleanMatrix()`,
|
|
67
|
+
],
|
|
68
|
+
[
|
|
69
|
+
/^byte\[([0-9]+)?\]\[([0-9]+)?\]$/,
|
|
70
|
+
'Array<Array<Bytes>>',
|
|
71
|
+
(code: any) => `${code}.toBytesMatrix()`,
|
|
72
|
+
],
|
|
73
|
+
[
|
|
74
|
+
/^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]+)?\]$/,
|
|
75
|
+
'Array<Array<Bytes>>',
|
|
76
|
+
(code: any) => `${code}.toBytesMatrix()`,
|
|
77
|
+
],
|
|
78
|
+
[
|
|
79
|
+
/^int(8|16|24|32)\[([0-9]+)?\]\[([0-9]+)?\]$/,
|
|
80
|
+
'Array<Array<i32>>',
|
|
81
|
+
(code: any) => `${code}.toI32Matrix()`,
|
|
82
|
+
],
|
|
83
|
+
[
|
|
84
|
+
/^uint(8|16|24)\[([0-9]+)?\]\[([0-9]+)?\]$/,
|
|
85
|
+
'Array<Array<i32>>',
|
|
86
|
+
(code: any) => `${code}.toI32Matrix()`,
|
|
87
|
+
],
|
|
88
|
+
[
|
|
89
|
+
/^uint32\[([0-9]+)?\]\[([0-9]+)?\]$/,
|
|
90
|
+
'Array<Array<BigInt>>',
|
|
91
|
+
(code: any) => `${code}.toBigIntMatrix()`,
|
|
92
|
+
],
|
|
93
|
+
[
|
|
94
|
+
/^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]+)?\]$/,
|
|
95
|
+
'Array<Array<BigInt>>',
|
|
96
|
+
(code: any) => `${code}.toBigIntMatrix()`,
|
|
97
|
+
],
|
|
98
|
+
[
|
|
99
|
+
/^string\[([0-9]+)?\]\[([0-9]+)?\]$/,
|
|
100
|
+
'Array<Array<string>>',
|
|
101
|
+
(code: any) => `${code}.toStringMatrix()`,
|
|
102
|
+
],
|
|
103
|
+
[
|
|
104
|
+
/^tuple\[([0-9]+)?\]\[([0-9]+)?\]$/,
|
|
105
|
+
'Array<Array<ethereum.Tuple>>',
|
|
106
|
+
(code: any, type: any) => `${code}.toTupleMatrix<${type}>()`,
|
|
107
|
+
],
|
|
108
|
+
]
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* AssemblyScript -> ethereum.Value conversions
|
|
112
|
+
*
|
|
113
|
+
* Note: The order and patterns for conversions in this direction differ slightly
|
|
114
|
+
* from ethereum.Value -> AssemblyScript, which is why there is a separate table
|
|
115
|
+
* for them.
|
|
116
|
+
*/
|
|
117
|
+
const ASSEMBLYSCRIPT_TO_ETHEREUM_VALUE = [
|
|
118
|
+
// Scalar values
|
|
119
|
+
|
|
120
|
+
['Address', 'address', (code: any) => `ethereum.Value.fromAddress(${code})`],
|
|
121
|
+
['boolean', 'bool', (code: any) => `ethereum.Value.fromBoolean(${code})`],
|
|
122
|
+
['Bytes', 'byte', (code: any) => `ethereum.Value.fromFixedBytes(${code})`],
|
|
123
|
+
['Bytes', 'bytes', (code: any) => `ethereum.Value.fromBytes(${code})`],
|
|
124
|
+
[
|
|
125
|
+
'Bytes',
|
|
126
|
+
/^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)$/,
|
|
127
|
+
(code: any) => `ethereum.Value.fromFixedBytes(${code})`,
|
|
128
|
+
],
|
|
129
|
+
['i32', /^int(8|16|24|32)$/, (code: any) => `ethereum.Value.fromI32(${code})`],
|
|
130
|
+
[
|
|
131
|
+
'i32',
|
|
132
|
+
/^uint(8|16|24)$/,
|
|
133
|
+
(code: any) => `ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(${code}))`,
|
|
134
|
+
],
|
|
135
|
+
[
|
|
136
|
+
'BigInt',
|
|
137
|
+
/^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)$/,
|
|
138
|
+
(code: any) => `ethereum.Value.fromSignedBigInt(${code})`,
|
|
139
|
+
],
|
|
140
|
+
[
|
|
141
|
+
'BigInt',
|
|
142
|
+
/^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)$/,
|
|
143
|
+
(code: any) => `ethereum.Value.fromUnsignedBigInt(${code})`,
|
|
144
|
+
],
|
|
145
|
+
['string', 'string', (code: any) => `ethereum.Value.fromString(${code})`],
|
|
146
|
+
|
|
147
|
+
// Arrays
|
|
148
|
+
|
|
149
|
+
[
|
|
150
|
+
'Array<Address>',
|
|
151
|
+
/^address\[([0-9]+)?\]$/,
|
|
152
|
+
(code: any) => `ethereum.Value.fromAddressArray(${code})`,
|
|
153
|
+
],
|
|
154
|
+
[
|
|
155
|
+
'Array<boolean>',
|
|
156
|
+
/^bool\[([0-9]+)?\]$/,
|
|
157
|
+
(code: any) => `ethereum.Value.fromBooleanArray(${code})`,
|
|
158
|
+
],
|
|
159
|
+
[
|
|
160
|
+
'Array<Bytes>',
|
|
161
|
+
/^byte\[([0-9]+)?\]$/,
|
|
162
|
+
(code: any) => `ethereum.Value.fromFixedBytesArray(${code})`,
|
|
163
|
+
],
|
|
164
|
+
[
|
|
165
|
+
'Array<Bytes>',
|
|
166
|
+
/bytes\[([0-9]+)?\]$/,
|
|
167
|
+
(code: any) => `ethereum.Value.fromBytesArray(${code})`,
|
|
168
|
+
],
|
|
169
|
+
[
|
|
170
|
+
'Array<Bytes>',
|
|
171
|
+
/^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]+)?\]$/,
|
|
172
|
+
(code: any) => `ethereum.Value.fromFixedBytesArray(${code})`,
|
|
173
|
+
],
|
|
174
|
+
[
|
|
175
|
+
'Array<i32>',
|
|
176
|
+
/^int(8|16|24|32)\[([0-9]+)?\]$/,
|
|
177
|
+
(code: any) => `ethereum.Value.fromI32Array(${code})`,
|
|
178
|
+
],
|
|
179
|
+
[
|
|
180
|
+
'Array<i32>',
|
|
181
|
+
/^uint(8|16|24)\[([0-9]+)?\]$/,
|
|
182
|
+
(code: any) => `ethereum.Value.fromI32Array(${code})`,
|
|
183
|
+
],
|
|
184
|
+
[
|
|
185
|
+
'Array<BigInt>',
|
|
186
|
+
/^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]+)?\]$/,
|
|
187
|
+
(code: any) => `ethereum.Value.fromSignedBigIntArray(${code})`,
|
|
188
|
+
],
|
|
189
|
+
[
|
|
190
|
+
'Array<BigInt>',
|
|
191
|
+
/^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]+)?\]$/,
|
|
192
|
+
(code: any) => `ethereum.Value.fromUnsignedBigIntArray(${code})`,
|
|
193
|
+
],
|
|
194
|
+
[
|
|
195
|
+
'Array<string>',
|
|
196
|
+
/^string\[([0-9]+)?\]$/,
|
|
197
|
+
(code: any) => `ethereum.Value.fromStringArray(${code})`,
|
|
198
|
+
],
|
|
199
|
+
|
|
200
|
+
// Tuples
|
|
201
|
+
|
|
202
|
+
['ethereum.Tuple', 'tuple', (code: any) => `ethereum.Value.fromTuple(${code})`],
|
|
203
|
+
[
|
|
204
|
+
'Array<ethereum.Tuple>',
|
|
205
|
+
/^tuple\[([0-9]+)?\]$/,
|
|
206
|
+
(code: any) => `ethereum.Value.fromTupleArray(${code})`,
|
|
207
|
+
],
|
|
208
|
+
|
|
209
|
+
// Multi dimentional arrays
|
|
210
|
+
|
|
211
|
+
[
|
|
212
|
+
'Array<Array<Address>>',
|
|
213
|
+
/^address\[([0-9]+)?\]\[([0-9]+)?\]$/,
|
|
214
|
+
(code: any) => `ethereum.Value.fromAddressMatrix(${code})`,
|
|
215
|
+
],
|
|
216
|
+
[
|
|
217
|
+
'Array<Array<boolean>>',
|
|
218
|
+
/^bool\[([0-9]+)?\]\[([0-9]+)?\]$/,
|
|
219
|
+
(code: any) => `ethereum.Value.fromBooleanMatrix(${code})`,
|
|
220
|
+
],
|
|
221
|
+
[
|
|
222
|
+
'Array<Array<Bytes>>',
|
|
223
|
+
/^byte\[([0-9]+)?\]\[([0-9]+)?\]$/,
|
|
224
|
+
(code: any) => `ethereum.Value.fromFixedBytesMatrix(${code})`,
|
|
225
|
+
],
|
|
226
|
+
[
|
|
227
|
+
'Array<Array<Bytes>>',
|
|
228
|
+
/bytes\[([0-9]+)?\]\[([0-9]+)?\]$/,
|
|
229
|
+
(code: any) => `ethereum.Value.fromBytesMatrix(${code})`,
|
|
230
|
+
],
|
|
231
|
+
[
|
|
232
|
+
'Array<Array<Bytes>>',
|
|
233
|
+
/^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]+)?\]$/,
|
|
234
|
+
(code: any) => `ethereum.Value.fromFixedBytesMatrix(${code})`,
|
|
235
|
+
],
|
|
236
|
+
[
|
|
237
|
+
'Array<Array<i32>>',
|
|
238
|
+
/^int(8|16|24|32)\[([0-9]+)?\]\[([0-9]+)?\]$/,
|
|
239
|
+
(code: any) => `ethereum.Value.fromI32Matrix(${code})`,
|
|
240
|
+
],
|
|
241
|
+
[
|
|
242
|
+
'Array<Array<i32>>',
|
|
243
|
+
/^uint(8|16|24)\[([0-9]+)?\]\[([0-9]+)?\]$/,
|
|
244
|
+
(code: any) => `ethereum.Value.fromI32Matrix(${code})`,
|
|
245
|
+
],
|
|
246
|
+
[
|
|
247
|
+
'Array<Array<BigInt>>',
|
|
248
|
+
/^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]+)?\]$/,
|
|
249
|
+
(code: any) => `ethereum.Value.fromSignedBigIntMatrix(${code})`,
|
|
250
|
+
],
|
|
251
|
+
[
|
|
252
|
+
'Array<Array<BigInt>>',
|
|
253
|
+
/^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]+)?\]$/,
|
|
254
|
+
(code: any) => `ethereum.Value.fromUnsignedBigIntMatrix(${code})`,
|
|
255
|
+
],
|
|
256
|
+
[
|
|
257
|
+
'Array<Array<string>>',
|
|
258
|
+
/^string\[([0-9]+)?\]\[([0-9]+)?\]$/,
|
|
259
|
+
(code: any) => `ethereum.Value.fromStringMatrix(${code})`,
|
|
260
|
+
],
|
|
261
|
+
[
|
|
262
|
+
'Array<Array<ethereum.Tuple>>',
|
|
263
|
+
/^tuple\[([0-9]+)?\]\[([0-9]+)?\]$/,
|
|
264
|
+
(code: any) => `ethereum.Value.fromTupleMatrix(${code})`,
|
|
265
|
+
],
|
|
266
|
+
]
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Value -> AssemblyScript conversions
|
|
270
|
+
*/
|
|
271
|
+
const VALUE_TO_ASSEMBLYSCRIPT = [
|
|
272
|
+
// Arrays
|
|
273
|
+
|
|
274
|
+
['[Bytes]', 'Array<Bytes>', (code: any) => `${code}.toBytesArray()`],
|
|
275
|
+
['[Boolean]', 'Array<boolean>', (code: any) => `${code}.toBooleanArray()`],
|
|
276
|
+
['[Int]', 'Array<i32>', (code: any) => `${code}.toI32Array()`],
|
|
277
|
+
['[BigInt]', 'Array<BigInt>', (code: any) => `${code}.toBigIntArray()`],
|
|
278
|
+
['[ID]', 'Array<string>', (code: any) => `${code}.toStringArray()`],
|
|
279
|
+
['[String]', 'Array<string>', (code: any) => `${code}.toStringArray()`],
|
|
280
|
+
['[BigDecimal]', 'Array<BigDecimal>', (code: any) => `${code}.toBigDecimalArray()`],
|
|
281
|
+
[/\[.*\]/, 'Array<string>', (code: any) => `${code}.toStringArray()`],
|
|
282
|
+
|
|
283
|
+
// Scalar values
|
|
284
|
+
|
|
285
|
+
['Bytes', 'Bytes', (code: any) => `${code}.toBytes()`],
|
|
286
|
+
['Boolean', 'boolean', (code: any) => `${code}.toBoolean()`],
|
|
287
|
+
['Int', 'i32', (code: any) => `${code}.toI32()`],
|
|
288
|
+
['BigInt', 'BigInt', (code: any) => `${code}.toBigInt()`],
|
|
289
|
+
['ID', 'string', (code: any) => `${code}.toString()`],
|
|
290
|
+
['String', 'string', (code: any) => `${code}.toString()`],
|
|
291
|
+
['BigDecimal', 'BigDecimal', (code: any) => `${code}.toBigDecimal()`],
|
|
292
|
+
[/.*/, 'string', (code: any) => `${code}.toString()`],
|
|
293
|
+
]
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* AssemblyScript -> Value conversions
|
|
297
|
+
*
|
|
298
|
+
* Note: The order and patterns for conversions in this direction differ slightly
|
|
299
|
+
* from Value -> AssemblyScript, which is why there is a separate table
|
|
300
|
+
* for them.
|
|
301
|
+
*/
|
|
302
|
+
const ASSEMBLYSCRIPT_TO_VALUE = [
|
|
303
|
+
// Matrices
|
|
304
|
+
|
|
305
|
+
['Array<Array<Address>>', '[[Bytes]]', (code: any) => `Value.fromBytesMatrix(${code})`],
|
|
306
|
+
['Array<Array<Bytes>>', '[[Bytes]]', (code: any) => `Value.fromBytesMatrix(${code})`],
|
|
307
|
+
[
|
|
308
|
+
'Array<Array<boolean>>',
|
|
309
|
+
'[[Boolean]]',
|
|
310
|
+
(code: any) => `Value.fromBooleanMatrix(${code})`,
|
|
311
|
+
],
|
|
312
|
+
['Array<Array<i32>>', '[[Int]]', (code: any) => `Value.fromI32Matrix(${code})`],
|
|
313
|
+
[
|
|
314
|
+
'Array<Array<BigInt>>',
|
|
315
|
+
'[[BigInt]]',
|
|
316
|
+
(code: any) => `Value.fromBigIntMatrix(${code})`,
|
|
317
|
+
],
|
|
318
|
+
[
|
|
319
|
+
'Array<Array<string>>',
|
|
320
|
+
'[[String]]',
|
|
321
|
+
(code: any) => `Value.fromStringMatrix(${code})`,
|
|
322
|
+
],
|
|
323
|
+
['Array<Array<string>>', '[[ID]]', (code: any) => `Value.fromStringMatrix(${code})`],
|
|
324
|
+
[
|
|
325
|
+
'Array<Array<BigDecimal>>',
|
|
326
|
+
'[[BigDecimal]]',
|
|
327
|
+
(code: any) => `Value.fromBigDecimalMatrix(${code})`,
|
|
328
|
+
],
|
|
329
|
+
[
|
|
330
|
+
'Array<Array<string>>',
|
|
331
|
+
/\[\[.*\]\]/,
|
|
332
|
+
(code: any) => `Value.fromStringMatrix(${code})`,
|
|
333
|
+
],
|
|
334
|
+
['Array<Array<string | null>>', null, (code: any) => `Value.fromStringMatrix(${code})`], // is this overwriting the Array null below?
|
|
335
|
+
|
|
336
|
+
// Arrays
|
|
337
|
+
|
|
338
|
+
['Array<Address>', '[Bytes]', (code: any) => `Value.fromBytesArray(${code})`],
|
|
339
|
+
['Array<Bytes>', '[Bytes]', (code: any) => `Value.fromBytesArray(${code})`],
|
|
340
|
+
['Array<boolean>', '[Boolean]', (code: any) => `Value.fromBooleanArray(${code})`],
|
|
341
|
+
['Array<i32>', '[Int]', (code: any) => `Value.fromI32Array(${code})`],
|
|
342
|
+
['Array<BigInt>', '[BigInt]', (code: any) => `Value.fromBigIntArray(${code})`],
|
|
343
|
+
['Array<string>', '[String]', (code: any) => `Value.fromStringArray(${code})`],
|
|
344
|
+
['Array<string>', '[ID]', (code: any) => `Value.fromStringArray(${code})`],
|
|
345
|
+
[
|
|
346
|
+
'Array<BigDecimal>',
|
|
347
|
+
'[BigDecimal]',
|
|
348
|
+
(code: any) => `Value.fromBigDecimalArray(${code})`,
|
|
349
|
+
],
|
|
350
|
+
['Array<string>', /\[.*\]/, (code: any) => `Value.fromStringArray(${code})`],
|
|
351
|
+
['Array<string | null>', null, (code: any) => `Value.fromStringArray(${code})`],
|
|
352
|
+
|
|
353
|
+
// Scalar values
|
|
354
|
+
|
|
355
|
+
['Address', 'Bytes', (code: any) => `Value.fromBytes(${code})`],
|
|
356
|
+
['Bytes', 'Bytes', (code: any) => `Value.fromBytes(${code})`],
|
|
357
|
+
['boolean', 'Boolean', (code: any) => `Value.fromBoolean(${code})`],
|
|
358
|
+
['i32', 'Int', (code: any) => `Value.fromI32(${code})`],
|
|
359
|
+
['BigInt', 'BigInt', (code: any) => `Value.fromBigInt(${code})`],
|
|
360
|
+
['string', 'String', (code: any) => `Value.fromString(${code})`],
|
|
361
|
+
['string', 'ID', (code: any) => `Value.fromString(${code})`],
|
|
362
|
+
['BigDecimal', 'BigDecimal', (code: any) => `Value.fromBigDecimal(${code})`],
|
|
363
|
+
['string', /.*/, (code: any) => `Value.fromString(${code})`],
|
|
364
|
+
]
|
|
365
|
+
|
|
366
|
+
const CONVERSIONS = {
|
|
367
|
+
ethereum: {
|
|
368
|
+
AssemblyScript: ETHEREUM_VALUE_TO_ASSEMBLYSCRIPT,
|
|
369
|
+
},
|
|
370
|
+
AssemblyScript: {
|
|
371
|
+
ethereum: ASSEMBLYSCRIPT_TO_ETHEREUM_VALUE,
|
|
372
|
+
Value: ASSEMBLYSCRIPT_TO_VALUE,
|
|
373
|
+
},
|
|
374
|
+
Value: {
|
|
375
|
+
AssemblyScript: VALUE_TO_ASSEMBLYSCRIPT,
|
|
376
|
+
},
|
|
377
|
+
} as const
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Type conversions
|
|
381
|
+
*/
|
|
382
|
+
export default immutable.fromJS(CONVERSIONS)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import immutable from 'immutable'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import TYPE_CONVERSIONS from './conversions'
|
|
4
4
|
|
|
5
5
|
// Conversion utilities
|
|
6
6
|
|
|
@@ -72,8 +72,7 @@ const ascTypeForProtocol = (protocol, protocolType) =>
|
|
|
72
72
|
findConversionFromType(protocol, 'AssemblyScript', protocolType).getIn(['to', 'type'])
|
|
73
73
|
|
|
74
74
|
// TODO: this can be removed/replaced by the function above
|
|
75
|
-
const ascTypeForEthereum = ethereumType =>
|
|
76
|
-
ascTypeForProtocol('ethereum', ethereumType)
|
|
75
|
+
const ascTypeForEthereum = ethereumType => ascTypeForProtocol('ethereum', ethereumType)
|
|
77
76
|
|
|
78
77
|
const ethereumTypeForAsc = ascType =>
|
|
79
78
|
findConversionFromType('AssemblyScript', 'ethereum', ascType).getIn(['to', 'type'])
|
|
@@ -99,16 +98,14 @@ const valueToAsc = (code, valueType) =>
|
|
|
99
98
|
const valueFromAsc = (code, valueType) =>
|
|
100
99
|
findConversionToType('AssemblyScript', 'Value', valueType).get('convert')(code)
|
|
101
100
|
|
|
102
|
-
|
|
101
|
+
export {
|
|
103
102
|
// protocol <-> AssemblyScript
|
|
104
103
|
ascTypeForProtocol,
|
|
105
|
-
|
|
106
104
|
// ethereum <-> AssemblyScript
|
|
107
105
|
ascTypeForEthereum,
|
|
108
106
|
ethereumTypeForAsc,
|
|
109
107
|
ethereumToAsc,
|
|
110
108
|
ethereumFromAsc,
|
|
111
|
-
|
|
112
109
|
// Value <-> AssemblyScript
|
|
113
110
|
ascTypeForValue,
|
|
114
111
|
valueTypeForAsc,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import * as codegen from '.'
|
|
2
2
|
|
|
3
3
|
describe('ethereum.Value -> AssemblyScript', () => {
|
|
4
4
|
// Scalar values
|
|
@@ -268,7 +268,9 @@ describe('ethereum.Value -> AssemblyScript', () => {
|
|
|
268
268
|
expect(codegen.ascTypeForEthereum(`bytes${i}[][]`)).toBe('Array<Array<Bytes>>')
|
|
269
269
|
expect(codegen.ascTypeForEthereum(`bytes${i}[6][]`)).toBe('Array<Array<Bytes>>')
|
|
270
270
|
expect(codegen.ascTypeForEthereum(`bytes${i}[][7]`)).toBe('Array<Array<Bytes>>')
|
|
271
|
-
expect(codegen.ascTypeForEthereum(`bytes${i}[432][234]`)).toBe(
|
|
271
|
+
expect(codegen.ascTypeForEthereum(`bytes${i}[432][234]`)).toBe(
|
|
272
|
+
'Array<Array<Bytes>>',
|
|
273
|
+
)
|
|
272
274
|
}
|
|
273
275
|
})
|
|
274
276
|
|
|
@@ -331,7 +333,9 @@ describe('ethereum.Value -> AssemblyScript', () => {
|
|
|
331
333
|
expect(codegen.ascTypeForEthereum(`int${i}[][]`)).toBe('Array<Array<BigInt>>')
|
|
332
334
|
expect(codegen.ascTypeForEthereum(`int${i}[7][]`)).toBe('Array<Array<BigInt>>')
|
|
333
335
|
expect(codegen.ascTypeForEthereum(`int${i}[][7]`)).toBe('Array<Array<BigInt>>')
|
|
334
|
-
expect(codegen.ascTypeForEthereum(`int${i}[6833][3386]`)).toBe(
|
|
336
|
+
expect(codegen.ascTypeForEthereum(`int${i}[6833][3386]`)).toBe(
|
|
337
|
+
'Array<Array<BigInt>>',
|
|
338
|
+
)
|
|
335
339
|
|
|
336
340
|
expect(codegen.ethereumToAsc('x', `uint${i}[][]`)).toBe('x.toBigIntMatrix()')
|
|
337
341
|
expect(codegen.ethereumToAsc('x', `uint${i}[23][]`)).toBe('x.toBigIntMatrix()')
|
|
@@ -341,7 +345,9 @@ describe('ethereum.Value -> AssemblyScript', () => {
|
|
|
341
345
|
expect(codegen.ascTypeForEthereum(`uint${i}[][]`)).toBe('Array<Array<BigInt>>')
|
|
342
346
|
expect(codegen.ascTypeForEthereum(`uint${i}[23][]`)).toBe('Array<Array<BigInt>>')
|
|
343
347
|
expect(codegen.ascTypeForEthereum(`uint${i}[][32]`)).toBe('Array<Array<BigInt>>')
|
|
344
|
-
expect(codegen.ascTypeForEthereum(`uint${i}[467][764]`)).toBe(
|
|
348
|
+
expect(codegen.ascTypeForEthereum(`uint${i}[467][764]`)).toBe(
|
|
349
|
+
'Array<Array<BigInt>>',
|
|
350
|
+
)
|
|
345
351
|
}
|
|
346
352
|
})
|
|
347
353
|
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
let immutable = require('immutable')
|
|
2
|
-
let Map = immutable.Map
|
|
3
|
-
|
|
4
1
|
class Param {
|
|
5
|
-
constructor(name, type) {
|
|
2
|
+
constructor(public name: string, public type: string) {
|
|
6
3
|
this.name = name
|
|
7
4
|
this.type = type
|
|
8
5
|
}
|
|
@@ -13,7 +10,12 @@ class Param {
|
|
|
13
10
|
}
|
|
14
11
|
|
|
15
12
|
class Method {
|
|
16
|
-
constructor(
|
|
13
|
+
constructor(
|
|
14
|
+
public name: string,
|
|
15
|
+
public params: string[],
|
|
16
|
+
public returnType: string,
|
|
17
|
+
public body: string,
|
|
18
|
+
) {
|
|
17
19
|
this.name = name
|
|
18
20
|
this.params = params || []
|
|
19
21
|
this.returnType = returnType
|
|
@@ -31,7 +33,12 @@ class Method {
|
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
class StaticMethod {
|
|
34
|
-
constructor(
|
|
36
|
+
constructor(
|
|
37
|
+
public name: string,
|
|
38
|
+
public params: string[],
|
|
39
|
+
public returnType: string,
|
|
40
|
+
public body: string,
|
|
41
|
+
) {
|
|
35
42
|
this.name = name
|
|
36
43
|
this.params = params || []
|
|
37
44
|
this.returnType = returnType || 'void'
|
|
@@ -48,8 +55,18 @@ class StaticMethod {
|
|
|
48
55
|
}
|
|
49
56
|
}
|
|
50
57
|
|
|
58
|
+
interface ClassOptions {
|
|
59
|
+
extends?: string
|
|
60
|
+
export?: boolean
|
|
61
|
+
}
|
|
62
|
+
|
|
51
63
|
class Class {
|
|
52
|
-
|
|
64
|
+
public extends: string | undefined
|
|
65
|
+
public methods: string[]
|
|
66
|
+
public members: any[]
|
|
67
|
+
public export: boolean
|
|
68
|
+
|
|
69
|
+
constructor(public name: string, options: ClassOptions) {
|
|
53
70
|
this.name = name
|
|
54
71
|
this.extends = options.extends
|
|
55
72
|
this.methods = []
|
|
@@ -57,11 +74,11 @@ class Class {
|
|
|
57
74
|
this.export = options.export || false
|
|
58
75
|
}
|
|
59
76
|
|
|
60
|
-
addMember(member) {
|
|
77
|
+
addMember(member: any) {
|
|
61
78
|
this.members.push(member)
|
|
62
79
|
}
|
|
63
80
|
|
|
64
|
-
addMethod(method) {
|
|
81
|
+
addMethod(method: any) {
|
|
65
82
|
this.methods.push(method)
|
|
66
83
|
}
|
|
67
84
|
|
|
@@ -78,7 +95,7 @@ ${this.methods.map(method => method.toString()).join('')}
|
|
|
78
95
|
}
|
|
79
96
|
|
|
80
97
|
class ClassMember {
|
|
81
|
-
constructor(name, type) {
|
|
98
|
+
constructor(public name: string, public type: string) {
|
|
82
99
|
this.name = name
|
|
83
100
|
this.type = type
|
|
84
101
|
}
|
|
@@ -89,7 +106,7 @@ class ClassMember {
|
|
|
89
106
|
}
|
|
90
107
|
|
|
91
108
|
class NamedType {
|
|
92
|
-
constructor(name) {
|
|
109
|
+
constructor(public name: string) {
|
|
93
110
|
this.name = name
|
|
94
111
|
}
|
|
95
112
|
|
|
@@ -123,7 +140,9 @@ class NamedType {
|
|
|
123
140
|
}
|
|
124
141
|
|
|
125
142
|
class ArrayType {
|
|
126
|
-
|
|
143
|
+
public name: string
|
|
144
|
+
|
|
145
|
+
constructor(public inner: string) {
|
|
127
146
|
this.inner = inner
|
|
128
147
|
this.name = `Array<${inner.toString()}>`
|
|
129
148
|
}
|
|
@@ -134,7 +153,7 @@ class ArrayType {
|
|
|
134
153
|
}
|
|
135
154
|
|
|
136
155
|
class NullableType {
|
|
137
|
-
constructor(inner) {
|
|
156
|
+
constructor(public inner: string) {
|
|
138
157
|
this.inner = inner
|
|
139
158
|
}
|
|
140
159
|
|
|
@@ -144,7 +163,7 @@ class NullableType {
|
|
|
144
163
|
}
|
|
145
164
|
|
|
146
165
|
class ModuleImports {
|
|
147
|
-
constructor(nameOrNames, module) {
|
|
166
|
+
constructor(public nameOrNames: string | string[], public module: string) {
|
|
148
167
|
this.nameOrNames = nameOrNames
|
|
149
168
|
this.module = module
|
|
150
169
|
}
|
|
@@ -156,23 +175,24 @@ class ModuleImports {
|
|
|
156
175
|
}
|
|
157
176
|
}
|
|
158
177
|
|
|
159
|
-
const namedType = name => new NamedType(name)
|
|
160
|
-
const arrayType = name => new ArrayType(name)
|
|
161
|
-
const param = (name, type) => new Param(name, type)
|
|
162
|
-
const method = (name, params, returnType, body) =>
|
|
178
|
+
const namedType = (name: string) => new NamedType(name)
|
|
179
|
+
const arrayType = (name: string) => new ArrayType(name)
|
|
180
|
+
const param = (name: string, type: string) => new Param(name, type)
|
|
181
|
+
const method = (name: string, params: string[], returnType: string, body: string) =>
|
|
163
182
|
new Method(name, params, returnType, body)
|
|
164
|
-
const staticMethod = (name, params, returnType, body) =>
|
|
183
|
+
const staticMethod = (name: string, params: string[], returnType: string, body: string) =>
|
|
165
184
|
new StaticMethod(name, params, returnType, body)
|
|
166
|
-
const klass = (name, options) => new Class(name, options)
|
|
167
|
-
const klassMember = (name, type) => new ClassMember(name, type)
|
|
168
|
-
const nullableType = type => new NullableType(type)
|
|
169
|
-
const moduleImports = (nameOrNames
|
|
185
|
+
const klass = (name: string, options: ClassOptions) => new Class(name, options)
|
|
186
|
+
const klassMember = (name: string, type: string) => new ClassMember(name, type)
|
|
187
|
+
const nullableType = (type: string) => new NullableType(type)
|
|
188
|
+
const moduleImports = (nameOrNames: string | string[], module: string) =>
|
|
189
|
+
new ModuleImports(nameOrNames, module)
|
|
170
190
|
|
|
171
191
|
const GENERATED_FILE_NOTE = `
|
|
172
192
|
// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
|
173
193
|
`
|
|
174
194
|
|
|
175
|
-
|
|
195
|
+
export {
|
|
176
196
|
// Types
|
|
177
197
|
Param,
|
|
178
198
|
Method,
|
|
@@ -183,7 +203,6 @@ module.exports = {
|
|
|
183
203
|
NullableType,
|
|
184
204
|
ArrayType,
|
|
185
205
|
ModuleImports,
|
|
186
|
-
|
|
187
206
|
// Code generators
|
|
188
207
|
namedType,
|
|
189
208
|
arrayType,
|
|
@@ -194,7 +213,6 @@ module.exports = {
|
|
|
194
213
|
param,
|
|
195
214
|
nullableType,
|
|
196
215
|
moduleImports,
|
|
197
|
-
|
|
198
216
|
// Utilities
|
|
199
217
|
GENERATED_FILE_NOTE,
|
|
200
218
|
}
|
package/src/codegen/util.js
CHANGED
package/src/codegen/util.test.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { disambiguateNames, unrollTuple } from './util'
|
|
2
2
|
|
|
3
3
|
describe('Codegen utilities', () => {
|
|
4
4
|
test('Name disambiguation', () => {
|
|
@@ -64,7 +64,10 @@ describe('Codegen utilities', () => {
|
|
|
64
64
|
value: {
|
|
65
65
|
type: 'tuple',
|
|
66
66
|
name: 'value',
|
|
67
|
-
components: [
|
|
67
|
+
components: [
|
|
68
|
+
{ name: 'a', type: 'string' },
|
|
69
|
+
{ name: 'b', type: 'uint256' },
|
|
70
|
+
],
|
|
68
71
|
},
|
|
69
72
|
path: ['value'],
|
|
70
73
|
index: 0,
|