@serveryyswys/node.operit 0.0.0-stage → 0.1.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/BUILTINS.json +233 -0
- package/DESIGN.md +513 -0
- package/LICENSE +674 -0
- package/README.md +301 -2
- package/dist/assert/strict.d.ts +2 -0
- package/dist/assert/strict.js +7 -0
- package/dist/assert.d.ts +3 -0
- package/dist/assert.js +483 -0
- package/dist/buffer.d.ts +60 -0
- package/dist/buffer.js +524 -0
- package/dist/child_process.d.ts +56 -0
- package/dist/child_process.js +371 -0
- package/dist/constants.d.ts +2 -0
- package/dist/constants.js +19 -0
- package/dist/crypto.d.ts +76 -0
- package/dist/crypto.js +312 -0
- package/dist/dns/promises.d.ts +34 -0
- package/dist/dns/promises.js +190 -0
- package/dist/dns.d.ts +88 -0
- package/dist/dns.js +259 -0
- package/dist/events.d.ts +40 -0
- package/dist/events.js +237 -0
- package/dist/fs/promises.d.ts +159 -0
- package/dist/fs/promises.js +129 -0
- package/dist/fs.d.ts +221 -0
- package/dist/fs.js +944 -0
- package/dist/http.d.ts +92 -0
- package/dist/http.js +319 -0
- package/dist/https.d.ts +296 -0
- package/dist/https.js +50 -0
- package/dist/index.d.ts +2422 -0
- package/dist/index.js +57 -0
- package/dist/lib/bridge.d.ts +60 -0
- package/dist/lib/bridge.js +205 -0
- package/dist/lib/bytes.d.ts +20 -0
- package/dist/lib/bytes.js +239 -0
- package/dist/lib/child-process-types.d.ts +45 -0
- package/dist/lib/child-process-types.js +2 -0
- package/dist/lib/cwd.d.ts +2 -0
- package/dist/lib/cwd.js +32 -0
- package/dist/lib/deep-equal.d.ts +3 -0
- package/dist/lib/deep-equal.js +223 -0
- package/dist/lib/deflate.d.ts +2 -0
- package/dist/lib/deflate.js +234 -0
- package/dist/lib/dns-driver.d.ts +14 -0
- package/dist/lib/dns-driver.js +85 -0
- package/dist/lib/dns-types.d.ts +22 -0
- package/dist/lib/dns-types.js +2 -0
- package/dist/lib/errors.d.ts +48 -0
- package/dist/lib/errors.js +424 -0
- package/dist/lib/fs-driver.d.ts +70 -0
- package/dist/lib/fs-driver.js +364 -0
- package/dist/lib/fs-env.d.ts +30 -0
- package/dist/lib/fs-env.js +157 -0
- package/dist/lib/fs-types.d.ts +19 -0
- package/dist/lib/fs-types.js +2 -0
- package/dist/lib/hashes.d.ts +27 -0
- package/dist/lib/hashes.js +432 -0
- package/dist/lib/http-driver.d.ts +30 -0
- package/dist/lib/http-driver.js +72 -0
- package/dist/lib/http-types.d.ts +18 -0
- package/dist/lib/http-types.js +2 -0
- package/dist/lib/inflate.d.ts +6 -0
- package/dist/lib/inflate.js +284 -0
- package/dist/lib/path-types.d.ts +37 -0
- package/dist/lib/path-types.js +2 -0
- package/dist/lib/paths.d.ts +8 -0
- package/dist/lib/paths.js +106 -0
- package/dist/lib/perf-hooks-types.d.ts +18 -0
- package/dist/lib/perf-hooks-types.js +2 -0
- package/dist/lib/process-driver.d.ts +31 -0
- package/dist/lib/process-driver.js +102 -0
- package/dist/lib/punycode.d.ts +8 -0
- package/dist/lib/punycode.js +179 -0
- package/dist/lib/stream-types.d.ts +29 -0
- package/dist/lib/stream-types.js +2 -0
- package/dist/lib/timers-types.d.ts +18 -0
- package/dist/lib/timers-types.js +2 -0
- package/dist/lib/url-search-params.d.ts +26 -0
- package/dist/lib/url-search-params.js +281 -0
- package/dist/lib/url-types.d.ts +44 -0
- package/dist/lib/url-types.js +2 -0
- package/dist/lib/url-whatwg.d.ts +78 -0
- package/dist/lib/url-whatwg.js +857 -0
- package/dist/lib/zlib-types.d.ts +12 -0
- package/dist/lib/zlib-types.js +2 -0
- package/dist/module.d.ts +8 -0
- package/dist/module.js +72 -0
- package/dist/os.d.ts +80 -0
- package/dist/os.js +247 -0
- package/dist/path/posix.d.ts +2 -0
- package/dist/path/posix.js +7 -0
- package/dist/path/win32.d.ts +2 -0
- package/dist/path/win32.js +10 -0
- package/dist/path.d.ts +3 -0
- package/dist/path.js +1222 -0
- package/dist/perf_hooks.d.ts +36 -0
- package/dist/perf_hooks.js +144 -0
- package/dist/process.d.ts +69 -0
- package/dist/process.js +230 -0
- package/dist/querystring.d.ts +15 -0
- package/dist/querystring.js +209 -0
- package/dist/stream/promises.d.ts +5 -0
- package/dist/stream/promises.js +10 -0
- package/dist/stream.d.ts +84 -0
- package/dist/stream.js +875 -0
- package/dist/string_decoder.d.ts +15 -0
- package/dist/string_decoder.js +237 -0
- package/dist/timers/promises.d.ts +19 -0
- package/dist/timers/promises.js +74 -0
- package/dist/timers.d.ts +21 -0
- package/dist/timers.js +41 -0
- package/dist/tty.d.ts +9 -0
- package/dist/tty.js +25 -0
- package/dist/unsupported.d.ts +12 -0
- package/dist/unsupported.js +17 -0
- package/dist/url.d.ts +28 -0
- package/dist/url.js +486 -0
- package/dist/util.d.ts +74 -0
- package/dist/util.js +515 -0
- package/dist/zlib.d.ts +88 -0
- package/dist/zlib.js +371 -0
- package/package.json +29 -4
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ERRNO = void 0;
|
|
4
|
+
exports.createError = createError;
|
|
5
|
+
exports.onjError = onjError;
|
|
6
|
+
exports.parseJavaError = parseJavaError;
|
|
7
|
+
exports.codeForJavaException = codeForJavaException;
|
|
8
|
+
exports.javaError = javaError;
|
|
9
|
+
exports.withContext = withContext;
|
|
10
|
+
/**
|
|
11
|
+
* Node 错误码与 Java 异常之间的唯一翻译层。
|
|
12
|
+
*
|
|
13
|
+
* 设计约束:
|
|
14
|
+
* - 每个错误对象都必须带 code。三方库普遍靠 code 分支(fs.existsSync、mkdirp、tar 等),
|
|
15
|
+
* 没有 code 的实现等于跑不通。
|
|
16
|
+
* - Java 侧异常类名来自 bridge 的错误文本前缀,形如 "java.io.FileNotFoundException: /x"。
|
|
17
|
+
* - 未归类的 Java 异常一律映射为 EIO,并把原始类名与消息写进 message —— 这是明确定义的行为,
|
|
18
|
+
* Node 自己的 fs 在无法归类的系统错误上也报 EIO。
|
|
19
|
+
*/
|
|
20
|
+
/** 与 Linux errno 对齐,供依赖 errno 数值的三方库使用。 */
|
|
21
|
+
exports.ERRNO = {
|
|
22
|
+
EPERM: -1,
|
|
23
|
+
ENOENT: -2,
|
|
24
|
+
ESRCH: -3,
|
|
25
|
+
EINTR: -4,
|
|
26
|
+
EIO: -5,
|
|
27
|
+
ENXIO: -6,
|
|
28
|
+
E2BIG: -7,
|
|
29
|
+
ENOEXEC: -8,
|
|
30
|
+
EBADF: -9,
|
|
31
|
+
ECHILD: -10,
|
|
32
|
+
EAGAIN: -11,
|
|
33
|
+
EWOULDBLOCK: -11,
|
|
34
|
+
ENOMEM: -12,
|
|
35
|
+
EACCES: -13,
|
|
36
|
+
EFAULT: -14,
|
|
37
|
+
ENOTBLK: -15,
|
|
38
|
+
EBUSY: -16,
|
|
39
|
+
EEXIST: -17,
|
|
40
|
+
EXDEV: -18,
|
|
41
|
+
ENODEV: -19,
|
|
42
|
+
ENOTDIR: -20,
|
|
43
|
+
EISDIR: -21,
|
|
44
|
+
EINVAL: -22,
|
|
45
|
+
ENFILE: -23,
|
|
46
|
+
EMFILE: -24,
|
|
47
|
+
ENOTTY: -25,
|
|
48
|
+
ETXTBSY: -26,
|
|
49
|
+
EFBIG: -27,
|
|
50
|
+
ENOSPC: -28,
|
|
51
|
+
ESPIPE: -29,
|
|
52
|
+
EROFS: -30,
|
|
53
|
+
EMLINK: -31,
|
|
54
|
+
EPIPE: -32,
|
|
55
|
+
EDOM: -33,
|
|
56
|
+
ERANGE: -34,
|
|
57
|
+
EDEADLK: -35,
|
|
58
|
+
EDEADLOCK: -35,
|
|
59
|
+
ENAMETOOLONG: -36,
|
|
60
|
+
ENOLCK: -37,
|
|
61
|
+
ENOSYS: -38,
|
|
62
|
+
ENOTEMPTY: -39,
|
|
63
|
+
ELOOP: -40,
|
|
64
|
+
ENOMSG: -42,
|
|
65
|
+
EIDRM: -43,
|
|
66
|
+
ECHRNG: -44,
|
|
67
|
+
EL2NSYNC: -45,
|
|
68
|
+
EL3HLT: -46,
|
|
69
|
+
EL3RST: -47,
|
|
70
|
+
ELNRNG: -48,
|
|
71
|
+
EUNATCH: -49,
|
|
72
|
+
ENOCSI: -50,
|
|
73
|
+
EL2HLT: -51,
|
|
74
|
+
EBADE: -52,
|
|
75
|
+
EBADR: -53,
|
|
76
|
+
EXFULL: -54,
|
|
77
|
+
ENOANO: -55,
|
|
78
|
+
EBADRQC: -56,
|
|
79
|
+
EBADSLT: -57,
|
|
80
|
+
EBFONT: -59,
|
|
81
|
+
ENOSTR: -60,
|
|
82
|
+
ENODATA: -61,
|
|
83
|
+
ETIME: -62,
|
|
84
|
+
ENOSR: -63,
|
|
85
|
+
ENONET: -64,
|
|
86
|
+
ENOPKG: -65,
|
|
87
|
+
EREMOTE: -66,
|
|
88
|
+
ENOLINK: -67,
|
|
89
|
+
EADV: -68,
|
|
90
|
+
ESRMNT: -69,
|
|
91
|
+
ECOMM: -70,
|
|
92
|
+
EPROTO: -71,
|
|
93
|
+
EMULTIHOP: -72,
|
|
94
|
+
EDOTDOT: -73,
|
|
95
|
+
EBADMSG: -74,
|
|
96
|
+
EOVERFLOW: -75,
|
|
97
|
+
ENOTUNIQ: -76,
|
|
98
|
+
EBADFD: -77,
|
|
99
|
+
EREMCHG: -78,
|
|
100
|
+
ELIBACC: -79,
|
|
101
|
+
ELIBBAD: -80,
|
|
102
|
+
ELIBSCN: -81,
|
|
103
|
+
ELIBMAX: -82,
|
|
104
|
+
ELIBEXEC: -83,
|
|
105
|
+
EILSEQ: -84,
|
|
106
|
+
ERESTART: -85,
|
|
107
|
+
ESTRPIPE: -86,
|
|
108
|
+
EUSERS: -87,
|
|
109
|
+
ENOTSOCK: -88,
|
|
110
|
+
EDESTADDRREQ: -89,
|
|
111
|
+
EMSGSIZE: -90,
|
|
112
|
+
EPROTOTYPE: -91,
|
|
113
|
+
ENOPROTOOPT: -92,
|
|
114
|
+
EPROTONOSUPPORT: -93,
|
|
115
|
+
ESOCKTNOSUPPORT: -94,
|
|
116
|
+
EOPNOTSUPP: -95,
|
|
117
|
+
ENOTSUP: -95,
|
|
118
|
+
EPFNOSUPPORT: -96,
|
|
119
|
+
EAFNOSUPPORT: -97,
|
|
120
|
+
EADDRINUSE: -98,
|
|
121
|
+
EADDRNOTAVAIL: -99,
|
|
122
|
+
ENETDOWN: -100,
|
|
123
|
+
ENETUNREACH: -101,
|
|
124
|
+
ENETRESET: -102,
|
|
125
|
+
ECONNABORTED: -103,
|
|
126
|
+
ECONNRESET: -104,
|
|
127
|
+
ENOBUFS: -105,
|
|
128
|
+
EISCONN: -106,
|
|
129
|
+
ENOTCONN: -107,
|
|
130
|
+
ESHUTDOWN: -108,
|
|
131
|
+
ETOOMANYREFS: -109,
|
|
132
|
+
ETIMEDOUT: -110,
|
|
133
|
+
ECONNREFUSED: -111,
|
|
134
|
+
EHOSTDOWN: -112,
|
|
135
|
+
EHOSTUNREACH: -113,
|
|
136
|
+
EALREADY: -114,
|
|
137
|
+
EINPROGRESS: -115,
|
|
138
|
+
ESTALE: -116,
|
|
139
|
+
EUCLEAN: -117,
|
|
140
|
+
ENOTNAM: -118,
|
|
141
|
+
ENAVAIL: -119,
|
|
142
|
+
EISNAM: -120,
|
|
143
|
+
EREMOTEIO: -121,
|
|
144
|
+
EDQUOT: -122,
|
|
145
|
+
ENOMEDIUM: -123,
|
|
146
|
+
EMEDIUMTYPE: -124,
|
|
147
|
+
ECANCELED: -125,
|
|
148
|
+
ENOKEY: -126,
|
|
149
|
+
EKEYEXPIRED: -127,
|
|
150
|
+
EKEYREVOKED: -128,
|
|
151
|
+
EKEYREJECTED: -129,
|
|
152
|
+
EOWNERDEAD: -130,
|
|
153
|
+
ENOTRECOVERABLE: -131,
|
|
154
|
+
ERFKILL: -132,
|
|
155
|
+
EHWPOISON: -133
|
|
156
|
+
};
|
|
157
|
+
const MESSAGES = {
|
|
158
|
+
EPERM: 'operation not permitted',
|
|
159
|
+
ENOENT: 'no such file or directory',
|
|
160
|
+
ESRCH: 'no such process',
|
|
161
|
+
EINTR: 'interrupted system call',
|
|
162
|
+
EIO: 'input/output error',
|
|
163
|
+
ENXIO: 'no such device or address',
|
|
164
|
+
E2BIG: 'argument list too long',
|
|
165
|
+
ENOEXEC: 'exec format error',
|
|
166
|
+
EBADF: 'bad file descriptor',
|
|
167
|
+
ECHILD: 'no child processes',
|
|
168
|
+
EAGAIN: 'resource temporarily unavailable',
|
|
169
|
+
EWOULDBLOCK: 'resource temporarily unavailable',
|
|
170
|
+
ENOMEM: 'cannot allocate memory',
|
|
171
|
+
EACCES: 'permission denied',
|
|
172
|
+
EFAULT: 'bad address',
|
|
173
|
+
ENOTBLK: 'block device required',
|
|
174
|
+
EBUSY: 'device or resource busy',
|
|
175
|
+
EEXIST: 'file already exists',
|
|
176
|
+
EXDEV: 'invalid cross-device link',
|
|
177
|
+
ENODEV: 'no such device',
|
|
178
|
+
ENOTDIR: 'not a directory',
|
|
179
|
+
EISDIR: 'is a directory',
|
|
180
|
+
EINVAL: 'invalid argument',
|
|
181
|
+
ENFILE: 'too many open files in system',
|
|
182
|
+
EMFILE: 'too many open files',
|
|
183
|
+
ENOTTY: 'inappropriate ioctl for device',
|
|
184
|
+
ETXTBSY: 'text file busy',
|
|
185
|
+
EFBIG: 'file too large',
|
|
186
|
+
ENOSPC: 'no space left on device',
|
|
187
|
+
ESPIPE: 'illegal seek',
|
|
188
|
+
EROFS: 'read-only file system',
|
|
189
|
+
EMLINK: 'too many links',
|
|
190
|
+
EPIPE: 'broken pipe',
|
|
191
|
+
EDOM: 'numerical argument out of domain',
|
|
192
|
+
ERANGE: 'numerical result out of range',
|
|
193
|
+
EDEADLK: 'resource deadlock avoided',
|
|
194
|
+
EDEADLOCK: 'resource deadlock avoided',
|
|
195
|
+
ENAMETOOLONG: 'file name too long',
|
|
196
|
+
ENOLCK: 'no locks available',
|
|
197
|
+
ENOSYS: 'function not implemented',
|
|
198
|
+
ENOTEMPTY: 'directory not empty',
|
|
199
|
+
ELOOP: 'too many levels of symbolic links',
|
|
200
|
+
ENOMSG: 'no message of desired type',
|
|
201
|
+
EIDRM: 'identifier removed',
|
|
202
|
+
ECHRNG: 'channel number out of range',
|
|
203
|
+
EL2NSYNC: 'level 2 not synchronized',
|
|
204
|
+
EL3HLT: 'level 3 halted',
|
|
205
|
+
EL3RST: 'level 3 reset',
|
|
206
|
+
ELNRNG: 'link number out of range',
|
|
207
|
+
EUNATCH: 'protocol driver not attached',
|
|
208
|
+
ENOCSI: 'no CSI structure available',
|
|
209
|
+
EL2HLT: 'level 2 halted',
|
|
210
|
+
EBADE: 'invalid exchange',
|
|
211
|
+
EBADR: 'invalid request descriptor',
|
|
212
|
+
EXFULL: 'exchange full',
|
|
213
|
+
ENOANO: 'no anode',
|
|
214
|
+
EBADRQC: 'invalid request code',
|
|
215
|
+
EBADSLT: 'invalid slot',
|
|
216
|
+
EBFONT: 'bad font file format',
|
|
217
|
+
ENOSTR: 'device not a stream',
|
|
218
|
+
ENODATA: 'no data available',
|
|
219
|
+
ETIME: 'timer expired',
|
|
220
|
+
ENOSR: 'out of streams resources',
|
|
221
|
+
ENONET: 'machine is not on the network',
|
|
222
|
+
ENOPKG: 'package not installed',
|
|
223
|
+
EREMOTE: 'object is remote',
|
|
224
|
+
ENOLINK: 'link has been severed',
|
|
225
|
+
EADV: 'advertise error',
|
|
226
|
+
ESRMNT: 'srmount error',
|
|
227
|
+
ECOMM: 'communication error on send',
|
|
228
|
+
EPROTO: 'protocol error',
|
|
229
|
+
EMULTIHOP: 'multihop attempted',
|
|
230
|
+
EDOTDOT: 'RFS specific error',
|
|
231
|
+
EBADMSG: 'bad message',
|
|
232
|
+
EOVERFLOW: 'value too large for defined data type',
|
|
233
|
+
ENOTUNIQ: 'name not unique on network',
|
|
234
|
+
EBADFD: 'file descriptor in bad state',
|
|
235
|
+
EREMCHG: 'remote address changed',
|
|
236
|
+
ELIBACC: 'can not access a needed shared library',
|
|
237
|
+
ELIBBAD: 'accessing a corrupted shared library',
|
|
238
|
+
ELIBSCN: '.lib section in a.out corrupted',
|
|
239
|
+
ELIBMAX: 'attempting to link in too many shared libraries',
|
|
240
|
+
ELIBEXEC: 'cannot exec a shared library directly',
|
|
241
|
+
EILSEQ: 'invalid or incomplete multibyte or wide character',
|
|
242
|
+
ERESTART: 'interrupted system call should be restarted',
|
|
243
|
+
ESTRPIPE: 'streams pipe error',
|
|
244
|
+
EUSERS: 'too many users',
|
|
245
|
+
ENOTSOCK: 'socket operation on non-socket',
|
|
246
|
+
EDESTADDRREQ: 'destination address required',
|
|
247
|
+
EMSGSIZE: 'message too long',
|
|
248
|
+
EPROTOTYPE: 'protocol wrong type for socket',
|
|
249
|
+
ENOPROTOOPT: 'protocol not available',
|
|
250
|
+
EPROTONOSUPPORT: 'protocol not supported',
|
|
251
|
+
ESOCKTNOSUPPORT: 'socket type not supported',
|
|
252
|
+
EOPNOTSUPP: 'operation not supported',
|
|
253
|
+
ENOTSUP: 'operation not supported',
|
|
254
|
+
EPFNOSUPPORT: 'protocol family not supported',
|
|
255
|
+
EAFNOSUPPORT: 'address family not supported by protocol',
|
|
256
|
+
EADDRINUSE: 'address already in use',
|
|
257
|
+
EADDRNOTAVAIL: 'cannot assign requested address',
|
|
258
|
+
ENETDOWN: 'network is down',
|
|
259
|
+
ENETUNREACH: 'network is unreachable',
|
|
260
|
+
ENETRESET: 'network dropped connection on reset',
|
|
261
|
+
ECONNABORTED: 'software caused connection abort',
|
|
262
|
+
ECONNRESET: 'connection reset by peer',
|
|
263
|
+
ENOBUFS: 'no buffer space available',
|
|
264
|
+
EISCONN: 'transport endpoint is already connected',
|
|
265
|
+
ENOTCONN: 'transport endpoint is not connected',
|
|
266
|
+
ESHUTDOWN: 'cannot send after transport endpoint shutdown',
|
|
267
|
+
ETOOMANYREFS: 'too many references: cannot splice',
|
|
268
|
+
ETIMEDOUT: 'connection timed out',
|
|
269
|
+
ECONNREFUSED: 'connection refused',
|
|
270
|
+
EHOSTDOWN: 'host is down',
|
|
271
|
+
EHOSTUNREACH: 'no route to host',
|
|
272
|
+
EALREADY: 'operation already in progress',
|
|
273
|
+
EINPROGRESS: 'operation now in progress',
|
|
274
|
+
ESTALE: 'stale file handle',
|
|
275
|
+
EUCLEAN: 'structure needs cleaning',
|
|
276
|
+
ENOTNAM: 'not a XENIX named type file',
|
|
277
|
+
ENAVAIL: 'no XENIX semaphores available',
|
|
278
|
+
EISNAM: 'is a named type file',
|
|
279
|
+
EREMOTEIO: 'remote I/O error',
|
|
280
|
+
EDQUOT: 'disk quota exceeded',
|
|
281
|
+
ENOMEDIUM: 'no medium found',
|
|
282
|
+
EMEDIUMTYPE: 'wrong medium type',
|
|
283
|
+
ECANCELED: 'operation canceled',
|
|
284
|
+
ENOKEY: 'required key not available',
|
|
285
|
+
EKEYEXPIRED: 'key has expired',
|
|
286
|
+
EKEYREVOKED: 'key has been revoked',
|
|
287
|
+
EKEYREJECTED: 'key was rejected by service',
|
|
288
|
+
EOWNERDEAD: 'owner died',
|
|
289
|
+
ENOTRECOVERABLE: 'state not recoverable',
|
|
290
|
+
ERFKILL: 'operation not possible due to RF-kill',
|
|
291
|
+
EHWPOISON: 'memory page has hardware error'
|
|
292
|
+
};
|
|
293
|
+
/** node.operit 自有错误码:只描述库内部状态,不占用 POSIX 命名空间。 */
|
|
294
|
+
const ONJ_MESSAGE = {
|
|
295
|
+
ONJ_MISSING_HOST: 'node.operit 需要在 Operit 运行时中执行(NativeInterface 不可用)。',
|
|
296
|
+
ONJ_BRIDGE_PROTOCOL: 'Java bridge 返回了不符合约定的内容。',
|
|
297
|
+
ONJ_UNKNOWN_ENV: 'fs 环境未注册。',
|
|
298
|
+
ONJ_ENV_UNAVAILABLE: 'fs 环境的根不可用。',
|
|
299
|
+
ONJ_ENV_ASYNC_SCOPE: 'fs.env.with() 的回调必须是同步的。',
|
|
300
|
+
ONJ_ENV_NOT_SET: 'fs 环境未显式设置,而当前处于 strict 模式。',
|
|
301
|
+
ONJ_UNSUPPORTED: '该能力在 Operit 的 QuickJS 运行时不成立。'
|
|
302
|
+
};
|
|
303
|
+
/** Java 异常类名 → Node 错误码的精确表。 */
|
|
304
|
+
const JAVA_CODE = {
|
|
305
|
+
'java.io.FileNotFoundException': 'ENOENT',
|
|
306
|
+
'java.nio.file.NoSuchFileException': 'ENOENT',
|
|
307
|
+
'java.io.FileSystemException': 'EIO',
|
|
308
|
+
'java.nio.file.FileSystemException': 'EIO',
|
|
309
|
+
'java.nio.file.FileSystemLoopException': 'ELOOP',
|
|
310
|
+
'java.nio.file.AccessDeniedException': 'EACCES',
|
|
311
|
+
'java.lang.SecurityException': 'EACCES',
|
|
312
|
+
'java.nio.file.FileAlreadyExistsException': 'EEXIST',
|
|
313
|
+
'java.nio.file.NotDirectoryException': 'ENOTDIR',
|
|
314
|
+
'java.nio.file.DirectoryNotEmptyException': 'ENOTEMPTY',
|
|
315
|
+
'java.nio.file.NotLinkException': 'EINVAL',
|
|
316
|
+
'java.io.EOFException': 'EIO',
|
|
317
|
+
'java.io.IOException': 'EIO',
|
|
318
|
+
'java.io.UnsupportedEncodingException': 'EINVAL',
|
|
319
|
+
'java.lang.IllegalArgumentException': 'EINVAL',
|
|
320
|
+
'java.lang.IllegalStateException': 'EINVAL',
|
|
321
|
+
'java.lang.NullPointerException': 'EINVAL'
|
|
322
|
+
};
|
|
323
|
+
/** 构造一个 Node 形状的错误。syscall / path / dest 与 Node 自身的字段语义一致。 */
|
|
324
|
+
function createError(code, syscall, targetPath, destPath) {
|
|
325
|
+
const base = MESSAGES[code] ?? 'unknown error';
|
|
326
|
+
let message = code + ': ' + base + ', ' + syscall;
|
|
327
|
+
if (targetPath !== undefined && targetPath !== null) {
|
|
328
|
+
message += " '" + targetPath + "'";
|
|
329
|
+
}
|
|
330
|
+
if (destPath !== undefined && destPath !== null) {
|
|
331
|
+
message += " -> '" + destPath + "'";
|
|
332
|
+
}
|
|
333
|
+
const err = new Error(message);
|
|
334
|
+
err.code = code;
|
|
335
|
+
err.errno = Object.prototype.hasOwnProperty.call(exports.ERRNO, code) ? exports.ERRNO[code] : -1;
|
|
336
|
+
err.syscall = syscall;
|
|
337
|
+
if (targetPath !== undefined && targetPath !== null) {
|
|
338
|
+
err.path = targetPath;
|
|
339
|
+
}
|
|
340
|
+
if (destPath !== undefined && destPath !== null) {
|
|
341
|
+
err.dest = destPath;
|
|
342
|
+
}
|
|
343
|
+
return err;
|
|
344
|
+
}
|
|
345
|
+
/** node.operit 内部状态错误。 */
|
|
346
|
+
function onjError(code, detail) {
|
|
347
|
+
const base = ONJ_MESSAGE[code] ?? code;
|
|
348
|
+
const message = detail !== undefined && detail.length > 0 ? base + ' ' + detail : base;
|
|
349
|
+
const err = new Error('[' + code + '] ' + message);
|
|
350
|
+
err.code = code;
|
|
351
|
+
return err;
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* 从 Java bridge 的错误文本里剥离异常类名。
|
|
355
|
+
* 形如 "java.io.FileNotFoundException: /sdcard/x" 或 "java.lang.SecurityException"。
|
|
356
|
+
*/
|
|
357
|
+
function parseJavaError(text) {
|
|
358
|
+
const source = typeof text === 'string' ? text : String(text);
|
|
359
|
+
const match = /^([A-Za-z_$][A-Za-z0-9_$]*(?:\.[A-Za-z_$][A-Za-z0-9_$]*)*):?\s*([\s\S]*)$/.exec(source);
|
|
360
|
+
if (match === null) {
|
|
361
|
+
return { className: 'java.lang.Throwable', message: source };
|
|
362
|
+
}
|
|
363
|
+
return {
|
|
364
|
+
className: match[1],
|
|
365
|
+
message: match[2].length > 0 ? match[2] : source
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Java 异常类名 → Node 错误码。
|
|
370
|
+
* 先查精确表,再按消息特征识别少数几种,仍未命中则 EIO。
|
|
371
|
+
*/
|
|
372
|
+
function codeForJavaException(className, javaMessage) {
|
|
373
|
+
// 消息特征优先:java.io.IOException 是通用类,精确表只能给出 EIO,
|
|
374
|
+
// 而 "No space left on device" 这类消息能给出更准确的码。
|
|
375
|
+
if (/No space left on device/i.test(javaMessage)) {
|
|
376
|
+
return 'ENOSPC';
|
|
377
|
+
}
|
|
378
|
+
if (/Read-only file system/i.test(javaMessage)) {
|
|
379
|
+
return 'EROFS';
|
|
380
|
+
}
|
|
381
|
+
if (/Too many open files/i.test(javaMessage)) {
|
|
382
|
+
return 'EMFILE';
|
|
383
|
+
}
|
|
384
|
+
// ProcessBuilder.start() 找不到可执行文件时是 IOException + 这段消息
|
|
385
|
+
if (/No such file or directory/i.test(javaMessage)) {
|
|
386
|
+
return 'ENOENT';
|
|
387
|
+
}
|
|
388
|
+
if (/Is a directory/i.test(javaMessage)) {
|
|
389
|
+
return 'EISDIR';
|
|
390
|
+
}
|
|
391
|
+
if (/Not a directory/i.test(javaMessage)) {
|
|
392
|
+
return 'ENOTDIR';
|
|
393
|
+
}
|
|
394
|
+
const exact = JAVA_CODE[className];
|
|
395
|
+
if (exact !== undefined) {
|
|
396
|
+
return exact;
|
|
397
|
+
}
|
|
398
|
+
return 'EIO';
|
|
399
|
+
}
|
|
400
|
+
/** 由 Java 错误文本构造中间态错误,保留原始类名与消息。 */
|
|
401
|
+
function javaError(text) {
|
|
402
|
+
const parsed = parseJavaError(text);
|
|
403
|
+
const err = new Error(parsed.className + ': ' + parsed.message);
|
|
404
|
+
err.code = codeForJavaException(parsed.className, parsed.message);
|
|
405
|
+
err.javaClass = parsed.className;
|
|
406
|
+
err.javaMessage = parsed.message;
|
|
407
|
+
err.isJavaError = true;
|
|
408
|
+
return err;
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* 给中间态错误补上 syscall / path,产出语义完整的 Node 错误。
|
|
412
|
+
* 非 Java 错误原样返回。
|
|
413
|
+
*/
|
|
414
|
+
function withContext(err, syscall, targetPath, destPath) {
|
|
415
|
+
const candidate = err;
|
|
416
|
+
if (candidate === null || candidate === undefined || candidate.isJavaError !== true) {
|
|
417
|
+
return err;
|
|
418
|
+
}
|
|
419
|
+
const out = createError(candidate.code, syscall, targetPath, destPath);
|
|
420
|
+
out.cause = candidate;
|
|
421
|
+
out.javaClass = candidate.javaClass;
|
|
422
|
+
out.javaMessage = candidate.javaMessage;
|
|
423
|
+
return out;
|
|
424
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
export interface FileStat {
|
|
2
|
+
isFile: boolean;
|
|
3
|
+
isDirectory: boolean;
|
|
4
|
+
isSymbolicLink: boolean;
|
|
5
|
+
size: number;
|
|
6
|
+
mode: number;
|
|
7
|
+
atimeMs: number;
|
|
8
|
+
mtimeMs: number;
|
|
9
|
+
ctimeMs: number;
|
|
10
|
+
birthtimeMs: number;
|
|
11
|
+
}
|
|
12
|
+
export interface DirectoryEntry {
|
|
13
|
+
name: string;
|
|
14
|
+
isFile: boolean;
|
|
15
|
+
isDirectory: boolean;
|
|
16
|
+
isSymbolicLink: boolean;
|
|
17
|
+
}
|
|
18
|
+
/** fd 语义下的打开选项,由 fs.ts 从 flag 解析后传入。 */
|
|
19
|
+
export interface OpenHandleOptions {
|
|
20
|
+
readable: boolean;
|
|
21
|
+
writable: boolean;
|
|
22
|
+
append: boolean;
|
|
23
|
+
exclusive: boolean;
|
|
24
|
+
truncate: boolean;
|
|
25
|
+
}
|
|
26
|
+
/** 一个打开的句柄。position 为 null 表示"用当前位置并推进",与 Node 的 fd 语义一致。 */
|
|
27
|
+
export interface FileHandle {
|
|
28
|
+
read(position: number | null, length: number): Uint8Array;
|
|
29
|
+
write(position: number | null, data: Uint8Array): number;
|
|
30
|
+
size(): number;
|
|
31
|
+
truncate(length: number): void;
|
|
32
|
+
sync(): void;
|
|
33
|
+
close(): void;
|
|
34
|
+
}
|
|
35
|
+
export interface FsDriver {
|
|
36
|
+
openHandle(target: string, options: OpenHandleOptions): FileHandle;
|
|
37
|
+
stat(target: string, followLinks: boolean): FileStat;
|
|
38
|
+
exists(target: string): boolean;
|
|
39
|
+
readdir(target: string): DirectoryEntry[];
|
|
40
|
+
readFileBytes(target: string): Uint8Array;
|
|
41
|
+
writeFileBytes(target: string, data: Uint8Array, append: boolean, exclusive: boolean): void;
|
|
42
|
+
mkdir(target: string, recursive: boolean): string | undefined;
|
|
43
|
+
remove(target: string, recursive: boolean, force: boolean): void;
|
|
44
|
+
rename(from: string, to: string): void;
|
|
45
|
+
copyFile(from: string, to: string): void;
|
|
46
|
+
realpath(target: string): string;
|
|
47
|
+
readlink(target: string): string;
|
|
48
|
+
symlink(target: string, linkPath: string): void;
|
|
49
|
+
chmod(target: string, mode: number): void;
|
|
50
|
+
truncate(target: string, length: number): void;
|
|
51
|
+
utimes(target: string, atimeMs: number, mtimeMs: number): void;
|
|
52
|
+
mkdtemp(prefix: string): string;
|
|
53
|
+
}
|
|
54
|
+
/** 宿主注入点:桌面测试用,传 null 恢复为 Operit Java 驱动。 */
|
|
55
|
+
export declare function setDriver(next: FsDriver | null): void;
|
|
56
|
+
export declare function getDriver(): FsDriver;
|
|
57
|
+
/**
|
|
58
|
+
* 基于 java.io.File / java.nio.file.Files / java.io.RandomAccessFile 的驱动。
|
|
59
|
+
*
|
|
60
|
+
* 通道选择(对应 DESIGN.md §6.3):
|
|
61
|
+
* - 读:Files.readAllBytes(Path) 返回 byte[],bridge 会展开成 JSON 数字数组,直接用
|
|
62
|
+
* - 写:RandomAccessFile.writeBytes(String) 写每个字符的低 8 位 —— 正好是 latin1 通道,
|
|
63
|
+
* 避免了"把 JS 数组当 byte[] 参数传进去"这类未验证行为
|
|
64
|
+
*
|
|
65
|
+
* 已知近似(真机验证时要确认):
|
|
66
|
+
* - atime / ctime / birthtime 都取 lastModified
|
|
67
|
+
* - mode 按类型给默认值,不反映真实权限位
|
|
68
|
+
* - readdir 不区分符号链接
|
|
69
|
+
*/
|
|
70
|
+
export declare function createJavaDriver(): FsDriver;
|