Compare commits
No commits in common. "72ffa267965955f38b71a41dfa079976a09134aa" and "394ab8c9d38e1a77b44ee0675b23ba3e429ed1c2" have entirely different histories.
72ffa26796
...
394ab8c9d3
|
@ -34,7 +34,7 @@ const migrations: Array<Migration<string>> = [
|
|||
];
|
||||
|
||||
// Migrate your data.
|
||||
const migrated = await migrate(data, version, migrations);
|
||||
const migrated = migrate(data, version, migrations);
|
||||
|
||||
// Congratulations, your data is now on version 1.0.2!
|
||||
console.log(migrated);
|
||||
|
|
10
package.json
10
package.json
|
@ -2,12 +2,9 @@
|
|||
"name": "migration-helper",
|
||||
"description": "A tiny helper library for migrating data.",
|
||||
"license": "GPL-3.0-or-later",
|
||||
"version": "0.1.2",
|
||||
"version": "0.1.0",
|
||||
"author": "Holllo <helllo@holllo.cc>",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Holllo/migration-helper"
|
||||
},
|
||||
"repository": "https://github.com/Holllo/migration-helper",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"prepublishOnly": "pnpm test && pnpm build",
|
||||
|
@ -56,9 +53,6 @@
|
|||
},
|
||||
"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 = await migration.migrate(migratedData);
|
||||
migratedData = migration.migrate(migratedData);
|
||||
}
|
||||
|
||||
return migratedData;
|
||||
|
|
Loading…
Reference in New Issue