diff --git a/docs/pages/client-side.mdx b/docs/pages/client-side.mdx index 287cd1b9393..fc73319ed16 100644 --- a/docs/pages/client-side.mdx +++ b/docs/pages/client-side.mdx @@ -24,7 +24,7 @@ const config = mudConfig({ tables: { NameComponent: "string", PlayerComponent: "bool", - PositionComponent: { schema: { x: "int32", y: "int32" } }, + PositionComponent: { valueSchema: { x: "int32", y: "int32" } }, }, }); ``` diff --git a/docs/pages/ecs.mdx b/docs/pages/ecs.mdx index 03fe09b6119..0f855a5da71 100644 --- a/docs/pages/ecs.mdx +++ b/docs/pages/ecs.mdx @@ -19,7 +19,7 @@ export default mudConfig({ tables: { PlayerComponent: "bool", PositionComponent: { - schema: { x: "int32", y: "int32" }, + valueSchema: { x: "int32", y: "int32" }, }, NameComponent: "string", DamageComponent: uint256, diff --git a/docs/pages/quick-start.mdx b/docs/pages/quick-start.mdx index e03fe5a60bf..e8251e0f6f5 100644 --- a/docs/pages/quick-start.mdx +++ b/docs/pages/quick-start.mdx @@ -81,7 +81,7 @@ export default mudConfig({ tables: { Counter: { keySchema: {}, - schema: "uint32", + valueSchema: "uint32", }, }, }); @@ -117,7 +117,7 @@ contract IncrementSystem is System { } ``` -The increment system is able to import `Counter` (from its autogenerated table schema) and operate on it by increasing its value by one. +The increment system is able to import `Counter` (from its autogenerated table library) and operate on it by increasing its value by one. Each system can contain any number of methods, though this system only has the single method—`increment`. These methods can then be called in the client to execute them in a transaction. @@ -127,7 +127,6 @@ The client package will vary depending on which template used (vanilla, react, p - You can adjust `createClientComponents.ts` to either override contract components or add client-only components. - If you are using chains other than foundry/anvil and lattice testnet, you can add them in `getNetworkConfig.ts` -- `createSystemCalls` represents how the client talks to the system contracts via our `worldSend` helper - `setup.ts` Beyond these files you can concern yourself simply with building out the frontend of the client. @@ -136,13 +135,13 @@ Beyond these files you can concern yourself simply with building out the fronten Now that you’re familiar with the basic structure of the client package, let’s go over how you can call on systems from the contracts package. -The starter project comes with `IncrementSystem.sol`—you can see it being called in `index.ts` (or `index.tsx` in the react template). +The starter project comes with `IncrementSystem.sol`—you can see it being called in `index.ts` (or `App.tsx` in the react template). ```tsx // Just for demonstration purposes: we create a global function that can be // called to invoke the Increment system contract via the world. (See IncrementSystem.sol.) (window as any).increment = async () => { - const tx = await worldSend("increment", []); + const tx = await worldContract.write.increment(); console.log("increment tx", tx); console.log("increment result", await tx.wait()); diff --git a/docs/pages/store/advanced-features.mdx b/docs/pages/store/advanced-features.mdx index e3ff1efea97..1a859967df6 100644 --- a/docs/pages/store/advanced-features.mdx +++ b/docs/pages/store/advanced-features.mdx @@ -17,7 +17,7 @@ export default mudConfig({ tables: { CounterSingleton: { keySchema: {}, - schema: "uint256", + valueSchema: "uint256", }, }, }); @@ -48,7 +48,7 @@ import { mudConfig } from "@latticexyz/store/register"; export default mudConfig({ tables: { TradeExecuted: { - schema: { + valueSchema: { amount: "uint32", receiver: "bytes32", }, @@ -84,8 +84,8 @@ uint256 constant indexerTableId = uint256(keccak256("indexer.table")); contract MirrorSubscriber is IStoreHook { uint256 _table; - constructor(uint256 table, Schema schema, Schema keySchema) { - IStore(msg.sender).registerSchema(indexerTableId, schema, keySchema); + constructor(uint256 table, Schema keySchema, Schema valueSchema) { + IStore(msg.sender).registerSchema(indexerTableId, valueSchema, keySchema); _table = table; } @@ -110,9 +110,9 @@ Registering the hook can be done using the low-level Store API: ```solidity uint256 table = keccak256("table"); -Schema schema = SchemaLib.encode(SchemaType.UINT256, SchemaType.UINT256); +Schema valueSchema = SchemaLib.encode(SchemaType.UINT256, SchemaType.UINT256); Schema keySchema = SchemaLib.encode(SchemaType.UINT256); -MirrorSubscriber subscriber = new MirrorSubscriber(table, schema, keySchema); +MirrorSubscriber subscriber = new MirrorSubscriber(table, keySchema, valueSchema); StoreCore.registerStoreHook(table, subscriber); ``` diff --git a/docs/pages/store/config.mdx b/docs/pages/store/config.mdx index 386ac9e79b7..36eacbcbdd3 100644 --- a/docs/pages/store/config.mdx +++ b/docs/pages/store/config.mdx @@ -46,7 +46,7 @@ import { mudConfig } from "@latticexyz/store/register"; export default mudConfig({ tables: { MyTable: { - schema: { + valueSchema: { value: "uint32", }, }, @@ -62,7 +62,7 @@ The table configuration can have these properties: **`fileSelector` (optional)** _only used with the World framework_: a `string`: where to create the table in the namespace. -**`tableIdArgument` (optional)**: `bool`: whether to create getter and setter functions with the table ID as an argument, this is used to generate a single library to operate on multiple tables with the same schema and key structure. +**`tableIdArgument` (optional)**: `bool`: whether to create getter and setter functions with the table ID as an argument, this is used to generate a single library to operate on multiple tables with the same key and value structure. **`storeArgument` (optional)**: `bool`: whether to create getter and setter functions with the store address as an argument, this is used to generate a single library to operate on the same table in multiple stores. This adds new functions to the library, doubling the amount of functions created (each getter/setter will comes in a pair of “with `storeArgument`” and “without `storeArgument`”) @@ -86,7 +86,7 @@ Example: ```tsx tables: { MyTableWithTwoKeys: { - schema: { + valueSchema: { value1: "uint32", value2: "uint32", }, @@ -98,14 +98,14 @@ tables: { } ``` -**`schema` (required)**: an object with keys being the column name, and value being types from `SchemaType` +**`valueSchema` (required)**: an object with keys being the column name, and value being types from `SchemaType` Example: ```tsx tables: { MyTableWithFourValues: { - schema: { + valueSchema: { x: "uint32", y: "uint32", stringField: "string", @@ -135,7 +135,7 @@ Example: ```tsx tables: { MySingletonTable: { - schema: { + valueSchema: { value1: "uint32", value2: "uint32", }, diff --git a/docs/pages/store/reading-and-writing.mdx b/docs/pages/store/reading-and-writing.mdx index 229a678f4bc..a2471147c28 100644 --- a/docs/pages/store/reading-and-writing.mdx +++ b/docs/pages/store/reading-and-writing.mdx @@ -21,7 +21,7 @@ This section assumes the existence of “MyTable” as described with the config // definition of MyTable tables: { MyTable: { - schema: { + valueSchema: { foo: "uint256", bar: "bool", fooArray: "uint256[]", // Store supports dynamic arrays @@ -106,7 +106,7 @@ This section assumes the existence of “MyTable” as described with the config // definition of MyTable tables: { MyTable: { - schema: { + valueSchema: { foo: "uint256", bar: "bool", }, @@ -147,8 +147,8 @@ uint256 tableId = uint256(keccak256("MyTable")); bytes32[] memory key = new bytes32[](1); key[0] = keccak256("some.key"); // Retrieve a record -Schema schema = SchemaLib.encode(SchemaType.UINT256, SchemaType.UINT256); -bytes memory loadedData = StoreCore.getRecord(tableId, key, schema); +Schema valueSchema = SchemaLib.encode(SchemaType.UINT256, SchemaType.UINT256); +bytes memory loadedData = StoreCore.getRecord(tableId, key, valueSchema); uint256 foo = (uint256(Bytes.slice4(loadedData, 0))); uint256 bar = (uint256(Bytes.slice4(loadedData, 32))); ``` diff --git a/docs/pages/store/using-without-world.mdx b/docs/pages/store/using-without-world.mdx index 497f389adf9..c1fc921b73a 100644 --- a/docs/pages/store/using-without-world.mdx +++ b/docs/pages/store/using-without-world.mdx @@ -42,7 +42,7 @@ import { mudConfig } from "@latticexyz/store/register"; export default mudConfig({ tables: { MyTable: { - schema: { + valueSchema: { field1: "uint256", field2: "uint256", }, @@ -78,18 +78,25 @@ contract Contract is Store { ```solidity import { Store } from "@latticexyz/store/src/Store.sol"; import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; contract Contract is Store { constructor() { + bytes32 tableId = bytes32("MyTable"); + + FieldLayout fieldLayout = FieldLayoutLib.encode(32, 32); Schema keySchema = SchemaLib.encode(SchemaType.UINT256); - Schema schema = SchemaLib.encode(SchemaType.UINT256, SchemaType.UINT256); - uint256 table = uint256(keccak256("MyTable")); - StoreCore.registerSchema(table, schema, keySchema); - // Setting metadata is optional. It helps off-chain actors name columns + Schema valueSchema = SchemaLib.encode(SchemaType.UINT256, SchemaType.UINT256); + + string[] memory keyNames = new string[](1); + keyNames[0] = "field1"; + string[] memory fieldNames = new string[](2); fieldNames[0] = "field1"; fieldNames[1] = "field2"; - StoreSwitch.setMetadata(table, "MyTable", fieldNames); + + StoreCore.registerTable(tableId, fieldLayout, keySchema, valueSchema, keyNames, fieldNames); } } ``` diff --git a/docs/pages/tutorials/emojimon/a-wild-emojimon-appears.mdx b/docs/pages/tutorials/emojimon/a-wild-emojimon-appears.mdx index 633dbb113e9..2972511adce 100644 --- a/docs/pages/tutorials/emojimon/a-wild-emojimon-appears.mdx +++ b/docs/pages/tutorials/emojimon/a-wild-emojimon-appears.mdx @@ -46,7 +46,7 @@ export default mudConfig({ keySchema: { player: "bytes32", }, - schema: { + valueSchema: { exists: "bool", monster: "bytes32", catchAttempts: "uint256", @@ -57,7 +57,7 @@ export default mudConfig({ MapConfig: { keySchema: {}, dataStruct: false, - schema: { + valueSchema: { width: "uint32", height: "uint32", terrain: "bytes", @@ -68,7 +68,7 @@ export default mudConfig({ Player: "bool", Position: { dataStruct: false, - schema: { + valueSchema: { x: "uint32", y: "uint32", }, @@ -523,7 +523,7 @@ export default mudConfig({ keySchema: { player: "bytes32", }, - schema: { + valueSchema: { exists: "bool", monster: "bytes32", catchAttempts: "uint256", @@ -534,7 +534,7 @@ export default mudConfig({ MapConfig: { keySchema: {}, dataStruct: false, - schema: { + valueSchema: { width: "uint32", height: "uint32", terrain: "bytes", @@ -546,7 +546,7 @@ export default mudConfig({ Player: "bool", Position: { dataStruct: false, - schema: { + valueSchema: { x: "uint32", y: "uint32", }, @@ -749,7 +749,7 @@ export default mudConfig({ keySchema: { player: "bytes32", }, - schema: { + valueSchema: { exists: "bool", monster: "bytes32", catchAttempts: "uint256", @@ -760,7 +760,7 @@ export default mudConfig({ MapConfig: { keySchema: {}, dataStruct: false, - schema: { + valueSchema: { width: "uint32", height: "uint32", terrain: "bytes", @@ -772,7 +772,7 @@ export default mudConfig({ keySchema: { encounter: "bytes32", }, - schema: { + valueSchema: { result: "MonsterCatchResult", }, }, @@ -783,7 +783,7 @@ export default mudConfig({ Player: "bool", Position: { dataStruct: false, - schema: { + valueSchema: { x: "uint32", y: "uint32", }, diff --git a/docs/pages/tutorials/emojimon/map-and-terrain.mdx b/docs/pages/tutorials/emojimon/map-and-terrain.mdx index 7d57928e29b..d2f8b5e6436 100644 --- a/docs/pages/tutorials/emojimon/map-and-terrain.mdx +++ b/docs/pages/tutorials/emojimon/map-and-terrain.mdx @@ -27,7 +27,7 @@ export default mudConfig({ MapConfig: { keySchema: {}, dataStruct: false, - schema: { + valueSchema: { width: "uint32", height: "uint32", terrain: "bytes", @@ -37,7 +37,7 @@ export default mudConfig({ Player: "bool", Position: { dataStruct: false, - schema: { + valueSchema: { x: "uint32", y: "uint32", }, @@ -205,7 +205,7 @@ export default mudConfig({ MapConfig: { keySchema: {}, dataStruct: false, - schema: { + valueSchema: { width: "uint32", height: "uint32", terrain: "bytes", @@ -216,7 +216,7 @@ export default mudConfig({ Player: "bool", Position: { dataStruct: false, - schema: { + valueSchema: { x: "uint32", y: "uint32", }, diff --git a/docs/pages/tutorials/emojimon/players-and-movement.mdx b/docs/pages/tutorials/emojimon/players-and-movement.mdx index acb1703a84c..e17c7ffd943 100644 --- a/docs/pages/tutorials/emojimon/players-and-movement.mdx +++ b/docs/pages/tutorials/emojimon/players-and-movement.mdx @@ -16,7 +16,7 @@ We're going to start by defining three new tables: 1. `Player: 'bool'` → determine which entities are players (e.g. distinct wallet addresses) 2. `Movable: 'bool'` → determine whether or not an entity can move -3. `Position: { schema: { x: 'uint32', y: 'uint32' } }` → determine which position an entity is located on a 2D grid +3. `Position: { valueSchema: { x: 'uint32', y: 'uint32' } }` → determine which position an entity is located on a 2D grid The syntax is as follows: @@ -34,7 +34,7 @@ export default mudConfig({ Player: "bool", Position: { dataStruct: false, - schema: { + valueSchema: { x: "uint32", y: "uint32", }, diff --git a/docs/pages/tutorials/minimal/add-table.mdx b/docs/pages/tutorials/minimal/add-table.mdx index 39a35466a70..800f9b0267d 100644 --- a/docs/pages/tutorials/minimal/add-table.mdx +++ b/docs/pages/tutorials/minimal/add-table.mdx @@ -22,13 +22,13 @@ For the sake of simplicity, we will implement this in the `increment` function r tables: { Counter: { keySchema: {}, - schema: "uint32", + valueSchema: "uint32", }, History: { keySchema: { counterValue: "uint32", }, - schema: { + valueSchema: { blockNumber: "uint256", time: "uint256", }, @@ -45,7 +45,7 @@ For the sake of simplicity, we will implement this in the `increment` function r A MUD table has two schemas: - `keySchema`, the key used to find entries -- `schema`, the value in the entry (soon to be renamed to `valueSchema`) +- `valueSchema`, the value in the entry Each schema is represented as a structure with field names as keys, and the appropriate [Solidity data types](https://docs.soliditylang.org/en/latest/types.html) as their values. diff --git a/docs/pages/tutorials/walkthrough/minimal-onchain.mdx b/docs/pages/tutorials/walkthrough/minimal-onchain.mdx index 2cdb489d950..10cb2606058 100644 --- a/docs/pages/tutorials/walkthrough/minimal-onchain.mdx +++ b/docs/pages/tutorials/walkthrough/minimal-onchain.mdx @@ -29,13 +29,13 @@ export default mudConfig({ tables: { Counter: { keySchema: {}, - schema: "uint32", + valueSchema: "uint32", }, Users: { keySchema: { user: "address", }, - schema: { + valueSchema: { score: "uint32", name: "string", }, @@ -128,18 +128,18 @@ The default namespace is empty. ```solidity library Counter { - /** Get the table's schema */ - function getSchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](1); - _schema[0] = SchemaType.UINT32; + /** Get the table's value schema */ + function getValueSchema() internal pure returns (Schema) { + SchemaType[] memory _valueSchema = new SchemaType[](1); + _valueSchema[0] = SchemaType.UINT32; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_valueSchema); } function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](0); + SchemaType[] memory _keySchema = new SchemaType[](0); - return SchemaLib.encode(_schema); + return SchemaLib.encode(_keySchema); } ``` diff --git a/docs/pages/what-is-mud.mdx b/docs/pages/what-is-mud.mdx index 6f277d92e85..0a5e09b9b76 100644 --- a/docs/pages/what-is-mud.mdx +++ b/docs/pages/what-is-mud.mdx @@ -57,7 +57,7 @@ Allowance: { from: "address", to: "address", }, - schema: { + valueSchema: { amount: "uint256", }, } diff --git a/docs/pages/world/config.mdx b/docs/pages/world/config.mdx index e5af9a8bbe0..ae021458b6a 100644 --- a/docs/pages/world/config.mdx +++ b/docs/pages/world/config.mdx @@ -29,7 +29,7 @@ export default mudConfig({ }, tables: { CounterTable: { - schema: { + valueSchema: { value: "uint32", }, }, diff --git a/docs/pages/world/modules.mdx b/docs/pages/world/modules.mdx index 86b4b44dd6c..5ae80689bb8 100644 --- a/docs/pages/world/modules.mdx +++ b/docs/pages/world/modules.mdx @@ -96,7 +96,7 @@ Using `getKeysWithValue` to retrieve all NFTs owned by a specific address: ```solidity // assumes this ownership table: // Owners: { -// schema: "address", +// valueSchema: "address", // keySchema: { nftId: "uint256" } // } import { getKeysWithValue } from "@latticexyz/world/src/modules/keyswithvalue/getKeysWithValue.sol"; @@ -157,7 +157,7 @@ import { resolveTableId } from "@latticexyz/config"; export default mudConfig({ tables: { MyTable: { - schema: "uint32", + valueSchema: "uint32", }, }, modules: [ diff --git a/docs/pages/world/querying.mdx b/docs/pages/world/querying.mdx index 2cbe89a6217..0a3cc1a53af 100644 --- a/docs/pages/world/querying.mdx +++ b/docs/pages/world/querying.mdx @@ -19,7 +19,7 @@ import { mudConfig } from "@latticexyz/world/register"; export default mudConfig({ tables: { Player: "bool", - Position: { schema: { x: "int32", y: "int32" } }, + Position: { valueSchema: { x: "int32", y: "int32" } }, }, }); ``` diff --git a/docs/pages/world/subsystems.mdx b/docs/pages/world/subsystems.mdx index 93e2561876f..a1c2f1a4814 100644 --- a/docs/pages/world/subsystems.mdx +++ b/docs/pages/world/subsystems.mdx @@ -28,11 +28,11 @@ export default mudConfig({ tables: { BalanceTable: { keySchema: { owner: "address"}, - schema: { amount: "uint256" }, + valueSchema: { amount: "uint256" }, }, OwnerTable: { keySchema: { token: "uint256" }, - schema: { owner: "address" }, + valueSchema: { owner: "address" }, }, }, }); diff --git a/docs/pages/world/world-101.mdx b/docs/pages/world/world-101.mdx index bd38836be7d..84a3d247e89 100644 --- a/docs/pages/world/world-101.mdx +++ b/docs/pages/world/world-101.mdx @@ -126,7 +126,7 @@ export default mudConfig({ tables: { Counter: { keySchema: {}, - schema: "uint32", + valueSchema: "uint32", }, }, }); @@ -177,10 +177,10 @@ export default mudConfig({ tables: { Counter: { keySchema: {}, - schema: "uint32", + valueSchema: "uint32", }, Dog: { - schema: { + valueSchema: { owner: "address", name: "string", color: "string",