@bepalo/spine 1.0.3

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 (83) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +830 -0
  3. package/dist/auth-middlewares.d.ts +119 -0
  4. package/dist/auth-middlewares.d.ts.map +1 -0
  5. package/dist/auth-middlewares.js +168 -0
  6. package/dist/auth-middlewares.js.map +1 -0
  7. package/dist/cjs/auth-middlewares.d.ts +119 -0
  8. package/dist/cjs/auth-middlewares.d.ts.map +1 -0
  9. package/dist/cjs/auth-middlewares.js +168 -0
  10. package/dist/cjs/auth-middlewares.js.map +1 -0
  11. package/dist/cjs/helpers.d.ts +180 -0
  12. package/dist/cjs/helpers.d.ts.map +1 -0
  13. package/dist/cjs/helpers.js +366 -0
  14. package/dist/cjs/helpers.js.map +1 -0
  15. package/dist/cjs/index.d.ts +11 -0
  16. package/dist/cjs/index.d.ts.map +1 -0
  17. package/dist/cjs/index.js +30 -0
  18. package/dist/cjs/index.js.map +1 -0
  19. package/dist/cjs/middlewares.d.ts +88 -0
  20. package/dist/cjs/middlewares.d.ts.map +1 -0
  21. package/dist/cjs/middlewares.js +262 -0
  22. package/dist/cjs/middlewares.js.map +1 -0
  23. package/dist/cjs/parsers.d.ts +177 -0
  24. package/dist/cjs/parsers.d.ts.map +1 -0
  25. package/dist/cjs/parsers.js +1021 -0
  26. package/dist/cjs/parsers.js.map +1 -0
  27. package/dist/cjs/router.d.ts +124 -0
  28. package/dist/cjs/router.d.ts.map +1 -0
  29. package/dist/cjs/router.js +1378 -0
  30. package/dist/cjs/router.js.map +1 -0
  31. package/dist/cjs/status.d.ts +77 -0
  32. package/dist/cjs/status.d.ts.map +1 -0
  33. package/dist/cjs/status.js +252 -0
  34. package/dist/cjs/status.js.map +1 -0
  35. package/dist/cjs/types.d.ts +135 -0
  36. package/dist/cjs/types.d.ts.map +1 -0
  37. package/dist/cjs/types.js +109 -0
  38. package/dist/cjs/types.js.map +1 -0
  39. package/dist/cjs/utils.d.ts +11 -0
  40. package/dist/cjs/utils.d.ts.map +1 -0
  41. package/dist/cjs/utils.js +76 -0
  42. package/dist/cjs/utils.js.map +1 -0
  43. package/dist/cjs/utils.node.d.ts +4 -0
  44. package/dist/cjs/utils.node.d.ts.map +1 -0
  45. package/dist/cjs/utils.node.js +99 -0
  46. package/dist/cjs/utils.node.js.map +1 -0
  47. package/dist/helpers.d.ts +180 -0
  48. package/dist/helpers.d.ts.map +1 -0
  49. package/dist/helpers.js +366 -0
  50. package/dist/helpers.js.map +1 -0
  51. package/dist/index.d.ts +11 -0
  52. package/dist/index.d.ts.map +1 -0
  53. package/dist/index.js +30 -0
  54. package/dist/index.js.map +1 -0
  55. package/dist/middlewares.d.ts +88 -0
  56. package/dist/middlewares.d.ts.map +1 -0
  57. package/dist/middlewares.js +262 -0
  58. package/dist/middlewares.js.map +1 -0
  59. package/dist/parsers.d.ts +177 -0
  60. package/dist/parsers.d.ts.map +1 -0
  61. package/dist/parsers.js +1021 -0
  62. package/dist/parsers.js.map +1 -0
  63. package/dist/router.d.ts +124 -0
  64. package/dist/router.d.ts.map +1 -0
  65. package/dist/router.js +1378 -0
  66. package/dist/router.js.map +1 -0
  67. package/dist/status.d.ts +77 -0
  68. package/dist/status.d.ts.map +1 -0
  69. package/dist/status.js +252 -0
  70. package/dist/status.js.map +1 -0
  71. package/dist/types.d.ts +135 -0
  72. package/dist/types.d.ts.map +1 -0
  73. package/dist/types.js +109 -0
  74. package/dist/types.js.map +1 -0
  75. package/dist/utils.d.ts +11 -0
  76. package/dist/utils.d.ts.map +1 -0
  77. package/dist/utils.js +76 -0
  78. package/dist/utils.js.map +1 -0
  79. package/dist/utils.node.d.ts +4 -0
  80. package/dist/utils.node.d.ts.map +1 -0
  81. package/dist/utils.node.js +66 -0
  82. package/dist/utils.node.js.map +1 -0
  83. package/package.json +57 -0
package/dist/router.js ADDED
@@ -0,0 +1,1378 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
12
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
13
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
14
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
15
+ };
16
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
17
+ if (kind === "m") throw new TypeError("Private method is not writable");
18
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
19
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
20
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
21
+ };
22
+ var __asyncValues = (this && this.__asyncValues) || function (o) {
23
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
24
+ var m = o[Symbol.asyncIterator], i;
25
+ return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
26
+ function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
27
+ function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
28
+ };
29
+ var _Router_instances, _Router_config, _Router_routes, _Router_register, _Router_processPath, _Router_getRouteEntries, _Router_InitEntries, _Router_initRoutes;
30
+ Object.defineProperty(exports, "__esModule", { value: true });
31
+ exports.Router = exports.HANDLER_TYPES = exports.HTTP_METHODS_UPPER = exports.CRUD_METHODS = exports.HTTP_METHODS = void 0;
32
+ const status_ts_1 = require("./status.js");
33
+ const types_ts_1 = require("./types.js");
34
+ const utils_node_ts_1 = require("./utils.node.js");
35
+ const EMPTY_PARAMS = Object.freeze({});
36
+ const W = "[\\p{L}\\p{M}\\p{N}\\p{S}\\p{P}_\\-.]";
37
+ const PATH_PART_REGEX = new RegExp(`^(?:#?${W}+|\\[(?:${W}*|#{1,2}|##\\s*${W}*\\s*|\\[##\\s*${W}*\\s*\\]|\\[${W}*(?:,${W}*)*\\](?:\\s*${W}*\\s*|\\[\\s*${W}*\\s*\\]))\\])$`, "u");
38
+ const REGISTER_PATH_REGEX = new RegExp(`^(?:/(?:${W}*|${W}*(?:\\|${W}*)*:${W}*|\\*))+|(?:/${W}*)*(?:/\\.?\\*\\*)|(?:/${W}*)*(?:/::${W}*)$`, "u");
39
+ exports.HTTP_METHODS = new Set([
40
+ "Head",
41
+ "Get",
42
+ "Post",
43
+ "Put",
44
+ "Patch",
45
+ "Delete",
46
+ "Options",
47
+ "Trace",
48
+ "Connect",
49
+ ]);
50
+ exports.CRUD_METHODS = new Set([
51
+ "Get",
52
+ "Post",
53
+ "Put",
54
+ "Patch",
55
+ "Delete",
56
+ ]);
57
+ exports.HTTP_METHODS_UPPER = new Set([
58
+ "HEAD",
59
+ "GET",
60
+ "POST",
61
+ "PUT",
62
+ "PATCH",
63
+ "DELETE",
64
+ "OPTIONS",
65
+ "TRACE",
66
+ "CONNECT",
67
+ ]);
68
+ exports.HANDLER_TYPES = new Set([
69
+ "handler",
70
+ "filter",
71
+ "fallback",
72
+ "catcher",
73
+ "after",
74
+ ]);
75
+ /**
76
+ * The Router class.
77
+ *
78
+ * @template {Record<string, unknown>} ExtendContext - Extend Router Context
79
+ */
80
+ class Router {
81
+ get maxPath() {
82
+ return __classPrivateFieldGet(this, _Router_config, "f").maxPath;
83
+ }
84
+ get enable() {
85
+ return Object.assign({}, __classPrivateFieldGet(this, _Router_config, "f").enable);
86
+ }
87
+ constructor(config) {
88
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
89
+ _Router_instances.add(this);
90
+ _Router_config.set(this, void 0);
91
+ _Router_routes.set(this, void 0);
92
+ __classPrivateFieldSet(this, _Router_config, Object.assign(Object.assign({}, config), { maxPath: (_a = config === null || config === void 0 ? void 0 : config.maxPath) !== null && _a !== void 0 ? _a : 24, enable: {
93
+ filter: (_c = (_b = config === null || config === void 0 ? void 0 : config.enable) === null || _b === void 0 ? void 0 : _b.filter) !== null && _c !== void 0 ? _c : true,
94
+ handler: (_e = (_d = config === null || config === void 0 ? void 0 : config.enable) === null || _d === void 0 ? void 0 : _d.handler) !== null && _e !== void 0 ? _e : true,
95
+ fallback: (_g = (_f = config === null || config === void 0 ? void 0 : config.enable) === null || _f === void 0 ? void 0 : _f.fallback) !== null && _g !== void 0 ? _g : true,
96
+ after: (_j = (_h = config === null || config === void 0 ? void 0 : config.enable) === null || _h === void 0 ? void 0 : _h.after) !== null && _j !== void 0 ? _j : true,
97
+ catcher: (_l = (_k = config === null || config === void 0 ? void 0 : config.enable) === null || _k === void 0 ? void 0 : _k.catcher) !== null && _l !== void 0 ? _l : true,
98
+ } }), "f");
99
+ __classPrivateFieldSet(this, _Router_routes, __classPrivateFieldGet(this, _Router_instances, "m", _Router_initRoutes).call(this), "f");
100
+ }
101
+ respond(request, ctxInit) {
102
+ return __awaiter(this, void 0, void 0, function* () {
103
+ var _a, _b, _c, _d, _e, _f;
104
+ let response = undefined;
105
+ const method = request.method;
106
+ const url = new URL(request.url);
107
+ let pathname;
108
+ try {
109
+ pathname = decodeURIComponent(url.pathname);
110
+ }
111
+ catch (_g) {
112
+ return new Response(null, {
113
+ status: 400,
114
+ statusText: (0, status_ts_1.getHttpStatusText)(400),
115
+ });
116
+ }
117
+ const parts = [];
118
+ const ctx = Object.assign({ router: this, url,
119
+ request, headers: (_a = ctxInit === null || ctxInit === void 0 ? void 0 : ctxInit.headers) !== null && _a !== void 0 ? _a : new Headers(), params: EMPTY_PARAMS, pathname, $pathname: parts }, ctxInit);
120
+ {
121
+ const count = this.splitPath(pathname, parts, __classPrivateFieldGet(this, _Router_config, "f").maxPath);
122
+ if (count < 0) {
123
+ return count === -1
124
+ ? new Response(null, {
125
+ status: 400,
126
+ statusText: (0, status_ts_1.getHttpStatusText)(400),
127
+ headers: ctx.headers,
128
+ })
129
+ : new Response(null, {
130
+ status: 414,
131
+ statusText: (0, status_ts_1.getHttpStatusText)(414),
132
+ headers: ctx.headers,
133
+ });
134
+ }
135
+ }
136
+ const found = {
137
+ filter: 0,
138
+ handler: 0,
139
+ fallback: 0,
140
+ after: 0,
141
+ catcher: 0,
142
+ };
143
+ try {
144
+ // filters
145
+ if ((_b = __classPrivateFieldGet(this, _Router_config, "f").enable) === null || _b === void 0 ? void 0 : _b.filter) {
146
+ const filterRoutes = __classPrivateFieldGet(this, _Router_instances, "m", _Router_getRouteEntries).call(this, pathname, parts, __classPrivateFieldGet(this, _Router_routes, "f").filter[method], false);
147
+ found.filter = filterRoutes.length;
148
+ if (filterRoutes.length > 0) {
149
+ away: for (const routeEntry of filterRoutes) {
150
+ // parse params
151
+ const params = routeEntry.parseParams(pathname, parts);
152
+ ctx.params = params !== null && params !== void 0 ? params : EMPTY_PARAMS;
153
+ // call request handlers
154
+ for (const handler of routeEntry.pipeline) {
155
+ const resp = yield handler.apply(this, [ctx]);
156
+ if (resp instanceof Response) {
157
+ response = resp;
158
+ break;
159
+ }
160
+ else if (resp === types_ts_1.Break_Pipe) {
161
+ break;
162
+ }
163
+ else if (resp === types_ts_1.Break_Pipeline) {
164
+ break away;
165
+ }
166
+ }
167
+ if (response instanceof Response) {
168
+ break;
169
+ }
170
+ }
171
+ }
172
+ // default filter
173
+ if (!(response instanceof Response) && __classPrivateFieldGet(this, _Router_config, "f").defaultFilter) {
174
+ const resp = yield __classPrivateFieldGet(this, _Router_config, "f").defaultFilter(ctx);
175
+ if (resp instanceof Response) {
176
+ response = resp;
177
+ }
178
+ }
179
+ }
180
+ // handlers
181
+ if (((_c = __classPrivateFieldGet(this, _Router_config, "f").enable) === null || _c === void 0 ? void 0 : _c.handler) && !(response instanceof Response)) {
182
+ const handlerRoutes = __classPrivateFieldGet(this, _Router_instances, "m", _Router_getRouteEntries).call(this, pathname, parts, __classPrivateFieldGet(this, _Router_routes, "f").handler[method], true);
183
+ found.handler = handlerRoutes.length;
184
+ if (handlerRoutes.length > 0) {
185
+ away: for (const routeEntry of handlerRoutes) {
186
+ // parse params
187
+ const params = routeEntry.parseParams(pathname, parts);
188
+ ctx.params = params !== null && params !== void 0 ? params : EMPTY_PARAMS;
189
+ // call request handlers
190
+ for (const handler of routeEntry.pipeline) {
191
+ const resp = yield handler(ctx);
192
+ if (resp instanceof Response) {
193
+ response = resp;
194
+ break;
195
+ }
196
+ else if (resp === types_ts_1.Break_Pipe) {
197
+ break;
198
+ }
199
+ else if (resp === types_ts_1.Break_Pipeline) {
200
+ break away;
201
+ }
202
+ }
203
+ if (response instanceof Response) {
204
+ break;
205
+ }
206
+ }
207
+ }
208
+ }
209
+ // fallbacks
210
+ if (((_d = __classPrivateFieldGet(this, _Router_config, "f").enable) === null || _d === void 0 ? void 0 : _d.fallback) && !(response instanceof Response)) {
211
+ const fallbackRoutes = __classPrivateFieldGet(this, _Router_instances, "m", _Router_getRouteEntries).call(this, pathname, parts, __classPrivateFieldGet(this, _Router_routes, "f").fallback[method], false);
212
+ found.fallback = fallbackRoutes.length;
213
+ if (fallbackRoutes.length > 0) {
214
+ away: for (const routeEntry of fallbackRoutes) {
215
+ // parse params
216
+ const params = routeEntry.parseParams(pathname, parts);
217
+ ctx.params = params !== null && params !== void 0 ? params : EMPTY_PARAMS;
218
+ // call request handlers
219
+ for (const handler of routeEntry.pipeline) {
220
+ const resp = yield handler(ctx);
221
+ if (resp instanceof Response) {
222
+ response = resp;
223
+ break;
224
+ }
225
+ else if (resp === types_ts_1.Break_Pipe) {
226
+ break;
227
+ }
228
+ else if (resp === types_ts_1.Break_Pipeline) {
229
+ break away;
230
+ }
231
+ }
232
+ if (response instanceof Response) {
233
+ break;
234
+ }
235
+ }
236
+ }
237
+ // default fallback
238
+ if (!(response instanceof Response) && __classPrivateFieldGet(this, _Router_config, "f").defaultFallback) {
239
+ const resp = yield __classPrivateFieldGet(this, _Router_config, "f").defaultFallback(ctx);
240
+ if (resp instanceof Response) {
241
+ response = resp;
242
+ }
243
+ }
244
+ }
245
+ // append headers
246
+ if ((response === null || response === void 0 ? void 0 : response.headers) != null) {
247
+ for (const [k, v] of response.headers) {
248
+ ctx.headers.append(k, v);
249
+ }
250
+ }
251
+ // default response to not-implemented or not-found if null
252
+ response =
253
+ response instanceof Response
254
+ ? new Response(response.body, Object.assign(Object.assign({}, response), { status: response.status, statusText: (0, status_ts_1.getHttpStatusText)(response.status), headers: ctx.headers }))
255
+ : found.handler + found.fallback > 0
256
+ ? new Response(null, {
257
+ status: 501,
258
+ statusText: (0, status_ts_1.getHttpStatusText)(501),
259
+ headers: ctx.headers,
260
+ })
261
+ : new Response(null, {
262
+ status: 404,
263
+ statusText: (0, status_ts_1.getHttpStatusText)(404),
264
+ headers: ctx.headers,
265
+ });
266
+ }
267
+ catch (_error) {
268
+ const error = _error instanceof Error ? _error : Error(String(_error));
269
+ ctx.error = error;
270
+ // catchers
271
+ if ((_e = __classPrivateFieldGet(this, _Router_config, "f").enable) === null || _e === void 0 ? void 0 : _e.catcher) {
272
+ const catcherRoutes = __classPrivateFieldGet(this, _Router_instances, "m", _Router_getRouteEntries).call(this, pathname, parts, __classPrivateFieldGet(this, _Router_routes, "f").catcher[method], false);
273
+ found.catcher = catcherRoutes.length;
274
+ if (catcherRoutes.length > 0) {
275
+ away: for (const routeEntry of catcherRoutes) {
276
+ // parse params
277
+ const params = routeEntry.parseParams(url.pathname, parts);
278
+ ctx.params = params !== null && params !== void 0 ? params : EMPTY_PARAMS;
279
+ // call request handlers
280
+ for (const handler of routeEntry.pipeline) {
281
+ const resp = yield handler(ctx);
282
+ if (resp instanceof Response) {
283
+ response = resp;
284
+ break;
285
+ }
286
+ else if (resp === types_ts_1.Break_Pipe) {
287
+ break;
288
+ }
289
+ else if (resp === types_ts_1.Break_Pipeline) {
290
+ break away;
291
+ }
292
+ }
293
+ }
294
+ }
295
+ }
296
+ // default cathcer
297
+ if (!(response instanceof Response) && __classPrivateFieldGet(this, _Router_config, "f").defaultCatcher) {
298
+ const errorCtx = ctx;
299
+ ctx.error = error;
300
+ const resp = yield __classPrivateFieldGet(this, _Router_config, "f").defaultCatcher(errorCtx);
301
+ if (resp instanceof Response) {
302
+ response = resp;
303
+ }
304
+ }
305
+ if (!(response instanceof Response)) {
306
+ const status = ctx.error && ctx.error instanceof types_ts_1.HttpError ? ctx.error.status : 500;
307
+ response = new Response(null, {
308
+ status,
309
+ statusText: (0, status_ts_1.getHttpStatusText)(status),
310
+ });
311
+ }
312
+ // append headers
313
+ for (const [k, v] of response.headers) {
314
+ ctx.headers.append(k, v);
315
+ }
316
+ response = new Response(response.body, Object.assign(Object.assign({}, response), { status: response.status, statusText: (0, status_ts_1.getHttpStatusText)(response.status), headers: ctx.headers }));
317
+ }
318
+ ctx.response = response;
319
+ // afters
320
+ if ((_f = __classPrivateFieldGet(this, _Router_config, "f").enable) === null || _f === void 0 ? void 0 : _f.after) {
321
+ const afterRoutes = __classPrivateFieldGet(this, _Router_instances, "m", _Router_getRouteEntries).call(this, pathname, parts, __classPrivateFieldGet(this, _Router_routes, "f").after[method], false);
322
+ found.after = afterRoutes.length;
323
+ if (afterRoutes.length > 0) {
324
+ away: for (const routeEntry of afterRoutes) {
325
+ // parse params
326
+ const params = routeEntry.parseParams(pathname, parts);
327
+ ctx.params = params !== null && params !== void 0 ? params : EMPTY_PARAMS;
328
+ ctx.response = response;
329
+ // call request handlers
330
+ for (const handler of routeEntry.pipeline) {
331
+ const resp = yield handler(ctx);
332
+ if (resp instanceof Response) {
333
+ response = resp;
334
+ break;
335
+ }
336
+ else if (resp === types_ts_1.Break_Pipe) {
337
+ break;
338
+ }
339
+ else if (resp === types_ts_1.Break_Pipeline) {
340
+ break away;
341
+ }
342
+ }
343
+ if (response instanceof Response) {
344
+ break;
345
+ }
346
+ }
347
+ }
348
+ }
349
+ // default after
350
+ if (__classPrivateFieldGet(this, _Router_config, "f").defaultAfter) {
351
+ const resp = yield __classPrivateFieldGet(this, _Router_config, "f").defaultAfter(ctx);
352
+ if (resp instanceof Response) {
353
+ response = resp;
354
+ }
355
+ }
356
+ return response;
357
+ });
358
+ }
359
+ load(_a) {
360
+ return __awaiter(this, arguments, void 0, function* ({ routesPath, pattern = /\.(js|ts|mjs|cjs)$/, dirPattern = /.*/, processName = (name) => name.substring(0, name.lastIndexOf(".")), }) {
361
+ var _b, e_1, _c, _d;
362
+ try {
363
+ for (var _e = true, _f = __asyncValues((0, utils_node_ts_1.walk)(routesPath)), _g; _g = yield _f.next(), _b = _g.done, !_b; _e = true) {
364
+ _d = _g.value;
365
+ _e = false;
366
+ const node = _d;
367
+ if (node.type === "file") {
368
+ if (!pattern.test(node.name)) {
369
+ continue;
370
+ }
371
+ if (!dirPattern.test(node.parent)) {
372
+ continue;
373
+ }
374
+ let handlersImp;
375
+ try {
376
+ handlersImp = (yield (0, utils_node_ts_1.dynamicImport)(node.fullPath));
377
+ const processedName = decodeURIComponent(processName(node.name));
378
+ const pathname = !node.parent
379
+ ? `/${processedName}`
380
+ : `/${node.parent}/${processedName}`;
381
+ const path = this.translateRouteFilePath(pathname);
382
+ for (const _method of Object.keys(handlersImp)) {
383
+ const _definition = handlersImp[_method];
384
+ let method;
385
+ let upperMethod = _method.toUpperCase();
386
+ let handlerType = "handler";
387
+ if (exports.HTTP_METHODS_UPPER.has(upperMethod)) {
388
+ method = _method;
389
+ }
390
+ else {
391
+ const [spMethod, _handlerType] = _method.split("_", 2);
392
+ if (!(spMethod && _handlerType)) {
393
+ continue;
394
+ }
395
+ upperMethod = spMethod.toUpperCase();
396
+ if (exports.HTTP_METHODS_UPPER.has(upperMethod)) {
397
+ method = spMethod;
398
+ }
399
+ else {
400
+ continue;
401
+ }
402
+ if (exports.HANDLER_TYPES.has(_handlerType === null || _handlerType === void 0 ? void 0 : _handlerType.toLowerCase())) {
403
+ handlerType = _handlerType.toLowerCase();
404
+ }
405
+ else {
406
+ continue;
407
+ }
408
+ }
409
+ const definition = Array.isArray(_definition) || typeof _definition === "function"
410
+ ? { pipeline: _definition }
411
+ : {
412
+ pipeline: _definition.pipeline,
413
+ openApi: _definition.openApi,
414
+ };
415
+ const pipeline = definition.pipeline;
416
+ const openApi = definition.openApi;
417
+ if (openApi != null && handlerType !== "handler") {
418
+ console.warn(`OpenApi definition will be ignored in '${node.path}' ${_method}`);
419
+ }
420
+ if (pipeline == null) {
421
+ throw new types_ts_1.RouterError(`Undefined pipeline in '${node.path}' ${_method}`);
422
+ }
423
+ if (!Array.isArray(pipeline) && typeof pipeline !== "function") {
424
+ throw new types_ts_1.RouterError(`Bad pipeline type in '${node.path}' ${_method}`);
425
+ }
426
+ if (openApi != null && typeof openApi !== "object") {
427
+ throw new types_ts_1.RouterError(`Bad openApi type in '${node.path}' ${_method}`);
428
+ }
429
+ const options = handlerType === "handler" && openApi != null
430
+ ? { openApi }
431
+ : undefined;
432
+ if (Array.isArray(pipeline) || typeof pipeline === "function") {
433
+ __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, handlerType, `${method} ${path}`, pipeline, options);
434
+ }
435
+ }
436
+ }
437
+ catch (error) {
438
+ console.error(`Failed to import route at ${node.fullPath}:`, error);
439
+ }
440
+ }
441
+ }
442
+ }
443
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
444
+ finally {
445
+ try {
446
+ if (!_e && !_b && (_c = _f.return)) yield _c.call(_f);
447
+ }
448
+ finally { if (e_1) throw e_1.error; }
449
+ }
450
+ });
451
+ }
452
+ generateOpenAPI(info) {
453
+ return new Promise((resolve) => {
454
+ var _a, _b, _c, _d;
455
+ const { title = "API", version = "1.0.0" } = info !== null && info !== void 0 ? info : {};
456
+ const paths = {};
457
+ const handlers = __classPrivateFieldGet(this, _Router_routes, "f").handler;
458
+ for (const method of Object.keys(handlers)) {
459
+ const methodHandlers = handlers[method];
460
+ for (const entries of [
461
+ methodHandlers.entries,
462
+ methodHandlers.globs,
463
+ methodHandlers.superGlobs,
464
+ // methodHandlers.superGlobsWithGlobs,
465
+ ])
466
+ for (const bucket of entries) {
467
+ if (bucket == null) {
468
+ continue;
469
+ }
470
+ for (const key of bucket.keys()) {
471
+ const entry = bucket.get(key);
472
+ if (entry == null) {
473
+ continue;
474
+ }
475
+ const pathname = entry.openApiPath;
476
+ const openApi = entry.openApi;
477
+ if (openApi != null) {
478
+ if (paths[pathname] == null) {
479
+ paths[pathname] = {};
480
+ }
481
+ const methodLower = method.toLowerCase();
482
+ const parameters = (_c = (_a = openApi.parameters) !== null && _a !== void 0 ? _a : (_b = entry.params) === null || _b === void 0 ? void 0 : _b.map(([, paramId]) => ({
483
+ name: paramId,
484
+ in: "path",
485
+ required: true,
486
+ schema: { type: "string" },
487
+ }))) !== null && _c !== void 0 ? _c : [];
488
+ const responses = (_d = openApi.responses) !== null && _d !== void 0 ? _d : {
489
+ "200": {
490
+ description: "OK",
491
+ content: {
492
+ "application/json": {
493
+ schema: { type: "object" },
494
+ },
495
+ },
496
+ },
497
+ };
498
+ paths[pathname][methodLower] = Object.assign(Object.assign({}, openApi), { parameters,
499
+ responses });
500
+ }
501
+ }
502
+ }
503
+ }
504
+ resolve({
505
+ openapi: "3.0.0",
506
+ info: { title, version },
507
+ paths,
508
+ });
509
+ });
510
+ }
511
+ all(paths, pipeline, options) {
512
+ paths = Array.isArray(paths) ? paths : [paths];
513
+ const methodPaths = [];
514
+ for (const p of paths) {
515
+ for (const method of exports.HTTP_METHODS.keys()) {
516
+ methodPaths.push(`${method} ${p}`);
517
+ }
518
+ }
519
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "handler", methodPaths, pipeline, options);
520
+ }
521
+ crud(paths, pipeline, options) {
522
+ paths = Array.isArray(paths) ? paths : [paths];
523
+ const methodPaths = [];
524
+ for (const p of paths) {
525
+ for (const method of exports.CRUD_METHODS.keys()) {
526
+ methodPaths.push(`${method} ${p}`);
527
+ }
528
+ }
529
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "handler", methodPaths, pipeline, options);
530
+ }
531
+ head(paths, pipeline, options) {
532
+ paths = Array.isArray(paths) ? paths : [paths];
533
+ const methodPaths = paths.map((p) => `Head ${p}`);
534
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "handler", methodPaths, pipeline, options);
535
+ }
536
+ get(paths, pipeline, options) {
537
+ paths = Array.isArray(paths) ? paths : [paths];
538
+ const methodPaths = paths.map((p) => `Get ${p}`);
539
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "handler", methodPaths, pipeline, options);
540
+ }
541
+ post(paths, pipeline, options) {
542
+ paths = Array.isArray(paths) ? paths : [paths];
543
+ const methodPaths = paths.map((p) => `Post ${p}`);
544
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "handler", methodPaths, pipeline, options);
545
+ }
546
+ put(paths, pipeline, options) {
547
+ paths = Array.isArray(paths) ? paths : [paths];
548
+ const methodPaths = paths.map((p) => `Put ${p}`);
549
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "handler", methodPaths, pipeline, options);
550
+ }
551
+ patch(paths, pipeline, options) {
552
+ paths = Array.isArray(paths) ? paths : [paths];
553
+ const methodPaths = paths.map((p) => `Patch ${p}`);
554
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "handler", methodPaths, pipeline, options);
555
+ }
556
+ delete(paths, pipeline, options) {
557
+ paths = Array.isArray(paths) ? paths : [paths];
558
+ const methodPaths = paths.map((p) => `Delete ${p}`);
559
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "handler", methodPaths, pipeline, options);
560
+ }
561
+ options(paths, pipeline, options) {
562
+ paths = Array.isArray(paths) ? paths : [paths];
563
+ const methodPaths = paths.map((p) => `Options ${p}`);
564
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "handler", methodPaths, pipeline, options);
565
+ }
566
+ trace(paths, pipeline, options) {
567
+ paths = Array.isArray(paths) ? paths : [paths];
568
+ const methodPaths = paths.map((p) => `Trace ${p}`);
569
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "handler", methodPaths, pipeline, options);
570
+ }
571
+ connect(paths, pipeline, options) {
572
+ paths = Array.isArray(paths) ? paths : [paths];
573
+ const methodPaths = paths.map((p) => `Connect ${p}`);
574
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "handler", methodPaths, pipeline, options);
575
+ }
576
+ filterAll(paths, pipeline, options) {
577
+ paths = Array.isArray(paths) ? paths : [paths];
578
+ const methodPaths = [];
579
+ for (const p of paths) {
580
+ for (const method of exports.HTTP_METHODS.keys()) {
581
+ methodPaths.push(`${method} ${p}`);
582
+ }
583
+ }
584
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "filter", methodPaths, pipeline, options);
585
+ }
586
+ filterCrud(paths, pipeline, options) {
587
+ paths = Array.isArray(paths) ? paths : [paths];
588
+ const methodPaths = [];
589
+ for (const p of paths) {
590
+ for (const method of exports.CRUD_METHODS.keys()) {
591
+ methodPaths.push(`${method} ${p}`);
592
+ }
593
+ }
594
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "filter", methodPaths, pipeline, options);
595
+ }
596
+ filterHead(paths, pipeline, options) {
597
+ paths = Array.isArray(paths) ? paths : [paths];
598
+ const methodPaths = paths.map((p) => `Head ${p}`);
599
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "filter", methodPaths, pipeline, options);
600
+ }
601
+ filterGet(paths, pipeline, options) {
602
+ paths = Array.isArray(paths) ? paths : [paths];
603
+ const methodPaths = paths.map((p) => `Get ${p}`);
604
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "filter", methodPaths, pipeline, options);
605
+ }
606
+ filterPost(paths, pipeline, options) {
607
+ paths = Array.isArray(paths) ? paths : [paths];
608
+ const methodPaths = paths.map((p) => `Post ${p}`);
609
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "filter", methodPaths, pipeline, options);
610
+ }
611
+ filterPut(paths, pipeline, options) {
612
+ paths = Array.isArray(paths) ? paths : [paths];
613
+ const methodPaths = paths.map((p) => `Put ${p}`);
614
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "filter", methodPaths, pipeline, options);
615
+ }
616
+ filterPatch(paths, pipeline, options) {
617
+ paths = Array.isArray(paths) ? paths : [paths];
618
+ const methodPaths = paths.map((p) => `Patch ${p}`);
619
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "filter", methodPaths, pipeline, options);
620
+ }
621
+ filterDelete(paths, pipeline, options) {
622
+ paths = Array.isArray(paths) ? paths : [paths];
623
+ const methodPaths = paths.map((p) => `Delete ${p}`);
624
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "filter", methodPaths, pipeline, options);
625
+ }
626
+ filterOptions(paths, pipeline, options) {
627
+ paths = Array.isArray(paths) ? paths : [paths];
628
+ const methodPaths = paths.map((p) => `Options ${p}`);
629
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "filter", methodPaths, pipeline, options);
630
+ }
631
+ filterTrace(paths, pipeline, options) {
632
+ paths = Array.isArray(paths) ? paths : [paths];
633
+ const methodPaths = paths.map((p) => `Trace ${p}`);
634
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "filter", methodPaths, pipeline, options);
635
+ }
636
+ filterConnect(paths, pipeline, options) {
637
+ paths = Array.isArray(paths) ? paths : [paths];
638
+ const methodPaths = paths.map((p) => `Connect ${p}`);
639
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "filter", methodPaths, pipeline, options);
640
+ }
641
+ handleAll(paths, pipeline, options) {
642
+ paths = Array.isArray(paths) ? paths : [paths];
643
+ const methodPaths = [];
644
+ for (const p of paths) {
645
+ for (const method of exports.HTTP_METHODS.keys()) {
646
+ methodPaths.push(`${method} ${p}`);
647
+ }
648
+ }
649
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "handler", methodPaths, pipeline, options);
650
+ }
651
+ handleCrud(paths, pipeline, options) {
652
+ paths = Array.isArray(paths) ? paths : [paths];
653
+ const methodPaths = [];
654
+ for (const p of paths) {
655
+ for (const method of exports.CRUD_METHODS.keys()) {
656
+ methodPaths.push(`${method} ${p}`);
657
+ }
658
+ }
659
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "handler", methodPaths, pipeline, options);
660
+ }
661
+ handleHead(paths, pipeline, options) {
662
+ paths = Array.isArray(paths) ? paths : [paths];
663
+ const methodPaths = paths.map((p) => `Head ${p}`);
664
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "handler", methodPaths, pipeline, options);
665
+ }
666
+ handleGet(paths, pipeline, options) {
667
+ paths = Array.isArray(paths) ? paths : [paths];
668
+ const methodPaths = paths.map((p) => `Get ${p}`);
669
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "handler", methodPaths, pipeline, options);
670
+ }
671
+ handlePost(paths, pipeline, options) {
672
+ paths = Array.isArray(paths) ? paths : [paths];
673
+ const methodPaths = paths.map((p) => `Post ${p}`);
674
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "handler", methodPaths, pipeline, options);
675
+ }
676
+ handlePut(paths, pipeline, options) {
677
+ paths = Array.isArray(paths) ? paths : [paths];
678
+ const methodPaths = paths.map((p) => `Put ${p}`);
679
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "handler", methodPaths, pipeline, options);
680
+ }
681
+ handlePatch(paths, pipeline, options) {
682
+ paths = Array.isArray(paths) ? paths : [paths];
683
+ const methodPaths = paths.map((p) => `Patch ${p}`);
684
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "handler", methodPaths, pipeline, options);
685
+ }
686
+ handleDelete(paths, pipeline, options) {
687
+ paths = Array.isArray(paths) ? paths : [paths];
688
+ const methodPaths = paths.map((p) => `Delete ${p}`);
689
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "handler", methodPaths, pipeline, options);
690
+ }
691
+ handleOptions(paths, pipeline, options) {
692
+ paths = Array.isArray(paths) ? paths : [paths];
693
+ const methodPaths = paths.map((p) => `Options ${p}`);
694
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "handler", methodPaths, pipeline, options);
695
+ }
696
+ handleTrace(paths, pipeline, options) {
697
+ paths = Array.isArray(paths) ? paths : [paths];
698
+ const methodPaths = paths.map((p) => `Trace ${p}`);
699
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "handler", methodPaths, pipeline, options);
700
+ }
701
+ handleConnect(paths, pipeline, options) {
702
+ paths = Array.isArray(paths) ? paths : [paths];
703
+ const methodPaths = paths.map((p) => `Connect ${p}`);
704
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "handler", methodPaths, pipeline, options);
705
+ }
706
+ fallbackAll(paths, pipeline, options) {
707
+ paths = Array.isArray(paths) ? paths : [paths];
708
+ const methodPaths = [];
709
+ for (const p of paths) {
710
+ for (const method of exports.HTTP_METHODS.keys()) {
711
+ methodPaths.push(`${method} ${p}`);
712
+ }
713
+ }
714
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "fallback", methodPaths, pipeline, options);
715
+ }
716
+ fallbackCrud(paths, pipeline, options) {
717
+ paths = Array.isArray(paths) ? paths : [paths];
718
+ const methodPaths = [];
719
+ for (const p of paths) {
720
+ for (const method of exports.CRUD_METHODS.keys()) {
721
+ methodPaths.push(`${method} ${p}`);
722
+ }
723
+ }
724
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "fallback", methodPaths, pipeline, options);
725
+ }
726
+ fallbackHead(paths, pipeline, options) {
727
+ paths = Array.isArray(paths) ? paths : [paths];
728
+ const methodPaths = paths.map((p) => `Head ${p}`);
729
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "fallback", methodPaths, pipeline, options);
730
+ }
731
+ fallbackGet(paths, pipeline, options) {
732
+ paths = Array.isArray(paths) ? paths : [paths];
733
+ const methodPaths = paths.map((p) => `Get ${p}`);
734
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "fallback", methodPaths, pipeline, options);
735
+ }
736
+ fallbackPost(paths, pipeline, options) {
737
+ paths = Array.isArray(paths) ? paths : [paths];
738
+ const methodPaths = paths.map((p) => `Post ${p}`);
739
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "fallback", methodPaths, pipeline, options);
740
+ }
741
+ fallbackPut(paths, pipeline, options) {
742
+ paths = Array.isArray(paths) ? paths : [paths];
743
+ const methodPaths = paths.map((p) => `Put ${p}`);
744
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "fallback", methodPaths, pipeline, options);
745
+ }
746
+ fallbackPatch(paths, pipeline, options) {
747
+ paths = Array.isArray(paths) ? paths : [paths];
748
+ const methodPaths = paths.map((p) => `Patch ${p}`);
749
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "fallback", methodPaths, pipeline, options);
750
+ }
751
+ fallbackDelete(paths, pipeline, options) {
752
+ paths = Array.isArray(paths) ? paths : [paths];
753
+ const methodPaths = paths.map((p) => `Delete ${p}`);
754
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "fallback", methodPaths, pipeline, options);
755
+ }
756
+ fallbackOptions(paths, pipeline, options) {
757
+ paths = Array.isArray(paths) ? paths : [paths];
758
+ const methodPaths = paths.map((p) => `Options ${p}`);
759
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "fallback", methodPaths, pipeline, options);
760
+ }
761
+ fallbackTrace(paths, pipeline, options) {
762
+ paths = Array.isArray(paths) ? paths : [paths];
763
+ const methodPaths = paths.map((p) => `Trace ${p}`);
764
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "fallback", methodPaths, pipeline, options);
765
+ }
766
+ fallbackConnect(paths, pipeline, options) {
767
+ paths = Array.isArray(paths) ? paths : [paths];
768
+ const methodPaths = paths.map((p) => `Connect ${p}`);
769
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "fallback", methodPaths, pipeline, options);
770
+ }
771
+ afterAll(paths, pipeline, options) {
772
+ paths = Array.isArray(paths) ? paths : [paths];
773
+ const methodPaths = [];
774
+ for (const p of paths) {
775
+ for (const method of exports.HTTP_METHODS.keys()) {
776
+ methodPaths.push(`${method} ${p}`);
777
+ }
778
+ }
779
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "after", methodPaths, pipeline, options);
780
+ }
781
+ afterCrud(paths, pipeline, options) {
782
+ paths = Array.isArray(paths) ? paths : [paths];
783
+ const methodPaths = [];
784
+ for (const p of paths) {
785
+ for (const method of exports.CRUD_METHODS.keys()) {
786
+ methodPaths.push(`${method} ${p}`);
787
+ }
788
+ }
789
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "after", methodPaths, pipeline, options);
790
+ }
791
+ afterHead(paths, pipeline, options) {
792
+ paths = Array.isArray(paths) ? paths : [paths];
793
+ const methodPaths = paths.map((p) => `Head ${p}`);
794
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "after", methodPaths, pipeline, options);
795
+ }
796
+ afterGet(paths, pipeline, options) {
797
+ paths = Array.isArray(paths) ? paths : [paths];
798
+ const methodPaths = paths.map((p) => `Get ${p}`);
799
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "after", methodPaths, pipeline, options);
800
+ }
801
+ afterPost(paths, pipeline, options) {
802
+ paths = Array.isArray(paths) ? paths : [paths];
803
+ const methodPaths = paths.map((p) => `Post ${p}`);
804
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "after", methodPaths, pipeline, options);
805
+ }
806
+ afterPut(paths, pipeline, options) {
807
+ paths = Array.isArray(paths) ? paths : [paths];
808
+ const methodPaths = paths.map((p) => `Put ${p}`);
809
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "after", methodPaths, pipeline, options);
810
+ }
811
+ afterPatch(paths, pipeline, options) {
812
+ paths = Array.isArray(paths) ? paths : [paths];
813
+ const methodPaths = paths.map((p) => `Patch ${p}`);
814
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "after", methodPaths, pipeline, options);
815
+ }
816
+ afterDelete(paths, pipeline, options) {
817
+ paths = Array.isArray(paths) ? paths : [paths];
818
+ const methodPaths = paths.map((p) => `Delete ${p}`);
819
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "after", methodPaths, pipeline, options);
820
+ }
821
+ afterOptions(paths, pipeline, options) {
822
+ paths = Array.isArray(paths) ? paths : [paths];
823
+ const methodPaths = paths.map((p) => `Options ${p}`);
824
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "after", methodPaths, pipeline, options);
825
+ }
826
+ afterTrace(paths, pipeline, options) {
827
+ paths = Array.isArray(paths) ? paths : [paths];
828
+ const methodPaths = paths.map((p) => `Trace ${p}`);
829
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "after", methodPaths, pipeline, options);
830
+ }
831
+ afterConnect(paths, pipeline, options) {
832
+ paths = Array.isArray(paths) ? paths : [paths];
833
+ const methodPaths = paths.map((p) => `Connect ${p}`);
834
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "after", methodPaths, pipeline, options);
835
+ }
836
+ catchAll(paths, pipeline, options) {
837
+ paths = Array.isArray(paths) ? paths : [paths];
838
+ const methodPaths = [];
839
+ for (const p of paths) {
840
+ for (const method of exports.HTTP_METHODS.keys()) {
841
+ methodPaths.push(`${method} ${p}`);
842
+ }
843
+ }
844
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "catcher", methodPaths, pipeline, options);
845
+ }
846
+ catchCrud(paths, pipeline, options) {
847
+ paths = Array.isArray(paths) ? paths : [paths];
848
+ const methodPaths = [];
849
+ for (const p of paths) {
850
+ for (const method of exports.CRUD_METHODS.keys()) {
851
+ methodPaths.push(`${method} ${p}`);
852
+ }
853
+ }
854
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "catcher", methodPaths, pipeline, options);
855
+ }
856
+ catchHead(paths, pipeline, options) {
857
+ paths = Array.isArray(paths) ? paths : [paths];
858
+ const methodPaths = paths.map((p) => `Head ${p}`);
859
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "catcher", methodPaths, pipeline, options);
860
+ }
861
+ catchGet(paths, pipeline, options) {
862
+ paths = Array.isArray(paths) ? paths : [paths];
863
+ const methodPaths = paths.map((p) => `Get ${p}`);
864
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "catcher", methodPaths, pipeline, options);
865
+ }
866
+ catchPost(paths, pipeline, options) {
867
+ paths = Array.isArray(paths) ? paths : [paths];
868
+ const methodPaths = paths.map((p) => `Post ${p}`);
869
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "catcher", methodPaths, pipeline, options);
870
+ }
871
+ catchPut(paths, pipeline, options) {
872
+ paths = Array.isArray(paths) ? paths : [paths];
873
+ const methodPaths = paths.map((p) => `Put ${p}`);
874
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "catcher", methodPaths, pipeline, options);
875
+ }
876
+ catchPatch(paths, pipeline, options) {
877
+ paths = Array.isArray(paths) ? paths : [paths];
878
+ const methodPaths = paths.map((p) => `Patch ${p}`);
879
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "catcher", methodPaths, pipeline, options);
880
+ }
881
+ catchDelete(paths, pipeline, options) {
882
+ paths = Array.isArray(paths) ? paths : [paths];
883
+ const methodPaths = paths.map((p) => `Delete ${p}`);
884
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "catcher", methodPaths, pipeline, options);
885
+ }
886
+ catchOptions(paths, pipeline, options) {
887
+ paths = Array.isArray(paths) ? paths : [paths];
888
+ const methodPaths = paths.map((p) => `Options ${p}`);
889
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "catcher", methodPaths, pipeline, options);
890
+ }
891
+ catchTrace(paths, pipeline, options) {
892
+ paths = Array.isArray(paths) ? paths : [paths];
893
+ const methodPaths = paths.map((p) => `Trace ${p}`);
894
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "catcher", methodPaths, pipeline, options);
895
+ }
896
+ catchConnect(paths, pipeline, options) {
897
+ paths = Array.isArray(paths) ? paths : [paths];
898
+ const methodPaths = paths.map((p) => `Connect ${p}`);
899
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "catcher", methodPaths, pipeline, options);
900
+ }
901
+ filter(methodPaths, pipeline, options) {
902
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "filter", methodPaths, pipeline, options);
903
+ }
904
+ handle(methodPaths, pipeline, options) {
905
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "handler", methodPaths, pipeline, options);
906
+ }
907
+ fallback(methodPaths, pipeline, options) {
908
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "fallback", methodPaths, pipeline, options);
909
+ }
910
+ after(methodPaths, pipeline, options) {
911
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "after", methodPaths, pipeline, options);
912
+ }
913
+ catch(methodPaths, pipeline, options) {
914
+ return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "catcher", methodPaths, pipeline, options);
915
+ }
916
+ splitPath(pathname, parts, maxPath) {
917
+ const path_len_1 = pathname.length - 1;
918
+ let count = 0;
919
+ let lastI = 0;
920
+ // parse pathname parts and check path length
921
+ for (let i = 0; i < pathname.length; i++) {
922
+ const cc = pathname.charCodeAt(i);
923
+ if (cc === 47) {
924
+ parts.push(pathname.substring(lastI, i));
925
+ if (i === path_len_1) {
926
+ parts.push("");
927
+ }
928
+ lastI = i + 1;
929
+ count++;
930
+ if (count > maxPath) {
931
+ return -count;
932
+ }
933
+ }
934
+ // null char
935
+ else if (cc === 0) {
936
+ return -1;
937
+ }
938
+ }
939
+ if (lastI < pathname.length) {
940
+ parts.push(pathname.substring(lastI));
941
+ }
942
+ return count;
943
+ }
944
+ translateRouteFilePath(pathname) {
945
+ const parts = pathname.split("/", __classPrivateFieldGet(this, _Router_config, "f").maxPath + 1);
946
+ const parts_len_1 = parts.length - 1;
947
+ let lastPartIsEscaped = false;
948
+ for (let i = 1; i < parts.length; i++) {
949
+ const part = parts[i];
950
+ if (part == null) {
951
+ parts[i] = "";
952
+ continue;
953
+ }
954
+ // validate part
955
+ if (!PATH_PART_REGEX.test(part)) {
956
+ throw new types_ts_1.RouterError(`Invalid path ${pathname} -> ${part}`);
957
+ }
958
+ // parse part
959
+ switch (part) {
960
+ case "":
961
+ break;
962
+ case "[#]":
963
+ parts[i] = "*";
964
+ break;
965
+ case "[##]":
966
+ parts[i] = "**";
967
+ break;
968
+ case "[[#]]":
969
+ parts[i] = "*!";
970
+ break;
971
+ case "[[##]]":
972
+ parts[i] = "**!";
973
+ break;
974
+ default:
975
+ if (part.startsWith("#")) {
976
+ if (i === parts_len_1) {
977
+ lastPartIsEscaped = true;
978
+ }
979
+ parts[i] = part.substring(1);
980
+ }
981
+ else if (part.startsWith("[") && part.endsWith("]")) {
982
+ const nextBracketIdx = part.indexOf("[", 1);
983
+ if (nextBracketIdx < 0) {
984
+ const extractedPart = part.substring(1, part.length - 1);
985
+ // check for ## name
986
+ if (extractedPart.startsWith("##")) {
987
+ parts[i] = "::" + extractedPart.substring(2).trim();
988
+ }
989
+ else {
990
+ // [name]
991
+ parts[i] = ":" + extractedPart;
992
+ }
993
+ }
994
+ else {
995
+ // [[##name]] | [[## name! ]] | [[a,b]name!] | [[a,b] name ] | [[a,b] [name] ]
996
+ const lastBracketIdx = part.indexOf("]", 1);
997
+ const separatorIdx = lastBracketIdx >= 0 ? lastBracketIdx : part.length;
998
+ const paths = part.substring(nextBracketIdx + 1, separatorIdx);
999
+ // [[##name]] | [[## name]]
1000
+ if (paths.startsWith("##")) {
1001
+ const paramId = paths.substring(2).trim();
1002
+ parts[i] = `::${paramId}!`;
1003
+ }
1004
+ else {
1005
+ const paramId = part
1006
+ .substring(separatorIdx + 1, part.length - 1)
1007
+ .trim();
1008
+ // split values a,b,c and replace , with |
1009
+ let newPaths = "";
1010
+ let lastI = 0;
1011
+ for (let i = 0; i < paths.length;) {
1012
+ const cc = paths.charCodeAt(i);
1013
+ if (cc === 44) {
1014
+ newPaths += paths.substring(lastI, i) + "|";
1015
+ lastI = ++i;
1016
+ continue;
1017
+ }
1018
+ i++;
1019
+ }
1020
+ if (lastI < paths.length) {
1021
+ newPaths += paths.substring(lastI);
1022
+ }
1023
+ if (paramId.startsWith("[") && paramId.endsWith("]")) {
1024
+ const extrParamId = paramId
1025
+ .substring(1, paramId.length - 1)
1026
+ .trim();
1027
+ parts[i] = `${newPaths}:${extrParamId}!`;
1028
+ }
1029
+ else {
1030
+ parts[i] = newPaths + ":" + paramId;
1031
+ }
1032
+ }
1033
+ }
1034
+ }
1035
+ }
1036
+ }
1037
+ if (!lastPartIsEscaped &&
1038
+ parts.length > 1 &&
1039
+ parts[parts_len_1] === "index") {
1040
+ parts[parts_len_1] = "";
1041
+ }
1042
+ return parts.join("/");
1043
+ }
1044
+ }
1045
+ exports.Router = Router;
1046
+ _Router_config = new WeakMap(), _Router_routes = new WeakMap(), _Router_instances = new WeakSet(), _Router_register = function _Router_register(handlerType, methodPaths, pipeline, options) {
1047
+ const overwrite = (options === null || options === void 0 ? void 0 : options.overwrite) === true;
1048
+ methodPaths = Array.isArray(methodPaths) ? methodPaths : [methodPaths];
1049
+ pipeline = Array.isArray(pipeline) ? pipeline : [pipeline];
1050
+ for (const methodPath of methodPaths) {
1051
+ const [method, originalPath] = methodPath.split(" ", 2);
1052
+ const processedPaths = __classPrivateFieldGet(this, _Router_instances, "m", _Router_processPath).call(this, originalPath);
1053
+ const { params, paths } = processedPaths;
1054
+ const paramsMap = params ? new Map(params) : undefined;
1055
+ for (const path of paths) {
1056
+ const standardPath = params
1057
+ ? path
1058
+ .split("/")
1059
+ .map((p, idx) => (p === "*" ? `:${paramsMap === null || paramsMap === void 0 ? void 0 : paramsMap.get(idx)}` : p))
1060
+ .join("/")
1061
+ : path;
1062
+ const openApiPath = params
1063
+ ? path
1064
+ .split("/")
1065
+ .map((p, idx) => (p === "*" ? `{${paramsMap === null || paramsMap === void 0 ? void 0 : paramsMap.get(idx)}}` : p))
1066
+ .join("/")
1067
+ : path;
1068
+ const upperMethod = method.toUpperCase();
1069
+ if (!exports.HTTP_METHODS_UPPER.has(upperMethod)) {
1070
+ throw new types_ts_1.RouterError(`Unsupported HTTP Method ${method}`);
1071
+ }
1072
+ const routes = __classPrivateFieldGet(this, _Router_routes, "f")[handlerType][upperMethod];
1073
+ if (!REGISTER_PATH_REGEX.test(path)) {
1074
+ throw new types_ts_1.RouterError(`Invalid path for (${method} ${originalPath} -> ${path})`);
1075
+ }
1076
+ const parts = path.split("/", __classPrivateFieldGet(this, _Router_config, "f").maxPath + 1);
1077
+ if (parts.length - 1 > __classPrivateFieldGet(this, _Router_config, "f").maxPath) {
1078
+ throw new types_ts_1.RouterError(`Path parts length limit exceeded ${__classPrivateFieldGet(this, _Router_config, "f").maxPath}`);
1079
+ }
1080
+ const parts_len_1 = parts.length - 1;
1081
+ const hasGlob = parts.some((p) => p === "*");
1082
+ const superGlobIndex = path.endsWith("/**") ? path.length - 3 : -1;
1083
+ const hasSuperGlob = superGlobIndex >= 0;
1084
+ const entry = {
1085
+ parseParams: parseParams.bind(null, hasSuperGlob ? superGlobIndex + 1 : undefined, params),
1086
+ params,
1087
+ pipeline,
1088
+ originalPath,
1089
+ standardPath,
1090
+ openApiPath,
1091
+ path,
1092
+ pathParts: parts,
1093
+ openApi: options === null || options === void 0 ? void 0 : options.openApi,
1094
+ };
1095
+ // check for super globs
1096
+ if (hasSuperGlob) {
1097
+ if (hasGlob) {
1098
+ throw new types_ts_1.RouterError(`SuperGlob route with Globs are not allowed. for (${method} ${originalPath} -> ${path})`);
1099
+ }
1100
+ let superGlobEntries = routes.superGlobs[parts_len_1];
1101
+ const basePath = path.substring(0, superGlobIndex + 1);
1102
+ if (!overwrite &&
1103
+ superGlobEntries &&
1104
+ superGlobEntries.has(basePath)) {
1105
+ throw new types_ts_1.RouterError(`SuperGlob route already set for (${method} ${originalPath} -> ${path})`);
1106
+ }
1107
+ if (superGlobEntries == null) {
1108
+ superGlobEntries = new Map();
1109
+ routes.superGlobs[parts_len_1] = superGlobEntries;
1110
+ }
1111
+ superGlobEntries.set(basePath, entry);
1112
+ }
1113
+ else if (hasGlob) {
1114
+ // check for globs
1115
+ let globEntries = routes.globs[parts.length];
1116
+ if (globEntries) {
1117
+ if (!overwrite && globEntries && globEntries.has(path)) {
1118
+ throw new types_ts_1.RouterError(`Glob route already set for (${method} ${originalPath} -> ${path})`);
1119
+ }
1120
+ // check for collision
1121
+ for (const globEntry of globEntries.values()) {
1122
+ let collision = -1;
1123
+ for (let i = 1; i < parts.length; i++) {
1124
+ if (parts[i] === "*" && globEntry.pathParts[i] === "*") {
1125
+ collision = i;
1126
+ }
1127
+ else if (parts[i] !== globEntry.pathParts[i]) {
1128
+ collision = -1;
1129
+ break;
1130
+ }
1131
+ }
1132
+ if (collision >= 0 && !overwrite) {
1133
+ throw new types_ts_1.RouterError(`Route collision for (${method} ${originalPath} -> ${path} with ${globEntry.originalPath} at ${parts.slice(0, collision + 1).join("/")})`);
1134
+ }
1135
+ }
1136
+ }
1137
+ if (globEntries == null) {
1138
+ globEntries = new Map();
1139
+ routes.globs[parts.length] = globEntries;
1140
+ }
1141
+ globEntries.set(path, entry);
1142
+ }
1143
+ else {
1144
+ let entries = routes.entries[parts.length];
1145
+ if (!overwrite && entries && entries.has(path)) {
1146
+ throw new types_ts_1.RouterError(`Route already set for (${method} ${originalPath} -> ${path})`);
1147
+ }
1148
+ if (entries == null) {
1149
+ entries = new Map();
1150
+ routes.entries[parts.length] = entries;
1151
+ }
1152
+ entries.set(path, entry);
1153
+ }
1154
+ }
1155
+ }
1156
+ return this;
1157
+ }, _Router_processPath = function _Router_processPath(path) {
1158
+ const processedPaths = {
1159
+ paths: [""],
1160
+ };
1161
+ const parts = path.split("/", __classPrivateFieldGet(this, _Router_config, "f").maxPath + 1);
1162
+ const parts_len_1 = parts.length - 1;
1163
+ for (let i = 1; i < parts.length; i++) {
1164
+ const part = parts[i];
1165
+ const partIncludesPipe = part.includes("|");
1166
+ const partIncludesColon = part.includes(":");
1167
+ if (partIncludesPipe && !partIncludesColon) {
1168
+ const subParts = part.split("|");
1169
+ const prevProcessedPath = [...processedPaths.paths];
1170
+ for (let k = 0; k < processedPaths.paths.length; k++) {
1171
+ processedPaths.paths[k] += "/" + subParts[0];
1172
+ }
1173
+ for (let j = 1; j < subParts.length; j++) {
1174
+ for (let k = 0; k < prevProcessedPath.length; k++) {
1175
+ processedPaths.paths.push(prevProcessedPath[k] + "/" + subParts[j]);
1176
+ }
1177
+ }
1178
+ }
1179
+ else if (partIncludesColon && part.startsWith("::")) {
1180
+ // /::named-super-glob
1181
+ const endTokenIdx = part.lastIndexOf("!");
1182
+ const paramId = endTokenIdx > 0 ? part.substring(2, endTokenIdx) : part.substring(2);
1183
+ if (processedPaths.params == null) {
1184
+ processedPaths.params = [];
1185
+ }
1186
+ processedPaths.params.push([i, paramId]);
1187
+ if (endTokenIdx > 0) {
1188
+ const prevProcessedPath = [...processedPaths.paths];
1189
+ for (let k = 0; k < prevProcessedPath.length; k++) {
1190
+ processedPaths.paths.push(prevProcessedPath[k] + "/**");
1191
+ }
1192
+ }
1193
+ else {
1194
+ for (let j = 0; j < processedPaths.paths.length; j++) {
1195
+ processedPaths.paths[j] += "/**";
1196
+ }
1197
+ }
1198
+ break;
1199
+ }
1200
+ else if (partIncludesColon) {
1201
+ // /:param | /:param! | /a|b|c:certain-param
1202
+ if (processedPaths.params == null) {
1203
+ processedPaths.params = [];
1204
+ }
1205
+ const colonIdx = partIncludesPipe
1206
+ ? part.lastIndexOf(":")
1207
+ : part.indexOf(":");
1208
+ const subPartsStr = part.substring(0, colonIdx);
1209
+ const endTokenIdx = part.lastIndexOf("!");
1210
+ const paramId = endTokenIdx > 0
1211
+ ? part.substring(colonIdx + 1, endTokenIdx)
1212
+ : part.substring(colonIdx + 1);
1213
+ processedPaths.params.push([i, paramId]);
1214
+ if (colonIdx > 0) {
1215
+ const subParts = subPartsStr.split("|");
1216
+ const prevProcessedPath = [...processedPaths.paths];
1217
+ if (endTokenIdx < 0) {
1218
+ for (let k = 0; k < processedPaths.paths.length; k++) {
1219
+ processedPaths.paths[k] += "/" + subParts[0];
1220
+ }
1221
+ for (let j = 1; j < subParts.length; j++) {
1222
+ for (let k = 0; k < prevProcessedPath.length; k++) {
1223
+ processedPaths.paths.push(prevProcessedPath[k] + "/" + subParts[j]);
1224
+ }
1225
+ }
1226
+ }
1227
+ else {
1228
+ for (let j = 0; j < subParts.length; j++) {
1229
+ for (let k = 0; k < prevProcessedPath.length; k++) {
1230
+ processedPaths.paths.push(prevProcessedPath[k] + "/" + subParts[j]);
1231
+ }
1232
+ }
1233
+ }
1234
+ }
1235
+ else if (endTokenIdx > 0) {
1236
+ const prevProcessedPath = [...processedPaths.paths];
1237
+ for (let k = 0; k < prevProcessedPath.length; k++) {
1238
+ processedPaths.paths.push(prevProcessedPath[k] + "/*");
1239
+ }
1240
+ }
1241
+ else {
1242
+ for (let j = 0; j < processedPaths.paths.length; j++) {
1243
+ processedPaths.paths[j] += "/*";
1244
+ }
1245
+ }
1246
+ }
1247
+ else if (part === "*!" || (i >= parts_len_1 && part === "**!")) {
1248
+ const endTokenIdx = part.lastIndexOf("!");
1249
+ const globPath = "/" +
1250
+ (endTokenIdx > 0
1251
+ ? part.substring(0, endTokenIdx)
1252
+ : part.substring(0));
1253
+ const prevProcessedPath = [...processedPaths.paths];
1254
+ for (let k = 0; k < prevProcessedPath.length; k++) {
1255
+ processedPaths.paths.push(prevProcessedPath[k] + globPath);
1256
+ }
1257
+ }
1258
+ else {
1259
+ for (let j = 0; j < processedPaths.paths.length; j++) {
1260
+ processedPaths.paths[j] += "/" + part;
1261
+ }
1262
+ }
1263
+ }
1264
+ return processedPaths;
1265
+ }, _Router_getRouteEntries = function _Router_getRouteEntries(pathname, parts, routes, noBubble) {
1266
+ var _a;
1267
+ if (routes == null)
1268
+ return [];
1269
+ const routeEntries = [];
1270
+ const parts_len_1 = parts.length - 1;
1271
+ // match exact
1272
+ {
1273
+ const routeEntry = (_a = routes.entries[parts.length]) === null || _a === void 0 ? void 0 : _a.get(pathname);
1274
+ if (routeEntry != null) {
1275
+ routeEntries.push(routeEntry);
1276
+ if (noBubble) {
1277
+ return routeEntries;
1278
+ }
1279
+ }
1280
+ }
1281
+ {
1282
+ // match globs *
1283
+ const globRoutes = routes.globs[parts.length];
1284
+ if (globRoutes != null) {
1285
+ let bestRoute = undefined;
1286
+ for (const entry of globRoutes.values()) {
1287
+ const entryPathParts = entry.pathParts;
1288
+ let matching = true;
1289
+ for (let i = 1; i < parts.length; i++) {
1290
+ const part = parts[i];
1291
+ const globPart = entryPathParts[i];
1292
+ const isGlob = globPart === "*";
1293
+ if (!isGlob && part !== globPart) {
1294
+ matching = false;
1295
+ break;
1296
+ }
1297
+ // check precedence by specificity with `bestRoute`
1298
+ if (bestRoute != null) {
1299
+ const bestRoutePathPart = bestRoute.pathParts[i];
1300
+ if (isGlob && bestRoutePathPart !== globPart) {
1301
+ matching = false;
1302
+ break;
1303
+ }
1304
+ }
1305
+ }
1306
+ if (matching) {
1307
+ bestRoute = entry;
1308
+ }
1309
+ }
1310
+ if (bestRoute != null) {
1311
+ routeEntries.push(bestRoute);
1312
+ if (noBubble) {
1313
+ return routeEntries;
1314
+ }
1315
+ }
1316
+ }
1317
+ }
1318
+ {
1319
+ // match super globs **
1320
+ let globPath = pathname.length > 1
1321
+ ? pathname.substring(0, pathname.lastIndexOf("/", pathname.length - 1) + 1)
1322
+ : pathname;
1323
+ for (let i = parts_len_1; i > 0; i--,
1324
+ globPath = globPath.substring(0, globPath.lastIndexOf("/", globPath.length - 2) + 1)) {
1325
+ const superGlobRoutes = routes.superGlobs[i];
1326
+ if (superGlobRoutes != null) {
1327
+ const entry = superGlobRoutes.get(globPath);
1328
+ if (entry != null) {
1329
+ routeEntries.push(entry);
1330
+ if (noBubble) {
1331
+ break;
1332
+ }
1333
+ }
1334
+ }
1335
+ }
1336
+ }
1337
+ return routeEntries;
1338
+ }, _Router_InitEntries = function _Router_InitEntries(method) {
1339
+ return {
1340
+ method,
1341
+ entries: new Array(__classPrivateFieldGet(this, _Router_config, "f").maxPath + 1),
1342
+ globs: new Array(__classPrivateFieldGet(this, _Router_config, "f").maxPath + 1),
1343
+ superGlobs: new Array(__classPrivateFieldGet(this, _Router_config, "f").maxPath + 1),
1344
+ };
1345
+ }, _Router_initRoutes = function _Router_initRoutes() {
1346
+ const routes = {};
1347
+ for (const handlerType of exports.HANDLER_TYPES.keys()) {
1348
+ routes[handlerType] = {
1349
+ HEAD: __classPrivateFieldGet(this, _Router_instances, "m", _Router_InitEntries).call(this, "HEAD"),
1350
+ GET: __classPrivateFieldGet(this, _Router_instances, "m", _Router_InitEntries).call(this, "GET"),
1351
+ POST: __classPrivateFieldGet(this, _Router_instances, "m", _Router_InitEntries).call(this, "POST"),
1352
+ PUT: __classPrivateFieldGet(this, _Router_instances, "m", _Router_InitEntries).call(this, "PUT"),
1353
+ PATCH: __classPrivateFieldGet(this, _Router_instances, "m", _Router_InitEntries).call(this, "PATCH"),
1354
+ DELETE: __classPrivateFieldGet(this, _Router_instances, "m", _Router_InitEntries).call(this, "DELETE"),
1355
+ OPTIONS: __classPrivateFieldGet(this, _Router_instances, "m", _Router_InitEntries).call(this, "OPTIONS"),
1356
+ TRACE: __classPrivateFieldGet(this, _Router_instances, "m", _Router_InitEntries).call(this, "TRACE"),
1357
+ CONNECT: __classPrivateFieldGet(this, _Router_instances, "m", _Router_InitEntries).call(this, "CONNECT"),
1358
+ };
1359
+ }
1360
+ return routes;
1361
+ };
1362
+ const parseParams = (superGlobIndex, params, pathname, parts) => {
1363
+ if (params == null && superGlobIndex == null)
1364
+ return undefined;
1365
+ const paramsRec = {};
1366
+ if (params != null && superGlobIndex != null) {
1367
+ const name = params[0][1];
1368
+ paramsRec[name] = pathname.substring(superGlobIndex);
1369
+ }
1370
+ else if (params != null) {
1371
+ for (const [idx, paramId] of params) {
1372
+ paramsRec[paramId] = parts[idx];
1373
+ }
1374
+ }
1375
+ return paramsRec;
1376
+ };
1377
+ exports.default = Router;
1378
+ //# sourceMappingURL=router.js.map