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,78 +1,78 @@
|
|
|
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 { PruneProgrammer } from "./PruneProgrammer";
|
|
10
|
-
import { ValidateProgrammer } from "./ValidateProgrammer";
|
|
11
|
-
|
|
12
|
-
export namespace ValidatePruneProgrammer {
|
|
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
|
-
TypeFactory.keyword("any"),
|
|
24
|
-
),
|
|
25
|
-
],
|
|
26
|
-
ts.factory.createTypeReferenceNode(
|
|
27
|
-
`typia.IValidation<${
|
|
28
|
-
name ?? TypeFactory.getFullName(project.checker)(type)
|
|
29
|
-
}>`,
|
|
30
|
-
),
|
|
31
|
-
undefined,
|
|
32
|
-
ts.factory.createBlock([
|
|
33
|
-
StatementFactory.constant(
|
|
34
|
-
"validate",
|
|
35
|
-
ValidateProgrammer.write({
|
|
36
|
-
...project,
|
|
37
|
-
options: {
|
|
38
|
-
...project.options,
|
|
39
|
-
functional: false,
|
|
40
|
-
numeric: true,
|
|
41
|
-
},
|
|
42
|
-
})(modulo)(false)(type, name),
|
|
43
|
-
),
|
|
44
|
-
StatementFactory.constant(
|
|
45
|
-
"prune",
|
|
46
|
-
PruneProgrammer.write({
|
|
47
|
-
...project,
|
|
48
|
-
options: {
|
|
49
|
-
...project.options,
|
|
50
|
-
functional: false,
|
|
51
|
-
numeric: false,
|
|
52
|
-
},
|
|
53
|
-
})(modulo)(type, name),
|
|
54
|
-
),
|
|
55
|
-
StatementFactory.constant(
|
|
56
|
-
"output",
|
|
57
|
-
ts.factory.createCallExpression(
|
|
58
|
-
ts.factory.createIdentifier("validate"),
|
|
59
|
-
undefined,
|
|
60
|
-
[ts.factory.createIdentifier("input")],
|
|
61
|
-
),
|
|
62
|
-
),
|
|
63
|
-
ts.factory.createIfStatement(
|
|
64
|
-
ts.factory.createIdentifier("output.success"),
|
|
65
|
-
ts.factory.createExpressionStatement(
|
|
66
|
-
ts.factory.createCallExpression(
|
|
67
|
-
ts.factory.createIdentifier("prune"),
|
|
68
|
-
undefined,
|
|
69
|
-
[ts.factory.createIdentifier("input")],
|
|
70
|
-
),
|
|
71
|
-
),
|
|
72
|
-
),
|
|
73
|
-
ts.factory.createReturnStatement(
|
|
74
|
-
ts.factory.createIdentifier("output"),
|
|
75
|
-
),
|
|
76
|
-
]),
|
|
77
|
-
);
|
|
78
|
-
}
|
|
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 { PruneProgrammer } from "./PruneProgrammer";
|
|
10
|
+
import { ValidateProgrammer } from "./ValidateProgrammer";
|
|
11
|
+
|
|
12
|
+
export namespace ValidatePruneProgrammer {
|
|
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
|
+
TypeFactory.keyword("any"),
|
|
24
|
+
),
|
|
25
|
+
],
|
|
26
|
+
ts.factory.createTypeReferenceNode(
|
|
27
|
+
`typia.IValidation<${
|
|
28
|
+
name ?? TypeFactory.getFullName(project.checker)(type)
|
|
29
|
+
}>`,
|
|
30
|
+
),
|
|
31
|
+
undefined,
|
|
32
|
+
ts.factory.createBlock([
|
|
33
|
+
StatementFactory.constant(
|
|
34
|
+
"validate",
|
|
35
|
+
ValidateProgrammer.write({
|
|
36
|
+
...project,
|
|
37
|
+
options: {
|
|
38
|
+
...project.options,
|
|
39
|
+
functional: false,
|
|
40
|
+
numeric: true,
|
|
41
|
+
},
|
|
42
|
+
})(modulo)(false)(type, name),
|
|
43
|
+
),
|
|
44
|
+
StatementFactory.constant(
|
|
45
|
+
"prune",
|
|
46
|
+
PruneProgrammer.write({
|
|
47
|
+
...project,
|
|
48
|
+
options: {
|
|
49
|
+
...project.options,
|
|
50
|
+
functional: false,
|
|
51
|
+
numeric: false,
|
|
52
|
+
},
|
|
53
|
+
})(modulo)(type, name),
|
|
54
|
+
),
|
|
55
|
+
StatementFactory.constant(
|
|
56
|
+
"output",
|
|
57
|
+
ts.factory.createCallExpression(
|
|
58
|
+
ts.factory.createIdentifier("validate"),
|
|
59
|
+
undefined,
|
|
60
|
+
[ts.factory.createIdentifier("input")],
|
|
61
|
+
),
|
|
62
|
+
),
|
|
63
|
+
ts.factory.createIfStatement(
|
|
64
|
+
ts.factory.createIdentifier("output.success"),
|
|
65
|
+
ts.factory.createExpressionStatement(
|
|
66
|
+
ts.factory.createCallExpression(
|
|
67
|
+
ts.factory.createIdentifier("prune"),
|
|
68
|
+
undefined,
|
|
69
|
+
[ts.factory.createIdentifier("input")],
|
|
70
|
+
),
|
|
71
|
+
),
|
|
72
|
+
),
|
|
73
|
+
ts.factory.createReturnStatement(
|
|
74
|
+
ts.factory.createIdentifier("output"),
|
|
75
|
+
),
|
|
76
|
+
]),
|
|
77
|
+
);
|
|
78
|
+
}
|
|
@@ -1,84 +1,84 @@
|
|
|
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 { StringifyProgrammer } from "./StringifyProgrammer";
|
|
10
|
-
import { ValidateProgrammer } from "./ValidateProgrammer";
|
|
11
|
-
|
|
12
|
-
export namespace ValidateStringifyProgrammer {
|
|
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.createTypeReferenceNode("typia.IValidation<string>"),
|
|
30
|
-
undefined,
|
|
31
|
-
ts.factory.createBlock([
|
|
32
|
-
StatementFactory.constant(
|
|
33
|
-
"validate",
|
|
34
|
-
ValidateProgrammer.write({
|
|
35
|
-
...project,
|
|
36
|
-
options: {
|
|
37
|
-
...project.options,
|
|
38
|
-
functional: false,
|
|
39
|
-
numeric: true,
|
|
40
|
-
},
|
|
41
|
-
})(modulo)(false)(type, name),
|
|
42
|
-
),
|
|
43
|
-
StatementFactory.constant(
|
|
44
|
-
"stringify",
|
|
45
|
-
StringifyProgrammer.write({
|
|
46
|
-
...project,
|
|
47
|
-
options: {
|
|
48
|
-
...project.options,
|
|
49
|
-
functional: false,
|
|
50
|
-
numeric: false,
|
|
51
|
-
},
|
|
52
|
-
})(modulo)(type, name),
|
|
53
|
-
),
|
|
54
|
-
StatementFactory.constant(
|
|
55
|
-
"output",
|
|
56
|
-
ts.factory.createAsExpression(
|
|
57
|
-
ts.factory.createCallExpression(
|
|
58
|
-
ts.factory.createIdentifier("validate"),
|
|
59
|
-
undefined,
|
|
60
|
-
[ts.factory.createIdentifier("input")],
|
|
61
|
-
),
|
|
62
|
-
TypeFactory.keyword("any"),
|
|
63
|
-
),
|
|
64
|
-
),
|
|
65
|
-
ts.factory.createIfStatement(
|
|
66
|
-
ts.factory.createIdentifier("output.success"),
|
|
67
|
-
ts.factory.createExpressionStatement(
|
|
68
|
-
ts.factory.createBinaryExpression(
|
|
69
|
-
ts.factory.createIdentifier("output.data"),
|
|
70
|
-
ts.SyntaxKind.EqualsToken,
|
|
71
|
-
ts.factory.createCallExpression(
|
|
72
|
-
ts.factory.createIdentifier("stringify"),
|
|
73
|
-
undefined,
|
|
74
|
-
[ts.factory.createIdentifier("input")],
|
|
75
|
-
),
|
|
76
|
-
),
|
|
77
|
-
),
|
|
78
|
-
),
|
|
79
|
-
ts.factory.createReturnStatement(
|
|
80
|
-
ts.factory.createIdentifier("output"),
|
|
81
|
-
),
|
|
82
|
-
]),
|
|
83
|
-
);
|
|
84
|
-
}
|
|
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 { StringifyProgrammer } from "./StringifyProgrammer";
|
|
10
|
+
import { ValidateProgrammer } from "./ValidateProgrammer";
|
|
11
|
+
|
|
12
|
+
export namespace ValidateStringifyProgrammer {
|
|
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.createTypeReferenceNode("typia.IValidation<string>"),
|
|
30
|
+
undefined,
|
|
31
|
+
ts.factory.createBlock([
|
|
32
|
+
StatementFactory.constant(
|
|
33
|
+
"validate",
|
|
34
|
+
ValidateProgrammer.write({
|
|
35
|
+
...project,
|
|
36
|
+
options: {
|
|
37
|
+
...project.options,
|
|
38
|
+
functional: false,
|
|
39
|
+
numeric: true,
|
|
40
|
+
},
|
|
41
|
+
})(modulo)(false)(type, name),
|
|
42
|
+
),
|
|
43
|
+
StatementFactory.constant(
|
|
44
|
+
"stringify",
|
|
45
|
+
StringifyProgrammer.write({
|
|
46
|
+
...project,
|
|
47
|
+
options: {
|
|
48
|
+
...project.options,
|
|
49
|
+
functional: false,
|
|
50
|
+
numeric: false,
|
|
51
|
+
},
|
|
52
|
+
})(modulo)(type, name),
|
|
53
|
+
),
|
|
54
|
+
StatementFactory.constant(
|
|
55
|
+
"output",
|
|
56
|
+
ts.factory.createAsExpression(
|
|
57
|
+
ts.factory.createCallExpression(
|
|
58
|
+
ts.factory.createIdentifier("validate"),
|
|
59
|
+
undefined,
|
|
60
|
+
[ts.factory.createIdentifier("input")],
|
|
61
|
+
),
|
|
62
|
+
TypeFactory.keyword("any"),
|
|
63
|
+
),
|
|
64
|
+
),
|
|
65
|
+
ts.factory.createIfStatement(
|
|
66
|
+
ts.factory.createIdentifier("output.success"),
|
|
67
|
+
ts.factory.createExpressionStatement(
|
|
68
|
+
ts.factory.createBinaryExpression(
|
|
69
|
+
ts.factory.createIdentifier("output.data"),
|
|
70
|
+
ts.SyntaxKind.EqualsToken,
|
|
71
|
+
ts.factory.createCallExpression(
|
|
72
|
+
ts.factory.createIdentifier("stringify"),
|
|
73
|
+
undefined,
|
|
74
|
+
[ts.factory.createIdentifier("input")],
|
|
75
|
+
),
|
|
76
|
+
),
|
|
77
|
+
),
|
|
78
|
+
),
|
|
79
|
+
ts.factory.createReturnStatement(
|
|
80
|
+
ts.factory.createIdentifier("output"),
|
|
81
|
+
),
|
|
82
|
+
]),
|
|
83
|
+
);
|
|
84
|
+
}
|
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
import { Metadata } from "../../metadata/Metadata";
|
|
2
|
-
import { MetadataTuple } from "../../metadata/MetadataTuple";
|
|
3
|
-
import { IJsonComponents } from "../../schemas/IJsonComponents";
|
|
4
|
-
import { IJsonSchema } from "../../schemas/IJsonSchema";
|
|
5
|
-
|
|
6
|
-
import { ApplicationProgrammer } from "../ApplicationProgrammer";
|
|
7
|
-
import { application_schema } from "./application_schema";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @internal
|
|
11
|
-
*/
|
|
12
|
-
export const application_tuple =
|
|
13
|
-
(options: ApplicationProgrammer.IOptions) =>
|
|
14
|
-
(components: IJsonComponents) =>
|
|
15
|
-
(tuple: MetadataTuple) =>
|
|
16
|
-
(
|
|
17
|
-
attribute: IJsonSchema.IAttribute,
|
|
18
|
-
): IJsonSchema.ITuple | IJsonSchema.IArray => {
|
|
19
|
-
const schema: IJsonSchema.ITuple = {
|
|
20
|
-
type: "array",
|
|
21
|
-
items: tuple.elements.map((meta, i) =>
|
|
22
|
-
application_schema(options)(false)(components)(
|
|
23
|
-
meta.rest ?? meta,
|
|
24
|
-
)({
|
|
25
|
-
...attribute,
|
|
26
|
-
"x-typia-rest":
|
|
27
|
-
i === tuple.elements.length - 1 && meta.rest !== null,
|
|
28
|
-
"x-typia-required": meta.required,
|
|
29
|
-
"x-typia-optional": meta.optional,
|
|
30
|
-
}),
|
|
31
|
-
),
|
|
32
|
-
...attribute,
|
|
33
|
-
minItems: !!tuple.elements.at(-1)?.rest
|
|
34
|
-
? tuple.elements.length - 1
|
|
35
|
-
: tuple.elements.filter((x) => !x.optional).length,
|
|
36
|
-
maxItems: !!tuple.elements.at(-1)?.rest
|
|
37
|
-
? undefined
|
|
38
|
-
: tuple.elements.length,
|
|
39
|
-
};
|
|
40
|
-
if (options.purpose === "ajv")
|
|
41
|
-
if (tuple.elements.length === 0) return schema;
|
|
42
|
-
else if (!tuple.elements.at(-1)?.rest) return schema;
|
|
43
|
-
|
|
44
|
-
const wrapper: IJsonSchema.IArray = {
|
|
45
|
-
...schema,
|
|
46
|
-
items: application_schema(options)(false)(components)(
|
|
47
|
-
tuple.elements.reduce(
|
|
48
|
-
(x, y) => Metadata.merge(x.rest ?? x, y.rest ?? y),
|
|
49
|
-
Metadata.initialize(),
|
|
50
|
-
),
|
|
51
|
-
)(tuple.recursive ? {} : attribute),
|
|
52
|
-
"x-typia-tuple": schema,
|
|
53
|
-
minItems: schema.minItems,
|
|
54
|
-
maxItems: schema.maxItems,
|
|
55
|
-
};
|
|
56
|
-
return wrapper;
|
|
57
|
-
};
|
|
1
|
+
import { Metadata } from "../../metadata/Metadata";
|
|
2
|
+
import { MetadataTuple } from "../../metadata/MetadataTuple";
|
|
3
|
+
import { IJsonComponents } from "../../schemas/IJsonComponents";
|
|
4
|
+
import { IJsonSchema } from "../../schemas/IJsonSchema";
|
|
5
|
+
|
|
6
|
+
import { ApplicationProgrammer } from "../ApplicationProgrammer";
|
|
7
|
+
import { application_schema } from "./application_schema";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export const application_tuple =
|
|
13
|
+
(options: ApplicationProgrammer.IOptions) =>
|
|
14
|
+
(components: IJsonComponents) =>
|
|
15
|
+
(tuple: MetadataTuple) =>
|
|
16
|
+
(
|
|
17
|
+
attribute: IJsonSchema.IAttribute,
|
|
18
|
+
): IJsonSchema.ITuple | IJsonSchema.IArray => {
|
|
19
|
+
const schema: IJsonSchema.ITuple = {
|
|
20
|
+
type: "array",
|
|
21
|
+
items: tuple.elements.map((meta, i) =>
|
|
22
|
+
application_schema(options)(false)(components)(
|
|
23
|
+
meta.rest ?? meta,
|
|
24
|
+
)({
|
|
25
|
+
...attribute,
|
|
26
|
+
"x-typia-rest":
|
|
27
|
+
i === tuple.elements.length - 1 && meta.rest !== null,
|
|
28
|
+
"x-typia-required": meta.required,
|
|
29
|
+
"x-typia-optional": meta.optional,
|
|
30
|
+
}),
|
|
31
|
+
),
|
|
32
|
+
...attribute,
|
|
33
|
+
minItems: !!tuple.elements.at(-1)?.rest
|
|
34
|
+
? tuple.elements.length - 1
|
|
35
|
+
: tuple.elements.filter((x) => !x.optional).length,
|
|
36
|
+
maxItems: !!tuple.elements.at(-1)?.rest
|
|
37
|
+
? undefined
|
|
38
|
+
: tuple.elements.length,
|
|
39
|
+
};
|
|
40
|
+
if (options.purpose === "ajv")
|
|
41
|
+
if (tuple.elements.length === 0) return schema;
|
|
42
|
+
else if (!tuple.elements.at(-1)?.rest) return schema;
|
|
43
|
+
|
|
44
|
+
const wrapper: IJsonSchema.IArray = {
|
|
45
|
+
...schema,
|
|
46
|
+
items: application_schema(options)(false)(components)(
|
|
47
|
+
tuple.elements.reduce(
|
|
48
|
+
(x, y) => Metadata.merge(x.rest ?? x, y.rest ?? y),
|
|
49
|
+
Metadata.initialize(),
|
|
50
|
+
),
|
|
51
|
+
)(tuple.recursive ? {} : attribute),
|
|
52
|
+
"x-typia-tuple": schema,
|
|
53
|
+
minItems: schema.minItems,
|
|
54
|
+
maxItems: schema.maxItems,
|
|
55
|
+
};
|
|
56
|
+
return wrapper;
|
|
57
|
+
};
|
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
4
|
-
|
|
5
|
-
import { MetadataObject } from "../../metadata/MetadataObject";
|
|
6
|
-
|
|
7
|
-
import { Escaper } from "../../utils/Escaper";
|
|
8
|
-
|
|
9
|
-
import { FeatureProgrammer } from "../FeatureProgrammer";
|
|
10
|
-
import { FunctionImporter } from "../helpers/FunctionImporeter";
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* @internal
|
|
14
|
-
*/
|
|
15
|
-
export const feature_object_entries =
|
|
16
|
-
<Output extends ts.ConciseBody>(
|
|
17
|
-
config: Pick<
|
|
18
|
-
FeatureProgrammer.IConfig<Output>,
|
|
19
|
-
"decoder" | "path" | "trace"
|
|
20
|
-
>,
|
|
21
|
-
) =>
|
|
22
|
-
(importer: FunctionImporter) =>
|
|
23
|
-
(obj: MetadataObject) =>
|
|
24
|
-
(input: ts.Expression, from: "object" | "top" | "array" = "object") =>
|
|
25
|
-
obj.properties.map((prop) => {
|
|
26
|
-
const sole: string | null = prop.key.getSoleLiteral();
|
|
27
|
-
const propInput =
|
|
28
|
-
sole === null
|
|
29
|
-
? ts.factory.createIdentifier("value")
|
|
30
|
-
: Escaper.variable(sole)
|
|
31
|
-
? ts.factory.createPropertyAccessExpression(
|
|
32
|
-
input,
|
|
33
|
-
ts.factory.createIdentifier(sole),
|
|
34
|
-
)
|
|
35
|
-
: ts.factory.createElementAccessExpression(
|
|
36
|
-
input,
|
|
37
|
-
ts.factory.createStringLiteral(sole),
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
return {
|
|
41
|
-
input: propInput,
|
|
42
|
-
key: prop.key,
|
|
43
|
-
meta: prop.value,
|
|
44
|
-
expression: config.decoder()(
|
|
45
|
-
propInput,
|
|
46
|
-
prop.value,
|
|
47
|
-
{
|
|
48
|
-
tracable: config.path || config.trace,
|
|
49
|
-
source: "function",
|
|
50
|
-
from,
|
|
51
|
-
postfix:
|
|
52
|
-
sole !== null
|
|
53
|
-
? IdentifierFactory.postfix(sole)
|
|
54
|
-
: (() => {
|
|
55
|
-
importer.use("join");
|
|
56
|
-
return `$join(key)`;
|
|
57
|
-
})(),
|
|
58
|
-
},
|
|
59
|
-
prop.tags,
|
|
60
|
-
prop.jsDocTags,
|
|
61
|
-
),
|
|
62
|
-
};
|
|
63
|
-
});
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
4
|
+
|
|
5
|
+
import { MetadataObject } from "../../metadata/MetadataObject";
|
|
6
|
+
|
|
7
|
+
import { Escaper } from "../../utils/Escaper";
|
|
8
|
+
|
|
9
|
+
import { FeatureProgrammer } from "../FeatureProgrammer";
|
|
10
|
+
import { FunctionImporter } from "../helpers/FunctionImporeter";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
export const feature_object_entries =
|
|
16
|
+
<Output extends ts.ConciseBody>(
|
|
17
|
+
config: Pick<
|
|
18
|
+
FeatureProgrammer.IConfig<Output>,
|
|
19
|
+
"decoder" | "path" | "trace"
|
|
20
|
+
>,
|
|
21
|
+
) =>
|
|
22
|
+
(importer: FunctionImporter) =>
|
|
23
|
+
(obj: MetadataObject) =>
|
|
24
|
+
(input: ts.Expression, from: "object" | "top" | "array" = "object") =>
|
|
25
|
+
obj.properties.map((prop) => {
|
|
26
|
+
const sole: string | null = prop.key.getSoleLiteral();
|
|
27
|
+
const propInput =
|
|
28
|
+
sole === null
|
|
29
|
+
? ts.factory.createIdentifier("value")
|
|
30
|
+
: Escaper.variable(sole)
|
|
31
|
+
? ts.factory.createPropertyAccessExpression(
|
|
32
|
+
input,
|
|
33
|
+
ts.factory.createIdentifier(sole),
|
|
34
|
+
)
|
|
35
|
+
: ts.factory.createElementAccessExpression(
|
|
36
|
+
input,
|
|
37
|
+
ts.factory.createStringLiteral(sole),
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
input: propInput,
|
|
42
|
+
key: prop.key,
|
|
43
|
+
meta: prop.value,
|
|
44
|
+
expression: config.decoder()(
|
|
45
|
+
propInput,
|
|
46
|
+
prop.value,
|
|
47
|
+
{
|
|
48
|
+
tracable: config.path || config.trace,
|
|
49
|
+
source: "function",
|
|
50
|
+
from,
|
|
51
|
+
postfix:
|
|
52
|
+
sole !== null
|
|
53
|
+
? IdentifierFactory.postfix(sole)
|
|
54
|
+
: (() => {
|
|
55
|
+
importer.use("join");
|
|
56
|
+
return `$join(key)`;
|
|
57
|
+
})(),
|
|
58
|
+
},
|
|
59
|
+
prop.tags,
|
|
60
|
+
prop.jsDocTags,
|
|
61
|
+
),
|
|
62
|
+
};
|
|
63
|
+
});
|