mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-26 02:11:56 +00:00
chore: Remove the stupid config
This commit is contained in:
@@ -5,12 +5,12 @@ import { Utils, utils } from "../util"
|
||||
|
||||
export class CreatedAction<
|
||||
WrapperData,
|
||||
ConfigType extends Record<string, any> | Config<any, any, any>,
|
||||
ConfigType extends Record<string, any> | Config<any, any>,
|
||||
Type extends Record<string, any> = ExtractConfigType<ConfigType>,
|
||||
> {
|
||||
private constructor(
|
||||
public readonly myMetaData: Omit<ActionMetaData, "input"> & {
|
||||
input: Config<Type, WrapperData, Type>
|
||||
input: Config<Type, WrapperData>
|
||||
},
|
||||
readonly fn: (options: {
|
||||
effects: Effects
|
||||
@@ -22,11 +22,11 @@ export class CreatedAction<
|
||||
|
||||
static of<
|
||||
WrapperData,
|
||||
ConfigType extends Record<string, any> | Config<any, any, any>,
|
||||
ConfigType extends Record<string, any> | Config<any, any>,
|
||||
Type extends Record<string, any> = ExtractConfigType<ConfigType>,
|
||||
>(
|
||||
metaData: Omit<ActionMetaData, "input"> & {
|
||||
input: Config<Type, WrapperData, Type>
|
||||
input: Config<Type, WrapperData>
|
||||
},
|
||||
fn: (options: {
|
||||
effects: Effects
|
||||
@@ -52,7 +52,6 @@ export class CreatedAction<
|
||||
input: await this.myMetaData.input.build({
|
||||
effects,
|
||||
utils: myUtils,
|
||||
config: null,
|
||||
}),
|
||||
}
|
||||
await effects.exportAction(metaData)
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { GenericManifest } from "../manifest/ManifestTypes"
|
||||
import { SDKManifest } from "../manifest/ManifestTypes"
|
||||
import { AutoConfig, AutoConfigFrom } from "./AutoConfig"
|
||||
|
||||
export function setupAutoConfig<
|
||||
WD,
|
||||
Input,
|
||||
Manifest extends GenericManifest,
|
||||
Manifest extends SDKManifest,
|
||||
NestedConfigs extends {
|
||||
[key in keyof Manifest["dependencies"]]: unknown
|
||||
},
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { GenericManifest } from "../manifest/ManifestTypes"
|
||||
import { SDKManifest } from "../manifest/ManifestTypes"
|
||||
import * as T from "../types"
|
||||
|
||||
export type BACKUP = "BACKUP"
|
||||
@@ -37,14 +37,14 @@ type BackupSet<Volumes extends string> = {
|
||||
* ).build()q
|
||||
* ```
|
||||
*/
|
||||
export class Backups<M extends GenericManifest> {
|
||||
export class Backups<M extends SDKManifest> {
|
||||
static BACKUP: BACKUP = "BACKUP"
|
||||
|
||||
constructor(
|
||||
private options = DEFAULT_OPTIONS,
|
||||
private backupSet = [] as BackupSet<keyof M["volumes"] & string>[],
|
||||
) {}
|
||||
static volumes<M extends GenericManifest = never>(
|
||||
static volumes<M extends SDKManifest = never>(
|
||||
...volumeNames: Array<keyof M["volumes"] & string>
|
||||
) {
|
||||
return new Backups().addSets(
|
||||
@@ -56,12 +56,12 @@ export class Backups<M extends GenericManifest> {
|
||||
})),
|
||||
)
|
||||
}
|
||||
static addSets<M extends GenericManifest = never>(
|
||||
static addSets<M extends SDKManifest = never>(
|
||||
...options: BackupSet<keyof M["volumes"] & string>[]
|
||||
) {
|
||||
return new Backups().addSets(...options)
|
||||
}
|
||||
static with_options<M extends GenericManifest = never>(
|
||||
static with_options<M extends SDKManifest = never>(
|
||||
options?: Partial<T.BackupOptions>,
|
||||
) {
|
||||
return new Backups({ ...DEFAULT_OPTIONS, ...options })
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { string } from "ts-matches"
|
||||
import { Backups } from "."
|
||||
import { GenericManifest } from "../manifest/ManifestTypes"
|
||||
import { SDKManifest } from "../manifest/ManifestTypes"
|
||||
import { BackupOptions, ExpectedExports } from "../types"
|
||||
import { _ } from "../util"
|
||||
|
||||
export type SetupBackupsParams<M extends GenericManifest> = Array<
|
||||
export type SetupBackupsParams<M extends SDKManifest> = Array<
|
||||
(keyof M["volumes"] & string) | Backups<M>
|
||||
>
|
||||
|
||||
export function setupBackups<M extends GenericManifest>(
|
||||
export function setupBackups<M extends SDKManifest>(
|
||||
...args: _<SetupBackupsParams<M>>
|
||||
) {
|
||||
const backups = Array<Backups<M>>()
|
||||
|
||||
@@ -5,21 +5,20 @@ import { _ } from "../../util"
|
||||
import { Effects } from "../../types"
|
||||
import { Parser, object } from "ts-matches"
|
||||
|
||||
export type LazyBuildOptions<WD, ConfigType> = {
|
||||
export type LazyBuildOptions<WD> = {
|
||||
effects: Effects
|
||||
utils: Utils<WD>
|
||||
config: ConfigType | null
|
||||
}
|
||||
export type LazyBuild<WD, ConfigType, ExpectedOut> = (
|
||||
options: LazyBuildOptions<WD, ConfigType>,
|
||||
export type LazyBuild<WD, ExpectedOut> = (
|
||||
options: LazyBuildOptions<WD>,
|
||||
) => Promise<ExpectedOut> | ExpectedOut
|
||||
|
||||
// prettier-ignore
|
||||
export type ExtractConfigType<A extends Record<string, any> | Config<Record<string, any>, any, any>> =
|
||||
A extends Config<infer B, any, any> ? B :
|
||||
export type ExtractConfigType<A extends Record<string, any> | Config<Record<string, any>, any>> =
|
||||
A extends Config<infer B, any> ? B :
|
||||
A
|
||||
|
||||
export type MaybeLazyValues<A> = LazyBuild<any, any, A> | A
|
||||
export type MaybeLazyValues<A> = LazyBuild<any, A> | A
|
||||
/**
|
||||
* Configs are the specs that are used by the os configuration form for this service.
|
||||
* Here is an example of a simple configuration
|
||||
@@ -76,14 +75,14 @@ export const addNodesSpec = Config.of({ hostname: hostname, port: port });
|
||||
|
||||
```
|
||||
*/
|
||||
export class Config<Type extends Record<string, any>, WD, ConfigType> {
|
||||
export class Config<Type extends Record<string, any>, WD> {
|
||||
private constructor(
|
||||
private readonly spec: {
|
||||
[K in keyof Type]: Value<Type[K], WD, ConfigType>
|
||||
[K in keyof Type]: Value<Type[K], WD>
|
||||
},
|
||||
public validator: Parser<unknown, Type>,
|
||||
) {}
|
||||
async build(options: LazyBuildOptions<WD, ConfigType>) {
|
||||
async build(options: LazyBuildOptions<WD>) {
|
||||
const answer = {} as {
|
||||
[K in keyof Type]: ValueSpec
|
||||
}
|
||||
@@ -93,8 +92,8 @@ export class Config<Type extends Record<string, any>, WD, ConfigType> {
|
||||
return answer
|
||||
}
|
||||
|
||||
static of<Type extends Record<string, any>, WrapperData, ConfigType>(spec: {
|
||||
[K in keyof Type]: Value<Type[K], WrapperData, ConfigType>
|
||||
static of<Type extends Record<string, any>, WrapperData>(spec: {
|
||||
[K in keyof Type]: Value<Type[K], WrapperData>
|
||||
}) {
|
||||
const validatorObj = {} as {
|
||||
[K in keyof Type]: Parser<unknown, Type[K]>
|
||||
@@ -103,21 +102,22 @@ export class Config<Type extends Record<string, any>, WD, ConfigType> {
|
||||
validatorObj[key] = spec[key].validator
|
||||
}
|
||||
const validator = object(validatorObj)
|
||||
return new Config<Type, WrapperData, ConfigType>(spec, validator)
|
||||
return new Config<Type, WrapperData>(spec, validator)
|
||||
}
|
||||
|
||||
static withWrapperData<WrapperData>() {
|
||||
return {
|
||||
of<Type extends Record<string, any>>(spec: {
|
||||
[K in keyof Type]: Value<Type[K], WrapperData, Type>
|
||||
[K in keyof Type]: Value<Type[K], WrapperData>
|
||||
}) {
|
||||
return Config.of<Type, WrapperData, Type>(spec)
|
||||
return Config.of<Type, WrapperData>(spec)
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function topConfig<WrapperData>() {
|
||||
return <Type extends Record<string, any>>(spec: {
|
||||
[K in keyof Type]: Value<Type[K], WrapperData, Type>
|
||||
}) => Config.of<Type, WrapperData, Type>(spec)
|
||||
[K in keyof Type]: Value<Type[K], WrapperData>
|
||||
}) => Config.of<Type, WrapperData>(spec)
|
||||
}
|
||||
|
||||
@@ -19,12 +19,12 @@ export const authorizationList = List.string({
|
||||
export const auth = Value.list(authorizationList);
|
||||
```
|
||||
*/
|
||||
export class List<Type, WD, ConfigType> {
|
||||
export class List<Type, WD> {
|
||||
private constructor(
|
||||
public build: LazyBuild<WD, ConfigType, ValueSpecList>,
|
||||
public build: LazyBuild<WD, ValueSpecList>,
|
||||
public validator: Parser<unknown, Type>,
|
||||
) {}
|
||||
static text<WD, CT>(
|
||||
static text<WD>(
|
||||
a: {
|
||||
name: string
|
||||
description?: string | null
|
||||
@@ -45,7 +45,7 @@ export class List<Type, WD, ConfigType> {
|
||||
inputmode?: ListValueSpecText["inputmode"]
|
||||
},
|
||||
) {
|
||||
return new List<string[], WD, CT>(() => {
|
||||
return new List<string[], WD>(() => {
|
||||
const spec = {
|
||||
type: "text" as const,
|
||||
placeholder: null,
|
||||
@@ -67,10 +67,9 @@ export class List<Type, WD, ConfigType> {
|
||||
}
|
||||
}, arrayOf(string))
|
||||
}
|
||||
static dynamicText<WD, CT>(
|
||||
static dynamicText<WD>(
|
||||
getA: LazyBuild<
|
||||
WD,
|
||||
CT,
|
||||
{
|
||||
name: string
|
||||
description?: string | null
|
||||
@@ -92,7 +91,7 @@ export class List<Type, WD, ConfigType> {
|
||||
}
|
||||
>,
|
||||
) {
|
||||
return new List<string[], WD, CT>(async (options) => {
|
||||
return new List<string[], WD>(async (options) => {
|
||||
const { spec: aSpec, ...a } = await getA(options)
|
||||
const spec = {
|
||||
type: "text" as const,
|
||||
@@ -115,7 +114,7 @@ export class List<Type, WD, ConfigType> {
|
||||
}
|
||||
}, arrayOf(string))
|
||||
}
|
||||
static number<WD, CT>(
|
||||
static number<WD>(
|
||||
a: {
|
||||
name: string
|
||||
description?: string | null
|
||||
@@ -134,7 +133,7 @@ export class List<Type, WD, ConfigType> {
|
||||
placeholder?: string | null
|
||||
},
|
||||
) {
|
||||
return new List<number[], WD, CT>(() => {
|
||||
return new List<number[], WD>(() => {
|
||||
const spec = {
|
||||
type: "number" as const,
|
||||
placeholder: null,
|
||||
@@ -156,10 +155,9 @@ export class List<Type, WD, ConfigType> {
|
||||
}
|
||||
}, arrayOf(number))
|
||||
}
|
||||
static dynamicNumber<WD, CT>(
|
||||
static dynamicNumber<WD>(
|
||||
getA: LazyBuild<
|
||||
WD,
|
||||
CT,
|
||||
{
|
||||
name: string
|
||||
description?: string | null
|
||||
@@ -179,7 +177,7 @@ export class List<Type, WD, ConfigType> {
|
||||
}
|
||||
>,
|
||||
) {
|
||||
return new List<number[], WD, CT>(async (options) => {
|
||||
return new List<number[], WD>(async (options) => {
|
||||
const { spec: aSpec, ...a } = await getA(options)
|
||||
const spec = {
|
||||
type: "number" as const,
|
||||
@@ -202,7 +200,7 @@ export class List<Type, WD, ConfigType> {
|
||||
}
|
||||
}, arrayOf(number))
|
||||
}
|
||||
static obj<Type extends Record<string, any>, WrapperData, ConfigType>(
|
||||
static obj<Type extends Record<string, any>, WrapperData>(
|
||||
a: {
|
||||
name: string
|
||||
description?: string | null
|
||||
@@ -213,12 +211,12 @@ export class List<Type, WD, ConfigType> {
|
||||
maxLength?: number | null
|
||||
},
|
||||
aSpec: {
|
||||
spec: Config<Type, WrapperData, ConfigType>
|
||||
spec: Config<Type, WrapperData>
|
||||
displayAs?: null | string
|
||||
uniqueBy?: null | UniqueBy
|
||||
},
|
||||
) {
|
||||
return new List<Type[], WrapperData, ConfigType>(async (options) => {
|
||||
return new List<Type[], WrapperData>(async (options) => {
|
||||
const { spec: previousSpecSpec, ...restSpec } = aSpec
|
||||
const specSpec = await previousSpecSpec.build(options)
|
||||
const spec = {
|
||||
|
||||
@@ -93,18 +93,18 @@ const username = Value.string({
|
||||
});
|
||||
```
|
||||
*/
|
||||
export class Value<Type, WD, ConfigType> {
|
||||
export class Value<Type, WD> {
|
||||
private constructor(
|
||||
public build: LazyBuild<WD, ConfigType, ValueSpec>,
|
||||
public build: LazyBuild<WD, ValueSpec>,
|
||||
public validator: Parser<unknown, Type>,
|
||||
) {}
|
||||
static toggle<WD, CT>(a: {
|
||||
static toggle<WD>(a: {
|
||||
name: string
|
||||
description?: string | null
|
||||
warning?: string | null
|
||||
default?: boolean | null
|
||||
}) {
|
||||
return new Value<boolean, WD, CT>(
|
||||
return new Value<boolean, WD>(
|
||||
async () => ({
|
||||
description: null,
|
||||
warning: null,
|
||||
@@ -115,10 +115,9 @@ export class Value<Type, WD, ConfigType> {
|
||||
boolean,
|
||||
)
|
||||
}
|
||||
static dynamicToggle<WD, CT>(
|
||||
static dynamicToggle<WD>(
|
||||
a: LazyBuild<
|
||||
WD,
|
||||
CT,
|
||||
{
|
||||
name: string
|
||||
description?: string | null
|
||||
@@ -127,7 +126,7 @@ export class Value<Type, WD, ConfigType> {
|
||||
}
|
||||
>,
|
||||
) {
|
||||
return new Value<boolean, WD, CT>(
|
||||
return new Value<boolean, WD>(
|
||||
async (options) => ({
|
||||
description: null,
|
||||
warning: null,
|
||||
@@ -138,7 +137,7 @@ export class Value<Type, WD, ConfigType> {
|
||||
boolean,
|
||||
)
|
||||
}
|
||||
static text<Required extends RequiredDefault<DefaultString>, WD, CT>(a: {
|
||||
static text<Required extends RequiredDefault<DefaultString>, WD>(a: {
|
||||
name: string
|
||||
description?: string | null
|
||||
warning?: string | null
|
||||
@@ -153,7 +152,7 @@ export class Value<Type, WD, ConfigType> {
|
||||
/** Default = 'text' */
|
||||
inputmode?: ValueSpecText["inputmode"]
|
||||
}) {
|
||||
return new Value<AsRequired<string, Required>, WD, CT>(
|
||||
return new Value<AsRequired<string, Required>, WD>(
|
||||
async () => ({
|
||||
type: "text" as const,
|
||||
description: null,
|
||||
@@ -170,10 +169,9 @@ export class Value<Type, WD, ConfigType> {
|
||||
asRequiredParser(string, a),
|
||||
)
|
||||
}
|
||||
static dynamicText<WD, CT>(
|
||||
static dynamicText<WD>(
|
||||
getA: LazyBuild<
|
||||
WD,
|
||||
CT,
|
||||
{
|
||||
name: string
|
||||
description?: string | null
|
||||
@@ -191,7 +189,7 @@ export class Value<Type, WD, ConfigType> {
|
||||
}
|
||||
>,
|
||||
) {
|
||||
return new Value<string | null | undefined, WD, CT>(async (options) => {
|
||||
return new Value<string | null | undefined, WD>(async (options) => {
|
||||
const a = await getA(options)
|
||||
return {
|
||||
type: "text" as const,
|
||||
@@ -208,7 +206,7 @@ export class Value<Type, WD, ConfigType> {
|
||||
}
|
||||
}, string.optional())
|
||||
}
|
||||
static textarea<WD, CT>(a: {
|
||||
static textarea<WD>(a: {
|
||||
name: string
|
||||
description?: string | null
|
||||
warning?: string | null
|
||||
@@ -217,7 +215,7 @@ export class Value<Type, WD, ConfigType> {
|
||||
maxLength?: number | null
|
||||
placeholder?: string | null
|
||||
}) {
|
||||
return new Value<string, WD, CT>(
|
||||
return new Value<string, WD>(
|
||||
async () =>
|
||||
({
|
||||
description: null,
|
||||
@@ -231,10 +229,9 @@ export class Value<Type, WD, ConfigType> {
|
||||
string,
|
||||
)
|
||||
}
|
||||
static dynamicTextarea<WD, CT>(
|
||||
static dynamicTextarea<WD>(
|
||||
getA: LazyBuild<
|
||||
WD,
|
||||
CT,
|
||||
{
|
||||
name: string
|
||||
description?: string | null
|
||||
@@ -246,7 +243,7 @@ export class Value<Type, WD, ConfigType> {
|
||||
}
|
||||
>,
|
||||
) {
|
||||
return new Value<string, WD, CT>(async (options) => {
|
||||
return new Value<string, WD>(async (options) => {
|
||||
const a = await getA(options)
|
||||
return {
|
||||
description: null,
|
||||
@@ -259,7 +256,7 @@ export class Value<Type, WD, ConfigType> {
|
||||
}
|
||||
}, string)
|
||||
}
|
||||
static number<Required extends RequiredDefault<number>, WD, CT>(a: {
|
||||
static number<Required extends RequiredDefault<number>, WD>(a: {
|
||||
name: string
|
||||
description?: string | null
|
||||
warning?: string | null
|
||||
@@ -272,7 +269,7 @@ export class Value<Type, WD, ConfigType> {
|
||||
units?: string | null
|
||||
placeholder?: string | null
|
||||
}) {
|
||||
return new Value<AsRequired<number, Required>, WD, CT>(
|
||||
return new Value<AsRequired<number, Required>, WD>(
|
||||
() => ({
|
||||
type: "number" as const,
|
||||
description: null,
|
||||
@@ -288,10 +285,9 @@ export class Value<Type, WD, ConfigType> {
|
||||
asRequiredParser(number, a),
|
||||
)
|
||||
}
|
||||
static dynamicNumber<WD, CT>(
|
||||
static dynamicNumber<WD>(
|
||||
getA: LazyBuild<
|
||||
WD,
|
||||
CT,
|
||||
{
|
||||
name: string
|
||||
description?: string | null
|
||||
@@ -307,7 +303,7 @@ export class Value<Type, WD, ConfigType> {
|
||||
}
|
||||
>,
|
||||
) {
|
||||
return new Value<number | null | undefined, WD, CT>(async (options) => {
|
||||
return new Value<number | null | undefined, WD>(async (options) => {
|
||||
const a = await getA(options)
|
||||
return {
|
||||
type: "number" as const,
|
||||
@@ -323,13 +319,13 @@ export class Value<Type, WD, ConfigType> {
|
||||
}
|
||||
}, number.optional())
|
||||
}
|
||||
static color<Required extends RequiredDefault<string>, WD, CT>(a: {
|
||||
static color<Required extends RequiredDefault<string>, WD>(a: {
|
||||
name: string
|
||||
description?: string | null
|
||||
warning?: string | null
|
||||
required: Required
|
||||
}) {
|
||||
return new Value<AsRequired<string, Required>, WD, CT>(
|
||||
return new Value<AsRequired<string, Required>, WD>(
|
||||
() => ({
|
||||
type: "color" as const,
|
||||
description: null,
|
||||
@@ -342,10 +338,9 @@ export class Value<Type, WD, ConfigType> {
|
||||
)
|
||||
}
|
||||
|
||||
static dynamicColor<WD, CT>(
|
||||
static dynamicColor<WD>(
|
||||
getA: LazyBuild<
|
||||
WD,
|
||||
CT,
|
||||
{
|
||||
name: string
|
||||
description?: string | null
|
||||
@@ -354,7 +349,7 @@ export class Value<Type, WD, ConfigType> {
|
||||
}
|
||||
>,
|
||||
) {
|
||||
return new Value<string | null | undefined, WD, CT>(async (options) => {
|
||||
return new Value<string | null | undefined, WD>(async (options) => {
|
||||
const a = await getA(options)
|
||||
return {
|
||||
type: "color" as const,
|
||||
@@ -365,7 +360,7 @@ export class Value<Type, WD, ConfigType> {
|
||||
}
|
||||
}, string.optional())
|
||||
}
|
||||
static datetime<Required extends RequiredDefault<string>, WD, CT>(a: {
|
||||
static datetime<Required extends RequiredDefault<string>, WD>(a: {
|
||||
name: string
|
||||
description?: string | null
|
||||
warning?: string | null
|
||||
@@ -376,7 +371,7 @@ export class Value<Type, WD, ConfigType> {
|
||||
max?: string | null
|
||||
step?: string | null
|
||||
}) {
|
||||
return new Value<AsRequired<string, Required>, WD, CT>(
|
||||
return new Value<AsRequired<string, Required>, WD>(
|
||||
() => ({
|
||||
type: "datetime" as const,
|
||||
description: null,
|
||||
@@ -391,10 +386,9 @@ export class Value<Type, WD, ConfigType> {
|
||||
asRequiredParser(string, a),
|
||||
)
|
||||
}
|
||||
static dynamicDatetime<WD, CT>(
|
||||
static dynamicDatetime<WD>(
|
||||
getA: LazyBuild<
|
||||
WD,
|
||||
CT,
|
||||
{
|
||||
name: string
|
||||
description?: string | null
|
||||
@@ -408,7 +402,7 @@ export class Value<Type, WD, ConfigType> {
|
||||
}
|
||||
>,
|
||||
) {
|
||||
return new Value<string | null | undefined, WD, CT>(async (options) => {
|
||||
return new Value<string | null | undefined, WD>(async (options) => {
|
||||
const a = await getA(options)
|
||||
return {
|
||||
type: "datetime" as const,
|
||||
@@ -435,7 +429,7 @@ export class Value<Type, WD, ConfigType> {
|
||||
required: Required
|
||||
values: B
|
||||
}) {
|
||||
return new Value<AsRequired<keyof B, Required>, WD, CT>(
|
||||
return new Value<AsRequired<keyof B, Required>, WD>(
|
||||
() => ({
|
||||
description: null,
|
||||
warning: null,
|
||||
@@ -451,10 +445,9 @@ export class Value<Type, WD, ConfigType> {
|
||||
) as any,
|
||||
)
|
||||
}
|
||||
static dynamicSelect<WD, CT>(
|
||||
static dynamicSelect<WD>(
|
||||
getA: LazyBuild<
|
||||
WD,
|
||||
CT,
|
||||
{
|
||||
name: string
|
||||
description?: string | null
|
||||
@@ -464,7 +457,7 @@ export class Value<Type, WD, ConfigType> {
|
||||
}
|
||||
>,
|
||||
) {
|
||||
return new Value<string | null | undefined, WD, CT>(async (options) => {
|
||||
return new Value<string | null | undefined, WD>(async (options) => {
|
||||
const a = await getA(options)
|
||||
return {
|
||||
description: null,
|
||||
@@ -475,7 +468,7 @@ export class Value<Type, WD, ConfigType> {
|
||||
}
|
||||
}, string.optional())
|
||||
}
|
||||
static multiselect<Values extends Record<string, string>, WD, CT>(a: {
|
||||
static multiselect<Values extends Record<string, string>, WD>(a: {
|
||||
name: string
|
||||
description?: string | null
|
||||
warning?: string | null
|
||||
@@ -484,7 +477,7 @@ export class Value<Type, WD, ConfigType> {
|
||||
minLength?: number | null
|
||||
maxLength?: number | null
|
||||
}) {
|
||||
return new Value<(keyof Values)[], WD, CT>(
|
||||
return new Value<(keyof Values)[], WD>(
|
||||
() => ({
|
||||
type: "multiselect" as const,
|
||||
minLength: null,
|
||||
@@ -498,10 +491,9 @@ export class Value<Type, WD, ConfigType> {
|
||||
),
|
||||
)
|
||||
}
|
||||
static dynamicMultiselect<WD, CT>(
|
||||
static dynamicMultiselect<WD>(
|
||||
getA: LazyBuild<
|
||||
WD,
|
||||
CT,
|
||||
{
|
||||
name: string
|
||||
description?: string | null
|
||||
@@ -513,7 +505,7 @@ export class Value<Type, WD, ConfigType> {
|
||||
}
|
||||
>,
|
||||
) {
|
||||
return new Value<string[], WD, CT>(async (options) => {
|
||||
return new Value<string[], WD>(async (options) => {
|
||||
const a = await getA(options)
|
||||
return {
|
||||
type: "multiselect" as const,
|
||||
@@ -525,15 +517,15 @@ export class Value<Type, WD, ConfigType> {
|
||||
}
|
||||
}, arrayOf(string))
|
||||
}
|
||||
static object<Type extends Record<string, any>, WrapperData, ConfigType>(
|
||||
static object<Type extends Record<string, any>, WrapperData>(
|
||||
a: {
|
||||
name: string
|
||||
description?: string | null
|
||||
warning?: string | null
|
||||
},
|
||||
previousSpec: Config<Type, WrapperData, ConfigType>,
|
||||
previousSpec: Config<Type, WrapperData>,
|
||||
) {
|
||||
return new Value<Type, WrapperData, ConfigType>(async (options) => {
|
||||
return new Value<Type, WrapperData>(async (options) => {
|
||||
const spec = await previousSpec.build(options as any)
|
||||
return {
|
||||
type: "object" as const,
|
||||
@@ -557,9 +549,9 @@ export class Value<Type, WD, ConfigType> {
|
||||
required: Required
|
||||
default?: string | null
|
||||
},
|
||||
aVariants: Variants<Type, WrapperData, ConfigType>,
|
||||
aVariants: Variants<Type, WrapperData>,
|
||||
) {
|
||||
return new Value<AsRequired<Type, Required>, WrapperData, ConfigType>(
|
||||
return new Value<AsRequired<Type, Required>, WrapperData>(
|
||||
async (options) => ({
|
||||
type: "union" as const,
|
||||
description: null,
|
||||
@@ -584,14 +576,13 @@ export class Value<Type, WD, ConfigType> {
|
||||
required: Required
|
||||
default?: string | null
|
||||
},
|
||||
aVariants: Variants<Type, WrapperData, ConfigType>,
|
||||
aVariants: Variants<Type, WrapperData>,
|
||||
getDisabledFn: LazyBuild<
|
||||
WrapperData,
|
||||
ConfigType,
|
||||
Array<Type extends { unionSelectKey: infer B } ? B & string : never>
|
||||
>,
|
||||
) {
|
||||
return new Value<Type | null | undefined, WrapperData, ConfigType>(
|
||||
return new Value<Type | null | undefined, WrapperData>(
|
||||
async (options) => ({
|
||||
type: "union" as const,
|
||||
description: null,
|
||||
@@ -605,11 +596,9 @@ export class Value<Type, WD, ConfigType> {
|
||||
)
|
||||
}
|
||||
|
||||
static list<Type, WrapperData, ConfigType>(
|
||||
a: List<Type, WrapperData, ConfigType>,
|
||||
) {
|
||||
static list<Type, WrapperData>(a: List<Type, WrapperData>) {
|
||||
/// TODO
|
||||
return new Value<Type, WrapperData, ConfigType>(
|
||||
return new Value<Type, WrapperData>(
|
||||
(options) => a.build(options),
|
||||
a.validator,
|
||||
)
|
||||
|
||||
@@ -52,9 +52,9 @@ export const pruning = Value.union(
|
||||
);
|
||||
```
|
||||
*/
|
||||
export class Variants<Type, WD, ConfigType> {
|
||||
export class Variants<Type, WD> {
|
||||
private constructor(
|
||||
public build: LazyBuild<WD, ConfigType, ValueSpecUnion["variants"]>,
|
||||
public build: LazyBuild<WD, ValueSpecUnion["variants"]>,
|
||||
public validator: Parser<unknown, Type>,
|
||||
) {}
|
||||
// A extends {
|
||||
@@ -70,7 +70,7 @@ export class Variants<Type, WD, ConfigType> {
|
||||
>(a: {
|
||||
[K in keyof TypeMap]: {
|
||||
name: string
|
||||
spec: Config<TypeMap[K], WrapperData, ConfigType>
|
||||
spec: Config<TypeMap[K], WrapperData>
|
||||
}
|
||||
}) {
|
||||
type TypeOut = {
|
||||
@@ -89,7 +89,7 @@ export class Variants<Type, WD, ConfigType> {
|
||||
),
|
||||
) as Parser<unknown, TypeOut>
|
||||
|
||||
return new Variants<TypeOut, WrapperData, ConfigType>(async (options) => {
|
||||
return new Variants<TypeOut, WrapperData>(async (options) => {
|
||||
const variants = {} as {
|
||||
[K in keyof TypeMap]: { name: string; spec: InputSpec }
|
||||
}
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
import { GenericManifest } from "../manifest/ManifestTypes"
|
||||
import { SDKManifest } from "../manifest/ManifestTypes"
|
||||
import { Dependency, PackageId } from "../types"
|
||||
|
||||
export type Dependencies<T extends GenericManifest> = {
|
||||
export type Dependencies<T extends SDKManifest> = {
|
||||
exists(id: keyof T["dependencies"]): Dependency
|
||||
running(id: keyof T["dependencies"]): Dependency
|
||||
}
|
||||
|
||||
export const dependenciesSet = <
|
||||
T extends GenericManifest,
|
||||
>(): Dependencies<T> => ({
|
||||
export const dependenciesSet = <T extends SDKManifest>(): Dependencies<T> => ({
|
||||
exists(id: keyof T["dependencies"]) {
|
||||
return {
|
||||
id,
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Config } from "./builder"
|
||||
import { DeepPartial, Dependencies, Effects, ExpectedExports } from "../types"
|
||||
import { InputSpec } from "./configTypes"
|
||||
import { Utils, nullIfEmpty, once, utils } from "../util"
|
||||
import { GenericManifest } from "../manifest/ManifestTypes"
|
||||
import { SDKManifest } from "../manifest/ManifestTypes"
|
||||
import * as D from "./dependencies"
|
||||
import { ExtractConfigType } from "./builder/config"
|
||||
|
||||
@@ -13,8 +13,8 @@ export type DependenciesReceipt = void & {
|
||||
|
||||
export type Save<
|
||||
WD,
|
||||
A extends Record<string, any> | Config<Record<string, any>, any, any>,
|
||||
Manifest extends GenericManifest,
|
||||
A extends Record<string, any> | Config<Record<string, any>, any>,
|
||||
Manifest extends SDKManifest,
|
||||
> = (options: {
|
||||
effects: Effects
|
||||
input: ExtractConfigType<A> & Record<string, any>
|
||||
@@ -23,7 +23,7 @@ export type Save<
|
||||
}) => Promise<DependenciesReceipt>
|
||||
export type Read<
|
||||
WD,
|
||||
A extends Record<string, any> | Config<Record<string, any>, any, any>,
|
||||
A extends Record<string, any> | Config<Record<string, any>, any>,
|
||||
> = (options: {
|
||||
effects: Effects
|
||||
utils: Utils<WD>
|
||||
@@ -37,11 +37,11 @@ export type Read<
|
||||
*/
|
||||
export function setupConfig<
|
||||
WD,
|
||||
ConfigType extends Record<string, any> | Config<any, any, any>,
|
||||
Manifest extends GenericManifest,
|
||||
ConfigType extends Record<string, any> | Config<any, any>,
|
||||
Manifest extends SDKManifest,
|
||||
Type extends Record<string, any> = ExtractConfigType<ConfigType>,
|
||||
>(
|
||||
spec: Config<Type, WD, Type>,
|
||||
spec: Config<Type, WD>,
|
||||
write: Save<WD, Type, Manifest>,
|
||||
read: Read<WD, Type>,
|
||||
) {
|
||||
@@ -68,7 +68,6 @@ export function setupConfig<
|
||||
spec: await spec.build({
|
||||
effects,
|
||||
utils: myUtils,
|
||||
config: configValue as Type,
|
||||
}),
|
||||
config: configValue,
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { setupActions } from "../../actions/setupActions"
|
||||
import { EmVer } from "../../emverLite/mod"
|
||||
import { GenericManifest } from "../../manifest/ManifestTypes"
|
||||
import { SDKManifest } from "../../manifest/ManifestTypes"
|
||||
import { ExpectedExports } from "../../types"
|
||||
import { once } from "../../util/once"
|
||||
import { Migration } from "./Migration"
|
||||
|
||||
export class Migrations {
|
||||
private constructor(
|
||||
readonly manifest: GenericManifest,
|
||||
readonly manifest: SDKManifest,
|
||||
readonly migrations: Array<Migration<any>>,
|
||||
) {}
|
||||
private sortedMigrations = once(() => {
|
||||
@@ -19,7 +19,7 @@ export class Migrations {
|
||||
})
|
||||
private currentVersion = once(() => EmVer.parse(this.manifest.version))
|
||||
static of<Migrations extends Array<Migration<any>>>(
|
||||
manifest: GenericManifest,
|
||||
manifest: SDKManifest,
|
||||
...migrations: EnsureUniqueId<Migrations>
|
||||
) {
|
||||
return new Migrations(manifest, migrations as Array<Migration<any>>)
|
||||
@@ -54,7 +54,7 @@ export class Migrations {
|
||||
}
|
||||
|
||||
export function setupMigrations<Migrations extends Array<Migration<any>>>(
|
||||
manifest: GenericManifest,
|
||||
manifest: SDKManifest,
|
||||
...migrations: EnsureUniqueId<Migrations>
|
||||
) {
|
||||
return Migrations.of(manifest, ...migrations)
|
||||
|
||||
@@ -14,7 +14,7 @@ export interface Container {
|
||||
|
||||
export type ManifestVersion = ValidEmVer
|
||||
|
||||
export interface GenericManifest {
|
||||
export interface SDKManifest {
|
||||
/** The package identifier used by the OS. This must be unique amongst all other known packages */
|
||||
id: string
|
||||
/** A human readable service title */
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { GenericManifest, ManifestVersion } from "./ManifestTypes"
|
||||
import { SDKManifest, ManifestVersion } from "./ManifestTypes"
|
||||
|
||||
export function setupManifest<
|
||||
Id extends string,
|
||||
Version extends ManifestVersion,
|
||||
Dependencies extends Record<string, unknown>,
|
||||
Volumes extends Record<string, unknown>,
|
||||
Manifest extends GenericManifest & {
|
||||
Manifest extends SDKManifest & {
|
||||
dependencies: Dependencies
|
||||
id: Id
|
||||
version: Version
|
||||
|
||||
@@ -303,7 +303,7 @@ describe("values", () => {
|
||||
utils: "utils",
|
||||
} as any
|
||||
test("toggle", async () => {
|
||||
const value = Value.dynamicToggle<{}, {}>(async () => ({
|
||||
const value = Value.dynamicToggle<{}>(async () => ({
|
||||
name: "Testing",
|
||||
description: null,
|
||||
warning: null,
|
||||
@@ -368,7 +368,7 @@ describe("values", () => {
|
||||
})
|
||||
})
|
||||
test("color", async () => {
|
||||
const value = Value.dynamicColor<null, null>(async () => ({
|
||||
const value = Value.dynamicColor<null>(async () => ({
|
||||
name: "Testing",
|
||||
required: false,
|
||||
description: null,
|
||||
@@ -387,11 +387,10 @@ describe("values", () => {
|
||||
})
|
||||
})
|
||||
test("datetime", async () => {
|
||||
const value = Value.dynamicDatetime<{ test: "a" }, { test2: 6 }>(
|
||||
async ({ effects, utils, config }) => {
|
||||
const value = Value.dynamicDatetime<{ test: "a" }>(
|
||||
async ({ effects, utils }) => {
|
||||
;async () => {
|
||||
;(await utils.getOwnWrapperData("/test").once()) satisfies "a"
|
||||
config satisfies { test2: 6 } | null
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user