typia 4.1.0 → 4.1.1-dev.20230621
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/factories/internal/metadata/iterate_metadata_array.js +1 -1
- package/lib/factories/internal/metadata/iterate_metadata_array.js.map +1 -1
- package/lib/module.d.ts +2 -2
- package/package.json +3 -2
- package/src/factories/CommentFactory.ts +64 -64
- package/src/factories/IdentifierFactory.ts +59 -59
- package/src/factories/MetadataFactory.ts +30 -30
- package/src/factories/internal/metadata/iterate_metadata_array.ts +1 -2
- package/src/metadata/MetadataObject.ts +118 -118
- package/src/module.ts +2038 -2038
- package/src/programmers/ApplicationProgrammer.ts +47 -47
- package/src/programmers/AssertCloneProgrammer.ts +71 -71
- package/src/programmers/AssertParseProgrammer.ts +66 -66
- package/src/programmers/AssertProgrammer.ts +279 -279
- package/src/programmers/AssertPruneProgrammer.ts +68 -68
- package/src/programmers/AssertStringifyProgrammer.ts +66 -66
- package/src/programmers/CloneProgrammer.ts +587 -587
- package/src/programmers/IsCloneProgrammer.ts +78 -78
- package/src/programmers/IsParseProgrammer.ts +72 -72
- package/src/programmers/IsProgrammer.ts +239 -239
- package/src/programmers/IsPruneProgrammer.ts +73 -73
- package/src/programmers/IsStringifyProgrammer.ts +76 -76
- package/src/programmers/LiteralsProgrammer.ts +60 -60
- package/src/programmers/PruneProgrammer.ts +542 -542
- package/src/programmers/RandomProgrammer.ts +581 -581
- package/src/programmers/StringifyProgrammer.ts +978 -978
- package/src/programmers/ValidateCloneProgrammer.ts +85 -85
- package/src/programmers/ValidateParseProgrammer.ts +70 -70
- package/src/programmers/ValidateProgrammer.ts +305 -305
- package/src/programmers/ValidatePruneProgrammer.ts +78 -78
- package/src/programmers/ValidateStringifyProgrammer.ts +84 -84
- package/src/programmers/internal/application_tuple.ts +57 -57
- package/src/programmers/internal/feature_object_entries.ts +63 -63
- package/src/schemas/IJsonSchema.ts +133 -133
|
@@ -1,76 +1,76 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { IdentifierFactory } from "../factories/IdentifierFactory";
|
|
4
|
-
import { StatementFactory } from "../factories/StatementFactory";
|
|
5
|
-
import { TypeFactory } from "../factories/TypeFactory";
|
|
6
|
-
|
|
7
|
-
import { IProject } from "../transformers/IProject";
|
|
8
|
-
|
|
9
|
-
import { IsProgrammer } from "./IsProgrammer";
|
|
10
|
-
import { StringifyProgrammer } from "./StringifyProgrammer";
|
|
11
|
-
|
|
12
|
-
export namespace IsStringifyProgrammer {
|
|
13
|
-
export const write =
|
|
14
|
-
(project: IProject) =>
|
|
15
|
-
(modulo: ts.LeftHandSideExpression) =>
|
|
16
|
-
(type: ts.Type, name?: string) =>
|
|
17
|
-
ts.factory.createArrowFunction(
|
|
18
|
-
undefined,
|
|
19
|
-
undefined,
|
|
20
|
-
[
|
|
21
|
-
IdentifierFactory.parameter(
|
|
22
|
-
"input",
|
|
23
|
-
ts.factory.createTypeReferenceNode(
|
|
24
|
-
name ??
|
|
25
|
-
TypeFactory.getFullName(project.checker)(type),
|
|
26
|
-
),
|
|
27
|
-
),
|
|
28
|
-
],
|
|
29
|
-
ts.factory.createUnionTypeNode([
|
|
30
|
-
TypeFactory.keyword("string"),
|
|
31
|
-
ts.factory.createLiteralTypeNode(ts.factory.createNull()),
|
|
32
|
-
]),
|
|
33
|
-
undefined,
|
|
34
|
-
ts.factory.createBlock([
|
|
35
|
-
StatementFactory.constant(
|
|
36
|
-
"is",
|
|
37
|
-
IsProgrammer.write({
|
|
38
|
-
...project,
|
|
39
|
-
options: {
|
|
40
|
-
...project.options,
|
|
41
|
-
functional: false,
|
|
42
|
-
numeric: true,
|
|
43
|
-
},
|
|
44
|
-
})(modulo)(false)(type, name),
|
|
45
|
-
),
|
|
46
|
-
StatementFactory.constant(
|
|
47
|
-
"stringify",
|
|
48
|
-
StringifyProgrammer.write({
|
|
49
|
-
...project,
|
|
50
|
-
options: {
|
|
51
|
-
...project.options,
|
|
52
|
-
functional: false,
|
|
53
|
-
numeric: false,
|
|
54
|
-
},
|
|
55
|
-
})(modulo)(type, name),
|
|
56
|
-
),
|
|
57
|
-
ts.factory.createReturnStatement(
|
|
58
|
-
ts.factory.createConditionalExpression(
|
|
59
|
-
ts.factory.createCallExpression(
|
|
60
|
-
ts.factory.createIdentifier("is"),
|
|
61
|
-
undefined,
|
|
62
|
-
[ts.factory.createIdentifier("input")],
|
|
63
|
-
),
|
|
64
|
-
undefined,
|
|
65
|
-
ts.factory.createCallExpression(
|
|
66
|
-
ts.factory.createIdentifier("stringify"),
|
|
67
|
-
undefined,
|
|
68
|
-
[ts.factory.createIdentifier("input")],
|
|
69
|
-
),
|
|
70
|
-
undefined,
|
|
71
|
-
ts.factory.createNull(),
|
|
72
|
-
),
|
|
73
|
-
),
|
|
74
|
-
]),
|
|
75
|
-
);
|
|
76
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { IdentifierFactory } from "../factories/IdentifierFactory";
|
|
4
|
+
import { StatementFactory } from "../factories/StatementFactory";
|
|
5
|
+
import { TypeFactory } from "../factories/TypeFactory";
|
|
6
|
+
|
|
7
|
+
import { IProject } from "../transformers/IProject";
|
|
8
|
+
|
|
9
|
+
import { IsProgrammer } from "./IsProgrammer";
|
|
10
|
+
import { StringifyProgrammer } from "./StringifyProgrammer";
|
|
11
|
+
|
|
12
|
+
export namespace IsStringifyProgrammer {
|
|
13
|
+
export const write =
|
|
14
|
+
(project: IProject) =>
|
|
15
|
+
(modulo: ts.LeftHandSideExpression) =>
|
|
16
|
+
(type: ts.Type, name?: string) =>
|
|
17
|
+
ts.factory.createArrowFunction(
|
|
18
|
+
undefined,
|
|
19
|
+
undefined,
|
|
20
|
+
[
|
|
21
|
+
IdentifierFactory.parameter(
|
|
22
|
+
"input",
|
|
23
|
+
ts.factory.createTypeReferenceNode(
|
|
24
|
+
name ??
|
|
25
|
+
TypeFactory.getFullName(project.checker)(type),
|
|
26
|
+
),
|
|
27
|
+
),
|
|
28
|
+
],
|
|
29
|
+
ts.factory.createUnionTypeNode([
|
|
30
|
+
TypeFactory.keyword("string"),
|
|
31
|
+
ts.factory.createLiteralTypeNode(ts.factory.createNull()),
|
|
32
|
+
]),
|
|
33
|
+
undefined,
|
|
34
|
+
ts.factory.createBlock([
|
|
35
|
+
StatementFactory.constant(
|
|
36
|
+
"is",
|
|
37
|
+
IsProgrammer.write({
|
|
38
|
+
...project,
|
|
39
|
+
options: {
|
|
40
|
+
...project.options,
|
|
41
|
+
functional: false,
|
|
42
|
+
numeric: true,
|
|
43
|
+
},
|
|
44
|
+
})(modulo)(false)(type, name),
|
|
45
|
+
),
|
|
46
|
+
StatementFactory.constant(
|
|
47
|
+
"stringify",
|
|
48
|
+
StringifyProgrammer.write({
|
|
49
|
+
...project,
|
|
50
|
+
options: {
|
|
51
|
+
...project.options,
|
|
52
|
+
functional: false,
|
|
53
|
+
numeric: false,
|
|
54
|
+
},
|
|
55
|
+
})(modulo)(type, name),
|
|
56
|
+
),
|
|
57
|
+
ts.factory.createReturnStatement(
|
|
58
|
+
ts.factory.createConditionalExpression(
|
|
59
|
+
ts.factory.createCallExpression(
|
|
60
|
+
ts.factory.createIdentifier("is"),
|
|
61
|
+
undefined,
|
|
62
|
+
[ts.factory.createIdentifier("input")],
|
|
63
|
+
),
|
|
64
|
+
undefined,
|
|
65
|
+
ts.factory.createCallExpression(
|
|
66
|
+
ts.factory.createIdentifier("stringify"),
|
|
67
|
+
undefined,
|
|
68
|
+
[ts.factory.createIdentifier("input")],
|
|
69
|
+
),
|
|
70
|
+
undefined,
|
|
71
|
+
ts.factory.createNull(),
|
|
72
|
+
),
|
|
73
|
+
),
|
|
74
|
+
]),
|
|
75
|
+
);
|
|
76
|
+
}
|
|
@@ -1,60 +1,60 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { MetadataCollection } from "../factories/MetadataCollection";
|
|
4
|
-
import { MetadataFactory } from "../factories/MetadataFactory";
|
|
5
|
-
|
|
6
|
-
import { Metadata } from "../metadata/Metadata";
|
|
7
|
-
|
|
8
|
-
import { IProject } from "../transformers/IProject";
|
|
9
|
-
|
|
10
|
-
import { Atomic } from "../typings/Atomic";
|
|
11
|
-
|
|
12
|
-
import { ArrayUtil } from "../utils/ArrayUtil";
|
|
13
|
-
|
|
14
|
-
export namespace LiteralsProgrammer {
|
|
15
|
-
export const write = (project: IProject) => (type: ts.Type) => {
|
|
16
|
-
const meta: Metadata = MetadataFactory.analyze(project.checker)({
|
|
17
|
-
resolve: true,
|
|
18
|
-
constant: true,
|
|
19
|
-
absorb: true,
|
|
20
|
-
validate: (meta) => {
|
|
21
|
-
const length: number =
|
|
22
|
-
meta.constants
|
|
23
|
-
.map((c) => c.values.length)
|
|
24
|
-
.reduce((a, b) => a + b, 0) +
|
|
25
|
-
meta.atomics.filter((type) => type === "boolean").length;
|
|
26
|
-
if (0 === length) throw new Error(ErrorMessages.NO);
|
|
27
|
-
else if (meta.size() !== length)
|
|
28
|
-
throw new Error(ErrorMessages.ONLY);
|
|
29
|
-
},
|
|
30
|
-
})(new MetadataCollection())(type);
|
|
31
|
-
const values: Set<Atomic.Type> = new Set([
|
|
32
|
-
...ArrayUtil.flat<Atomic.Type>(meta.constants.map((c) => c.values)),
|
|
33
|
-
...(meta.atomics.filter((type) => type === "boolean").length
|
|
34
|
-
? [true, false]
|
|
35
|
-
: []),
|
|
36
|
-
]);
|
|
37
|
-
return ts.factory.createAsExpression(
|
|
38
|
-
ts.factory.createArrayLiteralExpression(
|
|
39
|
-
[...values].map((v) =>
|
|
40
|
-
typeof v === "boolean"
|
|
41
|
-
? v
|
|
42
|
-
? ts.factory.createTrue()
|
|
43
|
-
: ts.factory.createFalse()
|
|
44
|
-
: typeof v === "number"
|
|
45
|
-
? ts.factory.createNumericLiteral(v)
|
|
46
|
-
: typeof v === "bigint"
|
|
47
|
-
? ts.factory.createBigIntLiteral(v.toString())
|
|
48
|
-
: ts.factory.createStringLiteral(v),
|
|
49
|
-
),
|
|
50
|
-
true,
|
|
51
|
-
),
|
|
52
|
-
ts.factory.createTypeReferenceNode("const"),
|
|
53
|
-
);
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
enum ErrorMessages {
|
|
58
|
-
NO = "Error on typia.literals(): no literal type found.",
|
|
59
|
-
ONLY = "Error on typia.literals(): only literal type allowed.",
|
|
60
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { MetadataCollection } from "../factories/MetadataCollection";
|
|
4
|
+
import { MetadataFactory } from "../factories/MetadataFactory";
|
|
5
|
+
|
|
6
|
+
import { Metadata } from "../metadata/Metadata";
|
|
7
|
+
|
|
8
|
+
import { IProject } from "../transformers/IProject";
|
|
9
|
+
|
|
10
|
+
import { Atomic } from "../typings/Atomic";
|
|
11
|
+
|
|
12
|
+
import { ArrayUtil } from "../utils/ArrayUtil";
|
|
13
|
+
|
|
14
|
+
export namespace LiteralsProgrammer {
|
|
15
|
+
export const write = (project: IProject) => (type: ts.Type) => {
|
|
16
|
+
const meta: Metadata = MetadataFactory.analyze(project.checker)({
|
|
17
|
+
resolve: true,
|
|
18
|
+
constant: true,
|
|
19
|
+
absorb: true,
|
|
20
|
+
validate: (meta) => {
|
|
21
|
+
const length: number =
|
|
22
|
+
meta.constants
|
|
23
|
+
.map((c) => c.values.length)
|
|
24
|
+
.reduce((a, b) => a + b, 0) +
|
|
25
|
+
meta.atomics.filter((type) => type === "boolean").length;
|
|
26
|
+
if (0 === length) throw new Error(ErrorMessages.NO);
|
|
27
|
+
else if (meta.size() !== length)
|
|
28
|
+
throw new Error(ErrorMessages.ONLY);
|
|
29
|
+
},
|
|
30
|
+
})(new MetadataCollection())(type);
|
|
31
|
+
const values: Set<Atomic.Type> = new Set([
|
|
32
|
+
...ArrayUtil.flat<Atomic.Type>(meta.constants.map((c) => c.values)),
|
|
33
|
+
...(meta.atomics.filter((type) => type === "boolean").length
|
|
34
|
+
? [true, false]
|
|
35
|
+
: []),
|
|
36
|
+
]);
|
|
37
|
+
return ts.factory.createAsExpression(
|
|
38
|
+
ts.factory.createArrayLiteralExpression(
|
|
39
|
+
[...values].map((v) =>
|
|
40
|
+
typeof v === "boolean"
|
|
41
|
+
? v
|
|
42
|
+
? ts.factory.createTrue()
|
|
43
|
+
: ts.factory.createFalse()
|
|
44
|
+
: typeof v === "number"
|
|
45
|
+
? ts.factory.createNumericLiteral(v)
|
|
46
|
+
: typeof v === "bigint"
|
|
47
|
+
? ts.factory.createBigIntLiteral(v.toString())
|
|
48
|
+
: ts.factory.createStringLiteral(v),
|
|
49
|
+
),
|
|
50
|
+
true,
|
|
51
|
+
),
|
|
52
|
+
ts.factory.createTypeReferenceNode("const"),
|
|
53
|
+
);
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
enum ErrorMessages {
|
|
58
|
+
NO = "Error on typia.literals(): no literal type found.",
|
|
59
|
+
ONLY = "Error on typia.literals(): only literal type allowed.",
|
|
60
|
+
}
|