@bepalo/spine 1.1.7 → 1.1.9

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