From afdba793fd84abf17eef5ef59dd56fabe353c8bd Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Thu, 27 Jul 2023 10:32:06 -0700 Subject: [PATCH] feat(cli,recs,std-client): update RECS components with v2 key/value schemas (#1195) --- .changeset/weak-mails-cross.md | 15 +++ .../src/mud/contractComponents.ts | 41 ++++--- .../src/mud/contractComponents.ts | 35 ++++-- .../src/mud/contractComponents.ts | 35 ++++-- .../src/mud/contractComponents.ts | 35 ++++-- .../cli/src/render-ts/recsV1TableOptions.ts | 18 +++ .../cli/src/render-ts/renderRecsV1Tables.ts | 16 ++- packages/cli/src/render-ts/types.ts | 4 + packages/react/src/useComponentValue.ts | 7 +- packages/recs/src/Component.ts | 32 +++-- packages/recs/src/Indexer.ts | 2 +- packages/recs/src/types.ts | 16 +-- .../src/components/ActionComponent.ts | 2 +- .../src/contractComponents.test-d.ts | 9 +- .../store/contractComponents.ts | 73 ++++++++---- .../world/contractComponents.ts | 111 +++++++++++------- .../std-client/src/setup/setupMUDV2Network.ts | 9 +- packages/std-client/src/setup/types.ts | 2 +- .../ActionSystem/createActionSystem.ts | 2 +- .../src/systems/ActionSystem/types.ts | 4 +- .../client/src/mud/contractComponents.ts | 11 +- .../client/src/mud/contractComponents.ts | 11 +- .../client/src/mud/contractComponents.ts | 11 +- .../client/src/mud/contractComponents.ts | 11 +- 24 files changed, 326 insertions(+), 186 deletions(-) create mode 100644 .changeset/weak-mails-cross.md diff --git a/.changeset/weak-mails-cross.md b/.changeset/weak-mails-cross.md new file mode 100644 index 0000000000..6d42241d47 --- /dev/null +++ b/.changeset/weak-mails-cross.md @@ -0,0 +1,15 @@ +--- +"@latticexyz/cli": patch +"@latticexyz/recs": patch +"@latticexyz/std-client": patch +--- + +Update RECS components with v2 key/value schemas. This helps with encoding/decoding composite keys and strong types for keys/values. + +This may break if you were previously dependent on `component.id`, `component.metadata.componentId`, or `component.metadata.tableId`: + +- `component.id` is now the on-chain `bytes32` hex representation of the table ID +- `component.metadata.componentName` is the table name (e.g. `Position`) +- `component.metadata.tableName` is the namespaced table name (e.g. `myworld:Position`) +- `component.metadata.keySchema` is an object with key names and their corresponding ABI types +- `component.metadata.valueSchema` is an object with field names and their corresponding ABI types diff --git a/e2e/packages/client-vanilla/src/mud/contractComponents.ts b/e2e/packages/client-vanilla/src/mud/contractComponents.ts index 388ac45595..9ffa13a377 100644 --- a/e2e/packages/client-vanilla/src/mud/contractComponents.ts +++ b/e2e/packages/client-vanilla/src/mud/contractComponents.ts @@ -1,27 +1,27 @@ /* Autogenerated file. Do not edit manually. */ -import { TableId } from "@latticexyz/common"; import { defineComponent, Type as RecsType, World } from "@latticexyz/recs"; export function defineContractComponents(world: World) { return { Number: (() => { - const tableId = new TableId("", "Number"); return defineComponent( world, { value: RecsType.Number, }, { + id: "0x000000000000000000000000000000004e756d62657200000000000000000000", metadata: { - contractId: tableId.toHex(), - tableId: tableId.toString(), + componentName: "Number", + tableName: ":Number", + keySchema: { key: "uint32" }, + valueSchema: { value: "uint32" }, }, - } + } as const ); })(), Vector: (() => { - const tableId = new TableId("", "Vector"); return defineComponent( world, { @@ -29,30 +29,34 @@ export function defineContractComponents(world: World) { y: RecsType.Number, }, { + id: "0x00000000000000000000000000000000566563746f7200000000000000000000", metadata: { - contractId: tableId.toHex(), - tableId: tableId.toString(), + componentName: "Vector", + tableName: ":Vector", + keySchema: { key: "uint32" }, + valueSchema: { x: "int32", y: "int32" }, }, - } + } as const ); })(), NumberList: (() => { - const tableId = new TableId("", "NumberList"); return defineComponent( world, { value: RecsType.NumberArray, }, { + id: "0x000000000000000000000000000000004e756d6265724c697374000000000000", metadata: { - contractId: tableId.toHex(), - tableId: tableId.toString(), + componentName: "NumberList", + tableName: ":NumberList", + keySchema: {}, + valueSchema: { value: "uint32[]" }, }, - } + } as const ); })(), Multi: (() => { - const tableId = new TableId("", "Multi"); return defineComponent( world, { @@ -60,11 +64,14 @@ export function defineContractComponents(world: World) { value: RecsType.Boolean, }, { + id: "0x000000000000000000000000000000004d756c74690000000000000000000000", metadata: { - contractId: tableId.toHex(), - tableId: tableId.toString(), + componentName: "Multi", + tableName: ":Multi", + keySchema: { a: "uint32", b: "bool", c: "uint256", d: "int120" }, + valueSchema: { num: "int256", value: "bool" }, }, - } + } as const ); })(), }; diff --git a/examples/minimal/packages/client-phaser/src/mud/contractComponents.ts b/examples/minimal/packages/client-phaser/src/mud/contractComponents.ts index d84f563b1b..5ab7b05983 100644 --- a/examples/minimal/packages/client-phaser/src/mud/contractComponents.ts +++ b/examples/minimal/packages/client-phaser/src/mud/contractComponents.ts @@ -1,53 +1,62 @@ /* Autogenerated file. Do not edit manually. */ -import { TableId } from "@latticexyz/common"; import { defineComponent, Type as RecsType, World } from "@latticexyz/recs"; export function defineContractComponents(world: World) { return { CounterTable: (() => { - const tableId = new TableId("", "CounterTable"); return defineComponent( world, { value: RecsType.Number, }, { + id: "0x00000000000000000000000000000000436f756e7465725461626c6500000000", metadata: { - contractId: tableId.toHex(), - tableId: tableId.toString(), + componentName: "CounterTable", + tableName: ":CounterTable", + keySchema: { key: "bytes32" }, + valueSchema: { value: "uint32" }, }, - } + } as const ); })(), MessageTable: (() => { - const tableId = new TableId("", "MessageTable"); return defineComponent( world, { value: RecsType.String, }, { + id: "0x000000000000000000000000000000004d6573736167655461626c6500000000", metadata: { - contractId: tableId.toHex(), - tableId: tableId.toString(), + componentName: "MessageTable", + tableName: ":MessageTable", + keySchema: {}, + valueSchema: { value: "string" }, }, - } + } as const ); })(), Inventory: (() => { - const tableId = new TableId("", "Inventory"); return defineComponent( world, { amount: RecsType.Number, }, { + id: "0x00000000000000000000000000000000496e76656e746f727900000000000000", metadata: { - contractId: tableId.toHex(), - tableId: tableId.toString(), + componentName: "Inventory", + tableName: ":Inventory", + keySchema: { + owner: "address", + item: "uint32", + itemVariant: "uint32", + }, + valueSchema: { amount: "uint32" }, }, - } + } as const ); })(), }; diff --git a/examples/minimal/packages/client-react/src/mud/contractComponents.ts b/examples/minimal/packages/client-react/src/mud/contractComponents.ts index d84f563b1b..5ab7b05983 100644 --- a/examples/minimal/packages/client-react/src/mud/contractComponents.ts +++ b/examples/minimal/packages/client-react/src/mud/contractComponents.ts @@ -1,53 +1,62 @@ /* Autogenerated file. Do not edit manually. */ -import { TableId } from "@latticexyz/common"; import { defineComponent, Type as RecsType, World } from "@latticexyz/recs"; export function defineContractComponents(world: World) { return { CounterTable: (() => { - const tableId = new TableId("", "CounterTable"); return defineComponent( world, { value: RecsType.Number, }, { + id: "0x00000000000000000000000000000000436f756e7465725461626c6500000000", metadata: { - contractId: tableId.toHex(), - tableId: tableId.toString(), + componentName: "CounterTable", + tableName: ":CounterTable", + keySchema: { key: "bytes32" }, + valueSchema: { value: "uint32" }, }, - } + } as const ); })(), MessageTable: (() => { - const tableId = new TableId("", "MessageTable"); return defineComponent( world, { value: RecsType.String, }, { + id: "0x000000000000000000000000000000004d6573736167655461626c6500000000", metadata: { - contractId: tableId.toHex(), - tableId: tableId.toString(), + componentName: "MessageTable", + tableName: ":MessageTable", + keySchema: {}, + valueSchema: { value: "string" }, }, - } + } as const ); })(), Inventory: (() => { - const tableId = new TableId("", "Inventory"); return defineComponent( world, { amount: RecsType.Number, }, { + id: "0x00000000000000000000000000000000496e76656e746f727900000000000000", metadata: { - contractId: tableId.toHex(), - tableId: tableId.toString(), + componentName: "Inventory", + tableName: ":Inventory", + keySchema: { + owner: "address", + item: "uint32", + itemVariant: "uint32", + }, + valueSchema: { amount: "uint32" }, }, - } + } as const ); })(), }; diff --git a/examples/minimal/packages/client-vanilla/src/mud/contractComponents.ts b/examples/minimal/packages/client-vanilla/src/mud/contractComponents.ts index d84f563b1b..5ab7b05983 100644 --- a/examples/minimal/packages/client-vanilla/src/mud/contractComponents.ts +++ b/examples/minimal/packages/client-vanilla/src/mud/contractComponents.ts @@ -1,53 +1,62 @@ /* Autogenerated file. Do not edit manually. */ -import { TableId } from "@latticexyz/common"; import { defineComponent, Type as RecsType, World } from "@latticexyz/recs"; export function defineContractComponents(world: World) { return { CounterTable: (() => { - const tableId = new TableId("", "CounterTable"); return defineComponent( world, { value: RecsType.Number, }, { + id: "0x00000000000000000000000000000000436f756e7465725461626c6500000000", metadata: { - contractId: tableId.toHex(), - tableId: tableId.toString(), + componentName: "CounterTable", + tableName: ":CounterTable", + keySchema: { key: "bytes32" }, + valueSchema: { value: "uint32" }, }, - } + } as const ); })(), MessageTable: (() => { - const tableId = new TableId("", "MessageTable"); return defineComponent( world, { value: RecsType.String, }, { + id: "0x000000000000000000000000000000004d6573736167655461626c6500000000", metadata: { - contractId: tableId.toHex(), - tableId: tableId.toString(), + componentName: "MessageTable", + tableName: ":MessageTable", + keySchema: {}, + valueSchema: { value: "string" }, }, - } + } as const ); })(), Inventory: (() => { - const tableId = new TableId("", "Inventory"); return defineComponent( world, { amount: RecsType.Number, }, { + id: "0x00000000000000000000000000000000496e76656e746f727900000000000000", metadata: { - contractId: tableId.toHex(), - tableId: tableId.toString(), + componentName: "Inventory", + tableName: ":Inventory", + keySchema: { + owner: "address", + item: "uint32", + itemVariant: "uint32", + }, + valueSchema: { amount: "uint32" }, }, - } + } as const ); })(), }; diff --git a/packages/cli/src/render-ts/recsV1TableOptions.ts b/packages/cli/src/render-ts/recsV1TableOptions.ts index c7bcbd184b..c15d4e8f43 100644 --- a/packages/cli/src/render-ts/recsV1TableOptions.ts +++ b/packages/cli/src/render-ts/recsV1TableOptions.ts @@ -2,6 +2,8 @@ import { StoreConfig } from "@latticexyz/store"; import { resolveAbiOrUserType } from "@latticexyz/store/codegen"; import { schemaTypesToRecsTypeStrings } from "./schemaTypesToRecsTypeStrings"; import { RecsV1TableOptions } from "./types"; +import { SchemaTypeToAbiType } from "@latticexyz/schema-type/deprecated"; +import { StaticAbiType } from "@latticexyz/schema-type"; export function getRecsV1TableOptions(config: StoreConfig): RecsV1TableOptions { const tableOptions = []; @@ -27,8 +29,24 @@ export function getRecsV1TableOptions(config: StoreConfig): RecsV1TableOptions { name: tableData.name, }; + // TODO: move user type -> abi type into our config expanding step rather than sprinkled everywhere (https://github.com/latticexyz/mud/issues/1201) + const keySchema = Object.fromEntries( + Object.entries(tableData.keySchema).map(([name, type]) => [ + name, + SchemaTypeToAbiType[resolveAbiOrUserType(type, config).schemaType] as StaticAbiType, + ]) + ); + const valueSchema = Object.fromEntries( + Object.entries(tableData.schema).map(([name, type]) => [ + name, + SchemaTypeToAbiType[resolveAbiOrUserType(type, config).schemaType], + ]) + ); + tableOptions.push({ tableName, + keySchema, + valueSchema, fields, staticResourceData, }); diff --git a/packages/cli/src/render-ts/renderRecsV1Tables.ts b/packages/cli/src/render-ts/renderRecsV1Tables.ts index 7b006e0fbb..e3b53d0609 100644 --- a/packages/cli/src/render-ts/renderRecsV1Tables.ts +++ b/packages/cli/src/render-ts/renderRecsV1Tables.ts @@ -1,3 +1,4 @@ +import { TableId } from "@latticexyz/common"; import { RecsV1TableOptions } from "./types"; export function renderRecsV1Tables(options: RecsV1TableOptions) { @@ -5,7 +6,6 @@ export function renderRecsV1Tables(options: RecsV1TableOptions) { return `/* Autogenerated file. Do not edit manually. */ -import { TableId } from "@latticexyz/common"; import { defineComponent, Type as RecsType, World } from "@latticexyz/recs"; export function defineContractComponents(world: World) { @@ -18,14 +18,20 @@ export function defineContractComponents(world: World) { function renderDefineComponent(table: RecsV1TableOptions["tables"][number]) { const { namespace, name } = table.staticResourceData; + const tableId = new TableId(namespace, name); return ` (() => { - const tableId = new TableId("${namespace}", "${name}"); return defineComponent(world, { - ${table.fields.map(({ name, recsTypeString }) => `${name}: ${recsTypeString},`).join("")} + ${table.fields.map(({ name, recsTypeString }) => `${name}: ${recsTypeString}`).join(",")} }, { - metadata: { contractId: tableId.toHex(), tableId: tableId.toString() }, - }); + id: ${JSON.stringify(tableId.toHex())}, + metadata: { + componentName: ${JSON.stringify(name)}, + tableName: ${JSON.stringify([namespace, name].join(":"))}, + keySchema: ${JSON.stringify(table.keySchema)}, + valueSchema: ${JSON.stringify(table.valueSchema)}, + }, + } as const); })() `; } diff --git a/packages/cli/src/render-ts/types.ts b/packages/cli/src/render-ts/types.ts index 85746e2655..b5c0e1cb15 100644 --- a/packages/cli/src/render-ts/types.ts +++ b/packages/cli/src/render-ts/types.ts @@ -1,6 +1,10 @@ +import { SchemaAbiType, StaticAbiType } from "@latticexyz/schema-type"; + export interface RecsV1TableOptions { tables: { tableName: string; + keySchema: Record; + valueSchema: Record; fields: { recsTypeString: string; name: string; diff --git a/packages/react/src/useComponentValue.ts b/packages/react/src/useComponentValue.ts index c0308c82bb..63c8beb967 100644 --- a/packages/react/src/useComponentValue.ts +++ b/packages/react/src/useComponentValue.ts @@ -6,24 +6,23 @@ import { getComponentValue, Has, isComponentUpdate, - Metadata, Schema, } from "@latticexyz/recs"; import { useEffect, useState } from "react"; export function useComponentValue( - component: Component, + component: Component, entity: Entity | undefined, defaultValue: ComponentValue ): ComponentValue; export function useComponentValue( - component: Component, + component: Component, entity: Entity | undefined ): ComponentValue | undefined; export function useComponentValue( - component: Component, + component: Component, entity: Entity | undefined, defaultValue?: ComponentValue ) { diff --git a/packages/recs/src/Component.ts b/packages/recs/src/Component.ts index 72835acdce..e6f62664c0 100644 --- a/packages/recs/src/Component.ts +++ b/packages/recs/src/Component.ts @@ -19,7 +19,13 @@ import { isFullComponentValue, isIndexer } from "./utils"; import { getEntityString, getEntitySymbol } from "./Entity"; function getComponentName(component: Component) { - return component.metadata?.tableId ?? component.metadata?.contractId ?? component.id; + return ( + component.metadata?.componentName ?? + component.metadata?.tableName ?? + component.metadata?.tableId ?? + component.metadata?.contractId ?? + component.id + ); } /** @@ -41,7 +47,7 @@ function getComponentName(component: Component) { * const Position = defineComponent(world, { x: Type.Number, y: Type.Number }, { id: "Position" }); * ``` */ -export function defineComponent( +export function defineComponent( world: World, schema: S, options?: { id?: string; metadata?: M; indexed?: boolean } @@ -71,7 +77,7 @@ export function defineComponent( +export function setComponent( component: Component, entity: Entity, value: ComponentValue @@ -122,7 +128,7 @@ export function setComponent( * updateComponent(Position, entity, { x: 1 }); * ``` */ -export function updateComponent( +export function updateComponent( component: Component, entity: Entity, value: Partial>, @@ -145,7 +151,7 @@ export function updateComponent( * @param component {@link defineComponent Component} to be updated. * @param entity {@link Entity} whose value should be removed from this component. */ -export function removeComponent( +export function removeComponent( component: Component, entity: Entity ) { @@ -164,7 +170,7 @@ export function removeComponent( * @param entity {@link Entity} to check whether it has a value in the given component. * @returns true if the component contains a value for the given entity, else false. */ -export function hasComponent( +export function hasComponent( component: Component, entity: Entity ): boolean { @@ -181,7 +187,7 @@ export function hasComponent( * @param entity {@link Entity} to get the value for from the given component. * @returns Value of the given entity in the given component or undefined if no value exists. */ -export function getComponentValue( +export function getComponentValue( component: Component, entity: Entity ): ComponentValue | undefined { @@ -210,7 +216,7 @@ export function getComponentValue( * @remarks * Throws an error if no value exists in the component for the given entity. */ -export function getComponentValueStrict( +export function getComponentValueStrict( component: Component, entity: Entity ): ComponentValue { @@ -233,7 +239,7 @@ export function getComponentValueStrict( * componentValueEquals({ x: 1 }, { x: 1, y: 3 }) // returns true because x is equal and y is not present in a * ``` */ -export function componentValueEquals( +export function componentValueEquals( a?: Partial>, b?: ComponentValue ): boolean { @@ -256,7 +262,7 @@ export function componentValueEquals( * @param value {@link ComponentValue} with {@link ComponentSchema} `S` * @returns Tuple `[component, value]` */ -export function withValue( +export function withValue( component: Component, value: ComponentValue ): [Component, ComponentValue] { @@ -296,7 +302,7 @@ export function getEntitiesWithValue( * @param component {@link defineComponent Component} to get all entities from * @returns Set of all entities in the given component. */ -export function getComponentEntities( +export function getComponentEntities( component: Component ): IterableIterator { return component.entities(); @@ -316,7 +322,7 @@ export function getComponentEntities( * @param component {@link defineComponent Component} to use as underlying source for the overridable component * @returns overridable component */ -export function overridableComponent( +export function overridableComponent( component: Component ): OverridableComponent { let nonce = 0; @@ -455,7 +461,7 @@ export function clearLocalCache(component: Component, uniqueWorldIdentifier?: st } // Note: Only proof of concept for now - use this only for component that do not update frequently -export function createLocalCache( +export function createLocalCache( component: Component, uniqueWorldIdentifier?: string ): Component { diff --git a/packages/recs/src/Indexer.ts b/packages/recs/src/Indexer.ts index 95a4680942..bf7d39a472 100644 --- a/packages/recs/src/Indexer.ts +++ b/packages/recs/src/Indexer.ts @@ -16,7 +16,7 @@ import { Component, ComponentValue, Entity, EntitySymbol, Indexer, Metadata, Sch * @param component {@link defineComponent Component} to index. * @returns Indexed version of the component. */ -export function createIndexer( +export function createIndexer( component: Component ): Indexer { const valueToEntities = new Map>(); diff --git a/packages/recs/src/types.ts b/packages/recs/src/types.ts index b20cbb38c8..4f0c905f6e 100644 --- a/packages/recs/src/types.ts +++ b/packages/recs/src/types.ts @@ -31,7 +31,7 @@ export type Metadata = /** * Mapping between JavaScript {@link Type} enum and corresponding TypeScript type. */ -export type ValueType = { +export type ValueType = { [Type.Boolean]: boolean; [Type.Number]: number; [Type.BigInt]: bigint; @@ -56,14 +56,14 @@ export type ValueType = { /** * Used to infer the TypeScript type of a component value corresponding to a given {@link Schema}. */ -export type ComponentValue = { +export type ComponentValue = { [key in keyof S]: ValueType[S[key]]; }; /** * Type of a component update corresponding to a given {@link Schema}. */ -export type ComponentUpdate = { +export type ComponentUpdate = { entity: Entity; value: [ComponentValue | undefined, ComponentValue | undefined]; component: Component; @@ -72,7 +72,7 @@ export type ComponentUpdate = { /** * Type of component returned by {@link defineComponent}. */ -export interface Component { +export interface Component { id: string; values: { [key in keyof S]: Map[S[key]]> }; schema: S; @@ -86,7 +86,7 @@ export interface Component = Component & { +export type Indexer = Component & { getEntitiesWithValue: (value: ComponentValue) => Set; }; @@ -94,7 +94,7 @@ export type Components = { [key: string]: Component; }; -export interface ComponentWithStream extends Component { +export interface ComponentWithStream extends Component { stream$: Subject<{ entity: Entity; value: ComponentValue | undefined }>; } @@ -180,7 +180,7 @@ export type QueryFragments = QueryFragment[]; export type SchemaOf> = C extends Component ? S : never; -export type Override = { +export type Override = { entity: Entity; value: Partial> | null; }; @@ -188,7 +188,7 @@ export type Override = { /** * Type of overridable component returned by {@link overridableComponent}. */ -export type OverridableComponent = Component< +export type OverridableComponent = Component< S, M, T diff --git a/packages/std-client/src/components/ActionComponent.ts b/packages/std-client/src/components/ActionComponent.ts index f092483be4..029ef1cc24 100644 --- a/packages/std-client/src/components/ActionComponent.ts +++ b/packages/std-client/src/components/ActionComponent.ts @@ -1,6 +1,6 @@ import { defineComponent, World, Type, Component, Metadata, SchemaOf } from "@latticexyz/recs"; -export function defineActionComponent(world: World) { +export function defineActionComponent(world: World) { const Action = defineComponent( world, { diff --git a/packages/std-client/src/contractComponents.test-d.ts b/packages/std-client/src/contractComponents.test-d.ts index c516d7576d..0b030d5103 100644 --- a/packages/std-client/src/contractComponents.test-d.ts +++ b/packages/std-client/src/contractComponents.test-d.ts @@ -12,10 +12,11 @@ describe("store/contractComponents", () => { y: RecsType.Number; }, { - contractId: `0x${string}`; - tableId: string; - }, - undefined + readonly componentName: "Vector2"; + readonly tableName: "mudstore:Vector2"; + readonly keySchema: { key: "bytes32" }; + readonly valueSchema: { x: "uint32"; y: "uint32" }; + } > >(); }); diff --git a/packages/std-client/src/mud-definitions/store/contractComponents.ts b/packages/std-client/src/mud-definitions/store/contractComponents.ts index 42001c8c29..30372c5ff5 100644 --- a/packages/std-client/src/mud-definitions/store/contractComponents.ts +++ b/packages/std-client/src/mud-definitions/store/contractComponents.ts @@ -1,42 +1,44 @@ /* Autogenerated file. Do not edit manually. */ -import { TableId } from "@latticexyz/common"; import { defineComponent, Type as RecsType, World } from "@latticexyz/recs"; export function defineContractComponents(world: World) { return { Hooks: (() => { - const tableId = new TableId("mudstore", "Hooks"); return defineComponent( world, { value: RecsType.StringArray, }, { + id: "0x6d756473746f72650000000000000000486f6f6b730000000000000000000000", metadata: { - contractId: tableId.toHex(), - tableId: tableId.toString(), + componentName: "Hooks", + tableName: "mudstore:Hooks", + keySchema: { key: "bytes32" }, + valueSchema: { value: "address[]" }, }, - } + } as const ); })(), Callbacks: (() => { - const tableId = new TableId("mudstore", "Callbacks"); return defineComponent( world, { value: RecsType.StringArray, }, { + id: "0x6d756473746f7265000000000000000043616c6c6261636b7300000000000000", metadata: { - contractId: tableId.toHex(), - tableId: tableId.toString(), + componentName: "Callbacks", + tableName: "mudstore:Callbacks", + keySchema: { key: "bytes32" }, + valueSchema: { value: "bytes24[]" }, }, - } + } as const ); })(), StoreMetadata: (() => { - const tableId = new TableId("mudstore", "StoreMetadata"); return defineComponent( world, { @@ -44,15 +46,17 @@ export function defineContractComponents(world: World) { abiEncodedFieldNames: RecsType.String, }, { + id: "0x6d756473746f7265000000000000000053746f72654d65746164617461000000", metadata: { - contractId: tableId.toHex(), - tableId: tableId.toString(), + componentName: "StoreMetadata", + tableName: "mudstore:StoreMetadata", + keySchema: { tableId: "bytes32" }, + valueSchema: { tableName: "string", abiEncodedFieldNames: "bytes" }, }, - } + } as const ); })(), Mixed: (() => { - const tableId = new TableId("mudstore", "Mixed"); return defineComponent( world, { @@ -62,15 +66,22 @@ export function defineContractComponents(world: World) { s: RecsType.String, }, { + id: "0x6d756473746f726500000000000000004d697865640000000000000000000000", metadata: { - contractId: tableId.toHex(), - tableId: tableId.toString(), + componentName: "Mixed", + tableName: "mudstore:Mixed", + keySchema: { key: "bytes32" }, + valueSchema: { + u32: "uint32", + u128: "uint128", + a32: "uint32[]", + s: "string", + }, }, - } + } as const ); })(), Vector2: (() => { - const tableId = new TableId("mudstore", "Vector2"); return defineComponent( world, { @@ -78,26 +89,38 @@ export function defineContractComponents(world: World) { y: RecsType.Number, }, { + id: "0x6d756473746f72650000000000000000566563746f7232000000000000000000", metadata: { - contractId: tableId.toHex(), - tableId: tableId.toString(), + componentName: "Vector2", + tableName: "mudstore:Vector2", + keySchema: { key: "bytes32" }, + valueSchema: { x: "uint32", y: "uint32" }, }, - } + } as const ); })(), KeyEncoding: (() => { - const tableId = new TableId("mudstore", "KeyEncoding"); return defineComponent( world, { value: RecsType.Boolean, }, { + id: "0x6d756473746f726500000000000000004b6579456e636f64696e670000000000", metadata: { - contractId: tableId.toHex(), - tableId: tableId.toString(), + componentName: "KeyEncoding", + tableName: "mudstore:KeyEncoding", + keySchema: { + k1: "uint256", + k2: "int32", + k3: "bytes16", + k4: "address", + k5: "bool", + k6: "uint8", + }, + valueSchema: { value: "bool" }, }, - } + } as const ); })(), }; diff --git a/packages/std-client/src/mud-definitions/world/contractComponents.ts b/packages/std-client/src/mud-definitions/world/contractComponents.ts index 84d3e5457e..f697d8a359 100644 --- a/packages/std-client/src/mud-definitions/world/contractComponents.ts +++ b/packages/std-client/src/mud-definitions/world/contractComponents.ts @@ -1,57 +1,61 @@ /* Autogenerated file. Do not edit manually. */ -import { TableId } from "@latticexyz/common"; import { defineComponent, Type as RecsType, World } from "@latticexyz/recs"; export function defineContractComponents(world: World) { return { NamespaceOwner: (() => { - const tableId = new TableId("", "NamespaceOwner"); return defineComponent( world, { owner: RecsType.String, }, { + id: "0x000000000000000000000000000000004e616d6573706163654f776e65720000", metadata: { - contractId: tableId.toHex(), - tableId: tableId.toString(), + componentName: "NamespaceOwner", + tableName: ":NamespaceOwner", + keySchema: { namespace: "bytes16" }, + valueSchema: { owner: "address" }, }, - } + } as const ); })(), ResourceAccess: (() => { - const tableId = new TableId("", "ResourceAccess"); return defineComponent( world, { access: RecsType.Boolean, }, { + id: "0x000000000000000000000000000000005265736f757263654163636573730000", metadata: { - contractId: tableId.toHex(), - tableId: tableId.toString(), + componentName: "ResourceAccess", + tableName: ":ResourceAccess", + keySchema: { resourceSelector: "bytes32", caller: "address" }, + valueSchema: { access: "bool" }, }, - } + } as const ); })(), InstalledModules: (() => { - const tableId = new TableId("", "InstalledModules"); return defineComponent( world, { moduleAddress: RecsType.String, }, { + id: "0x00000000000000000000000000000000496e7374616c6c65644d6f64756c6573", metadata: { - contractId: tableId.toHex(), - tableId: tableId.toString(), + componentName: "InstalledModules", + tableName: ":InstalledModules", + keySchema: { moduleName: "bytes16", argumentsHash: "bytes32" }, + valueSchema: { moduleAddress: "address" }, }, - } + } as const ); })(), Systems: (() => { - const tableId = new TableId("", "Systems"); return defineComponent( world, { @@ -59,60 +63,68 @@ export function defineContractComponents(world: World) { publicAccess: RecsType.Boolean, }, { + id: "0x0000000000000000000000000000000053797374656d73000000000000000000", metadata: { - contractId: tableId.toHex(), - tableId: tableId.toString(), + componentName: "Systems", + tableName: ":Systems", + keySchema: { resourceSelector: "bytes32" }, + valueSchema: { system: "address", publicAccess: "bool" }, }, - } + } as const ); })(), SystemRegistry: (() => { - const tableId = new TableId("", "SystemRegistry"); return defineComponent( world, { resourceSelector: RecsType.String, }, { + id: "0x0000000000000000000000000000000053797374656d52656769737472790000", metadata: { - contractId: tableId.toHex(), - tableId: tableId.toString(), + componentName: "SystemRegistry", + tableName: ":SystemRegistry", + keySchema: { system: "address" }, + valueSchema: { resourceSelector: "bytes32" }, }, - } + } as const ); })(), SystemHooks: (() => { - const tableId = new TableId("", "SystemHooks"); return defineComponent( world, { value: RecsType.StringArray, }, { + id: "0x0000000000000000000000000000000053797374656d486f6f6b730000000000", metadata: { - contractId: tableId.toHex(), - tableId: tableId.toString(), + componentName: "SystemHooks", + tableName: ":SystemHooks", + keySchema: { resourceSelector: "bytes32" }, + valueSchema: { value: "address[]" }, }, - } + } as const ); })(), ResourceType: (() => { - const tableId = new TableId("", "ResourceType"); return defineComponent( world, { resourceType: RecsType.Number, }, { + id: "0x000000000000000000000000000000005265736f757263655479706500000000", metadata: { - contractId: tableId.toHex(), - tableId: tableId.toString(), + componentName: "ResourceType", + tableName: ":ResourceType", + keySchema: { resourceSelector: "bytes32" }, + valueSchema: { resourceType: "uint8" }, }, - } + } as const ); })(), FunctionSelectors: (() => { - const tableId = new TableId("", "FunctionSelector"); return defineComponent( world, { @@ -121,15 +133,21 @@ export function defineContractComponents(world: World) { systemFunctionSelector: RecsType.String, }, { + id: "0x0000000000000000000000000000000046756e6374696f6e53656c6563746f72", metadata: { - contractId: tableId.toHex(), - tableId: tableId.toString(), + componentName: "FunctionSelector", + tableName: ":FunctionSelector", + keySchema: { functionSelector: "bytes4" }, + valueSchema: { + namespace: "bytes16", + name: "bytes16", + systemFunctionSelector: "bytes4", + }, }, - } + } as const ); })(), KeysInTable: (() => { - const tableId = new TableId("", "KeysInTable"); return defineComponent( world, { @@ -140,15 +158,23 @@ export function defineContractComponents(world: World) { keys4: RecsType.StringArray, }, { + id: "0x000000000000000000000000000000004b657973496e5461626c650000000000", metadata: { - contractId: tableId.toHex(), - tableId: tableId.toString(), + componentName: "KeysInTable", + tableName: ":KeysInTable", + keySchema: { sourceTable: "bytes32" }, + valueSchema: { + keys0: "bytes32[]", + keys1: "bytes32[]", + keys2: "bytes32[]", + keys3: "bytes32[]", + keys4: "bytes32[]", + }, }, - } + } as const ); })(), UsedKeysIndex: (() => { - const tableId = new TableId("", "UsedKeysIndex"); return defineComponent( world, { @@ -156,11 +182,14 @@ export function defineContractComponents(world: World) { index: RecsType.Number, }, { + id: "0x00000000000000000000000000000000557365644b657973496e646578000000", metadata: { - contractId: tableId.toHex(), - tableId: tableId.toString(), + componentName: "UsedKeysIndex", + tableName: ":UsedKeysIndex", + keySchema: { sourceTable: "bytes32", keysHash: "bytes32" }, + valueSchema: { has: "bool", index: "uint40" }, }, - } + } as const ); })(), }; diff --git a/packages/std-client/src/setup/setupMUDV2Network.ts b/packages/std-client/src/setup/setupMUDV2Network.ts index aa666426c3..50d45b89a4 100644 --- a/packages/std-client/src/setup/setupMUDV2Network.ts +++ b/packages/std-client/src/setup/setupMUDV2Network.ts @@ -107,11 +107,12 @@ export async function setupMUDV2Network; +export type ContractComponent = Component; export type ContractComponents = { [key: string]: ContractComponent; diff --git a/packages/std-client/src/systems/ActionSystem/createActionSystem.ts b/packages/std-client/src/systems/ActionSystem/createActionSystem.ts index a2818209da..f1e89f5b89 100644 --- a/packages/std-client/src/systems/ActionSystem/createActionSystem.ts +++ b/packages/std-client/src/systems/ActionSystem/createActionSystem.ts @@ -20,7 +20,7 @@ import { merge, Observable } from "rxjs"; export type ActionSystem = ReturnType; -export function createActionSystem(world: World, txReduced$: Observable) { +export function createActionSystem(world: World, txReduced$: Observable) { // Action component const Action = defineActionComponent(world); diff --git a/packages/std-client/src/systems/ActionSystem/types.ts b/packages/std-client/src/systems/ActionSystem/types.ts index 30099f0de4..20a24edbcc 100644 --- a/packages/std-client/src/systems/ActionSystem/types.ts +++ b/packages/std-client/src/systems/ActionSystem/types.ts @@ -10,7 +10,7 @@ export type ComponentUpdate = ValueOf<{ }; }>; -export type ActionRequest = { +export type ActionRequest = { // Identifier of this action. Will be used as entity id of the Action component. id: string; @@ -47,7 +47,7 @@ export type ActionRequest = { metadata?: M; }; -export type ActionData = ActionRequest & { +export type ActionData = ActionRequest & { componentsWithOptimisticUpdates: Components; entity: Entity; }; diff --git a/templates/phaser/packages/client/src/mud/contractComponents.ts b/templates/phaser/packages/client/src/mud/contractComponents.ts index 3c11df6aad..943b86184e 100644 --- a/templates/phaser/packages/client/src/mud/contractComponents.ts +++ b/templates/phaser/packages/client/src/mud/contractComponents.ts @@ -1,23 +1,24 @@ /* Autogenerated file. Do not edit manually. */ -import { TableId } from "@latticexyz/common"; import { defineComponent, Type as RecsType, World } from "@latticexyz/recs"; export function defineContractComponents(world: World) { return { Counter: (() => { - const tableId = new TableId("", "Counter"); return defineComponent( world, { value: RecsType.Number, }, { + id: "0x00000000000000000000000000000000436f756e746572000000000000000000", metadata: { - contractId: tableId.toHex(), - tableId: tableId.toString(), + componentName: "Counter", + tableName: ":Counter", + keySchema: {}, + valueSchema: { value: "uint32" }, }, - } + } as const ); })(), }; diff --git a/templates/react/packages/client/src/mud/contractComponents.ts b/templates/react/packages/client/src/mud/contractComponents.ts index 3c11df6aad..943b86184e 100644 --- a/templates/react/packages/client/src/mud/contractComponents.ts +++ b/templates/react/packages/client/src/mud/contractComponents.ts @@ -1,23 +1,24 @@ /* Autogenerated file. Do not edit manually. */ -import { TableId } from "@latticexyz/common"; import { defineComponent, Type as RecsType, World } from "@latticexyz/recs"; export function defineContractComponents(world: World) { return { Counter: (() => { - const tableId = new TableId("", "Counter"); return defineComponent( world, { value: RecsType.Number, }, { + id: "0x00000000000000000000000000000000436f756e746572000000000000000000", metadata: { - contractId: tableId.toHex(), - tableId: tableId.toString(), + componentName: "Counter", + tableName: ":Counter", + keySchema: {}, + valueSchema: { value: "uint32" }, }, - } + } as const ); })(), }; diff --git a/templates/threejs/packages/client/src/mud/contractComponents.ts b/templates/threejs/packages/client/src/mud/contractComponents.ts index b851f08579..40e0720d05 100644 --- a/templates/threejs/packages/client/src/mud/contractComponents.ts +++ b/templates/threejs/packages/client/src/mud/contractComponents.ts @@ -1,12 +1,10 @@ /* Autogenerated file. Do not edit manually. */ -import { TableId } from "@latticexyz/common"; import { defineComponent, Type as RecsType, World } from "@latticexyz/recs"; export function defineContractComponents(world: World) { return { Position: (() => { - const tableId = new TableId("", "Position"); return defineComponent( world, { @@ -15,11 +13,14 @@ export function defineContractComponents(world: World) { z: RecsType.Number, }, { + id: "0x00000000000000000000000000000000506f736974696f6e0000000000000000", metadata: { - contractId: tableId.toHex(), - tableId: tableId.toString(), + componentName: "Position", + tableName: ":Position", + keySchema: { key: "bytes32" }, + valueSchema: { x: "int32", y: "int32", z: "int32" }, }, - } + } as const ); })(), }; diff --git a/templates/vanilla/packages/client/src/mud/contractComponents.ts b/templates/vanilla/packages/client/src/mud/contractComponents.ts index 3c11df6aad..943b86184e 100644 --- a/templates/vanilla/packages/client/src/mud/contractComponents.ts +++ b/templates/vanilla/packages/client/src/mud/contractComponents.ts @@ -1,23 +1,24 @@ /* Autogenerated file. Do not edit manually. */ -import { TableId } from "@latticexyz/common"; import { defineComponent, Type as RecsType, World } from "@latticexyz/recs"; export function defineContractComponents(world: World) { return { Counter: (() => { - const tableId = new TableId("", "Counter"); return defineComponent( world, { value: RecsType.Number, }, { + id: "0x00000000000000000000000000000000436f756e746572000000000000000000", metadata: { - contractId: tableId.toHex(), - tableId: tableId.toString(), + componentName: "Counter", + tableName: ":Counter", + keySchema: {}, + valueSchema: { value: "uint32" }, }, - } + } as const ); })(), };