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

test: improve type benches with baseline + .ts files, avoiding build #2988

Merged
merged 4 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all 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: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"sort-package-json": "npx sort-package-json package.json 'packages/*/package.json' 'templates/*/package.json' 'templates/*/packages/*/package.json' 'examples/*/package.json' 'examples/*/packages/*/package.json' 'e2e/*/package.json' 'e2e/*/packages/*/package.json' 'docs/package.json' 'test/*/package.json'",
"test": "pnpm run --recursive test",
"test:ci": "pnpm run --recursive --parallel test:ci",
"type-bench": "pnpm --filter ./test/ts-benchmarks bench",
"type-stats-repo": "attest stats packages/*"
},
"lint-staged": {
Expand All @@ -37,7 +38,7 @@
"package.json": "pnpm sort-package-json"
},
"devDependencies": {
"@arktype/attest": "0.7.5",
"@ark/attest": "0.10.2",
"@changesets/cli": "^2.27.7",
"@types/node": "^18.15.11",
"@typescript-eslint/eslint-plugin": "7.1.1",
Expand All @@ -56,9 +57,9 @@
"turbo": "^1.9.3",
"typescript": "5.4.2"
},
"packageManager": "pnpm@9.1.1",
"packageManager": "pnpm@9.6.0",
"engines": {
"node": "^18.20.1",
"pnpm": "^9.1.1"
"pnpm": "^9.6.0"
}
}
2 changes: 1 addition & 1 deletion packages/config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"test:ci": "pnpm run test"
},
"dependencies": {
"@arktype/util": "0.0.40",
"@ark/util": "catalog:",
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's a great feature! I figured I'd use it since I was updating @ark/util anyways, but you could migrate to this for all packages you share as non-dev dependencies across multiple packages.

Having multiple package versions can cause lots of problems, so the centralization is super valuable.

"@latticexyz/common": "workspace:*",
"@latticexyz/schema-type": "workspace:*",
"esbuild": "^0.17.15",
Expand Down
2 changes: 1 addition & 1 deletion packages/config/src/common.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Hex } from "viem";
import { DynamicAbiType, StaticAbiType } from "@latticexyz/schema-type/internal";
import { ResourceType } from "@latticexyz/common";
import { satisfy } from "@arktype/util";
import { satisfy } from "@ark/util";

/**
* Common output types of a MUD config. We use these types as inputs for libraries.
Expand Down
2 changes: 1 addition & 1 deletion packages/query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"test:ci": "pnpm run test"
},
"dependencies": {
"@arktype/util": "0.0.40",
"@ark/util": "catalog:",
"@latticexyz/common": "workspace:*",
"@latticexyz/config": "workspace:*",
"@latticexyz/schema-type": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/query/src/api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Hex } from "viem";
import { satisfy } from "@arktype/util";
import { satisfy } from "@ark/util";
import { StaticPrimitiveType, DynamicPrimitiveType, SchemaAbiType } from "@latticexyz/schema-type/internal";
import { SchemaToPrimitives } from "@latticexyz/store/internal";
import { Table } from "@latticexyz/config";
Expand Down
2 changes: 1 addition & 1 deletion packages/store-sync/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"test:ci": "vitest --run"
},
"dependencies": {
"@arktype/util": "0.1.0",
"@ark/util": "catalog:",
"@latticexyz/block-logs-stream": "workspace:*",
"@latticexyz/common": "workspace:*",
"@latticexyz/config": "workspace:*",
Expand Down
4 changes: 2 additions & 2 deletions packages/store-sync/src/common.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, it } from "vitest";
import { attest } from "@arktype/attest";
import { isDisjoint } from "@arktype/util";
import { attest } from "@ark/attest";
import { isDisjoint } from "@ark/util";
import storeConfig from "@latticexyz/store/mud.config";
import worldConfig from "@latticexyz/world/mud.config";
import { configToTables } from "./configToTables";
Expand Down
2 changes: 1 addition & 1 deletion packages/store-sync/src/configToTables.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { describe, it } from "vitest";
import { configToTables } from "./configToTables";
import { defineWorld } from "@latticexyz/world";
import { resourceToHex } from "@latticexyz/common";
import { attest } from "@arktype/attest";
import { attest } from "@ark/attest";

describe("configToTables", () => {
it("flattens tables from single namespace", async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/store-sync/src/configToTables.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { show } from "@arktype/util";
import { show } from "@ark/util";
import { Store } from "@latticexyz/store";

type flattenedTableKeys<config extends Store> = config extends { readonly namespaces: infer namespaces }
Expand Down
2 changes: 1 addition & 1 deletion packages/store-sync/src/recs/createStorageAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { hexKeyTupleToEntity } from "./hexKeyTupleToEntity";
import { StorageAdapter, StorageAdapterBlock } from "../common";
import { singletonEntity } from "./singletonEntity";
import { tablesToComponents } from "./tablesToComponents";
import { merge } from "@arktype/util";
import { merge } from "@ark/util";

export type CreateStorageAdapterOptions<tables extends Tables> = {
world: RecsWorld;
Expand Down
7 changes: 5 additions & 2 deletions packages/store-sync/src/recs/syncToRecs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ import { createStoreSync } from "../createStoreSync";
import { singletonEntity } from "./singletonEntity";
import { SyncStep } from "../SyncStep";
import { configToTables } from "../configToTables";
import { merge } from "@arktype/util";
import { merge } from "@ark/util";

export type SyncToRecsOptions<config extends StoreConfig, extraTables extends Tables> = Omit<SyncOptions, "config"> & {
export type SyncToRecsOptions<config extends StoreConfig = StoreConfig, extraTables extends Tables = Tables> = Omit<
SyncOptions,
"config"
> & {
world: RecsWorld;
config: config;
tables?: extraTables;
Expand Down
2 changes: 1 addition & 1 deletion packages/store-sync/src/recs/tablesToComponents.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Tables } from "@latticexyz/config";
import { tableToComponent } from "./tableToComponent";
import { World } from "@latticexyz/recs";
import { show } from "@arktype/util";
import { show } from "@ark/util";

export type tablesToComponents<tables extends Tables> = {
[label in keyof tables as tables[label]["label"]]: tableToComponent<tables[label]>;
Expand Down
2 changes: 1 addition & 1 deletion packages/store-sync/src/zustand/syncToZustand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Address } from "viem";
import { SyncStep } from "../SyncStep";
import { Store as StoreConfig } from "@latticexyz/store";
import { Tables } from "@latticexyz/config";
import { merge } from "@arktype/util";
import { merge } from "@ark/util";
import { configToTables } from "../configToTables";

export type SyncToZustandOptions<config extends StoreConfig, extraTables extends Tables> = Omit<
Expand Down
2 changes: 1 addition & 1 deletion packages/store-sync/vitestSetup.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { setup, cleanup as teardown } from "@arktype/attest";
export { setup, cleanup as teardown } from "@ark/attest";
3 changes: 1 addition & 2 deletions packages/store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"test:ci": "pnpm run test"
},
"dependencies": {
"@arktype/util": "0.0.40",
"@ark/util": "catalog:",
"@latticexyz/common": "workspace:*",
"@latticexyz/config": "workspace:*",
"@latticexyz/protocol-parser": "workspace:*",
Expand All @@ -69,7 +69,6 @@
"viem": "2.9.20"
},
"devDependencies": {
"@arktype/attest": "0.7.5",
"@latticexyz/abi-ts": "workspace:*",
"@latticexyz/gas-report": "workspace:*",
"@types/ejs": "^3.1.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/store/ts/config/v2/enums.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { flatMorph } from "@arktype/util";
import { flatMorph } from "@ark/util";
import { EnumsInput } from "./input";
import { AbiTypeScope, extendScope } from "./scope";
import { parseNumber } from "./generics";
Expand Down
2 changes: 1 addition & 1 deletion packages/store/ts/config/v2/flattenNamespacedTables.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { show } from "@arktype/util";
import { show } from "@ark/util";
import { Namespaces } from "./output";

type flattenNamespacedTableKeys<config> = config extends {
Expand Down
2 changes: 1 addition & 1 deletion packages/store/ts/config/v2/namespace.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ErrorMessage, flatMorph } from "@arktype/util";
import { ErrorMessage, flatMorph } from "@ark/util";
import { hasOwnKey, mergeIfUndefined } from "./generics";
import { NamespaceInput } from "./input";
import { resolveTables, validateTables } from "./tables";
Expand Down
2 changes: 1 addition & 1 deletion packages/store/ts/config/v2/namespaces.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, it } from "vitest";
import { attest } from "@arktype/attest";
import { attest } from "@ark/attest";
import { defineNamespaces } from "./namespaces";

describe("defineNamespaces", () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/store/ts/config/v2/namespaces.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { show, flatMorph } from "@arktype/util";
import { show, flatMorph } from "@ark/util";
import { isObject, mergeIfUndefined } from "./generics";
import { NamespacesInput } from "./input";
import { AbiTypeScope, Scope } from "./scope";
Expand Down
2 changes: 1 addition & 1 deletion packages/store/ts/config/v2/output.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { show } from "@arktype/util";
import { show } from "@ark/util";
import { AbiType, Schema, Table as BaseTable } from "@latticexyz/config";
import { EnumsInput } from "./input";

Expand Down
26 changes: 17 additions & 9 deletions packages/store/ts/config/v2/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { describe, it } from "vitest";
import { defineSchema } from "./schema";
import { Schema } from "./output";
import { extendScope, AbiTypeScope } from "./scope";
import { attest } from "@arktype/attest";
import { attest } from "@ark/attest";

describe("resolveSchema", () => {
it("should map user types to their primitive type", () => {
Expand All @@ -19,11 +19,16 @@ describe("resolveSchema", () => {
},
} as const;

attest<typeof expected>(resolved)
.equals(expected)
.type.toString.snap(
'{ readonly regular: { readonly type: "uint256"; readonly internalType: "uint256"; }; readonly user: { readonly type: "address"; readonly internalType: "CustomType"; }; }',
);
attest<typeof expected>(resolved).equals(expected).type.toString.snap(`{
readonly regular: {
readonly type: "uint256"
readonly internalType: "uint256"
}
readonly user: {
readonly type: "address"
readonly internalType: "CustomType"
}
}`);
});

it("should throw if a type is not part of the scope", () => {
Expand Down Expand Up @@ -57,8 +62,11 @@ describe("resolveSchema", () => {
},
} as const;

attest<typeof expected>(resolved)
.equals(expected)
.type.toString.snap('{ readonly coordinate: { readonly type: "int32[]"; readonly internalType: "int32[2]"; }; }');
attest<typeof expected>(resolved).equals(expected).type.toString.snap(`{
readonly coordinate: {
readonly type: "int32[]"
readonly internalType: "int32[2]"
}
}`);
});
});
2 changes: 1 addition & 1 deletion packages/store/ts/config/v2/schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { conform, show } from "@arktype/util";
import { conform, show } from "@ark/util";
import { AbiTypeScope, Scope } from "./scope";
import { hasOwnKey, isObject } from "./generics";
import { SchemaInput } from "./input";
Expand Down
15 changes: 10 additions & 5 deletions packages/store/ts/config/v2/scope.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
import { attest } from "@arktype/attest";
import { attest } from "@ark/attest";
import { describe, it } from "vitest";
import { AbiTypeScope, Scope, ScopeOptions, extendScope, getStaticAbiTypeKeys } from "./scope";

describe("extendScope", () => {
it("should extend the provided scope", () => {
const extendedScope = extendScope(Scope, { static: "uint256", dynamic: "string" });
attest<ScopeOptions<{ static: "uint256"; dynamic: "string" }>>(extendedScope).type.toString.snap(
'{ types: { static: "uint256"; dynamic: "string"; }; }',
'{ types: { static: "uint256"; dynamic: "string" } }',
);

const furtherExtendedScope = extendScope(extendedScope, { static2: "uint256", dynamic2: "string" });
attest<ScopeOptions<{ static: "uint256"; dynamic: "string"; static2: "uint256"; dynamic2: "string" }>>(
furtherExtendedScope,
).type.toString.snap(
'{ types: { static: "uint256"; dynamic: "string"; static2: "uint256"; dynamic2: "string"; }; }',
);
).type.toString.snap(`{
types: {
static: "uint256"
dynamic: "string"
static2: "uint256"
dynamic2: "string"
}
}`);
});
});

Expand Down
2 changes: 1 addition & 1 deletion packages/store/ts/config/v2/scope.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Dict, show } from "@arktype/util";
import { Dict, show } from "@ark/util";
import { SchemaInput } from "./input";
import { StaticAbiType, schemaAbiTypes } from "@latticexyz/schema-type/internal";
import { AbiType } from "./output";
Expand Down
4 changes: 2 additions & 2 deletions packages/store/ts/config/v2/store.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { describe, it } from "vitest";
import { defineStore } from "./store";
import { attest } from "@arktype/attest";
import { attest } from "@ark/attest";
import { resourceToHex } from "@latticexyz/common";
import { Store } from "./output";
import { satisfy } from "@arktype/util";
import { satisfy } from "@ark/util";
import { Hex } from "viem";

describe("defineStore", () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/store/ts/config/v2/store.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ErrorMessage, show, narrow } from "@arktype/util";
import { ErrorMessage, show, narrow } from "@ark/util";
import { get, hasOwnKey } from "./generics";
import { UserTypes } from "./output";
import { CONFIG_DEFAULTS } from "./defaults";
Expand Down
2 changes: 1 addition & 1 deletion packages/store/ts/config/v2/table.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { attest } from "@arktype/attest";
import { attest } from "@ark/attest";
import { describe, it } from "vitest";
import { getStaticAbiTypeKeys, AbiTypeScope, extendScope } from "./scope";
import { validateKeys, defineTable } from "./table";
Expand Down
2 changes: 1 addition & 1 deletion packages/store/ts/config/v2/table.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ErrorMessage, conform, show, narrow, requiredKeyOf } from "@arktype/util";
import { ErrorMessage, conform, show, narrow, requiredKeyOf } from "@ark/util";
import { isStaticAbiType } from "@latticexyz/schema-type/internal";
import { Hex } from "viem";
import { get, hasOwnKey, mergeIfUndefined } from "./generics";
Expand Down
2 changes: 1 addition & 1 deletion packages/store/ts/config/v2/tableShorthand.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, it } from "vitest";
import { attest } from "@arktype/attest";
import { attest } from "@ark/attest";
import { AbiTypeScope, extendScope } from "./scope";
import { NoStaticKeyFieldError, defineTableShorthand } from "./tableShorthand";

Expand Down
2 changes: 1 addition & 1 deletion packages/store/ts/config/v2/tableShorthand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { hasOwnKey, isObject } from "./generics";
import { SchemaInput, ScopedSchemaInput, TableShorthandInput } from "./input";
import { isSchemaInput } from "./schema";
import { AbiTypeScope, Scope, getStaticAbiTypeKeys } from "./scope";
import { ErrorMessage, conform } from "@arktype/util";
import { ErrorMessage, conform } from "@ark/util";

export const NoStaticKeyFieldError =
"Invalid schema. Expected an `id` field with a static ABI type or an explicit `key` option.";
Expand Down
2 changes: 1 addition & 1 deletion packages/store/ts/config/v2/tables.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, it } from "vitest";
import { attest } from "@arktype/attest";
import { attest } from "@ark/attest";
import { AbiTypeScope, extendScope } from "./scope";
import { defineTables, validateTables } from "./tables";

Expand Down
2 changes: 1 addition & 1 deletion packages/store/ts/config/v2/tables.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ErrorMessage, show } from "@arktype/util";
import { ErrorMessage, show } from "@ark/util";
import { isObject, mergeIfUndefined } from "./generics";
import { TableShorthandInput, TablesInput } from "./input";
import { Scope, AbiTypeScope } from "./scope";
Expand Down
2 changes: 1 addition & 1 deletion packages/store/vitestSetup.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { setup, cleanup as teardown } from "@arktype/attest";
export { setup, cleanup as teardown } from "@ark/attest";
3 changes: 1 addition & 2 deletions packages/world/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"test:ci": "pnpm run test"
},
"dependencies": {
"@arktype/util": "0.0.40",
"@ark/util": "catalog:",
"@latticexyz/common": "workspace:*",
"@latticexyz/config": "workspace:*",
"@latticexyz/protocol-parser": "workspace:*",
Expand All @@ -70,7 +70,6 @@
"viem": "2.9.20"
},
"devDependencies": {
"@arktype/attest": "0.7.5",
"@latticexyz/abi-ts": "workspace:*",
"@latticexyz/gas-report": "workspace:*",
"@types/ejs": "^3.1.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/world/ts/config/v2/namespaces.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { show, flatMorph } from "@arktype/util";
import { show, flatMorph } from "@ark/util";
import { NamespacesInput } from "./input";
import { validateNamespace, resolveNamespace } from "./namespace";
import { groupBy } from "@latticexyz/common/utils";
Expand Down
2 changes: 1 addition & 1 deletion packages/world/ts/config/v2/system.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, it } from "vitest";
import { attest } from "@arktype/attest";
import { attest } from "@ark/attest";
import { resourceToHex } from "@latticexyz/common";
import { defineSystem } from "./system";
import { SYSTEM_DEFAULTS } from "./defaults";
Expand Down
2 changes: 1 addition & 1 deletion packages/world/ts/config/v2/system.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SYSTEM_DEFAULTS } from "./defaults";
import { SystemInput } from "./input";
import { hasOwnKey, mergeIfUndefined } from "@latticexyz/store/config/v2";
import { ErrorMessage, narrow, requiredKeyOf } from "@arktype/util";
import { ErrorMessage, narrow, requiredKeyOf } from "@ark/util";
import { Hex } from "viem";
import { resourceToHex } from "@latticexyz/common";

Expand Down
2 changes: 1 addition & 1 deletion packages/world/ts/config/v2/systems.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ErrorMessage } from "@arktype/util";
import { ErrorMessage } from "@ark/util";
import { isObject } from "@latticexyz/store/config/v2";
import { SystemsInput } from "./input";
import { resolveSystem, validateSystem } from "./system";
Expand Down
Loading
Loading