-
-
Notifications
You must be signed in to change notification settings - Fork 160
/
contract.ts
35 lines (29 loc) · 913 Bytes
/
contract.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import type {MigrationParams} from '../types'
export type UmzugStorage<Ctx = unknown> = {
/**
* Logs migration to be considered as executed.
*/
logMigration: (params: MigrationParams<Ctx>) => Promise<void>
/**
* Unlogs migration (makes it to be considered as pending).
*/
unlogMigration: (params: MigrationParams<Ctx>) => Promise<void>
/**
* Gets list of executed migrations.
*/
executed: (meta: Pick<MigrationParams<Ctx>, 'context'>) => Promise<string[]>
}
export function isUmzugStorage(arg: Partial<UmzugStorage>): arg is UmzugStorage {
return (
arg &&
typeof arg.logMigration === 'function' &&
typeof arg.unlogMigration === 'function' &&
typeof arg.executed === 'function'
)
}
export const verifyUmzugStorage = (arg: Partial<UmzugStorage>): UmzugStorage => {
if (!isUmzugStorage(arg)) {
throw new Error(`Invalid umzug storage`)
}
return arg
}