@vite-hub/source 0.0.4 → 0.3.0
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.
- package/README.md +267 -96
- package/dist/client.d.ts +27 -10
- package/dist/client.js +99 -15
- package/dist/collection-B8sgxw5-.d.ts +290 -0
- package/dist/collection-C0Rvrx3p.js +297 -0
- package/dist/collection-route-BplWPxHR.js +10 -0
- package/dist/drizzle.d.ts +48 -0
- package/dist/drizzle.js +87 -0
- package/dist/error-diagnostics-ClQKdi7c.js +194 -0
- package/dist/github-D5S0dEZe.js +1312 -0
- package/dist/{glob.js → glob-DmdMVqjx.js} +154 -57
- package/dist/index.d.ts +284 -62
- package/dist/index.js +583 -29
- package/dist/invariant-DolT9EEx.js +22 -0
- package/dist/mcp.d.ts +3 -4
- package/dist/mcp.js +184 -5917
- package/dist/object-CtSHeGQO.js +17 -0
- package/dist/{path-CUhvUREm.js → path-DFlSryRA.js} +90 -40
- package/dist/root-DJNmqCEW.js +11 -0
- package/dist/server.d.ts +24 -11
- package/dist/server.js +97 -26
- package/dist/types-Ln-FxVFn.d.ts +98 -0
- package/dist/vite.d.ts +202 -14
- package/dist/vite.js +1683 -122
- package/package.json +55 -58
- package/dist/auth-Ddw55OUG.js +0 -1261
- package/dist/client-CDfTmtQu.js +0 -7903
- package/dist/collection-B8pXGM2d.js +0 -141
- package/dist/collection-CF2ON__k.d.ts +0 -92
- package/dist/collection-route-Dw7QLFyx.js +0 -6
- package/dist/content/client.d.ts +0 -3
- package/dist/content/client.js +0 -2
- package/dist/content.d.ts +0 -44
- package/dist/content.js +0 -157
- package/dist/file-BSWQg9Qv.js +0 -503
- package/dist/file-EQ3AjVM6.d.ts +0 -20
- package/dist/file.d.ts +0 -2
- package/dist/file.js +0 -2
- package/dist/github.d.ts +0 -17
- package/dist/github.js +0 -1033
- package/dist/glob.d.ts +0 -15
- package/dist/markdown.d.ts +0 -7
- package/dist/markdown.js +0 -10
- package/dist/path-BzmU4Eni.js +0 -36
- package/dist/registry-C8skfCSV.js +0 -120
- package/dist/sse-CE9Q2JqM.js +0 -407
- package/dist/streamableHttp-BszaXLmg.js +0 -491
- package/dist/types-AIBmt_m6.js +0 -6275
- package/dist/types-Bu3WvNX9.d.ts +0 -71
- package/tsconfig.vite.json +0 -6
- package/types/source/fallback.d.ts +0 -1
- package/types/source/index.d.ts +0 -1
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as sourceError, n as normalizeSafeSourcePath, r as normalizeSourcePath } from "./path-BzmU4Eni.js";
|
|
1
|
+
import { a as normalizeSafeSourcePath, o as normalizeSourcePath, r as require_picomatch, s as sourceError, t as createPathMatcher, u as __toESM } from "./path-DFlSryRA.js";
|
|
3
2
|
import * as nativeFs from "fs";
|
|
4
3
|
import { readdir, readdirSync, realpath, realpathSync, stat, statSync } from "fs";
|
|
5
4
|
import { basename, dirname, isAbsolute, normalize, posix, relative, resolve, sep } from "path";
|
|
6
5
|
import { fileURLToPath } from "url";
|
|
7
|
-
//#region ../../node_modules/.pnpm/fdir@6.5.0_picomatch@4.0.
|
|
6
|
+
//#region ../../node_modules/.pnpm/fdir@6.5.0_picomatch@4.0.7/node_modules/fdir/dist/index.mjs
|
|
8
7
|
function cleanPath(path) {
|
|
9
8
|
let normalized = normalize(path);
|
|
10
9
|
if (normalized.length > 1 && normalized[normalized.length - 1] === sep) normalized = normalized.substring(0, normalized.length - 1);
|
|
@@ -785,87 +784,148 @@ async function glob$1(globInput, options) {
|
|
|
785
784
|
}
|
|
786
785
|
//#endregion
|
|
787
786
|
//#region src/sources/glob.ts
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
787
|
+
/**
|
|
788
|
+
* The options a pattern stands for: the folders before its first wildcard are `cwd`, so keys are the paths below
|
|
789
|
+
* them (`content/docs/**\/*.md` keys `guide/setup.md`). A pattern without a wildcard names a folder: every file in it.
|
|
790
|
+
*/
|
|
791
|
+
function resolveGlobInput(input) {
|
|
792
|
+
if (typeof input !== "string") return input;
|
|
793
|
+
const parts = input.replaceAll("\\", "/").replace(/^\.\//, "").split("/").filter(Boolean);
|
|
794
|
+
const wild = parts.findIndex((part) => /[*?[\]{}()!]/.test(part));
|
|
795
|
+
if (wild === -1) return {
|
|
796
|
+
cwd: parts.join("/") || ".",
|
|
797
|
+
include: "**/*"
|
|
798
|
+
};
|
|
799
|
+
return {
|
|
800
|
+
cwd: parts.slice(0, wild).join("/") || ".",
|
|
801
|
+
include: parts.slice(wild).join("/")
|
|
802
|
+
};
|
|
803
|
+
}
|
|
804
|
+
/** The project's files a glob matches, sorted, and where they sit. Shared by `glob()` and the build that bundles it. */
|
|
805
|
+
async function collectGlobFiles(rootDir, options) {
|
|
806
|
+
const paths = await resolveGlobPaths(rootDir, options.cwd);
|
|
807
|
+
const include = normalizePatterns(options.include).map(normalizeGlobPattern);
|
|
808
|
+
const ignore = normalizePatterns(options.ignore).map(normalizeGlobPattern);
|
|
809
|
+
const files = await glob$1(include, {
|
|
810
|
+
cwd: paths.cwd,
|
|
811
|
+
dot: options.dot ?? false,
|
|
812
|
+
followSymbolicLinks: options.followSymlinks ?? false,
|
|
813
|
+
ignore: [
|
|
814
|
+
"**/.git/**",
|
|
815
|
+
"**/node_modules/**",
|
|
816
|
+
...ignore
|
|
817
|
+
],
|
|
818
|
+
onlyFiles: true
|
|
819
|
+
});
|
|
820
|
+
const matchesInclude = createPathMatcher(include);
|
|
821
|
+
const matchesIgnore = createPathMatcher(ignore);
|
|
822
|
+
let keys = files.map((file) => normalizeSafeSourcePath(file, { allowReserved: true })).filter((file) => matchesInclude(file) && !matchesIgnore(file));
|
|
823
|
+
if (options.followSymlinks) {
|
|
824
|
+
const rooted = [];
|
|
825
|
+
for (const key of keys) if (await resolveRootedGlobFilePath(key, paths, true)) rooted.push(key);
|
|
826
|
+
keys = rooted;
|
|
827
|
+
}
|
|
828
|
+
return {
|
|
829
|
+
paths,
|
|
830
|
+
keys: keys.sort((left, right) => left.localeCompare(right))
|
|
831
|
+
};
|
|
832
|
+
}
|
|
833
|
+
/** Where a key's file is, or undefined when glob() would not read it (a symbolic link it does not follow, say). */
|
|
834
|
+
function globFilePath(key, paths, followSymlinks) {
|
|
835
|
+
return resolveRootedGlobFilePath(key, paths, followSymlinks);
|
|
836
|
+
}
|
|
837
|
+
/**
|
|
838
|
+
* Project files that match a pattern, such as `glob("content/docs/**\/*.md")`. Under `vite dev` they are read from
|
|
839
|
+
* disk, so new files show up at once. A ViteHub build bundles a call with literal options into the server, so hosts
|
|
840
|
+
* without a file system, such as Cloudflare Workers, serve the same files.
|
|
841
|
+
*/
|
|
842
|
+
function glob(input) {
|
|
843
|
+
const options = resolveGlobInput(input);
|
|
844
|
+
const caches = /* @__PURE__ */ new WeakMap();
|
|
845
|
+
function cacheFor(ctx) {
|
|
846
|
+
let cache = caches.get(ctx);
|
|
847
|
+
if (!cache) {
|
|
848
|
+
cache = {};
|
|
849
|
+
caches.set(ctx, cache);
|
|
850
|
+
}
|
|
851
|
+
return cache;
|
|
852
|
+
}
|
|
791
853
|
async function getContextKey(ctx) {
|
|
792
|
-
|
|
854
|
+
const { root, cwd } = await resolveGlobPaths(resolveSourceRoot(ctx), options.cwd);
|
|
855
|
+
return `${root}\0${cwd}`;
|
|
793
856
|
}
|
|
794
857
|
async function loadKeys(ctx) {
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
cwd,
|
|
799
|
-
dot: options.dot ?? false,
|
|
800
|
-
followSymbolicLinks: options.followSymlinks ?? false,
|
|
801
|
-
ignore: [
|
|
802
|
-
"**/.git/**",
|
|
803
|
-
"**/node_modules/**",
|
|
804
|
-
...ignore
|
|
805
|
-
],
|
|
806
|
-
onlyFiles: true
|
|
807
|
-
})).map((file) => normalizeSourcePath(file)).filter((file) => matchesAny(file, options.include) && !matchesAny(file, ignore)).sort((left, right) => left.localeCompare(right));
|
|
808
|
-
}
|
|
809
|
-
async function refreshKeys(ctx) {
|
|
858
|
+
return (await collectGlobFiles(resolveSourceRoot(ctx), options)).keys;
|
|
859
|
+
}
|
|
860
|
+
async function refreshListing(ctx) {
|
|
810
861
|
const key = await getContextKey(ctx);
|
|
811
862
|
const keys = await loadKeys(ctx);
|
|
812
|
-
|
|
863
|
+
const listing = {
|
|
864
|
+
keys,
|
|
865
|
+
keySet: new Set(keys)
|
|
866
|
+
};
|
|
867
|
+
cacheFor(ctx).latest = {
|
|
813
868
|
key,
|
|
814
|
-
|
|
869
|
+
listing
|
|
815
870
|
};
|
|
816
|
-
return
|
|
871
|
+
return listing;
|
|
817
872
|
}
|
|
818
|
-
async function
|
|
819
|
-
if (options.keyCache === false) return await
|
|
873
|
+
async function getCachedListing(ctx) {
|
|
874
|
+
if (options.keyCache === false) return await refreshListing(ctx);
|
|
820
875
|
const key = await getContextKey(ctx);
|
|
821
|
-
|
|
822
|
-
|
|
876
|
+
const cache = cacheFor(ctx);
|
|
877
|
+
if (!cache.snapshot || cache.snapshot.key !== key) {
|
|
878
|
+
const listing = refreshListing(ctx);
|
|
823
879
|
const entry = {
|
|
824
880
|
key,
|
|
825
|
-
|
|
881
|
+
listing
|
|
826
882
|
};
|
|
827
|
-
snapshot = entry;
|
|
828
|
-
|
|
829
|
-
if (snapshot === entry) snapshot = void 0;
|
|
883
|
+
cache.snapshot = entry;
|
|
884
|
+
listing.catch(() => {
|
|
885
|
+
if (cache.snapshot === entry) cache.snapshot = void 0;
|
|
830
886
|
});
|
|
831
887
|
}
|
|
832
|
-
return await snapshot.
|
|
888
|
+
return await cache.snapshot.listing;
|
|
833
889
|
}
|
|
834
|
-
async function
|
|
890
|
+
async function getKnownListing(ctx) {
|
|
835
891
|
const key = await getContextKey(ctx);
|
|
836
|
-
|
|
837
|
-
|
|
892
|
+
const { latest } = cacheFor(ctx);
|
|
893
|
+
if (latest?.key === key) return latest.listing;
|
|
894
|
+
return await getCachedListing(ctx);
|
|
838
895
|
}
|
|
839
896
|
async function assertKey(key, ctx) {
|
|
840
|
-
if ((await
|
|
841
|
-
if (options.keyCache !== false) throw
|
|
842
|
-
if ((await
|
|
843
|
-
throw
|
|
897
|
+
if ((await getKnownListing(ctx)).keySet.has(key)) return;
|
|
898
|
+
if (options.keyCache !== false) throw missingKeyError(key);
|
|
899
|
+
if ((await refreshListing(ctx)).keySet.has(key)) return;
|
|
900
|
+
throw missingKeyError(key);
|
|
901
|
+
}
|
|
902
|
+
async function resolveGlobFilePath(key, ctx) {
|
|
903
|
+
const path = await resolveRootedGlobFilePath(key, await resolveGlobPaths(resolveSourceRoot(ctx), options.cwd), options.followSymlinks === true);
|
|
904
|
+
if (!path) throw missingKeyError(key);
|
|
905
|
+
return path;
|
|
844
906
|
}
|
|
845
907
|
return {
|
|
846
908
|
name: "glob",
|
|
847
909
|
async prepare(ctx) {
|
|
848
|
-
snapshot = void 0;
|
|
849
|
-
await
|
|
910
|
+
cacheFor(ctx).snapshot = void 0;
|
|
911
|
+
await getCachedListing(ctx);
|
|
850
912
|
},
|
|
851
|
-
getKeys(ctx) {
|
|
852
|
-
return
|
|
913
|
+
async getKeys(ctx) {
|
|
914
|
+
return (await getCachedListing(ctx)).keys.slice();
|
|
853
915
|
},
|
|
854
916
|
async getMeta(key, ctx) {
|
|
855
917
|
await assertKey(key, ctx);
|
|
856
918
|
const { stat } = await import("node:fs/promises");
|
|
857
|
-
const
|
|
858
|
-
const info = await stat(resolve(await resolveCwd(resolveSourceRoot(ctx), options.cwd), key));
|
|
919
|
+
const info = await stat(await resolveGlobFilePath(key, ctx));
|
|
859
920
|
return { digest: `${info.size}:${info.mtimeMs}` };
|
|
860
921
|
},
|
|
861
922
|
async getItem(key, ctx) {
|
|
862
923
|
await assertKey(key, ctx);
|
|
863
924
|
const { readFile, stat } = await import("node:fs/promises");
|
|
864
|
-
const
|
|
865
|
-
const cwd = await resolveCwd(resolveSourceRoot(ctx), options.cwd);
|
|
925
|
+
const filePath = await resolveGlobFilePath(key, ctx);
|
|
866
926
|
const prefix = normalizeSafeSourcePath(options.prefix || "", { allowEmpty: true });
|
|
867
|
-
const bytes = await readFile(
|
|
868
|
-
const info = await stat(
|
|
927
|
+
const bytes = await readFile(filePath);
|
|
928
|
+
const info = await stat(filePath);
|
|
869
929
|
return {
|
|
870
930
|
key,
|
|
871
931
|
path: normalizeSourcePath(prefix ? `${prefix}/${key}` : key),
|
|
@@ -875,21 +935,58 @@ function glob(options) {
|
|
|
875
935
|
}
|
|
876
936
|
};
|
|
877
937
|
}
|
|
938
|
+
function missingKeyError(key) {
|
|
939
|
+
return sourceError(`[vitehub] glob could not find ${JSON.stringify(key)}.`);
|
|
940
|
+
}
|
|
878
941
|
function normalizePatterns(patterns) {
|
|
879
942
|
if (!patterns) return [];
|
|
880
943
|
return Array.isArray(patterns) ? patterns : [String(patterns)];
|
|
881
944
|
}
|
|
945
|
+
function normalizeGlobPattern(pattern) {
|
|
946
|
+
return pattern.replaceAll("\\", "/");
|
|
947
|
+
}
|
|
882
948
|
function resolveSourceRoot(ctx) {
|
|
883
949
|
return ctx.sourceRootDir || ctx.rootDir;
|
|
884
950
|
}
|
|
885
|
-
async function
|
|
951
|
+
async function resolveGlobPaths(rootDir, cwd = ".") {
|
|
886
952
|
const { realpath } = await import("node:fs/promises");
|
|
887
|
-
const { isAbsolute, relative, resolve } = await import("node:path");
|
|
953
|
+
const { isAbsolute, relative, resolve, sep } = await import("node:path");
|
|
888
954
|
const resolvedRoot = await realpath(resolve(rootDir));
|
|
889
|
-
const
|
|
955
|
+
const normalizedCwd = isAbsolute(cwd) ? cwd : normalizeSafeSourcePath(cwd === "." ? "" : cwd, { allowEmpty: true });
|
|
956
|
+
const resolvedCwd = await realpath(isAbsolute(normalizedCwd) ? resolve(normalizedCwd) : resolve(resolvedRoot, normalizedCwd));
|
|
890
957
|
const rel = relative(resolvedRoot, resolvedCwd);
|
|
891
|
-
if (rel
|
|
892
|
-
return
|
|
958
|
+
if (rel === ".." || rel.startsWith(`..${sep}`) || isAbsolute(rel)) throw sourceError(`[vitehub] glob cwd escapes the source root: ${JSON.stringify(cwd)}.`);
|
|
959
|
+
return {
|
|
960
|
+
root: resolvedRoot,
|
|
961
|
+
cwd: resolvedCwd
|
|
962
|
+
};
|
|
963
|
+
}
|
|
964
|
+
async function resolveRootedGlobFilePath(key, paths, followSymlinks) {
|
|
965
|
+
const { lstat, realpath } = await import("node:fs/promises");
|
|
966
|
+
const { isAbsolute, relative, resolve, sep } = await import("node:path");
|
|
967
|
+
const safeKey = normalizeSafeSourcePath(key, { allowReserved: true });
|
|
968
|
+
const path = resolve(paths.cwd, safeKey);
|
|
969
|
+
if (followSymlinks) {
|
|
970
|
+
let target;
|
|
971
|
+
try {
|
|
972
|
+
target = await realpath(path);
|
|
973
|
+
} catch (error) {
|
|
974
|
+
if (isUnavailablePathError(error)) return;
|
|
975
|
+
throw error;
|
|
976
|
+
}
|
|
977
|
+
const rel = relative(paths.root, target);
|
|
978
|
+
if (rel === ".." || rel.startsWith(`..${sep}`) || isAbsolute(rel)) return;
|
|
979
|
+
return target;
|
|
980
|
+
}
|
|
981
|
+
let current = paths.cwd;
|
|
982
|
+
for (const part of safeKey.split("/")) {
|
|
983
|
+
current = resolve(current, part);
|
|
984
|
+
if ((await lstat(current)).isSymbolicLink()) return;
|
|
985
|
+
}
|
|
986
|
+
return path;
|
|
987
|
+
}
|
|
988
|
+
function isUnavailablePathError(error) {
|
|
989
|
+
return error instanceof Error && ["ENOENT", "ELOOP"].includes(String(Reflect.get(error, "code")));
|
|
893
990
|
}
|
|
894
991
|
//#endregion
|
|
895
|
-
export { glob };
|
|
992
|
+
export { resolveGlobInput as i, glob as n, globFilePath as r, collectGlobFiles as t };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,75 +1,117 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
import { a as
|
|
1
|
+
import { A as CollectionCursorErrorReason, C as ProviderCollectionOptions, D as defineCollection, E as SourceCollectionOptions, O as CollectionCursorError, S as ProviderCollectionLoader, T as ProviderCollectionSource, _ as CollectionQueryInput, a as CollectionClientItem, b as CollectionSource, c as CollectionFacets, d as CollectionLoader, f as CollectionOptions, g as CollectionQueryBuilder, h as CollectionQuery, i as CollectionAccess, k as CollectionCursorErrorOptions, l as CollectionItem, m as CollectionPageOptions, n as AnyCollectionSource, o as CollectionCursorValue, p as CollectionPage, r as Collection, s as CollectionFacetValue, t as AnyCollection, u as CollectionLoadOptions, v as CollectionReadOptions, w as ProviderCollectionPage, x as CursorCollectionSource, y as CollectionRequestQuery } from "./collection-B8sgxw5-.js";
|
|
2
|
+
import { _ as SourceMetadata, a as SingleFileSource, b as SourceRevision, c as SourceContent, d as SourceEntry, f as SourceFile, g as SourceMap, h as SourceListEntry, i as RegisteredSource, l as SourceContext, m as SourceKey, n as ReadSourceOptions, o as Source, p as SourceItem, r as ReadSourceResult, s as SourceCacheOptions, t as FileSource, u as SourceData, v as SourceName, y as SourceReader } from "./types-Ln-FxVFn.js";
|
|
3
3
|
import { ViteHubError } from "@vite-hub/runtime";
|
|
4
|
-
|
|
5
|
-
//#region src/core/
|
|
6
|
-
interface
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}>>;
|
|
4
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
5
|
+
//#region src/core/array-collection.d.ts
|
|
6
|
+
interface ArrayCollectionSort {
|
|
7
|
+
direction?: "asc" | "desc";
|
|
8
|
+
/** Field path to sort by. Numbers sort numerically; other values sort as strings. */
|
|
9
|
+
field: string;
|
|
11
10
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
type TaggedCombinedItemVariant<TSource extends string, TItem> = TItem extends {
|
|
32
|
-
key: string;
|
|
33
|
-
} ? Omit<TItem, "identity" | "source"> & {
|
|
34
|
-
identity: readonly [TSource, TItem["key"]];
|
|
35
|
-
source: TSource;
|
|
36
|
-
} : never;
|
|
37
|
-
type TaggedCombinedItem<TSource extends string, TReader> = TaggedCombinedItemVariant<TSource, CombinedSourceItem<TReader>>;
|
|
38
|
-
type CombinedItem<TSources extends CombinedSources> = { [TSource in Extract<keyof TSources, string>]: TaggedCombinedItem<TSource, TSources[TSource]> }[Extract<keyof TSources, string>];
|
|
39
|
-
type CombinedIdentity<TSources extends CombinedSources> = { [TSource in Extract<keyof TSources, string>]: readonly [source: TSource, key: CombinedSourceKey<TSources[TSource]>] }[Extract<keyof TSources, string>];
|
|
40
|
-
type CombinedIdentityValue<TSources extends CombinedSources, TIdentity> = TIdentity extends readonly [infer TSource extends Extract<keyof TSources, string>, string] ? CombinedSourceValue<TSources[TSource]> : never;
|
|
41
|
-
interface CombinedSourcesDefinition<TSources extends CombinedSources> {
|
|
42
|
-
readonly sources: TSources & ValidCombinedSources<TSources> & Record<Exclude<keyof TSources, string>, never>;
|
|
11
|
+
interface ArrayCollectionOptions<TFilter extends string = string> {
|
|
12
|
+
/**
|
|
13
|
+
* Field paths clients may filter by. `?category=guide` matches case-insensitively, a repeated key matches any of
|
|
14
|
+
* its values, and `?empty=category` matches items with no value at that path. Dot paths read nested objects and
|
|
15
|
+
* every element of nested arrays.
|
|
16
|
+
*/
|
|
17
|
+
filters?: readonly TFilter[];
|
|
18
|
+
/** Field paths that the `search` query matches as a case-insensitive substring. Omit to reject `search`. */
|
|
19
|
+
search?: readonly string[];
|
|
20
|
+
/** Order of every page. Omit to keep the array order. */
|
|
21
|
+
sort?: ArrayCollectionSort;
|
|
22
|
+
/** Field paths counted into `page.facets` over every matching item. */
|
|
23
|
+
facets?: readonly string[];
|
|
24
|
+
/** Field path that `collection.get(key)` matches. Omit to leave the Collection without `get()`. */
|
|
25
|
+
key?: string;
|
|
26
|
+
/** Page size when the caller omits `limit` (default `50`). */
|
|
27
|
+
defaultLimit?: number;
|
|
28
|
+
/** Largest accepted `limit` and the most values kept per facet (default `100`). */
|
|
29
|
+
maxLimit?: number;
|
|
43
30
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
31
|
+
/** Items plus an optional content digest. Without `digest`, the Collection hashes the items to bind its cursors. */
|
|
32
|
+
interface ArrayCollectionSnapshot<TItem> {
|
|
33
|
+
digest?: string;
|
|
34
|
+
items: readonly TItem[];
|
|
47
35
|
}
|
|
48
|
-
|
|
36
|
+
type ArrayCollectionLoader<TItem> = (options: {
|
|
37
|
+
signal?: AbortSignal;
|
|
38
|
+
}) => Promise<readonly TItem[] | ArrayCollectionSnapshot<TItem>> | readonly TItem[] | ArrayCollectionSnapshot<TItem>;
|
|
39
|
+
/** Request query accepted by an array Collection route and by `useCollection({ filter })`. */
|
|
40
|
+
type ArrayCollectionQueryInput<TFilter extends string = string> = { [TKey in TFilter]?: string | readonly string[]; } & {
|
|
41
|
+
empty?: TFilter | readonly TFilter[];
|
|
42
|
+
search?: string;
|
|
43
|
+
};
|
|
44
|
+
/** Parsed query that an array Collection evaluates. Values match case-insensitively. */
|
|
45
|
+
type ArrayCollectionQuery<TFilter extends string = string> = { [TKey in TFilter]?: readonly string[]; } & {
|
|
46
|
+
empty?: readonly TFilter[];
|
|
47
|
+
search?: string;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* A Collection source that filters, searches, sorts, counts, and pages an array in memory.
|
|
51
|
+
*
|
|
52
|
+
* `load` runs on every request, so keep the array bounded. Cursors are bound to the data digest and the query:
|
|
53
|
+
* a cursor from changed data or another query is rejected as stale (`409` on the generated route).
|
|
54
|
+
*
|
|
55
|
+
* Pass `schema` to validate every item on load and type the items from its output.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* export const articles = defineCollection({
|
|
59
|
+
* source: array(() => loadArticles(), { filters: ['category'], search: ['title'], facets: ['category'] }),
|
|
60
|
+
* })
|
|
61
|
+
*/
|
|
62
|
+
export declare function array<TSchema extends StandardSchemaV1, const TFilter extends string = never>(load: readonly unknown[] | ArrayCollectionLoader<unknown>, options: ArrayCollectionOptions<TFilter> & {
|
|
63
|
+
schema: TSchema;
|
|
64
|
+
}): ProviderCollectionSource<StandardSchemaV1.InferOutput<TSchema>, ArrayCollectionQuery<TFilter>, ArrayCollectionQueryInput<TFilter>>;
|
|
65
|
+
export declare function array<TItem, const TFilter extends string = never>(load: readonly TItem[] | ArrayCollectionLoader<TItem>, options?: ArrayCollectionOptions<TFilter> & {
|
|
66
|
+
schema?: undefined;
|
|
67
|
+
}): ProviderCollectionSource<TItem, ArrayCollectionQuery<TFilter>, ArrayCollectionQueryInput<TFilter>>;
|
|
49
68
|
//#endregion
|
|
50
|
-
//#region src/core/
|
|
51
|
-
|
|
52
|
-
|
|
69
|
+
//#region src/core/split-source.d.ts
|
|
70
|
+
/** One part of a parent item. Its key is unique inside the parent and has no `#`. */
|
|
71
|
+
type SplitSourcePart = SourceItem<string, unknown, object>;
|
|
72
|
+
interface SplitSourceOptions<TSource extends Source, TPart extends SplitSourcePart> {
|
|
73
|
+
/** The Source whose items are split. */
|
|
74
|
+
source: TSource;
|
|
75
|
+
/** Defaults to the parent Source name. */
|
|
76
|
+
name?: string;
|
|
77
|
+
/** Returns the parts of one parent item, in order. Return an empty array to skip the item. */
|
|
78
|
+
split(item: SourceEntry<TSource>): readonly TPart[] | Promise<readonly TPart[]>;
|
|
53
79
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
80
|
+
/** A part's key: the parent key, `#`, and the part key. */
|
|
81
|
+
type SplitSourceKey<TSource extends Source> = `${SourceKey<TSource>}#${string}`;
|
|
82
|
+
/** A part as the split Source returns it: its full key, and the parent's path when the part has none. */
|
|
83
|
+
type SplitSourceItem<TSource extends Source, TPart extends SplitSourcePart> = Omit<TPart, "key"> & {
|
|
84
|
+
key: SplitSourceKey<TSource>;
|
|
85
|
+
};
|
|
86
|
+
/** A Source with one item for each part of another Source's items. */
|
|
87
|
+
type SplitSourceMeta<TSource extends Source> = NonNullable<TSource["getMeta"]> extends ((...args: any[]) => infer TResult) ? TResult : Promise<undefined>;
|
|
88
|
+
type SplitSource<TSource extends Source, TPart extends SplitSourcePart> = Omit<Source<SplitSourceKey<TSource>>, "getItem" | "getItems" | "getMeta"> & {
|
|
89
|
+
getItem(key: SplitSourceKey<TSource>, ctx: SourceContext): Promise<SplitSourceItem<TSource, TPart>>;
|
|
90
|
+
getItems(ctx: SourceContext): Promise<SplitSourceItem<TSource, TPart>[]>;
|
|
91
|
+
getMeta(key: SplitSourceKey<TSource>, ctx: SourceContext): SplitSourceMeta<TSource>;
|
|
92
|
+
};
|
|
93
|
+
/** Split each item of a Source into parts, such as the sections of a Markdown file. Each part is an item. */
|
|
94
|
+
export declare function splitSource<const TSource extends Source, TPart extends SplitSourcePart>(options: SplitSourceOptions<TSource, TPart>): SplitSource<TSource, TPart>;
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region src/core/define.d.ts
|
|
97
|
+
/** Define a loader. Open it with createSource() to bind its runtime context. */
|
|
98
|
+
export declare function defineSource<const TSource extends Source>(source: TSource): TSource;
|
|
99
|
+
//#endregion
|
|
100
|
+
//#region src/core/reader.d.ts
|
|
101
|
+
export declare function createSource<const TSource extends Source>(source: TSource, context?: Partial<SourceContext>): SourceReader<TSource>;
|
|
60
102
|
//#endregion
|
|
61
103
|
//#region src/core/registry.d.ts
|
|
62
|
-
declare function registerSource<const TName extends string, const TSource extends Source>(name: TName, source: TSource): TSource;
|
|
63
|
-
declare function registerSources<const TSources extends Record<string, Source>>(sources: TSources): TSources;
|
|
64
|
-
declare function
|
|
65
|
-
|
|
66
|
-
declare function useSource<TName extends SourceName>(name: TName, context?: Partial<SourceContext>): SourceReader<TName
|
|
104
|
+
export declare function registerSource<const TName extends string, const TSource extends Source>(name: TName, source: TSource): TSource;
|
|
105
|
+
export declare function registerSources<const TSources extends Record<string, Source>>(sources: TSources): TSources;
|
|
106
|
+
export declare function clearSources(): void;
|
|
107
|
+
/** Open a registered definition with the same lifecycle as direct Source readers. */
|
|
108
|
+
export declare function useSource<TName extends SourceName>(name: TName, context?: Partial<SourceContext>): SourceReader<RegisteredSource<TName>>;
|
|
67
109
|
//#endregion
|
|
68
110
|
//#region src/core/errors.d.ts
|
|
69
111
|
type SourceErrorCode = "SOURCE_FAILED" | "SOURCE_NOT_FOUND" | "SOURCE_PATH_INVALID";
|
|
70
112
|
//#endregion
|
|
71
113
|
//#region src/ignores.d.ts
|
|
72
|
-
declare const sourceIgnores: Readonly<{
|
|
114
|
+
export declare const sourceIgnores: Readonly<{
|
|
73
115
|
defaults: readonly string[];
|
|
74
116
|
dependencies: readonly string[];
|
|
75
117
|
generated: readonly string[];
|
|
@@ -78,7 +120,187 @@ declare const sourceIgnores: Readonly<{
|
|
|
78
120
|
system: readonly string[];
|
|
79
121
|
}>;
|
|
80
122
|
//#endregion
|
|
81
|
-
//#region src/sources/
|
|
82
|
-
|
|
123
|
+
//#region src/sources/file.d.ts
|
|
124
|
+
interface FileSourcePathOptions<TKey extends string = string> {
|
|
125
|
+
path: string;
|
|
126
|
+
workspacePath?: TKey;
|
|
127
|
+
content?: never;
|
|
128
|
+
mediaType?: string;
|
|
129
|
+
}
|
|
130
|
+
interface FileSourceInlineOptions<TKey extends string = string> {
|
|
131
|
+
workspacePath: TKey;
|
|
132
|
+
content: SourceContent;
|
|
133
|
+
mediaType?: string;
|
|
134
|
+
path?: never;
|
|
135
|
+
}
|
|
136
|
+
type FileSourceOptions<TKey extends string = string> = FileSourcePathOptions<TKey> | FileSourceInlineOptions<TKey>;
|
|
137
|
+
type FileSourceInput<TKey extends string = string> = FileSourceOptions<TKey> | TKey;
|
|
138
|
+
export declare function file<const TKey extends string = string>(input: FileSourceInput<TKey>): SingleFileSource<TKey>;
|
|
139
|
+
//#endregion
|
|
140
|
+
//#region src/sources/files.d.ts
|
|
141
|
+
interface FilesSourceOptions {
|
|
142
|
+
/** Removed from the start of every path, such as the folder that an `import.meta.glob()` pattern starts with. */
|
|
143
|
+
base?: string;
|
|
144
|
+
/** Put before every item's path, like glob()'s `prefix`. Keys stay without it. */
|
|
145
|
+
prefix?: string;
|
|
146
|
+
}
|
|
147
|
+
/** A file's content, or a function that loads it on the first read, such as an `import.meta.glob()` loader. */
|
|
148
|
+
type FilesSourceEntry = SourceContent | (() => SourceContent | Promise<SourceContent>);
|
|
149
|
+
/**
|
|
150
|
+
* A Source of files that the server already holds, keyed by path. A ViteHub build turns `glob()` into this, with the
|
|
151
|
+
* matched files in the server bundle. Call it yourself for files you hold another way.
|
|
152
|
+
*/
|
|
153
|
+
export declare function files(entries: Record<string, FilesSourceEntry>, options?: FilesSourceOptions): FileSource<string>;
|
|
154
|
+
//#endregion
|
|
155
|
+
//#region src/sources/github/types.d.ts
|
|
156
|
+
interface GitHubSourceOptions {
|
|
157
|
+
repo: string;
|
|
158
|
+
ref?: string;
|
|
159
|
+
root?: string;
|
|
160
|
+
/**
|
|
161
|
+
* GitHub token, or a trusted callback that returns one. Omitted: Server Env `VITEHUB_GITHUB_TOKEN`, then `FORGES_GITHUB_TOKEN`.
|
|
162
|
+
* `false`: anonymous reads only.
|
|
163
|
+
*/
|
|
164
|
+
auth?: false | string | (() => Promise<string | undefined> | string | undefined);
|
|
165
|
+
include?: string | string[];
|
|
166
|
+
ignore?: string | readonly string[];
|
|
167
|
+
cache?: false | SourceCacheOptions;
|
|
168
|
+
}
|
|
169
|
+
/** One commit that changed a file, as `GitHubSource.history()` returns it. */
|
|
170
|
+
interface GitHubFileCommit {
|
|
171
|
+
sha: string;
|
|
172
|
+
/** The author date, as an ISO date. */
|
|
173
|
+
date: string;
|
|
174
|
+
/** The author's GitHub login, else the Git author name, else null. */
|
|
175
|
+
author: string | null;
|
|
176
|
+
/** The first line of the commit message. */
|
|
177
|
+
message: string;
|
|
178
|
+
/** The commit page on GitHub. */
|
|
179
|
+
url: string;
|
|
180
|
+
}
|
|
181
|
+
interface GitHubHistoryOptions {
|
|
182
|
+
/** The full commit SHA to read back from. */
|
|
183
|
+
sha: string;
|
|
184
|
+
/** The page, from 1. */
|
|
185
|
+
page: number;
|
|
186
|
+
/** Commits per page, from 1 to 100. */
|
|
187
|
+
perPage: number;
|
|
188
|
+
}
|
|
189
|
+
/** A ref of the repository: a full commit SHA, a branch name, or a pull request number. */
|
|
190
|
+
type GitHubRef = {
|
|
191
|
+
sha: string;
|
|
192
|
+
} | {
|
|
193
|
+
branch: string;
|
|
194
|
+
} | {
|
|
195
|
+
pull: number;
|
|
196
|
+
};
|
|
197
|
+
/** A pull request, as `resolveRef({ pull })` returns it. */
|
|
198
|
+
interface GitHubPullRequest {
|
|
199
|
+
number: number;
|
|
200
|
+
state: "open" | "closed";
|
|
201
|
+
merged: boolean;
|
|
202
|
+
/** The head branch, such as `feat/x`. */
|
|
203
|
+
head: string;
|
|
204
|
+
/** The repository of the head branch, such as `acme/docs`. Null when the fork was deleted. */
|
|
205
|
+
headRepo: string | null;
|
|
206
|
+
/** The base branch, such as `main`. */
|
|
207
|
+
base: string;
|
|
208
|
+
/** True when the head branch lives in another repository. */
|
|
209
|
+
fork: boolean;
|
|
210
|
+
/** The label names, such as `preview:enabled`. */
|
|
211
|
+
labels: string[];
|
|
212
|
+
}
|
|
213
|
+
/** The commit that a ref points to. `pull` is set for a pull request ref. */
|
|
214
|
+
interface GitHubRefTarget {
|
|
215
|
+
sha: string;
|
|
216
|
+
pull?: GitHubPullRequest;
|
|
217
|
+
}
|
|
218
|
+
/** What github() returns: a File Source with every optional method. */
|
|
219
|
+
type GitHubSource = FileSource<string> & Required<Pick<FileSource<string>, "getItems" | "getMeta" | "resolveRevision">> & {
|
|
220
|
+
/** Whether reads send a token: `auth`, or the Server Env token when `auth` is omitted. */
|
|
221
|
+
authenticated(): Promise<boolean>;
|
|
222
|
+
/**
|
|
223
|
+
* The commits that changed one file, newest first, from `sha` back. It reads `GET /repos/{owner}/{repo}/commits`
|
|
224
|
+
* with `path`, so it does not follow renames. `more` is true when GitHub has another page.
|
|
225
|
+
*/
|
|
226
|
+
history(key: string, options: GitHubHistoryOptions): Promise<{
|
|
227
|
+
commits: GitHubFileCommit[];
|
|
228
|
+
more: boolean;
|
|
229
|
+
}>;
|
|
230
|
+
/**
|
|
231
|
+
* The latest commit that changed each file, from the full commit SHA `sha` back. A key without commits has no entry.
|
|
232
|
+
* It asks GitHub GraphQL for 150 files per request, so 2,600 files cost 18 requests. Like `history()`, it does not
|
|
233
|
+
* follow renames.
|
|
234
|
+
*/
|
|
235
|
+
latest(keys: readonly string[], options: {
|
|
236
|
+
sha: string;
|
|
237
|
+
}): Promise<Map<string, GitHubFileCommit>>;
|
|
238
|
+
/**
|
|
239
|
+
* The keys of the Source that a commit from `base` to `head` changed, with the old key of a renamed file. A file that
|
|
240
|
+
* one commit edits and a later one reverts is in the list. One compare request, plus one commit request per commit
|
|
241
|
+
* when there is more than one. Undefined when `head` does not descend from `base`, when more than 20 commits lie
|
|
242
|
+
* between them, or when more files changed than GitHub lists.
|
|
243
|
+
*/
|
|
244
|
+
changes(base: string, head: string): Promise<string[] | undefined>;
|
|
245
|
+
/**
|
|
246
|
+
* The keys of the Source that a pull request adds or changes, from `GET /repos/{owner}/{repo}/pulls/{number}/files`.
|
|
247
|
+
* A renamed file gives its new key, and removed files are not listed. Undefined when the repository has no such pull
|
|
248
|
+
* request. GitHub lists at most 3,000 files of a pull request.
|
|
249
|
+
*/
|
|
250
|
+
pullChanges(number: number): Promise<string[] | undefined>;
|
|
251
|
+
/**
|
|
252
|
+
* The commit that a ref of the repository points to now. A branch must match its full name, and a SHA must be a full
|
|
253
|
+
* commit SHA. Undefined when the repository has no such commit, branch, or pull request.
|
|
254
|
+
*/
|
|
255
|
+
resolveRef(ref: GitHubRef, options?: {
|
|
256
|
+
signal?: AbortSignal;
|
|
257
|
+
}): Promise<GitHubRefTarget | undefined>;
|
|
258
|
+
/**
|
|
259
|
+
* Whether the history of the Source ref (the `ref` option, or the default branch) contains a commit: GitHub compares
|
|
260
|
+
* the ref with the commit and answers `behind` or `identical`. False for a commit that shares no history with it.
|
|
261
|
+
*/
|
|
262
|
+
contains(sha: string, options?: {
|
|
263
|
+
signal?: AbortSignal;
|
|
264
|
+
}): Promise<boolean>;
|
|
265
|
+
/**
|
|
266
|
+
* The pull requests whose head commit is this commit, open or closed, from this repository or a fork. GitHub does not
|
|
267
|
+
* list a fork pull request for its commits, so a fork pull request counts only while it is one of the 100 most recently
|
|
268
|
+
* updated open pull requests.
|
|
269
|
+
*/
|
|
270
|
+
pullsAt(sha: string, options?: {
|
|
271
|
+
signal?: AbortSignal;
|
|
272
|
+
}): Promise<GitHubPullRequest[]>;
|
|
273
|
+
};
|
|
274
|
+
//#endregion
|
|
275
|
+
//#region src/sources/github/lazy.d.ts
|
|
276
|
+
/**
|
|
277
|
+
* github() as the Source root exports it. The loader imports Node built-ins, ocache, and the forge client, so it loads
|
|
278
|
+
* on the first read. A bundle that imports the root and never calls github() keeps none of them.
|
|
279
|
+
*/
|
|
280
|
+
export declare function github(options: GitHubSourceOptions): GitHubSource;
|
|
281
|
+
//#endregion
|
|
282
|
+
//#region src/sources/glob.d.ts
|
|
283
|
+
interface GlobSourceOptions {
|
|
284
|
+
cwd?: string;
|
|
285
|
+
dot?: boolean;
|
|
286
|
+
followSymlinks?: boolean;
|
|
287
|
+
/** Portable glob patterns: backslashes are separators, never escapes. Use [*], [?], [[] for literals. */
|
|
288
|
+
include: string | string[];
|
|
289
|
+
/** Uses the same portable separator and literal syntax as include. */
|
|
290
|
+
ignore?: string | readonly string[];
|
|
291
|
+
keyCache?: boolean;
|
|
292
|
+
prefix?: string;
|
|
293
|
+
}
|
|
294
|
+
/** A pattern such as `content/docs/**\/*.md`, or the options. */
|
|
295
|
+
type GlobInput = string | GlobSourceOptions;
|
|
296
|
+
/**
|
|
297
|
+
* Project files that match a pattern, such as `glob("content/docs/**\/*.md")`. Under `vite dev` they are read from
|
|
298
|
+
* disk, so new files show up at once. A ViteHub build bundles a call with literal options into the server, so hosts
|
|
299
|
+
* without a file system, such as Cloudflare Workers, serve the same files.
|
|
300
|
+
*/
|
|
301
|
+
export declare function glob(input: GlobInput): FileSource<string>;
|
|
302
|
+
//#endregion
|
|
303
|
+
//#region src/sources/markdown.d.ts
|
|
304
|
+
export declare function markdown<const TKey extends string = string>(options: FileSourceOptions<TKey>): SingleFileSource<TKey>;
|
|
83
305
|
//#endregion
|
|
84
|
-
export { type AnyCollection, type Collection, type CollectionClientItem, CollectionCursorError, type CollectionCursorValue, type CollectionItem, type CollectionLoadOptions, type CollectionLoader, type CollectionOptions, type CollectionPage, type CollectionPageOptions, type CollectionQuery, type CollectionQueryInput, type CollectionRequestQuery, type ReadSourceOptions, type ReadSourceResult, type Source, type SourceCacheOptions, type SourceContent, type SourceContext, type SourceData, type SourceErrorCode, type SourceItem, type SourceKey, type SourceListEntry, type SourceMap, type SourceMetadata, type SourceName, type SourceReader, type SourceRevision,
|
|
306
|
+
export { type AnyCollection, type AnyCollectionSource, type ArrayCollectionLoader, type ArrayCollectionOptions, type ArrayCollectionQuery, type ArrayCollectionQueryInput, type ArrayCollectionSnapshot, type ArrayCollectionSort, type Collection, type CollectionAccess, type CollectionClientItem, CollectionCursorError, type CollectionCursorErrorOptions, type CollectionCursorErrorReason, type CollectionCursorValue, type CollectionFacetValue, type CollectionFacets, type CollectionItem, type CollectionLoadOptions, type CollectionLoader, type CollectionOptions, type CollectionPage, type CollectionPageOptions, type CollectionQuery, type CollectionQueryBuilder, type CollectionQueryInput, type CollectionReadOptions, type CollectionRequestQuery, type CollectionSource, type CursorCollectionSource, type FileSource, type FileSourceInlineOptions, type FileSourceOptions, type FileSourcePathOptions, type FilesSourceEntry, type FilesSourceOptions, type GitHubFileCommit, type GitHubHistoryOptions, type GitHubPullRequest, type GitHubRef, type GitHubRefTarget, type GitHubSource, type GitHubSourceOptions, type GlobInput, type GlobSourceOptions, type ProviderCollectionLoader, type ProviderCollectionOptions, type ProviderCollectionPage, type ProviderCollectionSource, type ReadSourceOptions, type ReadSourceResult, type RegisteredSource, type SingleFileSource, type Source, type SourceCacheOptions, type SourceCollectionOptions, type SourceContent, type SourceContext, type SourceData, type SourceEntry, type SourceErrorCode, type SourceFile, type SourceItem, type SourceKey, type SourceListEntry, type SourceMap, type SourceMetadata, type SourceName, type SourceReader, type SourceRevision, type SplitSource, type SplitSourceItem, type SplitSourceKey, type SplitSourceOptions, type SplitSourcePart, defineCollection };
|