mulink 1.1.8 → 1.1.9

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.
@@ -324,22 +324,66 @@ interface FileMetadata {
324
324
  imports: string[];
325
325
  dependencies: string[];
326
326
  }
327
+ /**
328
+ * Base error class for all Mulink errors
329
+ *
330
+ * Follows best practices similar to Apollo Client's error handling.
331
+ * Provides structured error information with error codes and details.
332
+ *
333
+ * @public
334
+ */
327
335
  declare class BridgeError extends Error {
328
336
  readonly code: string;
329
337
  readonly details?: unknown;
330
- constructor(message: string, code: string, details?: unknown);
338
+ readonly timestamp: number;
339
+ readonly cause?: Error;
340
+ constructor(message: string, code: string, details?: unknown, cause?: Error);
341
+ /**
342
+ * Converts the error to a JSON-serializable object
343
+ *
344
+ * @returns JSON representation of the error
345
+ */
346
+ toJSON(): Record<string, unknown>;
347
+ /**
348
+ * Checks if this error is retryable
349
+ *
350
+ * @returns True if the operation that caused this error can be retried
351
+ */
352
+ isRetryable(): boolean;
331
353
  }
354
+ /**
355
+ * Error thrown when configuration validation fails
356
+ *
357
+ * Contains Zod validation errors for detailed feedback.
358
+ */
332
359
  declare class ValidationError extends BridgeError {
333
360
  readonly errors: z.ZodError;
334
- constructor(message: string, errors: z.ZodError);
361
+ constructor(message: string, errors: z.ZodError, cause?: Error);
362
+ /**
363
+ * Gets formatted validation error messages
364
+ *
365
+ * @returns Array of formatted error messages
366
+ */
367
+ getFormattedErrors(): string[];
335
368
  }
369
+ /**
370
+ * Error thrown when OpenAPI schema parsing fails
371
+ *
372
+ * Contains the schema URL that failed to parse.
373
+ */
336
374
  declare class SchemaParseError extends BridgeError {
337
375
  readonly schemaUrl: string;
338
- constructor(message: string, schemaUrl: string);
376
+ constructor(message: string, schemaUrl: string, cause?: Error);
377
+ isRetryable(): boolean;
339
378
  }
379
+ /**
380
+ * Error thrown when code generation fails
381
+ *
382
+ * Contains the file path where generation failed, if applicable.
383
+ */
340
384
  declare class GenerationError extends BridgeError {
341
385
  readonly file?: string;
342
- constructor(message: string, file?: string);
386
+ constructor(message: string, file?: string, cause?: Error);
343
387
  }
344
388
  interface BridgePlugin {
345
389
  name: string;
@@ -403,23 +447,119 @@ interface StreamingResponse<T = any> {
403
447
  controller: AbortController;
404
448
  }
405
449
 
450
+ /**
451
+ * Core class for the Mulink library
452
+ *
453
+ * This class orchestrates the entire code generation process from OpenAPI schemas
454
+ * to production-ready Next.js 16.0.7 code. It follows best practices similar to
455
+ * Apollo Client and other enterprise-grade libraries.
456
+ *
457
+ * @example
458
+ * ```typescript
459
+ * const bridge = new BridgeCore();
460
+ * await bridge.generate(configuration);
461
+ * ```
462
+ *
463
+ * @public
464
+ */
406
465
  declare class BridgeCore {
407
466
  private readonly logger;
408
467
  private readonly schemaParser;
409
468
  private readonly fileManager;
469
+ /**
470
+ * Creates a new instance of BridgeCore
471
+ *
472
+ * Initializes all required dependencies including logger, schema parser, and file manager.
473
+ * All dependencies are readonly to ensure immutability and thread safety.
474
+ */
410
475
  constructor();
476
+ /**
477
+ * Generates type-safe API client code from OpenAPI schema
478
+ *
479
+ * This is the main entry point for code generation. It validates the configuration,
480
+ * parses the OpenAPI schema, generates all necessary files, and writes them to disk.
481
+ *
482
+ * The generated code follows Next.js 16.0.7 best practices including:
483
+ * - Server Actions with type safety
484
+ * - React Query hooks with proper caching
485
+ * - Middleware support
486
+ * - Error handling
487
+ * - Cache tag management
488
+ *
489
+ * @param configuration - The bridge configuration containing schema URL, output directory, and framework settings
490
+ * @returns Promise that resolves when generation is complete
491
+ * @throws {ValidationError} When configuration is invalid
492
+ * @throws {SchemaParseError} When OpenAPI schema cannot be parsed
493
+ * @throws {GenerationError} When code generation fails
494
+ *
495
+ * @example
496
+ * ```typescript
497
+ * const config: BridgeConfiguration = {
498
+ * schema: 'https://api.example.com/openapi.json',
499
+ * outputDir: 'src/generated',
500
+ * framework: { type: 'nextjs', router: 'app', features: {...} },
501
+ * api: { baseUrl: 'https://api.example.com', timeout: 30000, retries: 3 }
502
+ * };
503
+ * await bridge.generate(config);
504
+ * ```
505
+ */
411
506
  generate(configuration: BridgeConfiguration): Promise<void>;
412
507
  private validateConfiguration;
413
508
  private generateFiles;
414
509
  private writeFiles;
415
510
  private logGenerationSummary;
511
+ /**
512
+ * Validates an OpenAPI schema without generating code
513
+ *
514
+ * Useful for checking schema validity before running full generation.
515
+ *
516
+ * @param schemaUrl - URL or file path to the OpenAPI schema
517
+ * @returns Promise resolving to true if schema is valid, false otherwise
518
+ *
519
+ * @example
520
+ * ```typescript
521
+ * const isValid = await bridge.validateSchema('https://api.example.com/openapi.json');
522
+ * if (isValid) {
523
+ * await bridge.generate(config);
524
+ * }
525
+ * ```
526
+ */
416
527
  validateSchema(schemaUrl: string): Promise<boolean>;
528
+ /**
529
+ * Retrieves metadata from an OpenAPI schema
530
+ *
531
+ * Extracts schema metadata including title, version, description, and other
532
+ * OpenAPI document information without parsing the entire schema.
533
+ *
534
+ * @param schemaUrl - URL or file path to the OpenAPI schema
535
+ * @returns Promise resolving to schema metadata
536
+ * @throws {BridgeError} When schema URL is invalid
537
+ * @throws {SchemaParseError} When schema cannot be parsed
538
+ *
539
+ * @example
540
+ * ```typescript
541
+ * const metadata = await bridge.getSchemaInfo('https://api.example.com/openapi.json');
542
+ * console.log(`Schema: ${metadata.title} v${metadata.version}`);
543
+ * ```
544
+ */
417
545
  getSchemaInfo(schemaUrl: string): Promise<ParsedApiSchema['metadata']>;
546
+ /**
547
+ * Clears the internal schema cache
548
+ *
549
+ * Useful when you need to force re-fetching of schemas or during development.
550
+ * The cache is automatically managed, but this method allows manual invalidation.
551
+ *
552
+ * @example
553
+ * ```typescript
554
+ * bridge.clearCache();
555
+ * await bridge.generate(config); // Will fetch fresh schema
556
+ * ```
557
+ */
418
558
  clearCache(): void;
419
559
  }
420
560
 
421
561
  declare class OpenApiSchemaParser {
422
- private schemaCache;
562
+ private readonly schemaCache;
423
563
  parse(schemaUrl: string): Promise<ParsedApiSchema>;
424
564
  private fetchSchema;
425
565
  private parseDocument;
@@ -443,7 +583,7 @@ declare class OpenApiSchemaParser {
443
583
 
444
584
  declare class ConfigurationLoader {
445
585
  load(configPath?: string): Promise<BridgeConfiguration>;
446
- createDefault(framework?: 'nextjs'): Promise<BridgeConfiguration>;
586
+ createDefault(framework?: 'nextjs'): BridgeConfiguration;
447
587
  save(config: BridgeConfiguration, configPath?: string): Promise<void>;
448
588
  }
449
589
 
@@ -498,10 +638,10 @@ interface VersionInfo {
498
638
  }
499
639
  type PackageManager = 'npm' | 'yarn' | 'pnpm' | 'bun' | 'unknown';
500
640
  declare class VersionChecker {
501
- private logger;
502
- private packageName;
503
- private currentVersion;
504
- private cache;
641
+ private readonly logger;
642
+ private readonly packageName;
643
+ private readonly currentVersion;
644
+ private readonly cache;
505
645
  private readonly CACHE_DURATION;
506
646
  constructor(packageName: string, currentVersion: string, logger?: BridgeLogger);
507
647
  /**
@@ -515,7 +655,7 @@ declare class VersionChecker {
515
655
  /**
516
656
  * Get the appropriate upgrade command for the detected package manager
517
657
  */
518
- getUpgradeCommand(versionInfo: VersionInfo): string;
658
+ getUpgradeCommand(_versionInfo: VersionInfo): string;
519
659
  /**
520
660
  * Get a user-friendly update message
521
661
  */
@@ -575,4 +715,4 @@ declare function checkAndNotifyUpdates(options?: {
575
715
  logger?: BridgeLogger;
576
716
  }): Promise<VersionInfo | null>;
577
717
 
578
- export { type ApiConfiguration as A, type BridgeConfiguration as B, ConfigurationLoader as C, type DevelopmentConfiguration as D, type EndpointMetadata as E, FileSystemManager as F, type GenerationContext as G, type HttpMethod as H, GenerationError as I, type ClientConfiguration as J, type RequestConfiguration as K, LogLevel as L, type ClientResponse as M, type StreamingResponse as N, OpenApiSchemaParser as O, type PluginConfiguration as P, type RequestBodyDefinition as R, type SchemaDefinition as S, VersionChecker as V, type GeneratedFile as a, BridgeCore as b, BridgeLogger as c, createBridgeVersionChecker as d, checkAndNotifyUpdates as e, type FrameworkConfiguration as f, type AuthConfiguration as g, type CacheConfiguration as h, type GenerationConfiguration as i, type OpenApiDocument as j, type ParsedApiSchema as k, type ApiEndpointDefinition as l, type ParameterDefinition as m, type ApiResponseDefinition as n, type SecuritySchemeDefinition as o, type ServerDefinition as p, type SchemaMetadata as q, type SecurityRequirement as r, type CacheStrategy as s, type RateLimit as t, type FileMetadata as u, type BridgePlugin as v, type VersionInfo as w, BridgeError as x, ValidationError as y, SchemaParseError as z };
718
+ export { type ApiConfiguration as A, type BridgeConfiguration as B, ConfigurationLoader as C, type DevelopmentConfiguration as D, type EndpointMetadata as E, FileSystemManager as F, type GenerationConfiguration as G, type HttpMethod as H, BridgeError as I, ValidationError as J, SchemaParseError as K, LogLevel as L, GenerationError as M, type VersionInfo as N, OpenApiSchemaParser as O, type PluginConfiguration as P, type RequestBodyDefinition as R, type SchemaDefinition as S, VersionChecker as V, BridgeCore as a, BridgeLogger as b, createBridgeVersionChecker as c, checkAndNotifyUpdates as d, type FrameworkConfiguration as e, type AuthConfiguration as f, type CacheConfiguration as g, type OpenApiDocument as h, type ParsedApiSchema as i, type ApiEndpointDefinition as j, type ParameterDefinition as k, type ApiResponseDefinition as l, type SecuritySchemeDefinition as m, type ServerDefinition as n, type SchemaMetadata as o, type SecurityRequirement as p, type CacheStrategy as q, type RateLimit as r, type GenerationContext as s, type GeneratedFile as t, type FileMetadata as u, type BridgePlugin as v, type ClientConfiguration as w, type RequestConfiguration as x, type ClientResponse as y, type StreamingResponse as z };
@@ -324,22 +324,66 @@ interface FileMetadata {
324
324
  imports: string[];
325
325
  dependencies: string[];
326
326
  }
327
+ /**
328
+ * Base error class for all Mulink errors
329
+ *
330
+ * Follows best practices similar to Apollo Client's error handling.
331
+ * Provides structured error information with error codes and details.
332
+ *
333
+ * @public
334
+ */
327
335
  declare class BridgeError extends Error {
328
336
  readonly code: string;
329
337
  readonly details?: unknown;
330
- constructor(message: string, code: string, details?: unknown);
338
+ readonly timestamp: number;
339
+ readonly cause?: Error;
340
+ constructor(message: string, code: string, details?: unknown, cause?: Error);
341
+ /**
342
+ * Converts the error to a JSON-serializable object
343
+ *
344
+ * @returns JSON representation of the error
345
+ */
346
+ toJSON(): Record<string, unknown>;
347
+ /**
348
+ * Checks if this error is retryable
349
+ *
350
+ * @returns True if the operation that caused this error can be retried
351
+ */
352
+ isRetryable(): boolean;
331
353
  }
354
+ /**
355
+ * Error thrown when configuration validation fails
356
+ *
357
+ * Contains Zod validation errors for detailed feedback.
358
+ */
332
359
  declare class ValidationError extends BridgeError {
333
360
  readonly errors: z.ZodError;
334
- constructor(message: string, errors: z.ZodError);
361
+ constructor(message: string, errors: z.ZodError, cause?: Error);
362
+ /**
363
+ * Gets formatted validation error messages
364
+ *
365
+ * @returns Array of formatted error messages
366
+ */
367
+ getFormattedErrors(): string[];
335
368
  }
369
+ /**
370
+ * Error thrown when OpenAPI schema parsing fails
371
+ *
372
+ * Contains the schema URL that failed to parse.
373
+ */
336
374
  declare class SchemaParseError extends BridgeError {
337
375
  readonly schemaUrl: string;
338
- constructor(message: string, schemaUrl: string);
376
+ constructor(message: string, schemaUrl: string, cause?: Error);
377
+ isRetryable(): boolean;
339
378
  }
379
+ /**
380
+ * Error thrown when code generation fails
381
+ *
382
+ * Contains the file path where generation failed, if applicable.
383
+ */
340
384
  declare class GenerationError extends BridgeError {
341
385
  readonly file?: string;
342
- constructor(message: string, file?: string);
386
+ constructor(message: string, file?: string, cause?: Error);
343
387
  }
344
388
  interface BridgePlugin {
345
389
  name: string;
@@ -403,23 +447,119 @@ interface StreamingResponse<T = any> {
403
447
  controller: AbortController;
404
448
  }
405
449
 
450
+ /**
451
+ * Core class for the Mulink library
452
+ *
453
+ * This class orchestrates the entire code generation process from OpenAPI schemas
454
+ * to production-ready Next.js 16.0.7 code. It follows best practices similar to
455
+ * Apollo Client and other enterprise-grade libraries.
456
+ *
457
+ * @example
458
+ * ```typescript
459
+ * const bridge = new BridgeCore();
460
+ * await bridge.generate(configuration);
461
+ * ```
462
+ *
463
+ * @public
464
+ */
406
465
  declare class BridgeCore {
407
466
  private readonly logger;
408
467
  private readonly schemaParser;
409
468
  private readonly fileManager;
469
+ /**
470
+ * Creates a new instance of BridgeCore
471
+ *
472
+ * Initializes all required dependencies including logger, schema parser, and file manager.
473
+ * All dependencies are readonly to ensure immutability and thread safety.
474
+ */
410
475
  constructor();
476
+ /**
477
+ * Generates type-safe API client code from OpenAPI schema
478
+ *
479
+ * This is the main entry point for code generation. It validates the configuration,
480
+ * parses the OpenAPI schema, generates all necessary files, and writes them to disk.
481
+ *
482
+ * The generated code follows Next.js 16.0.7 best practices including:
483
+ * - Server Actions with type safety
484
+ * - React Query hooks with proper caching
485
+ * - Middleware support
486
+ * - Error handling
487
+ * - Cache tag management
488
+ *
489
+ * @param configuration - The bridge configuration containing schema URL, output directory, and framework settings
490
+ * @returns Promise that resolves when generation is complete
491
+ * @throws {ValidationError} When configuration is invalid
492
+ * @throws {SchemaParseError} When OpenAPI schema cannot be parsed
493
+ * @throws {GenerationError} When code generation fails
494
+ *
495
+ * @example
496
+ * ```typescript
497
+ * const config: BridgeConfiguration = {
498
+ * schema: 'https://api.example.com/openapi.json',
499
+ * outputDir: 'src/generated',
500
+ * framework: { type: 'nextjs', router: 'app', features: {...} },
501
+ * api: { baseUrl: 'https://api.example.com', timeout: 30000, retries: 3 }
502
+ * };
503
+ * await bridge.generate(config);
504
+ * ```
505
+ */
411
506
  generate(configuration: BridgeConfiguration): Promise<void>;
412
507
  private validateConfiguration;
413
508
  private generateFiles;
414
509
  private writeFiles;
415
510
  private logGenerationSummary;
511
+ /**
512
+ * Validates an OpenAPI schema without generating code
513
+ *
514
+ * Useful for checking schema validity before running full generation.
515
+ *
516
+ * @param schemaUrl - URL or file path to the OpenAPI schema
517
+ * @returns Promise resolving to true if schema is valid, false otherwise
518
+ *
519
+ * @example
520
+ * ```typescript
521
+ * const isValid = await bridge.validateSchema('https://api.example.com/openapi.json');
522
+ * if (isValid) {
523
+ * await bridge.generate(config);
524
+ * }
525
+ * ```
526
+ */
416
527
  validateSchema(schemaUrl: string): Promise<boolean>;
528
+ /**
529
+ * Retrieves metadata from an OpenAPI schema
530
+ *
531
+ * Extracts schema metadata including title, version, description, and other
532
+ * OpenAPI document information without parsing the entire schema.
533
+ *
534
+ * @param schemaUrl - URL or file path to the OpenAPI schema
535
+ * @returns Promise resolving to schema metadata
536
+ * @throws {BridgeError} When schema URL is invalid
537
+ * @throws {SchemaParseError} When schema cannot be parsed
538
+ *
539
+ * @example
540
+ * ```typescript
541
+ * const metadata = await bridge.getSchemaInfo('https://api.example.com/openapi.json');
542
+ * console.log(`Schema: ${metadata.title} v${metadata.version}`);
543
+ * ```
544
+ */
417
545
  getSchemaInfo(schemaUrl: string): Promise<ParsedApiSchema['metadata']>;
546
+ /**
547
+ * Clears the internal schema cache
548
+ *
549
+ * Useful when you need to force re-fetching of schemas or during development.
550
+ * The cache is automatically managed, but this method allows manual invalidation.
551
+ *
552
+ * @example
553
+ * ```typescript
554
+ * bridge.clearCache();
555
+ * await bridge.generate(config); // Will fetch fresh schema
556
+ * ```
557
+ */
418
558
  clearCache(): void;
419
559
  }
420
560
 
421
561
  declare class OpenApiSchemaParser {
422
- private schemaCache;
562
+ private readonly schemaCache;
423
563
  parse(schemaUrl: string): Promise<ParsedApiSchema>;
424
564
  private fetchSchema;
425
565
  private parseDocument;
@@ -443,7 +583,7 @@ declare class OpenApiSchemaParser {
443
583
 
444
584
  declare class ConfigurationLoader {
445
585
  load(configPath?: string): Promise<BridgeConfiguration>;
446
- createDefault(framework?: 'nextjs'): Promise<BridgeConfiguration>;
586
+ createDefault(framework?: 'nextjs'): BridgeConfiguration;
447
587
  save(config: BridgeConfiguration, configPath?: string): Promise<void>;
448
588
  }
449
589
 
@@ -498,10 +638,10 @@ interface VersionInfo {
498
638
  }
499
639
  type PackageManager = 'npm' | 'yarn' | 'pnpm' | 'bun' | 'unknown';
500
640
  declare class VersionChecker {
501
- private logger;
502
- private packageName;
503
- private currentVersion;
504
- private cache;
641
+ private readonly logger;
642
+ private readonly packageName;
643
+ private readonly currentVersion;
644
+ private readonly cache;
505
645
  private readonly CACHE_DURATION;
506
646
  constructor(packageName: string, currentVersion: string, logger?: BridgeLogger);
507
647
  /**
@@ -515,7 +655,7 @@ declare class VersionChecker {
515
655
  /**
516
656
  * Get the appropriate upgrade command for the detected package manager
517
657
  */
518
- getUpgradeCommand(versionInfo: VersionInfo): string;
658
+ getUpgradeCommand(_versionInfo: VersionInfo): string;
519
659
  /**
520
660
  * Get a user-friendly update message
521
661
  */
@@ -575,4 +715,4 @@ declare function checkAndNotifyUpdates(options?: {
575
715
  logger?: BridgeLogger;
576
716
  }): Promise<VersionInfo | null>;
577
717
 
578
- export { type ApiConfiguration as A, type BridgeConfiguration as B, ConfigurationLoader as C, type DevelopmentConfiguration as D, type EndpointMetadata as E, FileSystemManager as F, type GenerationContext as G, type HttpMethod as H, GenerationError as I, type ClientConfiguration as J, type RequestConfiguration as K, LogLevel as L, type ClientResponse as M, type StreamingResponse as N, OpenApiSchemaParser as O, type PluginConfiguration as P, type RequestBodyDefinition as R, type SchemaDefinition as S, VersionChecker as V, type GeneratedFile as a, BridgeCore as b, BridgeLogger as c, createBridgeVersionChecker as d, checkAndNotifyUpdates as e, type FrameworkConfiguration as f, type AuthConfiguration as g, type CacheConfiguration as h, type GenerationConfiguration as i, type OpenApiDocument as j, type ParsedApiSchema as k, type ApiEndpointDefinition as l, type ParameterDefinition as m, type ApiResponseDefinition as n, type SecuritySchemeDefinition as o, type ServerDefinition as p, type SchemaMetadata as q, type SecurityRequirement as r, type CacheStrategy as s, type RateLimit as t, type FileMetadata as u, type BridgePlugin as v, type VersionInfo as w, BridgeError as x, ValidationError as y, SchemaParseError as z };
718
+ export { type ApiConfiguration as A, type BridgeConfiguration as B, ConfigurationLoader as C, type DevelopmentConfiguration as D, type EndpointMetadata as E, FileSystemManager as F, type GenerationConfiguration as G, type HttpMethod as H, BridgeError as I, ValidationError as J, SchemaParseError as K, LogLevel as L, GenerationError as M, type VersionInfo as N, OpenApiSchemaParser as O, type PluginConfiguration as P, type RequestBodyDefinition as R, type SchemaDefinition as S, VersionChecker as V, BridgeCore as a, BridgeLogger as b, createBridgeVersionChecker as c, checkAndNotifyUpdates as d, type FrameworkConfiguration as e, type AuthConfiguration as f, type CacheConfiguration as g, type OpenApiDocument as h, type ParsedApiSchema as i, type ApiEndpointDefinition as j, type ParameterDefinition as k, type ApiResponseDefinition as l, type SecuritySchemeDefinition as m, type ServerDefinition as n, type SchemaMetadata as o, type SecurityRequirement as p, type CacheStrategy as q, type RateLimit as r, type GenerationContext as s, type GeneratedFile as t, type FileMetadata as u, type BridgePlugin as v, type ClientConfiguration as w, type RequestConfiguration as x, type ClientResponse as y, type StreamingResponse as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mulink",
3
- "version": "1.1.8",
3
+ "version": "1.1.9",
4
4
  "description": "Universal type-safe API integration library for modern web applications",
5
5
  "type": "module",
6
6
  "exports": {
@@ -30,7 +30,7 @@
30
30
  "scripts": {
31
31
  "build": "tsup",
32
32
  "dev": "tsup --watch",
33
- "test": "vitest",
33
+ "test": "vitest run",
34
34
  "test:ui": "vitest --ui",
35
35
  "test:coverage": "vitest --coverage",
36
36
  "test:watch": "vitest --watch",