diff --git a/.changeset/dry-toes-lay.md b/.changeset/dry-toes-lay.md new file mode 100644 index 0000000000..786c32100f --- /dev/null +++ b/.changeset/dry-toes-lay.md @@ -0,0 +1,10 @@ +--- +"@latticexyz/store": patch +"@latticexyz/world": patch +--- + +Minor fixes to config input validations: + +- `systems.openAccess` incorrectly expected `true` as the only valid input. It now allows `boolean`. +- The config complained if parts of it were defined `as const` outside the config input. This is now possible. +- Shorthand inputs are now enabled. diff --git a/packages/store/package.json b/packages/store/package.json index 26da6936b7..3aa4528479 100644 --- a/packages/store/package.json +++ b/packages/store/package.json @@ -59,7 +59,7 @@ "test:ci": "pnpm run test" }, "dependencies": { - "@arktype/util": "0.0.25", + "@arktype/util": "0.0.27", "@latticexyz/common": "workspace:*", "@latticexyz/config": "workspace:*", "@latticexyz/protocol-parser": "workspace:*", diff --git a/packages/store/ts/config/v2/input.ts b/packages/store/ts/config/v2/input.ts index c75f58c088..4fec0c9298 100644 --- a/packages/store/ts/config/v2/input.ts +++ b/packages/store/ts/config/v2/input.ts @@ -38,7 +38,7 @@ export type StoreInput = { export type TableShorthandInput = SchemaInput | string; export type TablesWithShorthandsInput = { - [key: string]: TableInput | TableShorthandInput; + readonly [key: string]: TableInput | TableShorthandInput; }; export type StoreWithShorthandsInput = Omit & { tables: TablesWithShorthandsInput }; diff --git a/packages/store/ts/config/v2/store.test.ts b/packages/store/ts/config/v2/store.test.ts index 21b5ef938c..458f356d6a 100644 --- a/packages/store/ts/config/v2/store.test.ts +++ b/packages/store/ts/config/v2/store.test.ts @@ -495,4 +495,25 @@ describe("defineStore", () => { }), ).throwsAndHasTypeError("Overrides of `name` and `namespace` are not allowed for tables in a store config"); }); + + it("should allow const enum as input", () => { + const enums = { + Example: ["First", "Second"], + } as const; + + attest(defineStore({ enums }).enums).equals(enums); + }); + + it("should allow a const config as input", () => { + const config = { + tables: { + Example: { + schema: { id: "address", name: "string", age: "uint256" }, + key: ["age"], + }, + }, + } as const; + + defineStore(config); + }); }); diff --git a/packages/store/ts/config/v2/table.test.ts b/packages/store/ts/config/v2/table.test.ts index a385fd3812..d617b62803 100644 --- a/packages/store/ts/config/v2/table.test.ts +++ b/packages/store/ts/config/v2/table.test.ts @@ -9,7 +9,7 @@ import { getKeySchema, getValueSchema } from "@latticexyz/protocol-parser/intern describe("validateKeys", () => { it("should return a tuple of valid keys", () => { attest< - ["static"], + readonly ["static"], validateKeys, ["static"]> >(); }); @@ -18,7 +18,7 @@ describe("validateKeys", () => { const scope = extendScope(AbiTypeScope, { static: "address", dynamic: "string" }); attest< - ["static", "customStatic"], + readonly ["static", "customStatic"], validateKeys< getStaticAbiTypeKeys< { static: "uint256"; dynamic: "string"; customStatic: "static"; customDynamic: "dynamic" }, @@ -33,7 +33,7 @@ describe("validateKeys", () => { const scope = extendScope(AbiTypeScope, { static: "address", dynamic: "string" }); attest< - ["static", "customStatic"], + readonly ["static", "customStatic"], validateKeys< getStaticAbiTypeKeys< { static: "uint256"; dynamic: "string"; customStatic: "static"; customDynamic: "dynamic" }, @@ -218,13 +218,13 @@ describe("resolveTable", () => { attest(() => defineTable({ schema: { id: "address" }, - // @ts-expect-error Type 'string' is not assignable to type 'string[]' + // @ts-expect-error Type 'string' is not assignable to type 'readonly string[]' key: "", name: "", }), ) .throws('Invalid key. Expected `("id")[]`, received ``') - .type.errors("Type 'string' is not assignable to type 'string[]'"); + .type.errors("Type 'string' is not assignable to type 'readonly string[]'"); }); it("should throw if a string is provided as schema", () => { diff --git a/packages/store/ts/config/v2/table.ts b/packages/store/ts/config/v2/table.ts index 2f1fd83929..933cd6baad 100644 --- a/packages/store/ts/config/v2/table.ts +++ b/packages/store/ts/config/v2/table.ts @@ -37,11 +37,11 @@ export function isValidPrimaryKey = keys extends string[] +export type validateKeys = keys extends readonly string[] ? { - [i in keyof keys]: keys[i] extends validKeys ? keys[i] : validKeys; + readonly [i in keyof keys]: keys[i] extends validKeys ? keys[i] : validKeys; } - : string[]; + : readonly string[]; export type ValidateTableOptions = { inStoreContext: boolean }; diff --git a/packages/store/ts/exports/index.ts b/packages/store/ts/exports/index.ts index 7048492f24..a44a7a2658 100644 --- a/packages/store/ts/exports/index.ts +++ b/packages/store/ts/exports/index.ts @@ -16,5 +16,5 @@ export { export { storeEventsAbi } from "../storeEventsAbi"; export type { StoreEventsAbi, StoreEventsAbiItem } from "../storeEventsAbi"; -export { defineStore } from "../config/v2/store"; +export { defineStoreWithShorthands as defineStore } from "../config/v2/storeWithShorthands"; export type { Store } from "../config/v2/output"; diff --git a/packages/world/package.json b/packages/world/package.json index 7c977c1064..dfb466f871 100644 --- a/packages/world/package.json +++ b/packages/world/package.json @@ -54,7 +54,7 @@ "test:ci": "pnpm run test" }, "dependencies": { - "@arktype/util": "0.0.25", + "@arktype/util": "0.0.27", "@latticexyz/common": "workspace:*", "@latticexyz/config": "workspace:*", "@latticexyz/schema-type": "workspace:*", diff --git a/packages/world/ts/config/v2/input.ts b/packages/world/ts/config/v2/input.ts index 5769a69c57..6c58dcc0ab 100644 --- a/packages/world/ts/config/v2/input.ts +++ b/packages/world/ts/config/v2/input.ts @@ -14,7 +14,7 @@ export type SystemInput = { */ registerFunctionSelectors?: boolean; /** If openAccess is true, any address can call the system */ - openAccess?: true; + openAccess?: boolean; /** An array of addresses or system names that can access the system */ accessList?: string[]; }; diff --git a/packages/world/ts/config/v2/world.test.ts b/packages/world/ts/config/v2/world.test.ts index 0c06a3b9fe..94ab0f6842 100644 --- a/packages/world/ts/config/v2/world.test.ts +++ b/packages/world/ts/config/v2/world.test.ts @@ -727,4 +727,29 @@ describe("defineWorld", () => { }), ).type.errors("Namespaces config will be enabled soon."); }); + + it("should allow setting openAccess of a system to false", () => { + const config = defineWorld({ + systems: { + Example: { + openAccess: false, + }, + }, + }); + + attest(config.systems.Example.openAccess).equals(false); + }); + + it("should allow a const config as input", () => { + const config = { + tables: { + Example: { + schema: { id: "address", name: "string", age: "uint256" }, + key: ["age"], + }, + }, + } as const; + + defineWorld(config); + }); }); diff --git a/packages/world/ts/config/v2/worldWithShorthands.test.ts b/packages/world/ts/config/v2/worldWithShorthands.test.ts index c992cb36c0..0a186d71f0 100644 --- a/packages/world/ts/config/v2/worldWithShorthands.test.ts +++ b/packages/world/ts/config/v2/worldWithShorthands.test.ts @@ -321,4 +321,17 @@ describe("defineWorldWithShorthands", () => { "Invalid schema. Expected an `id` field with a static ABI type or an explicit `key` option.", ); }); + + it("should allow a const config as input", () => { + const config = { + tables: { + Example: { + schema: { id: "address", name: "string", age: "uint256" }, + key: ["age"], + }, + }, + } as const; + + defineWorldWithShorthands(config); + }); }); diff --git a/packages/world/ts/exports/index.ts b/packages/world/ts/exports/index.ts index 283c71b3e1..254108b7dc 100644 --- a/packages/world/ts/exports/index.ts +++ b/packages/world/ts/exports/index.ts @@ -6,5 +6,5 @@ export { helloWorldEvent, worldDeployedEvent } from "../worldEvents"; -export { defineWorld } from "../config/v2/world"; +export { defineWorldWithShorthands as defineWorld } from "../config/v2/worldWithShorthands"; export type { World } from "../config/v2/output"; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f0d75816be..a107c187a6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -733,8 +733,8 @@ importers: packages/store: dependencies: '@arktype/util': - specifier: 0.0.25 - version: 0.0.25 + specifier: 0.0.27 + version: 0.0.27 '@latticexyz/common': specifier: workspace:* version: link:../common @@ -1028,8 +1028,8 @@ importers: packages/world: dependencies: '@arktype/util': - specifier: 0.0.25 - version: 0.0.25 + specifier: 0.0.27 + version: 0.0.27 '@latticexyz/common': specifier: workspace:* version: link:../common @@ -1243,8 +1243,8 @@ packages: resolution: {integrity: sha512-MwtDGjbgfXWxlExjIL78HvPlWOma1XFEcDd3VWuCPMt/f+3TR7fXyiGFNlIYZGOYdOIU7qgjaE8dmbd6jdJa3Q==} dev: true - /@arktype/util@0.0.25: - resolution: {integrity: sha512-rcUpLkSNC6mA9qSesSL2WvSLzEbyh2VvzeLcywE6i6bp9TPLpB6G3k5cpVjM3bCE6bpZmTR2SR3ybZuQ+tCvbw==} + /@arktype/util@0.0.27: + resolution: {integrity: sha512-ZkPuSU8Q56YVgPInFhojLTujejM+VPfaZx6Guop41CvnozWFOTlC0uAHuDqvY4nYq3zXsMkRwm8LmaRZ3mslMg==} dev: false /@babel/code-frame@7.21.4: