@honestjs/rpc-plugin 1.5.0 → 1.6.1
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/README.md +31 -17
- package/dist/index.d.mts +69 -8
- package/dist/index.d.ts +69 -8
- package/dist/index.js +237 -64
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +234 -64
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -36,6 +36,11 @@ interface RPCPluginOptions {
|
|
|
36
36
|
readonly outputDir?: string // Output directory for generated files (default: './generated/rpc')
|
|
37
37
|
readonly generateOnInit?: boolean // Generate files on initialization (default: true)
|
|
38
38
|
readonly generators?: readonly RPCGenerator[] // Optional list of generators to execute
|
|
39
|
+
readonly mode?: 'strict' | 'best-effort' // strict fails on warnings/fallbacks
|
|
40
|
+
readonly logLevel?: 'silent' | 'error' | 'warn' | 'info' | 'debug' // default: info
|
|
41
|
+
readonly customClassMatcher?: (classDeclaration: ClassDeclaration) => boolean // optional override; default discovery uses decorators
|
|
42
|
+
readonly failOnSchemaError?: boolean // default true in strict mode
|
|
43
|
+
readonly failOnRouteAnalysisWarning?: boolean // default true in strict mode
|
|
39
44
|
readonly context?: {
|
|
40
45
|
readonly namespace?: string // Default: 'rpc'
|
|
41
46
|
readonly keys?: {
|
|
@@ -65,12 +70,14 @@ After analysis, RPC plugin publishes this artifact to the application context:
|
|
|
65
70
|
|
|
66
71
|
```typescript
|
|
67
72
|
type RpcArtifact = {
|
|
73
|
+
artifactVersion: string
|
|
68
74
|
routes: ExtendedRouteInfo[]
|
|
69
75
|
schemas: SchemaInfo[]
|
|
70
76
|
}
|
|
71
77
|
```
|
|
72
78
|
|
|
73
|
-
Default key is `'rpc.artifact'` (from `context.namespace + '.' + context.keys.artifact`). This enables direct
|
|
79
|
+
Default key is `'rpc.artifact'` (from `context.namespace + '.' + context.keys.artifact`). This enables direct
|
|
80
|
+
integration with API docs:
|
|
74
81
|
|
|
75
82
|
```typescript
|
|
76
83
|
import { ApiDocsPlugin } from '@honestjs/api-docs-plugin'
|
|
@@ -80,15 +87,18 @@ const { hono } = await Application.create(AppModule, {
|
|
|
80
87
|
})
|
|
81
88
|
```
|
|
82
89
|
|
|
90
|
+
`artifactVersion` is currently `"1"` and is used for compatibility checks.
|
|
91
|
+
|
|
83
92
|
## What It Generates
|
|
84
93
|
|
|
85
94
|
The plugin generates files in the output directory (default: `./generated/rpc`):
|
|
86
95
|
|
|
87
|
-
| File
|
|
88
|
-
|
|
|
89
|
-
| `client.ts`
|
|
90
|
-
| `.rpc-checksum`
|
|
91
|
-
| `rpc-artifact.json`
|
|
96
|
+
| File | Description | When generated |
|
|
97
|
+
| ---------------------- | ---------------------------------------------------------------------- | ------------------------------ |
|
|
98
|
+
| `client.ts` | Type-safe RPC client with all DTOs | When TypeScript generator runs |
|
|
99
|
+
| `.rpc-checksum` | Hash of source files for incremental caching | Always |
|
|
100
|
+
| `rpc-artifact.json` | Serialized routes/schemas artifact for cache-backed context publishing | Always |
|
|
101
|
+
| `rpc-diagnostics.json` | Diagnostics report (mode, warnings, cache status) | Always |
|
|
92
102
|
|
|
93
103
|
### TypeScript RPC Client (`client.ts`)
|
|
94
104
|
|
|
@@ -228,24 +238,25 @@ expect(mockFetch).toHaveBeenCalledWith('http://test.com/api/v1/users/123', expec
|
|
|
228
238
|
|
|
229
239
|
## Hash-based Caching
|
|
230
240
|
|
|
231
|
-
On startup the plugin hashes all controller source files (SHA-256) and stores the checksum in `.rpc-checksum` inside the
|
|
241
|
+
On startup the plugin hashes all controller source files (SHA-256) and stores the checksum in `.rpc-checksum` inside the
|
|
242
|
+
output directory. On subsequent runs, if the hash matches and the expected output files already exist, the expensive
|
|
243
|
+
analysis and generation pipeline is skipped entirely. This significantly reduces startup time in large projects.
|
|
232
244
|
|
|
233
245
|
Caching is automatic and requires no configuration. To force regeneration:
|
|
234
246
|
|
|
235
247
|
```typescript
|
|
236
|
-
// Manual call — defaults to force=true, always regenerates
|
|
237
|
-
await rpcPlugin.analyze()
|
|
238
|
-
|
|
239
248
|
// Explicit cache bypass
|
|
240
|
-
await rpcPlugin.analyze(true)
|
|
249
|
+
await rpcPlugin.analyze({ force: true })
|
|
241
250
|
|
|
242
251
|
// Respect the cache (same behavior as automatic startup)
|
|
243
|
-
await rpcPlugin.analyze(false)
|
|
252
|
+
await rpcPlugin.analyze({ force: false })
|
|
244
253
|
```
|
|
245
254
|
|
|
246
255
|
You can also delete `.rpc-checksum` from the output directory to clear the cache.
|
|
247
256
|
|
|
248
|
-
> **Note:** The hash covers controller files matched by the `controllerPattern` glob. If you only change a DTO/model
|
|
257
|
+
> **Note:** The hash covers controller files matched by the `controllerPattern` glob. If you only change a DTO/model
|
|
258
|
+
> file that lives outside that pattern, the cache won't invalidate automatically. Use `analyze()` or delete
|
|
259
|
+
> `.rpc-checksum` in that case.
|
|
249
260
|
|
|
250
261
|
## How It Works
|
|
251
262
|
|
|
@@ -324,8 +335,11 @@ You can also manually trigger generation:
|
|
|
324
335
|
|
|
325
336
|
```typescript
|
|
326
337
|
const rpcPlugin = new RPCPlugin()
|
|
327
|
-
await rpcPlugin.analyze() // Force regeneration (bypasses cache)
|
|
328
|
-
await rpcPlugin.analyze(false) // Respect cache
|
|
338
|
+
await rpcPlugin.analyze({ force: true }) // Force regeneration (bypasses cache)
|
|
339
|
+
await rpcPlugin.analyze({ force: false }) // Respect cache
|
|
340
|
+
|
|
341
|
+
// Analyze-only mode (no files generated, diagnostics still emitted)
|
|
342
|
+
await rpcPlugin.analyze({ force: true, dryRun: true })
|
|
329
343
|
```
|
|
330
344
|
|
|
331
345
|
## Advanced Usage
|
|
@@ -361,7 +375,7 @@ await rpcPlugin.analyze()
|
|
|
361
375
|
Here's how your controllers should be structured for optimal RPC generation:
|
|
362
376
|
|
|
363
377
|
```typescript
|
|
364
|
-
import {
|
|
378
|
+
import { Body, Controller, Get, Param, Post, Query } from 'honestjs'
|
|
365
379
|
|
|
366
380
|
interface CreateUserDto {
|
|
367
381
|
name: string
|
|
@@ -403,7 +417,7 @@ import { UsersService } from './users.service'
|
|
|
403
417
|
|
|
404
418
|
@Module({
|
|
405
419
|
controllers: [UsersController],
|
|
406
|
-
|
|
420
|
+
services: [UsersService]
|
|
407
421
|
})
|
|
408
422
|
export class UsersModule {}
|
|
409
423
|
```
|
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
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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 };
|