@nestia/migrate 11.2.0 → 12.0.0-dev.20260520.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/NestiaMigrateApplication.d.ts +1 -12
- package/lib/NestiaMigrateApplication.js +22 -24873
- package/lib/NestiaMigrateApplication.js.map +1 -1
- package/lib/analyzers/NestiaMigrateControllerAnalyzer.js.map +1 -1
- package/lib/archivers/NestiaMigrateFileArchiver.js.map +1 -1
- package/lib/bundles/NEST_TEMPLATE.js +5 -5
- package/lib/bundles/NEST_TEMPLATE.js.map +1 -1
- package/lib/bundles/SDK_TEMPLATE.js +4 -4
- package/lib/bundles/SDK_TEMPLATE.js.map +1 -1
- package/lib/executable/NestiaMigrateCommander.js +14 -5
- package/lib/executable/NestiaMigrateCommander.js.map +1 -1
- package/lib/executable/NestiaMigrateInquirer.js.map +1 -1
- package/lib/factories/TypeLiteralFactory.d.ts +1 -1
- package/lib/factories/TypeLiteralFactory.js +49 -13
- package/lib/factories/TypeLiteralFactory.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +177 -24588
- package/lib/index.mjs.map +1 -1
- package/lib/internal/ts.d.ts +32 -0
- package/lib/internal/ts.js +37 -0
- package/lib/internal/ts.js.map +1 -0
- package/lib/programmers/NestiaMigrateApiFileProgrammer.d.ts +1 -1
- package/lib/programmers/NestiaMigrateApiFileProgrammer.js +2 -5
- package/lib/programmers/NestiaMigrateApiFileProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateApiFunctionProgrammer.d.ts +1 -1
- package/lib/programmers/NestiaMigrateApiFunctionProgrammer.js +87 -49
- package/lib/programmers/NestiaMigrateApiFunctionProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateApiNamespaceProgrammer.d.ts +2 -2
- package/lib/programmers/NestiaMigrateApiNamespaceProgrammer.js +80 -82
- package/lib/programmers/NestiaMigrateApiNamespaceProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateApiProgrammer.js +3 -2
- package/lib/programmers/NestiaMigrateApiProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateApiSimulationProgrammer.d.ts +2 -2
- package/lib/programmers/NestiaMigrateApiSimulationProgrammer.js +39 -37
- package/lib/programmers/NestiaMigrateApiSimulationProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateApiStartProgrammer.js +33 -35
- package/lib/programmers/NestiaMigrateApiStartProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateDtoProgrammer.d.ts +1 -1
- package/lib/programmers/NestiaMigrateDtoProgrammer.js +17 -19
- package/lib/programmers/NestiaMigrateDtoProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateE2eFileProgrammer.d.ts +1 -1
- package/lib/programmers/NestiaMigrateE2eFileProgrammer.js +26 -23
- package/lib/programmers/NestiaMigrateE2eFileProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateE2eProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateImportProgrammer.d.ts +1 -1
- package/lib/programmers/NestiaMigrateImportProgrammer.js +11 -14
- package/lib/programmers/NestiaMigrateImportProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateNestControllerProgrammer.d.ts +1 -1
- package/lib/programmers/NestiaMigrateNestControllerProgrammer.js +16 -18
- package/lib/programmers/NestiaMigrateNestControllerProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateNestMethodProgrammer.d.ts +1 -1
- package/lib/programmers/NestiaMigrateNestMethodProgrammer.js +128 -132
- package/lib/programmers/NestiaMigrateNestMethodProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateNestModuleProgrammer.d.ts +1 -1
- package/lib/programmers/NestiaMigrateNestModuleProgrammer.js +10 -9
- package/lib/programmers/NestiaMigrateNestModuleProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateNestProgrammer.js +3 -2
- package/lib/programmers/NestiaMigrateNestProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateSchemaProgrammer.d.ts +2 -2
- package/lib/programmers/NestiaMigrateSchemaProgrammer.js +114 -81
- package/lib/programmers/NestiaMigrateSchemaProgrammer.js.map +1 -1
- package/lib/structures/INestiaMigrateConfig.d.ts +1 -1
- package/lib/utils/FilePrinter.d.ts +2 -2
- package/lib/utils/FilePrinter.js +8 -10
- package/lib/utils/FilePrinter.js.map +1 -1
- package/lib/utils/MapUtil.js.map +1 -1
- package/lib/utils/StringUtil.d.ts +0 -1
- package/lib/utils/StringUtil.js +0 -1
- package/lib/utils/StringUtil.js.map +1 -1
- package/package.json +9 -11
- package/src/NestiaMigrateApplication.ts +29 -30
- package/src/bundles/NEST_TEMPLATE.ts +5 -5
- package/src/bundles/SDK_TEMPLATE.ts +4 -4
- package/src/executable/NestiaMigrateCommander.ts +15 -4
- package/src/executable/bundle.js +237 -4
- package/src/factories/TypeLiteralFactory.ts +22 -16
- package/src/internal/ts.ts +94 -0
- package/src/programmers/NestiaMigrateApiFileProgrammer.ts +7 -4
- package/src/programmers/NestiaMigrateApiFunctionProgrammer.ts +88 -68
- package/src/programmers/NestiaMigrateApiNamespaceProgrammer.ts +122 -111
- package/src/programmers/NestiaMigrateApiProgrammer.ts +6 -5
- package/src/programmers/NestiaMigrateApiSimulationProgrammer.ts +67 -61
- package/src/programmers/NestiaMigrateApiStartProgrammer.ts +46 -45
- package/src/programmers/NestiaMigrateDtoProgrammer.ts +4 -3
- package/src/programmers/NestiaMigrateE2eFileProgrammer.ts +33 -30
- package/src/programmers/NestiaMigrateE2eProgrammer.ts +1 -1
- package/src/programmers/NestiaMigrateImportProgrammer.ts +20 -19
- package/src/programmers/NestiaMigrateNestControllerProgrammer.ts +8 -7
- package/src/programmers/NestiaMigrateNestMethodProgrammer.ts +82 -77
- package/src/programmers/NestiaMigrateNestModuleProgrammer.ts +18 -17
- package/src/programmers/NestiaMigrateNestProgrammer.ts +6 -5
- package/src/programmers/NestiaMigrateSchemaProgrammer.ts +54 -42
- package/src/structures/INestiaMigrateConfig.ts +1 -1
- package/src/utils/FilePrinter.ts +9 -14
- package/src/utils/StringUtil.ts +0 -5
- package/lib/structures/INestiaMigrateDto.d.ts +0 -7
- package/lib/structures/INestiaMigrateDto.js +0 -3
- package/lib/structures/INestiaMigrateDto.js.map +0 -1
- package/lib/structures/INestiaMigrateProgram.d.ts +0 -9
- package/lib/structures/INestiaMigrateProgram.js +0 -3
- package/lib/structures/INestiaMigrateProgram.js.map +0 -1
- package/lib/structures/INestiaMigrateSchema.d.ts +0 -4
- package/lib/structures/INestiaMigrateSchema.js +0 -3
- package/lib/structures/INestiaMigrateSchema.js.map +0 -1
- package/lib/utils/SetupWizard.d.ts +0 -3
- package/lib/utils/SetupWizard.js +0 -18
- package/lib/utils/SetupWizard.js.map +0 -1
- package/lib/utils/openapi-down-convert/RefVisitor.d.ts +0 -52
- package/lib/utils/openapi-down-convert/RefVisitor.js +0 -102
- package/lib/utils/openapi-down-convert/RefVisitor.js.map +0 -1
- package/lib/utils/openapi-down-convert/converter.d.ts +0 -146
- package/lib/utils/openapi-down-convert/converter.js +0 -441
- package/lib/utils/openapi-down-convert/converter.js.map +0 -1
- package/src/structures/INestiaMigrateDto.ts +0 -8
- package/src/structures/INestiaMigrateProgram.ts +0 -11
- package/src/structures/INestiaMigrateSchema.ts +0 -4
- package/src/utils/SetupWizard.ts +0 -12
- package/src/utils/openapi-down-convert/RefVisitor.ts +0 -134
- package/src/utils/openapi-down-convert/converter.ts +0 -536
package/src/executable/bundle.js
CHANGED
|
@@ -8,7 +8,7 @@ const TYPIA = require("js-yaml").load(
|
|
|
8
8
|
fs.readFileSync(`${__dirname}/../../../../pnpm-lock.yaml`, "utf8"),
|
|
9
9
|
).catalogs.samchon;
|
|
10
10
|
|
|
11
|
-
const update = (content) => {
|
|
11
|
+
const update = (content, options = {}) => {
|
|
12
12
|
const parsed = JSON.parse(content);
|
|
13
13
|
for (const record of [
|
|
14
14
|
parsed.dependencies ?? {},
|
|
@@ -18,9 +18,210 @@ const update = (content) => {
|
|
|
18
18
|
if (key.startsWith("@nestia/") || key === "nestia")
|
|
19
19
|
record[key] = `^${version}`;
|
|
20
20
|
else if (TYPIA[key]) record[key] = TYPIA[key].specifier;
|
|
21
|
+
migratePackageJson(parsed);
|
|
22
|
+
if (options.sdkAggregate) {
|
|
23
|
+
parsed.devDependencies ??= {};
|
|
24
|
+
parsed.devDependencies["@nestia/core"] = `^${version}`;
|
|
25
|
+
}
|
|
21
26
|
return JSON.stringify(parsed, null, 2);
|
|
22
27
|
};
|
|
23
28
|
|
|
29
|
+
const migratePackageJson = (parsed) => {
|
|
30
|
+
if (parsed.scripts)
|
|
31
|
+
for (const [key, value] of Object.entries(parsed.scripts))
|
|
32
|
+
if (typeof value === "string")
|
|
33
|
+
parsed.scripts[key] = normalizeScript(value);
|
|
34
|
+
|
|
35
|
+
if (typeof parsed.scripts?.prepare === "string") {
|
|
36
|
+
const prepare = parsed.scripts.prepare
|
|
37
|
+
.split("&&")
|
|
38
|
+
.map((str) => str.trim())
|
|
39
|
+
.filter((str) => str !== "ts-patch install" && str !== "typia patch")
|
|
40
|
+
.join(" && ");
|
|
41
|
+
if (prepare.length === 0) delete parsed.scripts.prepare;
|
|
42
|
+
else parsed.scripts.prepare = prepare;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const devDependencies = parsed.devDependencies;
|
|
46
|
+
if (devDependencies) {
|
|
47
|
+
const usesTypeScript = typeof devDependencies.typescript === "string";
|
|
48
|
+
delete devDependencies["ts-patch"];
|
|
49
|
+
delete devDependencies["typescript-transform-paths"];
|
|
50
|
+
if (usesTypeScript) devDependencies.ttsc ??= "^0.10.2";
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const trimTemplateDependencies = (parsed) => {
|
|
55
|
+
if (parsed.dependencies) {
|
|
56
|
+
delete parsed.dependencies.commander;
|
|
57
|
+
delete parsed.dependencies.inquirer;
|
|
58
|
+
}
|
|
59
|
+
if (parsed.devDependencies) {
|
|
60
|
+
delete parsed.devDependencies["@types/inquirer"];
|
|
61
|
+
delete parsed.devDependencies.commander;
|
|
62
|
+
delete parsed.devDependencies.inquirer;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const normalizeScript = (script) =>
|
|
67
|
+
script.replace(/(^|[^A-Za-z0-9_-])tsc(?=$|[^A-Za-z0-9_-])/g, "$1ttsc");
|
|
68
|
+
|
|
69
|
+
const TYPIA_PLUGIN = `{ "transform": "typia/lib/transform", "enabled": false }`;
|
|
70
|
+
const SDK_PLUGIN = `{ "transform": "@nestia/sdk/lib/transform" }`;
|
|
71
|
+
const CORE_PLUGIN = `{ "transform": "@nestia/core/native/transform.cjs" }`;
|
|
72
|
+
|
|
73
|
+
const ARGUMENT_PARSER = `import { createInterface } from "node:readline/promises";
|
|
74
|
+
|
|
75
|
+
export namespace ArgumentParser {
|
|
76
|
+
export interface Command {
|
|
77
|
+
option: (flags: string, description?: string) => Command;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface Prompt {
|
|
81
|
+
select: (
|
|
82
|
+
name: string,
|
|
83
|
+
) => (
|
|
84
|
+
message: string,
|
|
85
|
+
) => <Choice extends string>(choices: Choice[]) => Promise<Choice>;
|
|
86
|
+
boolean: (name: string) => (message: string) => Promise<boolean>;
|
|
87
|
+
number: (name: string) => (message: string) => Promise<number>;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export const parse = async <T>(
|
|
91
|
+
inquiry: (
|
|
92
|
+
command: Command,
|
|
93
|
+
prompt: Prompt,
|
|
94
|
+
action: (closure: (options: Partial<T>) => Promise<T>) => Promise<T>,
|
|
95
|
+
) => Promise<T>,
|
|
96
|
+
): Promise<T> => {
|
|
97
|
+
const command: Command = {
|
|
98
|
+
option: (_flags: string, _description?: string): Command => command,
|
|
99
|
+
};
|
|
100
|
+
const action = (closure: (options: Partial<T>) => Promise<T>) =>
|
|
101
|
+
closure(parseArguments() as Partial<T>);
|
|
102
|
+
return inquiry(
|
|
103
|
+
command,
|
|
104
|
+
{ select, boolean, number },
|
|
105
|
+
action,
|
|
106
|
+
);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const select =
|
|
110
|
+
(_name: string) =>
|
|
111
|
+
(message: string) =>
|
|
112
|
+
async <Choice extends string>(choices: Choice[]): Promise<Choice> => {
|
|
113
|
+
const answer: string = await ask(\`\${message} (\${choices.join("/")})\`);
|
|
114
|
+
return (choices.find((choice) => choice === answer) ?? choices[0])!;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const boolean = (_name: string) => async (message: string) =>
|
|
118
|
+
/^(true|t|yes|y|1)$/i.test(await ask(\`\${message} [y/N]\`));
|
|
119
|
+
|
|
120
|
+
const number = (_name: string) => async (message: string) =>
|
|
121
|
+
Number(await ask(message));
|
|
122
|
+
|
|
123
|
+
const ask = async (message: string): Promise<string> => {
|
|
124
|
+
const reader = createInterface({
|
|
125
|
+
input: process.stdin,
|
|
126
|
+
output: process.stdout,
|
|
127
|
+
});
|
|
128
|
+
try {
|
|
129
|
+
return (await reader.question(\`\${message}: \`)).trim();
|
|
130
|
+
} finally {
|
|
131
|
+
reader.close();
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const parseArguments = (): Record<string, string | string[] | boolean> => {
|
|
136
|
+
const output: Record<string, string | string[] | boolean> = {};
|
|
137
|
+
const args: string[] = process.argv.slice(2);
|
|
138
|
+
for (let i = 0; i < args.length; ++i) {
|
|
139
|
+
const raw: string = args[i]!;
|
|
140
|
+
if (raw.startsWith("--") === false) continue;
|
|
141
|
+
|
|
142
|
+
const equal: number = raw.indexOf("=");
|
|
143
|
+
const name: string = toCamelCase(
|
|
144
|
+
raw.slice(2, equal === -1 ? undefined : equal),
|
|
145
|
+
);
|
|
146
|
+
if (equal !== -1) {
|
|
147
|
+
assign(output, name, raw.slice(equal + 1));
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const values: string[] = [];
|
|
152
|
+
while (i + 1 < args.length && args[i + 1]!.startsWith("--") === false)
|
|
153
|
+
values.push(args[++i]!);
|
|
154
|
+
assign(
|
|
155
|
+
output,
|
|
156
|
+
name,
|
|
157
|
+
values.length === 0 ? true : values.length === 1 ? values[0]! : values,
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
return output;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const assign = (
|
|
164
|
+
output: Record<string, string | string[] | boolean>,
|
|
165
|
+
name: string,
|
|
166
|
+
value: string | string[] | boolean,
|
|
167
|
+
): void => {
|
|
168
|
+
const current: string | string[] | boolean | undefined = output[name];
|
|
169
|
+
if (current === undefined) output[name] = value;
|
|
170
|
+
else
|
|
171
|
+
output[name] = [
|
|
172
|
+
...(Array.isArray(current) ? current : [String(current)]),
|
|
173
|
+
...(Array.isArray(value) ? value : [String(value)]),
|
|
174
|
+
];
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
const toCamelCase = (str: string): string =>
|
|
178
|
+
str.replace(/-([a-z])/g, (_matched, letter: string) =>
|
|
179
|
+
letter.toUpperCase(),
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
`;
|
|
183
|
+
|
|
184
|
+
const updateTsConfig = (content, options = {}) => {
|
|
185
|
+
content = content.replace(
|
|
186
|
+
/^\s*\{\s*"transform":\s*"typescript-transform-paths"\s*\},\n/gm,
|
|
187
|
+
"",
|
|
188
|
+
);
|
|
189
|
+
if (options.disableTypia)
|
|
190
|
+
content = content.replace(
|
|
191
|
+
/\{\s*"transform":\s*"typia\/lib\/transform"\s*\}/g,
|
|
192
|
+
TYPIA_PLUGIN,
|
|
193
|
+
);
|
|
194
|
+
if (options.useNestiaAggregate)
|
|
195
|
+
content = content.replace(
|
|
196
|
+
/\{\s*"transform":\s*"@nestia\/core\/lib\/transform"\s*\}/g,
|
|
197
|
+
CORE_PLUGIN,
|
|
198
|
+
);
|
|
199
|
+
if (
|
|
200
|
+
options.useNestiaSdk &&
|
|
201
|
+
content.includes(`"@nestia/sdk/lib/transform"`) === false
|
|
202
|
+
)
|
|
203
|
+
content = content.replace(
|
|
204
|
+
/\{\s*"transform":\s*"@nestia\/core\/native\/transform\.cjs"\s*\}/g,
|
|
205
|
+
`${SDK_PLUGIN},\n ${CORE_PLUGIN}`,
|
|
206
|
+
);
|
|
207
|
+
if (
|
|
208
|
+
options.useNestiaAggregate &&
|
|
209
|
+
content.includes(`"@nestia/core/native/transform.cjs"`) === false
|
|
210
|
+
)
|
|
211
|
+
content = content.replace(
|
|
212
|
+
/\{\s*"transform":\s*"typia\/lib\/transform",\s*"enabled":\s*false\s*\},/g,
|
|
213
|
+
options.useNestiaSdk
|
|
214
|
+
? `${TYPIA_PLUGIN},\n ${SDK_PLUGIN},\n ${CORE_PLUGIN},`
|
|
215
|
+
: `${TYPIA_PLUGIN},\n ${CORE_PLUGIN},`,
|
|
216
|
+
);
|
|
217
|
+
if (options.useNestiaSdk)
|
|
218
|
+
content = content.replace(
|
|
219
|
+
/\{\s*"transform":\s*"@nestia\/core\/native\/transform\.cjs"\s*\},\n\s*\{\s*"transform":\s*"@nestia\/sdk\/lib\/transform"\s*\},/g,
|
|
220
|
+
`${SDK_PLUGIN},\n ${CORE_PLUGIN},`,
|
|
221
|
+
);
|
|
222
|
+
return content;
|
|
223
|
+
};
|
|
224
|
+
|
|
24
225
|
const bundle = async ({ mode, repository, exceptions, transform }) => {
|
|
25
226
|
const root = `${__dirname}/../..`;
|
|
26
227
|
const assets = `${root}/assets`;
|
|
@@ -82,10 +283,19 @@ const bundle = async ({ mode, repository, exceptions, transform }) => {
|
|
|
82
283
|
await iterate(collection)(template);
|
|
83
284
|
if (transform)
|
|
84
285
|
for (const [key, value] of Object.entries(collection))
|
|
85
|
-
collection[key] =
|
|
286
|
+
collection[key] = await writeTransformedAsset(
|
|
287
|
+
template,
|
|
288
|
+
key,
|
|
289
|
+
transform(key, value),
|
|
290
|
+
);
|
|
86
291
|
await archive(collection);
|
|
87
292
|
};
|
|
88
293
|
|
|
294
|
+
const writeTransformedAsset = async (template, key, value) => {
|
|
295
|
+
await fs.promises.writeFile(`${template}/${key}`, value, "utf8");
|
|
296
|
+
return value;
|
|
297
|
+
};
|
|
298
|
+
|
|
89
299
|
const main = async () => {
|
|
90
300
|
await bundle({
|
|
91
301
|
mode: "nest",
|
|
@@ -101,7 +311,18 @@ const main = async () => {
|
|
|
101
311
|
"test/features",
|
|
102
312
|
],
|
|
103
313
|
transform: (key, value) => {
|
|
104
|
-
if (key.endsWith("package.json"))
|
|
314
|
+
if (key.endsWith("package.json")) {
|
|
315
|
+
const parsed = JSON.parse(update(value));
|
|
316
|
+
trimTemplateDependencies(parsed);
|
|
317
|
+
return JSON.stringify(parsed, null, 2);
|
|
318
|
+
}
|
|
319
|
+
if (key === "test/helpers/ArgumentParser.ts") return ARGUMENT_PARSER;
|
|
320
|
+
if (key.endsWith("tsconfig.json"))
|
|
321
|
+
return updateTsConfig(value, {
|
|
322
|
+
disableTypia: true,
|
|
323
|
+
useNestiaAggregate: key === "tsconfig.json",
|
|
324
|
+
useNestiaSdk: key === "tsconfig.json",
|
|
325
|
+
});
|
|
105
326
|
return value;
|
|
106
327
|
},
|
|
107
328
|
});
|
|
@@ -118,7 +339,19 @@ const main = async () => {
|
|
|
118
339
|
"test/features",
|
|
119
340
|
],
|
|
120
341
|
transform: (key, value) => {
|
|
121
|
-
if (key.endsWith("package.json"))
|
|
342
|
+
if (key.endsWith("package.json")) {
|
|
343
|
+
const parsed = JSON.parse(
|
|
344
|
+
update(value, { sdkAggregate: key === "package.json" }),
|
|
345
|
+
);
|
|
346
|
+
trimTemplateDependencies(parsed);
|
|
347
|
+
return JSON.stringify(parsed, null, 2);
|
|
348
|
+
}
|
|
349
|
+
if (key === "test/utils/ArgumentParser.ts") return ARGUMENT_PARSER;
|
|
350
|
+
if (key.endsWith("tsconfig.json"))
|
|
351
|
+
return updateTsConfig(value, {
|
|
352
|
+
disableTypia: true,
|
|
353
|
+
useNestiaAggregate: true,
|
|
354
|
+
});
|
|
122
355
|
return value;
|
|
123
356
|
},
|
|
124
357
|
});
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { TypeScriptFactory } from "@nestia/factory";
|
|
2
|
+
import * as typiaUtils from "@typia/utils";
|
|
3
|
+
import ts from "../internal/ts";
|
|
4
|
+
|
|
5
|
+
const { NamingConvention } =
|
|
6
|
+
(typiaUtils as { default?: typeof typiaUtils }).default ?? typiaUtils;
|
|
3
7
|
|
|
4
8
|
export namespace TypeLiteralFactory {
|
|
5
9
|
export const generate = (value: any): ts.TypeNode =>
|
|
@@ -15,40 +19,42 @@ export namespace TypeLiteralFactory {
|
|
|
15
19
|
: Array.isArray(value)
|
|
16
20
|
? generateTuple(value)
|
|
17
21
|
: generateObject(value)
|
|
18
|
-
:
|
|
22
|
+
: TypeScriptFactory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword);
|
|
19
23
|
|
|
20
24
|
const generatestring = (str: string) =>
|
|
21
|
-
|
|
25
|
+
TypeScriptFactory.createLiteralTypeNode(
|
|
26
|
+
TypeScriptFactory.createStringLiteral(str),
|
|
27
|
+
);
|
|
22
28
|
|
|
23
29
|
const generateNumber = (num: number) =>
|
|
24
|
-
|
|
30
|
+
TypeScriptFactory.createLiteralTypeNode(
|
|
25
31
|
num < 0
|
|
26
|
-
?
|
|
32
|
+
? TypeScriptFactory.createPrefixUnaryExpression(
|
|
27
33
|
ts.SyntaxKind.MinusToken,
|
|
28
|
-
|
|
34
|
+
TypeScriptFactory.createNumericLiteral(-num),
|
|
29
35
|
)
|
|
30
|
-
:
|
|
36
|
+
: TypeScriptFactory.createNumericLiteral(num),
|
|
31
37
|
);
|
|
32
38
|
|
|
33
39
|
const generateBoolean = (bool: boolean) =>
|
|
34
|
-
|
|
35
|
-
bool ?
|
|
40
|
+
TypeScriptFactory.createLiteralTypeNode(
|
|
41
|
+
bool ? TypeScriptFactory.createTrue() : TypeScriptFactory.createFalse(),
|
|
36
42
|
);
|
|
37
43
|
|
|
38
44
|
const generateNull = () =>
|
|
39
|
-
|
|
45
|
+
TypeScriptFactory.createLiteralTypeNode(TypeScriptFactory.createNull());
|
|
40
46
|
|
|
41
47
|
const generateTuple = (items: any[]) =>
|
|
42
|
-
|
|
48
|
+
TypeScriptFactory.createTupleTypeNode(items.map(generate));
|
|
43
49
|
|
|
44
50
|
const generateObject = (obj: object) =>
|
|
45
|
-
|
|
51
|
+
TypeScriptFactory.createTypeLiteralNode(
|
|
46
52
|
Object.entries(obj).map(([key, value]) =>
|
|
47
|
-
|
|
53
|
+
TypeScriptFactory.createPropertySignature(
|
|
48
54
|
undefined,
|
|
49
55
|
NamingConvention.variable(key)
|
|
50
|
-
?
|
|
51
|
-
:
|
|
56
|
+
? TypeScriptFactory.createIdentifier(key)
|
|
57
|
+
: TypeScriptFactory.createStringLiteral(key),
|
|
52
58
|
undefined,
|
|
53
59
|
generate(value),
|
|
54
60
|
),
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// Compatibility shim that replaces `import ts from "./ts"`. The values
|
|
2
|
+
// (`ts.factory`, `ts.SyntaxKind`, `ts.NodeFlags`) are routed to @nestia/factory
|
|
3
|
+
// so the migration generators run without a `typescript` dependency, while the
|
|
4
|
+
// type aliases (`ts.Expression`, `ts.ParameterDeclaration`, …) collapse to the
|
|
5
|
+
// shared @nestia/factory `Node` so existing annotations type-check unchanged.
|
|
6
|
+
//
|
|
7
|
+
// Every alias is intentionally `Node`; the migrate package treats AST nodes as
|
|
8
|
+
// opaque tokens it composes and prints — it never inspects them with
|
|
9
|
+
// TypeScript-Compiler-API guards that would need the original brands.
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
NodeFlags,
|
|
13
|
+
SyntaxKind,
|
|
14
|
+
TypeScriptFactory,
|
|
15
|
+
type Node,
|
|
16
|
+
} from "@nestia/factory";
|
|
17
|
+
|
|
18
|
+
interface MutableEmitNode {
|
|
19
|
+
leadingComments?: Array<{
|
|
20
|
+
kind: number;
|
|
21
|
+
text: string;
|
|
22
|
+
hasTrailingNewLine?: boolean;
|
|
23
|
+
}>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface TsValue {
|
|
27
|
+
factory: typeof TypeScriptFactory;
|
|
28
|
+
NodeFlags: typeof NodeFlags;
|
|
29
|
+
SyntaxKind: typeof SyntaxKind;
|
|
30
|
+
addSyntheticLeadingComment(
|
|
31
|
+
node: Node,
|
|
32
|
+
kind: number,
|
|
33
|
+
text: string,
|
|
34
|
+
hasTrailingNewLine?: boolean,
|
|
35
|
+
): Node;
|
|
36
|
+
isUnionTypeNode(node: Node | undefined): node is Node;
|
|
37
|
+
isTypeReferenceNode(node: Node | undefined): node is Node;
|
|
38
|
+
isIdentifier(node: Node | undefined): node is Node;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const ts: TsValue = {
|
|
42
|
+
factory: TypeScriptFactory,
|
|
43
|
+
NodeFlags,
|
|
44
|
+
SyntaxKind,
|
|
45
|
+
// Pushes a synthetic leading comment onto the node's emit metadata, matching
|
|
46
|
+
// the surface of the TypeScript-Compiler-API helper of the same name. The
|
|
47
|
+
// @nestia/factory printer reads `emitNode.leadingComments` and emits them
|
|
48
|
+
// before the node body.
|
|
49
|
+
addSyntheticLeadingComment: (
|
|
50
|
+
node: Node,
|
|
51
|
+
kind: number,
|
|
52
|
+
text: string,
|
|
53
|
+
hasTrailingNewLine?: boolean,
|
|
54
|
+
): Node => {
|
|
55
|
+
const mutable = node as Node & { emitNode?: MutableEmitNode };
|
|
56
|
+
const emitNode = (mutable.emitNode ??= {});
|
|
57
|
+
(emitNode.leadingComments ??= []).push({
|
|
58
|
+
kind,
|
|
59
|
+
text,
|
|
60
|
+
hasTrailingNewLine,
|
|
61
|
+
});
|
|
62
|
+
return node;
|
|
63
|
+
},
|
|
64
|
+
isUnionTypeNode: (node: Node | undefined): node is Node =>
|
|
65
|
+
!!node && node.kind === SyntaxKind.UnionType,
|
|
66
|
+
isTypeReferenceNode: (node: Node | undefined): node is Node =>
|
|
67
|
+
!!node && node.kind === SyntaxKind.TypeReference,
|
|
68
|
+
isIdentifier: (node: Node | undefined): node is Node =>
|
|
69
|
+
!!node && node.kind === SyntaxKind.Identifier,
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
type _Node = Node;
|
|
73
|
+
|
|
74
|
+
declare namespace ts {
|
|
75
|
+
export type Node = _Node;
|
|
76
|
+
export type CallExpression = Node;
|
|
77
|
+
export type ConciseBody = Node;
|
|
78
|
+
export type Decorator = Node;
|
|
79
|
+
export type Expression = Node;
|
|
80
|
+
export type FunctionDeclaration = Node;
|
|
81
|
+
export type Identifier = Node;
|
|
82
|
+
export type KeywordTypeNode = Node;
|
|
83
|
+
export type MethodDeclaration = Node;
|
|
84
|
+
export type ModuleDeclaration = Node;
|
|
85
|
+
export type ParameterDeclaration = Node;
|
|
86
|
+
export type Statement = Node;
|
|
87
|
+
export type TypeAliasDeclaration = Node;
|
|
88
|
+
export type TypeNode = Node;
|
|
89
|
+
export type TypeReferenceNode = Node;
|
|
90
|
+
export type UnionTypeNode = Node;
|
|
91
|
+
export type VariableStatement = Node;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export default ts;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { TypeScriptFactory } from "@nestia/factory";
|
|
1
2
|
import { IHttpMigrateRoute, OpenApi } from "@typia/interface";
|
|
2
|
-
import ts from "
|
|
3
|
+
import ts from "../internal/ts";
|
|
3
4
|
|
|
4
5
|
import { INestiaMigrateConfig } from "../structures/INestiaMigrateConfig";
|
|
5
6
|
import { FilePrinter } from "../utils/FilePrinter";
|
|
@@ -41,11 +42,13 @@ export namespace NestiaMigrateApiFileProgrammer {
|
|
|
41
42
|
(ref) => `../${"../".repeat(props.namespace.length)}structures/${ref}`,
|
|
42
43
|
),
|
|
43
44
|
...[...props.children].map((child) =>
|
|
44
|
-
|
|
45
|
+
TypeScriptFactory.createExportDeclaration(
|
|
45
46
|
undefined,
|
|
46
47
|
false,
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
TypeScriptFactory.createNamespaceExport(
|
|
49
|
+
TypeScriptFactory.createIdentifier(child),
|
|
50
|
+
),
|
|
51
|
+
TypeScriptFactory.createStringLiteral(`./${child}/index`),
|
|
49
52
|
undefined,
|
|
50
53
|
),
|
|
51
54
|
),
|