typia 4.0.3 → 4.0.4-dev.20230609
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/transform.js
CHANGED
|
@@ -7,6 +7,12 @@ exports.transform = void 0;
|
|
|
7
7
|
var typescript_1 = __importDefault(require("typescript"));
|
|
8
8
|
var FileTransformer_1 = require("./transformers/FileTransformer");
|
|
9
9
|
var transform = function (program, options) {
|
|
10
|
+
var compilerOptions = program.getCompilerOptions();
|
|
11
|
+
var strict = compilerOptions.strictNullChecks !== undefined
|
|
12
|
+
? !!compilerOptions.strictNullChecks
|
|
13
|
+
: !!compilerOptions.strict;
|
|
14
|
+
if (strict === false)
|
|
15
|
+
throw new Error("Error on \"tsconfig.json\": typia requires `strictNullChecks` or `strict` to be true.");
|
|
10
16
|
return FileTransformer_1.FileTransformer.transform({
|
|
11
17
|
program: program,
|
|
12
18
|
compilerOptions: program.getCompilerOptions(),
|
package/lib/transform.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.js","sourceRoot":"","sources":["../src/transform.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA4B;AAE5B,kEAAiE;AAG1D,IAAM,SAAS,GAAG,UACrB,OAAmB,EACnB,OAA2B;IAE3B,
|
|
1
|
+
{"version":3,"file":"transform.js","sourceRoot":"","sources":["../src/transform.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA4B;AAE5B,kEAAiE;AAG1D,IAAM,SAAS,GAAG,UACrB,OAAmB,EACnB,OAA2B;IAE3B,IAAM,eAAe,GAAuB,OAAO,CAAC,kBAAkB,EAAE,CAAC;IACzE,IAAM,MAAM,GACR,eAAe,CAAC,gBAAgB,KAAK,SAAS;QAC1C,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,gBAAgB;QACpC,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,MAAM,CAAC;IACnC,IAAI,MAAM,KAAK,KAAK;QAChB,MAAM,IAAI,KAAK,CACX,uFAAyF,CAC5F,CAAC;IAEN,OAAO,iCAAe,CAAC,SAAS,CAAC;QAC7B,OAAO,SAAA;QACP,eAAe,EAAE,OAAO,CAAC,kBAAkB,EAAE;QAC7C,OAAO,EAAE,OAAO,CAAC,cAAc,EAAE;QACjC,OAAO,EAAE,oBAAE,CAAC,aAAa,EAAE;QAC3B,OAAO,EAAE,OAAO,IAAI,EAAE;KACzB,CAAC,CAAC;AACP,CAAC,CAAC;AArBW,QAAA,SAAS,aAqBpB;AACF,kBAAe,iBAAS,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
import { MetadataAlias } from "../../metadata/MetadataAlias";
|
|
2
|
-
import { IJsonComponents } from "../../schemas/IJsonComponents";
|
|
3
|
-
|
|
4
|
-
import { IJsonSchema } from "../../module";
|
|
5
|
-
import { ApplicationProgrammer } from "../ApplicationProgrammer";
|
|
6
|
-
import { JSON_COMPONENTS_PREFIX } from "./JSON_SCHEMA_PREFIX";
|
|
7
|
-
import { application_object } from "./application_object";
|
|
8
|
-
import { application_schema } from "./application_schema";
|
|
9
|
-
|
|
10
|
-
export const application_alias =
|
|
11
|
-
(options: ApplicationProgrammer.IOptions) =>
|
|
12
|
-
<BlockNever extends boolean>(blockNever: BlockNever) =>
|
|
13
|
-
(components: IJsonComponents) =>
|
|
14
|
-
(alias: MetadataAlias) =>
|
|
15
|
-
(
|
|
16
|
-
nullable: boolean,
|
|
17
|
-
): IJsonSchema.IReference | IJsonSchema.IRecursiveReference => {
|
|
18
|
-
if (alias.value.size() === 1 && alias.value.objects.length === 1)
|
|
19
|
-
return application_object(options)(components)(
|
|
20
|
-
alias.value.objects[0]!,
|
|
21
|
-
)(nullable);
|
|
22
|
-
|
|
23
|
-
const key: string =
|
|
24
|
-
options.purpose === "ajv"
|
|
25
|
-
? alias.name
|
|
26
|
-
: `${alias.name}${nullable ? ".Nullable" : ""}`;
|
|
27
|
-
const $id: string = `${JSON_COMPONENTS_PREFIX}/schemas/${key}`;
|
|
28
|
-
|
|
29
|
-
// TEMPORARY ASSIGNMENT
|
|
30
|
-
if (components.schemas?.[key] === undefined) {
|
|
31
|
-
components.schemas ??= {};
|
|
32
|
-
components.schemas[key] = {
|
|
33
|
-
$id: key,
|
|
34
|
-
} as any;
|
|
35
|
-
|
|
36
|
-
// GENERATE SCHEM
|
|
37
|
-
const schema: IJsonSchema = application_schema(options)(blockNever)(
|
|
38
|
-
components,
|
|
39
|
-
)(alias.value)({})!;
|
|
40
|
-
components.schemas ??= {};
|
|
41
|
-
components.schemas[key] = {
|
|
42
|
-
$id: options.purpose === "ajv" ? $id : undefined,
|
|
43
|
-
$recursiveAnchor:
|
|
44
|
-
(options.purpose === "ajv" && alias.recursive) || undefined,
|
|
45
|
-
...schema,
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
return options.purpose === "ajv" && alias.recursive
|
|
49
|
-
? { $recursiveRef: $id }
|
|
50
|
-
: { $ref: $id };
|
|
51
|
-
};
|
|
1
|
+
import { MetadataAlias } from "../../metadata/MetadataAlias";
|
|
2
|
+
import { IJsonComponents } from "../../schemas/IJsonComponents";
|
|
3
|
+
|
|
4
|
+
import { IJsonSchema } from "../../module";
|
|
5
|
+
import { ApplicationProgrammer } from "../ApplicationProgrammer";
|
|
6
|
+
import { JSON_COMPONENTS_PREFIX } from "./JSON_SCHEMA_PREFIX";
|
|
7
|
+
import { application_object } from "./application_object";
|
|
8
|
+
import { application_schema } from "./application_schema";
|
|
9
|
+
|
|
10
|
+
export const application_alias =
|
|
11
|
+
(options: ApplicationProgrammer.IOptions) =>
|
|
12
|
+
<BlockNever extends boolean>(blockNever: BlockNever) =>
|
|
13
|
+
(components: IJsonComponents) =>
|
|
14
|
+
(alias: MetadataAlias) =>
|
|
15
|
+
(
|
|
16
|
+
nullable: boolean,
|
|
17
|
+
): IJsonSchema.IReference | IJsonSchema.IRecursiveReference => {
|
|
18
|
+
if (alias.value.size() === 1 && alias.value.objects.length === 1)
|
|
19
|
+
return application_object(options)(components)(
|
|
20
|
+
alias.value.objects[0]!,
|
|
21
|
+
)(nullable);
|
|
22
|
+
|
|
23
|
+
const key: string =
|
|
24
|
+
options.purpose === "ajv"
|
|
25
|
+
? alias.name
|
|
26
|
+
: `${alias.name}${nullable ? ".Nullable" : ""}`;
|
|
27
|
+
const $id: string = `${JSON_COMPONENTS_PREFIX}/schemas/${key}`;
|
|
28
|
+
|
|
29
|
+
// TEMPORARY ASSIGNMENT
|
|
30
|
+
if (components.schemas?.[key] === undefined) {
|
|
31
|
+
components.schemas ??= {};
|
|
32
|
+
components.schemas[key] = {
|
|
33
|
+
$id: key,
|
|
34
|
+
} as any;
|
|
35
|
+
|
|
36
|
+
// GENERATE SCHEM
|
|
37
|
+
const schema: IJsonSchema = application_schema(options)(blockNever)(
|
|
38
|
+
components,
|
|
39
|
+
)(alias.value)({})!;
|
|
40
|
+
components.schemas ??= {};
|
|
41
|
+
components.schemas[key] = {
|
|
42
|
+
$id: options.purpose === "ajv" ? $id : undefined,
|
|
43
|
+
$recursiveAnchor:
|
|
44
|
+
(options.purpose === "ajv" && alias.recursive) || undefined,
|
|
45
|
+
...schema,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
return options.purpose === "ajv" && alias.recursive
|
|
49
|
+
? { $recursiveRef: $id }
|
|
50
|
+
: { $ref: $id };
|
|
51
|
+
};
|
package/src/transform.ts
CHANGED
|
@@ -6,12 +6,23 @@ import { ITransformOptions } from "./transformers/ITransformOptions";
|
|
|
6
6
|
export const transform = (
|
|
7
7
|
program: ts.Program,
|
|
8
8
|
options?: ITransformOptions,
|
|
9
|
-
): ts.TransformerFactory<ts.SourceFile> =>
|
|
10
|
-
|
|
9
|
+
): ts.TransformerFactory<ts.SourceFile> => {
|
|
10
|
+
const compilerOptions: ts.CompilerOptions = program.getCompilerOptions();
|
|
11
|
+
const strict: boolean =
|
|
12
|
+
compilerOptions.strictNullChecks !== undefined
|
|
13
|
+
? !!compilerOptions.strictNullChecks
|
|
14
|
+
: !!compilerOptions.strict;
|
|
15
|
+
if (strict === false)
|
|
16
|
+
throw new Error(
|
|
17
|
+
`Error on "tsconfig.json": typia requires \`strictNullChecks\` or \`strict\` to be true.`,
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
return FileTransformer.transform({
|
|
11
21
|
program,
|
|
12
22
|
compilerOptions: program.getCompilerOptions(),
|
|
13
23
|
checker: program.getTypeChecker(),
|
|
14
24
|
printer: ts.createPrinter(),
|
|
15
25
|
options: options || {},
|
|
16
26
|
});
|
|
27
|
+
};
|
|
17
28
|
export default transform;
|