typia 4.1.6-dev.20230213 → 4.1.7-dev.20230715

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.
Files changed (37) hide show
  1. package/lib/factories/MetadataCollection.js +1 -0
  2. package/lib/factories/MetadataCollection.js.map +1 -1
  3. package/lib/factories/internal/metadata/{emplace_metadata_definition.d.ts → emplace_metadata_alias.d.ts} +1 -1
  4. package/lib/factories/internal/metadata/{emplace_metadata_definition.js → emplace_metadata_alias.js} +17 -5
  5. package/lib/factories/internal/metadata/emplace_metadata_alias.js.map +1 -0
  6. package/lib/factories/internal/metadata/iterate_metadata_alias.js +2 -2
  7. package/lib/factories/internal/metadata/iterate_metadata_alias.js.map +1 -1
  8. package/lib/factories/internal/metadata/iterate_metadata_collection.js +4 -4
  9. package/lib/factories/internal/metadata/iterate_metadata_collection.js.map +1 -1
  10. package/lib/metadata/IMetadataAlias.d.ts +3 -1
  11. package/lib/metadata/MetadataAlias.d.ts +2 -0
  12. package/lib/metadata/MetadataAlias.js +4 -1
  13. package/lib/metadata/MetadataAlias.js.map +1 -1
  14. package/lib/programmers/LiteralsProgrammer.js +3 -2
  15. package/lib/programmers/LiteralsProgrammer.js.map +1 -1
  16. package/lib/programmers/internal/application_alias.js +21 -3
  17. package/lib/programmers/internal/application_alias.js.map +1 -1
  18. package/lib/programmers/internal/application_object.js +1 -1
  19. package/lib/programmers/internal/application_object.js.map +1 -1
  20. package/package.json +1 -1
  21. package/src/factories/MetadataCollection.ts +1 -0
  22. package/src/factories/MetadataTagFactory.ts +355 -355
  23. package/src/factories/internal/metadata/{emplace_metadata_definition.ts → emplace_metadata_alias.ts} +7 -2
  24. package/src/factories/internal/metadata/iterate_metadata_alias.ts +4 -4
  25. package/src/factories/internal/metadata/iterate_metadata_collection.ts +4 -4
  26. package/src/metadata/IMetadataAlias.ts +3 -1
  27. package/src/metadata/IMetadataTag.ts +105 -105
  28. package/src/metadata/Metadata.ts +603 -603
  29. package/src/metadata/MetadataAlias.ts +6 -1
  30. package/src/module.ts +2038 -2038
  31. package/src/programmers/LiteralsProgrammer.ts +63 -62
  32. package/src/programmers/internal/application_alias.ts +22 -1
  33. package/src/programmers/internal/application_number.ts +74 -74
  34. package/src/programmers/internal/application_object.ts +1 -1
  35. package/src/transformers/CallExpressionTransformer.ts +179 -179
  36. package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +104 -104
  37. package/lib/factories/internal/metadata/emplace_metadata_definition.js.map +0 -1
@@ -1,62 +1,63 @@
1
- import ts from "typescript";
2
-
3
- import { MetadataCollection } from "../factories/MetadataCollection";
4
- import { MetadataFactory } from "../factories/MetadataFactory";
5
-
6
- import { Metadata } from "../metadata/Metadata";
7
-
8
- import { IProject } from "../transformers/IProject";
9
-
10
- import { Atomic } from "../typings/Atomic";
11
-
12
- import { ArrayUtil } from "../utils/ArrayUtil";
13
-
14
- export namespace LiteralsProgrammer {
15
- export const write = (project: IProject) => (type: ts.Type) => {
16
- const meta: Metadata = MetadataFactory.analyze(project.checker)({
17
- resolve: true,
18
- constant: true,
19
- absorb: true,
20
- validate: (meta) => {
21
- const length: number =
22
- meta.constants
23
- .map((c) => c.values.length)
24
- .reduce((a, b) => a + b, 0) +
25
- meta.atomics.filter((type) => type === "boolean").length;
26
- if (0 === length) throw new Error(ErrorMessages.NO);
27
- else if (meta.size() !== length)
28
- throw new Error(ErrorMessages.ONLY);
29
- },
30
- })(new MetadataCollection())(type);
31
- const values: Set<Atomic.Type | null> = new Set([
32
- ...ArrayUtil.flat<Atomic.Type>(meta.constants.map((c) => c.values)),
33
- ...(meta.atomics.filter((type) => type === "boolean").length
34
- ? [true, false]
35
- : []),
36
- ...meta.nullable ? [null] : []
37
- ]);
38
- return ts.factory.createAsExpression(
39
- ts.factory.createArrayLiteralExpression(
40
- [...values].map((v) =>
41
- v === null ? ts.factory.createNull()
42
- : typeof v === "boolean"
43
- ? v
44
- ? ts.factory.createTrue()
45
- : ts.factory.createFalse()
46
- : typeof v === "number"
47
- ? ts.factory.createNumericLiteral(v)
48
- : typeof v === "bigint"
49
- ? ts.factory.createBigIntLiteral(v.toString())
50
- : ts.factory.createStringLiteral(v),
51
- ),
52
- true,
53
- ),
54
- ts.factory.createTypeReferenceNode("const"),
55
- );
56
- };
57
- }
58
-
59
- enum ErrorMessages {
60
- NO = "Error on typia.literals(): no literal type found.",
61
- ONLY = "Error on typia.literals(): only literal type allowed.",
62
- }
1
+ import ts from "typescript";
2
+
3
+ import { MetadataCollection } from "../factories/MetadataCollection";
4
+ import { MetadataFactory } from "../factories/MetadataFactory";
5
+
6
+ import { Metadata } from "../metadata/Metadata";
7
+
8
+ import { IProject } from "../transformers/IProject";
9
+
10
+ import { Atomic } from "../typings/Atomic";
11
+
12
+ import { ArrayUtil } from "../utils/ArrayUtil";
13
+
14
+ export namespace LiteralsProgrammer {
15
+ export const write = (project: IProject) => (type: ts.Type) => {
16
+ const meta: Metadata = MetadataFactory.analyze(project.checker)({
17
+ resolve: true,
18
+ constant: true,
19
+ absorb: true,
20
+ validate: (meta) => {
21
+ const length: number =
22
+ meta.constants
23
+ .map((c) => c.values.length)
24
+ .reduce((a, b) => a + b, 0) +
25
+ meta.atomics.filter((type) => type === "boolean").length;
26
+ if (0 === length) throw new Error(ErrorMessages.NO);
27
+ else if (meta.size() !== length)
28
+ throw new Error(ErrorMessages.ONLY);
29
+ },
30
+ })(new MetadataCollection())(type);
31
+ const values: Set<Atomic.Type | null> = new Set([
32
+ ...ArrayUtil.flat<Atomic.Type>(meta.constants.map((c) => c.values)),
33
+ ...(meta.atomics.filter((type) => type === "boolean").length
34
+ ? [true, false]
35
+ : []),
36
+ ...(meta.nullable ? [null] : []),
37
+ ]);
38
+ return ts.factory.createAsExpression(
39
+ ts.factory.createArrayLiteralExpression(
40
+ [...values].map((v) =>
41
+ v === null
42
+ ? ts.factory.createNull()
43
+ : typeof v === "boolean"
44
+ ? v
45
+ ? ts.factory.createTrue()
46
+ : ts.factory.createFalse()
47
+ : typeof v === "number"
48
+ ? ts.factory.createNumericLiteral(v)
49
+ : typeof v === "bigint"
50
+ ? ts.factory.createBigIntLiteral(v.toString())
51
+ : ts.factory.createStringLiteral(v),
52
+ ),
53
+ true,
54
+ ),
55
+ ts.factory.createTypeReferenceNode("const"),
56
+ );
57
+ };
58
+ }
59
+
60
+ enum ErrorMessages {
61
+ NO = "Error on typia.literals(): no literal type found.",
62
+ ONLY = "Error on typia.literals(): only literal type allowed.",
63
+ }
@@ -1,3 +1,6 @@
1
+ import { CommentFactory } from "../../factories/CommentFactory";
2
+
3
+ import { IJsDocTagInfo } from "../../metadata/IJsDocTagInfo";
1
4
  import { MetadataAlias } from "../../metadata/MetadataAlias";
2
5
  import { IJsonComponents } from "../../schemas/IJsonComponents";
3
6
 
@@ -34,7 +37,25 @@ export const application_alias =
34
37
  // GENERATE SCHEM
35
38
  const schema: IJsonSchema = application_schema(options)(blockNever)(
36
39
  components,
37
- )(alias.value)({})!;
40
+ )(alias.value)({
41
+ deprecated:
42
+ alias.jsDocTags.some((tag) => tag.name === "deprecated") ||
43
+ undefined,
44
+ title: (() => {
45
+ const info: IJsDocTagInfo | undefined =
46
+ alias.jsDocTags.find((tag) => tag.name === "title");
47
+ return info?.text?.length
48
+ ? CommentFactory.merge(info.text)
49
+ : undefined;
50
+ })(),
51
+ description: alias.description ?? undefined,
52
+ "x-typia-metaTags": alias.tags.length ? alias.tags : undefined,
53
+ "x-typia-jsDocTags": alias.jsDocTags.length
54
+ ? alias.jsDocTags
55
+ : undefined,
56
+ "x-typia-required": alias.value.required,
57
+ "x-typia-optional": alias.value.optional,
58
+ })!;
38
59
  components.schemas ??= {};
39
60
  components.schemas[key] = {
40
61
  $id: options.purpose === "ajv" ? $id : undefined,
@@ -1,74 +1,74 @@
1
- import { IJsonSchema } from "../../module";
2
- import { application_default } from "./application_default";
3
-
4
- /**
5
- * @internal
6
- */
7
- export const application_number = (
8
- attribute: IJsonSchema.IAttribute,
9
- ): IJsonSchema.INumber | IJsonSchema.IInteger => {
10
- const output: IJsonSchema.INumber | IJsonSchema.IInteger = {
11
- ...attribute,
12
- type: "number" as "number" | "integer",
13
- };
14
- for (const tag of attribute["x-typia-metaTags"] ?? []) {
15
- // CHECK TYPE
16
- if (
17
- tag.kind === "type" &&
18
- (tag.value === "int" ||
19
- tag.value === "uint" ||
20
- tag.value === "{int}" ||
21
- tag.value === "{uint}")
22
- )
23
- output.type = "integer";
24
- // RANGE TAG
25
- else if (tag.kind === "minimum") output.minimum = tag.value;
26
- else if (tag.kind === "maximum") output.maximum = tag.value;
27
- else if (tag.kind === "exclusiveMinimum") {
28
- output.minimum = tag.value;
29
- output.exclusiveMinimum = true;
30
- } else if (tag.kind === "exclusiveMaximum") {
31
- output.maximum = tag.value;
32
- output.exclusiveMaximum = true;
33
- }
34
- // MULTIPLE-OF
35
- else if (tag.kind === "multipleOf") output.multipleOf = tag.value;
36
- }
37
-
38
- // WHEN UNSIGNED INT
39
- if (
40
- output.type === "integer" &&
41
- (attribute["x-typia-metaTags"] ?? []).find(
42
- (tag) => tag.kind === "type" && tag.value === "uint",
43
- )
44
- )
45
- if (
46
- output.minimum === undefined ||
47
- (output.exclusiveMaximum !== true && output.minimum < 0)
48
- )
49
- output.minimum = 0;
50
- else if (output.exclusiveMinimum === true && output.minimum < -1) {
51
- output.maximum = 0;
52
- delete output.exclusiveMinimum;
53
- }
54
-
55
- // DEFAULT CONFIGURATION
56
- output.default = application_default(attribute)((str) => {
57
- const value: number = Number(str);
58
- const conditions: boolean[] = [!Number.isNaN(value)];
59
- if (output.minimum !== undefined)
60
- if (output.exclusiveMinimum === true)
61
- conditions.push(value > output.minimum);
62
- else conditions.push(value >= output.minimum);
63
- if (output.maximum !== undefined)
64
- if (output.exclusiveMaximum === true)
65
- conditions.push(value < output.maximum);
66
- else conditions.push(value <= output.maximum);
67
- if (output.multipleOf !== undefined)
68
- conditions.push(value % output.multipleOf === 0);
69
- return conditions.every((cond) => cond);
70
- })((str) => Number(str));
71
-
72
- // RETURNS
73
- return output;
74
- };
1
+ import { IJsonSchema } from "../../module";
2
+ import { application_default } from "./application_default";
3
+
4
+ /**
5
+ * @internal
6
+ */
7
+ export const application_number = (
8
+ attribute: IJsonSchema.IAttribute,
9
+ ): IJsonSchema.INumber | IJsonSchema.IInteger => {
10
+ const output: IJsonSchema.INumber | IJsonSchema.IInteger = {
11
+ ...attribute,
12
+ type: "number" as "number" | "integer",
13
+ };
14
+ for (const tag of attribute["x-typia-metaTags"] ?? []) {
15
+ // CHECK TYPE
16
+ if (
17
+ tag.kind === "type" &&
18
+ (tag.value === "int" ||
19
+ tag.value === "uint" ||
20
+ tag.value === "{int}" ||
21
+ tag.value === "{uint}")
22
+ )
23
+ output.type = "integer";
24
+ // RANGE TAG
25
+ else if (tag.kind === "minimum") output.minimum = tag.value;
26
+ else if (tag.kind === "maximum") output.maximum = tag.value;
27
+ else if (tag.kind === "exclusiveMinimum") {
28
+ output.minimum = tag.value;
29
+ output.exclusiveMinimum = true;
30
+ } else if (tag.kind === "exclusiveMaximum") {
31
+ output.maximum = tag.value;
32
+ output.exclusiveMaximum = true;
33
+ }
34
+ // MULTIPLE-OF
35
+ else if (tag.kind === "multipleOf") output.multipleOf = tag.value;
36
+ }
37
+
38
+ // WHEN UNSIGNED INT
39
+ if (
40
+ output.type === "integer" &&
41
+ (attribute["x-typia-metaTags"] ?? []).find(
42
+ (tag) => tag.kind === "type" && tag.value === "uint",
43
+ )
44
+ )
45
+ if (
46
+ output.minimum === undefined ||
47
+ (output.exclusiveMaximum !== true && output.minimum < 0)
48
+ )
49
+ output.minimum = 0;
50
+ else if (output.exclusiveMinimum === true && output.minimum < -1) {
51
+ output.maximum = 0;
52
+ delete output.exclusiveMinimum;
53
+ }
54
+
55
+ // DEFAULT CONFIGURATION
56
+ output.default = application_default(attribute)((str) => {
57
+ const value: number = Number(str);
58
+ const conditions: boolean[] = [!Number.isNaN(value)];
59
+ if (output.minimum !== undefined)
60
+ if (output.exclusiveMinimum === true)
61
+ conditions.push(value > output.minimum);
62
+ else conditions.push(value >= output.minimum);
63
+ if (output.maximum !== undefined)
64
+ if (output.exclusiveMaximum === true)
65
+ conditions.push(value < output.maximum);
66
+ else conditions.push(value <= output.maximum);
67
+ if (output.multipleOf !== undefined)
68
+ conditions.push(value % output.multipleOf === 0);
69
+ return conditions.every((cond) => cond);
70
+ })((str) => Number(str));
71
+
72
+ // RETURNS
73
+ return output;
74
+ };
@@ -55,7 +55,7 @@ export const application_object =
55
55
  true,
56
56
  )(components)(property.value)({
57
57
  deprecated:
58
- !!property.jsDocTags.find(
58
+ property.jsDocTags.some(
59
59
  (tag) => tag.name === "deprecated",
60
60
  ) || undefined,
61
61
  title: (() => {