Skip to content

Commit

Permalink
fix(world): disable namespaces in defineWorld (#2498)
Browse files Browse the repository at this point in the history
  • Loading branch information
alvrs authored Mar 21, 2024
1 parent c9ee5e4 commit bde8bd6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 23 deletions.
24 changes: 13 additions & 11 deletions packages/world/ts/config/v2/world.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, it } from "vitest";
import { defineWorld, defineWorldWithoutNamespaces } from "./world";
import { defineWorld } from "./world";
import { attest } from "@arktype/attest";
import { resourceToHex } from "@latticexyz/common";
import {
Expand All @@ -14,6 +14,7 @@ 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 @@ -68,6 +69,7 @@ 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 @@ -134,6 +136,7 @@ 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 @@ -163,6 +166,7 @@ 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 @@ -677,16 +681,16 @@ describe("defineWorld", () => {
).throwsAndHasTypeError("Overrides of `name` and `namespace` are not allowed for tables in a store config");
});

it("should throw if name is overridden in namespaced tables", () => {
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 @@ -696,16 +700,16 @@ describe("defineWorld", () => {
).throwsAndHasTypeError("Overrides of `name` and `namespace` are not allowed for tables in a store config");
});

it("should throw if namespace is overridden in namespaced tables", () => {
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 @@ -714,15 +718,13 @@ describe("defineWorld", () => {
}),
).throwsAndHasTypeError("Overrides of `name` and `namespace` are not allowed for tables in a store config");
});
});

describe("defineWorldWithoutNamespaces", () => {
it("should throw if namespaces are defined", () => {
it("should throw if namespaces are defined (TODO: remove once namespaces support ships)", () => {
attest(() =>
defineWorldWithoutNamespaces({
// @ts-expect-error Namespaces will be enabled soon
defineWorld({
// @ts-expect-error TODO: remove once namespaces support ships
namespaces: {},
}),
).type.errors("Namespaces will be enabled soon");
).type.errors("Namespaces config will be enabled soon.");
});
});
15 changes: 4 additions & 11 deletions packages/world/ts/config/v2/world.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { conform, evaluate, narrow } from "@arktype/util";
import { ErrorMessage, conform, evaluate, narrow } from "@arktype/util";
import {
UserTypes,
extendedScope,
Expand All @@ -17,7 +17,7 @@ import { SystemsInput, WorldInput } from "./input";
import { CONFIG_DEFAULTS } from "./defaults";
import { Tables } from "@latticexyz/store/internal";
import { resolveSystems } from "./systems";
import { resolveNamespacedTables, validateNamespaces } from "./namespaces";
import { resolveNamespacedTables } from "./namespaces";
import { resolveCodegen } from "./codegen";
import { resolveDeploy } from "./deploy";

Expand All @@ -29,7 +29,8 @@ export type validateWorld<world> = {
: key extends "enums"
? narrow<world[key]>
: key extends "namespaces"
? validateNamespaces<world[key], extendedScope<world>>
? // ? validateNamespaces<world[key], extendedScope<world>>
ErrorMessage<`Namespaces config will be enabled soon.`>
: key extends keyof WorldInput
? conform<world[key], WorldInput[key]>
: world[key];
Expand Down Expand Up @@ -108,11 +109,3 @@ export function defineWorld<const world>(world: validateWorld<world>): resolveWo
validateWorld(world);
return resolveWorld(world) as unknown as resolveWorld<world>;
}

// Temporary external export of defineWorld with namespaces disabled
export function defineWorldWithoutNamespaces<const world>(
world: validateWorld<world> & { namespaces?: `Namespaces will be enabled soon` },
): resolveWorld<world> {
validateWorld(world);
return resolveWorld(world) as unknown as resolveWorld<world>;
}
2 changes: 1 addition & 1 deletion packages/world/ts/exports/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@

export { helloWorldEvent, worldDeployedEvent } from "../worldEvents";

export { defineWorldWithoutNamespaces as defineWorld } from "../config/v2/world";
export { defineWorld } from "../config/v2/world";
export type { World } from "../config/v2/output";

0 comments on commit bde8bd6

Please sign in to comment.