Skip to content

Commit

Permalink
add v2 config to v1 compat
Browse files Browse the repository at this point in the history
  • Loading branch information
alvrs committed Mar 20, 2024
1 parent 1bc57e8 commit cb88ed0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/store/ts/config/v2/compat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { Store } from "./output";

describe("configToV1", () => {
it("should transform the broad v2 output to the broad v1 output", () => {
attest<StoreConfigV1, storeToV1<Store>>();
attest<storeToV1<Store>, StoreConfigV1>();
attest<StoreConfigV1, Omit<storeToV1<Store>, "v2">>();
attest<Omit<storeToV1<Store>, "v2">, StoreConfigV1>();
});

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

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

attest<typeof configV1>(v1FromV2).equals(configV1);
attest<Omit<storeToV1<typeof configV2>, "v2">>(configV1);
});
});
2 changes: 2 additions & 0 deletions packages/store/ts/config/v2/compat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export type storeToV1<store> = store extends Store
tables: {
[key in keyof store["tables"] as store["tables"][key]["name"]]: tableToV1<store["tables"][key]>;
};
v2: store;
}
: never;

Expand Down Expand Up @@ -69,5 +70,6 @@ export function storeToV1<store>(store: conform<store, Store>): storeToV1<store>
codegenDirectory: store.codegen.codegenDirectory,
codegenIndexFilename: store.codegen.codegenIndexFilename,
tables: resolvedTables,
v2: store,
} as unknown as storeToV1<store>;
}

0 comments on commit cb88ed0

Please sign in to comment.