@nestbridge/vite 1.1.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/build/nestbridge.vite.d.ts +18 -15
- package/build/nestbridge.vite.js +1098 -1262
- package/build/nestbridge.vite.js.map +1 -1
- package/package.json +6 -6
package/build/nestbridge.vite.js
CHANGED
|
@@ -1,1324 +1,1160 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
return decorators.find((decorator) => decoratorNameOf(decorator) === decoratorName);
|
|
1
|
+
import { SyntaxKind, isArrayLiteralExpression, isArrayTypeNode, isArrowFunction, isBlock, isCallExpression, isClassDeclaration, isDecorator, isExportDeclaration, isFunctionExpression, isIdentifier, isImportDeclaration, isMethodDeclaration, isNamedExports, isNamedImports, isObjectLiteralExpression, isPropertyAssignment, isPropertyDeclaration, isReturnStatement, isStringLiteralLikeNode, isTypeReferenceNode, isUnionTypeNode } from "typescript/unstable/ast";
|
|
2
|
+
import { API } from "typescript/unstable/sync";
|
|
3
|
+
import { existsSync, globSync, mkdirSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { dirname, extname, join, relative, resolve } from "node:path";
|
|
5
|
+
import { normalizePath } from "vite";
|
|
6
|
+
//#region ../core/build/nestbridge.core.js
|
|
7
|
+
var getDecorators = (node) => {
|
|
8
|
+
const decorators = node.modifiers?.filter(isDecorator);
|
|
9
|
+
return decorators === void 0 || decorators.length === 0 ? void 0 : decorators;
|
|
12
10
|
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
return decorators.find((decorator) => decoratorNames.includes(decoratorNameOf(decorator) ?? ""));
|
|
11
|
+
var findDecorator = (node, decoratorName) => {
|
|
12
|
+
const decorators = getDecorators(node);
|
|
13
|
+
if (decorators === void 0) return;
|
|
14
|
+
return decorators.find((decorator) => decoratorNameOf(decorator) === decoratorName);
|
|
19
15
|
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
if (ts.isIdentifier(expression)) {
|
|
26
|
-
return expression.text;
|
|
27
|
-
}
|
|
28
|
-
return void 0;
|
|
16
|
+
var findAnyDecorator = (node, decoratorNames) => {
|
|
17
|
+
const decorators = getDecorators(node);
|
|
18
|
+
if (decorators === void 0) return;
|
|
19
|
+
return decorators.find((decorator) => decoratorNames.includes(decoratorNameOf(decorator) ?? ""));
|
|
29
20
|
};
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
const [firstArgument] = expression.arguments;
|
|
36
|
-
if (firstArgument === void 0) {
|
|
37
|
-
return { ok: true, value: void 0 };
|
|
38
|
-
}
|
|
39
|
-
if (ts.isStringLiteralLike(firstArgument)) {
|
|
40
|
-
return { ok: true, value: firstArgument.text };
|
|
41
|
-
}
|
|
42
|
-
return { ok: false, argumentText: firstArgument.getText() };
|
|
21
|
+
var decoratorNameOf = (decorator) => {
|
|
22
|
+
const expression = decorator.expression;
|
|
23
|
+
if (isCallExpression(expression) && isIdentifier(expression.expression)) return expression.expression.text;
|
|
24
|
+
if (isIdentifier(expression)) return expression.text;
|
|
43
25
|
};
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
26
|
+
var readStaticStringArgument = (decorator) => {
|
|
27
|
+
const expression = decorator.expression;
|
|
28
|
+
if (!isCallExpression(expression)) return {
|
|
29
|
+
ok: true,
|
|
30
|
+
value: void 0
|
|
31
|
+
};
|
|
32
|
+
const [firstArgument] = expression.arguments;
|
|
33
|
+
if (firstArgument === void 0) return {
|
|
34
|
+
ok: true,
|
|
35
|
+
value: void 0
|
|
36
|
+
};
|
|
37
|
+
if (isStringLiteralLikeNode(firstArgument)) return {
|
|
38
|
+
ok: true,
|
|
39
|
+
value: firstArgument.text
|
|
40
|
+
};
|
|
41
|
+
return {
|
|
42
|
+
ok: false,
|
|
43
|
+
argumentText: firstArgument.getText()
|
|
44
|
+
};
|
|
51
45
|
};
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
46
|
+
var HTTP_METHOD_DECORATOR_NAMES = {
|
|
47
|
+
Get: "GET",
|
|
48
|
+
Post: "POST",
|
|
49
|
+
Put: "PUT",
|
|
50
|
+
Patch: "PATCH",
|
|
51
|
+
Delete: "DELETE"
|
|
56
52
|
};
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
...KNOWN_UNSUPPORTED_PARAMETER_DECORATORS
|
|
64
|
-
]);
|
|
65
|
-
const location = locationOf(context.sourceFile, parameter);
|
|
66
|
-
if (decorator === void 0) {
|
|
67
|
-
context.diagnostics.push({
|
|
68
|
-
code: "unsupported-parameter",
|
|
69
|
-
title: "Unsupported parameter.",
|
|
70
|
-
controllerName: context.controllerName,
|
|
71
|
-
memberName: context.methodName,
|
|
72
|
-
detail: `Parameter "${parameter.name.getText()}" must be decorated with one of @Param, @Query, @Body, or @Headers to be transported through a NestBridge HTTP client.`,
|
|
73
|
-
filePath: context.filePath,
|
|
74
|
-
line: location.line,
|
|
75
|
-
column: location.column
|
|
76
|
-
});
|
|
77
|
-
return void 0;
|
|
78
|
-
}
|
|
79
|
-
const decoratorName = decoratorNameOf(decorator);
|
|
80
|
-
if (decoratorName !== void 0 && KNOWN_UNSUPPORTED_PARAMETER_DECORATORS.includes(decoratorName)) {
|
|
81
|
-
context.diagnostics.push({
|
|
82
|
-
code: "unsupported-parameter",
|
|
83
|
-
title: "Unsupported parameter.",
|
|
84
|
-
controllerName: context.controllerName,
|
|
85
|
-
memberName: context.methodName,
|
|
86
|
-
detail: `@${decoratorName}() cannot be transported through a NestBridge HTTP client.`,
|
|
87
|
-
filePath: context.filePath,
|
|
88
|
-
line: location.line,
|
|
89
|
-
column: location.column
|
|
90
|
-
});
|
|
91
|
-
return void 0;
|
|
92
|
-
}
|
|
93
|
-
if (!ts.isIdentifier(parameter.name)) {
|
|
94
|
-
context.diagnostics.push({
|
|
95
|
-
code: "unsupported-parameter",
|
|
96
|
-
title: "Unsupported parameter.",
|
|
97
|
-
controllerName: context.controllerName,
|
|
98
|
-
memberName: context.methodName,
|
|
99
|
-
detail: "Destructured parameters cannot be transported through a NestBridge HTTP client.",
|
|
100
|
-
filePath: context.filePath,
|
|
101
|
-
line: location.line,
|
|
102
|
-
column: location.column
|
|
103
|
-
});
|
|
104
|
-
return void 0;
|
|
105
|
-
}
|
|
106
|
-
const argument = readStaticStringArgument(decorator);
|
|
107
|
-
if (!argument.ok) {
|
|
108
|
-
context.diagnostics.push({
|
|
109
|
-
code: "unsupported-parameter",
|
|
110
|
-
title: "Unsupported parameter.",
|
|
111
|
-
controllerName: context.controllerName,
|
|
112
|
-
memberName: context.methodName,
|
|
113
|
-
detail: `@${decoratorName}() arguments must be statically analyzable string literals.`,
|
|
114
|
-
found: `@${decoratorName}(${argument.argumentText})`,
|
|
115
|
-
filePath: context.filePath,
|
|
116
|
-
line: location.line,
|
|
117
|
-
column: location.column
|
|
118
|
-
});
|
|
119
|
-
return void 0;
|
|
120
|
-
}
|
|
121
|
-
const base = {
|
|
122
|
-
index,
|
|
123
|
-
parameterName: parameter.name.text
|
|
124
|
-
};
|
|
125
|
-
if (decoratorName === "Param") {
|
|
126
|
-
if (argument.value === void 0) {
|
|
127
|
-
context.diagnostics.push({
|
|
128
|
-
code: "unsupported-parameter",
|
|
129
|
-
title: "Unsupported parameter.",
|
|
130
|
-
controllerName: context.controllerName,
|
|
131
|
-
memberName: context.methodName,
|
|
132
|
-
detail: "A whole @Param() is not supported; provide a route parameter name such as @Param('id').",
|
|
133
|
-
filePath: context.filePath,
|
|
134
|
-
line: location.line,
|
|
135
|
-
column: location.column
|
|
136
|
-
});
|
|
137
|
-
return void 0;
|
|
138
|
-
}
|
|
139
|
-
return { ...base, kind: "param", name: argument.value };
|
|
140
|
-
}
|
|
141
|
-
if (decoratorName === "Headers") {
|
|
142
|
-
if (argument.value === void 0) {
|
|
143
|
-
context.diagnostics.push({
|
|
144
|
-
code: "unsupported-parameter",
|
|
145
|
-
title: "Unsupported parameter.",
|
|
146
|
-
controllerName: context.controllerName,
|
|
147
|
-
memberName: context.methodName,
|
|
148
|
-
detail: "A whole @Headers() is not supported; provide a header name such as @Headers('x-example').",
|
|
149
|
-
filePath: context.filePath,
|
|
150
|
-
line: location.line,
|
|
151
|
-
column: location.column
|
|
152
|
-
});
|
|
153
|
-
return void 0;
|
|
154
|
-
}
|
|
155
|
-
return { ...base, kind: "header", name: argument.value };
|
|
156
|
-
}
|
|
157
|
-
if (decoratorName === "Query") {
|
|
158
|
-
return { ...base, kind: "query", name: argument.value };
|
|
159
|
-
}
|
|
160
|
-
return { ...base, kind: "body", name: argument.value };
|
|
53
|
+
var locationOf = (sourceFile, node) => {
|
|
54
|
+
const { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile));
|
|
55
|
+
return {
|
|
56
|
+
line: line + 1,
|
|
57
|
+
column: character + 1
|
|
58
|
+
};
|
|
161
59
|
};
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
60
|
+
var SUPPORTED_PARAMETER_DECORATORS = [
|
|
61
|
+
"Param",
|
|
62
|
+
"Query",
|
|
63
|
+
"Body",
|
|
64
|
+
"Headers"
|
|
65
|
+
];
|
|
66
|
+
var KNOWN_UNSUPPORTED_PARAMETER_DECORATORS = [
|
|
67
|
+
"Req",
|
|
68
|
+
"Res",
|
|
69
|
+
"Request",
|
|
70
|
+
"Response"
|
|
71
|
+
];
|
|
72
|
+
var extractParameterDefinition = (parameter, index, context) => {
|
|
73
|
+
const decorator = findAnyDecorator(parameter, [...SUPPORTED_PARAMETER_DECORATORS, ...KNOWN_UNSUPPORTED_PARAMETER_DECORATORS]);
|
|
74
|
+
const location = locationOf(context.sourceFile, parameter);
|
|
75
|
+
if (decorator === void 0) {
|
|
76
|
+
context.diagnostics.push({
|
|
77
|
+
code: "unsupported-parameter",
|
|
78
|
+
title: "Unsupported parameter.",
|
|
79
|
+
controllerName: context.controllerName,
|
|
80
|
+
memberName: context.methodName,
|
|
81
|
+
detail: `Parameter "${parameter.name.getText()}" must be decorated with one of @Param, @Query, @Body, or @Headers to be transported through a NestBridge HTTP client.`,
|
|
82
|
+
filePath: context.filePath,
|
|
83
|
+
line: location.line,
|
|
84
|
+
column: location.column
|
|
85
|
+
});
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const decoratorName = decoratorNameOf(decorator);
|
|
89
|
+
if (decoratorName !== void 0 && KNOWN_UNSUPPORTED_PARAMETER_DECORATORS.includes(decoratorName)) {
|
|
90
|
+
context.diagnostics.push({
|
|
91
|
+
code: "unsupported-parameter",
|
|
92
|
+
title: "Unsupported parameter.",
|
|
93
|
+
controllerName: context.controllerName,
|
|
94
|
+
memberName: context.methodName,
|
|
95
|
+
detail: `@${decoratorName}() cannot be transported through a NestBridge HTTP client.`,
|
|
96
|
+
filePath: context.filePath,
|
|
97
|
+
line: location.line,
|
|
98
|
+
column: location.column
|
|
99
|
+
});
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (!isIdentifier(parameter.name)) {
|
|
103
|
+
context.diagnostics.push({
|
|
104
|
+
code: "unsupported-parameter",
|
|
105
|
+
title: "Unsupported parameter.",
|
|
106
|
+
controllerName: context.controllerName,
|
|
107
|
+
memberName: context.methodName,
|
|
108
|
+
detail: "Destructured parameters cannot be transported through a NestBridge HTTP client.",
|
|
109
|
+
filePath: context.filePath,
|
|
110
|
+
line: location.line,
|
|
111
|
+
column: location.column
|
|
112
|
+
});
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const argument = readStaticStringArgument(decorator);
|
|
116
|
+
if (!argument.ok) {
|
|
117
|
+
context.diagnostics.push({
|
|
118
|
+
code: "unsupported-parameter",
|
|
119
|
+
title: "Unsupported parameter.",
|
|
120
|
+
controllerName: context.controllerName,
|
|
121
|
+
memberName: context.methodName,
|
|
122
|
+
detail: `@${decoratorName}() arguments must be statically analyzable string literals.`,
|
|
123
|
+
found: `@${decoratorName}(${argument.argumentText})`,
|
|
124
|
+
filePath: context.filePath,
|
|
125
|
+
line: location.line,
|
|
126
|
+
column: location.column
|
|
127
|
+
});
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
const base = {
|
|
131
|
+
index,
|
|
132
|
+
parameterName: parameter.name.text
|
|
133
|
+
};
|
|
134
|
+
if (decoratorName === "Param") {
|
|
135
|
+
if (argument.value === void 0) {
|
|
136
|
+
context.diagnostics.push({
|
|
137
|
+
code: "unsupported-parameter",
|
|
138
|
+
title: "Unsupported parameter.",
|
|
139
|
+
controllerName: context.controllerName,
|
|
140
|
+
memberName: context.methodName,
|
|
141
|
+
detail: "A whole @Param() is not supported; provide a route parameter name such as @Param('id').",
|
|
142
|
+
filePath: context.filePath,
|
|
143
|
+
line: location.line,
|
|
144
|
+
column: location.column
|
|
145
|
+
});
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
return {
|
|
149
|
+
...base,
|
|
150
|
+
kind: "param",
|
|
151
|
+
name: argument.value
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
if (decoratorName === "Headers") {
|
|
155
|
+
if (argument.value === void 0) {
|
|
156
|
+
context.diagnostics.push({
|
|
157
|
+
code: "unsupported-parameter",
|
|
158
|
+
title: "Unsupported parameter.",
|
|
159
|
+
controllerName: context.controllerName,
|
|
160
|
+
memberName: context.methodName,
|
|
161
|
+
detail: "A whole @Headers() is not supported; provide a header name such as @Headers('x-example').",
|
|
162
|
+
filePath: context.filePath,
|
|
163
|
+
line: location.line,
|
|
164
|
+
column: location.column
|
|
165
|
+
});
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
return {
|
|
169
|
+
...base,
|
|
170
|
+
kind: "header",
|
|
171
|
+
name: argument.value
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
if (decoratorName === "Query") return {
|
|
175
|
+
...base,
|
|
176
|
+
kind: "query",
|
|
177
|
+
name: argument.value
|
|
178
|
+
};
|
|
179
|
+
return {
|
|
180
|
+
...base,
|
|
181
|
+
kind: "body",
|
|
182
|
+
name: argument.value
|
|
183
|
+
};
|
|
167
184
|
};
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
return typeNode;
|
|
185
|
+
var PRIMITIVE_SCALAR_TYPES = {
|
|
186
|
+
string: "String",
|
|
187
|
+
number: "Float",
|
|
188
|
+
boolean: "Boolean"
|
|
173
189
|
};
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
}
|
|
178
|
-
const nonNullMembers = typeNode.types.filter(
|
|
179
|
-
(member) => member.kind !== ts.SyntaxKind.NullKeyword && member.kind !== ts.SyntaxKind.UndefinedKeyword
|
|
180
|
-
);
|
|
181
|
-
const [onlyMember] = nonNullMembers;
|
|
182
|
-
if (nonNullMembers.length !== 1 || onlyMember === void 0) {
|
|
183
|
-
return { inner: typeNode, isNullable: nonNullMembers.length !== typeNode.types.length };
|
|
184
|
-
}
|
|
185
|
-
return { inner: onlyMember, isNullable: true };
|
|
190
|
+
var unwrapPromise = (typeNode) => {
|
|
191
|
+
if (isTypeReferenceNode(typeNode) && isIdentifier(typeNode.typeName) && typeNode.typeName.text === "Promise" && typeNode.typeArguments?.[0] !== void 0) return unwrapPromise(typeNode.typeArguments[0]);
|
|
192
|
+
return typeNode;
|
|
186
193
|
};
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
194
|
+
var unwrapNullable = (typeNode) => {
|
|
195
|
+
if (!isUnionTypeNode(typeNode)) return {
|
|
196
|
+
inner: typeNode,
|
|
197
|
+
isNullable: false
|
|
198
|
+
};
|
|
199
|
+
const nonNullMembers = typeNode.types.filter((member) => member.kind !== SyntaxKind.NullKeyword && member.kind !== SyntaxKind.UndefinedKeyword);
|
|
200
|
+
const [onlyMember] = nonNullMembers;
|
|
201
|
+
if (nonNullMembers.length !== 1 || onlyMember === void 0) return {
|
|
202
|
+
inner: typeNode,
|
|
203
|
+
isNullable: nonNullMembers.length !== typeNode.types.length
|
|
204
|
+
};
|
|
205
|
+
return {
|
|
206
|
+
inner: onlyMember,
|
|
207
|
+
isNullable: true
|
|
208
|
+
};
|
|
195
209
|
};
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
}
|
|
200
|
-
switch (typeNode.kind) {
|
|
201
|
-
case ts.SyntaxKind.StringKeyword:
|
|
202
|
-
return "string";
|
|
203
|
-
case ts.SyntaxKind.NumberKeyword:
|
|
204
|
-
return "number";
|
|
205
|
-
case ts.SyntaxKind.BooleanKeyword:
|
|
206
|
-
return "boolean";
|
|
207
|
-
default:
|
|
208
|
-
return void 0;
|
|
209
|
-
}
|
|
210
|
+
var unwrapArrayElement = (typeNode) => {
|
|
211
|
+
if (isArrayTypeNode(typeNode)) return typeNode.elementType;
|
|
212
|
+
if (isTypeReferenceNode(typeNode) && isIdentifier(typeNode.typeName) && typeNode.typeName.text === "Array" && typeNode.typeArguments?.[0] !== void 0) return typeNode.typeArguments[0];
|
|
210
213
|
};
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
}
|
|
220
|
-
return { identifierText, isArray: arrayElement !== void 0, isNullable };
|
|
214
|
+
var identifierTextOf = (typeNode) => {
|
|
215
|
+
if (isTypeReferenceNode(typeNode) && isIdentifier(typeNode.typeName)) return typeNode.typeName.text;
|
|
216
|
+
switch (typeNode.kind) {
|
|
217
|
+
case SyntaxKind.StringKeyword: return "string";
|
|
218
|
+
case SyntaxKind.NumberKeyword: return "number";
|
|
219
|
+
case SyntaxKind.BooleanKeyword: return "boolean";
|
|
220
|
+
default: return;
|
|
221
|
+
}
|
|
221
222
|
};
|
|
222
|
-
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
223
|
+
var unwrapTypeNode = (typeNode) => {
|
|
224
|
+
const { inner: withoutNullable, isNullable } = unwrapNullable(unwrapPromise(typeNode));
|
|
225
|
+
const arrayElement = unwrapArrayElement(withoutNullable);
|
|
226
|
+
const identifierText = identifierTextOf(arrayElement === void 0 ? withoutNullable : unwrapNullable(arrayElement).inner);
|
|
227
|
+
if (identifierText === void 0) return;
|
|
228
|
+
return {
|
|
229
|
+
identifierText,
|
|
230
|
+
isArray: arrayElement !== void 0,
|
|
231
|
+
isNullable
|
|
232
|
+
};
|
|
227
233
|
};
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
const
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
return "json";
|
|
234
|
-
}
|
|
235
|
-
const unwrapped = unwrapPromise(returnType);
|
|
236
|
-
if (!ts.isTypeReferenceNode(unwrapped) || !ts.isIdentifier(unwrapped.typeName)) {
|
|
237
|
-
return "json";
|
|
238
|
-
}
|
|
239
|
-
if (unwrapped.typeName.text === OBSERVABLE_TYPE_NAME) {
|
|
240
|
-
return "observable";
|
|
241
|
-
}
|
|
242
|
-
if (unwrapped.typeName.text === STREAMABLE_FILE_TYPE_NAME) {
|
|
243
|
-
return "stream";
|
|
244
|
-
}
|
|
245
|
-
return "json";
|
|
234
|
+
var graphqlScalarNameFor = (identifierText) => PRIMITIVE_SCALAR_TYPES[identifierText] ?? identifierText;
|
|
235
|
+
var graphqlTypeStringFor = (unwrapped, explicitTypeName) => {
|
|
236
|
+
const baseName = explicitTypeName ?? graphqlScalarNameFor(unwrapped.identifierText);
|
|
237
|
+
const wrapped = unwrapped.isArray ? `[${baseName}!]` : baseName;
|
|
238
|
+
return unwrapped.isNullable ? wrapped : `${wrapped}!`;
|
|
246
239
|
};
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
240
|
+
var OBSERVABLE_TYPE_NAME = "Observable";
|
|
241
|
+
var STREAMABLE_FILE_TYPE_NAME = "StreamableFile";
|
|
242
|
+
var readResponseKind = (returnType) => {
|
|
243
|
+
if (returnType === void 0) return "json";
|
|
244
|
+
const unwrapped = unwrapPromise(returnType);
|
|
245
|
+
if (!isTypeReferenceNode(unwrapped) || !isIdentifier(unwrapped.typeName)) return "json";
|
|
246
|
+
if (unwrapped.typeName.text === OBSERVABLE_TYPE_NAME) return "observable";
|
|
247
|
+
if (unwrapped.typeName.text === STREAMABLE_FILE_TYPE_NAME) return "stream";
|
|
248
|
+
return "json";
|
|
254
249
|
};
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
if (decorator === void 0) {
|
|
259
|
-
return void 0;
|
|
260
|
-
}
|
|
261
|
-
const methodName = method.name.getText();
|
|
262
|
-
const decoratorName = decoratorNameOf(decorator);
|
|
263
|
-
const location = locationOf(context.sourceFile, method);
|
|
264
|
-
if (decoratorName === void 0) {
|
|
265
|
-
return void 0;
|
|
266
|
-
}
|
|
267
|
-
const httpMethod = HTTP_METHOD_DECORATOR_NAMES[decoratorName];
|
|
268
|
-
if (httpMethod === void 0) {
|
|
269
|
-
return void 0;
|
|
270
|
-
}
|
|
271
|
-
const routeArgument = readStaticStringArgument(decorator);
|
|
272
|
-
if (!routeArgument.ok) {
|
|
273
|
-
context.diagnostics.push({
|
|
274
|
-
code: "unsupported-route",
|
|
275
|
-
title: "Unsupported route.",
|
|
276
|
-
controllerName: context.controllerName,
|
|
277
|
-
memberName: methodName,
|
|
278
|
-
detail: "Route paths must be statically analyzable.",
|
|
279
|
-
found: `@${decoratorName}(${routeArgument.argumentText})`,
|
|
280
|
-
filePath: context.filePath,
|
|
281
|
-
line: location.line,
|
|
282
|
-
column: location.column
|
|
283
|
-
});
|
|
284
|
-
return void 0;
|
|
285
|
-
}
|
|
286
|
-
const parameters = method.parameters.map(
|
|
287
|
-
(parameter, index) => extractParameterDefinition(parameter, index, {
|
|
288
|
-
sourceFile: context.sourceFile,
|
|
289
|
-
filePath: context.filePath,
|
|
290
|
-
controllerName: context.controllerName,
|
|
291
|
-
methodName,
|
|
292
|
-
diagnostics: context.diagnostics
|
|
293
|
-
})
|
|
294
|
-
);
|
|
295
|
-
if (parameters.some((parameter) => parameter === void 0)) {
|
|
296
|
-
return void 0;
|
|
297
|
-
}
|
|
298
|
-
return {
|
|
299
|
-
name: methodName,
|
|
300
|
-
httpMethod,
|
|
301
|
-
path: joinRoutePath(context.controllerPath, routeArgument.value),
|
|
302
|
-
parameters: parameters.filter((parameter) => parameter !== void 0),
|
|
303
|
-
responseKind: readResponseKind(method.type),
|
|
304
|
-
line: location.line,
|
|
305
|
-
column: location.column
|
|
306
|
-
};
|
|
250
|
+
var trimSlashes = (segment) => segment.replace(/^\/+/, "").replace(/\/+$/, "");
|
|
251
|
+
var joinRoutePath = (controllerPath, methodPath) => {
|
|
252
|
+
return `/${[trimSlashes(controllerPath), trimSlashes(methodPath ?? "")].filter((segment) => segment.length > 0).join("/")}`;
|
|
307
253
|
};
|
|
308
|
-
|
|
309
|
-
const
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
254
|
+
var extractMethodDefinition = (method, context) => {
|
|
255
|
+
const decorator = findAnyDecorator(method, Object.keys(HTTP_METHOD_DECORATOR_NAMES));
|
|
256
|
+
if (decorator === void 0) return;
|
|
257
|
+
const methodName = method.name.getText();
|
|
258
|
+
const decoratorName = decoratorNameOf(decorator);
|
|
259
|
+
const location = locationOf(context.sourceFile, method);
|
|
260
|
+
if (decoratorName === void 0) return;
|
|
261
|
+
const httpMethod = HTTP_METHOD_DECORATOR_NAMES[decoratorName];
|
|
262
|
+
if (httpMethod === void 0) return;
|
|
263
|
+
const routeArgument = readStaticStringArgument(decorator);
|
|
264
|
+
if (!routeArgument.ok) {
|
|
265
|
+
context.diagnostics.push({
|
|
266
|
+
code: "unsupported-route",
|
|
267
|
+
title: "Unsupported route.",
|
|
268
|
+
controllerName: context.controllerName,
|
|
269
|
+
memberName: methodName,
|
|
270
|
+
detail: "Route paths must be statically analyzable.",
|
|
271
|
+
found: `@${decoratorName}(${routeArgument.argumentText})`,
|
|
272
|
+
filePath: context.filePath,
|
|
273
|
+
line: location.line,
|
|
274
|
+
column: location.column
|
|
275
|
+
});
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
const parameters = method.parameters.map((parameter, index) => extractParameterDefinition(parameter, index, {
|
|
279
|
+
sourceFile: context.sourceFile,
|
|
280
|
+
filePath: context.filePath,
|
|
281
|
+
controllerName: context.controllerName,
|
|
282
|
+
methodName,
|
|
283
|
+
diagnostics: context.diagnostics
|
|
284
|
+
}));
|
|
285
|
+
if (parameters.some((parameter) => parameter === void 0)) return;
|
|
286
|
+
return {
|
|
287
|
+
name: methodName,
|
|
288
|
+
httpMethod,
|
|
289
|
+
path: joinRoutePath(context.controllerPath, routeArgument.value),
|
|
290
|
+
parameters: parameters.filter((parameter) => parameter !== void 0),
|
|
291
|
+
responseKind: readResponseKind(method.type),
|
|
292
|
+
line: location.line,
|
|
293
|
+
column: location.column
|
|
294
|
+
};
|
|
346
295
|
};
|
|
347
|
-
|
|
348
|
-
const
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
296
|
+
var extractControllerDefinition = (classDeclaration, sourceFile, filePath, diagnostics) => {
|
|
297
|
+
const controllerName = classDeclaration.name?.text ?? "(anonymous controller)";
|
|
298
|
+
const decorator = findDecorator(classDeclaration, "Controller");
|
|
299
|
+
if (decorator === void 0) return;
|
|
300
|
+
const location = locationOf(sourceFile, classDeclaration);
|
|
301
|
+
const argument = readStaticStringArgument(decorator);
|
|
302
|
+
if (!argument.ok) {
|
|
303
|
+
diagnostics.push({
|
|
304
|
+
code: "unsupported-route",
|
|
305
|
+
title: "Unsupported route.",
|
|
306
|
+
controllerName,
|
|
307
|
+
memberName: "",
|
|
308
|
+
detail: "Controller paths must be statically analyzable.",
|
|
309
|
+
found: `@Controller(${argument.argumentText})`,
|
|
310
|
+
filePath,
|
|
311
|
+
line: location.line,
|
|
312
|
+
column: location.column
|
|
313
|
+
});
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
const methods = classDeclaration.members.filter((member) => isMethodDeclaration(member)).map((method) => extractMethodDefinition(method, {
|
|
317
|
+
sourceFile,
|
|
318
|
+
filePath,
|
|
319
|
+
controllerName,
|
|
320
|
+
controllerPath: argument.value ?? "",
|
|
321
|
+
diagnostics
|
|
322
|
+
})).filter((method) => method !== void 0);
|
|
323
|
+
return {
|
|
324
|
+
name: controllerName,
|
|
325
|
+
path: argument.value ?? "",
|
|
326
|
+
sourceFile: filePath,
|
|
327
|
+
methods
|
|
328
|
+
};
|
|
352
329
|
};
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
const diagnostics = [];
|
|
356
|
-
const controllers = [];
|
|
357
|
-
for (const filePath of filePaths) {
|
|
358
|
-
const content = readFileSync(filePath, "utf-8");
|
|
359
|
-
const sourceFile = ts.createSourceFile(
|
|
360
|
-
filePath,
|
|
361
|
-
content,
|
|
362
|
-
ts.ScriptTarget.ESNext,
|
|
363
|
-
true,
|
|
364
|
-
ts.ScriptKind.TS
|
|
365
|
-
);
|
|
366
|
-
for (const classDeclaration of findControllerClasses(sourceFile)) {
|
|
367
|
-
const controller = extractControllerDefinition(
|
|
368
|
-
classDeclaration,
|
|
369
|
-
sourceFile,
|
|
370
|
-
filePath,
|
|
371
|
-
diagnostics
|
|
372
|
-
);
|
|
373
|
-
if (controller !== void 0) {
|
|
374
|
-
controllers.push(controller);
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
return { controllers, diagnostics };
|
|
330
|
+
var findControllerClasses = (sourceFile) => {
|
|
331
|
+
return sourceFile.statements.filter((statement) => isClassDeclaration(statement) && findDecorator(statement, "Controller") !== void 0);
|
|
379
332
|
};
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
333
|
+
var sharedApi;
|
|
334
|
+
var parseSourceFile = (filePath) => {
|
|
335
|
+
sharedApi ??= new API();
|
|
336
|
+
const sourceFile = sharedApi.updateSnapshot({ openFiles: [filePath] }).getDefaultProjectForFile(filePath)?.program.getSourceFile(filePath);
|
|
337
|
+
if (sourceFile === void 0) throw new Error(`Unable to parse source file: ${filePath}`);
|
|
338
|
+
return sourceFile;
|
|
384
339
|
};
|
|
385
|
-
|
|
386
|
-
const
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
340
|
+
var analyzeControllers = (filePaths) => {
|
|
341
|
+
const diagnostics = [];
|
|
342
|
+
const controllers = [];
|
|
343
|
+
for (const filePath of filePaths) {
|
|
344
|
+
const sourceFile = parseSourceFile(filePath);
|
|
345
|
+
for (const classDeclaration of findControllerClasses(sourceFile)) {
|
|
346
|
+
const controller = extractControllerDefinition(classDeclaration, sourceFile, filePath, diagnostics);
|
|
347
|
+
if (controller !== void 0) controllers.push(controller);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
return {
|
|
351
|
+
controllers,
|
|
352
|
+
diagnostics
|
|
353
|
+
};
|
|
392
354
|
};
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
return void 0;
|
|
397
|
-
}
|
|
398
|
-
const optionsArgument = decorator.expression.arguments.find(ts.isObjectLiteralExpression);
|
|
399
|
-
if (optionsArgument === void 0) {
|
|
400
|
-
return void 0;
|
|
401
|
-
}
|
|
402
|
-
const typeProperty = optionsArgument.properties.find(
|
|
403
|
-
(property) => ts.isPropertyAssignment(property) && ts.isIdentifier(property.name) && property.name.text === "type"
|
|
404
|
-
);
|
|
405
|
-
if (typeProperty === void 0) {
|
|
406
|
-
return void 0;
|
|
407
|
-
}
|
|
408
|
-
const thunk = typeProperty.initializer;
|
|
409
|
-
if (!ts.isArrowFunction(thunk) && !ts.isFunctionExpression(thunk)) {
|
|
410
|
-
return void 0;
|
|
411
|
-
}
|
|
412
|
-
const returnedExpression = readTypeThunkExpression(thunk);
|
|
413
|
-
if (returnedExpression === void 0) {
|
|
414
|
-
return void 0;
|
|
415
|
-
}
|
|
416
|
-
if (ts.isArrayLiteralExpression(returnedExpression)) {
|
|
417
|
-
const element = returnedExpression.elements[0];
|
|
418
|
-
return element !== void 0 && ts.isIdentifier(element) ? { typeName: element.text, isArray: true } : void 0;
|
|
419
|
-
}
|
|
420
|
-
return ts.isIdentifier(returnedExpression) ? { typeName: returnedExpression.text, isArray: false } : void 0;
|
|
355
|
+
var GRAPHQL_OPERATION_DECORATOR_NAMES = {
|
|
356
|
+
Query: "query",
|
|
357
|
+
Mutation: "mutation"
|
|
421
358
|
};
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
const location = locationOf(context.sourceFile, parameter);
|
|
426
|
-
if (decorator === void 0) {
|
|
427
|
-
context.diagnostics.push({
|
|
428
|
-
code: "unsupported-argument",
|
|
429
|
-
title: "Unsupported argument.",
|
|
430
|
-
controllerName: context.resolverName,
|
|
431
|
-
memberName: context.methodName,
|
|
432
|
-
detail: `Parameter "${parameter.name.getText()}" must be decorated with @Args to be transported through a NestBridge GraphQL client.`,
|
|
433
|
-
filePath: context.filePath,
|
|
434
|
-
line: location.line,
|
|
435
|
-
column: location.column
|
|
436
|
-
});
|
|
437
|
-
return void 0;
|
|
438
|
-
}
|
|
439
|
-
if (!ts.isIdentifier(parameter.name)) {
|
|
440
|
-
context.diagnostics.push({
|
|
441
|
-
code: "unsupported-argument",
|
|
442
|
-
title: "Unsupported argument.",
|
|
443
|
-
controllerName: context.resolverName,
|
|
444
|
-
memberName: context.methodName,
|
|
445
|
-
detail: "Destructured parameters cannot be transported through a NestBridge GraphQL client.",
|
|
446
|
-
filePath: context.filePath,
|
|
447
|
-
line: location.line,
|
|
448
|
-
column: location.column
|
|
449
|
-
});
|
|
450
|
-
return void 0;
|
|
451
|
-
}
|
|
452
|
-
const nameArgument = readStaticStringArgument(decorator);
|
|
453
|
-
if (!nameArgument.ok) {
|
|
454
|
-
context.diagnostics.push({
|
|
455
|
-
code: "unsupported-argument",
|
|
456
|
-
title: "Unsupported argument.",
|
|
457
|
-
controllerName: context.resolverName,
|
|
458
|
-
memberName: context.methodName,
|
|
459
|
-
detail: "@Args() name must be a statically analyzable string literal.",
|
|
460
|
-
found: `@Args(${nameArgument.argumentText})`,
|
|
461
|
-
filePath: context.filePath,
|
|
462
|
-
line: location.line,
|
|
463
|
-
column: location.column
|
|
464
|
-
});
|
|
465
|
-
return void 0;
|
|
466
|
-
}
|
|
467
|
-
if (nameArgument.value === void 0) {
|
|
468
|
-
context.diagnostics.push({
|
|
469
|
-
code: "unsupported-argument",
|
|
470
|
-
title: "Unsupported argument.",
|
|
471
|
-
controllerName: context.resolverName,
|
|
472
|
-
memberName: context.methodName,
|
|
473
|
-
detail: "A whole @Args() is not supported; provide an argument name such as @Args('id').",
|
|
474
|
-
filePath: context.filePath,
|
|
475
|
-
line: location.line,
|
|
476
|
-
column: location.column
|
|
477
|
-
});
|
|
478
|
-
return void 0;
|
|
479
|
-
}
|
|
480
|
-
if (parameter.type === void 0) {
|
|
481
|
-
context.diagnostics.push({
|
|
482
|
-
code: "unsupported-argument",
|
|
483
|
-
title: "Unsupported argument.",
|
|
484
|
-
controllerName: context.resolverName,
|
|
485
|
-
memberName: context.methodName,
|
|
486
|
-
detail: `@Args() parameter "${parameter.name.text}" needs an explicit type annotation.`,
|
|
487
|
-
filePath: context.filePath,
|
|
488
|
-
line: location.line,
|
|
489
|
-
column: location.column
|
|
490
|
-
});
|
|
491
|
-
return void 0;
|
|
492
|
-
}
|
|
493
|
-
const unwrapped = unwrapTypeNode(parameter.type);
|
|
494
|
-
if (unwrapped === void 0) {
|
|
495
|
-
context.diagnostics.push({
|
|
496
|
-
code: "unsupported-argument",
|
|
497
|
-
title: "Unsupported argument.",
|
|
498
|
-
controllerName: context.resolverName,
|
|
499
|
-
memberName: context.methodName,
|
|
500
|
-
detail: `@Args() parameter "${parameter.name.text}" has a type NestBridge cannot statically resolve to a GraphQL type.`,
|
|
501
|
-
found: parameter.type.getText(),
|
|
502
|
-
filePath: context.filePath,
|
|
503
|
-
line: location.line,
|
|
504
|
-
column: location.column
|
|
505
|
-
});
|
|
506
|
-
return void 0;
|
|
507
|
-
}
|
|
508
|
-
const explicitType = readArgsTypeOption(decorator);
|
|
509
|
-
return {
|
|
510
|
-
index,
|
|
511
|
-
parameterName: parameter.name.text,
|
|
512
|
-
name: nameArgument.value,
|
|
513
|
-
graphqlType: graphqlTypeStringFor(unwrapped, explicitType?.typeName)
|
|
514
|
-
};
|
|
359
|
+
var readTypeThunkExpression = (thunk) => {
|
|
360
|
+
if (!isBlock(thunk.body)) return thunk.body;
|
|
361
|
+
return thunk.body.statements.find(isReturnStatement)?.expression;
|
|
515
362
|
};
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
const
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
363
|
+
var readArgsTypeOption = (decorator) => {
|
|
364
|
+
if (!isCallExpression(decorator.expression)) return;
|
|
365
|
+
const optionsArgument = decorator.expression.arguments.find(isObjectLiteralExpression);
|
|
366
|
+
if (optionsArgument === void 0) return;
|
|
367
|
+
const typeProperty = optionsArgument.properties.find((property) => isPropertyAssignment(property) && isIdentifier(property.name) && property.name.text === "type");
|
|
368
|
+
if (typeProperty === void 0) return;
|
|
369
|
+
const thunk = typeProperty.initializer;
|
|
370
|
+
if (!isArrowFunction(thunk) && !isFunctionExpression(thunk)) return;
|
|
371
|
+
const returnedExpression = readTypeThunkExpression(thunk);
|
|
372
|
+
if (returnedExpression === void 0) return;
|
|
373
|
+
if (isArrayLiteralExpression(returnedExpression)) {
|
|
374
|
+
const element = returnedExpression.elements[0];
|
|
375
|
+
return element !== void 0 && isIdentifier(element) ? {
|
|
376
|
+
typeName: element.text,
|
|
377
|
+
isArray: true
|
|
378
|
+
} : void 0;
|
|
379
|
+
}
|
|
380
|
+
return isIdentifier(returnedExpression) ? {
|
|
381
|
+
typeName: returnedExpression.text,
|
|
382
|
+
isArray: false
|
|
383
|
+
} : void 0;
|
|
533
384
|
};
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
385
|
+
var extractResolverArgumentDefinition = (parameter, index, context) => {
|
|
386
|
+
const decorator = findAnyDecorator(parameter, ["Args"]);
|
|
387
|
+
const location = locationOf(context.sourceFile, parameter);
|
|
388
|
+
if (decorator === void 0) {
|
|
389
|
+
context.diagnostics.push({
|
|
390
|
+
code: "unsupported-argument",
|
|
391
|
+
title: "Unsupported argument.",
|
|
392
|
+
controllerName: context.resolverName,
|
|
393
|
+
memberName: context.methodName,
|
|
394
|
+
detail: `Parameter "${parameter.name.getText()}" must be decorated with @Args to be transported through a NestBridge GraphQL client.`,
|
|
395
|
+
filePath: context.filePath,
|
|
396
|
+
line: location.line,
|
|
397
|
+
column: location.column
|
|
398
|
+
});
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
if (!isIdentifier(parameter.name)) {
|
|
402
|
+
context.diagnostics.push({
|
|
403
|
+
code: "unsupported-argument",
|
|
404
|
+
title: "Unsupported argument.",
|
|
405
|
+
controllerName: context.resolverName,
|
|
406
|
+
memberName: context.methodName,
|
|
407
|
+
detail: "Destructured parameters cannot be transported through a NestBridge GraphQL client.",
|
|
408
|
+
filePath: context.filePath,
|
|
409
|
+
line: location.line,
|
|
410
|
+
column: location.column
|
|
411
|
+
});
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
const nameArgument = readStaticStringArgument(decorator);
|
|
415
|
+
if (!nameArgument.ok) {
|
|
416
|
+
context.diagnostics.push({
|
|
417
|
+
code: "unsupported-argument",
|
|
418
|
+
title: "Unsupported argument.",
|
|
419
|
+
controllerName: context.resolverName,
|
|
420
|
+
memberName: context.methodName,
|
|
421
|
+
detail: "@Args() name must be a statically analyzable string literal.",
|
|
422
|
+
found: `@Args(${nameArgument.argumentText})`,
|
|
423
|
+
filePath: context.filePath,
|
|
424
|
+
line: location.line,
|
|
425
|
+
column: location.column
|
|
426
|
+
});
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
if (nameArgument.value === void 0) {
|
|
430
|
+
context.diagnostics.push({
|
|
431
|
+
code: "unsupported-argument",
|
|
432
|
+
title: "Unsupported argument.",
|
|
433
|
+
controllerName: context.resolverName,
|
|
434
|
+
memberName: context.methodName,
|
|
435
|
+
detail: "A whole @Args() is not supported; provide an argument name such as @Args('id').",
|
|
436
|
+
filePath: context.filePath,
|
|
437
|
+
line: location.line,
|
|
438
|
+
column: location.column
|
|
439
|
+
});
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
if (parameter.type === void 0) {
|
|
443
|
+
context.diagnostics.push({
|
|
444
|
+
code: "unsupported-argument",
|
|
445
|
+
title: "Unsupported argument.",
|
|
446
|
+
controllerName: context.resolverName,
|
|
447
|
+
memberName: context.methodName,
|
|
448
|
+
detail: `@Args() parameter "${parameter.name.text}" needs an explicit type annotation.`,
|
|
449
|
+
filePath: context.filePath,
|
|
450
|
+
line: location.line,
|
|
451
|
+
column: location.column
|
|
452
|
+
});
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
const unwrapped = unwrapTypeNode(parameter.type);
|
|
456
|
+
if (unwrapped === void 0) {
|
|
457
|
+
context.diagnostics.push({
|
|
458
|
+
code: "unsupported-argument",
|
|
459
|
+
title: "Unsupported argument.",
|
|
460
|
+
controllerName: context.resolverName,
|
|
461
|
+
memberName: context.methodName,
|
|
462
|
+
detail: `@Args() parameter "${parameter.name.text}" has a type NestBridge cannot statically resolve to a GraphQL type.`,
|
|
463
|
+
found: parameter.type.getText(),
|
|
464
|
+
filePath: context.filePath,
|
|
465
|
+
line: location.line,
|
|
466
|
+
column: location.column
|
|
467
|
+
});
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
const explicitType = readArgsTypeOption(decorator);
|
|
471
|
+
return {
|
|
472
|
+
index,
|
|
473
|
+
parameterName: parameter.name.text,
|
|
474
|
+
name: nameArgument.value,
|
|
475
|
+
graphqlType: graphqlTypeStringFor(unwrapped, explicitType?.typeName)
|
|
476
|
+
};
|
|
541
477
|
};
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
);
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
}
|
|
550
|
-
const namedBindings = statement.importClause?.namedBindings;
|
|
551
|
-
if (namedBindings === void 0 || !ts.isNamedImports(namedBindings)) {
|
|
552
|
-
continue;
|
|
553
|
-
}
|
|
554
|
-
const element = namedBindings.elements.find((candidate) => candidate.name.text === localName);
|
|
555
|
-
if (element !== void 0) {
|
|
556
|
-
return {
|
|
557
|
-
moduleSpecifierText: statement.moduleSpecifier.text,
|
|
558
|
-
importedName: element.propertyName?.text ?? element.name.text
|
|
559
|
-
};
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
return void 0;
|
|
478
|
+
var parsedFilesByPath = /* @__PURE__ */ new Map();
|
|
479
|
+
var parseFile = (filePath) => {
|
|
480
|
+
const cached = parsedFilesByPath.get(filePath);
|
|
481
|
+
if (cached !== void 0) return cached;
|
|
482
|
+
const sourceFile = parseSourceFile(filePath);
|
|
483
|
+
parsedFilesByPath.set(filePath, sourceFile);
|
|
484
|
+
return sourceFile;
|
|
563
485
|
};
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
if (ts.isNamedExports(statement.exportClause) && statement.exportClause.elements.some(
|
|
573
|
-
(element) => (element.propertyName?.text ?? element.name.text) === name
|
|
574
|
-
)) {
|
|
575
|
-
return statement.moduleSpecifier.text;
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
return void 0;
|
|
486
|
+
var resolveModuleFile = (fromFilePath, moduleSpecifierText) => {
|
|
487
|
+
if (!moduleSpecifierText.startsWith(".")) return;
|
|
488
|
+
const base = resolve(dirname(fromFilePath), moduleSpecifierText);
|
|
489
|
+
return [
|
|
490
|
+
`${base}.ts`,
|
|
491
|
+
`${base}.tsx`,
|
|
492
|
+
resolve(base, "index.ts")
|
|
493
|
+
].find((candidate) => existsSync(candidate));
|
|
579
494
|
};
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
if (resolvedPath !== void 0) {
|
|
593
|
-
const nextSourceFile = parseFile(resolvedPath);
|
|
594
|
-
const result = resolveClassDeclaration(
|
|
595
|
-
importSource.importedName,
|
|
596
|
-
nextSourceFile,
|
|
597
|
-
resolvedPath,
|
|
598
|
-
visited
|
|
599
|
-
);
|
|
600
|
-
if (result !== void 0) {
|
|
601
|
-
return result;
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
const reExportModuleSpecifierText = findReExportSource(fromSourceFile, name);
|
|
606
|
-
if (reExportModuleSpecifierText !== void 0) {
|
|
607
|
-
const resolvedPath = resolveModuleFile(fromFilePath, reExportModuleSpecifierText);
|
|
608
|
-
if (resolvedPath !== void 0) {
|
|
609
|
-
const nextSourceFile = parseFile(resolvedPath);
|
|
610
|
-
return resolveClassDeclaration(name, nextSourceFile, resolvedPath, visited);
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
|
-
return void 0;
|
|
495
|
+
var findExportedDeclaration = (sourceFile, name) => sourceFile.statements.find((statement) => isClassDeclaration(statement) && statement.name?.text === name);
|
|
496
|
+
var findImportSource = (sourceFile, localName) => {
|
|
497
|
+
for (const statement of sourceFile.statements) {
|
|
498
|
+
if (!isImportDeclaration(statement) || !isStringLiteralLikeNode(statement.moduleSpecifier)) continue;
|
|
499
|
+
const namedBindings = statement.importClause?.namedBindings;
|
|
500
|
+
if (namedBindings === void 0 || !isNamedImports(namedBindings)) continue;
|
|
501
|
+
const element = namedBindings.elements.find((candidate) => candidate.name.text === localName);
|
|
502
|
+
if (element !== void 0) return {
|
|
503
|
+
moduleSpecifierText: statement.moduleSpecifier.text,
|
|
504
|
+
importedName: element.propertyName?.text ?? element.name.text
|
|
505
|
+
};
|
|
506
|
+
}
|
|
614
507
|
};
|
|
615
|
-
|
|
616
|
-
const
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
context.diagnostics.push({
|
|
622
|
-
code: "circular-type",
|
|
623
|
-
title: "Circular type.",
|
|
624
|
-
controllerName: context.resolverName,
|
|
625
|
-
memberName: context.methodName,
|
|
626
|
-
detail: `Type "${typeName}" references itself, directly or indirectly. NestBridge cannot build a finite GraphQL selection set for it.`,
|
|
627
|
-
filePath,
|
|
628
|
-
line: location.line,
|
|
629
|
-
column: location.column
|
|
630
|
-
});
|
|
631
|
-
return void 0;
|
|
632
|
-
}
|
|
633
|
-
const nextVisited = new Set(context.visitedTypeNames).add(typeName);
|
|
634
|
-
const properties = classDeclaration.members.filter(
|
|
635
|
-
(member) => ts.isPropertyDeclaration(member) && findDecorator(member, "Field") !== void 0
|
|
636
|
-
);
|
|
637
|
-
const fields = [];
|
|
638
|
-
for (const property of properties) {
|
|
639
|
-
if (!ts.isIdentifier(property.name)) {
|
|
640
|
-
continue;
|
|
641
|
-
}
|
|
642
|
-
const fieldName = property.name.text;
|
|
643
|
-
const fieldLocation = locationOf(sourceFile, property);
|
|
644
|
-
if (property.type === void 0) {
|
|
645
|
-
context.diagnostics.push({
|
|
646
|
-
code: "unsupported-return-type",
|
|
647
|
-
title: "Unsupported field type.",
|
|
648
|
-
controllerName: context.resolverName,
|
|
649
|
-
memberName: context.methodName,
|
|
650
|
-
detail: `Field "${fieldName}" on "${typeName}" needs an explicit type annotation.`,
|
|
651
|
-
filePath,
|
|
652
|
-
line: fieldLocation.line,
|
|
653
|
-
column: fieldLocation.column
|
|
654
|
-
});
|
|
655
|
-
return void 0;
|
|
656
|
-
}
|
|
657
|
-
const unwrapped = unwrapTypeNode(property.type);
|
|
658
|
-
if (unwrapped === void 0) {
|
|
659
|
-
context.diagnostics.push({
|
|
660
|
-
code: "unsupported-return-type",
|
|
661
|
-
title: "Unsupported field type.",
|
|
662
|
-
controllerName: context.resolverName,
|
|
663
|
-
memberName: context.methodName,
|
|
664
|
-
detail: `Field "${fieldName}" on "${typeName}" has a type NestBridge cannot statically resolve.`,
|
|
665
|
-
found: property.type.getText(),
|
|
666
|
-
filePath,
|
|
667
|
-
line: fieldLocation.line,
|
|
668
|
-
column: fieldLocation.column
|
|
669
|
-
});
|
|
670
|
-
return void 0;
|
|
671
|
-
}
|
|
672
|
-
if (PRIMITIVE_SCALAR_NAMES$1.has(unwrapped.identifierText)) {
|
|
673
|
-
fields.push({ name: fieldName });
|
|
674
|
-
continue;
|
|
675
|
-
}
|
|
676
|
-
const resolved = resolveClassDeclaration(unwrapped.identifierText, sourceFile, filePath);
|
|
677
|
-
if (resolved === void 0) {
|
|
678
|
-
fields.push({ name: fieldName });
|
|
679
|
-
continue;
|
|
680
|
-
}
|
|
681
|
-
if (findDecorator(resolved.classDeclaration, "ObjectType") === void 0) {
|
|
682
|
-
context.diagnostics.push({
|
|
683
|
-
code: "unsupported-return-type",
|
|
684
|
-
title: "Unsupported field type.",
|
|
685
|
-
controllerName: context.resolverName,
|
|
686
|
-
memberName: context.methodName,
|
|
687
|
-
detail: `Field "${fieldName}" on "${typeName}" resolves to class "${unwrapped.identifierText}", which is not decorated with @ObjectType(). NestBridge cannot build a GraphQL selection set for it.`,
|
|
688
|
-
filePath,
|
|
689
|
-
line: fieldLocation.line,
|
|
690
|
-
column: fieldLocation.column
|
|
691
|
-
});
|
|
692
|
-
return void 0;
|
|
693
|
-
}
|
|
694
|
-
const children = extractSelectionFields(
|
|
695
|
-
resolved.classDeclaration,
|
|
696
|
-
resolved.sourceFile,
|
|
697
|
-
resolved.filePath,
|
|
698
|
-
{
|
|
699
|
-
...context,
|
|
700
|
-
visitedTypeNames: nextVisited
|
|
701
|
-
}
|
|
702
|
-
);
|
|
703
|
-
if (children === void 0) {
|
|
704
|
-
return void 0;
|
|
705
|
-
}
|
|
706
|
-
fields.push({ name: fieldName, children });
|
|
707
|
-
}
|
|
708
|
-
return fields;
|
|
508
|
+
var findReExportSource = (sourceFile, name) => {
|
|
509
|
+
for (const statement of sourceFile.statements) {
|
|
510
|
+
if (!isExportDeclaration(statement) || statement.moduleSpecifier === void 0 || !isStringLiteralLikeNode(statement.moduleSpecifier)) continue;
|
|
511
|
+
if (statement.exportClause === void 0) return statement.moduleSpecifier.text;
|
|
512
|
+
if (isNamedExports(statement.exportClause) && statement.exportClause.elements.some((element) => (element.propertyName?.text ?? element.name.text) === name)) return statement.moduleSpecifier.text;
|
|
513
|
+
}
|
|
709
514
|
};
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
515
|
+
var resolveClassDeclaration = (name, fromSourceFile, fromFilePath, visited = /* @__PURE__ */ new Set()) => {
|
|
516
|
+
if (visited.has(fromFilePath)) return;
|
|
517
|
+
visited.add(fromFilePath);
|
|
518
|
+
const direct = findExportedDeclaration(fromSourceFile, name);
|
|
519
|
+
if (direct !== void 0) return {
|
|
520
|
+
classDeclaration: direct,
|
|
521
|
+
sourceFile: fromSourceFile,
|
|
522
|
+
filePath: fromFilePath
|
|
523
|
+
};
|
|
524
|
+
const importSource = findImportSource(fromSourceFile, name);
|
|
525
|
+
if (importSource !== void 0) {
|
|
526
|
+
const resolvedPath = resolveModuleFile(fromFilePath, importSource.moduleSpecifierText);
|
|
527
|
+
if (resolvedPath !== void 0) {
|
|
528
|
+
const nextSourceFile = parseFile(resolvedPath);
|
|
529
|
+
const result = resolveClassDeclaration(importSource.importedName, nextSourceFile, resolvedPath, visited);
|
|
530
|
+
if (result !== void 0) return result;
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
const reExportModuleSpecifierText = findReExportSource(fromSourceFile, name);
|
|
534
|
+
if (reExportModuleSpecifierText !== void 0) {
|
|
535
|
+
const resolvedPath = resolveModuleFile(fromFilePath, reExportModuleSpecifierText);
|
|
536
|
+
if (resolvedPath !== void 0) return resolveClassDeclaration(name, parseFile(resolvedPath), resolvedPath, visited);
|
|
537
|
+
}
|
|
719
538
|
};
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
539
|
+
var PRIMITIVE_SCALAR_NAMES$1 = /* @__PURE__ */ new Set([
|
|
540
|
+
"string",
|
|
541
|
+
"number",
|
|
542
|
+
"boolean"
|
|
543
|
+
]);
|
|
544
|
+
var extractSelectionFields = (classDeclaration, sourceFile, filePath, context) => {
|
|
545
|
+
const typeName = classDeclaration.name?.text ?? "(anonymous type)";
|
|
546
|
+
const location = locationOf(sourceFile, classDeclaration);
|
|
547
|
+
if (context.visitedTypeNames.has(typeName)) {
|
|
548
|
+
context.diagnostics.push({
|
|
549
|
+
code: "circular-type",
|
|
550
|
+
title: "Circular type.",
|
|
551
|
+
controllerName: context.resolverName,
|
|
552
|
+
memberName: context.methodName,
|
|
553
|
+
detail: `Type "${typeName}" references itself, directly or indirectly. NestBridge cannot build a finite GraphQL selection set for it.`,
|
|
554
|
+
filePath,
|
|
555
|
+
line: location.line,
|
|
556
|
+
column: location.column
|
|
557
|
+
});
|
|
558
|
+
return;
|
|
559
|
+
}
|
|
560
|
+
const nextVisited = new Set(context.visitedTypeNames).add(typeName);
|
|
561
|
+
const properties = classDeclaration.members.filter((member) => isPropertyDeclaration(member) && findDecorator(member, "Field") !== void 0);
|
|
562
|
+
const fields = [];
|
|
563
|
+
for (const property of properties) {
|
|
564
|
+
if (!isIdentifier(property.name)) continue;
|
|
565
|
+
const fieldName = property.name.text;
|
|
566
|
+
const fieldLocation = locationOf(sourceFile, property);
|
|
567
|
+
if (property.type === void 0) {
|
|
568
|
+
context.diagnostics.push({
|
|
569
|
+
code: "unsupported-return-type",
|
|
570
|
+
title: "Unsupported field type.",
|
|
571
|
+
controllerName: context.resolverName,
|
|
572
|
+
memberName: context.methodName,
|
|
573
|
+
detail: `Field "${fieldName}" on "${typeName}" needs an explicit type annotation.`,
|
|
574
|
+
filePath,
|
|
575
|
+
line: fieldLocation.line,
|
|
576
|
+
column: fieldLocation.column
|
|
577
|
+
});
|
|
578
|
+
return;
|
|
579
|
+
}
|
|
580
|
+
const unwrapped = unwrapTypeNode(property.type);
|
|
581
|
+
if (unwrapped === void 0) {
|
|
582
|
+
context.diagnostics.push({
|
|
583
|
+
code: "unsupported-return-type",
|
|
584
|
+
title: "Unsupported field type.",
|
|
585
|
+
controllerName: context.resolverName,
|
|
586
|
+
memberName: context.methodName,
|
|
587
|
+
detail: `Field "${fieldName}" on "${typeName}" has a type NestBridge cannot statically resolve.`,
|
|
588
|
+
found: property.type.getText(),
|
|
589
|
+
filePath,
|
|
590
|
+
line: fieldLocation.line,
|
|
591
|
+
column: fieldLocation.column
|
|
592
|
+
});
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
if (PRIMITIVE_SCALAR_NAMES$1.has(unwrapped.identifierText)) {
|
|
596
|
+
fields.push({ name: fieldName });
|
|
597
|
+
continue;
|
|
598
|
+
}
|
|
599
|
+
const resolved = resolveClassDeclaration(unwrapped.identifierText, sourceFile, filePath);
|
|
600
|
+
if (resolved === void 0) {
|
|
601
|
+
fields.push({ name: fieldName });
|
|
602
|
+
continue;
|
|
603
|
+
}
|
|
604
|
+
if (findDecorator(resolved.classDeclaration, "ObjectType") === void 0) {
|
|
605
|
+
context.diagnostics.push({
|
|
606
|
+
code: "unsupported-return-type",
|
|
607
|
+
title: "Unsupported field type.",
|
|
608
|
+
controllerName: context.resolverName,
|
|
609
|
+
memberName: context.methodName,
|
|
610
|
+
detail: `Field "${fieldName}" on "${typeName}" resolves to class "${unwrapped.identifierText}", which is not decorated with @ObjectType(). NestBridge cannot build a GraphQL selection set for it.`,
|
|
611
|
+
filePath,
|
|
612
|
+
line: fieldLocation.line,
|
|
613
|
+
column: fieldLocation.column
|
|
614
|
+
});
|
|
615
|
+
return;
|
|
616
|
+
}
|
|
617
|
+
const children = extractSelectionFields(resolved.classDeclaration, resolved.sourceFile, resolved.filePath, {
|
|
618
|
+
...context,
|
|
619
|
+
visitedTypeNames: nextVisited
|
|
620
|
+
});
|
|
621
|
+
if (children === void 0) return;
|
|
622
|
+
fields.push({
|
|
623
|
+
name: fieldName,
|
|
624
|
+
children
|
|
625
|
+
});
|
|
626
|
+
}
|
|
627
|
+
return fields;
|
|
741
628
|
};
|
|
742
|
-
|
|
743
|
-
const
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
}
|
|
747
|
-
const thunk = decorator.expression.arguments.find(
|
|
748
|
-
(argument) => ts.isArrowFunction(argument) || ts.isFunctionExpression(argument)
|
|
749
|
-
);
|
|
750
|
-
if (thunk === void 0) {
|
|
751
|
-
return void 0;
|
|
752
|
-
}
|
|
753
|
-
const returnedExpression = readTypeThunkExpression(thunk);
|
|
754
|
-
if (returnedExpression === void 0) {
|
|
755
|
-
return void 0;
|
|
756
|
-
}
|
|
757
|
-
if (ts.isArrayLiteralExpression(returnedExpression)) {
|
|
758
|
-
const element = returnedExpression.elements[0];
|
|
759
|
-
return element !== void 0 && ts.isIdentifier(element) ? element.text : void 0;
|
|
760
|
-
}
|
|
761
|
-
return ts.isIdentifier(returnedExpression) ? returnedExpression.text : void 0;
|
|
629
|
+
var readNameFromOptions = (optionsArgument) => {
|
|
630
|
+
const nameProperty = optionsArgument.properties.find((property) => isPropertyAssignment(property) && isIdentifier(property.name) && property.name.text === "name");
|
|
631
|
+
if (nameProperty === void 0 || !isStringLiteralLikeNode(nameProperty.initializer)) return;
|
|
632
|
+
return nameProperty.initializer.text;
|
|
762
633
|
};
|
|
763
|
-
|
|
764
|
-
const
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
filePath: context.filePath,
|
|
790
|
-
line: location.line,
|
|
791
|
-
column: location.column
|
|
792
|
-
});
|
|
793
|
-
return void 0;
|
|
794
|
-
}
|
|
795
|
-
const decoratorReturnType = readGraphqlReturnTypeOption(decorator);
|
|
796
|
-
const identifierText = decoratorReturnType ?? (method.type === void 0 ? void 0 : unwrapTypeNode(method.type)?.identifierText);
|
|
797
|
-
if (identifierText === void 0) {
|
|
798
|
-
context.diagnostics.push({
|
|
799
|
-
code: "unsupported-return-type",
|
|
800
|
-
title: "Unsupported return type.",
|
|
801
|
-
controllerName: context.resolverName,
|
|
802
|
-
memberName: methodName,
|
|
803
|
-
detail: 'GraphQL resolver methods need a type thunk on @Query()/@Mutation() (e.g. "() => UserType") or an explicit return type annotation so NestBridge can build a selection set.',
|
|
804
|
-
filePath: context.filePath,
|
|
805
|
-
line: location.line,
|
|
806
|
-
column: location.column
|
|
807
|
-
});
|
|
808
|
-
return void 0;
|
|
809
|
-
}
|
|
810
|
-
let selection = [];
|
|
811
|
-
if (!PRIMITIVE_SCALAR_NAMES.has(identifierText.toLowerCase())) {
|
|
812
|
-
const resolved = resolveClassDeclaration(identifierText, context.sourceFile, context.filePath);
|
|
813
|
-
if (resolved === void 0 && decoratorReturnType === void 0) {
|
|
814
|
-
context.diagnostics.push({
|
|
815
|
-
code: "unsupported-return-type",
|
|
816
|
-
title: "Unsupported return type.",
|
|
817
|
-
controllerName: context.resolverName,
|
|
818
|
-
memberName: methodName,
|
|
819
|
-
detail: `NestBridge could not locate the declaration of type "${identifierText}".`,
|
|
820
|
-
filePath: context.filePath,
|
|
821
|
-
line: location.line,
|
|
822
|
-
column: location.column
|
|
823
|
-
});
|
|
824
|
-
return void 0;
|
|
825
|
-
}
|
|
826
|
-
if (resolved !== void 0) {
|
|
827
|
-
const fields = extractSelectionFields(
|
|
828
|
-
resolved.classDeclaration,
|
|
829
|
-
resolved.sourceFile,
|
|
830
|
-
resolved.filePath,
|
|
831
|
-
{
|
|
832
|
-
resolverName: context.resolverName,
|
|
833
|
-
methodName,
|
|
834
|
-
diagnostics: context.diagnostics,
|
|
835
|
-
visitedTypeNames: /* @__PURE__ */ new Set()
|
|
836
|
-
}
|
|
837
|
-
);
|
|
838
|
-
if (fields === void 0) {
|
|
839
|
-
return void 0;
|
|
840
|
-
}
|
|
841
|
-
selection = fields;
|
|
842
|
-
}
|
|
843
|
-
}
|
|
844
|
-
const args = method.parameters.map(
|
|
845
|
-
(parameter, index) => extractResolverArgumentDefinition(parameter, index, {
|
|
846
|
-
sourceFile: context.sourceFile,
|
|
847
|
-
filePath: context.filePath,
|
|
848
|
-
resolverName: context.resolverName,
|
|
849
|
-
methodName,
|
|
850
|
-
diagnostics: context.diagnostics
|
|
851
|
-
})
|
|
852
|
-
);
|
|
853
|
-
if (args.some((argument) => argument === void 0)) {
|
|
854
|
-
return void 0;
|
|
855
|
-
}
|
|
856
|
-
return {
|
|
857
|
-
name: methodName,
|
|
858
|
-
operationKind,
|
|
859
|
-
operationName: nameArgument.value ?? methodName,
|
|
860
|
-
arguments: args.filter((argument) => argument !== void 0),
|
|
861
|
-
selection,
|
|
862
|
-
line: location.line,
|
|
863
|
-
column: location.column
|
|
864
|
-
};
|
|
634
|
+
var readGraphqlOperationName = (decorator) => {
|
|
635
|
+
const expression = decorator.expression;
|
|
636
|
+
if (!isCallExpression(expression)) return {
|
|
637
|
+
ok: true,
|
|
638
|
+
value: void 0
|
|
639
|
+
};
|
|
640
|
+
let value;
|
|
641
|
+
for (const argument of expression.arguments) {
|
|
642
|
+
if (isArrowFunction(argument) || isFunctionExpression(argument)) continue;
|
|
643
|
+
if (isStringLiteralLikeNode(argument)) {
|
|
644
|
+
value = argument.text;
|
|
645
|
+
continue;
|
|
646
|
+
}
|
|
647
|
+
if (isObjectLiteralExpression(argument)) {
|
|
648
|
+
value = readNameFromOptions(argument) ?? value;
|
|
649
|
+
continue;
|
|
650
|
+
}
|
|
651
|
+
return {
|
|
652
|
+
ok: false,
|
|
653
|
+
argumentText: argument.getText()
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
return {
|
|
657
|
+
ok: true,
|
|
658
|
+
value
|
|
659
|
+
};
|
|
865
660
|
};
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
return {
|
|
878
|
-
name: resolverName,
|
|
879
|
-
sourceFile: filePath,
|
|
880
|
-
methods
|
|
881
|
-
};
|
|
661
|
+
var readGraphqlReturnTypeOption = (decorator) => {
|
|
662
|
+
if (!isCallExpression(decorator.expression)) return;
|
|
663
|
+
const thunk = decorator.expression.arguments.find((argument) => isArrowFunction(argument) || isFunctionExpression(argument));
|
|
664
|
+
if (thunk === void 0) return;
|
|
665
|
+
const returnedExpression = readTypeThunkExpression(thunk);
|
|
666
|
+
if (returnedExpression === void 0) return;
|
|
667
|
+
if (isArrayLiteralExpression(returnedExpression)) {
|
|
668
|
+
const element = returnedExpression.elements[0];
|
|
669
|
+
return element !== void 0 && isIdentifier(element) ? element.text : void 0;
|
|
670
|
+
}
|
|
671
|
+
return isIdentifier(returnedExpression) ? returnedExpression.text : void 0;
|
|
882
672
|
};
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
673
|
+
var PRIMITIVE_SCALAR_NAMES = /* @__PURE__ */ new Set([
|
|
674
|
+
"string",
|
|
675
|
+
"number",
|
|
676
|
+
"boolean"
|
|
677
|
+
]);
|
|
678
|
+
var extractResolverMethodDefinition = (method, context) => {
|
|
679
|
+
const decorator = findAnyDecorator(method, Object.keys(GRAPHQL_OPERATION_DECORATOR_NAMES));
|
|
680
|
+
if (decorator === void 0) return;
|
|
681
|
+
const methodName = method.name.getText();
|
|
682
|
+
const decoratorName = decoratorNameOf(decorator);
|
|
683
|
+
const location = locationOf(context.sourceFile, method);
|
|
684
|
+
if (decoratorName === void 0) return;
|
|
685
|
+
const operationKind = GRAPHQL_OPERATION_DECORATOR_NAMES[decoratorName];
|
|
686
|
+
if (operationKind === void 0) return;
|
|
687
|
+
const nameArgument = readGraphqlOperationName(decorator);
|
|
688
|
+
if (!nameArgument.ok) {
|
|
689
|
+
context.diagnostics.push({
|
|
690
|
+
code: "unsupported-route",
|
|
691
|
+
title: "Unsupported operation name.",
|
|
692
|
+
controllerName: context.resolverName,
|
|
693
|
+
memberName: methodName,
|
|
694
|
+
detail: "GraphQL operation names must be statically analyzable string literals.",
|
|
695
|
+
found: `@${decoratorName}(${nameArgument.argumentText})`,
|
|
696
|
+
filePath: context.filePath,
|
|
697
|
+
line: location.line,
|
|
698
|
+
column: location.column
|
|
699
|
+
});
|
|
700
|
+
return;
|
|
701
|
+
}
|
|
702
|
+
const decoratorReturnType = readGraphqlReturnTypeOption(decorator);
|
|
703
|
+
const identifierText = decoratorReturnType ?? (method.type === void 0 ? void 0 : unwrapTypeNode(method.type)?.identifierText);
|
|
704
|
+
if (identifierText === void 0) {
|
|
705
|
+
context.diagnostics.push({
|
|
706
|
+
code: "unsupported-return-type",
|
|
707
|
+
title: "Unsupported return type.",
|
|
708
|
+
controllerName: context.resolverName,
|
|
709
|
+
memberName: methodName,
|
|
710
|
+
detail: "GraphQL resolver methods need a type thunk on @Query()/@Mutation() (e.g. \"() => UserType\") or an explicit return type annotation so NestBridge can build a selection set.",
|
|
711
|
+
filePath: context.filePath,
|
|
712
|
+
line: location.line,
|
|
713
|
+
column: location.column
|
|
714
|
+
});
|
|
715
|
+
return;
|
|
716
|
+
}
|
|
717
|
+
let selection = [];
|
|
718
|
+
if (!PRIMITIVE_SCALAR_NAMES.has(identifierText.toLowerCase())) {
|
|
719
|
+
const resolved = resolveClassDeclaration(identifierText, context.sourceFile, context.filePath);
|
|
720
|
+
if (resolved === void 0 && decoratorReturnType === void 0) {
|
|
721
|
+
context.diagnostics.push({
|
|
722
|
+
code: "unsupported-return-type",
|
|
723
|
+
title: "Unsupported return type.",
|
|
724
|
+
controllerName: context.resolverName,
|
|
725
|
+
memberName: methodName,
|
|
726
|
+
detail: `NestBridge could not locate the declaration of type "${identifierText}".`,
|
|
727
|
+
filePath: context.filePath,
|
|
728
|
+
line: location.line,
|
|
729
|
+
column: location.column
|
|
730
|
+
});
|
|
731
|
+
return;
|
|
732
|
+
}
|
|
733
|
+
if (resolved !== void 0) {
|
|
734
|
+
const fields = extractSelectionFields(resolved.classDeclaration, resolved.sourceFile, resolved.filePath, {
|
|
735
|
+
resolverName: context.resolverName,
|
|
736
|
+
methodName,
|
|
737
|
+
diagnostics: context.diagnostics,
|
|
738
|
+
visitedTypeNames: /* @__PURE__ */ new Set()
|
|
739
|
+
});
|
|
740
|
+
if (fields === void 0) return;
|
|
741
|
+
selection = fields;
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
const args = method.parameters.map((parameter, index) => extractResolverArgumentDefinition(parameter, index, {
|
|
745
|
+
sourceFile: context.sourceFile,
|
|
746
|
+
filePath: context.filePath,
|
|
747
|
+
resolverName: context.resolverName,
|
|
748
|
+
methodName,
|
|
749
|
+
diagnostics: context.diagnostics
|
|
750
|
+
}));
|
|
751
|
+
if (args.some((argument) => argument === void 0)) return;
|
|
752
|
+
return {
|
|
753
|
+
name: methodName,
|
|
754
|
+
operationKind,
|
|
755
|
+
operationName: nameArgument.value ?? methodName,
|
|
756
|
+
arguments: args.filter((argument) => argument !== void 0),
|
|
757
|
+
selection,
|
|
758
|
+
line: location.line,
|
|
759
|
+
column: location.column
|
|
760
|
+
};
|
|
888
761
|
};
|
|
889
|
-
|
|
890
|
-
const
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
);
|
|
902
|
-
for (const classDeclaration of findResolverClasses(sourceFile)) {
|
|
903
|
-
const resolver = extractResolverDefinition(
|
|
904
|
-
classDeclaration,
|
|
905
|
-
sourceFile,
|
|
906
|
-
filePath,
|
|
907
|
-
diagnostics
|
|
908
|
-
);
|
|
909
|
-
if (resolver !== void 0) {
|
|
910
|
-
resolvers.push(resolver);
|
|
911
|
-
}
|
|
912
|
-
}
|
|
913
|
-
}
|
|
914
|
-
return { resolvers, diagnostics };
|
|
762
|
+
var extractResolverDefinition = (classDeclaration, sourceFile, filePath, diagnostics) => {
|
|
763
|
+
const resolverName = classDeclaration.name?.text ?? "(anonymous resolver)";
|
|
764
|
+
return {
|
|
765
|
+
name: resolverName,
|
|
766
|
+
sourceFile: filePath,
|
|
767
|
+
methods: classDeclaration.members.filter((member) => isMethodDeclaration(member)).map((method) => extractResolverMethodDefinition(method, {
|
|
768
|
+
sourceFile,
|
|
769
|
+
filePath,
|
|
770
|
+
resolverName,
|
|
771
|
+
diagnostics
|
|
772
|
+
})).filter((method) => method !== void 0)
|
|
773
|
+
};
|
|
915
774
|
};
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
json: "RemoteResult",
|
|
919
|
-
observable: "RemoteObservableResult",
|
|
920
|
-
stream: "RemoteStreamResult"
|
|
775
|
+
var findResolverClasses = (sourceFile) => {
|
|
776
|
+
return sourceFile.statements.filter((statement) => isClassDeclaration(statement) && findDecorator(statement, "Resolver") !== void 0);
|
|
921
777
|
};
|
|
922
|
-
|
|
923
|
-
const
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
778
|
+
var analyzeResolvers = (filePaths) => {
|
|
779
|
+
const diagnostics = [];
|
|
780
|
+
const resolvers = [];
|
|
781
|
+
for (const filePath of filePaths) {
|
|
782
|
+
const sourceFile = parseSourceFile(filePath);
|
|
783
|
+
for (const classDeclaration of findResolverClasses(sourceFile)) {
|
|
784
|
+
const resolver = extractResolverDefinition(classDeclaration, sourceFile, filePath, diagnostics);
|
|
785
|
+
if (resolver !== void 0) resolvers.push(resolver);
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
return {
|
|
789
|
+
resolvers,
|
|
790
|
+
diagnostics
|
|
791
|
+
};
|
|
929
792
|
};
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
793
|
+
var REMOTE_RESULT_HELPERS = {
|
|
794
|
+
json: "RemoteResult",
|
|
795
|
+
observable: "RemoteObservableResult",
|
|
796
|
+
stream: "RemoteStreamResult"
|
|
933
797
|
};
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
const helperName = REMOTE_RESULT_HELPERS[method.responseKind ?? "json"];
|
|
940
|
-
return ` ${method.name}(...args: Parameters<${serverAlias}['${method.name}']>): ${helperName}<${serverAlias}['${method.name}']>;`;
|
|
941
|
-
});
|
|
942
|
-
const classBody = [" constructor();", "", ...methodDeclarations].join("\n");
|
|
943
|
-
const usedHelperNames = new Set(
|
|
944
|
-
controller.methods.map((method) => REMOTE_RESULT_HELPERS[method.responseKind ?? "json"])
|
|
945
|
-
);
|
|
946
|
-
const helperImports = Array.from(
|
|
947
|
-
usedHelperNames.size > 0 ? usedHelperNames : ["RemoteResult"]
|
|
948
|
-
).sort();
|
|
949
|
-
return [
|
|
950
|
-
`import type { ${controller.name} as ${serverAlias} } from '${importSpecifier}';`,
|
|
951
|
-
`import type { ${helperImports.join(", ")} } from '@nestbridge/runtime';`,
|
|
952
|
-
"",
|
|
953
|
-
"/**",
|
|
954
|
-
" * Generated by NestBridge — client-facing methods only.",
|
|
955
|
-
` * @see {@link ${sourceFileSpecifier}} for the real controller implementation.`,
|
|
956
|
-
" */",
|
|
957
|
-
`export declare class ${controller.name} {`,
|
|
958
|
-
classBody,
|
|
959
|
-
"}",
|
|
960
|
-
""
|
|
961
|
-
].join("\n");
|
|
798
|
+
var toPosixPath = (filePath) => filePath.replace(/\\/g, "/");
|
|
799
|
+
var importSpecifierFor = (sourceFile, outputFilePath) => {
|
|
800
|
+
if (!sourceFile.startsWith(".") && !/^[A-Za-z]:[\\/]/.test(sourceFile) && !sourceFile.startsWith("/")) return sourceFile;
|
|
801
|
+
const relativePath = toPosixPath(relative(dirname(outputFilePath), sourceFile));
|
|
802
|
+
return relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
|
|
962
803
|
};
|
|
963
|
-
|
|
964
|
-
const
|
|
965
|
-
|
|
966
|
-
const lines = [`[NestBridge] ${diagnostic.title}`, "", subject, "", diagnostic.detail];
|
|
967
|
-
if (diagnostic.found !== void 0) {
|
|
968
|
-
lines.push("", "Found:", diagnostic.found);
|
|
969
|
-
}
|
|
970
|
-
if (diagnostic.expected !== void 0) {
|
|
971
|
-
lines.push("", "Expected:", diagnostic.expected);
|
|
972
|
-
}
|
|
973
|
-
lines.push("", `${diagnostic.filePath}:${diagnostic.line}:${diagnostic.column}`);
|
|
974
|
-
return lines.join("\n");
|
|
804
|
+
var stripExtension = (filePath) => {
|
|
805
|
+
const extension = extname(filePath);
|
|
806
|
+
return extension.length > 0 ? filePath.slice(0, -extension.length) : filePath;
|
|
975
807
|
};
|
|
976
|
-
|
|
977
|
-
const
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
)
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
808
|
+
var generateControllerDeclaration = (controller, outputFilePath) => {
|
|
809
|
+
const sourceFileSpecifier = importSpecifierFor(controller.sourceFile, outputFilePath);
|
|
810
|
+
const importSpecifier = stripExtension(sourceFileSpecifier);
|
|
811
|
+
const serverAlias = `__Server${controller.name}`;
|
|
812
|
+
const classBody = [
|
|
813
|
+
" constructor();",
|
|
814
|
+
"",
|
|
815
|
+
...controller.methods.map((method) => {
|
|
816
|
+
const helperName = REMOTE_RESULT_HELPERS[method.responseKind ?? "json"];
|
|
817
|
+
return ` ${method.name}(...args: Parameters<${serverAlias}['${method.name}']>): ${helperName}<${serverAlias}['${method.name}']>;`;
|
|
818
|
+
})
|
|
819
|
+
].join("\n");
|
|
820
|
+
const usedHelperNames = new Set(controller.methods.map((method) => REMOTE_RESULT_HELPERS[method.responseKind ?? "json"]));
|
|
821
|
+
const helperImports = Array.from(usedHelperNames.size > 0 ? usedHelperNames : ["RemoteResult"]).sort();
|
|
822
|
+
return [
|
|
823
|
+
`import type { ${controller.name} as ${serverAlias} } from '${importSpecifier}';`,
|
|
824
|
+
`import type { ${helperImports.join(", ")} } from 'nestbridge';`,
|
|
825
|
+
"",
|
|
826
|
+
"/**",
|
|
827
|
+
" * Generated by NestBridge — client-facing methods only.",
|
|
828
|
+
` * @see {@link ${sourceFileSpecifier}} for the real controller implementation.`,
|
|
829
|
+
" */",
|
|
830
|
+
`export declare class ${controller.name} {`,
|
|
831
|
+
classBody,
|
|
832
|
+
"}",
|
|
833
|
+
""
|
|
834
|
+
].join("\n");
|
|
993
835
|
};
|
|
994
|
-
|
|
995
|
-
const
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
836
|
+
var formatDiagnostic = (diagnostic) => {
|
|
837
|
+
const subject = diagnostic.memberName.length > 0 ? `${diagnostic.controllerName}.${diagnostic.memberName}` : diagnostic.controllerName;
|
|
838
|
+
const lines = [
|
|
839
|
+
`[NestBridge] ${diagnostic.title}`,
|
|
840
|
+
"",
|
|
841
|
+
subject,
|
|
842
|
+
"",
|
|
843
|
+
diagnostic.detail
|
|
844
|
+
];
|
|
845
|
+
if (diagnostic.found !== void 0) lines.push("", "Found:", diagnostic.found);
|
|
846
|
+
if (diagnostic.expected !== void 0) lines.push("", "Expected:", diagnostic.expected);
|
|
847
|
+
lines.push("", `${diagnostic.filePath}:${diagnostic.line}:${diagnostic.column}`);
|
|
848
|
+
return lines.join("\n");
|
|
1006
849
|
};
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
const
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
if (!isParamToken) {
|
|
1018
|
-
if (part.length > 0) {
|
|
1019
|
-
expressionParts.push(JSON.stringify(part));
|
|
1020
|
-
}
|
|
1021
|
-
return;
|
|
1022
|
-
}
|
|
1023
|
-
const match = paramParameters.find((parameter) => parameter.name === part);
|
|
1024
|
-
expressionParts.push(
|
|
1025
|
-
match !== void 0 ? `encodeURIComponent(${match.parameterName})` : JSON.stringify(`:${part}`)
|
|
1026
|
-
);
|
|
1027
|
-
});
|
|
1028
|
-
return expressionParts.length > 0 ? expressionParts.join(" + ") : "''";
|
|
850
|
+
//#endregion
|
|
851
|
+
//#region src/codegen/merge-named-parameters-expression.ts
|
|
852
|
+
var mergeNamedParametersExpression = (parameters) => {
|
|
853
|
+
if (parameters.length === 0) return;
|
|
854
|
+
const whole = parameters.find((parameter) => parameter.name === void 0);
|
|
855
|
+
const named = parameters.filter((parameter) => parameter.name !== void 0);
|
|
856
|
+
const namedEntries = named.map((parameter) => `${JSON.stringify(parameter.name)}: ${parameter.parameterName}`);
|
|
857
|
+
if (whole === void 0) return `{ ${namedEntries.join(", ")} }`;
|
|
858
|
+
if (named.length === 0) return whole.parameterName;
|
|
859
|
+
return `{ ...${whole.parameterName}, ${namedEntries.join(", ")} }`;
|
|
1029
860
|
};
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
if (queryExpression !== void 0) {
|
|
1040
|
-
requestProperties.push(`query: ${queryExpression}`);
|
|
1041
|
-
}
|
|
1042
|
-
const bodyExpression = generateBodyExpression(method.parameters);
|
|
1043
|
-
if (bodyExpression !== void 0) {
|
|
1044
|
-
requestProperties.push(`body: ${bodyExpression}`);
|
|
1045
|
-
}
|
|
1046
|
-
const headersExpression = generateHeadersExpression(method.parameters);
|
|
1047
|
-
if (headersExpression !== void 0) {
|
|
1048
|
-
requestProperties.push(`headers: ${headersExpression}`);
|
|
1049
|
-
}
|
|
1050
|
-
if (method.responseKind === "stream") {
|
|
1051
|
-
requestProperties.push(`responseType: "blob"`);
|
|
1052
|
-
}
|
|
1053
|
-
return [
|
|
1054
|
-
` ${method.name}(${generateParameterList(method.parameters)}) {`,
|
|
1055
|
-
" return request({",
|
|
1056
|
-
...requestProperties.map((property) => ` ${property},`),
|
|
1057
|
-
" });",
|
|
1058
|
-
" }"
|
|
1059
|
-
].join("\n");
|
|
861
|
+
//#endregion
|
|
862
|
+
//#region src/codegen/generate-body-expression.ts
|
|
863
|
+
var generateBodyExpression = (parameters) => mergeNamedParametersExpression(parameters.filter((parameter) => parameter.kind === "body"));
|
|
864
|
+
//#endregion
|
|
865
|
+
//#region src/codegen/generate-headers-expression.ts
|
|
866
|
+
var generateHeadersExpression = (parameters) => {
|
|
867
|
+
const headerParameters = parameters.filter((parameter) => parameter.kind === "header");
|
|
868
|
+
if (headerParameters.length === 0) return;
|
|
869
|
+
return `{ ${headerParameters.map((parameter) => `${JSON.stringify(parameter.name)}: ${parameter.parameterName}`).join(", ")} }`;
|
|
1060
870
|
};
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
871
|
+
//#endregion
|
|
872
|
+
//#region src/codegen/generate-parameter-list.ts
|
|
873
|
+
var generateParameterList = (parameters) => [...parameters].sort((a, b) => a.index - b.index).map((parameter) => parameter.parameterName).join(", ");
|
|
874
|
+
//#endregion
|
|
875
|
+
//#region src/codegen/generate-path-expression.ts
|
|
876
|
+
var PARAM_TOKEN_PATTERN = /:([A-Za-z0-9_]+)/;
|
|
877
|
+
var generatePathExpression = (method) => {
|
|
878
|
+
const paramParameters = method.parameters.filter((parameter) => parameter.kind === "param");
|
|
879
|
+
const parts = method.path.split(PARAM_TOKEN_PATTERN);
|
|
880
|
+
const expressionParts = [];
|
|
881
|
+
parts.forEach((part, index) => {
|
|
882
|
+
if (!(index % 2 === 1)) {
|
|
883
|
+
if (part.length > 0) expressionParts.push(JSON.stringify(part));
|
|
884
|
+
return;
|
|
885
|
+
}
|
|
886
|
+
const match = paramParameters.find((parameter) => parameter.name === part);
|
|
887
|
+
expressionParts.push(match !== void 0 ? `encodeURIComponent(${match.parameterName})` : JSON.stringify(`:${part}`));
|
|
888
|
+
});
|
|
889
|
+
return expressionParts.length > 0 ? expressionParts.join(" + ") : "''";
|
|
1073
890
|
};
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
891
|
+
//#endregion
|
|
892
|
+
//#region src/codegen/generate-query-expression.ts
|
|
893
|
+
var generateQueryExpression = (parameters) => mergeNamedParametersExpression(parameters.filter((parameter) => parameter.kind === "query"));
|
|
894
|
+
//#endregion
|
|
895
|
+
//#region src/codegen/generate-controller-module.ts
|
|
896
|
+
var generateMethod$1 = (method) => {
|
|
897
|
+
const requestProperties = [`method: ${JSON.stringify(method.httpMethod)}`, `path: ${generatePathExpression(method)}`];
|
|
898
|
+
const queryExpression = generateQueryExpression(method.parameters);
|
|
899
|
+
if (queryExpression !== void 0) requestProperties.push(`query: ${queryExpression}`);
|
|
900
|
+
const bodyExpression = generateBodyExpression(method.parameters);
|
|
901
|
+
if (bodyExpression !== void 0) requestProperties.push(`body: ${bodyExpression}`);
|
|
902
|
+
const headersExpression = generateHeadersExpression(method.parameters);
|
|
903
|
+
if (headersExpression !== void 0) requestProperties.push(`headers: ${headersExpression}`);
|
|
904
|
+
if (method.responseKind === "stream") requestProperties.push(`responseType: "blob"`);
|
|
905
|
+
return [
|
|
906
|
+
` ${method.name}(${generateParameterList(method.parameters)}) {`,
|
|
907
|
+
" return request({",
|
|
908
|
+
...requestProperties.map((property) => ` ${property},`),
|
|
909
|
+
" });",
|
|
910
|
+
" }"
|
|
911
|
+
].join("\n");
|
|
1081
912
|
};
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
913
|
+
var generateControllerModule = (controller) => {
|
|
914
|
+
const methods = controller.methods.map(generateMethod$1).join("\n\n");
|
|
915
|
+
return [
|
|
916
|
+
"import { request } from 'nestbridge';",
|
|
917
|
+
"",
|
|
918
|
+
`export class ${controller.name} {`,
|
|
919
|
+
" constructor() {}",
|
|
920
|
+
"",
|
|
921
|
+
methods,
|
|
922
|
+
"}",
|
|
923
|
+
""
|
|
924
|
+
].join("\n");
|
|
1089
925
|
};
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
return void 0;
|
|
1096
|
-
}
|
|
1097
|
-
const entries = resolverArguments.map(
|
|
1098
|
-
(argument) => `${JSON.stringify(argument.name)}: ${argument.parameterName}`
|
|
1099
|
-
);
|
|
1100
|
-
return `{ ${entries.join(", ")} }`;
|
|
926
|
+
//#endregion
|
|
927
|
+
//#region src/codegen/generate-graphql-document.ts
|
|
928
|
+
var capitalize = (value) => `${value.charAt(0).toUpperCase()}${value.slice(1)}`;
|
|
929
|
+
var renderSelectionSet = (fields) => {
|
|
930
|
+
return `{ ${fields.map((field) => field.children === void 0 ? field.name : `${field.name} ${renderSelectionSet(field.children)}`).join(" ")} }`;
|
|
1101
931
|
};
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
` async ${method.name}(${generateResolverArgumentList(method.arguments)}) {`,
|
|
1110
|
-
" const result = await graphqlRequest({",
|
|
1111
|
-
...requestProperties.map((property) => ` ${property},`),
|
|
1112
|
-
" });",
|
|
1113
|
-
"",
|
|
1114
|
-
` return result.${method.operationName};`,
|
|
1115
|
-
" }"
|
|
1116
|
-
].join("\n");
|
|
932
|
+
var generateGraphqlDocument = (method) => {
|
|
933
|
+
const variableDeclarations = method.arguments.map((argument) => `$${argument.name}: ${argument.graphqlType}`).join(", ");
|
|
934
|
+
const fieldArguments = method.arguments.map((argument) => `${argument.name}: $${argument.name}`).join(", ");
|
|
935
|
+
const variablesClause = variableDeclarations.length > 0 ? `(${variableDeclarations})` : "";
|
|
936
|
+
const fieldArgumentsClause = fieldArguments.length > 0 ? `(${fieldArguments})` : "";
|
|
937
|
+
const fieldSelection = method.selection.length > 0 ? ` ${renderSelectionSet(method.selection)}` : "";
|
|
938
|
+
return `${method.operationKind} ${capitalize(method.name)}${variablesClause} { ${method.operationName}${fieldArgumentsClause}${fieldSelection} }`;
|
|
1117
939
|
};
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
methods,
|
|
1127
|
-
"}",
|
|
1128
|
-
""
|
|
1129
|
-
].join("\n");
|
|
940
|
+
//#endregion
|
|
941
|
+
//#region src/codegen/generate-resolver-argument-list.ts
|
|
942
|
+
var generateResolverArgumentList = (resolverArguments) => [...resolverArguments].sort((a, b) => a.index - b.index).map((argument) => argument.parameterName).join(", ");
|
|
943
|
+
//#endregion
|
|
944
|
+
//#region src/codegen/generate-resolver-module.ts
|
|
945
|
+
var generateVariablesExpression = (resolverArguments) => {
|
|
946
|
+
if (resolverArguments.length === 0) return;
|
|
947
|
+
return `{ ${resolverArguments.map((argument) => `${JSON.stringify(argument.name)}: ${argument.parameterName}`).join(", ")} }`;
|
|
1130
948
|
};
|
|
1131
|
-
|
|
1132
|
-
const
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
949
|
+
var generateMethod = (method) => {
|
|
950
|
+
const requestProperties = [`document: ${JSON.stringify(generateGraphqlDocument(method))}`];
|
|
951
|
+
const variablesExpression = generateVariablesExpression(method.arguments);
|
|
952
|
+
if (variablesExpression !== void 0) requestProperties.push(`variables: ${variablesExpression}`);
|
|
953
|
+
return [
|
|
954
|
+
` async ${method.name}(${generateResolverArgumentList(method.arguments)}) {`,
|
|
955
|
+
" const result = await graphqlRequest({",
|
|
956
|
+
...requestProperties.map((property) => ` ${property},`),
|
|
957
|
+
" });",
|
|
958
|
+
"",
|
|
959
|
+
` return result.${method.operationName};`,
|
|
960
|
+
" }"
|
|
961
|
+
].join("\n");
|
|
1136
962
|
};
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
963
|
+
var generateResolverModule = (resolver) => {
|
|
964
|
+
const methods = resolver.methods.map(generateMethod).join("\n\n");
|
|
965
|
+
return [
|
|
966
|
+
"import { graphqlRequest } from 'nestbridge';",
|
|
967
|
+
"",
|
|
968
|
+
`export class ${resolver.name} {`,
|
|
969
|
+
" constructor() {}",
|
|
970
|
+
"",
|
|
971
|
+
methods,
|
|
972
|
+
"}",
|
|
973
|
+
""
|
|
974
|
+
].join("\n");
|
|
1141
975
|
};
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
outputFilePath,
|
|
1149
|
-
generateControllerDeclaration(controller, outputFilePath),
|
|
1150
|
-
"utf-8"
|
|
1151
|
-
);
|
|
1152
|
-
}
|
|
976
|
+
//#endregion
|
|
977
|
+
//#region src/declarations/mirror-declaration-path.ts
|
|
978
|
+
var stripLeadingParentSegments = (relativePath) => {
|
|
979
|
+
const segments = relativePath.split(/[\\/]/);
|
|
980
|
+
const firstOwnedIndex = segments.findIndex((segment) => segment !== "..");
|
|
981
|
+
return segments.slice(firstOwnedIndex === -1 ? segments.length : firstOwnedIndex).join("/");
|
|
1153
982
|
};
|
|
1154
|
-
|
|
1155
|
-
const
|
|
1156
|
-
|
|
1157
|
-
const outputFilePath = mirroredDeclarationPath(root, outputDir, resolver.sourceFile);
|
|
1158
|
-
mkdirSync(dirname(outputFilePath), { recursive: true });
|
|
1159
|
-
writeFileSync(outputFilePath, generateControllerDeclaration(resolver, outputFilePath), "utf-8");
|
|
1160
|
-
}
|
|
983
|
+
var mirroredDeclarationPath = (root, outputDir, controllerFilePath) => {
|
|
984
|
+
const mirroredPath = stripLeadingParentSegments(relative(root, controllerFilePath)).replace(/\.ts$/, ".d.ts");
|
|
985
|
+
return join(root, outputDir, mirroredPath);
|
|
1161
986
|
};
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
987
|
+
//#endregion
|
|
988
|
+
//#region src/declarations/write-controller-declarations.ts
|
|
989
|
+
var writeControllerDeclarations = (controllers, root, outputDir) => {
|
|
990
|
+
for (const controller of controllers) {
|
|
991
|
+
const outputFilePath = mirroredDeclarationPath(root, outputDir, controller.sourceFile);
|
|
992
|
+
mkdirSync(dirname(outputFilePath), { recursive: true });
|
|
993
|
+
writeFileSync(outputFilePath, generateControllerDeclaration(controller, outputFilePath), "utf-8");
|
|
994
|
+
}
|
|
1166
995
|
};
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
996
|
+
//#endregion
|
|
997
|
+
//#region src/declarations/write-resolver-declarations.ts
|
|
998
|
+
var writeResolverDeclarations = (resolvers, root, outputDir) => {
|
|
999
|
+
for (const resolver of resolvers) {
|
|
1000
|
+
const outputFilePath = mirroredDeclarationPath(root, outputDir, resolver.sourceFile);
|
|
1001
|
+
mkdirSync(dirname(outputFilePath), { recursive: true });
|
|
1002
|
+
writeFileSync(outputFilePath, generateControllerDeclaration(resolver, outputFilePath), "utf-8");
|
|
1003
|
+
}
|
|
1004
|
+
};
|
|
1005
|
+
//#endregion
|
|
1006
|
+
//#region src/discovery/discover-files.ts
|
|
1007
|
+
var discoverFiles = (patterns, root) => {
|
|
1008
|
+
const matches = globSync([...patterns], { cwd: root });
|
|
1009
|
+
return [...new Set(matches.map((match) => resolve(root, match)))].sort();
|
|
1010
|
+
};
|
|
1011
|
+
//#endregion
|
|
1012
|
+
//#region src/options/nestbridge-options.ts
|
|
1013
|
+
var resolveNestBridgeOptions = (options) => ({
|
|
1014
|
+
controllers: Array.isArray(options.controllers) ? options.controllers : [options.controllers],
|
|
1015
|
+
resolvers: options.resolvers === void 0 ? [] : Array.isArray(options.resolvers) ? options.resolvers : [options.resolvers],
|
|
1016
|
+
baseURL: options.baseURL,
|
|
1017
|
+
debug: options.debug ?? false,
|
|
1018
|
+
outputDir: options.outputDir ?? ".nestbridge"
|
|
1174
1019
|
});
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1020
|
+
//#endregion
|
|
1021
|
+
//#region src/virtual-modules/controller-virtual-id.ts
|
|
1022
|
+
var VIRTUAL_MODULE_PREFIX$1 = "virtual:nestbridge/controller/";
|
|
1023
|
+
var RESOLVED_VIRTUAL_MODULE_PREFIX$1 = `\0${VIRTUAL_MODULE_PREFIX$1}`;
|
|
1024
|
+
var encodeControllerVirtualId = (absoluteControllerPath) => `${VIRTUAL_MODULE_PREFIX$1}${encodeURIComponent(absoluteControllerPath)}`;
|
|
1025
|
+
var resolvedControllerVirtualId = (virtualId) => `\0${virtualId}`;
|
|
1026
|
+
var isResolvedControllerVirtualId = (id) => id.startsWith(RESOLVED_VIRTUAL_MODULE_PREFIX$1);
|
|
1027
|
+
var decodeControllerVirtualId = (resolvedId) => decodeURIComponent(resolvedId.slice(RESOLVED_VIRTUAL_MODULE_PREFIX$1.length));
|
|
1028
|
+
//#endregion
|
|
1029
|
+
//#region src/virtual-modules/resolver-virtual-id.ts
|
|
1030
|
+
var VIRTUAL_MODULE_PREFIX = "virtual:nestbridge/resolver/";
|
|
1031
|
+
var RESOLVED_VIRTUAL_MODULE_PREFIX = `\0${VIRTUAL_MODULE_PREFIX}`;
|
|
1032
|
+
var encodeResolverVirtualId = (absoluteResolverPath) => `${VIRTUAL_MODULE_PREFIX}${encodeURIComponent(absoluteResolverPath)}`;
|
|
1033
|
+
var resolvedResolverVirtualId = (virtualId) => `\0${virtualId}`;
|
|
1034
|
+
var isResolvedResolverVirtualId = (id) => id.startsWith(RESOLVED_VIRTUAL_MODULE_PREFIX);
|
|
1035
|
+
var decodeResolverVirtualId = (resolvedId) => decodeURIComponent(resolvedId.slice(RESOLVED_VIRTUAL_MODULE_PREFIX.length));
|
|
1036
|
+
//#endregion
|
|
1037
|
+
//#region src/plugin/controller-registry.ts
|
|
1038
|
+
var createControllerRegistry = (patterns, root) => {
|
|
1039
|
+
const controllersByFile = /* @__PURE__ */ new Map();
|
|
1040
|
+
const refresh = () => {
|
|
1041
|
+
controllersByFile.clear();
|
|
1042
|
+
const { controllers, diagnostics } = analyzeControllers(discoverFiles(patterns, root));
|
|
1043
|
+
for (const controller of controllers) controllersByFile.set(normalizePath(controller.sourceFile), controller);
|
|
1044
|
+
return {
|
|
1045
|
+
controllers,
|
|
1046
|
+
diagnostics
|
|
1047
|
+
};
|
|
1048
|
+
};
|
|
1049
|
+
return {
|
|
1050
|
+
refresh,
|
|
1051
|
+
get: (filePath) => controllersByFile.get(filePath),
|
|
1052
|
+
has: (filePath) => controllersByFile.has(filePath),
|
|
1053
|
+
all: () => [...controllersByFile.values()]
|
|
1054
|
+
};
|
|
1207
1055
|
};
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1056
|
+
//#endregion
|
|
1057
|
+
//#region src/plugin/resolver-registry.ts
|
|
1058
|
+
var createResolverRegistry = (patterns, root) => {
|
|
1059
|
+
const resolversByFile = /* @__PURE__ */ new Map();
|
|
1060
|
+
const refresh = () => {
|
|
1061
|
+
resolversByFile.clear();
|
|
1062
|
+
const { resolvers, diagnostics } = analyzeResolvers(discoverFiles(patterns, root));
|
|
1063
|
+
for (const resolver of resolvers) resolversByFile.set(normalizePath(resolver.sourceFile), resolver);
|
|
1064
|
+
return {
|
|
1065
|
+
resolvers,
|
|
1066
|
+
diagnostics
|
|
1067
|
+
};
|
|
1068
|
+
};
|
|
1069
|
+
return {
|
|
1070
|
+
refresh,
|
|
1071
|
+
get: (filePath) => resolversByFile.get(filePath),
|
|
1072
|
+
has: (filePath) => resolversByFile.has(filePath),
|
|
1073
|
+
all: () => [...resolversByFile.values()]
|
|
1074
|
+
};
|
|
1226
1075
|
};
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
const normalizedFile = normalizePath(ctx.file);
|
|
1305
|
-
const matchedBefore = controllerRegistry.has(normalizedFile) || resolverRegistry.has(normalizedFile);
|
|
1306
|
-
const matchesNow = discoverFiles(resolvedOptions.controllers, viteConfig.root).includes(normalizedFile) || discoverFiles(resolvedOptions.resolvers, viteConfig.root).includes(normalizedFile);
|
|
1307
|
-
if (!matchedBefore && !matchesNow) {
|
|
1308
|
-
return void 0;
|
|
1309
|
-
}
|
|
1310
|
-
runAnalysis(devReporter);
|
|
1311
|
-
log(`nestbridge source changed: ${normalizedFile}`);
|
|
1312
|
-
const virtualId = controllerRegistry.has(normalizedFile) ? resolvedControllerVirtualId(encodeControllerVirtualId(normalizedFile)) : resolvedResolverVirtualId(encodeResolverVirtualId(normalizedFile));
|
|
1313
|
-
const moduleNode = ctx.server.moduleGraph.getModuleById(virtualId);
|
|
1314
|
-
return moduleNode === void 0 ? void 0 : [moduleNode, ...ctx.modules];
|
|
1315
|
-
}
|
|
1316
|
-
};
|
|
1076
|
+
//#endregion
|
|
1077
|
+
//#region src/plugin/nestbridge-vite-plugin.ts
|
|
1078
|
+
var nestBridge = (options) => {
|
|
1079
|
+
const resolvedOptions = resolveNestBridgeOptions(options);
|
|
1080
|
+
let viteConfig;
|
|
1081
|
+
let controllerRegistry;
|
|
1082
|
+
let resolverRegistry;
|
|
1083
|
+
const log = (message) => {
|
|
1084
|
+
if (resolvedOptions.debug) console.log(`[nestbridge] ${message}`);
|
|
1085
|
+
};
|
|
1086
|
+
const reportDiagnostics = (diagnostics, reporter) => {
|
|
1087
|
+
for (const diagnostic of diagnostics) {
|
|
1088
|
+
const message = formatDiagnostic(diagnostic);
|
|
1089
|
+
if (viteConfig.command === "build") reporter.error(message);
|
|
1090
|
+
else reporter.warn(message);
|
|
1091
|
+
}
|
|
1092
|
+
};
|
|
1093
|
+
const devReporter = {
|
|
1094
|
+
warn: (message) => console.warn(message),
|
|
1095
|
+
error: (message) => {
|
|
1096
|
+
throw new Error(message);
|
|
1097
|
+
}
|
|
1098
|
+
};
|
|
1099
|
+
const runAnalysis = (reporter) => {
|
|
1100
|
+
const { controllers, diagnostics: controllerDiagnostics } = controllerRegistry.refresh();
|
|
1101
|
+
const { resolvers, diagnostics: resolverDiagnostics } = resolverRegistry.refresh();
|
|
1102
|
+
reportDiagnostics([...controllerDiagnostics, ...resolverDiagnostics], reporter);
|
|
1103
|
+
writeControllerDeclarations(controllers, viteConfig.root, resolvedOptions.outputDir);
|
|
1104
|
+
writeResolverDeclarations(resolvers, viteConfig.root, resolvedOptions.outputDir);
|
|
1105
|
+
log(`analyzed ${controllers.length} controller(s), ${resolvers.length} resolver(s), ${controllerDiagnostics.length + resolverDiagnostics.length} diagnostic(s)`);
|
|
1106
|
+
};
|
|
1107
|
+
return {
|
|
1108
|
+
name: "nestbridge",
|
|
1109
|
+
enforce: "pre",
|
|
1110
|
+
configResolved(config) {
|
|
1111
|
+
viteConfig = config;
|
|
1112
|
+
controllerRegistry = createControllerRegistry(resolvedOptions.controllers, config.root);
|
|
1113
|
+
resolverRegistry = createResolverRegistry(resolvedOptions.resolvers, config.root);
|
|
1114
|
+
},
|
|
1115
|
+
buildStart() {
|
|
1116
|
+
runAnalysis(this);
|
|
1117
|
+
},
|
|
1118
|
+
async resolveId(source, importer, resolveOptions) {
|
|
1119
|
+
if (importer === void 0) return null;
|
|
1120
|
+
const resolved = await this.resolve(source, importer, {
|
|
1121
|
+
...resolveOptions,
|
|
1122
|
+
skipSelf: true
|
|
1123
|
+
});
|
|
1124
|
+
if (resolved === null) return null;
|
|
1125
|
+
const absolutePath = normalizePath(resolved.id);
|
|
1126
|
+
if (controllerRegistry.has(absolutePath)) return resolvedControllerVirtualId(encodeControllerVirtualId(absolutePath));
|
|
1127
|
+
if (resolverRegistry.has(absolutePath)) return resolvedResolverVirtualId(encodeResolverVirtualId(absolutePath));
|
|
1128
|
+
return null;
|
|
1129
|
+
},
|
|
1130
|
+
load(id) {
|
|
1131
|
+
if (isResolvedControllerVirtualId(id)) {
|
|
1132
|
+
const controller = controllerRegistry.get(decodeControllerVirtualId(id));
|
|
1133
|
+
return controller === void 0 ? null : generateControllerModule(controller);
|
|
1134
|
+
}
|
|
1135
|
+
if (isResolvedResolverVirtualId(id)) {
|
|
1136
|
+
const resolver = resolverRegistry.get(decodeResolverVirtualId(id));
|
|
1137
|
+
return resolver === void 0 ? null : generateResolverModule(resolver);
|
|
1138
|
+
}
|
|
1139
|
+
return null;
|
|
1140
|
+
},
|
|
1141
|
+
handleHotUpdate(ctx) {
|
|
1142
|
+
const normalizedFile = normalizePath(ctx.file);
|
|
1143
|
+
const matchedBefore = controllerRegistry.has(normalizedFile) || resolverRegistry.has(normalizedFile);
|
|
1144
|
+
const matchesNow = discoverFiles(resolvedOptions.controllers, viteConfig.root).includes(normalizedFile) || discoverFiles(resolvedOptions.resolvers, viteConfig.root).includes(normalizedFile);
|
|
1145
|
+
if (!matchedBefore && !matchesNow) return;
|
|
1146
|
+
runAnalysis(devReporter);
|
|
1147
|
+
log(`nestbridge source changed: ${normalizedFile}`);
|
|
1148
|
+
const virtualId = controllerRegistry.has(normalizedFile) ? resolvedControllerVirtualId(encodeControllerVirtualId(normalizedFile)) : resolvedResolverVirtualId(encodeResolverVirtualId(normalizedFile));
|
|
1149
|
+
const moduleNode = ctx.server.moduleGraph.getModuleById(virtualId);
|
|
1150
|
+
return moduleNode === void 0 ? void 0 : [moduleNode, ...ctx.modules];
|
|
1151
|
+
}
|
|
1152
|
+
};
|
|
1317
1153
|
};
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1154
|
+
//#endregion
|
|
1155
|
+
//#region src/version.ts
|
|
1156
|
+
var VERSION = "1.1.1";
|
|
1157
|
+
//#endregion
|
|
1323
1158
|
export { VERSION, nestBridge };
|
|
1324
|
-
|
|
1159
|
+
|
|
1160
|
+
//# sourceMappingURL=nestbridge.vite.js.map
|