diff --git a/lib/index.ts b/lib/index.ts index bc8087d..5779781 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -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"; diff --git a/lib/migrations.ts b/lib/migrations.ts deleted file mode 100644 index 3f8b9f5..0000000 --- a/lib/migrations.ts +++ /dev/null @@ -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: Version; - up: (effects: T.Effects) => Promise; - down: (effects: T.Effects) => Promise; - constructor(options: { - version: Version; - up: (effects: T.Effects) => Promise; - down: (effects: T.Effects) => Promise; - }) { - this.version = options.version; - this.up = options.up; - this.down = options.down; - } -} -export class MigrationMapping2[]> { - constructor(readonly migrations: Migrations) {} -} - -export type MigrationFn = ( - effects: T.Effects -) => Promise & { _type: type; _version: version }; - -export function migrationFn( - fn: (effects: T.Effects) => Promise -): MigrationFn { - return fn as MigrationFn; -} - -export interface Migration { - up: MigrationFn; - down: MigrationFn; -} - -export type MigrationMapping = { - [version in versions]: Migration; -}; - -export function fromMapping( - migrations: MigrationMapping, - 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, - Migration - ][] - ) - .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 } }; - }; -} diff --git a/lib/utils/propertiesMatcher.test.ts b/lib/utils/propertiesMatcher.test.ts index df2dc88..e1ee694 100644 --- a/lib/utils/propertiesMatcher.test.ts +++ b/lib/utils/propertiesMatcher.test.ts @@ -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"; diff --git a/package-lock.json b/package-lock.json index 79ac408..60f4ff6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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",