hono 4.8.12 → 4.9.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/adapter/aws-lambda/handler.js +6 -5
- package/dist/adapter/aws-lambda/index.js +2 -1
- package/dist/adapter/bun/index.js +4 -2
- package/dist/adapter/bun/serve-static.js +2 -5
- package/dist/adapter/bun/websocket.js +47 -50
- package/dist/adapter/deno/serve-static.js +2 -4
- package/dist/cjs/adapter/aws-lambda/handler.js +7 -6
- package/dist/cjs/adapter/aws-lambda/index.js +2 -0
- package/dist/cjs/adapter/bun/index.js +6 -2
- package/dist/cjs/adapter/bun/serve-static.js +2 -5
- package/dist/cjs/adapter/bun/websocket.js +50 -51
- package/dist/cjs/adapter/deno/serve-static.js +2 -4
- package/dist/cjs/client/fetch-result-please.js +73 -0
- package/dist/cjs/client/index.js +7 -2
- package/dist/cjs/client/utils.js +8 -0
- package/dist/cjs/helper/cookie/index.js +14 -2
- package/dist/cjs/middleware/jwk/jwk.js +4 -2
- package/dist/cjs/middleware/jwt/index.js +4 -2
- package/dist/cjs/middleware/jwt/jwt.js +10 -3
- package/dist/cjs/middleware/serve-static/index.js +22 -60
- package/dist/cjs/middleware/serve-static/path.js +41 -0
- package/dist/cjs/utils/jwt/index.js +1 -1
- package/dist/cjs/utils/jwt/jwt.js +33 -10
- package/dist/cjs/utils/jwt/types.js +8 -0
- package/dist/client/fetch-result-please.js +49 -0
- package/dist/client/index.js +4 -1
- package/dist/client/utils.js +6 -0
- package/dist/helper/cookie/index.js +12 -2
- package/dist/middleware/jwk/jwk.js +4 -2
- package/dist/middleware/jwt/index.js +3 -2
- package/dist/middleware/jwt/jwt.js +8 -2
- package/dist/middleware/serve-static/index.js +22 -60
- package/dist/middleware/serve-static/path.js +18 -0
- package/dist/types/adapter/aws-lambda/handler.d.ts +50 -4
- package/dist/types/adapter/aws-lambda/index.d.ts +1 -1
- package/dist/types/adapter/bun/index.d.ts +1 -1
- package/dist/types/adapter/bun/websocket.d.ts +6 -0
- package/dist/types/client/fetch-result-please.d.ts +35 -0
- package/dist/types/client/index.d.ts +1 -0
- package/dist/types/client/utils.d.ts +11 -0
- package/dist/types/helper/adapter/index.d.ts +1 -1
- package/dist/types/helper/cookie/index.d.ts +2 -0
- package/dist/types/helper/ssg/ssg.d.ts +9 -0
- package/dist/types/middleware/jwk/jwk.d.ts +9 -1
- package/dist/types/middleware/jwt/index.d.ts +1 -1
- package/dist/types/middleware/jwt/jwt.d.ts +9 -1
- package/dist/types/middleware/serve-static/index.d.ts +8 -0
- package/dist/types/middleware/serve-static/path.d.ts +5 -0
- package/dist/types/request.d.ts +0 -5
- package/dist/types/utils/jwt/index.d.ts +3 -2
- package/dist/types/utils/jwt/jwt.d.ts +17 -2
- package/dist/types/utils/jwt/types.d.ts +7 -0
- package/dist/utils/jwt/index.js +2 -2
- package/dist/utils/jwt/jwt.js +33 -9
- package/dist/utils/jwt/types.js +7 -0
- package/package.json +3 -3
|
@@ -52,7 +52,7 @@ var streamHandle = (app) => {
|
|
|
52
52
|
}
|
|
53
53
|
);
|
|
54
54
|
};
|
|
55
|
-
var handle = (app) => {
|
|
55
|
+
var handle = (app, { isContentTypeBinary } = { isContentTypeBinary: void 0 }) => {
|
|
56
56
|
return async (event, lambdaContext) => {
|
|
57
57
|
const processor = getProcessor(event);
|
|
58
58
|
const req = processor.createRequest(event);
|
|
@@ -62,7 +62,7 @@ var handle = (app) => {
|
|
|
62
62
|
requestContext,
|
|
63
63
|
lambdaContext
|
|
64
64
|
});
|
|
65
|
-
return processor.createResult(event, res);
|
|
65
|
+
return processor.createResult(event, res, { isContentTypeBinary });
|
|
66
66
|
};
|
|
67
67
|
};
|
|
68
68
|
var EventProcessor = class {
|
|
@@ -83,8 +83,9 @@ var EventProcessor = class {
|
|
|
83
83
|
}
|
|
84
84
|
return new Request(url, requestInit);
|
|
85
85
|
}
|
|
86
|
-
async createResult(event, res) {
|
|
86
|
+
async createResult(event, res, options) {
|
|
87
87
|
const contentType = res.headers.get("content-type");
|
|
88
|
+
const isContentTypeBinary = options.isContentTypeBinary ?? defaultIsContentTypeBinary;
|
|
88
89
|
let isBase64Encoded = contentType && isContentTypeBinary(contentType) ? true : false;
|
|
89
90
|
if (!isBase64Encoded) {
|
|
90
91
|
const contentEncoding = res.headers.get("content-encoding");
|
|
@@ -267,7 +268,7 @@ var isProxyEventALB = (event) => {
|
|
|
267
268
|
var isProxyEventV2 = (event) => {
|
|
268
269
|
return Object.hasOwn(event, "rawPath");
|
|
269
270
|
};
|
|
270
|
-
var
|
|
271
|
+
var defaultIsContentTypeBinary = (contentType) => {
|
|
271
272
|
return !/^(text\/(plain|html|css|javascript|csv).*|application\/(.*json|.*xml).*|image\/svg\+xml.*)$/.test(
|
|
272
273
|
contentType
|
|
273
274
|
);
|
|
@@ -283,9 +284,9 @@ export {
|
|
|
283
284
|
EventProcessor,
|
|
284
285
|
EventV1Processor,
|
|
285
286
|
EventV2Processor,
|
|
287
|
+
defaultIsContentTypeBinary,
|
|
286
288
|
getProcessor,
|
|
287
289
|
handle,
|
|
288
290
|
isContentEncodingBinary,
|
|
289
|
-
isContentTypeBinary,
|
|
290
291
|
streamHandle
|
|
291
292
|
};
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
// src/adapter/bun/index.ts
|
|
2
2
|
import { serveStatic } from "./serve-static.js";
|
|
3
3
|
import { bunFileSystemModule, toSSG } from "./ssg.js";
|
|
4
|
-
import { createBunWebSocket } from "./websocket.js";
|
|
4
|
+
import { createBunWebSocket, upgradeWebSocket, websocket } from "./websocket.js";
|
|
5
5
|
import { getConnInfo } from "./conninfo.js";
|
|
6
6
|
export {
|
|
7
7
|
bunFileSystemModule,
|
|
8
8
|
createBunWebSocket,
|
|
9
9
|
getConnInfo,
|
|
10
10
|
serveStatic,
|
|
11
|
-
toSSG
|
|
11
|
+
toSSG,
|
|
12
|
+
upgradeWebSocket,
|
|
13
|
+
websocket
|
|
12
14
|
};
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
// src/adapter/bun/serve-static.ts
|
|
2
2
|
import { stat } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
3
4
|
import { serveStatic as baseServeStatic } from "../../middleware/serve-static/index.js";
|
|
4
5
|
var serveStatic = (options) => {
|
|
5
6
|
return async function serveStatic2(c, next) {
|
|
6
7
|
const getContent = async (path) => {
|
|
7
|
-
path = path.startsWith("/") ? path : `./${path}`;
|
|
8
8
|
const file = Bun.file(path);
|
|
9
9
|
return await file.exists() ? file : null;
|
|
10
10
|
};
|
|
11
|
-
const pathResolve = (path) => {
|
|
12
|
-
return path.startsWith("/") ? path : `./${path}`;
|
|
13
|
-
};
|
|
14
11
|
const isDir = async (path) => {
|
|
15
12
|
let isDir2;
|
|
16
13
|
try {
|
|
@@ -23,7 +20,7 @@ var serveStatic = (options) => {
|
|
|
23
20
|
return baseServeStatic({
|
|
24
21
|
...options,
|
|
25
22
|
getContent,
|
|
26
|
-
|
|
23
|
+
join,
|
|
27
24
|
isDir
|
|
28
25
|
})(c, next);
|
|
29
26
|
};
|
|
@@ -15,60 +15,57 @@ var createWSContext = (ws) => {
|
|
|
15
15
|
}
|
|
16
16
|
});
|
|
17
17
|
};
|
|
18
|
-
var
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
var upgradeWebSocket = defineWebSocketHelper((c, events) => {
|
|
19
|
+
const server = getBunServer(c);
|
|
20
|
+
if (!server) {
|
|
21
|
+
throw new TypeError("env has to include the 2nd argument of fetch.");
|
|
22
|
+
}
|
|
23
|
+
const upgradeResult = server.upgrade(c.req.raw, {
|
|
24
|
+
data: {
|
|
25
|
+
events,
|
|
26
|
+
url: new URL(c.req.url),
|
|
27
|
+
protocol: c.req.url
|
|
23
28
|
}
|
|
24
|
-
const upgradeResult = server.upgrade(c.req.raw, {
|
|
25
|
-
data: {
|
|
26
|
-
events,
|
|
27
|
-
url: new URL(c.req.url),
|
|
28
|
-
protocol: c.req.url
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
if (upgradeResult) {
|
|
32
|
-
return new Response(null);
|
|
33
|
-
}
|
|
34
|
-
return;
|
|
35
29
|
});
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
30
|
+
if (upgradeResult) {
|
|
31
|
+
return new Response(null);
|
|
32
|
+
}
|
|
33
|
+
return;
|
|
34
|
+
});
|
|
35
|
+
var websocket = {
|
|
36
|
+
open(ws) {
|
|
37
|
+
const websocketListeners = ws.data.events;
|
|
38
|
+
if (websocketListeners.onOpen) {
|
|
39
|
+
websocketListeners.onOpen(new Event("open"), createWSContext(ws));
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
close(ws, code, reason) {
|
|
43
|
+
const websocketListeners = ws.data.events;
|
|
44
|
+
if (websocketListeners.onClose) {
|
|
45
|
+
websocketListeners.onClose(
|
|
46
|
+
new CloseEvent("close", {
|
|
47
|
+
code,
|
|
48
|
+
reason
|
|
49
|
+
}),
|
|
50
|
+
createWSContext(ws)
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
message(ws, message) {
|
|
55
|
+
const websocketListeners = ws.data.events;
|
|
56
|
+
if (websocketListeners.onMessage) {
|
|
57
|
+
const normalizedReceiveData = typeof message === "string" ? message : message.buffer;
|
|
58
|
+
websocketListeners.onMessage(createWSMessageEvent(normalizedReceiveData), createWSContext(ws));
|
|
64
59
|
}
|
|
65
|
-
}
|
|
66
|
-
return {
|
|
67
|
-
upgradeWebSocket,
|
|
68
|
-
websocket
|
|
69
|
-
};
|
|
60
|
+
}
|
|
70
61
|
};
|
|
62
|
+
var createBunWebSocket = () => ({
|
|
63
|
+
upgradeWebSocket,
|
|
64
|
+
websocket
|
|
65
|
+
});
|
|
71
66
|
export {
|
|
72
67
|
createBunWebSocket,
|
|
73
|
-
createWSContext
|
|
68
|
+
createWSContext,
|
|
69
|
+
upgradeWebSocket,
|
|
70
|
+
websocket
|
|
74
71
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// src/adapter/deno/serve-static.ts
|
|
2
|
+
import { join } from "node:path";
|
|
2
3
|
import { serveStatic as baseServeStatic } from "../../middleware/serve-static/index.js";
|
|
3
4
|
var { open, lstatSync, errors } = Deno;
|
|
4
5
|
var serveStatic = (options) => {
|
|
@@ -17,9 +18,6 @@ var serveStatic = (options) => {
|
|
|
17
18
|
return null;
|
|
18
19
|
}
|
|
19
20
|
};
|
|
20
|
-
const pathResolve = (path) => {
|
|
21
|
-
return path.startsWith("/") ? path : `./${path}`;
|
|
22
|
-
};
|
|
23
21
|
const isDir = (path) => {
|
|
24
22
|
let isDir2;
|
|
25
23
|
try {
|
|
@@ -32,7 +30,7 @@ var serveStatic = (options) => {
|
|
|
32
30
|
return baseServeStatic({
|
|
33
31
|
...options,
|
|
34
32
|
getContent,
|
|
35
|
-
|
|
33
|
+
join,
|
|
36
34
|
isDir
|
|
37
35
|
})(c, next);
|
|
38
36
|
};
|
|
@@ -22,10 +22,10 @@ __export(handler_exports, {
|
|
|
22
22
|
EventProcessor: () => EventProcessor,
|
|
23
23
|
EventV1Processor: () => EventV1Processor,
|
|
24
24
|
EventV2Processor: () => EventV2Processor,
|
|
25
|
+
defaultIsContentTypeBinary: () => defaultIsContentTypeBinary,
|
|
25
26
|
getProcessor: () => getProcessor,
|
|
26
27
|
handle: () => handle,
|
|
27
28
|
isContentEncodingBinary: () => isContentEncodingBinary,
|
|
28
|
-
isContentTypeBinary: () => isContentTypeBinary,
|
|
29
29
|
streamHandle: () => streamHandle
|
|
30
30
|
});
|
|
31
31
|
module.exports = __toCommonJS(handler_exports);
|
|
@@ -82,7 +82,7 @@ const streamHandle = (app) => {
|
|
|
82
82
|
}
|
|
83
83
|
);
|
|
84
84
|
};
|
|
85
|
-
const handle = (app) => {
|
|
85
|
+
const handle = (app, { isContentTypeBinary } = { isContentTypeBinary: void 0 }) => {
|
|
86
86
|
return async (event, lambdaContext) => {
|
|
87
87
|
const processor = getProcessor(event);
|
|
88
88
|
const req = processor.createRequest(event);
|
|
@@ -92,7 +92,7 @@ const handle = (app) => {
|
|
|
92
92
|
requestContext,
|
|
93
93
|
lambdaContext
|
|
94
94
|
});
|
|
95
|
-
return processor.createResult(event, res);
|
|
95
|
+
return processor.createResult(event, res, { isContentTypeBinary });
|
|
96
96
|
};
|
|
97
97
|
};
|
|
98
98
|
class EventProcessor {
|
|
@@ -113,8 +113,9 @@ class EventProcessor {
|
|
|
113
113
|
}
|
|
114
114
|
return new Request(url, requestInit);
|
|
115
115
|
}
|
|
116
|
-
async createResult(event, res) {
|
|
116
|
+
async createResult(event, res, options) {
|
|
117
117
|
const contentType = res.headers.get("content-type");
|
|
118
|
+
const isContentTypeBinary = options.isContentTypeBinary ?? defaultIsContentTypeBinary;
|
|
118
119
|
let isBase64Encoded = contentType && isContentTypeBinary(contentType) ? true : false;
|
|
119
120
|
if (!isBase64Encoded) {
|
|
120
121
|
const contentEncoding = res.headers.get("content-encoding");
|
|
@@ -297,7 +298,7 @@ const isProxyEventALB = (event) => {
|
|
|
297
298
|
const isProxyEventV2 = (event) => {
|
|
298
299
|
return Object.hasOwn(event, "rawPath");
|
|
299
300
|
};
|
|
300
|
-
const
|
|
301
|
+
const defaultIsContentTypeBinary = (contentType) => {
|
|
301
302
|
return !/^(text\/(plain|html|css|javascript|csv).*|application\/(.*json|.*xml).*|image\/svg\+xml.*)$/.test(
|
|
302
303
|
contentType
|
|
303
304
|
);
|
|
@@ -314,9 +315,9 @@ const isContentEncodingBinary = (contentEncoding) => {
|
|
|
314
315
|
EventProcessor,
|
|
315
316
|
EventV1Processor,
|
|
316
317
|
EventV2Processor,
|
|
318
|
+
defaultIsContentTypeBinary,
|
|
317
319
|
getProcessor,
|
|
318
320
|
handle,
|
|
319
321
|
isContentEncodingBinary,
|
|
320
|
-
isContentTypeBinary,
|
|
321
322
|
streamHandle
|
|
322
323
|
});
|
|
@@ -18,6 +18,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var aws_lambda_exports = {};
|
|
20
20
|
__export(aws_lambda_exports, {
|
|
21
|
+
defaultIsContentTypeBinary: () => import_handler.defaultIsContentTypeBinary,
|
|
21
22
|
handle: () => import_handler.handle,
|
|
22
23
|
streamHandle: () => import_handler.streamHandle
|
|
23
24
|
});
|
|
@@ -25,6 +26,7 @@ module.exports = __toCommonJS(aws_lambda_exports);
|
|
|
25
26
|
var import_handler = require("./handler");
|
|
26
27
|
// Annotate the CommonJS export names for ESM import in node:
|
|
27
28
|
0 && (module.exports = {
|
|
29
|
+
defaultIsContentTypeBinary,
|
|
28
30
|
handle,
|
|
29
31
|
streamHandle
|
|
30
32
|
});
|
|
@@ -22,7 +22,9 @@ __export(bun_exports, {
|
|
|
22
22
|
createBunWebSocket: () => import_websocket.createBunWebSocket,
|
|
23
23
|
getConnInfo: () => import_conninfo.getConnInfo,
|
|
24
24
|
serveStatic: () => import_serve_static.serveStatic,
|
|
25
|
-
toSSG: () => import_ssg.toSSG
|
|
25
|
+
toSSG: () => import_ssg.toSSG,
|
|
26
|
+
upgradeWebSocket: () => import_websocket.upgradeWebSocket,
|
|
27
|
+
websocket: () => import_websocket.websocket
|
|
26
28
|
});
|
|
27
29
|
module.exports = __toCommonJS(bun_exports);
|
|
28
30
|
var import_serve_static = require("./serve-static");
|
|
@@ -35,5 +37,7 @@ var import_conninfo = require("./conninfo");
|
|
|
35
37
|
createBunWebSocket,
|
|
36
38
|
getConnInfo,
|
|
37
39
|
serveStatic,
|
|
38
|
-
toSSG
|
|
40
|
+
toSSG,
|
|
41
|
+
upgradeWebSocket,
|
|
42
|
+
websocket
|
|
39
43
|
});
|
|
@@ -22,17 +22,14 @@ __export(serve_static_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(serve_static_exports);
|
|
24
24
|
var import_promises = require("node:fs/promises");
|
|
25
|
+
var import_node_path = require("node:path");
|
|
25
26
|
var import_serve_static = require("../../middleware/serve-static");
|
|
26
27
|
const serveStatic = (options) => {
|
|
27
28
|
return async function serveStatic2(c, next) {
|
|
28
29
|
const getContent = async (path) => {
|
|
29
|
-
path = path.startsWith("/") ? path : `./${path}`;
|
|
30
30
|
const file = Bun.file(path);
|
|
31
31
|
return await file.exists() ? file : null;
|
|
32
32
|
};
|
|
33
|
-
const pathResolve = (path) => {
|
|
34
|
-
return path.startsWith("/") ? path : `./${path}`;
|
|
35
|
-
};
|
|
36
33
|
const isDir = async (path) => {
|
|
37
34
|
let isDir2;
|
|
38
35
|
try {
|
|
@@ -45,7 +42,7 @@ const serveStatic = (options) => {
|
|
|
45
42
|
return (0, import_serve_static.serveStatic)({
|
|
46
43
|
...options,
|
|
47
44
|
getContent,
|
|
48
|
-
|
|
45
|
+
join: import_node_path.join,
|
|
49
46
|
isDir
|
|
50
47
|
})(c, next);
|
|
51
48
|
};
|
|
@@ -19,7 +19,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
var websocket_exports = {};
|
|
20
20
|
__export(websocket_exports, {
|
|
21
21
|
createBunWebSocket: () => createBunWebSocket,
|
|
22
|
-
createWSContext: () => createWSContext
|
|
22
|
+
createWSContext: () => createWSContext,
|
|
23
|
+
upgradeWebSocket: () => upgradeWebSocket,
|
|
24
|
+
websocket: () => websocket
|
|
23
25
|
});
|
|
24
26
|
module.exports = __toCommonJS(websocket_exports);
|
|
25
27
|
var import_websocket = require("../../helper/websocket");
|
|
@@ -38,61 +40,58 @@ const createWSContext = (ws) => {
|
|
|
38
40
|
}
|
|
39
41
|
});
|
|
40
42
|
};
|
|
41
|
-
const
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
protocol: c.req.url
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
if (upgradeResult) {
|
|
55
|
-
return new Response(null);
|
|
43
|
+
const upgradeWebSocket = (0, import_websocket.defineWebSocketHelper)((c, events) => {
|
|
44
|
+
const server = (0, import_server.getBunServer)(c);
|
|
45
|
+
if (!server) {
|
|
46
|
+
throw new TypeError("env has to include the 2nd argument of fetch.");
|
|
47
|
+
}
|
|
48
|
+
const upgradeResult = server.upgrade(c.req.raw, {
|
|
49
|
+
data: {
|
|
50
|
+
events,
|
|
51
|
+
url: new URL(c.req.url),
|
|
52
|
+
protocol: c.req.url
|
|
56
53
|
}
|
|
57
|
-
return;
|
|
58
54
|
});
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
55
|
+
if (upgradeResult) {
|
|
56
|
+
return new Response(null);
|
|
57
|
+
}
|
|
58
|
+
return;
|
|
59
|
+
});
|
|
60
|
+
const websocket = {
|
|
61
|
+
open(ws) {
|
|
62
|
+
const websocketListeners = ws.data.events;
|
|
63
|
+
if (websocketListeners.onOpen) {
|
|
64
|
+
websocketListeners.onOpen(new Event("open"), createWSContext(ws));
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
close(ws, code, reason) {
|
|
68
|
+
const websocketListeners = ws.data.events;
|
|
69
|
+
if (websocketListeners.onClose) {
|
|
70
|
+
websocketListeners.onClose(
|
|
71
|
+
new CloseEvent("close", {
|
|
72
|
+
code,
|
|
73
|
+
reason
|
|
74
|
+
}),
|
|
75
|
+
createWSContext(ws)
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
message(ws, message) {
|
|
80
|
+
const websocketListeners = ws.data.events;
|
|
81
|
+
if (websocketListeners.onMessage) {
|
|
82
|
+
const normalizedReceiveData = typeof message === "string" ? message : message.buffer;
|
|
83
|
+
websocketListeners.onMessage((0, import_websocket.createWSMessageEvent)(normalizedReceiveData), createWSContext(ws));
|
|
87
84
|
}
|
|
88
|
-
}
|
|
89
|
-
return {
|
|
90
|
-
upgradeWebSocket,
|
|
91
|
-
websocket
|
|
92
|
-
};
|
|
85
|
+
}
|
|
93
86
|
};
|
|
87
|
+
const createBunWebSocket = () => ({
|
|
88
|
+
upgradeWebSocket,
|
|
89
|
+
websocket
|
|
90
|
+
});
|
|
94
91
|
// Annotate the CommonJS export names for ESM import in node:
|
|
95
92
|
0 && (module.exports = {
|
|
96
93
|
createBunWebSocket,
|
|
97
|
-
createWSContext
|
|
94
|
+
createWSContext,
|
|
95
|
+
upgradeWebSocket,
|
|
96
|
+
websocket
|
|
98
97
|
});
|
|
@@ -21,6 +21,7 @@ __export(serve_static_exports, {
|
|
|
21
21
|
serveStatic: () => serveStatic
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(serve_static_exports);
|
|
24
|
+
var import_node_path = require("node:path");
|
|
24
25
|
var import_serve_static = require("../../middleware/serve-static");
|
|
25
26
|
const { open, lstatSync, errors } = Deno;
|
|
26
27
|
const serveStatic = (options) => {
|
|
@@ -39,9 +40,6 @@ const serveStatic = (options) => {
|
|
|
39
40
|
return null;
|
|
40
41
|
}
|
|
41
42
|
};
|
|
42
|
-
const pathResolve = (path) => {
|
|
43
|
-
return path.startsWith("/") ? path : `./${path}`;
|
|
44
|
-
};
|
|
45
43
|
const isDir = (path) => {
|
|
46
44
|
let isDir2;
|
|
47
45
|
try {
|
|
@@ -54,7 +52,7 @@ const serveStatic = (options) => {
|
|
|
54
52
|
return (0, import_serve_static.serveStatic)({
|
|
55
53
|
...options,
|
|
56
54
|
getContent,
|
|
57
|
-
|
|
55
|
+
join: import_node_path.join,
|
|
58
56
|
isDir
|
|
59
57
|
})(c, next);
|
|
60
58
|
};
|
|
@@ -0,0 +1,73 @@
|
|
|
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 fetch_result_please_exports = {};
|
|
20
|
+
__export(fetch_result_please_exports, {
|
|
21
|
+
DetailedError: () => DetailedError,
|
|
22
|
+
fetchRP: () => fetchRP
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(fetch_result_please_exports);
|
|
25
|
+
const nullBodyResponses = /* @__PURE__ */ new Set([101, 204, 205, 304]);
|
|
26
|
+
async function fetchRP(fetchRes) {
|
|
27
|
+
const _fetchRes = await fetchRes;
|
|
28
|
+
const hasBody = _fetchRes.body && !nullBodyResponses.has(_fetchRes.status);
|
|
29
|
+
if (hasBody) {
|
|
30
|
+
const responseType = detectResponseType(_fetchRes);
|
|
31
|
+
_fetchRes._data = await _fetchRes[responseType]();
|
|
32
|
+
}
|
|
33
|
+
if (!_fetchRes.ok) {
|
|
34
|
+
throw new DetailedError(`${_fetchRes.status} ${_fetchRes.statusText}`, {
|
|
35
|
+
statusCode: _fetchRes?.status,
|
|
36
|
+
detail: {
|
|
37
|
+
data: _fetchRes?._data,
|
|
38
|
+
statusText: _fetchRes?.statusText
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
return _fetchRes._data;
|
|
43
|
+
}
|
|
44
|
+
class DetailedError extends Error {
|
|
45
|
+
detail;
|
|
46
|
+
code;
|
|
47
|
+
log;
|
|
48
|
+
statusCode;
|
|
49
|
+
constructor(message, options = {}) {
|
|
50
|
+
super(message);
|
|
51
|
+
this.log = options.log;
|
|
52
|
+
this.detail = options.detail;
|
|
53
|
+
this.code = options.code;
|
|
54
|
+
this.statusCode = options.statusCode;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const jsonRegex = /^application\/(?:[\w!#$%&*.^`~-]*\+)?json(?:;.+)?$/i;
|
|
58
|
+
function detectResponseType(response) {
|
|
59
|
+
const _contentType = response.headers.get("content-type");
|
|
60
|
+
if (!_contentType) {
|
|
61
|
+
return "text";
|
|
62
|
+
}
|
|
63
|
+
const contentType = _contentType.split(";").shift();
|
|
64
|
+
if (jsonRegex.test(contentType)) {
|
|
65
|
+
return "json";
|
|
66
|
+
}
|
|
67
|
+
return "text";
|
|
68
|
+
}
|
|
69
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
70
|
+
0 && (module.exports = {
|
|
71
|
+
DetailedError,
|
|
72
|
+
fetchRP
|
|
73
|
+
});
|
package/dist/cjs/client/index.js
CHANGED
|
@@ -18,11 +18,16 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var client_exports = {};
|
|
20
20
|
__export(client_exports, {
|
|
21
|
-
|
|
21
|
+
DetailedError: () => import_utils.DetailedError,
|
|
22
|
+
hc: () => import_client.hc,
|
|
23
|
+
parseResponse: () => import_utils.parseResponse
|
|
22
24
|
});
|
|
23
25
|
module.exports = __toCommonJS(client_exports);
|
|
24
26
|
var import_client = require("./client");
|
|
27
|
+
var import_utils = require("./utils");
|
|
25
28
|
// Annotate the CommonJS export names for ESM import in node:
|
|
26
29
|
0 && (module.exports = {
|
|
27
|
-
|
|
30
|
+
DetailedError,
|
|
31
|
+
hc,
|
|
32
|
+
parseResponse
|
|
28
33
|
});
|
package/dist/cjs/client/utils.js
CHANGED
|
@@ -18,14 +18,17 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var utils_exports = {};
|
|
20
20
|
__export(utils_exports, {
|
|
21
|
+
DetailedError: () => import_fetch_result_please.DetailedError,
|
|
21
22
|
buildSearchParams: () => buildSearchParams,
|
|
22
23
|
deepMerge: () => deepMerge,
|
|
23
24
|
mergePath: () => mergePath,
|
|
25
|
+
parseResponse: () => parseResponse,
|
|
24
26
|
removeIndexString: () => removeIndexString,
|
|
25
27
|
replaceUrlParam: () => replaceUrlParam,
|
|
26
28
|
replaceUrlProtocol: () => replaceUrlProtocol
|
|
27
29
|
});
|
|
28
30
|
module.exports = __toCommonJS(utils_exports);
|
|
31
|
+
var import_fetch_result_please = require("./fetch-result-please");
|
|
29
32
|
const mergePath = (base, path) => {
|
|
30
33
|
base = base.replace(/\/+$/, "");
|
|
31
34
|
base = base + "/";
|
|
@@ -87,11 +90,16 @@ function deepMerge(target, source) {
|
|
|
87
90
|
}
|
|
88
91
|
return merged;
|
|
89
92
|
}
|
|
93
|
+
async function parseResponse(fetchRes) {
|
|
94
|
+
return (0, import_fetch_result_please.fetchRP)(fetchRes);
|
|
95
|
+
}
|
|
90
96
|
// Annotate the CommonJS export names for ESM import in node:
|
|
91
97
|
0 && (module.exports = {
|
|
98
|
+
DetailedError,
|
|
92
99
|
buildSearchParams,
|
|
93
100
|
deepMerge,
|
|
94
101
|
mergePath,
|
|
102
|
+
parseResponse,
|
|
95
103
|
removeIndexString,
|
|
96
104
|
replaceUrlParam,
|
|
97
105
|
replaceUrlProtocol
|