@latticexyz/world 2.0.0-main-dc4a48e2 → 2.0.0-main-849ec533

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.
@@ -1,2 +1,2 @@
1
- import{resolveStoreTablesConfig as o,extendedScope as y,get as e}from"@latticexyz/store/config/v2";function C(s){let a=e(s,"namespaces")??{},p=y(s),r=Object.fromEntries(Object.entries(a).map(([n,t])=>{let l=e(t,"tables")??{};return Object.entries(l).map(([c,u])=>[`${n}__${c}`,u])}).flat()),i=Object.fromEntries(Object.entries(a).map(([n,t])=>[n,{tables:o(e(t,"tables")??{},p)}]));return{tables:o({...e(s,"tables")??{},...r},p),namespaces:i,userTypes:e(s,"userTypes")??{},enums:e(s,"enums")??{},namespace:e(s,"namespace")??""}}export{C as resolveWorldConfig};
1
+ import{resourceToHex as y}from"@latticexyz/common";import{mapObject as m}from"@latticexyz/common/utils";import{resolveStoreTablesConfig as f,extendedScope as b,get as t,isTableShorthandInput as g,resolveTableShorthand as v,resolveTableFullConfig as T,validateStoreTablesConfig as u,validateTableFull as k,isObject as x,hasOwnKey as S}from"@latticexyz/store/config/v2";function C(e,s){if(x(e)){for(let a of Object.values(e)){if(!S(a,"tables"))throw new Error(`Expected namespace config, received ${JSON.stringify(a)}`);u(a.tables,s)}return}throw new Error(`Expected namespaces config, received ${JSON.stringify(e)}`)}function K(e){let s=b(e),a=t(e,"namespaces")??{};C(a,s);let l=t(e,"tables")??{};u(l,s);let c=m(a,(o,p)=>({tables:m(o.tables,(n,r)=>{let i=g(n,s)?v(n,s):n;return k(i,s),T({...i,tableId:i.tableId??y({type:"table",namespace:p,name:r})},s)})})),d=Object.fromEntries(Object.entries(c).map(([o,p])=>Object.entries(p.tables).map(([n,r])=>[`${o}__${n}`,r])).flat());return{tables:{...f(l,s),...d},namespaces:c,userTypes:t(e,"userTypes")??{},enums:t(e,"enums")??{},namespace:t(e,"namespace")??""}}export{K as resolveWorldConfig};
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../ts/config/v2/world.ts"],"sourcesContent":["import { evaluate, narrow } from \"@arktype/util\";\nimport {\n UserTypes,\n Enums,\n StoreConfigInput,\n resolveStoreConfig,\n validateStoreTablesConfig,\n resolveStoreTablesConfig,\n extendedScope,\n StoreTablesConfigInput,\n resolveTableConfig,\n AbiTypeScope,\n get,\n} from \"@latticexyz/store/config/v2\";\n\nexport type WorldConfigInput<userTypes extends UserTypes = UserTypes, enums extends Enums = Enums> = evaluate<\n StoreConfigInput<userTypes, enums> & {\n namespaces?: NamespacesInput;\n }\n>;\n\nexport type NamespacesInput = { [key: string]: NamespaceInput };\n\nexport type NamespaceInput = Pick<StoreConfigInput, \"tables\">;\n\nexport type validateNamespaces<input, scope extends AbiTypeScope = AbiTypeScope> = {\n [namespace in keyof input]: {\n [key in keyof input[namespace]]: key extends \"tables\"\n ? validateStoreTablesConfig<input[namespace][key], scope>\n : input[namespace][key];\n };\n};\n\nexport type validateWorldConfig<input> = {\n readonly [key in keyof input]: key extends \"tables\"\n ? validateStoreTablesConfig<input[key], extendedScope<input>>\n : key extends \"userTypes\"\n ? UserTypes\n : key extends \"enums\"\n ? narrow<input[key]>\n : key extends \"namespaces\"\n ? validateNamespaces<input[key], extendedScope<input>>\n : input[key];\n};\n\nexport type namespacedTableKeys<input> = \"namespaces\" extends keyof input\n ? \"tables\" extends keyof input[\"namespaces\"][keyof input[\"namespaces\"]]\n ? `${keyof input[\"namespaces\"] & string}__${keyof input[\"namespaces\"][keyof input[\"namespaces\"]][\"tables\"] &\n string}`\n : never\n : never;\n\nexport type resolveWorldConfig<input> = evaluate<\n resolveStoreConfig<input> & {\n readonly tables: \"namespaces\" extends keyof input\n ? {\n readonly [key in namespacedTableKeys<input>]: key extends `${infer namespace}__${infer table}`\n ? resolveTableConfig<\n get<get<get<get<input, \"namespaces\">, namespace>, \"tables\">, table>,\n extendedScope<input>\n >\n : never;\n }\n : {};\n readonly namespaces: \"namespaces\" extends keyof input\n ? {\n [key in keyof input[\"namespaces\"]]: {\n readonly tables: resolveStoreTablesConfig<get<input[\"namespaces\"][key], \"tables\">, extendedScope<input>>;\n };\n }\n : {};\n }\n>;\n\nexport function resolveWorldConfig<const input>(input: validateWorldConfig<input>): resolveWorldConfig<input> {\n const namespaces = get(input, \"namespaces\") ?? {};\n const scope = extendedScope(input);\n\n const namespacedTables = Object.fromEntries(\n Object.entries(namespaces)\n .map(([namespaceKey, namespace]) => {\n const tables = get(namespace, \"tables\") ?? {};\n return Object.entries(tables).map(([tableKey, table]) => [`${namespaceKey}__${tableKey}`, table]);\n })\n .flat(),\n ) as StoreTablesConfigInput<typeof scope>;\n\n const resolvedNamespaces = Object.fromEntries(\n Object.entries(namespaces).map(([namespaceKey, namespace]) => [\n namespaceKey,\n { tables: resolveStoreTablesConfig(get(namespace, \"tables\") ?? {}, scope) },\n ]),\n );\n\n return {\n tables: resolveStoreTablesConfig({ ...(get(input, \"tables\") ?? {}), ...namespacedTables }, scope),\n namespaces: resolvedNamespaces,\n userTypes: get(input, \"userTypes\") ?? {},\n enums: get(input, \"enums\") ?? {},\n namespace: get(input, \"namespace\") ?? \"\",\n } as resolveWorldConfig<input>;\n}\n"],"mappings":"AACA,OAME,4BAAAA,EACA,iBAAAC,EAIA,OAAAC,MACK,8BA6DA,SAASC,EAAgCC,EAA8D,CAC5G,IAAMC,EAAaH,EAAIE,EAAO,YAAY,GAAK,CAAC,EAC1CE,EAAQL,EAAcG,CAAK,EAE3BG,EAAmB,OAAO,YAC9B,OAAO,QAAQF,CAAU,EACtB,IAAI,CAAC,CAACG,EAAcC,CAAS,IAAM,CAClC,IAAMC,EAASR,EAAIO,EAAW,QAAQ,GAAK,CAAC,EAC5C,OAAO,OAAO,QAAQC,CAAM,EAAE,IAAI,CAAC,CAACC,EAAUC,CAAK,IAAM,CAAC,GAAGJ,MAAiBG,IAAYC,CAAK,CAAC,CAClG,CAAC,EACA,KAAK,CACV,EAEMC,EAAqB,OAAO,YAChC,OAAO,QAAQR,CAAU,EAAE,IAAI,CAAC,CAACG,EAAcC,CAAS,IAAM,CAC5DD,EACA,CAAE,OAAQR,EAAyBE,EAAIO,EAAW,QAAQ,GAAK,CAAC,EAAGH,CAAK,CAAE,CAC5E,CAAC,CACH,EAEA,MAAO,CACL,OAAQN,EAAyB,CAAE,GAAIE,EAAIE,EAAO,QAAQ,GAAK,CAAC,EAAI,GAAGG,CAAiB,EAAGD,CAAK,EAChG,WAAYO,EACZ,UAAWX,EAAIE,EAAO,WAAW,GAAK,CAAC,EACvC,MAAOF,EAAIE,EAAO,OAAO,GAAK,CAAC,EAC/B,UAAWF,EAAIE,EAAO,WAAW,GAAK,EACxC,CACF","names":["resolveStoreTablesConfig","extendedScope","get","resolveWorldConfig","input","namespaces","scope","namespacedTables","namespaceKey","namespace","tables","tableKey","table","resolvedNamespaces"]}
1
+ {"version":3,"sources":["../../../../ts/config/v2/world.ts"],"sourcesContent":["import { evaluate, narrow } from \"@arktype/util\";\nimport { resourceToHex } from \"@latticexyz/common\";\nimport { mapObject } from \"@latticexyz/common/utils\";\nimport {\n UserTypes,\n Enums,\n StoreConfigInput,\n resolveStoreConfig,\n resolveStoreTablesConfig,\n extendedScope,\n resolveTableConfig,\n AbiTypeScope,\n get,\n isTableShorthandInput,\n resolveTableShorthand,\n validateTableShorthand,\n resolveTableFullConfig,\n validateStoreTablesConfig,\n validateTableFull,\n isObject,\n hasOwnKey,\n Table,\n} from \"@latticexyz/store/config/v2\";\nimport { Config } from \"./output\";\n\nexport type WorldConfigInput<userTypes extends UserTypes = UserTypes, enums extends Enums = Enums> = evaluate<\n StoreConfigInput<userTypes, enums> & {\n namespaces?: NamespacesInput;\n }\n>;\n\nexport type NamespacesInput = { [key: string]: NamespaceInput };\n\nexport type NamespaceInput = Pick<StoreConfigInput, \"tables\">;\n\nexport type validateNamespaces<input, scope extends AbiTypeScope = AbiTypeScope> = {\n [namespace in keyof input]: {\n [key in keyof input[namespace]]: key extends \"tables\"\n ? validateStoreTablesConfig<input[namespace][key], scope>\n : input[namespace][key];\n };\n};\n\nfunction validateNamespaces<scope extends AbiTypeScope = AbiTypeScope>(\n input: unknown,\n scope: scope,\n): asserts input is NamespacesInput {\n if (isObject(input)) {\n for (const namespace of Object.values(input)) {\n if (!hasOwnKey(namespace, \"tables\")) {\n throw new Error(`Expected namespace config, received ${JSON.stringify(namespace)}`);\n }\n validateStoreTablesConfig(namespace.tables, scope);\n }\n return;\n }\n throw new Error(`Expected namespaces config, received ${JSON.stringify(input)}`);\n}\n\nexport type validateWorldConfig<input> = {\n readonly [key in keyof input]: key extends \"tables\"\n ? validateStoreTablesConfig<input[key], extendedScope<input>>\n : key extends \"userTypes\"\n ? UserTypes\n : key extends \"enums\"\n ? narrow<input[key]>\n : key extends \"namespaces\"\n ? validateNamespaces<input[key], extendedScope<input>>\n : input[key];\n};\n\nexport type namespacedTableKeys<input> = \"namespaces\" extends keyof input\n ? \"tables\" extends keyof input[\"namespaces\"][keyof input[\"namespaces\"]]\n ? `${keyof input[\"namespaces\"] & string}__${keyof input[\"namespaces\"][keyof input[\"namespaces\"]][\"tables\"] &\n string}`\n : never\n : never;\n\nexport type resolveWorldConfig<input> = evaluate<\n resolveStoreConfig<input> & {\n readonly tables: \"namespaces\" extends keyof input\n ? {\n readonly [key in namespacedTableKeys<input>]: key extends `${infer namespace}__${infer table}`\n ? resolveTableConfig<\n get<get<get<get<input, \"namespaces\">, namespace>, \"tables\">, table>,\n extendedScope<input>\n >\n : never;\n }\n : {};\n readonly namespaces: \"namespaces\" extends keyof input\n ? {\n [key in keyof input[\"namespaces\"]]: {\n readonly tables: resolveStoreTablesConfig<get<input[\"namespaces\"][key], \"tables\">, extendedScope<input>>;\n };\n }\n : {};\n }\n>;\n\nexport function resolveWorldConfig<const input>(input: validateWorldConfig<input>): resolveWorldConfig<input> {\n const scope = extendedScope(input);\n\n const namespaces = get(input, \"namespaces\") ?? {};\n validateNamespaces(namespaces, scope);\n\n const rootTables = get(input, \"tables\") ?? {};\n validateStoreTablesConfig(rootTables, scope);\n\n const resolvedNamespaces = mapObject(namespaces, (namespace, namespaceKey) => ({\n tables: mapObject(namespace.tables, (table, tableKey) => {\n const fullInput = isTableShorthandInput(table, scope)\n ? resolveTableShorthand(table as validateTableShorthand<typeof table, typeof scope>, scope)\n : table;\n validateTableFull(fullInput, scope);\n return resolveTableFullConfig(\n {\n ...fullInput,\n tableId:\n fullInput.tableId ??\n resourceToHex({ type: \"table\", namespace: namespaceKey as string, name: tableKey as string }),\n },\n scope,\n ) as Table;\n }) as Config[\"namespaces\"][string][\"tables\"],\n })) as Config[\"namespaces\"];\n\n const resolvedNamespacedTables = Object.fromEntries(\n Object.entries(resolvedNamespaces)\n .map(([namespaceKey, namespace]) =>\n Object.entries(namespace.tables).map(([tableKey, table]) => [`${namespaceKey}__${tableKey}`, table]),\n )\n .flat(),\n ) as Config[\"tables\"];\n\n const resolvedRootTables = resolveStoreTablesConfig(rootTables, scope);\n\n return {\n tables: { ...resolvedRootTables, ...resolvedNamespacedTables },\n namespaces: resolvedNamespaces,\n userTypes: get(input, \"userTypes\") ?? {},\n enums: get(input, \"enums\") ?? {},\n namespace: get(input, \"namespace\") ?? \"\",\n } as resolveWorldConfig<input>;\n}\n"],"mappings":"AACA,OAAS,iBAAAA,MAAqB,qBAC9B,OAAS,aAAAC,MAAiB,2BAC1B,OAKE,4BAAAC,EACA,iBAAAC,EAGA,OAAAC,EACA,yBAAAC,EACA,yBAAAC,EAEA,0BAAAC,EACA,6BAAAC,EACA,qBAAAC,EACA,YAAAC,EACA,aAAAC,MAEK,8BAqBP,SAASC,EACPC,EACAC,EACkC,CAClC,GAAIJ,EAASG,CAAK,EAAG,CACnB,QAAWE,KAAa,OAAO,OAAOF,CAAK,EAAG,CAC5C,GAAI,CAACF,EAAUI,EAAW,QAAQ,EAChC,MAAM,IAAI,MAAM,uCAAuC,KAAK,UAAUA,CAAS,GAAG,EAEpFP,EAA0BO,EAAU,OAAQD,CAAK,EAEnD,OAEF,MAAM,IAAI,MAAM,wCAAwC,KAAK,UAAUD,CAAK,GAAG,CACjF,CA2CO,SAASG,EAAgCH,EAA8D,CAC5G,IAAMC,EAAQX,EAAcU,CAAK,EAE3BI,EAAab,EAAIS,EAAO,YAAY,GAAK,CAAC,EAChDD,EAAmBK,EAAYH,CAAK,EAEpC,IAAMI,EAAad,EAAIS,EAAO,QAAQ,GAAK,CAAC,EAC5CL,EAA0BU,EAAYJ,CAAK,EAE3C,IAAMK,EAAqBlB,EAAUgB,EAAY,CAACF,EAAWK,KAAkB,CAC7E,OAAQnB,EAAUc,EAAU,OAAQ,CAACM,EAAOC,IAAa,CACvD,IAAMC,EAAYlB,EAAsBgB,EAAOP,CAAK,EAChDR,EAAsBe,EAA6DP,CAAK,EACxFO,EACJ,OAAAZ,EAAkBc,EAAWT,CAAK,EAC3BP,EACL,CACE,GAAGgB,EACH,QACEA,EAAU,SACVvB,EAAc,CAAE,KAAM,QAAS,UAAWoB,EAAwB,KAAME,CAAmB,CAAC,CAChG,EACAR,CACF,CACF,CAAC,CACH,EAAE,EAEIU,EAA2B,OAAO,YACtC,OAAO,QAAQL,CAAkB,EAC9B,IAAI,CAAC,CAACC,EAAcL,CAAS,IAC5B,OAAO,QAAQA,EAAU,MAAM,EAAE,IAAI,CAAC,CAACO,EAAUD,CAAK,IAAM,CAAC,GAAGD,MAAiBE,IAAYD,CAAK,CAAC,CACrG,EACC,KAAK,CACV,EAIA,MAAO,CACL,OAAQ,CAAE,GAHenB,EAAyBgB,EAAYJ,CAAK,EAGlC,GAAGU,CAAyB,EAC7D,WAAYL,EACZ,UAAWf,EAAIS,EAAO,WAAW,GAAK,CAAC,EACvC,MAAOT,EAAIS,EAAO,OAAO,GAAK,CAAC,EAC/B,UAAWT,EAAIS,EAAO,WAAW,GAAK,EACxC,CACF","names":["resourceToHex","mapObject","resolveStoreTablesConfig","extendedScope","get","isTableShorthandInput","resolveTableShorthand","resolveTableFullConfig","validateStoreTablesConfig","validateTableFull","isObject","hasOwnKey","validateNamespaces","input","scope","namespace","resolveWorldConfig","namespaces","rootTables","resolvedNamespaces","namespaceKey","table","tableKey","fullInput","resolvedNamespacedTables"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@latticexyz/world",
3
- "version": "2.0.0-main-dc4a48e2",
3
+ "version": "2.0.0-main-849ec533",
4
4
  "description": "World framework",
5
5
  "repository": {
6
6
  "type": "git",
@@ -39,10 +39,10 @@
39
39
  "arktype": "1.0.29-alpha",
40
40
  "viem": "2.7.12",
41
41
  "zod": "^3.21.4",
42
- "@latticexyz/common": "2.0.0-main-dc4a48e2",
43
- "@latticexyz/config": "2.0.0-main-dc4a48e2",
44
- "@latticexyz/schema-type": "2.0.0-main-dc4a48e2",
45
- "@latticexyz/store": "2.0.0-main-dc4a48e2"
42
+ "@latticexyz/config": "2.0.0-main-849ec533",
43
+ "@latticexyz/schema-type": "2.0.0-main-849ec533",
44
+ "@latticexyz/store": "2.0.0-main-849ec533",
45
+ "@latticexyz/common": "2.0.0-main-849ec533"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@types/ejs": "^3.1.1",
@@ -57,8 +57,8 @@
57
57
  "tsup": "^6.7.0",
58
58
  "tsx": "^3.12.6",
59
59
  "vitest": "0.34.6",
60
- "@latticexyz/abi-ts": "2.0.0-main-dc4a48e2",
61
- "@latticexyz/gas-report": "2.0.0-main-dc4a48e2"
60
+ "@latticexyz/abi-ts": "2.0.0-main-849ec533",
61
+ "@latticexyz/gas-report": "2.0.0-main-849ec533"
62
62
  },
63
63
  "gitHead": "914a1e0ae4a573d685841ca2ea921435057deb8f",
64
64
  "scripts": {
@@ -2,7 +2,7 @@ import { describe, it } from "vitest";
2
2
  import { resolveWorldConfig } from "./world";
3
3
  import { Config } from "./output";
4
4
  import { attest } from "@arktype/attest";
5
- import { Hex } from "viem";
5
+ import { resourceToHex } from "@latticexyz/common";
6
6
 
7
7
  describe("resolveWorldConfig", () => {
8
8
  it("should resolve namespaced tables", () => {
@@ -26,7 +26,7 @@ describe("resolveWorldConfig", () => {
26
26
  const expected = {
27
27
  tables: {
28
28
  ExampleNamespace__ExampleTable: {
29
- tableId: "0x" as Hex,
29
+ tableId: resourceToHex({ type: "table", namespace: "ExampleNamespace", name: "ExampleTable" }),
30
30
  schema: {
31
31
  key: {
32
32
  type: "address",
@@ -64,7 +64,7 @@ describe("resolveWorldConfig", () => {
64
64
  ExampleNamespace: {
65
65
  tables: {
66
66
  ExampleTable: {
67
- tableId: "0x" as Hex,
67
+ tableId: resourceToHex({ type: "table", namespace: "ExampleNamespace", name: "ExampleTable" }),
68
68
  schema: {
69
69
  key: {
70
70
  type: "address",
@@ -136,7 +136,7 @@ describe("resolveWorldConfig", () => {
136
136
  const expected = {
137
137
  tables: {
138
138
  ExampleNamespace__ExampleTable: {
139
- tableId: "0x" as Hex,
139
+ tableId: resourceToHex({ type: "table", namespace: "ExampleNamespace", name: "ExampleTable" }),
140
140
  schema: {
141
141
  key: {
142
142
  type: "address",
@@ -174,7 +174,7 @@ describe("resolveWorldConfig", () => {
174
174
  ExampleNamespace: {
175
175
  tables: {
176
176
  ExampleTable: {
177
- tableId: "0x" as Hex,
177
+ tableId: resourceToHex({ type: "table", namespace: "ExampleNamespace", name: "ExampleTable" }),
178
178
  schema: {
179
179
  key: {
180
180
  type: "address",
@@ -258,7 +258,7 @@ describe("resolveWorldConfig", () => {
258
258
  const expected = {
259
259
  tables: {
260
260
  Name: {
261
- tableId: "0x" as Hex,
261
+ tableId: resourceToHex({ type: "table", namespace: "", name: "Name" }),
262
262
  schema: {
263
263
  key: {
264
264
  type: "bytes32",
@@ -298,7 +298,7 @@ describe("resolveWorldConfig", () => {
298
298
  const expected = {
299
299
  tables: {
300
300
  Name: {
301
- tableId: "0x" as Hex,
301
+ tableId: resourceToHex({ type: "table", namespace: "", name: "Name" }),
302
302
  schema: {
303
303
  key: {
304
304
  type: "bytes32",
@@ -338,7 +338,7 @@ describe("resolveWorldConfig", () => {
338
338
  const expected = {
339
339
  tables: {
340
340
  Example: {
341
- tableId: "0x" as Hex,
341
+ tableId: resourceToHex({ type: "table", namespace: "", name: "Example" }),
342
342
  schema: {
343
343
  key: {
344
344
  type: "address",
@@ -386,7 +386,7 @@ describe("resolveWorldConfig", () => {
386
386
  const expected = {
387
387
  tables: {
388
388
  Example: {
389
- tableId: "0x" as Hex,
389
+ tableId: resourceToHex({ type: "table", namespace: "", name: "Example" }),
390
390
  schema: {
391
391
  key: {
392
392
  type: "address",
@@ -478,7 +478,7 @@ describe("resolveWorldConfig", () => {
478
478
  const expected = {
479
479
  tables: {
480
480
  Example: {
481
- tableId: "0x" as Hex,
481
+ tableId: resourceToHex({ type: "table", namespace: "", name: "Example" }),
482
482
  schema: {
483
483
  key: {
484
484
  type: "address",
@@ -534,7 +534,7 @@ describe("resolveWorldConfig", () => {
534
534
  const expected = {
535
535
  tables: {
536
536
  Example: {
537
- tableId: "0x" as Hex,
537
+ tableId: resourceToHex({ type: "table", namespace: "", name: "Example" }),
538
538
  schema: {
539
539
  key: {
540
540
  type: "string",
@@ -589,7 +589,7 @@ describe("resolveWorldConfig", () => {
589
589
  const expected = {
590
590
  tables: {
591
591
  Example: {
592
- tableId: "0x" as Hex,
592
+ tableId: resourceToHex({ type: "table", namespace: "", name: "Example" }),
593
593
  schema: {
594
594
  key: {
595
595
  type: "address",
@@ -648,7 +648,7 @@ describe("resolveWorldConfig", () => {
648
648
  const expected = {
649
649
  tables: {
650
650
  First: {
651
- tableId: "0x" as Hex,
651
+ tableId: resourceToHex({ type: "table", namespace: "", name: "First" }),
652
652
  schema: {
653
653
  firstKey: {
654
654
  type: "address",
@@ -682,7 +682,7 @@ describe("resolveWorldConfig", () => {
682
682
  primaryKey: ["firstKey", "firstAge"],
683
683
  },
684
684
  Second: {
685
- tableId: "0x" as Hex,
685
+ tableId: resourceToHex({ type: "table", namespace: "", name: "Second" }),
686
686
  schema: {
687
687
  secondKey: {
688
688
  type: "address",
@@ -742,7 +742,7 @@ describe("resolveWorldConfig", () => {
742
742
  const expected = {
743
743
  tables: {
744
744
  First: {
745
- tableId: "0x" as Hex,
745
+ tableId: resourceToHex({ type: "table", namespace: "", name: "First" }),
746
746
  schema: {
747
747
  firstKey: {
748
748
  type: "address",
@@ -776,7 +776,7 @@ describe("resolveWorldConfig", () => {
776
776
  primaryKey: ["firstKey", "firstAge"],
777
777
  },
778
778
  Second: {
779
- tableId: "0x" as Hex,
779
+ tableId: resourceToHex({ type: "table", namespace: "", name: "Second" }),
780
780
  schema: {
781
781
  secondKey: {
782
782
  type: "address",
@@ -890,7 +890,7 @@ describe("resolveWorldConfig", () => {
890
890
  const expected = {
891
891
  tables: {
892
892
  Example: {
893
- tableId: "0x" as Hex,
893
+ tableId: resourceToHex({ type: "table", namespace: "", name: "Example" }),
894
894
  schema: {
895
895
  key: {
896
896
  type: "string",
@@ -1,17 +1,27 @@
1
1
  import { evaluate, narrow } from "@arktype/util";
2
+ import { resourceToHex } from "@latticexyz/common";
3
+ import { mapObject } from "@latticexyz/common/utils";
2
4
  import {
3
5
  UserTypes,
4
6
  Enums,
5
7
  StoreConfigInput,
6
8
  resolveStoreConfig,
7
- validateStoreTablesConfig,
8
9
  resolveStoreTablesConfig,
9
10
  extendedScope,
10
- StoreTablesConfigInput,
11
11
  resolveTableConfig,
12
12
  AbiTypeScope,
13
13
  get,
14
+ isTableShorthandInput,
15
+ resolveTableShorthand,
16
+ validateTableShorthand,
17
+ resolveTableFullConfig,
18
+ validateStoreTablesConfig,
19
+ validateTableFull,
20
+ isObject,
21
+ hasOwnKey,
22
+ Table,
14
23
  } from "@latticexyz/store/config/v2";
24
+ import { Config } from "./output";
15
25
 
16
26
  export type WorldConfigInput<userTypes extends UserTypes = UserTypes, enums extends Enums = Enums> = evaluate<
17
27
  StoreConfigInput<userTypes, enums> & {
@@ -31,6 +41,22 @@ export type validateNamespaces<input, scope extends AbiTypeScope = AbiTypeScope>
31
41
  };
32
42
  };
33
43
 
44
+ function validateNamespaces<scope extends AbiTypeScope = AbiTypeScope>(
45
+ input: unknown,
46
+ scope: scope,
47
+ ): asserts input is NamespacesInput {
48
+ if (isObject(input)) {
49
+ for (const namespace of Object.values(input)) {
50
+ if (!hasOwnKey(namespace, "tables")) {
51
+ throw new Error(`Expected namespace config, received ${JSON.stringify(namespace)}`);
52
+ }
53
+ validateStoreTablesConfig(namespace.tables, scope);
54
+ }
55
+ return;
56
+ }
57
+ throw new Error(`Expected namespaces config, received ${JSON.stringify(input)}`);
58
+ }
59
+
34
60
  export type validateWorldConfig<input> = {
35
61
  readonly [key in keyof input]: key extends "tables"
36
62
  ? validateStoreTablesConfig<input[key], extendedScope<input>>
@@ -73,27 +99,44 @@ export type resolveWorldConfig<input> = evaluate<
73
99
  >;
74
100
 
75
101
  export function resolveWorldConfig<const input>(input: validateWorldConfig<input>): resolveWorldConfig<input> {
76
- const namespaces = get(input, "namespaces") ?? {};
77
102
  const scope = extendedScope(input);
78
103
 
79
- const namespacedTables = Object.fromEntries(
80
- Object.entries(namespaces)
81
- .map(([namespaceKey, namespace]) => {
82
- const tables = get(namespace, "tables") ?? {};
83
- return Object.entries(tables).map(([tableKey, table]) => [`${namespaceKey}__${tableKey}`, table]);
84
- })
104
+ const namespaces = get(input, "namespaces") ?? {};
105
+ validateNamespaces(namespaces, scope);
106
+
107
+ const rootTables = get(input, "tables") ?? {};
108
+ validateStoreTablesConfig(rootTables, scope);
109
+
110
+ const resolvedNamespaces = mapObject(namespaces, (namespace, namespaceKey) => ({
111
+ tables: mapObject(namespace.tables, (table, tableKey) => {
112
+ const fullInput = isTableShorthandInput(table, scope)
113
+ ? resolveTableShorthand(table as validateTableShorthand<typeof table, typeof scope>, scope)
114
+ : table;
115
+ validateTableFull(fullInput, scope);
116
+ return resolveTableFullConfig(
117
+ {
118
+ ...fullInput,
119
+ tableId:
120
+ fullInput.tableId ??
121
+ resourceToHex({ type: "table", namespace: namespaceKey as string, name: tableKey as string }),
122
+ },
123
+ scope,
124
+ ) as Table;
125
+ }) as Config["namespaces"][string]["tables"],
126
+ })) as Config["namespaces"];
127
+
128
+ const resolvedNamespacedTables = Object.fromEntries(
129
+ Object.entries(resolvedNamespaces)
130
+ .map(([namespaceKey, namespace]) =>
131
+ Object.entries(namespace.tables).map(([tableKey, table]) => [`${namespaceKey}__${tableKey}`, table]),
132
+ )
85
133
  .flat(),
86
- ) as StoreTablesConfigInput<typeof scope>;
134
+ ) as Config["tables"];
87
135
 
88
- const resolvedNamespaces = Object.fromEntries(
89
- Object.entries(namespaces).map(([namespaceKey, namespace]) => [
90
- namespaceKey,
91
- { tables: resolveStoreTablesConfig(get(namespace, "tables") ?? {}, scope) },
92
- ]),
93
- );
136
+ const resolvedRootTables = resolveStoreTablesConfig(rootTables, scope);
94
137
 
95
138
  return {
96
- tables: resolveStoreTablesConfig({ ...(get(input, "tables") ?? {}), ...namespacedTables }, scope),
139
+ tables: { ...resolvedRootTables, ...resolvedNamespacedTables },
97
140
  namespaces: resolvedNamespaces,
98
141
  userTypes: get(input, "userTypes") ?? {},
99
142
  enums: get(input, "enums") ?? {},