mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-30 12:21:57 +00:00
fix types
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { SDKManifest } from "../manifest/ManifestTypes"
|
import { SDKManifest } from "../manifest/ManifestTypes"
|
||||||
import { Dependency, PackageId } from "../types"
|
import { Dependency } from "../types"
|
||||||
|
|
||||||
export type Dependencies<T extends SDKManifest> = {
|
export type Dependencies<T extends SDKManifest> = {
|
||||||
exists(id: keyof T["dependencies"]): Dependency
|
exists(id: keyof T["dependencies"]): Dependency
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { InterfaceReceipt } from "../mainFn/interfaceReceipt"
|
import { Effects } from "../types"
|
||||||
import { Daemon, Effects } from "../types"
|
|
||||||
import { CheckResult } from "./checkFns/CheckResult"
|
import { CheckResult } from "./checkFns/CheckResult"
|
||||||
import { HealthReceipt } from "./HealthReceipt"
|
import { HealthReceipt } from "./HealthReceipt"
|
||||||
import { Trigger } from "./trigger"
|
import { Trigger } from "./trigger"
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { ManifestVersion } from "../../manifest/ManifestTypes"
|
|||||||
import { Effects } from "../../types"
|
import { Effects } from "../../types"
|
||||||
import { Utils } from "../../util"
|
import { Utils } from "../../util"
|
||||||
|
|
||||||
export class Migration<Version extends ManifestVersion, WD> {
|
export class Migration<WD, Version = ManifestVersion> {
|
||||||
constructor(
|
constructor(
|
||||||
readonly options: {
|
readonly options: {
|
||||||
version: Version
|
version: Version
|
||||||
@@ -10,10 +10,10 @@ export class Migration<Version extends ManifestVersion, WD> {
|
|||||||
down: (opts: { effects: Effects; utils: Utils<WD> }) => Promise<void>
|
down: (opts: { effects: Effects; utils: Utils<WD> }) => Promise<void>
|
||||||
},
|
},
|
||||||
) {}
|
) {}
|
||||||
static of<Version extends ManifestVersion>(options: {
|
static of<WD, Version = ManifestVersion>(options: {
|
||||||
version: Version
|
version: Version
|
||||||
up: (opts: { effects: Effects }) => Promise<void>
|
up: (opts: { effects: Effects; utils: Utils<WD> }) => Promise<void>
|
||||||
down: (opts: { effects: Effects }) => Promise<void>
|
down: (opts: { effects: Effects; utils: Utils<WD> }) => Promise<void>
|
||||||
}) {
|
}) {
|
||||||
return new Migration(options)
|
return new Migration(options)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,21 +7,21 @@ import { Migration } from "./Migration"
|
|||||||
export class Migrations<WD> {
|
export class Migrations<WD> {
|
||||||
private constructor(
|
private constructor(
|
||||||
readonly manifest: SDKManifest,
|
readonly manifest: SDKManifest,
|
||||||
readonly migrations: Array<Migration<any, WD>>,
|
readonly migrations: Array<Migration<WD, any>>,
|
||||||
) {}
|
) {}
|
||||||
private sortedMigrations = once(() => {
|
private sortedMigrations = once(() => {
|
||||||
const migrationsAsVersions = (
|
const migrationsAsVersions = (
|
||||||
this.migrations as Array<Migration<any, WD>>
|
this.migrations as Array<Migration<WD, any>>
|
||||||
).map((x) => [EmVer.parse(x.options.version), x] as const)
|
).map((x) => [EmVer.parse(x.options.version), x] as const)
|
||||||
migrationsAsVersions.sort((a, b) => a[0].compareForSort(b[0]))
|
migrationsAsVersions.sort((a, b) => a[0].compareForSort(b[0]))
|
||||||
return migrationsAsVersions
|
return migrationsAsVersions
|
||||||
})
|
})
|
||||||
private currentVersion = once(() => EmVer.parse(this.manifest.version))
|
private currentVersion = once(() => EmVer.parse(this.manifest.version))
|
||||||
static of<Migrations extends Array<Migration<any, WD>>, WD>(
|
static of<Migrations extends Array<Migration<WD, any>>, WD>(
|
||||||
manifest: SDKManifest,
|
manifest: SDKManifest,
|
||||||
...migrations: EnsureUniqueId<Migrations, WD>
|
...migrations: EnsureUniqueId<Migrations, WD>
|
||||||
) {
|
) {
|
||||||
return new Migrations(manifest, migrations as Array<Migration<any, WD>>)
|
return new Migrations(manifest, migrations as Array<Migration<WD, any>>)
|
||||||
}
|
}
|
||||||
async init({
|
async init({
|
||||||
effects,
|
effects,
|
||||||
@@ -55,7 +55,7 @@ export class Migrations<WD> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function setupMigrations<
|
export function setupMigrations<
|
||||||
Migrations extends Array<Migration<any, WD>>,
|
Migrations extends Array<Migration<WD, any>>,
|
||||||
WD,
|
WD,
|
||||||
>(manifest: SDKManifest, ...migrations: EnsureUniqueId<Migrations, WD>) {
|
>(manifest: SDKManifest, ...migrations: EnsureUniqueId<Migrations, WD>) {
|
||||||
return Migrations.of(manifest, ...migrations)
|
return Migrations.of(manifest, ...migrations)
|
||||||
@@ -64,7 +64,7 @@ export function setupMigrations<
|
|||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
export type EnsureUniqueId<A, WD, B = A, ids = never> =
|
export type EnsureUniqueId<A, WD, B = A, ids = never> =
|
||||||
B extends [] ? A :
|
B extends [] ? A :
|
||||||
B extends [Migration<infer id, WD>, ...infer Rest] ? (
|
B extends [Migration<WD, infer id>, ...infer Rest] ? (
|
||||||
id extends ids ? "One of the ids are not unique"[] :
|
id extends ids ? "One of the ids are not unique"[] :
|
||||||
EnsureUniqueId<A, Rest, id | ids>
|
EnsureUniqueId<A, Rest, id | ids>
|
||||||
) : "There exists a migration that is not a Migration"[]
|
) : "There exists a migration that is not a Migration"[]
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@start9labs/start-sdk",
|
"name": "@start9labs/start-sdk",
|
||||||
"version": "0.4.0-rev0.lib0.rc1",
|
"version": "0.4.0-rev0.lib0.rc2",
|
||||||
"description": "For making the patterns that are wanted in making services for the startOS.",
|
"description": "For making the patterns that are wanted in making services for the startOS.",
|
||||||
"main": "./lib/index.js",
|
"main": "./lib/index.js",
|
||||||
"types": "./lib/index.d.ts",
|
"types": "./lib/index.d.ts",
|
||||||
|
|||||||
Reference in New Issue
Block a user