Compare commits
No commits in common. "f26b4dd09e560e75de4de12d33dbfbf2d8cf25bf" and "43c3a5c13242eab252ce0f6b98c8e901383222fd" have entirely different histories.
f26b4dd09e
...
43c3a5c132
|
@ -1,4 +1,107 @@
|
|||
.direnv/
|
||||
build/
|
||||
coverage/
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
*.lcov
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# TypeScript v1 declaration files
|
||||
typings/
|
||||
|
||||
# TypeScript cache
|
||||
*.tsbuildinfo
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Microbundle cache
|
||||
.rpt2_cache/
|
||||
.rts2_cache_cjs/
|
||||
.rts2_cache_es/
|
||||
.rts2_cache_umd/
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variables file
|
||||
.env
|
||||
.env.test
|
||||
|
||||
# parcel-bundler cache (https://parceljs.org/)
|
||||
.cache
|
||||
|
||||
# Next.js build output
|
||||
.next
|
||||
|
||||
# Nuxt.js build / generate output
|
||||
.nuxt
|
||||
dist
|
||||
|
||||
# Gatsby files
|
||||
.cache/
|
||||
# Comment in the public line in if your project uses Gatsby and *not* Next.js
|
||||
# https://nextjs.org/blog/next-9-1#public-directory-support
|
||||
# public
|
||||
|
||||
# vuepress build output
|
||||
.vuepress/dist
|
||||
|
||||
# Serverless directories
|
||||
.serverless/
|
||||
|
||||
# FuseBox cache
|
||||
.fusebox/
|
||||
|
||||
# DynamoDB Local files
|
||||
.dynamodb/
|
||||
|
||||
# TernJS port file
|
||||
.tern-port
|
||||
|
||||
# Build output directory
|
||||
build/
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
# Build the package.
|
||||
[tasks.build]
|
||||
dependencies = ["clean", "lint"]
|
||||
clear = true
|
||||
command = "pnpm"
|
||||
args = ["tsc"]
|
||||
|
||||
# Clean the build directory.
|
||||
[tasks.clean]
|
||||
clear = true
|
||||
command = "pnpm"
|
||||
args = ["trash", "build/"]
|
||||
|
||||
# Run the full set of linting and testing.
|
||||
[tasks.lint]
|
||||
clear = true
|
||||
dependencies = ["lint-js", "typecheck", "test"]
|
||||
|
||||
# Lint the TypeScript using XO.
|
||||
[tasks.lint-js]
|
||||
clear = true
|
||||
command = "pnpm"
|
||||
args = ["xo"]
|
||||
|
||||
# Run the tests.
|
||||
[tasks.test]
|
||||
clear = true
|
||||
command = "pnpm"
|
||||
args = ["tsx", "tests/migrate.test.ts"]
|
||||
|
||||
# Do a typecheck with tsc.
|
||||
[tasks.typecheck]
|
||||
clear = true
|
||||
command = "pnpm"
|
||||
args = ["tsc", "--noEmit"]
|
59
flake.lock
59
flake.lock
|
@ -1,59 +0,0 @@
|
|||
{
|
||||
"nodes": {
|
||||
"flake-utils": {
|
||||
"inputs": {
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1705309234,
|
||||
"narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1705975988,
|
||||
"narHash": "sha256-HJS/ilLkwLaFe+kPciiVuEwa90p7d7Y2FUZXuq7ztVk=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "4d3d04cfd372a0511f12b885c9822e406b00fe8e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"id": "nixpkgs",
|
||||
"type": "indirect"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
13
flake.nix
13
flake.nix
|
@ -1,13 +0,0 @@
|
|||
{
|
||||
inputs.flake-utils.url = "github:numtide/flake-utils";
|
||||
|
||||
outputs = { self, nixpkgs, flake-utils }:
|
||||
flake-utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
in
|
||||
{
|
||||
devShells.default = import ./shell.nix { inherit pkgs; };
|
||||
}
|
||||
);
|
||||
}
|
39
package.json
39
package.json
|
@ -9,14 +9,16 @@
|
|||
"url": "https://git.bauke.xyz/Holllo/migration-helper"
|
||||
},
|
||||
"scripts": {
|
||||
"prepublishOnly": "makers build"
|
||||
"build": "tsc",
|
||||
"prepublishOnly": "pnpm test && pnpm build",
|
||||
"test": "xo && c8 ava && tsc --noEmit"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@holllo/test": "^0.2.1",
|
||||
"trash-cli": "^5.0.0",
|
||||
"tsx": "^4.7.0",
|
||||
"typescript": "^5.3.3",
|
||||
"xo": "^0.56.0"
|
||||
"ava": "^4.3.3",
|
||||
"c8": "^7.12.0",
|
||||
"ts-node": "^10.9.1",
|
||||
"typescript": "^4.8.4",
|
||||
"xo": "^0.52.3"
|
||||
},
|
||||
"type": "module",
|
||||
"main": "build/source/migration-helper.js",
|
||||
|
@ -27,6 +29,31 @@
|
|||
"LICENSE",
|
||||
"README.md"
|
||||
],
|
||||
"ava": {
|
||||
"extensions": {
|
||||
"ts": "module"
|
||||
},
|
||||
"files": [
|
||||
"tests/**/*.ts"
|
||||
],
|
||||
"nodeArguments": [
|
||||
"--loader=ts-node/esm",
|
||||
"--no-warnings"
|
||||
]
|
||||
},
|
||||
"c8": {
|
||||
"100": true,
|
||||
"all": true,
|
||||
"include": [
|
||||
"source",
|
||||
"tests"
|
||||
],
|
||||
"reportDir": "coverage",
|
||||
"reporter": [
|
||||
"text",
|
||||
"html"
|
||||
]
|
||||
},
|
||||
"xo": {
|
||||
"prettier": true,
|
||||
"rules": {
|
||||
|
|
3457
pnpm-lock.yaml
3457
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
|
@ -1,7 +0,0 @@
|
|||
{ pkgs ? import <nixpkgs> { } }:
|
||||
|
||||
with pkgs;
|
||||
|
||||
mkShell rec {
|
||||
packages = [ cargo-make nodejs nodePackages.pnpm ];
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
import test from 'ava';
|
||||
|
||||
import {migrate, Migration} from '../source/migration-helper.js';
|
||||
|
||||
test('migrate<Date>', async (t) => {
|
||||
const migrations: Array<Migration<Date, string, string>> = [
|
||||
{
|
||||
version: new Date('2022-01-01'),
|
||||
migrate: async (data: string) => `${data} migrated`,
|
||||
},
|
||||
];
|
||||
|
||||
function offsetDate(offset: number): Date {
|
||||
const d = new Date(migrations[0].version);
|
||||
d.setDate(d.getDate() + offset);
|
||||
return d;
|
||||
}
|
||||
|
||||
const data = 'data';
|
||||
t.is(await migrate(data, offsetDate(-1), migrations), 'data migrated');
|
||||
t.is(await migrate(data, offsetDate(1), migrations), data);
|
||||
});
|
|
@ -1,77 +0,0 @@
|
|||
import {setup} from '@holllo/test';
|
||||
import {
|
||||
migrate,
|
||||
Migration,
|
||||
SkipMigrationFn,
|
||||
} from '../source/migration-helper.js';
|
||||
|
||||
await setup('migrate<T>', async (group) => {
|
||||
group.test('T = Date', async (test) => {
|
||||
const migrations: Array<Migration<Date, string, string>> = [
|
||||
{
|
||||
version: new Date('2022-01-01'),
|
||||
migrate: async (data: string) => `${data} migrated`,
|
||||
},
|
||||
];
|
||||
|
||||
function offsetDate(offset: number): Date {
|
||||
const d = new Date(migrations[0].version);
|
||||
d.setDate(d.getDate() + offset);
|
||||
return d;
|
||||
}
|
||||
|
||||
const data = 'data';
|
||||
test.equals(
|
||||
await migrate(data, offsetDate(-1), migrations),
|
||||
'data migrated',
|
||||
);
|
||||
test.equals(await migrate(data, offsetDate(1), migrations), data);
|
||||
});
|
||||
|
||||
group.test('T = number', async (test) => {
|
||||
const migrations: Array<Migration<number, string, string>> = [
|
||||
{
|
||||
version: 5,
|
||||
migrate: async (data: string) => `${data} migrated`,
|
||||
},
|
||||
];
|
||||
|
||||
const data = 'data';
|
||||
test.equals(await migrate(data, 4, migrations), 'data migrated');
|
||||
test.equals(await migrate(data, 6, migrations), data);
|
||||
});
|
||||
|
||||
group.test('T = {custom: number}', async (test) => {
|
||||
type Custom = {
|
||||
custom: number;
|
||||
};
|
||||
|
||||
const skip: SkipMigrationFn<Custom> = (a, b) => a.custom > b.custom;
|
||||
const migrations: Array<Migration<Custom, string, string>> = [
|
||||
{
|
||||
version: {custom: 5},
|
||||
migrate: async (data: string) => `${data} migrated`,
|
||||
},
|
||||
];
|
||||
|
||||
const data = 'data';
|
||||
test.equals(await migrate(data, {custom: 4}, migrations, skip), data);
|
||||
test.equals(
|
||||
await migrate(data, {custom: 6}, migrations, skip),
|
||||
'data migrated',
|
||||
);
|
||||
});
|
||||
|
||||
group.test('T = string', async (test) => {
|
||||
const migrations: Array<Migration<string, string, string>> = [
|
||||
{
|
||||
version: '0.2.4',
|
||||
migrate: async (data: string) => `${data} migrated`,
|
||||
},
|
||||
];
|
||||
|
||||
const data = 'data';
|
||||
test.equals(await migrate(data, '0.2.3', migrations), 'data migrated');
|
||||
test.equals(await migrate(data, '0.2.5', migrations), data);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,16 @@
|
|||
import test from 'ava';
|
||||
|
||||
import {migrate, Migration} from '../source/migration-helper.js';
|
||||
|
||||
test('migrate<number>', async (t) => {
|
||||
const migrations: Array<Migration<number, string, string>> = [
|
||||
{
|
||||
version: 5,
|
||||
migrate: async (data: string) => `${data} migrated`,
|
||||
},
|
||||
];
|
||||
|
||||
const data = 'data';
|
||||
t.is(await migrate(data, 4, migrations), 'data migrated');
|
||||
t.is(await migrate(data, 6, migrations), data);
|
||||
});
|
|
@ -0,0 +1,25 @@
|
|||
import test from 'ava';
|
||||
|
||||
import {
|
||||
migrate,
|
||||
Migration,
|
||||
SkipMigrationFn,
|
||||
} from '../source/migration-helper.js';
|
||||
|
||||
test('migrate<{custom: number}>', async (t) => {
|
||||
type Custom = {
|
||||
custom: number;
|
||||
};
|
||||
|
||||
const skip: SkipMigrationFn<Custom> = (a, b) => a.custom > b.custom;
|
||||
const migrations: Array<Migration<Custom, string, string>> = [
|
||||
{
|
||||
version: {custom: 5},
|
||||
migrate: async (data: string) => `${data} migrated`,
|
||||
},
|
||||
];
|
||||
|
||||
const data = 'data';
|
||||
t.is(await migrate(data, {custom: 4}, migrations, skip), data);
|
||||
t.is(await migrate(data, {custom: 6}, migrations, skip), 'data migrated');
|
||||
});
|
|
@ -0,0 +1,16 @@
|
|||
import test from 'ava';
|
||||
|
||||
import {migrate, Migration} from '../source/migration-helper.js';
|
||||
|
||||
test('migrate<string>', async (t) => {
|
||||
const migrations: Array<Migration<string, string, string>> = [
|
||||
{
|
||||
version: '0.2.4',
|
||||
migrate: async (data: string) => `${data} migrated`,
|
||||
},
|
||||
];
|
||||
|
||||
const data = 'data';
|
||||
t.is(await migrate(data, '0.2.3', migrations), 'data migrated');
|
||||
t.is(await migrate(data, '0.2.5', migrations), data);
|
||||
});
|
Loading…
Reference in New Issue