From f24fac2da050659f0faa3f745fe6b2708f036790 Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Wed, 20 Mar 2024 19:49:34 +0000 Subject: [PATCH] feat(store,world): update exports (#2485) --- packages/cli/scripts/generate-test-tables.ts | 2 +- packages/cli/src/commands/tablegen.ts | 2 +- packages/cli/src/commands/trace.ts | 2 +- packages/cli/src/deploy/common.ts | 6 ++++-- packages/cli/src/deploy/configToTables.ts | 2 +- packages/cli/src/deploy/resolveConfig.ts | 2 +- packages/dev-tools/src/common.ts | 2 +- .../dev-tools/src/zustand/TableDataTable.tsx | 2 +- packages/dev-tools/src/zustand/useRecords.ts | 2 +- packages/dev-tools/src/zustand/useTables.ts | 2 +- packages/query/package.json | 1 + packages/query/src/api.ts | 4 ++-- packages/query/src/common.ts | 4 ++-- packages/query/src/findSubjects.ts | 2 +- packages/query/src/matchRecords.ts | 2 +- packages/store-sync/package.json | 1 + packages/store-sync/src/common.ts | 6 ++++-- packages/store-sync/src/createStoreSync.ts | 2 +- packages/store-sync/src/flattenSchema.ts | 2 +- .../postgres-decoded/createStorageAdapter.ts | 2 +- .../src/postgres-decoded/syncToPostgres.ts | 2 +- .../src/postgres/createStorageAdapter.ts | 2 +- .../store-sync/src/postgres/syncToPostgres.ts | 2 +- packages/store-sync/src/query-cache/common.ts | 3 ++- .../store-sync/src/query-cache/createStore.ts | 4 ++-- .../src/query-cache/syncToQueryCache.ts | 2 +- .../store-sync/src/recs/recsStorage.test.ts | 3 ++- packages/store-sync/src/recs/recsStorage.ts | 2 +- packages/store-sync/src/recs/syncToRecs.ts | 5 +++-- .../store-sync/src/recs/tableToComponent.ts | 2 +- .../store-sync/src/recs/tablesToComponents.ts | 2 +- .../store-sync/src/sqlite/sqliteStorage.ts | 2 +- .../store-sync/src/sqlite/syncToSqlite.ts | 2 +- packages/store-sync/src/zustand/common.ts | 2 +- .../src/zustand/createStorageAdapter.ts | 2 +- .../store-sync/src/zustand/createStore.ts | 2 +- .../store-sync/src/zustand/syncToZustand.ts | 5 +++-- packages/store-sync/test/mockGame.ts | 2 +- packages/store-sync/test/utils.ts | 2 +- packages/store/package.json | 16 +++++++++------ packages/store/ts/exports/index.ts | 20 +++++++++++++++++++ .../ts/{index.ts => exports/internal.ts} | 6 ++---- packages/store/ts/register/mudConfig.ts | 2 +- packages/store/tsup.config.ts | 17 ++++++++-------- packages/world-modules/ts/scripts/tablegen.ts | 2 +- packages/world/package.json | 14 ++++++++----- .../world/ts/config/resolveWorldConfig.ts | 2 +- packages/world/ts/config/v2/compat.ts | 3 ++- packages/world/ts/config/v2/output.ts | 2 +- packages/world/ts/config/v2/world.ts | 2 +- packages/world/ts/exports/index.ts | 10 ++++++++++ packages/world/ts/exports/internal.ts | 9 +++++++++ packages/world/ts/index.ts | 10 ---------- packages/world/ts/scripts/tablegen.ts | 2 +- packages/world/tsup.config.ts | 9 ++++++++- pnpm-lock.yaml | 6 ++++++ 56 files changed, 145 insertions(+), 85 deletions(-) create mode 100644 packages/store/ts/exports/index.ts rename packages/store/ts/{index.ts => exports/internal.ts} (52%) create mode 100644 packages/world/ts/exports/index.ts create mode 100644 packages/world/ts/exports/internal.ts delete mode 100644 packages/world/ts/index.ts diff --git a/packages/cli/scripts/generate-test-tables.ts b/packages/cli/scripts/generate-test-tables.ts index 21e81469ee..7c541ae54c 100644 --- a/packages/cli/scripts/generate-test-tables.ts +++ b/packages/cli/scripts/generate-test-tables.ts @@ -1,6 +1,6 @@ import path from "path"; import { tablegen } from "@latticexyz/store/codegen"; -import { defineStore } from "@latticexyz/store/config/v2"; +import { defineStore } from "@latticexyz/store"; import { getRemappings, getSrcDirectory } from "@latticexyz/common/foundry"; // This config is used only for tests. diff --git a/packages/cli/src/commands/tablegen.ts b/packages/cli/src/commands/tablegen.ts index cd78f43456..48a6dddb3e 100644 --- a/packages/cli/src/commands/tablegen.ts +++ b/packages/cli/src/commands/tablegen.ts @@ -1,7 +1,7 @@ import path from "path"; import type { CommandModule } from "yargs"; import { loadConfig } from "@latticexyz/config/node"; -import { Store as StoreConfig } from "@latticexyz/store/config/v2"; +import { Store as StoreConfig } from "@latticexyz/store"; import { tablegen } from "@latticexyz/store/codegen"; import { getRemappings, getSrcDirectory } from "@latticexyz/common/foundry"; diff --git a/packages/cli/src/commands/trace.ts b/packages/cli/src/commands/trace.ts index 1926c56933..53cc30e5a1 100644 --- a/packages/cli/src/commands/trace.ts +++ b/packages/cli/src/commands/trace.ts @@ -5,7 +5,7 @@ import { ethers } from "ethers"; import { loadConfig } from "@latticexyz/config/node"; import { MUDError } from "@latticexyz/common/errors"; import { cast, getRpcUrl, getSrcDirectory } from "@latticexyz/common/foundry"; -import { resolveWorldConfig } from "@latticexyz/world"; +import { resolveWorldConfig } from "@latticexyz/world/internal"; import IBaseWorldAbi from "@latticexyz/world/out/IBaseWorld.sol/IBaseWorld.abi.json" assert { type: "json" }; import worldConfig from "@latticexyz/world/mud.config"; import { resourceToHex } from "@latticexyz/common"; diff --git a/packages/cli/src/deploy/common.ts b/packages/cli/src/deploy/common.ts index 87be77529d..aad107a045 100644 --- a/packages/cli/src/deploy/common.ts +++ b/packages/cli/src/deploy/common.ts @@ -4,8 +4,10 @@ import worldConfig from "@latticexyz/world/mud.config"; import IBaseWorldAbi from "@latticexyz/world/out/IBaseWorld.sol/IBaseWorld.abi.json" assert { type: "json" }; import IModuleAbi from "@latticexyz/world-modules/out/IModule.sol/IModule.abi.json" assert { type: "json" }; import { Tables, configToTables } from "./configToTables"; -import { StoreConfig, helloStoreEvent } from "@latticexyz/store"; -import { WorldConfig, helloWorldEvent } from "@latticexyz/world"; +import { helloStoreEvent } from "@latticexyz/store"; +import { StoreConfig } from "@latticexyz/store/internal"; +import { helloWorldEvent } from "@latticexyz/world"; +import { WorldConfig } from "@latticexyz/world/internal"; import { storeToV1 } from "@latticexyz/store/config/v2"; import { worldToV1 } from "@latticexyz/world/config/v2"; diff --git a/packages/cli/src/deploy/configToTables.ts b/packages/cli/src/deploy/configToTables.ts index f69e7f9cf0..82392e1b50 100644 --- a/packages/cli/src/deploy/configToTables.ts +++ b/packages/cli/src/deploy/configToTables.ts @@ -1,7 +1,7 @@ import { resourceToHex } from "@latticexyz/common"; import { KeySchema, ValueSchema } from "@latticexyz/protocol-parser/internal"; import { SchemaAbiType, StaticAbiType } from "@latticexyz/schema-type/internal"; -import { StoreConfig, resolveUserTypes } from "@latticexyz/store"; +import { StoreConfig, resolveUserTypes } from "@latticexyz/store/internal"; import { Hex } from "viem"; // TODO: we shouldn't need this file once our config parsing returns nicely formed tables diff --git a/packages/cli/src/deploy/resolveConfig.ts b/packages/cli/src/deploy/resolveConfig.ts index 64adee54c9..85d6b2938d 100644 --- a/packages/cli/src/deploy/resolveConfig.ts +++ b/packages/cli/src/deploy/resolveConfig.ts @@ -1,5 +1,5 @@ import path from "path"; -import { resolveWorldConfig } from "@latticexyz/world"; +import { resolveWorldConfig } from "@latticexyz/world/internal"; import { Config, ConfigInput, Library, Module, System, WorldFunction } from "./common"; import { resourceToHex } from "@latticexyz/common"; import { resolveWithContext } from "@latticexyz/config/library"; diff --git a/packages/dev-tools/src/common.ts b/packages/dev-tools/src/common.ts index c473018e60..18fa5a2d08 100644 --- a/packages/dev-tools/src/common.ts +++ b/packages/dev-tools/src/common.ts @@ -1,6 +1,6 @@ import { Observable } from "rxjs"; import { Abi, Block, Chain, PublicClient, Transport, WalletClient } from "viem"; -import { Store as StoreConfig } from "@latticexyz/store/config/v2"; +import { Store as StoreConfig } from "@latticexyz/store"; import { StorageAdapterBlock } from "@latticexyz/store-sync"; import { ZustandStore } from "@latticexyz/store-sync/zustand"; import { ContractWrite } from "@latticexyz/common"; diff --git a/packages/dev-tools/src/zustand/TableDataTable.tsx b/packages/dev-tools/src/zustand/TableDataTable.tsx index c6e147951f..36d29922e3 100644 --- a/packages/dev-tools/src/zustand/TableDataTable.tsx +++ b/packages/dev-tools/src/zustand/TableDataTable.tsx @@ -1,4 +1,4 @@ -import { Table } from "@latticexyz/store"; +import { Table } from "@latticexyz/store/internal"; import { useRecords } from "./useRecords"; import { FieldValue } from "./FieldValue"; diff --git a/packages/dev-tools/src/zustand/useRecords.ts b/packages/dev-tools/src/zustand/useRecords.ts index 7656bd55b3..27d4b7f9fc 100644 --- a/packages/dev-tools/src/zustand/useRecords.ts +++ b/packages/dev-tools/src/zustand/useRecords.ts @@ -1,4 +1,4 @@ -import { Table } from "@latticexyz/store"; +import { Table } from "@latticexyz/store/internal"; import { useDevToolsContext } from "../DevToolsContext"; import { useEffect, useState } from "react"; import { TableRecord } from "@latticexyz/store-sync/zustand"; diff --git a/packages/dev-tools/src/zustand/useTables.ts b/packages/dev-tools/src/zustand/useTables.ts index 81f37eeaf4..d9fbd55ea3 100644 --- a/packages/dev-tools/src/zustand/useTables.ts +++ b/packages/dev-tools/src/zustand/useTables.ts @@ -1,4 +1,4 @@ -import { Table } from "@latticexyz/store"; +import { Table } from "@latticexyz/store/internal"; import { useDevToolsContext } from "../DevToolsContext"; import { useEffect, useState } from "react"; diff --git a/packages/query/package.json b/packages/query/package.json index b2079cb67b..9846d9cc36 100644 --- a/packages/query/package.json +++ b/packages/query/package.json @@ -32,6 +32,7 @@ }, "dependencies": { "@latticexyz/common": "workspace:*", + "@latticexyz/config": "workspace:*", "@latticexyz/schema-type": "workspace:*", "@latticexyz/store": "workspace:*", "viem": "2.7.12" diff --git a/packages/query/src/api.ts b/packages/query/src/api.ts index eb3be879ef..48479801cd 100644 --- a/packages/query/src/api.ts +++ b/packages/query/src/api.ts @@ -1,8 +1,8 @@ import { Hex } from "viem"; import { StaticPrimitiveType, DynamicPrimitiveType, SchemaAbiType } from "@latticexyz/schema-type/internal"; import { satisfy } from "@latticexyz/common/type-utils"; -import { SchemaToPrimitives } from "@latticexyz/store"; -import { Table } from "@latticexyz/store/config/v2"; +import { SchemaToPrimitives } from "@latticexyz/store/internal"; +import { Table } from "@latticexyz/config"; /** * These types represent the "over the wire" protocol (i.e. JSON) for the query API. diff --git a/packages/query/src/common.ts b/packages/query/src/common.ts index cc8508da6d..a107a6a1b0 100644 --- a/packages/query/src/common.ts +++ b/packages/query/src/common.ts @@ -1,6 +1,6 @@ import { StaticPrimitiveType } from "@latticexyz/schema-type/internal"; -import { SchemaToPrimitives } from "@latticexyz/store"; -import { Table } from "@latticexyz/store/config/v2"; +import { SchemaToPrimitives } from "@latticexyz/store/internal"; +import { Table } from "@latticexyz/config"; import { Hex } from "viem"; export type TableRecord = { diff --git a/packages/query/src/findSubjects.ts b/packages/query/src/findSubjects.ts index a060426c05..81243c8661 100644 --- a/packages/query/src/findSubjects.ts +++ b/packages/query/src/findSubjects.ts @@ -1,5 +1,5 @@ import { encodeAbiParameters } from "viem"; -import { Table } from "@latticexyz/store/config/v2"; +import { Table } from "@latticexyz/config"; import { groupBy, uniqueBy } from "@latticexyz/common/utils"; import { Query, SubjectRecords } from "./api"; import { matchRecords } from "./matchRecords"; diff --git a/packages/query/src/matchRecords.ts b/packages/query/src/matchRecords.ts index 15f3dfe2eb..d7aba8bb5a 100644 --- a/packages/query/src/matchRecords.ts +++ b/packages/query/src/matchRecords.ts @@ -1,4 +1,4 @@ -import { Table } from "@latticexyz/store/config/v2"; +import { Table } from "@latticexyz/config"; import { ComparisonCondition, ConditionLiteral, QueryCondition } from "./api"; import { TableRecord } from "./common"; diff --git a/packages/store-sync/package.json b/packages/store-sync/package.json index 0794ec69df..8a39fe2313 100644 --- a/packages/store-sync/package.json +++ b/packages/store-sync/package.json @@ -61,6 +61,7 @@ "dependencies": { "@latticexyz/block-logs-stream": "workspace:*", "@latticexyz/common": "workspace:*", + "@latticexyz/config": "workspace:*", "@latticexyz/protocol-parser": "workspace:*", "@latticexyz/query": "workspace:*", "@latticexyz/recs": "workspace:*", diff --git a/packages/store-sync/src/common.ts b/packages/store-sync/src/common.ts index 2bd8f2219a..e1ba55fd76 100644 --- a/packages/store-sync/src/common.ts +++ b/packages/store-sync/src/common.ts @@ -1,12 +1,14 @@ import { Address, Block, Hex, Log, PublicClient } from "viem"; -import { StoreEventsAbiItem, StoreEventsAbi, resolveConfig } from "@latticexyz/store"; +import { StoreEventsAbiItem, StoreEventsAbi } from "@latticexyz/store"; +import { resolveConfig } from "@latticexyz/store/internal"; import { Observable } from "rxjs"; import { UnionPick } from "@latticexyz/common/type-utils"; import { KeySchema, TableRecord, ValueSchema } from "@latticexyz/protocol-parser/internal"; import storeConfig from "@latticexyz/store/mud.config"; import worldConfig from "@latticexyz/world/mud.config"; import { flattenSchema } from "./flattenSchema"; -import { Store as StoreConfig, storeToV1 } from "@latticexyz/store/config/v2"; +import { Store as StoreConfig } from "@latticexyz/store"; +import { storeToV1 } from "@latticexyz/store/config/v2"; /** @internal Temporary workaround until we redo our config parsing and can pull this directly from the config (https://github.com/latticexyz/mud/issues/1668) */ export const storeTables = resolveConfig(storeToV1(storeConfig)).tables; diff --git a/packages/store-sync/src/createStoreSync.ts b/packages/store-sync/src/createStoreSync.ts index 0b7488759d..a489ea0f77 100644 --- a/packages/store-sync/src/createStoreSync.ts +++ b/packages/store-sync/src/createStoreSync.ts @@ -32,7 +32,7 @@ import { SyncStep } from "./SyncStep"; import { bigIntMax, chunk, isDefined, waitForIdle } from "@latticexyz/common/utils"; import { getSnapshot } from "./getSnapshot"; import { fetchAndStoreLogs } from "./fetchAndStoreLogs"; -import { Store as StoreConfig } from "@latticexyz/store/config/v2"; +import { Store as StoreConfig } from "@latticexyz/store"; const debug = parentDebug.extend("createStoreSync"); diff --git a/packages/store-sync/src/flattenSchema.ts b/packages/store-sync/src/flattenSchema.ts index dd2a61d019..cba8e6b81c 100644 --- a/packages/store-sync/src/flattenSchema.ts +++ b/packages/store-sync/src/flattenSchema.ts @@ -1,5 +1,5 @@ import { mapObject } from "@latticexyz/common/utils"; -import { ValueSchema } from "@latticexyz/store"; +import { ValueSchema } from "@latticexyz/store/internal"; export function flattenSchema( schema: schema, diff --git a/packages/store-sync/src/postgres-decoded/createStorageAdapter.ts b/packages/store-sync/src/postgres-decoded/createStorageAdapter.ts index 26a89320c1..c89db48889 100644 --- a/packages/store-sync/src/postgres-decoded/createStorageAdapter.ts +++ b/packages/store-sync/src/postgres-decoded/createStorageAdapter.ts @@ -2,7 +2,7 @@ import { Hex, PublicClient, concatHex, getAddress } from "viem"; import { PgDatabase, QueryResultHKT } from "drizzle-orm/pg-core"; import { and, eq } from "drizzle-orm"; import { buildTable } from "./buildTable"; -import { Store as StoreConfig } from "@latticexyz/store/config/v2"; +import { Store as StoreConfig } from "@latticexyz/store"; import { debug } from "./debug"; import { StorageAdapter, StorageAdapterBlock } from "../common"; import { isTableRegistrationLog } from "../isTableRegistrationLog"; diff --git a/packages/store-sync/src/postgres-decoded/syncToPostgres.ts b/packages/store-sync/src/postgres-decoded/syncToPostgres.ts index 87ffc4e91f..a413faa593 100644 --- a/packages/store-sync/src/postgres-decoded/syncToPostgres.ts +++ b/packages/store-sync/src/postgres-decoded/syncToPostgres.ts @@ -1,4 +1,4 @@ -import { Store as StoreConfig } from "@latticexyz/store/config/v2"; +import { Store as StoreConfig } from "@latticexyz/store"; import { PgDatabase } from "drizzle-orm/pg-core"; import { SyncOptions, SyncResult } from "../common"; import { createStorageAdapter } from "./createStorageAdapter"; diff --git a/packages/store-sync/src/postgres/createStorageAdapter.ts b/packages/store-sync/src/postgres/createStorageAdapter.ts index ed5e138fa0..c44a4b39b9 100644 --- a/packages/store-sync/src/postgres/createStorageAdapter.ts +++ b/packages/store-sync/src/postgres/createStorageAdapter.ts @@ -1,7 +1,7 @@ import { PublicClient, encodePacked, size } from "viem"; import { PgDatabase, QueryResultHKT } from "drizzle-orm/pg-core"; import { and, eq } from "drizzle-orm"; -import { Store as StoreConfig } from "@latticexyz/store/config/v2"; +import { Store as StoreConfig } from "@latticexyz/store"; import { debug } from "./debug"; import { tables } from "./tables"; import { spliceHex } from "@latticexyz/common"; diff --git a/packages/store-sync/src/postgres/syncToPostgres.ts b/packages/store-sync/src/postgres/syncToPostgres.ts index 87ffc4e91f..a413faa593 100644 --- a/packages/store-sync/src/postgres/syncToPostgres.ts +++ b/packages/store-sync/src/postgres/syncToPostgres.ts @@ -1,4 +1,4 @@ -import { Store as StoreConfig } from "@latticexyz/store/config/v2"; +import { Store as StoreConfig } from "@latticexyz/store"; import { PgDatabase } from "drizzle-orm/pg-core"; import { SyncOptions, SyncResult } from "../common"; import { createStorageAdapter } from "./createStorageAdapter"; diff --git a/packages/store-sync/src/query-cache/common.ts b/packages/store-sync/src/query-cache/common.ts index b793bfc74f..2352e4ec12 100644 --- a/packages/store-sync/src/query-cache/common.ts +++ b/packages/store-sync/src/query-cache/common.ts @@ -1,4 +1,5 @@ -import { Store, Table } from "@latticexyz/store/config/v2"; +import { Store } from "@latticexyz/store"; +import { Table } from "@latticexyz/config"; import { SchemaAbiType, SchemaAbiTypeToPrimitiveType } from "@latticexyz/schema-type/internal"; import { ComparisonCondition, InCondition } from "@latticexyz/query"; diff --git a/packages/store-sync/src/query-cache/createStore.ts b/packages/store-sync/src/query-cache/createStore.ts index 780de1e73b..8bff3d18a8 100644 --- a/packages/store-sync/src/query-cache/createStore.ts +++ b/packages/store-sync/src/query-cache/createStore.ts @@ -1,9 +1,9 @@ import { StoreApi, UseBoundStore, create } from "zustand"; -import { Table } from "@latticexyz/store/config/v2"; +import { Table } from "@latticexyz/config"; import { Tables } from "./common"; import { Hex } from "viem"; import { StaticPrimitiveType } from "@latticexyz/schema-type/internal"; -import { SchemaToPrimitives } from "@latticexyz/store"; +import { SchemaToPrimitives } from "@latticexyz/store/internal"; import { getKeySchema, getValueSchema } from "@latticexyz/protocol-parser/internal"; export type RawTableRecord
= { diff --git a/packages/store-sync/src/query-cache/syncToQueryCache.ts b/packages/store-sync/src/query-cache/syncToQueryCache.ts index e33a6f81bc..84f77f5c80 100644 --- a/packages/store-sync/src/query-cache/syncToQueryCache.ts +++ b/packages/store-sync/src/query-cache/syncToQueryCache.ts @@ -1,7 +1,7 @@ import { SyncOptions, SyncResult } from "../common"; import { createStoreSync } from "../createStoreSync"; import { Address } from "viem"; -import { Store } from "@latticexyz/store/config/v2"; +import { Store } from "@latticexyz/store"; import { createStore } from "./createStore"; import { createStorageAdapter } from "./createStorageAdapter"; diff --git a/packages/store-sync/src/recs/recsStorage.test.ts b/packages/store-sync/src/recs/recsStorage.test.ts index f0ad3fd0ab..fbe22bce3a 100644 --- a/packages/store-sync/src/recs/recsStorage.test.ts +++ b/packages/store-sync/src/recs/recsStorage.test.ts @@ -7,7 +7,8 @@ import { groupLogsByBlockNumber } from "@latticexyz/block-logs-stream"; import { StoreEventsLog } from "../common"; import { singletonEntity } from "./singletonEntity"; import { RpcLog, formatLog, decodeEventLog, Hex } from "viem"; -import { resolveConfig, storeEventsAbi } from "@latticexyz/store"; +import { storeEventsAbi } from "@latticexyz/store"; +import { resolveConfig } from "@latticexyz/store/internal"; import { storeToV1 } from "@latticexyz/store/config/v2"; const tables = resolveConfig(storeToV1(mudConfig)).tables; diff --git a/packages/store-sync/src/recs/recsStorage.ts b/packages/store-sync/src/recs/recsStorage.ts index 6b12c55bb7..0604cd72f0 100644 --- a/packages/store-sync/src/recs/recsStorage.ts +++ b/packages/store-sync/src/recs/recsStorage.ts @@ -1,4 +1,4 @@ -import { Table, resolveConfig } from "@latticexyz/store"; +import { Table, resolveConfig } from "@latticexyz/store/internal"; import { debug } from "./debug"; import { World as RecsWorld, getComponentValue, hasComponent, removeComponent, setComponent } from "@latticexyz/recs"; import { defineInternalComponents } from "./defineInternalComponents"; diff --git a/packages/store-sync/src/recs/syncToRecs.ts b/packages/store-sync/src/recs/syncToRecs.ts index c15f11aea9..2643cfaebf 100644 --- a/packages/store-sync/src/recs/syncToRecs.ts +++ b/packages/store-sync/src/recs/syncToRecs.ts @@ -1,5 +1,6 @@ -import { Table, ResolvedStoreConfig, resolveConfig } from "@latticexyz/store"; -import { Store as StoreConfig, storeToV1 } from "@latticexyz/store/config/v2"; +import { Table, ResolvedStoreConfig, resolveConfig } from "@latticexyz/store/internal"; +import { Store as StoreConfig } from "@latticexyz/store"; +import { storeToV1 } from "@latticexyz/store/config/v2"; import { Component as RecsComponent, World as RecsWorld, getComponentValue, setComponent } from "@latticexyz/recs"; import { SyncOptions, SyncResult } from "../common"; import { RecsStorageAdapter, recsStorage } from "./recsStorage"; diff --git a/packages/store-sync/src/recs/tableToComponent.ts b/packages/store-sync/src/recs/tableToComponent.ts index 2ca0280cb2..0634fa171a 100644 --- a/packages/store-sync/src/recs/tableToComponent.ts +++ b/packages/store-sync/src/recs/tableToComponent.ts @@ -2,7 +2,7 @@ import { Component, Type, World, defineComponent } from "@latticexyz/recs"; import { StoreComponentMetadata } from "./common"; import { SchemaAbiTypeToRecsType, schemaAbiTypeToRecsType } from "./schemaAbiTypeToRecsType"; import { SchemaAbiType } from "@latticexyz/schema-type/internal"; -import { Table } from "@latticexyz/store"; +import { Table } from "@latticexyz/store/internal"; import { mapObject } from "@latticexyz/common/utils"; import { ResourceLabel, resourceToLabel } from "@latticexyz/common"; diff --git a/packages/store-sync/src/recs/tablesToComponents.ts b/packages/store-sync/src/recs/tablesToComponents.ts index 5952f6aa7a..8806dd43fc 100644 --- a/packages/store-sync/src/recs/tablesToComponents.ts +++ b/packages/store-sync/src/recs/tablesToComponents.ts @@ -1,4 +1,4 @@ -import { Table } from "@latticexyz/store"; +import { Table } from "@latticexyz/store/internal"; import { TableToComponent, tableToComponent } from "./tableToComponent"; import { mapObject } from "@latticexyz/common/utils"; import { World } from "@latticexyz/recs"; diff --git a/packages/store-sync/src/sqlite/sqliteStorage.ts b/packages/store-sync/src/sqlite/sqliteStorage.ts index a23d701e29..4dcc7a216b 100644 --- a/packages/store-sync/src/sqlite/sqliteStorage.ts +++ b/packages/store-sync/src/sqlite/sqliteStorage.ts @@ -3,7 +3,7 @@ import { BaseSQLiteDatabase } from "drizzle-orm/sqlite-core"; import { and, eq, sql } from "drizzle-orm"; import { sqliteTableToSql } from "./sqliteTableToSql"; import { buildTable } from "./buildTable"; -import { Store as StoreConfig } from "@latticexyz/store/config/v2"; +import { Store as StoreConfig } from "@latticexyz/store"; import { debug } from "./debug"; import { getTableName } from "./getTableName"; import { chainState, mudStoreTables } from "./internalTables"; diff --git a/packages/store-sync/src/sqlite/syncToSqlite.ts b/packages/store-sync/src/sqlite/syncToSqlite.ts index 2bff8d2830..5c32249664 100644 --- a/packages/store-sync/src/sqlite/syncToSqlite.ts +++ b/packages/store-sync/src/sqlite/syncToSqlite.ts @@ -1,4 +1,4 @@ -import { Store as StoreConfig } from "@latticexyz/store/config/v2"; +import { Store as StoreConfig } from "@latticexyz/store"; import { BaseSQLiteDatabase } from "drizzle-orm/sqlite-core"; import { SyncOptions, SyncResult } from "../common"; import { sqliteStorage } from "./sqliteStorage"; diff --git a/packages/store-sync/src/zustand/common.ts b/packages/store-sync/src/zustand/common.ts index d06a75047a..d86b1ad654 100644 --- a/packages/store-sync/src/zustand/common.ts +++ b/packages/store-sync/src/zustand/common.ts @@ -1,4 +1,4 @@ -import { Table, SchemaToPrimitives } from "@latticexyz/store"; +import { Table, SchemaToPrimitives } from "@latticexyz/store/internal"; import { Hex } from "viem"; export type RawRecord = { diff --git a/packages/store-sync/src/zustand/createStorageAdapter.ts b/packages/store-sync/src/zustand/createStorageAdapter.ts index 09d6f940fd..aefa93bae7 100644 --- a/packages/store-sync/src/zustand/createStorageAdapter.ts +++ b/packages/store-sync/src/zustand/createStorageAdapter.ts @@ -1,4 +1,4 @@ -import { Tables } from "@latticexyz/store"; +import { Tables } from "@latticexyz/store/internal"; import { StorageAdapter } from "../common"; import { RawRecord, TableRecord } from "./common"; import { ZustandStore } from "./createStore"; diff --git a/packages/store-sync/src/zustand/createStore.ts b/packages/store-sync/src/zustand/createStore.ts index 9a6c93547a..67810bb8f3 100644 --- a/packages/store-sync/src/zustand/createStore.ts +++ b/packages/store-sync/src/zustand/createStore.ts @@ -1,4 +1,4 @@ -import { SchemaToPrimitives, Table, Tables } from "@latticexyz/store"; +import { SchemaToPrimitives, Table, Tables } from "@latticexyz/store/internal"; import { StoreApi, UseBoundStore, create } from "zustand"; import { RawRecord, TableRecord } from "./common"; import { Hex } from "viem"; diff --git a/packages/store-sync/src/zustand/syncToZustand.ts b/packages/store-sync/src/zustand/syncToZustand.ts index 69cdec1864..38c4caaa19 100644 --- a/packages/store-sync/src/zustand/syncToZustand.ts +++ b/packages/store-sync/src/zustand/syncToZustand.ts @@ -1,4 +1,4 @@ -import { ResolvedStoreConfig, Tables, resolveConfig } from "@latticexyz/store"; +import { ResolvedStoreConfig, Tables, resolveConfig } from "@latticexyz/store/internal"; import { SyncOptions, SyncResult, storeTables, worldTables } from "../common"; import { createStoreSync } from "../createStoreSync"; import { ZustandStore } from "./createStore"; @@ -6,7 +6,8 @@ import { createStore } from "./createStore"; import { createStorageAdapter } from "./createStorageAdapter"; import { Address } from "viem"; import { SyncStep } from "../SyncStep"; -import { Store as StoreConfig, storeToV1 } from "@latticexyz/store/config/v2"; +import { Store as StoreConfig } from "@latticexyz/store"; +import { storeToV1 } from "@latticexyz/store/config/v2"; type AllTables = ResolvedStoreConfig< storeToV1 diff --git a/packages/store-sync/test/mockGame.ts b/packages/store-sync/test/mockGame.ts index de70479bf9..29e2ca0fab 100644 --- a/packages/store-sync/test/mockGame.ts +++ b/packages/store-sync/test/mockGame.ts @@ -1,7 +1,7 @@ import { execa } from "execa"; import { anvilRpcUrl } from "./common"; import configV2 from "mock-game-contracts/mud.config"; -import { resolveConfig } from "@latticexyz/store"; +import { resolveConfig } from "@latticexyz/store/internal"; import { Hex, isHex } from "viem"; import worldAbi from "mock-game-contracts/out/IWorld.sol/IWorld.abi.json"; import { storeToV1 } from "@latticexyz/store/config/v2"; diff --git a/packages/store-sync/test/utils.ts b/packages/store-sync/test/utils.ts index 53c1f77594..b9c002f620 100644 --- a/packages/store-sync/test/utils.ts +++ b/packages/store-sync/test/utils.ts @@ -4,7 +4,7 @@ import { foundry } from "viem/chains"; import initSqlJs from "sql.js"; import mudConfig from "../../../e2e/packages/contracts/mud.config"; import { createWorld } from "@latticexyz/recs"; -import { resolveConfig } from "@latticexyz/store"; +import { resolveConfig } from "@latticexyz/store/internal"; import { RecsStorageAdapter, recsStorage } from "../src/recs"; import { sqliteStorage } from "../src/sqlite"; import { ZustandStore, createStorageAdapter, createStore } from "../src/zustand"; diff --git a/packages/store/package.json b/packages/store/package.json index 8d82ba7688..cd8aaaf03a 100644 --- a/packages/store/package.json +++ b/packages/store/package.json @@ -10,18 +10,22 @@ "license": "MIT", "type": "module", "exports": { - ".": "./dist/ts/index.js", + ".": "./dist/index.js", + "./internal": "./dist/internal.js", "./mud.config": "./dist/mud.config.js", - "./codegen": "./dist/ts/codegen/index.js", - "./config": "./dist/ts/config/index.js", - "./config/v2": "./dist/ts/config/v2/index.js", - "./register": "./dist/ts/register/index.js", + "./codegen": "./dist/codegen.js", + "./config": "./dist/config.js", + "./config/v2": "./dist/config/v2.js", + "./register": "./dist/register.js", "./out/*": "./out/*" }, "typesVersions": { "*": { "index": [ - "./ts/index.ts" + "./ts/exports/index.ts" + ], + "internal": [ + "./ts/exports/internal.ts" ], "codegen": [ "./ts/codegen/index.ts" diff --git a/packages/store/ts/exports/index.ts b/packages/store/ts/exports/index.ts new file mode 100644 index 0000000000..7048492f24 --- /dev/null +++ b/packages/store/ts/exports/index.ts @@ -0,0 +1,20 @@ +/** + * External exports. + * + * Be sure we're ready to commit to these being supported and changes made backward compatible! + */ + +export { + helloStoreEvent, + storeSetRecordEvent, + storeSpliceStaticDataEvent, + storeSpliceDynamicDataEvent, + storeDeleteRecordEvent, + storeEvents, +} from "../storeEvents"; + +export { storeEventsAbi } from "../storeEventsAbi"; +export type { StoreEventsAbi, StoreEventsAbiItem } from "../storeEventsAbi"; + +export { defineStore } from "../config/v2/store"; +export type { Store } from "../config/v2/output"; diff --git a/packages/store/ts/index.ts b/packages/store/ts/exports/internal.ts similarity index 52% rename from packages/store/ts/index.ts rename to packages/store/ts/exports/internal.ts index 16df2f12f0..680997716b 100644 --- a/packages/store/ts/index.ts +++ b/packages/store/ts/exports/internal.ts @@ -1,7 +1,5 @@ // Importing library has no side-effects, unlike register // (library neither creates nor extends MUDCoreContext when imported) -export * from "./config"; +export * from "../config"; -export * from "./common"; -export * from "./storeEvents"; -export * from "./storeEventsAbi"; +export * from "../common"; diff --git a/packages/store/ts/register/mudConfig.ts b/packages/store/ts/register/mudConfig.ts index 348e349eaf..86f8908787 100644 --- a/packages/store/ts/register/mudConfig.ts +++ b/packages/store/ts/register/mudConfig.ts @@ -1,7 +1,7 @@ import { mudCoreConfig, MUDCoreUserConfig } from "@latticexyz/config/library"; import { ExtractUserTypes, StringForUnion } from "@latticexyz/common/type-utils"; -import { MUDUserConfig } from ".."; import { ExpandMUDUserConfig } from "./typeExtensions"; +import { MUDUserConfig } from "../config/storeConfig"; /** mudCoreConfig wrapper to use generics in some options for better type inference */ export function mudConfig< diff --git a/packages/store/tsup.config.ts b/packages/store/tsup.config.ts index e43cc3eee9..3a4b84cdac 100644 --- a/packages/store/tsup.config.ts +++ b/packages/store/tsup.config.ts @@ -1,14 +1,15 @@ import { defineConfig } from "tsup"; export default defineConfig({ - entry: [ - "mud.config.ts", - "ts/index.ts", - "ts/codegen/index.ts", - "ts/config/index.ts", - "ts/config/v2/index.ts", - "ts/register/index.ts", - ], + entry: { + "mud.config": "mud.config.ts", + index: "ts/exports/index.ts", + internal: "ts/exports/internal.ts", + codegen: "ts/codegen/index.ts", + config: "ts/config/index.ts", + "config/v2": "ts/config/v2/index.ts", + register: "ts/register/index.ts", + }, target: "esnext", format: ["esm"], dts: true, diff --git a/packages/world-modules/ts/scripts/tablegen.ts b/packages/world-modules/ts/scripts/tablegen.ts index e33ecfa8bd..eff4998f7e 100644 --- a/packages/world-modules/ts/scripts/tablegen.ts +++ b/packages/world-modules/ts/scripts/tablegen.ts @@ -1,7 +1,7 @@ import path from "path"; import { loadConfig } from "@latticexyz/config/node"; import { getRemappings, getSrcDirectory } from "@latticexyz/common/foundry"; -import { Store as StoreConfig } from "@latticexyz/store/config/v2"; +import { Store as StoreConfig } from "@latticexyz/store"; import { tablegen } from "@latticexyz/store/codegen"; const config = (await loadConfig()) as StoreConfig; diff --git a/packages/world/package.json b/packages/world/package.json index b4e4d9696c..2f2c86ad8d 100644 --- a/packages/world/package.json +++ b/packages/world/package.json @@ -10,17 +10,21 @@ "license": "MIT", "type": "module", "exports": { - ".": "./dist/ts/index.js", + ".": "./dist/index.js", + "./internal": "./dist/internal.js", "./mud.config": "./dist/mud.config.js", - "./config/v2": "./dist/ts/config/v2/index.js", - "./register": "./dist/ts/register/index.js", - "./node": "./dist/ts/node/index.js", + "./config/v2": "./dist/config/v2.js", + "./register": "./dist/register.js", + "./node": "./dist/node.js", "./out/*": "./out/*" }, "typesVersions": { "*": { "index": [ - "./ts/index.ts" + "./ts/exports/index.ts" + ], + "internal": [ + "./ts/exports/internal.ts" ], "config/v2": [ "./ts/config/v2/index.ts" diff --git a/packages/world/ts/config/resolveWorldConfig.ts b/packages/world/ts/config/resolveWorldConfig.ts index 36997e9007..8b9bea5dab 100644 --- a/packages/world/ts/config/resolveWorldConfig.ts +++ b/packages/world/ts/config/resolveWorldConfig.ts @@ -1,5 +1,5 @@ import { UnrecognizedSystemErrorFactory } from "@latticexyz/config/library"; -import { StoreConfig } from "@latticexyz/store"; +import { StoreConfig } from "@latticexyz/store/internal"; import { SystemConfig, WorldConfig } from "./types"; export type ResolvedSystemConfig = ReturnType; diff --git a/packages/world/ts/config/v2/compat.ts b/packages/world/ts/config/v2/compat.ts index 85f8326078..bb1c3b457e 100644 --- a/packages/world/ts/config/v2/compat.ts +++ b/packages/world/ts/config/v2/compat.ts @@ -1,6 +1,7 @@ import { conform, mutable } from "@arktype/util"; import { Module, World, Systems } from "./output"; -import { storeToV1, Store } from "@latticexyz/store/config/v2"; +import { Store } from "@latticexyz/store"; +import { storeToV1 } from "@latticexyz/store/config/v2"; type modulesToV1 = mutable<{ [key in keyof modules]: Required; diff --git a/packages/world/ts/config/v2/output.ts b/packages/world/ts/config/v2/output.ts index 290d191e65..3e84bbd5d4 100644 --- a/packages/world/ts/config/v2/output.ts +++ b/packages/world/ts/config/v2/output.ts @@ -1,4 +1,4 @@ -import { Store } from "@latticexyz/store/config/v2"; +import { Store } from "@latticexyz/store"; import { DynamicResolution, ValueWithType } from "./dynamicResolution"; export type Module = { diff --git a/packages/world/ts/config/v2/world.ts b/packages/world/ts/config/v2/world.ts index 70a011f0e9..d7cfb74355 100644 --- a/packages/world/ts/config/v2/world.ts +++ b/packages/world/ts/config/v2/world.ts @@ -15,7 +15,7 @@ import { } from "@latticexyz/store/config/v2"; import { SystemsInput, WorldInput } from "./input"; import { CONFIG_DEFAULTS } from "./defaults"; -import { Tables } from "@latticexyz/store"; +import { Tables } from "@latticexyz/store/internal"; import { resolveSystems } from "./systems"; import { resolveNamespacedTables, validateNamespaces } from "./namespaces"; import { resolveCodegen } from "./codegen"; diff --git a/packages/world/ts/exports/index.ts b/packages/world/ts/exports/index.ts new file mode 100644 index 0000000000..283c71b3e1 --- /dev/null +++ b/packages/world/ts/exports/index.ts @@ -0,0 +1,10 @@ +/** + * External exports. + * + * Be sure we're ready to commit to these being supported and changes made backward compatible! + */ + +export { helloWorldEvent, worldDeployedEvent } from "../worldEvents"; + +export { defineWorld } from "../config/v2/world"; +export type { World } from "../config/v2/output"; diff --git a/packages/world/ts/exports/internal.ts b/packages/world/ts/exports/internal.ts new file mode 100644 index 0000000000..9866fe55e4 --- /dev/null +++ b/packages/world/ts/exports/internal.ts @@ -0,0 +1,9 @@ +export * from "../config/defaults"; +export * from "../config/resolveWorldConfig"; +export * from "../config/types"; +export * from "../config/worldConfig"; + +export * from "../encodeSystemCall"; +export * from "../encodeSystemCallFrom"; +export * from "../encodeSystemCalls"; +export * from "../encodeSystemCallsFrom"; diff --git a/packages/world/ts/index.ts b/packages/world/ts/index.ts deleted file mode 100644 index e7abeed4de..0000000000 --- a/packages/world/ts/index.ts +++ /dev/null @@ -1,10 +0,0 @@ -export * from "./config/defaults"; -export * from "./config/resolveWorldConfig"; -export * from "./config/types"; -export * from "./config/worldConfig"; - -export * from "./encodeSystemCall"; -export * from "./encodeSystemCallFrom"; -export * from "./encodeSystemCalls"; -export * from "./encodeSystemCallsFrom"; -export * from "./worldEvents"; diff --git a/packages/world/ts/scripts/tablegen.ts b/packages/world/ts/scripts/tablegen.ts index e33ecfa8bd..eff4998f7e 100644 --- a/packages/world/ts/scripts/tablegen.ts +++ b/packages/world/ts/scripts/tablegen.ts @@ -1,7 +1,7 @@ import path from "path"; import { loadConfig } from "@latticexyz/config/node"; import { getRemappings, getSrcDirectory } from "@latticexyz/common/foundry"; -import { Store as StoreConfig } from "@latticexyz/store/config/v2"; +import { Store as StoreConfig } from "@latticexyz/store"; import { tablegen } from "@latticexyz/store/codegen"; const config = (await loadConfig()) as StoreConfig; diff --git a/packages/world/tsup.config.ts b/packages/world/tsup.config.ts index 5f37fe631a..cb091b605f 100644 --- a/packages/world/tsup.config.ts +++ b/packages/world/tsup.config.ts @@ -1,7 +1,14 @@ import { defineConfig } from "tsup"; export default defineConfig({ - entry: ["mud.config.ts", "ts/index.ts", "ts/register/index.ts", "ts/config/v2/index.ts", "ts/node/index.ts"], + entry: { + "mud.config": "mud.config.ts", + index: "ts/exports/index.ts", + internal: "ts/exports/internal.ts", + register: "ts/register/index.ts", + "config/v2": "ts/config/v2/index.ts", + node: "ts/node/index.ts", + }, target: "esnext", format: ["esm"], dts: true, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f0d848aab1..9e2c5c67d5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -560,6 +560,9 @@ importers: '@latticexyz/common': specifier: workspace:* version: link:../common + '@latticexyz/config': + specifier: workspace:* + version: link:../config '@latticexyz/schema-type': specifier: workspace:* version: link:../schema-type @@ -924,6 +927,9 @@ importers: '@latticexyz/common': specifier: workspace:* version: link:../common + '@latticexyz/config': + specifier: workspace:* + version: link:../config '@latticexyz/protocol-parser': specifier: workspace:* version: link:../protocol-parser