@latticexyz/cli 2.0.0-alpha.41 → 2.0.0-alpha.43
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/dist/chunk-5NC2OON2.js +164 -0
- package/dist/chunk-7GA2K5A6.js +283 -0
- package/dist/{chunk-J4DJQNIC.js → chunk-KPBNUPK6.js} +3 -438
- package/dist/chunk-LPWKZQUI.js +454 -0
- package/dist/chunk-MXDV47JM.js +710 -0
- package/dist/{chunk-X57YP77L.js → chunk-SLIMIO4Z.js} +18 -28
- package/dist/{chunk-O57QENJ6.js → chunk-UU3AZIV2.js} +1293 -1424
- package/dist/config/index.d.ts +12 -367
- package/dist/config/index.js +14 -12
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -1
- package/dist/mud.js +274 -748
- package/dist/parseStoreConfig-899f574e.d.ts +369 -0
- package/dist/render-solidity/index.d.ts +171 -0
- package/dist/render-solidity/index.js +50 -0
- package/dist/render-ts/index.d.ts +27 -0
- package/dist/render-ts/index.js +15 -0
- package/dist/utils/deprecated/index.js +1 -1
- package/dist/utils/index.d.ts +6 -1
- package/dist/utils/index.js +13 -4
- package/package.json +11 -9
- package/src/commands/index.ts +4 -0
- package/src/commands/set-version.ts +171 -0
- package/src/commands/tsgen.ts +33 -0
- package/src/config/world/parseWorldConfig.ts +1 -0
- package/src/config/world/userTypes.ts +2 -0
- package/src/render-solidity/tablegen.ts +3 -13
- package/src/render-solidity/worldgen.ts +5 -6
- package/src/render-ts/index.ts +5 -0
- package/src/render-ts/recsV1TableOptions.ts +39 -0
- package/src/render-ts/renderRecsV1Tables.ts +31 -0
- package/src/render-ts/schemaTypesToRecsTypeStrings.ts +202 -0
- package/src/render-ts/tsgen.ts +12 -0
- package/src/render-ts/types.ts +13 -0
- package/src/utils/deploy-v2.ts +4 -4
- package/src/utils/format.ts +6 -0
- package/src/utils/formatAndWrite.ts +11 -2
- package/src/utils/index.ts +1 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AbiTypeToSchemaType,
|
|
3
|
+
SchemaType,
|
|
4
|
+
SchemaTypeToAbiType,
|
|
5
|
+
getStaticByteLength,
|
|
6
|
+
parseStaticArray
|
|
7
|
+
} from "./chunk-KPBNUPK6.js";
|
|
8
|
+
|
|
9
|
+
// src/render-solidity/userType.ts
|
|
10
|
+
function resolveAbiOrUserType(abiOrUserType, config) {
|
|
11
|
+
if (abiOrUserType in AbiTypeToSchemaType) {
|
|
12
|
+
const schemaType = AbiTypeToSchemaType[abiOrUserType];
|
|
13
|
+
return {
|
|
14
|
+
schemaType,
|
|
15
|
+
renderTableType: getSchemaTypeInfo(schemaType)
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
const staticArray = parseStaticArray(abiOrUserType);
|
|
19
|
+
if (staticArray) {
|
|
20
|
+
if (staticArray.elementType in AbiTypeToSchemaType) {
|
|
21
|
+
return getStaticArrayTypeInfo(abiOrUserType, staticArray.elementType, staticArray.staticLength);
|
|
22
|
+
} else {
|
|
23
|
+
throw new Error("Static arrays of user types are not supported");
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return getUserTypeInfo(abiOrUserType, config);
|
|
27
|
+
}
|
|
28
|
+
function importForAbiOrUserType(abiOrUserType, usedInDirectory, config) {
|
|
29
|
+
if (abiOrUserType in AbiTypeToSchemaType) {
|
|
30
|
+
return void 0;
|
|
31
|
+
}
|
|
32
|
+
const staticArray = parseStaticArray(abiOrUserType);
|
|
33
|
+
if (staticArray) {
|
|
34
|
+
return void 0;
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
symbol: abiOrUserType,
|
|
38
|
+
fromPath: config.userTypesPath + ".sol",
|
|
39
|
+
usedInPath: usedInDirectory
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function getSchemaTypeInfo(schemaType) {
|
|
43
|
+
const staticByteLength = getStaticByteLength(schemaType);
|
|
44
|
+
const isDynamic = staticByteLength === 0;
|
|
45
|
+
const typeId = SchemaTypeToAbiType[schemaType];
|
|
46
|
+
return {
|
|
47
|
+
typeId,
|
|
48
|
+
typeWithLocation: isDynamic ? typeId + " memory" : typeId,
|
|
49
|
+
enumName: SchemaType[schemaType],
|
|
50
|
+
staticByteLength,
|
|
51
|
+
isDynamic,
|
|
52
|
+
typeWrap: "",
|
|
53
|
+
typeUnwrap: "",
|
|
54
|
+
internalTypeId: typeId
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function getUserTypeInfo(userType, config) {
|
|
58
|
+
if (userType in config.enums) {
|
|
59
|
+
const schemaType = 0 /* UINT8 */;
|
|
60
|
+
const staticByteLength = getStaticByteLength(schemaType);
|
|
61
|
+
const isDynamic = staticByteLength === 0;
|
|
62
|
+
const typeId = userType;
|
|
63
|
+
return {
|
|
64
|
+
schemaType,
|
|
65
|
+
renderTableType: {
|
|
66
|
+
typeId,
|
|
67
|
+
typeWithLocation: typeId,
|
|
68
|
+
enumName: SchemaType[schemaType],
|
|
69
|
+
staticByteLength,
|
|
70
|
+
isDynamic,
|
|
71
|
+
typeWrap: `${userType}`,
|
|
72
|
+
typeUnwrap: `uint8`,
|
|
73
|
+
internalTypeId: `${SchemaTypeToAbiType[schemaType]}`
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
throw new Error(`User type "${userType}" does not exist`);
|
|
78
|
+
}
|
|
79
|
+
function getStaticArrayTypeInfo(abiType, elementType, staticLength) {
|
|
80
|
+
const internalTypeId = elementType + "[]";
|
|
81
|
+
const schemaType = AbiTypeToSchemaType[internalTypeId];
|
|
82
|
+
return {
|
|
83
|
+
schemaType,
|
|
84
|
+
renderTableType: {
|
|
85
|
+
typeId: abiType,
|
|
86
|
+
typeWithLocation: `${abiType} memory`,
|
|
87
|
+
enumName: SchemaType[schemaType],
|
|
88
|
+
staticByteLength: 0,
|
|
89
|
+
isDynamic: true,
|
|
90
|
+
typeWrap: `toStaticArray_${elementType}_${staticLength}`,
|
|
91
|
+
typeUnwrap: `fromStaticArray_${elementType}_${staticLength}`,
|
|
92
|
+
typeWrappingData: {
|
|
93
|
+
kind: "staticArray",
|
|
94
|
+
elementType,
|
|
95
|
+
staticLength
|
|
96
|
+
},
|
|
97
|
+
internalTypeId
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// src/utils/format.ts
|
|
103
|
+
import chalk from "chalk";
|
|
104
|
+
import prettier from "prettier";
|
|
105
|
+
import prettierPluginSolidity from "prettier-plugin-solidity";
|
|
106
|
+
async function formatSolidity(content, prettierConfigPath) {
|
|
107
|
+
let config;
|
|
108
|
+
if (prettierConfigPath) {
|
|
109
|
+
config = await prettier.resolveConfig(prettierConfigPath);
|
|
110
|
+
}
|
|
111
|
+
try {
|
|
112
|
+
return prettier.format(content, {
|
|
113
|
+
plugins: [prettierPluginSolidity],
|
|
114
|
+
parser: "solidity-parse",
|
|
115
|
+
printWidth: 120,
|
|
116
|
+
semi: true,
|
|
117
|
+
tabWidth: 2,
|
|
118
|
+
useTabs: false,
|
|
119
|
+
bracketSpacing: true,
|
|
120
|
+
...config
|
|
121
|
+
});
|
|
122
|
+
} catch (error) {
|
|
123
|
+
let message;
|
|
124
|
+
if (error instanceof Error) {
|
|
125
|
+
message = error.message;
|
|
126
|
+
} else {
|
|
127
|
+
message = error;
|
|
128
|
+
}
|
|
129
|
+
console.log(chalk.yellow(`Error during output formatting: ${message}`));
|
|
130
|
+
return content;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
async function formatTypescript(content) {
|
|
134
|
+
return prettier.format(content, {
|
|
135
|
+
parser: "typescript"
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// src/utils/formatAndWrite.ts
|
|
140
|
+
import { mkdirSync, writeFileSync } from "fs";
|
|
141
|
+
import { dirname } from "path";
|
|
142
|
+
async function formatAndWriteSolidity(output, fullOutputPath, logPrefix) {
|
|
143
|
+
const formattedOutput = await formatSolidity(output);
|
|
144
|
+
mkdirSync(dirname(fullOutputPath), { recursive: true });
|
|
145
|
+
writeFileSync(fullOutputPath, formattedOutput);
|
|
146
|
+
console.log(`${logPrefix}: ${fullOutputPath}`);
|
|
147
|
+
}
|
|
148
|
+
async function formatAndWriteTypescript(output, fullOutputPath, logPrefix) {
|
|
149
|
+
const formattedOutput = await formatTypescript(output);
|
|
150
|
+
mkdirSync(dirname(fullOutputPath), { recursive: true });
|
|
151
|
+
writeFileSync(fullOutputPath, formattedOutput);
|
|
152
|
+
console.log(`${logPrefix}: ${fullOutputPath}`);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export {
|
|
156
|
+
resolveAbiOrUserType,
|
|
157
|
+
importForAbiOrUserType,
|
|
158
|
+
getSchemaTypeInfo,
|
|
159
|
+
getUserTypeInfo,
|
|
160
|
+
formatSolidity,
|
|
161
|
+
formatTypescript,
|
|
162
|
+
formatAndWriteSolidity,
|
|
163
|
+
formatAndWriteTypescript
|
|
164
|
+
};
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import {
|
|
2
|
+
formatAndWriteTypescript,
|
|
3
|
+
resolveAbiOrUserType
|
|
4
|
+
} from "./chunk-5NC2OON2.js";
|
|
5
|
+
|
|
6
|
+
// src/render-ts/schemaTypesToRecsTypeStrings.ts
|
|
7
|
+
var schemaTypesToRecsTypeStrings = {
|
|
8
|
+
[0 /* UINT8 */]: "RecsType.Number",
|
|
9
|
+
[1 /* UINT16 */]: "RecsType.Number",
|
|
10
|
+
[2 /* UINT24 */]: "RecsType.Number",
|
|
11
|
+
[3 /* UINT32 */]: "RecsType.Number",
|
|
12
|
+
[4 /* UINT40 */]: "RecsType.Number",
|
|
13
|
+
[5 /* UINT48 */]: "RecsType.Number",
|
|
14
|
+
[6 /* UINT56 */]: "RecsType.Number",
|
|
15
|
+
[7 /* UINT64 */]: "RecsType.Number",
|
|
16
|
+
[8 /* UINT72 */]: "RecsType.Number",
|
|
17
|
+
[9 /* UINT80 */]: "RecsType.Number",
|
|
18
|
+
[10 /* UINT88 */]: "RecsType.Number",
|
|
19
|
+
[11 /* UINT96 */]: "RecsType.Number",
|
|
20
|
+
[12 /* UINT104 */]: "RecsType.Number",
|
|
21
|
+
[13 /* UINT112 */]: "RecsType.Number",
|
|
22
|
+
[14 /* UINT120 */]: "RecsType.Number",
|
|
23
|
+
[15 /* UINT128 */]: "RecsType.Number",
|
|
24
|
+
[16 /* UINT136 */]: "RecsType.Number",
|
|
25
|
+
[17 /* UINT144 */]: "RecsType.Number",
|
|
26
|
+
[18 /* UINT152 */]: "RecsType.Number",
|
|
27
|
+
[19 /* UINT160 */]: "RecsType.Number",
|
|
28
|
+
[20 /* UINT168 */]: "RecsType.Number",
|
|
29
|
+
[21 /* UINT176 */]: "RecsType.Number",
|
|
30
|
+
[22 /* UINT184 */]: "RecsType.Number",
|
|
31
|
+
[23 /* UINT192 */]: "RecsType.Number",
|
|
32
|
+
[24 /* UINT200 */]: "RecsType.Number",
|
|
33
|
+
[25 /* UINT208 */]: "RecsType.Number",
|
|
34
|
+
[26 /* UINT216 */]: "RecsType.Number",
|
|
35
|
+
[27 /* UINT224 */]: "RecsType.Number",
|
|
36
|
+
[28 /* UINT232 */]: "RecsType.Number",
|
|
37
|
+
[29 /* UINT240 */]: "RecsType.Number",
|
|
38
|
+
[30 /* UINT248 */]: "RecsType.Number",
|
|
39
|
+
[31 /* UINT256 */]: "RecsType.Number",
|
|
40
|
+
[32 /* INT8 */]: "RecsType.Number",
|
|
41
|
+
[33 /* INT16 */]: "RecsType.Number",
|
|
42
|
+
[34 /* INT24 */]: "RecsType.Number",
|
|
43
|
+
[35 /* INT32 */]: "RecsType.Number",
|
|
44
|
+
[36 /* INT40 */]: "RecsType.Number",
|
|
45
|
+
[37 /* INT48 */]: "RecsType.Number",
|
|
46
|
+
[38 /* INT56 */]: "RecsType.Number",
|
|
47
|
+
[39 /* INT64 */]: "RecsType.Number",
|
|
48
|
+
[40 /* INT72 */]: "RecsType.Number",
|
|
49
|
+
[41 /* INT80 */]: "RecsType.Number",
|
|
50
|
+
[42 /* INT88 */]: "RecsType.Number",
|
|
51
|
+
[43 /* INT96 */]: "RecsType.Number",
|
|
52
|
+
[44 /* INT104 */]: "RecsType.Number",
|
|
53
|
+
[45 /* INT112 */]: "RecsType.Number",
|
|
54
|
+
[46 /* INT120 */]: "RecsType.Number",
|
|
55
|
+
[47 /* INT128 */]: "RecsType.Number",
|
|
56
|
+
[48 /* INT136 */]: "RecsType.Number",
|
|
57
|
+
[49 /* INT144 */]: "RecsType.Number",
|
|
58
|
+
[50 /* INT152 */]: "RecsType.Number",
|
|
59
|
+
[51 /* INT160 */]: "RecsType.Number",
|
|
60
|
+
[52 /* INT168 */]: "RecsType.Number",
|
|
61
|
+
[53 /* INT176 */]: "RecsType.Number",
|
|
62
|
+
[54 /* INT184 */]: "RecsType.Number",
|
|
63
|
+
[55 /* INT192 */]: "RecsType.Number",
|
|
64
|
+
[56 /* INT200 */]: "RecsType.Number",
|
|
65
|
+
[57 /* INT208 */]: "RecsType.Number",
|
|
66
|
+
[58 /* INT216 */]: "RecsType.Number",
|
|
67
|
+
[59 /* INT224 */]: "RecsType.Number",
|
|
68
|
+
[60 /* INT232 */]: "RecsType.Number",
|
|
69
|
+
[61 /* INT240 */]: "RecsType.Number",
|
|
70
|
+
[62 /* INT248 */]: "RecsType.Number",
|
|
71
|
+
[63 /* INT256 */]: "RecsType.Number",
|
|
72
|
+
[64 /* BYTES1 */]: "RecsType.String",
|
|
73
|
+
[65 /* BYTES2 */]: "RecsType.String",
|
|
74
|
+
[66 /* BYTES3 */]: "RecsType.String",
|
|
75
|
+
[67 /* BYTES4 */]: "RecsType.String",
|
|
76
|
+
[68 /* BYTES5 */]: "RecsType.String",
|
|
77
|
+
[69 /* BYTES6 */]: "RecsType.String",
|
|
78
|
+
[70 /* BYTES7 */]: "RecsType.String",
|
|
79
|
+
[71 /* BYTES8 */]: "RecsType.String",
|
|
80
|
+
[72 /* BYTES9 */]: "RecsType.String",
|
|
81
|
+
[73 /* BYTES10 */]: "RecsType.String",
|
|
82
|
+
[74 /* BYTES11 */]: "RecsType.String",
|
|
83
|
+
[75 /* BYTES12 */]: "RecsType.String",
|
|
84
|
+
[76 /* BYTES13 */]: "RecsType.String",
|
|
85
|
+
[77 /* BYTES14 */]: "RecsType.String",
|
|
86
|
+
[78 /* BYTES15 */]: "RecsType.String",
|
|
87
|
+
[79 /* BYTES16 */]: "RecsType.String",
|
|
88
|
+
[80 /* BYTES17 */]: "RecsType.String",
|
|
89
|
+
[81 /* BYTES18 */]: "RecsType.String",
|
|
90
|
+
[82 /* BYTES19 */]: "RecsType.String",
|
|
91
|
+
[83 /* BYTES20 */]: "RecsType.String",
|
|
92
|
+
[84 /* BYTES21 */]: "RecsType.String",
|
|
93
|
+
[85 /* BYTES22 */]: "RecsType.String",
|
|
94
|
+
[86 /* BYTES23 */]: "RecsType.String",
|
|
95
|
+
[87 /* BYTES24 */]: "RecsType.String",
|
|
96
|
+
[88 /* BYTES25 */]: "RecsType.String",
|
|
97
|
+
[89 /* BYTES26 */]: "RecsType.String",
|
|
98
|
+
[90 /* BYTES27 */]: "RecsType.String",
|
|
99
|
+
[91 /* BYTES28 */]: "RecsType.String",
|
|
100
|
+
[92 /* BYTES29 */]: "RecsType.String",
|
|
101
|
+
[93 /* BYTES30 */]: "RecsType.String",
|
|
102
|
+
[94 /* BYTES31 */]: "RecsType.String",
|
|
103
|
+
[95 /* BYTES32 */]: "RecsType.String",
|
|
104
|
+
[96 /* BOOL */]: "RecsType.Boolean",
|
|
105
|
+
[97 /* ADDRESS */]: "RecsType.String",
|
|
106
|
+
[98 /* UINT8_ARRAY */]: "RecsType.NumberArray",
|
|
107
|
+
[99 /* UINT16_ARRAY */]: "RecsType.NumberArray",
|
|
108
|
+
[100 /* UINT24_ARRAY */]: "RecsType.NumberArray",
|
|
109
|
+
[101 /* UINT32_ARRAY */]: "RecsType.NumberArray",
|
|
110
|
+
[102 /* UINT40_ARRAY */]: "RecsType.NumberArray",
|
|
111
|
+
[103 /* UINT48_ARRAY */]: "RecsType.NumberArray",
|
|
112
|
+
[104 /* UINT56_ARRAY */]: "RecsType.NumberArray",
|
|
113
|
+
[105 /* UINT64_ARRAY */]: "RecsType.NumberArray",
|
|
114
|
+
[106 /* UINT72_ARRAY */]: "RecsType.NumberArray",
|
|
115
|
+
[107 /* UINT80_ARRAY */]: "RecsType.NumberArray",
|
|
116
|
+
[108 /* UINT88_ARRAY */]: "RecsType.NumberArray",
|
|
117
|
+
[109 /* UINT96_ARRAY */]: "RecsType.NumberArray",
|
|
118
|
+
[110 /* UINT104_ARRAY */]: "RecsType.NumberArray",
|
|
119
|
+
[111 /* UINT112_ARRAY */]: "RecsType.NumberArray",
|
|
120
|
+
[112 /* UINT120_ARRAY */]: "RecsType.NumberArray",
|
|
121
|
+
[113 /* UINT128_ARRAY */]: "RecsType.NumberArray",
|
|
122
|
+
[114 /* UINT136_ARRAY */]: "RecsType.NumberArray",
|
|
123
|
+
[115 /* UINT144_ARRAY */]: "RecsType.NumberArray",
|
|
124
|
+
[116 /* UINT152_ARRAY */]: "RecsType.NumberArray",
|
|
125
|
+
[117 /* UINT160_ARRAY */]: "RecsType.NumberArray",
|
|
126
|
+
[118 /* UINT168_ARRAY */]: "RecsType.NumberArray",
|
|
127
|
+
[119 /* UINT176_ARRAY */]: "RecsType.NumberArray",
|
|
128
|
+
[120 /* UINT184_ARRAY */]: "RecsType.NumberArray",
|
|
129
|
+
[121 /* UINT192_ARRAY */]: "RecsType.NumberArray",
|
|
130
|
+
[122 /* UINT200_ARRAY */]: "RecsType.NumberArray",
|
|
131
|
+
[123 /* UINT208_ARRAY */]: "RecsType.NumberArray",
|
|
132
|
+
[124 /* UINT216_ARRAY */]: "RecsType.NumberArray",
|
|
133
|
+
[125 /* UINT224_ARRAY */]: "RecsType.NumberArray",
|
|
134
|
+
[126 /* UINT232_ARRAY */]: "RecsType.NumberArray",
|
|
135
|
+
[127 /* UINT240_ARRAY */]: "RecsType.NumberArray",
|
|
136
|
+
[128 /* UINT248_ARRAY */]: "RecsType.NumberArray",
|
|
137
|
+
[129 /* UINT256_ARRAY */]: "RecsType.NumberArray",
|
|
138
|
+
[130 /* INT8_ARRAY */]: "RecsType.NumberArray",
|
|
139
|
+
[131 /* INT16_ARRAY */]: "RecsType.NumberArray",
|
|
140
|
+
[132 /* INT24_ARRAY */]: "RecsType.NumberArray",
|
|
141
|
+
[133 /* INT32_ARRAY */]: "RecsType.NumberArray",
|
|
142
|
+
[134 /* INT40_ARRAY */]: "RecsType.NumberArray",
|
|
143
|
+
[135 /* INT48_ARRAY */]: "RecsType.NumberArray",
|
|
144
|
+
[136 /* INT56_ARRAY */]: "RecsType.NumberArray",
|
|
145
|
+
[137 /* INT64_ARRAY */]: "RecsType.NumberArray",
|
|
146
|
+
[138 /* INT72_ARRAY */]: "RecsType.NumberArray",
|
|
147
|
+
[139 /* INT80_ARRAY */]: "RecsType.NumberArray",
|
|
148
|
+
[140 /* INT88_ARRAY */]: "RecsType.NumberArray",
|
|
149
|
+
[141 /* INT96_ARRAY */]: "RecsType.NumberArray",
|
|
150
|
+
[142 /* INT104_ARRAY */]: "RecsType.NumberArray",
|
|
151
|
+
[143 /* INT112_ARRAY */]: "RecsType.NumberArray",
|
|
152
|
+
[144 /* INT120_ARRAY */]: "RecsType.NumberArray",
|
|
153
|
+
[145 /* INT128_ARRAY */]: "RecsType.NumberArray",
|
|
154
|
+
[146 /* INT136_ARRAY */]: "RecsType.NumberArray",
|
|
155
|
+
[147 /* INT144_ARRAY */]: "RecsType.NumberArray",
|
|
156
|
+
[148 /* INT152_ARRAY */]: "RecsType.NumberArray",
|
|
157
|
+
[149 /* INT160_ARRAY */]: "RecsType.NumberArray",
|
|
158
|
+
[150 /* INT168_ARRAY */]: "RecsType.NumberArray",
|
|
159
|
+
[151 /* INT176_ARRAY */]: "RecsType.NumberArray",
|
|
160
|
+
[152 /* INT184_ARRAY */]: "RecsType.NumberArray",
|
|
161
|
+
[153 /* INT192_ARRAY */]: "RecsType.NumberArray",
|
|
162
|
+
[154 /* INT200_ARRAY */]: "RecsType.NumberArray",
|
|
163
|
+
[155 /* INT208_ARRAY */]: "RecsType.NumberArray",
|
|
164
|
+
[156 /* INT216_ARRAY */]: "RecsType.NumberArray",
|
|
165
|
+
[157 /* INT224_ARRAY */]: "RecsType.NumberArray",
|
|
166
|
+
[158 /* INT232_ARRAY */]: "RecsType.NumberArray",
|
|
167
|
+
[159 /* INT240_ARRAY */]: "RecsType.NumberArray",
|
|
168
|
+
[160 /* INT248_ARRAY */]: "RecsType.NumberArray",
|
|
169
|
+
[161 /* INT256_ARRAY */]: "RecsType.NumberArray",
|
|
170
|
+
[162 /* BYTES1_ARRAY */]: "RecsType.StringArray",
|
|
171
|
+
[163 /* BYTES2_ARRAY */]: "RecsType.StringArray",
|
|
172
|
+
[164 /* BYTES3_ARRAY */]: "RecsType.StringArray",
|
|
173
|
+
[165 /* BYTES4_ARRAY */]: "RecsType.StringArray",
|
|
174
|
+
[166 /* BYTES5_ARRAY */]: "RecsType.StringArray",
|
|
175
|
+
[167 /* BYTES6_ARRAY */]: "RecsType.StringArray",
|
|
176
|
+
[168 /* BYTES7_ARRAY */]: "RecsType.StringArray",
|
|
177
|
+
[169 /* BYTES8_ARRAY */]: "RecsType.StringArray",
|
|
178
|
+
[170 /* BYTES9_ARRAY */]: "RecsType.StringArray",
|
|
179
|
+
[171 /* BYTES10_ARRAY */]: "RecsType.StringArray",
|
|
180
|
+
[172 /* BYTES11_ARRAY */]: "RecsType.StringArray",
|
|
181
|
+
[173 /* BYTES12_ARRAY */]: "RecsType.StringArray",
|
|
182
|
+
[174 /* BYTES13_ARRAY */]: "RecsType.StringArray",
|
|
183
|
+
[175 /* BYTES14_ARRAY */]: "RecsType.StringArray",
|
|
184
|
+
[176 /* BYTES15_ARRAY */]: "RecsType.StringArray",
|
|
185
|
+
[177 /* BYTES16_ARRAY */]: "RecsType.StringArray",
|
|
186
|
+
[178 /* BYTES17_ARRAY */]: "RecsType.StringArray",
|
|
187
|
+
[179 /* BYTES18_ARRAY */]: "RecsType.StringArray",
|
|
188
|
+
[180 /* BYTES19_ARRAY */]: "RecsType.StringArray",
|
|
189
|
+
[181 /* BYTES20_ARRAY */]: "RecsType.StringArray",
|
|
190
|
+
[182 /* BYTES21_ARRAY */]: "RecsType.StringArray",
|
|
191
|
+
[183 /* BYTES22_ARRAY */]: "RecsType.StringArray",
|
|
192
|
+
[184 /* BYTES23_ARRAY */]: "RecsType.StringArray",
|
|
193
|
+
[185 /* BYTES24_ARRAY */]: "RecsType.StringArray",
|
|
194
|
+
[186 /* BYTES25_ARRAY */]: "RecsType.StringArray",
|
|
195
|
+
[187 /* BYTES26_ARRAY */]: "RecsType.StringArray",
|
|
196
|
+
[188 /* BYTES27_ARRAY */]: "RecsType.StringArray",
|
|
197
|
+
[189 /* BYTES28_ARRAY */]: "RecsType.StringArray",
|
|
198
|
+
[190 /* BYTES29_ARRAY */]: "RecsType.StringArray",
|
|
199
|
+
[191 /* BYTES30_ARRAY */]: "RecsType.StringArray",
|
|
200
|
+
[192 /* BYTES31_ARRAY */]: "RecsType.StringArray",
|
|
201
|
+
[193 /* BYTES32_ARRAY */]: "RecsType.StringArray",
|
|
202
|
+
[194 /* BOOL_ARRAY */]: "RecsType.T",
|
|
203
|
+
// no boolean array
|
|
204
|
+
[195 /* ADDRESS_ARRAY */]: "RecsType.StringArray",
|
|
205
|
+
[196 /* BYTES */]: "RecsType.String",
|
|
206
|
+
[197 /* STRING */]: "RecsType.String"
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
// src/render-ts/recsV1TableOptions.ts
|
|
210
|
+
function getRecsV1TableOptions(config) {
|
|
211
|
+
const tableOptions = [];
|
|
212
|
+
for (const tableName of Object.keys(config.tables)) {
|
|
213
|
+
const tableData = config.tables[tableName];
|
|
214
|
+
const fields = Object.keys(tableData.schema).map((name) => {
|
|
215
|
+
const abiOrUserType = tableData.schema[name];
|
|
216
|
+
const { schemaType } = resolveAbiOrUserType(abiOrUserType, config);
|
|
217
|
+
const recsTypeString = schemaTypesToRecsTypeStrings[schemaType];
|
|
218
|
+
return {
|
|
219
|
+
recsTypeString,
|
|
220
|
+
name
|
|
221
|
+
};
|
|
222
|
+
});
|
|
223
|
+
if (tableData.tableIdArgument)
|
|
224
|
+
continue;
|
|
225
|
+
const staticResourceData = {
|
|
226
|
+
namespace: config.namespace,
|
|
227
|
+
fileSelector: tableData.fileSelector
|
|
228
|
+
};
|
|
229
|
+
tableOptions.push({
|
|
230
|
+
tableName,
|
|
231
|
+
fields,
|
|
232
|
+
staticResourceData
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
return {
|
|
236
|
+
tables: tableOptions
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// src/render-ts/renderRecsV1Tables.ts
|
|
241
|
+
function renderRecsV1Tables(options) {
|
|
242
|
+
const { tables } = options;
|
|
243
|
+
return `/* Autogenerated file. Do not edit manually. */
|
|
244
|
+
|
|
245
|
+
import { TableId } from "@latticexyz/utils";
|
|
246
|
+
import { defineComponent, Type as RecsType, World } from "@latticexyz/recs";
|
|
247
|
+
|
|
248
|
+
export function defineContractComponents(world: World) {
|
|
249
|
+
return {
|
|
250
|
+
${tables.map((table) => `${table.tableName}: ${renderDefineComponent(table)},`).join("")}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
`;
|
|
254
|
+
}
|
|
255
|
+
function renderDefineComponent(table) {
|
|
256
|
+
const { namespace, fileSelector } = table.staticResourceData;
|
|
257
|
+
return `
|
|
258
|
+
(() => {
|
|
259
|
+
const tableId = new TableId("${namespace}", "${fileSelector}");
|
|
260
|
+
return defineComponent(world, {
|
|
261
|
+
${table.fields.map(({ name, recsTypeString }) => `${name}: ${recsTypeString},`).join("")}
|
|
262
|
+
}, {
|
|
263
|
+
metadata: { contractId: tableId.toHexString(), tableId: tableId.toString() },
|
|
264
|
+
});
|
|
265
|
+
})()
|
|
266
|
+
`;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// src/render-ts/tsgen.ts
|
|
270
|
+
import path from "path";
|
|
271
|
+
async function tsgen(config, outDirectory) {
|
|
272
|
+
const fullOutputPath = path.join(outDirectory, `contractComponents.ts`);
|
|
273
|
+
const options = getRecsV1TableOptions(config);
|
|
274
|
+
const output = renderRecsV1Tables(options);
|
|
275
|
+
formatAndWriteTypescript(output, fullOutputPath, "Generated ts definition files");
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export {
|
|
279
|
+
schemaTypesToRecsTypeStrings,
|
|
280
|
+
getRecsV1TableOptions,
|
|
281
|
+
renderRecsV1Tables,
|
|
282
|
+
tsgen
|
|
283
|
+
};
|