Skip to content

Commit

Permalink
review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
alvrs committed Mar 11, 2024
1 parent d4ee4fe commit 781e02f
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 7 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
{
"extendDefaults": true,
"types": {
// don't throw an error for the empty object type ({})
"{}": false,
},
},
Expand Down
11 changes: 11 additions & 0 deletions packages/store/ts/config/v2/store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe("resolveStoreConfig", () => {
enums: {},
namespace: "",
} as const;

attest<typeof expected>(config);
});

Expand Down Expand Up @@ -74,6 +75,7 @@ describe("resolveStoreConfig", () => {
enums: {},
namespace: "",
} as const;

attest<typeof expected>(config);
});

Expand Down Expand Up @@ -119,6 +121,7 @@ describe("resolveStoreConfig", () => {
enums: {},
namespace: "",
} as const;

attest<typeof expected>(config);
});

Expand Down Expand Up @@ -164,6 +167,7 @@ describe("resolveStoreConfig", () => {
enums: {},
namespace: "",
} as const;

attest<typeof expected>(config);
});

Expand Down Expand Up @@ -247,6 +251,7 @@ describe("resolveStoreConfig", () => {
enums: {},
namespace: "",
} as const;

attest<typeof expected>(config);
});

Expand Down Expand Up @@ -300,6 +305,7 @@ describe("resolveStoreConfig", () => {
enums: {},
namespace: "",
} as const;

attest<typeof expected>(config);
}),
it("it should return the full config given a full config with two primaryKey", () => {
Expand Down Expand Up @@ -351,6 +357,7 @@ describe("resolveStoreConfig", () => {
enums: {},
namespace: "",
} as const;

attest<typeof expected>(config);
});

Expand Down Expand Up @@ -440,6 +447,7 @@ describe("resolveStoreConfig", () => {
enums: {},
namespace: "",
} as const;

attest<typeof expected>(config);
});

Expand Down Expand Up @@ -530,6 +538,7 @@ describe("resolveStoreConfig", () => {
enums: {},
namespace: "",
} as const;

attest<typeof expected>(config);
});

Expand Down Expand Up @@ -637,11 +646,13 @@ describe("resolveStoreConfig", () => {
},
namespace: "",
} as const;

attest<typeof expected>(config);
});

it("should use the root namespace as default namespace", () => {
const config = resolveStoreConfig({ tables: { Example: {} } });

attest<"">(config.namespace);
});
});
2 changes: 1 addition & 1 deletion packages/store/ts/config/v2/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export type validateStoreConfig<input> = {
: input[key];
};

export type resolveEnums<enums> = { [key in keyof enums]: Readonly<enums[key]> };
export type resolveEnums<enums> = { readonly [key in keyof enums]: Readonly<enums[key]> };

export type resolveStoreConfig<input> = evaluate<{
readonly tables: "tables" extends keyof input ? resolveStoreTablesConfig<input["tables"], extendedScope<input>> : {};
Expand Down
15 changes: 15 additions & 0 deletions packages/store/ts/config/v2/table.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe("validateKeys", () => {

it("should return a tuple of valid keys with an extended scope", () => {
const scope = extendScope(AbiTypeScope, { static: "address", dynamic: "string" });

attest<
["static", "customStatic"],
validateKeys<
Expand All @@ -34,6 +35,7 @@ describe("validateKeys", () => {

it("should return a tuple of valid keys with an extended scope", () => {
const scope = extendScope(AbiTypeScope, { static: "address", dynamic: "string" });

attest<
["static", "customStatic"],
validateKeys<
Expand All @@ -50,6 +52,7 @@ describe("validateKeys", () => {
describe("resolveTableShorthand", () => {
it("should expand a single ABI type into a key/value schema", () => {
const table = resolveTableShorthand("address");

attest<{
schema: {
key: "bytes32";
Expand All @@ -62,6 +65,7 @@ describe("resolveTableShorthand", () => {
it("should expand a single custom into a key/value schema", () => {
const scope = extendScope(AbiTypeScope, { CustomType: "uint256" });
const table = resolveTableShorthand("CustomType", scope);

attest<{
schema: {
key: "bytes32";
Expand All @@ -88,6 +92,7 @@ describe("resolveTableShorthand", () => {

it("should use `key` as single key if it has a static ABI type", () => {
const table = resolveTableShorthand({ key: "address", name: "string", age: "uint256" });

attest<{
schema: {
key: "address";
Expand Down Expand Up @@ -124,6 +129,7 @@ describe("resolveTableShorthand", () => {
it("should use `key` as single key if it has a static custom type", () => {
const scope = extendScope(AbiTypeScope, { CustomType: "uint256" });
const table = resolveTableShorthand({ key: "CustomType", name: "string", age: "uint256" }, scope);

attest<{
schema: { key: "CustomType"; name: "string"; age: "uint256" };
primaryKey: ["key"];
Expand All @@ -134,6 +140,7 @@ describe("resolveTableShorthand", () => {

it("should throw an error if `key` is not a custom static type", () => {
const scope = extendScope(AbiTypeScope, { CustomType: "bytes" });

// @ts-expect-error "Error: Provide a `key` field with static ABI type or a full config with explicit primaryKey override."
attest(resolveTableShorthand({ key: "CustomType", name: "string", age: "uint256" }, scope)).type.errors(
`Provide a \`key\` field with static ABI type or a full config with explicit primaryKey override.`,
Expand Down Expand Up @@ -169,6 +176,7 @@ describe("resolveTableConfig", () => {
},
primaryKey: ["key"],
} as const;

attest<typeof expected>(table);
});

Expand Down Expand Up @@ -200,6 +208,7 @@ describe("resolveTableConfig", () => {
},
primaryKey: ["key"],
} as const;

attest<typeof expected>(table);
});

Expand Down Expand Up @@ -238,6 +247,7 @@ describe("resolveTableConfig", () => {
},
primaryKey: ["key"],
} as const;

attest<typeof expected>(table);
});

Expand Down Expand Up @@ -277,6 +287,7 @@ describe("resolveTableConfig", () => {
},
primaryKey: ["key"],
} as const;

attest<typeof expected>(table);
});

Expand Down Expand Up @@ -329,6 +340,7 @@ describe("resolveTableConfig", () => {
},
primaryKey: ["age"],
} as const;

attest<typeof expected>(table);
});

Expand All @@ -352,6 +364,7 @@ describe("resolveTableConfig", () => {
},
primaryKey: ["age", "key"],
} as const;

attest<typeof expected>(table);
});

Expand Down Expand Up @@ -391,6 +404,7 @@ describe("resolveTableConfig", () => {
},
primaryKey: ["key"],
} as const;

attest<typeof expected>(table);
});

Expand Down Expand Up @@ -430,6 +444,7 @@ describe("resolveTableConfig", () => {
},
primaryKey: ["key"],
} as const;

attest<typeof expected>(table);
});

Expand Down
6 changes: 6 additions & 0 deletions packages/world/ts/config/v2/world.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ describe("resolveWorldConfig", () => {
namespace: "",
namespaces: {},
} as const;

attest<typeof config>(expected);
});

Expand Down Expand Up @@ -470,6 +471,7 @@ describe("resolveWorldConfig", () => {
namespace: "",
namespaces: {},
} as const;

attest<typeof expected>(config);
});

Expand Down Expand Up @@ -669,6 +671,7 @@ describe("resolveWorldConfig", () => {
namespace: "",
namespaces: {},
} as const;

attest<typeof expected>(config);
});

Expand Down Expand Up @@ -760,6 +763,7 @@ describe("resolveWorldConfig", () => {
namespace: "",
namespaces: {},
} as const;

attest<typeof expected>(config);
});

Expand Down Expand Up @@ -868,11 +872,13 @@ describe("resolveWorldConfig", () => {
namespace: "",
namespaces: {},
} as const;

attest<typeof expected>(config);
});

it("should use the root namespace as default namespace", () => {
const config = resolveWorldConfig({ tables: { Example: {} } });

attest<"">(config.namespace);
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/world/ts/config/v2/world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export type WorldConfigInput<userTypes extends UserTypes = UserTypes, enums exte

export type NamespacesInput = { [key: string]: NamespaceInput };

export type NamespaceInput = Omit<StoreConfigInput, "userTypes" | "enums">;
export type NamespaceInput = Pick<StoreConfigInput, "tables">;

export type validateNamespaces<input, scope extends AbiTypeScope = AbiTypeScope> = {
[namespace in keyof input]: {
Expand Down
4 changes: 3 additions & 1 deletion templates/phaser/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
{}
{
"typescript.tsdk": "node_modules/typescript/lib"
}
4 changes: 3 additions & 1 deletion templates/react-ecs/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
{}
{
"typescript.tsdk": "node_modules/typescript/lib"
}
4 changes: 3 additions & 1 deletion templates/react/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
{}
{
"typescript.tsdk": "node_modules/typescript/lib"
}
4 changes: 3 additions & 1 deletion templates/threejs/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
{}
{
"typescript.tsdk": "node_modules/typescript/lib"
}
4 changes: 3 additions & 1 deletion templates/vanilla/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
{}
{
"typescript.tsdk": "node_modules/typescript/lib"
}

0 comments on commit 781e02f

Please sign in to comment.