From 2e216b2c6f10c5eb1d632e2740e0ad5a0705b12c Mon Sep 17 00:00:00 2001 From: BluJ Date: Mon, 17 Apr 2023 13:40:07 -0600 Subject: [PATCH] chore: charlie23 --- lib/config/index.ts | 2 +- lib/config/setupConfigExports.ts | 22 +++++-- lib/mainFn/NetworkBuilder.ts | 2 +- lib/types.ts | 106 ++++++++++++++++++++++++------- package-lock.json | 4 +- package.json | 2 +- 6 files changed, 107 insertions(+), 31 deletions(-) diff --git a/lib/config/index.ts b/lib/config/index.ts index a54b7de..5aa1a25 100644 --- a/lib/config/index.ts +++ b/lib/config/index.ts @@ -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"; diff --git a/lib/config/setupConfigExports.ts b/lib/config/setupConfigExports.ts index 7347b18..dce48c2 100644 --- a/lib/config/setupConfigExports.ts +++ b/lib/config/setupConfigExports.ts @@ -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(options: { spec: Config; - write(options: { effects: Effects; input: TypeFromProps }): Promise<[ConfigType, Dependencies]>; - read(options: { effects: Effects; config: ConfigType }): Promise>>; + write(options: { + effects: Effects; + input: TypeFromProps; + }): Promise<[ConfigType, Dependencies]>; + read(options: { + effects: Effects; + config: ConfigType; + }): Promise>>; }) { const validator = options.spec.validator(); return { @@ -31,7 +43,9 @@ export function setupConfigExports(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, }; diff --git a/lib/mainFn/NetworkBuilder.ts b/lib/mainFn/NetworkBuilder.ts index d8fa424..4edbdac 100644 --- a/lib/mainFn/NetworkBuilder.ts +++ b/lib/mainFn/NetworkBuilder.ts @@ -14,4 +14,4 @@ export class NetworkBuilder { getPort(id: string) { return new LocalPort(this.effects, id); } -} \ No newline at end of file +} diff --git a/lib/types.ts b/lib/types.ts index 72c758a..66fc6b2 100644 --- a/lib/types.ts +++ b/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 }) => Promise; + export type setConfig = (options: { + effects: Effects; + input: Record; + }) => Promise; /** 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; + export type getConfig = (options: { + effects: Effects; + config: unknown; + }) => Promise; // /** 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; + export type createBackup = (options: { + effects: Effects; + }) => Promise; /** 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; + export type restoreBackup = (options: { + effects: Effects; + }) => Promise; /** 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; + export type properties = (options: { + effects: Effects; + }) => Promise; // /** 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 }) => Promise; + [id: string]: (options: { + effects: Effects; + input?: Record; + }) => Promise; }; /** * 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; + export type main = (options: { + effects: Effects; + started(onTerm: () => void): null; + }) => Promise; /** * 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; + export type afterShutdown = (options: { + effects: Effects; + }) => Promise; /** * 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; + export type init = (options: { + effects: Effects; + previousVersion: null | string; + }) => Promise; /** 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; + export type uninit = (options: { + effects: Effects; + nextVersion: null | string; + }) => Promise; } export type TimeMs = number; export type VersionString = string; -export type ValidIfNoStupidEscape = A extends `${string}'"'"'${string}` | `${string}\\"${string}` +export type ValidIfNoStupidEscape = 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 = ValidIfNoStupidEscape | [string, ...string[]]; +export type CommandType = + | ValidIfNoStupidEscape + | [string, ...string[]]; export type DaemonReturned = { wait(): Promise; @@ -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; + writeFile(input: { + path: string; + volumeId: string; + toWrite: string; + }): Promise; readFile(input: { volumeId: string; path: string }): Promise; metadata(input: { volumeId: string; path: string }): Promise; /** Create a directory. Usable when not sandboxed */ @@ -106,10 +140,17 @@ export type Effects = { removeFile(input: { volumeId: string; path: string }): Promise; /** Write a json file into an object. Usable when not sandboxed */ - writeJsonFile(input: { volumeId: string; path: string; toWrite: Record }): Promise; + writeJsonFile(input: { + volumeId: string; + path: string; + toWrite: Record; + }): Promise; /** Read a json file into an object */ - readJsonFile(input: { volumeId: string; path: string }): Promise>; + readJsonFile(input: { + volumeId: string; + path: string; + }): Promise>; runCommand( command: ValidIfNoStupidEscape | [string, ...string[]], @@ -121,7 +162,9 @@ export type Effects = { wait(): Promise; term(): Promise; }; - runDaemon(command: ValidIfNoStupidEscape | [string, ...string[]]): DaemonReturned; + runDaemon( + command: ValidIfNoStupidEscape | [string, ...string[]] + ): DaemonReturned; /** Uses the chown on the system */ chown(input: { volumeId: string; path: string; uid: string }): Promise; @@ -151,7 +194,11 @@ export type Effects = { */ bindLan(options: { internalPort: number; name: string }): Promise; /** Declaring that we are opening a interface on some protocal for tor network */ - bindTor(options: { internalPort: number; name: string; externalPort: number }): Promise; + bindTor(options: { + internalPort: number; + name: string; + externalPort: number; + }): Promise; /** 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; getIPHostname(): Promise; /** Get the address for another service for tor interfaces */ - getServiceTorHostname(interfaceId: string, packageId?: string): Promise; + getServiceTorHostname( + interfaceId: string, + packageId?: string + ): Promise; /** * Get the port address for another service */ - getServicePortForward(internalPort: number, packageId?: string): Promise; + getServicePortForward( + internalPort: number, + packageId?: string + ): Promise; /** 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; + setHealth(o: { + name: string; + status: HealthStatus; + message?: string; + }): Promise; /** Set the dependencies of what the service needs, usually ran during the set config as a best practice */ setDependencies(dependencies: Dependencies): Promise; @@ -429,4 +489,6 @@ export type Dependency = { }; export type Dependencies = Array; -export type DeepPartial = T extends {} ? { [P in keyof T]?: DeepPartial } : T; +export type DeepPartial = T extends {} + ? { [P in keyof T]?: DeepPartial } + : T; diff --git a/package-lock.json b/package-lock.json index c2a2c04..f11af0e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index 4683089..1b4bcfe 100644 --- a/package.json +++ b/package.json @@ -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",