@noxfly/noxus 3.0.0-dev.11 → 3.0.0-dev.12

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.
package/dist/main.d.mts CHANGED
@@ -276,6 +276,16 @@ declare class Router {
276
276
  private tryFindRoute;
277
277
  private findRoute;
278
278
  private tryLoadLazyRoute;
279
+ /**
280
+ * Returns true when `requestPath` starts with `prefix`, treating `:param`
281
+ * segments in the prefix as single-segment wildcards.
282
+ *
283
+ * @example
284
+ * pathHasPrefix('contact/123/notes', 'contact/:id/notes') // true
285
+ * pathHasPrefix('contact/123/notes/get', 'contact/:id/notes') // true
286
+ * pathHasPrefix('contact/123', 'contact/:id/notes') // false
287
+ */
288
+ private pathHasPrefix;
279
289
  private loadLazyModule;
280
290
  private resolveController;
281
291
  private runPipeline;
package/dist/main.d.ts CHANGED
@@ -276,6 +276,16 @@ declare class Router {
276
276
  private tryFindRoute;
277
277
  private findRoute;
278
278
  private tryLoadLazyRoute;
279
+ /**
280
+ * Returns true when `requestPath` starts with `prefix`, treating `:param`
281
+ * segments in the prefix as single-segment wildcards.
282
+ *
283
+ * @example
284
+ * pathHasPrefix('contact/123/notes', 'contact/:id/notes') // true
285
+ * pathHasPrefix('contact/123/notes/get', 'contact/:id/notes') // true
286
+ * pathHasPrefix('contact/123', 'contact/:id/notes') // false
287
+ */
288
+ private pathHasPrefix;
279
289
  private loadLazyModule;
280
290
  private resolveController;
281
291
  private runPipeline;
package/dist/main.js CHANGED
@@ -1321,17 +1321,31 @@ var _Router = class _Router {
1321
1321
  throw new NotFoundException(`No route matches ${request.method} ${request.path}`);
1322
1322
  }
1323
1323
  async tryLoadLazyRoute(requestPath) {
1324
- const firstSegment = requestPath.replace(/^\/+/, "").split("/")[0] ?? "";
1324
+ const normalized = requestPath.replace(/^\/+/, "");
1325
1325
  for (const [prefix, entry] of this.lazyRoutes) {
1326
1326
  if (entry.loaded) continue;
1327
- const normalized = requestPath.replace(/^\/+/, "");
1328
- if (normalized === prefix || normalized.startsWith(prefix + "/") || firstSegment === prefix) {
1327
+ if (this.pathHasPrefix(normalized, prefix)) {
1329
1328
  if (!entry.loading) entry.loading = this.loadLazyModule(prefix, entry);
1330
1329
  await entry.loading;
1331
1330
  return;
1332
1331
  }
1333
1332
  }
1334
1333
  }
1334
+ /**
1335
+ * Returns true when `requestPath` starts with `prefix`, treating `:param`
1336
+ * segments in the prefix as single-segment wildcards.
1337
+ *
1338
+ * @example
1339
+ * pathHasPrefix('contact/123/notes', 'contact/:id/notes') // true
1340
+ * pathHasPrefix('contact/123/notes/get', 'contact/:id/notes') // true
1341
+ * pathHasPrefix('contact/123', 'contact/:id/notes') // false
1342
+ */
1343
+ pathHasPrefix(requestPath, prefix) {
1344
+ const reqSegments = requestPath.split("/");
1345
+ const prefixSegments = prefix.split("/");
1346
+ if (reqSegments.length < prefixSegments.length) return false;
1347
+ return prefixSegments.every((seg, i) => seg.startsWith(":") || seg === reqSegments[i]);
1348
+ }
1335
1349
  loadLazyModule(prefix, entry) {
1336
1350
  const task = this.lazyLoadLock.then(async () => {
1337
1351
  const t0 = performance.now();