@latticexyz/cli 1.40.0 → 1.41.1-alpha.0
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/LICENSE +21 -0
- package/dist/chunk-ATAWDHWC.js +67 -0
- package/dist/{chunk-6AQ6LFVZ.js → chunk-J4DJQNIC.js} +743 -103
- package/dist/chunk-KD354QKC.js +23039 -0
- package/dist/{chunk-S3V3XX7N.js → chunk-SLIMIO4Z.js} +1 -1
- package/dist/config/index.d.ts +746 -8
- package/dist/config/index.js +63 -17
- package/dist/index.d.ts +1 -2
- package/dist/index.js +14 -10
- package/dist/mud.js +1055 -49
- package/dist/utils/deprecated/index.js +2 -2
- package/dist/utils/index.d.ts +56 -7
- package/dist/utils/index.js +17 -3
- package/package.json +16 -11
- package/src/commands/deploy-v2.ts +96 -0
- package/src/commands/deprecated/call-system.ts +1 -1
- package/src/commands/deprecated/deploy-contracts.ts +1 -1
- package/src/commands/deprecated/test.ts +9 -6
- package/src/commands/deprecated/trace.ts +1 -1
- package/src/commands/gas-report.ts +1 -1
- package/src/commands/index.ts +4 -0
- package/src/commands/tablegen.ts +4 -18
- package/src/commands/worldgen.ts +55 -0
- package/src/config/commonSchemas.ts +19 -5
- package/src/config/dynamicResolution.ts +49 -0
- package/src/config/index.ts +20 -0
- package/src/config/loadStoreConfig.ts +3 -89
- package/src/config/parseStoreConfig.test-d.ts +40 -0
- package/src/config/parseStoreConfig.ts +314 -0
- package/src/config/validation.ts +71 -0
- package/src/config/world/index.ts +4 -0
- package/src/config/world/loadWorldConfig.test-d.ts +11 -0
- package/src/config/world/loadWorldConfig.ts +26 -0
- package/src/config/world/parseWorldConfig.ts +55 -0
- package/src/config/world/resolveWorldConfig.ts +80 -0
- package/src/config/world/userTypes.ts +72 -0
- package/src/index.ts +13 -5
- package/src/mud.ts +4 -0
- package/src/render-solidity/common.ts +138 -0
- package/src/render-solidity/field.ts +137 -0
- package/src/render-solidity/index.ts +10 -0
- package/src/render-solidity/record.ts +154 -0
- package/src/render-solidity/renderSystemInterface.ts +31 -0
- package/src/render-solidity/renderTable.ts +164 -0
- package/src/render-solidity/renderTypeHelpers.ts +99 -0
- package/src/render-solidity/renderTypes.ts +19 -0
- package/src/render-solidity/renderTypesFromConfig.ts +13 -0
- package/src/render-solidity/renderWorld.ts +24 -0
- package/src/{render-table/renderTablesFromConfig.ts → render-solidity/tableOptions.ts} +45 -37
- package/src/render-solidity/tablegen.ts +33 -0
- package/src/render-solidity/types.ts +110 -0
- package/src/render-solidity/userType.ts +132 -0
- package/src/render-solidity/worldgen.ts +60 -0
- package/src/utils/contractToInterface.ts +130 -0
- package/src/utils/deploy-v2.ts +512 -0
- package/src/utils/deprecated/build.ts +1 -1
- package/src/utils/deprecated/typegen.ts +1 -1
- package/src/utils/errors.ts +12 -2
- package/src/utils/execLog.ts +22 -0
- package/src/utils/formatAndWrite.ts +12 -0
- package/src/utils/foundry.ts +94 -0
- package/src/utils/getChainId.ts +10 -0
- package/src/utils/index.ts +2 -1
- package/src/utils/typeUtils.ts +17 -0
- package/dist/chunk-B6VWCGHZ.js +0 -199
- package/dist/chunk-JKAA3WMC.js +0 -55
- package/dist/chunk-JNGSW4AP.js +0 -493
- package/dist/chunk-PJ6GS2R4.js +0 -22
- package/dist/chunk-UC3QPOON.js +0 -35
- package/dist/loadStoreConfig-37f99136.d.ts +0 -164
- package/dist/render-table/index.d.ts +0 -29
- package/dist/render-table/index.js +0 -24
- package/dist/renderTable-9e6410c5.d.ts +0 -72
- package/src/config/loadStoreConfig.test-d.ts +0 -11
- package/src/render-table/common.ts +0 -67
- package/src/render-table/field.ts +0 -132
- package/src/render-table/index.ts +0 -6
- package/src/render-table/record.ts +0 -176
- package/src/render-table/renderTable.ts +0 -109
- package/src/render-table/types.ts +0 -51
- package/src/utils/forgeConfig.ts +0 -45
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { renderArguments, renderCommonData, renderList } from "./common.js";
|
|
2
|
-
import { renderFieldMethods } from "./field.js";
|
|
3
|
-
import { renderRecordMethods } from "./record.js";
|
|
4
|
-
import { RenderTableOptions } from "./types.js";
|
|
5
|
-
|
|
6
|
-
export function renderTable(options: RenderTableOptions) {
|
|
7
|
-
const { libraryName, structName, staticRouteData, storeImportPath, fields, withRecordMethods } = options;
|
|
8
|
-
|
|
9
|
-
const { _typedTableId, _typedKeyArgs, _primaryKeysDefinition } = renderCommonData(options);
|
|
10
|
-
|
|
11
|
-
return `// SPDX-License-Identifier: MIT
|
|
12
|
-
pragma solidity >=0.8.0;
|
|
13
|
-
|
|
14
|
-
/* Autogenerated file. Do not edit manually. */
|
|
15
|
-
|
|
16
|
-
import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol";
|
|
17
|
-
|
|
18
|
-
import { IStore } from "${storeImportPath}IStore.sol";
|
|
19
|
-
import { StoreSwitch } from "${storeImportPath}StoreSwitch.sol";
|
|
20
|
-
import { StoreCore } from "${storeImportPath}StoreCore.sol";
|
|
21
|
-
import { Bytes } from "${storeImportPath}Bytes.sol";
|
|
22
|
-
import { SliceLib } from "${storeImportPath}Slice.sol";
|
|
23
|
-
import { EncodeArray } from "${storeImportPath}tightcoder/EncodeArray.sol";
|
|
24
|
-
import { Schema, SchemaLib } from "${storeImportPath}Schema.sol";
|
|
25
|
-
import { PackedCounter, PackedCounterLib } from "${storeImportPath}PackedCounter.sol";
|
|
26
|
-
|
|
27
|
-
${
|
|
28
|
-
!staticRouteData
|
|
29
|
-
? ""
|
|
30
|
-
: `
|
|
31
|
-
uint256 constant _tableId = uint256(keccak256("${staticRouteData.baseRoute + staticRouteData.subRoute}"));
|
|
32
|
-
uint256 constant ${staticRouteData.tableIdName} = _tableId;
|
|
33
|
-
`
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
${
|
|
37
|
-
!structName
|
|
38
|
-
? ""
|
|
39
|
-
: `
|
|
40
|
-
struct ${structName} {
|
|
41
|
-
${renderList(fields, ({ name, typeId }) => `${typeId} ${name};`)}
|
|
42
|
-
}
|
|
43
|
-
`
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
library ${libraryName} {
|
|
47
|
-
/** Get the table's schema */
|
|
48
|
-
function getSchema() internal pure returns (Schema) {
|
|
49
|
-
SchemaType[] memory _schema = new SchemaType[](${fields.length});
|
|
50
|
-
${renderList(fields, ({ enumName }, index) => `_schema[${index}] = SchemaType.${enumName};`)}
|
|
51
|
-
|
|
52
|
-
return SchemaLib.encode(_schema);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/** Register the table's schema */
|
|
56
|
-
function registerSchema(${_typedTableId}) internal {
|
|
57
|
-
StoreSwitch.registerSchema(_tableId, getSchema());
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
${
|
|
61
|
-
!options.storeArgument
|
|
62
|
-
? ""
|
|
63
|
-
: `
|
|
64
|
-
/** Register the table's schema for the specified store */
|
|
65
|
-
function registerSchema(${renderArguments([_typedTableId, "IStore _store"])}) internal {
|
|
66
|
-
_store.registerSchema(_tableId, getSchema());
|
|
67
|
-
}
|
|
68
|
-
`
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
${renderFieldMethods(options)}
|
|
72
|
-
|
|
73
|
-
${withRecordMethods ? renderRecordMethods(options) : ""}
|
|
74
|
-
|
|
75
|
-
/* Delete all data for given keys */
|
|
76
|
-
function deleteRecord(${renderArguments([_typedTableId, _typedKeyArgs])}) internal {
|
|
77
|
-
${_primaryKeysDefinition}
|
|
78
|
-
StoreSwitch.deleteRecord(_tableId, _primaryKeys);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
${
|
|
83
|
-
// nothing can be cast to bool, so an assembly helper is required
|
|
84
|
-
!fields.some(({ typeId }) => typeId === "bool")
|
|
85
|
-
? ""
|
|
86
|
-
: `
|
|
87
|
-
function _toBool(uint8 value) pure returns (bool result) {
|
|
88
|
-
assembly {
|
|
89
|
-
result := value
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
`
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
${
|
|
96
|
-
// nothing can be cast from bool, so an assembly helper is required
|
|
97
|
-
!options.primaryKeys.some(({ typeId }) => typeId === "bool")
|
|
98
|
-
? ""
|
|
99
|
-
: `
|
|
100
|
-
function _boolToBytes32(bool value) pure returns (bytes32 result) {
|
|
101
|
-
assembly {
|
|
102
|
-
result := value
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
`
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
`;
|
|
109
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
export interface RenderTableOptions {
|
|
2
|
-
/** Name of the library to render. */
|
|
3
|
-
libraryName: string;
|
|
4
|
-
/** Name of the struct to render. If undefined, struct and its methods aren't rendered. */
|
|
5
|
-
structName?: string;
|
|
6
|
-
/** Data used to statically registed the table. If undefined, all methods receive `_tableId` as an argument. */
|
|
7
|
-
staticRouteData?: StaticRouteData;
|
|
8
|
-
storeImportPath: string;
|
|
9
|
-
primaryKeys: RenderTablePrimaryKey[];
|
|
10
|
-
fields: RenderTableField[];
|
|
11
|
-
staticFields: RenderTableStaticField[];
|
|
12
|
-
dynamicFields: RenderTableDynamicField[];
|
|
13
|
-
/** Whether to render get/set methods for the whole record */
|
|
14
|
-
withRecordMethods: boolean;
|
|
15
|
-
/** Whether to render additional methods that accept a manual `IStore` argument */
|
|
16
|
-
storeArgument: boolean;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface StaticRouteData {
|
|
20
|
-
/** Name of the table id constant to render. */
|
|
21
|
-
tableIdName: string;
|
|
22
|
-
baseRoute: string;
|
|
23
|
-
subRoute: string;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface RenderTableType {
|
|
27
|
-
typeId: string;
|
|
28
|
-
typeWithLocation: string;
|
|
29
|
-
enumName: string;
|
|
30
|
-
staticByteLength: number;
|
|
31
|
-
isDynamic: boolean;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export interface RenderTablePrimaryKey extends RenderTableType {
|
|
35
|
-
name: string;
|
|
36
|
-
isDynamic: false;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export interface RenderTableStaticField extends RenderTableField {
|
|
40
|
-
isDynamic: false;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export interface RenderTableDynamicField extends RenderTableField {
|
|
44
|
-
isDynamic: true;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export interface RenderTableField extends RenderTableType {
|
|
48
|
-
arrayElement: RenderTableType | undefined;
|
|
49
|
-
name: string;
|
|
50
|
-
methodNameSuffix: string;
|
|
51
|
-
}
|
package/src/utils/forgeConfig.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { execa } from "execa";
|
|
2
|
-
|
|
3
|
-
export interface ForgeConfig {
|
|
4
|
-
// project
|
|
5
|
-
src: string;
|
|
6
|
-
test: string;
|
|
7
|
-
out: string;
|
|
8
|
-
libs: string[];
|
|
9
|
-
|
|
10
|
-
// all unspecified keys (this interface is far from comprehensive)
|
|
11
|
-
[key: string]: unknown;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Get forge config as a parsed json object.
|
|
16
|
-
*/
|
|
17
|
-
export async function getForgeConfig() {
|
|
18
|
-
const { stdout } = await execa("forge", ["config", "--json"], { stdio: ["inherit", "pipe", "pipe"] });
|
|
19
|
-
|
|
20
|
-
return JSON.parse(stdout) as ForgeConfig;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Get the value of "src" from forge config.
|
|
25
|
-
* The path to the contract sources relative to the root of the project.
|
|
26
|
-
*/
|
|
27
|
-
export async function getSrcDirectory() {
|
|
28
|
-
return (await getForgeConfig()).src;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Get the value of "test" from forge config.
|
|
33
|
-
* The path to the test contract sources relative to the root of the project.
|
|
34
|
-
*/
|
|
35
|
-
export async function getTestDirectory() {
|
|
36
|
-
return (await getForgeConfig()).test;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Get the value of "out" from forge config.
|
|
41
|
-
* The path to put contract artifacts in, relative to the root of the project.
|
|
42
|
-
*/
|
|
43
|
-
export async function getOutDirectory() {
|
|
44
|
-
return (await getForgeConfig()).out;
|
|
45
|
-
}
|