@vite-hub/source
v0.0.3
Published
Typed source retrieval primitives for ViteHub.
Maintainers
Readme
@vite-hub/source
@vite-hub/source loads files, globs, markdown, GitHub content, or custom data before something else places it in a workspace.
Install
pnpm add @vite-hub/sourceMinimal API
// server/utils/sources.ts
import { defineSources, file, github, glob, registerSources, useSource } from "@vite-hub/source"
registerSources(defineSources({
docs: glob({ include: "docs/**/*.md" }),
readme: file("README.md"),
upstream: github({ repo: "vite-hub/vitehub" }),
}))
const docs = useSource("docs", { rootDir: process.cwd() })
const keys = await docs.keys()
const first = await docs.read(keys[0]!)Structured sources preserve record and metadata types through useSource():
import type { Source } from "@vite-hub/source"
interface Article {
author: string
cover: { key: string, mediaType: string }
title: string
}
interface ArticleMetadata {
revision: string
}
declare global {
interface ViteHubSourceMap {
articles: Source<`article_${string}`, Article, ArticleMetadata>
}
}
const article = await useSource("articles").get("article_123")
article.data?.title
article.metadata?.revision
const articles = await useSource("articles").items()Keep binary assets behind the Blob boundary and store a serializable reference in the record. This keeps ordinary record reads lazy while treating the structured data and its assets as one logical item.
Used by
@vite-hub/workspace materializes Source output into workspace files. Use this package directly when you only need typed source loading and not a workspace file tree.
Built on tinyglobby, picomatch, and mrmime.
Learn more at vitehub.dev.
