@nestia/migrate 14.0.0 → 14.0.2
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/NestiaMigrateApplication.d.ts +111 -0
- package/lib/NestiaMigrateApplication.js +148 -9
- package/lib/NestiaMigrateApplication.js.map +1 -1
- package/lib/NestiaMigrateApplication.mjs +147 -5
- package/lib/analyzers/NestiaMigrateControllerAnalyzer.d.ts +58 -0
- package/lib/analyzers/NestiaMigrateControllerAnalyzer.js +88 -2
- package/lib/analyzers/NestiaMigrateControllerAnalyzer.js.map +1 -1
- package/lib/analyzers/NestiaMigrateControllerAnalyzer.mjs +20 -2
- package/lib/archivers/NestiaMigrateFileArchiver.d.ts +34 -0
- package/lib/archivers/NestiaMigrateFileArchiver.js +34 -0
- package/lib/archivers/NestiaMigrateFileArchiver.js.map +1 -1
- 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.d.ts +36 -0
- package/lib/executable/NestiaMigrateCommander.js +43 -1
- package/lib/executable/NestiaMigrateCommander.js.map +1 -1
- package/lib/executable/NestiaMigrateCommander.mjs +4 -2
- package/lib/executable/NestiaMigrateInquirer.d.ts +29 -0
- package/lib/executable/NestiaMigrateInquirer.js +27 -25
- package/lib/executable/NestiaMigrateInquirer.js.map +1 -1
- package/lib/executable/NestiaMigrateInquirer.mjs +5 -7
- package/lib/factories/ExpressionFactory.d.ts +14 -0
- package/lib/factories/ExpressionFactory.js +14 -0
- package/lib/factories/ExpressionFactory.js.map +1 -1
- package/lib/factories/IdentifierFactory.d.ts +20 -0
- package/lib/factories/IdentifierFactory.js +20 -0
- package/lib/factories/IdentifierFactory.js.map +1 -1
- package/lib/factories/LiteralFactory.d.ts +18 -2
- package/lib/factories/LiteralFactory.js +18 -2
- package/lib/factories/LiteralFactory.js.map +1 -1
- package/lib/factories/StatementFactory.d.ts +26 -1
- package/lib/factories/StatementFactory.js +26 -1
- package/lib/factories/StatementFactory.js.map +1 -1
- package/lib/factories/SupportedStringFormats.d.ts +6 -0
- package/lib/factories/SupportedStringFormats.js +33 -0
- package/lib/factories/SupportedStringFormats.js.map +1 -0
- package/lib/factories/SupportedStringFormats.mjs +34 -0
- package/lib/factories/SupportedStringFormats.mjs.map +1 -0
- package/lib/factories/TypeFactory.d.ts +21 -0
- package/lib/factories/TypeFactory.js +13 -0
- package/lib/factories/TypeFactory.js.map +1 -1
- package/lib/factories/TypeLiteralFactory.d.ts +18 -0
- package/lib/factories/TypeLiteralFactory.js +18 -0
- package/lib/factories/TypeLiteralFactory.js.map +1 -1
- package/lib/internal/ts.d.ts +153 -0
- package/lib/internal/ts.js.map +1 -1
- package/lib/programmers/NestiaMigrateApiFileProgrammer.d.ts +31 -0
- package/lib/programmers/NestiaMigrateApiFileProgrammer.js +17 -0
- package/lib/programmers/NestiaMigrateApiFileProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateApiFunctionProgrammer.d.ts +40 -0
- package/lib/programmers/NestiaMigrateApiFunctionProgrammer.js +34 -5
- package/lib/programmers/NestiaMigrateApiFunctionProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateApiFunctionProgrammer.mjs +4 -2
- package/lib/programmers/NestiaMigrateApiNamespaceProgrammer.d.ts +39 -0
- package/lib/programmers/NestiaMigrateApiNamespaceProgrammer.js +57 -13
- package/lib/programmers/NestiaMigrateApiNamespaceProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateApiNamespaceProgrammer.mjs +17 -8
- package/lib/programmers/NestiaMigrateApiProgrammer.d.ts +18 -0
- package/lib/programmers/NestiaMigrateApiProgrammer.js +18 -0
- package/lib/programmers/NestiaMigrateApiProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateApiProgrammer.mjs +1 -1
- package/lib/programmers/NestiaMigrateApiSimulationProgrammer.d.ts +40 -0
- package/lib/programmers/NestiaMigrateApiSimulationProgrammer.js +51 -22
- package/lib/programmers/NestiaMigrateApiSimulationProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateApiSimulationProgrammer.mjs +13 -20
- package/lib/programmers/NestiaMigrateApiStartProgrammer.d.ts +17 -0
- package/lib/programmers/NestiaMigrateApiStartProgrammer.js +19 -8
- package/lib/programmers/NestiaMigrateApiStartProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateApiStartProgrammer.mjs +1 -6
- package/lib/programmers/NestiaMigrateDtoProgrammer.d.ts +30 -0
- package/lib/programmers/NestiaMigrateDtoProgrammer.js +17 -0
- package/lib/programmers/NestiaMigrateDtoProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateE2eFileProgrammer.d.ts +39 -0
- package/lib/programmers/NestiaMigrateE2eFileProgrammer.js +46 -5
- package/lib/programmers/NestiaMigrateE2eFileProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateE2eFileProgrammer.mjs +6 -2
- package/lib/programmers/NestiaMigrateE2eProgrammer.d.ts +16 -0
- package/lib/programmers/NestiaMigrateE2eProgrammer.js +16 -0
- package/lib/programmers/NestiaMigrateE2eProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateImportProgrammer.d.ts +75 -0
- package/lib/programmers/NestiaMigrateImportProgrammer.js +58 -3
- package/lib/programmers/NestiaMigrateImportProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateImportProgrammer.mjs +58 -3
- package/lib/programmers/NestiaMigrateNestControllerProgrammer.d.ts +28 -0
- package/lib/programmers/NestiaMigrateNestControllerProgrammer.js +16 -0
- package/lib/programmers/NestiaMigrateNestControllerProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateNestMethodProgrammer.d.ts +30 -0
- package/lib/programmers/NestiaMigrateNestMethodProgrammer.js +85 -13
- package/lib/programmers/NestiaMigrateNestMethodProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateNestMethodProgrammer.mjs +46 -9
- package/lib/programmers/NestiaMigrateNestModuleProgrammer.d.ts +16 -0
- package/lib/programmers/NestiaMigrateNestModuleProgrammer.js +16 -0
- package/lib/programmers/NestiaMigrateNestModuleProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateNestProgrammer.d.ts +17 -0
- package/lib/programmers/NestiaMigrateNestProgrammer.js +17 -0
- package/lib/programmers/NestiaMigrateNestProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateSchemaProgrammer.d.ts +16 -0
- package/lib/programmers/NestiaMigrateSchemaProgrammer.js +45 -9
- package/lib/programmers/NestiaMigrateSchemaProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateSchemaProgrammer.mjs +19 -8
- package/lib/structures/INestiaMigrateConfig.d.ts +21 -0
- package/lib/structures/INestiaMigrateContext.d.ts +15 -0
- package/lib/structures/INestiaMigrateController.d.ts +13 -0
- package/lib/structures/INestiaMigrateFile.d.ts +11 -0
- package/lib/utils/FilePrinter.d.ts +33 -0
- package/lib/utils/FilePrinter.js +33 -0
- package/lib/utils/FilePrinter.js.map +1 -1
- package/lib/utils/MapUtil.d.ts +17 -0
- package/lib/utils/MapUtil.js +19 -3
- package/lib/utils/MapUtil.js.map +1 -1
- package/lib/utils/MapUtil.mjs +1 -2
- package/lib/utils/PathTemplate.d.ts +41 -0
- package/lib/utils/PathTemplate.js +56 -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 +22 -0
- package/lib/utils/RequestBody.js +29 -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/StringUtil.d.ts +55 -0
- package/lib/utils/StringUtil.js +93 -8
- package/lib/utils/StringUtil.js.map +1 -1
- package/lib/utils/StringUtil.mjs +30 -8
- package/lib/utils/SuccessStatus.d.ts +34 -0
- package/lib/utils/SuccessStatus.js +48 -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 +5 -4
- package/src/NestiaMigrateApplication.ts +151 -13
- package/src/analyzers/NestiaMigrateControllerAnalyzer.ts +94 -2
- package/src/archivers/NestiaMigrateFileArchiver.ts +34 -0
- package/src/bundles/NEST_TEMPLATE.ts +1 -1
- package/src/bundles/SDK_TEMPLATE.ts +1 -1
- package/src/executable/NestiaMigrateCommander.ts +47 -1
- package/src/executable/NestiaMigrateInquirer.ts +41 -26
- package/src/factories/ExpressionFactory.ts +14 -0
- package/src/factories/IdentifierFactory.ts +20 -0
- package/src/factories/LiteralFactory.ts +18 -2
- package/src/factories/StatementFactory.ts +26 -1
- package/src/factories/SupportedStringFormats.ts +29 -0
- package/src/factories/TypeFactory.ts +21 -0
- package/src/factories/TypeLiteralFactory.ts +18 -0
- package/src/internal/ts.ts +153 -0
- package/src/programmers/NestiaMigrateApiFileProgrammer.ts +35 -0
- package/src/programmers/NestiaMigrateApiFunctionProgrammer.ts +53 -4
- package/src/programmers/NestiaMigrateApiNamespaceProgrammer.ts +83 -20
- package/src/programmers/NestiaMigrateApiProgrammer.ts +18 -0
- package/src/programmers/NestiaMigrateApiSimulationProgrammer.ts +66 -73
- package/src/programmers/NestiaMigrateApiStartProgrammer.ts +19 -10
- package/src/programmers/NestiaMigrateDtoProgrammer.ts +33 -0
- package/src/programmers/NestiaMigrateE2eFileProgrammer.ts +83 -8
- package/src/programmers/NestiaMigrateE2eProgrammer.ts +16 -0
- package/src/programmers/NestiaMigrateImportProgrammer.ts +86 -5
- package/src/programmers/NestiaMigrateNestControllerProgrammer.ts +30 -0
- package/src/programmers/NestiaMigrateNestMethodProgrammer.ts +122 -29
- package/src/programmers/NestiaMigrateNestModuleProgrammer.ts +16 -0
- package/src/programmers/NestiaMigrateNestProgrammer.ts +17 -0
- package/src/programmers/NestiaMigrateSchemaProgrammer.ts +53 -18
- package/src/structures/INestiaMigrateConfig.ts +26 -0
- package/src/structures/INestiaMigrateContext.ts +17 -0
- package/src/structures/INestiaMigrateController.ts +16 -0
- package/src/structures/INestiaMigrateFile.ts +13 -0
- package/src/utils/FilePrinter.ts +33 -0
- package/src/utils/MapUtil.ts +18 -2
- package/src/utils/PathTemplate.ts +61 -0
- package/src/utils/RequestBody.ts +27 -0
- package/src/utils/StringUtil.ts +101 -9
- package/src/utils/SuccessStatus.ts +49 -0
- package/lib/factories/FormatCheatSheet.d.ts +0 -25
- package/lib/factories/FormatCheatSheet.js +0 -34
- package/lib/factories/FormatCheatSheet.js.map +0 -1
- package/lib/factories/FormatCheatSheet.mjs +0 -31
- package/lib/factories/FormatCheatSheet.mjs.map +0 -1
- package/src/factories/FormatCheatSheet.ts +0 -71
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { IHttpMigrateRoute } from "@typia/interface";
|
|
2
|
+
/**
|
|
3
|
+
* Splits a route path template into literal and parameter segments.
|
|
4
|
+
*
|
|
5
|
+
* @evidence contracts/common.md#principled-implementation The namespace scans the template for `{name}` placeholders and matches each with the route's parameter of that name.
|
|
6
|
+
* @evidence contracts/common.md#clear-and-simple-design One type and one function.
|
|
7
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts The scan is by the template syntax.
|
|
8
|
+
* @evidence contracts/common.md#meaningful-documentation The comment states its purpose.
|
|
9
|
+
*/
|
|
10
|
+
export declare namespace PathTemplate {
|
|
11
|
+
/**
|
|
12
|
+
* A segment of a path: a literal text or a parameter.
|
|
13
|
+
*
|
|
14
|
+
* @evidence contracts/common.md#principled-implementation The union is discriminated by `type`, so a consumer handles each case once.
|
|
15
|
+
* @evidence contracts/common.md#clear-and-simple-design A two-member union.
|
|
16
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts It is a type and adds no runtime behavior.
|
|
17
|
+
* @evidence contracts/common.md#meaningful-documentation The comment names the two cases.
|
|
18
|
+
*/
|
|
19
|
+
type ISegment = {
|
|
20
|
+
type: "literal";
|
|
21
|
+
value: string;
|
|
22
|
+
} | {
|
|
23
|
+
type: "param";
|
|
24
|
+
parameter: IHttpMigrateRoute.IParameter;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* The route's path as literal text and path parameters, in order, read from
|
|
28
|
+
* the document's own template (`/files/{id}.json`), whose braces delimit each
|
|
29
|
+
* parameter name. The emended path (`/files/:id.json`) cannot be split back:
|
|
30
|
+
* its `:id.json` could name `id` or `id.json`, and a name such as `item-id`
|
|
31
|
+
* would read as `item` followed by `-id`. It always starts with `/`, as the
|
|
32
|
+
* emended path does. A placeholder without a matching route parameter remains
|
|
33
|
+
* literal text; adjacent literals are merged.
|
|
34
|
+
*
|
|
35
|
+
* @evidence contracts/common.md#principled-implementation The scan uses a regular expression over the placeholders and joins the text between them, and merging adjacent literals keeps the segment list minimal.
|
|
36
|
+
* @evidence contracts/common.md#clear-and-simple-design One function with one helper for merging.
|
|
37
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts It never drops text of the template.
|
|
38
|
+
* @evidence contracts/common.md#meaningful-documentation The comment states the merging and the unmatched placeholder rule.
|
|
39
|
+
*/
|
|
40
|
+
const segments: (route: IHttpMigrateRoute) => ISegment[];
|
|
41
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PathTemplate = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Splits a route path template into literal and parameter segments.
|
|
6
|
+
*
|
|
7
|
+
* @evidence contracts/common.md#principled-implementation The namespace scans the template for `{name}` placeholders and matches each with the route's parameter of that name.
|
|
8
|
+
* @evidence contracts/common.md#clear-and-simple-design One type and one function.
|
|
9
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts The scan is by the template syntax.
|
|
10
|
+
* @evidence contracts/common.md#meaningful-documentation The comment states its purpose.
|
|
11
|
+
*/
|
|
12
|
+
var PathTemplate;
|
|
13
|
+
(function (PathTemplate) {
|
|
14
|
+
/**
|
|
15
|
+
* The route's path as literal text and path parameters, in order, read from
|
|
16
|
+
* the document's own template (`/files/{id}.json`), whose braces delimit each
|
|
17
|
+
* parameter name. The emended path (`/files/:id.json`) cannot be split back:
|
|
18
|
+
* its `:id.json` could name `id` or `id.json`, and a name such as `item-id`
|
|
19
|
+
* would read as `item` followed by `-id`. It always starts with `/`, as the
|
|
20
|
+
* emended path does. A placeholder without a matching route parameter remains
|
|
21
|
+
* literal text; adjacent literals are merged.
|
|
22
|
+
*
|
|
23
|
+
* @evidence contracts/common.md#principled-implementation The scan uses a regular expression over the placeholders and joins the text between them, and merging adjacent literals keeps the segment list minimal.
|
|
24
|
+
* @evidence contracts/common.md#clear-and-simple-design One function with one helper for merging.
|
|
25
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts It never drops text of the template.
|
|
26
|
+
* @evidence contracts/common.md#meaningful-documentation The comment states the merging and the unmatched placeholder rule.
|
|
27
|
+
*/
|
|
28
|
+
PathTemplate.segments = (route) => {
|
|
29
|
+
const path = route.path.startsWith("/")
|
|
30
|
+
? route.path
|
|
31
|
+
: `/${route.path}`;
|
|
32
|
+
const output = [];
|
|
33
|
+
const literal = (value) => {
|
|
34
|
+
if (value.length === 0)
|
|
35
|
+
return;
|
|
36
|
+
const last = output[output.length - 1];
|
|
37
|
+
if ((last === null || last === void 0 ? void 0 : last.type) === "literal")
|
|
38
|
+
last.value += value;
|
|
39
|
+
else
|
|
40
|
+
output.push({ type: "literal", value });
|
|
41
|
+
};
|
|
42
|
+
let cursor = 0;
|
|
43
|
+
for (const match of path.matchAll(/\{([^{}]+)\}/g)) {
|
|
44
|
+
literal(path.slice(cursor, match.index));
|
|
45
|
+
cursor = match.index + match[0].length;
|
|
46
|
+
const parameter = route.parameters.find((p) => p.name === match[1]);
|
|
47
|
+
if (parameter === undefined)
|
|
48
|
+
literal(match[0]);
|
|
49
|
+
else
|
|
50
|
+
output.push({ type: "param", parameter });
|
|
51
|
+
}
|
|
52
|
+
literal(path.slice(cursor));
|
|
53
|
+
return output;
|
|
54
|
+
};
|
|
55
|
+
})(PathTemplate || (exports.PathTemplate = PathTemplate = {}));
|
|
56
|
+
//# sourceMappingURL=PathTemplate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PathTemplate.js","sourceRoot":"","sources":["../../src/utils/PathTemplate.ts"],"names":[],"mappings":";;;AAEA;;;;;;;GAOG;AACH,IAAiB,YAAY,CAkD5B;AAlDD,WAAiB,YAAY;IAa3B;;;;;;;;;;;;;OAaG;IACU,qBAAQ,GAAG,CAAC,KAAwB,EAAc,EAAE;QAC/D,MAAM,IAAI,GAAW,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;YAC7C,CAAC,CAAC,KAAK,CAAC,IAAI;YACZ,CAAC,CAAC,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC;QACrB,MAAM,MAAM,GAAe,EAAE,CAAC;QAC9B,MAAM,OAAO,GAAG,CAAC,KAAa,EAAQ,EAAE;YACtC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;gBAAE,OAAO;YAC/B,MAAM,IAAI,GAAyB,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;YAC7D,IAAI,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,IAAI,MAAK,SAAS;gBAAE,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC;;gBAC7C,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;QAC/C,CAAC,CAAC;QACF,IAAI,MAAM,GAAW,CAAC,CAAC;QACvB,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC;YACnD,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;YACzC,MAAM,GAAG,KAAK,CAAC,KAAM,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;YACxC,MAAM,SAAS,GACb,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;YACpD,IAAI,SAAS,KAAK,SAAS;gBAAE,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;;gBAC1C,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC;QACjD,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;QAC5B,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC,EAlDgB,YAAY,aAAZ,YAAY,GAAZ,YAAY,QAkD5B"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
//#region src/utils/PathTemplate.ts
|
|
2
|
+
let PathTemplate;
|
|
3
|
+
(function(_PathTemplate) {
|
|
4
|
+
_PathTemplate.segments = (route) => {
|
|
5
|
+
const path = route.path.startsWith("/") ? route.path : `/${route.path}`;
|
|
6
|
+
const output = [];
|
|
7
|
+
const literal = (value) => {
|
|
8
|
+
if (value.length === 0) return;
|
|
9
|
+
const last = output[output.length - 1];
|
|
10
|
+
if (last?.type === "literal") last.value += value;
|
|
11
|
+
else output.push({
|
|
12
|
+
type: "literal",
|
|
13
|
+
value
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
let cursor = 0;
|
|
17
|
+
for (const match of path.matchAll(/\{([^{}]+)\}/g)) {
|
|
18
|
+
literal(path.slice(cursor, match.index));
|
|
19
|
+
cursor = match.index + match[0].length;
|
|
20
|
+
const parameter = route.parameters.find((p) => p.name === match[1]);
|
|
21
|
+
if (parameter === void 0) literal(match[0]);
|
|
22
|
+
else output.push({
|
|
23
|
+
type: "param",
|
|
24
|
+
parameter
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
literal(path.slice(cursor));
|
|
28
|
+
return output;
|
|
29
|
+
};
|
|
30
|
+
})(PathTemplate || (PathTemplate = {}));
|
|
31
|
+
//#endregion
|
|
32
|
+
export { PathTemplate };
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=PathTemplate.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PathTemplate.mjs","names":[],"sources":[],"mappings":""}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { IHttpMigrateRoute } from "@typia/interface";
|
|
2
|
+
/**
|
|
3
|
+
* Helpers about the request body of a route.
|
|
4
|
+
*
|
|
5
|
+
* @evidence contracts/common.md#principled-implementation The namespace holds the optional-body predicate.
|
|
6
|
+
* @evidence contracts/common.md#clear-and-simple-design One function.
|
|
7
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts It is a plain helper.
|
|
8
|
+
* @evidence contracts/common.md#meaningful-documentation The comment states its purpose.
|
|
9
|
+
*/
|
|
10
|
+
export declare namespace RequestBody {
|
|
11
|
+
/**
|
|
12
|
+
* Whether the route's body may be omitted: a JSON or text body the document
|
|
13
|
+
* does not require. The SDK's positional and keyword functions and the Nest
|
|
14
|
+
* controller all read this one rule.
|
|
15
|
+
*
|
|
16
|
+
* @evidence contracts/common.md#principled-implementation The requirement flag is read from the operation and only an explicit `false` makes the body optional.
|
|
17
|
+
* @evidence contracts/common.md#clear-and-simple-design One expression.
|
|
18
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts It reads the document.
|
|
19
|
+
* @evidence contracts/common.md#meaningful-documentation The comment states the condition.
|
|
20
|
+
*/
|
|
21
|
+
const optional: (route: IHttpMigrateRoute) => boolean;
|
|
22
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RequestBody = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Helpers about the request body of a route.
|
|
6
|
+
*
|
|
7
|
+
* @evidence contracts/common.md#principled-implementation The namespace holds the optional-body predicate.
|
|
8
|
+
* @evidence contracts/common.md#clear-and-simple-design One function.
|
|
9
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts It is a plain helper.
|
|
10
|
+
* @evidence contracts/common.md#meaningful-documentation The comment states its purpose.
|
|
11
|
+
*/
|
|
12
|
+
var RequestBody;
|
|
13
|
+
(function (RequestBody) {
|
|
14
|
+
/**
|
|
15
|
+
* Whether the route's body may be omitted: a JSON or text body the document
|
|
16
|
+
* does not require. The SDK's positional and keyword functions and the Nest
|
|
17
|
+
* controller all read this one rule.
|
|
18
|
+
*
|
|
19
|
+
* @evidence contracts/common.md#principled-implementation The requirement flag is read from the operation and only an explicit `false` makes the body optional.
|
|
20
|
+
* @evidence contracts/common.md#clear-and-simple-design One expression.
|
|
21
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts It reads the document.
|
|
22
|
+
* @evidence contracts/common.md#meaningful-documentation The comment states the condition.
|
|
23
|
+
*/
|
|
24
|
+
RequestBody.optional = (route) => { var _a; return route.body !== null &&
|
|
25
|
+
(route.body.type === "application/json" ||
|
|
26
|
+
route.body.type === "text/plain") &&
|
|
27
|
+
((_a = route.operation().requestBody) === null || _a === void 0 ? void 0 : _a.required) === false; };
|
|
28
|
+
})(RequestBody || (exports.RequestBody = RequestBody = {}));
|
|
29
|
+
//# sourceMappingURL=RequestBody.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RequestBody.js","sourceRoot":"","sources":["../../src/utils/RequestBody.ts"],"names":[],"mappings":";;;AAEA;;;;;;;GAOG;AACH,IAAiB,WAAW,CAgB3B;AAhBD,WAAiB,WAAW;IAC1B;;;;;;;;;OASG;IACU,oBAAQ,GAAG,CAAC,KAAwB,EAAW,EAAE,kBAC5D,KAAK,CAAC,IAAI,KAAK,IAAI;QACnB,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,KAAK,kBAAkB;YACrC,KAAK,CAAC,IAAI,CAAC,IAAI,KAAK,YAAY,CAAC;QACnC,CAAA,MAAA,KAAK,CAAC,SAAS,EAAE,CAAC,WAAW,0CAAE,QAAQ,MAAK,KAAK,GAAA,CAAC;AACtD,CAAC,EAhBgB,WAAW,aAAX,WAAW,GAAX,WAAW,QAgB3B"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/utils/RequestBody.ts
|
|
2
|
+
let RequestBody;
|
|
3
|
+
(function(_RequestBody) {
|
|
4
|
+
_RequestBody.optional = (route) => route.body !== null && (route.body.type === "application/json" || route.body.type === "text/plain") && route.operation().requestBody?.required === false;
|
|
5
|
+
})(RequestBody || (RequestBody = {}));
|
|
6
|
+
//#endregion
|
|
7
|
+
export { RequestBody };
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=RequestBody.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RequestBody.mjs","names":[],"sources":[],"mappings":""}
|
|
@@ -1,5 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* String helpers that turn arbitrary text into valid identifiers and names.
|
|
3
|
+
*
|
|
4
|
+
* Identifier escaping traverses the input with a fixed punctuation table and
|
|
5
|
+
* Unicode-aware per-segment replacements; total work and intermediate storage
|
|
6
|
+
* scale with encoded output length.
|
|
7
|
+
*
|
|
8
|
+
* @evidence contracts/common.md#principled-implementation The namespace holds the capitalization, path segment normalization, and identifier escaping rules used by the generators.
|
|
9
|
+
* @evidence contracts/common.md#clear-and-simple-design Three functions and private tables of reserved words and replacements.
|
|
10
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts The tables are the language's reserved words and a fixed replacement of punctuation.
|
|
11
|
+
* @evidence contracts/common.md#meaningful-documentation The comment states its purpose.
|
|
12
|
+
*/
|
|
1
13
|
export declare namespace StringUtil {
|
|
14
|
+
/**
|
|
15
|
+
* Upper-cases the first character and lower-cases the rest; an empty string
|
|
16
|
+
* stays empty.
|
|
17
|
+
*
|
|
18
|
+
* One leading-character conversion and one remainder conversion cost O(N) in
|
|
19
|
+
* the input length.
|
|
20
|
+
*
|
|
21
|
+
* @evidence contracts/common.md#principled-implementation The first character is transformed alone and the remainder is lower-cased, so the result is a normalized word.
|
|
22
|
+
* @evidence contracts/common.md#clear-and-simple-design One expression.
|
|
23
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts It applies to every input.
|
|
24
|
+
* @evidence contracts/common.md#meaningful-documentation The comment states the rule and the empty case.
|
|
25
|
+
*/
|
|
2
26
|
const capitalize: (str: string) => string;
|
|
27
|
+
/**
|
|
28
|
+
* Splits a path by slashes and normalizes each non-empty segment into a name.
|
|
29
|
+
*
|
|
30
|
+
* The path is split once and each segment normalized with a fixed number of
|
|
31
|
+
* transformations: O(N) total text work and output storage.
|
|
32
|
+
*
|
|
33
|
+
* @evidence contracts/common.md#principled-implementation Each segment loses dots and dashes, a reserved word or a leading digit gets an underscore prefix, and empty segments are dropped.
|
|
34
|
+
* @evidence contracts/common.md#clear-and-simple-design One expression over the private normalizer.
|
|
35
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts The rules apply to every segment.
|
|
36
|
+
* @evidence contracts/common.md#meaningful-documentation The comment states the normalization.
|
|
37
|
+
*/
|
|
3
38
|
const splitWithNormalization: (path: string) => string[];
|
|
39
|
+
/**
|
|
40
|
+
* Escapes a string into a valid, possibly qualified, name.
|
|
41
|
+
*
|
|
42
|
+
* A dot separates the segments of a qualified name, so each segment is
|
|
43
|
+
* escaped as one identifier. Punctuation is replaced by a word such as
|
|
44
|
+
* `_at_`, any other character an identifier cannot hold by its code point, a
|
|
45
|
+
* reserved word or a segment that cannot start an identifier gets an
|
|
46
|
+
* underscore prefix, and an empty segment is `_empty_`. The last segment
|
|
47
|
+
* names a type, so it is also prefixed when it is a predefined type name.
|
|
48
|
+
*
|
|
49
|
+
* A fixed punctuation table traverses the text before per-segment Unicode
|
|
50
|
+
* escaping. Work scales linearly with the encoded text length for the fixed
|
|
51
|
+
* table; expanded code-point spellings are retained only in the returned
|
|
52
|
+
* string.
|
|
53
|
+
*
|
|
54
|
+
* @evidence contracts/common.md#principled-implementation Whitespace at the edges is trimmed and the punctuation table is applied in its fixed order over the whole string; the string is then split at the dots, which stay as the namespace separators the DTO tree reads, and every segment is made an identifier by the ECMAScript rule: characters outside `ID_Continue` become their code point, and a reserved word, a predefined type name in the last segment or a segment not starting with `ID_Start`, `_` or `$` is prefixed with an underscore, so each segment is a valid identifier even where the punctuation table does not cover its characters.
|
|
55
|
+
* @evidence contracts/common.md#clear-and-simple-design One function over one segment helper and three private tables of reserved words, predefined type names and replacements.
|
|
56
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts No schema name is special-cased; the fixed punctuation table and Unicode identifier rules apply to every segment.
|
|
57
|
+
* @evidence contracts/common.md#meaningful-documentation The comment states the segment rule, the replacements, the prefixes and the empty case.
|
|
58
|
+
*/
|
|
4
59
|
const escapeNonVariable: (str: string) => string;
|
|
5
60
|
}
|
package/lib/utils/StringUtil.js
CHANGED
|
@@ -1,25 +1,78 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.StringUtil = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* String helpers that turn arbitrary text into valid identifiers and names.
|
|
6
|
+
*
|
|
7
|
+
* Identifier escaping traverses the input with a fixed punctuation table and
|
|
8
|
+
* Unicode-aware per-segment replacements; total work and intermediate storage
|
|
9
|
+
* scale with encoded output length.
|
|
10
|
+
*
|
|
11
|
+
* @evidence contracts/common.md#principled-implementation The namespace holds the capitalization, path segment normalization, and identifier escaping rules used by the generators.
|
|
12
|
+
* @evidence contracts/common.md#clear-and-simple-design Three functions and private tables of reserved words and replacements.
|
|
13
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts The tables are the language's reserved words and a fixed replacement of punctuation.
|
|
14
|
+
* @evidence contracts/common.md#meaningful-documentation The comment states its purpose.
|
|
15
|
+
*/
|
|
4
16
|
var StringUtil;
|
|
5
17
|
(function (StringUtil) {
|
|
6
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Upper-cases the first character and lower-cases the rest; an empty string
|
|
20
|
+
* stays empty.
|
|
21
|
+
*
|
|
22
|
+
* One leading-character conversion and one remainder conversion cost O(N) in
|
|
23
|
+
* the input length.
|
|
24
|
+
*
|
|
25
|
+
* @evidence contracts/common.md#principled-implementation The first character is transformed alone and the remainder is lower-cased, so the result is a normalized word.
|
|
26
|
+
* @evidence contracts/common.md#clear-and-simple-design One expression.
|
|
27
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts It applies to every input.
|
|
28
|
+
* @evidence contracts/common.md#meaningful-documentation The comment states the rule and the empty case.
|
|
29
|
+
*/
|
|
30
|
+
StringUtil.capitalize = (str) => str.length === 0 ? str : str[0].toUpperCase() + str.slice(1).toLowerCase();
|
|
31
|
+
/**
|
|
32
|
+
* Splits a path by slashes and normalizes each non-empty segment into a name.
|
|
33
|
+
*
|
|
34
|
+
* The path is split once and each segment normalized with a fixed number of
|
|
35
|
+
* transformations: O(N) total text work and output storage.
|
|
36
|
+
*
|
|
37
|
+
* @evidence contracts/common.md#principled-implementation Each segment loses dots and dashes, a reserved word or a leading digit gets an underscore prefix, and empty segments are dropped.
|
|
38
|
+
* @evidence contracts/common.md#clear-and-simple-design One expression over the private normalizer.
|
|
39
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts The rules apply to every segment.
|
|
40
|
+
* @evidence contracts/common.md#meaningful-documentation The comment states the normalization.
|
|
41
|
+
*/
|
|
7
42
|
StringUtil.splitWithNormalization = (path) => path
|
|
8
43
|
.split("/")
|
|
9
44
|
.map((str) => normalize(str.trim()))
|
|
10
45
|
.filter((str) => !!str.length);
|
|
46
|
+
/**
|
|
47
|
+
* Escapes a string into a valid, possibly qualified, name.
|
|
48
|
+
*
|
|
49
|
+
* A dot separates the segments of a qualified name, so each segment is
|
|
50
|
+
* escaped as one identifier. Punctuation is replaced by a word such as
|
|
51
|
+
* `_at_`, any other character an identifier cannot hold by its code point, a
|
|
52
|
+
* reserved word or a segment that cannot start an identifier gets an
|
|
53
|
+
* underscore prefix, and an empty segment is `_empty_`. The last segment
|
|
54
|
+
* names a type, so it is also prefixed when it is a predefined type name.
|
|
55
|
+
*
|
|
56
|
+
* A fixed punctuation table traverses the text before per-segment Unicode
|
|
57
|
+
* escaping. Work scales linearly with the encoded text length for the fixed
|
|
58
|
+
* table; expanded code-point spellings are retained only in the returned
|
|
59
|
+
* string.
|
|
60
|
+
*
|
|
61
|
+
* @evidence contracts/common.md#principled-implementation Whitespace at the edges is trimmed and the punctuation table is applied in its fixed order over the whole string; the string is then split at the dots, which stay as the namespace separators the DTO tree reads, and every segment is made an identifier by the ECMAScript rule: characters outside `ID_Continue` become their code point, and a reserved word, a predefined type name in the last segment or a segment not starting with `ID_Start`, `_` or `$` is prefixed with an underscore, so each segment is a valid identifier even where the punctuation table does not cover its characters.
|
|
62
|
+
* @evidence contracts/common.md#clear-and-simple-design One function over one segment helper and three private tables of reserved words, predefined type names and replacements.
|
|
63
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts No schema name is special-cased; the fixed punctuation table and Unicode identifier rules apply to every segment.
|
|
64
|
+
* @evidence contracts/common.md#meaningful-documentation The comment states the segment rule, the replacements, the prefixes and the empty case.
|
|
65
|
+
*/
|
|
11
66
|
StringUtil.escapeNonVariable = (str) => {
|
|
12
|
-
str =
|
|
67
|
+
str = str.trim();
|
|
13
68
|
for (const [before, after] of VARIABLE_REPLACERS)
|
|
14
69
|
str = str.split(before).join(after);
|
|
15
|
-
for (let i = 0; i <= 9; ++i)
|
|
16
|
-
if (str[0] === i.toString()) {
|
|
17
|
-
str = "_" + str;
|
|
18
|
-
break;
|
|
19
|
-
}
|
|
20
70
|
if (str === "")
|
|
21
71
|
return "_empty_";
|
|
22
|
-
|
|
72
|
+
const segments = str.split(".");
|
|
73
|
+
return segments
|
|
74
|
+
.map((segment, index) => escapeSegment(segment, index === segments.length - 1))
|
|
75
|
+
.join(".");
|
|
23
76
|
};
|
|
24
77
|
})(StringUtil || (exports.StringUtil = StringUtil = {}));
|
|
25
78
|
const escape = (str) => {
|
|
@@ -30,8 +83,35 @@ const escape = (str) => {
|
|
|
30
83
|
str = `_${str}`;
|
|
31
84
|
return str;
|
|
32
85
|
};
|
|
86
|
+
// One identifier. The patterns are built at run time because the property
|
|
87
|
+
// escapes need a newer script target than the one this package compiles to.
|
|
88
|
+
const NON_IDENTIFIER_PART = new RegExp("[^\\p{ID_Continue}]", "gu");
|
|
89
|
+
const IDENTIFIER_START = new RegExp("^[\\p{ID_Start}_$]", "u");
|
|
90
|
+
const escapeSegment = (segment, type) => {
|
|
91
|
+
segment = segment.replace(NON_IDENTIFIER_PART, (char) => `_u${char.codePointAt(0).toString(16)}_`);
|
|
92
|
+
if (segment.length === 0)
|
|
93
|
+
return "_empty_";
|
|
94
|
+
return RESERVED.has(segment) ||
|
|
95
|
+
(type && TYPE_NAMES.has(segment)) ||
|
|
96
|
+
IDENTIFIER_START.test(segment) === false
|
|
97
|
+
? `_${segment}`
|
|
98
|
+
: segment;
|
|
99
|
+
};
|
|
33
100
|
const normalize = (str) => escape(str.split(".").join("_").split("-").join("_"));
|
|
101
|
+
const TYPE_NAMES = new Set([
|
|
102
|
+
"any",
|
|
103
|
+
"bigint",
|
|
104
|
+
"boolean",
|
|
105
|
+
"never",
|
|
106
|
+
"number",
|
|
107
|
+
"object",
|
|
108
|
+
"string",
|
|
109
|
+
"symbol",
|
|
110
|
+
"undefined",
|
|
111
|
+
"unknown",
|
|
112
|
+
]);
|
|
34
113
|
const RESERVED = new Set([
|
|
114
|
+
"await",
|
|
35
115
|
"break",
|
|
36
116
|
"case",
|
|
37
117
|
"catch",
|
|
@@ -51,9 +131,12 @@ const RESERVED = new Set([
|
|
|
51
131
|
"for",
|
|
52
132
|
"function",
|
|
53
133
|
"if",
|
|
134
|
+
"implements",
|
|
54
135
|
"import",
|
|
55
136
|
"in",
|
|
56
137
|
"instanceof",
|
|
138
|
+
"interface",
|
|
139
|
+
"let",
|
|
57
140
|
"module",
|
|
58
141
|
"new",
|
|
59
142
|
"null",
|
|
@@ -62,6 +145,7 @@ const RESERVED = new Set([
|
|
|
62
145
|
"private",
|
|
63
146
|
"protected",
|
|
64
147
|
"return",
|
|
148
|
+
"static",
|
|
65
149
|
"super",
|
|
66
150
|
"switch",
|
|
67
151
|
"this",
|
|
@@ -73,6 +157,7 @@ const RESERVED = new Set([
|
|
|
73
157
|
"void",
|
|
74
158
|
"while",
|
|
75
159
|
"with",
|
|
160
|
+
"yield",
|
|
76
161
|
]);
|
|
77
162
|
const VARIABLE_REPLACERS = [
|
|
78
163
|
["`", "_backquote_"],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StringUtil.js","sourceRoot":"","sources":["../../src/utils/StringUtil.ts"],"names":[],"mappings":";;;AAAA,IAAiB,UAAU,
|
|
1
|
+
{"version":3,"file":"StringUtil.js","sourceRoot":"","sources":["../../src/utils/StringUtil.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;GAWG;AACH,IAAiB,UAAU,CAiE1B;AAjED,WAAiB,UAAU;IACzB;;;;;;;;;;;OAWG;IACU,qBAAU,GAAG,CAAC,GAAW,EAAU,EAAE,CAChD,GAAG,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAE,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;IAE9E;;;;;;;;;;OAUG;IACU,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G,EAAE,MAAM,CAAC;IACb,CAAC,GAAG,EAAE,OAAO,CAAC;IACd,CAAC,GAAG,EAAE,OAAO,CAAC;IACd,CAAC,GAAG,EAAE,SAAS,CAAC;IAChB,CAAC,GAAG,EAAE,eAAe,CAAC;IACtB,CAAC,GAAG,EAAE,eAAe,CAAC;IACtB,CAAC,GAAG,EAAE,SAAS,CAAC;IAChB,CAAC,GAAG,EAAE,YAAY,CAAC;IACnB,CAAC,GAAG,EAAE,SAAS,CAAC;IAChB,CAAC,GAAG,EAAE,aAAa,CAAC;IACpB,CAAC,KAAK,EAAE,QAAQ,CAAC;CAClB,CAAC"}
|
package/lib/utils/StringUtil.mjs
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
//#region src/utils/StringUtil.ts
|
|
2
2
|
let StringUtil;
|
|
3
3
|
(function(_StringUtil) {
|
|
4
|
-
_StringUtil.capitalize = (str) => str[0].toUpperCase() + str.slice(1).toLowerCase();
|
|
4
|
+
_StringUtil.capitalize = (str) => str.length === 0 ? str : str[0].toUpperCase() + str.slice(1).toLowerCase();
|
|
5
5
|
_StringUtil.splitWithNormalization = (path) => path.split("/").map((str) => normalize(str.trim())).filter((str) => !!str.length);
|
|
6
6
|
_StringUtil.escapeNonVariable = (str) => {
|
|
7
|
-
str =
|
|
7
|
+
str = str.trim();
|
|
8
8
|
for (const [before, after] of VARIABLE_REPLACERS) str = str.split(before).join(after);
|
|
9
|
-
for (let i = 0; i <= 9; ++i) if (str[0] === i.toString()) {
|
|
10
|
-
str = "_" + str;
|
|
11
|
-
break;
|
|
12
|
-
}
|
|
13
9
|
if (str === "") return "_empty_";
|
|
14
|
-
|
|
10
|
+
const segments = str.split(".");
|
|
11
|
+
return segments.map((segment, index) => escapeSegment(segment, index === segments.length - 1)).join(".");
|
|
15
12
|
};
|
|
16
13
|
})(StringUtil || (StringUtil = {}));
|
|
17
14
|
const escape = (str) => {
|
|
@@ -20,8 +17,28 @@ const escape = (str) => {
|
|
|
20
17
|
else if (str.length !== 0 && "0" <= str[0] && str[0] <= "9") str = `_${str}`;
|
|
21
18
|
return str;
|
|
22
19
|
};
|
|
20
|
+
const NON_IDENTIFIER_PART = /* @__PURE__ */ new RegExp("[^\\p{ID_Continue}]", "gu");
|
|
21
|
+
const IDENTIFIER_START = /* @__PURE__ */ new RegExp("^[\\p{ID_Start}_$]", "u");
|
|
22
|
+
const escapeSegment = (segment, type) => {
|
|
23
|
+
segment = segment.replace(NON_IDENTIFIER_PART, (char) => `_u${char.codePointAt(0).toString(16)}_`);
|
|
24
|
+
if (segment.length === 0) return "_empty_";
|
|
25
|
+
return RESERVED.has(segment) || type && TYPE_NAMES.has(segment) || IDENTIFIER_START.test(segment) === false ? `_${segment}` : segment;
|
|
26
|
+
};
|
|
23
27
|
const normalize = (str) => escape(str.split(".").join("_").split("-").join("_"));
|
|
28
|
+
const TYPE_NAMES = /* @__PURE__ */ new Set([
|
|
29
|
+
"any",
|
|
30
|
+
"bigint",
|
|
31
|
+
"boolean",
|
|
32
|
+
"never",
|
|
33
|
+
"number",
|
|
34
|
+
"object",
|
|
35
|
+
"string",
|
|
36
|
+
"symbol",
|
|
37
|
+
"undefined",
|
|
38
|
+
"unknown"
|
|
39
|
+
]);
|
|
24
40
|
const RESERVED = /* @__PURE__ */ new Set([
|
|
41
|
+
"await",
|
|
25
42
|
"break",
|
|
26
43
|
"case",
|
|
27
44
|
"catch",
|
|
@@ -41,9 +58,12 @@ const RESERVED = /* @__PURE__ */ new Set([
|
|
|
41
58
|
"for",
|
|
42
59
|
"function",
|
|
43
60
|
"if",
|
|
61
|
+
"implements",
|
|
44
62
|
"import",
|
|
45
63
|
"in",
|
|
46
64
|
"instanceof",
|
|
65
|
+
"interface",
|
|
66
|
+
"let",
|
|
47
67
|
"module",
|
|
48
68
|
"new",
|
|
49
69
|
"null",
|
|
@@ -52,6 +72,7 @@ const RESERVED = /* @__PURE__ */ new Set([
|
|
|
52
72
|
"private",
|
|
53
73
|
"protected",
|
|
54
74
|
"return",
|
|
75
|
+
"static",
|
|
55
76
|
"super",
|
|
56
77
|
"switch",
|
|
57
78
|
"this",
|
|
@@ -62,7 +83,8 @@ const RESERVED = /* @__PURE__ */ new Set([
|
|
|
62
83
|
"var",
|
|
63
84
|
"void",
|
|
64
85
|
"while",
|
|
65
|
-
"with"
|
|
86
|
+
"with",
|
|
87
|
+
"yield"
|
|
66
88
|
]);
|
|
67
89
|
const VARIABLE_REPLACERS = [
|
|
68
90
|
["`", "_backquote_"],
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { IHttpMigrateRoute } from "@typia/interface";
|
|
2
|
+
/**
|
|
3
|
+
* Helpers about the success status of a route.
|
|
4
|
+
*
|
|
5
|
+
* @evidence contracts/common.md#principled-implementation The namespace holds the status that the SDK should treat as success and the status that the generated NestJS controller answers.
|
|
6
|
+
* @evidence contracts/common.md#clear-and-simple-design Two functions and one private priority.
|
|
7
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts The rules follow HTTP conventions.
|
|
8
|
+
* @evidence contracts/common.md#meaningful-documentation The comment states its purpose.
|
|
9
|
+
*/
|
|
10
|
+
export declare namespace SuccessStatus {
|
|
11
|
+
/**
|
|
12
|
+
* The route's success status code, or null when the document declares only a
|
|
13
|
+
* range (`2XX`) or a `default` response.
|
|
14
|
+
*
|
|
15
|
+
* The success response is the one typia's route composer selects: 200, then
|
|
16
|
+
* 201, then the lowest other 2xx. A bodiless one, such as a 204 No Content,
|
|
17
|
+
* leaves `route.success` null, so its status is read from the responses.
|
|
18
|
+
*
|
|
19
|
+
* @evidence contracts/common.md#principled-implementation The candidates are the 2xx keys of the responses ordered by a fixed priority, and a value that is not a three-digit number is rejected.
|
|
20
|
+
* @evidence contracts/common.md#clear-and-simple-design One function with one priority helper.
|
|
21
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts The order is the HTTP convention.
|
|
22
|
+
* @evidence contracts/common.md#meaningful-documentation The comment states the selection.
|
|
23
|
+
*/
|
|
24
|
+
const of: (route: IHttpMigrateRoute) => number | null;
|
|
25
|
+
/**
|
|
26
|
+
* The status NestJS answers without `@HttpCode()`.
|
|
27
|
+
*
|
|
28
|
+
* @evidence contracts/common.md#principled-implementation NestJS answers 201 for POST and 200 for the other methods when no status is set, so a generated controller matches without an explicit one.
|
|
29
|
+
* @evidence contracts/common.md#clear-and-simple-design One expression.
|
|
30
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts The rule is NestJS's.
|
|
31
|
+
* @evidence contracts/common.md#meaningful-documentation The comment states the two statuses.
|
|
32
|
+
*/
|
|
33
|
+
const nest: (route: IHttpMigrateRoute) => number;
|
|
34
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SuccessStatus = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Helpers about the success status of a route.
|
|
6
|
+
*
|
|
7
|
+
* @evidence contracts/common.md#principled-implementation The namespace holds the status that the SDK should treat as success and the status that the generated NestJS controller answers.
|
|
8
|
+
* @evidence contracts/common.md#clear-and-simple-design Two functions and one private priority.
|
|
9
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts The rules follow HTTP conventions.
|
|
10
|
+
* @evidence contracts/common.md#meaningful-documentation The comment states its purpose.
|
|
11
|
+
*/
|
|
12
|
+
var SuccessStatus;
|
|
13
|
+
(function (SuccessStatus) {
|
|
14
|
+
/**
|
|
15
|
+
* The route's success status code, or null when the document declares only a
|
|
16
|
+
* range (`2XX`) or a `default` response.
|
|
17
|
+
*
|
|
18
|
+
* The success response is the one typia's route composer selects: 200, then
|
|
19
|
+
* 201, then the lowest other 2xx. A bodiless one, such as a 204 No Content,
|
|
20
|
+
* leaves `route.success` null, so its status is read from the responses.
|
|
21
|
+
*
|
|
22
|
+
* @evidence contracts/common.md#principled-implementation The candidates are the 2xx keys of the responses ordered by a fixed priority, and a value that is not a three-digit number is rejected.
|
|
23
|
+
* @evidence contracts/common.md#clear-and-simple-design One function with one priority helper.
|
|
24
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts The order is the HTTP convention.
|
|
25
|
+
* @evidence contracts/common.md#meaningful-documentation The comment states the selection.
|
|
26
|
+
*/
|
|
27
|
+
SuccessStatus.of = (route) => {
|
|
28
|
+
var _a;
|
|
29
|
+
var _b, _c;
|
|
30
|
+
const status = (_b = (_a = route.success) === null || _a === void 0 ? void 0 : _a.status) !== null && _b !== void 0 ? _b : Object.keys((_c = route.operation().responses) !== null && _c !== void 0 ? _c : {})
|
|
31
|
+
.filter((key) => /^2\d\d$/.test(key))
|
|
32
|
+
.sort((x, y) => priority(x) - priority(y))[0];
|
|
33
|
+
return status !== undefined && /^\d{3}$/.test(status)
|
|
34
|
+
? Number(status)
|
|
35
|
+
: null;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* The status NestJS answers without `@HttpCode()`.
|
|
39
|
+
*
|
|
40
|
+
* @evidence contracts/common.md#principled-implementation NestJS answers 201 for POST and 200 for the other methods when no status is set, so a generated controller matches without an explicit one.
|
|
41
|
+
* @evidence contracts/common.md#clear-and-simple-design One expression.
|
|
42
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts The rule is NestJS's.
|
|
43
|
+
* @evidence contracts/common.md#meaningful-documentation The comment states the two statuses.
|
|
44
|
+
*/
|
|
45
|
+
SuccessStatus.nest = (route) => route.method === "post" ? 201 : 200;
|
|
46
|
+
const priority = (status) => status === "200" ? 0 : status === "201" ? 1 : Number(status);
|
|
47
|
+
})(SuccessStatus || (exports.SuccessStatus = SuccessStatus = {}));
|
|
48
|
+
//# sourceMappingURL=SuccessStatus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SuccessStatus.js","sourceRoot":"","sources":["../../src/utils/SuccessStatus.ts"],"names":[],"mappings":";;;AAEA;;;;;;;GAOG;AACH,IAAiB,aAAa,CAsC7B;AAtCD,WAAiB,aAAa;IAC5B;;;;;;;;;;;;OAYG;IACU,gBAAE,GAAG,CAAC,KAAwB,EAAiB,EAAE;;;QAC5D,MAAM,MAAM,SACV,MAAA,KAAK,CAAC,OAAO,0CAAE,MAAM,mCACrB,MAAM,CAAC,IAAI,OAAC,KAAK,CAAC,SAAS,EAAE,CAAC,SAAS,mCAAI,EAAE,CAAC;aAC3C,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;aACpC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAClD,OAAO,MAAM,KAAK,SAAS,IAAI,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC;YACnD,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC;YAChB,CAAC,CAAC,IAAI,CAAC;IACX,CAAC,CAAC;IAEF;;;;;;;OAOG;IACU,kBAAI,GAAG,CAAC,KAAwB,EAAU,EAAE,CACvD,KAAK,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;IAEtC,MAAM,QAAQ,GAAG,CAAC,MAAc,EAAU,EAAE,CAC1C,MAAM,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AACjE,CAAC,EAtCgB,aAAa,aAAb,aAAa,GAAb,aAAa,QAsC7B"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/utils/SuccessStatus.ts
|
|
2
|
+
let SuccessStatus;
|
|
3
|
+
(function(_SuccessStatus) {
|
|
4
|
+
_SuccessStatus.of = (route) => {
|
|
5
|
+
const status = route.success?.status ?? Object.keys(route.operation().responses ?? {}).filter((key) => /^2\d\d$/.test(key)).sort((x, y) => priority(x) - priority(y))[0];
|
|
6
|
+
return status !== void 0 && /^\d{3}$/.test(status) ? Number(status) : null;
|
|
7
|
+
};
|
|
8
|
+
_SuccessStatus.nest = (route) => route.method === "post" ? 201 : 200;
|
|
9
|
+
const priority = (status) => status === "200" ? 0 : status === "201" ? 1 : Number(status);
|
|
10
|
+
})(SuccessStatus || (SuccessStatus = {}));
|
|
11
|
+
//#endregion
|
|
12
|
+
export { SuccessStatus };
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=SuccessStatus.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SuccessStatus.mjs","names":[],"sources":[],"mappings":""}
|