diff --git a/packages/stash/src/actions/getTable.test.ts b/packages/stash/src/actions/getTable.test.ts index 3c894d93d8..c3fff9c034 100644 --- a/packages/stash/src/actions/getTable.test.ts +++ b/packages/stash/src/actions/getTable.test.ts @@ -131,7 +131,7 @@ describe("getTable", () => { const table = stash.getTable({ table: config, }); - attest>(); + attest>(); }); }); diff --git a/packages/stash/src/actions/getTable.ts b/packages/stash/src/actions/getTable.ts index 636d6b0552..9188756bd3 100644 --- a/packages/stash/src/actions/getTable.ts +++ b/packages/stash/src/actions/getTable.ts @@ -3,7 +3,7 @@ import { Stash } from "../common"; import { DecodeKeyArgs, DecodeKeyResult, decodeKey } from "./decodeKey"; import { DeleteRecordArgs, DeleteRecordResult, deleteRecord } from "./deleteRecord"; import { EncodeKeyArgs, EncodeKeyResult, encodeKey } from "./encodeKey"; -import { GetConfigResult, getConfig } from "./getConfig"; +import { GetTableConfigResult, getTableConfig } from "./getTableConfig"; import { GetKeysResult, getKeys } from "./getKeys"; import { GetRecordArgs, GetRecordResult, getRecord } from "./getRecord"; import { GetRecordsArgs, GetRecordsResult, getRecords } from "./getRecords"; @@ -28,7 +28,7 @@ export type BoundTable = { decodeKey: (args: TableBoundDecodeKeyArgs
) => DecodeKeyResult
; deleteRecord: (args: TableBoundDeleteRecordArgs
) => DeleteRecordResult; encodeKey: (args: TableBoundEncodeKeyArgs
) => EncodeKeyResult; - getConfig: () => GetConfigResult
; + getTableConfig: () => GetTableConfigResult
; getKeys: () => GetKeysResult
; getRecord: (args: TableBoundGetRecordArgs
) => GetRecordResult
; getRecords: (args?: TableBoundGetRecordsArgs
) => GetRecordsResult
; @@ -55,7 +55,7 @@ export function getTable
({ stash, table }: GetTableArgs) => decodeKey({ stash, table, ...args }), deleteRecord: (args: TableBoundDeleteRecordArgs
) => deleteRecord({ stash, table, ...args }), encodeKey: (args: TableBoundEncodeKeyArgs
) => encodeKey({ table, ...args }), - getConfig: () => getConfig({ stash, table }) as table, + getTableConfig: () => getTableConfig({ stash, table }) as table, getKeys: () => getKeys({ stash, table }), getRecord: (args: TableBoundGetRecordArgs
) => getRecord({ stash, table, ...args }), getRecords: (args?: TableBoundGetRecordsArgs
) => getRecords({ stash, table, ...args }), diff --git a/packages/stash/src/actions/getConfig.test.ts b/packages/stash/src/actions/getTableConfig.test.ts similarity index 81% rename from packages/stash/src/actions/getConfig.test.ts rename to packages/stash/src/actions/getTableConfig.test.ts index e24f7eeb45..5de7e83bcf 100644 --- a/packages/stash/src/actions/getConfig.test.ts +++ b/packages/stash/src/actions/getTableConfig.test.ts @@ -2,7 +2,7 @@ import { defineTable } from "@latticexyz/store/config/v2"; import { describe, it } from "vitest"; import { createStash } from "../createStash"; import { attest } from "@ark/attest"; -import { getConfig } from "./getConfig"; +import { getTableConfig } from "./getTableConfig"; import { registerTable } from "./registerTable"; describe("getConfig", () => { @@ -36,7 +36,9 @@ describe("getConfig", () => { registerTable({ stash: stash, table: rootTable }); registerTable({ stash: stash, table: namespacedTable }); - attest(getConfig({ stash: stash, table: { label: "test" } })).equals(rootTable); - attest(getConfig({ stash: stash, table: { label: "test", namespaceLabel: "namespace" } })).equals(namespacedTable); + attest(getTableConfig({ stash: stash, table: { label: "test" } })).equals(rootTable); + attest(getTableConfig({ stash: stash, table: { label: "test", namespaceLabel: "namespace" } })).equals( + namespacedTable, + ); }); }); diff --git a/packages/stash/src/actions/getConfig.ts b/packages/stash/src/actions/getTableConfig.ts similarity index 55% rename from packages/stash/src/actions/getConfig.ts rename to packages/stash/src/actions/getTableConfig.ts index 11ce416266..9a01ac8e4b 100644 --- a/packages/stash/src/actions/getConfig.ts +++ b/packages/stash/src/actions/getTableConfig.ts @@ -1,14 +1,14 @@ import { Table } from "@latticexyz/config"; import { Stash } from "../common"; -export type GetConfigArgs = { +export type GetTableConfigArgs = { stash: Stash; table: { label: string; namespaceLabel?: string }; }; -export type GetConfigResult
= table; +export type GetTableConfigResult
= table; -export function getConfig({ stash, table }: GetConfigArgs): GetConfigResult
{ +export function getTableConfig({ stash, table }: GetTableConfigArgs): GetTableConfigResult
{ const { namespaceLabel, label } = table; return stash.get().config[namespaceLabel ?? ""][label]; } diff --git a/packages/stash/src/actions/getTables.test.ts b/packages/stash/src/actions/getTables.test.ts index e04f174992..f3a6ea75df 100644 --- a/packages/stash/src/actions/getTables.test.ts +++ b/packages/stash/src/actions/getTables.test.ts @@ -39,7 +39,7 @@ describe("getTables", () => { decodeKey: "Function(decodeKey)", deleteRecord: "Function(deleteRecord)", encodeKey: "Function(encodeKey)", - getConfig: "Function(getConfig)", + getTableConfig: "Function(getTableConfig)", getKeys: "Function(getKeys)", getRecord: "Function(getRecord)", getRecords: "Function(getRecords)", @@ -53,7 +53,7 @@ describe("getTables", () => { decodeKey: "Function(decodeKey1)", deleteRecord: "Function(deleteRecord1)", encodeKey: "Function(encodeKey1)", - getConfig: "Function(getConfig1)", + getTableConfig: "Function(getTableConfig1)", getKeys: "Function(getKeys1)", getRecord: "Function(getRecord1)", getRecords: "Function(getRecords1)", diff --git a/packages/stash/src/actions/getTables.ts b/packages/stash/src/actions/getTables.ts index f9f42b94f7..f226264bf3 100644 --- a/packages/stash/src/actions/getTables.ts +++ b/packages/stash/src/actions/getTables.ts @@ -1,15 +1,15 @@ -import { Stash, StoreConfig, getNamespaces, getTableConfig, getNamespaceTables } from "../common"; +import { Stash, StoreConfig, getNamespaces, getConfig, getNamespaceTables } from "../common"; import { BoundTable, getTable } from "./getTable"; type MutableBoundTables = { -readonly [namespace in getNamespaces]: { - -readonly [table in getNamespaceTables]: BoundTable>; + -readonly [table in getNamespaceTables]: BoundTable>; }; }; export type BoundTables = { [namespace in getNamespaces]: { - [table in getNamespaceTables]: BoundTable>; + [table in getNamespaceTables]: BoundTable>; }; }; diff --git a/packages/stash/src/actions/index.ts b/packages/stash/src/actions/index.ts index eb44c0514c..ebf2d6ed2a 100644 --- a/packages/stash/src/actions/index.ts +++ b/packages/stash/src/actions/index.ts @@ -2,7 +2,7 @@ export * from "./decodeKey"; export * from "./deleteRecord"; export * from "./encodeKey"; export * from "./extend"; -export * from "./getConfig"; +export * from "./getTableConfig"; export * from "./getKeys"; export * from "./getRecord"; export * from "./getRecords"; diff --git a/packages/stash/src/actions/runQuery.ts b/packages/stash/src/actions/runQuery.ts index 8948455ea1..4ea11068fb 100644 --- a/packages/stash/src/actions/runQuery.ts +++ b/packages/stash/src/actions/runQuery.ts @@ -8,7 +8,7 @@ import { CommonQueryResult, getQueryConfig, } from "../common"; -import { getConfig } from "./getConfig"; +import { getTableConfig } from "./getTableConfig"; import { getRecords } from "./getRecords"; export type RunQueryOptions = CommonQueryOptions & { @@ -41,11 +41,11 @@ export function runQuery({ }: RunQueryArgs): RunQueryResult { // Only allow fragments with matching table keys for now // TODO: we might be able to enable this if we add something like a `keySelector` - const expectedKeySchema = getKeySchema(getConfig({ stash, table: query[0].table })); + const expectedKeySchema = getKeySchema(getTableConfig({ stash, table: query[0].table })); for (const fragment of query) { if ( Object.values(expectedKeySchema).join("|") !== - Object.values(getKeySchema(getConfig({ stash, table: fragment.table }))).join("|") + Object.values(getKeySchema(getTableConfig({ stash, table: fragment.table }))).join("|") ) { throw new Error( "All tables in a query must share the same key schema. Found mismatch when comparing tables: " + diff --git a/packages/stash/src/actions/subscribeQuery.ts b/packages/stash/src/actions/subscribeQuery.ts index 2edb4bbf86..d20426e095 100644 --- a/packages/stash/src/actions/subscribeQuery.ts +++ b/packages/stash/src/actions/subscribeQuery.ts @@ -10,7 +10,7 @@ import { StoreConfig, getNamespaces, getNamespaceTables, - getTableConfig, + getConfig, getQueryConfig, } from "../common"; import { decodeKey } from "./decodeKey"; @@ -26,7 +26,7 @@ export type SubscribeQueryOptions = Co type QueryTableUpdates = { [namespace in getNamespaces]: { - [table in getNamespaceTables]: TableUpdates>; + [table in getNamespaceTables]: TableUpdates>; }; }; diff --git a/packages/stash/src/common.ts b/packages/stash/src/common.ts index 21de0dee56..fb28474766 100644 --- a/packages/stash/src/common.ts +++ b/packages/stash/src/common.ts @@ -19,7 +19,7 @@ export type getNamespaceTables< namespace extends keyof config["namespaces"], > = keyof config["namespaces"][namespace]["tables"]; -export type getTableConfig< +export type getConfig< config extends StoreConfig, namespace extends keyof config["namespaces"] | undefined, table extends keyof config["namespaces"][namespace extends undefined ? "" : namespace]["tables"], @@ -81,14 +81,14 @@ export type MutableTableRecords
= { [key: string]: export type StoreRecords = { readonly [namespace in getNamespaces]: { - readonly [table in getNamespaceTables]: TableRecords>; + readonly [table in getNamespaceTables]: TableRecords>; }; }; export type MutableStoreRecords = { -readonly [namespace in getNamespaces]: { -readonly [table in getNamespaceTables]: MutableTableRecords< - getTableConfig + getConfig >; }; }; @@ -96,7 +96,7 @@ export type MutableStoreRecords = { export type State = { readonly config: { readonly [namespace in getNamespaces]: { - readonly [table in getNamespaceTables]: getTableConfig; + readonly [table in getNamespaceTables]: getConfig; }; }; readonly records: StoreRecords; @@ -105,7 +105,7 @@ export type State = { export type MutableState = { config: { -readonly [namespace in getNamespaces]: { - -readonly [table in getNamespaceTables]: getTableConfig; + -readonly [table in getNamespaceTables]: getConfig; }; }; records: MutableStoreRecords; @@ -136,7 +136,7 @@ export type StoreUpdates = { }; records: { [namespace in getNamespaces]: { - [table in getNamespaceTables]: TableUpdates>; + [table in getNamespaceTables]: TableUpdates>; }; } & { [namespace: string]: { diff --git a/packages/stash/src/decorators/defaultActions.test.ts b/packages/stash/src/decorators/defaultActions.test.ts index ada2eef48c..1dee81f42c 100644 --- a/packages/stash/src/decorators/defaultActions.test.ts +++ b/packages/stash/src/decorators/defaultActions.test.ts @@ -125,7 +125,7 @@ describe("stash with default actions", () => { const stash = createStash(); stash.registerTable({ table }); - attest(stash.getConfig({ table: { label: "test", namespaceLabel: "namespace" } })).equals(table); + attest(stash.getTableConfig({ table: { label: "test", namespaceLabel: "namespace" } })).equals(table); }); }); @@ -299,7 +299,7 @@ describe("stash with default actions", () => { decodeKey: "Function(decodeKey)", deleteRecord: "Function(deleteRecord)", encodeKey: "Function(encodeKey)", - getConfig: "Function(getConfig)", + getTableConfig: "Function(getTableConfig)", getKeys: "Function(getKeys)", getRecord: "Function(getRecord)", getRecords: "Function(getRecords)", @@ -313,7 +313,7 @@ describe("stash with default actions", () => { decodeKey: "Function(decodeKey1)", deleteRecord: "Function(deleteRecord1)", encodeKey: "Function(encodeKey1)", - getConfig: "Function(getConfig1)", + getTableConfig: "Function(getTableConfig1)", getKeys: "Function(getKeys1)", getRecord: "Function(getRecord1)", getRecords: "Function(getRecords1)", diff --git a/packages/stash/src/decorators/defaultActions.ts b/packages/stash/src/decorators/defaultActions.ts index e7fa7b2245..70ae53f9a5 100644 --- a/packages/stash/src/decorators/defaultActions.ts +++ b/packages/stash/src/decorators/defaultActions.ts @@ -2,7 +2,7 @@ import { Query, Stash, StoreConfig } from "../common"; import { DecodeKeyArgs, DecodeKeyResult, decodeKey } from "../actions/decodeKey"; import { DeleteRecordArgs, DeleteRecordResult, deleteRecord } from "../actions/deleteRecord"; import { EncodeKeyArgs, EncodeKeyResult, encodeKey } from "../actions/encodeKey"; -import { GetConfigArgs, GetConfigResult, getConfig } from "../actions/getConfig"; +import { GetTableConfigArgs, GetTableConfigResult, getTableConfig } from "../actions/getTableConfig"; import { GetKeysArgs, GetKeysResult, getKeys } from "../actions/getKeys"; import { GetRecordArgs, GetRecordResult, getRecord } from "../actions/getRecord"; import { GetRecordsArgs, GetRecordsResult, getRecords } from "../actions/getRecords"; @@ -20,7 +20,7 @@ import { Table } from "@latticexyz/config"; export type StashBoundDecodeKeyArgs
= Omit, "stash">; export type StashBoundDeleteRecordArgs
= Omit, "stash">; export type StashBoundEncodeKeyArgs
= EncodeKeyArgs
; -export type StashBoundGetConfigArgs = Omit; +export type StashBoundGetTableConfigArgs = Omit; export type StashBoundGetKeysArgs
= Omit, "stash">; export type StashBoundGetRecordArgs
= Omit, "stash">; export type StashBoundGetRecordsArgs
= Omit, "stash">; @@ -43,7 +43,7 @@ export type DefaultActions = { decodeKey:
(args: StashBoundDecodeKeyArgs
) => DecodeKeyResult
; deleteRecord:
(args: StashBoundDeleteRecordArgs
) => DeleteRecordResult; encodeKey:
(args: StashBoundEncodeKeyArgs
) => EncodeKeyResult; - getConfig: (args: StashBoundGetConfigArgs) => GetConfigResult; + getTableConfig: (args: StashBoundGetTableConfigArgs) => GetTableConfigResult; getKeys:
(args: StashBoundGetKeysArgs
) => GetKeysResult
; getRecord:
(args: StashBoundGetRecordArgs
) => GetRecordResult
; getRecords:
(args: StashBoundGetRecordsArgs
) => GetRecordsResult
; @@ -65,7 +65,7 @@ export function defaultActions(stash: Stash) decodeKey:
(args: StashBoundDecodeKeyArgs
) => decodeKey({ stash, ...args }), deleteRecord:
(args: StashBoundDeleteRecordArgs
) => deleteRecord({ stash, ...args }), encodeKey:
(args: StashBoundEncodeKeyArgs
) => encodeKey(args), - getConfig: (args: StashBoundGetConfigArgs) => getConfig({ stash, ...args }), + getTableConfig: (args: StashBoundGetTableConfigArgs) => getTableConfig({ stash, ...args }), getKeys:
(args: StashBoundGetKeysArgs
) => getKeys({ stash, ...args }), getRecord:
(args: StashBoundGetRecordArgs
) => getRecord({ stash, ...args }), getRecords:
(args: StashBoundGetRecordsArgs
) => getRecords({ stash, ...args }),