@mgamadeus/ddd-web 0.19.0 → 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,24 @@
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
+
16
+ ## 0.19.1
17
+
18
+ ### Fixed
19
+ - `enums: 'const'`: an integer enum keeps its numbers (`{ "1": 1, "101": 101 }`); the members were strings (`"1"`), so
20
+ the property type did not fit the numbers the backend sends.
21
+
3
22
  ## 0.19.0
4
23
 
5
24
  ### Added
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/* → getBookGetResponseDtoMock()
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
 
@@ -1326,7 +1326,8 @@ function applyEnumConsts(body, modelName, model, options = {}) {
1326
1326
  if (!values || values.length === 0) continue;
1327
1327
  const constName = `${modelName}${propertyName2.charAt(0).toUpperCase()}${propertyName2.slice(1)}`;
1328
1328
  if (!/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(constName)) continue;
1329
- const members = [...new Set(values.map(String))].map((value) => ` ${enumKeyOf(value)}: ${JSON.stringify(value)},`).join("\n");
1329
+ const unique = [...new Map(values.map((value) => [String(value), value])).values()];
1330
+ const members = unique.map((value) => ` ${enumKeyOf(String(value))}: ${JSON.stringify(value)},`).join("\n");
1330
1331
  consts.set(constName, `export const ${constName} = {
1331
1332
  ${members}
1332
1333
  };
@@ -2084,7 +2085,7 @@ function renderMswHandlers(input) {
2084
2085
  if (shape && local) defaultMock = shape.array ? `[${local}()]` : `${local}()`;
2085
2086
  }
2086
2087
  if (kind === "text" && responseType === "unknown") responseType = "string";
2087
- const pattern = `*${endpoint.path.replace(/\{[^}]+\}/g, "*")}`;
2088
+ const pattern = mswPathPattern(endpoint.path);
2088
2089
  const key = IDENTIFIER2.test(endpoint.key) ? endpoint.key : JSON.stringify(endpoint.key);
2089
2090
  entries.push(
2090
2091
  ` ${key}: (custom?: Partial<StoryMock<${responseType}, ${argType}>>) =>
@@ -2131,7 +2132,7 @@ export type StoryMockParams<Arg> = { [Name in Arg extends object ? Extract<keyof
2131
2132
 
2132
2133
  /** How a generated handler answers; the factories take \`Partial<StoryMock<\u2026>>\`. */
2133
2134
  export interface StoryMock<Response, Arg = void> {
2134
- /** URL pattern matched instead of the generated one (any origin + the operation path, \`*\` per path parameter). */
2135
+ /** URL pattern matched instead of the generated one (any origin + the operation path, \`:name\` per path parameter). */
2135
2136
  url: string;
2136
2137
  /** Default: the operation's first declared 2xx status (200 for a file download). */
2137
2138
  status: number;
@@ -2193,6 +2194,18 @@ const mockOperation = <Response, Arg>(
2193
2194
  return new HttpResponse(body as unknown as BodyInit, init);
2194
2195
  });
2195
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
+ }
2196
2209
  function successStatus(responses) {
2197
2210
  const codes = Object.keys(responses ?? {}).filter((code) => /^2\d\d$/.test(code)).map(Number).sort((a, b) => a - b);
2198
2211
  return codes[0] ?? 200;
@@ -3383,4 +3396,4 @@ export {
3383
3396
  runSkillLinks,
3384
3397
  linkSkills
3385
3398
  };
3386
- //# sourceMappingURL=chunk-HZ4VYIHY.js.map
3399
+ //# sourceMappingURL=chunk-K3AQR2GB.js.map