mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-30 12:21:57 +00:00
chore: Use the types from the fronted system
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { YAML } from "../dependencies.ts";
|
||||
import { matches } from "../dependencies.ts";
|
||||
import { ExpectedExports } from "../types.ts";
|
||||
import { ConfigSpec } from "../types.ts";
|
||||
import { ConfigSpec } from "../types/config-types.ts";
|
||||
import { typeFromProps, TypeFromProps } from "../utils/propertiesMatcher.ts";
|
||||
|
||||
const { any, string, dictionary } = matches;
|
||||
|
||||
@@ -3,6 +3,7 @@ import * as T from "../types.ts";
|
||||
import * as M from "../migrations.ts";
|
||||
import * as util from "../util.ts";
|
||||
import { EmVer } from "../emver-lite/mod.ts";
|
||||
import { ConfigSpec } from "../types/config-types.ts";
|
||||
|
||||
export interface NoRepeat<version extends string, type extends "up" | "down"> {
|
||||
version: version;
|
||||
@@ -16,14 +17,11 @@ export interface NoRepeat<version extends string, type extends "up" | "down"> {
|
||||
* @param noFail (optional, default:false) whether or not to fail the migration if fn throws an error
|
||||
* @returns a migraion function
|
||||
*/
|
||||
export function updateConfig<
|
||||
version extends string,
|
||||
type extends "up" | "down",
|
||||
>(
|
||||
fn: (config: T.Config, effects: T.Effects) => T.Config | Promise<T.Config>,
|
||||
configured: boolean,
|
||||
noRepeat?: NoRepeat<version, type>,
|
||||
noFail = false,
|
||||
export function updateConfig<version extends string, type extends "up" | "down">(
|
||||
fn: (config: ConfigSpec, effects: T.Effects) => ConfigSpec | Promise<ConfigSpec>,
|
||||
configured: boolean,
|
||||
noRepeat?: NoRepeat<version, type>,
|
||||
noFail = false
|
||||
): M.MigrationFn<version, type> {
|
||||
return M.migrationFn(async (effects: T.Effects) => {
|
||||
await noRepeatGuard(effects, noRepeat, async () => {
|
||||
@@ -45,20 +43,15 @@ export function updateConfig<
|
||||
});
|
||||
}
|
||||
|
||||
export async function noRepeatGuard<
|
||||
version extends string,
|
||||
type extends "up" | "down",
|
||||
>(
|
||||
effects: T.Effects,
|
||||
noRepeat: NoRepeat<version, type> | undefined,
|
||||
fn: () => Promise<void>,
|
||||
export async function noRepeatGuard<version extends string, type extends "up" | "down">(
|
||||
effects: T.Effects,
|
||||
noRepeat: NoRepeat<version, type> | undefined,
|
||||
fn: () => Promise<void>
|
||||
): Promise<void> {
|
||||
if (!noRepeat) {
|
||||
return fn();
|
||||
}
|
||||
if (
|
||||
!await util.exists(effects, { path: "start9/migrations", volumeId: "main" })
|
||||
) {
|
||||
if (!(await util.exists(effects, { path: "start9/migrations", volumeId: "main" }))) {
|
||||
await effects.createDir({ path: "start9/migrations", volumeId: "main" });
|
||||
}
|
||||
const migrationPath = {
|
||||
@@ -66,7 +59,7 @@ export async function noRepeatGuard<
|
||||
volumeId: "main",
|
||||
};
|
||||
if (noRepeat.type === "up") {
|
||||
if (!await util.exists(effects, migrationPath)) {
|
||||
if (!(await util.exists(effects, migrationPath))) {
|
||||
await fn();
|
||||
await effects.writeFile({ ...migrationPath, toWrite: "" });
|
||||
}
|
||||
@@ -81,11 +74,9 @@ export async function noRepeatGuard<
|
||||
export async function initNoRepeat<versions extends string>(
|
||||
effects: T.Effects,
|
||||
migrations: M.MigrationMapping<versions>,
|
||||
startingVersion: string,
|
||||
startingVersion: string
|
||||
) {
|
||||
if (
|
||||
!await util.exists(effects, { path: "start9/migrations", volumeId: "main" })
|
||||
) {
|
||||
if (!(await util.exists(effects, { path: "start9/migrations", volumeId: "main" }))) {
|
||||
const starting = EmVer.parse(startingVersion);
|
||||
await effects.createDir({ path: "start9/migrations", volumeId: "main" });
|
||||
for (const version in migrations) {
|
||||
@@ -103,19 +94,11 @@ export async function initNoRepeat<versions extends string>(
|
||||
|
||||
export function fromMapping<versions extends string>(
|
||||
migrations: M.MigrationMapping<versions>,
|
||||
currentVersion: string,
|
||||
currentVersion: string
|
||||
): T.ExpectedExports.migration {
|
||||
const inner = M.fromMapping(migrations, currentVersion);
|
||||
return async (
|
||||
effects: T.Effects,
|
||||
version: string,
|
||||
direction?: unknown,
|
||||
) => {
|
||||
await initNoRepeat(
|
||||
effects,
|
||||
migrations,
|
||||
direction === "from" ? version : currentVersion,
|
||||
);
|
||||
return async (effects: T.Effects, version: string, direction?: unknown) => {
|
||||
await initNoRepeat(effects, migrations, direction === "from" ? version : currentVersion);
|
||||
return inner(effects, version, direction);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
import { YAML } from "../dependencies.ts";
|
||||
import {
|
||||
Config,
|
||||
DependsOn,
|
||||
Effects,
|
||||
ExpectedExports,
|
||||
SetResult,
|
||||
} from "../types.ts";
|
||||
import { DependsOn, Effects, ExpectedExports, SetResult } from "../types.ts";
|
||||
import { ConfigSpec } from "../types/config-types.ts";
|
||||
|
||||
/**
|
||||
* Will set the config to the default start9/config.yaml
|
||||
@@ -15,11 +10,7 @@ import {
|
||||
* @param depends_on This would be the depends on for condition depends_on
|
||||
* @returns
|
||||
*/
|
||||
export const setConfig = async (
|
||||
effects: Effects,
|
||||
newConfig: Config,
|
||||
dependsOn: DependsOn = {},
|
||||
) => {
|
||||
export const setConfig = async (effects: Effects, newConfig: ConfigSpec, dependsOn: DependsOn = {}) => {
|
||||
await effects.createDir({
|
||||
path: "start9",
|
||||
volumeId: "main",
|
||||
|
||||
Reference in New Issue
Block a user