@nestia/sdk 2.6.3 → 2.6.4-dev.20240401

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.
@@ -1,147 +1,147 @@
1
- import path from "path";
2
- import { HashMap, HashSet, Pair } from "tstl";
3
- import ts from "typescript";
4
-
5
- import { FilePrinter } from "./FilePrinter";
6
-
7
- export class ImportDictionary {
8
- private readonly components_: HashMap<Pair<string, boolean>, IComposition> =
9
- new HashMap();
10
-
11
- public constructor(public readonly file: string) {}
12
-
13
- public empty(): boolean {
14
- return this.components_.empty();
15
- }
16
-
17
- public external(props: ImportDictionary.IExternalProps): string {
18
- const composition: IComposition = this.components_.take(
19
- new Pair(props.library, props.type),
20
- () => ({
21
- location: `node_modules/${props.library}`,
22
- elements: new HashSet(),
23
- default: false,
24
- type: props.type,
25
- }),
26
- );
27
- if (props.instance === null) composition.default = true;
28
- else composition.elements.insert(props.instance);
29
- return props.instance ?? props.library;
30
- }
31
-
32
- public internal(props: ImportDictionary.IInternalProps): string {
33
- const file: string = (() => {
34
- if (props.file.substring(props.file.length - 5) === ".d.ts")
35
- return props.file.substring(0, props.file.length - 5);
36
- else if (props.file.substring(props.file.length - 3) === ".ts")
37
- return props.file.substring(0, props.file.length - 3);
38
- return props.file;
39
- })();
40
- const composition: IComposition = this.components_.take(
41
- new Pair(file, props.type),
42
- () => ({
43
- location: file,
44
- elements: new HashSet(),
45
- default: false,
46
- type: props.type,
47
- }),
48
- );
49
- if (props.instance === null) {
50
- composition.default = true;
51
- if (props.name) composition.name = props.name;
52
- } else composition.elements.insert(props.instance);
53
- return props.instance ?? file;
54
- }
55
-
56
- public toStatements(outDir: string): ts.Statement[] {
57
- const external: ts.ImportDeclaration[] = [];
58
- const internal: ts.ImportDeclaration[] = [];
59
-
60
- const locator = (str: string) => {
61
- const location: string = path.relative(outDir, str).split("\\").join("/");
62
- const index: number = location.lastIndexOf(NODE_MODULES);
63
- return index === -1
64
- ? location.startsWith("..")
65
- ? location
66
- : `./${location}`
67
- : location.substring(index + NODE_MODULES.length);
68
- };
69
- const enroll =
70
- (filter: (str: string) => boolean) =>
71
- (container: ts.ImportDeclaration[]) => {
72
- const compositions: IComposition[] = this.components_
73
- .toJSON()
74
- .filter((c) => filter(c.second.location))
75
- .map((e) => ({
76
- ...e.second,
77
- location: locator(e.second.location),
78
- }))
79
- .sort((a, b) => a.location.localeCompare(b.location));
80
- for (const c of compositions) {
81
- const brackets: string[] = [];
82
- if (c.default) brackets.push(c.name ?? c.location);
83
- if (c.elements.empty() === false)
84
- brackets.push(
85
- `{ ${c.elements
86
- .toJSON()
87
- .sort((a, b) => a.localeCompare(b))
88
- .join(", ")} }`,
89
- );
90
- container.push(
91
- ts.factory.createImportDeclaration(
92
- undefined,
93
- ts.factory.createImportClause(
94
- c.type,
95
- c.default
96
- ? ts.factory.createIdentifier(c.name ?? c.location)
97
- : undefined,
98
- c.elements.empty() === false
99
- ? ts.factory.createNamedImports(
100
- [...c.elements].map((elem) =>
101
- ts.factory.createImportSpecifier(
102
- false,
103
- undefined,
104
- ts.factory.createIdentifier(elem),
105
- ),
106
- ),
107
- )
108
- : undefined,
109
- ),
110
- ts.factory.createStringLiteral(c.location),
111
- ),
112
- );
113
- }
114
- };
115
-
116
- enroll((str) => str.indexOf(NODE_MODULES) !== -1)(external);
117
- enroll((str) => str.indexOf(NODE_MODULES) === -1)(internal);
118
- return [
119
- ...external,
120
- ...(external.length && internal.length ? [FilePrinter.enter()] : []),
121
- ...internal,
122
- ];
123
- }
124
- }
125
- export namespace ImportDictionary {
126
- export interface IExternalProps {
127
- type: boolean;
128
- library: string;
129
- instance: string | null;
130
- }
131
- export interface IInternalProps {
132
- type: boolean;
133
- file: string;
134
- instance: string | null;
135
- name?: string | null;
136
- }
137
- }
138
-
139
- interface IComposition {
140
- location: string;
141
- type: boolean;
142
- default: boolean;
143
- name?: string;
144
- elements: HashSet<string>;
145
- }
146
-
147
- const NODE_MODULES = "node_modules/";
1
+ import path from "path";
2
+ import { HashMap, HashSet, Pair } from "tstl";
3
+ import ts from "typescript";
4
+
5
+ import { FilePrinter } from "./FilePrinter";
6
+
7
+ export class ImportDictionary {
8
+ private readonly components_: HashMap<Pair<string, boolean>, IComposition> =
9
+ new HashMap();
10
+
11
+ public constructor(public readonly file: string) {}
12
+
13
+ public empty(): boolean {
14
+ return this.components_.empty();
15
+ }
16
+
17
+ public external(props: ImportDictionary.IExternalProps): string {
18
+ const composition: IComposition = this.components_.take(
19
+ new Pair(props.library, props.type),
20
+ () => ({
21
+ location: `node_modules/${props.library}`,
22
+ elements: new HashSet(),
23
+ default: false,
24
+ type: props.type,
25
+ }),
26
+ );
27
+ if (props.instance === null) composition.default = true;
28
+ else composition.elements.insert(props.instance);
29
+ return props.instance ?? props.library;
30
+ }
31
+
32
+ public internal(props: ImportDictionary.IInternalProps): string {
33
+ const file: string = (() => {
34
+ if (props.file.substring(props.file.length - 5) === ".d.ts")
35
+ return props.file.substring(0, props.file.length - 5);
36
+ else if (props.file.substring(props.file.length - 3) === ".ts")
37
+ return props.file.substring(0, props.file.length - 3);
38
+ return props.file;
39
+ })();
40
+ const composition: IComposition = this.components_.take(
41
+ new Pair(file, props.type),
42
+ () => ({
43
+ location: file,
44
+ elements: new HashSet(),
45
+ default: false,
46
+ type: props.type,
47
+ }),
48
+ );
49
+ if (props.instance === null) {
50
+ composition.default = true;
51
+ if (props.name) composition.name = props.name;
52
+ } else composition.elements.insert(props.instance);
53
+ return props.instance ?? file;
54
+ }
55
+
56
+ public toStatements(outDir: string): ts.Statement[] {
57
+ const external: ts.ImportDeclaration[] = [];
58
+ const internal: ts.ImportDeclaration[] = [];
59
+
60
+ const locator = (str: string) => {
61
+ const location: string = path.relative(outDir, str).split("\\").join("/");
62
+ const index: number = location.lastIndexOf(NODE_MODULES);
63
+ return index === -1
64
+ ? location.startsWith("..")
65
+ ? location
66
+ : `./${location}`
67
+ : location.substring(index + NODE_MODULES.length);
68
+ };
69
+ const enroll =
70
+ (filter: (str: string) => boolean) =>
71
+ (container: ts.ImportDeclaration[]) => {
72
+ const compositions: IComposition[] = this.components_
73
+ .toJSON()
74
+ .filter((c) => filter(c.second.location))
75
+ .map((e) => ({
76
+ ...e.second,
77
+ location: locator(e.second.location),
78
+ }))
79
+ .sort((a, b) => a.location.localeCompare(b.location));
80
+ for (const c of compositions) {
81
+ const brackets: string[] = [];
82
+ if (c.default) brackets.push(c.name ?? c.location);
83
+ if (c.elements.empty() === false)
84
+ brackets.push(
85
+ `{ ${c.elements
86
+ .toJSON()
87
+ .sort((a, b) => a.localeCompare(b))
88
+ .join(", ")} }`,
89
+ );
90
+ container.push(
91
+ ts.factory.createImportDeclaration(
92
+ undefined,
93
+ ts.factory.createImportClause(
94
+ c.type,
95
+ c.default
96
+ ? ts.factory.createIdentifier(c.name ?? c.location)
97
+ : undefined,
98
+ c.elements.empty() === false
99
+ ? ts.factory.createNamedImports(
100
+ [...c.elements].map((elem) =>
101
+ ts.factory.createImportSpecifier(
102
+ false,
103
+ undefined,
104
+ ts.factory.createIdentifier(elem),
105
+ ),
106
+ ),
107
+ )
108
+ : undefined,
109
+ ),
110
+ ts.factory.createStringLiteral(c.location),
111
+ ),
112
+ );
113
+ }
114
+ };
115
+
116
+ enroll((str) => str.indexOf(NODE_MODULES) !== -1)(external);
117
+ enroll((str) => str.indexOf(NODE_MODULES) === -1)(internal);
118
+ return [
119
+ ...external,
120
+ ...(external.length && internal.length ? [FilePrinter.enter()] : []),
121
+ ...internal,
122
+ ];
123
+ }
124
+ }
125
+ export namespace ImportDictionary {
126
+ export interface IExternalProps {
127
+ type: boolean;
128
+ library: string;
129
+ instance: string | null;
130
+ }
131
+ export interface IInternalProps {
132
+ type: boolean;
133
+ file: string;
134
+ instance: string | null;
135
+ name?: string | null;
136
+ }
137
+ }
138
+
139
+ interface IComposition {
140
+ location: string;
141
+ type: boolean;
142
+ default: boolean;
143
+ name?: string;
144
+ elements: HashSet<string>;
145
+ }
146
+
147
+ const NODE_MODULES = "node_modules/";
@@ -1,6 +1,8 @@
1
1
  import { ISwaggerComponents } from "./ISwaggerComponents";
2
2
  import { ISwaggerInfo } from "./ISwaggerInfo";
3
3
  import { ISwaggerRoute } from "./ISwaggerRoute";
4
+ import { ISwaggerServer } from "./ISwaggerServer";
5
+ import { ISwaggerTag } from "./ISwaggerTag";
4
6
 
5
7
  /**
6
8
  * Swagger Document.
@@ -22,7 +24,7 @@ export interface ISwagger {
22
24
  /**
23
25
  * List of servers that provide the API.
24
26
  */
25
- servers: ISwagger.IServer[];
27
+ servers: ISwaggerServer[];
26
28
 
27
29
  /**
28
30
  * Information about the API.
@@ -46,6 +48,11 @@ export interface ISwagger {
46
48
  */
47
49
  components: ISwaggerComponents;
48
50
 
51
+ /**
52
+ * List of tags.
53
+ */
54
+ tags: ISwaggerTag[];
55
+
49
56
  // /**
50
57
  // * A declaration of which security mechanisms can be used across the API.
51
58
  // *
@@ -57,35 +64,3 @@ export interface ISwagger {
57
64
  // */
58
65
  // security?: Record<string, string[]>[];
59
66
  }
60
- export namespace ISwagger {
61
- /**
62
- * Remote server definition.
63
- */
64
- export interface IServer {
65
- /**
66
- * A URL to the target host.
67
- *
68
- * @format uri
69
- */
70
- url: string;
71
-
72
- /**
73
- * An optional string describing the target server.
74
- */
75
- description?: string;
76
- }
77
-
78
- export interface IExternalDocs {
79
- /**
80
- * The URL for target documentation.
81
- *
82
- * @format uri
83
- */
84
- url: string;
85
-
86
- /**
87
- * A short description of the target documentation.
88
- */
89
- description?: string;
90
- }
91
- }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Remote server definition.
3
+ */
4
+ export interface ISwaggerServer {
5
+ /**
6
+ * A URL to the target host.
7
+ *
8
+ * @format uri
9
+ */
10
+ url: string;
11
+
12
+ /**
13
+ * An optional string describing the target server.
14
+ */
15
+ description?: string;
16
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Tag name and description.
3
+ *
4
+ * @author Jeongho Nam - https://github.com/samchon
5
+ */
6
+ export interface ISwaggerTag {
7
+ name: string;
8
+ description?: string;
9
+ }
@@ -1,22 +1,22 @@
1
- import { hash } from "tstl";
2
- import ts from "typescript";
3
-
4
- export class TypeEntry {
5
- public constructor(
6
- public readonly type: ts.Type,
7
- public readonly nullable: boolean,
8
- public readonly required: boolean,
9
- ) {}
10
-
11
- public equals(obj: TypeEntry): boolean {
12
- return (
13
- this.type === obj.type &&
14
- this.nullable === obj.nullable &&
15
- this.required === obj.required
16
- );
17
- }
18
-
19
- public hashCode(): number {
20
- return hash(this.type, this.nullable, this.required);
21
- }
22
- }
1
+ import { hash } from "tstl";
2
+ import ts from "typescript";
3
+
4
+ export class TypeEntry {
5
+ public constructor(
6
+ public readonly type: ts.Type,
7
+ public readonly nullable: boolean,
8
+ public readonly required: boolean,
9
+ ) {}
10
+
11
+ public equals(obj: TypeEntry): boolean {
12
+ return (
13
+ this.type === obj.type &&
14
+ this.nullable === obj.nullable &&
15
+ this.required === obj.required
16
+ );
17
+ }
18
+
19
+ public hashCode(): number {
20
+ return hash(this.type, this.nullable, this.required);
21
+ }
22
+ }