@latticexyz/store 2.0.0 → 2.0.1
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-YZTNEBXQ.js → chunk-QX7XTPMU.js} +1 -1
- package/dist/chunk-QX7XTPMU.js.map +1 -0
- package/dist/chunk-TVGPNLGB.js +2 -0
- package/dist/chunk-TVGPNLGB.js.map +1 -0
- package/dist/config/v2.d.ts +5 -57
- package/dist/config/v2.js +1 -1
- package/dist/config/v2.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/mud.config.d.ts +5 -5
- package/dist/mud.config.js +1 -1
- package/dist/storeWithShorthands-224ad75e.d.ts +111 -0
- package/dist/{table-ae48252c.d.ts → table-eb26e26f.d.ts} +5 -5
- package/package.json +8 -8
- package/ts/config/v2/input.ts +1 -1
- package/ts/config/v2/store.test.ts +21 -0
- package/ts/config/v2/table.test.ts +5 -5
- package/ts/config/v2/table.ts +3 -3
- package/ts/exports/index.ts +1 -1
- package/dist/chunk-YZTNEBXQ.js.map +0 -1
- package/dist/store-a6c17d89.d.ts +0 -60
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
function a(e,t){return typeof e=="object"&&e!=null&&n(e,t)?e[t]:void 0}function n(e,t){return typeof e=="object"&&e!==null&&e.hasOwnProperty(t)}function p(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 d={storeImportPath:"@latticexyz/store/src/",userTypesFilename:"common.sol",outputDirectory:"codegen",indexFilename:"index.sol"},i={outputDirectory:"tables",tableIdArgument:!1,storeArgument:!1},S={disabled:!1},m={namespace:"",type:"table"},k={namespace:""};import{schemaAbiTypes as U}from"@latticexyz/schema-type/internal";var Y={types:{}},r={types:Object.fromEntries(U.map(e=>[e,e]))};function y(e,t){return{types:{...e.types,...t}}}import{fixedArrayToArray as D,isFixedArrayAbiType as u}from"@latticexyz/schema-type/internal";function l(e,t=r){if(!p(e))throw new Error(`Expected schema, received ${JSON.stringify(e)}`);for(let s of Object.values(e))if(!u(s)&&!n(t.types,s))throw new Error(`"${String(s)}" is not a valid type in this scope.`)}function f(e,t=r){return Object.fromEntries(Object.entries(e).map(([s,o])=>[s,{type:u(o)?D(o):t.types[o],internalType:o}]))}function ee(e,t=r){return l(e,t),f(e,t)}function te(e,t=r){return typeof e=="object"&&e!=null&&Object.values(e).every(s=>u(s)||n(t.types,s))}import{isStaticAbiType as g}from"@latticexyz/schema-type/internal";import{resourceToHex as j}from"@latticexyz/common";function C(e,t=r){return Object.entries(e).filter(([,s])=>n(t.types,s)&&g(t.types[s])).map(([s])=>s)}function L(e,t,s=r){return Array.isArray(e)&&e.every(o=>n(t,o)&&n(s.types,t[o])&&g(s.types[t[o]]))}function x(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(l(e.schema,t),!n(e,"key")||!L(e.key,e.schema,t))throw new Error(`Invalid key. Expected \`(${C(e.schema,t).map(o=>`"${String(o)}"`).join(" | ")})[]\`, received \`${n(e,"key")&&Array.isArray(e.key)?`[${e.key.map(o=>`"${o}"`).join(", ")}]`:String(a(e,"key"))}\``);if(s.inStoreContext&&n(e,"name")||n(e,"namespace"))throw new Error("Overrides of `name` and `namespace` are not allowed for tables in a store config.")}function _(e){let t=e.codegen;return{outputDirectory:a(t,"outputDirectory")??i.outputDirectory,tableIdArgument:a(t,"tableIdArgument")??i.tableIdArgument,storeArgument:a(t,"storeArgument")??i.storeArgument,dataStruct:a(t,"dataStruct")??Object.keys(e.schema).length-e.key.length>1}}function b(e,t=r){let s=e.name,o=e.type??m.type,T=e.namespace??m.namespace;return{tableId:e.tableId??j({type:o,namespace:T,name:s}),name:s,namespace:T,type:o,key:e.key,schema:f(e.schema,t),codegen:_(e),deploy:c(e.deploy??{},S)}}function de(e,t=r){return x(e,t),b(e,t)}function A(e,t){if(p(e)){for(let s of Object.values(e))x(s,t,{inStoreContext:!0});return}throw new Error(`Expected store config, received ${JSON.stringify(e)}`)}function h(e,t=r){if(!p(e))throw new Error(`Expected tables config, received ${JSON.stringify(e)}`);return Object.fromEntries(Object.entries(e).map(([s,o])=>[s,b(c(o,{name:s}),t)]))}import{mapObject as K}from"@latticexyz/common/utils";import{isSchemaAbiType as F}from"@latticexyz/schema-type/internal";function N(e){return K(e,t=>t.type)}function $(e){return p(e)&&Object.values(e).every(t=>F(t.type))}function v(e,t=r){return $(e)?y(t,N(e)):t}function E(e){if(!p(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.`)}function B(e){return typeof e=="object"&&e!=null&&Object.values(e).every(t=>Array.isArray(t)&&t.every(s=>typeof s=="string"))}function O(e,t=r){if(B(e)){let s=Object.fromEntries(Object.keys(e).map(o=>[o,"uint8"]));return y(t,s)}return t}function I(e){return p(e)?c(e,d):d}function w(e){return O(a(e,"enums"),v(a(e,"userTypes")))}function G(e){let t=w(e);n(e,"tables")&&A(e.tables,t),n(e,"userTypes")&&E(e.userTypes)}function W(e){return{tables:h(Object.fromEntries(Object.entries(e.tables??{}).map(([t,s])=>[e.namespace?`${e.namespace}__${t}`:t,c(s,{namespace:e.namespace,name:t})])),w(e)),userTypes:e.userTypes??{},enums:e.enums??{},namespace:e.namespace??k.namespace,codegen:I(e.codegen)}}function Ke(e){return G(e),W(e)}export{a,n as b,p as c,c as d,d as e,i as f,S as g,m as h,k as i,Y as j,r as k,y as l,l as m,f as n,ee as o,te as p,L as q,x as r,_ as s,b as t,de as u,A as v,h as w,N as x,$ as y,v as z,E as A,O as B,I as C,w as D,G as E,W as F,Ke as G};
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
2
|
+
//# sourceMappingURL=chunk-QX7XTPMU.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/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 get<\n input,\n key\n >;\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 mergeIfUndefined<base, merged>;\n}\n","export const CODEGEN_DEFAULTS = {\n storeImportPath: \"@latticexyz/store/src/\",\n userTypesFilename: \"common.sol\",\n outputDirectory: \"codegen\",\n indexFilename: \"index.sol\",\n} as const;\n\nexport const TABLE_CODEGEN_DEFAULTS = {\n outputDirectory: \"tables\",\n tableIdArgument: false,\n storeArgument: false,\n} as const;\n\nexport const TABLE_DEPLOY_DEFAULTS = {\n disabled: false,\n} as const;\n\nexport const TABLE_DEFAULTS = {\n namespace: \"\",\n type: \"table\",\n} as const;\n\nexport const CONFIG_DEFAULTS = {\n namespace: \"\",\n} as const;\n","import { Dict, evaluate } 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\"][schema[key] & keyof scope[\"types\"]] extends StaticAbiType ? key : never;\n }[keyof schema];\n\nexport type extendScope<scope extends ScopeOptions, additionalTypes extends Dict<string, AbiType>> = evaluate<\n ScopeOptions<evaluate<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, evaluate } 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 unknown as scope,\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> = evaluate<{\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)\n ? fixedArrayToArray(internalType)\n : scope.types[internalType as keyof typeof scope.types],\n internalType,\n },\n ]),\n ) as unknown as resolveSchema<schema, scope>;\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 resolveSchema<schema, scope>;\n}\n\nexport function isSchemaInput<scope extends Scope = AbiTypeScope>(\n input: unknown,\n scope: scope = AbiTypeScope as unknown as scope,\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, 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 unknown as ValidKeys<schema, scope>;\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 validateTable<\n input,\n scope extends Scope = AbiTypeScope,\n options extends ValidateTableOptions = { inStoreContext: false },\n> = {\n [key in\n | keyof input\n | Exclude<\n requiredKeyOf<TableInput>,\n options[\"inStoreContext\"] extends true ? \"name\" | \"namespace\" : \"\"\n >]: 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 \"name\" | \"namespace\"\n ? options[\"inStoreContext\"] extends true\n ? ErrorMessage<\"Overrides of `name` 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 ((options.inStoreContext && hasOwnKey(input, \"name\")) || hasOwnKey(input, \"namespace\")) {\n throw new Error(\"Overrides of `name` and `namespace` are not allowed for tables in a store config.\");\n }\n}\n\nexport type resolveTableCodegen<input extends TableInput> = {\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 typeof TABLE_CODEGEN_DEFAULTS\n ? (typeof 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 typeof TABLE_CODEGEN_DEFAULTS\n ? (typeof 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 resolveTableCodegen<input>;\n}\n\nexport type resolveTable<input, scope extends Scope = Scope> = input extends TableInput\n ? {\n readonly tableId: Hex;\n readonly name: input[\"name\"];\n readonly namespace: undefined extends input[\"namespace\"] ? typeof TABLE_DEFAULTS.namespace : input[\"namespace\"];\n readonly type: undefined extends input[\"type\"] ? typeof TABLE_DEFAULTS.type : input[\"type\"];\n readonly key: Readonly<input[\"key\"]>;\n readonly schema: resolveSchema<input[\"schema\"], scope>;\n readonly codegen: resolveTableCodegen<input>;\n readonly deploy: mergeIfUndefined<\n undefined extends input[\"deploy\"] ? {} : input[\"deploy\"],\n typeof 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 name = input.name;\n const type = input.type ?? TABLE_DEFAULTS.type;\n const namespace = input.namespace ?? TABLE_DEFAULTS.namespace;\n const tableId = input.tableId ?? resourceToHex({ type, namespace, name });\n\n return {\n tableId,\n name,\n namespace,\n type,\n key: input.key,\n schema: resolveSchema(input.schema, scope),\n codegen: resolveTableCodegen(input),\n deploy: mergeIfUndefined(input.deploy ?? {}, TABLE_DEPLOY_DEFAULTS),\n } as unknown as resolveTable<input, scope>;\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 resolveTable<input, scope>;\n}\n","import { ErrorMessage, evaluate } 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 [key in keyof tables]: tables[key] extends object\n ? validateTable<tables[key], 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> = evaluate<{\n readonly [key in keyof tables]: resolveTable<mergeIfUndefined<tables[key], { name: key }>, scope>;\n}>;\n\nexport function resolveTables<tables extends TablesInput, scope extends Scope = AbiTypeScope>(\n tables: tables,\n scope: scope = AbiTypeScope as unknown as 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(([key, table]) => {\n return [key, resolveTable(mergeIfUndefined(table, { name: key }), scope)];\n }),\n ) as unknown as resolveTables<tables, scope>;\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 scopeWithUserTypes<\n userTypes,\n scope\n >;\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 { Enums } from \"./output\";\nimport { AbiTypeScope, extendScope } from \"./scope\";\n\nfunction isEnums(enums: unknown): enums is Enums {\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> = Enums extends enums\n ? scope\n : enums extends Enums\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 scopeWithEnums<enums, scope>;\n }\n return scope as scopeWithEnums<enums, scope>;\n}\n\nexport type resolveEnums<enums> = { readonly [key in keyof enums]: Readonly<enums[key]> };\n","import { CODEGEN_DEFAULTS } from \"./defaults\";\nimport { isObject, mergeIfUndefined } from \"./generics\";\n\nexport type resolveCodegen<codegen> = codegen extends {}\n ? mergeIfUndefined<codegen, typeof CODEGEN_DEFAULTS>\n : typeof 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 { evaluate, 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 { resolveEnums, scopeWithEnums } from \"./enums\";\nimport { resolveCodegen } from \"./codegen\";\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<store> = {\n [key in keyof store]: key extends \"tables\"\n ? validateTables<store[key], extendedScope<store>>\n : key extends \"userTypes\"\n ? UserTypes\n : key extends \"enums\"\n ? narrow<store[key]>\n : key extends keyof StoreInput\n ? StoreInput[key]\n : never;\n};\n\nexport function validateStore(store: unknown): asserts store is StoreInput {\n const scope = extendedScope(store);\n if (hasOwnKey(store, \"tables\")) {\n validateTables(store.tables, scope);\n }\n\n if (hasOwnKey(store, \"userTypes\")) {\n validateUserTypes(store.userTypes);\n }\n}\n\ntype keyPrefix<store> = \"namespace\" extends keyof store\n ? store[\"namespace\"] extends \"\"\n ? \"\"\n : `${store[\"namespace\"] & string}__`\n : \"\";\n\nexport type resolveStore<store> = evaluate<{\n readonly tables: \"tables\" extends keyof store\n ? resolveTables<\n {\n [tableKey in keyof store[\"tables\"] & string as `${keyPrefix<store>}${tableKey}`]: mergeIfUndefined<\n store[\"tables\"][tableKey],\n { namespace: get<store, \"namespace\">; name: tableKey }\n >;\n },\n extendedScope<store>\n >\n : {};\n readonly userTypes: \"userTypes\" extends keyof store ? store[\"userTypes\"] : {};\n readonly enums: \"enums\" extends keyof store ? resolveEnums<store[\"enums\"]> : {};\n readonly namespace: \"namespace\" extends keyof store ? store[\"namespace\"] : (typeof CONFIG_DEFAULTS)[\"namespace\"];\n readonly codegen: \"codegen\" extends keyof store ? resolveCodegen<store[\"codegen\"]> : resolveCodegen<{}>;\n}>;\n\nexport function resolveStore<const store extends StoreInput>(store: store): resolveStore<store> {\n return {\n tables: resolveTables(\n Object.fromEntries(\n Object.entries(store.tables ?? {}).map(([tableKey, table]) => {\n const key = store.namespace ? `${store.namespace}__${tableKey}` : tableKey;\n return [key, mergeIfUndefined(table, { namespace: store.namespace, name: tableKey })];\n }),\n ),\n extendedScope(store),\n ),\n userTypes: store.userTypes ?? {},\n enums: store.enums ?? {},\n namespace: store.namespace ?? CONFIG_DEFAULTS[\"namespace\"],\n codegen: resolveCodegen(store.codegen),\n } as unknown as resolveStore<store>;\n}\n\nexport function defineStore<const store>(store: validateStore<store>): resolveStore<store> {\n validateStore(store);\n return resolveStore(store) as unknown as resolveStore<store>;\n}\n"],"mappings":"AAIO,SAASA,EAAoCC,EAAcC,EAA2B,CAC3F,OAAQ,OAAOD,GAAU,UAAYA,GAAS,MAAQE,EAAUF,EAAOC,CAAG,EAAID,EAAMC,CAAG,EAAI,MAI7F,CAEO,SAASC,EACdC,EACAF,EACwE,CAExE,OAAO,OAAOE,GAAW,UAAYA,IAAW,MA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,GAAGA,EAAM,cAAcO,IAAaA,EACrDE,EAAiBD,EAAO,CAAE,UAAWR,EAAM,UAAW,KAAMO,CAAS,CAAC,CAAC,CACrF,CACH,EACAb,EAAcM,CAAK,CACrB,EACA,UAAWA,EAAM,WAAa,CAAC,EAC/B,MAAOA,EAAM,OAAS,CAAC,EACvB,UAAWA,EAAM,WAAaU,EAAgB,UAC9C,QAASC,EAAeX,EAAM,OAAO,CACvC,CACF,CAEO,SAASY,GAAyBZ,EAAkD,CACzF,OAAAD,EAAcC,CAAK,EACZK,EAAaL,CAAK,CAC3B","names":["get","input","key","hasOwnKey","object","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","name","type","TABLE_DEFAULTS","namespace","resolveSchema","mergeIfUndefined","TABLE_DEPLOY_DEFAULTS","defineTable","validateTables","input","scope","isObject","table","validateTable","resolveTables","tables","AbiTypeScope","key","resolveTable","mergeIfUndefined","mapObject","isSchemaAbiType","extractInternalType","userTypes","mapObject","userType","isUserTypes","isObject","isSchemaAbiType","scopeWithUserTypes","scope","AbiTypeScope","extendScope","validateUserTypes","type","hasOwnKey","isEnums","enums","item","element","scopeWithEnums","scope","AbiTypeScope","enumScope","key","extendScope","resolveCodegen","codegen","isObject","mergeIfUndefined","CODEGEN_DEFAULTS","extendedScope","input","scopeWithEnums","get","scopeWithUserTypes","validateStore","store","scope","hasOwnKey","validateTables","validateUserTypes","resolveStore","resolveTables","tableKey","table","mergeIfUndefined","CONFIG_DEFAULTS","resolveCodegen","defineStore"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{D as h,E as S,F as y,a as r,b as n,c as s,k as a,p,r as c}from"./chunk-QX7XTPMU.js";import{isFixedArrayAbiType as T,isStaticAbiType as x}from"@latticexyz/schema-type/internal";function d(e){return typeof e=="string"||s(e)&&Object.values(e).every(t=>typeof t=="string")}function b(e,t=a){if(typeof e=="string"){if(T(e)||n(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(n(e,"id")&&x(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(s(e))for(let o of Object.keys(e))d(r(e,o))?b(r(e,o),t):c(r(e,o),t)}import{mapObject as f}from"@latticexyz/common/utils";function v(e){let t=h(e);n(e,"tables")&&s(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 $(e){return v(e),m(e)}export{d as a,b,l as c,j as d,u as e,v as f,m as g,$ as h};
|
|
2
|
+
//# sourceMappingURL=chunk-TVGPNLGB.js.map
|
|
@@ -0,0 +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 type NoStaticKeyFieldError =\n ErrorMessage<\"Invalid schema. Expected an `id` field with a static ABI type or an explicit `key` option.\">;\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 unknown as scope,\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 unknown as scope,\n): resolveTableShorthand<shorthand, scope> {\n if (isSchemaInput(shorthand, scope)) {\n return {\n schema: shorthand,\n key: [\"id\"],\n } as unknown as resolveTableShorthand<shorthand, scope>;\n }\n\n return {\n schema: {\n id: \"bytes32\",\n value: shorthand,\n },\n key: [\"id\"],\n } as unknown as resolveTableShorthand<shorthand, scope>;\n}\n\nexport function defineTableShorthand<shorthand, scope extends Scope = AbiTypeScope>(\n shorthand: validateTableShorthand<shorthand, scope>,\n scope: scope = AbiTypeScope as unknown as scope,\n): resolveTableShorthand<shorthand, scope> {\n validateTableShorthand(shorthand, scope);\n return resolveTableShorthand(shorthand, scope) as resolveTableShorthand<shorthand, scope>;\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 [key in keyof input]: resolveTableWithShorthand<input[key], scope>;\n};\n\nexport type validateTablesWithShorthands<tables, scope extends Scope = AbiTypeScope> = {\n [key in keyof tables]: validateTableWithShorthand<tables[key], 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 key of Object.keys(tables)) {\n if (isTableShorthandInput(get(tables, key))) {\n validateTableShorthand(get(tables, key), scope);\n } else {\n validateTable(get(tables, key), 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 unknown as resolveStoreWithShorthands<store>;\n}\n\nexport function defineStoreWithShorthands<const store>(\n store: validateStoreWithShorthands<store>,\n): resolveStoreWithShorthands<store> {\n validateStoreWithShorthands(store);\n return resolveStoreWithShorthands(store) as unknown as resolveStoreWithShorthands<store>;\n}\n"],"mappings":"2FACA,OAA4B,uBAAAA,EAAqB,mBAAAC,MAAuB,mCAWjE,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,EAAUH,EAAM,MAAOJ,CAAS,EACpE,OAEF,MAAM,IAAI,MAAM,uBAAuBA,yBAAiC,EAE1E,GAAI,OAAOA,GAAc,UAAYA,IAAc,KAAM,CACvD,GAAIQ,EAAcR,EAAWI,CAAK,EAAG,CACnC,GAAIG,EAAUP,EAAW,IAAI,GAAKS,EAAgBL,EAAM,MAAMJ,EAAU,EAA8B,CAAC,EACrG,OAEF,MAAM,IAAI,MAAM,4FAAgG,EAElH,MAAM,IAAI,MAAM,6EAA6E,EAE/F,MAAM,IAAI,MAAM,0BAA0B,CAC5C,CAaO,SAASU,EACdV,EACAI,EAAeC,EAC0B,CACzC,OAAIG,EAAcR,EAAWI,CAAK,EACzB,CACL,OAAQJ,EACR,IAAK,CAAC,IAAI,CACZ,EAGK,CACL,OAAQ,CACN,GAAI,UACJ,MAAOA,CACT,EACA,IAAK,CAAC,IAAI,CACZ,CACF,CAEO,SAASW,EACdX,EACAI,EAAeC,EAC0B,CACzC,OAAAF,EAAuBH,EAAWI,CAAK,EAChCM,EAAsBV,EAAWI,CAAK,CAC/C,CAkBO,SAASQ,EACdC,EACAT,EAC6C,CAC7C,GAAIH,EAASY,CAAM,EACjB,QAAWC,KAAO,OAAO,KAAKD,CAAM,EAC9Bd,EAAsBgB,EAAIF,EAAQC,CAAG,CAAC,EACxCX,EAAuBY,EAAIF,EAAQC,CAAG,EAAGV,CAAK,EAE9CY,EAAcD,EAAIF,EAAQC,CAAG,EAAGV,CAAK,CAI7C,CCrIA,OAAS,aAAAa,MAAiB,2BAiBnB,SAASC,EAA4BC,EAA2D,CACrG,IAAMC,EAAQC,EAAcF,CAAK,EAC7BG,EAAUH,EAAO,QAAQ,GAAKI,EAASJ,EAAM,MAAM,GACrDK,EAA6BL,EAAM,OAAQC,CAAK,CAEpD,CAQO,SAASK,EACdN,EACmC,CACnC,IAAMC,EAAQC,EAAcF,CAAK,EAC3BO,EAAa,CACjB,GAAGP,EACH,OAAQQ,EAAUR,EAAM,OAASS,GACxBC,EAAsBD,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","isTableShorthandInput","shorthand","isObject","value","validateTableShorthand","scope","AbiTypeScope","isFixedArrayAbiType","hasOwnKey","isSchemaInput","isStaticAbiType","resolveTableShorthand","defineTableShorthand","validateTablesWithShorthands","tables","key","get","validateTable","mapObject","validateStoreWithShorthands","store","scope","extendedScope","hasOwnKey","isObject","validateTablesWithShorthands","resolveStoreWithShorthands","fullConfig","mapObject","table","isTableShorthandInput","resolveTableShorthand","validateStore","resolveStore","defineStoreWithShorthands"]}
|
package/dist/config/v2.d.ts
CHANGED
|
@@ -1,65 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
3
|
-
import { ErrorMessage, conform } from '@arktype/util';
|
|
4
|
-
import { FixedArrayAbiType } from '@latticexyz/schema-type/internal';
|
|
5
|
-
import { e as extendedScope, v as validateStore, r as resolveStore } from '../store-a6c17d89.js';
|
|
6
|
-
export { d as defineStore, g as extractInternalType, i as isUserTypes, c as resolveCodegen, f as resolveEnums, b as resolveTables, s as scopeWithEnums, h as scopeWithUserTypes, a as validateTables, j as validateUserTypes } from '../store-a6c17d89.js';
|
|
1
|
+
export { A as AbiTypeScope, C as CODEGEN_DEFAULTS, E as CONFIG_DEFAULTS, q as SchemaInput, S as Scope, a as ScopeOptions, s as ScopedSchemaInput, u as StoreInput, y as StoreWithShorthandsInput, z as TABLE_CODEGEN_DEFAULTS, D as TABLE_DEFAULTS, B as TABLE_DEPLOY_DEFAULTS, T as TableInput, w as TableShorthandInput, t as TablesInput, x as TablesWithShorthandsInput, V as ValidKeys, l as ValidateTableOptions, d as defineSchema, p as defineTable, e as extendScope, g as get, b as getStaticAbiTypeKeys, h as hasOwnKey, i as isObject, f as isSchemaInput, j as isValidPrimaryKey, m as mergeIfUndefined, c as resolveSchema, o as resolveTable, r as resolveTableCodegen, k as validateKeys, v as validateSchema, n as validateTable } from '../table-eb26e26f.js';
|
|
2
|
+
export { N as NoStaticKeyFieldError, o as defineStore, d as defineStoreWithShorthands, b as defineTableShorthand, l as extendedScope, t as extractInternalType, i as isTableShorthandInput, u as isUserTypes, p as resolveCodegen, q as resolveEnums, n as resolveStore, h as resolveStoreWithShorthands, r as resolveTableShorthand, c as resolveTableWithShorthand, k as resolveTables, e as resolveTablesWithShorthands, s as scopeWithEnums, w as scopeWithUserTypes, m as validateStore, g as validateStoreWithShorthands, a as validateTableShorthand, v as validateTableWithShorthand, j as validateTables, f as validateTablesWithShorthands, x as validateUserTypes } from '../storeWithShorthands-224ad75e.js';
|
|
7
3
|
import { T as Table, S as Store } from '../output-bc27f6a8.js';
|
|
8
4
|
export { C as Codegen, E as Enums, a as TableCodegen, b as TableDeploy, U as UserTypes } from '../output-bc27f6a8.js';
|
|
5
|
+
import { conform } from '@arktype/util';
|
|
9
6
|
import { getKeySchema, getValueSchema } from '@latticexyz/protocol-parser/internal';
|
|
10
7
|
import { Schema } from '@latticexyz/config';
|
|
11
8
|
export { AbiType, Schema } from '@latticexyz/config';
|
|
12
9
|
import 'viem';
|
|
13
|
-
|
|
14
|
-
type NoStaticKeyFieldError = ErrorMessage<"Invalid schema. Expected an `id` field with a static ABI type or an explicit `key` option.">;
|
|
15
|
-
declare function isTableShorthandInput(shorthand: unknown): shorthand is TableShorthandInput;
|
|
16
|
-
type validateTableWithShorthand<table, scope extends Scope = AbiTypeScope, options extends ValidateTableOptions = {
|
|
17
|
-
inStoreContext: boolean;
|
|
18
|
-
}> = table extends TableShorthandInput ? validateTableShorthand<table, scope> : validateTable<table, scope, options>;
|
|
19
|
-
type validateTableShorthand<input, scope extends Scope = AbiTypeScope> = input extends SchemaInput ? "id" extends getStaticAbiTypeKeys<input, scope> ? conform<input, ScopedSchemaInput<scope>> : NoStaticKeyFieldError : input extends FixedArrayAbiType ? input : input extends keyof scope["types"] ? input : input extends string ? keyof scope["types"] : ScopedSchemaInput<scope>;
|
|
20
|
-
declare function validateTableShorthand<scope extends Scope = AbiTypeScope>(shorthand: unknown, scope?: scope): asserts shorthand is TableShorthandInput;
|
|
21
|
-
type resolveTableShorthand<shorthand, scope extends Scope = AbiTypeScope> = shorthand extends FixedArrayAbiType ? {
|
|
22
|
-
schema: {
|
|
23
|
-
id: "bytes32";
|
|
24
|
-
value: shorthand;
|
|
25
|
-
};
|
|
26
|
-
key: ["id"];
|
|
27
|
-
} : shorthand extends keyof scope["types"] ? {
|
|
28
|
-
schema: {
|
|
29
|
-
id: "bytes32";
|
|
30
|
-
value: shorthand;
|
|
31
|
-
};
|
|
32
|
-
key: ["id"];
|
|
33
|
-
} : shorthand extends SchemaInput ? "id" extends getStaticAbiTypeKeys<shorthand, scope> ? {
|
|
34
|
-
schema: shorthand;
|
|
35
|
-
key: ["id"];
|
|
36
|
-
} : never : never;
|
|
37
|
-
declare function resolveTableShorthand<shorthand extends TableShorthandInput, scope extends Scope = AbiTypeScope>(shorthand: shorthand, scope?: scope): resolveTableShorthand<shorthand, scope>;
|
|
38
|
-
declare function defineTableShorthand<shorthand, scope extends Scope = AbiTypeScope>(shorthand: validateTableShorthand<shorthand, scope>, scope?: scope): resolveTableShorthand<shorthand, scope>;
|
|
39
|
-
/**
|
|
40
|
-
* If a shorthand is provided, it is resolved to a full config.
|
|
41
|
-
* If a full config is provided, it is passed through.
|
|
42
|
-
*/
|
|
43
|
-
type resolveTableWithShorthand<table, scope extends Scope = AbiTypeScope> = table extends TableShorthandInput ? resolveTableShorthand<table, scope> : table;
|
|
44
|
-
type resolveTablesWithShorthands<input, scope extends AbiTypeScope = AbiTypeScope> = {
|
|
45
|
-
[key in keyof input]: resolveTableWithShorthand<input[key], scope>;
|
|
46
|
-
};
|
|
47
|
-
type validateTablesWithShorthands<tables, scope extends Scope = AbiTypeScope> = {
|
|
48
|
-
[key in keyof tables]: validateTableWithShorthand<tables[key], scope, {
|
|
49
|
-
inStoreContext: true;
|
|
50
|
-
}>;
|
|
51
|
-
};
|
|
52
|
-
declare function validateTablesWithShorthands<scope extends Scope = AbiTypeScope>(tables: unknown, scope: scope): asserts tables is TablesWithShorthandsInput;
|
|
53
|
-
|
|
54
|
-
type validateStoreWithShorthands<store> = {
|
|
55
|
-
[key in keyof store]: key extends "tables" ? validateTablesWithShorthands<store[key], extendedScope<store>> : validateStore<store>[key];
|
|
56
|
-
};
|
|
57
|
-
declare function validateStoreWithShorthands(store: unknown): asserts store is StoreWithShorthandsInput;
|
|
58
|
-
type resolveStoreWithShorthands<store> = resolveStore<{
|
|
59
|
-
[key in keyof store]: key extends "tables" ? resolveTablesWithShorthands<store[key], extendedScope<store>> : store[key];
|
|
60
|
-
}>;
|
|
61
|
-
declare function resolveStoreWithShorthands<const store extends StoreWithShorthandsInput>(store: store): resolveStoreWithShorthands<store>;
|
|
62
|
-
declare function defineStoreWithShorthands<const store>(store: validateStoreWithShorthands<store>): resolveStoreWithShorthands<store>;
|
|
10
|
+
import '@latticexyz/schema-type/internal';
|
|
63
11
|
|
|
64
12
|
type schemaToV1<schema extends Schema> = {
|
|
65
13
|
[key in keyof schema]: schema[key]["internalType"];
|
|
@@ -96,4 +44,4 @@ type storeToV1<store> = store extends Store ? {
|
|
|
96
44
|
} : never;
|
|
97
45
|
declare function storeToV1<store>(store: conform<store, Store>): storeToV1<store>;
|
|
98
46
|
|
|
99
|
-
export {
|
|
47
|
+
export { Store, Table, storeToV1, tableToV1 };
|
package/dist/config/v2.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{a as H,b as I,c as J,d as K,e as L,f as M,g as N,h as O}from"../chunk-TVGPNLGB.js";import{A,B,C,D,E,F,G,a as o,b as r,c as e,d as f,e as m,f as p,g as t,h as x,i as a,j as b,k as c,l as d,m as g,n as h,o as i,p as j,q as k,r as l,s as n,t as q,u as s,v as u,w as v,x as w,y,z}from"../chunk-QX7XTPMU.js";import{a as P}from"../chunk-2ERRNVDO.js";export{c as AbiTypeScope,m as CODEGEN_DEFAULTS,a as CONFIG_DEFAULTS,b as Scope,p as TABLE_CODEGEN_DEFAULTS,x as TABLE_DEFAULTS,t as TABLE_DEPLOY_DEFAULTS,i as defineSchema,G as defineStore,O as defineStoreWithShorthands,s as defineTable,K as defineTableShorthand,d as extendScope,D as extendedScope,w as extractInternalType,o as get,r as hasOwnKey,e as isObject,j as isSchemaInput,H as isTableShorthandInput,y as isUserTypes,k as isValidPrimaryKey,f as mergeIfUndefined,C as resolveCodegen,h as resolveSchema,F as resolveStore,N as resolveStoreWithShorthands,q as resolveTable,n as resolveTableCodegen,J as resolveTableShorthand,v as resolveTables,B as scopeWithEnums,z as scopeWithUserTypes,P as storeToV1,g as validateSchema,E as validateStore,M as validateStoreWithShorthands,l as validateTable,I as validateTableShorthand,u as validateTables,L as validateTablesWithShorthands,A as validateUserTypes};
|
|
2
2
|
//# sourceMappingURL=v2.js.map
|
package/dist/config/v2.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { d as defineStore } from './
|
|
1
|
+
export { d as defineStore } from './storeWithShorthands-224ad75e.js';
|
|
2
2
|
export { S as Store } from './output-bc27f6a8.js';
|
|
3
3
|
import '@arktype/util';
|
|
4
|
-
import './table-
|
|
4
|
+
import './table-eb26e26f.js';
|
|
5
5
|
import 'viem';
|
|
6
6
|
import '@latticexyz/schema-type/internal';
|
|
7
7
|
import '@latticexyz/config';
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{h as n}from"./chunk-TVGPNLGB.js";import"./chunk-QX7XTPMU.js";var i="event HelloStore(bytes32 indexed storeVersion)",t="event Store_SetRecord(bytes32 indexed tableId, bytes32[] keyTuple, bytes staticData, bytes32 encodedLengths, bytes dynamicData)",o="event Store_SpliceStaticData(bytes32 indexed tableId, bytes32[] keyTuple, uint48 start, bytes data)",r="event Store_SpliceDynamicData(bytes32 indexed tableId, bytes32[] keyTuple, uint8 dynamicFieldIndex, uint48 start, uint40 deleteCount, bytes32 encodedLengths, bytes data)",s="event Store_DeleteRecord(bytes32 indexed tableId, bytes32[] keyTuple)",e=[t,o,r,s];import{parseAbi as a}from"abitype";var d=a(e);export{n as defineStore,i as helloStoreEvent,s as storeDeleteRecordEvent,e as storeEvents,d as storeEventsAbi,t as storeSetRecordEvent,r as storeSpliceDynamicDataEvent,o as storeSpliceStaticDataEvent};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../ts/storeEvents.ts","../ts/storeEventsAbi.ts"],"sourcesContent":["export const helloStoreEvent = \"event HelloStore(bytes32 indexed storeVersion)\";\n\nexport const storeSetRecordEvent =\n \"event Store_SetRecord(bytes32 indexed tableId, bytes32[] keyTuple, bytes staticData, bytes32 encodedLengths, bytes dynamicData)\";\n\nexport const storeSpliceStaticDataEvent =\n \"event Store_SpliceStaticData(bytes32 indexed tableId, bytes32[] keyTuple, uint48 start, bytes data)\";\n\nexport const storeSpliceDynamicDataEvent =\n \"event Store_SpliceDynamicData(bytes32 indexed tableId, bytes32[] keyTuple, uint8 dynamicFieldIndex, uint48 start, uint40 deleteCount, bytes32 encodedLengths, bytes data)\";\n\nexport const storeDeleteRecordEvent = \"event Store_DeleteRecord(bytes32 indexed tableId, bytes32[] keyTuple)\";\n\n// Store protocol events\nexport const storeEvents = [\n storeSetRecordEvent,\n storeSpliceStaticDataEvent,\n storeSpliceDynamicDataEvent,\n storeDeleteRecordEvent,\n] as const;\n","import { parseAbi, AbiEvent } from \"abitype\";\nimport { storeEvents } from \"./storeEvents\";\n\nexport const storeEventsAbi = parseAbi(storeEvents) satisfies readonly AbiEvent[];\n\nexport type StoreEventsAbi = typeof storeEventsAbi;\nexport type StoreEventsAbiItem = (typeof storeEventsAbi)[number];\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../ts/storeEvents.ts","../ts/storeEventsAbi.ts"],"sourcesContent":["export const helloStoreEvent = \"event HelloStore(bytes32 indexed storeVersion)\";\n\nexport const storeSetRecordEvent =\n \"event Store_SetRecord(bytes32 indexed tableId, bytes32[] keyTuple, bytes staticData, bytes32 encodedLengths, bytes dynamicData)\";\n\nexport const storeSpliceStaticDataEvent =\n \"event Store_SpliceStaticData(bytes32 indexed tableId, bytes32[] keyTuple, uint48 start, bytes data)\";\n\nexport const storeSpliceDynamicDataEvent =\n \"event Store_SpliceDynamicData(bytes32 indexed tableId, bytes32[] keyTuple, uint8 dynamicFieldIndex, uint48 start, uint40 deleteCount, bytes32 encodedLengths, bytes data)\";\n\nexport const storeDeleteRecordEvent = \"event Store_DeleteRecord(bytes32 indexed tableId, bytes32[] keyTuple)\";\n\n// Store protocol events\nexport const storeEvents = [\n storeSetRecordEvent,\n storeSpliceStaticDataEvent,\n storeSpliceDynamicDataEvent,\n storeDeleteRecordEvent,\n] as const;\n","import { parseAbi, AbiEvent } from \"abitype\";\nimport { storeEvents } from \"./storeEvents\";\n\nexport const storeEventsAbi = parseAbi(storeEvents) satisfies readonly AbiEvent[];\n\nexport type StoreEventsAbi = typeof storeEventsAbi;\nexport type StoreEventsAbiItem = (typeof storeEventsAbi)[number];\n"],"mappings":"oEAAO,IAAMA,EAAkB,iDAElBC,EACX,kIAEWC,EACX,sGAEWC,EACX,4KAEWC,EAAyB,wEAGzBC,EAAc,CACzBJ,EACAC,EACAC,EACAC,CACF,ECnBA,OAAS,YAAAE,MAA0B,UAG5B,IAAMC,EAAiBC,EAASC,CAAW","names":["helloStoreEvent","storeSetRecordEvent","storeSpliceStaticDataEvent","storeSpliceDynamicDataEvent","storeDeleteRecordEvent","storeEvents","parseAbi","storeEventsAbi","parseAbi","storeEvents"]}
|
package/dist/mud.config.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as resolveTableCodegen } from './table-
|
|
1
|
+
import { r as resolveTableCodegen } from './table-eb26e26f.js';
|
|
2
2
|
import '@arktype/util';
|
|
3
3
|
import 'viem';
|
|
4
4
|
import './output-bc27f6a8.js';
|
|
@@ -29,7 +29,7 @@ declare const _default: {
|
|
|
29
29
|
readonly tableId: "ResourceId";
|
|
30
30
|
readonly hooks: "bytes21[]";
|
|
31
31
|
};
|
|
32
|
-
key: ["tableId"];
|
|
32
|
+
key: readonly ["tableId"];
|
|
33
33
|
name: "StoreHooks";
|
|
34
34
|
}>;
|
|
35
35
|
readonly deploy: {
|
|
@@ -78,7 +78,7 @@ declare const _default: {
|
|
|
78
78
|
readonly abiEncodedKeyNames: "bytes";
|
|
79
79
|
readonly abiEncodedFieldNames: "bytes";
|
|
80
80
|
};
|
|
81
|
-
key: ["tableId"];
|
|
81
|
+
key: readonly ["tableId"];
|
|
82
82
|
name: "Tables";
|
|
83
83
|
}>;
|
|
84
84
|
readonly deploy: {
|
|
@@ -107,7 +107,7 @@ declare const _default: {
|
|
|
107
107
|
readonly resourceId: "ResourceId";
|
|
108
108
|
readonly exists: "bool";
|
|
109
109
|
};
|
|
110
|
-
key: ["resourceId"];
|
|
110
|
+
key: readonly ["resourceId"];
|
|
111
111
|
name: "ResourceIds";
|
|
112
112
|
}>;
|
|
113
113
|
readonly deploy: {
|
|
@@ -139,7 +139,7 @@ declare const _default: {
|
|
|
139
139
|
readonly resourceId: "ResourceId";
|
|
140
140
|
readonly hooks: "bytes21[]";
|
|
141
141
|
};
|
|
142
|
-
key: ["resourceId"];
|
|
142
|
+
key: readonly ["resourceId"];
|
|
143
143
|
name: "Hooks";
|
|
144
144
|
}>;
|
|
145
145
|
readonly deploy: {
|
package/dist/mud.config.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{G as e}from"./chunk-
|
|
1
|
+
import{G as e}from"./chunk-QX7XTPMU.js";var o=e({codegen:{storeImportPath:"../../"},namespace:"store",userTypes:{ResourceId:{filePath:"./src/ResourceId.sol",type:"bytes32"},FieldLayout:{filePath:"./src/FieldLayout.sol",type:"bytes32"},Schema:{filePath:"./src/Schema.sol",type:"bytes32"}},tables:{StoreHooks:{schema:{tableId:"ResourceId",hooks:"bytes21[]"},key:["tableId"]},Tables:{schema:{tableId:"ResourceId",fieldLayout:"FieldLayout",keySchema:"Schema",valueSchema:"Schema",abiEncodedKeyNames:"bytes",abiEncodedFieldNames:"bytes"},key:["tableId"]},ResourceIds:{schema:{resourceId:"ResourceId",exists:"bool"},key:["resourceId"]},Hooks:{schema:{resourceId:"ResourceId",hooks:"bytes21[]"},key:["resourceId"],codegen:{tableIdArgument:!0}}}});export{o as default};
|
|
2
2
|
//# sourceMappingURL=mud.config.js.map
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { ErrorMessage, evaluate, narrow, conform } from '@arktype/util';
|
|
2
|
+
import { S as Scope, A as AbiTypeScope, n as validateTable, t as TablesInput, o as resolveTable, m as mergeIfUndefined, e as extendScope, C as CODEGEN_DEFAULTS, g as get, u as StoreInput, E as CONFIG_DEFAULTS, w as TableShorthandInput, l as ValidateTableOptions, q as SchemaInput, b as getStaticAbiTypeKeys, s as ScopedSchemaInput, x as TablesWithShorthandsInput, y as StoreWithShorthandsInput } from './table-eb26e26f.js';
|
|
3
|
+
import { U as UserTypes, E as Enums } from './output-bc27f6a8.js';
|
|
4
|
+
import { FixedArrayAbiType } from '@latticexyz/schema-type/internal';
|
|
5
|
+
|
|
6
|
+
type validateTables<tables, scope extends Scope = AbiTypeScope> = {
|
|
7
|
+
[key in keyof tables]: tables[key] extends object ? validateTable<tables[key], scope, {
|
|
8
|
+
inStoreContext: true;
|
|
9
|
+
}> : ErrorMessage<`Expected full table config.`>;
|
|
10
|
+
};
|
|
11
|
+
declare function validateTables<scope extends Scope = AbiTypeScope>(input: unknown, scope: scope): asserts input is TablesInput;
|
|
12
|
+
type resolveTables<tables, scope extends Scope = AbiTypeScope> = evaluate<{
|
|
13
|
+
readonly [key in keyof tables]: resolveTable<mergeIfUndefined<tables[key], {
|
|
14
|
+
name: key;
|
|
15
|
+
}>, scope>;
|
|
16
|
+
}>;
|
|
17
|
+
declare function resolveTables<tables extends TablesInput, scope extends Scope = AbiTypeScope>(tables: tables, scope?: scope): resolveTables<tables, scope>;
|
|
18
|
+
|
|
19
|
+
type extractInternalType<userTypes extends UserTypes> = {
|
|
20
|
+
[key in keyof userTypes]: userTypes[key]["type"];
|
|
21
|
+
};
|
|
22
|
+
declare function extractInternalType<userTypes extends UserTypes>(userTypes: userTypes): extractInternalType<userTypes>;
|
|
23
|
+
declare function isUserTypes(userTypes: unknown): userTypes is UserTypes;
|
|
24
|
+
type scopeWithUserTypes<userTypes, scope extends AbiTypeScope = AbiTypeScope> = UserTypes extends userTypes ? scope : userTypes extends UserTypes ? extendScope<scope, extractInternalType<userTypes>> : scope;
|
|
25
|
+
declare function scopeWithUserTypes<userTypes, scope extends AbiTypeScope = AbiTypeScope>(userTypes: userTypes, scope?: scope): scopeWithUserTypes<userTypes, scope>;
|
|
26
|
+
declare function validateUserTypes(userTypes: unknown): asserts userTypes is UserTypes;
|
|
27
|
+
|
|
28
|
+
type scopeWithEnums<enums, scope extends AbiTypeScope = AbiTypeScope> = Enums extends enums ? scope : enums extends Enums ? extendScope<scope, {
|
|
29
|
+
[key in keyof enums]: "uint8";
|
|
30
|
+
}> : scope;
|
|
31
|
+
declare function scopeWithEnums<enums, scope extends AbiTypeScope = AbiTypeScope>(enums: enums, scope?: scope): scopeWithEnums<enums, scope>;
|
|
32
|
+
type resolveEnums<enums> = {
|
|
33
|
+
readonly [key in keyof enums]: Readonly<enums[key]>;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
type resolveCodegen<codegen> = codegen extends {} ? mergeIfUndefined<codegen, typeof CODEGEN_DEFAULTS> : typeof CODEGEN_DEFAULTS;
|
|
37
|
+
declare function resolveCodegen<codegen>(codegen: codegen): resolveCodegen<codegen>;
|
|
38
|
+
|
|
39
|
+
type extendedScope<input> = scopeWithEnums<get<input, "enums">, scopeWithUserTypes<get<input, "userTypes">>>;
|
|
40
|
+
declare function extendedScope<input>(input: input): extendedScope<input>;
|
|
41
|
+
type validateStore<store> = {
|
|
42
|
+
[key in keyof store]: key extends "tables" ? validateTables<store[key], extendedScope<store>> : key extends "userTypes" ? UserTypes : key extends "enums" ? narrow<store[key]> : key extends keyof StoreInput ? StoreInput[key] : never;
|
|
43
|
+
};
|
|
44
|
+
declare function validateStore(store: unknown): asserts store is StoreInput;
|
|
45
|
+
type keyPrefix<store> = "namespace" extends keyof store ? store["namespace"] extends "" ? "" : `${store["namespace"] & string}__` : "";
|
|
46
|
+
type resolveStore<store> = evaluate<{
|
|
47
|
+
readonly tables: "tables" extends keyof store ? resolveTables<{
|
|
48
|
+
[tableKey in keyof store["tables"] & string as `${keyPrefix<store>}${tableKey}`]: mergeIfUndefined<store["tables"][tableKey], {
|
|
49
|
+
namespace: get<store, "namespace">;
|
|
50
|
+
name: tableKey;
|
|
51
|
+
}>;
|
|
52
|
+
}, extendedScope<store>> : {};
|
|
53
|
+
readonly userTypes: "userTypes" extends keyof store ? store["userTypes"] : {};
|
|
54
|
+
readonly enums: "enums" extends keyof store ? resolveEnums<store["enums"]> : {};
|
|
55
|
+
readonly namespace: "namespace" extends keyof store ? store["namespace"] : (typeof CONFIG_DEFAULTS)["namespace"];
|
|
56
|
+
readonly codegen: "codegen" extends keyof store ? resolveCodegen<store["codegen"]> : resolveCodegen<{}>;
|
|
57
|
+
}>;
|
|
58
|
+
declare function resolveStore<const store extends StoreInput>(store: store): resolveStore<store>;
|
|
59
|
+
declare function defineStore<const store>(store: validateStore<store>): resolveStore<store>;
|
|
60
|
+
|
|
61
|
+
type NoStaticKeyFieldError = ErrorMessage<"Invalid schema. Expected an `id` field with a static ABI type or an explicit `key` option.">;
|
|
62
|
+
declare function isTableShorthandInput(shorthand: unknown): shorthand is TableShorthandInput;
|
|
63
|
+
type validateTableWithShorthand<table, scope extends Scope = AbiTypeScope, options extends ValidateTableOptions = {
|
|
64
|
+
inStoreContext: boolean;
|
|
65
|
+
}> = table extends TableShorthandInput ? validateTableShorthand<table, scope> : validateTable<table, scope, options>;
|
|
66
|
+
type validateTableShorthand<input, scope extends Scope = AbiTypeScope> = input extends SchemaInput ? "id" extends getStaticAbiTypeKeys<input, scope> ? conform<input, ScopedSchemaInput<scope>> : NoStaticKeyFieldError : input extends FixedArrayAbiType ? input : input extends keyof scope["types"] ? input : input extends string ? keyof scope["types"] : ScopedSchemaInput<scope>;
|
|
67
|
+
declare function validateTableShorthand<scope extends Scope = AbiTypeScope>(shorthand: unknown, scope?: scope): asserts shorthand is TableShorthandInput;
|
|
68
|
+
type resolveTableShorthand<shorthand, scope extends Scope = AbiTypeScope> = shorthand extends FixedArrayAbiType ? {
|
|
69
|
+
schema: {
|
|
70
|
+
id: "bytes32";
|
|
71
|
+
value: shorthand;
|
|
72
|
+
};
|
|
73
|
+
key: ["id"];
|
|
74
|
+
} : shorthand extends keyof scope["types"] ? {
|
|
75
|
+
schema: {
|
|
76
|
+
id: "bytes32";
|
|
77
|
+
value: shorthand;
|
|
78
|
+
};
|
|
79
|
+
key: ["id"];
|
|
80
|
+
} : shorthand extends SchemaInput ? "id" extends getStaticAbiTypeKeys<shorthand, scope> ? {
|
|
81
|
+
schema: shorthand;
|
|
82
|
+
key: ["id"];
|
|
83
|
+
} : never : never;
|
|
84
|
+
declare function resolveTableShorthand<shorthand extends TableShorthandInput, scope extends Scope = AbiTypeScope>(shorthand: shorthand, scope?: scope): resolveTableShorthand<shorthand, scope>;
|
|
85
|
+
declare function defineTableShorthand<shorthand, scope extends Scope = AbiTypeScope>(shorthand: validateTableShorthand<shorthand, scope>, scope?: scope): resolveTableShorthand<shorthand, scope>;
|
|
86
|
+
/**
|
|
87
|
+
* If a shorthand is provided, it is resolved to a full config.
|
|
88
|
+
* If a full config is provided, it is passed through.
|
|
89
|
+
*/
|
|
90
|
+
type resolveTableWithShorthand<table, scope extends Scope = AbiTypeScope> = table extends TableShorthandInput ? resolveTableShorthand<table, scope> : table;
|
|
91
|
+
type resolveTablesWithShorthands<input, scope extends AbiTypeScope = AbiTypeScope> = {
|
|
92
|
+
[key in keyof input]: resolveTableWithShorthand<input[key], scope>;
|
|
93
|
+
};
|
|
94
|
+
type validateTablesWithShorthands<tables, scope extends Scope = AbiTypeScope> = {
|
|
95
|
+
[key in keyof tables]: validateTableWithShorthand<tables[key], scope, {
|
|
96
|
+
inStoreContext: true;
|
|
97
|
+
}>;
|
|
98
|
+
};
|
|
99
|
+
declare function validateTablesWithShorthands<scope extends Scope = AbiTypeScope>(tables: unknown, scope: scope): asserts tables is TablesWithShorthandsInput;
|
|
100
|
+
|
|
101
|
+
type validateStoreWithShorthands<store> = {
|
|
102
|
+
[key in keyof store]: key extends "tables" ? validateTablesWithShorthands<store[key], extendedScope<store>> : validateStore<store>[key];
|
|
103
|
+
};
|
|
104
|
+
declare function validateStoreWithShorthands(store: unknown): asserts store is StoreWithShorthandsInput;
|
|
105
|
+
type resolveStoreWithShorthands<store> = resolveStore<{
|
|
106
|
+
[key in keyof store]: key extends "tables" ? resolveTablesWithShorthands<store[key], extendedScope<store>> : store[key];
|
|
107
|
+
}>;
|
|
108
|
+
declare function resolveStoreWithShorthands<const store extends StoreWithShorthandsInput>(store: store): resolveStoreWithShorthands<store>;
|
|
109
|
+
declare function defineStoreWithShorthands<const store>(store: validateStoreWithShorthands<store>): resolveStoreWithShorthands<store>;
|
|
110
|
+
|
|
111
|
+
export { NoStaticKeyFieldError as N, validateTableShorthand as a, defineTableShorthand as b, resolveTableWithShorthand as c, defineStoreWithShorthands as d, resolveTablesWithShorthands as e, validateTablesWithShorthands as f, validateStoreWithShorthands as g, resolveStoreWithShorthands as h, isTableShorthandInput as i, validateTables as j, resolveTables as k, extendedScope as l, validateStore as m, resolveStore as n, defineStore as o, resolveCodegen as p, resolveEnums as q, resolveTableShorthand as r, scopeWithEnums as s, extractInternalType as t, isUserTypes as u, validateTableWithShorthand as v, scopeWithUserTypes as w, validateUserTypes as x };
|
|
@@ -44,7 +44,7 @@ type StoreInput = {
|
|
|
44
44
|
/******** Variations with shorthands ********/
|
|
45
45
|
type TableShorthandInput = SchemaInput | string;
|
|
46
46
|
type TablesWithShorthandsInput = {
|
|
47
|
-
[key: string]: TableInput | TableShorthandInput;
|
|
47
|
+
readonly [key: string]: TableInput | TableShorthandInput;
|
|
48
48
|
};
|
|
49
49
|
type StoreWithShorthandsInput = Omit<StoreInput, "tables"> & {
|
|
50
50
|
tables: TablesWithShorthandsInput;
|
|
@@ -110,9 +110,9 @@ type ValidKeys<schema extends SchemaInput, scope extends Scope> = readonly [
|
|
|
110
110
|
...getStaticAbiTypeKeys<schema, scope>[]
|
|
111
111
|
];
|
|
112
112
|
declare function isValidPrimaryKey<schema extends SchemaInput, scope extends Scope>(key: unknown, schema: schema, scope?: scope): key is ValidKeys<schema, scope>;
|
|
113
|
-
type validateKeys<validKeys extends PropertyKey, keys> = keys extends string[] ? {
|
|
114
|
-
[i in keyof keys]: keys[i] extends validKeys ? keys[i] : validKeys;
|
|
115
|
-
} : string[];
|
|
113
|
+
type validateKeys<validKeys extends PropertyKey, keys> = keys extends readonly string[] ? {
|
|
114
|
+
readonly [i in keyof keys]: keys[i] extends validKeys ? keys[i] : validKeys;
|
|
115
|
+
} : readonly string[];
|
|
116
116
|
type ValidateTableOptions = {
|
|
117
117
|
inStoreContext: boolean;
|
|
118
118
|
};
|
|
@@ -139,4 +139,4 @@ type resolveTable<input, scope extends Scope = Scope> = input extends TableInput
|
|
|
139
139
|
declare function resolveTable<input extends TableInput, scope extends Scope = AbiTypeScope>(input: input, scope?: scope): resolveTable<input, scope>;
|
|
140
140
|
declare function defineTable<input, scope extends Scope = AbiTypeScope>(input: validateTable<input, scope>, scope?: scope): resolveTable<input, scope>;
|
|
141
141
|
|
|
142
|
-
export { AbiTypeScope as A, TABLE_DEPLOY_DEFAULTS as B, CODEGEN_DEFAULTS as C, TABLE_DEFAULTS as D, CONFIG_DEFAULTS as E, Scope as S,
|
|
142
|
+
export { AbiTypeScope as A, TABLE_DEPLOY_DEFAULTS as B, CODEGEN_DEFAULTS as C, TABLE_DEFAULTS as D, CONFIG_DEFAULTS as E, Scope as S, TableInput as T, ValidKeys as V, ScopeOptions as a, getStaticAbiTypeKeys as b, resolveSchema as c, defineSchema as d, extendScope as e, isSchemaInput as f, get as g, hasOwnKey as h, isObject as i, isValidPrimaryKey as j, validateKeys as k, ValidateTableOptions as l, mergeIfUndefined as m, validateTable as n, resolveTable as o, defineTable as p, SchemaInput as q, resolveTableCodegen as r, ScopedSchemaInput as s, TablesInput as t, StoreInput as u, validateSchema as v, TableShorthandInput as w, TablesWithShorthandsInput as x, StoreWithShorthandsInput as y, TABLE_CODEGEN_DEFAULTS as z };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@latticexyz/store",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Store",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -42,15 +42,15 @@
|
|
|
42
42
|
}
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@arktype/util": "0.0.
|
|
45
|
+
"@arktype/util": "0.0.27",
|
|
46
46
|
"abitype": "1.0.0",
|
|
47
47
|
"arktype": "1.0.29-alpha",
|
|
48
48
|
"viem": "2.7.12",
|
|
49
49
|
"zod": "^3.21.4",
|
|
50
|
-
"@latticexyz/common": "2.0.
|
|
51
|
-
"@latticexyz/config": "2.0.
|
|
52
|
-
"@latticexyz/
|
|
53
|
-
"@latticexyz/
|
|
50
|
+
"@latticexyz/common": "2.0.1",
|
|
51
|
+
"@latticexyz/config": "2.0.1",
|
|
52
|
+
"@latticexyz/schema-type": "2.0.1",
|
|
53
|
+
"@latticexyz/protocol-parser": "2.0.1"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@types/ejs": "^3.1.1",
|
|
@@ -63,8 +63,8 @@
|
|
|
63
63
|
"tsup": "^6.7.0",
|
|
64
64
|
"tsx": "^3.12.6",
|
|
65
65
|
"vitest": "0.34.6",
|
|
66
|
-
"@latticexyz/abi-ts": "2.0.
|
|
67
|
-
"@latticexyz/gas-report": "2.0.
|
|
66
|
+
"@latticexyz/abi-ts": "2.0.1",
|
|
67
|
+
"@latticexyz/gas-report": "2.0.1"
|
|
68
68
|
},
|
|
69
69
|
"scripts": {
|
|
70
70
|
"build": "pnpm run build:tightcoder && pnpm run build:mud && pnpm run build:abi && pnpm run build:abi-ts && pnpm run build:js",
|
package/ts/config/v2/input.ts
CHANGED
|
@@ -38,7 +38,7 @@ export type StoreInput = {
|
|
|
38
38
|
export type TableShorthandInput = SchemaInput | string;
|
|
39
39
|
|
|
40
40
|
export type TablesWithShorthandsInput = {
|
|
41
|
-
[key: string]: TableInput | TableShorthandInput;
|
|
41
|
+
readonly [key: string]: TableInput | TableShorthandInput;
|
|
42
42
|
};
|
|
43
43
|
|
|
44
44
|
export type StoreWithShorthandsInput = Omit<StoreInput, "tables"> & { tables: TablesWithShorthandsInput };
|
|
@@ -495,4 +495,25 @@ describe("defineStore", () => {
|
|
|
495
495
|
}),
|
|
496
496
|
).throwsAndHasTypeError("Overrides of `name` and `namespace` are not allowed for tables in a store config");
|
|
497
497
|
});
|
|
498
|
+
|
|
499
|
+
it("should allow const enum as input", () => {
|
|
500
|
+
const enums = {
|
|
501
|
+
Example: ["First", "Second"],
|
|
502
|
+
} as const;
|
|
503
|
+
|
|
504
|
+
attest(defineStore({ enums }).enums).equals(enums);
|
|
505
|
+
});
|
|
506
|
+
|
|
507
|
+
it("should allow a const config as input", () => {
|
|
508
|
+
const config = {
|
|
509
|
+
tables: {
|
|
510
|
+
Example: {
|
|
511
|
+
schema: { id: "address", name: "string", age: "uint256" },
|
|
512
|
+
key: ["age"],
|
|
513
|
+
},
|
|
514
|
+
},
|
|
515
|
+
} as const;
|
|
516
|
+
|
|
517
|
+
defineStore(config);
|
|
518
|
+
});
|
|
498
519
|
});
|
|
@@ -9,7 +9,7 @@ import { getKeySchema, getValueSchema } from "@latticexyz/protocol-parser/intern
|
|
|
9
9
|
describe("validateKeys", () => {
|
|
10
10
|
it("should return a tuple of valid keys", () => {
|
|
11
11
|
attest<
|
|
12
|
-
["static"],
|
|
12
|
+
readonly ["static"],
|
|
13
13
|
validateKeys<getStaticAbiTypeKeys<{ static: "uint256"; dynamic: "string" }, AbiTypeScope>, ["static"]>
|
|
14
14
|
>();
|
|
15
15
|
});
|
|
@@ -18,7 +18,7 @@ describe("validateKeys", () => {
|
|
|
18
18
|
const scope = extendScope(AbiTypeScope, { static: "address", dynamic: "string" });
|
|
19
19
|
|
|
20
20
|
attest<
|
|
21
|
-
["static", "customStatic"],
|
|
21
|
+
readonly ["static", "customStatic"],
|
|
22
22
|
validateKeys<
|
|
23
23
|
getStaticAbiTypeKeys<
|
|
24
24
|
{ static: "uint256"; dynamic: "string"; customStatic: "static"; customDynamic: "dynamic" },
|
|
@@ -33,7 +33,7 @@ describe("validateKeys", () => {
|
|
|
33
33
|
const scope = extendScope(AbiTypeScope, { static: "address", dynamic: "string" });
|
|
34
34
|
|
|
35
35
|
attest<
|
|
36
|
-
["static", "customStatic"],
|
|
36
|
+
readonly ["static", "customStatic"],
|
|
37
37
|
validateKeys<
|
|
38
38
|
getStaticAbiTypeKeys<
|
|
39
39
|
{ static: "uint256"; dynamic: "string"; customStatic: "static"; customDynamic: "dynamic" },
|
|
@@ -218,13 +218,13 @@ describe("resolveTable", () => {
|
|
|
218
218
|
attest(() =>
|
|
219
219
|
defineTable({
|
|
220
220
|
schema: { id: "address" },
|
|
221
|
-
// @ts-expect-error Type 'string' is not assignable to type 'string[]'
|
|
221
|
+
// @ts-expect-error Type 'string' is not assignable to type 'readonly string[]'
|
|
222
222
|
key: "",
|
|
223
223
|
name: "",
|
|
224
224
|
}),
|
|
225
225
|
)
|
|
226
226
|
.throws('Invalid key. Expected `("id")[]`, received ``')
|
|
227
|
-
.type.errors("Type 'string' is not assignable to type 'string[]'");
|
|
227
|
+
.type.errors("Type 'string' is not assignable to type 'readonly string[]'");
|
|
228
228
|
});
|
|
229
229
|
|
|
230
230
|
it("should throw if a string is provided as schema", () => {
|
package/ts/config/v2/table.ts
CHANGED
|
@@ -37,11 +37,11 @@ export function isValidPrimaryKey<schema extends SchemaInput, scope extends Scop
|
|
|
37
37
|
);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
export type validateKeys<validKeys extends PropertyKey, keys> = keys extends string[]
|
|
40
|
+
export type validateKeys<validKeys extends PropertyKey, keys> = keys extends readonly string[]
|
|
41
41
|
? {
|
|
42
|
-
[i in keyof keys]: keys[i] extends validKeys ? keys[i] : validKeys;
|
|
42
|
+
readonly [i in keyof keys]: keys[i] extends validKeys ? keys[i] : validKeys;
|
|
43
43
|
}
|
|
44
|
-
: string[];
|
|
44
|
+
: readonly string[];
|
|
45
45
|
|
|
46
46
|
export type ValidateTableOptions = { inStoreContext: boolean };
|
|
47
47
|
|
package/ts/exports/index.ts
CHANGED
|
@@ -16,5 +16,5 @@ export {
|
|
|
16
16
|
export { storeEventsAbi } from "../storeEventsAbi";
|
|
17
17
|
export type { StoreEventsAbi, StoreEventsAbiItem } from "../storeEventsAbi";
|
|
18
18
|
|
|
19
|
-
export { defineStore } from "../config/v2/
|
|
19
|
+
export { defineStoreWithShorthands as defineStore } from "../config/v2/storeWithShorthands";
|
|
20
20
|
export type { Store } from "../config/v2/output";
|
|
@@ -1 +0,0 @@
|
|
|
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/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 get<\n input,\n key\n >;\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 mergeIfUndefined<base, merged>;\n}\n","export const CODEGEN_DEFAULTS = {\n storeImportPath: \"@latticexyz/store/src/\",\n userTypesFilename: \"common.sol\",\n outputDirectory: \"codegen\",\n indexFilename: \"index.sol\",\n} as const;\n\nexport const TABLE_CODEGEN_DEFAULTS = {\n outputDirectory: \"tables\",\n tableIdArgument: false,\n storeArgument: false,\n} as const;\n\nexport const TABLE_DEPLOY_DEFAULTS = {\n disabled: false,\n} as const;\n\nexport const TABLE_DEFAULTS = {\n namespace: \"\",\n type: \"table\",\n} as const;\n\nexport const CONFIG_DEFAULTS = {\n namespace: \"\",\n} as const;\n","import { Dict, evaluate } 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\"][schema[key] & keyof scope[\"types\"]] extends StaticAbiType ? key : never;\n }[keyof schema];\n\nexport type extendScope<scope extends ScopeOptions, additionalTypes extends Dict<string, AbiType>> = evaluate<\n ScopeOptions<evaluate<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, evaluate } 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 unknown as scope,\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> = evaluate<{\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)\n ? fixedArrayToArray(internalType)\n : scope.types[internalType as keyof typeof scope.types],\n internalType,\n },\n ]),\n ) as unknown as resolveSchema<schema, scope>;\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 resolveSchema<schema, scope>;\n}\n\nexport function isSchemaInput<scope extends Scope = AbiTypeScope>(\n input: unknown,\n scope: scope = AbiTypeScope as unknown as scope,\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, 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 unknown as ValidKeys<schema, scope>;\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 string[]\n ? {\n [i in keyof keys]: keys[i] extends validKeys ? keys[i] : validKeys;\n }\n : string[];\n\nexport type ValidateTableOptions = { inStoreContext: boolean };\n\nexport type validateTable<\n input,\n scope extends Scope = AbiTypeScope,\n options extends ValidateTableOptions = { inStoreContext: false },\n> = {\n [key in\n | keyof input\n | Exclude<\n requiredKeyOf<TableInput>,\n options[\"inStoreContext\"] extends true ? \"name\" | \"namespace\" : \"\"\n >]: 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 \"name\" | \"namespace\"\n ? options[\"inStoreContext\"] extends true\n ? ErrorMessage<\"Overrides of `name` 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 ((options.inStoreContext && hasOwnKey(input, \"name\")) || hasOwnKey(input, \"namespace\")) {\n throw new Error(\"Overrides of `name` and `namespace` are not allowed for tables in a store config.\");\n }\n}\n\nexport type resolveTableCodegen<input extends TableInput> = {\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 typeof TABLE_CODEGEN_DEFAULTS\n ? (typeof 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 typeof TABLE_CODEGEN_DEFAULTS\n ? (typeof 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 resolveTableCodegen<input>;\n}\n\nexport type resolveTable<input, scope extends Scope = Scope> = input extends TableInput\n ? {\n readonly tableId: Hex;\n readonly name: input[\"name\"];\n readonly namespace: undefined extends input[\"namespace\"] ? typeof TABLE_DEFAULTS.namespace : input[\"namespace\"];\n readonly type: undefined extends input[\"type\"] ? typeof TABLE_DEFAULTS.type : input[\"type\"];\n readonly key: Readonly<input[\"key\"]>;\n readonly schema: resolveSchema<input[\"schema\"], scope>;\n readonly codegen: resolveTableCodegen<input>;\n readonly deploy: mergeIfUndefined<\n undefined extends input[\"deploy\"] ? {} : input[\"deploy\"],\n typeof 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 name = input.name;\n const type = input.type ?? TABLE_DEFAULTS.type;\n const namespace = input.namespace ?? TABLE_DEFAULTS.namespace;\n const tableId = input.tableId ?? resourceToHex({ type, namespace, name });\n\n return {\n tableId,\n name,\n namespace,\n type,\n key: input.key,\n schema: resolveSchema(input.schema, scope),\n codegen: resolveTableCodegen(input),\n deploy: mergeIfUndefined(input.deploy ?? {}, TABLE_DEPLOY_DEFAULTS),\n } as unknown as resolveTable<input, scope>;\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 resolveTable<input, scope>;\n}\n","import { ErrorMessage, evaluate } 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 [key in keyof tables]: tables[key] extends object\n ? validateTable<tables[key], 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> = evaluate<{\n readonly [key in keyof tables]: resolveTable<mergeIfUndefined<tables[key], { name: key }>, scope>;\n}>;\n\nexport function resolveTables<tables extends TablesInput, scope extends Scope = AbiTypeScope>(\n tables: tables,\n scope: scope = AbiTypeScope as unknown as 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(([key, table]) => {\n return [key, resolveTable(mergeIfUndefined(table, { name: key }), scope)];\n }),\n ) as unknown as resolveTables<tables, scope>;\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 scopeWithUserTypes<\n userTypes,\n scope\n >;\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 { Enums } from \"./output\";\nimport { AbiTypeScope, extendScope } from \"./scope\";\n\nfunction isEnums(enums: unknown): enums is Enums {\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> = Enums extends enums\n ? scope\n : enums extends Enums\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 scopeWithEnums<enums, scope>;\n }\n return scope as scopeWithEnums<enums, scope>;\n}\n\nexport type resolveEnums<enums> = { readonly [key in keyof enums]: Readonly<enums[key]> };\n","import { CODEGEN_DEFAULTS } from \"./defaults\";\nimport { isObject, mergeIfUndefined } from \"./generics\";\n\nexport type resolveCodegen<codegen> = codegen extends {}\n ? mergeIfUndefined<codegen, typeof CODEGEN_DEFAULTS>\n : typeof 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 { evaluate, 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 { resolveEnums, scopeWithEnums } from \"./enums\";\nimport { resolveCodegen } from \"./codegen\";\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<store> = {\n [key in keyof store]: key extends \"tables\"\n ? validateTables<store[key], extendedScope<store>>\n : key extends \"userTypes\"\n ? UserTypes\n : key extends \"enums\"\n ? narrow<store[key]>\n : key extends keyof StoreInput\n ? StoreInput[key]\n : never;\n};\n\nexport function validateStore(store: unknown): asserts store is StoreInput {\n const scope = extendedScope(store);\n if (hasOwnKey(store, \"tables\")) {\n validateTables(store.tables, scope);\n }\n\n if (hasOwnKey(store, \"userTypes\")) {\n validateUserTypes(store.userTypes);\n }\n}\n\ntype keyPrefix<store> = \"namespace\" extends keyof store\n ? store[\"namespace\"] extends \"\"\n ? \"\"\n : `${store[\"namespace\"] & string}__`\n : \"\";\n\nexport type resolveStore<store> = evaluate<{\n readonly tables: \"tables\" extends keyof store\n ? resolveTables<\n {\n [tableKey in keyof store[\"tables\"] & string as `${keyPrefix<store>}${tableKey}`]: mergeIfUndefined<\n store[\"tables\"][tableKey],\n { namespace: get<store, \"namespace\">; name: tableKey }\n >;\n },\n extendedScope<store>\n >\n : {};\n readonly userTypes: \"userTypes\" extends keyof store ? store[\"userTypes\"] : {};\n readonly enums: \"enums\" extends keyof store ? resolveEnums<store[\"enums\"]> : {};\n readonly namespace: \"namespace\" extends keyof store ? store[\"namespace\"] : (typeof CONFIG_DEFAULTS)[\"namespace\"];\n readonly codegen: \"codegen\" extends keyof store ? resolveCodegen<store[\"codegen\"]> : resolveCodegen<{}>;\n}>;\n\nexport function resolveStore<const store extends StoreInput>(store: store): resolveStore<store> {\n return {\n tables: resolveTables(\n Object.fromEntries(\n Object.entries(store.tables ?? {}).map(([tableKey, table]) => {\n const key = store.namespace ? `${store.namespace}__${tableKey}` : tableKey;\n return [key, mergeIfUndefined(table, { namespace: store.namespace, name: tableKey })];\n }),\n ),\n extendedScope(store),\n ),\n userTypes: store.userTypes ?? {},\n enums: store.enums ?? {},\n namespace: store.namespace ?? CONFIG_DEFAULTS[\"namespace\"],\n codegen: resolveCodegen(store.codegen),\n } as unknown as resolveStore<store>;\n}\n\nexport function defineStore<const store>(store: validateStore<store>): resolveStore<store> {\n validateStore(store);\n return resolveStore(store) as unknown as resolveStore<store>;\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AUF,EAAO,WAAW,GAC9BI,EAAkBJ,EAAM,SAAS,CAErC,CA0BO,SAASK,EAA6CL,EAAmC,CAC9F,MAAO,CACL,OAAQM,EACN,OAAO,YACL,OAAO,QAAQN,EAAM,QAAU,CAAC,CAAC,EAAE,IAAI,CAAC,CAACO,EAAUC,CAAK,IAE/C,CADKR,EAAM,UAAY,GAAGA,EAAM,cAAcO,IAAaA,EACrDE,EAAiBD,EAAO,CAAE,UAAWR,EAAM,UAAW,KAAMO,CAAS,CAAC,CAAC,CACrF,CACH,EACAb,EAAcM,CAAK,CACrB,EACA,UAAWA,EAAM,WAAa,CAAC,EAC/B,MAAOA,EAAM,OAAS,CAAC,EACvB,UAAWA,EAAM,WAAaU,EAAgB,UAC9C,QAASC,EAAeX,EAAM,OAAO,CACvC,CACF,CAEO,SAASY,GAAyBZ,EAAkD,CACzF,OAAAD,EAAcC,CAAK,EACZK,EAAaL,CAAK,CAC3B","names":["get","input","key","hasOwnKey","object","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","name","type","TABLE_DEFAULTS","namespace","resolveSchema","mergeIfUndefined","TABLE_DEPLOY_DEFAULTS","defineTable","validateTables","input","scope","isObject","table","validateTable","resolveTables","tables","AbiTypeScope","key","resolveTable","mergeIfUndefined","mapObject","isSchemaAbiType","extractInternalType","userTypes","mapObject","userType","isUserTypes","isObject","isSchemaAbiType","scopeWithUserTypes","scope","AbiTypeScope","extendScope","validateUserTypes","type","hasOwnKey","isEnums","enums","item","element","scopeWithEnums","scope","AbiTypeScope","enumScope","key","extendScope","resolveCodegen","codegen","isObject","mergeIfUndefined","CODEGEN_DEFAULTS","extendedScope","input","scopeWithEnums","get","scopeWithUserTypes","validateStore","store","scope","hasOwnKey","validateTables","validateUserTypes","resolveStore","resolveTables","tableKey","table","mergeIfUndefined","CONFIG_DEFAULTS","resolveCodegen","defineStore"]}
|
package/dist/store-a6c17d89.d.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { ErrorMessage, evaluate, narrow } from '@arktype/util';
|
|
2
|
-
import { S as Scope, A as AbiTypeScope, v as validateTable, x as TablesInput, t as resolveTable, m as mergeIfUndefined, j as extendScope, C as CODEGEN_DEFAULTS, e as get, y as StoreInput, E as CONFIG_DEFAULTS } from './table-ae48252c.js';
|
|
3
|
-
import { U as UserTypes, E as Enums } from './output-bc27f6a8.js';
|
|
4
|
-
|
|
5
|
-
type validateTables<tables, scope extends Scope = AbiTypeScope> = {
|
|
6
|
-
[key in keyof tables]: tables[key] extends object ? validateTable<tables[key], scope, {
|
|
7
|
-
inStoreContext: true;
|
|
8
|
-
}> : ErrorMessage<`Expected full table config.`>;
|
|
9
|
-
};
|
|
10
|
-
declare function validateTables<scope extends Scope = AbiTypeScope>(input: unknown, scope: scope): asserts input is TablesInput;
|
|
11
|
-
type resolveTables<tables, scope extends Scope = AbiTypeScope> = evaluate<{
|
|
12
|
-
readonly [key in keyof tables]: resolveTable<mergeIfUndefined<tables[key], {
|
|
13
|
-
name: key;
|
|
14
|
-
}>, scope>;
|
|
15
|
-
}>;
|
|
16
|
-
declare function resolveTables<tables extends TablesInput, scope extends Scope = AbiTypeScope>(tables: tables, scope?: scope): resolveTables<tables, scope>;
|
|
17
|
-
|
|
18
|
-
type extractInternalType<userTypes extends UserTypes> = {
|
|
19
|
-
[key in keyof userTypes]: userTypes[key]["type"];
|
|
20
|
-
};
|
|
21
|
-
declare function extractInternalType<userTypes extends UserTypes>(userTypes: userTypes): extractInternalType<userTypes>;
|
|
22
|
-
declare function isUserTypes(userTypes: unknown): userTypes is UserTypes;
|
|
23
|
-
type scopeWithUserTypes<userTypes, scope extends AbiTypeScope = AbiTypeScope> = UserTypes extends userTypes ? scope : userTypes extends UserTypes ? extendScope<scope, extractInternalType<userTypes>> : scope;
|
|
24
|
-
declare function scopeWithUserTypes<userTypes, scope extends AbiTypeScope = AbiTypeScope>(userTypes: userTypes, scope?: scope): scopeWithUserTypes<userTypes, scope>;
|
|
25
|
-
declare function validateUserTypes(userTypes: unknown): asserts userTypes is UserTypes;
|
|
26
|
-
|
|
27
|
-
type scopeWithEnums<enums, scope extends AbiTypeScope = AbiTypeScope> = Enums extends enums ? scope : enums extends Enums ? extendScope<scope, {
|
|
28
|
-
[key in keyof enums]: "uint8";
|
|
29
|
-
}> : scope;
|
|
30
|
-
declare function scopeWithEnums<enums, scope extends AbiTypeScope = AbiTypeScope>(enums: enums, scope?: scope): scopeWithEnums<enums, scope>;
|
|
31
|
-
type resolveEnums<enums> = {
|
|
32
|
-
readonly [key in keyof enums]: Readonly<enums[key]>;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
type resolveCodegen<codegen> = codegen extends {} ? mergeIfUndefined<codegen, typeof CODEGEN_DEFAULTS> : typeof CODEGEN_DEFAULTS;
|
|
36
|
-
declare function resolveCodegen<codegen>(codegen: codegen): resolveCodegen<codegen>;
|
|
37
|
-
|
|
38
|
-
type extendedScope<input> = scopeWithEnums<get<input, "enums">, scopeWithUserTypes<get<input, "userTypes">>>;
|
|
39
|
-
declare function extendedScope<input>(input: input): extendedScope<input>;
|
|
40
|
-
type validateStore<store> = {
|
|
41
|
-
[key in keyof store]: key extends "tables" ? validateTables<store[key], extendedScope<store>> : key extends "userTypes" ? UserTypes : key extends "enums" ? narrow<store[key]> : key extends keyof StoreInput ? StoreInput[key] : never;
|
|
42
|
-
};
|
|
43
|
-
declare function validateStore(store: unknown): asserts store is StoreInput;
|
|
44
|
-
type keyPrefix<store> = "namespace" extends keyof store ? store["namespace"] extends "" ? "" : `${store["namespace"] & string}__` : "";
|
|
45
|
-
type resolveStore<store> = evaluate<{
|
|
46
|
-
readonly tables: "tables" extends keyof store ? resolveTables<{
|
|
47
|
-
[tableKey in keyof store["tables"] & string as `${keyPrefix<store>}${tableKey}`]: mergeIfUndefined<store["tables"][tableKey], {
|
|
48
|
-
namespace: get<store, "namespace">;
|
|
49
|
-
name: tableKey;
|
|
50
|
-
}>;
|
|
51
|
-
}, extendedScope<store>> : {};
|
|
52
|
-
readonly userTypes: "userTypes" extends keyof store ? store["userTypes"] : {};
|
|
53
|
-
readonly enums: "enums" extends keyof store ? resolveEnums<store["enums"]> : {};
|
|
54
|
-
readonly namespace: "namespace" extends keyof store ? store["namespace"] : (typeof CONFIG_DEFAULTS)["namespace"];
|
|
55
|
-
readonly codegen: "codegen" extends keyof store ? resolveCodegen<store["codegen"]> : resolveCodegen<{}>;
|
|
56
|
-
}>;
|
|
57
|
-
declare function resolveStore<const store extends StoreInput>(store: store): resolveStore<store>;
|
|
58
|
-
declare function defineStore<const store>(store: validateStore<store>): resolveStore<store>;
|
|
59
|
-
|
|
60
|
-
export { validateTables as a, resolveTables as b, resolveCodegen as c, defineStore as d, extendedScope as e, resolveEnums as f, extractInternalType as g, scopeWithUserTypes as h, isUserTypes as i, validateUserTypes as j, resolveStore as r, scopeWithEnums as s, validateStore as v };
|