hono 4.0.10 → 4.1.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 +1 -1
- package/dist/adapter/bun/index.js +2 -0
- package/dist/adapter/bun/websocket.js +77 -0
- package/dist/adapter/cloudflare-workers/index.js +3 -1
- package/dist/adapter/cloudflare-workers/websocket.js +57 -0
- package/dist/adapter/deno/index.js +3 -1
- package/dist/adapter/deno/websocket.js +29 -0
- package/dist/adapter/lambda-edge/handler.js +1 -1
- package/dist/cjs/adapter/aws-lambda/handler.js +1 -1
- package/dist/cjs/adapter/bun/index.js +3 -0
- package/dist/cjs/adapter/bun/websocket.js +98 -0
- package/dist/cjs/adapter/cloudflare-workers/index.js +5 -2
- package/dist/cjs/adapter/cloudflare-workers/websocket.js +80 -0
- package/dist/cjs/adapter/deno/index.js +5 -2
- package/dist/cjs/adapter/deno/websocket.js +52 -0
- package/dist/cjs/adapter/lambda-edge/handler.js +1 -1
- package/dist/cjs/client/client.js +68 -61
- package/dist/cjs/context.js +164 -188
- package/dist/cjs/helper/adapter/index.js +1 -1
- package/dist/cjs/helper/cookie/index.js +48 -8
- package/dist/cjs/helper/dev/index.js +3 -4
- package/dist/cjs/helper/factory/index.js +1 -3
- package/dist/cjs/helper/ssg/index.js +9 -159
- package/dist/cjs/helper/ssg/middleware.js +57 -0
- package/dist/cjs/helper/ssg/ssg.js +212 -0
- package/dist/cjs/helper/websocket/index.js +32 -0
- package/dist/cjs/helper.js +1 -0
- package/dist/cjs/hono-base.js +46 -65
- package/dist/cjs/http-exception.js +3 -1
- package/dist/cjs/jsx/base.js +7 -2
- package/dist/cjs/jsx/components.js +1 -1
- package/dist/cjs/jsx/dom/index.js +45 -3
- package/dist/cjs/jsx/dom/render.js +6 -6
- package/dist/cjs/jsx/hooks/index.js +25 -16
- package/dist/cjs/jsx/index.js +34 -2
- package/dist/cjs/middleware/body-limit/index.js +80 -0
- package/dist/cjs/middleware/logger/index.js +9 -7
- package/dist/cjs/request.js +29 -48
- package/dist/cjs/router/linear-router/router.js +3 -5
- package/dist/cjs/router/pattern-router/router.js +2 -4
- package/dist/cjs/router/reg-exp-router/node.js +3 -3
- package/dist/cjs/router/reg-exp-router/router.js +11 -12
- package/dist/cjs/router/reg-exp-router/trie.js +2 -4
- package/dist/cjs/router/smart-router/router.js +3 -3
- package/dist/cjs/router/trie-router/node.js +6 -2
- package/dist/cjs/router/trie-router/router.js +2 -1
- package/dist/cjs/test-utils/setup-vitest.js +2 -0
- package/dist/cjs/utils/color.js +32 -0
- package/dist/cjs/utils/concurrent.js +62 -0
- package/dist/cjs/utils/cookie.js +28 -1
- package/dist/cjs/utils/stream.js +5 -1
- package/dist/cjs/utils/url.js +2 -2
- package/dist/client/client.js +68 -61
- package/dist/context.js +164 -189
- package/dist/helper/adapter/index.js +1 -1
- package/dist/helper/cookie/index.js +48 -8
- package/dist/helper/dev/index.js +3 -4
- package/dist/helper/factory/index.js +1 -3
- package/dist/helper/ssg/index.js +3 -151
- package/dist/helper/ssg/middleware.js +29 -0
- package/dist/helper/ssg/ssg.js +187 -0
- package/dist/helper/websocket/index.js +9 -0
- package/dist/helper.js +1 -0
- package/dist/hono-base.js +45 -65
- package/dist/http-exception.js +3 -1
- package/dist/jsx/base.js +7 -2
- package/dist/jsx/components.js +1 -1
- package/dist/jsx/dom/index.js +44 -4
- package/dist/jsx/dom/render.js +6 -6
- package/dist/jsx/hooks/index.js +23 -16
- package/dist/jsx/index.js +34 -3
- package/dist/middleware/body-limit/index.js +57 -0
- package/dist/middleware/logger/index.js +9 -7
- package/dist/request.js +29 -49
- package/dist/router/linear-router/router.js +3 -5
- package/dist/router/pattern-router/router.js +2 -4
- package/dist/router/reg-exp-router/node.js +3 -3
- package/dist/router/reg-exp-router/router.js +11 -12
- package/dist/router/reg-exp-router/trie.js +2 -4
- package/dist/router/smart-router/router.js +3 -3
- package/dist/router/trie-router/node.js +6 -2
- package/dist/router/trie-router/router.js +2 -1
- package/dist/test-utils/setup-vitest.js +2 -0
- package/dist/types/adapter/bun/index.d.ts +1 -0
- package/dist/types/adapter/bun/websocket.d.ts +26 -0
- package/dist/types/adapter/cloudflare-workers/index.d.ts +1 -0
- package/dist/types/adapter/cloudflare-workers/websocket.d.ts +2 -0
- package/dist/types/adapter/deno/index.d.ts +1 -0
- package/dist/types/adapter/deno/websocket.d.ts +2 -0
- package/dist/types/client/types.d.ts +9 -0
- package/dist/types/helper/cookie/index.d.ts +3 -1
- package/dist/types/helper/ssg/index.d.ts +2 -105
- package/dist/types/helper/ssg/middleware.d.ts +38 -0
- package/dist/types/helper/ssg/ssg.d.ts +70 -0
- package/dist/types/helper/websocket/index.d.ts +34 -0
- package/dist/types/http-exception.d.ts +1 -0
- package/dist/types/jsx/dom/index.d.ts +40 -7
- package/dist/types/jsx/hooks/index.d.ts +2 -0
- package/dist/types/jsx/index.d.ts +41 -5
- package/dist/types/middleware/body-limit/index.d.ts +28 -0
- package/dist/types/utils/color.d.ts +1 -0
- package/dist/types/utils/concurrent.d.ts +7 -0
- package/dist/types/utils/cookie.d.ts +2 -0
- package/dist/utils/color.js +9 -0
- package/dist/utils/concurrent.js +39 -0
- package/dist/utils/cookie.js +28 -1
- package/dist/utils/stream.js +5 -1
- package/dist/utils/url.js +2 -2
- package/package.json +18 -2
|
@@ -23,10 +23,8 @@ __export(router_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(router_exports);
|
|
24
24
|
var import_router = require("../../router");
|
|
25
25
|
class PatternRouter {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
this.routes = [];
|
|
29
|
-
}
|
|
26
|
+
name = "PatternRouter";
|
|
27
|
+
routes = [];
|
|
30
28
|
add(method, path, handler) {
|
|
31
29
|
const endsWithWildcard = path[path.length - 1] === "*";
|
|
32
30
|
if (endsWithWildcard) {
|
|
@@ -46,9 +46,9 @@ function compareKey(a, b) {
|
|
|
46
46
|
return a.length === b.length ? a < b ? -1 : 1 : b.length - a.length;
|
|
47
47
|
}
|
|
48
48
|
class Node {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
49
|
+
index;
|
|
50
|
+
varIndex;
|
|
51
|
+
children = {};
|
|
52
52
|
insert(tokens, index, paramMap, context, pathErrorCheckOnly) {
|
|
53
53
|
if (tokens.length === 0) {
|
|
54
54
|
if (this.index !== void 0) {
|
|
@@ -29,9 +29,9 @@ const emptyParam = [];
|
|
|
29
29
|
const nullMatcher = [/^$/, [], {}];
|
|
30
30
|
let wildcardRegExpCache = {};
|
|
31
31
|
function buildWildcardRegExp(path) {
|
|
32
|
-
return wildcardRegExpCache[path]
|
|
32
|
+
return wildcardRegExpCache[path] ??= new RegExp(
|
|
33
33
|
path === "*" ? "" : `^${path.replace(/\/\*/, "(?:|/.*)")}$`
|
|
34
|
-
)
|
|
34
|
+
);
|
|
35
35
|
}
|
|
36
36
|
function clearWildcardRegExpCache() {
|
|
37
37
|
wildcardRegExpCache = {};
|
|
@@ -105,13 +105,14 @@ function findMiddleware(middleware, path) {
|
|
|
105
105
|
return void 0;
|
|
106
106
|
}
|
|
107
107
|
class RegExpRouter {
|
|
108
|
+
name = "RegExpRouter";
|
|
109
|
+
middleware;
|
|
110
|
+
routes;
|
|
108
111
|
constructor() {
|
|
109
|
-
this.name = "RegExpRouter";
|
|
110
112
|
this.middleware = { [import_router.METHOD_NAME_ALL]: {} };
|
|
111
113
|
this.routes = { [import_router.METHOD_NAME_ALL]: {} };
|
|
112
114
|
}
|
|
113
115
|
add(method, path, handler) {
|
|
114
|
-
var _a;
|
|
115
116
|
const { middleware, routes } = this;
|
|
116
117
|
if (!middleware || !routes) {
|
|
117
118
|
throw new Error(import_router.MESSAGE_MATCHER_IS_ALREADY_BUILT);
|
|
@@ -133,11 +134,10 @@ class RegExpRouter {
|
|
|
133
134
|
const re = buildWildcardRegExp(path);
|
|
134
135
|
if (method === import_router.METHOD_NAME_ALL) {
|
|
135
136
|
Object.keys(middleware).forEach((m) => {
|
|
136
|
-
|
|
137
|
-
(_a2 = middleware[m])[path] || (_a2[path] = findMiddleware(middleware[m], path) || findMiddleware(middleware[import_router.METHOD_NAME_ALL], path) || []);
|
|
137
|
+
middleware[m][path] ||= findMiddleware(middleware[m], path) || findMiddleware(middleware[import_router.METHOD_NAME_ALL], path) || [];
|
|
138
138
|
});
|
|
139
139
|
} else {
|
|
140
|
-
|
|
140
|
+
middleware[method][path] ||= findMiddleware(middleware[method], path) || findMiddleware(middleware[import_router.METHOD_NAME_ALL], path) || [];
|
|
141
141
|
}
|
|
142
142
|
Object.keys(middleware).forEach((m) => {
|
|
143
143
|
if (method === import_router.METHOD_NAME_ALL || method === m) {
|
|
@@ -159,11 +159,10 @@ class RegExpRouter {
|
|
|
159
159
|
for (let i = 0, len = paths.length; i < len; i++) {
|
|
160
160
|
const path2 = paths[i];
|
|
161
161
|
Object.keys(routes).forEach((m) => {
|
|
162
|
-
var _a2;
|
|
163
162
|
if (method === import_router.METHOD_NAME_ALL || method === m) {
|
|
164
|
-
|
|
163
|
+
routes[m][path2] ||= [
|
|
165
164
|
...findMiddleware(middleware[m], path2) || findMiddleware(middleware[import_router.METHOD_NAME_ALL], path2) || []
|
|
166
|
-
]
|
|
165
|
+
];
|
|
167
166
|
routes[m][path2].push([handler, paramCount - len + i + 1]);
|
|
168
167
|
}
|
|
169
168
|
});
|
|
@@ -190,7 +189,7 @@ class RegExpRouter {
|
|
|
190
189
|
buildAllMatchers() {
|
|
191
190
|
const matchers = {};
|
|
192
191
|
[...Object.keys(this.routes), ...Object.keys(this.middleware)].forEach((method) => {
|
|
193
|
-
matchers[method]
|
|
192
|
+
matchers[method] ||= this.buildMatcher(method);
|
|
194
193
|
});
|
|
195
194
|
this.middleware = this.routes = void 0;
|
|
196
195
|
return matchers;
|
|
@@ -201,7 +200,7 @@ class RegExpRouter {
|
|
|
201
200
|
[this.middleware, this.routes].forEach((r) => {
|
|
202
201
|
const ownRoute = r[method] ? Object.keys(r[method]).map((path) => [path, r[method][path]]) : [];
|
|
203
202
|
if (ownRoute.length !== 0) {
|
|
204
|
-
hasOwnRoute
|
|
203
|
+
hasOwnRoute ||= true;
|
|
205
204
|
routes.push(...ownRoute);
|
|
206
205
|
} else if (method !== import_router.METHOD_NAME_ALL) {
|
|
207
206
|
routes.push(
|
|
@@ -23,10 +23,8 @@ __export(trie_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(trie_exports);
|
|
24
24
|
var import_node = require("./node");
|
|
25
25
|
class Trie {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
this.root = new import_node.Node();
|
|
29
|
-
}
|
|
26
|
+
context = { varIndex: 0 };
|
|
27
|
+
root = new import_node.Node();
|
|
30
28
|
insert(path, index, pathErrorCheckOnly) {
|
|
31
29
|
const paramAssoc = [];
|
|
32
30
|
const groups = [];
|
|
@@ -23,10 +23,10 @@ __export(router_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(router_exports);
|
|
24
24
|
var import_router = require("../../router");
|
|
25
25
|
class SmartRouter {
|
|
26
|
+
name = "SmartRouter";
|
|
27
|
+
routers = [];
|
|
28
|
+
routes = [];
|
|
26
29
|
constructor(init) {
|
|
27
|
-
this.name = "SmartRouter";
|
|
28
|
-
this.routers = [];
|
|
29
|
-
this.routes = [];
|
|
30
30
|
Object.assign(this, init);
|
|
31
31
|
}
|
|
32
32
|
add(method, path, handler) {
|
|
@@ -24,9 +24,13 @@ module.exports = __toCommonJS(node_exports);
|
|
|
24
24
|
var import_router = require("../../router");
|
|
25
25
|
var import_url = require("../../utils/url");
|
|
26
26
|
class Node {
|
|
27
|
+
methods;
|
|
28
|
+
children;
|
|
29
|
+
patterns;
|
|
30
|
+
order = 0;
|
|
31
|
+
name;
|
|
32
|
+
params = {};
|
|
27
33
|
constructor(method, handler, children) {
|
|
28
|
-
this.order = 0;
|
|
29
|
-
this.params = {};
|
|
30
34
|
this.children = children || {};
|
|
31
35
|
this.methods = [];
|
|
32
36
|
this.name = "";
|
|
@@ -24,8 +24,9 @@ module.exports = __toCommonJS(router_exports);
|
|
|
24
24
|
var import_url = require("../../utils/url");
|
|
25
25
|
var import_node = require("./node");
|
|
26
26
|
class TrieRouter {
|
|
27
|
+
name = "TrieRouter";
|
|
28
|
+
node;
|
|
27
29
|
constructor() {
|
|
28
|
-
this.name = "TrieRouter";
|
|
29
30
|
this.node = new import_node.Node();
|
|
30
31
|
}
|
|
31
32
|
add(method, path, handler) {
|
|
@@ -21,6 +21,8 @@ var import_node_crypto = __toESM(require("node:crypto"), 1);
|
|
|
21
21
|
var import_vitest = require("vitest");
|
|
22
22
|
import_vitest.vi.stubGlobal("crypto", import_node_crypto.default);
|
|
23
23
|
class MockCache {
|
|
24
|
+
name;
|
|
25
|
+
store;
|
|
24
26
|
constructor(name, store) {
|
|
25
27
|
this.name = name;
|
|
26
28
|
this.store = store;
|
|
@@ -0,0 +1,32 @@
|
|
|
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 color_exports = {};
|
|
20
|
+
__export(color_exports, {
|
|
21
|
+
getColorEnabled: () => getColorEnabled
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(color_exports);
|
|
24
|
+
function getColorEnabled() {
|
|
25
|
+
const { process, Deno } = globalThis;
|
|
26
|
+
const isNoColor = typeof process !== "undefined" ? "NO_COLOR" in process?.env : typeof Deno?.noColor === "boolean" ? Deno.noColor : false;
|
|
27
|
+
return !isNoColor;
|
|
28
|
+
}
|
|
29
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
30
|
+
0 && (module.exports = {
|
|
31
|
+
getColorEnabled
|
|
32
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
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 concurrent_exports = {};
|
|
20
|
+
__export(concurrent_exports, {
|
|
21
|
+
createPool: () => createPool
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(concurrent_exports);
|
|
24
|
+
const DEFAULT_CONCURRENCY = 1024;
|
|
25
|
+
const createPool = ({
|
|
26
|
+
concurrency,
|
|
27
|
+
interval
|
|
28
|
+
} = {}) => {
|
|
29
|
+
concurrency ||= DEFAULT_CONCURRENCY;
|
|
30
|
+
if (concurrency === Infinity) {
|
|
31
|
+
return {
|
|
32
|
+
run: async (fn) => fn()
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
const pool = /* @__PURE__ */ new Set();
|
|
36
|
+
const run = async (fn, promise, resolve) => {
|
|
37
|
+
if (pool.size >= concurrency) {
|
|
38
|
+
promise ||= new Promise((r) => resolve = r);
|
|
39
|
+
setTimeout(() => run(fn, promise, resolve));
|
|
40
|
+
return promise;
|
|
41
|
+
}
|
|
42
|
+
const marker = {};
|
|
43
|
+
pool.add(marker);
|
|
44
|
+
const result = await fn();
|
|
45
|
+
if (interval) {
|
|
46
|
+
setTimeout(() => pool.delete(marker), interval);
|
|
47
|
+
} else {
|
|
48
|
+
pool.delete(marker);
|
|
49
|
+
}
|
|
50
|
+
if (resolve) {
|
|
51
|
+
resolve(result);
|
|
52
|
+
return promise;
|
|
53
|
+
} else {
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
return { run };
|
|
58
|
+
};
|
|
59
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
60
|
+
0 && (module.exports = {
|
|
61
|
+
createPool
|
|
62
|
+
});
|
package/dist/cjs/utils/cookie.js
CHANGED
|
@@ -91,16 +91,40 @@ const parseSigned = async (cookie, secret, name) => {
|
|
|
91
91
|
};
|
|
92
92
|
const _serialize = (name, value, opt = {}) => {
|
|
93
93
|
let cookie = `${name}=${value}`;
|
|
94
|
+
if (name.startsWith("__Secure-") && !opt.secure) {
|
|
95
|
+
throw new Error("__Secure- Cookie must have Secure attributes");
|
|
96
|
+
}
|
|
97
|
+
if (name.startsWith("__Host-")) {
|
|
98
|
+
if (!opt.secure) {
|
|
99
|
+
throw new Error("__Host- Cookie must have Secure attributes");
|
|
100
|
+
}
|
|
101
|
+
if (opt.path !== "/") {
|
|
102
|
+
throw new Error('__Host- Cookie must have Path attributes with "/"');
|
|
103
|
+
}
|
|
104
|
+
if (opt.domain) {
|
|
105
|
+
throw new Error("__Host- Cookie must not have Domain attributes");
|
|
106
|
+
}
|
|
107
|
+
}
|
|
94
108
|
if (opt && typeof opt.maxAge === "number" && opt.maxAge >= 0) {
|
|
109
|
+
if (opt.maxAge > 3456e4) {
|
|
110
|
+
throw new Error(
|
|
111
|
+
"Cookies Max-Age SHOULD NOT be greater than 400 days (34560000 seconds) in duration."
|
|
112
|
+
);
|
|
113
|
+
}
|
|
95
114
|
cookie += `; Max-Age=${Math.floor(opt.maxAge)}`;
|
|
96
115
|
}
|
|
97
|
-
if (opt.domain) {
|
|
116
|
+
if (opt.domain && opt.prefix !== "host") {
|
|
98
117
|
cookie += `; Domain=${opt.domain}`;
|
|
99
118
|
}
|
|
100
119
|
if (opt.path) {
|
|
101
120
|
cookie += `; Path=${opt.path}`;
|
|
102
121
|
}
|
|
103
122
|
if (opt.expires) {
|
|
123
|
+
if (opt.expires.getTime() - Date.now() > 3456e7) {
|
|
124
|
+
throw new Error(
|
|
125
|
+
"Cookies Expires SHOULD NOT be greater than 400 days (34560000 seconds) in the future."
|
|
126
|
+
);
|
|
127
|
+
}
|
|
104
128
|
cookie += `; Expires=${opt.expires.toUTCString()}`;
|
|
105
129
|
}
|
|
106
130
|
if (opt.httpOnly) {
|
|
@@ -113,6 +137,9 @@ const _serialize = (name, value, opt = {}) => {
|
|
|
113
137
|
cookie += `; SameSite=${opt.sameSite}`;
|
|
114
138
|
}
|
|
115
139
|
if (opt.partitioned) {
|
|
140
|
+
if (!opt.secure) {
|
|
141
|
+
throw new Error("Partitioned Cookie must have Secure attributes");
|
|
142
|
+
}
|
|
116
143
|
cookie += "; Partitioned";
|
|
117
144
|
}
|
|
118
145
|
return cookie;
|
package/dist/cjs/utils/stream.js
CHANGED
|
@@ -22,8 +22,12 @@ __export(stream_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(stream_exports);
|
|
24
24
|
class StreamingApi {
|
|
25
|
+
writer;
|
|
26
|
+
encoder;
|
|
27
|
+
writable;
|
|
28
|
+
abortSubscribers = [];
|
|
29
|
+
responseReadable;
|
|
25
30
|
constructor(writable, _readable) {
|
|
26
|
-
this.abortSubscribers = [];
|
|
27
31
|
this.writable = writable;
|
|
28
32
|
this.writer = writable.getWriter();
|
|
29
33
|
this.encoder = new TextEncoder();
|
package/dist/cjs/utils/url.js
CHANGED
|
@@ -176,7 +176,7 @@ const _getQueryParam = (url, key, multiple) => {
|
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
178
|
const results = {};
|
|
179
|
-
encoded
|
|
179
|
+
encoded ??= /[%+]/.test(url);
|
|
180
180
|
let keyIndex = url.indexOf("?", 8);
|
|
181
181
|
while (keyIndex !== -1) {
|
|
182
182
|
const nextKeyIndex = url.indexOf("&", keyIndex + 1);
|
|
@@ -211,7 +211,7 @@ const _getQueryParam = (url, key, multiple) => {
|
|
|
211
211
|
;
|
|
212
212
|
results[name].push(value);
|
|
213
213
|
} else {
|
|
214
|
-
results[name]
|
|
214
|
+
results[name] ??= value;
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
217
|
return key ? results[key] : results;
|
package/dist/client/client.js
CHANGED
|
@@ -20,76 +20,79 @@ var createProxy = (callback, path) => {
|
|
|
20
20
|
return proxy;
|
|
21
21
|
};
|
|
22
22
|
var ClientRequestImpl = class {
|
|
23
|
+
url;
|
|
24
|
+
method;
|
|
25
|
+
queryParams = void 0;
|
|
26
|
+
pathParams = {};
|
|
27
|
+
rBody;
|
|
28
|
+
cType = void 0;
|
|
23
29
|
constructor(url, method) {
|
|
24
|
-
this.
|
|
25
|
-
this.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
this.queryParams || (this.queryParams = new URLSearchParams());
|
|
35
|
-
if (Array.isArray(v)) {
|
|
36
|
-
for (const v2 of v) {
|
|
37
|
-
this.queryParams.append(k, v2);
|
|
38
|
-
}
|
|
39
|
-
} else {
|
|
40
|
-
this.queryParams.set(k, v);
|
|
41
|
-
}
|
|
30
|
+
this.url = url;
|
|
31
|
+
this.method = method;
|
|
32
|
+
}
|
|
33
|
+
fetch = (args, opt) => {
|
|
34
|
+
if (args) {
|
|
35
|
+
if (args.query) {
|
|
36
|
+
for (const [k, v] of Object.entries(args.query)) {
|
|
37
|
+
if (v === void 0) {
|
|
38
|
+
continue;
|
|
42
39
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
40
|
+
this.queryParams ||= new URLSearchParams();
|
|
41
|
+
if (Array.isArray(v)) {
|
|
42
|
+
for (const v2 of v) {
|
|
43
|
+
this.queryParams.append(k, v2);
|
|
44
|
+
}
|
|
45
|
+
} else {
|
|
46
|
+
this.queryParams.set(k, v);
|
|
48
47
|
}
|
|
49
|
-
this.rBody = form;
|
|
50
|
-
}
|
|
51
|
-
if (args.json) {
|
|
52
|
-
this.rBody = JSON.stringify(args.json);
|
|
53
|
-
this.cType = "application/json";
|
|
54
|
-
}
|
|
55
|
-
if (args.param) {
|
|
56
|
-
this.pathParams = args.param;
|
|
57
48
|
}
|
|
58
49
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
...opt?.headers ? opt.headers : {}
|
|
64
|
-
};
|
|
65
|
-
if (args?.cookie) {
|
|
66
|
-
const cookies = [];
|
|
67
|
-
for (const [key, value] of Object.entries(args.cookie)) {
|
|
68
|
-
cookies.push(serialize(key, value, { path: "/" }));
|
|
50
|
+
if (args.form) {
|
|
51
|
+
const form = new FormData();
|
|
52
|
+
for (const [k, v] of Object.entries(args.form)) {
|
|
53
|
+
form.append(k, v);
|
|
69
54
|
}
|
|
70
|
-
|
|
55
|
+
this.rBody = form;
|
|
71
56
|
}
|
|
72
|
-
if (
|
|
73
|
-
|
|
57
|
+
if (args.json) {
|
|
58
|
+
this.rBody = JSON.stringify(args.json);
|
|
59
|
+
this.cType = "application/json";
|
|
74
60
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
url = removeIndexString(url);
|
|
78
|
-
url = replaceUrlParam(url, this.pathParams);
|
|
79
|
-
if (this.queryParams) {
|
|
80
|
-
url = url + "?" + this.queryParams.toString();
|
|
61
|
+
if (args.param) {
|
|
62
|
+
this.pathParams = args.param;
|
|
81
63
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
});
|
|
64
|
+
}
|
|
65
|
+
let methodUpperCase = this.method.toUpperCase();
|
|
66
|
+
let setBody = !(methodUpperCase === "GET" || methodUpperCase === "HEAD");
|
|
67
|
+
const headerValues = {
|
|
68
|
+
...args?.header ?? {},
|
|
69
|
+
...opt?.headers ? opt.headers : {}
|
|
89
70
|
};
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
71
|
+
if (args?.cookie) {
|
|
72
|
+
const cookies = [];
|
|
73
|
+
for (const [key, value] of Object.entries(args.cookie)) {
|
|
74
|
+
cookies.push(serialize(key, value, { path: "/" }));
|
|
75
|
+
}
|
|
76
|
+
headerValues["Cookie"] = cookies.join(",");
|
|
77
|
+
}
|
|
78
|
+
if (this.cType) {
|
|
79
|
+
headerValues["Content-Type"] = this.cType;
|
|
80
|
+
}
|
|
81
|
+
const headers = new Headers(headerValues ?? void 0);
|
|
82
|
+
let url = this.url;
|
|
83
|
+
url = removeIndexString(url);
|
|
84
|
+
url = replaceUrlParam(url, this.pathParams);
|
|
85
|
+
if (this.queryParams) {
|
|
86
|
+
url = url + "?" + this.queryParams.toString();
|
|
87
|
+
}
|
|
88
|
+
methodUpperCase = this.method.toUpperCase();
|
|
89
|
+
setBody = !(methodUpperCase === "GET" || methodUpperCase === "HEAD");
|
|
90
|
+
return (opt?.fetch || fetch)(url, {
|
|
91
|
+
body: setBody ? this.rBody : void 0,
|
|
92
|
+
method: methodUpperCase,
|
|
93
|
+
headers
|
|
94
|
+
});
|
|
95
|
+
};
|
|
93
96
|
};
|
|
94
97
|
var hc = (baseUrl, options) => createProxy((opts) => {
|
|
95
98
|
const parts = [...opts.path];
|
|
@@ -108,9 +111,13 @@ var hc = (baseUrl, options) => createProxy((opts) => {
|
|
|
108
111
|
}
|
|
109
112
|
return new URL(url);
|
|
110
113
|
}
|
|
114
|
+
if (method === "ws") {
|
|
115
|
+
const targetUrl = opts.args[0] && opts.args[0].param ? replaceUrlParam(url, opts.args[0].param) : url;
|
|
116
|
+
return new WebSocket(targetUrl);
|
|
117
|
+
}
|
|
111
118
|
const req = new ClientRequestImpl(url, method);
|
|
112
119
|
if (method) {
|
|
113
|
-
options
|
|
120
|
+
options ??= {};
|
|
114
121
|
const args = deepMerge(options, { ...opts.args[1] ?? {} });
|
|
115
122
|
return req.fetch(opts.args[0], args);
|
|
116
123
|
}
|