@daytonaio/sdk 0.0.0-dev

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.
Files changed (59) hide show
  1. package/README.md +146 -0
  2. package/package.json +39 -0
  3. package/src/Daytona.d.ts +331 -0
  4. package/src/Daytona.js +400 -0
  5. package/src/Daytona.js.map +1 -0
  6. package/src/FileSystem.d.ts +270 -0
  7. package/src/FileSystem.js +302 -0
  8. package/src/FileSystem.js.map +1 -0
  9. package/src/Git.d.ts +211 -0
  10. package/src/Git.js +275 -0
  11. package/src/Git.js.map +1 -0
  12. package/src/Image.d.ts +264 -0
  13. package/src/Image.js +565 -0
  14. package/src/Image.js.map +1 -0
  15. package/src/LspServer.d.ts +173 -0
  16. package/src/LspServer.js +209 -0
  17. package/src/LspServer.js.map +1 -0
  18. package/src/ObjectStorage.d.ts +85 -0
  19. package/src/ObjectStorage.js +231 -0
  20. package/src/ObjectStorage.js.map +1 -0
  21. package/src/Process.d.ts +246 -0
  22. package/src/Process.js +290 -0
  23. package/src/Process.js.map +1 -0
  24. package/src/Sandbox.d.ts +266 -0
  25. package/src/Sandbox.js +389 -0
  26. package/src/Sandbox.js.map +1 -0
  27. package/src/Snapshot.d.ts +116 -0
  28. package/src/Snapshot.js +187 -0
  29. package/src/Snapshot.js.map +1 -0
  30. package/src/Volume.d.ts +79 -0
  31. package/src/Volume.js +97 -0
  32. package/src/Volume.js.map +1 -0
  33. package/src/code-toolbox/SandboxPythonCodeToolbox.d.ts +11 -0
  34. package/src/code-toolbox/SandboxPythonCodeToolbox.js +358 -0
  35. package/src/code-toolbox/SandboxPythonCodeToolbox.js.map +1 -0
  36. package/src/code-toolbox/SandboxTsCodeToolbox.d.ts +5 -0
  37. package/src/code-toolbox/SandboxTsCodeToolbox.js +17 -0
  38. package/src/code-toolbox/SandboxTsCodeToolbox.js.map +1 -0
  39. package/src/errors/DaytonaError.d.ts +10 -0
  40. package/src/errors/DaytonaError.js +20 -0
  41. package/src/errors/DaytonaError.js.map +1 -0
  42. package/src/index.d.ts +15 -0
  43. package/src/index.js +32 -0
  44. package/src/index.js.map +1 -0
  45. package/src/types/Charts.d.ts +151 -0
  46. package/src/types/Charts.js +46 -0
  47. package/src/types/Charts.js.map +1 -0
  48. package/src/types/ExecuteResponse.d.ts +26 -0
  49. package/src/types/ExecuteResponse.js +7 -0
  50. package/src/types/ExecuteResponse.js.map +1 -0
  51. package/src/utils/ArtifactParser.d.ts +13 -0
  52. package/src/utils/ArtifactParser.js +55 -0
  53. package/src/utils/ArtifactParser.js.map +1 -0
  54. package/src/utils/Path.d.ts +1 -0
  55. package/src/utils/Path.js +61 -0
  56. package/src/utils/Path.js.map +1 -0
  57. package/src/utils/Stream.d.ts +13 -0
  58. package/src/utils/Stream.js +82 -0
  59. package/src/utils/Stream.js.map +1 -0
@@ -0,0 +1,270 @@
1
+ import { FileInfo, Match, ReplaceResult, SearchFilesResponse, ToolboxApi } from '@daytonaio/api-client';
2
+ /**
3
+ * Parameters for setting file permissions in the Sandbox.
4
+ *
5
+ * @interface
6
+ * @property {string} [mode] - File mode/permissions in octal format (e.g. "644")
7
+ * @property {string} [owner] - User owner of the file
8
+ * @property {string} [group] - Group owner of the file
9
+ *
10
+ * @example
11
+ * const permissions: FilePermissionsParams = {
12
+ * mode: '644',
13
+ * owner: 'daytona',
14
+ * group: 'users'
15
+ * };
16
+ */
17
+ export type FilePermissionsParams = {
18
+ /** Group owner of the file */
19
+ group?: string;
20
+ /** File mode/permissions in octal format (e.g. "644") */
21
+ mode?: string;
22
+ /** User owner of the file */
23
+ owner?: string;
24
+ };
25
+ /**
26
+ * Represents a file to be uploaded to the Sandbox.
27
+ *
28
+ * @interface
29
+ * @property {string | Buffer} source - File to upload. If a Buffer, it is interpreted as the file content which is loaded into memory.
30
+ * Make sure it fits into memory, otherwise use the local file path which content will be streamed to the Sandbox.
31
+ * @property {string} destination - Absolute destination path in the Sandbox. Relative paths are resolved based on the user's
32
+ * root directory.
33
+ */
34
+ export interface FileUpload {
35
+ source: string | Buffer;
36
+ destination: string;
37
+ }
38
+ /**
39
+ * Provides file system operations within a Sandbox.
40
+ *
41
+ * @class
42
+ */
43
+ export declare class FileSystem {
44
+ private readonly sandboxId;
45
+ private readonly toolboxApi;
46
+ private readonly getRootDir;
47
+ constructor(sandboxId: string, toolboxApi: ToolboxApi, getRootDir: () => Promise<string>);
48
+ /**
49
+ * Create a new directory in the Sandbox with specified permissions.
50
+ *
51
+ * @param {string} path - Path where the directory should be created. Relative paths are resolved based on the user's
52
+ * root directory.
53
+ * @param {string} mode - Directory permissions in octal format (e.g. "755")
54
+ * @returns {Promise<void>}
55
+ *
56
+ * @example
57
+ * // Create a directory with standard permissions
58
+ * await fs.createFolder('app/data', '755');
59
+ */
60
+ createFolder(path: string, mode: string): Promise<void>;
61
+ /**
62
+ * Deletes a file or directory from the Sandbox.
63
+ *
64
+ * @param {string} path - Path to the file or directory to delete. Relative paths are resolved based on the user's
65
+ * root directory.
66
+ * @returns {Promise<void>}
67
+ *
68
+ * @example
69
+ * // Delete a file
70
+ * await fs.deleteFile('app/temp.log');
71
+ */
72
+ deleteFile(path: string): Promise<void>;
73
+ /**
74
+ * Downloads a file from the Sandbox. This method loads the entire file into memory, so it is not recommended
75
+ * for downloading large files.
76
+ *
77
+ * @param {string} remotePath - Path to the file to download. Relative paths are resolved based on the user's
78
+ * root directory.
79
+ * @param {number} [timeout] - Timeout for the download operation in seconds. 0 means no timeout.
80
+ * Default is 30 minutes.
81
+ * @returns {Promise<Buffer>} The file contents as a Buffer.
82
+ *
83
+ * @example
84
+ * // Download and process a file
85
+ * const fileBuffer = await fs.downloadFile('tmp/data.json');
86
+ * console.log('File content:', fileBuffer.toString());
87
+ */
88
+ downloadFile(remotePath: string, timeout?: number): Promise<Buffer>;
89
+ /**
90
+ * Downloads a file from the Sandbox and saves it to a local file. This method uses streaming to download the file,
91
+ * so it is recommended for downloading larger files.
92
+ *
93
+ * @param {string} remotePath - Path to the file to download in the Sandbox. Relative paths are resolved based on the user's
94
+ * root directory.
95
+ * @param {string} localPath - Path to save the downloaded file.
96
+ * @param {number} [timeout] - Timeout for the download operation in seconds. 0 means no timeout.
97
+ * Default is 30 minutes.
98
+ * @returns {Promise<void>}
99
+ *
100
+ * @example
101
+ * // Download and save a file
102
+ * await fs.downloadFile('tmp/data.json', 'local_file.json');
103
+ */
104
+ downloadFile(remotePath: string, localPath: string, timeout?: number): Promise<void>;
105
+ /**
106
+ * Searches for text patterns within files in the Sandbox.
107
+ *
108
+ * @param {string} path - Directory to search in. Relative paths are resolved based on the user's
109
+ * root directory.
110
+ * @param {string} pattern - Search pattern
111
+ * @returns {Promise<Array<Match>>} Array of matches with file and line information
112
+ *
113
+ * @example
114
+ * // Find all TODO comments in TypeScript files
115
+ * const matches = await fs.findFiles('app/src', 'TODO:');
116
+ * matches.forEach(match => {
117
+ * console.log(`${match.file}:${match.line}: ${match.content}`);
118
+ * });
119
+ */
120
+ findFiles(path: string, pattern: string): Promise<Array<Match>>;
121
+ /**
122
+ * Retrieves detailed information about a file or directory.
123
+ *
124
+ * @param {string} path - Path to the file or directory. Relative paths are resolved based on the user's
125
+ * root directory.
126
+ * @returns {Promise<FileInfo>} Detailed file information including size, permissions, modification time
127
+ *
128
+ * @example
129
+ * // Get file details
130
+ * const info = await fs.getFileDetails('app/config.json');
131
+ * console.log(`Size: ${info.size}, Modified: ${info.modTime}`);
132
+ */
133
+ getFileDetails(path: string): Promise<FileInfo>;
134
+ /**
135
+ * Lists contents of a directory in the Sandbox.
136
+ *
137
+ * @param {string} path - Directory path to list. Relative paths are resolved based on the user's
138
+ * root directory.
139
+ * @returns {Promise<FileInfo[]>} Array of file and directory information
140
+ *
141
+ * @example
142
+ * // List directory contents
143
+ * const files = await fs.listFiles('app/src');
144
+ * files.forEach(file => {
145
+ * console.log(`${file.name} (${file.size} bytes)`);
146
+ * });
147
+ */
148
+ listFiles(path: string): Promise<FileInfo[]>;
149
+ /**
150
+ * Moves or renames a file or directory.
151
+ *
152
+ * @param {string} source - Source path. Relative paths are resolved based on the user's
153
+ * root directory.
154
+ * @param {string} destination - Destination path. Relative paths are resolved based on the user's
155
+ * root directory.
156
+ * @returns {Promise<void>}
157
+ *
158
+ * @example
159
+ * // Move a file to a new location
160
+ * await fs.moveFiles('app/temp/data.json', 'app/data/data.json');
161
+ */
162
+ moveFiles(source: string, destination: string): Promise<void>;
163
+ /**
164
+ * Replaces text content in multiple files.
165
+ *
166
+ * @param {string[]} files - Array of file paths to process. Relative paths are resolved based on the user's
167
+ * @param {string} pattern - Pattern to replace
168
+ * @param {string} newValue - Replacement text
169
+ * @returns {Promise<Array<ReplaceResult>>} Results of the replace operation for each file
170
+ *
171
+ * @example
172
+ * // Update version number across multiple files
173
+ * const results = await fs.replaceInFiles(
174
+ * ['app/package.json', 'app/version.ts'],
175
+ * '"version": "1.0.0"',
176
+ * '"version": "1.1.0"'
177
+ * );
178
+ */
179
+ replaceInFiles(files: string[], pattern: string, newValue: string): Promise<Array<ReplaceResult>>;
180
+ /**
181
+ * Searches for files and directories by name pattern in the Sandbox.
182
+ *
183
+ * @param {string} path - Directory to search in. Relative paths are resolved based on the user's
184
+ * @param {string} pattern - File name pattern (supports globs)
185
+ * @returns {Promise<SearchFilesResponse>} Search results with matching files
186
+ *
187
+ * @example
188
+ * // Find all TypeScript files
189
+ * const result = await fs.searchFiles('app', '*.ts');
190
+ * result.files.forEach(file => console.log(file));
191
+ */
192
+ searchFiles(path: string, pattern: string): Promise<SearchFilesResponse>;
193
+ /**
194
+ * Sets permissions and ownership for a file or directory.
195
+ *
196
+ * @param {string} path - Path to the file or directory. Relative paths are resolved based on the user's
197
+ * root directory.
198
+ * @param {FilePermissionsParams} permissions - Permission settings
199
+ * @returns {Promise<void>}
200
+ *
201
+ * @example
202
+ * // Set file permissions and ownership
203
+ * await fs.setFilePermissions('app/script.sh', {
204
+ * owner: 'daytona',
205
+ * group: 'users',
206
+ * mode: '755' // Execute permission for shell script
207
+ * });
208
+ */
209
+ setFilePermissions(path: string, permissions: FilePermissionsParams): Promise<void>;
210
+ /**
211
+ * Uploads a file to the Sandbox. This method loads the entire file into memory, so it is not recommended
212
+ * for uploading large files.
213
+ *
214
+ * @param {Buffer} file - Buffer of the file to upload.
215
+ * @param {string} remotePath - Destination path in the Sandbox. Relative paths are resolved based on the user's
216
+ * root directory.
217
+ * @param {number} [timeout] - Timeout for the upload operation in seconds. 0 means no timeout.
218
+ * Default is 30 minutes.
219
+ * @returns {Promise<void>}
220
+ *
221
+ * @example
222
+ * // Upload a configuration file
223
+ * await fs.uploadFile(Buffer.from('{"setting": "value"}'), 'tmp/config.json');
224
+ */
225
+ uploadFile(file: Buffer, remotePath: string, timeout?: number): Promise<void>;
226
+ /**
227
+ * Uploads a file from the local file system to the Sandbox. This method uses streaming to upload the file,
228
+ * so it is recommended for uploading larger files.
229
+ *
230
+ * @param {string} localPath - Path to the local file to upload.
231
+ * @param {string} remotePath - Destination path in the Sandbox. Relative paths are resolved based on the user's
232
+ * root directory.
233
+ * @param {number} [timeout] - Timeout for the upload operation in seconds. 0 means no timeout.
234
+ * Default is 30 minutes.
235
+ * @returns {Promise<void>}
236
+ *
237
+ * @example
238
+ * // Upload a local file
239
+ * await fs.uploadFile('local_file.txt', 'tmp/file.txt');
240
+ */
241
+ uploadFile(localPath: string, remotePath: string, timeout?: number): Promise<void>;
242
+ /**
243
+ * Uploads multiple files to the Sandbox. If files already exist at the destination paths,
244
+ * they will be overwritten.
245
+ *
246
+ * @param {FileUpload[]} files - Array of files to upload.
247
+ * @param {number} [timeout] - Timeout for the upload operation in seconds. 0 means no timeout.
248
+ * Default is 30 minutes.
249
+ * @returns {Promise<void>}
250
+ *
251
+ * @example
252
+ * // Upload multiple text files
253
+ * const files = [
254
+ * {
255
+ * source: Buffer.from('Content of file 1'),
256
+ * destination: '/tmp/file1.txt'
257
+ * },
258
+ * {
259
+ * source: 'app/data/file2.txt',
260
+ * destination: '/tmp/file2.txt'
261
+ * },
262
+ * {
263
+ * source: Buffer.from('{"key": "value"}'),
264
+ * destination: '/tmp/config.json'
265
+ * }
266
+ * ];
267
+ * await fs.uploadFiles(files);
268
+ */
269
+ uploadFiles(files: FileUpload[], timeout?: number): Promise<void>;
270
+ }
@@ -0,0 +1,302 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2025 Daytona Platforms Inc.
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ var desc = Object.getOwnPropertyDescriptor(m, k);
9
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
+ desc = { enumerable: true, get: function() { return m[k]; } };
11
+ }
12
+ Object.defineProperty(o, k2, desc);
13
+ }) : (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ o[k2] = m[k];
16
+ }));
17
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
18
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
19
+ }) : function(o, v) {
20
+ o["default"] = v;
21
+ });
22
+ var __importStar = (this && this.__importStar) || (function () {
23
+ var ownKeys = function(o) {
24
+ ownKeys = Object.getOwnPropertyNames || function (o) {
25
+ var ar = [];
26
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
27
+ return ar;
28
+ };
29
+ return ownKeys(o);
30
+ };
31
+ return function (mod) {
32
+ if (mod && mod.__esModule) return mod;
33
+ var result = {};
34
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
35
+ __setModuleDefault(result, mod);
36
+ return result;
37
+ };
38
+ })();
39
+ var __importDefault = (this && this.__importDefault) || function (mod) {
40
+ return (mod && mod.__esModule) ? mod : { "default": mod };
41
+ };
42
+ Object.defineProperty(exports, "__esModule", { value: true });
43
+ exports.FileSystem = void 0;
44
+ const Path_1 = require("./utils/Path");
45
+ const fs = __importStar(require("fs"));
46
+ const stream_1 = require("stream");
47
+ const form_data_1 = __importDefault(require("form-data"));
48
+ /**
49
+ * Provides file system operations within a Sandbox.
50
+ *
51
+ * @class
52
+ */
53
+ class FileSystem {
54
+ sandboxId;
55
+ toolboxApi;
56
+ getRootDir;
57
+ constructor(sandboxId, toolboxApi, getRootDir) {
58
+ this.sandboxId = sandboxId;
59
+ this.toolboxApi = toolboxApi;
60
+ this.getRootDir = getRootDir;
61
+ }
62
+ /**
63
+ * Create a new directory in the Sandbox with specified permissions.
64
+ *
65
+ * @param {string} path - Path where the directory should be created. Relative paths are resolved based on the user's
66
+ * root directory.
67
+ * @param {string} mode - Directory permissions in octal format (e.g. "755")
68
+ * @returns {Promise<void>}
69
+ *
70
+ * @example
71
+ * // Create a directory with standard permissions
72
+ * await fs.createFolder('app/data', '755');
73
+ */
74
+ async createFolder(path, mode) {
75
+ const response = await this.toolboxApi.createFolder(this.sandboxId, (0, Path_1.prefixRelativePath)(await this.getRootDir(), path), mode);
76
+ return response.data;
77
+ }
78
+ /**
79
+ * Deletes a file or directory from the Sandbox.
80
+ *
81
+ * @param {string} path - Path to the file or directory to delete. Relative paths are resolved based on the user's
82
+ * root directory.
83
+ * @returns {Promise<void>}
84
+ *
85
+ * @example
86
+ * // Delete a file
87
+ * await fs.deleteFile('app/temp.log');
88
+ */
89
+ async deleteFile(path) {
90
+ const response = await this.toolboxApi.deleteFile(this.sandboxId, (0, Path_1.prefixRelativePath)(await this.getRootDir(), path));
91
+ return response.data;
92
+ }
93
+ async downloadFile(src, dst, timeout = 30 * 60) {
94
+ const remotePath = (0, Path_1.prefixRelativePath)(await this.getRootDir(), src);
95
+ if (typeof dst !== 'string') {
96
+ timeout = dst;
97
+ const { data } = await this.toolboxApi.downloadFile(this.sandboxId, remotePath, undefined, {
98
+ responseType: 'arraybuffer',
99
+ timeout: timeout * 1000,
100
+ });
101
+ if (Buffer.isBuffer(data)) {
102
+ return data;
103
+ }
104
+ if (data instanceof ArrayBuffer) {
105
+ return Buffer.from(data);
106
+ }
107
+ return Buffer.from(await data.arrayBuffer());
108
+ }
109
+ const response = await this.toolboxApi.downloadFile(this.sandboxId, remotePath, undefined, {
110
+ responseType: 'stream',
111
+ timeout: timeout * 1000,
112
+ });
113
+ const writer = fs.createWriteStream(dst);
114
+ response.data.pipe(writer);
115
+ await new Promise((resolve, reject) => {
116
+ writer.on('finish', () => resolve());
117
+ writer.on('error', (err) => reject(err));
118
+ });
119
+ }
120
+ /**
121
+ * Searches for text patterns within files in the Sandbox.
122
+ *
123
+ * @param {string} path - Directory to search in. Relative paths are resolved based on the user's
124
+ * root directory.
125
+ * @param {string} pattern - Search pattern
126
+ * @returns {Promise<Array<Match>>} Array of matches with file and line information
127
+ *
128
+ * @example
129
+ * // Find all TODO comments in TypeScript files
130
+ * const matches = await fs.findFiles('app/src', 'TODO:');
131
+ * matches.forEach(match => {
132
+ * console.log(`${match.file}:${match.line}: ${match.content}`);
133
+ * });
134
+ */
135
+ async findFiles(path, pattern) {
136
+ const response = await this.toolboxApi.findInFiles(this.sandboxId, (0, Path_1.prefixRelativePath)(await this.getRootDir(), path), pattern);
137
+ return response.data;
138
+ }
139
+ /**
140
+ * Retrieves detailed information about a file or directory.
141
+ *
142
+ * @param {string} path - Path to the file or directory. Relative paths are resolved based on the user's
143
+ * root directory.
144
+ * @returns {Promise<FileInfo>} Detailed file information including size, permissions, modification time
145
+ *
146
+ * @example
147
+ * // Get file details
148
+ * const info = await fs.getFileDetails('app/config.json');
149
+ * console.log(`Size: ${info.size}, Modified: ${info.modTime}`);
150
+ */
151
+ async getFileDetails(path) {
152
+ const response = await this.toolboxApi.getFileInfo(this.sandboxId, (0, Path_1.prefixRelativePath)(await this.getRootDir(), path));
153
+ return response.data;
154
+ }
155
+ /**
156
+ * Lists contents of a directory in the Sandbox.
157
+ *
158
+ * @param {string} path - Directory path to list. Relative paths are resolved based on the user's
159
+ * root directory.
160
+ * @returns {Promise<FileInfo[]>} Array of file and directory information
161
+ *
162
+ * @example
163
+ * // List directory contents
164
+ * const files = await fs.listFiles('app/src');
165
+ * files.forEach(file => {
166
+ * console.log(`${file.name} (${file.size} bytes)`);
167
+ * });
168
+ */
169
+ async listFiles(path) {
170
+ const response = await this.toolboxApi.listFiles(this.sandboxId, undefined, (0, Path_1.prefixRelativePath)(await this.getRootDir(), path));
171
+ return response.data;
172
+ }
173
+ /**
174
+ * Moves or renames a file or directory.
175
+ *
176
+ * @param {string} source - Source path. Relative paths are resolved based on the user's
177
+ * root directory.
178
+ * @param {string} destination - Destination path. Relative paths are resolved based on the user's
179
+ * root directory.
180
+ * @returns {Promise<void>}
181
+ *
182
+ * @example
183
+ * // Move a file to a new location
184
+ * await fs.moveFiles('app/temp/data.json', 'app/data/data.json');
185
+ */
186
+ async moveFiles(source, destination) {
187
+ const response = await this.toolboxApi.moveFile(this.sandboxId, (0, Path_1.prefixRelativePath)(await this.getRootDir(), source), (0, Path_1.prefixRelativePath)(await this.getRootDir(), destination));
188
+ return response.data;
189
+ }
190
+ /**
191
+ * Replaces text content in multiple files.
192
+ *
193
+ * @param {string[]} files - Array of file paths to process. Relative paths are resolved based on the user's
194
+ * @param {string} pattern - Pattern to replace
195
+ * @param {string} newValue - Replacement text
196
+ * @returns {Promise<Array<ReplaceResult>>} Results of the replace operation for each file
197
+ *
198
+ * @example
199
+ * // Update version number across multiple files
200
+ * const results = await fs.replaceInFiles(
201
+ * ['app/package.json', 'app/version.ts'],
202
+ * '"version": "1.0.0"',
203
+ * '"version": "1.1.0"'
204
+ * );
205
+ */
206
+ async replaceInFiles(files, pattern, newValue) {
207
+ for (let i = 0; i < files.length; i++) {
208
+ files[i] = (0, Path_1.prefixRelativePath)(await this.getRootDir(), files[i]);
209
+ }
210
+ const replaceRequest = {
211
+ files,
212
+ newValue,
213
+ pattern,
214
+ };
215
+ const response = await this.toolboxApi.replaceInFiles(this.sandboxId, replaceRequest);
216
+ return response.data;
217
+ }
218
+ /**
219
+ * Searches for files and directories by name pattern in the Sandbox.
220
+ *
221
+ * @param {string} path - Directory to search in. Relative paths are resolved based on the user's
222
+ * @param {string} pattern - File name pattern (supports globs)
223
+ * @returns {Promise<SearchFilesResponse>} Search results with matching files
224
+ *
225
+ * @example
226
+ * // Find all TypeScript files
227
+ * const result = await fs.searchFiles('app', '*.ts');
228
+ * result.files.forEach(file => console.log(file));
229
+ */
230
+ async searchFiles(path, pattern) {
231
+ const response = await this.toolboxApi.searchFiles(this.sandboxId, (0, Path_1.prefixRelativePath)(await this.getRootDir(), path), pattern);
232
+ return response.data;
233
+ }
234
+ /**
235
+ * Sets permissions and ownership for a file or directory.
236
+ *
237
+ * @param {string} path - Path to the file or directory. Relative paths are resolved based on the user's
238
+ * root directory.
239
+ * @param {FilePermissionsParams} permissions - Permission settings
240
+ * @returns {Promise<void>}
241
+ *
242
+ * @example
243
+ * // Set file permissions and ownership
244
+ * await fs.setFilePermissions('app/script.sh', {
245
+ * owner: 'daytona',
246
+ * group: 'users',
247
+ * mode: '755' // Execute permission for shell script
248
+ * });
249
+ */
250
+ async setFilePermissions(path, permissions) {
251
+ const response = await this.toolboxApi.setFilePermissions(this.sandboxId, (0, Path_1.prefixRelativePath)(await this.getRootDir(), path), undefined, permissions.owner, permissions.group, permissions.mode);
252
+ return response.data;
253
+ }
254
+ async uploadFile(src, dst, timeout = 30 * 60) {
255
+ await this.uploadFiles([{ source: src, destination: dst }], timeout);
256
+ }
257
+ /**
258
+ * Uploads multiple files to the Sandbox. If files already exist at the destination paths,
259
+ * they will be overwritten.
260
+ *
261
+ * @param {FileUpload[]} files - Array of files to upload.
262
+ * @param {number} [timeout] - Timeout for the upload operation in seconds. 0 means no timeout.
263
+ * Default is 30 minutes.
264
+ * @returns {Promise<void>}
265
+ *
266
+ * @example
267
+ * // Upload multiple text files
268
+ * const files = [
269
+ * {
270
+ * source: Buffer.from('Content of file 1'),
271
+ * destination: '/tmp/file1.txt'
272
+ * },
273
+ * {
274
+ * source: 'app/data/file2.txt',
275
+ * destination: '/tmp/file2.txt'
276
+ * },
277
+ * {
278
+ * source: Buffer.from('{"key": "value"}'),
279
+ * destination: '/tmp/config.json'
280
+ * }
281
+ * ];
282
+ * await fs.uploadFiles(files);
283
+ */
284
+ async uploadFiles(files, timeout = 30 * 60) {
285
+ const form = new form_data_1.default();
286
+ const rootDir = await this.getRootDir();
287
+ files.forEach(({ source, destination }, i) => {
288
+ const dst = (0, Path_1.prefixRelativePath)(rootDir, destination);
289
+ form.append(`files[${i}].path`, dst);
290
+ const stream = typeof source === 'string' ? fs.createReadStream(source) : stream_1.Readable.from(source);
291
+ // the third arg sets filename in Content-Disposition
292
+ form.append(`files[${i}].file`, stream, dst);
293
+ });
294
+ await this.toolboxApi.uploadFiles(this.sandboxId, undefined, {
295
+ data: form,
296
+ maxRedirects: 0,
297
+ timeout: timeout * 1000,
298
+ });
299
+ }
300
+ }
301
+ exports.FileSystem = FileSystem;
302
+ //# sourceMappingURL=FileSystem.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FileSystem.js","sourceRoot":"","sources":["../../../../libs/sdk-typescript/src/FileSystem.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGH,uCAAiD;AACjD,uCAAwB;AACxB,mCAAiC;AACjC,0DAAgC;AAwChC;;;;GAIG;AACH,MAAa,UAAU;IAEF;IACA;IACA;IAHnB,YACmB,SAAiB,EACjB,UAAsB,EACtB,UAAiC;QAFjC,cAAS,GAAT,SAAS,CAAQ;QACjB,eAAU,GAAV,UAAU,CAAY;QACtB,eAAU,GAAV,UAAU,CAAuB;IACjD,CAAC;IAEJ;;;;;;;;;;;OAWG;IACI,KAAK,CAAC,YAAY,CAAC,IAAY,EAAE,IAAY;QAClD,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,YAAY,CACjD,IAAI,CAAC,SAAS,EACd,IAAA,yBAAkB,EAAC,MAAM,IAAI,CA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