@vite-hub/source 0.3.0 → 0.4.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 +26 -27
- package/dist/client.js +1 -1
- package/dist/{collection-C0Rvrx3p.js → collection-C1TZnrRP.js} +1 -1
- package/dist/drizzle.js +1 -1
- package/dist/{error-diagnostics-ClQKdi7c.js → error-diagnostics-DZdhDQpU.js} +8 -0
- package/dist/{github-D5S0dEZe.js → github-509beZOn.js} +97 -92
- package/dist/{glob-DmdMVqjx.js → glob-DT9HlkyK.js} +2 -1
- package/dist/index.d.ts +3 -12
- package/dist/index.js +9 -134
- package/dist/internal/registry.d.ts +2 -0
- package/dist/internal/registry.js +2 -0
- package/dist/mcp.js +3 -2
- package/dist/path-Cm7wV1Dk.js +32 -0
- package/dist/{path-DFlSryRA.js → path-Q-KcGmAN.js} +2 -32
- package/dist/registry-BSyFEr9r.js +156 -0
- package/dist/registry-CUv12y8b.d.ts +23 -0
- package/dist/{root-DJNmqCEW.js → root-0Ef8tgF5.js} +1 -1
- package/dist/server.js +2 -2
- package/dist/vite.d.ts +32 -2
- package/dist/vite.js +312 -148
- package/package.json +10 -5
package/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# @vite-hub/source
|
|
2
2
|
|
|
3
3
|
<p>
|
|
4
|
-
<a href="https://vitehub.dev"><img alt="ViteHub" src="https://
|
|
5
|
-
<img alt="TypeScript" src="https://
|
|
6
|
-
<img alt="Sources" src="https://
|
|
4
|
+
<a href="https://vitehub.dev"><img alt="ViteHub" src="https://img.shields.io/static/v1?label=ViteHub&message=vitehub.dev&color=blue"></a>
|
|
5
|
+
<img alt="TypeScript" src="https://img.shields.io/static/v1?label=TypeScript&message=ready&color=blue">
|
|
6
|
+
<img alt="Sources" src="https://img.shields.io/static/v1?label=Source&message=typed+retrieval&color=blue">
|
|
7
7
|
</p>
|
|
8
8
|
|
|
9
9
|
`@vite-hub/source` loads files, globs, markdown, GitHub content, or custom data before something else places it in a workspace.
|
|
@@ -17,21 +17,21 @@ pnpm add @vite-hub/source
|
|
|
17
17
|
## Open a Source
|
|
18
18
|
|
|
19
19
|
```ts
|
|
20
|
-
import {
|
|
20
|
+
import { glob, useSource } from "@vite-hub/source"
|
|
21
21
|
|
|
22
22
|
export const docs = glob({ cwd: "docs", include: "**/*.md" })
|
|
23
23
|
|
|
24
|
-
const reader =
|
|
24
|
+
const reader = useSource(docs, { rootDir: process.cwd() })
|
|
25
25
|
const revision = await reader.revision()
|
|
26
26
|
const keys = await reader.keys()
|
|
27
27
|
const first = await reader.read(keys[0]!)
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
-
`
|
|
30
|
+
`useSource(definition, context?)` infers keys, items, and metadata from the
|
|
31
31
|
Source definition. It resolves a revision and prepares the Source once per
|
|
32
32
|
reader. Revision-aware loaders receive the same pinned revision on every
|
|
33
33
|
operation. Loaders without revision support can observe origin changes. Create
|
|
34
|
-
another reader to resolve a new revision.
|
|
34
|
+
another reader to resolve a new revision.
|
|
35
35
|
|
|
36
36
|
`glob()` treats both `/` and `\` as path separators in `include` and `ignore`,
|
|
37
37
|
including before wildcards: the JavaScript string `"docs\\*.md"` means
|
|
@@ -52,7 +52,7 @@ File paths are relative to the Source root. Absolute paths, Windows drive paths
|
|
|
52
52
|
Use `defineSource()` for custom loaders:
|
|
53
53
|
|
|
54
54
|
```ts
|
|
55
|
-
import {
|
|
55
|
+
import { defineSource, useSource } from "@vite-hub/source"
|
|
56
56
|
|
|
57
57
|
const articles = defineSource({
|
|
58
58
|
name: "articles",
|
|
@@ -64,7 +64,7 @@ const articles = defineSource({
|
|
|
64
64
|
},
|
|
65
65
|
})
|
|
66
66
|
|
|
67
|
-
const article = await
|
|
67
|
+
const article = await useSource(articles).get("article_123")
|
|
68
68
|
article.data.title
|
|
69
69
|
article.metadata.version
|
|
70
70
|
```
|
|
@@ -82,7 +82,7 @@ Their `SourceFile` items guarantee `content`. Custom loaders that guarantee
|
|
|
82
82
|
content receive file methods too. Record readers use `get()` and `items()`.
|
|
83
83
|
|
|
84
84
|
`github()` reads GitHub through `@vite-hub/forge`, an optional peer that it loads on the first read. Install it with
|
|
85
|
-
`pnpm add @vite-hub/forge`. `auth` is a token or a trusted
|
|
85
|
+
`pnpm add @vite-hub/forge`. A build of server code that calls `github()` without it fails with `VITE_HUB_R0136`. `auth` is a token or a trusted
|
|
86
86
|
callback. Without `auth`, it reads Server Env `VITEHUB_GITHUB_TOKEN`, then
|
|
87
87
|
`FORGES_GITHUB_TOKEN`. It does not read `GH_TOKEN` or `GITHUB_TOKEN`.
|
|
88
88
|
`auth: false` reads without a token. `authenticated()` tells whether reads send a
|
|
@@ -158,26 +158,25 @@ export default defineWorkspace({
|
|
|
158
158
|
Workspace owns paths, materialization, sync, and access rules. Source owns
|
|
159
159
|
retrieval. Content owns parsed documents, navigation, queries, and search.
|
|
160
160
|
|
|
161
|
-
##
|
|
161
|
+
## Name a Source with a file
|
|
162
162
|
|
|
163
|
-
```ts
|
|
164
|
-
import {
|
|
163
|
+
```ts [server/sources/docs.ts]
|
|
164
|
+
import { glob } from "vite-hub/source"
|
|
165
165
|
|
|
166
|
-
|
|
166
|
+
export default glob({ cwd: "docs", include: "**/*.md" })
|
|
167
|
+
```
|
|
167
168
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
docs: typeof docs
|
|
171
|
-
}
|
|
172
|
-
}
|
|
169
|
+
```ts fragment
|
|
170
|
+
import { useSource } from "vite-hub/source"
|
|
173
171
|
|
|
174
172
|
await useSource("docs").read("intro.md")
|
|
175
173
|
```
|
|
176
174
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
`RegisteredSource<"docs">`
|
|
175
|
+
The Vite integration finds each file in `server/sources/`. It registers the
|
|
176
|
+
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.
|
|
181
180
|
|
|
182
181
|
## Split items into parts
|
|
183
182
|
|
|
@@ -185,7 +184,7 @@ for Collections and Content does not generate `ViteHubSourceMap`.
|
|
|
185
184
|
sections of a Markdown file. Each part key is `<parent key>#<part key>`:
|
|
186
185
|
|
|
187
186
|
```ts
|
|
188
|
-
import {
|
|
187
|
+
import { splitSource, glob, useSource } from "@vite-hub/source"
|
|
189
188
|
|
|
190
189
|
const sections = splitSource({
|
|
191
190
|
source: glob({ cwd: "docs", include: "**/*.md" }),
|
|
@@ -193,7 +192,7 @@ const sections = splitSource({
|
|
|
193
192
|
.map(section => ({ key: section.slice(0, section.indexOf("\n")), content: section })),
|
|
194
193
|
})
|
|
195
194
|
|
|
196
|
-
await
|
|
195
|
+
await useSource(sections).read("guide.md#Usage")
|
|
197
196
|
```
|
|
198
197
|
|
|
199
198
|
The result is a Source definition. `get()` reads only the parent item of the
|
|
@@ -208,7 +207,7 @@ Use `cachedSource()` to add Nitro caching to a keyed reader. It loads
|
|
|
208
207
|
```ts fragment
|
|
209
208
|
import { cachedSource } from "@vite-hub/source/server"
|
|
210
209
|
|
|
211
|
-
const cachedDocs = cachedSource(
|
|
210
|
+
const cachedDocs = cachedSource(useSource(docs), { name: "docs", maxAge: 60 })
|
|
212
211
|
await cachedDocs.get("intro.md")
|
|
213
212
|
```
|
|
214
213
|
|
|
@@ -216,7 +215,7 @@ Use a different cache name for each origin and access scope.
|
|
|
216
215
|
|
|
217
216
|
The `cache` option of a loader, such as `github({ cache: { maxAge } })`, is a
|
|
218
217
|
hint for the consumer of the Source. The Workspace reads it to decide when its
|
|
219
|
-
copy of the Source content is stale. A reader from `
|
|
218
|
+
copy of the Source content is stale. A reader from `useSource()` alone does
|
|
220
219
|
not read `cache` and does not cache.
|
|
221
220
|
|
|
222
221
|
## Collections
|
package/dist/client.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as encodeCollectionRouteSegment } from "./collection-route-BplWPxHR.js";
|
|
2
|
-
import { t as sourceErrorDiagnostics } from "./error-diagnostics-
|
|
2
|
+
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
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as sourceErrorDiagnostics } from "./error-diagnostics-
|
|
1
|
+
import { t as sourceErrorDiagnostics } from "./error-diagnostics-DZdhDQpU.js";
|
|
2
2
|
import { t as isPlainRecord } from "./object-CtSHeGQO.js";
|
|
3
3
|
import { Diagnostic } from "nostics";
|
|
4
4
|
//#region src/core/schema.ts
|
package/dist/drizzle.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as sourceErrorDiagnostics } from "./error-diagnostics-
|
|
1
|
+
import { t as sourceErrorDiagnostics } from "./error-diagnostics-DZdhDQpU.js";
|
|
2
2
|
import { and, asc, desc, eq, getTableColumns, gt, lt, or } from "drizzle-orm";
|
|
3
3
|
//#region src/drizzle.ts
|
|
4
4
|
const requestQuerySchema = { "~standard": {
|
|
@@ -180,6 +180,14 @@ const sourceErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
180
180
|
why: ({ route, other }) => `[vitehub] defineContent({ seo: { mcp } }) serves its MCP server at ${JSON.stringify(route)}, and ${other} answers there too.`,
|
|
181
181
|
fix: "One route serves one MCP server. Give the app MCP server another route, such as `vitehub({ mcp: { route: '/mcp/app' } })`, or another `publicRoute`. Or set `seo: { mcp: false }` in server/content.ts."
|
|
182
182
|
},
|
|
183
|
+
SOURCE_FILE_DEFAULT_EXPORT_MISSING: {
|
|
184
|
+
why: ({ path }) => `[vitehub] ${path} has no default export. Each file in server/sources/ defines one Source as its default export.`,
|
|
185
|
+
fix: "Write `export default glob({ ... })`, or another Source such as `github({ ... })`, in the file. Move helper code that is not a Source out of server/sources/."
|
|
186
|
+
},
|
|
187
|
+
SOURCE_FILE_NAME_DUPLICATE: {
|
|
188
|
+
why: ({ name, files }) => `[vitehub] The Source name ${JSON.stringify(name)} comes from two files: ${files}.`,
|
|
189
|
+
fix: "Keep each Source name in one server directory. Rename or remove one of the two files, such as the one in a Nuxt layer."
|
|
190
|
+
},
|
|
183
191
|
SOURCE_GITHUB_ARCHIVE_INVALID: {
|
|
184
192
|
why: "[vitehub] The archive of the github() Source has an entry with an invalid size.",
|
|
185
193
|
fix: "Load the Source again: GitHub or `git archive` sent a cut or broken archive. If it fails again, check the network and that the ref of the `github()` Source exists."
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as sourceErrorDiagnostics } from "./error-diagnostics-
|
|
1
|
+
import { n as matchesAny } from "./path-Q-KcGmAN.js";
|
|
2
|
+
import { t as sourceErrorDiagnostics } from "./error-diagnostics-DZdhDQpU.js";
|
|
3
3
|
import { n as isRecord } from "./object-CtSHeGQO.js";
|
|
4
|
-
import {
|
|
4
|
+
import { i as sourceError, n as normalizeSafeSourcePath, r as normalizeSourcePath } from "./path-Cm7wV1Dk.js";
|
|
5
|
+
import { t as normalizeGitHubRoot } from "./root-0Ef8tgF5.js";
|
|
5
6
|
import { n as invariantError } from "./invariant-DolT9EEx.js";
|
|
6
7
|
import { defineDiagnostics } from "nostics";
|
|
7
8
|
import { devNull } from "node:os";
|
|
@@ -9,94 +10,6 @@ import { createHash } from "node:crypto";
|
|
|
9
10
|
import { gunzipSync } from "node:zlib";
|
|
10
11
|
import { defineCachedFunction } from "ocache";
|
|
11
12
|
import { Buffer } from "node:buffer";
|
|
12
|
-
//#region src/sources/github/archive.ts
|
|
13
|
-
function parseGitHubArchive(bytes) {
|
|
14
|
-
const tar = gunzipSync(bytes);
|
|
15
|
-
const files = [];
|
|
16
|
-
let offset = 0;
|
|
17
|
-
let paxPath;
|
|
18
|
-
while (offset + 512 <= tar.length) {
|
|
19
|
-
const header = tar.subarray(offset, offset + 512);
|
|
20
|
-
if (header.every((byte) => byte === 0)) break;
|
|
21
|
-
const name = readTarString(header, 0, 100);
|
|
22
|
-
const prefix = readTarString(header, 345, 155);
|
|
23
|
-
const path = paxPath || [prefix, name].filter(Boolean).join("/");
|
|
24
|
-
const sizeField = readTarString(header, 124, 12).trim();
|
|
25
|
-
if (sizeField && !/^[0-7]+$/.test(sizeField)) throw sourceErrorDiagnostics.SOURCE_GITHUB_ARCHIVE_INVALID();
|
|
26
|
-
const size = sizeField ? Number.parseInt(sizeField, 8) : 0;
|
|
27
|
-
if (!Number.isSafeInteger(size) || size < 0) throw sourceErrorDiagnostics.SOURCE_GITHUB_ARCHIVE_INVALID();
|
|
28
|
-
const type = String.fromCharCode(header[156] || 0);
|
|
29
|
-
const contentStart = offset + 512;
|
|
30
|
-
const contentEnd = contentStart + size;
|
|
31
|
-
const entryEnd = contentStart + Math.ceil(size / 512) * 512;
|
|
32
|
-
if (entryEnd > tar.length) throw sourceErrorDiagnostics.SOURCE_GITHUB_ARCHIVE_INVALID();
|
|
33
|
-
const content = tar.subarray(contentStart, contentEnd);
|
|
34
|
-
if (type === "x") paxPath = readPaxPath(content);
|
|
35
|
-
else {
|
|
36
|
-
if (type === "0" || type === "\0") {
|
|
37
|
-
const entryPath = stripArchiveRoot(path);
|
|
38
|
-
if (entryPath) files.push({
|
|
39
|
-
content: new Uint8Array(content),
|
|
40
|
-
path: entryPath
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
paxPath = void 0;
|
|
44
|
-
}
|
|
45
|
-
offset = entryEnd;
|
|
46
|
-
}
|
|
47
|
-
return files;
|
|
48
|
-
}
|
|
49
|
-
function readTarString(buffer, offset, length) {
|
|
50
|
-
const slice = buffer.subarray(offset, offset + length);
|
|
51
|
-
const end = slice.indexOf(0);
|
|
52
|
-
return Buffer.from(end === -1 ? slice : slice.subarray(0, end)).toString("utf8");
|
|
53
|
-
}
|
|
54
|
-
function readPaxPath(content) {
|
|
55
|
-
let index = 0;
|
|
56
|
-
while (index < content.length) {
|
|
57
|
-
let space = index;
|
|
58
|
-
while (space < content.length && content[space] !== 32) space++;
|
|
59
|
-
if (space >= content.length) return;
|
|
60
|
-
const length = Number.parseInt(Buffer.from(content.subarray(index, space)).toString("ascii"), 10);
|
|
61
|
-
if (!Number.isFinite(length) || length <= 0 || index + length > content.length) return;
|
|
62
|
-
const record = content.subarray(space + 1, index + length - 1);
|
|
63
|
-
const equals = record.indexOf(61);
|
|
64
|
-
if (equals !== -1 && Buffer.from(record.subarray(0, equals)).toString("utf8") === "path") return Buffer.from(record.subarray(equals + 1)).toString("utf8");
|
|
65
|
-
index += length;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
function stripArchiveRoot(path) {
|
|
69
|
-
try {
|
|
70
|
-
normalizeSafeSourcePath(path);
|
|
71
|
-
const slash = path.indexOf("/");
|
|
72
|
-
if (slash === -1) return;
|
|
73
|
-
return normalizeSafeSourcePath(path.slice(slash + 1));
|
|
74
|
-
} catch {
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
//#endregion
|
|
79
|
-
//#region src/sources/github/cache.ts
|
|
80
|
-
function normalizeGitHubCache(options) {
|
|
81
|
-
if (options.cache === false) return;
|
|
82
|
-
if (options.cache && typeof options.cache === "object") return { maxAge: options.cache.maxAge };
|
|
83
|
-
}
|
|
84
|
-
function createGitHubCacheKey(input) {
|
|
85
|
-
return JSON.stringify([
|
|
86
|
-
input.kind,
|
|
87
|
-
input.repo,
|
|
88
|
-
input.ref,
|
|
89
|
-
input.root,
|
|
90
|
-
input.include ?? null,
|
|
91
|
-
input.ignore ?? null,
|
|
92
|
-
input.authScope,
|
|
93
|
-
input.key || ""
|
|
94
|
-
]);
|
|
95
|
-
}
|
|
96
|
-
function githubAuthenticationScope(token) {
|
|
97
|
-
return token ? createHash("sha256").update(token).digest("hex") : "anonymous";
|
|
98
|
-
}
|
|
99
|
-
//#endregion
|
|
100
13
|
//#region ../internal/src/error-diagnostics.ts
|
|
101
14
|
const dynamicError = { why: ({ message }) => message === void 0 ? "" : String(message) };
|
|
102
15
|
const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
@@ -268,7 +181,7 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
268
181
|
},
|
|
269
182
|
INTERNAL_R0004: {
|
|
270
183
|
...dynamicError,
|
|
271
|
-
fix: "Set a larger `maxResponseBytes` on the HTTP request, such as the `
|
|
184
|
+
fix: "Set a larger `maxResponseBytes` on the HTTP request, such as the `url()` Source options, or ask the server for a smaller response."
|
|
272
185
|
},
|
|
273
186
|
INTERNAL_R0005: {
|
|
274
187
|
...dynamicError,
|
|
@@ -314,6 +227,10 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
314
227
|
why: ({ variable }) => `[vitehub] ${variable} must be the 43-character private key that \`vitehub secret console-key\` prints, and its name 1 to 64 of A-Z, 0-9, and _.`,
|
|
315
228
|
fix: "Set the variable that the message names to the private key that `vitehub secret console-key` prints, and name it `VITEHUB_CONSOLE_PRIVATE_KEY_<NAME>` with A-Z, 0-9, and _ in `<NAME>`."
|
|
316
229
|
},
|
|
230
|
+
INTERNAL_DEV_SERVER_NOT_FOUND: {
|
|
231
|
+
why: ({ command }) => `[vitehub] No dev server of this project is running, and --url is not set, so \`vitehub ${command}\` has no app to call.`,
|
|
232
|
+
fix: "Start the dev server of this project, such as with `pnpm dev`, or pass --url with the app URL, such as --url http://localhost:3000."
|
|
233
|
+
},
|
|
317
234
|
INTERNAL_FORGE_NOT_INSTALLED: {
|
|
318
235
|
why: ({ feature }) => `${feature} needs @vite-hub/forge, and the app did not install it.`,
|
|
319
236
|
fix: "Install Forge in your app with `pnpm add @vite-hub/forge`, then build again."
|
|
@@ -361,6 +278,94 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
361
278
|
}
|
|
362
279
|
});
|
|
363
280
|
//#endregion
|
|
281
|
+
//#region src/sources/github/archive.ts
|
|
282
|
+
function parseGitHubArchive(bytes) {
|
|
283
|
+
const tar = gunzipSync(bytes);
|
|
284
|
+
const files = [];
|
|
285
|
+
let offset = 0;
|
|
286
|
+
let paxPath;
|
|
287
|
+
while (offset + 512 <= tar.length) {
|
|
288
|
+
const header = tar.subarray(offset, offset + 512);
|
|
289
|
+
if (header.every((byte) => byte === 0)) break;
|
|
290
|
+
const name = readTarString(header, 0, 100);
|
|
291
|
+
const prefix = readTarString(header, 345, 155);
|
|
292
|
+
const path = paxPath || [prefix, name].filter(Boolean).join("/");
|
|
293
|
+
const sizeField = readTarString(header, 124, 12).trim();
|
|
294
|
+
if (sizeField && !/^[0-7]+$/.test(sizeField)) throw sourceErrorDiagnostics.SOURCE_GITHUB_ARCHIVE_INVALID();
|
|
295
|
+
const size = sizeField ? Number.parseInt(sizeField, 8) : 0;
|
|
296
|
+
if (!Number.isSafeInteger(size) || size < 0) throw sourceErrorDiagnostics.SOURCE_GITHUB_ARCHIVE_INVALID();
|
|
297
|
+
const type = String.fromCharCode(header[156] || 0);
|
|
298
|
+
const contentStart = offset + 512;
|
|
299
|
+
const contentEnd = contentStart + size;
|
|
300
|
+
const entryEnd = contentStart + Math.ceil(size / 512) * 512;
|
|
301
|
+
if (entryEnd > tar.length) throw sourceErrorDiagnostics.SOURCE_GITHUB_ARCHIVE_INVALID();
|
|
302
|
+
const content = tar.subarray(contentStart, contentEnd);
|
|
303
|
+
if (type === "x") paxPath = readPaxPath(content);
|
|
304
|
+
else {
|
|
305
|
+
if (type === "0" || type === "\0") {
|
|
306
|
+
const entryPath = stripArchiveRoot(path);
|
|
307
|
+
if (entryPath) files.push({
|
|
308
|
+
content: new Uint8Array(content),
|
|
309
|
+
path: entryPath
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
paxPath = void 0;
|
|
313
|
+
}
|
|
314
|
+
offset = entryEnd;
|
|
315
|
+
}
|
|
316
|
+
return files;
|
|
317
|
+
}
|
|
318
|
+
function readTarString(buffer, offset, length) {
|
|
319
|
+
const slice = buffer.subarray(offset, offset + length);
|
|
320
|
+
const end = slice.indexOf(0);
|
|
321
|
+
return Buffer.from(end === -1 ? slice : slice.subarray(0, end)).toString("utf8");
|
|
322
|
+
}
|
|
323
|
+
function readPaxPath(content) {
|
|
324
|
+
let index = 0;
|
|
325
|
+
while (index < content.length) {
|
|
326
|
+
let space = index;
|
|
327
|
+
while (space < content.length && content[space] !== 32) space++;
|
|
328
|
+
if (space >= content.length) return;
|
|
329
|
+
const length = Number.parseInt(Buffer.from(content.subarray(index, space)).toString("ascii"), 10);
|
|
330
|
+
if (!Number.isFinite(length) || length <= 0 || index + length > content.length) return;
|
|
331
|
+
const record = content.subarray(space + 1, index + length - 1);
|
|
332
|
+
const equals = record.indexOf(61);
|
|
333
|
+
if (equals !== -1 && Buffer.from(record.subarray(0, equals)).toString("utf8") === "path") return Buffer.from(record.subarray(equals + 1)).toString("utf8");
|
|
334
|
+
index += length;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
function stripArchiveRoot(path) {
|
|
338
|
+
try {
|
|
339
|
+
normalizeSafeSourcePath(path);
|
|
340
|
+
const slash = path.indexOf("/");
|
|
341
|
+
if (slash === -1) return;
|
|
342
|
+
return normalizeSafeSourcePath(path.slice(slash + 1));
|
|
343
|
+
} catch {
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
//#endregion
|
|
348
|
+
//#region src/sources/github/cache.ts
|
|
349
|
+
function normalizeGitHubCache(options) {
|
|
350
|
+
if (options.cache === false) return;
|
|
351
|
+
if (options.cache && typeof options.cache === "object") return { maxAge: options.cache.maxAge };
|
|
352
|
+
}
|
|
353
|
+
function createGitHubCacheKey(input) {
|
|
354
|
+
return JSON.stringify([
|
|
355
|
+
input.kind,
|
|
356
|
+
input.repo,
|
|
357
|
+
input.ref,
|
|
358
|
+
input.root,
|
|
359
|
+
input.include ?? null,
|
|
360
|
+
input.ignore ?? null,
|
|
361
|
+
input.authScope,
|
|
362
|
+
input.key || ""
|
|
363
|
+
]);
|
|
364
|
+
}
|
|
365
|
+
function githubAuthenticationScope(token) {
|
|
366
|
+
return token ? createHash("sha256").update(token).digest("hex") : "anonymous";
|
|
367
|
+
}
|
|
368
|
+
//#endregion
|
|
364
369
|
//#region ../internal/src/forge.ts
|
|
365
370
|
/**
|
|
366
371
|
* Server Env of each Forge, keyed by the `env.server.<forge>.<field>` path.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
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";
|
|
2
3
|
import * as nativeFs from "fs";
|
|
3
4
|
import { readdir, readdirSync, realpath, realpathSync, stat, statSync } from "fs";
|
|
4
5
|
import { basename, dirname, isAbsolute, normalize, posix, relative, resolve, sep } from "path";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
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";
|
|
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
|
+
import { o as useSource } from "./registry-CUv12y8b.js";
|
|
3
4
|
import { ViteHubError } from "@vite-hub/runtime";
|
|
4
5
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
5
6
|
//#region src/core/array-collection.d.ts
|
|
@@ -94,19 +95,9 @@ type SplitSource<TSource extends Source, TPart extends SplitSourcePart> = Omit<S
|
|
|
94
95
|
export declare function splitSource<const TSource extends Source, TPart extends SplitSourcePart>(options: SplitSourceOptions<TSource, TPart>): SplitSource<TSource, TPart>;
|
|
95
96
|
//#endregion
|
|
96
97
|
//#region src/core/define.d.ts
|
|
97
|
-
/** Define a loader. Open it with
|
|
98
|
+
/** Define a loader. Open it with useSource() to bind its runtime context. */
|
|
98
99
|
export declare function defineSource<const TSource extends Source>(source: TSource): TSource;
|
|
99
100
|
//#endregion
|
|
100
|
-
//#region src/core/reader.d.ts
|
|
101
|
-
export declare function createSource<const TSource extends Source>(source: TSource, context?: Partial<SourceContext>): SourceReader<TSource>;
|
|
102
|
-
//#endregion
|
|
103
|
-
//#region src/core/registry.d.ts
|
|
104
|
-
export declare function registerSource<const TName extends string, const TSource extends Source>(name: TName, source: TSource): TSource;
|
|
105
|
-
export declare function registerSources<const TSources extends Record<string, Source>>(sources: TSources): TSources;
|
|
106
|
-
export declare function clearSources(): void;
|
|
107
|
-
/** Open a registered definition with the same lifecycle as direct Source readers. */
|
|
108
|
-
export declare function useSource<TName extends SourceName>(name: TName, context?: Partial<SourceContext>): SourceReader<RegisteredSource<TName>>;
|
|
109
|
-
//#endregion
|
|
110
101
|
//#region src/core/errors.d.ts
|
|
111
102
|
type SourceErrorCode = "SOURCE_FAILED" | "SOURCE_NOT_FOUND" | "SOURCE_PATH_INVALID";
|
|
112
103
|
//#endregion
|
|
@@ -303,4 +294,4 @@ export declare function glob(input: GlobInput): FileSource<string>;
|
|
|
303
294
|
//#region src/sources/markdown.d.ts
|
|
304
295
|
export declare function markdown<const TKey extends string = string>(options: FileSourceOptions<TKey>): SingleFileSource<TKey>;
|
|
305
296
|
//#endregion
|
|
306
|
-
export { type AnyCollection, type AnyCollectionSource, type ArrayCollectionLoader, type ArrayCollectionOptions, type ArrayCollectionQuery, type ArrayCollectionQueryInput, type ArrayCollectionSnapshot, type ArrayCollectionSort, type Collection, type CollectionAccess, type CollectionClientItem, CollectionCursorError, type CollectionCursorErrorOptions, type CollectionCursorErrorReason, type CollectionCursorValue, type CollectionFacetValue, type CollectionFacets, type CollectionItem, type CollectionLoadOptions, type CollectionLoader, type CollectionOptions, type CollectionPage, type CollectionPageOptions, type CollectionQuery, type CollectionQueryBuilder, type CollectionQueryInput, type CollectionReadOptions, type CollectionRequestQuery, type CollectionSource, type CursorCollectionSource, type FileSource, type FileSourceInlineOptions, type FileSourceOptions, type FileSourcePathOptions, type FilesSourceEntry, type FilesSourceOptions, type GitHubFileCommit, type GitHubHistoryOptions, type GitHubPullRequest, type GitHubRef, type GitHubRefTarget, type GitHubSource, type GitHubSourceOptions, type GlobInput, type GlobSourceOptions, type ProviderCollectionLoader, type ProviderCollectionOptions, type ProviderCollectionPage, type ProviderCollectionSource, type ReadSourceOptions, type ReadSourceResult, type RegisteredSource, type SingleFileSource, type Source, type SourceCacheOptions, type SourceCollectionOptions, type SourceContent, type SourceContext, type SourceData, type SourceEntry, type SourceErrorCode, type SourceFile, type SourceItem, type SourceKey, type SourceListEntry, type SourceMap, type SourceMetadata, type SourceName, type SourceReader, type SourceRevision, type SplitSource, type SplitSourceItem, type SplitSourceKey, type SplitSourceOptions, type SplitSourcePart, defineCollection };
|
|
297
|
+
export { type AnyCollection, type AnyCollectionSource, type ArrayCollectionLoader, type ArrayCollectionOptions, type ArrayCollectionQuery, type ArrayCollectionQueryInput, type ArrayCollectionSnapshot, type ArrayCollectionSort, type Collection, type CollectionAccess, type CollectionClientItem, CollectionCursorError, type CollectionCursorErrorOptions, type CollectionCursorErrorReason, type CollectionCursorValue, type CollectionFacetValue, type CollectionFacets, type CollectionItem, type CollectionLoadOptions, type CollectionLoader, type CollectionOptions, type CollectionPage, type CollectionPageOptions, type CollectionQuery, type CollectionQueryBuilder, type CollectionQueryInput, type CollectionReadOptions, type CollectionRequestQuery, type CollectionSource, type CursorCollectionSource, type FileSource, type FileSourceInlineOptions, type FileSourceOptions, type FileSourcePathOptions, type FilesSourceEntry, type FilesSourceOptions, type GitHubFileCommit, type GitHubHistoryOptions, type GitHubPullRequest, type GitHubRef, type GitHubRefTarget, type GitHubSource, type GitHubSourceOptions, type GlobInput, type GlobSourceOptions, type ProviderCollectionLoader, type ProviderCollectionOptions, type ProviderCollectionPage, type ProviderCollectionSource, type ReadSourceOptions, type ReadSourceResult, type RegisteredSource, type SingleFileSource, type Source, type SourceCacheOptions, type SourceCollectionOptions, type SourceContent, type SourceContext, type SourceData, type SourceEntry, type SourceErrorCode, type SourceFile, type SourceItem, type SourceKey, type SourceListEntry, type SourceMap, type SourceMetadata, type SourceName, type SourceReader, type SourceRevision, type SplitSource, type SplitSourceItem, type SplitSourceKey, type SplitSourceOptions, type SplitSourcePart, defineCollection, useSource };
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as sourceErrorDiagnostics } from "./error-diagnostics-ClQKdi7c.js";
|
|
1
|
+
import { t as sourceErrorDiagnostics } from "./error-diagnostics-DZdhDQpU.js";
|
|
3
2
|
import { r as isRecordOrFunction } from "./object-CtSHeGQO.js";
|
|
4
|
-
import { a as parseCollectionSchema, i as createCollectionCursorCodec, n as defineCollection, r as CollectionCursorError } from "./collection-
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
3
|
+
import { a as parseCollectionSchema, i as createCollectionCursorCodec, n as defineCollection, r as CollectionCursorError } from "./collection-C1TZnrRP.js";
|
|
4
|
+
import { i as sourceError, n as normalizeSafeSourcePath, o as sourcePathError, r as normalizeSourcePath } from "./path-Cm7wV1Dk.js";
|
|
5
|
+
import { a as useSource } from "./registry-BSyFEr9r.js";
|
|
6
|
+
import { t as normalizeGitHubRoot } from "./root-0Ef8tgF5.js";
|
|
7
|
+
import { n as glob } from "./glob-DT9HlkyK.js";
|
|
7
8
|
import { lookup } from "mrmime";
|
|
8
9
|
//#region src/core/array-collection.ts
|
|
9
10
|
const defaultMaxLimit = 100;
|
|
@@ -325,137 +326,11 @@ function splitSource(options) {
|
|
|
325
326
|
}
|
|
326
327
|
//#endregion
|
|
327
328
|
//#region src/core/define.ts
|
|
328
|
-
/** Define a loader. Open it with
|
|
329
|
+
/** Define a loader. Open it with useSource() to bind its runtime context. */
|
|
329
330
|
function defineSource(source) {
|
|
330
331
|
return source;
|
|
331
332
|
}
|
|
332
333
|
//#endregion
|
|
333
|
-
//#region src/core/reader.ts
|
|
334
|
-
function createSourceContext(name, context = {}) {
|
|
335
|
-
return {
|
|
336
|
-
abortSignal: context.abortSignal,
|
|
337
|
-
revision: context.revision,
|
|
338
|
-
rootDir: context.rootDir || process.cwd(),
|
|
339
|
-
source: context.source || name,
|
|
340
|
-
sourceRootDir: context.sourceRootDir,
|
|
341
|
-
workspace: context.workspace
|
|
342
|
-
};
|
|
343
|
-
}
|
|
344
|
-
function createMissingContentError(key) {
|
|
345
|
-
return sourceError(`[vitehub] Source item ${JSON.stringify(key)} does not provide readable content.`);
|
|
346
|
-
}
|
|
347
|
-
function isNestedUnder(path, prefix) {
|
|
348
|
-
return !prefix || path === prefix || path.startsWith(`${prefix}/`);
|
|
349
|
-
}
|
|
350
|
-
function createDirectorySet(paths, prefix) {
|
|
351
|
-
const directories = /* @__PURE__ */ new Set();
|
|
352
|
-
const start = prefix ? prefix.length + 1 : 0;
|
|
353
|
-
for (const path of paths) {
|
|
354
|
-
const normalized = normalizeSourcePath(path).split("/").filter(Boolean).join("/");
|
|
355
|
-
if (prefix && !normalized.startsWith(`${prefix}/`)) continue;
|
|
356
|
-
const end = normalized.indexOf("/", start);
|
|
357
|
-
if (end !== -1) directories.add(normalized.slice(0, end));
|
|
358
|
-
}
|
|
359
|
-
return directories;
|
|
360
|
-
}
|
|
361
|
-
function createSource(source, context) {
|
|
362
|
-
const ctx = createSourceContext(source.name, context);
|
|
363
|
-
let revisionPromise;
|
|
364
|
-
let preparePromise;
|
|
365
|
-
async function revision() {
|
|
366
|
-
if (ctx.revision) return ctx.revision;
|
|
367
|
-
revisionPromise ||= source.resolveRevision?.(ctx) ?? Promise.resolve(void 0);
|
|
368
|
-
const resolved = await revisionPromise;
|
|
369
|
-
if (resolved) ctx.revision = resolved;
|
|
370
|
-
return resolved;
|
|
371
|
-
}
|
|
372
|
-
async function ensurePrepared() {
|
|
373
|
-
await revision();
|
|
374
|
-
if (!source.prepare) return;
|
|
375
|
-
preparePromise ||= source.prepare(ctx);
|
|
376
|
-
await preparePromise;
|
|
377
|
-
}
|
|
378
|
-
async function keys() {
|
|
379
|
-
await ensurePrepared();
|
|
380
|
-
return await source.getKeys(ctx);
|
|
381
|
-
}
|
|
382
|
-
async function get(key) {
|
|
383
|
-
await ensurePrepared();
|
|
384
|
-
return await source.getItem(key, ctx);
|
|
385
|
-
}
|
|
386
|
-
return {
|
|
387
|
-
revision,
|
|
388
|
-
keys,
|
|
389
|
-
get,
|
|
390
|
-
async items() {
|
|
391
|
-
await ensurePrepared();
|
|
392
|
-
if (source.getItems) return await source.getItems(ctx);
|
|
393
|
-
return await Promise.all((await keys()).map(get));
|
|
394
|
-
},
|
|
395
|
-
async read(key, options) {
|
|
396
|
-
const item = await get(key);
|
|
397
|
-
if (item.content === void 0) throw createMissingContentError(key);
|
|
398
|
-
return decodeSourceContent(item.content, options);
|
|
399
|
-
},
|
|
400
|
-
async meta(key) {
|
|
401
|
-
await ensurePrepared();
|
|
402
|
-
return await source.getMeta?.(key, ctx);
|
|
403
|
-
},
|
|
404
|
-
async exists(key) {
|
|
405
|
-
return (await keys()).includes(key);
|
|
406
|
-
},
|
|
407
|
-
async list(prefix = "") {
|
|
408
|
-
await ensurePrepared();
|
|
409
|
-
const normalizedPrefix = prefix ? normalizeSafeSourcePath(prefix, { allowEmpty: true }).split("/").filter(Boolean).join("/") : "";
|
|
410
|
-
const sourceKeys = await keys();
|
|
411
|
-
const directories = createDirectorySet(sourceKeys, normalizedPrefix);
|
|
412
|
-
const result = /* @__PURE__ */ new Map();
|
|
413
|
-
for (const directory of directories) result.set(directory, {
|
|
414
|
-
key: directory,
|
|
415
|
-
type: "directory"
|
|
416
|
-
});
|
|
417
|
-
for (const key of sourceKeys) {
|
|
418
|
-
const normalizedKey = normalizeSourcePath(key).split("/").filter(Boolean).join("/");
|
|
419
|
-
if (normalizedKey === normalizedPrefix) continue;
|
|
420
|
-
if (!isNestedUnder(normalizedKey, normalizedPrefix)) continue;
|
|
421
|
-
if (normalizedKey.slice(normalizedPrefix.length).replace(/^\//, "").includes("/")) continue;
|
|
422
|
-
result.delete(normalizedKey);
|
|
423
|
-
result.set(key, {
|
|
424
|
-
key,
|
|
425
|
-
type: "file"
|
|
426
|
-
});
|
|
427
|
-
}
|
|
428
|
-
return [...result.values()].sort((left, right) => left.key.localeCompare(right.key));
|
|
429
|
-
}
|
|
430
|
-
};
|
|
431
|
-
}
|
|
432
|
-
//#endregion
|
|
433
|
-
//#region src/core/registry.ts
|
|
434
|
-
const sourceRegistry = /* @__PURE__ */ new Map();
|
|
435
|
-
function registerSource(name, source) {
|
|
436
|
-
sourceRegistry.set(name, source);
|
|
437
|
-
return source;
|
|
438
|
-
}
|
|
439
|
-
function registerSources(sources) {
|
|
440
|
-
for (const [name, source] of Object.entries(sources)) registerSource(name, source);
|
|
441
|
-
return sources;
|
|
442
|
-
}
|
|
443
|
-
function getRegisteredSource(name) {
|
|
444
|
-
const source = sourceRegistry.get(name);
|
|
445
|
-
if (!source) throw sourceNotFoundError(name);
|
|
446
|
-
return source;
|
|
447
|
-
}
|
|
448
|
-
function clearSources() {
|
|
449
|
-
sourceRegistry.clear();
|
|
450
|
-
}
|
|
451
|
-
/** Open a registered definition with the same lifecycle as direct Source readers. */
|
|
452
|
-
function useSource(name, context) {
|
|
453
|
-
return createSource(getRegisteredSource(name), {
|
|
454
|
-
...context,
|
|
455
|
-
source: context?.source ?? name
|
|
456
|
-
});
|
|
457
|
-
}
|
|
458
|
-
//#endregion
|
|
459
334
|
//#region src/ignores.ts
|
|
460
335
|
const dependencies = Object.freeze([
|
|
461
336
|
"**/node_modules/**",
|
|
@@ -594,7 +469,7 @@ function files(entries, options = {}) {
|
|
|
594
469
|
function github(options) {
|
|
595
470
|
const root = normalizeGitHubRoot(options.root || "");
|
|
596
471
|
let loader;
|
|
597
|
-
const load = () => loader ??= import("./github-
|
|
472
|
+
const load = () => loader ??= import("./github-509beZOn.js").then((module) => module.github(options)).catch((error) => {
|
|
598
473
|
loader = void 0;
|
|
599
474
|
throw error;
|
|
600
475
|
});
|
|
@@ -632,4 +507,4 @@ function markdown(options) {
|
|
|
632
507
|
});
|
|
633
508
|
}
|
|
634
509
|
//#endregion
|
|
635
|
-
export { CollectionCursorError, array,
|
|
510
|
+
export { CollectionCursorError, array, defineCollection, defineSource, file, files, github, glob, markdown, sourceIgnores, splitSource, useSource };
|
package/dist/mcp.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as sourceErrorDiagnostics } from "./error-diagnostics-
|
|
1
|
+
import { n as matchesAny, t as createPathMatcher } from "./path-Q-KcGmAN.js";
|
|
2
|
+
import { t as sourceErrorDiagnostics } from "./error-diagnostics-DZdhDQpU.js";
|
|
3
|
+
import { i as sourceError, n as normalizeSafeSourcePath } from "./path-Cm7wV1Dk.js";
|
|
3
4
|
//#region ../internal/src/abort.ts
|
|
4
5
|
/**
|
|
5
6
|
* Runs `task` and rejects as soon as `signal` aborts, without waiting for the task.
|