@latticexyz/world 2.0.0-alpha.1.93 → 2.0.0-alpha.1.95
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-ERVVJTMR.js +2 -0
- package/dist/chunk-ERVVJTMR.js.map +1 -0
- package/dist/chunk-OWSPJIEF.js +1 -0
- package/dist/chunk-OWSPJIEF.js.map +1 -0
- package/dist/{chunk-4746NAFE.js → chunk-ZQK5MJZC.js} +2 -2
- package/dist/mud.config.js +1 -1
- package/dist/mud.config.js.map +1 -1
- package/dist/ts/library/index.js +1 -1
- package/dist/ts/node/index.js +30 -0
- package/dist/ts/node/index.js.map +1 -0
- package/dist/ts/register/index.js +1 -1
- package/package.json +10 -6
- package/ts/library/index.ts +0 -1
- package/ts/node/index.ts +1 -0
- package/ts/{library → node}/render-solidity/worldgen.ts +1 -1
- package/ts/scripts/tablegen.ts +1 -1
- package/ts/scripts/worldgen.ts +3 -2
- package/dist/chunk-4PLEKSTO.js +0 -30
- package/dist/chunk-4PLEKSTO.js.map +0 -1
- /package/dist/{chunk-4746NAFE.js.map → chunk-ZQK5MJZC.js.map} +0 -0
- /package/ts/{library → node}/render-solidity/index.ts +0 -0
- /package/ts/{library → node}/render-solidity/renderSystemInterface.ts +0 -0
- /package/ts/{library → node}/render-solidity/renderWorld.ts +0 -0
- /package/ts/{library → node}/render-solidity/types.ts +0 -0
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var m={registerFunctionSelector:!0,openAccess:!0,accessList:[]},o={worldContractName:void 0,worldInterfaceName:"IWorld",overrideSystems:{},excludeSystems:[],postDeployScript:"PostDeploy",deploysDirectory:"./deploys",worldsFile:"./worlds.json",worldgenDirectory:"world",worldImportPath:"@latticexyz/world/src/",modules:[]};import{getDuplicates as g,STORE_SELECTOR_MAX_LENGTH as w,UnrecognizedSystemErrorFactory as f}from"@latticexyz/config";import{MUDError as v}from"@latticexyz/common/errors";function R(r,s){let n=s?.filter(t=>t.endsWith("System")&&t!=="System"&&!t.match(/^I[A-Z]/))??[],c=Object.keys(r.overrideSystems);if(s){for(let t of c)if(!s.includes(t)||t==="World")throw f(["overrideSystems",t],t)}let i=[...new Set([...n,...c])].filter(t=>!r.excludeSystems.includes(t)).reduce((t,u)=>({...t,[u]:D(u,r.overrideSystems[u],s)}),{}),l=Object.values(r.tables).map(({name:t})=>t),a=Object.values(i).map(({name:t})=>t),d=g([...l,...a]);if(d.length>0)throw new v(`Table and system names must be unique: ${d.join(", ")}`);return{systems:i}}function D(r,s,n){let c=s?.name??r.slice(0,w),p=s?.registerFunctionSelectors??!0,i=s?.openAccess??!0,l=[],a=[],d=s&&!s.openAccess?s.accessList:[];for(let t of d)if(t.startsWith("0x"))l.push(t);else{if(n&&!n.includes(t))throw f(["overrideSystems",r,"accessList"],t);a.push(t)}return{name:c,registerFunctionSelectors:p,openAccess:i,accessListAddresses:l,accessListSystems:a}}import{z as e}from"zod";import{DynamicResolutionType as b,zEthereumAddress as A,zObjectName as S,zSelector as L}from"@latticexyz/config";var y=S,C=S,h=e.array(y.or(A)).default(m.accessList),z=e.intersection(e.object({name:L,registerFunctionSelectors:e.boolean().default(m.registerFunctionSelector)}),e.discriminatedUnion("openAccess",[e.object({openAccess:e.literal(!0).default(m.openAccess)}),e.object({openAccess:e.literal(!1),accessList:h})])),x=e.object({value:e.union([e.string(),e.number(),e.instanceof(Uint8Array)]),type:e.string()}),E=e.object({type:e.nativeEnum(b),input:e.string()}),N=e.object({name:C,root:e.boolean().default(!1),args:e.array(e.union([x,E])).default([])}),T=e.object({worldContractName:e.string().optional(),worldInterfaceName:e.string().default(o.worldInterfaceName),overrideSystems:e.record(y,z).default(o.overrideSystems),excludeSystems:e.array(y).default(o.excludeSystems),postDeployScript:e.string().default(o.postDeployScript),deploysDirectory:e.string().default(o.deploysDirectory),worldsFile:e.string().default(o.worldsFile),worldgenDirectory:e.string().default(o.worldgenDirectory),worldImportPath:e.string().default(o.worldImportPath),modules:e.array(N).default(o.modules)}),M=T.catchall(e.any());export{m as a,o as b,R as c,D as d,T as e,M as f};
|
|
2
|
+
//# sourceMappingURL=chunk-ERVVJTMR.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../ts/library/config/defaults.ts","../ts/library/config/resolveWorldConfig.ts","../ts/library/config/worldConfig.ts"],"sourcesContent":["export const SYSTEM_DEFAULTS = {\n registerFunctionSelector: true,\n openAccess: true,\n accessList: [] as string[],\n} as const;\n\nexport const WORLD_DEFAULTS = {\n worldContractName: undefined,\n worldInterfaceName: \"IWorld\",\n overrideSystems: {} as Record<string, never>,\n excludeSystems: [] as string[],\n postDeployScript: \"PostDeploy\",\n deploysDirectory: \"./deploys\",\n worldsFile: \"./worlds.json\",\n worldgenDirectory: \"world\",\n worldImportPath: \"@latticexyz/world/src/\",\n modules: [] as [],\n} as const;\n","import { getDuplicates, STORE_SELECTOR_MAX_LENGTH, UnrecognizedSystemErrorFactory } from \"@latticexyz/config\";\nimport { MUDError } from \"@latticexyz/common/errors\";\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\";\nimport { SYSTEM_DEFAULTS, WORLD_DEFAULTS } from \"./defaults\";\n\nconst zSystemName = zObjectName;\nconst zModuleName = zObjectName;\nconst zSystemAccessList = z.array(zSystemName.or(zEthereumAddress)).default(SYSTEM_DEFAULTS.accessList);\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(SYSTEM_DEFAULTS.registerFunctionSelector),\n }),\n z.discriminatedUnion(\"openAccess\", [\n z.object({\n openAccess: z.literal(true).default(SYSTEM_DEFAULTS.openAccess),\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 worldContractName: z.string().optional(),\n worldInterfaceName: z.string().default(WORLD_DEFAULTS.worldInterfaceName),\n overrideSystems: z.record(zSystemName, zSystemConfig).default(WORLD_DEFAULTS.overrideSystems),\n excludeSystems: z.array(zSystemName).default(WORLD_DEFAULTS.excludeSystems),\n postDeployScript: z.string().default(WORLD_DEFAULTS.postDeployScript),\n deploysDirectory: z.string().default(WORLD_DEFAULTS.deploysDirectory),\n worldsFile: z.string().default(WORLD_DEFAULTS.worldsFile),\n worldgenDirectory: z.string().default(WORLD_DEFAULTS.worldgenDirectory),\n worldImportPath: z.string().default(WORLD_DEFAULTS.worldImportPath),\n modules: z.array(zModuleConfig).default(WORLD_DEFAULTS.modules),\n});\n\n// Catchall preserves other plugins' options\nexport const zPluginWorldConfig = zWorldConfig.catchall(z.any());\n"],"mappings":"AAAO,IAAMA,EAAkB,CAC7B,yBAA0B,GAC1B,WAAY,GACZ,WAAY,CAAC,CACf,EAEaC,EAAiB,CAC5B,kBAAmB,OACnB,mBAAoB,SACpB,gBAAiB,CAAC,EAClB,eAAgB,CAAC,EACjB,iBAAkB,aAClB,iBAAkB,YAClB,WAAY,gBACZ,kBAAmB,QACnB,gBAAiB,yBACjB,QAAS,CAAC,CACZ,ECjBA,OAAS,iBAAAC,EAAe,6BAAAC,EAA2B,kCAAAC,MAAsC,qBACzF,OAAS,YAAAC,MAAgB,4BAalB,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,MAAMR,EAA+B,CAAC,kBAAmBQ,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,CAAU,EAAGJ,CAAiB,CACrG,GACC,CAAC,CAAC,EAGCQ,EAAa,OAAO,OAAOT,EAAO,MAAM,EAAE,IAAI,CAAC,CAAE,KAAAG,CAAK,IAAMA,CAAI,EAChEO,EAAwB,OAAO,OAAOJ,CAAe,EAAE,IAA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AI,CAAC","names":["SYSTEM_DEFAULTS","WORLD_DEFAULTS","getDuplicates","STORE_SELECTOR_MAX_LENGTH","UnrecognizedSystemErrorFactory","MUDError","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","zObjectName","zModuleName","zSystemAccessList","z","zEthereumAddress","SYSTEM_DEFAULTS","zSystemConfig","zSelector","zValueWithType","zDynamicResolution","DynamicResolutionType","zModuleConfig","zWorldConfig","WORLD_DEFAULTS","zPluginWorldConfig"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=chunk-OWSPJIEF.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{f as o}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{f as o}from"./chunk-ERVVJTMR.js";import"@latticexyz/store/register";import{mudConfig as c,mudCoreConfig as C,resolveTableId as g}from"@latticexyz/store/register";import{extendMUDCoreConfig as t,fromZodErrorCustom as i}from"@latticexyz/config";import{ZodError as d}from"zod";t(r=>{try{return o.parse(r)}catch(e){throw e instanceof d?i(e,"WorldConfig Validation Error"):e}});import"@latticexyz/store/register";export{c as a,C as b,g as c};
|
|
2
|
+
//# sourceMappingURL=chunk-ZQK5MJZC.js.map
|
package/dist/mud.config.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as e}from"./chunk-
|
|
1
|
+
import{a as e}from"./chunk-ZQK5MJZC.js";import"./chunk-OWSPJIEF.js";import"./chunk-ERVVJTMR.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},KeysInTable:{directory:"modules/keysintable/tables",primaryKeys:{sourceTable:"bytes32"},schema:{length:"uint32",keys:"bytes32[]"}},UsedKeysIndex:{directory:"modules/keysintable/tables",primaryKeys:{sourceTable:"bytes32",keysHash:"bytes32"},schema:{has:"bool",index:"uint32"},dataStruct:!1},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 \"./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 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 KeysInTable: {\n directory: \"modules/keysintable/tables\",\n primaryKeys: { sourceTable: \"bytes32\" },\n schema: { length: \"uint32\", keys: \"bytes32[]\" }, // For now only indexes the first key of a primary key tuple\n },\n UsedKeysIndex: {\n directory: \"modules/keysintable/tables\",\n primaryKeys: {\n sourceTable: \"bytes32\",\n keysHash: \"bytes32\",\n },\n schema: { has: \"bool\", index: \"uint32\" },\n dataStruct: false,\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":"
|
|
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 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 KeysInTable: {\n directory: \"modules/keysintable/tables\",\n primaryKeys: { sourceTable: \"bytes32\" },\n schema: { length: \"uint32\", keys: \"bytes32[]\" }, // For now only indexes the first key of a primary key tuple\n },\n UsedKeysIndex: {\n directory: \"modules/keysintable/tables\",\n primaryKeys: {\n sourceTable: \"bytes32\",\n keysHash: \"bytes32\",\n },\n schema: { has: \"bool\", index: \"uint32\" },\n dataStruct: false,\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":"gGAEA,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,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,YAAa,CACX,UAAW,6BACX,YAAa,CAAE,YAAa,SAAU,EACtC,OAAQ,CAAE,OAAQ,SAAU,KAAM,WAAY,CAChD,EACA,cAAe,CACb,UAAW,6BACX,YAAa,CACX,YAAa,UACb,SAAU,SACZ,EACA,OAAQ,CAAE,IAAK,OAAQ,MAAO,QAAS,EACvC,WAAY,EACd,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"]}
|
package/dist/ts/library/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a,b,c,d,e,f
|
|
1
|
+
import"../../chunk-OWSPJIEF.js";import{a,b,c,d,e,f}from"../../chunk-ERVVJTMR.js";export{a as SYSTEM_DEFAULTS,b as WORLD_DEFAULTS,d as resolveSystemConfig,c as resolveWorldConfig,f as zPluginWorldConfig,e as zWorldConfig};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import{c as u}from"../../chunk-ERVVJTMR.js";import{renderArguments as c,renderList as y,renderedSolidityHeader as O,renderImports as A}from"@latticexyz/common/codegen";function I(e){let{imports:r,name:i,functionPrefix:s,functions:o,errors:m}=e;return`${O}
|
|
2
|
+
|
|
3
|
+
${A(r)}
|
|
4
|
+
|
|
5
|
+
interface ${i} {
|
|
6
|
+
${y(m,({name:n,parameters:a})=>`error ${n}(${c(a)});`)}
|
|
7
|
+
|
|
8
|
+
${y(o,({name:n,parameters:a,stateMutability:f,returnParameters:t})=>`
|
|
9
|
+
function ${s}${n}(
|
|
10
|
+
${c(a)}
|
|
11
|
+
) external ${f} ${D(t)};
|
|
12
|
+
`)}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
`}function D(e){return e.length>0?`returns (${c(e)})`:""}import{renderArguments as j,renderedSolidityHeader as v,renderAbsoluteImports as C,renderRelativeImports as N}from"@latticexyz/common/codegen";function h(e){let{interfaceName:r,storeImportPath:i,worldImportPath:s,imports:o}=e,m=r==="IBaseWorld"?[{symbol:"IStore",path:`${i}IStore.sol`},{symbol:"IWorldKernel",path:`${s}interfaces/IWorldKernel.sol`}]:[{symbol:"IBaseWorld",path:`${s}interfaces/IBaseWorld.sol`}],n=[...m,...o].map(({symbol:a})=>a);return`${v}
|
|
16
|
+
|
|
17
|
+
${C(m)}
|
|
18
|
+
|
|
19
|
+
${N(o)}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The ${r} interface includes all systems dynamically added to the World
|
|
23
|
+
* during the deploy process.
|
|
24
|
+
*/
|
|
25
|
+
interface ${r} is ${j(n)} {
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
`}import{readFileSync as B}from"fs";import l from"path";import{formatAndWriteSolidity as $,contractToInterface as G}from"@latticexyz/common/codegen";async function M(e,r,i){let s=u(e,r.map(({basename:t})=>t)),o=l.join(i,e.worldgenDirectory),m=r.filter(({basename:t})=>Object.keys(s.systems).includes(t)),n=[];for(let t of m){let b=B(t.path,"utf8"),{functions:P,errors:W,symbolImports:S}=G(b,t.basename),w=S.map(p=>p.path[0]==="."?{symbol:p.symbol,fromPath:l.join(l.dirname(t.path),p.path),usedInPath:o}:{symbol:p.symbol,path:p.path}),d=`I${t.basename}`,{name:x}=s.systems[t.basename],g=I({name:d,functionPrefix:e.namespace===""?"":`${e.namespace}_${x}_`,functions:P,errors:W,imports:w}),R=l.join(o,d+".sol");await $(g,R,"Generated system interface"),n.push({symbol:d,fromPath:`${d}.sol`,usedInPath:"./"})}let a=h({interfaceName:e.worldInterfaceName,imports:n,storeImportPath:e.storeImportPath,worldImportPath:e.worldImportPath}),f=l.join(o,e.worldInterfaceName+".sol");await $(a,f,"Generated system interface")}export{I as renderSystemInterface,h as renderWorld,M as worldgen};
|
|
30
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../ts/node/render-solidity/renderSystemInterface.ts","../../../ts/node/render-solidity/renderWorld.ts","../../../ts/node/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, errors } = options;\n\n return `${renderedSolidityHeader}\n\n${renderImports(imports)}\n\ninterface ${name} {\n ${renderList(errors, ({ name, parameters }) => `error ${name}(${renderArguments(parameters)});`)}\n\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 \"../../library/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, errors, 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 errors,\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":"4CAAA,OAAS,mBAAAA,EAAiB,cAAAC,EAAY,0BAAAC,EAAwB,iBAAAC,MAAqB,6BAG5E,SAASC,EAAsBC,EAAuC,CAC3E,GAAM,CAAE,QAAAC,EAAS,KAAAC,EAAM,eAAAC,EAAgB,UAAAC,EAAW,OAAAC,CAAO,EAAIL,EAE7D,MAAO,GAAGH;AAAA;AAAA,EAEVC,EAAcG,CAAO;AAAA;AAAA,YAEXC;AAAA,IACRN,EAAWS,EAAQ,CAAC,CAAE,KAAAH,EAAM,WAAAI,CAAW,IAAM,SAASJ,KAAQP,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renderImports","renderSystemInterface","options","imports","name","functionPrefix","functions","errors","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","errors","symbolImports","contractToInterface","imports","symbolImport","systemInterfaceName","name","output","renderSystemInterface","fullOutputPath","formatAndWriteSolidity","renderWorld"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a,b,c}from"../../chunk-
|
|
1
|
+
import{a,b,c}from"../../chunk-ZQK5MJZC.js";import"../../chunk-OWSPJIEF.js";import"../../chunk-ERVVJTMR.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.95+9347a5fb",
|
|
4
4
|
"description": "World framework",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"exports": {
|
|
13
13
|
".": "./dist/ts/library/index.js",
|
|
14
14
|
"./register": "./dist/ts/register/index.js",
|
|
15
|
+
"./node": "./dist/ts/node/index.js",
|
|
15
16
|
"./mud.config.js": "./dist/mud.config.js",
|
|
16
17
|
"./abi/*": "./abi/*",
|
|
17
18
|
"./types/*": "./types/*"
|
|
@@ -23,6 +24,9 @@
|
|
|
23
24
|
],
|
|
24
25
|
"register": [
|
|
25
26
|
"./ts/register/index.ts"
|
|
27
|
+
],
|
|
28
|
+
"node": [
|
|
29
|
+
"./ts/node/index.ts"
|
|
26
30
|
]
|
|
27
31
|
}
|
|
28
32
|
},
|
|
@@ -45,10 +49,10 @@
|
|
|
45
49
|
"dependencies": {
|
|
46
50
|
"@ethersproject/abi": "^5.7.0",
|
|
47
51
|
"@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.
|
|
52
|
+
"@latticexyz/common": "2.0.0-alpha.1.95+9347a5fb",
|
|
53
|
+
"@latticexyz/config": "2.0.0-alpha.1.95+9347a5fb",
|
|
54
|
+
"@latticexyz/schema-type": "2.0.0-alpha.1.95+9347a5fb",
|
|
55
|
+
"@latticexyz/store": "2.0.0-alpha.1.95+9347a5fb",
|
|
52
56
|
"ethers": "^5.7.2",
|
|
53
57
|
"zod": "^3.21.4"
|
|
54
58
|
},
|
|
@@ -73,5 +77,5 @@
|
|
|
73
77
|
"typescript": "^4.9.5",
|
|
74
78
|
"vitest": "0.30.1"
|
|
75
79
|
},
|
|
76
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "9347a5fbed1c690b4b6717f83d2f7dfe811d98a7"
|
|
77
81
|
}
|
package/ts/library/index.ts
CHANGED
package/ts/node/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./render-solidity";
|
|
@@ -4,7 +4,7 @@ import { formatAndWriteSolidity, contractToInterface, type RelativeImportDatum }
|
|
|
4
4
|
import { StoreConfig } from "@latticexyz/store";
|
|
5
5
|
import { renderSystemInterface } from "./renderSystemInterface";
|
|
6
6
|
import { renderWorld } from "./renderWorld";
|
|
7
|
-
import { resolveWorldConfig, WorldConfig } from "
|
|
7
|
+
import { resolveWorldConfig, WorldConfig } from "../../library/config";
|
|
8
8
|
|
|
9
9
|
export async function worldgen(
|
|
10
10
|
config: StoreConfig & WorldConfig,
|
package/ts/scripts/tablegen.ts
CHANGED
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 { loadConfig } from "@latticexyz/config";
|
|
4
|
+
import { loadConfig } from "@latticexyz/config/node";
|
|
5
5
|
import { getSrcDirectory } from "@latticexyz/common/foundry";
|
|
6
|
-
import { WorldConfig
|
|
6
|
+
import { WorldConfig } from "../library";
|
|
7
|
+
import { worldgen } from "../node";
|
|
7
8
|
import { StoreConfig } from "@latticexyz/store";
|
|
8
9
|
|
|
9
10
|
// TODO dedupe this and cli's worldgen command
|
package/dist/chunk-4PLEKSTO.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
var S={registerFunctionSelector:!0,openAccess:!0,accessList:[]},c={worldContractName:void 0,worldInterfaceName:"IWorld",overrideSystems:{},excludeSystems:[],postDeployScript:"PostDeploy",deploysDirectory:"./deploys",worldsFile:"./worlds.json",worldgenDirectory:"world",worldImportPath:"@latticexyz/world/src/",modules:[]};import{getDuplicates as j,STORE_SELECTOR_MAX_LENGTH as T,UnrecognizedSystemErrorFactory as I}from"@latticexyz/config";import{MUDError as z}from"@latticexyz/common/errors";function b(r,o){let l=o?.filter(e=>e.endsWith("System")&&e!=="System"&&!e.match(/^I[A-Z]/))??[],n=Object.keys(r.overrideSystems);if(o){for(let e of n)if(!o.includes(e)||e==="World")throw I(["overrideSystems",e],e)}let m=[...new Set([...l,...n])].filter(e=>!r.excludeSystems.includes(e)).reduce((e,p)=>({...e,[p]:O(p,r.overrideSystems[p],o)}),{}),s=Object.values(r.tables).map(({name:e})=>e),a=Object.values(m).map(({name:e})=>e),d=j([...s,...a]);if(d.length>0)throw new z(`Table and system names must be unique: ${d.join(", ")}`);return{systems:m}}function O(r,o,l){let n=o?.name??r.slice(0,T),i=o?.registerFunctionSelectors??!0,m=o?.openAccess??!0,s=[],a=[],d=o&&!o.openAccess?o.accessList:[];for(let e of d)if(e.startsWith("0x"))s.push(e);else{if(l&&!l.includes(e))throw I(["overrideSystems",r,"accessList"],e);a.push(e)}return{name:n,registerFunctionSelectors:i,openAccess:m,accessListAddresses:s,accessListSystems:a}}import{z as t}from"zod";import{DynamicResolutionType as E,zEthereumAddress as F,zObjectName as w,zSelector as _}from"@latticexyz/config";var g=w,U=w,M=t.array(g.or(F)).default(S.accessList),B=t.intersection(t.object({name:_,registerFunctionSelectors:t.boolean().default(S.registerFunctionSelector)}),t.discriminatedUnion("openAccess",[t.object({openAccess:t.literal(!0).default(S.openAccess)}),t.object({openAccess:t.literal(!1),accessList:M})])),G=t.object({value:t.union([t.string(),t.number(),t.instanceof(Uint8Array)]),type:t.string()}),H=t.object({type:t.nativeEnum(E),input:t.string()}),k=t.object({name:U,root:t.boolean().default(!1),args:t.array(t.union([G,H])).default([])}),K=t.object({worldContractName:t.string().optional(),worldInterfaceName:t.string().default(c.worldInterfaceName),overrideSystems:t.record(g,B).default(c.overrideSystems),excludeSystems:t.array(g).default(c.excludeSystems),postDeployScript:t.string().default(c.postDeployScript),deploysDirectory:t.string().default(c.deploysDirectory),worldsFile:t.string().default(c.worldsFile),worldgenDirectory:t.string().default(c.worldgenDirectory),worldImportPath:t.string().default(c.worldImportPath),modules:t.array(k).default(c.modules)}),le=K.catchall(t.any());import{renderArguments as h,renderList as W,renderedSolidityHeader as Y,renderImports as q}from"@latticexyz/common/codegen";function $(r){let{imports:o,name:l,functionPrefix:n,functions:i,errors:m}=r;return`${Y}
|
|
2
|
-
|
|
3
|
-
${q(o)}
|
|
4
|
-
|
|
5
|
-
interface ${l} {
|
|
6
|
-
${W(m,({name:s,parameters:a})=>`error ${s}(${h(a)});`)}
|
|
7
|
-
|
|
8
|
-
${W(i,({name:s,parameters:a,stateMutability:d,returnParameters:e})=>`
|
|
9
|
-
function ${n}${s}(
|
|
10
|
-
${h(a)}
|
|
11
|
-
) external ${d} ${V(e)};
|
|
12
|
-
`)}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
`}function V(r){return r.length>0?`returns (${h(r)})`:""}import{renderArguments as X,renderedSolidityHeader as Z,renderAbsoluteImports as J,renderRelativeImports as Q}from"@latticexyz/common/codegen";function v(r){let{interfaceName:o,storeImportPath:l,worldImportPath:n,imports:i}=r,m=o==="IBaseWorld"?[{symbol:"IStore",path:`${l}IStore.sol`},{symbol:"IWorldKernel",path:`${n}interfaces/IWorldKernel.sol`}]:[{symbol:"IBaseWorld",path:`${n}interfaces/IBaseWorld.sol`}],s=[...m,...i].map(({symbol:a})=>a);return`${Z}
|
|
16
|
-
|
|
17
|
-
${J(m)}
|
|
18
|
-
|
|
19
|
-
${Q(i)}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* The ${o} interface includes all systems dynamically added to the World
|
|
23
|
-
* during the deploy process.
|
|
24
|
-
*/
|
|
25
|
-
interface ${o} is ${X(s)} {
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
`}import{readFileSync as ee}from"fs";import u from"path";import{formatAndWriteSolidity as D,contractToInterface as te}from"@latticexyz/common/codegen";async function Ae(r,o,l){let n=b(r,o.map(({basename:e})=>e)),i=u.join(l,r.worldgenDirectory),m=o.filter(({basename:e})=>Object.keys(n.systems).includes(e)),s=[];for(let e of m){let p=ee(e.path,"utf8"),{functions:x,errors:A,symbolImports:C}=te(p,e.basename),R=C.map(f=>f.path[0]==="."?{symbol:f.symbol,fromPath:u.join(u.dirname(e.path),f.path),usedInPath:i}:{symbol:f.symbol,path:f.path}),y=`I${e.basename}`,{name:L}=n.systems[e.basename],N=$({name:y,functionPrefix:r.namespace===""?"":`${r.namespace}_${L}_`,functions:x,errors:A,imports:R}),P=u.join(i,y+".sol");await D(N,P,"Generated system interface"),s.push({symbol:y,fromPath:`${y}.sol`,usedInPath:"./"})}let a=v({interfaceName:r.worldInterfaceName,imports:s,storeImportPath:r.storeImportPath,worldImportPath:r.worldImportPath}),d=u.join(i,r.worldInterfaceName+".sol");await D(a,d,"Generated system interface")}export{S as a,c as b,b as c,O as d,K as e,le as f,$ as g,v as h,Ae as i};
|
|
30
|
-
//# sourceMappingURL=chunk-4PLEKSTO.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../ts/library/config/defaults.ts","../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":["export const SYSTEM_DEFAULTS = {\n registerFunctionSelector: true,\n openAccess: true,\n accessList: [] as string[],\n} as const;\n\nexport const WORLD_DEFAULTS = {\n worldContractName: undefined,\n worldInterfaceName: \"IWorld\",\n overrideSystems: {} as Record<string, never>,\n excludeSystems: [] as string[],\n postDeployScript: \"PostDeploy\",\n deploysDirectory: \"./deploys\",\n worldsFile: \"./worlds.json\",\n worldgenDirectory: \"world\",\n worldImportPath: \"@latticexyz/world/src/\",\n modules: [] as [],\n} as const;\n","import { getDuplicates, STORE_SELECTOR_MAX_LENGTH, UnrecognizedSystemErrorFactory } from \"@latticexyz/config\";\nimport { MUDError } from \"@latticexyz/common/errors\";\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\";\nimport { SYSTEM_DEFAULTS, WORLD_DEFAULTS } from \"./defaults\";\n\nconst zSystemName = zObjectName;\nconst zModuleName = zObjectName;\nconst zSystemAccessList = z.array(zSystemName.or(zEthereumAddress)).default(SYSTEM_DEFAULTS.accessList);\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(SYSTEM_DEFAULTS.registerFunctionSelector),\n }),\n z.discriminatedUnion(\"openAccess\", [\n z.object({\n openAccess: z.literal(true).default(SYSTEM_DEFAULTS.openAccess),\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 worldContractName: z.string().optional(),\n worldInterfaceName: z.string().default(WORLD_DEFAULTS.worldInterfaceName),\n overrideSystems: z.record(zSystemName, zSystemConfig).default(WORLD_DEFAULTS.overrideSystems),\n excludeSystems: z.array(zSystemName).default(WORLD_DEFAULTS.excludeSystems),\n postDeployScript: z.string().default(WORLD_DEFAULTS.postDeployScript),\n deploysDirectory: z.string().default(WORLD_DEFAULTS.deploysDirectory),\n worldsFile: z.string().default(WORLD_DEFAULTS.worldsFile),\n worldgenDirectory: z.string().default(WORLD_DEFAULTS.worldgenDirectory),\n worldImportPath: z.string().default(WORLD_DEFAULTS.worldImportPath),\n modules: z.array(zModuleConfig).default(WORLD_DEFAULTS.modules),\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, errors } = options;\n\n return `${renderedSolidityHeader}\n\n${renderImports(imports)}\n\ninterface ${name} {\n ${renderList(errors, ({ name, parameters }) => `error ${name}(${renderArguments(parameters)});`)}\n\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, errors, 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 errors,\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":"AAAO,IAAMA,EAAkB,CAC7B,yBAA0B,GAC1B,WAAY,GACZ,WAAY,CAAC,CACf,EAEaC,EAAiB,CAC5B,kBAAmB,OACnB,mBAAoB,SACpB,gBAAiB,CAAC,EAClB,eAAgB,CAAC,EACjB,iBAAkB,aAClB,iBAAkB,YAClB,WAAY,gBACZ,kBAAmB,QACnB,gBAAiB,yBACjB,QAAS,CAAC,CACZ,ECjBA,OAAS,iBAAAC,EAAe,6BAAAC,EAA2B,kCAAAC,MAAsC,qBACzF,OAAS,YAAAC,MAAgB,4BAalB,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,MAAMR,EAA+B,CAAC,kBAAmBQ,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,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QAAQ,EACjDW,EAASC,EAAsB,CACnC,KAAMH,EACN,eAAgBnB,EAAO,YAAc,GAAK,GAAK,GAAGA,EAAO,aAAaoB,KACtE,UAAAP,EACA,OAAAC,EACA,QAAAG,CACF,CAAC,EAEKM,EAAiBhB,EAAK,KAAKD,EAAuBa,EAAsB,MAAM,EACpF,MAAMK,EAAuBH,EAAQE,EAAgB,4BAA4B,EAGjFd,EAAuB,KAAK,CAC1B,OAAQU,EACR,SAAU,GAAGA,QACb,WAAY,IACd,CAAC,EAIH,IAAME,EAASI,EAAY,CACzB,cAAezB,EAAO,mBACtB,QAASS,EACT,gBAAiBT,EAAO,gBACxB,gBAAiBA,EAAO,eAC1B,CAAC,EAEKuB,EAAiBhB,EAAK,KAAKD,EAAuBN,EAAO,mBAAqB,MAAM,EAC1F,MAAMwB,EAAuBH,EAAQE,EAAgB,4BAA4B,CACnF","names":["SYSTEM_DEFAULTS","WORLD_DEFAULTS","getDuplicates","STORE_SELECTOR_MAX_LENGTH","UnrecognizedSystemErrorFactory","MUDError","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","zObjectName","zModuleName","zSystemAccessList","z","zEthereumAddress","SYSTEM_DEFAULTS","zSystemConfig","zSelector","zValueWithType","zDynamicResolution","DynamicResolutionType","zModuleConfig","zWorldConfig","WORLD_DEFAULTS","zPluginWorldConfig","renderArguments","renderList","renderedSolidityHeader","renderImports","renderSystemInterface","options","imports","name","functionPrefix","functions","errors","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","errors","symbolImports","contractToInterface","imports","symbolImport","systemInterfaceName","name","output","renderSystemInterface","fullOutputPath","formatAndWriteSolidity","renderWorld"]}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|