hono 1.2.0 → 1.3.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/README.md +92 -21
- package/dist/compose.test.d.ts +1 -0
- package/dist/compose.test.js +511 -0
- package/dist/context.d.ts +4 -1
- package/dist/context.js +31 -6
- package/dist/context.test.d.ts +1 -0
- package/dist/context.test.js +127 -0
- package/dist/hono.d.ts +21 -29
- package/dist/hono.js +27 -65
- package/dist/hono.test.d.ts +1 -0
- package/dist/hono.test.js +656 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -2
- package/dist/middleware/basic-auth/index.js +7 -8
- package/dist/middleware/basic-auth/index.test.d.ts +1 -0
- package/dist/middleware/basic-auth/index.test.js +119 -0
- package/dist/middleware/body-parse/index.test.d.ts +1 -0
- package/dist/middleware/body-parse/index.test.js +59 -0
- package/dist/middleware/cookie/index.d.ts +5 -2
- package/dist/middleware/cookie/index.js +9 -4
- package/dist/middleware/cookie/index.test.d.ts +1 -0
- package/dist/middleware/cookie/index.test.js +78 -0
- package/dist/middleware/cors/index.test.d.ts +1 -0
- package/dist/middleware/cors/index.test.js +59 -0
- package/dist/middleware/etag/index.test.d.ts +1 -0
- package/dist/middleware/etag/index.test.js +45 -0
- package/dist/middleware/graphql-server/index.js +1 -1
- package/dist/middleware/graphql-server/index.test.d.ts +1 -0
- package/dist/middleware/graphql-server/index.test.js +480 -0
- package/dist/middleware/graphql-server/parse-body.test.d.ts +1 -0
- package/dist/middleware/graphql-server/parse-body.test.js +57 -0
- package/dist/middleware/jwt/index.test.d.ts +1 -0
- package/dist/middleware/jwt/index.test.js +51 -0
- package/dist/middleware/logger/index.test.d.ts +1 -0
- package/dist/middleware/logger/index.test.js +49 -0
- package/dist/middleware/mustache/index.test.d.ts +1 -0
- package/dist/middleware/mustache/index.test.js +49 -0
- package/dist/middleware/powered-by/index.test.d.ts +1 -0
- package/dist/middleware/powered-by/index.test.js +15 -0
- package/dist/middleware/pretty-json/index.test.d.ts +1 -0
- package/dist/middleware/pretty-json/index.test.js +28 -0
- package/dist/middleware/serve-static/index.test.d.ts +1 -0
- package/dist/middleware/serve-static/index.test.js +58 -0
- package/dist/router/reg-exp-router/index.d.ts +1 -1
- package/dist/router/reg-exp-router/index.js +1 -1
- package/dist/router/reg-exp-router/router.js +1 -1
- package/dist/router/reg-exp-router/router.test.d.ts +1 -0
- package/dist/router/reg-exp-router/router.test.js +212 -0
- package/dist/router/reg-exp-router/trie.d.ts +3 -3
- package/dist/router/reg-exp-router/trie.js +1 -1
- package/dist/router/trie-router/index.d.ts +1 -1
- package/dist/router/trie-router/index.js +1 -1
- package/dist/router/trie-router/node.test.d.ts +1 -0
- package/dist/router/trie-router/node.test.js +351 -0
- package/dist/router/trie-router/router.d.ts +1 -1
- package/dist/router/trie-router/router.js +1 -1
- package/dist/router/trie-router/router.test.d.ts +1 -0
- package/dist/router/trie-router/router.test.js +98 -0
- package/dist/utils/body.test.d.ts +1 -0
- package/dist/utils/body.test.js +45 -0
- package/dist/utils/buffer.js +1 -1
- package/dist/utils/buffer.test.d.ts +1 -0
- package/dist/utils/buffer.test.js +36 -0
- package/dist/utils/cloudflare.test.d.ts +1 -0
- package/dist/utils/cloudflare.test.js +42 -0
- package/dist/utils/crypto.test.d.ts +1 -0
- package/dist/utils/crypto.test.js +15 -0
- package/dist/utils/encode.test.d.ts +1 -0
- package/dist/utils/encode.test.js +54 -0
- package/dist/utils/http-status.test.d.ts +1 -0
- package/dist/utils/http-status.test.js +8 -0
- package/dist/utils/jwt/jwt.test.d.ts +1 -0
- package/dist/utils/jwt/jwt.test.js +171 -0
- package/dist/utils/jwt/types.test.d.ts +1 -0
- package/dist/utils/jwt/types.test.js +12 -0
- package/dist/utils/mime.test.d.ts +1 -0
- package/dist/utils/mime.test.js +13 -0
- package/dist/utils/url.js +4 -0
- package/dist/utils/url.test.d.ts +1 -0
- package/dist/utils/url.test.js +96 -0
- package/package.json +3 -4
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const encode_1 = require("./encode");
|
|
4
|
+
describe('encode', () => {
|
|
5
|
+
describe('base64', () => {
|
|
6
|
+
it('encodeBase64', () => {
|
|
7
|
+
expect((0, encode_1.encodeBase64)('hooooooooo')).toBe('aG9vb29vb29vbw==');
|
|
8
|
+
expect((0, encode_1.encodeBase64)('炎')).toBe('54KO');
|
|
9
|
+
expect((0, encode_1.encodeBase64)('abcdef')).not.toBe('abcdedf');
|
|
10
|
+
expect((0, encode_1.encodeBase64)('')).toBe('');
|
|
11
|
+
expect(() => {
|
|
12
|
+
(0, encode_1.encodeBase64)(null);
|
|
13
|
+
}).toThrow(TypeError);
|
|
14
|
+
});
|
|
15
|
+
it('decodeBase64', async () => {
|
|
16
|
+
expect((0, encode_1.decodeBase64)('aG9vb29vb29vbw==')).toBe('hooooooooo');
|
|
17
|
+
expect((0, encode_1.decodeBase64)('54KO')).toBe('炎');
|
|
18
|
+
expect((0, encode_1.decodeBase64)('abcdedf')).not.toBe('abcdef');
|
|
19
|
+
expect((0, encode_1.decodeBase64)('')).toBe('');
|
|
20
|
+
expect(() => {
|
|
21
|
+
(0, encode_1.decodeBase64)(null);
|
|
22
|
+
}).toThrowError(TypeError);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
describe('base64url', () => {
|
|
26
|
+
it('encodeBase64URL', () => {
|
|
27
|
+
expect((0, encode_1.encodeBase64URL)('hooooooooo')).toBe('aG9vb29vb29vbw');
|
|
28
|
+
expect((0, encode_1.encodeBase64URL)('http://github.com/honojs/hono')).toBe('aHR0cDovL2dpdGh1Yi5jb20vaG9ub2pzL2hvbm8');
|
|
29
|
+
expect((0, encode_1.encodeBase64URL)('炎')).toBe('54KO');
|
|
30
|
+
expect((0, encode_1.encodeBase64URL)('abcdef')).not.toBe('abcdedf');
|
|
31
|
+
expect((0, encode_1.encodeBase64URL)('')).toBe('');
|
|
32
|
+
expect(() => {
|
|
33
|
+
(0, encode_1.encodeBase64URL)(null);
|
|
34
|
+
}).toThrow(TypeError);
|
|
35
|
+
});
|
|
36
|
+
it('decodeBase64URL', async () => {
|
|
37
|
+
expect((0, encode_1.decodeBase64URL)('aG9vb29vb29vbw')).toBe('hooooooooo');
|
|
38
|
+
expect((0, encode_1.decodeBase64URL)('aHR0cDovL2dpdGh1Yi5jb20vaG9ub2pzL2hvbm8')).toBe('http://github.com/honojs/hono');
|
|
39
|
+
expect((0, encode_1.decodeBase64URL)('54KO')).toBe('炎');
|
|
40
|
+
expect((0, encode_1.decodeBase64URL)('abcdedf')).not.toBe('abcdef');
|
|
41
|
+
expect((0, encode_1.decodeBase64URL)('')).toBe('');
|
|
42
|
+
expect(() => {
|
|
43
|
+
(0, encode_1.decodeBase64URL)(null);
|
|
44
|
+
}).toThrowError(TypeError);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
describe('utf8ToUint8Array', () => {
|
|
48
|
+
it('should be equal', () => {
|
|
49
|
+
const k = 'a-secret-key';
|
|
50
|
+
const arr = (0, encode_1.utf8ToUint8Array)(k);
|
|
51
|
+
expect(String(arr)).toEqual('97,45,115,101,99,114,101,116,45,107,101,121');
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const http_status_1 = require("./http-status");
|
|
4
|
+
describe('http-status utility', () => {
|
|
5
|
+
it('getStatusText', () => {
|
|
6
|
+
expect((0, http_status_1.getStatusText)(200)).toBe('OK');
|
|
7
|
+
});
|
|
8
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const JWT = __importStar(require("./jwt"));
|
|
27
|
+
const types_1 = require("./types");
|
|
28
|
+
describe('JWT', () => {
|
|
29
|
+
it('JwtAlorithmNotImplemented', async () => {
|
|
30
|
+
const payload = { message: 'hello world' };
|
|
31
|
+
const secret = 'a-secret';
|
|
32
|
+
const alg = '';
|
|
33
|
+
let tok = '';
|
|
34
|
+
let err;
|
|
35
|
+
try {
|
|
36
|
+
tok = await JWT.sign(payload, secret, alg);
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
err = e;
|
|
40
|
+
}
|
|
41
|
+
expect(tok).toBe('');
|
|
42
|
+
expect(err).toEqual(new types_1.JwtAlorithmNotImplemented(alg));
|
|
43
|
+
});
|
|
44
|
+
it('JwtTokenInvalid', async () => {
|
|
45
|
+
const tok = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJtZXNzYWdlIjoiaGVsbG8gd29ybGQifQ';
|
|
46
|
+
const secret = 'a-secret';
|
|
47
|
+
let err;
|
|
48
|
+
let authorized = false;
|
|
49
|
+
try {
|
|
50
|
+
authorized = await JWT.verify(tok, secret, types_1.AlgorithmTypes.HS256);
|
|
51
|
+
}
|
|
52
|
+
catch (e) {
|
|
53
|
+
err = e;
|
|
54
|
+
}
|
|
55
|
+
expect(err).toEqual(new types_1.JwtTokenInvalid(tok));
|
|
56
|
+
expect(authorized).toBe(false);
|
|
57
|
+
});
|
|
58
|
+
it('JwtTokenNotBefore', async () => {
|
|
59
|
+
const tok = 'eyJraWQiOiJFemF7bVZWbnd0TUpUNEFveFVtT0dILWJ0Y2VUVFM3djBYcEJuMm5ZZ2VjIiwiYWxnIjoiSFMyNTYifQ.eyJyb2xlIjoiYXBpX3JvbGUiLCJuYmYiOjE2NjQ1ODI0MDB9.BatadbUj5e41OZ33odEFTAndQFzX0w9aAgpQPgO-zaQ';
|
|
60
|
+
const secret = 'a-secret';
|
|
61
|
+
let err;
|
|
62
|
+
let authorized = false;
|
|
63
|
+
try {
|
|
64
|
+
authorized = await JWT.verify(tok, secret, types_1.AlgorithmTypes.HS256);
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
67
|
+
err = e;
|
|
68
|
+
}
|
|
69
|
+
expect(err).toEqual(new types_1.JwtTokenNotBefore(tok));
|
|
70
|
+
expect(authorized).toBe(false);
|
|
71
|
+
});
|
|
72
|
+
it('JwtTokenExpired', async () => {
|
|
73
|
+
const tok = 'eyJraWQiOiJFemF6bVZWbnd0TUpUNEFveFVtT0dILWJ0Y2VUVFM3djBYcEJuMm5ZZ2VjIiwiYWxnIjoiSFMyNTYifQ.eyJyb2xlIjoiYXBpX3JvbGUiLCJleHAiOjE2MzMwNDY0MDB9.Gmq_dozOnwzqkMUMEm7uny7cMZuF1d0QkCnmRXAbTEk';
|
|
74
|
+
const secret = 'a-secret';
|
|
75
|
+
let err;
|
|
76
|
+
let authorized = false;
|
|
77
|
+
try {
|
|
78
|
+
authorized = await JWT.verify(tok, secret, types_1.AlgorithmTypes.HS256);
|
|
79
|
+
}
|
|
80
|
+
catch (e) {
|
|
81
|
+
err = e;
|
|
82
|
+
}
|
|
83
|
+
expect(err).toEqual(new types_1.JwtTokenExpired(tok));
|
|
84
|
+
expect(authorized).toBe(false);
|
|
85
|
+
});
|
|
86
|
+
it('HS256 sign & verify & decode', async () => {
|
|
87
|
+
const payload = { message: 'hello world' };
|
|
88
|
+
const secret = 'a-secret';
|
|
89
|
+
const tok = await JWT.sign(payload, secret, types_1.AlgorithmTypes.HS256);
|
|
90
|
+
const expected = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJtZXNzYWdlIjoiaGVsbG8gd29ybGQifQ.B54pAqIiLbu170tGQ1rY06Twv__0qSHTA0ioQPIOvFE';
|
|
91
|
+
expect(tok).toEqual(expected);
|
|
92
|
+
expect(await JWT.verify(tok, secret, types_1.AlgorithmTypes.HS256)).toBe(true);
|
|
93
|
+
expect(JWT.decode(tok)).toEqual({
|
|
94
|
+
header: {
|
|
95
|
+
alg: 'HS256',
|
|
96
|
+
typ: 'JWT',
|
|
97
|
+
},
|
|
98
|
+
payload: {
|
|
99
|
+
message: 'hello world',
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
it('HS256 sign & verify', async () => {
|
|
104
|
+
const payload = { message: 'hello world' };
|
|
105
|
+
const secret = 'a-secret';
|
|
106
|
+
const tok = await JWT.sign(payload, secret, types_1.AlgorithmTypes.HS256);
|
|
107
|
+
const expected = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJtZXNzYWdlIjoiaGVsbG8gd29ybGQifQ.B54pAqIiLbu170tGQ1rY06Twv__0qSHTA0ioQPIOvFE';
|
|
108
|
+
expect(tok).toEqual(expected);
|
|
109
|
+
let err = null;
|
|
110
|
+
let authorized = false;
|
|
111
|
+
try {
|
|
112
|
+
authorized = await JWT.verify(tok, secret + 'invalid', types_1.AlgorithmTypes.HS256);
|
|
113
|
+
}
|
|
114
|
+
catch (e) {
|
|
115
|
+
err = e;
|
|
116
|
+
}
|
|
117
|
+
expect(authorized).toBe(false);
|
|
118
|
+
expect(err instanceof types_1.JwtTokenSignatureMismatched).toBe(true);
|
|
119
|
+
});
|
|
120
|
+
it('HS512 sign & verify & decode', async () => {
|
|
121
|
+
const payload = { message: 'hello world' };
|
|
122
|
+
const secret = 'a-secret';
|
|
123
|
+
const tok = await JWT.sign(payload, secret, types_1.AlgorithmTypes.HS512);
|
|
124
|
+
const expected = 'eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJtZXNzYWdlIjoiaGVsbG8gd29ybGQifQ.RqVLgExB_GXF1-9T-k4V4HjFmiuQKTEjVSiZd-YL0WERIlywZ7PfzAuTZSJU4gg8cscGamQa030cieEWrYcywg';
|
|
125
|
+
expect(tok).toEqual(expected);
|
|
126
|
+
expect(await JWT.verify(tok, secret, types_1.AlgorithmTypes.HS512)).toBe(true);
|
|
127
|
+
expect(JWT.decode(tok)).toEqual({
|
|
128
|
+
header: {
|
|
129
|
+
alg: 'HS512',
|
|
130
|
+
typ: 'JWT',
|
|
131
|
+
},
|
|
132
|
+
payload: {
|
|
133
|
+
message: 'hello world',
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
it('HS512 sign & verify', async () => {
|
|
138
|
+
const payload = { message: 'hello world' };
|
|
139
|
+
const secret = 'a-secret';
|
|
140
|
+
const tok = await JWT.sign(payload, secret, types_1.AlgorithmTypes.HS512);
|
|
141
|
+
const expected = 'eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJtZXNzYWdlIjoiaGVsbG8gd29ybGQifQ.RqVLgExB_GXF1-9T-k4V4HjFmiuQKTEjVSiZd-YL0WERIlywZ7PfzAuTZSJU4gg8cscGamQa030cieEWrYcywg';
|
|
142
|
+
expect(tok).toEqual(expected);
|
|
143
|
+
let err = null;
|
|
144
|
+
let authorized = false;
|
|
145
|
+
try {
|
|
146
|
+
authorized = await JWT.verify(tok, secret + 'invalid', types_1.AlgorithmTypes.HS256);
|
|
147
|
+
}
|
|
148
|
+
catch (e) {
|
|
149
|
+
err = e;
|
|
150
|
+
}
|
|
151
|
+
expect(authorized).toBe(false);
|
|
152
|
+
expect(err instanceof types_1.JwtTokenSignatureMismatched).toBe(true);
|
|
153
|
+
});
|
|
154
|
+
it('HS384 sign & verify', async () => {
|
|
155
|
+
const payload = { message: 'hello world' };
|
|
156
|
+
const secret = 'a-secret%你好';
|
|
157
|
+
const tok = await JWT.sign(payload, secret, types_1.AlgorithmTypes.HS384);
|
|
158
|
+
const expected = 'eyJhbGciOiJIUzM4NCIsInR5cCI6IkpXVCJ9.eyJtZXNzYWdlIjoiaGVsbG8gd29ybGQifQ.C1Br1183Oy6O7th4NDCOaI9WB75i3FMCuYlv1tCL9HggsU89T-SNutghwhJykD3r';
|
|
159
|
+
expect(tok).toEqual(expected);
|
|
160
|
+
let err = null;
|
|
161
|
+
let authorized = false;
|
|
162
|
+
try {
|
|
163
|
+
authorized = await JWT.verify(tok, secret + 'invalid', types_1.AlgorithmTypes.HS256);
|
|
164
|
+
}
|
|
165
|
+
catch (e) {
|
|
166
|
+
err = e;
|
|
167
|
+
}
|
|
168
|
+
expect(authorized).toBe(false);
|
|
169
|
+
expect(err instanceof types_1.JwtTokenSignatureMismatched).toBe(true);
|
|
170
|
+
});
|
|
171
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const types_1 = require("./types");
|
|
4
|
+
describe('Types', () => {
|
|
5
|
+
it('AlgorithmTypes', () => {
|
|
6
|
+
expect('HS256').toBe(types_1.AlgorithmTypes.HS256);
|
|
7
|
+
expect('HS384').toBe(types_1.AlgorithmTypes.HS384);
|
|
8
|
+
expect('HS512').toBe(types_1.AlgorithmTypes.HS512);
|
|
9
|
+
expect(undefined).toBe(undefined);
|
|
10
|
+
expect('').toBe('');
|
|
11
|
+
});
|
|
12
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const mime_1 = require("./mime");
|
|
4
|
+
describe('mime', () => {
|
|
5
|
+
it('getMimeType', () => {
|
|
6
|
+
expect((0, mime_1.getMimeType)('hello.txt')).toBe('text/plain; charset=utf-8');
|
|
7
|
+
expect((0, mime_1.getMimeType)('hello.html')).toBe('text/html; charset=utf-8');
|
|
8
|
+
expect((0, mime_1.getMimeType)('hello.json')).toBe('application/json; charset=utf-8');
|
|
9
|
+
expect((0, mime_1.getMimeType)('good.morning.hello.gif')).toBe('image/gif');
|
|
10
|
+
expect((0, mime_1.getMimeType)('goodmorninghellogif')).toBeUndefined();
|
|
11
|
+
expect((0, mime_1.getMimeType)('indexjs.abcd')).toBeUndefined();
|
|
12
|
+
});
|
|
13
|
+
});
|
package/dist/utils/url.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const url_1 = require("./url");
|
|
4
|
+
describe('url', () => {
|
|
5
|
+
it('splitPath', () => {
|
|
6
|
+
let ps = (0, url_1.splitPath)('/');
|
|
7
|
+
expect(ps).toStrictEqual(['']);
|
|
8
|
+
ps = (0, url_1.splitPath)('/hello');
|
|
9
|
+
expect(ps).toStrictEqual(['hello']);
|
|
10
|
+
ps = (0, url_1.splitPath)('*');
|
|
11
|
+
expect(ps).toStrictEqual(['*']);
|
|
12
|
+
ps = (0, url_1.splitPath)('/wildcard-abc/*/wildcard-efg');
|
|
13
|
+
expect(ps).toStrictEqual(['wildcard-abc', '*', 'wildcard-efg']);
|
|
14
|
+
ps = (0, url_1.splitPath)('/map/:location/events');
|
|
15
|
+
expect(ps).toStrictEqual(['map', ':location', 'events']);
|
|
16
|
+
});
|
|
17
|
+
it('getPattern', () => {
|
|
18
|
+
let res = (0, url_1.getPattern)(':id');
|
|
19
|
+
expect(res).not.toBeNull();
|
|
20
|
+
expect(res[0]).toBe(':id');
|
|
21
|
+
expect(res[1]).toBe('id');
|
|
22
|
+
expect(res[2]).toBe(true);
|
|
23
|
+
res = (0, url_1.getPattern)(':id{[0-9]+}');
|
|
24
|
+
expect(res[0]).toBe(':id{[0-9]+}');
|
|
25
|
+
expect(res[1]).toBe('id');
|
|
26
|
+
expect(res[2]).toEqual(/^[0-9]+$/);
|
|
27
|
+
res = (0, url_1.getPattern)('*');
|
|
28
|
+
expect(res).toBe('*');
|
|
29
|
+
});
|
|
30
|
+
describe('getPathFromURL', () => {
|
|
31
|
+
it('getPathFromURL - no trailing slash', () => {
|
|
32
|
+
let path = (0, url_1.getPathFromURL)('https://example.com/');
|
|
33
|
+
expect(path).toBe('/');
|
|
34
|
+
path = (0, url_1.getPathFromURL)('https://example.com/hello');
|
|
35
|
+
expect(path).toBe('/hello');
|
|
36
|
+
path = (0, url_1.getPathFromURL)('https://example.com/hello/hey');
|
|
37
|
+
expect(path).toBe('/hello/hey');
|
|
38
|
+
path = (0, url_1.getPathFromURL)('https://example.com/hello?name=foo');
|
|
39
|
+
expect(path).toBe('/hello');
|
|
40
|
+
path = (0, url_1.getPathFromURL)('https://example.com/hello/hey?name=foo&name=bar');
|
|
41
|
+
expect(path).toBe('/hello/hey');
|
|
42
|
+
path = (0, url_1.getPathFromURL)('https://example.com/hello/hey#fragment');
|
|
43
|
+
expect(path).toBe('/hello/hey');
|
|
44
|
+
});
|
|
45
|
+
it('getPathFromURL - with trailing slash', () => {
|
|
46
|
+
let path = (0, url_1.getPathFromURL)('https://example.com/hello/');
|
|
47
|
+
expect(path).toBe('/hello/');
|
|
48
|
+
path = (0, url_1.getPathFromURL)('https://example.com/hello/hey/');
|
|
49
|
+
expect(path).toBe('/hello/hey/');
|
|
50
|
+
});
|
|
51
|
+
it('getPathFromURL - no strict is false', () => {
|
|
52
|
+
let path = (0, url_1.getPathFromURL)('https://example.com/hello/', { strict: false });
|
|
53
|
+
expect(path).toBe('/hello');
|
|
54
|
+
path = (0, url_1.getPathFromURL)('https://example.com/hello/hey/', { strict: false });
|
|
55
|
+
expect(path).toBe('/hello/hey');
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
describe('isAbsoluteURL', () => {
|
|
59
|
+
it('absolute url', () => {
|
|
60
|
+
expect((0, url_1.isAbsoluteURL)('https://example.com')).toBeTruthy();
|
|
61
|
+
expect((0, url_1.isAbsoluteURL)('https://example.com/xxx')).toBeTruthy();
|
|
62
|
+
});
|
|
63
|
+
it('relative url', () => {
|
|
64
|
+
expect((0, url_1.isAbsoluteURL)('/')).not.toBeTruthy();
|
|
65
|
+
expect((0, url_1.isAbsoluteURL)('/location')).not.toBeTruthy();
|
|
66
|
+
expect((0, url_1.isAbsoluteURL)('')).not.toBeTruthy();
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
describe('mergePath', () => {
|
|
70
|
+
it('mergePath', () => {
|
|
71
|
+
expect((0, url_1.mergePath)('/book', '/')).toBe('/book');
|
|
72
|
+
expect((0, url_1.mergePath)('/book/', '/')).toBe('/book/');
|
|
73
|
+
expect((0, url_1.mergePath)('/book', '/hey')).toBe('/book/hey');
|
|
74
|
+
expect((0, url_1.mergePath)('/book/', '/hey')).toBe('/book/hey');
|
|
75
|
+
expect((0, url_1.mergePath)('/book', '/hey/')).toBe('/book/hey/');
|
|
76
|
+
expect((0, url_1.mergePath)('/book/', '/hey/')).toBe('/book/hey/');
|
|
77
|
+
expect((0, url_1.mergePath)('/book', 'hey', 'say')).toBe('/book/hey/say');
|
|
78
|
+
expect((0, url_1.mergePath)('/book', '/hey/', '/say/')).toBe('/book/hey/say/');
|
|
79
|
+
expect((0, url_1.mergePath)('/book', '/hey/', '/say/', '/')).toBe('/book/hey/say/');
|
|
80
|
+
expect((0, url_1.mergePath)('book', '/')).toBe('/book');
|
|
81
|
+
expect((0, url_1.mergePath)('book/', '/')).toBe('/book/');
|
|
82
|
+
expect((0, url_1.mergePath)('book', '/hey')).toBe('/book/hey');
|
|
83
|
+
expect((0, url_1.mergePath)('book', 'hey')).toBe('/book/hey');
|
|
84
|
+
expect((0, url_1.mergePath)('book', 'hey/')).toBe('/book/hey/');
|
|
85
|
+
});
|
|
86
|
+
it('Should be `/book`', () => {
|
|
87
|
+
expect((0, url_1.mergePath)('/', 'book')).toBe('/book');
|
|
88
|
+
});
|
|
89
|
+
it('Should be `/book`', () => {
|
|
90
|
+
expect((0, url_1.mergePath)('/', '/book')).toBe('/book');
|
|
91
|
+
});
|
|
92
|
+
it('Should be `/`', () => {
|
|
93
|
+
expect((0, url_1.mergePath)('/', '/')).toBe('/');
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hono",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Ultrafast web framework for Cloudflare Workers.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
"test": "jest",
|
|
12
12
|
"lint": "eslint --ext js,ts src .eslintrc.js",
|
|
13
13
|
"lint:fix": "eslint --ext js,ts src .eslintrc.js --fix",
|
|
14
|
-
"build": "rimraf dist && tsc
|
|
15
|
-
"watch": "tsc -w
|
|
14
|
+
"build": "rimraf dist && tsc",
|
|
15
|
+
"watch": "tsc -w",
|
|
16
16
|
"prepublishOnly": "yarn build"
|
|
17
17
|
},
|
|
18
18
|
"exports": {
|
|
@@ -131,7 +131,6 @@
|
|
|
131
131
|
"prettier-plugin-md-nocjsp": "^1.2.0",
|
|
132
132
|
"rimraf": "^3.0.2",
|
|
133
133
|
"ts-jest": "^27.1.4",
|
|
134
|
-
"tsc-alias": "^1.6.7",
|
|
135
134
|
"typescript": "^4.6.3"
|
|
136
135
|
},
|
|
137
136
|
"engines": {
|