@nestbridge/core 1.0.0 → 1.1.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 CHANGED
@@ -3,8 +3,9 @@
3
3
  [![CI](https://github.com/MDReal32/nestbridge/actions/workflows/ci.yml/badge.svg)](https://github.com/MDReal32/nestbridge/actions/workflows/ci.yml)
4
4
  [![npm](https://img.shields.io/npm/v/@nestbridge/core.svg)](https://www.npmjs.com/package/@nestbridge/core)
5
5
 
6
- Static analysis of NestJS controllers, and generation of the client-facing
7
- `.d.ts` declarations that make them safely importable from the browser.
6
+ Static analysis of NestJS controllers and GraphQL resolvers, and generation
7
+ of the client-facing `.d.ts` declarations that make them safely importable
8
+ from the browser.
8
9
 
9
10
  This package has no runtime dependency on NestJS, Vite, or the DOM — it reads
10
11
  TypeScript source text via the TypeScript Compiler API and never executes
@@ -37,13 +38,35 @@ const { controllers, diagnostics } = analyzeControllers([
37
38
  ]);
38
39
  ```
39
40
 
40
- ### `generateControllerDeclaration(controller, outputFilePath)`
41
+ ### `analyzeResolvers(filePaths)`
41
42
 
42
- Turns a `ControllerDefinition` into the text of a `.d.ts` file. The generated
43
- class re-declares each method using a type-only reference back to the real
44
- controller (`Parameters<__ServerX['method']>` / `RemoteResult<...>`), so
45
- argument and return types are projected from the real controller's own type —
46
- never re-derived from the AST.
43
+ Parses each file, finds classes decorated with `@Resolver(...)`, and
44
+ extracts a plain `ResolverDefinition` per resolver — its name, and each
45
+ `@Query`/`@Mutation` method's operation kind (`'query'` | `'mutation'`),
46
+ operation name, `@Args()` parameter mapping (name, GraphQL type), and a
47
+ `selection` of `SelectionField`s built by walking the return type's
48
+ `@ObjectType()` fields. The return type itself is read from the
49
+ `@Query()`/`@Mutation()` type-thunk argument (`() => UserType`) first,
50
+ falling back to a TypeScript return-type annotation only when no thunk is
51
+ present — a resolver method never needs both.
52
+
53
+ ```ts
54
+ import { analyzeResolvers } from '@nestbridge/core';
55
+
56
+ const { resolvers, diagnostics } = analyzeResolvers([
57
+ 'src/users/users.resolver.ts',
58
+ ]);
59
+ ```
60
+
61
+ ### `generateControllerDeclaration(definition, outputFilePath)`
62
+
63
+ Turns a `ControllerDefinition` or a `ResolverDefinition` into the text of a
64
+ `.d.ts` file — both share the same `{ name, sourceFile, methods }` shape, so
65
+ the same generator is used for both. The generated class re-declares each
66
+ method using a type-only reference back to the real controller or resolver
67
+ (`Parameters<__ServerX['method']>` / `RemoteResult<...>`), so argument and
68
+ return types are projected from the real class's own type — never re-derived
69
+ from the AST.
47
70
 
48
71
  ```ts
49
72
  import { generateControllerDeclaration } from '@nestbridge/core';
@@ -65,6 +88,8 @@ more diagnostics as a thrown `Error`.
65
88
 
66
89
  `ControllerDefinition`, `ControllerMethodDefinition`,
67
90
  `ControllerParameterDefinition`, `HttpMethod`, `ParameterSourceKind`,
91
+ `ResolverDefinition`, `ResolverMethodDefinition`,
92
+ `ResolverArgumentDefinition`, `SelectionField`, `GraphqlOperationKind`,
68
93
  `NestBridgeDiagnostic`, `NestBridgeDiagnosticCode`.
69
94
 
70
95
  ## License
@@ -1,114 +1,132 @@
1
- export declare const analyzeControllers: (filePaths: readonly string[]) => {
2
- controllers: ControllerDefinition[];
3
- diagnostics: NestBridgeDiagnostic[];
4
- };
5
-
6
- export declare const analyzeResolvers: (filePaths: readonly string[]) => {
7
- resolvers: ResolverDefinition[];
8
- diagnostics: NestBridgeDiagnostic[];
9
- };
10
-
11
- declare interface ClientDeclarationSource {
12
- name: string;
13
- sourceFile: string;
14
- methods: readonly {
15
- name: string;
16
- }[];
17
- }
18
-
19
- export declare interface ControllerDefinition {
20
- name: string;
21
- path: string;
22
- sourceFile: string;
23
- methods: ControllerMethodDefinition[];
24
- }
25
-
26
- export declare interface ControllerMethodDefinition {
27
- name: string;
28
- httpMethod: HttpMethod;
29
- path: string;
30
- parameters: ControllerParameterDefinition[];
31
- line: number;
32
- column: number;
33
- }
34
-
35
- declare interface ControllerParameterBase {
36
- index: number;
37
- parameterName: string;
38
- }
39
-
40
- export declare type ControllerParameterDefinition = (ControllerParameterBase & {
41
- kind: 'param';
42
- name: string;
43
- }) | (ControllerParameterBase & {
44
- kind: 'query';
45
- name?: string;
46
- }) | (ControllerParameterBase & {
47
- kind: 'body';
48
- name?: string;
49
- }) | (ControllerParameterBase & {
50
- kind: 'header';
51
- name: string;
52
- });
53
-
54
- export declare const formatDiagnostic: (diagnostic: NestBridgeDiagnostic) => string;
55
-
56
- export declare const generateControllerDeclaration: (controller: ClientDeclarationSource, outputFilePath: string) => string;
57
-
58
- export declare type GraphqlOperationKind = 'query' | 'mutation';
59
-
60
- export declare type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
61
-
62
- export declare interface NestBridgeDiagnostic {
63
- code: NestBridgeDiagnosticCode;
64
- title: string;
65
- controllerName: string;
66
- memberName: string;
67
- detail: string;
68
- found?: string;
69
- expected?: string;
70
- filePath: string;
71
- line: number;
72
- column: number;
73
- }
74
-
75
- export declare type NestBridgeDiagnosticCode = 'unsupported-route' | 'unsupported-parameter' | 'unsupported-argument' | 'unsupported-return-type' | 'circular-type';
76
-
77
- export declare class NestBridgeDiagnosticError extends Error {
78
- readonly diagnostic: NestBridgeDiagnostic;
79
- constructor(diagnostic: NestBridgeDiagnostic);
80
- }
81
-
82
- export declare type ParameterSourceKind = 'param' | 'query' | 'body' | 'header';
83
-
84
- export declare interface ResolverArgumentDefinition {
85
- index: number;
86
- parameterName: string;
87
- name: string;
88
- graphqlType: string;
89
- }
90
-
91
- export declare interface ResolverDefinition {
92
- name: string;
93
- sourceFile: string;
94
- methods: ResolverMethodDefinition[];
95
- }
96
-
97
- export declare interface ResolverMethodDefinition {
98
- name: string;
99
- operationKind: GraphqlOperationKind;
100
- operationName: string;
101
- arguments: ResolverArgumentDefinition[];
102
- selection: SelectionField[];
103
- line: number;
104
- column: number;
105
- }
106
-
107
- export declare interface SelectionField {
108
- name: string;
109
- children?: SelectionField[];
110
- }
111
-
112
- export declare const VERSION: string;
113
-
114
- export { }
1
+ //#region src/diagnostics/nestbridge-diagnostic.d.ts
2
+ type NestBridgeDiagnosticCode = "unsupported-route" | "unsupported-parameter" | "unsupported-argument" | "unsupported-return-type" | "circular-type";
3
+ interface NestBridgeDiagnostic {
4
+ code: NestBridgeDiagnosticCode;
5
+ title: string;
6
+ controllerName: string;
7
+ memberName: string;
8
+ detail: string;
9
+ found?: string;
10
+ expected?: string;
11
+ filePath: string;
12
+ line: number;
13
+ column: number;
14
+ }
15
+ //#endregion
16
+ //#region src/diagnostics/format-diagnostic.d.ts
17
+ export declare const formatDiagnostic: (diagnostic: NestBridgeDiagnostic) => string;
18
+ //#endregion
19
+ //#region src/diagnostics/nestbridge-diagnostic-error.d.ts
20
+ export declare class NestBridgeDiagnosticError extends Error {
21
+ readonly diagnostic: NestBridgeDiagnostic;
22
+ constructor(diagnostic: NestBridgeDiagnostic);
23
+ }
24
+ //#endregion
25
+ //#region src/models/controller-parameter-definition.d.ts
26
+ type ParameterSourceKind = "param" | "query" | "body" | "header";
27
+ interface ControllerParameterBase {
28
+ index: number;
29
+ parameterName: string;
30
+ }
31
+ type ControllerParameterDefinition = (ControllerParameterBase & {
32
+ kind: "param";
33
+ name: string;
34
+ }) | (ControllerParameterBase & {
35
+ kind: "query";
36
+ name?: string;
37
+ }) | (ControllerParameterBase & {
38
+ kind: "body";
39
+ name?: string;
40
+ }) | (ControllerParameterBase & {
41
+ kind: "header";
42
+ name: string;
43
+ });
44
+ //#endregion
45
+ //#region src/models/http-method.d.ts
46
+ type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
47
+ //#endregion
48
+ //#region src/models/response-kind.d.ts
49
+ type ResponseKind = "json" | "observable" | "stream";
50
+ //#endregion
51
+ //#region src/models/controller-method-definition.d.ts
52
+ interface ControllerMethodDefinition {
53
+ name: string;
54
+ httpMethod: HttpMethod;
55
+ path: string;
56
+ parameters: ControllerParameterDefinition[];
57
+ responseKind: ResponseKind;
58
+ line: number;
59
+ column: number;
60
+ }
61
+ //#endregion
62
+ //#region src/models/controller-definition.d.ts
63
+ interface ControllerDefinition {
64
+ name: string;
65
+ path: string;
66
+ sourceFile: string;
67
+ methods: ControllerMethodDefinition[];
68
+ }
69
+ //#endregion
70
+ //#region src/models/graphql-operation-kind.d.ts
71
+ type GraphqlOperationKind = "query" | "mutation";
72
+ //#endregion
73
+ //#region src/models/resolver-argument-definition.d.ts
74
+ interface ResolverArgumentDefinition {
75
+ index: number;
76
+ parameterName: string;
77
+ name: string;
78
+ graphqlType: string;
79
+ }
80
+ //#endregion
81
+ //#region src/models/selection-field.d.ts
82
+ interface SelectionField {
83
+ name: string;
84
+ children?: SelectionField[];
85
+ }
86
+ //#endregion
87
+ //#region src/models/resolver-method-definition.d.ts
88
+ interface ResolverMethodDefinition {
89
+ name: string;
90
+ operationKind: GraphqlOperationKind;
91
+ operationName: string;
92
+ arguments: ResolverArgumentDefinition[];
93
+ selection: SelectionField[];
94
+ line: number;
95
+ column: number;
96
+ }
97
+ //#endregion
98
+ //#region src/models/resolver-definition.d.ts
99
+ interface ResolverDefinition {
100
+ name: string;
101
+ sourceFile: string;
102
+ methods: ResolverMethodDefinition[];
103
+ }
104
+ //#endregion
105
+ //#region src/analysis/analyze-controllers.d.ts
106
+ export declare const analyzeControllers: (filePaths: readonly string[]) => {
107
+ controllers: ControllerDefinition[];
108
+ diagnostics: NestBridgeDiagnostic[];
109
+ };
110
+ //#endregion
111
+ //#region src/analysis/analyze-resolvers.d.ts
112
+ export declare const analyzeResolvers: (filePaths: readonly string[]) => {
113
+ resolvers: ResolverDefinition[];
114
+ diagnostics: NestBridgeDiagnostic[];
115
+ };
116
+ //#endregion
117
+ //#region src/declarations/generate-controller-declaration.d.ts
118
+ interface ClientDeclarationSource {
119
+ name: string;
120
+ sourceFile: string;
121
+ methods: readonly {
122
+ name: string;
123
+ responseKind?: ResponseKind;
124
+ }[];
125
+ }
126
+ export declare const generateControllerDeclaration: (controller: ClientDeclarationSource, outputFilePath: string) => string;
127
+ //#endregion
128
+ //#region src/version.d.ts
129
+ export declare const VERSION: string;
130
+ //#endregion
131
+ export type { ControllerDefinition, ControllerMethodDefinition, ControllerParameterDefinition, GraphqlOperationKind, HttpMethod, NestBridgeDiagnostic, NestBridgeDiagnosticCode, ParameterSourceKind, ResolverArgumentDefinition, ResolverDefinition, ResolverMethodDefinition, ResponseKind, SelectionField };
132
+ //# sourceMappingURL=nestbridge.core.d.ts.map