update sdk

This commit is contained in:
Matt Hill
2024-03-18 12:37:50 -06:00
parent a4cb2708cc
commit a02b531e47
12 changed files with 113 additions and 71 deletions

View File

@@ -1,4 +1,21 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { ExposedUI } from "./ExposedUI"; import type { ExposedUI } from "./ExposedUI";
export interface ExposeUiParams { paths: Array<ExposedUI>, } export type ExposeUiParams =
| {
type: "object";
value: { [k: string]: ExposeUiParams };
}
| {
type: "string";
/** The path to the value in the Store. [JsonPath](https://jsonpath.com/) */
path: string;
/** A human readable description or explanation of the value */
description: string | null;
/** (string/number only) Whether or not to mask the value, for example, when displaying a password */
masked: boolean;
/** (string/number only) Whether or not to include a button for copying the value to clipboard */
copyable: boolean | null;
/** (string/number only) Whether or not to include a button for displaying the value as a QR code */
qr: boolean | null;
};

View File

@@ -691,9 +691,19 @@ async fn expose_for_dependents(
} }
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, TS)] #[derive(Debug, Clone, serde::Serialize, serde::Deserialize, TS)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
#[serde(tag = "type")]
#[ts(export)] #[ts(export)]
struct ExposeUiParams { enum ExposeUiParams {
paths: Vec<ExposedUI>, Object {
value: Record<String, ExposeUiParams>,
},
r#String {
path: String,
description: Option<String>,
masked: bool,
copyable: Option<bool>,
qr: Option<bool>,
},
} }
async fn expose_ui( async fn expose_ui(

View File

@@ -54,6 +54,7 @@ import {
} from "./interfaces/setupInterfaces" } from "./interfaces/setupInterfaces"
import { successFailure } from "./trigger/successFailure" import { successFailure } from "./trigger/successFailure"
import { SetupExports } from "./inits/setupExports" import { SetupExports } from "./inits/setupExports"
import { HealthReceipt } from "./health/HealthReceipt"
// prettier-ignore // prettier-ignore
type AnyNeverCond<T extends any[], Then, Else> = type AnyNeverCond<T extends any[], Then, Else> =
@@ -234,7 +235,15 @@ export class StartSdk<Manifest extends SDKManifest, Store> {
spec: Spec, spec: Spec,
) => Config.of<Spec, Store>(spec), ) => Config.of<Spec, Store>(spec),
}, },
Daemons: { of: Daemons.of }, Daemons: {
of(config: {
effects: Effects
started: (onTerm: () => PromiseLike<void>) => PromiseLike<void>
healthReceipts: HealthReceipt[]
}) {
return Daemons.of<Manifest>(config)
},
},
DependencyConfig: { DependencyConfig: {
of< of<
LocalConfig extends Record<string, any>, LocalConfig extends Record<string, any>,

View File

@@ -42,7 +42,7 @@ export class Backups<M extends SDKManifest> {
private constructor( private constructor(
private options = DEFAULT_OPTIONS, private options = DEFAULT_OPTIONS,
private backupSet = [] as BackupSet<M["volumes"][0]>[], private backupSet = [] as BackupSet<M["volumes"][number]>[],
) {} ) {}
static volumes<M extends SDKManifest = never>( static volumes<M extends SDKManifest = never>(
...volumeNames: Array<M["volumes"][0]> ...volumeNames: Array<M["volumes"][0]>

View File

@@ -4,7 +4,7 @@ import { ExpectedExports } from "../types"
import { _ } from "../util" import { _ } from "../util"
export type SetupBackupsParams<M extends SDKManifest> = Array< export type SetupBackupsParams<M extends SDKManifest> = Array<
M["volumes"][0] | Backups<M> M["volumes"][number] | Backups<M>
> >
export function setupBackups<M extends SDKManifest>( export function setupBackups<M extends SDKManifest>(

View File

@@ -4,6 +4,7 @@ export { Overlay } from "./util/Overlay"
export { Utils } from "./util/utils" export { Utils } from "./util/utils"
export { StartSdk } from "./StartSdk" export { StartSdk } from "./StartSdk"
export { setupManifest } from "./manifest/setupManifest" export { setupManifest } from "./manifest/setupManifest"
export { FileHelper } from "./util/fileHelper"
export * as actions from "./actions" export * as actions from "./actions"
export * as backup from "./backup" export * as backup from "./backup"
export * as config from "./config" export * as config from "./config"

View File

@@ -6,11 +6,11 @@ export type SetupExports<Store> = (opts: {
utils: Utils<any, Store> utils: Utils<any, Store>
}) => }) =>
| { | {
ui: ExposeUiPaths<Store> ui: { [k: string]: ExposeUiPaths<Store> }
services: ExposeServicePaths<Store> services: ExposeServicePaths<Store>
} }
| Promise<{ | Promise<{
ui: ExposeUiPaths<Store> ui: { [k: string]: ExposeUiPaths<Store> }
services: ExposeServicePaths<Store> services: ExposeServicePaths<Store>
}> }>

View File

@@ -1,6 +1,6 @@
import { SetInterfaces } from "../interfaces/setupInterfaces" import { SetInterfaces } from "../interfaces/setupInterfaces"
import { SDKManifest } from "../manifest/ManifestTypes" import { SDKManifest } from "../manifest/ManifestTypes"
import { ExpectedExports } from "../types" import { ExpectedExports, ExposeUiPaths, ExposeUiPathsAll } from "../types"
import { createUtils } from "../util" import { createUtils } from "../util"
import { Migrations } from "./migrations/setupMigrations" import { Migrations } from "./migrations/setupMigrations"
import { SetupExports } from "./setupExports" import { SetupExports } from "./setupExports"
@@ -32,14 +32,12 @@ export function setupInit<Manifest extends SDKManifest, Store>(
utils, utils,
}) })
await opts.effects.exposeForDependents(services) await opts.effects.exposeForDependents(services)
await opts.effects.exposeUi({ await opts.effects.exposeUi(
paths: ui.map((x) => ({ forExpose({
description: null, type: "object",
copyable: null, value: ui,
qr: null, }),
...x, )
})),
})
}, },
uninit: async (opts) => { uninit: async (opts) => {
await migrations.uninit(opts) await migrations.uninit(opts)
@@ -47,3 +45,21 @@ export function setupInit<Manifest extends SDKManifest, Store>(
}, },
} }
} }
function forExpose<Store>(ui: ExposeUiPaths<Store>): ExposeUiPathsAll {
if (ui.type === ("object" as const)) {
return {
type: "object" as const,
value: Object.fromEntries(
Object.entries(ui.value).map(([key, value]) => [key, forExpose(value)]),
),
}
}
return {
description: null,
copyable: null,
qr: null,
...ui,
}
}

View File

@@ -82,15 +82,15 @@ type NotProtocolsWithSslVariants = Exclude<
type BindOptionsByKnownProtocol = type BindOptionsByKnownProtocol =
| { | {
protocol: ProtocolsWithSslVariants protocol: ProtocolsWithSslVariants
preferredExternalPort: number | null preferredExternalPort?: number
scheme: Scheme | null scheme?: Scheme
addSsl: Partial<AddSslOptions> | null addSsl?: Partial<AddSslOptions>
} }
| { | {
protocol: NotProtocolsWithSslVariants protocol: NotProtocolsWithSslVariants
preferredExternalPort: number | null preferredExternalPort?: number
scheme: Scheme | null scheme?: Scheme
addSsl: AddSslOptions | null addSsl?: AddSslOptions
} }
type BindOptionsByProtocol = BindOptionsByKnownProtocol | BindOptions type BindOptionsByProtocol = BindOptionsByKnownProtocol | BindOptions

View File

@@ -9,9 +9,6 @@ describe("host", () => {
const foo = utils.host.multi("foo") const foo = utils.host.multi("foo")
const fooOrigin = await foo.bindPort(80, { const fooOrigin = await foo.bindPort(80, {
protocol: "http" as const, protocol: "http" as const,
scheme: null,
addSsl: null,
preferredExternalPort: null,
}) })
const fooInterface = new ServiceInterfaceBuilder({ const fooInterface = new ServiceInterfaceBuilder({
effects, effects,

View File

@@ -261,22 +261,42 @@ export type ExposeServicePaths<Store = never> = {
paths: Store extends never ? string[] : ExposeAllServicePaths<Store>[] paths: Store extends never ? string[] : ExposeAllServicePaths<Store>[]
} }
export type ExposeUiPaths<Store> = Array<{ export type ExposeUiPaths<Store> =
/** The path to the value in the Store. [JsonPath](https://jsonpath.com/) */ | {
path: ExposeAllUiPaths<Store> type: "object"
/** A human readable title for the value */ value: { [k: string]: ExposeUiPaths<Store> }
title: string }
/** A human readable description or explanation of the value */ | {
description?: string type: "string"
/** (string/number only) Whether or not to mask the value, for example, when displaying a password */ /** The path to the value in the Store. [JsonPath](https://jsonpath.com/) */
masked: boolean path: ExposeAllUiPaths<Store>
/** (string/number only) Whether or not to include a button for copying the value to clipboard */ /** A human readable description or explanation of the value */
copyable?: boolean description?: string
/** (string/number only) Whether or not to include a button for displaying the value as a QR code */ /** (string/number only) Whether or not to mask the value, for example, when displaying a password */
qr?: boolean masked: boolean
}> /** (string/number only) Whether or not to include a button for copying the value to clipboard */
copyable?: boolean
type tset = keyof Effects /** (string/number only) Whether or not to include a button for displaying the value as a QR code */
qr?: boolean
}
export type ExposeUiPathsAll =
| {
type: "object"
value: { [k: string]: ExposeUiPathsAll }
}
| {
type: "string"
/** The path to the value in the Store. [JsonPath](https://jsonpath.com/) */
path: string
/** A human readable description or explanation of the value */
description: string | null
/** (string/number only) Whether or not to mask the value, for example, when displaying a password */
masked: boolean
/** (string/number only) Whether or not to include a button for copying the value to clipboard */
copyable: boolean | null
/** (string/number only) Whether or not to include a button for displaying the value as a QR code */
qr: boolean | null
}
/** Used to reach out from the pure js runtime */ /** Used to reach out from the pure js runtime */
export type Effects = { export type Effects = {
@@ -375,16 +395,7 @@ export type Effects = {
exposeForDependents(options: { paths: string[] }): Promise<void> exposeForDependents(options: { paths: string[] }): Promise<void>
exposeUi<Store = never>(options: { exposeUi(options: ExposeUiPathsAll): Promise<void>
paths: {
path: string
title: string | null
description: string | null
masked: boolean | null
copyable: boolean | null
qr: boolean | null
}[]
}): Promise<void>
/** /**
* There are times that we want to see the addresses that where exported * There are times that we want to see the addresses that where exported
* @param options.addressId If we want to filter the address id * @param options.addressId If we want to filter the address id

View File

@@ -56,23 +56,6 @@ export type Utils<
Store, Store,
WrapperOverWrite = { const: never }, WrapperOverWrite = { const: never },
> = { > = {
checkPortListening(
port: number,
options: {
errorMessage: string
successMessage: string
timeoutMessage?: string
timeout?: number
},
): Promise<CheckResult>
checkWebUrl(
url: string,
options?: {
timeout?: number
successMessage?: string
errorMessage?: string
},
): Promise<CheckResult>
childProcess: typeof childProcess childProcess: typeof childProcess
createInterface: (options: { createInterface: (options: {
name: string name: string
@@ -304,8 +287,6 @@ export const createUtils = <
}, },
} }
}, },
checkPortListening: checkPortListening.bind(null, effects),
checkWebUrl: checkWebUrl.bind(null, effects),
mountDependencies: < mountDependencies: <
In extends In extends