@latticexyz/config 2.0.0-next.11 → 2.0.0-next.13

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,4 @@
1
+ var a=Object.defineProperty;var d=(r,e,o)=>e in r?a(r,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):r[e]=o;var p=(r,e,o)=>(d(r,typeof e!="symbol"?e+"":e,o),o);import{z as m,ZodIssueCode as c}from"zod";import{fromZodError as i}from"zod-validation-error";var t=class extends Error{name="MUDContextAlreadyCreatedError";message="MUD context was already created"},s=class extends Error{name="MUDContextNotCreatedError";message="MUD context has not been created"};function f(r,e){return i(r,{prefix:e,prefixSeparator:`
2
+ - `,issueSeparator:`
3
+ - `})}var n=class extends Error{name="NotInsideProjectError";message="You are not inside a MUD project"};function Z(r,e){return new m.ZodError([{code:c.custom,path:r,message:`Unrecognized system: "${e}"`}])}export{p as a,t as b,s as c,f as d,n as e,Z as f};
4
+ //# sourceMappingURL=chunk-NOTUCTDJ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/library/errors.ts"],"sourcesContent":["import { z, ZodError, ZodIssueCode } from \"zod\";\nimport { fromZodError } from \"zod-validation-error\";\n\nexport class MUDContextAlreadyCreatedError extends Error {\n name = \"MUDContextAlreadyCreatedError\";\n message = \"MUD context was already created\";\n}\n\nexport class MUDContextNotCreatedError extends Error {\n name = \"MUDContextNotCreatedError\";\n message = \"MUD context has not been created\";\n}\n\n// Wrapper with preset styles, only requires a `prefix`\nexport function fromZodErrorCustom(error: ZodError, prefix: string) {\n return fromZodError(error, {\n prefix: prefix,\n prefixSeparator: \"\\n- \",\n issueSeparator: \"\\n- \",\n });\n}\n\nexport class NotInsideProjectError extends Error {\n name = \"NotInsideProjectError\";\n message = \"You are not inside a MUD project\";\n}\n\nexport function UnrecognizedSystemErrorFactory(path: string[], systemName: string) {\n return new z.ZodError([{ code: ZodIssueCode.custom, path: path, message: `Unrecognized system: \"${systemName}\"` }]);\n}\n"],"mappings":"wKAAA,OAAS,KAAAA,EAAa,gBAAAC,MAAoB,MAC1C,OAAS,gBAAAC,MAAoB,uBAEtB,IAAMC,EAAN,cAA4C,KAAM,CACvD,KAAO,gCACP,QAAU,iCACZ,EAEaC,EAAN,cAAwC,KAAM,CACnD,KAAO,4BACP,QAAU,kCACZ,EAGO,SAASC,EAAmBC,EAAiBC,EAAgB,CAClE,OAAOL,EAAaI,EAAO,CACzB,OAAQC,EACR,gBAAiB;AAAA,IACjB,eAAgB;AAAA,GAClB,CAAC,CACH,CAEO,IAAMC,EAAN,cAAoC,KAAM,CAC/C,KAAO,wBACP,QAAU,kCACZ,EAEO,SAASC,EAA+BC,EAAgBC,EAAoB,CACjF,OAAO,IAAIX,EAAE,SAAS,CAAC,CAAE,KAAMC,EAAa,OAAQ,KAAMS,EAAM,QAAS,yBAAyBC,IAAc,CAAC,CAAC,CACpH","names":["z","ZodIssueCode","fromZodError","MUDContextAlreadyCreatedError","MUDContextNotCreatedError","fromZodErrorCustom","error","prefix","NotInsideProjectError","UnrecognizedSystemErrorFactory","path","systemName"]}
@@ -0,0 +1,3 @@
1
+ import{a as m,b as f,c as p}from"./chunk-NOTUCTDJ.js";import{z as r}from"zod";import{ZodIssueCode as s}from"zod";import{isAddress as U}from"viem";var z=16,g=14;function d(e,t){/^\w+$/.test(e)||t.addIssue({code:s.custom,message:"Name must contain only alphanumeric & underscore characters"})}function x(e,t){d(e,t),/^[A-Z]/.test(e)||t.addIssue({code:s.custom,message:"Name must start with a capital letter"})}function C(e,t){d(e,t),/^[a-z]/.test(e)||t.addIssue({code:s.custom,message:"Name must start with a lowercase letter"})}function h(e,t){e.length===0&&t.addIssue({code:s.custom,message:"Enum must not be empty"}),e.length>=256&&t.addIssue({code:s.custom,message:"Length of enum must be < 256"});let o=M(e);o.length>0&&t.addIssue({code:s.custom,message:`Enum must not have duplicate names for: ${o.join(", ")}`})}function c(e,t){return(o,n)=>{if(o===""){e&&n.addIssue({code:s.custom,message:"Route must not be empty"});return}o[0]!=="/"&&n.addIssue({code:s.custom,message:'Route must start with "/"'}),o[o.length-1]==="/"&&n.addIssue({code:s.custom,message:'Route must not end with "/"'});let a=o.split("/");t&&a.length>2&&n.addIssue({code:s.custom,message:'Route must only have one level (e.g. "/foo")'});for(let u=1;u<a.length;u++)a[u]===""&&n.addIssue({code:s.custom,message:'Route must not contain empty route fragments (e.g. "//")'}),/^\w+$/.test(a[u])||n.addIssue({code:s.custom,message:"Route must contain only alphanumeric & underscore characters"})}}var R=c(!0,!1),y=c(!1,!1),b=c(!0,!0);function D(e,t){U(e)||t.addIssue({code:s.custom,message:"Address must be a valid Ethereum address"})}function M(e){let t=new Set,o=new Set;for(let n of e)t.has(n)&&o.add(n),t.add(n);return[...o]}function E(e,t){e.length>g&&t.addIssue({code:s.custom,message:`Namespace must be <= ${g} characters`}),/^\w*$/.test(e)||t.addIssue({code:s.custom,message:"Selector must contain only alphanumeric & underscore characters"})}function S(e){let t=e.match(/^(\w+)\[(\d+)\]$/);return t?{elementType:t[1],staticLength:Number.parseInt(t[2])}:null}var v=r.string().superRefine(x),B=r.string().superRefine(C),G=r.string().superRefine(d),O=r.string().superRefine(E),V=r.array(v).superRefine(h),j=r.string().superRefine(R),k=r.string().superRefine(b),H=r.string().superRefine(y),P=r.string().superRefine(D);var l=class{static isCreated(){return this._global.__mudCoreContext!==void 0}static createContext(){if(this.isCreated())throw new f;let t=this._global,o=new l;return t.__mudCoreContext=o,o}static getContext(){let o=this._global.__mudCoreContext;if(o===void 0)throw new p;return o}configExtenders=[]},i=l;m(i,"_global",typeof global>"u"?window.global??{}:global);function q(e){let t=e,o=i.getContext();for(let n of o.configExtenders)t=n(t);return t}function K(e){i.getContext().configExtenders.push(e)}import{MUDError as I}from"@latticexyz/common/errors";var N=(o=>(o[o.TABLE_ID=0]="TABLE_ID",o[o.SYSTEM_ADDRESS=1]="SYSTEM_ADDRESS",o))(N||{});function te(e){return{type:0,input:e}}function w(e){return typeof e=="object"&&e!==null&&"type"in e&&"input"in e}function oe(e,t){if(!w(e))return e;let o;if(e.type===0){let n=t.tableIds?.[e.input];o=n&&{value:n,type:"bytes32"}}if(o===void 0)throw new I(`Could not resolve dynamic resolution:
2
+ ${JSON.stringify(e,null,2)}`);return o}export{z as a,g as b,d as c,x as d,C as e,h as f,R as g,y as h,b as i,D as j,M as k,E as l,S as m,v as n,B as o,G as p,O as q,V as r,j as s,k as t,H as u,P as v,i as w,q as x,K as y,N as z,te as A,w as B,oe as C};
3
+ //# sourceMappingURL=chunk-YRED5UZY.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/library/commonSchemas.ts","../src/library/validation.ts","../src/library/context.ts","../src/library/core.ts","../src/library/dynamicResolution.ts"],"sourcesContent":["import { z } from \"zod\";\nimport {\n validateBaseRoute,\n validateCapitalizedName,\n validateEthereumAddress,\n validateEnum,\n validateName,\n validateRoute,\n validateSingleLevelRoute,\n validateUncapitalizedName,\n validateNamespace,\n} from \"./validation\";\n\n/** Capitalized names of objects, like tables and systems */\nexport const zObjectName = z.string().superRefine(validateCapitalizedName);\n/** Uncapitalized names of values, like keys and columns */\nexport const zValueName = z.string().superRefine(validateUncapitalizedName);\n/** Name that can start with any case */\nexport const zName = z.string().superRefine(validateName);\n/** A namespace */\nexport const zNamespace = z.string().superRefine(validateNamespace);\n\n/** List of unique enum member names and 0 < length < 256 */\nexport const zUserEnum = z.array(zObjectName).superRefine(validateEnum);\n\n/** Ordinary routes */\nexport const zOrdinaryRoute = z.string().superRefine(validateRoute);\n/** Routes with exactly 1 non-empty level */\nexport const zSingleLevelRoute = z.string().superRefine(validateSingleLevelRoute);\n/** Base routes (can be an empty string) */\nexport const zBaseRoute = z.string().superRefine(validateBaseRoute);\n\n/** A valid Ethereum address */\nexport const zEthereumAddress = z.string().superRefine(validateEthereumAddress);\n","import { ZodIssueCode, RefinementCtx } from \"zod\";\nimport { isAddress } from \"viem\";\n\nexport const STORE_NAME_MAX_LENGTH = 16;\nexport const STORE_NAMESPACE_MAX_LENGTH = 14;\n\nexport function validateName(name: string, ctx: RefinementCtx) {\n if (!/^\\w+$/.test(name)) {\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message: `Name must contain only alphanumeric & underscore characters`,\n });\n }\n}\n\nexport function validateCapitalizedName(name: string, ctx: RefinementCtx) {\n validateName(name, ctx);\n\n if (!/^[A-Z]/.test(name)) {\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message: `Name must start with a capital letter`,\n });\n }\n}\n\nexport function validateUncapitalizedName(name: string, ctx: RefinementCtx) {\n validateName(name, ctx);\n\n if (!/^[a-z]/.test(name)) {\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message: `Name must start with a lowercase letter`,\n });\n }\n}\n\n// validates only the enum array, not the names of enum members\nexport function validateEnum(members: string[], ctx: RefinementCtx) {\n if (members.length === 0) {\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message: `Enum must not be empty`,\n });\n }\n if (members.length >= 256) {\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message: `Length of enum must be < 256`,\n });\n }\n\n const duplicates = getDuplicates(members);\n if (duplicates.length > 0) {\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message: `Enum must not have duplicate names for: ${duplicates.join(\", \")}`,\n });\n }\n}\n\nfunction _factoryForValidateRoute(requireNonEmpty: boolean, requireSingleLevel: boolean) {\n return (route: string, ctx: RefinementCtx) => {\n if (route === \"\") {\n if (requireNonEmpty) {\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message: `Route must not be empty`,\n });\n }\n // we can skip further validation for empty routes\n return;\n }\n\n if (route[0] !== \"/\") {\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message: `Route must start with \"/\"`,\n });\n }\n\n if (route[route.length - 1] === \"/\") {\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message: `Route must not end with \"/\"`,\n });\n }\n\n const parts = route.split(\"/\");\n if (requireSingleLevel && parts.length > 2) {\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message: `Route must only have one level (e.g. \"/foo\")`,\n });\n }\n\n // start at 1 to skip the first empty part\n for (let i = 1; i < parts.length; i++) {\n if (parts[i] === \"\") {\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message: `Route must not contain empty route fragments (e.g. \"//\")`,\n });\n }\n\n if (!/^\\w+$/.test(parts[i])) {\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message: `Route must contain only alphanumeric & underscore characters`,\n });\n }\n }\n };\n}\n\nexport const validateRoute = _factoryForValidateRoute(true, false);\n\nexport const validateBaseRoute = _factoryForValidateRoute(false, false);\n\nexport const validateSingleLevelRoute = _factoryForValidateRoute(true, true);\n\nexport function validateEthereumAddress(address: string, ctx: RefinementCtx) {\n if (!isAddress(address)) {\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message: `Address must be a valid Ethereum address`,\n });\n }\n}\n\nexport function getDuplicates<T>(array: T[]) {\n const checked = new Set<T>();\n const duplicates = new Set<T>();\n for (const element of array) {\n if (checked.has(element)) {\n duplicates.add(element);\n }\n checked.add(element);\n }\n return [...duplicates];\n}\n\nexport function validateNamespace(name: string, ctx: RefinementCtx) {\n if (name.length > STORE_NAMESPACE_MAX_LENGTH) {\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message: `Namespace must be <= ${STORE_NAMESPACE_MAX_LENGTH} characters`,\n });\n }\n if (!/^\\w*$/.test(name)) {\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message: `Selector must contain only alphanumeric & underscore characters`,\n });\n }\n}\n\n/** Returns null if the type does not look like a static array, otherwise element and length data */\nexport function parseStaticArray(abiType: string) {\n const matches = abiType.match(/^(\\w+)\\[(\\d+)\\]$/);\n if (!matches) return null;\n return {\n elementType: matches[1],\n staticLength: Number.parseInt(matches[2]),\n };\n}\n","import { MUDConfigExtender } from \"./core\";\nimport { MUDContextAlreadyCreatedError, MUDContextNotCreatedError } from \"./errors\";\n\nexport type GlobalWithMUDCoreContext = typeof global & {\n __mudCoreContext: MUDCoreContext;\n};\n\nexport class MUDCoreContext {\n static _global = typeof global === \"undefined\" ? window.global ?? {} : global;\n\n public static isCreated(): boolean {\n const globalWithMUDCoreContext = this._global as GlobalWithMUDCoreContext;\n return globalWithMUDCoreContext.__mudCoreContext !== undefined;\n }\n\n public static createContext(): MUDCoreContext {\n if (this.isCreated()) {\n throw new MUDContextAlreadyCreatedError();\n }\n const globalWithMUDCoreContext = this._global as GlobalWithMUDCoreContext;\n const context = new MUDCoreContext();\n globalWithMUDCoreContext.__mudCoreContext = context;\n return context;\n }\n\n public static getContext(): MUDCoreContext {\n const globalWithMUDCoreContext = this._global as GlobalWithMUDCoreContext;\n const context = globalWithMUDCoreContext.__mudCoreContext;\n if (context === undefined) {\n throw new MUDContextNotCreatedError();\n }\n return context;\n }\n\n public readonly configExtenders: MUDConfigExtender[] = [];\n}\n","import { MUDCoreContext } from \"./context\";\n\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface MUDCoreUserConfig {}\n\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface MUDCoreConfig {}\n\nexport type MUDConfigExtender = (config: MUDCoreConfig) => Record<string, unknown>;\n\n/** Resolver that sequentially passes the config through all the plugins */\nexport function mudCoreConfig(config: MUDCoreUserConfig): MUDCoreConfig {\n // config types can change with plugins, `any` helps avoid errors when typechecking dependencies\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let configAsAny = config as any;\n const context = MUDCoreContext.getContext();\n for (const extender of context.configExtenders) {\n configAsAny = extender(configAsAny);\n }\n return configAsAny;\n}\n\n/** Utility for plugin developers to extend the core config */\nexport function extendMUDCoreConfig(extender: MUDConfigExtender) {\n const context = MUDCoreContext.getContext();\n context.configExtenders.push(extender);\n}\n","import { MUDError } from \"@latticexyz/common/errors\";\n\nexport enum DynamicResolutionType {\n TABLE_ID,\n SYSTEM_ADDRESS,\n}\n\nexport type DynamicResolution = {\n type: DynamicResolutionType;\n input: string;\n};\n\nexport type ValueWithType = {\n value: string | number | Uint8Array;\n type: string;\n};\n\n/**\n * Dynamically resolve a table name to a table id at deploy time\n */\nexport function resolveTableId(tableName: string) {\n return {\n type: DynamicResolutionType.TABLE_ID,\n input: tableName,\n };\n}\n\n/** Type guard for DynamicResolution */\nexport function isDynamicResolution(value: unknown): value is DynamicResolution {\n return typeof value === \"object\" && value !== null && \"type\" in value && \"input\" in value;\n}\n\n/**\n * Turn a DynamicResolution object into a ValueWithType based on the provided context\n */\nexport function resolveWithContext(\n unresolved: any,\n context: { systemAddresses?: Record<string, Promise<string>>; tableIds?: Record<string, Uint8Array> }\n): ValueWithType {\n if (!isDynamicResolution(unresolved)) return unresolved;\n let resolved: ValueWithType | undefined = undefined;\n\n if (unresolved.type === DynamicResolutionType.TABLE_ID) {\n const tableId = context.tableIds?.[unresolved.input];\n resolved = tableId && { value: tableId, type: \"bytes32\" };\n }\n\n if (resolved === undefined) {\n throw new MUDError(`Could not resolve dynamic resolution: \\n${JSON.stringify(unresolved, null, 2)}`);\n }\n\n return resolved;\n}\n"],"mappings":"sDAAA,OAAS,KAAAA,MAAS,MCAlB,OAAS,gBAAAC,MAAmC,MAC5C,OAAS,aAAAC,MAAiB,OAEnB,IAAMC,EAAwB,GACxBC,EAA6B,GAEnC,SAASC,EAAaC,EAAcC,EAAoB,CACxD,QAAQ,KAAKD,CAAI,GACpBC,EAAI,SAAS,CACX,KAAMN,EAAa,OACnB,QAAS,6DACX,CAAC,CAEL,CAEO,SAASO,EAAwBF,EAAcC,EAAoB,CACxEF,EAAaC,EAAMC,CAAG,EAEjB,SAAS,KAAKD,CAAI,GACrBC,EAAI,SAAS,CACX,KAAMN,EAAa,OACnB,QAAS,uCACX,CAAC,CAEL,CAEO,SAASQ,EAA0BH,EAAcC,EAAoB,CAC1EF,EAAaC,EAAMC,CAAG,EAEjB,SAAS,KAAKD,CAAI,GACrBC,EAAI,SAAS,CACX,KAAMN,EAAa,OACnB,QAAS,yCACX,CAAC,CAEL,CAGO,SAASS,EAAaC,EAAmBJ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E_NAMESPACE_MAX_LENGTH","validateName","name","ctx","validateCapitalizedName","validateUncapitalizedName","validateEnum","members","duplicates","getDuplicates","_factoryForValidateRoute","requireNonEmpty","requireSingleLevel","route","parts","i","validateRoute","validateBaseRoute","validateSingleLevelRoute","validateEthereumAddress","address","array","checked","element","validateNamespace","parseStaticArray","abiType","matches","zObjectName","z","validateCapitalizedName","zValueName","validateUncapitalizedName","zName","validateName","zNamespace","validateNamespace","zUserEnum","validateEnum","zOrdinaryRoute","validateRoute","zSingleLevelRoute","validateSingleLevelRoute","zBaseRoute","validateBaseRoute","zEthereumAddress","validateEthereumAddress","_MUDCoreContext","MUDContextAlreadyCreatedError","globalWithMUDCoreContext","context","MUDContextNotCreatedError","MUDCoreContext","__publicField","mudCoreConfig","config","configAsAny","context","MUDCoreContext","extender","extendMUDCoreConfig","MUDError","DynamicResolutionType","resolveTableId","tableName","isDynamicResolution","value","resolveWithContext","unresolved","context","resolved","tableId"]}
@@ -1,2 +1,2 @@
1
- import{A as F,B as G,C as H,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w as B,x as C,y as D,z as E}from"../chunk-3J7LHGP4.js";import{b as w,c as x,d as y,e as z,f as A}from"../chunk-AXXYPYMM.js";export{E as DynamicResolutionType,w as MUDContextAlreadyCreatedError,x as MUDContextNotCreatedError,B as MUDCoreContext,z as NotInsideProjectError,b as STORE_NAMESPACE_MAX_LENGTH,a as STORE_NAME_MAX_LENGTH,A as UnrecognizedSystemErrorFactory,D as extendMUDCoreConfig,y as fromZodErrorCustom,k as getDuplicates,G as isDynamicResolution,C as mudCoreConfig,m as parseStaticArray,F as resolveTableId,H as resolveWithContext,h as validateBaseRoute,d as validateCapitalizedName,f as validateEnum,j as validateEthereumAddress,c as validateName,l as validateNamespace,g as validateRoute,i as validateSingleLevelRoute,e as validateUncapitalizedName,u as zBaseRoute,v as zEthereumAddress,p as zName,q as zNamespace,n as zObjectName,s as zOrdinaryRoute,t as zSingleLevelRoute,r as zUserEnum,o as zValueName};
1
+ import{A as F,B as G,C as H,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w as B,x as C,y as D,z as E}from"../chunk-YRED5UZY.js";import{b as w,c as x,d as y,e as z,f as A}from"../chunk-NOTUCTDJ.js";export{E as DynamicResolutionType,w as MUDContextAlreadyCreatedError,x as MUDContextNotCreatedError,B as MUDCoreContext,z as NotInsideProjectError,b as STORE_NAMESPACE_MAX_LENGTH,a as STORE_NAME_MAX_LENGTH,A as UnrecognizedSystemErrorFactory,D as extendMUDCoreConfig,y as fromZodErrorCustom,k as getDuplicates,G as isDynamicResolution,C as mudCoreConfig,m as parseStaticArray,F as resolveTableId,H as resolveWithContext,h as validateBaseRoute,d as validateCapitalizedName,f as validateEnum,j as validateEthereumAddress,c as validateName,l as validateNamespace,g as validateRoute,i as validateSingleLevelRoute,e as validateUncapitalizedName,u as zBaseRoute,v as zEthereumAddress,p as zName,q as zNamespace,n as zObjectName,s as zOrdinaryRoute,t as zSingleLevelRoute,r as zUserEnum,o as zValueName};
2
2
  //# sourceMappingURL=index.js.map
@@ -1,2 +1,2 @@
1
- import{e as t}from"../chunk-AXXYPYMM.js";import{findUp as m}from"find-up";import o from"path";import s from"esbuild";import{rmSync as u}from"fs";import{pathToFileURL as f}from"url";import a from"os";var d=["mud.config.js","mud.config.mjs","mud.config.ts","mud.config.mts"],e="mud.config.temp.mjs";async function x(r){r=await n(r);try{return await s.build({entryPoints:[r],format:"esm",outfile:e,platform:"node",bundle:!0,packages:"external"}),r=await n(e,!0),(await import(r+`?update=${Date.now()}`)).default}finally{u(e,{force:!0})}}async function n(r,i){return r===void 0?r=await p():o.isAbsolute(r)||(r=o.join(process.cwd(),r),r=o.normalize(r)),i&&a.platform()==="win32"?f(r).href:r}async function p(){let r=await m(d);if(r===void 0)throw new t;return r}export{x as loadConfig,n as resolveConfigPath};
1
+ import{e as t}from"../chunk-NOTUCTDJ.js";import{findUp as m}from"find-up";import o from"path";import s from"esbuild";import{rmSync as u}from"fs";import{pathToFileURL as f}from"url";import a from"os";var d=["mud.config.js","mud.config.mjs","mud.config.ts","mud.config.mts"],e="mud.config.temp.mjs";async function x(r){r=await n(r);try{return await s.build({entryPoints:[r],format:"esm",outfile:e,platform:"node",bundle:!0,packages:"external"}),r=await n(e,!0),(await import(r+`?update=${Date.now()}`)).default}finally{u(e,{force:!0})}}async function n(r,i){return r===void 0?r=await p():o.isAbsolute(r)||(r=o.join(process.cwd(),r),r=o.normalize(r)),i&&a.platform()==="win32"?f(r).href:r}async function p(){let r=await m(d);if(r===void 0)throw new t;return r}export{x as loadConfig,n as resolveConfigPath};
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/node/loadConfig.ts"],"sourcesContent":["import { findUp } from \"find-up\";\nimport path from \"path\";\nimport { NotInsideProjectError } from \"../library/errors\";\nimport esbuild from \"esbuild\";\nimport { rmSync } from \"fs\";\nimport { pathToFileURL } from \"url\";\nimport os from \"os\";\n\n// In order of preference files are checked\nconst configFiles = [\"mud.config.js\", \"mud.config.mjs\", \"mud.config.ts\", \"mud.config.mts\"];\nconst TEMP_CONFIG = \"mud.config.temp.mjs\";\n\nexport async function loadConfig(configPath?: string): Promise<unknown> {\n configPath = await resolveConfigPath(configPath);\n try {\n await esbuild.build({\n entryPoints: [configPath],\n format: \"esm\",\n outfile: TEMP_CONFIG,\n // https://esbuild.github.io/getting-started/#bundling-for-node\n platform: \"node\",\n // bundle local imports (otherwise it may error, js can't import ts)\n bundle: true,\n // avoid bundling external imports (it's unnecessary and esbuild can't handle all node features)\n packages: \"external\",\n });\n configPath = await resolveConfigPath(TEMP_CONFIG, true);\n // Node.js caches dynamic imports, so without appending a cache breaking\n // param like `?update={Date.now()}` this import always returns the same config\n // if called multiple times in a single process, like the `dev-contracts` cli\n return (await import(configPath + `?update=${Date.now()}`)).default;\n } finally {\n rmSync(TEMP_CONFIG, { force: true });\n }\n}\n\nexport async function resolveConfigPath(configPath: string | undefined, toFileURL?: boolean) {\n if (configPath === undefined) {\n configPath = await getUserConfigPath();\n } else {\n if (!path.isAbsolute(configPath)) {\n configPath = path.join(process.cwd(), configPath);\n configPath = path.normalize(configPath);\n }\n }\n\n // Add `file:///` for Windows support\n // (see https://github.com/nodejs/node/issues/31710)\n return toFileURL && os.platform() === \"win32\" ? pathToFileURL(configPath).href : configPath;\n}\n\nasync function getUserConfigPath() {\n const tsConfigPath = await findUp(configFiles);\n if (tsConfigPath === undefined) {\n throw new NotInsideProjectError();\n }\n return tsConfigPath;\n}\n"],"mappings":"yCAAA,OAAS,UAAAA,MAAc,UACvB,OAAOC,MAAU,OAEjB,OAAOC,MAAa,UACpB,OAAS,UAAAC,MAAc,KACvB,OAAS,iBAAAC,MAAqB,MAC9B,OAAOC,MAAQ,KAGf,IAAMC,EAAc,CAAC,gBAAiB,iBAAkB,gBAAiB,gBAAgB,EACnFC,EAAc,sBAEpB,eAAsBC,EAAWC,EAAuC,CACtEA,EAAa,MAAMC,EAAkBD,CAAU,EAC/C,GAAI,CACF,aAAMP,EAAQ,MAAM,CAClB,YAAa,CAACO,CAAU,EACxB,OAAQ,MACR,QAASF,EAET,SAAU,OAEV,OAAQ,GAER,SAAU,UACZ,CAAC,EACDE,EAAa,MAAMC,EAAkBH,EAAa,EAAI,GAI9C,MAAM,OAAOE,EAAa,WAAW,KAAK,IAAI,MAAM,OAC9D,QAAE,CACAN,EAAOI,EAAa,CAAE,MAAO,EAAK,CAAC,CACrC,CACF,CAEA,eAAsBG,EAAkBD,EAAgCE,EAAqB,CAC3F,OAAIF,IAAe,OACjBA,EAAa,MAAMG,EAAkB,EAEhCC,EAAK,WAAWJ,CAAU,IAC7BA,EAAaI,EAAK,KAAK,QAAQ,IAAI,EAAGJ,CAAU,EAChDA,EAAaI,EAAK,UAAUJ,CAAU,GAMnCE,GAAaN,EAAG,SAAS,IAAM,QAAUD,EAAcK,CAAU,EAAE,KAAOA,CACnF,CAEA,eAAeG,GAAoB,CACjC,IAAME,EAAe,MAAMC,EAAOT,CAAW,EAC7C,GAAIQ,IAAiB,OACnB,MAAM,IAAIE,EAEZ,OAAOF,CACT","names":["findUp","path","esbuild","rmSync","pathToFileURL","os","configFiles","TEMP_CONFIG","loadConfig","configPath","resolveConfigPath","toFileURL","getUserConfigPath","path","tsConfigPath","findUp","NotInsideProjectError"]}
1
+ {"version":3,"sources":["../../src/node/loadConfig.ts"],"sourcesContent":["import { findUp } from \"find-up\";\nimport path from \"path\";\nimport { NotInsideProjectError } from \"../library/errors\";\nimport esbuild from \"esbuild\";\nimport { rmSync } from \"fs\";\nimport { pathToFileURL } from \"url\";\nimport os from \"os\";\n\n// TODO: explore using https://www.npmjs.com/package/ts-import instead\n\n// In order of preference files are checked\nconst configFiles = [\"mud.config.js\", \"mud.config.mjs\", \"mud.config.ts\", \"mud.config.mts\"];\nconst TEMP_CONFIG = \"mud.config.temp.mjs\";\n\nexport async function loadConfig(configPath?: string): Promise<unknown> {\n configPath = await resolveConfigPath(configPath);\n try {\n await esbuild.build({\n entryPoints: [configPath],\n format: \"esm\",\n outfile: TEMP_CONFIG,\n // https://esbuild.github.io/getting-started/#bundling-for-node\n platform: \"node\",\n // bundle local imports (otherwise it may error, js can't import ts)\n bundle: true,\n // avoid bundling external imports (it's unnecessary and esbuild can't handle all node features)\n packages: \"external\",\n });\n configPath = await resolveConfigPath(TEMP_CONFIG, true);\n // Node.js caches dynamic imports, so without appending a cache breaking\n // param like `?update={Date.now()}` this import always returns the same config\n // if called multiple times in a single process, like the `dev-contracts` cli\n return (await import(configPath + `?update=${Date.now()}`)).default;\n } finally {\n rmSync(TEMP_CONFIG, { force: true });\n }\n}\n\nexport async function resolveConfigPath(configPath: string | undefined, toFileURL?: boolean) {\n if (configPath === undefined) {\n configPath = await getUserConfigPath();\n } else {\n if (!path.isAbsolute(configPath)) {\n configPath = path.join(process.cwd(), configPath);\n configPath = path.normalize(configPath);\n }\n }\n\n // Add `file:///` for Windows support\n // (see https://github.com/nodejs/node/issues/31710)\n return toFileURL && os.platform() === \"win32\" ? pathToFileURL(configPath).href : configPath;\n}\n\nasync function getUserConfigPath() {\n const tsConfigPath = await findUp(configFiles);\n if (tsConfigPath === undefined) {\n throw new NotInsideProjectError();\n }\n return tsConfigPath;\n}\n"],"mappings":"yCAAA,OAAS,UAAAA,MAAc,UACvB,OAAOC,MAAU,OAEjB,OAAOC,MAAa,UACpB,OAAS,UAAAC,MAAc,KACvB,OAAS,iBAAAC,MAAqB,MAC9B,OAAOC,MAAQ,KAKf,IAAMC,EAAc,CAAC,gBAAiB,iBAAkB,gBAAiB,gBAAgB,EACnFC,EAAc,sBAEpB,eAAsBC,EAAWC,EAAuC,CACtEA,EAAa,MAAMC,EAAkBD,CAAU,EAC/C,GAAI,CACF,aAAMP,EAAQ,MAAM,CAClB,YAAa,CAACO,CAAU,EACxB,OAAQ,MACR,QAASF,EAET,SAAU,OAEV,OAAQ,GAER,SAAU,UACZ,CAAC,EACDE,EAAa,MAAMC,EAAkBH,EAAa,EAAI,GAI9C,MAAM,OAAOE,EAAa,WAAW,KAAK,IAAI,MAAM,OAC9D,QAAE,CACAN,EAAOI,EAAa,CAAE,MAAO,EAAK,CAAC,CACrC,CACF,CAEA,eAAsBG,EAAkBD,EAAgCE,EAAqB,CAC3F,OAAIF,IAAe,OACjBA,EAAa,MAAMG,EAAkB,EAEhCC,EAAK,WAAWJ,CAAU,IAC7BA,EAAaI,EAAK,KAAK,QAAQ,IAAI,EAAGJ,CAAU,EAChDA,EAAaI,EAAK,UAAUJ,CAAU,GAMnCE,GAAaN,EAAG,SAAS,IAAM,QAAUD,EAAcK,CAAU,EAAE,KAAOA,CACnF,CAEA,eAAeG,GAAoB,CACjC,IAAME,EAAe,MAAMC,EAAOT,CAAW,EAC7C,GAAIQ,IAAiB,OACnB,MAAM,IAAIE,EAEZ,OAAOF,CACT","names":["findUp","path","esbuild","rmSync","pathToFileURL","os","configFiles","TEMP_CONFIG","loadConfig","configPath","resolveConfigPath","toFileURL","getUserConfigPath","path","tsConfigPath","findUp","NotInsideProjectError"]}
@@ -1,2 +1,2 @@
1
- import{A as r,w as e,x as o}from"../chunk-3J7LHGP4.js";import"../chunk-AXXYPYMM.js";e.isCreated()||e.createContext();export{o as mudCoreConfig,r as resolveTableId};
1
+ import{A as r,w as e,x as o}from"../chunk-YRED5UZY.js";import"../chunk-NOTUCTDJ.js";e.isCreated()||e.createContext();export{o as mudCoreConfig,r as resolveTableId};
2
2
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@latticexyz/config",
3
- "version": "2.0.0-next.11",
3
+ "version": "2.0.0-next.13",
4
4
  "description": "Config for Store and World",
5
5
  "repository": {
6
6
  "type": "git",
@@ -28,14 +28,13 @@
28
28
  }
29
29
  },
30
30
  "dependencies": {
31
- "chalk": "^5.2.0",
32
31
  "esbuild": "^0.17.15",
33
- "ethers": "^5.7.2",
34
32
  "find-up": "^6.3.0",
33
+ "viem": "1.14.0",
35
34
  "zod": "^3.21.4",
36
35
  "zod-validation-error": "^1.3.0",
37
- "@latticexyz/common": "2.0.0-next.11",
38
- "@latticexyz/schema-type": "2.0.0-next.11"
36
+ "@latticexyz/common": "2.0.0-next.13",
37
+ "@latticexyz/schema-type": "2.0.0-next.13"
39
38
  },
40
39
  "devDependencies": {
41
40
  "tsup": "^6.7.0"
@@ -1,4 +1,3 @@
1
- import chalk from "chalk";
2
1
  import { z, ZodError, ZodIssueCode } from "zod";
3
2
  import { fromZodError } from "zod-validation-error";
4
3
 
@@ -15,7 +14,7 @@ export class MUDContextNotCreatedError extends Error {
15
14
  // Wrapper with preset styles, only requires a `prefix`
16
15
  export function fromZodErrorCustom(error: ZodError, prefix: string) {
17
16
  return fromZodError(error, {
18
- prefix: chalk.red(prefix),
17
+ prefix: prefix,
19
18
  prefixSeparator: "\n- ",
20
19
  issueSeparator: "\n- ",
21
20
  });
@@ -1,5 +1,5 @@
1
- import { utils } from "ethers";
2
1
  import { ZodIssueCode, RefinementCtx } from "zod";
2
+ import { isAddress } from "viem";
3
3
 
4
4
  export const STORE_NAME_MAX_LENGTH = 16;
5
5
  export const STORE_NAMESPACE_MAX_LENGTH = 14;
@@ -120,7 +120,7 @@ export const validateBaseRoute = _factoryForValidateRoute(false, false);
120
120
  export const validateSingleLevelRoute = _factoryForValidateRoute(true, true);
121
121
 
122
122
  export function validateEthereumAddress(address: string, ctx: RefinementCtx) {
123
- if (!utils.isAddress(address)) {
123
+ if (!isAddress(address)) {
124
124
  ctx.addIssue({
125
125
  code: ZodIssueCode.custom,
126
126
  message: `Address must be a valid Ethereum address`,
@@ -6,6 +6,8 @@ import { rmSync } from "fs";
6
6
  import { pathToFileURL } from "url";
7
7
  import os from "os";
8
8
 
9
+ // TODO: explore using https://www.npmjs.com/package/ts-import instead
10
+
9
11
  // In order of preference files are checked
10
12
  const configFiles = ["mud.config.js", "mud.config.mjs", "mud.config.ts", "mud.config.mts"];
11
13
  const TEMP_CONFIG = "mud.config.temp.mjs";
@@ -1,3 +0,0 @@
1
- import{a as m,b as f,c as p}from"./chunk-AXXYPYMM.js";import{z as r}from"zod";import{utils as U}from"ethers";import{ZodIssueCode as s}from"zod";var z=16,g=14;function d(e,t){/^\w+$/.test(e)||t.addIssue({code:s.custom,message:"Name must contain only alphanumeric & underscore characters"})}function x(e,t){d(e,t),/^[A-Z]/.test(e)||t.addIssue({code:s.custom,message:"Name must start with a capital letter"})}function C(e,t){d(e,t),/^[a-z]/.test(e)||t.addIssue({code:s.custom,message:"Name must start with a lowercase letter"})}function h(e,t){e.length===0&&t.addIssue({code:s.custom,message:"Enum must not be empty"}),e.length>=256&&t.addIssue({code:s.custom,message:"Length of enum must be < 256"});let o=M(e);o.length>0&&t.addIssue({code:s.custom,message:`Enum must not have duplicate names for: ${o.join(", ")}`})}function c(e,t){return(o,n)=>{if(o===""){e&&n.addIssue({code:s.custom,message:"Route must not be empty"});return}o[0]!=="/"&&n.addIssue({code:s.custom,message:'Route must start with "/"'}),o[o.length-1]==="/"&&n.addIssue({code:s.custom,message:'Route must not end with "/"'});let a=o.split("/");t&&a.length>2&&n.addIssue({code:s.custom,message:'Route must only have one level (e.g. "/foo")'});for(let u=1;u<a.length;u++)a[u]===""&&n.addIssue({code:s.custom,message:'Route must not contain empty route fragments (e.g. "//")'}),/^\w+$/.test(a[u])||n.addIssue({code:s.custom,message:"Route must contain only alphanumeric & underscore characters"})}}var R=c(!0,!1),y=c(!1,!1),b=c(!0,!0);function D(e,t){U.isAddress(e)||t.addIssue({code:s.custom,message:"Address must be a valid Ethereum address"})}function M(e){let t=new Set,o=new Set;for(let n of e)t.has(n)&&o.add(n),t.add(n);return[...o]}function E(e,t){e.length>g&&t.addIssue({code:s.custom,message:`Namespace must be <= ${g} characters`}),/^\w*$/.test(e)||t.addIssue({code:s.custom,message:"Selector must contain only alphanumeric & underscore characters"})}function S(e){let t=e.match(/^(\w+)\[(\d+)\]$/);return t?{elementType:t[1],staticLength:Number.parseInt(t[2])}:null}var v=r.string().superRefine(x),B=r.string().superRefine(C),G=r.string().superRefine(d),O=r.string().superRefine(E),V=r.array(v).superRefine(h),j=r.string().superRefine(R),k=r.string().superRefine(b),H=r.string().superRefine(y),P=r.string().superRefine(D);var l=class{static isCreated(){return this._global.__mudCoreContext!==void 0}static createContext(){if(this.isCreated())throw new f;let t=this._global,o=new l;return t.__mudCoreContext=o,o}static getContext(){let o=this._global.__mudCoreContext;if(o===void 0)throw new p;return o}configExtenders=[]},i=l;m(i,"_global",typeof global>"u"?window.global??{}:global);function q(e){let t=e,o=i.getContext();for(let n of o.configExtenders)t=n(t);return t}function K(e){i.getContext().configExtenders.push(e)}import{MUDError as I}from"@latticexyz/common/errors";var N=(o=>(o[o.TABLE_ID=0]="TABLE_ID",o[o.SYSTEM_ADDRESS=1]="SYSTEM_ADDRESS",o))(N||{});function te(e){return{type:0,input:e}}function w(e){return typeof e=="object"&&e!==null&&"type"in e&&"input"in e}function oe(e,t){if(!w(e))return e;let o;if(e.type===0){let n=t.tableIds?.[e.input];o=n&&{value:n,type:"bytes32"}}if(o===void 0)throw new I(`Could not resolve dynamic resolution:
2
- ${JSON.stringify(e,null,2)}`);return o}export{z as a,g as b,d as c,x as d,C as e,h as f,R as g,y as h,b as i,D as j,M as k,E as l,S as m,v as n,B as o,G as p,O as q,V as r,j as s,k as t,H as u,P as v,i as w,q as x,K as y,N as z,te as A,w as B,oe as C};
3
- //# sourceMappingURL=chunk-3J7LHGP4.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/library/commonSchemas.ts","../src/library/validation.ts","../src/library/context.ts","../src/library/core.ts","../src/library/dynamicResolution.ts"],"sourcesContent":["import { z } from \"zod\";\nimport {\n validateBaseRoute,\n validateCapitalizedName,\n validateEthereumAddress,\n validateEnum,\n validateName,\n validateRoute,\n validateSingleLevelRoute,\n validateUncapitalizedName,\n validateNamespace,\n} from \"./validation\";\n\n/** Capitalized names of objects, like tables and systems */\nexport const zObjectName = z.string().superRefine(validateCapitalizedName);\n/** Uncapitalized names of values, like keys and columns */\nexport const zValueName = z.string().superRefine(validateUncapitalizedName);\n/** Name that can start with any case */\nexport const zName = z.string().superRefine(validateName);\n/** A namespace */\nexport const zNamespace = z.string().superRefine(validateNamespace);\n\n/** List of unique enum member names and 0 < length < 256 */\nexport const zUserEnum = z.array(zObjectName).superRefine(validateEnum);\n\n/** Ordinary routes */\nexport const zOrdinaryRoute = z.string().superRefine(validateRoute);\n/** Routes with exactly 1 non-empty level */\nexport const zSingleLevelRoute = z.string().superRefine(validateSingleLevelRoute);\n/** Base routes (can be an empty string) */\nexport const zBaseRoute = z.string().superRefine(validateBaseRoute);\n\n/** A valid Ethereum address */\nexport const zEthereumAddress = z.string().superRefine(validateEthereumAddress);\n","import { utils } from \"ethers\";\nimport { ZodIssueCode, RefinementCtx } from \"zod\";\n\nexport const STORE_NAME_MAX_LENGTH = 16;\nexport const STORE_NAMESPACE_MAX_LENGTH = 14;\n\nexport function validateName(name: string, ctx: RefinementCtx) {\n if (!/^\\w+$/.test(name)) {\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message: `Name must contain only alphanumeric & underscore characters`,\n });\n }\n}\n\nexport function validateCapitalizedName(name: string, ctx: RefinementCtx) {\n validateName(name, ctx);\n\n if (!/^[A-Z]/.test(name)) {\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message: `Name must start with a capital letter`,\n });\n }\n}\n\nexport function validateUncapitalizedName(name: string, ctx: RefinementCtx) {\n validateName(name, ctx);\n\n if (!/^[a-z]/.test(name)) {\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message: `Name must start with a lowercase letter`,\n });\n }\n}\n\n// validates only the enum array, not the names of enum members\nexport function validateEnum(members: string[], ctx: RefinementCtx) {\n if (members.length === 0) {\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message: `Enum must not be empty`,\n });\n }\n if (members.length >= 256) {\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message: `Length of enum must be < 256`,\n });\n }\n\n const duplicates = getDuplicates(members);\n if (duplicates.length > 0) {\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message: `Enum must not have duplicate names for: ${duplicates.join(\", \")}`,\n });\n }\n}\n\nfunction _factoryForValidateRoute(requireNonEmpty: boolean, requireSingleLevel: boolean) {\n return (route: string, ctx: RefinementCtx) => {\n if (route === \"\") {\n if (requireNonEmpty) {\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message: `Route must not be empty`,\n });\n }\n // we can skip further validation for empty routes\n return;\n }\n\n if (route[0] !== \"/\") {\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message: `Route must start with \"/\"`,\n });\n }\n\n if (route[route.length - 1] === \"/\") {\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message: `Route must not end with \"/\"`,\n });\n }\n\n const parts = route.split(\"/\");\n if (requireSingleLevel && parts.length > 2) {\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message: `Route must only have one level (e.g. \"/foo\")`,\n });\n }\n\n // start at 1 to skip the first empty part\n for (let i = 1; i < parts.length; i++) {\n if (parts[i] === \"\") {\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message: `Route must not contain empty route fragments (e.g. \"//\")`,\n });\n }\n\n if (!/^\\w+$/.test(parts[i])) {\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message: `Route must contain only alphanumeric & underscore characters`,\n });\n }\n }\n };\n}\n\nexport const validateRoute = _factoryForValidateRoute(true, false);\n\nexport const validateBaseRoute = _factoryForValidateRoute(false, false);\n\nexport const validateSingleLevelRoute = _factoryForValidateRoute(true, true);\n\nexport function validateEthereumAddress(address: string, ctx: RefinementCtx) {\n if (!utils.isAddress(address)) {\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message: `Address must be a valid Ethereum address`,\n });\n }\n}\n\nexport function getDuplicates<T>(array: T[]) {\n const checked = new Set<T>();\n const duplicates = new Set<T>();\n for (const element of array) {\n if (checked.has(element)) {\n duplicates.add(element);\n }\n checked.add(element);\n }\n return [...duplicates];\n}\n\nexport function validateNamespace(name: string, ctx: RefinementCtx) {\n if (name.length > STORE_NAMESPACE_MAX_LENGTH) {\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message: `Namespace must be <= ${STORE_NAMESPACE_MAX_LENGTH} characters`,\n });\n }\n if (!/^\\w*$/.test(name)) {\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message: `Selector must contain only alphanumeric & underscore characters`,\n });\n }\n}\n\n/** Returns null if the type does not look like a static array, otherwise element and length data */\nexport function parseStaticArray(abiType: string) {\n const matches = abiType.match(/^(\\w+)\\[(\\d+)\\]$/);\n if (!matches) return null;\n return {\n elementType: matches[1],\n staticLength: Number.parseInt(matches[2]),\n };\n}\n","import { MUDConfigExtender } from \"./core\";\nimport { MUDContextAlreadyCreatedError, MUDContextNotCreatedError } from \"./errors\";\n\nexport type GlobalWithMUDCoreContext = typeof global & {\n __mudCoreContext: MUDCoreContext;\n};\n\nexport class MUDCoreContext {\n static _global = typeof global === \"undefined\" ? window.global ?? {} : global;\n\n public static isCreated(): boolean {\n const globalWithMUDCoreContext = this._global as GlobalWithMUDCoreContext;\n return globalWithMUDCoreContext.__mudCoreContext !== undefined;\n }\n\n public static createContext(): MUDCoreContext {\n if (this.isCreated()) {\n throw new MUDContextAlreadyCreatedError();\n }\n const globalWithMUDCoreContext = this._global as GlobalWithMUDCoreContext;\n const context = new MUDCoreContext();\n globalWithMUDCoreContext.__mudCoreContext = context;\n return context;\n }\n\n public static getContext(): MUDCoreContext {\n const globalWithMUDCoreContext = this._global as GlobalWithMUDCoreContext;\n const context = globalWithMUDCoreContext.__mudCoreContext;\n if (context === undefined) {\n throw new MUDContextNotCreatedError();\n }\n return context;\n }\n\n public readonly configExtenders: MUDConfigExtender[] = [];\n}\n","import { MUDCoreContext } from \"./context\";\n\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface MUDCoreUserConfig {}\n\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface MUDCoreConfig {}\n\nexport type MUDConfigExtender = (config: MUDCoreConfig) => Record<string, unknown>;\n\n/** Resolver that sequentially passes the config through all the plugins */\nexport function mudCoreConfig(config: MUDCoreUserConfig): MUDCoreConfig {\n // config types can change with plugins, `any` helps avoid errors when typechecking dependencies\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let configAsAny = config as any;\n const context = MUDCoreContext.getContext();\n for (const extender of context.configExtenders) {\n configAsAny = extender(configAsAny);\n }\n return configAsAny;\n}\n\n/** Utility for plugin developers to extend the core config */\nexport function extendMUDCoreConfig(extender: MUDConfigExtender) {\n const context = MUDCoreContext.getContext();\n context.configExtenders.push(extender);\n}\n","import { MUDError } from \"@latticexyz/common/errors\";\n\nexport enum DynamicResolutionType {\n TABLE_ID,\n SYSTEM_ADDRESS,\n}\n\nexport type DynamicResolution = {\n type: DynamicResolutionType;\n input: string;\n};\n\nexport type ValueWithType = {\n value: string | number | Uint8Array;\n type: string;\n};\n\n/**\n * Dynamically resolve a table name to a table id at deploy time\n */\nexport function resolveTableId(tableName: string) {\n return {\n type: DynamicResolutionType.TABLE_ID,\n input: tableName,\n };\n}\n\n/** Type guard for DynamicResolution */\nexport function isDynamicResolution(value: unknown): value is DynamicResolution {\n return typeof value === \"object\" && value !== null && \"type\" in value && \"input\" in value;\n}\n\n/**\n * Turn a DynamicResolution object into a ValueWithType based on the provided context\n */\nexport function resolveWithContext(\n unresolved: any,\n context: { systemAddresses?: Record<string, Promise<string>>; tableIds?: Record<string, Uint8Array> }\n): ValueWithType {\n if (!isDynamicResolution(unresolved)) return unresolved;\n let resolved: ValueWithType | undefined = undefined;\n\n if (unresolved.type === DynamicResolutionType.TABLE_ID) {\n const tableId = context.tableIds?.[unresolved.input];\n resolved = tableId && { value: tableId, type: \"bytes32\" };\n }\n\n if (resolved === undefined) {\n throw new MUDError(`Could not resolve dynamic resolution: \\n${JSON.stringify(unresolved, null, 2)}`);\n }\n\n return resolved;\n}\n"],"mappings":"sDAAA,OAAS,KAAAA,MAAS,MCAlB,OAAS,SAAAC,MAAa,SACtB,OAAS,gBAAAC,MAAmC,MAErC,IAAMC,EAAwB,GACxBC,EAA6B,GAEnC,SAASC,EAAaC,EAAcC,EAAoB,CACxD,QAAQ,KAAKD,CAAI,GACpBC,EAAI,SAAS,CACX,KAAML,EAAa,OACnB,QAAS,6DACX,CAAC,CAEL,CAEO,SAASM,EAAwBF,EAAcC,EAAoB,CACxEF,EAAaC,EAAMC,CAAG,EAEjB,SAAS,KAAKD,CAAI,GACrBC,EAAI,SAAS,CACX,KAAML,EAAa,OACnB,QAAS,uCACX,CAAC,CAEL,CAEO,SAASO,EAA0BH,EAAcC,EAAoB,CAC1EF,EAAaC,EAAMC,CAAG,EAEjB,SAAS,KAAKD,CAAI,GACrBC,EAAI,SAAS,CACX,KAAML,EAAa,OACnB,QAAS,yCACX,CAAC,CAEL,CAGO,SAASQ,EAAaC,EAAmBJ,EAAoB,CAC9DI,EAAQ,SAAW,GACrBJ,EAAI,SAAS,CACX,KAAML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2B,KAAK,QAChCC,EAAU,IAAIH,EACpB,OAAAE,EAAyB,iBAAmBC,EACrCA,CACT,CAEA,OAAc,YAA6B,CAEzC,IAAMA,EAD2B,KAAK,QACG,iBACzC,GAAIA,IAAY,OACd,MAAM,IAAIC,EAEZ,OAAOD,CACT,CAEgB,gBAAuC,CAAC,CAC1D,EA5BaE,EAANL,EACLM,EADWD,EACJ,UAAU,OAAO,OAAW,IAAc,OAAO,QAAU,CAAC,EAAI,QCGlE,SAASE,EAAcC,EAA0C,CAGtE,IAAIC,EAAcD,EACZE,EAAUC,EAAe,WAAW,EAC1C,QAAWC,KAAYF,EAAQ,gBAC7BD,EAAcG,EAASH,CAAW,EAEpC,OAAOA,CACT,CAGO,SAASI,EAAoBD,EAA6B,CAC/CD,EAAe,WAAW,EAClC,gBAAgB,KAAKC,CAAQ,CACvC,CC1BA,OAAS,YAAAE,MAAgB,4BAElB,IAAKC,OACVA,IAAA,uBACAA,IAAA,mCAFUA,OAAA,IAkBL,SAASC,GAAeC,EAAmB,CAChD,MAAO,CACL,KAAM,EACN,MAAOA,CACT,CACF,CAGO,SAASC,EAAoBC,EAA4C,CAC9E,OAAO,OAAOA,GAAU,UAAYA,IAAU,MAAQ,SAAUA,GAAS,UAAWA,CACtF,CAKO,SAASC,GACdC,EACAC,EACe,CACf,GAAI,CAACJ,EAAoBG,CAAU,EAAG,OAAOA,EAC7C,IAAIE,EAEJ,GAAIF,EAAW,OAAS,EAAgC,CACtD,IAAMG,EAAUF,EAAQ,WAAWD,EAAW,KAAK,EACnDE,EAAWC,GAAW,CAAE,MAAOA,EAAS,KAAM,SAAU,EAG1D,GAAID,IAAa,OACf,MAAM,IAAIT,EAAS;AAAA,EAA2C,KAAK,UAAUO,EAAY,KAAM,CAAC,GAAG,EAGrG,OAAOE,CACT","names":["z","utils","ZodIssueCode","STORE_NAME_MAX_LENGTH","STORE_NAMESPACE_MAX_LENGTH","validateName","name","ctx","validateCapitalizedName","validateUncapitalizedName","validateEnum","members","duplicates","getDuplicates","_factoryForValidateRoute","requireNonEmpty","requireSingleLevel","route","parts","i","validateRoute","validateBaseRoute","validateSingleLevelRoute","validateEthereumAddress","address","array","checked","element","validateNamespace","parseStaticArray","abiType","matches","zObjectName","z","validateCapitalizedName","zValueName","validateUncapitalizedName","zName","validateName","zNamespace","validateNamespace","zUserEnum","validateEnum","zOrdinaryRoute","validateRoute","zSingleLevelRoute","validateSingleLevelRoute","zBaseRoute","validateBaseRoute","zEthereumAddress","validateEthereumAddress","_MUDCoreContext","MUDContextAlreadyCreatedError","globalWithMUDCoreContext","context","MUDContextNotCreatedError","MUDCoreContext","__publicField","mudCoreConfig","config","configAsAny","context","MUDCoreContext","extender","extendMUDCoreConfig","MUDError","DynamicResolutionType","resolveTableId","tableName","isDynamicResolution","value","resolveWithContext","unresolved","context","resolved","tableId"]}
@@ -1,4 +0,0 @@
1
- var a=Object.defineProperty;var m=(r,e,o)=>e in r?a(r,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):r[e]=o;var x=(r,e,o)=>(m(r,typeof e!="symbol"?e+"":e,o),o);import d from"chalk";import{z as c,ZodIssueCode as i}from"zod";import{fromZodError as p}from"zod-validation-error";var t=class extends Error{name="MUDContextAlreadyCreatedError";message="MUD context was already created"},s=class extends Error{name="MUDContextNotCreatedError";message="MUD context has not been created"};function l(r,e){return p(r,{prefix:d.red(e),prefixSeparator:`
2
- - `,issueSeparator:`
3
- - `})}var n=class extends Error{name="NotInsideProjectError";message="You are not inside a MUD project"};function U(r,e){return new c.ZodError([{code:i.custom,path:r,message:`Unrecognized system: "${e}"`}])}export{x as a,t as b,s as c,l as d,n as e,U as f};
4
- //# sourceMappingURL=chunk-AXXYPYMM.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/library/errors.ts"],"sourcesContent":["import chalk from \"chalk\";\nimport { z, ZodError, ZodIssueCode } from \"zod\";\nimport { fromZodError } from \"zod-validation-error\";\n\nexport class MUDContextAlreadyCreatedError extends Error {\n name = \"MUDContextAlreadyCreatedError\";\n message = \"MUD context was already created\";\n}\n\nexport class MUDContextNotCreatedError extends Error {\n name = \"MUDContextNotCreatedError\";\n message = \"MUD context has not been created\";\n}\n\n// Wrapper with preset styles, only requires a `prefix`\nexport function fromZodErrorCustom(error: ZodError, prefix: string) {\n return fromZodError(error, {\n prefix: chalk.red(prefix),\n prefixSeparator: \"\\n- \",\n issueSeparator: \"\\n- \",\n });\n}\n\nexport class NotInsideProjectError extends Error {\n name = \"NotInsideProjectError\";\n message = \"You are not inside a MUD project\";\n}\n\nexport function UnrecognizedSystemErrorFactory(path: string[], systemName: string) {\n return new z.ZodError([{ code: ZodIssueCode.custom, path: path, message: `Unrecognized system: \"${systemName}\"` }]);\n}\n"],"mappings":"wKAAA,OAAOA,MAAW,QAClB,OAAS,KAAAC,EAAa,gBAAAC,MAAoB,MAC1C,OAAS,gBAAAC,MAAoB,uBAEtB,IAAMC,EAAN,cAA4C,KAAM,CACvD,KAAO,gCACP,QAAU,iCACZ,EAEaC,EAAN,cAAwC,KAAM,CACnD,KAAO,4BACP,QAAU,kCACZ,EAGO,SAASC,EAAmBC,EAAiBC,EAAgB,CAClE,OAAOL,EAAaI,EAAO,CACzB,OAAQP,EAAM,IAAIQ,CAAM,EACxB,gBAAiB;AAAA,IACjB,eAAgB;AAAA,GAClB,CAAC,CACH,CAEO,IAAMC,EAAN,cAAoC,KAAM,CAC/C,KAAO,wBACP,QAAU,kCACZ,EAEO,SAASC,EAA+BC,EAAgBC,EAAoB,CACjF,OAAO,IAAIX,EAAE,SAAS,CAAC,CAAE,KAAMC,EAAa,OAAQ,KAAMS,EAAM,QAAS,yBAAyBC,IAAc,CAAC,CAAC,CACpH","names":["chalk","z","ZodIssueCode","fromZodError","MUDContextAlreadyCreatedError","MUDContextNotCreatedError","fromZodErrorCustom","error","prefix","NotInsideProjectError","UnrecognizedSystemErrorFactory","path","systemName"]}