mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-04-01 21:13:11 +00:00
feat: Utils to do bindLan and have ipv4 and ipv6 if need be
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
export type InputSpec = Record<string, ValueSpec>;
|
||||
export type InputSpec = Record<string, ValueSpec>
|
||||
export type ValueType =
|
||||
| "text"
|
||||
| "textarea"
|
||||
@@ -11,8 +11,8 @@ export type ValueType =
|
||||
| "list"
|
||||
| "object"
|
||||
| "file"
|
||||
| "union";
|
||||
export type ValueSpec = ValueSpecOf<ValueType>;
|
||||
| "union"
|
||||
export type ValueSpec = ValueSpecOf<ValueType>
|
||||
/** core spec types. These types provide the metadata for performing validations */
|
||||
export type ValueSpecOf<T extends ValueType> = T extends "text"
|
||||
? ValueSpecText
|
||||
@@ -38,82 +38,82 @@ export type ValueSpecOf<T extends ValueType> = T extends "text"
|
||||
? ValueSpecFile
|
||||
: T extends "union"
|
||||
? ValueSpecUnion
|
||||
: never;
|
||||
: never
|
||||
|
||||
export interface ValueSpecText extends ListValueSpecText, WithStandalone {
|
||||
required: boolean;
|
||||
default: DefaultString | null;
|
||||
required: boolean
|
||||
default: DefaultString | null
|
||||
}
|
||||
export interface ValueSpecTextarea extends WithStandalone {
|
||||
type: "textarea";
|
||||
placeholder: string | null;
|
||||
minLength: number | null;
|
||||
maxLength: number | null;
|
||||
required: boolean;
|
||||
type: "textarea"
|
||||
placeholder: string | null
|
||||
minLength: number | null
|
||||
maxLength: number | null
|
||||
required: boolean
|
||||
}
|
||||
export interface ValueSpecNumber extends ListValueSpecNumber, WithStandalone {
|
||||
required: boolean;
|
||||
default: number | null;
|
||||
required: boolean
|
||||
default: number | null
|
||||
}
|
||||
export interface ValueSpecColor extends WithStandalone {
|
||||
type: "color";
|
||||
required: boolean;
|
||||
default: string | null;
|
||||
type: "color"
|
||||
required: boolean
|
||||
default: string | null
|
||||
}
|
||||
export interface ValueSpecDatetime extends WithStandalone {
|
||||
type: "datetime";
|
||||
required: boolean;
|
||||
inputmode: "date" | "time" | "datetime-local";
|
||||
min: string | null;
|
||||
max: string | null;
|
||||
step: string | null;
|
||||
default: string | null;
|
||||
type: "datetime"
|
||||
required: boolean
|
||||
inputmode: "date" | "time" | "datetime-local"
|
||||
min: string | null
|
||||
max: string | null
|
||||
step: string | null
|
||||
default: string | null
|
||||
}
|
||||
export interface ValueSpecSelect extends SelectBase, WithStandalone {
|
||||
type: "select";
|
||||
required: boolean;
|
||||
default: string | null;
|
||||
type: "select"
|
||||
required: boolean
|
||||
default: string | null
|
||||
}
|
||||
export interface ValueSpecMultiselect extends SelectBase, WithStandalone {
|
||||
type: "multiselect";
|
||||
minLength: number | null;
|
||||
maxLength: number | null;
|
||||
default: string[];
|
||||
type: "multiselect"
|
||||
minLength: number | null
|
||||
maxLength: number | null
|
||||
default: string[]
|
||||
}
|
||||
export interface ValueSpecToggle extends WithStandalone {
|
||||
type: "toggle";
|
||||
default: boolean | null;
|
||||
type: "toggle"
|
||||
default: boolean | null
|
||||
}
|
||||
export interface ValueSpecUnion extends WithStandalone {
|
||||
type: "union";
|
||||
type: "union"
|
||||
variants: Record<
|
||||
string,
|
||||
{
|
||||
name: string;
|
||||
spec: InputSpec;
|
||||
name: string
|
||||
spec: InputSpec
|
||||
}
|
||||
>;
|
||||
required: boolean;
|
||||
default: string | null;
|
||||
>
|
||||
required: boolean
|
||||
default: string | null
|
||||
}
|
||||
export interface ValueSpecFile extends WithStandalone {
|
||||
type: "file";
|
||||
extensions: string[];
|
||||
required: boolean;
|
||||
type: "file"
|
||||
extensions: string[]
|
||||
required: boolean
|
||||
}
|
||||
export interface ValueSpecObject extends WithStandalone {
|
||||
type: "object";
|
||||
spec: InputSpec;
|
||||
type: "object"
|
||||
spec: InputSpec
|
||||
}
|
||||
export interface WithStandalone {
|
||||
name: string;
|
||||
description: string | null;
|
||||
warning: string | null;
|
||||
name: string
|
||||
description: string | null
|
||||
warning: string | null
|
||||
}
|
||||
export interface SelectBase {
|
||||
values: Record<string, string>;
|
||||
values: Record<string, string>
|
||||
}
|
||||
export type ListValueSpecType = "text" | "number" | "object";
|
||||
export type ListValueSpecType = "text" | "number" | "object"
|
||||
/** represents a spec for the values of a list */
|
||||
export type ListValueSpecOf<T extends ListValueSpecType> = T extends "text"
|
||||
? ListValueSpecText
|
||||
@@ -121,15 +121,15 @@ export type ListValueSpecOf<T extends ListValueSpecType> = T extends "text"
|
||||
? ListValueSpecNumber
|
||||
: T extends "object"
|
||||
? ListValueSpecObject
|
||||
: never;
|
||||
: never
|
||||
/** represents a spec for a list */
|
||||
export type ValueSpecList = ValueSpecListOf<ListValueSpecType>;
|
||||
export type ValueSpecList = ValueSpecListOf<ListValueSpecType>
|
||||
export interface ValueSpecListOf<T extends ListValueSpecType>
|
||||
extends WithStandalone {
|
||||
type: "list";
|
||||
spec: ListValueSpecOf<T>;
|
||||
minLength: number | null;
|
||||
maxLength: number | null;
|
||||
type: "list"
|
||||
spec: ListValueSpecOf<T>
|
||||
minLength: number | null
|
||||
maxLength: number | null
|
||||
default:
|
||||
| string[]
|
||||
| number[]
|
||||
@@ -138,64 +138,64 @@ export interface ValueSpecListOf<T extends ListValueSpecType>
|
||||
| readonly string[]
|
||||
| readonly number[]
|
||||
| readonly DefaultString[]
|
||||
| readonly Record<string, unknown>[];
|
||||
| readonly Record<string, unknown>[]
|
||||
}
|
||||
export interface Pattern {
|
||||
regex: string;
|
||||
description: string;
|
||||
regex: string
|
||||
description: string
|
||||
}
|
||||
export interface ListValueSpecText {
|
||||
type: "text";
|
||||
patterns: Pattern[];
|
||||
minLength: number | null;
|
||||
maxLength: number | null;
|
||||
masked: boolean;
|
||||
inputmode: "text" | "email" | "tel" | "url";
|
||||
placeholder: string | null;
|
||||
type: "text"
|
||||
patterns: Pattern[]
|
||||
minLength: number | null
|
||||
maxLength: number | null
|
||||
masked: boolean
|
||||
inputmode: "text" | "email" | "tel" | "url"
|
||||
placeholder: string | null
|
||||
}
|
||||
export interface ListValueSpecNumber {
|
||||
type: "number";
|
||||
min: number | null;
|
||||
max: number | null;
|
||||
integer: boolean;
|
||||
step: string | null;
|
||||
units: string | null;
|
||||
placeholder: string | null;
|
||||
type: "number"
|
||||
min: number | null
|
||||
max: number | null
|
||||
integer: boolean
|
||||
step: string | null
|
||||
units: string | null
|
||||
placeholder: string | null
|
||||
}
|
||||
export interface ListValueSpecObject {
|
||||
type: "object";
|
||||
type: "object"
|
||||
/** this is a mapped type of the config object at this level, replacing the object's values with specs on those values */
|
||||
spec: InputSpec;
|
||||
spec: InputSpec
|
||||
/** indicates whether duplicates can be permitted in the list */
|
||||
uniqueBy: UniqueBy;
|
||||
uniqueBy: UniqueBy
|
||||
/** this should be a handlebars template which can make use of the entire config which corresponds to 'spec' */
|
||||
displayAs: string | null;
|
||||
displayAs: string | null
|
||||
}
|
||||
export type UniqueBy =
|
||||
| null
|
||||
| string
|
||||
| {
|
||||
any: readonly UniqueBy[] | UniqueBy[];
|
||||
any: readonly UniqueBy[] | UniqueBy[]
|
||||
}
|
||||
| {
|
||||
all: readonly UniqueBy[] | UniqueBy[];
|
||||
};
|
||||
all: readonly UniqueBy[] | UniqueBy[]
|
||||
}
|
||||
export type DefaultString =
|
||||
| string
|
||||
| {
|
||||
charset: string;
|
||||
len: number;
|
||||
};
|
||||
charset: string
|
||||
len: number
|
||||
}
|
||||
|
||||
// sometimes the type checker needs just a little bit of help
|
||||
export function isValueSpecListOf<S extends ListValueSpecType>(
|
||||
t: ValueSpecListOf<ListValueSpecType>,
|
||||
s: S,
|
||||
): t is ValueSpecListOf<S> & { spec: ListValueSpecOf<S> } {
|
||||
return t.spec.type === s;
|
||||
return t.spec.type === s
|
||||
}
|
||||
export const unionSelectKey = "unionSelectKey" as const;
|
||||
export type UnionSelectKey = typeof unionSelectKey;
|
||||
export const unionSelectKey = "unionSelectKey" as const
|
||||
export type UnionSelectKey = typeof unionSelectKey
|
||||
|
||||
export const unionValueKey = "unionValueKey" as const;
|
||||
export type UnionValueKey = typeof unionValueKey;
|
||||
export const unionValueKey = "unionValueKey" as const
|
||||
export type UnionValueKey = typeof unionValueKey
|
||||
|
||||
Reference in New Issue
Block a user