Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli,recs,std-client): update RECS components with v2 key/value schemas #1195

Merged
merged 10 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/weak-mails-cross.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@latticexyz/cli": patch
"@latticexyz/recs": patch
"@latticexyz/std-client": patch
---

update RECS components with v2 key/value schemas
41 changes: 24 additions & 17 deletions e2e/packages/client-vanilla/src/mud/contractComponents.ts
Original file line number Diff line number Diff line change
@@ -1,70 +1,77 @@
/* Autogenerated file. Do not edit manually. */

import { TableId } from "@latticexyz/common";
import { defineComponent, Type as RecsType, World } from "@latticexyz/recs";

export function defineContractComponents(world: World) {
return {
Number: (() => {
const tableId = new TableId("", "Number");
return defineComponent(
world,
{
value: RecsType.Number,
},
{
id: "0x000000000000000000000000000000004e756d62657200000000000000000000",
metadata: {
contractId: tableId.toHex(),
tableId: tableId.toString(),
componentName: "Number",
tableName: ":Number",
keySchema: { key: "uint32" },
valueSchema: { value: "uint32" },
},
}
} as const
);
})(),
Vector: (() => {
const tableId = new TableId("", "Vector");
return defineComponent(
world,
{
x: RecsType.Number,
y: RecsType.Number,
},
{
id: "0x00000000000000000000000000000000566563746f7200000000000000000000",
metadata: {
contractId: tableId.toHex(),
tableId: tableId.toString(),
componentName: "Vector",
tableName: ":Vector",
keySchema: { key: "uint32" },
valueSchema: { x: "int32", y: "int32" },
},
}
} as const
);
})(),
NumberList: (() => {
const tableId = new TableId("", "NumberList");
return defineComponent(
world,
{
value: RecsType.NumberArray,
},
{
id: "0x000000000000000000000000000000004e756d6265724c697374000000000000",
metadata: {
contractId: tableId.toHex(),
tableId: tableId.toString(),
componentName: "NumberList",
tableName: ":NumberList",
keySchema: {},
valueSchema: { value: "uint32[]" },
},
}
} as const
);
})(),
Multi: (() => {
const tableId = new TableId("", "Multi");
return defineComponent(
world,
{
num: RecsType.BigInt,
value: RecsType.Boolean,
},
{
id: "0x000000000000000000000000000000004d756c74690000000000000000000000",
metadata: {
contractId: tableId.toHex(),
tableId: tableId.toString(),
componentName: "Multi",
tableName: ":Multi",
keySchema: { a: "uint32", b: "bool", c: "uint256", d: "int120" },
valueSchema: { num: "int256", value: "bool" },
},
}
} as const
);
})(),
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,53 +1,62 @@
/* Autogenerated file. Do not edit manually. */

import { TableId } from "@latticexyz/common";
import { defineComponent, Type as RecsType, World } from "@latticexyz/recs";

export function defineContractComponents(world: World) {
return {
CounterTable: (() => {
const tableId = new TableId("", "CounterTable");
return defineComponent(
world,
{
value: RecsType.Number,
},
{
id: "0x00000000000000000000000000000000436f756e7465725461626c6500000000",
metadata: {
contractId: tableId.toHex(),
tableId: tableId.toString(),
componentName: "CounterTable",
tableName: ":CounterTable",
keySchema: { key: "bytes32" },
valueSchema: { value: "uint32" },
},
}
} as const
);
})(),
MessageTable: (() => {
const tableId = new TableId("", "MessageTable");
return defineComponent(
world,
{
value: RecsType.String,
},
{
id: "0x000000000000000000000000000000004d6573736167655461626c6500000000",
metadata: {
contractId: tableId.toHex(),
tableId: tableId.toString(),
componentName: "MessageTable",
tableName: ":MessageTable",
keySchema: {},
valueSchema: { value: "string" },
},
}
} as const
);
})(),
Inventory: (() => {
const tableId = new TableId("", "Inventory");
return defineComponent(
world,
{
amount: RecsType.Number,
},
{
id: "0x00000000000000000000000000000000496e76656e746f727900000000000000",
metadata: {
contractId: tableId.toHex(),
tableId: tableId.toString(),
componentName: "Inventory",
tableName: ":Inventory",
keySchema: {
owner: "address",
item: "uint32",
itemVariant: "uint32",
},
valueSchema: { amount: "uint32" },
},
}
} as const
);
})(),
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,53 +1,62 @@
/* Autogenerated file. Do not edit manually. */

import { TableId } from "@latticexyz/common";
import { defineComponent, Type as RecsType, World } from "@latticexyz/recs";

export function defineContractComponents(world: World) {
return {
CounterTable: (() => {
const tableId = new TableId("", "CounterTable");
return defineComponent(
world,
{
value: RecsType.Number,
},
{
id: "0x00000000000000000000000000000000436f756e7465725461626c6500000000",
metadata: {
contractId: tableId.toHex(),
tableId: tableId.toString(),
componentName: "CounterTable",
tableName: ":CounterTable",
keySchema: { key: "bytes32" },
valueSchema: { value: "uint32" },
},
}
} as const
);
})(),
MessageTable: (() => {
const tableId = new TableId("", "MessageTable");
return defineComponent(
world,
{
value: RecsType.String,
},
{
id: "0x000000000000000000000000000000004d6573736167655461626c6500000000",
metadata: {
contractId: tableId.toHex(),
tableId: tableId.toString(),
componentName: "MessageTable",
tableName: ":MessageTable",
keySchema: {},
valueSchema: { value: "string" },
},
}
} as const
);
})(),
Inventory: (() => {
const tableId = new TableId("", "Inventory");
return defineComponent(
world,
{
amount: RecsType.Number,
},
{
id: "0x00000000000000000000000000000000496e76656e746f727900000000000000",
metadata: {
contractId: tableId.toHex(),
tableId: tableId.toString(),
componentName: "Inventory",
tableName: ":Inventory",
keySchema: {
owner: "address",
item: "uint32",
itemVariant: "uint32",
},
valueSchema: { amount: "uint32" },
},
}
} as const
);
})(),
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,53 +1,62 @@
/* Autogenerated file. Do not edit manually. */

import { TableId } from "@latticexyz/common";
import { defineComponent, Type as RecsType, World } from "@latticexyz/recs";

export function defineContractComponents(world: World) {
return {
CounterTable: (() => {
const tableId = new TableId("", "CounterTable");
return defineComponent(
world,
{
value: RecsType.Number,
},
{
id: "0x00000000000000000000000000000000436f756e7465725461626c6500000000",
metadata: {
contractId: tableId.toHex(),
tableId: tableId.toString(),
componentName: "CounterTable",
tableName: ":CounterTable",
keySchema: { key: "bytes32" },
valueSchema: { value: "uint32" },
},
}
} as const
);
})(),
MessageTable: (() => {
const tableId = new TableId("", "MessageTable");
return defineComponent(
world,
{
value: RecsType.String,
},
{
id: "0x000000000000000000000000000000004d6573736167655461626c6500000000",
metadata: {
contractId: tableId.toHex(),
tableId: tableId.toString(),
componentName: "MessageTable",
tableName: ":MessageTable",
keySchema: {},
valueSchema: { value: "string" },
},
}
} as const
);
})(),
Inventory: (() => {
const tableId = new TableId("", "Inventory");
return defineComponent(
world,
{
amount: RecsType.Number,
},
{
id: "0x00000000000000000000000000000000496e76656e746f727900000000000000",
metadata: {
contractId: tableId.toHex(),
tableId: tableId.toString(),
componentName: "Inventory",
tableName: ":Inventory",
keySchema: {
owner: "address",
item: "uint32",
itemVariant: "uint32",
},
valueSchema: { amount: "uint32" },
},
}
} as const
);
})(),
};
Expand Down
18 changes: 18 additions & 0 deletions packages/cli/src/render-ts/recsV1TableOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { StoreConfig } from "@latticexyz/store";
import { resolveAbiOrUserType } from "@latticexyz/store/codegen";
import { schemaTypesToRecsTypeStrings } from "./schemaTypesToRecsTypeStrings";
import { RecsV1TableOptions } from "./types";
import { SchemaTypeToAbiType } from "@latticexyz/schema-type/deprecated";
import { StaticAbiType } from "@latticexyz/schema-type";

export function getRecsV1TableOptions(config: StoreConfig): RecsV1TableOptions {
const tableOptions = [];
Expand All @@ -27,8 +29,24 @@ export function getRecsV1TableOptions(config: StoreConfig): RecsV1TableOptions {
name: tableData.name,
};

// TODO: move user type -> abi type into our config expanding step rather than sprinkled everywhere
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's create an issue for this to keep track of the TODO

const keySchema = Object.fromEntries(
Object.entries(tableData.keySchema).map(([name, type]) => [
name,
SchemaTypeToAbiType[resolveAbiOrUserType(type, config).schemaType] as StaticAbiType,
])
);
const valueSchema = Object.fromEntries(
Object.entries(tableData.schema).map(([name, type]) => [
name,
SchemaTypeToAbiType[resolveAbiOrUserType(type, config).schemaType],
])
);

tableOptions.push({
tableName,
keySchema,
valueSchema,
fields,
staticResourceData,
});
Expand Down
Loading