@latticexyz/world 2.0.0-main-e241c056 → 2.0.0-main-29c3f508

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.
@@ -0,0 +1,2 @@
1
+ import{STORE_NAME_MAX_LENGTH as d,UnrecognizedSystemErrorFactory as y}from"@latticexyz/config";function u(t,s){let n=s?.filter(e=>e.endsWith("System")&&e!=="System"&&!e.match(/^I[A-Z]/))??[],c=Object.keys(t.systems);if(s){for(let e of c)if(!s.includes(e)||e==="World")throw y(["systems",e],e)}return{systems:[...new Set([...n,...c])].filter(e=>!t.excludeSystems.includes(e)).reduce((e,o)=>({...e,[o]:f(o,t.systems[o],s)}),{})}}function f(t,s,n){let c=(s?.name??t).slice(0,d),i=s?.registerFunctionSelectors??!0,m=s?.openAccess??!0,e=[],o=[],l=s&&!s.openAccess?s.accessList:[];for(let r of l)if(r.startsWith("0x"))e.push(r);else{if(n&&!n.includes(r))throw y(["systems",t,"accessList"],r);o.push(r)}return{name:c,registerFunctionSelectors:i,openAccess:m,accessListAddresses:e,accessListSystems:o}}export{u as a,f as b};
2
+ //# sourceMappingURL=chunk-BZ6EK2LH.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../ts/config/resolveWorldConfig.ts"],"sourcesContent":["import { STORE_NAME_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.systems);\n\n // Validate every key in systems 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([\"systems\", 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.systems[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_NAME_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([\"systems\", systemName, \"accessList\"], accessListItem);\n }\n accessListSystems.push(accessListItem);\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AAkB,KAAKE,CAAc,EAIzC,MAAO,CAAE,KAAAV,EAAM,0BAAAK,EAA2B,WAAAC,EAAY,oBAAAC,EAAqB,kBAAAC,CAAkB,CAC/F","names":["STORE_NAME_MAX_LENGTH","UnrecognizedSystemErrorFactory","resolveWorldConfig","config","existingContracts","defaultSystemNames","name","overriddenSystemNames","systemName","acc","resolveSystemConfig","registerFunctionSelectors","openAccess","accessListAddresses","accessListSystems","accessList","accessListItem"]}
package/dist/ts/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import{a as e,b as o,c as r,d as t}from"../chunk-UYSOB7U2.js";import{a as d,b as l}from"../chunk-IPKL3OQG.js";var n="event WorldDeployed(address indexed newContract)",p="event HelloWorld(bytes32 indexed worldVersion)";export{e as SYSTEM_DEFAULTS,o as WORLD_DEFAULTS,p as helloWorldEvent,l as resolveSystemConfig,d as resolveWorldConfig,n as worldDeployedEvent,t as zPluginWorldConfig,r as zWorldConfig};
1
+ import{a as e,b as o,c as r,d as t}from"../chunk-UYSOB7U2.js";import{a as d,b as l}from"../chunk-BZ6EK2LH.js";var n="event WorldDeployed(address indexed newContract)",p="event HelloWorld(bytes32 indexed worldVersion)";export{e as SYSTEM_DEFAULTS,o as WORLD_DEFAULTS,p as helloWorldEvent,l as resolveSystemConfig,d as resolveWorldConfig,n as worldDeployedEvent,t as zPluginWorldConfig,r as zWorldConfig};
2
2
  //# sourceMappingURL=index.js.map
@@ -1,4 +1,4 @@
1
- import{a as u}from"../../chunk-IPKL3OQG.js";import{renderArguments as c,renderList as y,renderedSolidityHeader as v,renderImports as D}from"@latticexyz/common/codegen";function h(e){let{imports:r,name:m,functionPrefix:s,functions:o,errors:i}=e;return`
1
+ import{a as u}from"../../chunk-BZ6EK2LH.js";import{renderArguments as c,renderList as y,renderedSolidityHeader as v,renderImports as D}from"@latticexyz/common/codegen";function h(e){let{imports:r,name:m,functionPrefix:s,functions:o,errors:i}=e;return`
2
2
  ${v}
3
3
 
4
4
  ${D(r)}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@latticexyz/world",
3
- "version": "2.0.0-main-e241c056",
3
+ "version": "2.0.0-main-29c3f508",
4
4
  "description": "World framework",
5
5
  "repository": {
6
6
  "type": "git",
@@ -32,10 +32,10 @@
32
32
  "dependencies": {
33
33
  "abitype": "0.9.8",
34
34
  "zod": "^3.21.4",
35
- "@latticexyz/common": "2.0.0-main-e241c056",
36
- "@latticexyz/config": "2.0.0-main-e241c056",
37
- "@latticexyz/schema-type": "2.0.0-main-e241c056",
38
- "@latticexyz/store": "2.0.0-main-e241c056"
35
+ "@latticexyz/common": "2.0.0-main-29c3f508",
36
+ "@latticexyz/config": "2.0.0-main-29c3f508",
37
+ "@latticexyz/schema-type": "2.0.0-main-29c3f508",
38
+ "@latticexyz/store": "2.0.0-main-29c3f508"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/ejs": "^3.1.1",
@@ -50,8 +50,8 @@
50
50
  "tsup": "^6.7.0",
51
51
  "tsx": "^3.12.6",
52
52
  "vitest": "0.31.4",
53
- "@latticexyz/abi-ts": "2.0.0-main-e241c056",
54
- "@latticexyz/gas-report": "2.0.0-main-e241c056"
53
+ "@latticexyz/abi-ts": "2.0.0-main-29c3f508",
54
+ "@latticexyz/gas-report": "2.0.0-main-29c3f508"
55
55
  },
56
56
  "gitHead": "914a1e0ae4a573d685841ca2ea921435057deb8f",
57
57
  "scripts": {
@@ -67,7 +67,7 @@
67
67
  "dev": "tsup --watch",
68
68
  "gas-report": "gas-report --save gas-report.json",
69
69
  "lint": "solhint --config ./.solhint.json 'src/**/*.sol'",
70
- "test": "tsc --noEmit && vitest --run && forge test",
70
+ "test": "tsc --noEmit && vitest --run --passWithNoTests && forge test",
71
71
  "test:ci": "pnpm run test"
72
72
  }
73
73
  }
@@ -1,5 +1,4 @@
1
- import { getDuplicates, STORE_NAME_MAX_LENGTH, UnrecognizedSystemErrorFactory } from "@latticexyz/config";
2
- import { MUDError } from "@latticexyz/common/errors";
1
+ import { STORE_NAME_MAX_LENGTH, UnrecognizedSystemErrorFactory } from "@latticexyz/config";
3
2
  import { StoreConfig } from "@latticexyz/store";
4
3
  import { SystemConfig, WorldConfig } from "./types";
5
4
 
@@ -40,14 +39,6 @@ export function resolveWorldConfig(config: StoreConfig & WorldConfig, existingCo
40
39
  };
41
40
  }, {});
42
41
 
43
- // Table and system names must be unique (because they're both used for world selectors)
44
- const tableNames = Object.values(config.tables).map(({ name }) => name);
45
- const configuredSystemNames = Object.values(resolvedSystems).map(({ name }) => name);
46
- const duplicateNames = getDuplicates([...tableNames, ...configuredSystemNames]);
47
- if (duplicateNames.length > 0) {
48
- throw new MUDError(`Table and system names must be unique: ${duplicateNames.join(", ")}`);
49
- }
50
-
51
42
  return { systems: resolvedSystems };
52
43
  }
53
44
 
@@ -1,2 +0,0 @@
1
- import{getDuplicates as d,STORE_NAME_MAX_LENGTH as f,UnrecognizedSystemErrorFactory as u}from"@latticexyz/config";import{MUDError as p}from"@latticexyz/common/errors";function v(t,s){let o=s?.filter(e=>e.endsWith("System")&&e!=="System"&&!e.match(/^I[A-Z]/))??[],r=Object.keys(t.systems);if(s){for(let e of r)if(!s.includes(e)||e==="World")throw u(["systems",e],e)}let n=[...new Set([...o,...r])].filter(e=>!t.excludeSystems.includes(e)).reduce((e,l)=>({...e,[l]:a(l,t.systems[l],s)}),{}),c=Object.values(t.tables).map(({name:e})=>e),m=Object.values(n).map(({name:e})=>e),i=d([...c,...m]);if(i.length>0)throw new p(`Table and system names must be unique: ${i.join(", ")}`);return{systems:n}}function a(t,s,o){let r=(s?.name??t).slice(0,f),y=s?.registerFunctionSelectors??!0,n=s?.openAccess??!0,c=[],m=[],i=s&&!s.openAccess?s.accessList:[];for(let e of i)if(e.startsWith("0x"))c.push(e);else{if(o&&!o.includes(e))throw u(["systems",t,"accessList"],e);m.push(e)}return{name:r,registerFunctionSelectors:y,openAccess:n,accessListAddresses:c,accessListSystems:m}}export{v as a,a as b};
2
- //# sourceMappingURL=chunk-IPKL3OQG.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../ts/config/resolveWorldConfig.ts"],"sourcesContent":["import { getDuplicates, STORE_NAME_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.systems);\n\n // Validate every key in systems 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([\"systems\", 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.systems[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_NAME_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([\"systems\", systemName, \"accessList\"], accessListItem);\n }\n accessListSystems.push(accessListItem);\n }\n }\n\n return { name, registerFunctionSelectors, openAccess, accessListAddresses, accessListSystems };\n}\n"],"mappings":"AAAA,OAAS,iBAAAA,EAAe,yBAAAC,EAAuB,kCAAAC,MAAsC,qBACrF,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,OAAO,EAGxD,GAAIC,GACF,QAAWI,KAAcD,EACvB,GAAI,CAACH,EAAkB,SAASI,CAAU,GAAKA,IAAe,QAC5D,MAAMR,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S,EAA2B,WAAAC,EAAY,oBAAAC,EAAqB,kBAAAC,CAAkB,CAC/F","names":["getDuplicates","STORE_NAME_MAX_LENGTH","UnrecognizedSystemErrorFactory","MUDError","resolveWorldConfig","config","existingContracts","defaultSystemNames","name","overriddenSystemNames","systemName","resolvedSystems","acc","resolveSystemConfig","tableNames","configuredSystemNames","duplicateNames","registerFunctionSelectors","openAccess","accessListAddresses","accessListSystems","accessList","accessListItem"]}
@@ -1,24 +0,0 @@
1
- import { expect, test } from "vitest";
2
- import { mudConfig } from ".";
3
- import { resolveWorldConfig } from "../config/resolveWorldConfig";
4
-
5
- test("resolveWorldConfig requires unique table and system names", () => {
6
- expect(() =>
7
- resolveWorldConfig(
8
- mudConfig({
9
- tables: {
10
- Selector: {
11
- valueSchema: "uint256",
12
- },
13
- },
14
- systems: {
15
- Selector: {
16
- openAccess: false,
17
- accessList: [],
18
- },
19
- },
20
- }),
21
- ["Selector"]
22
- )
23
- ).toThrowError("Table and system names must be unique: Selector");
24
- });