mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-30 04:11:57 +00:00
feat: Remove the vault
This commit is contained in:
@@ -2,39 +2,27 @@ import { ManifestVersion } from "../../manifest/ManifestTypes"
|
||||
import { Effects } from "../../types"
|
||||
import { Utils } from "../../util/utils"
|
||||
|
||||
export class Migration<Store, Vault, Version extends ManifestVersion> {
|
||||
export class Migration<Stor, Version extends ManifestVersion> {
|
||||
constructor(
|
||||
readonly options: {
|
||||
version: Version
|
||||
up: (opts: {
|
||||
effects: Effects
|
||||
utils: Utils<Store, Vault>
|
||||
}) => Promise<void>
|
||||
down: (opts: {
|
||||
effects: Effects
|
||||
utils: Utils<Store, Vault>
|
||||
}) => Promise<void>
|
||||
up: (opts: { effects: Effects; utils: Utils<Stor> }) => Promise<void>
|
||||
down: (opts: { effects: Effects; utils: Utils<Stor> }) => Promise<void>
|
||||
},
|
||||
) {}
|
||||
static of<Store, Vault, Version extends ManifestVersion>(options: {
|
||||
static of<Stor, Version extends ManifestVersion>(options: {
|
||||
version: Version
|
||||
up: (opts: {
|
||||
effects: Effects
|
||||
utils: Utils<Store, Vault>
|
||||
}) => Promise<void>
|
||||
down: (opts: {
|
||||
effects: Effects
|
||||
utils: Utils<Store, Vault>
|
||||
}) => Promise<void>
|
||||
up: (opts: { effects: Effects; utils: Utils<Stor> }) => Promise<void>
|
||||
down: (opts: { effects: Effects; utils: Utils<Stor> }) => Promise<void>
|
||||
}) {
|
||||
return new Migration<Store, Vault, Version>(options)
|
||||
return new Migration<Stor, Version>(options)
|
||||
}
|
||||
|
||||
async up(opts: { effects: Effects; utils: Utils<Store, Vault> }) {
|
||||
async up(opts: { effects: Effects; utils: Utils<Stor> }) {
|
||||
this.up(opts)
|
||||
}
|
||||
|
||||
async down(opts: { effects: Effects; utils: Utils<Store, Vault> }) {
|
||||
async down(opts: { effects: Effects; utils: Utils<Stor> }) {
|
||||
this.down(opts)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,34 +5,30 @@ import { createUtils } from "../../util"
|
||||
import { once } from "../../util/once"
|
||||
import { Migration } from "./Migration"
|
||||
|
||||
export class Migrations<Store, Vault> {
|
||||
export class Migrations<Store> {
|
||||
private constructor(
|
||||
readonly manifest: SDKManifest,
|
||||
readonly migrations: Array<Migration<Store, Vault, any>>,
|
||||
readonly migrations: Array<Migration<Store, any>>,
|
||||
) {}
|
||||
private sortedMigrations = once(() => {
|
||||
const migrationsAsVersions = (
|
||||
this.migrations as Array<Migration<Store, Vault, any>>
|
||||
this.migrations as Array<Migration<Store, any>>
|
||||
).map((x) => [EmVer.parse(x.options.version), x] as const)
|
||||
migrationsAsVersions.sort((a, b) => a[0].compareForSort(b[0]))
|
||||
return migrationsAsVersions
|
||||
})
|
||||
private currentVersion = once(() => EmVer.parse(this.manifest.version))
|
||||
static of<
|
||||
Store,
|
||||
Vault,
|
||||
Migrations extends Array<Migration<Store, Vault, any>>,
|
||||
>(manifest: SDKManifest, ...migrations: EnsureUniqueId<Migrations>) {
|
||||
return new Migrations(
|
||||
manifest,
|
||||
migrations as Array<Migration<Store, Vault, any>>,
|
||||
)
|
||||
static of<Store, Migrations extends Array<Migration<Store, any>>>(
|
||||
manifest: SDKManifest,
|
||||
...migrations: EnsureUniqueId<Migrations>
|
||||
) {
|
||||
return new Migrations(manifest, migrations as Array<Migration<Store, any>>)
|
||||
}
|
||||
async init({
|
||||
effects,
|
||||
previousVersion,
|
||||
}: Parameters<ExpectedExports.init>[0]) {
|
||||
const utils = createUtils<Store, Vault>(effects)
|
||||
const utils = createUtils<Store>(effects)
|
||||
if (!!previousVersion) {
|
||||
const previousVersionEmVer = EmVer.parse(previousVersion)
|
||||
for (const [_, migration] of this.sortedMigrations()
|
||||
@@ -46,7 +42,7 @@ export class Migrations<Store, Vault> {
|
||||
effects,
|
||||
nextVersion,
|
||||
}: Parameters<ExpectedExports.uninit>[0]) {
|
||||
const utils = createUtils<Store, Vault>(effects)
|
||||
const utils = createUtils<Store>(effects)
|
||||
if (!!nextVersion) {
|
||||
const nextVersionEmVer = EmVer.parse(nextVersion)
|
||||
const reversed = [...this.sortedMigrations()].reverse()
|
||||
@@ -61,16 +57,15 @@ export class Migrations<Store, Vault> {
|
||||
|
||||
export function setupMigrations<
|
||||
Store,
|
||||
Vault,
|
||||
Migrations extends Array<Migration<Store, Vault, any>>,
|
||||
Migrations extends Array<Migration<Store, any>>,
|
||||
>(manifest: SDKManifest, ...migrations: EnsureUniqueId<Migrations>) {
|
||||
return Migrations.of<Store, Vault, Migrations>(manifest, ...migrations)
|
||||
return Migrations.of<Store, Migrations>(manifest, ...migrations)
|
||||
}
|
||||
|
||||
// prettier-ignore
|
||||
export type EnsureUniqueId<A, B = A, ids = never> =
|
||||
B extends [] ? A :
|
||||
B extends [Migration<any,any, infer id>, ...infer Rest] ? (
|
||||
B extends [Migration<any, infer id>, ...infer Rest] ? (
|
||||
id extends ids ? "One of the ids are not unique"[] :
|
||||
EnsureUniqueId<A, Rest, id | ids>
|
||||
) : "There exists a migration that is not a Migration"[]
|
||||
|
||||
Reference in New Issue
Block a user