@t0.labs/daxta 0.4.20 → 0.4.22

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.
@@ -171,6 +171,42 @@ function exampleKeyForHit(hit, index) {
171
171
  const base = slug(label, index);
172
172
  return base ? `${base}-${index}` : `example-${index + 1}`;
173
173
  }
174
+ function isSuccessStatus(status) {
175
+ return status >= 200 && status < 300;
176
+ }
177
+ /**
178
+ * Seed calls in the same it() share Jest's currentTestName.
179
+ * SEMANTIC: create-then-assert-409 must not surface the setup 201.
180
+ */
181
+ function selectHitsForDocs(hits) {
182
+ const byTest = new Map();
183
+ const unlabeled = [];
184
+ for (const hit of hits) {
185
+ if (!hit.test) {
186
+ unlabeled.push(hit);
187
+ continue;
188
+ }
189
+ const list = byTest.get(hit.test) ?? [];
190
+ list.push(hit);
191
+ byTest.set(hit.test, list);
192
+ }
193
+ const selected = [...unlabeled];
194
+ for (const group of byTest.values()) {
195
+ const section = (0, catalog_1.parseCaseSection)(group[0]?.test);
196
+ if (section === 'semantic' || section === 'invalid' || section === 'omitted' || section === 'auth') {
197
+ const errors = group.filter((hit) => !isSuccessStatus(hit.status));
198
+ selected.push(...(errors.length ? errors : group));
199
+ continue;
200
+ }
201
+ if (section === 'positive') {
202
+ const ok = group.filter((hit) => isSuccessStatus(hit.status));
203
+ selected.push(...(ok.length ? ok : group));
204
+ continue;
205
+ }
206
+ selected.push(...group);
207
+ }
208
+ return selected;
209
+ }
174
210
  function isPrimaryHit(hit) {
175
211
  if (!hit.test)
176
212
  return false;
@@ -349,13 +385,7 @@ function securityForHits(opHits) {
349
385
  return [requirement];
350
386
  }
351
387
  function scenarioDisplayName(hit) {
352
- const cas = (0, catalog_1.caseName)(hit.test);
353
- const title = (0, catalog_1.apiTitle)(hit.test);
354
- const style = (0, config_1.getConfig)().exampleLabelStyle ?? 'status-title-case';
355
- if ((style === 'status-title-case' || style === 'full') && title) {
356
- return `${title} — ${cas}`;
357
- }
358
- return cas;
388
+ return (0, catalog_1.docsScenarioClause)((0, catalog_1.caseName)(hit.test));
359
389
  }
360
390
  function toScenario(hit) {
361
391
  return {
@@ -371,7 +401,7 @@ function toScenario(hit) {
371
401
  }
372
402
  function sortScenarios(scenarios) {
373
403
  const groupRank = (group) => {
374
- const order = ['Success', 'Business errors', 'Invalid input', 'Missing fields', 'Auth', 'Other'];
404
+ const order = [...catalog_1.CASE_GROUP_ORDER];
375
405
  const index = order.indexOf(group);
376
406
  return index === -1 ? order.length : index;
377
407
  };
@@ -466,7 +496,7 @@ function sortOperations(entries) {
466
496
  }
467
497
  function buildSpec(hits) {
468
498
  const grouped = new Map();
469
- for (const hit of hits.filter(isPrimaryHit)) {
499
+ for (const hit of selectHitsForDocs(hits.filter(isPrimaryHit))) {
470
500
  const key = `${hit.method} ${hit.path}`;
471
501
  const opHits = grouped.get(key) ?? [];
472
502
  opHits.push(hit);
@@ -1,6 +1,6 @@
1
1
  import { type TreeLayout } from '../config';
2
2
  export { parseOperationLabel, suggestOperationTitles, suggestOperationTitleResult, formatTestTitle } from './test-title';
3
- export { isValidItCase, suggestItCases, parseCaseSection, type CaseSection } from './it-case';
3
+ export { isValidItCase, suggestItCases, docsScenarioClause, parseCaseSection, type CaseSection } from './it-case';
4
4
  export type { TreeLayout };
5
5
  export type FieldDoc = {
6
6
  name: string;
@@ -32,6 +32,7 @@ export declare function viewerTreeConfig(): {
32
32
  };
33
33
  export declare function operationTag(pathTemplate: string, method: string): string;
34
34
  export declare function defaultTitle(method: string, pathTemplate: string): string;
35
+ export declare const CASE_GROUP_ORDER: string[];
35
36
  export declare function caseGroup(test?: string): string;
36
37
  export declare function caseSectionLabel(test?: string): string;
37
38
  /**
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.STATUS_TEXT = exports.parseCaseSection = exports.suggestItCases = exports.isValidItCase = exports.formatTestTitle = exports.suggestOperationTitleResult = exports.suggestOperationTitles = exports.parseOperationLabel = void 0;
3
+ exports.CASE_GROUP_ORDER = exports.STATUS_TEXT = exports.parseCaseSection = exports.docsScenarioClause = exports.suggestItCases = exports.isValidItCase = exports.formatTestTitle = exports.suggestOperationTitleResult = exports.suggestOperationTitles = exports.parseOperationLabel = void 0;
4
4
  exports.declaredMethods = declaredMethods;
5
5
  exports.pathSegments = pathSegments;
6
6
  exports.treePathSegments = treePathSegments;
@@ -15,15 +15,17 @@ exports.exampleLabel = exampleLabel;
15
15
  exports.operationSummary = operationSummary;
16
16
  const config_1 = require("../config");
17
17
  const test_title_1 = require("./test-title");
18
+ const it_case_1 = require("./it-case");
18
19
  var test_title_2 = require("./test-title");
19
20
  Object.defineProperty(exports, "parseOperationLabel", { enumerable: true, get: function () { return test_title_2.parseOperationLabel; } });
20
21
  Object.defineProperty(exports, "suggestOperationTitles", { enumerable: true, get: function () { return test_title_2.suggestOperationTitles; } });
21
22
  Object.defineProperty(exports, "suggestOperationTitleResult", { enumerable: true, get: function () { return test_title_2.suggestOperationTitleResult; } });
22
23
  Object.defineProperty(exports, "formatTestTitle", { enumerable: true, get: function () { return test_title_2.formatTestTitle; } });
23
- var it_case_1 = require("./it-case");
24
- Object.defineProperty(exports, "isValidItCase", { enumerable: true, get: function () { return it_case_1.isValidItCase; } });
25
- Object.defineProperty(exports, "suggestItCases", { enumerable: true, get: function () { return it_case_1.suggestItCases; } });
26
- Object.defineProperty(exports, "parseCaseSection", { enumerable: true, get: function () { return it_case_1.parseCaseSection; } });
24
+ var it_case_2 = require("./it-case");
25
+ Object.defineProperty(exports, "isValidItCase", { enumerable: true, get: function () { return it_case_2.isValidItCase; } });
26
+ Object.defineProperty(exports, "suggestItCases", { enumerable: true, get: function () { return it_case_2.suggestItCases; } });
27
+ Object.defineProperty(exports, "docsScenarioClause", { enumerable: true, get: function () { return it_case_2.docsScenarioClause; } });
28
+ Object.defineProperty(exports, "parseCaseSection", { enumerable: true, get: function () { return it_case_2.parseCaseSection; } });
27
29
  exports.STATUS_TEXT = {
28
30
  '200': 'OK',
29
31
  '201': 'Created',
@@ -128,19 +130,27 @@ function defaultTitle(method, pathTemplate) {
128
130
  return custom;
129
131
  return pathTemplate;
130
132
  }
133
+ exports.CASE_GROUP_ORDER = [
134
+ 'POSITIVE CASES',
135
+ 'SEMANTIC ERROR CASES',
136
+ 'INVALID CASES',
137
+ 'OMITTED CASES',
138
+ 'SEMANTIC ERROR CASES - AUTH',
139
+ 'Other',
140
+ ];
131
141
  function caseGroup(test) {
132
142
  if (!test)
133
143
  return 'Other';
134
144
  if (/SEMANTIC ERROR CASES\s*-\s*AUTH/i.test(test))
135
- return 'Auth';
145
+ return 'SEMANTIC ERROR CASES - AUTH';
136
146
  if (/POSITIVE CASES/i.test(test))
137
- return 'Success';
147
+ return 'POSITIVE CASES';
138
148
  if (/SEMANTIC ERROR CASES/i.test(test))
139
- return 'Business errors';
149
+ return 'SEMANTIC ERROR CASES';
140
150
  if (/INVALID CASES/i.test(test))
141
- return 'Invalid input';
151
+ return 'INVALID CASES';
142
152
  if (/OMITTED/i.test(test))
143
- return 'Missing fields';
153
+ return 'OMITTED CASES';
144
154
  return 'Other';
145
155
  }
146
156
  function caseSectionLabel(test) {
@@ -196,7 +206,7 @@ function caseName(test) {
196
206
  /** OpenAPI example summary / scenario display name. */
197
207
  function exampleLabel(hit) {
198
208
  const style = (0, config_1.getConfig)().exampleLabelStyle ?? 'status-title-case';
199
- const cas = caseName(hit.test);
209
+ const cas = (0, it_case_1.docsScenarioClause)(caseName(hit.test));
200
210
  const title = apiTitle(hit.test);
201
211
  const method = (hit.method || 'get').toUpperCase();
202
212
  const section = caseSectionLabel(hit.test);
@@ -8,6 +8,11 @@ export declare function isValidItCase(name?: string): boolean;
8
8
  * Never collapse many cases into one generic sentence.
9
9
  */
10
10
  export declare function rewriteItFromOriginal(raw: string, section?: CaseSection, method?: string, pathTemplate?: string): string | undefined;
11
+ /**
12
+ * Docs / Postman example line: the unique condition only.
13
+ * Test keeps `creates mock tbs when cyprus payload shape` → docs `cyprus payload shape`.
14
+ */
15
+ export declare function docsScenarioClause(raw?: string): string;
11
16
  export type ItSuggestion = {
12
17
  names: string[];
13
18
  /** Safe for --yes / `a` — rewritten from this case's own text. */
@@ -5,6 +5,7 @@ exports.isDynamicItName = isDynamicItName;
5
5
  exports.isGenericItName = isGenericItName;
6
6
  exports.isValidItCase = isValidItCase;
7
7
  exports.rewriteItFromOriginal = rewriteItFromOriginal;
8
+ exports.docsScenarioClause = docsScenarioClause;
8
9
  exports.suggestItCases = suggestItCases;
9
10
  exports.suggestItCaseResult = suggestItCaseResult;
10
11
  const test_title_1 = require("./test-title");
@@ -17,6 +18,10 @@ const GENERIC_IT = new Set([
17
18
  'rejects when payload is invalid',
18
19
  'rejects when a required field is omitted',
19
20
  'rejects when unauthorized',
21
+ 'returns error when resource already exists',
22
+ 'returns error when payload is invalid',
23
+ 'returns error when a required field is omitted',
24
+ 'returns error when unauthorized',
20
25
  ]);
21
26
  function parseCaseSection(raw) {
22
27
  if (!raw)
@@ -42,9 +47,11 @@ function isGenericItName(name) {
42
47
  return true;
43
48
  if (/^rejects when (resource|payload) (already exists|is invalid)$/i.test(value))
44
49
  return true;
50
+ if (/^returns error when (resource|payload) (already exists|is invalid)$/i.test(value))
51
+ return true;
45
52
  if (/^returns [\w\s]+ list when query is valid$/i.test(value))
46
53
  return true;
47
- if (/^creates [\w\s]+ when payload is valid$/i.test(value))
54
+ if (/^returns resource\b/i.test(value))
48
55
  return true;
49
56
  return false;
50
57
  }
@@ -89,8 +96,9 @@ function stemVerb(raw) {
89
96
  return `${v}s`;
90
97
  }
91
98
  function outcomeVerb(section, method) {
92
- if (section === 'auth' || section === 'invalid' || section === 'omitted' || section === 'semantic')
93
- return 'rejects';
99
+ if (section === 'auth' || section === 'invalid' || section === 'omitted' || section === 'semantic') {
100
+ return 'returns error';
101
+ }
94
102
  const m = (method || 'get').toLowerCase();
95
103
  if (m === 'post')
96
104
  return 'creates';
@@ -131,11 +139,12 @@ function rewriteItFromOriginal(raw, section, method, pathTemplate) {
131
139
  const res = pathTemplate ? (0, test_title_1.resourceLabel)(pathTemplate).toLowerCase() : 'resource';
132
140
  const outcome = outcomeVerb(section, method);
133
141
  s = s
134
- .replace(/^returns?\s+unauthorized\s+/i, 'rejects ')
135
- .replace(/^returns?\s+conflict\s+/i, 'rejects ')
136
- .replace(/^returns?\s+error\s+/i, 'rejects ')
137
- .replace(/^returns?\s+bad request\s+/i, 'rejects ')
138
- .replace(/^returns?\s+not found\s+/i, 'rejects ');
142
+ .replace(/^rejects\s+/i, 'returns error ')
143
+ .replace(/^returns?\s+unauthorized\s+/i, 'returns error ')
144
+ .replace(/^returns?\s+conflict\s+/i, 'returns error ')
145
+ .replace(/^returns?\s+error\s+/i, 'returns error ')
146
+ .replace(/^returns?\s+bad request\s+/i, 'returns error ')
147
+ .replace(/^returns?\s+not found\s+/i, 'returns error ');
139
148
  if (/^not\s+/i.test(s)) {
140
149
  const beforeWhen = s.replace(/^not\s+/i, '').split(/\bwhen\b/i)[0].trim();
141
150
  return fitItName(`${outcome} ${res} when not ${beforeWhen}`);
@@ -163,6 +172,24 @@ function rewriteItFromOriginal(raw, section, method, pathTemplate) {
163
172
  }
164
173
  return fitItName(`${outcome} when ${s}`);
165
174
  }
175
+ const OUTCOME_PREFIX = /^(returns|creates|updates|upserts|inserts|merges|replaces|deletes|lists|rejects|conflicts)\s+/i;
176
+ /**
177
+ * Docs / Postman example line: the unique condition only.
178
+ * Test keeps `creates mock tbs when cyprus payload shape` → docs `cyprus payload shape`.
179
+ */
180
+ function docsScenarioClause(raw) {
181
+ if (!raw)
182
+ return 'example';
183
+ let s = raw.trim().replace(/\s+/g, ' ');
184
+ const field = s.match(/^([A-Za-z0-9_.]+)\s+-\s+(should not be\s+.+)$/i);
185
+ if (field)
186
+ return `${field[1]} ${field[2]}`.trim();
187
+ const when = s.match(/\bwhen\s+(.+)$/i);
188
+ if (when?.[1])
189
+ return when[1].trim();
190
+ s = s.replace(OUTCOME_PREFIX, '').replace(/^resource\s+/i, '').trim();
191
+ return s || 'example';
192
+ }
166
193
  /**
167
194
  * Prefer a unique rewrite of the current it() name.
168
195
  * Generic section templates are never auto-applied.
@@ -130,7 +130,9 @@ async function runTitleCheck(options) {
130
130
  }
131
131
  (0, ui_1.banner)('Test naming', 'runs before Jest — docs / Postman labels');
132
132
  console.log(` ${ui_1.c.dim('Title')} Create Mock Tbs — POST /v1/admin/mock-tbs`);
133
- console.log(` ${ui_1.c.dim('it()')} unique per case — from should …, not one shared template`);
133
+ console.log(` ${ui_1.c.dim('it()+')} creates mock tbs when cyprus payload shape`);
134
+ console.log(` ${ui_1.c.dim('it()-')} returns error when tax id already exists`);
135
+ console.log(` ${ui_1.c.dim('docs')} 201 — cyprus payload shape`);
134
136
  console.log(` ${ui_1.c.gold(String(total))} to review — ${ui_1.c.ice('y')} one recommended, ${ui_1.c.ice('a')} all remaining, ${ui_1.c.ice('s')} skip.`);
135
137
  let written = 0;
136
138
  let skipped = 0;
package/dist/cli/tree.js CHANGED
@@ -119,11 +119,11 @@ async function pickExampleStyle(current) {
119
119
  console.log('');
120
120
  console.log(` ${ui_1.c.bold('Example / scenario labels')}`);
121
121
  console.log(` ${ui_1.c.ice('1')} status-title-case`);
122
- console.log(` ${ui_1.c.dim('200 — Admin Find One Basket By Id API — returns basket when found')}`);
122
+ console.log(` ${ui_1.c.dim('201 — cyprus payload shape')}`);
123
123
  console.log(` ${ui_1.c.ice('2')} status-case`);
124
- console.log(` ${ui_1.c.dim('200 — returns basket when found')}`);
124
+ console.log(` ${ui_1.c.dim('201 — cyprus payload shape')}`);
125
125
  console.log(` ${ui_1.c.ice('3')} full`);
126
- console.log(` ${ui_1.c.dim('200 — Admin Find… API - GET /v1/admin/baskets/{id} POSITIVE CASES returns…')}`);
126
+ console.log(` ${ui_1.c.dim('201 — Create Mock Tbs - POST /v1/admin/mock-tbs POSITIVE CASES cyprus payload shape')}`);
127
127
  console.log(` ${ui_1.c.ice('4')} keep ${ui_1.c.dim(`(${current})`)}`);
128
128
  const answer = await (0, ui_1.readlineAsk)(` ${ui_1.c.gold('?')} Choose\n ${ui_1.c.ice('›')} `);
129
129
  if (!answer || answer === '4' || /^k(eep)?$/i.test(answer))
package/dist/config.d.ts CHANGED
@@ -39,9 +39,10 @@ export type DaxtaConfig = {
39
39
  treePathOverrides?: Record<string, string[]>;
40
40
  /**
41
41
  * OpenAPI example + scenario labels:
42
- * - status-case → `200 — returns basket when found`
43
- * - status-title-case → `200 — Admin Find One Basket By Id API — returns…`
44
- * - full → `200 — Admin Find… API - GET /v1/admin/baskets/{id} POSITIVE CASES returns…`
42
+ * - status-case → `201 — cyprus payload shape`
43
+ * - status-title-case → `201 — Create Mock Tbs — cyprus payload shape`
44
+ * - full → includes path + POSITIVE CASES + clause
45
+ * Test it() stays `creates mock tbs when cyprus payload shape`; docs take the `when` clause.
45
46
  */
46
47
  exampleLabelStyle?: ExampleLabelStyle;
47
48
  port?: number;
package/dist/index.d.ts CHANGED
@@ -6,5 +6,5 @@ export { dtoRequired, type FieldLocation } from './fields/dto-fields';
6
6
  export { buildFieldsFile, writeFieldsFile, readFieldsFile, type FieldsFile } from './fields/export-fields';
7
7
  export { apiDocs, apiDocsHandler, serveApiDocs, getDocsBasePath, getHtmlPath, getOutDir, getSpecJsonPath, type ApiDocsHandler, type ApiDocsOptions, } from './serve';
8
8
  export { runInteractiveCall, runFileCall, executeCall, type CallValues } from './call';
9
- export { apiTitle, parseOperationLabel, suggestOperationTitles, suggestOperationTitleResult, formatTestTitle, isValidItCase, suggestItCases, type FieldDoc, type OperationDoc, } from './catalog';
9
+ export { apiTitle, parseOperationLabel, suggestOperationTitles, suggestOperationTitleResult, formatTestTitle, isValidItCase, suggestItCases, docsScenarioClause, type FieldDoc, type OperationDoc, } from './catalog';
10
10
  export { installDaxta, type InstallOptions } from './cli/install';
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.installDaxta = exports.suggestItCases = exports.isValidItCase = exports.formatTestTitle = exports.suggestOperationTitleResult = exports.suggestOperationTitles = exports.parseOperationLabel = exports.apiTitle = exports.executeCall = exports.runFileCall = exports.runInteractiveCall = exports.getSpecJsonPath = exports.getOutDir = exports.getHtmlPath = exports.getDocsBasePath = exports.serveApiDocs = exports.apiDocsHandler = exports.apiDocs = exports.readFieldsFile = exports.writeFieldsFile = exports.buildFieldsFile = exports.dtoRequired = exports.getHits = exports.clearWorkerHits = exports.flush = exports.install = exports.touchPartialMarker = exports.clearPartialMarker = exports.flushAndRebuild = exports.rebuildFromDisk = exports.loadHits = exports.buildOpenApi = exports.buildDaxtaSpec = exports.normalizeTreeLayout = exports.resolveConfig = exports.getConfig = exports.defineConfig = void 0;
3
+ exports.installDaxta = exports.docsScenarioClause = exports.suggestItCases = exports.isValidItCase = exports.formatTestTitle = exports.suggestOperationTitleResult = exports.suggestOperationTitles = exports.parseOperationLabel = exports.apiTitle = exports.executeCall = exports.runFileCall = exports.runInteractiveCall = exports.getSpecJsonPath = exports.getOutDir = exports.getHtmlPath = exports.getDocsBasePath = exports.serveApiDocs = exports.apiDocsHandler = exports.apiDocs = exports.readFieldsFile = exports.writeFieldsFile = exports.buildFieldsFile = exports.dtoRequired = exports.getHits = exports.clearWorkerHits = exports.flush = exports.install = exports.touchPartialMarker = exports.clearPartialMarker = exports.flushAndRebuild = exports.rebuildFromDisk = exports.loadHits = exports.buildOpenApi = exports.buildDaxtaSpec = exports.normalizeTreeLayout = exports.resolveConfig = exports.getConfig = exports.defineConfig = void 0;
4
4
  var config_1 = require("./config");
5
5
  Object.defineProperty(exports, "defineConfig", { enumerable: true, get: function () { return config_1.defineConfig; } });
6
6
  Object.defineProperty(exports, "getConfig", { enumerable: true, get: function () { return config_1.getConfig; } });
@@ -46,5 +46,6 @@ Object.defineProperty(exports, "suggestOperationTitleResult", { enumerable: true
46
46
  Object.defineProperty(exports, "formatTestTitle", { enumerable: true, get: function () { return catalog_1.formatTestTitle; } });
47
47
  Object.defineProperty(exports, "isValidItCase", { enumerable: true, get: function () { return catalog_1.isValidItCase; } });
48
48
  Object.defineProperty(exports, "suggestItCases", { enumerable: true, get: function () { return catalog_1.suggestItCases; } });
49
+ Object.defineProperty(exports, "docsScenarioClause", { enumerable: true, get: function () { return catalog_1.docsScenarioClause; } });
49
50
  var install_1 = require("./cli/install");
50
51
  Object.defineProperty(exports, "installDaxta", { enumerable: true, get: function () { return install_1.installDaxta; } });
@@ -283,8 +283,8 @@ function printNamingFindings(report, paint) {
283
283
  // spacer already from titles
284
284
  }
285
285
  console.log('');
286
- console.log(` ${paint.yellow('!')} ${paint.bold(`${report.cases.length} it() case(s) can keep unique wording`)} ${paint.dim('should … → outcome when …')}`);
287
- console.log(` ${paint.dim('Never collapse')} ${paint.cyan('nace codes / TRNC / not-found')} ${paint.dim('into one shared line')}`);
286
+ console.log(` ${paint.yellow('!')} ${paint.bold(`${report.cases.length} it() case(s) to rewrite`)} ${paint.dim('keep unique when-clause')}`);
287
+ console.log(` ${paint.dim('Positive')} ${paint.cyan('creates … when …')} ${paint.dim('errors')} ${paint.cyan('returns error when …')} ${paint.dim('docs = after when')}`);
288
288
  for (const item of report.cases) {
289
289
  console.log('');
290
290
  console.log(` ${paint.cyan(item.file)}${paint.dim(`:${item.line}:${item.column}`)}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t0.labs/daxta",
3
- "version": "0.4.20",
3
+ "version": "0.4.22",
4
4
  "description": "DAxTA \u2014 docs from Nest integration traffic + DTO field CLI / Try-it",
5
5
  "license": "MIT",
6
6
  "repository": {