@vite-hub/source 0.0.0 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,110 @@
1
+ import { i as normalizeSourcePath, n as matchesAny, o as sourceError, r as normalizeSafeSourcePath } from "../path-B5QNI5sY.js";
2
+ import { glob as glob$1 } from "tinyglobby";
3
+ //#region src/sources/glob.ts
4
+ function glob(options) {
5
+ let snapshot;
6
+ let latest;
7
+ async function getContextKey(ctx) {
8
+ return resolveCwd(resolveSourceRoot(ctx), options.cwd);
9
+ }
10
+ async function loadKeys(ctx) {
11
+ const cwd = await resolveCwd(resolveSourceRoot(ctx), options.cwd);
12
+ const ignore = normalizePatterns(options.ignore);
13
+ return (await glob$1(options.include, {
14
+ cwd,
15
+ dot: options.dot ?? false,
16
+ followSymbolicLinks: options.followSymlinks ?? false,
17
+ ignore: [
18
+ "**/.git/**",
19
+ "**/node_modules/**",
20
+ ...ignore
21
+ ],
22
+ onlyFiles: true
23
+ })).map((file) => normalizeSourcePath(file)).filter((file) => matchesAny(file, options.include) && !matchesAny(file, ignore)).sort((left, right) => left.localeCompare(right));
24
+ }
25
+ async function refreshKeys(ctx) {
26
+ const key = await getContextKey(ctx);
27
+ const keys = await loadKeys(ctx);
28
+ latest = {
29
+ key,
30
+ keys
31
+ };
32
+ return keys;
33
+ }
34
+ async function getCachedKeys(ctx) {
35
+ if (options.keyCache === false) return await refreshKeys(ctx);
36
+ const key = await getContextKey(ctx);
37
+ if (!snapshot || snapshot.key !== key) {
38
+ const keys = refreshKeys(ctx);
39
+ const entry = {
40
+ key,
41
+ keys
42
+ };
43
+ snapshot = entry;
44
+ keys.catch(() => {
45
+ if (snapshot === entry) snapshot = void 0;
46
+ });
47
+ }
48
+ return await snapshot.keys;
49
+ }
50
+ async function getKnownKeys(ctx) {
51
+ const key = await getContextKey(ctx);
52
+ if (latest?.key === key) return latest.keys;
53
+ return await getCachedKeys(ctx);
54
+ }
55
+ async function assertKey(key, ctx) {
56
+ if ((await getKnownKeys(ctx)).includes(key)) return;
57
+ if (options.keyCache !== false) throw sourceError(`[vitehub] glob could not find ${JSON.stringify(key)}.`);
58
+ if ((await refreshKeys(ctx)).includes(key)) return;
59
+ throw sourceError(`[vitehub] glob could not find ${JSON.stringify(key)}.`);
60
+ }
61
+ return {
62
+ name: "glob",
63
+ async prepare(ctx) {
64
+ snapshot = void 0;
65
+ await getCachedKeys(ctx);
66
+ },
67
+ getKeys(ctx) {
68
+ return getCachedKeys(ctx);
69
+ },
70
+ async getMeta(key, ctx) {
71
+ await assertKey(key, ctx);
72
+ const { stat } = await import("node:fs/promises");
73
+ const { resolve } = await import("node:path");
74
+ const info = await stat(resolve(await resolveCwd(resolveSourceRoot(ctx), options.cwd), key));
75
+ return { digest: `${info.size}:${info.mtimeMs}` };
76
+ },
77
+ async getItem(key, ctx) {
78
+ await assertKey(key, ctx);
79
+ const { readFile, stat } = await import("node:fs/promises");
80
+ const { resolve } = await import("node:path");
81
+ const cwd = await resolveCwd(resolveSourceRoot(ctx), options.cwd);
82
+ const prefix = normalizeSafeSourcePath(options.prefix || "", { allowEmpty: true });
83
+ const bytes = await readFile(resolve(cwd, key));
84
+ const info = await stat(resolve(cwd, key));
85
+ return {
86
+ key,
87
+ path: normalizeSourcePath(prefix ? `${prefix}/${key}` : key),
88
+ content: new Uint8Array(bytes),
89
+ metadata: { mtime: info.mtimeMs }
90
+ };
91
+ }
92
+ };
93
+ }
94
+ function normalizePatterns(patterns) {
95
+ return Array.isArray(patterns) ? patterns : patterns ? [patterns] : [];
96
+ }
97
+ function resolveSourceRoot(ctx) {
98
+ return ctx.sourceRootDir || ctx.rootDir;
99
+ }
100
+ async function resolveCwd(rootDir, cwd = ".") {
101
+ const { realpath } = await import("node:fs/promises");
102
+ const { isAbsolute, relative, resolve } = await import("node:path");
103
+ const resolvedRoot = await realpath(resolve(rootDir));
104
+ const resolvedCwd = await realpath(isAbsolute(cwd) ? resolve(cwd) : resolve(resolvedRoot, cwd));
105
+ const rel = relative(resolvedRoot, resolvedCwd);
106
+ if (rel && (rel.startsWith("..") || isAbsolute(rel))) throw sourceError(`[vitehub] glob cwd escapes the source root: ${JSON.stringify(cwd)}.`);
107
+ return resolvedCwd;
108
+ }
109
+ //#endregion
110
+ export { glob };
@@ -0,0 +1,13 @@
1
+ import { t as custom } from "../custom-EnZvMLiy.js";
2
+ import { i as file, n as FileSourceOptions } from "../file-slFAccIZ.js";
3
+ import { n as GitHubSourceOptions, t as github } from "../index-CJpN2j6c.js";
4
+ import { n as glob, t as GlobSourceOptions } from "../glob-CuxZwoC3.js";
5
+ import { t as markdown } from "../markdown-Beo-0cqc.js";
6
+ import { a as McpResourcesRequestOptions, i as McpResourcesClientConfig, l as mcpResources, n as McpResourceDescriptor, o as McpResourcesServer, r as McpResourcesClient, s as McpResourcesSourceOptions, t as McpResourceContent } from "../mcp-resources-C7-5Qeh4.js";
7
+
8
+ //#region src/sources/index.d.ts
9
+ declare namespace index_d_exports {
10
+ export { FileSourceOptions, GitHubSourceOptions, GlobSourceOptions, McpResourceContent, McpResourceDescriptor, McpResourcesClient, McpResourcesClientConfig, McpResourcesRequestOptions, McpResourcesServer, McpResourcesSourceOptions, custom, file, github, glob, markdown, mcpResources };
11
+ }
12
+ //#endregion
13
+ export { type FileSourceOptions, type GitHubSourceOptions, type GlobSourceOptions, type McpResourceContent, type McpResourceDescriptor, type McpResourcesClient, type McpResourcesClientConfig, type McpResourcesRequestOptions, type McpResourcesServer, type McpResourcesSourceOptions, custom, file, github, glob, markdown, mcpResources, index_d_exports as t };
@@ -0,0 +1,18 @@
1
+ import { t as __exportAll } from "../chunk-D7D4PA-g.js";
2
+ import { custom } from "./custom.js";
3
+ import { file } from "./file.js";
4
+ import { t as github } from "../github-B4lgrzXQ.js";
5
+ import { glob } from "./glob.js";
6
+ import { markdown } from "./markdown.js";
7
+ import { t as mcpResources } from "../mcp-resources-DSDqTfbK.js";
8
+ //#region src/sources/index.ts
9
+ var sources_exports = /* @__PURE__ */ __exportAll({
10
+ custom: () => custom,
11
+ file: () => file,
12
+ github: () => github,
13
+ glob: () => glob,
14
+ markdown: () => markdown,
15
+ mcpResources: () => mcpResources
16
+ });
17
+ //#endregion
18
+ export { custom, file, github, glob, markdown, mcpResources, sources_exports as t };
@@ -0,0 +1,2 @@
1
+ import { t as markdown } from "../markdown-Beo-0cqc.js";
2
+ export { markdown };
@@ -0,0 +1,10 @@
1
+ import { file } from "./file.js";
2
+ //#region src/sources/markdown.ts
3
+ function markdown(options) {
4
+ return file({
5
+ ...options,
6
+ mediaType: options.mediaType || "text/markdown"
7
+ });
8
+ }
9
+ //#endregion
10
+ export { markdown };
@@ -0,0 +1,2 @@
1
+ import { a as McpResourcesRequestOptions, c as McpResourcesTransportConfig, i as McpResourcesClientConfig, l as mcpResources, n as McpResourceDescriptor, o as McpResourcesServer, r as McpResourcesClient, s as McpResourcesSourceOptions, t as McpResourceContent } from "../mcp-resources-C7-5Qeh4.js";
2
+ export { McpResourceContent, McpResourceDescriptor, McpResourcesClient, McpResourcesClientConfig, McpResourcesRequestOptions, McpResourcesServer, McpResourcesSourceOptions, McpResourcesTransportConfig, mcpResources };
@@ -0,0 +1,2 @@
1
+ import { t as mcpResources } from "../mcp-resources-DSDqTfbK.js";
2
+ export { mcpResources };
@@ -0,0 +1,73 @@
1
+ //#region src/core/types.d.ts
2
+ type SourceContent = string | Uint8Array;
3
+ interface ReadSourceOptions {
4
+ encoding?: "utf8" | "binary";
5
+ }
6
+ type ReadSourceResult<TOptions extends ReadSourceOptions | undefined = undefined> = TOptions extends {
7
+ encoding: "binary";
8
+ } ? Uint8Array : string;
9
+ interface SourceContext {
10
+ abortSignal?: AbortSignal;
11
+ rootDir: string;
12
+ sourceRootDir?: string;
13
+ source?: string;
14
+ workspace?: string;
15
+ }
16
+ interface SourceCacheOptions {
17
+ maxAge?: number;
18
+ }
19
+ interface SourceSearchQuery {
20
+ pattern: string;
21
+ cwd?: string;
22
+ paths?: string[];
23
+ regex?: boolean;
24
+ caseSensitive?: boolean;
25
+ limit?: number;
26
+ }
27
+ interface SourceSearchHit {
28
+ path: string;
29
+ line: number;
30
+ column: number;
31
+ text: string;
32
+ }
33
+ interface SourceItem<TKey extends string = string> {
34
+ key: TKey;
35
+ path?: string;
36
+ content?: SourceContent;
37
+ data?: unknown;
38
+ mediaType?: string;
39
+ metadata?: Record<string, unknown>;
40
+ }
41
+ interface Source<TKey extends string = string> {
42
+ name: string;
43
+ cache?: false | SourceCacheOptions;
44
+ fingerprint?: unknown;
45
+ prepare?(ctx: SourceContext): Promise<void>;
46
+ getKeys(ctx: SourceContext): Promise<TKey[]>;
47
+ getItem(key: TKey, ctx: SourceContext): Promise<SourceItem<TKey>>;
48
+ getItems?(ctx: SourceContext): Promise<SourceItem<TKey>[]>;
49
+ getMeta?(key: TKey, ctx: SourceContext): Promise<Record<string, unknown> | undefined>;
50
+ search?(query: SourceSearchQuery, ctx: SourceContext): Promise<SourceSearchHit[]>;
51
+ watch?: unknown[];
52
+ }
53
+ interface SourceListEntry<TKey extends string = string> {
54
+ key: TKey;
55
+ type: "file" | "directory";
56
+ }
57
+ declare global {
58
+ interface ViteHubSourceMap {}
59
+ }
60
+ interface SourceMap extends ViteHubSourceMap {}
61
+ type SourceKeyOf<TSource> = TSource extends Source<infer TKey> ? TKey : string;
62
+ type SourceName = [keyof ViteHubSourceMap] extends [never] ? string : Extract<keyof ViteHubSourceMap, string>;
63
+ type SourceKey<TName extends SourceName = SourceName> = TName extends keyof ViteHubSourceMap ? Extract<SourceKeyOf<ViteHubSourceMap[TName]>, string> : string;
64
+ interface SourceReader<TName extends SourceName = SourceName> {
65
+ keys(): Promise<SourceKey<TName>[]>;
66
+ get(key: SourceKey<TName>): Promise<SourceItem<SourceKey<TName>>>;
67
+ read<TOptions extends ReadSourceOptions | undefined = undefined>(key: SourceKey<TName>, options?: TOptions): Promise<ReadSourceResult<TOptions>>;
68
+ meta(key: SourceKey<TName>): Promise<Record<string, unknown> | undefined>;
69
+ exists(key: SourceKey<TName>): Promise<boolean>;
70
+ list(prefix?: SourceKey<TName> | (string & {}) | ""): Promise<SourceListEntry<SourceKey<TName>>[]>;
71
+ }
72
+ //#endregion
73
+ export { SourceContent as a, SourceKey as c, SourceName as d, SourceReader as f, SourceCacheOptions as i, SourceListEntry as l, SourceSearchQuery as m, ReadSourceResult as n, SourceContext as o, SourceSearchHit as p, Source as r, SourceItem as s, ReadSourceOptions as t, SourceMap as u };
package/package.json CHANGED
@@ -1,9 +1,91 @@
1
1
  {
2
2
  "name": "@vite-hub/source",
3
- "version": "0.0.0",
4
- "description": "Reserved package name for ViteHub.",
3
+ "version": "0.0.2",
4
+ "description": "Typed source retrieval primitives for ViteHub.",
5
+ "keywords": [
6
+ "content",
7
+ "files",
8
+ "github",
9
+ "source",
10
+ "vitehub"
11
+ ],
12
+ "homepage": "https://github.com/vite-hub/vitehub#readme",
13
+ "bugs": "https://github.com/vite-hub/vitehub/issues",
5
14
  "license": "Apache-2.0",
6
- "publishConfig": {
7
- "access": "public"
15
+ "author": "onmax <maximogarciamtnez@gmail.com>",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/vite-hub/vitehub.git",
19
+ "directory": "packages/source"
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "package.json"
24
+ ],
25
+ "type": "module",
26
+ "sideEffects": false,
27
+ "types": "./dist/index.d.ts",
28
+ "exports": {
29
+ ".": {
30
+ "types": "./dist/index.d.ts",
31
+ "import": "./dist/index.js"
32
+ },
33
+ "./sources": {
34
+ "types": "./dist/sources/index.d.ts",
35
+ "import": "./dist/sources/index.js"
36
+ },
37
+ "./sources/custom": {
38
+ "types": "./dist/sources/custom.d.ts",
39
+ "import": "./dist/sources/custom.js"
40
+ },
41
+ "./sources/file": {
42
+ "types": "./dist/sources/file.d.ts",
43
+ "import": "./dist/sources/file.js"
44
+ },
45
+ "./sources/github": {
46
+ "types": "./dist/sources/github.d.ts",
47
+ "import": "./dist/sources/github.js"
48
+ },
49
+ "./sources/glob": {
50
+ "types": "./dist/sources/glob.d.ts",
51
+ "import": "./dist/sources/glob.js"
52
+ },
53
+ "./sources/markdown": {
54
+ "types": "./dist/sources/markdown.d.ts",
55
+ "import": "./dist/sources/markdown.js"
56
+ },
57
+ "./sources/mcp-resources": {
58
+ "types": "./dist/sources/mcp-resources.d.ts",
59
+ "import": "./dist/sources/mcp-resources.js"
60
+ },
61
+ "./package.json": "./package.json"
62
+ },
63
+ "dependencies": {
64
+ "@modelcontextprotocol/sdk": "^1.29.0",
65
+ "effect": "4.0.0-beta.99",
66
+ "mrmime": "^2.0.1",
67
+ "ocache": "^0.1.5",
68
+ "pathe": "^2.0.3",
69
+ "picomatch": "^4.0.5",
70
+ "tinyglobby": "^0.2.17",
71
+ "@vite-hub/runtime": "0.0.2"
72
+ },
73
+ "devDependencies": {
74
+ "@types/node": "^24.13.3",
75
+ "@types/picomatch": "^4.0.3",
76
+ "publint": "^0.3.21",
77
+ "typescript": "^6.0.3",
78
+ "vite-plus": "^0.1.24",
79
+ "vitest": "^4.1.4",
80
+ "@vite-hub/internal": "0.0.1"
81
+ },
82
+ "engines": {
83
+ "node": ">=24.0.0"
84
+ },
85
+ "scripts": {
86
+ "build": "vp pack",
87
+ "dev": "vp pack --watch",
88
+ "typecheck": "tsc --noEmit -p ./tsconfig.json",
89
+ "test": "vp run -t @vite-hub/source#build && vp test"
8
90
  }
9
- }
91
+ }