@bepalo/spine 2.8.21 → 3.9.22

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 (51) hide show
  1. package/dist/auth-middlewares.d.ts +6 -2
  2. package/dist/auth-middlewares.d.ts.map +1 -1
  3. package/dist/auth-middlewares.js +20 -7
  4. package/dist/auth-middlewares.js.map +1 -1
  5. package/dist/cjs/auth-middlewares.d.ts +6 -2
  6. package/dist/cjs/auth-middlewares.d.ts.map +1 -1
  7. package/dist/cjs/auth-middlewares.js +20 -7
  8. package/dist/cjs/auth-middlewares.js.map +1 -1
  9. package/dist/cjs/generator.js.map +1 -1
  10. package/dist/cjs/helpers.d.ts +14 -2
  11. package/dist/cjs/helpers.d.ts.map +1 -1
  12. package/dist/cjs/helpers.js +31 -3
  13. package/dist/cjs/helpers.js.map +1 -1
  14. package/dist/cjs/middlewares.d.ts +116 -6
  15. package/dist/cjs/middlewares.d.ts.map +1 -1
  16. package/dist/cjs/middlewares.js +291 -35
  17. package/dist/cjs/middlewares.js.map +1 -1
  18. package/dist/cjs/router.d.ts +51 -52
  19. package/dist/cjs/router.d.ts.map +1 -1
  20. package/dist/cjs/router.js +233 -122
  21. package/dist/cjs/router.js.map +1 -1
  22. package/dist/cjs/types.d.ts +99 -17
  23. package/dist/cjs/types.d.ts.map +1 -1
  24. package/dist/cjs/types.js +1 -0
  25. package/dist/cjs/types.js.map +1 -1
  26. package/dist/cjs/utils.d.ts +2 -0
  27. package/dist/cjs/utils.d.ts.map +1 -1
  28. package/dist/cjs/utils.js +18 -1
  29. package/dist/cjs/utils.js.map +1 -1
  30. package/dist/generator.js.map +1 -1
  31. package/dist/helpers.d.ts +14 -2
  32. package/dist/helpers.d.ts.map +1 -1
  33. package/dist/helpers.js +31 -3
  34. package/dist/helpers.js.map +1 -1
  35. package/dist/middlewares.d.ts +116 -6
  36. package/dist/middlewares.d.ts.map +1 -1
  37. package/dist/middlewares.js +291 -35
  38. package/dist/middlewares.js.map +1 -1
  39. package/dist/router.d.ts +51 -52
  40. package/dist/router.d.ts.map +1 -1
  41. package/dist/router.js +233 -122
  42. package/dist/router.js.map +1 -1
  43. package/dist/types.d.ts +99 -17
  44. package/dist/types.d.ts.map +1 -1
  45. package/dist/types.js +1 -0
  46. package/dist/types.js.map +1 -1
  47. package/dist/utils.d.ts +2 -0
  48. package/dist/utils.d.ts.map +1 -1
  49. package/dist/utils.js +18 -1
  50. package/dist/utils.js.map +1 -1
  51. package/package.json +1 -1
@@ -29,17 +29,18 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
29
29
  };
30
30
  var _Router_instances, _Router_config, _Router_routes, _Router_generateUniqueOperationId, _Router_processPath, _Router_getRouteEntries, _Router_InitEntries, _Router_initRoutes;
31
31
  Object.defineProperty(exports, "__esModule", { value: true });
32
- exports.translateRouteFilePath = exports.Router = exports.HANDLER_TYPES = exports.HTTP_METHODS_UPPER = exports.CRUD_METHODS = exports.HTTP_METHODS = exports.REGISTER_PATH_REGEX = exports.PATH_PART_REGEX = void 0;
32
+ exports.translateRouteFilePath = exports.Router = exports.HANDLER_TYPES = exports.HTTP_METHODS_UPPER = exports.CRUD_METHODS = exports.HTTP_METHODS = exports.REGISTER_PATH_REGEX = exports.PATH_PART_REGEX = exports.EMPTY_PARAMS = void 0;
33
33
  const status_ts_1 = require("./status.js");
34
34
  const types_ts_1 = require("./types.js");
35
35
  const utils_node_ts_1 = require("./utils.node.js");
36
- const EMPTY_PARAMS = Object.freeze({});
36
+ exports.EMPTY_PARAMS = Object.freeze({});
37
37
  const W = "[\\p{L}\\p{M}\\p{N}\\p{S}\\p{P}_\\-\\s.]";
38
38
  exports.PATH_PART_REGEX = new RegExp(`^(?:#?${W}+|\\[(?:${W}*|#{1,2}|##\\s*${W}*\\s*|\\[##\\s*${W}*\\s*\\]|\\[${W}*(?:,${W}*)*\\](?:\\s*${W}*\\s*|\\[\\s*${W}*\\s*\\]))\\])$`, "u");
39
39
  exports.REGISTER_PATH_REGEX = new RegExp(`^(?:/(?:${W}*|${W}*(?:\\|${W}*)*:${W}*|\\*))+|(?:/${W}*)*(?:/\\.?\\*\\*)|(?:/${W}*)*(?:/::${W}*)$`, "u");
40
40
  exports.HTTP_METHODS = new Set([
41
41
  "Head",
42
42
  "Get",
43
+ "Query",
43
44
  "Post",
44
45
  "Put",
45
46
  "Patch",
@@ -58,6 +59,7 @@ exports.CRUD_METHODS = new Set([
58
59
  exports.HTTP_METHODS_UPPER = new Set([
59
60
  "HEAD",
60
61
  "GET",
62
+ "QUERY",
61
63
  "POST",
62
64
  "PUT",
63
65
  "PATCH",
@@ -100,7 +102,7 @@ class Router {
100
102
  }
101
103
  respond(request, ctxInit) {
102
104
  return __awaiter(this, void 0, void 0, function* () {
103
- var _a, _b, _c, _d, _e;
105
+ var _a;
104
106
  const startTimestamp = performance.now();
105
107
  const requestTimestamp = Date.now();
106
108
  const method = request.method;
@@ -110,31 +112,34 @@ class Router {
110
112
  try {
111
113
  pathname = decodeURIComponent(url.pathname);
112
114
  }
113
- catch (_f) {
115
+ catch (_b) {
114
116
  return new Response(null, {
115
- status: 400,
116
- statusText: (0, status_ts_1.getHttpStatusText)(400),
117
+ status: status_ts_1.Status._400_BadRequest,
118
+ statusText: (0, status_ts_1.getHttpStatusText)(status_ts_1.Status._400_BadRequest),
119
+ headers: ctxInit === null || ctxInit === void 0 ? void 0 : ctxInit.headers,
117
120
  });
118
121
  }
119
122
  const parts = [];
120
- const ctx = Object.assign(Object.assign({ router: this, url,
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) });
123
+ const ctx = Object.assign(Object.assign({}, ctxInit), { router: this, url,
124
+ request, headers: (_a = ctxInit === null || ctxInit === void 0 ? void 0 : ctxInit.headers) !== null && _a !== void 0 ? _a : new Headers(), params: exports.EMPTY_PARAMS, method,
125
+ pathname, timestamps: Object.assign(Object.assign({}, ctxInit === null || ctxInit === void 0 ? void 0 : ctxInit.timestamps), { request: requestTimestamp, start: startTimestamp, end: startTimestamp }) });
122
126
  {
123
127
  const count = this.splitPath(pathname, parts, __classPrivateFieldGet(this, _Router_config, "f").maxPath);
124
128
  if (count < 0) {
125
129
  return count === -1
126
130
  ? new Response(null, {
127
- status: 400,
128
- statusText: (0, status_ts_1.getHttpStatusText)(400),
131
+ status: status_ts_1.Status._400_BadRequest,
132
+ statusText: (0, status_ts_1.getHttpStatusText)(status_ts_1.Status._400_BadRequest),
129
133
  headers: ctx.headers,
130
134
  })
131
135
  : new Response(null, {
132
- status: 414,
133
- statusText: (0, status_ts_1.getHttpStatusText)(414),
136
+ status: status_ts_1.Status._414_URITooLong,
137
+ statusText: (0, status_ts_1.getHttpStatusText)(status_ts_1.Status._414_URITooLong),
134
138
  headers: ctx.headers,
135
139
  });
136
140
  }
137
141
  }
142
+ const enable = __classPrivateFieldGet(this, _Router_config, "f").enable;
138
143
  const found = {
139
144
  filter: 0,
140
145
  handler: 0,
@@ -142,48 +147,55 @@ class Router {
142
147
  after: 0,
143
148
  catcher: 0,
144
149
  };
150
+ const paramsRef = {};
145
151
  try {
146
152
  // filters
147
- if ((_b = __classPrivateFieldGet(this, _Router_config, "f").enable) === null || _b === void 0 ? void 0 : _b.filter) {
153
+ if (enable === null || enable === void 0 ? void 0 : enable.filter) {
148
154
  const filterRoutes = __classPrivateFieldGet(this, _Router_instances, "m", _Router_getRouteEntries).call(this, pathname, parts, __classPrivateFieldGet(this, _Router_routes, "f").filter[method], false);
149
155
  found.filter = filterRoutes.length;
150
- if (filterRoutes.length > 0) {
151
- away: for (const routeEntry of filterRoutes) {
152
- // parse params
153
- const params = routeEntry.parseParams(pathname, parts);
154
- ctx.params = params !== null && params !== void 0 ? params : EMPTY_PARAMS;
155
- // call request handlers
156
- for (const handler of routeEntry.pipe) {
157
- const resp = yield handler.apply(this, [ctx]);
158
- if (resp instanceof Response) {
159
- response = resp;
160
- break away;
161
- }
162
- else if (resp === types_ts_1.Break_Pipe) {
163
- break;
164
- }
165
- else if (resp === types_ts_1.Break_Pipeline) {
166
- break away;
167
- }
156
+ away: for (const routeEntry of filterRoutes) {
157
+ // parse params
158
+ const params = routeEntry.parseParams(pathname, parts, paramsRef);
159
+ ctx.params = params;
160
+ // call request handlers
161
+ for (const handler of routeEntry.pipe) {
162
+ const resp = yield handler.apply(this, [ctx]);
163
+ if (resp instanceof Response) {
164
+ response = resp;
165
+ break away;
166
+ }
167
+ else if (resp === types_ts_1.Break_Pipe) {
168
+ break;
169
+ }
170
+ else if (resp === types_ts_1.Break_Pipeline) {
171
+ break away;
168
172
  }
169
173
  }
170
- }
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;
174
+ // update params
175
+ if (routeEntry.hasAnyGlob && params !== ctx.params) {
176
+ const idxHash = routeEntry.hasSuperGlob ? "##" : "#";
177
+ for (const [idx, paramId] of routeEntry.params) {
178
+ const key = paramId + idxHash + idx;
179
+ paramsRef[key] = ctx.params[paramId];
180
+ }
176
181
  }
177
182
  }
178
183
  }
184
+ // default filter
185
+ if (__classPrivateFieldGet(this, _Router_config, "f").defaultFilter && !(response instanceof Response)) {
186
+ const resp = yield __classPrivateFieldGet(this, _Router_config, "f").defaultFilter(ctx);
187
+ if (resp instanceof Response) {
188
+ response = resp;
189
+ }
190
+ }
179
191
  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
192
  // handlers
182
193
  if (handlerRoutes.length > 0 && !(response instanceof Response)) {
194
+ found.handler = handlerRoutes.length;
183
195
  away: for (const routeEntry of handlerRoutes) {
184
196
  // parse params
185
- const params = routeEntry.parseParams(pathname, parts);
186
- ctx.params = params !== null && params !== void 0 ? params : EMPTY_PARAMS;
197
+ const params = routeEntry.parseParams(pathname, parts, paramsRef);
198
+ ctx.params = params;
187
199
  // call request handlers
188
200
  for (const handler of routeEntry.pipe) {
189
201
  const resp = yield handler(ctx);
@@ -198,16 +210,31 @@ class Router {
198
210
  break away;
199
211
  }
200
212
  }
213
+ // update params
214
+ if (routeEntry.hasAnyGlob && params !== ctx.params) {
215
+ const idxHash = routeEntry.hasSuperGlob ? "##" : "#";
216
+ for (const [idx, paramId] of routeEntry.params) {
217
+ const key = paramId + idxHash + idx;
218
+ paramsRef[key] = ctx.params[paramId];
219
+ }
220
+ }
221
+ }
222
+ }
223
+ // default handler
224
+ if (__classPrivateFieldGet(this, _Router_config, "f").defaultHandler && !(response instanceof Response)) {
225
+ const resp = yield __classPrivateFieldGet(this, _Router_config, "f").defaultHandler(ctx);
226
+ if (resp instanceof Response) {
227
+ response = resp;
201
228
  }
202
229
  }
203
230
  // fallbacks
204
- if (((_c = __classPrivateFieldGet(this, _Router_config, "f").enable) === null || _c === void 0 ? void 0 : _c.fallback) && !(response instanceof Response)) {
231
+ if (enable.fallback && !(response instanceof Response)) {
205
232
  const fallbackRoutes = __classPrivateFieldGet(this, _Router_instances, "m", _Router_getRouteEntries).call(this, pathname, parts, __classPrivateFieldGet(this, _Router_routes, "f").fallback[method], false);
233
+ found.fallback = fallbackRoutes.length;
206
234
  away: for (const routeEntry of fallbackRoutes) {
207
235
  // parse params
208
- const params = routeEntry.parseParams(pathname, parts);
209
- ctx.params = params !== null && params !== void 0 ? params : EMPTY_PARAMS;
210
- // call request handlers
236
+ const params = routeEntry.parseParams(pathname, parts, paramsRef);
237
+ ctx.params = params;
211
238
  for (const handler of routeEntry.pipe) {
212
239
  const resp = yield handler(ctx);
213
240
  if (resp instanceof Response) {
@@ -221,34 +248,41 @@ class Router {
221
248
  break away;
222
249
  }
223
250
  }
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;
251
+ // update params
252
+ if (routeEntry.hasAnyGlob && params !== ctx.params) {
253
+ const idxHash = routeEntry.hasSuperGlob ? "##" : "#";
254
+ for (const [idx, paramId] of routeEntry.params) {
255
+ const key = paramId + idxHash + idx;
256
+ paramsRef[key] = ctx.params[paramId];
257
+ }
230
258
  }
231
259
  }
232
260
  }
261
+ // default fallback
262
+ if (__classPrivateFieldGet(this, _Router_config, "f").defaultFallback && !(response instanceof Response)) {
263
+ const resp = yield __classPrivateFieldGet(this, _Router_config, "f").defaultFallback(ctx);
264
+ if (resp instanceof Response) {
265
+ response = resp;
266
+ }
267
+ }
233
268
  // append headers
234
- if ((response === null || response === void 0 ? void 0 : response.headers) != null) {
235
- for (const [k, v] of response.headers) {
236
- ctx.headers.append(k, v);
269
+ if (response instanceof Response) {
270
+ for (const [k, v] of ctx.headers) {
271
+ response.headers.append(k, v);
237
272
  }
238
273
  }
239
- // default response to not-implemented or not-found if null
240
274
  response =
241
275
  response instanceof Response
242
- ? new Response(response.body, Object.assign(Object.assign({}, response), { status: response.status, statusText: (0, status_ts_1.getHttpStatusText)(response.status), headers: ctx.headers }))
276
+ ? response
243
277
  : found.handler + found.fallback > 0
244
278
  ? new Response(null, {
245
- status: 501,
246
- statusText: (0, status_ts_1.getHttpStatusText)(501),
279
+ status: status_ts_1.Status._501_NotImplemented,
280
+ statusText: (0, status_ts_1.getHttpStatusText)(status_ts_1.Status._501_NotImplemented),
247
281
  headers: ctx.headers,
248
282
  })
249
283
  : new Response(null, {
250
- status: 404,
251
- statusText: (0, status_ts_1.getHttpStatusText)(404),
284
+ status: status_ts_1.Status._404_NotFound,
285
+ statusText: (0, status_ts_1.getHttpStatusText)(status_ts_1.Status._404_NotFound),
252
286
  headers: ctx.headers,
253
287
  });
254
288
  }
@@ -256,90 +290,103 @@ class Router {
256
290
  const error = _error instanceof Error ? _error : Error(String(_error));
257
291
  ctx.error = error;
258
292
  // catchers
259
- if ((_d = __classPrivateFieldGet(this, _Router_config, "f").enable) === null || _d === void 0 ? void 0 : _d.catcher) {
293
+ if (enable.catcher) {
260
294
  const catcherRoutes = __classPrivateFieldGet(this, _Router_instances, "m", _Router_getRouteEntries).call(this, pathname, parts, __classPrivateFieldGet(this, _Router_routes, "f").catcher[method], false);
261
295
  found.catcher = catcherRoutes.length;
262
- if (catcherRoutes.length > 0) {
263
- away: for (const routeEntry of catcherRoutes) {
264
- // parse params
265
- const params = routeEntry.parseParams(url.pathname, parts);
266
- ctx.params = params !== null && params !== void 0 ? params : EMPTY_PARAMS;
267
- // call request handlers
268
- for (const handler of routeEntry.pipe) {
269
- const resp = yield handler(ctx);
270
- if (resp instanceof Response) {
271
- response = resp;
272
- break away;
273
- }
274
- else if (resp === types_ts_1.Break_Pipe) {
275
- break;
276
- }
277
- else if (resp === types_ts_1.Break_Pipeline) {
278
- break away;
279
- }
296
+ away: for (const routeEntry of catcherRoutes) {
297
+ // parse params
298
+ const params = routeEntry.parseParams(pathname, parts, paramsRef);
299
+ ctx.params = params;
300
+ // call request handlers
301
+ for (const handler of routeEntry.pipe) {
302
+ const resp = yield handler(ctx);
303
+ if (resp instanceof Response) {
304
+ response = resp;
305
+ break away;
306
+ }
307
+ else if (resp === types_ts_1.Break_Pipe) {
308
+ break;
309
+ }
310
+ else if (resp === types_ts_1.Break_Pipeline) {
311
+ break away;
312
+ }
313
+ }
314
+ // update params
315
+ if (routeEntry.hasAnyGlob && params !== ctx.params) {
316
+ const idxHash = routeEntry.hasSuperGlob ? "##" : "#";
317
+ for (const [idx, paramId] of routeEntry.params) {
318
+ const key = paramId + idxHash + idx;
319
+ paramsRef[key] = ctx.params[paramId];
280
320
  }
281
321
  }
282
322
  }
283
323
  }
284
324
  // default cathcer
285
- if (!(response instanceof Response) && __classPrivateFieldGet(this, _Router_config, "f").defaultCatcher) {
286
- const errorCtx = ctx;
325
+ if (__classPrivateFieldGet(this, _Router_config, "f").defaultCatcher && !(response instanceof Response)) {
287
326
  ctx.error = error;
288
- const resp = yield __classPrivateFieldGet(this, _Router_config, "f").defaultCatcher(errorCtx);
327
+ const resp = yield __classPrivateFieldGet(this, _Router_config, "f").defaultCatcher(ctx);
289
328
  if (resp instanceof Response) {
290
329
  response = resp;
291
330
  }
292
331
  }
293
332
  if (!(response instanceof Response)) {
294
- const status = ctx.error && ctx.error instanceof types_ts_1.HttpError ? ctx.error.status : 500;
333
+ const status = ctx.error && ctx.error instanceof types_ts_1.HttpError
334
+ ? ctx.error.status
335
+ : status_ts_1.Status._500_InternalServerError;
295
336
  response = new Response(null, {
296
337
  status,
297
338
  statusText: (0, status_ts_1.getHttpStatusText)(status),
298
339
  });
299
340
  }
300
341
  // append headers
301
- for (const [k, v] of response.headers) {
302
- ctx.headers.append(k, v);
342
+ if (response instanceof Response) {
343
+ for (const [k, v] of ctx.headers) {
344
+ response.headers.append(k, v);
345
+ }
303
346
  }
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 }));
305
347
  }
306
348
  ctx.response = response;
307
349
  ctx.timestamps.end = performance.now();
308
- // afters
309
- if ((_e = __classPrivateFieldGet(this, _Router_config, "f").enable) === null || _e === void 0 ? void 0 : _e.after) {
310
- const afterRoutes = __classPrivateFieldGet(this, _Router_instances, "m", _Router_getRouteEntries).call(this, pathname, parts, __classPrivateFieldGet(this, _Router_routes, "f").after[method], false);
311
- found.after = afterRoutes.length;
312
- if (afterRoutes.length > 0) {
350
+ try {
351
+ // afters
352
+ if (enable.after) {
353
+ const afterRoutes = __classPrivateFieldGet(this, _Router_instances, "m", _Router_getRouteEntries).call(this, pathname, parts, __classPrivateFieldGet(this, _Router_routes, "f").after[method], false);
354
+ found.after = afterRoutes.length;
313
355
  away: for (const routeEntry of afterRoutes) {
314
356
  // parse params
315
- const params = routeEntry.parseParams(pathname, parts);
316
- ctx.params = params !== null && params !== void 0 ? params : EMPTY_PARAMS;
317
- ctx.response = response;
357
+ const params = routeEntry.parseParams(pathname, parts, paramsRef);
358
+ ctx.params = params;
318
359
  // call request handlers
319
360
  for (const handler of routeEntry.pipe) {
320
361
  const resp = yield handler(ctx);
321
- if (resp instanceof Response) {
322
- response = resp;
323
- break away;
324
- }
325
- else if (resp === types_ts_1.Break_Pipe) {
362
+ if (resp === types_ts_1.Break_Pipe) {
326
363
  break;
327
364
  }
328
365
  else if (resp === types_ts_1.Break_Pipeline) {
329
366
  break away;
330
367
  }
331
368
  }
332
- if (response instanceof Response) {
333
- break;
369
+ // update params
370
+ if (routeEntry.hasAnyGlob && params !== ctx.params) {
371
+ const idxHash = routeEntry.hasSuperGlob ? "##" : "#";
372
+ for (const [idx, paramId] of routeEntry.params) {
373
+ const key = paramId + idxHash + idx;
374
+ paramsRef[key] = ctx.params[paramId];
375
+ }
334
376
  }
335
377
  }
336
378
  }
379
+ // default after
380
+ if (__classPrivateFieldGet(this, _Router_config, "f").defaultAfter) {
381
+ yield __classPrivateFieldGet(this, _Router_config, "f").defaultAfter(ctx);
382
+ }
337
383
  }
338
- // default after
339
- if (__classPrivateFieldGet(this, _Router_config, "f").defaultAfter) {
340
- const resp = yield __classPrivateFieldGet(this, _Router_config, "f").defaultAfter(ctx);
341
- if (resp instanceof Response) {
342
- response = resp;
384
+ catch (_error) {
385
+ const error = _error instanceof Error ? _error : Error(String(_error));
386
+ // default after cathcer
387
+ if (__classPrivateFieldGet(this, _Router_config, "f").defaultAfterCatcher) {
388
+ ctx.error = error;
389
+ yield __classPrivateFieldGet(this, _Router_config, "f").defaultAfterCatcher(ctx);
343
390
  }
344
391
  }
345
392
  return response;
@@ -398,7 +445,9 @@ class Router {
398
445
  const defIsObject = !Array.isArray(def) && typeof def === "object";
399
446
  // get pipe and any other options
400
447
  const pipe = defIsObject ? def.pipe : def;
401
- const options = defIsObject ? {} : undefined;
448
+ const options = defIsObject
449
+ ? {}
450
+ : undefined;
402
451
  if (options != null) {
403
452
  options.openApi = def.openApi;
404
453
  options.overwrite = def.overwrite;
@@ -746,11 +795,11 @@ class Router {
746
795
  const userParams = ((_d = openApi.parameters) !== null && _d !== void 0 ? _d : []).filter((p) => p.in !== "path");
747
796
  // Combine: common parameters + user params + path params
748
797
  // Path params come last so they take precedence for required: true
749
- const allParams = [...commonParameters, ...userParams, ...pathParams];
798
+ const paramsRef = [...commonParameters, ...userParams, ...pathParams];
750
799
  // Remove duplicates (by name + in combination)
751
800
  const paramSet = new Set();
752
801
  const finalParams = [];
753
- for (const param of allParams) {
802
+ for (const param of paramsRef) {
754
803
  const key = `${param.name}:${param.in}`;
755
804
  if (!paramSet.has(key)) {
756
805
  paramSet.add(key);
@@ -915,6 +964,11 @@ class Router {
915
964
  const methodPaths = paths.map((p) => `Get ${p}`);
916
965
  return this.register("handler", methodPaths, pipe, options);
917
966
  }
967
+ query(paths, pipe, options) {
968
+ paths = Array.isArray(paths) ? paths : [paths];
969
+ const methodPaths = paths.map((p) => `Query ${p}`);
970
+ return this.register("handler", methodPaths, pipe, options);
971
+ }
918
972
  post(paths, pipe, options) {
919
973
  paths = Array.isArray(paths) ? paths : [paths];
920
974
  const methodPaths = paths.map((p) => `Post ${p}`);
@@ -980,6 +1034,11 @@ class Router {
980
1034
  const methodPaths = paths.map((p) => `Get ${p}`);
981
1035
  return this.register("filter", methodPaths, pipe, options);
982
1036
  }
1037
+ filterQuery(paths, pipe, options) {
1038
+ paths = Array.isArray(paths) ? paths : [paths];
1039
+ const methodPaths = paths.map((p) => `Query ${p}`);
1040
+ return this.register("filter", methodPaths, pipe, options);
1041
+ }
983
1042
  filterPost(paths, pipe, options) {
984
1043
  paths = Array.isArray(paths) ? paths : [paths];
985
1044
  const methodPaths = paths.map((p) => `Post ${p}`);
@@ -1045,6 +1104,11 @@ class Router {
1045
1104
  const methodPaths = paths.map((p) => `Get ${p}`);
1046
1105
  return this.register("handler", methodPaths, pipe, options);
1047
1106
  }
1107
+ handleQuery(paths, pipe, options) {
1108
+ paths = Array.isArray(paths) ? paths : [paths];
1109
+ const methodPaths = paths.map((p) => `Query ${p}`);
1110
+ return this.register("handler", methodPaths, pipe, options);
1111
+ }
1048
1112
  handlePost(paths, pipe, options) {
1049
1113
  paths = Array.isArray(paths) ? paths : [paths];
1050
1114
  const methodPaths = paths.map((p) => `Post ${p}`);
@@ -1110,6 +1174,11 @@ class Router {
1110
1174
  const methodPaths = paths.map((p) => `Get ${p}`);
1111
1175
  return this.register("fallback", methodPaths, pipe, options);
1112
1176
  }
1177
+ fallbackQuery(paths, pipe, options) {
1178
+ paths = Array.isArray(paths) ? paths : [paths];
1179
+ const methodPaths = paths.map((p) => `Query ${p}`);
1180
+ return this.register("fallback", methodPaths, pipe, options);
1181
+ }
1113
1182
  fallbackPost(paths, pipe, options) {
1114
1183
  paths = Array.isArray(paths) ? paths : [paths];
1115
1184
  const methodPaths = paths.map((p) => `Post ${p}`);
@@ -1175,6 +1244,11 @@ class Router {
1175
1244
  const methodPaths = paths.map((p) => `Get ${p}`);
1176
1245
  return this.register("after", methodPaths, pipe, options);
1177
1246
  }
1247
+ afterQuery(paths, pipe, options) {
1248
+ paths = Array.isArray(paths) ? paths : [paths];
1249
+ const methodPaths = paths.map((p) => `Query ${p}`);
1250
+ return this.register("after", methodPaths, pipe, options);
1251
+ }
1178
1252
  afterPost(paths, pipe, options) {
1179
1253
  paths = Array.isArray(paths) ? paths : [paths];
1180
1254
  const methodPaths = paths.map((p) => `Post ${p}`);
@@ -1240,6 +1314,11 @@ class Router {
1240
1314
  const methodPaths = paths.map((p) => `Get ${p}`);
1241
1315
  return this.register("catcher", methodPaths, pipe, options);
1242
1316
  }
1317
+ catchQuery(paths, pipe, options) {
1318
+ paths = Array.isArray(paths) ? paths : [paths];
1319
+ const methodPaths = paths.map((p) => `Query ${p}`);
1320
+ return this.register("catcher", methodPaths, pipe, options);
1321
+ }
1243
1322
  catchPost(paths, pipe, options) {
1244
1323
  paths = Array.isArray(paths) ? paths : [paths];
1245
1324
  const methodPaths = paths.map((p) => `Post ${p}`);
@@ -1428,22 +1507,31 @@ class Router {
1428
1507
  register(handlerType, methodPaths, pipe, options) {
1429
1508
  const overwrite = (options === null || options === void 0 ? void 0 : options.overwrite) === true;
1430
1509
  methodPaths = Array.isArray(methodPaths) ? methodPaths : [methodPaths];
1431
- pipe = Array.isArray(pipe) ? pipe : [pipe];
1510
+ const pipe_ = Array.isArray(pipe) ? pipe : [pipe];
1432
1511
  for (const methodPath of methodPaths) {
1433
1512
  const separator1Idx = methodPath.indexOf(" ");
1434
1513
  const method = methodPath.substring(0, separator1Idx);
1435
1514
  const originalPath = methodPath.substring(separator1Idx + 1);
1515
+ {
1516
+ // check for optional glob in the middle
1517
+ const splitPaths = originalPath.split("/").map((part) => part.trim());
1518
+ for (let i = 1; i < splitPaths.length; i++) {
1519
+ if (splitPaths[i].endsWith("!") && i < splitPaths.length - 1) {
1520
+ throw new types_ts_1.RouterError(`Glob routes with Optional Globs in the middle are not allowed. for (${method} ${originalPath})`);
1521
+ }
1522
+ }
1523
+ }
1436
1524
  const processedPaths = __classPrivateFieldGet(this, _Router_instances, "m", _Router_processPath).call(this, originalPath);
1437
1525
  const { params, paths } = processedPaths;
1438
- const paramsMap = params ? new Map(params) : undefined;
1526
+ const paramsCache = params ? new Map(params) : undefined;
1439
1527
  for (const path of paths) {
1440
1528
  const parts = path.split("/", __classPrivateFieldGet(this, _Router_config, "f").maxPath + 1);
1441
1529
  const containsParams = params || parts.some((p) => p === "*");
1442
1530
  const standardPath = containsParams
1443
1531
  ? parts
1444
1532
  .map((p, idx) => p === "*"
1445
- ? (paramsMap === null || paramsMap === void 0 ? void 0 : paramsMap.has(idx))
1446
- ? `:${paramsMap.get(idx)}`
1533
+ ? (paramsCache === null || paramsCache === void 0 ? void 0 : paramsCache.has(idx))
1534
+ ? `:${paramsCache.get(idx)}`
1447
1535
  : "*"
1448
1536
  : p)
1449
1537
  .join("/")
@@ -1453,7 +1541,7 @@ class Router {
1453
1541
  ? path
1454
1542
  .split("/")
1455
1543
  .map((p, idx) => p === "*"
1456
- ? `{${(paramsMap === null || paramsMap === void 0 ? void 0 : paramsMap.get(idx)) || `glob${++globIdx}`}}`
1544
+ ? `{${(paramsCache === null || paramsCache === void 0 ? void 0 : paramsCache.get(idx)) || `glob${++globIdx}`}}`
1457
1545
  : p)
1458
1546
  .join("/")
1459
1547
  : path;
@@ -1475,13 +1563,16 @@ class Router {
1475
1563
  const entry = {
1476
1564
  parseParams: parseParams.bind(null, hasSuperGlob ? superGlobIndex + 1 : undefined, params),
1477
1565
  params,
1478
- pipe,
1566
+ pipe: pipe_,
1479
1567
  originalPath,
1480
1568
  standardPath,
1481
1569
  openApiPath,
1482
1570
  path,
1483
1571
  pathParts: parts,
1484
1572
  openApi: options === null || options === void 0 ? void 0 : options.openApi,
1573
+ hasAnyGlob: hasSuperGlob || hasGlob,
1574
+ hasGlob,
1575
+ hasSuperGlob,
1485
1576
  };
1486
1577
  // check for super globs
1487
1578
  if (hasSuperGlob) {
@@ -1783,6 +1874,7 @@ _Router_config = new WeakMap(), _Router_routes = new WeakMap(), _Router_instance
1783
1874
  routes[handlerType] = {
1784
1875
  HEAD: __classPrivateFieldGet(this, _Router_instances, "m", _Router_InitEntries).call(this, "HEAD"),
1785
1876
  GET: __classPrivateFieldGet(this, _Router_instances, "m", _Router_InitEntries).call(this, "GET"),
1877
+ QUERY: __classPrivateFieldGet(this, _Router_instances, "m", _Router_InitEntries).call(this, "QUERY"),
1786
1878
  POST: __classPrivateFieldGet(this, _Router_instances, "m", _Router_InitEntries).call(this, "POST"),
1787
1879
  PUT: __classPrivateFieldGet(this, _Router_instances, "m", _Router_InitEntries).call(this, "PUT"),
1788
1880
  PATCH: __classPrivateFieldGet(this, _Router_instances, "m", _Router_InitEntries).call(this, "PATCH"),
@@ -1794,17 +1886,36 @@ _Router_config = new WeakMap(), _Router_routes = new WeakMap(), _Router_instance
1794
1886
  }
1795
1887
  return routes;
1796
1888
  };
1797
- const parseParams = (superGlobIndex, params, pathname, parts) => {
1798
- if (params == null && superGlobIndex == null)
1799
- return undefined;
1889
+ const parseParams = (superGlobIndex, params, pathname, parts, paramsRef) => {
1890
+ const definedParam = params !== undefined;
1891
+ if (!definedParam && superGlobIndex == null) {
1892
+ return exports.EMPTY_PARAMS;
1893
+ }
1800
1894
  const paramsRec = {};
1801
- if (params != null && superGlobIndex != null) {
1802
- const name = params[0][1];
1803
- paramsRec[name] = pathname.substring(superGlobIndex);
1895
+ if (definedParam && superGlobIndex != null) {
1896
+ const paramId = params[0][1];
1897
+ const idx = params[0][0];
1898
+ const key = paramId + "##" + idx;
1899
+ if (key in paramsRef) {
1900
+ paramsRec[paramId] = paramsRef[key];
1901
+ }
1902
+ else {
1903
+ const param = pathname.substring(superGlobIndex);
1904
+ paramsRec[paramId] = param;
1905
+ paramsRef[key] = param;
1906
+ }
1804
1907
  }
1805
- else if (params != null) {
1908
+ else if (definedParam) {
1806
1909
  for (const [idx, paramId] of params) {
1807
- paramsRec[paramId] = parts[idx];
1910
+ const key = paramId + "#" + idx;
1911
+ if (key in paramsRef) {
1912
+ paramsRec[paramId] = paramsRef[key];
1913
+ }
1914
+ else {
1915
+ const param = parts[idx];
1916
+ paramsRec[paramId] = param;
1917
+ paramsRef[key] = param;
1918
+ }
1808
1919
  }
1809
1920
  }
1810
1921
  return paramsRec;