@vite-hub/source 0.4.1 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,7 +1,6 @@
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-DXi2zyTi.js";
2
2
  import { Diagnostic } from "nostics";
3
3
  import { ComputedRef, MaybeRefOrGetter, Ref } from "vue";
4
- //#region src/client.d.ts
5
4
  export interface CollectionRequestOptions {
6
5
  query?: Record<string, unknown>;
7
6
  signal: AbortSignal;
@@ -46,4 +45,4 @@ export declare class CollectionAccessError extends Diagnostic {
46
45
  };
47
46
  }
48
47
  export declare function useCollection<TName extends CollectionName>(name: TName, options?: UseCollectionOptions<RegisteredCollection<TName>>): UseCollectionReturn<RegisteredCollection<TName>>;
49
- //#endregion
48
+ export {};
package/dist/client.js CHANGED
@@ -1,9 +1,8 @@
1
- import { n as encodeCollectionRouteSegment } from "./collection-route-BplWPxHR.js";
2
- import { t as sourceErrorDiagnostics } from "./error-diagnostics-DZdhDQpU.js";
1
+ import { n as encodeCollectionRouteSegment } from "./collection-route-DhDZBuGk.js";
2
+ import { t as sourceErrorDiagnostics } from "./error-diagnostics-TunlTPXq.js";
3
3
  import { Diagnostic } from "nostics";
4
4
  import { computed, onScopeDispose, ref, toValue, watch } from "vue";
5
- //#region src/client.ts
6
- /** Thrown by the default requester when a Collection route answers with an error status. */
5
+ // src/client.ts
7
6
  var CollectionRequestError = class CollectionRequestError extends Diagnostic {
8
7
  status;
9
8
  constructor(endpoint, status) {
@@ -201,5 +200,4 @@ function useCollection(name, options = {}) {
201
200
  total
202
201
  };
203
202
  }
204
- //#endregion
205
203
  export { CollectionAccessError, useCollection };
@@ -1,14 +1,13 @@
1
- import { t as sourceErrorDiagnostics } from "./error-diagnostics-DZdhDQpU.js";
2
- import { t as isPlainRecord } from "./object-CtSHeGQO.js";
1
+ import { t as sourceErrorDiagnostics } from "./error-diagnostics-TunlTPXq.js";
2
+ import { t as isPlainRecord } from "./object-D8cOtgW3.js";
3
3
  import { Diagnostic } from "nostics";
4
- //#region src/core/schema.ts
4
+ // src/core/schema.ts
5
5
  async function parseCollectionSchema(schema, value) {
6
6
  const result = await schema["~standard"].validate(value);
7
7
  if (result.issues) throw sourceErrorDiagnostics.SOURCE_R0006({ message: result.issues[0]?.message ?? "Collection value is invalid." });
8
8
  return result.value;
9
9
  }
10
- //#endregion
11
- //#region src/core/collection-cursor.ts
10
+ // src/core/collection-cursor.ts
12
11
  /** A Collection cursor was rejected. Routes answer `400` for `malformed` and `409` for `stale`. */
13
12
  var CollectionCursorError = class CollectionCursorError extends Diagnostic {
14
13
  reason;
@@ -31,7 +30,6 @@ function encodeBase64Url(value) {
31
30
  for (const byte of bytes) binary += String.fromCharCode(byte);
32
31
  return btoa(binary).replaceAll("+", "-").replaceAll("/", "_").replaceAll("=", "");
33
32
  }
34
- /** The decoded text, or undefined for a value that is not canonical unpadded base64url. */
35
33
  function decodeBase64Url(value) {
36
34
  if (!/^[A-Za-z0-9_-]*$/.test(value) || value.length % 4 === 1) return;
37
35
  const normalized = value.replaceAll("-", "+").replaceAll("_", "/");
@@ -104,8 +102,7 @@ function createCollectionCursorCodec(schema) {
104
102
  }
105
103
  };
106
104
  }
107
- //#endregion
108
- //#region src/core/collection.ts
105
+ // src/core/collection.ts
109
106
  const untransformedTableRows = Symbol.for("@vite-hub/source/untransformed-table-rows");
110
107
  const defaultPageLimit = 50;
111
108
  const defaultMaxLimit = 100;
@@ -293,5 +290,4 @@ function assertCollectionAccess(definition) {
293
290
  function isProviderCursor(value) {
294
291
  return value === String(value);
295
292
  }
296
- //#endregion
297
293
  export { parseCollectionSchema as a, createCollectionCursorCodec as i, defineCollection as n, CollectionCursorError as r, assertCollectionAccess as t };
@@ -1,7 +1,6 @@
1
1
  import { Diagnostic } from "nostics";
2
2
  import { AccessAuthorizeOption, ViteHubContext } from "@vite-hub/runtime";
3
3
  import { StandardSchemaV1 } from "@standard-schema/spec";
4
- //#region src/core/collection-cursor.d.ts
5
4
  /** Why a Collection rejected a cursor: it cannot be decoded, or it belongs to other data or another query. */
6
5
  type CollectionCursorErrorReason = "malformed" | "stale";
7
6
  interface CollectionCursorErrorOptions extends ErrorOptions {
@@ -12,8 +11,6 @@ declare class CollectionCursorError extends Diagnostic {
12
11
  readonly reason: CollectionCursorErrorReason;
13
12
  constructor(message?: string, options?: CollectionCursorErrorOptions);
14
13
  }
15
- //#endregion
16
- //#region src/core/collection.d.ts
17
14
  declare const collectionQueryInput: unique symbol;
18
15
  type CollectionRequestQuery = Record<string, string | readonly string[] | undefined>;
19
16
  type CollectionCursorValue = boolean | null | number | string | readonly CollectionCursorValue[] | {
@@ -132,7 +129,6 @@ type CollectionAccess = {
132
129
  authorize?: AccessAuthorizeOption<Request & ViteHubContext>;
133
130
  route: false;
134
131
  };
135
- /** The access of a source that returns whole table rows without `transform`. The route cannot be public. */
136
132
  type RawRowsAccess = {
137
133
  access?: undefined;
138
134
  authorize: AccessAuthorizeOption<Request & ViteHubContext>;
@@ -142,10 +138,6 @@ type RawRowsAccess = {
142
138
  authorize?: AccessAuthorizeOption<Request & ViteHubContext>;
143
139
  route: false;
144
140
  };
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
141
  type ReadonlyCursor<TCursorInput> = TCursorInput extends object ? Readonly<TCursorInput> : TCursorInput;
150
142
  interface CollectionLoaderOptions<TSourceItem, TQuery extends object, TCursorInput extends CollectionCursorValue, TCursorOutput extends CollectionCursorValue = TCursorInput> {
151
143
  cursor(item: NoInfer<TSourceItem>): ReadonlyCursor<TCursorInput>;
@@ -177,10 +169,6 @@ interface CollectionSourceBase<TSourceItem, TQueryInput extends object, TQuery e
177
169
  defaultLimit?: number;
178
170
  maxLimit?: number;
179
171
  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
172
  rawRows?: boolean;
185
173
  }
186
174
  /** A loader whose rows carry their own cursor. The Collection requests one extra row to detect the next page. */
@@ -211,10 +199,6 @@ type LoadedItemOf<TSource> = TSource extends {
211
199
  type LoadOptionsOf<TSource> = TSource extends {
212
200
  load: (options: infer TOptions) => unknown;
213
201
  } ? 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
202
  type SourceContract<TSource> = (TSource extends {
219
203
  cursor: (item: never) => unknown;
220
204
  } ? {
@@ -235,7 +219,6 @@ type SourceContract<TSource> = (TSource extends {
235
219
  type SourceCollectionOptions<TSource extends AnyCollectionSource> = {
236
220
  source: TSource & SourceContract<TSource>;
237
221
  } & CollectionAccess;
238
- /** A source with `rawRows: true` and no `transform` cannot have a public route. */
239
222
  type SourceAccessWithoutTransform<TSource> = TSource extends {
240
223
  rawRows: true;
241
224
  } ? RawRowsAccess : unknown;
@@ -286,5 +269,4 @@ declare function defineCollection<TSourceItem, TCursorSchema extends StandardSch
286
269
  querySchema?: undefined;
287
270
  transform?: undefined;
288
271
  }): Collection<TSourceItem, CollectionRequestQuery, CollectionRequestQuery>;
289
- //#endregion
290
272
  export { CollectionCursorErrorReason as A, ProviderCollectionOptions as C, defineCollection as D, SourceCollectionOptions as E, CollectionCursorError as O, ProviderCollectionLoader as S, ProviderCollectionSource as T, CollectionQueryInput as _, CollectionClientItem as a, CollectionSource as b, CollectionFacets as c, CollectionLoader as d, CollectionOptions as f, CollectionQueryBuilder as g, CollectionQuery as h, CollectionAccess as i, CollectionCursorErrorOptions as k, CollectionItem as l, CollectionPageOptions as m, AnyCollectionSource as n, CollectionCursorValue as o, CollectionPage as p, Collection as r, CollectionFacetValue as s, AnyCollection as t, CollectionLoadOptions as u, CollectionReadOptions as v, ProviderCollectionPage as w, CursorCollectionSource as x, CollectionRequestQuery as y };
@@ -1,4 +1,4 @@
1
- //#region src/internal/collection-route.ts
1
+ // src/internal/collection-route.ts
2
2
  function encodeCollectionRouteSegment(segment) {
3
3
  return encodeURIComponent(segment).replaceAll("*", "%2A");
4
4
  }
@@ -6,5 +6,4 @@ function encodeCollectionRouteSegment(segment) {
6
6
  function collectionRoutePath(name) {
7
7
  return `/api/${name.split("/").map(encodeCollectionRouteSegment).join("/")}`;
8
8
  }
9
- //#endregion
10
9
  export { encodeCollectionRouteSegment as n, collectionRoutePath as t };
package/dist/drizzle.d.ts CHANGED
@@ -1,6 +1,5 @@
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-DXi2zyTi.js";
2
2
  import { StandardSchemaV1 } from "@standard-schema/spec";
3
- //#region src/drizzle.d.ts
4
3
  interface TableShape {
5
4
  readonly _: {
6
5
  readonly columns: Record<string, unknown>;
@@ -45,4 +44,4 @@ export declare function table<TTable extends TableShape>(options: TableSourceOpt
45
44
  }): CollectionSource<TTable["$inferSelect"], CollectionRequestQuery, KeysetCursor> & {
46
45
  rawRows: true;
47
46
  };
48
- //#endregion
47
+ export {};
package/dist/drizzle.js CHANGED
@@ -1,6 +1,6 @@
1
- import { t as sourceErrorDiagnostics } from "./error-diagnostics-DZdhDQpU.js";
1
+ import { t as sourceErrorDiagnostics } from "./error-diagnostics-TunlTPXq.js";
2
2
  import { and, asc, desc, eq, getTableColumns, gt, lt, or } from "drizzle-orm";
3
- //#region src/drizzle.ts
3
+ // src/drizzle.ts
4
4
  const requestQuerySchema = { "~standard": {
5
5
  version: 1,
6
6
  vendor: "vite-hub",
@@ -83,5 +83,4 @@ function table(input) {
83
83
  rawRows: true
84
84
  };
85
85
  }
86
- //#endregion
87
86
  export { table };
@@ -1,5 +1,5 @@
1
1
  import { defineDiagnostics } from "nostics";
2
- //#region src/error-diagnostics.ts
2
+ // src/error-diagnostics.ts
3
3
  const dynamicError = { why: ({ message }) => message === void 0 ? "" : String(message) };
4
4
  const sourceErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
5
5
  docsBase: "https://vitehub.dev/docs/source/diagnostics",
@@ -198,5 +198,4 @@ const sourceErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
198
198
  }
199
199
  }
200
200
  });
201
- //#endregion
202
201
  export { sourceErrorDiagnostics as t };
@@ -1,16 +1,16 @@
1
- import { n as matchesAny } from "./path-Q-KcGmAN.js";
2
- import { t as sourceErrorDiagnostics } from "./error-diagnostics-DZdhDQpU.js";
3
- import { n as isRecord } from "./object-CtSHeGQO.js";
4
- import { i as sourceError, n as normalizeSafeSourcePath, r as normalizeSourcePath } from "./path-Cm7wV1Dk.js";
5
- import { t as normalizeGitHubRoot } from "./root-0Ef8tgF5.js";
6
- import { n as invariantError } from "./invariant-DolT9EEx.js";
1
+ import { i as sourceError, n as normalizeSafeSourcePath, r as normalizeSourcePath } from "./path-ZomRTEWV.js";
2
+ import { t as createPathMatcher } from "./path-8MJ_XVEB.js";
3
+ import { t as sourceErrorDiagnostics } from "./error-diagnostics-TunlTPXq.js";
4
+ import { n as isRecord } from "./object-D8cOtgW3.js";
5
+ import { n as invariantError } from "./invariant-Dj2R1eMr.js";
6
+ import { t as normalizeGitHubRoot } from "./root-gdkJ8uqd.js";
7
7
  import { defineDiagnostics } from "nostics";
8
8
  import { devNull } from "node:os";
9
9
  import { createHash } from "node:crypto";
10
10
  import { gunzipSync } from "node:zlib";
11
11
  import { defineCachedFunction } from "ocache";
12
12
  import { Buffer } from "node:buffer";
13
- //#region ../internal/src/error-diagnostics.ts
13
+ // ../internal/src/error-diagnostics.ts
14
14
  const dynamicError = { why: ({ message }) => message === void 0 ? "" : String(message) };
15
15
  const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
16
16
  docsBase: "https://vitehub.dev/docs/development/diagnostics",
@@ -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\")`."
@@ -263,6 +267,10 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
263
267
  why: ({ minimum }) => `[vitehub] VITEHUB_SECRET must be at least ${minimum} characters. Generate one with \`openssl rand -base64 32\`.`,
264
268
  fix: "Set `VITEHUB_SECRET` to the output of `openssl rand -base64 32`, which has 44 characters."
265
269
  },
270
+ INTERNAL_SITE_TOKEN_TOO_LONG: {
271
+ why: ({ length, maximum }) => `The Site access token is ${length} characters, and an app accepts ${maximum}.`,
272
+ fix: "Open the app with a shorter path, or give the person and the project shorter names, so that the Site access token fits."
273
+ },
266
274
  INTERNAL_SQLITE_ARGUMENT_INVALID: {
267
275
  why: ({ value }) => value === "undefined" ? "undefined cannot be passed as argument to the database" : "Only finite numbers (not Infinity or NaN) can be passed as arguments",
268
276
  fix: "Pass query arguments as finite numbers, strings, booleans, bigints, dates, byte arrays, or null. Replace undefined with null, and check numbers with `Number.isFinite()` before the query."
@@ -277,8 +285,7 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
277
285
  }
278
286
  }
279
287
  });
280
- //#endregion
281
- //#region src/sources/github/archive.ts
288
+ // src/sources/github/archive.ts
282
289
  function parseGitHubArchive(bytes) {
283
290
  const tar = gunzipSync(bytes);
284
291
  const files = [];
@@ -344,8 +351,7 @@ function stripArchiveRoot(path) {
344
351
  return;
345
352
  }
346
353
  }
347
- //#endregion
348
- //#region src/sources/github/cache.ts
354
+ // src/sources/github/cache.ts
349
355
  function normalizeGitHubCache(options) {
350
356
  if (options.cache === false) return;
351
357
  if (options.cache && typeof options.cache === "object") return { maxAge: options.cache.maxAge };
@@ -365,8 +371,7 @@ function createGitHubCacheKey(input) {
365
371
  function githubAuthenticationScope(token) {
366
372
  return token ? createHash("sha256").update(token).digest("hex") : "anonymous";
367
373
  }
368
- //#endregion
369
- //#region ../internal/src/forge.ts
374
+ // ../internal/src/forge.ts
370
375
  /**
371
376
  * Server Env of each Forge, keyed by the `env.server.<forge>.<field>` path.
372
377
  * Channels, Capabilities, Workspaces and Sources read the same names.
@@ -414,6 +419,17 @@ const forgeEnv = {
414
419
  names: ["VITEHUB_FORGEJO_WEBHOOK_SECRET", "FORGES_FORGEJO_WEBHOOK_SECRET"],
415
420
  secret: true
416
421
  }
422
+ },
423
+ gitea: {
424
+ baseUrl: { names: ["VITEHUB_GITEA_BASE_URL", "FORGES_GITEA_BASE_URL"] },
425
+ token: {
426
+ names: ["VITEHUB_GITEA_TOKEN", "FORGES_GITEA_TOKEN"],
427
+ secret: true
428
+ },
429
+ webhookSecret: {
430
+ names: ["VITEHUB_GITEA_WEBHOOK_SECRET", "FORGES_GITEA_WEBHOOK_SECRET"],
431
+ secret: true
432
+ }
417
433
  }
418
434
  };
419
435
  /**
@@ -451,8 +467,7 @@ function forgeImportError(error, feature) {
451
467
  function isMissingForge(error) {
452
468
  return error instanceof Error && /(?:cannot find (?:package|module)|no such module|could not resolve) ['"]@vite-hub\/forge['"]/i.test(error.message);
453
469
  }
454
- //#endregion
455
- //#region src/sources/github/client.ts
470
+ // src/sources/github/client.ts
456
471
  /** `@vite-hub/forge`, an optional peer. A GitHub Source loads it on its first request. */
457
472
  async function loadForge() {
458
473
  try {
@@ -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
  },
@@ -773,8 +778,7 @@ function createGitHubClient(repo) {
773
778
  }
774
779
  };
775
780
  }
776
- //#endregion
777
- //#region src/sources/github/git.ts
781
+ // src/sources/github/git.ts
778
782
  function createGitEnv(home, authHeader, baseEnv = process.env) {
779
783
  const env = { ...baseEnv };
780
784
  for (const key of [
@@ -952,13 +956,9 @@ async function loadGitArchiveFiles(input, executeGit = runGit) {
952
956
  });
953
957
  }
954
958
  }
955
- //#endregion
956
- //#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. */
959
+ // src/sources/github/index.ts
958
960
  const historyBatch = 150;
959
- /** `latest()` splits a request that GitHub stopped down to this many files, then gives up. */
960
961
  const historyBatchMin = 20;
961
- /** GraphQL requests of `latest()` that run at once. */
962
962
  const historyConcurrency = 4;
963
963
  function dedupeProviderPromise(promises, key, load) {
964
964
  const promise = promises.get(key);
@@ -1000,26 +1000,32 @@ function github(options) {
1000
1000
  return await auth;
1001
1001
  }
1002
1002
  function keyForRepoPath(path) {
1003
- let normalized;
1004
1003
  try {
1005
- normalized = normalizeSafeSourcePath(path);
1004
+ const normalized = normalizeSafeSourcePath(path);
1005
+ if (!root) return normalized;
1006
+ if (!normalized.startsWith(`${root}/`)) return;
1007
+ return normalizeSafeSourcePath(normalized.slice(root.length + 1));
1006
1008
  } catch {
1007
1009
  return;
1008
1010
  }
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
1011
  }
1015
1012
  function repoPathForKey(key) {
1016
1013
  const normalized = normalizeSourcePath(key);
1017
1014
  return root ? `${root}/${normalized}` : normalized;
1018
1015
  }
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;
1016
+ function keyFilter() {
1017
+ const include = createPathMatcher(options.include);
1018
+ const ignore = options.ignore ? createPathMatcher(options.ignore) : () => false;
1019
+ return (key) => include(key) && !ignore(key);
1020
+ }
1021
+ function sourceKeys(paths) {
1022
+ const shouldInclude = keyFilter();
1023
+ const keys = /* @__PURE__ */ new Set();
1024
+ for (const path of paths) {
1025
+ const key = keyForRepoPath(path);
1026
+ if (key && shouldInclude(key)) keys.add(key);
1027
+ }
1028
+ return [...keys];
1023
1029
  }
1024
1030
  async function resolveRef(token) {
1025
1031
  if (configuredRef) return configuredRef;
@@ -1073,8 +1079,7 @@ function github(options) {
1073
1079
  if (!configuredRef) return;
1074
1080
  await client.resolveCommit(configuredRef, token);
1075
1081
  }
1076
- async function loadArchiveFiles(token, resolvedRef) {
1077
- const ref = resolvedRef ?? await getRef(token);
1082
+ async function loadArchiveFiles(token, ref, shouldInclude) {
1078
1083
  return parseGitHubArchive(await client.archive(ref, token)).map((entry) => {
1079
1084
  const key = keyForRepoPath(entry.path);
1080
1085
  if (!key || !shouldInclude(key)) return void 0;
@@ -1089,6 +1094,7 @@ function github(options) {
1089
1094
  }
1090
1095
  async function loadFiles(token, resolvedRef) {
1091
1096
  const ref = resolvedRef ?? await getRef(token);
1097
+ const shouldInclude = keyFilter();
1092
1098
  if (sparsePatterns) try {
1093
1099
  return await loadGitArchiveFiles({
1094
1100
  credentials: (await loadForge()).forgeGitCredentials({
@@ -1103,7 +1109,7 @@ function github(options) {
1103
1109
  sparsePatterns
1104
1110
  });
1105
1111
  } catch {}
1106
- return await loadArchiveFiles(token, ref);
1112
+ return await loadArchiveFiles(token, ref, shouldInclude);
1107
1113
  }
1108
1114
  const loadedFiles = /* @__PURE__ */ new Map();
1109
1115
  const cachedLoadFiles = providerCache ? defineCachedFunction(async (resolvedRef, token) => await loadFiles(token, resolvedRef), {
@@ -1121,7 +1127,7 @@ function github(options) {
1121
1127
  } catch {
1122
1128
  return;
1123
1129
  }
1124
- if (!normalizedKey || !shouldInclude(normalizedKey)) return;
1130
+ if (!normalizedKey || !keyFilter()(normalizedKey)) return;
1125
1131
  const ref = resolvedRef ?? await getRef(token);
1126
1132
  const repoPath = repoPathForKey(normalizedKey);
1127
1133
  let file;
@@ -1159,7 +1165,7 @@ function github(options) {
1159
1165
  } catch {
1160
1166
  throw sourceError(`[vitehub] github(${JSON.stringify(options.repo)}) could not find ${JSON.stringify(key)}.`);
1161
1167
  }
1162
- if (!normalizedKey || !shouldInclude(normalizedKey)) throw sourceError(`[vitehub] github(${JSON.stringify(options.repo)}) could not find ${JSON.stringify(key)}.`);
1168
+ if (!normalizedKey || !keyFilter()(normalizedKey)) throw sourceError(`[vitehub] github(${JSON.stringify(options.repo)}) could not find ${JSON.stringify(key)}.`);
1163
1169
  const ref = resolvedRef ?? await getRef(token, signal);
1164
1170
  const repoPath = repoPathForKey(normalizedKey);
1165
1171
  const file = await client.file(repoPath, ref, token, signal);
@@ -1236,14 +1242,12 @@ function github(options) {
1236
1242
  async changes(base, head) {
1237
1243
  const paths = await client.changedPaths(base, head, await resolveAuth());
1238
1244
  if (!paths) return;
1239
- const prefix = root ? `${root}/` : "";
1240
- return [...new Set(paths.filter((path) => path.startsWith(prefix)).map((path) => path.slice(prefix.length)))];
1245
+ return sourceKeys(paths);
1241
1246
  },
1242
1247
  async pullChanges(number) {
1243
1248
  const paths = await client.pullPaths(number, await resolveAuth());
1244
1249
  if (!paths) return;
1245
- const prefix = root ? `${root}/` : "";
1246
- return [...new Set(paths.filter((path) => path.startsWith(prefix)).map((path) => path.slice(prefix.length)))];
1250
+ return sourceKeys(paths);
1247
1251
  },
1248
1252
  async resolveRef(ref, refOptions) {
1249
1253
  const token = await resolveAuth();
@@ -1313,5 +1317,4 @@ function github(options) {
1313
1317
  }
1314
1318
  };
1315
1319
  }
1316
- //#endregion
1317
1320
  export { github };
@@ -1,10 +1,10 @@
1
- import { i as __toESM, r as require_picomatch, t as createPathMatcher } from "./path-Q-KcGmAN.js";
2
- import { i as sourceError, n as normalizeSafeSourcePath, r as normalizeSourcePath } from "./path-Cm7wV1Dk.js";
1
+ import { i as __toESM, r as require_picomatch, t as createPathMatcher } from "./path-8MJ_XVEB.js";
2
+ import { i as sourceError, n as normalizeSafeSourcePath, r as normalizeSourcePath } from "./path-ZomRTEWV.js";
3
3
  import * as nativeFs from "fs";
4
4
  import { readdir, readdirSync, realpath, realpathSync, stat, statSync } from "fs";
5
5
  import { basename, dirname, isAbsolute, normalize, posix, relative, resolve, sep } from "path";
6
6
  import { fileURLToPath } from "url";
7
- //#region ../../node_modules/.pnpm/fdir@6.5.0_picomatch@4.0.7/node_modules/fdir/dist/index.mjs
7
+ // ../../node_modules/.pnpm/fdir@6.5.0_picomatch@4.0.7/node_modules/fdir/dist/index.mjs
8
8
  function cleanPath(path) {
9
9
  let normalized = normalize(path);
10
10
  if (normalized.length > 1 && normalized[normalized.length - 1] === sep) normalized = normalized.substring(0, normalized.length - 1);
@@ -505,8 +505,7 @@ var Builder = class {
505
505
  return this;
506
506
  }
507
507
  };
508
- //#endregion
509
- //#region ../../node_modules/.pnpm/tinyglobby@0.2.17/node_modules/tinyglobby/dist/index.mjs
508
+ // ../../node_modules/.pnpm/tinyglobby@0.2.17/node_modules/tinyglobby/dist/index.mjs
510
509
  var import_picomatch = /* @__PURE__ */ __toESM(require_picomatch(), 1);
511
510
  const isReadonlyArray = Array.isArray;
512
511
  const BACKSLASHES = /\\/g;
@@ -783,8 +782,7 @@ async function glob$1(globInput, options) {
783
782
  const [crawler, relative] = getCrawler(globInput, options);
784
783
  return crawler ? formatPaths(await crawler.withPromise(), relative) : [];
785
784
  }
786
- //#endregion
787
- //#region src/sources/glob.ts
785
+ // src/sources/glob.ts
788
786
  /**
789
787
  * The options a pattern stands for: the folders before its first wildcard are `cwd`, so keys are the paths below
790
788
  * them (`content/docs/**\/*.md` keys `guide/setup.md`). A pattern without a wildcard names a folder: every file in it.
@@ -989,5 +987,4 @@ async function resolveRootedGlobFilePath(key, paths, followSymlinks) {
989
987
  function isUnavailablePathError(error) {
990
988
  return error instanceof Error && ["ENOENT", "ELOOP"].includes(String(Reflect.get(error, "code")));
991
989
  }
992
- //#endregion
993
990
  export { resolveGlobInput as i, glob as n, globFilePath as r, collectGlobFiles as t };