@vite-hub/workspace 0.0.0 → 0.0.2
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 +262 -1
- package/dist/ai-Cztw4eLk.js +472 -0
- package/dist/ai-hFdsvDHC.d.ts +162 -0
- package/dist/ai.d.ts +3 -0
- package/dist/ai.js +2 -0
- package/dist/artifacts-store-BAV9jZpd.js +555 -0
- package/dist/asset-registry-CaG9b7tf.js +19 -0
- package/dist/chunk-8H4AJuhK.js +14 -0
- package/dist/cli.d.ts +31 -0
- package/dist/cli.js +303 -0
- package/dist/cloudflare-env-CKxUs2fa.js +20 -0
- package/dist/cloudflare.d.ts +16 -0
- package/dist/cloudflare.js +3 -0
- package/dist/collections/client.d.ts +39 -0
- package/dist/collections/client.js +137 -0
- package/dist/collections.d.ts +59 -0
- package/dist/collections.js +159 -0
- package/dist/config--r5unwPc.js +7811 -0
- package/dist/config-Ca5DM8fF.d.ts +28 -0
- package/dist/config-DCQ6y30R.js +30 -0
- package/dist/file-B2q9NE18.js +24 -0
- package/dist/files-xy0le-_U.js +51 -0
- package/dist/github-lIO6-2sH.js +194 -0
- package/dist/glob-DeH0dzZX.js +23 -0
- package/dist/host-I-_vDs05.js +370 -0
- package/dist/hosted-vercel-blob.d.ts +15 -0
- package/dist/hosted-vercel-blob.js +26 -0
- package/dist/hosted.d.ts +18 -0
- package/dist/hosted.js +30 -0
- package/dist/index.d.ts +185 -0
- package/dist/index.js +541 -0
- package/dist/lifecycle-Lhk3dAMt.js +176 -0
- package/dist/loader.d.ts +17 -0
- package/dist/loader.js +22 -0
- package/dist/nitro.d.ts +2 -0
- package/dist/nitro.js +2 -0
- package/dist/nuxt.d.ts +26 -0
- package/dist/nuxt.js +36 -0
- package/dist/path-CNI6wKIU.js +115 -0
- package/dist/provider-CeQciesl.js +599 -0
- package/dist/providers/cloudflare/artifacts-store.d.ts +6 -0
- package/dist/providers/cloudflare/artifacts-store.js +2 -0
- package/dist/providers/github/store.d.ts +6 -0
- package/dist/providers/github/store.js +362 -0
- package/dist/providers/vercel/blob-store.d.ts +6 -0
- package/dist/providers/vercel/blob-store.js +235 -0
- package/dist/publish.d.ts +35 -0
- package/dist/publish.js +112 -0
- package/dist/registry-C7DMdBXN.js +74 -0
- package/dist/registry-CoC9JxVt.d.ts +11 -0
- package/dist/request-execution-C8qRcReq.js +80 -0
- package/dist/runtime/assets.d.ts +12 -0
- package/dist/runtime/assets.js +138 -0
- package/dist/runtime/empty-assets-registry.d.ts +6 -0
- package/dist/runtime/empty-assets-registry.js +4 -0
- package/dist/runtime/empty-registry.d.ts +6 -0
- package/dist/runtime/empty-registry.js +4 -0
- package/dist/runtime/state.d.ts +4 -0
- package/dist/runtime/state.js +15 -0
- package/dist/runtime/workspace.d.ts +2 -0
- package/dist/runtime/workspace.js +2 -0
- package/dist/runtime.d.ts +38 -0
- package/dist/runtime.js +643 -0
- package/dist/search-C4REyHj9.js +39 -0
- package/dist/server.d.ts +65 -0
- package/dist/server.js +355 -0
- package/dist/shared-BRycRSbo.js +255 -0
- package/dist/source-metadata.d.ts +2 -0
- package/dist/source-metadata.js +2 -0
- package/dist/state-DSAHEsq6.d.ts +25 -0
- package/dist/sync-DO42ypji.js +269 -0
- package/dist/target-D4Bqb1eH.js +11 -0
- package/dist/test.d.ts +2 -0
- package/dist/test.js +2 -0
- package/dist/types-DHkae7Cb.d.ts +628 -0
- package/dist/use-D16tf8Ph.d.ts +86 -0
- package/dist/use-d_PlAdOu.js +353 -0
- package/dist/utils-BPdaCyI6.js +55 -0
- package/dist/vite-NWC9mFjI.js +1882 -0
- package/dist/vite.d.ts +50 -0
- package/dist/vite.js +2 -0
- package/dist/workspace-f2DBLmPZ.d.ts +6 -0
- package/dist/workspace-n4wBmdaM.js +1476 -0
- package/package.json +197 -5
package/dist/cli.js
ADDED
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import { readWorkspaceDevToken, workspaceDevHeader, workspaceDevRoute, workspaceDevTokenHeader } from "./server.js";
|
|
2
|
+
//#region src/cli.ts
|
|
3
|
+
const workspaceCommandFeedbackIntervalMs = 15e3;
|
|
4
|
+
const workspaceCommandStartedMessage = "[workspace] command started; first run may materialize sources.\n";
|
|
5
|
+
const workspaceCommandWaitingMessage = "[workspace] command still running; sources may still be materializing.\n";
|
|
6
|
+
function startWorkspaceCommandFeedback(context) {
|
|
7
|
+
context.stderr.write(workspaceCommandStartedMessage);
|
|
8
|
+
const timer = setInterval(() => context.stderr.write(workspaceCommandWaitingMessage), workspaceCommandFeedbackIntervalMs);
|
|
9
|
+
timer.unref?.();
|
|
10
|
+
return () => clearInterval(timer);
|
|
11
|
+
}
|
|
12
|
+
function formatDurationMs(durationMs) {
|
|
13
|
+
return durationMs < 1e3 ? `${durationMs}ms` : `${(durationMs / 1e3).toFixed(1)}s`;
|
|
14
|
+
}
|
|
15
|
+
function workspaceDevDataNumber(event, key) {
|
|
16
|
+
const value = event.data?.[key];
|
|
17
|
+
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
18
|
+
}
|
|
19
|
+
function writeWorkspaceDevProgress(context, event) {
|
|
20
|
+
const duration = typeof event.durationMs === "number" ? ` (${formatDurationMs(event.durationMs)})` : "";
|
|
21
|
+
if (event.status === "started") {
|
|
22
|
+
context.stderr.write(`[workspace] ${event.label}...\n`);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (event.status === "updating") {
|
|
26
|
+
const files = workspaceDevDataNumber(event, "files");
|
|
27
|
+
const bytes = workspaceDevDataNumber(event, "bytes");
|
|
28
|
+
const detail = files === void 0 ? "" : `: ${files} file${files === 1 ? "" : "s"}${bytes === void 0 ? "" : `, ${bytes} bytes`}`;
|
|
29
|
+
context.stderr.write(`[workspace] ${event.label}${detail}\n`);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (event.status === "failed") {
|
|
33
|
+
context.stderr.write(`[workspace] ${event.label} failed${duration}${event.error ? `: ${event.error}` : ""}\n`);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
context.stderr.write(`[workspace] ${event.label} completed${duration}\n`);
|
|
37
|
+
}
|
|
38
|
+
function isWorkspaceDevStream(response) {
|
|
39
|
+
return response.headers.get("content-type")?.toLowerCase().includes("application/x-ndjson") === true;
|
|
40
|
+
}
|
|
41
|
+
function handleWorkspaceDevStreamLine(line, context) {
|
|
42
|
+
const parsed = JSON.parse(line);
|
|
43
|
+
if (parsed.type === "progress" && parsed.event) {
|
|
44
|
+
writeWorkspaceDevProgress(context, parsed.event);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (parsed.type === "error") {
|
|
48
|
+
context.stderr.write(`${parsed.error || "Workspace Dev command failed."}\n`);
|
|
49
|
+
return {
|
|
50
|
+
exitCode: 1,
|
|
51
|
+
stderr: "",
|
|
52
|
+
stdout: ""
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
if (parsed.type === "result") return parsed.result || {};
|
|
56
|
+
}
|
|
57
|
+
async function readWorkspaceDevStream(response, context) {
|
|
58
|
+
const reader = response.body?.getReader();
|
|
59
|
+
if (!reader) return {};
|
|
60
|
+
const decoder = new TextDecoder();
|
|
61
|
+
let buffer = "";
|
|
62
|
+
let result;
|
|
63
|
+
for (;;) {
|
|
64
|
+
const { done, value } = await reader.read();
|
|
65
|
+
buffer += decoder.decode(value, { stream: !done });
|
|
66
|
+
let newline = buffer.indexOf("\n");
|
|
67
|
+
while (newline >= 0) {
|
|
68
|
+
const line = buffer.slice(0, newline).trim();
|
|
69
|
+
buffer = buffer.slice(newline + 1);
|
|
70
|
+
if (line) result = handleWorkspaceDevStreamLine(line, context) ?? result;
|
|
71
|
+
newline = buffer.indexOf("\n");
|
|
72
|
+
}
|
|
73
|
+
if (done) break;
|
|
74
|
+
}
|
|
75
|
+
const line = buffer.trim();
|
|
76
|
+
if (line) result = handleWorkspaceDevStreamLine(line, context) ?? result;
|
|
77
|
+
return result || {};
|
|
78
|
+
}
|
|
79
|
+
function writeWorkspaceDevUsage(context) {
|
|
80
|
+
context.stdout.write([
|
|
81
|
+
"Usage: vitehub workspace dev <workspace> [exec <command...>] [--url <url>] [--timeout <ms>]",
|
|
82
|
+
"",
|
|
83
|
+
"Run Workspace commands through a running Vite Development Server.",
|
|
84
|
+
"Omit exec to open the interactive command loop.",
|
|
85
|
+
"",
|
|
86
|
+
"Options:",
|
|
87
|
+
" --url <url> Compatible Vite Development Server URL. Defaults to http://localhost:5173.",
|
|
88
|
+
" --timeout <ms> Workspace command timeout.",
|
|
89
|
+
" --path <path> Workspace path to materialize for command sessions. Repeatable.",
|
|
90
|
+
" -h, --help Show this help.",
|
|
91
|
+
""
|
|
92
|
+
].join("\n"));
|
|
93
|
+
}
|
|
94
|
+
function readOptionValue(args, index, flag) {
|
|
95
|
+
const value = args[index + 1];
|
|
96
|
+
if (!value || value.startsWith("-")) throw new Error(`Missing value for ${flag}.`);
|
|
97
|
+
return value;
|
|
98
|
+
}
|
|
99
|
+
function parseWorkspaceDevArgs(args, env) {
|
|
100
|
+
const parsed = {
|
|
101
|
+
help: false,
|
|
102
|
+
url: env.VITEHUB_DEV_SERVER_URL || "http://localhost:5173"
|
|
103
|
+
};
|
|
104
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
105
|
+
const arg = args[index];
|
|
106
|
+
if (arg === "-h" || arg === "--help") {
|
|
107
|
+
parsed.help = true;
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
if (arg === "--url" || arg === "--server") {
|
|
111
|
+
parsed.url = readOptionValue(args, index, arg);
|
|
112
|
+
index += 1;
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (arg.startsWith("--url=")) {
|
|
116
|
+
parsed.url = arg.slice(6);
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
if (arg === "--timeout") {
|
|
120
|
+
const timeout = Number.parseInt(readOptionValue(args, index, arg), 10);
|
|
121
|
+
if (!Number.isFinite(timeout) || timeout <= 0) throw new Error("--timeout must be a positive number.");
|
|
122
|
+
parsed.timeout = timeout;
|
|
123
|
+
index += 1;
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
if (arg.startsWith("--timeout=")) {
|
|
127
|
+
const timeout = Number.parseInt(arg.slice(10), 10);
|
|
128
|
+
if (!Number.isFinite(timeout) || timeout <= 0) throw new Error("--timeout must be a positive number.");
|
|
129
|
+
parsed.timeout = timeout;
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (arg === "--path") {
|
|
133
|
+
parsed.paths ??= [];
|
|
134
|
+
parsed.paths.push(readOptionValue(args, index, arg));
|
|
135
|
+
index += 1;
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
if (arg.startsWith("--path=")) {
|
|
139
|
+
parsed.paths ??= [];
|
|
140
|
+
parsed.paths.push(arg.slice(7));
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
if (arg.startsWith("-") && !parsed.workspace) throw new Error(`Unknown option: ${arg}.`);
|
|
144
|
+
if (!parsed.workspace) {
|
|
145
|
+
parsed.workspace = arg;
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
if (arg === "exec") {
|
|
149
|
+
const [command, ...commandArgs] = args.slice(index + 1);
|
|
150
|
+
if (!command?.trim()) throw new Error("workspace dev exec requires a command.");
|
|
151
|
+
parsed.command = command;
|
|
152
|
+
if (commandArgs.length) parsed.args = commandArgs;
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
throw new Error(`Unexpected argument: ${arg}. Use exec <command...> for one-shot commands.`);
|
|
156
|
+
}
|
|
157
|
+
return parsed;
|
|
158
|
+
}
|
|
159
|
+
function endpointUrl(baseUrl) {
|
|
160
|
+
return new URL(workspaceDevRoute, baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`).href;
|
|
161
|
+
}
|
|
162
|
+
async function readWorkspaceDiscovery(parsed, context, fetchImpl) {
|
|
163
|
+
if (!parsed.workspace) {
|
|
164
|
+
context.stderr.write("Missing Workspace Dev target.\n");
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
let url;
|
|
168
|
+
try {
|
|
169
|
+
url = endpointUrl(parsed.url);
|
|
170
|
+
} catch {
|
|
171
|
+
context.stderr.write(`Invalid Vite Development Server URL: ${parsed.url}\n`);
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
let response;
|
|
175
|
+
try {
|
|
176
|
+
response = await fetchImpl(url, { headers: {
|
|
177
|
+
accept: "application/json",
|
|
178
|
+
[workspaceDevHeader]: "1"
|
|
179
|
+
} });
|
|
180
|
+
} catch {
|
|
181
|
+
context.stderr.write(`No Compatible Vite Development Server found at ${parsed.url}.\n`);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
if (!response.ok) {
|
|
185
|
+
context.stderr.write(`No Compatible Vite Development Server found at ${parsed.url}.\n`);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
const discovery = await response.json().catch(() => ({}));
|
|
189
|
+
if (typeof discovery.root === "string" && discovery.root !== context.rootDir) {
|
|
190
|
+
context.stderr.write(`Compatible Vite Development Server root mismatch: ${discovery.root}\n`);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
if (!(discovery.workspaces || []).flatMap((workspace) => typeof workspace.name === "string" ? [workspace.name] : []).includes(parsed.workspace)) {
|
|
194
|
+
context.stderr.write(`Unknown Workspace Dev target: ${parsed.workspace}\n`);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
return {
|
|
198
|
+
tokenOptions: typeof discovery.workspaceDevTokenServerId === "string" ? { serverId: discovery.workspaceDevTokenServerId } : {},
|
|
199
|
+
url
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
async function sendWorkspaceCommand(target, parsed, context, fetchImpl) {
|
|
203
|
+
if (!parsed.command) {
|
|
204
|
+
context.stderr.write("Pass a command or run in an interactive terminal.\n");
|
|
205
|
+
return 1;
|
|
206
|
+
}
|
|
207
|
+
const token = await readWorkspaceDevToken(context.rootDir, target.tokenOptions);
|
|
208
|
+
if (!token) {
|
|
209
|
+
context.stderr.write("No private Workspace Dev token found. Start the Compatible Vite Development Server first.\n");
|
|
210
|
+
return 1;
|
|
211
|
+
}
|
|
212
|
+
const startedAt = Date.now();
|
|
213
|
+
const stopFeedback = startWorkspaceCommandFeedback(context);
|
|
214
|
+
try {
|
|
215
|
+
const response = await fetchImpl(target.url, {
|
|
216
|
+
body: JSON.stringify({ workspaceCommand: {
|
|
217
|
+
...parsed.args ? { args: parsed.args } : {},
|
|
218
|
+
command: parsed.command,
|
|
219
|
+
...parsed.paths?.length ? { paths: parsed.paths } : {},
|
|
220
|
+
...parsed.timeout ? { timeout: parsed.timeout } : {},
|
|
221
|
+
workspace: parsed.workspace
|
|
222
|
+
} }),
|
|
223
|
+
headers: {
|
|
224
|
+
accept: "application/x-ndjson, application/json",
|
|
225
|
+
"content-type": "application/json",
|
|
226
|
+
[workspaceDevHeader]: "1",
|
|
227
|
+
[workspaceDevTokenHeader]: token
|
|
228
|
+
},
|
|
229
|
+
method: "POST"
|
|
230
|
+
});
|
|
231
|
+
if (!response.ok) {
|
|
232
|
+
context.stderr.write(`${await response.text()}\n`);
|
|
233
|
+
return 1;
|
|
234
|
+
}
|
|
235
|
+
if (isWorkspaceDevStream(response)) stopFeedback();
|
|
236
|
+
const result = isWorkspaceDevStream(response) ? await readWorkspaceDevStream(response, context) : await response.json().catch(() => ({}));
|
|
237
|
+
if (typeof result.stdout === "string") context.stdout.write(result.stdout);
|
|
238
|
+
if (typeof result.stderr === "string" && result.stderr) context.stderr.write(result.stderr);
|
|
239
|
+
context.stderr.write(`[workspace] command completed (${formatDurationMs(Date.now() - startedAt)})\n`);
|
|
240
|
+
return typeof result.exitCode === "number" ? result.exitCode : 0;
|
|
241
|
+
} finally {
|
|
242
|
+
stopFeedback();
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
async function runInteractiveWorkspaceDev(parsed, context, fetchImpl, target) {
|
|
246
|
+
const { createInterface } = await import("node:readline/promises");
|
|
247
|
+
const readline = createInterface({
|
|
248
|
+
input: process.stdin,
|
|
249
|
+
output: process.stdout
|
|
250
|
+
});
|
|
251
|
+
context.stdout.write(`Connected to ${parsed.workspace} at ${parsed.url}\n`);
|
|
252
|
+
try {
|
|
253
|
+
for (;;) {
|
|
254
|
+
const command = (await readline.question("> ")).trim();
|
|
255
|
+
if (!command) continue;
|
|
256
|
+
if (command === ".exit" || command === "exit") return 0;
|
|
257
|
+
const exitCode = await sendWorkspaceCommand(target, {
|
|
258
|
+
...parsed,
|
|
259
|
+
command
|
|
260
|
+
}, context, fetchImpl);
|
|
261
|
+
if (exitCode !== 0) return exitCode;
|
|
262
|
+
}
|
|
263
|
+
} finally {
|
|
264
|
+
readline.close();
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
async function runWorkspaceDevCli(args, context, options = {}) {
|
|
268
|
+
let parsed;
|
|
269
|
+
try {
|
|
270
|
+
parsed = parseWorkspaceDevArgs(args, context.env);
|
|
271
|
+
} catch (error) {
|
|
272
|
+
context.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
|
|
273
|
+
writeWorkspaceDevUsage(context);
|
|
274
|
+
return 1;
|
|
275
|
+
}
|
|
276
|
+
if (parsed.help) {
|
|
277
|
+
writeWorkspaceDevUsage(context);
|
|
278
|
+
return 0;
|
|
279
|
+
}
|
|
280
|
+
const fetchImpl = options.fetch || globalThis.fetch;
|
|
281
|
+
const target = await readWorkspaceDiscovery(parsed, context, fetchImpl);
|
|
282
|
+
if (!target) return 1;
|
|
283
|
+
if (parsed.command) return await sendWorkspaceCommand(target, parsed, context, fetchImpl);
|
|
284
|
+
if (!process.stdin.isTTY) {
|
|
285
|
+
context.stderr.write("Pass a command or run in an interactive terminal.\n");
|
|
286
|
+
return 1;
|
|
287
|
+
}
|
|
288
|
+
return await runInteractiveWorkspaceDev(parsed, context, fetchImpl, target);
|
|
289
|
+
}
|
|
290
|
+
function createWorkspaceCliContributor() {
|
|
291
|
+
return { namespaces: [{
|
|
292
|
+
description: "Workspace development workflows.",
|
|
293
|
+
features: [{
|
|
294
|
+
description: "Run commands through a Workspace Session.",
|
|
295
|
+
name: "dev",
|
|
296
|
+
run: async (args, context) => await runWorkspaceDevCli(args, context),
|
|
297
|
+
usage: "vitehub workspace dev <workspace> [exec <command...>]"
|
|
298
|
+
}],
|
|
299
|
+
name: "workspace"
|
|
300
|
+
}] };
|
|
301
|
+
}
|
|
302
|
+
//#endregion
|
|
303
|
+
export { createWorkspaceCliContributor, runWorkspaceDevCli };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
//#region ../internal/src/runtime/cloudflare-env.ts
|
|
3
|
+
let activeEnv;
|
|
4
|
+
const activeEnvStorage = new AsyncLocalStorage();
|
|
5
|
+
function setActiveCloudflareEnv(env) {
|
|
6
|
+
activeEnv = env;
|
|
7
|
+
globalThis.__env__ = env;
|
|
8
|
+
try {
|
|
9
|
+
activeEnvStorage.enterWith({ env });
|
|
10
|
+
} catch {}
|
|
11
|
+
}
|
|
12
|
+
function getActiveCloudflareEnv() {
|
|
13
|
+
const scoped = activeEnvStorage.getStore();
|
|
14
|
+
return scoped ? scoped.env : activeEnv ?? globalThis.__env__;
|
|
15
|
+
}
|
|
16
|
+
function getActiveCloudflareBinding(name) {
|
|
17
|
+
return getActiveCloudflareEnv()?.[name];
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
export { setActiveCloudflareEnv as n, getActiveCloudflareBinding as t };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { o as GitHubWorkspaceStoreOptions, t as CloudflareArtifactsWorkspaceStoreOptions, v as ResolvedWorkspaceModuleOptions } from "./types-DHkae7Cb.js";
|
|
2
|
+
import { configureHostedWorkspaceRuntime } from "./hosted.js";
|
|
3
|
+
import { createCloudflareArtifactsWorkspaceStore } from "./providers/cloudflare/artifacts-store.js";
|
|
4
|
+
|
|
5
|
+
//#region src/cloudflare.d.ts
|
|
6
|
+
type CloudflareWorkspaceRuntimeStoreOptions = Partial<CloudflareArtifactsWorkspaceStoreOptions> | (Partial<GitHubWorkspaceStoreOptions> & {
|
|
7
|
+
provider: "github";
|
|
8
|
+
});
|
|
9
|
+
interface CloudflareWorkspaceRuntimeOptions {
|
|
10
|
+
assets?: boolean | string[];
|
|
11
|
+
env?: Record<string, string | undefined>;
|
|
12
|
+
root?: string;
|
|
13
|
+
store?: CloudflareWorkspaceRuntimeStoreOptions;
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
export { type CloudflareArtifactsWorkspaceStoreOptions, CloudflareWorkspaceRuntimeOptions, CloudflareWorkspaceRuntimeStoreOptions, type GitHubWorkspaceStoreOptions, type ResolvedWorkspaceModuleOptions, configureHostedWorkspaceRuntime as configureCloudflareWorkspaceRuntime, createCloudflareArtifactsWorkspaceStore };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { t as createCloudflareArtifactsWorkspaceStore } from "./artifacts-store-BAV9jZpd.js";
|
|
2
|
+
import { configureHostedWorkspaceRuntime } from "./hosted.js";
|
|
3
|
+
export { configureHostedWorkspaceRuntime as configureCloudflareWorkspaceRuntime, createCloudflareArtifactsWorkspaceStore };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { WorkspaceCollectionItem, WorkspaceCollectionPage } from "../collections.js";
|
|
2
|
+
import { ComputedRef, MaybeRefOrGetter, Ref } from "vue";
|
|
3
|
+
|
|
4
|
+
//#region src/collections/client.d.ts
|
|
5
|
+
interface WorkspaceCollectionRequestOptions {
|
|
6
|
+
query?: Record<string, unknown>;
|
|
7
|
+
signal: AbortSignal;
|
|
8
|
+
}
|
|
9
|
+
type WorkspaceCollectionRequester = <T>(endpoint: string, options: WorkspaceCollectionRequestOptions) => Promise<T>;
|
|
10
|
+
interface UseWorkspaceCollectionOptions {
|
|
11
|
+
immediate?: boolean;
|
|
12
|
+
limit?: number;
|
|
13
|
+
query?: MaybeRefOrGetter<Record<string, unknown>>;
|
|
14
|
+
request?: WorkspaceCollectionRequester;
|
|
15
|
+
}
|
|
16
|
+
interface UseWorkspaceCollectionReturn<T> {
|
|
17
|
+
error: Ref<unknown>;
|
|
18
|
+
facets: Ref<WorkspaceCollectionPage<T>["facets"]>;
|
|
19
|
+
hasMore: ComputedRef<boolean>;
|
|
20
|
+
items: Ref<T[]>;
|
|
21
|
+
loadMore: () => Promise<WorkspaceCollectionPage<T> | undefined>;
|
|
22
|
+
pending: Ref<boolean>;
|
|
23
|
+
refresh: () => Promise<WorkspaceCollectionPage<T> | undefined>;
|
|
24
|
+
total: Ref<number>;
|
|
25
|
+
}
|
|
26
|
+
interface UseWorkspaceCollectionItemOptions {
|
|
27
|
+
immediate?: boolean;
|
|
28
|
+
request?: WorkspaceCollectionRequester;
|
|
29
|
+
}
|
|
30
|
+
interface UseWorkspaceCollectionItemReturn<T> {
|
|
31
|
+
data: Ref<T | null>;
|
|
32
|
+
error: Ref<unknown>;
|
|
33
|
+
pending: Ref<boolean>;
|
|
34
|
+
refresh: () => Promise<WorkspaceCollectionItem<T> | undefined>;
|
|
35
|
+
}
|
|
36
|
+
declare function useWorkspaceCollection<T = Record<string, unknown>>(endpoint: string, options?: UseWorkspaceCollectionOptions): UseWorkspaceCollectionReturn<T>;
|
|
37
|
+
declare function useWorkspaceCollectionItem<T = Record<string, unknown>>(endpoint: string, value: MaybeRefOrGetter<string | undefined>, options?: UseWorkspaceCollectionItemOptions): UseWorkspaceCollectionItemReturn<T>;
|
|
38
|
+
//#endregion
|
|
39
|
+
export { UseWorkspaceCollectionItemOptions, UseWorkspaceCollectionItemReturn, UseWorkspaceCollectionOptions, UseWorkspaceCollectionReturn, WorkspaceCollectionRequestOptions, WorkspaceCollectionRequester, useWorkspaceCollection, useWorkspaceCollectionItem };
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { $fetch } from "ofetch";
|
|
2
|
+
import { computed, onScopeDispose, ref, toValue, watch } from "vue";
|
|
3
|
+
//#region src/collections/client.ts
|
|
4
|
+
const defaultRequester = async (endpoint, options) => {
|
|
5
|
+
return await $fetch(endpoint, options);
|
|
6
|
+
};
|
|
7
|
+
function isAbortError(error) {
|
|
8
|
+
return Boolean(error && typeof error === "object" && "name" in error && error.name === "AbortError");
|
|
9
|
+
}
|
|
10
|
+
function isStaleCursorError(error) {
|
|
11
|
+
if (!error || typeof error !== "object") return false;
|
|
12
|
+
return ("statusCode" in error ? error.statusCode : "status" in error ? error.status : void 0) === 409;
|
|
13
|
+
}
|
|
14
|
+
function useWorkspaceCollection(endpoint, options = {}) {
|
|
15
|
+
const items = ref([]);
|
|
16
|
+
const facets = ref({});
|
|
17
|
+
const total = ref(0);
|
|
18
|
+
const nextCursor = ref(null);
|
|
19
|
+
const pending = ref(false);
|
|
20
|
+
const error = ref(null);
|
|
21
|
+
const request = options.request || defaultRequester;
|
|
22
|
+
let active;
|
|
23
|
+
let loaded = false;
|
|
24
|
+
async function load(reset) {
|
|
25
|
+
if (!reset && (pending.value || loaded && !nextCursor.value)) return;
|
|
26
|
+
active?.abort();
|
|
27
|
+
const controller = new AbortController();
|
|
28
|
+
active = controller;
|
|
29
|
+
pending.value = true;
|
|
30
|
+
error.value = null;
|
|
31
|
+
try {
|
|
32
|
+
const response = await request(endpoint, {
|
|
33
|
+
query: {
|
|
34
|
+
...options.query ? toValue(options.query) : {},
|
|
35
|
+
cursor: reset ? void 0 : nextCursor.value || void 0,
|
|
36
|
+
limit: options.limit
|
|
37
|
+
},
|
|
38
|
+
signal: controller.signal
|
|
39
|
+
});
|
|
40
|
+
if (active !== controller) return;
|
|
41
|
+
items.value = reset ? response.items : [...items.value, ...response.items];
|
|
42
|
+
facets.value = response.facets;
|
|
43
|
+
total.value = response.total;
|
|
44
|
+
nextCursor.value = response.nextCursor;
|
|
45
|
+
loaded = true;
|
|
46
|
+
return response;
|
|
47
|
+
} catch (cause) {
|
|
48
|
+
if (active !== controller || isAbortError(cause)) return;
|
|
49
|
+
if (!reset && isStaleCursorError(cause)) return await load(true);
|
|
50
|
+
error.value = cause;
|
|
51
|
+
} finally {
|
|
52
|
+
if (active === controller) {
|
|
53
|
+
active = void 0;
|
|
54
|
+
pending.value = false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const stop = watch(() => options.query ? toValue(options.query) : void 0, () => {
|
|
59
|
+
load(true);
|
|
60
|
+
}, {
|
|
61
|
+
deep: true,
|
|
62
|
+
immediate: options.immediate !== false && (options.request !== void 0 || "window" in globalThis)
|
|
63
|
+
});
|
|
64
|
+
onScopeDispose(() => {
|
|
65
|
+
stop();
|
|
66
|
+
active?.abort();
|
|
67
|
+
active = void 0;
|
|
68
|
+
pending.value = false;
|
|
69
|
+
});
|
|
70
|
+
return {
|
|
71
|
+
error,
|
|
72
|
+
facets,
|
|
73
|
+
hasMore: computed(() => Boolean(nextCursor.value)),
|
|
74
|
+
items,
|
|
75
|
+
loadMore: () => load(false),
|
|
76
|
+
pending,
|
|
77
|
+
refresh: () => load(true),
|
|
78
|
+
total
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function useWorkspaceCollectionItem(endpoint, value, options = {}) {
|
|
82
|
+
const data = ref(null);
|
|
83
|
+
const pending = ref(false);
|
|
84
|
+
const error = ref(null);
|
|
85
|
+
const request = options.request || defaultRequester;
|
|
86
|
+
let active;
|
|
87
|
+
async function refresh() {
|
|
88
|
+
const resolvedValue = toValue(value);
|
|
89
|
+
if (resolvedValue === void 0) {
|
|
90
|
+
active?.abort();
|
|
91
|
+
active = void 0;
|
|
92
|
+
data.value = null;
|
|
93
|
+
error.value = null;
|
|
94
|
+
pending.value = false;
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
active?.abort();
|
|
98
|
+
const controller = new AbortController();
|
|
99
|
+
active = controller;
|
|
100
|
+
pending.value = true;
|
|
101
|
+
error.value = null;
|
|
102
|
+
try {
|
|
103
|
+
const response = await request(endpoint, {
|
|
104
|
+
query: { value: resolvedValue },
|
|
105
|
+
signal: controller.signal
|
|
106
|
+
});
|
|
107
|
+
if (active !== controller) return;
|
|
108
|
+
data.value = response.item;
|
|
109
|
+
return response;
|
|
110
|
+
} catch (cause) {
|
|
111
|
+
if (active !== controller || isAbortError(cause)) return;
|
|
112
|
+
error.value = cause;
|
|
113
|
+
} finally {
|
|
114
|
+
if (active === controller) {
|
|
115
|
+
active = void 0;
|
|
116
|
+
pending.value = false;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
const stop = watch(() => toValue(value), () => {
|
|
121
|
+
refresh();
|
|
122
|
+
}, { immediate: options.immediate !== false && (options.request !== void 0 || "window" in globalThis) });
|
|
123
|
+
onScopeDispose(() => {
|
|
124
|
+
stop();
|
|
125
|
+
active?.abort();
|
|
126
|
+
active = void 0;
|
|
127
|
+
pending.value = false;
|
|
128
|
+
});
|
|
129
|
+
return {
|
|
130
|
+
data,
|
|
131
|
+
error,
|
|
132
|
+
pending,
|
|
133
|
+
refresh
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
//#endregion
|
|
137
|
+
export { useWorkspaceCollection, useWorkspaceCollectionItem };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { ot as WorkspaceName } from "./types-DHkae7Cb.js";
|
|
2
|
+
import { t as ReadonlyWorkspaceFacade } from "./use-D16tf8Ph.js";
|
|
3
|
+
|
|
4
|
+
//#region src/collections.d.ts
|
|
5
|
+
interface WorkspaceCollectionEmptyFilter {
|
|
6
|
+
empty: true;
|
|
7
|
+
}
|
|
8
|
+
declare const workspaceCollectionEmpty: WorkspaceCollectionEmptyFilter;
|
|
9
|
+
type WorkspaceCollectionFilter = string | string[] | WorkspaceCollectionEmptyFilter;
|
|
10
|
+
interface WorkspaceCollectionSort {
|
|
11
|
+
direction?: "asc" | "desc";
|
|
12
|
+
field: string;
|
|
13
|
+
}
|
|
14
|
+
interface WorkspaceCollectionQuery {
|
|
15
|
+
cursor?: string;
|
|
16
|
+
facets?: string[];
|
|
17
|
+
filters?: Record<string, WorkspaceCollectionFilter | undefined>;
|
|
18
|
+
limit?: number;
|
|
19
|
+
search?: string;
|
|
20
|
+
searchFields?: string[];
|
|
21
|
+
select?: string[];
|
|
22
|
+
sort?: WorkspaceCollectionSort;
|
|
23
|
+
}
|
|
24
|
+
interface WorkspaceCollectionItemQuery {
|
|
25
|
+
key: string;
|
|
26
|
+
select?: string[];
|
|
27
|
+
value: string | number;
|
|
28
|
+
}
|
|
29
|
+
interface WorkspaceCollectionOptions<Name extends WorkspaceName = WorkspaceName> {
|
|
30
|
+
defaultLimit?: number;
|
|
31
|
+
maxLimit?: number;
|
|
32
|
+
path: string;
|
|
33
|
+
workspace: Name | ReadonlyWorkspaceFacade<Name> | Promise<ReadonlyWorkspaceFacade<Name>>;
|
|
34
|
+
}
|
|
35
|
+
interface WorkspaceCollectionPageOptions<Name extends WorkspaceName = WorkspaceName> extends WorkspaceCollectionOptions<Name> {
|
|
36
|
+
query?: WorkspaceCollectionQuery;
|
|
37
|
+
}
|
|
38
|
+
interface WorkspaceCollectionItemOptions<Name extends WorkspaceName = WorkspaceName> extends WorkspaceCollectionOptions<Name> {
|
|
39
|
+
query: WorkspaceCollectionItemQuery;
|
|
40
|
+
}
|
|
41
|
+
interface WorkspaceCollectionFacetValue {
|
|
42
|
+
count: number;
|
|
43
|
+
value: string;
|
|
44
|
+
}
|
|
45
|
+
interface WorkspaceCollectionPage<T = Record<string, unknown>> {
|
|
46
|
+
digest: string;
|
|
47
|
+
facets: Record<string, WorkspaceCollectionFacetValue[]>;
|
|
48
|
+
items: T[];
|
|
49
|
+
nextCursor: string | null;
|
|
50
|
+
total: number;
|
|
51
|
+
}
|
|
52
|
+
interface WorkspaceCollectionItem<T = Record<string, unknown>> {
|
|
53
|
+
digest: string;
|
|
54
|
+
item: T | null;
|
|
55
|
+
}
|
|
56
|
+
declare function queryWorkspaceCollection<T = Record<string, unknown>, Name extends WorkspaceName = WorkspaceName>(options: WorkspaceCollectionPageOptions<Name>): Promise<WorkspaceCollectionPage<T>>;
|
|
57
|
+
declare function getWorkspaceCollectionItem<T = Record<string, unknown>, Name extends WorkspaceName = WorkspaceName>(options: WorkspaceCollectionItemOptions<Name>): Promise<WorkspaceCollectionItem<T>>;
|
|
58
|
+
//#endregion
|
|
59
|
+
export { WorkspaceCollectionEmptyFilter, WorkspaceCollectionFacetValue, WorkspaceCollectionFilter, WorkspaceCollectionItem, WorkspaceCollectionItemOptions, WorkspaceCollectionItemQuery, WorkspaceCollectionOptions, WorkspaceCollectionPage, WorkspaceCollectionPageOptions, WorkspaceCollectionQuery, WorkspaceCollectionSort, getWorkspaceCollectionItem, queryWorkspaceCollection, workspaceCollectionEmpty };
|