mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-30 04:11:57 +00:00
chore: Add an effect
This commit is contained in:
107
lib/types.ts
107
lib/types.ts
@@ -4,39 +4,24 @@ import { InputSpec } from "./config/config-types";
|
|||||||
export namespace ExpectedExports {
|
export namespace ExpectedExports {
|
||||||
version: 1;
|
version: 1;
|
||||||
/** Set configuration is called after we have modified and saved the configuration in the embassy ui. Use this to make a file for the docker to read from for configuration. */
|
/** Set configuration is called after we have modified and saved the configuration in the embassy ui. Use this to make a file for the docker to read from for configuration. */
|
||||||
export type setConfig = (options: {
|
export type setConfig = (options: { effects: Effects; input: Record<string, unknown> }) => Promise<unknown>;
|
||||||
effects: Effects;
|
|
||||||
input: Record<string, unknown>;
|
|
||||||
}) => Promise<unknown>;
|
|
||||||
/** Get configuration returns a shape that describes the format that the embassy ui will generate, and later send to the set config */
|
/** Get configuration returns a shape that describes the format that the embassy ui will generate, and later send to the set config */
|
||||||
export type getConfig = (options: {
|
export type getConfig = (options: { effects: Effects; config: unknown }) => Promise<ConfigRes>;
|
||||||
effects: Effects;
|
|
||||||
config: unknown;
|
|
||||||
}) => Promise<ConfigRes>;
|
|
||||||
/** These are how we make sure the our dependency configurations are valid and if not how to fix them. */
|
/** These are how we make sure the our dependency configurations are valid and if not how to fix them. */
|
||||||
export type dependencies = Dependencies;
|
export type dependencies = Dependencies;
|
||||||
/** For backing up service data though the embassyOS UI */
|
/** For backing up service data though the embassyOS UI */
|
||||||
export type createBackup = (options: {
|
export type createBackup = (options: { effects: Effects }) => Promise<unknown>;
|
||||||
effects: Effects;
|
|
||||||
}) => Promise<unknown>;
|
|
||||||
/** For restoring service data that was previously backed up using the embassyOS UI create backup flow. Backup restores are also triggered via the embassyOS UI, or doing a system restore flow during setup. */
|
/** For restoring service data that was previously backed up using the embassyOS UI create backup flow. Backup restores are also triggered via the embassyOS UI, or doing a system restore flow during setup. */
|
||||||
export type restoreBackup = (options: {
|
export type restoreBackup = (options: { effects: Effects }) => Promise<unknown>;
|
||||||
effects: Effects;
|
|
||||||
}) => Promise<unknown>;
|
|
||||||
/** Properties are used to get values from the docker, like a username + password, what ports we are hosting from */
|
/** Properties are used to get values from the docker, like a username + password, what ports we are hosting from */
|
||||||
export type properties = (options: {
|
export type properties = (options: { effects: Effects }) => Promise<Properties>;
|
||||||
effects: Effects;
|
|
||||||
}) => Promise<Properties>;
|
|
||||||
|
|
||||||
/** Health checks are used to determine if the service is working properly after starting
|
/** Health checks are used to determine if the service is working properly after starting
|
||||||
* A good use case is if we are using a web server, seeing if we can get to the web server.
|
* A good use case is if we are using a web server, seeing if we can get to the web server.
|
||||||
*/
|
*/
|
||||||
export type health = {
|
export type health = {
|
||||||
/** Should be the health check id */
|
/** Should be the health check id */
|
||||||
[id: string]: (options: {
|
[id: string]: (options: { effects: Effects; input: TimeMs }) => Promise<unknown>;
|
||||||
effects: Effects;
|
|
||||||
input: TimeMs;
|
|
||||||
}) => Promise<unknown>;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -45,36 +30,24 @@ export namespace ExpectedExports {
|
|||||||
* service starting, and that file would indicate that it would rescan all the data.
|
* service starting, and that file would indicate that it would rescan all the data.
|
||||||
*/
|
*/
|
||||||
export type action = {
|
export type action = {
|
||||||
[id: string]: (options: {
|
[id: string]: (options: { effects: Effects; input?: Record<string, unknown> }) => Promise<ActionResult>;
|
||||||
effects: Effects;
|
|
||||||
input?: Record<string, unknown>;
|
|
||||||
}) => Promise<ActionResult>;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the entrypoint for the main container. Used to start up something like the service that the
|
* This is the entrypoint for the main container. Used to start up something like the service that the
|
||||||
* package represents, like running a bitcoind in a bitcoind-wrapper.
|
* package represents, like running a bitcoind in a bitcoind-wrapper.
|
||||||
*/
|
*/
|
||||||
export type main = (options: {
|
export type main = (options: { effects: Effects; started(onTerm: () => void): null }) => Promise<unknown>;
|
||||||
effects: Effects;
|
|
||||||
started(onTerm: () => void): null;
|
|
||||||
}) => Promise<unknown>;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Every time a package completes an install, this function is called before the main.
|
* Every time a package completes an install, this function is called before the main.
|
||||||
* Can be used to do migration like things.
|
* Can be used to do migration like things.
|
||||||
*/
|
*/
|
||||||
export type init = (options: {
|
export type init = (options: { effects: Effects; previousVersion: null | string }) => Promise<unknown>;
|
||||||
effects: Effects;
|
|
||||||
previousVersion: null | string;
|
|
||||||
}) => Promise<unknown>;
|
|
||||||
/** This will be ran during any time a package is uninstalled, for example during a update
|
/** This will be ran during any time a package is uninstalled, for example during a update
|
||||||
* this will be called.
|
* this will be called.
|
||||||
*/
|
*/
|
||||||
export type uninit = (options: {
|
export type uninit = (options: { effects: Effects; nextVersion: null | string }) => Promise<unknown>;
|
||||||
effects: Effects;
|
|
||||||
nextVersion: null | string;
|
|
||||||
}) => Promise<unknown>;
|
|
||||||
}
|
}
|
||||||
export type TimeMs = number;
|
export type TimeMs = number;
|
||||||
export type VersionString = string;
|
export type VersionString = string;
|
||||||
@@ -88,11 +61,7 @@ export type ConfigRes = {
|
|||||||
/** Used to reach out from the pure js runtime */
|
/** Used to reach out from the pure js runtime */
|
||||||
export type Effects = {
|
export type Effects = {
|
||||||
/** Usable when not sandboxed */
|
/** Usable when not sandboxed */
|
||||||
writeFile(input: {
|
writeFile(input: { path: string; volumeId: string; toWrite: string }): Promise<void>;
|
||||||
path: string;
|
|
||||||
volumeId: string;
|
|
||||||
toWrite: string;
|
|
||||||
}): Promise<void>;
|
|
||||||
readFile(input: { volumeId: string; path: string }): Promise<string>;
|
readFile(input: { volumeId: string; path: string }): Promise<string>;
|
||||||
metadata(input: { volumeId: string; path: string }): Promise<Metadata>;
|
metadata(input: { volumeId: string; path: string }): Promise<Metadata>;
|
||||||
/** Create a directory. Usable when not sandboxed */
|
/** Create a directory. Usable when not sandboxed */
|
||||||
@@ -104,23 +73,13 @@ export type Effects = {
|
|||||||
removeFile(input: { volumeId: string; path: string }): Promise<void>;
|
removeFile(input: { volumeId: string; path: string }): Promise<void>;
|
||||||
|
|
||||||
/** Write a json file into an object. Usable when not sandboxed */
|
/** Write a json file into an object. Usable when not sandboxed */
|
||||||
writeJsonFile(input: {
|
writeJsonFile(input: { volumeId: string; path: string; toWrite: Record<string, unknown> }): Promise<void>;
|
||||||
volumeId: string;
|
|
||||||
path: string;
|
|
||||||
toWrite: Record<string, unknown>;
|
|
||||||
}): Promise<void>;
|
|
||||||
|
|
||||||
/** Read a json file into an object */
|
/** Read a json file into an object */
|
||||||
readJsonFile(input: {
|
readJsonFile(input: { volumeId: string; path: string }): Promise<Record<string, unknown>>;
|
||||||
volumeId: string;
|
|
||||||
path: string;
|
|
||||||
}): Promise<Record<string, unknown>>;
|
|
||||||
|
|
||||||
runCommand(input: {
|
shell(command: string, options?: { timeoutMillis?: number | null }): Promise<string>;
|
||||||
command: string;
|
runCommand(input: { command: string; args?: string[]; timeoutMillis?: number }): Promise<string>;
|
||||||
args?: string[];
|
|
||||||
timeoutMillis?: number;
|
|
||||||
}): Promise<string>;
|
|
||||||
runDaemon(input: { command: string; args?: string[] }): {
|
runDaemon(input: { command: string; args?: string[] }): {
|
||||||
wait(): Promise<string>;
|
wait(): Promise<string>;
|
||||||
term(): Promise<void>;
|
term(): Promise<void>;
|
||||||
@@ -150,17 +109,9 @@ export type Effects = {
|
|||||||
/** Check that a file exists or not */
|
/** Check that a file exists or not */
|
||||||
exists(input: { volumeId: string; path: string }): Promise<boolean>;
|
exists(input: { volumeId: string; path: string }): Promise<boolean>;
|
||||||
/** Declaring that we are opening a interface on some protocal for local network */
|
/** Declaring that we are opening a interface on some protocal for local network */
|
||||||
bindLocal(options: {
|
bindLocal(options: { internalPort: number; name: string; externalPort: number }): Promise<string>;
|
||||||
internalPort: number;
|
|
||||||
name: string;
|
|
||||||
externalPort: number;
|
|
||||||
}): Promise<string>;
|
|
||||||
/** Declaring that we are opening a interface on some protocal for tor network */
|
/** Declaring that we are opening a interface on some protocal for tor network */
|
||||||
bindTor(options: {
|
bindTor(options: { internalPort: number; name: string; externalPort: number }): Promise<string>;
|
||||||
internalPort: number;
|
|
||||||
name: string;
|
|
||||||
externalPort: number;
|
|
||||||
}): Promise<string>;
|
|
||||||
|
|
||||||
/** Similar to the fetch api via the mdn, this is simplified but the point is
|
/** Similar to the fetch api via the mdn, this is simplified but the point is
|
||||||
* to get something from some website, and return the response.
|
* to get something from some website, and return the response.
|
||||||
@@ -208,22 +159,13 @@ export type Effects = {
|
|||||||
}): Promise<unknown>;
|
}): Promise<unknown>;
|
||||||
|
|
||||||
/** Get the address for another service for local internet*/
|
/** Get the address for another service for local internet*/
|
||||||
getServiceLocalAddress(options: {
|
getServiceLocalAddress(options: { packageId: string; interfaceName: string }): Promise<string>;
|
||||||
packageId: string;
|
|
||||||
interfaceName: string;
|
|
||||||
}): Promise<string>;
|
|
||||||
/** Get the address for another service for tor interfaces */
|
/** Get the address for another service for tor interfaces */
|
||||||
getServiceTorAddress(options: {
|
getServiceTorAddress(options: { packageId: string; interfaceName: string }): Promise<string>;
|
||||||
packageId: string;
|
|
||||||
interfaceName: string;
|
|
||||||
}): Promise<string>;
|
|
||||||
/**
|
/**
|
||||||
* Get the port address for another service
|
* Get the port address for another service
|
||||||
*/
|
*/
|
||||||
getServicePortForward(options: {
|
getServicePortForward(options: { packageId: string; internalPort: number }): Promise<string>;
|
||||||
packageId: string;
|
|
||||||
internalPort: number;
|
|
||||||
}): Promise<string>;
|
|
||||||
|
|
||||||
/** When we want to create a link in the front end interfaces, and example is
|
/** When we want to create a link in the front end interfaces, and example is
|
||||||
* exposing a url to view a web service
|
* exposing a url to view a web service
|
||||||
@@ -279,10 +221,7 @@ export type Effects = {
|
|||||||
*
|
*
|
||||||
* @returns PEM encoded fullchain (ecdsa)
|
* @returns PEM encoded fullchain (ecdsa)
|
||||||
*/
|
*/
|
||||||
getSslCertificate: (
|
getSslCertificate: (packageId: string, algorithm?: "ecdsa" | "ed25519") => [string, string, string];
|
||||||
packageId: string,
|
|
||||||
algorithm?: "ecdsa" | "ed25519"
|
|
||||||
) => [string, string, string];
|
|
||||||
/**
|
/**
|
||||||
* @returns PEM encoded ssl key (ecdsa)
|
* @returns PEM encoded ssl key (ecdsa)
|
||||||
*/
|
*/
|
||||||
@@ -410,6 +349,4 @@ export type Dependencies = {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export type DeepPartial<T> = T extends {}
|
export type DeepPartial<T> = T extends {} ? { [P in keyof T]?: DeepPartial<T[P]> } : T;
|
||||||
? { [P in keyof T]?: DeepPartial<T[P]> }
|
|
||||||
: T;
|
|
||||||
|
|||||||
Reference in New Issue
Block a user