typia 3.8.4 → 4.0.0-dev.20230502

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 (142) hide show
  1. package/README.md +9 -1
  2. package/lib/factories/ProtocolFactory.d.ts +8 -0
  3. package/lib/factories/ProtocolFactory.js +112 -0
  4. package/lib/factories/ProtocolFactory.js.map +1 -0
  5. package/lib/factories/internal/protocols/ProtocolMetadataUtil.d.ts +16 -0
  6. package/lib/factories/internal/protocols/ProtocolMetadataUtil.js +160 -0
  7. package/lib/factories/internal/protocols/ProtocolMetadataUtil.js.map +1 -0
  8. package/lib/factories/internal/protocols/emplace_protocol_object.d.ts +3 -0
  9. package/lib/factories/internal/protocols/emplace_protocol_object.js +47 -0
  10. package/lib/factories/internal/protocols/emplace_protocol_object.js.map +1 -0
  11. package/lib/factories/internal/protocols/emplace_protocol_property.d.ts +4 -0
  12. package/lib/factories/internal/protocols/emplace_protocol_property.js +20 -0
  13. package/lib/factories/internal/protocols/emplace_protocol_property.js.map +1 -0
  14. package/lib/factories/internal/protocols/iterate_protocol_atomic.d.ts +3 -0
  15. package/lib/factories/internal/protocols/iterate_protocol_atomic.js +69 -0
  16. package/lib/factories/internal/protocols/iterate_protocol_atomic.js.map +1 -0
  17. package/lib/factories/internal/protocols/iterate_protocol_constant.d.ts +2 -0
  18. package/lib/factories/internal/protocols/iterate_protocol_constant.js +30 -0
  19. package/lib/factories/internal/protocols/iterate_protocol_constant.js.map +1 -0
  20. package/lib/factories/internal/protocols/iterate_protocol_main.d.ts +3 -0
  21. package/lib/factories/internal/protocols/iterate_protocol_main.js +17 -0
  22. package/lib/factories/internal/protocols/iterate_protocol_main.js.map +1 -0
  23. package/lib/factories/internal/protocols/iterate_protocol_map.d.ts +4 -0
  24. package/lib/factories/internal/protocols/iterate_protocol_map.js +75 -0
  25. package/lib/factories/internal/protocols/iterate_protocol_map.js.map +1 -0
  26. package/lib/factories/internal/protocols/iterate_protocol_metadata.d.ts +5 -0
  27. package/lib/factories/internal/protocols/iterate_protocol_metadata.js +190 -0
  28. package/lib/factories/internal/protocols/iterate_protocol_metadata.js.map +1 -0
  29. package/lib/factories/internal/protocols/iterate_protocol_native.d.ts +2 -0
  30. package/lib/factories/internal/protocols/iterate_protocol_native.js +33 -0
  31. package/lib/factories/internal/protocols/iterate_protocol_native.js.map +1 -0
  32. package/lib/factories/internal/protocols/iterate_protocol_never.d.ts +1 -0
  33. package/lib/factories/internal/protocols/iterate_protocol_never.js +6 -0
  34. package/lib/factories/internal/protocols/iterate_protocol_never.js.map +1 -0
  35. package/lib/factories/internal/protocols/iterate_protocol_object.d.ts +4 -0
  36. package/lib/factories/internal/protocols/iterate_protocol_object.js +157 -0
  37. package/lib/factories/internal/protocols/iterate_protocol_object.js.map +1 -0
  38. package/lib/factories/internal/protocols/iterate_protocol_repeated.d.ts +5 -0
  39. package/lib/factories/internal/protocols/iterate_protocol_repeated.js +25 -0
  40. package/lib/factories/internal/protocols/iterate_protocol_repeated.js.map +1 -0
  41. package/lib/factories/internal/protocols/iterate_protocol_tuple.d.ts +3 -0
  42. package/lib/factories/internal/protocols/iterate_protocol_tuple.js +46 -0
  43. package/lib/factories/internal/protocols/iterate_protocol_tuple.js.map +1 -0
  44. package/lib/functional/$proto_bytes.d.ts +2 -0
  45. package/lib/functional/$proto_bytes.js +37 -0
  46. package/lib/functional/$proto_bytes.js.map +1 -0
  47. package/lib/functional/$proto_field.d.ts +10 -0
  48. package/lib/functional/$proto_field.js +42 -0
  49. package/lib/functional/$proto_field.js.map +1 -0
  50. package/lib/functional/$proto_float.d.ts +4 -0
  51. package/lib/functional/$proto_float.js +28 -0
  52. package/lib/functional/$proto_float.js.map +1 -0
  53. package/lib/functional/$proto_i32.d.ts +2 -0
  54. package/lib/functional/$proto_i32.js +23 -0
  55. package/lib/functional/$proto_i32.js.map +1 -0
  56. package/lib/functional/$proto_i64.d.ts +2 -0
  57. package/lib/functional/$proto_i64.js +31 -0
  58. package/lib/functional/$proto_i64.js.map +1 -0
  59. package/lib/functional/$proto_size.d.ts +6 -0
  60. package/lib/functional/$proto_size.js +76 -0
  61. package/lib/functional/$proto_size.js.map +1 -0
  62. package/lib/functional/$proto_string.d.ts +2 -0
  63. package/lib/functional/$proto_string.js +34 -0
  64. package/lib/functional/$proto_string.js.map +1 -0
  65. package/lib/functional/$varint.d.ts +6 -0
  66. package/lib/functional/$varint.js +99 -0
  67. package/lib/functional/$varint.js.map +1 -0
  68. package/lib/functional/$zigzag.d.ts +4 -0
  69. package/lib/functional/$zigzag.js +34 -0
  70. package/lib/functional/$zigzag.js.map +1 -0
  71. package/lib/messages/IProtocolMap.d.ts +5 -0
  72. package/lib/messages/IProtocolMap.js +3 -0
  73. package/lib/messages/IProtocolMap.js.map +1 -0
  74. package/lib/messages/IProtocolMessage.d.ts +5 -0
  75. package/lib/messages/IProtocolMessage.js +3 -0
  76. package/lib/messages/IProtocolMessage.js.map +1 -0
  77. package/lib/messages/IProtocolProperty.d.ts +12 -0
  78. package/lib/messages/IProtocolProperty.js +3 -0
  79. package/lib/messages/IProtocolProperty.js.map +1 -0
  80. package/lib/metadata/IMetadataTag.d.ts +3 -3
  81. package/lib/metadata/Metadata.js +1 -1
  82. package/lib/metadata/Metadata.js.map +1 -1
  83. package/lib/module.d.ts +2 -0
  84. package/lib/module.js +6 -1
  85. package/lib/module.js.map +1 -1
  86. package/lib/programmers/MessageProgrammer.d.ts +5 -0
  87. package/lib/programmers/MessageProgrammer.js +141 -0
  88. package/lib/programmers/MessageProgrammer.js.map +1 -0
  89. package/lib/transformers/CallExpressionTransformer.js +5 -3
  90. package/lib/transformers/CallExpressionTransformer.js.map +1 -1
  91. package/lib/transformers/features/miscellaneous/ApplicationTransformer.js +1 -3
  92. package/lib/transformers/features/miscellaneous/ApplicationTransformer.js.map +1 -1
  93. package/lib/transformers/features/protocols/MessageTransformer.d.ts +5 -0
  94. package/lib/transformers/features/protocols/MessageTransformer.js +20 -0
  95. package/lib/transformers/features/protocols/MessageTransformer.js.map +1 -0
  96. package/lib/utils/NameEncoder.d.ts +4 -0
  97. package/lib/utils/NameEncoder.js +89 -0
  98. package/lib/utils/NameEncoder.js.map +1 -0
  99. package/package.json +1 -1
  100. package/src/Primitive.ts +123 -123
  101. package/src/factories/MetadataFactory.ts +62 -62
  102. package/src/factories/ProtocolFactory.ts +79 -0
  103. package/src/factories/internal/metadata/emplace_metadata_object.ts +143 -143
  104. package/src/factories/internal/metadata/iterate_metadata_tuple.ts +48 -48
  105. package/src/factories/internal/protocols/ProtocolMetadataUtil.ts +167 -0
  106. package/src/factories/internal/protocols/emplace_protocol_object.ts +25 -0
  107. package/src/factories/internal/protocols/emplace_protocol_property.ts +12 -0
  108. package/src/factories/internal/protocols/iterate_protocol_atomic.ts +34 -0
  109. package/src/factories/internal/protocols/iterate_protocol_constant.ts +27 -0
  110. package/src/factories/internal/protocols/iterate_protocol_main.ts +19 -0
  111. package/src/factories/internal/protocols/iterate_protocol_map.ts +58 -0
  112. package/src/factories/internal/protocols/iterate_protocol_metadata.ts +96 -0
  113. package/src/factories/internal/protocols/iterate_protocol_native.ts +34 -0
  114. package/src/factories/internal/protocols/iterate_protocol_never.ts +1 -0
  115. package/src/factories/internal/protocols/iterate_protocol_object.ts +110 -0
  116. package/src/factories/internal/protocols/iterate_protocol_repeated.ts +34 -0
  117. package/src/factories/internal/protocols/iterate_protocol_tuple.ts +29 -0
  118. package/src/functional/$proto_bytes.ts +25 -0
  119. package/src/functional/$proto_field.ts +30 -0
  120. package/src/functional/$proto_float.ts +37 -0
  121. package/src/functional/$proto_i32.ts +29 -0
  122. package/src/functional/$proto_i64.ts +37 -0
  123. package/src/functional/$proto_size.ts +82 -0
  124. package/src/functional/$proto_string.ts +24 -0
  125. package/src/functional/$varint.ts +130 -0
  126. package/src/functional/$zigzag.ts +39 -0
  127. package/src/messages/IProtocolMap.ts +5 -0
  128. package/src/messages/IProtocolMessage.ts +6 -0
  129. package/src/messages/IProtocolProperty.ts +13 -0
  130. package/src/metadata/IMetadata.ts +26 -26
  131. package/src/metadata/IMetadataTag.ts +11 -3
  132. package/src/metadata/Metadata.ts +543 -539
  133. package/src/module.ts +11 -0
  134. package/src/programmers/CheckerProgrammer.ts +901 -901
  135. package/src/programmers/MessageProgrammer.ts +126 -0
  136. package/src/programmers/internal/application_object.ts +155 -155
  137. package/src/programmers/internal/application_tuple.ts +31 -31
  138. package/src/schemas/IJsonSchema.ts +130 -130
  139. package/src/transformers/CallExpressionTransformer.ts +17 -10
  140. package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +1 -3
  141. package/src/transformers/features/protocols/MessageTransformer.ts +31 -0
  142. package/src/utils/NameEncoder.ts +32 -0
@@ -0,0 +1,126 @@
1
+ import ts from "typescript";
2
+
3
+ import { MetadataCollection } from "../factories/MetadataCollection";
4
+ import { ProtocolFactory } from "../factories/ProtocolFactory";
5
+
6
+ import { Metadata } from "../metadata/Metadata";
7
+
8
+ import { IProject } from "../transformers/IProject";
9
+
10
+ import { Escaper } from "../utils/Escaper";
11
+ import { MapUtil } from "../utils/MapUtil";
12
+ import { NameEncoder } from "../utils/NameEncoder";
13
+
14
+ import { IProtocolMap } from "../messages/IProtocolMap";
15
+ import { IProtocolMessage } from "../messages/IProtocolMessage";
16
+
17
+ export namespace MessageProgrammer {
18
+ export const generate =
19
+ ({ checker }: IProject) =>
20
+ (type: ts.Type) => {
21
+ // PARSE TARGET TYPE
22
+ const collection: MetadataCollection = new MetadataCollection();
23
+ const metadata: Metadata =
24
+ ProtocolFactory.metadata(checker)(collection)(type);
25
+
26
+ // CONVERT TO PROTOCOL MESSAGES
27
+ const dict: Map<string, IProtocolMessage> = new Map();
28
+ ProtocolFactory.generate(collection)(dict)(metadata);
29
+
30
+ // STRINGIFY
31
+ const hierarchies: Map<string, Hierarchy> = new Map();
32
+ for (const msg of dict.values()) emplace(hierarchies)(msg);
33
+
34
+ const content: string =
35
+ `syntax = "proto3";\n\n` +
36
+ [...hierarchies.values()]
37
+ .map((hier) => stringify(hier))
38
+ .join("\n\n");
39
+
40
+ // RETURNS
41
+ return ts.factory.createStringLiteral(content);
42
+ };
43
+
44
+ const stringify = (hierarchy: Hierarchy): string => {
45
+ const { key, message, children } = hierarchy;
46
+ let index: number = 1;
47
+
48
+ const elements: string[] = [`message ${NameEncoder.encode(key)} {`];
49
+ if (message !== null)
50
+ elements.push(
51
+ ...message.properties.map((property) => {
52
+ const key: string =
53
+ Escaper.variable(property.key) &&
54
+ property.key.indexOf("$") === -1
55
+ ? property.key
56
+ : `v${index + 1}`;
57
+ if (property.oneOf.length === 1)
58
+ return [
59
+ TAB,
60
+ property.required ? "" : "optional ",
61
+ property.repeated ? "repeated " : "",
62
+ getTypeName(property.oneOf[0]!.type) + " ",
63
+ key,
64
+ " = ",
65
+ `${index++};`,
66
+ ].join("");
67
+ return (
68
+ `${TAB}oneof ${key} {\n` +
69
+ property.oneOf
70
+ .map(
71
+ (o, i) =>
72
+ `${TAB}${TAB}${getTypeName(
73
+ o.type,
74
+ )} ${key}_o${i} = ${index++};`,
75
+ )
76
+ .join("\n") +
77
+ `\n${TAB}}`
78
+ );
79
+ }),
80
+ );
81
+ if (message !== null && children.size) elements.push("\n");
82
+ if (children.size)
83
+ elements.push(
84
+ [...children.values()]
85
+ .map((child) => stringify(child))
86
+ .map((body) =>
87
+ body
88
+ .split("\n")
89
+ .map((line) => `${TAB}${line}`)
90
+ .join("\n"),
91
+ )
92
+ .join("\n\n"),
93
+ );
94
+ elements.push("}");
95
+
96
+ return elements.join("\n");
97
+ };
98
+
99
+ const emplace =
100
+ (dict: Map<string, Hierarchy>) => (message: IProtocolMessage) => {
101
+ const accessors: string[] = message.name.split(".");
102
+ accessors.forEach((access, i) => {
103
+ const hierarchy: Hierarchy = MapUtil.take(dict)(access, () => ({
104
+ key: access,
105
+ message: null!,
106
+ children: new Map(),
107
+ }));
108
+ dict = hierarchy.children;
109
+ if (i === accessors.length - 1) hierarchy.message = message;
110
+ });
111
+ };
112
+
113
+ function getTypeName(type: string | IProtocolMap): string {
114
+ return typeof type === "string"
115
+ ? NameEncoder.encode(type)
116
+ : `map<${type.key}, ${getTypeName(type.value)}>`;
117
+ }
118
+ }
119
+
120
+ interface Hierarchy {
121
+ key: string;
122
+ message: IProtocolMessage | null;
123
+ children: Map<string, Hierarchy>;
124
+ }
125
+
126
+ const TAB = " ".repeat(4);
@@ -1,155 +1,155 @@
1
- import { CommentFactory } from "../../factories/CommentFactory";
2
-
3
- import { IJsDocTagInfo } from "../../metadata/IJsDocTagInfo";
4
- import { Metadata } from "../../metadata/Metadata";
5
- import { MetadataObject } from "../../metadata/MetadataObject";
6
- import { IJsonComponents } from "../../schemas/IJsonComponents";
7
-
8
- import { PatternUtil } from "../../utils/PatternUtil";
9
-
10
- import { IJsonSchema } from "../../module";
11
- import { ApplicationProgrammer } from "../ApplicationProgrammer";
12
- import { application_schema } from "./application_schema";
13
- import { metadata_to_pattern } from "./metadata_to_pattern";
14
-
15
- /**
16
- * @internal
17
- */
18
- export const application_object =
19
- (options: ApplicationProgrammer.IOptions) =>
20
- (components: IJsonComponents) =>
21
- (obj: MetadataObject) =>
22
- (props: { key: string; nullable: boolean }): void => {
23
- // TEMPORARY ASSIGNMENT
24
- if (components.schemas[props.key] !== undefined) return;
25
- components.schemas[props.key] = {} as any;
26
-
27
- // ITERATE PROPERTIES
28
- const properties: Record<string, any> = {};
29
- const extraMeta: ISuperfluous = {
30
- patternProperties: {},
31
- additionalProperties: undefined,
32
- };
33
- const required: string[] = [];
34
-
35
- for (const property of obj.properties) {
36
- if (
37
- property.value.functional === true &&
38
- property.value.nullable === false &&
39
- property.value.required === true &&
40
- property.value.size() === 0
41
- )
42
- continue;
43
-
44
- const key: string | null = property.key.getSoleLiteral();
45
- const schema: IJsonSchema | null = application_schema(options)(
46
- true,
47
- )(components)(property.value)({
48
- deprecated:
49
- !!property.jsDocTags.find(
50
- (tag) => tag.name === "deprecated",
51
- ) || undefined,
52
- title: (() => {
53
- const info: IJsDocTagInfo | undefined =
54
- property.jsDocTags.find((tag) => tag.name === "title");
55
- return info?.text?.length
56
- ? CommentFactory.string(info.text)
57
- : undefined;
58
- })(),
59
- description: property.description,
60
- "x-typia-metaTags": property.tags.length
61
- ? property.tags
62
- : undefined,
63
- "x-typia-jsDocTags": property.jsDocTags.length
64
- ? property.jsDocTags
65
- : undefined,
66
- "x-typia-required": property.value.required,
67
- "x-typia-optional": property.value.optional,
68
- });
69
-
70
- if (schema === null) continue;
71
- else if (key !== null) {
72
- properties[key] = schema;
73
- if (property.value.required === true) required.push(key);
74
- } else {
75
- const pattern: string = metadata_to_pattern(true)(property.key);
76
- if (pattern === PatternUtil.STRING)
77
- extraMeta.additionalProperties = [property.value, schema];
78
- else
79
- extraMeta.patternProperties[pattern] = [
80
- property.value,
81
- schema,
82
- ];
83
- }
84
- }
85
-
86
- const extraProps = {
87
- additionalProperties: extraMeta.additionalProperties?.[1],
88
- patternProperties: (() => {
89
- if (Object.keys(extraMeta.patternProperties).length === 0)
90
- return undefined;
91
- const output: Record<string, IJsonSchema> = {};
92
- for (const [key, value] of Object.entries(
93
- extraMeta.patternProperties,
94
- ))
95
- output[key] = value[1];
96
- return output;
97
- })(),
98
- };
99
- const schema: IJsonComponents.IObject = {
100
- $id:
101
- options.purpose === "ajv"
102
- ? options.prefix + "/" + props.key
103
- : undefined,
104
- $recursiveAnchor:
105
- (options.purpose === "ajv" && obj.recursive) || undefined,
106
- type: "object",
107
- properties,
108
- nullable: props.nullable,
109
- required: required.length ? required : undefined,
110
- description: obj.description,
111
- "x-typia-jsDocTags": obj.jsDocTags,
112
- ...(options.purpose === "ajv"
113
- ? extraProps
114
- : {
115
- // swagger can't express patternProperties
116
- "x-typia-additionalProperties":
117
- extraProps.additionalProperties,
118
- "x-typia-patternProperties": extraProps.patternProperties,
119
- additionalProperties:
120
- join(options)(components)(extraMeta),
121
- }),
122
- };
123
- components.schemas[props.key] = schema;
124
- };
125
-
126
- const join =
127
- (options: ApplicationProgrammer.IOptions) =>
128
- (components: IJsonComponents) =>
129
- (extra: ISuperfluous): IJsonSchema | undefined => {
130
- // LIST UP METADATA
131
- const elements: [Metadata, IJsonSchema][] = Object.values(
132
- extra.patternProperties || {},
133
- );
134
- if (extra.additionalProperties)
135
- elements.push(extra.additionalProperties);
136
-
137
- // SHORT RETURN
138
- if (elements.length === 0) return undefined;
139
- else if (elements.length === 1) return elements[0]![1]!;
140
-
141
- // MERGE METADATA AND GENERATE VULNERABLE SCHEMA
142
- const meta: Metadata = elements
143
- .map((tuple) => tuple[0])
144
- .reduce((x, y) => Metadata.merge(x, y));
145
- return (
146
- application_schema(options)(true)(components)(meta)({
147
- "x-typia-required": false,
148
- }) ?? undefined
149
- );
150
- };
151
-
152
- interface ISuperfluous {
153
- additionalProperties?: [Metadata, IJsonSchema];
154
- patternProperties: Record<string, [Metadata, IJsonSchema]>;
155
- }
1
+ import { CommentFactory } from "../../factories/CommentFactory";
2
+
3
+ import { IJsDocTagInfo } from "../../metadata/IJsDocTagInfo";
4
+ import { Metadata } from "../../metadata/Metadata";
5
+ import { MetadataObject } from "../../metadata/MetadataObject";
6
+ import { IJsonComponents } from "../../schemas/IJsonComponents";
7
+
8
+ import { PatternUtil } from "../../utils/PatternUtil";
9
+
10
+ import { IJsonSchema } from "../../module";
11
+ import { ApplicationProgrammer } from "../ApplicationProgrammer";
12
+ import { application_schema } from "./application_schema";
13
+ import { metadata_to_pattern } from "./metadata_to_pattern";
14
+
15
+ /**
16
+ * @internal
17
+ */
18
+ export const application_object =
19
+ (options: ApplicationProgrammer.IOptions) =>
20
+ (components: IJsonComponents) =>
21
+ (obj: MetadataObject) =>
22
+ (props: { key: string; nullable: boolean }): void => {
23
+ // TEMPORARY ASSIGNMENT
24
+ if (components.schemas[props.key] !== undefined) return;
25
+ components.schemas[props.key] = {} as any;
26
+
27
+ // ITERATE PROPERTIES
28
+ const properties: Record<string, any> = {};
29
+ const extraMeta: ISuperfluous = {
30
+ patternProperties: {},
31
+ additionalProperties: undefined,
32
+ };
33
+ const required: string[] = [];
34
+
35
+ for (const property of obj.properties) {
36
+ if (
37
+ property.value.functional === true &&
38
+ property.value.nullable === false &&
39
+ property.value.required === true &&
40
+ property.value.size() === 0
41
+ )
42
+ continue;
43
+
44
+ const key: string | null = property.key.getSoleLiteral();
45
+ const schema: IJsonSchema | null = application_schema(options)(
46
+ true,
47
+ )(components)(property.value)({
48
+ deprecated:
49
+ !!property.jsDocTags.find(
50
+ (tag) => tag.name === "deprecated",
51
+ ) || undefined,
52
+ title: (() => {
53
+ const info: IJsDocTagInfo | undefined =
54
+ property.jsDocTags.find((tag) => tag.name === "title");
55
+ return info?.text?.length
56
+ ? CommentFactory.string(info.text)
57
+ : undefined;
58
+ })(),
59
+ description: property.description,
60
+ "x-typia-metaTags": property.tags.length
61
+ ? property.tags
62
+ : undefined,
63
+ "x-typia-jsDocTags": property.jsDocTags.length
64
+ ? property.jsDocTags
65
+ : undefined,
66
+ "x-typia-required": property.value.required,
67
+ "x-typia-optional": property.value.optional,
68
+ });
69
+
70
+ if (schema === null) continue;
71
+ else if (key !== null) {
72
+ properties[key] = schema;
73
+ if (property.value.required === true) required.push(key);
74
+ } else {
75
+ const pattern: string = metadata_to_pattern(true)(property.key);
76
+ if (pattern === PatternUtil.STRING)
77
+ extraMeta.additionalProperties = [property.value, schema];
78
+ else
79
+ extraMeta.patternProperties[pattern] = [
80
+ property.value,
81
+ schema,
82
+ ];
83
+ }
84
+ }
85
+
86
+ const extraProps = {
87
+ additionalProperties: extraMeta.additionalProperties?.[1],
88
+ patternProperties: (() => {
89
+ if (Object.keys(extraMeta.patternProperties).length === 0)
90
+ return undefined;
91
+ const output: Record<string, IJsonSchema> = {};
92
+ for (const [key, value] of Object.entries(
93
+ extraMeta.patternProperties,
94
+ ))
95
+ output[key] = value[1];
96
+ return output;
97
+ })(),
98
+ };
99
+ const schema: IJsonComponents.IObject = {
100
+ $id:
101
+ options.purpose === "ajv"
102
+ ? options.prefix + "/" + props.key
103
+ : undefined,
104
+ $recursiveAnchor:
105
+ (options.purpose === "ajv" && obj.recursive) || undefined,
106
+ type: "object",
107
+ properties,
108
+ nullable: props.nullable,
109
+ required: required.length ? required : undefined,
110
+ description: obj.description,
111
+ "x-typia-jsDocTags": obj.jsDocTags,
112
+ ...(options.purpose === "ajv"
113
+ ? extraProps
114
+ : {
115
+ // swagger can't express patternProperties
116
+ "x-typia-additionalProperties":
117
+ extraProps.additionalProperties,
118
+ "x-typia-patternProperties": extraProps.patternProperties,
119
+ additionalProperties:
120
+ join(options)(components)(extraMeta),
121
+ }),
122
+ };
123
+ components.schemas[props.key] = schema;
124
+ };
125
+
126
+ const join =
127
+ (options: ApplicationProgrammer.IOptions) =>
128
+ (components: IJsonComponents) =>
129
+ (extra: ISuperfluous): IJsonSchema | undefined => {
130
+ // LIST UP METADATA
131
+ const elements: [Metadata, IJsonSchema][] = Object.values(
132
+ extra.patternProperties || {},
133
+ );
134
+ if (extra.additionalProperties)
135
+ elements.push(extra.additionalProperties);
136
+
137
+ // SHORT RETURN
138
+ if (elements.length === 0) return undefined;
139
+ else if (elements.length === 1) return elements[0]![1]!;
140
+
141
+ // MERGE METADATA AND GENERATE VULNERABLE SCHEMA
142
+ const meta: Metadata = elements
143
+ .map((tuple) => tuple[0])
144
+ .reduce((x, y) => Metadata.merge(x, y));
145
+ return (
146
+ application_schema(options)(true)(components)(meta)({
147
+ "x-typia-required": false,
148
+ }) ?? undefined
149
+ );
150
+ };
151
+
152
+ interface ISuperfluous {
153
+ additionalProperties?: [Metadata, IJsonSchema];
154
+ patternProperties: Record<string, [Metadata, IJsonSchema]>;
155
+ }
@@ -1,31 +1,31 @@
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 { application_schema } from "./application_schema";
7
-
8
- /**
9
- * @internal
10
- */
11
- export const application_tuple =
12
- (options: ApplicationProgrammer.IOptions) =>
13
- (components: IJsonComponents) =>
14
- (items: Array<Metadata>) =>
15
- (props: {
16
- nullable: boolean;
17
- attribute: IJsonSchema.IAttribute;
18
- }): IJsonSchema.ITuple => ({
19
- type: "array",
20
- items: items.map((meta, i) =>
21
- application_schema(options)(false)(components)(meta.rest ?? meta)({
22
- ...props.attribute,
23
- "x-typia-rest":
24
- i === items.length - 1 ? meta.rest !== null : undefined,
25
- "x-typia-required": meta.required,
26
- "x-typia-optional": meta.optional,
27
- }),
28
- ),
29
- nullable: props.nullable,
30
- ...props.attribute,
31
- });
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 { application_schema } from "./application_schema";
7
+
8
+ /**
9
+ * @internal
10
+ */
11
+ export const application_tuple =
12
+ (options: ApplicationProgrammer.IOptions) =>
13
+ (components: IJsonComponents) =>
14
+ (items: Array<Metadata>) =>
15
+ (props: {
16
+ nullable: boolean;
17
+ attribute: IJsonSchema.IAttribute;
18
+ }): IJsonSchema.ITuple => ({
19
+ type: "array",
20
+ items: items.map((meta, i) =>
21
+ application_schema(options)(false)(components)(meta.rest ?? meta)({
22
+ ...props.attribute,
23
+ "x-typia-rest":
24
+ i === items.length - 1 ? meta.rest !== null : undefined,
25
+ "x-typia-required": meta.required,
26
+ "x-typia-optional": meta.optional,
27
+ }),
28
+ ),
29
+ nullable: props.nullable,
30
+ ...props.attribute,
31
+ });