@t0.labs/daxta 0.4.17 → 0.4.19

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
@@ -168,20 +168,33 @@ Then `daxta build` to refresh `/docs` and export.
168
168
 
169
169
  ## Test titles (docs / Postman names)
170
170
 
171
- Docs and the collection use a **human title**, not the raw path. Put it in `TEST_TITLE` (or the describe string):
171
+ Readable `TEST_TITLE` (path stays after the em dash so DAxTA can still bind the route):
172
172
 
173
173
  ```ts
174
- static TEST_TITLE = () => `Create Mock Tbs /v1/admin/mock-tbs [POST] (integration)`;
174
+ static TEST_TITLE = () => `Create Mock Tbs — POST /v1/admin/mock-tbs`;
175
175
  describe(`${TEST_TITLE()} POSITIVE CASES`, () => { /* … */ });
176
176
  ```
177
177
 
178
- Format: `{Title} {path} [{METHOD}] (integration)`
178
+ Format: `{Title} — {METHOD} {path}`
179
179
 
180
- - Verb comes from the method (`GET` collection → Find All, `GET …/{id}` → Find One, `POST` → Create, …) plus kebab resource (`mock-tbs` → Mock Tbs). Action segments (`validate`, `approve`, …) become the verb.
181
- - Skip the title and docs fall back to the path.
182
- - `it()` example names: `{outcome} when {condition}` — e.g. `creates mock tbs when payload is valid`. No path, no `[POST]`, no status (status comes from the recorded hit).
183
- - `daxta titles` lists file:line for both rules; pick a suggestion, type custom, or skip.
184
- - **Before tests:** `daxta install` and `daxta test` ask in the terminal (TTY). `pnpm test:integration` also asks via Jest `globalSetup` when stdin is a TTY. CI only prints. `--yes` / `CI=1` skip the questions.
180
+ Suggested titles (method + path, never `:id` as a name):
181
+
182
+ | Call | Title |
183
+ | --- | --- |
184
+ | `GET /…/mock-tbs` | Find All Mock Tbs |
185
+ | `GET /…/mock-tbs/:id` | Find One Mock Tbs By Id |
186
+ | `POST /…/mock-tbs` | Create Mock Tbs |
187
+ | `PATCH /…/mock-tbs/:id` | Update Mock Tbs By Id |
188
+ | `POST /…/products/bulk` | Create Bulk Products |
189
+ | `POST /…/validator/tax-id/validate` | Validate Tax Id |
190
+
191
+ `--yes` / `a` only rewrite **known** patterns (CRUD + bulk + validate/approve/…). Unknown routes are **not skipped**: they stay listed until you type a custom title (`c`).
192
+
193
+ Old `{path} [METHOD] (integration)` still parses. `daxta titles --yes` rewrites to the new form.
194
+
195
+ - `it()`: `{outcome} when {condition}` — e.g. `creates mock tbs when payload is valid`
196
+ - `daxta titles` / `--yes` / `y` / `a` as before
197
+ - **Before tests:** install, `daxta test`, and Jest `globalSetup` (TTY). `--yes` / `CI=1` skip questions.
185
198
 
186
199
  ```bash
187
200
  daxta titles # interactive (y = this recommended, a = all remaining)
@@ -1,5 +1,5 @@
1
1
  import { type TreeLayout } from '../config';
2
- export { parseOperationLabel, suggestOperationTitles, formatTestTitle } from './test-title';
2
+ export { parseOperationLabel, suggestOperationTitles, suggestOperationTitleResult, formatTestTitle } from './test-title';
3
3
  export { isValidItCase, suggestItCases, parseCaseSection, type CaseSection } from './it-case';
4
4
  export type { TreeLayout };
5
5
  export type FieldDoc = {
@@ -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.suggestOperationTitles = exports.parseOperationLabel = void 0;
3
+ exports.STATUS_TEXT = exports.parseCaseSection = 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;
@@ -18,6 +18,7 @@ const test_title_1 = require("./test-title");
18
18
  var test_title_2 = require("./test-title");
19
19
  Object.defineProperty(exports, "parseOperationLabel", { enumerable: true, get: function () { return test_title_2.parseOperationLabel; } });
20
20
  Object.defineProperty(exports, "suggestOperationTitles", { enumerable: true, get: function () { return test_title_2.suggestOperationTitles; } });
21
+ Object.defineProperty(exports, "suggestOperationTitleResult", { enumerable: true, get: function () { return test_title_2.suggestOperationTitleResult; } });
21
22
  Object.defineProperty(exports, "formatTestTitle", { enumerable: true, get: function () { return test_title_2.formatTestTitle; } });
22
23
  var it_case_1 = require("./it-case");
23
24
  Object.defineProperty(exports, "isValidItCase", { enumerable: true, get: function () { return it_case_1.isValidItCase; } });
@@ -43,6 +44,11 @@ const CASE_SECTION_RE = /^(POSITIVE CASES|SEMANTIC ERROR CASES(?:\s*-\s*AUTH)?|I
43
44
  function declaredMethods(test) {
44
45
  if (!test)
45
46
  return null;
47
+ const fromLabel = (0, test_title_1.parseOperationLabel)(test);
48
+ if (fromLabel?.method) {
49
+ const method = fromLabel.method.toLowerCase();
50
+ return METHOD_ALIASES[method] ?? [method];
51
+ }
46
52
  const declared = test.match(/\[(GET|POST|PUT|PATCH|DELETE|UPDATE|UPSERT)\]/i);
47
53
  if (!declared)
48
54
  return null;
@@ -50,7 +56,7 @@ function declaredMethods(test) {
50
56
  return METHOD_ALIASES[method] ?? [method];
51
57
  }
52
58
  function pathSegments(pathTemplate) {
53
- return pathTemplate.split('/').filter((part) => part && !part.startsWith('{'));
59
+ return pathTemplate.split('/').filter((part) => part && !part.startsWith('{') && !part.startsWith(':'));
54
60
  }
55
61
  function applyLayout(parts, layout) {
56
62
  if (parts.length >= 3 && /^v\d+$/i.test(parts[0]) && layout === 'resource-role') {
@@ -168,6 +174,7 @@ function caseName(test) {
168
174
  if (!test)
169
175
  return 'example';
170
176
  let rest = test
177
+ .replace(/^.+?\s+[—–-]\s+(?:GET|POST|PUT|PATCH|DELETE|UPDATE|UPSERT)\s+\S+\s*/i, '')
171
178
  .replace(/^.*?\[(?:GET|POST|PUT|PATCH|DELETE|UPDATE|UPSERT)\]\s*(?:\(integration\))?\s*/i, '')
172
179
  .replace(CASE_SECTION_RE, '')
173
180
  .trim();
@@ -39,11 +39,7 @@ function isValidItCase(name) {
39
39
  function resourcePhrase(pathTemplate) {
40
40
  if (!pathTemplate)
41
41
  return 'resource';
42
- const named = pathTemplate.split('/').filter((part) => part && !part.startsWith('{') && !/^v\d+$/i.test(part));
43
- const last = named[named.length - 1] || 'resource';
44
- const prev = named[named.length - 2];
45
- const action = /^(validate|approve|reject|sync|search|export|import|lock|unlock)$/i.test(last);
46
- return (0, test_title_1.titleCaseToken)(action && prev ? prev : last).toLowerCase();
42
+ return (0, test_title_1.resourceLabel)(pathTemplate).toLowerCase();
47
43
  }
48
44
  /**
49
45
  * Deterministic it() suggestions: `{outcome} when {condition}`.
@@ -51,7 +47,7 @@ function resourcePhrase(pathTemplate) {
51
47
  function suggestItCases(section, method, pathTemplate) {
52
48
  const res = resourcePhrase(pathTemplate);
53
49
  const m = (method || 'get').toLowerCase();
54
- const hasParam = Boolean(pathTemplate?.split('/').some((part) => part.startsWith('{')));
50
+ const hasParam = Boolean(pathTemplate?.split('/').some((part) => (0, test_title_1.isPathParam)(part)));
55
51
  const out = [];
56
52
  const add = (value) => {
57
53
  const next = value.replace(/\s+/g, ' ').trim();
@@ -4,16 +4,28 @@ export type ParsedOperationLabel = {
4
4
  method: string;
5
5
  integration: boolean;
6
6
  };
7
+ export declare function isPathParam(part: string): boolean;
7
8
  export declare function titleCaseToken(value: string): string;
8
9
  export declare function isHumanOperationTitle(title: string | undefined): boolean;
9
10
  /**
10
11
  * Pull path / method / optional human title from a TEST_TITLE or Jest name.
11
- * Section suffixes (POSITIVE CASES …) are ignored.
12
12
  */
13
13
  export declare function parseOperationLabel(raw?: string): ParsedOperationLabel | undefined;
14
+ /** Readable TEST_TITLE: `Create Mock Tbs — POST /v1/admin/mock-tbs` */
14
15
  export declare function formatTestTitle(title: string, pathTemplate: string, method: string): string;
16
+ export declare function resourceLabel(pathTemplate: string): string;
17
+ export type TitleSuggestion = {
18
+ titles: string[];
19
+ /** Safe to apply with --yes / `a`. False → user must type a custom name. */
20
+ auto: boolean;
21
+ };
15
22
  /**
16
- * Deterministic title suggestions from HTTP method + path (no AI).
17
- * POST /v1/admin/mock-tbs → ["Create Mock Tbs", "Create Admin Mock Tbs"]
23
+ * POST /v1/admin/mock-tbs → Create Mock Tbs
24
+ * GET /v1/me/branches → Find All Branches
25
+ * GET /v1/integrator/merchants/{id}/branches → Find All Branches By Merchant Id
26
+ * GET /v1/admin/addresses/:id → Find One Address By Id
27
+ * POST /v1/me/branches/:id/addresses/billing → Create Billing Address
28
+ * POST /v1/public/external-checkout/:id/complete → Complete External Checkout
18
29
  */
30
+ export declare function suggestOperationTitleResult(method: string, pathTemplate: string): TitleSuggestion;
19
31
  export declare function suggestOperationTitles(method: string, pathTemplate: string): string[];
@@ -1,20 +1,31 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isPathParam = isPathParam;
3
4
  exports.titleCaseToken = titleCaseToken;
4
5
  exports.isHumanOperationTitle = isHumanOperationTitle;
5
6
  exports.parseOperationLabel = parseOperationLabel;
6
7
  exports.formatTestTitle = formatTestTitle;
8
+ exports.resourceLabel = resourceLabel;
9
+ exports.suggestOperationTitleResult = suggestOperationTitleResult;
7
10
  exports.suggestOperationTitles = suggestOperationTitles;
8
11
  const METHODS = 'GET|POST|PUT|PATCH|DELETE|UPDATE|UPSERT';
9
- const PATH_ONLY_RE = new RegExp(`^(?<path>\\/\\S+)\\s+\\[(?<method>${METHODS})\\](?:\\s+\\(integration\\))?\\s*$`, 'i');
10
- const WITH_TITLE_RE = new RegExp(`^(?<title>.+?)\\s+(?<path>\\/\\S+)\\s+\\[(?<method>${METHODS})\\](?:\\s+\\(integration\\))?\\s*$`, 'i');
12
+ const PATH_ONLY_BRACKET_RE = new RegExp(`^(?<path>\\/\\S+)\\s+\\[(?<method>${METHODS})\\](?:\\s+\\(integration\\))?\\s*$`, 'i');
13
+ const TITLE_BRACKET_RE = new RegExp(`^(?<title>.+?)\\s+(?<path>\\/\\S+)\\s+\\[(?<method>${METHODS})\\](?:\\s+\\(integration\\))?\\s*$`, 'i');
14
+ /** `Create Mock Tbs — POST /v1/admin/mock-tbs` */
15
+ const TITLE_DASH_RE = new RegExp(`^(?<title>.+?)\\s+[—–-]\\s+(?<method>${METHODS})\\s+(?<path>\\/\\S+)(?:\\s+\\(integration\\))?\\s*$`, 'i');
16
+ const PATH_ONLY_DASH_RE = new RegExp(`^(?<method>${METHODS})\\s+(?<path>\\/\\S+)(?:\\s+\\(integration\\))?\\s*$`, 'i');
11
17
  const ROLE_WORDS = new Set([
12
18
  'admin',
13
19
  'user',
14
20
  'users',
21
+ 'me',
15
22
  'public',
16
23
  'internal',
24
+ 'internal-application',
25
+ 'internal-service',
26
+ 'integrator',
17
27
  'partner',
28
+ 'device',
18
29
  'staff',
19
30
  'customer',
20
31
  'vendor',
@@ -23,6 +34,7 @@ const ROLE_WORDS = new Set([
23
34
  'system',
24
35
  'superadmin',
25
36
  ]);
37
+ const MODULE_WORDS = new Set(['validator', 'validation', 'validators', 'business-data']);
26
38
  const ACTION_WORDS = new Set([
27
39
  'validate',
28
40
  'approve',
@@ -41,11 +53,41 @@ const ACTION_WORDS = new Set([
41
53
  'restore',
42
54
  'verify',
43
55
  'confirm',
56
+ 'complete',
44
57
  'activate',
45
58
  'deactivate',
59
+ 'check',
60
+ 'calculate',
61
+ 'retry',
62
+ 'send',
63
+ 'insert',
64
+ 'merge',
65
+ 'upsert',
66
+ 'onboard',
67
+ 'assign',
46
68
  ]);
69
+ const NOTIFY_WORDS = new Set(['sms', 'email', 'phone', 'push']);
70
+ function isPathParam(part) {
71
+ const value = part.trim();
72
+ if (!value)
73
+ return false;
74
+ if (value.startsWith('{') || value.startsWith(':') || value.startsWith('${'))
75
+ return true;
76
+ if (/\$\{[^}]+\}/.test(value))
77
+ return true;
78
+ return false;
79
+ }
80
+ function paramName(part) {
81
+ return part
82
+ .trim()
83
+ .replace(/^\$\{/, '')
84
+ .replace(/^[:{]+/, '')
85
+ .replace(/[}]+$/, '')
86
+ .replace(/^\$/, '');
87
+ }
47
88
  function titleCaseToken(value) {
48
89
  return value
90
+ .replace(/^[:]/, '')
49
91
  .replace(/[{}]/g, '')
50
92
  .split(/[-_]/g)
51
93
  .filter(Boolean)
@@ -56,83 +98,231 @@ function isHumanOperationTitle(title) {
56
98
  const value = title?.trim() ?? '';
57
99
  if (value.length < 2 || value.length > 80)
58
100
  return false;
59
- if (value.startsWith('/'))
101
+ if (value.startsWith('/') || value.startsWith(':'))
102
+ return false;
103
+ if (/[{}]/.test(value) || /:[a-zA-Z]/.test(value))
60
104
  return false;
61
105
  if (!/[a-zA-Z]/.test(value))
62
106
  return false;
63
107
  return true;
64
108
  }
109
+ function stripCaseTail(raw) {
110
+ return raw
111
+ .replace(/\s+(POSITIVE CASES|SEMANTIC ERROR CASES(?:\s*-\s*AUTH)?|INVALID CASES|OMITTED(?: FIELD)? CASES)\b[\s\S]*$/i, '')
112
+ .trim();
113
+ }
65
114
  /**
66
115
  * Pull path / method / optional human title from a TEST_TITLE or Jest name.
67
- * Section suffixes (POSITIVE CASES …) are ignored.
68
116
  */
69
117
  function parseOperationLabel(raw) {
70
118
  if (!raw)
71
119
  return undefined;
72
- const cut = raw
73
- .replace(/\s+(POSITIVE CASES|SEMANTIC ERROR CASES(?:\s*-\s*AUTH)?|INVALID CASES|OMITTED(?: FIELD)? CASES)\b[\s\S]*$/i, '')
74
- .trim();
120
+ const cut = stripCaseTail(raw);
75
121
  const integration = /\(integration\)/i.test(cut);
76
- const pathOnly = cut.match(PATH_ONLY_RE);
77
- if (pathOnly?.groups?.path && pathOnly.groups.method) {
78
- return { path: pathOnly.groups.path, method: pathOnly.groups.method.toUpperCase(), integration };
79
- }
80
- const withTitle = cut.match(WITH_TITLE_RE);
81
- if (!withTitle?.groups?.path || !withTitle.groups.method)
82
- return undefined;
83
- const title = withTitle.groups.title?.trim();
84
- return {
85
- title: isHumanOperationTitle(title) ? title : undefined,
86
- path: withTitle.groups.path,
87
- method: withTitle.groups.method.toUpperCase(),
88
- integration,
122
+ const fromGroups = (match) => {
123
+ const path = match?.groups?.path;
124
+ const method = match?.groups?.method;
125
+ if (!path || !method)
126
+ return undefined;
127
+ const title = match.groups?.title?.trim();
128
+ return {
129
+ title: isHumanOperationTitle(title) ? title : undefined,
130
+ path,
131
+ method: method.toUpperCase(),
132
+ integration,
133
+ };
89
134
  };
135
+ return (fromGroups(cut.match(TITLE_DASH_RE)) ||
136
+ fromGroups(cut.match(PATH_ONLY_DASH_RE)) ||
137
+ fromGroups(cut.match(PATH_ONLY_BRACKET_RE)) ||
138
+ fromGroups(cut.match(TITLE_BRACKET_RE)));
90
139
  }
140
+ /** Readable TEST_TITLE: `Create Mock Tbs — POST /v1/admin/mock-tbs` */
91
141
  function formatTestTitle(title, pathTemplate, method) {
92
142
  const clean = title.trim().replace(/\s+/g, ' ');
93
- return `${clean} ${pathTemplate} [${method.toUpperCase()}] (integration)`;
143
+ return `${clean} — ${method.toUpperCase()} ${pathTemplate}`;
94
144
  }
95
- function verbFor(method, pathTemplate, actionLabel) {
96
- if (actionLabel)
97
- return actionLabel;
98
- const hasParam = pathTemplate.split('/').some((part) => part.startsWith('{'));
99
- const m = method.toLowerCase();
100
- if (m === 'get')
101
- return hasParam ? 'Find One' : 'Find All';
102
- if (m === 'post')
103
- return 'Create';
104
- if (m === 'delete')
105
- return 'Delete';
106
- if (m === 'put' || m === 'patch' || m === 'update')
107
- return 'Update';
108
- if (m === 'upsert')
109
- return 'Upsert';
110
- return titleCaseToken(m);
145
+ function namedSegments(pathTemplate) {
146
+ return pathTemplate.split('/').filter((part) => part && !isPathParam(part) && !/^v\d+$/i.test(part));
147
+ }
148
+ function operationSegments(pathTemplate) {
149
+ return namedSegments(pathTemplate).filter((part) => !ROLE_WORDS.has(part.toLowerCase()) && !MODULE_WORDS.has(part.toLowerCase()));
150
+ }
151
+ function resourceLabel(pathTemplate) {
152
+ const rest = operationSegments(pathTemplate);
153
+ const last = rest[rest.length - 1] || namedSegments(pathTemplate)[namedSegments(pathTemplate).length - 1] || 'resource';
154
+ const prev = rest[rest.length - 2];
155
+ if ((ACTION_WORDS.has(last.toLowerCase()) || last.toLowerCase() === 'bulk') && prev)
156
+ return titleCaseToken(prev);
157
+ return titleCaseToken(last);
158
+ }
159
+ function lastSegment(pathTemplate) {
160
+ const rest = operationSegments(pathTemplate);
161
+ return (rest[rest.length - 1] || '').toLowerCase();
162
+ }
163
+ function singularSimple(raw) {
164
+ const value = raw.toLowerCase();
165
+ if (value.length <= 3)
166
+ return value;
167
+ if (value.endsWith('ies') && value.length > 4)
168
+ return value.slice(0, -3) + 'y';
169
+ if (value.endsWith('ches') || value.endsWith('shes') || value.endsWith('sses'))
170
+ return value.slice(0, -2);
171
+ if (value.endsWith('ses') && value.length > 4)
172
+ return value.slice(0, -2);
173
+ if (value.endsWith('s') && !value.endsWith('ss'))
174
+ return value.slice(0, -1);
175
+ return value;
176
+ }
177
+ function singularStem(token) {
178
+ if (token.includes('-')) {
179
+ const bits = token.split('-');
180
+ bits[bits.length - 1] = singularSimple(bits[bits.length - 1]);
181
+ return bits.join('-');
182
+ }
183
+ return singularSimple(token);
184
+ }
185
+ /** `{id}` after `merchants` (parent) → Merchant Id; trailing `:id` → Id */
186
+ function byClauseFromParam(param, precedingNamed, role) {
187
+ const name = paramName(param);
188
+ if (!name)
189
+ return 'By Id';
190
+ if (/^id$/i.test(name)) {
191
+ if (role === 'parent' && precedingNamed) {
192
+ return `By ${titleCaseToken(singularStem(precedingNamed))} Id`;
193
+ }
194
+ return 'By Id';
195
+ }
196
+ if (/Id$/i.test(name))
197
+ return `By ${titleCaseToken(name.replace(/Id$/i, ''))} Id`;
198
+ return `By ${titleCaseToken(name)}`;
199
+ }
200
+ function pathTokens(pathTemplate) {
201
+ return pathTemplate.split('/').filter(Boolean);
202
+ }
203
+ function trailingParam(pathTemplate) {
204
+ const tokens = pathTokens(pathTemplate);
205
+ const last = tokens[tokens.length - 1];
206
+ return last && isPathParam(last) ? last : undefined;
207
+ }
208
+ function parentParam(pathTemplate) {
209
+ const tokens = pathTokens(pathTemplate);
210
+ for (let i = tokens.length - 1; i >= 1; i -= 1) {
211
+ if (!isPathParam(tokens[i]))
212
+ continue;
213
+ if (i === tokens.length - 1)
214
+ continue;
215
+ let named = '';
216
+ for (let j = i - 1; j >= 0; j -= 1) {
217
+ if (!isPathParam(tokens[j]) && !/^v\d+$/i.test(tokens[j]) && !ROLE_WORDS.has(tokens[j].toLowerCase())) {
218
+ named = tokens[j];
219
+ break;
220
+ }
221
+ }
222
+ return { param: tokens[i], named };
223
+ }
224
+ return undefined;
111
225
  }
112
226
  /**
113
- * Deterministic title suggestions from HTTP method + path (no AI).
114
- * POST /v1/admin/mock-tbs → ["Create Mock Tbs", "Create Admin Mock Tbs"]
227
+ * POST /v1/admin/mock-tbs → Create Mock Tbs
228
+ * GET /v1/me/branches → Find All Branches
229
+ * GET /v1/integrator/merchants/{id}/branches → Find All Branches By Merchant Id
230
+ * GET /v1/admin/addresses/:id → Find One Address By Id
231
+ * POST /v1/me/branches/:id/addresses/billing → Create Billing Address
232
+ * POST /v1/public/external-checkout/:id/complete → Complete External Checkout
115
233
  */
116
- function suggestOperationTitles(method, pathTemplate) {
117
- const parts = pathTemplate.split('/').filter(Boolean);
118
- const named = parts.filter((part) => !part.startsWith('{') && !/^v\d+$/i.test(part));
119
- const last = named[named.length - 1] || 'resource';
120
- const prev = named[named.length - 2];
121
- const lastIsAction = ACTION_WORDS.has(last.toLowerCase());
122
- const resource = titleCaseToken(lastIsAction && prev ? prev : last);
123
- const actionLabel = lastIsAction ? titleCaseToken(last) : null;
124
- const role = named.find((part) => ROLE_WORDS.has(part.toLowerCase()));
125
- const verb = verbFor(method, pathTemplate, actionLabel);
234
+ function suggestOperationTitleResult(method, pathTemplate) {
235
+ const rest = operationSegments(pathTemplate);
236
+ const last = lastSegment(pathTemplate);
237
+ const prev = rest.length >= 2 ? rest[rest.length - 2] : undefined;
238
+ const leafAll = last ? titleCaseToken(last) : resourceLabel(pathTemplate);
239
+ const leafOne = last ? titleCaseToken(singularStem(last)) : leafAll;
240
+ const m = method.toLowerCase();
241
+ const endParam = trailingParam(pathTemplate);
242
+ const nested = parentParam(pathTemplate);
126
243
  const out = [];
127
244
  const add = (value) => {
128
245
  const next = value.replace(/\s+/g, ' ').trim();
129
- if (next && !out.includes(next))
246
+ if (next && !out.includes(next) && isHumanOperationTitle(next))
130
247
  out.push(next);
131
248
  };
132
- add(`${verb} ${resource}`);
133
- if (role)
134
- add(`${verb} ${titleCaseToken(role)} ${resource}`);
135
- if (actionLabel && verb !== actionLabel)
136
- add(`${actionLabel} ${resource}`);
137
- return out.slice(0, 3);
249
+ if (last === 'bulk') {
250
+ const resource = resourceLabel(pathTemplate);
251
+ add(m === 'get' ? `Find Bulk ${resource}` : `Create Bulk ${resource}`);
252
+ return { titles: out.slice(0, 3), auto: out.length > 0 };
253
+ }
254
+ if (last.startsWith('by-')) {
255
+ const target = prev ? titleCaseToken(prev) : resourceLabel(pathTemplate);
256
+ const by = titleCaseToken(last);
257
+ if (m === 'get') {
258
+ add(`Find All ${target} ${by}`);
259
+ add(`Find ${target} ${by}`);
260
+ }
261
+ else if (m === 'post')
262
+ add(`Create ${target} ${by}`);
263
+ else
264
+ add(`${titleCaseToken(m)} ${target} ${by}`);
265
+ return { titles: out.slice(0, 3), auto: out.length > 0 };
266
+ }
267
+ if (NOTIFY_WORDS.has(last) && (prev === 'send' || prev === 'validations' || ACTION_WORDS.has(prev || ''))) {
268
+ if (prev === 'send' || last !== 'phone')
269
+ add(`Send ${titleCaseToken(last)}`);
270
+ if (prev === 'validations' || prev === 'validate')
271
+ add(`Validate ${titleCaseToken(last)}`);
272
+ if (out.length)
273
+ return { titles: out.slice(0, 3), auto: true };
274
+ }
275
+ if (NOTIFY_WORDS.has(last) && m === 'post') {
276
+ add(`Send ${titleCaseToken(last)}`);
277
+ return { titles: out.slice(0, 3), auto: out.length > 0 };
278
+ }
279
+ if (last.endsWith('-retries') || last === 'retries') {
280
+ const subject = prev ? titleCaseToken(prev) : titleCaseToken(last.replace(/-?retries$/, '') || 'operation');
281
+ add(`Retry ${subject}`);
282
+ add('Retry Operation');
283
+ return { titles: out.slice(0, 3), auto: out.length > 0 };
284
+ }
285
+ if (ACTION_WORDS.has(last)) {
286
+ const resource = prev ? titleCaseToken(prev) : resourceLabel(pathTemplate);
287
+ add(`${titleCaseToken(last)} ${resource}`);
288
+ return { titles: out.slice(0, 3), auto: out.length > 0 };
289
+ }
290
+ if (prev && /^(addresses?|items?)$/i.test(prev) && !ACTION_WORDS.has(last) && !endParam) {
291
+ const kind = titleCaseToken(last);
292
+ const noun = titleCaseToken(singularStem(prev));
293
+ if (m === 'post')
294
+ add(`Create ${kind} ${noun}`);
295
+ else if (m === 'get')
296
+ add(`Find ${kind} ${noun}`);
297
+ else
298
+ add(`${titleCaseToken(m)} ${kind} ${noun}`);
299
+ if (out.length)
300
+ return { titles: out.slice(0, 3), auto: true };
301
+ }
302
+ const byEnd = endParam ? byClauseFromParam(endParam, last, 'end') : undefined;
303
+ const byParent = nested ? byClauseFromParam(nested.param, nested.named, 'parent') : undefined;
304
+ if (m === 'get' && endParam)
305
+ add(`Find One ${leafOne} ${byEnd}`);
306
+ else if (m === 'get' && byParent) {
307
+ add(`Find All ${leafAll} ${byParent}`);
308
+ add(`Find All ${leafAll}`);
309
+ }
310
+ else if (m === 'get')
311
+ add(`Find All ${leafAll}`);
312
+ else if (m === 'post')
313
+ add(`Create ${leafOne}`);
314
+ else if (m === 'delete' && endParam)
315
+ add(`Delete One ${leafOne} ${byEnd}`);
316
+ else if (m === 'delete')
317
+ add(`Delete ${leafAll}`);
318
+ else if ((m === 'put' || m === 'patch' || m === 'update') && endParam)
319
+ add(`Update ${leafOne} ${byEnd}`);
320
+ else if (m === 'put' || m === 'patch' || m === 'update')
321
+ add(`Update ${leafAll}`);
322
+ else
323
+ return { titles: out.slice(0, 3), auto: false };
324
+ return { titles: out.slice(0, 3), auto: out.length > 0 };
325
+ }
326
+ function suggestOperationTitles(method, pathTemplate) {
327
+ return suggestOperationTitleResult(method, pathTemplate).titles;
138
328
  }
@@ -39,19 +39,9 @@ exports.extractJestConfigFromCommand = extractJestConfigFromCommand;
39
39
  exports.resolveTestScript = resolveTestScript;
40
40
  exports.upsertTestWiringInConfig = upsertTestWiringInConfig;
41
41
  exports.wrapUserTestScript = wrapUserTestScript;
42
- const readline_1 = require("readline");
43
42
  const fs_1 = require("fs");
44
43
  const path = __importStar(require("path"));
45
44
  const ui_1 = require("./ui");
46
- function prompt(question) {
47
- const rl = (0, readline_1.createInterface)({ input: process.stdin, output: process.stdout });
48
- return new Promise((resolve) => {
49
- rl.question(question, (answer) => {
50
- rl.close();
51
- resolve(answer.trim());
52
- });
53
- });
54
- }
55
45
  function scoreScript(name, command) {
56
46
  const n = name.toLowerCase();
57
47
  const cmd = command.toLowerCase();
@@ -111,27 +101,39 @@ async function resolveTestScript(options) {
111
101
  if (!choices.length) {
112
102
  if (options.yes || !process.stdin.isTTY)
113
103
  return null;
114
- const typed = await prompt(` ${ui_1.c.yellow('?')} ${ui_1.c.bold('No test script found.')} Enter script name, or ${ui_1.c.dim('n')} to skip:\n ${ui_1.c.cyan('›')} `);
104
+ const typed = await (0, ui_1.readlineAsk)((0, ui_1.askLine)('No test script found', 'script name, or n to skip'));
115
105
  if (!typed || /^n(o)?$/i.test(typed))
116
106
  return null;
117
107
  return typed;
118
108
  }
119
- const def = choices[0];
109
+ const shown = choices.slice(0, 8);
110
+ const def = shown[0];
120
111
  if (options.yes || !process.stdin.isTTY)
121
112
  return def.name;
122
- console.log(` ${ui_1.c.dim('your scripts')}`);
123
- choices.slice(0, 8).forEach((choice, i) => {
124
- const mark = i === 0 ? ui_1.c.cyan('●') : ui_1.c.dim('○');
125
- const label = i === 0 ? ui_1.c.bold(choice.name) : ui_1.c.dim(choice.name);
126
- const cmd = isDaxtaWrappedScript(choice.command) ? '(already wired → daxta test)' : choice.command.slice(0, 56);
127
- console.log(` ${mark} ${label} ${ui_1.c.dim(cmd)}`);
113
+ console.log(` ${ui_1.c.gold('?')} ${ui_1.c.bold('Test script')} ${ui_1.c.dim('— reporter + globalSetup')}`);
114
+ shown.forEach((choice, i) => {
115
+ const n = String(i + 1);
116
+ const rec = i === 0 ? ui_1.c.dim(' recommended') : '';
117
+ const cmd = isDaxtaWrappedScript(choice.command)
118
+ ? '(already wired → daxta test)'
119
+ : choice.command.length > 52
120
+ ? `${choice.command.slice(0, 52)}…`
121
+ : choice.command;
122
+ console.log(` ${ui_1.c.ice(n)} ${ui_1.c.bold(choice.name)}${rec}`);
123
+ console.log(` ${ui_1.c.dim(cmd)}`);
128
124
  });
129
- const answer = await prompt(` ${ui_1.c.yellow('?')} Attach DAxTA plugin to ${ui_1.c.cyan(def.name)}?\n` +
130
- ` ${ui_1.c.dim('Y')} yes · ${ui_1.c.dim('n')} skip · or type another script name\n ${ui_1.c.cyan('›')} `);
131
- if (!answer || /^y(es)?$/i.test(answer))
125
+ console.log(` ${ui_1.c.dim('n')} skip`);
126
+ const answer = await (0, ui_1.readlineAsk)(` ${ui_1.c.dim(`Enter = 1 (${def.name})`)} ${ui_1.c.dim('·')} ${ui_1.c.dim('or type a script name')}\n ${ui_1.c.ice('›')} `);
127
+ if (!answer)
132
128
  return def.name;
133
129
  if (/^n(o)?$/i.test(answer))
134
130
  return null;
131
+ if (/^\d+$/.test(answer)) {
132
+ const picked = shown[Number(answer) - 1];
133
+ if (!picked)
134
+ throw new Error(`No script #${answer}`);
135
+ return picked.name;
136
+ }
135
137
  return answer;
136
138
  }
137
139
  function upsertConfigFields(cwd, fields, dryRun = false) {