@nestia/sdk 0.1.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/assets/bundle/HttpError.ts +1 -0
- package/assets/bundle/IConnection.ts +1 -0
- package/assets/bundle/Primitive.ts +1 -0
- package/assets/config/nestia.config.ts +70 -0
- package/lib/INestiaConfig.d.ts +110 -0
- package/lib/INestiaConfig.js +3 -0
- package/lib/INestiaConfig.js.map +1 -0
- package/lib/NestiaSdkApplication.d.ts +11 -0
- package/lib/NestiaSdkApplication.js +156 -0
- package/lib/NestiaSdkApplication.js.map +1 -0
- package/lib/analyses/ControllerAnalyzer.d.ts +6 -0
- package/lib/analyses/ControllerAnalyzer.js +106 -0
- package/lib/analyses/ControllerAnalyzer.js.map +1 -0
- package/lib/analyses/GenericAnalyzer.d.ts +5 -0
- package/lib/analyses/GenericAnalyzer.js +41 -0
- package/lib/analyses/GenericAnalyzer.js.map +1 -0
- package/lib/analyses/ImportAnalyzer.d.ts +13 -0
- package/lib/analyses/ImportAnalyzer.js +86 -0
- package/lib/analyses/ImportAnalyzer.js.map +1 -0
- package/lib/analyses/PathAnalyzer.d.ts +5 -0
- package/lib/analyses/PathAnalyzer.js +51 -0
- package/lib/analyses/PathAnalyzer.js.map +1 -0
- package/lib/analyses/ReflectAnalyzer.d.ts +4 -0
- package/lib/analyses/ReflectAnalyzer.js +231 -0
- package/lib/analyses/ReflectAnalyzer.js.map +1 -0
- package/lib/analyses/SourceFinder.d.ts +4 -0
- package/lib/analyses/SourceFinder.js +71 -0
- package/lib/analyses/SourceFinder.js.map +1 -0
- package/lib/executable/internal/CommandParser.d.ts +3 -0
- package/lib/executable/internal/CommandParser.js +21 -0
- package/lib/executable/internal/CommandParser.js.map +1 -0
- package/lib/executable/internal/NestiaConfigCompilerOptions.d.ts +11 -0
- package/lib/executable/internal/NestiaConfigCompilerOptions.js +18 -0
- package/lib/executable/internal/NestiaConfigCompilerOptions.js.map +1 -0
- package/lib/executable/internal/NestiaSdkCommand.d.ts +4 -0
- package/lib/executable/internal/NestiaSdkCommand.js +128 -0
- package/lib/executable/internal/NestiaSdkCommand.js.map +1 -0
- package/lib/executable/internal/NestiaSdkConfig.d.ts +4 -0
- package/lib/executable/internal/NestiaSdkConfig.js +539 -0
- package/lib/executable/internal/NestiaSdkConfig.js.map +1 -0
- package/lib/executable/internal/nestia.config.getter.d.ts +1 -0
- package/lib/executable/internal/nestia.config.getter.js +24 -0
- package/lib/executable/internal/nestia.config.getter.js.map +1 -0
- package/lib/executable/sdk.d.ts +2 -0
- package/lib/executable/sdk.js +86 -0
- package/lib/executable/sdk.js.map +1 -0
- package/lib/generates/FileGenerator.d.ts +5 -0
- package/lib/generates/FileGenerator.js +138 -0
- package/lib/generates/FileGenerator.js.map +1 -0
- package/lib/generates/FunctionGenerator.d.ts +5 -0
- package/lib/generates/FunctionGenerator.js +204 -0
- package/lib/generates/FunctionGenerator.js.map +1 -0
- package/lib/generates/SdkGenerator.d.ts +7 -0
- package/lib/generates/SdkGenerator.js +45 -0
- package/lib/generates/SdkGenerator.js.map +1 -0
- package/lib/generates/SwaggerGenerator.d.ts +6 -0
- package/lib/generates/SwaggerGenerator.js +244 -0
- package/lib/generates/SwaggerGenerator.js.map +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +28 -0
- package/lib/index.js.map +1 -0
- package/lib/module.d.ts +2 -0
- package/lib/module.js +19 -0
- package/lib/module.js.map +1 -0
- package/lib/structures/IController.d.ts +23 -0
- package/lib/structures/IController.js +3 -0
- package/lib/structures/IController.js.map +1 -0
- package/lib/structures/IRoute.d.ts +24 -0
- package/lib/structures/IRoute.js +3 -0
- package/lib/structures/IRoute.js.map +1 -0
- package/lib/structures/ISwagger.d.ts +48 -0
- package/lib/structures/ISwagger.js +3 -0
- package/lib/structures/ISwagger.js.map +1 -0
- package/lib/structures/ITypeTuple.d.ts +5 -0
- package/lib/structures/ITypeTuple.js +3 -0
- package/lib/structures/ITypeTuple.js.map +1 -0
- package/lib/structures/MethodType.d.ts +4 -0
- package/lib/structures/MethodType.js +14 -0
- package/lib/structures/MethodType.js.map +1 -0
- package/lib/structures/ParamCategory.d.ts +1 -0
- package/lib/structures/ParamCategory.js +3 -0
- package/lib/structures/ParamCategory.js.map +1 -0
- package/lib/structures/TypeEntry.d.ts +9 -0
- package/lib/structures/TypeEntry.js +21 -0
- package/lib/structures/TypeEntry.js.map +1 -0
- package/lib/test/TestBuilder.d.ts +4 -0
- package/lib/test/TestBuilder.js +64 -0
- package/lib/test/TestBuilder.js.map +1 -0
- package/lib/test/index.d.ts +1 -0
- package/lib/test/index.js +61 -0
- package/lib/test/index.js.map +1 -0
- package/lib/test/test.builder.executor.d.ts +1 -0
- package/lib/test/test.builder.executor.js +24 -0
- package/lib/test/test.builder.executor.js.map +1 -0
- package/lib/utils/ArrayUtil.d.ts +5 -0
- package/lib/utils/ArrayUtil.js +39 -0
- package/lib/utils/ArrayUtil.js.map +1 -0
- package/lib/utils/ImportDictionary.d.ts +6 -0
- package/lib/utils/ImportDictionary.js +50 -0
- package/lib/utils/ImportDictionary.js.map +1 -0
- package/lib/utils/MapUtil.d.ts +3 -0
- package/lib/utils/MapUtil.js +16 -0
- package/lib/utils/MapUtil.js.map +1 -0
- package/lib/utils/StripEnums.d.ts +3 -0
- package/lib/utils/StripEnums.js +3 -0
- package/lib/utils/StripEnums.js.map +1 -0
- package/package.json +74 -0
- package/src/INestiaConfig.ts +120 -0
- package/src/NestiaSdkApplication.ts +183 -0
- package/src/analyses/ControllerAnalyzer.ts +203 -0
- package/src/analyses/GenericAnalyzer.ts +53 -0
- package/src/analyses/ImportAnalyzer.ts +143 -0
- package/src/analyses/PathAnalyzer.ts +58 -0
- package/src/analyses/ReflectAnalyzer.ts +279 -0
- package/src/analyses/SourceFinder.ts +59 -0
- package/src/executable/internal/CommandParser.ts +15 -0
- package/src/executable/internal/NestiaConfigCompilerOptions.ts +18 -0
- package/src/executable/internal/NestiaSdkCommand.ts +174 -0
- package/src/executable/internal/NestiaSdkConfig.ts +35 -0
- package/src/executable/internal/nestia.config.getter.ts +12 -0
- package/src/executable/sdk.ts +51 -0
- package/src/generates/FileGenerator.ts +156 -0
- package/src/generates/FunctionGenerator.ts +287 -0
- package/src/generates/SdkGenerator.ts +50 -0
- package/src/generates/SwaggerGenerator.ts +393 -0
- package/src/index.ts +3 -0
- package/src/module.ts +2 -0
- package/src/structures/IController.ts +27 -0
- package/src/structures/IRoute.ts +29 -0
- package/src/structures/ISwagger.ts +55 -0
- package/src/structures/ITypeTuple.ts +6 -0
- package/src/structures/MethodType.ts +11 -0
- package/src/structures/ParamCategory.ts +1 -0
- package/src/structures/TypeEntry.ts +22 -0
- package/src/utils/ArrayUtil.ts +26 -0
- package/src/utils/ImportDictionary.ts +56 -0
- package/src/utils/MapUtil.ts +14 -0
- package/src/utils/StripEnums.ts +10 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { HttpError } from "@nestia/fetcher";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { IConnection } from "@nestia/fetcher";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Primitive } from "@nestia/fetcher";
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { INestiaSdkConfiguration } from "@nestia/sdk";
|
|
2
|
+
|
|
3
|
+
export const NESTIA_CONFIG: INestiaSdkConfiguration = {
|
|
4
|
+
/**
|
|
5
|
+
* List of files or directories containing the NestJS controller classes.
|
|
6
|
+
*/
|
|
7
|
+
input: "src/controllers",
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Output directory that SDK would be placed in.
|
|
11
|
+
*
|
|
12
|
+
* If not configured, you can't build the SDK library.
|
|
13
|
+
*/
|
|
14
|
+
output: "src/api",
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Whether to assert parameter types or not.
|
|
18
|
+
*
|
|
19
|
+
* If you configure this property to be `true`, all of the function parameters would be
|
|
20
|
+
* checked through the [typia](https://github.com/samchon/typia#runtime-type-checkers).
|
|
21
|
+
* This option would make your SDK library slower, but would enahcne the type safety even
|
|
22
|
+
* in the runtime level.
|
|
23
|
+
*
|
|
24
|
+
* @default false
|
|
25
|
+
*/
|
|
26
|
+
// assert: true,
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Whether to optimize JSON string conversion 2x faster or not.
|
|
30
|
+
*
|
|
31
|
+
* If you configure this property to be `true`, the SDK library would utilize the
|
|
32
|
+
* [typia](https://github.com/samchon/typia#fastest-json-string-converter)
|
|
33
|
+
* and the JSON string conversion speed really be 2x faster.
|
|
34
|
+
*
|
|
35
|
+
* @default false
|
|
36
|
+
*/
|
|
37
|
+
// json: true,
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Whether to wrap DTO by primitive type.
|
|
41
|
+
*
|
|
42
|
+
* If you don't configure this property as `false`, all of DTOs in the
|
|
43
|
+
* SDK library would be automatically wrapped by {@link Primitive} type.
|
|
44
|
+
*
|
|
45
|
+
* For refenrece, if a DTO type be capsuled by the {@link Primitive} type,
|
|
46
|
+
* all of methods in the DTO type would be automatically erased. Also, if
|
|
47
|
+
* the DTO has a `toJSON()` method, the DTO type would be automatically
|
|
48
|
+
* converted to return type of the `toJSON()` method.
|
|
49
|
+
*
|
|
50
|
+
* @default true
|
|
51
|
+
*/
|
|
52
|
+
// primitive: false,
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Building `swagger.json` is also possible.
|
|
56
|
+
*
|
|
57
|
+
* If not specified, you can't build the `swagger.json`.
|
|
58
|
+
*/
|
|
59
|
+
swagger: {
|
|
60
|
+
/**
|
|
61
|
+
* Output path of the `swagger.json`.
|
|
62
|
+
*
|
|
63
|
+
* If you've configured only directory, the file name would be the `swagger.json`.
|
|
64
|
+
* Otherwise you've configured the full path with file name and extension, the
|
|
65
|
+
* `swagger.json` file would be renamed to it.
|
|
66
|
+
*/
|
|
67
|
+
output: "dist/swagger.json",
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
export default NESTIA_CONFIG;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import type { StripEnums } from "./utils/StripEnums";
|
|
3
|
+
/**
|
|
4
|
+
* Definition for the `nestia.config.ts` file.
|
|
5
|
+
*
|
|
6
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
7
|
+
*/
|
|
8
|
+
export interface INestiaConfig {
|
|
9
|
+
/**
|
|
10
|
+
* List of files or directories containing the NestJS controller classes.
|
|
11
|
+
*/
|
|
12
|
+
input: string | string[] | INestiaConfig.IInput;
|
|
13
|
+
/**
|
|
14
|
+
* Output directory that SDK would be placed in.
|
|
15
|
+
*
|
|
16
|
+
* If not configured, you can't build the SDK library.
|
|
17
|
+
*/
|
|
18
|
+
output?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Compiler options for the TypeScript.
|
|
21
|
+
*
|
|
22
|
+
* If you've omitted this property or the assigned property cannot fully cover the
|
|
23
|
+
* `tsconfig.json`, the properties from the `tsconfig.json` would be assigned to here.
|
|
24
|
+
* Otherwise, this property has been configured and it's detailed values are different
|
|
25
|
+
* with the `tsconfig.json`, this property values would be used instead.
|
|
26
|
+
*
|
|
27
|
+
* ```typescript
|
|
28
|
+
* import ts from "typescript";
|
|
29
|
+
*
|
|
30
|
+
* const tsconfig: ts.TsConfig;
|
|
31
|
+
* const nestiaConfig: IConfiguration;
|
|
32
|
+
*
|
|
33
|
+
* const compilerOptions: ts.CompilerOptions = {
|
|
34
|
+
* ...tsconfig.compilerOptions,
|
|
35
|
+
* ...(nestiaConfig.compilerOptions || {})
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
compilerOptions?: StripEnums<ts.CompilerOptions>;
|
|
40
|
+
/**
|
|
41
|
+
* Whether to assert parameter types or not.
|
|
42
|
+
*
|
|
43
|
+
* If you configure this property to be `true`, all of the function parameters would be
|
|
44
|
+
* checked through the [typia](https://github.com/samchon/typia#runtime-type-checkers).
|
|
45
|
+
* This option would make your SDK library slower, but would enahcne the type safety even
|
|
46
|
+
* in the runtime level.
|
|
47
|
+
*
|
|
48
|
+
* @default false
|
|
49
|
+
*/
|
|
50
|
+
assert?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Whether to optimize JSON string conversion 2x faster or not.
|
|
53
|
+
*
|
|
54
|
+
* If you configure this property to be `true`, the SDK library would utilize the
|
|
55
|
+
* [typia](https://github.com/samchon/typia#fastest-json-string-converter)
|
|
56
|
+
* and the JSON string conversion speed really be 2x faster.
|
|
57
|
+
*
|
|
58
|
+
* @default false
|
|
59
|
+
*/
|
|
60
|
+
json?: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Whether to wrap DTO by primitive type.
|
|
63
|
+
*
|
|
64
|
+
* If you don't configure this property as `false`, all of DTOs in the
|
|
65
|
+
* SDK library would be automatically wrapped by {@link Primitive} type.
|
|
66
|
+
*
|
|
67
|
+
* For refenrece, if a DTO type be capsuled by the {@link Primitive} type,
|
|
68
|
+
* all of methods in the DTO type would be automatically erased. Also, if
|
|
69
|
+
* the DTO has a `toJSON()` method, the DTO type would be automatically
|
|
70
|
+
* converted to return type of the `toJSON()` method.
|
|
71
|
+
*
|
|
72
|
+
* @default true
|
|
73
|
+
*/
|
|
74
|
+
primitive?: boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Building `swagger.json` is also possible.
|
|
77
|
+
*
|
|
78
|
+
* If not specified, you can't build the `swagger.json`.
|
|
79
|
+
*/
|
|
80
|
+
swagger?: INestiaConfig.ISwagger;
|
|
81
|
+
}
|
|
82
|
+
export declare namespace INestiaConfig {
|
|
83
|
+
/**
|
|
84
|
+
* List of files or directories to include or exclude to specifying the NestJS
|
|
85
|
+
* controllers.
|
|
86
|
+
*/
|
|
87
|
+
interface IInput {
|
|
88
|
+
/**
|
|
89
|
+
* List of files or directories containing the NestJS controller classes.
|
|
90
|
+
*/
|
|
91
|
+
include: string[];
|
|
92
|
+
/**
|
|
93
|
+
* List of files or directories to be excluded.
|
|
94
|
+
*/
|
|
95
|
+
exclude?: string[];
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Building `swagger.json` is also possible.
|
|
99
|
+
*/
|
|
100
|
+
interface ISwagger {
|
|
101
|
+
/**
|
|
102
|
+
* Output path of the `swagger.json`.
|
|
103
|
+
*
|
|
104
|
+
* If you've configured only directory, the file name would be the `swagger.json`.
|
|
105
|
+
* Otherwise you've configured the full path with file name and extension, the
|
|
106
|
+
* `swagger.json` file would be renamed to it.
|
|
107
|
+
*/
|
|
108
|
+
output: string;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"INestiaConfig.js","sourceRoot":"","sources":["../src/INestiaConfig.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { INestiaConfig } from "./INestiaConfig";
|
|
2
|
+
export declare class NestiaSdkApplication {
|
|
3
|
+
private readonly config_;
|
|
4
|
+
private readonly bundle_checker_;
|
|
5
|
+
constructor(config: INestiaConfig);
|
|
6
|
+
sdk(): Promise<void>;
|
|
7
|
+
swagger(): Promise<void>;
|
|
8
|
+
private generate;
|
|
9
|
+
private prepare;
|
|
10
|
+
private is_not_excluded;
|
|
11
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.NestiaSdkApplication = void 0;
|
|
39
|
+
const fs_1 = __importDefault(require("fs"));
|
|
40
|
+
const path_1 = __importDefault(require("path"));
|
|
41
|
+
const runner = __importStar(require("ts-node"));
|
|
42
|
+
const Singleton_1 = require("tstl/thread/Singleton");
|
|
43
|
+
const Pair_1 = require("tstl/utility/Pair");
|
|
44
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
45
|
+
const ControllerAnalyzer_1 = require("./analyses/ControllerAnalyzer");
|
|
46
|
+
const ReflectAnalyzer_1 = require("./analyses/ReflectAnalyzer");
|
|
47
|
+
const SourceFinder_1 = require("./analyses/SourceFinder");
|
|
48
|
+
const NestiaConfigCompilerOptions_1 = require("./executable/internal/NestiaConfigCompilerOptions");
|
|
49
|
+
const SdkGenerator_1 = require("./generates/SdkGenerator");
|
|
50
|
+
const SwaggerGenerator_1 = require("./generates/SwaggerGenerator");
|
|
51
|
+
const ArrayUtil_1 = require("./utils/ArrayUtil");
|
|
52
|
+
class NestiaSdkApplication {
|
|
53
|
+
constructor(config) {
|
|
54
|
+
this.config_ = config;
|
|
55
|
+
this.bundle_checker_ = new Singleton_1.Singleton(() => __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
if (!this.config_.output)
|
|
57
|
+
return () => false;
|
|
58
|
+
const bundles = yield fs_1.default.promises.readdir(SdkGenerator_1.SdkGenerator.BUNDLE_PATH);
|
|
59
|
+
const tuples = yield ArrayUtil_1.ArrayUtil.asyncMap(bundles, (file) => __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
const relative = path_1.default.join(this.config_.output, file);
|
|
61
|
+
const location = path_1.default.join(SdkGenerator_1.SdkGenerator.BUNDLE_PATH, file);
|
|
62
|
+
const stats = yield fs_1.default.promises.stat(location);
|
|
63
|
+
return new Pair_1.Pair(relative, stats.isDirectory());
|
|
64
|
+
}));
|
|
65
|
+
return (file) => {
|
|
66
|
+
for (const it of tuples)
|
|
67
|
+
if (it.second === false && file === it.first)
|
|
68
|
+
return true;
|
|
69
|
+
else if (it.second === true && file.indexOf(it.first) === 0)
|
|
70
|
+
return true;
|
|
71
|
+
return false;
|
|
72
|
+
};
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
75
|
+
sdk() {
|
|
76
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
if (!this.config_.output)
|
|
78
|
+
throw new Error("Error on NestiaApplication.sdk(): output path is not specified.");
|
|
79
|
+
const parent = path_1.default.resolve(this.config_.output + "/..");
|
|
80
|
+
const stats = yield fs_1.default.promises.lstat(parent);
|
|
81
|
+
if (stats.isDirectory() === false)
|
|
82
|
+
throw new Error("Error on NestiaApplication.sdk(): output directory does not exists.");
|
|
83
|
+
yield this.generate((config) => config, SdkGenerator_1.SdkGenerator.generate);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
swagger() {
|
|
87
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
+
if (!this.config_.swagger || !this.config_.swagger.output)
|
|
89
|
+
throw new Error(`Error on NestiaApplication.swagger(): output path of the "swagger.json" is not specified.`);
|
|
90
|
+
const parsed = path_1.default.parse(this.config_.swagger.output);
|
|
91
|
+
const directory = !!parsed.ext
|
|
92
|
+
? path_1.default.resolve(parsed.dir)
|
|
93
|
+
: this.config_.swagger.output;
|
|
94
|
+
const stats = yield fs_1.default.promises.lstat(directory);
|
|
95
|
+
if (stats.isDirectory() === false)
|
|
96
|
+
throw new Error("Error on NestiaApplication.swagger(): output directory does not exists.");
|
|
97
|
+
yield this.generate((config) => config.swagger, SwaggerGenerator_1.SwaggerGenerator.generate);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
generate(config, archiver) {
|
|
101
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
+
// MOUNT TS-NODE
|
|
103
|
+
this.prepare();
|
|
104
|
+
// LOAD CONTROLLER FILES
|
|
105
|
+
const input = this.config_.input instanceof Array
|
|
106
|
+
? { include: this.config_.input }
|
|
107
|
+
: typeof this.config_.input === "string"
|
|
108
|
+
? { include: [this.config_.input] }
|
|
109
|
+
: this.config_.input;
|
|
110
|
+
const fileList = yield ArrayUtil_1.ArrayUtil.asyncFilter(yield SourceFinder_1.SourceFinder.find(input), (file) => this.is_not_excluded(file));
|
|
111
|
+
// ANALYZE REFLECTS
|
|
112
|
+
const unique = new WeakSet();
|
|
113
|
+
const controllerList = [];
|
|
114
|
+
for (const file of fileList)
|
|
115
|
+
controllerList.push(...(yield ReflectAnalyzer_1.ReflectAnalyzer.analyze(unique, file)));
|
|
116
|
+
// ANALYZE TYPESCRIPT CODE
|
|
117
|
+
const program = typescript_1.default.createProgram(controllerList.map((c) => c.file), this.config_.compilerOptions || { noEmit: true });
|
|
118
|
+
const checker = program.getTypeChecker();
|
|
119
|
+
const routeList = [];
|
|
120
|
+
for (const controller of controllerList) {
|
|
121
|
+
const sourceFile = program.getSourceFile(controller.file);
|
|
122
|
+
if (sourceFile === undefined)
|
|
123
|
+
continue;
|
|
124
|
+
routeList.push(...ControllerAnalyzer_1.ControllerAnalyzer.analyze(checker, sourceFile, controller));
|
|
125
|
+
}
|
|
126
|
+
// DO GENERATE
|
|
127
|
+
yield archiver(checker, config(this.config_), routeList);
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
prepare() {
|
|
131
|
+
var _a;
|
|
132
|
+
// CONSTRUCT OPTIONS
|
|
133
|
+
if (!this.config_.compilerOptions)
|
|
134
|
+
this.config_.compilerOptions =
|
|
135
|
+
NestiaConfigCompilerOptions_1.NestiaConfigCompilerOptions.DEFAULT_OPTIONS;
|
|
136
|
+
const absoluted = !!((_a = this.config_.compilerOptions) === null || _a === void 0 ? void 0 : _a.baseUrl);
|
|
137
|
+
// MOUNT TS-NODE
|
|
138
|
+
runner.register({
|
|
139
|
+
emit: false,
|
|
140
|
+
compiler: "ttypescript",
|
|
141
|
+
compilerOptions: this.config_.compilerOptions,
|
|
142
|
+
require: absoluted ? ["tsconfig-paths/register"] : undefined,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
is_not_excluded(file) {
|
|
146
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
147
|
+
if (this.config_.output)
|
|
148
|
+
return (file.indexOf(path_1.default.join(this.config_.output, "functional")) ===
|
|
149
|
+
-1 && (yield this.bundle_checker_.get())(file) === false);
|
|
150
|
+
const content = yield fs_1.default.promises.readFile(file, "utf8");
|
|
151
|
+
return (content.indexOf(" * @nestia Generated by Nestia - https://github.com/samchon/nestia") === -1);
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
exports.NestiaSdkApplication = NestiaSdkApplication;
|
|
156
|
+
//# sourceMappingURL=NestiaSdkApplication.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NestiaSdkApplication.js","sourceRoot":"","sources":["../src/NestiaSdkApplication.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AACxB,gDAAkC;AAClC,qDAAkD;AAClD,4CAAyC;AACzC,4DAA4B;AAG5B,sEAAmE;AACnE,gEAA6D;AAC7D,0DAAuD;AACvD,mGAAgG;AAChG,2DAAwD;AACxD,mEAAgE;AAGhE,iDAA8C;AAE9C,MAAa,oBAAoB;IAM7B,YAAmB,MAAqB;QACpC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,eAAe,GAAG,IAAI,qBAAS,CAAC,GAAS,EAAE;YAC5C,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM;gBAAE,OAAO,GAAG,EAAE,CAAC,KAAK,CAAC;YAE7C,MAAM,OAAO,GAAa,MAAM,YAAE,CAAC,QAAQ,CAAC,OAAO,CAC/C,2BAAY,CAAC,WAAW,CAC3B,CAAC;YACF,MAAM,MAAM,GAA4B,MAAM,qBAAS,CAAC,QAAQ,CAC5D,OAAO,EACP,CAAO,IAAI,EAAE,EAAE;gBACX,MAAM,QAAQ,GAAW,cAAI,CAAC,IAAI,CAC9B,IAAI,CAAC,OAAO,CAAC,MAAO,EACpB,IAAI,CACP,CAAC;gBACF,MAAM,QAAQ,GAAW,cAAI,CAAC,IAAI,CAC9B,2BAAY,CAAC,WAAW,EACxB,IAAI,CACP,CAAC;gBACF,MAAM,KAAK,GAAa,MAAM,YAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,QA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eAAe,0CAAE,OAAO,CAAA,CAAC;QAEnE,gBAAgB;QAChB,MAAM,CAAC,QAAQ,CAAC;YACZ,IAAI,EAAE,KAAK;YACX,QAAQ,EAAE,aAAa;YACvB,eAAe,EAAE,IAAI,CAAC,OAAO,CAAC,eAAe;YAC7C,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,yBAAyB,CAAC,CAAC,CAAC,CAAC,SAAS;SAC/D,CAAC,CAAC;IACP,CAAC;IAEa,eAAe,CAAC,IAAY;;YACtC,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM;gBACnB,OAAO,CACH,IAAI,CAAC,OAAO,CAAC,cAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;oBACtD,CAAC,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,eAAe,CAAC,GAAG,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,KAAK,CAC/D,CAAC;YAEN,MAAM,OAAO,GAAW,MAAM,YAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;YACjE,OAAO,CACH,OAAO,CAAC,OAAO,CACX,oEAAoE,CACvE,KAAK,CAAC,CAAC,CACX,CAAC;QACN,CAAC;KAAA;CACJ;AApKD,oDAoKC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { IController } from "../structures/IController";
|
|
3
|
+
import { IRoute } from "../structures/IRoute";
|
|
4
|
+
export declare namespace ControllerAnalyzer {
|
|
5
|
+
function analyze(checker: ts.TypeChecker, sourceFile: ts.SourceFile, controller: IController): IRoute[];
|
|
6
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ControllerAnalyzer = void 0;
|
|
7
|
+
const HashMap_1 = require("tstl/container/HashMap");
|
|
8
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
9
|
+
const GenericAnalyzer_1 = require("./GenericAnalyzer");
|
|
10
|
+
const ImportAnalyzer_1 = require("./ImportAnalyzer");
|
|
11
|
+
const PathAnalyzer_1 = require("./PathAnalyzer");
|
|
12
|
+
var ControllerAnalyzer;
|
|
13
|
+
(function (ControllerAnalyzer) {
|
|
14
|
+
function analyze(checker, sourceFile, controller) {
|
|
15
|
+
// FIND CONTROLLER CLASS
|
|
16
|
+
const ret = [];
|
|
17
|
+
typescript_1.default.forEachChild(sourceFile, (node) => {
|
|
18
|
+
var _a;
|
|
19
|
+
if (typescript_1.default.isClassDeclaration(node) &&
|
|
20
|
+
((_a = node.name) === null || _a === void 0 ? void 0 : _a.escapedText) === controller.name) {
|
|
21
|
+
// ANALYZE THE CONTROLLER
|
|
22
|
+
ret.push(..._Analyze_controller(checker, controller, node));
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
return ret;
|
|
27
|
+
}
|
|
28
|
+
ControllerAnalyzer.analyze = analyze;
|
|
29
|
+
/* ---------------------------------------------------------
|
|
30
|
+
CLASS
|
|
31
|
+
--------------------------------------------------------- */
|
|
32
|
+
function _Analyze_controller(checker, controller, classNode) {
|
|
33
|
+
const classType = checker.getTypeAtLocation(classNode);
|
|
34
|
+
const genericDict = GenericAnalyzer_1.GenericAnalyzer.analyze(checker, classNode);
|
|
35
|
+
const ret = [];
|
|
36
|
+
for (const property of classType.getProperties()) {
|
|
37
|
+
// GET METHOD DECLARATION
|
|
38
|
+
const declaration = (property.declarations || [])[0];
|
|
39
|
+
if (!declaration || !typescript_1.default.isMethodDeclaration(declaration))
|
|
40
|
+
continue;
|
|
41
|
+
// IDENTIFIER MUST BE
|
|
42
|
+
const identifier = declaration.name;
|
|
43
|
+
if (!typescript_1.default.isIdentifier(identifier))
|
|
44
|
+
continue;
|
|
45
|
+
// ANALYZED WITH THE REFLECTED-FUNCTION
|
|
46
|
+
const runtime = controller.functions.find((f) => f.name === identifier.escapedText);
|
|
47
|
+
if (runtime === undefined)
|
|
48
|
+
continue;
|
|
49
|
+
const routes = _Analyze_function(checker, controller, genericDict, runtime, property);
|
|
50
|
+
ret.push(...routes);
|
|
51
|
+
}
|
|
52
|
+
return ret;
|
|
53
|
+
}
|
|
54
|
+
/* ---------------------------------------------------------
|
|
55
|
+
FUNCTION
|
|
56
|
+
--------------------------------------------------------- */
|
|
57
|
+
function _Analyze_function(checker, controller, genericDict, func, symbol) {
|
|
58
|
+
// PREPARE ASSETS
|
|
59
|
+
const type = checker.getTypeOfSymbolAtLocation(symbol, symbol.valueDeclaration);
|
|
60
|
+
const signature = checker.getSignaturesOfType(type, typescript_1.default.SignatureKind.Call)[0];
|
|
61
|
+
if (signature === undefined)
|
|
62
|
+
throw new Error(`Error on ControllerAnalyzer.analyze(): unable to get the signature from the ${controller.name}.${func.name}().`);
|
|
63
|
+
const importDict = new HashMap_1.HashMap();
|
|
64
|
+
// EXPLORE CHILDREN TYPES
|
|
65
|
+
const parameters = func.parameters.map((param) => _Analyze_parameter(checker, genericDict, importDict, controller, func.name, param, signature.getParameters()[param.index]));
|
|
66
|
+
const output = ImportAnalyzer_1.ImportAnalyzer.analyze(checker, genericDict, importDict, signature.getReturnType());
|
|
67
|
+
const imports = importDict
|
|
68
|
+
.toJSON()
|
|
69
|
+
.map((pair) => [pair.first, pair.second.toJSON()]);
|
|
70
|
+
// CONSTRUCT COMMON DATA
|
|
71
|
+
const common = Object.assign(Object.assign({}, func), { parameters,
|
|
72
|
+
output,
|
|
73
|
+
imports, symbol: `${controller.name}.${func.name}()`, comments: signature.getDocumentationComment(undefined), tags: signature.getJsDocTags() });
|
|
74
|
+
// CONFIGURE PATHS
|
|
75
|
+
const pathList = [];
|
|
76
|
+
for (const controllerPath of controller.paths)
|
|
77
|
+
for (const filePath of func.paths) {
|
|
78
|
+
const path = PathAnalyzer_1.PathAnalyzer.join(controllerPath, filePath);
|
|
79
|
+
pathList.push(PathAnalyzer_1.PathAnalyzer.espace(path, () => "ControllerAnalyzer.analyze()"));
|
|
80
|
+
}
|
|
81
|
+
// RETURNS
|
|
82
|
+
return pathList.map((path) => (Object.assign(Object.assign({}, common), { path })));
|
|
83
|
+
}
|
|
84
|
+
/* ---------------------------------------------------------
|
|
85
|
+
PARAMETER
|
|
86
|
+
--------------------------------------------------------- */
|
|
87
|
+
function _Analyze_parameter(checker, genericDict, importDict, controller, funcName, param, symbol) {
|
|
88
|
+
const type = checker.getTypeOfSymbolAtLocation(symbol, symbol.valueDeclaration);
|
|
89
|
+
const name = symbol.getEscapedName().toString();
|
|
90
|
+
// DO NOT SUPPORT BODY PARAMETER
|
|
91
|
+
if (param.category === "body" && param.field !== undefined) {
|
|
92
|
+
const method = `${controller.name}.${funcName}()`;
|
|
93
|
+
throw new Error(`Error on ${method}: nestia does not support body field specification. ` +
|
|
94
|
+
`Therefore, erase the ${method}#${name} parameter and ` +
|
|
95
|
+
`re-define a new body decorator accepting full structured message.`);
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
name,
|
|
99
|
+
category: param.category,
|
|
100
|
+
field: param.field,
|
|
101
|
+
encrypted: param.encrypted,
|
|
102
|
+
type: ImportAnalyzer_1.ImportAnalyzer.analyze(checker, genericDict, importDict, type),
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
})(ControllerAnalyzer = exports.ControllerAnalyzer || (exports.ControllerAnalyzer = {}));
|
|
106
|
+
//# sourceMappingURL=ControllerAnalyzer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ControllerAnalyzer.js","sourceRoot":"","sources":["../../src/analyses/ControllerAnalyzer.ts"],"names":[],"mappings":";;;;;;AAAA,oDAAiD;AACjD,4DAA4B;AAK5B,uDAAoD;AACpD,qDAAkD;AAClD,iDAA8C;AAE9C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IAAI,GAAW,MAAM,CAAC,cAAc,EAAE,CAAC,QAAQ,EAAE,CAAC;QAExD,gCAAgC;QAChC,IAAI,KAAK,CAAC,QAAQ,KAAK,MAAM,IAAI,KAAK,CAAC,KAAK,KAAK,SAAS,EAAE;YACxD,MAAM,MAAM,GAAW,GAAG,UAAU,CAAC,IAAI,IAAI,QAAQ,IAAI,CAAC;YAC1D,MAAM,IAAI,KAAK,CACX,YAAY,MAAM,sDAAsD;gBACpE,wBAAwB,MAAM,IAAI,IAAI,iBAAiB;gBACvD,mEAAmE,CAC1E,CAAC;SACL;QAED,OAAO;YACH,IAAI;YACJ,QAAQ,EAAE,KAAK,CAAC,QAAQ;YACxB,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,IAAI,EAAE,+BAAc,CAAC,OAAO,CACxB,OAAO,EACP,WAAW,EACX,UAAU,EACV,IAAI,CACP;SACJ,CAAC;IACN,CAAC;AACL,CAAC,EAhMgB,kBAAkB,GAAlB,0BAAkB,KAAlB,0BAAkB,QAgMlC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.GenericAnalyzer = void 0;
|
|
7
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
8
|
+
var GenericAnalyzer;
|
|
9
|
+
(function (GenericAnalyzer) {
|
|
10
|
+
function analyze(checker, classNode) {
|
|
11
|
+
const dict = new WeakMap();
|
|
12
|
+
explore(checker, dict, classNode);
|
|
13
|
+
return dict;
|
|
14
|
+
}
|
|
15
|
+
GenericAnalyzer.analyze = analyze;
|
|
16
|
+
function explore(checker, dict, classNode) {
|
|
17
|
+
if (classNode.heritageClauses === undefined)
|
|
18
|
+
return;
|
|
19
|
+
for (const heritage of classNode.heritageClauses)
|
|
20
|
+
for (const hType of heritage.types) {
|
|
21
|
+
// MUST BE CLASS
|
|
22
|
+
const expression = checker.getTypeAtLocation(hType.expression);
|
|
23
|
+
const superNode = expression.symbol.getDeclarations()[0];
|
|
24
|
+
if (!typescript_1.default.isClassDeclaration(superNode))
|
|
25
|
+
continue;
|
|
26
|
+
// SPECIFY GENERICS
|
|
27
|
+
const usages = hType.typeArguments || [];
|
|
28
|
+
const parameters = superNode.typeParameters || [];
|
|
29
|
+
parameters.forEach((param, index) => {
|
|
30
|
+
const paramType = checker.getTypeAtLocation(param);
|
|
31
|
+
const usageType = usages[index] !== undefined
|
|
32
|
+
? checker.getTypeAtLocation(usages[index])
|
|
33
|
+
: checker.getTypeAtLocation(param.default);
|
|
34
|
+
dict.set(paramType, usageType);
|
|
35
|
+
});
|
|
36
|
+
// RECUSRIVE EXPLORATION
|
|
37
|
+
explore(checker, dict, superNode);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
})(GenericAnalyzer = exports.GenericAnalyzer || (exports.GenericAnalyzer = {}));
|
|
41
|
+
//# sourceMappingURL=GenericAnalyzer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GenericAnalyzer.js","sourceRoot":"","sources":["../../src/analyses/GenericAnalyzer.ts"],"names":[],"mappings":";;;;;;AAAA,4DAA4B;AAE5B,IAAiB,eAAe,CAkD/B;AAlDD,WAAiB,eAAe;IAG5B,SAAgB,OAAO,CACnB,OAAuB,EACvB,SAA8B;QAE9B,MAAM,IAAI,GAAe,IAAI,OAAO,EAAE,CAAC;QACvC,OAAO,CAAC,OAAO,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC;QAClC,OAAO,IAAI,CAAC;IAChB,CAAC;IAPe,uBAAO,UAOtB,CAAA;IAED,SAAS,OAAO,CACZ,OAAuB,EACvB,IAAgB,EAChB,SAA8B;QAE9B,IAAI,SAAS,CAAC,eAAe,KAAK,SAAS;YAAE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
|
4
|
+
import { ITypeTuple } from "../structures/ITypeTuple";
|
|
5
|
+
import { GenericAnalyzer } from "./GenericAnalyzer";
|
|
6
|
+
export declare namespace ImportAnalyzer {
|
|
7
|
+
interface IOutput {
|
|
8
|
+
features: [string, string[]][];
|
|
9
|
+
alias: string;
|
|
10
|
+
}
|
|
11
|
+
type Dictionary = HashMap<string, HashSet<string>>;
|
|
12
|
+
function analyze(checker: ts.TypeChecker, genericDict: GenericAnalyzer.Dictionary, importDict: Dictionary, type: ts.Type): ITypeTuple;
|
|
13
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ImportAnalyzer = void 0;
|
|
7
|
+
const HashSet_1 = require("tstl/container/HashSet");
|
|
8
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
9
|
+
var ImportAnalyzer;
|
|
10
|
+
(function (ImportAnalyzer) {
|
|
11
|
+
function analyze(checker, genericDict, importDict, type) {
|
|
12
|
+
type = get_type(checker, type);
|
|
13
|
+
return {
|
|
14
|
+
type,
|
|
15
|
+
name: explore_escaped_name(checker, genericDict, importDict, type),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
ImportAnalyzer.analyze = analyze;
|
|
19
|
+
/* ---------------------------------------------------------
|
|
20
|
+
TYPE
|
|
21
|
+
--------------------------------------------------------- */
|
|
22
|
+
function get_type(checker, type) {
|
|
23
|
+
const symbol = type.getSymbol();
|
|
24
|
+
return symbol && get_name(symbol) === "Promise"
|
|
25
|
+
? escape_promise(checker, type)
|
|
26
|
+
: type;
|
|
27
|
+
}
|
|
28
|
+
function escape_promise(checker, type) {
|
|
29
|
+
const generic = checker.getTypeArguments(type);
|
|
30
|
+
if (generic.length !== 1)
|
|
31
|
+
throw new Error("Error on ImportAnalyzer.analyze(): invalid promise type.");
|
|
32
|
+
return generic[0];
|
|
33
|
+
}
|
|
34
|
+
function get_name(symbol) {
|
|
35
|
+
return explore_name(symbol.escapedName.toString(), symbol.getDeclarations()[0].parent);
|
|
36
|
+
}
|
|
37
|
+
/* ---------------------------------------------------------
|
|
38
|
+
ESCAPED TEXT WITH IMPORT STATEMENTS
|
|
39
|
+
--------------------------------------------------------- */
|
|
40
|
+
function explore_escaped_name(checker, genericDict, importDict, type) {
|
|
41
|
+
//----
|
|
42
|
+
// CONDITIONAL BRANCHES
|
|
43
|
+
//----
|
|
44
|
+
// DECOMPOSE GENERIC ARGUMENT
|
|
45
|
+
while (genericDict.has(type) === true)
|
|
46
|
+
type = genericDict.get(type);
|
|
47
|
+
// PRIMITIVE
|
|
48
|
+
const symbol = type.aliasSymbol || type.getSymbol();
|
|
49
|
+
if (symbol === undefined)
|
|
50
|
+
return checker.typeToString(type, undefined, undefined);
|
|
51
|
+
// UNION OR INTERSECT
|
|
52
|
+
else if (type.aliasSymbol === undefined &&
|
|
53
|
+
type.isUnionOrIntersection()) {
|
|
54
|
+
const joiner = type.isIntersection() ? " & " : " | ";
|
|
55
|
+
return type.types
|
|
56
|
+
.map((child) => explore_escaped_name(checker, genericDict, importDict, child))
|
|
57
|
+
.join(joiner);
|
|
58
|
+
}
|
|
59
|
+
//----
|
|
60
|
+
// SPECIALIZATION
|
|
61
|
+
//----
|
|
62
|
+
const name = get_name(symbol);
|
|
63
|
+
const sourceFile = symbol.declarations[0].getSourceFile();
|
|
64
|
+
if (sourceFile.fileName.indexOf("typescript/lib") === -1) {
|
|
65
|
+
const set = importDict.take(sourceFile.fileName, () => new HashSet_1.HashSet());
|
|
66
|
+
set.insert(name.split(".")[0]);
|
|
67
|
+
}
|
|
68
|
+
// CHECK GENERIC
|
|
69
|
+
const generic = type.aliasSymbol
|
|
70
|
+
? type.aliasTypeArguments || []
|
|
71
|
+
: checker.getTypeArguments(type);
|
|
72
|
+
return generic.length
|
|
73
|
+
? name === "Promise"
|
|
74
|
+
? explore_escaped_name(checker, genericDict, importDict, generic[0])
|
|
75
|
+
: `${name}<${generic
|
|
76
|
+
.map((child) => explore_escaped_name(checker, genericDict, importDict, child))
|
|
77
|
+
.join(", ")}>`
|
|
78
|
+
: name;
|
|
79
|
+
}
|
|
80
|
+
function explore_name(name, decl) {
|
|
81
|
+
return typescript_1.default.isModuleBlock(decl)
|
|
82
|
+
? explore_name(`${decl.parent.name.getText()}.${name}`, decl.parent.parent)
|
|
83
|
+
: name;
|
|
84
|
+
}
|
|
85
|
+
})(ImportAnalyzer = exports.ImportAnalyzer || (exports.ImportAnalyzer = {}));
|
|
86
|
+
//# sourceMappingURL=ImportAnalyzer.js.map
|