@latticexyz/cli 2.0.0-alpha.0 → 2.0.0-alpha.2
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-6V563IAZ.js +283 -0
- package/dist/{chunk-ATAWDHWC.js → chunk-FPG73MVN.js} +5 -1
- package/dist/{chunk-O6HOO6WA.js → chunk-L4YLJHLJ.js} +1 -9
- package/dist/{chunk-J4DJQNIC.js → chunk-SKNB74MT.js} +129 -568
- package/dist/chunk-VQTZJIFF.js +353 -0
- package/dist/chunk-WZFXLDPK.js +761 -0
- package/dist/chunk-YL4GJLLL.js +26139 -0
- package/dist/chunk-ZSZDPSLH.js +3841 -0
- package/dist/index.d.ts +2 -3
- package/dist/index.js +0 -21
- package/dist/mud.d.ts +1 -1
- package/dist/mud.js +326 -4452
- package/dist/mud2.d.ts +1 -0
- package/dist/mud2.js +25 -0
- package/dist/render-solidity/index.d.ts +171 -0
- package/dist/render-solidity/index.js +49 -0
- package/dist/render-ts/index.d.ts +26 -0
- package/dist/render-ts/index.js +14 -0
- package/dist/utils/deprecated/index.js +3 -3
- package/dist/utils/index.d.ts +13 -18
- package/dist/utils/index.js +14 -16
- package/package.json +20 -21
- package/src/commands/deploy-v2.ts +80 -64
- package/src/commands/deprecated/index.ts +22 -0
- package/src/commands/deprecated/test.ts +1 -1
- package/src/commands/gas-report.ts +54 -55
- package/src/commands/index.ts +6 -17
- package/src/commands/set-version.ts +172 -0
- package/src/commands/tablegen.ts +5 -5
- package/src/commands/test-v2.ts +71 -0
- package/src/commands/tsgen.ts +33 -0
- package/src/commands/worldgen.ts +5 -4
- package/src/contracts/BulkUpload.sol +13 -20
- package/src/contracts/Deploy.sol +3 -3
- package/src/contracts/LibDeploy.sol +1 -1
- package/src/contracts/LibDeployStub.sol +1 -1
- package/src/index.ts +1 -15
- package/src/mud.ts +4 -3
- package/src/mud2.ts +29 -0
- package/src/render-solidity/common.ts +4 -4
- package/src/render-solidity/field.ts +25 -2
- package/src/render-solidity/record.ts +14 -10
- package/src/render-solidity/renderSystemInterface.ts +4 -4
- package/src/render-solidity/renderTableIndex.ts +15 -0
- package/src/render-solidity/renderTypesFromConfig.ts +1 -1
- package/src/render-solidity/tableOptions.ts +2 -2
- package/src/render-solidity/tablegen.ts +15 -13
- package/src/render-solidity/types.ts +2 -1
- package/src/render-solidity/userType.ts +1 -2
- package/src/render-solidity/worldgen.ts +8 -9
- 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/contractToInterface.ts +5 -3
- package/src/utils/deploy-v2.ts +90 -84
- package/src/utils/errors.ts +3 -34
- package/src/utils/format.ts +6 -0
- package/src/utils/formatAndWrite.ts +11 -2
- package/src/utils/foundry.ts +9 -0
- package/src/utils/index.ts +1 -0
- package/dist/chunk-O57QENJ6.js +0 -23039
- package/dist/chunk-SLIMIO4Z.js +0 -14358
- package/dist/config/index.d.ts +0 -763
- package/dist/config/index.js +0 -83
- package/src/config/commonSchemas.ts +0 -34
- package/src/config/dynamicResolution.ts +0 -49
- package/src/config/index.ts +0 -24
- package/src/config/loadConfig.ts +0 -39
- package/src/config/loadStoreConfig.ts +0 -18
- package/src/config/parseStoreConfig.test-d.ts +0 -40
- package/src/config/parseStoreConfig.ts +0 -314
- package/src/config/validation.ts +0 -163
- package/src/config/world/index.ts +0 -4
- package/src/config/world/loadWorldConfig.test-d.ts +0 -11
- package/src/config/world/loadWorldConfig.ts +0 -26
- package/src/config/world/parseWorldConfig.ts +0 -55
- package/src/config/world/resolveWorldConfig.ts +0 -80
- package/src/config/world/userTypes.ts +0 -72
- package/src/utils/typeUtils.ts +0 -17
|
@@ -1,259 +1,3 @@
|
|
|
1
|
-
// src/config/commonSchemas.ts
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
|
|
4
|
-
// src/config/validation.ts
|
|
5
|
-
import { ethers } from "ethers";
|
|
6
|
-
import { ZodIssueCode } from "zod";
|
|
7
|
-
function validateName(name, ctx) {
|
|
8
|
-
if (!/^\w+$/.test(name)) {
|
|
9
|
-
ctx.addIssue({
|
|
10
|
-
code: ZodIssueCode.custom,
|
|
11
|
-
message: `Name must contain only alphanumeric & underscore characters`
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
function validateCapitalizedName(name, ctx) {
|
|
16
|
-
validateName(name, ctx);
|
|
17
|
-
if (!/^[A-Z]/.test(name)) {
|
|
18
|
-
ctx.addIssue({
|
|
19
|
-
code: ZodIssueCode.custom,
|
|
20
|
-
message: `Name must start with a capital letter`
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
function validateUncapitalizedName(name, ctx) {
|
|
25
|
-
validateName(name, ctx);
|
|
26
|
-
if (!/^[a-z]/.test(name)) {
|
|
27
|
-
ctx.addIssue({
|
|
28
|
-
code: ZodIssueCode.custom,
|
|
29
|
-
message: `Name must start with a lowercase letter`
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
function validateEnum(members, ctx) {
|
|
34
|
-
if (members.length === 0) {
|
|
35
|
-
ctx.addIssue({
|
|
36
|
-
code: ZodIssueCode.custom,
|
|
37
|
-
message: `Enum must not be empty`
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
if (members.length >= 256) {
|
|
41
|
-
ctx.addIssue({
|
|
42
|
-
code: ZodIssueCode.custom,
|
|
43
|
-
message: `Length of enum must be < 256`
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
const duplicates = getDuplicates(members);
|
|
47
|
-
if (duplicates.length > 0) {
|
|
48
|
-
ctx.addIssue({
|
|
49
|
-
code: ZodIssueCode.custom,
|
|
50
|
-
message: `Enum must not have duplicate names for: ${duplicates.join(", ")}`
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
function _factoryForValidateRoute(requireNonEmpty, requireSingleLevel) {
|
|
55
|
-
return (route, ctx) => {
|
|
56
|
-
if (route === "") {
|
|
57
|
-
if (requireNonEmpty) {
|
|
58
|
-
ctx.addIssue({
|
|
59
|
-
code: ZodIssueCode.custom,
|
|
60
|
-
message: `Route must not be empty`
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
if (route[0] !== "/") {
|
|
66
|
-
ctx.addIssue({
|
|
67
|
-
code: ZodIssueCode.custom,
|
|
68
|
-
message: `Route must start with "/"`
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
if (route[route.length - 1] === "/") {
|
|
72
|
-
ctx.addIssue({
|
|
73
|
-
code: ZodIssueCode.custom,
|
|
74
|
-
message: `Route must not end with "/"`
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
const parts = route.split("/");
|
|
78
|
-
if (requireSingleLevel && parts.length > 2) {
|
|
79
|
-
ctx.addIssue({
|
|
80
|
-
code: ZodIssueCode.custom,
|
|
81
|
-
message: `Route must only have one level (e.g. "/foo")`
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
for (let i = 1; i < parts.length; i++) {
|
|
85
|
-
if (parts[i] === "") {
|
|
86
|
-
ctx.addIssue({
|
|
87
|
-
code: ZodIssueCode.custom,
|
|
88
|
-
message: `Route must not contain empty route fragments (e.g. "//")`
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
if (!/^\w+$/.test(parts[i])) {
|
|
92
|
-
ctx.addIssue({
|
|
93
|
-
code: ZodIssueCode.custom,
|
|
94
|
-
message: `Route must contain only alphanumeric & underscore characters`
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
var validateRoute = _factoryForValidateRoute(true, false);
|
|
101
|
-
var validateBaseRoute = _factoryForValidateRoute(false, false);
|
|
102
|
-
var validateSingleLevelRoute = _factoryForValidateRoute(true, true);
|
|
103
|
-
function validateEthereumAddress(address, ctx) {
|
|
104
|
-
if (!ethers.utils.isAddress(address)) {
|
|
105
|
-
ctx.addIssue({
|
|
106
|
-
code: ZodIssueCode.custom,
|
|
107
|
-
message: `Address must be a valid Ethereum address`
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
function getDuplicates(array) {
|
|
112
|
-
const checked = /* @__PURE__ */ new Set();
|
|
113
|
-
const duplicates = /* @__PURE__ */ new Set();
|
|
114
|
-
for (const element of array) {
|
|
115
|
-
if (checked.has(element)) {
|
|
116
|
-
duplicates.add(element);
|
|
117
|
-
}
|
|
118
|
-
checked.add(element);
|
|
119
|
-
}
|
|
120
|
-
return [...duplicates];
|
|
121
|
-
}
|
|
122
|
-
function validateSelector(name, ctx) {
|
|
123
|
-
if (name.length > 16) {
|
|
124
|
-
ctx.addIssue({
|
|
125
|
-
code: ZodIssueCode.custom,
|
|
126
|
-
message: `Selector must be <= 16 characters`
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
if (!/^\w*$/.test(name)) {
|
|
130
|
-
ctx.addIssue({
|
|
131
|
-
code: ZodIssueCode.custom,
|
|
132
|
-
message: `Selector must contain only alphanumeric & underscore characters`
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
function parseStaticArray(abiType) {
|
|
137
|
-
const matches = abiType.match(/^(\w+)\[(\d+)\]$/);
|
|
138
|
-
if (!matches)
|
|
139
|
-
return null;
|
|
140
|
-
return {
|
|
141
|
-
elementType: matches[1],
|
|
142
|
-
staticLength: Number.parseInt(matches[2])
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// src/config/commonSchemas.ts
|
|
147
|
-
var zObjectName = z.string().superRefine(validateCapitalizedName);
|
|
148
|
-
var zValueName = z.string().superRefine(validateUncapitalizedName);
|
|
149
|
-
var zAnyCaseName = z.string().superRefine(validateName);
|
|
150
|
-
var zUserEnum = z.array(zObjectName).superRefine(validateEnum);
|
|
151
|
-
var zOrdinaryRoute = z.string().superRefine(validateRoute);
|
|
152
|
-
var zSingleLevelRoute = z.string().superRefine(validateSingleLevelRoute);
|
|
153
|
-
var zBaseRoute = z.string().superRefine(validateBaseRoute);
|
|
154
|
-
var zEthereumAddress = z.string().superRefine(validateEthereumAddress);
|
|
155
|
-
var zSelector = z.string().superRefine(validateSelector);
|
|
156
|
-
|
|
157
|
-
// src/config/loadConfig.ts
|
|
158
|
-
import { findUp } from "find-up";
|
|
159
|
-
import path from "path";
|
|
160
|
-
|
|
161
|
-
// src/utils/errors.ts
|
|
162
|
-
import chalk from "chalk";
|
|
163
|
-
import { z as z2, ZodError, ZodIssueCode as ZodIssueCode2 } from "zod";
|
|
164
|
-
import { fromZodError, ValidationError } from "zod-validation-error";
|
|
165
|
-
function fromZodErrorCustom(error, prefix) {
|
|
166
|
-
return fromZodError(error, {
|
|
167
|
-
prefix: chalk.red(prefix),
|
|
168
|
-
prefixSeparator: "\n- ",
|
|
169
|
-
issueSeparator: "\n- "
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
var NotInsideProjectError = class extends Error {
|
|
173
|
-
constructor() {
|
|
174
|
-
super(...arguments);
|
|
175
|
-
this.name = "NotInsideProjectError";
|
|
176
|
-
this.message = "You are not inside a MUD project";
|
|
177
|
-
}
|
|
178
|
-
};
|
|
179
|
-
var NotESMConfigError = class extends Error {
|
|
180
|
-
constructor() {
|
|
181
|
-
super(...arguments);
|
|
182
|
-
this.name = "NotESMConfigError";
|
|
183
|
-
this.message = "MUD config must be an ES module";
|
|
184
|
-
}
|
|
185
|
-
};
|
|
186
|
-
var MUDError = class extends Error {
|
|
187
|
-
constructor() {
|
|
188
|
-
super(...arguments);
|
|
189
|
-
this.name = "MUDError";
|
|
190
|
-
}
|
|
191
|
-
};
|
|
192
|
-
function UnrecognizedSystemErrorFactory(path2, systemName) {
|
|
193
|
-
return new z2.ZodError([{ code: ZodIssueCode2.custom, path: path2, message: `Unrecognized system: "${systemName}"` }]);
|
|
194
|
-
}
|
|
195
|
-
function logError(error) {
|
|
196
|
-
if (error instanceof ValidationError) {
|
|
197
|
-
console.log(chalk.redBright(error.message));
|
|
198
|
-
} else if (error instanceof ZodError) {
|
|
199
|
-
const validationError = fromZodError(error, {
|
|
200
|
-
prefixSeparator: "\n- ",
|
|
201
|
-
issueSeparator: "\n- "
|
|
202
|
-
});
|
|
203
|
-
console.log(chalk.redBright(validationError.message));
|
|
204
|
-
} else if (error instanceof NotInsideProjectError) {
|
|
205
|
-
console.log(chalk.red(error.message));
|
|
206
|
-
console.log("");
|
|
207
|
-
console.log(chalk.blue(`To learn more about MUD's configuration, please go to https://mud.dev/packages/cli/`));
|
|
208
|
-
} else if (error instanceof NotESMConfigError) {
|
|
209
|
-
console.log(chalk.red(error.message));
|
|
210
|
-
console.log("");
|
|
211
|
-
console.log(
|
|
212
|
-
chalk.blue(`Please name your config file \`mud.config.mts\`, or use \`type: "module"\` in package.json`)
|
|
213
|
-
);
|
|
214
|
-
} else if (error instanceof MUDError) {
|
|
215
|
-
console.log(chalk.red(error));
|
|
216
|
-
} else {
|
|
217
|
-
console.log(error);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
// src/config/loadConfig.ts
|
|
222
|
-
var configFiles = ["mud.config.ts", "mud.config.mts"];
|
|
223
|
-
async function loadConfig(configPath) {
|
|
224
|
-
configPath = await resolveConfigPath(configPath);
|
|
225
|
-
try {
|
|
226
|
-
return (await import(configPath)).default;
|
|
227
|
-
} catch (error) {
|
|
228
|
-
if (error instanceof SyntaxError && error.message === "Cannot use import statement outside a module") {
|
|
229
|
-
throw new NotESMConfigError();
|
|
230
|
-
} else {
|
|
231
|
-
throw error;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
async function resolveConfigPath(configPath) {
|
|
236
|
-
if (configPath === void 0) {
|
|
237
|
-
configPath = await getUserConfigPath();
|
|
238
|
-
} else {
|
|
239
|
-
if (!path.isAbsolute(configPath)) {
|
|
240
|
-
configPath = path.join(process.cwd(), configPath);
|
|
241
|
-
configPath = path.normalize(configPath);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
return configPath;
|
|
245
|
-
}
|
|
246
|
-
async function getUserConfigPath() {
|
|
247
|
-
const tsConfigPath = await findUp(configFiles);
|
|
248
|
-
if (tsConfigPath === void 0) {
|
|
249
|
-
throw new NotInsideProjectError();
|
|
250
|
-
}
|
|
251
|
-
return tsConfigPath;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
// src/config/loadStoreConfig.ts
|
|
255
|
-
import { ZodError as ZodError2 } from "zod";
|
|
256
|
-
|
|
257
1
|
// ../schema-type/src/typescript/SchemaType.ts
|
|
258
2
|
var SchemaType = /* @__PURE__ */ ((SchemaType2) => {
|
|
259
3
|
SchemaType2[SchemaType2["UINT8"] = 0] = "UINT8";
|
|
@@ -821,345 +565,162 @@ var StaticAbiTypes = AbiTypes.filter(
|
|
|
821
565
|
(abiType) => getStaticByteLength(AbiTypeToSchemaType[abiType]) > 0
|
|
822
566
|
);
|
|
823
567
|
|
|
824
|
-
// src/
|
|
825
|
-
import {
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
var zFullSchemaConfig = z3.record(zColumnName, zFieldData).refine((arg) => Object.keys(arg).length > 0, "Table schema may not be empty");
|
|
834
|
-
var zShorthandSchemaConfig = zFieldData.transform((fieldData) => {
|
|
835
|
-
return zFullSchemaConfig.parse({
|
|
836
|
-
value: fieldData
|
|
837
|
-
});
|
|
838
|
-
});
|
|
839
|
-
var zSchemaConfig = zFullSchemaConfig.or(zShorthandSchemaConfig);
|
|
840
|
-
var zFullTableConfig = z3.object({
|
|
841
|
-
directory: z3.string().default("tables"),
|
|
842
|
-
fileSelector: zSelector.optional(),
|
|
843
|
-
tableIdArgument: z3.boolean().default(false),
|
|
844
|
-
storeArgument: z3.boolean().default(false),
|
|
845
|
-
primaryKeys: zPrimaryKeys,
|
|
846
|
-
schema: zSchemaConfig,
|
|
847
|
-
dataStruct: z3.boolean().optional()
|
|
848
|
-
}).transform((arg) => {
|
|
849
|
-
if (Object.keys(arg.schema).length === 1) {
|
|
850
|
-
arg.dataStruct ??= false;
|
|
851
|
-
} else {
|
|
852
|
-
arg.dataStruct ??= true;
|
|
853
|
-
}
|
|
854
|
-
return arg;
|
|
855
|
-
});
|
|
856
|
-
var zShorthandTableConfig = zFieldData.transform((fieldData) => {
|
|
857
|
-
return zFullTableConfig.parse({
|
|
858
|
-
schema: {
|
|
859
|
-
value: fieldData
|
|
860
|
-
}
|
|
861
|
-
});
|
|
862
|
-
});
|
|
863
|
-
var zTableConfig = zFullTableConfig.or(zShorthandTableConfig);
|
|
864
|
-
var zTablesConfig = z3.record(zTableName, zTableConfig).transform((tables) => {
|
|
865
|
-
for (const tableName of Object.keys(tables)) {
|
|
866
|
-
const table = tables[tableName];
|
|
867
|
-
table.fileSelector ??= tableName;
|
|
868
|
-
tables[tableName] = table;
|
|
869
|
-
}
|
|
870
|
-
return tables;
|
|
871
|
-
});
|
|
872
|
-
var zEnumsConfig = z3.object({
|
|
873
|
-
enums: z3.record(zUserEnumName, zUserEnum).default({})
|
|
874
|
-
});
|
|
875
|
-
function storeConfig(config) {
|
|
876
|
-
return config;
|
|
877
|
-
}
|
|
878
|
-
var StoreConfigUnrefined = z3.object({
|
|
879
|
-
namespace: zSelector.default(""),
|
|
880
|
-
storeImportPath: z3.string().default("@latticexyz/store/src/"),
|
|
881
|
-
tables: zTablesConfig,
|
|
882
|
-
userTypesPath: z3.string().default("Types")
|
|
883
|
-
}).merge(zEnumsConfig);
|
|
884
|
-
var zStoreConfig = StoreConfigUnrefined.superRefine(validateStoreConfig);
|
|
885
|
-
function parseStoreConfig(config) {
|
|
886
|
-
return zStoreConfig.parse(config);
|
|
887
|
-
}
|
|
888
|
-
function validateStoreConfig(config, ctx) {
|
|
889
|
-
for (const table of Object.values(config.tables)) {
|
|
890
|
-
const primaryKeyNames = Object.keys(table.primaryKeys);
|
|
891
|
-
const fieldNames = Object.keys(table.schema);
|
|
892
|
-
const duplicateVariableNames = getDuplicates([...primaryKeyNames, ...fieldNames]);
|
|
893
|
-
if (duplicateVariableNames.length > 0) {
|
|
894
|
-
ctx.addIssue({
|
|
895
|
-
code: ZodIssueCode3.custom,
|
|
896
|
-
message: `Field and primary key names within one table must be unique: ${duplicateVariableNames.join(", ")}`
|
|
897
|
-
});
|
|
898
|
-
}
|
|
899
|
-
}
|
|
900
|
-
const tableNames = Object.keys(config.tables);
|
|
901
|
-
const staticUserTypeNames = Object.keys(config.enums);
|
|
902
|
-
const userTypeNames = staticUserTypeNames;
|
|
903
|
-
const globalNames = [...tableNames, ...userTypeNames];
|
|
904
|
-
const duplicateGlobalNames = getDuplicates(globalNames);
|
|
905
|
-
if (duplicateGlobalNames.length > 0) {
|
|
906
|
-
ctx.addIssue({
|
|
907
|
-
code: ZodIssueCode3.custom,
|
|
908
|
-
message: `Table, enum names must be globally unique: ${duplicateGlobalNames.join(", ")}`
|
|
909
|
-
});
|
|
910
|
-
}
|
|
911
|
-
for (const table of Object.values(config.tables)) {
|
|
912
|
-
for (const primaryKeyType of Object.values(table.primaryKeys)) {
|
|
913
|
-
validateStaticAbiOrUserType(staticUserTypeNames, primaryKeyType, ctx);
|
|
914
|
-
}
|
|
915
|
-
for (const fieldType of Object.values(table.schema)) {
|
|
916
|
-
validateAbiOrUserType(userTypeNames, staticUserTypeNames, fieldType, ctx);
|
|
917
|
-
}
|
|
568
|
+
// src/render-solidity/userType.ts
|
|
569
|
+
import { parseStaticArray } from "@latticexyz/config";
|
|
570
|
+
function resolveAbiOrUserType(abiOrUserType, config) {
|
|
571
|
+
if (abiOrUserType in AbiTypeToSchemaType) {
|
|
572
|
+
const schemaType = AbiTypeToSchemaType[abiOrUserType];
|
|
573
|
+
return {
|
|
574
|
+
schemaType,
|
|
575
|
+
renderTableType: getSchemaTypeInfo(schemaType)
|
|
576
|
+
};
|
|
918
577
|
}
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
if (staticArray) {
|
|
924
|
-
validateStaticArray(staticUserTypeNames, staticArray.elementType, staticArray.staticLength, ctx);
|
|
578
|
+
const staticArray = parseStaticArray(abiOrUserType);
|
|
579
|
+
if (staticArray) {
|
|
580
|
+
if (staticArray.elementType in AbiTypeToSchemaType) {
|
|
581
|
+
return getStaticArrayTypeInfo(abiOrUserType, staticArray.elementType, staticArray.staticLength);
|
|
925
582
|
} else {
|
|
926
|
-
|
|
927
|
-
code: ZodIssueCode3.custom,
|
|
928
|
-
message: `${type} is not a valid abi type, and is not defined in userTypes`
|
|
929
|
-
});
|
|
583
|
+
throw new Error("Static arrays of user types are not supported");
|
|
930
584
|
}
|
|
931
585
|
}
|
|
586
|
+
return getUserTypeInfo(abiOrUserType, config);
|
|
932
587
|
}
|
|
933
|
-
function
|
|
934
|
-
if (
|
|
935
|
-
|
|
936
|
-
code: ZodIssueCode3.custom,
|
|
937
|
-
message: `${type} is not a static type`
|
|
938
|
-
});
|
|
588
|
+
function importForAbiOrUserType(abiOrUserType, usedInDirectory, config) {
|
|
589
|
+
if (abiOrUserType in AbiTypeToSchemaType) {
|
|
590
|
+
return void 0;
|
|
939
591
|
}
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
if (staticLength === 0) {
|
|
944
|
-
ctx.addIssue({
|
|
945
|
-
code: ZodIssueCode3.custom,
|
|
946
|
-
message: `Static array length must not be 0`
|
|
947
|
-
});
|
|
948
|
-
} else if (staticLength >= 2 ** 16) {
|
|
949
|
-
ctx.addIssue({
|
|
950
|
-
code: ZodIssueCode3.custom,
|
|
951
|
-
message: `Static array length must be less than 2**16`
|
|
952
|
-
});
|
|
592
|
+
const staticArray = parseStaticArray(abiOrUserType);
|
|
593
|
+
if (staticArray) {
|
|
594
|
+
return void 0;
|
|
953
595
|
}
|
|
954
|
-
}
|
|
955
|
-
|
|
956
|
-
// src/config/loadStoreConfig.ts
|
|
957
|
-
async function loadStoreConfig(configPath) {
|
|
958
|
-
const config = await loadConfig(configPath);
|
|
959
|
-
try {
|
|
960
|
-
return parseStoreConfig(config);
|
|
961
|
-
} catch (error) {
|
|
962
|
-
if (error instanceof ZodError2) {
|
|
963
|
-
throw fromZodErrorCustom(error, "StoreConfig Validation Error");
|
|
964
|
-
} else {
|
|
965
|
-
throw error;
|
|
966
|
-
}
|
|
967
|
-
}
|
|
968
|
-
}
|
|
969
|
-
|
|
970
|
-
// src/config/world/loadWorldConfig.ts
|
|
971
|
-
import { ZodError as ZodError3 } from "zod";
|
|
972
|
-
|
|
973
|
-
// src/config/world/parseWorldConfig.ts
|
|
974
|
-
import { z as z4 } from "zod";
|
|
975
|
-
|
|
976
|
-
// src/config/dynamicResolution.ts
|
|
977
|
-
var DynamicResolutionType = /* @__PURE__ */ ((DynamicResolutionType2) => {
|
|
978
|
-
DynamicResolutionType2[DynamicResolutionType2["TABLE_ID"] = 0] = "TABLE_ID";
|
|
979
|
-
DynamicResolutionType2[DynamicResolutionType2["SYSTEM_ADDRESS"] = 1] = "SYSTEM_ADDRESS";
|
|
980
|
-
return DynamicResolutionType2;
|
|
981
|
-
})(DynamicResolutionType || {});
|
|
982
|
-
function resolveTableId(tableName) {
|
|
983
596
|
return {
|
|
984
|
-
|
|
985
|
-
|
|
597
|
+
symbol: abiOrUserType,
|
|
598
|
+
fromPath: config.userTypesPath + ".sol",
|
|
599
|
+
usedInPath: usedInDirectory
|
|
986
600
|
};
|
|
987
601
|
}
|
|
988
|
-
function
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
}
|
|
1003
|
-
return resolved;
|
|
1004
|
-
}
|
|
1005
|
-
|
|
1006
|
-
// src/config/world/parseWorldConfig.ts
|
|
1007
|
-
var zSystemName = zObjectName;
|
|
1008
|
-
var zModuleName = zObjectName;
|
|
1009
|
-
var zSystemAccessList = z4.array(zSystemName.or(zEthereumAddress)).default([]);
|
|
1010
|
-
var zSystemConfig = z4.intersection(
|
|
1011
|
-
z4.object({
|
|
1012
|
-
fileSelector: zSelector,
|
|
1013
|
-
registerFunctionSelectors: z4.boolean().default(true)
|
|
1014
|
-
}),
|
|
1015
|
-
z4.discriminatedUnion("openAccess", [
|
|
1016
|
-
z4.object({
|
|
1017
|
-
openAccess: z4.literal(true)
|
|
1018
|
-
}),
|
|
1019
|
-
z4.object({
|
|
1020
|
-
openAccess: z4.literal(false),
|
|
1021
|
-
accessList: zSystemAccessList
|
|
1022
|
-
})
|
|
1023
|
-
])
|
|
1024
|
-
);
|
|
1025
|
-
var zValueWithType = z4.object({
|
|
1026
|
-
value: z4.union([z4.string(), z4.number(), z4.instanceof(Uint8Array)]),
|
|
1027
|
-
type: z4.string()
|
|
1028
|
-
});
|
|
1029
|
-
var zDynamicResolution = z4.object({ type: z4.nativeEnum(DynamicResolutionType), input: z4.string() });
|
|
1030
|
-
var zModuleConfig = z4.object({
|
|
1031
|
-
name: zModuleName,
|
|
1032
|
-
root: z4.boolean().default(false),
|
|
1033
|
-
args: z4.array(z4.union([zValueWithType, zDynamicResolution])).default([])
|
|
1034
|
-
});
|
|
1035
|
-
var zWorldConfig = z4.object({
|
|
1036
|
-
namespace: zSelector.default(""),
|
|
1037
|
-
worldContractName: z4.string().optional(),
|
|
1038
|
-
overrideSystems: z4.record(zSystemName, zSystemConfig).default({}),
|
|
1039
|
-
excludeSystems: z4.array(zSystemName).default([]),
|
|
1040
|
-
postDeployScript: z4.string().default("PostDeploy"),
|
|
1041
|
-
deploysDirectory: z4.string().default("./deploys"),
|
|
1042
|
-
worldgenDirectory: z4.string().default("world"),
|
|
1043
|
-
worldImportPath: z4.string().default("@latticexyz/world/src/"),
|
|
1044
|
-
modules: z4.array(zModuleConfig).default([])
|
|
1045
|
-
});
|
|
1046
|
-
async function parseWorldConfig(config) {
|
|
1047
|
-
return zWorldConfig.parse(config);
|
|
602
|
+
function getSchemaTypeInfo(schemaType) {
|
|
603
|
+
const staticByteLength = getStaticByteLength(schemaType);
|
|
604
|
+
const isDynamic = staticByteLength === 0;
|
|
605
|
+
const typeId = SchemaTypeToAbiType[schemaType];
|
|
606
|
+
return {
|
|
607
|
+
typeId,
|
|
608
|
+
typeWithLocation: isDynamic ? typeId + " memory" : typeId,
|
|
609
|
+
enumName: SchemaType[schemaType],
|
|
610
|
+
staticByteLength,
|
|
611
|
+
isDynamic,
|
|
612
|
+
typeWrap: "",
|
|
613
|
+
typeUnwrap: "",
|
|
614
|
+
internalTypeId: typeId
|
|
615
|
+
};
|
|
1048
616
|
}
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
for (const systemName of overriddenSystemNames) {
|
|
1056
|
-
if (!existingContracts.includes(systemName) || systemName === "World") {
|
|
1057
|
-
throw UnrecognizedSystemErrorFactory(["overrideSystems", systemName], systemName);
|
|
1058
|
-
}
|
|
1059
|
-
}
|
|
1060
|
-
}
|
|
1061
|
-
const systemNames = [.../* @__PURE__ */ new Set([...defaultSystemNames, ...overriddenSystemNames])].filter(
|
|
1062
|
-
(name) => !config.excludeSystems.includes(name)
|
|
1063
|
-
);
|
|
1064
|
-
const resolvedSystems = systemNames.reduce((acc, systemName) => {
|
|
617
|
+
function getUserTypeInfo(userType, config) {
|
|
618
|
+
if (userType in config.enums) {
|
|
619
|
+
const schemaType = 0 /* UINT8 */;
|
|
620
|
+
const staticByteLength = getStaticByteLength(schemaType);
|
|
621
|
+
const isDynamic = staticByteLength === 0;
|
|
622
|
+
const typeId = userType;
|
|
1065
623
|
return {
|
|
1066
|
-
|
|
1067
|
-
|
|
624
|
+
schemaType,
|
|
625
|
+
renderTableType: {
|
|
626
|
+
typeId,
|
|
627
|
+
typeWithLocation: typeId,
|
|
628
|
+
enumName: SchemaType[schemaType],
|
|
629
|
+
staticByteLength,
|
|
630
|
+
isDynamic,
|
|
631
|
+
typeWrap: `${userType}`,
|
|
632
|
+
typeUnwrap: `uint8`,
|
|
633
|
+
internalTypeId: `${SchemaTypeToAbiType[schemaType]}`
|
|
634
|
+
}
|
|
1068
635
|
};
|
|
1069
|
-
}
|
|
1070
|
-
|
|
1071
|
-
return { ...otherConfig, systems: resolvedSystems };
|
|
636
|
+
}
|
|
637
|
+
throw new Error(`User type "${userType}" does not exist`);
|
|
1072
638
|
}
|
|
1073
|
-
function
|
|
1074
|
-
const
|
|
1075
|
-
const
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
639
|
+
function getStaticArrayTypeInfo(abiType, elementType, staticLength) {
|
|
640
|
+
const internalTypeId = elementType + "[]";
|
|
641
|
+
const schemaType = AbiTypeToSchemaType[internalTypeId];
|
|
642
|
+
return {
|
|
643
|
+
schemaType,
|
|
644
|
+
renderTableType: {
|
|
645
|
+
typeId: abiType,
|
|
646
|
+
typeWithLocation: `${abiType} memory`,
|
|
647
|
+
enumName: SchemaType[schemaType],
|
|
648
|
+
staticByteLength: 0,
|
|
649
|
+
isDynamic: true,
|
|
650
|
+
typeWrap: `toStaticArray_${elementType}_${staticLength}`,
|
|
651
|
+
typeUnwrap: `fromStaticArray_${elementType}_${staticLength}`,
|
|
652
|
+
typeWrappingData: {
|
|
653
|
+
kind: "staticArray",
|
|
654
|
+
elementType,
|
|
655
|
+
staticLength
|
|
656
|
+
},
|
|
657
|
+
internalTypeId
|
|
1088
658
|
}
|
|
1089
|
-
}
|
|
1090
|
-
return { fileSelector, registerFunctionSelectors, openAccess, accessListAddresses, accessListSystems };
|
|
659
|
+
};
|
|
1091
660
|
}
|
|
1092
661
|
|
|
1093
|
-
// src/
|
|
1094
|
-
|
|
1095
|
-
|
|
662
|
+
// src/utils/format.ts
|
|
663
|
+
import chalk from "chalk";
|
|
664
|
+
import prettier from "prettier";
|
|
665
|
+
import prettierPluginSolidity from "prettier-plugin-solidity";
|
|
666
|
+
async function formatSolidity(content, prettierConfigPath) {
|
|
667
|
+
let config;
|
|
668
|
+
if (prettierConfigPath) {
|
|
669
|
+
config = await prettier.resolveConfig(prettierConfigPath);
|
|
670
|
+
}
|
|
1096
671
|
try {
|
|
1097
|
-
|
|
1098
|
-
|
|
672
|
+
return prettier.format(content, {
|
|
673
|
+
plugins: [prettierPluginSolidity],
|
|
674
|
+
parser: "solidity-parse",
|
|
675
|
+
printWidth: 120,
|
|
676
|
+
semi: true,
|
|
677
|
+
tabWidth: 2,
|
|
678
|
+
useTabs: false,
|
|
679
|
+
bracketSpacing: true,
|
|
680
|
+
...config
|
|
681
|
+
});
|
|
1099
682
|
} catch (error) {
|
|
1100
|
-
|
|
1101
|
-
|
|
683
|
+
let message;
|
|
684
|
+
if (error instanceof Error) {
|
|
685
|
+
message = error.message;
|
|
1102
686
|
} else {
|
|
1103
|
-
|
|
687
|
+
message = error;
|
|
1104
688
|
}
|
|
689
|
+
console.log(chalk.yellow(`Error during output formatting: ${message}`));
|
|
690
|
+
return content;
|
|
1105
691
|
}
|
|
1106
692
|
}
|
|
693
|
+
async function formatTypescript(content) {
|
|
694
|
+
return prettier.format(content, {
|
|
695
|
+
parser: "typescript"
|
|
696
|
+
});
|
|
697
|
+
}
|
|
1107
698
|
|
|
1108
|
-
// src/
|
|
1109
|
-
|
|
1110
|
-
|
|
699
|
+
// src/utils/formatAndWrite.ts
|
|
700
|
+
import { mkdirSync, writeFileSync } from "fs";
|
|
701
|
+
import { dirname } from "path";
|
|
702
|
+
async function formatAndWriteSolidity(output, fullOutputPath, logPrefix) {
|
|
703
|
+
const formattedOutput = await formatSolidity(output);
|
|
704
|
+
mkdirSync(dirname(fullOutputPath), { recursive: true });
|
|
705
|
+
writeFileSync(fullOutputPath, formattedOutput);
|
|
706
|
+
console.log(`${logPrefix}: ${fullOutputPath}`);
|
|
707
|
+
}
|
|
708
|
+
async function formatAndWriteTypescript(output, fullOutputPath, logPrefix) {
|
|
709
|
+
const formattedOutput = await formatTypescript(output);
|
|
710
|
+
mkdirSync(dirname(fullOutputPath), { recursive: true });
|
|
711
|
+
writeFileSync(fullOutputPath, formattedOutput);
|
|
712
|
+
console.log(`${logPrefix}: ${fullOutputPath}`);
|
|
1111
713
|
}
|
|
1112
714
|
|
|
1113
715
|
export {
|
|
1114
|
-
fromZodErrorCustom,
|
|
1115
|
-
NotInsideProjectError,
|
|
1116
|
-
NotESMConfigError,
|
|
1117
|
-
MUDError,
|
|
1118
|
-
UnrecognizedSystemErrorFactory,
|
|
1119
|
-
logError,
|
|
1120
|
-
loadConfig,
|
|
1121
|
-
SchemaType,
|
|
1122
|
-
getStaticByteLength,
|
|
1123
716
|
encodeSchema,
|
|
1124
717
|
SchemaTypeArrayToElement,
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
validateSingleLevelRoute,
|
|
1134
|
-
validateEthereumAddress,
|
|
1135
|
-
getDuplicates,
|
|
1136
|
-
validateSelector,
|
|
1137
|
-
parseStaticArray,
|
|
1138
|
-
zObjectName,
|
|
1139
|
-
zValueName,
|
|
1140
|
-
zAnyCaseName,
|
|
1141
|
-
zUserEnum,
|
|
1142
|
-
zOrdinaryRoute,
|
|
1143
|
-
zSingleLevelRoute,
|
|
1144
|
-
zBaseRoute,
|
|
1145
|
-
zEthereumAddress,
|
|
1146
|
-
zSelector,
|
|
1147
|
-
zSchemaConfig,
|
|
1148
|
-
zTableConfig,
|
|
1149
|
-
zTablesConfig,
|
|
1150
|
-
zEnumsConfig,
|
|
1151
|
-
storeConfig,
|
|
1152
|
-
zStoreConfig,
|
|
1153
|
-
parseStoreConfig,
|
|
1154
|
-
loadStoreConfig,
|
|
1155
|
-
DynamicResolutionType,
|
|
1156
|
-
resolveTableId,
|
|
1157
|
-
isDynamicResolution,
|
|
1158
|
-
resolveWithContext,
|
|
1159
|
-
zWorldConfig,
|
|
1160
|
-
parseWorldConfig,
|
|
1161
|
-
resolveWorldConfig,
|
|
1162
|
-
resolveSystemConfig,
|
|
1163
|
-
loadWorldConfig,
|
|
1164
|
-
mudConfig
|
|
718
|
+
resolveAbiOrUserType,
|
|
719
|
+
importForAbiOrUserType,
|
|
720
|
+
getSchemaTypeInfo,
|
|
721
|
+
getUserTypeInfo,
|
|
722
|
+
formatSolidity,
|
|
723
|
+
formatTypescript,
|
|
724
|
+
formatAndWriteSolidity,
|
|
725
|
+
formatAndWriteTypescript
|
|
1165
726
|
};
|