diff --git a/compat/migrations.ts b/compat/migrations.ts index 5603923..156a263 100644 --- a/compat/migrations.ts +++ b/compat/migrations.ts @@ -25,7 +25,7 @@ export function updateConfig< noRepeat?: NoRepeat, noFail = false, ): M.MigrationFn { - return async (effects: T.Effects) => { + return M.migrationFn(async (effects: T.Effects) => { await noRepeatGuard(effects, noRepeat, async () => { let config = util.unwrapResultType(await getConfig({})(effects)).config; if (config) { @@ -42,7 +42,7 @@ export function updateConfig< } }); return { configured }; - }; + }); } export async function noRepeatGuard< diff --git a/migrations.ts b/migrations.ts index 5d49edb..2aab863 100644 --- a/migrations.ts +++ b/migrations.ts @@ -4,7 +4,15 @@ import { matches } from "./dependencies.ts"; export type MigrationFn = ( effects: T.Effects, -) => Promise; +) => Promise & { _type: type; _version: version }; + +export function migrationFn( + fn: ( + effects: T.Effects, + ) => Promise, +): MigrationFn { + return fn as MigrationFn; +} export interface Migration { up: MigrationFn; @@ -34,17 +42,16 @@ export function fromMapping( const current = EmVer.parse(currentVersion); const other = EmVer.parse(version); - const filteredMigrations = - (Object.entries(migrations) as [ - keyof MigrationMapping, - Migration, - ][]) - .map(([version, migration]) => ({ - version: EmVer.parse(version), - migration, - })).filter(({ version }) => - version.greaterThan(other) && version.lessThanOrEqual(current) - ); + const filteredMigrations = (Object.entries(migrations) as [ + keyof MigrationMapping, + Migration, + ][]) + .map(([version, migration]) => ({ + version: EmVer.parse(version), + migration, + })).filter(({ version }) => + version.greaterThan(other) && version.lessThanOrEqual(current) + ); const migrationsToRun = matches.matches(direction) .when("from", () =>