@cloudflare/sandbox 0.4.8 → 0.4.9
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/.turbo/turbo-build.log +13 -13
- package/CHANGELOG.md +15 -0
- package/dist/{chunk-MA44U7QN.js → chunk-HBTENZ2Q.js} +26 -2
- package/dist/chunk-HBTENZ2Q.js.map +1 -0
- package/dist/chunk-QHRFHK6X.js +7 -0
- package/dist/{chunk-3RA7RDAX.js.map → chunk-QHRFHK6X.js.map} +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/interpreter.d.ts +1 -1
- package/dist/request-handler.d.ts +1 -1
- package/dist/request-handler.js +2 -2
- package/dist/{sandbox-DMlNr93l.d.ts → sandbox-DWQVgVTY.d.ts} +8 -1
- package/dist/sandbox.d.ts +1 -1
- package/dist/sandbox.js +2 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/src/clients/file-client.ts +26 -0
- package/src/sandbox.ts +6 -0
- package/src/version.ts +1 -1
- package/tests/file-client.test.ts +76 -0
- package/dist/chunk-3RA7RDAX.js +0 -7
- package/dist/chunk-MA44U7QN.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _repo_shared from '@repo/shared';
|
|
2
|
-
import { Logger, MkdirResult, WriteFileResult, ReadFileResult, DeleteFileResult, RenameFileResult, MoveFileResult, ListFilesOptions, ListFilesResult, GitCheckoutResult, CreateContextOptions, CodeContext, OutputMessage, Result, ExecutionError, PortExposeResult, PortCloseResult, PortListResult, ProcessStartResult, ProcessListResult, ProcessInfoResult, ProcessKillResult, ProcessCleanupResult, ProcessLogsResult, ISandbox, ExecOptions, ExecResult, ProcessOptions, Process, StreamOptions, SessionOptions, ExecutionSession, RunCodeOptions, ExecutionResult, SandboxOptions } from '@repo/shared';
|
|
2
|
+
import { Logger, MkdirResult, WriteFileResult, ReadFileResult, DeleteFileResult, RenameFileResult, MoveFileResult, ListFilesOptions, ListFilesResult, FileExistsResult, GitCheckoutResult, CreateContextOptions, CodeContext, OutputMessage, Result, ExecutionError, PortExposeResult, PortCloseResult, PortListResult, ProcessStartResult, ProcessListResult, ProcessInfoResult, ProcessKillResult, ProcessCleanupResult, ProcessLogsResult, ISandbox, ExecOptions, ExecResult, ProcessOptions, Process, StreamOptions, SessionOptions, ExecutionSession, RunCodeOptions, ExecutionResult, SandboxOptions } from '@repo/shared';
|
|
3
3
|
import { DurableObject } from 'cloudflare:workers';
|
|
4
4
|
import { Container } from '@cloudflare/containers';
|
|
5
5
|
|
|
@@ -239,6 +239,12 @@ declare class FileClient extends BaseHttpClient {
|
|
|
239
239
|
* @param options - Optional settings (recursive, includeHidden)
|
|
240
240
|
*/
|
|
241
241
|
listFiles(path: string, sessionId: string, options?: ListFilesOptions): Promise<ListFilesResult>;
|
|
242
|
+
/**
|
|
243
|
+
* Check if a file or directory exists
|
|
244
|
+
* @param path - Path to check
|
|
245
|
+
* @param sessionId - The session ID for this operation
|
|
246
|
+
*/
|
|
247
|
+
exists(path: string, sessionId: string): Promise<FileExistsResult>;
|
|
242
248
|
}
|
|
243
249
|
|
|
244
250
|
/**
|
|
@@ -546,6 +552,7 @@ declare class Sandbox<Env = unknown> extends Container<Env> implements ISandbox
|
|
|
546
552
|
recursive?: boolean;
|
|
547
553
|
includeHidden?: boolean;
|
|
548
554
|
}): Promise<_repo_shared.ListFilesResult>;
|
|
555
|
+
exists(path: string, sessionId?: string): Promise<_repo_shared.FileExistsResult>;
|
|
549
556
|
exposePort(port: number, options: {
|
|
550
557
|
name?: string;
|
|
551
558
|
hostname: string;
|
package/dist/sandbox.d.ts
CHANGED
package/dist/sandbox.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Sandbox,
|
|
3
3
|
getSandbox
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-HBTENZ2Q.js";
|
|
5
5
|
import "./chunk-JXZMAU2C.js";
|
|
6
6
|
import "./chunk-Z532A7QC.js";
|
|
7
7
|
import "./chunk-EKSWCBCA.js";
|
|
8
|
-
import "./chunk-
|
|
8
|
+
import "./chunk-QHRFHK6X.js";
|
|
9
9
|
export {
|
|
10
10
|
Sandbox,
|
|
11
11
|
getSandbox
|
package/dist/version.d.ts
CHANGED
package/dist/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
DeleteFileResult,
|
|
3
|
+
FileExistsResult,
|
|
3
4
|
ListFilesOptions,
|
|
4
5
|
ListFilesResult,
|
|
5
6
|
MkdirResult,
|
|
@@ -266,4 +267,29 @@ export class FileClient extends BaseHttpClient {
|
|
|
266
267
|
throw error;
|
|
267
268
|
}
|
|
268
269
|
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Check if a file or directory exists
|
|
273
|
+
* @param path - Path to check
|
|
274
|
+
* @param sessionId - The session ID for this operation
|
|
275
|
+
*/
|
|
276
|
+
async exists(
|
|
277
|
+
path: string,
|
|
278
|
+
sessionId: string
|
|
279
|
+
): Promise<FileExistsResult> {
|
|
280
|
+
try {
|
|
281
|
+
const data = {
|
|
282
|
+
path,
|
|
283
|
+
sessionId,
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
const response = await this.post<FileExistsResult>('/api/exists', data);
|
|
287
|
+
|
|
288
|
+
this.logSuccess('Path existence checked', `${path} (exists: ${response.exists})`);
|
|
289
|
+
return response;
|
|
290
|
+
} catch (error) {
|
|
291
|
+
this.logError('exists', error);
|
|
292
|
+
throw error;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
269
295
|
}
|
package/src/sandbox.ts
CHANGED
|
@@ -697,6 +697,11 @@ export class Sandbox<Env = unknown> extends Container<Env> implements ISandbox {
|
|
|
697
697
|
return this.client.files.listFiles(path, session, options);
|
|
698
698
|
}
|
|
699
699
|
|
|
700
|
+
async exists(path: string, sessionId?: string) {
|
|
701
|
+
const session = sessionId ?? await this.ensureDefaultSession();
|
|
702
|
+
return this.client.files.exists(path, session);
|
|
703
|
+
}
|
|
704
|
+
|
|
700
705
|
async exposePort(port: number, options: { name?: string; hostname: string }) {
|
|
701
706
|
// Check if hostname is workers.dev domain (doesn't support wildcard subdomains)
|
|
702
707
|
if (options.hostname.endsWith('.workers.dev')) {
|
|
@@ -934,6 +939,7 @@ export class Sandbox<Env = unknown> extends Container<Env> implements ISandbox {
|
|
|
934
939
|
renameFile: (oldPath, newPath) => this.renameFile(oldPath, newPath, sessionId),
|
|
935
940
|
moveFile: (sourcePath, destPath) => this.moveFile(sourcePath, destPath, sessionId),
|
|
936
941
|
listFiles: (path, options) => this.client.files.listFiles(path, sessionId, options),
|
|
942
|
+
exists: (path) => this.exists(path, sessionId),
|
|
937
943
|
|
|
938
944
|
// Git operations
|
|
939
945
|
gitCheckout: (repoUrl, options) => this.gitCheckout(repoUrl, { ...options, sessionId }),
|
package/src/version.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
DeleteFileResult,
|
|
3
|
+
FileExistsResult,
|
|
3
4
|
ListFilesResult,
|
|
4
5
|
MkdirResult,
|
|
5
6
|
MoveFileResult,
|
|
@@ -584,6 +585,81 @@ database:
|
|
|
584
585
|
});
|
|
585
586
|
});
|
|
586
587
|
|
|
588
|
+
describe('exists', () => {
|
|
589
|
+
it('should return true when file exists', async () => {
|
|
590
|
+
const mockResponse: FileExistsResult = {
|
|
591
|
+
success: true,
|
|
592
|
+
path: '/workspace/test.txt',
|
|
593
|
+
exists: true,
|
|
594
|
+
timestamp: '2023-01-01T00:00:00Z',
|
|
595
|
+
};
|
|
596
|
+
|
|
597
|
+
mockFetch.mockResolvedValue(new Response(JSON.stringify(mockResponse), { status: 200 }));
|
|
598
|
+
|
|
599
|
+
const result = await client.exists('/workspace/test.txt', 'session-exists');
|
|
600
|
+
|
|
601
|
+
expect(result.success).toBe(true);
|
|
602
|
+
expect(result.exists).toBe(true);
|
|
603
|
+
expect(result.path).toBe('/workspace/test.txt');
|
|
604
|
+
});
|
|
605
|
+
|
|
606
|
+
it('should return false when file does not exist', async () => {
|
|
607
|
+
const mockResponse: FileExistsResult = {
|
|
608
|
+
success: true,
|
|
609
|
+
path: '/workspace/nonexistent.txt',
|
|
610
|
+
exists: false,
|
|
611
|
+
timestamp: '2023-01-01T00:00:00Z',
|
|
612
|
+
};
|
|
613
|
+
|
|
614
|
+
mockFetch.mockResolvedValue(new Response(JSON.stringify(mockResponse), { status: 200 }));
|
|
615
|
+
|
|
616
|
+
const result = await client.exists('/workspace/nonexistent.txt', 'session-exists');
|
|
617
|
+
|
|
618
|
+
expect(result.success).toBe(true);
|
|
619
|
+
expect(result.exists).toBe(false);
|
|
620
|
+
});
|
|
621
|
+
|
|
622
|
+
it('should return true when directory exists', async () => {
|
|
623
|
+
const mockResponse: FileExistsResult = {
|
|
624
|
+
success: true,
|
|
625
|
+
path: '/workspace/some-dir',
|
|
626
|
+
exists: true,
|
|
627
|
+
timestamp: '2023-01-01T00:00:00Z',
|
|
628
|
+
};
|
|
629
|
+
|
|
630
|
+
mockFetch.mockResolvedValue(new Response(JSON.stringify(mockResponse), { status: 200 }));
|
|
631
|
+
|
|
632
|
+
const result = await client.exists('/workspace/some-dir', 'session-exists');
|
|
633
|
+
|
|
634
|
+
expect(result.success).toBe(true);
|
|
635
|
+
expect(result.exists).toBe(true);
|
|
636
|
+
});
|
|
637
|
+
|
|
638
|
+
it('should send correct request payload', async () => {
|
|
639
|
+
const mockResponse: FileExistsResult = {
|
|
640
|
+
success: true,
|
|
641
|
+
path: '/test/path',
|
|
642
|
+
exists: true,
|
|
643
|
+
timestamp: '2023-01-01T00:00:00Z',
|
|
644
|
+
};
|
|
645
|
+
|
|
646
|
+
mockFetch.mockResolvedValue(new Response(JSON.stringify(mockResponse), { status: 200 }));
|
|
647
|
+
|
|
648
|
+
await client.exists('/test/path', 'session-test');
|
|
649
|
+
|
|
650
|
+
expect(mockFetch).toHaveBeenCalledWith(
|
|
651
|
+
expect.stringContaining('/api/exists'),
|
|
652
|
+
expect.objectContaining({
|
|
653
|
+
method: 'POST',
|
|
654
|
+
body: JSON.stringify({
|
|
655
|
+
path: '/test/path',
|
|
656
|
+
sessionId: 'session-test',
|
|
657
|
+
})
|
|
658
|
+
})
|
|
659
|
+
);
|
|
660
|
+
});
|
|
661
|
+
});
|
|
662
|
+
|
|
587
663
|
describe('error handling', () => {
|
|
588
664
|
it('should handle network failures gracefully', async () => {
|
|
589
665
|
mockFetch.mockRejectedValue(new Error('Network connection failed'));
|