@latticexyz/world 2.0.0-alpha.1.48 → 2.0.0-alpha.1.49
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-3QXNZECS.js +28 -0
- package/dist/chunk-3QXNZECS.js.map +1 -0
- package/dist/chunk-SBTH4LWF.js +2 -0
- package/dist/chunk-SBTH4LWF.js.map +1 -0
- package/dist/mud.config.js +1 -1
- package/dist/ts/library/index.js +1 -1
- package/dist/ts/register/index.js +1 -1
- package/package.json +7 -7
- package/ts/library/config/resolveWorldConfig.ts +11 -2
- package/ts/register/index.test.ts +26 -0
- package/ts/register/index.ts +1 -0
- package/dist/chunk-EPL7W3PZ.js +0 -28
- package/dist/chunk-EPL7W3PZ.js.map +0 -1
- package/dist/chunk-JTTYJCC2.js +0 -2
- package/dist/chunk-JTTYJCC2.js.map +0 -1
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import{getDuplicates as P,MUDError as N,STORE_SELECTOR_MAX_LENGTH as z,UnrecognizedSystemErrorFactory as S}from"@latticexyz/config";function h(r,o){let i=o?.filter(t=>t.endsWith("System")&&t!=="System"&&!t.match(/^I[A-Z]/))??[],s=Object.keys(r.overrideSystems);if(o){for(let t of s)if(!o.includes(t)||t==="World")throw S(["overrideSystems",t],t)}let a=[...new Set([...i,...s])].filter(t=>!r.excludeSystems.includes(t)).reduce((t,d)=>({...t,[d]:D(d,r.overrideSystems[d],o)}),{}),m=Object.values(r.tables).map(({name:t})=>t),l=Object.values(a).map(({name:t})=>t),c=P([...m,...l]);if(c.length>0)throw new N(`Table and system names must be unique: ${c.join(", ")}`);return{systems:a}}function D(r,o,i){let s=o?.name??r.slice(0,z),n=o?.registerFunctionSelectors??!0,a=o?.openAccess??!0,m=[],l=[],c=o&&!o.openAccess?o.accessList:[];for(let t of c)if(t.startsWith("0x"))m.push(t);else{if(i&&!i.includes(t))throw S(["overrideSystems",r,"accessList"],t);l.push(t)}return{name:s,registerFunctionSelectors:n,openAccess:a,accessListAddresses:m,accessListSystems:l}}import{z as e}from"zod";import{DynamicResolutionType as O,zEthereumAddress as L,zObjectName as g,zSelector as I}from"@latticexyz/config";var y=g,T=g,E=e.array(y.or(L)).default([]),F=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:E})])),_=e.object({value:e.union([e.string(),e.number(),e.instanceof(Uint8Array)]),type:e.string()}),B=e.object({type:e.nativeEnum(O),input:e.string()}),M=e.object({name:T,root:e.boolean().default(!1),args:e.array(e.union([_,B])).default([])}),U=e.object({namespace:I.default(""),worldContractName:e.string().optional(),worldInterfaceName:e.string().default("IWorld"),overrideSystems:e.record(y,F).default({}),excludeSystems:e.array(y).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(M).default([])}),oe=U.catchall(e.any());import{renderArguments as b,renderList as G,renderedSolidityHeader as H,renderImports as k}from"@latticexyz/common/codegen";function W(r){let{imports:o,name:i,functionPrefix:s,functions:n}=r;return`${H}
|
|
2
|
+
|
|
3
|
+
${k(o)}
|
|
4
|
+
|
|
5
|
+
interface ${i} {
|
|
6
|
+
${G(n,({name:a,parameters:m,stateMutability:l,returnParameters:c})=>`
|
|
7
|
+
function ${s}${a}(
|
|
8
|
+
${b(m)}
|
|
9
|
+
) external ${l} ${K(c)};
|
|
10
|
+
`)}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
`}function K(r){return r.length>0?`returns (${b(r)})`:""}import{renderArguments as q,renderedSolidityHeader as V,renderAbsoluteImports as X,renderRelativeImports as Z}from"@latticexyz/common/codegen";function $(r){let{interfaceName:o,storeImportPath:i,worldImportPath:s,imports:n}=r,a=o==="IBaseWorld"?[{symbol:"IStore",path:`${i}IStore.sol`},{symbol:"IWorldKernel",path:`${s}interfaces/IWorldKernel.sol`}]:[{symbol:"IBaseWorld",path:`${s}interfaces/IBaseWorld.sol`}],m=[...a,...n].map(({symbol:l})=>l);return`${V}
|
|
14
|
+
|
|
15
|
+
${X(a)}
|
|
16
|
+
|
|
17
|
+
${Z(n)}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The ${o} interface includes all systems dynamically added to the World
|
|
21
|
+
* during the deploy process.
|
|
22
|
+
*/
|
|
23
|
+
interface ${o} is ${q(m)} {
|
|
24
|
+
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
`}import{readFileSync as J}from"fs";import f from"path";import{formatAndWriteSolidity as v,contractToInterface as Q}from"@latticexyz/common/codegen";async function be(r,o,i){let s=h(r,o.map(({basename:t})=>t)),n=f.join(i,r.worldgenDirectory),a=o.filter(({basename:t})=>Object.keys(s.systems).includes(t)),m=[];for(let t of a){let d=J(t.path,"utf8"),{functions:w,symbolImports:x}=Q(d,t.basename),C=x.map(p=>p.path[0]==="."?{symbol:p.symbol,fromPath:f.join(f.dirname(t.path),p.path),usedInPath:n}:{symbol:p.symbol,path:p.path}),u=`I${t.basename}`,{name:A}=s.systems[t.basename],R=W({name:u,functionPrefix:r.namespace===""?"":`${r.namespace}_${A}_`,functions:w,imports:C}),j=f.join(n,u+".sol");await v(R,j,"Generated system interface"),m.push({symbol:u,fromPath:`${u}.sol`,usedInPath:"./"})}let l=$({interfaceName:r.worldInterfaceName,imports:m,storeImportPath:r.storeImportPath,worldImportPath:r.worldImportPath}),c=f.join(n,r.worldInterfaceName+".sol");await v(l,c,"Generated system interface")}export{h as a,D as b,U as c,oe as d,W as e,$ as f,be as g};
|
|
28
|
+
//# sourceMappingURL=chunk-3QXNZECS.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 { getDuplicates, MUDError, STORE_SELECTOR_MAX_LENGTH, UnrecognizedSystemErrorFactory } from \"@latticexyz/config\";\nimport { StoreConfig } from \"@latticexyz/store\";\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: StoreConfig & 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 // Table and system names must be unique (because they're both used for world selectors)\n const tableNames = Object.values(config.tables).map(({ name }) => name);\n const configuredSystemNames = Object.values(resolvedSystems).map(({ name }) => name);\n const duplicateNames = getDuplicates([...tableNames, ...configuredSystemNames]);\n if (duplicateNames.length > 0) {\n throw new MUDError(`Table and system names must be unique: ${duplicateNames.join(\", \")}`);\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.slice(0, STORE_SELECTOR_MAX_LENGTH);\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,iBAAAA,EAAe,YAAAC,EAAU,6BAAAC,EAA2B,kCAAAC,MAAsC,qBAa5F,SAASC,EAAmBC,EAAmCC,EAA8B,CAElG,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,EAWtF,IAAMC,EALc,CAAC,GAAG,IAAI,IAAI,CAAC,GAAGJ,EAAoB,GAAGE,CAAqB,CAAC,CAAC,EAAE,OACjFD,GAAS,CAACH,EAAO,eAAe,SAASG,CAAI,CAChD,EAG0E,OAAO,CAACI,EAAKF,KAC9E,CACL,GAAGE,EACH,CAACF,CAAU,EAAGG,EAAoBH,EAAYL,EAAO,gBAAgBK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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":["getDuplicates","MUDError","STORE_SELECTOR_MAX_LENGTH","UnrecognizedSystemErrorFactory","resolveWorldConfig","config","existingContracts","defaultSystemNames","name","overriddenSystemNames","systemName","resolvedSystems","acc","resolveSystemConfig","tableNames","configuredSystemNames","duplicateNames","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-3QXNZECS.js";import"@latticexyz/store/register";import{mudConfig as g,mudCoreConfig as s,resolveTableId as u}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{g as a,s as b,u as c};
|
|
2
|
+
//# sourceMappingURL=chunk-SBTH4LWF.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\nimport \"@latticexyz/store/register\";\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,MAAO,6BACP,OAAS,aAAAA,EAAW,iBAAAC,EAAe,kBAAAC,MAAsB,6BCPzD,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{a as e}from"./chunk-
|
|
1
|
+
import{a as e}from"./chunk-SBTH4LWF.js";import"./chunk-3QXNZECS.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",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/ts/library/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a,b,c,d,e,f,g}from"../../chunk-
|
|
1
|
+
import{a,b,c,d,e,f,g}from"../../chunk-3QXNZECS.js";export{e as renderSystemInterface,f as renderWorld,b as resolveSystemConfig,a as resolveWorldConfig,g as worldgen,d as zPluginWorldConfig,c as zWorldConfig};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a,b,c}from"../../chunk-
|
|
1
|
+
import{a,b,c}from"../../chunk-SBTH4LWF.js";import"../../chunk-3QXNZECS.js";export{a as mudConfig,b as mudCoreConfig,c as resolveTableId};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
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.49+b4e12cbb",
|
|
4
4
|
"description": "World framework",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -40,15 +40,15 @@
|
|
|
40
40
|
"gas-report": "../cli/dist/mud.js gas-report --path test/* --path test/**/* --save gas-report.json",
|
|
41
41
|
"lint": "solhint --config ./.solhint.json 'src/**/*.sol'",
|
|
42
42
|
"release": "npm publish --access=public",
|
|
43
|
-
"test": "tsc --noEmit && forge test"
|
|
43
|
+
"test": "tsc --noEmit && vitest --run && forge test"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@ethersproject/abi": "^5.7.0",
|
|
47
47
|
"@ethersproject/providers": "^5.7.2",
|
|
48
|
-
"@latticexyz/common": "2.0.0-alpha.1.
|
|
49
|
-
"@latticexyz/config": "2.0.0-alpha.1.
|
|
50
|
-
"@latticexyz/schema-type": "2.0.0-alpha.1.
|
|
51
|
-
"@latticexyz/store": "2.0.0-alpha.1.
|
|
48
|
+
"@latticexyz/common": "2.0.0-alpha.1.49+b4e12cbb",
|
|
49
|
+
"@latticexyz/config": "2.0.0-alpha.1.49+b4e12cbb",
|
|
50
|
+
"@latticexyz/schema-type": "2.0.0-alpha.1.49+b4e12cbb",
|
|
51
|
+
"@latticexyz/store": "2.0.0-alpha.1.49+b4e12cbb",
|
|
52
52
|
"ethers": "^5.7.2",
|
|
53
53
|
"zod": "^3.21.4"
|
|
54
54
|
},
|
|
@@ -73,5 +73,5 @@
|
|
|
73
73
|
"typescript": "^4.9.5",
|
|
74
74
|
"vitest": "0.30.1"
|
|
75
75
|
},
|
|
76
|
-
"gitHead": "
|
|
76
|
+
"gitHead": "b4e12cbb81079d91f5c5f51cc2aa37f5bc0e638e"
|
|
77
77
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { STORE_SELECTOR_MAX_LENGTH, UnrecognizedSystemErrorFactory } from "@latticexyz/config";
|
|
1
|
+
import { getDuplicates, MUDError, STORE_SELECTOR_MAX_LENGTH, UnrecognizedSystemErrorFactory } from "@latticexyz/config";
|
|
2
|
+
import { StoreConfig } from "@latticexyz/store";
|
|
2
3
|
import { SystemConfig, WorldConfig } from "./types";
|
|
3
4
|
|
|
4
5
|
export type ResolvedSystemConfig = ReturnType<typeof resolveSystemConfig>;
|
|
@@ -10,7 +11,7 @@ export type ResolvedWorldConfig = ReturnType<typeof resolveWorldConfig>;
|
|
|
10
11
|
* filtering out excluded systems, validate system names refer to existing contracts, and
|
|
11
12
|
* splitting the access list into addresses and system names.
|
|
12
13
|
*/
|
|
13
|
-
export function resolveWorldConfig(config: WorldConfig, existingContracts?: string[]) {
|
|
14
|
+
export function resolveWorldConfig(config: StoreConfig & WorldConfig, existingContracts?: string[]) {
|
|
14
15
|
// Include contract names ending in "System", but not the base "System" contract, and not Interfaces
|
|
15
16
|
const defaultSystemNames =
|
|
16
17
|
existingContracts?.filter((name) => name.endsWith("System") && name !== "System" && !name.match(/^I[A-Z]/)) ?? [];
|
|
@@ -38,6 +39,14 @@ export function resolveWorldConfig(config: WorldConfig, existingContracts?: stri
|
|
|
38
39
|
};
|
|
39
40
|
}, {});
|
|
40
41
|
|
|
42
|
+
// Table and system names must be unique (because they're both used for world selectors)
|
|
43
|
+
const tableNames = Object.values(config.tables).map(({ name }) => name);
|
|
44
|
+
const configuredSystemNames = Object.values(resolvedSystems).map(({ name }) => name);
|
|
45
|
+
const duplicateNames = getDuplicates([...tableNames, ...configuredSystemNames]);
|
|
46
|
+
if (duplicateNames.length > 0) {
|
|
47
|
+
throw new MUDError(`Table and system names must be unique: ${duplicateNames.join(", ")}`);
|
|
48
|
+
}
|
|
49
|
+
|
|
41
50
|
return { systems: resolvedSystems };
|
|
42
51
|
}
|
|
43
52
|
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { expect, test } from "vitest";
|
|
2
|
+
import { mudConfig } from ".";
|
|
3
|
+
import { resolveWorldConfig } from "../library";
|
|
4
|
+
|
|
5
|
+
test("resolveWorldConfig requires unique table and system names", () => {
|
|
6
|
+
expect(() =>
|
|
7
|
+
resolveWorldConfig(
|
|
8
|
+
mudConfig({
|
|
9
|
+
tables: {
|
|
10
|
+
Table: {
|
|
11
|
+
name: "Selector",
|
|
12
|
+
schema: "uint256",
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
overrideSystems: {
|
|
16
|
+
TestSystem: {
|
|
17
|
+
name: "Selector",
|
|
18
|
+
openAccess: false,
|
|
19
|
+
accessList: [],
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
}),
|
|
23
|
+
["TestSystem"]
|
|
24
|
+
)
|
|
25
|
+
).toThrowError("Table and system names must be unique: Selector");
|
|
26
|
+
});
|
package/ts/register/index.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
// For convenience register and reexport store (which does the same for core config),
|
|
6
6
|
// to reduce the number of needed imports for users
|
|
7
|
+
import "@latticexyz/store/register";
|
|
7
8
|
export { mudConfig, mudCoreConfig, resolveTableId } from "@latticexyz/store/register";
|
|
8
9
|
// Extend core config and types
|
|
9
10
|
import "./configExtensions";
|
package/dist/chunk-EPL7W3PZ.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import{STORE_SELECTOR_MAX_LENGTH as z,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]:j(a,t.overrideSystems[a],o)}),{})}}function j(t,o,m){let n=o?.name??t.slice(0,z),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 N,zEthereumAddress as D,zObjectName as h,zSelector as I}from"@latticexyz/config";var u=h,L=h,O=e.array(u.or(D)).default([]),T=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:O})])),E=e.object({value:e.union([e.string(),e.number(),e.instanceof(Uint8Array)]),type:e.string()}),F=e.object({type:e.nativeEnum(N),input:e.string()}),_=e.object({name:L,root:e.boolean().default(!1),args:e.array(e.union([E,F])).default([])}),B=e.object({namespace:I.default(""),worldContractName:e.string().optional(),worldInterfaceName:e.string().default("IWorld"),overrideSystems:e.record(u,T).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(_).default([])}),te=B.catchall(e.any());import{renderArguments as g,renderList as G,renderedSolidityHeader as H,renderImports as M}from"@latticexyz/common/codegen";function b(t){let{imports:o,name:m,functionPrefix:n,functions:i}=t;return`${H}
|
|
2
|
-
|
|
3
|
-
${M(o)}
|
|
4
|
-
|
|
5
|
-
interface ${m} {
|
|
6
|
-
${G(i,({name:l,parameters:r,stateMutability:a,returnParameters:c})=>`
|
|
7
|
-
function ${n}${l}(
|
|
8
|
-
${g(r)}
|
|
9
|
-
) external ${a} ${U(c)};
|
|
10
|
-
`)}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
`}function U(t){return t.length>0?`returns (${g(t)})`:""}import{renderArguments as k,renderedSolidityHeader as K,renderAbsoluteImports as V,renderRelativeImports as X}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`${K}
|
|
14
|
-
|
|
15
|
-
${V(l)}
|
|
16
|
-
|
|
17
|
-
${X(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 Ie(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],R=b({name:f,functionPrefix:t.namespace===""?"":`${t.namespace}_${C}_`,functions:x,imports:A}),P=p.join(i,f+".sol");await $(R,P,"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,j as b,B as c,te as d,b as e,W as f,Ie as g};
|
|
28
|
-
//# sourceMappingURL=chunk-EPL7W3PZ.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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 { STORE_SELECTOR_MAX_LENGTH, 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.slice(0, STORE_SELECTOR_MAX_LENGTH);\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,6BAAAA,EAA2B,kCAAAC,MAAsC,qBAYnE,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,GAAG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sB,EAAiBf,EAAK,KAAKD,EAAuBN,EAAO,mBAAqB,MAAM,EAC1F,MAAMuB,EAAuBH,EAAQE,EAAgB,4BAA4B,CACnF","names":["STORE_SELECTOR_MAX_LENGTH","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"]}
|
package/dist/chunk-JTTYJCC2.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{d as o}from"./chunk-EPL7W3PZ.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-JTTYJCC2.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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"]}
|