mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 04:01:58 +00:00
Refactor/actions (#2733)
* store, properties, manifest * interfaces * init and backups * fix init and backups * file models * more versions * dependencies * config except dynamic types * clean up config * remove disabled from non-dynamic vaues * actions * standardize example code block formats * wip: actions refactor Co-authored-by: Jade <Blu-J@users.noreply.github.com> * commit types * fix types * update types * update action request type * update apis * add description to actionrequest * clean up imports * revert package json * chore: Remove the recursive to the index * chore: Remove the other thing I was testing * flatten action requests * update container runtime with new config paradigm * new actions strategy * seems to be working * misc backend fixes * fix fe bugs * only show breakages if breakages * only show success modal if result * don't panic on failed removal * hide config from actions page * polyfill autoconfig * use metadata strategy for actions instead of prev * misc fixes * chore: split the sdk into 2 libs (#2736) * follow sideload progress (#2718) * follow sideload progress * small bugfix * shareReplay with no refcount false * don't wrap sideload progress in RPCResult * dont present toast --------- Co-authored-by: Aiden McClelland <me@drbonez.dev> * chore: Add the initial of the creation of the two sdk * chore: Add in the baseDist * chore: Add in the baseDist * chore: Get the web and the runtime-container running * chore: Remove the empty file * chore: Fix it so the container-runtime works --------- Co-authored-by: Matt Hill <MattDHill@users.noreply.github.com> Co-authored-by: Aiden McClelland <me@drbonez.dev> * misc fixes * update todos * minor clean up * fix link script * update node version in CI test * fix node version syntax in ci build * wip: fixing callbacks * fix sdk makefile dependencies * add support for const outside of main * update apis * don't panic! * Chore: Capture weird case on rpc, and log that * fix procedure id issue * pass input value for dep auto config * handle disabled and warning for actions * chore: Fix for link not having node_modules * sdk fixes * fix build * fix build * fix build --------- Co-authored-by: Matt Hill <mattnine@protonmail.com> Co-authored-by: Jade <Blu-J@users.noreply.github.com> Co-authored-by: J H <dragondef@gmail.com> Co-authored-by: Jade <2364004+Blu-J@users.noreply.github.com> Co-authored-by: Matt Hill <MattDHill@users.noreply.github.com>
This commit is contained in:
9
sdk/.gitignore
vendored
9
sdk/.gitignore
vendored
@@ -1,5 +1,6 @@
|
||||
.vscode
|
||||
dist/
|
||||
node_modules/
|
||||
lib/coverage
|
||||
lib/test/output.ts
|
||||
baseDist/
|
||||
base/lib/coverage
|
||||
base/lib/node_modules
|
||||
package/lib/coverage
|
||||
package/lib/node_modules
|
||||
@@ -1 +1 @@
|
||||
/lib/exver/exver.ts
|
||||
/base/lib/exver/exver.ts
|
||||
71
sdk/Makefile
71
sdk/Makefile
@@ -1,48 +1,75 @@
|
||||
TS_FILES := $(shell git ls-files lib) lib/test/output.ts
|
||||
PACKAGE_TS_FILES := $(shell git ls-files package/lib) package/lib/test/output.ts
|
||||
BASE_TS_FILES := $(shell git ls-files base/lib) package/lib/test/output.ts
|
||||
version = $(shell git tag --sort=committerdate | tail -1)
|
||||
|
||||
.PHONY: test clean bundle fmt buildOutput check
|
||||
.PHONY: test base/test package/test clean bundle fmt buildOutput check
|
||||
|
||||
all: bundle
|
||||
|
||||
test: $(TS_FILES) lib/test/output.ts
|
||||
npm test
|
||||
package/test: $(PACKAGE_TS_FILES) package/lib/test/output.ts package/node_modules base/node_modules
|
||||
cd package && npm test
|
||||
|
||||
base/test: $(BASE_TS_FILES) base/node_modules
|
||||
cd base && npm test
|
||||
|
||||
test: base/test package/test
|
||||
|
||||
clean:
|
||||
rm -rf base/node_modules
|
||||
rm -rf dist
|
||||
rm -f lib/test/output.ts
|
||||
rm -rf node_modules
|
||||
rm -rf baseDist
|
||||
rm -f package/lib/test/output.ts
|
||||
rm -rf package/node_modules
|
||||
|
||||
lib/test/output.ts: node_modules lib/test/makeOutput.ts scripts/oldSpecToBuilder.ts
|
||||
npm run buildOutput
|
||||
package/lib/test/output.ts: package/node_modules package/lib/test/makeOutput.ts package/scripts/oldSpecToBuilder.ts
|
||||
cd package && npm run buildOutput
|
||||
|
||||
bundle: dist | test fmt
|
||||
bundle: dist baseDist | test fmt
|
||||
touch dist
|
||||
|
||||
lib/exver/exver.ts: node_modules lib/exver/exver.pegjs
|
||||
npx peggy --allowed-start-rules '*' --plugin ./node_modules/ts-pegjs/dist/tspegjs -o lib/exver/exver.ts lib/exver/exver.pegjs
|
||||
base/lib/exver/exver.ts: base/node_modules base/lib/exver/exver.pegjs
|
||||
cd base && npm run peggy
|
||||
|
||||
dist: $(TS_FILES) package.json node_modules README.md LICENSE
|
||||
npx tsc
|
||||
npx tsc --project tsconfig-cjs.json
|
||||
cp package.json dist/package.json
|
||||
cp README.md dist/README.md
|
||||
cp LICENSE dist/LICENSE
|
||||
baseDist: $(PACKAGE_TS_FILES) $(BASE_TS_FILES) base/package.json base/node_modules base/README.md base/LICENSE
|
||||
(cd base && npm run tsc)
|
||||
rsync -ac base/node_modules baseDist/
|
||||
cp base/package.json baseDist/package.json
|
||||
cp base/README.md baseDist/README.md
|
||||
cp base/LICENSE baseDist/LICENSE
|
||||
touch baseDist
|
||||
|
||||
dist: $(PACKAGE_TS_FILES) $(BASE_TS_FILES) package/package.json package/.npmignore package/node_modules package/README.md package/LICENSE
|
||||
(cd package && npm run tsc)
|
||||
rsync -ac package/node_modules dist/
|
||||
cp package/.npmignore dist/.npmignore
|
||||
cp package/package.json dist/package.json
|
||||
cp package/README.md dist/README.md
|
||||
cp package/LICENSE dist/LICENSE
|
||||
touch dist
|
||||
|
||||
full-bundle: bundle
|
||||
|
||||
check:
|
||||
cd package
|
||||
npm run check
|
||||
cd ../base
|
||||
npm run check
|
||||
|
||||
fmt: node_modules
|
||||
fmt: package/node_modules base/node_modules
|
||||
npx prettier . "**/*.ts" --write
|
||||
|
||||
node_modules: package.json
|
||||
npm ci
|
||||
|
||||
publish: bundle package.json README.md LICENSE
|
||||
cd dist && npm publish --access=public
|
||||
package/node_modules: package/package.json
|
||||
cd package && npm ci
|
||||
|
||||
base/node_modules: base/package.json
|
||||
cd base && npm ci
|
||||
|
||||
node_modules: package/node_modules base/node_modules
|
||||
|
||||
publish: bundle package/package.json README.md LICENSE
|
||||
cd dist
|
||||
npm publish --access=public
|
||||
|
||||
link: bundle
|
||||
cd dist && npm link
|
||||
|
||||
5
sdk/base/.gitignore
vendored
Normal file
5
sdk/base/.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
.vscode
|
||||
dist/
|
||||
node_modules/
|
||||
lib/coverage
|
||||
lib/test/output.ts
|
||||
1
sdk/base/README.md
Normal file
1
sdk/base/README.md
Normal file
@@ -0,0 +1 @@
|
||||
# See ../package/README.md
|
||||
191
sdk/base/lib/Effects.ts
Normal file
191
sdk/base/lib/Effects.ts
Normal file
@@ -0,0 +1,191 @@
|
||||
import {
|
||||
ActionId,
|
||||
ActionInput,
|
||||
ActionMetadata,
|
||||
SetMainStatus,
|
||||
DependencyRequirement,
|
||||
CheckDependenciesResult,
|
||||
SetHealth,
|
||||
BindParams,
|
||||
HostId,
|
||||
LanInfo,
|
||||
Host,
|
||||
ExportServiceInterfaceParams,
|
||||
ServiceInterface,
|
||||
ActionRequest,
|
||||
RequestActionParams,
|
||||
} from "./osBindings"
|
||||
import { StorePath } from "./util/PathBuilder"
|
||||
import {
|
||||
PackageId,
|
||||
Dependencies,
|
||||
ServiceInterfaceId,
|
||||
SmtpValue,
|
||||
ActionResult,
|
||||
} from "./types"
|
||||
import { UrlString } from "./util/getServiceInterface"
|
||||
|
||||
/** Used to reach out from the pure js runtime */
|
||||
|
||||
export type Effects = {
|
||||
constRetry: () => void
|
||||
clearCallbacks: (
|
||||
options: { only: number[] } | { except: number[] },
|
||||
) => Promise<void>
|
||||
|
||||
// action
|
||||
action: {
|
||||
/** Define an action that can be invoked by a user or service */
|
||||
export(options: { id: ActionId; metadata: ActionMetadata }): Promise<void>
|
||||
/** Remove all exported actions */
|
||||
clear(options: { except: ActionId[] }): Promise<void>
|
||||
getInput(options: {
|
||||
packageId?: PackageId
|
||||
actionId: ActionId
|
||||
}): Promise<ActionInput | null>
|
||||
run<Input extends Record<string, unknown>>(options: {
|
||||
packageId?: PackageId
|
||||
actionId: ActionId
|
||||
input?: Input
|
||||
}): Promise<ActionResult | null>
|
||||
request<Input extends Record<string, unknown>>(
|
||||
options: RequestActionParams,
|
||||
): Promise<void>
|
||||
clearRequests(
|
||||
options: { only: ActionId[] } | { except: ActionId[] },
|
||||
): Promise<void>
|
||||
}
|
||||
|
||||
// control
|
||||
/** restart this service's main function */
|
||||
restart(): Promise<void>
|
||||
/** stop this service's main function */
|
||||
shutdown(): Promise<void>
|
||||
/** indicate to the host os what runstate the service is in */
|
||||
setMainStatus(options: SetMainStatus): Promise<void>
|
||||
|
||||
// dependency
|
||||
/** Set the dependencies of what the service needs, usually run during the inputSpec action as a best practice */
|
||||
setDependencies(options: { dependencies: Dependencies }): Promise<void>
|
||||
/** Get the list of the dependencies, both the dynamic set by the effect of setDependencies and the end result any required in the manifest */
|
||||
getDependencies(): Promise<DependencyRequirement[]>
|
||||
/** Test whether current dependency requirements are satisfied */
|
||||
checkDependencies(options: {
|
||||
packageIds?: PackageId[]
|
||||
}): Promise<CheckDependenciesResult[]>
|
||||
/** mount a volume of a dependency */
|
||||
mount(options: {
|
||||
location: string
|
||||
target: {
|
||||
packageId: string
|
||||
volumeId: string
|
||||
subpath: string | null
|
||||
readonly: boolean
|
||||
}
|
||||
}): Promise<string>
|
||||
/** Returns a list of the ids of all installed packages */
|
||||
getInstalledPackages(): Promise<string[]>
|
||||
/** grants access to certain paths in the store to dependents */
|
||||
exposeForDependents(options: { paths: string[] }): Promise<void>
|
||||
|
||||
// health
|
||||
/** sets the result of a health check */
|
||||
setHealth(o: SetHealth): Promise<void>
|
||||
|
||||
// subcontainer
|
||||
subcontainer: {
|
||||
/** A low level api used by SubContainer */
|
||||
createFs(options: {
|
||||
imageId: string
|
||||
name: string | null
|
||||
}): Promise<[string, string]>
|
||||
/** A low level api used by SubContainer */
|
||||
destroyFs(options: { guid: string }): Promise<void>
|
||||
}
|
||||
|
||||
// net
|
||||
// bind
|
||||
/** Creates a host connected to the specified port with the provided options */
|
||||
bind(options: BindParams): Promise<void>
|
||||
/** Get the port address for a service */
|
||||
getServicePortForward(options: {
|
||||
packageId?: PackageId
|
||||
hostId: HostId
|
||||
internalPort: number
|
||||
}): Promise<LanInfo>
|
||||
/** Removes all network bindings, called in the setupInputSpec */
|
||||
clearBindings(options: {
|
||||
except: { id: HostId; internalPort: number }[]
|
||||
}): Promise<void>
|
||||
// host
|
||||
/** Returns information about the specified host, if it exists */
|
||||
getHostInfo(options: {
|
||||
packageId?: PackageId
|
||||
hostId: HostId
|
||||
callback?: () => void
|
||||
}): Promise<Host | null>
|
||||
/** Returns the primary url that a user has selected for a host, if it exists */
|
||||
getPrimaryUrl(options: {
|
||||
packageId?: PackageId
|
||||
hostId: HostId
|
||||
callback?: () => void
|
||||
}): Promise<UrlString | null>
|
||||
/** Returns the IP address of the container */
|
||||
getContainerIp(): Promise<string>
|
||||
// interface
|
||||
/** Creates an interface bound to a specific host and port to show to the user */
|
||||
exportServiceInterface(options: ExportServiceInterfaceParams): Promise<void>
|
||||
/** Returns an exported service interface */
|
||||
getServiceInterface(options: {
|
||||
packageId?: PackageId
|
||||
serviceInterfaceId: ServiceInterfaceId
|
||||
callback?: () => void
|
||||
}): Promise<ServiceInterface | null>
|
||||
/** Returns all exported service interfaces for a package */
|
||||
listServiceInterfaces(options: {
|
||||
packageId?: PackageId
|
||||
callback?: () => void
|
||||
}): Promise<Record<ServiceInterfaceId, ServiceInterface>>
|
||||
/** Removes all service interfaces */
|
||||
clearServiceInterfaces(options: {
|
||||
except: ServiceInterfaceId[]
|
||||
}): Promise<void>
|
||||
// ssl
|
||||
/** Returns a PEM encoded fullchain for the hostnames specified */
|
||||
getSslCertificate: (options: {
|
||||
hostnames: string[]
|
||||
algorithm?: "ecdsa" | "ed25519"
|
||||
callback?: () => void
|
||||
}) => Promise<[string, string, string]>
|
||||
/** Returns a PEM encoded private key corresponding to the certificate for the hostnames specified */
|
||||
getSslKey: (options: {
|
||||
hostnames: string[]
|
||||
algorithm?: "ecdsa" | "ed25519"
|
||||
}) => Promise<string>
|
||||
|
||||
// store
|
||||
store: {
|
||||
/** Get a value in a json like data, can be observed and subscribed */
|
||||
get<Store = never, ExtractStore = unknown>(options: {
|
||||
/** If there is no packageId it is assumed the current package */
|
||||
packageId?: string
|
||||
/** The path defaults to root level, using the [JsonPath](https://jsonpath.com/) */
|
||||
path: StorePath
|
||||
callback?: () => void
|
||||
}): Promise<ExtractStore>
|
||||
/** Used to store values that can be accessed and subscribed to */
|
||||
set<Store = never, ExtractStore = unknown>(options: {
|
||||
/** Sets the value for the wrapper at the path, it will override, using the [JsonPath](https://jsonpath.com/) */
|
||||
path: StorePath
|
||||
value: ExtractStore
|
||||
}): Promise<void>
|
||||
}
|
||||
/** sets the version that this service's data has been migrated to */
|
||||
setDataVersion(options: { version: string }): Promise<void>
|
||||
/** returns the version that this service's data has been migrated to */
|
||||
getDataVersion(): Promise<string | null>
|
||||
|
||||
// system
|
||||
/** Returns globally configured SMTP settings, if they exist */
|
||||
getSystemSmtp(options: { callback?: () => void }): Promise<SmtpValue | null>
|
||||
}
|
||||
65
sdk/base/lib/actions/index.ts
Normal file
65
sdk/base/lib/actions/index.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import * as T from "../types"
|
||||
import * as IST from "../actions/input/inputSpecTypes"
|
||||
|
||||
export type RunActionInput<Input> =
|
||||
| Input
|
||||
| ((prev?: { spec: IST.InputSpec; value: Input | null }) => Input)
|
||||
|
||||
export const runAction = async <
|
||||
Input extends Record<string, unknown>,
|
||||
>(options: {
|
||||
effects: T.Effects
|
||||
// packageId?: T.PackageId
|
||||
actionId: T.ActionId
|
||||
input?: RunActionInput<Input>
|
||||
}) => {
|
||||
if (options.input) {
|
||||
if (options.input instanceof Function) {
|
||||
const prev = await options.effects.action.getInput({
|
||||
// packageId: options.packageId,
|
||||
actionId: options.actionId,
|
||||
})
|
||||
const input = options.input(
|
||||
prev
|
||||
? { spec: prev.spec as IST.InputSpec, value: prev.value as Input }
|
||||
: undefined,
|
||||
)
|
||||
return options.effects.action.run({
|
||||
// packageId: options.packageId,
|
||||
actionId: options.actionId,
|
||||
input,
|
||||
})
|
||||
} else {
|
||||
return options.effects.action.run({
|
||||
// packageId: options.packageId,
|
||||
actionId: options.actionId,
|
||||
input: options.input,
|
||||
})
|
||||
}
|
||||
} else {
|
||||
return options.effects.action.run({
|
||||
// packageId: options.packageId,
|
||||
actionId: options.actionId,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// prettier-ignore
|
||||
export type ActionRequest<T extends Omit<T.ActionRequest, "packageId">> =
|
||||
T extends { when: { condition: "input-not-matches" } }
|
||||
? (T extends { input: T.ActionRequestInput } ? T : "input is required for condition 'input-not-matches'")
|
||||
: T
|
||||
|
||||
export const requestAction = <
|
||||
T extends Omit<T.ActionRequest, "packageId">,
|
||||
>(options: {
|
||||
effects: T.Effects
|
||||
request: ActionRequest<T> & { replayId?: string; packageId: T.PackageId }
|
||||
}) => {
|
||||
const request = options.request
|
||||
const req = {
|
||||
...request,
|
||||
replayId: request.replayId || `${request.packageId}:${request.actionId}`,
|
||||
}
|
||||
return options.effects.action.request(req)
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Config } from "./config"
|
||||
import { InputSpec } from "./inputSpec"
|
||||
import { List } from "./list"
|
||||
import { Value } from "./value"
|
||||
import { Variants } from "./variants"
|
||||
|
||||
export { Config, List, Value, Variants }
|
||||
export { InputSpec as InputSpec, List, Value, Variants }
|
||||
@@ -1,7 +1,7 @@
|
||||
import { ValueSpec } from "../configTypes"
|
||||
import { ValueSpec } from "../inputSpecTypes"
|
||||
import { Value } from "./value"
|
||||
import { _ } from "../../util"
|
||||
import { Effects } from "../../types"
|
||||
import { _ } from "../../../util"
|
||||
import { Effects } from "../../../Effects"
|
||||
import { Parser, object } from "ts-matches"
|
||||
|
||||
export type LazyBuildOptions<Store> = {
|
||||
@@ -12,20 +12,20 @@ export type LazyBuild<Store, ExpectedOut> = (
|
||||
) => Promise<ExpectedOut> | ExpectedOut
|
||||
|
||||
// prettier-ignore
|
||||
export type ExtractConfigType<A extends Record<string, any> | Config<Record<string, any>, any> | Config<Record<string, any>, never>> =
|
||||
A extends Config<infer B, any> | Config<infer B, never> ? B :
|
||||
export type ExtractInputSpecType<A extends Record<string, any> | InputSpec<Record<string, any>, any> | InputSpec<Record<string, any>, never>> =
|
||||
A extends InputSpec<infer B, any> | InputSpec<infer B, never> ? B :
|
||||
A
|
||||
|
||||
export type ConfigSpecOf<A extends Record<string, any>, Store = never> = {
|
||||
export type InputSpecOf<A extends Record<string, any>, Store = never> = {
|
||||
[K in keyof A]: Value<A[K], Store>
|
||||
}
|
||||
|
||||
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
|
||||
* InputSpecs are the specs that are used by the os input specification form for this service.
|
||||
* Here is an example of a simple input specification
|
||||
```ts
|
||||
const smallConfig = Config.of({
|
||||
const smallInputSpec = InputSpec.of({
|
||||
test: Value.boolean({
|
||||
name: "Test",
|
||||
description: "This is the description for the test",
|
||||
@@ -35,17 +35,17 @@ export type MaybeLazyValues<A> = LazyBuild<any, A> | A
|
||||
});
|
||||
```
|
||||
|
||||
The idea of a config is that now the form is going to ask for
|
||||
The idea of an inputSpec is that now the form is going to ask for
|
||||
Test: [ ] and the value is going to be checked as a boolean.
|
||||
There are more complex values like selects, lists, and objects. See {@link Value}
|
||||
|
||||
Also, there is the ability to get a validator/parser from this config spec.
|
||||
Also, there is the ability to get a validator/parser from this inputSpec spec.
|
||||
```ts
|
||||
const matchSmallConfig = smallConfig.validator();
|
||||
type SmallConfig = typeof matchSmallConfig._TYPE;
|
||||
const matchSmallInputSpec = smallInputSpec.validator();
|
||||
type SmallInputSpec = typeof matchSmallInputSpec._TYPE;
|
||||
```
|
||||
|
||||
Here is an example of a more complex configuration which came from a configuration for a service
|
||||
Here is an example of a more complex input specification which came from an input specification for a service
|
||||
that works with bitcoin, like c-lightning.
|
||||
```ts
|
||||
|
||||
@@ -73,11 +73,11 @@ export const port = Value.number({
|
||||
units: null,
|
||||
placeholder: null,
|
||||
});
|
||||
export const addNodesSpec = Config.of({ hostname: hostname, port: port });
|
||||
export const addNodesSpec = InputSpec.of({ hostname: hostname, port: port });
|
||||
|
||||
```
|
||||
*/
|
||||
export class Config<Type extends Record<string, any>, Store = never> {
|
||||
export class InputSpec<Type extends Record<string, any>, Store = never> {
|
||||
private constructor(
|
||||
private readonly spec: {
|
||||
[K in keyof Type]: Value<Type[K], Store> | Value<Type[K], never>
|
||||
@@ -105,7 +105,7 @@ export class Config<Type extends Record<string, any>, Store = never> {
|
||||
validatorObj[key] = spec[key].validator
|
||||
}
|
||||
const validator = object(validatorObj)
|
||||
return new Config<
|
||||
return new InputSpec<
|
||||
{
|
||||
[K in keyof Spec]: Spec[K] extends
|
||||
| Value<infer T, Store>
|
||||
@@ -119,19 +119,19 @@ export class Config<Type extends Record<string, any>, Store = never> {
|
||||
|
||||
/**
|
||||
* Use this during the times that the input needs a more specific type.
|
||||
* Used in types that the value/ variant/ list/ config is constructed somewhere else.
|
||||
* Used in types that the value/ variant/ list/ inputSpec is constructed somewhere else.
|
||||
```ts
|
||||
const a = Config.text({
|
||||
const a = InputSpec.text({
|
||||
name: "a",
|
||||
required: false,
|
||||
})
|
||||
|
||||
return Config.of<Store>()({
|
||||
return InputSpec.of<Store>()({
|
||||
myValue: a.withStore(),
|
||||
})
|
||||
```
|
||||
*/
|
||||
withStore<NewStore extends Store extends never ? any : Store>() {
|
||||
return this as any as Config<Type, NewStore>
|
||||
return this as any as InputSpec<Type, NewStore>
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Config, LazyBuild } from "./config"
|
||||
import { InputSpec, LazyBuild } from "./inputSpec"
|
||||
import {
|
||||
ListValueSpecText,
|
||||
Pattern,
|
||||
@@ -6,45 +6,55 @@ import {
|
||||
UniqueBy,
|
||||
ValueSpecList,
|
||||
ValueSpecListOf,
|
||||
} from "../configTypes"
|
||||
import { Parser, arrayOf, number, string } from "ts-matches"
|
||||
/**
|
||||
* Used as a subtype of Value.list
|
||||
```ts
|
||||
export const authorizationList = List.string({
|
||||
"name": "Authorization",
|
||||
"range": "[0,*)",
|
||||
"default": [],
|
||||
"description": "Username and hashed password for JSON-RPC connections. RPC clients connect using the usual http basic authentication.",
|
||||
"warning": null
|
||||
}, {"masked":false,"placeholder":null,"pattern":"^[a-zA-Z0-9_-]+:([0-9a-fA-F]{2})+\\$([0-9a-fA-F]{2})+$","patternDescription":"Each item must be of the form \"<USERNAME>:<SALT>$<HASH>\"."});
|
||||
export const auth = Value.list(authorizationList);
|
||||
```
|
||||
*/
|
||||
} from "../inputSpecTypes"
|
||||
import { Parser, arrayOf, string } from "ts-matches"
|
||||
|
||||
export class List<Type, Store> {
|
||||
private constructor(
|
||||
public build: LazyBuild<Store, ValueSpecList>,
|
||||
public validator: Parser<unknown, Type>,
|
||||
) {}
|
||||
|
||||
static text(
|
||||
a: {
|
||||
name: string
|
||||
description?: string | null
|
||||
warning?: string | null
|
||||
/** Default = [] */
|
||||
default?: string[]
|
||||
minLength?: number | null
|
||||
maxLength?: number | null
|
||||
},
|
||||
aSpec: {
|
||||
/** Default = false */
|
||||
/**
|
||||
* @description Mask (aka camouflage) text input with dots: ● ● ●
|
||||
* @default false
|
||||
*/
|
||||
masked?: boolean
|
||||
placeholder?: string | null
|
||||
minLength?: number | null
|
||||
maxLength?: number | null
|
||||
patterns: Pattern[]
|
||||
/** Default = "text" */
|
||||
/**
|
||||
* @description A list of regular expressions to which the text must conform to pass validation. A human readable description is provided in case the validation fails.
|
||||
* @default []
|
||||
* @example
|
||||
* ```
|
||||
[
|
||||
{
|
||||
regex: "[a-z]",
|
||||
description: "May only contain lower case letters from the English alphabet."
|
||||
}
|
||||
]
|
||||
* ```
|
||||
*/
|
||||
patterns?: Pattern[]
|
||||
/**
|
||||
* @description Informs the browser how to behave and which keyboard to display on mobile
|
||||
* @default "text"
|
||||
*/
|
||||
inputmode?: ListValueSpecText["inputmode"]
|
||||
/**
|
||||
* @description Displays a button that will generate a random string according to the provided charset and len attributes.
|
||||
*/
|
||||
generate?: null | RandomString
|
||||
},
|
||||
) {
|
||||
@@ -57,6 +67,7 @@ export class List<Type, Store> {
|
||||
masked: false,
|
||||
inputmode: "text" as const,
|
||||
generate: null,
|
||||
patterns: aSpec.patterns || [],
|
||||
...aSpec,
|
||||
}
|
||||
const built: ValueSpecListOf<"text"> = {
|
||||
@@ -73,6 +84,7 @@ export class List<Type, Store> {
|
||||
return built
|
||||
}, arrayOf(string))
|
||||
}
|
||||
|
||||
static dynamicText<Store = never>(
|
||||
getA: LazyBuild<
|
||||
Store,
|
||||
@@ -80,20 +92,17 @@ export class List<Type, Store> {
|
||||
name: string
|
||||
description?: string | null
|
||||
warning?: string | null
|
||||
/** Default = [] */
|
||||
default?: string[]
|
||||
minLength?: number | null
|
||||
maxLength?: number | null
|
||||
disabled?: false | string
|
||||
generate?: null | RandomString
|
||||
spec: {
|
||||
/** Default = false */
|
||||
masked?: boolean
|
||||
placeholder?: string | null
|
||||
minLength?: number | null
|
||||
maxLength?: number | null
|
||||
patterns: Pattern[]
|
||||
/** Default = "text" */
|
||||
patterns?: Pattern[]
|
||||
inputmode?: ListValueSpecText["inputmode"]
|
||||
}
|
||||
}
|
||||
@@ -109,6 +118,7 @@ export class List<Type, Store> {
|
||||
masked: false,
|
||||
inputmode: "text" as const,
|
||||
generate: null,
|
||||
patterns: aSpec.patterns || [],
|
||||
...aSpec,
|
||||
}
|
||||
const built: ValueSpecListOf<"text"> = {
|
||||
@@ -125,18 +135,18 @@ export class List<Type, Store> {
|
||||
return built
|
||||
}, arrayOf(string))
|
||||
}
|
||||
|
||||
static obj<Type extends Record<string, any>, Store>(
|
||||
a: {
|
||||
name: string
|
||||
description?: string | null
|
||||
warning?: string | null
|
||||
/** Default [] */
|
||||
default?: []
|
||||
minLength?: number | null
|
||||
maxLength?: number | null
|
||||
},
|
||||
aSpec: {
|
||||
spec: Config<Type, Store>
|
||||
spec: InputSpec<Type, Store>
|
||||
displayAs?: null | string
|
||||
uniqueBy?: null | UniqueBy
|
||||
},
|
||||
@@ -170,14 +180,14 @@ export class List<Type, Store> {
|
||||
|
||||
/**
|
||||
* Use this during the times that the input needs a more specific type.
|
||||
* Used in types that the value/ variant/ list/ config is constructed somewhere else.
|
||||
* Used in types that the value/ variant/ list/ inputSpec is constructed somewhere else.
|
||||
```ts
|
||||
const a = Config.text({
|
||||
const a = InputSpec.text({
|
||||
name: "a",
|
||||
required: false,
|
||||
})
|
||||
|
||||
return Config.of<Store>()({
|
||||
return InputSpec.of<Store>()({
|
||||
myValue: a.withStore(),
|
||||
})
|
||||
```
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Config, LazyBuild, LazyBuildOptions } from "./config"
|
||||
import { InputSpec, LazyBuild } from "./inputSpec"
|
||||
import { List } from "./list"
|
||||
import { Variants } from "./variants"
|
||||
import {
|
||||
@@ -7,13 +7,15 @@ import {
|
||||
RandomString,
|
||||
ValueSpec,
|
||||
ValueSpecDatetime,
|
||||
ValueSpecHidden,
|
||||
ValueSpecText,
|
||||
ValueSpecTextarea,
|
||||
} from "../configTypes"
|
||||
import { DefaultString } from "../configTypes"
|
||||
import { _ } from "../../util"
|
||||
} from "../inputSpecTypes"
|
||||
import { DefaultString } from "../inputSpecTypes"
|
||||
import { _, once } from "../../../util"
|
||||
import {
|
||||
Parser,
|
||||
any,
|
||||
anyOf,
|
||||
arrayOf,
|
||||
boolean,
|
||||
@@ -24,7 +26,6 @@ import {
|
||||
string,
|
||||
unknown,
|
||||
} from "ts-matches"
|
||||
import { once } from "../../util/once"
|
||||
|
||||
export type RequiredDefault<A> =
|
||||
| false
|
||||
@@ -54,11 +55,6 @@ type AsRequired<Type, MaybeRequiredType> = MaybeRequiredType extends
|
||||
? Type
|
||||
: Type | null | undefined
|
||||
|
||||
type InputAsRequired<A, Type> = A extends
|
||||
| { required: { default: any } | never }
|
||||
| never
|
||||
? Type
|
||||
: Type | null | undefined
|
||||
const testForAsRequiredParser = once(
|
||||
() => object({ required: object({ default: unknown }) }).test,
|
||||
)
|
||||
@@ -73,28 +69,6 @@ function asRequiredParser<
|
||||
return parser.optional() as any
|
||||
}
|
||||
|
||||
/**
|
||||
* A value is going to be part of the form in the FE of the OS.
|
||||
* Something like a boolean, a string, a number, etc.
|
||||
* in the fe it will ask for the name of value, and use the rest of the value to determine how to render it.
|
||||
* While writing with a value, you will start with `Value.` then let the IDE suggest the rest.
|
||||
* for things like string, the options are going to be in {}.
|
||||
* Keep an eye out for another config builder types as params.
|
||||
* Note, usually this is going to be used in a `Config` {@link Config} builder.
|
||||
```ts
|
||||
const username = Value.string({
|
||||
name: "Username",
|
||||
default: "bitcoin",
|
||||
description: "The username for connecting to Bitcoin over RPC.",
|
||||
warning: null,
|
||||
required: true,
|
||||
masked: true,
|
||||
placeholder: null,
|
||||
pattern: "^[a-zA-Z0-9_]+$",
|
||||
patternDescription: "Must be alphanumeric (can contain underscore).",
|
||||
});
|
||||
```
|
||||
*/
|
||||
export class Value<Type, Store> {
|
||||
protected constructor(
|
||||
public build: LazyBuild<Store, ValueSpec>,
|
||||
@@ -103,10 +77,13 @@ export class Value<Type, Store> {
|
||||
static toggle(a: {
|
||||
name: string
|
||||
description?: string | null
|
||||
/** Presents a warning prompt before permitting the value to change. */
|
||||
warning?: string | null
|
||||
default: boolean
|
||||
/** Immutable means it can only be configed at the first config then never again
|
||||
Default is false */
|
||||
/**
|
||||
* @description Once set, the value can never be changed.
|
||||
* @default false
|
||||
*/
|
||||
immutable?: boolean
|
||||
}) {
|
||||
return new Value<boolean, never>(
|
||||
@@ -148,22 +125,53 @@ export class Value<Type, Store> {
|
||||
static text<Required extends RequiredDefault<DefaultString>>(a: {
|
||||
name: string
|
||||
description?: string | null
|
||||
/** Presents a warning prompt before permitting the value to change. */
|
||||
warning?: string | null
|
||||
/**
|
||||
* @description Determines if the field is required. If so, optionally provide a default value.
|
||||
* @type { false | { default: string | RandomString | null } }
|
||||
* @example required: false
|
||||
* @example required: { default: null }
|
||||
* @example required: { default: 'World' }
|
||||
* @example required: { default: { charset: 'abcdefg', len: 16 } }
|
||||
*/
|
||||
required: Required
|
||||
|
||||
/** Default = false */
|
||||
/**
|
||||
* @description Mask (aka camouflage) text input with dots: ● ● ●
|
||||
* @default false
|
||||
*/
|
||||
masked?: boolean
|
||||
placeholder?: string | null
|
||||
minLength?: number | null
|
||||
maxLength?: number | null
|
||||
/**
|
||||
* @description A list of regular expressions to which the text must conform to pass validation. A human readable description is provided in case the validation fails.
|
||||
* @default []
|
||||
* @example
|
||||
* ```
|
||||
[
|
||||
{
|
||||
regex: "[a-z]",
|
||||
description: "May only contain lower case letters from the English alphabet."
|
||||
}
|
||||
]
|
||||
* ```
|
||||
*/
|
||||
patterns?: Pattern[]
|
||||
/** Default = 'text' */
|
||||
/**
|
||||
* @description Informs the browser how to behave and which keyboard to display on mobile
|
||||
* @default "text"
|
||||
*/
|
||||
inputmode?: ValueSpecText["inputmode"]
|
||||
/** Immutable means it can only be configured at the first config then never again
|
||||
* Default is false
|
||||
/**
|
||||
* @description Once set, the value can never be changed.
|
||||
* @default false
|
||||
*/
|
||||
immutable?: boolean
|
||||
generate?: null | RandomString
|
||||
/**
|
||||
* @description Displays a button that will generate a random string according to the provided charset and len attributes.
|
||||
*/
|
||||
generate?: RandomString | null
|
||||
}) {
|
||||
return new Value<AsRequired<string, Required>, never>(
|
||||
async () => ({
|
||||
@@ -193,19 +201,13 @@ export class Value<Type, Store> {
|
||||
description?: string | null
|
||||
warning?: string | null
|
||||
required: RequiredDefault<DefaultString>
|
||||
|
||||
/** Default = false */
|
||||
masked?: boolean
|
||||
placeholder?: string | null
|
||||
minLength?: number | null
|
||||
maxLength?: number | null
|
||||
patterns?: Pattern[]
|
||||
/** Default = 'text' */
|
||||
inputmode?: ValueSpecText["inputmode"]
|
||||
disabled?: string | false
|
||||
/** Immutable means it can only be configured at the first config then never again
|
||||
* Default is false
|
||||
*/
|
||||
generate?: null | RandomString
|
||||
}
|
||||
>,
|
||||
@@ -233,13 +235,19 @@ export class Value<Type, Store> {
|
||||
static textarea(a: {
|
||||
name: string
|
||||
description?: string | null
|
||||
/** Presents a warning prompt before permitting the value to change. */
|
||||
warning?: string | null
|
||||
/**
|
||||
* @description Unlike other "required" fields, for textarea this is a simple boolean.
|
||||
*/
|
||||
required: boolean
|
||||
minLength?: number | null
|
||||
maxLength?: number | null
|
||||
placeholder?: string | null
|
||||
/** Immutable means it can only be configed at the first config then never again
|
||||
Default is false */
|
||||
/**
|
||||
* @description Once set, the value can never be changed.
|
||||
* @default false
|
||||
*/
|
||||
immutable?: boolean
|
||||
}) {
|
||||
return new Value<string, never>(async () => {
|
||||
@@ -290,17 +298,36 @@ export class Value<Type, Store> {
|
||||
static number<Required extends RequiredDefault<number>>(a: {
|
||||
name: string
|
||||
description?: string | null
|
||||
/** Presents a warning prompt before permitting the value to change. */
|
||||
warning?: string | null
|
||||
/**
|
||||
* @description Determines if the field is required. If so, optionally provide a default value.
|
||||
* @type { false | { default: number | null } }
|
||||
* @example required: false
|
||||
* @example required: { default: null }
|
||||
* @example required: { default: 7 }
|
||||
*/
|
||||
required: Required
|
||||
min?: number | null
|
||||
max?: number | null
|
||||
/** Default = '1' */
|
||||
/**
|
||||
* @description How much does the number increase/decrease when using the arrows provided by the browser.
|
||||
* @default 1
|
||||
*/
|
||||
step?: number | null
|
||||
/**
|
||||
* @description Requires the number to be an integer.
|
||||
*/
|
||||
integer: boolean
|
||||
/**
|
||||
* @description Optionally display units to the right of the input box.
|
||||
*/
|
||||
units?: string | null
|
||||
placeholder?: string | null
|
||||
/** Immutable means it can only be configed at the first config then never again
|
||||
Default is false */
|
||||
/**
|
||||
* @description Once set, the value can never be changed.
|
||||
* @default false
|
||||
*/
|
||||
immutable?: boolean
|
||||
}) {
|
||||
return new Value<AsRequired<number, Required>, never>(
|
||||
@@ -331,7 +358,6 @@ export class Value<Type, Store> {
|
||||
required: RequiredDefault<number>
|
||||
min?: number | null
|
||||
max?: number | null
|
||||
/** Default = '1' */
|
||||
step?: number | null
|
||||
integer: boolean
|
||||
units?: string | null
|
||||
@@ -361,10 +387,20 @@ export class Value<Type, Store> {
|
||||
static color<Required extends RequiredDefault<string>>(a: {
|
||||
name: string
|
||||
description?: string | null
|
||||
/** Presents a warning prompt before permitting the value to change. */
|
||||
warning?: string | null
|
||||
/**
|
||||
* @description Determines if the field is required. If so, optionally provide a default value.
|
||||
* @type { false | { default: string | null } }
|
||||
* @example required: false
|
||||
* @example required: { default: null }
|
||||
* @example required: { default: 'ffffff' }
|
||||
*/
|
||||
required: Required
|
||||
/** Immutable means it can only be configed at the first config then never again
|
||||
Default is false */
|
||||
/**
|
||||
* @description Once set, the value can never be changed.
|
||||
* @default false
|
||||
*/
|
||||
immutable?: boolean
|
||||
}) {
|
||||
return new Value<AsRequired<string, Required>, never>(
|
||||
@@ -410,14 +446,27 @@ export class Value<Type, Store> {
|
||||
static datetime<Required extends RequiredDefault<string>>(a: {
|
||||
name: string
|
||||
description?: string | null
|
||||
/** Presents a warning prompt before permitting the value to change. */
|
||||
warning?: string | null
|
||||
/**
|
||||
* @description Determines if the field is required. If so, optionally provide a default value.
|
||||
* @type { false | { default: string | null } }
|
||||
* @example required: false
|
||||
* @example required: { default: null }
|
||||
* @example required: { default: '1985-12-16 18:00:00.000' }
|
||||
*/
|
||||
required: Required
|
||||
/** Default = 'datetime-local' */
|
||||
/**
|
||||
* @description Informs the browser how to behave and which date/time component to display.
|
||||
* @default "datetime-local"
|
||||
*/
|
||||
inputmode?: ValueSpecDatetime["inputmode"]
|
||||
min?: string | null
|
||||
max?: string | null
|
||||
/** Immutable means it can only be configed at the first config then never again
|
||||
Default is false */
|
||||
/**
|
||||
* @description Once set, the value can never be changed.
|
||||
* @default false
|
||||
*/
|
||||
immutable?: boolean
|
||||
}) {
|
||||
return new Value<AsRequired<string, Required>, never>(
|
||||
@@ -445,7 +494,6 @@ export class Value<Type, Store> {
|
||||
description?: string | null
|
||||
warning?: string | null
|
||||
required: RequiredDefault<string>
|
||||
/** Default = 'datetime-local' */
|
||||
inputmode?: ValueSpecDatetime["inputmode"]
|
||||
min?: string | null
|
||||
max?: string | null
|
||||
@@ -471,24 +519,39 @@ export class Value<Type, Store> {
|
||||
}
|
||||
static select<
|
||||
Required extends RequiredDefault<string>,
|
||||
B extends Record<string, string>,
|
||||
Values extends Record<string, string>,
|
||||
>(a: {
|
||||
name: string
|
||||
description?: string | null
|
||||
/** Presents a warning prompt before permitting the value to change. */
|
||||
warning?: string | null
|
||||
required: Required
|
||||
values: B
|
||||
/**
|
||||
* Disabled: false means that there is nothing disabled, good to modify
|
||||
* string means that this is the message displayed and the whole thing is disabled
|
||||
* string[] means that the options are disabled
|
||||
* @description Determines if the field is required. If so, optionally provide a default value from the list of values.
|
||||
* @type { false | { default: string | null } }
|
||||
* @example required: false
|
||||
* @example required: { default: null }
|
||||
* @example required: { default: 'radio1' }
|
||||
*/
|
||||
required: Required
|
||||
/**
|
||||
* @description A mapping of unique radio options to their human readable display format.
|
||||
* @example
|
||||
* ```
|
||||
{
|
||||
radio1: "Radio 1"
|
||||
radio2: "Radio 2"
|
||||
radio3: "Radio 3"
|
||||
}
|
||||
* ```
|
||||
*/
|
||||
values: Values
|
||||
/**
|
||||
* @description Once set, the value can never be changed.
|
||||
* @default false
|
||||
*/
|
||||
disabled?: false | string | (string & keyof B)[]
|
||||
/** Immutable means it can only be configed at the first config then never again
|
||||
Default is false */
|
||||
immutable?: boolean
|
||||
}) {
|
||||
return new Value<AsRequired<keyof B, Required>, never>(
|
||||
return new Value<AsRequired<keyof Values, Required>, never>(
|
||||
() => ({
|
||||
description: null,
|
||||
warning: null,
|
||||
@@ -500,7 +563,9 @@ export class Value<Type, Store> {
|
||||
}),
|
||||
asRequiredParser(
|
||||
anyOf(
|
||||
...Object.keys(a.values).map((x: keyof B & string) => literal(x)),
|
||||
...Object.keys(a.values).map((x: keyof Values & string) =>
|
||||
literal(x),
|
||||
),
|
||||
),
|
||||
a,
|
||||
) as any,
|
||||
@@ -515,11 +580,6 @@ export class Value<Type, Store> {
|
||||
warning?: string | null
|
||||
required: RequiredDefault<string>
|
||||
values: Record<string, string>
|
||||
/**
|
||||
* Disabled: false means that there is nothing disabled, good to modify
|
||||
* string means that this is the message displayed and the whole thing is disabled
|
||||
* string[] means that the options are disabled
|
||||
*/
|
||||
disabled?: false | string | string[]
|
||||
}
|
||||
>,
|
||||
@@ -540,20 +600,31 @@ export class Value<Type, Store> {
|
||||
static multiselect<Values extends Record<string, string>>(a: {
|
||||
name: string
|
||||
description?: string | null
|
||||
/** Presents a warning prompt before permitting the value to change. */
|
||||
warning?: string | null
|
||||
/**
|
||||
* @description A simple list of which options should be checked by default.
|
||||
*/
|
||||
default: string[]
|
||||
/**
|
||||
* @description A mapping of checkbox options to their human readable display format.
|
||||
* @example
|
||||
* ```
|
||||
{
|
||||
option1: "Option 1"
|
||||
option2: "Option 2"
|
||||
option3: "Option 3"
|
||||
}
|
||||
* ```
|
||||
*/
|
||||
values: Values
|
||||
minLength?: number | null
|
||||
maxLength?: number | null
|
||||
/** Immutable means it can only be configed at the first config then never again
|
||||
Default is false */
|
||||
immutable?: boolean
|
||||
/**
|
||||
* Disabled: false means that there is nothing disabled, good to modify
|
||||
* string means that this is the message displayed and the whole thing is disabled
|
||||
* string[] means that the options are disabled
|
||||
* @description Once set, the value can never be changed.
|
||||
* @default false
|
||||
*/
|
||||
disabled?: false | string | (string & keyof Values)[]
|
||||
immutable?: boolean
|
||||
}) {
|
||||
return new Value<(keyof Values)[], never>(
|
||||
() => ({
|
||||
@@ -582,11 +653,6 @@ export class Value<Type, Store> {
|
||||
values: Record<string, string>
|
||||
minLength?: number | null
|
||||
maxLength?: number | null
|
||||
/**
|
||||
* Disabled: false means that there is nothing disabled, good to modify
|
||||
* string means that this is the message displayed and the whole thing is disabled
|
||||
* string[] means that the options are disabled
|
||||
*/
|
||||
disabled?: false | string | string[]
|
||||
}
|
||||
>,
|
||||
@@ -609,9 +675,8 @@ export class Value<Type, Store> {
|
||||
a: {
|
||||
name: string
|
||||
description?: string | null
|
||||
warning?: string | null
|
||||
},
|
||||
spec: Config<Type, Store>,
|
||||
spec: InputSpec<Type, Store>,
|
||||
) {
|
||||
return new Value<Type, Store>(async (options) => {
|
||||
const built = await spec.build(options as any)
|
||||
@@ -624,12 +689,11 @@ export class Value<Type, Store> {
|
||||
}
|
||||
}, spec.validator)
|
||||
}
|
||||
static file<Required extends RequiredDefault<string>, Store>(a: {
|
||||
static file<Store>(a: {
|
||||
name: string
|
||||
description?: string | null
|
||||
warning?: string | null
|
||||
extensions: string[]
|
||||
required: Required
|
||||
required: boolean
|
||||
}) {
|
||||
const buildValue = {
|
||||
type: "file" as const,
|
||||
@@ -637,11 +701,9 @@ export class Value<Type, Store> {
|
||||
warning: null,
|
||||
...a,
|
||||
}
|
||||
return new Value<AsRequired<FilePath, Required>, Store>(
|
||||
return new Value<FilePath, Store>(
|
||||
() => ({
|
||||
...buildValue,
|
||||
|
||||
...requiredLikeToAbove(a.required),
|
||||
}),
|
||||
asRequiredParser(object({ filePath: string }), a),
|
||||
)
|
||||
@@ -672,17 +734,21 @@ export class Value<Type, Store> {
|
||||
a: {
|
||||
name: string
|
||||
description?: string | null
|
||||
/** Presents a warning prompt before permitting the value to change. */
|
||||
warning?: string | null
|
||||
required: Required
|
||||
/** Immutable means it can only be configed at the first config then never again
|
||||
Default is false */
|
||||
immutable?: boolean
|
||||
/**
|
||||
* Disabled: false means that there is nothing disabled, good to modify
|
||||
* string means that this is the message displayed and the whole thing is disabled
|
||||
* string[] means that the options are disabled
|
||||
* @description Determines if the field is required. If so, optionally provide a default value from the list of variants.
|
||||
* @type { false | { default: string | null } }
|
||||
* @example required: false
|
||||
* @example required: { default: null }
|
||||
* @example required: { default: 'variant1' }
|
||||
*/
|
||||
disabled?: false | string | string[]
|
||||
required: Required
|
||||
/**
|
||||
* @description Once set, the value can never be changed.
|
||||
* @default false
|
||||
*/
|
||||
immutable?: boolean
|
||||
},
|
||||
aVariants: Variants<Type, Store>,
|
||||
) {
|
||||
@@ -736,11 +802,11 @@ export class Value<Type, Store> {
|
||||
getA: LazyBuild<
|
||||
Store,
|
||||
{
|
||||
disabled: string[] | false | string
|
||||
name: string
|
||||
description?: string | null
|
||||
warning?: string | null
|
||||
required: Required
|
||||
disabled: string[] | false | string
|
||||
}
|
||||
>,
|
||||
aVariants: Variants<Type, Store> | Variants<Type, never>,
|
||||
@@ -763,16 +829,25 @@ export class Value<Type, Store> {
|
||||
return new Value<Type, Store>((options) => a.build(options), a.validator)
|
||||
}
|
||||
|
||||
static hidden<T>(parser: Parser<unknown, T> = any) {
|
||||
return new Value<T, never>(async () => {
|
||||
const built: ValueSpecHidden = {
|
||||
type: "hidden" as const,
|
||||
}
|
||||
return built
|
||||
}, parser)
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this during the times that the input needs a more specific type.
|
||||
* Used in types that the value/ variant/ list/ config is constructed somewhere else.
|
||||
* Used in types that the value/ variant/ list/ inputSpec is constructed somewhere else.
|
||||
```ts
|
||||
const a = Config.text({
|
||||
const a = InputSpec.text({
|
||||
name: "a",
|
||||
required: false,
|
||||
})
|
||||
|
||||
return Config.of<Store>()({
|
||||
return InputSpec.of<Store>()({
|
||||
myValue: a.withStore(),
|
||||
})
|
||||
```
|
||||
@@ -1,5 +1,5 @@
|
||||
import { InputSpec, ValueSpecUnion } from "../configTypes"
|
||||
import { LazyBuild, Config } from "./config"
|
||||
import { ValueSpec, ValueSpecUnion } from "../inputSpecTypes"
|
||||
import { LazyBuild, InputSpec } from "./inputSpec"
|
||||
import { Parser, anyOf, literals, object } from "ts-matches"
|
||||
|
||||
/**
|
||||
@@ -8,7 +8,7 @@ import { Parser, anyOf, literals, object } from "ts-matches"
|
||||
* key to the tag.id in the Value.select
|
||||
```ts
|
||||
|
||||
export const disabled = Config.of({});
|
||||
export const disabled = InputSpec.of({});
|
||||
export const size = Value.number({
|
||||
name: "Max Chain Size",
|
||||
default: 550,
|
||||
@@ -20,7 +20,7 @@ export const size = Value.number({
|
||||
units: "MiB",
|
||||
placeholder: null,
|
||||
});
|
||||
export const automatic = Config.of({ size: size });
|
||||
export const automatic = InputSpec.of({ size: size });
|
||||
export const size1 = Value.number({
|
||||
name: "Failsafe Chain Size",
|
||||
default: 65536,
|
||||
@@ -32,7 +32,7 @@ export const size1 = Value.number({
|
||||
units: "MiB",
|
||||
placeholder: null,
|
||||
});
|
||||
export const manual = Config.of({ size: size1 });
|
||||
export const manual = InputSpec.of({ size: size1 });
|
||||
export const pruningSettingsVariants = Variants.of({
|
||||
disabled: { name: "Disabled", spec: disabled },
|
||||
automatic: { name: "Automatic", spec: automatic },
|
||||
@@ -61,7 +61,7 @@ export class Variants<Type, Store> {
|
||||
VariantValues extends {
|
||||
[K in string]: {
|
||||
name: string
|
||||
spec: Config<any, Store> | Config<any, never>
|
||||
spec: InputSpec<any, Store> | InputSpec<any, never>
|
||||
}
|
||||
},
|
||||
Store = never,
|
||||
@@ -81,14 +81,17 @@ export class Variants<Type, Store> {
|
||||
selection: K
|
||||
// prettier-ignore
|
||||
value:
|
||||
VariantValues[K]["spec"] extends (Config<infer B, Store> | Config<infer B, never>) ? B :
|
||||
VariantValues[K]["spec"] extends (InputSpec<infer B, Store> | InputSpec<infer B, never>) ? B :
|
||||
never
|
||||
}
|
||||
}[keyof VariantValues],
|
||||
Store
|
||||
>(async (options) => {
|
||||
const variants = {} as {
|
||||
[K in keyof VariantValues]: { name: string; spec: InputSpec }
|
||||
[K in keyof VariantValues]: {
|
||||
name: string
|
||||
spec: Record<string, ValueSpec>
|
||||
}
|
||||
}
|
||||
for (const key in a) {
|
||||
const value = a[key]
|
||||
@@ -102,14 +105,14 @@ export class Variants<Type, Store> {
|
||||
}
|
||||
/**
|
||||
* Use this during the times that the input needs a more specific type.
|
||||
* Used in types that the value/ variant/ list/ config is constructed somewhere else.
|
||||
* Used in types that the value/ variant/ list/ inputSpec is constructed somewhere else.
|
||||
```ts
|
||||
const a = Config.text({
|
||||
const a = InputSpec.text({
|
||||
name: "a",
|
||||
required: false,
|
||||
})
|
||||
|
||||
return Config.of<Store>()({
|
||||
return InputSpec.of<Store>()({
|
||||
myValue: a.withStore(),
|
||||
})
|
||||
```
|
||||
3
sdk/base/lib/actions/input/index.ts
Normal file
3
sdk/base/lib/actions/input/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export * as constants from "./inputSpecConstants"
|
||||
export * as types from "./inputSpecTypes"
|
||||
export * as builder from "./builder"
|
||||
@@ -1,14 +1,13 @@
|
||||
import { SmtpValue } from "../types"
|
||||
import { GetSystemSmtp } from "../util/GetSystemSmtp"
|
||||
import { email } from "../util/patterns"
|
||||
import { Config, ConfigSpecOf } from "./builder/config"
|
||||
import { SmtpValue } from "../../types"
|
||||
import { GetSystemSmtp, Patterns } from "../../util"
|
||||
import { InputSpec, InputSpecOf } from "./builder/inputSpec"
|
||||
import { Value } from "./builder/value"
|
||||
import { Variants } from "./builder/variants"
|
||||
|
||||
/**
|
||||
* Base SMTP settings, to be used by StartOS for system wide SMTP
|
||||
*/
|
||||
export const customSmtp = Config.of<ConfigSpecOf<SmtpValue>, never>({
|
||||
export const customSmtp = InputSpec.of<InputSpecOf<SmtpValue>, never>({
|
||||
server: Value.text({
|
||||
name: "SMTP Server",
|
||||
required: {
|
||||
@@ -29,7 +28,7 @@ export const customSmtp = Config.of<ConfigSpecOf<SmtpValue>, never>({
|
||||
},
|
||||
placeholder: "<name>test@example.com",
|
||||
inputmode: "email",
|
||||
patterns: [email],
|
||||
patterns: [Patterns.email],
|
||||
}),
|
||||
login: Value.text({
|
||||
name: "Login",
|
||||
@@ -45,9 +44,9 @@ export const customSmtp = Config.of<ConfigSpecOf<SmtpValue>, never>({
|
||||
})
|
||||
|
||||
/**
|
||||
* For service config. Gives users 3 options for SMTP: (1) disabled, (2) use system SMTP settings, (3) use custom SMTP settings
|
||||
* For service inputSpec. Gives users 3 options for SMTP: (1) disabled, (2) use system SMTP settings, (3) use custom SMTP settings
|
||||
*/
|
||||
export const smtpConfig = Value.filteredUnion(
|
||||
export const smtpInputSpec = Value.filteredUnion(
|
||||
async ({ effects }) => {
|
||||
const smtp = await new GetSystemSmtp(effects).once()
|
||||
return smtp ? [] : ["system"]
|
||||
@@ -58,10 +57,10 @@ export const smtpConfig = Value.filteredUnion(
|
||||
required: { default: "disabled" },
|
||||
},
|
||||
Variants.of({
|
||||
disabled: { name: "Disabled", spec: Config.of({}) },
|
||||
disabled: { name: "Disabled", spec: InputSpec.of({}) },
|
||||
system: {
|
||||
name: "System Credentials",
|
||||
spec: Config.of({
|
||||
spec: InputSpec.of({
|
||||
customFrom: Value.text({
|
||||
name: "Custom From Address",
|
||||
description:
|
||||
@@ -69,7 +68,7 @@ export const smtpConfig = Value.filteredUnion(
|
||||
required: false,
|
||||
placeholder: "<name>test@example.com",
|
||||
inputmode: "email",
|
||||
patterns: [email],
|
||||
patterns: [Patterns.email],
|
||||
}),
|
||||
}),
|
||||
},
|
||||
@@ -12,6 +12,7 @@ export type ValueType =
|
||||
| "object"
|
||||
| "file"
|
||||
| "union"
|
||||
| "hidden"
|
||||
export type ValueSpec = ValueSpecOf<ValueType>
|
||||
/** core spec types. These types provide the metadata for performing validations */
|
||||
// prettier-ignore
|
||||
@@ -28,6 +29,7 @@ export type ValueSpecOf<T extends ValueType> =
|
||||
T extends "object" ? ValueSpecObject :
|
||||
T extends "file" ? ValueSpecFile :
|
||||
T extends "union" ? ValueSpecUnion :
|
||||
T extends "hidden" ? ValueSpecHidden :
|
||||
never
|
||||
|
||||
export type ValueSpecText = {
|
||||
@@ -48,7 +50,6 @@ export type ValueSpecText = {
|
||||
default: DefaultString | null
|
||||
disabled: false | string
|
||||
generate: null | RandomString
|
||||
/** Immutable means it can only be configured at the first config then never again */
|
||||
immutable: boolean
|
||||
}
|
||||
export type ValueSpecTextarea = {
|
||||
@@ -62,7 +63,6 @@ export type ValueSpecTextarea = {
|
||||
maxLength: number | null
|
||||
required: boolean
|
||||
disabled: false | string
|
||||
/** Immutable means it can only be configured at the first config then never again */
|
||||
immutable: boolean
|
||||
}
|
||||
|
||||
@@ -83,7 +83,6 @@ export type ValueSpecNumber = {
|
||||
required: boolean
|
||||
default: number | null
|
||||
disabled: false | string
|
||||
/** Immutable means it can only be configured at the first config then never again */
|
||||
immutable: boolean
|
||||
}
|
||||
export type ValueSpecColor = {
|
||||
@@ -95,7 +94,6 @@ export type ValueSpecColor = {
|
||||
required: boolean
|
||||
default: string | null
|
||||
disabled: false | string
|
||||
/** Immutable means it can only be configured at the first config then never again */
|
||||
immutable: boolean
|
||||
}
|
||||
export type ValueSpecDatetime = {
|
||||
@@ -109,7 +107,6 @@ export type ValueSpecDatetime = {
|
||||
max: string | null
|
||||
default: string | null
|
||||
disabled: false | string
|
||||
/** Immutable means it can only be configured at the first config then never again */
|
||||
immutable: boolean
|
||||
}
|
||||
export type ValueSpecSelect = {
|
||||
@@ -120,13 +117,7 @@ export type ValueSpecSelect = {
|
||||
type: "select"
|
||||
required: boolean
|
||||
default: string | null
|
||||
/**
|
||||
* Disabled: false means that there is nothing disabled, good to modify
|
||||
* string means that this is the message displayed and the whole thing is disabled
|
||||
* string[] means that the options are disabled
|
||||
*/
|
||||
disabled: false | string | string[]
|
||||
/** Immutable means it can only be configured at the first config then never again */
|
||||
immutable: boolean
|
||||
}
|
||||
export type ValueSpecMultiselect = {
|
||||
@@ -139,14 +130,8 @@ export type ValueSpecMultiselect = {
|
||||
type: "multiselect"
|
||||
minLength: number | null
|
||||
maxLength: number | null
|
||||
/**
|
||||
* Disabled: false means that there is nothing disabled, good to modify
|
||||
* string means that this is the message displayed and the whole thing is disabled
|
||||
* string[] means that the options are disabled
|
||||
*/
|
||||
disabled: false | string | string[]
|
||||
default: string[]
|
||||
/** Immutable means it can only be configured at the first config then never again */
|
||||
immutable: boolean
|
||||
}
|
||||
export type ValueSpecToggle = {
|
||||
@@ -157,7 +142,6 @@ export type ValueSpecToggle = {
|
||||
type: "toggle"
|
||||
default: boolean | null
|
||||
disabled: false | string
|
||||
/** Immutable means it can only be configured at the first config then never again */
|
||||
immutable: boolean
|
||||
}
|
||||
export type ValueSpecUnion = {
|
||||
@@ -173,15 +157,9 @@ export type ValueSpecUnion = {
|
||||
spec: InputSpec
|
||||
}
|
||||
>
|
||||
/**
|
||||
* Disabled: false means that there is nothing disabled, good to modify
|
||||
* string means that this is the message displayed and the whole thing is disabled
|
||||
* string[] means that the options are disabled
|
||||
*/
|
||||
disabled: false | string | string[]
|
||||
required: boolean
|
||||
default: string | null
|
||||
/** Immutable means it can only be configured at the first config then never again */
|
||||
immutable: boolean
|
||||
}
|
||||
export type ValueSpecFile = {
|
||||
@@ -199,14 +177,15 @@ export type ValueSpecObject = {
|
||||
type: "object"
|
||||
spec: InputSpec
|
||||
}
|
||||
export type ValueSpecHidden = {
|
||||
type: "hidden"
|
||||
}
|
||||
export type ListValueSpecType = "text" | "object"
|
||||
/** represents a spec for the values of a list */
|
||||
// prettier-ignore
|
||||
export type ListValueSpecOf<T extends ListValueSpecType> =
|
||||
T extends "text" ? ListValueSpecText :
|
||||
T extends "object" ? ListValueSpecObject :
|
||||
never
|
||||
/** represents a spec for a list */
|
||||
export type ValueSpecList = ValueSpecListOf<ListValueSpecType>
|
||||
export type ValueSpecListOf<T extends ListValueSpecType> = {
|
||||
name: string
|
||||
@@ -242,13 +221,13 @@ export type ListValueSpecText = {
|
||||
}
|
||||
export type ListValueSpecObject = {
|
||||
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
|
||||
/** indicates whether duplicates can be permitted in the list */
|
||||
uniqueBy: UniqueBy
|
||||
/** this should be a handlebars template which can make use of the entire config which corresponds to 'spec' */
|
||||
displayAs: string | null
|
||||
}
|
||||
// TODO Aiden do we really want this expressivity? Why not the below. Also what's with the "readonly" portion?
|
||||
// export type UniqueBy = null | string | { any: string[] } | { all: string[] }
|
||||
|
||||
export type UniqueBy =
|
||||
| null
|
||||
| string
|
||||
152
sdk/base/lib/actions/setupActions.ts
Normal file
152
sdk/base/lib/actions/setupActions.ts
Normal file
@@ -0,0 +1,152 @@
|
||||
import { InputSpec } from "./input/builder"
|
||||
import { ExtractInputSpecType } from "./input/builder/inputSpec"
|
||||
import * as T from "../types"
|
||||
|
||||
export type Run<
|
||||
A extends
|
||||
| Record<string, any>
|
||||
| InputSpec<Record<string, any>, any>
|
||||
| InputSpec<Record<string, never>, never>,
|
||||
> = (options: {
|
||||
effects: T.Effects
|
||||
input: ExtractInputSpecType<A> & Record<string, any>
|
||||
}) => Promise<T.ActionResult | null>
|
||||
export type GetInput<
|
||||
A extends
|
||||
| Record<string, any>
|
||||
| InputSpec<Record<string, any>, any>
|
||||
| InputSpec<Record<string, any>, never>,
|
||||
> = (options: {
|
||||
effects: T.Effects
|
||||
}) => Promise<null | (ExtractInputSpecType<A> & Record<string, any>)>
|
||||
|
||||
export type MaybeFn<T> = T | ((options: { effects: T.Effects }) => Promise<T>)
|
||||
function callMaybeFn<T>(
|
||||
maybeFn: MaybeFn<T>,
|
||||
options: { effects: T.Effects },
|
||||
): Promise<T> {
|
||||
if (maybeFn instanceof Function) {
|
||||
return maybeFn(options)
|
||||
} else {
|
||||
return Promise.resolve(maybeFn)
|
||||
}
|
||||
}
|
||||
function mapMaybeFn<T, U>(
|
||||
maybeFn: MaybeFn<T>,
|
||||
map: (value: T) => U,
|
||||
): MaybeFn<U> {
|
||||
if (maybeFn instanceof Function) {
|
||||
return async (...args) => map(await maybeFn(...args))
|
||||
} else {
|
||||
return map(maybeFn)
|
||||
}
|
||||
}
|
||||
|
||||
export class Action<
|
||||
Id extends T.ActionId,
|
||||
Store,
|
||||
InputSpecType extends
|
||||
| Record<string, any>
|
||||
| InputSpec<any, Store>
|
||||
| InputSpec<any, never>,
|
||||
Type extends
|
||||
ExtractInputSpecType<InputSpecType> = ExtractInputSpecType<InputSpecType>,
|
||||
> {
|
||||
private constructor(
|
||||
readonly id: Id,
|
||||
private readonly metadataFn: MaybeFn<T.ActionMetadata>,
|
||||
private readonly inputSpec: InputSpecType,
|
||||
private readonly getInputFn: GetInput<Type>,
|
||||
private readonly runFn: Run<Type>,
|
||||
) {}
|
||||
static withInput<
|
||||
Id extends T.ActionId,
|
||||
Store,
|
||||
InputSpecType extends
|
||||
| Record<string, any>
|
||||
| InputSpec<any, Store>
|
||||
| InputSpec<any, never>,
|
||||
Type extends
|
||||
ExtractInputSpecType<InputSpecType> = ExtractInputSpecType<InputSpecType>,
|
||||
>(
|
||||
id: Id,
|
||||
metadata: MaybeFn<Omit<T.ActionMetadata, "hasInput">>,
|
||||
inputSpec: InputSpecType,
|
||||
getInput: GetInput<Type>,
|
||||
run: Run<Type>,
|
||||
): Action<Id, Store, InputSpecType, Type> {
|
||||
return new Action(
|
||||
id,
|
||||
mapMaybeFn(metadata, (m) => ({ ...m, hasInput: true })),
|
||||
inputSpec,
|
||||
getInput,
|
||||
run,
|
||||
)
|
||||
}
|
||||
static withoutInput<Id extends T.ActionId, Store>(
|
||||
id: Id,
|
||||
metadata: MaybeFn<Omit<T.ActionMetadata, "hasInput">>,
|
||||
run: Run<{}>,
|
||||
): Action<Id, Store, {}, {}> {
|
||||
return new Action(
|
||||
id,
|
||||
mapMaybeFn(metadata, (m) => ({ ...m, hasInput: true })),
|
||||
{},
|
||||
async () => null,
|
||||
run,
|
||||
)
|
||||
}
|
||||
async exportMetadata(options: {
|
||||
effects: T.Effects
|
||||
}): Promise<T.ActionMetadata> {
|
||||
const metadata = await callMaybeFn(this.metadataFn, options)
|
||||
await options.effects.action.export({ id: this.id, metadata })
|
||||
return metadata
|
||||
}
|
||||
async getInput(options: { effects: T.Effects }): Promise<T.ActionInput> {
|
||||
return {
|
||||
spec: await this.inputSpec.build(options),
|
||||
value: (await this.getInputFn(options)) || null,
|
||||
}
|
||||
}
|
||||
async run(options: {
|
||||
effects: T.Effects
|
||||
input: Type
|
||||
}): Promise<T.ActionResult | null> {
|
||||
return this.runFn(options)
|
||||
}
|
||||
}
|
||||
|
||||
export class Actions<
|
||||
Store,
|
||||
AllActions extends Record<T.ActionId, Action<T.ActionId, Store, any, any>>,
|
||||
> {
|
||||
private constructor(private readonly actions: AllActions) {}
|
||||
static of<Store>(): Actions<Store, {}> {
|
||||
return new Actions({})
|
||||
}
|
||||
addAction<A extends Action<T.ActionId, Store, any, any>>(
|
||||
action: A,
|
||||
): Actions<Store, AllActions & { [id in A["id"]]: A }> {
|
||||
return new Actions({ ...this.actions, [action.id]: action })
|
||||
}
|
||||
update(options: { effects: T.Effects }): Promise<void> {
|
||||
const updater = async (options: { effects: T.Effects }) => {
|
||||
for (let action of Object.values(this.actions)) {
|
||||
await action.exportMetadata(options)
|
||||
}
|
||||
await options.effects.action.clear({ except: Object.keys(this.actions) })
|
||||
}
|
||||
const updaterCtx = { options }
|
||||
updaterCtx.options = {
|
||||
effects: {
|
||||
...options.effects,
|
||||
constRetry: () => updater(updaterCtx.options),
|
||||
},
|
||||
}
|
||||
return updater(updaterCtx.options)
|
||||
}
|
||||
get<Id extends T.ActionId>(actionId: Id): AllActions[Id] {
|
||||
return this.actions[actionId]
|
||||
}
|
||||
}
|
||||
208
sdk/base/lib/backup/Backups.ts
Normal file
208
sdk/base/lib/backup/Backups.ts
Normal file
@@ -0,0 +1,208 @@
|
||||
import * as T from "../types"
|
||||
import * as child_process from "child_process"
|
||||
import { asError } from "../util"
|
||||
|
||||
export const DEFAULT_OPTIONS: T.SyncOptions = {
|
||||
delete: true,
|
||||
exclude: [],
|
||||
}
|
||||
export type BackupSync<Volumes extends string> = {
|
||||
dataPath: `/media/startos/volumes/${Volumes}/${string}`
|
||||
backupPath: `/media/startos/backup/${string}`
|
||||
options?: Partial<T.SyncOptions>
|
||||
backupOptions?: Partial<T.SyncOptions>
|
||||
restoreOptions?: Partial<T.SyncOptions>
|
||||
}
|
||||
/**
|
||||
* This utility simplifies the volume backup process.
|
||||
* ```ts
|
||||
* export const { createBackup, restoreBackup } = Backups.volumes("main").build();
|
||||
* ```
|
||||
*
|
||||
* Changing the options of the rsync, (ie excludes) use either
|
||||
* ```ts
|
||||
* Backups.volumes("main").set_options({exclude: ['bigdata/']}).volumes('excludedVolume').build()
|
||||
* // or
|
||||
* Backups.with_options({exclude: ['bigdata/']}).volumes('excludedVolume').build()
|
||||
* ```
|
||||
*
|
||||
* Using the more fine control, using the addSets for more control
|
||||
* ```ts
|
||||
* Backups.addSets({
|
||||
* srcVolume: 'main', srcPath:'smallData/', dstPath: 'main/smallData/', dstVolume: : Backups.BACKUP
|
||||
* }, {
|
||||
* srcVolume: 'main', srcPath:'bigData/', dstPath: 'main/bigData/', dstVolume: : Backups.BACKUP, options: {exclude:['bigData/excludeThis']}}
|
||||
* ).build()q
|
||||
* ```
|
||||
*/
|
||||
export class Backups<M extends T.Manifest> {
|
||||
private constructor(
|
||||
private options = DEFAULT_OPTIONS,
|
||||
private restoreOptions: Partial<T.SyncOptions> = {},
|
||||
private backupOptions: Partial<T.SyncOptions> = {},
|
||||
private backupSet = [] as BackupSync<M["volumes"][number]>[],
|
||||
) {}
|
||||
|
||||
static withVolumes<M extends T.Manifest = never>(
|
||||
...volumeNames: Array<M["volumes"][number]>
|
||||
): Backups<M> {
|
||||
return Backups.withSyncs(
|
||||
...volumeNames.map((srcVolume) => ({
|
||||
dataPath: `/media/startos/volumes/${srcVolume}/` as const,
|
||||
backupPath: `/media/startos/backup/${srcVolume}/` as const,
|
||||
})),
|
||||
)
|
||||
}
|
||||
|
||||
static withSyncs<M extends T.Manifest = never>(
|
||||
...syncs: BackupSync<M["volumes"][number]>[]
|
||||
) {
|
||||
return syncs.reduce((acc, x) => acc.addSync(x), new Backups<M>())
|
||||
}
|
||||
|
||||
static withOptions<M extends T.Manifest = never>(
|
||||
options?: Partial<T.SyncOptions>,
|
||||
) {
|
||||
return new Backups<M>({ ...DEFAULT_OPTIONS, ...options })
|
||||
}
|
||||
|
||||
setOptions(options?: Partial<T.SyncOptions>) {
|
||||
this.options = {
|
||||
...this.options,
|
||||
...options,
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
setBackupOptions(options?: Partial<T.SyncOptions>) {
|
||||
this.backupOptions = {
|
||||
...this.backupOptions,
|
||||
...options,
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
setRestoreOptions(options?: Partial<T.SyncOptions>) {
|
||||
this.restoreOptions = {
|
||||
...this.restoreOptions,
|
||||
...options,
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
addVolume(
|
||||
volume: M["volumes"][number],
|
||||
options?: Partial<{
|
||||
options: T.SyncOptions
|
||||
backupOptions: T.SyncOptions
|
||||
restoreOptions: T.SyncOptions
|
||||
}>,
|
||||
) {
|
||||
return this.addSync({
|
||||
dataPath: `/media/startos/volumes/${volume}/` as const,
|
||||
backupPath: `/media/startos/backup/${volume}/` as const,
|
||||
...options,
|
||||
})
|
||||
}
|
||||
addSync(sync: BackupSync<M["volumes"][0]>) {
|
||||
this.backupSet.push({
|
||||
...sync,
|
||||
options: { ...this.options, ...sync.options },
|
||||
})
|
||||
return this
|
||||
}
|
||||
|
||||
async createBackup() {
|
||||
for (const item of this.backupSet) {
|
||||
const rsyncResults = await runRsync({
|
||||
srcPath: item.dataPath,
|
||||
dstPath: item.backupPath,
|
||||
options: {
|
||||
...this.options,
|
||||
...this.backupOptions,
|
||||
...item.options,
|
||||
...item.backupOptions,
|
||||
},
|
||||
})
|
||||
await rsyncResults.wait()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
async restoreBackup() {
|
||||
for (const item of this.backupSet) {
|
||||
const rsyncResults = await runRsync({
|
||||
srcPath: item.backupPath,
|
||||
dstPath: item.dataPath,
|
||||
options: {
|
||||
...this.options,
|
||||
...this.backupOptions,
|
||||
...item.options,
|
||||
...item.backupOptions,
|
||||
},
|
||||
})
|
||||
await rsyncResults.wait()
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
async function runRsync(rsyncOptions: {
|
||||
srcPath: string
|
||||
dstPath: string
|
||||
options: T.SyncOptions
|
||||
}): Promise<{
|
||||
id: () => Promise<string>
|
||||
wait: () => Promise<null>
|
||||
progress: () => Promise<number>
|
||||
}> {
|
||||
const { srcPath, dstPath, options } = rsyncOptions
|
||||
|
||||
const command = "rsync"
|
||||
const args: string[] = []
|
||||
if (options.delete) {
|
||||
args.push("--delete")
|
||||
}
|
||||
for (const exclude of options.exclude) {
|
||||
args.push(`--exclude=${exclude}`)
|
||||
}
|
||||
args.push("-actAXH")
|
||||
args.push("--info=progress2")
|
||||
args.push("--no-inc-recursive")
|
||||
args.push(srcPath)
|
||||
args.push(dstPath)
|
||||
const spawned = child_process.spawn(command, args, { detached: true })
|
||||
let percentage = 0.0
|
||||
spawned.stdout.on("data", (data: unknown) => {
|
||||
const lines = String(data).replace("\r", "\n").split("\n")
|
||||
for (const line of lines) {
|
||||
const parsed = /$([0-9.]+)%/.exec(line)?.[1]
|
||||
if (!parsed) continue
|
||||
percentage = Number.parseFloat(parsed)
|
||||
}
|
||||
})
|
||||
|
||||
spawned.stderr.on("data", (data: unknown) => {
|
||||
console.error(`Backups.runAsync`, asError(data))
|
||||
})
|
||||
|
||||
const id = async () => {
|
||||
const pid = spawned.pid
|
||||
if (pid === undefined) {
|
||||
throw new Error("rsync process has no pid")
|
||||
}
|
||||
return String(pid)
|
||||
}
|
||||
const waitPromise = new Promise<null>((resolve, reject) => {
|
||||
spawned.on("exit", (code: any) => {
|
||||
if (code === 0) {
|
||||
resolve(null)
|
||||
} else {
|
||||
reject(new Error(`rsync exited with code ${code}`))
|
||||
}
|
||||
})
|
||||
})
|
||||
const wait = () => waitPromise
|
||||
const progress = () => Promise.resolve(percentage)
|
||||
return { id, wait, progress }
|
||||
}
|
||||
39
sdk/base/lib/backup/setupBackups.ts
Normal file
39
sdk/base/lib/backup/setupBackups.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { Backups } from "./Backups"
|
||||
import * as T from "../types"
|
||||
import { _ } from "../util"
|
||||
|
||||
export type SetupBackupsParams<M extends T.Manifest> =
|
||||
| M["volumes"][number][]
|
||||
| ((_: { effects: T.Effects }) => Promise<Backups<M>>)
|
||||
|
||||
type SetupBackupsRes = {
|
||||
createBackup: T.ExpectedExports.createBackup
|
||||
restoreBackup: T.ExpectedExports.restoreBackup
|
||||
}
|
||||
|
||||
export function setupBackups<M extends T.Manifest>(
|
||||
options: SetupBackupsParams<M>,
|
||||
) {
|
||||
let backupsFactory: (_: { effects: T.Effects }) => Promise<Backups<M>>
|
||||
if (options instanceof Function) {
|
||||
backupsFactory = options
|
||||
} else {
|
||||
backupsFactory = async () => Backups.withVolumes(...options)
|
||||
}
|
||||
const answer: {
|
||||
createBackup: T.ExpectedExports.createBackup
|
||||
restoreBackup: T.ExpectedExports.restoreBackup
|
||||
} = {
|
||||
get createBackup() {
|
||||
return (async (options) => {
|
||||
return (await backupsFactory(options)).createBackup()
|
||||
}) as T.ExpectedExports.createBackup
|
||||
},
|
||||
get restoreBackup() {
|
||||
return (async (options) => {
|
||||
return (await backupsFactory(options)).restoreBackup()
|
||||
}) as T.ExpectedExports.restoreBackup
|
||||
},
|
||||
}
|
||||
return answer
|
||||
}
|
||||
21
sdk/base/lib/dependencies/Dependency.ts
Normal file
21
sdk/base/lib/dependencies/Dependency.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { VersionRange } from "../exver"
|
||||
|
||||
export class Dependency {
|
||||
constructor(
|
||||
readonly data:
|
||||
| {
|
||||
/** Either "running" or "exists". Does the dependency need to be running, or does it only need to exist? */
|
||||
type: "running"
|
||||
/** The acceptable version range of the dependency. */
|
||||
versionRange: VersionRange
|
||||
/** A list of the dependency's health check IDs that must be passing for the service to be satisfied. */
|
||||
healthChecks: string[]
|
||||
}
|
||||
| {
|
||||
/** Either "running" or "exists". Does the dependency need to be running, or does it only need to exist? */
|
||||
type: "exists"
|
||||
/** The acceptable version range of the dependency. */
|
||||
versionRange: VersionRange
|
||||
},
|
||||
) {}
|
||||
}
|
||||
@@ -1,18 +1,12 @@
|
||||
import { ExtendedVersion, VersionRange } from "../exver"
|
||||
import {
|
||||
Effects,
|
||||
PackageId,
|
||||
DependencyRequirement,
|
||||
SetHealth,
|
||||
CheckDependenciesResult,
|
||||
HealthCheckId,
|
||||
} from "../types"
|
||||
import { PackageId, HealthCheckId } from "../types"
|
||||
import { Effects } from "../Effects"
|
||||
|
||||
export type CheckDependencies<DependencyId extends PackageId = PackageId> = {
|
||||
installedSatisfied: (packageId: DependencyId) => boolean
|
||||
installedVersionSatisfied: (packageId: DependencyId) => boolean
|
||||
runningSatisfied: (packageId: DependencyId) => boolean
|
||||
configSatisfied: (packageId: DependencyId) => boolean
|
||||
actionsSatisfied: (packageId: DependencyId) => boolean
|
||||
healthCheckSatisfied: (
|
||||
packageId: DependencyId,
|
||||
healthCheckId: HealthCheckId,
|
||||
@@ -22,7 +16,7 @@ export type CheckDependencies<DependencyId extends PackageId = PackageId> = {
|
||||
throwIfInstalledNotSatisfied: (packageId: DependencyId) => void
|
||||
throwIfInstalledVersionNotSatisfied: (packageId: DependencyId) => void
|
||||
throwIfRunningNotSatisfied: (packageId: DependencyId) => void
|
||||
throwIfConfigNotSatisfied: (packageId: DependencyId) => void
|
||||
throwIfActionsNotSatisfied: (packageId: DependencyId) => void
|
||||
throwIfHealthNotSatisfied: (
|
||||
packageId: DependencyId,
|
||||
healthCheckId?: HealthCheckId,
|
||||
@@ -71,8 +65,8 @@ export async function checkDependencies<
|
||||
const dep = find(packageId)
|
||||
return dep.requirement.kind !== "running" || dep.result.isRunning
|
||||
}
|
||||
const configSatisfied = (packageId: DependencyId) =>
|
||||
find(packageId).result.configSatisfied
|
||||
const actionsSatisfied = (packageId: DependencyId) =>
|
||||
Object.keys(find(packageId).result.requestedActions).length === 0
|
||||
const healthCheckSatisfied = (
|
||||
packageId: DependencyId,
|
||||
healthCheckId?: HealthCheckId,
|
||||
@@ -94,7 +88,7 @@ export async function checkDependencies<
|
||||
installedSatisfied(packageId) &&
|
||||
installedVersionSatisfied(packageId) &&
|
||||
runningSatisfied(packageId) &&
|
||||
configSatisfied(packageId) &&
|
||||
actionsSatisfied(packageId) &&
|
||||
healthCheckSatisfied(packageId)
|
||||
const satisfied = (packageId?: DependencyId) =>
|
||||
packageId
|
||||
@@ -130,11 +124,12 @@ export async function checkDependencies<
|
||||
throw new Error(`${dep.result.title || packageId} is not running`)
|
||||
}
|
||||
}
|
||||
const throwIfConfigNotSatisfied = (packageId: DependencyId) => {
|
||||
const throwIfActionsNotSatisfied = (packageId: DependencyId) => {
|
||||
const dep = find(packageId)
|
||||
if (!dep.result.configSatisfied) {
|
||||
const reqs = Object.keys(dep.result.requestedActions)
|
||||
if (reqs.length) {
|
||||
throw new Error(
|
||||
`${dep.result.title || packageId}'s configuration does not satisfy requirements`,
|
||||
`The following action requests have not been fulfilled: ${reqs.join(", ")}`,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -168,7 +163,7 @@ export async function checkDependencies<
|
||||
throwIfInstalledNotSatisfied(packageId)
|
||||
throwIfInstalledVersionNotSatisfied(packageId)
|
||||
throwIfRunningNotSatisfied(packageId)
|
||||
throwIfConfigNotSatisfied(packageId)
|
||||
throwIfActionsNotSatisfied(packageId)
|
||||
throwIfHealthNotSatisfied(packageId)
|
||||
}
|
||||
const throwIfNotSatisfied = (packageId?: DependencyId) =>
|
||||
@@ -193,13 +188,13 @@ export async function checkDependencies<
|
||||
installedSatisfied,
|
||||
installedVersionSatisfied,
|
||||
runningSatisfied,
|
||||
configSatisfied,
|
||||
actionsSatisfied,
|
||||
healthCheckSatisfied,
|
||||
satisfied,
|
||||
throwIfInstalledNotSatisfied,
|
||||
throwIfInstalledVersionNotSatisfied,
|
||||
throwIfRunningNotSatisfied,
|
||||
throwIfConfigNotSatisfied,
|
||||
throwIfActionsNotSatisfied,
|
||||
throwIfHealthNotSatisfied,
|
||||
throwIfNotSatisfied,
|
||||
}
|
||||
@@ -4,6 +4,3 @@ export type ReadonlyDeep<A> =
|
||||
A extends {} ? { readonly [K in keyof A]: ReadonlyDeep<A[K]> } : A;
|
||||
export type MaybePromise<A> = Promise<A> | A
|
||||
export type Message = string
|
||||
|
||||
import "./DependencyConfig"
|
||||
import "./setupDependencyConfig"
|
||||
56
sdk/base/lib/dependencies/setupDependencies.ts
Normal file
56
sdk/base/lib/dependencies/setupDependencies.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import * as T from "../types"
|
||||
import { Dependency } from "./Dependency"
|
||||
|
||||
type DependencyType<Manifest extends T.Manifest> = {
|
||||
[K in keyof {
|
||||
[K in keyof Manifest["dependencies"]]: Manifest["dependencies"][K]["optional"] extends false
|
||||
? K
|
||||
: never
|
||||
}]: Dependency
|
||||
} & {
|
||||
[K in keyof {
|
||||
[K in keyof Manifest["dependencies"]]: Manifest["dependencies"][K]["optional"] extends true
|
||||
? K
|
||||
: never
|
||||
}]?: Dependency
|
||||
}
|
||||
|
||||
export function setupDependencies<Manifest extends T.Manifest>(
|
||||
fn: (options: { effects: T.Effects }) => Promise<DependencyType<Manifest>>,
|
||||
): (options: { effects: T.Effects }) => Promise<void> {
|
||||
return (options: { effects: T.Effects }) => {
|
||||
const updater = async (options: { effects: T.Effects }) => {
|
||||
const dependencyType = await fn(options)
|
||||
return await options.effects.setDependencies({
|
||||
dependencies: Object.entries(dependencyType).map(
|
||||
([
|
||||
id,
|
||||
{
|
||||
data: { versionRange, ...x },
|
||||
},
|
||||
]) => ({
|
||||
id,
|
||||
...x,
|
||||
...(x.type === "running"
|
||||
? {
|
||||
kind: "running",
|
||||
healthChecks: x.healthChecks,
|
||||
}
|
||||
: {
|
||||
kind: "exists",
|
||||
}),
|
||||
versionRange: versionRange.toString(),
|
||||
}),
|
||||
),
|
||||
})
|
||||
}
|
||||
const updaterCtx = { options }
|
||||
updaterCtx.options = {
|
||||
effects: {
|
||||
...options.effects,
|
||||
constRetry: () => updater(updaterCtx.options),
|
||||
},
|
||||
}
|
||||
return updater(updaterCtx.options)
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,12 @@
|
||||
export { S9pk } from "./s9pk"
|
||||
export { VersionRange, ExtendedVersion, Version } from "./exver"
|
||||
|
||||
export * as config from "./config"
|
||||
export * as CB from "./config/builder"
|
||||
export * as CT from "./config/configTypes"
|
||||
export * as dependencyConfig from "./dependencies"
|
||||
export * as inputSpec from "./actions/input"
|
||||
export * as ISB from "./actions/input/builder"
|
||||
export * as IST from "./actions/input/inputSpecTypes"
|
||||
export * as types from "./types"
|
||||
export * as T from "./types"
|
||||
export * as yaml from "yaml"
|
||||
export * as matches from "ts-matches"
|
||||
|
||||
export * as utils from "./util/index.browser"
|
||||
export * as utils from "./util"
|
||||
@@ -1,10 +1,10 @@
|
||||
import { number, object, string } from "ts-matches"
|
||||
import { Effects } from "../types"
|
||||
import { object, string } from "ts-matches"
|
||||
import { Effects } from "../Effects"
|
||||
import { Origin } from "./Origin"
|
||||
import { AddSslOptions, BindParams } from ".././osBindings"
|
||||
import { Security } from ".././osBindings"
|
||||
import { BindOptions } from ".././osBindings"
|
||||
import { AlpnInfo } from ".././osBindings"
|
||||
import { AddSslOptions, BindParams } from "../osBindings"
|
||||
import { Security } from "../osBindings"
|
||||
import { BindOptions } from "../osBindings"
|
||||
import { AlpnInfo } from "../osBindings"
|
||||
|
||||
export { AddSslOptions, Security, BindOptions }
|
||||
|
||||
@@ -94,6 +94,22 @@ export class Host {
|
||||
},
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @description Use this function to bind the host to an internal port and configured options for protocol, security, and external port.
|
||||
*
|
||||
* @param internalPort - The internal port to be bound.
|
||||
* @param options - The protocol options for this binding.
|
||||
* @returns A multi-origin that is capable of exporting one or more service interfaces.
|
||||
* @example
|
||||
* In this example, we bind a previously created multi-host to port 80, then select the http protocol and request an external port of 8332.
|
||||
*
|
||||
* ```
|
||||
const uiMultiOrigin = await uiMulti.bindPort(80, {
|
||||
protocol: 'http',
|
||||
preferredExternalPort: 8332,
|
||||
})
|
||||
* ```
|
||||
*/
|
||||
async bindPort(
|
||||
internalPort: number,
|
||||
options: BindOptionsByProtocol,
|
||||
@@ -1,6 +1,6 @@
|
||||
import { AddressInfo } from "../types"
|
||||
import { AddressReceipt } from "./AddressReceipt"
|
||||
import { Host, BindOptions, Scheme } from "./Host"
|
||||
import { Host, Scheme } from "./Host"
|
||||
import { ServiceInterfaceBuilder } from "./ServiceInterfaceBuilder"
|
||||
|
||||
export class Origin<T extends Host> {
|
||||
@@ -31,9 +31,9 @@ export class Origin<T extends Host> {
|
||||
}
|
||||
|
||||
/**
|
||||
* A function to register a group of origins (<PROTOCOL> :// <HOSTNAME> : <PORT>) with StartOS
|
||||
* @description A function to register a group of origins (<PROTOCOL> :// <HOSTNAME> : <PORT>) with StartOS
|
||||
*
|
||||
* The returned addressReceipt serves as proof that the addresses were registered
|
||||
* The returned addressReceipt serves as proof that the addresses were registered
|
||||
*
|
||||
* @param addressInfo
|
||||
* @returns
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ServiceInterfaceType } from "../StartSdk"
|
||||
import { Effects } from "../types"
|
||||
import { ServiceInterfaceType } from "../types"
|
||||
import { Effects } from "../Effects"
|
||||
import { Scheme } from "./Host"
|
||||
|
||||
/**
|
||||
54
sdk/base/lib/interfaces/setupInterfaces.ts
Normal file
54
sdk/base/lib/interfaces/setupInterfaces.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import * as T from "../types"
|
||||
import { AddressReceipt } from "./AddressReceipt"
|
||||
|
||||
declare const UpdateServiceInterfacesProof: unique symbol
|
||||
export type UpdateServiceInterfacesReceipt = {
|
||||
[UpdateServiceInterfacesProof]: never
|
||||
}
|
||||
|
||||
export type ServiceInterfacesReceipt = Array<T.AddressInfo[] & AddressReceipt>
|
||||
export type SetServiceInterfaces<Output extends ServiceInterfacesReceipt> =
|
||||
(opts: { effects: T.Effects }) => Promise<Output>
|
||||
export type UpdateServiceInterfaces<Output extends ServiceInterfacesReceipt> =
|
||||
(opts: {
|
||||
effects: T.Effects
|
||||
}) => Promise<Output & UpdateServiceInterfacesReceipt>
|
||||
export type SetupServiceInterfaces = <Output extends ServiceInterfacesReceipt>(
|
||||
fn: SetServiceInterfaces<Output>,
|
||||
) => UpdateServiceInterfaces<Output>
|
||||
export const NO_INTERFACE_CHANGES = {} as UpdateServiceInterfacesReceipt
|
||||
export const setupServiceInterfaces: SetupServiceInterfaces = <
|
||||
Output extends ServiceInterfacesReceipt,
|
||||
>(
|
||||
fn: SetServiceInterfaces<Output>,
|
||||
) =>
|
||||
((options: { effects: T.Effects }) => {
|
||||
const updater = async (options: { effects: T.Effects }) => {
|
||||
const bindings: T.BindId[] = []
|
||||
const interfaces: T.ServiceInterfaceId[] = []
|
||||
const res = await fn({
|
||||
effects: {
|
||||
...options.effects,
|
||||
bind: (params: T.BindParams) => {
|
||||
bindings.push({ id: params.id, internalPort: params.internalPort })
|
||||
return options.effects.bind(params)
|
||||
},
|
||||
exportServiceInterface: (params: T.ExportServiceInterfaceParams) => {
|
||||
interfaces.push(params.id)
|
||||
return options.effects.exportServiceInterface(params)
|
||||
},
|
||||
},
|
||||
})
|
||||
await options.effects.clearBindings({ except: bindings })
|
||||
await options.effects.clearServiceInterfaces({ except: interfaces })
|
||||
return res
|
||||
}
|
||||
const updaterCtx = { options }
|
||||
updaterCtx.options = {
|
||||
effects: {
|
||||
...options.effects,
|
||||
constRetry: () => updater(updaterCtx.options),
|
||||
},
|
||||
}
|
||||
return updater(updaterCtx.options)
|
||||
}) as UpdateServiceInterfaces<Output>
|
||||
@@ -1,4 +1,6 @@
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
import type { MainStatus } from "./MainStatus"
|
||||
|
||||
export type Status = { configured: boolean; main: MainStatus }
|
||||
export type ActionInput = {
|
||||
spec: Record<string, unknown>
|
||||
value: Record<string, unknown> | null
|
||||
}
|
||||
@@ -1,12 +1,13 @@
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
import type { ActionVisibility } from "./ActionVisibility"
|
||||
import type { AllowedStatuses } from "./AllowedStatuses"
|
||||
|
||||
export type ActionMetadata = {
|
||||
name: string
|
||||
description: string
|
||||
warning: string | null
|
||||
input: any
|
||||
disabled: boolean
|
||||
visibility: ActionVisibility
|
||||
allowedStatuses: AllowedStatuses
|
||||
hasInput: boolean
|
||||
group: string | null
|
||||
}
|
||||
13
sdk/base/lib/osBindings/ActionRequest.ts
Normal file
13
sdk/base/lib/osBindings/ActionRequest.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
import type { ActionId } from "./ActionId"
|
||||
import type { ActionRequestInput } from "./ActionRequestInput"
|
||||
import type { ActionRequestTrigger } from "./ActionRequestTrigger"
|
||||
import type { PackageId } from "./PackageId"
|
||||
|
||||
export type ActionRequest = {
|
||||
packageId: PackageId
|
||||
actionId: ActionId
|
||||
description?: string
|
||||
when?: ActionRequestTrigger
|
||||
input?: ActionRequestInput
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
|
||||
export type AllowedStatuses = "onlyRunning" | "onlyStopped" | "any"
|
||||
export type ActionRequestCondition = "input-not-matches"
|
||||
4
sdk/base/lib/osBindings/ActionRequestEntry.ts
Normal file
4
sdk/base/lib/osBindings/ActionRequestEntry.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
import type { ActionRequest } from "./ActionRequest"
|
||||
|
||||
export type ActionRequestEntry = { request: ActionRequest; active: boolean }
|
||||
6
sdk/base/lib/osBindings/ActionRequestInput.ts
Normal file
6
sdk/base/lib/osBindings/ActionRequestInput.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
|
||||
export type ActionRequestInput = {
|
||||
kind: "partial"
|
||||
value: Record<string, unknown>
|
||||
}
|
||||
7
sdk/base/lib/osBindings/ActionRequestTrigger.ts
Normal file
7
sdk/base/lib/osBindings/ActionRequestTrigger.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
import type { ActionRequestCondition } from "./ActionRequestCondition"
|
||||
|
||||
export type ActionRequestTrigger = {
|
||||
once: boolean
|
||||
condition: ActionRequestCondition
|
||||
}
|
||||
6
sdk/base/lib/osBindings/ActionVisibility.ts
Normal file
6
sdk/base/lib/osBindings/ActionVisibility.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
|
||||
export type ActionVisibility =
|
||||
| "hidden"
|
||||
| { disabled: { reason: string } }
|
||||
| "enabled"
|
||||
3
sdk/base/lib/osBindings/AllowedStatuses.ts
Normal file
3
sdk/base/lib/osBindings/AllowedStatuses.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
|
||||
export type AllowedStatuses = "only-running" | "only-stopped" | "any"
|
||||
4
sdk/base/lib/osBindings/BindId.ts
Normal file
4
sdk/base/lib/osBindings/BindId.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
import type { HostId } from "./HostId"
|
||||
|
||||
export type BindId = { id: HostId; internalPort: number }
|
||||
@@ -2,4 +2,4 @@
|
||||
import type { BindOptions } from "./BindOptions"
|
||||
import type { LanInfo } from "./LanInfo"
|
||||
|
||||
export type BindInfo = { options: BindOptions; lan: LanInfo }
|
||||
export type BindInfo = { enabled: boolean; options: BindOptions; lan: LanInfo }
|
||||
@@ -1,14 +1,17 @@
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
import type { ActionRequestEntry } from "./ActionRequestEntry"
|
||||
import type { HealthCheckId } from "./HealthCheckId"
|
||||
import type { NamedHealthCheckResult } from "./NamedHealthCheckResult"
|
||||
import type { PackageId } from "./PackageId"
|
||||
import type { ReplayId } from "./ReplayId"
|
||||
import type { Version } from "./Version"
|
||||
|
||||
export type CheckDependenciesResult = {
|
||||
packageId: PackageId
|
||||
title: string | null
|
||||
installedVersion: string | null
|
||||
satisfies: string[]
|
||||
installedVersion: Version | null
|
||||
satisfies: Array<Version>
|
||||
isRunning: boolean
|
||||
configSatisfied: boolean
|
||||
requestedActions: { [key: ReplayId]: ActionRequestEntry }
|
||||
healthChecks: { [key: HealthCheckId]: NamedHealthCheckResult }
|
||||
}
|
||||
5
sdk/base/lib/osBindings/ClearActionRequestsParams.ts
Normal file
5
sdk/base/lib/osBindings/ClearActionRequestsParams.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
|
||||
export type ClearActionRequestsParams =
|
||||
| { only: string[] }
|
||||
| { except: string[] }
|
||||
4
sdk/base/lib/osBindings/ClearActionsParams.ts
Normal file
4
sdk/base/lib/osBindings/ClearActionsParams.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
import type { ActionId } from "./ActionId"
|
||||
|
||||
export type ClearActionsParams = { except: Array<ActionId> }
|
||||
4
sdk/base/lib/osBindings/ClearBindingsParams.ts
Normal file
4
sdk/base/lib/osBindings/ClearBindingsParams.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
import type { BindId } from "./BindId"
|
||||
|
||||
export type ClearBindingsParams = { except: Array<BindId> }
|
||||
3
sdk/base/lib/osBindings/ClearCallbacksParams.ts
Normal file
3
sdk/base/lib/osBindings/ClearCallbacksParams.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
|
||||
export type ClearCallbacksParams = { only: number[] } | { except: number[] }
|
||||
4
sdk/base/lib/osBindings/ClearServiceInterfacesParams.ts
Normal file
4
sdk/base/lib/osBindings/ClearServiceInterfacesParams.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
import type { ServiceInterfaceId } from "./ServiceInterfaceId"
|
||||
|
||||
export type ClearServiceInterfacesParams = { except: Array<ServiceInterfaceId> }
|
||||
@@ -5,5 +5,4 @@ export type CurrentDependencyInfo = {
|
||||
title: string | null
|
||||
icon: DataUrl | null
|
||||
versionRange: string
|
||||
configSatisfied: boolean
|
||||
} & ({ kind: "exists" } | { kind: "running"; healthChecks: string[] })
|
||||
@@ -1,10 +1,5 @@
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
import type { ActionId } from "./ActionId"
|
||||
import type { ActionMetadata } from "./ActionMetadata"
|
||||
import type { PackageId } from "./PackageId"
|
||||
|
||||
export type ExportActionParams = {
|
||||
packageId?: PackageId
|
||||
id: ActionId
|
||||
metadata: ActionMetadata
|
||||
}
|
||||
export type ExportActionParams = { id: ActionId; metadata: ActionMetadata }
|
||||
@@ -1,4 +1,5 @@
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
import type { ActionId } from "./ActionId"
|
||||
import type { PackageId } from "./PackageId"
|
||||
|
||||
export type GetConfiguredParams = { packageId?: PackageId }
|
||||
export type GetActionInputParams = { packageId?: PackageId; actionId: ActionId }
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user