MCPcopy Create free account
hub / github.com/cloudflare/computer / WorkspaceRuntimeStub

Class WorkspaceRuntimeStub

packages/computer/src/stub.ts:374–443  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

372}
373
374export class WorkspaceRuntimeStub extends RpcTarget {
375 readonly #ws: Workspace;
376
377 constructor(ws: Workspace) {
378 super();
379 this.#ws = ws;
380 trackStub(this);
381 }
382
383 [Symbol.dispose](): void {
384 untrackStub(this);
385 }
386
387 exec(source: string): Promise<WorkspaceRuntimeExecHandleStub<undefined>>;
388 exec(
389 source: string,
390 options: WorkspaceRuntimeExecOptions<"utf8">,
391 ): Promise<WorkspaceRuntimeExecHandleStub<"utf8">>;
392 exec(
393 source: string,
394 options: WorkspaceRuntimeExecOptions<undefined>,
395 ): Promise<WorkspaceRuntimeExecHandleStub<undefined>>;
396 async exec(
397 source: string,
398 options: WorkspaceRuntimeExecOptions<"utf8" | undefined> = {},
399 ): Promise<WorkspaceRuntimeExecHandleStub<"utf8" | undefined>> {
400 await this.#ws.ready(options.backend);
401 const handle = await (
402 this.#ws.runtime.exec as unknown as (
403 source: string,
404 options: WorkspaceRuntimeExecOptions<"utf8" | undefined>,
405 ) => Promise<WorkspaceRuntimeExecHandle<"utf8" | undefined>>
406 )(source, options);
407 if (options.id !== undefined && handle.id !== options.id) {
408 throw new Error(`backend ran exec as ${handle.id}, not the requested id ${options.id}`);
409 }
410 return new WorkspaceRuntimeExecHandleStub(handle);
411 }
412
413 getExec(id: string): Promise<WorkspaceRuntimeExecHandleStub<undefined>>;
414 getExec(
415 id: string,
416 options: WorkspaceRuntimeGetOptions<"utf8">,
417 ): Promise<WorkspaceRuntimeExecHandleStub<"utf8">>;
418 getExec(
419 id: string,
420 options: WorkspaceRuntimeGetOptions<undefined>,
421 ): Promise<WorkspaceRuntimeExecHandleStub<undefined>>;
422 async getExec(
423 id: string,
424 options: WorkspaceRuntimeGetOptions<"utf8" | undefined> = {},
425 ): Promise<WorkspaceRuntimeExecHandleStub<"utf8" | undefined>> {
426 await this.#ws.ready(options.backend);
427 const handle = await (
428 this.#ws.runtime.getExec as unknown as (
429 id: string,
430 options: WorkspaceRuntimeGetOptions<"utf8" | undefined>,
431 ) => Promise<WorkspaceRuntimeExecHandle<"utf8" | undefined>>

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected