@t0.labs/daxta 0.4.4 → 0.4.6

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/README.md CHANGED
@@ -39,27 +39,51 @@ Jest finishes — Docs ready on /docs
39
39
 
40
40
 
41
41
 
42
- ## Install
42
+ ## CLI ile kurulum
43
+
44
+ Tek komut — dependency, `apiDocs(app)`, Jest plugin, `daxta.config.ts` ve sidebar tercihler:
43
45
 
44
46
  ```bash
45
47
  pnpm dlx @t0.labs/daxta install
46
- # or
48
+ # veya
47
49
  npx @t0.labs/daxta install
48
50
  ```
49
51
 
50
- Wires `apiDocs(app)` into your Nest entry and hooks Jest. Then:
52
+ Kurulum sırasında sorulur: Nest entry, test script, docs folder order (`role-resource` / `resource-role`), `{id}` fold, example label stili.
53
+
54
+ Sonra:
55
+
56
+ ```bash
57
+ pnpm run test:integration # test bitince Docs ready
58
+ DAXTA_DOCS=true pnpm start:dev # app portunda /docs
59
+ ```
51
60
 
52
61
  ```ts
53
62
  import { apiDocs } from '@t0.labs/daxta';
54
63
 
55
- apiDocs(app); // requires DAXTA_DOCS in the environment
64
+ apiDocs(app); // DAXTA_DOCS zorunlu (true | false)
56
65
  ```
57
66
 
67
+ Flags: `--yes` · `--dry-run` · `--skip-main` · `--skip-dep` · `--main <path>` · `--fast`
68
+
69
+ ## CLI ile kaldırma
70
+
58
71
  ```bash
59
- pnpm run test:integration # Docs ready when Jest finishes
60
- DAXTA_DOCS=true pnpm start:dev # open /docs on the app port
72
+ pnpm dlx @t0.labs/daxta uninstall
73
+ # veya
74
+ npx @t0.labs/daxta uninstall
61
75
  ```
62
76
 
77
+ Otomatik temizler:
78
+
79
+ - `apiDocs` + `@t0.labs/daxta` import (`main.ts`)
80
+ - Jest `setup` + `jest-reporter` hooks
81
+ - `daxta.config.*` ve `daxta/` output
82
+ - `.gitignore` / `.env` içindeki DAxTA satırları
83
+ - `@t0.labs/daxta` paketi
84
+
85
+ Flags: `--yes` · `--dry-run` · `--keep-dep` (paketi bırakıp sadece wiring’i sök) · `--fast`
86
+
63
87
 
64
88
 
65
89
  ## Docs UI
@@ -87,27 +111,34 @@ DAXTA_DOCS=false # no-op (must still be set)
87
111
  ## Commands
88
112
 
89
113
  ```bash
90
- daxta install # one-shot setup
91
- daxta migrate # after a package bump
92
- daxta build # rebuild OpenAPI/HTML from recorded hits
93
- daxta serve # optional standalone viewer (prefer apiDocs on the app)
94
- daxta tree # choose sidebar folder order for a path
95
- daxta fields … # export field map for an operation
96
- daxta call … # CLI Try-it
114
+ daxta install # CLI kurulum (+ sidebar prompts)
115
+ daxta uninstall # CLI kaldırma (komple)
116
+ daxta migrate # paket bump sonrası upgrade (+ sidebar prompts)
117
+ daxta build # OpenAPI/HTML rebuild
118
+ daxta serve # standalone viewer (opsiyonel)
119
+ daxta tree # sidebar / example tercihlerini yeniden sor
120
+ daxta fields … # field map export
121
+ daxta call … # CLI Try-it
97
122
  ```
98
123
 
99
- ### Sidebar order (`daxta tree`)
124
+ ### Docs presentation (`daxta install` / `daxta migrate` / `daxta tree`)
125
+
126
+ Company-wide choices (saved in `daxta.config.ts`):
127
+
128
+ | Option | Meaning |
129
+ | --- | --- |
130
+ | `treeLayout` | `role-resource` (`v1 › admin › baskets`) or `resource-role` (`v1 › baskets › admin`) |
131
+ | `treeSkipParams` | Don’t nest folders under `{id}` (recommended `true`) |
132
+ | `treeMaxDepth` | Optional max folder depth (e.g. `3`) |
133
+ | `exampleLabelStyle` | OpenAPI example labels: `status-title-case` / `status-case` / `full` |
100
134
 
101
- Pick a path and how it should nest under `/docs`:
135
+ Example label (`status-title-case`):
102
136
 
103
137
  ```text
104
- /v1/admin/baskets
105
- 1) URL order v1 › admin › baskets
106
- 2) Resource-first v1 › baskets › admin
107
- 3) Custom …
138
+ 200 — Admin Find One Basket By Id API — returns basket with items when found by id
108
139
  ```
109
140
 
110
- Saves `treeLayout` / `treePathOverrides` in `daxta.config.ts`. Then `daxta build`.
141
+ Then `daxta build` to refresh `/docs` and export.
111
142
 
112
143
 
113
144
 
@@ -300,7 +300,13 @@
300
300
  }
301
301
  .btn.primary:hover { opacity: 0.92; color: var(--white); }
302
302
  .btn.primary:disabled { opacity: 0.45; cursor: default; }
303
- .live-err { color: #8a2e2e; font-size: 13px; padding: 8px 0; white-space: pre-wrap; }
303
+ .live-err {
304
+ color: #8a2e2e;
305
+ font-size: 13px;
306
+ line-height: 1.5;
307
+ padding: 14px 16px;
308
+ white-space: pre-wrap;
309
+ }
304
310
 
305
311
  .app {
306
312
  display: grid;
@@ -664,7 +670,7 @@
664
670
  .s { color: #2e6b2e; }
665
671
  .n { color: #8a4b12; }
666
672
  .p { color: #6b3fa0; }
667
- .empty { color: var(--stone); font-size: 13px; padding: 8px 0; }
673
+ .empty { color: var(--stone); font-size: 13px; padding: 14px 16px; }
668
674
  .code {
669
675
  font: 500 12px/1 var(--mono);
670
676
  padding: 4px 8px;
@@ -1237,23 +1243,55 @@
1237
1243
  renderEnvPop();
1238
1244
 
1239
1245
  const VIEWER_EXTENSIONS = new Set(["x-viewer", "x-docs", "x-scenarios", "x-tree-segments", "x-workspace"]);
1246
+ const HTTP_EXPORT = ["get", "post", "put", "patch", "delete", "options", "head", "trace"];
1240
1247
 
1248
+ const stripExt = (value) => {
1249
+ if (Array.isArray(value)) return value.map(stripExt);
1250
+ if (!value || typeof value !== "object") return value;
1251
+ const out = {};
1252
+ for (const [key, child] of Object.entries(value)) {
1253
+ if (VIEWER_EXTENSIONS.has(key)) continue;
1254
+ out[key] = stripExt(child);
1255
+ }
1256
+ return out;
1257
+ };
1258
+
1259
+ /** Real URL paths + tags from sidebar tree segments. */
1241
1260
  const toExportSpec = (source) => {
1242
- const walk = (value) => {
1243
- if (Array.isArray(value)) return value.map(walk);
1244
- if (!value || typeof value !== "object") return value;
1245
- const out = {};
1246
- for (const [key, child] of Object.entries(value)) {
1247
- if (VIEWER_EXTENSIONS.has(key)) continue;
1248
- out[key] = walk(child);
1261
+ const pathsIn = source.paths || {};
1262
+ const pathsOut = {};
1263
+ const tagNames = new Set();
1264
+
1265
+ for (const [urlPath, pathItem] of Object.entries(pathsIn)) {
1266
+ if (!pathItem || typeof pathItem !== "object") continue;
1267
+ const itemOut = {};
1268
+ for (const [method, operation] of Object.entries(pathItem)) {
1269
+ if (!HTTP_EXPORT.includes(method) || !operation || typeof operation !== "object") {
1270
+ if (!HTTP_EXPORT.includes(method)) itemOut[method] = stripExt(operation);
1271
+ continue;
1272
+ }
1273
+ const segments = operation["x-tree-segments"] || urlPath.split("/").filter(Boolean);
1274
+ const cleaned = stripExt(operation);
1275
+ const tagParts = segments.filter((part) => !String(part).startsWith("{"));
1276
+ const tag = tagParts.length ? tagParts.join(" / ") : "API";
1277
+ cleaned.tags = [tag];
1278
+ tagNames.add(tag);
1279
+ itemOut[method] = cleaned;
1249
1280
  }
1250
- return out;
1281
+ pathsOut[urlPath] = itemOut;
1282
+ }
1283
+
1284
+ const ordered = {};
1285
+ for (const key of Object.keys(pathsOut).sort((a, b) => a.localeCompare(b))) ordered[key] = pathsOut[key];
1286
+
1287
+ return {
1288
+ openapi: source.openapi || "3.0.3",
1289
+ info: stripExt(source.info) || { title: title, version: "0.0.0" },
1290
+ ...(source.servers ? { servers: stripExt(source.servers) } : {}),
1291
+ tags: [...tagNames].sort((a, b) => a.localeCompare(b)).map((name) => ({ name })),
1292
+ paths: ordered,
1293
+ ...(source.components ? { components: stripExt(source.components) } : {}),
1251
1294
  };
1252
- const exported = walk(source);
1253
- exported.openapi = exported.openapi || "3.0.3";
1254
- if (!exported.info) exported.info = { title: title, version: "0.0.0" };
1255
- if (!exported.paths) exported.paths = {};
1256
- return exported;
1257
1295
  };
1258
1296
 
1259
1297
  const downloadOpenApi = () => {
@@ -162,7 +162,7 @@ function valueFingerprint(value) {
162
162
  }
163
163
  /** Stable shared key so request + response examples from the same hit stay paired. */
164
164
  function exampleKeyForHit(hit, index) {
165
- const base = slug(exampleLabel(hit), index);
165
+ const base = slug((0, catalog_1.exampleLabel)(hit), index);
166
166
  return `${base}-${index}`;
167
167
  }
168
168
  function putExample(store, key, summary, value) {
@@ -324,7 +324,10 @@ function inferDocs(method, pathTemplate, opHits) {
324
324
  collectBodyFields(hit.reqBody, '', add);
325
325
  }
326
326
  }
327
- return { title: (0, catalog_1.defaultTitle)(method, pathTemplate), fields };
327
+ return {
328
+ title: (0, catalog_1.operationSummary)(method, pathTemplate, opHits.map((hit) => hit.test)),
329
+ fields,
330
+ };
328
331
  }
329
332
  function securityForHits(opHits) {
330
333
  const headers = new Set();
@@ -342,12 +345,18 @@ function securityForHits(opHits) {
342
345
  requirement[schemeIdFromHeader(header)] = [];
343
346
  return [requirement];
344
347
  }
345
- function exampleLabel(hit) {
346
- return `${hit.status} - ${(0, catalog_1.caseName)(hit.test)}`;
348
+ function scenarioDisplayName(hit) {
349
+ const cas = (0, catalog_1.caseName)(hit.test);
350
+ const title = (0, catalog_1.apiTitle)(hit.test);
351
+ const style = (0, config_1.getConfig)().exampleLabelStyle ?? 'status-title-case';
352
+ if ((style === 'status-title-case' || style === 'full') && title) {
353
+ return `${title} — ${cas}`;
354
+ }
355
+ return cas;
347
356
  }
348
357
  function toScenario(hit) {
349
358
  return {
350
- name: (0, catalog_1.caseName)(hit.test),
359
+ name: scenarioDisplayName(hit),
351
360
  group: (0, catalog_1.caseGroup)(hit.test),
352
361
  status: hit.status,
353
362
  pathParams: pathParamsFromHit(hit),
@@ -465,7 +474,7 @@ function buildSpec(hits) {
465
474
  const pathItem = (paths[pathTemplate] ??= {});
466
475
  const operation = (pathItem[method] ??= {
467
476
  tags: [tag],
468
- summary: docs.title,
477
+ summary: (0, catalog_1.operationSummary)(method, pathTemplate, opHits.map((hit) => hit.test)),
469
478
  security,
470
479
  responses: {},
471
480
  'x-docs': docs,
@@ -477,7 +486,7 @@ function buildSpec(hits) {
477
486
  operation.parameters = parameters;
478
487
  for (let index = 0; index < opHits.length; index += 1) {
479
488
  const hit = opHits[index];
480
- const label = exampleLabel(hit);
489
+ const label = (0, catalog_1.exampleLabel)(hit);
481
490
  const exampleKey = exampleKeyForHit(hit, index);
482
491
  if (hit.reqBody !== undefined) {
483
492
  operation.requestBody ??= { required: method === 'post' || method === 'put', content: { 'application/json': { schema: inferSchema(hit.reqBody), examples: {} } } };
@@ -13,15 +13,38 @@ export type OperationDoc = {
13
13
  export declare const STATUS_TEXT: Record<string, string>;
14
14
  export declare function declaredMethods(test?: string): string[] | null;
15
15
  export declare function pathSegments(pathTemplate: string): string[];
16
+ /**
17
+ * Sidebar / export-tag folder segments for a path.
18
+ * Honors treeLayout, treeSkipParams, treeMaxDepth, and per-path overrides.
19
+ */
16
20
  export declare function treePathSegments(pathTemplate: string): string[];
17
21
  export declare function viewerTreeConfig(): {
18
22
  workspace: string;
19
23
  baseUrl: string;
20
24
  docsPath: string;
21
- treeLayout: "resource-first" | "url-order";
25
+ treeLayout: TreeLayout;
26
+ treeSkipParams: boolean;
27
+ treeMaxDepth: number | null;
22
28
  treePathOverrides: Record<string, string[]>;
29
+ exampleLabelStyle: "status-case" | "status-title-case" | "full";
23
30
  };
24
31
  export declare function operationTag(pathTemplate: string, method: string): string;
25
32
  export declare function defaultTitle(method: string, pathTemplate: string): string;
26
33
  export declare function caseGroup(test?: string): string;
34
+ export declare function caseSectionLabel(test?: string): string;
35
+ /**
36
+ * Human-readable API title from Jest test name, e.g.
37
+ * "Admin Find One Basket By Id API".
38
+ */
39
+ export declare function apiTitle(test?: string): string | undefined;
27
40
  export declare function caseName(test?: string): string;
41
+ export type ExampleLabelHit = {
42
+ status: number;
43
+ method: string;
44
+ path: string;
45
+ test?: string;
46
+ };
47
+ /** OpenAPI example summary / scenario display name. */
48
+ export declare function exampleLabel(hit: ExampleLabelHit): string;
49
+ /** Prefer human API title from hits; else path. */
50
+ export declare function operationSummary(method: string, pathTemplate: string, tests: Array<string | undefined>): string;
@@ -8,7 +8,11 @@ exports.viewerTreeConfig = viewerTreeConfig;
8
8
  exports.operationTag = operationTag;
9
9
  exports.defaultTitle = defaultTitle;
10
10
  exports.caseGroup = caseGroup;
11
+ exports.caseSectionLabel = caseSectionLabel;
12
+ exports.apiTitle = apiTitle;
11
13
  exports.caseName = caseName;
14
+ exports.exampleLabel = exampleLabel;
15
+ exports.operationSummary = operationSummary;
12
16
  const config_1 = require("../config");
13
17
  exports.STATUS_TEXT = {
14
18
  '200': 'OK',
@@ -26,6 +30,7 @@ const METHOD_ALIASES = {
26
30
  update: ['patch', 'put'],
27
31
  upsert: ['put', 'post', 'patch'],
28
32
  };
33
+ const CASE_SECTION_RE = /^(POSITIVE CASES|SEMANTIC ERROR CASES(?:\s*-\s*AUTH)?|INVALID CASES|OMITTED(?: FIELD)? CASES)\s+/i;
29
34
  function declaredMethods(test) {
30
35
  if (!test)
31
36
  return null;
@@ -38,6 +43,28 @@ function declaredMethods(test) {
38
43
  function pathSegments(pathTemplate) {
39
44
  return pathTemplate.split('/').filter((part) => part && !part.startsWith('{'));
40
45
  }
46
+ function applyLayout(parts, layout) {
47
+ if (parts.length >= 3 && /^v\d+$/i.test(parts[0]) && layout === 'resource-role') {
48
+ return [parts[0], parts[2], parts[1], ...parts.slice(3)];
49
+ }
50
+ return parts;
51
+ }
52
+ function applyFold(parts, skipParams, maxDepth) {
53
+ let next = parts;
54
+ if (skipParams) {
55
+ const paramIdx = next.findIndex((part) => part.startsWith('{'));
56
+ if (paramIdx >= 0)
57
+ next = next.slice(0, paramIdx);
58
+ }
59
+ if (typeof maxDepth === 'number' && maxDepth > 0) {
60
+ next = next.slice(0, maxDepth);
61
+ }
62
+ return next;
63
+ }
64
+ /**
65
+ * Sidebar / export-tag folder segments for a path.
66
+ * Honors treeLayout, treeSkipParams, treeMaxDepth, and per-path overrides.
67
+ */
41
68
  function treePathSegments(pathTemplate) {
42
69
  const config = (0, config_1.getConfig)();
43
70
  const custom = config.treePathSegments?.(pathTemplate);
@@ -46,11 +73,9 @@ function treePathSegments(pathTemplate) {
46
73
  const exact = config.treePathOverrides[pathTemplate];
47
74
  if (exact?.length)
48
75
  return exact;
49
- const parts = pathTemplate.split('/').filter(Boolean);
50
- if (parts.length >= 3 && /^v\d+$/i.test(parts[0]) && config.treeLayout === 'resource-first') {
51
- return [parts[0], parts[2], parts[1], ...parts.slice(3)];
52
- }
53
- return parts;
76
+ const layout = (0, config_1.normalizeTreeLayout)(config.treeLayout);
77
+ const parts = applyLayout(pathTemplate.split('/').filter(Boolean), layout);
78
+ return applyFold(parts, config.treeSkipParams !== false, config.treeMaxDepth);
54
79
  }
55
80
  function viewerTreeConfig() {
56
81
  const config = (0, config_1.getConfig)();
@@ -58,8 +83,11 @@ function viewerTreeConfig() {
58
83
  workspace: config.workspace,
59
84
  baseUrl: config.baseUrl,
60
85
  docsPath: config.docsPath,
61
- treeLayout: config.treeLayout,
86
+ treeLayout: (0, config_1.normalizeTreeLayout)(config.treeLayout),
87
+ treeSkipParams: config.treeSkipParams !== false,
88
+ treeMaxDepth: config.treeMaxDepth ?? null,
62
89
  treePathOverrides: config.treePathOverrides,
90
+ exampleLabelStyle: config.exampleLabelStyle ?? 'status-title-case',
63
91
  };
64
92
  }
65
93
  function titleCase(value) {
@@ -73,7 +101,7 @@ function operationTag(pathTemplate, method) {
73
101
  const custom = (0, config_1.getConfig)().operationTag?.(pathTemplate, method);
74
102
  if (custom)
75
103
  return custom;
76
- const parts = pathSegments(pathTemplate).filter((part) => !/^v\d+$/i.test(part));
104
+ const parts = treePathSegments(pathTemplate).filter((part) => !part.startsWith('{') && !/^v\d+$/i.test(part));
77
105
  if (!parts.length)
78
106
  return 'API';
79
107
  if (parts.length === 1)
@@ -101,11 +129,78 @@ function caseGroup(test) {
101
129
  return 'Missing fields';
102
130
  return 'Other';
103
131
  }
132
+ function caseSectionLabel(test) {
133
+ if (!test)
134
+ return '';
135
+ const match = test.match(/(POSITIVE CASES|SEMANTIC ERROR CASES(?:\s*-\s*AUTH)?|INVALID CASES|OMITTED(?: FIELD)? CASES)/i);
136
+ return match?.[1]?.toUpperCase() ?? '';
137
+ }
138
+ /**
139
+ * Human-readable API title from Jest test name, e.g.
140
+ * "Admin Find One Basket By Id API".
141
+ */
142
+ function apiTitle(test) {
143
+ if (!test)
144
+ return undefined;
145
+ const patterns = [
146
+ /^(.+?\bAPI)\s*[-–—]\s*(?:GET|POST|PUT|PATCH|DELETE)\b/i,
147
+ /\]\s*(?:\([^)]*\)\s*)?(.+?\bAPI)\s+(?:POSITIVE|SEMANTIC|INVALID|OMITTED)\b/i,
148
+ /^(.+?\bAPI)\s+\/\S+\s+\[(?:GET|POST|PUT|PATCH|DELETE)/i,
149
+ /\[(?:GET|POST|PUT|PATCH|DELETE|UPDATE|UPSERT)\]\s*(?:\([^)]*\)\s*)?(.+?\bAPI)\b/i,
150
+ ];
151
+ for (const re of patterns) {
152
+ const match = test.match(re);
153
+ const title = match?.[1]?.trim();
154
+ if (title && title.length < 120)
155
+ return title;
156
+ }
157
+ return undefined;
158
+ }
104
159
  function caseName(test) {
105
160
  if (!test)
106
161
  return 'example';
107
- return (test
162
+ let rest = test
108
163
  .replace(/^.*?\[(?:GET|POST|PUT|PATCH|DELETE|UPDATE|UPSERT)\]\s*(?:\(integration\))?\s*/i, '')
109
- .replace(/^(POSITIVE CASES|SEMANTIC ERROR CASES(?:\s*-\s*AUTH)?|INVALID CASES|OMITTED(?: FIELD)? CASES)\s+/i, '')
110
- .trim() || test);
164
+ .replace(CASE_SECTION_RE, '')
165
+ .trim();
166
+ // "Admin Find One Basket By Id API - GET /path POSITIVE CASES returns…"
167
+ rest = rest
168
+ .replace(/^.+?\bAPI\s*[-–—]\s*(?:GET|POST|PUT|PATCH|DELETE)\s+\S+\s+/i, '')
169
+ .replace(CASE_SECTION_RE, '')
170
+ .trim();
171
+ // Drop leading human title if still present before the case text
172
+ const title = apiTitle(test);
173
+ if (title && rest.startsWith(title)) {
174
+ rest = rest.slice(title.length).replace(/^[-–—\s]+/, '').replace(CASE_SECTION_RE, '').trim();
175
+ }
176
+ return rest || test;
177
+ }
178
+ /** OpenAPI example summary / scenario display name. */
179
+ function exampleLabel(hit) {
180
+ const style = (0, config_1.getConfig)().exampleLabelStyle ?? 'status-title-case';
181
+ const cas = caseName(hit.test);
182
+ const title = apiTitle(hit.test);
183
+ const method = (hit.method || 'get').toUpperCase();
184
+ const section = caseSectionLabel(hit.test);
185
+ if (style === 'full') {
186
+ const head = title ? `${title} - ${method} ${hit.path}` : `${method} ${hit.path}`;
187
+ const tail = [section, cas].filter(Boolean).join(' ');
188
+ return `${hit.status} — ${head}${tail ? ` ${tail}` : ''}`;
189
+ }
190
+ if (style === 'status-title-case' && title) {
191
+ return `${hit.status} — ${title} — ${cas}`;
192
+ }
193
+ return `${hit.status} — ${cas}`;
194
+ }
195
+ /** Prefer human API title from hits; else path. */
196
+ function operationSummary(method, pathTemplate, tests) {
197
+ const custom = (0, config_1.getConfig)().operationTitle?.(method, pathTemplate);
198
+ if (custom)
199
+ return custom;
200
+ for (const test of tests) {
201
+ const title = apiTitle(test);
202
+ if (title)
203
+ return title;
204
+ }
205
+ return defaultTitle(method, pathTemplate);
111
206
  }
@@ -5,6 +5,8 @@ export declare function findMainCandidates(cwd: string): string[];
5
5
  */
6
6
  export declare function resolveMainPath(cwd: string, candidates: string[]): Promise<string | null>;
7
7
  export declare function injectApiDocs(filePath: string, dryRun?: boolean): string;
8
+ /** Remove `apiDocs(...)` calls and `@t0.labs/daxta` imports from a Nest entry file. */
9
+ export declare function removeApiDocs(filePath: string, dryRun?: boolean): string;
8
10
  export type InjectMainOptions = {
9
11
  cwd?: string;
10
12
  dryRun?: boolean;
@@ -36,6 +36,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.findMainCandidates = findMainCandidates;
37
37
  exports.resolveMainPath = resolveMainPath;
38
38
  exports.injectApiDocs = injectApiDocs;
39
+ exports.removeApiDocs = removeApiDocs;
39
40
  exports.resolveMainTarget = resolveMainTarget;
40
41
  const readline_1 = require("readline");
41
42
  const fs_1 = require("fs");
@@ -191,6 +192,31 @@ function injectApiDocs(filePath, dryRun = false) {
191
192
  (0, fs_1.writeFileSync)(filePath, next);
192
193
  return `injected apiDocs() into ${path.relative(process.cwd(), filePath)}`;
193
194
  }
195
+ /** Remove `apiDocs(...)` calls and `@t0.labs/daxta` imports from a Nest entry file. */
196
+ function removeApiDocs(filePath, dryRun = false) {
197
+ const before = (0, fs_1.readFileSync)(filePath, 'utf8');
198
+ let next = before;
199
+ next = next.replace(/^[ \t]*apiDocs\s*\([^;]*\)\s*;?[ \t]*\n?/gm, '');
200
+ next = next.replace(/^[ \t]*\b(?:mountDaxtaDocs|docs)\s*\([^;]*\)\s*;?[ \t]*\n?/gm, '');
201
+ next = next.replace(/^[ \t]*import\s*\{[^}]*\bapiDocs\b[^}]*\}\s*from\s*['"]@t0\.labs\/daxta['"]\s*;?[ \t]*\n?/gm, (line) => {
202
+ // Drop whole import if only apiDocs (and legacy aliases); otherwise strip the name
203
+ const names = line.match(/\{([^}]*)\}/)?.[1] ?? '';
204
+ const remaining = names
205
+ .split(',')
206
+ .map((part) => part.trim())
207
+ .filter((part) => part && !/^(apiDocs|mountDaxtaDocs|docs)$/.test(part));
208
+ if (!remaining.length)
209
+ return '';
210
+ return line.replace(/\{[^}]*\}/, `{ ${remaining.join(', ')} }`);
211
+ });
212
+ // Orphan blank lines left after removals — light tidy
213
+ next = next.replace(/\n{3,}/g, '\n\n');
214
+ if (next === before)
215
+ return `no apiDocs in ${path.relative(process.cwd(), filePath)}`;
216
+ if (!dryRun)
217
+ (0, fs_1.writeFileSync)(filePath, next);
218
+ return `removed apiDocs from ${path.relative(process.cwd(), filePath)}`;
219
+ }
194
220
  /** Resolve which file to inject into (prompt / --main / --yes). Null = skip. */
195
221
  async function resolveMainTarget(options = {}) {
196
222
  const cwd = options.cwd ?? process.cwd();
@@ -114,7 +114,10 @@ export default defineConfig({
114
114
  controllersRoot: 'src',
115
115
  outDir: 'daxta/out',
116
116
  docsPath: '/docs',
117
- treeLayout: 'resource-first',
117
+ treeLayout: 'role-resource',
118
+ treeSkipParams: true,
119
+ treeMaxDepth: null,
120
+ exampleLabelStyle: 'status-title-case',
118
121
  fieldsFile: 'daxta/out/daxta.fields.json',
119
122
  });
120
123
  `;
@@ -11,4 +11,6 @@ export declare function resolveJestConfigPath(cwd: string, options: {
11
11
  export declare function injectJestHooks(jestConfigPath: string, dryRun?: boolean): string[];
12
12
  /** Restore package.json script if it was wrapped as `daxta test --yes`. */
13
13
  export declare function unwrapDaxtaTestScript(scripts: Record<string, string>, scriptName: string, originalCommand: string): boolean;
14
+ /** Remove DAxTA Jest setup + reporter from a JSON/JS config. */
15
+ export declare function removeJestHooks(jestConfigPath: string, dryRun?: boolean): string[];
14
16
  export {};
@@ -37,6 +37,7 @@ exports.loadJestJson = loadJestJson;
37
37
  exports.resolveJestConfigPath = resolveJestConfigPath;
38
38
  exports.injectJestHooks = injectJestHooks;
39
39
  exports.unwrapDaxtaTestScript = unwrapDaxtaTestScript;
40
+ exports.removeJestHooks = removeJestHooks;
40
41
  const fs_1 = require("fs");
41
42
  const path = __importStar(require("path"));
42
43
  const discover_test_1 = require("./discover-test");
@@ -209,3 +210,102 @@ function unwrapDaxtaTestScript(scripts, scriptName, originalCommand) {
209
210
  scripts[scriptName] = originalCommand;
210
211
  return true;
211
212
  }
213
+ function removeStringFromArrayLiteral(source, key, needle) {
214
+ const range = findArrayPropRange(source, key);
215
+ if (!range)
216
+ return { source, removed: false };
217
+ const inner = source.slice(range.open + 1, range.close);
218
+ if (!inner.includes(needle))
219
+ return { source, removed: false };
220
+ let nextInner = inner
221
+ .replace(new RegExp(`(['"])${needle.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\1\\s*,\\s*`), '')
222
+ .replace(new RegExp(`,\\s*(['"])${needle.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\1`), '')
223
+ .replace(new RegExp(`(['"])${needle.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\1`), '');
224
+ return {
225
+ source: `${source.slice(0, range.open + 1)}${nextInner}${source.slice(range.close)}`,
226
+ removed: true,
227
+ };
228
+ }
229
+ function removeReporterFromJsSource(source) {
230
+ // Single-string reporter entry
231
+ let { source: next, removed } = removeStringFromArrayLiteral(source, 'reporters', REPORTER);
232
+ // Array tuple reporter: [ '@t0.labs/daxta/jest-reporter', { ... } ],
233
+ const tupleRe = new RegExp(`,?\\s*\\[\\s*['"]${REPORTER.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}['"]\\s*,\\s*\\{[\\s\\S]*?\\}\\s*\\]\\s*,?`);
234
+ if (tupleRe.test(next)) {
235
+ next = next.replace(tupleRe, (match) => (match.trim().startsWith(',') ? '' : ''));
236
+ // Clean double commas / leading commas in array
237
+ const range = findArrayPropRange(next, 'reporters');
238
+ if (range) {
239
+ let inner = next.slice(range.open + 1, range.close);
240
+ inner = inner.replace(/,\s*,/g, ',').replace(/^\s*,/, '').replace(/,\s*$/, '');
241
+ next = `${next.slice(0, range.open + 1)}${inner}${next.slice(range.close)}`;
242
+ }
243
+ removed = true;
244
+ }
245
+ return { source: next, removed };
246
+ }
247
+ function removeFromJsSource(source) {
248
+ const notes = [];
249
+ let next = source;
250
+ const setup = removeStringFromArrayLiteral(next, 'setupFilesAfterEnv', SETUP);
251
+ next = setup.source;
252
+ if (setup.removed)
253
+ notes.push(`setupFilesAfterEnv -= ${SETUP}`);
254
+ const reporters = removeReporterFromJsSource(next);
255
+ next = reporters.source;
256
+ if (reporters.removed)
257
+ notes.push(`reporters -= ${REPORTER}`);
258
+ else {
259
+ const plain = removeStringFromArrayLiteral(next, 'reporters', REPORTER);
260
+ next = plain.source;
261
+ if (plain.removed)
262
+ notes.push(`reporters -= ${REPORTER}`);
263
+ }
264
+ return { source: next, notes };
265
+ }
266
+ function removeFromJsonConfig(filePath, dryRun) {
267
+ const notes = [];
268
+ const data = loadJestJson(filePath);
269
+ if (Array.isArray(data.setupFilesAfterEnv)) {
270
+ const before = data.setupFilesAfterEnv;
271
+ const after = before.filter((entry) => entry !== SETUP);
272
+ if (after.length !== before.length) {
273
+ data.setupFilesAfterEnv = after;
274
+ notes.push(`setupFilesAfterEnv -= ${SETUP}`);
275
+ }
276
+ }
277
+ if (Array.isArray(data.reporters)) {
278
+ const before = data.reporters;
279
+ const after = before.filter((entry) => {
280
+ if (entry === REPORTER)
281
+ return false;
282
+ if (Array.isArray(entry) && entry[0] === REPORTER)
283
+ return false;
284
+ return true;
285
+ });
286
+ if (after.length !== before.length) {
287
+ data.reporters = after.length ? after : ['default'];
288
+ notes.push(`reporters -= ${REPORTER}`);
289
+ }
290
+ }
291
+ if (!dryRun && notes.length) {
292
+ (0, fs_1.writeFileSync)(filePath, `${JSON.stringify(data, null, 2)}\n`);
293
+ }
294
+ return notes;
295
+ }
296
+ /** Remove DAxTA Jest setup + reporter from a JSON/JS config. */
297
+ function removeJestHooks(jestConfigPath, dryRun = false) {
298
+ if (!(0, fs_1.existsSync)(jestConfigPath))
299
+ return [];
300
+ if (isJsonConfigPath(jestConfigPath)) {
301
+ return removeFromJsonConfig(jestConfigPath, dryRun);
302
+ }
303
+ if (!isJsLikeConfigPath(jestConfigPath))
304
+ return [];
305
+ const original = (0, fs_1.readFileSync)(jestConfigPath, 'utf8');
306
+ const { source, notes } = removeFromJsSource(original);
307
+ if (!dryRun && notes.length && source !== original) {
308
+ (0, fs_1.writeFileSync)(jestConfigPath, source);
309
+ }
310
+ return notes;
311
+ }