typia 4.0.0 → 4.0.1-dev.20230604

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 (87) hide show
  1. package/lib/programmers/ApplicationProgrammer.js +1 -1
  2. package/lib/programmers/internal/application_array.js +19 -41
  3. package/lib/programmers/internal/application_array.js.map +1 -1
  4. package/lib/programmers/internal/application_definition.d.ts +1 -1
  5. package/lib/programmers/internal/application_definition.js +8 -8
  6. package/lib/programmers/internal/application_definition.js.map +1 -1
  7. package/lib/programmers/internal/application_native.js +3 -3
  8. package/lib/programmers/internal/application_object.js +4 -4
  9. package/lib/programmers/internal/application_schema.js +3 -3
  10. package/lib/programmers/internal/application_schema.js.map +1 -1
  11. package/lib/programmers/internal/application_tuple.js +8 -30
  12. package/lib/programmers/internal/application_tuple.js.map +1 -1
  13. package/lib/schemas/IJsonComponents.d.ts +1 -12
  14. package/lib/schemas/IJsonSchema.d.ts +1 -1
  15. package/package.json +1 -1
  16. package/src/IRandomGenerator.ts +34 -34
  17. package/src/factories/IdentifierFactory.ts +65 -65
  18. package/src/factories/MetadataCollection.ts +254 -254
  19. package/src/factories/MetadataFactory.ts +40 -40
  20. package/src/factories/MetadataTagFactory.ts +300 -300
  21. package/src/factories/internal/metadata/emplace_metadata_array.ts +34 -34
  22. package/src/factories/internal/metadata/emplace_metadata_definition.ts +35 -35
  23. package/src/factories/internal/metadata/emplace_metadata_object.ts +142 -142
  24. package/src/factories/internal/metadata/emplace_metadata_tuple.ts +50 -50
  25. package/src/factories/internal/metadata/explore_metadata.ts +66 -66
  26. package/src/factories/internal/metadata/iterate_metadata.ts +77 -77
  27. package/src/factories/internal/metadata/iterate_metadata_array.ts +25 -25
  28. package/src/factories/internal/metadata/iterate_metadata_collection.ts +130 -130
  29. package/src/factories/internal/metadata/iterate_metadata_definition.ts +30 -30
  30. package/src/factories/internal/metadata/iterate_metadata_object.ts +49 -49
  31. package/src/factories/internal/metadata/iterate_metadata_sort.ts +68 -68
  32. package/src/factories/internal/metadata/iterate_metadata_tuple.ts +24 -24
  33. package/src/factories/internal/metadata/iterate_metadata_union.ts +68 -68
  34. package/src/metadata/IMetadata.ts +27 -27
  35. package/src/metadata/IMetadataAlias.ts +12 -12
  36. package/src/metadata/IMetadataApplication.ts +7 -7
  37. package/src/metadata/IMetadataArray.ts +10 -10
  38. package/src/metadata/IMetadataCollection.ts +11 -11
  39. package/src/metadata/IMetadataDictionary.ts +14 -14
  40. package/src/metadata/IMetadataObject.ts +18 -18
  41. package/src/metadata/IMetadataProperty.ts +11 -11
  42. package/src/metadata/IMetadataTuple.ts +10 -10
  43. package/src/metadata/Metadata.ts +585 -585
  44. package/src/metadata/MetadataAlias.ts +61 -61
  45. package/src/metadata/MetadataArray.ts +52 -52
  46. package/src/metadata/MetadataObject.ts +114 -114
  47. package/src/metadata/MetadataProperty.ts +64 -64
  48. package/src/metadata/MetadataTuple.ts +53 -53
  49. package/src/programmers/ApplicationProgrammer.ts +55 -55
  50. package/src/programmers/AssertProgrammer.ts +291 -291
  51. package/src/programmers/CheckerProgrammer.ts +1182 -1182
  52. package/src/programmers/CloneProgrammer.ts +595 -595
  53. package/src/programmers/FeatureProgrammer.ts +495 -495
  54. package/src/programmers/IsProgrammer.ts +250 -250
  55. package/src/programmers/LiteralsProgrammer.ts +66 -66
  56. package/src/programmers/PruneProgrammer.ts +550 -550
  57. package/src/programmers/RandomProgrammer.ts +589 -589
  58. package/src/programmers/StringifyProgrammer.ts +990 -990
  59. package/src/programmers/ValidateProgrammer.ts +313 -313
  60. package/src/programmers/helpers/FunctionImporeter.ts +78 -78
  61. package/src/programmers/helpers/RandomJoiner.ts +173 -173
  62. package/src/programmers/helpers/UnionExplorer.ts +301 -301
  63. package/src/programmers/helpers/UnionPredicator.ts +81 -81
  64. package/src/programmers/helpers/disable_function_importer_declare.ts +26 -26
  65. package/src/programmers/internal/JSON_SCHEMA_PREFIX.ts +1 -1
  66. package/src/programmers/internal/application_array.ts +30 -64
  67. package/src/programmers/internal/application_boolean.ts +15 -15
  68. package/src/programmers/internal/application_constant.ts +26 -26
  69. package/src/programmers/internal/application_default.ts +17 -17
  70. package/src/programmers/internal/application_definition.ts +45 -45
  71. package/src/programmers/internal/application_native.ts +39 -39
  72. package/src/programmers/internal/application_number.ts +74 -74
  73. package/src/programmers/internal/application_object.ts +167 -167
  74. package/src/programmers/internal/application_schema.ts +156 -164
  75. package/src/programmers/internal/application_tuple.ts +47 -77
  76. package/src/programmers/internal/check_union_array_like.ts +329 -329
  77. package/src/programmers/internal/feature_object_entries.ts +63 -63
  78. package/src/programmers/internal/wrap_metadata_rest_tuple.ts +16 -16
  79. package/src/schemas/IJsonApplication.ts +8 -8
  80. package/src/schemas/IJsonComponents.ts +34 -45
  81. package/src/schemas/IJsonSchema.ts +134 -134
  82. package/src/transformers/CallExpressionTransformer.ts +179 -179
  83. package/src/transformers/FileTransformer.ts +47 -47
  84. package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +104 -104
  85. package/src/transformers/features/miscellaneous/MetadataTransformer.ts +53 -53
  86. package/src/utils/ArrayUtil.ts +45 -45
  87. package/src/utils/RandomGenerator.ts +81 -81
@@ -1,164 +1,156 @@
1
- import { Metadata } from "../../metadata/Metadata";
2
- import { IJsonComponents } from "../../schemas/IJsonComponents";
3
- import { IJsonSchema } from "../../schemas/IJsonSchema";
4
-
5
- import { ApplicationProgrammer } from "../ApplicationProgrammer";
6
- import { AtomicPredicator } from "../helpers/AtomicPredicator";
7
- import { application_array } from "./application_array";
8
- import { application_boolean } from "./application_boolean";
9
- import { application_constant } from "./application_constant";
10
- import { application_definition } from "./application_definition";
11
- import { application_native } from "./application_native";
12
- import { application_number } from "./application_number";
13
- import { application_object } from "./application_object";
14
- import { application_string } from "./application_string";
15
- import { application_templates } from "./application_templates";
16
- import { application_tuple } from "./application_tuple";
17
-
18
- /**
19
- * @internal
20
- */
21
- export const application_schema =
22
- (options: ApplicationProgrammer.IOptions) =>
23
- <BlockNever extends boolean>(blockNever: BlockNever) =>
24
- (components: IJsonComponents) =>
25
- (meta: Metadata) =>
26
- (
27
- attribute: IJsonSchema.IAttribute,
28
- ): BlockNever extends true ? IJsonSchema | null : IJsonSchema => {
29
- // VULNERABLE CASE
30
- if (meta.any === true)
31
- return {
32
- ...attribute,
33
- type: undefined,
34
- };
35
- else if (meta.nullable && meta.empty())
36
- return { type: "null", ...attribute };
37
-
38
- //----
39
- // GATHER UNION SCHEMAS
40
- //----
41
- const union: IJsonSchema[] = [];
42
- if (meta.nullable && options.purpose !== "swagger")
43
- union.push({
44
- ...attribute,
45
- type: "null",
46
- });
47
-
48
- const insert =
49
- meta.nullable && options.purpose === "swagger"
50
- ? (s: IJsonSchema) =>
51
- union.push({
52
- ...s,
53
- nullable: (s as IJsonSchema.ISignificant<any>).type
54
- ? true
55
- : undefined,
56
- } as IJsonSchema)
57
- : (schema: IJsonSchema) => union.push(schema);
58
-
59
- // toJSON() METHOD
60
- if (meta.resolved !== null) {
61
- const resolved = application_schema(options)(blockNever)(
62
- components,
63
- )(meta.resolved)(attribute);
64
- if (resolved !== null) union.push(resolved);
65
- }
66
-
67
- // ATOMIC TYPES
68
- if (meta.templates.length && AtomicPredicator.template(meta))
69
- insert(application_templates(meta)(attribute));
70
- for (const constant of meta.constants)
71
- if (constant.type === "bigint") throw new Error(NO_BIGINT);
72
- else if (
73
- (constant.type === "string" && meta.templates.length) ||
74
- AtomicPredicator.constant(meta)(constant.type) === false
75
- )
76
- continue;
77
- else insert(application_constant(constant)(attribute));
78
- for (const type of meta.atomics)
79
- if (type === "bigint") throw new Error(NO_BIGINT);
80
- else if (AtomicPredicator.atomic(meta)(type) === false) continue;
81
- else
82
- insert(
83
- type === "string"
84
- ? application_string(meta)(attribute)
85
- : type === "boolean"
86
- ? application_boolean(attribute)
87
- : application_number(attribute),
88
- );
89
-
90
- // ARRAY
91
- for (const array of meta.arrays)
92
- insert(
93
- application_array(options)(components)(array)(attribute)(
94
- meta.nullable,
95
- ),
96
- );
97
-
98
- // TUPLE
99
- for (const tuple of meta.tuples)
100
- insert(
101
- application_tuple(options)(components)(tuple)(attribute)(
102
- meta.nullable,
103
- ),
104
- );
105
-
106
- // NATIVES
107
- for (const native of meta.natives)
108
- if (AtomicPredicator.native(native))
109
- insert(
110
- native === "String"
111
- ? application_string(meta)(attribute)
112
- : native === "Boolean"
113
- ? application_boolean(attribute)
114
- : application_number(attribute),
115
- );
116
- else
117
- insert(
118
- application_native(options)(components)(native)({
119
- nullable: meta.nullable,
120
- attribute,
121
- }),
122
- );
123
- if (meta.sets.length)
124
- insert(
125
- application_native(options)(components)(`Set`)({
126
- nullable: meta.nullable,
127
- attribute,
128
- }),
129
- );
130
- if (meta.maps.length)
131
- insert(
132
- application_native(options)(components)(`Map`)({
133
- nullable: meta.nullable,
134
- attribute,
135
- }),
136
- );
137
-
138
- // OBJECT
139
- for (const obj of meta.objects)
140
- insert(application_object(options)(components)(obj)(meta.nullable));
141
-
142
- // ALIASES
143
- for (const alias of meta.aliases)
144
- insert(
145
- application_definition(options)(blockNever)(components)(alias)(
146
- meta.nullable,
147
- ),
148
- );
149
-
150
- //----
151
- // RETURNS
152
- //----
153
- if (union.length === 0)
154
- return blockNever === true
155
- ? null!
156
- : {
157
- ...attribute,
158
- type: undefined,
159
- };
160
- else if (union.length === 1) return union[0]!;
161
- return { oneOf: union, ...attribute };
162
- };
163
-
164
- const NO_BIGINT = "Error on typia.application(): does not allow bigint type.";
1
+ import { Metadata } from "../../metadata/Metadata";
2
+ import { IJsonComponents } from "../../schemas/IJsonComponents";
3
+ import { IJsonSchema } from "../../schemas/IJsonSchema";
4
+
5
+ import { ApplicationProgrammer } from "../ApplicationProgrammer";
6
+ import { AtomicPredicator } from "../helpers/AtomicPredicator";
7
+ import { application_array } from "./application_array";
8
+ import { application_boolean } from "./application_boolean";
9
+ import { application_constant } from "./application_constant";
10
+ import { application_alias } from "./application_definition";
11
+ import { application_native } from "./application_native";
12
+ import { application_number } from "./application_number";
13
+ import { application_object } from "./application_object";
14
+ import { application_string } from "./application_string";
15
+ import { application_templates } from "./application_templates";
16
+ import { application_tuple } from "./application_tuple";
17
+
18
+ /**
19
+ * @internal
20
+ */
21
+ export const application_schema =
22
+ (options: ApplicationProgrammer.IOptions) =>
23
+ <BlockNever extends boolean>(blockNever: BlockNever) =>
24
+ (components: IJsonComponents) =>
25
+ (meta: Metadata) =>
26
+ (
27
+ attribute: IJsonSchema.IAttribute,
28
+ ): BlockNever extends true ? IJsonSchema | null : IJsonSchema => {
29
+ // VULNERABLE CASE
30
+ if (meta.any === true)
31
+ return {
32
+ ...attribute,
33
+ type: undefined,
34
+ };
35
+ else if (meta.nullable && meta.empty())
36
+ return { type: "null", ...attribute };
37
+
38
+ //----
39
+ // GATHER UNION SCHEMAS
40
+ //----
41
+ const union: IJsonSchema[] = [];
42
+ if (meta.nullable && options.purpose !== "swagger")
43
+ union.push({
44
+ ...attribute,
45
+ type: "null",
46
+ });
47
+
48
+ const insert =
49
+ meta.nullable && options.purpose === "swagger"
50
+ ? (s: IJsonSchema) =>
51
+ union.push({
52
+ ...s,
53
+ nullable: (s as IJsonSchema.ISignificant<any>).type
54
+ ? true
55
+ : undefined,
56
+ } as IJsonSchema)
57
+ : (schema: IJsonSchema) => union.push(schema);
58
+
59
+ // toJSON() METHOD
60
+ if (meta.resolved !== null) {
61
+ const resolved = application_schema(options)(blockNever)(
62
+ components,
63
+ )(meta.resolved)(attribute);
64
+ if (resolved !== null) union.push(resolved);
65
+ }
66
+
67
+ // ATOMIC TYPES
68
+ if (meta.templates.length && AtomicPredicator.template(meta))
69
+ insert(application_templates(meta)(attribute));
70
+ for (const constant of meta.constants)
71
+ if (constant.type === "bigint") throw new Error(NO_BIGINT);
72
+ else if (
73
+ (constant.type === "string" && meta.templates.length) ||
74
+ AtomicPredicator.constant(meta)(constant.type) === false
75
+ )
76
+ continue;
77
+ else insert(application_constant(constant)(attribute));
78
+ for (const type of meta.atomics)
79
+ if (type === "bigint") throw new Error(NO_BIGINT);
80
+ else if (AtomicPredicator.atomic(meta)(type) === false) continue;
81
+ else
82
+ insert(
83
+ type === "string"
84
+ ? application_string(meta)(attribute)
85
+ : type === "boolean"
86
+ ? application_boolean(attribute)
87
+ : application_number(attribute),
88
+ );
89
+
90
+ // ARRAY
91
+ for (const array of meta.arrays)
92
+ insert(application_array(options)(components)(array)(attribute));
93
+
94
+ // TUPLE
95
+ for (const tuple of meta.tuples)
96
+ insert(application_tuple(options)(components)(tuple)(attribute));
97
+
98
+ // NATIVES
99
+ for (const native of meta.natives)
100
+ if (AtomicPredicator.native(native))
101
+ insert(
102
+ native === "String"
103
+ ? application_string(meta)(attribute)
104
+ : native === "Boolean"
105
+ ? application_boolean(attribute)
106
+ : application_number(attribute),
107
+ );
108
+ else
109
+ insert(
110
+ application_native(options)(components)(native)({
111
+ nullable: meta.nullable,
112
+ attribute,
113
+ }),
114
+ );
115
+ if (meta.sets.length)
116
+ insert(
117
+ application_native(options)(components)(`Set`)({
118
+ nullable: meta.nullable,
119
+ attribute,
120
+ }),
121
+ );
122
+ if (meta.maps.length)
123
+ insert(
124
+ application_native(options)(components)(`Map`)({
125
+ nullable: meta.nullable,
126
+ attribute,
127
+ }),
128
+ );
129
+
130
+ // OBJECT
131
+ for (const obj of meta.objects)
132
+ insert(application_object(options)(components)(obj)(meta.nullable));
133
+
134
+ // ALIASES
135
+ for (const alias of meta.aliases)
136
+ insert(
137
+ application_alias(options)(blockNever)(components)(alias)(
138
+ meta.nullable,
139
+ ),
140
+ );
141
+
142
+ //----
143
+ // RETURNS
144
+ //----
145
+ if (union.length === 0)
146
+ return blockNever === true
147
+ ? null!
148
+ : {
149
+ ...attribute,
150
+ type: undefined,
151
+ };
152
+ else if (union.length === 1) return union[0]!;
153
+ return { oneOf: union, ...attribute };
154
+ };
155
+
156
+ const NO_BIGINT = "Error on typia.application(): does not allow bigint type.";
@@ -1,77 +1,47 @@
1
- import { Metadata } from "../../metadata/Metadata";
2
- import { MetadataTuple } from "../../metadata/MetadataTuple";
3
- import { IJsonComponents } from "../../schemas/IJsonComponents";
4
- import { IJsonSchema } from "../../schemas/IJsonSchema";
5
-
6
- import { ApplicationProgrammer } from "../ApplicationProgrammer";
7
- import { JSON_COMPONENTS_PREFIX } from "./JSON_SCHEMA_PREFIX";
8
- import { application_schema } from "./application_schema";
9
-
10
- /**
11
- * @internal
12
- */
13
- export const application_tuple =
14
- (options: ApplicationProgrammer.IOptions) =>
15
- (components: IJsonComponents) =>
16
- (tuple: MetadataTuple) =>
17
- (attribute: IJsonSchema.IAttribute) =>
18
- (
19
- nullable: boolean,
20
- ):
21
- | IJsonSchema.ITuple
22
- | IJsonSchema.IArray
23
- | IJsonSchema.IReference
24
- | IJsonSchema.IRecursiveReference => {
25
- const generator = () => {
26
- const schema: IJsonSchema.ITuple = {
27
- ...attribute,
28
- type: "array",
29
- items: tuple.elements.map((elem) =>
30
- application_schema(options)(false)(components)(
31
- elem.rest ?? elem,
32
- )(tuple.recursive ? {} : attribute),
33
- ),
34
- "x-typia-rest": !!tuple.elements.at(-1)?.rest,
35
- };
36
- const wrapper: IJsonSchema.ITuple | IJsonSchema.IArray =
37
- options.purpose === "ajv" && !tuple.elements.at(-1)?.rest
38
- ? schema
39
- : {
40
- ...schema,
41
- items: application_schema(options)(false)(components)(
42
- tuple.elements.reduce(
43
- (x, y) =>
44
- Metadata.merge(x.rest ?? x, y.rest ?? y),
45
- Metadata.initialize(),
46
- ),
47
- )(tuple.recursive ? {} : attribute),
48
- "x-typia-tuple": schema,
49
- };
50
- return wrapper;
51
- };
52
- if (tuple.recursive === false) return generator();
53
-
54
- // KEY
55
- const key: string =
56
- options.purpose === "ajv"
57
- ? tuple.name
58
- : `${tuple.name}${nullable ? ".Nullable" : ""}`;
59
- const $id: string = `${JSON_COMPONENTS_PREFIX}/tuples/${key}`;
60
-
61
- // REFERENCE
62
- if (components.tuples?.[key] === undefined) {
63
- components.tuples ??= {};
64
- components.tuples[key] = {} as any;
65
-
66
- const repeated: IJsonComponents.IArray | IJsonComponents.ITuple = {
67
- ...generator(),
68
- $id: options.purpose === "ajv" ? $id : undefined,
69
- $recursiveAnchor: options.purpose === "ajv" || undefined,
70
- };
71
- components.tuples ??= {};
72
- components.tuples[key] = repeated;
73
- }
74
- return options.purpose === "ajv" && tuple.recursive
75
- ? { ...attribute, $recursiveRef: $id }
76
- : { ...attribute, $ref: $id };
77
- };
1
+ import { Metadata } from "../../metadata/Metadata";
2
+ import { MetadataTuple } from "../../metadata/MetadataTuple";
3
+ import { IJsonComponents } from "../../schemas/IJsonComponents";
4
+ import { IJsonSchema } from "../../schemas/IJsonSchema";
5
+
6
+ import { ApplicationProgrammer } from "../ApplicationProgrammer";
7
+ import { application_schema } from "./application_schema";
8
+
9
+ /**
10
+ * @internal
11
+ */
12
+ export const application_tuple =
13
+ (options: ApplicationProgrammer.IOptions) =>
14
+ (components: IJsonComponents) =>
15
+ (tuple: MetadataTuple) =>
16
+ (
17
+ attribute: IJsonSchema.IAttribute,
18
+ ): IJsonSchema.ITuple | IJsonSchema.IArray => {
19
+ const schema: IJsonSchema.ITuple = {
20
+ type: "array",
21
+ items: tuple.elements.map((meta, i) =>
22
+ application_schema(options)(false)(components)(
23
+ meta.rest ?? meta,
24
+ )({
25
+ ...attribute,
26
+ "x-typia-rest":
27
+ i === tuple.elements.length - 1 && meta.rest !== null,
28
+ "x-typia-required": meta.required,
29
+ "x-typia-optional": meta.optional,
30
+ }),
31
+ ),
32
+ ...attribute,
33
+ };
34
+ if (options.purpose === "ajv") return schema;
35
+
36
+ const wrapper: IJsonSchema.IArray = {
37
+ ...schema,
38
+ items: application_schema(options)(false)(components)(
39
+ tuple.elements.reduce(
40
+ (x, y) => Metadata.merge(x.rest ?? x, y.rest ?? y),
41
+ Metadata.initialize(),
42
+ ),
43
+ )(tuple.recursive ? {} : attribute),
44
+ "x-typia-tuple": schema,
45
+ };
46
+ return wrapper;
47
+ };