@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.
Files changed (82) hide show
  1. package/dist/chunk-6V563IAZ.js +283 -0
  2. package/dist/{chunk-ATAWDHWC.js → chunk-FPG73MVN.js} +5 -1
  3. package/dist/{chunk-O6HOO6WA.js → chunk-L4YLJHLJ.js} +1 -9
  4. package/dist/{chunk-J4DJQNIC.js → chunk-SKNB74MT.js} +129 -568
  5. package/dist/chunk-VQTZJIFF.js +353 -0
  6. package/dist/chunk-WZFXLDPK.js +761 -0
  7. package/dist/chunk-YL4GJLLL.js +26139 -0
  8. package/dist/chunk-ZSZDPSLH.js +3841 -0
  9. package/dist/index.d.ts +2 -3
  10. package/dist/index.js +0 -21
  11. package/dist/mud.d.ts +1 -1
  12. package/dist/mud.js +326 -4452
  13. package/dist/mud2.d.ts +1 -0
  14. package/dist/mud2.js +25 -0
  15. package/dist/render-solidity/index.d.ts +171 -0
  16. package/dist/render-solidity/index.js +49 -0
  17. package/dist/render-ts/index.d.ts +26 -0
  18. package/dist/render-ts/index.js +14 -0
  19. package/dist/utils/deprecated/index.js +3 -3
  20. package/dist/utils/index.d.ts +13 -18
  21. package/dist/utils/index.js +14 -16
  22. package/package.json +20 -21
  23. package/src/commands/deploy-v2.ts +80 -64
  24. package/src/commands/deprecated/index.ts +22 -0
  25. package/src/commands/deprecated/test.ts +1 -1
  26. package/src/commands/gas-report.ts +54 -55
  27. package/src/commands/index.ts +6 -17
  28. package/src/commands/set-version.ts +172 -0
  29. package/src/commands/tablegen.ts +5 -5
  30. package/src/commands/test-v2.ts +71 -0
  31. package/src/commands/tsgen.ts +33 -0
  32. package/src/commands/worldgen.ts +5 -4
  33. package/src/contracts/BulkUpload.sol +13 -20
  34. package/src/contracts/Deploy.sol +3 -3
  35. package/src/contracts/LibDeploy.sol +1 -1
  36. package/src/contracts/LibDeployStub.sol +1 -1
  37. package/src/index.ts +1 -15
  38. package/src/mud.ts +4 -3
  39. package/src/mud2.ts +29 -0
  40. package/src/render-solidity/common.ts +4 -4
  41. package/src/render-solidity/field.ts +25 -2
  42. package/src/render-solidity/record.ts +14 -10
  43. package/src/render-solidity/renderSystemInterface.ts +4 -4
  44. package/src/render-solidity/renderTableIndex.ts +15 -0
  45. package/src/render-solidity/renderTypesFromConfig.ts +1 -1
  46. package/src/render-solidity/tableOptions.ts +2 -2
  47. package/src/render-solidity/tablegen.ts +15 -13
  48. package/src/render-solidity/types.ts +2 -1
  49. package/src/render-solidity/userType.ts +1 -2
  50. package/src/render-solidity/worldgen.ts +8 -9
  51. package/src/render-ts/index.ts +5 -0
  52. package/src/render-ts/recsV1TableOptions.ts +39 -0
  53. package/src/render-ts/renderRecsV1Tables.ts +31 -0
  54. package/src/render-ts/schemaTypesToRecsTypeStrings.ts +202 -0
  55. package/src/render-ts/tsgen.ts +12 -0
  56. package/src/render-ts/types.ts +13 -0
  57. package/src/utils/contractToInterface.ts +5 -3
  58. package/src/utils/deploy-v2.ts +90 -84
  59. package/src/utils/errors.ts +3 -34
  60. package/src/utils/format.ts +6 -0
  61. package/src/utils/formatAndWrite.ts +11 -2
  62. package/src/utils/foundry.ts +9 -0
  63. package/src/utils/index.ts +1 -0
  64. package/dist/chunk-O57QENJ6.js +0 -23039
  65. package/dist/chunk-SLIMIO4Z.js +0 -14358
  66. package/dist/config/index.d.ts +0 -763
  67. package/dist/config/index.js +0 -83
  68. package/src/config/commonSchemas.ts +0 -34
  69. package/src/config/dynamicResolution.ts +0 -49
  70. package/src/config/index.ts +0 -24
  71. package/src/config/loadConfig.ts +0 -39
  72. package/src/config/loadStoreConfig.ts +0 -18
  73. package/src/config/parseStoreConfig.test-d.ts +0 -40
  74. package/src/config/parseStoreConfig.ts +0 -314
  75. package/src/config/validation.ts +0 -163
  76. package/src/config/world/index.ts +0 -4
  77. package/src/config/world/loadWorldConfig.test-d.ts +0 -11
  78. package/src/config/world/loadWorldConfig.ts +0 -26
  79. package/src/config/world/parseWorldConfig.ts +0 -55
  80. package/src/config/world/resolveWorldConfig.ts +0 -80
  81. package/src/config/world/userTypes.ts +0 -72
  82. 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/config/parseStoreConfig.ts
825
- import { z as z3, ZodIssueCode as ZodIssueCode3 } from "zod";
826
- var zTableName = zObjectName;
827
- var zKeyName = zValueName;
828
- var zColumnName = zValueName;
829
- var zUserEnumName = zObjectName;
830
- var zFieldData = z3.string();
831
- var zPrimaryKey = z3.string();
832
- var zPrimaryKeys = z3.record(zKeyName, zPrimaryKey).default({ key: "bytes32" });
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
- function validateAbiOrUserType(userTypeNames, staticUserTypeNames, type, ctx) {
921
- if (!AbiTypes.includes(type) && !userTypeNames.includes(type)) {
922
- const staticArray = parseStaticArray(type);
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
- ctx.addIssue({
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 validateStaticAbiOrUserType(staticUserTypeNames, type, ctx) {
934
- if (!StaticAbiTypes.includes(type) && !staticUserTypeNames.includes(type)) {
935
- ctx.addIssue({
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
- function validateStaticArray(staticUserTypeNames, elementType, staticLength, ctx) {
942
- validateStaticAbiOrUserType(staticUserTypeNames, elementType, ctx);
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
- type: 0 /* TABLE_ID */,
985
- input: tableName
597
+ symbol: abiOrUserType,
598
+ fromPath: config.userTypesPath + ".sol",
599
+ usedInPath: usedInDirectory
986
600
  };
987
601
  }
988
- function isDynamicResolution(value) {
989
- return typeof value === "object" && value !== null && "type" in value && "input" in value;
990
- }
991
- async function resolveWithContext(unresolved, context) {
992
- if (!isDynamicResolution(unresolved))
993
- return unresolved;
994
- let resolved = void 0;
995
- if (unresolved.type === 0 /* TABLE_ID */) {
996
- const tableId = context.tableIds?.[unresolved.input];
997
- resolved = tableId && { value: tableId, type: "bytes32" };
998
- }
999
- if (resolved === void 0) {
1000
- throw new MUDError(`Could not resolve dynamic resolution:
1001
- ${JSON.stringify(unresolved, null, 2)}`);
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
- // src/config/world/resolveWorldConfig.ts
1051
- function resolveWorldConfig(config, existingContracts) {
1052
- const defaultSystemNames = existingContracts?.filter((name) => name.endsWith("System") && name !== "System" && !name.match(/^I[A-Z]/)) ?? [];
1053
- const overriddenSystemNames = Object.keys(config.overrideSystems);
1054
- if (existingContracts) {
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
- ...acc,
1067
- [systemName]: resolveSystemConfig(systemName, config.overrideSystems[systemName], existingContracts)
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
- const { overrideSystems, excludeSystems, ...otherConfig } = config;
1071
- return { ...otherConfig, systems: resolvedSystems };
636
+ }
637
+ throw new Error(`User type "${userType}" does not exist`);
1072
638
  }
1073
- function resolveSystemConfig(systemName, config, existingContracts) {
1074
- const fileSelector = config?.fileSelector ?? systemName;
1075
- const registerFunctionSelectors = config?.registerFunctionSelectors ?? true;
1076
- const openAccess = config?.openAccess ?? true;
1077
- const accessListAddresses = [];
1078
- const accessListSystems = [];
1079
- const accessList = config && !config.openAccess ? config.accessList : [];
1080
- for (const accessListItem of accessList) {
1081
- if (accessListItem.startsWith("0x")) {
1082
- accessListAddresses.push(accessListItem);
1083
- } else {
1084
- if (existingContracts && !existingContracts.includes(accessListItem)) {
1085
- throw UnrecognizedSystemErrorFactory(["overrideSystems", systemName, "accessList"], accessListItem);
1086
- }
1087
- accessListSystems.push(accessListItem);
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/config/world/loadWorldConfig.ts
1094
- async function loadWorldConfig(configPath, existingContracts) {
1095
- const config = await loadConfig(configPath);
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
- const parsedConfig = zWorldConfig.parse(config);
1098
- return resolveWorldConfig(parsedConfig, existingContracts);
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
- if (error instanceof ZodError3) {
1101
- throw fromZodErrorCustom(error, "WorldConfig Validation Error");
683
+ let message;
684
+ if (error instanceof Error) {
685
+ message = error.message;
1102
686
  } else {
1103
- throw error;
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/config/index.ts
1109
- function mudConfig(config) {
1110
- return config;
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
- SchemaTypeToAbiType,
1126
- AbiTypeToSchemaType,
1127
- validateName,
1128
- validateCapitalizedName,
1129
- validateUncapitalizedName,
1130
- validateEnum,
1131
- validateRoute,
1132
- validateBaseRoute,
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
  };