fix: Type to include promise

This commit is contained in:
BluJ
2022-08-18 08:38:38 -06:00
parent 21d93c803f
commit a30099157a

View File

@@ -19,18 +19,18 @@ export interface NoRepeat<version extends string, type extends "up" | "down"> {
export function updateConfig< export function updateConfig<
version extends string, version extends string,
type extends "up" | "down", type extends "up" | "down",
>( >(
fn: (config: T.Config, effects: T.Effects) => T.Config, fn: (config: T.Config, effects: T.Effects) => T.Config | Promise<T.Config>,
configured: boolean, configured: boolean,
noRepeat?: NoRepeat<version, type>, noRepeat?: NoRepeat<version, type>,
noFail = false, noFail = false,
): M.MigrationFn<version, type> { ): M.MigrationFn<version, type> {
return M.migrationFn(async (effects: T.Effects) => { return M.migrationFn(async (effects: T.Effects) => {
await noRepeatGuard(effects, noRepeat, async () => { await noRepeatGuard(effects, noRepeat, async () => {
let config = util.unwrapResultType(await getConfig({})(effects)).config; let config = util.unwrapResultType(await getConfig({})(effects)).config;
if (config) { if (config) {
try { try {
config = fn(config, effects); config = await fn(config, effects);
} catch (e) { } catch (e) {
if (!noFail) { if (!noFail) {
throw e; throw e;
@@ -48,10 +48,10 @@ export function updateConfig<
export async function noRepeatGuard< export async function noRepeatGuard<
version extends string, version extends string,
type extends "up" | "down", type extends "up" | "down",
>( >(
effects: T.Effects, effects: T.Effects,
noRepeat: NoRepeat<version, type> | undefined, noRepeat: NoRepeat<version, type> | undefined,
fn: () => Promise<void>, fn: () => Promise<void>,
): Promise<void> { ): Promise<void> {
if (!noRepeat) { if (!noRepeat) {
return fn(); return fn();