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