mirror of
https://github.com/trezor/trezor-suite.git
synced 2026-03-23 15:47:18 +01:00
21 lines
615 B
TypeScript
21 lines
615 B
TypeScript
import type { DBSchema } from 'idb';
|
|
|
|
import { encodeIDBVersion } from './encode';
|
|
import { parseIdbVersion } from './parseIdbVersion';
|
|
import { DBMigration } from './types';
|
|
|
|
type BaseSemver = `${number}.${number}.${number}`;
|
|
type IdbVersionString = `${BaseSemver}` | `${BaseSemver}.${number}`;
|
|
|
|
export const createMigration = <Schema extends DBSchema>(
|
|
version: IdbVersionString,
|
|
migrate: DBMigration<Schema>['migrate'],
|
|
): DBMigration<Schema> => {
|
|
const { versionString: threshold } = parseIdbVersion(version);
|
|
|
|
return {
|
|
threshold: encodeIDBVersion(threshold),
|
|
migrate,
|
|
};
|
|
};
|