@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 +33 -8
- package/build/nestbridge.core.d.ts +132 -114
- package/build/nestbridge.core.js +914 -957
- package/build/nestbridge.core.js.map +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
[](https://github.com/MDReal32/nestbridge/actions/workflows/ci.yml)
|
|
4
4
|
[](https://www.npmjs.com/package/@nestbridge/core)
|
|
5
5
|
|
|
6
|
-
Static analysis of NestJS controllers
|
|
7
|
-
`.d.ts` declarations that make them safely importable
|
|
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
|
-
### `
|
|
41
|
+
### `analyzeResolvers(filePaths)`
|
|
41
42
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
export declare const
|
|
113
|
-
|
|
114
|
-
|
|
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
|