typia 9.7.2 → 10.0.0-dev.20251107
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/LICENSE +21 -21
- package/README.md +153 -153
- package/lib/factories/ProtobufFactory.js +1 -1
- package/lib/factories/ProtobufFactory.mjs +1 -1
- package/lib/programmers/internal/json_schema_station.d.mts +2 -2
- package/lib/programmers/internal/json_schema_station.d.ts +2 -2
- package/lib/programmers/llm/LlmApplicationProgrammer.js +5 -1
- package/lib/programmers/llm/LlmApplicationProgrammer.js.map +1 -1
- package/lib/programmers/llm/LlmApplicationProgrammer.mjs +5 -1
- package/lib/programmers/llm/LlmSchemaProgrammer.js +1 -4
- package/lib/programmers/llm/LlmSchemaProgrammer.js.map +1 -1
- package/lib/programmers/llm/LlmSchemaProgrammer.mjs +1 -35
- package/package.json +121 -121
- package/src/AssertionGuard.ts +41 -41
- package/src/CamelCase.ts +75 -75
- package/src/IRandomGenerator.ts +337 -337
- package/src/IReadableURLSearchParams.ts +9 -9
- package/src/PascalCase.ts +71 -71
- package/src/Primitive.ts +90 -90
- package/src/Resolved.ts +72 -72
- package/src/SnakeCase.ts +127 -127
- package/src/TypeGuardError.ts +216 -216
- package/src/factories/MetadataCollection.ts +270 -270
- package/src/factories/MetadataCommentTagFactory.ts +632 -632
- package/src/factories/MetadataFactory.ts +402 -402
- package/src/factories/ProtobufFactory.ts +873 -873
- package/src/functional.ts +705 -705
- package/src/http.ts +972 -972
- package/src/internal/_ProtobufReader.ts +188 -188
- package/src/internal/_ProtobufSizer.ts +137 -137
- package/src/internal/_ProtobufWriter.ts +135 -135
- package/src/internal/_jsonStringifyString.ts +42 -42
- package/src/json.ts +643 -643
- package/src/llm.ts +615 -615
- package/src/misc.ts +594 -594
- package/src/module.ts +889 -889
- package/src/notations.ts +751 -751
- package/src/programmers/FeatureProgrammer.ts +605 -605
- package/src/programmers/ImportProgrammer.ts +179 -179
- package/src/programmers/RandomProgrammer.ts +1195 -1195
- package/src/programmers/helpers/ProtobufWire.ts +34 -34
- package/src/programmers/internal/check_array_length.ts +43 -43
- package/src/programmers/internal/check_bigint.ts +46 -46
- package/src/programmers/internal/check_dynamic_key.ts +197 -197
- package/src/programmers/internal/check_dynamic_properties.ts +231 -231
- package/src/programmers/internal/check_everything.ts +21 -21
- package/src/programmers/internal/check_native.ts +23 -23
- package/src/programmers/internal/check_number.ts +108 -108
- package/src/programmers/internal/check_object.ts +72 -72
- package/src/programmers/internal/check_string.ts +46 -46
- package/src/programmers/internal/check_template.ts +46 -46
- package/src/programmers/internal/check_union_array_like.ts +331 -331
- package/src/programmers/internal/decode_union_object.ts +110 -110
- package/src/programmers/internal/feature_object_entries.ts +59 -59
- package/src/programmers/internal/json_schema_escaped.ts +78 -78
- package/src/programmers/internal/json_schema_object.ts +150 -150
- package/src/programmers/internal/json_schema_station.ts +2 -2
- package/src/programmers/internal/metadata_to_pattern.ts +40 -40
- package/src/programmers/internal/postfix_of_tuple.ts +3 -3
- package/src/programmers/internal/prune_object_properties.ts +69 -69
- package/src/programmers/internal/stringify_dynamic_properties.ts +158 -158
- package/src/programmers/internal/stringify_native.ts +5 -5
- package/src/programmers/internal/stringify_regular_properties.ts +77 -77
- package/src/programmers/internal/template_to_pattern.ts +21 -21
- package/src/programmers/internal/wrap_metadata_rest_tuple.ts +21 -21
- package/src/programmers/json/JsonStringifyProgrammer.ts +1124 -1124
- package/src/programmers/llm/LlmApplicationProgrammer.ts +10 -1
- package/src/programmers/llm/LlmSchemaProgrammer.ts +2 -7
- package/src/protobuf.ts +820 -820
- package/src/reflect.ts +46 -46
- package/src/schemas/json/IJsonApplication.ts +77 -77
- package/src/schemas/json/IJsonSchemaCollection.ts +212 -212
- package/src/schemas/json/IJsonSchemaUnit.ts +263 -263
- package/src/schemas/metadata/IMetadataTypeTag.ts +14 -14
- package/src/schemas/metadata/Metadata.ts +669 -669
- package/src/schemas/metadata/MetadataAliasType.ts +57 -57
- package/src/schemas/metadata/MetadataApplication.ts +40 -40
- package/src/schemas/metadata/MetadataArray.ts +47 -47
- package/src/schemas/metadata/MetadataArrayType.ts +51 -51
- package/src/schemas/metadata/MetadataAtomic.ts +85 -85
- package/src/schemas/metadata/MetadataEscaped.ts +45 -45
- package/src/schemas/metadata/MetadataFunction.ts +45 -45
- package/src/schemas/metadata/MetadataObject.ts +46 -46
- package/src/schemas/metadata/MetadataObjectType.ts +137 -137
- package/src/schemas/metadata/MetadataParameter.ts +52 -52
- package/src/schemas/metadata/MetadataProperty.ts +53 -53
- package/src/schemas/metadata/MetadataTemplate.ts +78 -78
- package/src/schemas/metadata/MetadataTuple.ts +28 -28
- package/src/schemas/metadata/MetadataTupleType.ts +61 -61
- package/src/tags/Constant.ts +47 -47
- package/src/tags/ContentMediaType.ts +27 -27
- package/src/tags/Default.ts +52 -52
- package/src/tags/Example.ts +56 -56
- package/src/tags/Examples.ts +56 -56
- package/src/tags/ExclusiveMaximum.ts +44 -44
- package/src/tags/ExclusiveMinimum.ts +44 -44
- package/src/tags/Format.ts +78 -78
- package/src/tags/JsonSchemaPlugin.ts +36 -36
- package/src/tags/MaxItems.ts +31 -31
- package/src/tags/MaxLength.ts +25 -25
- package/src/tags/Maximum.ts +39 -39
- package/src/tags/MinItems.ts +31 -31
- package/src/tags/MinLength.ts +25 -25
- package/src/tags/Minimum.ts +39 -39
- package/src/tags/MultipleOf.ts +42 -42
- package/src/tags/Pattern.ts +49 -49
- package/src/tags/Sequence.ts +37 -37
- package/src/tags/TagBase.ts +102 -102
- package/src/tags/Type.ts +64 -64
- package/src/tags/UniqueItems.ts +34 -34
- package/src/tags/internal/FormatCheatSheet.ts +71 -71
- package/src/transformers/ITransformOptions.ts +70 -70
- package/src/transformers/ImportTransformer.ts +253 -253
- package/src/transformers/NoTransformConfigurationError.ts +16 -16
- package/src/transformers/features/llm/LlmApplicationTransformer.ts +224 -224
- package/src/typings/Equal.ts +18 -18
|
@@ -1,150 +1,150 @@
|
|
|
1
|
-
import { OpenApi } from "@samchon/openapi";
|
|
2
|
-
|
|
3
|
-
import { CommentFactory } from "../../factories/CommentFactory";
|
|
4
|
-
|
|
5
|
-
import { IJsDocTagInfo } from "../../schemas/metadata/IJsDocTagInfo";
|
|
6
|
-
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
7
|
-
import { MetadataObject } from "../../schemas/metadata/MetadataObject";
|
|
8
|
-
|
|
9
|
-
import { PatternUtil } from "../../utils/PatternUtil";
|
|
10
|
-
|
|
11
|
-
import { json_schema_description } from "./json_schema_description";
|
|
12
|
-
import { json_schema_plugin } from "./json_schema_plugin";
|
|
13
|
-
import { json_schema_station } from "./json_schema_station";
|
|
14
|
-
import { json_schema_title } from "./json_schema_title";
|
|
15
|
-
import { metadata_to_pattern } from "./metadata_to_pattern";
|
|
16
|
-
|
|
17
|
-
/** @internal */
|
|
18
|
-
export const json_schema_object = (props: {
|
|
19
|
-
components: OpenApi.IComponents;
|
|
20
|
-
object: MetadataObject;
|
|
21
|
-
}): Array<OpenApi.IJsonSchema.IReference | OpenApi.IJsonSchema.IObject> =>
|
|
22
|
-
json_schema_plugin({
|
|
23
|
-
schema: emplace_object(props),
|
|
24
|
-
tags: props.object.tags,
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
const emplace_object = (props: {
|
|
28
|
-
components: OpenApi.IComponents;
|
|
29
|
-
object: MetadataObject;
|
|
30
|
-
}): OpenApi.IJsonSchema.IReference | OpenApi.IJsonSchema.IObject => {
|
|
31
|
-
if (props.object.type.isLiteral() === true)
|
|
32
|
-
return create_object_schema(props);
|
|
33
|
-
|
|
34
|
-
const key: string = props.object.type.name;
|
|
35
|
-
const $ref: string = `#/components/schemas/${key}`;
|
|
36
|
-
if (props.components.schemas?.[key] !== undefined) return { $ref };
|
|
37
|
-
|
|
38
|
-
const lazy: OpenApi.IJsonSchema = {};
|
|
39
|
-
props.components.schemas ??= {};
|
|
40
|
-
props.components.schemas[key] = lazy;
|
|
41
|
-
Object.assign(lazy, create_object_schema(props));
|
|
42
|
-
return { $ref };
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
/** @internal */
|
|
46
|
-
const create_object_schema = (props: {
|
|
47
|
-
components: OpenApi.IComponents;
|
|
48
|
-
object: MetadataObject;
|
|
49
|
-
}): OpenApi.IJsonSchema.IObject => {
|
|
50
|
-
// ITERATE PROPERTIES
|
|
51
|
-
const properties: Record<string, any> = {};
|
|
52
|
-
const extraMeta: ISuperfluous = {
|
|
53
|
-
patternProperties: {},
|
|
54
|
-
additionalProperties: undefined,
|
|
55
|
-
};
|
|
56
|
-
const required: string[] = [];
|
|
57
|
-
|
|
58
|
-
for (const property of props.object.type.properties) {
|
|
59
|
-
if (
|
|
60
|
-
// FUNCTIONAL TYPE
|
|
61
|
-
property.value.functions.length &&
|
|
62
|
-
property.value.nullable === false &&
|
|
63
|
-
property.value.isRequired() === true &&
|
|
64
|
-
property.value.size() === 0
|
|
65
|
-
)
|
|
66
|
-
continue;
|
|
67
|
-
else if (property.jsDocTags.find((tag) => tag.name === "hidden")) continue; // THE HIDDEN TAG
|
|
68
|
-
|
|
69
|
-
const key: string | null = property.key.getSoleLiteral();
|
|
70
|
-
const schema: OpenApi.IJsonSchema | null = json_schema_station({
|
|
71
|
-
blockNever: true,
|
|
72
|
-
components: props.components,
|
|
73
|
-
attribute: {
|
|
74
|
-
deprecated:
|
|
75
|
-
property.jsDocTags.some((tag) => tag.name === "deprecated") ||
|
|
76
|
-
undefined,
|
|
77
|
-
title: json_schema_title(property),
|
|
78
|
-
description: json_schema_description(property),
|
|
79
|
-
},
|
|
80
|
-
metadata: property.value,
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
if (schema === null) continue;
|
|
84
|
-
if (key !== null) {
|
|
85
|
-
properties[key] = schema;
|
|
86
|
-
if (property.value.isRequired() === true) required.push(key);
|
|
87
|
-
} else {
|
|
88
|
-
const pattern: string = metadata_to_pattern({
|
|
89
|
-
top: true,
|
|
90
|
-
metadata: property.key,
|
|
91
|
-
});
|
|
92
|
-
if (pattern === PatternUtil.STRING)
|
|
93
|
-
extraMeta.additionalProperties = [property.value, schema];
|
|
94
|
-
else extraMeta.patternProperties[pattern] = [property.value, schema];
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return {
|
|
99
|
-
type: "object",
|
|
100
|
-
properties,
|
|
101
|
-
required,
|
|
102
|
-
title: (() => {
|
|
103
|
-
const info: IJsDocTagInfo | undefined = props.object.type.jsDocTags.find(
|
|
104
|
-
(tag) => tag.name === "title",
|
|
105
|
-
);
|
|
106
|
-
return info?.text?.length ? CommentFactory.merge(info.text) : undefined;
|
|
107
|
-
})(),
|
|
108
|
-
description: json_schema_description(props.object.type),
|
|
109
|
-
additionalProperties: join({
|
|
110
|
-
components: props.components,
|
|
111
|
-
extra: extraMeta,
|
|
112
|
-
}),
|
|
113
|
-
};
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
/** @internal */
|
|
117
|
-
const join = (props: {
|
|
118
|
-
components: OpenApi.IComponents;
|
|
119
|
-
extra: ISuperfluous;
|
|
120
|
-
}): OpenApi.IJsonSchema | undefined => {
|
|
121
|
-
// LIST UP METADATA
|
|
122
|
-
const elements: [Metadata, OpenApi.IJsonSchema][] = Object.values(
|
|
123
|
-
props.extra.patternProperties || {},
|
|
124
|
-
);
|
|
125
|
-
if (props.extra.additionalProperties)
|
|
126
|
-
elements.push(props.extra.additionalProperties);
|
|
127
|
-
|
|
128
|
-
// SHORT RETURN
|
|
129
|
-
if (elements.length === 0) return undefined;
|
|
130
|
-
else if (elements.length === 1) return elements[0]![1]!;
|
|
131
|
-
|
|
132
|
-
// MERGE METADATA AND GENERATE VULNERABLE SCHEMA
|
|
133
|
-
const metadata: Metadata = elements
|
|
134
|
-
.map((tuple) => tuple[0])
|
|
135
|
-
.reduce((x, y) => Metadata.merge(x, y));
|
|
136
|
-
return (
|
|
137
|
-
json_schema_station({
|
|
138
|
-
blockNever: true,
|
|
139
|
-
components: props.components,
|
|
140
|
-
attribute: {},
|
|
141
|
-
metadata,
|
|
142
|
-
}) ?? undefined
|
|
143
|
-
);
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
/** @internal */
|
|
147
|
-
interface ISuperfluous {
|
|
148
|
-
additionalProperties?: undefined | [Metadata, OpenApi.IJsonSchema];
|
|
149
|
-
patternProperties: Record<string, [Metadata, OpenApi.IJsonSchema]>;
|
|
150
|
-
}
|
|
1
|
+
import { OpenApi } from "@samchon/openapi";
|
|
2
|
+
|
|
3
|
+
import { CommentFactory } from "../../factories/CommentFactory";
|
|
4
|
+
|
|
5
|
+
import { IJsDocTagInfo } from "../../schemas/metadata/IJsDocTagInfo";
|
|
6
|
+
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
7
|
+
import { MetadataObject } from "../../schemas/metadata/MetadataObject";
|
|
8
|
+
|
|
9
|
+
import { PatternUtil } from "../../utils/PatternUtil";
|
|
10
|
+
|
|
11
|
+
import { json_schema_description } from "./json_schema_description";
|
|
12
|
+
import { json_schema_plugin } from "./json_schema_plugin";
|
|
13
|
+
import { json_schema_station } from "./json_schema_station";
|
|
14
|
+
import { json_schema_title } from "./json_schema_title";
|
|
15
|
+
import { metadata_to_pattern } from "./metadata_to_pattern";
|
|
16
|
+
|
|
17
|
+
/** @internal */
|
|
18
|
+
export const json_schema_object = (props: {
|
|
19
|
+
components: OpenApi.IComponents;
|
|
20
|
+
object: MetadataObject;
|
|
21
|
+
}): Array<OpenApi.IJsonSchema.IReference | OpenApi.IJsonSchema.IObject> =>
|
|
22
|
+
json_schema_plugin({
|
|
23
|
+
schema: emplace_object(props),
|
|
24
|
+
tags: props.object.tags,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const emplace_object = (props: {
|
|
28
|
+
components: OpenApi.IComponents;
|
|
29
|
+
object: MetadataObject;
|
|
30
|
+
}): OpenApi.IJsonSchema.IReference | OpenApi.IJsonSchema.IObject => {
|
|
31
|
+
if (props.object.type.isLiteral() === true)
|
|
32
|
+
return create_object_schema(props);
|
|
33
|
+
|
|
34
|
+
const key: string = props.object.type.name;
|
|
35
|
+
const $ref: string = `#/components/schemas/${key}`;
|
|
36
|
+
if (props.components.schemas?.[key] !== undefined) return { $ref };
|
|
37
|
+
|
|
38
|
+
const lazy: OpenApi.IJsonSchema = {};
|
|
39
|
+
props.components.schemas ??= {};
|
|
40
|
+
props.components.schemas[key] = lazy;
|
|
41
|
+
Object.assign(lazy, create_object_schema(props));
|
|
42
|
+
return { $ref };
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/** @internal */
|
|
46
|
+
const create_object_schema = (props: {
|
|
47
|
+
components: OpenApi.IComponents;
|
|
48
|
+
object: MetadataObject;
|
|
49
|
+
}): OpenApi.IJsonSchema.IObject => {
|
|
50
|
+
// ITERATE PROPERTIES
|
|
51
|
+
const properties: Record<string, any> = {};
|
|
52
|
+
const extraMeta: ISuperfluous = {
|
|
53
|
+
patternProperties: {},
|
|
54
|
+
additionalProperties: undefined,
|
|
55
|
+
};
|
|
56
|
+
const required: string[] = [];
|
|
57
|
+
|
|
58
|
+
for (const property of props.object.type.properties) {
|
|
59
|
+
if (
|
|
60
|
+
// FUNCTIONAL TYPE
|
|
61
|
+
property.value.functions.length &&
|
|
62
|
+
property.value.nullable === false &&
|
|
63
|
+
property.value.isRequired() === true &&
|
|
64
|
+
property.value.size() === 0
|
|
65
|
+
)
|
|
66
|
+
continue;
|
|
67
|
+
else if (property.jsDocTags.find((tag) => tag.name === "hidden")) continue; // THE HIDDEN TAG
|
|
68
|
+
|
|
69
|
+
const key: string | null = property.key.getSoleLiteral();
|
|
70
|
+
const schema: OpenApi.IJsonSchema | null = json_schema_station({
|
|
71
|
+
blockNever: true,
|
|
72
|
+
components: props.components,
|
|
73
|
+
attribute: {
|
|
74
|
+
deprecated:
|
|
75
|
+
property.jsDocTags.some((tag) => tag.name === "deprecated") ||
|
|
76
|
+
undefined,
|
|
77
|
+
title: json_schema_title(property),
|
|
78
|
+
description: json_schema_description(property),
|
|
79
|
+
},
|
|
80
|
+
metadata: property.value,
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
if (schema === null) continue;
|
|
84
|
+
if (key !== null) {
|
|
85
|
+
properties[key] = schema;
|
|
86
|
+
if (property.value.isRequired() === true) required.push(key);
|
|
87
|
+
} else {
|
|
88
|
+
const pattern: string = metadata_to_pattern({
|
|
89
|
+
top: true,
|
|
90
|
+
metadata: property.key,
|
|
91
|
+
});
|
|
92
|
+
if (pattern === PatternUtil.STRING)
|
|
93
|
+
extraMeta.additionalProperties = [property.value, schema];
|
|
94
|
+
else extraMeta.patternProperties[pattern] = [property.value, schema];
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return {
|
|
99
|
+
type: "object",
|
|
100
|
+
properties,
|
|
101
|
+
required,
|
|
102
|
+
title: (() => {
|
|
103
|
+
const info: IJsDocTagInfo | undefined = props.object.type.jsDocTags.find(
|
|
104
|
+
(tag) => tag.name === "title",
|
|
105
|
+
);
|
|
106
|
+
return info?.text?.length ? CommentFactory.merge(info.text) : undefined;
|
|
107
|
+
})(),
|
|
108
|
+
description: json_schema_description(props.object.type),
|
|
109
|
+
additionalProperties: join({
|
|
110
|
+
components: props.components,
|
|
111
|
+
extra: extraMeta,
|
|
112
|
+
}),
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
/** @internal */
|
|
117
|
+
const join = (props: {
|
|
118
|
+
components: OpenApi.IComponents;
|
|
119
|
+
extra: ISuperfluous;
|
|
120
|
+
}): OpenApi.IJsonSchema | undefined => {
|
|
121
|
+
// LIST UP METADATA
|
|
122
|
+
const elements: [Metadata, OpenApi.IJsonSchema][] = Object.values(
|
|
123
|
+
props.extra.patternProperties || {},
|
|
124
|
+
);
|
|
125
|
+
if (props.extra.additionalProperties)
|
|
126
|
+
elements.push(props.extra.additionalProperties);
|
|
127
|
+
|
|
128
|
+
// SHORT RETURN
|
|
129
|
+
if (elements.length === 0) return undefined;
|
|
130
|
+
else if (elements.length === 1) return elements[0]![1]!;
|
|
131
|
+
|
|
132
|
+
// MERGE METADATA AND GENERATE VULNERABLE SCHEMA
|
|
133
|
+
const metadata: Metadata = elements
|
|
134
|
+
.map((tuple) => tuple[0])
|
|
135
|
+
.reduce((x, y) => Metadata.merge(x, y));
|
|
136
|
+
return (
|
|
137
|
+
json_schema_station({
|
|
138
|
+
blockNever: true,
|
|
139
|
+
components: props.components,
|
|
140
|
+
attribute: {},
|
|
141
|
+
metadata,
|
|
142
|
+
}) ?? undefined
|
|
143
|
+
);
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
/** @internal */
|
|
147
|
+
interface ISuperfluous {
|
|
148
|
+
additionalProperties?: undefined | [Metadata, OpenApi.IJsonSchema];
|
|
149
|
+
patternProperties: Record<string, [Metadata, OpenApi.IJsonSchema]>;
|
|
150
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OpenApi } from "@samchon/openapi";
|
|
1
|
+
import { IJsonSchemaAttribute, OpenApi } from "@samchon/openapi";
|
|
2
2
|
|
|
3
3
|
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
4
4
|
import { MetadataAtomic } from "../../schemas/metadata/MetadataAtomic";
|
|
@@ -24,7 +24,7 @@ import { json_schema_tuple } from "./json_schema_tuple";
|
|
|
24
24
|
export const json_schema_station = <BlockNever extends boolean>(props: {
|
|
25
25
|
blockNever: BlockNever;
|
|
26
26
|
components: OpenApi.IComponents;
|
|
27
|
-
attribute:
|
|
27
|
+
attribute: IJsonSchemaAttribute;
|
|
28
28
|
metadata: Metadata;
|
|
29
29
|
}): BlockNever extends true
|
|
30
30
|
? OpenApi.IJsonSchema | null
|
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
2
|
-
|
|
3
|
-
import { PatternUtil } from "../../utils/PatternUtil";
|
|
4
|
-
|
|
5
|
-
import { template_to_pattern } from "./template_to_pattern";
|
|
6
|
-
|
|
7
|
-
/** @internal */
|
|
8
|
-
export const metadata_to_pattern = (props: {
|
|
9
|
-
top: boolean;
|
|
10
|
-
metadata: Metadata;
|
|
11
|
-
}): string => {
|
|
12
|
-
if (props.metadata.atomics.find((a) => a.type === "string") !== undefined)
|
|
13
|
-
return "(.*)";
|
|
14
|
-
|
|
15
|
-
const values: string[] = props.metadata.constants
|
|
16
|
-
.map((c) => {
|
|
17
|
-
if (c.type !== "string") return c.values.map((v) => v.toString());
|
|
18
|
-
return (c.values.map((v) => v.value) as string[]).map((str) =>
|
|
19
|
-
PatternUtil.escape(str),
|
|
20
|
-
);
|
|
21
|
-
})
|
|
22
|
-
.flat();
|
|
23
|
-
for (const a of props.metadata.atomics)
|
|
24
|
-
if (a.type === "number" || a.type === "bigint")
|
|
25
|
-
values.push(PatternUtil.NUMBER);
|
|
26
|
-
else if (a.type === "boolean") values.push(PatternUtil.BOOLEAN);
|
|
27
|
-
for (const { row } of props.metadata.templates)
|
|
28
|
-
values.push(
|
|
29
|
-
"(" +
|
|
30
|
-
template_to_pattern({
|
|
31
|
-
top: false,
|
|
32
|
-
template: row,
|
|
33
|
-
}) +
|
|
34
|
-
")",
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
const pattern: string =
|
|
38
|
-
values.length === 1 ? values[0]! : "(" + values.join("|") + ")";
|
|
39
|
-
return props.top ? PatternUtil.fix(pattern) : pattern;
|
|
40
|
-
};
|
|
1
|
+
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
2
|
+
|
|
3
|
+
import { PatternUtil } from "../../utils/PatternUtil";
|
|
4
|
+
|
|
5
|
+
import { template_to_pattern } from "./template_to_pattern";
|
|
6
|
+
|
|
7
|
+
/** @internal */
|
|
8
|
+
export const metadata_to_pattern = (props: {
|
|
9
|
+
top: boolean;
|
|
10
|
+
metadata: Metadata;
|
|
11
|
+
}): string => {
|
|
12
|
+
if (props.metadata.atomics.find((a) => a.type === "string") !== undefined)
|
|
13
|
+
return "(.*)";
|
|
14
|
+
|
|
15
|
+
const values: string[] = props.metadata.constants
|
|
16
|
+
.map((c) => {
|
|
17
|
+
if (c.type !== "string") return c.values.map((v) => v.toString());
|
|
18
|
+
return (c.values.map((v) => v.value) as string[]).map((str) =>
|
|
19
|
+
PatternUtil.escape(str),
|
|
20
|
+
);
|
|
21
|
+
})
|
|
22
|
+
.flat();
|
|
23
|
+
for (const a of props.metadata.atomics)
|
|
24
|
+
if (a.type === "number" || a.type === "bigint")
|
|
25
|
+
values.push(PatternUtil.NUMBER);
|
|
26
|
+
else if (a.type === "boolean") values.push(PatternUtil.BOOLEAN);
|
|
27
|
+
for (const { row } of props.metadata.templates)
|
|
28
|
+
values.push(
|
|
29
|
+
"(" +
|
|
30
|
+
template_to_pattern({
|
|
31
|
+
top: false,
|
|
32
|
+
template: row,
|
|
33
|
+
}) +
|
|
34
|
+
")",
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const pattern: string =
|
|
38
|
+
values.length === 1 ? values[0]! : "(" + values.join("|") + ")";
|
|
39
|
+
return props.top ? PatternUtil.fix(pattern) : pattern;
|
|
40
|
+
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/** @internal */
|
|
2
|
-
export const postfix_of_tuple = (str: string): string =>
|
|
3
|
-
str.endsWith('"') ? str.slice(0, -1) : `${str} + "`;
|
|
1
|
+
/** @internal */
|
|
2
|
+
export const postfix_of_tuple = (str: string): string =>
|
|
3
|
+
str.endsWith('"') ? str.slice(0, -1) : `${str} + "`;
|
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { MetadataObjectType } from "../../schemas/metadata/MetadataObjectType";
|
|
4
|
-
|
|
5
|
-
import { metadata_to_pattern } from "./metadata_to_pattern";
|
|
6
|
-
|
|
7
|
-
/** @internal */
|
|
8
|
-
export const prune_object_properties = (object: MetadataObjectType) => {
|
|
9
|
-
const input: ts.Expression = ts.factory.createIdentifier("input");
|
|
10
|
-
const key: ts.Expression = ts.factory.createIdentifier("key");
|
|
11
|
-
|
|
12
|
-
const condition: ts.Expression[] = object.properties.map((prop) => {
|
|
13
|
-
const name: string | null = prop.key.getSoleLiteral();
|
|
14
|
-
if (name !== null)
|
|
15
|
-
return ts.factory.createStrictEquality(
|
|
16
|
-
ts.factory.createStringLiteral(name),
|
|
17
|
-
ts.factory.createIdentifier("key"),
|
|
18
|
-
);
|
|
19
|
-
return ts.factory.createCallExpression(
|
|
20
|
-
ts.factory.createIdentifier(
|
|
21
|
-
`RegExp(/${metadata_to_pattern({
|
|
22
|
-
top: true,
|
|
23
|
-
metadata: prop.key,
|
|
24
|
-
})}/).test`,
|
|
25
|
-
),
|
|
26
|
-
undefined,
|
|
27
|
-
[key],
|
|
28
|
-
);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
const statements: ts.Statement[] = [];
|
|
32
|
-
if (condition.length)
|
|
33
|
-
statements.push(
|
|
34
|
-
ts.factory.createIfStatement(
|
|
35
|
-
condition.reduce((a, b) => ts.factory.createLogicalOr(a, b)),
|
|
36
|
-
ts.factory.createContinueStatement(),
|
|
37
|
-
),
|
|
38
|
-
);
|
|
39
|
-
statements.push(
|
|
40
|
-
ts.factory.createExpressionStatement(
|
|
41
|
-
ts.factory.createDeleteExpression(
|
|
42
|
-
ts.factory.createElementAccessExpression(input, key),
|
|
43
|
-
),
|
|
44
|
-
),
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
return ts.factory.createForOfStatement(
|
|
48
|
-
undefined,
|
|
49
|
-
ts.factory.createVariableDeclarationList(
|
|
50
|
-
[
|
|
51
|
-
ts.factory.createVariableDeclaration(
|
|
52
|
-
ts.factory.createIdentifier("key"),
|
|
53
|
-
undefined,
|
|
54
|
-
undefined,
|
|
55
|
-
undefined,
|
|
56
|
-
),
|
|
57
|
-
],
|
|
58
|
-
ts.NodeFlags.Const,
|
|
59
|
-
),
|
|
60
|
-
ts.factory.createCallExpression(
|
|
61
|
-
ts.factory.createIdentifier("Object.keys"),
|
|
62
|
-
undefined,
|
|
63
|
-
[input],
|
|
64
|
-
),
|
|
65
|
-
statements.length === 1
|
|
66
|
-
? statements[0]!
|
|
67
|
-
: ts.factory.createBlock(statements, true),
|
|
68
|
-
);
|
|
69
|
-
};
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { MetadataObjectType } from "../../schemas/metadata/MetadataObjectType";
|
|
4
|
+
|
|
5
|
+
import { metadata_to_pattern } from "./metadata_to_pattern";
|
|
6
|
+
|
|
7
|
+
/** @internal */
|
|
8
|
+
export const prune_object_properties = (object: MetadataObjectType) => {
|
|
9
|
+
const input: ts.Expression = ts.factory.createIdentifier("input");
|
|
10
|
+
const key: ts.Expression = ts.factory.createIdentifier("key");
|
|
11
|
+
|
|
12
|
+
const condition: ts.Expression[] = object.properties.map((prop) => {
|
|
13
|
+
const name: string | null = prop.key.getSoleLiteral();
|
|
14
|
+
if (name !== null)
|
|
15
|
+
return ts.factory.createStrictEquality(
|
|
16
|
+
ts.factory.createStringLiteral(name),
|
|
17
|
+
ts.factory.createIdentifier("key"),
|
|
18
|
+
);
|
|
19
|
+
return ts.factory.createCallExpression(
|
|
20
|
+
ts.factory.createIdentifier(
|
|
21
|
+
`RegExp(/${metadata_to_pattern({
|
|
22
|
+
top: true,
|
|
23
|
+
metadata: prop.key,
|
|
24
|
+
})}/).test`,
|
|
25
|
+
),
|
|
26
|
+
undefined,
|
|
27
|
+
[key],
|
|
28
|
+
);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const statements: ts.Statement[] = [];
|
|
32
|
+
if (condition.length)
|
|
33
|
+
statements.push(
|
|
34
|
+
ts.factory.createIfStatement(
|
|
35
|
+
condition.reduce((a, b) => ts.factory.createLogicalOr(a, b)),
|
|
36
|
+
ts.factory.createContinueStatement(),
|
|
37
|
+
),
|
|
38
|
+
);
|
|
39
|
+
statements.push(
|
|
40
|
+
ts.factory.createExpressionStatement(
|
|
41
|
+
ts.factory.createDeleteExpression(
|
|
42
|
+
ts.factory.createElementAccessExpression(input, key),
|
|
43
|
+
),
|
|
44
|
+
),
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
return ts.factory.createForOfStatement(
|
|
48
|
+
undefined,
|
|
49
|
+
ts.factory.createVariableDeclarationList(
|
|
50
|
+
[
|
|
51
|
+
ts.factory.createVariableDeclaration(
|
|
52
|
+
ts.factory.createIdentifier("key"),
|
|
53
|
+
undefined,
|
|
54
|
+
undefined,
|
|
55
|
+
undefined,
|
|
56
|
+
),
|
|
57
|
+
],
|
|
58
|
+
ts.NodeFlags.Const,
|
|
59
|
+
),
|
|
60
|
+
ts.factory.createCallExpression(
|
|
61
|
+
ts.factory.createIdentifier("Object.keys"),
|
|
62
|
+
undefined,
|
|
63
|
+
[input],
|
|
64
|
+
),
|
|
65
|
+
statements.length === 1
|
|
66
|
+
? statements[0]!
|
|
67
|
+
: ts.factory.createBlock(statements, true),
|
|
68
|
+
);
|
|
69
|
+
};
|