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.
- package/lib/programmers/ApplicationProgrammer.js +1 -1
- package/lib/programmers/internal/application_array.js +19 -41
- package/lib/programmers/internal/application_array.js.map +1 -1
- package/lib/programmers/internal/application_definition.d.ts +1 -1
- package/lib/programmers/internal/application_definition.js +8 -8
- package/lib/programmers/internal/application_definition.js.map +1 -1
- package/lib/programmers/internal/application_native.js +3 -3
- package/lib/programmers/internal/application_object.js +4 -4
- package/lib/programmers/internal/application_schema.js +3 -3
- package/lib/programmers/internal/application_schema.js.map +1 -1
- package/lib/programmers/internal/application_tuple.js +8 -30
- package/lib/programmers/internal/application_tuple.js.map +1 -1
- package/lib/schemas/IJsonComponents.d.ts +1 -12
- package/lib/schemas/IJsonSchema.d.ts +1 -1
- package/package.json +1 -1
- package/src/IRandomGenerator.ts +34 -34
- package/src/factories/IdentifierFactory.ts +65 -65
- package/src/factories/MetadataCollection.ts +254 -254
- package/src/factories/MetadataFactory.ts +40 -40
- package/src/factories/MetadataTagFactory.ts +300 -300
- package/src/factories/internal/metadata/emplace_metadata_array.ts +34 -34
- package/src/factories/internal/metadata/emplace_metadata_definition.ts +35 -35
- package/src/factories/internal/metadata/emplace_metadata_object.ts +142 -142
- package/src/factories/internal/metadata/emplace_metadata_tuple.ts +50 -50
- package/src/factories/internal/metadata/explore_metadata.ts +66 -66
- package/src/factories/internal/metadata/iterate_metadata.ts +77 -77
- package/src/factories/internal/metadata/iterate_metadata_array.ts +25 -25
- package/src/factories/internal/metadata/iterate_metadata_collection.ts +130 -130
- package/src/factories/internal/metadata/iterate_metadata_definition.ts +30 -30
- package/src/factories/internal/metadata/iterate_metadata_object.ts +49 -49
- package/src/factories/internal/metadata/iterate_metadata_sort.ts +68 -68
- package/src/factories/internal/metadata/iterate_metadata_tuple.ts +24 -24
- package/src/factories/internal/metadata/iterate_metadata_union.ts +68 -68
- package/src/metadata/IMetadata.ts +27 -27
- package/src/metadata/IMetadataAlias.ts +12 -12
- package/src/metadata/IMetadataApplication.ts +7 -7
- package/src/metadata/IMetadataArray.ts +10 -10
- package/src/metadata/IMetadataCollection.ts +11 -11
- package/src/metadata/IMetadataDictionary.ts +14 -14
- package/src/metadata/IMetadataObject.ts +18 -18
- package/src/metadata/IMetadataProperty.ts +11 -11
- package/src/metadata/IMetadataTuple.ts +10 -10
- package/src/metadata/Metadata.ts +585 -585
- package/src/metadata/MetadataAlias.ts +61 -61
- package/src/metadata/MetadataArray.ts +52 -52
- package/src/metadata/MetadataObject.ts +114 -114
- package/src/metadata/MetadataProperty.ts +64 -64
- package/src/metadata/MetadataTuple.ts +53 -53
- package/src/programmers/ApplicationProgrammer.ts +55 -55
- package/src/programmers/AssertProgrammer.ts +291 -291
- package/src/programmers/CheckerProgrammer.ts +1182 -1182
- package/src/programmers/CloneProgrammer.ts +595 -595
- package/src/programmers/FeatureProgrammer.ts +495 -495
- package/src/programmers/IsProgrammer.ts +250 -250
- package/src/programmers/LiteralsProgrammer.ts +66 -66
- package/src/programmers/PruneProgrammer.ts +550 -550
- package/src/programmers/RandomProgrammer.ts +589 -589
- package/src/programmers/StringifyProgrammer.ts +990 -990
- package/src/programmers/ValidateProgrammer.ts +313 -313
- package/src/programmers/helpers/FunctionImporeter.ts +78 -78
- package/src/programmers/helpers/RandomJoiner.ts +173 -173
- package/src/programmers/helpers/UnionExplorer.ts +301 -301
- package/src/programmers/helpers/UnionPredicator.ts +81 -81
- package/src/programmers/helpers/disable_function_importer_declare.ts +26 -26
- package/src/programmers/internal/JSON_SCHEMA_PREFIX.ts +1 -1
- package/src/programmers/internal/application_array.ts +30 -64
- package/src/programmers/internal/application_boolean.ts +15 -15
- package/src/programmers/internal/application_constant.ts +26 -26
- package/src/programmers/internal/application_default.ts +17 -17
- package/src/programmers/internal/application_definition.ts +45 -45
- package/src/programmers/internal/application_native.ts +39 -39
- package/src/programmers/internal/application_number.ts +74 -74
- package/src/programmers/internal/application_object.ts +167 -167
- package/src/programmers/internal/application_schema.ts +156 -164
- package/src/programmers/internal/application_tuple.ts +47 -77
- package/src/programmers/internal/check_union_array_like.ts +329 -329
- package/src/programmers/internal/feature_object_entries.ts +63 -63
- package/src/programmers/internal/wrap_metadata_rest_tuple.ts +16 -16
- package/src/schemas/IJsonApplication.ts +8 -8
- package/src/schemas/IJsonComponents.ts +34 -45
- package/src/schemas/IJsonSchema.ts +134 -134
- package/src/transformers/CallExpressionTransformer.ts +179 -179
- package/src/transformers/FileTransformer.ts +47 -47
- package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +104 -104
- package/src/transformers/features/miscellaneous/MetadataTransformer.ts +53 -53
- package/src/utils/ArrayUtil.ts +45 -45
- package/src/utils/RandomGenerator.ts +81 -81
|
@@ -1,81 +1,81 @@
|
|
|
1
|
-
import { Metadata } from "../../metadata/Metadata";
|
|
2
|
-
import { MetadataObject } from "../../metadata/MetadataObject";
|
|
3
|
-
import { MetadataProperty } from "../../metadata/MetadataProperty";
|
|
4
|
-
|
|
5
|
-
import { ArrayUtil } from "../../utils/ArrayUtil";
|
|
6
|
-
import { MapUtil } from "../../utils/MapUtil";
|
|
7
|
-
|
|
8
|
-
export namespace UnionPredicator {
|
|
9
|
-
export interface ISpecialized {
|
|
10
|
-
index: number;
|
|
11
|
-
object: MetadataObject;
|
|
12
|
-
property: MetadataProperty;
|
|
13
|
-
neighbour: boolean;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const object = (targets: MetadataObject[]): Array<ISpecialized> => {
|
|
17
|
-
// PROPERTY MATRIX
|
|
18
|
-
const matrix: Map<string, Array<MetadataProperty | null>> = new Map();
|
|
19
|
-
for (const obj of targets)
|
|
20
|
-
for (const prop of obj.properties) {
|
|
21
|
-
const key: string | null = prop.key.getSoleLiteral();
|
|
22
|
-
if (key !== null)
|
|
23
|
-
MapUtil.take(matrix)(key, () =>
|
|
24
|
-
ArrayUtil.repeat(targets.length, () => null),
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
targets.forEach((obj, i) => {
|
|
28
|
-
for (const prop of obj.properties) {
|
|
29
|
-
const key: string | null = prop.key.getSoleLiteral();
|
|
30
|
-
if (key !== null) matrix.get(key)![i] = prop;
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
// EXPLORE SPECIALIZERS
|
|
35
|
-
const output: ISpecialized[] = [];
|
|
36
|
-
targets.forEach((obj, i) => {
|
|
37
|
-
const children: ISpecializedProperty[] = [];
|
|
38
|
-
obj.properties.forEach((prop) => {
|
|
39
|
-
// MUST BE REQUIRED
|
|
40
|
-
if (prop.value.required === false) return;
|
|
41
|
-
const key: string | null = prop.key.getSoleLiteral();
|
|
42
|
-
if (key === null) return;
|
|
43
|
-
|
|
44
|
-
// FIND NEIGHBORHOOD PROPERTIES
|
|
45
|
-
const neighbors: MetadataProperty[] = matrix
|
|
46
|
-
.get(key)!
|
|
47
|
-
.filter(
|
|
48
|
-
(oppo, k) => i !== k && oppo !== null,
|
|
49
|
-
) as MetadataProperty[];
|
|
50
|
-
|
|
51
|
-
// NO NEIGHBORHOOD
|
|
52
|
-
const unique: boolean =
|
|
53
|
-
neighbors.length === 0 ||
|
|
54
|
-
neighbors.every(
|
|
55
|
-
(n) => !Metadata.intersects(prop.value, n.value),
|
|
56
|
-
);
|
|
57
|
-
if (unique === true)
|
|
58
|
-
children.push({
|
|
59
|
-
property: prop,
|
|
60
|
-
neighbour: neighbors.length !== 0,
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
if (children.length === 0) return;
|
|
64
|
-
|
|
65
|
-
const top: ISpecializedProperty =
|
|
66
|
-
children.find((child) => child.property.value.isConstant()) ||
|
|
67
|
-
children[0]!;
|
|
68
|
-
output.push({
|
|
69
|
-
index: i,
|
|
70
|
-
object: obj,
|
|
71
|
-
...top,
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
return output;
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
interface ISpecializedProperty {
|
|
79
|
-
property: MetadataProperty;
|
|
80
|
-
neighbour: boolean;
|
|
81
|
-
}
|
|
1
|
+
import { Metadata } from "../../metadata/Metadata";
|
|
2
|
+
import { MetadataObject } from "../../metadata/MetadataObject";
|
|
3
|
+
import { MetadataProperty } from "../../metadata/MetadataProperty";
|
|
4
|
+
|
|
5
|
+
import { ArrayUtil } from "../../utils/ArrayUtil";
|
|
6
|
+
import { MapUtil } from "../../utils/MapUtil";
|
|
7
|
+
|
|
8
|
+
export namespace UnionPredicator {
|
|
9
|
+
export interface ISpecialized {
|
|
10
|
+
index: number;
|
|
11
|
+
object: MetadataObject;
|
|
12
|
+
property: MetadataProperty;
|
|
13
|
+
neighbour: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const object = (targets: MetadataObject[]): Array<ISpecialized> => {
|
|
17
|
+
// PROPERTY MATRIX
|
|
18
|
+
const matrix: Map<string, Array<MetadataProperty | null>> = new Map();
|
|
19
|
+
for (const obj of targets)
|
|
20
|
+
for (const prop of obj.properties) {
|
|
21
|
+
const key: string | null = prop.key.getSoleLiteral();
|
|
22
|
+
if (key !== null)
|
|
23
|
+
MapUtil.take(matrix)(key, () =>
|
|
24
|
+
ArrayUtil.repeat(targets.length, () => null),
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
targets.forEach((obj, i) => {
|
|
28
|
+
for (const prop of obj.properties) {
|
|
29
|
+
const key: string | null = prop.key.getSoleLiteral();
|
|
30
|
+
if (key !== null) matrix.get(key)![i] = prop;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// EXPLORE SPECIALIZERS
|
|
35
|
+
const output: ISpecialized[] = [];
|
|
36
|
+
targets.forEach((obj, i) => {
|
|
37
|
+
const children: ISpecializedProperty[] = [];
|
|
38
|
+
obj.properties.forEach((prop) => {
|
|
39
|
+
// MUST BE REQUIRED
|
|
40
|
+
if (prop.value.required === false) return;
|
|
41
|
+
const key: string | null = prop.key.getSoleLiteral();
|
|
42
|
+
if (key === null) return;
|
|
43
|
+
|
|
44
|
+
// FIND NEIGHBORHOOD PROPERTIES
|
|
45
|
+
const neighbors: MetadataProperty[] = matrix
|
|
46
|
+
.get(key)!
|
|
47
|
+
.filter(
|
|
48
|
+
(oppo, k) => i !== k && oppo !== null,
|
|
49
|
+
) as MetadataProperty[];
|
|
50
|
+
|
|
51
|
+
// NO NEIGHBORHOOD
|
|
52
|
+
const unique: boolean =
|
|
53
|
+
neighbors.length === 0 ||
|
|
54
|
+
neighbors.every(
|
|
55
|
+
(n) => !Metadata.intersects(prop.value, n.value),
|
|
56
|
+
);
|
|
57
|
+
if (unique === true)
|
|
58
|
+
children.push({
|
|
59
|
+
property: prop,
|
|
60
|
+
neighbour: neighbors.length !== 0,
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
if (children.length === 0) return;
|
|
64
|
+
|
|
65
|
+
const top: ISpecializedProperty =
|
|
66
|
+
children.find((child) => child.property.value.isConstant()) ||
|
|
67
|
+
children[0]!;
|
|
68
|
+
output.push({
|
|
69
|
+
index: i,
|
|
70
|
+
object: obj,
|
|
71
|
+
...top,
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
return output;
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
interface ISpecializedProperty {
|
|
79
|
+
property: MetadataProperty;
|
|
80
|
+
neighbour: boolean;
|
|
81
|
+
}
|
|
@@ -1,26 +1,26 @@
|
|
|
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
|
-
emplaceUnion: (
|
|
17
|
-
prefix: string,
|
|
18
|
-
name: string,
|
|
19
|
-
factory: () => ts.ArrowFunction,
|
|
20
|
-
): string => importer.emplaceUnion(prefix, name, factory),
|
|
21
|
-
trace: (): void => importer.trace(),
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
type MethodOnly<T> = {
|
|
25
|
-
[P in keyof T]: T[P] extends Function ? T[P] : never;
|
|
26
|
-
};
|
|
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
|
+
emplaceUnion: (
|
|
17
|
+
prefix: string,
|
|
18
|
+
name: string,
|
|
19
|
+
factory: () => ts.ArrowFunction,
|
|
20
|
+
): string => importer.emplaceUnion(prefix, name, factory),
|
|
21
|
+
trace: (): void => importer.trace(),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
type MethodOnly<T> = {
|
|
25
|
+
[P in keyof T]: T[P] extends Function ? T[P] : never;
|
|
26
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const JSON_COMPONENTS_PREFIX = "#/components";
|
|
1
|
+
export const JSON_COMPONENTS_PREFIX = "#/components";
|
|
@@ -1,64 +1,30 @@
|
|
|
1
|
-
import { MetadataArray } from "../../metadata/MetadataArray";
|
|
2
|
-
import { IJsonComponents } from "../../schemas/IJsonComponents";
|
|
3
|
-
import { IJsonSchema } from "../../schemas/IJsonSchema";
|
|
4
|
-
|
|
5
|
-
import { ApplicationProgrammer } from "../ApplicationProgrammer";
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
(
|
|
14
|
-
(
|
|
15
|
-
(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
};
|
|
32
|
-
if (array.recursive === false) {
|
|
33
|
-
for (const tag of attribute["x-typia-metaTags"] ?? [])
|
|
34
|
-
if (tag.kind === "minItems") schema.minItems = tag.value;
|
|
35
|
-
else if (tag.kind === "maxItems")
|
|
36
|
-
schema.maxItems = tag.value;
|
|
37
|
-
}
|
|
38
|
-
return schema;
|
|
39
|
-
};
|
|
40
|
-
if (array.recursive === false) return generator();
|
|
41
|
-
|
|
42
|
-
// KEY
|
|
43
|
-
const key: string =
|
|
44
|
-
options.purpose === "ajv"
|
|
45
|
-
? array.name
|
|
46
|
-
: `${array.name}${nullable ? ".Nullable" : ""}`;
|
|
47
|
-
const $id: string = `${JSON_COMPONENTS_PREFIX}/arrays/${key}`;
|
|
48
|
-
|
|
49
|
-
// REFERENCE
|
|
50
|
-
if (components.arrays?.[key] === undefined) {
|
|
51
|
-
components.arrays ??= {};
|
|
52
|
-
components.arrays[key] = {} as any;
|
|
53
|
-
|
|
54
|
-
const repeated: IJsonComponents.IArray = {
|
|
55
|
-
...generator(),
|
|
56
|
-
$id: options.purpose === "ajv" ? $id : undefined,
|
|
57
|
-
$recursiveAnchor: options.purpose === "ajv" || undefined,
|
|
58
|
-
};
|
|
59
|
-
components.arrays[key] = repeated;
|
|
60
|
-
}
|
|
61
|
-
return options.purpose === "ajv" && array.recursive
|
|
62
|
-
? { ...attribute, $recursiveRef: $id }
|
|
63
|
-
: { ...attribute, $ref: $id };
|
|
64
|
-
};
|
|
1
|
+
import { MetadataArray } from "../../metadata/MetadataArray";
|
|
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_array =
|
|
12
|
+
(options: ApplicationProgrammer.IOptions) =>
|
|
13
|
+
(components: IJsonComponents) =>
|
|
14
|
+
(array: MetadataArray) =>
|
|
15
|
+
(attribute: IJsonSchema.IAttribute): IJsonSchema.IArray => {
|
|
16
|
+
// SCHEMA
|
|
17
|
+
const schema: IJsonSchema.IArray = {
|
|
18
|
+
...attribute,
|
|
19
|
+
type: "array",
|
|
20
|
+
items: application_schema(options)(false)(components)(array.value)(
|
|
21
|
+
attribute,
|
|
22
|
+
),
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// RANGE
|
|
26
|
+
for (const tag of attribute["x-typia-metaTags"] ?? [])
|
|
27
|
+
if (tag.kind === "minItems") schema.minItems = tag.value;
|
|
28
|
+
else if (tag.kind === "maxItems") schema.maxItems = tag.value;
|
|
29
|
+
return schema;
|
|
30
|
+
};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { IJsonSchema } from "../../module";
|
|
2
|
-
import { application_default } from "./application_default";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @internal
|
|
6
|
-
*/
|
|
7
|
-
export const application_boolean = (
|
|
8
|
-
attribute: IJsonSchema.IAttribute,
|
|
9
|
-
): IJsonSchema.IBoolean => ({
|
|
10
|
-
...attribute,
|
|
11
|
-
default: application_default(attribute)(
|
|
12
|
-
(alias) => alias === "true" || alias === "false",
|
|
13
|
-
)((str) => Boolean(str)),
|
|
14
|
-
type: "boolean",
|
|
15
|
-
});
|
|
1
|
+
import { IJsonSchema } from "../../module";
|
|
2
|
+
import { application_default } from "./application_default";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export const application_boolean = (
|
|
8
|
+
attribute: IJsonSchema.IAttribute,
|
|
9
|
+
): IJsonSchema.IBoolean => ({
|
|
10
|
+
...attribute,
|
|
11
|
+
default: application_default(attribute)(
|
|
12
|
+
(alias) => alias === "true" || alias === "false",
|
|
13
|
+
)((str) => Boolean(str)),
|
|
14
|
+
type: "boolean",
|
|
15
|
+
});
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { MetadataConstant } from "../../metadata/MetadataConstant";
|
|
2
|
-
import { IJsonSchema } from "../../schemas/IJsonSchema";
|
|
3
|
-
|
|
4
|
-
import { application_default } from "./application_default";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @internal
|
|
8
|
-
*/
|
|
9
|
-
export const application_constant =
|
|
10
|
-
(constant: MetadataConstant) =>
|
|
11
|
-
(attribute: IJsonSchema.IAttribute): IJsonSchema.IEnumeration<any> => ({
|
|
12
|
-
...attribute,
|
|
13
|
-
type: constant.type,
|
|
14
|
-
enum: constant.values as any,
|
|
15
|
-
default: application_default(attribute)((alias) =>
|
|
16
|
-
constant.values.some((v) => v.toString() === alias),
|
|
17
|
-
)(
|
|
18
|
-
constant.type === "string"
|
|
19
|
-
? (str) => str
|
|
20
|
-
: constant.type === "number"
|
|
21
|
-
? (str) => Number(str)
|
|
22
|
-
: constant.type === "boolean"
|
|
23
|
-
? (str) => Boolean(str)
|
|
24
|
-
: (str) => BigInt(str) as any,
|
|
25
|
-
),
|
|
26
|
-
});
|
|
1
|
+
import { MetadataConstant } from "../../metadata/MetadataConstant";
|
|
2
|
+
import { IJsonSchema } from "../../schemas/IJsonSchema";
|
|
3
|
+
|
|
4
|
+
import { application_default } from "./application_default";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export const application_constant =
|
|
10
|
+
(constant: MetadataConstant) =>
|
|
11
|
+
(attribute: IJsonSchema.IAttribute): IJsonSchema.IEnumeration<any> => ({
|
|
12
|
+
...attribute,
|
|
13
|
+
type: constant.type,
|
|
14
|
+
enum: constant.values as any,
|
|
15
|
+
default: application_default(attribute)((alias) =>
|
|
16
|
+
constant.values.some((v) => v.toString() === alias),
|
|
17
|
+
)(
|
|
18
|
+
constant.type === "string"
|
|
19
|
+
? (str) => str
|
|
20
|
+
: constant.type === "number"
|
|
21
|
+
? (str) => Number(str)
|
|
22
|
+
: constant.type === "boolean"
|
|
23
|
+
? (str) => Boolean(str)
|
|
24
|
+
: (str) => BigInt(str) as any,
|
|
25
|
+
),
|
|
26
|
+
});
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { IJsonSchema } from "../../schemas/IJsonSchema";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @internal
|
|
5
|
-
*/
|
|
6
|
-
export const application_default =
|
|
7
|
-
(attribute: IJsonSchema.IAttribute) =>
|
|
8
|
-
(pred: (value: string) => boolean) =>
|
|
9
|
-
<T>(caster: (str: string) => T): T | undefined => {
|
|
10
|
-
const defaults = (attribute["x-typia-jsDocTags"] ?? []).filter(
|
|
11
|
-
(tag) => tag.name === "default",
|
|
12
|
-
);
|
|
13
|
-
for (const alias of defaults)
|
|
14
|
-
if (alias.text?.length && pred(alias.text[0]!.text))
|
|
15
|
-
return caster(alias.text[0]!.text);
|
|
16
|
-
return undefined;
|
|
17
|
-
};
|
|
1
|
+
import { IJsonSchema } from "../../schemas/IJsonSchema";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
export const application_default =
|
|
7
|
+
(attribute: IJsonSchema.IAttribute) =>
|
|
8
|
+
(pred: (value: string) => boolean) =>
|
|
9
|
+
<T>(caster: (str: string) => T): T | undefined => {
|
|
10
|
+
const defaults = (attribute["x-typia-jsDocTags"] ?? []).filter(
|
|
11
|
+
(tag) => tag.name === "default",
|
|
12
|
+
);
|
|
13
|
+
for (const alias of defaults)
|
|
14
|
+
if (alias.text?.length && pred(alias.text[0]!.text))
|
|
15
|
+
return caster(alias.text[0]!.text);
|
|
16
|
+
return undefined;
|
|
17
|
+
};
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import { MetadataAlias } from "../../metadata/MetadataAlias";
|
|
2
|
-
import { IJsonComponents } from "../../schemas/IJsonComponents";
|
|
3
|
-
|
|
4
|
-
import { IJsonSchema } from "../../module";
|
|
5
|
-
import { ApplicationProgrammer } from "../ApplicationProgrammer";
|
|
6
|
-
import { JSON_COMPONENTS_PREFIX } from "./JSON_SCHEMA_PREFIX";
|
|
7
|
-
import { application_schema } from "./application_schema";
|
|
8
|
-
|
|
9
|
-
export const
|
|
10
|
-
(options: ApplicationProgrammer.IOptions) =>
|
|
11
|
-
<BlockNever extends boolean>(blockNever: BlockNever) =>
|
|
12
|
-
(components: IJsonComponents) =>
|
|
13
|
-
(alias: MetadataAlias) =>
|
|
14
|
-
(
|
|
15
|
-
nullable: boolean,
|
|
16
|
-
): IJsonSchema.IReference | IJsonSchema.IRecursiveReference => {
|
|
17
|
-
const key: string =
|
|
18
|
-
options.purpose === "ajv"
|
|
19
|
-
? alias.name
|
|
20
|
-
: `${alias.name}${nullable ? ".Nullable" : ""}`;
|
|
21
|
-
const $id: string = `${JSON_COMPONENTS_PREFIX}/aliases/${key}`;
|
|
22
|
-
|
|
23
|
-
// TEMPORARY ASSIGNMENT
|
|
24
|
-
if (components.
|
|
25
|
-
components.
|
|
26
|
-
components.
|
|
27
|
-
$id: key,
|
|
28
|
-
} as any;
|
|
29
|
-
|
|
30
|
-
// GENERATE SCHEM
|
|
31
|
-
const schema: IJsonSchema = application_schema(options)(blockNever)(
|
|
32
|
-
components,
|
|
33
|
-
)(alias.value)({})!;
|
|
34
|
-
components.
|
|
35
|
-
components.
|
|
36
|
-
$id: options.purpose === "ajv" ? $id : undefined,
|
|
37
|
-
$recursiveAnchor:
|
|
38
|
-
(options.purpose === "ajv" && alias.recursive) || undefined,
|
|
39
|
-
...schema,
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
return options.purpose === "ajv" && alias.recursive
|
|
43
|
-
? { $recursiveRef: $id }
|
|
44
|
-
: { $ref: $id };
|
|
45
|
-
};
|
|
1
|
+
import { MetadataAlias } from "../../metadata/MetadataAlias";
|
|
2
|
+
import { IJsonComponents } from "../../schemas/IJsonComponents";
|
|
3
|
+
|
|
4
|
+
import { IJsonSchema } from "../../module";
|
|
5
|
+
import { ApplicationProgrammer } from "../ApplicationProgrammer";
|
|
6
|
+
import { JSON_COMPONENTS_PREFIX } from "./JSON_SCHEMA_PREFIX";
|
|
7
|
+
import { application_schema } from "./application_schema";
|
|
8
|
+
|
|
9
|
+
export const application_alias =
|
|
10
|
+
(options: ApplicationProgrammer.IOptions) =>
|
|
11
|
+
<BlockNever extends boolean>(blockNever: BlockNever) =>
|
|
12
|
+
(components: IJsonComponents) =>
|
|
13
|
+
(alias: MetadataAlias) =>
|
|
14
|
+
(
|
|
15
|
+
nullable: boolean,
|
|
16
|
+
): IJsonSchema.IReference | IJsonSchema.IRecursiveReference => {
|
|
17
|
+
const key: string =
|
|
18
|
+
options.purpose === "ajv"
|
|
19
|
+
? alias.name
|
|
20
|
+
: `${alias.name}${nullable ? ".Nullable" : ""}`;
|
|
21
|
+
const $id: string = `${JSON_COMPONENTS_PREFIX}/aliases/${key}`;
|
|
22
|
+
|
|
23
|
+
// TEMPORARY ASSIGNMENT
|
|
24
|
+
if (components.schemas?.[key] === undefined) {
|
|
25
|
+
components.schemas ??= {};
|
|
26
|
+
components.schemas[key] = {
|
|
27
|
+
$id: key,
|
|
28
|
+
} as any;
|
|
29
|
+
|
|
30
|
+
// GENERATE SCHEM
|
|
31
|
+
const schema: IJsonSchema = application_schema(options)(blockNever)(
|
|
32
|
+
components,
|
|
33
|
+
)(alias.value)({})!;
|
|
34
|
+
components.schemas ??= {};
|
|
35
|
+
components.schemas[key] = {
|
|
36
|
+
$id: options.purpose === "ajv" ? $id : undefined,
|
|
37
|
+
$recursiveAnchor:
|
|
38
|
+
(options.purpose === "ajv" && alias.recursive) || undefined,
|
|
39
|
+
...schema,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
return options.purpose === "ajv" && alias.recursive
|
|
43
|
+
? { $recursiveRef: $id }
|
|
44
|
+
: { $ref: $id };
|
|
45
|
+
};
|
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
import { IJsonComponents } from "../../schemas/IJsonComponents";
|
|
2
|
-
|
|
3
|
-
import { IJsonSchema } from "../../module";
|
|
4
|
-
import { ApplicationProgrammer } from "../ApplicationProgrammer";
|
|
5
|
-
import { JSON_COMPONENTS_PREFIX } from "./JSON_SCHEMA_PREFIX";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @internal
|
|
9
|
-
*/
|
|
10
|
-
export const application_native =
|
|
11
|
-
(options: ApplicationProgrammer.IOptions) =>
|
|
12
|
-
(components: IJsonComponents) =>
|
|
13
|
-
(name: string) =>
|
|
14
|
-
(props: {
|
|
15
|
-
nullable: boolean;
|
|
16
|
-
attribute: IJsonSchema.IAttribute;
|
|
17
|
-
}): IJsonSchema.IReference => {
|
|
18
|
-
const key: string =
|
|
19
|
-
options.purpose === "ajv"
|
|
20
|
-
? name
|
|
21
|
-
: `${name}${props.nullable ? ".Nullable" : ""}`;
|
|
22
|
-
if (components.
|
|
23
|
-
components.
|
|
24
|
-
components.
|
|
25
|
-
type: "object",
|
|
26
|
-
$id:
|
|
27
|
-
options.purpose === "ajv"
|
|
28
|
-
? `${JSON_COMPONENTS_PREFIX}/objects/${key}`
|
|
29
|
-
: undefined,
|
|
30
|
-
properties: {},
|
|
31
|
-
nullable:
|
|
32
|
-
options.purpose === "swagger" ? props.nullable : undefined,
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
return {
|
|
36
|
-
...props.attribute,
|
|
37
|
-
$ref: `${JSON_COMPONENTS_PREFIX}/objects/${key}`,
|
|
38
|
-
};
|
|
39
|
-
};
|
|
1
|
+
import { IJsonComponents } from "../../schemas/IJsonComponents";
|
|
2
|
+
|
|
3
|
+
import { IJsonSchema } from "../../module";
|
|
4
|
+
import { ApplicationProgrammer } from "../ApplicationProgrammer";
|
|
5
|
+
import { JSON_COMPONENTS_PREFIX } from "./JSON_SCHEMA_PREFIX";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export const application_native =
|
|
11
|
+
(options: ApplicationProgrammer.IOptions) =>
|
|
12
|
+
(components: IJsonComponents) =>
|
|
13
|
+
(name: string) =>
|
|
14
|
+
(props: {
|
|
15
|
+
nullable: boolean;
|
|
16
|
+
attribute: IJsonSchema.IAttribute;
|
|
17
|
+
}): IJsonSchema.IReference => {
|
|
18
|
+
const key: string =
|
|
19
|
+
options.purpose === "ajv"
|
|
20
|
+
? name
|
|
21
|
+
: `${name}${props.nullable ? ".Nullable" : ""}`;
|
|
22
|
+
if (components.schemas?.[key] === undefined) {
|
|
23
|
+
components.schemas ??= {};
|
|
24
|
+
components.schemas[key] ??= {
|
|
25
|
+
type: "object",
|
|
26
|
+
$id:
|
|
27
|
+
options.purpose === "ajv"
|
|
28
|
+
? `${JSON_COMPONENTS_PREFIX}/objects/${key}`
|
|
29
|
+
: undefined,
|
|
30
|
+
properties: {},
|
|
31
|
+
nullable:
|
|
32
|
+
options.purpose === "swagger" ? props.nullable : undefined,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
...props.attribute,
|
|
37
|
+
$ref: `${JSON_COMPONENTS_PREFIX}/objects/${key}`,
|
|
38
|
+
};
|
|
39
|
+
};
|