@nestia/migrate 13.0.4 → 14.0.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/README.md +1 -1
- package/lib/analyzers/NestiaMigrateControllerAnalyzer.d.ts +13 -0
- package/lib/analyzers/NestiaMigrateControllerAnalyzer.js +32 -2
- package/lib/analyzers/NestiaMigrateControllerAnalyzer.js.map +1 -1
- package/lib/analyzers/NestiaMigrateControllerAnalyzer.mjs +14 -2
- package/lib/bundles/NEST_TEMPLATE.js +1 -1
- package/lib/bundles/NEST_TEMPLATE.js.map +1 -1
- package/lib/bundles/NEST_TEMPLATE.mjs +1 -1
- package/lib/bundles/SDK_TEMPLATE.js +1 -1
- package/lib/bundles/SDK_TEMPLATE.js.map +1 -1
- package/lib/bundles/SDK_TEMPLATE.mjs +1 -1
- package/lib/executable/NestiaMigrateCommander.js +5 -1
- package/lib/executable/NestiaMigrateCommander.js.map +1 -1
- package/lib/executable/NestiaMigrateCommander.mjs +1 -1
- package/lib/executable/NestiaMigrateInquirer.js +7 -25
- package/lib/executable/NestiaMigrateInquirer.js.map +1 -1
- package/lib/executable/NestiaMigrateInquirer.mjs +5 -7
- package/lib/programmers/NestiaMigrateApiFunctionProgrammer.js +7 -5
- package/lib/programmers/NestiaMigrateApiFunctionProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateApiFunctionProgrammer.mjs +4 -2
- package/lib/programmers/NestiaMigrateApiNamespaceProgrammer.js +31 -13
- package/lib/programmers/NestiaMigrateApiNamespaceProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateApiNamespaceProgrammer.mjs +17 -8
- package/lib/programmers/NestiaMigrateApiSimulationProgrammer.js +24 -22
- package/lib/programmers/NestiaMigrateApiSimulationProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateApiSimulationProgrammer.mjs +13 -20
- package/lib/programmers/NestiaMigrateE2eFileProgrammer.js +20 -5
- package/lib/programmers/NestiaMigrateE2eFileProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateE2eFileProgrammer.mjs +6 -2
- package/lib/programmers/NestiaMigrateNestMethodProgrammer.js +69 -13
- package/lib/programmers/NestiaMigrateNestMethodProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateNestMethodProgrammer.mjs +46 -9
- package/lib/programmers/NestiaMigrateSchemaProgrammer.js +25 -4
- package/lib/programmers/NestiaMigrateSchemaProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateSchemaProgrammer.mjs +15 -4
- package/lib/utils/PathTemplate.d.ts +19 -0
- package/lib/utils/PathTemplate.js +42 -0
- package/lib/utils/PathTemplate.js.map +1 -0
- package/lib/utils/PathTemplate.mjs +34 -0
- package/lib/utils/PathTemplate.mjs.map +1 -0
- package/lib/utils/RequestBody.d.ts +9 -0
- package/lib/utils/RequestBody.js +16 -0
- package/lib/utils/RequestBody.js.map +1 -0
- package/lib/utils/RequestBody.mjs +9 -0
- package/lib/utils/RequestBody.mjs.map +1 -0
- package/lib/utils/SuccessStatus.d.ts +14 -0
- package/lib/utils/SuccessStatus.js +28 -0
- package/lib/utils/SuccessStatus.js.map +1 -0
- package/lib/utils/SuccessStatus.mjs +14 -0
- package/lib/utils/SuccessStatus.mjs.map +1 -0
- package/package.json +4 -4
- package/src/analyzers/NestiaMigrateControllerAnalyzer.ts +39 -2
- package/src/bundles/NEST_TEMPLATE.ts +1 -1
- package/src/bundles/SDK_TEMPLATE.ts +1 -1
- package/src/executable/NestiaMigrateCommander.ts +7 -1
- package/src/executable/NestiaMigrateInquirer.ts +12 -26
- package/src/programmers/NestiaMigrateApiFunctionProgrammer.ts +10 -4
- package/src/programmers/NestiaMigrateApiNamespaceProgrammer.ts +41 -20
- package/src/programmers/NestiaMigrateApiSimulationProgrammer.ts +23 -73
- package/src/programmers/NestiaMigrateE2eFileProgrammer.ts +41 -8
- package/src/programmers/NestiaMigrateNestMethodProgrammer.ts +88 -29
- package/src/programmers/NestiaMigrateSchemaProgrammer.ts +28 -10
- package/src/utils/PathTemplate.ts +39 -0
- package/src/utils/RequestBody.ts +14 -0
- package/src/utils/SuccessStatus.ts +29 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { IHttpMigrateRoute } from "@typia/interface";
|
|
2
|
+
|
|
3
|
+
export namespace PathTemplate {
|
|
4
|
+
export type ISegment =
|
|
5
|
+
| { type: "literal"; value: string }
|
|
6
|
+
| { type: "param"; parameter: IHttpMigrateRoute.IParameter };
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The route's path as literal text and path parameters, in order, read from
|
|
10
|
+
* the document's own template (`/files/{id}.json`), whose braces delimit each
|
|
11
|
+
* parameter name. The emended path (`/files/:id.json`) cannot be split back:
|
|
12
|
+
* its `:id.json` could name `id` or `id.json`, and a name such as `item-id`
|
|
13
|
+
* would read as `item` followed by `-id`. It always starts with `/`, as the
|
|
14
|
+
* emended path does.
|
|
15
|
+
*/
|
|
16
|
+
export const segments = (route: IHttpMigrateRoute): ISegment[] => {
|
|
17
|
+
const path: string = route.path.startsWith("/")
|
|
18
|
+
? route.path
|
|
19
|
+
: `/${route.path}`;
|
|
20
|
+
const output: ISegment[] = [];
|
|
21
|
+
const literal = (value: string): void => {
|
|
22
|
+
if (value.length === 0) return;
|
|
23
|
+
const last: ISegment | undefined = output[output.length - 1];
|
|
24
|
+
if (last?.type === "literal") last.value += value;
|
|
25
|
+
else output.push({ type: "literal", value });
|
|
26
|
+
};
|
|
27
|
+
let cursor: number = 0;
|
|
28
|
+
for (const match of path.matchAll(/\{([^{}]+)\}/g)) {
|
|
29
|
+
literal(path.slice(cursor, match.index));
|
|
30
|
+
cursor = match.index! + match[0].length;
|
|
31
|
+
const parameter: IHttpMigrateRoute.IParameter | undefined =
|
|
32
|
+
route.parameters.find((p) => p.name === match[1]);
|
|
33
|
+
if (parameter === undefined) literal(match[0]);
|
|
34
|
+
else output.push({ type: "param", parameter });
|
|
35
|
+
}
|
|
36
|
+
literal(path.slice(cursor));
|
|
37
|
+
return output;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { IHttpMigrateRoute } from "@typia/interface";
|
|
2
|
+
|
|
3
|
+
export namespace RequestBody {
|
|
4
|
+
/**
|
|
5
|
+
* Whether the route's body may be omitted: a JSON or text body the document
|
|
6
|
+
* does not require. The SDK's positional and keyword functions and the Nest
|
|
7
|
+
* controller all read this one rule.
|
|
8
|
+
*/
|
|
9
|
+
export const optional = (route: IHttpMigrateRoute): boolean =>
|
|
10
|
+
route.body !== null &&
|
|
11
|
+
(route.body.type === "application/json" ||
|
|
12
|
+
route.body.type === "text/plain") &&
|
|
13
|
+
route.operation().requestBody?.required === false;
|
|
14
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { IHttpMigrateRoute } from "@typia/interface";
|
|
2
|
+
|
|
3
|
+
export namespace SuccessStatus {
|
|
4
|
+
/**
|
|
5
|
+
* The route's success status code, or null when the document declares only a
|
|
6
|
+
* range (`2XX`) or a `default` response.
|
|
7
|
+
*
|
|
8
|
+
* The success response is the one typia's route composer selects: 200, then
|
|
9
|
+
* 201, then the lowest other 2xx. A bodiless one, such as a 204 No Content,
|
|
10
|
+
* leaves `route.success` null, so its status is read from the responses.
|
|
11
|
+
*/
|
|
12
|
+
export const of = (route: IHttpMigrateRoute): number | null => {
|
|
13
|
+
const status: string | undefined =
|
|
14
|
+
route.success?.status ??
|
|
15
|
+
Object.keys(route.operation().responses ?? {})
|
|
16
|
+
.filter((key) => /^2\d\d$/.test(key))
|
|
17
|
+
.sort((x, y) => priority(x) - priority(y))[0];
|
|
18
|
+
return status !== undefined && /^\d{3}$/.test(status)
|
|
19
|
+
? Number(status)
|
|
20
|
+
: null;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/** The status NestJS answers without `@HttpCode()`. */
|
|
24
|
+
export const nest = (route: IHttpMigrateRoute): number =>
|
|
25
|
+
route.method === "post" ? 201 : 200;
|
|
26
|
+
|
|
27
|
+
const priority = (status: string): number =>
|
|
28
|
+
status === "200" ? 0 : status === "201" ? 1 : Number(status);
|
|
29
|
+
}
|