@latticexyz/world 2.0.0-alpha.1.43 → 2.0.0-alpha.1.44
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-EOSNM56M.js +28 -0
- package/dist/chunk-EOSNM56M.js.map +1 -0
- package/dist/chunk-WABR4LFG.js +2 -0
- package/dist/chunk-WABR4LFG.js.map +1 -0
- package/dist/mud.config.js +1 -1
- package/dist/mud.config.js.map +1 -1
- package/dist/ts/library/index.js +2 -0
- package/dist/ts/library/index.js.map +1 -0
- package/dist/ts/register/index.js +2 -0
- package/dist/ts/register/index.js.map +1 -0
- package/package.json +23 -10
- package/ts/library/config/index.ts +3 -0
- package/ts/library/config/resolveWorldConfig.ts +78 -0
- package/ts/library/config/types.ts +74 -0
- package/ts/library/config/worldConfig.test-d.ts +12 -0
- package/ts/library/config/worldConfig.ts +52 -0
- package/ts/{index.ts → library/index.ts} +1 -0
- package/ts/{render-solidity → library/render-solidity}/worldgen.ts +10 -4
- package/ts/register/configExtensions.ts +18 -0
- package/ts/register/index.ts +10 -0
- package/ts/register/typeExtensions.ts +17 -0
- package/ts/scripts/tablegen.ts +3 -3
- package/ts/scripts/worldgen.ts +4 -8
- package/dist/ts/index.js +0 -28
- package/dist/ts/index.js.map +0 -1
- /package/ts/{render-solidity → library/render-solidity}/index.ts +0 -0
- /package/ts/{render-solidity → library/render-solidity}/renderSystemInterface.ts +0 -0
- /package/ts/{render-solidity → library/render-solidity}/renderWorld.ts +0 -0
- /package/ts/{render-solidity → library/render-solidity}/types.ts +0 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import{UnrecognizedSystemErrorFactory as y}from"@latticexyz/config";function S(t,o){let m=o?.filter(r=>r.endsWith("System")&&r!=="System"&&!r.match(/^I[A-Z]/))??[],n=Object.keys(t.overrideSystems);if(o){for(let r of n)if(!o.includes(r)||r==="World")throw y(["overrideSystems",r],r)}return{systems:[...new Set([...m,...n])].filter(r=>!t.excludeSystems.includes(r)).reduce((r,a)=>({...r,[a]:z(a,t.overrideSystems[a],o)}),{})}}function z(t,o,m){let n=o?.name??t,i=o?.registerFunctionSelectors??!0,l=o?.openAccess??!0,r=[],a=[],c=o&&!o.openAccess?o.accessList:[];for(let s of c)if(s.startsWith("0x"))r.push(s);else{if(m&&!m.includes(s))throw y(["overrideSystems",t,"accessList"],s);a.push(s)}return{name:n,registerFunctionSelectors:i,openAccess:l,accessListAddresses:r,accessListSystems:a}}import{z as e}from"zod";import{DynamicResolutionType as j,zEthereumAddress as D,zObjectName as h,zSelector as I}from"@latticexyz/config";var u=h,N=h,L=e.array(u.or(D)).default([]),O=e.intersection(e.object({name:I,registerFunctionSelectors:e.boolean().default(!0)}),e.discriminatedUnion("openAccess",[e.object({openAccess:e.literal(!0)}),e.object({openAccess:e.literal(!1),accessList:L})])),T=e.object({value:e.union([e.string(),e.number(),e.instanceof(Uint8Array)]),type:e.string()}),F=e.object({type:e.nativeEnum(j),input:e.string()}),B=e.object({name:N,root:e.boolean().default(!1),args:e.array(e.union([T,F])).default([])}),E=e.object({namespace:I.default(""),worldContractName:e.string().optional(),worldInterfaceName:e.string().default("IWorld"),overrideSystems:e.record(u,O).default({}),excludeSystems:e.array(u).default([]),postDeployScript:e.string().default("PostDeploy"),deploysDirectory:e.string().default("./deploys"),worldgenDirectory:e.string().default("world"),worldImportPath:e.string().default("@latticexyz/world/src/"),modules:e.array(B).default([])}),ee=E.catchall(e.any());import{renderArguments as g,renderList as U,renderedSolidityHeader as k,renderImports as G}from"@latticexyz/common/codegen";function b(t){let{imports:o,name:m,functionPrefix:n,functions:i}=t;return`${k}
|
|
2
|
+
|
|
3
|
+
${G(o)}
|
|
4
|
+
|
|
5
|
+
interface ${m} {
|
|
6
|
+
${U(i,({name:l,parameters:r,stateMutability:a,returnParameters:c})=>`
|
|
7
|
+
function ${n}${l}(
|
|
8
|
+
${g(r)}
|
|
9
|
+
) external ${a} ${H(c)};
|
|
10
|
+
`)}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
`}function H(t){return t.length>0?`returns (${g(t)})`:""}import{renderArguments as K,renderedSolidityHeader as M,renderAbsoluteImports as _,renderRelativeImports as V}from"@latticexyz/common/codegen";function W(t){let{interfaceName:o,storeImportPath:m,worldImportPath:n,imports:i}=t,l=o==="IBaseWorld"?[{symbol:"IStore",path:`${m}IStore.sol`},{symbol:"IWorldKernel",path:`${n}interfaces/IWorldKernel.sol`}]:[{symbol:"IBaseWorld",path:`${n}interfaces/IBaseWorld.sol`}],r=[...l,...i].map(({symbol:a})=>a);return`${M}
|
|
14
|
+
|
|
15
|
+
${_(l)}
|
|
16
|
+
|
|
17
|
+
${V(i)}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The ${o} interface includes all systems dynamically added to the World
|
|
21
|
+
* during the deploy process.
|
|
22
|
+
*/
|
|
23
|
+
interface ${o} is ${K(r)} {
|
|
24
|
+
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
`}import{readFileSync as Z}from"fs";import p from"path";import{formatAndWriteSolidity as $,contractToInterface as q}from"@latticexyz/common/codegen";async function he(t,o,m){let n=S(t,o.map(({basename:s})=>s)),i=p.join(m,t.worldgenDirectory),l=o.filter(({basename:s})=>Object.keys(n.systems).includes(s)),r=[];for(let s of l){let v=Z(s.path,"utf8"),{functions:x,symbolImports:w}=q(v,s.basename),A=w.map(d=>d.path[0]==="."?{symbol:d.symbol,fromPath:p.join(p.dirname(s.path),d.path),usedInPath:i}:{symbol:d.symbol,path:d.path}),f=`I${s.basename}`,{name:C}=n.systems[s.basename],P=b({name:f,functionPrefix:t.namespace===""?"":`${t.namespace}_${C}_`,functions:x,imports:A}),R=p.join(i,f+".sol");await $(P,R,"Generated system interface"),r.push({symbol:f,fromPath:`${f}.sol`,usedInPath:"./"})}let a=W({interfaceName:t.worldInterfaceName,imports:r,storeImportPath:t.storeImportPath,worldImportPath:t.worldImportPath}),c=p.join(i,t.worldInterfaceName+".sol");await $(a,c,"Generated system interface")}export{S as a,z as b,E as c,ee as d,b as e,W as f,he as g};
|
|
28
|
+
//# sourceMappingURL=chunk-EOSNM56M.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../ts/library/config/resolveWorldConfig.ts","../ts/library/config/worldConfig.ts","../ts/library/render-solidity/renderSystemInterface.ts","../ts/library/render-solidity/renderWorld.ts","../ts/library/render-solidity/worldgen.ts"],"sourcesContent":["import { UnrecognizedSystemErrorFactory } from \"@latticexyz/config\";\nimport { SystemConfig, WorldConfig } from \"./types\";\n\nexport type ResolvedSystemConfig = ReturnType<typeof resolveSystemConfig>;\n\nexport type ResolvedWorldConfig = ReturnType<typeof resolveWorldConfig>;\n\n/**\n * Resolves the world config by combining the default and overridden system configs,\n * filtering out excluded systems, validate system names refer to existing contracts, and\n * splitting the access list into addresses and system names.\n */\nexport function resolveWorldConfig(config: WorldConfig, existingContracts?: string[]) {\n // Include contract names ending in \"System\", but not the base \"System\" contract, and not Interfaces\n const defaultSystemNames =\n existingContracts?.filter((name) => name.endsWith(\"System\") && name !== \"System\" && !name.match(/^I[A-Z]/)) ?? [];\n const overriddenSystemNames = Object.keys(config.overrideSystems);\n\n // Validate every key in overrideSystems refers to an existing system contract (and is not called \"World\")\n if (existingContracts) {\n for (const systemName of overriddenSystemNames) {\n if (!existingContracts.includes(systemName) || systemName === \"World\") {\n throw UnrecognizedSystemErrorFactory([\"overrideSystems\", systemName], systemName);\n }\n }\n }\n\n // Combine the default and overridden system names and filter out excluded systems\n const systemNames = [...new Set([...defaultSystemNames, ...overriddenSystemNames])].filter(\n (name) => !config.excludeSystems.includes(name)\n );\n\n // Resolve the config\n const resolvedSystems: Record<string, ResolvedSystemConfig> = systemNames.reduce((acc, systemName) => {\n return {\n ...acc,\n [systemName]: resolveSystemConfig(systemName, config.overrideSystems[systemName], existingContracts),\n };\n }, {});\n\n return { systems: resolvedSystems };\n}\n\n/**\n * Resolves the system config by combining the default and overridden system configs,\n * @param systemName name of the system\n * @param config optional SystemConfig object, if none is provided the default config is used\n * @param existingContracts optional list of existing contract names, used to validate system names in the access list. If not provided, no validation is performed.\n * @returns ResolvedSystemConfig object\n * Default value for name is `systemName`\n * Default value for registerFunctionSelectors is true\n * Default value for openAccess is true\n * Default value for accessListAddresses is []\n * Default value for accessListSystems is []\n */\nexport function resolveSystemConfig(systemName: string, config?: SystemConfig, existingContracts?: string[]) {\n const name = config?.name ?? systemName;\n const registerFunctionSelectors = config?.registerFunctionSelectors ?? true;\n const openAccess = config?.openAccess ?? true;\n const accessListAddresses: string[] = [];\n const accessListSystems: string[] = [];\n const accessList = config && !config.openAccess ? config.accessList : [];\n\n // Split the access list into addresses and system names\n for (const accessListItem of accessList) {\n if (accessListItem.startsWith(\"0x\")) {\n accessListAddresses.push(accessListItem);\n } else {\n // Validate every system refers to an existing system contract\n if (existingContracts && !existingContracts.includes(accessListItem)) {\n throw UnrecognizedSystemErrorFactory([\"overrideSystems\", systemName, \"accessList\"], accessListItem);\n }\n accessListSystems.push(accessListItem);\n }\n }\n\n return { name, registerFunctionSelectors, openAccess, accessListAddresses, accessListSystems };\n}\n","import { z } from \"zod\";\nimport { DynamicResolutionType, zEthereumAddress, zObjectName, zSelector } from \"@latticexyz/config\";\n\nconst zSystemName = zObjectName;\nconst zModuleName = zObjectName;\nconst zSystemAccessList = z.array(zSystemName.or(zEthereumAddress)).default([]);\n\n// The system config is a combination of a name config and access config\nconst zSystemConfig = z.intersection(\n z.object({\n name: zSelector,\n registerFunctionSelectors: z.boolean().default(true),\n }),\n z.discriminatedUnion(\"openAccess\", [\n z.object({\n openAccess: z.literal(true),\n }),\n z.object({\n openAccess: z.literal(false),\n accessList: zSystemAccessList,\n }),\n ])\n);\n\nconst zValueWithType = z.object({\n value: z.union([z.string(), z.number(), z.instanceof(Uint8Array)]),\n type: z.string(),\n});\nconst zDynamicResolution = z.object({ type: z.nativeEnum(DynamicResolutionType), input: z.string() });\n\nconst zModuleConfig = z.object({\n name: zModuleName,\n root: z.boolean().default(false),\n args: z.array(z.union([zValueWithType, zDynamicResolution])).default([]),\n});\n\n// The parsed world config is the result of parsing the user config\nexport const zWorldConfig = z.object({\n namespace: zSelector.default(\"\"),\n worldContractName: z.string().optional(),\n worldInterfaceName: z.string().default(\"IWorld\"),\n overrideSystems: z.record(zSystemName, zSystemConfig).default({}),\n excludeSystems: z.array(zSystemName).default([]),\n postDeployScript: z.string().default(\"PostDeploy\"),\n deploysDirectory: z.string().default(\"./deploys\"),\n worldgenDirectory: z.string().default(\"world\"),\n worldImportPath: z.string().default(\"@latticexyz/world/src/\"),\n modules: z.array(zModuleConfig).default([]),\n});\n\n// Catchall preserves other plugins' options\nexport const zPluginWorldConfig = zWorldConfig.catchall(z.any());\n","import { renderArguments, renderList, renderedSolidityHeader, renderImports } from \"@latticexyz/common/codegen\";\nimport { RenderSystemInterfaceOptions } from \"./types\";\n\nexport function renderSystemInterface(options: RenderSystemInterfaceOptions) {\n const { imports, name, functionPrefix, functions } = options;\n\n return `${renderedSolidityHeader}\n\n${renderImports(imports)}\n\ninterface ${name} {\n ${renderList(\n functions,\n ({ name, parameters, stateMutability, returnParameters }) => `\n function ${functionPrefix}${name}(\n ${renderArguments(parameters)}\n ) external ${stateMutability} ${renderReturnParameters(returnParameters)};\n `\n )}\n}\n\n`;\n}\n\nfunction renderReturnParameters(returnParameters: string[]) {\n if (returnParameters.length > 0) {\n return `returns (${renderArguments(returnParameters)})`;\n } else {\n return \"\";\n }\n}\n","import {\n renderArguments,\n renderedSolidityHeader,\n renderAbsoluteImports,\n renderRelativeImports,\n type AbsoluteImportDatum,\n} from \"@latticexyz/common/codegen\";\nimport type { RenderWorldOptions } from \"./types\";\n\nexport function renderWorld(options: RenderWorldOptions) {\n const { interfaceName, storeImportPath, worldImportPath, imports } = options;\n const baseImports: AbsoluteImportDatum[] =\n interfaceName === \"IBaseWorld\"\n ? [\n { symbol: \"IStore\", path: `${storeImportPath}IStore.sol` },\n { symbol: \"IWorldKernel\", path: `${worldImportPath}interfaces/IWorldKernel.sol` },\n ]\n : [\n {\n symbol: \"IBaseWorld\",\n path: `${worldImportPath}interfaces/IBaseWorld.sol`,\n },\n ];\n const importSymbols = [...baseImports, ...imports].map(({ symbol }) => symbol);\n\n return `${renderedSolidityHeader}\n\n${renderAbsoluteImports(baseImports)}\n\n${renderRelativeImports(imports)}\n\n/**\n * The ${interfaceName} interface includes all systems dynamically added to the World\n * during the deploy process.\n */\ninterface ${interfaceName} is ${renderArguments(importSymbols)} {\n\n}\n\n`;\n}\n","import { readFileSync } from \"fs\";\nimport path from \"path\";\nimport { formatAndWriteSolidity, contractToInterface, type RelativeImportDatum } from \"@latticexyz/common/codegen\";\nimport { StoreConfig } from \"@latticexyz/store\";\nimport { renderSystemInterface } from \"./renderSystemInterface\";\nimport { renderWorld } from \"./renderWorld\";\nimport { resolveWorldConfig, WorldConfig } from \"../config\";\n\nexport async function worldgen(\n config: StoreConfig & WorldConfig,\n existingContracts: { path: string; basename: string }[],\n outputBaseDirectory: string\n) {\n const resolvedConfig = resolveWorldConfig(\n config,\n existingContracts.map(({ basename }) => basename)\n );\n\n const worldgenBaseDirectory = path.join(outputBaseDirectory, config.worldgenDirectory);\n const systems = existingContracts.filter(({ basename }) => Object.keys(resolvedConfig.systems).includes(basename));\n\n const systemInterfaceImports: RelativeImportDatum[] = [];\n for (const system of systems) {\n const data = readFileSync(system.path, \"utf8\");\n // get external funcions from a contract\n const { functions, symbolImports } = contractToInterface(data, system.basename);\n const imports = symbolImports.map((symbolImport) => {\n if (symbolImport.path[0] === \".\") {\n // relative import\n return {\n symbol: symbolImport.symbol,\n fromPath: path.join(path.dirname(system.path), symbolImport.path),\n usedInPath: worldgenBaseDirectory,\n };\n } else {\n // absolute import\n return {\n symbol: symbolImport.symbol,\n path: symbolImport.path,\n };\n }\n });\n const systemInterfaceName = `I${system.basename}`;\n // create an interface using the external functions and imports\n const { name } = resolvedConfig.systems[system.basename];\n const output = renderSystemInterface({\n name: systemInterfaceName,\n functionPrefix: config.namespace === \"\" ? \"\" : `${config.namespace}_${name}_`,\n functions,\n imports,\n });\n // write to file\n const fullOutputPath = path.join(worldgenBaseDirectory, systemInterfaceName + \".sol\");\n await formatAndWriteSolidity(output, fullOutputPath, \"Generated system interface\");\n\n // prepare imports for IWorld\n systemInterfaceImports.push({\n symbol: systemInterfaceName,\n fromPath: `${systemInterfaceName}.sol`,\n usedInPath: \"./\",\n });\n }\n\n // render IWorld\n const output = renderWorld({\n interfaceName: config.worldInterfaceName,\n imports: systemInterfaceImports,\n storeImportPath: config.storeImportPath,\n worldImportPath: config.worldImportPath,\n });\n // write to file\n const fullOutputPath = path.join(worldgenBaseDirectory, config.worldInterfaceName + \".sol\");\n await formatAndWriteSolidity(output, fullOutputPath, \"Generated system interface\");\n}\n"],"mappings":"AAAA,OAAS,kCAAAA,MAAsC,qBAYxC,SAASC,EAAmBC,EAAqBC,EAA8B,CAEpF,IAAMC,EACJD,GAAmB,OAAQE,GAASA,EAAK,SAAS,QAAQ,GAAKA,IAAS,UAAY,CAACA,EAAK,MAAM,SAAS,CAAC,GAAK,CAAC,EAC5GC,EAAwB,OAAO,KAAKJ,EAAO,eAAe,EAGhE,GAAIC,GACF,QAAWI,KAAcD,EACvB,GAAI,CAACH,EAAkB,SAASI,CAAU,GAAKA,IAAe,QAC5D,MAAMP,EAA+B,CAAC,kBAAmBO,CAAU,EAAGA,CAAU,EAkBtF,MAAO,CAAE,QAZW,CAAC,GAAG,IAAI,IAAI,CAAC,GAAGH,EAAoB,GAAGE,CAAqB,CAAC,CAAC,EAAE,OACjFD,GAAS,CAACH,EAAO,eAAe,SAASG,CAAI,CAChD,EAG0E,OAAO,CAACG,EAAKD,KAC9E,CACL,GAAGC,EACH,CAACD,CAAU,EAAGE,EAAoBF,EAAYL,EAAO,gBAAgBK,CAAU,EAAGJ,CAAiB,CACrG,GACC,CAAC,CAAC,CAE6B,CACpC,CAcO,SAASM,EAAoBF,EAAoBL,EAAuBC,EAA8B,CAC3G,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3GI,EAAgD,CAAC,EACvD,QAAWC,KAAUF,EAAS,CAC5B,IAAMG,EAAOC,EAAaF,EAAO,KAAM,MAAM,EAEvC,CAAE,UAAAG,EAAW,cAAAC,CAAc,EAAIC,EAAoBJ,EAAMD,EAAO,QAAQ,EACxEM,EAAUF,EAAc,IAAKG,GAC7BA,EAAa,KAAK,CAAC,IAAM,IAEpB,CACL,OAAQA,EAAa,OACrB,SAAUV,EAAK,KAAKA,EAAK,QAAQG,EAAO,IAAI,EAAGO,EAAa,IAAI,EAChE,WAAYX,CACd,EAGO,CACL,OAAQW,EAAa,OACrB,KAAMA,EAAa,IACrB,CAEH,EACKC,EAAsB,IAAIR,EAAO,WAEjC,CAAE,KAAAS,CAAK,EAAIhB,EAAe,QAAQO,EAAO,QAAQ,EACjDU,EAASC,EAAsB,CACnC,KAAMH,EACN,eAAgBlB,EAAO,YAAc,GAAK,GAAK,GAAGA,EAAO,aAAamB,KACtE,UAAAN,EACA,QAAAG,CACF,CAAC,EAEKM,EAAiBf,EAAK,KAAKD,EAAuBY,EAAsB,MAAM,EACpF,MAAMK,EAAuBH,EAAQE,EAAgB,4BAA4B,EAGjFb,EAAuB,KAAK,CAC1B,OAAQS,EACR,SAAU,GAAGA,QACb,WAAY,IACd,CAAC,EAIH,IAAME,EAASI,EAAY,CACzB,cAAexB,EAAO,mBACtB,QAASS,EACT,gBAAiBT,EAAO,gBACxB,gBAAiBA,EAAO,eAC1B,CAAC,EAEKsB,EAAiBf,EAAK,KAAKD,EAAuBN,EAAO,mBAAqB,MAAM,EAC1F,MAAMuB,EAAuBH,EAAQE,EAAgB,4BAA4B,CACnF","names":["UnrecognizedSystemErrorFactory","resolveWorldConfig","config","existingContracts","defaultSystemNames","name","overriddenSystemNames","systemName","acc","resolveSystemConfig","registerFunctionSelectors","openAccess","accessListAddresses","accessListSystems","accessList","accessListItem","z","DynamicResolutionType","zEthereumAddress","zObjectName","zSelector","zSystemName","zModuleName","zSystemAccessList","zSystemConfig","zValueWithType","zDynamicResolution","zModuleConfig","zWorldConfig","zPluginWorldConfig","renderArguments","renderList","renderedSolidityHeader","renderImports","renderSystemInterface","options","imports","name","functionPrefix","functions","parameters","stateMutability","returnParameters","renderReturnParameters","renderArguments","renderedSolidityHeader","renderAbsoluteImports","renderRelativeImports","renderWorld","options","interfaceName","storeImportPath","worldImportPath","imports","baseImports","importSymbols","symbol","readFileSync","path","formatAndWriteSolidity","contractToInterface","worldgen","config","existingContracts","outputBaseDirectory","resolvedConfig","resolveWorldConfig","basename","worldgenBaseDirectory","path","systems","systemInterfaceImports","system","data","readFileSync","functions","symbolImports","contractToInterface","imports","symbolImport","systemInterfaceName","name","output","renderSystemInterface","fullOutputPath","formatAndWriteSolidity","renderWorld"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{d as o}from"./chunk-EOSNM56M.js";import{mudConfig as a,mudCoreConfig as g,resolveTableId as s}from"@latticexyz/store/register";import{extendMUDCoreConfig as t,fromZodErrorCustom as e}from"@latticexyz/config";import{ZodError as m}from"zod";t(i=>{try{return o.parse(i)}catch(r){throw r instanceof m?e(r,"WorldConfig Validation Error"):r}});export{a,g as b,s as c};
|
|
2
|
+
//# sourceMappingURL=chunk-WABR4LFG.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../ts/register/index.ts","../ts/register/configExtensions.ts"],"sourcesContent":["// Importing this file has side-effects for MUD config,\n// and the order of imports is important in relation to other plugins\n// (store should usually be the first plugin, followed by world)\n\n// For convenience register and reexport store (which does the same for core config),\n// to reduce the number of needed imports for users\nexport { mudConfig, mudCoreConfig, resolveTableId } from \"@latticexyz/store/register\";\n// Extend core config and types\nimport \"./configExtensions\";\nimport \"./typeExtensions\";\n","import { extendMUDCoreConfig, fromZodErrorCustom } from \"@latticexyz/config\";\nimport { ZodError } from \"zod\";\nimport { zPluginWorldConfig } from \"../library\";\n\nextendMUDCoreConfig((config) => {\n // This function gets called within mudConfig.\n // The call order of config extenders depends on the order of their imports.\n // Any config validation and transformation should be placed here.\n try {\n return zPluginWorldConfig.parse(config);\n } catch (error) {\n if (error instanceof ZodError) {\n throw fromZodErrorCustom(error, \"WorldConfig Validation Error\");\n } else {\n throw error;\n }\n }\n});\n"],"mappings":"wCAMA,OAAS,aAAAA,EAAW,iBAAAC,EAAe,kBAAAC,MAAsB,6BCNzD,OAAS,uBAAAC,EAAqB,sBAAAC,MAA0B,qBACxD,OAAS,YAAAC,MAAgB,MAGzBC,EAAqBC,GAAW,CAI9B,GAAI,CACF,OAAOC,EAAmB,MAAMD,CAAM,CACxC,OAASE,EAAP,CACA,MAAIA,aAAiBC,EACbC,EAAmBF,EAAO,8BAA8B,EAExDA,CAEV,CACF,CAAC","names":["mudConfig","mudCoreConfig","resolveTableId","extendMUDCoreConfig","fromZodErrorCustom","ZodError","extendMUDCoreConfig","config","zPluginWorldConfig","error","ZodError","fromZodErrorCustom"]}
|
package/dist/mud.config.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{a as e}from"./chunk-WABR4LFG.js";import"./chunk-EOSNM56M.js";var r=e({worldImportPath:"../",worldgenDirectory:"interfaces",worldInterfaceName:"IBaseWorld",codegenDirectory:"",tables:{NamespaceOwner:{primaryKeys:{namespace:"bytes16"},schema:{owner:"address"}},ResourceAccess:{primaryKeys:{resourceSelector:"bytes32",caller:"address"},schema:{access:"bool"}},InstalledModules:{primaryKeys:{moduleName:"bytes16",argumentsHash:"bytes32"},schema:{moduleAddress:"address"},dataStruct:!0},Systems:{directory:"modules/core/tables",primaryKeys:{resourceSelector:"bytes32"},schema:{system:"address",publicAccess:"bool"},dataStruct:!1},SystemRegistry:{directory:"modules/core/tables",primaryKeys:{system:"address"},schema:{resourceSelector:"bytes32"}},ResourceType:{directory:"modules/core/tables",primaryKeys:{resourceSelector:"bytes32"},schema:{resourceType:"Resource"}},FunctionSelectors:{directory:"modules/core/tables",name:"funcSelectors",primaryKeys:{functionSelector:"bytes4"},schema:{namespace:"bytes16",name:"bytes16",systemFunctionSelector:"bytes4"},dataStruct:!1},KeysWithValue:{directory:"modules/keyswithvalue/tables",primaryKeys:{valueHash:"bytes32"},schema:{keysWithValue:"bytes32[]"},tableIdArgument:!0},UniqueEntity:{directory:"modules/uniqueentity/tables",primaryKeys:{},schema:"uint256",tableIdArgument:!0,storeArgument:!0},Bool:{directory:"../test/tables",primaryKeys:{},schema:{value:"bool"},tableIdArgument:!0},AddressArray:{directory:"../test/tables",schema:"address[]",tableIdArgument:!0}},enums:{Resource:["NONE","NAMESPACE","TABLE","SYSTEM"]},excludeSystems:["UniqueEntitySystem","StoreRegistrationSystem"]});export{r as default};
|
|
2
2
|
//# sourceMappingURL=mud.config.js.map
|
package/dist/mud.config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../mud.config.ts"],"sourcesContent":["import { mudConfig } from \"
|
|
1
|
+
{"version":3,"sources":["../mud.config.ts"],"sourcesContent":["import { mudConfig } from \"./ts/register\";\n\nexport default mudConfig({\n worldImportPath: \"../\",\n worldgenDirectory: \"interfaces\",\n worldInterfaceName: \"IBaseWorld\",\n codegenDirectory: \"\",\n tables: {\n /************************************************************************\n *\n * CORE TABLES\n *\n ************************************************************************/\n NamespaceOwner: {\n primaryKeys: {\n namespace: \"bytes16\",\n },\n schema: {\n owner: \"address\",\n },\n },\n ResourceAccess: {\n primaryKeys: {\n resourceSelector: \"bytes32\",\n caller: \"address\",\n },\n schema: {\n access: \"bool\",\n },\n },\n InstalledModules: {\n primaryKeys: {\n moduleName: \"bytes16\",\n argumentsHash: \"bytes32\", // Hash of the params passed to the `install` function\n },\n schema: {\n moduleAddress: \"address\",\n },\n // TODO: this is a workaround to use `getRecord` instead of `getField` in the autogen library,\n // to allow using the table before it is registered. This is because `getRecord` passes the schema\n // to store, while `getField` loads it from storage. Remove this once we have support for passing the\n // schema in `getField` too. (See https://github.com/latticexyz/mud/issues/444)\n dataStruct: true,\n },\n /************************************************************************\n *\n * MODULE TABLES\n *\n ************************************************************************/\n Systems: {\n directory: \"modules/core/tables\",\n primaryKeys: {\n resourceSelector: \"bytes32\",\n },\n schema: {\n system: \"address\",\n publicAccess: \"bool\",\n },\n dataStruct: false,\n },\n SystemRegistry: {\n directory: \"modules/core/tables\",\n primaryKeys: {\n system: \"address\",\n },\n schema: {\n resourceSelector: \"bytes32\",\n },\n },\n ResourceType: {\n directory: \"modules/core/tables\",\n primaryKeys: {\n resourceSelector: \"bytes32\",\n },\n schema: {\n resourceType: \"Resource\",\n },\n },\n FunctionSelectors: {\n directory: \"modules/core/tables\",\n name: \"funcSelectors\",\n primaryKeys: {\n functionSelector: \"bytes4\",\n },\n schema: {\n namespace: \"bytes16\",\n name: \"bytes16\",\n systemFunctionSelector: \"bytes4\",\n },\n dataStruct: false,\n },\n KeysWithValue: {\n directory: \"modules/keyswithvalue/tables\",\n primaryKeys: {\n valueHash: \"bytes32\",\n },\n schema: {\n keysWithValue: \"bytes32[]\", // For now only supports 1 key per value\n },\n tableIdArgument: true,\n },\n UniqueEntity: {\n directory: \"modules/uniqueentity/tables\",\n primaryKeys: {},\n schema: \"uint256\",\n tableIdArgument: true,\n storeArgument: true,\n },\n /************************************************************************\n *\n * TEST TABLES\n *\n ************************************************************************/\n Bool: {\n directory: \"../test/tables\",\n primaryKeys: {},\n schema: {\n value: \"bool\",\n },\n tableIdArgument: true,\n },\n AddressArray: {\n directory: \"../test/tables\",\n schema: \"address[]\",\n tableIdArgument: true,\n },\n },\n enums: {\n Resource: [\"NONE\", \"NAMESPACE\", \"TABLE\", \"SYSTEM\"],\n },\n\n excludeSystems: [\n // IUniqueEntitySystem is not part of the root namespace and\n // installed separately by UniqueEntityModule.\n // TODO: Move optional modules into a separate package\n // (see https://github.com/latticexyz/mud/pull/584)\n \"UniqueEntitySystem\",\n\n // Worldgen currently does not support systems inheriting logic\n // from other contracts, so all parts of CoreSystem are named\n // System too to be included in the IBaseWorld interface.\n // However, IStoreRegistrationSystem overlaps with IStore if\n // included in IBaseWorld, so it needs to be excluded from worldgen.\n // TODO: add support for inheritance to worldgen\n // (see: https://github.com/latticexyz/mud/issues/631)\n \"StoreRegistrationSystem\",\n ],\n});\n"],"mappings":"oEAEA,IAAOA,EAAQC,EAAU,CACvB,gBAAiB,MACjB,kBAAmB,aACnB,mBAAoB,aACpB,iBAAkB,GAClB,OAAQ,CAMN,eAAgB,CACd,YAAa,CACX,UAAW,SACb,EACA,OAAQ,CACN,MAAO,SACT,CACF,EACA,eAAgB,CACd,YAAa,CACX,iBAAkB,UAClB,OAAQ,SACV,EACA,OAAQ,CACN,OAAQ,MACV,CACF,EACA,iBAAkB,CAChB,YAAa,CACX,WAAY,UACZ,cAAe,SACjB,EACA,OAAQ,CACN,cAAe,SACjB,EAKA,WAAY,EACd,EAMA,QAAS,CACP,UAAW,sBACX,YAAa,CACX,iBAAkB,SACpB,EACA,OAAQ,CACN,OAAQ,UACR,aAAc,MAChB,EACA,WAAY,EACd,EACA,eAAgB,CACd,UAAW,sBACX,YAAa,CACX,OAAQ,SACV,EACA,OAAQ,CACN,iBAAkB,SACpB,CACF,EACA,aAAc,CACZ,UAAW,sBACX,YAAa,CACX,iBAAkB,SACpB,EACA,OAAQ,CACN,aAAc,UAChB,CACF,EACA,kBAAmB,CACjB,UAAW,sBACX,KAAM,gBACN,YAAa,CACX,iBAAkB,QACpB,EACA,OAAQ,CACN,UAAW,UACX,KAAM,UACN,uBAAwB,QAC1B,EACA,WAAY,EACd,EACA,cAAe,CACb,UAAW,+BACX,YAAa,CACX,UAAW,SACb,EACA,OAAQ,CACN,cAAe,WACjB,EACA,gBAAiB,EACnB,EACA,aAAc,CACZ,UAAW,8BACX,YAAa,CAAC,EACd,OAAQ,UACR,gBAAiB,GACjB,cAAe,EACjB,EAMA,KAAM,CACJ,UAAW,iBACX,YAAa,CAAC,EACd,OAAQ,CACN,MAAO,MACT,EACA,gBAAiB,EACnB,EACA,aAAc,CACZ,UAAW,iBACX,OAAQ,YACR,gBAAiB,EACnB,CACF,EACA,MAAO,CACL,SAAU,CAAC,OAAQ,YAAa,QAAS,QAAQ,CACnD,EAEA,eAAgB,CAKd,qBASA,yBACF,CACF,CAAC","names":["mud_config_default","mudConfig"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@latticexyz/world",
|
|
3
|
-
"version": "2.0.0-alpha.1.
|
|
3
|
+
"version": "2.0.0-alpha.1.44+4b3b4725",
|
|
4
4
|
"description": "World framework",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -10,11 +10,21 @@
|
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"type": "module",
|
|
12
12
|
"exports": {
|
|
13
|
-
".": "./dist/ts/index.js",
|
|
13
|
+
".": "./dist/ts/library/index.js",
|
|
14
|
+
"./register": "./dist/ts/register/index.js",
|
|
14
15
|
"./mud.config.js": "./dist/mud.config.js",
|
|
15
16
|
"./abi/*": "./abi/*"
|
|
16
17
|
},
|
|
17
|
-
"
|
|
18
|
+
"typesVersions": {
|
|
19
|
+
"*": {
|
|
20
|
+
"index": [
|
|
21
|
+
"./ts/library/index.ts"
|
|
22
|
+
],
|
|
23
|
+
"register": [
|
|
24
|
+
"./ts/register/index.ts"
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
},
|
|
18
28
|
"scripts": {
|
|
19
29
|
"build": "pnpm run build:mud && pnpm run build:abi && pnpm run build:typechain && pnpm run build:js",
|
|
20
30
|
"build:abi": "forge build --extra-output-files abi --out abi --skip test script",
|
|
@@ -35,11 +45,12 @@
|
|
|
35
45
|
"dependencies": {
|
|
36
46
|
"@ethersproject/abi": "^5.7.0",
|
|
37
47
|
"@ethersproject/providers": "^5.7.2",
|
|
38
|
-
"@latticexyz/common": "2.0.0-alpha.1.
|
|
39
|
-
"@latticexyz/config": "2.0.0-alpha.1.
|
|
40
|
-
"@latticexyz/schema-type": "2.0.0-alpha.1.
|
|
41
|
-
"@latticexyz/store": "2.0.0-alpha.1.
|
|
42
|
-
"ethers": "^5.7.2"
|
|
48
|
+
"@latticexyz/common": "2.0.0-alpha.1.44+4b3b4725",
|
|
49
|
+
"@latticexyz/config": "2.0.0-alpha.1.44+4b3b4725",
|
|
50
|
+
"@latticexyz/schema-type": "2.0.0-alpha.1.44+4b3b4725",
|
|
51
|
+
"@latticexyz/store": "2.0.0-alpha.1.44+4b3b4725",
|
|
52
|
+
"ethers": "^5.7.2",
|
|
53
|
+
"zod": "^3.21.4"
|
|
43
54
|
},
|
|
44
55
|
"devDependencies": {
|
|
45
56
|
"@typechain/ethers-v5": "^10.2.0",
|
|
@@ -58,7 +69,9 @@
|
|
|
58
69
|
"tsup": "^6.7.0",
|
|
59
70
|
"tsx": "^3.12.6",
|
|
60
71
|
"typechain": "^8.1.1",
|
|
61
|
-
"typedoc": "0.23.10"
|
|
72
|
+
"typedoc": "0.23.10",
|
|
73
|
+
"typescript": "^4.9.5",
|
|
74
|
+
"vitest": "0.30.1"
|
|
62
75
|
},
|
|
63
|
-
"gitHead": "
|
|
76
|
+
"gitHead": "4b3b472541e8f933051219da1e52b876396c58cd"
|
|
64
77
|
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { UnrecognizedSystemErrorFactory } from "@latticexyz/config";
|
|
2
|
+
import { SystemConfig, WorldConfig } from "./types";
|
|
3
|
+
|
|
4
|
+
export type ResolvedSystemConfig = ReturnType<typeof resolveSystemConfig>;
|
|
5
|
+
|
|
6
|
+
export type ResolvedWorldConfig = ReturnType<typeof resolveWorldConfig>;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Resolves the world config by combining the default and overridden system configs,
|
|
10
|
+
* filtering out excluded systems, validate system names refer to existing contracts, and
|
|
11
|
+
* splitting the access list into addresses and system names.
|
|
12
|
+
*/
|
|
13
|
+
export function resolveWorldConfig(config: WorldConfig, existingContracts?: string[]) {
|
|
14
|
+
// Include contract names ending in "System", but not the base "System" contract, and not Interfaces
|
|
15
|
+
const defaultSystemNames =
|
|
16
|
+
existingContracts?.filter((name) => name.endsWith("System") && name !== "System" && !name.match(/^I[A-Z]/)) ?? [];
|
|
17
|
+
const overriddenSystemNames = Object.keys(config.overrideSystems);
|
|
18
|
+
|
|
19
|
+
// Validate every key in overrideSystems refers to an existing system contract (and is not called "World")
|
|
20
|
+
if (existingContracts) {
|
|
21
|
+
for (const systemName of overriddenSystemNames) {
|
|
22
|
+
if (!existingContracts.includes(systemName) || systemName === "World") {
|
|
23
|
+
throw UnrecognizedSystemErrorFactory(["overrideSystems", systemName], systemName);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Combine the default and overridden system names and filter out excluded systems
|
|
29
|
+
const systemNames = [...new Set([...defaultSystemNames, ...overriddenSystemNames])].filter(
|
|
30
|
+
(name) => !config.excludeSystems.includes(name)
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
// Resolve the config
|
|
34
|
+
const resolvedSystems: Record<string, ResolvedSystemConfig> = systemNames.reduce((acc, systemName) => {
|
|
35
|
+
return {
|
|
36
|
+
...acc,
|
|
37
|
+
[systemName]: resolveSystemConfig(systemName, config.overrideSystems[systemName], existingContracts),
|
|
38
|
+
};
|
|
39
|
+
}, {});
|
|
40
|
+
|
|
41
|
+
return { systems: resolvedSystems };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Resolves the system config by combining the default and overridden system configs,
|
|
46
|
+
* @param systemName name of the system
|
|
47
|
+
* @param config optional SystemConfig object, if none is provided the default config is used
|
|
48
|
+
* @param existingContracts optional list of existing contract names, used to validate system names in the access list. If not provided, no validation is performed.
|
|
49
|
+
* @returns ResolvedSystemConfig object
|
|
50
|
+
* Default value for name is `systemName`
|
|
51
|
+
* Default value for registerFunctionSelectors is true
|
|
52
|
+
* Default value for openAccess is true
|
|
53
|
+
* Default value for accessListAddresses is []
|
|
54
|
+
* Default value for accessListSystems is []
|
|
55
|
+
*/
|
|
56
|
+
export function resolveSystemConfig(systemName: string, config?: SystemConfig, existingContracts?: string[]) {
|
|
57
|
+
const name = config?.name ?? systemName;
|
|
58
|
+
const registerFunctionSelectors = config?.registerFunctionSelectors ?? true;
|
|
59
|
+
const openAccess = config?.openAccess ?? true;
|
|
60
|
+
const accessListAddresses: string[] = [];
|
|
61
|
+
const accessListSystems: string[] = [];
|
|
62
|
+
const accessList = config && !config.openAccess ? config.accessList : [];
|
|
63
|
+
|
|
64
|
+
// Split the access list into addresses and system names
|
|
65
|
+
for (const accessListItem of accessList) {
|
|
66
|
+
if (accessListItem.startsWith("0x")) {
|
|
67
|
+
accessListAddresses.push(accessListItem);
|
|
68
|
+
} else {
|
|
69
|
+
// Validate every system refers to an existing system contract
|
|
70
|
+
if (existingContracts && !existingContracts.includes(accessListItem)) {
|
|
71
|
+
throw UnrecognizedSystemErrorFactory(["overrideSystems", systemName, "accessList"], accessListItem);
|
|
72
|
+
}
|
|
73
|
+
accessListSystems.push(accessListItem);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return { name, registerFunctionSelectors, openAccess, accessListAddresses, accessListSystems };
|
|
78
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { DynamicResolution, ValueWithType } from "@latticexyz/config";
|
|
3
|
+
import { zWorldConfig } from "./worldConfig";
|
|
4
|
+
|
|
5
|
+
// zod doesn't preserve doc comments
|
|
6
|
+
export type SystemUserConfig =
|
|
7
|
+
| {
|
|
8
|
+
/** The full resource selector consists of namespace and name */
|
|
9
|
+
name?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Register function selectors for the system in the World.
|
|
12
|
+
* Defaults to true.
|
|
13
|
+
* Note:
|
|
14
|
+
* - For root systems all World function selectors will correspond to the system's function selectors.
|
|
15
|
+
* - For non-root systems, the World function selectors will be <namespace>_<system>_<function>.
|
|
16
|
+
*/
|
|
17
|
+
registerFunctionSelectors?: boolean;
|
|
18
|
+
} & (
|
|
19
|
+
| {
|
|
20
|
+
/** If openAccess is true, any address can call the system */
|
|
21
|
+
openAccess: true;
|
|
22
|
+
}
|
|
23
|
+
| {
|
|
24
|
+
/** If openAccess is false, only the addresses or systems in `access` can call the system */
|
|
25
|
+
openAccess: false;
|
|
26
|
+
/** An array of addresses or system names that can access the system */
|
|
27
|
+
accessList: string[];
|
|
28
|
+
}
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
export type ModuleConfig = {
|
|
32
|
+
/** The name of the module */
|
|
33
|
+
name: string;
|
|
34
|
+
/** Should this module be installed as a root module? */
|
|
35
|
+
root?: boolean;
|
|
36
|
+
/** Arguments to be passed to the module's install method */
|
|
37
|
+
args?: (ValueWithType | DynamicResolution)[];
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// zod doesn't preserve doc comments
|
|
41
|
+
export interface WorldUserConfig {
|
|
42
|
+
/** The namespace to register tables and systems at. Defaults to the root namespace (empty string) */
|
|
43
|
+
namespace?: string;
|
|
44
|
+
/** The name of the World contract to deploy. If no name is provided, a vanilla World is deployed */
|
|
45
|
+
worldContractName?: string;
|
|
46
|
+
/** The name of the World interface to generate. (Default `IWorld`) */
|
|
47
|
+
worldInterfaceName?: string;
|
|
48
|
+
/**
|
|
49
|
+
* Contracts named *System will be deployed by default
|
|
50
|
+
* as public systems at `namespace/ContractName`, unless overridden
|
|
51
|
+
*
|
|
52
|
+
* The key is the system name (capitalized).
|
|
53
|
+
* The value is a SystemConfig object.
|
|
54
|
+
*/
|
|
55
|
+
overrideSystems?: Record<string, SystemUserConfig>;
|
|
56
|
+
/** Systems to exclude from automatic deployment */
|
|
57
|
+
excludeSystems?: string[];
|
|
58
|
+
/**
|
|
59
|
+
* Script to execute after the deployment is complete (Default "PostDeploy").
|
|
60
|
+
* Script must be placed in the forge scripts directory (see foundry.toml) and have a ".s.sol" extension.
|
|
61
|
+
*/
|
|
62
|
+
postDeployScript?: string;
|
|
63
|
+
/** Directory to write the deployment info to (Default "./deploys") */
|
|
64
|
+
deploysDirectory?: string;
|
|
65
|
+
/** Directory to output system and world interfaces of `worldgen` (Default "world") */
|
|
66
|
+
worldgenDirectory?: string;
|
|
67
|
+
/** Path for world package imports. Default is "@latticexyz/world/src/" */
|
|
68
|
+
worldImportPath?: string;
|
|
69
|
+
/** Modules to in the World */
|
|
70
|
+
modules?: ModuleConfig[];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export type WorldConfig = z.output<typeof zWorldConfig>;
|
|
74
|
+
export type SystemConfig = WorldConfig["overrideSystems"][string];
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { describe, expectTypeOf } from "vitest";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { zWorldConfig } from "./worldConfig";
|
|
4
|
+
import { WorldUserConfig } from "./types";
|
|
5
|
+
|
|
6
|
+
describe("worldConfig", () => {
|
|
7
|
+
// Typecheck manual interfaces against zod
|
|
8
|
+
expectTypeOf<WorldUserConfig>().toEqualTypeOf<z.input<typeof zWorldConfig>>();
|
|
9
|
+
// type equality isn't deep for optionals
|
|
10
|
+
expectTypeOf<WorldUserConfig["overrideSystems"]>().toEqualTypeOf<z.input<typeof zWorldConfig>["overrideSystems"]>();
|
|
11
|
+
// TODO If more nested schemas are added, provide separate tests for them
|
|
12
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { DynamicResolutionType, zEthereumAddress, zObjectName, zSelector } from "@latticexyz/config";
|
|
3
|
+
|
|
4
|
+
const zSystemName = zObjectName;
|
|
5
|
+
const zModuleName = zObjectName;
|
|
6
|
+
const zSystemAccessList = z.array(zSystemName.or(zEthereumAddress)).default([]);
|
|
7
|
+
|
|
8
|
+
// The system config is a combination of a name config and access config
|
|
9
|
+
const zSystemConfig = z.intersection(
|
|
10
|
+
z.object({
|
|
11
|
+
name: zSelector,
|
|
12
|
+
registerFunctionSelectors: z.boolean().default(true),
|
|
13
|
+
}),
|
|
14
|
+
z.discriminatedUnion("openAccess", [
|
|
15
|
+
z.object({
|
|
16
|
+
openAccess: z.literal(true),
|
|
17
|
+
}),
|
|
18
|
+
z.object({
|
|
19
|
+
openAccess: z.literal(false),
|
|
20
|
+
accessList: zSystemAccessList,
|
|
21
|
+
}),
|
|
22
|
+
])
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
const zValueWithType = z.object({
|
|
26
|
+
value: z.union([z.string(), z.number(), z.instanceof(Uint8Array)]),
|
|
27
|
+
type: z.string(),
|
|
28
|
+
});
|
|
29
|
+
const zDynamicResolution = z.object({ type: z.nativeEnum(DynamicResolutionType), input: z.string() });
|
|
30
|
+
|
|
31
|
+
const zModuleConfig = z.object({
|
|
32
|
+
name: zModuleName,
|
|
33
|
+
root: z.boolean().default(false),
|
|
34
|
+
args: z.array(z.union([zValueWithType, zDynamicResolution])).default([]),
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// The parsed world config is the result of parsing the user config
|
|
38
|
+
export const zWorldConfig = z.object({
|
|
39
|
+
namespace: zSelector.default(""),
|
|
40
|
+
worldContractName: z.string().optional(),
|
|
41
|
+
worldInterfaceName: z.string().default("IWorld"),
|
|
42
|
+
overrideSystems: z.record(zSystemName, zSystemConfig).default({}),
|
|
43
|
+
excludeSystems: z.array(zSystemName).default([]),
|
|
44
|
+
postDeployScript: z.string().default("PostDeploy"),
|
|
45
|
+
deploysDirectory: z.string().default("./deploys"),
|
|
46
|
+
worldgenDirectory: z.string().default("world"),
|
|
47
|
+
worldImportPath: z.string().default("@latticexyz/world/src/"),
|
|
48
|
+
modules: z.array(zModuleConfig).default([]),
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// Catchall preserves other plugins' options
|
|
52
|
+
export const zPluginWorldConfig = zWorldConfig.catchall(z.any());
|
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
import { readFileSync } from "fs";
|
|
2
2
|
import path from "path";
|
|
3
|
-
import { MUDConfig } from "@latticexyz/config";
|
|
4
3
|
import { formatAndWriteSolidity, contractToInterface, type RelativeImportDatum } from "@latticexyz/common/codegen";
|
|
4
|
+
import { StoreConfig } from "@latticexyz/store";
|
|
5
5
|
import { renderSystemInterface } from "./renderSystemInterface";
|
|
6
6
|
import { renderWorld } from "./renderWorld";
|
|
7
|
+
import { resolveWorldConfig, WorldConfig } from "../config";
|
|
7
8
|
|
|
8
9
|
export async function worldgen(
|
|
9
|
-
config:
|
|
10
|
+
config: StoreConfig & WorldConfig,
|
|
10
11
|
existingContracts: { path: string; basename: string }[],
|
|
11
12
|
outputBaseDirectory: string
|
|
12
13
|
) {
|
|
14
|
+
const resolvedConfig = resolveWorldConfig(
|
|
15
|
+
config,
|
|
16
|
+
existingContracts.map(({ basename }) => basename)
|
|
17
|
+
);
|
|
18
|
+
|
|
13
19
|
const worldgenBaseDirectory = path.join(outputBaseDirectory, config.worldgenDirectory);
|
|
14
|
-
const systems = existingContracts.filter(({ basename }) => Object.keys(
|
|
20
|
+
const systems = existingContracts.filter(({ basename }) => Object.keys(resolvedConfig.systems).includes(basename));
|
|
15
21
|
|
|
16
22
|
const systemInterfaceImports: RelativeImportDatum[] = [];
|
|
17
23
|
for (const system of systems) {
|
|
@@ -36,7 +42,7 @@ export async function worldgen(
|
|
|
36
42
|
});
|
|
37
43
|
const systemInterfaceName = `I${system.basename}`;
|
|
38
44
|
// create an interface using the external functions and imports
|
|
39
|
-
const { name } =
|
|
45
|
+
const { name } = resolvedConfig.systems[system.basename];
|
|
40
46
|
const output = renderSystemInterface({
|
|
41
47
|
name: systemInterfaceName,
|
|
42
48
|
functionPrefix: config.namespace === "" ? "" : `${config.namespace}_${name}_`,
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { extendMUDCoreConfig, fromZodErrorCustom } from "@latticexyz/config";
|
|
2
|
+
import { ZodError } from "zod";
|
|
3
|
+
import { zPluginWorldConfig } from "../library";
|
|
4
|
+
|
|
5
|
+
extendMUDCoreConfig((config) => {
|
|
6
|
+
// This function gets called within mudConfig.
|
|
7
|
+
// The call order of config extenders depends on the order of their imports.
|
|
8
|
+
// Any config validation and transformation should be placed here.
|
|
9
|
+
try {
|
|
10
|
+
return zPluginWorldConfig.parse(config);
|
|
11
|
+
} catch (error) {
|
|
12
|
+
if (error instanceof ZodError) {
|
|
13
|
+
throw fromZodErrorCustom(error, "WorldConfig Validation Error");
|
|
14
|
+
} else {
|
|
15
|
+
throw error;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Importing this file has side-effects for MUD config,
|
|
2
|
+
// and the order of imports is important in relation to other plugins
|
|
3
|
+
// (store should usually be the first plugin, followed by world)
|
|
4
|
+
|
|
5
|
+
// For convenience register and reexport store (which does the same for core config),
|
|
6
|
+
// to reduce the number of needed imports for users
|
|
7
|
+
export { mudConfig, mudCoreConfig, resolveTableId } from "@latticexyz/store/register";
|
|
8
|
+
// Extend core config and types
|
|
9
|
+
import "./configExtensions";
|
|
10
|
+
import "./typeExtensions";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { WorldConfig, WorldUserConfig } from "../library";
|
|
2
|
+
|
|
3
|
+
// Inject the plugin options into the core config.
|
|
4
|
+
// Re-exporting an interface of an existing module merges them, adding new options to the interface.
|
|
5
|
+
// (typescript has no way to override types)
|
|
6
|
+
declare module "@latticexyz/config" {
|
|
7
|
+
// Extend the user config type, which represents the config as written by the users.
|
|
8
|
+
// Most things are optional here.
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
10
|
+
export interface MUDCoreUserConfig extends WorldUserConfig {}
|
|
11
|
+
|
|
12
|
+
// Also extend the config type, which represents the configuration after it has been resolved.
|
|
13
|
+
// It should not have any optional properties, with the default values applied instead.
|
|
14
|
+
// Other plugins may receive this resolved config as their input.
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
16
|
+
export interface MUDCoreConfig extends WorldConfig {}
|
|
17
|
+
}
|
package/ts/scripts/tablegen.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
import {
|
|
3
|
-
import { tablegen } from "@latticexyz/store";
|
|
2
|
+
import { loadConfig } from "@latticexyz/config";
|
|
4
3
|
import { getSrcDirectory } from "@latticexyz/common/foundry";
|
|
4
|
+
import { StoreConfig, tablegen } from "@latticexyz/store";
|
|
5
5
|
|
|
6
|
-
const config = await
|
|
6
|
+
const config = (await loadConfig()) as StoreConfig;
|
|
7
7
|
const srcDir = await getSrcDirectory();
|
|
8
8
|
|
|
9
9
|
await tablegen(config, path.join(srcDir, config.codegenDirectory));
|
package/ts/scripts/worldgen.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import glob from "glob";
|
|
2
2
|
import path, { basename } from "path";
|
|
3
3
|
import { rmSync } from "fs";
|
|
4
|
-
import {
|
|
5
|
-
import { worldgen } from "../render-solidity/worldgen";
|
|
4
|
+
import { loadConfig } from "@latticexyz/config";
|
|
6
5
|
import { getSrcDirectory } from "@latticexyz/common/foundry";
|
|
6
|
+
import { WorldConfig, worldgen } from "../library";
|
|
7
|
+
import { StoreConfig } from "@latticexyz/store";
|
|
7
8
|
|
|
8
9
|
// TODO dedupe this and cli's worldgen command
|
|
9
10
|
const configPath = undefined;
|
|
@@ -17,12 +18,7 @@ const existingContracts = glob.sync(`${srcDir}/**/*.sol`).map((path) => ({
|
|
|
17
18
|
}));
|
|
18
19
|
|
|
19
20
|
// Load and resolve the config
|
|
20
|
-
const
|
|
21
|
-
configPath,
|
|
22
|
-
existingContracts.map(({ basename }) => basename)
|
|
23
|
-
);
|
|
24
|
-
const storeConfig = await loadStoreConfig(configPath);
|
|
25
|
-
const mudConfig = { ...worldConfig, ...storeConfig };
|
|
21
|
+
const mudConfig = (await loadConfig(configPath)) as StoreConfig & WorldConfig;
|
|
26
22
|
|
|
27
23
|
const outputBaseDirectory = path.join(srcDir, mudConfig.codegenDirectory);
|
|
28
24
|
|
package/dist/ts/index.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import{renderArguments as c,renderList as W,renderedSolidityHeader as w,renderImports as D}from"@latticexyz/common/codegen";function f(e){let{imports:o,name:a,functionPrefix:r,functions:s}=e;return`${w}
|
|
2
|
-
|
|
3
|
-
${D(o)}
|
|
4
|
-
|
|
5
|
-
interface ${a} {
|
|
6
|
-
${W(s,({name:n,parameters:m,stateMutability:i,returnParameters:t})=>`
|
|
7
|
-
function ${r}${n}(
|
|
8
|
-
${c(m)}
|
|
9
|
-
) external ${i} ${R(t)};
|
|
10
|
-
`)}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
`}function R(e){return e.length>0?`returns (${c(e)})`:""}import{renderArguments as O,renderedSolidityHeader as A,renderAbsoluteImports as g,renderRelativeImports as j}from"@latticexyz/common/codegen";function u(e){let{interfaceName:o,storeImportPath:a,worldImportPath:r,imports:s}=e,n=o==="IBaseWorld"?[{symbol:"IStore",path:`${a}IStore.sol`},{symbol:"IWorldKernel",path:`${r}interfaces/IWorldKernel.sol`}]:[{symbol:"IBaseWorld",path:`${r}interfaces/IBaseWorld.sol`}],m=[...n,...s].map(({symbol:i})=>i);return`${A}
|
|
14
|
-
|
|
15
|
-
${g(n)}
|
|
16
|
-
|
|
17
|
-
${j(s)}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* The ${o} interface includes all systems dynamically added to the World
|
|
21
|
-
* during the deploy process.
|
|
22
|
-
*/
|
|
23
|
-
interface ${o} is ${O(m)} {
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
`}import{readFileSync as N}from"fs";import d from"path";import{formatAndWriteSolidity as y,contractToInterface as B}from"@latticexyz/common/codegen";async function k(e,o,a){let r=d.join(a,e.worldgenDirectory),s=o.filter(({basename:t})=>Object.keys(e.systems).includes(t)),n=[];for(let t of s){let I=N(t.path,"utf8"),{functions:h,symbolImports:$}=B(I,t.basename),b=$.map(p=>p.path[0]==="."?{symbol:p.symbol,fromPath:d.join(d.dirname(t.path),p.path),usedInPath:r}:{symbol:p.symbol,path:p.path}),l=`I${t.basename}`,{name:P}=e.systems[t.basename],x=f({name:l,functionPrefix:e.namespace===""?"":`${e.namespace}_${P}_`,functions:h,imports:b}),S=d.join(r,l+".sol");await y(x,S,"Generated system interface"),n.push({symbol:l,fromPath:`${l}.sol`,usedInPath:"./"})}let m=u({interfaceName:e.worldInterfaceName,imports:n,storeImportPath:e.storeImportPath,worldImportPath:e.worldImportPath}),i=d.join(r,e.worldInterfaceName+".sol");await y(m,i,"Generated system interface")}export{f as renderSystemInterface,u as renderWorld,k as worldgen};
|
|
28
|
-
//# sourceMappingURL=index.js.map
|
package/dist/ts/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../ts/render-solidity/renderSystemInterface.ts","../../ts/render-solidity/renderWorld.ts","../../ts/render-solidity/worldgen.ts"],"sourcesContent":["import { renderArguments, renderList, renderedSolidityHeader, renderImports } from \"@latticexyz/common/codegen\";\nimport { RenderSystemInterfaceOptions } from \"./types\";\n\nexport function renderSystemInterface(options: RenderSystemInterfaceOptions) {\n const { imports, name, functionPrefix, functions } = options;\n\n return `${renderedSolidityHeader}\n\n${renderImports(imports)}\n\ninterface ${name} {\n ${renderList(\n functions,\n ({ name, parameters, stateMutability, returnParameters }) => `\n function ${functionPrefix}${name}(\n ${renderArguments(parameters)}\n ) external ${stateMutability} ${renderReturnParameters(returnParameters)};\n `\n )}\n}\n\n`;\n}\n\nfunction renderReturnParameters(returnParameters: string[]) {\n if (returnParameters.length > 0) {\n return `returns (${renderArguments(returnParameters)})`;\n } else {\n return \"\";\n }\n}\n","import {\n renderArguments,\n renderedSolidityHeader,\n renderAbsoluteImports,\n renderRelativeImports,\n type AbsoluteImportDatum,\n} from \"@latticexyz/common/codegen\";\nimport type { RenderWorldOptions } from \"./types\";\n\nexport function renderWorld(options: RenderWorldOptions) {\n const { interfaceName, storeImportPath, worldImportPath, imports } = options;\n const baseImports: AbsoluteImportDatum[] =\n interfaceName === \"IBaseWorld\"\n ? [\n { symbol: \"IStore\", path: `${storeImportPath}IStore.sol` },\n { symbol: \"IWorldKernel\", path: `${worldImportPath}interfaces/IWorldKernel.sol` },\n ]\n : [\n {\n symbol: \"IBaseWorld\",\n path: `${worldImportPath}interfaces/IBaseWorld.sol`,\n },\n ];\n const importSymbols = [...baseImports, ...imports].map(({ symbol }) => symbol);\n\n return `${renderedSolidityHeader}\n\n${renderAbsoluteImports(baseImports)}\n\n${renderRelativeImports(imports)}\n\n/**\n * The ${interfaceName} interface includes all systems dynamically added to the World\n * during the deploy process.\n */\ninterface ${interfaceName} is ${renderArguments(importSymbols)} {\n\n}\n\n`;\n}\n","import { readFileSync } from \"fs\";\nimport path from \"path\";\nimport { MUDConfig } from \"@latticexyz/config\";\nimport { formatAndWriteSolidity, contractToInterface, type RelativeImportDatum } from \"@latticexyz/common/codegen\";\nimport { renderSystemInterface } from \"./renderSystemInterface\";\nimport { renderWorld } from \"./renderWorld\";\n\nexport async function worldgen(\n config: MUDConfig,\n existingContracts: { path: string; basename: string }[],\n outputBaseDirectory: string\n) {\n const worldgenBaseDirectory = path.join(outputBaseDirectory, config.worldgenDirectory);\n const systems = existingContracts.filter(({ basename }) => Object.keys(config.systems).includes(basename));\n\n const systemInterfaceImports: RelativeImportDatum[] = [];\n for (const system of systems) {\n const data = readFileSync(system.path, \"utf8\");\n // get external funcions from a contract\n const { functions, symbolImports } = contractToInterface(data, system.basename);\n const imports = symbolImports.map((symbolImport) => {\n if (symbolImport.path[0] === \".\") {\n // relative import\n return {\n symbol: symbolImport.symbol,\n fromPath: path.join(path.dirname(system.path), symbolImport.path),\n usedInPath: worldgenBaseDirectory,\n };\n } else {\n // absolute import\n return {\n symbol: symbolImport.symbol,\n path: symbolImport.path,\n };\n }\n });\n const systemInterfaceName = `I${system.basename}`;\n // create an interface using the external functions and imports\n const { name } = config.systems[system.basename];\n const output = renderSystemInterface({\n name: systemInterfaceName,\n functionPrefix: config.namespace === \"\" ? \"\" : `${config.namespace}_${name}_`,\n functions,\n imports,\n });\n // write to file\n const fullOutputPath = path.join(worldgenBaseDirectory, systemInterfaceName + \".sol\");\n await formatAndWriteSolidity(output, fullOutputPath, \"Generated system interface\");\n\n // prepare imports for IWorld\n systemInterfaceImports.push({\n symbol: systemInterfaceName,\n fromPath: `${systemInterfaceName}.sol`,\n usedInPath: \"./\",\n });\n }\n\n // render IWorld\n const output = renderWorld({\n interfaceName: config.worldInterfaceName,\n imports: systemInterfaceImports,\n storeImportPath: config.storeImportPath,\n worldImportPath: config.worldImportPath,\n });\n // write to file\n const fullOutputPath = path.join(worldgenBaseDirectory, config.worldInterfaceName + \".sol\");\n await formatAndWriteSolidity(output, fullOutputPath, \"Generated system interface\");\n}\n"],"mappings":"AAAA,OAAS,mBAAAA,EAAiB,cAAAC,EAAY,0BAAAC,EAAwB,iBAAAC,MAAqB,6BAG5E,SAASC,EAAsBC,EAAuC,CAC3E,GAAM,CAAE,QAAAC,EAAS,KAAAC,EAAM,eAAAC,EAAgB,UAAAC,CAAU,EAAIJ,EAErD,MAAO,GAAGH;AAAA;AAAA,EAEVC,EAAcG,CAAO;AAAA;AAAA,YAEXC;AAAA,IACRN,EACAQ,EACA,CAAC,CAAE,KAAAF,EAAM,WAAAG,EAAY,gBAAAC,EAAiB,iBAAAC,CAAiB,IAAM;AAAA,eAClDJ,IAAiBD;AAAA,QACxBP,EAAgBU,CAAU;AAAA,iBACjBC,KAAmBE,EAAuBD,CAAgB;AAAA,GAEzE;AAAA;AAAA;AAAA,CAIF,CAEA,SAASC,EAAuBD,EAA4B,CAC1D,OAAIA,EAAiB,OAAS,EAC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ACL,OAAQA,EAAa,OACrB,SAAUX,EAAK,KAAKA,EAAK,QAAQI,EAAO,IAAI,EAAGO,EAAa,IAAI,EAChE,WAAYZ,CACd,EAGO,CACL,OAAQY,EAAa,OACrB,KAAMA,EAAa,IACrB,CAEH,EACKC,EAAsB,IAAIR,EAAO,WAEjC,CAAE,KAAAS,CAAK,EAAIjB,EAAO,QAAQQ,EAAO,QAAQ,EACzCU,EAASC,EAAsB,CACnC,KAAMH,EACN,eAAgBhB,EAAO,YAAc,GAAK,GAAK,GAAGA,EAAO,aAAaiB,KACtE,UAAAN,EACA,QAAAG,CACF,CAAC,EAEKM,EAAiBhB,EAAK,KAAKD,EAAuBa,EAAsB,MAAM,EACpF,MAAMK,EAAuBH,EAAQE,EAAgB,4BAA4B,EAGjFb,EAAuB,KAAK,CAC1B,OAAQS,EACR,SAAU,GAAGA,QACb,WAAY,IACd,CAAC,EAIH,IAAME,EAASI,EAAY,CACzB,cAAetB,EAAO,mBACtB,QAASO,EACT,gBAAiBP,EAAO,gBACxB,gBAAiBA,EAAO,eAC1B,CAAC,EAEKoB,EAAiBhB,EAAK,KAAKD,EAAuBH,EAAO,mBAAqB,MAAM,EAC1F,MAAMqB,EAAuBH,EAAQE,EAAgB,4BAA4B,CACnF","names":["renderArguments","renderList","renderedSolidityHeader","renderImports","renderSystemInterface","options","imports","name","functionPrefix","functions","parameters","stateMutability","returnParameters","renderReturnParameters","renderArguments","renderedSolidityHeader","renderAbsoluteImports","renderRelativeImports","renderWorld","options","interfaceName","storeImportPath","worldImportPath","imports","baseImports","importSymbols","symbol","readFileSync","path","formatAndWriteSolidity","contractToInterface","worldgen","config","existingContracts","outputBaseDirectory","worldgenBaseDirectory","path","systems","basename","systemInterfaceImports","system","data","readFileSync","functions","symbolImports","contractToInterface","imports","symbolImport","systemInterfaceName","name","output","renderSystemInterface","fullOutputPath","formatAndWriteSolidity","renderWorld"]}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|