@latticexyz/world 3.0.0-main-560fd6a0c → 3.0.0-main-8f6fa588d
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-DK3XOTC2.js +2 -0
- package/dist/chunk-DK3XOTC2.js.map +1 -0
- package/dist/chunk-OM2LE2WB.js +2 -0
- package/dist/chunk-OM2LE2WB.js.map +1 -0
- package/dist/{chunk-236CU3CY.js → chunk-Z53LAQKB.js} +2 -2
- package/dist/config/v2.d.ts +3 -2
- package/dist/config/v2.js +1 -1
- package/dist/{dynamicResolution-b1bf86e3.d.ts → dynamicResolution-34391fca.d.ts} +17 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +1 -1
- package/dist/internal.d.ts +1 -1
- package/dist/internal.js +1 -1
- package/dist/mud.config.d.ts +24 -24
- package/dist/mud.config.js +1 -1
- package/dist/node.d.ts +2 -5
- package/dist/node.js +3 -3
- package/dist/node.js.map +1 -1
- package/dist/{world-95f49fc0.d.ts → world-ef5ac077.d.ts} +75 -32
- package/package.json +8 -8
- package/dist/chunk-JEHHYC6A.js +0 -2
- package/dist/chunk-JEHHYC6A.js.map +0 -1
- package/dist/chunk-QWCOI4NR.js +0 -2
- package/dist/chunk-QWCOI4NR.js.map +0 -1
- /package/dist/{chunk-236CU3CY.js.map → chunk-Z53LAQKB.js.map} +0 -0
@@ -1,10 +1,24 @@
|
|
1
|
-
import { show, conform, ErrorMessage, narrow, withJsDoc } from '@arktype/util';
|
1
|
+
import { show, conform, ErrorMessage, narrow, requiredKeyOf, withJsDoc } from '@arktype/util';
|
2
2
|
import { StoreInput, StoreWithShorthandsInput, resolveTable, mergeIfUndefined, getPath, extendedScope, Scope, AbiTypeScope, validateTables, UserTypes, resolveStore, Store } from '@latticexyz/store/config/v2';
|
3
|
-
import { V as ValueWithType, c as DynamicResolution, W as World } from './dynamicResolution-
|
3
|
+
import { V as ValueWithType, c as DynamicResolution, W as World } from './dynamicResolution-34391fca.js';
|
4
|
+
import { Hex } from 'viem';
|
4
5
|
|
5
6
|
type SystemInput = {
|
6
|
-
/**
|
7
|
-
|
7
|
+
/**
|
8
|
+
* Human-readable system label. Used as config keys, interface names, and filenames.
|
9
|
+
* Labels are not length constrained like resource names, but special characters should be avoided to be compatible with the filesystem, Solidity compiler, etc.
|
10
|
+
*/
|
11
|
+
readonly label: string;
|
12
|
+
/**
|
13
|
+
* System namespace used in systems's resource ID and determines access control.
|
14
|
+
* Defaults to the nearest namespace in the config or root namespace if not set.
|
15
|
+
*/
|
16
|
+
readonly namespace?: string;
|
17
|
+
/**
|
18
|
+
* System name used in systems's resource ID.
|
19
|
+
* Defaults to the first 16 characters of `label` if not set.
|
20
|
+
*/
|
21
|
+
readonly name?: string;
|
8
22
|
/**
|
9
23
|
* Register function selectors for the system in the World.
|
10
24
|
* Defaults to true.
|
@@ -12,14 +26,14 @@ type SystemInput = {
|
|
12
26
|
* - For root systems all World function selectors will correspond to the system's function selectors.
|
13
27
|
* - For non-root systems, the World function selectors will be <namespace>__<function>.
|
14
28
|
*/
|
15
|
-
registerFunctionSelectors?: boolean;
|
29
|
+
readonly registerFunctionSelectors?: boolean;
|
16
30
|
/** If openAccess is true, any address can call the system */
|
17
|
-
openAccess?: boolean;
|
31
|
+
readonly openAccess?: boolean;
|
18
32
|
/** An array of addresses or system names that can access the system */
|
19
|
-
accessList?: readonly string[];
|
33
|
+
readonly accessList?: readonly string[];
|
20
34
|
};
|
21
35
|
type SystemsInput = {
|
22
|
-
[
|
36
|
+
readonly [label: string]: Omit<SystemInput, "label" | "namespace">;
|
23
37
|
};
|
24
38
|
type ModuleInputArtifactPath = {
|
25
39
|
/**
|
@@ -50,29 +64,29 @@ type ModuleInput = ModuleInputArtifactPath & {
|
|
50
64
|
};
|
51
65
|
type DeployInput = {
|
52
66
|
/** The name of a custom World contract to deploy. If no name is provided, a default MUD World is deployed. */
|
53
|
-
customWorldContract?: never;
|
67
|
+
readonly customWorldContract?: never;
|
54
68
|
/**
|
55
69
|
* Script to execute after the deployment is complete (Default "PostDeploy").
|
56
70
|
* Script must be placed in the forge scripts directory (see foundry.toml) and have a ".s.sol" extension.
|
57
71
|
*/
|
58
|
-
postDeployScript?: string;
|
72
|
+
readonly postDeployScript?: string;
|
59
73
|
/** Directory to write the deployment info to (Default "./deploys") */
|
60
|
-
deploysDirectory?: string;
|
74
|
+
readonly deploysDirectory?: string;
|
61
75
|
/** JSON file to write to with chain -> latest world deploy address (Default "./worlds.json") */
|
62
|
-
worldsFile?: string;
|
76
|
+
readonly worldsFile?: string;
|
63
77
|
/** Deploy the World as an upgradeable proxy */
|
64
|
-
upgradeableWorldImplementation?: boolean;
|
78
|
+
readonly upgradeableWorldImplementation?: boolean;
|
65
79
|
};
|
66
80
|
type CodegenInput = {
|
67
81
|
/** The name of the World interface to generate. (Default `IWorld`) */
|
68
|
-
worldInterfaceName?: string;
|
82
|
+
readonly worldInterfaceName?: string;
|
69
83
|
/** Directory to output system and world interfaces of `worldgen` (Default "world") */
|
70
|
-
worldgenDirectory?: string;
|
84
|
+
readonly worldgenDirectory?: string;
|
71
85
|
/** Path for world package imports. Default is "@latticexyz/world/src/" */
|
72
|
-
worldImportPath?: string;
|
86
|
+
readonly worldImportPath?: string;
|
73
87
|
};
|
74
88
|
type WorldInput = show<StoreInput & {
|
75
|
-
namespaces?: NamespacesInput;
|
89
|
+
readonly namespaces?: NamespacesInput;
|
76
90
|
/**
|
77
91
|
* Contracts named *System will be deployed by default
|
78
92
|
* as public systems at `namespace/ContractName`, unless overridden
|
@@ -80,18 +94,18 @@ type WorldInput = show<StoreInput & {
|
|
80
94
|
* The key is the system name (capitalized).
|
81
95
|
* The value is a SystemConfig object.
|
82
96
|
*/
|
83
|
-
systems?: SystemsInput;
|
97
|
+
readonly systems?: SystemsInput;
|
84
98
|
/** System names to exclude from codegen and deployment */
|
85
|
-
excludeSystems?: readonly string[];
|
99
|
+
readonly excludeSystems?: readonly string[];
|
86
100
|
/** Modules to install in the World */
|
87
|
-
modules?: readonly ModuleInput[];
|
101
|
+
readonly modules?: readonly ModuleInput[];
|
88
102
|
/** Deploy config */
|
89
|
-
deploy?: DeployInput;
|
103
|
+
readonly deploy?: DeployInput;
|
90
104
|
/** Codegen config */
|
91
|
-
codegen?: CodegenInput;
|
105
|
+
readonly codegen?: CodegenInput;
|
92
106
|
}>;
|
93
107
|
type NamespacesInput = {
|
94
|
-
[label: string]: NamespaceInput;
|
108
|
+
readonly [label: string]: NamespaceInput;
|
95
109
|
};
|
96
110
|
type NamespaceInput = Pick<StoreInput, "tables">;
|
97
111
|
/******** Variations with shorthands ********/
|
@@ -116,6 +130,7 @@ type resolveNamespacedTables<world> = "namespaces" extends keyof world ? {
|
|
116
130
|
} : {};
|
117
131
|
|
118
132
|
declare const SYSTEM_DEFAULTS: {
|
133
|
+
readonly namespace: "";
|
119
134
|
readonly registerFunctionSelectors: true;
|
120
135
|
readonly openAccess: true;
|
121
136
|
readonly accessList: readonly [];
|
@@ -155,10 +170,38 @@ declare const CONFIG_DEFAULTS: {
|
|
155
170
|
};
|
156
171
|
type CONFIG_DEFAULTS = typeof CONFIG_DEFAULTS;
|
157
172
|
|
158
|
-
type
|
159
|
-
|
173
|
+
type ValidateSystemOptions = {
|
174
|
+
readonly inNamespace?: true;
|
175
|
+
};
|
176
|
+
type requiredSystemKey<inNamespace extends true | undefined> = Exclude<requiredKeyOf<SystemInput>, inNamespace extends true ? "label" | "namespace" : never>;
|
177
|
+
type validateSystem<input, options extends ValidateSystemOptions = {}> = {
|
178
|
+
[key in keyof input | requiredSystemKey<options["inNamespace"]>]: key extends keyof SystemInput ? key extends "label" | "namespace" ? options["inNamespace"] extends true ? ErrorMessage<"Overrides of `label` and `namespace` are not allowed for systems in this context."> : key extends keyof input ? narrow<input[key]> : never : SystemInput[key] : ErrorMessage<`Key \`${key & string}\` does not exist in SystemInput`>;
|
179
|
+
};
|
180
|
+
declare function validateSystem<input>(input: input, options?: ValidateSystemOptions): asserts input is SystemInput & input;
|
181
|
+
type resolveSystem<input> = input extends SystemInput ? {
|
182
|
+
readonly label: input["label"];
|
183
|
+
readonly namespace: undefined extends input["namespace"] ? SYSTEM_DEFAULTS["namespace"] : input["namespace"];
|
184
|
+
readonly name: string;
|
185
|
+
readonly systemId: Hex;
|
186
|
+
readonly registerFunctionSelectors: undefined extends input["registerFunctionSelectors"] ? SYSTEM_DEFAULTS["registerFunctionSelectors"] : input["registerFunctionSelectors"];
|
187
|
+
readonly openAccess: undefined extends input["openAccess"] ? SYSTEM_DEFAULTS["openAccess"] : input["openAccess"];
|
188
|
+
readonly accessList: undefined extends input["accessList"] ? SYSTEM_DEFAULTS["accessList"] : input["accessList"];
|
189
|
+
} : never;
|
190
|
+
declare function resolveSystem<input extends SystemInput>(input: input): resolveSystem<input>;
|
191
|
+
|
192
|
+
type validateSystems<input> = {
|
193
|
+
[label in keyof input]: input[label] extends object ? validateSystem<input[label], {
|
194
|
+
inNamespace: true;
|
195
|
+
}> : ErrorMessage<`Expected a system config for ${label & string}.`>;
|
196
|
+
};
|
197
|
+
declare function validateSystems(input: unknown): asserts input is SystemsInput;
|
198
|
+
type resolveSystems<systems extends SystemsInput, namespace extends string> = {
|
199
|
+
[label in keyof systems]: resolveSystem<systems[label] & {
|
200
|
+
label: label;
|
201
|
+
namespace: namespace;
|
202
|
+
}>;
|
160
203
|
};
|
161
|
-
declare function resolveSystems<systems extends SystemsInput>(systems: systems): resolveSystems<systems>;
|
204
|
+
declare function resolveSystems<systems extends SystemsInput, namespace extends string>(systems: systems, namespace: namespace): resolveSystems<systems, namespace>;
|
162
205
|
|
163
206
|
type resolveCodegen<codegen> = codegen extends {} ? mergeIfUndefined<codegen, CODEGEN_DEFAULTS> : CODEGEN_DEFAULTS;
|
164
207
|
declare function resolveCodegen<codegen>(codegen: codegen): resolveCodegen<codegen>;
|
@@ -167,14 +210,14 @@ type resolveDeploy<deploy> = deploy extends {} ? mergeIfUndefined<deploy, DEPLOY
|
|
167
210
|
declare function resolveDeploy<deploy>(deploy: deploy): resolveDeploy<deploy>;
|
168
211
|
|
169
212
|
type validateWorld<world> = {
|
170
|
-
readonly [key in keyof world]: key extends "tables" ? validateTables<world[key], extendedScope<world>> : key extends "userTypes" ? UserTypes : key extends "enums" ? narrow<world[key]> : key extends "namespaces" ? ErrorMessage<`Namespaces config will be enabled soon.`> : key extends keyof WorldInput ? conform<world[key], WorldInput[key]> : ErrorMessage<`\`${key & string}\` is not a valid World config option.`>;
|
213
|
+
readonly [key in keyof world]: key extends "tables" ? validateTables<world[key], extendedScope<world>> : key extends "userTypes" ? UserTypes : key extends "enums" ? narrow<world[key]> : key extends "systems" ? validateSystems<world[key]> : key extends "namespaces" ? ErrorMessage<`Namespaces config will be enabled soon.`> : key extends keyof WorldInput ? conform<world[key], WorldInput[key]> : ErrorMessage<`\`${key & string}\` is not a valid World config option.`>;
|
171
214
|
};
|
172
215
|
declare function validateWorld(world: unknown): asserts world is WorldInput;
|
173
|
-
type resolveWorld<world> = withJsDoc<resolveStore<world> & mergeIfUndefined<{
|
174
|
-
tables: resolveNamespacedTables<world>;
|
175
|
-
} &
|
176
|
-
[key in keyof world]: key extends "systems" ? resolveSystems<world[key] & SystemsInput> : key extends "deploy" ? resolveDeploy<world[key]> : key extends "codegen" ? resolveCodegen<world[key]> : world[key];
|
177
|
-
},
|
216
|
+
type resolveWorld<world, namespace = resolveStore<world>["namespace"]> = withJsDoc<resolveStore<world> & mergeIfUndefined<{
|
217
|
+
readonly tables: resolveNamespacedTables<world>;
|
218
|
+
} & {
|
219
|
+
[key in Exclude<keyof world, "namespaces" | keyof Store>]: key extends "systems" ? resolveSystems<world[key] & SystemsInput, namespace & string> : key extends "deploy" ? resolveDeploy<world[key]> : key extends "codegen" ? resolveCodegen<world[key]> : world[key];
|
220
|
+
}, CONFIG_DEFAULTS>, World>;
|
178
221
|
declare function resolveWorld<const world extends WorldInput>(world: world): resolveWorld<world>;
|
179
222
|
declare function defineWorld<const input>(input: validateWorld<input>): resolveWorld<input>;
|
180
223
|
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@latticexyz/world",
|
3
|
-
"version": "3.0.0-main-
|
3
|
+
"version": "3.0.0-main-8f6fa588d",
|
4
4
|
"description": "World framework",
|
5
5
|
"repository": {
|
6
6
|
"type": "git",
|
@@ -47,11 +47,11 @@
|
|
47
47
|
"abitype": "1.0.0",
|
48
48
|
"arktype": "1.0.29-alpha",
|
49
49
|
"viem": "2.9.20",
|
50
|
-
"@latticexyz/common": "3.0.0-main-
|
51
|
-
"@latticexyz/
|
52
|
-
"@latticexyz/
|
53
|
-
"@latticexyz/schema-type": "3.0.0-main-
|
54
|
-
"@latticexyz/store": "3.0.0-main-
|
50
|
+
"@latticexyz/common": "3.0.0-main-8f6fa588d",
|
51
|
+
"@latticexyz/config": "3.0.0-main-8f6fa588d",
|
52
|
+
"@latticexyz/protocol-parser": "3.0.0-main-8f6fa588d",
|
53
|
+
"@latticexyz/schema-type": "3.0.0-main-8f6fa588d",
|
54
|
+
"@latticexyz/store": "3.0.0-main-8f6fa588d"
|
55
55
|
},
|
56
56
|
"devDependencies": {
|
57
57
|
"@arktype/attest": "0.7.5",
|
@@ -66,8 +66,8 @@
|
|
66
66
|
"tsup": "^6.7.0",
|
67
67
|
"tsx": "^3.12.6",
|
68
68
|
"vitest": "0.34.6",
|
69
|
-
"@latticexyz/abi-ts": "3.0.0-main-
|
70
|
-
"@latticexyz/gas-report": "3.0.0-main-
|
69
|
+
"@latticexyz/abi-ts": "3.0.0-main-8f6fa588d",
|
70
|
+
"@latticexyz/gas-report": "3.0.0-main-8f6fa588d"
|
71
71
|
},
|
72
72
|
"scripts": {
|
73
73
|
"build": "pnpm run build:mud && pnpm run build:abi && pnpm run build:abi-ts && pnpm run build:js",
|
package/dist/chunk-JEHHYC6A.js
DELETED
@@ -1,2 +0,0 @@
|
|
1
|
-
var l=Object.create;var p=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var E=Object.getPrototypeOf,c=Object.prototype.hasOwnProperty;var d=(e,t,o)=>t in e?p(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o;var L=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var S=(e,t,o,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of D(t))!c.call(e,r)&&r!==o&&p(e,r,{get:()=>t[r],enumerable:!(s=a(t,r))||s.enumerable});return e};var u=(e,t,o)=>(o=e!=null?l(E(e)):{},S(t||!e||!e.__esModule?p(o,"default",{value:e,enumerable:!0}):o,e));var F=(e,t,o)=>(d(e,typeof t!="symbol"?t+"":t,o),o),n=(e,t,o)=>{if(!t.has(e))throw TypeError("Cannot "+o)};var f=(e,t,o)=>(n(e,t,"read from private field"),o?o.call(e):t.get(e)),T=(e,t,o)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,o)},U=(e,t,o,s)=>(n(e,t,"write to private field"),s?s.call(e,o):t.set(e,o),o);var I=(e,t,o)=>(n(e,t,"access private method"),o);var _={registerFunctionSelectors:!0,openAccess:!0,accessList:[]},m={root:!1,args:[],artifactPath:void 0},i={worldInterfaceName:"IWorld",worldgenDirectory:"world",worldImportPath:"@latticexyz/world/src/"},y={customWorldContract:void 0,postDeployScript:"PostDeploy",deploysDirectory:"./deploys",worldsFile:"./worlds.json",upgradeableWorldImplementation:!1},x={systems:{},tables:{},excludeSystems:[],modules:[],codegen:i,deploy:y};export{L as a,u as b,F as c,f as d,T as e,U as f,I as g,_ as h,m as i,i as j,y as k,x as l};
|
2
|
-
//# sourceMappingURL=chunk-JEHHYC6A.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../ts/config/v2/defaults.ts"],"sourcesContent":["import { CodegenInput, DeployInput, ModuleInput, SystemInput, WorldInput } from \"./input\";\n\nexport const SYSTEM_DEFAULTS = {\n registerFunctionSelectors: true,\n openAccess: true,\n accessList: [],\n} as const satisfies SystemInput;\n\nexport type SYSTEM_DEFAULTS = typeof SYSTEM_DEFAULTS;\n\nexport const MODULE_DEFAULTS = {\n root: false,\n args: [],\n artifactPath: undefined,\n} as const satisfies Pick<ModuleInput, \"root\" | \"args\" | \"artifactPath\">;\n\nexport type MODULE_DEFAULTS = typeof MODULE_DEFAULTS;\n\nexport const CODEGEN_DEFAULTS = {\n worldInterfaceName: \"IWorld\",\n worldgenDirectory: \"world\",\n worldImportPath: \"@latticexyz/world/src/\",\n} as const satisfies CodegenInput;\n\nexport type CODEGEN_DEFAULTS = typeof CODEGEN_DEFAULTS;\n\nexport const DEPLOY_DEFAULTS = {\n customWorldContract: undefined,\n postDeployScript: \"PostDeploy\",\n deploysDirectory: \"./deploys\",\n worldsFile: \"./worlds.json\",\n upgradeableWorldImplementation: false,\n} as const satisfies DeployInput;\n\nexport type DEPLOY_DEFAULTS = typeof DEPLOY_DEFAULTS;\n\nexport const CONFIG_DEFAULTS = {\n systems: {},\n tables: {},\n excludeSystems: [],\n modules: [],\n codegen: CODEGEN_DEFAULTS,\n deploy: DEPLOY_DEFAULTS,\n} as const satisfies WorldInput;\n\nexport type CONFIG_DEFAULTS = typeof CONFIG_DEFAULTS;\n"],"mappings":"shCAEO,IAAMA,EAAkB,CAC7B,0BAA2B,GAC3B,WAAY,GACZ,WAAY,CAAC,CACf,EAIaC,EAAkB,CAC7B,KAAM,GACN,KAAM,CAAC,EACP,aAAc,MAChB,EAIaC,EAAmB,CAC9B,mBAAoB,SACpB,kBAAmB,QACnB,gBAAiB,wBACnB,EAIaC,EAAkB,CAC7B,oBAAqB,OACrB,iBAAkB,aAClB,iBAAkB,YAClB,WAAY,gBACZ,+BAAgC,EAClC,EAIaC,EAAkB,CAC7B,QAAS,CAAC,EACV,OAAQ,CAAC,EACT,eAAgB,CAAC,EACjB,QAAS,CAAC,EACV,QAASF,EACT,OAAQC,CACV","names":["SYSTEM_DEFAULTS","MODULE_DEFAULTS","CODEGEN_DEFAULTS","DEPLOY_DEFAULTS","CONFIG_DEFAULTS"]}
|
package/dist/chunk-QWCOI4NR.js
DELETED
@@ -1,2 +0,0 @@
|
|
1
|
-
import{h as c,i,j as p,k as d,l as t}from"./chunk-JEHHYC6A.js";import{extendedScope as S,get as A,resolveTable as W,validateTable as L,mergeIfUndefined as r,resolveStore as F,hasOwnKey as C,validateStore as j}from"@latticexyz/store/config/v2";import{mapObject as g}from"@latticexyz/common/utils";import{mergeIfUndefined as T}from"@latticexyz/store/config/v2";function y(e){return g(e,s=>T(s,c))}import{validateTables as E,isObject as I,hasOwnKey as w}from"@latticexyz/store/config/v2";function D(e,s){w(e,"tables")&&E(e.tables,s)}function f(e,s){if(!I(e))throw new Error(`Expected namespaces, received ${JSON.stringify(e)}`);for(let n of Object.values(e))D(n,s)}import{isObject as U,mergeIfUndefined as N}from"@latticexyz/store/config/v2";function v(e){return U(e)?N(e,p):p}import{mergeIfUndefined as O,isObject as _}from"@latticexyz/store/config/v2";function b(e){return _(e)?O(e,d):d}function $(e){let s=S(e);j(e),C(e,"namespaces")&&f(e.namespaces,s)}function M(e){let s=S(e),n=e.namespaces??{},x=Object.fromEntries(Object.entries(n).map(([o,u])=>Object.entries(u.tables??{}).map(([l,m])=>(L(m,s),[`${o}__${l}`,W(r(m,{namespace:o,name:l}),s)]))).flat()),a=F(e),k=(e.modules??t.modules).map(o=>r(o,i));return r({...a,tables:{...a.tables,...x},codegen:r(a.codegen,v(e.codegen)),deploy:b(e.deploy),systems:y(e.systems??t.systems),excludeSystems:A(e,"excludeSystems"),modules:k},t)}function ye(e){return $(e),M(e)}export{$ as a,M as b,ye as c};
|
2
|
-
//# sourceMappingURL=chunk-QWCOI4NR.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../ts/config/v2/world.ts","../ts/config/v2/systems.ts","../ts/config/v2/namespaces.ts","../ts/config/v2/codegen.ts","../ts/config/v2/deploy.ts"],"sourcesContent":["import { ErrorMessage, conform, narrow, type withJsDoc } from \"@arktype/util\";\nimport {\n UserTypes,\n extendedScope,\n get,\n resolveTable,\n validateTable,\n mergeIfUndefined,\n validateTables,\n resolveStore,\n Store,\n hasOwnKey,\n validateStore,\n} from \"@latticexyz/store/config/v2\";\nimport { SystemsInput, WorldInput } from \"./input\";\nimport { CONFIG_DEFAULTS, MODULE_DEFAULTS } from \"./defaults\";\nimport { Tables } from \"@latticexyz/store/internal\";\nimport { resolveSystems } from \"./systems\";\nimport { resolveNamespacedTables, validateNamespaces } from \"./namespaces\";\nimport { resolveCodegen } from \"./codegen\";\nimport { resolveDeploy } from \"./deploy\";\nimport type { World } from \"./output.js\";\n\nexport type validateWorld<world> = {\n readonly [key in keyof world]: key extends \"tables\"\n ? validateTables<world[key], extendedScope<world>>\n : key extends \"userTypes\"\n ? UserTypes\n : key extends \"enums\"\n ? narrow<world[key]>\n : key extends \"namespaces\"\n ? // ? validateNamespaces<world[key], extendedScope<world>>\n ErrorMessage<`Namespaces config will be enabled soon.`>\n : key extends keyof WorldInput\n ? conform<world[key], WorldInput[key]>\n : ErrorMessage<`\\`${key & string}\\` is not a valid World config option.`>;\n};\n\nexport function validateWorld(world: unknown): asserts world is WorldInput {\n const scope = extendedScope(world);\n validateStore(world);\n\n if (hasOwnKey(world, \"namespaces\")) {\n validateNamespaces(world.namespaces, scope);\n }\n}\n\nexport type resolveWorld<world> = withJsDoc<\n resolveStore<world> &\n mergeIfUndefined<\n { tables: resolveNamespacedTables<world> } & Omit<\n {\n [key in keyof world]: key extends \"systems\"\n ? resolveSystems<world[key] & SystemsInput>\n : key extends \"deploy\"\n ? resolveDeploy<world[key]>\n : key extends \"codegen\"\n ? resolveCodegen<world[key]>\n : world[key];\n },\n \"namespaces\" | keyof Store\n >,\n CONFIG_DEFAULTS\n >,\n World\n>;\n\nexport function resolveWorld<const world extends WorldInput>(world: world): resolveWorld<world> {\n const scope = extendedScope(world);\n const namespaces = world.namespaces ?? {};\n\n const resolvedNamespacedTables = Object.fromEntries(\n Object.entries(namespaces)\n .map(([namespaceKey, namespace]) =>\n Object.entries(namespace.tables ?? {}).map(([tableKey, table]) => {\n validateTable(table, scope);\n return [\n `${namespaceKey}__${tableKey}`,\n resolveTable(mergeIfUndefined(table, { namespace: namespaceKey, name: tableKey }), scope),\n ];\n }),\n )\n .flat(),\n ) as Tables;\n\n const resolvedStore = resolveStore(world);\n\n const modules = (world.modules ?? CONFIG_DEFAULTS.modules).map((mod) => mergeIfUndefined(mod, MODULE_DEFAULTS));\n\n return mergeIfUndefined(\n {\n ...resolvedStore,\n tables: { ...resolvedStore.tables, ...resolvedNamespacedTables },\n codegen: mergeIfUndefined(resolvedStore.codegen, resolveCodegen(world.codegen)),\n deploy: resolveDeploy(world.deploy),\n systems: resolveSystems(world.systems ?? CONFIG_DEFAULTS.systems),\n excludeSystems: get(world, \"excludeSystems\"),\n modules,\n },\n CONFIG_DEFAULTS,\n ) as never;\n}\n\nexport function defineWorld<const input>(input: validateWorld<input>): resolveWorld<input> {\n validateWorld(input);\n return resolveWorld(input) as never;\n}\n","import { mapObject } from \"@latticexyz/common/utils\";\nimport { SYSTEM_DEFAULTS } from \"./defaults\";\nimport { SystemsInput } from \"./input\";\nimport { mergeIfUndefined } from \"@latticexyz/store/config/v2\";\n\nexport type resolveSystems<systems extends SystemsInput> = {\n [label in keyof systems]: mergeIfUndefined<systems[label], typeof SYSTEM_DEFAULTS>;\n};\n\nexport function resolveSystems<systems extends SystemsInput>(systems: systems): resolveSystems<systems> {\n return mapObject(systems, (system) => mergeIfUndefined(system, SYSTEM_DEFAULTS));\n}\n","import {\n Scope,\n AbiTypeScope,\n validateTables,\n isObject,\n hasOwnKey,\n resolveTable,\n mergeIfUndefined,\n extendedScope,\n getPath,\n} from \"@latticexyz/store/config/v2\";\nimport { NamespaceInput, NamespacesInput } from \"./input\";\nimport { ErrorMessage, conform } from \"@arktype/util\";\n\nexport type namespacedTableKeys<world> = world extends { namespaces: infer namespaces }\n ? {\n [k in keyof namespaces]: namespaces[k] extends { tables: infer tables }\n ? `${k & string}__${keyof tables & string}`\n : never;\n }[keyof namespaces]\n : never;\n\nexport type validateNamespace<namespace, scope extends Scope = AbiTypeScope> = {\n readonly [key in keyof namespace]: key extends \"tables\"\n ? validateTables<namespace[key], scope>\n : key extends keyof NamespaceInput\n ? conform<namespace[key], NamespaceInput[key]>\n : ErrorMessage<`\\`${key & string}\\` is not a valid namespace config option.`>;\n};\n\nexport function validateNamespace<scope extends Scope = AbiTypeScope>(\n namespace: unknown,\n scope: scope,\n): asserts namespace is NamespaceInput {\n if (hasOwnKey(namespace, \"tables\")) {\n validateTables(namespace.tables, scope);\n }\n}\n\nexport type validateNamespaces<namespaces, scope extends Scope = AbiTypeScope> = {\n [label in keyof namespaces]: validateNamespace<namespaces[label], scope>;\n};\n\nexport function validateNamespaces<scope extends Scope = AbiTypeScope>(\n namespaces: unknown,\n scope: scope,\n): asserts namespaces is NamespacesInput {\n if (!isObject(namespaces)) {\n throw new Error(`Expected namespaces, received ${JSON.stringify(namespaces)}`);\n }\n for (const namespace of Object.values(namespaces)) {\n validateNamespace(namespace, scope);\n }\n}\n\nexport type resolveNamespacedTables<world> = \"namespaces\" extends keyof world\n ? {\n readonly [key in namespacedTableKeys<world>]: key extends `${infer namespace}__${infer table}`\n ? resolveTable<\n mergeIfUndefined<\n getPath<world, [\"namespaces\", namespace, \"tables\", table]>,\n { name: table; namespace: namespace }\n >,\n extendedScope<world>\n >\n : never;\n }\n : {};\n","import { isObject, mergeIfUndefined } from \"@latticexyz/store/config/v2\";\nimport { CODEGEN_DEFAULTS } from \"./defaults\";\n\nexport type resolveCodegen<codegen> = codegen extends {}\n ? mergeIfUndefined<codegen, CODEGEN_DEFAULTS>\n : CODEGEN_DEFAULTS;\n\nexport function resolveCodegen<codegen>(codegen: codegen): resolveCodegen<codegen> {\n return (isObject(codegen) ? mergeIfUndefined(codegen, CODEGEN_DEFAULTS) : CODEGEN_DEFAULTS) as never;\n}\n","import { mergeIfUndefined, isObject } from \"@latticexyz/store/config/v2\";\nimport { DEPLOY_DEFAULTS } from \"./defaults\";\n\nexport type resolveDeploy<deploy> = deploy extends {} ? mergeIfUndefined<deploy, DEPLOY_DEFAULTS> : DEPLOY_DEFAULTS;\n\nexport function resolveDeploy<deploy>(deploy: deploy): resolveDeploy<deploy> {\n return (isObject(deploy) ? mergeIfUndefined(deploy, DEPLOY_DEFAULTS) : DEPLOY_DEFAULTS) as never;\n}\n"],"mappings":"+DACA,OAEE,iBAAAA,EACA,OAAAC,EACA,gBAAAC,EACA,iBAAAC,EACA,oBAAAC,EAEA,gBAAAC,EAEA,aAAAC,EACA,iBAAAC,MACK,8BCbP,OAAS,aAAAC,MAAiB,2BAG1B,OAAS,oBAAAC,MAAwB,8BAM1B,SAASC,EAA6CC,EAA2C,CACtG,OAAOC,EAAUD,EAAUE,GAAWJ,EAAiBI,EAAQC,CAAe,CAAC,CACjF,CCXA,OAGE,kBAAAC,EACA,YAAAC,EACA,aAAAC,MAKK,8BAoBA,SAASC,EACdC,EACAC,EACqC,CACjCH,EAAUE,EAAW,QAAQ,GAC/BJ,EAAeI,EAAU,OAAQC,CAAK,CAE1C,CAMO,SAASC,EACdC,EACAF,EACuC,CACvC,GAAI,CAACJ,EAASM,CAAU,EACtB,MAAM,IAAI,MAAM,iCAAiC,KAAK,UAAUA,CAAU,GAAG,EAE/E,QAAWH,KAAa,OAAO,OAAOG,CAAU,EAC9CJ,EAAkBC,EAAWC,CAAK,CAEtC,CCrDA,OAAS,YAAAG,EAAU,oBAAAC,MAAwB,8BAOpC,SAASC,EAAwBC,EAA2C,CACjF,OAAQC,EAASD,CAAO,EAAIE,EAAiBF,EAASG,CAAgB,EAAIA,CAC5E,CCTA,OAAS,oBAAAC,EAAkB,YAAAC,MAAgB,8BAKpC,SAASC,EAAsBC,EAAuC,CAC3E,OAAQC,EAASD,CAAM,EAAIE,EAAiBF,EAAQG,CAAe,EAAIA,CACzE,CJ+BO,SAASC,EAAcC,EAA6C,CACzE,IAAMC,EAAQC,EAAcF,CAAK,EACjCG,EAAcH,CAAK,EAEfI,EAAUJ,EAAO,YAAY,GAC/BK,EAAmBL,EAAM,WAAYC,CAAK,CAE9C,CAsBO,SAASK,EAA6CN,EAAmC,CAC9F,IAAMC,EAAQC,EAAcF,CAAK,EAC3BO,EAAaP,EAAM,YAAc,CAAC,EAElCQ,EAA2B,OAAO,YACtC,OAAO,QAAQD,CAAU,EACtB,IAAI,CAAC,CAACE,EAAcC,CAAS,IAC5B,OAAO,QAAQA,EAAU,QAAU,CAAC,CAAC,EAAE,IAAI,CAAC,CAACC,EAAUC,CAAK,KAC1DC,EAAcD,EAAOX,CAAK,EACnB,CACL,GAAGQ,MAAiBE,IACpBG,EAAaC,EAAiBH,EAAO,CAAE,UAAWH,EAAc,KAAME,CAAS,CAAC,EAAGV,CAAK,CAC1F,EACD,CACH,EACC,KAAK,CACV,EAEMe,EAAgBC,EAAajB,CAAK,EAElCkB,GAAWlB,EAAM,SAAWmB,EAAgB,SAAS,IAAKC,GAAQL,EAAiBK,EAAKC,CAAe,CAAC,EAE9G,OAAON,EACL,CACE,GAAGC,EACH,OAAQ,CAAE,GAAGA,EAAc,OAAQ,GAAGR,CAAyB,EAC/D,QAASO,EAAiBC,EAAc,QAASM,EAAetB,EAAM,OAAO,CAAC,EAC9E,OAAQuB,EAAcvB,EAAM,MAAM,EAClC,QAASwB,EAAexB,EAAM,SAAWmB,EAAgB,OAAO,EAChE,eAAgBM,EAAIzB,EAAO,gBAAgB,EAC3C,QAAAkB,CACF,EACAC,CACF,CACF,CAEO,SAASO,GAAyBC,EAAkD,CACzF,OAAA5B,EAAc4B,CAAK,EACZrB,EAAaqB,CAAK,CAC3B","names":["extendedScope","get","resolveTable","validateTable","mergeIfUndefined","resolveStore","hasOwnKey","validateStore","mapObject","mergeIfUndefined","resolveSystems","systems","mapObject","system","SYSTEM_DEFAULTS","validateTables","isObject","hasOwnKey","validateNamespace","namespace","scope","validateNamespaces","namespaces","isObject","mergeIfUndefined","resolveCodegen","codegen","isObject","mergeIfUndefined","CODEGEN_DEFAULTS","mergeIfUndefined","isObject","resolveDeploy","deploy","isObject","mergeIfUndefined","DEPLOY_DEFAULTS","validateWorld","world","scope","extendedScope","validateStore","hasOwnKey","validateNamespaces","resolveWorld","namespaces","resolvedNamespacedTables","namespaceKey","namespace","tableKey","table","validateTable","resolveTable","mergeIfUndefined","resolvedStore","resolveStore","modules","CONFIG_DEFAULTS","mod","MODULE_DEFAULTS","resolveCodegen","resolveDeploy","resolveSystems","get","defineWorld","input"]}
|
File without changes
|