@latticexyz/cli 2.0.0-alpha.78 → 2.0.0-alpha.80
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-TLEAEDUA.js → chunk-6OEU4O7P.js} +36 -36
- package/dist/{chunk-DO7OWTMM.js → chunk-K25KS5QJ.js} +2 -4
- package/dist/{chunk-TPZUS44H.js → chunk-SADK4UCO.js} +1 -1
- package/dist/{chunk-KPBNUPK6.js → chunk-SKNB74MT.js} +155 -159
- package/dist/{chunk-XUNWAEP7.js → chunk-YNVRICE5.js} +59 -36
- package/dist/index.d.ts +2 -4
- package/dist/index.js +0 -22
- package/dist/mud.js +5 -7
- package/dist/mud2.js +5 -7
- package/dist/render-solidity/index.d.ts +1 -2
- package/dist/render-solidity/index.js +2 -3
- package/dist/render-ts/index.d.ts +1 -2
- package/dist/render-ts/index.js +2 -3
- package/dist/utils/index.d.ts +2 -15
- package/dist/utils/index.js +3 -14
- package/package.json +12 -14
- package/src/commands/deploy-v2.ts +3 -3
- package/src/commands/set-version.ts +3 -2
- package/src/commands/tablegen.ts +1 -1
- package/src/commands/tsgen.ts +1 -1
- package/src/commands/worldgen.ts +1 -2
- package/src/index.ts +1 -15
- package/src/render-solidity/renderTypesFromConfig.ts +1 -1
- package/src/render-solidity/tableOptions.ts +1 -1
- package/src/render-solidity/tablegen.ts +1 -1
- package/src/render-solidity/userType.ts +1 -2
- package/src/render-solidity/worldgen.ts +1 -1
- package/src/render-ts/recsV1TableOptions.ts +1 -1
- package/src/render-ts/tsgen.ts +1 -1
- package/src/utils/contractToInterface.ts +1 -1
- package/src/utils/deploy-v2.ts +2 -2
- package/src/utils/errors.ts +3 -23
- package/dist/chunk-5NC2OON2.js +0 -164
- package/dist/chunk-MN3HYFJK.js +0 -442
- package/dist/config/index.d.ts +0 -409
- package/dist/config/index.js +0 -85
- package/dist/parseStoreConfig-8aa69ac9.d.ts +0 -377
- 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 -40
- package/src/config/loadStoreConfig.ts +0 -18
- package/src/config/parseStoreConfig.test-d.ts +0 -40
- package/src/config/parseStoreConfig.ts +0 -317
- 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 -56
- package/src/config/world/resolveWorldConfig.ts +0 -80
- package/src/config/world/userTypes.ts +0 -74
- package/src/utils/typeUtils.ts +0 -17
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
-
deploy
|
|
3
|
-
} from "./chunk-XUNWAEP7.js";
|
|
4
|
-
import {
|
|
5
|
-
MUDError,
|
|
6
|
-
loadStoreConfig,
|
|
7
|
-
loadWorldConfig,
|
|
2
|
+
deploy,
|
|
8
3
|
logError
|
|
9
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-YNVRICE5.js";
|
|
10
5
|
import {
|
|
11
6
|
execLog
|
|
12
7
|
} from "./chunk-FFY7VTYB.js";
|
|
@@ -22,13 +17,13 @@ import {
|
|
|
22
17
|
renderList,
|
|
23
18
|
renderedSolidityHeader,
|
|
24
19
|
tablegen
|
|
25
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-K25KS5QJ.js";
|
|
26
21
|
import {
|
|
27
22
|
tsgen
|
|
28
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-SADK4UCO.js";
|
|
29
24
|
import {
|
|
30
25
|
formatAndWriteSolidity
|
|
31
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-SKNB74MT.js";
|
|
32
27
|
import {
|
|
33
28
|
__commonJS,
|
|
34
29
|
__toESM
|
|
@@ -3091,6 +3086,7 @@ var hello_default = commandModule4;
|
|
|
3091
3086
|
|
|
3092
3087
|
// src/commands/tablegen.ts
|
|
3093
3088
|
import path2 from "path";
|
|
3089
|
+
import { loadStoreConfig } from "@latticexyz/config";
|
|
3094
3090
|
var commandModule5 = {
|
|
3095
3091
|
command: "tablegen",
|
|
3096
3092
|
describe: "Autogenerate MUD Store table libraries based on the config file",
|
|
@@ -3109,6 +3105,7 @@ var commandModule5 = {
|
|
|
3109
3105
|
var tablegen_default = commandModule5;
|
|
3110
3106
|
|
|
3111
3107
|
// src/commands/tsgen.ts
|
|
3108
|
+
import { loadStoreConfig as loadStoreConfig2 } from "@latticexyz/config";
|
|
3112
3109
|
var commandModule6 = {
|
|
3113
3110
|
command: "tsgen",
|
|
3114
3111
|
describe: "Autogenerate MUD typescript definitions based on the config file",
|
|
@@ -3120,7 +3117,7 @@ var commandModule6 = {
|
|
|
3120
3117
|
},
|
|
3121
3118
|
async handler(args) {
|
|
3122
3119
|
const { configPath, out } = args;
|
|
3123
|
-
const config = await
|
|
3120
|
+
const config = await loadStoreConfig2(configPath);
|
|
3124
3121
|
await tsgen(config, out);
|
|
3125
3122
|
process.exit(0);
|
|
3126
3123
|
}
|
|
@@ -3131,6 +3128,8 @@ var tsgen_default = commandModule6;
|
|
|
3131
3128
|
import chalk3 from "chalk";
|
|
3132
3129
|
import glob from "glob";
|
|
3133
3130
|
import path3, { basename } from "path";
|
|
3131
|
+
import { loadStoreConfig as loadStoreConfig3, loadWorldConfig } from "@latticexyz/config";
|
|
3132
|
+
import { MUDError } from "@latticexyz/config";
|
|
3134
3133
|
import { mkdirSync, writeFileSync as writeFileSync2 } from "fs";
|
|
3135
3134
|
|
|
3136
3135
|
// src/utils/getChainId.ts
|
|
@@ -3175,7 +3174,7 @@ async function deployHandler(args) {
|
|
|
3175
3174
|
const srcDir = await getSrcDirectory();
|
|
3176
3175
|
const existingContracts = glob.sync(`${srcDir}/**/*.sol`).map((path7) => basename(path7, ".sol"));
|
|
3177
3176
|
const worldConfig = await loadWorldConfig(configPath, existingContracts);
|
|
3178
|
-
const storeConfig = await
|
|
3177
|
+
const storeConfig = await loadStoreConfig3(configPath);
|
|
3179
3178
|
const mudConfig = { ...worldConfig, ...storeConfig };
|
|
3180
3179
|
if (printConfig)
|
|
3181
3180
|
console.log(chalk3.green("\nResolved config:\n"), JSON.stringify(mudConfig, null, 2));
|
|
@@ -3215,6 +3214,7 @@ var commandModule7 = {
|
|
|
3215
3214
|
var deploy_v2_default = commandModule7;
|
|
3216
3215
|
|
|
3217
3216
|
// src/commands/worldgen.ts
|
|
3217
|
+
import { loadStoreConfig as loadStoreConfig4, loadWorldConfig as loadWorldConfig2 } from "@latticexyz/config";
|
|
3218
3218
|
import glob2 from "glob";
|
|
3219
3219
|
import path5, { basename as basename2 } from "path";
|
|
3220
3220
|
|
|
@@ -3224,6 +3224,7 @@ import path4 from "path";
|
|
|
3224
3224
|
|
|
3225
3225
|
// src/utils/contractToInterface.ts
|
|
3226
3226
|
import { parse, visit } from "@solidity-parser/parser";
|
|
3227
|
+
import { MUDError as MUDError2 } from "@latticexyz/config";
|
|
3227
3228
|
function contractToInterface(data, contractName) {
|
|
3228
3229
|
const ast = parse(data);
|
|
3229
3230
|
let withContract = false;
|
|
@@ -3241,7 +3242,7 @@ function contractToInterface(data, contractName) {
|
|
|
3241
3242
|
if (isConstructor || isFallback || isReceiveEther)
|
|
3242
3243
|
return;
|
|
3243
3244
|
if (visibility === "default")
|
|
3244
|
-
throw new
|
|
3245
|
+
throw new MUDError2(`Visibility is not specified`);
|
|
3245
3246
|
if (visibility === "external" || visibility === "public") {
|
|
3246
3247
|
functions.push({
|
|
3247
3248
|
name: name === null ? "" : name,
|
|
@@ -3254,7 +3255,7 @@ function contractToInterface(data, contractName) {
|
|
|
3254
3255
|
}
|
|
3255
3256
|
}
|
|
3256
3257
|
} catch (error) {
|
|
3257
|
-
if (error instanceof
|
|
3258
|
+
if (error instanceof MUDError2) {
|
|
3258
3259
|
error.message = `Function "${name}" in contract "${contractName}": ${error.message}`;
|
|
3259
3260
|
}
|
|
3260
3261
|
throw error;
|
|
@@ -3263,7 +3264,7 @@ function contractToInterface(data, contractName) {
|
|
|
3263
3264
|
}
|
|
3264
3265
|
});
|
|
3265
3266
|
if (!withContract) {
|
|
3266
|
-
throw new
|
|
3267
|
+
throw new MUDError2(`Contract not found: ${contractName}`);
|
|
3267
3268
|
}
|
|
3268
3269
|
return {
|
|
3269
3270
|
functions,
|
|
@@ -3310,7 +3311,7 @@ function flattenTypeName(typeName) {
|
|
|
3310
3311
|
stateMutability
|
|
3311
3312
|
};
|
|
3312
3313
|
} else {
|
|
3313
|
-
throw new
|
|
3314
|
+
throw new MUDError2(`Invalid typeName.type ${typeName.type}`);
|
|
3314
3315
|
}
|
|
3315
3316
|
}
|
|
3316
3317
|
function typeNameToExternalSymbols(typeName) {
|
|
@@ -3431,11 +3432,11 @@ var commandModule8 = {
|
|
|
3431
3432
|
path: path7,
|
|
3432
3433
|
basename: basename2(path7, ".sol")
|
|
3433
3434
|
}));
|
|
3434
|
-
const worldConfig = await
|
|
3435
|
+
const worldConfig = await loadWorldConfig2(
|
|
3435
3436
|
configPath,
|
|
3436
3437
|
existingContracts.map(({ basename: basename3 }) => basename3)
|
|
3437
3438
|
);
|
|
3438
|
-
const storeConfig = await
|
|
3439
|
+
const storeConfig = await loadStoreConfig4(configPath);
|
|
3439
3440
|
const mudConfig = { ...worldConfig, ...storeConfig };
|
|
3440
3441
|
const outputBaseDirectory = path5.join(srcDir, mudConfig.codegenDirectory);
|
|
3441
3442
|
if (clean)
|
|
@@ -3450,11 +3451,12 @@ var worldgen_default = commandModule8;
|
|
|
3450
3451
|
import chalk4 from "chalk";
|
|
3451
3452
|
import { existsSync, readFileSync as readFileSync3, rmSync as rmSync4, writeFileSync as writeFileSync3 } from "fs";
|
|
3452
3453
|
import path6 from "path";
|
|
3454
|
+
import { MUDError as MUDError3 } from "@latticexyz/config";
|
|
3453
3455
|
|
|
3454
3456
|
// package.json
|
|
3455
3457
|
var package_default = {
|
|
3456
3458
|
name: "@latticexyz/cli",
|
|
3457
|
-
version: "2.0.0-alpha.
|
|
3459
|
+
version: "2.0.0-alpha.80+3eb8b70a",
|
|
3458
3460
|
description: "Command line interface for mud",
|
|
3459
3461
|
main: "dist/index.js",
|
|
3460
3462
|
types: "dist/index.d.ts",
|
|
@@ -3471,33 +3473,34 @@ var package_default = {
|
|
|
3471
3473
|
},
|
|
3472
3474
|
scripts: {
|
|
3473
3475
|
prepare: "yarn build",
|
|
3474
|
-
codegen: "
|
|
3476
|
+
codegen: "tsx ./scripts/codegen.ts",
|
|
3475
3477
|
lint: "eslint . --ext .ts",
|
|
3476
3478
|
dev: "tsup --watch",
|
|
3477
3479
|
build: "tsup",
|
|
3478
3480
|
link: "yarn link",
|
|
3479
|
-
test: "
|
|
3481
|
+
test: "tsc --noEmit && yarn test:contracts",
|
|
3480
3482
|
"test:contracts": "yarn codegen && forge test",
|
|
3481
3483
|
release: "npm publish --access=public"
|
|
3482
3484
|
},
|
|
3483
3485
|
devDependencies: {
|
|
3484
|
-
"@latticexyz/store": "^2.0.0-alpha.
|
|
3486
|
+
"@latticexyz/store": "^2.0.0-alpha.80+3eb8b70a",
|
|
3485
3487
|
"@types/ejs": "^3.1.1",
|
|
3486
3488
|
"@types/glob": "^7.2.0",
|
|
3487
3489
|
"@types/node": "^17.0.34",
|
|
3488
3490
|
"@types/openurl": "^1.0.0",
|
|
3489
3491
|
"@types/yargs": "^17.0.10",
|
|
3490
|
-
esbuild: "^0.15.16",
|
|
3491
3492
|
tsup: "^6.6.3",
|
|
3493
|
+
tsx: "^3.12.6",
|
|
3492
3494
|
vitest: "^0.29.8"
|
|
3493
3495
|
},
|
|
3494
3496
|
dependencies: {
|
|
3495
3497
|
"@improbable-eng/grpc-web": "^0.15.0",
|
|
3496
3498
|
"@improbable-eng/grpc-web-node-http-transport": "^0.15.0",
|
|
3497
|
-
"@latticexyz/
|
|
3498
|
-
"@latticexyz/
|
|
3499
|
-
"@latticexyz/
|
|
3500
|
-
"@latticexyz/
|
|
3499
|
+
"@latticexyz/config": "^2.0.0-alpha.80+3eb8b70a",
|
|
3500
|
+
"@latticexyz/schema-type": "^2.0.0-alpha.80+3eb8b70a",
|
|
3501
|
+
"@latticexyz/services": "^2.0.0-alpha.80+3eb8b70a",
|
|
3502
|
+
"@latticexyz/solecs": "^2.0.0-alpha.80+3eb8b70a",
|
|
3503
|
+
"@latticexyz/std-contracts": "^2.0.0-alpha.80+3eb8b70a",
|
|
3501
3504
|
"@solidity-parser/parser": "^0.16.0",
|
|
3502
3505
|
"@typechain/ethers-v5": "^10.1.1",
|
|
3503
3506
|
chalk: "^5.0.1",
|
|
@@ -3505,10 +3508,8 @@ var package_default = {
|
|
|
3505
3508
|
dotenv: "^16.0.3",
|
|
3506
3509
|
"ds-test": "https://github.com/dapphub/ds-test.git#c9ce3f25bde29fc5eb9901842bf02850dfd2d084",
|
|
3507
3510
|
ejs: "^3.1.8",
|
|
3508
|
-
esbuild: "^0.17.14",
|
|
3509
3511
|
ethers: "^5.7.2",
|
|
3510
3512
|
execa: "^7.0.0",
|
|
3511
|
-
"find-up": "^6.3.0",
|
|
3512
3513
|
"forge-std": "https://github.com/foundry-rs/forge-std.git#b4f121555729b3afb3c5ffccb62ff4b6e2818fd3",
|
|
3513
3514
|
glob: "^8.0.3",
|
|
3514
3515
|
"nice-grpc-web": "^2.0.1",
|
|
@@ -3517,14 +3518,13 @@ var package_default = {
|
|
|
3517
3518
|
prettier: "^2.8.4",
|
|
3518
3519
|
"prettier-plugin-solidity": "^1.1.2",
|
|
3519
3520
|
table: "^6.8.1",
|
|
3520
|
-
"ts-node": "^10.9.1",
|
|
3521
3521
|
typechain: "^8.1.1",
|
|
3522
3522
|
typescript: "^4.9.5",
|
|
3523
3523
|
yargs: "^17.7.1",
|
|
3524
3524
|
zod: "^3.21.4",
|
|
3525
|
-
"zod-validation-error": "^1.0
|
|
3525
|
+
"zod-validation-error": "^1.3.0"
|
|
3526
3526
|
},
|
|
3527
|
-
gitHead: "
|
|
3527
|
+
gitHead: "3eb8b70a5f324f9b2fc98ecaf9c85fe8a9108dbd"
|
|
3528
3528
|
};
|
|
3529
3529
|
|
|
3530
3530
|
// src/commands/set-version.ts
|
|
@@ -3547,7 +3547,7 @@ var commandModule9 = {
|
|
|
3547
3547
|
async handler(options) {
|
|
3548
3548
|
try {
|
|
3549
3549
|
if (!options.mudVersion && !options.restore) {
|
|
3550
|
-
throw new
|
|
3550
|
+
throw new MUDError3(`Version parameter is required unless --restore is provided.`);
|
|
3551
3551
|
}
|
|
3552
3552
|
options.mudVersion = options.mudVersion === "canary" ? await getCanaryVersion(package_default.name) : options.mudVersion;
|
|
3553
3553
|
const rootPath = "./package.json";
|
|
@@ -3569,7 +3569,7 @@ function updatePackageJson(filePath, options) {
|
|
|
3569
3569
|
const { backup, restore, force, mudVersion } = options;
|
|
3570
3570
|
const backupFilePath = path6.join(path6.dirname(filePath), BACKUP_FILE);
|
|
3571
3571
|
if (backup && !force && existsSync(backupFilePath)) {
|
|
3572
|
-
throw new
|
|
3572
|
+
throw new MUDError3(
|
|
3573
3573
|
`A backup file already exists at ${backupFilePath}.
|
|
3574
3574
|
Use --force to overwrite it or --restore to restore it.`
|
|
3575
3575
|
);
|
|
@@ -3620,7 +3620,7 @@ function readPackageJson(path7) {
|
|
|
3620
3620
|
const jsonString = readFileSync3(path7, "utf8");
|
|
3621
3621
|
return JSON.parse(jsonString);
|
|
3622
3622
|
} catch {
|
|
3623
|
-
throw new
|
|
3623
|
+
throw new MUDError3("Could not read JSON at " + path7);
|
|
3624
3624
|
}
|
|
3625
3625
|
}
|
|
3626
3626
|
async function getCanaryVersion(pkg) {
|
|
@@ -3631,7 +3631,7 @@ async function getCanaryVersion(pkg) {
|
|
|
3631
3631
|
console.log(chalk4.green("MUD canary version:", canary));
|
|
3632
3632
|
return canary;
|
|
3633
3633
|
} catch (e) {
|
|
3634
|
-
throw new
|
|
3634
|
+
throw new MUDError3(`Could not fetch canary version of ${pkg}`);
|
|
3635
3635
|
}
|
|
3636
3636
|
}
|
|
3637
3637
|
function logComparison(prev, curr) {
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
|
+
SchemaTypeArrayToElement,
|
|
2
3
|
formatAndWriteSolidity,
|
|
3
4
|
getSchemaTypeInfo,
|
|
4
5
|
importForAbiOrUserType,
|
|
5
6
|
resolveAbiOrUserType
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import {
|
|
8
|
-
SchemaTypeArrayToElement
|
|
9
|
-
} from "./chunk-KPBNUPK6.js";
|
|
7
|
+
} from "./chunk-SKNB74MT.js";
|
|
10
8
|
|
|
11
9
|
// src/render-solidity/tableOptions.ts
|
|
12
10
|
import path from "path";
|
|
@@ -1,145 +1,3 @@
|
|
|
1
|
-
// src/config/validation.ts
|
|
2
|
-
import { ethers } from "ethers";
|
|
3
|
-
import { ZodIssueCode } from "zod";
|
|
4
|
-
function validateName(name, ctx) {
|
|
5
|
-
if (!/^\w+$/.test(name)) {
|
|
6
|
-
ctx.addIssue({
|
|
7
|
-
code: ZodIssueCode.custom,
|
|
8
|
-
message: `Name must contain only alphanumeric & underscore characters`
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
function validateCapitalizedName(name, ctx) {
|
|
13
|
-
validateName(name, ctx);
|
|
14
|
-
if (!/^[A-Z]/.test(name)) {
|
|
15
|
-
ctx.addIssue({
|
|
16
|
-
code: ZodIssueCode.custom,
|
|
17
|
-
message: `Name must start with a capital letter`
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
function validateUncapitalizedName(name, ctx) {
|
|
22
|
-
validateName(name, ctx);
|
|
23
|
-
if (!/^[a-z]/.test(name)) {
|
|
24
|
-
ctx.addIssue({
|
|
25
|
-
code: ZodIssueCode.custom,
|
|
26
|
-
message: `Name must start with a lowercase letter`
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
function validateEnum(members, ctx) {
|
|
31
|
-
if (members.length === 0) {
|
|
32
|
-
ctx.addIssue({
|
|
33
|
-
code: ZodIssueCode.custom,
|
|
34
|
-
message: `Enum must not be empty`
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
if (members.length >= 256) {
|
|
38
|
-
ctx.addIssue({
|
|
39
|
-
code: ZodIssueCode.custom,
|
|
40
|
-
message: `Length of enum must be < 256`
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
const duplicates = getDuplicates(members);
|
|
44
|
-
if (duplicates.length > 0) {
|
|
45
|
-
ctx.addIssue({
|
|
46
|
-
code: ZodIssueCode.custom,
|
|
47
|
-
message: `Enum must not have duplicate names for: ${duplicates.join(", ")}`
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
function _factoryForValidateRoute(requireNonEmpty, requireSingleLevel) {
|
|
52
|
-
return (route, ctx) => {
|
|
53
|
-
if (route === "") {
|
|
54
|
-
if (requireNonEmpty) {
|
|
55
|
-
ctx.addIssue({
|
|
56
|
-
code: ZodIssueCode.custom,
|
|
57
|
-
message: `Route must not be empty`
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
if (route[0] !== "/") {
|
|
63
|
-
ctx.addIssue({
|
|
64
|
-
code: ZodIssueCode.custom,
|
|
65
|
-
message: `Route must start with "/"`
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
if (route[route.length - 1] === "/") {
|
|
69
|
-
ctx.addIssue({
|
|
70
|
-
code: ZodIssueCode.custom,
|
|
71
|
-
message: `Route must not end with "/"`
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
const parts = route.split("/");
|
|
75
|
-
if (requireSingleLevel && parts.length > 2) {
|
|
76
|
-
ctx.addIssue({
|
|
77
|
-
code: ZodIssueCode.custom,
|
|
78
|
-
message: `Route must only have one level (e.g. "/foo")`
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
for (let i = 1; i < parts.length; i++) {
|
|
82
|
-
if (parts[i] === "") {
|
|
83
|
-
ctx.addIssue({
|
|
84
|
-
code: ZodIssueCode.custom,
|
|
85
|
-
message: `Route must not contain empty route fragments (e.g. "//")`
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
if (!/^\w+$/.test(parts[i])) {
|
|
89
|
-
ctx.addIssue({
|
|
90
|
-
code: ZodIssueCode.custom,
|
|
91
|
-
message: `Route must contain only alphanumeric & underscore characters`
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
var validateRoute = _factoryForValidateRoute(true, false);
|
|
98
|
-
var validateBaseRoute = _factoryForValidateRoute(false, false);
|
|
99
|
-
var validateSingleLevelRoute = _factoryForValidateRoute(true, true);
|
|
100
|
-
function validateEthereumAddress(address, ctx) {
|
|
101
|
-
if (!ethers.utils.isAddress(address)) {
|
|
102
|
-
ctx.addIssue({
|
|
103
|
-
code: ZodIssueCode.custom,
|
|
104
|
-
message: `Address must be a valid Ethereum address`
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
function getDuplicates(array) {
|
|
109
|
-
const checked = /* @__PURE__ */ new Set();
|
|
110
|
-
const duplicates = /* @__PURE__ */ new Set();
|
|
111
|
-
for (const element of array) {
|
|
112
|
-
if (checked.has(element)) {
|
|
113
|
-
duplicates.add(element);
|
|
114
|
-
}
|
|
115
|
-
checked.add(element);
|
|
116
|
-
}
|
|
117
|
-
return [...duplicates];
|
|
118
|
-
}
|
|
119
|
-
function validateSelector(name, ctx) {
|
|
120
|
-
if (name.length > 16) {
|
|
121
|
-
ctx.addIssue({
|
|
122
|
-
code: ZodIssueCode.custom,
|
|
123
|
-
message: `Selector must be <= 16 characters`
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
if (!/^\w*$/.test(name)) {
|
|
127
|
-
ctx.addIssue({
|
|
128
|
-
code: ZodIssueCode.custom,
|
|
129
|
-
message: `Selector must contain only alphanumeric & underscore characters`
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
function parseStaticArray(abiType) {
|
|
134
|
-
const matches = abiType.match(/^(\w+)\[(\d+)\]$/);
|
|
135
|
-
if (!matches)
|
|
136
|
-
return null;
|
|
137
|
-
return {
|
|
138
|
-
elementType: matches[1],
|
|
139
|
-
staticLength: Number.parseInt(matches[2])
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
|
|
143
1
|
// ../schema-type/src/typescript/SchemaType.ts
|
|
144
2
|
var SchemaType = /* @__PURE__ */ ((SchemaType2) => {
|
|
145
3
|
SchemaType2[SchemaType2["UINT8"] = 0] = "UINT8";
|
|
@@ -707,24 +565,162 @@ var StaticAbiTypes = AbiTypes.filter(
|
|
|
707
565
|
(abiType) => getStaticByteLength(AbiTypeToSchemaType[abiType]) > 0
|
|
708
566
|
);
|
|
709
567
|
|
|
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
|
+
};
|
|
577
|
+
}
|
|
578
|
+
const staticArray = parseStaticArray(abiOrUserType);
|
|
579
|
+
if (staticArray) {
|
|
580
|
+
if (staticArray.elementType in AbiTypeToSchemaType) {
|
|
581
|
+
return getStaticArrayTypeInfo(abiOrUserType, staticArray.elementType, staticArray.staticLength);
|
|
582
|
+
} else {
|
|
583
|
+
throw new Error("Static arrays of user types are not supported");
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
return getUserTypeInfo(abiOrUserType, config);
|
|
587
|
+
}
|
|
588
|
+
function importForAbiOrUserType(abiOrUserType, usedInDirectory, config) {
|
|
589
|
+
if (abiOrUserType in AbiTypeToSchemaType) {
|
|
590
|
+
return void 0;
|
|
591
|
+
}
|
|
592
|
+
const staticArray = parseStaticArray(abiOrUserType);
|
|
593
|
+
if (staticArray) {
|
|
594
|
+
return void 0;
|
|
595
|
+
}
|
|
596
|
+
return {
|
|
597
|
+
symbol: abiOrUserType,
|
|
598
|
+
fromPath: config.userTypesPath + ".sol",
|
|
599
|
+
usedInPath: usedInDirectory
|
|
600
|
+
};
|
|
601
|
+
}
|
|
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
|
+
};
|
|
616
|
+
}
|
|
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;
|
|
623
|
+
return {
|
|
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
|
+
}
|
|
635
|
+
};
|
|
636
|
+
}
|
|
637
|
+
throw new Error(`User type "${userType}" does not exist`);
|
|
638
|
+
}
|
|
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
|
|
658
|
+
}
|
|
659
|
+
};
|
|
660
|
+
}
|
|
661
|
+
|
|
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
|
+
}
|
|
671
|
+
try {
|
|
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
|
+
});
|
|
682
|
+
} catch (error) {
|
|
683
|
+
let message;
|
|
684
|
+
if (error instanceof Error) {
|
|
685
|
+
message = error.message;
|
|
686
|
+
} else {
|
|
687
|
+
message = error;
|
|
688
|
+
}
|
|
689
|
+
console.log(chalk.yellow(`Error during output formatting: ${message}`));
|
|
690
|
+
return content;
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
async function formatTypescript(content) {
|
|
694
|
+
return prettier.format(content, {
|
|
695
|
+
parser: "typescript"
|
|
696
|
+
});
|
|
697
|
+
}
|
|
698
|
+
|
|
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}`);
|
|
713
|
+
}
|
|
714
|
+
|
|
710
715
|
export {
|
|
711
|
-
SchemaType,
|
|
712
|
-
getStaticByteLength,
|
|
713
716
|
encodeSchema,
|
|
714
717
|
SchemaTypeArrayToElement,
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
validateRoute,
|
|
724
|
-
validateBaseRoute,
|
|
725
|
-
validateSingleLevelRoute,
|
|
726
|
-
validateEthereumAddress,
|
|
727
|
-
getDuplicates,
|
|
728
|
-
validateSelector,
|
|
729
|
-
parseStaticArray
|
|
718
|
+
resolveAbiOrUserType,
|
|
719
|
+
importForAbiOrUserType,
|
|
720
|
+
getSchemaTypeInfo,
|
|
721
|
+
getUserTypeInfo,
|
|
722
|
+
formatSolidity,
|
|
723
|
+
formatTypescript,
|
|
724
|
+
formatAndWriteSolidity,
|
|
725
|
+
formatAndWriteTypescript
|
|
730
726
|
};
|