hono 2.3.2 → 2.4.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.
Files changed (141) hide show
  1. package/dist/cjs/compose.js +82 -66
  2. package/dist/cjs/context.js +159 -144
  3. package/dist/cjs/hono.js +173 -150
  4. package/dist/cjs/index.js +31 -11
  5. package/dist/cjs/middleware/basic-auth/index.js +70 -39
  6. package/dist/cjs/middleware/bearer-auth/index.js +69 -51
  7. package/dist/cjs/middleware/cache/index.js +49 -28
  8. package/dist/cjs/middleware/compress/index.js +39 -16
  9. package/dist/cjs/middleware/cors/index.js +89 -71
  10. package/dist/cjs/middleware/etag/index.js +46 -24
  11. package/dist/cjs/middleware/html/index.js +50 -30
  12. package/dist/cjs/middleware/jsx/index.js +178 -166
  13. package/dist/cjs/middleware/jsx/jsx-dev-runtime.js +30 -7
  14. package/dist/cjs/middleware/jsx/jsx-runtime.js +30 -6
  15. package/dist/cjs/middleware/jwt/index.js +74 -54
  16. package/dist/cjs/middleware/logger/index.js +59 -38
  17. package/dist/cjs/middleware/powered-by/index.js +30 -7
  18. package/dist/cjs/middleware/pretty-json/index.js +31 -8
  19. package/dist/cjs/middleware/serve-static/bun.js +56 -38
  20. package/dist/cjs/middleware/serve-static/index.js +27 -4
  21. package/dist/cjs/middleware/serve-static/module.js +42 -0
  22. package/dist/cjs/middleware/serve-static/serve-static.js +58 -39
  23. package/dist/cjs/middleware/validator/index.js +27 -4
  24. package/dist/cjs/middleware/validator/middleware.js +125 -91
  25. package/dist/cjs/package.json +3 -0
  26. package/dist/cjs/request.js +129 -116
  27. package/dist/cjs/router/reg-exp-router/index.js +27 -4
  28. package/dist/cjs/router/reg-exp-router/node.js +108 -97
  29. package/dist/cjs/router/reg-exp-router/router.js +158 -141
  30. package/dist/cjs/router/reg-exp-router/trie.js +55 -39
  31. package/dist/cjs/router/smart-router/index.js +27 -4
  32. package/dist/cjs/router/smart-router/router.js +70 -49
  33. package/dist/cjs/router/static-router/index.js +27 -4
  34. package/dist/cjs/router/static-router/router.js +78 -64
  35. package/dist/cjs/router/trie-router/index.js +27 -4
  36. package/dist/cjs/router/trie-router/node.js +167 -159
  37. package/dist/cjs/router/trie-router/router.js +43 -20
  38. package/dist/cjs/router.js +35 -6
  39. package/dist/cjs/types.js +16 -0
  40. package/dist/cjs/utils/body.js +36 -15
  41. package/dist/cjs/utils/buffer.js +56 -31
  42. package/dist/cjs/utils/cloudflare.js +53 -34
  43. package/dist/cjs/utils/cookie.js +59 -35
  44. package/dist/cjs/utils/crypto.js +69 -43
  45. package/dist/cjs/utils/encode.js +92 -65
  46. package/dist/cjs/utils/filepath.js +39 -22
  47. package/dist/cjs/utils/html.js +54 -33
  48. package/dist/cjs/utils/http-status.js +68 -45
  49. package/dist/cjs/utils/json.js +91 -76
  50. package/dist/cjs/utils/jwt/index.js +32 -25
  51. package/dist/cjs/utils/jwt/jwt.js +124 -93
  52. package/dist/cjs/utils/jwt/types.js +65 -38
  53. package/dist/cjs/utils/mime.js +110 -87
  54. package/dist/cjs/utils/object.js +53 -35
  55. package/dist/cjs/utils/types.js +15 -1
  56. package/dist/cjs/utils/url.js +89 -78
  57. package/dist/cjs/validator/rule.js +78 -64
  58. package/dist/cjs/validator/sanitizer.js +28 -4
  59. package/dist/cjs/validator/schema.js +15 -1
  60. package/dist/cjs/validator/validator.js +405 -386
  61. package/dist/compose.d.ts +1 -1
  62. package/dist/compose.js +61 -64
  63. package/dist/context.d.ts +4 -4
  64. package/dist/context.js +139 -143
  65. package/dist/hono.d.ts +1 -17
  66. package/dist/hono.js +153 -149
  67. package/dist/index.d.ts +3 -1
  68. package/dist/index.js +9 -9
  69. package/dist/middleware/basic-auth/index.d.ts +1 -1
  70. package/dist/middleware/basic-auth/index.js +52 -40
  71. package/dist/middleware/bearer-auth/index.d.ts +1 -1
  72. package/dist/middleware/bearer-auth/index.js +48 -49
  73. package/dist/middleware/cache/index.d.ts +1 -1
  74. package/dist/middleware/cache/index.js +28 -26
  75. package/dist/middleware/compress/index.d.ts +1 -1
  76. package/dist/middleware/compress/index.js +18 -14
  77. package/dist/middleware/cors/index.d.ts +1 -1
  78. package/dist/middleware/cors/index.js +68 -69
  79. package/dist/middleware/etag/index.d.ts +1 -1
  80. package/dist/middleware/etag/index.js +25 -22
  81. package/dist/middleware/html/index.js +29 -28
  82. package/dist/middleware/jsx/index.js +164 -172
  83. package/dist/middleware/jsx/jsx-dev-runtime.js +9 -5
  84. package/dist/middleware/jsx/jsx-runtime.js +7 -2
  85. package/dist/middleware/jwt/index.d.ts +1 -1
  86. package/dist/middleware/jwt/index.js +53 -52
  87. package/dist/middleware/logger/index.d.ts +1 -1
  88. package/dist/middleware/logger/index.js +35 -39
  89. package/dist/middleware/powered-by/index.d.ts +1 -1
  90. package/dist/middleware/powered-by/index.js +9 -5
  91. package/dist/middleware/pretty-json/index.d.ts +1 -1
  92. package/dist/middleware/pretty-json/index.js +10 -6
  93. package/dist/middleware/serve-static/bun.d.ts +1 -1
  94. package/dist/middleware/serve-static/bun.js +35 -36
  95. package/dist/middleware/serve-static/index.js +5 -1
  96. package/dist/middleware/serve-static/{module.d.mts → module.d.ts} +1 -1
  97. package/dist/middleware/serve-static/module.js +13 -0
  98. package/dist/middleware/serve-static/serve-static.d.ts +1 -1
  99. package/dist/middleware/serve-static/serve-static.js +36 -36
  100. package/dist/middleware/validator/index.js +5 -2
  101. package/dist/middleware/validator/middleware.d.ts +1 -1
  102. package/dist/middleware/validator/middleware.js +104 -89
  103. package/dist/request.js +108 -114
  104. package/dist/router/reg-exp-router/index.js +5 -1
  105. package/dist/router/reg-exp-router/node.js +87 -96
  106. package/dist/router/reg-exp-router/router.js +140 -142
  107. package/dist/router/reg-exp-router/trie.js +35 -38
  108. package/dist/router/smart-router/index.js +5 -1
  109. package/dist/router/smart-router/router.js +50 -48
  110. package/dist/router/static-router/index.js +5 -1
  111. package/dist/router/static-router/router.js +58 -63
  112. package/dist/router/trie-router/index.js +5 -1
  113. package/dist/router/trie-router/node.js +147 -158
  114. package/dist/router/trie-router/router.js +23 -19
  115. package/dist/router.js +12 -5
  116. package/dist/types.d.ts +22 -0
  117. package/dist/types.js +0 -0
  118. package/dist/utils/body.js +15 -13
  119. package/dist/utils/buffer.js +35 -29
  120. package/dist/utils/cloudflare.js +32 -32
  121. package/dist/utils/cookie.js +38 -33
  122. package/dist/utils/crypto.js +48 -41
  123. package/dist/utils/encode.js +70 -62
  124. package/dist/utils/filepath.js +18 -20
  125. package/dist/utils/html.js +34 -32
  126. package/dist/utils/http-status.js +48 -44
  127. package/dist/utils/json.js +71 -75
  128. package/dist/utils/jwt/index.js +5 -1
  129. package/dist/utils/jwt/jwt.js +95 -90
  130. package/dist/utils/jwt/types.js +47 -41
  131. package/dist/utils/mime.js +90 -86
  132. package/dist/utils/object.js +31 -32
  133. package/dist/utils/types.js +0 -1
  134. package/dist/utils/url.js +69 -77
  135. package/dist/validator/rule.js +56 -62
  136. package/dist/validator/sanitizer.js +6 -2
  137. package/dist/validator/schema.js +0 -1
  138. package/dist/validator/validator.d.ts +5 -4
  139. package/dist/validator/validator.js +393 -393
  140. package/package.json +14 -8
  141. package/dist/middleware/serve-static/module.mjs +0 -13
@@ -1,170 +1,159 @@
1
- import { METHOD_NAME_ALL } from '../../router';
2
- import { splitPath, getPattern } from '../../utils/url';
1
+ // src/router/trie-router/node.ts
2
+ import { METHOD_NAME_ALL } from "../../router.js";
3
+ import { splitPath, getPattern } from "../../utils/url.js";
3
4
  function findParam(node, name) {
4
- for (let i = 0, len = node.patterns.length; i < len; i++) {
5
- if (typeof node.patterns[i] === 'object' && node.patterns[i][1] === name) {
6
- return true;
7
- }
5
+ for (let i = 0, len = node.patterns.length; i < len; i++) {
6
+ if (typeof node.patterns[i] === "object" && node.patterns[i][1] === name) {
7
+ return true;
8
8
  }
9
- const nodes = Object.values(node.children);
10
- for (let i = 0, len = nodes.length; i < len; i++) {
11
- if (findParam(nodes[i], name)) {
12
- return true;
13
- }
9
+ }
10
+ const nodes = Object.values(node.children);
11
+ for (let i = 0, len = nodes.length; i < len; i++) {
12
+ if (findParam(nodes[i], name)) {
13
+ return true;
14
14
  }
15
- return false;
15
+ }
16
+ return false;
16
17
  }
17
- export class Node {
18
- constructor(method, handler, children) {
19
- this.order = 0;
20
- this.children = children || {};
21
- this.methods = [];
22
- this.name = '';
23
- if (method && handler) {
24
- const m = {};
25
- m[method] = { handler: handler, score: 0, name: this.name };
26
- this.methods = [m];
27
- }
28
- this.patterns = [];
29
- this.handlerSetCache = {};
18
+ var Node = class {
19
+ constructor(method, handler, children) {
20
+ this.order = 0;
21
+ this.children = children || {};
22
+ this.methods = [];
23
+ this.name = "";
24
+ if (method && handler) {
25
+ const m = {};
26
+ m[method] = { handler, score: 0, name: this.name };
27
+ this.methods = [m];
30
28
  }
31
- insert(method, path, handler) {
32
- this.name = `${method} ${path}`;
33
- this.order = ++this.order;
34
- // eslint-disable-next-line @typescript-eslint/no-this-alias
35
- let curNode = this;
36
- const parts = splitPath(path);
37
- const parentPatterns = [];
38
- const errorMessage = (name) => {
39
- return `Duplicate param name, use another name instead of '${name}' - ${method} ${path} <--- '${name}'`;
40
- };
41
- for (let i = 0, len = parts.length; i < len; i++) {
42
- const p = parts[i];
43
- if (Object.keys(curNode.children).includes(p)) {
44
- parentPatterns.push(...curNode.patterns);
45
- curNode = curNode.children[p];
46
- continue;
29
+ this.patterns = [];
30
+ this.handlerSetCache = {};
31
+ }
32
+ insert(method, path, handler) {
33
+ this.name = `${method} ${path}`;
34
+ this.order = ++this.order;
35
+ let curNode = this;
36
+ const parts = splitPath(path);
37
+ const parentPatterns = [];
38
+ const errorMessage = (name) => {
39
+ return `Duplicate param name, use another name instead of '${name}' - ${method} ${path} <--- '${name}'`;
40
+ };
41
+ for (let i = 0, len = parts.length; i < len; i++) {
42
+ const p = parts[i];
43
+ if (Object.keys(curNode.children).includes(p)) {
44
+ parentPatterns.push(...curNode.patterns);
45
+ curNode = curNode.children[p];
46
+ continue;
47
+ }
48
+ curNode.children[p] = new Node();
49
+ const pattern = getPattern(p);
50
+ if (pattern) {
51
+ if (typeof pattern === "object") {
52
+ for (let j = 0, len2 = parentPatterns.length; j < len2; j++) {
53
+ if (typeof parentPatterns[j] === "object" && parentPatterns[j][1] === pattern[1]) {
54
+ throw new Error(errorMessage(pattern[1]));
47
55
  }
48
- curNode.children[p] = new Node();
49
- const pattern = getPattern(p);
50
- if (pattern) {
51
- if (typeof pattern === 'object') {
52
- for (let j = 0, len = parentPatterns.length; j < len; j++) {
53
- if (typeof parentPatterns[j] === 'object' && parentPatterns[j][1] === pattern[1]) {
54
- throw new Error(errorMessage(pattern[1]));
55
- }
56
- }
57
- if (Object.values(curNode.children).some((n) => findParam(n, pattern[1]))) {
58
- throw new Error(errorMessage(pattern[1]));
59
- }
60
- }
61
- curNode.patterns.push(pattern);
62
- parentPatterns.push(...curNode.patterns);
63
- }
64
- parentPatterns.push(...curNode.patterns);
65
- curNode = curNode.children[p];
66
- }
67
- if (!curNode.methods.length) {
68
- curNode.methods = [];
56
+ }
57
+ if (Object.values(curNode.children).some((n) => findParam(n, pattern[1]))) {
58
+ throw new Error(errorMessage(pattern[1]));
59
+ }
69
60
  }
70
- const m = {};
71
- const handlerSet = { handler: handler, name: this.name, score: this.order };
72
- m[method] = handlerSet;
73
- curNode.methods.push(m);
74
- return curNode;
61
+ curNode.patterns.push(pattern);
62
+ parentPatterns.push(...curNode.patterns);
63
+ }
64
+ parentPatterns.push(...curNode.patterns);
65
+ curNode = curNode.children[p];
75
66
  }
76
- getHandlerSets(node, method, wildcard) {
77
- var _a, _b;
78
- return ((_a = node.handlerSetCache)[_b = `${method}:${wildcard ? '1' : '0'}`] || (_a[_b] = (() => {
79
- const handlerSets = [];
80
- for (let i = 0, len = node.methods.length; i < len; i++) {
81
- const m = node.methods[i];
82
- const handlerSet = m[method] || m[METHOD_NAME_ALL];
83
- if (handlerSet !== undefined) {
84
- handlerSets.push(handlerSet);
85
- }
86
- }
87
- return handlerSets;
88
- })()));
67
+ if (!curNode.methods.length) {
68
+ curNode.methods = [];
89
69
  }
90
- search(method, path) {
91
- const handlerSets = [];
92
- const params = {};
93
- // eslint-disable-next-line @typescript-eslint/no-this-alias
94
- const curNode = this;
95
- let curNodes = [curNode];
96
- const parts = splitPath(path);
97
- for (let i = 0, len = parts.length; i < len; i++) {
98
- const part = parts[i];
99
- const isLast = i === len - 1;
100
- const tempNodes = [];
101
- let matched = false;
102
- for (let j = 0, len2 = curNodes.length; j < len2; j++) {
103
- const node = curNodes[j];
104
- const nextNode = node.children[part];
105
- if (nextNode) {
106
- if (isLast === true) {
107
- // '/hello/*' => match '/hello'
108
- if (nextNode.children['*']) {
109
- handlerSets.push(...this.getHandlerSets(nextNode.children['*'], method, true));
110
- }
111
- handlerSets.push(...this.getHandlerSets(nextNode, method));
112
- matched = true;
113
- }
114
- else {
115
- tempNodes.push(nextNode);
116
- }
117
- }
118
- for (let k = 0, len3 = node.patterns.length; k < len3; k++) {
119
- const pattern = node.patterns[k];
120
- // Wildcard
121
- // '/hello/*/foo' => match /hello/bar/foo
122
- if (pattern === '*') {
123
- const astNode = node.children['*'];
124
- if (astNode) {
125
- handlerSets.push(...this.getHandlerSets(astNode, method));
126
- tempNodes.push(astNode);
127
- }
128
- continue;
129
- }
130
- if (part === '')
131
- continue;
132
- // Named match
133
- // `/posts/:id` => match /posts/123
134
- const [key, name, matcher] = pattern;
135
- if (matcher === true || (matcher instanceof RegExp && matcher.test(part))) {
136
- if (typeof key === 'string') {
137
- if (isLast === true) {
138
- handlerSets.push(...this.getHandlerSets(node.children[key], method));
139
- }
140
- else {
141
- tempNodes.push(node.children[key]);
142
- }
143
- }
144
- // '/book/a' => not-slug
145
- // '/book/:slug' => slug
146
- // GET /book/a ~> no-slug, param['slug'] => undefined
147
- // GET /book/foo ~> slug, param['slug'] => foo
148
- if (typeof name === 'string' && !matched) {
149
- params[name] = part;
150
- }
151
- }
152
- }
70
+ const m = {};
71
+ const handlerSet = { handler, name: this.name, score: this.order };
72
+ m[method] = handlerSet;
73
+ curNode.methods.push(m);
74
+ return curNode;
75
+ }
76
+ getHandlerSets(node, method, wildcard) {
77
+ var _a, _b;
78
+ return (_a = node.handlerSetCache)[_b = `${method}:${wildcard ? "1" : "0"}`] || (_a[_b] = (() => {
79
+ const handlerSets = [];
80
+ for (let i = 0, len = node.methods.length; i < len; i++) {
81
+ const m = node.methods[i];
82
+ const handlerSet = m[method] || m[METHOD_NAME_ALL];
83
+ if (handlerSet !== void 0) {
84
+ handlerSets.push(handlerSet);
85
+ }
86
+ }
87
+ return handlerSets;
88
+ })());
89
+ }
90
+ search(method, path) {
91
+ const handlerSets = [];
92
+ const params = {};
93
+ const curNode = this;
94
+ let curNodes = [curNode];
95
+ const parts = splitPath(path);
96
+ for (let i = 0, len2 = parts.length; i < len2; i++) {
97
+ const part = parts[i];
98
+ const isLast = i === len2 - 1;
99
+ const tempNodes = [];
100
+ let matched = false;
101
+ for (let j = 0, len22 = curNodes.length; j < len22; j++) {
102
+ const node = curNodes[j];
103
+ const nextNode = node.children[part];
104
+ if (nextNode) {
105
+ if (isLast === true) {
106
+ if (nextNode.children["*"]) {
107
+ handlerSets.push(...this.getHandlerSets(nextNode.children["*"], method, true));
108
+ }
109
+ handlerSets.push(...this.getHandlerSets(nextNode, method));
110
+ matched = true;
111
+ } else {
112
+ tempNodes.push(nextNode);
113
+ }
114
+ }
115
+ for (let k = 0, len3 = node.patterns.length; k < len3; k++) {
116
+ const pattern = node.patterns[k];
117
+ if (pattern === "*") {
118
+ const astNode = node.children["*"];
119
+ if (astNode) {
120
+ handlerSets.push(...this.getHandlerSets(astNode, method));
121
+ tempNodes.push(astNode);
153
122
  }
154
- curNodes = tempNodes;
123
+ continue;
124
+ }
125
+ if (part === "")
126
+ continue;
127
+ const [key, name, matcher] = pattern;
128
+ if (matcher === true || matcher instanceof RegExp && matcher.test(part)) {
129
+ if (typeof key === "string") {
130
+ if (isLast === true) {
131
+ handlerSets.push(...this.getHandlerSets(node.children[key], method));
132
+ } else {
133
+ tempNodes.push(node.children[key]);
134
+ }
135
+ }
136
+ if (typeof name === "string" && !matched) {
137
+ params[name] = part;
138
+ }
139
+ }
155
140
  }
156
- const len = handlerSets.length;
157
- if (len === 0)
158
- return null;
159
- if (len === 1)
160
- return { handlers: [handlerSets[0].handler], params };
161
- const handlers = handlerSets
162
- .sort((a, b) => {
163
- return a.score - b.score;
164
- })
165
- .map((s) => {
166
- return s.handler;
167
- });
168
- return { handlers, params };
141
+ }
142
+ curNodes = tempNodes;
169
143
  }
170
- }
144
+ const len = handlerSets.length;
145
+ if (len === 0)
146
+ return null;
147
+ if (len === 1)
148
+ return { handlers: [handlerSets[0].handler], params };
149
+ const handlers = handlerSets.sort((a, b) => {
150
+ return a.score - b.score;
151
+ }).map((s) => {
152
+ return s.handler;
153
+ });
154
+ return { handlers, params };
155
+ }
156
+ };
157
+ export {
158
+ Node
159
+ };
@@ -1,20 +1,24 @@
1
- import { checkOptionalParameter } from '../../utils/url';
2
- import { Node } from './node';
3
- export class TrieRouter {
4
- constructor() {
5
- this.node = new Node();
1
+ // src/router/trie-router/router.ts
2
+ import { checkOptionalParameter } from "../../utils/url.js";
3
+ import { Node } from "./node.js";
4
+ var TrieRouter = class {
5
+ constructor() {
6
+ this.node = new Node();
7
+ }
8
+ add(method, path, handler) {
9
+ const results = checkOptionalParameter(path);
10
+ if (results) {
11
+ for (const p of results) {
12
+ this.node.insert(method, p, handler);
13
+ }
14
+ return;
6
15
  }
7
- add(method, path, handler) {
8
- const results = checkOptionalParameter(path);
9
- if (results) {
10
- for (const p of results) {
11
- this.node.insert(method, p, handler);
12
- }
13
- return;
14
- }
15
- this.node.insert(method, path, handler);
16
- }
17
- match(method, path) {
18
- return this.node.search(method, path);
19
- }
20
- }
16
+ this.node.insert(method, path, handler);
17
+ }
18
+ match(method, path) {
19
+ return this.node.search(method, path);
20
+ }
21
+ };
22
+ export {
23
+ TrieRouter
24
+ };
package/dist/router.js CHANGED
@@ -1,5 +1,12 @@
1
- export const METHOD_NAME_ALL = 'ALL';
2
- export const METHOD_NAME_ALL_LOWERCASE = 'all';
3
- export const METHODS = ['get', 'post', 'put', 'delete', 'head', 'options', 'patch'];
4
- export class UnsupportedPathError extends Error {
5
- }
1
+ // src/router.ts
2
+ var METHOD_NAME_ALL = "ALL";
3
+ var METHOD_NAME_ALL_LOWERCASE = "all";
4
+ var METHODS = ["get", "post", "put", "delete", "head", "options", "patch"];
5
+ var UnsupportedPathError = class extends Error {
6
+ };
7
+ export {
8
+ METHODS,
9
+ METHOD_NAME_ALL,
10
+ METHOD_NAME_ALL_LOWERCASE,
11
+ UnsupportedPathError
12
+ };
@@ -0,0 +1,22 @@
1
+ import type { Context } from './context';
2
+ import type { Schema } from './validator/schema';
3
+ export interface ContextVariableMap {
4
+ }
5
+ export declare type Bindings = Record<string, any>;
6
+ export declare type Variables = Record<string, any>;
7
+ export declare type Environment = {
8
+ Bindings: Bindings;
9
+ Variables: Variables;
10
+ };
11
+ export declare type Handler<P extends string = string, E extends Partial<Environment> = Environment, S extends Partial<Schema> = Schema> = (c: Context<P, E, S>, next: Next) => Response | Promise<Response | undefined | void>;
12
+ export declare type MiddlewareHandler<P extends string = string, E extends Partial<Environment> = Environment, S extends Partial<Schema> = Schema> = (c: Context<P, E, S>, next: Next) => Promise<Response | undefined | void>;
13
+ export declare type NotFoundHandler<P extends string = string, E extends Partial<Environment> = Environment, S extends Partial<Schema> = Schema> = (c: Context<P, E, S>) => Response | Promise<Response>;
14
+ export declare type ErrorHandler<P extends string = string, E extends Partial<Environment> = Environment, S extends Partial<Schema> = Schema> = (err: Error, c: Context<P, E, S>) => Response;
15
+ export declare type Next = () => Promise<void>;
16
+ declare type ParamKeyName<NameWithPattern> = NameWithPattern extends `${infer Name}{${infer _Pattern}` ? Name : NameWithPattern;
17
+ declare type ParamKey<Component> = Component extends `:${infer NameWithPattern}` ? ParamKeyName<NameWithPattern> : never;
18
+ export declare type ParamKeys<Path> = Path extends `${infer Component}/${infer Rest}` ? ParamKey<Component> | ParamKeys<Rest> : ParamKey<Path>;
19
+ export interface CustomHandler<P extends string | Partial<Environment> | Schema = string, E = Partial<Environment> | Partial<Schema>, S = Partial<Schema>> {
20
+ (c: Context<P extends string ? P : P extends Partial<Environment> ? string : P extends Partial<Schema> ? string : never, P extends Partial<Environment> ? P : P extends Partial<Schema> ? Partial<Environment> : E extends Partial<Environment> ? E extends Partial<Schema> ? Environment : E : E extends Partial<Schema> ? Partial<Environment> : Environment, P extends Partial<Schema> ? P : E extends Partial<Schema> ? P extends Partial<Environment> ? E extends Partial<Environment> ? unknown : E : unknown : S extends Partial<Schema> ? S : never>, next: Next): Response | Promise<Response | undefined | void>;
21
+ }
22
+ export {};
package/dist/types.js ADDED
File without changes
@@ -1,14 +1,16 @@
1
- export async function parseBody(r) {
2
- let body = {};
3
- const contentType = r.headers.get('Content-Type');
4
- if (contentType &&
5
- (contentType.startsWith('multipart/form-data') ||
6
- contentType === 'application/x-www-form-urlencoded')) {
7
- const form = {};
8
- body = [...(await r.formData())].reduce((acc, cur) => {
9
- acc[cur[0]] = cur[1];
10
- return acc;
11
- }, form);
12
- }
13
- return body;
1
+ // src/utils/body.ts
2
+ async function parseBody(r) {
3
+ let body = {};
4
+ const contentType = r.headers.get("Content-Type");
5
+ if (contentType && (contentType.startsWith("multipart/form-data") || contentType === "application/x-www-form-urlencoded")) {
6
+ const form = {};
7
+ body = [...await r.formData()].reduce((acc, cur) => {
8
+ acc[cur[0]] = cur[1];
9
+ return acc;
10
+ }, form);
11
+ }
12
+ return body;
14
13
  }
14
+ export {
15
+ parseBody
16
+ };
@@ -1,33 +1,39 @@
1
- import { sha256 } from './crypto';
2
- export const equal = (a, b) => {
3
- if (a === b) {
4
- return true;
5
- }
6
- if (a.byteLength !== b.byteLength) {
7
- return false;
8
- }
9
- const va = new DataView(a);
10
- const vb = new DataView(b);
11
- let i = va.byteLength;
12
- while (i--) {
13
- if (va.getUint8(i) !== vb.getUint8(i)) {
14
- return false;
15
- }
16
- }
1
+ // src/utils/buffer.ts
2
+ import { sha256 } from "./crypto.js";
3
+ var equal = (a, b) => {
4
+ if (a === b) {
17
5
  return true;
18
- };
19
- export const timingSafeEqual = async (a, b, hashFunction) => {
20
- if (!hashFunction) {
21
- hashFunction = sha256;
6
+ }
7
+ if (a.byteLength !== b.byteLength) {
8
+ return false;
9
+ }
10
+ const va = new DataView(a);
11
+ const vb = new DataView(b);
12
+ let i = va.byteLength;
13
+ while (i--) {
14
+ if (va.getUint8(i) !== vb.getUint8(i)) {
15
+ return false;
22
16
  }
23
- const sa = await hashFunction(a);
24
- const sb = await hashFunction(b);
25
- return sa === sb && a === b;
17
+ }
18
+ return true;
26
19
  };
27
- export const bufferToString = (buffer) => {
28
- if (buffer instanceof ArrayBuffer) {
29
- const enc = new TextDecoder('utf-8');
30
- return enc.decode(buffer);
31
- }
32
- return buffer;
20
+ var timingSafeEqual = async (a, b, hashFunction) => {
21
+ if (!hashFunction) {
22
+ hashFunction = sha256;
23
+ }
24
+ const sa = await hashFunction(a);
25
+ const sb = await hashFunction(b);
26
+ return sa === sb && a === b;
27
+ };
28
+ var bufferToString = (buffer) => {
29
+ if (buffer instanceof ArrayBuffer) {
30
+ const enc = new TextDecoder("utf-8");
31
+ return enc.decode(buffer);
32
+ }
33
+ return buffer;
34
+ };
35
+ export {
36
+ bufferToString,
37
+ equal,
38
+ timingSafeEqual
33
39
  };
@@ -1,35 +1,35 @@
1
- export const getContentFromKVAsset = async (path, options) => {
2
- let ASSET_MANIFEST = {};
3
- if (options && options.manifest) {
4
- if (typeof options.manifest === 'string') {
5
- ASSET_MANIFEST = JSON.parse(options.manifest);
6
- }
7
- else {
8
- ASSET_MANIFEST = options.manifest;
9
- }
1
+ // src/utils/cloudflare.ts
2
+ var getContentFromKVAsset = async (path, options) => {
3
+ let ASSET_MANIFEST = {};
4
+ if (options && options.manifest) {
5
+ if (typeof options.manifest === "string") {
6
+ ASSET_MANIFEST = JSON.parse(options.manifest);
7
+ } else {
8
+ ASSET_MANIFEST = options.manifest;
10
9
  }
11
- else {
12
- if (typeof __STATIC_CONTENT_MANIFEST === 'string') {
13
- ASSET_MANIFEST = JSON.parse(__STATIC_CONTENT_MANIFEST);
14
- }
15
- else {
16
- ASSET_MANIFEST = __STATIC_CONTENT_MANIFEST;
17
- }
10
+ } else {
11
+ if (typeof __STATIC_CONTENT_MANIFEST === "string") {
12
+ ASSET_MANIFEST = JSON.parse(__STATIC_CONTENT_MANIFEST);
13
+ } else {
14
+ ASSET_MANIFEST = __STATIC_CONTENT_MANIFEST;
18
15
  }
19
- let ASSET_NAMESPACE;
20
- if (options && options.namespace) {
21
- ASSET_NAMESPACE = options.namespace;
22
- }
23
- else {
24
- ASSET_NAMESPACE = __STATIC_CONTENT;
25
- }
26
- const key = ASSET_MANIFEST[path] || path;
27
- if (!key) {
28
- return null;
29
- }
30
- let content = await ASSET_NAMESPACE.get(key, { type: 'arrayBuffer' });
31
- if (content) {
32
- content = content;
33
- }
34
- return content;
16
+ }
17
+ let ASSET_NAMESPACE;
18
+ if (options && options.namespace) {
19
+ ASSET_NAMESPACE = options.namespace;
20
+ } else {
21
+ ASSET_NAMESPACE = __STATIC_CONTENT;
22
+ }
23
+ const key = ASSET_MANIFEST[path] || path;
24
+ if (!key) {
25
+ return null;
26
+ }
27
+ let content = await ASSET_NAMESPACE.get(key, { type: "arrayBuffer" });
28
+ if (content) {
29
+ content = content;
30
+ }
31
+ return content;
32
+ };
33
+ export {
34
+ getContentFromKVAsset
35
35
  };