@hono/node-server 1.19.14 → 2.0.0-rc.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 (63) hide show
  1. package/README.md +56 -18
  2. package/dist/conninfo.cjs +22 -0
  3. package/dist/{conninfo.d.ts → conninfo.d.cts} +4 -3
  4. package/dist/conninfo.d.mts +4 -3
  5. package/dist/conninfo.mjs +19 -16
  6. package/dist/constants-BLSFu_RU.mjs +5 -0
  7. package/dist/constants-BXAKTxRC.cjs +11 -0
  8. package/dist/index.cjs +1006 -0
  9. package/dist/index.d.cts +73 -0
  10. package/dist/index.d.mts +73 -8
  11. package/dist/index.mjs +976 -637
  12. package/dist/serve-static.cjs +135 -0
  13. package/dist/serve-static.d.cts +18 -0
  14. package/dist/serve-static.d.mts +14 -13
  15. package/dist/serve-static.mjs +127 -145
  16. package/dist/utils/response.cjs +8 -0
  17. package/dist/utils/response.d.cts +4 -0
  18. package/dist/utils/response.d.mts +3 -2
  19. package/dist/utils/response.mjs +6 -9
  20. package/package.json +53 -40
  21. package/dist/conninfo.js +0 -42
  22. package/dist/globals.d.mts +0 -2
  23. package/dist/globals.d.ts +0 -2
  24. package/dist/globals.js +0 -29
  25. package/dist/globals.mjs +0 -5
  26. package/dist/index.d.ts +0 -8
  27. package/dist/index.js +0 -702
  28. package/dist/listener.d.mts +0 -13
  29. package/dist/listener.d.ts +0 -13
  30. package/dist/listener.js +0 -670
  31. package/dist/listener.mjs +0 -635
  32. package/dist/request.d.mts +0 -25
  33. package/dist/request.d.ts +0 -25
  34. package/dist/request.js +0 -238
  35. package/dist/request.mjs +0 -206
  36. package/dist/response.d.mts +0 -26
  37. package/dist/response.d.ts +0 -26
  38. package/dist/response.js +0 -112
  39. package/dist/response.mjs +0 -85
  40. package/dist/serve-static.d.ts +0 -17
  41. package/dist/serve-static.js +0 -177
  42. package/dist/server.d.mts +0 -10
  43. package/dist/server.d.ts +0 -10
  44. package/dist/server.js +0 -696
  45. package/dist/server.mjs +0 -660
  46. package/dist/types.d.mts +0 -44
  47. package/dist/types.d.ts +0 -44
  48. package/dist/types.js +0 -18
  49. package/dist/types.mjs +0 -0
  50. package/dist/utils/response/constants.d.mts +0 -3
  51. package/dist/utils/response/constants.d.ts +0 -3
  52. package/dist/utils/response/constants.js +0 -30
  53. package/dist/utils/response/constants.mjs +0 -5
  54. package/dist/utils/response.d.ts +0 -3
  55. package/dist/utils/response.js +0 -37
  56. package/dist/utils.d.mts +0 -9
  57. package/dist/utils.d.ts +0 -9
  58. package/dist/utils.js +0 -99
  59. package/dist/utils.mjs +0 -71
  60. package/dist/vercel.d.mts +0 -7
  61. package/dist/vercel.d.ts +0 -7
  62. package/dist/vercel.js +0 -677
  63. package/dist/vercel.mjs +0 -640
package/dist/request.js DELETED
@@ -1,238 +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
-
20
- // src/request.ts
21
- var request_exports = {};
22
- __export(request_exports, {
23
- GlobalRequest: () => GlobalRequest,
24
- Request: () => Request,
25
- RequestError: () => RequestError,
26
- abortControllerKey: () => abortControllerKey,
27
- getAbortController: () => getAbortController,
28
- newRequest: () => newRequest,
29
- toRequestError: () => toRequestError,
30
- wrapBodyStream: () => wrapBodyStream
31
- });
32
- module.exports = __toCommonJS(request_exports);
33
- var import_node_http2 = require("http2");
34
- var import_node_stream = require("stream");
35
- var RequestError = class extends Error {
36
- constructor(message, options) {
37
- super(message, options);
38
- this.name = "RequestError";
39
- }
40
- };
41
- var toRequestError = (e) => {
42
- if (e instanceof RequestError) {
43
- return e;
44
- }
45
- return new RequestError(e.message, { cause: e });
46
- };
47
- var GlobalRequest = global.Request;
48
- var Request = class extends GlobalRequest {
49
- constructor(input, options) {
50
- if (typeof input === "object" && getRequestCache in input) {
51
- input = input[getRequestCache]();
52
- }
53
- if (typeof options?.body?.getReader !== "undefined") {
54
- ;
55
- options.duplex ??= "half";
56
- }
57
- super(input, options);
58
- }
59
- };
60
- var newHeadersFromIncoming = (incoming) => {
61
- const headerRecord = [];
62
- const rawHeaders = incoming.rawHeaders;
63
- for (let i = 0; i < rawHeaders.length; i += 2) {
64
- const { [i]: key, [i + 1]: value } = rawHeaders;
65
- if (key.charCodeAt(0) !== /*:*/
66
- 58) {
67
- headerRecord.push([key, value]);
68
- }
69
- }
70
- return new Headers(headerRecord);
71
- };
72
- var wrapBodyStream = Symbol("wrapBodyStream");
73
- var newRequestFromIncoming = (method, url, headers, incoming, abortController) => {
74
- const init = {
75
- method,
76
- headers,
77
- signal: abortController.signal
78
- };
79
- if (method === "TRACE") {
80
- init.method = "GET";
81
- const req = new Request(url, init);
82
- Object.defineProperty(req, "method", {
83
- get() {
84
- return "TRACE";
85
- }
86
- });
87
- return req;
88
- }
89
- if (!(method === "GET" || method === "HEAD")) {
90
- if ("rawBody" in incoming && incoming.rawBody instanceof Buffer) {
91
- init.body = new ReadableStream({
92
- start(controller) {
93
- controller.enqueue(incoming.rawBody);
94
- controller.close();
95
- }
96
- });
97
- } else if (incoming[wrapBodyStream]) {
98
- let reader;
99
- init.body = new ReadableStream({
100
- async pull(controller) {
101
- try {
102
- reader ||= import_node_stream.Readable.toWeb(incoming).getReader();
103
- const { done, value } = await reader.read();
104
- if (done) {
105
- controller.close();
106
- } else {
107
- controller.enqueue(value);
108
- }
109
- } catch (error) {
110
- controller.error(error);
111
- }
112
- }
113
- });
114
- } else {
115
- init.body = import_node_stream.Readable.toWeb(incoming);
116
- }
117
- }
118
- return new Request(url, init);
119
- };
120
- var getRequestCache = Symbol("getRequestCache");
121
- var requestCache = Symbol("requestCache");
122
- var incomingKey = Symbol("incomingKey");
123
- var urlKey = Symbol("urlKey");
124
- var headersKey = Symbol("headersKey");
125
- var abortControllerKey = Symbol("abortControllerKey");
126
- var getAbortController = Symbol("getAbortController");
127
- var requestPrototype = {
128
- get method() {
129
- return this[incomingKey].method || "GET";
130
- },
131
- get url() {
132
- return this[urlKey];
133
- },
134
- get headers() {
135
- return this[headersKey] ||= newHeadersFromIncoming(this[incomingKey]);
136
- },
137
- [getAbortController]() {
138
- this[getRequestCache]();
139
- return this[abortControllerKey];
140
- },
141
- [getRequestCache]() {
142
- this[abortControllerKey] ||= new AbortController();
143
- return this[requestCache] ||= newRequestFromIncoming(
144
- this.method,
145
- this[urlKey],
146
- this.headers,
147
- this[incomingKey],
148
- this[abortControllerKey]
149
- );
150
- }
151
- };
152
- [
153
- "body",
154
- "bodyUsed",
155
- "cache",
156
- "credentials",
157
- "destination",
158
- "integrity",
159
- "mode",
160
- "redirect",
161
- "referrer",
162
- "referrerPolicy",
163
- "signal",
164
- "keepalive"
165
- ].forEach((k) => {
166
- Object.defineProperty(requestPrototype, k, {
167
- get() {
168
- return this[getRequestCache]()[k];
169
- }
170
- });
171
- });
172
- ["arrayBuffer", "blob", "clone", "formData", "json", "text"].forEach((k) => {
173
- Object.defineProperty(requestPrototype, k, {
174
- value: function() {
175
- return this[getRequestCache]()[k]();
176
- }
177
- });
178
- });
179
- Object.defineProperty(requestPrototype, Symbol.for("nodejs.util.inspect.custom"), {
180
- value: function(depth, options, inspectFn) {
181
- const props = {
182
- method: this.method,
183
- url: this.url,
184
- headers: this.headers,
185
- nativeRequest: this[requestCache]
186
- };
187
- return `Request (lightweight) ${inspectFn(props, { ...options, depth: depth == null ? null : depth - 1 })}`;
188
- }
189
- });
190
- Object.setPrototypeOf(requestPrototype, Request.prototype);
191
- var newRequest = (incoming, defaultHostname) => {
192
- const req = Object.create(requestPrototype);
193
- req[incomingKey] = incoming;
194
- const incomingUrl = incoming.url || "";
195
- if (incomingUrl[0] !== "/" && // short-circuit for performance. most requests are relative URL.
196
- (incomingUrl.startsWith("http://") || incomingUrl.startsWith("https://"))) {
197
- if (incoming instanceof import_node_http2.Http2ServerRequest) {
198
- throw new RequestError("Absolute URL for :path is not allowed in HTTP/2");
199
- }
200
- try {
201
- const url2 = new URL(incomingUrl);
202
- req[urlKey] = url2.href;
203
- } catch (e) {
204
- throw new RequestError("Invalid absolute URL", { cause: e });
205
- }
206
- return req;
207
- }
208
- const host = (incoming instanceof import_node_http2.Http2ServerRequest ? incoming.authority : incoming.headers.host) || defaultHostname;
209
- if (!host) {
210
- throw new RequestError("Missing host header");
211
- }
212
- let scheme;
213
- if (incoming instanceof import_node_http2.Http2ServerRequest) {
214
- scheme = incoming.scheme;
215
- if (!(scheme === "http" || scheme === "https")) {
216
- throw new RequestError("Unsupported scheme");
217
- }
218
- } else {
219
- scheme = incoming.socket && incoming.socket.encrypted ? "https" : "http";
220
- }
221
- const url = new URL(`${scheme}://${host}${incomingUrl}`);
222
- if (url.hostname.length !== host.length && url.hostname !== host.replace(/:\d+$/, "")) {
223
- throw new RequestError("Invalid host header");
224
- }
225
- req[urlKey] = url.href;
226
- return req;
227
- };
228
- // Annotate the CommonJS export names for ESM import in node:
229
- 0 && (module.exports = {
230
- GlobalRequest,
231
- Request,
232
- RequestError,
233
- abortControllerKey,
234
- getAbortController,
235
- newRequest,
236
- toRequestError,
237
- wrapBodyStream
238
- });
package/dist/request.mjs DELETED
@@ -1,206 +0,0 @@
1
- // src/request.ts
2
- import { Http2ServerRequest } from "http2";
3
- import { Readable } from "stream";
4
- var RequestError = class extends Error {
5
- constructor(message, options) {
6
- super(message, options);
7
- this.name = "RequestError";
8
- }
9
- };
10
- var toRequestError = (e) => {
11
- if (e instanceof RequestError) {
12
- return e;
13
- }
14
- return new RequestError(e.message, { cause: e });
15
- };
16
- var GlobalRequest = global.Request;
17
- var Request = class extends GlobalRequest {
18
- constructor(input, options) {
19
- if (typeof input === "object" && getRequestCache in input) {
20
- input = input[getRequestCache]();
21
- }
22
- if (typeof options?.body?.getReader !== "undefined") {
23
- ;
24
- options.duplex ??= "half";
25
- }
26
- super(input, options);
27
- }
28
- };
29
- var newHeadersFromIncoming = (incoming) => {
30
- const headerRecord = [];
31
- const rawHeaders = incoming.rawHeaders;
32
- for (let i = 0; i < rawHeaders.length; i += 2) {
33
- const { [i]: key, [i + 1]: value } = rawHeaders;
34
- if (key.charCodeAt(0) !== /*:*/
35
- 58) {
36
- headerRecord.push([key, value]);
37
- }
38
- }
39
- return new Headers(headerRecord);
40
- };
41
- var wrapBodyStream = Symbol("wrapBodyStream");
42
- var newRequestFromIncoming = (method, url, headers, incoming, abortController) => {
43
- const init = {
44
- method,
45
- headers,
46
- signal: abortController.signal
47
- };
48
- if (method === "TRACE") {
49
- init.method = "GET";
50
- const req = new Request(url, init);
51
- Object.defineProperty(req, "method", {
52
- get() {
53
- return "TRACE";
54
- }
55
- });
56
- return req;
57
- }
58
- if (!(method === "GET" || method === "HEAD")) {
59
- if ("rawBody" in incoming && incoming.rawBody instanceof Buffer) {
60
- init.body = new ReadableStream({
61
- start(controller) {
62
- controller.enqueue(incoming.rawBody);
63
- controller.close();
64
- }
65
- });
66
- } else if (incoming[wrapBodyStream]) {
67
- let reader;
68
- init.body = new ReadableStream({
69
- async pull(controller) {
70
- try {
71
- reader ||= Readable.toWeb(incoming).getReader();
72
- const { done, value } = await reader.read();
73
- if (done) {
74
- controller.close();
75
- } else {
76
- controller.enqueue(value);
77
- }
78
- } catch (error) {
79
- controller.error(error);
80
- }
81
- }
82
- });
83
- } else {
84
- init.body = Readable.toWeb(incoming);
85
- }
86
- }
87
- return new Request(url, init);
88
- };
89
- var getRequestCache = Symbol("getRequestCache");
90
- var requestCache = Symbol("requestCache");
91
- var incomingKey = Symbol("incomingKey");
92
- var urlKey = Symbol("urlKey");
93
- var headersKey = Symbol("headersKey");
94
- var abortControllerKey = Symbol("abortControllerKey");
95
- var getAbortController = Symbol("getAbortController");
96
- var requestPrototype = {
97
- get method() {
98
- return this[incomingKey].method || "GET";
99
- },
100
- get url() {
101
- return this[urlKey];
102
- },
103
- get headers() {
104
- return this[headersKey] ||= newHeadersFromIncoming(this[incomingKey]);
105
- },
106
- [getAbortController]() {
107
- this[getRequestCache]();
108
- return this[abortControllerKey];
109
- },
110
- [getRequestCache]() {
111
- this[abortControllerKey] ||= new AbortController();
112
- return this[requestCache] ||= newRequestFromIncoming(
113
- this.method,
114
- this[urlKey],
115
- this.headers,
116
- this[incomingKey],
117
- this[abortControllerKey]
118
- );
119
- }
120
- };
121
- [
122
- "body",
123
- "bodyUsed",
124
- "cache",
125
- "credentials",
126
- "destination",
127
- "integrity",
128
- "mode",
129
- "redirect",
130
- "referrer",
131
- "referrerPolicy",
132
- "signal",
133
- "keepalive"
134
- ].forEach((k) => {
135
- Object.defineProperty(requestPrototype, k, {
136
- get() {
137
- return this[getRequestCache]()[k];
138
- }
139
- });
140
- });
141
- ["arrayBuffer", "blob", "clone", "formData", "json", "text"].forEach((k) => {
142
- Object.defineProperty(requestPrototype, k, {
143
- value: function() {
144
- return this[getRequestCache]()[k]();
145
- }
146
- });
147
- });
148
- Object.defineProperty(requestPrototype, Symbol.for("nodejs.util.inspect.custom"), {
149
- value: function(depth, options, inspectFn) {
150
- const props = {
151
- method: this.method,
152
- url: this.url,
153
- headers: this.headers,
154
- nativeRequest: this[requestCache]
155
- };
156
- return `Request (lightweight) ${inspectFn(props, { ...options, depth: depth == null ? null : depth - 1 })}`;
157
- }
158
- });
159
- Object.setPrototypeOf(requestPrototype, Request.prototype);
160
- var newRequest = (incoming, defaultHostname) => {
161
- const req = Object.create(requestPrototype);
162
- req[incomingKey] = incoming;
163
- const incomingUrl = incoming.url || "";
164
- if (incomingUrl[0] !== "/" && // short-circuit for performance. most requests are relative URL.
165
- (incomingUrl.startsWith("http://") || incomingUrl.startsWith("https://"))) {
166
- if (incoming instanceof Http2ServerRequest) {
167
- throw new RequestError("Absolute URL for :path is not allowed in HTTP/2");
168
- }
169
- try {
170
- const url2 = new URL(incomingUrl);
171
- req[urlKey] = url2.href;
172
- } catch (e) {
173
- throw new RequestError("Invalid absolute URL", { cause: e });
174
- }
175
- return req;
176
- }
177
- const host = (incoming instanceof Http2ServerRequest ? incoming.authority : incoming.headers.host) || defaultHostname;
178
- if (!host) {
179
- throw new RequestError("Missing host header");
180
- }
181
- let scheme;
182
- if (incoming instanceof Http2ServerRequest) {
183
- scheme = incoming.scheme;
184
- if (!(scheme === "http" || scheme === "https")) {
185
- throw new RequestError("Unsupported scheme");
186
- }
187
- } else {
188
- scheme = incoming.socket && incoming.socket.encrypted ? "https" : "http";
189
- }
190
- const url = new URL(`${scheme}://${host}${incomingUrl}`);
191
- if (url.hostname.length !== host.length && url.hostname !== host.replace(/:\d+$/, "")) {
192
- throw new RequestError("Invalid host header");
193
- }
194
- req[urlKey] = url.href;
195
- return req;
196
- };
197
- export {
198
- GlobalRequest,
199
- Request,
200
- RequestError,
201
- abortControllerKey,
202
- getAbortController,
203
- newRequest,
204
- toRequestError,
205
- wrapBodyStream
206
- };
@@ -1,26 +0,0 @@
1
- import { OutgoingHttpHeaders } from 'node:http';
2
-
3
- declare const getResponseCache: unique symbol;
4
- declare const cacheKey: unique symbol;
5
- type InternalCache = [
6
- number,
7
- string | ReadableStream,
8
- Record<string, string> | [string, string][] | Headers | OutgoingHttpHeaders | undefined
9
- ];
10
- declare const GlobalResponse: {
11
- new (body?: BodyInit | null, init?: ResponseInit): globalThis.Response;
12
- prototype: globalThis.Response;
13
- error(): globalThis.Response;
14
- json(data: any, init?: ResponseInit): globalThis.Response;
15
- redirect(url: string | URL, status?: number): globalThis.Response;
16
- };
17
- declare class Response {
18
- #private;
19
- [getResponseCache](): globalThis.Response;
20
- constructor(body?: BodyInit | null, init?: ResponseInit);
21
- get headers(): Headers;
22
- get status(): number;
23
- get ok(): boolean;
24
- }
25
-
26
- export { GlobalResponse, type InternalCache, Response, cacheKey };
@@ -1,26 +0,0 @@
1
- import { OutgoingHttpHeaders } from 'node:http';
2
-
3
- declare const getResponseCache: unique symbol;
4
- declare const cacheKey: unique symbol;
5
- type InternalCache = [
6
- number,
7
- string | ReadableStream,
8
- Record<string, string> | [string, string][] | Headers | OutgoingHttpHeaders | undefined
9
- ];
10
- declare const GlobalResponse: {
11
- new (body?: BodyInit | null, init?: ResponseInit): globalThis.Response;
12
- prototype: globalThis.Response;
13
- error(): globalThis.Response;
14
- json(data: any, init?: ResponseInit): globalThis.Response;
15
- redirect(url: string | URL, status?: number): globalThis.Response;
16
- };
17
- declare class Response {
18
- #private;
19
- [getResponseCache](): globalThis.Response;
20
- constructor(body?: BodyInit | null, init?: ResponseInit);
21
- get headers(): Headers;
22
- get status(): number;
23
- get ok(): boolean;
24
- }
25
-
26
- export { GlobalResponse, type InternalCache, Response, cacheKey };
package/dist/response.js DELETED
@@ -1,112 +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
-
20
- // src/response.ts
21
- var response_exports = {};
22
- __export(response_exports, {
23
- GlobalResponse: () => GlobalResponse,
24
- Response: () => Response,
25
- cacheKey: () => cacheKey
26
- });
27
- module.exports = __toCommonJS(response_exports);
28
- var responseCache = Symbol("responseCache");
29
- var getResponseCache = Symbol("getResponseCache");
30
- var cacheKey = Symbol("cache");
31
- var GlobalResponse = global.Response;
32
- var Response = class _Response {
33
- #body;
34
- #init;
35
- [getResponseCache]() {
36
- delete this[cacheKey];
37
- return this[responseCache] ||= new GlobalResponse(this.#body, this.#init);
38
- }
39
- constructor(body, init) {
40
- let headers;
41
- this.#body = body;
42
- if (init instanceof _Response) {
43
- const cachedGlobalResponse = init[responseCache];
44
- if (cachedGlobalResponse) {
45
- this.#init = cachedGlobalResponse;
46
- this[getResponseCache]();
47
- return;
48
- } else {
49
- this.#init = init.#init;
50
- headers = new Headers(init.#init.headers);
51
- }
52
- } else {
53
- this.#init = init;
54
- }
55
- if (typeof body === "string" || typeof body?.getReader !== "undefined" || body instanceof Blob || body instanceof Uint8Array) {
56
- ;
57
- this[cacheKey] = [init?.status || 200, body, headers || init?.headers];
58
- }
59
- }
60
- get headers() {
61
- const cache = this[cacheKey];
62
- if (cache) {
63
- if (!(cache[2] instanceof Headers)) {
64
- cache[2] = new Headers(
65
- cache[2] || { "content-type": "text/plain; charset=UTF-8" }
66
- );
67
- }
68
- return cache[2];
69
- }
70
- return this[getResponseCache]().headers;
71
- }
72
- get status() {
73
- return this[cacheKey]?.[0] ?? this[getResponseCache]().status;
74
- }
75
- get ok() {
76
- const status = this.status;
77
- return status >= 200 && status < 300;
78
- }
79
- };
80
- ["body", "bodyUsed", "redirected", "statusText", "trailers", "type", "url"].forEach((k) => {
81
- Object.defineProperty(Response.prototype, k, {
82
- get() {
83
- return this[getResponseCache]()[k];
84
- }
85
- });
86
- });
87
- ["arrayBuffer", "blob", "clone", "formData", "json", "text"].forEach((k) => {
88
- Object.defineProperty(Response.prototype, k, {
89
- value: function() {
90
- return this[getResponseCache]()[k]();
91
- }
92
- });
93
- });
94
- Object.defineProperty(Response.prototype, Symbol.for("nodejs.util.inspect.custom"), {
95
- value: function(depth, options, inspectFn) {
96
- const props = {
97
- status: this.status,
98
- headers: this.headers,
99
- ok: this.ok,
100
- nativeResponse: this[responseCache]
101
- };
102
- return `Response (lightweight) ${inspectFn(props, { ...options, depth: depth == null ? null : depth - 1 })}`;
103
- }
104
- });
105
- Object.setPrototypeOf(Response, GlobalResponse);
106
- Object.setPrototypeOf(Response.prototype, GlobalResponse.prototype);
107
- // Annotate the CommonJS export names for ESM import in node:
108
- 0 && (module.exports = {
109
- GlobalResponse,
110
- Response,
111
- cacheKey
112
- });
package/dist/response.mjs DELETED
@@ -1,85 +0,0 @@
1
- // src/response.ts
2
- var responseCache = Symbol("responseCache");
3
- var getResponseCache = Symbol("getResponseCache");
4
- var cacheKey = Symbol("cache");
5
- var GlobalResponse = global.Response;
6
- var Response = class _Response {
7
- #body;
8
- #init;
9
- [getResponseCache]() {
10
- delete this[cacheKey];
11
- return this[responseCache] ||= new GlobalResponse(this.#body, this.#init);
12
- }
13
- constructor(body, init) {
14
- let headers;
15
- this.#body = body;
16
- if (init instanceof _Response) {
17
- const cachedGlobalResponse = init[responseCache];
18
- if (cachedGlobalResponse) {
19
- this.#init = cachedGlobalResponse;
20
- this[getResponseCache]();
21
- return;
22
- } else {
23
- this.#init = init.#init;
24
- headers = new Headers(init.#init.headers);
25
- }
26
- } else {
27
- this.#init = init;
28
- }
29
- if (typeof body === "string" || typeof body?.getReader !== "undefined" || body instanceof Blob || body instanceof Uint8Array) {
30
- ;
31
- this[cacheKey] = [init?.status || 200, body, headers || init?.headers];
32
- }
33
- }
34
- get headers() {
35
- const cache = this[cacheKey];
36
- if (cache) {
37
- if (!(cache[2] instanceof Headers)) {
38
- cache[2] = new Headers(
39
- cache[2] || { "content-type": "text/plain; charset=UTF-8" }
40
- );
41
- }
42
- return cache[2];
43
- }
44
- return this[getResponseCache]().headers;
45
- }
46
- get status() {
47
- return this[cacheKey]?.[0] ?? this[getResponseCache]().status;
48
- }
49
- get ok() {
50
- const status = this.status;
51
- return status >= 200 && status < 300;
52
- }
53
- };
54
- ["body", "bodyUsed", "redirected", "statusText", "trailers", "type", "url"].forEach((k) => {
55
- Object.defineProperty(Response.prototype, k, {
56
- get() {
57
- return this[getResponseCache]()[k];
58
- }
59
- });
60
- });
61
- ["arrayBuffer", "blob", "clone", "formData", "json", "text"].forEach((k) => {
62
- Object.defineProperty(Response.prototype, k, {
63
- value: function() {
64
- return this[getResponseCache]()[k]();
65
- }
66
- });
67
- });
68
- Object.defineProperty(Response.prototype, Symbol.for("nodejs.util.inspect.custom"), {
69
- value: function(depth, options, inspectFn) {
70
- const props = {
71
- status: this.status,
72
- headers: this.headers,
73
- ok: this.ok,
74
- nativeResponse: this[responseCache]
75
- };
76
- return `Response (lightweight) ${inspectFn(props, { ...options, depth: depth == null ? null : depth - 1 })}`;
77
- }
78
- });
79
- Object.setPrototypeOf(Response, GlobalResponse);
80
- Object.setPrototypeOf(Response.prototype, GlobalResponse.prototype);
81
- export {
82
- GlobalResponse,
83
- Response,
84
- cacheKey
85
- };