hono 2.7.0 → 3.0.0-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 (37) hide show
  1. package/dist/cjs/compose.js +6 -0
  2. package/dist/cjs/context.js +29 -6
  3. package/dist/cjs/hono.js +21 -6
  4. package/dist/cjs/middleware/cache/index.js +1 -1
  5. package/dist/cjs/middleware/validator/index.js +29 -2
  6. package/dist/cjs/request.js +94 -36
  7. package/dist/compose.js +6 -0
  8. package/dist/context.js +29 -6
  9. package/dist/hono.js +21 -6
  10. package/dist/middleware/cache/index.js +1 -1
  11. package/dist/middleware/validator/index.js +29 -2
  12. package/dist/request.js +94 -36
  13. package/dist/types/compose.d.ts +1 -1
  14. package/dist/types/context.d.ts +25 -9
  15. package/dist/types/hono.d.ts +33 -26
  16. package/dist/types/index.d.ts +2 -4
  17. package/dist/types/middleware/serve-static/module.d.ts +1 -1
  18. package/dist/types/middleware/validator/index.d.ts +8 -2
  19. package/dist/types/request.d.ts +41 -36
  20. package/dist/types/types.d.ts +87 -14
  21. package/dist/types/utils/types.d.ts +1 -0
  22. package/package.json +5 -3
  23. package/dist/cjs/middleware/validator/middleware.js +0 -137
  24. package/dist/cjs/validator/rule.js +0 -94
  25. package/dist/cjs/validator/sanitizer.js +0 -30
  26. package/dist/cjs/validator/schema.js +0 -16
  27. package/dist/cjs/validator/validator.js +0 -441
  28. package/dist/middleware/validator/middleware.js +0 -114
  29. package/dist/types/middleware/validator/middleware.d.ts +0 -15
  30. package/dist/types/validator/rule.d.ts +0 -21
  31. package/dist/types/validator/sanitizer.d.ts +0 -3
  32. package/dist/types/validator/schema.d.ts +0 -10
  33. package/dist/types/validator/validator.d.ts +0 -134
  34. package/dist/validator/rule.js +0 -71
  35. package/dist/validator/sanitizer.js +0 -7
  36. package/dist/validator/schema.js +0 -0
  37. package/dist/validator/validator.js +0 -408
@@ -1,137 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var middleware_exports = {};
20
- __export(middleware_exports, {
21
- validatorMiddleware: () => validatorMiddleware
22
- });
23
- module.exports = __toCommonJS(middleware_exports);
24
- var import_http_status = require("../../utils/http-status");
25
- var import_object = require("../../utils/object");
26
- var import_validator = require("../../validator/validator");
27
- const validatorMiddleware = (validationFunction, options) => {
28
- const v = new import_validator.Validator();
29
- const handler = async (c, next) => {
30
- var _a;
31
- const resultSet = {
32
- hasError: false,
33
- messages: [],
34
- results: []
35
- };
36
- const schema = validationFunction(v, c);
37
- const validatorList = getValidatorList(schema);
38
- let data = {};
39
- for (const [keys, validator] of validatorList) {
40
- let results;
41
- try {
42
- results = await validator.validate(c.req);
43
- } catch (e) {
44
- if (e instanceof Error) {
45
- const result = getErrorResult(e);
46
- resultSet.hasError = true;
47
- resultSet.messages = [result.message || ""];
48
- resultSet.results = [result];
49
- break;
50
- } else {
51
- return c.text((0, import_http_status.getStatusText)(400), 400);
52
- }
53
- }
54
- let isValid = true;
55
- const value = results[0].value;
56
- const jsonData = results[0].jsonData;
57
- for (const result of results) {
58
- if (!result.isValid) {
59
- isValid = false;
60
- resultSet.hasError = true;
61
- if (result.ruleType === "value" && result.message !== void 0) {
62
- resultSet.messages.push(result.message);
63
- }
64
- }
65
- resultSet.results.push(result);
66
- }
67
- if (!isValid && resultSet.messages.length === 0) {
68
- resultSet.results.map((r) => {
69
- if (!r.isValid && r.ruleType === "type" && r.message) {
70
- resultSet.messages.push(r.message);
71
- }
72
- });
73
- }
74
- if (isValid) {
75
- if (jsonData) {
76
- const dst = data;
77
- data = (0, import_object.mergeObjects)(dst, jsonData);
78
- } else {
79
- let tmp = data;
80
- for (let i = 0; i < keys.length - 1; i++) {
81
- tmp = tmp[_a = keys[i]] || (tmp[_a] = {});
82
- }
83
- tmp[keys[keys.length - 1]] = value;
84
- }
85
- }
86
- }
87
- if (!resultSet.hasError) {
88
- c.req.valid(data);
89
- }
90
- if (options && options.done) {
91
- const res = options.done(resultSet, c);
92
- if (res) {
93
- return res;
94
- }
95
- }
96
- if (resultSet.hasError) {
97
- return c.text(resultSet.messages.join("\n"), 400);
98
- }
99
- await next();
100
- };
101
- return handler;
102
- };
103
- function getValidatorList(schema) {
104
- const map = [];
105
- for (const [key, value] of Object.entries(schema)) {
106
- if (value instanceof import_validator.VObjectBase) {
107
- const validators = value.getValidators();
108
- for (const validator of validators) {
109
- map.push([value.keys, validator]);
110
- }
111
- } else if (value instanceof import_validator.VBase) {
112
- map.push([[key], value]);
113
- } else {
114
- const children = getValidatorList(value);
115
- for (const [keys, validator] of children) {
116
- map.push([[key, ...keys], validator]);
117
- }
118
- }
119
- }
120
- return map;
121
- }
122
- const getErrorResult = (e) => {
123
- const result = {
124
- isValid: false,
125
- message: e.message,
126
- target: "unknown",
127
- key: null,
128
- value: null,
129
- ruleName: e.message,
130
- ruleType: "value"
131
- };
132
- return result;
133
- };
134
- // Annotate the CommonJS export names for ESM import in node:
135
- 0 && (module.exports = {
136
- validatorMiddleware
137
- });
@@ -1,94 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var rule_exports = {};
20
- __export(rule_exports, {
21
- rule: () => rule
22
- });
23
- module.exports = __toCommonJS(rule_exports);
24
- const rule = {
25
- isEmpty(value, options = { ignore_whitespace: false }) {
26
- if (value === void 0)
27
- return false;
28
- return (options.ignore_whitespace ? value.trim().length : value.length) === 0;
29
- },
30
- isLength: (value, options, arg2) => {
31
- if (value === void 0)
32
- return false;
33
- let min;
34
- let max;
35
- if (typeof options === "object") {
36
- min = options.min || 0;
37
- max = options.max;
38
- } else {
39
- min = options || 0;
40
- max = arg2;
41
- }
42
- const presentationSequences = value.match(/(\uFE0F|\uFE0E)/g) || [];
43
- const surrogatePairs = value.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g) || [];
44
- const len = value.length - presentationSequences.length - surrogatePairs.length;
45
- return len >= min && (typeof max === "undefined" || len <= max);
46
- },
47
- isAlpha: (value) => {
48
- if (value === void 0)
49
- return false;
50
- return /^[A-Z]+$/i.test(value);
51
- },
52
- isNumeric: (value) => {
53
- if (value === void 0)
54
- return false;
55
- return /^[0-9]+$/.test(value);
56
- },
57
- contains: (value, elem, options = {
58
- ignoreCase: false,
59
- minOccurrences: 1
60
- }) => {
61
- if (value === void 0 || elem === void 0)
62
- return false;
63
- options.ignoreCase || (options.ignoreCase = false);
64
- options.minOccurrences || (options.minOccurrences = 1);
65
- if (options.ignoreCase) {
66
- return value.toLowerCase().split(elem.toLowerCase()).length > options.minOccurrences;
67
- }
68
- return value.split(elem).length > options.minOccurrences;
69
- },
70
- isIn: (value, options) => {
71
- if (value === void 0)
72
- return false;
73
- if (typeof options === "object") {
74
- for (const elem of options) {
75
- if (elem === value)
76
- return true;
77
- }
78
- }
79
- return false;
80
- },
81
- match: (value, regExp) => {
82
- if (value === void 0 || regExp === void 0)
83
- return false;
84
- return regExp.test(value);
85
- },
86
- isGte: (value, min) => min <= value,
87
- isLte: (value, max) => value <= max,
88
- isTrue: (value) => value === true,
89
- isFalse: (value) => value === false
90
- };
91
- // Annotate the CommonJS export names for ESM import in node:
92
- 0 && (module.exports = {
93
- rule
94
- });
@@ -1,30 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var sanitizer_exports = {};
20
- __export(sanitizer_exports, {
21
- sanitizer: () => sanitizer
22
- });
23
- module.exports = __toCommonJS(sanitizer_exports);
24
- const sanitizer = {
25
- trim: (value) => value.trim()
26
- };
27
- // Annotate the CommonJS export names for ESM import in node:
28
- 0 && (module.exports = {
29
- sanitizer
30
- });
@@ -1,16 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
8
- for (let key of __getOwnPropNames(from))
9
- if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
- }
12
- return to;
13
- };
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
- var schema_exports = {};
16
- module.exports = __toCommonJS(schema_exports);