Files
start-os/sdk/lib/inits/setupUninstall.ts
Aiden McClelland c174b65465 create version graph to handle migrations (#2708)
* create version graph to handle migrations

* Fix some version alpha test

* connect dataVersion api

* rename init fns

* improve types and add tests

* set data version after backup restore

* chore: Add some types tests for version info

* wip: More changes to versionInfo tests

* wip: fix my stupid

* update mocks

* update runtime

* chore: Fix the loop

---------

Co-authored-by: Jade <2364004+Blu-J@users.noreply.github.com>
Co-authored-by: J H <dragondef@gmail.com>
2024-08-15 20:58:53 +00:00

30 lines
710 B
TypeScript

import * as T from "../types"
export type UninstallFn<Manifest extends T.Manifest, Store> = (opts: {
effects: T.Effects
}) => Promise<void>
export class Uninstall<Manifest extends T.Manifest, Store> {
private constructor(readonly fn: UninstallFn<Manifest, Store>) {}
static of<Manifest extends T.Manifest, Store>(
fn: UninstallFn<Manifest, Store>,
) {
return new Uninstall(fn)
}
async uninstall({
effects,
nextVersion,
}: Parameters<T.ExpectedExports.uninit>[0]) {
if (!nextVersion)
await this.fn({
effects,
})
}
}
export function setupUninstall<Manifest extends T.Manifest, Store>(
fn: UninstallFn<Manifest, Store>,
) {
return Uninstall.of(fn)
}