@honestjs/rpc-plugin 1.5.0 → 1.6.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.
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { RouteInfo, ParameterMetadata, IPlugin, Application } from 'honestjs';
2
2
  import { Hono } from 'hono';
3
- import { Project, Type } from 'ts-morph';
3
+ import { ClassDeclaration, Project, Type } from 'ts-morph';
4
4
 
5
5
  /**
6
6
  * Parameter metadata with enhanced type information
@@ -49,6 +49,14 @@ interface GeneratedClientInfo {
49
49
  readonly outputFiles?: readonly string[];
50
50
  readonly generatedAt: string;
51
51
  }
52
+ /**
53
+ * Serialized artifact produced by RPCPlugin and published to application context.
54
+ */
55
+ interface RpcArtifact {
56
+ readonly artifactVersion: string;
57
+ readonly routes: readonly ExtendedRouteInfo[];
58
+ readonly schemas: readonly SchemaInfo[];
59
+ }
52
60
 
53
61
  /**
54
62
  * Clean separation of concerns for request options
@@ -90,6 +98,17 @@ interface RPCGenerator {
90
98
  generate(context: RPCGeneratorContext): Promise<GeneratedClientInfo>;
91
99
  }
92
100
 
101
+ type RPCMode = 'strict' | 'best-effort';
102
+ type RPCLogLevel = 'silent' | 'error' | 'warn' | 'info' | 'debug';
103
+ interface RPCDiagnostics {
104
+ readonly generatedAt: string;
105
+ readonly mode: RPCMode;
106
+ readonly dryRun: boolean;
107
+ readonly cache: 'hit' | 'miss' | 'bypass';
108
+ readonly routesCount: number;
109
+ readonly schemasCount: number;
110
+ readonly warnings: readonly string[];
111
+ }
93
112
  /**
94
113
  * Configuration options for the RPCPlugin
95
114
  */
@@ -99,6 +118,11 @@ interface RPCPluginOptions {
99
118
  readonly outputDir?: string;
100
119
  readonly generateOnInit?: boolean;
101
120
  readonly generators?: readonly RPCGenerator[];
121
+ readonly mode?: RPCMode;
122
+ readonly logLevel?: RPCLogLevel;
123
+ readonly customClassMatcher?: (classDeclaration: ClassDeclaration) => boolean;
124
+ readonly failOnSchemaError?: boolean;
125
+ readonly failOnRouteAnalysisWarning?: boolean;
102
126
  readonly context?: {
103
127
  readonly namespace?: string;
104
128
  readonly keys?: {
@@ -116,6 +140,11 @@ declare class RPCPlugin implements IPlugin {
116
140
  private readonly generateOnInit;
117
141
  private readonly contextNamespace;
118
142
  private readonly contextArtifactKey;
143
+ private readonly mode;
144
+ private readonly logLevel;
145
+ private readonly failOnSchemaError;
146
+ private readonly failOnRouteAnalysisWarning;
147
+ private readonly customClassMatcher?;
119
148
  private readonly routeAnalyzer;
120
149
  private readonly schemaGenerator;
121
150
  private readonly generators;
@@ -123,6 +152,7 @@ declare class RPCPlugin implements IPlugin {
123
152
  private analyzedRoutes;
124
153
  private analyzedSchemas;
125
154
  private generatedInfos;
155
+ private diagnostics;
126
156
  private app;
127
157
  constructor(options?: RPCPluginOptions);
128
158
  /**
@@ -141,7 +171,11 @@ declare class RPCPlugin implements IPlugin {
141
171
  * Manually trigger analysis (useful for testing or re-generation).
142
172
  * Defaults to force=true to bypass cache; pass false to use caching.
143
173
  */
144
- analyze(force?: boolean): Promise<void>;
174
+ analyze(force: boolean): Promise<void>;
175
+ analyze(options: {
176
+ force?: boolean;
177
+ dryRun?: boolean;
178
+ }): Promise<void>;
145
179
  /**
146
180
  * Get the analyzed routes
147
181
  */
@@ -158,12 +192,15 @@ declare class RPCPlugin implements IPlugin {
158
192
  * Get all generation infos
159
193
  */
160
194
  getGenerationInfos(): readonly GeneratedClientInfo[];
195
+ getDiagnostics(): RPCDiagnostics | null;
161
196
  /**
162
197
  * Checks whether expected output files exist on disk
163
198
  */
164
199
  private outputFilesExist;
165
200
  private getArtifactPath;
201
+ private getDiagnosticsPath;
166
202
  private writeArtifactToDisk;
203
+ private writeDiagnosticsToDisk;
167
204
  private loadArtifactFromDisk;
168
205
  private runGenerators;
169
206
  private hasTypeScriptGenerator;
@@ -181,6 +218,9 @@ declare class RPCPlugin implements IPlugin {
181
218
  * Logs an error with the plugin prefix
182
219
  */
183
220
  private logError;
221
+ private logWarn;
222
+ private logDebug;
223
+ private canLog;
184
224
  }
185
225
 
186
226
  /**
@@ -218,20 +258,25 @@ declare class TypeScriptClientGenerator implements RPCGenerator {
218
258
  * Generates schema types from integrated schema generation.
219
259
  */
220
260
  private generateSchemaTypes;
221
- /**
222
- * Groups routes by controller for better organization.
223
- */
224
- private groupRoutesByController;
225
261
  /**
226
262
  * Analyzes route parameters to determine their types and usage.
227
263
  */
228
264
  private analyzeRouteParameters;
229
265
  }
230
266
 
267
+ interface RouteAnalyzerOptions {
268
+ readonly customClassMatcher?: (classDeclaration: ClassDeclaration) => boolean;
269
+ readonly onWarn?: (message: string, details?: unknown) => void;
270
+ }
231
271
  /**
232
272
  * Service for analyzing controller methods and extracting type information
233
273
  */
234
274
  declare class RouteAnalyzerService {
275
+ private readonly customClassMatcher?;
276
+ private readonly onWarn?;
277
+ private warnings;
278
+ constructor(options?: RouteAnalyzerOptions);
279
+ getWarnings(): readonly string[];
235
280
  /**
236
281
  * Analyzes controller methods to extract type information
237
282
  */
@@ -240,6 +285,7 @@ declare class RouteAnalyzerService {
240
285
  * Finds controller classes in the project
241
286
  */
242
287
  private findControllerClasses;
288
+ private isControllerClass;
243
289
  /**
244
290
  * Processes all routes and extracts type information
245
291
  */
@@ -258,13 +304,21 @@ declare class RouteAnalyzerService {
258
304
  private getParametersWithTypes;
259
305
  }
260
306
 
307
+ interface SchemaGeneratorOptions {
308
+ readonly failOnSchemaError?: boolean;
309
+ readonly onWarn?: (message: string, details?: unknown) => void;
310
+ }
261
311
  /**
262
312
  * Service for generating JSON schemas from TypeScript types used in controllers
263
313
  */
264
314
  declare class SchemaGeneratorService {
265
315
  private readonly controllerPattern;
266
316
  private readonly tsConfigPath;
267
- constructor(controllerPattern: string, tsConfigPath: string);
317
+ private readonly failOnSchemaError;
318
+ private readonly onWarn?;
319
+ private warnings;
320
+ constructor(controllerPattern: string, tsConfigPath: string, options?: SchemaGeneratorOptions);
321
+ getWarnings(): readonly string[];
268
322
  /**
269
323
  * Generates JSON schemas from types used in controllers
270
324
  */
@@ -307,6 +361,10 @@ declare function readChecksum(outputDir: string): ChecksumData | null;
307
361
  */
308
362
  declare function writeChecksum(outputDir: string, data: ChecksumData): Promise<void>;
309
363
 
364
+ declare const RPC_ARTIFACT_VERSION = "1";
365
+ declare function isRpcArtifact(value: unknown): value is RpcArtifact;
366
+ declare function assertRpcArtifact(value: unknown): asserts value is RpcArtifact;
367
+
310
368
  /** Minimal route shape needed to build the full API path (prefix + version + route + path). */
311
369
  type RoutePathInput = Pick<ExtendedRouteInfo, 'prefix' | 'version' | 'route' | 'path'>;
312
370
  /**
@@ -349,6 +407,9 @@ declare const DEFAULT_OPTIONS: {
349
407
  readonly tsConfigPath: "tsconfig.json";
350
408
  readonly outputDir: "./generated/rpc";
351
409
  readonly generateOnInit: true;
410
+ readonly mode: "best-effort";
411
+ readonly logLevel: "info";
412
+ readonly artifactVersion: "1";
352
413
  readonly context: {
353
414
  readonly namespace: "rpc";
354
415
  readonly keys: {
@@ -373,4 +434,4 @@ declare const BUILTIN_TYPES: Set<string>;
373
434
  */
374
435
  declare const GENERIC_TYPES: Set<string>;
375
436
 
376
- export { ApiError, BUILTIN_TYPES, BUILTIN_UTILITY_TYPES, type ChecksumData, type ControllerGroups, DEFAULT_OPTIONS, type ExtendedRouteInfo, type FetchFunction, GENERIC_TYPES, type GeneratedClientInfo, LOG_PREFIX, type ParameterMetadataWithType, RPCPlugin, type RPCPluginOptions, type RequestOptions, RouteAnalyzerService, type RouteParameter, type RoutePathInput, SchemaGeneratorService, type SchemaInfo, TypeScriptClientGenerator, buildFullApiPath, buildFullPath, camelCase, computeHash, extractNamedType, generateTypeScriptInterface, mapJsonSchemaTypeToTypeScript, readChecksum, safeToString, writeChecksum };
437
+ export { ApiError, BUILTIN_TYPES, BUILTIN_UTILITY_TYPES, type ChecksumData, type ControllerGroups, DEFAULT_OPTIONS, type ExtendedRouteInfo, type FetchFunction, GENERIC_TYPES, type GeneratedClientInfo, LOG_PREFIX, type ParameterMetadataWithType, type RPCGenerator, type RPCGeneratorContext, RPCPlugin, type RPCPluginOptions, RPC_ARTIFACT_VERSION, type RequestOptions, RouteAnalyzerService, type RouteParameter, type RoutePathInput, SchemaGeneratorService, type SchemaInfo, TypeScriptClientGenerator, assertRpcArtifact, buildFullApiPath, buildFullPath, camelCase, computeHash, extractNamedType, generateTypeScriptInterface, isRpcArtifact, mapJsonSchemaTypeToTypeScript, readChecksum, safeToString, writeChecksum };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { RouteInfo, ParameterMetadata, IPlugin, Application } from 'honestjs';
2
2
  import { Hono } from 'hono';
3
- import { Project, Type } from 'ts-morph';
3
+ import { ClassDeclaration, Project, Type } from 'ts-morph';
4
4
 
5
5
  /**
6
6
  * Parameter metadata with enhanced type information
@@ -49,6 +49,14 @@ interface GeneratedClientInfo {
49
49
  readonly outputFiles?: readonly string[];
50
50
  readonly generatedAt: string;
51
51
  }
52
+ /**
53
+ * Serialized artifact produced by RPCPlugin and published to application context.
54
+ */
55
+ interface RpcArtifact {
56
+ readonly artifactVersion: string;
57
+ readonly routes: readonly ExtendedRouteInfo[];
58
+ readonly schemas: readonly SchemaInfo[];
59
+ }
52
60
 
53
61
  /**
54
62
  * Clean separation of concerns for request options
@@ -90,6 +98,17 @@ interface RPCGenerator {
90
98
  generate(context: RPCGeneratorContext): Promise<GeneratedClientInfo>;
91
99
  }
92
100
 
101
+ type RPCMode = 'strict' | 'best-effort';
102
+ type RPCLogLevel = 'silent' | 'error' | 'warn' | 'info' | 'debug';
103
+ interface RPCDiagnostics {
104
+ readonly generatedAt: string;
105
+ readonly mode: RPCMode;
106
+ readonly dryRun: boolean;
107
+ readonly cache: 'hit' | 'miss' | 'bypass';
108
+ readonly routesCount: number;
109
+ readonly schemasCount: number;
110
+ readonly warnings: readonly string[];
111
+ }
93
112
  /**
94
113
  * Configuration options for the RPCPlugin
95
114
  */
@@ -99,6 +118,11 @@ interface RPCPluginOptions {
99
118
  readonly outputDir?: string;
100
119
  readonly generateOnInit?: boolean;
101
120
  readonly generators?: readonly RPCGenerator[];
121
+ readonly mode?: RPCMode;
122
+ readonly logLevel?: RPCLogLevel;
123
+ readonly customClassMatcher?: (classDeclaration: ClassDeclaration) => boolean;
124
+ readonly failOnSchemaError?: boolean;
125
+ readonly failOnRouteAnalysisWarning?: boolean;
102
126
  readonly context?: {
103
127
  readonly namespace?: string;
104
128
  readonly keys?: {
@@ -116,6 +140,11 @@ declare class RPCPlugin implements IPlugin {
116
140
  private readonly generateOnInit;
117
141
  private readonly contextNamespace;
118
142
  private readonly contextArtifactKey;
143
+ private readonly mode;
144
+ private readonly logLevel;
145
+ private readonly failOnSchemaError;
146
+ private readonly failOnRouteAnalysisWarning;
147
+ private readonly customClassMatcher?;
119
148
  private readonly routeAnalyzer;
120
149
  private readonly schemaGenerator;
121
150
  private readonly generators;
@@ -123,6 +152,7 @@ declare class RPCPlugin implements IPlugin {
123
152
  private analyzedRoutes;
124
153
  private analyzedSchemas;
125
154
  private generatedInfos;
155
+ private diagnostics;
126
156
  private app;
127
157
  constructor(options?: RPCPluginOptions);
128
158
  /**
@@ -141,7 +171,11 @@ declare class RPCPlugin implements IPlugin {
141
171
  * Manually trigger analysis (useful for testing or re-generation).
142
172
  * Defaults to force=true to bypass cache; pass false to use caching.
143
173
  */
144
- analyze(force?: boolean): Promise<void>;
174
+ analyze(force: boolean): Promise<void>;
175
+ analyze(options: {
176
+ force?: boolean;
177
+ dryRun?: boolean;
178
+ }): Promise<void>;
145
179
  /**
146
180
  * Get the analyzed routes
147
181
  */
@@ -158,12 +192,15 @@ declare class RPCPlugin implements IPlugin {
158
192
  * Get all generation infos
159
193
  */
160
194
  getGenerationInfos(): readonly GeneratedClientInfo[];
195
+ getDiagnostics(): RPCDiagnostics | null;
161
196
  /**
162
197
  * Checks whether expected output files exist on disk
163
198
  */
164
199
  private outputFilesExist;
165
200
  private getArtifactPath;
201
+ private getDiagnosticsPath;
166
202
  private writeArtifactToDisk;
203
+ private writeDiagnosticsToDisk;
167
204
  private loadArtifactFromDisk;
168
205
  private runGenerators;
169
206
  private hasTypeScriptGenerator;
@@ -181,6 +218,9 @@ declare class RPCPlugin implements IPlugin {
181
218
  * Logs an error with the plugin prefix
182
219
  */
183
220
  private logError;
221
+ private logWarn;
222
+ private logDebug;
223
+ private canLog;
184
224
  }
185
225
 
186
226
  /**
@@ -218,20 +258,25 @@ declare class TypeScriptClientGenerator implements RPCGenerator {
218
258
  * Generates schema types from integrated schema generation.
219
259
  */
220
260
  private generateSchemaTypes;
221
- /**
222
- * Groups routes by controller for better organization.
223
- */
224
- private groupRoutesByController;
225
261
  /**
226
262
  * Analyzes route parameters to determine their types and usage.
227
263
  */
228
264
  private analyzeRouteParameters;
229
265
  }
230
266
 
267
+ interface RouteAnalyzerOptions {
268
+ readonly customClassMatcher?: (classDeclaration: ClassDeclaration) => boolean;
269
+ readonly onWarn?: (message: string, details?: unknown) => void;
270
+ }
231
271
  /**
232
272
  * Service for analyzing controller methods and extracting type information
233
273
  */
234
274
  declare class RouteAnalyzerService {
275
+ private readonly customClassMatcher?;
276
+ private readonly onWarn?;
277
+ private warnings;
278
+ constructor(options?: RouteAnalyzerOptions);
279
+ getWarnings(): readonly string[];
235
280
  /**
236
281
  * Analyzes controller methods to extract type information
237
282
  */
@@ -240,6 +285,7 @@ declare class RouteAnalyzerService {
240
285
  * Finds controller classes in the project
241
286
  */
242
287
  private findControllerClasses;
288
+ private isControllerClass;
243
289
  /**
244
290
  * Processes all routes and extracts type information
245
291
  */
@@ -258,13 +304,21 @@ declare class RouteAnalyzerService {
258
304
  private getParametersWithTypes;
259
305
  }
260
306
 
307
+ interface SchemaGeneratorOptions {
308
+ readonly failOnSchemaError?: boolean;
309
+ readonly onWarn?: (message: string, details?: unknown) => void;
310
+ }
261
311
  /**
262
312
  * Service for generating JSON schemas from TypeScript types used in controllers
263
313
  */
264
314
  declare class SchemaGeneratorService {
265
315
  private readonly controllerPattern;
266
316
  private readonly tsConfigPath;
267
- constructor(controllerPattern: string, tsConfigPath: string);
317
+ private readonly failOnSchemaError;
318
+ private readonly onWarn?;
319
+ private warnings;
320
+ constructor(controllerPattern: string, tsConfigPath: string, options?: SchemaGeneratorOptions);
321
+ getWarnings(): readonly string[];
268
322
  /**
269
323
  * Generates JSON schemas from types used in controllers
270
324
  */
@@ -307,6 +361,10 @@ declare function readChecksum(outputDir: string): ChecksumData | null;
307
361
  */
308
362
  declare function writeChecksum(outputDir: string, data: ChecksumData): Promise<void>;
309
363
 
364
+ declare const RPC_ARTIFACT_VERSION = "1";
365
+ declare function isRpcArtifact(value: unknown): value is RpcArtifact;
366
+ declare function assertRpcArtifact(value: unknown): asserts value is RpcArtifact;
367
+
310
368
  /** Minimal route shape needed to build the full API path (prefix + version + route + path). */
311
369
  type RoutePathInput = Pick<ExtendedRouteInfo, 'prefix' | 'version' | 'route' | 'path'>;
312
370
  /**
@@ -349,6 +407,9 @@ declare const DEFAULT_OPTIONS: {
349
407
  readonly tsConfigPath: "tsconfig.json";
350
408
  readonly outputDir: "./generated/rpc";
351
409
  readonly generateOnInit: true;
410
+ readonly mode: "best-effort";
411
+ readonly logLevel: "info";
412
+ readonly artifactVersion: "1";
352
413
  readonly context: {
353
414
  readonly namespace: "rpc";
354
415
  readonly keys: {
@@ -373,4 +434,4 @@ declare const BUILTIN_TYPES: Set<string>;
373
434
  */
374
435
  declare const GENERIC_TYPES: Set<string>;
375
436
 
376
- export { ApiError, BUILTIN_TYPES, BUILTIN_UTILITY_TYPES, type ChecksumData, type ControllerGroups, DEFAULT_OPTIONS, type ExtendedRouteInfo, type FetchFunction, GENERIC_TYPES, type GeneratedClientInfo, LOG_PREFIX, type ParameterMetadataWithType, RPCPlugin, type RPCPluginOptions, type RequestOptions, RouteAnalyzerService, type RouteParameter, type RoutePathInput, SchemaGeneratorService, type SchemaInfo, TypeScriptClientGenerator, buildFullApiPath, buildFullPath, camelCase, computeHash, extractNamedType, generateTypeScriptInterface, mapJsonSchemaTypeToTypeScript, readChecksum, safeToString, writeChecksum };
437
+ export { ApiError, BUILTIN_TYPES, BUILTIN_UTILITY_TYPES, type ChecksumData, type ControllerGroups, DEFAULT_OPTIONS, type ExtendedRouteInfo, type FetchFunction, GENERIC_TYPES, type GeneratedClientInfo, LOG_PREFIX, type ParameterMetadataWithType, type RPCGenerator, type RPCGeneratorContext, RPCPlugin, type RPCPluginOptions, RPC_ARTIFACT_VERSION, type RequestOptions, RouteAnalyzerService, type RouteParameter, type RoutePathInput, SchemaGeneratorService, type SchemaInfo, TypeScriptClientGenerator, assertRpcArtifact, buildFullApiPath, buildFullPath, camelCase, computeHash, extractNamedType, generateTypeScriptInterface, isRpcArtifact, mapJsonSchemaTypeToTypeScript, readChecksum, safeToString, writeChecksum };