@vite-hub/workspace 0.0.4 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +225 -58
- package/dist/{ai-CjxvGqM0.d.ts → ai-BW2ZhizI.d.ts} +22 -7
- package/dist/{ai-BqCC8BpY.js → ai-BZyLwULx.js} +147 -66
- package/dist/ai.d.ts +2 -2
- package/dist/ai.js +1 -1
- package/dist/{asset-registry-8QI3ML3K.js → asset-registry-DfBV5kmw.js} +3 -2
- package/dist/association-Cm0dUTDU-CDDhJnIh-Cv3bWnVb.js +19 -0
- package/dist/blob-database.d.ts +521 -0
- package/dist/blob-database.js +601 -0
- package/dist/cloudflare.d.ts +5 -6
- package/dist/cloudflare.js +1 -1
- package/dist/config-B7dmzDX3.js +1112 -0
- package/dist/{config-DE9xlaIw.d.ts → config-DLKdaFWN.d.ts} +1 -2
- package/dist/error-diagnostics-A_8Kp-48.js +116 -0
- package/dist/error-diagnostics-DY5GP47p.js +96 -0
- package/dist/events-7EBoeIPd-A2RUkJi5-BxrICQ17.js +354 -0
- package/dist/events-CRaLy7U3-3PNNp5WZ-Gv9nd0cH.js +214 -0
- package/dist/events-CeChclTf-CX-gD8oy-4aL2j6V-.js +527 -0
- package/dist/feed-DsC7Vws1-M_de2nSK-tKc0Pwo8.js +248 -0
- package/dist/feed-Dyf730Ys-D0HgBba6-BUnCa5gS.js +179 -0
- package/dist/file-C0_aPWSS.js +26 -0
- package/dist/file-metadata-CxDy-E2H.js +58 -0
- package/dist/{files-Q6xZjDHA.js → files-C7Px8uaC.js} +3 -3
- package/dist/forgejo-BN8ItCfl-Bbn4vhDd.js +2278 -0
- package/dist/{github-DHnjxQIX.js → github-CPxHtFB7.js} +16 -23
- package/dist/github-DtncTfmv-Du2S8lGF.js +4159 -0
- package/dist/gitlab-BoDm8-BC-xzZsW9eW.js +2530 -0
- package/dist/glob--XcLlcml.js +22 -0
- package/dist/glob--kNYDbfU.js +30 -0
- package/dist/graphql-DG5aJBT3-DceyFYdM-C4saqX37.js +489 -0
- package/dist/{host-DJH8cuoU.js → host-CFnrTXTK.js} +97 -41
- package/dist/{hosted-RPeJOCFz.js → hosted-acMA5XyL.js} +102 -19
- package/dist/hosted-vercel-blob-DKntsHaf.js +12603 -0
- package/dist/hosted-vercel-blob.d.ts +5 -6
- package/dist/hosted-vercel-blob.js +1 -1
- package/dist/hosted.d.ts +6 -7
- package/dist/hosted.js +1 -1
- package/dist/index.d.ts +57 -36
- package/dist/index.js +56 -56
- package/dist/inspect-BoObD2cJ.js +167 -0
- package/dist/internal/path.d.ts +2 -0
- package/dist/internal/path.js +2 -0
- package/dist/lifecycle-BwZ7c9hb.js +596 -0
- package/dist/loader.d.ts +5 -6
- package/dist/loader.js +3 -2
- package/dist/mcp-resources-BREFCmtn.js +39 -0
- package/dist/memory-BbwOqDXl.js +248 -0
- package/dist/metadata-target-DZEZQGHA.js +1588 -0
- package/dist/mountx.d.ts +4 -6
- package/dist/mountx.js +10 -8
- package/dist/nitro.d.ts +1 -1
- package/dist/nitro.js +1 -1
- package/dist/nuxt.d.ts +13 -12
- package/dist/nuxt.js +4 -8
- package/dist/operations-BcpWr41m.js +159 -0
- package/dist/operations-CGqY1XeG.js +965 -0
- package/dist/operations-DnOwKsJT.d.ts +136 -0
- package/dist/operations.d.ts +53 -0
- package/dist/operations.js +2 -0
- package/dist/path-CNAwN7pw.js +114 -0
- package/dist/path-DrSIenjj.js +59 -0
- package/dist/path-zHxQUbqa.d.ts +9 -0
- package/dist/plugins-DqQ8b4T5.d.ts +10 -0
- package/dist/provider-kXjfli9u.js +1457 -0
- package/dist/providers/github/store.d.ts +3 -5
- package/dist/providers/github/store.js +1 -1
- package/dist/{registry-D3yzt8HQ.js → registry-Bp-8UUfG.js} +9 -7
- package/dist/{registry-Uj6IVxes.d.ts → registry-Cg1TJVVZ.d.ts} +1 -2
- package/dist/{request-execution-B-dSFlGB.js → request-execution-Dk9rY-Yh.js} +19 -19
- package/dist/{chunk-2rV9d50f.js → rolldown-runtime-B4iAMlE-.js} +2 -2
- package/dist/runtime/assets.d.ts +3 -5
- package/dist/runtime/assets.js +7 -6
- package/dist/runtime/empty-assets-registry.d.ts +1 -2
- package/dist/runtime/empty-registry.d.ts +1 -2
- package/dist/runtime/state.d.ts +3 -3
- package/dist/runtime/state.js +6 -6
- package/dist/runtime/workspace.d.ts +1 -1
- package/dist/runtime/workspace.js +1 -1
- package/dist/runtime.d.ts +51 -17
- package/dist/runtime.js +320 -60
- package/dist/{search-BpiCF2Tw.js → search-CrTmXj5h.js} +10 -9
- package/dist/server-BNQ-Nbjj.js +290 -0
- package/dist/server.d.ts +22 -34
- package/dist/server.js +2 -328
- package/dist/shared-DalXdP0i.js +2158 -0
- package/dist/source-metadata.d.ts +6 -7
- package/dist/source-metadata.js +7 -7
- package/dist/{state-tYcRWEh2.d.ts → state-B8zbLi5t.d.ts} +3 -3
- package/dist/store-CXgmu-uw.js +1729 -0
- package/dist/{sync-DnTQwt8r.js → sync-CN6ec-5M.js} +61 -41
- package/dist/templates-Bn8a-pd2-D9DhJEVD-CBfXNRzz.js +125 -0
- package/dist/test.d.ts +1 -1
- package/dist/test.js +1 -1
- package/dist/{token-CVzURBxC.js → token-CO62GglH.js} +3 -3
- package/dist/{types-CYuwjJ4V.d.ts → types-DeK9GIxy.d.ts} +256 -24
- package/dist/{use-BTNDR5Rd.js → use-BQj7nSz6.js} +82 -41
- package/dist/{use-BiHzt0xA.d.ts → use-DhwhbAVV.d.ts} +16 -11
- package/dist/utils-Blrh4N2n.js +545 -0
- package/dist/vite-BEvgU2GY.js +20909 -0
- package/dist/vite-CcZmMQ7S.d.ts +476 -0
- package/dist/vite.d.ts +2 -2
- package/dist/vite.js +2 -2
- package/dist/webhooks-DgHwxxYz-D1V2LOr1-azofFOiP.js +1565 -0
- package/dist/{workspace-Dq08Yn72.js → workspace-6pxkOuxr.js} +361 -230
- package/dist/{workspace-Xddf4G1B.d.ts → workspace-BWJQBK1u.d.ts} +4 -3
- package/package.json +89 -55
- package/dist/collections/client.d.ts +0 -39
- package/dist/collections/client.js +0 -137
- package/dist/collections.d.ts +0 -59
- package/dist/collections.js +0 -159
- package/dist/config-Bc3c4Su1.js +0 -7904
- package/dist/config-CHLLWklZ.js +0 -36
- package/dist/file-Bc1X7pco.js +0 -23
- package/dist/glob-CEZKeZFC.js +0 -18
- package/dist/hosted-vercel-blob-d6C8ND5j.js +0 -23580
- package/dist/lifecycle-LrL3sA4n.js +0 -316
- package/dist/metadata-target-B0tOmVW7.js +0 -717
- package/dist/path-Cp59koVz.js +0 -139
- package/dist/provider-B1yLjCJJ.js +0 -746
- package/dist/publish.d.ts +0 -35
- package/dist/publish.js +0 -112
- package/dist/runtime-options-BsPSv5O7.js +0 -13
- package/dist/runtime-type-iEE6BjQJ.js +0 -34
- package/dist/shared-DTR1Hhma.js +0 -331
- package/dist/store-Dt_Jyys3.js +0 -608
- package/dist/vite-BptCrpv2.js +0 -4526
- package/dist/vite-CtA9guIM.d.ts +0 -66
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
|
+
//#region ../internal/src/operations.d.ts
|
|
3
|
+
/** `read` never changes state. `write` changes state. `destructive` deletes or publishes. */
|
|
4
|
+
type OperationKind = "read" | "write" | "destructive";
|
|
5
|
+
/** The signed-in user of a call. */
|
|
6
|
+
interface OperationUser {
|
|
7
|
+
id: string;
|
|
8
|
+
name?: string;
|
|
9
|
+
email?: string;
|
|
10
|
+
image?: string;
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
}
|
|
13
|
+
/** The Agent Actor when an agent calls through a capability or MCP on behalf of a user. */
|
|
14
|
+
interface OperationActor {
|
|
15
|
+
id: string;
|
|
16
|
+
kind?: string;
|
|
17
|
+
label?: string;
|
|
18
|
+
meta?: object;
|
|
19
|
+
}
|
|
20
|
+
/** The checked Console access of a call. `vite-hub` issues it. `ConsoleAccess` has this shape. */
|
|
21
|
+
interface OperationAccess {
|
|
22
|
+
readonly mode: string;
|
|
23
|
+
/**
|
|
24
|
+
* The sections that the call may use. `"all"` when no section filter applies. An entry is a section id (`"kv"`, every
|
|
25
|
+
* operation of the section) or `"<section>:read"` (only the operations that read).
|
|
26
|
+
*/
|
|
27
|
+
readonly sections: "all" | readonly string[];
|
|
28
|
+
readonly user?: OperationUser;
|
|
29
|
+
}
|
|
30
|
+
interface OperationContext {
|
|
31
|
+
/** The checked Console access of the call. */
|
|
32
|
+
access: OperationAccess;
|
|
33
|
+
/** The signed-in user, or null. */
|
|
34
|
+
user: OperationUser | null;
|
|
35
|
+
/** The Agent Actor when an agent calls on behalf of `user`. */
|
|
36
|
+
actor?: OperationActor;
|
|
37
|
+
surface: "console" | "cli" | "mcp" | "agent";
|
|
38
|
+
/** Set by the host from generated build identity, never from request input or runtime NODE_ENV. */
|
|
39
|
+
development?: boolean;
|
|
40
|
+
env?: Record<string, unknown>;
|
|
41
|
+
waitUntil?: (task: Promise<unknown>) => void;
|
|
42
|
+
request?: Request;
|
|
43
|
+
/** Operations set a success status here, such as 202 for an accepted call. */
|
|
44
|
+
response?: {
|
|
45
|
+
status?: number;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* An agent or an MCP client may pass `lease: "override"` to `content.save`, `content.remove`, and `content.restore`
|
|
49
|
+
* only when the developer allowed it. Defaults to false, so a model cannot take over a document that a person is editing.
|
|
50
|
+
*/
|
|
51
|
+
overrideLeases?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* What an Agent may read of the Channel conversations, set by `operations({ conversations })`. `participant`: only the
|
|
54
|
+
* threads that the Actor takes part in. `all`: every thread. Unset: none.
|
|
55
|
+
*/
|
|
56
|
+
conversations?: "all" | "participant";
|
|
57
|
+
}
|
|
58
|
+
interface OperationDefinition<Input, Output> {
|
|
59
|
+
/** `<section>.<verb>`, such as `content.publish`. Unique per app. */
|
|
60
|
+
name: string;
|
|
61
|
+
/** One sentence. Becomes the CLI help line and the MCP tool description. */
|
|
62
|
+
description: string;
|
|
63
|
+
/**
|
|
64
|
+
* Console section that grants access, such as `content`. `false`: any Console user. A function reads the section
|
|
65
|
+
* from the input, for operations that serve several sections.
|
|
66
|
+
*/
|
|
67
|
+
section: string | false | ((input: Input) => string | undefined);
|
|
68
|
+
/** `read` never changes state. `write` changes state. `destructive` deletes or publishes; the CLI asks for `--yes`, MCP marks `destructiveHint`, agents require approval by default. */
|
|
69
|
+
kind: OperationKind;
|
|
70
|
+
/** Standard Schema (valibot in this repo). Its Standard JSON Schema builds CLI flags and the MCP input schema. */
|
|
71
|
+
input: StandardSchemaV1<unknown, Input>;
|
|
72
|
+
output?: StandardSchemaV1<unknown, Output>;
|
|
73
|
+
cli?: {
|
|
74
|
+
/** Defaults: namespace = section, command = verb. */
|
|
75
|
+
namespace?: string;
|
|
76
|
+
command?: string;
|
|
77
|
+
/** Input keys read from positional arguments, in order. */
|
|
78
|
+
positional?: string[];
|
|
79
|
+
/** Human output, written verbatim. Without it the CLI prints JSON. `--json` always prints JSON. */
|
|
80
|
+
format?: (output: Output) => string;
|
|
81
|
+
/** `vitehub <namespace>` runs this command when no command is named, such as `vitehub usage`. */
|
|
82
|
+
default?: boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Route of the app that takes a signed dispatch of this operation, such as `/_vitehub/schedules/run`. With `--url`
|
|
85
|
+
* and a dispatch key in the environment (`VITEHUB_DISPATCH_KEY`), the command signs the input and posts it there, so
|
|
86
|
+
* a CI job needs no Console credentials. Without a key it calls the RPC.
|
|
87
|
+
*/
|
|
88
|
+
dispatch?: string;
|
|
89
|
+
};
|
|
90
|
+
/** Largest request body in bytes. It can raise the 64 KiB default but not lower it. */
|
|
91
|
+
maxRequestBytes?: number;
|
|
92
|
+
/**
|
|
93
|
+
* Returns true when this call only reads, such as a dry run of a `destructive` operation. The CLI then skips the
|
|
94
|
+
* confirmation, and agents run it without approval. Without it, every call of a `destructive` operation asks.
|
|
95
|
+
*/
|
|
96
|
+
readOnlyWhen?: (input: Input) => boolean;
|
|
97
|
+
/** `false`: MCP does not offer the operation as a tool, such as an editor transport that only the Console uses. */
|
|
98
|
+
mcp?: false;
|
|
99
|
+
/** `false`: the operation never reads `context.user`, so the Console skips the session lookup for it. */
|
|
100
|
+
user?: false;
|
|
101
|
+
/**
|
|
102
|
+
* The operation runs code of the app, such as a workflow, a job, a task, or a schedule. The Console registers it only
|
|
103
|
+
* when `console.invoke` is on, which is the default in development and off in a production build.
|
|
104
|
+
*/
|
|
105
|
+
invoke?: true;
|
|
106
|
+
run: (input: Input, context: OperationContext) => Output | Promise<Output>;
|
|
107
|
+
}
|
|
108
|
+
/** An operation of any input and output, as a registry holds it. */
|
|
109
|
+
interface AnyOperation extends Omit<OperationDefinition<unknown, unknown>, "cli" | "input" | "output" | "readOnlyWhen" | "run" | "section"> {
|
|
110
|
+
readOnlyWhen?: (input: never) => boolean;
|
|
111
|
+
cli?: {
|
|
112
|
+
namespace?: string;
|
|
113
|
+
command?: string;
|
|
114
|
+
default?: boolean;
|
|
115
|
+
dispatch?: string;
|
|
116
|
+
positional?: string[];
|
|
117
|
+
format?: (output: never) => string;
|
|
118
|
+
};
|
|
119
|
+
input: StandardSchemaV1;
|
|
120
|
+
output?: StandardSchemaV1;
|
|
121
|
+
run: (input: never, context: OperationContext) => unknown;
|
|
122
|
+
section: string | false | ((input: never) => string | undefined);
|
|
123
|
+
}
|
|
124
|
+
/** The contribution of one plugin: operations, or a module that exports them. */
|
|
125
|
+
interface OperationContributionEntry {
|
|
126
|
+
/** Module the app imports, such as `@vite-hub/content/operations`. */
|
|
127
|
+
module: string;
|
|
128
|
+
/** Named export that holds an operation or an array of operations. Defaults to `default`. */
|
|
129
|
+
export?: string;
|
|
130
|
+
/** Loads the export in the tool process, for a module that the tool cannot resolve by name. */
|
|
131
|
+
load?: () => Promise<unknown>;
|
|
132
|
+
/** `false`: the app already has these operations at runtime. Only tools such as the CLI and `vitehub inspect` read the entry. */
|
|
133
|
+
runtime?: false;
|
|
134
|
+
}
|
|
135
|
+
//#endregion
|
|
136
|
+
export { OperationContributionEntry as n, AnyOperation as t };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { At as WorkspaceRevision } from "./types-DeK9GIxy.js";
|
|
2
|
+
import { t as AnyOperation } from "./operations-DnOwKsJT.js";
|
|
3
|
+
//#region src/results.d.ts
|
|
4
|
+
/** A retained revision as `workspace.history`, `workspace.refs`, and `workspace.show` report it. */
|
|
5
|
+
interface WorkspaceHistoryRevision extends WorkspaceRevision {
|
|
6
|
+
/** The `author` string from the revision metadata, when it has one. */
|
|
7
|
+
author?: string;
|
|
8
|
+
}
|
|
9
|
+
interface WorkspaceHistoryList {
|
|
10
|
+
workspace: string;
|
|
11
|
+
/** Set when the list reads one ref. Without it, the list merges every ref, newest first. */
|
|
12
|
+
ref?: string;
|
|
13
|
+
revisions: WorkspaceHistoryRevision[];
|
|
14
|
+
/** Pass to the next request with the same ref. */
|
|
15
|
+
cursor?: string;
|
|
16
|
+
/** True when older revisions exist than the ones in this list. */
|
|
17
|
+
more: boolean;
|
|
18
|
+
}
|
|
19
|
+
interface WorkspaceHistoryRefs {
|
|
20
|
+
workspace: string;
|
|
21
|
+
refs: Array<{
|
|
22
|
+
name: string;
|
|
23
|
+
head: WorkspaceHistoryRevision;
|
|
24
|
+
}>;
|
|
25
|
+
}
|
|
26
|
+
interface WorkspaceHistoryFile {
|
|
27
|
+
path: string;
|
|
28
|
+
size?: number;
|
|
29
|
+
mediaType?: string;
|
|
30
|
+
/** SHA-256 of the retained bytes, when the Store reports it. */
|
|
31
|
+
digest?: string;
|
|
32
|
+
}
|
|
33
|
+
interface WorkspaceHistoryContent extends WorkspaceHistoryFile {
|
|
34
|
+
/** `utf8` for valid UTF-8 text. Other bytes use `base64`. */
|
|
35
|
+
encoding: "base64" | "utf8";
|
|
36
|
+
content: string;
|
|
37
|
+
}
|
|
38
|
+
interface WorkspaceHistoryDetails {
|
|
39
|
+
workspace: string;
|
|
40
|
+
revision: WorkspaceHistoryRevision;
|
|
41
|
+
/** The path inside the revision, when the request names one. */
|
|
42
|
+
path?: string;
|
|
43
|
+
/** Files of the revision, or of the directory at `path`. */
|
|
44
|
+
files?: WorkspaceHistoryFile[];
|
|
45
|
+
/** The file at `path`. */
|
|
46
|
+
file?: WorkspaceHistoryContent;
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/operations.d.ts
|
|
50
|
+
/** The `workspace.*` operations: history, refs, and show. The Console, `vitehub workspace`, and agents run them. */
|
|
51
|
+
export declare const workspaceOperations: readonly AnyOperation[];
|
|
52
|
+
//#endregion
|
|
53
|
+
export type { WorkspaceHistoryContent, WorkspaceHistoryDetails, WorkspaceHistoryFile, WorkspaceHistoryList, WorkspaceHistoryRefs, WorkspaceHistoryRevision };
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { n as __exportAll } from "./rolldown-runtime-B4iAMlE-.js";
|
|
2
|
+
import { l as workspacePathError, t as normalizeSafeWorkspacePath } from "./path-DrSIenjj.js";
|
|
3
|
+
import { isAbsolute, relative, resolve, sep } from "node:path";
|
|
4
|
+
import { createHash } from "node:crypto";
|
|
5
|
+
import { minimatch } from "minimatch";
|
|
6
|
+
import { hasRuntimeType } from "@vite-hub/runtime/internal/runtime-type";
|
|
7
|
+
//#region src/core/path.ts
|
|
8
|
+
var path_exports = /* @__PURE__ */ __exportAll({
|
|
9
|
+
contentStreamChunks: () => contentStreamChunks,
|
|
10
|
+
contentStreamToBytes: () => contentStreamToBytes,
|
|
11
|
+
contentToBytes: () => contentToBytes,
|
|
12
|
+
decodeFile: () => decodeFile,
|
|
13
|
+
isExcludedWorkspacePath: () => isExcludedWorkspacePath,
|
|
14
|
+
isWorkspaceBytes: () => isWorkspaceBytes,
|
|
15
|
+
matchesAny: () => matchesAny,
|
|
16
|
+
normalizeSafeWorkspacePath: () => normalizeSafeWorkspacePath,
|
|
17
|
+
normalizeSafeWorkspacePattern: () => normalizeSafeWorkspacePattern,
|
|
18
|
+
normalizeWorkspacePath: () => normalizeWorkspacePath,
|
|
19
|
+
resolveInside: () => resolveInside,
|
|
20
|
+
sha256: () => sha256
|
|
21
|
+
});
|
|
22
|
+
function normalizeWorkspacePath(path = "") {
|
|
23
|
+
return path.replace(/\\/g, "/").replace(/^\/+/, "").replace(/\/+$/, "");
|
|
24
|
+
}
|
|
25
|
+
function isExcludedWorkspacePath(path, excluded = []) {
|
|
26
|
+
const normalized = normalizeWorkspacePath(path);
|
|
27
|
+
return excluded.some((item) => {
|
|
28
|
+
const excludedPath = normalizeWorkspacePath(item);
|
|
29
|
+
return excludedPath === "" || normalized === excludedPath || normalized.startsWith(`${excludedPath}/`);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
function normalizeSafeWorkspacePattern(pattern) {
|
|
33
|
+
return normalizeSafeWorkspacePath(pattern, {
|
|
34
|
+
allowEmpty: true,
|
|
35
|
+
pattern: true
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
function resolveInside(root, path = "") {
|
|
39
|
+
const resolvedRoot = resolve(root);
|
|
40
|
+
const normalized = normalizeSafeWorkspacePath(path, {
|
|
41
|
+
allowEmpty: true,
|
|
42
|
+
allowReserved: true
|
|
43
|
+
});
|
|
44
|
+
const resolved = resolve(resolvedRoot, normalized);
|
|
45
|
+
const rel = relative(resolvedRoot, resolved);
|
|
46
|
+
if (rel === ".." || rel.startsWith(`..${sep}`) || isAbsolute(rel)) throw workspacePathError(path);
|
|
47
|
+
return resolved;
|
|
48
|
+
}
|
|
49
|
+
function matchesAny(path, patterns) {
|
|
50
|
+
if (!patterns) return true;
|
|
51
|
+
const list = Array.isArray(patterns) ? patterns : [patterns];
|
|
52
|
+
const normalizedPath = normalizeWorkspacePath(path);
|
|
53
|
+
return list.some((pattern) => minimatch(normalizedPath, normalizeWorkspacePath(pattern), { dot: true }));
|
|
54
|
+
}
|
|
55
|
+
const typedArrayTag = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(Uint8Array.prototype), Symbol.toStringTag)?.get;
|
|
56
|
+
/** Recognize byte arrays from VM and sandbox realms. */
|
|
57
|
+
function isWorkspaceBytes(value) {
|
|
58
|
+
return ArrayBuffer.isView(value) && typedArrayTag?.call(value) === "Uint8Array";
|
|
59
|
+
}
|
|
60
|
+
function contentToBytes(content) {
|
|
61
|
+
return typeof content === "string" ? new TextEncoder().encode(content) : content;
|
|
62
|
+
}
|
|
63
|
+
function isReadableStream(value) {
|
|
64
|
+
return Boolean(value && typeof value.getReader === "function");
|
|
65
|
+
}
|
|
66
|
+
async function* contentStreamChunks(stream) {
|
|
67
|
+
if (isReadableStream(stream)) {
|
|
68
|
+
const reader = stream.getReader();
|
|
69
|
+
let completed = false;
|
|
70
|
+
try {
|
|
71
|
+
while (true) {
|
|
72
|
+
const chunk = await reader.read();
|
|
73
|
+
if (chunk.done) {
|
|
74
|
+
completed = true;
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
yield chunk.value;
|
|
78
|
+
}
|
|
79
|
+
} finally {
|
|
80
|
+
try {
|
|
81
|
+
if (!completed) await reader.cancel();
|
|
82
|
+
} finally {
|
|
83
|
+
reader.releaseLock();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
yield* stream;
|
|
89
|
+
}
|
|
90
|
+
async function contentStreamToBytes(stream) {
|
|
91
|
+
const chunks = [];
|
|
92
|
+
let size = 0;
|
|
93
|
+
for await (const chunk of contentStreamChunks(stream)) {
|
|
94
|
+
chunks.push(chunk);
|
|
95
|
+
size += chunk.byteLength;
|
|
96
|
+
}
|
|
97
|
+
const bytes = new Uint8Array(size);
|
|
98
|
+
let offset = 0;
|
|
99
|
+
for (const chunk of chunks) {
|
|
100
|
+
bytes.set(chunk, offset);
|
|
101
|
+
offset += chunk.byteLength;
|
|
102
|
+
}
|
|
103
|
+
return bytes;
|
|
104
|
+
}
|
|
105
|
+
function decodeFile(content, options) {
|
|
106
|
+
if (options?.encoding === "binary") return content;
|
|
107
|
+
return typeof content === "string" ? content : new TextDecoder().decode(content);
|
|
108
|
+
}
|
|
109
|
+
async function sha256(input) {
|
|
110
|
+
const bytes = contentToBytes(hasRuntimeType(input, "string") || isWorkspaceBytes(input) ? input : JSON.stringify(input));
|
|
111
|
+
return createHash("sha256").update(bytes).digest("hex");
|
|
112
|
+
}
|
|
113
|
+
//#endregion
|
|
114
|
+
export { isExcludedWorkspacePath as a, normalizeSafeWorkspacePattern as c, resolveInside as d, sha256 as f, decodeFile as i, normalizeWorkspacePath as l, contentStreamToBytes as n, isWorkspaceBytes as o, contentToBytes as r, matchesAny as s, contentStreamChunks as t, path_exports as u };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { ViteHubError, getViteHubErrorShape } from "@vite-hub/runtime";
|
|
2
|
+
//#region src/core/errors.ts
|
|
3
|
+
function workspaceError(message, options) {
|
|
4
|
+
const code = message.startsWith("[vitehub] Workspace file does not exist:") || message.startsWith("[vitehub] Workspace path does not exist:") || message.startsWith("[vitehub] Custom Workspace Source file does not exist:") ? "WORKSPACE_NOT_FOUND" : "WORKSPACE_FAILED";
|
|
5
|
+
return new ViteHubError(code, message, options);
|
|
6
|
+
}
|
|
7
|
+
function workspaceConflict(message, options) {
|
|
8
|
+
return new ViteHubError("WORKSPACE_CONFLICT", message, options);
|
|
9
|
+
}
|
|
10
|
+
function workspaceConflictError(path, expected, actual) {
|
|
11
|
+
return workspaceConflict(`[vitehub] Workspace path changed before the conditional write: ${path}.`, { details: {
|
|
12
|
+
actual,
|
|
13
|
+
expected,
|
|
14
|
+
path
|
|
15
|
+
} });
|
|
16
|
+
}
|
|
17
|
+
function assertWorkspaceDigest(path, expected, actual) {
|
|
18
|
+
if (expected === null ? actual !== void 0 : actual !== expected) throw workspaceConflictError(path, expected, actual);
|
|
19
|
+
}
|
|
20
|
+
function workspaceNotFoundError(name) {
|
|
21
|
+
return new ViteHubError("WORKSPACE_NOT_FOUND", `[vitehub] Workspace "${name}" is not registered.`, { details: { name } });
|
|
22
|
+
}
|
|
23
|
+
function workspacePathError(path) {
|
|
24
|
+
const publicPath = path.slice(0, 4096);
|
|
25
|
+
return new ViteHubError("WORKSPACE_PATH_INVALID", `[vitehub] Workspace path escapes the workspace root: ${JSON.stringify(publicPath)}.`, { details: { path: publicPath } });
|
|
26
|
+
}
|
|
27
|
+
function isWorkspaceError(value) {
|
|
28
|
+
const code = getViteHubErrorShape(value)?.code;
|
|
29
|
+
return code === "WORKSPACE_CONFLICT" || code === "WORKSPACE_FAILED" || code === "WORKSPACE_NOT_FOUND" || code === "WORKSPACE_PATH_INVALID";
|
|
30
|
+
}
|
|
31
|
+
function isWorkspaceConflict(value) {
|
|
32
|
+
return getViteHubErrorShape(value)?.code === "WORKSPACE_CONFLICT";
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/internal/path.ts
|
|
36
|
+
function classifyWindowsComponent(part) {
|
|
37
|
+
const withoutStream = part.toLowerCase().split(":", 1)[0];
|
|
38
|
+
return {
|
|
39
|
+
normalized: withoutStream.replace(/[ .]+$/, ""),
|
|
40
|
+
isTraversal: /^(?:\.(?: +[. ]*)?|\.\.(?: +[. ]*)?)$/.test(withoutStream)
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function normalizeSafeWorkspacePath(path = "", options = {}) {
|
|
44
|
+
const raw = path.replace(/\\/g, "/");
|
|
45
|
+
const normalized = raw.replace(/^\/+/, "").replace(/\/+$/, "");
|
|
46
|
+
const parts = normalized.split("/").filter(Boolean);
|
|
47
|
+
if (!options.allowEmpty && !normalized) throw workspacePathError(path);
|
|
48
|
+
if (raw.startsWith("/") || /^[a-z]:/i.test(raw) || raw.includes("\0")) throw workspacePathError(path);
|
|
49
|
+
if (parts.some((part, index) => {
|
|
50
|
+
const name = part.toLowerCase();
|
|
51
|
+
const classification = classifyWindowsComponent(part);
|
|
52
|
+
const reserved = classification.normalized === ".git" || /^git~\d+$/.test(classification.normalized) || index === 0 && classification.normalized === ".vitehub" || index === 0 && /^vitehu~\d+$/.test(classification.normalized);
|
|
53
|
+
const canonical = (classification.normalized === ".git" || index === 0 && classification.normalized === ".vitehub") && name === classification.normalized;
|
|
54
|
+
return classification.isTraversal || reserved && (!options.allowReserved || !canonical);
|
|
55
|
+
})) throw workspacePathError(path);
|
|
56
|
+
return normalized;
|
|
57
|
+
}
|
|
58
|
+
//#endregion
|
|
59
|
+
export { workspaceConflict as a, workspaceNotFoundError as c, isWorkspaceError as i, workspacePathError as l, assertWorkspaceDigest as n, workspaceConflictError as o, isWorkspaceConflict as r, workspaceError as s, normalizeSafeWorkspacePath as t };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/internal/path.d.ts
|
|
2
|
+
interface SafeWorkspacePathOptions {
|
|
3
|
+
allowEmpty?: boolean;
|
|
4
|
+
allowReserved?: boolean;
|
|
5
|
+
pattern?: boolean;
|
|
6
|
+
}
|
|
7
|
+
declare function normalizeSafeWorkspacePath(path?: string, options?: SafeWorkspacePathOptions): string;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { normalizeSafeWorkspacePath as n, SafeWorkspacePathOptions as t };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Tt as WorkspacePlugin } from "./types-DeK9GIxy.js";
|
|
2
|
+
//#region src/core/plugins.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Add a plugin's rules and hooks to a Workspace by name, including discovered Workspaces the caller does not define.
|
|
5
|
+
* Registering the same plugin id again replaces the earlier registration. A plugin declared by the Workspace Definition
|
|
6
|
+
* with the same id wins. The returned function removes this registration.
|
|
7
|
+
*/
|
|
8
|
+
declare function registerWorkspacePlugin(workspace: string, plugin: WorkspacePlugin): () => void;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { registerWorkspacePlugin as t };
|