@vite-hub/source 0.1.0 → 0.3.1

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.
Files changed (48) hide show
  1. package/README.md +83 -49
  2. package/dist/client.d.ts +1 -1
  3. package/dist/client.js +30 -4
  4. package/dist/{collection-B_4w_J8h.d.ts → collection-B8sgxw5-.d.ts} +52 -19
  5. package/dist/collection-C0Rvrx3p.js +297 -0
  6. package/dist/drizzle.d.ts +11 -4
  7. package/dist/drizzle.js +6 -8
  8. package/dist/error-diagnostics-ClQKdi7c.js +194 -0
  9. package/dist/github-D5S0dEZe.js +1312 -0
  10. package/dist/{glob-BmFqTvJY.js → glob-DmdMVqjx.js} +1 -2
  11. package/dist/index.d.ts +186 -55
  12. package/dist/index.js +152 -207
  13. package/dist/invariant-DolT9EEx.js +22 -0
  14. package/dist/mcp.d.ts +1 -1
  15. package/dist/mcp.js +25 -140
  16. package/dist/object-CtSHeGQO.js +17 -0
  17. package/dist/{path-BS8rYm0n.js → path-DFlSryRA.js} +32 -2
  18. package/dist/root-DJNmqCEW.js +11 -0
  19. package/dist/server.d.ts +7 -244
  20. package/dist/server.js +38 -45
  21. package/dist/{types-BigOktIj.d.ts → types-Ln-FxVFn.d.ts} +6 -1
  22. package/dist/vite.d.ts +77 -10
  23. package/dist/vite.js +619 -713
  24. package/package.json +25 -47
  25. package/dist/auth-B-tX_rp0.js +0 -1426
  26. package/dist/client-BwstxtdY.js +0 -8280
  27. package/dist/collection-cursor-WzV1Jd6v.js +0 -124
  28. package/dist/error-diagnostics-X0kuFjBT.js +0 -51
  29. package/dist/file-BX0FSvgE.js +0 -60
  30. package/dist/file-DadN9dbN.d.ts +0 -19
  31. package/dist/file.d.ts +0 -2
  32. package/dist/file.js +0 -2
  33. package/dist/files.d.ts +0 -15
  34. package/dist/files.js +0 -38
  35. package/dist/github.d.ts +0 -20
  36. package/dist/github.js +0 -1332
  37. package/dist/glob.d.ts +0 -23
  38. package/dist/glob.js +0 -2
  39. package/dist/markdown.d.ts +0 -5
  40. package/dist/markdown.js +0 -10
  41. package/dist/mrmime-40h5OOIp.js +0 -448
  42. package/dist/path-DOBpV8ol.js +0 -32
  43. package/dist/sse-D9gqqNPj.js +0 -448
  44. package/dist/streamableHttp-BL-E7pl5.js +0 -509
  45. package/dist/types-CoWcW8oz.js +0 -7590
  46. package/tsconfig.vite.json +0 -6
  47. package/types/source/fallback.d.ts +0 -1
  48. package/types/source/index.d.ts +0 -1
@@ -1,124 +0,0 @@
1
- import { t as sourceErrorDiagnostics } from "./error-diagnostics-X0kuFjBT.js";
2
- import { Diagnostic } from "nostics";
3
- //#region ../internal/src/object.ts
4
- function isPlainObject(value) {
5
- if (value === null || Object(value) !== value || Array.isArray(value)) return false;
6
- return typeof value === "object";
7
- }
8
- function isPlainRecord(value) {
9
- if (!isPlainObject(value)) return false;
10
- const prototype = Object.getPrototypeOf(value);
11
- if (prototype === null) return true;
12
- return Object.getPrototypeOf(prototype) === null && Object.hasOwn(prototype, "constructor") && prototype.constructor?.name === "Object";
13
- }
14
- //#endregion
15
- //#region src/core/schema.ts
16
- async function parseCollectionSchema(schema, value) {
17
- const result = await schema["~standard"].validate(value);
18
- if (result.issues) throw sourceErrorDiagnostics.SOURCE_R0006({ message: result.issues[0]?.message ?? "Collection value is invalid." });
19
- return result.value;
20
- }
21
- //#endregion
22
- //#region src/core/collection-cursor.ts
23
- /** A Collection cursor was rejected. Routes answer `400` for `malformed` and `409` for `stale`. */
24
- var CollectionCursorError = class CollectionCursorError extends Diagnostic {
25
- reason;
26
- constructor(message, options) {
27
- const reason = options?.reason ?? "malformed";
28
- super({
29
- cause: options?.cause,
30
- code: reason === "stale" ? "SOURCE_R0027" : "SOURCE_R0023",
31
- docs: "https://vitehub.dev/docs/reference/diagnostics",
32
- why: message ?? (reason === "stale" ? "[vitehub] Collection cursor is stale. Its data or query changed; reload from the first page." : "[vitehub] Collection cursor is malformed.")
33
- }, CollectionCursorError);
34
- this.name = "CollectionCursorError";
35
- this.reason = reason;
36
- }
37
- };
38
- function encodeBase64Url(value) {
39
- const bytes = new TextEncoder().encode(value);
40
- let binary = "";
41
- for (const byte of bytes) binary += String.fromCharCode(byte);
42
- return btoa(binary).replaceAll("+", "-").replaceAll("/", "_").replaceAll("=", "");
43
- }
44
- function decodeBase64Url(value) {
45
- if (!/^[A-Za-z0-9_-]*$/.test(value) || value.length % 4 === 1) throw new TypeError("Malformed base64url cursor");
46
- const normalized = value.replaceAll("-", "+").replaceAll("_", "/");
47
- const binary = atob(normalized.padEnd(Math.ceil(normalized.length / 4) * 4, "="));
48
- if (btoa(binary).replaceAll("+", "-").replaceAll("/", "_").replaceAll("=", "") !== value) throw new TypeError("Noncanonical base64url cursor");
49
- return new TextDecoder("utf-8", { fatal: true }).decode(Uint8Array.from(binary, (character) => character.charCodeAt(0)));
50
- }
51
- function hasPrimitiveRuntimeTag(value, tag) {
52
- return value !== null && value !== void 0 && Object(value) !== value && Object.prototype.toString.call(value) === tag;
53
- }
54
- function isRuntimeNumber(value) {
55
- return hasPrimitiveRuntimeTag(value, "[object Number]");
56
- }
57
- function isRuntimeObject(value) {
58
- return value !== null && Object(value) === value;
59
- }
60
- function isRuntimeString(value) {
61
- return hasPrimitiveRuntimeTag(value, "[object String]");
62
- }
63
- function isCursorValue(value, ancestors = /* @__PURE__ */ new Set()) {
64
- if (isRuntimeNumber(value)) return Number.isFinite(value) && !Object.is(value, -0);
65
- if (value === null || value === true || value === false || isRuntimeString(value)) return true;
66
- if (!isRuntimeObject(value) || ancestors.has(value)) return false;
67
- ancestors.add(value);
68
- try {
69
- if (Array.isArray(value)) {
70
- const keys = Reflect.ownKeys(value);
71
- if (keys.length !== value.length + 1 || keys.some((key) => key !== "length" && !isRuntimeString(key))) return false;
72
- for (let index = 0; index < value.length; index += 1) {
73
- const descriptor = Object.getOwnPropertyDescriptor(value, String(index));
74
- if (!descriptor?.enumerable || !("value" in descriptor) || !isCursorValue(descriptor.value, ancestors)) return false;
75
- }
76
- return true;
77
- }
78
- if (!isPlainRecord(value)) return false;
79
- for (const key of Reflect.ownKeys(value)) {
80
- if (!isRuntimeString(key)) return false;
81
- const descriptor = Object.getOwnPropertyDescriptor(value, key);
82
- if (!descriptor?.enumerable || !("value" in descriptor) || !isCursorValue(descriptor.value, ancestors)) return false;
83
- }
84
- return true;
85
- } catch {
86
- return false;
87
- } finally {
88
- ancestors.delete(value);
89
- }
90
- }
91
- function encodeCursor(value) {
92
- if (!isCursorValue(value)) throw sourceErrorDiagnostics.SOURCE_R0005({ message: "[vitehub] Collection cursor() must return a JSON-serializable value." });
93
- return encodeBase64Url(JSON.stringify(value));
94
- }
95
- async function decodeCursor(value, schema) {
96
- if (value === void 0) return;
97
- let decoded;
98
- try {
99
- decoded = JSON.parse(decodeBase64Url(value));
100
- } catch (cause) {
101
- throw new CollectionCursorError(void 0, { cause });
102
- }
103
- if (!isCursorValue(decoded)) throw new CollectionCursorError();
104
- try {
105
- const cursor = await parseCollectionSchema(schema, decoded);
106
- if (!isCursorValue(cursor)) throw sourceErrorDiagnostics.SOURCE_R0007({ message: "Collection cursor schema returned an invalid value." });
107
- return cursor;
108
- } catch (cause) {
109
- throw new CollectionCursorError(void 0, { cause });
110
- }
111
- }
112
- /** Bind cursor transport and validation to the Collection's schema once. */
113
- function createCollectionCursorCodec(schema) {
114
- return {
115
- encode(value) {
116
- return encodeCursor(value);
117
- },
118
- decode(value) {
119
- return decodeCursor(value, schema);
120
- }
121
- };
122
- }
123
- //#endregion
124
- export { createCollectionCursorCodec as n, parseCollectionSchema as r, CollectionCursorError as t };
@@ -1,51 +0,0 @@
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 };
@@ -1,60 +0,0 @@
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,19 +0,0 @@
1
- import { s as SourceContent, t as FileSource } from "./types-BigOktIj.js";
2
- //#region src/sources/file.d.ts
3
- interface FileSourcePathOptions<TKey extends string = string> {
4
- path: string;
5
- workspacePath?: TKey;
6
- content?: never;
7
- mediaType?: string;
8
- }
9
- interface FileSourceInlineOptions<TKey extends string = string> {
10
- workspacePath: TKey;
11
- content: SourceContent;
12
- mediaType?: string;
13
- path?: never;
14
- }
15
- type FileSourceOptions<TKey extends string = string> = FileSourcePathOptions<TKey> | FileSourceInlineOptions<TKey>;
16
- type FileSourceInput<TKey extends string = string> = FileSourceOptions<TKey> | TKey;
17
- declare function file<const TKey extends string = string>(input: FileSourceInput<TKey>): FileSource<TKey>;
18
- //#endregion
19
- export { file as i, FileSourceOptions as n, FileSourcePathOptions as r, FileSourceInlineOptions as t };
package/dist/file.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import { i as file, n as FileSourceOptions, r as FileSourcePathOptions, t as FileSourceInlineOptions } from "./file-DadN9dbN.js";
2
- export { type FileSourceInlineOptions, type FileSourceOptions, type FileSourcePathOptions, file };
package/dist/file.js DELETED
@@ -1,2 +0,0 @@
1
- import { t as file } from "./file-BX0FSvgE.js";
2
- export { file };
package/dist/files.d.ts DELETED
@@ -1,15 +0,0 @@
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 DELETED
@@ -1,38 +0,0 @@
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 DELETED
@@ -1,20 +0,0 @@
1
- import { o as SourceCacheOptions, t as FileSource } from "./types-BigOktIj.js";
2
- //#region src/sources/github/types.d.ts
3
- interface GitHubSourceOptions {
4
- repo: string;
5
- ref?: string;
6
- root?: string;
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);
12
- include?: string | string[];
13
- ignore?: string | readonly string[];
14
- cache?: false | SourceCacheOptions;
15
- }
16
- //#endregion
17
- //#region src/sources/github/index.d.ts
18
- export declare function github(options: GitHubSourceOptions): FileSource<string>;
19
- //#endregion
20
- export type { GitHubSourceOptions };