mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 10:21:52 +00:00
* add comments to everything potentially consumer facing * rework smtp --------- Co-authored-by: Aiden McClelland <3732071+dr-bonez@users.noreply.github.com>
64 lines
1.9 KiB
TypeScript
64 lines
1.9 KiB
TypeScript
import { ExtendedVersion, VersionRange } from '../../../base/lib/exver'
|
|
import * as T from '../../../base/lib/types'
|
|
|
|
/**
|
|
* Function signature for an uninit handler that runs during service shutdown/uninstall.
|
|
*/
|
|
export type UninitFn = (
|
|
effects: T.Effects,
|
|
/**
|
|
* @description the target version to prepare for
|
|
*
|
|
* on update: the canMigrateFrom of the new package
|
|
* on uninstall: null
|
|
* on shutdown: the current version
|
|
*/
|
|
target: VersionRange | ExtendedVersion | null,
|
|
) => Promise<void | null | undefined>
|
|
|
|
/** Object form of an uninit handler — implements an `uninit()` method. */
|
|
export interface UninitScript {
|
|
uninit(
|
|
effects: T.Effects,
|
|
/**
|
|
* @description the target version to prepare for
|
|
*
|
|
* on update: the canMigrateFrom of the new package
|
|
* on uninstall: null
|
|
* on shutdown: the current version
|
|
*/
|
|
target: VersionRange | ExtendedVersion | null,
|
|
): Promise<void>
|
|
}
|
|
|
|
/** Either a {@link UninitScript} object or a {@link UninitFn} function. */
|
|
export type UninitScriptOrFn = UninitScript | UninitFn
|
|
|
|
/**
|
|
* Composes multiple uninit handlers into a single `ExpectedExports.uninit`-compatible function.
|
|
* Handlers are executed sequentially in the order provided.
|
|
*
|
|
* @param uninits - One or more uninit handlers to compose
|
|
*/
|
|
export function setupUninit(
|
|
...uninits: UninitScriptOrFn[]
|
|
): T.ExpectedExports.uninit {
|
|
return async (opts) => {
|
|
for (const uninit of uninits) {
|
|
if ('uninit' in uninit) await uninit.uninit(opts.effects, opts.target)
|
|
else await uninit(opts.effects, opts.target)
|
|
}
|
|
}
|
|
}
|
|
|
|
/** Normalizes a {@link UninitScriptOrFn} into a {@link UninitScript} object. */
|
|
export function setupOnUninit(onUninit: UninitScriptOrFn): UninitScript {
|
|
return 'uninit' in onUninit
|
|
? onUninit
|
|
: {
|
|
uninit: async (effects, target) => {
|
|
await onUninit(effects, target)
|
|
},
|
|
}
|
|
}
|