Skip to content

Commit

Permalink
add v2 config to v1 world compat
Browse files Browse the repository at this point in the history
  • Loading branch information
alvrs committed Mar 20, 2024
1 parent cb88ed0 commit 25ef52f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
6 changes: 3 additions & 3 deletions packages/store/ts/config/v2/compat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ describe("configToV1", () => {
},
});

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { v2: _, ...v1FromV2 } = storeToV1(configV2);
const { v2, ...v1FromV2 } = storeToV1(configV2);

attest<typeof configV1>(v1FromV2).equals(configV1);
attest<Omit<storeToV1<typeof configV2>, "v2">>(configV1);
attest<typeof v1FromV2>(configV1).equals(v1FromV2);
attest<typeof configV2>(v2).equals(configV2);
});
});
11 changes: 7 additions & 4 deletions packages/world/ts/config/v2/compat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { defineWorld } from "./world";
describe("configToV1", () => {
it("should transform the broad v2 output to the broad v1 output", () => {
// Making the `worldContractName` prop required here since it is required on the output of `mudConfig`
attest<WorldConfigV1 & StoreConfigV1 & { worldContractName: string | undefined }, worldToV1<World>>();
attest<worldToV1<World>, WorldConfigV1 & StoreConfigV1 & { worldContractName: string | undefined }>();
attest<WorldConfigV1 & StoreConfigV1 & { worldContractName: string | undefined }, Omit<worldToV1<World>, "v2">>();
attest<Omit<worldToV1<World>, "v2">, WorldConfigV1 & StoreConfigV1 & { worldContractName: string | undefined }>();
});

it("should transform a v2 store config output to the v1 config output", () => {
Expand Down Expand Up @@ -90,7 +90,10 @@ describe("configToV1", () => {
},
});

attest<typeof configV1>(worldToV1(configV2)).equals(configV1);
attest<worldToV1<typeof configV2>>(configV1);
const { v2, ...v1FromV2 } = worldToV1(configV2);

attest<typeof configV1>(v1FromV2).equals(configV1);
attest<typeof v1FromV2>(configV1).equals(v1FromV2);
attest<typeof v2>(configV2).equals(v2);
});
});
5 changes: 3 additions & 2 deletions packages/world/ts/config/v2/compat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function systemsToV1<systems extends Systems>(systems: systems): systemsToV1<sys
}

export type worldToV1<world> = world extends World
? storeToV1<world> & {
? Omit<storeToV1<world>, "v2"> & {
systems: systemsToV1<world["systems"]>;
excludeSystems: mutable<world["excludeSystems"]>;
modules: modulesToV1<world["modules"]>;
Expand All @@ -37,6 +37,7 @@ export type worldToV1<world> = world extends World
worldInterfaceName: world["codegen"]["worldInterfaceName"];
worldgenDirectory: world["codegen"]["worldgenDirectory"];
worldImportPath: world["codegen"]["worldImportPath"];
v2: world;
}
: never;

Expand All @@ -54,5 +55,5 @@ export function worldToV1<world>(world: conform<world, World>): worldToV1<world>
worldImportPath: world.codegen.worldImportPath,
};

return { ...storeToV1(world as Store), ...v1WorldConfig } as worldToV1<world>;
return { ...storeToV1(world as Store), ...v1WorldConfig, v2: world } as worldToV1<world>;
}

0 comments on commit 25ef52f

Please sign in to comment.