@vite-hub/source 0.4.1 → 0.5.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 CHANGED
@@ -77,7 +77,8 @@ definition type.
77
77
 
78
78
  All managed readers expose `revision()`, `keys()`, `get()`, `items()`, `meta()`,
79
79
  and `exists()`. File readers also expose `read()` and `list()`. Built-in `file`,
80
- `glob`, `github`, `markdown`, and `mcpResources` loaders return `FileSource`.
80
+ `files`, `glob`, `github`, `markdown`, and `mcpResources` (from
81
+ `@vite-hub/source/mcp`) loaders return `FileSource`.
81
82
  Their `SourceFile` items guarantee `content`. Custom loaders that guarantee
82
83
  content receive file methods too. Record readers use `get()` and `items()`.
83
84
 
@@ -174,9 +175,9 @@ await useSource("docs").read("intro.md")
174
175
 
175
176
  The Vite integration finds each file in `server/sources/`. It registers the
176
177
  default export by the path of the file, such as `docs`, when the server starts,
177
- and writes the `ViteHubSourceMap` types to `.vitehub/types`. In Nuxt,
178
- `useSource` is auto-imported in server code. `RegisteredSource<"docs">` gives
179
- the Source type of a name.
178
+ and writes the `ViteHubSourceMap` types to `.vitehub/types`. In Nuxt with
179
+ `experimental.nitroAutoImports` on, `useSource` is auto-imported in server
180
+ code. `RegisteredSource<"docs">` gives the Source type of a name.
180
181
 
181
182
  ## Split items into parts
182
183
 
@@ -316,8 +317,10 @@ export const articles = defineCollection({
316
317
  Clients filter with the declared field paths: `?category=guide` matches without
317
318
  case, a repeated key matches any of its values, `?empty=category` matches items
318
319
  with no value, and `?search=` matches the `search` fields. Any other key returns
319
- `400`. Cursors are bound to the data and the query. A cursor from changed data or
320
- another query returns `409`. `load` runs on every request; return
320
+ `400`. String sort keys and facet ties use UTF-16 code unit order, folding common
321
+ Latin letters and accents first, then comparing the original strings to break ties.
322
+ Cursors are bound to the data, query, and sort order. A cursor from changed data,
323
+ another query, or an older sort order returns `409`. `load` runs on every request; return
321
324
  `{ items, digest }` when the origin already has a content digest, or ViteHub
322
325
  hashes the items for pagination. Keyed lookups do not compute a digest.
323
326
  `useCollection()` exposes `total` and `facets` from the latest
package/dist/client.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as CollectionClientItem, c as CollectionFacets, h as CollectionQuery, p as CollectionPage, t as AnyCollection } from "./collection-B8sgxw5-.js";
1
+ import { a as CollectionClientItem, c as CollectionFacets, h as CollectionQuery, p as CollectionPage, t as AnyCollection } from "./collection-DTk0O1SE.js";
2
2
  import { Diagnostic } from "nostics";
3
3
  import { ComputedRef, MaybeRefOrGetter, Ref } from "vue";
4
4
  //#region src/client.d.ts
package/dist/client.js CHANGED
@@ -3,7 +3,6 @@ import { t as sourceErrorDiagnostics } from "./error-diagnostics-DZdhDQpU.js";
3
3
  import { Diagnostic } from "nostics";
4
4
  import { computed, onScopeDispose, ref, toValue, watch } from "vue";
5
5
  //#region src/client.ts
6
- /** Thrown by the default requester when a Collection route answers with an error status. */
7
6
  var CollectionRequestError = class CollectionRequestError extends Diagnostic {
8
7
  status;
9
8
  constructor(endpoint, status) {
@@ -31,7 +31,6 @@ function encodeBase64Url(value) {
31
31
  for (const byte of bytes) binary += String.fromCharCode(byte);
32
32
  return btoa(binary).replaceAll("+", "-").replaceAll("/", "_").replaceAll("=", "");
33
33
  }
34
- /** The decoded text, or undefined for a value that is not canonical unpadded base64url. */
35
34
  function decodeBase64Url(value) {
36
35
  if (!/^[A-Za-z0-9_-]*$/.test(value) || value.length % 4 === 1) return;
37
36
  const normalized = value.replaceAll("-", "+").replaceAll("_", "/");
@@ -132,7 +132,6 @@ type CollectionAccess = {
132
132
  authorize?: AccessAuthorizeOption<Request & ViteHubContext>;
133
133
  route: false;
134
134
  };
135
- /** The access of a source that returns whole table rows without `transform`. The route cannot be public. */
136
135
  type RawRowsAccess = {
137
136
  access?: undefined;
138
137
  authorize: AccessAuthorizeOption<Request & ViteHubContext>;
@@ -142,10 +141,6 @@ type RawRowsAccess = {
142
141
  authorize?: AccessAuthorizeOption<Request & ViteHubContext>;
143
142
  route: false;
144
143
  };
145
- /**
146
- * A cursor the loader must not mutate. Only object cursors become readonly, so `AnyCollectionSource` keeps `any`
147
- * instead of `Readonly<any>`, an index-signature object that rejects string and number cursors.
148
- */
149
144
  type ReadonlyCursor<TCursorInput> = TCursorInput extends object ? Readonly<TCursorInput> : TCursorInput;
150
145
  interface CollectionLoaderOptions<TSourceItem, TQuery extends object, TCursorInput extends CollectionCursorValue, TCursorOutput extends CollectionCursorValue = TCursorInput> {
151
146
  cursor(item: NoInfer<TSourceItem>): ReadonlyCursor<TCursorInput>;
@@ -177,10 +172,6 @@ interface CollectionSourceBase<TSourceItem, TQueryInput extends object, TQuery e
177
172
  defaultLimit?: number;
178
173
  maxLimit?: number;
179
174
  querySchema?: StandardSchemaV1<TQueryInput, TQuery>;
180
- /**
181
- * `true` when the source returns whole rows, such as every column of a database table. A Collection over it needs
182
- * `transform` to pick the public fields before it can set `access: "public"`.
183
- */
184
175
  rawRows?: boolean;
185
176
  }
186
177
  /** A loader whose rows carry their own cursor. The Collection requests one extra row to detect the next page. */
@@ -211,10 +202,6 @@ type LoadedItemOf<TSource> = TSource extends {
211
202
  type LoadOptionsOf<TSource> = TSource extends {
212
203
  load: (options: infer TOptions) => unknown;
213
204
  } ? TOptions : never;
214
- /**
215
- * Ties a source's own parts to its loader. `AnyCollectionSource` only bounds each part, so without this a cursor,
216
- * `get`, or query schema written for other rows or another query would pass.
217
- */
218
205
  type SourceContract<TSource> = (TSource extends {
219
206
  cursor: (item: never) => unknown;
220
207
  } ? {
@@ -235,7 +222,6 @@ type SourceContract<TSource> = (TSource extends {
235
222
  type SourceCollectionOptions<TSource extends AnyCollectionSource> = {
236
223
  source: TSource & SourceContract<TSource>;
237
224
  } & CollectionAccess;
238
- /** A source with `rawRows: true` and no `transform` cannot have a public route. */
239
225
  type SourceAccessWithoutTransform<TSource> = TSource extends {
240
226
  rawRows: true;
241
227
  } ? RawRowsAccess : unknown;
package/dist/drizzle.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { _ as CollectionQueryInput, b as CollectionSource, y as CollectionRequestQuery } from "./collection-B8sgxw5-.js";
1
+ import { _ as CollectionQueryInput, b as CollectionSource, y as CollectionRequestQuery } from "./collection-DTk0O1SE.js";
2
2
  import { StandardSchemaV1 } from "@standard-schema/spec";
3
3
  //#region src/drizzle.d.ts
4
4
  interface TableShape {
@@ -1,4 +1,4 @@
1
- import { n as matchesAny } from "./path-Q-KcGmAN.js";
1
+ import { t as createPathMatcher } from "./path-Q-KcGmAN.js";
2
2
  import { t as sourceErrorDiagnostics } from "./error-diagnostics-DZdhDQpU.js";
3
3
  import { n as isRecord } from "./object-CtSHeGQO.js";
4
4
  import { i as sourceError, n as normalizeSafeSourcePath, r as normalizeSourcePath } from "./path-Cm7wV1Dk.js";
@@ -36,7 +36,7 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
36
36
  why: ({ message }) => message === void 0 ? "" : String(message)
37
37
  },
38
38
  INTERNAL_R0022: {
39
- fix: "Send input that matches the schema of the operation. `vitehub <namespace> <command> --help` shows the fields.",
39
+ fix: "Send input that matches the schema of the operation. `vitehub <namespace> <command> --help` shows the fields, and the list_operations tool of the ViteHub MCP gives the input schema of each operation.",
40
40
  why: ({ message }) => message === void 0 ? "" : String(message)
41
41
  },
42
42
  INTERNAL_R0024: {
@@ -255,6 +255,10 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
255
255
  why: ({ owner }) => `[vitehub] ${owner} extends tuple requires [preset, options] with an options object.`,
256
256
  fix: "Set `extends` to a preset, or to a two-item tuple `[preset, { ...options }]` whose second item is a plain object."
257
257
  },
258
+ INTERNAL_RUNTIME_PACKAGE_VERSION_CONFLICT: {
259
+ why: ({ first, name, second }) => `[vitehub] One server function needs ${name} from two installations: ${first} and ${second}.`,
260
+ fix: "Install one version of the package that the message names, for example with `pnpm dedupe` or an `overrides` entry in `package.json`, then build again."
261
+ },
258
262
  INTERNAL_SECRET_PURPOSE_MISSING: {
259
263
  why: "[vitehub] A derived secret requires a purpose.",
260
264
  fix: "Pass a non-empty purpose to `deriveSecret()`, such as `deriveSecret(\"my-module:session\")`."
@@ -414,6 +418,17 @@ const forgeEnv = {
414
418
  names: ["VITEHUB_FORGEJO_WEBHOOK_SECRET", "FORGES_FORGEJO_WEBHOOK_SECRET"],
415
419
  secret: true
416
420
  }
421
+ },
422
+ gitea: {
423
+ baseUrl: { names: ["VITEHUB_GITEA_BASE_URL", "FORGES_GITEA_BASE_URL"] },
424
+ token: {
425
+ names: ["VITEHUB_GITEA_TOKEN", "FORGES_GITEA_TOKEN"],
426
+ secret: true
427
+ },
428
+ webhookSecret: {
429
+ names: ["VITEHUB_GITEA_WEBHOOK_SECRET", "FORGES_GITEA_WEBHOOK_SECRET"],
430
+ secret: true
431
+ }
417
432
  }
418
433
  };
419
434
  /**
@@ -461,16 +476,9 @@ async function loadForge() {
461
476
  throw forgeImportError(error, "A GitHub Source");
462
477
  }
463
478
  }
464
- /** GitHub lists at most this many files in a compare response. */
465
479
  const compareFileLimit = 300;
466
- /** GitHub lists at most 3,000 files of a pull request, 100 on each page. */
467
480
  const pullFilePages = 30;
468
- /**
469
- * `changedPaths()` reads the files of each commit between the two commits, up to this many commits. More commits read
470
- * every page again.
471
- */
472
481
  const compareCommitLimit = 20;
473
- /** Commit requests of `changedPaths()` that run at once. */
474
482
  const compareCommitConcurrency = 4;
475
483
  /** The Server Env token: `VITEHUB_GITHUB_TOKEN`, then `FORGES_GITHUB_TOKEN`. */
476
484
  function githubEnvToken() {
@@ -499,7 +507,6 @@ function fileCommit(repo, item) {
499
507
  url: item.html_url
500
508
  };
501
509
  }
502
- /** Undefined when GitHub answers that the ref does not exist: 404, or 422 for an unknown commit SHA. */
503
510
  async function missingAsUndefined(load) {
504
511
  try {
505
512
  return await load();
@@ -551,7 +558,6 @@ function createGitHubClient(repo) {
551
558
  function repoName(value) {
552
559
  return isRecord(value) && isNonEmptyString(value.full_name) ? value.full_name : null;
553
560
  }
554
- /** A pull request from `/pulls/<number>` or `/commits/<sha>/pulls`. The list has `merged_at` but no `merged`. */
555
561
  function pullRequest(data, number) {
556
562
  if (!isRecord(data) || !Number.isSafeInteger(number) || !isRecord(data.head) || !isRecord(data.base) || !isNonEmptyString(data.head.sha) || !isNonEmptyString(data.head.ref) || !isNonEmptyString(data.base.ref)) throw malformed(repo, "pull request");
557
563
  const headRepo = repoName(data.head.repo);
@@ -575,7 +581,6 @@ function createGitHubClient(repo) {
575
581
  async branch(branch, token, signal) {
576
582
  const data = await missingAsUndefined(() => request(branch, "branch", token, signal, async (client, repoRef) => (await client.request("GET", `${repoPath(repoRef)}/git/ref/heads/${branch.split("/").map(encodeURIComponent).join("/")}`, { signal })).data));
577
583
  if (data === void 0) return;
578
- if (Array.isArray(data)) return;
579
584
  if (!isRecord(data) || !isRecord(data.object) || !isNonEmptyString(data.object.sha)) throw malformed(repo, "branch");
580
585
  return data.object.sha;
581
586
  },
@@ -954,11 +959,8 @@ async function loadGitArchiveFiles(input, executeGit = runGit) {
954
959
  }
955
960
  //#endregion
956
961
  //#region src/sources/github/index.ts
957
- /** Files per GraphQL request of `latest()`. GitHub answers 150 in about 4 seconds, and stops a request at 10. */
958
962
  const historyBatch = 150;
959
- /** `latest()` splits a request that GitHub stopped down to this many files, then gives up. */
960
963
  const historyBatchMin = 20;
961
- /** GraphQL requests of `latest()` that run at once. */
962
964
  const historyConcurrency = 4;
963
965
  function dedupeProviderPromise(promises, key, load) {
964
966
  const promise = promises.get(key);
@@ -1000,26 +1002,32 @@ function github(options) {
1000
1002
  return await auth;
1001
1003
  }
1002
1004
  function keyForRepoPath(path) {
1003
- let normalized;
1004
1005
  try {
1005
- normalized = normalizeSafeSourcePath(path);
1006
+ const normalized = normalizeSafeSourcePath(path);
1007
+ if (!root) return normalized;
1008
+ if (!normalized.startsWith(`${root}/`)) return;
1009
+ return normalizeSafeSourcePath(normalized.slice(root.length + 1));
1006
1010
  } catch {
1007
1011
  return;
1008
1012
  }
1009
- if (!root) return normalized;
1010
- if (!normalized.startsWith(`${root}/`)) return void 0;
1011
- const key = normalized.slice(root.length + 1);
1012
- if (!key || key.startsWith("/")) return void 0;
1013
- return normalizeSafeSourcePath(key);
1014
1013
  }
1015
1014
  function repoPathForKey(key) {
1016
1015
  const normalized = normalizeSourcePath(key);
1017
1016
  return root ? `${root}/${normalized}` : normalized;
1018
1017
  }
1019
- function shouldInclude(key) {
1020
- if (options.include && !matchesAny(key, options.include)) return false;
1021
- if (options.ignore && matchesAny(key, options.ignore)) return false;
1022
- return true;
1018
+ function keyFilter() {
1019
+ const include = createPathMatcher(options.include);
1020
+ const ignore = options.ignore ? createPathMatcher(options.ignore) : () => false;
1021
+ return (key) => include(key) && !ignore(key);
1022
+ }
1023
+ function sourceKeys(paths) {
1024
+ const shouldInclude = keyFilter();
1025
+ const keys = /* @__PURE__ */ new Set();
1026
+ for (const path of paths) {
1027
+ const key = keyForRepoPath(path);
1028
+ if (key && shouldInclude(key)) keys.add(key);
1029
+ }
1030
+ return [...keys];
1023
1031
  }
1024
1032
  async function resolveRef(token) {
1025
1033
  if (configuredRef) return configuredRef;
@@ -1073,8 +1081,7 @@ function github(options) {
1073
1081
  if (!configuredRef) return;
1074
1082
  await client.resolveCommit(configuredRef, token);
1075
1083
  }
1076
- async function loadArchiveFiles(token, resolvedRef) {
1077
- const ref = resolvedRef ?? await getRef(token);
1084
+ async function loadArchiveFiles(token, ref, shouldInclude) {
1078
1085
  return parseGitHubArchive(await client.archive(ref, token)).map((entry) => {
1079
1086
  const key = keyForRepoPath(entry.path);
1080
1087
  if (!key || !shouldInclude(key)) return void 0;
@@ -1089,6 +1096,7 @@ function github(options) {
1089
1096
  }
1090
1097
  async function loadFiles(token, resolvedRef) {
1091
1098
  const ref = resolvedRef ?? await getRef(token);
1099
+ const shouldInclude = keyFilter();
1092
1100
  if (sparsePatterns) try {
1093
1101
  return await loadGitArchiveFiles({
1094
1102
  credentials: (await loadForge()).forgeGitCredentials({
@@ -1103,7 +1111,7 @@ function github(options) {
1103
1111
  sparsePatterns
1104
1112
  });
1105
1113
  } catch {}
1106
- return await loadArchiveFiles(token, ref);
1114
+ return await loadArchiveFiles(token, ref, shouldInclude);
1107
1115
  }
1108
1116
  const loadedFiles = /* @__PURE__ */ new Map();
1109
1117
  const cachedLoadFiles = providerCache ? defineCachedFunction(async (resolvedRef, token) => await loadFiles(token, resolvedRef), {
@@ -1121,7 +1129,7 @@ function github(options) {
1121
1129
  } catch {
1122
1130
  return;
1123
1131
  }
1124
- if (!normalizedKey || !shouldInclude(normalizedKey)) return;
1132
+ if (!normalizedKey || !keyFilter()(normalizedKey)) return;
1125
1133
  const ref = resolvedRef ?? await getRef(token);
1126
1134
  const repoPath = repoPathForKey(normalizedKey);
1127
1135
  let file;
@@ -1159,7 +1167,7 @@ function github(options) {
1159
1167
  } catch {
1160
1168
  throw sourceError(`[vitehub] github(${JSON.stringify(options.repo)}) could not find ${JSON.stringify(key)}.`);
1161
1169
  }
1162
- if (!normalizedKey || !shouldInclude(normalizedKey)) throw sourceError(`[vitehub] github(${JSON.stringify(options.repo)}) could not find ${JSON.stringify(key)}.`);
1170
+ if (!normalizedKey || !keyFilter()(normalizedKey)) throw sourceError(`[vitehub] github(${JSON.stringify(options.repo)}) could not find ${JSON.stringify(key)}.`);
1163
1171
  const ref = resolvedRef ?? await getRef(token, signal);
1164
1172
  const repoPath = repoPathForKey(normalizedKey);
1165
1173
  const file = await client.file(repoPath, ref, token, signal);
@@ -1236,14 +1244,12 @@ function github(options) {
1236
1244
  async changes(base, head) {
1237
1245
  const paths = await client.changedPaths(base, head, await resolveAuth());
1238
1246
  if (!paths) return;
1239
- const prefix = root ? `${root}/` : "";
1240
- return [...new Set(paths.filter((path) => path.startsWith(prefix)).map((path) => path.slice(prefix.length)))];
1247
+ return sourceKeys(paths);
1241
1248
  },
1242
1249
  async pullChanges(number) {
1243
1250
  const paths = await client.pullPaths(number, await resolveAuth());
1244
1251
  if (!paths) return;
1245
- const prefix = root ? `${root}/` : "";
1246
- return [...new Set(paths.filter((path) => path.startsWith(prefix)).map((path) => path.slice(prefix.length)))];
1252
+ return sourceKeys(paths);
1247
1253
  },
1248
1254
  async resolveRef(ref, refOptions) {
1249
1255
  const token = await resolveAuth();
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { A as CollectionCursorErrorReason, C as ProviderCollectionOptions, D as defineCollection, E as SourceCollectionOptions, O as CollectionCursorError, S as ProviderCollectionLoader, T as ProviderCollectionSource, _ as CollectionQueryInput, a as CollectionClientItem, b as CollectionSource, c as CollectionFacets, d as CollectionLoader, f as CollectionOptions, g as CollectionQueryBuilder, h as CollectionQuery, i as CollectionAccess, k as CollectionCursorErrorOptions, l as CollectionItem, m as CollectionPageOptions, n as AnyCollectionSource, o as CollectionCursorValue, p as CollectionPage, r as Collection, s as CollectionFacetValue, t as AnyCollection, u as CollectionLoadOptions, v as CollectionReadOptions, w as ProviderCollectionPage, x as CursorCollectionSource, y as CollectionRequestQuery } from "./collection-B8sgxw5-.js";
1
+ import { A as CollectionCursorErrorReason, C as ProviderCollectionOptions, D as defineCollection, E as SourceCollectionOptions, O as CollectionCursorError, S as ProviderCollectionLoader, T as ProviderCollectionSource, _ as CollectionQueryInput, a as CollectionClientItem, b as CollectionSource, c as CollectionFacets, d as CollectionLoader, f as CollectionOptions, g as CollectionQueryBuilder, h as CollectionQuery, i as CollectionAccess, k as CollectionCursorErrorOptions, l as CollectionItem, m as CollectionPageOptions, n as AnyCollectionSource, o as CollectionCursorValue, p as CollectionPage, r as Collection, s as CollectionFacetValue, t as AnyCollection, u as CollectionLoadOptions, v as CollectionReadOptions, w as ProviderCollectionPage, x as CursorCollectionSource, y as CollectionRequestQuery } from "./collection-DTk0O1SE.js";
2
2
  import { _ as SourceMetadata, a as SingleFileSource, b as SourceRevision, c as SourceContent, d as SourceEntry, f as SourceFile, g as SourceMap, h as SourceListEntry, i as RegisteredSource, l as SourceContext, m as SourceKey, n as ReadSourceOptions, o as Source, p as SourceItem, r as ReadSourceResult, s as SourceCacheOptions, t as FileSource, u as SourceData, v as SourceName, y as SourceReader } from "./types-Ln-FxVFn.js";
3
3
  import { o as useSource } from "./registry-CUv12y8b.js";
4
4
  import { ViteHubError } from "@vite-hub/runtime";
@@ -84,7 +84,6 @@ type SplitSourceKey<TSource extends Source> = `${SourceKey<TSource>}#${string}`;
84
84
  type SplitSourceItem<TSource extends Source, TPart extends SplitSourcePart> = Omit<TPart, "key"> & {
85
85
  key: SplitSourceKey<TSource>;
86
86
  };
87
- /** A Source with one item for each part of another Source's items. */
88
87
  type SplitSourceMeta<TSource extends Source> = NonNullable<TSource["getMeta"]> extends ((...args: any[]) => infer TResult) ? TResult : Promise<undefined>;
89
88
  type SplitSource<TSource extends Source, TPart extends SplitSourcePart> = Omit<Source<SplitSourceKey<TSource>>, "getItem" | "getItems" | "getMeta"> & {
90
89
  getItem(key: SplitSourceKey<TSource>, ctx: SourceContext): Promise<SplitSourceItem<TSource, TPart>>;
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { t as sourceErrorDiagnostics } from "./error-diagnostics-DZdhDQpU.js";
2
2
  import { r as isRecordOrFunction } from "./object-CtSHeGQO.js";
3
- import { a as parseCollectionSchema, i as createCollectionCursorCodec, n as defineCollection, r as CollectionCursorError } from "./collection-C1TZnrRP.js";
3
+ import { a as parseCollectionSchema, i as createCollectionCursorCodec, n as defineCollection, r as CollectionCursorError } from "./collection-BYbbVAf8.js";
4
4
  import { i as sourceError, n as normalizeSafeSourcePath, o as sourcePathError, r as normalizeSourcePath } from "./path-Cm7wV1Dk.js";
5
5
  import { a as useSource } from "./registry-BSyFEr9r.js";
6
6
  import { t as normalizeGitHubRoot } from "./root-0Ef8tgF5.js";
@@ -17,6 +17,12 @@ const reservedQueryKeys = /* @__PURE__ */ new Set([
17
17
  function compareProtocolStrings(left, right) {
18
18
  return left < right ? -1 : left > right ? 1 : 0;
19
19
  }
20
+ function foldLatinText(value) {
21
+ return value.replace(/[A-Za-z\u00C0-\u017F\u0300-\u036F\u1E00-\u1EFF\u212A\u212B]+/g, (latin) => latin.normalize("NFD").replace(/[\u0300-\u036F]/g, "").toLowerCase());
22
+ }
23
+ function compareText(left, right) {
24
+ return compareProtocolStrings(foldLatinText(left), foldLatinText(right)) || compareProtocolStrings(left, right);
25
+ }
20
26
  const cursorCodec = createCollectionCursorCodec({ "~standard": {
21
27
  version: 1,
22
28
  vendor: "vite-hub",
@@ -33,7 +39,6 @@ const cursorCodec = createCollectionCursorCodec({ "~standard": {
33
39
  } };
34
40
  }
35
41
  } });
36
- /** Read a dot path through own properties. Arrays fan out to every element. */
37
42
  function collectionValueAt(value, path) {
38
43
  const segments = path.split(".").filter(Boolean);
39
44
  function visit(current, remaining) {
@@ -114,7 +119,7 @@ function sortItems(items, sort) {
114
119
  value: firstScalar(collectionValueAt(item, sort.field))
115
120
  })).sort(({ value: leftValue }, { value: rightValue }) => {
116
121
  if (Number(leftValue) === leftValue && Number(rightValue) === rightValue) return (leftValue - rightValue) * direction;
117
- return String(leftValue ?? "").localeCompare(String(rightValue ?? "")) * direction;
122
+ return compareText(String(leftValue ?? ""), String(rightValue ?? "")) * direction;
118
123
  }).map(({ item }) => item);
119
124
  }
120
125
  function buildFacets(items, fields, maxValues) {
@@ -124,7 +129,7 @@ function buildFacets(items, fields, maxValues) {
124
129
  return [field, [...counts].map(([value, count]) => ({
125
130
  count,
126
131
  value
127
- })).sort((left, right) => right.count - left.count || left.value.localeCompare(right.value)).slice(0, maxValues)];
132
+ })).sort((left, right) => right.count - left.count || compareText(left.value, right.value)).slice(0, maxValues)];
128
133
  }));
129
134
  }
130
135
  function array(load, options = {}) {
@@ -143,7 +148,8 @@ function array(load, options = {}) {
143
148
  search: [...searchFields].sort(),
144
149
  sort: options.sort ? {
145
150
  direction: options.sort.direction ?? "asc",
146
- field: options.sort.field
151
+ field: options.sort.field,
152
+ text: "latin-fold-v1"
147
153
  } : null
148
154
  });
149
155
  async function snapshot(signal, includeDigest) {
@@ -469,7 +475,7 @@ function files(entries, options = {}) {
469
475
  function github(options) {
470
476
  const root = normalizeGitHubRoot(options.root || "");
471
477
  let loader;
472
- const load = () => loader ??= import("./github-509beZOn.js").then((module) => module.github(options)).catch((error) => {
478
+ const load = () => loader ??= import("./github-D5JBLnyA.js").then((module) => module.github(options)).catch((error) => {
473
479
  loader = void 0;
474
480
  throw error;
475
481
  });
package/dist/server.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { r as Collection } from "./collection-B8sgxw5-.js";
1
+ import { r as Collection } from "./collection-DTk0O1SE.js";
2
2
  import { AccessAuthorizeOption, ViteHubContext } from "@vite-hub/runtime";
3
3
  import { CacheOptions } from "ocache";
4
4
  //#region src/cached-source.d.ts
package/dist/server.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { t as sourceErrorDiagnostics } from "./error-diagnostics-DZdhDQpU.js";
2
- import { r as CollectionCursorError, t as assertCollectionAccess } from "./collection-C1TZnrRP.js";
2
+ import { r as CollectionCursorError, t as assertCollectionAccess } from "./collection-BYbbVAf8.js";
3
3
  //#region src/cached-source.ts
4
4
  /** Cache `get(key)` in the Nitro `cache` storage. Other reader operations pass through unchanged. */
5
5
  function cachedSource(reader, options) {
@@ -39,7 +39,6 @@ function cachedSource(reader, options) {
39
39
  }
40
40
  //#endregion
41
41
  //#region src/server.ts
42
- /** The query of a request URL. A parameter that the URL repeats becomes an array, as in H3's `getQuery()`. */
43
42
  function requestQuery(request) {
44
43
  const query = /* @__PURE__ */ new Map();
45
44
  for (const [key, value] of new URL(request.url).searchParams) {
@@ -64,7 +63,6 @@ function queryLimit(query) {
64
63
  function collectionQuery(query) {
65
64
  return Object.fromEntries(Object.entries(query).filter(([key]) => key !== "cursor" && key !== "limit"));
66
65
  }
67
- /** An error Response with the `status` and `message` fields of an H3 error body. */
68
66
  function errorResponse(status, message) {
69
67
  return Response.json({
70
68
  status,
@@ -88,7 +86,7 @@ function serializeCollectionPage(value) {
88
86
  return JSON.parse(serialized);
89
87
  }
90
88
  function isCallable(value) {
91
- return typeof value === "function" || typeof value === "undefined" && value !== void 0;
89
+ return typeof value === "function";
92
90
  }
93
91
  function hasDeclaredMethod(value, key) {
94
92
  const object = Object(value);
package/dist/vite.d.ts CHANGED
@@ -49,6 +49,8 @@ interface ViteHubResourceSummary {
49
49
  owner: string;
50
50
  /** Absent when no id is known yet. */
51
51
  source?: ViteHubResourceIdSource;
52
+ /** The resource is in the Wrangler config of a standalone Provider Output Worker, not in Nitro's. */
53
+ standalone?: boolean;
52
54
  }
53
55
  interface ViteHubInspectionContributor {
54
56
  definitions?: readonly ViteHubDefinitionInspector[];
@@ -69,6 +71,8 @@ interface ContributionContext {
69
71
  projectRoot: string;
70
72
  /** Server directories that the host forwards, for example Nuxt's `serverDir` and the server directories of layers. */
71
73
  serverDirs?: readonly string[];
74
+ /** The flat list of Vite plugins, so a factory can read what sibling plugins declare. */
75
+ plugins?: readonly unknown[];
72
76
  }
73
77
  //#endregion
74
78
  //#region src/inspect.d.ts
@@ -96,6 +100,8 @@ export interface GeneratedSourceRoute {
96
100
  * because a lazy handler does not receive `next`. Such a handler must load heavy modules itself, on demand.
97
101
  */
98
102
  lazy?: false;
103
+ /** The Nitro route meta, such as `ownAccessRouteMeta` for a route that checks its own access. */
104
+ meta?: object;
99
105
  plugin?: never;
100
106
  route: string;
101
107
  }
package/dist/vite.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { t as collectionRoutePath } from "./collection-route-BplWPxHR.js";
2
2
  import { t as sourceErrorDiagnostics } from "./error-diagnostics-DZdhDQpU.js";
3
- import { r as isRecordOrFunction } from "./object-CtSHeGQO.js";
3
+ import { n as isRecord, r as isRecordOrFunction } from "./object-CtSHeGQO.js";
4
4
  import { i as resolveGlobInput, r as globFilePath, t as collectGlobFiles } from "./glob-DT9HlkyK.js";
5
5
  import { t as invariant } from "./invariant-DolT9EEx.js";
6
6
  import { formatDiagnostic } from "nostics";
@@ -172,7 +172,7 @@ function hasProjectRootDirectoryMarker(root) {
172
172
  for (const marker of projectRootDirectoryMarkers) try {
173
173
  if (statSync(resolve(root, ...marker)).isDirectory()) return true;
174
174
  } catch (error) {
175
- if (error.code !== "ENOENT") throw error;
175
+ if (!isMissingProjectMarker(error)) throw error;
176
176
  }
177
177
  return false;
178
178
  }
@@ -186,11 +186,15 @@ function hasProjectRootFileMarker(root, markers) {
186
186
  try {
187
187
  if (statSync(resolve(root, ...path)).isFile()) return true;
188
188
  } catch (error) {
189
- if (error.code !== "ENOENT") throw error;
189
+ if (!isMissingProjectMarker(error)) throw error;
190
190
  }
191
191
  }
192
192
  return false;
193
193
  }
194
+ function isMissingProjectMarker(error) {
195
+ const code = error.code;
196
+ return code === "ENOENT" || code === "ENOTDIR";
197
+ }
194
198
  //#endregion
195
199
  //#region ../internal/src/build/ast-walk.ts
196
200
  /** The oxc parser grammar for a file, from its extension. Defaults to TypeScript. */
@@ -446,8 +450,15 @@ function startViteHubHints(config, owner = config) {
446
450
  started.add(owner);
447
451
  write(startRun(config));
448
452
  }
449
- //#endregion
450
- //#region ../internal/src/nitro-kit.ts
453
+ Object.freeze({ vitehubAuthAccess: "handler" });
454
+ /**
455
+ * The route meta of a generated handler that checks access on every request, even when the app adds no rule: a required
456
+ * `authorize` policy, an explicit `access` rule, a required access token, or a signature. Auth access routes still apply
457
+ * to it, so an app rule stays in force. `checksOwnAccess(event)` of `vite-hub/auth` reads it, so app middleware can skip
458
+ * the route. A route that can run without a check, such as a browser error sink, an optional `authorize`, or a webhook
459
+ * with `secret: false`, must not use it.
460
+ */
461
+ const ownAccessRouteMeta = Object.freeze({ vitehubOwnAccess: true });
451
462
  function cloneArray(value) {
452
463
  return Array.isArray(value) ? [...value] : [];
453
464
  }
@@ -576,7 +587,6 @@ function renderContentTypesPlugin(importBase, contentModule) {
576
587
  }
577
588
  //#endregion
578
589
  //#region src/internal/collection-discovery.ts
579
- /** The initializers of top-level `const`, `let`, and `var` declarations named `name`, with their declaration kind. */
580
590
  function declarationInitializers(module, name, exportedOnly) {
581
591
  return module.program.body.flatMap((statement) => {
582
592
  const declaration = statement.type === "ExportNamedDeclaration" ? statement.declaration : exportedOnly ? void 0 : statement;
@@ -588,7 +598,6 @@ function declarationInitializers(module, name, exportedOnly) {
588
598
  });
589
599
  }
590
600
  const viteHubSourceSpecifier = /^(?:@vite-hub\/source|vite-hub\/source)(?:\/|$)/;
591
- /** Checks binding targets, including nested destructuring, without treating property keys or defaults as bindings. */
592
601
  function bindsCollectionFactory(binding) {
593
602
  switch (binding.type) {
594
603
  case "Identifier": return binding.name === "defineCollection";
@@ -599,11 +608,6 @@ function bindsCollectionFactory(binding) {
599
608
  default: return false;
600
609
  }
601
610
  }
602
- /**
603
- * True when `defineCollection` in this module is ViteHub's factory: imported from a ViteHub Source entry, or not
604
- * declared in the module at all (an auto-import). A local function or an import from elsewhere with that name can
605
- * return any Collection, so its options say nothing about the route.
606
- */
607
611
  function callsViteHubFactory(module) {
608
612
  for (const statement of module.program.body) {
609
613
  if (statement.type === "ImportDeclaration") {
@@ -616,17 +620,12 @@ function callsViteHubFactory(module) {
616
620
  }
617
621
  return true;
618
622
  }
619
- /** The local binding that `export { local as exportName }` exports, without a module source. */
620
623
  function exportedLocalName(module, exportName) {
621
624
  for (const statement of module.program.body) {
622
625
  if (statement.type !== "ExportNamedDeclaration" || statement.source || statement.exportKind === "type") continue;
623
626
  for (const specifier of statement.specifiers) if ((specifier.exported.type === "Identifier" ? specifier.exported.name : specifier.exported.value) === exportName && specifier.local.type === "Identifier") return specifier.local.name;
624
627
  }
625
628
  }
626
- /**
627
- * Finds the `defineCollection(...)` call that initializes the named export. An initializer with more than one call,
628
- * such as a conditional, has no known call: the scanner cannot know which branch runs.
629
- */
630
629
  function findCollectionDefinitionCall(source, exportName, file) {
631
630
  const module = scanModule(source, `${file}.ts`);
632
631
  const calls = findCalls(module, ["defineCollection"]);
@@ -650,11 +649,6 @@ function findCollectionDefinitionCall(source, exportName, file) {
650
649
  if (call) return call;
651
650
  }
652
651
  }
653
- /**
654
- * True only for a literal `route: false` in the options of the exported `defineCollection()` call. A spread or a
655
- * computed key after it can set `route` again when the module runs, so the route stays. Any other form keeps the route,
656
- * and `defineCollectionHandler()` answers 404 at request time when the Collection has `route: false`.
657
- */
658
652
  function collectionRouteDisabled(definition) {
659
653
  if (!definition?.exported) return false;
660
654
  const options = argumentExpression(definition.call.arguments[1] ?? definition.call.arguments[0]);
@@ -737,7 +731,6 @@ function readMember(object, name) {
737
731
  value: property.value
738
732
  };
739
733
  }
740
- /** An identifier path such as `schema` or `tables.articles`, as written without whitespace. */
741
734
  function identifierPath(value, optional) {
742
735
  if (value.type === "Identifier") return value.name;
743
736
  if (value.type !== "MemberExpression" || value.computed || value.property.type !== "Identifier" || value.optional && !optional) return;
@@ -768,7 +761,6 @@ function describeStringList(member) {
768
761
  if (values.some((value) => value === void 0)) return dynamic;
769
762
  return values.length ? values.join(", ") : "None";
770
763
  }
771
- /** Shows an identifier path as written and a call as `callee(...)`. Other expressions show as `Inline`. */
772
764
  function describeExpression(member) {
773
765
  if (member.method) return "Inline";
774
766
  const path = identifierPath(member.value, true);
@@ -872,7 +864,6 @@ function tableFields(options) {
872
864
  pushLimits(fields, options);
873
865
  return fields;
874
866
  }
875
- /** Fields of a custom source object and of the options in `defineCollection(load, options)`. */
876
867
  function loaderFields(options) {
877
868
  const pagination = readMember(options, "pagination");
878
869
  const fields = [{
@@ -966,11 +957,6 @@ async function inspectCollectionDefinitions(options) {
966
957
  }
967
958
  //#endregion
968
959
  //#region src/internal/bundle-glob.ts
969
- /**
970
- * Bundling glob(): a ViteHub server build swaps each `glob()` call whose options are literals for a module that holds
971
- * the files it matches, through files(). Hosts without a file system, such as Cloudflare Workers, then serve the same
972
- * keys and bytes that glob() reads from disk. `vite dev` keeps glob() as it is.
973
- */
974
960
  /** Prefix of the generated modules' ids. `\0` keeps other plugins from resolving or transforming them. */
975
961
  const BUNDLED_GLOB_ID = "\0vitehub-source-glob:";
976
962
  /** Matches those ids, for Rolldown's hook filters. */
@@ -993,7 +979,6 @@ function walk(node, visit) {
993
979
  for (const value of Object.values(node)) if (Array.isArray(value)) value.forEach((child) => isNode(child) && walk(child, visit));
994
980
  else if (isNode(value)) walk(value, visit);
995
981
  }
996
- /** A literal's value, or undefined for anything that is not one. */
997
982
  function literal(node) {
998
983
  if (!node) return void 0;
999
984
  if (node.type === "Literal") return node.value;
@@ -1368,10 +1353,6 @@ async function writeCollectionArtifacts(options, collections) {
1368
1353
  };
1369
1354
  }));
1370
1355
  }
1371
- /**
1372
- * Writes the `ViteHubSourceMap` types and a Nitro plugin that registers a loader for each file in `server/sources/`
1373
- * by its name, so `useSource("docs")` opens the default export of `server/sources/docs.ts`.
1374
- */
1375
1356
  async function writeSourceArtifacts(options, sources) {
1376
1357
  const types = resolve(options.projectRoot, sourceTypesEntry);
1377
1358
  const registry = resolve(options.projectRoot, sourceRegistryEntry);
@@ -1446,7 +1427,6 @@ function astName(node) {
1446
1427
  if (node.type === "Identifier" && String(node.name) === node.name) return node.name;
1447
1428
  if (node.type === "Literal" && String(node.value) === node.value) return node.value;
1448
1429
  }
1449
- /** Drops `as`, `satisfies`, `!`, and parentheses around an expression. */
1450
1430
  function unwrapAst(node) {
1451
1431
  let current = node;
1452
1432
  while (isAstNode(current) && [
@@ -1626,23 +1606,27 @@ function inspectContentOptions(program, contentImportBase) {
1626
1606
  }
1627
1607
  return features;
1628
1608
  }
1609
+ async function inspectContentEntryForGeneration(file, contentImportBase) {
1610
+ const { parseAst } = await import("vite");
1611
+ return inspectContentModule(parseAst(await readFile(file, "utf8"), { lang: /\.[cm]?ts$/.test(file) ? "ts" : "js" }), contentImportBase);
1612
+ }
1629
1613
  /** Read what the Content module defines without running it. A file that does not parse counts as defining everything. */
1630
1614
  async function inspectContentEntry(file, contentImportBase) {
1631
- const { parseAst } = await import("vite");
1632
1615
  try {
1633
- return inspectContentModule(parseAst(await readFile(file, "utf8"), { lang: /\.[cm]?ts$/.test(file) ? "ts" : "js" }), contentImportBase);
1634
- } catch {
1616
+ return await inspectContentEntryForGeneration(file, contentImportBase);
1617
+ } catch (error) {
1618
+ if (!isRecord(error) || error.code !== "PARSE_ERROR") throw error;
1635
1619
  return {
1636
1620
  route: true,
1637
1621
  collections: true,
1638
- sitemap: false,
1639
- robots: false,
1640
- markdown: false,
1641
- rss: false,
1642
- mcp: false,
1643
- llms: false,
1622
+ sitemap: true,
1623
+ robots: true,
1624
+ markdown: true,
1625
+ rss: true,
1626
+ mcp: "unknown",
1627
+ llms: true,
1644
1628
  live: true,
1645
- previews: false,
1629
+ previews: true,
1646
1630
  sqlite: false,
1647
1631
  github: false
1648
1632
  };
@@ -1685,7 +1669,7 @@ async function writeContentArtifact(options, file) {
1685
1669
  const importBase = JSON.stringify(options.contentImportBase ?? "@vite-hub/content");
1686
1670
  const contentModule = JSON.stringify(toRuntimeModuleSpecifier(file));
1687
1671
  const features = {
1688
- ...await inspectContentEntry(file, options.contentImportBase ?? "@vite-hub/content"),
1672
+ ...await inspectContentEntryForGeneration(file, options.contentImportBase ?? "@vite-hub/content"),
1689
1673
  ...options.appSeo?.sitemap ? { sitemap: false } : {},
1690
1674
  ...options.appSeo?.robots ? { robots: false } : {}
1691
1675
  };
@@ -1754,6 +1738,7 @@ async function writeContentArtifact(options, file) {
1754
1738
  ].join("\n"));
1755
1739
  handlers.push({
1756
1740
  handler: githubWebhook,
1741
+ meta: { ...ownAccessRouteMeta },
1757
1742
  method: "post",
1758
1743
  route: "/_vitehub/content/github"
1759
1744
  });
@@ -1878,7 +1863,6 @@ async function prepareSourceArtifacts(options) {
1878
1863
  async function prepareSourceGeneration(options) {
1879
1864
  return (await prepareSourceArtifacts(options)).handlers;
1880
1865
  }
1881
- /** Nuxt serves Vite assets from `/_nuxt/`, so its Vite `base` is not the app base. `vite-hub/nuxt` passes the app base. */
1882
1866
  function applicationBaseURL(config) {
1883
1867
  const configured = Reflect.get(config, VITEHUB_APP_BASE_URL);
1884
1868
  const base = typeof configured === "string" ? configured : config.base;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vite-hub/source",
3
- "version": "0.4.1",
3
+ "version": "0.5.0",
4
4
  "description": "Typed source retrieval primitives for ViteHub.",
5
5
  "keywords": [
6
6
  "content",
@@ -67,7 +67,7 @@
67
67
  },
68
68
  "dependencies": {
69
69
  "@standard-schema/spec": "^1.1.0",
70
- "@vite-hub/runtime": "0.4.1",
70
+ "@vite-hub/runtime": "0.5.0",
71
71
  "mrmime": "^2.0.1",
72
72
  "nostics": "1.4.0",
73
73
  "ocache": "^0.3.1"
@@ -76,7 +76,7 @@
76
76
  "@modelcontextprotocol/sdk": "^1.32.1",
77
77
  "@types/node": "^24.19.1",
78
78
  "@types/picomatch": "^4.0.3",
79
- "@vite-hub/forge": "0.4.1",
79
+ "@vite-hub/forge": "0.5.0",
80
80
  "@vite-hub/internal": "0.0.1",
81
81
  "drizzle-orm": "1.0.0-rc.5",
82
82
  "h3": "^2.0.8",
@@ -97,7 +97,7 @@
97
97
  "nitro": "3.0.261102-rc || ^3.0.261103-rc",
98
98
  "vite": ">=8.0.0",
99
99
  "vue": "^3.5.0",
100
- "@vite-hub/forge": "0.4.1"
100
+ "@vite-hub/forge": "0.5.0"
101
101
  },
102
102
  "peerDependenciesMeta": {
103
103
  "@modelcontextprotocol/sdk": {