@lcap/wave-sandbox-sdk 0.0.1 → 0.0.2

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/README.md CHANGED
@@ -232,6 +232,28 @@ items.forEach(([name, type]) => {
232
232
  });
233
233
  ```
234
234
 
235
+ ##### `files(dirPath: string): Promise<Record<string, ProjectFile>>`
236
+
237
+ 获取指定目录下的所有文件(递归)。
238
+
239
+ **参数:**
240
+ - `dirPath`: 目录路径
241
+
242
+ **返回:** Promise<Record<string, ProjectFile>> 文件路径到文件信息的映射
243
+
244
+ **示例:**
245
+ ```typescript
246
+ const files = await client.fs.files('.');
247
+ Object.entries(files).forEach(([path, file]) => {
248
+ console.log(`文件路径: ${path}`);
249
+ console.log(`文件名: ${file.name}`);
250
+ console.log(`MIME类型: ${file.type}`);
251
+ console.log(`是否二进制: ${file.isBinary}`);
252
+ console.log(`最后修改时间: ${new Date(file.lastModified)}`);
253
+ console.log(`文件大小: ${file.size} 字节`);
254
+ });
255
+ ```
256
+
235
257
  ##### `writeFile(filePath: string, data: string | Blob | ArrayBuffer | Uint8Array, chunkSize?: number): Promise<void>`
236
258
 
237
259
  写入文件(流式)。
@@ -427,7 +449,7 @@ console.log('工作空间模式:', info.workspace);
427
449
 
428
450
  ##### `getFiles(): Promise<ProjectFile[]>`
429
451
 
430
- 获取项目文件列表。
452
+ 获取项目文件列表(仅返回文件,不包含目录)。
431
453
 
432
454
  **返回:** Promise<ProjectFile[]> 项目文件数组
433
455
 
@@ -435,7 +457,12 @@ console.log('工作空间模式:', info.workspace);
435
457
  ```typescript
436
458
  const files = await client.project.getFiles();
437
459
  files.forEach((file) => {
438
- console.log('文件:', file.path);
460
+ console.log('文件路径:', file.path);
461
+ console.log('文件名:', file.name);
462
+ console.log('MIME类型:', file.type);
463
+ console.log('是否二进制:', file.isBinary);
464
+ console.log('最后修改时间:', new Date(file.lastModified));
465
+ console.log('文件大小:', file.size, '字节');
439
466
  });
440
467
  ```
441
468
 
@@ -860,6 +887,12 @@ enum FileType {
860
887
  interface FileChangeEvent {
861
888
  type: 'add' | 'change' | 'unlink' | 'addDir' | 'unlinkDir';
862
889
  path: string;
890
+ /** 是否为二进制文件(仅在 add 和 change 事件中存在) */
891
+ isBinary?: boolean;
892
+ /** 最后修改时间(毫秒时间戳,仅在文件事件中存在) */
893
+ lastModified?: number;
894
+ /** 文件大小(字节,仅在文件事件中存在) */
895
+ size?: number;
863
896
  }
864
897
  ```
865
898
 
@@ -882,6 +915,19 @@ interface ProjectInfo {
882
915
  }
883
916
  ```
884
917
 
918
+ ### ProjectFile
919
+
920
+ ```typescript
921
+ interface ProjectFile {
922
+ path: string; // 文件相对路径
923
+ name: string; // 文件名
924
+ type: string; // MIME 类型
925
+ isBinary: boolean; // 是否为二进制文件
926
+ lastModified: number; // 最后修改时间(毫秒时间戳)
927
+ size: number; // 文件大小(字节)
928
+ }
929
+ ```
930
+
885
931
  ### SendMessageOptions
886
932
 
887
933
  ```typescript
@@ -1,5 +1,5 @@
1
1
  import type { Socket } from 'socket.io-client';
2
- import type { FileStat, DirectoryItem, FileChangeEvent } from '../types/index.js';
2
+ import type { FileStat, DirectoryItem, FileChangeEvent, ProjectFile } from '../types/index.js';
3
3
  /**
4
4
  * 文件系统模块
5
5
  */
@@ -12,6 +12,10 @@ export declare class FileSystemModule {
12
12
  * 获取查询参数
13
13
  */
14
14
  private getQueryParams;
15
+ /**
16
+ * 获取查询参数(用于目录路径)
17
+ */
18
+ private getDirQueryParams;
15
19
  /**
16
20
  * 获取文件状态
17
21
  */
@@ -34,6 +38,12 @@ export declare class FileSystemModule {
34
38
  * 读取目录
35
39
  */
36
40
  readdir(filePath: string): Promise<DirectoryItem[]>;
41
+ /**
42
+ * 获取指定目录下的所有文件
43
+ * @param dirPath 目录路径
44
+ * @returns Promise<Record<string, ProjectFile>> 文件路径到文件信息的映射
45
+ */
46
+ files(dirPath: string): Promise<Record<string, ProjectFile>>;
37
47
  /**
38
48
  * 写入文件(流式)
39
49
  * @param filePath 文件路径
@@ -18,6 +18,16 @@ export class FileSystemModule {
18
18
  }
19
19
  return params.toString();
20
20
  }
21
+ /**
22
+ * 获取查询参数(用于目录路径)
23
+ */
24
+ getDirQueryParams(dirPath) {
25
+ const params = new URLSearchParams({ dirPath });
26
+ if (this.projectId) {
27
+ params.set('projectId', this.projectId);
28
+ }
29
+ return params.toString();
30
+ }
21
31
  /**
22
32
  * 获取文件状态
23
33
  */
@@ -71,6 +81,20 @@ export class FileSystemModule {
71
81
  }
72
82
  return result.data;
73
83
  }
84
+ /**
85
+ * 获取指定目录下的所有文件
86
+ * @param dirPath 目录路径
87
+ * @returns Promise<Record<string, ProjectFile>> 文件路径到文件信息的映射
88
+ */
89
+ async files(dirPath) {
90
+ const url = `${this.baseUrl}/api/fs/files?${this.getDirQueryParams(dirPath)}`;
91
+ const response = await fetch(url);
92
+ const result = await response.json();
93
+ if (result.status === 'error') {
94
+ throw new Error(result.message);
95
+ }
96
+ return result.data;
97
+ }
74
98
  /**
75
99
  * 写入文件(流式)
76
100
  * @param filePath 文件路径
@@ -56,6 +56,10 @@ export interface FileChangeEvent {
56
56
  path: string;
57
57
  /** 是否为二进制文件(仅在 add 和 change 事件中存在) */
58
58
  isBinary?: boolean;
59
+ /** 最后修改时间(毫秒时间戳,仅在文件事件中存在) */
60
+ lastModified?: number;
61
+ /** 文件大小(字节,仅在文件事件中存在) */
62
+ size?: number;
59
63
  }
60
64
  /**
61
65
  * 端口状态类型
@@ -81,6 +85,11 @@ export interface ProjectInfo {
81
85
  */
82
86
  export interface ProjectFile {
83
87
  path: string;
88
+ name: string;
89
+ type: string;
90
+ isBinary: boolean;
91
+ lastModified: number;
92
+ size: number;
84
93
  }
85
94
  /**
86
95
  * SDK 配置选项
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lcap/wave-sandbox-sdk",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "SDK for Wave Sandbox Client",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -10,8 +10,17 @@
10
10
  "src",
11
11
  "README.md"
12
12
  ],
13
+ "scripts": {
14
+ "build": "rimraf dist && tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",
15
+ "type-check": "tsc --noEmit",
16
+ "dev": "tsc -p tsconfig.build.json --watch & tsc-alias -p tsconfig.build.json --watch",
17
+ "test": "vitest run",
18
+ "lint": "eslint --cache",
19
+ "format": "prettier --write .",
20
+ "prepublishOnly": "pnpm run build"
21
+ },
13
22
  "dependencies": {
14
- "socket.io-client": "^4.8.1"
23
+ "socket.io-client": "^4.8.3"
15
24
  },
16
25
  "devDependencies": {
17
26
  "rimraf": "^6.1.2",
@@ -22,13 +31,5 @@
22
31
  "engines": {
23
32
  "node": ">=16.0.0"
24
33
  },
25
- "license": "MIT",
26
- "scripts": {
27
- "build": "rimraf dist && tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",
28
- "type-check": "tsc --noEmit",
29
- "dev": "tsc -p tsconfig.build.json --watch & tsc-alias -p tsconfig.build.json --watch",
30
- "test": "vitest run",
31
- "lint": "eslint --cache",
32
- "format": "prettier --write ."
33
- }
34
- }
34
+ "license": "MIT"
35
+ }
@@ -1,6 +1,6 @@
1
1
  import type { Socket } from 'socket.io-client';
2
2
  import { createSocketHandler, onSocketEvent } from '../utils/socket.js';
3
- import type { FileStat, DirectoryItem, FileChangeEvent, HttpResponse } from '../types/index.js';
3
+ import type { FileStat, DirectoryItem, FileChangeEvent, HttpResponse, ProjectFile } from '../types/index.js';
4
4
 
5
5
  /**
6
6
  * 文件系统模块
@@ -23,6 +23,17 @@ export class FileSystemModule {
23
23
  return params.toString();
24
24
  }
25
25
 
26
+ /**
27
+ * 获取查询参数(用于目录路径)
28
+ */
29
+ private getDirQueryParams(dirPath: string): string {
30
+ const params = new URLSearchParams({ dirPath });
31
+ if (this.projectId) {
32
+ params.set('projectId', this.projectId);
33
+ }
34
+ return params.toString();
35
+ }
36
+
26
37
  /**
27
38
  * 获取文件状态
28
39
  */
@@ -93,6 +104,23 @@ export class FileSystemModule {
93
104
  return result.data;
94
105
  }
95
106
 
107
+ /**
108
+ * 获取指定目录下的所有文件
109
+ * @param dirPath 目录路径
110
+ * @returns Promise<Record<string, ProjectFile>> 文件路径到文件信息的映射
111
+ */
112
+ async files(dirPath: string): Promise<Record<string, ProjectFile>> {
113
+ const url = `${this.baseUrl}/api/fs/files?${this.getDirQueryParams(dirPath)}`;
114
+ const response = await fetch(url);
115
+ const result: HttpResponse<Record<string, ProjectFile>> = await response.json();
116
+
117
+ if (result.status === 'error') {
118
+ throw new Error(result.message);
119
+ }
120
+
121
+ return result.data;
122
+ }
123
+
96
124
  /**
97
125
  * 写入文件(流式)
98
126
  * @param filePath 文件路径
@@ -66,6 +66,10 @@ export interface FileChangeEvent {
66
66
  path: string;
67
67
  /** 是否为二进制文件(仅在 add 和 change 事件中存在) */
68
68
  isBinary?: boolean;
69
+ /** 最后修改时间(毫秒时间戳,仅在文件事件中存在) */
70
+ lastModified?: number;
71
+ /** 文件大小(字节,仅在文件事件中存在) */
72
+ size?: number;
69
73
  }
70
74
 
71
75
  /**
@@ -95,7 +99,11 @@ export interface ProjectInfo {
95
99
  */
96
100
  export interface ProjectFile {
97
101
  path: string;
98
- // 可以根据实际需要添加更多字段
102
+ name: string;
103
+ type: string;
104
+ isBinary: boolean;
105
+ lastModified: number;
106
+ size: number;
99
107
  }
100
108
 
101
109
  /**