chore: Use the types from the fronted system

This commit is contained in:
BluJ
2023-02-13 16:58:04 -07:00
parent 2989347a55
commit 1c4a14d631
13 changed files with 252 additions and 273 deletions

195
types.ts
View File

@@ -1,7 +1,10 @@
export * as configTypes from "./types/config-types.ts";
import { ConfigSpec } from "./types/config-types.ts";
// deno-lint-ignore no-namespace
export namespace ExpectedExports {
/** Set configuration is called after we have modified and saved the configuration in the embassy ui. Use this to make a file for the docker to read from for configuration. */
export type setConfig = (effects: Effects, input: Config) => Promise<ResultType<SetResult>>;
export type setConfig = (effects: Effects, input: ConfigSpec) => Promise<ResultType<SetResult>>;
/** Get configuration returns a shape that describes the format that the embassy ui will generate, and later send to the set config */
export type getConfig = (effects: Effects) => Promise<ResultType<ConfigRes>>;
/** These are how we make sure the our dependency configurations are valid and if not how to fix them. */
@@ -33,7 +36,7 @@ export namespace ExpectedExports {
* service starting, and that file would indicate that it would rescan all the data.
*/
export type action = {
[id: string]: (effects: Effects, config?: Config) => Promise<ResultType<ActionResult>>;
[id: string]: (effects: Effects, config?: ConfigSpec) => Promise<ResultType<ActionResult>>;
};
/**
@@ -43,6 +46,12 @@ export namespace ExpectedExports {
export type main = (effects: Effects) => Promise<ResultType<unknown>>;
}
export type ConfigRes = {
/** This should be the previous config, that way during set config we start with the previous */
config?: ConfigSpec;
/** Shape that is describing the form in the ui */
spec: ConfigSpec;
};
/** Used to reach out from the pure js runtime */
export type Effects = {
/** Usable when not sandboxed */
@@ -153,184 +162,6 @@ export type ActionResult = {
copyable: boolean;
qr: boolean;
};
export type ConfigRes = {
/** This should be the previous config, that way during set config we start with the previous */
config?: Config;
/** Shape that is describing the form in the ui */
spec: ConfigSpec;
};
export type Config = {
[propertyName: string]: unknown;
};
export type ConfigSpec = {
/** Given a config value, define what it should render with the following spec */
[configValue: string]: ValueSpecAny;
};
export type WithDefault<T, Default> = T & {
default: Default;
};
export type WithNullableDefault<T, Default> = T & {
default?: Default;
};
export type WithDescription<T> = T & {
description?: null | string;
name: string;
warning?: null | string;
};
export type ListSpec<T> = {
spec: T;
range: string;
};
export type Tag<T extends string, V> = V & {
type: T;
};
export type Subtype<T extends string, V> = V & {
subtype: T;
};
export type Target<T extends string, V> = V & {
target: T;
};
export type UniqueBy =
| {
any: UniqueBy[];
}
| string
| null;
export type WithNullable<T> = T & {
nullable: boolean;
};
export type DefaultString =
| string
| {
/** The chars available for the randome generation */
charset?: null | string;
/** Length that we generate to */
len: number;
};
export type ValueSpecString = (
| never // deno-lint-ignore ban-types
| {}
| {
pattern: string;
"pattern-description": string;
}
) & {
copyable?: null | boolean;
masked?: null | boolean;
placeholder?: null | string;
};
export type ValueSpecNumber = {
/** Something like [3,6] or [0, *) */
range?: null | string;
integral?: null | boolean;
/** Used a description of the units */
units?: null | string;
placeholder?: null | number;
};
export type ValueSpecBoolean = Record<string, unknown>;
export type ValueSpecAny =
| Tag<"boolean", WithDescription<WithDefault<ValueSpecBoolean, boolean>>>
| Tag<"string", WithDescription<WithNullableDefault<WithNullable<ValueSpecString>, DefaultString>>>
| Tag<"number", WithDescription<WithNullableDefault<WithNullable<ValueSpecNumber>, number>>>
| Tag<
"enum",
WithDescription<
WithDefault<
{
values: readonly string[] | string[];
"value-names": {
[key: string]: string;
};
},
string
>
>
>
| Tag<"list", ValueSpecList>
| Tag<"object", WithDescription<WithNullableDefault<ValueSpecObject, Config>>>
| Tag<"union", WithDescription<WithDefault<ValueSpecUnion, string>>>
| Tag<
"pointer",
WithDescription<
| Subtype<
"package",
| Target<
"tor-key",
{
"package-id": string;
interface: string;
}
>
| Target<
"tor-address",
{
"package-id": string;
interface: string;
}
>
| Target<
"lan-address",
{
"package-id": string;
interface: string;
}
>
| Target<
"config",
{
"package-id": string;
selector: string;
multi: boolean;
}
>
>
| Subtype<"system", Record<string, unknown>>
>
>;
export type ValueSpecUnion = {
/** What tag for the specification, for tag unions */
tag: {
id: string;
name?: null | string;
description?: null | string;
"variant-names": {
[key: string]: string;
};
};
/** The possible enum values */
variants: {
[key: string]: ConfigSpec;
};
"display-as"?: null | string;
"unique-by"?: null | UniqueBy;
};
export type ValueSpecObject = {
spec: ConfigSpec;
"display-as"?: null | string;
"unique-by"?: null | UniqueBy;
};
export type ValueSpecList =
| Subtype<"boolean", WithDescription<WithDefault<ListSpec<ValueSpecBoolean>, boolean[]>>>
| Subtype<"string", WithDescription<WithDefault<ListSpec<ValueSpecString>, string[]>>>
| Subtype<"number", WithDescription<WithDefault<ListSpec<ValueSpecNumber>, number[]>>>
| Subtype<"enum", WithDescription<WithDefault<ListSpec<ValueSpecEnum>, string[]>>>
| Subtype<"object", WithDescription<WithNullableDefault<ListSpec<ValueSpecObject>, Record<string, unknown>[]>>>
| Subtype<"union", WithDescription<WithDefault<ListSpec<ValueSpecUnion>, string[]>>>;
export type ValueSpecEnum = {
values: string[];
"value-names": { [key: string]: string };
};
export type SetResult = {
/** These are the unix process signals */
signal:
@@ -410,8 +241,8 @@ export type Dependencies = {
/** Id is the id of the package, should be the same as the manifest */
[id: string]: {
/** Checks are called to make sure that our dependency is in the correct shape. If a known error is returned we know that the dependency needs modification */
check(effects: Effects, input: Config): Promise<ResultType<void | null>>;
check(effects: Effects, input: ConfigSpec): Promise<ResultType<void | null>>;
/** This is called after we know that the dependency package needs a new configuration, this would be a transform for defaults */
autoConfigure(effects: Effects, input: Config): Promise<ResultType<Config>>;
autoConfigure(effects: Effects, input: ConfigSpec): Promise<ResultType<ConfigSpec>>;
};
};