@vite-hub/source 0.1.0 → 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 +83 -49
- package/dist/client.d.ts +1 -1
- package/dist/client.js +30 -4
- package/dist/{collection-B_4w_J8h.d.ts → collection-B8sgxw5-.d.ts} +52 -19
- package/dist/collection-C0Rvrx3p.js +297 -0
- package/dist/drizzle.d.ts +11 -4
- package/dist/drizzle.js +6 -8
- package/dist/error-diagnostics-ClQKdi7c.js +194 -0
- package/dist/github-D5S0dEZe.js +1312 -0
- package/dist/{glob-BmFqTvJY.js → glob-DmdMVqjx.js} +1 -2
- package/dist/index.d.ts +186 -55
- package/dist/index.js +152 -207
- package/dist/invariant-DolT9EEx.js +22 -0
- package/dist/mcp.d.ts +1 -1
- package/dist/mcp.js +25 -140
- package/dist/object-CtSHeGQO.js +17 -0
- package/dist/{path-BS8rYm0n.js → path-DFlSryRA.js} +32 -2
- package/dist/root-DJNmqCEW.js +11 -0
- package/dist/server.d.ts +7 -244
- package/dist/server.js +38 -45
- package/dist/{types-BigOktIj.d.ts → types-Ln-FxVFn.d.ts} +6 -1
- package/dist/vite.d.ts +77 -10
- package/dist/vite.js +619 -713
- package/package.json +25 -47
- package/dist/auth-B-tX_rp0.js +0 -1426
- package/dist/client-BwstxtdY.js +0 -8280
- package/dist/collection-cursor-WzV1Jd6v.js +0 -124
- package/dist/error-diagnostics-X0kuFjBT.js +0 -51
- package/dist/file-BX0FSvgE.js +0 -60
- package/dist/file-DadN9dbN.d.ts +0 -19
- package/dist/file.d.ts +0 -2
- package/dist/file.js +0 -2
- package/dist/files.d.ts +0 -15
- package/dist/files.js +0 -38
- package/dist/github.d.ts +0 -20
- package/dist/github.js +0 -1332
- package/dist/glob.d.ts +0 -23
- package/dist/glob.js +0 -2
- package/dist/markdown.d.ts +0 -5
- package/dist/markdown.js +0 -10
- package/dist/mrmime-40h5OOIp.js +0 -448
- package/dist/path-DOBpV8ol.js +0 -32
- package/dist/sse-D9gqqNPj.js +0 -448
- package/dist/streamableHttp-BL-E7pl5.js +0 -509
- package/dist/types-CoWcW8oz.js +0 -7590
- package/tsconfig.vite.json +0 -6
- package/types/source/fallback.d.ts +0 -1
- package/types/source/index.d.ts +0 -1
package/dist/mcp.js
CHANGED
|
@@ -1,122 +1,5 @@
|
|
|
1
|
-
import { n as matchesAny, t as createPathMatcher } from "./path-
|
|
2
|
-
import { t as sourceErrorDiagnostics } from "./error-diagnostics-
|
|
3
|
-
import { i as sourceError, n as normalizeSafeSourcePath } from "./path-DOBpV8ol.js";
|
|
4
|
-
import { I as ResourceContentsSchema, n as BlobResourceContentsSchema, t as AnnotationsSchema } from "./types-CoWcW8oz.js";
|
|
5
|
-
import { defineDiagnostics } from "nostics";
|
|
6
|
-
//#region ../internal/src/error-diagnostics.ts
|
|
7
|
-
const dynamicError = { why: ({ message }) => message === void 0 ? "" : String(message) };
|
|
8
|
-
const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
9
|
-
docsBase: () => "https://vitehub.dev/docs/reference/diagnostics",
|
|
10
|
-
codes: {
|
|
11
|
-
INTERNAL_R0012: dynamicError,
|
|
12
|
-
INTERNAL_R0013: dynamicError,
|
|
13
|
-
INTERNAL_R0014: {
|
|
14
|
-
why: ({ path }) => `Cannot read Provision State from "${path}".`,
|
|
15
|
-
fix: "Check file access and restore valid JSON while preserving existing resource IDs."
|
|
16
|
-
},
|
|
17
|
-
INTERNAL_R0020: {
|
|
18
|
-
fix: "Give the operation a name like `content.publish`, a description, a section, a kind, an input schema, and a run function.",
|
|
19
|
-
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
20
|
-
},
|
|
21
|
-
INTERNAL_R0021: {
|
|
22
|
-
fix: "Run `vitehub inspect definitions --kind operation` to list the operations of this app.",
|
|
23
|
-
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
24
|
-
},
|
|
25
|
-
INTERNAL_R0022: {
|
|
26
|
-
fix: "Send input that matches the schema of the operation. `vitehub <namespace> <command> --help` shows the fields.",
|
|
27
|
-
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
28
|
-
},
|
|
29
|
-
INTERNAL_R0024: {
|
|
30
|
-
fix: "Start the dev server with `vite dev`, or pass `--url <origin>` of a deployed app with credentials in VITEHUB_CONSOLE_AUTHORIZATION, VITEHUB_CONSOLE_COOKIE, or CF_ACCESS_CLIENT_ID and CF_ACCESS_CLIENT_SECRET.",
|
|
31
|
-
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
32
|
-
},
|
|
33
|
-
INTERNAL_R0023: {
|
|
34
|
-
fix: "Ask for access to the section of this operation.",
|
|
35
|
-
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
36
|
-
},
|
|
37
|
-
INTERNAL_B0001: dynamicError,
|
|
38
|
-
INTERNAL_B0002: dynamicError,
|
|
39
|
-
INTERNAL_B0003: dynamicError,
|
|
40
|
-
INTERNAL_B0004: dynamicError,
|
|
41
|
-
INTERNAL_B0005: dynamicError,
|
|
42
|
-
INTERNAL_B0006: dynamicError,
|
|
43
|
-
INTERNAL_B0007: dynamicError,
|
|
44
|
-
INTERNAL_B0008: dynamicError,
|
|
45
|
-
INTERNAL_B0009: dynamicError,
|
|
46
|
-
INTERNAL_B0010: dynamicError,
|
|
47
|
-
INTERNAL_B0011: dynamicError,
|
|
48
|
-
INTERNAL_B0012: dynamicError,
|
|
49
|
-
INTERNAL_B0013: dynamicError,
|
|
50
|
-
INTERNAL_B0014: dynamicError,
|
|
51
|
-
INTERNAL_B0015: dynamicError,
|
|
52
|
-
INTERNAL_B0016: dynamicError,
|
|
53
|
-
INTERNAL_B0017: dynamicError,
|
|
54
|
-
INTERNAL_B0018: dynamicError,
|
|
55
|
-
INTERNAL_B0019: dynamicError,
|
|
56
|
-
INTERNAL_B0020: dynamicError,
|
|
57
|
-
INTERNAL_B0021: dynamicError,
|
|
58
|
-
INTERNAL_B0022: dynamicError,
|
|
59
|
-
INTERNAL_B0023: dynamicError,
|
|
60
|
-
INTERNAL_B0024: dynamicError,
|
|
61
|
-
INTERNAL_B0025: dynamicError,
|
|
62
|
-
INTERNAL_B0026: dynamicError,
|
|
63
|
-
INTERNAL_B0027: dynamicError,
|
|
64
|
-
INTERNAL_B0028: dynamicError,
|
|
65
|
-
INTERNAL_B0029: dynamicError,
|
|
66
|
-
INTERNAL_B0030: dynamicError,
|
|
67
|
-
INTERNAL_B0031: dynamicError,
|
|
68
|
-
INTERNAL_B0032: dynamicError,
|
|
69
|
-
INTERNAL_B0033: dynamicError,
|
|
70
|
-
INTERNAL_B0034: dynamicError,
|
|
71
|
-
INTERNAL_B0035: dynamicError,
|
|
72
|
-
INTERNAL_B0036: dynamicError,
|
|
73
|
-
INTERNAL_B0037: dynamicError,
|
|
74
|
-
INTERNAL_B0038: dynamicError,
|
|
75
|
-
INTERNAL_B0039: dynamicError,
|
|
76
|
-
INTERNAL_B0040: dynamicError,
|
|
77
|
-
INTERNAL_B0041: dynamicError,
|
|
78
|
-
INTERNAL_B0042: dynamicError,
|
|
79
|
-
INTERNAL_B0043: dynamicError,
|
|
80
|
-
INTERNAL_B0044: dynamicError,
|
|
81
|
-
INTERNAL_B0045: dynamicError,
|
|
82
|
-
INTERNAL_B0046: dynamicError,
|
|
83
|
-
INTERNAL_B0047: dynamicError,
|
|
84
|
-
INTERNAL_B0048: {
|
|
85
|
-
fix: "Rename one of the two operations. A name is `<section>.<verb>` and is unique in the app.",
|
|
86
|
-
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
87
|
-
},
|
|
88
|
-
INTERNAL_B0049: {
|
|
89
|
-
fix: "Set `cli: { namespace, command }` on one of the two operations.",
|
|
90
|
-
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
91
|
-
},
|
|
92
|
-
INTERNAL_B0050: {
|
|
93
|
-
fix: "Rename one of the two operations, or set `mcp: false` on it. MCP tool names replace every character outside letters, digits, `_`, and `-` with `_`.",
|
|
94
|
-
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
95
|
-
},
|
|
96
|
-
INTERNAL_R0025: {
|
|
97
|
-
fix: "Start `vite dev` in the project that you run the command from, or pass `--url` of that server.",
|
|
98
|
-
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
99
|
-
},
|
|
100
|
-
INTERNAL_R0026: {
|
|
101
|
-
why: "The server parsed a destructive operation that the CLI did not confirm.",
|
|
102
|
-
fix: "Review the operation, then run it again with --yes to confirm the change."
|
|
103
|
-
},
|
|
104
|
-
INTERNAL_C0001: dynamicError,
|
|
105
|
-
INTERNAL_C0002: dynamicError,
|
|
106
|
-
INTERNAL_R0001: dynamicError,
|
|
107
|
-
INTERNAL_R0002: dynamicError,
|
|
108
|
-
INTERNAL_R0003: dynamicError,
|
|
109
|
-
INTERNAL_R0004: dynamicError,
|
|
110
|
-
INTERNAL_R0005: dynamicError,
|
|
111
|
-
INTERNAL_R0006: dynamicError,
|
|
112
|
-
INTERNAL_R0007: dynamicError,
|
|
113
|
-
INTERNAL_R0008: dynamicError,
|
|
114
|
-
INTERNAL_R0009: dynamicError,
|
|
115
|
-
INTERNAL_R0010: dynamicError,
|
|
116
|
-
INTERNAL_R0011: dynamicError
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
//#endregion
|
|
1
|
+
import { a as normalizeSafeSourcePath, n as matchesAny, s as sourceError, t as createPathMatcher } from "./path-DFlSryRA.js";
|
|
2
|
+
import { t as sourceErrorDiagnostics } from "./error-diagnostics-ClQKdi7c.js";
|
|
120
3
|
//#region ../internal/src/abort.ts
|
|
121
4
|
/**
|
|
122
5
|
* Runs `task` and rejects as soon as `signal` aborts, without waiting for the task.
|
|
@@ -145,9 +28,7 @@ function abortable(signal, message, task) {
|
|
|
145
28
|
}
|
|
146
29
|
function abortReason(signal, message) {
|
|
147
30
|
if (signal?.reason !== void 0) return signal.reason;
|
|
148
|
-
|
|
149
|
-
error.name = "AbortError";
|
|
150
|
-
return error;
|
|
31
|
+
return new DOMException(message, "AbortError");
|
|
151
32
|
}
|
|
152
33
|
//#endregion
|
|
153
34
|
//#region src/sources/mcp-resources.ts
|
|
@@ -184,14 +65,14 @@ async function createMcpTransport(config) {
|
|
|
184
65
|
if (isMcpTransport(config)) return config;
|
|
185
66
|
const { type = "http", url, ...options } = config;
|
|
186
67
|
if (type === "sse") {
|
|
187
|
-
const { SSEClientTransport } = await import("
|
|
68
|
+
const { SSEClientTransport } = await import("@modelcontextprotocol/sdk/client/sse.js");
|
|
188
69
|
return new SSEClientTransport(new URL(url), options);
|
|
189
70
|
}
|
|
190
|
-
const { StreamableHTTPClientTransport } = await import("
|
|
71
|
+
const { StreamableHTTPClientTransport } = await import("@modelcontextprotocol/sdk/client/streamableHttp.js");
|
|
191
72
|
return new StreamableHTTPClientTransport(new URL(url), options);
|
|
192
73
|
}
|
|
193
74
|
async function createMcpClient(config) {
|
|
194
|
-
const [{ Client }, transport] = await Promise.all([import("
|
|
75
|
+
const [{ Client }, transport] = await Promise.all([import("@modelcontextprotocol/sdk/client/index.js"), createMcpTransport(config.transport)]);
|
|
195
76
|
return {
|
|
196
77
|
client: new Client({
|
|
197
78
|
name: "vitehub-source",
|
|
@@ -309,45 +190,49 @@ function hasOptionalMcpField(value, key, validate) {
|
|
|
309
190
|
function isMcpNumber(value) {
|
|
310
191
|
return typeof value === "number" && Number.isFinite(value);
|
|
311
192
|
}
|
|
312
|
-
|
|
313
|
-
|
|
193
|
+
let mcpSchemas;
|
|
194
|
+
function loadMcpSchemas() {
|
|
195
|
+
return mcpSchemas ??= import("@modelcontextprotocol/sdk/types.js");
|
|
196
|
+
}
|
|
197
|
+
function isMcpMetadata(value, schemas) {
|
|
198
|
+
return schemas.ResourceContentsSchema.shape._meta.safeParse(value).success;
|
|
314
199
|
}
|
|
315
200
|
function isMcpArrayOf(value, validate) {
|
|
316
201
|
return isDenseArray(value) && value.every(validate);
|
|
317
202
|
}
|
|
318
|
-
function isResourceAnnotations(value) {
|
|
319
|
-
return isRecord(value) && hasOptionalMcpField(value, "audience", (audience) => isMcpArrayOf(audience, (role) => role === "assistant" || role === "user")) && hasOptionalMcpString(value, "lastModified") && hasOptionalMcpField(value, "priority", isMcpNumber) && AnnotationsSchema.safeParse(value).success;
|
|
203
|
+
function isResourceAnnotations(value, schemas) {
|
|
204
|
+
return isRecord(value) && hasOptionalMcpField(value, "audience", (audience) => isMcpArrayOf(audience, (role) => role === "assistant" || role === "user")) && hasOptionalMcpString(value, "lastModified") && hasOptionalMcpField(value, "priority", isMcpNumber) && schemas.AnnotationsSchema.safeParse(value).success;
|
|
320
205
|
}
|
|
321
206
|
function isResourceIcon(value) {
|
|
322
207
|
return isRecord(value) && isOwnMcpString(value, "src") && hasOptionalMcpString(value, "mimeType") && hasOptionalMcpField(value, "sizes", (sizes) => isMcpArrayOf(sizes, isMcpString)) && hasOptionalMcpField(value, "theme", (theme) => theme === "dark" || theme === "light");
|
|
323
208
|
}
|
|
324
|
-
function isResourceDescriptor(value) {
|
|
325
|
-
return isRecord(value) && isOwnMcpString(value, "name") && isOwnMcpString(value, "uri") && hasOptionalMcpString(value, "mimeType") && hasOptionalMcpString(value, "title") && hasOptionalMcpString(value, "description") && hasOptionalMcpField(value, "size", isMcpNumber) && hasOptionalMcpField(value, "_meta", isMcpMetadata) && hasOptionalMcpField(value, "annotations", isResourceAnnotations) && hasOptionalMcpField(value, "icons", (icons) => isMcpArrayOf(icons, isResourceIcon));
|
|
209
|
+
function isResourceDescriptor(value, schemas) {
|
|
210
|
+
return isRecord(value) && isOwnMcpString(value, "name") && isOwnMcpString(value, "uri") && hasOptionalMcpString(value, "mimeType") && hasOptionalMcpString(value, "title") && hasOptionalMcpString(value, "description") && hasOptionalMcpField(value, "size", isMcpNumber) && hasOptionalMcpField(value, "_meta", (meta) => isMcpMetadata(meta, schemas)) && hasOptionalMcpField(value, "annotations", (annotations) => isResourceAnnotations(annotations, schemas)) && hasOptionalMcpField(value, "icons", (icons) => isMcpArrayOf(icons, isResourceIcon));
|
|
326
211
|
}
|
|
327
|
-
function isResourceContent(value) {
|
|
328
|
-
if (!isRecord(value) || !isOwnMcpString(value, "uri") || !hasOptionalMcpString(value, "mimeType") || !hasOptionalMcpField(value, "_meta", isMcpMetadata)) return false;
|
|
212
|
+
function isResourceContent(value, schemas) {
|
|
213
|
+
if (!isRecord(value) || !isOwnMcpString(value, "uri") || !hasOptionalMcpString(value, "mimeType") || !hasOptionalMcpField(value, "_meta", (meta) => isMcpMetadata(meta, schemas))) return false;
|
|
329
214
|
const hasTextKey = Object.hasOwn(value, "text");
|
|
330
215
|
const hasBlobKey = Object.hasOwn(value, "blob");
|
|
331
216
|
const hasText = hasTextKey && isMcpString(Reflect.get(value, "text"));
|
|
332
|
-
const hasBlob = hasBlobKey && BlobResourceContentsSchema.safeParse(value).success;
|
|
217
|
+
const hasBlob = hasBlobKey && schemas.BlobResourceContentsSchema.safeParse(value).success;
|
|
333
218
|
return hasText !== hasBlob && (!hasTextKey || hasText) && (!hasBlobKey || hasBlob);
|
|
334
219
|
}
|
|
335
|
-
function parseResourceListPage(value) {
|
|
220
|
+
function parseResourceListPage(value, schemas) {
|
|
336
221
|
if (!isRecord(value)) throw sourceError("[vitehub] mcpResources server returned an invalid listResources response.");
|
|
337
222
|
if (!Object.hasOwn(value, "resources") || Reflect.has(value, "nextCursor") && !Object.hasOwn(value, "nextCursor")) throw sourceError("[vitehub] mcpResources server returned an invalid listResources response.");
|
|
338
223
|
const resources = Reflect.get(value, "resources");
|
|
339
224
|
const nextCursor = Object.hasOwn(value, "nextCursor") ? Reflect.get(value, "nextCursor") : void 0;
|
|
340
|
-
if (!isDenseArray(resources) || resources.some((resource) => !isResourceDescriptor(resource)) || nextCursor !== void 0 && !isMcpString(nextCursor)) throw sourceError("[vitehub] mcpResources server returned an invalid listResources response.");
|
|
225
|
+
if (!isDenseArray(resources) || resources.some((resource) => !isResourceDescriptor(resource, schemas)) || nextCursor !== void 0 && !isMcpString(nextCursor)) throw sourceError("[vitehub] mcpResources server returned an invalid listResources response.");
|
|
341
226
|
return {
|
|
342
227
|
nextCursor,
|
|
343
228
|
resources
|
|
344
229
|
};
|
|
345
230
|
}
|
|
346
|
-
function parseResourceContents(value) {
|
|
231
|
+
function parseResourceContents(value, schemas) {
|
|
347
232
|
if (!isRecord(value)) throw sourceError("[vitehub] mcpResources server returned an invalid readResource response.");
|
|
348
233
|
if (!Object.hasOwn(value, "contents")) throw sourceError("[vitehub] mcpResources server returned an invalid readResource response.");
|
|
349
234
|
const contents = Reflect.get(value, "contents");
|
|
350
|
-
if (!isDenseArray(contents) || contents.some((content) => !isResourceContent(content))) throw sourceError("[vitehub] mcpResources server returned an invalid readResource response.");
|
|
235
|
+
if (!isDenseArray(contents) || contents.some((content) => !isResourceContent(content, schemas))) throw sourceError("[vitehub] mcpResources server returned an invalid readResource response.");
|
|
351
236
|
return contents;
|
|
352
237
|
}
|
|
353
238
|
async function listAllResources(client, request) {
|
|
@@ -359,14 +244,14 @@ async function listAllResources(client, request) {
|
|
|
359
244
|
if (seenCursors.has(cursor)) throw sourceError("[vitehub] mcpResources server returned the same pagination cursor twice.");
|
|
360
245
|
seenCursors.add(cursor);
|
|
361
246
|
}
|
|
362
|
-
const page = parseResourceListPage(await client.listResources(cursor === void 0 ? void 0 : { cursor }, request));
|
|
247
|
+
const page = parseResourceListPage(await client.listResources(cursor === void 0 ? void 0 : { cursor }, request), await loadMcpSchemas());
|
|
363
248
|
for (const resource of page.resources) resources.push(resource);
|
|
364
249
|
cursor = page.nextCursor;
|
|
365
250
|
} while (cursor !== void 0);
|
|
366
251
|
return resources;
|
|
367
252
|
}
|
|
368
253
|
async function readResourceContents(client, resource, request) {
|
|
369
|
-
return parseResourceContents(await client.readResource({ uri: resource.uri }, request));
|
|
254
|
+
return parseResourceContents(await client.readResource({ uri: resource.uri }, request), await loadMcpSchemas());
|
|
370
255
|
}
|
|
371
256
|
async function createEntries(resources, options, client) {
|
|
372
257
|
const entries = [];
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region ../internal/src/object.ts
|
|
2
|
+
/** A non-null object that is not an array. Functions do not pass. */
|
|
3
|
+
function isRecord(value) {
|
|
4
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
5
|
+
}
|
|
6
|
+
/** A non-null object or a function that is not an array. */
|
|
7
|
+
function isRecordOrFunction(value) {
|
|
8
|
+
return Object(value) === value && !Array.isArray(value);
|
|
9
|
+
}
|
|
10
|
+
function isPlainRecord(value) {
|
|
11
|
+
if (!isRecord(value)) return false;
|
|
12
|
+
const prototype = Object.getPrototypeOf(value);
|
|
13
|
+
if (prototype === null) return true;
|
|
14
|
+
return Object.getPrototypeOf(prototype) === null && Object.hasOwn(prototype, "constructor") && prototype.constructor?.name === "Object";
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
export { isRecord as n, isRecordOrFunction as r, isPlainRecord as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ViteHubError } from "@vite-hub/runtime";
|
|
2
2
|
//#region \0rolldown/runtime.js
|
|
3
3
|
var __create = Object.create;
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
@@ -22,6 +22,36 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
22
22
|
enumerable: true
|
|
23
23
|
}) : target, mod));
|
|
24
24
|
//#endregion
|
|
25
|
+
//#region src/core/errors.ts
|
|
26
|
+
function sourceError(message, options) {
|
|
27
|
+
return new ViteHubError("SOURCE_FAILED", message, options);
|
|
28
|
+
}
|
|
29
|
+
function sourceNotFoundError(name) {
|
|
30
|
+
return new ViteHubError("SOURCE_NOT_FOUND", `[vitehub] Source "${name}" is not registered.`, { details: { name } });
|
|
31
|
+
}
|
|
32
|
+
function sourcePathError(path) {
|
|
33
|
+
const publicPath = path.slice(0, 4096);
|
|
34
|
+
return new ViteHubError("SOURCE_PATH_INVALID", `[vitehub] Source path escapes the source root: ${JSON.stringify(publicPath)}.`, { details: { path: publicPath } });
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region src/core/path.ts
|
|
38
|
+
function normalizeSourcePath(path = "") {
|
|
39
|
+
return path.replace(/\\/g, "/").replace(/^\/+/, "").replace(/\/+$/, "");
|
|
40
|
+
}
|
|
41
|
+
function normalizeSafeSourcePath(path = "", options = {}) {
|
|
42
|
+
const raw = path.replace(/\\/g, "/");
|
|
43
|
+
const normalized = normalizeSourcePath(path);
|
|
44
|
+
const parts = normalized.split("/").filter(Boolean);
|
|
45
|
+
if (!options.allowEmpty && !normalized) throw sourcePathError(path);
|
|
46
|
+
if (raw.startsWith("/") || /^[a-z]:/i.test(raw) || raw.includes("\0") || parts.some((part) => part === "." || part === "..")) throw sourcePathError(path);
|
|
47
|
+
if (!options.allowReserved && (parts[0] === ".git" || parts[0] === ".vitehub")) throw sourcePathError(path);
|
|
48
|
+
return normalized;
|
|
49
|
+
}
|
|
50
|
+
function decodeSourceContent(content, options) {
|
|
51
|
+
if (options?.encoding === "binary") return typeof content === "string" ? new TextEncoder().encode(content) : content;
|
|
52
|
+
return typeof content === "string" ? content : new TextDecoder().decode(content);
|
|
53
|
+
}
|
|
54
|
+
//#endregion
|
|
25
55
|
//#region ../../node_modules/.pnpm/picomatch@4.0.7/node_modules/picomatch/lib/constants.js
|
|
26
56
|
var require_constants = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
27
57
|
const WIN_SLASH = "\\\\/";
|
|
@@ -1953,4 +1983,4 @@ function matchesAny(path, patterns) {
|
|
|
1953
1983
|
return createPathMatcher(patterns)(path);
|
|
1954
1984
|
}
|
|
1955
1985
|
//#endregion
|
|
1956
|
-
export {
|
|
1986
|
+
export { normalizeSafeSourcePath as a, sourceNotFoundError as c, decodeSourceContent as i, sourcePathError as l, matchesAny as n, normalizeSourcePath as o, require_picomatch as r, sourceError as s, createPathMatcher as t, __toESM as u };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { a as normalizeSafeSourcePath } from "./path-DFlSryRA.js";
|
|
2
|
+
//#region src/sources/github/root.ts
|
|
3
|
+
function normalizeGitHubRoot(path = "") {
|
|
4
|
+
const root = path.replace(/\\/g, "/").split("/").filter((part) => part !== ".").join("/");
|
|
5
|
+
return normalizeSafeSourcePath(root, {
|
|
6
|
+
allowEmpty: true,
|
|
7
|
+
allowReserved: true
|
|
8
|
+
}).split("/").filter(Boolean).join("/");
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { normalizeGitHubRoot as t };
|
package/dist/server.d.ts
CHANGED
|
@@ -1,236 +1,6 @@
|
|
|
1
|
-
import { r as Collection } from "./collection-
|
|
2
|
-
import { AccessAuthorizeOption } from "@vite-hub/runtime";
|
|
3
|
-
|
|
4
|
-
interface StorageInterface {
|
|
5
|
-
get<T = unknown>(key: string): T | null | Promise<T | null>;
|
|
6
|
-
set<T = unknown>(key: string, value: T, opts?: {
|
|
7
|
-
ttl?: number;
|
|
8
|
-
}): void | Promise<void>;
|
|
9
|
-
/**
|
|
10
|
-
* Largest byte charge one entry may have, when the backend enforces a ceiling.
|
|
11
|
-
*
|
|
12
|
-
* The HTTP layer derives its response-body limit from this value so that a body the
|
|
13
|
-
* backend could never store is refused before it is buffered.
|
|
14
|
-
*/
|
|
15
|
-
maxEntryBytes?: number;
|
|
16
|
-
/**
|
|
17
|
-
* Whether stored values return byte views unchanged, including views nested in an object.
|
|
18
|
-
*
|
|
19
|
-
* Cached handlers store a binary response body as a `Uint8Array` when a backend declares
|
|
20
|
-
* this, and as base64 text otherwise. A backend that serializes entries must leave it unset:
|
|
21
|
-
* JSON renders a byte view as `{"0":255,...}`, which no reader can undo. A value read back
|
|
22
|
-
* in that shape is rejected as a miss rather than served.
|
|
23
|
-
*
|
|
24
|
-
* A declaring backend hands the same view to every hit, so nothing may mutate a stored body.
|
|
25
|
-
*/
|
|
26
|
-
binary?: boolean;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* A storage instance or a late-bound storage factory.
|
|
30
|
-
*
|
|
31
|
-
* The cache calls a factory once, on the first cache operation.
|
|
32
|
-
*/
|
|
33
|
-
type StorageOption = StorageInterface | (() => StorageInterface);
|
|
34
|
-
/**
|
|
35
|
-
* Result of one cache call.
|
|
36
|
-
*
|
|
37
|
-
* - `"hit"`: returned a fresh stored value.
|
|
38
|
-
* - `"stale"`: returned stale data and started background revalidation.
|
|
39
|
-
* - `"revalidated"`: replaced an old value before returning.
|
|
40
|
-
* - `"miss"`: resolved a value when none existed.
|
|
41
|
-
*/
|
|
42
|
-
type CacheStatus = "hit" | "stale" | "revalidated" | "miss";
|
|
43
|
-
/** Cached value and its metadata. */
|
|
44
|
-
interface CacheEntry<T = any> {
|
|
45
|
-
value?: T;
|
|
46
|
-
/** Expiry time in Unix milliseconds. */
|
|
47
|
-
expires?: number;
|
|
48
|
-
/** Last resolution time in Unix milliseconds. */
|
|
49
|
-
mtime?: number;
|
|
50
|
-
/** Hash of the cached function and computation options. */
|
|
51
|
-
integrity?: string;
|
|
52
|
-
/** Forces revalidation on the next access. */
|
|
53
|
-
stale?: boolean;
|
|
54
|
-
/** Per-entry fresh lifetime in seconds. */
|
|
55
|
-
maxAge?: number;
|
|
56
|
-
/** Per-entry stale lifetime in seconds. */
|
|
57
|
-
staleMaxAge?: number;
|
|
58
|
-
/**
|
|
59
|
-
* Stored form of a binary {@link value}.
|
|
60
|
-
*
|
|
61
|
-
* Set only for a value that is a byte view: `"bytes"` when the backend declares
|
|
62
|
-
* `StorageInterface.binary`, and `"base64"` when it does not.
|
|
63
|
-
* The field exists only between the storage write and the read that decodes it;
|
|
64
|
-
* hooks and callers always see a `Uint8Array`.
|
|
65
|
-
*/
|
|
66
|
-
encoding?: "bytes" | "base64";
|
|
67
|
-
/**
|
|
68
|
-
* Where this entry's bulk payload sits.
|
|
69
|
-
*
|
|
70
|
-
* A storage codec reads this to move the payload as bytes, outside whatever document
|
|
71
|
-
* holds the metadata: `"value"` for a cached function whose value is the payload, and
|
|
72
|
-
* `"value.body"` for a cached handler's response body. See {@link createBlobStorage}.
|
|
73
|
-
*
|
|
74
|
-
* The producer of the stored shape declares it, so a codec never infers a payload from
|
|
75
|
-
* the value. Like {@link encoding} it describes storage, not the value: it exists only
|
|
76
|
-
* between the storage write and the read that consumes it, and is written again from the
|
|
77
|
-
* options in use.
|
|
78
|
-
*/
|
|
79
|
-
payload?: "value" | "value.body";
|
|
80
|
-
/**
|
|
81
|
-
* Status for the current call.
|
|
82
|
-
* This field is available to `transform` and is not stored.
|
|
83
|
-
*/
|
|
84
|
-
status?: CacheStatus;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Options for cached functions.
|
|
88
|
-
*
|
|
89
|
-
* Explicit `undefined` values use defaults.
|
|
90
|
-
* `null` values remain unchanged.
|
|
91
|
-
*/
|
|
92
|
-
interface CacheOptions<T = any, ArgsT extends unknown[] = any[]> {
|
|
93
|
-
/**
|
|
94
|
-
* Cache-key name.
|
|
95
|
-
*
|
|
96
|
-
* Defaults to the function name or an anonymous function source hash.
|
|
97
|
-
* Pass an explicit name for equal-source closures created by factories or loops.
|
|
98
|
-
*/
|
|
99
|
-
name?: string;
|
|
100
|
-
/** Returns a cache key from the function arguments. */
|
|
101
|
-
getKey?: (...args: ArgsT) => string | Promise<string>;
|
|
102
|
-
/** Transforms an entry before return. The return value replaces the cached value unless it is `undefined`. */
|
|
103
|
-
transform?: (entry: CacheEntry<T>, ...args: ArgsT) => any;
|
|
104
|
-
/**
|
|
105
|
-
* Converts a resolved value to its stored form.
|
|
106
|
-
*
|
|
107
|
-
* Runs once per resolution after `getMaxAge`.
|
|
108
|
-
* It may safely consume a one-use source shared by deduplicated callers.
|
|
109
|
-
* `validate` receives this stored form on writes and reads.
|
|
110
|
-
*
|
|
111
|
-
* @example
|
|
112
|
-
* ```ts
|
|
113
|
-
* serialize: async (entry) => ({ ...entry.value, body: await streamToString(entry.value.body) }),
|
|
114
|
-
* ```
|
|
115
|
-
*/
|
|
116
|
-
serialize?: (entry: CacheEntry<T>, ctx: {
|
|
117
|
-
args: ArgsT;
|
|
118
|
-
}) => any;
|
|
119
|
-
/**
|
|
120
|
-
* Declares where the stored value's bulk payload sits, for a storage codec.
|
|
121
|
-
*
|
|
122
|
-
* `"value.body"` names the `body` member of an object value, as a `serialize` hook
|
|
123
|
-
* returning `{ body, ... }` produces. A value that is a byte view is its own payload and
|
|
124
|
-
* needs no declaration. Anything else stays inside the metadata document.
|
|
125
|
-
*
|
|
126
|
-
* Only {@link createBlobStorage} and other byte-payload backends read this; every other
|
|
127
|
-
* backend ignores it. See {@link CacheEntry.payload}.
|
|
128
|
-
*/
|
|
129
|
-
payload?: "value.body";
|
|
130
|
-
/**
|
|
131
|
-
* Validates an entry for the current arguments.
|
|
132
|
-
* Return or resolve to `false` to revalidate it.
|
|
133
|
-
*/
|
|
134
|
-
validate?: (entry: CacheEntry<T>, ctx: {
|
|
135
|
-
args: ArgsT;
|
|
136
|
-
}) => boolean | Promise<boolean>;
|
|
137
|
-
/** Return `true` to trigger revalidation. */
|
|
138
|
-
shouldInvalidateCache?: (...args: ArgsT) => boolean | Promise<boolean>;
|
|
139
|
-
/** Return `true` to call the function without cache processing. */
|
|
140
|
-
shouldBypassCache?: (...args: ArgsT) => boolean | Promise<boolean>;
|
|
141
|
-
/** Cache-key group. Defaults to `"functions"`. Escaped like `name`. */
|
|
142
|
-
group?: string;
|
|
143
|
-
/** Integrity value. Defaults to a hash of the function and options. */
|
|
144
|
-
integrity?: any;
|
|
145
|
-
/**
|
|
146
|
-
* Fresh lifetime in seconds. Defaults to `1`.
|
|
147
|
-
* A non-positive lifetime prevents storage.
|
|
148
|
-
*/
|
|
149
|
-
maxAge?: number;
|
|
150
|
-
/**
|
|
151
|
-
* Enables stale-while-revalidate. Defaults to `false`.
|
|
152
|
-
*
|
|
153
|
-
* Without {@link staleMaxAge}, stale reuse is limited only by backend eviction.
|
|
154
|
-
*/
|
|
155
|
-
swr?: boolean;
|
|
156
|
-
/**
|
|
157
|
-
* Stale lifetime in seconds.
|
|
158
|
-
*
|
|
159
|
-
* `0` requires foreground revalidation.
|
|
160
|
-
* An unset value allows stale reuse until backend eviction.
|
|
161
|
-
*/
|
|
162
|
-
staleMaxAge?: number;
|
|
163
|
-
/**
|
|
164
|
-
* Returns per-entry lifetimes after resolution and before storage.
|
|
165
|
-
*
|
|
166
|
-
* A number sets `maxAge`.
|
|
167
|
-
* An object can set `maxAge` and `staleMaxAge`.
|
|
168
|
-
* Returned fields override static options for freshness, storage, and Cache-Control.
|
|
169
|
-
* Non-positive `maxAge` values prevent storage.
|
|
170
|
-
*
|
|
171
|
-
* @example
|
|
172
|
-
* ```ts
|
|
173
|
-
* getMaxAge: (entry) => entry.value?.expires_in,
|
|
174
|
-
* getMaxAge: () => ({ maxAge: 60, staleMaxAge: 300 }),
|
|
175
|
-
* ```
|
|
176
|
-
*/
|
|
177
|
-
getMaxAge?: (entry: CacheEntry<T>) => number | {
|
|
178
|
-
maxAge?: number;
|
|
179
|
-
staleMaxAge?: number;
|
|
180
|
-
} | undefined | Promise<number | {
|
|
181
|
-
maxAge?: number;
|
|
182
|
-
staleMaxAge?: number;
|
|
183
|
-
} | undefined>;
|
|
184
|
-
/**
|
|
185
|
-
* Deadline for one shared resolution and its hooks, in seconds.
|
|
186
|
-
*
|
|
187
|
-
* Defaults to `30`.
|
|
188
|
-
* Set `Infinity` or `0` to disable the deadline.
|
|
189
|
-
* On timeout, all waiters reject with `TimeoutError` and the old entry is evicted.
|
|
190
|
-
* A handler's `event.req.signal` aborts with that error; a plain resolver receives no
|
|
191
|
-
* signal, so it continues but cannot write its late result.
|
|
192
|
-
*/
|
|
193
|
-
maxResolveTime?: number;
|
|
194
|
-
/**
|
|
195
|
-
* Cache-key base prefixes. Defaults to `"/cache"`.
|
|
196
|
-
* Reads stop at the first hit. Misses write every prefix.
|
|
197
|
-
* Revalidation writes the hit prefix and every earlier prefix.
|
|
198
|
-
*/
|
|
199
|
-
base?: string | string[];
|
|
200
|
-
/**
|
|
201
|
-
* Storage instance or late-bound factory.
|
|
202
|
-
*
|
|
203
|
-
* Defaults to one memory store per cached function or handler.
|
|
204
|
-
* Pass the same instance to share entries.
|
|
205
|
-
* A factory runs once on the first cache operation.
|
|
206
|
-
* The cache writes the resolved instance back to this options object.
|
|
207
|
-
*
|
|
208
|
-
* @example
|
|
209
|
-
* ```ts
|
|
210
|
-
* const storage = createMemoryStorage();
|
|
211
|
-
* const a = cachedFunction(fnA, { storage });
|
|
212
|
-
* const b = cachedFunction(fnB, { storage });
|
|
213
|
-
* ```
|
|
214
|
-
*/
|
|
215
|
-
storage?: StorageOption;
|
|
216
|
-
/**
|
|
217
|
-
* Registers background work with the host: cache writes, SWR refreshes, and evictions.
|
|
218
|
-
*
|
|
219
|
-
* A cached function has no event to read `req.waitUntil` from, so a serverless host may
|
|
220
|
-
* freeze the process before an SWR refresh lands. Pass the platform hook here.
|
|
221
|
-
* Takes precedence over `event.req.waitUntil` when both are present, so one promise is
|
|
222
|
-
* never registered twice.
|
|
223
|
-
*
|
|
224
|
-
* @example
|
|
225
|
-
* ```ts
|
|
226
|
-
* const cached = cachedFunction(fn, { swr: true, waitUntil: (p) => ctx.waitUntil(p) });
|
|
227
|
-
* ```
|
|
228
|
-
*/
|
|
229
|
-
waitUntil?: (promise: Promise<any>) => void;
|
|
230
|
-
/** Receives handled cache, hook, and background errors. */
|
|
231
|
-
onError?: (error: unknown) => void;
|
|
232
|
-
}
|
|
233
|
-
//#endregion
|
|
1
|
+
import { r as Collection } from "./collection-B8sgxw5-.js";
|
|
2
|
+
import { AccessAuthorizeOption, ViteHubContext } from "@vite-hub/runtime";
|
|
3
|
+
import { CacheOptions } from "ocache";
|
|
234
4
|
//#region src/cached-source.d.ts
|
|
235
5
|
interface KeyedSourceReader {
|
|
236
6
|
get(key: never): Promise<unknown>;
|
|
@@ -243,21 +13,14 @@ type SourceReaderCacheOptions<TKey, TValue> = Omit<CacheOptions<TValue, [key: TK
|
|
|
243
13
|
export declare function cachedSource<const TReader extends KeyedSourceReader>(reader: TReader & ValidCachedGet<TReader>, options: SourceReaderCacheOptions<Parameters<TReader["get"]>[0], Awaited<ReturnType<TReader["get"]>>>): TReader;
|
|
244
14
|
//#endregion
|
|
245
15
|
//#region src/server.d.ts
|
|
16
|
+
/** A Collection route as a Fetchable. Mount it as a Nitro route, or call `fetch()` with a Web Request. */
|
|
246
17
|
export interface CollectionHandler {
|
|
247
|
-
(
|
|
248
|
-
fetch(input: Request | URL | string): Promise<Response>;
|
|
249
|
-
}
|
|
250
|
-
export interface CollectionHandlerEvent {
|
|
251
|
-
req: {
|
|
252
|
-
signal: AbortSignal;
|
|
253
|
-
};
|
|
18
|
+
fetch(request: Request): Promise<Response>;
|
|
254
19
|
}
|
|
255
20
|
/** Wraps a Collection handler so it runs only after the request is authorized. Return a `Response` to reject the request. */
|
|
256
|
-
export type CollectionAuthorizationGuard = <
|
|
257
|
-
req: Request;
|
|
258
|
-
}, TResult>(authorize: AccessAuthorizeOption, handler: (event: TEvent) => Promise<TResult>) => (event: TEvent) => Promise<TResult | Response>;
|
|
21
|
+
export type CollectionAuthorizationGuard = <TResult>(authorize: AccessAuthorizeOption<Request & ViteHubContext>, handler: (request: Request) => Promise<TResult>) => (request: Request) => Promise<TResult | Response>;
|
|
259
22
|
export interface CollectionHandlerOptions {
|
|
260
|
-
/** Required
|
|
23
|
+
/** Required unless the Collection sets `access: "public"`. Generated routes pass Auth's `withAuthorization`. */
|
|
261
24
|
withAuthorization?: CollectionAuthorizationGuard;
|
|
262
25
|
}
|
|
263
26
|
export declare function defineCollectionHandler<TItem, TQuery extends object, TQueryInput extends object>(collection: Collection<TItem, TQuery, TQueryInput>, options?: CollectionHandlerOptions): CollectionHandler;
|