import type { K8sClient } from '$lib/server/k8s'; import { K8sResource } from '$lib/server/resources/k8s'; import type { StackCR } from '$lib/types/custom-resources'; import type { ResourceEvent } from '$lib/types/events'; import type { CoreResources } from '$lib/types/workspace'; import type { StackResources } from './types'; class K8sStackResourceImpl extends K8sResource { constructor(k8sClient: K8sClient, namespace: string) { super( k8sClient, namespace, { group: 'locostack.com', version: 'v1alpha1', namespace, resource: 'stacks', }, [], ); } } class K8sStackResources implements StackResources { #stackResources: K8sStackResourceImpl; constructor(k8sClient: K8sClient, namespace: string) { this.#stackResources = new K8sStackResourceImpl(k8sClient, namespace); } subscribe(handler: (event: ResourceEvent) => void): () => void { return this.#stackResources.subscribe(handler); } async getStacks(): Promise { return this.#stackResources.getResources(); } async getStackResources(stackId: string): Promise { return this.#stackResources.getCoreResources(stackId); } async getStackStatus(stackId: string): Promise { return this.#stackResources.getResourceStatus(stackId); } async applyStack(cr: StackCR): Promise { await this.#stackResources.apply(cr); } async deleteStack(id: string): Promise { await this.#stackResources.remove(id); } } export { K8sStackResources };