@nestia/core 0.1.5 → 0.1.6

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.
Files changed (44) hide show
  1. package/lib/decorators/PlainBody.d.ts +1 -1
  2. package/lib/decorators/PlainBody.js +1 -1
  3. package/lib/executable/core.d.ts +2 -0
  4. package/lib/executable/core.js +100 -0
  5. package/lib/executable/core.js.map +1 -0
  6. package/lib/executable/internal/CommandParser.d.ts +3 -0
  7. package/lib/executable/internal/CommandParser.js +21 -0
  8. package/lib/executable/internal/CommandParser.js.map +1 -0
  9. package/lib/executable/internal/CoreSetupWizard.d.ts +4 -0
  10. package/lib/executable/internal/CoreSetupWizard.js +259 -0
  11. package/lib/executable/internal/CoreSetupWizard.js.map +1 -0
  12. package/package.json +5 -1
  13. package/src/decorators/EncryptedBody.ts +102 -102
  14. package/src/decorators/EncryptedController.ts +43 -43
  15. package/src/decorators/EncryptedModule.ts +77 -77
  16. package/src/decorators/EncryptedRoute.ts +203 -203
  17. package/src/decorators/PlainBody.ts +38 -38
  18. package/src/decorators/TypedBody.ts +49 -49
  19. package/src/decorators/TypedParam.ts +70 -70
  20. package/src/decorators/TypedRoute.ts +149 -149
  21. package/src/decorators/internal/EncryptedConstant.ts +4 -4
  22. package/src/decorators/internal/get_path_and_stringify.ts +77 -77
  23. package/src/decorators/internal/headers_to_object.ts +10 -10
  24. package/src/decorators/internal/route_error.ts +38 -38
  25. package/src/decorators/internal/validate_request_body.ts +59 -59
  26. package/src/executable/core.ts +46 -0
  27. package/src/executable/internal/CommandParser.ts +15 -0
  28. package/src/executable/internal/CoreSetupWizard.ts +177 -0
  29. package/src/index.ts +5 -5
  30. package/src/module.ts +11 -11
  31. package/src/options/INestiaTransformOptions.ts +6 -6
  32. package/src/options/INestiaTransformProject.ts +7 -7
  33. package/src/options/IRequestBodyValidator.ts +20 -20
  34. package/src/options/IResponseBodyStringifier.ts +25 -25
  35. package/src/transform.ts +20 -20
  36. package/src/transformers/BodyTransformer.ts +106 -106
  37. package/src/transformers/FileTransformer.ts +49 -49
  38. package/src/transformers/MethodTransformer.ts +91 -91
  39. package/src/transformers/NodeTransformer.ts +18 -18
  40. package/src/transformers/ParameterTransformer.ts +45 -45
  41. package/src/transformers/RouteTransformer.ts +131 -131
  42. package/src/typings/Creator.ts +3 -3
  43. package/src/utils/ExceptionManager.ts +126 -126
  44. package/src/utils/Singleton.ts +20 -20
@@ -1,38 +1,38 @@
1
- import { HttpException } from "@nestjs/common";
2
- import express from "express";
3
- import { Observable, throwError } from "rxjs";
4
-
5
- import { ExceptionManager } from "../../utils/ExceptionManager";
6
-
7
- export function route_error(
8
- request: express.Request,
9
- error: any,
10
- ): Observable<never> {
11
- error = (() => {
12
- // HTTP-ERROR
13
- if (error instanceof HttpException) return error;
14
-
15
- // CUSTOM-REGISTERED ERROR
16
- for (const [creator, closure] of ExceptionManager.tuples)
17
- if (error instanceof creator) return closure(error);
18
-
19
- // MAYBE INTERNAL ERROR
20
- return error;
21
- })();
22
-
23
- try {
24
- error.method = request.method;
25
- error.path = request.path;
26
- } catch {}
27
-
28
- setTimeout(() => {
29
- for (const listener of ExceptionManager.listeners) {
30
- try {
31
- const res: any | Promise<any> = listener(error);
32
- if (typeof res === "object" && typeof res.catch === "function")
33
- res.catch(() => {});
34
- } catch {}
35
- }
36
- }, 0);
37
- return throwError(() => error);
38
- }
1
+ import { HttpException } from "@nestjs/common";
2
+ import express from "express";
3
+ import { Observable, throwError } from "rxjs";
4
+
5
+ import { ExceptionManager } from "../../utils/ExceptionManager";
6
+
7
+ export function route_error(
8
+ request: express.Request,
9
+ error: any,
10
+ ): Observable<never> {
11
+ error = (() => {
12
+ // HTTP-ERROR
13
+ if (error instanceof HttpException) return error;
14
+
15
+ // CUSTOM-REGISTERED ERROR
16
+ for (const [creator, closure] of ExceptionManager.tuples)
17
+ if (error instanceof creator) return closure(error);
18
+
19
+ // MAYBE INTERNAL ERROR
20
+ return error;
21
+ })();
22
+
23
+ try {
24
+ error.method = request.method;
25
+ error.path = request.path;
26
+ } catch {}
27
+
28
+ setTimeout(() => {
29
+ for (const listener of ExceptionManager.listeners) {
30
+ try {
31
+ const res: any | Promise<any> = listener(error);
32
+ if (typeof res === "object" && typeof res.catch === "function")
33
+ res.catch(() => {});
34
+ } catch {}
35
+ }
36
+ }, 0);
37
+ return throwError(() => error);
38
+ }
@@ -1,59 +1,59 @@
1
- import { BadRequestException } from "@nestjs/common";
2
- import { IValidation, TypeGuardError } from "typia";
3
-
4
- import { IRequestBodyValidator } from "../../options/IRequestBodyValidator";
5
-
6
- export const validate_request_body =
7
- (method: string) =>
8
- <T>(validator?: IRequestBodyValidator<T>) => {
9
- if (!validator)
10
- throw new Error(
11
- `Error on nestia.core.${method}(): no transformer.`,
12
- );
13
- else if (validator.type === "assert") return assert(validator.assert);
14
- else if (validator.type === "is") return is(validator.is);
15
- else if (validator.type === "validate")
16
- return validate(validator.validate);
17
- throw new Error(
18
- `Error on nestia.core.${method}(): invalid typed validator.`,
19
- );
20
- };
21
-
22
- const assert =
23
- <T>(closure: (data: T) => T) =>
24
- (data: T) => {
25
- try {
26
- closure(data);
27
- } catch (exp) {
28
- if (exp instanceof TypeGuardError) {
29
- throw new BadRequestException({
30
- path: exp.path,
31
- reason: exp.message,
32
- expected: exp.expected,
33
- value: exp.value,
34
- message: MESSAGE,
35
- });
36
- }
37
- throw exp;
38
- }
39
- };
40
-
41
- const is =
42
- <T>(closure: (data: T) => boolean) =>
43
- (data: T) => {
44
- const success: boolean = closure(data);
45
- if (success === false) throw new BadRequestException(MESSAGE);
46
- };
47
-
48
- const validate =
49
- <T>(closure: (data: T) => IValidation<T>) =>
50
- (data: T) => {
51
- const result: IValidation<T> = closure(data);
52
- if (result.success === false)
53
- throw new BadRequestException({
54
- errors: result.errors,
55
- message: MESSAGE,
56
- });
57
- };
58
-
59
- const MESSAGE = "Request body data is not following the promised type.";
1
+ import { BadRequestException } from "@nestjs/common";
2
+ import { IValidation, TypeGuardError } from "typia";
3
+
4
+ import { IRequestBodyValidator } from "../../options/IRequestBodyValidator";
5
+
6
+ export const validate_request_body =
7
+ (method: string) =>
8
+ <T>(validator?: IRequestBodyValidator<T>) => {
9
+ if (!validator)
10
+ throw new Error(
11
+ `Error on nestia.core.${method}(): no transformer.`,
12
+ );
13
+ else if (validator.type === "assert") return assert(validator.assert);
14
+ else if (validator.type === "is") return is(validator.is);
15
+ else if (validator.type === "validate")
16
+ return validate(validator.validate);
17
+ throw new Error(
18
+ `Error on nestia.core.${method}(): invalid typed validator.`,
19
+ );
20
+ };
21
+
22
+ const assert =
23
+ <T>(closure: (data: T) => T) =>
24
+ (data: T) => {
25
+ try {
26
+ closure(data);
27
+ } catch (exp) {
28
+ if (exp instanceof TypeGuardError) {
29
+ throw new BadRequestException({
30
+ path: exp.path,
31
+ reason: exp.message,
32
+ expected: exp.expected,
33
+ value: exp.value,
34
+ message: MESSAGE,
35
+ });
36
+ }
37
+ throw exp;
38
+ }
39
+ };
40
+
41
+ const is =
42
+ <T>(closure: (data: T) => boolean) =>
43
+ (data: T) => {
44
+ const success: boolean = closure(data);
45
+ if (success === false) throw new BadRequestException(MESSAGE);
46
+ };
47
+
48
+ const validate =
49
+ <T>(closure: (data: T) => IValidation<T>) =>
50
+ (data: T) => {
51
+ const result: IValidation<T> = closure(data);
52
+ if (result.success === false)
53
+ throw new BadRequestException({
54
+ errors: result.errors,
55
+ message: MESSAGE,
56
+ });
57
+ };
58
+
59
+ const MESSAGE = "Request body data is not following the promised type.";
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env node
2
+ import { CommandParser } from "./internal/CommandParser";
3
+ import { CoreSetupWizard } from "./internal/CoreSetupWizard";
4
+
5
+ const USAGE = `Wrong command has been detected. Use like below:
6
+
7
+ npx @nestia/core setup \\
8
+ --compiler (ttypescript|ts-patch) \\
9
+ --manager (npm|pnpm|yarn)
10
+
11
+ - npx @nestia/core setup
12
+ - npx @nestia/core setup --compiler ttypescript
13
+ - npx @nestia/core setup --compiler ts-patch
14
+ - npx @nestia/core setup --manager pnpm`;
15
+
16
+ function halt(desc: string): never {
17
+ console.error(desc);
18
+ process.exit(-1);
19
+ }
20
+
21
+ async function setup(): Promise<void> {
22
+ const options: Record<string, string> = CommandParser.parse(
23
+ process.argv.slice(3),
24
+ );
25
+ const manager: string = options.manager ?? "npm";
26
+ const compiler: string = options.compiler ?? "ttypescript";
27
+
28
+ if (
29
+ (compiler !== "ttypescript" && compiler !== "ts-patch") ||
30
+ (manager !== "npm" && manager !== "pnpm" && manager !== "yarn")
31
+ )
32
+ halt(USAGE);
33
+ else if (compiler === "ttypescript")
34
+ await CoreSetupWizard.ttypescript(manager);
35
+ else await CoreSetupWizard.tsPatch(manager);
36
+ }
37
+
38
+ async function main(): Promise<void> {
39
+ const type: string | undefined = process.argv[2];
40
+ if (type === "setup") await setup();
41
+ else halt(USAGE);
42
+ }
43
+ main().catch((exp) => {
44
+ console.error(exp);
45
+ process.exit(-1);
46
+ });
@@ -0,0 +1,15 @@
1
+ export namespace CommandParser {
2
+ export function parse(argList: string[]): Record<string, string> {
3
+ const output: Record<string, string> = {};
4
+ argList.forEach((arg, i) => {
5
+ if (arg.startsWith("--") === false) return;
6
+
7
+ const key = arg.slice(2);
8
+ const value: string | undefined = argList[i + 1];
9
+ if (value === undefined || value.startsWith("--")) return;
10
+
11
+ output[key] = value;
12
+ });
13
+ return output;
14
+ }
15
+ }
@@ -0,0 +1,177 @@
1
+ import cp from "child_process";
2
+ import type Comment from "comment-json";
3
+ import fs from "fs";
4
+
5
+ export namespace CoreSetupWizard {
6
+ export async function ttypescript(manager: string): Promise<void> {
7
+ // INSTALL
8
+ const pack: any = await prepare(manager);
9
+ add(manager)(pack)("ttypescript", true);
10
+ add(manager)(pack)("ts-node", true);
11
+
12
+ // TSCONFIG.JSON
13
+ await configure(manager)(pack);
14
+ }
15
+
16
+ export async function tsPatch(manager: string): Promise<void> {
17
+ // INSTALL
18
+ add(manager)(await prepare(manager))("ts-patch", true);
19
+ execute("npx ts-patch install");
20
+
21
+ // PACKAGE.JSON
22
+ const pack: any = JSON.parse(
23
+ await fs.promises.readFile("package.json", "utf8"),
24
+ );
25
+ if (!pack.scripts || typeof pack.scripts !== "object")
26
+ pack.scripts = {};
27
+ if (typeof pack.scripts.prepare === "string") {
28
+ if (pack.scripts.prepare.indexOf("ts-patch install") === -1)
29
+ pack.scripts.prepare =
30
+ "ts-patch install && " + pack.scripts.prepare;
31
+ } else pack.scripts.prepare = "ts-patch install";
32
+
33
+ await fs.promises.writeFile(
34
+ "package.json",
35
+ JSON.stringify(pack, null, 2),
36
+ "utf8",
37
+ );
38
+
39
+ // TSCONFIG.JSON
40
+ await configure(manager)(pack);
41
+ }
42
+
43
+ async function prepare(manager: string): Promise<any> {
44
+ if (fs.existsSync("package.json") === false)
45
+ halt(() => {})("make package.json file or move to it.");
46
+
47
+ const pack: any = JSON.parse(
48
+ await fs.promises.readFile("package.json", "utf8"),
49
+ );
50
+ add(manager)(pack)("typescript", true);
51
+ add(manager)(pack)("typia", false);
52
+ add(manager)(pack)("@nestia/core", false);
53
+ return pack;
54
+ }
55
+
56
+ const configure =
57
+ (manager: string) =>
58
+ async (pack: any): Promise<void> => {
59
+ // VALIDATE PRERATATION
60
+ if (fs.existsSync("tsconfig.json") === false) {
61
+ execute("npx tsc --init");
62
+ if (fs.existsSync("tsconfig.json") === false)
63
+ halt(() => {})("tsconfig.json file does not exist.");
64
+ }
65
+
66
+ const temporary: boolean = !fs.existsSync(
67
+ "node_modules/comment-json",
68
+ );
69
+ if (temporary === true) add(manager)(pack)("comment-json", true);
70
+
71
+ const halter: (msg: string) => never = halt(() => {
72
+ if (temporary === true) remove(manager)("comment-json", true);
73
+ });
74
+
75
+ // READ TSCONFIG FILE
76
+ const Comment: typeof import("comment-json") = await import(
77
+ process.cwd() + "/node_modules/comment-json"
78
+ );
79
+ const config: Comment.CommentObject = Comment.parse(
80
+ await fs.promises.readFile("tsconfig.json", "utf8"),
81
+ ) as Comment.CommentObject;
82
+ const options = config.compilerOptions as
83
+ | Comment.CommentObject
84
+ | undefined;
85
+ if (options === undefined)
86
+ halter(
87
+ `tsconfig.json file does not have "compilerOptions" property.`,
88
+ );
89
+
90
+ const plugins: Comment.CommentArray<Comment.CommentObject> =
91
+ (() => {
92
+ const plugins = options.plugins as
93
+ | Comment.CommentArray<Comment.CommentObject>
94
+ | undefined;
95
+ if (plugins === undefined)
96
+ return (options.plugins = [] as any);
97
+ else if (!Array.isArray(plugins))
98
+ halter(
99
+ `"plugins" property of tsconfig.json must be array type.`,
100
+ );
101
+ return plugins;
102
+ })();
103
+
104
+ // CHECK WHETHER CONFIGURED
105
+ const strict: boolean = options.strict === true;
106
+ const core: Comment.CommentObject | undefined = plugins.find(
107
+ (p) =>
108
+ typeof p === "object" &&
109
+ p !== null &&
110
+ p.transform === "@nestia/core/lib/transform",
111
+ );
112
+ const typia: Comment.CommentObject | undefined = plugins.find(
113
+ (p) =>
114
+ typeof p === "object" &&
115
+ p !== null &&
116
+ p.transform === "typia/lib/transform",
117
+ );
118
+
119
+ if (strict === true && core !== undefined && typia !== undefined) {
120
+ console.log(
121
+ "you've been already configured the tsconfig.json file.",
122
+ );
123
+ } else {
124
+ // DO CONFIGURE
125
+ options.strict = true;
126
+ if (core === undefined)
127
+ plugins.push({
128
+ transform: "@nestia/core/lib/transform",
129
+ } as any);
130
+ if (typia === undefined)
131
+ await fs.promises.writeFile(
132
+ "tsconfig.json",
133
+ Comment.stringify(config, null, 2),
134
+ );
135
+ }
136
+ if (temporary === true) remove(manager)("comment-json", false);
137
+ };
138
+ }
139
+
140
+ const add =
141
+ (manager: string) =>
142
+ (pack: any) =>
143
+ (modulo: string, devOnly: boolean): void => {
144
+ const exists: boolean =
145
+ (devOnly === false
146
+ ? !!pack.dependencies && !!pack.dependencies[modulo]
147
+ : !!pack.devDependencies && !!pack.devDependencies[modulo]) &&
148
+ fs.existsSync("node_modules/" + modulo);
149
+ const middle: string =
150
+ manager === "yarn"
151
+ ? `add${devOnly ? " -D" : ""}`
152
+ : `install ${devOnly ? "--save-dev" : "--save"}`;
153
+ if (exists === false) execute(`${manager} ${middle} ${modulo}`);
154
+ };
155
+
156
+ const remove =
157
+ (manager: string) =>
158
+ (modulo: string, devOnly: boolean): void => {
159
+ const middle: string =
160
+ manager === "yarn"
161
+ ? `remove${devOnly ? " -D" : ""}`
162
+ : `uninstall ${devOnly ? "--save-dev" : "--save"}`;
163
+ execute(`${manager} ${middle} ${modulo}`);
164
+ };
165
+
166
+ const halt =
167
+ (closer: () => any) =>
168
+ (desc: string): never => {
169
+ closer();
170
+ console.error(desc);
171
+ process.exit(-1);
172
+ };
173
+
174
+ function execute(command: string): void {
175
+ console.log(command);
176
+ cp.execSync(command, { stdio: "inherit" });
177
+ }
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
- import * as core from "./module";
2
-
3
- export * from "./module";
4
-
5
- export default core;
1
+ import * as core from "./module";
2
+
3
+ export * from "./module";
4
+
5
+ export default core;
package/src/module.ts CHANGED
@@ -1,11 +1,11 @@
1
- export * from "./decorators/DynamicModule";
2
- export * from "./decorators/EncryptedBody";
3
- export * from "./decorators/EncryptedController";
4
- export * from "./decorators/EncryptedModule";
5
- export * from "./decorators/EncryptedRoute";
6
- export * from "./utils/ExceptionManager";
7
- export * from "./decorators/PlainBody";
8
- export * from "./decorators/TypedBody";
9
- export * from "./decorators/TypedParam";
10
- export * from "./decorators/TypedRoute";
11
- export * from "./options/INestiaTransformOptions";
1
+ export * from "./decorators/DynamicModule";
2
+ export * from "./decorators/EncryptedBody";
3
+ export * from "./decorators/EncryptedController";
4
+ export * from "./decorators/EncryptedModule";
5
+ export * from "./decorators/EncryptedRoute";
6
+ export * from "./utils/ExceptionManager";
7
+ export * from "./decorators/PlainBody";
8
+ export * from "./decorators/TypedBody";
9
+ export * from "./decorators/TypedParam";
10
+ export * from "./decorators/TypedRoute";
11
+ export * from "./options/INestiaTransformOptions";
@@ -1,6 +1,6 @@
1
- import { ITransformOptions } from "typia/lib/transformers/ITransformOptions";
2
-
3
- export interface INestiaTransformOptions extends ITransformOptions {
4
- validate?: "assert" | "is" | "validate";
5
- stringify?: "stringify" | "assert" | "is" | "validate";
6
- }
1
+ import { ITransformOptions } from "typia/lib/transformers/ITransformOptions";
2
+
3
+ export interface INestiaTransformOptions extends ITransformOptions {
4
+ validate?: "assert" | "is" | "validate";
5
+ stringify?: "stringify" | "assert" | "is" | "validate";
6
+ }
@@ -1,7 +1,7 @@
1
- import { IProject } from "typia/lib/transformers/IProject";
2
-
3
- import { INestiaTransformOptions } from "./INestiaTransformOptions";
4
-
5
- export interface INestiaTransformProject extends Omit<IProject, "options"> {
6
- options: INestiaTransformOptions;
7
- }
1
+ import { IProject } from "typia/lib/transformers/IProject";
2
+
3
+ import { INestiaTransformOptions } from "./INestiaTransformOptions";
4
+
5
+ export interface INestiaTransformProject extends Omit<IProject, "options"> {
6
+ options: INestiaTransformOptions;
7
+ }
@@ -1,20 +1,20 @@
1
- import { IValidation } from "typia";
2
-
3
- export type IRequestBodyValidator<T> =
4
- | IRequestBodyValidator.IAssert<T>
5
- | IRequestBodyValidator.IIs<T>
6
- | IRequestBodyValidator.IValidate<T>;
7
- export namespace IRequestBodyValidator {
8
- export interface IAssert<T> {
9
- type: "assert";
10
- assert: (input: T) => T;
11
- }
12
- export interface IIs<T> {
13
- type: "is";
14
- is: (input: T) => boolean;
15
- }
16
- export interface IValidate<T> {
17
- type: "validate";
18
- validate: (input: T) => IValidation<T>;
19
- }
20
- }
1
+ import { IValidation } from "typia";
2
+
3
+ export type IRequestBodyValidator<T> =
4
+ | IRequestBodyValidator.IAssert<T>
5
+ | IRequestBodyValidator.IIs<T>
6
+ | IRequestBodyValidator.IValidate<T>;
7
+ export namespace IRequestBodyValidator {
8
+ export interface IAssert<T> {
9
+ type: "assert";
10
+ assert: (input: T) => T;
11
+ }
12
+ export interface IIs<T> {
13
+ type: "is";
14
+ is: (input: T) => boolean;
15
+ }
16
+ export interface IValidate<T> {
17
+ type: "validate";
18
+ validate: (input: T) => IValidation<T>;
19
+ }
20
+ }
@@ -1,25 +1,25 @@
1
- import { IValidation } from "typia";
2
-
3
- export type IResponseBodyStringifier<T> =
4
- | IResponseBodyStringifier.IStringify<T>
5
- | IResponseBodyStringifier.IIs<T>
6
- | IResponseBodyStringifier.IAssert<T>
7
- | IResponseBodyStringifier.IValidate<T>;
8
- export namespace IResponseBodyStringifier {
9
- export interface IStringify<T> {
10
- type: "stringify";
11
- stringify: (input: T) => string;
12
- }
13
- export interface IIs<T> {
14
- type: "is";
15
- is: (input: T) => string | null;
16
- }
17
- export interface IAssert<T> {
18
- type: "assert";
19
- assert: (input: T) => string;
20
- }
21
- export interface IValidate<T> {
22
- type: "validate";
23
- validate: (input: T) => IValidation<string>;
24
- }
25
- }
1
+ import { IValidation } from "typia";
2
+
3
+ export type IResponseBodyStringifier<T> =
4
+ | IResponseBodyStringifier.IStringify<T>
5
+ | IResponseBodyStringifier.IIs<T>
6
+ | IResponseBodyStringifier.IAssert<T>
7
+ | IResponseBodyStringifier.IValidate<T>;
8
+ export namespace IResponseBodyStringifier {
9
+ export interface IStringify<T> {
10
+ type: "stringify";
11
+ stringify: (input: T) => string;
12
+ }
13
+ export interface IIs<T> {
14
+ type: "is";
15
+ is: (input: T) => string | null;
16
+ }
17
+ export interface IAssert<T> {
18
+ type: "assert";
19
+ assert: (input: T) => string;
20
+ }
21
+ export interface IValidate<T> {
22
+ type: "validate";
23
+ validate: (input: T) => IValidation<string>;
24
+ }
25
+ }
package/src/transform.ts CHANGED
@@ -1,20 +1,20 @@
1
- import ts from "typescript";
2
- import { IProject } from "typia/lib/transformers/IProject";
3
-
4
- import { INestiaTransformOptions } from "./options/INestiaTransformOptions";
5
- import { FileTransformer } from "./transformers/FileTransformer";
6
-
7
- export default function transform(
8
- program: ts.Program,
9
- options?: INestiaTransformOptions,
10
- ): ts.TransformerFactory<ts.SourceFile> {
11
- const project: IProject = {
12
- program,
13
- compilerOptions: program.getCompilerOptions(),
14
- checker: program.getTypeChecker(),
15
- printer: ts.createPrinter(),
16
- options: options || {},
17
- };
18
- return (context) => (file) =>
19
- FileTransformer.transform(project, context, file);
20
- }
1
+ import ts from "typescript";
2
+ import { IProject } from "typia/lib/transformers/IProject";
3
+
4
+ import { INestiaTransformOptions } from "./options/INestiaTransformOptions";
5
+ import { FileTransformer } from "./transformers/FileTransformer";
6
+
7
+ export default function transform(
8
+ program: ts.Program,
9
+ options?: INestiaTransformOptions,
10
+ ): ts.TransformerFactory<ts.SourceFile> {
11
+ const project: IProject = {
12
+ program,
13
+ compilerOptions: program.getCompilerOptions(),
14
+ checker: program.getTypeChecker(),
15
+ printer: ts.createPrinter(),
16
+ options: options || {},
17
+ };
18
+ return (context) => (file) =>
19
+ FileTransformer.transform(project, context, file);
20
+ }