@cloudflare/workspace 0.0.0-alpha.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 +98 -0
- package/dist/bin/wsd-linux-x64 +0 -0
- package/dist/git.d.ts +119 -0
- package/dist/git.js +271 -0
- package/dist/git.js.map +1 -0
- package/dist/index.d.ts +384 -0
- package/dist/index.js +2902 -0
- package/dist/index.js.map +1 -0
- package/dist/shared-Dj4r_9xb.js +737 -0
- package/dist/shared-Dj4r_9xb.js.map +1 -0
- package/dist/shared-RIdME5uo.d.ts +302 -0
- package/package.json +72 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
import { _ as Database, a as SQLiteWorkspaceProviderOptions, c as WriteFileOptions, d as ReadFileOptions, f as WorkspaceDirentResult, g as WorkspaceFoundEntry, h as WorkspaceGrepMatch, i as SQLiteWorkspaceProvider, l as WorkspaceStatResult, m as GrepOptions, n as SkippedEntry, o as WorkspaceFilesystem, p as MkdirOptions, r as ChangeEntry, s as WriteFileContent, t as ApplyResult, u as RmOptions, v as DurableObjectStorageLike } from "./shared-RIdME5uo.js";
|
|
2
|
+
import { RpcTarget } from "capnweb";
|
|
3
|
+
import { RpcTarget as RpcTarget$1, WorkerEntrypoint } from "cloudflare:workers";
|
|
4
|
+
|
|
5
|
+
//#region ../rpc/dist/interface.d.ts
|
|
6
|
+
interface SyncRPC {
|
|
7
|
+
push(input: {
|
|
8
|
+
senderRev: number;
|
|
9
|
+
changes: ReadableStream<ChangeEntry>;
|
|
10
|
+
}): Promise<{
|
|
11
|
+
rev: number;
|
|
12
|
+
appliedPushRev: number;
|
|
13
|
+
}>;
|
|
14
|
+
fetchChanges(input: {
|
|
15
|
+
sinceRev?: number;
|
|
16
|
+
ignore?: string[];
|
|
17
|
+
}): Promise<{
|
|
18
|
+
currentRev: number;
|
|
19
|
+
appliedPushRev: number;
|
|
20
|
+
stream: ReadableStream<ChangeEntry>;
|
|
21
|
+
}>;
|
|
22
|
+
watermarks(): Promise<{
|
|
23
|
+
currentRev: number;
|
|
24
|
+
pushRev: number;
|
|
25
|
+
fetchRev: number;
|
|
26
|
+
}>;
|
|
27
|
+
readEntry(path: string): Promise<ChangeEntry | null>;
|
|
28
|
+
hasObjects(hashes: Uint8Array[]): Promise<Uint8Array[]>;
|
|
29
|
+
fetchObjects(hashes: Uint8Array[]): ReadableStream<{
|
|
30
|
+
hash: Uint8Array;
|
|
31
|
+
bytes: Uint8Array;
|
|
32
|
+
}>;
|
|
33
|
+
pushObjects(objects: ReadableStream<{
|
|
34
|
+
hash: Uint8Array;
|
|
35
|
+
bytes: Uint8Array;
|
|
36
|
+
}>): Promise<void>;
|
|
37
|
+
}
|
|
38
|
+
interface ShellRPC {
|
|
39
|
+
exec(input: {
|
|
40
|
+
command: string;
|
|
41
|
+
cwd?: string;
|
|
42
|
+
id?: string;
|
|
43
|
+
timeoutMs?: number;
|
|
44
|
+
}): Promise<{
|
|
45
|
+
id: string;
|
|
46
|
+
events: ReadableStream<ExecEvent>;
|
|
47
|
+
}>;
|
|
48
|
+
getExec(input: {
|
|
49
|
+
id: string;
|
|
50
|
+
after?: number | "tail";
|
|
51
|
+
}): Promise<{
|
|
52
|
+
id: string;
|
|
53
|
+
events: ReadableStream<ExecEvent>;
|
|
54
|
+
}>;
|
|
55
|
+
killExec(input: {
|
|
56
|
+
id: string;
|
|
57
|
+
signal?: "SIGTERM" | "SIGKILL" | "SIGINT" | "SIGHUP";
|
|
58
|
+
}): Promise<void>;
|
|
59
|
+
disposeExec(input: {
|
|
60
|
+
id: string;
|
|
61
|
+
}): Promise<void>;
|
|
62
|
+
}
|
|
63
|
+
interface WorkspaceRPC {
|
|
64
|
+
sync: SyncRPC;
|
|
65
|
+
shell: ShellRPC;
|
|
66
|
+
}
|
|
67
|
+
type ExecEvent = {
|
|
68
|
+
id: string;
|
|
69
|
+
seq: number;
|
|
70
|
+
name: "stdout";
|
|
71
|
+
value: Uint8Array;
|
|
72
|
+
} | {
|
|
73
|
+
id: string;
|
|
74
|
+
seq: number;
|
|
75
|
+
name: "stderr";
|
|
76
|
+
value: Uint8Array;
|
|
77
|
+
} | {
|
|
78
|
+
id: string;
|
|
79
|
+
seq: number;
|
|
80
|
+
name: "exit";
|
|
81
|
+
value: number;
|
|
82
|
+
};
|
|
83
|
+
//#endregion
|
|
84
|
+
//#region src/backend.d.ts
|
|
85
|
+
interface WorkspaceBackend {
|
|
86
|
+
readonly id: string;
|
|
87
|
+
connect(): Promise<BackendHandle>;
|
|
88
|
+
}
|
|
89
|
+
interface BackendHandle {
|
|
90
|
+
rpc: WorkspaceRPC;
|
|
91
|
+
closed?: Promise<void>;
|
|
92
|
+
close(): Promise<void>;
|
|
93
|
+
}
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region src/backends/container-host.d.ts
|
|
96
|
+
interface WorkspaceRef {
|
|
97
|
+
binding: string;
|
|
98
|
+
id: string;
|
|
99
|
+
}
|
|
100
|
+
interface IWorkspaceContainerAPI {
|
|
101
|
+
start(env: Record<string, string>): Promise<void>;
|
|
102
|
+
interceptOutboundHttp(host: string, workspace: WorkspaceRef): Promise<void>;
|
|
103
|
+
port(port: number): Fetcher;
|
|
104
|
+
}
|
|
105
|
+
declare class WorkspaceContainerAPI extends RpcTarget$1 implements IWorkspaceContainerAPI {
|
|
106
|
+
#private;
|
|
107
|
+
constructor(ctx: DurableObjectState);
|
|
108
|
+
start(env: Record<string, string>): Promise<void>;
|
|
109
|
+
interceptOutboundHttp(host: string, ref: WorkspaceRef): Promise<void>;
|
|
110
|
+
port(port: number): {
|
|
111
|
+
fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
|
|
112
|
+
connect(address: SocketAddress | string, options?: SocketOptions): Socket;
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
type DOCtor = new (...args: any[]) => object;
|
|
116
|
+
type WithWorkspaceContainerCtor<TBase extends DOCtor> = TBase & (new (...args: any[]) => InstanceType<TBase> & {
|
|
117
|
+
getWorkspaceContainer(): WorkspaceContainerAPI;
|
|
118
|
+
});
|
|
119
|
+
declare function withWorkspaceContainer<TBase extends DOCtor>(Base: TBase): WithWorkspaceContainerCtor<TBase>;
|
|
120
|
+
//#endregion
|
|
121
|
+
//#region src/backends/cloudflare-container.d.ts
|
|
122
|
+
interface ContainerHostHolder {
|
|
123
|
+
getWorkspaceContainer(): IWorkspaceContainerAPI | Promise<IWorkspaceContainerAPI>;
|
|
124
|
+
}
|
|
125
|
+
interface CloudflareContainerBackendOptions {
|
|
126
|
+
container: () => ContainerHostHolder | Promise<ContainerHostHolder>;
|
|
127
|
+
workspace: WorkspaceRef;
|
|
128
|
+
egressHost?: string;
|
|
129
|
+
containerPort?: number;
|
|
130
|
+
containerEnv?: Record<string, string>;
|
|
131
|
+
connectTimeoutMs?: number;
|
|
132
|
+
heartbeatIntervalMs?: number;
|
|
133
|
+
}
|
|
134
|
+
declare class CloudflareContainerBackend implements WorkspaceBackend {
|
|
135
|
+
#private;
|
|
136
|
+
readonly id = "cloudflare-container";
|
|
137
|
+
constructor(options: CloudflareContainerBackendOptions);
|
|
138
|
+
connect(): Promise<BackendHandle>;
|
|
139
|
+
handleFetch(req: Request): Promise<Response>;
|
|
140
|
+
}
|
|
141
|
+
//#endregion
|
|
142
|
+
//#region src/backends/test.d.ts
|
|
143
|
+
interface TestBackendOptions {
|
|
144
|
+
url: string;
|
|
145
|
+
}
|
|
146
|
+
declare class TestBackend implements WorkspaceBackend {
|
|
147
|
+
#private;
|
|
148
|
+
readonly id = "test";
|
|
149
|
+
constructor(options: TestBackendOptions);
|
|
150
|
+
connect(): Promise<BackendHandle>;
|
|
151
|
+
}
|
|
152
|
+
//#endregion
|
|
153
|
+
//#region src/mounts/types.d.ts
|
|
154
|
+
interface MountBase {
|
|
155
|
+
readonly kind: string;
|
|
156
|
+
readonly mode: "read-only" | "read-write";
|
|
157
|
+
readonly maxBytes?: number;
|
|
158
|
+
readonly maxEntries?: number;
|
|
159
|
+
}
|
|
160
|
+
interface EagerMount extends MountBase {
|
|
161
|
+
readonly strategy: "eager";
|
|
162
|
+
materialize(api: MountWriteAPI): Promise<void>;
|
|
163
|
+
}
|
|
164
|
+
type Mount = EagerMount;
|
|
165
|
+
type MountFactory = (ctx: MountContext) => Mount;
|
|
166
|
+
interface MountContext {
|
|
167
|
+
sessionId: string;
|
|
168
|
+
root: string;
|
|
169
|
+
vfs: SQLiteWorkspaceProvider;
|
|
170
|
+
}
|
|
171
|
+
interface MountWriteAPI {
|
|
172
|
+
readonly root: string;
|
|
173
|
+
writeFile(absPath: string, source: ReadableStream<Uint8Array>, mode?: number): Promise<void>;
|
|
174
|
+
mkdir(absPath: string, mode?: number): Promise<void>;
|
|
175
|
+
}
|
|
176
|
+
//#endregion
|
|
177
|
+
//#region src/mounts/providers/r2.d.ts
|
|
178
|
+
interface R2BucketBinding {
|
|
179
|
+
list(options?: {
|
|
180
|
+
prefix?: string;
|
|
181
|
+
cursor?: string;
|
|
182
|
+
limit?: number;
|
|
183
|
+
}): Promise<{
|
|
184
|
+
objects: Array<{
|
|
185
|
+
key: string;
|
|
186
|
+
size: number;
|
|
187
|
+
}>;
|
|
188
|
+
truncated: boolean;
|
|
189
|
+
cursor?: string;
|
|
190
|
+
}>;
|
|
191
|
+
get(key: string): Promise<{
|
|
192
|
+
body: ReadableStream<Uint8Array>;
|
|
193
|
+
size: number;
|
|
194
|
+
} | null>;
|
|
195
|
+
}
|
|
196
|
+
interface R2BucketOptions {
|
|
197
|
+
prefix?: string;
|
|
198
|
+
mode?: "read-only" | "read-write";
|
|
199
|
+
listLimit?: number;
|
|
200
|
+
concurrency?: number;
|
|
201
|
+
maxBytes?: number;
|
|
202
|
+
maxEntries?: number;
|
|
203
|
+
}
|
|
204
|
+
declare function R2Bucket(bucket: R2BucketBinding, options?: R2BucketOptions): EagerMount;
|
|
205
|
+
//#endregion
|
|
206
|
+
//#region src/proxy.d.ts
|
|
207
|
+
interface WorkspaceProxyProps {
|
|
208
|
+
binding: string;
|
|
209
|
+
id: string;
|
|
210
|
+
}
|
|
211
|
+
declare class WorkspaceProxy extends WorkerEntrypoint<unknown, WorkspaceProxyProps> {
|
|
212
|
+
fetch(request: Request): Promise<Response>;
|
|
213
|
+
}
|
|
214
|
+
//#endregion
|
|
215
|
+
//#region src/shell.d.ts
|
|
216
|
+
type ExecEncoding = "utf8" | undefined;
|
|
217
|
+
type Chunk<E extends ExecEncoding> = E extends "utf8" ? string : Uint8Array;
|
|
218
|
+
type WorkspaceExecEvent<E extends ExecEncoding = undefined> = {
|
|
219
|
+
id: string;
|
|
220
|
+
seq: number;
|
|
221
|
+
name: "stdout";
|
|
222
|
+
value: Chunk<E>;
|
|
223
|
+
} | {
|
|
224
|
+
id: string;
|
|
225
|
+
seq: number;
|
|
226
|
+
name: "stderr";
|
|
227
|
+
value: Chunk<E>;
|
|
228
|
+
} | {
|
|
229
|
+
id: string;
|
|
230
|
+
seq: number;
|
|
231
|
+
name: "exit";
|
|
232
|
+
value: number;
|
|
233
|
+
};
|
|
234
|
+
interface ExecResult<E extends ExecEncoding = undefined> {
|
|
235
|
+
exitCode: number;
|
|
236
|
+
stdout: Chunk<E>;
|
|
237
|
+
stderr: Chunk<E>;
|
|
238
|
+
pushed: number;
|
|
239
|
+
pulled: number;
|
|
240
|
+
skipped: SkippedEntry[];
|
|
241
|
+
}
|
|
242
|
+
type KillSignal = "SIGTERM" | "SIGKILL" | "SIGINT" | "SIGHUP";
|
|
243
|
+
interface ExecHandle<E extends ExecEncoding = undefined> extends ReadableStream<WorkspaceExecEvent<E>> {
|
|
244
|
+
readonly id: string;
|
|
245
|
+
result(): Promise<ExecResult<E>>;
|
|
246
|
+
kill(signal?: KillSignal): Promise<void>;
|
|
247
|
+
}
|
|
248
|
+
interface ExecOptions<E extends ExecEncoding = undefined> {
|
|
249
|
+
id?: string;
|
|
250
|
+
cwd?: string;
|
|
251
|
+
encoding?: E;
|
|
252
|
+
timeoutMs?: number;
|
|
253
|
+
}
|
|
254
|
+
interface GetExecOptions<E extends ExecEncoding = undefined> {
|
|
255
|
+
encoding?: E;
|
|
256
|
+
resume?: "tail" | "full" | number;
|
|
257
|
+
}
|
|
258
|
+
interface Sync {
|
|
259
|
+
push(): Promise<number>;
|
|
260
|
+
pull(): Promise<ApplyResult>;
|
|
261
|
+
}
|
|
262
|
+
declare class WorkspaceShell {
|
|
263
|
+
#private;
|
|
264
|
+
constructor(shell: ShellRPC, sync: Sync);
|
|
265
|
+
exec(command: string): Promise<ExecHandle<undefined>>;
|
|
266
|
+
exec(command: string, options: ExecOptions<undefined>): Promise<ExecHandle<undefined>>;
|
|
267
|
+
exec(command: string, options: ExecOptions<"utf8">): Promise<ExecHandle<"utf8">>;
|
|
268
|
+
get(id: string): Promise<ExecHandle<undefined>>;
|
|
269
|
+
get(id: string, options: GetExecOptions<undefined>): Promise<ExecHandle<undefined>>;
|
|
270
|
+
get(id: string, options: GetExecOptions<"utf8">): Promise<ExecHandle<"utf8">>;
|
|
271
|
+
}
|
|
272
|
+
//#endregion
|
|
273
|
+
//#region src/mounts/registry.d.ts
|
|
274
|
+
type MountValue = Mount | MountFactory;
|
|
275
|
+
//#endregion
|
|
276
|
+
//#region src/workspace.d.ts
|
|
277
|
+
interface WorkspaceOptions {
|
|
278
|
+
storage: DurableObjectStorageLike;
|
|
279
|
+
backends: WorkspaceBackend[];
|
|
280
|
+
now?: () => number;
|
|
281
|
+
sessionId?: string;
|
|
282
|
+
mounts?: Record<string, MountValue>;
|
|
283
|
+
reconnect?: ReconnectOptions;
|
|
284
|
+
}
|
|
285
|
+
interface ReconnectOptions {
|
|
286
|
+
attempts: number;
|
|
287
|
+
initialDelayMs: number;
|
|
288
|
+
maxDelayMs: number;
|
|
289
|
+
}
|
|
290
|
+
declare class Workspace {
|
|
291
|
+
#private;
|
|
292
|
+
constructor(options: WorkspaceOptions);
|
|
293
|
+
ensureMountsIndexed(): Promise<void>;
|
|
294
|
+
mounts(): Map<string, Mount>;
|
|
295
|
+
get db(): Database;
|
|
296
|
+
get fs(): WorkspaceFilesystem;
|
|
297
|
+
/**
|
|
298
|
+
* Underlying dofs `SQLiteWorkspaceProvider` over the local store.
|
|
299
|
+
*
|
|
300
|
+
* This is the `@platformatic/vfs`-shaped provider — a node:fs
|
|
301
|
+
* surface with full symlink support. Callers that want a
|
|
302
|
+
* `VirtualFileSystem` (e.g. to hand to isomorphic-git) wrap it
|
|
303
|
+
* themselves to keep `@platformatic/vfs` out of this package's
|
|
304
|
+
* dependency tree:
|
|
305
|
+
*
|
|
306
|
+
* ```ts
|
|
307
|
+
* import { create, VirtualProvider } from "@platformatic/vfs";
|
|
308
|
+
* import type { SQLiteWorkspaceProvider } from "@cloudflare/dofs";
|
|
309
|
+
*
|
|
310
|
+
* class Glue extends VirtualProvider {
|
|
311
|
+
* constructor(private inner: SQLiteWorkspaceProvider) { super(); }
|
|
312
|
+
* override get readonly() { return this.inner.readonly; }
|
|
313
|
+
* override get supportsSymlinks() { return this.inner.supportsSymlinks; }
|
|
314
|
+
* override get supportsWatch() { return this.inner.supportsWatch; }
|
|
315
|
+
* }
|
|
316
|
+
* // Forward every node:fs method to `inner` via a
|
|
317
|
+
* // `for (const name of [...]) Object.defineProperty(...)` loop.
|
|
318
|
+
* const vfs = create(new Glue(workspace.provider()));
|
|
319
|
+
* ```
|
|
320
|
+
*
|
|
321
|
+
* Available immediately; doesn't need `ready()` because the
|
|
322
|
+
* provider only reads/writes the local store, not the wire.
|
|
323
|
+
*/
|
|
324
|
+
provider(): SQLiteWorkspaceProvider;
|
|
325
|
+
get shell(): WorkspaceShell;
|
|
326
|
+
ready(): Promise<void>;
|
|
327
|
+
stub(): WorkspaceStub;
|
|
328
|
+
push(): Promise<number>;
|
|
329
|
+
pull(): Promise<ApplyResult>;
|
|
330
|
+
close(): Promise<void>;
|
|
331
|
+
}
|
|
332
|
+
//#endregion
|
|
333
|
+
//#region src/stub.d.ts
|
|
334
|
+
interface WorkspaceExecOptions {
|
|
335
|
+
cwd?: string;
|
|
336
|
+
encoding?: "utf8";
|
|
337
|
+
}
|
|
338
|
+
interface WorkspaceExecResult<E extends "utf8" | undefined = undefined> {
|
|
339
|
+
exitCode: number;
|
|
340
|
+
stdout: E extends "utf8" ? string : Uint8Array;
|
|
341
|
+
stderr: E extends "utf8" ? string : Uint8Array;
|
|
342
|
+
}
|
|
343
|
+
declare class WorkspaceFilesystemStub extends RpcTarget {
|
|
344
|
+
#private;
|
|
345
|
+
constructor(ws: Workspace);
|
|
346
|
+
[Symbol.dispose](): void;
|
|
347
|
+
readFile(path: string): Promise<ReadableStream<Uint8Array>>;
|
|
348
|
+
readFile(path: string, encoding: "utf8"): Promise<string>;
|
|
349
|
+
readFile(path: string, options: ReadFileOptions): Promise<string | ReadableStream<Uint8Array>>;
|
|
350
|
+
stat(path: string): Promise<WorkspaceStatResult>;
|
|
351
|
+
readdir(path: string): Promise<WorkspaceDirentResult[]>;
|
|
352
|
+
find(directory: string, pattern?: string): Promise<WorkspaceFoundEntry[]>;
|
|
353
|
+
ls(prefix: string): Promise<string[]>;
|
|
354
|
+
grep(pattern: string, path: string, options?: GrepOptions): Promise<WorkspaceGrepMatch[]>;
|
|
355
|
+
writeFile(path: string, content: WriteFileContent, options?: WriteFileOptions): Promise<void>;
|
|
356
|
+
mkdir(path: string, options?: MkdirOptions): Promise<void>;
|
|
357
|
+
rm(path: string, options?: RmOptions): Promise<void>;
|
|
358
|
+
}
|
|
359
|
+
declare class WorkspaceExecHandleStub<E extends "utf8" | undefined = undefined> extends RpcTarget {
|
|
360
|
+
#private;
|
|
361
|
+
constructor(pending: Promise<ExecResult<E>>);
|
|
362
|
+
[Symbol.dispose](): void;
|
|
363
|
+
result(): Promise<WorkspaceExecResult<E>>;
|
|
364
|
+
}
|
|
365
|
+
declare class WorkspaceShellStub extends RpcTarget {
|
|
366
|
+
#private;
|
|
367
|
+
constructor(ws: Workspace);
|
|
368
|
+
[Symbol.dispose](): void;
|
|
369
|
+
exec(command: string): Promise<WorkspaceExecHandleStub<undefined>>;
|
|
370
|
+
exec(command: string, options: WorkspaceExecOptions & {
|
|
371
|
+
encoding: "utf8";
|
|
372
|
+
}): Promise<WorkspaceExecHandleStub<"utf8">>;
|
|
373
|
+
exec(command: string, options: WorkspaceExecOptions): Promise<WorkspaceExecHandleStub<undefined>>;
|
|
374
|
+
}
|
|
375
|
+
declare class WorkspaceStub extends RpcTarget {
|
|
376
|
+
#private;
|
|
377
|
+
constructor(ws: Workspace);
|
|
378
|
+
[Symbol.dispose](): void;
|
|
379
|
+
get fs(): WorkspaceFilesystemStub;
|
|
380
|
+
get shell(): WorkspaceShellStub;
|
|
381
|
+
}
|
|
382
|
+
//#endregion
|
|
383
|
+
export { type ApplyResult, type BackendHandle, CloudflareContainerBackend, type CloudflareContainerBackendOptions, type DurableObjectStorageLike, type EagerMount, type ExecEncoding, type ExecHandle, type ExecOptions, type ExecResult, type GetExecOptions, type IWorkspaceContainerAPI, type KillSignal, type Mount, type MountBase, type MountContext, type MountFactory, type MountWriteAPI, R2Bucket, type R2BucketBinding, type R2BucketOptions, SQLiteWorkspaceProvider, type SQLiteWorkspaceProviderOptions, type SkippedEntry, TestBackend, type TestBackendOptions, Workspace, type WorkspaceBackend, WorkspaceContainerAPI, type WorkspaceExecEvent, WorkspaceExecHandleStub, type WorkspaceExecOptions, type WorkspaceExecResult, WorkspaceFilesystemStub, type WorkspaceOptions, WorkspaceProxy, type WorkspaceProxyProps, type WorkspaceRef, WorkspaceShell, WorkspaceShellStub, WorkspaceStub, withWorkspaceContainer };
|
|
384
|
+
//# sourceMappingURL=index.d.ts.map
|