@nestia/sdk 3.0.0-dev.20231209 → 3.0.0-dev.20240412
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -9
- package/assets/config/nestia.config.ts +82 -79
- package/lib/INestiaConfig.d.ts +28 -6
- package/lib/NestiaSdkApplication.js +12 -10
- package/lib/NestiaSdkApplication.js.map +1 -1
- package/lib/analyses/ConfigAnalyzer.js +1 -1
- package/lib/analyses/ConfigAnalyzer.js.map +1 -1
- package/lib/analyses/ControllerAnalyzer.js +30 -15
- package/lib/analyses/ControllerAnalyzer.js.map +1 -1
- package/lib/analyses/ExceptionAnalyzer.js +35 -6
- package/lib/analyses/ExceptionAnalyzer.js.map +1 -1
- package/lib/analyses/ImportAnalyzer.d.ts +1 -2
- package/lib/analyses/ImportAnalyzer.js +2 -2
- package/lib/analyses/ImportAnalyzer.js.map +1 -1
- package/lib/analyses/PathAnalyzer.d.ts +2 -4
- package/lib/analyses/PathAnalyzer.js +27 -11
- package/lib/analyses/PathAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectAnalyzer.js +34 -22
- package/lib/analyses/ReflectAnalyzer.js.map +1 -1
- package/lib/analyses/SecurityAnalyzer.js +13 -8
- package/lib/analyses/SecurityAnalyzer.js.map +1 -1
- package/lib/executable/internal/NestiaConfigLoader.js +300 -220
- package/lib/executable/internal/NestiaConfigLoader.js.map +1 -1
- package/lib/executable/sdk.js +11 -11
- package/lib/generates/CloneGenerator.d.ts +6 -0
- package/lib/generates/CloneGenerator.js +62 -0
- package/lib/generates/CloneGenerator.js.map +1 -0
- package/lib/generates/E2eGenerator.d.ts +2 -1
- package/lib/generates/E2eGenerator.js +2 -2
- package/lib/generates/E2eGenerator.js.map +1 -1
- package/lib/generates/SdkGenerator.js +3 -11
- package/lib/generates/SdkGenerator.js.map +1 -1
- package/lib/generates/SwaggerGenerator.d.ts +2 -0
- package/lib/generates/SwaggerGenerator.js +119 -62
- package/lib/generates/SwaggerGenerator.js.map +1 -1
- package/lib/generates/internal/E2eFileProgrammer.d.ts +2 -1
- package/lib/generates/internal/E2eFileProgrammer.js +49 -53
- package/lib/generates/internal/E2eFileProgrammer.js.map +1 -1
- package/lib/generates/internal/FilePrinter.d.ts +10 -0
- package/lib/generates/internal/FilePrinter.js +46 -0
- package/lib/generates/internal/FilePrinter.js.map +1 -0
- package/lib/{utils → generates/internal}/ImportDictionary.d.ts +2 -1
- package/lib/{utils → generates/internal}/ImportDictionary.js +20 -14
- package/lib/generates/internal/ImportDictionary.js.map +1 -0
- package/lib/generates/internal/SdkAliasCollection.d.ts +12 -0
- package/lib/generates/internal/SdkAliasCollection.js +97 -0
- package/lib/generates/internal/SdkAliasCollection.js.map +1 -0
- package/lib/generates/internal/SdkCloneProgrammer.d.ts +12 -0
- package/lib/generates/internal/SdkCloneProgrammer.js +99 -0
- package/lib/generates/internal/SdkCloneProgrammer.js.map +1 -0
- package/lib/generates/internal/SdkFileProgrammer.d.ts +2 -1
- package/lib/generates/internal/SdkFileProgrammer.js +27 -28
- package/lib/generates/internal/SdkFileProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkFunctionProgrammer.d.ts +7 -2
- package/lib/generates/internal/SdkFunctionProgrammer.js +115 -322
- package/lib/generates/internal/SdkFunctionProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkImportWizard.d.ts +1 -1
- package/lib/generates/internal/SdkNamespaceProgrammer.d.ts +11 -0
- package/lib/generates/internal/SdkNamespaceProgrammer.js +180 -0
- package/lib/generates/internal/SdkNamespaceProgrammer.js.map +1 -0
- package/lib/generates/internal/SdkRouteProgrammer.d.ts +7 -0
- package/lib/generates/internal/SdkRouteProgrammer.js +55 -0
- package/lib/generates/internal/SdkRouteProgrammer.js.map +1 -0
- package/lib/generates/internal/SdkSimulationProgrammer.d.ts +8 -2
- package/lib/generates/internal/SdkSimulationProgrammer.js +103 -89
- package/lib/generates/internal/SdkSimulationProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkTypeProgrammer.d.ts +9 -0
- package/lib/generates/internal/SdkTypeProgrammer.js +228 -0
- package/lib/generates/internal/SdkTypeProgrammer.js.map +1 -0
- package/lib/generates/internal/SwaggerSchemaGenerator.d.ts +4 -4
- package/lib/generates/internal/SwaggerSchemaGenerator.js +30 -28
- package/lib/generates/internal/SwaggerSchemaGenerator.js.map +1 -1
- package/lib/structures/IController.d.ts +4 -2
- package/lib/structures/IRoute.d.ts +5 -4
- package/lib/structures/ISwaggerLazyProperty.d.ts +2 -2
- package/lib/structures/ISwaggerLazySchema.d.ts +2 -2
- package/lib/structures/ParamCategory.d.ts +1 -1
- package/lib/structures/TypeEntry.js +2 -2
- package/lib/structures/TypeEntry.js.map +1 -1
- package/lib/utils/StringUtil.d.ts +3 -0
- package/lib/utils/StringUtil.js +8 -0
- package/lib/utils/StringUtil.js.map +1 -0
- package/package.json +12 -16
- package/src/INestiaConfig.ts +30 -6
- package/src/NestiaSdkApplication.ts +255 -253
- package/src/analyses/AccessorAnalyzer.ts +60 -60
- package/src/analyses/ConfigAnalyzer.ts +147 -147
- package/src/analyses/ControllerAnalyzer.ts +42 -19
- package/src/analyses/ExceptionAnalyzer.ts +148 -115
- package/src/analyses/GenericAnalyzer.ts +51 -51
- package/src/analyses/ImportAnalyzer.ts +1 -2
- package/src/analyses/PathAnalyzer.ts +110 -98
- package/src/analyses/ReflectAnalyzer.ts +39 -35
- package/src/analyses/SecurityAnalyzer.ts +24 -20
- package/src/executable/internal/CommandParser.ts +15 -15
- package/src/executable/internal/NestiaConfigLoader.ts +67 -67
- package/src/executable/internal/NestiaSdkCommand.ts +60 -60
- package/src/executable/sdk.ts +73 -73
- package/src/generates/CloneGenerator.ts +62 -0
- package/src/generates/E2eGenerator.ts +66 -64
- package/src/generates/SdkGenerator.ts +84 -96
- package/src/generates/SwaggerGenerator.ts +145 -53
- package/src/generates/internal/E2eFileProgrammer.ts +182 -123
- package/src/generates/internal/FilePrinter.ts +53 -0
- package/src/{utils → generates/internal}/ImportDictionary.ts +35 -13
- package/src/generates/internal/SdkAliasCollection.ts +152 -0
- package/src/generates/internal/SdkCloneProgrammer.ts +155 -0
- package/src/generates/internal/SdkDistributionComposer.ts +91 -91
- package/src/generates/internal/SdkFileProgrammer.ts +115 -106
- package/src/generates/internal/SdkFunctionProgrammer.ts +298 -518
- package/src/generates/internal/SdkImportWizard.ts +55 -55
- package/src/generates/internal/SdkNamespaceProgrammer.ts +510 -0
- package/src/generates/internal/SdkRouteDirectory.ts +17 -17
- package/src/generates/internal/SdkRouteProgrammer.ts +83 -0
- package/src/generates/internal/SdkSimulationProgrammer.ts +365 -133
- package/src/generates/internal/SdkTypeProgrammer.ts +386 -0
- package/src/generates/internal/SwaggerSchemaGenerator.ts +437 -427
- package/src/generates/internal/SwaggerSchemaValidator.ts +198 -198
- package/src/index.ts +4 -4
- package/src/module.ts +2 -2
- package/src/structures/IController.ts +94 -95
- package/src/structures/IErrorReport.ts +6 -6
- package/src/structures/INestiaProject.ts +13 -13
- package/src/structures/INormalizedInput.ts +20 -20
- package/src/structures/IRoute.ts +53 -53
- package/src/structures/ISwaggerLazyProperty.ts +2 -2
- package/src/structures/ISwaggerLazySchema.ts +2 -2
- package/src/structures/ITypeTuple.ts +6 -6
- package/src/structures/MethodType.ts +5 -5
- package/src/structures/ParamCategory.ts +1 -1
- package/src/structures/TypeEntry.ts +1 -1
- package/src/utils/ArrayUtil.ts +26 -26
- package/src/utils/FileRetriever.ts +22 -22
- package/src/utils/MapUtil.ts +14 -14
- package/src/utils/PathUtil.ts +10 -10
- package/src/utils/SourceFinder.ts +66 -66
- package/src/utils/StringUtil.ts +6 -0
- package/src/utils/StripEnums.ts +5 -5
- package/assets/bundle/api/utils/NestiaSimulator.ts +0 -70
- package/lib/generates/internal/SdkDtoGenerator.d.ts +0 -9
- package/lib/generates/internal/SdkDtoGenerator.js +0 -294
- package/lib/generates/internal/SdkDtoGenerator.js.map +0 -1
- package/lib/generates/internal/SdkTypeDefiner.d.ts +0 -11
- package/lib/generates/internal/SdkTypeDefiner.js +0 -82
- package/lib/generates/internal/SdkTypeDefiner.js.map +0 -1
- package/lib/structures/ISwagger.d.ts +0 -72
- package/lib/structures/ISwagger.js +0 -3
- package/lib/structures/ISwagger.js.map +0 -1
- package/lib/structures/ISwaggerComponents.d.ts +0 -26
- package/lib/structures/ISwaggerComponents.js +0 -3
- package/lib/structures/ISwaggerComponents.js.map +0 -1
- package/lib/structures/ISwaggerInfo.d.ts +0 -71
- package/lib/structures/ISwaggerInfo.js +0 -3
- package/lib/structures/ISwaggerInfo.js.map +0 -1
- package/lib/structures/ISwaggerRoute.d.ts +0 -47
- package/lib/structures/ISwaggerRoute.js +0 -3
- package/lib/structures/ISwaggerRoute.js.map +0 -1
- package/lib/structures/ISwaggerSecurityScheme.d.ts +0 -56
- package/lib/structures/ISwaggerSecurityScheme.js +0 -3
- package/lib/structures/ISwaggerSecurityScheme.js.map +0 -1
- package/lib/utils/ImportDictionary.js.map +0 -1
- package/src/generates/internal/SdkDtoGenerator.ts +0 -424
- package/src/generates/internal/SdkTypeDefiner.ts +0 -119
- package/src/structures/ISwagger.ts +0 -91
- package/src/structures/ISwaggerComponents.ts +0 -29
- package/src/structures/ISwaggerInfo.ts +0 -80
- package/src/structures/ISwaggerRoute.ts +0 -51
- package/src/structures/ISwaggerSecurityScheme.ts +0 -65
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { RouteInfo, VersionValue } from "@nestjs/common/interfaces";
|
|
2
|
-
|
|
3
|
-
export interface INormalizedInput {
|
|
4
|
-
include: INormalizedInput.IInput[];
|
|
5
|
-
globalPrefix?: {
|
|
6
|
-
prefix: string;
|
|
7
|
-
exclude?: Array<string | RouteInfo>;
|
|
8
|
-
};
|
|
9
|
-
versioning?: {
|
|
10
|
-
prefix: string;
|
|
11
|
-
defaultVersion?: VersionValue;
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
export namespace INormalizedInput {
|
|
15
|
-
export interface IInput {
|
|
16
|
-
paths: string[];
|
|
17
|
-
file: string;
|
|
18
|
-
controller?: Function;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
1
|
+
import { RouteInfo, VersionValue } from "@nestjs/common/interfaces";
|
|
2
|
+
|
|
3
|
+
export interface INormalizedInput {
|
|
4
|
+
include: INormalizedInput.IInput[];
|
|
5
|
+
globalPrefix?: {
|
|
6
|
+
prefix: string;
|
|
7
|
+
exclude?: Array<string | RouteInfo>;
|
|
8
|
+
};
|
|
9
|
+
versioning?: {
|
|
10
|
+
prefix: string;
|
|
11
|
+
defaultVersion?: VersionValue;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export namespace INormalizedInput {
|
|
15
|
+
export interface IInput {
|
|
16
|
+
paths: string[];
|
|
17
|
+
file: string;
|
|
18
|
+
controller?: Function;
|
|
19
|
+
}
|
|
20
|
+
}
|
package/src/structures/IRoute.ts
CHANGED
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
import { Metadata } from "typia/lib/schemas/metadata/Metadata";
|
|
3
|
-
|
|
4
|
-
import { IController } from "./IController";
|
|
5
|
-
|
|
6
|
-
export interface IRoute {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
| { type: "
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
| "application/
|
|
50
|
-
| "application/
|
|
51
|
-
| "text/plain";
|
|
52
|
-
}
|
|
53
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { Metadata } from "typia/lib/schemas/metadata/Metadata";
|
|
3
|
+
|
|
4
|
+
import { IController } from "./IController";
|
|
5
|
+
|
|
6
|
+
export interface IRoute {
|
|
7
|
+
controller: Function;
|
|
8
|
+
name: string;
|
|
9
|
+
method: string;
|
|
10
|
+
path: string;
|
|
11
|
+
encrypted: boolean;
|
|
12
|
+
status?: number;
|
|
13
|
+
|
|
14
|
+
accessors: string[];
|
|
15
|
+
parameters: IRoute.IParameter[];
|
|
16
|
+
imports: [string, string[]][];
|
|
17
|
+
output: IRoute.IOutput;
|
|
18
|
+
|
|
19
|
+
location: string;
|
|
20
|
+
target: {
|
|
21
|
+
class: Function;
|
|
22
|
+
function: Function;
|
|
23
|
+
};
|
|
24
|
+
description?: string;
|
|
25
|
+
operationId?: string;
|
|
26
|
+
jsDocTags: ts.JSDocTagInfo[];
|
|
27
|
+
setHeaders: Array<
|
|
28
|
+
| { type: "setter"; source: string; target?: string }
|
|
29
|
+
| { type: "assigner"; source: string }
|
|
30
|
+
>;
|
|
31
|
+
security: Record<string, string[]>[];
|
|
32
|
+
exceptions: Record<number | "2XX" | "3XX" | "4XX" | "5XX", IRoute.IOutput>;
|
|
33
|
+
swaggerTags: string[];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export namespace IRoute {
|
|
37
|
+
export type IParameter = IController.IParameter & {
|
|
38
|
+
optional: boolean;
|
|
39
|
+
type: ts.Type;
|
|
40
|
+
typeName: string;
|
|
41
|
+
metadata?: Metadata;
|
|
42
|
+
};
|
|
43
|
+
export interface IOutput {
|
|
44
|
+
type: ts.Type;
|
|
45
|
+
typeName: string;
|
|
46
|
+
metadata?: Metadata;
|
|
47
|
+
description?: string;
|
|
48
|
+
contentType:
|
|
49
|
+
| "application/x-www-form-urlencoded"
|
|
50
|
+
| "application/json"
|
|
51
|
+
| "text/plain";
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { OpenApi } from "@samchon/openapi";
|
|
2
2
|
import { Metadata } from "typia/lib/schemas/metadata/Metadata";
|
|
3
3
|
|
|
4
4
|
export interface ISwaggerLazySchema {
|
|
5
5
|
metadata: Metadata;
|
|
6
|
-
schema: IJsonSchema;
|
|
6
|
+
schema: OpenApi.IJsonSchema;
|
|
7
7
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
export interface ITypeTuple {
|
|
4
|
-
type: ts.Type;
|
|
5
|
-
typeName: string;
|
|
6
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
export interface ITypeTuple {
|
|
4
|
+
type: ts.Type;
|
|
5
|
+
typeName: string;
|
|
6
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export type MethodType = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
2
|
-
|
|
3
|
-
export namespace MethodType {
|
|
4
|
-
export const VALUES: MethodType[] = ["GET", "POST", "PUT", "PATCH", "DELETE"];
|
|
5
|
-
}
|
|
1
|
+
export type MethodType = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
2
|
+
|
|
3
|
+
export namespace MethodType {
|
|
4
|
+
export const VALUES: MethodType[] = ["GET", "POST", "PUT", "PATCH", "DELETE"];
|
|
5
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export type ParamCategory = "param" | "query" | "body" | "headers";
|
|
1
|
+
export type ParamCategory = "param" | "query" | "body" | "rawBody" | "headers";
|
package/src/utils/ArrayUtil.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
export namespace ArrayUtil {
|
|
2
|
-
export function has<T>(array: T[], ...items: T[]): boolean {
|
|
3
|
-
return items.every(
|
|
4
|
-
(elem) => array.find((org) => org === elem) !== undefined,
|
|
5
|
-
);
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export async function asyncMap<Input, Output>(
|
|
9
|
-
array: Input[],
|
|
10
|
-
closure: (input: Input) => Promise<Output>,
|
|
11
|
-
): Promise<Output[]> {
|
|
12
|
-
const ret: Output[] = [];
|
|
13
|
-
for (const elem of array) ret.push(await closure(elem));
|
|
14
|
-
return ret;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export async function asyncFilter<Input>(
|
|
18
|
-
array: Input[],
|
|
19
|
-
closure: (input: Input) => Promise<boolean>,
|
|
20
|
-
): Promise<Input[]> {
|
|
21
|
-
const ret: Input[] = [];
|
|
22
|
-
for (const elem of array)
|
|
23
|
-
if ((await closure(elem)) === true) ret.push(elem);
|
|
24
|
-
return ret;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
1
|
+
export namespace ArrayUtil {
|
|
2
|
+
export function has<T>(array: T[], ...items: T[]): boolean {
|
|
3
|
+
return items.every(
|
|
4
|
+
(elem) => array.find((org) => org === elem) !== undefined,
|
|
5
|
+
);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export async function asyncMap<Input, Output>(
|
|
9
|
+
array: Input[],
|
|
10
|
+
closure: (input: Input) => Promise<Output>,
|
|
11
|
+
): Promise<Output[]> {
|
|
12
|
+
const ret: Output[] = [];
|
|
13
|
+
for (const elem of array) ret.push(await closure(elem));
|
|
14
|
+
return ret;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export async function asyncFilter<Input>(
|
|
18
|
+
array: Input[],
|
|
19
|
+
closure: (input: Input) => Promise<boolean>,
|
|
20
|
+
): Promise<Input[]> {
|
|
21
|
+
const ret: Input[] = [];
|
|
22
|
+
for (const elem of array)
|
|
23
|
+
if ((await closure(elem)) === true) ret.push(elem);
|
|
24
|
+
return ret;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
|
|
4
|
-
export namespace FileRetriever {
|
|
5
|
-
export const directory =
|
|
6
|
-
(name: string) =>
|
|
7
|
-
(dir: string, depth: number = 0): string | null => {
|
|
8
|
-
const location: string = path.join(dir, name);
|
|
9
|
-
if (fs.existsSync(location)) return dir;
|
|
10
|
-
else if (depth > 2) return null;
|
|
11
|
-
return directory(name)(path.join(dir, ".."), depth + 1);
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export const file =
|
|
15
|
-
(name: string) =>
|
|
16
|
-
(directory: string, depth: number = 0): string | null => {
|
|
17
|
-
const location: string = path.join(directory, name);
|
|
18
|
-
if (fs.existsSync(location)) return location;
|
|
19
|
-
else if (depth > 2) return null;
|
|
20
|
-
return file(name)(path.join(directory, ".."), depth + 1);
|
|
21
|
-
};
|
|
22
|
-
}
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
|
|
4
|
+
export namespace FileRetriever {
|
|
5
|
+
export const directory =
|
|
6
|
+
(name: string) =>
|
|
7
|
+
(dir: string, depth: number = 0): string | null => {
|
|
8
|
+
const location: string = path.join(dir, name);
|
|
9
|
+
if (fs.existsSync(location)) return dir;
|
|
10
|
+
else if (depth > 2) return null;
|
|
11
|
+
return directory(name)(path.join(dir, ".."), depth + 1);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const file =
|
|
15
|
+
(name: string) =>
|
|
16
|
+
(directory: string, depth: number = 0): string | null => {
|
|
17
|
+
const location: string = path.join(directory, name);
|
|
18
|
+
if (fs.existsSync(location)) return location;
|
|
19
|
+
else if (depth > 2) return null;
|
|
20
|
+
return file(name)(path.join(directory, ".."), depth + 1);
|
|
21
|
+
};
|
|
22
|
+
}
|
package/src/utils/MapUtil.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
export namespace MapUtil {
|
|
2
|
-
export function take<Key, T>(
|
|
3
|
-
dict: Map<Key, T>,
|
|
4
|
-
key: Key,
|
|
5
|
-
generator: () => T,
|
|
6
|
-
): T {
|
|
7
|
-
const oldbie: T | undefined = dict.get(key);
|
|
8
|
-
if (oldbie) return oldbie;
|
|
9
|
-
|
|
10
|
-
const value: T = generator();
|
|
11
|
-
dict.set(key, value);
|
|
12
|
-
return value;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
1
|
+
export namespace MapUtil {
|
|
2
|
+
export function take<Key, T>(
|
|
3
|
+
dict: Map<Key, T>,
|
|
4
|
+
key: Key,
|
|
5
|
+
generator: () => T,
|
|
6
|
+
): T {
|
|
7
|
+
const oldbie: T | undefined = dict.get(key);
|
|
8
|
+
if (oldbie) return oldbie;
|
|
9
|
+
|
|
10
|
+
const value: T = generator();
|
|
11
|
+
dict.set(key, value);
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
}
|
package/src/utils/PathUtil.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export namespace PathUtil {
|
|
2
|
-
export const accessors = (path: string) =>
|
|
3
|
-
path
|
|
4
|
-
.split("/")
|
|
5
|
-
.filter((str) => str.length && str[0] !== ":")
|
|
6
|
-
.map(normalize);
|
|
7
|
-
|
|
8
|
-
const normalize = (str: string) =>
|
|
9
|
-
str.split("-").join("_").split(".").join("_");
|
|
10
|
-
}
|
|
1
|
+
export namespace PathUtil {
|
|
2
|
+
export const accessors = (path: string) =>
|
|
3
|
+
path
|
|
4
|
+
.split("/")
|
|
5
|
+
.filter((str) => str.length && str[0] !== ":")
|
|
6
|
+
.map(normalize);
|
|
7
|
+
|
|
8
|
+
const normalize = (str: string) =>
|
|
9
|
+
str.split("-").join("_").split(".").join("_");
|
|
10
|
+
}
|
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import glob from "glob";
|
|
3
|
-
import path from "path";
|
|
4
|
-
|
|
5
|
-
export namespace SourceFinder {
|
|
6
|
-
interface IProps {
|
|
7
|
-
exclude?: string[];
|
|
8
|
-
include: string[];
|
|
9
|
-
filter: (location: string) => Promise<boolean>;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const find = async (props: IProps): Promise<string[]> => {
|
|
13
|
-
const dict: Set<string> = new Set();
|
|
14
|
-
|
|
15
|
-
await emplace(props.filter)(props.include)((str) => dict.add(str));
|
|
16
|
-
if (props.exclude?.length)
|
|
17
|
-
await emplace(props.filter)(props.exclude)((str) => dict.delete(str));
|
|
18
|
-
|
|
19
|
-
return [...dict];
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const emplace =
|
|
23
|
-
(filter: (file: string) => Promise<boolean>) =>
|
|
24
|
-
(input: string[]) =>
|
|
25
|
-
async (closure: (location: string) => void): Promise<void> => {
|
|
26
|
-
for (const pattern of input) {
|
|
27
|
-
if (_Is_file(pattern)) {
|
|
28
|
-
closure(path.resolve(pattern));
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
for (const file of await _Glob(pattern)) {
|
|
32
|
-
const stats: fs.Stats = await fs.promises.stat(file);
|
|
33
|
-
if (stats.isDirectory() === true)
|
|
34
|
-
await iterate(filter)(closure)(file);
|
|
35
|
-
else if (stats.isFile() && (await filter(file))) closure(file);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const iterate =
|
|
41
|
-
(filter: (location: string) => Promise<boolean>) =>
|
|
42
|
-
(closure: (location: string) => void) =>
|
|
43
|
-
async (location: string): Promise<void> => {
|
|
44
|
-
const directory: string[] = await fs.promises.readdir(location);
|
|
45
|
-
for (const file of directory) {
|
|
46
|
-
const next: string = path.resolve(`${location}/${file}`);
|
|
47
|
-
const stats: fs.Stats = await fs.promises.stat(next);
|
|
48
|
-
|
|
49
|
-
if (stats.isDirectory() === true) await iterate(filter)(closure)(next);
|
|
50
|
-
else if (stats.isFile() && (await filter(next))) closure(next);
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
const _Glob = (pattern: string): Promise<string[]> =>
|
|
55
|
-
new Promise((resolve, reject) => {
|
|
56
|
-
glob(pattern, (err, matches) => {
|
|
57
|
-
if (err) reject(err);
|
|
58
|
-
else resolve(matches.map((str) => path.resolve(str)));
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
const _Is_file = (pattern: string): boolean =>
|
|
63
|
-
pattern.endsWith(".ts") &&
|
|
64
|
-
!pattern.endsWith(".d.ts") &&
|
|
65
|
-
fs.existsSync(pattern);
|
|
66
|
-
}
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import glob from "glob";
|
|
3
|
+
import path from "path";
|
|
4
|
+
|
|
5
|
+
export namespace SourceFinder {
|
|
6
|
+
interface IProps {
|
|
7
|
+
exclude?: string[];
|
|
8
|
+
include: string[];
|
|
9
|
+
filter: (location: string) => Promise<boolean>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const find = async (props: IProps): Promise<string[]> => {
|
|
13
|
+
const dict: Set<string> = new Set();
|
|
14
|
+
|
|
15
|
+
await emplace(props.filter)(props.include)((str) => dict.add(str));
|
|
16
|
+
if (props.exclude?.length)
|
|
17
|
+
await emplace(props.filter)(props.exclude)((str) => dict.delete(str));
|
|
18
|
+
|
|
19
|
+
return [...dict];
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const emplace =
|
|
23
|
+
(filter: (file: string) => Promise<boolean>) =>
|
|
24
|
+
(input: string[]) =>
|
|
25
|
+
async (closure: (location: string) => void): Promise<void> => {
|
|
26
|
+
for (const pattern of input) {
|
|
27
|
+
if (_Is_file(pattern)) {
|
|
28
|
+
closure(path.resolve(pattern));
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
for (const file of await _Glob(pattern)) {
|
|
32
|
+
const stats: fs.Stats = await fs.promises.stat(file);
|
|
33
|
+
if (stats.isDirectory() === true)
|
|
34
|
+
await iterate(filter)(closure)(file);
|
|
35
|
+
else if (stats.isFile() && (await filter(file))) closure(file);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const iterate =
|
|
41
|
+
(filter: (location: string) => Promise<boolean>) =>
|
|
42
|
+
(closure: (location: string) => void) =>
|
|
43
|
+
async (location: string): Promise<void> => {
|
|
44
|
+
const directory: string[] = await fs.promises.readdir(location);
|
|
45
|
+
for (const file of directory) {
|
|
46
|
+
const next: string = path.resolve(`${location}/${file}`);
|
|
47
|
+
const stats: fs.Stats = await fs.promises.stat(next);
|
|
48
|
+
|
|
49
|
+
if (stats.isDirectory() === true) await iterate(filter)(closure)(next);
|
|
50
|
+
else if (stats.isFile() && (await filter(next))) closure(next);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const _Glob = (pattern: string): Promise<string[]> =>
|
|
55
|
+
new Promise((resolve, reject) => {
|
|
56
|
+
glob(pattern, (err, matches) => {
|
|
57
|
+
if (err) reject(err);
|
|
58
|
+
else resolve(matches.map((str) => path.resolve(str)));
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const _Is_file = (pattern: string): boolean =>
|
|
63
|
+
pattern.endsWith(".ts") &&
|
|
64
|
+
!pattern.endsWith(".d.ts") &&
|
|
65
|
+
fs.existsSync(pattern);
|
|
66
|
+
}
|
package/src/utils/StripEnums.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export type StripEnums<T extends Record<string, any>> = {
|
|
2
|
-
[Key in keyof T]: T[Key] extends string | boolean | object | undefined | any[]
|
|
3
|
-
? T[Key]
|
|
4
|
-
: any;
|
|
5
|
-
};
|
|
1
|
+
export type StripEnums<T extends Record<string, any>> = {
|
|
2
|
+
[Key in keyof T]: T[Key] extends string | boolean | object | undefined | any[]
|
|
3
|
+
? T[Key]
|
|
4
|
+
: any;
|
|
5
|
+
};
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { HttpError } from "@nestia/fetcher";
|
|
2
|
-
|
|
3
|
-
import typia from "typia";
|
|
4
|
-
|
|
5
|
-
export namespace NestiaSimulator {
|
|
6
|
-
export interface IProps {
|
|
7
|
-
host: string;
|
|
8
|
-
path: string;
|
|
9
|
-
method: "GET" | "POST" | "PATCH" | "PUT" | "DELETE";
|
|
10
|
-
contentType: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export const assert = (props: IProps) => {
|
|
14
|
-
return {
|
|
15
|
-
param: param(props),
|
|
16
|
-
query: query(props),
|
|
17
|
-
body: body(props),
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
const param =
|
|
21
|
-
(props: IProps) =>
|
|
22
|
-
(name: string) =>
|
|
23
|
-
<T>(task: () => T): void => {
|
|
24
|
-
validate(
|
|
25
|
-
(exp) => `URL parameter "${name}" is not ${exp.expected} type.`,
|
|
26
|
-
)(props)(task);
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const query =
|
|
30
|
-
(props: IProps) =>
|
|
31
|
-
<T>(task: () => T): void =>
|
|
32
|
-
validate(
|
|
33
|
-
() =>
|
|
34
|
-
"Request query parameters are not following the promised type.",
|
|
35
|
-
)(props)(task);
|
|
36
|
-
|
|
37
|
-
const body =
|
|
38
|
-
(props: IProps) =>
|
|
39
|
-
<T>(task: () => T): void =>
|
|
40
|
-
validate(() => "Request body is not following the promised type.")(
|
|
41
|
-
props,
|
|
42
|
-
)(task);
|
|
43
|
-
|
|
44
|
-
const validate =
|
|
45
|
-
(message: (exp: typia.TypeGuardError) => string, path?: string) =>
|
|
46
|
-
(props: IProps) =>
|
|
47
|
-
<T>(task: () => T): void => {
|
|
48
|
-
try {
|
|
49
|
-
task();
|
|
50
|
-
} catch (exp) {
|
|
51
|
-
if (typia.is<typia.TypeGuardError>(exp))
|
|
52
|
-
throw new HttpError(
|
|
53
|
-
props.method,
|
|
54
|
-
props.host + props.path,
|
|
55
|
-
400,
|
|
56
|
-
{
|
|
57
|
-
"Content-Type": props.contentType,
|
|
58
|
-
},
|
|
59
|
-
JSON.stringify({
|
|
60
|
-
method: exp.method,
|
|
61
|
-
path: path ?? exp.path,
|
|
62
|
-
expected: exp.expected,
|
|
63
|
-
value: exp.value,
|
|
64
|
-
message: message(exp),
|
|
65
|
-
}),
|
|
66
|
-
);
|
|
67
|
-
throw exp;
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
import { Metadata } from "typia/lib/schemas/metadata/Metadata";
|
|
3
|
-
import { INestiaConfig } from "../../INestiaConfig";
|
|
4
|
-
import { IRoute } from "../../structures/IRoute";
|
|
5
|
-
import { ImportDictionary } from "../../utils/ImportDictionary";
|
|
6
|
-
export declare namespace SdkDtoGenerator {
|
|
7
|
-
const generate: (checker: ts.TypeChecker) => (config: INestiaConfig) => (routes: IRoute[]) => Promise<void>;
|
|
8
|
-
const decode: (config: INestiaConfig) => (importer: ImportDictionary) => (meta: Metadata, parentEscaped?: boolean) => string;
|
|
9
|
-
}
|