@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.
Files changed (123) hide show
  1. package/BUILTINS.json +233 -0
  2. package/DESIGN.md +513 -0
  3. package/LICENSE +674 -0
  4. package/README.md +301 -2
  5. package/dist/assert/strict.d.ts +2 -0
  6. package/dist/assert/strict.js +7 -0
  7. package/dist/assert.d.ts +3 -0
  8. package/dist/assert.js +483 -0
  9. package/dist/buffer.d.ts +60 -0
  10. package/dist/buffer.js +524 -0
  11. package/dist/child_process.d.ts +56 -0
  12. package/dist/child_process.js +371 -0
  13. package/dist/constants.d.ts +2 -0
  14. package/dist/constants.js +19 -0
  15. package/dist/crypto.d.ts +76 -0
  16. package/dist/crypto.js +312 -0
  17. package/dist/dns/promises.d.ts +34 -0
  18. package/dist/dns/promises.js +190 -0
  19. package/dist/dns.d.ts +88 -0
  20. package/dist/dns.js +259 -0
  21. package/dist/events.d.ts +40 -0
  22. package/dist/events.js +237 -0
  23. package/dist/fs/promises.d.ts +159 -0
  24. package/dist/fs/promises.js +129 -0
  25. package/dist/fs.d.ts +221 -0
  26. package/dist/fs.js +944 -0
  27. package/dist/http.d.ts +92 -0
  28. package/dist/http.js +319 -0
  29. package/dist/https.d.ts +296 -0
  30. package/dist/https.js +50 -0
  31. package/dist/index.d.ts +2422 -0
  32. package/dist/index.js +57 -0
  33. package/dist/lib/bridge.d.ts +60 -0
  34. package/dist/lib/bridge.js +205 -0
  35. package/dist/lib/bytes.d.ts +20 -0
  36. package/dist/lib/bytes.js +239 -0
  37. package/dist/lib/child-process-types.d.ts +45 -0
  38. package/dist/lib/child-process-types.js +2 -0
  39. package/dist/lib/cwd.d.ts +2 -0
  40. package/dist/lib/cwd.js +32 -0
  41. package/dist/lib/deep-equal.d.ts +3 -0
  42. package/dist/lib/deep-equal.js +223 -0
  43. package/dist/lib/deflate.d.ts +2 -0
  44. package/dist/lib/deflate.js +234 -0
  45. package/dist/lib/dns-driver.d.ts +14 -0
  46. package/dist/lib/dns-driver.js +85 -0
  47. package/dist/lib/dns-types.d.ts +22 -0
  48. package/dist/lib/dns-types.js +2 -0
  49. package/dist/lib/errors.d.ts +48 -0
  50. package/dist/lib/errors.js +424 -0
  51. package/dist/lib/fs-driver.d.ts +70 -0
  52. package/dist/lib/fs-driver.js +364 -0
  53. package/dist/lib/fs-env.d.ts +30 -0
  54. package/dist/lib/fs-env.js +157 -0
  55. package/dist/lib/fs-types.d.ts +19 -0
  56. package/dist/lib/fs-types.js +2 -0
  57. package/dist/lib/hashes.d.ts +27 -0
  58. package/dist/lib/hashes.js +432 -0
  59. package/dist/lib/http-driver.d.ts +30 -0
  60. package/dist/lib/http-driver.js +72 -0
  61. package/dist/lib/http-types.d.ts +18 -0
  62. package/dist/lib/http-types.js +2 -0
  63. package/dist/lib/inflate.d.ts +6 -0
  64. package/dist/lib/inflate.js +284 -0
  65. package/dist/lib/path-types.d.ts +37 -0
  66. package/dist/lib/path-types.js +2 -0
  67. package/dist/lib/paths.d.ts +8 -0
  68. package/dist/lib/paths.js +106 -0
  69. package/dist/lib/perf-hooks-types.d.ts +18 -0
  70. package/dist/lib/perf-hooks-types.js +2 -0
  71. package/dist/lib/process-driver.d.ts +31 -0
  72. package/dist/lib/process-driver.js +102 -0
  73. package/dist/lib/punycode.d.ts +8 -0
  74. package/dist/lib/punycode.js +179 -0
  75. package/dist/lib/stream-types.d.ts +29 -0
  76. package/dist/lib/stream-types.js +2 -0
  77. package/dist/lib/timers-types.d.ts +18 -0
  78. package/dist/lib/timers-types.js +2 -0
  79. package/dist/lib/url-search-params.d.ts +26 -0
  80. package/dist/lib/url-search-params.js +281 -0
  81. package/dist/lib/url-types.d.ts +44 -0
  82. package/dist/lib/url-types.js +2 -0
  83. package/dist/lib/url-whatwg.d.ts +78 -0
  84. package/dist/lib/url-whatwg.js +857 -0
  85. package/dist/lib/zlib-types.d.ts +12 -0
  86. package/dist/lib/zlib-types.js +2 -0
  87. package/dist/module.d.ts +8 -0
  88. package/dist/module.js +72 -0
  89. package/dist/os.d.ts +80 -0
  90. package/dist/os.js +247 -0
  91. package/dist/path/posix.d.ts +2 -0
  92. package/dist/path/posix.js +7 -0
  93. package/dist/path/win32.d.ts +2 -0
  94. package/dist/path/win32.js +10 -0
  95. package/dist/path.d.ts +3 -0
  96. package/dist/path.js +1222 -0
  97. package/dist/perf_hooks.d.ts +36 -0
  98. package/dist/perf_hooks.js +144 -0
  99. package/dist/process.d.ts +69 -0
  100. package/dist/process.js +230 -0
  101. package/dist/querystring.d.ts +15 -0
  102. package/dist/querystring.js +209 -0
  103. package/dist/stream/promises.d.ts +5 -0
  104. package/dist/stream/promises.js +10 -0
  105. package/dist/stream.d.ts +84 -0
  106. package/dist/stream.js +875 -0
  107. package/dist/string_decoder.d.ts +15 -0
  108. package/dist/string_decoder.js +237 -0
  109. package/dist/timers/promises.d.ts +19 -0
  110. package/dist/timers/promises.js +74 -0
  111. package/dist/timers.d.ts +21 -0
  112. package/dist/timers.js +41 -0
  113. package/dist/tty.d.ts +9 -0
  114. package/dist/tty.js +25 -0
  115. package/dist/unsupported.d.ts +12 -0
  116. package/dist/unsupported.js +17 -0
  117. package/dist/url.d.ts +28 -0
  118. package/dist/url.js +486 -0
  119. package/dist/util.d.ts +74 -0
  120. package/dist/util.js +515 -0
  121. package/dist/zlib.d.ts +88 -0
  122. package/dist/zlib.js +371 -0
  123. package/package.json +29 -4
@@ -0,0 +1,209 @@
1
+ 'use strict';
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.decode = exports.encode = void 0;
37
+ exports.escape = escape;
38
+ exports.unescape = unescape;
39
+ exports.stringify = stringify;
40
+ exports.parse = parse;
41
+ /**
42
+ * Node querystring 模块的移植。
43
+ *
44
+ * 与 URI 编码有关的两处 Node 特性必须照搬,否则三方库看到的串会不一样:
45
+ * - escape() 在 encodeURIComponent 之上额外转义 ! ' ( ) *
46
+ * - unescape()/parse() 是**宽松**解码:非法 % 序列原样保留,不抛 URIError
47
+ * 另外 parse() 会把 '+' 当空格,而 unescape() 不会 —— 这是 Node 的既有不对称。
48
+ */
49
+ const bytesCodec = __importStar(require("./lib/bytes"));
50
+ const CHAR_PERCENT = 37;
51
+ const CHAR_PLUS = 43;
52
+ const CHAR_SPACE = 32;
53
+ /** 与 Node 一致:querystring.escape 就是 encodeURIComponent(不额外转义 ! ' ( ) *)。 */
54
+ function escape(value) {
55
+ return encodeURIComponent(String(value));
56
+ }
57
+ function unescape(value) {
58
+ return decodeComponent(String(value), false);
59
+ }
60
+ function charCodeHex(code) {
61
+ const digits = '0123456789ABCDEF';
62
+ return digits.charAt((code >> 4) & 15) + digits.charAt(code & 15);
63
+ }
64
+ function hexValue(code) {
65
+ if (code >= 48 && code <= 57) {
66
+ return code - 48;
67
+ }
68
+ if (code >= 97 && code <= 102) {
69
+ return code - 87;
70
+ }
71
+ if (code >= 65 && code <= 70) {
72
+ return code - 55;
73
+ }
74
+ return -1;
75
+ }
76
+ /** 宽松百分号解码:连续的 %XX 汇总成字节后按 UTF-8 解释,非法序列原样保留。 */
77
+ function decodeComponent(text, decodeSpaces) {
78
+ let result = '';
79
+ let i = 0;
80
+ const length = text.length;
81
+ while (i < length) {
82
+ const code = text.charCodeAt(i);
83
+ if (code === CHAR_PERCENT && i + 3 <= length) {
84
+ const bytes = [];
85
+ while (i + 3 <= length && text.charCodeAt(i) === CHAR_PERCENT) {
86
+ const high = hexValue(text.charCodeAt(i + 1));
87
+ const low = hexValue(text.charCodeAt(i + 2));
88
+ if (high < 0 || low < 0) {
89
+ break;
90
+ }
91
+ bytes.push((high << 4) | low);
92
+ i += 3;
93
+ }
94
+ if (bytes.length === 0) {
95
+ result += '%';
96
+ i += 1;
97
+ continue;
98
+ }
99
+ result += bytesCodec.utf8Decode(new Uint8Array(bytes));
100
+ continue;
101
+ }
102
+ if (code === CHAR_PLUS && decodeSpaces) {
103
+ result += ' ';
104
+ i += 1;
105
+ continue;
106
+ }
107
+ result += text.charAt(i);
108
+ i += 1;
109
+ }
110
+ return result;
111
+ }
112
+ function stringifyPrimitive(value) {
113
+ if (typeof value === 'string') {
114
+ return value;
115
+ }
116
+ if (typeof value === 'number' && isFinite(value)) {
117
+ return String(value);
118
+ }
119
+ if (typeof value === 'boolean') {
120
+ return value ? 'true' : 'false';
121
+ }
122
+ return '';
123
+ }
124
+ function stringify(value, separator, equals, options) {
125
+ const sep = separator === undefined || separator === '' ? '&' : separator;
126
+ const eq = equals === undefined || equals === '' ? '=' : equals;
127
+ const encode = options !== undefined && typeof options.encodeURIComponent === 'function'
128
+ ? options.encodeURIComponent
129
+ : escape;
130
+ if (value === null || typeof value !== 'object') {
131
+ return '';
132
+ }
133
+ const source = value;
134
+ const keys = Object.keys(source);
135
+ let fields = '';
136
+ for (let i = 0; i < keys.length; i += 1) {
137
+ const key = keys[i];
138
+ const raw = source[key];
139
+ const prefix = encode(stringifyPrimitive(key)) + eq;
140
+ if (Array.isArray(raw)) {
141
+ for (let j = 0; j < raw.length; j += 1) {
142
+ if (fields.length > 0) {
143
+ fields += sep;
144
+ }
145
+ fields += prefix + encode(stringifyPrimitive(raw[j]));
146
+ }
147
+ }
148
+ else {
149
+ if (fields.length > 0) {
150
+ fields += sep;
151
+ }
152
+ fields += prefix + encode(stringifyPrimitive(raw));
153
+ }
154
+ }
155
+ return fields;
156
+ }
157
+ function parse(text, separator, equals, options) {
158
+ const result = Object.create(null);
159
+ if (typeof text !== 'string' || text.length === 0) {
160
+ return result;
161
+ }
162
+ const sep = separator === undefined || separator === '' ? '&' : separator;
163
+ const eq = equals === undefined || equals === '' ? '=' : equals;
164
+ const decode = options !== undefined && typeof options.decodeURIComponent === 'function'
165
+ ? options.decodeURIComponent
166
+ : function (value) {
167
+ return decodeComponent(value, true);
168
+ };
169
+ const maxKeys = options !== undefined && typeof options.maxKeys === 'number' && options.maxKeys >= 0
170
+ ? options.maxKeys
171
+ : 1000;
172
+ const pairs = text.split(sep);
173
+ let count = 0;
174
+ for (let i = 0; i < pairs.length; i += 1) {
175
+ if (maxKeys > 0 && count >= maxKeys) {
176
+ break;
177
+ }
178
+ // 空分段也占用 maxKeys 预算(Node: parse('&a=1', '&', '=', {maxKeys:1}) === {})
179
+ count += 1;
180
+ const pair = pairs[i];
181
+ if (pair.length === 0) {
182
+ continue;
183
+ }
184
+ const index = pair.indexOf(eq);
185
+ let key;
186
+ let value;
187
+ if (index >= 0) {
188
+ key = decode(pair.slice(0, index));
189
+ value = decode(pair.slice(index + eq.length));
190
+ }
191
+ else {
192
+ key = decode(pair);
193
+ value = '';
194
+ }
195
+ const existing = result[key];
196
+ if (existing === undefined) {
197
+ result[key] = value;
198
+ }
199
+ else if (Array.isArray(existing)) {
200
+ existing.push(value);
201
+ }
202
+ else {
203
+ result[key] = [existing, value];
204
+ }
205
+ }
206
+ return result;
207
+ }
208
+ exports.encode = stringify;
209
+ exports.decode = parse;
@@ -0,0 +1,5 @@
1
+ declare const _default: {
2
+ pipeline: (...streams: unknown[]) => Promise<void>;
3
+ finished: (stream: unknown) => Promise<void>;
4
+ };
5
+ export = _default;
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+ /**
3
+ * `stream/promises` 子路径入口。
4
+ *
5
+ * pipeline / finished 的 Promise 版实现放在 stream.ts 里(避免与它循环依赖),
6
+ * 这里只是把 `stream.promises` 暴露成子路径 —— 与 Node 的
7
+ * `require('stream').promises` / `require('stream/promises')` 两条路径一致。
8
+ */
9
+ const streamModule = require("../stream");
10
+ module.exports = streamModule.promises;
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Node stream 模块的移植:Readable / Writable / Duplex / Transform / PassThrough,
3
+ * 以及 pipeline / finished(回调与 Promise 两种)。
4
+ *
5
+ * 实现取舍:
6
+ * - 调度用 queueMicrotask(QuickJS 不一定有 process.nextTick),语义上贴近 Node 的 nextTick;
7
+ * 因此事件时序与 Node 是"同类但不必逐拍相同",测试验证的是**语义**(数据、顺序、事件、
8
+ * 背压返回值、错误传播),不是逐拍时序。
9
+ * - 不实现 objectMode 的完整语义差异(只影响 highWaterMark 的计数单位),
10
+ * 也不实现 cork 的深度合并优化。
11
+ * - 未实现:stream.Duplex 的 allowHalfOpen 完整语义、compose、addAbortSignal。
12
+ */
13
+ import EventEmitter = require('./events');
14
+ import type { StreamOptions, WritableLike } from './lib/stream-types';
15
+ declare class Readable extends EventEmitter {
16
+ readable: boolean;
17
+ constructor(options?: StreamOptions);
18
+ _read(size: number): void;
19
+ _destroy(error: Error | null, callback: (error?: Error | null) => void): void;
20
+ push(chunk: unknown, encoding?: string): boolean;
21
+ unshift(chunk: unknown): void;
22
+ read(size?: number): unknown;
23
+ setEncoding(encoding: string): this;
24
+ pause(): this;
25
+ resume(): this;
26
+ isPaused(): boolean;
27
+ pipe<T extends WritableLike>(destination: T, options?: {
28
+ end?: boolean;
29
+ }): T;
30
+ unpipe(destination?: WritableLike): this;
31
+ destroy(error?: Error | null): this;
32
+ on(event: string, listener: (...args: unknown[]) => void): this;
33
+ [Symbol.asyncIterator](): {
34
+ next(): Promise<{
35
+ value: unknown;
36
+ done: boolean;
37
+ }>;
38
+ };
39
+ static from(iterable: unknown): Readable;
40
+ }
41
+ declare class Writable extends EventEmitter {
42
+ writable: boolean;
43
+ constructor(options?: StreamOptions);
44
+ }
45
+ declare class Duplex extends Readable {
46
+ writable: boolean;
47
+ constructor(options?: StreamOptions);
48
+ }
49
+ declare class Transform extends Duplex {
50
+ constructor(options?: StreamOptions);
51
+ _transform(chunk: unknown, encoding: string, callback: (error?: Error | null, data?: unknown) => void): void;
52
+ /** Transform 的可读侧由 _write 推入,不去主动拉数据,因此这里是空的。 */
53
+ _read(size: number): void;
54
+ _flush(callback: (error?: Error | null) => void): void;
55
+ _write(chunk: unknown, encoding: string, callback: (error?: Error | null) => void): void;
56
+ _final(callback: (error?: Error | null) => void): void;
57
+ }
58
+ declare class PassThrough extends Transform {
59
+ _transform(chunk: unknown, encoding: string, callback: (error?: Error | null, data?: unknown) => void): void;
60
+ }
61
+ declare function finished(stream: WritableLike | Readable, callback: (error?: Error | null) => void): () => void;
62
+ declare function isReadableStream(value: unknown): boolean;
63
+ declare function isWritableStream(value: unknown): boolean;
64
+ declare function pipeline(...args: unknown[]): unknown;
65
+ /** stream/promises 用的 Promise 版:不走 pipeline 的回调校验。 */
66
+ declare function pipelinePromise(...streams: unknown[]): Promise<void>;
67
+ declare function finishedPromise(stream: unknown): Promise<void>;
68
+ declare class Stream extends EventEmitter {
69
+ static Readable: typeof Readable;
70
+ static Writable: typeof Writable;
71
+ static Duplex: typeof Duplex;
72
+ static Transform: typeof Transform;
73
+ static PassThrough: typeof PassThrough;
74
+ static Stream: typeof Stream;
75
+ static pipeline: typeof pipeline;
76
+ static finished: typeof finished;
77
+ static promises: {
78
+ pipeline: typeof pipelinePromise;
79
+ finished: typeof finishedPromise;
80
+ };
81
+ static isReadable: typeof isReadableStream;
82
+ static isWritable: typeof isWritableStream;
83
+ }
84
+ export = Stream;