From 07dd6f32c9bb9f0e807bac3586c5cc9833f14ab9 Mon Sep 17 00:00:00 2001 From: alvarius Date: Fri, 15 Sep 2023 12:15:33 +0100 Subject: [PATCH] feat: rename schema to valueSchema (#1482) Co-authored-by: Kevin Ingersoll --- .changeset/cold-years-itch.md | 25 ++++++++++++ docs/pages/client-side.mdx | 2 +- docs/pages/ecs.mdx | 2 +- docs/pages/quick-start.mdx | 10 ++--- docs/pages/store/advanced-features.mdx | 12 +++--- docs/pages/store/config.mdx | 12 +++--- docs/pages/store/reading-and-writing.mdx | 8 ++-- docs/pages/store/using-without-world.mdx | 19 ++++++--- .../emojimon/a-wild-emojimon-appears.mdx | 20 +++++----- .../tutorials/emojimon/map-and-terrain.mdx | 8 ++-- .../emojimon/players-and-movement.mdx | 4 +- docs/pages/tutorials/minimal/add-table.mdx | 6 +-- .../tutorials/walkthrough/minimal-onchain.mdx | 18 ++++----- docs/pages/what-is-mud.mdx | 2 +- docs/pages/world/config.mdx | 2 +- docs/pages/world/modules.mdx | 4 +- docs/pages/world/querying.mdx | 2 +- docs/pages/world/subsystems.mdx | 4 +- docs/pages/world/world-101.mdx | 6 +-- e2e/packages/contracts/mud.config.ts | 8 ++-- .../contracts/src/codegen/tables/Multi.sol | 20 +++++----- .../contracts/src/codegen/tables/Number.sol | 12 +++--- .../src/codegen/tables/NumberList.sol | 10 ++--- .../contracts/src/codegen/tables/Vector.sol | 14 +++---- e2e/packages/sync-test/data/encodeTestData.ts | 4 +- e2e/packages/sync-test/data/types.ts | 2 +- .../minimal/packages/contracts/mud.config.ts | 6 +-- .../src/codegen/tables/CounterTable.sol | 10 ++--- .../src/codegen/tables/Inventory.sol | 16 ++++---- .../src/codegen/tables/MessageTable.sol | 10 ++--- .../src/codegen/tables/Dynamics1.sol | 22 +++++----- .../src/codegen/tables/Dynamics2.sol | 16 ++++---- .../src/codegen/tables/Ephemeral.sol | 12 +++--- .../src/codegen/tables/Singleton.sol | 16 ++++---- .../contracts/src/codegen/tables/Statics.sol | 38 +++++++++--------- packages/cli/scripts/generate-test-tables.ts | 13 +++--- packages/cli/src/utils/deploy.ts | 6 +-- .../protocol-parser/src/decodeRecord.test.ts | 12 +++--- packages/protocol-parser/src/decodeRecord.ts | 16 ++++---- .../protocol-parser/src/encodeRecord.test.ts | 14 +++---- packages/protocol-parser/src/encodeRecord.ts | 15 ++++--- packages/protocol-parser/src/encodeValue.ts | 2 +- .../protocol-parser/src/hexToPackedCounter.ts | 4 +- .../protocol-parser/src/keySchemaToHex.ts | 4 +- .../protocol-parser/src/valueSchemaToHex.ts | 6 +-- packages/store-sync/src/blockLogsToStorage.ts | 4 +- .../src/postgres/buildInternalTables.ts | 1 - packages/store-sync/src/recs/common.ts | 6 +-- .../src/recs/configToRecsComponents.ts | 4 +- packages/store-sync/src/schemaToDefaults.ts | 4 +- packages/store/gas-report.json | 2 +- packages/store/mud.config.ts | 10 ++--- packages/store/src/IStore.sol | 4 +- packages/store/src/StoreRead.sol | 8 ++-- .../store/src/codegen/tables/Callbacks.sol | 12 +++--- packages/store/src/codegen/tables/Hooks.sol | 12 +++--- .../store/src/codegen/tables/KeyEncoding.sol | 22 +++++----- packages/store/src/codegen/tables/Mixed.sol | 18 ++++----- .../store/src/codegen/tables/StoreHooks.sol | 12 +++--- packages/store/src/codegen/tables/Tables.sol | 22 +++++----- packages/store/src/codegen/tables/Vector2.sol | 14 +++---- packages/store/test/StoreCore.t.sol | 4 +- packages/store/test/StoreCoreDynamic.t.sol | 2 +- packages/store/test/StoreCoreGas.t.sol | 22 +++++----- packages/store/test/tables/StoreHooks.t.sol | 2 +- packages/store/ts/codegen/renderTable.ts | 12 +++--- packages/store/ts/codegen/tableOptions.ts | 8 ++-- packages/store/ts/common.ts | 2 +- packages/store/ts/config/storeConfig.ts | 33 +++++++++------ .../store/ts/register/mudConfig.test-d.ts | 8 ++-- packages/world/mud.config.ts | 40 +++++++++---------- .../StoreRegistrationSystem.sol | 4 +- .../src/modules/core/tables/Balances.sol | 12 +++--- .../modules/core/tables/FunctionSelectors.sol | 14 +++---- .../src/modules/core/tables/ResourceType.sol | 12 +++--- .../src/modules/core/tables/SystemHooks.sol | 12 +++--- .../modules/core/tables/SystemRegistry.sol | 12 +++--- .../world/src/modules/core/tables/Systems.sol | 14 +++---- .../modules/keysintable/getKeysInTable.sol | 13 +++--- .../keysintable/tables/KeysInTable.sol | 22 +++++----- .../keysintable/tables/UsedKeysIndex.sol | 16 ++++---- .../keyswithvalue/tables/KeysWithValue.sol | 12 +++--- .../tables/CallboundDelegations.sol | 18 ++++----- .../tables/TimeboundDelegations.sol | 14 +++---- .../uniqueentity/tables/UniqueEntity.sol | 10 ++--- packages/world/src/tables/Delegations.sol | 14 +++---- .../world/src/tables/InstalledModules.sol | 14 +++---- packages/world/src/tables/NamespaceOwner.sol | 12 +++--- packages/world/src/tables/ResourceAccess.sol | 14 +++---- packages/world/test/tables/AddressArray.sol | 12 +++--- packages/world/test/tables/Bool.sol | 10 ++--- packages/world/ts/register/index.test.ts | 2 +- .../phaser/packages/contracts/mud.config.ts | 2 +- .../contracts/src/codegen/tables/Counter.sol | 10 ++--- .../react/packages/contracts/mud.config.ts | 2 +- .../contracts/src/codegen/tables/Counter.sol | 10 ++--- .../threejs/packages/contracts/mud.config.ts | 2 +- .../contracts/src/codegen/tables/Position.sol | 16 ++++---- .../vanilla/packages/contracts/mud.config.ts | 2 +- .../contracts/src/codegen/tables/Counter.sol | 10 ++--- 100 files changed, 559 insertions(+), 520 deletions(-) create mode 100644 .changeset/cold-years-itch.md diff --git a/.changeset/cold-years-itch.md b/.changeset/cold-years-itch.md new file mode 100644 index 0000000000..b132da0085 --- /dev/null +++ b/.changeset/cold-years-itch.md @@ -0,0 +1,25 @@ +--- +"@latticexyz/cli": major +"@latticexyz/protocol-parser": major +"@latticexyz/store-sync": major +"@latticexyz/store": major +"create-mud": minor +--- + +Renamed all occurrences of `schema` where it is used as "value schema" to `valueSchema` to clearly distinguish it from "key schema". +The only breaking change for users is the change from `schema` to `valueSchema` in `mud.config.ts`. + +```diff +// mud.config.ts +export default mudConfig({ + tables: { + CounterTable: { + keySchema: {}, +- schema: { ++ valueSchema: { + value: "uint32", + }, + }, + } +} +``` diff --git a/docs/pages/client-side.mdx b/docs/pages/client-side.mdx index 287cd1b939..fc73319ed1 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 03fe09b611..0f855a5da7 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 e03fe5a60b..127f62757e 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,7 @@ 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 +- `createSystemCalls` represents how the client talks to the system contracts - `setup.ts` Beyond these files you can concern yourself simply with building out the frontend of the client. @@ -136,13 +136,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 e3ff1efea9..1a859967df 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 386ac9e79b..36eacbcbdd 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 229a678f4b..a2471147c2 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 497f389adf..c1fc921b73 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 633dbb113e..2972511adc 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 7d57928e29..d2f8b5e643 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 acb1703a84..e17c7ffd94 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 39a35466a7..800f9b0267 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 2cdb489d95..10cb260605 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 6f277d92e8..0a5e09b9b7 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 e5af9a8bbe..ae021458b6 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 86b4b44dd6..5ae80689bb 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 2cbe89a621..0a3cc1a53a 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 93e2561876..a1c2f1a481 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 bd38836be7..84a3d247e8 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", diff --git a/e2e/packages/contracts/mud.config.ts b/e2e/packages/contracts/mud.config.ts index 762ce21584..c3da4297c5 100644 --- a/e2e/packages/contracts/mud.config.ts +++ b/e2e/packages/contracts/mud.config.ts @@ -6,7 +6,7 @@ export default mudConfig({ keySchema: { key: "uint32", }, - schema: { + valueSchema: { value: "uint32", }, }, @@ -14,14 +14,14 @@ export default mudConfig({ keySchema: { key: "uint32", }, - schema: { + valueSchema: { x: "int32", y: "int32", }, }, NumberList: { keySchema: {}, - schema: { + valueSchema: { value: "uint32[]", }, }, @@ -32,7 +32,7 @@ export default mudConfig({ c: "uint256", d: "int120", }, - schema: { + valueSchema: { num: "int256", value: "bool", }, diff --git a/e2e/packages/contracts/src/codegen/tables/Multi.sol b/e2e/packages/contracts/src/codegen/tables/Multi.sol index 873f71588f..a634403932 100644 --- a/e2e/packages/contracts/src/codegen/tables/Multi.sol +++ b/e2e/packages/contracts/src/codegen/tables/Multi.sol @@ -38,22 +38,22 @@ library Multi { /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](4); - _schema[0] = SchemaType.UINT32; - _schema[1] = SchemaType.BOOL; - _schema[2] = SchemaType.UINT256; - _schema[3] = SchemaType.INT120; + SchemaType[] memory _keySchema = new SchemaType[](4); + _keySchema[0] = SchemaType.UINT32; + _keySchema[1] = SchemaType.BOOL; + _keySchema[2] = SchemaType.UINT256; + _keySchema[3] = SchemaType.INT120; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_keySchema); } /** Get the table's value schema */ function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](2); - _schema[0] = SchemaType.INT256; - _schema[1] = SchemaType.BOOL; + SchemaType[] memory _valueSchema = new SchemaType[](2); + _valueSchema[0] = SchemaType.INT256; + _valueSchema[1] = SchemaType.BOOL; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_valueSchema); } /** Get the table's key names */ diff --git a/e2e/packages/contracts/src/codegen/tables/Number.sol b/e2e/packages/contracts/src/codegen/tables/Number.sol index 40ac16b6df..01127f809c 100644 --- a/e2e/packages/contracts/src/codegen/tables/Number.sol +++ b/e2e/packages/contracts/src/codegen/tables/Number.sol @@ -32,18 +32,18 @@ library Number { /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](1); - _schema[0] = SchemaType.UINT32; + SchemaType[] memory _keySchema = new SchemaType[](1); + _keySchema[0] = SchemaType.UINT32; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_keySchema); } /** Get the table's value schema */ function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](1); - _schema[0] = SchemaType.UINT32; + SchemaType[] memory _valueSchema = new SchemaType[](1); + _valueSchema[0] = SchemaType.UINT32; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_valueSchema); } /** Get the table's key names */ diff --git a/e2e/packages/contracts/src/codegen/tables/NumberList.sol b/e2e/packages/contracts/src/codegen/tables/NumberList.sol index c3bd7fdaa6..60d34cc507 100644 --- a/e2e/packages/contracts/src/codegen/tables/NumberList.sol +++ b/e2e/packages/contracts/src/codegen/tables/NumberList.sol @@ -31,17 +31,17 @@ library NumberList { /** Get the table's key schema */ 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); } /** Get the table's value schema */ function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](1); - _schema[0] = SchemaType.UINT32_ARRAY; + SchemaType[] memory _valueSchema = new SchemaType[](1); + _valueSchema[0] = SchemaType.UINT32_ARRAY; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_valueSchema); } /** Get the table's key names */ diff --git a/e2e/packages/contracts/src/codegen/tables/Vector.sol b/e2e/packages/contracts/src/codegen/tables/Vector.sol index 5b95bbaaa5..e258fac50c 100644 --- a/e2e/packages/contracts/src/codegen/tables/Vector.sol +++ b/e2e/packages/contracts/src/codegen/tables/Vector.sol @@ -38,19 +38,19 @@ library Vector { /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](1); - _schema[0] = SchemaType.UINT32; + SchemaType[] memory _keySchema = new SchemaType[](1); + _keySchema[0] = SchemaType.UINT32; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_keySchema); } /** Get the table's value schema */ function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](2); - _schema[0] = SchemaType.INT32; - _schema[1] = SchemaType.INT32; + SchemaType[] memory _valueSchema = new SchemaType[](2); + _valueSchema[0] = SchemaType.INT32; + _valueSchema[1] = SchemaType.INT32; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_valueSchema); } /** Get the table's key names */ diff --git a/e2e/packages/sync-test/data/encodeTestData.ts b/e2e/packages/sync-test/data/encodeTestData.ts index c0a6ab9dd5..a433626d61 100644 --- a/e2e/packages/sync-test/data/encodeTestData.ts +++ b/e2e/packages/sync-test/data/encodeTestData.ts @@ -18,9 +18,9 @@ export function encodeTestData(testData: Data) { return encodeAbiParameters([{ type: keyType }], [keyValue]); }); - const encodedValue = encodePacked(Object.values(config.tables[table].schema), Object.values(record.value)); + const encodedValue = encodePacked(Object.values(config.tables[table].valueSchema), Object.values(record.value)); - const encodedValueSchema = schemaToHex(abiTypesToSchema(Object.values(config.tables[table].schema))); + const encodedValueSchema = schemaToHex(abiTypesToSchema(Object.values(config.tables[table].valueSchema))); return { key: encodedKey, diff --git a/e2e/packages/sync-test/data/types.ts b/e2e/packages/sync-test/data/types.ts index 4ab5dab4ed..85abd2c90d 100644 --- a/e2e/packages/sync-test/data/types.ts +++ b/e2e/packages/sync-test/data/types.ts @@ -10,7 +10,7 @@ type Key = SchemaToPrimitive< (typeof config)["tables"][Table]["keySchema"] >; type Value
= SchemaToPrimitive< - (typeof config)["tables"][Table]["schema"] + (typeof config)["tables"][Table]["valueSchema"] >; export type Datum
= { diff --git a/examples/minimal/packages/contracts/mud.config.ts b/examples/minimal/packages/contracts/mud.config.ts index 70d98bb5d6..58cf475496 100644 --- a/examples/minimal/packages/contracts/mud.config.ts +++ b/examples/minimal/packages/contracts/mud.config.ts @@ -16,14 +16,14 @@ export default mudConfig({ tables: { CounterTable: { keySchema: {}, - schema: { + valueSchema: { value: "uint32", }, storeArgument: true, }, MessageTable: { keySchema: {}, - schema: { + valueSchema: { value: "string", }, ephemeral: true, @@ -34,7 +34,7 @@ export default mudConfig({ item: "uint32", itemVariant: "uint32", }, - schema: { amount: "uint32" }, + valueSchema: { amount: "uint32" }, }, }, // KeysWithValue doesn't seem to like singleton keys diff --git a/examples/minimal/packages/contracts/src/codegen/tables/CounterTable.sol b/examples/minimal/packages/contracts/src/codegen/tables/CounterTable.sol index d21d510f08..ed4f112789 100644 --- a/examples/minimal/packages/contracts/src/codegen/tables/CounterTable.sol +++ b/examples/minimal/packages/contracts/src/codegen/tables/CounterTable.sol @@ -32,17 +32,17 @@ library CounterTable { /** Get the table's key schema */ 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); } /** Get the table's value schema */ function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](1); - _schema[0] = SchemaType.UINT32; + SchemaType[] memory _valueSchema = new SchemaType[](1); + _valueSchema[0] = SchemaType.UINT32; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_valueSchema); } /** Get the table's key names */ diff --git a/examples/minimal/packages/contracts/src/codegen/tables/Inventory.sol b/examples/minimal/packages/contracts/src/codegen/tables/Inventory.sol index 65a36496d5..96df3c93dd 100644 --- a/examples/minimal/packages/contracts/src/codegen/tables/Inventory.sol +++ b/examples/minimal/packages/contracts/src/codegen/tables/Inventory.sol @@ -32,20 +32,20 @@ library Inventory { /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](3); - _schema[0] = SchemaType.ADDRESS; - _schema[1] = SchemaType.UINT32; - _schema[2] = SchemaType.UINT32; + SchemaType[] memory _keySchema = new SchemaType[](3); + _keySchema[0] = SchemaType.ADDRESS; + _keySchema[1] = SchemaType.UINT32; + _keySchema[2] = SchemaType.UINT32; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_keySchema); } /** Get the table's value schema */ function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](1); - _schema[0] = SchemaType.UINT32; + SchemaType[] memory _valueSchema = new SchemaType[](1); + _valueSchema[0] = SchemaType.UINT32; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_valueSchema); } /** Get the table's key names */ diff --git a/examples/minimal/packages/contracts/src/codegen/tables/MessageTable.sol b/examples/minimal/packages/contracts/src/codegen/tables/MessageTable.sol index 849483b418..5fe5d13250 100644 --- a/examples/minimal/packages/contracts/src/codegen/tables/MessageTable.sol +++ b/examples/minimal/packages/contracts/src/codegen/tables/MessageTable.sol @@ -31,17 +31,17 @@ library MessageTable { /** Get the table's key schema */ 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); } /** Get the table's value schema */ function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](1); - _schema[0] = SchemaType.STRING; + SchemaType[] memory _valueSchema = new SchemaType[](1); + _valueSchema[0] = SchemaType.STRING; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_valueSchema); } /** Get the table's key names */ diff --git a/packages/cli/contracts/src/codegen/tables/Dynamics1.sol b/packages/cli/contracts/src/codegen/tables/Dynamics1.sol index 177f030fde..368c3b73f4 100644 --- a/packages/cli/contracts/src/codegen/tables/Dynamics1.sol +++ b/packages/cli/contracts/src/codegen/tables/Dynamics1.sol @@ -39,22 +39,22 @@ library Dynamics1 { /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](1); - _schema[0] = SchemaType.BYTES32; + SchemaType[] memory _keySchema = new SchemaType[](1); + _keySchema[0] = SchemaType.BYTES32; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_keySchema); } /** Get the table's value schema */ function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](5); - _schema[0] = SchemaType.BYTES32_ARRAY; - _schema[1] = SchemaType.INT32_ARRAY; - _schema[2] = SchemaType.UINT128_ARRAY; - _schema[3] = SchemaType.ADDRESS_ARRAY; - _schema[4] = SchemaType.BOOL_ARRAY; - - return SchemaLib.encode(_schema); + SchemaType[] memory _valueSchema = new SchemaType[](5); + _valueSchema[0] = SchemaType.BYTES32_ARRAY; + _valueSchema[1] = SchemaType.INT32_ARRAY; + _valueSchema[2] = SchemaType.UINT128_ARRAY; + _valueSchema[3] = SchemaType.ADDRESS_ARRAY; + _valueSchema[4] = SchemaType.BOOL_ARRAY; + + return SchemaLib.encode(_valueSchema); } /** Get the table's key names */ diff --git a/packages/cli/contracts/src/codegen/tables/Dynamics2.sol b/packages/cli/contracts/src/codegen/tables/Dynamics2.sol index 7b9dfd6f1a..3bcbe30cd3 100644 --- a/packages/cli/contracts/src/codegen/tables/Dynamics2.sol +++ b/packages/cli/contracts/src/codegen/tables/Dynamics2.sol @@ -37,20 +37,20 @@ library Dynamics2 { /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](1); - _schema[0] = SchemaType.BYTES32; + SchemaType[] memory _keySchema = new SchemaType[](1); + _keySchema[0] = SchemaType.BYTES32; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_keySchema); } /** Get the table's value schema */ function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](3); - _schema[0] = SchemaType.UINT64_ARRAY; - _schema[1] = SchemaType.STRING; - _schema[2] = SchemaType.BYTES; + SchemaType[] memory _valueSchema = new SchemaType[](3); + _valueSchema[0] = SchemaType.UINT64_ARRAY; + _valueSchema[1] = SchemaType.STRING; + _valueSchema[2] = SchemaType.BYTES; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_valueSchema); } /** Get the table's key names */ diff --git a/packages/cli/contracts/src/codegen/tables/Ephemeral.sol b/packages/cli/contracts/src/codegen/tables/Ephemeral.sol index 61225beb79..0f9cec20cc 100644 --- a/packages/cli/contracts/src/codegen/tables/Ephemeral.sol +++ b/packages/cli/contracts/src/codegen/tables/Ephemeral.sol @@ -32,18 +32,18 @@ library Ephemeral { /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](1); - _schema[0] = SchemaType.BYTES32; + SchemaType[] memory _keySchema = new SchemaType[](1); + _keySchema[0] = SchemaType.BYTES32; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_keySchema); } /** Get the table's value schema */ function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](1); - _schema[0] = SchemaType.UINT256; + SchemaType[] memory _valueSchema = new SchemaType[](1); + _valueSchema[0] = SchemaType.UINT256; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_valueSchema); } /** Get the table's key names */ diff --git a/packages/cli/contracts/src/codegen/tables/Singleton.sol b/packages/cli/contracts/src/codegen/tables/Singleton.sol index 2c8f5b0f95..c309eedd60 100644 --- a/packages/cli/contracts/src/codegen/tables/Singleton.sol +++ b/packages/cli/contracts/src/codegen/tables/Singleton.sol @@ -32,20 +32,20 @@ library Singleton { /** Get the table's key schema */ 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); } /** Get the table's value schema */ function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](4); - _schema[0] = SchemaType.INT256; - _schema[1] = SchemaType.UINT32_ARRAY; - _schema[2] = SchemaType.UINT32_ARRAY; - _schema[3] = SchemaType.UINT32_ARRAY; + SchemaType[] memory _valueSchema = new SchemaType[](4); + _valueSchema[0] = SchemaType.INT256; + _valueSchema[1] = SchemaType.UINT32_ARRAY; + _valueSchema[2] = SchemaType.UINT32_ARRAY; + _valueSchema[3] = SchemaType.UINT32_ARRAY; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_valueSchema); } /** Get the table's key names */ diff --git a/packages/cli/contracts/src/codegen/tables/Statics.sol b/packages/cli/contracts/src/codegen/tables/Statics.sol index e2af928e82..089552188c 100644 --- a/packages/cli/contracts/src/codegen/tables/Statics.sol +++ b/packages/cli/contracts/src/codegen/tables/Statics.sol @@ -51,30 +51,30 @@ library Statics { /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](7); - _schema[0] = SchemaType.UINT256; - _schema[1] = SchemaType.INT32; - _schema[2] = SchemaType.BYTES16; - _schema[3] = SchemaType.ADDRESS; - _schema[4] = SchemaType.BOOL; - _schema[5] = SchemaType.UINT8; - _schema[6] = SchemaType.UINT8; + SchemaType[] memory _keySchema = new SchemaType[](7); + _keySchema[0] = SchemaType.UINT256; + _keySchema[1] = SchemaType.INT32; + _keySchema[2] = SchemaType.BYTES16; + _keySchema[3] = SchemaType.ADDRESS; + _keySchema[4] = SchemaType.BOOL; + _keySchema[5] = SchemaType.UINT8; + _keySchema[6] = SchemaType.UINT8; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_keySchema); } /** Get the table's value schema */ function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](7); - _schema[0] = SchemaType.UINT256; - _schema[1] = SchemaType.INT32; - _schema[2] = SchemaType.BYTES16; - _schema[3] = SchemaType.ADDRESS; - _schema[4] = SchemaType.BOOL; - _schema[5] = SchemaType.UINT8; - _schema[6] = SchemaType.UINT8; - - return SchemaLib.encode(_schema); + SchemaType[] memory _valueSchema = new SchemaType[](7); + _valueSchema[0] = SchemaType.UINT256; + _valueSchema[1] = SchemaType.INT32; + _valueSchema[2] = SchemaType.BYTES16; + _valueSchema[3] = SchemaType.ADDRESS; + _valueSchema[4] = SchemaType.BOOL; + _valueSchema[5] = SchemaType.UINT8; + _valueSchema[6] = SchemaType.UINT8; + + return SchemaLib.encode(_valueSchema); } /** Get the table's key names */ diff --git a/packages/cli/scripts/generate-test-tables.ts b/packages/cli/scripts/generate-test-tables.ts index ec8174f3ee..d7ca0db655 100644 --- a/packages/cli/scripts/generate-test-tables.ts +++ b/packages/cli/scripts/generate-test-tables.ts @@ -1,12 +1,11 @@ import path from "path"; -import { StoreConfig } from "@latticexyz/store"; import { tablegen } from "@latticexyz/store/codegen"; import { mudConfig } from "@latticexyz/world/register"; import { getSrcDirectory } from "@latticexyz/common/foundry"; import { logError } from "../src/utils/errors"; // This config is used only for tests. -// Aside from avoiding `mud.config.mts` in cli package (could cause issues), +// Aside from avoiding `mud.config.ts` in cli package (could cause issues), // this also tests that mudConfig and tablegen can work as standalone functions let config; try { @@ -22,7 +21,7 @@ try { k6: "Enum1", k7: "Enum2", }, - schema: { + valueSchema: { v1: "uint256", v2: "int32", v3: "bytes16", @@ -33,7 +32,7 @@ try { }, }, Dynamics1: { - schema: { + valueSchema: { staticB32: "bytes32[1]", staticI32: "int32[2]", staticU128: "uint128[3]", @@ -42,7 +41,7 @@ try { }, }, Dynamics2: { - schema: { + valueSchema: { u64: "uint64[]", str: "string", b: "bytes", @@ -50,7 +49,7 @@ try { }, Singleton: { keySchema: {}, - schema: { + valueSchema: { v1: "int256", v2: "uint32[2]", v3: "uint32[2]", @@ -59,7 +58,7 @@ try { dataStruct: false, }, Ephemeral: { - schema: "uint256", + valueSchema: "uint256", ephemeral: true, }, }, diff --git a/packages/cli/src/utils/deploy.ts b/packages/cli/src/utils/deploy.ts index e9079dfd39..5ac0bc5bf3 100644 --- a/packages/cli/src/utils/deploy.ts +++ b/packages/cli/src/utils/deploy.ts @@ -147,14 +147,14 @@ export async function deploy( const tableIds: { [tableName: string]: Uint8Array } = {}; promises = [ ...promises, - ...Object.entries(mudConfig.tables).map(async ([tableName, { name, schema, keySchema }]) => { + ...Object.entries(mudConfig.tables).map(async ([tableName, { name, valueSchema, keySchema }]) => { console.log(chalk.blue(`Registering table ${tableName} at ${namespace}/${name}`)); // Store the tableId for later use tableIds[tableName] = toResourceSelector(namespace, name); // Register table - const schemaTypes = Object.values(schema).map((abiOrUserType) => { + const schemaTypes = Object.values(valueSchema).map((abiOrUserType) => { const { schemaType } = resolveAbiOrUserType(abiOrUserType, mudConfig); return schemaType; }); @@ -179,7 +179,7 @@ export async function deploy( encodeSchema(keyTypes), encodeSchema(schemaTypes), Object.keys(keySchema), - Object.keys(schema), + Object.keys(valueSchema), ], confirmations ); diff --git a/packages/protocol-parser/src/decodeRecord.test.ts b/packages/protocol-parser/src/decodeRecord.test.ts index 390dcc6ade..87e357f599 100644 --- a/packages/protocol-parser/src/decodeRecord.test.ts +++ b/packages/protocol-parser/src/decodeRecord.test.ts @@ -3,17 +3,17 @@ import { decodeRecord } from "./decodeRecord"; describe("decodeRecord", () => { it("can decode hex to record values", () => { - const schema = { staticFields: ["uint32", "uint128"], dynamicFields: ["uint32[]", "string"] } as const; + const valueSchema = { staticFields: ["uint32", "uint128"], dynamicFields: ["uint32[]", "string"] } as const; const values = decodeRecord( - schema, + valueSchema, "0x0000000100000000000000000000000000000002000000000000000000000000000000000000000b0000000008000000000000130000000300000004736f6d6520737472696e67" ); expect(values).toStrictEqual([1, 2n, [3, 4], "some string"]); }); it("can decode an empty record", () => { - const schema = { staticFields: [], dynamicFields: ["string", "string"] } as const; - const values = decodeRecord(schema, "0x0000000000000000000000000000000000000000000000000000000000000000"); + const valueSchema = { staticFields: [], dynamicFields: ["string", "string"] } as const; + const values = decodeRecord(valueSchema, "0x0000000000000000000000000000000000000000000000000000000000000000"); expect(values).toMatchInlineSnapshot(` [ "", @@ -23,8 +23,8 @@ describe("decodeRecord", () => { }); it("can decode an out of bounds array", () => { - const schema = { staticFields: [], dynamicFields: ["uint32[]"] } as const; - const values = decodeRecord(schema, "0x0000000000000000000000000000000000000000000000000400000000000004"); + const valueSchema = { staticFields: [], dynamicFields: ["uint32[]"] } as const; + const values = decodeRecord(valueSchema, "0x0000000000000000000000000000000000000000000000000400000000000004"); expect(values).toMatchInlineSnapshot(` [ [ diff --git a/packages/protocol-parser/src/decodeRecord.ts b/packages/protocol-parser/src/decodeRecord.ts index 2f8536287d..c48dc0bd24 100644 --- a/packages/protocol-parser/src/decodeRecord.ts +++ b/packages/protocol-parser/src/decodeRecord.ts @@ -13,23 +13,23 @@ import { staticDataLength } from "./staticDataLength"; import { readHex } from "./readHex"; /** @deprecated use `decodeValue` instead */ -export function decodeRecord(schema: Schema, data: Hex): readonly (StaticPrimitiveType | DynamicPrimitiveType)[] { +export function decodeRecord(valueSchema: Schema, data: Hex): readonly (StaticPrimitiveType | DynamicPrimitiveType)[] { const values: (StaticPrimitiveType | DynamicPrimitiveType)[] = []; let bytesOffset = 0; - schema.staticFields.forEach((fieldType) => { + valueSchema.staticFields.forEach((fieldType) => { const fieldByteLength = staticAbiTypeToByteLength[fieldType]; const value = decodeStaticField(fieldType, readHex(data, bytesOffset, bytesOffset + fieldByteLength)); bytesOffset += fieldByteLength; values.push(value); }); - // Warn user if static data length doesn't match the schema, because data corruption might be possible. - const schemaStaticDataLength = staticDataLength(schema.staticFields); + // Warn user if static data length doesn't match the value schema, because data corruption might be possible. + const schemaStaticDataLength = staticDataLength(valueSchema.staticFields); const actualStaticDataLength = bytesOffset; if (actualStaticDataLength !== schemaStaticDataLength) { console.warn( - "Decoded static data length does not match schema's expected static data length. Data may get corrupted. Is `getStaticByteLength` outdated?", + "Decoded static data length does not match value schema's expected static data length. Data may get corrupted. Is `getStaticByteLength` outdated?", { expectedLength: schemaStaticDataLength, actualLength: actualStaticDataLength, @@ -38,11 +38,11 @@ export function decodeRecord(schema: Schema, data: Hex): readonly (StaticPrimiti ); } - if (schema.dynamicFields.length > 0) { + if (valueSchema.dynamicFields.length > 0) { const dataLayout = hexToPackedCounter(readHex(data, bytesOffset, bytesOffset + 32)); bytesOffset += 32; - schema.dynamicFields.forEach((fieldType, i) => { + valueSchema.dynamicFields.forEach((fieldType, i) => { const dataLength = dataLayout.fieldByteLengths[i]; if (dataLength > 0) { const value = decodeDynamicField(fieldType, readHex(data, bytesOffset, bytesOffset + dataLength)); @@ -53,7 +53,7 @@ export function decodeRecord(schema: Schema, data: Hex): readonly (StaticPrimiti } }); - // Warn user if dynamic data length doesn't match the schema, because data corruption might be possible. + // Warn user if dynamic data length doesn't match the dynamic data length, because data corruption might be possible. const actualDynamicDataLength = bytesOffset - 32 - actualStaticDataLength; // TODO: refactor this so we don't break for bytes offsets >UINT40 if (BigInt(actualDynamicDataLength) !== dataLayout.totalByteLength) { diff --git a/packages/protocol-parser/src/encodeRecord.test.ts b/packages/protocol-parser/src/encodeRecord.test.ts index fde765d9b6..29222756fa 100644 --- a/packages/protocol-parser/src/encodeRecord.test.ts +++ b/packages/protocol-parser/src/encodeRecord.test.ts @@ -2,23 +2,23 @@ import { describe, expect, it } from "vitest"; import { encodeRecord } from "./encodeRecord"; describe("encodeRecord", () => { - it("can encode a schema and record values to hex", () => { - const schema = { staticFields: ["uint32", "uint128"], dynamicFields: ["uint32[]", "string"] } as const; - const hex = encodeRecord(schema, [1, 2n, [3, 4], "some string"]); + it("can encode a value schema and record values to hex", () => { + const valueSchema = { staticFields: ["uint32", "uint128"], dynamicFields: ["uint32[]", "string"] } as const; + const hex = encodeRecord(valueSchema, [1, 2n, [3, 4], "some string"]); expect(hex).toBe( "0x0000000100000000000000000000000000000002000000000000000000000000000000000000000b0000000008000000000000130000000300000004736f6d6520737472696e67" ); }); it("should not include the packed dynamic lengths if there are no dynamic fields", () => { - const schema = { staticFields: ["uint32", "uint128"], dynamicFields: [] } as const; - const hex = encodeRecord(schema, [1, 2n]); + const valueSchema = { staticFields: ["uint32", "uint128"], dynamicFields: [] } as const; + const hex = encodeRecord(valueSchema, [1, 2n]); expect(hex).toBe("0x0000000100000000000000000000000000000002"); }); it("can encode an array to hex", () => { - const schema = { staticFields: [], dynamicFields: ["uint32[]"] } as const; - const hex = encodeRecord(schema, [[42]]); + const valueSchema = { staticFields: [], dynamicFields: ["uint32[]"] } as const; + const hex = encodeRecord(valueSchema, [[42]]); expect(hex).toBe("0x00000000000000000000000000000000000000000000000004000000000000040000002a"); }); }); diff --git a/packages/protocol-parser/src/encodeRecord.ts b/packages/protocol-parser/src/encodeRecord.ts index b224a6c532..b92287830c 100644 --- a/packages/protocol-parser/src/encodeRecord.ts +++ b/packages/protocol-parser/src/encodeRecord.ts @@ -4,18 +4,21 @@ import { encodeField } from "./encodeField"; import { Schema } from "./common"; /** @deprecated use `encodeValue` instead */ -export function encodeRecord(schema: Schema, values: readonly (StaticPrimitiveType | DynamicPrimitiveType)[]): Hex { - const staticValues = values.slice(0, schema.staticFields.length) as readonly StaticPrimitiveType[]; - const dynamicValues = values.slice(schema.staticFields.length) as readonly DynamicPrimitiveType[]; +export function encodeRecord( + valueSchema: Schema, + values: readonly (StaticPrimitiveType | DynamicPrimitiveType)[] +): Hex { + const staticValues = values.slice(0, valueSchema.staticFields.length) as readonly StaticPrimitiveType[]; + const dynamicValues = values.slice(valueSchema.staticFields.length) as readonly DynamicPrimitiveType[]; const staticData = staticValues - .map((value, i) => encodeField(schema.staticFields[i], value).replace(/^0x/, "")) + .map((value, i) => encodeField(valueSchema.staticFields[i], value).replace(/^0x/, "")) .join(""); - if (schema.dynamicFields.length === 0) return `0x${staticData}`; + if (valueSchema.dynamicFields.length === 0) return `0x${staticData}`; const dynamicDataItems = dynamicValues.map((value, i) => - encodeField(schema.dynamicFields[i], value).replace(/^0x/, "") + encodeField(valueSchema.dynamicFields[i], value).replace(/^0x/, "") ); const dynamicFieldByteLengths = dynamicDataItems.map((value) => value.length / 2).reverse(); diff --git a/packages/protocol-parser/src/encodeValue.ts b/packages/protocol-parser/src/encodeValue.ts index 6394f144b3..f953ccee21 100644 --- a/packages/protocol-parser/src/encodeValue.ts +++ b/packages/protocol-parser/src/encodeValue.ts @@ -13,6 +13,6 @@ export function encodeValue( // TODO: refactor and move all encodeRecord logic into this method so we can delete encodeRecord // This currently assumes fields/values are ordered by static, dynamic - // TODO: make sure we preserve ordering based on schema definition + // TODO: make sure we preserve ordering based on value schema definition return encodeRecord({ staticFields, dynamicFields }, Object.values(value)); } diff --git a/packages/protocol-parser/src/hexToPackedCounter.ts b/packages/protocol-parser/src/hexToPackedCounter.ts index 6ab5920bbd..c8816d15f7 100644 --- a/packages/protocol-parser/src/hexToPackedCounter.ts +++ b/packages/protocol-parser/src/hexToPackedCounter.ts @@ -9,7 +9,7 @@ import { readHex } from "./readHex"; // - Last 7 bytes (uint56) are used for the total byte length of the dynamic data // - The next 5 byte (uint40) sections are used for the byte length of each field, indexed from right to left -// We use byte lengths rather than item counts so that, on chain, we can slice without having to get the schema first (and thus the field lengths of each dynamic type) +// We use byte lengths rather than item counts so that, on chain, we can slice without having to get the value schema first (and thus the field lengths of each dynamic type) export function hexToPackedCounter(data: Hex): { totalByteLength: bigint; @@ -20,7 +20,7 @@ export function hexToPackedCounter(data: Hex): { } const totalByteLength = decodeStaticField("uint56", readHex(data, 32 - 7, 32)); - // TODO: use schema to make sure we only parse as many as we need (rather than zeroes at the end)? + // TODO: use value schema to make sure we only parse as many as we need (rather than zeroes at the end)? const reversedFieldByteLengths = decodeDynamicField("uint40[]", readHex(data, 0, 32 - 7)); // Reverse the lengths const fieldByteLengths = Object.freeze([...reversedFieldByteLengths].reverse()); diff --git a/packages/protocol-parser/src/keySchemaToHex.ts b/packages/protocol-parser/src/keySchemaToHex.ts index 0d5d3a697e..f2e9443153 100644 --- a/packages/protocol-parser/src/keySchemaToHex.ts +++ b/packages/protocol-parser/src/keySchemaToHex.ts @@ -3,6 +3,6 @@ import { Hex } from "viem"; import { KeySchema } from "./common"; import { schemaToHex } from "./schemaToHex"; -export function keySchemaToHex(schema: KeySchema): Hex { - return schemaToHex({ staticFields: Object.values(schema).filter(isStaticAbiType), dynamicFields: [] }); +export function keySchemaToHex(keySchema: KeySchema): Hex { + return schemaToHex({ staticFields: Object.values(keySchema).filter(isStaticAbiType), dynamicFields: [] }); } diff --git a/packages/protocol-parser/src/valueSchemaToHex.ts b/packages/protocol-parser/src/valueSchemaToHex.ts index b7e24b7f7a..205b8696ea 100644 --- a/packages/protocol-parser/src/valueSchemaToHex.ts +++ b/packages/protocol-parser/src/valueSchemaToHex.ts @@ -3,9 +3,9 @@ import { Hex } from "viem"; import { ValueSchema } from "./common"; import { schemaToHex } from "./schemaToHex"; -export function valueSchemaToHex(schema: ValueSchema): Hex { +export function valueSchemaToHex(valueSchema: ValueSchema): Hex { return schemaToHex({ - staticFields: Object.values(schema).filter(isStaticAbiType), - dynamicFields: Object.values(schema).filter(isDynamicAbiType), + staticFields: Object.values(valueSchema).filter(isStaticAbiType), + dynamicFields: Object.values(valueSchema).filter(isDynamicAbiType), }); } diff --git a/packages/store-sync/src/blockLogsToStorage.ts b/packages/store-sync/src/blockLogsToStorage.ts index 70f07276a6..f4af902b71 100644 --- a/packages/store-sync/src/blockLogsToStorage.ts +++ b/packages/store-sync/src/blockLogsToStorage.ts @@ -48,9 +48,9 @@ export function blockLogsToStorage({ const table = hexToTableId(tableId); - const valueTuple = decodeRecord(abiTypesToSchema(Object.values(schemasTable.schema)), log.args.data); + const valueTuple = decodeRecord(abiTypesToSchema(Object.values(schemasTable.valueSchema)), log.args.data); const value = Object.fromEntries( - Object.keys(schemasTable.schema).map((name, i) => [name, valueTuple[i]]) + Object.keys(schemasTable.valueSchema).map((name, i) => [name, valueTuple[i]]) ) as ConfigToValuePrimitives; const keySchema = hexToSchema(value.keySchema); diff --git a/packages/store-sync/src/postgres/buildInternalTables.ts b/packages/store-sync/src/postgres/buildInternalTables.ts index 889566db44..08a4fd8b80 100644 --- a/packages/store-sync/src/postgres/buildInternalTables.ts +++ b/packages/store-sync/src/postgres/buildInternalTables.ts @@ -1,5 +1,4 @@ import { integer, pgSchema, text } from "drizzle-orm/pg-core"; -import { DynamicAbiType, StaticAbiType } from "@latticexyz/schema-type"; import { transformSchemaName } from "./transformSchemaName"; import { asAddress, asBigInt, asJson, asNumber } from "./columnTypes"; import { KeySchema, ValueSchema } from "@latticexyz/protocol-parser"; diff --git a/packages/store-sync/src/recs/common.ts b/packages/store-sync/src/recs/common.ts index c384d5da13..d33aeb5b93 100644 --- a/packages/store-sync/src/recs/common.ts +++ b/packages/store-sync/src/recs/common.ts @@ -14,14 +14,14 @@ export type StoreComponentMetadata = RecsMetadata & { export type ConfigToRecsComponents = { [tableName in keyof TConfig["tables"] & string]: RecsComponent< { - [fieldName in keyof TConfig["tables"][tableName]["schema"] & string]: RecsType & - SchemaAbiTypeToRecsType; + [fieldName in keyof TConfig["tables"][tableName]["valueSchema"] & string]: RecsType & + SchemaAbiTypeToRecsType; }, StoreComponentMetadata & { componentName: tableName; tableName: `${TConfig["namespace"]}:${tableName}`; keySchema: TConfig["tables"][tableName]["keySchema"]; - valueSchema: TConfig["tables"][tableName]["schema"]; + valueSchema: TConfig["tables"][tableName]["valueSchema"]; } >; }; diff --git a/packages/store-sync/src/recs/configToRecsComponents.ts b/packages/store-sync/src/recs/configToRecsComponents.ts index f1b2e617e5..1d5b9e760e 100644 --- a/packages/store-sync/src/recs/configToRecsComponents.ts +++ b/packages/store-sync/src/recs/configToRecsComponents.ts @@ -15,7 +15,7 @@ export function configToRecsComponents( defineComponent( world, Object.fromEntries( - Object.entries(table.schema).map(([fieldName, schemaAbiType]) => [ + Object.entries(table.valueSchema).map(([fieldName, schemaAbiType]) => [ fieldName, schemaAbiTypeToRecsType[schemaAbiType as SchemaAbiType], ]) @@ -26,7 +26,7 @@ export function configToRecsComponents( componentName: tableName, tableName: `${config.namespace}:${tableName}`, keySchema: table.keySchema, - valueSchema: table.schema, + valueSchema: table.valueSchema, }, } ), diff --git a/packages/store-sync/src/schemaToDefaults.ts b/packages/store-sync/src/schemaToDefaults.ts index 36dab2b1ec..15be27c54c 100644 --- a/packages/store-sync/src/schemaToDefaults.ts +++ b/packages/store-sync/src/schemaToDefaults.ts @@ -1,8 +1,8 @@ import { schemaAbiTypeToDefaultValue } from "@latticexyz/schema-type"; import { ValueSchema, SchemaToPrimitives } from "@latticexyz/protocol-parser"; -export function schemaToDefaults(schema: TSchema): SchemaToPrimitives { +export function schemaToDefaults(valueSchema: TSchema): SchemaToPrimitives { return Object.fromEntries( - Object.entries(schema).map(([key, abiType]) => [key, schemaAbiTypeToDefaultValue[abiType]]) + Object.entries(valueSchema).map(([key, abiType]) => [key, schemaAbiTypeToDefaultValue[abiType]]) ) as SchemaToPrimitives; } diff --git a/packages/store/gas-report.json b/packages/store/gas-report.json index 0899ffa898..06772c450b 100644 --- a/packages/store/gas-report.json +++ b/packages/store/gas-report.json @@ -710,7 +710,7 @@ { "file": "test/StoreCoreGas.t.sol", "test": "testRegisterAndGetFieldLayout", - "name": "StoreCore: get schema (warm)", + "name": "StoreCore: get value schema (warm)", "gasUsed": 5033 }, { diff --git a/packages/store/mud.config.ts b/packages/store/mud.config.ts index 8a99d085b3..814ab527b9 100644 --- a/packages/store/mud.config.ts +++ b/packages/store/mud.config.ts @@ -13,7 +13,7 @@ export default mudConfig({ keySchema: { tableId: "bytes32", }, - schema: { + valueSchema: { fieldLayout: "bytes32", keySchema: "bytes32", valueSchema: "bytes32", @@ -23,12 +23,12 @@ export default mudConfig({ }, // The Hooks table is a generic table used by the `filterFromList` util in `Hook.sol` Hooks: { - schema: "bytes21[]", + valueSchema: "bytes21[]", tableIdArgument: true, }, // TODO: move these test tables to a separate mud config Mixed: { - schema: { + valueSchema: { u32: "uint32", u128: "uint128", a32: "uint32[]", @@ -36,7 +36,7 @@ export default mudConfig({ }, }, Vector2: { - schema: { + valueSchema: { x: "uint32", y: "uint32", }, @@ -50,7 +50,7 @@ export default mudConfig({ k5: "bool", k6: "ExampleEnum", }, - schema: "bool", + valueSchema: "bool", }, }, }); diff --git a/packages/store/src/IStore.sol b/packages/store/src/IStore.sol index 2a939e8529..c2e48c9fb4 100644 --- a/packages/store/src/IStore.sol +++ b/packages/store/src/IStore.sol @@ -9,9 +9,9 @@ import { IStoreHook } from "./IStoreHook.sol"; interface IStoreRead { function getFieldLayout(bytes32 table) external view returns (FieldLayout fieldLayout); - function getValueSchema(bytes32 table) external view returns (Schema schema); + function getValueSchema(bytes32 table) external view returns (Schema valueSchema); - function getKeySchema(bytes32 table) external view returns (Schema schema); + function getKeySchema(bytes32 table) external view returns (Schema keySchema); // Get full record (including full array) function getRecord( diff --git a/packages/store/src/StoreRead.sol b/packages/store/src/StoreRead.sol index 28fc1ff91a..425d66aee0 100644 --- a/packages/store/src/StoreRead.sol +++ b/packages/store/src/StoreRead.sol @@ -11,12 +11,12 @@ contract StoreRead is IStoreRead { fieldLayout = StoreCore.getFieldLayout(table); } - function getValueSchema(bytes32 table) public view virtual returns (Schema schema) { - schema = StoreCore.getValueSchema(table); + function getValueSchema(bytes32 table) public view virtual returns (Schema valueSchema) { + valueSchema = StoreCore.getValueSchema(table); } - function getKeySchema(bytes32 table) public view virtual returns (Schema schema) { - schema = StoreCore.getKeySchema(table); + function getKeySchema(bytes32 table) public view virtual returns (Schema keySchema) { + keySchema = StoreCore.getKeySchema(table); } // Get full record (static and dynamic data) diff --git a/packages/store/src/codegen/tables/Callbacks.sol b/packages/store/src/codegen/tables/Callbacks.sol index f43519c60d..0126d86c18 100644 --- a/packages/store/src/codegen/tables/Callbacks.sol +++ b/packages/store/src/codegen/tables/Callbacks.sol @@ -31,18 +31,18 @@ library Callbacks { /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](1); - _schema[0] = SchemaType.BYTES32; + SchemaType[] memory _keySchema = new SchemaType[](1); + _keySchema[0] = SchemaType.BYTES32; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_keySchema); } /** Get the table's value schema */ function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](1); - _schema[0] = SchemaType.BYTES24_ARRAY; + SchemaType[] memory _valueSchema = new SchemaType[](1); + _valueSchema[0] = SchemaType.BYTES24_ARRAY; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_valueSchema); } /** Get the table's key names */ diff --git a/packages/store/src/codegen/tables/Hooks.sol b/packages/store/src/codegen/tables/Hooks.sol index 8fca4a03b7..242d5c9730 100644 --- a/packages/store/src/codegen/tables/Hooks.sol +++ b/packages/store/src/codegen/tables/Hooks.sol @@ -28,18 +28,18 @@ library Hooks { /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](1); - _schema[0] = SchemaType.BYTES32; + SchemaType[] memory _keySchema = new SchemaType[](1); + _keySchema[0] = SchemaType.BYTES32; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_keySchema); } /** Get the table's value schema */ function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](1); - _schema[0] = SchemaType.BYTES21_ARRAY; + SchemaType[] memory _valueSchema = new SchemaType[](1); + _valueSchema[0] = SchemaType.BYTES21_ARRAY; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_valueSchema); } /** Get the table's key names */ diff --git a/packages/store/src/codegen/tables/KeyEncoding.sol b/packages/store/src/codegen/tables/KeyEncoding.sol index 43d4ca2cce..f2344cf382 100644 --- a/packages/store/src/codegen/tables/KeyEncoding.sol +++ b/packages/store/src/codegen/tables/KeyEncoding.sol @@ -35,23 +35,23 @@ library KeyEncoding { /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](6); - _schema[0] = SchemaType.UINT256; - _schema[1] = SchemaType.INT32; - _schema[2] = SchemaType.BYTES16; - _schema[3] = SchemaType.ADDRESS; - _schema[4] = SchemaType.BOOL; - _schema[5] = SchemaType.UINT8; + SchemaType[] memory _keySchema = new SchemaType[](6); + _keySchema[0] = SchemaType.UINT256; + _keySchema[1] = SchemaType.INT32; + _keySchema[2] = SchemaType.BYTES16; + _keySchema[3] = SchemaType.ADDRESS; + _keySchema[4] = SchemaType.BOOL; + _keySchema[5] = SchemaType.UINT8; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_keySchema); } /** Get the table's value schema */ function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](1); - _schema[0] = SchemaType.BOOL; + SchemaType[] memory _valueSchema = new SchemaType[](1); + _valueSchema[0] = SchemaType.BOOL; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_valueSchema); } /** Get the table's key names */ diff --git a/packages/store/src/codegen/tables/Mixed.sol b/packages/store/src/codegen/tables/Mixed.sol index bba29cecd6..22f664c8e1 100644 --- a/packages/store/src/codegen/tables/Mixed.sol +++ b/packages/store/src/codegen/tables/Mixed.sol @@ -40,21 +40,21 @@ library Mixed { /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](1); - _schema[0] = SchemaType.BYTES32; + SchemaType[] memory _keySchema = new SchemaType[](1); + _keySchema[0] = SchemaType.BYTES32; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_keySchema); } /** Get the table's value schema */ function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](4); - _schema[0] = SchemaType.UINT32; - _schema[1] = SchemaType.UINT128; - _schema[2] = SchemaType.UINT32_ARRAY; - _schema[3] = SchemaType.STRING; + SchemaType[] memory _valueSchema = new SchemaType[](4); + _valueSchema[0] = SchemaType.UINT32; + _valueSchema[1] = SchemaType.UINT128; + _valueSchema[2] = SchemaType.UINT32_ARRAY; + _valueSchema[3] = SchemaType.STRING; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_valueSchema); } /** Get the table's key names */ diff --git a/packages/store/src/codegen/tables/StoreHooks.sol b/packages/store/src/codegen/tables/StoreHooks.sol index 2168293bce..9b84a3549e 100644 --- a/packages/store/src/codegen/tables/StoreHooks.sol +++ b/packages/store/src/codegen/tables/StoreHooks.sol @@ -31,18 +31,18 @@ library StoreHooks { /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](1); - _schema[0] = SchemaType.BYTES32; + SchemaType[] memory _keySchema = new SchemaType[](1); + _keySchema[0] = SchemaType.BYTES32; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_keySchema); } /** Get the table's value schema */ function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](1); - _schema[0] = SchemaType.BYTES21_ARRAY; + SchemaType[] memory _valueSchema = new SchemaType[](1); + _valueSchema[0] = SchemaType.BYTES21_ARRAY; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_valueSchema); } /** Get the table's key names */ diff --git a/packages/store/src/codegen/tables/Tables.sol b/packages/store/src/codegen/tables/Tables.sol index 535a57a44f..fc82b0dedb 100644 --- a/packages/store/src/codegen/tables/Tables.sol +++ b/packages/store/src/codegen/tables/Tables.sol @@ -42,22 +42,22 @@ library Tables { /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](1); - _schema[0] = SchemaType.BYTES32; + SchemaType[] memory _keySchema = new SchemaType[](1); + _keySchema[0] = SchemaType.BYTES32; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_keySchema); } /** Get the table's value schema */ function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](5); - _schema[0] = SchemaType.BYTES32; - _schema[1] = SchemaType.BYTES32; - _schema[2] = SchemaType.BYTES32; - _schema[3] = SchemaType.BYTES; - _schema[4] = SchemaType.BYTES; - - return SchemaLib.encode(_schema); + SchemaType[] memory _valueSchema = new SchemaType[](5); + _valueSchema[0] = SchemaType.BYTES32; + _valueSchema[1] = SchemaType.BYTES32; + _valueSchema[2] = SchemaType.BYTES32; + _valueSchema[3] = SchemaType.BYTES; + _valueSchema[4] = SchemaType.BYTES; + + return SchemaLib.encode(_valueSchema); } /** Get the table's key names */ diff --git a/packages/store/src/codegen/tables/Vector2.sol b/packages/store/src/codegen/tables/Vector2.sol index 518695ee86..82a58d420b 100644 --- a/packages/store/src/codegen/tables/Vector2.sol +++ b/packages/store/src/codegen/tables/Vector2.sol @@ -38,19 +38,19 @@ library Vector2 { /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](1); - _schema[0] = SchemaType.BYTES32; + SchemaType[] memory _keySchema = new SchemaType[](1); + _keySchema[0] = SchemaType.BYTES32; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_keySchema); } /** Get the table's value schema */ function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](2); - _schema[0] = SchemaType.UINT32; - _schema[1] = SchemaType.UINT32; + SchemaType[] memory _valueSchema = new SchemaType[](2); + _valueSchema[0] = SchemaType.UINT32; + _valueSchema[1] = SchemaType.UINT32; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_valueSchema); } /** Get the table's key names */ diff --git a/packages/store/test/StoreCore.t.sol b/packages/store/test/StoreCore.t.sol index 15892cb85c..f6e37eac36 100644 --- a/packages/store/test/StoreCore.t.sol +++ b/packages/store/test/StoreCore.t.sol @@ -92,7 +92,7 @@ contract StoreCoreTest is Test, StoreMock { keccak256("table"), FieldLayout.wrap(keccak256("random bytes as value field layout")), Schema.wrap(keccak256("random bytes as key schema")), - Schema.wrap(keccak256("random bytes as schema")), + Schema.wrap(keccak256("random bytes as value schema")), keyNames, fieldNames ); @@ -926,7 +926,7 @@ contract StoreCoreTest is Test, StoreMock { bytes32[] memory key = new bytes32[](1); key[0] = keccak256("some key"); - // Register table's schema + // Register table's value schema FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(16, 0); Schema valueSchema = SchemaEncodeHelper.encode(SchemaType.UINT128); IStore(this).registerTable(table, fieldLayout, defaultKeySchema, valueSchema, new string[](1), new string[](1)); diff --git a/packages/store/test/StoreCoreDynamic.t.sol b/packages/store/test/StoreCoreDynamic.t.sol index 19a08dd88c..a29d56eaa5 100644 --- a/packages/store/test/StoreCoreDynamic.t.sol +++ b/packages/store/test/StoreCoreDynamic.t.sol @@ -37,7 +37,7 @@ contract StoreCoreDynamicTest is Test, GasReporter, StoreMock { } function setUp() public { - // Register table's schema + // Register table's value schema FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(32, 2); Schema valueSchema = SchemaEncodeHelper.encode( SchemaType.UINT256, diff --git a/packages/store/test/StoreCoreGas.t.sol b/packages/store/test/StoreCoreGas.t.sol index 97e2ec65a6..d09dc15539 100644 --- a/packages/store/test/StoreCoreGas.t.sol +++ b/packages/store/test/StoreCoreGas.t.sol @@ -60,7 +60,7 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { StoreCore.getFieldLayout(table); endGasReport(); - startGasReport("StoreCore: get schema (warm)"); + startGasReport("StoreCore: get value schema (warm)"); StoreCore.getValueSchema(table); endGasReport(); @@ -103,7 +103,7 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(1, 2, 4, 2); - // Register schema + // Register table StoreCore.registerTable(table, fieldLayout, defaultKeySchema, valueSchema, new string[](1), new string[](5)); // Create some key @@ -127,7 +127,7 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { } function testSetAndGetStaticData() public { - // Register table's schema + // Register table Schema valueSchema = SchemaEncodeHelper.encode( SchemaType.UINT8, SchemaType.UINT16, @@ -154,7 +154,7 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { } function testSetAndGetStaticDataSpanningWords() public { - // Register table's schema + // Register table Schema valueSchema = SchemaEncodeHelper.encode(SchemaType.UINT128, SchemaType.UINT256); FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(16, 32, 0); bytes32 table = keccak256("some.table"); @@ -182,7 +182,7 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { function testSetAndGetDynamicData() public { bytes32 table = keccak256("some.table"); - // Register table's schema + // Register table FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(16, 2); Schema valueSchema = SchemaEncodeHelper.encode( SchemaType.UINT128, @@ -258,7 +258,7 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { function testSetAndGetField() public { bytes32 table = keccak256("some.table"); - // Register table's schema + // Register table FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(16, 32, 2); Schema valueSchema = SchemaEncodeHelper.encode( SchemaType.UINT128, @@ -348,7 +348,7 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { function testDeleteData() public { bytes32 table = keccak256("some.table"); - // Register table's schema + // Register table FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(16, 2); Schema valueSchema = SchemaEncodeHelper.encode( SchemaType.UINT128, @@ -405,7 +405,7 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { function testPushToField() public { bytes32 table = keccak256("some.table"); - // Register table's schema + // Register table FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(32, 2); Schema valueSchema = SchemaEncodeHelper.encode( SchemaType.UINT256, @@ -492,7 +492,7 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { TestUpdateInFieldData memory data = TestUpdateInFieldData("", "", "", "", "", "", ""); bytes32 table = keccak256("some.table"); - // Register table's schema + // Register table FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(32, 2); Schema valueSchema = SchemaEncodeHelper.encode( SchemaType.UINT256, @@ -602,7 +602,7 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { bytes32[] memory key = new bytes32[](1); key[0] = keccak256("some key"); - // Register table's schema + // Register table FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(16, 0); Schema valueSchema = SchemaEncodeHelper.encode(SchemaType.UINT128); StoreCore.registerTable(table, fieldLayout, defaultKeySchema, valueSchema, new string[](1), new string[](1)); @@ -654,7 +654,7 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { bytes32[] memory key = new bytes32[](1); key[0] = keccak256("some key"); - // Register table's schema + // Register table FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(16, 1); Schema valueSchema = SchemaEncodeHelper.encode(SchemaType.UINT128, SchemaType.UINT32_ARRAY); StoreCore.registerTable(table, fieldLayout, defaultKeySchema, valueSchema, new string[](1), new string[](2)); diff --git a/packages/store/test/tables/StoreHooks.t.sol b/packages/store/test/tables/StoreHooks.t.sol index ff347c9b86..5960dde364 100644 --- a/packages/store/test/tables/StoreHooks.t.sol +++ b/packages/store/test/tables/StoreHooks.t.sol @@ -8,7 +8,7 @@ import { StoreHooks } from "../../src/codegen/Tables.sol"; contract StoreHooksTest is Test, GasReporter, StoreMock { function testTable() public { - // StoreHooks schema is already registered by StoreCore + // StoreHooks table is already registered by StoreMock bytes32 key = keccak256("somekey"); bytes21[] memory hooks = new bytes21[](1); diff --git a/packages/store/ts/codegen/renderTable.ts b/packages/store/ts/codegen/renderTable.ts index cc19b244ef..8181133cfb 100644 --- a/packages/store/ts/codegen/renderTable.ts +++ b/packages/store/ts/codegen/renderTable.ts @@ -84,18 +84,18 @@ export function renderTable(options: RenderTableOptions) { /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](${keyTuple.length}); - ${renderList(keyTuple, ({ enumName }, index) => `_schema[${index}] = SchemaType.${enumName};`)} + SchemaType[] memory _keySchema = new SchemaType[](${keyTuple.length}); + ${renderList(keyTuple, ({ enumName }, index) => `_keySchema[${index}] = SchemaType.${enumName};`)} - return SchemaLib.encode(_schema); + return SchemaLib.encode(_keySchema); } /** Get the table's value schema */ function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](${fields.length}); - ${renderList(fields, ({ enumName }, index) => `_schema[${index}] = SchemaType.${enumName};`)} + SchemaType[] memory _valueSchema = new SchemaType[](${fields.length}); + ${renderList(fields, ({ enumName }, index) => `_valueSchema[${index}] = SchemaType.${enumName};`)} - return SchemaLib.encode(_schema); + return SchemaLib.encode(_valueSchema); } /** Get the table's key names */ diff --git a/packages/store/ts/codegen/tableOptions.ts b/packages/store/ts/codegen/tableOptions.ts index 5dccb14aca..fa38785757 100644 --- a/packages/store/ts/codegen/tableOptions.ts +++ b/packages/store/ts/codegen/tableOptions.ts @@ -27,9 +27,9 @@ export function getTableOptions(config: StoreConfig): TableOptions[] { // struct adds methods to get/set all values at once const withStruct = tableData.dataStruct; // operate on all fields at once; for only 1 field keep them only if struct is also kept - const withRecordMethods = withStruct || Object.keys(tableData.schema).length > 1; + const withRecordMethods = withStruct || Object.keys(tableData.valueSchema).length > 1; // field methods can be simply get/set if there's only 1 field and no record methods - const noFieldMethodSuffix = !withRecordMethods && Object.keys(tableData.schema).length === 1; + const noFieldMethodSuffix = !withRecordMethods && Object.keys(tableData.valueSchema).length === 1; // list of any symbols that need to be imported const imports: RelativeImportDatum[] = []; @@ -50,8 +50,8 @@ export function getTableOptions(config: StoreConfig): TableOptions[] { return keyTuple; }); - const fields = Object.keys(tableData.schema).map((name) => { - const abiOrUserType = tableData.schema[name]; + const fields = Object.keys(tableData.valueSchema).map((name) => { + const abiOrUserType = tableData.valueSchema[name]; const { renderType, schemaType } = resolveAbiOrUserType(abiOrUserType, config); const importDatum = importForAbiOrUserType(abiOrUserType, tableData.directory, config); diff --git a/packages/store/ts/common.ts b/packages/store/ts/common.ts index 380709deec..5e6ce3e000 100644 --- a/packages/store/ts/common.ts +++ b/packages/store/ts/common.ts @@ -21,7 +21,7 @@ export type SchemaConfigToPrimitives = { export type ConfigToTablesPrimitives = { [key in keyof C["tables"]]: { key: SchemaConfigToPrimitives; - value: SchemaConfigToPrimitives; + value: SchemaConfigToPrimitives; }; }; diff --git a/packages/store/ts/config/storeConfig.ts b/packages/store/ts/config/storeConfig.ts index 6944b4f61b..8a3905d359 100644 --- a/packages/store/ts/config/storeConfig.ts +++ b/packages/store/ts/config/storeConfig.ts @@ -87,17 +87,24 @@ export interface TableConfig< dataStruct?: boolean; /** Generate only `emitEphemeral` which emits an event without writing to storage. Default is false. */ ephemeral?: boolean; - /** Table's key schema names mapped to their types. Default is `{ key: "bytes32" }` */ + /** + * Table's key names mapped to their types. + * Default is `{ key: "bytes32" }` + * Key names' first letter should be lowercase. + */ keySchema?: Record>; - /** Table's column names mapped to their types. Table name's 1st letter should be lowercase. */ - schema: SchemaConfig; + /** + * Table's field names mapped to their types. + * Field names' first letter should be lowercase. + */ + valueSchema: SchemaConfig; } export type FullTableConfig< UserTypes extends StringForUnion = StringForUnion, StaticUserTypes extends StringForUnion = StringForUnion > = Required> & { - schema: FullSchemaConfig; + valueSchema: FullSchemaConfig; }; export interface ExpandTableConfig, TableName extends string> @@ -108,13 +115,13 @@ export interface ExpandTableConfig, TableN name: TableName; tableIdArgument: typeof TABLE_DEFAULTS.tableIdArgument; storeArgument: typeof TABLE_DEFAULTS.storeArgument; - // dataStruct isn't expanded, because its value is conditional on the number of schema fields + // dataStruct isn't expanded, because its value is conditional on the number of value schema fields dataStruct: boolean; keySchema: typeof TABLE_DEFAULTS.keySchema; ephemeral: typeof TABLE_DEFAULTS.ephemeral; } > { - schema: ExpandSchemaConfig; + valueSchema: ExpandSchemaConfig; } const zFullTableConfig = z @@ -125,12 +132,12 @@ const zFullTableConfig = z storeArgument: z.boolean().default(TABLE_DEFAULTS.storeArgument), dataStruct: z.boolean().optional(), keySchema: zKeySchema, - schema: zSchemaConfig, + valueSchema: zSchemaConfig, ephemeral: z.boolean().default(TABLE_DEFAULTS.ephemeral), }) .transform((arg) => { - // default dataStruct value depends on schema's length - if (Object.keys(arg.schema).length === 1) { + // default dataStruct value depends on value schema's length + if (Object.keys(arg.valueSchema).length === 1) { arg.dataStruct ??= false; } else { arg.dataStruct ??= true; @@ -140,7 +147,7 @@ const zFullTableConfig = z const zShorthandTableConfig = zFieldData.transform((fieldData) => { return zFullTableConfig.parse({ - schema: { + valueSchema: { value: fieldData, }, }); @@ -177,7 +184,7 @@ export type FullTablesConfig< export type ExpandTablesConfig> = { [TableName in keyof T]: T[TableName] extends FieldData - ? ExpandTableConfig<{ schema: { value: T[TableName] } }, TableName extends string ? TableName : never> + ? ExpandTableConfig<{ valueSchema: { value: T[TableName] } }, TableName extends string ? TableName : never> : T[TableName] extends TableConfig ? ExpandTableConfig : // Weakly typed values get a weakly typed expansion. @@ -290,7 +297,7 @@ function validateStoreConfig(config: z.output, ctx: // Local table variables must be unique within the table for (const table of Object.values(config.tables)) { const keySchemaNames = Object.keys(table.keySchema); - const fieldNames = Object.keys(table.schema); + const fieldNames = Object.keys(table.valueSchema); const duplicateVariableNames = getDuplicates([...keySchemaNames, ...fieldNames]); if (duplicateVariableNames.length > 0) { ctx.addIssue({ @@ -325,7 +332,7 @@ function validateStoreConfig(config: z.output, ctx: for (const keySchemaType of Object.values(table.keySchema)) { validateStaticAbiOrUserType(staticUserTypeNames, keySchemaType, ctx); } - for (const fieldType of Object.values(table.schema)) { + for (const fieldType of Object.values(table.valueSchema)) { validateAbiOrUserType(userTypeNames, staticUserTypeNames, fieldType, ctx); } } diff --git a/packages/store/ts/register/mudConfig.test-d.ts b/packages/store/ts/register/mudConfig.test-d.ts index 3e0c7c39a0..de08e2695b 100644 --- a/packages/store/ts/register/mudConfig.test-d.ts +++ b/packages/store/ts/register/mudConfig.test-d.ts @@ -12,12 +12,12 @@ describe("mudConfig", () => { keySchema: { a: "Enum1"; }; - schema: { + valueSchema: { b: "Enum2"; }; }; Table2: { - schema: { + valueSchema: { a: "uint32"; }; }; @@ -38,12 +38,12 @@ describe("mudConfig", () => { keySchema: { a: "Enum1"; }; - schema: { + valueSchema: { b: "Enum2"; }; }; Table2: { - schema: { + valueSchema: { a: "uint32"; }; }; diff --git a/packages/world/mud.config.ts b/packages/world/mud.config.ts index b23b1e0919..a043d644dd 100644 --- a/packages/world/mud.config.ts +++ b/packages/world/mud.config.ts @@ -15,7 +15,7 @@ export default mudConfig({ keySchema: { namespace: "bytes16", }, - schema: { + valueSchema: { owner: "address", }, }, @@ -24,7 +24,7 @@ export default mudConfig({ resourceSelector: "bytes32", caller: "address", }, - schema: { + valueSchema: { access: "bool", }, }, @@ -33,13 +33,13 @@ export default mudConfig({ moduleName: "bytes16", argumentsHash: "bytes32", // Hash of the params passed to the `install` function }, - schema: { + valueSchema: { moduleAddress: "address", }, // TODO: this is a workaround to use `getRecord` instead of `getField` in the autogen library, - // to allow using the table before it is registered. This is because `getRecord` passes the schema + // to allow using the table before it is registered. This is because `getRecord` passes the valueSchema // to store, while `getField` loads it from storage. Remove this once we have support for passing the - // schema in `getField` too. (See https://github.com/latticexyz/mud/issues/444) + // valueSchema in `getField` too. (See https://github.com/latticexyz/mud/issues/444) dataStruct: true, }, Delegations: { @@ -47,7 +47,7 @@ export default mudConfig({ delegator: "address", delegatee: "address", }, - schema: { + valueSchema: { delegationControlId: "bytes32", }, }, @@ -61,7 +61,7 @@ export default mudConfig({ keySchema: { namespace: "bytes16", }, - schema: { + valueSchema: { balance: "uint256", }, }, @@ -70,7 +70,7 @@ export default mudConfig({ keySchema: { resourceSelector: "bytes32", }, - schema: { + valueSchema: { system: "address", publicAccess: "bool", }, @@ -81,7 +81,7 @@ export default mudConfig({ keySchema: { system: "address", }, - schema: { + valueSchema: { resourceSelector: "bytes32", }, }, @@ -90,14 +90,14 @@ export default mudConfig({ keySchema: { resourceSelector: "bytes32", }, - schema: "bytes21[]", + valueSchema: "bytes21[]", }, ResourceType: { directory: "modules/core/tables", keySchema: { resourceSelector: "bytes32", }, - schema: { + valueSchema: { resourceType: "Resource", }, }, @@ -106,7 +106,7 @@ export default mudConfig({ keySchema: { functionSelector: "bytes4", }, - schema: { + valueSchema: { resourceSelector: "bytes32", systemFunctionSelector: "bytes4", }, @@ -117,7 +117,7 @@ export default mudConfig({ keySchema: { valueHash: "bytes32", }, - schema: { + valueSchema: { keysWithValue: "bytes32[]", // For now only supports 1 key per value }, tableIdArgument: true, @@ -125,7 +125,7 @@ export default mudConfig({ KeysInTable: { directory: "modules/keysintable/tables", keySchema: { sourceTable: "bytes32" }, - schema: { + valueSchema: { keys0: "bytes32[]", keys1: "bytes32[]", keys2: "bytes32[]", @@ -139,13 +139,13 @@ export default mudConfig({ sourceTable: "bytes32", keysHash: "bytes32", }, - schema: { has: "bool", index: "uint40" }, + valueSchema: { has: "bool", index: "uint40" }, dataStruct: false, }, UniqueEntity: { directory: "modules/uniqueentity/tables", keySchema: {}, - schema: "uint256", + valueSchema: "uint256", tableIdArgument: true, storeArgument: true, }, @@ -157,7 +157,7 @@ export default mudConfig({ resourceSelector: "bytes32", funcSelectorAndArgsHash: "bytes32", }, - schema: { + valueSchema: { availableCalls: "uint256", }, }, @@ -167,7 +167,7 @@ export default mudConfig({ delegator: "address", delegatee: "address", }, - schema: { + valueSchema: { maxTimestamp: "uint256", }, }, @@ -179,14 +179,14 @@ export default mudConfig({ Bool: { directory: "../test/tables", keySchema: {}, - schema: { + valueSchema: { value: "bool", }, tableIdArgument: true, }, AddressArray: { directory: "../test/tables", - schema: "address[]", + valueSchema: "address[]", tableIdArgument: true, }, }, diff --git a/packages/world/src/modules/core/implementations/StoreRegistrationSystem.sol b/packages/world/src/modules/core/implementations/StoreRegistrationSystem.sol index 6281cab124..00a5d3017c 100644 --- a/packages/world/src/modules/core/implementations/StoreRegistrationSystem.sol +++ b/packages/world/src/modules/core/implementations/StoreRegistrationSystem.sol @@ -34,7 +34,7 @@ contract StoreRegistrationSystem is System, IWorldErrors { using ResourceSelector for bytes32; /** - * Register a table with given schema in the given namespace + * Register a table with the given config */ function registerTable( bytes32 resourceSelector, @@ -72,7 +72,7 @@ contract StoreRegistrationSystem is System, IWorldErrors { // Store the table resource type ResourceType.set(resourceSelector, Resource.TABLE); - // Register the table's schema + // Register the table StoreCore.registerTable(resourceSelector, fieldLayout, keySchema, valueSchema, keyNames, fieldNames); } diff --git a/packages/world/src/modules/core/tables/Balances.sol b/packages/world/src/modules/core/tables/Balances.sol index c1ccd74606..76f03b4f3c 100644 --- a/packages/world/src/modules/core/tables/Balances.sol +++ b/packages/world/src/modules/core/tables/Balances.sol @@ -32,18 +32,18 @@ library Balances { /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](1); - _schema[0] = SchemaType.BYTES16; + SchemaType[] memory _keySchema = new SchemaType[](1); + _keySchema[0] = SchemaType.BYTES16; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_keySchema); } /** Get the table's value schema */ function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](1); - _schema[0] = SchemaType.UINT256; + SchemaType[] memory _valueSchema = new SchemaType[](1); + _valueSchema[0] = SchemaType.UINT256; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_valueSchema); } /** Get the table's key names */ diff --git a/packages/world/src/modules/core/tables/FunctionSelectors.sol b/packages/world/src/modules/core/tables/FunctionSelectors.sol index 70b3329a17..e3023b3273 100644 --- a/packages/world/src/modules/core/tables/FunctionSelectors.sol +++ b/packages/world/src/modules/core/tables/FunctionSelectors.sol @@ -33,19 +33,19 @@ library FunctionSelectors { /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](1); - _schema[0] = SchemaType.BYTES4; + SchemaType[] memory _keySchema = new SchemaType[](1); + _keySchema[0] = SchemaType.BYTES4; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_keySchema); } /** Get the table's value schema */ function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](2); - _schema[0] = SchemaType.BYTES32; - _schema[1] = SchemaType.BYTES4; + SchemaType[] memory _valueSchema = new SchemaType[](2); + _valueSchema[0] = SchemaType.BYTES32; + _valueSchema[1] = SchemaType.BYTES4; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_valueSchema); } /** Get the table's key names */ diff --git a/packages/world/src/modules/core/tables/ResourceType.sol b/packages/world/src/modules/core/tables/ResourceType.sol index cf99407ecf..45ba98b6fb 100644 --- a/packages/world/src/modules/core/tables/ResourceType.sol +++ b/packages/world/src/modules/core/tables/ResourceType.sol @@ -35,18 +35,18 @@ library ResourceType { /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](1); - _schema[0] = SchemaType.BYTES32; + SchemaType[] memory _keySchema = new SchemaType[](1); + _keySchema[0] = SchemaType.BYTES32; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_keySchema); } /** Get the table's value schema */ function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](1); - _schema[0] = SchemaType.UINT8; + SchemaType[] memory _valueSchema = new SchemaType[](1); + _valueSchema[0] = SchemaType.UINT8; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_valueSchema); } /** Get the table's key names */ diff --git a/packages/world/src/modules/core/tables/SystemHooks.sol b/packages/world/src/modules/core/tables/SystemHooks.sol index 891623d6b4..0bb1d03e8a 100644 --- a/packages/world/src/modules/core/tables/SystemHooks.sol +++ b/packages/world/src/modules/core/tables/SystemHooks.sol @@ -31,18 +31,18 @@ library SystemHooks { /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](1); - _schema[0] = SchemaType.BYTES32; + SchemaType[] memory _keySchema = new SchemaType[](1); + _keySchema[0] = SchemaType.BYTES32; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_keySchema); } /** Get the table's value schema */ function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](1); - _schema[0] = SchemaType.BYTES21_ARRAY; + SchemaType[] memory _valueSchema = new SchemaType[](1); + _valueSchema[0] = SchemaType.BYTES21_ARRAY; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_valueSchema); } /** Get the table's key names */ diff --git a/packages/world/src/modules/core/tables/SystemRegistry.sol b/packages/world/src/modules/core/tables/SystemRegistry.sol index d560340662..1bae5fb67b 100644 --- a/packages/world/src/modules/core/tables/SystemRegistry.sol +++ b/packages/world/src/modules/core/tables/SystemRegistry.sol @@ -32,18 +32,18 @@ library SystemRegistry { /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](1); - _schema[0] = SchemaType.ADDRESS; + SchemaType[] memory _keySchema = new SchemaType[](1); + _keySchema[0] = SchemaType.ADDRESS; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_keySchema); } /** Get the table's value schema */ function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](1); - _schema[0] = SchemaType.BYTES32; + SchemaType[] memory _valueSchema = new SchemaType[](1); + _valueSchema[0] = SchemaType.BYTES32; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_valueSchema); } /** Get the table's key names */ diff --git a/packages/world/src/modules/core/tables/Systems.sol b/packages/world/src/modules/core/tables/Systems.sol index 1be8fb6223..fa6622d37e 100644 --- a/packages/world/src/modules/core/tables/Systems.sol +++ b/packages/world/src/modules/core/tables/Systems.sol @@ -33,19 +33,19 @@ library Systems { /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](1); - _schema[0] = SchemaType.BYTES32; + SchemaType[] memory _keySchema = new SchemaType[](1); + _keySchema[0] = SchemaType.BYTES32; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_keySchema); } /** Get the table's value schema */ function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](2); - _schema[0] = SchemaType.ADDRESS; - _schema[1] = SchemaType.BOOL; + SchemaType[] memory _valueSchema = new SchemaType[](2); + _valueSchema[0] = SchemaType.ADDRESS; + _valueSchema[1] = SchemaType.BOOL; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_valueSchema); } /** Get the table's key names */ diff --git a/packages/world/src/modules/keysintable/getKeysInTable.sol b/packages/world/src/modules/keysintable/getKeysInTable.sol index 9cdfb1abe0..c6b709f5fc 100644 --- a/packages/world/src/modules/keysintable/getKeysInTable.sol +++ b/packages/world/src/modules/keysintable/getKeysInTable.sol @@ -18,14 +18,13 @@ function getKeysInTable(bytes32 tableId) view returns (bytes32[][] memory keyTup * Note: this module only supports up to 5 composite keys. */ - Schema schema = StoreSwitch.getKeySchema(tableId); - - uint256 numFields = schema.numFields(); + Schema keySchema = StoreSwitch.getKeySchema(tableId); + uint256 numFields = keySchema.numFields(); uint256 length = KeysInTable.lengthKeys0(tableId); keyTuples = new bytes32[][](length); for (uint256 i; i < length; i++) { - keyTuples[i] = new bytes32[](numFields); // the length of the key tuple depends on the schema + keyTuples[i] = new bytes32[](numFields); // the length of the key tuple depends on the key schema if (numFields > 0) { keyTuples[i][0] = KeysInTable.getItemKeys0(tableId, i); @@ -53,14 +52,14 @@ function getKeysInTable(IStore store, bytes32 tableId) view returns (bytes32[][] * Note: this module only supports up to 5 composite keys. */ - Schema schema = store.getKeySchema(tableId); + Schema keySchema = store.getKeySchema(tableId); - uint256 numFields = schema.numFields(); + uint256 numFields = keySchema.numFields(); uint256 length = KeysInTable.lengthKeys0(store, tableId); keyTuples = new bytes32[][](length); for (uint256 i; i < length; i++) { - keyTuples[i] = new bytes32[](numFields); // the length of the key tuple depends on the schema + keyTuples[i] = new bytes32[](numFields); // the length of the key tuple depends on the key schema if (numFields > 0) { keyTuples[i][0] = KeysInTable.getItemKeys0(store, tableId, i); diff --git a/packages/world/src/modules/keysintable/tables/KeysInTable.sol b/packages/world/src/modules/keysintable/tables/KeysInTable.sol index 0840d6c228..fe4a0ef4f6 100644 --- a/packages/world/src/modules/keysintable/tables/KeysInTable.sol +++ b/packages/world/src/modules/keysintable/tables/KeysInTable.sol @@ -39,22 +39,22 @@ library KeysInTable { /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](1); - _schema[0] = SchemaType.BYTES32; + SchemaType[] memory _keySchema = new SchemaType[](1); + _keySchema[0] = SchemaType.BYTES32; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_keySchema); } /** Get the table's value schema */ function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](5); - _schema[0] = SchemaType.BYTES32_ARRAY; - _schema[1] = SchemaType.BYTES32_ARRAY; - _schema[2] = SchemaType.BYTES32_ARRAY; - _schema[3] = SchemaType.BYTES32_ARRAY; - _schema[4] = SchemaType.BYTES32_ARRAY; - - return SchemaLib.encode(_schema); + SchemaType[] memory _valueSchema = new SchemaType[](5); + _valueSchema[0] = SchemaType.BYTES32_ARRAY; + _valueSchema[1] = SchemaType.BYTES32_ARRAY; + _valueSchema[2] = SchemaType.BYTES32_ARRAY; + _valueSchema[3] = SchemaType.BYTES32_ARRAY; + _valueSchema[4] = SchemaType.BYTES32_ARRAY; + + return SchemaLib.encode(_valueSchema); } /** Get the table's key names */ diff --git a/packages/world/src/modules/keysintable/tables/UsedKeysIndex.sol b/packages/world/src/modules/keysintable/tables/UsedKeysIndex.sol index 724610a783..b29e54cab8 100644 --- a/packages/world/src/modules/keysintable/tables/UsedKeysIndex.sol +++ b/packages/world/src/modules/keysintable/tables/UsedKeysIndex.sol @@ -33,20 +33,20 @@ library UsedKeysIndex { /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](2); - _schema[0] = SchemaType.BYTES32; - _schema[1] = SchemaType.BYTES32; + SchemaType[] memory _keySchema = new SchemaType[](2); + _keySchema[0] = SchemaType.BYTES32; + _keySchema[1] = SchemaType.BYTES32; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_keySchema); } /** Get the table's value schema */ function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](2); - _schema[0] = SchemaType.BOOL; - _schema[1] = SchemaType.UINT40; + SchemaType[] memory _valueSchema = new SchemaType[](2); + _valueSchema[0] = SchemaType.BOOL; + _valueSchema[1] = SchemaType.UINT40; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_valueSchema); } /** Get the table's key names */ diff --git a/packages/world/src/modules/keyswithvalue/tables/KeysWithValue.sol b/packages/world/src/modules/keyswithvalue/tables/KeysWithValue.sol index 7ef033db5b..2ae73a6568 100644 --- a/packages/world/src/modules/keyswithvalue/tables/KeysWithValue.sol +++ b/packages/world/src/modules/keyswithvalue/tables/KeysWithValue.sol @@ -28,18 +28,18 @@ library KeysWithValue { /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](1); - _schema[0] = SchemaType.BYTES32; + SchemaType[] memory _keySchema = new SchemaType[](1); + _keySchema[0] = SchemaType.BYTES32; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_keySchema); } /** Get the table's value schema */ function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](1); - _schema[0] = SchemaType.BYTES32_ARRAY; + SchemaType[] memory _valueSchema = new SchemaType[](1); + _valueSchema[0] = SchemaType.BYTES32_ARRAY; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_valueSchema); } /** Get the table's key names */ diff --git a/packages/world/src/modules/std-delegations/tables/CallboundDelegations.sol b/packages/world/src/modules/std-delegations/tables/CallboundDelegations.sol index 3f582631db..a2f0f2519b 100644 --- a/packages/world/src/modules/std-delegations/tables/CallboundDelegations.sol +++ b/packages/world/src/modules/std-delegations/tables/CallboundDelegations.sol @@ -32,21 +32,21 @@ library CallboundDelegations { /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](4); - _schema[0] = SchemaType.ADDRESS; - _schema[1] = SchemaType.ADDRESS; - _schema[2] = SchemaType.BYTES32; - _schema[3] = SchemaType.BYTES32; + SchemaType[] memory _keySchema = new SchemaType[](4); + _keySchema[0] = SchemaType.ADDRESS; + _keySchema[1] = SchemaType.ADDRESS; + _keySchema[2] = SchemaType.BYTES32; + _keySchema[3] = SchemaType.BYTES32; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_keySchema); } /** Get the table's value schema */ function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](1); - _schema[0] = SchemaType.UINT256; + SchemaType[] memory _valueSchema = new SchemaType[](1); + _valueSchema[0] = SchemaType.UINT256; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_valueSchema); } /** Get the table's key names */ diff --git a/packages/world/src/modules/std-delegations/tables/TimeboundDelegations.sol b/packages/world/src/modules/std-delegations/tables/TimeboundDelegations.sol index 40fd73e643..27a2552404 100644 --- a/packages/world/src/modules/std-delegations/tables/TimeboundDelegations.sol +++ b/packages/world/src/modules/std-delegations/tables/TimeboundDelegations.sol @@ -32,19 +32,19 @@ library TimeboundDelegations { /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](2); - _schema[0] = SchemaType.ADDRESS; - _schema[1] = SchemaType.ADDRESS; + SchemaType[] memory _keySchema = new SchemaType[](2); + _keySchema[0] = SchemaType.ADDRESS; + _keySchema[1] = SchemaType.ADDRESS; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_keySchema); } /** Get the table's value schema */ function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](1); - _schema[0] = SchemaType.UINT256; + SchemaType[] memory _valueSchema = new SchemaType[](1); + _valueSchema[0] = SchemaType.UINT256; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_valueSchema); } /** Get the table's key names */ diff --git a/packages/world/src/modules/uniqueentity/tables/UniqueEntity.sol b/packages/world/src/modules/uniqueentity/tables/UniqueEntity.sol index 7adfa3d80d..092bde6646 100644 --- a/packages/world/src/modules/uniqueentity/tables/UniqueEntity.sol +++ b/packages/world/src/modules/uniqueentity/tables/UniqueEntity.sol @@ -29,17 +29,17 @@ library UniqueEntity { /** Get the table's key schema */ 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); } /** Get the table's value schema */ function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](1); - _schema[0] = SchemaType.UINT256; + SchemaType[] memory _valueSchema = new SchemaType[](1); + _valueSchema[0] = SchemaType.UINT256; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_valueSchema); } /** Get the table's key names */ diff --git a/packages/world/src/tables/Delegations.sol b/packages/world/src/tables/Delegations.sol index bdc5bf5f4f..5889c445bd 100644 --- a/packages/world/src/tables/Delegations.sol +++ b/packages/world/src/tables/Delegations.sol @@ -32,19 +32,19 @@ library Delegations { /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](2); - _schema[0] = SchemaType.ADDRESS; - _schema[1] = SchemaType.ADDRESS; + SchemaType[] memory _keySchema = new SchemaType[](2); + _keySchema[0] = SchemaType.ADDRESS; + _keySchema[1] = SchemaType.ADDRESS; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_keySchema); } /** Get the table's value schema */ function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](1); - _schema[0] = SchemaType.BYTES32; + SchemaType[] memory _valueSchema = new SchemaType[](1); + _valueSchema[0] = SchemaType.BYTES32; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_valueSchema); } /** Get the table's key names */ diff --git a/packages/world/src/tables/InstalledModules.sol b/packages/world/src/tables/InstalledModules.sol index 9a010b508d..9a03d507fa 100644 --- a/packages/world/src/tables/InstalledModules.sol +++ b/packages/world/src/tables/InstalledModules.sol @@ -36,19 +36,19 @@ library InstalledModules { /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](2); - _schema[0] = SchemaType.BYTES16; - _schema[1] = SchemaType.BYTES32; + SchemaType[] memory _keySchema = new SchemaType[](2); + _keySchema[0] = SchemaType.BYTES16; + _keySchema[1] = SchemaType.BYTES32; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_keySchema); } /** Get the table's value schema */ function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](1); - _schema[0] = SchemaType.ADDRESS; + SchemaType[] memory _valueSchema = new SchemaType[](1); + _valueSchema[0] = SchemaType.ADDRESS; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_valueSchema); } /** Get the table's key names */ diff --git a/packages/world/src/tables/NamespaceOwner.sol b/packages/world/src/tables/NamespaceOwner.sol index 3a57ea199a..54033da9dd 100644 --- a/packages/world/src/tables/NamespaceOwner.sol +++ b/packages/world/src/tables/NamespaceOwner.sol @@ -32,18 +32,18 @@ library NamespaceOwner { /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](1); - _schema[0] = SchemaType.BYTES16; + SchemaType[] memory _keySchema = new SchemaType[](1); + _keySchema[0] = SchemaType.BYTES16; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_keySchema); } /** Get the table's value schema */ function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](1); - _schema[0] = SchemaType.ADDRESS; + SchemaType[] memory _valueSchema = new SchemaType[](1); + _valueSchema[0] = SchemaType.ADDRESS; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_valueSchema); } /** Get the table's key names */ diff --git a/packages/world/src/tables/ResourceAccess.sol b/packages/world/src/tables/ResourceAccess.sol index 529c849038..f53abae8e7 100644 --- a/packages/world/src/tables/ResourceAccess.sol +++ b/packages/world/src/tables/ResourceAccess.sol @@ -32,19 +32,19 @@ library ResourceAccess { /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](2); - _schema[0] = SchemaType.BYTES32; - _schema[1] = SchemaType.ADDRESS; + SchemaType[] memory _keySchema = new SchemaType[](2); + _keySchema[0] = SchemaType.BYTES32; + _keySchema[1] = SchemaType.ADDRESS; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_keySchema); } /** Get the table's value schema */ function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](1); - _schema[0] = SchemaType.BOOL; + SchemaType[] memory _valueSchema = new SchemaType[](1); + _valueSchema[0] = SchemaType.BOOL; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_valueSchema); } /** Get the table's key names */ diff --git a/packages/world/test/tables/AddressArray.sol b/packages/world/test/tables/AddressArray.sol index 1daf1d0d6c..004e97be40 100644 --- a/packages/world/test/tables/AddressArray.sol +++ b/packages/world/test/tables/AddressArray.sol @@ -28,18 +28,18 @@ library AddressArray { /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](1); - _schema[0] = SchemaType.BYTES32; + SchemaType[] memory _keySchema = new SchemaType[](1); + _keySchema[0] = SchemaType.BYTES32; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_keySchema); } /** Get the table's value schema */ function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](1); - _schema[0] = SchemaType.ADDRESS_ARRAY; + SchemaType[] memory _valueSchema = new SchemaType[](1); + _valueSchema[0] = SchemaType.ADDRESS_ARRAY; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_valueSchema); } /** Get the table's key names */ diff --git a/packages/world/test/tables/Bool.sol b/packages/world/test/tables/Bool.sol index 73f02fd1af..955432d6b9 100644 --- a/packages/world/test/tables/Bool.sol +++ b/packages/world/test/tables/Bool.sol @@ -29,17 +29,17 @@ library Bool { /** Get the table's key schema */ 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); } /** Get the table's value schema */ function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](1); - _schema[0] = SchemaType.BOOL; + SchemaType[] memory _valueSchema = new SchemaType[](1); + _valueSchema[0] = SchemaType.BOOL; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_valueSchema); } /** Get the table's key names */ diff --git a/packages/world/ts/register/index.test.ts b/packages/world/ts/register/index.test.ts index 454855a828..71d4d0c8e7 100644 --- a/packages/world/ts/register/index.test.ts +++ b/packages/world/ts/register/index.test.ts @@ -8,7 +8,7 @@ test("resolveWorldConfig requires unique table and system names", () => { mudConfig({ tables: { Selector: { - schema: "uint256", + valueSchema: "uint256", }, }, systems: { diff --git a/templates/phaser/packages/contracts/mud.config.ts b/templates/phaser/packages/contracts/mud.config.ts index 1dc8d7e90f..70edda1693 100644 --- a/templates/phaser/packages/contracts/mud.config.ts +++ b/templates/phaser/packages/contracts/mud.config.ts @@ -4,7 +4,7 @@ export default mudConfig({ tables: { Counter: { keySchema: {}, - schema: "uint32", + valueSchema: "uint32", }, }, }); diff --git a/templates/phaser/packages/contracts/src/codegen/tables/Counter.sol b/templates/phaser/packages/contracts/src/codegen/tables/Counter.sol index afb08c8ee5..302b905c36 100644 --- a/templates/phaser/packages/contracts/src/codegen/tables/Counter.sol +++ b/templates/phaser/packages/contracts/src/codegen/tables/Counter.sol @@ -32,17 +32,17 @@ library Counter { /** Get the table's key schema */ 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); } /** Get the table's value schema */ function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](1); - _schema[0] = SchemaType.UINT32; + SchemaType[] memory _valueSchema = new SchemaType[](1); + _valueSchema[0] = SchemaType.UINT32; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_valueSchema); } /** Get the table's key names */ diff --git a/templates/react/packages/contracts/mud.config.ts b/templates/react/packages/contracts/mud.config.ts index 1dc8d7e90f..70edda1693 100644 --- a/templates/react/packages/contracts/mud.config.ts +++ b/templates/react/packages/contracts/mud.config.ts @@ -4,7 +4,7 @@ export default mudConfig({ tables: { Counter: { keySchema: {}, - schema: "uint32", + valueSchema: "uint32", }, }, }); diff --git a/templates/react/packages/contracts/src/codegen/tables/Counter.sol b/templates/react/packages/contracts/src/codegen/tables/Counter.sol index afb08c8ee5..302b905c36 100644 --- a/templates/react/packages/contracts/src/codegen/tables/Counter.sol +++ b/templates/react/packages/contracts/src/codegen/tables/Counter.sol @@ -32,17 +32,17 @@ library Counter { /** Get the table's key schema */ 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); } /** Get the table's value schema */ function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](1); - _schema[0] = SchemaType.UINT32; + SchemaType[] memory _valueSchema = new SchemaType[](1); + _valueSchema[0] = SchemaType.UINT32; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_valueSchema); } /** Get the table's key names */ diff --git a/templates/threejs/packages/contracts/mud.config.ts b/templates/threejs/packages/contracts/mud.config.ts index 3a04487138..6ee5c6a809 100644 --- a/templates/threejs/packages/contracts/mud.config.ts +++ b/templates/threejs/packages/contracts/mud.config.ts @@ -3,7 +3,7 @@ import { mudConfig } from "@latticexyz/world/register"; export default mudConfig({ tables: { Position: { - schema: { + valueSchema: { x: "int32", y: "int32", z: "int32", diff --git a/templates/threejs/packages/contracts/src/codegen/tables/Position.sol b/templates/threejs/packages/contracts/src/codegen/tables/Position.sol index ab4731aba7..fa15b967dc 100644 --- a/templates/threejs/packages/contracts/src/codegen/tables/Position.sol +++ b/templates/threejs/packages/contracts/src/codegen/tables/Position.sol @@ -40,20 +40,20 @@ library Position { /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](1); - _schema[0] = SchemaType.BYTES32; + SchemaType[] memory _keySchema = new SchemaType[](1); + _keySchema[0] = SchemaType.BYTES32; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_keySchema); } /** Get the table's value schema */ function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](3); - _schema[0] = SchemaType.INT32; - _schema[1] = SchemaType.INT32; - _schema[2] = SchemaType.INT32; + SchemaType[] memory _valueSchema = new SchemaType[](3); + _valueSchema[0] = SchemaType.INT32; + _valueSchema[1] = SchemaType.INT32; + _valueSchema[2] = SchemaType.INT32; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_valueSchema); } /** Get the table's key names */ diff --git a/templates/vanilla/packages/contracts/mud.config.ts b/templates/vanilla/packages/contracts/mud.config.ts index 1dc8d7e90f..70edda1693 100644 --- a/templates/vanilla/packages/contracts/mud.config.ts +++ b/templates/vanilla/packages/contracts/mud.config.ts @@ -4,7 +4,7 @@ export default mudConfig({ tables: { Counter: { keySchema: {}, - schema: "uint32", + valueSchema: "uint32", }, }, }); diff --git a/templates/vanilla/packages/contracts/src/codegen/tables/Counter.sol b/templates/vanilla/packages/contracts/src/codegen/tables/Counter.sol index afb08c8ee5..302b905c36 100644 --- a/templates/vanilla/packages/contracts/src/codegen/tables/Counter.sol +++ b/templates/vanilla/packages/contracts/src/codegen/tables/Counter.sol @@ -32,17 +32,17 @@ library Counter { /** Get the table's key schema */ 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); } /** Get the table's value schema */ function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](1); - _schema[0] = SchemaType.UINT32; + SchemaType[] memory _valueSchema = new SchemaType[](1); + _valueSchema[0] = SchemaType.UINT32; - return SchemaLib.encode(_schema); + return SchemaLib.encode(_valueSchema); } /** Get the table's key names */