@t0.labs/daxta 0.4.6 → 0.4.7

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
@@ -127,11 +127,12 @@ Company-wide choices (saved in `daxta.config.ts`):
127
127
 
128
128
  | Option | Meaning |
129
129
  | --- | --- |
130
- | `treeLayout` | `role-resource` (`v1 › admin › baskets`) or `resource-role` (`v1 › baskets › admin`) |
130
+ | `treeLayout` | `role-resource` (`v1 › admin › baskets`) or `resource-role` (`v1 › baskets › admin`) — sidebar **and** OpenAPI export path keys |
131
131
  | `treeSkipParams` | Don’t nest folders under `{id}` (recommended `true`) |
132
- | `treeMaxDepth` | Optional max folder depth (e.g. `3`) |
133
132
  | `exampleLabelStyle` | OpenAPI example labels: `status-title-case` / `status-case` / `full` |
134
133
 
134
+ OpenAPI export remaps path keys to match the sidebar tree. Real URLs are kept on `x-daxta-url-path` when the layout differs (e.g. `/v1/admin/baskets` → export `/v1/baskets/admin`).
135
+
135
136
  Example label (`status-title-case`):
136
137
 
137
138
  ```text
@@ -1256,7 +1256,21 @@
1256
1256
  return out;
1257
1257
  };
1258
1258
 
1259
- /** Real URL paths + tags from sidebar tree segments. */
1259
+ /** Path keys follow sidebar tree; real URL kept on x-daxta-url-path when remapped. */
1260
+ const exportPathFromTree = (urlPath, treeSegments) => {
1261
+ const originalParts = urlPath.split("/").filter(Boolean);
1262
+ const paramIdx = originalParts.findIndex((part) => String(part).startsWith("{"));
1263
+ const tail = paramIdx >= 0 ? originalParts.slice(paramIdx) : [];
1264
+ const treeHasParam = treeSegments.some((part) => String(part).startsWith("{"));
1265
+ const parts =
1266
+ treeSegments.length === 0
1267
+ ? originalParts
1268
+ : treeHasParam || paramIdx < 0
1269
+ ? treeSegments
1270
+ : [...treeSegments, ...tail];
1271
+ return "/" + parts.join("/");
1272
+ };
1273
+
1260
1274
  const toExportSpec = (source) => {
1261
1275
  const pathsIn = source.paths || {};
1262
1276
  const pathsOut = {};
@@ -1264,10 +1278,23 @@
1264
1278
 
1265
1279
  for (const [urlPath, pathItem] of Object.entries(pathsIn)) {
1266
1280
  if (!pathItem || typeof pathItem !== "object") continue;
1267
- const itemOut = {};
1281
+
1282
+ let treeSegments = null;
1283
+ for (const [method, operation] of Object.entries(pathItem)) {
1284
+ if (!HTTP_EXPORT.includes(method) || !operation || typeof operation !== "object") continue;
1285
+ treeSegments = operation["x-tree-segments"] || urlPath.split("/").filter(Boolean);
1286
+ break;
1287
+ }
1288
+ if (!treeSegments) treeSegments = urlPath.split("/").filter(Boolean);
1289
+
1290
+ const exportPath = exportPathFromTree(urlPath, treeSegments);
1291
+ const itemOut = { ...(pathsOut[exportPath] || {}) };
1292
+
1268
1293
  for (const [method, operation] of Object.entries(pathItem)) {
1269
1294
  if (!HTTP_EXPORT.includes(method) || !operation || typeof operation !== "object") {
1270
- if (!HTTP_EXPORT.includes(method)) itemOut[method] = stripExt(operation);
1295
+ if (!HTTP_EXPORT.includes(method) && itemOut[method] === undefined) {
1296
+ itemOut[method] = stripExt(operation);
1297
+ }
1271
1298
  continue;
1272
1299
  }
1273
1300
  const segments = operation["x-tree-segments"] || urlPath.split("/").filter(Boolean);
@@ -1276,9 +1303,10 @@
1276
1303
  const tag = tagParts.length ? tagParts.join(" / ") : "API";
1277
1304
  cleaned.tags = [tag];
1278
1305
  tagNames.add(tag);
1306
+ if (exportPath !== urlPath) cleaned["x-daxta-url-path"] = urlPath;
1279
1307
  itemOut[method] = cleaned;
1280
1308
  }
1281
- pathsOut[urlPath] = itemOut;
1309
+ pathsOut[exportPath] = itemOut;
1282
1310
  }
1283
1311
 
1284
1312
  const ordered = {};
@@ -15,7 +15,7 @@ export declare function declaredMethods(test?: string): string[] | null;
15
15
  export declare function pathSegments(pathTemplate: string): string[];
16
16
  /**
17
17
  * Sidebar / export-tag folder segments for a path.
18
- * Honors treeLayout, treeSkipParams, treeMaxDepth, and per-path overrides.
18
+ * Honors treeLayout, treeSkipParams, and per-path overrides.
19
19
  */
20
20
  export declare function treePathSegments(pathTemplate: string): string[];
21
21
  export declare function viewerTreeConfig(): {
@@ -24,7 +24,6 @@ export declare function viewerTreeConfig(): {
24
24
  docsPath: string;
25
25
  treeLayout: TreeLayout;
26
26
  treeSkipParams: boolean;
27
- treeMaxDepth: number | null;
28
27
  treePathOverrides: Record<string, string[]>;
29
28
  exampleLabelStyle: "status-case" | "status-title-case" | "full";
30
29
  };
@@ -49,21 +49,17 @@ function applyLayout(parts, layout) {
49
49
  }
50
50
  return parts;
51
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;
52
+ function applyFold(parts, skipParams) {
53
+ if (!skipParams)
54
+ return parts;
55
+ const paramIdx = parts.findIndex((part) => part.startsWith('{'));
56
+ if (paramIdx < 0)
57
+ return parts;
58
+ return parts.slice(0, paramIdx);
63
59
  }
64
60
  /**
65
61
  * Sidebar / export-tag folder segments for a path.
66
- * Honors treeLayout, treeSkipParams, treeMaxDepth, and per-path overrides.
62
+ * Honors treeLayout, treeSkipParams, and per-path overrides.
67
63
  */
68
64
  function treePathSegments(pathTemplate) {
69
65
  const config = (0, config_1.getConfig)();
@@ -75,7 +71,7 @@ function treePathSegments(pathTemplate) {
75
71
  return exact;
76
72
  const layout = (0, config_1.normalizeTreeLayout)(config.treeLayout);
77
73
  const parts = applyLayout(pathTemplate.split('/').filter(Boolean), layout);
78
- return applyFold(parts, config.treeSkipParams !== false, config.treeMaxDepth);
74
+ return applyFold(parts, config.treeSkipParams !== false);
79
75
  }
80
76
  function viewerTreeConfig() {
81
77
  const config = (0, config_1.getConfig)();
@@ -85,7 +81,6 @@ function viewerTreeConfig() {
85
81
  docsPath: config.docsPath,
86
82
  treeLayout: (0, config_1.normalizeTreeLayout)(config.treeLayout),
87
83
  treeSkipParams: config.treeSkipParams !== false,
88
- treeMaxDepth: config.treeMaxDepth ?? null,
89
84
  treePathOverrides: config.treePathOverrides,
90
85
  exampleLabelStyle: config.exampleLabelStyle ?? 'status-title-case',
91
86
  };
@@ -116,7 +116,6 @@ export default defineConfig({
116
116
  docsPath: '/docs',
117
117
  treeLayout: 'role-resource',
118
118
  treeSkipParams: true,
119
- treeMaxDepth: null,
120
119
  exampleLabelStyle: 'status-title-case',
121
120
  fieldsFile: 'daxta/out/daxta.fields.json',
122
121
  });
package/dist/cli/tree.js CHANGED
@@ -23,7 +23,7 @@ function normalizePathInput(raw) {
23
23
  return trimmed;
24
24
  return trimmed.startsWith('/') ? trimmed.replace(/\/+$/, '') || '/' : `/${trimmed.replace(/\/+$/, '')}`;
25
25
  }
26
- function layoutSegments(pathTemplate, layout, skipParams, maxDepth) {
26
+ function layoutSegments(pathTemplate, layout, skipParams) {
27
27
  let parts = pathTemplate.split('/').filter(Boolean);
28
28
  if (parts.length >= 3 && /^v\d+$/i.test(parts[0]) && layout === 'resource-role') {
29
29
  parts = [parts[0], parts[2], parts[1], ...parts.slice(3)];
@@ -33,8 +33,6 @@ function layoutSegments(pathTemplate, layout, skipParams, maxDepth) {
33
33
  if (idx >= 0)
34
34
  parts = parts.slice(0, idx);
35
35
  }
36
- if (typeof maxDepth === 'number' && maxDepth > 0)
37
- parts = parts.slice(0, maxDepth);
38
36
  return parts;
39
37
  }
40
38
  function listKnownPaths() {
@@ -94,11 +92,11 @@ async function pickLayout(current) {
94
92
  console.log(` ${ui_1.c.dim('sample')} ${ui_1.c.cyan(sample)}`);
95
93
  console.log('');
96
94
  console.log(` ${ui_1.c.cyan('1')} role → resource ${ui_1.c.dim('recommended')}`);
97
- console.log(` ${(0, config_edit_1.previewTree)(layoutSegments(sample, 'role-resource', true, null))}`);
95
+ console.log(` ${(0, config_edit_1.previewTree)(layoutSegments(sample, 'role-resource', true))}`);
98
96
  console.log(` ${ui_1.c.dim('v1 › admin › baskets (ops under baskets, not under {id})')}`);
99
97
  console.log('');
100
98
  console.log(` ${ui_1.c.cyan('2')} resource → role`);
101
- console.log(` ${(0, config_edit_1.previewTree)(layoutSegments(sample, 'resource-role', true, null))}`);
99
+ console.log(` ${(0, config_edit_1.previewTree)(layoutSegments(sample, 'resource-role', true))}`);
102
100
  console.log(` ${ui_1.c.dim('v1 › baskets › admin')}`);
103
101
  console.log('');
104
102
  console.log(` ${ui_1.c.cyan('3')} keep ${ui_1.c.dim(`(${current})`)}`);
@@ -127,22 +125,6 @@ async function pickSkipParams(current) {
127
125
  return false;
128
126
  throw new Error(`Unknown choice: ${answer}`);
129
127
  }
130
- async function pickMaxDepth(current) {
131
- console.log('');
132
- console.log(` ${ui_1.c.bold('Max folder depth')} ${ui_1.c.dim('(optional)')}`);
133
- console.log(` ${ui_1.c.dim('Counts version. Empty = no limit beyond param fold.')}`);
134
- console.log(` ${ui_1.c.dim('e.g. 3 → v1 / admin / baskets')}`);
135
- const hint = current == null ? 'none' : String(current);
136
- const answer = await prompt(` ${ui_1.c.yellow('?')} Depth ${ui_1.c.dim(`[${hint}]`)}\n ${ui_1.c.cyan('›')} `);
137
- if (!answer)
138
- return current ?? null;
139
- if (/^(none|null|n)$/i.test(answer))
140
- return null;
141
- const n = Number(answer);
142
- if (!Number.isFinite(n) || n < 1)
143
- throw new Error(`Invalid depth: ${answer}`);
144
- return Math.floor(n);
145
- }
146
128
  async function pickExampleStyle(current) {
147
129
  console.log('');
148
130
  console.log(` ${ui_1.c.bold('Example / scenario labels')}`);
@@ -164,9 +146,9 @@ async function pickExampleStyle(current) {
164
146
  return 'full';
165
147
  throw new Error(`Unknown style: ${answer}`);
166
148
  }
167
- function layoutChoicesFor(pathTemplate, layout, skipParams, maxDepth) {
168
- const role = layoutSegments(pathTemplate, 'role-resource', skipParams, maxDepth);
169
- const resource = layoutSegments(pathTemplate, 'resource-role', skipParams, maxDepth);
149
+ function layoutChoicesFor(pathTemplate, layout, skipParams) {
150
+ const role = layoutSegments(pathTemplate, 'role-resource', skipParams);
151
+ const resource = layoutSegments(pathTemplate, 'resource-role', skipParams);
170
152
  const choices = [
171
153
  { id: 'role', label: 'role → resource', segments: role },
172
154
  { id: 'resource', label: 'resource → role', segments: resource },
@@ -174,8 +156,8 @@ function layoutChoicesFor(pathTemplate, layout, skipParams, maxDepth) {
174
156
  ];
175
157
  return choices;
176
158
  }
177
- async function pickSegments(pathTemplate, layout, skipParams, maxDepth) {
178
- const choices = layoutChoicesFor(pathTemplate, layout, skipParams, maxDepth);
159
+ async function pickSegments(pathTemplate, layout, skipParams) {
160
+ const choices = layoutChoicesFor(pathTemplate, layout, skipParams);
179
161
  console.log('');
180
162
  console.log(` ${ui_1.c.bold('Override')} ${ui_1.c.cyan(pathTemplate)}`);
181
163
  choices.forEach((choice, index) => {
@@ -226,9 +208,6 @@ async function runTreeWizard(options = {}) {
226
208
  const skipParams = await pickSkipParams(config.treeSkipParams !== false);
227
209
  (0, config_edit_1.upsertConfigValue)(configPath, 'treeSkipParams', skipParams ? 'true' : 'false');
228
210
  console.log(` ${ui_1.c.green('✔')} treeSkipParams → ${ui_1.c.cyan(String(skipParams))}`);
229
- const maxDepth = await pickMaxDepth(config.treeMaxDepth ?? null);
230
- (0, config_edit_1.upsertConfigValue)(configPath, 'treeMaxDepth', maxDepth == null ? 'null' : String(maxDepth));
231
- console.log(` ${ui_1.c.green('✔')} treeMaxDepth → ${ui_1.c.cyan(maxDepth == null ? 'null' : String(maxDepth))}`);
232
211
  const exampleStyle = await pickExampleStyle(config.exampleLabelStyle ?? 'status-title-case');
233
212
  (0, config_edit_1.upsertConfigValue)(configPath, 'exampleLabelStyle', (0, config_edit_1.formatTsString)(exampleStyle));
234
213
  console.log(` ${ui_1.c.green('✔')} exampleLabelStyle → ${ui_1.c.cyan(exampleStyle)}`);
@@ -239,7 +218,7 @@ async function runTreeWizard(options = {}) {
239
218
  if (customize && !/^n(o)?$/i.test(customize)) {
240
219
  const pathTemplate = await pickPath(options.path);
241
220
  if (pathTemplate) {
242
- const segments = await pickSegments(pathTemplate, layout, skipParams, maxDepth);
221
+ const segments = await pickSegments(pathTemplate, layout, skipParams);
243
222
  if (segments?.length) {
244
223
  const overrides = (0, config_edit_1.readTreePathOverrides)();
245
224
  overrides[pathTemplate] = segments;
package/dist/config.d.ts CHANGED
@@ -24,12 +24,6 @@ export type DaxtaConfig = {
24
24
  * Ops like POST …/{id}/lock sit under the parent resource. Default true.
25
25
  */
26
26
  treeSkipParams?: boolean;
27
- /**
28
- * Max folder segments after (and including) version.
29
- * e.g. 3 → v1 / admin / baskets — deeper segments are not folders.
30
- * null/undefined = no extra limit (treeSkipParams still applies).
31
- */
32
- treeMaxDepth?: number | null;
33
27
  treePathOverrides?: Record<string, string[]>;
34
28
  /**
35
29
  * OpenAPI example + scenario labels:
package/dist/config.js CHANGED
@@ -48,7 +48,6 @@ const DEFAULTS = {
48
48
  outDir: 'daxta/out',
49
49
  treeLayout: 'role-resource',
50
50
  treeSkipParams: true,
51
- treeMaxDepth: null,
52
51
  treePathOverrides: {},
53
52
  exampleLabelStyle: 'status-title-case',
54
53
  port: 5199,
@@ -1,7 +1,13 @@
1
1
  export declare function stripViewerExtensions(value: unknown): unknown;
2
2
  /**
3
- * Export OpenAPI with real URL paths (correct for clients) and tags/folders
4
- * matching the docs sidebar (`x-tree-segments`).
3
+ * Build export path keys from sidebar tree segments (same order as docs),
4
+ * appending any `{param}` tail from the real URL so templates stay complete.
5
+ * Real URL is preserved on `x-daxta-url-path` when it differs.
6
+ */
7
+ export declare function exportPathFromTree(urlPath: string, treeSegments: string[]): string;
8
+ /**
9
+ * Export OpenAPI with path keys ordered like the docs sidebar (`x-tree-segments`).
10
+ * Real request URLs stay on `x-daxta-url-path` when remapped.
5
11
  */
6
12
  export declare function toTreeOrderedOpenApi(raw: Record<string, unknown>): Record<string, unknown>;
7
13
  export declare function readStrippedOpenApiJson(): string | null;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.stripViewerExtensions = stripViewerExtensions;
4
+ exports.exportPathFromTree = exportPathFromTree;
4
5
  exports.toTreeOrderedOpenApi = toTreeOrderedOpenApi;
5
6
  exports.readStrippedOpenApiJson = readStrippedOpenApiJson;
6
7
  const fs_1 = require("fs");
@@ -28,8 +29,25 @@ function treeSegmentsForOperation(urlPath, operation) {
28
29
  return urlPath.split('/').filter(Boolean);
29
30
  }
30
31
  /**
31
- * Export OpenAPI with real URL paths (correct for clients) and tags/folders
32
- * matching the docs sidebar (`x-tree-segments`).
32
+ * Build export path keys from sidebar tree segments (same order as docs),
33
+ * appending any `{param}` tail from the real URL so templates stay complete.
34
+ * Real URL is preserved on `x-daxta-url-path` when it differs.
35
+ */
36
+ function exportPathFromTree(urlPath, treeSegments) {
37
+ const originalParts = urlPath.split('/').filter(Boolean);
38
+ const paramIdx = originalParts.findIndex((part) => part.startsWith('{'));
39
+ const tail = paramIdx >= 0 ? originalParts.slice(paramIdx) : [];
40
+ const treeHasParam = treeSegments.some((part) => part.startsWith('{'));
41
+ const parts = treeSegments.length === 0
42
+ ? originalParts
43
+ : treeHasParam || paramIdx < 0
44
+ ? treeSegments
45
+ : [...treeSegments, ...tail];
46
+ return `/${parts.join('/')}`;
47
+ }
48
+ /**
49
+ * Export OpenAPI with path keys ordered like the docs sidebar (`x-tree-segments`).
50
+ * Real request URLs stay on `x-daxta-url-path` when remapped.
33
51
  */
34
52
  function toTreeOrderedOpenApi(raw) {
35
53
  const sourcePaths = (raw.paths ?? {});
@@ -38,11 +56,22 @@ function toTreeOrderedOpenApi(raw) {
38
56
  for (const [urlPath, pathItem] of Object.entries(sourcePaths)) {
39
57
  if (!pathItem || typeof pathItem !== 'object')
40
58
  continue;
41
- const exportPathItem = {};
59
+ let treeSegments = null;
60
+ for (const [key, value] of Object.entries(pathItem)) {
61
+ if (!HTTP_METHODS.has(key) || !value || typeof value !== 'object')
62
+ continue;
63
+ treeSegments = treeSegmentsForOperation(urlPath, value);
64
+ break;
65
+ }
66
+ if (!treeSegments)
67
+ treeSegments = urlPath.split('/').filter(Boolean);
68
+ const exportPath = exportPathFromTree(urlPath, treeSegments);
69
+ const exportPathItem = { ...(exportPaths[exportPath] ?? {}) };
42
70
  for (const [key, value] of Object.entries(pathItem)) {
43
71
  if (!HTTP_METHODS.has(key) || !value || typeof value !== 'object') {
44
- if (!HTTP_METHODS.has(key))
72
+ if (!HTTP_METHODS.has(key) && exportPathItem[key] === undefined) {
45
73
  exportPathItem[key] = stripViewerExtensions(value);
74
+ }
46
75
  continue;
47
76
  }
48
77
  const operation = value;
@@ -52,9 +81,12 @@ function toTreeOrderedOpenApi(raw) {
52
81
  const tag = tagParts.length ? tagParts.join(' / ') : 'API';
53
82
  cleaned.tags = [tag];
54
83
  tagNames.add(tag);
84
+ if (exportPath !== urlPath) {
85
+ cleaned['x-daxta-url-path'] = urlPath;
86
+ }
55
87
  exportPathItem[key] = cleaned;
56
88
  }
57
- exportPaths[urlPath] = exportPathItem;
89
+ exportPaths[exportPath] = exportPathItem;
58
90
  }
59
91
  const orderedPaths = {};
60
92
  for (const key of Object.keys(exportPaths).sort((a, b) => a.localeCompare(b))) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t0.labs/daxta",
3
- "version": "0.4.6",
3
+ "version": "0.4.7",
4
4
  "description": "DAxTA \u2014 docs from Nest integration traffic + DTO field CLI / Try-it",
5
5
  "license": "MIT",
6
6
  "repository": {