add callback for getContainerIp (#2851)

* add callback for getContainerIp

* register callback before retrieving info

* version bump; only use backports for linux
This commit is contained in:
Aiden McClelland
2025-03-20 15:54:05 -06:00
committed by GitHub
parent 05162ca350
commit 9e63f3f7c6
69 changed files with 592 additions and 262 deletions

View File

@@ -72,7 +72,7 @@ import * as actions from "../../base/lib/actions"
import { setupInit } from "./inits/setupInit"
import * as fs from "node:fs/promises"
export const OSVersion = testTypeVersion("0.3.6-alpha.16")
export const OSVersion = testTypeVersion("0.3.6-alpha.17")
// prettier-ignore
type AnyNeverCond<T extends any[], Then, Else> =
@@ -104,7 +104,10 @@ export class StartSdk<Manifest extends T.SDKManifest, Store> {
| "getHostInfo"
type MainUsedEffects = "setMainStatus" | "setHealth"
type CallbackEffects = "constRetry" | "clearCallbacks"
type AlreadyExposed = "getSslCertificate" | "getSystemSmtp"
type AlreadyExposed =
| "getSslCertificate"
| "getSystemSmtp"
| "getContainerIp"
// prettier-ignore
type StartSdkEffectWrapper = {
@@ -123,7 +126,6 @@ export class StartSdk<Manifest extends T.SDKManifest, Store> {
getServicePortForward: (effects, ...args) =>
effects.getServicePortForward(...args),
clearBindings: (effects, ...args) => effects.clearBindings(...args),
getContainerIp: (effects, ...args) => effects.getContainerIp(...args),
getOsIp: (effects, ...args) => effects.getOsIp(...args),
getSslKey: (effects, ...args) => effects.getSslKey(...args),
setDataVersion: (effects, ...args) => effects.setDataVersion(...args),
@@ -191,7 +193,61 @@ export class StartSdk<Manifest extends T.SDKManifest, Store> {
opts: { packageId: PackageId },
) => getServiceInterfaces(effects, opts),
},
getContainerIp: (
effects: T.Effects,
options: Omit<
Parameters<T.Effects["getContainerIp"]>[0],
"callback"
> = {},
) => {
async function* watch() {
while (true) {
let callback: () => void = () => {}
const waitForNext = new Promise<void>((resolve) => {
callback = resolve
})
yield await effects.getContainerIp({ ...options, callback })
await waitForNext
}
}
return {
const: () =>
effects.getContainerIp({
...options,
callback:
effects.constRetry &&
(() => effects.constRetry && effects.constRetry()),
}),
once: () => effects.getContainerIp(options),
watch,
onChange: (
callback: (
value: string | null,
error?: Error,
) => void | Promise<void>,
) => {
;(async () => {
for await (const value of watch()) {
try {
await callback(value)
} catch (e) {
console.error(
"callback function threw an error @ getContainerIp.onChange",
e,
)
}
}
})()
.catch((e) => callback(null, e))
.catch((e) =>
console.error(
"callback function threw an error @ getContainerIp.onChange",
e,
),
)
},
}
},
store: {
get: <E extends Effects, StoreValue = unknown>(
effects: E,

View File

@@ -1,12 +1,12 @@
{
"name": "@start9labs/start-sdk",
"version": "0.3.6-beta.18",
"version": "0.3.6-beta.19",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@start9labs/start-sdk",
"version": "0.3.6-beta.18",
"version": "0.3.6-beta.19",
"license": "MIT",
"dependencies": {
"@iarna/toml": "^2.2.5",

View File

@@ -1,6 +1,6 @@
{
"name": "@start9labs/start-sdk",
"version": "0.3.6-beta.18",
"version": "0.3.6-beta.19",
"description": "Software development kit to facilitate packaging services for StartOS",
"main": "./package/lib/index.js",
"types": "./package/lib/index.d.ts",