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.
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)]
#[serde(rename_all = "camelCase")]
#[serde(tag = "type")]
#[ts(export)]
struct ExposeUiParams {
paths: Vec<ExposedUI>,
enum ExposeUiParams {
Object {
value: Record<String, ExposeUiParams>,
},
r#String {
path: String,
description: Option<String>,
masked: bool,
copyable: Option<bool>,
qr: Option<bool>,
},
}
async fn expose_ui(

View File

@@ -54,6 +54,7 @@ import {
} from "./interfaces/setupInterfaces"
import { successFailure } from "./trigger/successFailure"
import { SetupExports } from "./inits/setupExports"
import { HealthReceipt } from "./health/HealthReceipt"
// prettier-ignore
type AnyNeverCond<T extends any[], Then, Else> =
@@ -234,7 +235,15 @@ export class StartSdk<Manifest extends SDKManifest, Store> {
spec: 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: {
of<
LocalConfig extends Record<string, any>,

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,6 +1,6 @@
import { SetInterfaces } from "../interfaces/setupInterfaces"
import { SDKManifest } from "../manifest/ManifestTypes"
import { ExpectedExports } from "../types"
import { ExpectedExports, ExposeUiPaths, ExposeUiPathsAll } from "../types"
import { createUtils } from "../util"
import { Migrations } from "./migrations/setupMigrations"
import { SetupExports } from "./setupExports"
@@ -32,14 +32,12 @@ export function setupInit<Manifest extends SDKManifest, Store>(
utils,
})
await opts.effects.exposeForDependents(services)
await opts.effects.exposeUi({
paths: ui.map((x) => ({
description: null,
copyable: null,
qr: null,
...x,
})),
})
await opts.effects.exposeUi(
forExpose({
type: "object",
value: ui,
}),
)
},
uninit: async (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 =
| {
protocol: ProtocolsWithSslVariants
preferredExternalPort: number | null
scheme: Scheme | null
addSsl: Partial<AddSslOptions> | null
preferredExternalPort?: number
scheme?: Scheme
addSsl?: Partial<AddSslOptions>
}
| {
protocol: NotProtocolsWithSslVariants
preferredExternalPort: number | null
scheme: Scheme | null
addSsl: AddSslOptions | null
preferredExternalPort?: number
scheme?: Scheme
addSsl?: AddSslOptions
}
type BindOptionsByProtocol = BindOptionsByKnownProtocol | BindOptions

View File

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

View File

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

View File

@@ -56,23 +56,6 @@ export type Utils<
Store,
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
createInterface: (options: {
name: string
@@ -304,8 +287,6 @@ export const createUtils = <
},
}
},
checkPortListening: checkPortListening.bind(null, effects),
checkWebUrl: checkWebUrl.bind(null, effects),
mountDependencies: <
In extends