@dpkit/core
Version:
Fast TypeScript data management framework built on top of the Data Package standard and Polars DataFrames
30 lines (24 loc) • 686 B
text/typescript
import { loadDescriptor } from "../descriptor/load.ts"
import { cache } from "./cache.ts"
import type { ProfileType } from "./registry.ts"
import { validateProfile } from "./validate.ts"
export async function loadProfile(
path: string,
options?: { type?: ProfileType },
) {
let profile = cache.get(path)
if (!profile) {
const descriptor = await loadDescriptor(path, { onlyRemote: true })
const result = await validateProfile({
descriptor,
path,
type: options?.type,
})
if (!result.profile) {
throw new Error(`Profile at path ${path} is invalid`)
}
profile = result.profile
cache.set(path, profile)
}
return profile
}