mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-26 02:11:56 +00:00
chore: Update to fix the types
This commit is contained in:
@@ -94,7 +94,7 @@ export class StartSdk<Manifest extends SDKManifest, Store> {
|
||||
}) => Promise<ActionResult>,
|
||||
) => {
|
||||
const { input, ...rest } = metaData
|
||||
return createAction<Store, ConfigType, Type>(rest, fn, input)
|
||||
return createAction<Manifest, Store, ConfigType, Type>(rest, fn, input)
|
||||
},
|
||||
createDynamicAction: <
|
||||
ConfigType extends
|
||||
@@ -114,7 +114,11 @@ export class StartSdk<Manifest extends SDKManifest, Store> {
|
||||
}) => Promise<ActionResult>,
|
||||
input: Config<Type, Store> | Config<Type, never>,
|
||||
) => {
|
||||
return createAction<Store, ConfigType, Type>(metaData, fn, input)
|
||||
return createAction<Manifest, Store, ConfigType, Type>(
|
||||
metaData,
|
||||
fn,
|
||||
input,
|
||||
)
|
||||
},
|
||||
|
||||
HealthCheck: {
|
||||
@@ -127,7 +131,7 @@ export class StartSdk<Manifest extends SDKManifest, Store> {
|
||||
},
|
||||
patterns,
|
||||
setupActions: (...createdActions: CreatedAction<any, any, any>[]) =>
|
||||
setupActions<Store>(...createdActions),
|
||||
setupActions<Manifest, Store>(...createdActions),
|
||||
setupBackups: (...args: SetupBackupsParams<Manifest>) =>
|
||||
setupBackups<Manifest>(...args),
|
||||
setupConfig: <
|
||||
@@ -168,26 +172,26 @@ export class StartSdk<Manifest extends SDKManifest, Store> {
|
||||
setupExports: (fn: SetupExports<Store>) => fn,
|
||||
setupDependencyMounts,
|
||||
setupInit: (
|
||||
migrations: Migrations<Store>,
|
||||
install: Install<Store>,
|
||||
uninstall: Uninstall<Store>,
|
||||
setInterfaces: SetInterfaces<Store, any, any>,
|
||||
migrations: Migrations<Manifest, Store>,
|
||||
install: Install<Manifest, Store>,
|
||||
uninstall: Uninstall<Manifest, Store>,
|
||||
setInterfaces: SetInterfaces<Manifest, Store, any, any>,
|
||||
setupExports: SetupExports<Store>,
|
||||
) =>
|
||||
setupInit<Store>(
|
||||
setupInit<Manifest, Store>(
|
||||
migrations,
|
||||
install,
|
||||
uninstall,
|
||||
setInterfaces,
|
||||
setupExports,
|
||||
),
|
||||
setupInstall: (fn: InstallFn<Store>) => Install.of(fn),
|
||||
setupInstall: (fn: InstallFn<Manifest, Store>) => Install.of(fn),
|
||||
setupInterfaces: <
|
||||
ConfigInput extends Record<string, any>,
|
||||
Output extends InterfacesReceipt,
|
||||
>(
|
||||
config: Config<ConfigInput, Store>,
|
||||
fn: SetInterfaces<Store, ConfigInput, Output>,
|
||||
fn: SetInterfaces<Manifest, Store, ConfigInput, Output>,
|
||||
) => setupInterfaces(config, fn),
|
||||
setupMain: (
|
||||
fn: (o: {
|
||||
@@ -196,10 +200,17 @@ export class StartSdk<Manifest extends SDKManifest, Store> {
|
||||
utils: Utils<Manifest, Store, {}>
|
||||
}) => Promise<Daemons<Manifest, any>>,
|
||||
) => setupMain<Manifest, Store>(fn),
|
||||
setupMigrations: <Migrations extends Array<Migration<Store, any>>>(
|
||||
setupMigrations: <
|
||||
Migrations extends Array<Migration<Manifest, Store, any>>,
|
||||
>(
|
||||
...migrations: EnsureUniqueId<Migrations>
|
||||
) => setupMigrations<Store, Migrations>(this.manifest, ...migrations),
|
||||
setupUninstall: (fn: UninstallFn<Store>) => setupUninstall<Store>(fn),
|
||||
) =>
|
||||
setupMigrations<Manifest, Store, Migrations>(
|
||||
this.manifest,
|
||||
...migrations,
|
||||
),
|
||||
setupUninstall: (fn: UninstallFn<Manifest, Store>) =>
|
||||
setupUninstall<Manifest, Store>(fn),
|
||||
trigger: {
|
||||
defaultTrigger,
|
||||
cooldownTrigger,
|
||||
@@ -331,7 +342,7 @@ export class StartSdk<Manifest extends SDKManifest, Store> {
|
||||
effects: Effects
|
||||
utils: Utils<Manifest, Store>
|
||||
}) => Promise<void>
|
||||
}) => Migration.of<Store, Version>(options),
|
||||
}) => Migration.of<Manifest, Store, Version>(options),
|
||||
},
|
||||
Value: {
|
||||
toggle: Value.toggle,
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
import { Config, ExtractConfigType } from "../config/builder/config"
|
||||
import { SDKManifest } from "../manifest/ManifestTypes"
|
||||
import { ActionMetadata, ActionResult, Effects, ExportedAction } from "../types"
|
||||
import { createUtils } from "../util"
|
||||
import { Utils } from "../util/utils"
|
||||
|
||||
export type MaybeFn<Store, Value> =
|
||||
export type MaybeFn<Manifest extends SDKManifest, Store, Value> =
|
||||
| Value
|
||||
| ((options: {
|
||||
effects: Effects
|
||||
utils: Utils<Store>
|
||||
utils: Utils<Manifest, Store>
|
||||
}) => Promise<Value> | Value)
|
||||
export class CreatedAction<
|
||||
Manifest extends SDKManifest,
|
||||
Store,
|
||||
ConfigType extends
|
||||
| Record<string, any>
|
||||
@@ -18,17 +20,22 @@ export class CreatedAction<
|
||||
Type extends Record<string, any> = ExtractConfigType<ConfigType>,
|
||||
> {
|
||||
private constructor(
|
||||
public readonly myMetaData: MaybeFn<Store, Omit<ActionMetadata, "input">>,
|
||||
public readonly myMetaData: MaybeFn<
|
||||
Manifest,
|
||||
Store,
|
||||
Omit<ActionMetadata, "input">
|
||||
>,
|
||||
readonly fn: (options: {
|
||||
effects: Effects
|
||||
utils: Utils<Store>
|
||||
utils: Utils<Manifest, Store>
|
||||
input: Type
|
||||
}) => Promise<ActionResult>,
|
||||
readonly input: Config<Type, Store>,
|
||||
public validator = input.validator,
|
||||
) {}
|
||||
public validator = this.input.validator
|
||||
|
||||
static of<
|
||||
Manifest extends SDKManifest,
|
||||
Store,
|
||||
ConfigType extends
|
||||
| Record<string, any>
|
||||
@@ -36,15 +43,15 @@ export class CreatedAction<
|
||||
| Config<any, never>,
|
||||
Type extends Record<string, any> = ExtractConfigType<ConfigType>,
|
||||
>(
|
||||
metaData: MaybeFn<Store, Omit<ActionMetadata, "input">>,
|
||||
metaData: MaybeFn<Manifest, Store, Omit<ActionMetadata, "input">>,
|
||||
fn: (options: {
|
||||
effects: Effects
|
||||
utils: Utils<Store>
|
||||
utils: Utils<Manifest, Store>
|
||||
input: Type
|
||||
}) => Promise<ActionResult>,
|
||||
inputConfig: Config<Type, Store> | Config<Type, never>,
|
||||
) {
|
||||
return new CreatedAction<Store, ConfigType, Type>(
|
||||
return new CreatedAction<Manifest, Store, ConfigType, Type>(
|
||||
metaData,
|
||||
fn,
|
||||
inputConfig as Config<Type, Store>,
|
||||
@@ -67,7 +74,7 @@ export class CreatedAction<
|
||||
})
|
||||
}
|
||||
|
||||
async metaData(options: { effects: Effects; utils: Utils<Store> }) {
|
||||
async metaData(options: { effects: Effects; utils: Utils<Manifest, Store> }) {
|
||||
if (this.myMetaData instanceof Function)
|
||||
return await this.myMetaData(options)
|
||||
return this.myMetaData
|
||||
@@ -75,7 +82,7 @@ export class CreatedAction<
|
||||
|
||||
async ActionMetadata(options: {
|
||||
effects: Effects
|
||||
utils: Utils<Store>
|
||||
utils: Utils<Manifest, Store>
|
||||
}): Promise<ActionMetadata> {
|
||||
return {
|
||||
...(await this.metaData(options)),
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
import { SDKManifest } from "../manifest/ManifestTypes"
|
||||
import { Effects, ExpectedExports } from "../types"
|
||||
import { createUtils } from "../util"
|
||||
import { once } from "../util/once"
|
||||
import { Utils } from "../util/utils"
|
||||
import { CreatedAction } from "./createAction"
|
||||
|
||||
export function setupActions<Store>(
|
||||
...createdActions: CreatedAction<Store, any>[]
|
||||
export function setupActions<Manifest extends SDKManifest, Store>(
|
||||
...createdActions: CreatedAction<Manifest, Store, any>[]
|
||||
) {
|
||||
const myActions = async (options: {
|
||||
effects: Effects
|
||||
utils: Utils<Store>
|
||||
utils: Utils<Manifest, Store>
|
||||
}) => {
|
||||
const actions: Record<string, CreatedAction<Store, any>> = {}
|
||||
const actions: Record<string, CreatedAction<Manifest, Store, any>> = {}
|
||||
for (const action of createdActions) {
|
||||
const actionMetadata = await action.metaData(options)
|
||||
actions[actionMetadata.id] = action
|
||||
@@ -23,7 +24,7 @@ export function setupActions<Store>(
|
||||
actionsMetadata: ExpectedExports.actionsMetadata
|
||||
} = {
|
||||
actions(options: { effects: Effects }) {
|
||||
const utils = createUtils<Store>(options.effects)
|
||||
const utils = createUtils<Manifest, Store>(options.effects)
|
||||
|
||||
return myActions({
|
||||
...options,
|
||||
@@ -31,7 +32,7 @@ export function setupActions<Store>(
|
||||
})
|
||||
},
|
||||
async actionsMetadata({ effects }: { effects: Effects }) {
|
||||
const utils = createUtils<Store>(effects)
|
||||
const utils = createUtils<Manifest, Store>(effects)
|
||||
return Promise.all(
|
||||
createdActions.map((x) => x.ActionMetadata({ effects, utils })),
|
||||
)
|
||||
|
||||
@@ -7,7 +7,7 @@ import { Parser, object } from "ts-matches"
|
||||
|
||||
export type LazyBuildOptions<Store> = {
|
||||
effects: Effects
|
||||
utils: Utils<Store>
|
||||
utils: Utils<any, Store>
|
||||
}
|
||||
export type LazyBuild<Store, ExpectedOut> = (
|
||||
options: LazyBuildOptions<Store>,
|
||||
|
||||
@@ -1,28 +1,48 @@
|
||||
import { ManifestVersion } from "../../manifest/ManifestTypes"
|
||||
import { ManifestVersion, SDKManifest } from "../../manifest/ManifestTypes"
|
||||
import { Effects } from "../../types"
|
||||
import { Utils } from "../../util/utils"
|
||||
|
||||
export class Migration<Stor, Version extends ManifestVersion> {
|
||||
export class Migration<
|
||||
Manifest extends SDKManifest,
|
||||
Store,
|
||||
Version extends ManifestVersion,
|
||||
> {
|
||||
constructor(
|
||||
readonly options: {
|
||||
version: Version
|
||||
up: (opts: { effects: Effects; utils: Utils<Stor> }) => Promise<void>
|
||||
down: (opts: { effects: Effects; utils: Utils<Stor> }) => Promise<void>
|
||||
up: (opts: {
|
||||
effects: Effects
|
||||
utils: Utils<Manifest, Store>
|
||||
}) => Promise<void>
|
||||
down: (opts: {
|
||||
effects: Effects
|
||||
utils: Utils<Manifest, Store>
|
||||
}) => Promise<void>
|
||||
},
|
||||
) {}
|
||||
static of<Stor, Version extends ManifestVersion>(options: {
|
||||
static of<
|
||||
Manifest extends SDKManifest,
|
||||
Store,
|
||||
Version extends ManifestVersion,
|
||||
>(options: {
|
||||
version: Version
|
||||
up: (opts: { effects: Effects; utils: Utils<Stor> }) => Promise<void>
|
||||
down: (opts: { effects: Effects; utils: Utils<Stor> }) => Promise<void>
|
||||
up: (opts: {
|
||||
effects: Effects
|
||||
utils: Utils<Manifest, Store>
|
||||
}) => Promise<void>
|
||||
down: (opts: {
|
||||
effects: Effects
|
||||
utils: Utils<Manifest, Store>
|
||||
}) => Promise<void>
|
||||
}) {
|
||||
return new Migration<Stor, Version>(options)
|
||||
return new Migration<Manifest, Store, Version>(options)
|
||||
}
|
||||
|
||||
async up(opts: { effects: Effects; utils: Utils<Stor> }) {
|
||||
async up(opts: { effects: Effects; utils: Utils<Manifest, Store> }) {
|
||||
this.up(opts)
|
||||
}
|
||||
|
||||
async down(opts: { effects: Effects; utils: Utils<Stor> }) {
|
||||
async down(opts: { effects: Effects; utils: Utils<Manifest, Store> }) {
|
||||
this.down(opts)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,30 +5,34 @@ import { createUtils } from "../../util"
|
||||
import { once } from "../../util/once"
|
||||
import { Migration } from "./Migration"
|
||||
|
||||
export class Migrations<Store> {
|
||||
export class Migrations<Manifest extends SDKManifest, Store> {
|
||||
private constructor(
|
||||
readonly manifest: SDKManifest,
|
||||
readonly migrations: Array<Migration<Store, any>>,
|
||||
readonly migrations: Array<Migration<Manifest, Store, any>>,
|
||||
) {}
|
||||
private sortedMigrations = once(() => {
|
||||
const migrationsAsVersions = (
|
||||
this.migrations as Array<Migration<Store, any>>
|
||||
this.migrations as Array<Migration<Manifest, 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, Migrations extends Array<Migration<Store, any>>>(
|
||||
manifest: SDKManifest,
|
||||
...migrations: EnsureUniqueId<Migrations>
|
||||
) {
|
||||
return new Migrations(manifest, migrations as Array<Migration<Store, any>>)
|
||||
static of<
|
||||
Manifest extends SDKManifest,
|
||||
Store,
|
||||
Migrations extends Array<Migration<Manifest, Store, any>>,
|
||||
>(manifest: SDKManifest, ...migrations: EnsureUniqueId<Migrations>) {
|
||||
return new Migrations(
|
||||
manifest,
|
||||
migrations as Array<Migration<Manifest, Store, any>>,
|
||||
)
|
||||
}
|
||||
async init({
|
||||
effects,
|
||||
previousVersion,
|
||||
}: Parameters<ExpectedExports.init>[0]) {
|
||||
const utils = createUtils<Store>(effects)
|
||||
const utils = createUtils<Manifest, Store>(effects)
|
||||
if (!!previousVersion) {
|
||||
const previousVersionEmVer = EmVer.parse(previousVersion)
|
||||
for (const [_, migration] of this.sortedMigrations()
|
||||
@@ -42,7 +46,7 @@ export class Migrations<Store> {
|
||||
effects,
|
||||
nextVersion,
|
||||
}: Parameters<ExpectedExports.uninit>[0]) {
|
||||
const utils = createUtils<Store>(effects)
|
||||
const utils = createUtils<Manifest, Store>(effects)
|
||||
if (!!nextVersion) {
|
||||
const nextVersionEmVer = EmVer.parse(nextVersion)
|
||||
const reversed = [...this.sortedMigrations()].reverse()
|
||||
@@ -56,16 +60,17 @@ export class Migrations<Store> {
|
||||
}
|
||||
|
||||
export function setupMigrations<
|
||||
Manifest extends SDKManifest,
|
||||
Store,
|
||||
Migrations extends Array<Migration<Store, any>>,
|
||||
Migrations extends Array<Migration<Manifest, Store, any>>,
|
||||
>(manifest: SDKManifest, ...migrations: EnsureUniqueId<Migrations>) {
|
||||
return Migrations.of<Store, Migrations>(manifest, ...migrations)
|
||||
return Migrations.of<Manifest, Store, Migrations>(manifest, ...migrations)
|
||||
}
|
||||
|
||||
// prettier-ignore
|
||||
export type EnsureUniqueId<A, B = A, ids = never> =
|
||||
B extends [] ? A :
|
||||
B extends [Migration<any, infer id>, ...infer Rest] ? (
|
||||
B extends [Migration<any, 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"[]
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { SetInterfaces } from "../interfaces/setupInterfaces"
|
||||
import { SDKManifest } from "../manifest/ManifestTypes"
|
||||
import { ExpectedExports } from "../types"
|
||||
import { createUtils } from "../util"
|
||||
import { Migrations } from "./migrations/setupMigrations"
|
||||
@@ -6,11 +7,11 @@ import { SetupExports } from "./setupExports"
|
||||
import { Install } from "./setupInstall"
|
||||
import { Uninstall } from "./setupUninstall"
|
||||
|
||||
export function setupInit<Store>(
|
||||
migrations: Migrations<Store>,
|
||||
install: Install<Store>,
|
||||
uninstall: Uninstall<Store>,
|
||||
setInterfaces: SetInterfaces<Store, any, any>,
|
||||
export function setupInit<Manifest extends SDKManifest, Store>(
|
||||
migrations: Migrations<Manifest, Store>,
|
||||
install: Install<Manifest, Store>,
|
||||
uninstall: Uninstall<Manifest, Store>,
|
||||
setInterfaces: SetInterfaces<Manifest, Store, any, any>,
|
||||
setupExports: SetupExports<Store>,
|
||||
): {
|
||||
init: ExpectedExports.init
|
||||
@@ -18,7 +19,7 @@ export function setupInit<Store>(
|
||||
} {
|
||||
return {
|
||||
init: async (opts) => {
|
||||
const utils = createUtils<Store>(opts.effects)
|
||||
const utils = createUtils<Manifest, Store>(opts.effects)
|
||||
await migrations.init(opts)
|
||||
await install.init(opts)
|
||||
await setInterfaces({
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
import { SDKManifest } from "../manifest/ManifestTypes"
|
||||
import { Effects, ExpectedExports } from "../types"
|
||||
import { Utils, utils } from "../util/utils"
|
||||
|
||||
export type InstallFn<Store> = (opts: {
|
||||
export type InstallFn<Manifest extends SDKManifest, Store> = (opts: {
|
||||
effects: Effects
|
||||
utils: Utils<Store>
|
||||
utils: Utils<Manifest, Store>
|
||||
}) => Promise<void>
|
||||
export class Install<Store> {
|
||||
private constructor(readonly fn: InstallFn<Store>) {}
|
||||
static of<Store>(fn: InstallFn<Store>) {
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -23,6 +26,8 @@ export class Install<Store> {
|
||||
}
|
||||
}
|
||||
|
||||
export function setupInstall<Store>(fn: InstallFn<Store>) {
|
||||
export function setupInstall<Manifest extends SDKManifest, Store>(
|
||||
fn: InstallFn<Manifest, Store>,
|
||||
) {
|
||||
return Install.of(fn)
|
||||
}
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
import { SDKManifest } from "../manifest/ManifestTypes"
|
||||
import { Effects, ExpectedExports } from "../types"
|
||||
import { Utils, utils } from "../util/utils"
|
||||
|
||||
export type UninstallFn<Store> = (opts: {
|
||||
export type UninstallFn<Manifest extends SDKManifest, Store> = (opts: {
|
||||
effects: Effects
|
||||
utils: Utils<Store>
|
||||
utils: Utils<Manifest, Store>
|
||||
}) => Promise<void>
|
||||
export class Uninstall<Store> {
|
||||
private constructor(readonly fn: UninstallFn<Store>) {}
|
||||
static of<Store>(fn: UninstallFn<Store>) {
|
||||
export class Uninstall<Manifest extends SDKManifest, Store> {
|
||||
private constructor(readonly fn: UninstallFn<Manifest, Store>) {}
|
||||
static of<Manifest extends SDKManifest, Store>(
|
||||
fn: UninstallFn<Manifest, Store>,
|
||||
) {
|
||||
return new Uninstall(fn)
|
||||
}
|
||||
|
||||
@@ -23,6 +26,8 @@ export class Uninstall<Store> {
|
||||
}
|
||||
}
|
||||
|
||||
export function setupUninstall<Store>(fn: UninstallFn<Store>) {
|
||||
export function setupUninstall<Manifest extends SDKManifest, Store>(
|
||||
fn: UninstallFn<Manifest, Store>,
|
||||
) {
|
||||
return Uninstall.of(fn)
|
||||
}
|
||||
|
||||
@@ -1,25 +1,28 @@
|
||||
import { Config } from "../config/builder/config"
|
||||
import { SDKManifest } from "../manifest/ManifestTypes"
|
||||
import { Address, Effects } from "../types"
|
||||
import { Utils } from "../util/utils"
|
||||
import { AddressReceipt } from "./AddressReceipt"
|
||||
|
||||
export type InterfacesReceipt = Array<Address[] & AddressReceipt>
|
||||
export type SetInterfaces<
|
||||
Manifest extends SDKManifest,
|
||||
Store,
|
||||
ConfigInput extends Record<string, any>,
|
||||
Output extends InterfacesReceipt,
|
||||
> = (opts: {
|
||||
effects: Effects
|
||||
input: null | ConfigInput
|
||||
utils: Utils<Store>
|
||||
utils: Utils<Manifest, Store>
|
||||
}) => Promise<Output>
|
||||
export type SetupInterfaces = <
|
||||
Manifest extends SDKManifest,
|
||||
Store,
|
||||
ConfigInput extends Record<string, any>,
|
||||
Output extends InterfacesReceipt,
|
||||
>(
|
||||
config: Config<ConfigInput, Store>,
|
||||
fn: SetInterfaces<Store, ConfigInput, Output>,
|
||||
) => SetInterfaces<Store, ConfigInput, Output>
|
||||
fn: SetInterfaces<Manifest, Store, ConfigInput, Output>,
|
||||
) => SetInterfaces<Manifest, Store, ConfigInput, Output>
|
||||
export const NO_INTERFACE_CHANGES = [] as InterfacesReceipt
|
||||
export const setupInterfaces: SetupInterfaces = (_config, fn) => fn
|
||||
|
||||
Reference in New Issue
Block a user