Skip to content

Commit

Permalink
feat: rename schema to valueSchema (#1482)
Browse files Browse the repository at this point in the history
Co-authored-by: Kevin Ingersoll <kingersoll@gmail.com>
  • Loading branch information
alvrs and holic committed Sep 15, 2023
1 parent 5150544 commit 07dd6f3
Show file tree
Hide file tree
Showing 100 changed files with 559 additions and 520 deletions.
25 changes: 25 additions & 0 deletions .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",
},
},
}
}
```
2 changes: 1 addition & 1 deletion docs/pages/client-side.mdx
Expand Up @@ -24,7 +24,7 @@ const config = mudConfig({
tables: {
NameComponent: "string",
PlayerComponent: "bool",
PositionComponent: { schema: { x: "int32", y: "int32" } },
PositionComponent: { valueSchema: { x: "int32", y: "int32" } },
},
});
```
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/ecs.mdx
Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions docs/pages/quick-start.mdx
Expand Up @@ -81,7 +81,7 @@ export default mudConfig({
tables: {
Counter: {
keySchema: {},
schema: "uint32",
valueSchema: "uint32",
},
},
});
Expand Down Expand Up @@ -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.

Expand All @@ -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.
Expand All @@ -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());
Expand Down
12 changes: 6 additions & 6 deletions docs/pages/store/advanced-features.mdx
Expand Up @@ -17,7 +17,7 @@ export default mudConfig({
tables: {
CounterSingleton: {
keySchema: {},
schema: "uint256",
valueSchema: "uint256",
},
},
});
Expand Down Expand Up @@ -48,7 +48,7 @@ import { mudConfig } from "@latticexyz/store/register";
export default mudConfig({
tables: {
TradeExecuted: {
schema: {
valueSchema: {
amount: "uint32",
receiver: "bytes32",
},
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
```

Expand Down
12 changes: 6 additions & 6 deletions docs/pages/store/config.mdx
Expand Up @@ -46,7 +46,7 @@ import { mudConfig } from "@latticexyz/store/register";
export default mudConfig({
tables: {
MyTable: {
schema: {
valueSchema: {
value: "uint32",
},
},
Expand All @@ -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`”)

Expand All @@ -86,7 +86,7 @@ Example:
```tsx
tables: {
MyTableWithTwoKeys: {
schema: {
valueSchema: {
value1: "uint32",
value2: "uint32",
},
Expand All @@ -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",
Expand Down Expand Up @@ -135,7 +135,7 @@ Example:
```tsx
tables: {
MySingletonTable: {
schema: {
valueSchema: {
value1: "uint32",
value2: "uint32",
},
Expand Down
8 changes: 4 additions & 4 deletions docs/pages/store/reading-and-writing.mdx
Expand Up @@ -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
Expand Down Expand Up @@ -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",
},
Expand Down Expand Up @@ -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)));
```
Expand Down
19 changes: 13 additions & 6 deletions docs/pages/store/using-without-world.mdx
Expand Up @@ -42,7 +42,7 @@ import { mudConfig } from "@latticexyz/store/register";
export default mudConfig({
tables: {
MyTable: {
schema: {
valueSchema: {
field1: "uint256",
field2: "uint256",
},
Expand Down Expand Up @@ -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);
}
}
```
20 changes: 10 additions & 10 deletions docs/pages/tutorials/emojimon/a-wild-emojimon-appears.mdx
Expand Up @@ -46,7 +46,7 @@ export default mudConfig({
keySchema: {
player: "bytes32",
},
schema: {
valueSchema: {
exists: "bool",
monster: "bytes32",
catchAttempts: "uint256",
Expand All @@ -57,7 +57,7 @@ export default mudConfig({
MapConfig: {
keySchema: {},
dataStruct: false,
schema: {
valueSchema: {
width: "uint32",
height: "uint32",
terrain: "bytes",
Expand All @@ -68,7 +68,7 @@ export default mudConfig({
Player: "bool",
Position: {
dataStruct: false,
schema: {
valueSchema: {
x: "uint32",
y: "uint32",
},
Expand Down Expand Up @@ -523,7 +523,7 @@ export default mudConfig({
keySchema: {
player: "bytes32",
},
schema: {
valueSchema: {
exists: "bool",
monster: "bytes32",
catchAttempts: "uint256",
Expand All @@ -534,7 +534,7 @@ export default mudConfig({
MapConfig: {
keySchema: {},
dataStruct: false,
schema: {
valueSchema: {
width: "uint32",
height: "uint32",
terrain: "bytes",
Expand All @@ -546,7 +546,7 @@ export default mudConfig({
Player: "bool",
Position: {
dataStruct: false,
schema: {
valueSchema: {
x: "uint32",
y: "uint32",
},
Expand Down Expand Up @@ -749,7 +749,7 @@ export default mudConfig({
keySchema: {
player: "bytes32",
},
schema: {
valueSchema: {
exists: "bool",
monster: "bytes32",
catchAttempts: "uint256",
Expand All @@ -760,7 +760,7 @@ export default mudConfig({
MapConfig: {
keySchema: {},
dataStruct: false,
schema: {
valueSchema: {
width: "uint32",
height: "uint32",
terrain: "bytes",
Expand All @@ -772,7 +772,7 @@ export default mudConfig({
keySchema: {
encounter: "bytes32",
},
schema: {
valueSchema: {
result: "MonsterCatchResult",
},
},
Expand All @@ -783,7 +783,7 @@ export default mudConfig({
Player: "bool",
Position: {
dataStruct: false,
schema: {
valueSchema: {
x: "uint32",
y: "uint32",
},
Expand Down
8 changes: 4 additions & 4 deletions docs/pages/tutorials/emojimon/map-and-terrain.mdx
Expand Up @@ -27,7 +27,7 @@ export default mudConfig({
MapConfig: {
keySchema: {},
dataStruct: false,
schema: {
valueSchema: {
width: "uint32",
height: "uint32",
terrain: "bytes",
Expand All @@ -37,7 +37,7 @@ export default mudConfig({
Player: "bool",
Position: {
dataStruct: false,
schema: {
valueSchema: {
x: "uint32",
y: "uint32",
},
Expand Down Expand Up @@ -205,7 +205,7 @@ export default mudConfig({
MapConfig: {
keySchema: {},
dataStruct: false,
schema: {
valueSchema: {
width: "uint32",
height: "uint32",
terrain: "bytes",
Expand All @@ -216,7 +216,7 @@ export default mudConfig({
Player: "bool",
Position: {
dataStruct: false,
schema: {
valueSchema: {
x: "uint32",
y: "uint32",
},
Expand Down
4 changes: 2 additions & 2 deletions docs/pages/tutorials/emojimon/players-and-movement.mdx
Expand Up @@ -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:

Expand All @@ -34,7 +34,7 @@ export default mudConfig({
Player: "bool",
Position: {
dataStruct: false,
schema: {
valueSchema: {
x: "uint32",
y: "uint32",
},
Expand Down

0 comments on commit 07dd6f3

Please sign in to comment.