@mgamadeus/ddd-web 0.18.0 → 0.19.0

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.
@@ -4,7 +4,7 @@ import {
4
4
  consoleLogger,
5
5
  generateSdk,
6
6
  runSkillLinks
7
- } from "../chunk-AGECBV52.js";
7
+ } from "../chunk-HZ4VYIHY.js";
8
8
 
9
9
  // src/codegen/cli.ts
10
10
  import { parseArgs } from "util";
@@ -259,6 +259,46 @@ interface ModelOptions {
259
259
  idType?: 'document' | 'number' | 'string';
260
260
  }
261
261
 
262
+ interface Logger {
263
+ info(message: string): void;
264
+ warn(message: string): void;
265
+ error(message: string): void;
266
+ }
267
+ declare const consoleLogger: Logger;
268
+ declare const silentLogger: Logger;
269
+ /** Thrown for expected aborts (bad spec, bad config); the CLI prints the message without a stack. */
270
+ declare class SdkGenerationError extends Error {
271
+ name: string;
272
+ }
273
+
274
+ /** Where the default answer of a generated MSW handler comes from: the application's model mock functions. */
275
+ interface ModelMocksOptions {
276
+ /**
277
+ * Module specifier prefix of the model mocks; the model's path below the models directory follows it, then
278
+ * `fileSuffix`. `'@mocks/models/'` + `App/Domain/Library/Entities/Books/Book` + `'.mock'`.
279
+ */
280
+ importPrefix: string;
281
+ /** Named export of a model's mock function (called without arguments). Default `get<ModelName>Mock`. */
282
+ exportName?: (modelName: string, modelPath: string) => string;
283
+ /** Appended to the model path in the import specifier. Default `'.mock'`. */
284
+ fileSuffix?: string;
285
+ }
286
+ /**
287
+ * Generated MSW request handlers, one factory per operation that has a request builder (`<stem>Mocks.ts`). The
288
+ * generated file imports `msw` (a dependency of the consuming project, never of DDD Web).
289
+ */
290
+ interface MswHandlersOptions {
291
+ /** Default answers from the application's model mocks; without it every handler answers `null`. */
292
+ modelMocks?: ModelMocksOptions;
293
+ }
294
+ /** Per api: `false` turns the handlers off for this api; the fields override the config-level ones. */
295
+ interface ApiMswHandlersOptions extends MswHandlersOptions {
296
+ /** The handlers file. Default `<stem>Mocks.ts` next to the api output file. */
297
+ outputFile?: string;
298
+ /** Name of the exported handler object. Default `<stem>Mocks`. */
299
+ exportName?: string;
300
+ }
301
+
262
302
  /** Selects operations by HTTP method (optional, case-insensitive) and path (exact string or RegExp). */
263
303
  interface OperationMatcher {
264
304
  method?: Uppercase<HttpMethod> | HttpMethod;
@@ -367,6 +407,11 @@ interface SdkApiConfig {
367
407
  responseHandlers?: ResponseHandlerOverride[];
368
408
  /** Checked before the global `invalidation`; the first resolver that returns a list wins. */
369
409
  invalidation?: InvalidationResolver;
410
+ /**
411
+ * MSW handlers for this api (default mode): `false` turns them off; an object enables them (also without the
412
+ * config-level `mswHandlers`) and overrides its fields, e.g. `outputFile`.
413
+ */
414
+ mswHandlers?: ApiMswHandlersOptions | false;
370
415
  /** Any further RTK codegen option (`argSuffix`, `flattenArg`, `endpointOverrides`, `filterEndpoints`, …). */
371
416
  [rtkOption: string]: unknown;
372
417
  }
@@ -431,6 +476,12 @@ interface SdkConfig {
431
476
  * your own function; the body as `requestBody` (see {@link EndpointOptions}).
432
477
  */
433
478
  endpoints?: EndpointOptions;
479
+ /**
480
+ * Generate MSW request handlers (default mode): per api a `<stem>Mocks.ts` next to the api file with one handler
481
+ * factory per operation that has a request builder, answering the response model's mock from `modelMocks`. Off
482
+ * when absent: nothing changes. The generated file imports `msw`, which the consuming project installs.
483
+ */
484
+ mswHandlers?: MswHandlersOptions;
434
485
  /** tsconfig used for the final type check. Default `tsconfig.json` next to the config file. */
435
486
  tsconfig?: string;
436
487
  }
@@ -446,18 +497,6 @@ interface LoadedConfig {
446
497
  */
447
498
  declare function loadConfig(configPath: string): Promise<LoadedConfig>;
448
499
 
449
- interface Logger {
450
- info(message: string): void;
451
- warn(message: string): void;
452
- error(message: string): void;
453
- }
454
- declare const consoleLogger: Logger;
455
- declare const silentLogger: Logger;
456
- /** Thrown for expected aborts (bad spec, bad config); the CLI prints the message without a stack. */
457
- declare class SdkGenerationError extends Error {
458
- name: string;
459
- }
460
-
461
500
  /**
462
501
  * `invalidation` resolver that restores the 0.2 default: writes without an identity from `x-ddd-entity` (a path
463
502
  * identity on an upsert / delete) invalidate LIST plus their whole tag type instead of the derived identity.
@@ -500,7 +539,8 @@ interface LegacySdkSource {
500
539
  onError?: string;
501
540
  outputs: Record<string, Record<string, unknown>>;
502
541
  }
503
- interface GeneratorResult {
542
+ /** One source's result of a legacy run. */
543
+ interface LegacySdkResult {
504
544
  source: string;
505
545
  ok: boolean;
506
546
  skipped?: boolean;
@@ -512,6 +552,11 @@ interface GeneratorResult {
512
552
  content: string;
513
553
  }>;
514
554
  }>;
555
+ /**
556
+ * With `prune`: the absolute paths of the files this source wrote on an earlier run and no longer writes, deleted
557
+ * by this run (with `dryRun`: the files the run would delete). Absent without `prune`.
558
+ */
559
+ pruned?: string[];
515
560
  }
516
561
  interface GenerateLegacySdkOptions {
517
562
  /** Explicit sources and directories for an existing SDK layout, processed in the given order. */
@@ -520,9 +565,20 @@ interface GenerateLegacySdkOptions {
520
565
  dryRun?: boolean;
521
566
  targetOptions?: Record<string, unknown>;
522
567
  logger?: Logger;
568
+ /**
569
+ * Delete the files an earlier run wrote and this run no longer plans (a store of a removed controller, a model or
570
+ * mock of a removed schema). Only files recorded in the manifest (`manifestFile`) are ever deleted, so hand-written
571
+ * files in a shared output directory stay. Scoped per source and output: an output of a source that did not run
572
+ * (left out, skipped, or without that output this time) deletes nothing, and a file it lists is kept. The first
573
+ * run with `prune` writes the manifest and deletes nothing. Default `false`: nothing is deleted, no manifest is
574
+ * read or written.
575
+ */
576
+ prune?: boolean;
577
+ /** The manifest of the files each source and output wrote, relative to `cwd`. Default `.ddd-web-legacy-sdk.json`. */
578
+ manifestFile?: string;
523
579
  }
524
580
  /** Runs the legacy generator for an app that owns its spec sources and generated file layout. */
525
- declare function generateLegacySdk(options: GenerateLegacySdkOptions): Promise<GeneratorResult[]>;
581
+ declare function generateLegacySdk(options: GenerateLegacySdkOptions): Promise<LegacySdkResult[]>;
526
582
 
527
583
  /** One entry of `.ddd-skills.json` → `skills`. */
528
584
  interface SkillsManifestEntry {
@@ -611,4 +667,4 @@ declare function loadSpec(source: string, timeoutMs?: number): Promise<OpenApiDo
611
667
  declare function validateSpec(doc: OpenApiDocument, source: string, logger: Logger): void;
612
668
 
613
669
  export { SUPPORTED_CONTRACT, SdkGenerationError, broadInvalidation, buildEndpointNameFromPath, consoleLogger, defineConfig, findSkillsRepositoryRoot, generateLegacySdk, generateSdk, linkSkills, loadConfig, loadSpec, runSkillLinks, silentLogger, validateSpec };
614
- export type { EndpointNamingOperation, EndpointOptions, GenerateLegacySdkOptions, GenerateSdkOptions, GenerateSdkResult, HooksOptions, InvalidationOperation, InvalidationResolver, InvalidationTag, LegacySdkSource, LinkSkillAction, LinkSkillsOptions, LinkSkillsResult, LoadedConfig, Logger, ModelOptions, OpenApiDocument, OperationMatcher, ResponseHandlerOverride, SdkApiConfig, SdkConfig, SdkGeneratorConfig, SdkGeneratorMode, SideEffectsOverride, SkillLinksOptions, SkillLinksReport, SkillsManifest, SkillsManifestEntry, WorkspaceOptions };
670
+ export type { ApiMswHandlersOptions, EndpointNamingOperation, EndpointOptions, GenerateLegacySdkOptions, GenerateSdkOptions, GenerateSdkResult, HooksOptions, InvalidationOperation, InvalidationResolver, InvalidationTag, LegacySdkResult, LegacySdkSource, LinkSkillAction, LinkSkillsOptions, LinkSkillsResult, LoadedConfig, Logger, ModelMocksOptions, ModelOptions, MswHandlersOptions, OpenApiDocument, OperationMatcher, ResponseHandlerOverride, SdkApiConfig, SdkConfig, SdkGeneratorConfig, SdkGeneratorMode, SideEffectsOverride, SkillLinksOptions, SkillLinksReport, SkillsManifest, SkillsManifestEntry, WorkspaceOptions };
@@ -14,7 +14,7 @@ import {
14
14
  runSkillLinks,
15
15
  silentLogger,
16
16
  validateSpec
17
- } from "../chunk-AGECBV52.js";
17
+ } from "../chunk-HZ4VYIHY.js";
18
18
  export {
19
19
  SUPPORTED_CONTRACT,
20
20
  SdkGenerationError,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mgamadeus/ddd-web",
3
- "version": "0.18.0",
3
+ "version": "0.19.0",
4
4
  "description": "TypeScript web client for backends built with mgamadeus/ddd, the DDD entity framework for Symfony and Doctrine (Composer/Packagist). Generates a typed RTK Query SDK from the backend's OpenAPI document, builds DDD QueryOptions (filters, orderBy, expand, select, paging) and handles JWT auth with token refresh.",
5
5
  "keywords": [
6
6
  "ddd",
@@ -116,6 +116,7 @@
116
116
  "devDependencies": {
117
117
  "@reduxjs/toolkit": "^2.13.0",
118
118
  "@types/node": "^26.6.6",
119
+ "msw": "^2.12.10",
119
120
  "tsup": "^9.0.0",
120
121
  "typescript": "^6.0.3",
121
122
  "vitest": "^5.0.5"