@modern-js/server-core 2.68.2 → 2.68.3
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/dist/cjs/adapters/node/index.js +2 -4
- package/dist/cjs/adapters/node/node.js +6 -10
- package/dist/esm/adapters/node/index.js +2 -3
- package/dist/esm/adapters/node/node.js +6 -9
- package/dist/esm-node/adapters/node/index.js +2 -3
- package/dist/esm-node/adapters/node/node.js +5 -8
- package/dist/types/adapters/node/index.d.ts +1 -1
- package/dist/types/adapters/node/node.d.ts +1 -1
- package/package.json +7 -7
- package/dist/cjs/adapters/node/polyfills/index.js +0 -24
- package/dist/cjs/adapters/node/polyfills/install.js +0 -72
- package/dist/cjs/adapters/node/polyfills/stream.js +0 -160
- package/dist/esm/adapters/node/polyfills/index.js +0 -2
- package/dist/esm/adapters/node/polyfills/install.js +0 -48
- package/dist/esm/adapters/node/polyfills/stream.js +0 -340
- package/dist/esm-node/adapters/node/polyfills/index.js +0 -2
- package/dist/esm-node/adapters/node/polyfills/install.js +0 -48
- package/dist/esm-node/adapters/node/polyfills/stream.js +0 -133
- package/dist/types/adapters/node/polyfills/index.d.ts +0 -2
- package/dist/types/adapters/node/polyfills/install.d.ts +0 -1
- package/dist/types/adapters/node/polyfills/stream.d.ts +0 -16
|
@@ -34,8 +34,7 @@ __export(node_exports, {
|
|
|
34
34
|
loadServerPlugins: () => import_helper.loadServerPlugins,
|
|
35
35
|
loadServerRuntimeConfig: () => import_helper.loadServerRuntimeConfig,
|
|
36
36
|
sendResponse: () => import_node.sendResponse,
|
|
37
|
-
serverStaticPlugin: () => import_plugins.serverStaticPlugin
|
|
38
|
-
writeReadableStreamToWritable: () => import_node.writeReadableStreamToWritable
|
|
37
|
+
serverStaticPlugin: () => import_plugins.serverStaticPlugin
|
|
39
38
|
});
|
|
40
39
|
module.exports = __toCommonJS(node_exports);
|
|
41
40
|
var import_hono = require("./hono");
|
|
@@ -60,6 +59,5 @@ var import_helper = require("./helper");
|
|
|
60
59
|
loadServerPlugins,
|
|
61
60
|
loadServerRuntimeConfig,
|
|
62
61
|
sendResponse,
|
|
63
|
-
serverStaticPlugin
|
|
64
|
-
writeReadableStreamToWritable
|
|
62
|
+
serverStaticPlugin
|
|
65
63
|
});
|
|
@@ -30,17 +30,13 @@ var node_exports = {};
|
|
|
30
30
|
__export(node_exports, {
|
|
31
31
|
createNodeServer: () => createNodeServer,
|
|
32
32
|
createWebRequest: () => createWebRequest,
|
|
33
|
-
sendResponse: () => sendResponse
|
|
34
|
-
writeReadableStreamToWritable: () => import_polyfills.writeReadableStreamToWritable
|
|
33
|
+
sendResponse: () => sendResponse
|
|
35
34
|
});
|
|
36
35
|
module.exports = __toCommonJS(node_exports);
|
|
37
36
|
var import_node_http = require("node:http");
|
|
37
|
+
var import_node_stream = require("node:stream");
|
|
38
38
|
var import_cloneable_readable = __toESM(require("cloneable-readable"));
|
|
39
39
|
var import_helper = require("./helper");
|
|
40
|
-
var import_install = require("./polyfills/install");
|
|
41
|
-
var import_stream = require("./polyfills/stream");
|
|
42
|
-
var import_polyfills = require("./polyfills");
|
|
43
|
-
(0, import_install.installGlobals)();
|
|
44
40
|
const createWebRequest = (req, res, body) => {
|
|
45
41
|
const headerRecord = [];
|
|
46
42
|
for (const [key, value] of Object.entries(req.headers)) {
|
|
@@ -81,7 +77,7 @@ const createWebRequest = (req, res, body) => {
|
|
|
81
77
|
init.body = body;
|
|
82
78
|
} else {
|
|
83
79
|
const stream = cloneableReq.clone();
|
|
84
|
-
init.body =
|
|
80
|
+
init.body = import_node_stream.Readable.toWeb(stream);
|
|
85
81
|
}
|
|
86
82
|
init.duplex = "half";
|
|
87
83
|
}
|
|
@@ -124,7 +120,8 @@ const sendResponse = async (response, res) => {
|
|
|
124
120
|
res.flushHeaders();
|
|
125
121
|
}
|
|
126
122
|
if (response.body) {
|
|
127
|
-
|
|
123
|
+
const writable = import_node_stream.Writable.toWeb(res);
|
|
124
|
+
await response.body.pipeTo(writable);
|
|
128
125
|
} else {
|
|
129
126
|
res.end();
|
|
130
127
|
}
|
|
@@ -193,6 +190,5 @@ const createNodeServer = async (requestHandler, httpsOptions, http2) => {
|
|
|
193
190
|
0 && (module.exports = {
|
|
194
191
|
createNodeServer,
|
|
195
192
|
createWebRequest,
|
|
196
|
-
sendResponse
|
|
197
|
-
writeReadableStreamToWritable
|
|
193
|
+
sendResponse
|
|
198
194
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { httpCallBack2HonoMid, connectMid2HonoMid, connectMockMid2HonoMid } from "./hono";
|
|
2
|
-
import { createNodeServer, sendResponse, createWebRequest
|
|
2
|
+
import { createNodeServer, sendResponse, createWebRequest } from "./node";
|
|
3
3
|
import { serverStaticPlugin, injectResourcePlugin, getHtmlTemplates, getServerManifest, injectNodeSeverPlugin, injectRscManifestPlugin } from "./plugins";
|
|
4
4
|
import { loadServerPlugins, loadServerEnv, loadServerRuntimeConfig, loadServerCliConfig, loadCacheConfig } from "./helper";
|
|
5
5
|
export {
|
|
@@ -19,6 +19,5 @@ export {
|
|
|
19
19
|
loadServerPlugins,
|
|
20
20
|
loadServerRuntimeConfig,
|
|
21
21
|
sendResponse,
|
|
22
|
-
serverStaticPlugin
|
|
23
|
-
writeReadableStreamToWritable
|
|
22
|
+
serverStaticPlugin
|
|
24
23
|
};
|
|
@@ -4,12 +4,9 @@ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
|
4
4
|
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
|
5
5
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
6
6
|
import { ServerResponse } from "node:http";
|
|
7
|
+
import { Readable, Writable } from "node:stream";
|
|
7
8
|
import cloneable from "cloneable-readable";
|
|
8
9
|
import { isResFinalized } from "./helper";
|
|
9
|
-
import { installGlobals } from "./polyfills/install";
|
|
10
|
-
import { createReadableStreamFromReadable, writeReadableStreamToWritable } from "./polyfills/stream";
|
|
11
|
-
import { writeReadableStreamToWritable as writeReadableStreamToWritable2 } from "./polyfills";
|
|
12
|
-
installGlobals();
|
|
13
10
|
var createWebRequest = function(req, res, body) {
|
|
14
11
|
var headerRecord = [];
|
|
15
12
|
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
@@ -86,7 +83,7 @@ var createWebRequest = function(req, res, body) {
|
|
|
86
83
|
init.body = body;
|
|
87
84
|
} else {
|
|
88
85
|
var stream = cloneableReq.clone();
|
|
89
|
-
init.body =
|
|
86
|
+
init.body = Readable.toWeb(stream);
|
|
90
87
|
}
|
|
91
88
|
init.duplex = "half";
|
|
92
89
|
}
|
|
@@ -112,7 +109,7 @@ var createWebRequest = function(req, res, body) {
|
|
|
112
109
|
};
|
|
113
110
|
var sendResponse = function() {
|
|
114
111
|
var _ref = _async_to_generator(function(response, res) {
|
|
115
|
-
var _response_headers_get, cookies, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _step_value, key, value;
|
|
112
|
+
var _response_headers_get, cookies, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _step_value, key, value, writable;
|
|
116
113
|
return _ts_generator(this, function(_state) {
|
|
117
114
|
switch (_state.label) {
|
|
118
115
|
case 0:
|
|
@@ -154,9 +151,10 @@ var sendResponse = function() {
|
|
|
154
151
|
3,
|
|
155
152
|
2
|
|
156
153
|
];
|
|
154
|
+
writable = Writable.toWeb(res);
|
|
157
155
|
return [
|
|
158
156
|
4,
|
|
159
|
-
|
|
157
|
+
response.body.pipeTo(writable)
|
|
160
158
|
];
|
|
161
159
|
case 1:
|
|
162
160
|
_state.sent();
|
|
@@ -332,6 +330,5 @@ var createNodeServer = function() {
|
|
|
332
330
|
export {
|
|
333
331
|
createNodeServer,
|
|
334
332
|
createWebRequest,
|
|
335
|
-
sendResponse
|
|
336
|
-
writeReadableStreamToWritable2 as writeReadableStreamToWritable
|
|
333
|
+
sendResponse
|
|
337
334
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { httpCallBack2HonoMid, connectMid2HonoMid, connectMockMid2HonoMid } from "./hono";
|
|
2
|
-
import { createNodeServer, sendResponse, createWebRequest
|
|
2
|
+
import { createNodeServer, sendResponse, createWebRequest } from "./node";
|
|
3
3
|
import { serverStaticPlugin, injectResourcePlugin, getHtmlTemplates, getServerManifest, injectNodeSeverPlugin, injectRscManifestPlugin } from "./plugins";
|
|
4
4
|
import { loadServerPlugins, loadServerEnv, loadServerRuntimeConfig, loadServerCliConfig, loadCacheConfig } from "./helper";
|
|
5
5
|
export {
|
|
@@ -19,6 +19,5 @@ export {
|
|
|
19
19
|
loadServerPlugins,
|
|
20
20
|
loadServerRuntimeConfig,
|
|
21
21
|
sendResponse,
|
|
22
|
-
serverStaticPlugin
|
|
23
|
-
writeReadableStreamToWritable
|
|
22
|
+
serverStaticPlugin
|
|
24
23
|
};
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { ServerResponse } from "node:http";
|
|
2
|
+
import { Readable, Writable } from "node:stream";
|
|
2
3
|
import cloneable from "cloneable-readable";
|
|
3
4
|
import { isResFinalized } from "./helper";
|
|
4
|
-
import { installGlobals } from "./polyfills/install";
|
|
5
|
-
import { createReadableStreamFromReadable, writeReadableStreamToWritable } from "./polyfills/stream";
|
|
6
|
-
import { writeReadableStreamToWritable as writeReadableStreamToWritable2 } from "./polyfills";
|
|
7
|
-
installGlobals();
|
|
8
5
|
const createWebRequest = (req, res, body) => {
|
|
9
6
|
const headerRecord = [];
|
|
10
7
|
for (const [key, value] of Object.entries(req.headers)) {
|
|
@@ -45,7 +42,7 @@ const createWebRequest = (req, res, body) => {
|
|
|
45
42
|
init.body = body;
|
|
46
43
|
} else {
|
|
47
44
|
const stream = cloneableReq.clone();
|
|
48
|
-
init.body =
|
|
45
|
+
init.body = Readable.toWeb(stream);
|
|
49
46
|
}
|
|
50
47
|
init.duplex = "half";
|
|
51
48
|
}
|
|
@@ -88,7 +85,8 @@ const sendResponse = async (response, res) => {
|
|
|
88
85
|
res.flushHeaders();
|
|
89
86
|
}
|
|
90
87
|
if (response.body) {
|
|
91
|
-
|
|
88
|
+
const writable = Writable.toWeb(res);
|
|
89
|
+
await response.body.pipeTo(writable);
|
|
92
90
|
} else {
|
|
93
91
|
res.end();
|
|
94
92
|
}
|
|
@@ -156,6 +154,5 @@ const createNodeServer = async (requestHandler, httpsOptions, http2) => {
|
|
|
156
154
|
export {
|
|
157
155
|
createNodeServer,
|
|
158
156
|
createWebRequest,
|
|
159
|
-
sendResponse
|
|
160
|
-
writeReadableStreamToWritable2 as writeReadableStreamToWritable
|
|
157
|
+
sendResponse
|
|
161
158
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { httpCallBack2HonoMid, connectMid2HonoMid, connectMockMid2HonoMid, } from './hono';
|
|
2
2
|
export type { ServerNodeContext, ServerNodeMiddleware } from './hono';
|
|
3
|
-
export { createNodeServer, sendResponse, createWebRequest,
|
|
3
|
+
export { createNodeServer, sendResponse, createWebRequest, } from './node';
|
|
4
4
|
export { serverStaticPlugin, injectResourcePlugin, getHtmlTemplates, getServerManifest, injectNodeSeverPlugin, injectRscManifestPlugin, } from './plugins';
|
|
5
5
|
export { loadServerPlugins, loadServerEnv, loadServerRuntimeConfig, loadServerCliConfig, loadCacheConfig, } from './helper';
|
|
@@ -3,7 +3,6 @@ import type { Http2SecureServer } from 'node:http2';
|
|
|
3
3
|
import type { Server as NodeHttpsServer } from 'node:https';
|
|
4
4
|
import type { NodeRequest, NodeResponse } from '@modern-js/types/server';
|
|
5
5
|
import type { RequestHandler } from '../../types';
|
|
6
|
-
export { writeReadableStreamToWritable } from './polyfills';
|
|
7
6
|
export declare const createWebRequest: (req: NodeRequest, res: NodeResponse, body?: BodyInit) => Request;
|
|
8
7
|
export declare const sendResponse: (response: Response, res: NodeResponse) => Promise<void>;
|
|
9
8
|
declare const getRequestListener: (handler: RequestHandler) => (req: NodeRequest, res: NodeResponse) => Promise<void>;
|
|
@@ -15,3 +14,4 @@ export declare const createNodeServer: (requestHandler: RequestHandler, httpsOpt
|
|
|
15
14
|
key?: string | Buffer;
|
|
16
15
|
cert?: string | Buffer;
|
|
17
16
|
}, http2?: boolean) => Promise<NodeServerWrapper>;
|
|
17
|
+
export {};
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.68.
|
|
18
|
+
"version": "2.68.3",
|
|
19
19
|
"jsnext:source": "./src/index.ts",
|
|
20
20
|
"types": "./dist/types/index.d.ts",
|
|
21
21
|
"main": "./dist/cjs/index.js",
|
|
@@ -54,21 +54,21 @@
|
|
|
54
54
|
"flatted": "^3.3.3",
|
|
55
55
|
"hono": "^3.12.2",
|
|
56
56
|
"ts-deepmerge": "7.0.2",
|
|
57
|
-
"@modern-js/plugin": "2.68.
|
|
58
|
-
"@modern-js/plugin-v2": "2.68.
|
|
59
|
-
"@modern-js/runtime-utils": "2.68.
|
|
60
|
-
"@modern-js/utils": "2.68.
|
|
57
|
+
"@modern-js/plugin": "2.68.3",
|
|
58
|
+
"@modern-js/plugin-v2": "2.68.3",
|
|
59
|
+
"@modern-js/runtime-utils": "2.68.3",
|
|
60
|
+
"@modern-js/utils": "2.68.3"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@types/cloneable-readable": "^2.0.3",
|
|
64
64
|
"@types/jest": "^29",
|
|
65
65
|
"@types/merge-deep": "^3.0.0",
|
|
66
|
-
"@types/node": "^
|
|
66
|
+
"@types/node": "^18",
|
|
67
67
|
"http-proxy-middleware": "^2.0.9",
|
|
68
68
|
"jest": "^29",
|
|
69
69
|
"ts-jest": "^29.1.0",
|
|
70
70
|
"typescript": "^5",
|
|
71
|
-
"@modern-js/types": "2.68.
|
|
71
|
+
"@modern-js/types": "2.68.3",
|
|
72
72
|
"@scripts/build": "2.66.0",
|
|
73
73
|
"@scripts/jest-config": "2.66.0"
|
|
74
74
|
},
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __copyProps = (to, from, except, desc) => {
|
|
7
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
-
for (let key of __getOwnPropNames(from))
|
|
9
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
-
}
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
-
var polyfills_exports = {};
|
|
17
|
-
module.exports = __toCommonJS(polyfills_exports);
|
|
18
|
-
__reExport(polyfills_exports, require("./install"), module.exports);
|
|
19
|
-
__reExport(polyfills_exports, require("./stream"), module.exports);
|
|
20
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
21
|
-
0 && (module.exports = {
|
|
22
|
-
...require("./install"),
|
|
23
|
-
...require("./stream")
|
|
24
|
-
});
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var install_exports = {};
|
|
20
|
-
__export(install_exports, {
|
|
21
|
-
installGlobals: () => installGlobals
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(install_exports);
|
|
24
|
-
var import_fetch = require("@web-std/fetch");
|
|
25
|
-
var import_file = require("@web-std/file");
|
|
26
|
-
var import_stream = require("@web-std/stream");
|
|
27
|
-
if (!Object.getOwnPropertyDescriptor(import_fetch.Headers.prototype, "getSetCookie")) {
|
|
28
|
-
Object.defineProperty(import_fetch.Headers.prototype, "getSetCookie", {
|
|
29
|
-
value: function getSetCookie() {
|
|
30
|
-
const cookies = [];
|
|
31
|
-
this.forEach((value, name) => {
|
|
32
|
-
if (name.toLowerCase() === "set-cookie") {
|
|
33
|
-
cookies.push(value);
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
return cookies;
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
const installGlobals = () => {
|
|
41
|
-
if (!global.Headers) {
|
|
42
|
-
global.Headers = import_fetch.Headers;
|
|
43
|
-
}
|
|
44
|
-
if (!global.Request) {
|
|
45
|
-
global.Request = import_fetch.Request;
|
|
46
|
-
}
|
|
47
|
-
if (!global.Response) {
|
|
48
|
-
global.Response = import_fetch.Response;
|
|
49
|
-
}
|
|
50
|
-
if (!global.FormData) {
|
|
51
|
-
global.FormData = import_fetch.FormData;
|
|
52
|
-
}
|
|
53
|
-
if (!global.TransformStream) {
|
|
54
|
-
global.TransformStream = import_stream.TransformStream;
|
|
55
|
-
}
|
|
56
|
-
if (!global.ReadableStream) {
|
|
57
|
-
global.ReadableStream = import_stream.ReadableStream;
|
|
58
|
-
}
|
|
59
|
-
if (!global.WritableStream) {
|
|
60
|
-
global.WritableStream = import_stream.WritableStream;
|
|
61
|
-
}
|
|
62
|
-
if (!global.File) {
|
|
63
|
-
global.File = import_file.File;
|
|
64
|
-
}
|
|
65
|
-
if (!global.Blob) {
|
|
66
|
-
global.Blob = import_file.Blob;
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
70
|
-
0 && (module.exports = {
|
|
71
|
-
installGlobals
|
|
72
|
-
});
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var stream_exports = {};
|
|
20
|
-
__export(stream_exports, {
|
|
21
|
-
createReadableStreamFromReadable: () => createReadableStreamFromReadable,
|
|
22
|
-
readableStreamToString: () => readableStreamToString,
|
|
23
|
-
writeAsyncIterableToWritable: () => writeAsyncIterableToWritable,
|
|
24
|
-
writeReadableStreamToWritable: () => writeReadableStreamToWritable
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(stream_exports);
|
|
27
|
-
var import_node_stream = require("node:stream");
|
|
28
|
-
async function writeReadableStreamToWritable(stream, writable) {
|
|
29
|
-
const reader = stream.getReader();
|
|
30
|
-
const flushable = writable;
|
|
31
|
-
try {
|
|
32
|
-
await new Promise((resolve, reject) => {
|
|
33
|
-
writable.on("finish", resolve);
|
|
34
|
-
writable.on("error", reject);
|
|
35
|
-
const writeAndFlush = async () => {
|
|
36
|
-
while (true) {
|
|
37
|
-
const { done, value } = await reader.read();
|
|
38
|
-
if (done) {
|
|
39
|
-
writable.end();
|
|
40
|
-
break;
|
|
41
|
-
}
|
|
42
|
-
writable.write(value);
|
|
43
|
-
if (typeof flushable.flush === "function") {
|
|
44
|
-
flushable.flush();
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
writeAndFlush().catch(reject);
|
|
49
|
-
});
|
|
50
|
-
} catch (error) {
|
|
51
|
-
writable.destroy(error);
|
|
52
|
-
throw error;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
async function writeAsyncIterableToWritable(iterable, writable) {
|
|
56
|
-
try {
|
|
57
|
-
for await (const chunk of iterable) {
|
|
58
|
-
writable.write(chunk);
|
|
59
|
-
}
|
|
60
|
-
writable.end();
|
|
61
|
-
} catch (error) {
|
|
62
|
-
writable.destroy(error);
|
|
63
|
-
throw error;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
async function readableStreamToString(stream, encoding) {
|
|
67
|
-
const reader = stream.getReader();
|
|
68
|
-
const chunks = [];
|
|
69
|
-
while (true) {
|
|
70
|
-
const { done, value } = await reader.read();
|
|
71
|
-
if (done) {
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
if (value) {
|
|
75
|
-
chunks.push(value);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return Buffer.concat(chunks).toString(encoding);
|
|
79
|
-
}
|
|
80
|
-
const createReadableStreamFromReadable = (source) => {
|
|
81
|
-
const pump = new StreamPump(source);
|
|
82
|
-
const stream = new ReadableStream(pump, pump);
|
|
83
|
-
return stream;
|
|
84
|
-
};
|
|
85
|
-
class StreamPump {
|
|
86
|
-
size(chunk) {
|
|
87
|
-
return (chunk === null || chunk === void 0 ? void 0 : chunk.byteLength) || 0;
|
|
88
|
-
}
|
|
89
|
-
start(controller) {
|
|
90
|
-
this.controller = controller;
|
|
91
|
-
this.stream.on("data", this.enqueue);
|
|
92
|
-
this.stream.once("error", this.error);
|
|
93
|
-
this.stream.once("end", this.close);
|
|
94
|
-
this.stream.once("close", this.close);
|
|
95
|
-
}
|
|
96
|
-
pull() {
|
|
97
|
-
this.resume();
|
|
98
|
-
}
|
|
99
|
-
cancel(reason) {
|
|
100
|
-
if (this.stream.destroy) {
|
|
101
|
-
this.stream.destroy(reason);
|
|
102
|
-
}
|
|
103
|
-
this.stream.off("data", this.enqueue);
|
|
104
|
-
this.stream.off("error", this.error);
|
|
105
|
-
this.stream.off("end", this.close);
|
|
106
|
-
this.stream.off("close", this.close);
|
|
107
|
-
}
|
|
108
|
-
enqueue(chunk) {
|
|
109
|
-
if (this.controller) {
|
|
110
|
-
try {
|
|
111
|
-
const bytes = chunk instanceof Uint8Array ? chunk : Buffer.from(chunk);
|
|
112
|
-
const available = (this.controller.desiredSize || 0) - bytes.byteLength;
|
|
113
|
-
this.controller.enqueue(bytes);
|
|
114
|
-
if (available <= 0) {
|
|
115
|
-
this.pause();
|
|
116
|
-
}
|
|
117
|
-
} catch (error) {
|
|
118
|
-
this.controller.error(new Error("Could not create Buffer, chunk must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object"));
|
|
119
|
-
this.cancel();
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
pause() {
|
|
124
|
-
if (this.stream.pause) {
|
|
125
|
-
this.stream.pause();
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
resume() {
|
|
129
|
-
if (this.stream.readable && this.stream.resume) {
|
|
130
|
-
this.stream.resume();
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
close() {
|
|
134
|
-
if (this.controller) {
|
|
135
|
-
this.controller.close();
|
|
136
|
-
delete this.controller;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
error(error) {
|
|
140
|
-
if (this.controller) {
|
|
141
|
-
this.controller.error(error);
|
|
142
|
-
delete this.controller;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
constructor(stream) {
|
|
146
|
-
this.highWaterMark = stream.readableHighWaterMark || new import_node_stream.Stream.Readable().readableHighWaterMark;
|
|
147
|
-
this.accumalatedSize = 0;
|
|
148
|
-
this.stream = stream;
|
|
149
|
-
this.enqueue = this.enqueue.bind(this);
|
|
150
|
-
this.error = this.error.bind(this);
|
|
151
|
-
this.close = this.close.bind(this);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
155
|
-
0 && (module.exports = {
|
|
156
|
-
createReadableStreamFromReadable,
|
|
157
|
-
readableStreamToString,
|
|
158
|
-
writeAsyncIterableToWritable,
|
|
159
|
-
writeReadableStreamToWritable
|
|
160
|
-
});
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { FormData as NodeFormData, Headers as NodeHeaders, Request as NodeRequest, Response as NodeResponse } from "@web-std/fetch";
|
|
2
|
-
import { Blob as NodeBlob, File as NodeFile } from "@web-std/file";
|
|
3
|
-
import { ReadableStream as NodeReadableStream, TransformStream as NodeTransformStream, WritableStream as NodeWritableStream } from "@web-std/stream";
|
|
4
|
-
if (!Object.getOwnPropertyDescriptor(NodeHeaders.prototype, "getSetCookie")) {
|
|
5
|
-
Object.defineProperty(NodeHeaders.prototype, "getSetCookie", {
|
|
6
|
-
value: function getSetCookie() {
|
|
7
|
-
var cookies = [];
|
|
8
|
-
this.forEach(function(value, name) {
|
|
9
|
-
if (name.toLowerCase() === "set-cookie") {
|
|
10
|
-
cookies.push(value);
|
|
11
|
-
}
|
|
12
|
-
});
|
|
13
|
-
return cookies;
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
var installGlobals = function() {
|
|
18
|
-
if (!global.Headers) {
|
|
19
|
-
global.Headers = NodeHeaders;
|
|
20
|
-
}
|
|
21
|
-
if (!global.Request) {
|
|
22
|
-
global.Request = NodeRequest;
|
|
23
|
-
}
|
|
24
|
-
if (!global.Response) {
|
|
25
|
-
global.Response = NodeResponse;
|
|
26
|
-
}
|
|
27
|
-
if (!global.FormData) {
|
|
28
|
-
global.FormData = NodeFormData;
|
|
29
|
-
}
|
|
30
|
-
if (!global.TransformStream) {
|
|
31
|
-
global.TransformStream = NodeTransformStream;
|
|
32
|
-
}
|
|
33
|
-
if (!global.ReadableStream) {
|
|
34
|
-
global.ReadableStream = NodeReadableStream;
|
|
35
|
-
}
|
|
36
|
-
if (!global.WritableStream) {
|
|
37
|
-
global.WritableStream = NodeWritableStream;
|
|
38
|
-
}
|
|
39
|
-
if (!global.File) {
|
|
40
|
-
global.File = NodeFile;
|
|
41
|
-
}
|
|
42
|
-
if (!global.Blob) {
|
|
43
|
-
global.Blob = NodeBlob;
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
export {
|
|
47
|
-
installGlobals
|
|
48
|
-
};
|
|
@@ -1,340 +0,0 @@
|
|
|
1
|
-
import { _ as _async_iterator } from "@swc/helpers/_/_async_iterator";
|
|
2
|
-
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
3
|
-
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
|
|
4
|
-
import { _ as _instanceof } from "@swc/helpers/_/_instanceof";
|
|
5
|
-
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
6
|
-
import { Stream } from "node:stream";
|
|
7
|
-
function writeReadableStreamToWritable(stream, writable) {
|
|
8
|
-
return _writeReadableStreamToWritable.apply(this, arguments);
|
|
9
|
-
}
|
|
10
|
-
function _writeReadableStreamToWritable() {
|
|
11
|
-
_writeReadableStreamToWritable = _async_to_generator(function(stream, writable) {
|
|
12
|
-
var reader, flushable, error;
|
|
13
|
-
return _ts_generator(this, function(_state) {
|
|
14
|
-
switch (_state.label) {
|
|
15
|
-
case 0:
|
|
16
|
-
reader = stream.getReader();
|
|
17
|
-
flushable = writable;
|
|
18
|
-
_state.label = 1;
|
|
19
|
-
case 1:
|
|
20
|
-
_state.trys.push([
|
|
21
|
-
1,
|
|
22
|
-
3,
|
|
23
|
-
,
|
|
24
|
-
4
|
|
25
|
-
]);
|
|
26
|
-
return [
|
|
27
|
-
4,
|
|
28
|
-
new Promise(function(resolve, reject) {
|
|
29
|
-
writable.on("finish", resolve);
|
|
30
|
-
writable.on("error", reject);
|
|
31
|
-
var writeAndFlush = function() {
|
|
32
|
-
var _ref = _async_to_generator(function() {
|
|
33
|
-
var _ref2, done, value;
|
|
34
|
-
return _ts_generator(this, function(_state2) {
|
|
35
|
-
switch (_state2.label) {
|
|
36
|
-
case 0:
|
|
37
|
-
if (false)
|
|
38
|
-
return [
|
|
39
|
-
3,
|
|
40
|
-
2
|
|
41
|
-
];
|
|
42
|
-
return [
|
|
43
|
-
4,
|
|
44
|
-
reader.read()
|
|
45
|
-
];
|
|
46
|
-
case 1:
|
|
47
|
-
_ref2 = _state2.sent(), done = _ref2.done, value = _ref2.value;
|
|
48
|
-
if (done) {
|
|
49
|
-
writable.end();
|
|
50
|
-
return [
|
|
51
|
-
3,
|
|
52
|
-
2
|
|
53
|
-
];
|
|
54
|
-
}
|
|
55
|
-
writable.write(value);
|
|
56
|
-
if (typeof flushable.flush === "function") {
|
|
57
|
-
flushable.flush();
|
|
58
|
-
}
|
|
59
|
-
return [
|
|
60
|
-
3,
|
|
61
|
-
0
|
|
62
|
-
];
|
|
63
|
-
case 2:
|
|
64
|
-
return [
|
|
65
|
-
2
|
|
66
|
-
];
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
return function writeAndFlush2() {
|
|
71
|
-
return _ref.apply(this, arguments);
|
|
72
|
-
};
|
|
73
|
-
}();
|
|
74
|
-
writeAndFlush().catch(reject);
|
|
75
|
-
})
|
|
76
|
-
];
|
|
77
|
-
case 2:
|
|
78
|
-
_state.sent();
|
|
79
|
-
return [
|
|
80
|
-
3,
|
|
81
|
-
4
|
|
82
|
-
];
|
|
83
|
-
case 3:
|
|
84
|
-
error = _state.sent();
|
|
85
|
-
writable.destroy(error);
|
|
86
|
-
throw error;
|
|
87
|
-
case 4:
|
|
88
|
-
return [
|
|
89
|
-
2
|
|
90
|
-
];
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
return _writeReadableStreamToWritable.apply(this, arguments);
|
|
95
|
-
}
|
|
96
|
-
function writeAsyncIterableToWritable(iterable, writable) {
|
|
97
|
-
return _writeAsyncIterableToWritable.apply(this, arguments);
|
|
98
|
-
}
|
|
99
|
-
function _writeAsyncIterableToWritable() {
|
|
100
|
-
_writeAsyncIterableToWritable = _async_to_generator(function(iterable, writable) {
|
|
101
|
-
var _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, chunk, err, error;
|
|
102
|
-
return _ts_generator(this, function(_state) {
|
|
103
|
-
switch (_state.label) {
|
|
104
|
-
case 0:
|
|
105
|
-
_state.trys.push([
|
|
106
|
-
0,
|
|
107
|
-
13,
|
|
108
|
-
,
|
|
109
|
-
14
|
|
110
|
-
]);
|
|
111
|
-
_iteratorAbruptCompletion = false, _didIteratorError = false;
|
|
112
|
-
_state.label = 1;
|
|
113
|
-
case 1:
|
|
114
|
-
_state.trys.push([
|
|
115
|
-
1,
|
|
116
|
-
6,
|
|
117
|
-
7,
|
|
118
|
-
12
|
|
119
|
-
]);
|
|
120
|
-
_iterator = _async_iterator(iterable);
|
|
121
|
-
_state.label = 2;
|
|
122
|
-
case 2:
|
|
123
|
-
return [
|
|
124
|
-
4,
|
|
125
|
-
_iterator.next()
|
|
126
|
-
];
|
|
127
|
-
case 3:
|
|
128
|
-
if (!(_iteratorAbruptCompletion = !(_step = _state.sent()).done))
|
|
129
|
-
return [
|
|
130
|
-
3,
|
|
131
|
-
5
|
|
132
|
-
];
|
|
133
|
-
_value = _step.value;
|
|
134
|
-
chunk = _value;
|
|
135
|
-
writable.write(chunk);
|
|
136
|
-
_state.label = 4;
|
|
137
|
-
case 4:
|
|
138
|
-
_iteratorAbruptCompletion = false;
|
|
139
|
-
return [
|
|
140
|
-
3,
|
|
141
|
-
2
|
|
142
|
-
];
|
|
143
|
-
case 5:
|
|
144
|
-
return [
|
|
145
|
-
3,
|
|
146
|
-
12
|
|
147
|
-
];
|
|
148
|
-
case 6:
|
|
149
|
-
err = _state.sent();
|
|
150
|
-
_didIteratorError = true;
|
|
151
|
-
_iteratorError = err;
|
|
152
|
-
return [
|
|
153
|
-
3,
|
|
154
|
-
12
|
|
155
|
-
];
|
|
156
|
-
case 7:
|
|
157
|
-
_state.trys.push([
|
|
158
|
-
7,
|
|
159
|
-
,
|
|
160
|
-
10,
|
|
161
|
-
11
|
|
162
|
-
]);
|
|
163
|
-
if (!(_iteratorAbruptCompletion && _iterator.return != null))
|
|
164
|
-
return [
|
|
165
|
-
3,
|
|
166
|
-
9
|
|
167
|
-
];
|
|
168
|
-
return [
|
|
169
|
-
4,
|
|
170
|
-
_iterator.return()
|
|
171
|
-
];
|
|
172
|
-
case 8:
|
|
173
|
-
_state.sent();
|
|
174
|
-
_state.label = 9;
|
|
175
|
-
case 9:
|
|
176
|
-
return [
|
|
177
|
-
3,
|
|
178
|
-
11
|
|
179
|
-
];
|
|
180
|
-
case 10:
|
|
181
|
-
if (_didIteratorError) {
|
|
182
|
-
throw _iteratorError;
|
|
183
|
-
}
|
|
184
|
-
return [
|
|
185
|
-
7
|
|
186
|
-
];
|
|
187
|
-
case 11:
|
|
188
|
-
return [
|
|
189
|
-
7
|
|
190
|
-
];
|
|
191
|
-
case 12:
|
|
192
|
-
writable.end();
|
|
193
|
-
return [
|
|
194
|
-
3,
|
|
195
|
-
14
|
|
196
|
-
];
|
|
197
|
-
case 13:
|
|
198
|
-
error = _state.sent();
|
|
199
|
-
writable.destroy(error);
|
|
200
|
-
throw error;
|
|
201
|
-
case 14:
|
|
202
|
-
return [
|
|
203
|
-
2
|
|
204
|
-
];
|
|
205
|
-
}
|
|
206
|
-
});
|
|
207
|
-
});
|
|
208
|
-
return _writeAsyncIterableToWritable.apply(this, arguments);
|
|
209
|
-
}
|
|
210
|
-
function readableStreamToString(stream, encoding) {
|
|
211
|
-
return _readableStreamToString.apply(this, arguments);
|
|
212
|
-
}
|
|
213
|
-
function _readableStreamToString() {
|
|
214
|
-
_readableStreamToString = _async_to_generator(function(stream, encoding) {
|
|
215
|
-
var reader, chunks, _ref, done, value;
|
|
216
|
-
return _ts_generator(this, function(_state) {
|
|
217
|
-
switch (_state.label) {
|
|
218
|
-
case 0:
|
|
219
|
-
reader = stream.getReader();
|
|
220
|
-
chunks = [];
|
|
221
|
-
_state.label = 1;
|
|
222
|
-
case 1:
|
|
223
|
-
if (false)
|
|
224
|
-
return [
|
|
225
|
-
3,
|
|
226
|
-
3
|
|
227
|
-
];
|
|
228
|
-
return [
|
|
229
|
-
4,
|
|
230
|
-
reader.read()
|
|
231
|
-
];
|
|
232
|
-
case 2:
|
|
233
|
-
_ref = _state.sent(), done = _ref.done, value = _ref.value;
|
|
234
|
-
if (done) {
|
|
235
|
-
return [
|
|
236
|
-
3,
|
|
237
|
-
3
|
|
238
|
-
];
|
|
239
|
-
}
|
|
240
|
-
if (value) {
|
|
241
|
-
chunks.push(value);
|
|
242
|
-
}
|
|
243
|
-
return [
|
|
244
|
-
3,
|
|
245
|
-
1
|
|
246
|
-
];
|
|
247
|
-
case 3:
|
|
248
|
-
return [
|
|
249
|
-
2,
|
|
250
|
-
Buffer.concat(chunks).toString(encoding)
|
|
251
|
-
];
|
|
252
|
-
}
|
|
253
|
-
});
|
|
254
|
-
});
|
|
255
|
-
return _readableStreamToString.apply(this, arguments);
|
|
256
|
-
}
|
|
257
|
-
var createReadableStreamFromReadable = function(source) {
|
|
258
|
-
var pump = new StreamPump(source);
|
|
259
|
-
var stream = new ReadableStream(pump, pump);
|
|
260
|
-
return stream;
|
|
261
|
-
};
|
|
262
|
-
var StreamPump = /* @__PURE__ */ function() {
|
|
263
|
-
"use strict";
|
|
264
|
-
function StreamPump2(stream) {
|
|
265
|
-
_class_call_check(this, StreamPump2);
|
|
266
|
-
this.highWaterMark = stream.readableHighWaterMark || new Stream.Readable().readableHighWaterMark;
|
|
267
|
-
this.accumalatedSize = 0;
|
|
268
|
-
this.stream = stream;
|
|
269
|
-
this.enqueue = this.enqueue.bind(this);
|
|
270
|
-
this.error = this.error.bind(this);
|
|
271
|
-
this.close = this.close.bind(this);
|
|
272
|
-
}
|
|
273
|
-
var _proto = StreamPump2.prototype;
|
|
274
|
-
_proto.size = function size(chunk) {
|
|
275
|
-
return (chunk === null || chunk === void 0 ? void 0 : chunk.byteLength) || 0;
|
|
276
|
-
};
|
|
277
|
-
_proto.start = function start(controller) {
|
|
278
|
-
this.controller = controller;
|
|
279
|
-
this.stream.on("data", this.enqueue);
|
|
280
|
-
this.stream.once("error", this.error);
|
|
281
|
-
this.stream.once("end", this.close);
|
|
282
|
-
this.stream.once("close", this.close);
|
|
283
|
-
};
|
|
284
|
-
_proto.pull = function pull() {
|
|
285
|
-
this.resume();
|
|
286
|
-
};
|
|
287
|
-
_proto.cancel = function cancel(reason) {
|
|
288
|
-
if (this.stream.destroy) {
|
|
289
|
-
this.stream.destroy(reason);
|
|
290
|
-
}
|
|
291
|
-
this.stream.off("data", this.enqueue);
|
|
292
|
-
this.stream.off("error", this.error);
|
|
293
|
-
this.stream.off("end", this.close);
|
|
294
|
-
this.stream.off("close", this.close);
|
|
295
|
-
};
|
|
296
|
-
_proto.enqueue = function enqueue(chunk) {
|
|
297
|
-
if (this.controller) {
|
|
298
|
-
try {
|
|
299
|
-
var bytes = _instanceof(chunk, Uint8Array) ? chunk : Buffer.from(chunk);
|
|
300
|
-
var available = (this.controller.desiredSize || 0) - bytes.byteLength;
|
|
301
|
-
this.controller.enqueue(bytes);
|
|
302
|
-
if (available <= 0) {
|
|
303
|
-
this.pause();
|
|
304
|
-
}
|
|
305
|
-
} catch (error) {
|
|
306
|
-
this.controller.error(new Error("Could not create Buffer, chunk must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object"));
|
|
307
|
-
this.cancel();
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
};
|
|
311
|
-
_proto.pause = function pause() {
|
|
312
|
-
if (this.stream.pause) {
|
|
313
|
-
this.stream.pause();
|
|
314
|
-
}
|
|
315
|
-
};
|
|
316
|
-
_proto.resume = function resume() {
|
|
317
|
-
if (this.stream.readable && this.stream.resume) {
|
|
318
|
-
this.stream.resume();
|
|
319
|
-
}
|
|
320
|
-
};
|
|
321
|
-
_proto.close = function close() {
|
|
322
|
-
if (this.controller) {
|
|
323
|
-
this.controller.close();
|
|
324
|
-
delete this.controller;
|
|
325
|
-
}
|
|
326
|
-
};
|
|
327
|
-
_proto.error = function error(error) {
|
|
328
|
-
if (this.controller) {
|
|
329
|
-
this.controller.error(error);
|
|
330
|
-
delete this.controller;
|
|
331
|
-
}
|
|
332
|
-
};
|
|
333
|
-
return StreamPump2;
|
|
334
|
-
}();
|
|
335
|
-
export {
|
|
336
|
-
createReadableStreamFromReadable,
|
|
337
|
-
readableStreamToString,
|
|
338
|
-
writeAsyncIterableToWritable,
|
|
339
|
-
writeReadableStreamToWritable
|
|
340
|
-
};
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { FormData as NodeFormData, Headers as NodeHeaders, Request as NodeRequest, Response as NodeResponse } from "@web-std/fetch";
|
|
2
|
-
import { Blob as NodeBlob, File as NodeFile } from "@web-std/file";
|
|
3
|
-
import { ReadableStream as NodeReadableStream, TransformStream as NodeTransformStream, WritableStream as NodeWritableStream } from "@web-std/stream";
|
|
4
|
-
if (!Object.getOwnPropertyDescriptor(NodeHeaders.prototype, "getSetCookie")) {
|
|
5
|
-
Object.defineProperty(NodeHeaders.prototype, "getSetCookie", {
|
|
6
|
-
value: function getSetCookie() {
|
|
7
|
-
const cookies = [];
|
|
8
|
-
this.forEach((value, name) => {
|
|
9
|
-
if (name.toLowerCase() === "set-cookie") {
|
|
10
|
-
cookies.push(value);
|
|
11
|
-
}
|
|
12
|
-
});
|
|
13
|
-
return cookies;
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
const installGlobals = () => {
|
|
18
|
-
if (!global.Headers) {
|
|
19
|
-
global.Headers = NodeHeaders;
|
|
20
|
-
}
|
|
21
|
-
if (!global.Request) {
|
|
22
|
-
global.Request = NodeRequest;
|
|
23
|
-
}
|
|
24
|
-
if (!global.Response) {
|
|
25
|
-
global.Response = NodeResponse;
|
|
26
|
-
}
|
|
27
|
-
if (!global.FormData) {
|
|
28
|
-
global.FormData = NodeFormData;
|
|
29
|
-
}
|
|
30
|
-
if (!global.TransformStream) {
|
|
31
|
-
global.TransformStream = NodeTransformStream;
|
|
32
|
-
}
|
|
33
|
-
if (!global.ReadableStream) {
|
|
34
|
-
global.ReadableStream = NodeReadableStream;
|
|
35
|
-
}
|
|
36
|
-
if (!global.WritableStream) {
|
|
37
|
-
global.WritableStream = NodeWritableStream;
|
|
38
|
-
}
|
|
39
|
-
if (!global.File) {
|
|
40
|
-
global.File = NodeFile;
|
|
41
|
-
}
|
|
42
|
-
if (!global.Blob) {
|
|
43
|
-
global.Blob = NodeBlob;
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
export {
|
|
47
|
-
installGlobals
|
|
48
|
-
};
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { Stream } from "node:stream";
|
|
2
|
-
async function writeReadableStreamToWritable(stream, writable) {
|
|
3
|
-
const reader = stream.getReader();
|
|
4
|
-
const flushable = writable;
|
|
5
|
-
try {
|
|
6
|
-
await new Promise((resolve, reject) => {
|
|
7
|
-
writable.on("finish", resolve);
|
|
8
|
-
writable.on("error", reject);
|
|
9
|
-
const writeAndFlush = async () => {
|
|
10
|
-
while (true) {
|
|
11
|
-
const { done, value } = await reader.read();
|
|
12
|
-
if (done) {
|
|
13
|
-
writable.end();
|
|
14
|
-
break;
|
|
15
|
-
}
|
|
16
|
-
writable.write(value);
|
|
17
|
-
if (typeof flushable.flush === "function") {
|
|
18
|
-
flushable.flush();
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
writeAndFlush().catch(reject);
|
|
23
|
-
});
|
|
24
|
-
} catch (error) {
|
|
25
|
-
writable.destroy(error);
|
|
26
|
-
throw error;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
async function writeAsyncIterableToWritable(iterable, writable) {
|
|
30
|
-
try {
|
|
31
|
-
for await (const chunk of iterable) {
|
|
32
|
-
writable.write(chunk);
|
|
33
|
-
}
|
|
34
|
-
writable.end();
|
|
35
|
-
} catch (error) {
|
|
36
|
-
writable.destroy(error);
|
|
37
|
-
throw error;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
async function readableStreamToString(stream, encoding) {
|
|
41
|
-
const reader = stream.getReader();
|
|
42
|
-
const chunks = [];
|
|
43
|
-
while (true) {
|
|
44
|
-
const { done, value } = await reader.read();
|
|
45
|
-
if (done) {
|
|
46
|
-
break;
|
|
47
|
-
}
|
|
48
|
-
if (value) {
|
|
49
|
-
chunks.push(value);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return Buffer.concat(chunks).toString(encoding);
|
|
53
|
-
}
|
|
54
|
-
const createReadableStreamFromReadable = (source) => {
|
|
55
|
-
const pump = new StreamPump(source);
|
|
56
|
-
const stream = new ReadableStream(pump, pump);
|
|
57
|
-
return stream;
|
|
58
|
-
};
|
|
59
|
-
class StreamPump {
|
|
60
|
-
size(chunk) {
|
|
61
|
-
return (chunk === null || chunk === void 0 ? void 0 : chunk.byteLength) || 0;
|
|
62
|
-
}
|
|
63
|
-
start(controller) {
|
|
64
|
-
this.controller = controller;
|
|
65
|
-
this.stream.on("data", this.enqueue);
|
|
66
|
-
this.stream.once("error", this.error);
|
|
67
|
-
this.stream.once("end", this.close);
|
|
68
|
-
this.stream.once("close", this.close);
|
|
69
|
-
}
|
|
70
|
-
pull() {
|
|
71
|
-
this.resume();
|
|
72
|
-
}
|
|
73
|
-
cancel(reason) {
|
|
74
|
-
if (this.stream.destroy) {
|
|
75
|
-
this.stream.destroy(reason);
|
|
76
|
-
}
|
|
77
|
-
this.stream.off("data", this.enqueue);
|
|
78
|
-
this.stream.off("error", this.error);
|
|
79
|
-
this.stream.off("end", this.close);
|
|
80
|
-
this.stream.off("close", this.close);
|
|
81
|
-
}
|
|
82
|
-
enqueue(chunk) {
|
|
83
|
-
if (this.controller) {
|
|
84
|
-
try {
|
|
85
|
-
const bytes = chunk instanceof Uint8Array ? chunk : Buffer.from(chunk);
|
|
86
|
-
const available = (this.controller.desiredSize || 0) - bytes.byteLength;
|
|
87
|
-
this.controller.enqueue(bytes);
|
|
88
|
-
if (available <= 0) {
|
|
89
|
-
this.pause();
|
|
90
|
-
}
|
|
91
|
-
} catch (error) {
|
|
92
|
-
this.controller.error(new Error("Could not create Buffer, chunk must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object"));
|
|
93
|
-
this.cancel();
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
pause() {
|
|
98
|
-
if (this.stream.pause) {
|
|
99
|
-
this.stream.pause();
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
resume() {
|
|
103
|
-
if (this.stream.readable && this.stream.resume) {
|
|
104
|
-
this.stream.resume();
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
close() {
|
|
108
|
-
if (this.controller) {
|
|
109
|
-
this.controller.close();
|
|
110
|
-
delete this.controller;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
error(error) {
|
|
114
|
-
if (this.controller) {
|
|
115
|
-
this.controller.error(error);
|
|
116
|
-
delete this.controller;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
constructor(stream) {
|
|
120
|
-
this.highWaterMark = stream.readableHighWaterMark || new Stream.Readable().readableHighWaterMark;
|
|
121
|
-
this.accumalatedSize = 0;
|
|
122
|
-
this.stream = stream;
|
|
123
|
-
this.enqueue = this.enqueue.bind(this);
|
|
124
|
-
this.error = this.error.bind(this);
|
|
125
|
-
this.close = this.close.bind(this);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
export {
|
|
129
|
-
createReadableStreamFromReadable,
|
|
130
|
-
readableStreamToString,
|
|
131
|
-
writeAsyncIterableToWritable,
|
|
132
|
-
writeReadableStreamToWritable
|
|
133
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const installGlobals: () => void;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The following code is modified based on
|
|
3
|
-
* https://github.com/remix-run/remix/blob/f7defe0b46c50947f6269d5ab5b6e3fe59339054/packages/remix-node/stream.ts#L3
|
|
4
|
-
*
|
|
5
|
-
* MIT Licensed
|
|
6
|
-
* Author Michael Jackson
|
|
7
|
-
* Copyright 2021 Remix Software Inc.
|
|
8
|
-
* https://github.com/remix-run/remix/blob/f7defe0b46c50947f6269d5ab5b6e3fe59339054/LICENSE.md
|
|
9
|
-
*/
|
|
10
|
-
import type { Readable, Writable } from 'node:stream';
|
|
11
|
-
export declare function writeReadableStreamToWritable(stream: ReadableStream, writable: Writable): Promise<void>;
|
|
12
|
-
export declare function writeAsyncIterableToWritable(iterable: AsyncIterable<Uint8Array>, writable: Writable): Promise<void>;
|
|
13
|
-
export declare function readableStreamToString(stream: ReadableStream<Uint8Array>, encoding?: BufferEncoding): Promise<string>;
|
|
14
|
-
export declare const createReadableStreamFromReadable: (source: Readable & {
|
|
15
|
-
readableHighWaterMark?: number;
|
|
16
|
-
}) => ReadableStream<Uint8Array>;
|