@kerebron/extension-server-hono 0.4.5 → 0.4.6

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 (61) hide show
  1. package/esm/HonoYjsMemAdapter.d.ts +2 -1
  2. package/esm/HonoYjsMemAdapter.d.ts.map +1 -1
  3. package/esm/HonoYjsMemAdapter.js +1 -0
  4. package/esm/_dnt.polyfills.d.ts +7 -0
  5. package/esm/_dnt.polyfills.d.ts.map +1 -0
  6. package/esm/_dnt.polyfills.js +1 -0
  7. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/compose.d.ts +15 -0
  8. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/compose.d.ts.map +1 -0
  9. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/compose.js +64 -0
  10. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/context.d.ts +452 -0
  11. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/context.d.ts.map +1 -0
  12. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/context.js +513 -0
  13. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/helper/websocket/index.d.ts +70 -0
  14. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/helper/websocket/index.d.ts.map +1 -0
  15. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/helper/websocket/index.js +95 -0
  16. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/hono-base.d.ts +221 -0
  17. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/hono-base.d.ts.map +1 -0
  18. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/hono-base.js +498 -0
  19. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/http-exception.d.ts +60 -0
  20. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/http-exception.d.ts.map +1 -0
  21. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/http-exception.js +71 -0
  22. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/request/constants.d.ts +2 -0
  23. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/request/constants.d.ts.map +1 -0
  24. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/request/constants.js +1 -0
  25. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/request.d.ts +314 -0
  26. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/request.d.ts.map +1 -0
  27. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/request.js +370 -0
  28. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/router.d.ts +98 -0
  29. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/router.d.ts.map +1 -0
  30. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/router.js +25 -0
  31. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/types.d.ts +563 -0
  32. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/types.d.ts.map +1 -0
  33. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/types.js +11 -0
  34. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/body.d.ts +80 -0
  35. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/body.d.ts.map +1 -0
  36. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/body.js +111 -0
  37. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/constants.d.ts +5 -0
  38. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/constants.d.ts.map +1 -0
  39. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/constants.js +4 -0
  40. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/headers.d.ts +9 -0
  41. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/headers.d.ts.map +1 -0
  42. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/headers.js +5 -0
  43. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/html.d.ts +45 -0
  44. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/html.d.ts.map +1 -0
  45. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/html.js +122 -0
  46. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/http-status.d.ts +33 -0
  47. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/http-status.d.ts.map +1 -0
  48. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/http-status.js +5 -0
  49. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/mime.d.ts +71 -0
  50. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/mime.d.ts.map +1 -0
  51. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/mime.js +83 -0
  52. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/types.d.ts +75 -0
  53. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/types.d.ts.map +1 -0
  54. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/types.js +5 -0
  55. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/url.d.ts +30 -0
  56. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/url.d.ts.map +1 -0
  57. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/url.js +255 -0
  58. package/esm/mod.d.ts +2 -1
  59. package/esm/mod.d.ts.map +1 -1
  60. package/esm/mod.js +1 -1
  61. package/package.json +3 -1
@@ -0,0 +1,255 @@
1
+ /**
2
+ * @module
3
+ * URL utility.
4
+ */
5
+ export const splitPath = (path) => {
6
+ const paths = path.split('/');
7
+ if (paths[0] === '') {
8
+ paths.shift();
9
+ }
10
+ return paths;
11
+ };
12
+ export const splitRoutingPath = (routePath) => {
13
+ const { groups, path } = extractGroupsFromPath(routePath);
14
+ const paths = splitPath(path);
15
+ return replaceGroupMarks(paths, groups);
16
+ };
17
+ const extractGroupsFromPath = (path) => {
18
+ const groups = [];
19
+ path = path.replace(/\{[^}]+\}/g, (match, index) => {
20
+ const mark = `@${index}`;
21
+ groups.push([mark, match]);
22
+ return mark;
23
+ });
24
+ return { groups, path };
25
+ };
26
+ const replaceGroupMarks = (paths, groups) => {
27
+ for (let i = groups.length - 1; i >= 0; i--) {
28
+ const [mark] = groups[i];
29
+ for (let j = paths.length - 1; j >= 0; j--) {
30
+ if (paths[j].includes(mark)) {
31
+ paths[j] = paths[j].replace(mark, groups[i][1]);
32
+ break;
33
+ }
34
+ }
35
+ }
36
+ return paths;
37
+ };
38
+ const patternCache = {};
39
+ export const getPattern = (label, next) => {
40
+ // * => wildcard
41
+ // :id{[0-9]+} => ([0-9]+)
42
+ // :id => (.+)
43
+ if (label === '*') {
44
+ return '*';
45
+ }
46
+ const match = label.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
47
+ if (match) {
48
+ const cacheKey = `${label}#${next}`;
49
+ if (!patternCache[cacheKey]) {
50
+ if (match[2]) {
51
+ patternCache[cacheKey] =
52
+ next && next[0] !== ':' && next[0] !== '*'
53
+ ? [cacheKey, match[1], new RegExp(`^${match[2]}(?=/${next})`)]
54
+ : [label, match[1], new RegExp(`^${match[2]}$`)];
55
+ }
56
+ else {
57
+ patternCache[cacheKey] = [label, match[1], true];
58
+ }
59
+ }
60
+ return patternCache[cacheKey];
61
+ }
62
+ return null;
63
+ };
64
+ export const tryDecode = (str, decoder) => {
65
+ try {
66
+ return decoder(str);
67
+ }
68
+ catch {
69
+ return str.replace(/(?:%[0-9A-Fa-f]{2})+/g, (match) => {
70
+ try {
71
+ return decoder(match);
72
+ }
73
+ catch {
74
+ return match;
75
+ }
76
+ });
77
+ }
78
+ };
79
+ /**
80
+ * Try to apply decodeURI() to given string.
81
+ * If it fails, skip invalid percent encoding or invalid UTF-8 sequences, and apply decodeURI() to the rest as much as possible.
82
+ * @param str The string to decode.
83
+ * @returns The decoded string that sometimes contains undecodable percent encoding.
84
+ * @example
85
+ * tryDecodeURI('Hello%20World') // 'Hello World'
86
+ * tryDecodeURI('Hello%20World/%A4%A2') // 'Hello World/%A4%A2'
87
+ */
88
+ const tryDecodeURI = (str) => tryDecode(str, decodeURI);
89
+ export const getPath = (request) => {
90
+ const url = request.url;
91
+ const start = url.indexOf('/', url.indexOf(':') + 4);
92
+ let i = start;
93
+ for (; i < url.length; i++) {
94
+ const charCode = url.charCodeAt(i);
95
+ if (charCode === 37) {
96
+ // '%'
97
+ // If the path contains percent encoding, use `indexOf()` to find '?' and return the result immediately.
98
+ // Although this is a performance disadvantage, it is acceptable since we prefer cases that do not include percent encoding.
99
+ const queryIndex = url.indexOf('?', i);
100
+ const path = url.slice(start, queryIndex === -1 ? undefined : queryIndex);
101
+ return tryDecodeURI(path.includes('%25') ? path.replace(/%25/g, '%2525') : path);
102
+ }
103
+ else if (charCode === 63) {
104
+ // '?'
105
+ break;
106
+ }
107
+ }
108
+ return url.slice(start, i);
109
+ };
110
+ export const getQueryStrings = (url) => {
111
+ const queryIndex = url.indexOf('?', 8);
112
+ return queryIndex === -1 ? '' : '?' + url.slice(queryIndex + 1);
113
+ };
114
+ export const getPathNoStrict = (request) => {
115
+ const result = getPath(request);
116
+ // if strict routing is false => `/hello/hey/` and `/hello/hey` are treated the same
117
+ return result.length > 1 && result.at(-1) === '/' ? result.slice(0, -1) : result;
118
+ };
119
+ /**
120
+ * Merge paths.
121
+ * @param {string[]} ...paths - The paths to merge.
122
+ * @returns {string} The merged path.
123
+ * @example
124
+ * mergePath('/api', '/users') // '/api/users'
125
+ * mergePath('/api/', '/users') // '/api/users'
126
+ * mergePath('/api', '/') // '/api'
127
+ * mergePath('/api/', '/') // '/api/'
128
+ */
129
+ export const mergePath = (base, sub, ...rest) => {
130
+ if (rest.length) {
131
+ sub = mergePath(sub, ...rest);
132
+ }
133
+ return `${base?.[0] === '/' ? '' : '/'}${base}${sub === '/' ? '' : `${base?.at(-1) === '/' ? '' : '/'}${sub?.[0] === '/' ? sub.slice(1) : sub}`}`;
134
+ };
135
+ export const checkOptionalParameter = (path) => {
136
+ /*
137
+ If path is `/api/animals/:type?` it will return:
138
+ [`/api/animals`, `/api/animals/:type`]
139
+ in other cases it will return null
140
+ */
141
+ if (path.charCodeAt(path.length - 1) !== 63 || !path.includes(':')) {
142
+ return null;
143
+ }
144
+ const segments = path.split('/');
145
+ const results = [];
146
+ let basePath = '';
147
+ segments.forEach((segment) => {
148
+ if (segment !== '' && !/\:/.test(segment)) {
149
+ basePath += '/' + segment;
150
+ }
151
+ else if (/\:/.test(segment)) {
152
+ if (/\?/.test(segment)) {
153
+ if (results.length === 0 && basePath === '') {
154
+ results.push('/');
155
+ }
156
+ else {
157
+ results.push(basePath);
158
+ }
159
+ const optionalSegment = segment.replace('?', '');
160
+ basePath += '/' + optionalSegment;
161
+ results.push(basePath);
162
+ }
163
+ else {
164
+ basePath += '/' + segment;
165
+ }
166
+ }
167
+ });
168
+ return results.filter((v, i, a) => a.indexOf(v) === i);
169
+ };
170
+ // Optimized
171
+ const _decodeURI = (value) => {
172
+ if (!/[%+]/.test(value)) {
173
+ return value;
174
+ }
175
+ if (value.indexOf('+') !== -1) {
176
+ value = value.replace(/\+/g, ' ');
177
+ }
178
+ return value.indexOf('%') !== -1 ? tryDecode(value, decodeURIComponent_) : value;
179
+ };
180
+ const _getQueryParam = (url, key, multiple) => {
181
+ let encoded;
182
+ if (!multiple && key && !/[%+]/.test(key)) {
183
+ // optimized for unencoded key
184
+ let keyIndex = url.indexOf('?', 8);
185
+ if (keyIndex === -1) {
186
+ return undefined;
187
+ }
188
+ if (!url.startsWith(key, keyIndex + 1)) {
189
+ keyIndex = url.indexOf(`&${key}`, keyIndex + 1);
190
+ }
191
+ while (keyIndex !== -1) {
192
+ const trailingKeyCode = url.charCodeAt(keyIndex + key.length + 1);
193
+ if (trailingKeyCode === 61) {
194
+ const valueIndex = keyIndex + key.length + 2;
195
+ const endIndex = url.indexOf('&', valueIndex);
196
+ return _decodeURI(url.slice(valueIndex, endIndex === -1 ? undefined : endIndex));
197
+ }
198
+ else if (trailingKeyCode == 38 || isNaN(trailingKeyCode)) {
199
+ return '';
200
+ }
201
+ keyIndex = url.indexOf(`&${key}`, keyIndex + 1);
202
+ }
203
+ encoded = /[%+]/.test(url);
204
+ if (!encoded) {
205
+ return undefined;
206
+ }
207
+ // fallback to default routine
208
+ }
209
+ const results = {};
210
+ encoded ??= /[%+]/.test(url);
211
+ let keyIndex = url.indexOf('?', 8);
212
+ while (keyIndex !== -1) {
213
+ const nextKeyIndex = url.indexOf('&', keyIndex + 1);
214
+ let valueIndex = url.indexOf('=', keyIndex);
215
+ if (valueIndex > nextKeyIndex && nextKeyIndex !== -1) {
216
+ valueIndex = -1;
217
+ }
218
+ let name = url.slice(keyIndex + 1, valueIndex === -1 ? (nextKeyIndex === -1 ? undefined : nextKeyIndex) : valueIndex);
219
+ if (encoded) {
220
+ name = _decodeURI(name);
221
+ }
222
+ keyIndex = nextKeyIndex;
223
+ if (name === '') {
224
+ continue;
225
+ }
226
+ let value;
227
+ if (valueIndex === -1) {
228
+ value = '';
229
+ }
230
+ else {
231
+ value = url.slice(valueIndex + 1, nextKeyIndex === -1 ? undefined : nextKeyIndex);
232
+ if (encoded) {
233
+ value = _decodeURI(value);
234
+ }
235
+ }
236
+ if (multiple) {
237
+ if (!(results[name] && Array.isArray(results[name]))) {
238
+ results[name] = [];
239
+ }
240
+ ;
241
+ results[name].push(value);
242
+ }
243
+ else {
244
+ results[name] ??= value;
245
+ }
246
+ }
247
+ return key ? results[key] : results;
248
+ };
249
+ export const getQueryParam = _getQueryParam;
250
+ export const getQueryParams = (url, key) => {
251
+ return _getQueryParam(url, key, true);
252
+ };
253
+ // `decodeURIComponent` is a long name.
254
+ // By making it a function, we can use it commonly when minified, reducing the amount of code.
255
+ export const decodeURIComponent_ = decodeURIComponent;
package/esm/mod.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { WSEvents } from 'hono/ws';
1
+ import "./_dnt.polyfills.js";
2
+ import { WSEvents } from './deps/jsr.io/@hono/hono/4.10.7/src/helper/websocket/index.js';
2
3
  export interface HonoWsAdapter {
3
4
  upgradeWebSocket(roomName: string): WSEvents<WebSocket>;
4
5
  }
package/esm/mod.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,MAAM,WAAW,aAAa;IAC5B,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC;CACzD"}
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,MAAM,+DAA+D,CAAC;AAEzF,MAAM,WAAW,aAAa;IAC5B,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC;CACzD"}
package/esm/mod.js CHANGED
@@ -1 +1 @@
1
- export {};
1
+ import "./_dnt.polyfills.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kerebron/extension-server-hono",
3
- "version": "0.4.5",
3
+ "version": "0.4.6",
4
4
  "license": "MIT",
5
5
  "module": "./esm/mod.js",
6
6
  "exports": {
@@ -13,6 +13,8 @@
13
13
  },
14
14
  "scripts": {},
15
15
  "dependencies": {
16
+ "lib0": "0.2.109",
17
+ "y-protocols": "1.0.6",
16
18
  "yjs": "13.6.24"
17
19
  },
18
20
  "devDependencies": {