@nestia/core 12.0.0-dev.20260521.6 → 12.0.0-dev.20260612.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/LICENSE +21 -21
- package/MIGRATION.md +169 -169
- package/README.md +93 -93
- package/lib/adaptors/McpAdaptor.d.ts +75 -0
- package/lib/adaptors/McpAdaptor.js +257 -0
- package/lib/adaptors/McpAdaptor.js.map +1 -0
- package/lib/adaptors/WebSocketAdaptor.js +4 -4
- package/lib/adaptors/WebSocketAdaptor.js.map +1 -1
- package/lib/decorators/McpRoute.d.ts +69 -0
- package/lib/decorators/McpRoute.js +58 -0
- package/lib/decorators/McpRoute.js.map +1 -0
- package/lib/decorators/TypedParam.js +4 -4
- package/lib/decorators/TypedParam.js.map +1 -1
- package/lib/decorators/TypedRoute.js +1 -1
- package/lib/decorators/TypedRoute.js.map +1 -1
- package/lib/decorators/internal/IMcpRouteReflect.d.ts +2 -0
- package/lib/decorators/internal/IMcpRouteReflect.js +3 -0
- package/lib/decorators/internal/IMcpRouteReflect.js.map +1 -0
- package/lib/decorators/internal/get_path_and_querify.js +4 -4
- package/lib/decorators/internal/get_path_and_querify.js.map +1 -1
- package/lib/decorators/internal/get_path_and_stringify.js +4 -4
- package/lib/decorators/internal/get_path_and_stringify.js.map +1 -1
- package/lib/decorators/internal/load_controller.js +34 -65
- package/lib/decorators/internal/load_controller.js.map +1 -1
- package/lib/decorators/internal/validate_request_body.js +4 -4
- package/lib/decorators/internal/validate_request_body.js.map +1 -1
- package/lib/decorators/internal/validate_request_form_data.js +4 -4
- package/lib/decorators/internal/validate_request_form_data.js.map +1 -1
- package/lib/decorators/internal/validate_request_headers.js +4 -4
- package/lib/decorators/internal/validate_request_headers.js.map +1 -1
- package/lib/decorators/internal/validate_request_query.js +4 -4
- package/lib/decorators/internal/validate_request_query.js.map +1 -1
- package/lib/module.d.ts +2 -0
- package/lib/module.js +2 -0
- package/lib/module.js.map +1 -1
- package/native/cmd/ttsc-nestia/main.go +11 -11
- package/native/go.mod +32 -32
- package/native/go.sum +54 -54
- package/native/plugin/plan.go +102 -102
- package/native/transform/ast.go +32 -32
- package/native/transform/build.go +380 -437
- package/native/transform/cleanup.go +408 -408
- package/native/transform/contributor.go +97 -68
- package/native/transform/core_querify.go +231 -227
- package/native/transform/core_transform.go +1996 -1713
- package/native/transform/core_websocket.go +115 -115
- package/native/transform/exports.go +13 -13
- package/native/transform/mcp_transform.go +414 -0
- package/native/transform/node_transform.go +357 -0
- package/native/transform/path_rewrite.go +285 -285
- package/native/transform/printer.go +244 -244
- package/native/transform/rewrite.go +668 -662
- package/native/transform/run.go +73 -73
- package/native/transform/transform.go +336 -387
- package/native/transform/typia_fast.go +352 -326
- package/native/transform/typia_replacement.go +24 -24
- package/native/transform.cjs +43 -43
- package/package.json +15 -8
- package/src/adaptors/McpAdaptor.ts +276 -0
- package/src/adaptors/WebSocketAdaptor.ts +429 -429
- package/src/decorators/DynamicModule.ts +44 -44
- package/src/decorators/EncryptedBody.ts +97 -97
- package/src/decorators/EncryptedController.ts +40 -40
- package/src/decorators/EncryptedModule.ts +98 -98
- package/src/decorators/EncryptedRoute.ts +213 -213
- package/src/decorators/HumanRoute.ts +21 -21
- package/src/decorators/McpRoute.ts +154 -0
- package/src/decorators/NoTransformConfigurationError.ts +40 -40
- package/src/decorators/PlainBody.ts +76 -76
- package/src/decorators/SwaggerCustomizer.ts +97 -97
- package/src/decorators/SwaggerExample.ts +180 -180
- package/src/decorators/TypedBody.ts +57 -57
- package/src/decorators/TypedException.ts +147 -147
- package/src/decorators/TypedFormData.ts +187 -187
- package/src/decorators/TypedHeaders.ts +66 -66
- package/src/decorators/TypedParam.ts +77 -77
- package/src/decorators/TypedQuery.ts +234 -234
- package/src/decorators/TypedRoute.ts +198 -196
- package/src/decorators/WebSocketRoute.ts +242 -242
- package/src/decorators/doNotThrowTransformError.ts +5 -5
- package/src/decorators/internal/EncryptedConstant.ts +2 -2
- package/src/decorators/internal/IMcpRouteReflect.ts +40 -0
- package/src/decorators/internal/IWebSocketRouteReflect.ts +23 -23
- package/src/decorators/internal/get_path_and_querify.ts +94 -94
- package/src/decorators/internal/get_path_and_stringify.ts +110 -110
- package/src/decorators/internal/get_text_body.ts +16 -16
- package/src/decorators/internal/headers_to_object.ts +11 -11
- package/src/decorators/internal/is_request_body_undefined.ts +12 -12
- package/src/decorators/internal/load_controller.ts +91 -76
- package/src/decorators/internal/route_error.ts +43 -43
- package/src/decorators/internal/validate_request_body.ts +64 -64
- package/src/decorators/internal/validate_request_form_data.ts +67 -67
- package/src/decorators/internal/validate_request_headers.ts +76 -76
- package/src/decorators/internal/validate_request_query.ts +83 -83
- package/src/index.ts +5 -5
- package/src/module.ts +25 -23
- package/src/options/IRequestBodyValidator.ts +20 -20
- package/src/options/IRequestFormDataProps.ts +27 -27
- package/src/options/IRequestHeadersValidator.ts +22 -22
- package/src/options/IRequestQueryValidator.ts +20 -20
- package/src/options/IResponseBodyQuerifier.ts +25 -25
- package/src/options/IResponseBodyStringifier.ts +30 -30
- package/src/transform.ts +101 -101
- package/src/typings/Creator.ts +3 -3
- package/src/typings/get-function-location.d.ts +7 -7
- package/src/utils/ArrayUtil.ts +7 -7
- package/src/utils/ExceptionManager.ts +115 -115
- package/src/utils/Singleton.ts +16 -16
- package/src/utils/SourceFinder.ts +54 -54
- package/src/utils/VersioningStrategy.ts +27 -27
- package/native/transform/cleanup_test.go +0 -76
- package/native/transform/commonjs_import_alias_test.go +0 -49
- package/native/transform/core_dispatch_test.go +0 -127
- package/native/transform/path_rewrite_test.go +0 -243
- package/native/transform/rewrite_test.go +0 -118
- package/native/transform/rewrite_unique_base_test.go +0 -48
|
@@ -1,115 +1,115 @@
|
|
|
1
|
-
import { HttpError } from "@nestia/fetcher";
|
|
2
|
-
import { HttpException } from "@nestjs/common";
|
|
3
|
-
|
|
4
|
-
import { Creator } from "../typings/Creator";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Exception manager for HTTP server.
|
|
8
|
-
*
|
|
9
|
-
* `ExceptionManager` is an utility class who can insert or erase custom error
|
|
10
|
-
* class with its conversion method to a regular {@link nest.HttpException}
|
|
11
|
-
* instance.
|
|
12
|
-
*
|
|
13
|
-
* If you define an API function through {@link TypedRoute} or
|
|
14
|
-
* {@link EncryptedRoute} instead of the basic router decorator functions like
|
|
15
|
-
* {@link nest.Get} or {@link nest.Post} and the API function throws a custom
|
|
16
|
-
* error whose class has been {@link ExceptionManager.insert inserted} in this
|
|
17
|
-
* `EntityManager`, the error would be automatically converted to the regular
|
|
18
|
-
* {@link nest.HttpException} instance by the {@link ExceptionManager.Closure}
|
|
19
|
-
* function.
|
|
20
|
-
*
|
|
21
|
-
* Therefore, with this `ExceptionManager` and {@link TypedRoute} or
|
|
22
|
-
* {@link EncryptedRoute}, you can manage your custom error classes much
|
|
23
|
-
* systemtically. You can avoid 500 internal server error or hard coding
|
|
24
|
-
* implementation about the custom error classes.
|
|
25
|
-
*
|
|
26
|
-
* Below error classes are defaultly configured in this `ExceptionManager`
|
|
27
|
-
*
|
|
28
|
-
* - `typia.TypeGuardError`
|
|
29
|
-
* - `@nestia/fetcher.HttpError`
|
|
30
|
-
*
|
|
31
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
32
|
-
*/
|
|
33
|
-
export namespace ExceptionManager {
|
|
34
|
-
/**
|
|
35
|
-
* Insert an error class with converter.
|
|
36
|
-
*
|
|
37
|
-
* If you've inserted an duplicated error class, the closure would be
|
|
38
|
-
* overwritten.
|
|
39
|
-
*
|
|
40
|
-
* @param creator Target error class
|
|
41
|
-
* @param closure A closure function converting to the `HttpException` class
|
|
42
|
-
*/
|
|
43
|
-
export function insert<T extends Error>(
|
|
44
|
-
creator: Creator<T>,
|
|
45
|
-
closure: Closure<T>,
|
|
46
|
-
): void {
|
|
47
|
-
const index: number = tuples.findIndex((tuple) => tuple[0] === creator);
|
|
48
|
-
if (index !== -1) tuples.splice(index, 1);
|
|
49
|
-
|
|
50
|
-
tuples.push([creator, closure]);
|
|
51
|
-
tuples.sort(([x], [y]) => (x.prototype instanceof y ? -1 : 1));
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Erase an error class.
|
|
56
|
-
*
|
|
57
|
-
* @param creator Target error class
|
|
58
|
-
* @returns Whether be erased or not
|
|
59
|
-
*/
|
|
60
|
-
export function erase<T extends Error>(creator: Creator<T>): boolean {
|
|
61
|
-
const index: number = tuples.findIndex((tuple) => tuple[0] === creator);
|
|
62
|
-
if (index === -1) return false;
|
|
63
|
-
|
|
64
|
-
tuples.splice(index, 1);
|
|
65
|
-
return true;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export function on(closure: (error: any) => any): void {
|
|
69
|
-
listeners.add(closure);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export function off(closure: (error: any) => any): void {
|
|
73
|
-
listeners.delete(closure);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Type of a closure function converting to the regular
|
|
78
|
-
* {@link nest.HttpException}.
|
|
79
|
-
*
|
|
80
|
-
* `ExceptionManager.Closure` is a type of closure function who are converting
|
|
81
|
-
* from custom error to the regular {@link nest.HttpException} instance. It
|
|
82
|
-
* would be used in the {@link ExceptionManager} with {@link TypedRoute} or
|
|
83
|
-
* {@link EncryptedRoute}.
|
|
84
|
-
*/
|
|
85
|
-
export interface Closure<T extends Error> {
|
|
86
|
-
/**
|
|
87
|
-
* Error converter.
|
|
88
|
-
*
|
|
89
|
-
* Convert from custom error to the regular {@link nest.HttpException}
|
|
90
|
-
* instance.
|
|
91
|
-
*
|
|
92
|
-
* @param exception Custom error instance
|
|
93
|
-
* @returns Regular {@link nest.HttpException} instance
|
|
94
|
-
*/
|
|
95
|
-
(exception: T): HttpException;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/** @internal */
|
|
99
|
-
export const tuples: Array<[Creator<any>, Closure<any>]> = [];
|
|
100
|
-
|
|
101
|
-
/** @internal */
|
|
102
|
-
export const listeners: Set<(error: any) => any> = new Set();
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
ExceptionManager.insert(
|
|
106
|
-
HttpError,
|
|
107
|
-
(error) =>
|
|
108
|
-
new HttpException(
|
|
109
|
-
{
|
|
110
|
-
path: error.path,
|
|
111
|
-
message: error.message,
|
|
112
|
-
},
|
|
113
|
-
error.status,
|
|
114
|
-
),
|
|
115
|
-
);
|
|
1
|
+
import { HttpError } from "@nestia/fetcher";
|
|
2
|
+
import { HttpException } from "@nestjs/common";
|
|
3
|
+
|
|
4
|
+
import { Creator } from "../typings/Creator";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Exception manager for HTTP server.
|
|
8
|
+
*
|
|
9
|
+
* `ExceptionManager` is an utility class who can insert or erase custom error
|
|
10
|
+
* class with its conversion method to a regular {@link nest.HttpException}
|
|
11
|
+
* instance.
|
|
12
|
+
*
|
|
13
|
+
* If you define an API function through {@link TypedRoute} or
|
|
14
|
+
* {@link EncryptedRoute} instead of the basic router decorator functions like
|
|
15
|
+
* {@link nest.Get} or {@link nest.Post} and the API function throws a custom
|
|
16
|
+
* error whose class has been {@link ExceptionManager.insert inserted} in this
|
|
17
|
+
* `EntityManager`, the error would be automatically converted to the regular
|
|
18
|
+
* {@link nest.HttpException} instance by the {@link ExceptionManager.Closure}
|
|
19
|
+
* function.
|
|
20
|
+
*
|
|
21
|
+
* Therefore, with this `ExceptionManager` and {@link TypedRoute} or
|
|
22
|
+
* {@link EncryptedRoute}, you can manage your custom error classes much
|
|
23
|
+
* systemtically. You can avoid 500 internal server error or hard coding
|
|
24
|
+
* implementation about the custom error classes.
|
|
25
|
+
*
|
|
26
|
+
* Below error classes are defaultly configured in this `ExceptionManager`
|
|
27
|
+
*
|
|
28
|
+
* - `typia.TypeGuardError`
|
|
29
|
+
* - `@nestia/fetcher.HttpError`
|
|
30
|
+
*
|
|
31
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
32
|
+
*/
|
|
33
|
+
export namespace ExceptionManager {
|
|
34
|
+
/**
|
|
35
|
+
* Insert an error class with converter.
|
|
36
|
+
*
|
|
37
|
+
* If you've inserted an duplicated error class, the closure would be
|
|
38
|
+
* overwritten.
|
|
39
|
+
*
|
|
40
|
+
* @param creator Target error class
|
|
41
|
+
* @param closure A closure function converting to the `HttpException` class
|
|
42
|
+
*/
|
|
43
|
+
export function insert<T extends Error>(
|
|
44
|
+
creator: Creator<T>,
|
|
45
|
+
closure: Closure<T>,
|
|
46
|
+
): void {
|
|
47
|
+
const index: number = tuples.findIndex((tuple) => tuple[0] === creator);
|
|
48
|
+
if (index !== -1) tuples.splice(index, 1);
|
|
49
|
+
|
|
50
|
+
tuples.push([creator, closure]);
|
|
51
|
+
tuples.sort(([x], [y]) => (x.prototype instanceof y ? -1 : 1));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Erase an error class.
|
|
56
|
+
*
|
|
57
|
+
* @param creator Target error class
|
|
58
|
+
* @returns Whether be erased or not
|
|
59
|
+
*/
|
|
60
|
+
export function erase<T extends Error>(creator: Creator<T>): boolean {
|
|
61
|
+
const index: number = tuples.findIndex((tuple) => tuple[0] === creator);
|
|
62
|
+
if (index === -1) return false;
|
|
63
|
+
|
|
64
|
+
tuples.splice(index, 1);
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function on(closure: (error: any) => any): void {
|
|
69
|
+
listeners.add(closure);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function off(closure: (error: any) => any): void {
|
|
73
|
+
listeners.delete(closure);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Type of a closure function converting to the regular
|
|
78
|
+
* {@link nest.HttpException}.
|
|
79
|
+
*
|
|
80
|
+
* `ExceptionManager.Closure` is a type of closure function who are converting
|
|
81
|
+
* from custom error to the regular {@link nest.HttpException} instance. It
|
|
82
|
+
* would be used in the {@link ExceptionManager} with {@link TypedRoute} or
|
|
83
|
+
* {@link EncryptedRoute}.
|
|
84
|
+
*/
|
|
85
|
+
export interface Closure<T extends Error> {
|
|
86
|
+
/**
|
|
87
|
+
* Error converter.
|
|
88
|
+
*
|
|
89
|
+
* Convert from custom error to the regular {@link nest.HttpException}
|
|
90
|
+
* instance.
|
|
91
|
+
*
|
|
92
|
+
* @param exception Custom error instance
|
|
93
|
+
* @returns Regular {@link nest.HttpException} instance
|
|
94
|
+
*/
|
|
95
|
+
(exception: T): HttpException;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** @internal */
|
|
99
|
+
export const tuples: Array<[Creator<any>, Closure<any>]> = [];
|
|
100
|
+
|
|
101
|
+
/** @internal */
|
|
102
|
+
export const listeners: Set<(error: any) => any> = new Set();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
ExceptionManager.insert(
|
|
106
|
+
HttpError,
|
|
107
|
+
(error) =>
|
|
108
|
+
new HttpException(
|
|
109
|
+
{
|
|
110
|
+
path: error.path,
|
|
111
|
+
message: error.message,
|
|
112
|
+
},
|
|
113
|
+
error.status,
|
|
114
|
+
),
|
|
115
|
+
);
|
package/src/utils/Singleton.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
/** @internal */
|
|
2
|
-
export class Singleton<T> {
|
|
3
|
-
private value_: T | object;
|
|
4
|
-
|
|
5
|
-
public constructor(private readonly closure_: () => T) {
|
|
6
|
-
this.value_ = NOT_MOUNTED_YET;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
public get(): T {
|
|
10
|
-
if (this.value_ === NOT_MOUNTED_YET) this.value_ = this.closure_();
|
|
11
|
-
return this.value_ as T;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/** @internal */
|
|
16
|
-
const NOT_MOUNTED_YET = {};
|
|
1
|
+
/** @internal */
|
|
2
|
+
export class Singleton<T> {
|
|
3
|
+
private value_: T | object;
|
|
4
|
+
|
|
5
|
+
public constructor(private readonly closure_: () => T) {
|
|
6
|
+
this.value_ = NOT_MOUNTED_YET;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
public get(): T {
|
|
10
|
+
if (this.value_ === NOT_MOUNTED_YET) this.value_ = this.closure_();
|
|
11
|
+
return this.value_ as T;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** @internal */
|
|
16
|
+
const NOT_MOUNTED_YET = {};
|
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import { glob } from "glob";
|
|
3
|
-
import path from "path";
|
|
4
|
-
|
|
5
|
-
export namespace SourceFinder {
|
|
6
|
-
export const find = async (props: IProps): Promise<string[]> => {
|
|
7
|
-
const dict: Set<string> = new Set();
|
|
8
|
-
|
|
9
|
-
await emplace(props.filter)(props.include)((str) => dict.add(str));
|
|
10
|
-
if (props.exclude?.length)
|
|
11
|
-
await emplace(props.filter)(props.exclude)((str) => dict.delete(str));
|
|
12
|
-
|
|
13
|
-
return [...dict];
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const emplace =
|
|
17
|
-
(filter: (file: string) => boolean) =>
|
|
18
|
-
(input: string[]) =>
|
|
19
|
-
async (closure: (location: string) => void): Promise<void> => {
|
|
20
|
-
for (const pattern of input) {
|
|
21
|
-
for (const file of await _Glob(path.resolve(pattern))) {
|
|
22
|
-
const stats: fs.Stats = await fs.promises.stat(file);
|
|
23
|
-
if (stats.isDirectory() === true)
|
|
24
|
-
await iterate(filter)(closure)(file);
|
|
25
|
-
else if (stats.isFile() && filter(file)) closure(file);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const iterate =
|
|
31
|
-
(filter: (location: string) => boolean) =>
|
|
32
|
-
(closure: (location: string) => void) =>
|
|
33
|
-
async (location: string): Promise<void> => {
|
|
34
|
-
const directory: string[] = await fs.promises.readdir(location);
|
|
35
|
-
for (const file of directory) {
|
|
36
|
-
const next: string = path.resolve(`${location}/${file}`);
|
|
37
|
-
const stats: fs.Stats = await fs.promises.stat(next);
|
|
38
|
-
|
|
39
|
-
if (stats.isDirectory() === true) await iterate(filter)(closure)(next);
|
|
40
|
-
else if (stats.isFile() && filter(next)) closure(next);
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const _Glob = async (pattern: string): Promise<string[]> => {
|
|
45
|
-
const matches = await glob(pattern);
|
|
46
|
-
return matches.map((str) => path.resolve(str));
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
interface IProps {
|
|
51
|
-
exclude?: string[];
|
|
52
|
-
include: string[];
|
|
53
|
-
filter: (location: string) => boolean;
|
|
54
|
-
}
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import { glob } from "glob";
|
|
3
|
+
import path from "path";
|
|
4
|
+
|
|
5
|
+
export namespace SourceFinder {
|
|
6
|
+
export const find = async (props: IProps): Promise<string[]> => {
|
|
7
|
+
const dict: Set<string> = new Set();
|
|
8
|
+
|
|
9
|
+
await emplace(props.filter)(props.include)((str) => dict.add(str));
|
|
10
|
+
if (props.exclude?.length)
|
|
11
|
+
await emplace(props.filter)(props.exclude)((str) => dict.delete(str));
|
|
12
|
+
|
|
13
|
+
return [...dict];
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const emplace =
|
|
17
|
+
(filter: (file: string) => boolean) =>
|
|
18
|
+
(input: string[]) =>
|
|
19
|
+
async (closure: (location: string) => void): Promise<void> => {
|
|
20
|
+
for (const pattern of input) {
|
|
21
|
+
for (const file of await _Glob(path.resolve(pattern))) {
|
|
22
|
+
const stats: fs.Stats = await fs.promises.stat(file);
|
|
23
|
+
if (stats.isDirectory() === true)
|
|
24
|
+
await iterate(filter)(closure)(file);
|
|
25
|
+
else if (stats.isFile() && filter(file)) closure(file);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const iterate =
|
|
31
|
+
(filter: (location: string) => boolean) =>
|
|
32
|
+
(closure: (location: string) => void) =>
|
|
33
|
+
async (location: string): Promise<void> => {
|
|
34
|
+
const directory: string[] = await fs.promises.readdir(location);
|
|
35
|
+
for (const file of directory) {
|
|
36
|
+
const next: string = path.resolve(`${location}/${file}`);
|
|
37
|
+
const stats: fs.Stats = await fs.promises.stat(next);
|
|
38
|
+
|
|
39
|
+
if (stats.isDirectory() === true) await iterate(filter)(closure)(next);
|
|
40
|
+
else if (stats.isFile() && filter(next)) closure(next);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const _Glob = async (pattern: string): Promise<string[]> => {
|
|
45
|
+
const matches = await glob(pattern);
|
|
46
|
+
return matches.map((str) => path.resolve(str));
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
interface IProps {
|
|
51
|
+
exclude?: string[];
|
|
52
|
+
include: string[];
|
|
53
|
+
filter: (location: string) => boolean;
|
|
54
|
+
}
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import { VERSION_NEUTRAL, VersionValue } from "@nestjs/common/interfaces";
|
|
2
|
-
|
|
3
|
-
export namespace VersioningStrategy {
|
|
4
|
-
export interface IConfig {
|
|
5
|
-
prefix: string;
|
|
6
|
-
defaultVersion?: VersionValue;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export const cast = (
|
|
10
|
-
value: VersionValue | undefined,
|
|
11
|
-
): Array<string | typeof VERSION_NEUTRAL> =>
|
|
12
|
-
value === undefined ? [] : Array.isArray(value) ? value : [value];
|
|
13
|
-
|
|
14
|
-
export const merge =
|
|
15
|
-
(config: IConfig | undefined) =>
|
|
16
|
-
(values: Array<string | typeof VERSION_NEUTRAL>): string[] => {
|
|
17
|
-
if (config === undefined) return [""];
|
|
18
|
-
const set: Set<string | typeof VERSION_NEUTRAL> = new Set(values);
|
|
19
|
-
const array: Array<string | typeof VERSION_NEUTRAL> =
|
|
20
|
-
set.size === 0 ? cast(config.defaultVersion) : Array.from(set);
|
|
21
|
-
return !!array?.length
|
|
22
|
-
? array.map((x) =>
|
|
23
|
-
typeof x === "symbol" ? "" : `${config.prefix}${x}`,
|
|
24
|
-
)
|
|
25
|
-
: [];
|
|
26
|
-
};
|
|
27
|
-
}
|
|
1
|
+
import { VERSION_NEUTRAL, VersionValue } from "@nestjs/common/interfaces";
|
|
2
|
+
|
|
3
|
+
export namespace VersioningStrategy {
|
|
4
|
+
export interface IConfig {
|
|
5
|
+
prefix: string;
|
|
6
|
+
defaultVersion?: VersionValue;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const cast = (
|
|
10
|
+
value: VersionValue | undefined,
|
|
11
|
+
): Array<string | typeof VERSION_NEUTRAL> =>
|
|
12
|
+
value === undefined ? [] : Array.isArray(value) ? value : [value];
|
|
13
|
+
|
|
14
|
+
export const merge =
|
|
15
|
+
(config: IConfig | undefined) =>
|
|
16
|
+
(values: Array<string | typeof VERSION_NEUTRAL>): string[] => {
|
|
17
|
+
if (config === undefined) return [""];
|
|
18
|
+
const set: Set<string | typeof VERSION_NEUTRAL> = new Set(values);
|
|
19
|
+
const array: Array<string | typeof VERSION_NEUTRAL> =
|
|
20
|
+
set.size === 0 ? cast(config.defaultVersion) : Array.from(set);
|
|
21
|
+
return !!array?.length
|
|
22
|
+
? array.map((x) =>
|
|
23
|
+
typeof x === "symbol" ? "" : `${config.prefix}${x}`,
|
|
24
|
+
)
|
|
25
|
+
: [];
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
package transform
|
|
2
|
-
|
|
3
|
-
import (
|
|
4
|
-
"strings"
|
|
5
|
-
"testing"
|
|
6
|
-
)
|
|
7
|
-
|
|
8
|
-
func TestCleanupTransformedTextWithRuntimeAliases(t *testing.T) {
|
|
9
|
-
input := strings.Join([]string{
|
|
10
|
-
`"use strict";`,
|
|
11
|
-
`const typia_1 = require("typia");`,
|
|
12
|
-
`const value = __typia_transform__isTypeInt32(input);`,
|
|
13
|
-
``,
|
|
14
|
-
}, "\n")
|
|
15
|
-
|
|
16
|
-
output := cleanupTransformedTextWithRuntimeAliases(
|
|
17
|
-
input,
|
|
18
|
-
[]string{"__typia_transform__isTypeInt32"},
|
|
19
|
-
)
|
|
20
|
-
|
|
21
|
-
if strings.Contains(output, `require("typia");`) {
|
|
22
|
-
t.Fatalf("unused typia import was not removed:\n%s", output)
|
|
23
|
-
}
|
|
24
|
-
expected := `const { _isTypeInt32: __typia_transform__isTypeInt32 } = require("typia/lib/internal/_isTypeInt32");`
|
|
25
|
-
if strings.Contains(output, expected) == false {
|
|
26
|
-
t.Fatalf("runtime import was not injected:\n%s", output)
|
|
27
|
-
}
|
|
28
|
-
if strings.Index(output, expected) >= strings.Index(output, "const value") {
|
|
29
|
-
t.Fatalf("runtime import was inserted after usage:\n%s", output)
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
func TestCleanupTransformedTextKeepsReferencedTypiaImport(t *testing.T) {
|
|
34
|
-
input := strings.Join([]string{
|
|
35
|
-
`"use strict";`,
|
|
36
|
-
`const typia_1 = require("typia");`,
|
|
37
|
-
`const value = typia_1.default.assert(input);`,
|
|
38
|
-
``,
|
|
39
|
-
}, "\n")
|
|
40
|
-
|
|
41
|
-
output := cleanupTransformedTextWithRuntimeAliases(input, []string{})
|
|
42
|
-
if strings.Contains(output, `const typia_1 = require("typia");`) == false {
|
|
43
|
-
t.Fatalf("referenced typia import was removed:\n%s", output)
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
func TestCleanupTransformedTextDoesNotDuplicateRuntimeImport(t *testing.T) {
|
|
48
|
-
existing := `const { _isTypeInt32: __typia_transform__isTypeInt32 } = require("typia/lib/internal/_isTypeInt32");`
|
|
49
|
-
input := strings.Join([]string{
|
|
50
|
-
`"use strict";`,
|
|
51
|
-
existing,
|
|
52
|
-
`const value = __typia_transform__isTypeInt32(input);`,
|
|
53
|
-
``,
|
|
54
|
-
}, "\n")
|
|
55
|
-
|
|
56
|
-
output := cleanupTransformedTextWithRuntimeAliases(
|
|
57
|
-
input,
|
|
58
|
-
[]string{"__typia_transform__isTypeInt32"},
|
|
59
|
-
)
|
|
60
|
-
if strings.Count(output, existing) != 1 {
|
|
61
|
-
t.Fatalf("runtime import was duplicated:\n%s", output)
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
func TestNativeRewriteSetCollectsRuntimeAliasesFromAppendArguments(t *testing.T) {
|
|
66
|
-
rewrites := newNativeRewriteSet()
|
|
67
|
-
rewrites.Add(nativeRewrite{
|
|
68
|
-
FilePath: "/project/src/controller.ts",
|
|
69
|
-
AppendArguments: []string{`__typia_transform__httpQueryParseURLSearchParams(input)`},
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
aliases := rewrites.RuntimeAliasesForOutput("/project/lib/controller.js")
|
|
73
|
-
if len(aliases) != 1 || aliases[0] != "__typia_transform__httpQueryParseURLSearchParams" {
|
|
74
|
-
t.Fatalf("unexpected aliases: %#v", aliases)
|
|
75
|
-
}
|
|
76
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
package transform
|
|
2
|
-
|
|
3
|
-
import "testing"
|
|
4
|
-
|
|
5
|
-
// Verifies commonJSImportAliasBase produces a valid JS identifier base
|
|
6
|
-
// for every module specifier the CommonJS substitution table feeds it.
|
|
7
|
-
//
|
|
8
|
-
// Output forms the `<base>_N.default` substitution map that the native
|
|
9
|
-
// rewrite scan looks up against tsgo's CJS emit. Any input that produces
|
|
10
|
-
// a non-identifier base (leading digit, contains `-`, empty after
|
|
11
|
-
// extension strip) would generate a substitution that never matches
|
|
12
|
-
// tsgo's emit and silently break the rewrite for that import. The
|
|
13
|
-
// reverted P-8 sat on top of this helper — locking the branches now
|
|
14
|
-
// guards the rewrite contract against future emit-side changes.
|
|
15
|
-
//
|
|
16
|
-
// 1. Letters / digits / `_` / `$` survive verbatim.
|
|
17
|
-
// 2. Non-identifier characters (dashes, dots, slashes) become `_`.
|
|
18
|
-
// 3. Empty or pathological bases (`.`, `/`) fall back to `mod`.
|
|
19
|
-
// 4. Leading digits are prefixed with `_` so the base is identifier-safe.
|
|
20
|
-
// 5. Unicode letters survive (Go's `unicode.IsLetter`).
|
|
21
|
-
// 6. File extensions are stripped before sanitization.
|
|
22
|
-
func TestCommonJSImportAliasBaseProducesIdentifierSafeName(t *testing.T) {
|
|
23
|
-
cases := []struct {
|
|
24
|
-
name string
|
|
25
|
-
module string
|
|
26
|
-
want string
|
|
27
|
-
}{
|
|
28
|
-
{"plain package", "typia", "typia"},
|
|
29
|
-
{"scoped package", "@nestia/core", "core"},
|
|
30
|
-
{"dotted package", "lodash.merge", "lodash"},
|
|
31
|
-
{"path with slashes", "@nestia/core/lib/transform", "transform"},
|
|
32
|
-
{"dashes become underscores", "kebab-case-lib", "kebab_case_lib"},
|
|
33
|
-
{"trailing extension stripped", "module.mjs", "module"},
|
|
34
|
-
{"empty becomes mod", "", "mod"},
|
|
35
|
-
{"dot becomes mod", ".", "mod"},
|
|
36
|
-
{"leading digit prefixed with underscore", "1abc", "_1abc"},
|
|
37
|
-
{"underscore start preserved", "_internal", "_internal"},
|
|
38
|
-
{"dollar start preserved", "$jq", "$jq"},
|
|
39
|
-
{"unicode letter preserved", "한글", "한글"},
|
|
40
|
-
{"mixed special chars sanitized", "foo.bar-baz", "foo"},
|
|
41
|
-
}
|
|
42
|
-
for _, tc := range cases {
|
|
43
|
-
t.Run(tc.name, func(t *testing.T) {
|
|
44
|
-
if got := commonJSImportAliasBase(tc.module); got != tc.want {
|
|
45
|
-
t.Fatalf("commonJSImportAliasBase(%q) = %q, want %q", tc.module, got, tc.want)
|
|
46
|
-
}
|
|
47
|
-
})
|
|
48
|
-
}
|
|
49
|
-
}
|