@latticexyz/store 2.0.13-main-609de113f → 3.0.0-main-e85dc5349
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-4TPTNI2Q.js → chunk-ULFS6I46.js} +2 -2
- package/dist/{chunk-4TPTNI2Q.js.map → chunk-ULFS6I46.js.map} +1 -1
- package/dist/chunk-YSCNU2IH.js +2 -0
- package/dist/chunk-YSCNU2IH.js.map +1 -0
- package/dist/codegen.d.ts +1 -1
- package/dist/codegen.js +41 -41
- package/dist/codegen.js.map +1 -1
- package/dist/config/v2.d.ts +3 -3
- package/dist/config/v2.js +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/mud.config.d.ts +129 -38
- package/dist/mud.config.js +1 -1
- package/dist/namespacedTables-bf676cf3.d.ts +12 -0
- package/dist/{output-2853398e.d.ts → output-672c1950.d.ts} +26 -7
- package/dist/{store-cb0f85e1.d.ts → storeWithShorthands-a1806a91.d.ts} +83 -33
- package/package.json +7 -7
- package/dist/chunk-M5RJAVGF.js +0 -2
- package/dist/chunk-M5RJAVGF.js.map +0 -1
- package/dist/storeWithShorthands-43aad36b.d.ts +0 -57
@@ -1,2 +1,2 @@
|
|
1
|
-
import{
|
2
|
-
//# sourceMappingURL=chunk-
|
1
|
+
import{H as h,I as S,J as y,a as s,c as r,d as n,l as a,q as p,s as c}from"./chunk-YSCNU2IH.js";import{isFixedArrayAbiType as x,isStaticAbiType as T}from"@latticexyz/schema-type/internal";var F="Invalid schema. Expected an `id` field with a static ABI type or an explicit `key` option.";function d(e){return typeof e=="string"||n(e)&&Object.values(e).every(t=>typeof t=="string")}function b(e,t=a){if(typeof e=="string"){if(x(e)||r(t.types,e))return;throw new Error(`Invalid ABI type. \`${e}\` not found in scope.`)}if(typeof e=="object"&&e!==null){if(p(e,t)){if(r(e,"id")&&T(t.types[e.id]))return;throw new Error("Invalid schema. Expected an `id` field with a static ABI type or an explicit `key` option.")}throw new Error("Invalid schema. Are you using invalid types or missing types in your scope?")}throw new Error("Invalid table shorthand.")}function l(e,t=a){return p(e,t)?{schema:e,key:["id"]}:{schema:{id:"bytes32",value:e},key:["id"]}}function j(e,t=a){return b(e,t),l(e,t)}function u(e,t){if(n(e))for(let o of Object.keys(e))d(s(e,o))?b(s(e,o),t):c(s(e,o),t)}import{mapObject as f}from"@latticexyz/common/utils";function v(e){let t=h(e);r(e,"tables")&&n(e.tables)&&u(e.tables,t)}function m(e){let t=h(e),o={...e,tables:f(e.tables,i=>d(i)?l(i,t):i)};return S(o),y(o)}function q(e){return v(e),m(e)}export{F as a,d as b,b as c,l as d,j as e,u as f,v as g,m as h,q as i};
|
2
|
+
//# sourceMappingURL=chunk-ULFS6I46.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../ts/config/v2/tableShorthand.ts","../ts/config/v2/storeWithShorthands.ts"],"sourcesContent":["import { ErrorMessage, conform } from \"@arktype/util\";\nimport { FixedArrayAbiType, isFixedArrayAbiType, isStaticAbiType } from \"@latticexyz/schema-type/internal\";\nimport { get, hasOwnKey, isObject } from \"./generics\";\nimport { isSchemaInput } from \"./schema\";\nimport { AbiTypeScope, Scope, getStaticAbiTypeKeys } from \"./scope\";\nimport { SchemaInput, ScopedSchemaInput, TablesWithShorthandsInput } from \"./input\";\nimport { TableShorthandInput } from \"./input\";\nimport { ValidateTableOptions, validateTable } from \"./table\";\n\nexport const NoStaticKeyFieldError =\n \"Invalid schema. Expected an `id` field with a static ABI type or an explicit `key` option.\";\n\nexport type NoStaticKeyFieldError = ErrorMessage<typeof NoStaticKeyFieldError>;\n\nexport function isTableShorthandInput(shorthand: unknown): shorthand is TableShorthandInput {\n return (\n typeof shorthand === \"string\" ||\n (isObject(shorthand) && Object.values(shorthand).every((value) => typeof value === \"string\"))\n );\n}\n\nexport type validateTableWithShorthand<\n table,\n scope extends Scope = AbiTypeScope,\n options extends ValidateTableOptions = { inStoreContext: boolean },\n> = table extends TableShorthandInput ? validateTableShorthand<table, scope> : validateTable<table, scope, options>;\n\n// We don't use `conform` here because the restrictions we're imposing here are not native to typescript\nexport type validateTableShorthand<input, scope extends Scope = AbiTypeScope> = input extends SchemaInput\n ? // If a shorthand schema is provided, require it to have a static `id` field\n \"id\" extends getStaticAbiTypeKeys<input, scope>\n ? // Require all values to be valid types in this scope\n conform<input, ScopedSchemaInput<scope>>\n : NoStaticKeyFieldError\n : // If a fixed array type is provided, accept it\n input extends FixedArrayAbiType\n ? input\n : // If a valid type from the scope is provided, accept it\n input extends keyof scope[\"types\"]\n ? input\n : // If the input is not a valid shorthand, return the expected type\n input extends string\n ? keyof scope[\"types\"]\n : ScopedSchemaInput<scope>;\n\nexport function validateTableShorthand<scope extends Scope = AbiTypeScope>(\n shorthand: unknown,\n scope: scope = AbiTypeScope as never,\n): asserts shorthand is TableShorthandInput {\n if (typeof shorthand === \"string\") {\n if (isFixedArrayAbiType(shorthand) || hasOwnKey(scope.types, shorthand)) {\n return;\n }\n throw new Error(`Invalid ABI type. \\`${shorthand}\\` not found in scope.`);\n }\n if (typeof shorthand === \"object\" && shorthand !== null) {\n if (isSchemaInput(shorthand, scope)) {\n if (hasOwnKey(shorthand, \"id\") && isStaticAbiType(scope.types[shorthand.id as keyof typeof scope.types])) {\n return;\n }\n throw new Error(`Invalid schema. Expected an \\`id\\` field with a static ABI type or an explicit \\`key\\` option.`);\n }\n throw new Error(`Invalid schema. Are you using invalid types or missing types in your scope?`);\n }\n throw new Error(`Invalid table shorthand.`);\n}\n\nexport type resolveTableShorthand<shorthand, scope extends Scope = AbiTypeScope> = shorthand extends FixedArrayAbiType\n ? { schema: { id: \"bytes32\"; value: shorthand }; key: [\"id\"] }\n : shorthand extends keyof scope[\"types\"]\n ? { schema: { id: \"bytes32\"; value: shorthand }; key: [\"id\"] }\n : shorthand extends SchemaInput\n ? \"id\" extends getStaticAbiTypeKeys<shorthand, scope>\n ? // If the shorthand includes a static field called `id`, use it as `key`\n { schema: shorthand; key: [\"id\"] }\n : never\n : never;\n\nexport function resolveTableShorthand<shorthand extends TableShorthandInput, scope extends Scope = AbiTypeScope>(\n shorthand: shorthand,\n scope: scope = AbiTypeScope as never,\n): resolveTableShorthand<shorthand, scope> {\n if (isSchemaInput(shorthand, scope)) {\n return {\n schema: shorthand,\n key: [\"id\"],\n } as never;\n }\n\n return {\n schema: {\n id: \"bytes32\",\n value: shorthand,\n },\n key: [\"id\"],\n } as never;\n}\n\nexport function defineTableShorthand<shorthand, scope extends Scope = AbiTypeScope>(\n shorthand: validateTableShorthand<shorthand, scope>,\n scope: scope = AbiTypeScope as never,\n): resolveTableShorthand<shorthand, scope> {\n validateTableShorthand(shorthand, scope);\n return resolveTableShorthand(shorthand, scope) as never;\n}\n\n/**\n * If a shorthand is provided, it is resolved to a full config.\n * If a full config is provided, it is passed through.\n */\nexport type resolveTableWithShorthand<table, scope extends Scope = AbiTypeScope> = table extends TableShorthandInput\n ? resolveTableShorthand<table, scope>\n : table;\n\nexport type resolveTablesWithShorthands<input, scope extends AbiTypeScope = AbiTypeScope> = {\n [
|
1
|
+
{"version":3,"sources":["../ts/config/v2/tableShorthand.ts","../ts/config/v2/storeWithShorthands.ts"],"sourcesContent":["import { ErrorMessage, conform } from \"@arktype/util\";\nimport { FixedArrayAbiType, isFixedArrayAbiType, isStaticAbiType } from \"@latticexyz/schema-type/internal\";\nimport { get, hasOwnKey, isObject } from \"./generics\";\nimport { isSchemaInput } from \"./schema\";\nimport { AbiTypeScope, Scope, getStaticAbiTypeKeys } from \"./scope\";\nimport { SchemaInput, ScopedSchemaInput, TablesWithShorthandsInput } from \"./input\";\nimport { TableShorthandInput } from \"./input\";\nimport { ValidateTableOptions, validateTable } from \"./table\";\n\nexport const NoStaticKeyFieldError =\n \"Invalid schema. Expected an `id` field with a static ABI type or an explicit `key` option.\";\n\nexport type NoStaticKeyFieldError = ErrorMessage<typeof NoStaticKeyFieldError>;\n\nexport function isTableShorthandInput(shorthand: unknown): shorthand is TableShorthandInput {\n return (\n typeof shorthand === \"string\" ||\n (isObject(shorthand) && Object.values(shorthand).every((value) => typeof value === \"string\"))\n );\n}\n\nexport type validateTableWithShorthand<\n table,\n scope extends Scope = AbiTypeScope,\n options extends ValidateTableOptions = { inStoreContext: boolean },\n> = table extends TableShorthandInput ? validateTableShorthand<table, scope> : validateTable<table, scope, options>;\n\n// We don't use `conform` here because the restrictions we're imposing here are not native to typescript\nexport type validateTableShorthand<input, scope extends Scope = AbiTypeScope> = input extends SchemaInput\n ? // If a shorthand schema is provided, require it to have a static `id` field\n \"id\" extends getStaticAbiTypeKeys<input, scope>\n ? // Require all values to be valid types in this scope\n conform<input, ScopedSchemaInput<scope>>\n : NoStaticKeyFieldError\n : // If a fixed array type is provided, accept it\n input extends FixedArrayAbiType\n ? input\n : // If a valid type from the scope is provided, accept it\n input extends keyof scope[\"types\"]\n ? input\n : // If the input is not a valid shorthand, return the expected type\n input extends string\n ? keyof scope[\"types\"]\n : ScopedSchemaInput<scope>;\n\nexport function validateTableShorthand<scope extends Scope = AbiTypeScope>(\n shorthand: unknown,\n scope: scope = AbiTypeScope as never,\n): asserts shorthand is TableShorthandInput {\n if (typeof shorthand === \"string\") {\n if (isFixedArrayAbiType(shorthand) || hasOwnKey(scope.types, shorthand)) {\n return;\n }\n throw new Error(`Invalid ABI type. \\`${shorthand}\\` not found in scope.`);\n }\n if (typeof shorthand === \"object\" && shorthand !== null) {\n if (isSchemaInput(shorthand, scope)) {\n if (hasOwnKey(shorthand, \"id\") && isStaticAbiType(scope.types[shorthand.id as keyof typeof scope.types])) {\n return;\n }\n throw new Error(`Invalid schema. Expected an \\`id\\` field with a static ABI type or an explicit \\`key\\` option.`);\n }\n throw new Error(`Invalid schema. Are you using invalid types or missing types in your scope?`);\n }\n throw new Error(`Invalid table shorthand.`);\n}\n\nexport type resolveTableShorthand<shorthand, scope extends Scope = AbiTypeScope> = shorthand extends FixedArrayAbiType\n ? { schema: { id: \"bytes32\"; value: shorthand }; key: [\"id\"] }\n : shorthand extends keyof scope[\"types\"]\n ? { schema: { id: \"bytes32\"; value: shorthand }; key: [\"id\"] }\n : shorthand extends SchemaInput\n ? \"id\" extends getStaticAbiTypeKeys<shorthand, scope>\n ? // If the shorthand includes a static field called `id`, use it as `key`\n { schema: shorthand; key: [\"id\"] }\n : never\n : never;\n\nexport function resolveTableShorthand<shorthand extends TableShorthandInput, scope extends Scope = AbiTypeScope>(\n shorthand: shorthand,\n scope: scope = AbiTypeScope as never,\n): resolveTableShorthand<shorthand, scope> {\n if (isSchemaInput(shorthand, scope)) {\n return {\n schema: shorthand,\n key: [\"id\"],\n } as never;\n }\n\n return {\n schema: {\n id: \"bytes32\",\n value: shorthand,\n },\n key: [\"id\"],\n } as never;\n}\n\nexport function defineTableShorthand<shorthand, scope extends Scope = AbiTypeScope>(\n shorthand: validateTableShorthand<shorthand, scope>,\n scope: scope = AbiTypeScope as never,\n): resolveTableShorthand<shorthand, scope> {\n validateTableShorthand(shorthand, scope);\n return resolveTableShorthand(shorthand, scope) as never;\n}\n\n/**\n * If a shorthand is provided, it is resolved to a full config.\n * If a full config is provided, it is passed through.\n */\nexport type resolveTableWithShorthand<table, scope extends Scope = AbiTypeScope> = table extends TableShorthandInput\n ? resolveTableShorthand<table, scope>\n : table;\n\nexport type resolveTablesWithShorthands<input, scope extends AbiTypeScope = AbiTypeScope> = {\n [label in keyof input]: resolveTableWithShorthand<input[label], scope>;\n};\n\nexport type validateTablesWithShorthands<tables, scope extends Scope = AbiTypeScope> = {\n [label in keyof tables]: validateTableWithShorthand<tables[label], scope, { inStoreContext: true }>;\n};\n\nexport function validateTablesWithShorthands<scope extends Scope = AbiTypeScope>(\n tables: unknown,\n scope: scope,\n): asserts tables is TablesWithShorthandsInput {\n if (isObject(tables)) {\n for (const label of Object.keys(tables)) {\n if (isTableShorthandInput(get(tables, label))) {\n validateTableShorthand(get(tables, label), scope);\n } else {\n validateTable(get(tables, label), scope);\n }\n }\n }\n}\n","import { mapObject } from \"@latticexyz/common/utils\";\nimport { resolveStore, validateStore, extendedScope } from \"./store\";\nimport {\n isTableShorthandInput,\n resolveTableShorthand,\n resolveTablesWithShorthands,\n validateTablesWithShorthands,\n} from \"./tableShorthand\";\nimport { hasOwnKey, isObject } from \"./generics\";\nimport { StoreWithShorthandsInput } from \"./input\";\n\nexport type validateStoreWithShorthands<store> = {\n [key in keyof store]: key extends \"tables\"\n ? validateTablesWithShorthands<store[key], extendedScope<store>>\n : validateStore<store>[key];\n};\n\nexport function validateStoreWithShorthands(store: unknown): asserts store is StoreWithShorthandsInput {\n const scope = extendedScope(store);\n if (hasOwnKey(store, \"tables\") && isObject(store.tables)) {\n validateTablesWithShorthands(store.tables, scope);\n }\n}\n\nexport type resolveStoreWithShorthands<store> = resolveStore<{\n [key in keyof store]: key extends \"tables\"\n ? resolveTablesWithShorthands<store[key], extendedScope<store>>\n : store[key];\n}>;\n\nexport function resolveStoreWithShorthands<const store extends StoreWithShorthandsInput>(\n store: store,\n): resolveStoreWithShorthands<store> {\n const scope = extendedScope(store);\n const fullConfig = {\n ...store,\n tables: mapObject(store.tables, (table) => {\n return isTableShorthandInput(table) ? resolveTableShorthand(table, scope) : table;\n }),\n };\n\n validateStore(fullConfig);\n return resolveStore(fullConfig) as never;\n}\n\nexport function defineStoreWithShorthands<const store>(\n store: validateStoreWithShorthands<store>,\n): resolveStoreWithShorthands<store> {\n validateStoreWithShorthands(store);\n return resolveStoreWithShorthands(store) as never;\n}\n"],"mappings":"gGACA,OAA4B,uBAAAA,EAAqB,mBAAAC,MAAuB,mCAQjE,IAAMC,EACX,6FAIK,SAASC,EAAsBC,EAAsD,CAC1F,OACE,OAAOA,GAAc,UACpBC,EAASD,CAAS,GAAK,OAAO,OAAOA,CAAS,EAAE,MAAOE,GAAU,OAAOA,GAAU,QAAQ,CAE/F,CA0BO,SAASC,EACdH,EACAI,EAAeC,EAC2B,CAC1C,GAAI,OAAOL,GAAc,SAAU,CACjC,GAAIM,EAAoBN,CAAS,GAAKO,E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AsBD,CAAK,EAAIE,EAAsBF,EAAOR,CAAK,EAAIQ,CAC7E,CACH,EAEA,OAAAG,EAAcL,CAAU,EACjBM,EAAaN,CAAU,CAChC,CAEO,SAASO,EACdd,EACmC,CACnC,OAAAD,EAA4BC,CAAK,EAC1BM,EAA2BN,CAAK,CACzC","names":["isFixedArrayAbiType","isStaticAbiType","NoStaticKeyFieldError","isTableShorthandInput","shorthand","isObject","value","validateTableShorthand","scope","AbiTypeScope","isFixedArrayAbiType","hasOwnKey","isSchemaInput","isStaticAbiType","resolveTableShorthand","defineTableShorthand","validateTablesWithShorthands","tables","label","get","validateTable","mapObject","validateStoreWithShorthands","store","scope","extendedScope","hasOwnKey","isObject","validateTablesWithShorthands","resolveStoreWithShorthands","fullConfig","mapObject","table","isTableShorthandInput","resolveTableShorthand","validateStore","resolveStore","defineStoreWithShorthands"]}
|
@@ -0,0 +1,2 @@
|
|
1
|
+
function p(e,t){return typeof e=="object"&&e!=null&&n(e,t)?e[t]:void 0}function F(e,t){return t.length?F(p(e,t[0]),t.slice(1)):e}function n(e,t){return typeof e=="object"&&e!==null&&e.hasOwnProperty(t)}function a(e){return e!=null&&typeof e=="object"}function c(e,t){let s=[...new Set([...Object.keys(e),...Object.keys(t)])];return Object.fromEntries(s.map(o=>[o,e[o]??t[o]]))}var u={storeImportPath:"@latticexyz/store/src/",userTypesFilename:"common.sol",outputDirectory:"codegen",namespaceDirectories:!1,indexFilename:"index.sol"},m={outputDirectory:"tables",tableIdArgument:!1,storeArgument:!1},g={disabled:!1},f={namespace:"",type:"table"},b={sourceDirectory:"src",namespace:""};import{schemaAbiTypes as j}from"@latticexyz/schema-type/internal";var te={types:{}},r={types:Object.fromEntries(j.map(e=>[e,e]))};function l(e,t){return{types:{...e.types,...t}}}import{fixedArrayToArray as N,isFixedArrayAbiType as x}from"@latticexyz/schema-type/internal";function T(e,t=r){if(!a(e))throw new Error(`Expected schema, received ${JSON.stringify(e)}`);for(let s of Object.values(e))if(!x(s)&&!n(t.types,s))throw new Error(`"${String(s)}" is not a valid type in this scope.`)}function S(e,t=r){return Object.fromEntries(Object.entries(e).map(([s,o])=>[s,{type:x(o)?N(o):t.types[o],internalType:o}]))}function ie(e,t=r){return T(e,t),S(e,t)}function ce(e,t=r){return typeof e=="object"&&e!=null&&Object.values(e).every(s=>x(s)||n(t.types,s))}import{isStaticAbiType as h}from"@latticexyz/schema-type/internal";import{resourceToHex as K}from"@latticexyz/common";function $(e,t=r){return Object.entries(e).filter(([,s])=>n(t.types,s)&&h(t.types[s])).map(([s])=>s)}function B(e,t,s=r){return Array.isArray(e)&&e.every(o=>n(t,o)&&n(s.types,t[o])&&h(s.types[t[o]]))}function k(e,t=r,s={inStoreContext:!1}){if(typeof e!="object"||e==null)throw new Error(`Expected full table config, got \`${JSON.stringify(e)}\``);if(!n(e,"schema"))throw new Error("Missing schema input");if(T(e.schema,t),!n(e,"key")||!B(e.key,e.schema,t))throw new Error(`Invalid key. Expected \`(${$(e.schema,t).map(o=>`"${String(o)}"`).join(" | ")})[]\`, received \`${n(e,"key")&&Array.isArray(e.key)?`[${e.key.map(o=>`"${o}"`).join(", ")}]`:String(p(e,"key"))}\``);if(n(e,"namespace")&&typeof e.namespace=="string"&&e.namespace.length>14)throw new Error(`Table \`namespace\` must fit into a \`bytes14\`, but "${e.namespace}" is too long.`);if(n(e,"name")&&typeof e.name=="string"&&e.name.length>16)throw new Error(`Table \`name\` must fit into a \`bytes16\`, but "${e.name}" is too long.`);if(s.inStoreContext&&(n(e,"label")||n(e,"namespace")))throw new Error("Overrides of `label` and `namespace` are not allowed for tables in a store config.")}function G(e){let t=e.codegen;return{outputDirectory:p(t,"outputDirectory")??m.outputDirectory,tableIdArgument:p(t,"tableIdArgument")??m.tableIdArgument,storeArgument:p(t,"storeArgument")??m.storeArgument,dataStruct:p(t,"dataStruct")??Object.keys(e.schema).length-e.key.length>1}}function E(e,t=r){let s=e.label,o=e.type??f.type,i=e.namespace??f.namespace,y=e.name??s.slice(0,16),d=K({type:o,namespace:i,name:y});return{label:s,type:o,namespace:i,name:y,tableId:d,schema:S(e.schema,t),key:e.key,codegen:G(e),deploy:c(e.deploy??{},g)}}function Se(e,t=r){return k(e,t),E(e,t)}function A(e,t){if(a(e)){for(let s of Object.values(e))k(s,t,{inStoreContext:!0});return}throw new Error(`Expected store config, received ${JSON.stringify(e)}`)}function v(e,t){if(!a(e))throw new Error(`Expected tables config, received ${JSON.stringify(e)}`);return Object.fromEntries(Object.entries(e).map(([s,o])=>[s,E(c(o,{label:s}),t)]))}import{mapObject as P}from"@latticexyz/common/utils";import{isSchemaAbiType as M}from"@latticexyz/schema-type/internal";function V(e){return P(e,t=>t.type)}function W(e){return a(e)&&Object.values(e).every(t=>M(t.type))}function I(e,t=r){return W(e)?l(t,V(e)):t}function D(e){if(!a(e))throw new Error(`Expected userTypes, received ${JSON.stringify(e)}`);for(let{type:t}of Object.values(e))if(!n(r.types,t))throw new Error(`"${String(t)}" is not a valid ABI type.`)}import{flatMorph as O}from"@arktype/util";function J(e){return typeof e=="object"&&e!=null&&Object.values(e).every(t=>Array.isArray(t)&&t.every(s=>typeof s=="string"))}function w(e,t=r){if(J(e)){let s=Object.fromEntries(Object.keys(e).map(o=>[o,"uint8"]));return l(t,s)}return t}function Y(e){return e}function U(e){return O(e,(t,s)=>[t,O(s,(o,i)=>[i,o])])}function L(e){return a(e)?c(e,u):u}import{flatMorph as q}from"@arktype/util";function _(e,t){return q(e,(s,o)=>[t===""?s:`${t}__${s}`,o])}import{flatMorph as H}from"@arktype/util";function C(e){return w(p(e,"enums"),I(p(e,"userTypes")))}function R(e){let t=C(e);n(e,"tables")&&A(e.tables,t),n(e,"userTypes")&&D(e.userTypes)}function z(e){let t=C(e),s=e.namespace??b.namespace,o=L(e.codegen),i=v(H(e.tables??{},(y,d)=>[y,{...d,label:y,namespace:s,codegen:{...d.codegen,outputDirectory:d.codegen?.outputDirectory??(o.namespaceDirectories&&s!==""?`${s}/tables`:"tables")}}]),t);return{namespace:s,sourceDirectory:e.sourceDirectory??b.sourceDirectory,tables:_(i,s),userTypes:e.userTypes??{},enums:e.enums??{},enumValues:U(e.enums??{}),codegen:o}}function Re(e){return R(e),z(e)}export{p as a,F as b,n as c,a as d,c as e,u as f,m as g,g as h,f as i,b as j,te as k,r as l,l as m,T as n,S as o,ie as p,ce as q,B as r,k as s,G as t,E as u,Se as v,A as w,v as x,V as y,W as z,I as A,D as B,w as C,Y as D,U as E,L as F,_ as G,C as H,R as I,z as J,Re as K};
|
2
|
+
//# sourceMappingURL=chunk-YSCNU2IH.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../ts/config/v2/generics.ts","../ts/config/v2/defaults.ts","../ts/config/v2/scope.ts","../ts/config/v2/schema.ts","../ts/config/v2/table.ts","../ts/config/v2/tables.ts","../ts/config/v2/userTypes.ts","../ts/config/v2/enums.ts","../ts/config/v2/codegen.ts","../ts/config/v2/namespacedTables.ts","../ts/config/v2/store.ts"],"sourcesContent":["import { merge } from \"@arktype/util\";\n\nexport type get<input, key> = key extends keyof input ? input[key] : undefined;\n\nexport function get<input, key extends PropertyKey>(input: input, key: key): get<input, key> {\n return (typeof input === \"object\" && input != null && hasOwnKey(input, key) ? input[key] : undefined) as never;\n}\n\nexport type getPath<input, path extends readonly PropertyKey[]> = path extends readonly [\n infer head,\n ...infer tail extends PropertyKey[],\n]\n ? head extends keyof input\n ? getPath<input[head], tail>\n : undefined\n : input;\n\nexport function getPath<input, path extends readonly PropertyKey[]>(input: input, path: path): getPath<input, path> {\n return path.length ? (getPath(get(input, path[0]), path.slice(1)) as never) : (input as never);\n}\n\nexport function hasOwnKey<obj, const key extends PropertyKey>(\n object: obj,\n key: key,\n): object is { [k in key]: k extends keyof obj ? obj[k] : unknown } & obj {\n // eslint-disable-next-line no-prototype-builtins\n return typeof object === \"object\" && object !== null && object.hasOwnProperty(key);\n}\n\nexport function isObject<input>(input: input): input is input & object {\n return input != null && typeof input === \"object\";\n}\n\nexport type mergeIfUndefined<base, merged> = merge<\n base,\n {\n [key in keyof merged]: key extends keyof base\n ? undefined extends base[key]\n ? merged[key]\n : base[key]\n : merged[key];\n }\n>;\n\nexport function mergeIfUndefined<base extends object, merged extends object>(\n base: base,\n merged: merged,\n): mergeIfUndefined<base, merged> {\n const allKeys = [...new Set([...Object.keys(base), ...Object.keys(merged)])];\n return Object.fromEntries(\n allKeys.map((key) => [key, base[key as keyof base] ?? merged[key as keyof merged]]),\n ) as never;\n}\n\nexport type parseNumber<T> = T extends `${infer N extends number}` ? N : never;\n","import { CodegenInput, StoreInput, TableCodegenInput, TableDeployInput, TableInput } from \"./input\";\n\nexport const CODEGEN_DEFAULTS = {\n storeImportPath: \"@latticexyz/store/src/\",\n userTypesFilename: \"common.sol\",\n outputDirectory: \"codegen\",\n // TODO: default to true if using top-level `namespaces` key (once its migrated to store)\n namespaceDirectories: false,\n indexFilename: \"index.sol\",\n} as const satisfies CodegenInput;\n\nexport type CODEGEN_DEFAULTS = typeof CODEGEN_DEFAULTS;\n\nexport const TABLE_CODEGEN_DEFAULTS = {\n outputDirectory: \"tables\" as string,\n tableIdArgument: false,\n storeArgument: false,\n} as const satisfies TableCodegenInput;\n\nexport type TABLE_CODEGEN_DEFAULTS = typeof TABLE_CODEGEN_DEFAULTS;\n\nexport const TABLE_DEPLOY_DEFAULTS = {\n disabled: false,\n} as const satisfies TableDeployInput;\n\nexport type TABLE_DEPLOY_DEFAULTS = typeof TABLE_DEPLOY_DEFAULTS;\n\nexport const TABLE_DEFAULTS = {\n namespace: \"\",\n type: \"table\",\n} as const satisfies Pick<TableInput, \"namespace\" | \"type\">;\n\nexport type TABLE_DEFAULTS = typeof TABLE_DEFAULTS;\n\nexport const CONFIG_DEFAULTS = {\n sourceDirectory: \"src\",\n namespace: \"\",\n} as const satisfies StoreInput;\n\nexport type CONFIG_DEFAULTS = typeof CONFIG_DEFAULTS;\n","import { Dict, show } from \"@arktype/util\";\nimport { SchemaInput } from \"./input\";\nimport { StaticAbiType, schemaAbiTypes } from \"@latticexyz/schema-type/internal\";\nimport { AbiType } from \"./output\";\n\nexport const Scope = { types: {} } as const satisfies ScopeOptions;\nexport type Scope = typeof Scope;\n\nexport type AbiTypeScope = ScopeOptions<{ [t in AbiType]: t }>;\nexport const AbiTypeScope = {\n types: Object.fromEntries(schemaAbiTypes.map((abiType) => [abiType, abiType])),\n} as AbiTypeScope;\n\nexport type ScopeOptions<types extends Dict<string, AbiType> = Dict<string, AbiType>> = {\n types: types;\n};\n\nexport type getStaticAbiTypeKeys<\n schema extends SchemaInput,\n scope extends Scope = AbiTypeScope,\n> = SchemaInput extends schema\n ? string\n : {\n [key in keyof schema]: scope[\"types\"] extends { [_ in schema[key]]: StaticAbiType } ? key : never;\n }[keyof schema];\n\nexport type extendScope<scope extends ScopeOptions, additionalTypes extends Dict<string, AbiType>> = show<\n ScopeOptions<show<scope[\"types\"] & additionalTypes>>\n>;\n\nexport function extendScope<scope extends ScopeOptions, additionalTypes extends Dict<string, AbiType>>(\n scope: scope,\n additionalTypes: additionalTypes,\n): extendScope<scope, additionalTypes> {\n return {\n types: {\n ...scope.types,\n ...additionalTypes,\n },\n };\n}\n","import { conform, show } from \"@arktype/util\";\nimport { AbiTypeScope, Scope } from \"./scope\";\nimport { hasOwnKey, isObject } from \"./generics\";\nimport { SchemaInput } from \"./input\";\nimport { FixedArrayAbiType, fixedArrayToArray, isFixedArrayAbiType } from \"@latticexyz/schema-type/internal\";\n\nexport type validateSchema<schema, scope extends Scope = AbiTypeScope> = schema extends string\n ? SchemaInput\n : {\n [key in keyof schema]: schema[key] extends FixedArrayAbiType\n ? schema[key]\n : conform<schema[key], keyof scope[\"types\"]>;\n };\n\nexport function validateSchema<scope extends Scope = AbiTypeScope>(\n schema: unknown,\n scope: scope = AbiTypeScope as never,\n): asserts schema is SchemaInput {\n if (!isObject(schema)) {\n throw new Error(`Expected schema, received ${JSON.stringify(schema)}`);\n }\n\n for (const internalType of Object.values(schema)) {\n if (isFixedArrayAbiType(internalType)) continue;\n if (hasOwnKey(scope.types, internalType)) continue;\n throw new Error(`\"${String(internalType)}\" is not a valid type in this scope.`);\n }\n}\n\nexport type resolveSchema<schema, scope extends Scope> = show<{\n readonly [key in keyof schema]: {\n /** the Solidity primitive ABI type */\n readonly type: schema[key] extends FixedArrayAbiType\n ? fixedArrayToArray<schema[key]>\n : scope[\"types\"][schema[key] & keyof scope[\"types\"]];\n /** the user defined type or Solidity primitive ABI type */\n readonly internalType: schema[key];\n };\n}>;\n\nexport function resolveSchema<schema extends SchemaInput, scope extends Scope = AbiTypeScope>(\n schema: schema,\n scope: scope = AbiTypeScope as unknown as scope,\n): resolveSchema<schema, scope> {\n return Object.fromEntries(\n Object.entries(schema).map(([key, internalType]) => [\n key,\n {\n type: isFixedArrayAbiType(internalType) ? fixedArrayToArray(internalType) : scope.types[internalType as never],\n internalType,\n },\n ]),\n ) as never;\n}\n\nexport function defineSchema<schema, scope extends AbiTypeScope = AbiTypeScope>(\n schema: validateSchema<schema, scope>,\n scope: scope = AbiTypeScope as scope,\n): resolveSchema<schema, scope> {\n validateSchema(schema, scope);\n return resolveSchema(schema, scope) as never;\n}\n\nexport function isSchemaInput<scope extends Scope = AbiTypeScope>(\n input: unknown,\n scope: scope = AbiTypeScope as never,\n): input is SchemaInput {\n return (\n typeof input === \"object\" &&\n input != null &&\n Object.values(input).every((fieldType) => isFixedArrayAbiType(fieldType) || hasOwnKey(scope.types, fieldType))\n );\n}\n","import { ErrorMessage, conform, show, narrow, requiredKeyOf } from \"@arktype/util\";\nimport { isStaticAbiType } from \"@latticexyz/schema-type/internal\";\nimport { Hex } from \"viem\";\nimport { get, hasOwnKey, mergeIfUndefined } from \"./generics\";\nimport { resolveSchema, validateSchema } from \"./schema\";\nimport { AbiTypeScope, Scope, getStaticAbiTypeKeys } from \"./scope\";\nimport { TableCodegen } from \"./output\";\nimport { TABLE_CODEGEN_DEFAULTS, TABLE_DEFAULTS, TABLE_DEPLOY_DEFAULTS } from \"./defaults\";\nimport { resourceToHex } from \"@latticexyz/common\";\nimport { SchemaInput, TableInput } from \"./input\";\n\nexport type ValidKeys<schema extends SchemaInput, scope extends Scope> = readonly [\n getStaticAbiTypeKeys<schema, scope>,\n ...getStaticAbiTypeKeys<schema, scope>[],\n];\n\nfunction getValidKeys<schema extends SchemaInput, scope extends Scope = AbiTypeScope>(\n schema: schema,\n scope: scope = AbiTypeScope as unknown as scope,\n): ValidKeys<schema, scope> {\n return Object.entries(schema)\n .filter(([, internalType]) => hasOwnKey(scope.types, internalType) && isStaticAbiType(scope.types[internalType]))\n .map(([key]) => key) as never;\n}\n\nexport function isValidPrimaryKey<schema extends SchemaInput, scope extends Scope>(\n key: unknown,\n schema: schema,\n scope: scope = AbiTypeScope as unknown as scope,\n): key is ValidKeys<schema, scope> {\n return (\n Array.isArray(key) &&\n key.every(\n (key) =>\n hasOwnKey(schema, key) && hasOwnKey(scope.types, schema[key]) && isStaticAbiType(scope.types[schema[key]]),\n )\n );\n}\n\nexport type validateKeys<validKeys extends PropertyKey, keys> = keys extends readonly string[]\n ? {\n readonly [i in keyof keys]: keys[i] extends validKeys ? keys[i] : validKeys;\n }\n : readonly string[];\n\nexport type ValidateTableOptions = { inStoreContext: boolean };\n\nexport type requiredTableKey<inStoreContext extends boolean> = Exclude<\n requiredKeyOf<TableInput>,\n inStoreContext extends true ? \"label\" | \"namespace\" : \"\"\n>;\n\nexport type validateTable<\n input,\n scope extends Scope = AbiTypeScope,\n options extends ValidateTableOptions = { inStoreContext: false },\n> = {\n [key in keyof input | requiredTableKey<options[\"inStoreContext\"]>]: key extends \"key\"\n ? validateKeys<getStaticAbiTypeKeys<conform<get<input, \"schema\">, SchemaInput>, scope>, get<input, key>>\n : key extends \"schema\"\n ? validateSchema<get<input, key>, scope>\n : key extends \"label\" | \"namespace\"\n ? options[\"inStoreContext\"] extends true\n ? ErrorMessage<\"Overrides of `label` and `namespace` are not allowed for tables in a store config\">\n : key extends keyof input\n ? narrow<input[key]>\n : never\n : key extends keyof TableInput\n ? TableInput[key]\n : ErrorMessage<`Key \\`${key & string}\\` does not exist in TableInput`>;\n};\n\nexport function validateTable<input, scope extends Scope = AbiTypeScope>(\n input: input,\n scope: scope = AbiTypeScope as unknown as scope,\n options: ValidateTableOptions = { inStoreContext: false },\n): asserts input is TableInput & input {\n if (typeof input !== \"object\" || input == null) {\n throw new Error(`Expected full table config, got \\`${JSON.stringify(input)}\\``);\n }\n\n if (!hasOwnKey(input, \"schema\")) {\n throw new Error(\"Missing schema input\");\n }\n validateSchema(input.schema, scope);\n\n if (!hasOwnKey(input, \"key\") || !isValidPrimaryKey(input[\"key\"], input[\"schema\"], scope)) {\n throw new Error(\n `Invalid key. Expected \\`(${getValidKeys(input[\"schema\"], scope)\n .map((item) => `\"${String(item)}\"`)\n .join(\" | \")})[]\\`, received \\`${\n hasOwnKey(input, \"key\") && Array.isArray(input.key)\n ? `[${input.key.map((item) => `\"${item}\"`).join(\", \")}]`\n : String(get(input, \"key\"))\n }\\``,\n );\n }\n\n if (hasOwnKey(input, \"namespace\") && typeof input.namespace === \"string\" && input.namespace.length > 14) {\n throw new Error(`Table \\`namespace\\` must fit into a \\`bytes14\\`, but \"${input.namespace}\" is too long.`);\n }\n if (hasOwnKey(input, \"name\") && typeof input.name === \"string\" && input.name.length > 16) {\n throw new Error(`Table \\`name\\` must fit into a \\`bytes16\\`, but \"${input.name}\" is too long.`);\n }\n\n if (options.inStoreContext && (hasOwnKey(input, \"label\") || hasOwnKey(input, \"namespace\"))) {\n throw new Error(\"Overrides of `label` and `namespace` are not allowed for tables in a store config.\");\n }\n}\n\nexport type resolveTableCodegen<input extends TableInput> = show<{\n [key in keyof TableCodegen]-?: key extends keyof input[\"codegen\"]\n ? undefined extends input[\"codegen\"][key]\n ? key extends \"dataStruct\"\n ? boolean\n : key extends keyof TABLE_CODEGEN_DEFAULTS\n ? TABLE_CODEGEN_DEFAULTS[key]\n : never\n : input[\"codegen\"][key]\n : // dataStruct isn't narrowed, because its value is conditional on the number of value schema fields\n key extends \"dataStruct\"\n ? boolean\n : key extends keyof TABLE_CODEGEN_DEFAULTS\n ? TABLE_CODEGEN_DEFAULTS[key]\n : never;\n}>;\n\nexport function resolveTableCodegen<input extends TableInput>(input: input): resolveTableCodegen<input> {\n const options = input.codegen;\n return {\n outputDirectory: get(options, \"outputDirectory\") ?? TABLE_CODEGEN_DEFAULTS.outputDirectory,\n tableIdArgument: get(options, \"tableIdArgument\") ?? TABLE_CODEGEN_DEFAULTS.tableIdArgument,\n storeArgument: get(options, \"storeArgument\") ?? TABLE_CODEGEN_DEFAULTS.storeArgument,\n // dataStruct is true if there are at least 2 value fields\n dataStruct: get(options, \"dataStruct\") ?? Object.keys(input.schema).length - input.key.length > 1,\n } satisfies TableCodegen as never;\n}\n\nexport type resolveTable<input, scope extends Scope = Scope> = input extends TableInput\n ? {\n readonly label: input[\"label\"];\n readonly type: undefined extends input[\"type\"] ? typeof TABLE_DEFAULTS.type : input[\"type\"];\n readonly namespace: undefined extends input[\"namespace\"] ? typeof TABLE_DEFAULTS.namespace : input[\"namespace\"];\n readonly name: string;\n readonly tableId: Hex;\n readonly schema: resolveSchema<input[\"schema\"], scope>;\n readonly key: Readonly<input[\"key\"]>;\n readonly codegen: resolveTableCodegen<input>;\n readonly deploy: mergeIfUndefined<\n undefined extends input[\"deploy\"] ? {} : input[\"deploy\"],\n TABLE_DEPLOY_DEFAULTS\n >;\n }\n : never;\n\nexport function resolveTable<input extends TableInput, scope extends Scope = AbiTypeScope>(\n input: input,\n scope: scope = AbiTypeScope as unknown as scope,\n): resolveTable<input, scope> {\n const label = input.label;\n const type = input.type ?? TABLE_DEFAULTS.type;\n const namespace = input.namespace ?? TABLE_DEFAULTS.namespace;\n const name = input.name ?? label.slice(0, 16);\n const tableId = resourceToHex({ type, namespace, name });\n\n return {\n label,\n type,\n namespace,\n name,\n tableId,\n schema: resolveSchema(input.schema, scope),\n key: input.key,\n codegen: resolveTableCodegen(input),\n deploy: mergeIfUndefined(input.deploy ?? {}, TABLE_DEPLOY_DEFAULTS),\n } as never;\n}\n\nexport function defineTable<input, scope extends Scope = AbiTypeScope>(\n input: validateTable<input, scope>,\n scope: scope = AbiTypeScope as unknown as scope,\n): resolveTable<input, scope> {\n validateTable(input, scope);\n return resolveTable(input, scope) as never;\n}\n","import { ErrorMessage, show } from \"@arktype/util\";\nimport { isObject, mergeIfUndefined } from \"./generics\";\nimport { TablesInput } from \"./input\";\nimport { Scope, AbiTypeScope } from \"./scope\";\nimport { validateTable, resolveTable } from \"./table\";\n\nexport type validateTables<tables, scope extends Scope = AbiTypeScope> = {\n [label in keyof tables]: tables[label] extends object\n ? validateTable<tables[label], scope, { inStoreContext: true }>\n : ErrorMessage<`Expected full table config.`>;\n};\n\nexport function validateTables<scope extends Scope = AbiTypeScope>(\n input: unknown,\n scope: scope,\n): asserts input is TablesInput {\n if (isObject(input)) {\n for (const table of Object.values(input)) {\n validateTable(table, scope, { inStoreContext: true });\n }\n return;\n }\n throw new Error(`Expected store config, received ${JSON.stringify(input)}`);\n}\n\nexport type resolveTables<tables, scope extends Scope = AbiTypeScope> = show<{\n readonly [label in keyof tables]: resolveTable<mergeIfUndefined<tables[label], { label: label }>, scope>;\n}>;\n\nexport function resolveTables<tables extends TablesInput, scope extends Scope = AbiTypeScope>(\n tables: tables,\n scope: scope,\n): resolveTables<tables, scope> {\n if (!isObject(tables)) {\n throw new Error(`Expected tables config, received ${JSON.stringify(tables)}`);\n }\n\n return Object.fromEntries(\n Object.entries(tables).map(([label, table]) => {\n return [label, resolveTable(mergeIfUndefined(table, { label }), scope)];\n }),\n ) as never;\n}\n","import { mapObject } from \"@latticexyz/common/utils\";\nimport { UserTypes } from \"./output\";\nimport { isSchemaAbiType } from \"@latticexyz/schema-type/internal\";\nimport { AbiTypeScope, extendScope } from \"./scope\";\nimport { hasOwnKey, isObject } from \"./generics\";\n\nexport type extractInternalType<userTypes extends UserTypes> = { [key in keyof userTypes]: userTypes[key][\"type\"] };\n\nexport function extractInternalType<userTypes extends UserTypes>(userTypes: userTypes): extractInternalType<userTypes> {\n return mapObject(userTypes, (userType) => userType.type);\n}\n\nexport function isUserTypes(userTypes: unknown): userTypes is UserTypes {\n return isObject(userTypes) && Object.values(userTypes).every((userType) => isSchemaAbiType(userType.type));\n}\n\nexport type scopeWithUserTypes<userTypes, scope extends AbiTypeScope = AbiTypeScope> = UserTypes extends userTypes\n ? scope\n : userTypes extends UserTypes\n ? extendScope<scope, extractInternalType<userTypes>>\n : scope;\n\nexport function scopeWithUserTypes<userTypes, scope extends AbiTypeScope = AbiTypeScope>(\n userTypes: userTypes,\n scope: scope = AbiTypeScope as scope,\n): scopeWithUserTypes<userTypes, scope> {\n return (isUserTypes(userTypes) ? extendScope(scope, extractInternalType(userTypes)) : scope) as never;\n}\n\nexport function validateUserTypes(userTypes: unknown): asserts userTypes is UserTypes {\n if (!isObject(userTypes)) {\n throw new Error(`Expected userTypes, received ${JSON.stringify(userTypes)}`);\n }\n\n for (const { type } of Object.values(userTypes)) {\n if (!hasOwnKey(AbiTypeScope.types, type)) {\n throw new Error(`\"${String(type)}\" is not a valid ABI type.`);\n }\n }\n}\n","import { flatMorph } from \"@arktype/util\";\nimport { EnumsInput } from \"./input\";\nimport { AbiTypeScope, extendScope } from \"./scope\";\nimport { parseNumber } from \"./generics\";\n\nfunction isEnums(enums: unknown): enums is EnumsInput {\n return (\n typeof enums === \"object\" &&\n enums != null &&\n Object.values(enums).every((item) => Array.isArray(item) && item.every((element) => typeof element === \"string\"))\n );\n}\n\nexport type scopeWithEnums<enums, scope extends AbiTypeScope = AbiTypeScope> = EnumsInput extends enums\n ? scope\n : enums extends EnumsInput\n ? extendScope<scope, { [key in keyof enums]: \"uint8\" }>\n : scope;\n\nexport function scopeWithEnums<enums, scope extends AbiTypeScope = AbiTypeScope>(\n enums: enums,\n scope: scope = AbiTypeScope as scope,\n): scopeWithEnums<enums, scope> {\n if (isEnums(enums)) {\n const enumScope = Object.fromEntries(Object.keys(enums).map((key) => [key, \"uint8\" as const]));\n return extendScope(scope, enumScope) as never;\n }\n return scope as never;\n}\n\nexport type resolveEnums<enums> = {\n readonly [key in keyof enums]: Readonly<enums[key]>;\n};\n\nexport function resolveEnums<enums extends EnumsInput>(enums: enums): resolveEnums<enums> {\n return enums;\n}\n\nexport type mapEnums<enums> = {\n readonly [key in keyof enums]: {\n readonly [element in keyof enums[key] as enums[key][element] & string]: parseNumber<element>;\n };\n};\n\nexport function mapEnums<enums extends EnumsInput>(enums: enums): resolveEnums<enums> {\n return flatMorph(enums as EnumsInput, (enumName, enumElements) => [\n enumName,\n flatMorph(enumElements, (enumIndex, enumElement) => [enumElement, enumIndex]),\n ]) as never;\n}\n","import { CODEGEN_DEFAULTS } from \"./defaults\";\nimport { isObject, mergeIfUndefined } from \"./generics\";\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 (\n isObject(codegen) ? mergeIfUndefined(codegen, CODEGEN_DEFAULTS) : CODEGEN_DEFAULTS\n ) as resolveCodegen<codegen>;\n}\n","import { flatMorph } from \"@arktype/util\";\nimport { Tables } from \"./output\";\n\n/**\n * @internal Only kept for backwards compatibility\n */\nexport type resolveNamespacedTables<tables, namespace> = {\n readonly [label in keyof tables as namespace extends \"\"\n ? label\n : `${namespace & string}__${label & string}`]: tables[label];\n};\n\n/**\n * @internal Only kept for backwards compatibility\n */\nexport function resolveNamespacedTables<tables, namespace>(\n tables: tables,\n namespace: namespace,\n): resolveNamespacedTables<tables, namespace> {\n return flatMorph(tables as Tables, (label, table) => [\n namespace === \"\" ? label : `${namespace}__${label}`,\n table,\n ]) as never;\n}\n","import { ErrorMessage, show, flatMorph, narrow } from \"@arktype/util\";\nimport { get, hasOwnKey, mergeIfUndefined } from \"./generics\";\nimport { UserTypes } from \"./output\";\nimport { CONFIG_DEFAULTS } from \"./defaults\";\nimport { StoreInput } from \"./input\";\nimport { resolveTables, validateTables } from \"./tables\";\nimport { scopeWithUserTypes, validateUserTypes } from \"./userTypes\";\nimport { mapEnums, resolveEnums, scopeWithEnums } from \"./enums\";\nimport { resolveCodegen } from \"./codegen\";\nimport { resolveNamespacedTables } from \"./namespacedTables\";\nimport { resolveTable } from \"./table\";\n\nexport type extendedScope<input> = scopeWithEnums<get<input, \"enums\">, scopeWithUserTypes<get<input, \"userTypes\">>>;\n\nexport function extendedScope<input>(input: input): extendedScope<input> {\n return scopeWithEnums(get(input, \"enums\"), scopeWithUserTypes(get(input, \"userTypes\")));\n}\n\nexport type validateStore<input> = {\n [key in keyof input]: key extends \"tables\"\n ? validateTables<input[key], extendedScope<input>>\n : key extends \"userTypes\"\n ? UserTypes\n : key extends \"enums\"\n ? narrow<input[key]>\n : key extends keyof StoreInput\n ? StoreInput[key]\n : ErrorMessage<`\\`${key & string}\\` is not a valid Store config option.`>;\n};\n\nexport function validateStore(input: unknown): asserts input is StoreInput {\n const scope = extendedScope(input);\n if (hasOwnKey(input, \"tables\")) {\n validateTables(input.tables, scope);\n }\n\n if (hasOwnKey(input, \"userTypes\")) {\n validateUserTypes(input.userTypes);\n }\n}\n\nexport type resolveStore<\n input,\n namespace = \"namespace\" extends keyof input ? input[\"namespace\"] : CONFIG_DEFAULTS[\"namespace\"],\n> = {\n readonly namespace: namespace;\n readonly sourceDirectory: \"sourceDirectory\" extends keyof input\n ? input[\"sourceDirectory\"]\n : CONFIG_DEFAULTS[\"sourceDirectory\"];\n readonly tables: \"tables\" extends keyof input\n ? resolveNamespacedTables<\n {\n readonly [label in keyof input[\"tables\"]]: resolveTable<\n mergeIfUndefined<input[\"tables\"][label], { label: label; namespace: namespace }>,\n extendedScope<input>\n >;\n },\n namespace\n >\n : {};\n readonly userTypes: \"userTypes\" extends keyof input ? input[\"userTypes\"] : {};\n readonly enums: \"enums\" extends keyof input ? show<resolveEnums<input[\"enums\"]>> : {};\n readonly enumValues: \"enums\" extends keyof input ? show<mapEnums<input[\"enums\"]>> : {};\n readonly codegen: \"codegen\" extends keyof input ? resolveCodegen<input[\"codegen\"]> : resolveCodegen<{}>;\n};\n\nexport function resolveStore<const input extends StoreInput>(input: input): resolveStore<input> {\n const scope = extendedScope(input);\n const namespace = input.namespace ?? CONFIG_DEFAULTS[\"namespace\"];\n const codegen = resolveCodegen(input.codegen);\n\n const tables = resolveTables(\n flatMorph(input.tables ?? {}, (label, table) => {\n return [\n label,\n {\n ...table,\n label,\n namespace,\n codegen: {\n ...table.codegen,\n outputDirectory:\n table.codegen?.outputDirectory ??\n (codegen.namespaceDirectories && namespace !== \"\" ? `${namespace}/tables` : \"tables\"),\n },\n },\n ];\n }),\n scope,\n );\n\n return {\n namespace,\n sourceDirectory: input.sourceDirectory ?? CONFIG_DEFAULTS[\"sourceDirectory\"],\n tables: resolveNamespacedTables(tables, namespace),\n userTypes: input.userTypes ?? {},\n enums: resolveEnums(input.enums ?? {}),\n enumValues: mapEnums(input.enums ?? {}),\n codegen,\n } as never;\n}\n\nexport function defineStore<const input>(input: validateStore<input>): show<resolveStore<input>> {\n validateStore(input);\n return resolveStore(input) as never;\n}\n"],"mappings":"AAIO,SAASA,EAAoCC,EAAcC,EAA2B,CAC3F,OAAQ,OAAOD,GAAU,UAAYA,GAAS,MAAQE,EAAUF,EAAOC,CAAG,EAAID,EAAMC,CAAG,EAAI,MAC7F,CAWO,SAASE,EAAoDH,EAAcI,EAAkC,CAClH,OAAOA,EAAK,OAAUD,EAAQJ,EAAIC,EAAOI,EAAK,CAAC,CAAC,EAAGA,EAAK,MAAM,CAAC,CAAC,EAAeJ,CACjF,CAEO,SAASE,EACdG,EACAJ,EACwE,CAExE,OAAO,OAAOI,GAAW,UAAYA,IAAW,MAAQA,EAAO,eAAeJ,CAAG,CACnF,CAEO,SAASK,EAAgBN,EAAuC,CACrE,OAAOA,GAAS,MAAQ,OAAOA,GAAU,QAC3C,CAaO,SAASO,EACdC,EACAC,EACgC,CAChC,IAAMC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isObject","mergeIfUndefined","base","merged","allKeys","CODEGEN_DEFAULTS","TABLE_CODEGEN_DEFAULTS","TABLE_DEPLOY_DEFAULTS","TABLE_DEFAULTS","CONFIG_DEFAULTS","schemaAbiTypes","Scope","AbiTypeScope","abiType","extendScope","scope","additionalTypes","fixedArrayToArray","isFixedArrayAbiType","validateSchema","schema","scope","AbiTypeScope","isObject","internalType","hasOwnKey","resolveSchema","key","defineSchema","isSchemaInput","input","fieldType","isStaticAbiType","resourceToHex","getValidKeys","schema","scope","AbiTypeScope","internalType","hasOwnKey","isStaticAbiType","key","isValidPrimaryKey","validateTable","input","options","validateSchema","item","get","resolveTableCodegen","TABLE_CODEGEN_DEFAULTS","resolveTable","label","type","TABLE_DEFAULTS","namespace","name","tableId","resolveSchema","mergeIfUndefined","TABLE_DEPLOY_DEFAULTS","defineTable","validateTables","input","scope","isObject","table","validateTable","resolveTables","tables","label","resolveTable","mergeIfUndefined","mapObject","isSchemaAbiType","extractInternalType","userTypes","mapObject","userType","isUserTypes","isObject","isSchemaAbiType","scopeWithUserTypes","scope","AbiTypeScope","extendScope","validateUserTypes","type","hasOwnKey","flatMorph","isEnums","enums","item","element","scopeWithEnums","scope","AbiTypeScope","enumScope","key","extendScope","resolveEnums","mapEnums","flatMorph","enumName","enumElements","enumIndex","enumElement","resolveCodegen","codegen","isObject","mergeIfUndefined","CODEGEN_DEFAULTS","flatMorph","resolveNamespacedTables","tables","namespace","label","table","flatMorph","extendedScope","input","scopeWithEnums","get","scopeWithUserTypes","validateStore","scope","hasOwnKey","validateTables","validateUserTypes","resolveStore","namespace","CONFIG_DEFAULTS","codegen","resolveCodegen","tables","resolveTables","flatMorph","label","table","resolveNamespacedTables","mapEnums","defineStore"]}
|
package/dist/codegen.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { ImportDatum, StaticResourceData, RenderKeyTuple, RenderField, RenderStaticField, RenderDynamicField, RenderType, SolidityUserDefinedType } from '@latticexyz/common/codegen';
|
2
|
-
import { S as Store } from './output-
|
2
|
+
import { S as Store } from './output-672c1950.js';
|
3
3
|
import { SchemaType } from '@latticexyz/schema-type/deprecated';
|
4
4
|
import '@arktype/util';
|
5
5
|
import '@latticexyz/config';
|
package/dist/codegen.js
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
import{renderArguments as S,renderCommonData as ie,renderWithFieldSuffix as _,renderWithStore as D}from"@latticexyz/common/codegen";function U(e){let n=e.storeArgument,{_typedTableId:r,_typedKeyArgs:t,_keyTupleDefinition:d}=ie(e),i="";for(let[c,o]of e.fields.entries()){if(!e.withDynamicFieldMethods&&o.isDynamic)continue;let
|
1
|
+
import{renderArguments as S,renderCommonData as ie,renderWithFieldSuffix as _,renderWithStore as D}from"@latticexyz/common/codegen";function U(e){let n=e.storeArgument,{_typedTableId:r,_typedKeyArgs:t,_keyTupleDefinition:d}=ie(e),i="";for(let[c,o]of e.fields.entries()){if(!e.withDynamicFieldMethods&&o.isDynamic)continue;let m=`${o.typeWithLocation} ${o.name}`;if(e.withGetters&&(i+=_(e.withSuffixlessFieldMethods,o.name,a=>D(n,({_typedStore:l,_store:y,_commentSuffix:p,_methodNamePrefix:h})=>`
|
2
2
|
/**
|
3
3
|
* @notice Get ${o.name}${p}.
|
4
4
|
*/
|
5
|
-
function ${h}get${a}(${S([
|
5
|
+
function ${h}get${a}(${S([l,r,t])}) internal view returns (${m}) {
|
6
6
|
${d}
|
7
7
|
${o.isDynamic?`bytes memory _blob = ${y}.getDynamicField(
|
8
8
|
_tableId,
|
@@ -16,7 +16,7 @@ import{renderArguments as S,renderCommonData as ie,renderWithFieldSuffix as _,re
|
|
16
16
|
);`}
|
17
17
|
return ${w(o)};
|
18
18
|
}
|
19
|
-
`))),i+=_(e.withSuffixlessFieldMethods,o.name,a=>D(n,({_typedStore:
|
19
|
+
`))),i+=_(e.withSuffixlessFieldMethods,o.name,a=>D(n,({_typedStore:l,_store:y,_commentSuffix:p,_methodNamePrefix:h})=>{let f=S([l,r,t,m]),s=o.isDynamic?"setDynamicField":"setStaticField",u=A(o),g=o.isDynamic?`_tableId, _keyTuple, ${c-e.staticFields.length}, ${u}`:`_tableId, _keyTuple, ${c}, ${u}, _fieldLayout`;return`
|
20
20
|
/**
|
21
21
|
* @notice Set ${o.name}${p}.
|
22
22
|
*/
|
@@ -24,7 +24,7 @@ import{renderArguments as S,renderCommonData as ie,renderWithFieldSuffix as _,re
|
|
24
24
|
${d}
|
25
25
|
${y}.${s}(${g});
|
26
26
|
}
|
27
|
-
`})),o.isDynamic){let a=ae(o),
|
27
|
+
`})),o.isDynamic){let a=ae(o),l=c-e.staticFields.length,{typeWrappingData:y}=o;e.withGetters&&(y&&y.kind==="staticArray"?i+=_(e.withSuffixlessFieldMethods,o.name,p=>`
|
28
28
|
// The length of ${o.name}
|
29
29
|
uint256 constant length${p} = ${y.staticLength};
|
30
30
|
`):i+=_(e.withSuffixlessFieldMethods,o.name,p=>D(n,({_typedStore:h,_store:f,_commentSuffix:s,_methodNamePrefix:u})=>`
|
@@ -33,7 +33,7 @@ import{renderArguments as S,renderCommonData as ie,renderWithFieldSuffix as _,re
|
|
33
33
|
*/
|
34
34
|
function ${u}length${p}(${S([h,r,t])}) internal view returns (uint256) {
|
35
35
|
${d}
|
36
|
-
uint256 _byteLength = ${f}.getDynamicFieldLength(_tableId, _keyTuple, ${
|
36
|
+
uint256 _byteLength = ${f}.getDynamicFieldLength(_tableId, _keyTuple, ${l});
|
37
37
|
unchecked {
|
38
38
|
return _byteLength / ${a.elementLength};
|
39
39
|
}
|
@@ -47,7 +47,7 @@ import{renderArguments as S,renderCommonData as ie,renderWithFieldSuffix as _,re
|
|
47
47
|
${d}
|
48
48
|
|
49
49
|
${y&&y.kind==="staticArray"&&o.arrayElement?`
|
50
|
-
uint256 _byteLength = ${f}.getDynamicFieldLength(_tableId, _keyTuple, ${
|
50
|
+
uint256 _byteLength = ${f}.getDynamicFieldLength(_tableId, _keyTuple, ${l});
|
51
51
|
uint256 dynamicLength = _byteLength / ${a.elementLength};
|
52
52
|
uint256 staticLength = ${y.staticLength};
|
53
53
|
|
@@ -59,7 +59,7 @@ import{renderArguments as S,renderCommonData as ie,renderWithFieldSuffix as _,re
|
|
59
59
|
bytes memory _blob = ${f}.getDynamicFieldSlice(
|
60
60
|
_tableId,
|
61
61
|
_keyTuple,
|
62
|
-
${
|
62
|
+
${l},
|
63
63
|
_index * ${a.elementLength},
|
64
64
|
(_index + 1) * ${a.elementLength}
|
65
65
|
);
|
@@ -72,7 +72,7 @@ import{renderArguments as S,renderCommonData as ie,renderWithFieldSuffix as _,re
|
|
72
72
|
*/
|
73
73
|
function ${u}push${p}(${S([h,r,t,`${a.typeWithLocation} ${a.name}`])}) internal {
|
74
74
|
${d}
|
75
|
-
${f}.pushToDynamicField(_tableId, _keyTuple, ${
|
75
|
+
${f}.pushToDynamicField(_tableId, _keyTuple, ${l}, ${a.encoded});
|
76
76
|
}
|
77
77
|
`)),i+=_(e.withSuffixlessFieldMethods,o.name,p=>D(n,({_typedStore:h,_store:f,_commentSuffix:s,_methodNamePrefix:u})=>`
|
78
78
|
/**
|
@@ -80,12 +80,12 @@ import{renderArguments as S,renderCommonData as ie,renderWithFieldSuffix as _,re
|
|
80
80
|
*/
|
81
81
|
function ${u}pop${p}(${S([h,r,t])}) internal {
|
82
82
|
${d}
|
83
|
-
${f}.popFromDynamicField(_tableId, _keyTuple, ${
|
83
|
+
${f}.popFromDynamicField(_tableId, _keyTuple, ${l}, ${a.elementLength});
|
84
84
|
}
|
85
85
|
`))),i+=_(e.withSuffixlessFieldMethods,o.name,p=>D(n,({_typedStore:h,_store:f,_commentSuffix:s,_methodNamePrefix:u})=>{let g=S([h,r,t,"uint256 _index",`${a.typeWithLocation} ${a.name}`]),b=`
|
86
86
|
_tableId,
|
87
87
|
_keyTuple,
|
88
|
-
${
|
88
|
+
${l},
|
89
89
|
uint40(_index * ${a.elementLength}),
|
90
90
|
uint40(_encoded.length),
|
91
91
|
_encoded
|
@@ -102,41 +102,41 @@ import{renderArguments as S,renderCommonData as ie,renderWithFieldSuffix as _,re
|
|
102
102
|
}
|
103
103
|
`}))}}return i}function A(e){let n;return e.arrayElement?n="EncodeArray.encode":e.isDynamic?n="bytes":n="abi.encodePacked",`${n}(${e.typeUnwrap}(${e.name}))`}function G(e,n){let{staticByteLength:r}=e,t=`Bytes.getBytes${r}(_blob, ${n})`;return O(e,t)}function O(e,n){let{staticByteLength:r,internalTypeId:t}=e,d=r*8,i;if(t.match(/^uint\d{1,3}$/)||t==="address")i=`${t}(${n})`;else if(t.match(/^int\d{1,3}$/))i=`${t}(uint${d}(${n}))`;else if(t.match(/^bytes\d{1,2}$/))i=n;else if(t==="bool")i=`_toBool(uint8(${n}))`;else throw new Error(`Unknown value type id ${t}`);return`${e.typeWrap}(${i})`}function ae(e){if(e.arrayElement){let n="_element",r={...e.arrayElement,arrayElement:void 0,name:n};return{typeWithLocation:e.arrayElement.typeWithLocation,name:n,encoded:A(r),decoded:w(r),title:"an element",elementLength:e.arrayElement.staticByteLength}}else{let n="_slice",r={...e,name:n};return{typeWithLocation:`${e.typeId} memory`,name:n,encoded:A(r),decoded:w(r),title:"a slice",elementLength:1}}}function w(e){let{isDynamic:n,arrayElement:r}=e;return r?`${e.typeWrap}(
|
104
104
|
SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_${r.internalTypeId}()
|
105
|
-
)`:n?`${e.typeWrap}(${e.internalTypeId}(_blob))`:O(e,`bytes${e.staticByteLength}(_blob)`)}import{renderArguments as $,renderCommonData as q,renderList as H,renderWithStore as F}from"@latticexyz/common/codegen";function Y(e){let{structName:n,storeArgument:r}=e,{_typedTableId:t,_typedKeyArgs:d,_keyTupleDefinition:i}=q(e),c="";return e.withGetters&&(c+=F(r,({_typedStore:o,_store:
|
105
|
+
)`:n?`${e.typeWrap}(${e.internalTypeId}(_blob))`:O(e,`bytes${e.staticByteLength}(_blob)`)}import{renderArguments as $,renderCommonData as q,renderList as H,renderWithStore as F}from"@latticexyz/common/codegen";function Y(e){let{structName:n,storeArgument:r}=e,{_typedTableId:t,_typedKeyArgs:d,_keyTupleDefinition:i}=q(e),c="";return e.withGetters&&(c+=F(r,({_typedStore:o,_store:m,_commentSuffix:a,_methodNamePrefix:l})=>`
|
106
106
|
/**
|
107
107
|
* @notice Get the full data${a}.
|
108
108
|
*/
|
109
|
-
function ${
|
109
|
+
function ${l}get(${$([o,t,d])}) internal view returns (${ce(e)}) {
|
110
110
|
${i}
|
111
111
|
|
112
112
|
(
|
113
113
|
bytes memory _staticData,
|
114
114
|
EncodedLengths _encodedLengths,
|
115
115
|
bytes memory _dynamicData
|
116
|
-
) = ${
|
116
|
+
) = ${m}.getRecord(_tableId, _keyTuple, _fieldLayout);
|
117
117
|
return decode(_staticData, _encodedLengths, _dynamicData);
|
118
118
|
}
|
119
|
-
`)),c+=F(r,({_typedStore:o,_store:
|
119
|
+
`)),c+=F(r,({_typedStore:o,_store:m,_commentSuffix:a,_methodNamePrefix:l,_useExplicitFieldLayout:y})=>{let p=$([o,t,d,$(e.fields.map(({name:f,typeWithLocation:s})=>`${s} ${f}`))]),h="_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData"+(y?", _fieldLayout":"");return`
|
120
120
|
/**
|
121
121
|
* @notice Set the full data using individual values${a}.
|
122
122
|
*/
|
123
|
-
function ${
|
123
|
+
function ${l}set(${p}) internal {
|
124
124
|
${R(e)}
|
125
125
|
|
126
126
|
${i}
|
127
127
|
|
128
|
-
${
|
128
|
+
${m}.setRecord(${h});
|
129
129
|
}
|
130
|
-
`}),n!==void 0&&(c+=F(r,({_typedStore:o,_store:
|
130
|
+
`}),n!==void 0&&(c+=F(r,({_typedStore:o,_store:m,_commentSuffix:a,_methodNamePrefix:l,_useExplicitFieldLayout:y})=>{let p=$([o,t,d,`${n} memory _table`]),h="_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData"+(y?", _fieldLayout":"");return`
|
131
131
|
/**
|
132
132
|
* @notice Set the full data using the data struct${a}.
|
133
133
|
*/
|
134
|
-
function ${
|
134
|
+
function ${l}set(${p}) internal {
|
135
135
|
${R(e,"_table.")}
|
136
136
|
|
137
137
|
${i}
|
138
138
|
|
139
|
-
${
|
139
|
+
${m}.setRecord(${h});
|
140
140
|
}
|
141
141
|
`})),c+=de(e),c}function R(e,n=""){let r="";return e.staticFields.length>0?r+=`
|
142
142
|
bytes memory _staticData = encodeStatic(
|
@@ -152,44 +152,44 @@ import{renderArguments as S,renderCommonData as ie,renderWithFieldSuffix as _,re
|
|
152
152
|
`:r+=`
|
153
153
|
EncodedLengths _encodedLengths;
|
154
154
|
bytes memory _dynamicData;
|
155
|
-
`,r}function X(e){let{storeArgument:n}=e,{_typedTableId:r,_typedKeyArgs:t,_keyTupleDefinition:d}=q(e);return F(n,({_typedStore:i,_store:c,_commentSuffix:o,_methodNamePrefix:
|
155
|
+
`,r}function X(e){let{storeArgument:n}=e,{_typedTableId:r,_typedKeyArgs:t,_keyTupleDefinition:d}=q(e);return F(n,({_typedStore:i,_store:c,_commentSuffix:o,_methodNamePrefix:m,_useExplicitFieldLayout:a})=>{let l=$([i,r,t]),y="_tableId, _keyTuple"+(a?", _fieldLayout":"");return`
|
156
156
|
/**
|
157
157
|
* @notice Delete all data for given keys${o}.
|
158
158
|
*/
|
159
|
-
function ${
|
159
|
+
function ${m}deleteRecord(${l}) internal {
|
160
160
|
${d}
|
161
161
|
${c}.deleteRecord(${y});
|
162
162
|
}
|
163
|
-
`})}function de({structName:e,fields:n,staticFields:r,dynamicFields:t}){let d=e?`${e} memory _table`:$(n.map(({name:a,typeWithLocation:
|
163
|
+
`})}function de({structName:e,fields:n,staticFields:r,dynamicFields:t}){let d=e?`${e} memory _table`:$(n.map(({name:a,typeWithLocation:l})=>`${l} ${a}`)),i=e?"_table.":"",c=r.map(()=>0),o=0;for(let[a,l]of r.entries())c[a]=o,o+=l.staticByteLength;let m="";return r.length>0&&(m+=`
|
164
164
|
/**
|
165
165
|
* @notice Decode the tightly packed blob of static data using this table's field layout.
|
166
166
|
*/
|
167
|
-
function decodeStatic(bytes memory _blob) internal pure returns (${$(r.map(({name:a,typeWithLocation:
|
168
|
-
${H(r,(a,
|
169
|
-
${a.name} = ${G(a,c[
|
167
|
+
function decodeStatic(bytes memory _blob) internal pure returns (${$(r.map(({name:a,typeWithLocation:l})=>`${l} ${a}`))}) {
|
168
|
+
${H(r,(a,l)=>`
|
169
|
+
${a.name} = ${G(a,c[l])};
|
170
170
|
`)}
|
171
171
|
}
|
172
|
-
`),t.length>0&&(
|
172
|
+
`),t.length>0&&(m+=`
|
173
173
|
/**
|
174
174
|
* @notice Decode the tightly packed blob of dynamic data using the encoded lengths.
|
175
175
|
*/
|
176
|
-
function decodeDynamic(EncodedLengths _encodedLengths, bytes memory _blob) internal pure returns (${$(t.map(({name:a,typeWithLocation:
|
177
|
-
${H(t,(a,
|
176
|
+
function decodeDynamic(EncodedLengths _encodedLengths, bytes memory _blob) internal pure returns (${$(t.map(({name:a,typeWithLocation:l})=>`${l} ${a}`))}) {
|
177
|
+
${H(t,(a,l)=>l===0?`
|
178
178
|
uint256 _start;
|
179
179
|
uint256 _end;
|
180
180
|
unchecked {
|
181
|
-
_end = _encodedLengths.atIndex(${
|
181
|
+
_end = _encodedLengths.atIndex(${l});
|
182
182
|
}
|
183
183
|
${a.name} = ${K(a)};
|
184
184
|
`:`
|
185
185
|
_start = _end;
|
186
186
|
unchecked {
|
187
|
-
_end += _encodedLengths.atIndex(${
|
187
|
+
_end += _encodedLengths.atIndex(${l});
|
188
188
|
}
|
189
189
|
${a.name} = ${K(a)};
|
190
190
|
`)}
|
191
191
|
}
|
192
|
-
`),
|
192
|
+
`),m+=`
|
193
193
|
/**
|
194
194
|
* @notice Decode the tightly packed blobs using this table's field layout.
|
195
195
|
* ${r.length>0?"@param _staticData Tightly packed static fields.":""}
|
@@ -201,19 +201,19 @@ import{renderArguments as S,renderCommonData as ie,renderWithFieldSuffix as _,re
|
|
201
201
|
EncodedLengths ${t.length>0?"_encodedLengths":""},
|
202
202
|
bytes memory ${t.length>0?"_dynamicData":""}
|
203
203
|
) internal pure returns (${d}) {
|
204
|
-
`,r.length>0&&(
|
204
|
+
`,r.length>0&&(m+=`
|
205
205
|
(${$(r.map(a=>`${i}${a.name}`))}) = decodeStatic(_staticData);
|
206
|
-
`),t.length>0&&(
|
206
|
+
`),t.length>0&&(m+=`
|
207
207
|
(${$(t.map(a=>`${i}${a.name}`))}) = decodeDynamic(_encodedLengths, _dynamicData);
|
208
|
-
`),
|
208
|
+
`),m+=`
|
209
209
|
}
|
210
|
-
`,
|
210
|
+
`,m}function ce({structName:e,fields:n}){return e?`${e} memory _table`:$(n.map(({name:r,typeWithLocation:t})=>`${t} ${r}`))}function K(e){let{typeId:n,arrayElement:r,typeWrap:t}=e;return r?`${t}(
|
211
211
|
SliceLib.getSubslice(_blob, _start, _end).decodeArray_${r.typeId}()
|
212
212
|
)`:`${t}(
|
213
213
|
${n}(
|
214
214
|
SliceLib.getSubslice(_blob, _start, _end).toBytes()
|
215
215
|
)
|
216
|
-
)`}import{renderArguments as T,renderCommonData as pe,renderList as v,renderImports as he,renderTableId as fe,renderTypeHelpers as $e,renderWithStore as ge,renderedSolidityHeader as Te}from"@latticexyz/common/codegen";var k={TOTAL_LENGTH:240,NUM_STATIC_FIELDS:232,NUM_DYNAMIC_FIELDS:224};function V(e){return`FieldLayout constant _fieldLayout = FieldLayout.wrap(${ue(e)});`}function ue(e){let n=e.filter(({isDynamic:c})=>!c),r=e.length-n.length,t=0n,d=0;if(e.length>28)throw new Error("FieldLayout: too many fields");if(r>5)throw new Error("FieldLayout: too many dynamic fields");for(let c=0;c<n.length;c++){let{isDynamic:o,staticByteLength:
|
216
|
+
)`}import{renderArguments as T,renderCommonData as pe,renderList as v,renderImports as he,renderTableId as fe,renderTypeHelpers as $e,renderWithStore as ge,renderedSolidityHeader as Te}from"@latticexyz/common/codegen";var k={TOTAL_LENGTH:240,NUM_STATIC_FIELDS:232,NUM_DYNAMIC_FIELDS:224};function V(e){return`FieldLayout constant _fieldLayout = FieldLayout.wrap(${ue(e)});`}function ue(e){let n=e.filter(({isDynamic:c})=>!c),r=e.length-n.length,t=0n,d=0;if(e.length>28)throw new Error("FieldLayout: too many fields");if(r>5)throw new Error("FieldLayout: too many dynamic fields");for(let c=0;c<n.length;c++){let{isDynamic:o,staticByteLength:m}=e[c];if(o)throw new Error("FieldLayout: static type after dynamic type");d+=m,t|=BigInt(m)<<BigInt((31-4-c)*8)}return t|=BigInt(d)<<BigInt(k.TOTAL_LENGTH),t|=BigInt(n.length)<<BigInt(k.NUM_STATIC_FIELDS),t|=BigInt(r)<<BigInt(k.NUM_DYNAMIC_FIELDS),`0x${t.toString(16).padStart(64,"0")}`}import{keySchemaToHex as _e,valueSchemaToHex as be}from"@latticexyz/protocol-parser/internal";function Z(e){let{imports:n,libraryName:r,structName:t,staticResourceData:d,storeImportPath:i,fields:c,staticFields:o,dynamicFields:m,withRecordMethods:a,storeArgument:l,keyTuple:y}=e,{_typedTableId:p,_typedKeyArgs:h,_keyTupleDefinition:f}=pe(e);return`
|
217
217
|
${Te}
|
218
218
|
|
219
219
|
// Import store internals
|
@@ -268,7 +268,7 @@ import{renderArguments as S,renderCommonData as ie,renderWithFieldSuffix as _,re
|
|
268
268
|
${v(c,(s,u)=>`fieldNames[${u}] = "${s.name}";`)}
|
269
269
|
}
|
270
270
|
|
271
|
-
${ge(
|
271
|
+
${ge(l,({_typedStore:s,_store:u,_commentSuffix:g,_methodNamePrefix:b})=>`
|
272
272
|
/**
|
273
273
|
* @notice Register the table with its config${g}.
|
274
274
|
*/
|
@@ -285,9 +285,9 @@ import{renderArguments as S,renderCommonData as ie,renderWithFieldSuffix as _,re
|
|
285
285
|
|
286
286
|
${Se(o)}
|
287
287
|
|
288
|
-
${De(
|
288
|
+
${De(m)}
|
289
289
|
|
290
|
-
${Le(
|
290
|
+
${Le(m)}
|
291
291
|
|
292
292
|
/**
|
293
293
|
* @notice Encode all of a record's fields.
|
@@ -340,11 +340,11 @@ import{renderArguments as S,renderCommonData as ie,renderWithFieldSuffix as _,re
|
|
340
340
|
function encodeDynamic(${T(e.map(({name:n,typeWithLocation:r})=>`${r} ${n}`))}) internal pure returns (bytes memory) {
|
341
341
|
return abi.encodePacked(${T(e.map(n=>A(n)))});
|
342
342
|
}
|
343
|
-
`}import{renderEnums as Ie}from"@latticexyz/common/codegen";function z(e){return Ie(e.enums)}import Be from"node:fs/promises";import I from"node:path";import{formatAndWriteSolidity as W,loadAndExtractUserTypes as Me}from"@latticexyz/common/codegen";import Ee from"path";import{SchemaTypeArrayToElement as Fe}from"@latticexyz/schema-type/deprecated";import{AbiTypeToSchemaType as L,getStaticByteLength as B,SchemaType as x,SchemaTypeToAbiType as J}from"@latticexyz/schema-type/deprecated";import{parseStaticArray as Q}from"@latticexyz/config/library";function M(e,n,r){if(e in L){let d=L[e];return{schemaType:d,renderType:N(d)}}let t=Q(e);if(t){if(t.elementType in L)return xe(e,t.elementType,t.staticLength);throw new Error("Static arrays of user types are not supported")}return Ae(e,n,r)}function C(e,n,r,t){if(!(e in L||Q(e))){if(e in t){let i=t[e],c=i.importSymbol;return i.isRelativePath?{symbol:c,fromPath:i.fromPath,usedInPath:n}:{symbol:c,path:i.fromPath}}return{symbol:e,fromPath:r.codegen.userTypesFilename,usedInPath:n}}}function N(e){let n=B(e),r=n===0,t=J[e];return{typeId:t,typeWithLocation:r?t+" memory":t,enumName:x[e],staticByteLength:n,isDynamic:r,typeWrap:"",typeUnwrap:"",internalTypeId:t}}function Ae(e,n,r){if(e in n.enums){let t=x.UINT8,d=B(t),i=d===0,c=e;return{schemaType:t,renderType:{typeId:c,typeWithLocation:c,enumName:x[t],staticByteLength:d,isDynamic:i,typeWrap:`${e}`,typeUnwrap:"uint8",internalTypeId:`${J[t]}`}}}if(e in r){if(!(e in r))throw new Error(`User type "${e}" not found in MUD config`);let t=r[e],d=t.typeId,i=L[t.internalTypeId];return{schemaType:i,renderType:{typeId:d,typeWithLocation:d,enumName:x[i],staticByteLength:B(i),isDynamic:!1,typeWrap:`${d}.wrap`,typeUnwrap:`${d}.unwrap`,internalTypeId:t.internalTypeId}}}throw new Error(`User type "${e}" does not exist`)}function xe(e,n,r){let t=n+"[]",d=L[t];return{schemaType:d,renderType:{typeId:e,typeWithLocation:`${e} memory`,enumName:x[d],staticByteLength:0,isDynamic:!0,typeWrap:`toStaticArray_${n}_${r}`,typeUnwrap:`fromStaticArray_${n}_${r}`,typeWrappingData:{kind:"staticArray",elementType:n,staticLength:r},internalTypeId:t}}}import{getKeySchema as Re,getValueSchema as ke}from"@latticexyz/protocol-parser/internal";function ee(e,n){return Object.values(e.tables).map(t=>{let d=Re(t),i=ke(t),c=t.codegen.dataStruct,o=c||t.type==="offchainTable"||Object.keys(i).length>1,
|
343
|
+
`}import{renderEnums as Ie}from"@latticexyz/common/codegen";function z(e){return Ie(e.enums)}import Be from"node:fs/promises";import I from"node:path";import{formatAndWriteSolidity as W,loadAndExtractUserTypes as Me}from"@latticexyz/common/codegen";import Ee from"path";import{SchemaTypeArrayToElement as Fe}from"@latticexyz/schema-type/deprecated";import{AbiTypeToSchemaType as L,getStaticByteLength as B,SchemaType as x,SchemaTypeToAbiType as J}from"@latticexyz/schema-type/deprecated";import{parseStaticArray as Q}from"@latticexyz/config/library";function M(e,n,r){if(e in L){let d=L[e];return{schemaType:d,renderType:N(d)}}let t=Q(e);if(t){if(t.elementType in L)return xe(e,t.elementType,t.staticLength);throw new Error("Static arrays of user types are not supported")}return Ae(e,n,r)}function C(e,n,r,t){if(!(e in L||Q(e))){if(e in t){let i=t[e],c=i.importSymbol;return i.isRelativePath?{symbol:c,fromPath:i.fromPath,usedInPath:n}:{symbol:c,path:i.fromPath}}return{symbol:e,fromPath:r.codegen.userTypesFilename,usedInPath:n}}}function N(e){let n=B(e),r=n===0,t=J[e];return{typeId:t,typeWithLocation:r?t+" memory":t,enumName:x[e],staticByteLength:n,isDynamic:r,typeWrap:"",typeUnwrap:"",internalTypeId:t}}function Ae(e,n,r){if(e in n.enums){let t=x.UINT8,d=B(t),i=d===0,c=e;return{schemaType:t,renderType:{typeId:c,typeWithLocation:c,enumName:x[t],staticByteLength:d,isDynamic:i,typeWrap:`${e}`,typeUnwrap:"uint8",internalTypeId:`${J[t]}`}}}if(e in r){if(!(e in r))throw new Error(`User type "${e}" not found in MUD config`);let t=r[e],d=t.typeId,i=L[t.internalTypeId];return{schemaType:i,renderType:{typeId:d,typeWithLocation:d,enumName:x[i],staticByteLength:B(i),isDynamic:!1,typeWrap:`${d}.wrap`,typeUnwrap:`${d}.unwrap`,internalTypeId:t.internalTypeId}}}throw new Error(`User type "${e}" does not exist`)}function xe(e,n,r){let t=n+"[]",d=L[t];return{schemaType:d,renderType:{typeId:e,typeWithLocation:`${e} memory`,enumName:x[d],staticByteLength:0,isDynamic:!0,typeWrap:`toStaticArray_${n}_${r}`,typeUnwrap:`fromStaticArray_${n}_${r}`,typeWrappingData:{kind:"staticArray",elementType:n,staticLength:r},internalTypeId:t}}}import{getKeySchema as Re,getValueSchema as ke}from"@latticexyz/protocol-parser/internal";function ee(e,n){return Object.values(e.tables).map(t=>{let d=Re(t),i=ke(t),c=t.codegen.dataStruct,o=c||t.type==="offchainTable"||Object.keys(i).length>1,m=!o&&Object.keys(i).length===1,a=[],l=Object.entries(d).map(([s,u])=>{let g=u.internalType,{renderType:b}=M(g,e,n),E=C(g,t.codegen.outputDirectory,e,n);return E&&a.push(E),{...b,name:s,isDynamic:!1}}),y=Object.entries(i).map(([s,u])=>{let g=u.internalType,{renderType:b,schemaType:E}=M(g,e,n),P=C(g,t.codegen.outputDirectory,e,n);P&&a.push(P);let j=Fe[E];return{...b,arrayElement:j!==void 0?N(j):void 0,name:s}}),p=y.filter(({isDynamic:s})=>!s),h=y.filter(({isDynamic:s})=>s),f=t.codegen.tableIdArgument?void 0:{namespace:t.namespace,name:t.name,offchainOnly:t.type==="offchainTable"};return{outputPath:Ee.join(t.codegen.outputDirectory,`${t.label}.sol`),tableName:t.label,renderOptions:{imports:a,libraryName:t.label,structName:c?t.label+"Data":void 0,staticResourceData:f,storeImportPath:e.codegen.storeImportPath,keyTuple:l,fields:y,staticFields:p,dynamicFields:h,withGetters:t.type==="table",withRecordMethods:o,withDynamicFieldMethods:t.type==="table",withSuffixlessFieldMethods:m,storeArgument:t.codegen.storeArgument}}})}import{posixPath as we,renderList as Oe,renderedSolidityHeader as ve}from"@latticexyz/common/codegen";function te(e){return`
|
344
344
|
${ve}
|
345
345
|
|
346
346
|
${Oe(e,({outputPath:n,tableName:r,renderOptions:{structName:t}})=>{let d=[r];return t&&d.push(t),`import { ${d.join(", ")} } from "./${we(n)}";`})}
|
347
|
-
`}import{mapObject as Ce}from"@latticexyz/common/utils";async function vt({rootDir:e,config:n,remappings:r}){let t=I.join(e,n.sourceDirectory,n.codegen.outputDirectory),d=Me(Ce(n.userTypes,o=>({...o,internalType:o.type})),t,r),i=ee(n,d),c=Array.from(new Set(i.map(({outputPath:o})=>I.dirname(o))));if(await Promise.all(c.map(async o=>{await Be.rm(I.join(t,o),{recursive:!0,force:!0})})),await Promise.all(i.map(async({outputPath:o,renderOptions:
|
347
|
+
`}import{mapObject as Ce}from"@latticexyz/common/utils";async function vt({rootDir:e,config:n,remappings:r}){let t=I.join(e,n.sourceDirectory,n.codegen.outputDirectory),d=Me(Ce(n.userTypes,o=>({...o,internalType:o.type})),t,r),i=ee(n,d),c=Array.from(new Set(i.map(({outputPath:o})=>I.dirname(o))));if(await Promise.all(c.map(async o=>{await Be.rm(I.join(t,o),{recursive:!0,force:!0})})),await Promise.all(i.map(async({outputPath:o,renderOptions:m})=>{let a=I.join(t,o),l=Z(m);await W(l,a,"Generated table")})),i.length>0){let o=I.join(t,n.codegen.indexFilename),m=te(i);await W(m,o,"Generated table index")}if(Object.keys(n.enums).length>0){let o=I.join(t,n.codegen.userTypesFilename),m=z(n);await W(m,o,"Generated types file")}}import{renderedSolidityHeader as Ne}from"@latticexyz/common/codegen";import{staticAbiTypeToByteLength as We,staticAbiTypes as Pe}from"@latticexyz/schema-type/internal";import{getLeftPaddingBits as ne}from"@latticexyz/common/codegen";function re(e){return`
|
348
348
|
/**
|
349
349
|
* @notice Decodes a slice into an array of ${e.internalTypeId}.
|
350
350
|
* @dev Uses TightCoder for initial decoding, and then assembly for memory conversion.
|