mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-30 12:21:57 +00:00
chore: Wrapper Data Contract
This commit is contained in:
@@ -1,24 +1,38 @@
|
||||
import { Effects, ExpectedExports } from "../types"
|
||||
import { Utils, utils } from "../util"
|
||||
import { WrapperDataContract } from "../wrapperData/wrapperDataContract"
|
||||
|
||||
export type InstallFn<WrapperData> = (opts: {
|
||||
export type InstallFn<WD> = (opts: {
|
||||
effects: Effects
|
||||
utils: Utils<WrapperData>
|
||||
utils: Utils<WD>
|
||||
}) => Promise<void>
|
||||
export class Install<WrapperData> {
|
||||
private constructor(readonly fn: InstallFn<WrapperData>) {}
|
||||
static of<WrapperData>(fn: InstallFn<WrapperData>) {
|
||||
return new Install(fn)
|
||||
export class Install<WD> {
|
||||
private constructor(
|
||||
readonly wrapperDataContract: WrapperDataContract<WD>,
|
||||
readonly fn: InstallFn<WD>,
|
||||
) {}
|
||||
static of<WD>(
|
||||
wrapperDataContract: WrapperDataContract<WD>,
|
||||
fn: InstallFn<WD>,
|
||||
) {
|
||||
return new Install(wrapperDataContract, fn)
|
||||
}
|
||||
|
||||
async init({
|
||||
effects,
|
||||
previousVersion,
|
||||
}: Parameters<ExpectedExports.init>[0]) {
|
||||
if (!previousVersion) await this.fn({ effects, utils: utils(effects) })
|
||||
if (!previousVersion)
|
||||
await this.fn({
|
||||
effects,
|
||||
utils: utils(this.wrapperDataContract, effects),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export function setupInstall<WrapperData>(fn: InstallFn<WrapperData>) {
|
||||
return Install.of(fn)
|
||||
export function setupInstall<WD>(
|
||||
wrapperDataContract: WrapperDataContract<WD>,
|
||||
fn: InstallFn<WD>,
|
||||
) {
|
||||
return Install.of(wrapperDataContract, fn)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user