Skip to content

Commit

Permalink
WIP, update comments
Browse files Browse the repository at this point in the history
  • Loading branch information
MattDHill committed Nov 24, 2024
1 parent c35dd9e commit 358233e
Show file tree
Hide file tree
Showing 10 changed files with 165 additions and 126 deletions.
1 change: 0 additions & 1 deletion sdk/base/lib/Effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
Host,
ExportServiceInterfaceParams,
ServiceInterface,
ActionRequest,
RequestActionParams,
MainStatus,
} from "./osBindings"
Expand Down
229 changes: 144 additions & 85 deletions sdk/package/lib/StartSdk.ts

Large diffs are not rendered by default.

23 changes: 1 addition & 22 deletions sdk/package/lib/backup/Backups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,7 @@ export type BackupSync<Volumes extends string> = {
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.SDKManifest> {
private constructor(
private options = DEFAULT_OPTIONS,
Expand Down
3 changes: 1 addition & 2 deletions sdk/package/lib/health/checkFns/checkPortListening.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Effects } from "../../../../base/lib/types"
import { stringFromStdErrOut } from "../../util"
import { HealthCheckResult } from "./HealthCheckResult"

import { promisify } from "node:util"
import * as CP from "node:child_process"

const cpExec = promisify(CP.exec)
const cpExecFile = promisify(CP.execFile)

export function containsAddress(x: string, port: number) {
const readPorts = x
.split("\n")
Expand Down
4 changes: 1 addition & 3 deletions sdk/package/lib/mainFn/CommandController.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { DEFAULT_SIGTERM_TIMEOUT } from "."
import { NO_TIMEOUT, SIGKILL, SIGTERM } from "../../../base/lib/types"
import { NO_TIMEOUT, SIGTERM } from "../../../base/lib/types"

import * as T from "../../../base/lib/types"
import { asError } from "../../../base/lib/util/asError"
import {
ExecSpawnable,
MountOptions,
SubContainerHandle,
SubContainer,
Expand Down
1 change: 0 additions & 1 deletion sdk/package/lib/manifest/setupManifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { execSync } from "child_process"
/**
* @description Use this function to define critical information about your package
*
* @param versions Every version of the package, imported from ./versions
* @param manifest Static properties of the package
*/
export function setupManifest<
Expand Down
1 change: 0 additions & 1 deletion sdk/package/lib/store/setupExposeStore.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ExposedStorePaths } from "../../../base/lib/types"
import { Affine, _ } from "../util"
import {
PathBuilder,
extractJsonPath,
Expand Down
1 change: 0 additions & 1 deletion sdk/package/lib/trigger/defaultTrigger.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { cooldownTrigger } from "./cooldownTrigger"
import { changeOnFirstSuccess } from "./changeOnFirstSuccess"
import { successFailure } from "./successFailure"

export const defaultTrigger = changeOnFirstSuccess({
beforeFirstSuccess: cooldownTrigger(1000),
Expand Down
3 changes: 2 additions & 1 deletion sdk/package/lib/util/SubContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import * as cp from "child_process"
import { promisify } from "util"
import { Buffer } from "node:buffer"
import { once } from "../../../base/lib/util/once"

export const execFile = promisify(cp.execFile)
const WORKDIR = (imageId: string) => `/media/startos/images/${imageId}/`
const False = () => false

type ExecResults = {
exitCode: number | null
exitSignal: NodeJS.Signals | null
Expand Down
25 changes: 16 additions & 9 deletions sdk/package/lib/util/fileHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,34 @@ async function onCreated(path: string) {
/**
* @description Use this class to read/write an underlying configuration file belonging to the upstream service.
*
* Using the static functions, choose between officially supported file formats (json, yaml, toml), or a custom format (raw).
* These type definitions should reflect the underlying file as closely as possible. For example, if the service does not require a particular value, it should be marked as optional(), even if your package requires it.
*
* It is recommended to use onMismatch() whenever possible. This provides an escape hatch in case the user edits the file manually and accidentally sets a value to an unsupported type.
*
* Officially supported file types are json, yaml, and toml. Other files types can use "raw"
*
* Choose between officially supported file formats (), or a custom format (raw).
*
* @example
* Below are a few examples
*
* ```
* import { matches, FileHelper } from '@start9labs/start-sdk'
* const { arrayOf, boolean, literal, literals, object, oneOf, natural, string } = matches
* const { arrayOf, boolean, literal, literals, object, natural, string } = matches
*
* export const jsonFile = FileHelper.json('./inputSpec.json', object({
* passwords: arrayOf(string)
* type: oneOf(literals('private', 'public'))
* passwords: arrayOf(string).onMismatch([])
* type: literals('private', 'public').optional().onMismatch(undefined)
* }))
*
* export const tomlFile = FileHelper.toml('./inputSpec.toml', object({
* url: literal('https://start9.com')
* public: boolean
* url: literal('https://start9.com').onMismatch('https://start9.com')
* public: boolean.onMismatch(true)
* }))
*
* export const yamlFile = FileHelper.yaml('./inputSpec.yml', object({
* name: string
* age: natural
* name: string.optional().onMismatch(undefined)
* age: natural.optional().onMismatch(undefined)
* }))
*
* export const bitcoinConfFile = FileHelper.raw(
Expand Down Expand Up @@ -183,7 +190,7 @@ export class FileHelper<A> {

/**
* We wanted to be able to have a fileHelper, and just modify the path later in time.
* Like one behaviour of another dependency or something similar.
* Like one behavior of another dependency or something similar.
*/
withPath(path: string) {
return new FileHelper<A>(path, this.writeData, this.readData, this.validate)
Expand Down

0 comments on commit 358233e

Please sign in to comment.