Files
start-sdk/lib/inits/setupInstall.ts
Aiden McClelland dc7a86a8e8 fixes from testing
2024-02-08 13:30:32 -07:00

34 lines
893 B
TypeScript

import { SDKManifest } from "../manifest/ManifestTypes"
import { Effects, ExpectedExports } from "../types"
import { Utils, createUtils } 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: createUtils(effects),
})
}
}
export function setupInstall<Manifest extends SDKManifest, Store>(
fn: InstallFn<Manifest, Store>,
) {
return Install.of(fn)
}