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.
|
// 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!
|
// Congratulations, your data is now on version 1.0.2!
|
||||||
console.log(migrated);
|
console.log(migrated);
|
||||||
|
|
10
package.json
10
package.json
|
@ -2,12 +2,9 @@
|
||||||
"name": "migration-helper",
|
"name": "migration-helper",
|
||||||
"description": "A tiny helper library for migrating data.",
|
"description": "A tiny helper library for migrating data.",
|
||||||
"license": "GPL-3.0-or-later",
|
"license": "GPL-3.0-or-later",
|
||||||
"version": "0.1.2",
|
"version": "0.1.0",
|
||||||
"author": "Holllo <helllo@holllo.cc>",
|
"author": "Holllo <helllo@holllo.cc>",
|
||||||
"repository": {
|
"repository": "https://github.com/Holllo/migration-helper",
|
||||||
"type": "git",
|
|
||||||
"url": "https://github.com/Holllo/migration-helper"
|
|
||||||
},
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
"prepublishOnly": "pnpm test && pnpm build",
|
"prepublishOnly": "pnpm test && pnpm build",
|
||||||
|
@ -56,9 +53,6 @@
|
||||||
},
|
},
|
||||||
"xo": {
|
"xo": {
|
||||||
"prettier": true,
|
"prettier": true,
|
||||||
"rules": {
|
|
||||||
"no-await-in-loop": "off"
|
|
||||||
},
|
|
||||||
"space": true
|
"space": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ export type Migration<V> = {
|
||||||
* tested, while the second argument will be the version passed into
|
* tested, while the second argument will be the version passed into
|
||||||
* {@link migrate}.
|
* {@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
|
* {@link Number numbers} and {@link String strings}. So if you want to use a
|
||||||
* different type for versioning you should create your own function.
|
* different type for versioning you should create your own function.
|
||||||
*/
|
*/
|
||||||
|
@ -35,7 +35,7 @@ export async function migrate<V>(
|
||||||
data: unknown,
|
data: unknown,
|
||||||
version: V,
|
version: V,
|
||||||
migrations: Array<Migration<V>>,
|
migrations: Array<Migration<V>>,
|
||||||
skip: SkipMigrationFn<V> = (a, b) => a <= b,
|
skip: SkipMigrationFn<V> = (a, b) => a < b,
|
||||||
): Promise<unknown> {
|
): Promise<unknown> {
|
||||||
let migratedData = data;
|
let migratedData = data;
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ export async function migrate<V>(
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
migratedData = await migration.migrate(migratedData);
|
migratedData = migration.migrate(migratedData);
|
||||||
}
|
}
|
||||||
|
|
||||||
return migratedData;
|
return migratedData;
|
||||||
|
|
Loading…
Reference in New Issue