import type { K8sClient } from '$lib/server/k8s'; import { K8sResource } from '$lib/server/resources/k8s'; import type { DocumentCR } from '$lib/types/custom-resources'; import type { ResourceEvent } from '$lib/types/events'; import type { CoreResources } from '$lib/types/workspace'; import type { DocumentResources } from './types'; class _K8sDocumentResources extends K8sResource { constructor(k8sClient: K8sClient, namespace: string) { super( k8sClient, namespace, { group: 'locostack.com', version: 'v1alpha1', namespace, resource: 'documents', }, [ { group: 'batch', version: 'v1', namespace, resource: 'jobs', labelSelector: 'locostack.com/kb', }, { group: 'core', version: 'v1', namespace, resource: 'pods', labelSelector: 'locostack.com/kb', }, ], ); } } class K8sDocumentResources implements DocumentResources { #documentResources: _K8sDocumentResources; constructor(k8sClient: K8sClient, namespace: string) { this.#documentResources = new _K8sDocumentResources(k8sClient, namespace); } subscribe(handler: (event: ResourceEvent) => void): () => void { return this.#documentResources.subscribe(handler); } async getDocuments(): Promise { return this.#documentResources.getResources(); } async getDocumentResources(docId: string): Promise { return this.#documentResources.getCoreResources(`doc-${docId}`); } async getDocumentStatus(docId: string): Promise { return this.#documentResources.getResourceStatus(docId); } async applyDocument(cr: DocumentCR): Promise { await this.#documentResources.apply(cr); } async deleteDocument(id: string): Promise { await this.#documentResources.remove(id); } } export { K8sDocumentResources };