@mgamadeus/ddd-web 0.19.1 → 0.19.2
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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.19.2
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
- `mswHandlers`: a path parameter in the URL pattern is an MSW `:param` (one segment) instead of `*` (any segments).
|
|
7
|
+
`*/books/*` also answered `/books/7/archive` and every other deeper path, so a handler could swallow the request of
|
|
8
|
+
another operation and hide a wrong URL. Parameter names are reduced to word characters and kept unique
|
|
9
|
+
(`{file-name}` → `:file_name`). The params a `response` function receives are unchanged. Regenerate the handlers;
|
|
10
|
+
a hand-written `url` override keeps working as it is.
|
|
11
|
+
|
|
12
|
+
### Tests
|
|
13
|
+
- `mswPathPattern` (names, several parameters, duplicates) and a runtime check that `/books/:bookId` leaves
|
|
14
|
+
`/books/7/preview` unanswered.
|
|
15
|
+
|
|
3
16
|
## 0.19.1
|
|
4
17
|
|
|
5
18
|
### Fixed
|
package/README.md
CHANGED
|
@@ -87,7 +87,7 @@ export default defineConfig({
|
|
|
87
87
|
import { adminApiMocks } from './api/adminApiMocks';
|
|
88
88
|
|
|
89
89
|
export const handlers = [
|
|
90
|
-
adminApiMocks.getApiAdminLibraryBooksByBookId(), // GET */api/admin/library/books
|
|
90
|
+
adminApiMocks.getApiAdminLibraryBooksByBookId(), // GET */api/admin/library/books/:bookId → getBookGetResponseDtoMock()
|
|
91
91
|
adminApiMocks.deleteApiAdminLibraryBooksByBookId({ status: 500, delay: 300 }),
|
|
92
92
|
adminApiMocks.getApiAdminLibraryBooksList({ response: (params, defaultMock) => ({ ...defaultMock!, books: { elements: [] } }) }),
|
|
93
93
|
];
|
|
@@ -258,9 +258,14 @@ ddd-web link-skills [--check] [--dry-run] [--quiet] [--root <dir>]
|
|
|
258
258
|
```
|
|
259
259
|
|
|
260
260
|
```json
|
|
261
|
-
{ "scripts": { "postinstall": "ddd-web link-skills" } }
|
|
261
|
+
{ "scripts": { "postinstall": "ddd-web link-skills", "link-skills": "ddd-web link-skills" } }
|
|
262
262
|
```
|
|
263
263
|
|
|
264
|
+
With `ignore-scripts=true` (in `.npmrc` or `~/.npmrc`) npm and pnpm run no `postinstall`: an install links nothing.
|
|
265
|
+
Run `npm run link-skills` (or `pnpm link-skills`) after the install — `npm run` runs a named script even then — or
|
|
266
|
+
rely on the Composer hook `ddd-link-skills`, which walks `node_modules/@mgamadeus/*` too and links the npm packages'
|
|
267
|
+
skills on the next Composer run.
|
|
268
|
+
|
|
264
269
|
Programmatic: `runSkillLinks({ cwd, root, check, dryRun, quiet, logger })` from `/codegen` returns a report with
|
|
265
270
|
`exitCode`, `skills`, `lines` and `problems`; `linkSkills()` (one result per skill) stays for existing callers.
|
|
266
271
|
|
|
@@ -2085,7 +2085,7 @@ function renderMswHandlers(input) {
|
|
|
2085
2085
|
if (shape && local) defaultMock = shape.array ? `[${local}()]` : `${local}()`;
|
|
2086
2086
|
}
|
|
2087
2087
|
if (kind === "text" && responseType === "unknown") responseType = "string";
|
|
2088
|
-
const pattern =
|
|
2088
|
+
const pattern = mswPathPattern(endpoint.path);
|
|
2089
2089
|
const key = IDENTIFIER2.test(endpoint.key) ? endpoint.key : JSON.stringify(endpoint.key);
|
|
2090
2090
|
entries.push(
|
|
2091
2091
|
` ${key}: (custom?: Partial<StoryMock<${responseType}, ${argType}>>) =>
|
|
@@ -2132,7 +2132,7 @@ export type StoryMockParams<Arg> = { [Name in Arg extends object ? Extract<keyof
|
|
|
2132
2132
|
|
|
2133
2133
|
/** How a generated handler answers; the factories take \`Partial<StoryMock<\u2026>>\`. */
|
|
2134
2134
|
export interface StoryMock<Response, Arg = void> {
|
|
2135
|
-
/** URL pattern matched instead of the generated one (any origin + the operation path,
|
|
2135
|
+
/** URL pattern matched instead of the generated one (any origin + the operation path, \`:name\` per path parameter). */
|
|
2136
2136
|
url: string;
|
|
2137
2137
|
/** Default: the operation's first declared 2xx status (200 for a file download). */
|
|
2138
2138
|
status: number;
|
|
@@ -2194,6 +2194,18 @@ const mockOperation = <Response, Arg>(
|
|
|
2194
2194
|
return new HttpResponse(body as unknown as BodyInit, init);
|
|
2195
2195
|
});
|
|
2196
2196
|
`;
|
|
2197
|
+
function mswPathPattern(operationPath) {
|
|
2198
|
+
const used = /* @__PURE__ */ new Set();
|
|
2199
|
+
const path13 = operationPath.replace(/\{([^}]+)\}/g, (_, raw) => {
|
|
2200
|
+
let name = raw.replace(/\W/g, "_") || "param";
|
|
2201
|
+
if (/^\d/.test(name)) name = `p${name}`;
|
|
2202
|
+
let unique = name;
|
|
2203
|
+
for (let index = 2; used.has(unique); index++) unique = `${name}${index}`;
|
|
2204
|
+
used.add(unique);
|
|
2205
|
+
return `:${unique}`;
|
|
2206
|
+
});
|
|
2207
|
+
return `*${path13}`;
|
|
2208
|
+
}
|
|
2197
2209
|
function successStatus(responses) {
|
|
2198
2210
|
const codes = Object.keys(responses ?? {}).filter((code) => /^2\d\d$/.test(code)).map(Number).sort((a, b) => a - b);
|
|
2199
2211
|
return codes[0] ?? 200;
|
|
@@ -3384,4 +3396,4 @@ export {
|
|
|
3384
3396
|
runSkillLinks,
|
|
3385
3397
|
linkSkills
|
|
3386
3398
|
};
|
|
3387
|
-
//# sourceMappingURL=chunk-
|
|
3399
|
+
//# sourceMappingURL=chunk-K3AQR2GB.js.map
|