@modern-js/runtime-utils 2.54.6 → 2.55.0
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/node/index.js +3 -1
- package/dist/cjs/node/stream.js +102 -0
- package/dist/cjs/universal/request.js +78 -0
- package/dist/esm/node/index.js +1 -0
- package/dist/esm/node/stream.js +84 -0
- package/dist/esm/universal/request.js +51 -0
- package/dist/esm-node/node/index.js +1 -0
- package/dist/esm-node/node/stream.js +78 -0
- package/dist/esm-node/universal/request.js +50 -0
- package/dist/types/node/index.d.ts +1 -0
- package/dist/types/node/stream.d.ts +5 -0
- package/dist/types/universal/request.d.ts +17 -0
- package/package.json +13 -5
package/dist/cjs/node/index.js
CHANGED
|
@@ -28,6 +28,7 @@ var import_storage = require("./storage");
|
|
|
28
28
|
var import_serialize = require("./serialize");
|
|
29
29
|
__reExport(node_exports, require("./nestedRoutes"), module.exports);
|
|
30
30
|
__reExport(node_exports, require("./loaderContext"), module.exports);
|
|
31
|
+
__reExport(node_exports, require("./stream"), module.exports);
|
|
31
32
|
const { run, useContext: useHeaders } = (0, import_storage.createStorage)();
|
|
32
33
|
// Annotate the CommonJS export names for ESM import in node:
|
|
33
34
|
0 && (module.exports = {
|
|
@@ -35,5 +36,6 @@ const { run, useContext: useHeaders } = (0, import_storage.createStorage)();
|
|
|
35
36
|
serializeJson,
|
|
36
37
|
useHeaders,
|
|
37
38
|
...require("./nestedRoutes"),
|
|
38
|
-
...require("./loaderContext")
|
|
39
|
+
...require("./loaderContext"),
|
|
40
|
+
...require("./stream")
|
|
39
41
|
});
|
|
@@ -0,0 +1,102 @@
|
|
|
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
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(stream_exports);
|
|
24
|
+
var import_stream = require("stream");
|
|
25
|
+
const createReadableStreamFromReadable = (source) => {
|
|
26
|
+
const pump = new StreamPump(source);
|
|
27
|
+
const stream = new ReadableStream(pump, pump);
|
|
28
|
+
return stream;
|
|
29
|
+
};
|
|
30
|
+
class StreamPump {
|
|
31
|
+
size(chunk) {
|
|
32
|
+
return (chunk === null || chunk === void 0 ? void 0 : chunk.byteLength) || 0;
|
|
33
|
+
}
|
|
34
|
+
start(controller) {
|
|
35
|
+
this.controller = controller;
|
|
36
|
+
this.stream.on("data", this.enqueue);
|
|
37
|
+
this.stream.once("error", this.error);
|
|
38
|
+
this.stream.once("end", this.close);
|
|
39
|
+
this.stream.once("close", this.close);
|
|
40
|
+
}
|
|
41
|
+
pull() {
|
|
42
|
+
this.resume();
|
|
43
|
+
}
|
|
44
|
+
cancel(reason) {
|
|
45
|
+
if (this.stream.destroy) {
|
|
46
|
+
this.stream.destroy(reason);
|
|
47
|
+
}
|
|
48
|
+
this.stream.off("data", this.enqueue);
|
|
49
|
+
this.stream.off("error", this.error);
|
|
50
|
+
this.stream.off("end", this.close);
|
|
51
|
+
this.stream.off("close", this.close);
|
|
52
|
+
}
|
|
53
|
+
enqueue(chunk) {
|
|
54
|
+
if (this.controller) {
|
|
55
|
+
try {
|
|
56
|
+
const bytes = chunk instanceof Uint8Array ? chunk : Buffer.from(chunk);
|
|
57
|
+
const available = (this.controller.desiredSize || 0) - bytes.byteLength;
|
|
58
|
+
this.controller.enqueue(bytes);
|
|
59
|
+
if (available <= 0) {
|
|
60
|
+
this.pause();
|
|
61
|
+
}
|
|
62
|
+
} catch (error) {
|
|
63
|
+
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"));
|
|
64
|
+
this.cancel();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
pause() {
|
|
69
|
+
if (this.stream.pause) {
|
|
70
|
+
this.stream.pause();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
resume() {
|
|
74
|
+
if (this.stream.readable && this.stream.resume) {
|
|
75
|
+
this.stream.resume();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
close() {
|
|
79
|
+
if (this.controller) {
|
|
80
|
+
this.controller.close();
|
|
81
|
+
delete this.controller;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
error(error) {
|
|
85
|
+
if (this.controller) {
|
|
86
|
+
this.controller.error(error);
|
|
87
|
+
delete this.controller;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
constructor(stream) {
|
|
91
|
+
this.highWaterMark = stream.readableHighWaterMark || new import_stream.Stream.Readable().readableHighWaterMark;
|
|
92
|
+
this.accumalatedSize = 0;
|
|
93
|
+
this.stream = stream;
|
|
94
|
+
this.enqueue = this.enqueue.bind(this);
|
|
95
|
+
this.error = this.error.bind(this);
|
|
96
|
+
this.close = this.close.bind(this);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
100
|
+
0 && (module.exports = {
|
|
101
|
+
createReadableStreamFromReadable
|
|
102
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
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 request_exports = {};
|
|
20
|
+
__export(request_exports, {
|
|
21
|
+
getHost: () => getHost,
|
|
22
|
+
getPathname: () => getPathname,
|
|
23
|
+
parseCookie: () => parseCookie,
|
|
24
|
+
parseHeaders: () => parseHeaders,
|
|
25
|
+
parseQuery: () => parseQuery
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(request_exports);
|
|
28
|
+
function parseQuery(req) {
|
|
29
|
+
const query = {};
|
|
30
|
+
const { url } = req;
|
|
31
|
+
const q = url.split("?")[1];
|
|
32
|
+
if (q) {
|
|
33
|
+
const search = new URLSearchParams(q);
|
|
34
|
+
search.forEach((v, k) => {
|
|
35
|
+
query[k] = v;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return query;
|
|
39
|
+
}
|
|
40
|
+
function parseHeaders(request) {
|
|
41
|
+
const headersData = {};
|
|
42
|
+
request.headers.forEach((value, key) => {
|
|
43
|
+
headersData[key] = value;
|
|
44
|
+
});
|
|
45
|
+
return headersData;
|
|
46
|
+
}
|
|
47
|
+
function getPathname(request) {
|
|
48
|
+
const match = request.url.match(/^https?:\/\/[^/]+(\/[^?]*)/);
|
|
49
|
+
return match ? match[1] : "/";
|
|
50
|
+
}
|
|
51
|
+
function getHost(request) {
|
|
52
|
+
const { headers } = request;
|
|
53
|
+
let host = headers.get("X-Forwarded-Host");
|
|
54
|
+
if (!host) {
|
|
55
|
+
host = headers.get("Host");
|
|
56
|
+
}
|
|
57
|
+
host = (host === null || host === void 0 ? void 0 : host.split(/\s*,\s*/, 1)[0]) || "undefined";
|
|
58
|
+
return host;
|
|
59
|
+
}
|
|
60
|
+
function parseCookie(req) {
|
|
61
|
+
const _cookie = req.headers.get("Cookie");
|
|
62
|
+
const cookie = {};
|
|
63
|
+
_cookie === null || _cookie === void 0 ? void 0 : _cookie.trim().split(";").forEach((item) => {
|
|
64
|
+
const [k, v] = item.trim().split("=");
|
|
65
|
+
if (k) {
|
|
66
|
+
cookie[k] = v;
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
return cookie;
|
|
70
|
+
}
|
|
71
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
72
|
+
0 && (module.exports = {
|
|
73
|
+
getHost,
|
|
74
|
+
getPathname,
|
|
75
|
+
parseCookie,
|
|
76
|
+
parseHeaders,
|
|
77
|
+
parseQuery
|
|
78
|
+
});
|
package/dist/esm/node/index.js
CHANGED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
|
|
2
|
+
import { _ as _instanceof } from "@swc/helpers/_/_instanceof";
|
|
3
|
+
import { Stream } from "stream";
|
|
4
|
+
var createReadableStreamFromReadable = function(source) {
|
|
5
|
+
var pump = new StreamPump(source);
|
|
6
|
+
var stream = new ReadableStream(pump, pump);
|
|
7
|
+
return stream;
|
|
8
|
+
};
|
|
9
|
+
var StreamPump = /* @__PURE__ */ function() {
|
|
10
|
+
"use strict";
|
|
11
|
+
function StreamPump2(stream) {
|
|
12
|
+
_class_call_check(this, StreamPump2);
|
|
13
|
+
this.highWaterMark = stream.readableHighWaterMark || new Stream.Readable().readableHighWaterMark;
|
|
14
|
+
this.accumalatedSize = 0;
|
|
15
|
+
this.stream = stream;
|
|
16
|
+
this.enqueue = this.enqueue.bind(this);
|
|
17
|
+
this.error = this.error.bind(this);
|
|
18
|
+
this.close = this.close.bind(this);
|
|
19
|
+
}
|
|
20
|
+
var _proto = StreamPump2.prototype;
|
|
21
|
+
_proto.size = function size(chunk) {
|
|
22
|
+
return (chunk === null || chunk === void 0 ? void 0 : chunk.byteLength) || 0;
|
|
23
|
+
};
|
|
24
|
+
_proto.start = function start(controller) {
|
|
25
|
+
this.controller = controller;
|
|
26
|
+
this.stream.on("data", this.enqueue);
|
|
27
|
+
this.stream.once("error", this.error);
|
|
28
|
+
this.stream.once("end", this.close);
|
|
29
|
+
this.stream.once("close", this.close);
|
|
30
|
+
};
|
|
31
|
+
_proto.pull = function pull() {
|
|
32
|
+
this.resume();
|
|
33
|
+
};
|
|
34
|
+
_proto.cancel = function cancel(reason) {
|
|
35
|
+
if (this.stream.destroy) {
|
|
36
|
+
this.stream.destroy(reason);
|
|
37
|
+
}
|
|
38
|
+
this.stream.off("data", this.enqueue);
|
|
39
|
+
this.stream.off("error", this.error);
|
|
40
|
+
this.stream.off("end", this.close);
|
|
41
|
+
this.stream.off("close", this.close);
|
|
42
|
+
};
|
|
43
|
+
_proto.enqueue = function enqueue(chunk) {
|
|
44
|
+
if (this.controller) {
|
|
45
|
+
try {
|
|
46
|
+
var bytes = _instanceof(chunk, Uint8Array) ? chunk : Buffer.from(chunk);
|
|
47
|
+
var available = (this.controller.desiredSize || 0) - bytes.byteLength;
|
|
48
|
+
this.controller.enqueue(bytes);
|
|
49
|
+
if (available <= 0) {
|
|
50
|
+
this.pause();
|
|
51
|
+
}
|
|
52
|
+
} catch (error) {
|
|
53
|
+
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"));
|
|
54
|
+
this.cancel();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
_proto.pause = function pause() {
|
|
59
|
+
if (this.stream.pause) {
|
|
60
|
+
this.stream.pause();
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
_proto.resume = function resume() {
|
|
64
|
+
if (this.stream.readable && this.stream.resume) {
|
|
65
|
+
this.stream.resume();
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
_proto.close = function close() {
|
|
69
|
+
if (this.controller) {
|
|
70
|
+
this.controller.close();
|
|
71
|
+
delete this.controller;
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
_proto.error = function error(error) {
|
|
75
|
+
if (this.controller) {
|
|
76
|
+
this.controller.error(error);
|
|
77
|
+
delete this.controller;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
return StreamPump2;
|
|
81
|
+
}();
|
|
82
|
+
export {
|
|
83
|
+
createReadableStreamFromReadable
|
|
84
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
|
2
|
+
function parseQuery(req) {
|
|
3
|
+
var query = {};
|
|
4
|
+
var url = req.url;
|
|
5
|
+
var q = url.split("?")[1];
|
|
6
|
+
if (q) {
|
|
7
|
+
var search = new URLSearchParams(q);
|
|
8
|
+
search.forEach(function(v, k) {
|
|
9
|
+
query[k] = v;
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
return query;
|
|
13
|
+
}
|
|
14
|
+
function parseHeaders(request) {
|
|
15
|
+
var headersData = {};
|
|
16
|
+
request.headers.forEach(function(value, key) {
|
|
17
|
+
headersData[key] = value;
|
|
18
|
+
});
|
|
19
|
+
return headersData;
|
|
20
|
+
}
|
|
21
|
+
function getPathname(request) {
|
|
22
|
+
var match = request.url.match(/^https?:\/\/[^/]+(\/[^?]*)/);
|
|
23
|
+
return match ? match[1] : "/";
|
|
24
|
+
}
|
|
25
|
+
function getHost(request) {
|
|
26
|
+
var headers = request.headers;
|
|
27
|
+
var host = headers.get("X-Forwarded-Host");
|
|
28
|
+
if (!host) {
|
|
29
|
+
host = headers.get("Host");
|
|
30
|
+
}
|
|
31
|
+
host = (host === null || host === void 0 ? void 0 : host.split(/\s*,\s*/, 1)[0]) || "undefined";
|
|
32
|
+
return host;
|
|
33
|
+
}
|
|
34
|
+
function parseCookie(req) {
|
|
35
|
+
var _cookie = req.headers.get("Cookie");
|
|
36
|
+
var cookie = {};
|
|
37
|
+
_cookie === null || _cookie === void 0 ? void 0 : _cookie.trim().split(";").forEach(function(item) {
|
|
38
|
+
var _item_trim_split = _sliced_to_array(item.trim().split("="), 2), k = _item_trim_split[0], v = _item_trim_split[1];
|
|
39
|
+
if (k) {
|
|
40
|
+
cookie[k] = v;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
return cookie;
|
|
44
|
+
}
|
|
45
|
+
export {
|
|
46
|
+
getHost,
|
|
47
|
+
getPathname,
|
|
48
|
+
parseCookie,
|
|
49
|
+
parseHeaders,
|
|
50
|
+
parseQuery
|
|
51
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Stream } from "stream";
|
|
2
|
+
const createReadableStreamFromReadable = (source) => {
|
|
3
|
+
const pump = new StreamPump(source);
|
|
4
|
+
const stream = new ReadableStream(pump, pump);
|
|
5
|
+
return stream;
|
|
6
|
+
};
|
|
7
|
+
class StreamPump {
|
|
8
|
+
size(chunk) {
|
|
9
|
+
return (chunk === null || chunk === void 0 ? void 0 : chunk.byteLength) || 0;
|
|
10
|
+
}
|
|
11
|
+
start(controller) {
|
|
12
|
+
this.controller = controller;
|
|
13
|
+
this.stream.on("data", this.enqueue);
|
|
14
|
+
this.stream.once("error", this.error);
|
|
15
|
+
this.stream.once("end", this.close);
|
|
16
|
+
this.stream.once("close", this.close);
|
|
17
|
+
}
|
|
18
|
+
pull() {
|
|
19
|
+
this.resume();
|
|
20
|
+
}
|
|
21
|
+
cancel(reason) {
|
|
22
|
+
if (this.stream.destroy) {
|
|
23
|
+
this.stream.destroy(reason);
|
|
24
|
+
}
|
|
25
|
+
this.stream.off("data", this.enqueue);
|
|
26
|
+
this.stream.off("error", this.error);
|
|
27
|
+
this.stream.off("end", this.close);
|
|
28
|
+
this.stream.off("close", this.close);
|
|
29
|
+
}
|
|
30
|
+
enqueue(chunk) {
|
|
31
|
+
if (this.controller) {
|
|
32
|
+
try {
|
|
33
|
+
const bytes = chunk instanceof Uint8Array ? chunk : Buffer.from(chunk);
|
|
34
|
+
const available = (this.controller.desiredSize || 0) - bytes.byteLength;
|
|
35
|
+
this.controller.enqueue(bytes);
|
|
36
|
+
if (available <= 0) {
|
|
37
|
+
this.pause();
|
|
38
|
+
}
|
|
39
|
+
} catch (error) {
|
|
40
|
+
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"));
|
|
41
|
+
this.cancel();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
pause() {
|
|
46
|
+
if (this.stream.pause) {
|
|
47
|
+
this.stream.pause();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
resume() {
|
|
51
|
+
if (this.stream.readable && this.stream.resume) {
|
|
52
|
+
this.stream.resume();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
close() {
|
|
56
|
+
if (this.controller) {
|
|
57
|
+
this.controller.close();
|
|
58
|
+
delete this.controller;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
error(error) {
|
|
62
|
+
if (this.controller) {
|
|
63
|
+
this.controller.error(error);
|
|
64
|
+
delete this.controller;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
constructor(stream) {
|
|
68
|
+
this.highWaterMark = stream.readableHighWaterMark || new Stream.Readable().readableHighWaterMark;
|
|
69
|
+
this.accumalatedSize = 0;
|
|
70
|
+
this.stream = stream;
|
|
71
|
+
this.enqueue = this.enqueue.bind(this);
|
|
72
|
+
this.error = this.error.bind(this);
|
|
73
|
+
this.close = this.close.bind(this);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
export {
|
|
77
|
+
createReadableStreamFromReadable
|
|
78
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
function parseQuery(req) {
|
|
2
|
+
const query = {};
|
|
3
|
+
const { url } = req;
|
|
4
|
+
const q = url.split("?")[1];
|
|
5
|
+
if (q) {
|
|
6
|
+
const search = new URLSearchParams(q);
|
|
7
|
+
search.forEach((v, k) => {
|
|
8
|
+
query[k] = v;
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
return query;
|
|
12
|
+
}
|
|
13
|
+
function parseHeaders(request) {
|
|
14
|
+
const headersData = {};
|
|
15
|
+
request.headers.forEach((value, key) => {
|
|
16
|
+
headersData[key] = value;
|
|
17
|
+
});
|
|
18
|
+
return headersData;
|
|
19
|
+
}
|
|
20
|
+
function getPathname(request) {
|
|
21
|
+
const match = request.url.match(/^https?:\/\/[^/]+(\/[^?]*)/);
|
|
22
|
+
return match ? match[1] : "/";
|
|
23
|
+
}
|
|
24
|
+
function getHost(request) {
|
|
25
|
+
const { headers } = request;
|
|
26
|
+
let host = headers.get("X-Forwarded-Host");
|
|
27
|
+
if (!host) {
|
|
28
|
+
host = headers.get("Host");
|
|
29
|
+
}
|
|
30
|
+
host = (host === null || host === void 0 ? void 0 : host.split(/\s*,\s*/, 1)[0]) || "undefined";
|
|
31
|
+
return host;
|
|
32
|
+
}
|
|
33
|
+
function parseCookie(req) {
|
|
34
|
+
const _cookie = req.headers.get("Cookie");
|
|
35
|
+
const cookie = {};
|
|
36
|
+
_cookie === null || _cookie === void 0 ? void 0 : _cookie.trim().split(";").forEach((item) => {
|
|
37
|
+
const [k, v] = item.trim().split("=");
|
|
38
|
+
if (k) {
|
|
39
|
+
cookie[k] = v;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
return cookie;
|
|
43
|
+
}
|
|
44
|
+
export {
|
|
45
|
+
getHost,
|
|
46
|
+
getPathname,
|
|
47
|
+
parseCookie,
|
|
48
|
+
parseHeaders,
|
|
49
|
+
parseQuery
|
|
50
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type Query = Record<string, string>;
|
|
2
|
+
export declare function parseQuery(req: Request): Query;
|
|
3
|
+
export type HeadersData = Record<string, string | undefined>;
|
|
4
|
+
export declare function parseHeaders(request: Request): HeadersData;
|
|
5
|
+
/**
|
|
6
|
+
* The function is modified based on
|
|
7
|
+
* https://github.com/honojs/hono/blob/main/src/utils/url.ts
|
|
8
|
+
*
|
|
9
|
+
* MIT Licensed
|
|
10
|
+
* https://github.com/honojs/hono/blob/main/LICENSE
|
|
11
|
+
*
|
|
12
|
+
*/
|
|
13
|
+
export declare function getPathname(request: Request): string;
|
|
14
|
+
export declare function getHost(request: Request): string;
|
|
15
|
+
type Cookie = Record<string, string>;
|
|
16
|
+
export declare function parseCookie(req: Request): Cookie;
|
|
17
|
+
export {};
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.
|
|
18
|
+
"version": "2.55.0",
|
|
19
19
|
"_comment": "Provide ESM and CJS exports, ESM is used by runtime package, for treeshaking",
|
|
20
20
|
"exports": {
|
|
21
21
|
"./router": {
|
|
@@ -43,6 +43,11 @@
|
|
|
43
43
|
"require": "./dist/cjs/node/router.js",
|
|
44
44
|
"default": "./dist/esm/node/router.js"
|
|
45
45
|
},
|
|
46
|
+
"./universal/request": {
|
|
47
|
+
"types": "./dist/universal/request.d.ts",
|
|
48
|
+
"require": "./dist/cjs/universal/request.js",
|
|
49
|
+
"default": "./dist/esm/universal/request.js"
|
|
50
|
+
},
|
|
46
51
|
"./time": {
|
|
47
52
|
"types": "./dist/types/time.d.ts",
|
|
48
53
|
"require": "./dist/cjs/time.js",
|
|
@@ -91,6 +96,9 @@
|
|
|
91
96
|
"node/router": [
|
|
92
97
|
"./dist/types/node/router.d.ts"
|
|
93
98
|
],
|
|
99
|
+
"universal/request": [
|
|
100
|
+
"./dist/types/universal/request.d.ts"
|
|
101
|
+
],
|
|
94
102
|
"time": [
|
|
95
103
|
"./dist/types/time.d.ts"
|
|
96
104
|
],
|
|
@@ -114,7 +122,7 @@
|
|
|
114
122
|
"react-router-dom": "6.22.0",
|
|
115
123
|
"@remix-run/router": "1.15.0",
|
|
116
124
|
"@swc/helpers": "0.5.3",
|
|
117
|
-
"@modern-js/utils": "2.
|
|
125
|
+
"@modern-js/utils": "2.55.0"
|
|
118
126
|
},
|
|
119
127
|
"peerDependencies": {
|
|
120
128
|
"react": ">=17.0.0",
|
|
@@ -137,9 +145,9 @@
|
|
|
137
145
|
"jest": "^29",
|
|
138
146
|
"typescript": "^5",
|
|
139
147
|
"@types/serialize-javascript": "^5.0.1",
|
|
140
|
-
"@scripts/build": "2.
|
|
141
|
-
"@scripts/jest-config": "2.
|
|
142
|
-
"@modern-js/types": "2.
|
|
148
|
+
"@scripts/build": "2.55.0",
|
|
149
|
+
"@scripts/jest-config": "2.55.0",
|
|
150
|
+
"@modern-js/types": "2.55.0"
|
|
143
151
|
},
|
|
144
152
|
"sideEffects": false,
|
|
145
153
|
"scripts": {
|