@bepalo/spine 1.5.17 → 2.7.19

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 (110) hide show
  1. package/README.md +532 -1
  2. package/dist/auth-middlewares.d.ts.map +1 -1
  3. package/dist/auth-middlewares.js +1 -0
  4. package/dist/auth-middlewares.js.map +1 -1
  5. package/dist/cache.d.ts +72 -0
  6. package/dist/cache.d.ts.map +1 -0
  7. package/dist/cache.js +387 -0
  8. package/dist/cache.js.map +1 -0
  9. package/dist/cjs/auth-middlewares.d.ts.map +1 -1
  10. package/dist/cjs/auth-middlewares.js +1 -0
  11. package/dist/cjs/auth-middlewares.js.map +1 -1
  12. package/dist/cjs/cache.d.ts +72 -0
  13. package/dist/cjs/cache.d.ts.map +1 -0
  14. package/dist/cjs/cache.js +387 -0
  15. package/dist/cjs/cache.js.map +1 -0
  16. package/dist/cjs/exp-cache.d.ts +101 -0
  17. package/dist/cjs/exp-cache.d.ts.map +1 -0
  18. package/dist/cjs/exp-cache.js +551 -0
  19. package/dist/cjs/exp-cache.js.map +1 -0
  20. package/dist/cjs/generator.d.ts +142 -19
  21. package/dist/cjs/generator.d.ts.map +1 -1
  22. package/dist/cjs/generator.js +416 -36
  23. package/dist/cjs/generator.js.map +1 -1
  24. package/dist/cjs/helpers.d.ts +49 -2
  25. package/dist/cjs/helpers.d.ts.map +1 -1
  26. package/dist/cjs/helpers.js +169 -14
  27. package/dist/cjs/helpers.js.map +1 -1
  28. package/dist/cjs/index.d.ts +2 -0
  29. package/dist/cjs/index.d.ts.map +1 -1
  30. package/dist/cjs/index.js +3 -0
  31. package/dist/cjs/index.js.map +1 -1
  32. package/dist/cjs/linked-list.d.ts +35 -0
  33. package/dist/cjs/linked-list.d.ts.map +1 -0
  34. package/dist/cjs/linked-list.js +300 -0
  35. package/dist/cjs/linked-list.js.map +1 -0
  36. package/dist/cjs/middlewares.d.ts +264 -28
  37. package/dist/cjs/middlewares.d.ts.map +1 -1
  38. package/dist/cjs/middlewares.js +691 -44
  39. package/dist/cjs/middlewares.js.map +1 -1
  40. package/dist/cjs/parsers.d.ts +32 -10
  41. package/dist/cjs/parsers.d.ts.map +1 -1
  42. package/dist/cjs/parsers.js +84 -46
  43. package/dist/cjs/parsers.js.map +1 -1
  44. package/dist/cjs/router.d.ts +5 -6
  45. package/dist/cjs/router.d.ts.map +1 -1
  46. package/dist/cjs/router.js +272 -149
  47. package/dist/cjs/router.js.map +1 -1
  48. package/dist/cjs/status.d.ts.map +1 -1
  49. package/dist/cjs/status.js +80 -79
  50. package/dist/cjs/status.js.map +1 -1
  51. package/dist/cjs/types.d.ts +74 -2
  52. package/dist/cjs/types.d.ts.map +1 -1
  53. package/dist/cjs/types.js +15 -2
  54. package/dist/cjs/types.js.map +1 -1
  55. package/dist/cjs/utils.d.ts +1 -0
  56. package/dist/cjs/utils.d.ts.map +1 -1
  57. package/dist/cjs/utils.js +1 -0
  58. package/dist/cjs/utils.js.map +1 -1
  59. package/dist/cjs/utils.node.d.ts +1 -1
  60. package/dist/cjs/utils.node.d.ts.map +1 -1
  61. package/dist/cjs/utils.node.js +31 -7
  62. package/dist/cjs/utils.node.js.map +1 -1
  63. package/dist/exp-cache.d.ts +101 -0
  64. package/dist/exp-cache.d.ts.map +1 -0
  65. package/dist/exp-cache.js +551 -0
  66. package/dist/exp-cache.js.map +1 -0
  67. package/dist/generator.d.ts +142 -19
  68. package/dist/generator.d.ts.map +1 -1
  69. package/dist/generator.js +416 -36
  70. package/dist/generator.js.map +1 -1
  71. package/dist/helpers.d.ts +49 -2
  72. package/dist/helpers.d.ts.map +1 -1
  73. package/dist/helpers.js +169 -14
  74. package/dist/helpers.js.map +1 -1
  75. package/dist/index.d.ts +2 -0
  76. package/dist/index.d.ts.map +1 -1
  77. package/dist/index.js +3 -0
  78. package/dist/index.js.map +1 -1
  79. package/dist/linked-list.d.ts +35 -0
  80. package/dist/linked-list.d.ts.map +1 -0
  81. package/dist/linked-list.js +300 -0
  82. package/dist/linked-list.js.map +1 -0
  83. package/dist/middlewares.d.ts +264 -28
  84. package/dist/middlewares.d.ts.map +1 -1
  85. package/dist/middlewares.js +691 -44
  86. package/dist/middlewares.js.map +1 -1
  87. package/dist/parsers.d.ts +32 -10
  88. package/dist/parsers.d.ts.map +1 -1
  89. package/dist/parsers.js +84 -46
  90. package/dist/parsers.js.map +1 -1
  91. package/dist/router.d.ts +5 -6
  92. package/dist/router.d.ts.map +1 -1
  93. package/dist/router.js +272 -149
  94. package/dist/router.js.map +1 -1
  95. package/dist/status.d.ts.map +1 -1
  96. package/dist/status.js +80 -79
  97. package/dist/status.js.map +1 -1
  98. package/dist/types.d.ts +74 -2
  99. package/dist/types.d.ts.map +1 -1
  100. package/dist/types.js +15 -2
  101. package/dist/types.js.map +1 -1
  102. package/dist/utils.d.ts +1 -0
  103. package/dist/utils.d.ts.map +1 -1
  104. package/dist/utils.js +1 -0
  105. package/dist/utils.js.map +1 -1
  106. package/dist/utils.node.d.ts +1 -1
  107. package/dist/utils.node.d.ts.map +1 -1
  108. package/dist/utils.node.js +31 -7
  109. package/dist/utils.node.js.map +1 -1
  110. package/package.json +6 -2
package/dist/router.js CHANGED
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
+ // src/router.ts
2
3
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
4
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
5
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -85,22 +86,22 @@ class Router {
85
86
  return Object.assign({}, __classPrivateFieldGet(this, _Router_config, "f").enable);
86
87
  }
87
88
  constructor(config) {
88
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
89
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
89
90
  _Router_instances.add(this);
90
91
  _Router_config.set(this, void 0);
91
92
  _Router_routes.set(this, void 0);
92
93
  __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
94
  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,
95
+ fallback: (_e = (_d = config === null || config === void 0 ? void 0 : config.enable) === null || _d === void 0 ? void 0 : _d.fallback) !== null && _e !== void 0 ? _e : true,
96
+ after: (_g = (_f = config === null || config === void 0 ? void 0 : config.enable) === null || _f === void 0 ? void 0 : _f.after) !== null && _g !== void 0 ? _g : true,
97
+ catcher: (_j = (_h = config === null || config === void 0 ? void 0 : config.enable) === null || _h === void 0 ? void 0 : _h.catcher) !== null && _j !== void 0 ? _j : true,
98
98
  } }), "f");
99
99
  __classPrivateFieldSet(this, _Router_routes, __classPrivateFieldGet(this, _Router_instances, "m", _Router_initRoutes).call(this), "f");
100
100
  }
101
101
  respond(request, ctxInit) {
102
102
  return __awaiter(this, void 0, void 0, function* () {
103
- var _a, _b, _c, _d, _e, _f;
103
+ var _a, _b, _c, _d, _e;
104
+ const startTimestamp = performance.now();
104
105
  const requestTimestamp = Date.now();
105
106
  const method = request.method;
106
107
  const url = new URL(request.url);
@@ -109,7 +110,7 @@ class Router {
109
110
  try {
110
111
  pathname = decodeURIComponent(url.pathname);
111
112
  }
112
- catch (_g) {
113
+ catch (_f) {
113
114
  return new Response(null, {
114
115
  status: 400,
115
116
  statusText: (0, status_ts_1.getHttpStatusText)(400),
@@ -117,7 +118,7 @@ class Router {
117
118
  }
118
119
  const parts = [];
119
120
  const ctx = Object.assign(Object.assign({ router: this, url,
120
- 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), { timestamps: Object.assign({ request: requestTimestamp, response: requestTimestamp }, ctxInit === null || ctxInit === void 0 ? void 0 : ctxInit.timestamps) });
121
+ 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), { timestamps: Object.assign({ request: requestTimestamp, start: startTimestamp, end: startTimestamp }, ctxInit === null || ctxInit === void 0 ? void 0 : ctxInit.timestamps) });
121
122
  {
122
123
  const count = this.splitPath(pathname, parts, __classPrivateFieldGet(this, _Router_config, "f").maxPath);
123
124
  if (count < 0) {
@@ -142,72 +143,21 @@ class Router {
142
143
  catcher: 0,
143
144
  };
144
145
  try {
145
- // get handlers first to check if any exist before filtering
146
- const handlerRoutes = __classPrivateFieldGet(this, _Router_instances, "m", _Router_getRouteEntries).call(this, pathname, parts, __classPrivateFieldGet(this, _Router_routes, "f").handler[method], true);
147
- found.handler = handlerRoutes.length;
148
- // for optmization, load fallbacks here only if necesasry
149
- // i.e. no handlers have been found or defaultFallback not set.
150
- // if fallback routes have not been loaded now then they will be lazy
151
- // loaded later.
152
- let handlerOrFallbackFound = __classPrivateFieldGet(this, _Router_config, "f").defaultFallback != null || found.handler > 0;
153
- let fallbacksLoaded = false;
154
- // get fallbacks if handlers have not been found
155
- let fallbackRoutes = [];
156
- if (!handlerOrFallbackFound && ((_b = __classPrivateFieldGet(this, _Router_config, "f").enable) === null || _b === void 0 ? void 0 : _b.fallback)) {
157
- fallbackRoutes = __classPrivateFieldGet(this, _Router_instances, "m", _Router_getRouteEntries).call(this, pathname, parts, __classPrivateFieldGet(this, _Router_routes, "f").fallback[method], false);
158
- found.fallback = fallbackRoutes.length;
159
- handlerOrFallbackFound = found.fallback > 0;
160
- fallbacksLoaded = true;
161
- }
162
- if (handlerOrFallbackFound) {
163
- // filters
164
- if ((_c = __classPrivateFieldGet(this, _Router_config, "f").enable) === null || _c === void 0 ? void 0 : _c.filter) {
165
- const filterRoutes = __classPrivateFieldGet(this, _Router_instances, "m", _Router_getRouteEntries).call(this, pathname, parts, __classPrivateFieldGet(this, _Router_routes, "f").filter[method], false);
166
- found.filter = filterRoutes.length;
167
- if (filterRoutes.length > 0) {
168
- away: for (const routeEntry of filterRoutes) {
169
- // parse params
170
- const params = routeEntry.parseParams(pathname, parts);
171
- ctx.params = params !== null && params !== void 0 ? params : EMPTY_PARAMS;
172
- // call request handlers
173
- for (const handler of routeEntry.pipe) {
174
- const resp = yield handler.apply(this, [ctx]);
175
- if (resp instanceof Response) {
176
- response = resp;
177
- break;
178
- }
179
- else if (resp === types_ts_1.Break_Pipe) {
180
- break;
181
- }
182
- else if (resp === types_ts_1.Break_Pipeline) {
183
- break away;
184
- }
185
- }
186
- if (response instanceof Response) {
187
- break;
188
- }
189
- }
190
- }
191
- // default filter
192
- if (!(response instanceof Response) && __classPrivateFieldGet(this, _Router_config, "f").defaultFilter) {
193
- const resp = yield __classPrivateFieldGet(this, _Router_config, "f").defaultFilter(ctx);
194
- if (resp instanceof Response) {
195
- response = resp;
196
- }
197
- }
198
- }
199
- // handlers
200
- if (handlerRoutes.length > 0 && !(response instanceof Response)) {
201
- away: for (const routeEntry of handlerRoutes) {
146
+ // filters
147
+ if ((_b = __classPrivateFieldGet(this, _Router_config, "f").enable) === null || _b === void 0 ? void 0 : _b.filter) {
148
+ const filterRoutes = __classPrivateFieldGet(this, _Router_instances, "m", _Router_getRouteEntries).call(this, pathname, parts, __classPrivateFieldGet(this, _Router_routes, "f").filter[method], false);
149
+ found.filter = filterRoutes.length;
150
+ if (filterRoutes.length > 0) {
151
+ away: for (const routeEntry of filterRoutes) {
202
152
  // parse params
203
153
  const params = routeEntry.parseParams(pathname, parts);
204
154
  ctx.params = params !== null && params !== void 0 ? params : EMPTY_PARAMS;
205
155
  // call request handlers
206
156
  for (const handler of routeEntry.pipe) {
207
- const resp = yield handler(ctx);
157
+ const resp = yield handler.apply(this, [ctx]);
208
158
  if (resp instanceof Response) {
209
159
  response = resp;
210
- break;
160
+ break away;
211
161
  }
212
162
  else if (resp === types_ts_1.Break_Pipe) {
213
163
  break;
@@ -216,46 +166,69 @@ class Router {
216
166
  break away;
217
167
  }
218
168
  }
219
- if (response instanceof Response) {
220
- break;
221
- }
222
169
  }
223
170
  }
224
- // fallbacks
225
- if (((_d = __classPrivateFieldGet(this, _Router_config, "f").enable) === null || _d === void 0 ? void 0 : _d.fallback) && !(response instanceof Response)) {
226
- if (!fallbacksLoaded) {
227
- fallbackRoutes = __classPrivateFieldGet(this, _Router_instances, "m", _Router_getRouteEntries).call(this, pathname, parts, __classPrivateFieldGet(this, _Router_routes, "f").fallback[method], false);
171
+ // default filter
172
+ if (!(response instanceof Response) && __classPrivateFieldGet(this, _Router_config, "f").defaultFilter) {
173
+ const resp = yield __classPrivateFieldGet(this, _Router_config, "f").defaultFilter(ctx);
174
+ if (resp instanceof Response) {
175
+ response = resp;
228
176
  }
229
- away: for (const routeEntry of fallbackRoutes) {
230
- // parse params
231
- const params = routeEntry.parseParams(pathname, parts);
232
- ctx.params = params !== null && params !== void 0 ? params : EMPTY_PARAMS;
233
- // call request handlers
234
- for (const handler of routeEntry.pipe) {
235
- const resp = yield handler(ctx);
236
- if (resp instanceof Response) {
237
- response = resp;
238
- break;
239
- }
240
- else if (resp === types_ts_1.Break_Pipe) {
241
- break;
242
- }
243
- else if (resp === types_ts_1.Break_Pipeline) {
244
- break away;
245
- }
177
+ }
178
+ }
179
+ const handlerRoutes = __classPrivateFieldGet(this, _Router_instances, "m", _Router_getRouteEntries).call(this, pathname, parts, __classPrivateFieldGet(this, _Router_routes, "f").handler[method], true);
180
+ found.handler = handlerRoutes.length;
181
+ // handlers
182
+ if (handlerRoutes.length > 0 && !(response instanceof Response)) {
183
+ away: for (const routeEntry of handlerRoutes) {
184
+ // parse params
185
+ const params = routeEntry.parseParams(pathname, parts);
186
+ ctx.params = params !== null && params !== void 0 ? params : EMPTY_PARAMS;
187
+ // call request handlers
188
+ for (const handler of routeEntry.pipe) {
189
+ const resp = yield handler(ctx);
190
+ if (resp instanceof Response) {
191
+ response = resp;
192
+ break away;
246
193
  }
247
- if (response instanceof Response) {
194
+ else if (resp === types_ts_1.Break_Pipe) {
248
195
  break;
249
196
  }
197
+ else if (resp === types_ts_1.Break_Pipeline) {
198
+ break away;
199
+ }
250
200
  }
251
- // default fallback
252
- if (!(response instanceof Response) && __classPrivateFieldGet(this, _Router_config, "f").defaultFallback) {
253
- const resp = yield __classPrivateFieldGet(this, _Router_config, "f").defaultFallback(ctx);
201
+ }
202
+ }
203
+ // fallbacks
204
+ if (((_c = __classPrivateFieldGet(this, _Router_config, "f").enable) === null || _c === void 0 ? void 0 : _c.fallback) && !(response instanceof Response)) {
205
+ const fallbackRoutes = __classPrivateFieldGet(this, _Router_instances, "m", _Router_getRouteEntries).call(this, pathname, parts, __classPrivateFieldGet(this, _Router_routes, "f").fallback[method], false);
206
+ away: for (const routeEntry of fallbackRoutes) {
207
+ // parse params
208
+ const params = routeEntry.parseParams(pathname, parts);
209
+ ctx.params = params !== null && params !== void 0 ? params : EMPTY_PARAMS;
210
+ // call request handlers
211
+ for (const handler of routeEntry.pipe) {
212
+ const resp = yield handler(ctx);
254
213
  if (resp instanceof Response) {
255
214
  response = resp;
215
+ break away;
216
+ }
217
+ else if (resp === types_ts_1.Break_Pipe) {
218
+ break;
219
+ }
220
+ else if (resp === types_ts_1.Break_Pipeline) {
221
+ break away;
256
222
  }
257
223
  }
258
224
  }
225
+ // default fallback
226
+ if (!(response instanceof Response) && __classPrivateFieldGet(this, _Router_config, "f").defaultFallback) {
227
+ const resp = yield __classPrivateFieldGet(this, _Router_config, "f").defaultFallback(ctx);
228
+ if (resp instanceof Response) {
229
+ response = resp;
230
+ }
231
+ }
259
232
  }
260
233
  // append headers
261
234
  if ((response === null || response === void 0 ? void 0 : response.headers) != null) {
@@ -283,7 +256,7 @@ class Router {
283
256
  const error = _error instanceof Error ? _error : Error(String(_error));
284
257
  ctx.error = error;
285
258
  // catchers
286
- if ((_e = __classPrivateFieldGet(this, _Router_config, "f").enable) === null || _e === void 0 ? void 0 : _e.catcher) {
259
+ if ((_d = __classPrivateFieldGet(this, _Router_config, "f").enable) === null || _d === void 0 ? void 0 : _d.catcher) {
287
260
  const catcherRoutes = __classPrivateFieldGet(this, _Router_instances, "m", _Router_getRouteEntries).call(this, pathname, parts, __classPrivateFieldGet(this, _Router_routes, "f").catcher[method], false);
288
261
  found.catcher = catcherRoutes.length;
289
262
  if (catcherRoutes.length > 0) {
@@ -296,7 +269,7 @@ class Router {
296
269
  const resp = yield handler(ctx);
297
270
  if (resp instanceof Response) {
298
271
  response = resp;
299
- break;
272
+ break away;
300
273
  }
301
274
  else if (resp === types_ts_1.Break_Pipe) {
302
275
  break;
@@ -331,9 +304,9 @@ class Router {
331
304
  response = new Response(response.body, Object.assign(Object.assign({}, response), { status: response.status, statusText: (0, status_ts_1.getHttpStatusText)(response.status), headers: ctx.headers }));
332
305
  }
333
306
  ctx.response = response;
334
- ctx.timestamps.response = Date.now();
307
+ ctx.timestamps.end = performance.now();
335
308
  // afters
336
- if ((_f = __classPrivateFieldGet(this, _Router_config, "f").enable) === null || _f === void 0 ? void 0 : _f.after) {
309
+ if ((_e = __classPrivateFieldGet(this, _Router_config, "f").enable) === null || _e === void 0 ? void 0 : _e.after) {
337
310
  const afterRoutes = __classPrivateFieldGet(this, _Router_instances, "m", _Router_getRouteEntries).call(this, pathname, parts, __classPrivateFieldGet(this, _Router_routes, "f").after[method], false);
338
311
  found.after = afterRoutes.length;
339
312
  if (afterRoutes.length > 0) {
@@ -347,7 +320,7 @@ class Router {
347
320
  const resp = yield handler(ctx);
348
321
  if (resp instanceof Response) {
349
322
  response = resp;
350
- break;
323
+ break away;
351
324
  }
352
325
  else if (resp === types_ts_1.Break_Pipe) {
353
326
  break;
@@ -389,69 +362,84 @@ class Router {
389
362
  }
390
363
  let handlersImp;
391
364
  try {
392
- handlersImp = (yield (0, utils_node_ts_1.dynamicImport)(node.fullPath));
365
+ handlersImp = (yield (0, utils_node_ts_1.dynamicImport)(node.fullPath, `v=${node.mtimeMs}`));
366
+ const importPath = node.path;
393
367
  const processedName = decodeURIComponent(processName(node.name));
394
368
  const pathname = !node.parent
395
369
  ? `/${processedName}`
396
370
  : `/${node.parent}/${processedName}`;
397
371
  const path = (0, exports.translateRouteFilePath)(pathname, __classPrivateFieldGet(this, _Router_config, "f").maxPath);
398
- for (const _method of Object.keys(handlersImp)) {
399
- const _definition = handlersImp[_method];
372
+ for (const methodHandler of Object.keys(handlersImp)) {
373
+ const [method_, handlerType_] = methodHandler.split("_", 2);
374
+ const def = handlersImp[methodHandler];
400
375
  let method;
401
- let upperMethod = _method.toUpperCase();
402
376
  let handlerType = "handler";
403
- if (exports.HTTP_METHODS_UPPER.has(upperMethod)) {
404
- method = _method;
377
+ const methodUpper = method_.toUpperCase();
378
+ if (methodUpper === "ALL") {
379
+ method = "All";
380
+ }
381
+ else if (methodUpper === "CRUD") {
382
+ method = "Crud";
383
+ }
384
+ else if (exports.HTTP_METHODS_UPPER.has(methodUpper)) {
385
+ method = (method_.charAt(0).toUpperCase() +
386
+ method_.substring(1).toLowerCase());
405
387
  }
406
388
  else {
407
- const [spMethod, _handlerType] = _method.split("_", 2);
408
- if (!(spMethod && _handlerType)) {
409
- continue;
410
- }
411
- upperMethod = spMethod.toUpperCase();
412
- if (exports.HTTP_METHODS_UPPER.has(upperMethod)) {
413
- method = spMethod;
414
- }
415
- else {
416
- continue;
417
- }
418
- if (exports.HANDLER_TYPES.has(_handlerType === null || _handlerType === void 0 ? void 0 : _handlerType.toLowerCase())) {
419
- handlerType = _handlerType.toLowerCase();
420
- }
421
- else {
422
- continue;
423
- }
389
+ continue;
390
+ }
391
+ if (handlerType_ &&
392
+ exports.HANDLER_TYPES.has(handlerType_.toLowerCase())) {
393
+ handlerType = handlerType_.toLowerCase();
394
+ }
395
+ else {
396
+ continue;
397
+ }
398
+ const defIsObject = !Array.isArray(def) && typeof def === "object";
399
+ // get pipe and any other options
400
+ const pipe = defIsObject ? def.pipe : def;
401
+ const options = defIsObject ? {} : undefined;
402
+ if (options != null) {
403
+ options.openApi = def.openApi;
404
+ options.overwrite = def.overwrite;
424
405
  }
425
- const definition = Array.isArray(_definition) || typeof _definition === "function"
426
- ? { pipe: _definition }
427
- : {
428
- pipe: _definition.pipe,
429
- openApi: _definition.openApi,
430
- };
431
- const pipe = definition.pipe;
432
- const openApi = definition.openApi;
433
- if (openApi != null && handlerType !== "handler") {
434
- console.warn(`OpenApi definition will be ignored in '${node.path}' ${_method}`);
406
+ if ((options === null || options === void 0 ? void 0 : options.openApi) != null && handlerType !== "handler") {
407
+ console.warn(`OpenApi definition will be ignored for \`${methodHandler}\` in '${importPath}'`);
435
408
  }
436
409
  if (pipe == null) {
437
- throw new types_ts_1.RouterError(`Undefined pipe in '${node.path}' ${_method}`);
410
+ throw new types_ts_1.RouterError(`Undefined pipe for \`${methodHandler}\` in '${importPath}'`);
438
411
  }
439
- if (!Array.isArray(pipe) && typeof pipe !== "function") {
440
- throw new types_ts_1.RouterError(`Bad pipe type in '${node.path}' ${_method}`);
412
+ if (!((Array.isArray(pipe) &&
413
+ pipe.every((h) => typeof h === "function")) ||
414
+ typeof pipe === "function")) {
415
+ throw new types_ts_1.RouterError(`Invalid pipe or handler type for \`${methodHandler}\` in '${importPath}'`);
441
416
  }
442
- if (openApi != null && typeof openApi !== "object") {
443
- throw new types_ts_1.RouterError(`Bad openApi type in '${node.path}' ${_method}`);
417
+ if ((options === null || options === void 0 ? void 0 : options.openApi) != null &&
418
+ typeof (options === null || options === void 0 ? void 0 : options.openApi) !== "object") {
419
+ throw new types_ts_1.RouterError(`Invalid openApi type for \`${methodHandler}\` in '${importPath}'`);
444
420
  }
445
- const options = handlerType === "handler" && openApi != null
446
- ? { openApi }
447
- : undefined;
448
- if (Array.isArray(pipe) || typeof pipe === "function") {
449
- this.register(handlerType, `${method} ${path}`, pipe, options);
421
+ switch (handlerType) {
422
+ case "filter":
423
+ this[`filter${method}`](pathname, pipe, options);
424
+ break;
425
+ case "handler":
426
+ this[`handle${method}`](pathname, pipe, options);
427
+ break;
428
+ case "fallback":
429
+ this[`fallback${method}`](pathname, pipe, options);
430
+ break;
431
+ case "after":
432
+ this[`after${method}`](pathname, pipe, options);
433
+ break;
434
+ case "catcher":
435
+ this[`catch${method}`](pathname, pipe, options);
436
+ break;
450
437
  }
438
+ this.register(handlerType, `${method} ${path}`, pipe, options);
451
439
  }
452
440
  }
453
441
  catch (error) {
454
- console.error(`Failed to import route at ${node.fullPath}:`, error);
442
+ console.error(`Failed to import route at '${node.fullPath}':`, error);
455
443
  }
456
444
  }
457
445
  }
@@ -1288,19 +1276,154 @@ class Router {
1288
1276
  return this.register("catcher", methodPaths, pipe, options);
1289
1277
  }
1290
1278
  filter(methodPaths, pipe, options) {
1291
- return this.register("filter", methodPaths, pipe, options);
1279
+ const methodPathIsArray = Array.isArray(methodPaths);
1280
+ if (methodPathIsArray &&
1281
+ !methodPaths.slice(1).every((mp) => typeof mp === "string")) {
1282
+ throw new types_ts_1.RouterError("Invalid path type. Allowed [[Methods...], ...Paths]");
1283
+ }
1284
+ const firstElementIsArray = methodPathIsArray && Array.isArray(methodPaths[0]);
1285
+ if (firstElementIsArray &&
1286
+ !methodPaths[0].every((mp) => typeof mp === "string")) {
1287
+ throw new types_ts_1.RouterError("Invalid method type. Allowed [[Methods...], ...Paths]");
1288
+ }
1289
+ if (methodPathIsArray &&
1290
+ !firstElementIsArray &&
1291
+ !methodPaths.every((mp) => typeof mp === "string")) {
1292
+ throw new types_ts_1.RouterError("Invalid method type. Allowed [...MethodPaths]");
1293
+ }
1294
+ if (!methodPathIsArray &&
1295
+ !firstElementIsArray &&
1296
+ typeof methodPaths !== "string") {
1297
+ throw new types_ts_1.RouterError("Invalid method type. Allowed MethodPath");
1298
+ }
1299
+ const methodPaths_ = methodPathIsArray
1300
+ ? Array.isArray(methodPaths[0])
1301
+ ? methodPaths[0].flatMap((method) => methodPaths
1302
+ .slice(1)
1303
+ .map((paths) => `${method} ${paths}`))
1304
+ : methodPaths
1305
+ : methodPaths;
1306
+ return this.register("filter", methodPaths_, pipe, options);
1292
1307
  }
1293
1308
  handle(methodPaths, pipe, options) {
1294
- return this.register("handler", methodPaths, pipe, options);
1309
+ const methodPathIsArray = Array.isArray(methodPaths);
1310
+ if (methodPathIsArray &&
1311
+ !methodPaths.slice(1).every((mp) => typeof mp === "string")) {
1312
+ throw new types_ts_1.RouterError("Invalid path type. Allowed [[Methods...], ...Paths]");
1313
+ }
1314
+ const firstElementIsArray = methodPathIsArray && Array.isArray(methodPaths[0]);
1315
+ if (firstElementIsArray &&
1316
+ !methodPaths[0].every((mp) => typeof mp === "string")) {
1317
+ throw new types_ts_1.RouterError("Invalid method type. Allowed [[Methods...], ...Paths]");
1318
+ }
1319
+ if (methodPathIsArray &&
1320
+ !firstElementIsArray &&
1321
+ !methodPaths.every((mp) => typeof mp === "string")) {
1322
+ throw new types_ts_1.RouterError("Invalid method type. Allowed [...MethodPaths]");
1323
+ }
1324
+ if (!methodPathIsArray &&
1325
+ !firstElementIsArray &&
1326
+ typeof methodPaths !== "string") {
1327
+ throw new types_ts_1.RouterError("Invalid method type. Allowed MethodPath");
1328
+ }
1329
+ const methodPaths_ = methodPathIsArray
1330
+ ? Array.isArray(methodPaths[0])
1331
+ ? methodPaths[0].flatMap((method) => methodPaths
1332
+ .slice(1)
1333
+ .map((paths) => `${method} ${paths}`))
1334
+ : methodPaths
1335
+ : methodPaths;
1336
+ return this.register("handler", methodPaths_, pipe, options);
1295
1337
  }
1296
1338
  fallback(methodPaths, pipe, options) {
1297
- return this.register("fallback", methodPaths, pipe, options);
1339
+ const methodPathIsArray = Array.isArray(methodPaths);
1340
+ if (methodPathIsArray &&
1341
+ !methodPaths.slice(1).every((mp) => typeof mp === "string")) {
1342
+ throw new types_ts_1.RouterError("Invalid path type. Allowed [[Methods...], ...Paths]");
1343
+ }
1344
+ const firstElementIsArray = methodPathIsArray && Array.isArray(methodPaths[0]);
1345
+ if (firstElementIsArray &&
1346
+ !methodPaths[0].every((mp) => typeof mp === "string")) {
1347
+ throw new types_ts_1.RouterError("Invalid method type. Allowed [[Methods...], ...Paths]");
1348
+ }
1349
+ if (methodPathIsArray &&
1350
+ !firstElementIsArray &&
1351
+ !methodPaths.every((mp) => typeof mp === "string")) {
1352
+ throw new types_ts_1.RouterError("Invalid method-paths type. Allowed [...MethodPaths]");
1353
+ }
1354
+ if (!methodPathIsArray &&
1355
+ !firstElementIsArray &&
1356
+ typeof methodPaths !== "string") {
1357
+ throw new types_ts_1.RouterError("Invalid method-path type. Allowed MethodPath");
1358
+ }
1359
+ const methodPaths_ = methodPathIsArray
1360
+ ? Array.isArray(methodPaths[0])
1361
+ ? methodPaths[0].flatMap((method) => methodPaths
1362
+ .slice(1)
1363
+ .map((paths) => `${method} ${paths}`))
1364
+ : methodPaths
1365
+ : methodPaths;
1366
+ return this.register("fallback", methodPaths_, pipe, options);
1298
1367
  }
1299
1368
  after(methodPaths, pipe, options) {
1300
- return this.register("after", methodPaths, pipe, options);
1369
+ const methodPathIsArray = Array.isArray(methodPaths);
1370
+ if (methodPathIsArray &&
1371
+ !methodPaths.slice(1).every((mp) => typeof mp === "string")) {
1372
+ throw new types_ts_1.RouterError("Invalid path type. Allowed [[Methods...], ...Paths]");
1373
+ }
1374
+ const firstElementIsArray = methodPathIsArray && Array.isArray(methodPaths[0]);
1375
+ if (firstElementIsArray &&
1376
+ !methodPaths[0].every((mp) => typeof mp === "string")) {
1377
+ throw new types_ts_1.RouterError("Invalid method type. Allowed [[Methods...], ...Paths]");
1378
+ }
1379
+ if (methodPathIsArray &&
1380
+ !firstElementIsArray &&
1381
+ !methodPaths.every((mp) => typeof mp === "string")) {
1382
+ throw new types_ts_1.RouterError("Invalid method type. Allowed [...MethodPaths]");
1383
+ }
1384
+ if (!methodPathIsArray &&
1385
+ !firstElementIsArray &&
1386
+ typeof methodPaths !== "string") {
1387
+ throw new types_ts_1.RouterError("Invalid method type. Allowed MethodPath");
1388
+ }
1389
+ const methodPaths_ = methodPathIsArray
1390
+ ? Array.isArray(methodPaths[0])
1391
+ ? methodPaths[0].flatMap((method) => methodPaths
1392
+ .slice(1)
1393
+ .map((paths) => `${method} ${paths}`))
1394
+ : methodPaths
1395
+ : methodPaths;
1396
+ return this.register("after", methodPaths_, pipe, options);
1301
1397
  }
1302
1398
  catch(methodPaths, pipe, options) {
1303
- return this.register("catcher", methodPaths, pipe, options);
1399
+ const methodPathIsArray = Array.isArray(methodPaths);
1400
+ if (methodPathIsArray &&
1401
+ !methodPaths.slice(1).every((mp) => typeof mp === "string")) {
1402
+ throw new types_ts_1.RouterError("Invalid path type. Allowed [[Methods...], ...Paths]");
1403
+ }
1404
+ const firstElementIsArray = methodPathIsArray && Array.isArray(methodPaths[0]);
1405
+ if (firstElementIsArray &&
1406
+ !methodPaths[0].every((mp) => typeof mp === "string")) {
1407
+ throw new types_ts_1.RouterError("Invalid method type. Allowed [[Methods...], ...Paths]");
1408
+ }
1409
+ if (methodPathIsArray &&
1410
+ !firstElementIsArray &&
1411
+ !methodPaths.every((mp) => typeof mp === "string")) {
1412
+ throw new types_ts_1.RouterError("Invalid method type. Allowed [...MethodPaths]");
1413
+ }
1414
+ if (!methodPathIsArray &&
1415
+ !firstElementIsArray &&
1416
+ typeof methodPaths !== "string") {
1417
+ throw new types_ts_1.RouterError("Invalid method type. Allowed MethodPath");
1418
+ }
1419
+ const methodPaths_ = methodPathIsArray
1420
+ ? Array.isArray(methodPaths[0])
1421
+ ? methodPaths[0].flatMap((method) => methodPaths
1422
+ .slice(1)
1423
+ .map((paths) => `${method} ${paths}`))
1424
+ : methodPaths
1425
+ : methodPaths;
1426
+ return this.register("catcher", methodPaths_, pipe, options);
1304
1427
  }
1305
1428
  register(handlerType, methodPaths, pipe, options) {
1306
1429
  const overwrite = (options === null || options === void 0 ? void 0 : options.overwrite) === true;