@daytonaio/sdk 0.9.0 → 0.10.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.
Files changed (222) hide show
  1. package/README.md +4 -4
  2. package/dist/Daytona.d.ts +243 -47
  3. package/dist/Daytona.js +278 -60
  4. package/dist/FileSystem.d.ts +183 -32
  5. package/dist/FileSystem.js +168 -28
  6. package/dist/Git.d.ts +178 -30
  7. package/dist/Git.js +178 -30
  8. package/dist/LspServer.d.ts +170 -22
  9. package/dist/LspServer.js +162 -18
  10. package/dist/Process.d.ts +187 -37
  11. package/dist/Process.js +185 -44
  12. package/dist/Workspace.d.ts +257 -35
  13. package/dist/Workspace.js +255 -48
  14. package/dist/code-toolbox/WorkspacePythonCodeToolbox.d.ts +2 -1
  15. package/dist/code-toolbox/WorkspacePythonCodeToolbox.js +4 -2
  16. package/dist/code-toolbox/WorkspaceTsCodeToolbox.d.ts +2 -1
  17. package/dist/code-toolbox/WorkspaceTsCodeToolbox.js +4 -2
  18. package/dist/errors/DaytonaError.d.ts +8 -0
  19. package/dist/errors/DaytonaError.js +12 -0
  20. package/dist/index.d.ts +4 -0
  21. package/dist/index.js +12 -1
  22. package/dist/utils/Axios.d.ts +6 -0
  23. package/dist/utils/Axios.js +28 -0
  24. package/dist/utils/errors.d.ts +10 -0
  25. package/dist/utils/errors.js +36 -0
  26. package/dist/utils/timeout.d.ts +35 -0
  27. package/dist/utils/timeout.js +73 -0
  28. package/package.json +11 -10
  29. package/dist/client/apis/ApiKeyApi.d.ts +0 -54
  30. package/dist/client/apis/ApiKeyApi.js +0 -135
  31. package/dist/client/apis/BuildApi.d.ts +0 -95
  32. package/dist/client/apis/BuildApi.js +0 -228
  33. package/dist/client/apis/ContainerRegistryApi.d.ts +0 -68
  34. package/dist/client/apis/ContainerRegistryApi.js +0 -163
  35. package/dist/client/apis/DefaultApi.d.ts +0 -31
  36. package/dist/client/apis/DefaultApi.js +0 -72
  37. package/dist/client/apis/GitProviderApi.d.ts +0 -197
  38. package/dist/client/apis/GitProviderApi.js +0 -477
  39. package/dist/client/apis/PrebuildApi.d.ts +0 -97
  40. package/dist/client/apis/PrebuildApi.js +0 -241
  41. package/dist/client/apis/ProfileApi.d.ts +0 -51
  42. package/dist/client/apis/ProfileApi.js +0 -128
  43. package/dist/client/apis/ProjectConfigApi.d.ts +0 -94
  44. package/dist/client/apis/ProjectConfigApi.js +0 -220
  45. package/dist/client/apis/ProviderApi.d.ts +0 -71
  46. package/dist/client/apis/ProviderApi.js +0 -160
  47. package/dist/client/apis/SampleApi.d.ts +0 -28
  48. package/dist/client/apis/SampleApi.js +0 -73
  49. package/dist/client/apis/ServerApi.d.ts +0 -61
  50. package/dist/client/apis/ServerApi.js +0 -156
  51. package/dist/client/apis/TargetApi.d.ts +0 -67
  52. package/dist/client/apis/TargetApi.js +0 -159
  53. package/dist/client/apis/WorkspaceApi.d.ts +0 -141
  54. package/dist/client/apis/WorkspaceApi.js +0 -330
  55. package/dist/client/apis/WorkspaceToolboxApi.d.ts +0 -464
  56. package/dist/client/apis/WorkspaceToolboxApi.js +0 -1248
  57. package/dist/client/apis/index.d.ts +0 -14
  58. package/dist/client/apis/index.js +0 -32
  59. package/dist/client/index.d.ts +0 -3
  60. package/dist/client/index.js +0 -21
  61. package/dist/client/models/ApiKey.d.ts +0 -45
  62. package/dist/client/models/ApiKey.js +0 -60
  63. package/dist/client/models/ApikeyApiKeyType.d.ts +0 -26
  64. package/dist/client/models/ApikeyApiKeyType.js +0 -52
  65. package/dist/client/models/Build.d.ts +0 -98
  66. package/dist/client/models/Build.js +0 -91
  67. package/dist/client/models/BuildBuildState.d.ts +0 -31
  68. package/dist/client/models/BuildBuildState.js +0 -57
  69. package/dist/client/models/BuildConfig.d.ts +0 -40
  70. package/dist/client/models/BuildConfig.js +0 -57
  71. package/dist/client/models/CachedBuild.d.ts +0 -38
  72. package/dist/client/models/CachedBuild.js +0 -55
  73. package/dist/client/models/CloneTarget.d.ts +0 -25
  74. package/dist/client/models/CloneTarget.js +0 -51
  75. package/dist/client/models/CompletionContext.d.ts +0 -38
  76. package/dist/client/models/CompletionContext.js +0 -53
  77. package/dist/client/models/CompletionItem.d.ts +0 -68
  78. package/dist/client/models/CompletionItem.js +0 -63
  79. package/dist/client/models/CompletionList.d.ts +0 -39
  80. package/dist/client/models/CompletionList.js +0 -56
  81. package/dist/client/models/ContainerConfig.d.ts +0 -38
  82. package/dist/client/models/ContainerConfig.js +0 -55
  83. package/dist/client/models/ContainerRegistry.d.ts +0 -44
  84. package/dist/client/models/ContainerRegistry.js +0 -59
  85. package/dist/client/models/CreateBuildDTO.d.ts +0 -52
  86. package/dist/client/models/CreateBuildDTO.js +0 -62
  87. package/dist/client/models/CreatePrebuildDTO.d.ts +0 -56
  88. package/dist/client/models/CreatePrebuildDTO.js +0 -59
  89. package/dist/client/models/CreateProjectConfigDTO.d.ts +0 -71
  90. package/dist/client/models/CreateProjectConfigDTO.js +0 -72
  91. package/dist/client/models/CreateProjectDTO.d.ts +0 -72
  92. package/dist/client/models/CreateProjectDTO.js +0 -73
  93. package/dist/client/models/CreateProjectSourceDTO.d.ts +0 -33
  94. package/dist/client/models/CreateProjectSourceDTO.js +0 -52
  95. package/dist/client/models/CreateProviderTargetDTO.d.ts +0 -45
  96. package/dist/client/models/CreateProviderTargetDTO.js +0 -60
  97. package/dist/client/models/CreateWorkspaceDTO.d.ts +0 -51
  98. package/dist/client/models/CreateWorkspaceDTO.js +0 -64
  99. package/dist/client/models/DevcontainerConfig.d.ts +0 -32
  100. package/dist/client/models/DevcontainerConfig.js +0 -51
  101. package/dist/client/models/ExecuteRequest.d.ts +0 -38
  102. package/dist/client/models/ExecuteRequest.js +0 -53
  103. package/dist/client/models/ExecuteResponse.d.ts +0 -38
  104. package/dist/client/models/ExecuteResponse.js +0 -55
  105. package/dist/client/models/FRPSConfig.d.ts +0 -44
  106. package/dist/client/models/FRPSConfig.js +0 -59
  107. package/dist/client/models/FileInfo.d.ts +0 -74
  108. package/dist/client/models/FileInfo.js +0 -79
  109. package/dist/client/models/FileStatus.d.ts +0 -51
  110. package/dist/client/models/FileStatus.js +0 -64
  111. package/dist/client/models/GetRepositoryContext.d.ts +0 -80
  112. package/dist/client/models/GetRepositoryContext.js +0 -67
  113. package/dist/client/models/GitAddRequest.d.ts +0 -38
  114. package/dist/client/models/GitAddRequest.js +0 -55
  115. package/dist/client/models/GitBranch.d.ts +0 -38
  116. package/dist/client/models/GitBranch.js +0 -55
  117. package/dist/client/models/GitBranchRequest.d.ts +0 -38
  118. package/dist/client/models/GitBranchRequest.js +0 -55
  119. package/dist/client/models/GitCloneRequest.d.ts +0 -62
  120. package/dist/client/models/GitCloneRequest.js +0 -63
  121. package/dist/client/models/GitCommitInfo.d.ts +0 -56
  122. package/dist/client/models/GitCommitInfo.js +0 -67
  123. package/dist/client/models/GitCommitRequest.d.ts +0 -50
  124. package/dist/client/models/GitCommitRequest.js +0 -63
  125. package/dist/client/models/GitCommitResponse.d.ts +0 -32
  126. package/dist/client/models/GitCommitResponse.js +0 -51
  127. package/dist/client/models/GitNamespace.d.ts +0 -38
  128. package/dist/client/models/GitNamespace.js +0 -55
  129. package/dist/client/models/GitProvider.d.ts +0 -75
  130. package/dist/client/models/GitProvider.js +0 -76
  131. package/dist/client/models/GitPullRequest.d.ts +0 -68
  132. package/dist/client/models/GitPullRequest.js +0 -75
  133. package/dist/client/models/GitRepoRequest.d.ts +0 -44
  134. package/dist/client/models/GitRepoRequest.js +0 -55
  135. package/dist/client/models/GitRepository.d.ts +0 -87
  136. package/dist/client/models/GitRepository.js +0 -84
  137. package/dist/client/models/GitStatus.d.ts +0 -57
  138. package/dist/client/models/GitStatus.js +0 -62
  139. package/dist/client/models/GitUser.d.ts +0 -50
  140. package/dist/client/models/GitUser.js +0 -63
  141. package/dist/client/models/InstallProviderRequest.d.ts +0 -40
  142. package/dist/client/models/InstallProviderRequest.js +0 -55
  143. package/dist/client/models/ListBranchResponse.d.ts +0 -32
  144. package/dist/client/models/ListBranchResponse.js +0 -51
  145. package/dist/client/models/LogFileConfig.d.ts +0 -62
  146. package/dist/client/models/LogFileConfig.js +0 -67
  147. package/dist/client/models/LspCompletionParams.d.ts +0 -58
  148. package/dist/client/models/LspCompletionParams.js +0 -69
  149. package/dist/client/models/LspDocumentRequest.d.ts +0 -44
  150. package/dist/client/models/LspDocumentRequest.js +0 -59
  151. package/dist/client/models/LspLocation.d.ts +0 -39
  152. package/dist/client/models/LspLocation.js +0 -56
  153. package/dist/client/models/LspPosition.d.ts +0 -38
  154. package/dist/client/models/LspPosition.js +0 -55
  155. package/dist/client/models/LspRange.d.ts +0 -39
  156. package/dist/client/models/LspRange.js +0 -56
  157. package/dist/client/models/LspServerRequest.d.ts +0 -38
  158. package/dist/client/models/LspServerRequest.js +0 -55
  159. package/dist/client/models/LspSymbol.d.ts +0 -45
  160. package/dist/client/models/LspSymbol.js +0 -60
  161. package/dist/client/models/Match.d.ts +0 -44
  162. package/dist/client/models/Match.js +0 -59
  163. package/dist/client/models/NetworkKey.d.ts +0 -32
  164. package/dist/client/models/NetworkKey.js +0 -51
  165. package/dist/client/models/Position.d.ts +0 -38
  166. package/dist/client/models/Position.js +0 -55
  167. package/dist/client/models/PrebuildConfig.d.ts +0 -56
  168. package/dist/client/models/PrebuildConfig.js +0 -67
  169. package/dist/client/models/PrebuildDTO.d.ts +0 -62
  170. package/dist/client/models/PrebuildDTO.js +0 -68
  171. package/dist/client/models/ProfileData.d.ts +0 -34
  172. package/dist/client/models/ProfileData.js +0 -51
  173. package/dist/client/models/Project.d.ts +0 -91
  174. package/dist/client/models/Project.js +0 -88
  175. package/dist/client/models/ProjectConfig.d.ts +0 -84
  176. package/dist/client/models/ProjectConfig.js +0 -87
  177. package/dist/client/models/ProjectDirResponse.d.ts +0 -32
  178. package/dist/client/models/ProjectDirResponse.js +0 -49
  179. package/dist/client/models/ProjectInfo.d.ts +0 -56
  180. package/dist/client/models/ProjectInfo.js +0 -65
  181. package/dist/client/models/ProjectState.d.ts +0 -45
  182. package/dist/client/models/ProjectState.js +0 -60
  183. package/dist/client/models/Provider.d.ts +0 -44
  184. package/dist/client/models/Provider.js +0 -57
  185. package/dist/client/models/ProviderProviderInfo.d.ts +0 -44
  186. package/dist/client/models/ProviderProviderInfo.js +0 -57
  187. package/dist/client/models/ProviderProviderTargetProperty.d.ts +0 -72
  188. package/dist/client/models/ProviderProviderTargetProperty.js +0 -64
  189. package/dist/client/models/ProviderProviderTargetPropertyType.d.ts +0 -29
  190. package/dist/client/models/ProviderProviderTargetPropertyType.js +0 -55
  191. package/dist/client/models/ProviderTarget.d.ts +0 -51
  192. package/dist/client/models/ProviderTarget.js +0 -64
  193. package/dist/client/models/ReplaceRequest.d.ts +0 -44
  194. package/dist/client/models/ReplaceRequest.js +0 -59
  195. package/dist/client/models/ReplaceResult.d.ts +0 -44
  196. package/dist/client/models/ReplaceResult.js +0 -53
  197. package/dist/client/models/RepositoryUrl.d.ts +0 -32
  198. package/dist/client/models/RepositoryUrl.js +0 -51
  199. package/dist/client/models/Sample.d.ts +0 -44
  200. package/dist/client/models/Sample.js +0 -59
  201. package/dist/client/models/SearchFilesResponse.d.ts +0 -32
  202. package/dist/client/models/SearchFilesResponse.js +0 -51
  203. package/dist/client/models/ServerConfig.d.ts +0 -130
  204. package/dist/client/models/ServerConfig.js +0 -119
  205. package/dist/client/models/SetGitProviderConfig.d.ts +0 -75
  206. package/dist/client/models/SetGitProviderConfig.js +0 -70
  207. package/dist/client/models/SetProjectState.d.ts +0 -39
  208. package/dist/client/models/SetProjectState.js +0 -56
  209. package/dist/client/models/SigningMethod.d.ts +0 -25
  210. package/dist/client/models/SigningMethod.js +0 -51
  211. package/dist/client/models/Status.d.ts +0 -31
  212. package/dist/client/models/Status.js +0 -57
  213. package/dist/client/models/Workspace.d.ts +0 -51
  214. package/dist/client/models/Workspace.js +0 -64
  215. package/dist/client/models/WorkspaceDTO.d.ts +0 -58
  216. package/dist/client/models/WorkspaceDTO.js +0 -67
  217. package/dist/client/models/WorkspaceInfo.d.ts +0 -45
  218. package/dist/client/models/WorkspaceInfo.js +0 -58
  219. package/dist/client/models/index.d.ts +0 -79
  220. package/dist/client/models/index.js +0 -97
  221. package/dist/client/runtime.d.ts +0 -182
  222. package/dist/client/runtime.js +0 -340
@@ -1,9 +1,84 @@
1
- import { FileInfo, Match, ReplaceResult, SearchFilesResponse, Workspace as WorkspaceInstance, ToolboxApi } from '@daytonaio/api-client';
2
1
  /**
3
- * Parameters for setting file permissions
2
+ * The Daytona SDK provides comprehensive file system operations through the `fs` module in Sandboxes.
3
+ * You can perform various operations like listing files, creating directories, reading and writing files, and more.
4
+ * This guide covers all available file system operations and best practices.
5
+ *
6
+ * @module FileSystem
7
+ *
8
+ * @example
9
+ * // Basic file operations
10
+ * // Create a workspace
11
+ * const workspace = await daytona.create();
12
+ *
13
+ * // Create a directory
14
+ * await workspace.fs.createFolder('/workspace/data', '755');
15
+ *
16
+ * // Upload a file
17
+ * const fileContent = new File(['content'], 'local_file.txt');
18
+ * await workspace.fs.uploadFile('/workspace/data/file.txt', fileContent);
19
+ *
20
+ * // List directory contents
21
+ * const files = await workspace.fs.listFiles('/workspace');
22
+ * files.forEach(file => {
23
+ * console.log(`Name: ${file.name}`);
24
+ * console.log(`Is directory: ${file.isDir}`);
25
+ * console.log(`Size: ${file.size}`);
26
+ * console.log(`Modified: ${file.modTime}`);
27
+ * });
28
+ *
29
+ * // Search file contents
30
+ * const matches = await workspace.fs.findFiles(
31
+ * '/workspace/src',
32
+ * 'text-of-interest'
33
+ * );
34
+ * matches.forEach(match => {
35
+ * console.log(`Absolute file path: ${match.file}`);
36
+ * console.log(`Line number: ${match.line}`);
37
+ * console.log(`Line content: ${match.content}\n`);
38
+ * });
39
+ *
40
+ * @example
41
+ * // File manipulation
42
+ * // Move files
43
+ * await workspace.fs.moveFiles(
44
+ * '/workspace/data/old.txt',
45
+ * '/workspace/data/new.txt'
46
+ * );
47
+ *
48
+ * // Replace text in files
49
+ * const results = await workspace.fs.replaceInFiles(
50
+ * ['/workspace/data/new.txt'],
51
+ * 'old_version',
52
+ * 'new_version'
53
+ * );
54
+ *
55
+ * // Set permissions
56
+ * await workspace.fs.setFilePermissions(
57
+ * '/workspace/data/script.sh',
58
+ * {
59
+ * mode: '755',
60
+ * owner: 'daytona'
61
+ * }
62
+ * );
63
+ */
64
+ import { FileInfo, Match, ReplaceResult, SearchFilesResponse, ToolboxApi } from '@daytonaio/api-client';
65
+ import { WorkspaceInstance } from './Workspace';
66
+ /**
67
+ * Parameters for setting file permissions in the Sandbox.
68
+ *
4
69
  * @interface FilePermissionsParams
70
+ * @property {string} [mode] - File mode/permissions in octal format (e.g. "644")
71
+ * @property {string} [owner] - User owner of the file
72
+ * @property {string} [group] - Group owner of the file
73
+ *
74
+ * @example
75
+ * const permissions: FilePermissionsParams = {
76
+ * mode: '644',
77
+ * owner: 'daytona',
78
+ * group: 'users'
79
+ * };
5
80
  */
6
- type FilePermissionsParams = {
81
+ export type FilePermissionsParams = {
7
82
  /** Group owner of the file */
8
83
  group?: string;
9
84
  /** File mode/permissions in octal format (e.g. "644") */
@@ -12,86 +87,162 @@ type FilePermissionsParams = {
12
87
  owner?: string;
13
88
  };
14
89
  /**
15
- * Provides file system operations within a workspace
16
- * @class FileSystem
90
+ * Provides file system operations within a Sandbox.
91
+ *
92
+ * This class implements a high-level interface to file system operations that can
93
+ * be performed within a Daytona Sandbox. It supports common operations like
94
+ * creating, deleting, and moving files, as well as searching file contents and
95
+ * managing permissions.
17
96
  */
18
97
  export declare class FileSystem {
19
98
  private readonly instance;
20
99
  private readonly toolboxApi;
21
100
  constructor(instance: WorkspaceInstance, toolboxApi: ToolboxApi);
22
101
  /**
23
- * Creates a new folder in the workspace
24
- * @param {string} path - Path where the folder should be created
25
- * @param {string} mode - Folder permissions in octal format
102
+ * Create a new directory in the Sandbox with specified permissions.
103
+ *
104
+ * @param {string} path - Path where the directory should be created
105
+ * @param {string} mode - Directory permissions in octal format (e.g. "755")
26
106
  * @returns {Promise<void>}
107
+ *
108
+ * @example
109
+ * // Create a directory with standard permissions
110
+ * await fs.createFolder('/app/data', '755');
27
111
  */
28
112
  createFolder(path: string, mode: string): Promise<void>;
29
113
  /**
30
- * Deletes a file from the workspace
31
- * @param {string} path - Path to the file to delete
114
+ * Deletes a file or directory from the Sandbox.
115
+ *
116
+ * @param {string} path - Path to the file or directory to delete
32
117
  * @returns {Promise<void>}
118
+ *
119
+ * @example
120
+ * // Delete a file
121
+ * await fs.deleteFile('/app/temp.log');
33
122
  */
34
123
  deleteFile(path: string): Promise<void>;
35
124
  /**
36
- * Downloads a file from the workspace
125
+ * Downloads a file from the Sandbox.
126
+ *
37
127
  * @param {string} path - Path to the file to download
38
128
  * @returns {Promise<Blob>} The file contents as a Blob
129
+ *
130
+ * @example
131
+ * // Download and process a file
132
+ * const fileBlob = await fs.downloadFile('/app/data.json');
133
+ * console.log('File content:', fileBlob.toString());
39
134
  */
40
135
  downloadFile(path: string): Promise<Blob>;
41
136
  /**
42
- * Searches for files matching a pattern
137
+ * Searches for text patterns within files in the Sandbox.
138
+ *
43
139
  * @param {string} path - Directory to search in
44
140
  * @param {string} pattern - Search pattern
45
- * @returns {Promise<Array<Match>>} Array of matching files
141
+ * @returns {Promise<Array<Match>>} Array of matches with file and line information
142
+ *
143
+ * @example
144
+ * // Find all TODO comments in TypeScript files
145
+ * const matches = await fs.findFiles('/app/src', 'TODO:');
146
+ * matches.forEach(match => {
147
+ * console.log(`${match.file}:${match.line}: ${match.content}`);
148
+ * });
46
149
  */
47
150
  findFiles(path: string, pattern: string): Promise<Array<Match>>;
48
151
  /**
49
- * Gets details about a file
50
- * @param {string} path - Path to the file
51
- * @returns {Promise<FileInfo>} File information
152
+ * Retrieves detailed information about a file or directory.
153
+ *
154
+ * @param {string} path - Path to the file or directory
155
+ * @returns {Promise<FileInfo>} Detailed file information including size, permissions, modification time
156
+ *
157
+ * @example
158
+ * // Get file details
159
+ * const info = await fs.getFileDetails('/app/config.json');
160
+ * console.log(`Size: ${info.size}, Modified: ${info.modTime}`);
52
161
  */
53
162
  getFileDetails(path: string): Promise<FileInfo>;
54
163
  /**
55
- * Lists files in a directory
164
+ * Lists contents of a directory in the Sandbox.
165
+ *
56
166
  * @param {string} path - Directory path to list
57
- * @returns {Promise<FileInfo[]>} Array of file information
167
+ * @returns {Promise<FileInfo[]>} Array of file and directory information
168
+ *
169
+ * @example
170
+ * // List directory contents
171
+ * const files = await fs.listFiles('/app/src');
172
+ * files.forEach(file => {
173
+ * console.log(`${file.name} (${file.size} bytes)`);
174
+ * });
58
175
  */
59
176
  listFiles(path: string): Promise<FileInfo[]>;
60
177
  /**
61
- * Moves/renames files
178
+ * Moves or renames a file or directory.
179
+ *
62
180
  * @param {string} source - Source path
63
181
  * @param {string} destination - Destination path
64
182
  * @returns {Promise<void>}
183
+ *
184
+ * @example
185
+ * // Move a file to a new location
186
+ * await fs.moveFiles('/app/temp/data.json', '/app/data/data.json');
65
187
  */
66
188
  moveFiles(source: string, destination: string): Promise<void>;
67
189
  /**
68
- * Replaces text in multiple files
69
- * @param {string[]} files - Array of file paths
190
+ * Replaces text content in multiple files.
191
+ *
192
+ * @param {string[]} files - Array of file paths to process
70
193
  * @param {string} pattern - Pattern to replace
71
- * @param {string} newValue - Replacement value
72
- * @returns {Promise<Array<ReplaceResult>>} Results of the replace operation
194
+ * @param {string} newValue - Replacement text
195
+ * @returns {Promise<Array<ReplaceResult>>} Results of the replace operation for each file
196
+ *
197
+ * @example
198
+ * // Update version number across multiple files
199
+ * const results = await fs.replaceInFiles(
200
+ * ['/app/package.json', '/app/version.ts'],
201
+ * '"version": "1.0.0"',
202
+ * '"version": "1.1.0"'
203
+ * );
73
204
  */
74
205
  replaceInFiles(files: string[], pattern: string, newValue: string): Promise<Array<ReplaceResult>>;
75
206
  /**
76
- * Searches for files by name pattern
207
+ * Searches for files and directories by name pattern in the Sandbox.
208
+ *
77
209
  * @param {string} path - Directory to search in
78
- * @param {string} pattern - Search pattern
79
- * @returns {Promise<SearchFilesResponse>} Search results
210
+ * @param {string} pattern - File name pattern (supports globs)
211
+ * @returns {Promise<SearchFilesResponse>} Search results with matching files
212
+ *
213
+ * @example
214
+ * // Find all TypeScript files
215
+ * const result = await fs.searchFiles('/app', '*.ts');
216
+ * result.files.forEach(file => console.log(file));
80
217
  */
81
218
  searchFiles(path: string, pattern: string): Promise<SearchFilesResponse>;
82
219
  /**
83
- * Sets file permissions
84
- * @param {string} path - Path to the file
220
+ * Sets permissions and ownership for a file or directory.
221
+ *
222
+ * @param {string} path - Path to the file or directory
85
223
  * @param {FilePermissionsParams} permissions - Permission settings
86
224
  * @returns {Promise<void>}
225
+ *
226
+ * @example
227
+ * // Set file permissions and ownership
228
+ * await fs.setFilePermissions('/app/script.sh', {
229
+ * owner: 'daytona',
230
+ * group: 'users',
231
+ * mode: '755' // Execute permission for shell script
232
+ * });
87
233
  */
88
234
  setFilePermissions(path: string, permissions: FilePermissionsParams): Promise<void>;
89
235
  /**
90
- * Uploads a file to the workspace
91
- * @param {string} path - Destination path
92
- * @param {Blob} file - File contents to upload
236
+ * Uploads a file to the Sandbox.
237
+ *
238
+ * @param {string} path - Destination path in the Sandbox
239
+ * @param {File} file - File to upload
93
240
  * @returns {Promise<void>}
241
+ *
242
+ * @example
243
+ * // Upload a configuration file
244
+ * const configFile = new File(['{"setting": "value"}'], 'config.json');
245
+ * await fs.uploadFile('/app/config.json', configFile);
94
246
  */
95
247
  uploadFile(path: string, file: File): Promise<void>;
96
248
  }
97
- export {};
@@ -1,9 +1,76 @@
1
1
  "use strict";
2
+ /**
3
+ * The Daytona SDK provides comprehensive file system operations through the `fs` module in Sandboxes.
4
+ * You can perform various operations like listing files, creating directories, reading and writing files, and more.
5
+ * This guide covers all available file system operations and best practices.
6
+ *
7
+ * @module FileSystem
8
+ *
9
+ * @example
10
+ * // Basic file operations
11
+ * // Create a workspace
12
+ * const workspace = await daytona.create();
13
+ *
14
+ * // Create a directory
15
+ * await workspace.fs.createFolder('/workspace/data', '755');
16
+ *
17
+ * // Upload a file
18
+ * const fileContent = new File(['content'], 'local_file.txt');
19
+ * await workspace.fs.uploadFile('/workspace/data/file.txt', fileContent);
20
+ *
21
+ * // List directory contents
22
+ * const files = await workspace.fs.listFiles('/workspace');
23
+ * files.forEach(file => {
24
+ * console.log(`Name: ${file.name}`);
25
+ * console.log(`Is directory: ${file.isDir}`);
26
+ * console.log(`Size: ${file.size}`);
27
+ * console.log(`Modified: ${file.modTime}`);
28
+ * });
29
+ *
30
+ * // Search file contents
31
+ * const matches = await workspace.fs.findFiles(
32
+ * '/workspace/src',
33
+ * 'text-of-interest'
34
+ * );
35
+ * matches.forEach(match => {
36
+ * console.log(`Absolute file path: ${match.file}`);
37
+ * console.log(`Line number: ${match.line}`);
38
+ * console.log(`Line content: ${match.content}\n`);
39
+ * });
40
+ *
41
+ * @example
42
+ * // File manipulation
43
+ * // Move files
44
+ * await workspace.fs.moveFiles(
45
+ * '/workspace/data/old.txt',
46
+ * '/workspace/data/new.txt'
47
+ * );
48
+ *
49
+ * // Replace text in files
50
+ * const results = await workspace.fs.replaceInFiles(
51
+ * ['/workspace/data/new.txt'],
52
+ * 'old_version',
53
+ * 'new_version'
54
+ * );
55
+ *
56
+ * // Set permissions
57
+ * await workspace.fs.setFilePermissions(
58
+ * '/workspace/data/script.sh',
59
+ * {
60
+ * mode: '755',
61
+ * owner: 'daytona'
62
+ * }
63
+ * );
64
+ */
2
65
  Object.defineProperty(exports, "__esModule", { value: true });
3
66
  exports.FileSystem = void 0;
4
67
  /**
5
- * Provides file system operations within a workspace
6
- * @class FileSystem
68
+ * Provides file system operations within a Sandbox.
69
+ *
70
+ * This class implements a high-level interface to file system operations that can
71
+ * be performed within a Daytona Sandbox. It supports common operations like
72
+ * creating, deleting, and moving files, as well as searching file contents and
73
+ * managing permissions.
7
74
  */
8
75
  class FileSystem {
9
76
  constructor(instance, toolboxApi) {
@@ -11,77 +78,129 @@ class FileSystem {
11
78
  this.toolboxApi = toolboxApi;
12
79
  }
13
80
  /**
14
- * Creates a new folder in the workspace
15
- * @param {string} path - Path where the folder should be created
16
- * @param {string} mode - Folder permissions in octal format
81
+ * Create a new directory in the Sandbox with specified permissions.
82
+ *
83
+ * @param {string} path - Path where the directory should be created
84
+ * @param {string} mode - Directory permissions in octal format (e.g. "755")
17
85
  * @returns {Promise<void>}
86
+ *
87
+ * @example
88
+ * // Create a directory with standard permissions
89
+ * await fs.createFolder('/app/data', '755');
18
90
  */
19
91
  async createFolder(path, mode) {
20
92
  const response = await this.toolboxApi.createFolder(this.instance.id, path, mode);
21
93
  return response.data;
22
94
  }
23
95
  /**
24
- * Deletes a file from the workspace
25
- * @param {string} path - Path to the file to delete
96
+ * Deletes a file or directory from the Sandbox.
97
+ *
98
+ * @param {string} path - Path to the file or directory to delete
26
99
  * @returns {Promise<void>}
100
+ *
101
+ * @example
102
+ * // Delete a file
103
+ * await fs.deleteFile('/app/temp.log');
27
104
  */
28
105
  async deleteFile(path) {
29
106
  const response = await this.toolboxApi.deleteFile(this.instance.id, path);
30
107
  return response.data;
31
108
  }
32
109
  /**
33
- * Downloads a file from the workspace
110
+ * Downloads a file from the Sandbox.
111
+ *
34
112
  * @param {string} path - Path to the file to download
35
113
  * @returns {Promise<Blob>} The file contents as a Blob
114
+ *
115
+ * @example
116
+ * // Download and process a file
117
+ * const fileBlob = await fs.downloadFile('/app/data.json');
118
+ * console.log('File content:', fileBlob.toString());
36
119
  */
37
120
  async downloadFile(path) {
38
121
  const response = await this.toolboxApi.downloadFile(this.instance.id, path);
39
122
  return response.data;
40
123
  }
41
124
  /**
42
- * Searches for files matching a pattern
125
+ * Searches for text patterns within files in the Sandbox.
126
+ *
43
127
  * @param {string} path - Directory to search in
44
128
  * @param {string} pattern - Search pattern
45
- * @returns {Promise<Array<Match>>} Array of matching files
129
+ * @returns {Promise<Array<Match>>} Array of matches with file and line information
130
+ *
131
+ * @example
132
+ * // Find all TODO comments in TypeScript files
133
+ * const matches = await fs.findFiles('/app/src', 'TODO:');
134
+ * matches.forEach(match => {
135
+ * console.log(`${match.file}:${match.line}: ${match.content}`);
136
+ * });
46
137
  */
47
138
  async findFiles(path, pattern) {
48
139
  const response = await this.toolboxApi.findInFiles(this.instance.id, path, pattern);
49
140
  return response.data;
50
141
  }
51
142
  /**
52
- * Gets details about a file
53
- * @param {string} path - Path to the file
54
- * @returns {Promise<FileInfo>} File information
143
+ * Retrieves detailed information about a file or directory.
144
+ *
145
+ * @param {string} path - Path to the file or directory
146
+ * @returns {Promise<FileInfo>} Detailed file information including size, permissions, modification time
147
+ *
148
+ * @example
149
+ * // Get file details
150
+ * const info = await fs.getFileDetails('/app/config.json');
151
+ * console.log(`Size: ${info.size}, Modified: ${info.modTime}`);
55
152
  */
56
153
  async getFileDetails(path) {
57
154
  const response = await this.toolboxApi.getFileInfo(this.instance.id, path);
58
155
  return response.data;
59
156
  }
60
157
  /**
61
- * Lists files in a directory
158
+ * Lists contents of a directory in the Sandbox.
159
+ *
62
160
  * @param {string} path - Directory path to list
63
- * @returns {Promise<FileInfo[]>} Array of file information
161
+ * @returns {Promise<FileInfo[]>} Array of file and directory information
162
+ *
163
+ * @example
164
+ * // List directory contents
165
+ * const files = await fs.listFiles('/app/src');
166
+ * files.forEach(file => {
167
+ * console.log(`${file.name} (${file.size} bytes)`);
168
+ * });
64
169
  */
65
170
  async listFiles(path) {
66
171
  const response = await this.toolboxApi.listFiles(this.instance.id, path);
67
172
  return response.data;
68
173
  }
69
174
  /**
70
- * Moves/renames files
175
+ * Moves or renames a file or directory.
176
+ *
71
177
  * @param {string} source - Source path
72
178
  * @param {string} destination - Destination path
73
179
  * @returns {Promise<void>}
180
+ *
181
+ * @example
182
+ * // Move a file to a new location
183
+ * await fs.moveFiles('/app/temp/data.json', '/app/data/data.json');
74
184
  */
75
185
  async moveFiles(source, destination) {
76
186
  const response = await this.toolboxApi.moveFile(this.instance.id, source, destination);
77
187
  return response.data;
78
188
  }
79
189
  /**
80
- * Replaces text in multiple files
81
- * @param {string[]} files - Array of file paths
190
+ * Replaces text content in multiple files.
191
+ *
192
+ * @param {string[]} files - Array of file paths to process
82
193
  * @param {string} pattern - Pattern to replace
83
- * @param {string} newValue - Replacement value
84
- * @returns {Promise<Array<ReplaceResult>>} Results of the replace operation
194
+ * @param {string} newValue - Replacement text
195
+ * @returns {Promise<Array<ReplaceResult>>} Results of the replace operation for each file
196
+ *
197
+ * @example
198
+ * // Update version number across multiple files
199
+ * const results = await fs.replaceInFiles(
200
+ * ['/app/package.json', '/app/version.ts'],
201
+ * '"version": "1.0.0"',
202
+ * '"version": "1.1.0"'
203
+ * );
85
204
  */
86
205
  async replaceInFiles(files, pattern, newValue) {
87
206
  const replaceRequest = {
@@ -93,30 +212,51 @@ class FileSystem {
93
212
  return response.data;
94
213
  }
95
214
  /**
96
- * Searches for files by name pattern
215
+ * Searches for files and directories by name pattern in the Sandbox.
216
+ *
97
217
  * @param {string} path - Directory to search in
98
- * @param {string} pattern - Search pattern
99
- * @returns {Promise<SearchFilesResponse>} Search results
218
+ * @param {string} pattern - File name pattern (supports globs)
219
+ * @returns {Promise<SearchFilesResponse>} Search results with matching files
220
+ *
221
+ * @example
222
+ * // Find all TypeScript files
223
+ * const result = await fs.searchFiles('/app', '*.ts');
224
+ * result.files.forEach(file => console.log(file));
100
225
  */
101
226
  async searchFiles(path, pattern) {
102
227
  const response = await this.toolboxApi.searchFiles(this.instance.id, path, pattern);
103
228
  return response.data;
104
229
  }
105
230
  /**
106
- * Sets file permissions
107
- * @param {string} path - Path to the file
231
+ * Sets permissions and ownership for a file or directory.
232
+ *
233
+ * @param {string} path - Path to the file or directory
108
234
  * @param {FilePermissionsParams} permissions - Permission settings
109
235
  * @returns {Promise<void>}
236
+ *
237
+ * @example
238
+ * // Set file permissions and ownership
239
+ * await fs.setFilePermissions('/app/script.sh', {
240
+ * owner: 'daytona',
241
+ * group: 'users',
242
+ * mode: '755' // Execute permission for shell script
243
+ * });
110
244
  */
111
245
  async setFilePermissions(path, permissions) {
112
246
  const response = await this.toolboxApi.setFilePermissions(this.instance.id, path, permissions.owner, permissions.group, permissions.mode);
113
247
  return response.data;
114
248
  }
115
249
  /**
116
- * Uploads a file to the workspace
117
- * @param {string} path - Destination path
118
- * @param {Blob} file - File contents to upload
250
+ * Uploads a file to the Sandbox.
251
+ *
252
+ * @param {string} path - Destination path in the Sandbox
253
+ * @param {File} file - File to upload
119
254
  * @returns {Promise<void>}
255
+ *
256
+ * @example
257
+ * // Upload a configuration file
258
+ * const configFile = new File(['{"setting": "value"}'], 'config.json');
259
+ * await fs.uploadFile('/app/config.json', configFile);
120
260
  */
121
261
  async uploadFile(path, file) {
122
262
  const response = await this.toolboxApi.uploadFile(this.instance.id, path, file);