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

Function workspaceIsomorphicGitClient

packages/computer/src/git/adapter.ts:107–169  ·  view source on GitHub ↗
(
  provider: SQLiteWorkspaceProvider,
)

Source from the content-addressed store, hash-verified

105 * one stack frame away from obvious.
106 */
107export async function workspaceIsomorphicGitClient(
108 provider: SQLiteWorkspaceProvider,
109): Promise<IsomorphicGitFSClient> {
110 let create: typeof import("@platformatic/vfs").create;
111 let VirtualProvider: typeof import("@platformatic/vfs").VirtualProvider;
112 try {
113 ({ create, VirtualProvider } = await import("@platformatic/vfs"));
114 } catch (cause) {
115 throw new Error(
116 "@cloudflare/computer/git requires @platformatic/vfs as an optional peer dependency. " +
117 "Install it, or pass `fs` to clone() explicitly.",
118 { cause },
119 );
120 }
121
122 class SQLiteVirtualProvider extends VirtualProvider {
123 readonly #inner: SQLiteWorkspaceProvider;
124 constructor(inner: SQLiteWorkspaceProvider) {
125 super();
126 this.#inner = inner;
127 }
128 // VirtualProvider's defaults are false. The dofs provider
129 // declares the real values as instance properties; the
130 // forwarding loop below skips accessors, so re-expose them.
131 override get readonly(): boolean {
132 return this.#inner.readonly;
133 }
134 override get supportsSymlinks(): boolean {
135 return this.#inner.supportsSymlinks;
136 }
137 override get supportsWatch(): boolean {
138 return this.#inner.supportsWatch;
139 }
140 /** Used by the forwarding loop below. */
141 get inner(): SQLiteWorkspaceProvider {
142 return this.#inner;
143 }
144 }
145
146 for (const name of FORWARDED_METHODS) {
147 Object.defineProperty(SQLiteVirtualProvider.prototype, name, {
148 value(this: SQLiteVirtualProvider, ...args: unknown[]): unknown {
149 // biome-ignore lint/suspicious/noExplicitAny: dispatch table
150 const inner = this.inner as any;
151 const fn = inner[name];
152 if (typeof fn !== "function") {
153 throw new Error(`SQLiteWorkspaceProvider.${String(name)} is not a function`);
154 }
155 return fn.apply(inner, args);
156 },
157 writable: true,
158 configurable: true,
159 });
160 }
161
162 // `moduleHooks: false` keeps @platformatic/vfs from installing
163 // Node module-resolution hooks, which depend on `node:module` and
164 // are pointless inside workerd.

Callers 2

cli.test.tsFile · 0.85
entrypoint.test.tsFile · 0.85

Calls 1

createFunction · 0.50

Tested by

no test coverage detected