mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-26 02:11:56 +00:00
chore: Updates something
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
export * as matches from "ts-matches";
|
||||
export * as TOML from "@iarna/toml";
|
||||
export * as YAML from "yaml";
|
||||
export * as types from "./types";
|
||||
export * as compat from "./compat/mod";
|
||||
// export * as migrations from "./migrations";
|
||||
export * as Types from "./types";
|
||||
export * as healthUtil from "./healthUtil";
|
||||
export * as util from "./util";
|
||||
export * as configBuilder from "./config_builder/mod";
|
||||
|
||||
@@ -1,93 +0,0 @@
|
||||
import { types as T } from "./index";
|
||||
import { EmVer } from "./emver-lite/mod";
|
||||
import * as matches from "ts-matches";
|
||||
import { LegacyExpectedExports as ExpectedExports } from "./types";
|
||||
|
||||
export class Migration2<Version extends string> {
|
||||
version: Version;
|
||||
up: (effects: T.Effects) => Promise<T.MigrationRes>;
|
||||
down: (effects: T.Effects) => Promise<T.MigrationRes>;
|
||||
constructor(options: {
|
||||
version: Version;
|
||||
up: (effects: T.Effects) => Promise<T.MigrationRes>;
|
||||
down: (effects: T.Effects) => Promise<T.MigrationRes>;
|
||||
}) {
|
||||
this.version = options.version;
|
||||
this.up = options.up;
|
||||
this.down = options.down;
|
||||
}
|
||||
}
|
||||
export class MigrationMapping2<Migrations extends Migration2<string>[]> {
|
||||
constructor(readonly migrations: Migrations) {}
|
||||
}
|
||||
|
||||
export type MigrationFn<version extends string, type extends "up" | "down"> = (
|
||||
effects: T.Effects
|
||||
) => Promise<T.MigrationRes> & { _type: type; _version: version };
|
||||
|
||||
export function migrationFn<version extends string, type extends "up" | "down">(
|
||||
fn: (effects: T.Effects) => Promise<T.MigrationRes>
|
||||
): MigrationFn<version, type> {
|
||||
return fn as MigrationFn<version, type>;
|
||||
}
|
||||
|
||||
export interface Migration<version extends string> {
|
||||
up: MigrationFn<version, "up">;
|
||||
down: MigrationFn<version, "down">;
|
||||
}
|
||||
|
||||
export type MigrationMapping<versions extends string> = {
|
||||
[version in versions]: Migration<version>;
|
||||
};
|
||||
|
||||
export function fromMapping<versions extends string>(
|
||||
migrations: MigrationMapping<versions>,
|
||||
currentVersion: string
|
||||
): ExpectedExports.migration {
|
||||
const directionShape = matches.literals("from", "to");
|
||||
return async (effects: T.Effects, version: string, direction?: unknown) => {
|
||||
if (!directionShape.test(direction)) {
|
||||
return { error: 'Must specify arg "from" or "to".' };
|
||||
}
|
||||
|
||||
let configured = true;
|
||||
|
||||
const current = EmVer.parse(currentVersion);
|
||||
const other = EmVer.parse(version);
|
||||
|
||||
const filteredMigrations = (
|
||||
Object.entries(migrations) as [
|
||||
keyof MigrationMapping<string>,
|
||||
Migration<string>
|
||||
][]
|
||||
)
|
||||
.map(([version, migration]) => ({
|
||||
version: EmVer.parse(version),
|
||||
migration,
|
||||
}))
|
||||
.filter(
|
||||
({ version }) =>
|
||||
version.greaterThan(other) && version.lessThanOrEqual(current)
|
||||
);
|
||||
|
||||
const migrationsToRun = matches
|
||||
.matches(direction)
|
||||
.when("from", () =>
|
||||
filteredMigrations
|
||||
.sort((a, b) => a.version.compareForSort(b.version)) // low to high
|
||||
.map(({ migration }) => migration.up)
|
||||
)
|
||||
.when("to", () =>
|
||||
filteredMigrations
|
||||
.sort((a, b) => b.version.compareForSort(a.version)) // high to low
|
||||
.map(({ migration }) => migration.down)
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
for (const migration of migrationsToRun) {
|
||||
configured = (await migration(effects)).configured && configured;
|
||||
}
|
||||
|
||||
return { result: { configured } };
|
||||
};
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
describe("Properties Matcher", () => {
|
||||
test("matches", () => {
|
||||
});
|
||||
test("matches", () => {});
|
||||
});
|
||||
// import * as PM from "./propertiesMatcher";
|
||||
// import { expect } from "https://deno.land/x/expect@v0.2.9/mod";
|
||||
|
||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "start-sdk",
|
||||
"version": "0.4.0-lib0.alpha0",
|
||||
"version": "0.4.0-lib0.alpha1",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "start-sdk",
|
||||
"version": "0.4.0-lib0.alpha0",
|
||||
"version": "0.4.0-lib0.alpha1",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@iarna/toml": "^2.2.5",
|
||||
|
||||
Reference in New Issue
Block a user