@honestjs/rpc-plugin 1.4.1 → 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/README.md +203 -129
- package/dist/index.d.mts +112 -21
- package/dist/index.d.ts +112 -21
- package/dist/index.js +339 -123
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +333 -120
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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
|
|
@@ -41,12 +41,22 @@ interface SchemaInfo {
|
|
|
41
41
|
readonly typescriptType?: string;
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
44
|
-
* Generated
|
|
44
|
+
* Generated output information for one generator run.
|
|
45
45
|
*/
|
|
46
46
|
interface GeneratedClientInfo {
|
|
47
|
-
readonly
|
|
47
|
+
readonly generator: string;
|
|
48
|
+
readonly clientFile?: string;
|
|
49
|
+
readonly outputFiles?: readonly string[];
|
|
48
50
|
readonly generatedAt: string;
|
|
49
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
|
+
}
|
|
50
60
|
|
|
51
61
|
/**
|
|
52
62
|
* Clean separation of concerns for request options
|
|
@@ -72,6 +82,33 @@ declare class ApiError extends Error {
|
|
|
72
82
|
constructor(statusCode: number, message: string);
|
|
73
83
|
}
|
|
74
84
|
|
|
85
|
+
/**
|
|
86
|
+
* Context passed to each RPC generator.
|
|
87
|
+
*/
|
|
88
|
+
interface RPCGeneratorContext {
|
|
89
|
+
readonly outputDir: string;
|
|
90
|
+
readonly routes: readonly ExtendedRouteInfo[];
|
|
91
|
+
readonly schemas: readonly SchemaInfo[];
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Contract for custom RPC generators.
|
|
95
|
+
*/
|
|
96
|
+
interface RPCGenerator {
|
|
97
|
+
readonly name: string;
|
|
98
|
+
generate(context: RPCGeneratorContext): Promise<GeneratedClientInfo>;
|
|
99
|
+
}
|
|
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
|
+
}
|
|
75
112
|
/**
|
|
76
113
|
* Configuration options for the RPCPlugin
|
|
77
114
|
*/
|
|
@@ -80,6 +117,12 @@ interface RPCPluginOptions {
|
|
|
80
117
|
readonly tsConfigPath?: string;
|
|
81
118
|
readonly outputDir?: string;
|
|
82
119
|
readonly generateOnInit?: boolean;
|
|
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;
|
|
83
126
|
readonly context?: {
|
|
84
127
|
readonly namespace?: string;
|
|
85
128
|
readonly keys?: {
|
|
@@ -97,13 +140,19 @@ declare class RPCPlugin implements IPlugin {
|
|
|
97
140
|
private readonly generateOnInit;
|
|
98
141
|
private readonly contextNamespace;
|
|
99
142
|
private readonly contextArtifactKey;
|
|
143
|
+
private readonly mode;
|
|
144
|
+
private readonly logLevel;
|
|
145
|
+
private readonly failOnSchemaError;
|
|
146
|
+
private readonly failOnRouteAnalysisWarning;
|
|
147
|
+
private readonly customClassMatcher?;
|
|
100
148
|
private readonly routeAnalyzer;
|
|
101
149
|
private readonly schemaGenerator;
|
|
102
|
-
private readonly
|
|
150
|
+
private readonly generators;
|
|
103
151
|
private project;
|
|
104
152
|
private analyzedRoutes;
|
|
105
153
|
private analyzedSchemas;
|
|
106
|
-
private
|
|
154
|
+
private generatedInfos;
|
|
155
|
+
private diagnostics;
|
|
107
156
|
private app;
|
|
108
157
|
constructor(options?: RPCPluginOptions);
|
|
109
158
|
/**
|
|
@@ -122,7 +171,11 @@ declare class RPCPlugin implements IPlugin {
|
|
|
122
171
|
* Manually trigger analysis (useful for testing or re-generation).
|
|
123
172
|
* Defaults to force=true to bypass cache; pass false to use caching.
|
|
124
173
|
*/
|
|
125
|
-
analyze(force
|
|
174
|
+
analyze(force: boolean): Promise<void>;
|
|
175
|
+
analyze(options: {
|
|
176
|
+
force?: boolean;
|
|
177
|
+
dryRun?: boolean;
|
|
178
|
+
}): Promise<void>;
|
|
126
179
|
/**
|
|
127
180
|
* Get the analyzed routes
|
|
128
181
|
*/
|
|
@@ -135,13 +188,22 @@ declare class RPCPlugin implements IPlugin {
|
|
|
135
188
|
* Get the generation info
|
|
136
189
|
*/
|
|
137
190
|
getGenerationInfo(): GeneratedClientInfo | null;
|
|
191
|
+
/**
|
|
192
|
+
* Get all generation infos
|
|
193
|
+
*/
|
|
194
|
+
getGenerationInfos(): readonly GeneratedClientInfo[];
|
|
195
|
+
getDiagnostics(): RPCDiagnostics | null;
|
|
138
196
|
/**
|
|
139
197
|
* Checks whether expected output files exist on disk
|
|
140
198
|
*/
|
|
141
199
|
private outputFilesExist;
|
|
142
200
|
private getArtifactPath;
|
|
201
|
+
private getDiagnosticsPath;
|
|
143
202
|
private writeArtifactToDisk;
|
|
203
|
+
private writeDiagnosticsToDisk;
|
|
144
204
|
private loadArtifactFromDisk;
|
|
205
|
+
private runGenerators;
|
|
206
|
+
private hasTypeScriptGenerator;
|
|
145
207
|
private publishArtifact;
|
|
146
208
|
private getArtifactContextKey;
|
|
147
209
|
/**
|
|
@@ -156,52 +218,65 @@ declare class RPCPlugin implements IPlugin {
|
|
|
156
218
|
* Logs an error with the plugin prefix
|
|
157
219
|
*/
|
|
158
220
|
private logError;
|
|
221
|
+
private logWarn;
|
|
222
|
+
private logDebug;
|
|
223
|
+
private canLog;
|
|
159
224
|
}
|
|
160
225
|
|
|
161
226
|
/**
|
|
162
|
-
*
|
|
227
|
+
* Built-in generator for TypeScript RPC clients.
|
|
163
228
|
*/
|
|
164
|
-
declare class
|
|
229
|
+
declare class TypeScriptClientGenerator implements RPCGenerator {
|
|
165
230
|
private readonly outputDir;
|
|
231
|
+
readonly name = "typescript-client";
|
|
166
232
|
constructor(outputDir: string);
|
|
167
233
|
/**
|
|
168
|
-
* Generates the TypeScript RPC client
|
|
234
|
+
* Generates the TypeScript RPC client.
|
|
235
|
+
*/
|
|
236
|
+
generate(context: RPCGeneratorContext): Promise<GeneratedClientInfo>;
|
|
237
|
+
/**
|
|
238
|
+
* Generates the TypeScript RPC client.
|
|
169
239
|
*/
|
|
170
240
|
generateClient(routes: readonly ExtendedRouteInfo[], schemas: readonly SchemaInfo[]): Promise<GeneratedClientInfo>;
|
|
171
241
|
/**
|
|
172
|
-
* Generates the main client file with types included
|
|
242
|
+
* Generates the main client file with types included.
|
|
173
243
|
*/
|
|
174
244
|
private generateClientFile;
|
|
175
245
|
/**
|
|
176
|
-
* Generates the client TypeScript content with types included
|
|
246
|
+
* Generates the client TypeScript content with types included.
|
|
177
247
|
*/
|
|
178
248
|
private generateClientContent;
|
|
179
249
|
/**
|
|
180
|
-
* Generates controller methods for the client
|
|
250
|
+
* Generates controller methods for the client.
|
|
181
251
|
*/
|
|
182
252
|
private generateControllerMethods;
|
|
183
253
|
/**
|
|
184
|
-
* Extracts the proper return type from route analysis
|
|
254
|
+
* Extracts the proper return type from route analysis.
|
|
185
255
|
*/
|
|
186
256
|
private extractReturnType;
|
|
187
257
|
/**
|
|
188
|
-
* Generates schema types from integrated schema generation
|
|
258
|
+
* Generates schema types from integrated schema generation.
|
|
189
259
|
*/
|
|
190
260
|
private generateSchemaTypes;
|
|
191
261
|
/**
|
|
192
|
-
*
|
|
193
|
-
*/
|
|
194
|
-
private groupRoutesByController;
|
|
195
|
-
/**
|
|
196
|
-
* Analyzes route parameters to determine their types and usage
|
|
262
|
+
* Analyzes route parameters to determine their types and usage.
|
|
197
263
|
*/
|
|
198
264
|
private analyzeRouteParameters;
|
|
199
265
|
}
|
|
200
266
|
|
|
267
|
+
interface RouteAnalyzerOptions {
|
|
268
|
+
readonly customClassMatcher?: (classDeclaration: ClassDeclaration) => boolean;
|
|
269
|
+
readonly onWarn?: (message: string, details?: unknown) => void;
|
|
270
|
+
}
|
|
201
271
|
/**
|
|
202
272
|
* Service for analyzing controller methods and extracting type information
|
|
203
273
|
*/
|
|
204
274
|
declare class RouteAnalyzerService {
|
|
275
|
+
private readonly customClassMatcher?;
|
|
276
|
+
private readonly onWarn?;
|
|
277
|
+
private warnings;
|
|
278
|
+
constructor(options?: RouteAnalyzerOptions);
|
|
279
|
+
getWarnings(): readonly string[];
|
|
205
280
|
/**
|
|
206
281
|
* Analyzes controller methods to extract type information
|
|
207
282
|
*/
|
|
@@ -210,6 +285,7 @@ declare class RouteAnalyzerService {
|
|
|
210
285
|
* Finds controller classes in the project
|
|
211
286
|
*/
|
|
212
287
|
private findControllerClasses;
|
|
288
|
+
private isControllerClass;
|
|
213
289
|
/**
|
|
214
290
|
* Processes all routes and extracts type information
|
|
215
291
|
*/
|
|
@@ -228,13 +304,21 @@ declare class RouteAnalyzerService {
|
|
|
228
304
|
private getParametersWithTypes;
|
|
229
305
|
}
|
|
230
306
|
|
|
307
|
+
interface SchemaGeneratorOptions {
|
|
308
|
+
readonly failOnSchemaError?: boolean;
|
|
309
|
+
readonly onWarn?: (message: string, details?: unknown) => void;
|
|
310
|
+
}
|
|
231
311
|
/**
|
|
232
312
|
* Service for generating JSON schemas from TypeScript types used in controllers
|
|
233
313
|
*/
|
|
234
314
|
declare class SchemaGeneratorService {
|
|
235
315
|
private readonly controllerPattern;
|
|
236
316
|
private readonly tsConfigPath;
|
|
237
|
-
|
|
317
|
+
private readonly failOnSchemaError;
|
|
318
|
+
private readonly onWarn?;
|
|
319
|
+
private warnings;
|
|
320
|
+
constructor(controllerPattern: string, tsConfigPath: string, options?: SchemaGeneratorOptions);
|
|
321
|
+
getWarnings(): readonly string[];
|
|
238
322
|
/**
|
|
239
323
|
* Generates JSON schemas from types used in controllers
|
|
240
324
|
*/
|
|
@@ -277,6 +361,10 @@ declare function readChecksum(outputDir: string): ChecksumData | null;
|
|
|
277
361
|
*/
|
|
278
362
|
declare function writeChecksum(outputDir: string, data: ChecksumData): Promise<void>;
|
|
279
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
|
+
|
|
280
368
|
/** Minimal route shape needed to build the full API path (prefix + version + route + path). */
|
|
281
369
|
type RoutePathInput = Pick<ExtendedRouteInfo, 'prefix' | 'version' | 'route' | 'path'>;
|
|
282
370
|
/**
|
|
@@ -319,6 +407,9 @@ declare const DEFAULT_OPTIONS: {
|
|
|
319
407
|
readonly tsConfigPath: "tsconfig.json";
|
|
320
408
|
readonly outputDir: "./generated/rpc";
|
|
321
409
|
readonly generateOnInit: true;
|
|
410
|
+
readonly mode: "best-effort";
|
|
411
|
+
readonly logLevel: "info";
|
|
412
|
+
readonly artifactVersion: "1";
|
|
322
413
|
readonly context: {
|
|
323
414
|
readonly namespace: "rpc";
|
|
324
415
|
readonly keys: {
|
|
@@ -343,4 +434,4 @@ declare const BUILTIN_TYPES: Set<string>;
|
|
|
343
434
|
*/
|
|
344
435
|
declare const GENERIC_TYPES: Set<string>;
|
|
345
436
|
|
|
346
|
-
export { ApiError, BUILTIN_TYPES, BUILTIN_UTILITY_TYPES, type ChecksumData,
|
|
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
|
|
@@ -41,12 +41,22 @@ interface SchemaInfo {
|
|
|
41
41
|
readonly typescriptType?: string;
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
44
|
-
* Generated
|
|
44
|
+
* Generated output information for one generator run.
|
|
45
45
|
*/
|
|
46
46
|
interface GeneratedClientInfo {
|
|
47
|
-
readonly
|
|
47
|
+
readonly generator: string;
|
|
48
|
+
readonly clientFile?: string;
|
|
49
|
+
readonly outputFiles?: readonly string[];
|
|
48
50
|
readonly generatedAt: string;
|
|
49
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
|
+
}
|
|
50
60
|
|
|
51
61
|
/**
|
|
52
62
|
* Clean separation of concerns for request options
|
|
@@ -72,6 +82,33 @@ declare class ApiError extends Error {
|
|
|
72
82
|
constructor(statusCode: number, message: string);
|
|
73
83
|
}
|
|
74
84
|
|
|
85
|
+
/**
|
|
86
|
+
* Context passed to each RPC generator.
|
|
87
|
+
*/
|
|
88
|
+
interface RPCGeneratorContext {
|
|
89
|
+
readonly outputDir: string;
|
|
90
|
+
readonly routes: readonly ExtendedRouteInfo[];
|
|
91
|
+
readonly schemas: readonly SchemaInfo[];
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Contract for custom RPC generators.
|
|
95
|
+
*/
|
|
96
|
+
interface RPCGenerator {
|
|
97
|
+
readonly name: string;
|
|
98
|
+
generate(context: RPCGeneratorContext): Promise<GeneratedClientInfo>;
|
|
99
|
+
}
|
|
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
|
+
}
|
|
75
112
|
/**
|
|
76
113
|
* Configuration options for the RPCPlugin
|
|
77
114
|
*/
|
|
@@ -80,6 +117,12 @@ interface RPCPluginOptions {
|
|
|
80
117
|
readonly tsConfigPath?: string;
|
|
81
118
|
readonly outputDir?: string;
|
|
82
119
|
readonly generateOnInit?: boolean;
|
|
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;
|
|
83
126
|
readonly context?: {
|
|
84
127
|
readonly namespace?: string;
|
|
85
128
|
readonly keys?: {
|
|
@@ -97,13 +140,19 @@ declare class RPCPlugin implements IPlugin {
|
|
|
97
140
|
private readonly generateOnInit;
|
|
98
141
|
private readonly contextNamespace;
|
|
99
142
|
private readonly contextArtifactKey;
|
|
143
|
+
private readonly mode;
|
|
144
|
+
private readonly logLevel;
|
|
145
|
+
private readonly failOnSchemaError;
|
|
146
|
+
private readonly failOnRouteAnalysisWarning;
|
|
147
|
+
private readonly customClassMatcher?;
|
|
100
148
|
private readonly routeAnalyzer;
|
|
101
149
|
private readonly schemaGenerator;
|
|
102
|
-
private readonly
|
|
150
|
+
private readonly generators;
|
|
103
151
|
private project;
|
|
104
152
|
private analyzedRoutes;
|
|
105
153
|
private analyzedSchemas;
|
|
106
|
-
private
|
|
154
|
+
private generatedInfos;
|
|
155
|
+
private diagnostics;
|
|
107
156
|
private app;
|
|
108
157
|
constructor(options?: RPCPluginOptions);
|
|
109
158
|
/**
|
|
@@ -122,7 +171,11 @@ declare class RPCPlugin implements IPlugin {
|
|
|
122
171
|
* Manually trigger analysis (useful for testing or re-generation).
|
|
123
172
|
* Defaults to force=true to bypass cache; pass false to use caching.
|
|
124
173
|
*/
|
|
125
|
-
analyze(force
|
|
174
|
+
analyze(force: boolean): Promise<void>;
|
|
175
|
+
analyze(options: {
|
|
176
|
+
force?: boolean;
|
|
177
|
+
dryRun?: boolean;
|
|
178
|
+
}): Promise<void>;
|
|
126
179
|
/**
|
|
127
180
|
* Get the analyzed routes
|
|
128
181
|
*/
|
|
@@ -135,13 +188,22 @@ declare class RPCPlugin implements IPlugin {
|
|
|
135
188
|
* Get the generation info
|
|
136
189
|
*/
|
|
137
190
|
getGenerationInfo(): GeneratedClientInfo | null;
|
|
191
|
+
/**
|
|
192
|
+
* Get all generation infos
|
|
193
|
+
*/
|
|
194
|
+
getGenerationInfos(): readonly GeneratedClientInfo[];
|
|
195
|
+
getDiagnostics(): RPCDiagnostics | null;
|
|
138
196
|
/**
|
|
139
197
|
* Checks whether expected output files exist on disk
|
|
140
198
|
*/
|
|
141
199
|
private outputFilesExist;
|
|
142
200
|
private getArtifactPath;
|
|
201
|
+
private getDiagnosticsPath;
|
|
143
202
|
private writeArtifactToDisk;
|
|
203
|
+
private writeDiagnosticsToDisk;
|
|
144
204
|
private loadArtifactFromDisk;
|
|
205
|
+
private runGenerators;
|
|
206
|
+
private hasTypeScriptGenerator;
|
|
145
207
|
private publishArtifact;
|
|
146
208
|
private getArtifactContextKey;
|
|
147
209
|
/**
|
|
@@ -156,52 +218,65 @@ declare class RPCPlugin implements IPlugin {
|
|
|
156
218
|
* Logs an error with the plugin prefix
|
|
157
219
|
*/
|
|
158
220
|
private logError;
|
|
221
|
+
private logWarn;
|
|
222
|
+
private logDebug;
|
|
223
|
+
private canLog;
|
|
159
224
|
}
|
|
160
225
|
|
|
161
226
|
/**
|
|
162
|
-
*
|
|
227
|
+
* Built-in generator for TypeScript RPC clients.
|
|
163
228
|
*/
|
|
164
|
-
declare class
|
|
229
|
+
declare class TypeScriptClientGenerator implements RPCGenerator {
|
|
165
230
|
private readonly outputDir;
|
|
231
|
+
readonly name = "typescript-client";
|
|
166
232
|
constructor(outputDir: string);
|
|
167
233
|
/**
|
|
168
|
-
* Generates the TypeScript RPC client
|
|
234
|
+
* Generates the TypeScript RPC client.
|
|
235
|
+
*/
|
|
236
|
+
generate(context: RPCGeneratorContext): Promise<GeneratedClientInfo>;
|
|
237
|
+
/**
|
|
238
|
+
* Generates the TypeScript RPC client.
|
|
169
239
|
*/
|
|
170
240
|
generateClient(routes: readonly ExtendedRouteInfo[], schemas: readonly SchemaInfo[]): Promise<GeneratedClientInfo>;
|
|
171
241
|
/**
|
|
172
|
-
* Generates the main client file with types included
|
|
242
|
+
* Generates the main client file with types included.
|
|
173
243
|
*/
|
|
174
244
|
private generateClientFile;
|
|
175
245
|
/**
|
|
176
|
-
* Generates the client TypeScript content with types included
|
|
246
|
+
* Generates the client TypeScript content with types included.
|
|
177
247
|
*/
|
|
178
248
|
private generateClientContent;
|
|
179
249
|
/**
|
|
180
|
-
* Generates controller methods for the client
|
|
250
|
+
* Generates controller methods for the client.
|
|
181
251
|
*/
|
|
182
252
|
private generateControllerMethods;
|
|
183
253
|
/**
|
|
184
|
-
* Extracts the proper return type from route analysis
|
|
254
|
+
* Extracts the proper return type from route analysis.
|
|
185
255
|
*/
|
|
186
256
|
private extractReturnType;
|
|
187
257
|
/**
|
|
188
|
-
* Generates schema types from integrated schema generation
|
|
258
|
+
* Generates schema types from integrated schema generation.
|
|
189
259
|
*/
|
|
190
260
|
private generateSchemaTypes;
|
|
191
261
|
/**
|
|
192
|
-
*
|
|
193
|
-
*/
|
|
194
|
-
private groupRoutesByController;
|
|
195
|
-
/**
|
|
196
|
-
* Analyzes route parameters to determine their types and usage
|
|
262
|
+
* Analyzes route parameters to determine their types and usage.
|
|
197
263
|
*/
|
|
198
264
|
private analyzeRouteParameters;
|
|
199
265
|
}
|
|
200
266
|
|
|
267
|
+
interface RouteAnalyzerOptions {
|
|
268
|
+
readonly customClassMatcher?: (classDeclaration: ClassDeclaration) => boolean;
|
|
269
|
+
readonly onWarn?: (message: string, details?: unknown) => void;
|
|
270
|
+
}
|
|
201
271
|
/**
|
|
202
272
|
* Service for analyzing controller methods and extracting type information
|
|
203
273
|
*/
|
|
204
274
|
declare class RouteAnalyzerService {
|
|
275
|
+
private readonly customClassMatcher?;
|
|
276
|
+
private readonly onWarn?;
|
|
277
|
+
private warnings;
|
|
278
|
+
constructor(options?: RouteAnalyzerOptions);
|
|
279
|
+
getWarnings(): readonly string[];
|
|
205
280
|
/**
|
|
206
281
|
* Analyzes controller methods to extract type information
|
|
207
282
|
*/
|
|
@@ -210,6 +285,7 @@ declare class RouteAnalyzerService {
|
|
|
210
285
|
* Finds controller classes in the project
|
|
211
286
|
*/
|
|
212
287
|
private findControllerClasses;
|
|
288
|
+
private isControllerClass;
|
|
213
289
|
/**
|
|
214
290
|
* Processes all routes and extracts type information
|
|
215
291
|
*/
|
|
@@ -228,13 +304,21 @@ declare class RouteAnalyzerService {
|
|
|
228
304
|
private getParametersWithTypes;
|
|
229
305
|
}
|
|
230
306
|
|
|
307
|
+
interface SchemaGeneratorOptions {
|
|
308
|
+
readonly failOnSchemaError?: boolean;
|
|
309
|
+
readonly onWarn?: (message: string, details?: unknown) => void;
|
|
310
|
+
}
|
|
231
311
|
/**
|
|
232
312
|
* Service for generating JSON schemas from TypeScript types used in controllers
|
|
233
313
|
*/
|
|
234
314
|
declare class SchemaGeneratorService {
|
|
235
315
|
private readonly controllerPattern;
|
|
236
316
|
private readonly tsConfigPath;
|
|
237
|
-
|
|
317
|
+
private readonly failOnSchemaError;
|
|
318
|
+
private readonly onWarn?;
|
|
319
|
+
private warnings;
|
|
320
|
+
constructor(controllerPattern: string, tsConfigPath: string, options?: SchemaGeneratorOptions);
|
|
321
|
+
getWarnings(): readonly string[];
|
|
238
322
|
/**
|
|
239
323
|
* Generates JSON schemas from types used in controllers
|
|
240
324
|
*/
|
|
@@ -277,6 +361,10 @@ declare function readChecksum(outputDir: string): ChecksumData | null;
|
|
|
277
361
|
*/
|
|
278
362
|
declare function writeChecksum(outputDir: string, data: ChecksumData): Promise<void>;
|
|
279
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
|
+
|
|
280
368
|
/** Minimal route shape needed to build the full API path (prefix + version + route + path). */
|
|
281
369
|
type RoutePathInput = Pick<ExtendedRouteInfo, 'prefix' | 'version' | 'route' | 'path'>;
|
|
282
370
|
/**
|
|
@@ -319,6 +407,9 @@ declare const DEFAULT_OPTIONS: {
|
|
|
319
407
|
readonly tsConfigPath: "tsconfig.json";
|
|
320
408
|
readonly outputDir: "./generated/rpc";
|
|
321
409
|
readonly generateOnInit: true;
|
|
410
|
+
readonly mode: "best-effort";
|
|
411
|
+
readonly logLevel: "info";
|
|
412
|
+
readonly artifactVersion: "1";
|
|
322
413
|
readonly context: {
|
|
323
414
|
readonly namespace: "rpc";
|
|
324
415
|
readonly keys: {
|
|
@@ -343,4 +434,4 @@ declare const BUILTIN_TYPES: Set<string>;
|
|
|
343
434
|
*/
|
|
344
435
|
declare const GENERIC_TYPES: Set<string>;
|
|
345
436
|
|
|
346
|
-
export { ApiError, BUILTIN_TYPES, BUILTIN_UTILITY_TYPES, type ChecksumData,
|
|
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 };
|