@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
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { a as sourceError, n as normalizeSafeSourcePath, r as normalizeSourcePath, s as sourcePathError } from "./path-BzmU4Eni.js";
|
|
2
1
|
//#region ../../node_modules/.pnpm/mrmime@2.0.1/node_modules/mrmime/index.mjs
|
|
3
2
|
const mimes = {
|
|
4
3
|
"3g2": "video/3gpp2",
|
|
@@ -446,58 +445,4 @@ function lookup(extn) {
|
|
|
446
445
|
return mimes[!~idx ? tmp : tmp.substring(++idx)];
|
|
447
446
|
}
|
|
448
447
|
//#endregion
|
|
449
|
-
|
|
450
|
-
function normalizeFileSourceOptions(input) {
|
|
451
|
-
return typeof input === "string" ? { path: input } : input;
|
|
452
|
-
}
|
|
453
|
-
function sourceKey(options) {
|
|
454
|
-
if (options.workspacePath) return normalizeSourcePath(options.workspacePath);
|
|
455
|
-
if ("path" in options && options.path) return normalizeSourcePath(normalizeSafeSourcePath(options.path));
|
|
456
|
-
throw new TypeError("[vitehub] file requires a path or workspacePath.");
|
|
457
|
-
}
|
|
458
|
-
function resolveSourceRoot(ctx) {
|
|
459
|
-
return ctx.sourceRootDir || ctx.rootDir;
|
|
460
|
-
}
|
|
461
|
-
async function readSourceFile(options, ctx) {
|
|
462
|
-
if (!("path" in options) || !options.path) throw new TypeError("[vitehub] file requires path when content is not provided.");
|
|
463
|
-
const { readFile } = await import("node:fs/promises");
|
|
464
|
-
return new Uint8Array(await readFile(await resolveSafeSourceFilePath(options.path, ctx)));
|
|
465
|
-
}
|
|
466
|
-
async function resolveSafeSourceFilePath(path, ctx) {
|
|
467
|
-
const { realpath } = await import("node:fs/promises");
|
|
468
|
-
const { relative, resolve, sep } = await import("node:path");
|
|
469
|
-
const root = await realpath(resolve(resolveSourceRoot(ctx)));
|
|
470
|
-
const target = await realpath(resolve(root, normalizeSafeSourcePath(path)));
|
|
471
|
-
const rel = relative(root, target);
|
|
472
|
-
if (rel === ".." || rel.startsWith(`..${sep}`)) throw sourcePathError(path);
|
|
473
|
-
return target;
|
|
474
|
-
}
|
|
475
|
-
function file(input) {
|
|
476
|
-
const options = normalizeFileSourceOptions(input);
|
|
477
|
-
const key = sourceKey(options);
|
|
478
|
-
const mediaType = options.mediaType || lookup(key);
|
|
479
|
-
return {
|
|
480
|
-
name: "file",
|
|
481
|
-
async getKeys() {
|
|
482
|
-
return [key];
|
|
483
|
-
},
|
|
484
|
-
async getMeta(requestedKey, ctx) {
|
|
485
|
-
if (requestedKey !== key) return;
|
|
486
|
-
if (!("path" in options) || !options.path) return;
|
|
487
|
-
const { stat } = await import("node:fs/promises");
|
|
488
|
-
const info = await stat(await resolveSafeSourceFilePath(options.path, ctx));
|
|
489
|
-
return { digest: `${info.size}:${info.mtimeMs}` };
|
|
490
|
-
},
|
|
491
|
-
async getItem(requestedKey, ctx) {
|
|
492
|
-
if (requestedKey !== key) throw sourceError(`[vitehub] file could not find ${JSON.stringify(requestedKey)}.`);
|
|
493
|
-
return {
|
|
494
|
-
key,
|
|
495
|
-
path: key,
|
|
496
|
-
content: typeof options.content === "undefined" ? await readSourceFile(options, ctx) : options.content,
|
|
497
|
-
mediaType
|
|
498
|
-
};
|
|
499
|
-
}
|
|
500
|
-
};
|
|
501
|
-
}
|
|
502
|
-
//#endregion
|
|
503
|
-
export { file as t };
|
|
448
|
+
export { lookup as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as normalizeSourcePath } from "./path-
|
|
1
|
+
import { r as normalizeSourcePath } from "./path-DOBpV8ol.js";
|
|
2
2
|
//#region \0rolldown/runtime.js
|
|
3
3
|
var __create = Object.create;
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
@@ -17,12 +17,12 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
}
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
21
21
|
value: mod,
|
|
22
22
|
enumerable: true
|
|
23
23
|
}) : target, mod));
|
|
24
24
|
//#endregion
|
|
25
|
-
//#region ../../node_modules/.pnpm/picomatch@4.0.
|
|
25
|
+
//#region ../../node_modules/.pnpm/picomatch@4.0.7/node_modules/picomatch/lib/constants.js
|
|
26
26
|
var require_constants = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
27
27
|
const WIN_SLASH = "\\\\/";
|
|
28
28
|
const WIN_NO_SLASH = `[^${WIN_SLASH}]`;
|
|
@@ -77,7 +77,7 @@ var require_constants = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
77
77
|
};
|
|
78
78
|
module.exports = {
|
|
79
79
|
DEFAULT_MAX_EXTGLOB_RECURSION,
|
|
80
|
-
MAX_LENGTH:
|
|
80
|
+
MAX_LENGTH: 65536,
|
|
81
81
|
POSIX_REGEX_SOURCE: {
|
|
82
82
|
__proto__: null,
|
|
83
83
|
alnum: "a-zA-Z0-9",
|
|
@@ -191,7 +191,7 @@ var require_constants = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
191
191
|
};
|
|
192
192
|
}));
|
|
193
193
|
//#endregion
|
|
194
|
-
//#region ../../node_modules/.pnpm/picomatch@4.0.
|
|
194
|
+
//#region ../../node_modules/.pnpm/picomatch@4.0.7/node_modules/picomatch/lib/utils.js
|
|
195
195
|
var require_utils = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
196
196
|
const { REGEX_BACKSLASH, REGEX_REMOVE_BACKSLASH, REGEX_SPECIAL_CHARS, REGEX_SPECIAL_CHARS_GLOBAL } = require_constants();
|
|
197
197
|
exports.isObject = (val) => val !== null && typeof val === "object" && !Array.isArray(val);
|
|
@@ -239,7 +239,7 @@ var require_utils = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
239
239
|
};
|
|
240
240
|
}));
|
|
241
241
|
//#endregion
|
|
242
|
-
//#region ../../node_modules/.pnpm/picomatch@4.0.
|
|
242
|
+
//#region ../../node_modules/.pnpm/picomatch@4.0.7/node_modules/picomatch/lib/scan.js
|
|
243
243
|
var require_scan = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
244
244
|
const utils = require_utils();
|
|
245
245
|
const { CHAR_ASTERISK, CHAR_AT, CHAR_BACKWARD_SLASH, CHAR_COMMA, CHAR_DOT, CHAR_EXCLAMATION_MARK, CHAR_FORWARD_SLASH, CHAR_LEFT_CURLY_BRACE, CHAR_LEFT_PARENTHESES, CHAR_LEFT_SQUARE_BRACKET, CHAR_PLUS, CHAR_QUESTION_MARK, CHAR_RIGHT_CURLY_BRACE, CHAR_RIGHT_PARENTHESES, CHAR_RIGHT_SQUARE_BRACKET } = require_constants();
|
|
@@ -268,7 +268,7 @@ var require_scan = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
268
268
|
const scan = (input, options) => {
|
|
269
269
|
const opts = options || {};
|
|
270
270
|
const length = input.length - 1;
|
|
271
|
-
const scanToEnd = opts.parts === true || opts.scanToEnd === true;
|
|
271
|
+
const scanToEnd = opts.parts === true || opts.tokens === true || opts.scanToEnd === true;
|
|
272
272
|
const slashes = [];
|
|
273
273
|
const tokens = [];
|
|
274
274
|
const parts = [];
|
|
@@ -371,14 +371,18 @@ var require_scan = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
371
371
|
finished = true;
|
|
372
372
|
if (code === CHAR_EXCLAMATION_MARK && index === start) negatedExtglob = true;
|
|
373
373
|
if (scanToEnd === true) {
|
|
374
|
+
let parens = 0;
|
|
374
375
|
while (eos() !== true && (code = advance())) {
|
|
375
376
|
if (code === CHAR_BACKWARD_SLASH) {
|
|
376
377
|
backslashes = token.backslashes = true;
|
|
377
|
-
|
|
378
|
+
advance();
|
|
379
|
+
continue;
|
|
380
|
+
}
|
|
381
|
+
if (code === CHAR_LEFT_PARENTHESES) {
|
|
382
|
+
parens++;
|
|
378
383
|
continue;
|
|
379
384
|
}
|
|
380
|
-
if (code === CHAR_RIGHT_PARENTHESES) {
|
|
381
|
-
isGlob = token.isGlob = true;
|
|
385
|
+
if (code === CHAR_RIGHT_PARENTHESES && --parens === 0) {
|
|
382
386
|
finished = true;
|
|
383
387
|
break;
|
|
384
388
|
}
|
|
@@ -426,13 +430,18 @@ var require_scan = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
426
430
|
if (opts.noparen !== true && code === CHAR_LEFT_PARENTHESES) {
|
|
427
431
|
isGlob = token.isGlob = true;
|
|
428
432
|
if (scanToEnd === true) {
|
|
433
|
+
let parens = 1;
|
|
429
434
|
while (eos() !== true && (code = advance())) {
|
|
430
|
-
if (code ===
|
|
435
|
+
if (code === CHAR_BACKWARD_SLASH) {
|
|
431
436
|
backslashes = token.backslashes = true;
|
|
432
|
-
|
|
437
|
+
advance();
|
|
433
438
|
continue;
|
|
434
439
|
}
|
|
435
|
-
if (code ===
|
|
440
|
+
if (code === CHAR_LEFT_PARENTHESES) {
|
|
441
|
+
parens++;
|
|
442
|
+
continue;
|
|
443
|
+
}
|
|
444
|
+
if (code === CHAR_RIGHT_PARENTHESES && --parens === 0) {
|
|
436
445
|
finished = true;
|
|
437
446
|
break;
|
|
438
447
|
}
|
|
@@ -495,7 +504,7 @@ var require_scan = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
495
504
|
if (opts.parts === true || opts.tokens === true) {
|
|
496
505
|
let prevIndex;
|
|
497
506
|
for (let idx = 0; idx < slashes.length; idx++) {
|
|
498
|
-
const n = prevIndex ? prevIndex + 1 : start;
|
|
507
|
+
const n = prevIndex !== void 0 ? prevIndex + 1 : start;
|
|
499
508
|
const i = slashes[idx];
|
|
500
509
|
const value = input.slice(n, i);
|
|
501
510
|
if (opts.tokens) {
|
|
@@ -506,18 +515,19 @@ var require_scan = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
506
515
|
depth(tokens[idx]);
|
|
507
516
|
state.maxDepth += tokens[idx].depth;
|
|
508
517
|
}
|
|
509
|
-
if (
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
if (prevIndex && prevIndex + 1 < input.length) {
|
|
513
|
-
const value = input.slice(prevIndex + 1);
|
|
514
|
-
parts.push(value);
|
|
515
|
-
if (opts.tokens) {
|
|
516
|
-
tokens[tokens.length - 1].value = value;
|
|
517
|
-
depth(tokens[tokens.length - 1]);
|
|
518
|
-
state.maxDepth += tokens[tokens.length - 1].depth;
|
|
518
|
+
if (i >= start) {
|
|
519
|
+
parts.push(value);
|
|
520
|
+
prevIndex = i;
|
|
519
521
|
}
|
|
520
522
|
}
|
|
523
|
+
const n = prevIndex !== void 0 ? prevIndex + 1 : start;
|
|
524
|
+
const value = input.slice(n);
|
|
525
|
+
parts.push(value);
|
|
526
|
+
if (opts.tokens && prevIndex && prevIndex + 1 < input.length) {
|
|
527
|
+
tokens[tokens.length - 1].value = value;
|
|
528
|
+
depth(tokens[tokens.length - 1]);
|
|
529
|
+
state.maxDepth += tokens[tokens.length - 1].depth;
|
|
530
|
+
}
|
|
521
531
|
state.slashes = slashes;
|
|
522
532
|
state.parts = parts;
|
|
523
533
|
}
|
|
@@ -526,7 +536,7 @@ var require_scan = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
526
536
|
module.exports = scan;
|
|
527
537
|
}));
|
|
528
538
|
//#endregion
|
|
529
|
-
//#region ../../node_modules/.pnpm/picomatch@4.0.
|
|
539
|
+
//#region ../../node_modules/.pnpm/picomatch@4.0.7/node_modules/picomatch/lib/parse.js
|
|
530
540
|
var require_parse = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
531
541
|
const constants = require_constants();
|
|
532
542
|
const utils = require_utils();
|
|
@@ -890,7 +900,8 @@ var require_parse = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
890
900
|
};
|
|
891
901
|
const extglobClose = (token) => {
|
|
892
902
|
const literal = input.slice(token.startIndex, state.index + 1);
|
|
893
|
-
const
|
|
903
|
+
const body = input.slice(token.startIndex + 2, state.index);
|
|
904
|
+
const analysis = analyzeRepeatedExtglob(body, opts);
|
|
894
905
|
if ((token.type === "plus" || token.type === "star") && analysis.risky) {
|
|
895
906
|
const safeOutput = analysis.safeOutput ? (token.output ? "" : ONE_CHAR) + (opts.capture ? `(${analysis.safeOutput})` : analysis.safeOutput) : void 0;
|
|
896
907
|
const open = tokens[token.tokensIndex];
|
|
@@ -955,10 +966,12 @@ var require_parse = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
955
966
|
}
|
|
956
967
|
return esc ? m : `\\${m}`;
|
|
957
968
|
});
|
|
958
|
-
if (backslashes === true)
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
969
|
+
if (backslashes === true) {
|
|
970
|
+
if (opts.unescape === true) output = output.replace(/\\/g, "");
|
|
971
|
+
else output = output.replace(/\\+/g, (m) => {
|
|
972
|
+
return m.length % 2 === 0 ? "\\\\" : m ? "\\" : "";
|
|
973
|
+
});
|
|
974
|
+
}
|
|
962
975
|
if (output === input && opts.contains === true) {
|
|
963
976
|
state.output = input;
|
|
964
977
|
return state;
|
|
@@ -1016,7 +1029,8 @@ var require_parse = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1016
1029
|
if (inner.includes(":")) {
|
|
1017
1030
|
const idx = prev.value.lastIndexOf("[");
|
|
1018
1031
|
const pre = prev.value.slice(0, idx);
|
|
1019
|
-
const
|
|
1032
|
+
const rest = prev.value.slice(idx + 2);
|
|
1033
|
+
const posix = POSIX_REGEX_SOURCE[rest];
|
|
1020
1034
|
if (posix) {
|
|
1021
1035
|
prev.value = pre + posix;
|
|
1022
1036
|
state.backtrack = true;
|
|
@@ -1424,6 +1438,7 @@ var require_parse = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1424
1438
|
rest = rest.slice(3);
|
|
1425
1439
|
consume("/**", 3);
|
|
1426
1440
|
}
|
|
1441
|
+
const isEnd = eos() || state.parens > 0 && rest === ")".repeat(state.parens) && !extglobs.some((extglob) => extglob.type === "negate");
|
|
1427
1442
|
if (prior.type === "bos" && eos()) {
|
|
1428
1443
|
prev.type = "globstar";
|
|
1429
1444
|
prev.value += value;
|
|
@@ -1433,7 +1448,7 @@ var require_parse = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1433
1448
|
consume(value);
|
|
1434
1449
|
continue;
|
|
1435
1450
|
}
|
|
1436
|
-
if (prior.type === "slash" && prior.prev.type !== "bos" && !afterStar &&
|
|
1451
|
+
if (prior.type === "slash" && prior.prev.type !== "bos" && !afterStar && isEnd) {
|
|
1437
1452
|
state.output = state.output.slice(0, -(prior.output + prev.output).length);
|
|
1438
1453
|
prior.output = `(?:${prior.output}`;
|
|
1439
1454
|
prev.type = "globstar";
|
|
@@ -1598,7 +1613,7 @@ var require_parse = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1598
1613
|
module.exports = parse;
|
|
1599
1614
|
}));
|
|
1600
1615
|
//#endregion
|
|
1601
|
-
//#region ../../node_modules/.pnpm/picomatch@4.0.
|
|
1616
|
+
//#region ../../node_modules/.pnpm/picomatch@4.0.7/node_modules/picomatch/lib/picomatch.js
|
|
1602
1617
|
var require_picomatch$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1603
1618
|
const scan = require_scan();
|
|
1604
1619
|
const parse = require_parse();
|
|
@@ -1728,8 +1743,10 @@ var require_picomatch$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1728
1743
|
output = format ? format(input) : input;
|
|
1729
1744
|
match = output === glob;
|
|
1730
1745
|
}
|
|
1731
|
-
if (match === false || opts.capture === true)
|
|
1732
|
-
|
|
1746
|
+
if (match === false || opts.capture === true) {
|
|
1747
|
+
if (opts.matchBase === true || opts.basename === true) match = picomatch.matchBase(input, regex, options, posix);
|
|
1748
|
+
else match = regex.exec(output);
|
|
1749
|
+
}
|
|
1733
1750
|
return {
|
|
1734
1751
|
isMatch: Boolean(match),
|
|
1735
1752
|
match,
|
|
@@ -1910,7 +1927,7 @@ var require_picomatch$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1910
1927
|
module.exports = picomatch;
|
|
1911
1928
|
}));
|
|
1912
1929
|
//#endregion
|
|
1913
|
-
//#region ../../node_modules/.pnpm/picomatch@4.0.
|
|
1930
|
+
//#region ../../node_modules/.pnpm/picomatch@4.0.7/node_modules/picomatch/index.js
|
|
1914
1931
|
var require_picomatch = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1915
1932
|
const pico = require_picomatch$1();
|
|
1916
1933
|
const utils = require_utils();
|
|
@@ -1927,10 +1944,13 @@ var require_picomatch = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1927
1944
|
//#endregion
|
|
1928
1945
|
//#region src/sources/path.ts
|
|
1929
1946
|
var import_picomatch = /* @__PURE__ */ __toESM(require_picomatch(), 1);
|
|
1947
|
+
function createPathMatcher(patterns) {
|
|
1948
|
+
if (!patterns) return () => true;
|
|
1949
|
+
const match = (0, import_picomatch.default)((Array.isArray(patterns) ? patterns : [String(patterns)]).map((pattern) => normalizeSourcePath(pattern)), { dot: true });
|
|
1950
|
+
return (path) => match(normalizeSourcePath(path));
|
|
1951
|
+
}
|
|
1930
1952
|
function matchesAny(path, patterns) {
|
|
1931
|
-
|
|
1932
|
-
const list = Array.isArray(patterns) ? patterns : [String(patterns)];
|
|
1933
|
-
return import_picomatch.default.isMatch(normalizeSourcePath(path), list.map((pattern) => normalizeSourcePath(pattern)), { dot: true });
|
|
1953
|
+
return createPathMatcher(patterns)(path);
|
|
1934
1954
|
}
|
|
1935
1955
|
//#endregion
|
|
1936
|
-
export { __toESM as i,
|
|
1956
|
+
export { __toESM as a, __commonJSMin as i, matchesAny as n, require_picomatch as r, createPathMatcher as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ViteHubError
|
|
1
|
+
import { ViteHubError } from "@vite-hub/runtime";
|
|
2
2
|
//#region src/core/errors.ts
|
|
3
3
|
function sourceError(message, options) {
|
|
4
4
|
return new ViteHubError("SOURCE_FAILED", message, options);
|
|
@@ -10,10 +10,6 @@ function sourcePathError(path) {
|
|
|
10
10
|
const publicPath = path.slice(0, 4096);
|
|
11
11
|
return new ViteHubError("SOURCE_PATH_INVALID", `[vitehub] Source path escapes the source root: ${JSON.stringify(publicPath)}.`, { details: { path: publicPath } });
|
|
12
12
|
}
|
|
13
|
-
function isSourceError(value) {
|
|
14
|
-
const code = getViteHubErrorShape(value)?.code;
|
|
15
|
-
return code === "SOURCE_FAILED" || code === "SOURCE_NOT_FOUND" || code === "SOURCE_PATH_INVALID";
|
|
16
|
-
}
|
|
17
13
|
//#endregion
|
|
18
14
|
//#region src/core/path.ts
|
|
19
15
|
function normalizeSourcePath(path = "") {
|
|
@@ -24,7 +20,7 @@ function normalizeSafeSourcePath(path = "", options = {}) {
|
|
|
24
20
|
const normalized = normalizeSourcePath(path);
|
|
25
21
|
const parts = normalized.split("/").filter(Boolean);
|
|
26
22
|
if (!options.allowEmpty && !normalized) throw sourcePathError(path);
|
|
27
|
-
if (raw.startsWith("/") || /^[a-z]
|
|
23
|
+
if (raw.startsWith("/") || /^[a-z]:/i.test(raw) || raw.includes("\0") || parts.some((part) => part === "." || part === "..")) throw sourcePathError(path);
|
|
28
24
|
if (!options.allowReserved && (parts[0] === ".git" || parts[0] === ".vitehub")) throw sourcePathError(path);
|
|
29
25
|
return normalized;
|
|
30
26
|
}
|
|
@@ -33,4 +29,4 @@ function decodeSourceContent(content, options) {
|
|
|
33
29
|
return typeof content === "string" ? content : new TextDecoder().decode(content);
|
|
34
30
|
}
|
|
35
31
|
//#endregion
|
|
36
|
-
export {
|
|
32
|
+
export { sourceNotFoundError as a, sourceError as i, normalizeSafeSourcePath as n, sourcePathError as o, normalizeSourcePath as r, decodeSourceContent as t };
|
package/dist/server.d.ts
CHANGED
|
@@ -1,15 +1,265 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { r as Collection } from "./collection-B_4w_J8h.js";
|
|
2
|
+
import { AccessAuthorizeOption } from "@vite-hub/runtime";
|
|
3
|
+
//#region ../../node_modules/.pnpm/ocache@0.3.0/node_modules/ocache/dist/index.d.mts
|
|
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
|
|
234
|
+
//#region src/cached-source.d.ts
|
|
235
|
+
interface KeyedSourceReader {
|
|
236
|
+
get(key: never): Promise<unknown>;
|
|
237
|
+
}
|
|
238
|
+
type ValidCachedGet<TReader extends KeyedSourceReader> = (<T>() => T extends TReader["get"] ? 1 : 2) extends (<T>() => T extends ((key: Parameters<TReader["get"]>[0]) => ReturnType<TReader["get"]>) ? 1 : 2) ? unknown : never;
|
|
239
|
+
type SourceReaderCacheOptions<TKey, TValue> = Omit<CacheOptions<TValue, [key: TKey]>, "name"> & {
|
|
240
|
+
name: string;
|
|
241
|
+
};
|
|
242
|
+
/** Cache `get(key)` in the Nitro `cache` storage. Other reader operations pass through unchanged. */
|
|
243
|
+
export declare function cachedSource<const TReader extends KeyedSourceReader>(reader: TReader & ValidCachedGet<TReader>, options: SourceReaderCacheOptions<Parameters<TReader["get"]>[0], Awaited<ReturnType<TReader["get"]>>>): TReader;
|
|
244
|
+
//#endregion
|
|
3
245
|
//#region src/server.d.ts
|
|
4
|
-
interface CollectionHandler {
|
|
246
|
+
export interface CollectionHandler {
|
|
5
247
|
(event: unknown): Promise<unknown>;
|
|
6
248
|
fetch(input: Request | URL | string): Promise<Response>;
|
|
7
249
|
}
|
|
8
|
-
interface CollectionHandlerEvent {
|
|
250
|
+
export interface CollectionHandlerEvent {
|
|
9
251
|
req: {
|
|
10
252
|
signal: AbortSignal;
|
|
11
253
|
};
|
|
12
254
|
}
|
|
13
|
-
|
|
255
|
+
/** Wraps a Collection handler so it runs only after the request is authorized. Return a `Response` to reject the request. */
|
|
256
|
+
export type CollectionAuthorizationGuard = <TEvent extends {
|
|
257
|
+
req: Request;
|
|
258
|
+
}, TResult>(authorize: AccessAuthorizeOption, handler: (event: TEvent) => Promise<TResult>) => (event: TEvent) => Promise<TResult | Response>;
|
|
259
|
+
export interface CollectionHandlerOptions {
|
|
260
|
+
/** Required when the Collection declares `authorize`. Generated routes pass Auth's `withAuthorization`. */
|
|
261
|
+
withAuthorization?: CollectionAuthorizationGuard;
|
|
262
|
+
}
|
|
263
|
+
export declare function defineCollectionHandler<TItem, TQuery extends object, TQueryInput extends object>(collection: Collection<TItem, TQuery, TQueryInput>, options?: CollectionHandlerOptions): CollectionHandler;
|
|
14
264
|
//#endregion
|
|
15
|
-
export {
|
|
265
|
+
export type { SourceReaderCacheOptions };
|