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(world): enable config namespaces key #2880

Closed
wants to merge 77 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
fad51ed
fix(world): namespaces table key must be a valid tables config
yonadaaa May 30, 2024
b4c3d30
feat(world): enable namespaces key
yonadaaa May 30, 2024
1f45e31
feat: default namespaceDirectories
yonadaaa May 30, 2024
7bd6dd7
fix: check if world.namespaces is defined
yonadaaa May 30, 2024
d2f2aec
fix: output directory for namespaces
yonadaaa May 30, 2024
3002556
fix: types
yonadaaa May 30, 2024
42ea56b
refactor: do not mutate input object
yonadaaa May 31, 2024
7257b96
fix: codegen default
yonadaaa May 31, 2024
2e99abb
fix: better error
yonadaaa May 31, 2024
97838a1
refactor: indexFilename can be false
yonadaaa May 31, 2024
1bedd85
chore: minimal example has no index
yonadaaa May 31, 2024
9b884d4
chore: example with codegen set
yonadaaa May 31, 2024
e9e3880
refactor: resolvedStore suggestion
yonadaaa May 31, 2024
75a7726
chore: move example
yonadaaa May 31, 2024
fa16add
chore: reset example
yonadaaa May 31, 2024
50df7bb
chore: build
yonadaaa May 31, 2024
6e0189a
chore: delete changelog
yonadaaa May 31, 2024
589c386
fix: package name
yonadaaa May 31, 2024
ffa7dc5
fix: types
yonadaaa May 31, 2024
6ce578e
chore: change test namespace
yonadaaa May 31, 2024
348d43e
fix: do not default namespaces key when resolving with shorthand
yonadaaa Jun 4, 2024
c6d8f1a
refactor: if statement
yonadaaa Jun 4, 2024
ff619ab
chore: changeset
yonadaaa Jun 4, 2024
c7e2559
feat: move example project
yonadaaa Jun 4, 2024
1d9866e
chore: remove unused interface
yonadaaa Jun 4, 2024
6d52753
chore: multiple namespaces in example
yonadaaa Jun 4, 2024
819b9fc
refactor: dashes in key name
yonadaaa Jun 4, 2024
5f0df8a
chore: systems in example
yonadaaa Jun 4, 2024
4dd7a43
refactor: empty string
yonadaaa Jun 4, 2024
0483ce3
refactor: do not rely on codegenIndexFilename
yonadaaa Jun 4, 2024
0a7e500
refactor: remove codegenIndexFilename
yonadaaa Jun 4, 2024
09bc274
test: attempt to fix world test
yonadaaa Jun 4, 2024
625cbaf
fix: use generic types
yonadaaa Jun 4, 2024
87f0dc2
fix: test outputDirectory
yonadaaa Jun 4, 2024
f73355b
Merge remote-tracking branch 'origin/main' into yonadaaa/fix-tables-w…
yonadaaa Jun 5, 2024
0d1c6ac
test: remove test object
yonadaaa Jun 5, 2024
2f196e2
Merge remote-tracking branch 'origin/main' into yonadaaa/fix-tables-w…
yonadaaa Jun 5, 2024
5a07319
chore: update example
yonadaaa Jun 5, 2024
463f6cd
Merge remote-tracking branch 'origin/main' into yonadaaa/fix-tables-w…
yonadaaa Jun 5, 2024
fb7fe89
chore: fix files
yonadaaa Jun 5, 2024
c3fa203
Merge remote-tracking branch 'origin/main' into yonadaaa/fix-tables-w…
yonadaaa Jun 5, 2024
a5aed4d
fix: add back workspace file
yonadaaa Jun 5, 2024
0138900
chore: delete weird file
yonadaaa Jun 5, 2024
15505f1
chore: build
yonadaaa Jun 5, 2024
74c443b
feat: throw error if using both keys
yonadaaa Jun 5, 2024
6ac5968
feat(world): can only use namespace or namespaces
yonadaaa Jun 5, 2024
ca20438
test: delete unused test
yonadaaa Jun 5, 2024
7a5e93f
chore: add example to changest
yonadaaa Jun 6, 2024
adbe5fc
test: add test for both keys
yonadaaa Jun 6, 2024
fef3ceb
feat: updated example
yonadaaa Jun 6, 2024
d191134
chore: update example
yonadaaa Jun 6, 2024
869a120
chore: comment
yonadaaa Jun 6, 2024
2b05ec2
test: fix test
yonadaaa Jun 6, 2024
5bd192b
refactor: address constant
yonadaaa Jun 6, 2024
ac2db03
chore: remove comment
yonadaaa Jun 6, 2024
68f841b
chore: review changeset suggestion
yonadaaa Jun 6, 2024
9fb7199
chore: change comment
yonadaaa Jun 6, 2024
9946bbb
fix: update runtime error
yonadaaa Jun 6, 2024
d70361e
test: fix runtime message
yonadaaa Jun 6, 2024
8e74ffe
Merge remote-tracking branch 'origin/main' into yonadaaa/fix-tables-w…
yonadaaa Jun 6, 2024
7fdd67c
chore: remove store from changeset
yonadaaa Jun 6, 2024
b9432a6
feat: deprecate index.sol
yonadaaa Jun 6, 2024
c8e150d
fix: remove index filename from defaults
yonadaaa Jun 6, 2024
1fa222d
fix: deprecate comment
yonadaaa Jun 6, 2024
ea18aaa
refactor: rename plugin namespace
yonadaaa Jun 6, 2024
7304d47
chore: remove access control example
yonadaaa Jun 6, 2024
3d18325
chore: changeset namespace
yonadaaa Jun 7, 2024
8130d10
chore: do not deprecate excludeSystems yet
yonadaaa Jun 7, 2024
76c7fa3
chore: add "revisit pattern" comment
yonadaaa Jun 7, 2024
856a6aa
chore: remove todo comment
yonadaaa Jun 7, 2024
e43978c
fix: better error messages
yonadaaa Jun 7, 2024
fb0a63e
chore: revisit this pattern comment
yonadaaa Jun 7, 2024
1bc9ea2
chore: prettier
yonadaaa Jun 7, 2024
de03bae
fix: check if tables or systems is set with namespaces
yonadaaa Jun 7, 2024
50738f5
fix: check with shorthands
yonadaaa Jun 7, 2024
a93cec6
Merge remote-tracking branch 'origin/main' into yonadaaa/fix-tables-w…
holic Jul 2, 2024
7ed17b9
wip
holic Jul 3, 2024
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
13 changes: 13 additions & 0 deletions examples/minimal/packages/contracts/mud.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ export default defineWorld({
key: ["owner", "item", "itemVariant"],
},
},
namespaces: {
royale: {
yonadaaa marked this conversation as resolved.
Show resolved Hide resolved
tables: {
Health: {
schema: {
player: "address",
value: "uint256",
},
key: ["player"],
},
},
},
},
modules: [
{
artifactPath: "@latticexyz/world-modules/out/KeysWithValueModule.sol/KeysWithValueModule.json",
Expand Down
1 change: 1 addition & 0 deletions examples/minimal/packages/contracts/src/codegen/index.sol

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/world/ts/config/v2/namespaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
getPath,
} from "@latticexyz/store/config/v2";
import { NamespacesInput } from "./input";
import { ErrorMessage } from "@arktype/util";

export type namespacedTableKeys<world> = world extends { namespaces: infer namespaces }
? {
Expand All @@ -23,7 +24,7 @@ export type validateNamespaces<namespaces, scope extends Scope = AbiTypeScope> =
[namespace in keyof namespaces]: {
[key in keyof namespaces[namespace]]: key extends "tables"
? validateTables<namespaces[namespace][key], scope>
: namespaces[namespace][key];
: ErrorMessage<`Expected full tables config.`>;
holic marked this conversation as resolved.
Show resolved Hide resolved
};
};

Expand Down
9 changes: 2 additions & 7 deletions packages/world/ts/config/v2/world.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const CODEGEN_DEFAULTS = { ...STORE_CODEGEN_DEFAULTS, ...WORLD_CODEGEN_DEFAULTS
describe("defineWorld", () => {
it("should resolve namespaced tables", () => {
const config = defineWorld({
// @ts-expect-error TODO: remove once namespaces support ships
namespaces: {
ExampleNamespace: {
tables: {
Expand Down Expand Up @@ -77,7 +76,6 @@ describe("defineWorld", () => {

it("should resolve namespaced table config with user types and enums", () => {
const config = defineWorld({
// @ts-expect-error TODO: remove once namespaces support ships
namespaces: {
ExampleNamespace: {
tables: {
Expand Down Expand Up @@ -150,7 +148,6 @@ describe("defineWorld", () => {

it("should extend the output World type", () => {
const config = defineWorld({
// @ts-expect-error TODO: remove once namespaces support ships
namespaces: {
ExampleNamespace: {
tables: {
Expand Down Expand Up @@ -180,7 +177,6 @@ describe("defineWorld", () => {
it("should not use the global namespace for namespaced tables", () => {
const config = defineWorld({
namespace: "namespace",
// @ts-expect-error TODO: remove once namespaces support ships
namespaces: {
AnotherOne: {
tables: {
Expand Down Expand Up @@ -709,13 +705,13 @@ describe("defineWorld", () => {
it.skip("should throw if name is overridden in namespaced tables", () => {
attest(() =>
defineWorld({
// @ts-expect-error TODO: remove once namespaces support ships
namespaces: {
MyNamespace: {
tables: {
Example: {
schema: { id: "address" },
key: ["id"],
// @ts-expect-error "Overrides of `name` and `namespace` are not allowed for tables in a store config"
name: "NotAllowed",
},
},
Expand All @@ -728,13 +724,13 @@ describe("defineWorld", () => {
it.skip("should throw if namespace is overridden in namespaced tables", () => {
attest(() =>
defineWorld({
// @ts-expect-error TODO: remove once namespaces support ships
namespaces: {
MyNamespace: {
tables: {
Example: {
schema: { id: "address" },
key: ["id"],
// @ts-expect-error "Overrides of `name` and `namespace` are not allowed for tables in a store config"
namespace: "NotAllowed",
},
},
Expand All @@ -747,7 +743,6 @@ describe("defineWorld", () => {
it("should throw if namespaces are defined (TODO: remove once namespaces support ships)", () => {
attest(() =>
defineWorld({
// @ts-expect-error TODO: remove once namespaces support ships
namespaces: {},
}),
).type.errors("Namespaces config will be enabled soon.");
Expand Down
29 changes: 23 additions & 6 deletions packages/world/ts/config/v2/world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { SystemsInput, WorldInput } from "./input";
import { CONFIG_DEFAULTS, MODULE_DEFAULTS } from "./defaults";
import { Tables } from "@latticexyz/store/internal";
import { resolveSystems } from "./systems";
import { resolveNamespacedTables } from "./namespaces";
import { resolveNamespacedTables, validateNamespaces } from "./namespaces";
import { resolveCodegen } from "./codegen";
import { resolveDeploy } from "./deploy";

Expand All @@ -29,8 +29,7 @@ export type validateWorld<world> = {
: key extends "enums"
? narrow<world[key]>
: key extends "namespaces"
? // ? validateNamespaces<world[key], extendedScope<world>>
ErrorMessage<`Namespaces config will be enabled soon.`>
? validateNamespaces<world[key], extendedScope<world>>
: key extends keyof WorldInput
? conform<world[key], WorldInput[key]>
: ErrorMessage<`\`${key & string}\` is not a valid World config option.`>;
Expand Down Expand Up @@ -75,22 +74,40 @@ export function resolveWorld<const world extends WorldInput>(world: world): reso
const scope = extendedScope(world);
const namespaces = world.namespaces ?? {};

if (world.namespaces) {
if (!world.codegen) {
world.codegen = {};
}
if (world.codegen.namespaceDirectories === undefined) {
world.codegen = { ...world.codegen, namespaceDirectories: true };
}
}
holic marked this conversation as resolved.
Show resolved Hide resolved

const resolvedStore = resolveStore(world);

const resolvedNamespacedTables = Object.fromEntries(
Object.entries(namespaces)
.map(([namespaceKey, namespace]) =>
Object.entries(namespace.tables ?? {}).map(([tableKey, table]) => {
validateTable(table, scope);
return [
`${namespaceKey}__${tableKey}`,
resolveTable(mergeIfUndefined(table, { namespace: namespaceKey, name: tableKey }), scope),
resolveTable(
mergeIfUndefined(table, {
namespace: namespaceKey,
name: tableKey,
codegen: mergeIfUndefined(table.codegen ?? {}, {
outputDirectory: resolvedStore.codegen.namespaceDirectories ? `${namespaceKey}/tables` : "tables",
}),
}),
scope,
),
];
}),
)
.flat(),
) as Tables;

const resolvedStore = resolveStore(world);

const modules = (world.modules ?? CONFIG_DEFAULTS.modules).map((mod) => mergeIfUndefined(mod, MODULE_DEFAULTS));

return mergeIfUndefined(
Expand Down
Loading