@serveryyswys/node.operit 0.1.3 → 0.1.5
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 +16 -8
- package/dist/buffer.d.ts +7 -0
- package/dist/buffer.js +24 -1
- package/dist/crypto.d.ts +5 -0
- package/dist/crypto.js +24 -0
- package/dist/fs.d.ts +7 -0
- package/dist/fs.js +9 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.js +1 -1
- package/dist/util/types.d.ts +1 -0
- package/dist/util.d.ts +1 -0
- package/dist/util.js +4 -0
- package/dist/zlib.d.ts +22 -0
- package/dist/zlib.js +25 -0
- package/package.json +2 -1
package/BUILTINS.json
CHANGED
|
@@ -17,11 +17,13 @@
|
|
|
17
17
|
"builtins": {
|
|
18
18
|
"path": {
|
|
19
19
|
"subpath": "path",
|
|
20
|
-
"status": "ready"
|
|
20
|
+
"status": "ready",
|
|
21
|
+
"note": "与 Node 对拍通过;见 README 的对应说明。"
|
|
21
22
|
},
|
|
22
23
|
"path/posix": {
|
|
23
24
|
"subpath": "path/posix",
|
|
24
|
-
"status": "ready"
|
|
25
|
+
"status": "ready",
|
|
26
|
+
"note": "与 Node 对拍通过;见 README 的对应说明。"
|
|
25
27
|
},
|
|
26
28
|
"path/win32": {
|
|
27
29
|
"subpath": "path/win32",
|
|
@@ -165,27 +167,33 @@
|
|
|
165
167
|
},
|
|
166
168
|
"vm": {
|
|
167
169
|
"status": "unsupported",
|
|
168
|
-
"
|
|
170
|
+
"note": "QuickJS 运行时未暴露独立上下文创建能力。",
|
|
171
|
+
"subpath": "vm"
|
|
169
172
|
},
|
|
170
173
|
"worker_threads": {
|
|
171
174
|
"status": "unsupported",
|
|
172
|
-
"
|
|
175
|
+
"note": "QuickJS 运行时为单线程解释器,无 worker 能力。",
|
|
176
|
+
"subpath": "worker_threads"
|
|
173
177
|
},
|
|
174
178
|
"cluster": {
|
|
175
179
|
"status": "unsupported",
|
|
176
|
-
"
|
|
180
|
+
"note": "依赖 worker_threads。",
|
|
181
|
+
"subpath": "cluster"
|
|
177
182
|
},
|
|
178
183
|
"async_hooks": {
|
|
179
184
|
"status": "unsupported",
|
|
180
|
-
"
|
|
185
|
+
"note": "QuickJS 未暴露异步资源跟踪钩子。",
|
|
186
|
+
"subpath": "async_hooks"
|
|
181
187
|
},
|
|
182
188
|
"inspector": {
|
|
183
189
|
"status": "unsupported",
|
|
184
|
-
"
|
|
190
|
+
"note": "无 V8 inspector 协议。",
|
|
191
|
+
"subpath": "inspector"
|
|
185
192
|
},
|
|
186
193
|
"repl": {
|
|
187
194
|
"status": "unsupported",
|
|
188
|
-
"
|
|
195
|
+
"note": "无 stdin/stdout 终端语义。",
|
|
196
|
+
"subpath": "repl"
|
|
189
197
|
},
|
|
190
198
|
"tty": {
|
|
191
199
|
"subpath": "tty",
|
package/dist/buffer.d.ts
CHANGED
|
@@ -57,4 +57,11 @@ export declare const kMaxLength: number;
|
|
|
57
57
|
export declare const INSPECT_MAX_BYTES = 50;
|
|
58
58
|
/** 把普通 Uint8Array 变成 Buffer 实例(不改内容、不拷贝)。 */
|
|
59
59
|
export declare function wrap(source: Uint8Array): Buffer;
|
|
60
|
+
/**
|
|
61
|
+
* Node 的 buffer **模块**把这些直接挂在模块上(不只是挂在 Buffer 类上)。
|
|
62
|
+
* 包写 `require('buffer').SlowBuffer` 是能拿到的,所以两边都要有。
|
|
63
|
+
*/
|
|
64
|
+
export declare const SlowBuffer: typeof Buffer;
|
|
65
|
+
/** 需要 ICU 字符集转换,运行时没有 —— 显式拒绝而不是静默返回空 Buffer。 */
|
|
66
|
+
export declare function transcode(): never;
|
|
60
67
|
export default Buffer;
|
package/dist/buffer.js
CHANGED
|
@@ -33,8 +33,10 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.INSPECT_MAX_BYTES = exports.kMaxLength = exports.constants = exports.Buffer = void 0;
|
|
36
|
+
exports.SlowBuffer = exports.INSPECT_MAX_BYTES = exports.kMaxLength = exports.constants = exports.Buffer = void 0;
|
|
37
37
|
exports.wrap = wrap;
|
|
38
|
+
exports.transcode = transcode;
|
|
39
|
+
const unsupportedNodeBuiltin = require("./unsupported");
|
|
38
40
|
/**
|
|
39
41
|
* Node Buffer 的移植。
|
|
40
42
|
*
|
|
@@ -498,6 +500,18 @@ function checkOffset(offset, size, length) {
|
|
|
498
500
|
}
|
|
499
501
|
return offset;
|
|
500
502
|
}
|
|
503
|
+
/**
|
|
504
|
+
* Node 的 Buffer.SlowBuffer:历史别名,等价于 Buffer 本身。
|
|
505
|
+
* 放在可枚举化那一遍**之前**,这样它和别的静态成员一样可枚举。
|
|
506
|
+
*/
|
|
507
|
+
Buffer.SlowBuffer = Buffer;
|
|
508
|
+
/**
|
|
509
|
+
* Node 的 Buffer.transcode 做的是 ICU 字符集转换,运行时没有 ICU。
|
|
510
|
+
* 显式抛 ONJ_UNSUPPORTED,而不是给一个静默返回空 Buffer 的实现。
|
|
511
|
+
*/
|
|
512
|
+
Buffer.transcode = function transcode() {
|
|
513
|
+
return unsupportedNodeBuiltin('Buffer.transcode');
|
|
514
|
+
};
|
|
501
515
|
/**
|
|
502
516
|
* 把静态成员补成**可枚举的自有属性**。
|
|
503
517
|
*
|
|
@@ -521,4 +535,13 @@ for (const staticKey of Object.getOwnPropertyNames(Buffer)) {
|
|
|
521
535
|
});
|
|
522
536
|
}
|
|
523
537
|
}
|
|
538
|
+
/**
|
|
539
|
+
* Node 的 buffer **模块**把这些直接挂在模块上(不只是挂在 Buffer 类上)。
|
|
540
|
+
* 包写 `require('buffer').SlowBuffer` 是能拿到的,所以两边都要有。
|
|
541
|
+
*/
|
|
542
|
+
exports.SlowBuffer = Buffer;
|
|
543
|
+
/** 需要 ICU 字符集转换,运行时没有 —— 显式拒绝而不是静默返回空 Buffer。 */
|
|
544
|
+
function transcode() {
|
|
545
|
+
return unsupportedNodeBuiltin('Buffer.transcode');
|
|
546
|
+
}
|
|
524
547
|
exports.default = Buffer;
|
package/dist/crypto.d.ts
CHANGED
|
@@ -42,6 +42,11 @@ declare function createVerify(): never;
|
|
|
42
42
|
declare function generateKeyPairSync(): never;
|
|
43
43
|
declare function createDiffieHellman(): never;
|
|
44
44
|
declare const crypto: {
|
|
45
|
+
webcrypto: {
|
|
46
|
+
getRandomValues<T extends ArrayBufferView>(array: T): T;
|
|
47
|
+
randomUUID: typeof randomUUID;
|
|
48
|
+
subtle: Record<string | symbol, unknown>;
|
|
49
|
+
};
|
|
45
50
|
createHash: typeof createHash;
|
|
46
51
|
createHmac: typeof createHmac;
|
|
47
52
|
randomBytes: typeof randomBytes;
|
package/dist/crypto.js
CHANGED
|
@@ -287,7 +287,31 @@ const constants = {
|
|
|
287
287
|
SSL_OP_NO_SSLv3: 0,
|
|
288
288
|
SSL_OP_NO_TLSv1: 0
|
|
289
289
|
};
|
|
290
|
+
/**
|
|
291
|
+
* Web Crypto 的最小可用面。
|
|
292
|
+
*
|
|
293
|
+
* getRandomValues / randomUUID 是真实现的(走同一条强随机源);
|
|
294
|
+
* subtle 整个是"存在但每个操作都显式拒绝"—— 运行时不提供 WebCrypto 的算法实现,
|
|
295
|
+
* 给一个看起来像但结果不对的契约比明确报错更糟。
|
|
296
|
+
*/
|
|
297
|
+
const webcrypto = {
|
|
298
|
+
getRandomValues(array) {
|
|
299
|
+
const bytes = randomBytes(array.length);
|
|
300
|
+
array.set(bytes);
|
|
301
|
+
return array;
|
|
302
|
+
},
|
|
303
|
+
randomUUID: randomUUID,
|
|
304
|
+
subtle: new Proxy({}, {
|
|
305
|
+
get(_target, property) {
|
|
306
|
+
if (property === Symbol.toStringTag || property === 'then' || property === 'toJSON' || property === 'inspect') {
|
|
307
|
+
return undefined;
|
|
308
|
+
}
|
|
309
|
+
throw unsupported('crypto.webcrypto.subtle.' + String(property));
|
|
310
|
+
}
|
|
311
|
+
})
|
|
312
|
+
};
|
|
290
313
|
const crypto = {
|
|
314
|
+
webcrypto: webcrypto,
|
|
291
315
|
createHash: createHash,
|
|
292
316
|
createHmac: createHmac,
|
|
293
317
|
randomBytes: randomBytes,
|
package/dist/fs.d.ts
CHANGED
|
@@ -115,6 +115,13 @@ declare function createReadStream(target: unknown, options?: ReadStreamOptions):
|
|
|
115
115
|
*/
|
|
116
116
|
declare function createWriteStream(target: unknown, options?: WriteStreamOptions): WriteStreamLike;
|
|
117
117
|
declare const fs: {
|
|
118
|
+
/**
|
|
119
|
+
* `require('fs').promises` —— 与 fs/promises 子路径**同一个对象**。
|
|
120
|
+
*
|
|
121
|
+
* 用惰性 getter 而不是直接 require:fs/promises 自己也 require fs,直接写会成环。
|
|
122
|
+
* getter 在对象字面量里是可枚举的,所以 for...in 探测(safer-buffer 那种)也能看到它。
|
|
123
|
+
*/
|
|
124
|
+
readonly promises: unknown;
|
|
118
125
|
readFileSync: typeof readFileSync;
|
|
119
126
|
writeFileSync: typeof writeFileSync;
|
|
120
127
|
appendFileSync: typeof appendFileSync;
|
package/dist/fs.js
CHANGED
|
@@ -882,6 +882,15 @@ const constants = {
|
|
|
882
882
|
S_IXOTH: 1
|
|
883
883
|
};
|
|
884
884
|
const fs = {
|
|
885
|
+
/**
|
|
886
|
+
* `require('fs').promises` —— 与 fs/promises 子路径**同一个对象**。
|
|
887
|
+
*
|
|
888
|
+
* 用惰性 getter 而不是直接 require:fs/promises 自己也 require fs,直接写会成环。
|
|
889
|
+
* getter 在对象字面量里是可枚举的,所以 for...in 探测(safer-buffer 那种)也能看到它。
|
|
890
|
+
*/
|
|
891
|
+
get promises() {
|
|
892
|
+
return require('./fs/promises');
|
|
893
|
+
},
|
|
885
894
|
readFileSync: readFileSync,
|
|
886
895
|
writeFileSync: writeFileSync,
|
|
887
896
|
appendFileSync: appendFileSync,
|
package/dist/index.d.ts
CHANGED
|
@@ -27,6 +27,7 @@ declare const api: {
|
|
|
27
27
|
stripVTControlCharacters: (value: string) => string;
|
|
28
28
|
isDeepStrictEqual: (left: unknown, right: unknown) => boolean;
|
|
29
29
|
types: {
|
|
30
|
+
isAnyArrayBuffer: (value: unknown) => boolean;
|
|
30
31
|
isDate: (value: unknown) => boolean;
|
|
31
32
|
isRegExp: (value: unknown) => boolean;
|
|
32
33
|
isArray: (value: unknown) => boolean;
|
|
@@ -71,6 +72,7 @@ declare const api: {
|
|
|
71
72
|
finished: (stream: unknown) => Promise<void>;
|
|
72
73
|
};
|
|
73
74
|
fs: {
|
|
75
|
+
readonly promises: unknown;
|
|
74
76
|
readFileSync: (target: unknown, options?: unknown) => string | bufferModule.Buffer;
|
|
75
77
|
writeFileSync: (target: unknown, data: unknown, options?: unknown) => void;
|
|
76
78
|
appendFileSync: (target: unknown, data: unknown, options?: unknown) => void;
|
|
@@ -592,6 +594,11 @@ declare const api: {
|
|
|
592
594
|
eventNames(): (string | symbol)[];
|
|
593
595
|
};
|
|
594
596
|
crypto: {
|
|
597
|
+
webcrypto: {
|
|
598
|
+
getRandomValues<T extends ArrayBufferView>(array: T): T;
|
|
599
|
+
randomUUID: () => string;
|
|
600
|
+
subtle: Record<string | symbol, unknown>;
|
|
601
|
+
};
|
|
595
602
|
createHash: (algorithm: string, options?: {
|
|
596
603
|
outputLength?: number;
|
|
597
604
|
}) => {
|
|
@@ -664,6 +671,38 @@ declare const api: {
|
|
|
664
671
|
};
|
|
665
672
|
};
|
|
666
673
|
zlib: {
|
|
674
|
+
Zlib: {
|
|
675
|
+
new (options?: import("./lib/zlib-types").DeflateOptions): unknown;
|
|
676
|
+
prototype: object;
|
|
677
|
+
};
|
|
678
|
+
Deflate: {
|
|
679
|
+
new (options?: import("./lib/zlib-types").DeflateOptions): unknown;
|
|
680
|
+
prototype: object;
|
|
681
|
+
};
|
|
682
|
+
Inflate: {
|
|
683
|
+
new (options?: import("./lib/zlib-types").DeflateOptions): unknown;
|
|
684
|
+
prototype: object;
|
|
685
|
+
};
|
|
686
|
+
DeflateRaw: {
|
|
687
|
+
new (options?: import("./lib/zlib-types").DeflateOptions): unknown;
|
|
688
|
+
prototype: object;
|
|
689
|
+
};
|
|
690
|
+
InflateRaw: {
|
|
691
|
+
new (options?: import("./lib/zlib-types").DeflateOptions): unknown;
|
|
692
|
+
prototype: object;
|
|
693
|
+
};
|
|
694
|
+
Gzip: {
|
|
695
|
+
new (options?: import("./lib/zlib-types").DeflateOptions): unknown;
|
|
696
|
+
prototype: object;
|
|
697
|
+
};
|
|
698
|
+
Gunzip: {
|
|
699
|
+
new (options?: import("./lib/zlib-types").DeflateOptions): unknown;
|
|
700
|
+
prototype: object;
|
|
701
|
+
};
|
|
702
|
+
Unzip: {
|
|
703
|
+
new (options?: import("./lib/zlib-types").DeflateOptions): unknown;
|
|
704
|
+
prototype: object;
|
|
705
|
+
};
|
|
667
706
|
deflateSync: (input: unknown, options?: import("./lib/zlib-types").DeflateOptions) => bufferModule.Buffer;
|
|
668
707
|
inflateSync: (input: unknown) => bufferModule.Buffer;
|
|
669
708
|
deflateRawSync: (input: unknown, options?: import("./lib/zlib-types").DeflateOptions) => bufferModule.Buffer;
|
|
@@ -2693,6 +2732,7 @@ declare const api: {
|
|
|
2693
2732
|
timeStamp: () => void;
|
|
2694
2733
|
};
|
|
2695
2734
|
'util/types': {
|
|
2735
|
+
isAnyArrayBuffer: (value: unknown) => boolean;
|
|
2696
2736
|
isDate: (value: unknown) => boolean;
|
|
2697
2737
|
isRegExp: (value: unknown) => boolean;
|
|
2698
2738
|
isArray: (value: unknown) => boolean;
|
|
@@ -2722,6 +2762,7 @@ declare const api: {
|
|
|
2722
2762
|
stripVTControlCharacters: (value: string) => string;
|
|
2723
2763
|
isDeepStrictEqual: (left: unknown, right: unknown) => boolean;
|
|
2724
2764
|
types: {
|
|
2765
|
+
isAnyArrayBuffer: (value: unknown) => boolean;
|
|
2725
2766
|
isDate: (value: unknown) => boolean;
|
|
2726
2767
|
isRegExp: (value: unknown) => boolean;
|
|
2727
2768
|
isArray: (value: unknown) => boolean;
|
package/dist/index.js
CHANGED
|
@@ -51,7 +51,7 @@ const diagnosticsChannelModule = require("./diagnostics_channel");
|
|
|
51
51
|
const streamConsumersModule = require("./stream/consumers");
|
|
52
52
|
const v8Module = require("./v8");
|
|
53
53
|
const api = {
|
|
54
|
-
version: '0.1.
|
|
54
|
+
version: '0.1.5',
|
|
55
55
|
path: pathModule,
|
|
56
56
|
'path/posix': pathPosixModule,
|
|
57
57
|
'path/win32': pathWin32Module,
|
package/dist/util/types.d.ts
CHANGED
package/dist/util.d.ts
CHANGED
|
@@ -43,6 +43,7 @@ declare const util: {
|
|
|
43
43
|
stripVTControlCharacters: typeof stripVTControlCharacters;
|
|
44
44
|
isDeepStrictEqual: typeof isDeepStrictEqual;
|
|
45
45
|
types: {
|
|
46
|
+
isAnyArrayBuffer: (value: unknown) => boolean;
|
|
46
47
|
isDate: (value: unknown) => boolean;
|
|
47
48
|
isRegExp: (value: unknown) => boolean;
|
|
48
49
|
isArray: (value: unknown) => boolean;
|
package/dist/util.js
CHANGED
|
@@ -428,6 +428,10 @@ function stripVTControlCharacters(value) {
|
|
|
428
428
|
return String(value).replace(/\u001b\[[0-9;]*m/g, '');
|
|
429
429
|
}
|
|
430
430
|
const types = {
|
|
431
|
+
isAnyArrayBuffer: function (value) {
|
|
432
|
+
return value instanceof ArrayBuffer ||
|
|
433
|
+
(typeof SharedArrayBuffer !== 'undefined' && value instanceof SharedArrayBuffer);
|
|
434
|
+
},
|
|
431
435
|
isDate: function (value) {
|
|
432
436
|
return value instanceof Date;
|
|
433
437
|
},
|
package/dist/zlib.d.ts
CHANGED
|
@@ -18,7 +18,29 @@ declare function deflateRawAsync(input: unknown, options?: DeflateOptions | Node
|
|
|
18
18
|
declare function inflateRawAsync(input: unknown, options?: NodeCallback, callback?: NodeCallback): void;
|
|
19
19
|
declare function gzip(input: unknown, options?: DeflateOptions | NodeCallback, callback?: NodeCallback): void;
|
|
20
20
|
declare function gunzip(input: unknown, options?: NodeCallback, callback?: NodeCallback): void;
|
|
21
|
+
/**
|
|
22
|
+
* zlib 的**类**导出。
|
|
23
|
+
*
|
|
24
|
+
* 为什么必须有:`util.inherits(X, zlib.Zlib)` 是流式压缩库的经典写法(pngjs 等),
|
|
25
|
+
* 拿到 undefined 就会抛 "The superConstructor argument must be a function.";
|
|
26
|
+
* `new zlib.Gzip()` 也很常见。这里把它们补成可用的构造器。
|
|
27
|
+
*
|
|
28
|
+
* 实现方式是"构造器返回现成的流实例":new 时返回 makeZlibStream 的产物,
|
|
29
|
+
* 同时给原型挂上 Transform.prototype,这样 util.inherits 与 instanceof 都成立。
|
|
30
|
+
*/
|
|
31
|
+
type ZlibConstructor = {
|
|
32
|
+
new (options?: DeflateOptions): unknown;
|
|
33
|
+
prototype: object;
|
|
34
|
+
};
|
|
21
35
|
declare const zlib: {
|
|
36
|
+
Zlib: ZlibConstructor;
|
|
37
|
+
Deflate: ZlibConstructor;
|
|
38
|
+
Inflate: ZlibConstructor;
|
|
39
|
+
DeflateRaw: ZlibConstructor;
|
|
40
|
+
InflateRaw: ZlibConstructor;
|
|
41
|
+
Gzip: ZlibConstructor;
|
|
42
|
+
Gunzip: ZlibConstructor;
|
|
43
|
+
Unzip: ZlibConstructor;
|
|
22
44
|
deflateSync: typeof deflateSync;
|
|
23
45
|
inflateSync: typeof inflateSync;
|
|
24
46
|
deflateRawSync: typeof deflateRawSync;
|
package/dist/zlib.js
CHANGED
|
@@ -345,7 +345,32 @@ const constants = {
|
|
|
345
345
|
Z_MAX_WINDOWBITS: 15,
|
|
346
346
|
Z_DEFAULT_WINDOWBITS: 15
|
|
347
347
|
};
|
|
348
|
+
function makeZlibClass(mode, direction, label) {
|
|
349
|
+
const klass = function Zlib(options) {
|
|
350
|
+
return makeZlibStream(mode, direction, options);
|
|
351
|
+
};
|
|
352
|
+
klass.prototype = Object.create(streamModule.Transform.prototype);
|
|
353
|
+
Object.defineProperty(klass, 'name', { value: label, configurable: true });
|
|
354
|
+
return klass;
|
|
355
|
+
}
|
|
356
|
+
const DeflateClass = makeZlibClass('zlib', 'compress', 'Deflate');
|
|
357
|
+
const InflateClass = makeZlibClass('zlib', 'decompress', 'Inflate');
|
|
358
|
+
const DeflateRawClass = makeZlibClass('raw', 'compress', 'DeflateRaw');
|
|
359
|
+
const InflateRawClass = makeZlibClass('raw', 'decompress', 'InflateRaw');
|
|
360
|
+
const GzipClass = makeZlibClass('gzip', 'compress', 'Gzip');
|
|
361
|
+
const GunzipClass = makeZlibClass('gzip', 'decompress', 'Gunzip');
|
|
362
|
+
const UnzipClass = makeZlibClass('auto', 'decompress', 'Unzip');
|
|
363
|
+
/** 基类:Node 里 Zlib 是所有压缩流的父类,子类继承它。这里给一个等价的 deflate 基类。 */
|
|
364
|
+
const ZlibClass = makeZlibClass('zlib', 'compress', 'Zlib');
|
|
348
365
|
const zlib = {
|
|
366
|
+
Zlib: ZlibClass,
|
|
367
|
+
Deflate: DeflateClass,
|
|
368
|
+
Inflate: InflateClass,
|
|
369
|
+
DeflateRaw: DeflateRawClass,
|
|
370
|
+
InflateRaw: InflateRawClass,
|
|
371
|
+
Gzip: GzipClass,
|
|
372
|
+
Gunzip: GunzipClass,
|
|
373
|
+
Unzip: UnzipClass,
|
|
349
374
|
deflateSync: deflateSync,
|
|
350
375
|
inflateSync: inflateSync,
|
|
351
376
|
deflateRawSync: deflateRawSync,
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@serveryyswys/node.operit",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "为 Operit 的 CommonJS 运行时补齐 Node 核心能力(fs / path / os / buffer / ...)",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "serveryyswys",
|
|
7
|
+
"type": "commonjs",
|
|
7
8
|
"main": "dist/index.js",
|
|
8
9
|
"types": "dist/index.d.ts",
|
|
9
10
|
"exports": {
|