Compare commits
5 Commits
394ab8c9d3
...
72ffa26796
Author | SHA1 | Date |
---|---|---|
Bauke | 72ffa26796 | |
Bauke | c9f30bffef | |
Bauke | 6d1dff6af5 | |
Bauke | cfa0e5ea34 | |
Bauke | 492673d71d |
|
@ -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);
|
||||
|
|
10
package.json
10
package.json
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue