hono 2.3.1 → 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.
- package/dist/cjs/compose.js +82 -66
- package/dist/cjs/context.js +159 -144
- package/dist/cjs/hono.js +173 -150
- package/dist/cjs/index.js +31 -11
- package/dist/cjs/middleware/basic-auth/index.js +70 -39
- package/dist/cjs/middleware/bearer-auth/index.js +69 -51
- package/dist/cjs/middleware/cache/index.js +49 -28
- package/dist/cjs/middleware/compress/index.js +39 -16
- package/dist/cjs/middleware/cors/index.js +89 -71
- package/dist/cjs/middleware/etag/index.js +46 -24
- package/dist/cjs/middleware/html/index.js +50 -30
- package/dist/cjs/middleware/jsx/index.js +178 -166
- package/dist/cjs/middleware/jsx/jsx-dev-runtime.js +30 -7
- package/dist/cjs/middleware/jsx/jsx-runtime.js +30 -6
- package/dist/cjs/middleware/jwt/index.js +74 -54
- package/dist/cjs/middleware/logger/index.js +59 -38
- package/dist/cjs/middleware/powered-by/index.js +30 -7
- package/dist/cjs/middleware/pretty-json/index.js +31 -8
- package/dist/cjs/middleware/serve-static/bun.js +56 -38
- package/dist/cjs/middleware/serve-static/index.js +27 -4
- package/dist/cjs/middleware/serve-static/module.js +42 -0
- package/dist/cjs/middleware/serve-static/serve-static.js +58 -39
- package/dist/cjs/middleware/validator/index.js +27 -4
- package/dist/cjs/middleware/validator/middleware.js +125 -91
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/request.js +129 -116
- package/dist/cjs/router/reg-exp-router/index.js +27 -4
- package/dist/cjs/router/reg-exp-router/node.js +108 -97
- package/dist/cjs/router/reg-exp-router/router.js +158 -141
- package/dist/cjs/router/reg-exp-router/trie.js +55 -39
- package/dist/cjs/router/smart-router/index.js +27 -4
- package/dist/cjs/router/smart-router/router.js +70 -49
- package/dist/cjs/router/static-router/index.js +27 -4
- package/dist/cjs/router/static-router/router.js +78 -64
- package/dist/cjs/router/trie-router/index.js +27 -4
- package/dist/cjs/router/trie-router/node.js +167 -159
- package/dist/cjs/router/trie-router/router.js +43 -20
- package/dist/cjs/router.js +35 -6
- package/dist/cjs/types.js +16 -0
- package/dist/cjs/utils/body.js +36 -15
- package/dist/cjs/utils/buffer.js +56 -31
- package/dist/cjs/utils/cloudflare.js +53 -34
- package/dist/cjs/utils/cookie.js +59 -35
- package/dist/cjs/utils/crypto.js +69 -43
- package/dist/cjs/utils/encode.js +92 -65
- package/dist/cjs/utils/filepath.js +39 -22
- package/dist/cjs/utils/html.js +54 -33
- package/dist/cjs/utils/http-status.js +68 -45
- package/dist/cjs/utils/json.js +91 -76
- package/dist/cjs/utils/jwt/index.js +32 -25
- package/dist/cjs/utils/jwt/jwt.js +124 -93
- package/dist/cjs/utils/jwt/types.js +65 -38
- package/dist/cjs/utils/mime.js +110 -87
- package/dist/cjs/utils/object.js +53 -35
- package/dist/cjs/utils/types.js +16 -0
- package/dist/cjs/utils/url.js +89 -78
- package/dist/cjs/validator/rule.js +80 -0
- package/dist/cjs/validator/sanitizer.js +30 -0
- package/dist/cjs/validator/schema.js +16 -0
- package/dist/cjs/validator/validator.js +439 -0
- package/dist/compose.d.ts +4 -3
- package/dist/compose.js +61 -64
- package/dist/context.d.ts +10 -9
- package/dist/context.js +139 -143
- package/dist/hono.d.ts +27 -42
- package/dist/hono.js +153 -149
- package/dist/index.d.ts +4 -1
- package/dist/index.js +9 -9
- package/dist/middleware/basic-auth/index.d.ts +1 -1
- package/dist/middleware/basic-auth/index.js +52 -40
- package/dist/middleware/bearer-auth/index.d.ts +1 -1
- package/dist/middleware/bearer-auth/index.js +48 -49
- package/dist/middleware/cache/index.d.ts +1 -1
- package/dist/middleware/cache/index.js +28 -26
- package/dist/middleware/compress/index.d.ts +1 -1
- package/dist/middleware/compress/index.js +18 -14
- package/dist/middleware/cors/index.d.ts +1 -1
- package/dist/middleware/cors/index.js +68 -69
- package/dist/middleware/etag/index.d.ts +1 -1
- package/dist/middleware/etag/index.js +25 -22
- package/dist/middleware/html/index.js +29 -28
- package/dist/middleware/jsx/index.js +164 -172
- package/dist/middleware/jsx/jsx-dev-runtime.js +9 -5
- package/dist/middleware/jsx/jsx-runtime.js +7 -2
- package/dist/middleware/jwt/index.d.ts +1 -1
- package/dist/middleware/jwt/index.js +53 -52
- package/dist/middleware/logger/index.d.ts +1 -1
- package/dist/middleware/logger/index.js +35 -39
- package/dist/middleware/powered-by/index.d.ts +1 -1
- package/dist/middleware/powered-by/index.js +9 -5
- package/dist/middleware/pretty-json/index.d.ts +1 -1
- package/dist/middleware/pretty-json/index.js +10 -6
- package/dist/middleware/serve-static/bun.d.ts +1 -1
- package/dist/middleware/serve-static/bun.js +35 -36
- package/dist/middleware/serve-static/index.js +5 -1
- package/dist/middleware/serve-static/module.d.ts +3 -0
- package/dist/middleware/serve-static/module.js +13 -0
- package/dist/middleware/serve-static/serve-static.d.ts +2 -3
- package/dist/middleware/serve-static/serve-static.js +36 -36
- package/dist/middleware/validator/index.js +5 -2
- package/dist/middleware/validator/middleware.d.ts +9 -15
- package/dist/middleware/validator/middleware.js +104 -89
- package/dist/request.d.ts +2 -2
- package/dist/request.js +108 -114
- package/dist/router/reg-exp-router/index.js +5 -1
- package/dist/router/reg-exp-router/node.js +87 -96
- package/dist/router/reg-exp-router/router.js +140 -142
- package/dist/router/reg-exp-router/trie.js +35 -38
- package/dist/router/smart-router/index.js +5 -1
- package/dist/router/smart-router/router.js +50 -48
- package/dist/router/static-router/index.js +5 -1
- package/dist/router/static-router/router.js +58 -63
- package/dist/router/trie-router/index.js +5 -1
- package/dist/router/trie-router/node.js +147 -158
- package/dist/router/trie-router/router.js +23 -19
- package/dist/router.js +12 -5
- package/dist/types.d.ts +22 -0
- package/dist/types.js +0 -0
- package/dist/utils/body.js +15 -13
- package/dist/utils/buffer.js +35 -29
- package/dist/utils/cloudflare.js +32 -32
- package/dist/utils/cookie.js +38 -33
- package/dist/utils/crypto.js +48 -41
- package/dist/utils/encode.js +70 -62
- package/dist/utils/filepath.js +18 -20
- package/dist/utils/html.js +34 -32
- package/dist/utils/http-status.js +48 -44
- package/dist/utils/json.js +71 -75
- package/dist/utils/jwt/index.js +5 -1
- package/dist/utils/jwt/jwt.js +95 -90
- package/dist/utils/jwt/types.js +47 -41
- package/dist/utils/mime.js +90 -86
- package/dist/utils/object.js +31 -32
- package/dist/utils/types.d.ts +3 -0
- package/dist/utils/types.js +0 -0
- package/dist/utils/url.js +69 -77
- package/dist/{middleware/validator → validator}/rule.d.ts +0 -0
- package/dist/validator/rule.js +57 -0
- package/dist/{middleware/validator → validator}/sanitizer.d.ts +0 -0
- package/dist/validator/sanitizer.js +7 -0
- package/dist/validator/schema.d.ts +7 -0
- package/dist/validator/schema.js +0 -0
- package/dist/{middleware/validator → validator}/validator.d.ts +10 -7
- package/dist/validator/validator.js +406 -0
- package/package.json +14 -8
- package/dist/cjs/middleware/validator/rule.js +0 -66
- package/dist/cjs/middleware/validator/sanitizer.js +0 -6
- package/dist/cjs/middleware/validator/validator.js +0 -417
- package/dist/middleware/serve-static/module.d.mts +0 -3
- package/dist/middleware/serve-static/module.mjs +0 -13
- package/dist/middleware/validator/rule.js +0 -63
- package/dist/middleware/validator/sanitizer.js +0 -3
- package/dist/middleware/validator/validator.js +0 -403
|
@@ -1,417 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.VBooleanArray = exports.VStringArray = exports.VNumberArray = exports.VBoolean = exports.VNumber = exports.VString = exports.VBase = exports.Validator = exports.VArray = exports.VObject = exports.VObjectBase = void 0;
|
|
4
|
-
const json_1 = require("../../utils/json");
|
|
5
|
-
const rule_1 = require("./rule");
|
|
6
|
-
const sanitizer_1 = require("./sanitizer");
|
|
7
|
-
class VObjectBase {
|
|
8
|
-
constructor(container, key) {
|
|
9
|
-
this.keys = [];
|
|
10
|
-
this._isOptional = false;
|
|
11
|
-
this.getValidators = () => {
|
|
12
|
-
const validators = [];
|
|
13
|
-
const thisKeys = [];
|
|
14
|
-
Object.assign(thisKeys, this.keys);
|
|
15
|
-
const walk = (container, keys, isOptional) => {
|
|
16
|
-
for (const v of Object.values(container)) {
|
|
17
|
-
if (v instanceof VArray || v instanceof VObject) {
|
|
18
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
19
|
-
// @ts-ignore
|
|
20
|
-
isOptional || (isOptional = v._isOptional);
|
|
21
|
-
keys.push(...v.keys);
|
|
22
|
-
walk(v.container, keys, isOptional);
|
|
23
|
-
const tmp = [];
|
|
24
|
-
Object.assign(tmp, thisKeys);
|
|
25
|
-
keys = tmp;
|
|
26
|
-
}
|
|
27
|
-
else if (v instanceof VBase) {
|
|
28
|
-
if (isOptional)
|
|
29
|
-
v.isOptional();
|
|
30
|
-
v.baseKeys.push(...keys);
|
|
31
|
-
validators.push(v);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
walk(this.container, this.keys, this._isOptional);
|
|
36
|
-
return validators;
|
|
37
|
-
};
|
|
38
|
-
this.container = container;
|
|
39
|
-
if (this instanceof VArray) {
|
|
40
|
-
this.keys.push(key, '[*]');
|
|
41
|
-
}
|
|
42
|
-
else if (this instanceof VObject) {
|
|
43
|
-
this.keys.push(key);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
isOptional() {
|
|
47
|
-
this._isOptional = true;
|
|
48
|
-
return this;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
exports.VObjectBase = VObjectBase;
|
|
52
|
-
class VObject extends VObjectBase {
|
|
53
|
-
constructor(container, key) {
|
|
54
|
-
super(container, key);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
exports.VObject = VObject;
|
|
58
|
-
class VArray extends VObjectBase {
|
|
59
|
-
constructor(container, key) {
|
|
60
|
-
super(container, key);
|
|
61
|
-
this.type = 'array';
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
exports.VArray = VArray;
|
|
65
|
-
class Validator {
|
|
66
|
-
constructor() {
|
|
67
|
-
this.isArray = false;
|
|
68
|
-
this.query = (key) => new VString({ target: 'query', key: key });
|
|
69
|
-
this.header = (key) => new VString({ target: 'header', key: key });
|
|
70
|
-
this.body = (key) => new VString({ target: 'body', key: key });
|
|
71
|
-
this.json = (key) => {
|
|
72
|
-
if (this.isArray) {
|
|
73
|
-
return new VStringArray({ target: 'json', key: key });
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
return new VString({ target: 'json', key: key });
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
this.array = (path, validator) => {
|
|
80
|
-
this.isArray = true;
|
|
81
|
-
const res = validator(this);
|
|
82
|
-
const arr = new VArray(res, path);
|
|
83
|
-
return arr;
|
|
84
|
-
};
|
|
85
|
-
this.object = (path, validator) => {
|
|
86
|
-
this.isArray = false;
|
|
87
|
-
const res = validator(this);
|
|
88
|
-
const obj = new VObject(res, path);
|
|
89
|
-
return obj;
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
exports.Validator = Validator;
|
|
94
|
-
class VBase {
|
|
95
|
-
constructor(options) {
|
|
96
|
-
this.baseKeys = [];
|
|
97
|
-
this._nested = () => (this.baseKeys.length ? true : false);
|
|
98
|
-
this.addSanitizer = (sanitizer) => {
|
|
99
|
-
this.sanitizers.push(sanitizer);
|
|
100
|
-
return this;
|
|
101
|
-
};
|
|
102
|
-
this.message = (text) => {
|
|
103
|
-
const len = this.rules.length;
|
|
104
|
-
if (len >= 1) {
|
|
105
|
-
this.rules[len - 1].customMessage = text;
|
|
106
|
-
}
|
|
107
|
-
return this;
|
|
108
|
-
};
|
|
109
|
-
this.isRequired = () => {
|
|
110
|
-
return this.addRule('isRequired', (value) => {
|
|
111
|
-
if (value !== undefined && value !== null && value !== '')
|
|
112
|
-
return true;
|
|
113
|
-
return false;
|
|
114
|
-
});
|
|
115
|
-
};
|
|
116
|
-
this.isOptional = () => {
|
|
117
|
-
this._optional = true;
|
|
118
|
-
return this.addRule('isOptional', () => true);
|
|
119
|
-
};
|
|
120
|
-
this.isEqual = (comparison) => {
|
|
121
|
-
return this.addRule('isEqual', (value) => {
|
|
122
|
-
return value === comparison;
|
|
123
|
-
});
|
|
124
|
-
};
|
|
125
|
-
this.asNumber = () => {
|
|
126
|
-
const newVNumber = new VNumber({ ...this, type: 'number' });
|
|
127
|
-
if (this.isArray)
|
|
128
|
-
return newVNumber.asArray();
|
|
129
|
-
return newVNumber;
|
|
130
|
-
};
|
|
131
|
-
this.asBoolean = () => {
|
|
132
|
-
const newVBoolean = new VBoolean({ ...this, type: 'boolean' });
|
|
133
|
-
if (this.isArray)
|
|
134
|
-
return newVBoolean.asArray();
|
|
135
|
-
return newVBoolean;
|
|
136
|
-
};
|
|
137
|
-
this.validate = async (req) => {
|
|
138
|
-
let value = undefined;
|
|
139
|
-
let jsonData = undefined;
|
|
140
|
-
if (this.target === 'query') {
|
|
141
|
-
value = req.query(this.key);
|
|
142
|
-
}
|
|
143
|
-
if (this.target === 'header') {
|
|
144
|
-
value = req.header(this.key);
|
|
145
|
-
}
|
|
146
|
-
if (this.target === 'body') {
|
|
147
|
-
const body = await req.parseBody();
|
|
148
|
-
value = body[this.key];
|
|
149
|
-
}
|
|
150
|
-
if (this.target === 'json') {
|
|
151
|
-
if (this._nested()) {
|
|
152
|
-
this.key = `${this.baseKeys.join('.')}.${this.key}`;
|
|
153
|
-
}
|
|
154
|
-
let obj = {};
|
|
155
|
-
try {
|
|
156
|
-
obj = (await req.json());
|
|
157
|
-
}
|
|
158
|
-
catch (e) {
|
|
159
|
-
throw new Error('Malformed JSON in request body');
|
|
160
|
-
}
|
|
161
|
-
const dst = {};
|
|
162
|
-
value = (0, json_1.JSONPathCopy)(obj, dst, this.key);
|
|
163
|
-
if (this._nested())
|
|
164
|
-
jsonData = dst;
|
|
165
|
-
}
|
|
166
|
-
const results = [];
|
|
167
|
-
let typeRule = this.rules.shift();
|
|
168
|
-
for (const rule of this.rules) {
|
|
169
|
-
if (rule.type === 'type') {
|
|
170
|
-
typeRule = rule;
|
|
171
|
-
}
|
|
172
|
-
else if (rule.type === 'value') {
|
|
173
|
-
const result = this.validateRule(rule, value);
|
|
174
|
-
result.jsonData || (result.jsonData = jsonData);
|
|
175
|
-
results.push(result);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
if (typeRule) {
|
|
179
|
-
const typeResult = this.validateRule(typeRule, value);
|
|
180
|
-
typeResult.jsonData || (typeResult.jsonData = jsonData);
|
|
181
|
-
results.unshift(typeResult);
|
|
182
|
-
}
|
|
183
|
-
return results;
|
|
184
|
-
};
|
|
185
|
-
this.validateType = (value) => {
|
|
186
|
-
if (this.isArray) {
|
|
187
|
-
if (!Array.isArray(value)) {
|
|
188
|
-
return false;
|
|
189
|
-
}
|
|
190
|
-
for (const val of value) {
|
|
191
|
-
if (typeof val === 'undefined' && this._nested()) {
|
|
192
|
-
value.pop();
|
|
193
|
-
}
|
|
194
|
-
for (const val of value) {
|
|
195
|
-
if (typeof val !== this.type) {
|
|
196
|
-
// Value is of wrong type here
|
|
197
|
-
// If it is not optional and not undefined, return false
|
|
198
|
-
if (!this._optional || typeof val !== 'undefined')
|
|
199
|
-
return false;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
else {
|
|
205
|
-
if (typeof value !== this.type) {
|
|
206
|
-
if (this._optional && (typeof value === 'undefined' || Array.isArray(value))) {
|
|
207
|
-
// Do nothing.
|
|
208
|
-
// If it is optional it's OK to be `undefined` or Array
|
|
209
|
-
}
|
|
210
|
-
else {
|
|
211
|
-
return false;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
return true;
|
|
216
|
-
};
|
|
217
|
-
this.validateValue = (func, value) => {
|
|
218
|
-
if (Array.isArray(value)) {
|
|
219
|
-
// Sanitize
|
|
220
|
-
for (const sanitizer of this.sanitizers) {
|
|
221
|
-
value = value.map((innerVal) => sanitizer(innerVal));
|
|
222
|
-
}
|
|
223
|
-
for (const val of value) {
|
|
224
|
-
if (!func(val)) {
|
|
225
|
-
return false;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
return true;
|
|
229
|
-
}
|
|
230
|
-
else {
|
|
231
|
-
// Sanitize
|
|
232
|
-
for (const sanitizer of this.sanitizers) {
|
|
233
|
-
value = sanitizer(value);
|
|
234
|
-
}
|
|
235
|
-
if (!func(value)) {
|
|
236
|
-
return false;
|
|
237
|
-
}
|
|
238
|
-
return true;
|
|
239
|
-
}
|
|
240
|
-
};
|
|
241
|
-
this.getMessage = (opts) => {
|
|
242
|
-
let keyText;
|
|
243
|
-
const valueText = Array.isArray(opts.value)
|
|
244
|
-
? `${opts.value
|
|
245
|
-
.map((val) => val === undefined ? 'undefined' : typeof val === 'string' ? `"${val}"` : val)
|
|
246
|
-
.join(', ')}`
|
|
247
|
-
: opts.value;
|
|
248
|
-
switch (this.target) {
|
|
249
|
-
case 'query':
|
|
250
|
-
keyText = `the query parameter "${this.key}"`;
|
|
251
|
-
break;
|
|
252
|
-
case 'header':
|
|
253
|
-
keyText = `the request header "${this.key}"`;
|
|
254
|
-
break;
|
|
255
|
-
case 'body':
|
|
256
|
-
keyText = `the request body "${this.key}"`;
|
|
257
|
-
break;
|
|
258
|
-
case 'json':
|
|
259
|
-
keyText = `the JSON body "${this.key}"`;
|
|
260
|
-
break;
|
|
261
|
-
}
|
|
262
|
-
return `Invalid Value [${valueText}]: ${keyText} is invalid - ${opts.ruleName}`;
|
|
263
|
-
};
|
|
264
|
-
this.target = options.target;
|
|
265
|
-
this.key = options.key;
|
|
266
|
-
this.type = options.type || 'string';
|
|
267
|
-
this.rules = [
|
|
268
|
-
{
|
|
269
|
-
name: this.getTypeRuleName(),
|
|
270
|
-
type: 'type',
|
|
271
|
-
func: this.validateType,
|
|
272
|
-
},
|
|
273
|
-
];
|
|
274
|
-
this.sanitizers = [];
|
|
275
|
-
this._optional = false;
|
|
276
|
-
this.isArray = options.isArray || false;
|
|
277
|
-
}
|
|
278
|
-
addRule(arg, func) {
|
|
279
|
-
if (typeof arg === 'string' && func) {
|
|
280
|
-
this.rules.push({ name: arg, func, type: 'value' });
|
|
281
|
-
}
|
|
282
|
-
else if (arg instanceof Function) {
|
|
283
|
-
this.rules.push({ name: arg.name, func: arg, type: 'value' });
|
|
284
|
-
}
|
|
285
|
-
return this;
|
|
286
|
-
}
|
|
287
|
-
get(value) {
|
|
288
|
-
const len = this.rules.length;
|
|
289
|
-
if (len > 0) {
|
|
290
|
-
this.rules[this.rules.length - 1].customMessage = value;
|
|
291
|
-
}
|
|
292
|
-
return this;
|
|
293
|
-
}
|
|
294
|
-
getTypeRuleName() {
|
|
295
|
-
const prefix = 'should be';
|
|
296
|
-
return this.isArray ? `${prefix} "${this.type}[]"` : `${prefix} "${this.type}"`;
|
|
297
|
-
}
|
|
298
|
-
validateRule(rule, value) {
|
|
299
|
-
let isValid = false;
|
|
300
|
-
if (this._nested() && this.target != 'json') {
|
|
301
|
-
isValid = false;
|
|
302
|
-
}
|
|
303
|
-
else if (rule.type === 'value') {
|
|
304
|
-
isValid = this.validateValue(rule.func, value);
|
|
305
|
-
}
|
|
306
|
-
else if (rule.type === 'type') {
|
|
307
|
-
isValid = this.validateType(value);
|
|
308
|
-
}
|
|
309
|
-
const message = isValid
|
|
310
|
-
? undefined
|
|
311
|
-
: rule.customMessage || this.getMessage({ ruleName: rule.name, value });
|
|
312
|
-
const result = {
|
|
313
|
-
isValid: isValid,
|
|
314
|
-
message: message,
|
|
315
|
-
target: this.target,
|
|
316
|
-
key: this.key,
|
|
317
|
-
value,
|
|
318
|
-
ruleName: rule.name,
|
|
319
|
-
ruleType: rule.type,
|
|
320
|
-
};
|
|
321
|
-
return result;
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
exports.VBase = VBase;
|
|
325
|
-
class VString extends VBase {
|
|
326
|
-
constructor(options) {
|
|
327
|
-
super(options);
|
|
328
|
-
this.asArray = () => {
|
|
329
|
-
return new VStringArray(this);
|
|
330
|
-
};
|
|
331
|
-
this.isEmpty = (options = { ignore_whitespace: false }) => {
|
|
332
|
-
return this.addRule('isEmpty', (value) => rule_1.rule.isEmpty(value, options));
|
|
333
|
-
};
|
|
334
|
-
this.isLength = (options, arg2) => {
|
|
335
|
-
return this.addRule('isLength', (value) => rule_1.rule.isLength(value, options, arg2));
|
|
336
|
-
};
|
|
337
|
-
this.isAlpha = () => {
|
|
338
|
-
return this.addRule('isAlpha', (value) => rule_1.rule.isAlpha(value));
|
|
339
|
-
};
|
|
340
|
-
this.isNumeric = () => {
|
|
341
|
-
return this.addRule('isNumeric', (value) => rule_1.rule.isNumeric(value));
|
|
342
|
-
};
|
|
343
|
-
this.contains = (elem, options = {
|
|
344
|
-
ignoreCase: false,
|
|
345
|
-
minOccurrences: 1,
|
|
346
|
-
}) => {
|
|
347
|
-
return this.addRule('contains', (value) => rule_1.rule.contains(value, elem, options));
|
|
348
|
-
};
|
|
349
|
-
this.isIn = (options) => {
|
|
350
|
-
return this.addRule('isIn', (value) => rule_1.rule.isIn(value, options));
|
|
351
|
-
};
|
|
352
|
-
this.match = (regExp) => {
|
|
353
|
-
return this.addRule('match', (value) => rule_1.rule.match(value, regExp));
|
|
354
|
-
};
|
|
355
|
-
this.trim = () => {
|
|
356
|
-
return this.addSanitizer((value) => sanitizer_1.sanitizer.trim(value));
|
|
357
|
-
};
|
|
358
|
-
this.type = 'string';
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
exports.VString = VString;
|
|
362
|
-
class VNumber extends VBase {
|
|
363
|
-
constructor(options) {
|
|
364
|
-
super(options);
|
|
365
|
-
this.asArray = () => {
|
|
366
|
-
return new VNumberArray(this);
|
|
367
|
-
};
|
|
368
|
-
this.isGte = (min) => {
|
|
369
|
-
return this.addRule('isGte', (value) => rule_1.rule.isGte(value, min));
|
|
370
|
-
};
|
|
371
|
-
this.isLte = (min) => {
|
|
372
|
-
return this.addRule('isLte', (value) => rule_1.rule.isLte(value, min));
|
|
373
|
-
};
|
|
374
|
-
this.type = 'number';
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
exports.VNumber = VNumber;
|
|
378
|
-
class VBoolean extends VBase {
|
|
379
|
-
constructor(options) {
|
|
380
|
-
super(options);
|
|
381
|
-
this.asArray = () => {
|
|
382
|
-
return new VBooleanArray(this);
|
|
383
|
-
};
|
|
384
|
-
this.isTrue = () => {
|
|
385
|
-
return this.addRule('isTrue', (value) => rule_1.rule.isTrue(value));
|
|
386
|
-
};
|
|
387
|
-
this.isFalse = () => {
|
|
388
|
-
return this.addRule('isFalse', (value) => rule_1.rule.isFalse(value));
|
|
389
|
-
};
|
|
390
|
-
this.type = 'boolean';
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
exports.VBoolean = VBoolean;
|
|
394
|
-
class VNumberArray extends VNumber {
|
|
395
|
-
constructor(options) {
|
|
396
|
-
super(options);
|
|
397
|
-
this.isArray = true;
|
|
398
|
-
this.rules[0].name = this.getTypeRuleName();
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
exports.VNumberArray = VNumberArray;
|
|
402
|
-
class VStringArray extends VString {
|
|
403
|
-
constructor(options) {
|
|
404
|
-
super(options);
|
|
405
|
-
this.isArray = true;
|
|
406
|
-
this.rules[0].name = this.getTypeRuleName();
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
exports.VStringArray = VStringArray;
|
|
410
|
-
class VBooleanArray extends VBoolean {
|
|
411
|
-
constructor(options) {
|
|
412
|
-
super(options);
|
|
413
|
-
this.isArray = true;
|
|
414
|
-
this.rules[0].name = this.getTypeRuleName();
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
exports.VBooleanArray = VBooleanArray;
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { ServeStaticOptions } from './serve-static';
|
|
2
|
-
declare const module: (options?: ServeStaticOptions) => (c: import("../..").Context<string, any, import("../../hono").ValidatedData>, next: import("../..").Next) => Promise<Response | undefined>;
|
|
3
|
-
export { module as serveStatic };
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2
|
-
// @ts-ignore
|
|
3
|
-
// For ES module mode
|
|
4
|
-
import manifest from '__STATIC_CONTENT_MANIFEST';
|
|
5
|
-
import { serveStatic } from './serve-static';
|
|
6
|
-
const module = (options = { root: '' }) => {
|
|
7
|
-
return serveStatic({
|
|
8
|
-
root: options.root,
|
|
9
|
-
path: options.path,
|
|
10
|
-
manifest: options.manifest ? options.manifest : manifest,
|
|
11
|
-
});
|
|
12
|
-
};
|
|
13
|
-
export { module as serveStatic };
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
// Some validation rules is are based on Validator.js
|
|
2
|
-
// Validator.js
|
|
3
|
-
// License (MIT)
|
|
4
|
-
// Copyright (c) 2018 Chris O'Hara <cohara87@gmail.com>
|
|
5
|
-
// https://github.com/validatorjs/validator.js
|
|
6
|
-
export const rule = {
|
|
7
|
-
// string
|
|
8
|
-
isEmpty(value, options = { ignore_whitespace: false }) {
|
|
9
|
-
return (options.ignore_whitespace ? value.trim().length : value.length) === 0;
|
|
10
|
-
},
|
|
11
|
-
isLength: (value, options, arg2) => {
|
|
12
|
-
let min;
|
|
13
|
-
let max;
|
|
14
|
-
if (typeof options === 'object') {
|
|
15
|
-
min = options.min || 0;
|
|
16
|
-
max = options.max;
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
// backwards compatibility: isLength(str, min [, max])
|
|
20
|
-
min = options || 0;
|
|
21
|
-
max = arg2;
|
|
22
|
-
}
|
|
23
|
-
const presentationSequences = value.match(/(\uFE0F|\uFE0E)/g) || [];
|
|
24
|
-
const surrogatePairs = value.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g) || [];
|
|
25
|
-
const len = value.length - presentationSequences.length - surrogatePairs.length;
|
|
26
|
-
return len >= min && (typeof max === 'undefined' || len <= max);
|
|
27
|
-
},
|
|
28
|
-
isAlpha: (value) => {
|
|
29
|
-
return /^[A-Z]+$/i.test(value);
|
|
30
|
-
},
|
|
31
|
-
isNumeric: (value) => {
|
|
32
|
-
return /^[0-9]+$/.test(value);
|
|
33
|
-
},
|
|
34
|
-
contains: (value, elem, options = {
|
|
35
|
-
ignoreCase: false,
|
|
36
|
-
minOccurrences: 1,
|
|
37
|
-
}) => {
|
|
38
|
-
options.ignoreCase || (options.ignoreCase = false);
|
|
39
|
-
options.minOccurrences || (options.minOccurrences = 1);
|
|
40
|
-
if (options.ignoreCase) {
|
|
41
|
-
return value.toLowerCase().split(elem.toLowerCase()).length > options.minOccurrences;
|
|
42
|
-
}
|
|
43
|
-
return value.split(elem).length > options.minOccurrences;
|
|
44
|
-
},
|
|
45
|
-
isIn: (value, options) => {
|
|
46
|
-
if (typeof options === 'object') {
|
|
47
|
-
for (const elem of options) {
|
|
48
|
-
if (elem === value)
|
|
49
|
-
return true;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return false;
|
|
53
|
-
},
|
|
54
|
-
match: (value, regExp) => {
|
|
55
|
-
return regExp.test(value);
|
|
56
|
-
},
|
|
57
|
-
// number
|
|
58
|
-
isGte: (value, min) => min <= value,
|
|
59
|
-
isLte: (value, max) => value <= max,
|
|
60
|
-
// boolean
|
|
61
|
-
isTrue: (value) => value === true,
|
|
62
|
-
isFalse: (value) => value === false,
|
|
63
|
-
};
|