mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-26 18:31:54 +00:00
25 lines
672 B
TypeScript
25 lines
672 B
TypeScript
import { Effects, ExpectedExports } from "../types";
|
|
import { Utils, utils } from "../util";
|
|
|
|
export type InstallFn<WrapperData> = (opts: {
|
|
effects: Effects;
|
|
utils: Utils<WrapperData>;
|
|
}) => Promise<void>;
|
|
export class Install<WrapperData> {
|
|
private constructor(readonly fn: InstallFn<WrapperData>) {}
|
|
static of<WrapperData>(fn: InstallFn<WrapperData>) {
|
|
return new Install(fn);
|
|
}
|
|
|
|
async init({
|
|
effects,
|
|
previousVersion,
|
|
}: Parameters<ExpectedExports.init>[0]) {
|
|
if (!previousVersion) await this.fn({ effects, utils: utils(effects) });
|
|
}
|
|
}
|
|
|
|
export function setupInstall<WrapperData>(fn: InstallFn<WrapperData>) {
|
|
return Install.of(fn);
|
|
}
|