@vite-hub/source 0.0.4 → 0.1.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 +219 -82
- package/dist/{auth-Ddw55OUG.js → auth-B-tX_rp0.js} +255 -90
- package/dist/{client-CDfTmtQu.js → client-BwstxtdY.js} +584 -207
- package/dist/client.d.ts +27 -10
- package/dist/client.js +71 -13
- package/dist/collection-B_4w_J8h.d.ts +257 -0
- package/dist/{collection-B8pXGM2d.js → collection-cursor-WzV1Jd6v.js} +37 -54
- package/dist/collection-route-BplWPxHR.js +10 -0
- package/dist/drizzle.d.ts +41 -0
- package/dist/drizzle.js +89 -0
- package/dist/error-diagnostics-X0kuFjBT.js +51 -0
- package/dist/file-BX0FSvgE.js +60 -0
- package/dist/{file-EQ3AjVM6.d.ts → file-DadN9dbN.d.ts} +2 -3
- package/dist/file.d.ts +1 -1
- package/dist/file.js +1 -1
- package/dist/files.d.ts +15 -0
- package/dist/files.js +38 -0
- package/dist/github.d.ts +8 -5
- package/dist/github.js +725 -426
- package/dist/glob-BmFqTvJY.js +993 -0
- package/dist/glob.d.ts +12 -4
- package/dist/glob.js +1 -894
- package/dist/index.d.ts +118 -27
- package/dist/index.js +623 -14
- package/dist/markdown.d.ts +4 -6
- package/dist/markdown.js +2 -2
- package/dist/mcp.d.ts +3 -4
- package/dist/mcp.js +302 -5920
- package/dist/{file-BSWQg9Qv.js → mrmime-40h5OOIp.js} +1 -56
- package/dist/{path-CUhvUREm.js → path-BS8rYm0n.js} +60 -40
- package/dist/{path-BzmU4Eni.js → path-DOBpV8ol.js} +3 -7
- package/dist/server.d.ts +256 -6
- package/dist/server.js +90 -12
- package/dist/{sse-CE9Q2JqM.js → sse-D9gqqNPj.js} +50 -9
- package/dist/{streamableHttp-BszaXLmg.js → streamableHttp-BL-E7pl5.js} +40 -22
- package/dist/types-BigOktIj.d.ts +93 -0
- package/dist/{types-AIBmt_m6.js → types-CoWcW8oz.js} +2502 -1187
- package/dist/vite.d.ts +134 -13
- package/dist/vite.js +1734 -79
- package/package.json +55 -36
- 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/registry-C8skfCSV.js +0 -120
- package/dist/types-Bu3WvNX9.d.ts +0 -71
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { g as CollectionQueryInput, v as CollectionRequestQuery, y as CollectionSource } from "./collection-B_4w_J8h.js";
|
|
2
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
3
|
+
//#region src/drizzle.d.ts
|
|
4
|
+
interface TableShape {
|
|
5
|
+
readonly _: {
|
|
6
|
+
readonly columns: Record<string, unknown>;
|
|
7
|
+
};
|
|
8
|
+
readonly $inferSelect: Record<string, unknown>;
|
|
9
|
+
}
|
|
10
|
+
type TableColumn<TTable extends TableShape> = TTable["_"]["columns"][keyof TTable["_"]["columns"]];
|
|
11
|
+
type QueryOutput<TSchema extends StandardSchemaV1<unknown, object> | undefined> = TSchema extends StandardSchemaV1<unknown, infer TOutput extends object> ? TOutput : CollectionRequestQuery;
|
|
12
|
+
type QueryInput<TSchema extends StandardSchemaV1<unknown, object> | undefined> = TSchema extends StandardSchemaV1<infer TInput extends object, object> ? CollectionQueryInput<TInput> : CollectionRequestQuery;
|
|
13
|
+
export interface TableSourceOptions<TTable extends TableShape, TQuerySchema extends StandardSchemaV1<unknown, object> | undefined = undefined> {
|
|
14
|
+
db: {
|
|
15
|
+
select(): unknown;
|
|
16
|
+
};
|
|
17
|
+
defaultLimit?: number;
|
|
18
|
+
maxLimit?: number;
|
|
19
|
+
orderBy: {
|
|
20
|
+
column: TableColumn<TTable>;
|
|
21
|
+
direction: "asc" | "desc";
|
|
22
|
+
tieBreaker: TableColumn<TTable>;
|
|
23
|
+
};
|
|
24
|
+
querySchema?: TQuerySchema;
|
|
25
|
+
table: TTable;
|
|
26
|
+
where?: (context: {
|
|
27
|
+
query: QueryOutput<TQuerySchema>;
|
|
28
|
+
table: TTable;
|
|
29
|
+
}) => {
|
|
30
|
+
getSQL(): unknown;
|
|
31
|
+
} | undefined;
|
|
32
|
+
}
|
|
33
|
+
type KeysetCursor = readonly (boolean | null | number | string)[];
|
|
34
|
+
/** Read a Drizzle SQLite table as a Collection source with keyset pagination. */
|
|
35
|
+
export declare function table<TTable extends TableShape, TQuerySchema extends StandardSchemaV1<unknown, object>>(options: TableSourceOptions<TTable, TQuerySchema> & {
|
|
36
|
+
querySchema: TQuerySchema;
|
|
37
|
+
}): CollectionSource<TTable["$inferSelect"], StandardSchemaV1.InferOutput<TQuerySchema>, KeysetCursor, KeysetCursor, QueryInput<TQuerySchema>>;
|
|
38
|
+
export declare function table<TTable extends TableShape>(options: TableSourceOptions<TTable> & {
|
|
39
|
+
querySchema?: undefined;
|
|
40
|
+
}): CollectionSource<TTable["$inferSelect"], CollectionRequestQuery, KeysetCursor>;
|
|
41
|
+
//#endregion
|
package/dist/drizzle.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { t as sourceErrorDiagnostics } from "./error-diagnostics-X0kuFjBT.js";
|
|
2
|
+
import { and, asc, desc, eq, getTableColumns, gt, lt, or } from "drizzle-orm";
|
|
3
|
+
//#region src/drizzle.ts
|
|
4
|
+
const requestQuerySchema = { "~standard": {
|
|
5
|
+
version: 1,
|
|
6
|
+
vendor: "vite-hub",
|
|
7
|
+
validate(value) {
|
|
8
|
+
if (Object(value) !== value || Array.isArray(value)) return { issues: [{ message: "Collection query must be an object." }] };
|
|
9
|
+
return { value };
|
|
10
|
+
}
|
|
11
|
+
} };
|
|
12
|
+
function isCursorScalar(value) {
|
|
13
|
+
return value === null || value === true || value === false || String(value) === value || Number(value) === value && Number.isFinite(Number(value));
|
|
14
|
+
}
|
|
15
|
+
function driverType(column) {
|
|
16
|
+
if ([
|
|
17
|
+
"boolean",
|
|
18
|
+
"date",
|
|
19
|
+
"number"
|
|
20
|
+
].includes(column.dataType)) return "number";
|
|
21
|
+
if (column.dataType === "string") return "string";
|
|
22
|
+
throw sourceErrorDiagnostics.SOURCE_R0029({ message: "[vitehub] Collection orderBy columns must encode as number or string values." });
|
|
23
|
+
}
|
|
24
|
+
function isColumnDriverValue(column, type, value) {
|
|
25
|
+
if (!(type === "string" ? String(value) === value : Number(value) === value && Number.isFinite(Number(value)))) return false;
|
|
26
|
+
try {
|
|
27
|
+
return Object.is(column.mapToDriverValue(column.mapFromDriverValue(value)), value);
|
|
28
|
+
} catch {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function keysetCursorSchema(columns) {
|
|
33
|
+
const types = columns.map(driverType);
|
|
34
|
+
return { "~standard": {
|
|
35
|
+
version: 1,
|
|
36
|
+
vendor: "vite-hub",
|
|
37
|
+
validate(value) {
|
|
38
|
+
if (!Array.isArray(value) || value.length !== columns.length || !value.every((entry, index) => isColumnDriverValue(columns[index], types[index], entry))) return { issues: [{ message: "Collection keyset cursor is malformed." }] };
|
|
39
|
+
return { value };
|
|
40
|
+
}
|
|
41
|
+
} };
|
|
42
|
+
}
|
|
43
|
+
function columnKey(table, column) {
|
|
44
|
+
const entry = Object.entries(getTableColumns(table)).find(([, candidate]) => candidate === column);
|
|
45
|
+
if (!entry) throw sourceErrorDiagnostics.SOURCE_R0030({ message: "[vitehub] Collection orderBy columns must belong to its table." });
|
|
46
|
+
return entry[0];
|
|
47
|
+
}
|
|
48
|
+
function driverValue(column, value) {
|
|
49
|
+
const encoded = column.mapToDriverValue(value);
|
|
50
|
+
if (!isCursorScalar(encoded)) throw sourceErrorDiagnostics.SOURCE_R0031({ message: "[vitehub] Collection orderBy columns must encode as scalar values." });
|
|
51
|
+
return encoded;
|
|
52
|
+
}
|
|
53
|
+
function cursorWhere(columns, cursor, direction) {
|
|
54
|
+
const compare = direction === "asc" ? gt : lt;
|
|
55
|
+
return or(...columns.map((column, index) => and(...columns.slice(0, index).map((previous, previousIndex) => eq(previous, previous.mapFromDriverValue(cursor[previousIndex]))), compare(column, column.mapFromDriverValue(cursor[index])))));
|
|
56
|
+
}
|
|
57
|
+
function table(input) {
|
|
58
|
+
const options = input;
|
|
59
|
+
const databaseTable = options.table;
|
|
60
|
+
const database = options.db;
|
|
61
|
+
const columns = [options.orderBy.column, options.orderBy.tieBreaker];
|
|
62
|
+
const keys = columns.map((column) => columnKey(databaseTable, column));
|
|
63
|
+
for (const column of columns) if (!column.notNull) throw sourceErrorDiagnostics.SOURCE_R0032({ message: "[vitehub] Collection orderBy columns must be non-null." });
|
|
64
|
+
const tieBreaker = columns[1];
|
|
65
|
+
if (!tieBreaker.primary && !tieBreaker.isUnique) throw sourceErrorDiagnostics.SOURCE_R0033({ message: "[vitehub] Collection orderBy tieBreaker must be unique." });
|
|
66
|
+
const direction = options.orderBy.direction;
|
|
67
|
+
const order = columns.map((column) => direction === "asc" ? asc(column) : desc(column));
|
|
68
|
+
const querySchema = options.querySchema ?? requestQuerySchema;
|
|
69
|
+
return {
|
|
70
|
+
cursor: (row) => columns.map((column, index) => driverValue(column, row[keys[index]])),
|
|
71
|
+
cursorSchema: keysetCursorSchema(columns),
|
|
72
|
+
defaultLimit: options.defaultLimit,
|
|
73
|
+
async load({ cursor, limit, query, signal }) {
|
|
74
|
+
signal?.throwIfAborted();
|
|
75
|
+
const filter = options.where?.({
|
|
76
|
+
query,
|
|
77
|
+
table: options.table
|
|
78
|
+
});
|
|
79
|
+
const after = cursor ? cursorWhere(columns, cursor, direction) : void 0;
|
|
80
|
+
const rows = await database.select().from(databaseTable).where(and(filter, after)).orderBy(...order).limit(limit);
|
|
81
|
+
signal?.throwIfAborted();
|
|
82
|
+
return rows;
|
|
83
|
+
},
|
|
84
|
+
maxLimit: options.maxLimit,
|
|
85
|
+
querySchema
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
//#endregion
|
|
89
|
+
export { table };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { defineDiagnostics } from "nostics";
|
|
2
|
+
//#region src/error-diagnostics.ts
|
|
3
|
+
const dynamicError = { why: ({ message }) => message === void 0 ? "" : String(message) };
|
|
4
|
+
const sourceErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
5
|
+
docsBase: () => "https://vitehub.dev/docs/reference/diagnostics",
|
|
6
|
+
codes: {
|
|
7
|
+
SOURCE_R0023: dynamicError,
|
|
8
|
+
SOURCE_R0001: dynamicError,
|
|
9
|
+
SOURCE_R0002: dynamicError,
|
|
10
|
+
SOURCE_R0003: dynamicError,
|
|
11
|
+
SOURCE_R0004: dynamicError,
|
|
12
|
+
SOURCE_R0005: dynamicError,
|
|
13
|
+
SOURCE_R0006: dynamicError,
|
|
14
|
+
SOURCE_R0007: dynamicError,
|
|
15
|
+
SOURCE_R0008: dynamicError,
|
|
16
|
+
SOURCE_R0009: dynamicError,
|
|
17
|
+
SOURCE_R0010: dynamicError,
|
|
18
|
+
SOURCE_R0011: dynamicError,
|
|
19
|
+
SOURCE_R0012: dynamicError,
|
|
20
|
+
SOURCE_R0013: dynamicError,
|
|
21
|
+
SOURCE_R0014: dynamicError,
|
|
22
|
+
SOURCE_R0015: dynamicError,
|
|
23
|
+
SOURCE_R0016: dynamicError,
|
|
24
|
+
SOURCE_R0017: dynamicError,
|
|
25
|
+
SOURCE_R0018: dynamicError,
|
|
26
|
+
SOURCE_R0019: dynamicError,
|
|
27
|
+
SOURCE_R0020: dynamicError,
|
|
28
|
+
SOURCE_R0021: dynamicError,
|
|
29
|
+
SOURCE_R0022: dynamicError,
|
|
30
|
+
SOURCE_R0024: dynamicError,
|
|
31
|
+
SOURCE_R0025: dynamicError,
|
|
32
|
+
SOURCE_R0026: dynamicError,
|
|
33
|
+
SOURCE_R0027: dynamicError,
|
|
34
|
+
SOURCE_R0028: dynamicError,
|
|
35
|
+
SOURCE_R0029: dynamicError,
|
|
36
|
+
SOURCE_R0030: dynamicError,
|
|
37
|
+
SOURCE_R0031: dynamicError,
|
|
38
|
+
SOURCE_R0032: dynamicError,
|
|
39
|
+
SOURCE_R0033: dynamicError,
|
|
40
|
+
SOURCE_B0001: dynamicError,
|
|
41
|
+
SOURCE_B0002: dynamicError,
|
|
42
|
+
SOURCE_B0003: dynamicError,
|
|
43
|
+
SOURCE_B0004: dynamicError,
|
|
44
|
+
SOURCE_B0005: dynamicError,
|
|
45
|
+
SOURCE_B0006: dynamicError,
|
|
46
|
+
SOURCE_B0007: dynamicError,
|
|
47
|
+
SOURCE_B0008: dynamicError
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
//#endregion
|
|
51
|
+
export { sourceErrorDiagnostics as t };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { t as sourceErrorDiagnostics } from "./error-diagnostics-X0kuFjBT.js";
|
|
2
|
+
import { i as sourceError, n as normalizeSafeSourcePath, o as sourcePathError, r as normalizeSourcePath } from "./path-DOBpV8ol.js";
|
|
3
|
+
import { t as lookup } from "./mrmime-40h5OOIp.js";
|
|
4
|
+
//#region src/sources/file.ts
|
|
5
|
+
function normalizeFileSourceOptions(input) {
|
|
6
|
+
return typeof input === "string" ? { path: input } : input;
|
|
7
|
+
}
|
|
8
|
+
function sourceKey(options) {
|
|
9
|
+
if (Object.hasOwn(options, "workspacePath") && options.workspacePath) return normalizeSafeSourcePath(options.workspacePath);
|
|
10
|
+
if (Object.hasOwn(options, "path") && options.path) return normalizeSourcePath(normalizeSafeSourcePath(options.path));
|
|
11
|
+
throw sourceErrorDiagnostics.SOURCE_R0017({ message: "[vitehub] file requires a path or workspacePath." });
|
|
12
|
+
}
|
|
13
|
+
function resolveSourceRoot(ctx) {
|
|
14
|
+
return ctx.sourceRootDir || ctx.rootDir;
|
|
15
|
+
}
|
|
16
|
+
async function readSourceFile(options, ctx) {
|
|
17
|
+
if (!Object.hasOwn(options, "path") || !options.path) throw sourceErrorDiagnostics.SOURCE_R0018({ message: "[vitehub] file requires path when content is not provided." });
|
|
18
|
+
const { readFile } = await import("node:fs/promises");
|
|
19
|
+
const content = await readFile(await resolveSafeSourceFilePath(options.path, ctx));
|
|
20
|
+
return content.byteOffset === 0 && content.byteLength === content.buffer.byteLength ? new Uint8Array(content.buffer) : new Uint8Array(content);
|
|
21
|
+
}
|
|
22
|
+
async function resolveSafeSourceFilePath(path, ctx) {
|
|
23
|
+
const { realpath } = await import("node:fs/promises");
|
|
24
|
+
const { isAbsolute, relative, resolve, sep } = await import("node:path");
|
|
25
|
+
const root = await realpath(resolve(resolveSourceRoot(ctx)));
|
|
26
|
+
const target = await realpath(resolve(root, normalizeSafeSourcePath(path)));
|
|
27
|
+
const rel = relative(root, target);
|
|
28
|
+
if (rel === ".." || rel.startsWith(`..${sep}`) || isAbsolute(rel)) throw sourcePathError(path);
|
|
29
|
+
return target;
|
|
30
|
+
}
|
|
31
|
+
function file(input) {
|
|
32
|
+
const options = normalizeFileSourceOptions(input);
|
|
33
|
+
const key = sourceKey(options);
|
|
34
|
+
const mediaType = Object.hasOwn(options, "mediaType") && options.mediaType ? options.mediaType : lookup(key);
|
|
35
|
+
return {
|
|
36
|
+
name: "file",
|
|
37
|
+
async getKeys() {
|
|
38
|
+
return [key];
|
|
39
|
+
},
|
|
40
|
+
async getMeta(requestedKey, ctx) {
|
|
41
|
+
if (requestedKey !== key) return;
|
|
42
|
+
if (!Object.hasOwn(options, "path") || !options.path) return;
|
|
43
|
+
const { stat } = await import("node:fs/promises");
|
|
44
|
+
const info = await stat(await resolveSafeSourceFilePath(options.path, ctx));
|
|
45
|
+
return { digest: `${info.size}:${info.mtimeMs}` };
|
|
46
|
+
},
|
|
47
|
+
async getItem(requestedKey, ctx) {
|
|
48
|
+
if (requestedKey !== key) throw sourceError(`[vitehub] file could not find ${JSON.stringify(requestedKey)}.`);
|
|
49
|
+
const content = Object.hasOwn(options, "content") && options.content !== void 0 ? options.content : await readSourceFile(options, ctx);
|
|
50
|
+
return {
|
|
51
|
+
key,
|
|
52
|
+
path: key,
|
|
53
|
+
content,
|
|
54
|
+
mediaType
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
//#endregion
|
|
60
|
+
export { file as t };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { s as SourceContent, t as FileSource } from "./types-BigOktIj.js";
|
|
3
2
|
//#region src/sources/file.d.ts
|
|
4
3
|
interface FileSourcePathOptions<TKey extends string = string> {
|
|
5
4
|
path: string;
|
|
@@ -15,6 +14,6 @@ interface FileSourceInlineOptions<TKey extends string = string> {
|
|
|
15
14
|
}
|
|
16
15
|
type FileSourceOptions<TKey extends string = string> = FileSourcePathOptions<TKey> | FileSourceInlineOptions<TKey>;
|
|
17
16
|
type FileSourceInput<TKey extends string = string> = FileSourceOptions<TKey> | TKey;
|
|
18
|
-
declare function file<const TKey extends string = string>(input: FileSourceInput<TKey>):
|
|
17
|
+
declare function file<const TKey extends string = string>(input: FileSourceInput<TKey>): FileSource<TKey>;
|
|
19
18
|
//#endregion
|
|
20
19
|
export { file as i, FileSourceOptions as n, FileSourcePathOptions as r, FileSourceInlineOptions as t };
|
package/dist/file.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as file, n as FileSourceOptions, r as FileSourcePathOptions, t as FileSourceInlineOptions } from "./file-
|
|
1
|
+
import { i as file, n as FileSourceOptions, r as FileSourcePathOptions, t as FileSourceInlineOptions } from "./file-DadN9dbN.js";
|
|
2
2
|
export { type FileSourceInlineOptions, type FileSourceOptions, type FileSourcePathOptions, file };
|
package/dist/file.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as file } from "./file-
|
|
1
|
+
import { t as file } from "./file-BX0FSvgE.js";
|
|
2
2
|
export { file };
|
package/dist/files.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { s as SourceContent, t as FileSource } from "./types-BigOktIj.js";
|
|
2
|
+
//#region src/sources/files.d.ts
|
|
3
|
+
interface FilesSourceOptions {
|
|
4
|
+
/** Removed from the start of every path, such as the folder that an `import.meta.glob()` pattern starts with. */
|
|
5
|
+
base?: string;
|
|
6
|
+
/** Put before every item's path, like glob()'s `prefix`. Keys stay without it. */
|
|
7
|
+
prefix?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* A Source of files that the server already holds, keyed by path. A ViteHub build turns `glob()` into this, with the
|
|
11
|
+
* matched files in the server bundle. Call it yourself for files you hold another way.
|
|
12
|
+
*/
|
|
13
|
+
export declare function files(entries: Record<string, SourceContent>, options?: FilesSourceOptions): FileSource<string>;
|
|
14
|
+
//#endregion
|
|
15
|
+
export type { FilesSourceOptions };
|
package/dist/files.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { i as sourceError, n as normalizeSafeSourcePath, r as normalizeSourcePath } from "./path-DOBpV8ol.js";
|
|
2
|
+
import { t as lookup } from "./mrmime-40h5OOIp.js";
|
|
3
|
+
//#region src/sources/files.ts
|
|
4
|
+
/**
|
|
5
|
+
* A Source of files that the server already holds, keyed by path. A ViteHub build turns `glob()` into this, with the
|
|
6
|
+
* matched files in the server bundle. Call it yourself for files you hold another way.
|
|
7
|
+
*/
|
|
8
|
+
function files(entries, options = {}) {
|
|
9
|
+
const base = options.base ? `${options.base.replace(/\\/g, "/").replace(/\/+$/, "")}/` : "";
|
|
10
|
+
const items = /* @__PURE__ */ new Map();
|
|
11
|
+
for (const [path, content] of Object.entries(entries)) {
|
|
12
|
+
const portable = path.replace(/\\/g, "/");
|
|
13
|
+
if (base && !portable.startsWith(base)) throw sourceError(`[vitehub] files() path ${JSON.stringify(path)} does not start with base ${JSON.stringify(options.base)}.`);
|
|
14
|
+
const key = normalizeSafeSourcePath(portable.slice(base.length));
|
|
15
|
+
if (items.has(key)) throw sourceError(`[vitehub] files() has two files at ${JSON.stringify(key)}.`);
|
|
16
|
+
items.set(key, content);
|
|
17
|
+
}
|
|
18
|
+
const keys = [...items.keys()].sort((left, right) => left.localeCompare(right));
|
|
19
|
+
const prefix = normalizeSafeSourcePath(options.prefix || "", { allowEmpty: true });
|
|
20
|
+
return {
|
|
21
|
+
name: "files",
|
|
22
|
+
async getKeys() {
|
|
23
|
+
return keys.slice();
|
|
24
|
+
},
|
|
25
|
+
async getItem(key) {
|
|
26
|
+
const content = items.get(key);
|
|
27
|
+
if (content === void 0) throw sourceError(`[vitehub] files() could not find ${JSON.stringify(key)}.`);
|
|
28
|
+
return {
|
|
29
|
+
key,
|
|
30
|
+
path: normalizeSourcePath(prefix ? `${prefix}/${key}` : key),
|
|
31
|
+
content,
|
|
32
|
+
mediaType: lookup(key)
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
//#endregion
|
|
38
|
+
export { files };
|
package/dist/github.d.ts
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { o as SourceCacheOptions, t as FileSource } from "./types-BigOktIj.js";
|
|
3
2
|
//#region src/sources/github/types.d.ts
|
|
4
3
|
interface GitHubSourceOptions {
|
|
5
4
|
repo: string;
|
|
6
5
|
ref?: string;
|
|
7
6
|
root?: string;
|
|
8
|
-
|
|
7
|
+
/**
|
|
8
|
+
* GitHub token, or a trusted callback that returns one. Omitted: Server Env `VITEHUB_GITHUB_TOKEN`, then `FORGES_GITHUB_TOKEN`.
|
|
9
|
+
* `false`: anonymous reads only.
|
|
10
|
+
*/
|
|
11
|
+
auth?: false | string | (() => Promise<string | undefined> | string | undefined);
|
|
9
12
|
include?: string | string[];
|
|
10
13
|
ignore?: string | readonly string[];
|
|
11
14
|
cache?: false | SourceCacheOptions;
|
|
12
15
|
}
|
|
13
16
|
//#endregion
|
|
14
17
|
//#region src/sources/github/index.d.ts
|
|
15
|
-
declare function github(options: GitHubSourceOptions):
|
|
18
|
+
export declare function github(options: GitHubSourceOptions): FileSource<string>;
|
|
16
19
|
//#endregion
|
|
17
|
-
export {
|
|
20
|
+
export type { GitHubSourceOptions };
|