typia 3.8.4 → 3.8.5-dev.20230510

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 (30) hide show
  1. package/lib/factories/MetadataTagFactory.js +5 -5
  2. package/lib/factories/MetadataTagFactory.js.map +1 -1
  3. package/lib/factories/internal/metadata/emplace_metadata_object.js +17 -15
  4. package/lib/factories/internal/metadata/emplace_metadata_object.js.map +1 -1
  5. package/lib/programmers/AssertProgrammer.js +1 -1
  6. package/lib/programmers/AssertProgrammer.js.map +1 -1
  7. package/lib/programmers/IsProgrammer.d.ts +1 -1
  8. package/lib/programmers/IsProgrammer.js +5 -2
  9. package/lib/programmers/IsProgrammer.js.map +1 -1
  10. package/lib/programmers/ValidateProgrammer.js +1 -1
  11. package/lib/programmers/ValidateProgrammer.js.map +1 -1
  12. package/lib/programmers/helpers/disable_function_importer_declare.d.ts +2 -0
  13. package/lib/programmers/helpers/disable_function_importer_declare.js +15 -0
  14. package/lib/programmers/helpers/disable_function_importer_declare.js.map +1 -0
  15. package/package.json +1 -1
  16. package/src/Primitive.ts +123 -123
  17. package/src/factories/MetadataFactory.ts +62 -62
  18. package/src/factories/MetadataTagFactory.ts +5 -7
  19. package/src/factories/internal/metadata/emplace_metadata_object.ts +143 -143
  20. package/src/factories/internal/metadata/iterate_metadata_tuple.ts +48 -48
  21. package/src/metadata/IMetadata.ts +26 -26
  22. package/src/metadata/Metadata.ts +539 -539
  23. package/src/programmers/AssertProgrammer.ts +1 -1
  24. package/src/programmers/CheckerProgrammer.ts +901 -901
  25. package/src/programmers/IsProgrammer.ts +6 -2
  26. package/src/programmers/ValidateProgrammer.ts +1 -1
  27. package/src/programmers/helpers/disable_function_importer_declare.ts +21 -0
  28. package/src/programmers/internal/application_object.ts +155 -155
  29. package/src/programmers/internal/application_tuple.ts +31 -31
  30. package/src/schemas/IJsonSchema.ts +130 -130
@@ -12,6 +12,7 @@ import { CheckerProgrammer } from "./CheckerProgrammer";
12
12
  import { FunctionImporter } from "./helpers/FunctionImporeter";
13
13
  import { IExpressionEntry } from "./helpers/IExpressionEntry";
14
14
  import { OptionPredicator } from "./helpers/OptionPredicator";
15
+ import { disable_function_importer_declare } from "./helpers/disable_function_importer_declare";
15
16
  import { check_object } from "./internal/check_object";
16
17
  import { feature_object_entries } from "./internal/feature_object_entries";
17
18
 
@@ -103,9 +104,12 @@ export namespace IsProgrammer {
103
104
 
104
105
  export const write =
105
106
  (project: IProject) =>
106
- (modulo: ts.LeftHandSideExpression) =>
107
+ (modulo: ts.LeftHandSideExpression, disable?: boolean) =>
107
108
  (equals: boolean) => {
108
- const importer: FunctionImporter = new FunctionImporter();
109
+ const importer: FunctionImporter =
110
+ disable === true
111
+ ? disable_function_importer_declare(new FunctionImporter())
112
+ : new FunctionImporter();
109
113
 
110
114
  // CONFIGURATION
111
115
  const config: CheckerProgrammer.IConfig = {
@@ -87,7 +87,7 @@ export namespace ValidateProgrammer {
87
87
  [
88
88
  StatementFactory.constant(
89
89
  "__is",
90
- IsProgrammer.write(project)(modulo)(equals)(
90
+ IsProgrammer.write(project)(modulo, true)(equals)(
91
91
  type,
92
92
  name ??
93
93
  TypeFactory.getFullName(project.checker)(
@@ -0,0 +1,21 @@
1
+ import ts from "typescript";
2
+
3
+ import { FunctionImporter } from "./FunctionImporeter";
4
+
5
+ export const disable_function_importer_declare = (
6
+ importer: FunctionImporter,
7
+ ): FunctionImporter => disable(importer) as FunctionImporter;
8
+
9
+ const disable = (importer: FunctionImporter): MethodOnly<FunctionImporter> => ({
10
+ empty: (): boolean => importer.empty(),
11
+ use: (name: string): ts.Identifier => importer.use(name),
12
+ useLocal: (name: string): string => importer.useLocal(name),
13
+ hasLocal: (name: string): boolean => importer.hasLocal(name),
14
+ declare: (_modulo: ts.LeftHandSideExpression): ts.Statement[] => [],
15
+ increment: (): number => importer.increment(),
16
+ trace: (): void => importer.trace(),
17
+ });
18
+
19
+ type MethodOnly<T> = {
20
+ [P in keyof T]: T[P] extends Function ? T[P] : never;
21
+ };
@@ -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
+ });