UNPKG

k8ts

Version:

Powerful framework for building Kubernetes manifests in TypeScript.

30 lines (28 loc) 1.1 kB
import { DataSource_Lazy, type DataSource, type Resource_Ref_Min } from "@k8ts/instruments" import { isArrayBufferLike, isTypedArray } from "what-are-you" export async function resolveDataSourceRecord( resource: Resource_Ref_Min, input: Record<string, DataSource> ) { const binaryData: [string, string][] = [] const data: [string, string][] = [] const entries = Object.entries(input ?? {}) as [string, DataSource][] for (const [k, v] of entries) { let current = v if (current instanceof DataSource_Lazy) { current = await current.get() } if (isTypedArray(current) || isArrayBufferLike(current)) { const encoded = Buffer.from(current).toString("base64") binaryData.push([k, encoded]) } else if (typeof current === "string") { data.push([k, current]) } else { throw new Error(`Unsupported DataSource for ConfigMap ${resource} key "${k}"`) } } return { data: Object.fromEntries(data), binaryData: Object.fromEntries(binaryData) } }