@nestbridge/core 2.1.4 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/README.md +66 -3
- package/build/nestbridge.core.d.ts +50 -6
- package/build/nestbridge.core.js +378 -35
- package/build/nestbridge.core.js.map +1 -1
- package/package.json +1 -1
package/build/nestbridge.core.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SyntaxKind, isArrayLiteralExpression, isArrayTypeNode, isArrowFunction, isBlock, isCallExpression, isClassDeclaration, isDecorator, isExportDeclaration, isExpressionStatement, isFalseLiteral, isFunctionExpression, isIdentifier, isImportDeclaration, isMethodDeclaration, isNamedExports, isNamedImports, isNewExpression, isNullLiteral, isNumericLiteral, isObjectLiteralExpression, isParenthesizedExpression, isPropertyAccessExpression, isPropertyAssignment, isPropertyDeclaration, isReturnStatement, isSpreadElement, isStringLiteral, isStringLiteralLikeNode, isTrueLiteral, isTypeReferenceNode, isUnionTypeNode, isVariableStatement } from "typescript/unstable/ast";
|
|
1
|
+
import { SyntaxKind, isArrayLiteralExpression, isArrayTypeNode, isArrowFunction, isBinaryExpression, isBlock, isCallExpression, isClassDeclaration, isConditionalExpression, isDecorator, isDoStatement, isExportDeclaration, isExpressionStatement, isFalseLiteral, isForInStatement, isForOfStatement, isForStatement, isFunctionExpression, isIdentifier, isIfStatement, isImportDeclaration, isMethodDeclaration, isNamedExports, isNamedImports, isNewExpression, isNullLiteral, isNumericLiteral, isObjectLiteralExpression, isParenthesizedExpression, isPropertyAccessExpression, isPropertyAssignment, isPropertyDeclaration, isReturnStatement, isSpreadElement, isStringLiteral, isStringLiteralLikeNode, isSwitchStatement, isTrueLiteral, isTypeReferenceNode, isUnionTypeNode, isVariableStatement, isWhileStatement } from "typescript/unstable/ast";
|
|
2
2
|
import { API } from "typescript/unstable/sync";
|
|
3
3
|
import { existsSync } from "node:fs";
|
|
4
4
|
import { dirname, extname, relative, resolve } from "node:path";
|
|
@@ -43,6 +43,12 @@ var readStaticStringArgument = (decorator) => {
|
|
|
43
43
|
};
|
|
44
44
|
};
|
|
45
45
|
//#endregion
|
|
46
|
+
//#region src/models/graphql-operation-kind.ts
|
|
47
|
+
var GRAPHQL_OPERATION_DECORATOR_NAMES = {
|
|
48
|
+
Query: "query",
|
|
49
|
+
Mutation: "mutation"
|
|
50
|
+
};
|
|
51
|
+
//#endregion
|
|
46
52
|
//#region src/models/http-method.ts
|
|
47
53
|
var HTTP_METHOD_DECORATOR_NAMES = {
|
|
48
54
|
Get: "GET",
|
|
@@ -136,26 +142,11 @@ var extractParameterDefinition = (parameter, index, context) => {
|
|
|
136
142
|
index,
|
|
137
143
|
parameterName: parameter.name.text
|
|
138
144
|
};
|
|
139
|
-
if (decoratorName === "Param") {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
controllerName: context.controllerName,
|
|
145
|
-
memberName: context.methodName,
|
|
146
|
-
detail: "A whole @Param() is not supported; provide a route parameter name such as @Param('id').",
|
|
147
|
-
filePath: context.filePath,
|
|
148
|
-
line: location.line,
|
|
149
|
-
column: location.column
|
|
150
|
-
});
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
return {
|
|
154
|
-
...base,
|
|
155
|
-
kind: "param",
|
|
156
|
-
name: argument.value
|
|
157
|
-
};
|
|
158
|
-
}
|
|
145
|
+
if (decoratorName === "Param") return {
|
|
146
|
+
...base,
|
|
147
|
+
kind: "param",
|
|
148
|
+
name: argument.value
|
|
149
|
+
};
|
|
159
150
|
if (decoratorName === "Headers") {
|
|
160
151
|
if (argument.value === void 0) {
|
|
161
152
|
context.diagnostics.push({
|
|
@@ -257,6 +248,35 @@ var readResponseKind = (returnType) => {
|
|
|
257
248
|
return "json";
|
|
258
249
|
};
|
|
259
250
|
//#endregion
|
|
251
|
+
//#region src/analysis/read-route-version.ts
|
|
252
|
+
var VERSION_NEUTRAL_NAME = "VERSION_NEUTRAL";
|
|
253
|
+
var readSingleRouteVersion = (expression) => {
|
|
254
|
+
if (isStringLiteralLikeNode(expression)) return {
|
|
255
|
+
ok: true,
|
|
256
|
+
version: expression.text
|
|
257
|
+
};
|
|
258
|
+
if (isIdentifier(expression) && expression.text === VERSION_NEUTRAL_NAME) return {
|
|
259
|
+
ok: true,
|
|
260
|
+
version: null
|
|
261
|
+
};
|
|
262
|
+
return {
|
|
263
|
+
ok: false,
|
|
264
|
+
argumentText: expression.getText()
|
|
265
|
+
};
|
|
266
|
+
};
|
|
267
|
+
/**
|
|
268
|
+
* An array of versions registers the route once per version, so any one of them is a valid URL;
|
|
269
|
+
* the first is used.
|
|
270
|
+
*/
|
|
271
|
+
var readRouteVersion = (expression) => {
|
|
272
|
+
if (!isArrayLiteralExpression(expression)) return readSingleRouteVersion(expression);
|
|
273
|
+
const [firstElement] = expression.elements;
|
|
274
|
+
return firstElement === void 0 ? {
|
|
275
|
+
ok: false,
|
|
276
|
+
argumentText: expression.getText()
|
|
277
|
+
} : readSingleRouteVersion(firstElement);
|
|
278
|
+
};
|
|
279
|
+
//#endregion
|
|
260
280
|
//#region src/analysis/route-path.ts
|
|
261
281
|
var trimSlashes = (segment) => segment.replace(/^\/+/, "").replace(/\/+$/, "");
|
|
262
282
|
var joinRoutePath = (controllerPath, methodPath) => {
|
|
@@ -264,6 +284,26 @@ var joinRoutePath = (controllerPath, methodPath) => {
|
|
|
264
284
|
};
|
|
265
285
|
//#endregion
|
|
266
286
|
//#region src/analysis/extract-method-definition.ts
|
|
287
|
+
var VERSION_DECORATOR_NAME = "Version";
|
|
288
|
+
var readMethodVersion = (method, context) => {
|
|
289
|
+
const decorator = findDecorator(method, VERSION_DECORATOR_NAME);
|
|
290
|
+
if (decorator === void 0) return { value: context.controllerVersion };
|
|
291
|
+
const [argument] = isCallExpression(decorator.expression) ? decorator.expression.arguments : [];
|
|
292
|
+
const routeVersion = argument === void 0 ? void 0 : readRouteVersion(argument);
|
|
293
|
+
if (routeVersion?.ok === true) return { value: routeVersion.version };
|
|
294
|
+
const location = locationOf(context.sourceFile, method);
|
|
295
|
+
context.diagnostics.push({
|
|
296
|
+
code: "unsupported-route",
|
|
297
|
+
title: "Unsupported route.",
|
|
298
|
+
controllerName: context.controllerName,
|
|
299
|
+
memberName: method.name.getText(),
|
|
300
|
+
detail: "Route versions must be statically analyzable.",
|
|
301
|
+
found: `@Version(${routeVersion?.argumentText ?? ""})`,
|
|
302
|
+
filePath: context.filePath,
|
|
303
|
+
line: location.line,
|
|
304
|
+
column: location.column
|
|
305
|
+
});
|
|
306
|
+
};
|
|
267
307
|
var extractMethodDefinition = (method, context) => {
|
|
268
308
|
const decorator = findAnyDecorator(method, Object.keys(HTTP_METHOD_DECORATOR_NAMES));
|
|
269
309
|
if (decorator === void 0) return;
|
|
@@ -288,6 +328,8 @@ var extractMethodDefinition = (method, context) => {
|
|
|
288
328
|
});
|
|
289
329
|
return;
|
|
290
330
|
}
|
|
331
|
+
const version = readMethodVersion(method, context);
|
|
332
|
+
if (version === void 0) return;
|
|
291
333
|
const parameters = method.parameters.map((parameter, index) => extractParameterDefinition(parameter, index, {
|
|
292
334
|
sourceFile: context.sourceFile,
|
|
293
335
|
filePath: context.filePath,
|
|
@@ -300,6 +342,7 @@ var extractMethodDefinition = (method, context) => {
|
|
|
300
342
|
name: methodName,
|
|
301
343
|
httpMethod,
|
|
302
344
|
path: joinRoutePath(context.controllerPath, routeArgument.value),
|
|
345
|
+
version: version.value,
|
|
303
346
|
parameters: parameters.filter((parameter) => parameter !== void 0),
|
|
304
347
|
responseKind: readResponseKind(method.type),
|
|
305
348
|
line: location.line,
|
|
@@ -307,21 +350,81 @@ var extractMethodDefinition = (method, context) => {
|
|
|
307
350
|
};
|
|
308
351
|
};
|
|
309
352
|
//#endregion
|
|
353
|
+
//#region src/analysis/read-controller-options.ts
|
|
354
|
+
var PATH_OPTION_NAME = "path";
|
|
355
|
+
var VERSION_OPTION_NAME = "version";
|
|
356
|
+
var optionNameOf = (property) => {
|
|
357
|
+
const name = property.name;
|
|
358
|
+
return isIdentifier(name) || isStringLiteralLikeNode(name) ? name.text : void 0;
|
|
359
|
+
};
|
|
360
|
+
var readControllerOptions = (decorator) => {
|
|
361
|
+
const expression = decorator.expression;
|
|
362
|
+
if (!isCallExpression(expression)) return {
|
|
363
|
+
ok: true,
|
|
364
|
+
path: void 0,
|
|
365
|
+
version: void 0
|
|
366
|
+
};
|
|
367
|
+
const [firstArgument] = expression.arguments;
|
|
368
|
+
if (firstArgument === void 0) return {
|
|
369
|
+
ok: true,
|
|
370
|
+
path: void 0,
|
|
371
|
+
version: void 0
|
|
372
|
+
};
|
|
373
|
+
if (isStringLiteralLikeNode(firstArgument)) return {
|
|
374
|
+
ok: true,
|
|
375
|
+
path: firstArgument.text,
|
|
376
|
+
version: void 0
|
|
377
|
+
};
|
|
378
|
+
if (!isObjectLiteralExpression(firstArgument)) return {
|
|
379
|
+
ok: false,
|
|
380
|
+
argumentText: firstArgument.getText()
|
|
381
|
+
};
|
|
382
|
+
let path;
|
|
383
|
+
let version;
|
|
384
|
+
for (const property of firstArgument.properties) {
|
|
385
|
+
if (!isPropertyAssignment(property)) return {
|
|
386
|
+
ok: false,
|
|
387
|
+
argumentText: firstArgument.getText()
|
|
388
|
+
};
|
|
389
|
+
const optionName = optionNameOf(property);
|
|
390
|
+
if (optionName === PATH_OPTION_NAME) {
|
|
391
|
+
if (!isStringLiteralLikeNode(property.initializer)) return {
|
|
392
|
+
ok: false,
|
|
393
|
+
argumentText: firstArgument.getText()
|
|
394
|
+
};
|
|
395
|
+
path = property.initializer.text;
|
|
396
|
+
}
|
|
397
|
+
if (optionName === VERSION_OPTION_NAME) {
|
|
398
|
+
const routeVersion = readRouteVersion(property.initializer);
|
|
399
|
+
if (!routeVersion.ok) return {
|
|
400
|
+
ok: false,
|
|
401
|
+
argumentText: firstArgument.getText()
|
|
402
|
+
};
|
|
403
|
+
version = routeVersion.version;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
return {
|
|
407
|
+
ok: true,
|
|
408
|
+
path,
|
|
409
|
+
version
|
|
410
|
+
};
|
|
411
|
+
};
|
|
412
|
+
//#endregion
|
|
310
413
|
//#region src/analysis/extract-controller-definition.ts
|
|
311
414
|
var extractControllerDefinition = (classDeclaration, sourceFile, filePath, diagnostics) => {
|
|
312
415
|
const controllerName = classDeclaration.name?.text ?? "(anonymous controller)";
|
|
313
416
|
const decorator = findDecorator(classDeclaration, "Controller");
|
|
314
417
|
if (decorator === void 0) return;
|
|
315
418
|
const location = locationOf(sourceFile, classDeclaration);
|
|
316
|
-
const
|
|
317
|
-
if (!
|
|
419
|
+
const options = readControllerOptions(decorator);
|
|
420
|
+
if (!options.ok) {
|
|
318
421
|
diagnostics.push({
|
|
319
422
|
code: "unsupported-route",
|
|
320
423
|
title: "Unsupported route.",
|
|
321
424
|
controllerName,
|
|
322
425
|
memberName: "",
|
|
323
|
-
detail: "Controller paths must be statically analyzable.",
|
|
324
|
-
found: `@Controller(${
|
|
426
|
+
detail: "Controller paths and versions must be statically analyzable.",
|
|
427
|
+
found: `@Controller(${options.argumentText})`,
|
|
325
428
|
filePath,
|
|
326
429
|
line: location.line,
|
|
327
430
|
column: location.column
|
|
@@ -332,12 +435,13 @@ var extractControllerDefinition = (classDeclaration, sourceFile, filePath, diagn
|
|
|
332
435
|
sourceFile,
|
|
333
436
|
filePath,
|
|
334
437
|
controllerName,
|
|
335
|
-
controllerPath:
|
|
438
|
+
controllerPath: options.path ?? "",
|
|
439
|
+
controllerVersion: options.version,
|
|
336
440
|
diagnostics
|
|
337
441
|
})).filter((method) => method !== void 0);
|
|
338
442
|
return {
|
|
339
443
|
name: controllerName,
|
|
340
|
-
path:
|
|
444
|
+
path: options.path ?? "",
|
|
341
445
|
sourceFile: filePath,
|
|
342
446
|
methods
|
|
343
447
|
};
|
|
@@ -378,12 +482,6 @@ var analyzeControllers = (filePaths) => {
|
|
|
378
482
|
};
|
|
379
483
|
};
|
|
380
484
|
//#endregion
|
|
381
|
-
//#region src/models/graphql-operation-kind.ts
|
|
382
|
-
var GRAPHQL_OPERATION_DECORATOR_NAMES = {
|
|
383
|
-
Query: "query",
|
|
384
|
-
Mutation: "mutation"
|
|
385
|
-
};
|
|
386
|
-
//#endregion
|
|
387
485
|
//#region src/analysis/read-type-thunk-expression.ts
|
|
388
486
|
var readTypeThunkExpression = (thunk) => {
|
|
389
487
|
if (!isBlock(thunk.body)) return thunk.body;
|
|
@@ -840,6 +938,40 @@ var analyzeResolvers = (filePaths) => {
|
|
|
840
938
|
};
|
|
841
939
|
};
|
|
842
940
|
//#endregion
|
|
941
|
+
//#region src/analysis/apply-application-routing.ts
|
|
942
|
+
var splitSegments = (path) => path.split("/").filter((segment) => segment.length > 0);
|
|
943
|
+
var matchesExclusionPath = (pattern, path) => {
|
|
944
|
+
const patternSegments = splitSegments(pattern);
|
|
945
|
+
const pathSegments = splitSegments(path);
|
|
946
|
+
for (const [index, patternSegment] of patternSegments.entries()) {
|
|
947
|
+
if (patternSegment.startsWith("*")) return pathSegments.length > index;
|
|
948
|
+
const pathSegment = pathSegments[index];
|
|
949
|
+
if (pathSegment === void 0) return false;
|
|
950
|
+
if (!patternSegment.startsWith(":") && patternSegment !== pathSegment) return false;
|
|
951
|
+
}
|
|
952
|
+
return patternSegments.length === pathSegments.length;
|
|
953
|
+
};
|
|
954
|
+
var isExcluded = (exclusion, method) => (exclusion.httpMethod === void 0 || exclusion.httpMethod === method.httpMethod) && matchesExclusionPath(exclusion.path, method.path);
|
|
955
|
+
var prefixSegmentFor = (method, globalPrefix) => {
|
|
956
|
+
if (globalPrefix === void 0 || splitSegments(globalPrefix.prefix).length === 0) return "";
|
|
957
|
+
if (globalPrefix.exclude.some((exclusion) => isExcluded(exclusion, method))) return "";
|
|
958
|
+
return `/${splitSegments(globalPrefix.prefix).join("/")}`;
|
|
959
|
+
};
|
|
960
|
+
var versionSegmentFor = (method, versioning) => {
|
|
961
|
+
if (versioning === void 0 || method.version === null) return "";
|
|
962
|
+
const version = method.version ?? versioning.defaultVersion;
|
|
963
|
+
return version === void 0 ? "" : `/${versioning.prefix}${version}`;
|
|
964
|
+
};
|
|
965
|
+
var joinRoutedPath = (...parts) => `/${splitSegments(parts.join("/")).join("/")}`;
|
|
966
|
+
var routeMethod = (method, routing) => ({
|
|
967
|
+
...method,
|
|
968
|
+
path: joinRoutedPath(prefixSegmentFor(method, routing.globalPrefix), versionSegmentFor(method, routing.versioning), method.path)
|
|
969
|
+
});
|
|
970
|
+
var applyApplicationRouting = (controllers, routing) => controllers.map((controller) => ({
|
|
971
|
+
...controller,
|
|
972
|
+
methods: controller.methods.map((method) => routeMethod(method, routing))
|
|
973
|
+
}));
|
|
974
|
+
//#endregion
|
|
843
975
|
//#region src/analysis/find-app-filter-provider-class-name.ts
|
|
844
976
|
var MODULE_DECORATOR_NAME = "Module";
|
|
845
977
|
var PROVIDERS_PROPERTY_NAME = "providers";
|
|
@@ -1025,6 +1157,152 @@ var detectErrorResponseShape = (bootstrapFilePath) => {
|
|
|
1025
1157
|
return errorBodyTypeSource === void 0 ? void 0 : { errorBodyTypeSource };
|
|
1026
1158
|
};
|
|
1027
1159
|
//#endregion
|
|
1160
|
+
//#region src/analysis/collect-bootstrap-calls.ts
|
|
1161
|
+
var isConditionalContainer = (node) => isIfStatement(node) || isConditionalExpression(node) || isSwitchStatement(node) || isForStatement(node) || isForInStatement(node) || isForOfStatement(node) || isWhileStatement(node) || isDoStatement(node) || isBinaryExpression(node) && (node.operatorToken.kind === SyntaxKind.AmpersandAmpersandToken || node.operatorToken.kind === SyntaxKind.BarBarToken || node.operatorToken.kind === SyntaxKind.QuestionQuestionToken);
|
|
1162
|
+
var collect = (node, methodName, conditional, calls) => {
|
|
1163
|
+
if (isCallExpression(node) && isPropertyAccessExpression(node.expression) && node.expression.name.text === methodName) calls.push({
|
|
1164
|
+
call: node,
|
|
1165
|
+
conditional
|
|
1166
|
+
});
|
|
1167
|
+
const childConditional = conditional || isConditionalContainer(node);
|
|
1168
|
+
node.forEachChild((child) => {
|
|
1169
|
+
collect(child, methodName, childConditional, calls);
|
|
1170
|
+
});
|
|
1171
|
+
};
|
|
1172
|
+
var collectBootstrapCalls = (sourceFile, methodName) => {
|
|
1173
|
+
const calls = [];
|
|
1174
|
+
collect(sourceFile, methodName, false, calls);
|
|
1175
|
+
return calls;
|
|
1176
|
+
};
|
|
1177
|
+
//#endregion
|
|
1178
|
+
//#region src/analysis/create-bootstrap-diagnostic.ts
|
|
1179
|
+
var createBootstrapDiagnostic = (source) => {
|
|
1180
|
+
const location = locationOf(source.sourceFile, source.node);
|
|
1181
|
+
return {
|
|
1182
|
+
code: source.code,
|
|
1183
|
+
title: source.title,
|
|
1184
|
+
controllerName: "(bootstrap)",
|
|
1185
|
+
memberName: "",
|
|
1186
|
+
detail: source.detail,
|
|
1187
|
+
found: source.node.getText(),
|
|
1188
|
+
expected: source.expected,
|
|
1189
|
+
filePath: source.filePath,
|
|
1190
|
+
line: location.line,
|
|
1191
|
+
column: location.column
|
|
1192
|
+
};
|
|
1193
|
+
};
|
|
1194
|
+
//#endregion
|
|
1195
|
+
//#region src/analysis/read-global-prefix-exclusions.ts
|
|
1196
|
+
var REQUEST_METHOD_ENUM_NAME = "RequestMethod";
|
|
1197
|
+
var REQUEST_METHOD_ALL_NAME = "ALL";
|
|
1198
|
+
var EXCLUDE_OPTION_NAME = "exclude";
|
|
1199
|
+
var PATH_PROPERTY_NAME = "path";
|
|
1200
|
+
var METHOD_PROPERTY_NAME = "method";
|
|
1201
|
+
var SUPPORTED_EXCLUSION_PATH = /^[A-Za-z0-9_\-./:*]*$/;
|
|
1202
|
+
var REQUEST_METHODS = {
|
|
1203
|
+
GET: "GET",
|
|
1204
|
+
POST: "POST",
|
|
1205
|
+
PUT: "PUT",
|
|
1206
|
+
PATCH: "PATCH",
|
|
1207
|
+
DELETE: "DELETE"
|
|
1208
|
+
};
|
|
1209
|
+
var readExclusionPath = (expression) => isStringLiteralLikeNode(expression) && SUPPORTED_EXCLUSION_PATH.test(expression.text) ? expression.text : void 0;
|
|
1210
|
+
var readRequestMethod = (expression) => {
|
|
1211
|
+
if (!isPropertyAccessExpression(expression) || !isIdentifier(expression.expression) || expression.expression.text !== REQUEST_METHOD_ENUM_NAME) return;
|
|
1212
|
+
const methodName = expression.name.text;
|
|
1213
|
+
if (methodName === REQUEST_METHOD_ALL_NAME) return {
|
|
1214
|
+
httpMethod: void 0,
|
|
1215
|
+
generated: true
|
|
1216
|
+
};
|
|
1217
|
+
const httpMethod = REQUEST_METHODS[methodName];
|
|
1218
|
+
return {
|
|
1219
|
+
httpMethod,
|
|
1220
|
+
generated: httpMethod !== void 0
|
|
1221
|
+
};
|
|
1222
|
+
};
|
|
1223
|
+
var readExclusion = (element) => {
|
|
1224
|
+
if (isStringLiteralLikeNode(element)) {
|
|
1225
|
+
const path = readExclusionPath(element);
|
|
1226
|
+
return path === void 0 ? void 0 : { exclusion: { path } };
|
|
1227
|
+
}
|
|
1228
|
+
if (!isObjectLiteralExpression(element)) return;
|
|
1229
|
+
let path;
|
|
1230
|
+
let httpMethod;
|
|
1231
|
+
for (const property of element.properties) {
|
|
1232
|
+
if (!isPropertyAssignment(property)) return;
|
|
1233
|
+
const propertyName = property.name.getText();
|
|
1234
|
+
if (propertyName === PATH_PROPERTY_NAME) path = readExclusionPath(property.initializer);
|
|
1235
|
+
if (propertyName === METHOD_PROPERTY_NAME) {
|
|
1236
|
+
const requestMethod = readRequestMethod(property.initializer);
|
|
1237
|
+
if (requestMethod === void 0) return;
|
|
1238
|
+
if (!requestMethod.generated) return { exclusion: void 0 };
|
|
1239
|
+
httpMethod = requestMethod.httpMethod;
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
if (path === void 0) return;
|
|
1243
|
+
return { exclusion: httpMethod === void 0 ? { path } : {
|
|
1244
|
+
path,
|
|
1245
|
+
httpMethod
|
|
1246
|
+
} };
|
|
1247
|
+
};
|
|
1248
|
+
/**
|
|
1249
|
+
* Returns `undefined` when an entry cannot be read statically. Entries for request methods
|
|
1250
|
+
* NestBridge never generates (OPTIONS, HEAD, SEARCH) are dropped because they cannot match.
|
|
1251
|
+
*/
|
|
1252
|
+
var readGlobalPrefixExclusions = (options) => {
|
|
1253
|
+
if (options === void 0) return [];
|
|
1254
|
+
if (!isObjectLiteralExpression(options)) return;
|
|
1255
|
+
const exclusions = [];
|
|
1256
|
+
for (const property of options.properties) {
|
|
1257
|
+
if (!isPropertyAssignment(property)) return;
|
|
1258
|
+
if (property.name.getText() !== EXCLUDE_OPTION_NAME) continue;
|
|
1259
|
+
if (!isArrayLiteralExpression(property.initializer)) return;
|
|
1260
|
+
for (const element of property.initializer.elements) {
|
|
1261
|
+
const entry = readExclusion(element);
|
|
1262
|
+
if (entry === void 0) return;
|
|
1263
|
+
if (entry.exclusion !== void 0) exclusions.push(entry.exclusion);
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
return exclusions;
|
|
1267
|
+
};
|
|
1268
|
+
//#endregion
|
|
1269
|
+
//#region src/analysis/detect-global-prefix.ts
|
|
1270
|
+
var SET_GLOBAL_PREFIX_METHOD_NAME = "setGlobalPrefix";
|
|
1271
|
+
var EXPECTED$1 = "A single unconditional setGlobalPrefix() call with a string literal prefix and exclude entries written as string literals or { path, method } literals. Set the `globalPrefix` option to provide the prefix explicitly.";
|
|
1272
|
+
var unsupported$1 = (sourceFile, filePath, node, detail) => ({
|
|
1273
|
+
value: void 0,
|
|
1274
|
+
diagnostics: [createBootstrapDiagnostic({
|
|
1275
|
+
code: "unsupported-global-prefix",
|
|
1276
|
+
title: "Unsupported global prefix.",
|
|
1277
|
+
detail,
|
|
1278
|
+
expected: EXPECTED$1,
|
|
1279
|
+
node,
|
|
1280
|
+
sourceFile,
|
|
1281
|
+
filePath
|
|
1282
|
+
})]
|
|
1283
|
+
});
|
|
1284
|
+
var detectGlobalPrefix = (bootstrapFilePath) => {
|
|
1285
|
+
const sourceFile = parseSourceFile(bootstrapFilePath);
|
|
1286
|
+
const calls = collectBootstrapCalls(sourceFile, SET_GLOBAL_PREFIX_METHOD_NAME);
|
|
1287
|
+
const [first] = calls;
|
|
1288
|
+
if (first === void 0) return {
|
|
1289
|
+
value: void 0,
|
|
1290
|
+
diagnostics: []
|
|
1291
|
+
};
|
|
1292
|
+
if (calls.length > 1 || first.conditional) return unsupported$1(sourceFile, bootstrapFilePath, first.call, "setGlobalPrefix() must be called exactly once and unconditionally.");
|
|
1293
|
+
const [prefixArgument, optionsArgument] = first.call.arguments;
|
|
1294
|
+
if (prefixArgument === void 0 || !isStringLiteralLikeNode(prefixArgument)) return unsupported$1(sourceFile, bootstrapFilePath, first.call, "The global prefix must be a string literal.");
|
|
1295
|
+
const exclude = readGlobalPrefixExclusions(optionsArgument);
|
|
1296
|
+
if (exclude === void 0) return unsupported$1(sourceFile, bootstrapFilePath, first.call, "Global prefix exclusions must be statically analyzable.");
|
|
1297
|
+
return {
|
|
1298
|
+
value: {
|
|
1299
|
+
prefix: prefixArgument.text,
|
|
1300
|
+
exclude
|
|
1301
|
+
},
|
|
1302
|
+
diagnostics: []
|
|
1303
|
+
};
|
|
1304
|
+
};
|
|
1305
|
+
//#endregion
|
|
1028
1306
|
//#region src/analysis/find-global-interceptor-class-names.ts
|
|
1029
1307
|
var USE_GLOBAL_INTERCEPTORS_METHOD_NAME = "useGlobalInterceptors";
|
|
1030
1308
|
var collectUseGlobalInterceptorsCalls = (node, calls) => {
|
|
@@ -1155,6 +1433,71 @@ var detectResponseWrapper = (bootstrapFilePath) => {
|
|
|
1155
1433
|
return { wrappedResultTypeSource: composedTypeSource };
|
|
1156
1434
|
};
|
|
1157
1435
|
//#endregion
|
|
1436
|
+
//#region src/analysis/detect-versioning.ts
|
|
1437
|
+
var ENABLE_VERSIONING_METHOD_NAME = "enableVersioning";
|
|
1438
|
+
var VERSIONING_TYPE_ENUM_NAME = "VersioningType";
|
|
1439
|
+
var URI_VERSIONING_TYPE_NAME = "URI";
|
|
1440
|
+
var TYPE_OPTION_NAME = "type";
|
|
1441
|
+
var PREFIX_OPTION_NAME = "prefix";
|
|
1442
|
+
var DEFAULT_VERSION_OPTION_NAME = "defaultVersion";
|
|
1443
|
+
var DEFAULT_VERSION_PREFIX = "v";
|
|
1444
|
+
var EXPECTED = "A single unconditional enableVersioning() call with `type: VersioningType.URI`, a string literal or `false` prefix, and a string literal defaultVersion. Header, media type and custom versioning need request headers NestBridge cannot set. Set the `versioning` option to provide URI versioning explicitly.";
|
|
1445
|
+
var unsupported = (sourceFile, filePath, node, detail) => ({
|
|
1446
|
+
value: void 0,
|
|
1447
|
+
diagnostics: [createBootstrapDiagnostic({
|
|
1448
|
+
code: "unsupported-versioning",
|
|
1449
|
+
title: "Unsupported versioning.",
|
|
1450
|
+
detail,
|
|
1451
|
+
expected: EXPECTED,
|
|
1452
|
+
node,
|
|
1453
|
+
sourceFile,
|
|
1454
|
+
filePath
|
|
1455
|
+
})]
|
|
1456
|
+
});
|
|
1457
|
+
var isUriVersioningType = (node) => isPropertyAccessExpression(node) && isIdentifier(node.expression) && node.expression.text === VERSIONING_TYPE_ENUM_NAME && node.name.text === URI_VERSIONING_TYPE_NAME;
|
|
1458
|
+
var detectVersioning = (bootstrapFilePath) => {
|
|
1459
|
+
const sourceFile = parseSourceFile(bootstrapFilePath);
|
|
1460
|
+
const calls = collectBootstrapCalls(sourceFile, ENABLE_VERSIONING_METHOD_NAME);
|
|
1461
|
+
const [first] = calls;
|
|
1462
|
+
if (first === void 0) return {
|
|
1463
|
+
value: void 0,
|
|
1464
|
+
diagnostics: []
|
|
1465
|
+
};
|
|
1466
|
+
if (calls.length > 1 || first.conditional) return unsupported(sourceFile, bootstrapFilePath, first.call, "enableVersioning() must be called exactly once and unconditionally.");
|
|
1467
|
+
const [options] = first.call.arguments;
|
|
1468
|
+
if (options === void 0 || !isObjectLiteralExpression(options)) return unsupported(sourceFile, bootstrapFilePath, first.call, "The versioning options must be an object literal.");
|
|
1469
|
+
let hasUriType = false;
|
|
1470
|
+
let prefix = DEFAULT_VERSION_PREFIX;
|
|
1471
|
+
let defaultVersion;
|
|
1472
|
+
for (const property of options.properties) {
|
|
1473
|
+
if (!isPropertyAssignment(property)) return unsupported(sourceFile, bootstrapFilePath, property, "Versioning options must be written as plain properties.");
|
|
1474
|
+
const optionName = property.name.getText();
|
|
1475
|
+
const value = property.initializer;
|
|
1476
|
+
if (optionName === TYPE_OPTION_NAME) {
|
|
1477
|
+
if (!isUriVersioningType(value)) return unsupported(sourceFile, bootstrapFilePath, property, "Only VersioningType.URI is supported.");
|
|
1478
|
+
hasUriType = true;
|
|
1479
|
+
}
|
|
1480
|
+
if (optionName === PREFIX_OPTION_NAME) {
|
|
1481
|
+
if (value.kind === SyntaxKind.FalseKeyword) prefix = "";
|
|
1482
|
+
else if (isStringLiteralLikeNode(value)) prefix = value.text;
|
|
1483
|
+
else return unsupported(sourceFile, bootstrapFilePath, property, "The version prefix must be a string literal or false.");
|
|
1484
|
+
}
|
|
1485
|
+
if (optionName === DEFAULT_VERSION_OPTION_NAME) {
|
|
1486
|
+
const routeVersion = readRouteVersion(value);
|
|
1487
|
+
if (!routeVersion.ok) return unsupported(sourceFile, bootstrapFilePath, property, "The default version must be a string literal.");
|
|
1488
|
+
defaultVersion = routeVersion.version ?? void 0;
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1491
|
+
if (!hasUriType) return unsupported(sourceFile, bootstrapFilePath, first.call, "The versioning type must be VersioningType.URI.");
|
|
1492
|
+
return {
|
|
1493
|
+
value: defaultVersion === void 0 ? { prefix } : {
|
|
1494
|
+
prefix,
|
|
1495
|
+
defaultVersion
|
|
1496
|
+
},
|
|
1497
|
+
diagnostics: []
|
|
1498
|
+
};
|
|
1499
|
+
};
|
|
1500
|
+
//#endregion
|
|
1158
1501
|
//#region src/declarations/generate-controller-declaration.ts
|
|
1159
1502
|
var REMOTE_RESULT_HELPERS = {
|
|
1160
1503
|
json: "RemoteResult",
|
|
@@ -1242,8 +1585,8 @@ var NestBridgeDiagnosticError = class extends Error {
|
|
|
1242
1585
|
};
|
|
1243
1586
|
//#endregion
|
|
1244
1587
|
//#region src/version.ts
|
|
1245
|
-
var VERSION = "2.
|
|
1588
|
+
var VERSION = "2.3.0";
|
|
1246
1589
|
//#endregion
|
|
1247
|
-
export { NestBridgeDiagnosticError, VERSION, analyzeControllers, analyzeResolvers, detectErrorResponseShape, detectResponseWrapper, formatDiagnostic, generateControllerDeclaration, generateErrorBodyDeclaration };
|
|
1590
|
+
export { NestBridgeDiagnosticError, VERSION, analyzeControllers, analyzeResolvers, applyApplicationRouting, detectErrorResponseShape, detectGlobalPrefix, detectResponseWrapper, detectVersioning, formatDiagnostic, generateControllerDeclaration, generateErrorBodyDeclaration };
|
|
1248
1591
|
|
|
1249
1592
|
//# sourceMappingURL=nestbridge.core.js.map
|