@lingxia/rong 0.0.1
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 +59 -0
- package/dist/abort.d.ts +36 -0
- package/dist/abort.d.ts.map +1 -0
- package/dist/abort.js +6 -0
- package/dist/assert.d.ts +44 -0
- package/dist/assert.d.ts.map +1 -0
- package/dist/assert.js +6 -0
- package/dist/buffer.d.ts +45 -0
- package/dist/buffer.d.ts.map +1 -0
- package/dist/buffer.js +6 -0
- package/dist/child_process.d.ts +99 -0
- package/dist/child_process.d.ts.map +1 -0
- package/dist/child_process.js +6 -0
- package/dist/console.d.ts +40 -0
- package/dist/console.d.ts.map +1 -0
- package/dist/console.js +9 -0
- package/dist/encoding.d.ts +10 -0
- package/dist/encoding.d.ts.map +1 -0
- package/dist/encoding.js +10 -0
- package/dist/error.d.ts +104 -0
- package/dist/error.d.ts.map +1 -0
- package/dist/error.js +90 -0
- package/dist/event.d.ts +96 -0
- package/dist/event.d.ts.map +1 -0
- package/dist/event.js +6 -0
- package/dist/exception.d.ts +19 -0
- package/dist/exception.d.ts.map +1 -0
- package/dist/exception.js +6 -0
- package/dist/fs.d.ts +450 -0
- package/dist/fs.d.ts.map +1 -0
- package/dist/fs.js +23 -0
- package/dist/global.d.ts +76 -0
- package/dist/global.d.ts.map +1 -0
- package/dist/global.js +8 -0
- package/dist/http.d.ts +117 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +9 -0
- package/dist/index.d.ts +56 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +77 -0
- package/dist/navigator.d.ts +16 -0
- package/dist/navigator.d.ts.map +1 -0
- package/dist/navigator.js +6 -0
- package/dist/path.d.ts +70 -0
- package/dist/path.d.ts.map +1 -0
- package/dist/path.js +6 -0
- package/dist/process.d.ts +53 -0
- package/dist/process.d.ts.map +1 -0
- package/dist/process.js +6 -0
- package/dist/storage.d.ts +53 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +8 -0
- package/dist/stream.d.ts +90 -0
- package/dist/stream.d.ts.map +1 -0
- package/dist/stream.js +90 -0
- package/dist/timer.d.ts +52 -0
- package/dist/timer.d.ts.map +1 -0
- package/dist/timer.js +6 -0
- package/dist/url.d.ts +75 -0
- package/dist/url.d.ts.map +1 -0
- package/dist/url.js +6 -0
- package/package.json +27 -0
- package/src/abort.ts +50 -0
- package/src/assert.ts +51 -0
- package/src/buffer.ts +60 -0
- package/src/child_process.ts +116 -0
- package/src/console.ts +53 -0
- package/src/encoding.ts +10 -0
- package/src/error.ts +149 -0
- package/src/event.ts +128 -0
- package/src/exception.ts +77 -0
- package/src/fs.ts +514 -0
- package/src/global.ts +98 -0
- package/src/http.ts +151 -0
- package/src/index.ts +67 -0
- package/src/navigator.ts +20 -0
- package/src/path.ts +83 -0
- package/src/process.ts +74 -0
- package/src/storage.ts +64 -0
- package/src/stream.ts +98 -0
- package/src/timer.ts +61 -0
- package/src/url.ts +106 -0
package/src/fs.ts
ADDED
|
@@ -0,0 +1,514 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File System module type definitions
|
|
3
|
+
* Corresponds to: modules/rong_fs
|
|
4
|
+
*
|
|
5
|
+
* Provides APIs for file system operations including reading, writing, and directory management.
|
|
6
|
+
* All file system APIs are mounted under the global `Rong` namespace.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// ==================== Options Types ====================
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Options for reading files.
|
|
13
|
+
*/
|
|
14
|
+
export interface ReadFileOptions {
|
|
15
|
+
/**
|
|
16
|
+
* AbortSignal to cancel the read operation.
|
|
17
|
+
* When aborted, the operation will throw an AbortError.
|
|
18
|
+
*
|
|
19
|
+
* @see {@link AbortSignal}
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const controller = new AbortController();
|
|
23
|
+
* const promise = Rong.readTextFile('/file.txt', {
|
|
24
|
+
* signal: controller.signal
|
|
25
|
+
* });
|
|
26
|
+
* // Cancel after 1 second
|
|
27
|
+
* setTimeout(() => controller.abort(), 1000);
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
signal?: AbortSignal;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Options for writing files.
|
|
35
|
+
*/
|
|
36
|
+
export interface WriteFileOptions {
|
|
37
|
+
/**
|
|
38
|
+
* Append to file instead of overwriting.
|
|
39
|
+
* Cannot be used together with `createNew`.
|
|
40
|
+
*
|
|
41
|
+
* @default false
|
|
42
|
+
*/
|
|
43
|
+
append?: boolean;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Create file only if it doesn't exist.
|
|
47
|
+
* Throws AlreadyExistsError if the file already exists.
|
|
48
|
+
* Cannot be used together with `append`.
|
|
49
|
+
*
|
|
50
|
+
* @default false
|
|
51
|
+
* @throws {AlreadyExistsError} If file already exists
|
|
52
|
+
*/
|
|
53
|
+
createNew?: boolean;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* File permissions mode (Unix-like systems only).
|
|
57
|
+
* Octal number (e.g., 0o644 for rw-r--r--).
|
|
58
|
+
* Ignored on Windows.
|
|
59
|
+
*
|
|
60
|
+
* @default 0o666 (modified by process umask)
|
|
61
|
+
* @platform unix
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* await Rong.writeTextFile('/script.sh', '#!/bin/bash\necho hello', {
|
|
65
|
+
* mode: 0o755 // rwxr-xr-x
|
|
66
|
+
* });
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
mode?: number;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* AbortSignal to cancel the write operation.
|
|
73
|
+
*
|
|
74
|
+
* @see {@link AbortSignal}
|
|
75
|
+
*/
|
|
76
|
+
signal?: AbortSignal;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Options for opening files.
|
|
81
|
+
*/
|
|
82
|
+
export interface FileOpenOptions {
|
|
83
|
+
/**
|
|
84
|
+
* Open file for reading.
|
|
85
|
+
* @default false
|
|
86
|
+
*/
|
|
87
|
+
read?: boolean;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Open file for writing.
|
|
91
|
+
* @default false
|
|
92
|
+
*/
|
|
93
|
+
write?: boolean;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Open file for appending (writes go to end of file).
|
|
97
|
+
* @default false
|
|
98
|
+
*/
|
|
99
|
+
append?: boolean;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Truncate file to 0 bytes when opening (if it exists).
|
|
103
|
+
* Only valid when `write` is true.
|
|
104
|
+
* @default false
|
|
105
|
+
*/
|
|
106
|
+
truncate?: boolean;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Create file if it doesn't exist.
|
|
110
|
+
* Only valid when `write` is true.
|
|
111
|
+
* @default false
|
|
112
|
+
*/
|
|
113
|
+
create?: boolean;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Create file only if it doesn't exist (exclusive creation).
|
|
117
|
+
* Throws AlreadyExistsError if file exists.
|
|
118
|
+
* Only valid when `write` is true.
|
|
119
|
+
*
|
|
120
|
+
* @default false
|
|
121
|
+
* @throws {AlreadyExistsError} If file already exists
|
|
122
|
+
*/
|
|
123
|
+
createNew?: boolean;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* File permissions mode (Unix-like systems only).
|
|
127
|
+
* @default 0o666 (modified by process umask)
|
|
128
|
+
* @platform unix
|
|
129
|
+
*/
|
|
130
|
+
mode?: number;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Options for creating directories.
|
|
135
|
+
*/
|
|
136
|
+
export interface MkdirOptions {
|
|
137
|
+
/**
|
|
138
|
+
* Create parent directories as needed.
|
|
139
|
+
* If false and parent doesn't exist, throws NotFoundError.
|
|
140
|
+
*
|
|
141
|
+
* @default false
|
|
142
|
+
* @throws {NotFoundError} If parent doesn't exist and recursive is false
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* // Create nested directories
|
|
146
|
+
* await Rong.mkdir('/path/to/nested/dir', { recursive: true });
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
recursive?: boolean;
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Directory permissions mode (Unix-like systems only).
|
|
153
|
+
* @default 0o777 (modified by process umask)
|
|
154
|
+
* @platform unix
|
|
155
|
+
*/
|
|
156
|
+
mode?: number;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Options for removing files and directories.
|
|
161
|
+
*/
|
|
162
|
+
export interface RemoveOptions {
|
|
163
|
+
/**
|
|
164
|
+
* Remove directories and their contents recursively.
|
|
165
|
+
* If false and path is a non-empty directory, throws an error.
|
|
166
|
+
*
|
|
167
|
+
* @default false
|
|
168
|
+
* @example
|
|
169
|
+
* ```typescript
|
|
170
|
+
* // Remove directory and all its contents
|
|
171
|
+
* await Rong.remove('/path/to/dir', { recursive: true });
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
recursive?: boolean;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Options for setting file timestamps via {@link FsModule.utime}.
|
|
179
|
+
*/
|
|
180
|
+
export interface UTimeOptions {
|
|
181
|
+
/**
|
|
182
|
+
* Access time in milliseconds since Unix epoch.
|
|
183
|
+
* If omitted, defaults to "now" (runtime-dependent).
|
|
184
|
+
*/
|
|
185
|
+
accessed?: number;
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Modified time in milliseconds since Unix epoch.
|
|
189
|
+
* If omitted, defaults to "now" (runtime-dependent).
|
|
190
|
+
*/
|
|
191
|
+
modified?: number;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// ==================== Information Types ====================
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* File or directory metadata information.
|
|
198
|
+
* Returned by `stat()` and `lstat()` functions.
|
|
199
|
+
*/
|
|
200
|
+
export interface FileInfo {
|
|
201
|
+
/**
|
|
202
|
+
* Whether this is a regular file.
|
|
203
|
+
* Mutually exclusive with `isDirectory` and `isSymlink`.
|
|
204
|
+
*/
|
|
205
|
+
readonly isFile: boolean;
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Whether this is a directory.
|
|
209
|
+
* Mutually exclusive with `isFile` and `isSymlink`.
|
|
210
|
+
*/
|
|
211
|
+
readonly isDirectory: boolean;
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Whether this is a symbolic link.
|
|
215
|
+
* For symbolic links, use `lstat()` instead of `stat()`
|
|
216
|
+
* to get link information rather than target information.
|
|
217
|
+
*/
|
|
218
|
+
readonly isSymlink: boolean;
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* File size in bytes.
|
|
222
|
+
* For directories, this is the size of the directory entry, not its contents.
|
|
223
|
+
*/
|
|
224
|
+
readonly size: number;
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Last modified time in milliseconds since Unix epoch.
|
|
228
|
+
* May be undefined if not supported by the file system.
|
|
229
|
+
*/
|
|
230
|
+
readonly modified?: number;
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Last accessed time in milliseconds since Unix epoch.
|
|
234
|
+
* May be undefined if not supported by the file system.
|
|
235
|
+
*/
|
|
236
|
+
readonly accessed?: number;
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Creation time in milliseconds since Unix epoch.
|
|
240
|
+
* May be undefined if not supported by the file system.
|
|
241
|
+
*/
|
|
242
|
+
readonly created?: number;
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* File permissions mode (Unix-like systems only).
|
|
246
|
+
* Octal representation of file permissions.
|
|
247
|
+
* Undefined on Windows.
|
|
248
|
+
*
|
|
249
|
+
* @platform unix
|
|
250
|
+
*/
|
|
251
|
+
readonly mode?: number;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Directory entry information.
|
|
256
|
+
* Returned by `readDir()` function.
|
|
257
|
+
*/
|
|
258
|
+
export interface DirEntry {
|
|
259
|
+
/**
|
|
260
|
+
* Entry name (without directory path).
|
|
261
|
+
* @example For `/path/to/file.txt`, name is `file.txt`
|
|
262
|
+
*/
|
|
263
|
+
readonly name: string;
|
|
264
|
+
|
|
265
|
+
/** Whether this entry is a regular file */
|
|
266
|
+
readonly isFile: boolean;
|
|
267
|
+
|
|
268
|
+
/** Whether this entry is a directory */
|
|
269
|
+
readonly isDirectory: boolean;
|
|
270
|
+
|
|
271
|
+
/** Whether this entry is a symbolic link */
|
|
272
|
+
readonly isSymlink: boolean;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Seek modes for file positioning.
|
|
277
|
+
* Used with `FsFile.seek()` method.
|
|
278
|
+
*/
|
|
279
|
+
export enum SeekMode {
|
|
280
|
+
/** Seek from start of file (absolute position) */
|
|
281
|
+
Start = 0,
|
|
282
|
+
/** Seek from current position (relative) */
|
|
283
|
+
Current = 1,
|
|
284
|
+
/** Seek from end of file (usually negative offset) */
|
|
285
|
+
End = 2
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// ==================== File Handle Interface ====================
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* File handle for advanced file operations.
|
|
292
|
+
* Obtained from `Rong.open()`.
|
|
293
|
+
*
|
|
294
|
+
* @example
|
|
295
|
+
* ```typescript
|
|
296
|
+
* const file = await Rong.open('/path/to/file.txt', {
|
|
297
|
+
* read: true,
|
|
298
|
+
* write: true
|
|
299
|
+
* });
|
|
300
|
+
*
|
|
301
|
+
* try {
|
|
302
|
+
* const buffer = new ArrayBuffer(1024);
|
|
303
|
+
* const bytesRead = await file.read(buffer);
|
|
304
|
+
* console.log(`Read ${bytesRead} bytes`);
|
|
305
|
+
* } finally {
|
|
306
|
+
* await file.close();
|
|
307
|
+
* }
|
|
308
|
+
* ```
|
|
309
|
+
*/
|
|
310
|
+
export interface FsFile {
|
|
311
|
+
/**
|
|
312
|
+
* Get file metadata.
|
|
313
|
+
*
|
|
314
|
+
* @returns Promise with file information
|
|
315
|
+
* @throws {IOError} If stat operation fails
|
|
316
|
+
* @example
|
|
317
|
+
* ```typescript
|
|
318
|
+
* const info = await file.stat();
|
|
319
|
+
* console.log(`File size: ${info.size} bytes`);
|
|
320
|
+
* ```
|
|
321
|
+
*/
|
|
322
|
+
stat(): Promise<FileInfo>;
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Read from file into buffer.
|
|
326
|
+
* Reads from current file position and advances the position.
|
|
327
|
+
*
|
|
328
|
+
* @param buffer - ArrayBuffer to read into
|
|
329
|
+
* @returns Promise with bytes read, or null on EOF
|
|
330
|
+
* @throws {IOError} If read operation fails
|
|
331
|
+
* @example
|
|
332
|
+
* ```typescript
|
|
333
|
+
* const buffer = new ArrayBuffer(4096);
|
|
334
|
+
* const bytesRead = await file.read(buffer);
|
|
335
|
+
* if (bytesRead === null) {
|
|
336
|
+
* console.log('Reached end of file');
|
|
337
|
+
* } else {
|
|
338
|
+
* console.log(`Read ${bytesRead} bytes`);
|
|
339
|
+
* }
|
|
340
|
+
* ```
|
|
341
|
+
*/
|
|
342
|
+
read(buffer: ArrayBuffer): Promise<number | null>;
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Write buffer to file.
|
|
346
|
+
* Writes at current file position and advances the position.
|
|
347
|
+
*
|
|
348
|
+
* @param buffer - ArrayBuffer to write
|
|
349
|
+
* @returns Promise with number of bytes written
|
|
350
|
+
* @throws {IOError} If write operation fails
|
|
351
|
+
* @example
|
|
352
|
+
* ```typescript
|
|
353
|
+
* const data = new TextEncoder().encode('Hello World');
|
|
354
|
+
* const bytesWritten = await file.write(data.buffer);
|
|
355
|
+
* console.log(`Wrote ${bytesWritten} bytes`);
|
|
356
|
+
* ```
|
|
357
|
+
*/
|
|
358
|
+
write(buffer: ArrayBuffer): Promise<number>;
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Sync file contents to disk.
|
|
362
|
+
* Ensures all buffered writes are flushed to storage.
|
|
363
|
+
*
|
|
364
|
+
* @returns Promise that resolves when sync is complete
|
|
365
|
+
* @throws {IOError} If sync operation fails
|
|
366
|
+
*/
|
|
367
|
+
sync(): Promise<void>;
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Truncate or extend file to specified length.
|
|
371
|
+
*
|
|
372
|
+
* @param len - Target length in bytes (default: 0)
|
|
373
|
+
* @returns Promise that resolves when truncate is complete
|
|
374
|
+
* @throws {IOError} If truncate operation fails
|
|
375
|
+
* @example
|
|
376
|
+
* ```typescript
|
|
377
|
+
* // Truncate to 100 bytes
|
|
378
|
+
* await file.truncate(100);
|
|
379
|
+
*
|
|
380
|
+
* // Truncate to 0 bytes (clear file)
|
|
381
|
+
* await file.truncate();
|
|
382
|
+
* ```
|
|
383
|
+
*/
|
|
384
|
+
truncate(len?: number): Promise<void>;
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* Seek to position in file.
|
|
388
|
+
*
|
|
389
|
+
* @param offset - Byte offset
|
|
390
|
+
* @param whence - Seek mode (Start, Current, or End)
|
|
391
|
+
* @returns Promise with new absolute position
|
|
392
|
+
* @throws {IOError} If seek operation fails
|
|
393
|
+
* @example
|
|
394
|
+
* ```typescript
|
|
395
|
+
* // Seek to byte 100 from start
|
|
396
|
+
* await file.seek(100, Rong.SeekMode.Start);
|
|
397
|
+
*
|
|
398
|
+
* // Seek forward 50 bytes from current position
|
|
399
|
+
* await file.seek(50, Rong.SeekMode.Current);
|
|
400
|
+
*
|
|
401
|
+
* // Seek to 10 bytes before end
|
|
402
|
+
* await file.seek(-10, Rong.SeekMode.End);
|
|
403
|
+
* ```
|
|
404
|
+
*/
|
|
405
|
+
seek(offset: number, whence?: SeekMode): Promise<number>;
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* Close file handle.
|
|
409
|
+
* After closing, no further operations can be performed.
|
|
410
|
+
* It's recommended to use try-finally to ensure files are closed.
|
|
411
|
+
*
|
|
412
|
+
* @returns Promise that resolves when file is closed
|
|
413
|
+
* @example
|
|
414
|
+
* ```typescript
|
|
415
|
+
* const file = await Rong.open('/file.txt', { read: true });
|
|
416
|
+
* try {
|
|
417
|
+
* // Use file...
|
|
418
|
+
* } finally {
|
|
419
|
+
* await file.close();
|
|
420
|
+
* }
|
|
421
|
+
* ```
|
|
422
|
+
*/
|
|
423
|
+
close(): Promise<void>;
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* Get ReadableStream for reading file contents.
|
|
427
|
+
* The stream reads from the current file position.
|
|
428
|
+
* Cannot be used simultaneously with direct read operations.
|
|
429
|
+
*
|
|
430
|
+
* @example
|
|
431
|
+
* ```typescript
|
|
432
|
+
* const file = await Rong.open('/file.txt', { read: true });
|
|
433
|
+
* const readable = file.readable;
|
|
434
|
+
*
|
|
435
|
+
* for await (const chunk of readable) {
|
|
436
|
+
* console.log('Received chunk:', chunk.length, 'bytes');
|
|
437
|
+
* }
|
|
438
|
+
* ```
|
|
439
|
+
*/
|
|
440
|
+
readonly readable: ReadableStream<Uint8Array>;
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* Get WritableStream for writing file contents.
|
|
444
|
+
* The stream writes to the current file position.
|
|
445
|
+
* Cannot be used simultaneously with direct write operations.
|
|
446
|
+
*
|
|
447
|
+
* @example
|
|
448
|
+
* ```typescript
|
|
449
|
+
* const file = await Rong.open('/file.txt', { write: true, create: true });
|
|
450
|
+
* const writable = file.writable;
|
|
451
|
+
* const writer = writable.getWriter();
|
|
452
|
+
*
|
|
453
|
+
* await writer.write(new TextEncoder().encode('Hello'));
|
|
454
|
+
* await writer.close();
|
|
455
|
+
* ```
|
|
456
|
+
*/
|
|
457
|
+
readonly writable: WritableStream<Uint8Array>;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
// ==================== Module Interface ====================
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* File System module interface.
|
|
464
|
+
* All operations are available under the global `Rong` namespace.
|
|
465
|
+
*/
|
|
466
|
+
export interface FsModule {
|
|
467
|
+
// Read operations
|
|
468
|
+
readTextFile(path: string, options?: ReadFileOptions): Promise<string>;
|
|
469
|
+
readFile(path: string, options?: ReadFileOptions): Promise<ArrayBuffer>;
|
|
470
|
+
|
|
471
|
+
// Write operations
|
|
472
|
+
writeTextFile(path: string, text: string, options?: WriteFileOptions): Promise<void>;
|
|
473
|
+
writeFile(path: string, data: ArrayBufferView, options?: WriteFileOptions): Promise<void>;
|
|
474
|
+
copyFile(from: string, to: string): Promise<void>;
|
|
475
|
+
truncate(path: string, len?: number): Promise<void>;
|
|
476
|
+
|
|
477
|
+
// File operations
|
|
478
|
+
open(path: string, options?: FileOpenOptions): Promise<FsFile>;
|
|
479
|
+
|
|
480
|
+
// Directory operations
|
|
481
|
+
mkdir(path: string, options?: MkdirOptions): Promise<void>;
|
|
482
|
+
readDir(path: string): Promise<AsyncIterableIterator<DirEntry>>;
|
|
483
|
+
stat(path: string): Promise<FileInfo>;
|
|
484
|
+
lstat(path: string): Promise<FileInfo>;
|
|
485
|
+
remove(path: string, options?: RemoveOptions): Promise<void>;
|
|
486
|
+
chdir(path: string): Promise<void>;
|
|
487
|
+
|
|
488
|
+
// Symlink operations
|
|
489
|
+
symlink(target: string, path: string): Promise<void>;
|
|
490
|
+
readlink(path: string): Promise<string>;
|
|
491
|
+
|
|
492
|
+
// Permission operations
|
|
493
|
+
/**
|
|
494
|
+
* Change file permissions (Unix only)
|
|
495
|
+
* @platform unix
|
|
496
|
+
*/
|
|
497
|
+
chmod(path: string, mode: number): Promise<void>;
|
|
498
|
+
/**
|
|
499
|
+
* Change file ownership (Unix only)
|
|
500
|
+
* @platform unix
|
|
501
|
+
*/
|
|
502
|
+
chown(path: string, uid: number, gid: number): Promise<void>;
|
|
503
|
+
utime(path: string, options: UTimeOptions): Promise<void>;
|
|
504
|
+
|
|
505
|
+
// Path operations
|
|
506
|
+
rename(oldPath: string, newPath: string): Promise<void>;
|
|
507
|
+
realPath(path: string): Promise<string>;
|
|
508
|
+
|
|
509
|
+
// Constants
|
|
510
|
+
readonly SeekMode: typeof SeekMode;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
// Note: File system APIs are declared under Rong namespace in global.d.ts
|
|
514
|
+
export {};
|
package/src/global.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Global API declarations for Rong JavaScript Runtime
|
|
3
|
+
*
|
|
4
|
+
* This file declares all globally available APIs injected by the Rong runtime.
|
|
5
|
+
* These declarations enable IDE autocomplete and TypeScript type checking.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { AssertFunction } from './assert';
|
|
9
|
+
import type { ChildProcessModule } from './child_process';
|
|
10
|
+
import type {
|
|
11
|
+
DirEntry,
|
|
12
|
+
FileInfo,
|
|
13
|
+
FileOpenOptions,
|
|
14
|
+
FsFile,
|
|
15
|
+
MkdirOptions,
|
|
16
|
+
ReadFileOptions,
|
|
17
|
+
RemoveOptions,
|
|
18
|
+
SeekMode,
|
|
19
|
+
UTimeOptions,
|
|
20
|
+
WriteFileOptions,
|
|
21
|
+
} from './fs';
|
|
22
|
+
import type { PathModule } from './path';
|
|
23
|
+
import type { Process } from './process';
|
|
24
|
+
import type { StorageConstructor, StorageModule } from './storage';
|
|
25
|
+
|
|
26
|
+
declare global {
|
|
27
|
+
/**
|
|
28
|
+
* Rong runtime namespace - Core APIs for file system and storage
|
|
29
|
+
*/
|
|
30
|
+
const Rong: {
|
|
31
|
+
// File System APIs
|
|
32
|
+
readTextFile(path: string, options?: ReadFileOptions): Promise<string>;
|
|
33
|
+
readFile(path: string, options?: ReadFileOptions): Promise<ArrayBuffer>;
|
|
34
|
+
writeTextFile(path: string, text: string, options?: WriteFileOptions): Promise<void>;
|
|
35
|
+
writeFile(path: string, data: ArrayBufferView, options?: WriteFileOptions): Promise<void>;
|
|
36
|
+
copyFile(from: string, to: string): Promise<void>;
|
|
37
|
+
truncate(path: string, len?: number): Promise<void>;
|
|
38
|
+
open(path: string, options?: FileOpenOptions): Promise<FsFile>;
|
|
39
|
+
mkdir(path: string, options?: MkdirOptions): Promise<void>;
|
|
40
|
+
readDir(path: string): Promise<AsyncIterableIterator<DirEntry>>;
|
|
41
|
+
stat(path: string): Promise<FileInfo>;
|
|
42
|
+
lstat(path: string): Promise<FileInfo>;
|
|
43
|
+
remove(path: string, options?: RemoveOptions): Promise<void>;
|
|
44
|
+
chdir(path: string): Promise<void>;
|
|
45
|
+
symlink(target: string, path: string): Promise<void>;
|
|
46
|
+
readlink(path: string): Promise<string>;
|
|
47
|
+
/**
|
|
48
|
+
* Change file permissions (Unix only)
|
|
49
|
+
* @platform unix
|
|
50
|
+
*/
|
|
51
|
+
chmod(path: string, mode: number): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Change file ownership (Unix only)
|
|
54
|
+
* @platform unix
|
|
55
|
+
*/
|
|
56
|
+
chown(path: string, uid: number, gid: number): Promise<void>;
|
|
57
|
+
utime(path: string, options: UTimeOptions): Promise<void>;
|
|
58
|
+
rename(oldPath: string, newPath: string): Promise<void>;
|
|
59
|
+
realPath(path: string): Promise<string>;
|
|
60
|
+
readonly SeekMode: typeof SeekMode;
|
|
61
|
+
|
|
62
|
+
// Storage
|
|
63
|
+
readonly Storage: StorageConstructor;
|
|
64
|
+
readonly storage: StorageModule;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Process object - Access to process information and environment
|
|
69
|
+
*/
|
|
70
|
+
const process: Process;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Child Process module - Node.js compatible child process spawning (globalThis.child_process)
|
|
74
|
+
*/
|
|
75
|
+
const child_process: ChildProcessModule;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Path module - Path manipulation utilities (Node.js compatible)
|
|
79
|
+
*/
|
|
80
|
+
const path: PathModule;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Base64 decode - Decode base64 string to binary string
|
|
84
|
+
*/
|
|
85
|
+
function atob(data: string): string;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Base64 encode - Encode binary string to base64
|
|
89
|
+
*/
|
|
90
|
+
function btoa(data: string): string;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Assert function - Test assertions (Node.js compatible)
|
|
94
|
+
*/
|
|
95
|
+
const assert: AssertFunction;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export {};
|