@t0.labs/daxta 1.2.2 → 1.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -98,8 +98,19 @@ function applyResourceAliases(parts, aliases) {
98
98
  }
99
99
  return current;
100
100
  }
101
+ function controllerBasePath(pathTemplate) {
102
+ try {
103
+ // Lazy require avoids circular init
104
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
105
+ const dto = require('../fields/dto-fields');
106
+ return dto.matchControllerPrefix?.(pathTemplate) || pathTemplate;
107
+ }
108
+ catch {
109
+ return pathTemplate;
110
+ }
111
+ }
101
112
  function applySubResourceMode(parts, mode) {
102
- if (!mode || mode === 'nested')
113
+ if (!mode || mode === 'nested' || mode === 'controller')
103
114
  return parts;
104
115
  const startIdx = /^v\d+$/i.test(parts[0] || '') ? 2 : 1;
105
116
  if (parts.length <= startIdx + 1)
@@ -122,7 +133,8 @@ function treePathSegments(pathTemplate) {
122
133
  if (exact?.length)
123
134
  return exact;
124
135
  const layout = (0, config_1.normalizeTreeLayout)(config.treeLayout);
125
- const folded = applyFold(pathTemplate.split('/').filter(Boolean), config.treeSkipParams !== false);
136
+ const sourcePath = config.treeSubResourceMode === 'controller' ? controllerBasePath(pathTemplate) : pathTemplate;
137
+ const folded = applyFold(sourcePath.split('/').filter(Boolean), config.treeSkipParams !== false);
126
138
  const aliased = applyResourceAliases(folded, config.treeResourceAliases);
127
139
  const shaped = applySubResourceMode(aliased, config.treeSubResourceMode);
128
140
  return applyLayout(shaped, layout);
package/dist/cli/tree.js CHANGED
@@ -120,15 +120,22 @@ async function pickSkipParams(current) {
120
120
  }
121
121
  async function pickSubResourceMode(current, layout) {
122
122
  const roleFirst = layout === 'role-resource';
123
+ const initialIndex = current === 'controller' ? 0 : current === 'merge' ? 1 : current === 'root' ? 2 : 3;
123
124
  return (0, ui_1.selectMenu)({
124
125
  title: 'Sub-resources after main resource',
125
- subtitle: 'e.g. /v1/public/shopping-cart/items/{id}/quantity',
126
- initialIndex: current === 'merge' ? 0 : current === 'root' ? 1 : 2,
126
+ subtitle: 'e.g. /v1/public/solution-partner-identity/auth/phone/verify-otp',
127
+ initialIndex,
127
128
  options: [
129
+ {
130
+ value: 'controller',
131
+ label: 'Group by @Controller path',
132
+ badge: 'recommended',
133
+ preview: roleFirst ? 'v1 › public › solution-partner-identity' : 'v1 › solution-partner-identity › public',
134
+ hint: 'Stops folders at each Nest @Controller(...) prefix; method routes sit inside',
135
+ },
128
136
  {
129
137
  value: 'merge',
130
138
  label: 'Merge into one folder (shopping-cart-items)',
131
- badge: 'recommended',
132
139
  preview: roleFirst ? 'v1 › public › shopping-cart-items' : 'v1 › shopping-cart-items › public',
133
140
  hint: 'Joins sub-resources with "-" instead of opening extra subfolders',
134
141
  },
@@ -136,12 +143,14 @@ async function pickSubResourceMode(current, layout) {
136
143
  value: 'root',
137
144
  label: 'Group under main resource (shopping-cart)',
138
145
  preview: roleFirst ? 'v1 › public › shopping-cart' : 'v1 › shopping-cart › public',
139
- hint: 'Keeps all sub-routes directly under the main resource folder',
146
+ hint: 'Keeps all sub-routes directly under the first resource segment',
140
147
  },
141
148
  {
142
149
  value: 'nested',
143
- label: 'Keep nested subfolders (shopping-cart › items)',
144
- preview: roleFirst ? 'v1 › public › shopping-cart › items' : 'v1 › shopping-cart › public › items',
150
+ label: 'Keep nested subfolders (auth › phone)',
151
+ preview: roleFirst
152
+ ? 'v1 › public › solution-partner-identity › auth › phone'
153
+ : 'v1 › solution-partner-identity › public › auth › phone',
145
154
  hint: 'Creates a separate subfolder for every segment',
146
155
  },
147
156
  ],
package/dist/config.d.ts CHANGED
@@ -4,7 +4,7 @@ export type TreeLayout = 'role-resource' | 'resource-role';
4
4
  export type LegacyTreeLayout = 'url-order' | 'resource-first';
5
5
  export type ExampleLabelStyle = 'status-case' | 'status-title-case' | 'full';
6
6
  export type WriteMode = 'on-complete' | 'incremental';
7
- export type SubResourceMode = 'nested' | 'merge' | 'root';
7
+ export type SubResourceMode = 'controller' | 'nested' | 'merge' | 'root';
8
8
  export type SpecInfo = {
9
9
  title?: string;
10
10
  version?: string;
@@ -52,6 +52,7 @@ export type DaxtaConfig = {
52
52
  treeCollapseSingle?: boolean;
53
53
  /**
54
54
  * How segments after the main resource are grouped into folders:
55
+ * - controller → stops folders at each NestJS @Controller(...) path
55
56
  * - nested → v1 › shopping-cart › public › items (default)
56
57
  * - merge → v1 › shopping-cart-items › public
57
58
  * - root → v1 › shopping-cart › public (all sub-routes under main resource)
@@ -8,5 +8,7 @@ export declare function listControllerPathTemplates(): string[];
8
8
  * Prefers the most specific declared route (longest path, fewest params).
9
9
  */
10
10
  export declare function matchControllerTemplate(pathname: string, method?: string): string | null;
11
+ /** Return the Nest @Controller(...) prefix for a route (used by `treeSubResourceMode: 'controller'`). */
12
+ export declare function matchControllerPrefix(pathname: string, method?: string): string | null;
11
13
  /** Returns required flag from DTO metadata, or undefined when unknown (no DTO / no validators). */
12
14
  export declare function dtoRequired(method: string, pathTemplate: string, location: FieldLocation, fieldName: string): boolean | undefined;
@@ -36,6 +36,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.controllerRouteCount = controllerRouteCount;
37
37
  exports.listControllerPathTemplates = listControllerPathTemplates;
38
38
  exports.matchControllerTemplate = matchControllerTemplate;
39
+ exports.matchControllerPrefix = matchControllerPrefix;
39
40
  exports.dtoRequired = dtoRequired;
40
41
  /**
41
42
  * Resolve Required / Optional from Nest controllers + class-validator DTO metadata.
@@ -298,6 +299,7 @@ function parseController(filePath) {
298
299
  routes.push({
299
300
  method: httpMethod === 'all' ? 'post' : httpMethod,
300
301
  pathTemplate: normalizeSegments(versionPrefix, controllerPath, routePath),
302
+ controllerPrefix: normalizeSegments(versionPrefix, controllerPath),
301
303
  body: resolve(bodyName),
302
304
  query: resolve(queryName),
303
305
  param: resolve(paramName),
@@ -381,6 +383,36 @@ function matchControllerTemplate(pathname, method) {
381
383
  }
382
384
  return best?.template ?? null;
383
385
  }
386
+ /** Return the Nest @Controller(...) prefix for a route (used by `treeSubResourceMode: 'controller'`). */
387
+ function matchControllerPrefix(pathname, method) {
388
+ const routes = getRoutes();
389
+ if (!routes.length)
390
+ return null;
391
+ const actual = (pathname.split('?')[0] || '/').replace(/\/+$/, '') || '/';
392
+ const stripped = actual.replace(/^\/v\d+(?=\/|$)/i, '') || '/';
393
+ const methodKey = method?.toLowerCase();
394
+ let best = null;
395
+ for (const route of routes) {
396
+ if (methodKey && route.method !== 'all' && route.method !== methodKey)
397
+ continue;
398
+ const base = route.pathTemplate;
399
+ const versioned = ensureVersionPrefix(base, actual);
400
+ const candidates = [...new Set([base, versioned])];
401
+ for (const template of candidates) {
402
+ const ok = (0, path_util_1.pathMatchesTemplate)(template, actual) ||
403
+ (0, path_util_1.pathMatchesTemplate)(base, stripped) ||
404
+ (0, path_util_1.pathMatchesTemplate)(template, stripped);
405
+ if (!ok)
406
+ continue;
407
+ const resolved = (0, path_util_1.pathMatchesTemplate)(template, actual) ? template : ensureVersionPrefix(base, actual);
408
+ const score = scoreTemplate(resolved);
409
+ if (!best || score > best.score) {
410
+ best = { prefix: ensureVersionPrefix(route.controllerPrefix, actual), score };
411
+ }
412
+ }
413
+ }
414
+ return best?.prefix && best.prefix !== '/' ? best.prefix : null;
415
+ }
384
416
  function findRoute(method, pathTemplate) {
385
417
  const keyMethod = method.toLowerCase();
386
418
  const routes = getRoutes();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t0.labs/daxta",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "description": "DAxTA — Tested behavior. Trusted API docs. Generate API documentation from observed test execution.",
5
5
  "license": "MIT",
6
6
  "author": {