Compare commits
3 Commits
b798e18a16
...
43c3a5c132
Author | SHA1 | Date |
---|---|---|
Bauke | 43c3a5c132 | |
Bauke | fd20d051a1 | |
Bauke | 7c95c574ce |
|
@ -8,14 +8,6 @@
|
||||||
* 100% code coverage.
|
* 100% code coverage.
|
||||||
* TypeScript definitions included.
|
* TypeScript definitions included.
|
||||||
|
|
||||||
## Registry Setup
|
|
||||||
|
|
||||||
To use this package, add a registry for the `@holllo` scope to your npm configuration.
|
|
||||||
|
|
||||||
```
|
|
||||||
npm config set @holllo:registry https://git.bauke.xyz/api/packages/Holllo/npm/
|
|
||||||
```
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
"name": "@holllo/migration-helper",
|
"name": "@holllo/migration-helper",
|
||||||
"description": "Tiny helper library for migrating data.",
|
"description": "Tiny helper library for migrating data.",
|
||||||
"license": "AGPL-3.0-or-later",
|
"license": "AGPL-3.0-or-later",
|
||||||
"version": "0.1.3",
|
"version": "0.1.4",
|
||||||
"author": "Holllo <helllo@holllo.org>",
|
"author": "Holllo <helllo@holllo.org>",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|
|
@ -7,9 +7,9 @@
|
||||||
* The migrate function should take the data you pass through {@link migrate}
|
* The migrate function should take the data you pass through {@link migrate}
|
||||||
* and modify it to your needs.
|
* and modify it to your needs.
|
||||||
*/
|
*/
|
||||||
export type Migration<V> = {
|
export type Migration<V, A = any, B = any> = {
|
||||||
version: V;
|
version: V;
|
||||||
migrate: (data: any) => Promise<unknown>;
|
migrate: (data: A) => Promise<B>;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -3,7 +3,7 @@ import test from 'ava';
|
||||||
import {migrate, Migration} from '../source/migration-helper.js';
|
import {migrate, Migration} from '../source/migration-helper.js';
|
||||||
|
|
||||||
test('migrate<Date>', async (t) => {
|
test('migrate<Date>', async (t) => {
|
||||||
const migrations: Array<Migration<Date>> = [
|
const migrations: Array<Migration<Date, string, string>> = [
|
||||||
{
|
{
|
||||||
version: new Date('2022-01-01'),
|
version: new Date('2022-01-01'),
|
||||||
migrate: async (data: string) => `${data} migrated`,
|
migrate: async (data: string) => `${data} migrated`,
|
||||||
|
|
|
@ -3,7 +3,7 @@ import test from 'ava';
|
||||||
import {migrate, Migration} from '../source/migration-helper.js';
|
import {migrate, Migration} from '../source/migration-helper.js';
|
||||||
|
|
||||||
test('migrate<number>', async (t) => {
|
test('migrate<number>', async (t) => {
|
||||||
const migrations: Array<Migration<number>> = [
|
const migrations: Array<Migration<number, string, string>> = [
|
||||||
{
|
{
|
||||||
version: 5,
|
version: 5,
|
||||||
migrate: async (data: string) => `${data} migrated`,
|
migrate: async (data: string) => `${data} migrated`,
|
||||||
|
|
|
@ -12,7 +12,7 @@ test('migrate<{custom: number}>', async (t) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const skip: SkipMigrationFn<Custom> = (a, b) => a.custom > b.custom;
|
const skip: SkipMigrationFn<Custom> = (a, b) => a.custom > b.custom;
|
||||||
const migrations: Array<Migration<Custom>> = [
|
const migrations: Array<Migration<Custom, string, string>> = [
|
||||||
{
|
{
|
||||||
version: {custom: 5},
|
version: {custom: 5},
|
||||||
migrate: async (data: string) => `${data} migrated`,
|
migrate: async (data: string) => `${data} migrated`,
|
||||||
|
|
|
@ -3,7 +3,7 @@ import test from 'ava';
|
||||||
import {migrate, Migration} from '../source/migration-helper.js';
|
import {migrate, Migration} from '../source/migration-helper.js';
|
||||||
|
|
||||||
test('migrate<string>', async (t) => {
|
test('migrate<string>', async (t) => {
|
||||||
const migrations: Array<Migration<string>> = [
|
const migrations: Array<Migration<string, string, string>> = [
|
||||||
{
|
{
|
||||||
version: '0.2.4',
|
version: '0.2.4',
|
||||||
migrate: async (data: string) => `${data} migrated`,
|
migrate: async (data: string) => `${data} migrated`,
|
||||||
|
|
Loading…
Reference in New Issue