@hono/node-server 1.19.10 → 2.0.0-rc.1

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 (58) hide show
  1. package/README.md +1 -7
  2. package/dist/conninfo.d.mts +4 -3
  3. package/dist/conninfo.d.ts +4 -3
  4. package/dist/conninfo.js +20 -40
  5. package/dist/conninfo.mjs +19 -16
  6. package/dist/constants-B7DBcQew.js +11 -0
  7. package/dist/constants-DEKKqoym.mjs +5 -0
  8. package/dist/index.d.mts +62 -8
  9. package/dist/index.d.ts +62 -8
  10. package/dist/index.js +28 -613
  11. package/dist/index.mjs +24 -573
  12. package/dist/listener-Brd4yZ5d.js +726 -0
  13. package/dist/listener-RIBxK9_x.mjs +715 -0
  14. package/dist/serve-static.d.mts +14 -13
  15. package/dist/serve-static.d.ts +14 -13
  16. package/dist/serve-static.js +128 -170
  17. package/dist/serve-static.mjs +127 -145
  18. package/dist/utils/response.d.mts +3 -2
  19. package/dist/utils/response.d.ts +3 -2
  20. package/dist/utils/response.js +6 -35
  21. package/dist/utils/response.mjs +6 -9
  22. package/dist/vercel.d.mts +6 -5
  23. package/dist/vercel.d.ts +6 -5
  24. package/dist/vercel.js +7 -585
  25. package/dist/vercel.mjs +6 -548
  26. package/package.json +11 -13
  27. package/dist/globals.d.mts +0 -2
  28. package/dist/globals.d.ts +0 -2
  29. package/dist/globals.js +0 -29
  30. package/dist/globals.mjs +0 -5
  31. package/dist/listener.d.mts +0 -13
  32. package/dist/listener.d.ts +0 -13
  33. package/dist/listener.js +0 -581
  34. package/dist/listener.mjs +0 -546
  35. package/dist/request.d.mts +0 -25
  36. package/dist/request.d.ts +0 -25
  37. package/dist/request.js +0 -227
  38. package/dist/request.mjs +0 -195
  39. package/dist/response.d.mts +0 -26
  40. package/dist/response.d.ts +0 -26
  41. package/dist/response.js +0 -99
  42. package/dist/response.mjs +0 -72
  43. package/dist/server.d.mts +0 -10
  44. package/dist/server.d.ts +0 -10
  45. package/dist/server.js +0 -607
  46. package/dist/server.mjs +0 -571
  47. package/dist/types.d.mts +0 -44
  48. package/dist/types.d.ts +0 -44
  49. package/dist/types.js +0 -18
  50. package/dist/types.mjs +0 -0
  51. package/dist/utils/response/constants.d.mts +0 -3
  52. package/dist/utils/response/constants.d.ts +0 -3
  53. package/dist/utils/response/constants.js +0 -30
  54. package/dist/utils/response/constants.mjs +0 -5
  55. package/dist/utils.d.mts +0 -9
  56. package/dist/utils.d.ts +0 -9
  57. package/dist/utils.js +0 -99
  58. package/dist/utils.mjs +0 -71
package/dist/request.js DELETED
@@ -1,227 +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.setPrototypeOf(requestPrototype, Request.prototype);
180
- var newRequest = (incoming, defaultHostname) => {
181
- const req = Object.create(requestPrototype);
182
- req[incomingKey] = incoming;
183
- const incomingUrl = incoming.url || "";
184
- if (incomingUrl[0] !== "/" && // short-circuit for performance. most requests are relative URL.
185
- (incomingUrl.startsWith("http://") || incomingUrl.startsWith("https://"))) {
186
- if (incoming instanceof import_node_http2.Http2ServerRequest) {
187
- throw new RequestError("Absolute URL for :path is not allowed in HTTP/2");
188
- }
189
- try {
190
- const url2 = new URL(incomingUrl);
191
- req[urlKey] = url2.href;
192
- } catch (e) {
193
- throw new RequestError("Invalid absolute URL", { cause: e });
194
- }
195
- return req;
196
- }
197
- const host = (incoming instanceof import_node_http2.Http2ServerRequest ? incoming.authority : incoming.headers.host) || defaultHostname;
198
- if (!host) {
199
- throw new RequestError("Missing host header");
200
- }
201
- let scheme;
202
- if (incoming instanceof import_node_http2.Http2ServerRequest) {
203
- scheme = incoming.scheme;
204
- if (!(scheme === "http" || scheme === "https")) {
205
- throw new RequestError("Unsupported scheme");
206
- }
207
- } else {
208
- scheme = incoming.socket && incoming.socket.encrypted ? "https" : "http";
209
- }
210
- const url = new URL(`${scheme}://${host}${incomingUrl}`);
211
- if (url.hostname.length !== host.length && url.hostname !== host.replace(/:\d+$/, "")) {
212
- throw new RequestError("Invalid host header");
213
- }
214
- req[urlKey] = url.href;
215
- return req;
216
- };
217
- // Annotate the CommonJS export names for ESM import in node:
218
- 0 && (module.exports = {
219
- GlobalRequest,
220
- Request,
221
- RequestError,
222
- abortControllerKey,
223
- getAbortController,
224
- newRequest,
225
- toRequestError,
226
- wrapBodyStream
227
- });
package/dist/request.mjs DELETED
@@ -1,195 +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.setPrototypeOf(requestPrototype, Request.prototype);
149
- var newRequest = (incoming, defaultHostname) => {
150
- const req = Object.create(requestPrototype);
151
- req[incomingKey] = incoming;
152
- const incomingUrl = incoming.url || "";
153
- if (incomingUrl[0] !== "/" && // short-circuit for performance. most requests are relative URL.
154
- (incomingUrl.startsWith("http://") || incomingUrl.startsWith("https://"))) {
155
- if (incoming instanceof Http2ServerRequest) {
156
- throw new RequestError("Absolute URL for :path is not allowed in HTTP/2");
157
- }
158
- try {
159
- const url2 = new URL(incomingUrl);
160
- req[urlKey] = url2.href;
161
- } catch (e) {
162
- throw new RequestError("Invalid absolute URL", { cause: e });
163
- }
164
- return req;
165
- }
166
- const host = (incoming instanceof Http2ServerRequest ? incoming.authority : incoming.headers.host) || defaultHostname;
167
- if (!host) {
168
- throw new RequestError("Missing host header");
169
- }
170
- let scheme;
171
- if (incoming instanceof Http2ServerRequest) {
172
- scheme = incoming.scheme;
173
- if (!(scheme === "http" || scheme === "https")) {
174
- throw new RequestError("Unsupported scheme");
175
- }
176
- } else {
177
- scheme = incoming.socket && incoming.socket.encrypted ? "https" : "http";
178
- }
179
- const url = new URL(`${scheme}://${host}${incomingUrl}`);
180
- if (url.hostname.length !== host.length && url.hostname !== host.replace(/:\d+$/, "")) {
181
- throw new RequestError("Invalid host header");
182
- }
183
- req[urlKey] = url.href;
184
- return req;
185
- };
186
- export {
187
- GlobalRequest,
188
- Request,
189
- RequestError,
190
- abortControllerKey,
191
- getAbortController,
192
- newRequest,
193
- toRequestError,
194
- wrapBodyStream
195
- };
@@ -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> | Headers | OutgoingHttpHeaders
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> | Headers | OutgoingHttpHeaders
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,99 +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
- headers ||= init?.headers || { "content-type": "text/plain; charset=UTF-8" };
57
- this[cacheKey] = [init?.status || 200, body, 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(cache[2]);
65
- }
66
- return cache[2];
67
- }
68
- return this[getResponseCache]().headers;
69
- }
70
- get status() {
71
- return this[cacheKey]?.[0] ?? this[getResponseCache]().status;
72
- }
73
- get ok() {
74
- const status = this.status;
75
- return status >= 200 && status < 300;
76
- }
77
- };
78
- ["body", "bodyUsed", "redirected", "statusText", "trailers", "type", "url"].forEach((k) => {
79
- Object.defineProperty(Response.prototype, k, {
80
- get() {
81
- return this[getResponseCache]()[k];
82
- }
83
- });
84
- });
85
- ["arrayBuffer", "blob", "clone", "formData", "json", "text"].forEach((k) => {
86
- Object.defineProperty(Response.prototype, k, {
87
- value: function() {
88
- return this[getResponseCache]()[k]();
89
- }
90
- });
91
- });
92
- Object.setPrototypeOf(Response, GlobalResponse);
93
- Object.setPrototypeOf(Response.prototype, GlobalResponse.prototype);
94
- // Annotate the CommonJS export names for ESM import in node:
95
- 0 && (module.exports = {
96
- GlobalResponse,
97
- Response,
98
- cacheKey
99
- });
package/dist/response.mjs DELETED
@@ -1,72 +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
- headers ||= init?.headers || { "content-type": "text/plain; charset=UTF-8" };
31
- this[cacheKey] = [init?.status || 200, body, 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(cache[2]);
39
- }
40
- return cache[2];
41
- }
42
- return this[getResponseCache]().headers;
43
- }
44
- get status() {
45
- return this[cacheKey]?.[0] ?? this[getResponseCache]().status;
46
- }
47
- get ok() {
48
- const status = this.status;
49
- return status >= 200 && status < 300;
50
- }
51
- };
52
- ["body", "bodyUsed", "redirected", "statusText", "trailers", "type", "url"].forEach((k) => {
53
- Object.defineProperty(Response.prototype, k, {
54
- get() {
55
- return this[getResponseCache]()[k];
56
- }
57
- });
58
- });
59
- ["arrayBuffer", "blob", "clone", "formData", "json", "text"].forEach((k) => {
60
- Object.defineProperty(Response.prototype, k, {
61
- value: function() {
62
- return this[getResponseCache]()[k]();
63
- }
64
- });
65
- });
66
- Object.setPrototypeOf(Response, GlobalResponse);
67
- Object.setPrototypeOf(Response.prototype, GlobalResponse.prototype);
68
- export {
69
- GlobalResponse,
70
- Response,
71
- cacheKey
72
- };
package/dist/server.d.mts DELETED
@@ -1,10 +0,0 @@
1
- import { AddressInfo } from 'node:net';
2
- import { Options, ServerType } from './types.mjs';
3
- import 'node:http';
4
- import 'node:http2';
5
- import 'node:https';
6
-
7
- declare const createAdaptorServer: (options: Options) => ServerType;
8
- declare const serve: (options: Options, listeningListener?: (info: AddressInfo) => void) => ServerType;
9
-
10
- export { createAdaptorServer, serve };
package/dist/server.d.ts DELETED
@@ -1,10 +0,0 @@
1
- import { AddressInfo } from 'node:net';
2
- import { Options, ServerType } from './types.js';
3
- import 'node:http';
4
- import 'node:http2';
5
- import 'node:https';
6
-
7
- declare const createAdaptorServer: (options: Options) => ServerType;
8
- declare const serve: (options: Options, listeningListener?: (info: AddressInfo) => void) => ServerType;
9
-
10
- export { createAdaptorServer, serve };