1
Fork 0

Compare commits

...

5 Commits

Author SHA1 Message Date
Bauke 72ffa26796
Version 0.1.2 2022-03-03 22:17:33 +01:00
Bauke c9f30bffef
Make the default skip use <= instead. 2022-03-03 22:17:04 +01:00
Bauke 6d1dff6af5
Fix the repository link. 2022-03-03 22:13:16 +01:00
Bauke cfa0e5ea34
Version 0.1.1 2022-03-03 15:01:32 +01:00
Bauke 492673d71d
Correctly await things. 2022-03-03 15:01:06 +01:00
3 changed files with 12 additions and 6 deletions

View File

@ -34,7 +34,7 @@ const migrations: Array<Migration<string>> = [
];
// Migrate your data.
const migrated = migrate(data, version, migrations);
const migrated = await migrate(data, version, migrations);
// Congratulations, your data is now on version 1.0.2!
console.log(migrated);

View File

@ -2,9 +2,12 @@
"name": "migration-helper",
"description": "A tiny helper library for migrating data.",
"license": "GPL-3.0-or-later",
"version": "0.1.0",
"version": "0.1.2",
"author": "Holllo <helllo@holllo.cc>",
"repository": "https://github.com/Holllo/migration-helper",
"repository": {
"type": "git",
"url": "https://github.com/Holllo/migration-helper"
},
"scripts": {
"build": "tsc",
"prepublishOnly": "pnpm test && pnpm build",
@ -53,6 +56,9 @@
},
"xo": {
"prettier": true,
"rules": {
"no-await-in-loop": "off"
},
"space": true
}
}

View File

@ -19,7 +19,7 @@ export type Migration<V> = {
* tested, while the second argument will be the version passed into
* {@link migrate}.
*
* If left undefined, `a < b` will be used. This works for {@link Date dates},
* If left undefined, `a <= b` will be used. This works for {@link Date dates},
* {@link Number numbers} and {@link String strings}. So if you want to use a
* different type for versioning you should create your own function.
*/
@ -35,7 +35,7 @@ export async function migrate<V>(
data: unknown,
version: V,
migrations: Array<Migration<V>>,
skip: SkipMigrationFn<V> = (a, b) => a < b,
skip: SkipMigrationFn<V> = (a, b) => a <= b,
): Promise<unknown> {
let migratedData = data;
@ -44,7 +44,7 @@ export async function migrate<V>(
continue;
}
migratedData = migration.migrate(migratedData);
migratedData = await migration.migrate(migratedData);
}
return migratedData;