update/alpha.9 (#2988)

* import marketplac preview for sideload

* fix: improve state service (#2977)

* fix: fix sideload DI

* fix: update Angular

* fix: cleanup

* fix: fix version selection

* Bump node version to fix build for Angular

* misc fixes
- update node to v22
- fix chroot-and-upgrade access to prune-images
- don't self-migrate legacy packages
- #2985
- move dataVersion to volume folder
- remove "instructions.md" from s9pk
- add "docsUrl" to manifest

* version bump

* include flavor when clicking view listing from updates tab

* closes #2980

* fix: fix select button

* bring back ssh keys

* fix: drop 'portal' from all routes

* fix: implement longtap action to select table rows

* fix description for ssh page

* replace instructions with docsLink and refactor marketplace preview

* delete unused translations

* fix patchdb diffing algorithm

* continue refactor of marketplace lib show components

* Booting StartOS instead of Setting up your server on init

* misc fixes
- closes #2990
- closes #2987

* fix build

* docsUrl and clickable service headers

* don't cleanup after update until new service install succeeds

* update types

* misc fixes

* beta.35

* sdkversion, githash for sideload, correct logs for init, startos pubkey display

* bring back reboot button on install

* misc fixes

* beta.36

* better handling of setup and init for websocket errors

* reopen init and setup logs even on graceful closure

* better logging, misc fixes

* fix build

* dont let package stats hang

* dont show docsurl in marketplace if no docsurl

* re-add needs-config

* show error if init fails, shorten hover state on header icons

* fix operator precedemce

---------

Co-authored-by: Matt Hill <mattnine@protonmail.com>
Co-authored-by: Alex Inkin <alexander@inkin.ru>
Co-authored-by: Mariusz Kogen <k0gen@pm.me>
This commit is contained in:
Aiden McClelland
2025-07-18 18:31:12 +00:00
committed by GitHub
parent ba2906a42e
commit 377b7b12ce
237 changed files with 5953 additions and 4777 deletions

153
sdk/base/lib/util/Drop.ts Normal file
View File

@@ -0,0 +1,153 @@
const dropId: unique symbol = Symbol("id")
export type DropRef = { [dropId]: number }
export abstract class Drop {
private static weak: { [id: number]: Drop } = {}
private static registry = new FinalizationRegistry((id: number) => {
const weak = Drop.weak[id]
if (weak) weak.drop()
})
private static idCtr: number = 0
private dropId?: number
private dropRef?: DropRef | WeakRef<DropRef>
protected constructor() {
this.dropId = Drop.idCtr++
this.dropRef = { [dropId]: this.dropId }
const weak = this.weak()
Drop.weak[this.dropId] = weak
Drop.registry.register(this.dropRef, this.dropId, this.dropRef)
return new Proxy(this, {
set(target: any, prop, value) {
if (prop === "dropRef" || prop == "dropId") return false
target[prop] = value
;(weak as any)[prop] = value
return true
},
})
}
protected register() {}
private weak(): this {
const weak = Object.assign(Object.create(Object.getPrototypeOf(this)), this)
if (this.dropRef) weak.ref = new WeakRef(this.dropRef)
return weak
}
abstract onDrop(): void
drop(): void {
if (!this.dropRef || !this.dropId) return
this.onDrop()
this.leak()
}
leak(): this {
if (!this.dropRef || !this.dropId) return this
Drop.registry.unregister(this.dropRef)
delete Drop.weak[this.dropId]
delete this.dropRef
delete this.dropId
return this
}
}
export class DropPromise<T> implements Promise<T> {
private static dropFns: { [id: number]: () => void } = {}
private static registry = new FinalizationRegistry((id: number) => {
const drop = DropPromise.dropFns[id]
if (drop) {
drop()
delete DropPromise.dropFns[id]
}
})
private static idCtr: number = 0
private dropId: number
private dropRef: DropRef;
[Symbol.toStringTag] = "DropPromise"
private constructor(
private readonly promise: Promise<T>,
dropFnOrRef?: (() => void) | DropRef,
) {
if (dropFnOrRef && dropId in dropFnOrRef) {
this.dropId = dropFnOrRef[dropId]
this.dropRef = dropFnOrRef
return
}
this.dropId = DropPromise.idCtr++
this.dropRef = { [dropId]: this.dropId }
if (dropFnOrRef) DropPromise.dropFns[this.dropId] = dropFnOrRef
DropPromise.registry.register(this.dropRef, this.dropId, this.dropRef)
}
static of<T>(promise: Promise<T>, dropFn?: () => void): DropPromise<T> {
return new DropPromise(promise, dropFn)
}
static ref<T>(promise: Promise<T>, dropRef: DropRef): DropPromise<T> {
return new DropPromise(promise, dropRef)
}
then<TResult1 = T, TResult2 = never>(
onfulfilled?:
| ((value: T) => TResult1 | PromiseLike<TResult1>)
| null
| undefined,
onrejected?:
| ((reason: any) => TResult2 | PromiseLike<TResult2>)
| null
| undefined,
): Promise<TResult1 | TResult2> {
return DropPromise.ref(
this.promise.then(onfulfilled, onrejected),
this.dropRef,
)
}
catch<TResult = never>(
onrejected?:
| ((reason: any) => TResult | PromiseLike<TResult>)
| null
| undefined,
): Promise<T | TResult> {
return DropPromise.ref(this.promise.catch(onrejected), this.dropRef)
}
finally(onfinally?: (() => void) | null | undefined): Promise<T> {
return DropPromise.ref(this.promise.finally(onfinally), this.dropRef)
}
}
export class DropGenerator<T = unknown, TReturn = any, TNext = unknown>
implements AsyncGenerator<T, TReturn, TNext>
{
private static dropFns: { [id: number]: () => void } = {}
private static registry = new FinalizationRegistry((id: number) => {
const drop = DropGenerator.dropFns[id]
if (drop) {
drop()
delete DropGenerator.dropFns[id]
}
})
private static idCtr: number = 0
private dropId: number
private dropRef: DropRef;
[Symbol.asyncIterator] = () => this
private constructor(
private readonly generator: AsyncGenerator<T, TReturn, TNext>,
dropFn?: () => void,
) {
this.dropId = DropGenerator.idCtr++
this.dropRef = { [dropId]: this.dropId }
if (dropFn) DropGenerator.dropFns[this.dropId] = dropFn
DropGenerator.registry.register(this.dropRef, this.dropId, this.dropRef)
}
static of<T, TReturn, TNext>(
generator: AsyncGenerator<T, TReturn, TNext>,
dropFn?: () => void,
): DropGenerator<T, TReturn, TNext> {
return new DropGenerator(generator, dropFn)
}
next(...args: [] | [TNext]): Promise<IteratorResult<T, TReturn>> {
return DropPromise.ref(this.generator.next(...args), this.dropRef)
}
return(
value: TReturn | PromiseLike<TReturn>,
): Promise<IteratorResult<T, TReturn>> {
return DropPromise.ref(this.generator.return(value), this.dropRef)
}
throw(e: any): Promise<IteratorResult<T, TReturn>> {
return DropPromise.ref(this.generator.throw(e), this.dropRef)
}
}

View File

@@ -1,5 +1,6 @@
import { Effects } from "../Effects"
import * as T from "../types"
import { DropGenerator, DropPromise } from "./Drop"
export class GetSystemSmtp {
constructor(readonly effects: Effects) {}
@@ -21,15 +22,13 @@ export class GetSystemSmtp {
return this.effects.getSystemSmtp({})
}
/**
* Watches the system SMTP credentials. Returns an async iterator that yields whenever the value changes
*/
async *watch() {
private async *watchGen(abort?: AbortSignal) {
const resolveCell = { resolve: () => {} }
this.effects.onLeaveContext(() => {
resolveCell.resolve()
})
while (this.effects.isInContext) {
abort?.addEventListener("abort", () => resolveCell.resolve())
while (this.effects.isInContext && !abort?.aborted) {
let callback: () => void = () => {}
const waitForNext = new Promise<void>((resolve) => {
callback = resolve
@@ -42,6 +41,17 @@ export class GetSystemSmtp {
}
}
/**
* Watches the system SMTP credentials. Returns an async iterator that yields whenever the value changes
*/
watch(
abort?: AbortSignal,
): AsyncGenerator<T.SmtpValue | null, void, unknown> {
const ctrl = new AbortController()
abort?.addEventListener("abort", () => ctrl.abort())
return DropGenerator.of(this.watchGen(ctrl.signal), () => ctrl.abort())
}
/**
* Watches the system SMTP credentials. Takes a custom callback function to run whenever the credentials change
*/
@@ -49,12 +59,17 @@ export class GetSystemSmtp {
callback: (
value: T.SmtpValue | null,
error?: Error,
) => void | Promise<void>,
) => { cancel: boolean } | Promise<{ cancel: boolean }>,
) {
;(async () => {
for await (const value of this.watch()) {
const ctrl = new AbortController()
for await (const value of this.watch(ctrl.signal)) {
try {
await callback(value)
const res = await callback(value)
if (res.cancel) {
ctrl.abort()
break
}
} catch (e) {
console.error(
"callback function threw an error @ GetSystemSmtp.onChange",
@@ -75,26 +90,20 @@ export class GetSystemSmtp {
/**
* Watches the system SMTP credentials. Returns when the predicate is true
*/
async waitFor(pred: (value: T.SmtpValue | null) => boolean) {
const resolveCell = { resolve: () => {} }
this.effects.onLeaveContext(() => {
resolveCell.resolve()
})
while (this.effects.isInContext) {
let callback: () => void = () => {}
const waitForNext = new Promise<void>((resolve) => {
callback = resolve
resolveCell.resolve = resolve
})
const res = await this.effects.getSystemSmtp({
callback: () => callback(),
})
if (pred(res)) {
resolveCell.resolve()
return res
}
await waitForNext
}
return null
waitFor(
pred: (value: T.SmtpValue | null) => boolean,
): Promise<T.SmtpValue | null> {
const ctrl = new AbortController()
return DropPromise.of(
Promise.resolve().then(async () => {
for await (const next of this.watchGen(ctrl.signal)) {
if (pred(next)) {
return next
}
}
return null
}),
() => ctrl.abort(),
)
}
}

View File

@@ -2,6 +2,7 @@ import { ServiceInterfaceType } from "../types"
import { knownProtocols } from "../interfaces/Host"
import { AddressInfo, Host, Hostname, HostnameInfo } from "../types"
import { Effects } from "../Effects"
import { DropGenerator, DropPromise } from "./Drop"
export type UrlString = string
export type HostId = string
@@ -312,16 +313,14 @@ export class GetServiceInterface {
return interfaceFilled
}
/**
* Watches the requested service interface. Returns an async iterator that yields whenever the value changes
*/
async *watch() {
private async *watchGen(abort?: AbortSignal) {
const { id, packageId } = this.opts
const resolveCell = { resolve: () => {} }
this.effects.onLeaveContext(() => {
resolveCell.resolve()
})
while (this.effects.isInContext) {
abort?.addEventListener("abort", () => resolveCell.resolve())
while (this.effects.isInContext && !abort?.aborted) {
let callback: () => void = () => {}
const waitForNext = new Promise<void>((resolve) => {
callback = resolve
@@ -337,6 +336,17 @@ export class GetServiceInterface {
}
}
/**
* Watches the requested service interface. Returns an async iterator that yields whenever the value changes
*/
watch(
abort?: AbortSignal,
): AsyncGenerator<ServiceInterfaceFilled | null, void, unknown> {
const ctrl = new AbortController()
abort?.addEventListener("abort", () => ctrl.abort())
return DropGenerator.of(this.watchGen(ctrl.signal), () => ctrl.abort())
}
/**
* Watches the requested service interface. Takes a custom callback function to run whenever the value changes
*/
@@ -344,12 +354,17 @@ export class GetServiceInterface {
callback: (
value: ServiceInterfaceFilled | null,
error?: Error,
) => void | Promise<void>,
) => { cancel: boolean } | Promise<{ cancel: boolean }>,
) {
;(async () => {
for await (const value of this.watch()) {
const ctrl = new AbortController()
for await (const value of this.watch(ctrl.signal)) {
try {
await callback(value)
const res = await callback(value)
if (res.cancel) {
ctrl.abort()
break
}
} catch (e) {
console.error(
"callback function threw an error @ GetServiceInterface.onChange",
@@ -370,31 +385,21 @@ export class GetServiceInterface {
/**
* Watches the requested service interface. Returns when the predicate is true
*/
async waitFor(pred: (value: ServiceInterfaceFilled | null) => boolean) {
const { id, packageId } = this.opts
const resolveCell = { resolve: () => {} }
this.effects.onLeaveContext(() => {
resolveCell.resolve()
})
while (this.effects.isInContext) {
let callback: () => void = () => {}
const waitForNext = new Promise<void>((resolve) => {
callback = resolve
resolveCell.resolve = resolve
})
const res = await makeInterfaceFilled({
effects: this.effects,
id,
packageId,
callback,
})
if (pred(res)) {
resolveCell.resolve()
return res
}
await waitForNext
}
return null
waitFor(
pred: (value: ServiceInterfaceFilled | null) => boolean,
): Promise<ServiceInterfaceFilled | null> {
const ctrl = new AbortController()
return DropPromise.of(
Promise.resolve().then(async () => {
for await (const next of this.watchGen(ctrl.signal)) {
if (pred(next)) {
return next
}
}
return null
}),
() => ctrl.abort(),
)
}
}
export function getServiceInterface(

View File

@@ -1,4 +1,5 @@
import { Effects } from "../Effects"
import { DropGenerator, DropPromise } from "./Drop"
import {
ServiceInterfaceFilled,
filledAddress,
@@ -77,16 +78,14 @@ export class GetServiceInterfaces {
return interfaceFilled
}
/**
* Watches the service interfaces for the package. Returns an async iterator that yields whenever the value changes
*/
async *watch() {
private async *watchGen(abort?: AbortSignal) {
const { packageId } = this.opts
const resolveCell = { resolve: () => {} }
this.effects.onLeaveContext(() => {
resolveCell.resolve()
})
while (this.effects.isInContext) {
abort?.addEventListener("abort", () => resolveCell.resolve())
while (this.effects.isInContext && !abort?.aborted) {
let callback: () => void = () => {}
const waitForNext = new Promise<void>((resolve) => {
callback = resolve
@@ -101,6 +100,17 @@ export class GetServiceInterfaces {
}
}
/**
* Watches the service interfaces for the package. Returns an async iterator that yields whenever the value changes
*/
watch(
abort?: AbortSignal,
): AsyncGenerator<ServiceInterfaceFilled[], void, unknown> {
const ctrl = new AbortController()
abort?.addEventListener("abort", () => ctrl.abort())
return DropGenerator.of(this.watchGen(ctrl.signal), () => ctrl.abort())
}
/**
* Watches the service interfaces for the package. Takes a custom callback function to run whenever the value changes
*/
@@ -108,12 +118,17 @@ export class GetServiceInterfaces {
callback: (
value: ServiceInterfaceFilled[] | null,
error?: Error,
) => void | Promise<void>,
) => { cancel: boolean } | Promise<{ cancel: boolean }>,
) {
;(async () => {
for await (const value of this.watch()) {
const ctrl = new AbortController()
for await (const value of this.watch(ctrl.signal)) {
try {
await callback(value)
const res = await callback(value)
if (res.cancel) {
ctrl.abort()
break
}
} catch (e) {
console.error(
"callback function threw an error @ GetServiceInterfaces.onChange",
@@ -134,30 +149,21 @@ export class GetServiceInterfaces {
/**
* Watches the service interfaces for the package. Returns when the predicate is true
*/
async waitFor(pred: (value: ServiceInterfaceFilled[] | null) => boolean) {
const { packageId } = this.opts
const resolveCell = { resolve: () => {} }
this.effects.onLeaveContext(() => {
resolveCell.resolve()
})
while (this.effects.isInContext) {
let callback: () => void = () => {}
const waitForNext = new Promise<void>((resolve) => {
callback = resolve
resolveCell.resolve = resolve
})
const res = await makeManyInterfaceFilled({
effects: this.effects,
packageId,
callback,
})
if (pred(res)) {
resolveCell.resolve()
return res
}
await waitForNext
}
return null
waitFor(
pred: (value: ServiceInterfaceFilled[] | null) => boolean,
): Promise<ServiceInterfaceFilled[] | null> {
const ctrl = new AbortController()
return DropPromise.of(
Promise.resolve().then(async () => {
for await (const next of this.watchGen(ctrl.signal)) {
if (pred(next)) {
return next
}
}
return null
}),
() => ctrl.abort(),
)
}
}
export function getServiceInterfaces(

View File

@@ -1,4 +1,5 @@
import { boolean } from "ts-matches"
import { ExtendedVersion } from "../exver"
export type Vertex<VMetadata = null, EMetadata = null> = {
metadata: VMetadata
@@ -14,6 +15,22 @@ export type Edge<EMetadata = null, VMetadata = null> = {
export class Graph<VMetadata = null, EMetadata = null> {
private readonly vertices: Array<Vertex<VMetadata, EMetadata>> = []
constructor() {}
dump(
metadataRepr: (metadata: VMetadata | EMetadata) => any = (a) => a,
): string {
const seen = new WeakSet()
return JSON.stringify(
this.vertices,
(k, v) => {
if (k === "metadata") return metadataRepr(v)
if (k === "from") return metadataRepr(v.metadata)
if (k === "to") return metadataRepr(v.metadata)
return v
},
2,
)
}
addVertex(
metadata: VMetadata,
fromEdges: Array<Omit<Edge<EMetadata, VMetadata>, "to">>,