mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-26 02:11:56 +00:00
chore: charlie23
This commit is contained in:
@@ -2,4 +2,4 @@ export * as configBuilder from "./builder";
|
||||
|
||||
export { setupConfigExports } from "./setupConfigExports";
|
||||
export { specToBuilder, specToBuilderFile } from "./specToBuilder";
|
||||
export * as dependencies from './dependencies'
|
||||
export * as dependencies from "./dependencies";
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
import { Config } from "./builder";
|
||||
import { DeepPartial, Dependencies, DependsOn, Effects, ExpectedExports } from "../types";
|
||||
import {
|
||||
DeepPartial,
|
||||
Dependencies,
|
||||
DependsOn,
|
||||
Effects,
|
||||
ExpectedExports,
|
||||
} from "../types";
|
||||
import { InputSpec } from "./configTypes";
|
||||
import { nullIfEmpty } from "../util";
|
||||
import { TypeFromProps } from "../util/propertiesMatcher";
|
||||
@@ -13,8 +19,14 @@ import { TypeFromProps } from "../util/propertiesMatcher";
|
||||
*/
|
||||
export function setupConfigExports<A extends InputSpec, ConfigType>(options: {
|
||||
spec: Config<A>;
|
||||
write(options: { effects: Effects; input: TypeFromProps<A> }): Promise<[ConfigType, Dependencies]>;
|
||||
read(options: { effects: Effects; config: ConfigType }): Promise<null | DeepPartial<TypeFromProps<A>>>;
|
||||
write(options: {
|
||||
effects: Effects;
|
||||
input: TypeFromProps<A>;
|
||||
}): Promise<[ConfigType, Dependencies]>;
|
||||
read(options: {
|
||||
effects: Effects;
|
||||
config: ConfigType;
|
||||
}): Promise<null | DeepPartial<TypeFromProps<A>>>;
|
||||
}) {
|
||||
const validator = options.spec.validator();
|
||||
return {
|
||||
@@ -31,7 +43,9 @@ export function setupConfigExports<A extends InputSpec, ConfigType>(options: {
|
||||
getConfig: (async ({ effects, config }) => {
|
||||
return {
|
||||
spec: options.spec.build(),
|
||||
config: nullIfEmpty(await options.read({ effects, config: config as ConfigType })),
|
||||
config: nullIfEmpty(
|
||||
await options.read({ effects, config: config as ConfigType })
|
||||
),
|
||||
};
|
||||
}) as ExpectedExports.getConfig,
|
||||
};
|
||||
|
||||
@@ -14,4 +14,4 @@ export class NetworkBuilder {
|
||||
getPort(id: string) {
|
||||
return new LocalPort(this.effects, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
106
lib/types.ts
106
lib/types.ts
@@ -5,17 +5,29 @@ import { ActionReceipt } from "./init";
|
||||
export namespace ExpectedExports {
|
||||
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. */
|
||||
export type setConfig = (options: { effects: Effects; input: Record<string, unknown> }) => Promise<void>;
|
||||
export type setConfig = (options: {
|
||||
effects: Effects;
|
||||
input: Record<string, unknown>;
|
||||
}) => Promise<void>;
|
||||
/** 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: { effects: Effects; config: unknown }) => Promise<ConfigRes>;
|
||||
export type getConfig = (options: {
|
||||
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. */
|
||||
// export type dependencies = Dependencies;
|
||||
/** For backing up service data though the embassyOS UI */
|
||||
export type createBackup = (options: { effects: Effects }) => Promise<unknown>;
|
||||
export type createBackup = (options: {
|
||||
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. */
|
||||
export type restoreBackup = (options: { effects: Effects }) => Promise<unknown>;
|
||||
export type restoreBackup = (options: {
|
||||
effects: Effects;
|
||||
}) => Promise<unknown>;
|
||||
/** Properties are used to get values from the docker, like a username + password, what ports we are hosting from */
|
||||
export type properties = (options: { effects: Effects }) => Promise<Properties | null | undefined | void>;
|
||||
export type properties = (options: {
|
||||
effects: Effects;
|
||||
}) => Promise<Properties | null | undefined | void>;
|
||||
|
||||
// /** 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.
|
||||
@@ -31,35 +43,51 @@ export namespace ExpectedExports {
|
||||
* service starting, and that file would indicate that it would rescan all the data.
|
||||
*/
|
||||
export type action = {
|
||||
[id: string]: (options: { effects: Effects; input?: Record<string, unknown> }) => Promise<ActionResult>;
|
||||
[id: string]: (options: {
|
||||
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
|
||||
* package represents, like running a bitcoind in a bitcoind-wrapper.
|
||||
*/
|
||||
export type main = (options: { effects: Effects; started(onTerm: () => void): null }) => Promise<unknown>;
|
||||
export type main = (options: {
|
||||
effects: Effects;
|
||||
started(onTerm: () => void): null;
|
||||
}) => Promise<unknown>;
|
||||
|
||||
/**
|
||||
* After a shutdown, if we wanted to do any operations to clean up things, like
|
||||
* set the action as unavailable or something.
|
||||
*/
|
||||
export type afterShutdown = (options: { effects: Effects }) => Promise<unknown>;
|
||||
export type afterShutdown = (options: {
|
||||
effects: Effects;
|
||||
}) => Promise<unknown>;
|
||||
|
||||
/**
|
||||
* Every time a package completes an install, this function is called before the main.
|
||||
* Can be used to do migration like things.
|
||||
*/
|
||||
export type init = (options: { effects: Effects; previousVersion: null | string }) => Promise<unknown>;
|
||||
export type init = (options: {
|
||||
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 called.
|
||||
*/
|
||||
export type uninit = (options: { effects: Effects; nextVersion: null | string }) => Promise<unknown>;
|
||||
export type uninit = (options: {
|
||||
effects: Effects;
|
||||
nextVersion: null | string;
|
||||
}) => Promise<unknown>;
|
||||
}
|
||||
export type TimeMs = number;
|
||||
export type VersionString = string;
|
||||
|
||||
export type ValidIfNoStupidEscape<A> = A extends `${string}'"'"'${string}` | `${string}\\"${string}`
|
||||
export type ValidIfNoStupidEscape<A> = A extends
|
||||
| `${string}'"'"'${string}`
|
||||
| `${string}\\"${string}`
|
||||
? never
|
||||
: "" extends A & ""
|
||||
? never
|
||||
@@ -84,7 +112,9 @@ export type Daemon = {
|
||||
|
||||
export type HealthStatus = "passing" | "warning" | "failing" | "disabled";
|
||||
|
||||
export type CommandType<A extends string> = ValidIfNoStupidEscape<A> | [string, ...string[]];
|
||||
export type CommandType<A extends string> =
|
||||
| ValidIfNoStupidEscape<A>
|
||||
| [string, ...string[]];
|
||||
|
||||
export type DaemonReturned = {
|
||||
wait(): Promise<string>;
|
||||
@@ -94,7 +124,11 @@ export type DaemonReturned = {
|
||||
/** Used to reach out from the pure js runtime */
|
||||
export type Effects = {
|
||||
/** Usable when not sandboxed */
|
||||
writeFile(input: { path: string; volumeId: string; toWrite: string }): Promise<void>;
|
||||
writeFile(input: {
|
||||
path: string;
|
||||
volumeId: string;
|
||||
toWrite: string;
|
||||
}): Promise<void>;
|
||||
readFile(input: { volumeId: string; path: string }): Promise<string>;
|
||||
metadata(input: { volumeId: string; path: string }): Promise<Metadata>;
|
||||
/** Create a directory. Usable when not sandboxed */
|
||||
@@ -106,10 +140,17 @@ export type Effects = {
|
||||
removeFile(input: { volumeId: string; path: string }): Promise<void>;
|
||||
|
||||
/** Write a json file into an object. Usable when not sandboxed */
|
||||
writeJsonFile(input: { volumeId: string; path: string; toWrite: Record<string, unknown> }): Promise<void>;
|
||||
writeJsonFile(input: {
|
||||
volumeId: string;
|
||||
path: string;
|
||||
toWrite: Record<string, unknown>;
|
||||
}): Promise<void>;
|
||||
|
||||
/** Read a json file into an object */
|
||||
readJsonFile(input: { volumeId: string; path: string }): Promise<Record<string, unknown>>;
|
||||
readJsonFile(input: {
|
||||
volumeId: string;
|
||||
path: string;
|
||||
}): Promise<Record<string, unknown>>;
|
||||
|
||||
runCommand<A extends string>(
|
||||
command: ValidIfNoStupidEscape<A> | [string, ...string[]],
|
||||
@@ -121,7 +162,9 @@ export type Effects = {
|
||||
wait(): Promise<string>;
|
||||
term(): Promise<void>;
|
||||
};
|
||||
runDaemon<A extends string>(command: ValidIfNoStupidEscape<A> | [string, ...string[]]): DaemonReturned;
|
||||
runDaemon<A extends string>(
|
||||
command: ValidIfNoStupidEscape<A> | [string, ...string[]]
|
||||
): DaemonReturned;
|
||||
|
||||
/** Uses the chown on the system */
|
||||
chown(input: { volumeId: string; path: string; uid: string }): Promise<null>;
|
||||
@@ -151,7 +194,11 @@ export type Effects = {
|
||||
*/
|
||||
bindLan(options: { internalPort: number; name: string }): Promise<number>;
|
||||
/** Declaring that we are opening a interface on some protocal for tor network */
|
||||
bindTor(options: { internalPort: number; name: string; externalPort: number }): Promise<string>;
|
||||
bindTor(options: {
|
||||
internalPort: number;
|
||||
name: string;
|
||||
externalPort: number;
|
||||
}): Promise<string>;
|
||||
|
||||
/** 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.
|
||||
@@ -211,11 +258,17 @@ export type Effects = {
|
||||
getLocalHostname(): Promise<string>;
|
||||
getIPHostname(): Promise<string>;
|
||||
/** Get the address for another service for tor interfaces */
|
||||
getServiceTorHostname(interfaceId: string, packageId?: string): Promise<string>;
|
||||
getServiceTorHostname(
|
||||
interfaceId: string,
|
||||
packageId?: string
|
||||
): Promise<string>;
|
||||
/**
|
||||
* Get the port address for another service
|
||||
*/
|
||||
getServicePortForward(internalPort: number, packageId?: string): Promise<number>;
|
||||
getServicePortForward(
|
||||
internalPort: number,
|
||||
packageId?: string
|
||||
): Promise<number>;
|
||||
|
||||
/** When we want to create a link in the front end interfaces, and example is
|
||||
* exposing a url to view a web service
|
||||
@@ -285,13 +338,20 @@ export type Effects = {
|
||||
*
|
||||
* @returns PEM encoded fullchain (ecdsa)
|
||||
*/
|
||||
getSslCertificate: (packageId: string, algorithm?: "ecdsa" | "ed25519") => [string, string, string];
|
||||
getSslCertificate: (
|
||||
packageId: string,
|
||||
algorithm?: "ecdsa" | "ed25519"
|
||||
) => [string, string, string];
|
||||
/**
|
||||
* @returns PEM encoded ssl key (ecdsa)
|
||||
*/
|
||||
getSslKey: (packageId: string, algorithm?: "ecdsa" | "ed25519") => string;
|
||||
|
||||
setHealth(o: { name: string; status: HealthStatus; message?: string }): Promise<void>;
|
||||
setHealth(o: {
|
||||
name: string;
|
||||
status: HealthStatus;
|
||||
message?: string;
|
||||
}): Promise<void>;
|
||||
|
||||
/** Set the dependencies of what the service needs, usually ran during the set config as a best practice */
|
||||
setDependencies(dependencies: Dependencies): Promise<void>;
|
||||
@@ -429,4 +489,6 @@ export type Dependency = {
|
||||
};
|
||||
export type Dependencies = Array<Dependency>;
|
||||
|
||||
export type DeepPartial<T> = T extends {} ? { [P in keyof T]?: DeepPartial<T[P]> } : T;
|
||||
export type DeepPartial<T> = T extends {}
|
||||
? { [P in keyof T]?: DeepPartial<T[P]> }
|
||||
: T;
|
||||
|
||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "start-sdk",
|
||||
"version": "0.4.0-lib0.charlie22",
|
||||
"version": "0.4.0-lib0.charlie23",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "start-sdk",
|
||||
"version": "0.4.0-lib0.charlie22",
|
||||
"version": "0.4.0-lib0.charlie23",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@iarna/toml": "^2.2.5",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "start-sdk",
|
||||
"version": "0.4.0-lib0.charlie22",
|
||||
"version": "0.4.0-lib0.charlie23",
|
||||
"description": "For making the patterns that are wanted in making services for the startOS.",
|
||||
"main": "./lib/index.js",
|
||||
"types": "./lib/index.d.ts",
|
||||
|
||||
Reference in New Issue
Block a user