typia 6.7.0 → 6.7.1

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 (85) hide show
  1. package/lib/programmers/AssertProgrammer.d.ts +0 -1
  2. package/lib/programmers/AssertProgrammer.js.map +1 -1
  3. package/lib/programmers/CheckerProgrammer.d.ts +1 -1
  4. package/lib/programmers/FeatureProgrammer.d.ts +1 -1
  5. package/lib/programmers/IsProgrammer.d.ts +1 -1
  6. package/lib/programmers/RandomProgrammer.d.ts +10 -1
  7. package/lib/programmers/RandomProgrammer.js +62 -37
  8. package/lib/programmers/RandomProgrammer.js.map +1 -1
  9. package/lib/programmers/ValidateProgrammer.d.ts +1 -1
  10. package/lib/programmers/json/JsonIsParseProgrammer.d.ts +1 -1
  11. package/lib/programmers/json/JsonIsStringifyProgrammer.d.ts +1 -1
  12. package/lib/programmers/json/JsonStringifyProgrammer.d.ts +1 -1
  13. package/lib/programmers/json/JsonStringifyProgrammer.js +1 -3
  14. package/lib/programmers/json/JsonStringifyProgrammer.js.map +1 -1
  15. package/lib/programmers/json/JsonValidateParseProgrammer.d.ts +1 -1
  16. package/lib/programmers/json/JsonValidateStringifyProgrammer.d.ts +1 -1
  17. package/lib/programmers/misc/MiscCloneProgrammer.d.ts +1 -1
  18. package/lib/programmers/misc/MiscCloneProgrammer.js +33 -14
  19. package/lib/programmers/misc/MiscCloneProgrammer.js.map +1 -1
  20. package/lib/programmers/misc/MiscIsCloneProgrammer.d.ts +1 -1
  21. package/lib/programmers/misc/MiscIsPruneProgrammer.d.ts +1 -1
  22. package/lib/programmers/misc/MiscPruneProgrammer.d.ts +1 -1
  23. package/lib/programmers/misc/MiscValidateCloneProgrammer.d.ts +1 -1
  24. package/lib/programmers/misc/MiscValidatePruneProgrammer.d.ts +1 -1
  25. package/lib/programmers/notations/NotationGeneralProgrammer.d.ts +1 -1
  26. package/lib/programmers/notations/NotationGeneralProgrammer.js +30 -11
  27. package/lib/programmers/notations/NotationGeneralProgrammer.js.map +1 -1
  28. package/lib/programmers/notations/NotationValidateGeneralProgrammer.d.ts +1 -1
  29. package/package.json +1 -1
  30. package/src/programmers/AssertProgrammer.ts +397 -398
  31. package/src/programmers/CheckerProgrammer.ts +1138 -1138
  32. package/src/programmers/FeatureProgrammer.ts +549 -549
  33. package/src/programmers/IsProgrammer.ts +1 -1
  34. package/src/programmers/RandomProgrammer.ts +112 -77
  35. package/src/programmers/ValidateProgrammer.ts +382 -382
  36. package/src/programmers/functional/FunctionalAssertFunctionProgrammer.ts +141 -141
  37. package/src/programmers/functional/FunctionalAssertParametersProgrammer.ts +108 -108
  38. package/src/programmers/functional/FunctionalAssertReturnProgrammer.ts +98 -98
  39. package/src/programmers/functional/FunctionalIsFunctionProgrammer.ts +72 -72
  40. package/src/programmers/functional/FunctionalIsParametersProgrammer.ts +101 -101
  41. package/src/programmers/functional/FunctionalIsReturnProgrammer.ts +106 -106
  42. package/src/programmers/functional/FunctionalValidateFunctionProgrammer.ts +123 -123
  43. package/src/programmers/functional/FunctionalValidateParametersProgrammer.ts +267 -267
  44. package/src/programmers/functional/FunctionalValidateReturnProgrammer.ts +126 -126
  45. package/src/programmers/helpers/FunctionImporter.ts +97 -97
  46. package/src/programmers/http/HttpAssertFormDataProgrammer.ts +91 -91
  47. package/src/programmers/http/HttpAssertHeadersProgrammer.ts +91 -91
  48. package/src/programmers/http/HttpAssertQueryProgrammer.ts +93 -93
  49. package/src/programmers/http/HttpFormDataProgrammer.ts +278 -278
  50. package/src/programmers/http/HttpHeadersProgrammer.ts +347 -347
  51. package/src/programmers/http/HttpIsFormDataProgrammer.ts +102 -102
  52. package/src/programmers/http/HttpIsHeadersProgrammer.ts +102 -102
  53. package/src/programmers/http/HttpIsQueryProgrammer.ts +104 -104
  54. package/src/programmers/http/HttpQueryProgrammer.ts +298 -298
  55. package/src/programmers/http/HttpValidateFormDataProgrammer.ts +85 -85
  56. package/src/programmers/http/HttpValidateHeadersProgrammer.ts +85 -85
  57. package/src/programmers/http/HttpValidateQueryProgrammer.ts +87 -87
  58. package/src/programmers/json/JsonAssertParseProgrammer.ts +96 -96
  59. package/src/programmers/json/JsonAssertStringifyProgrammer.ts +104 -104
  60. package/src/programmers/json/JsonIsParseProgrammer.ts +110 -110
  61. package/src/programmers/json/JsonIsStringifyProgrammer.ts +102 -102
  62. package/src/programmers/json/JsonStringifyProgrammer.ts +909 -910
  63. package/src/programmers/json/JsonValidateParseProgrammer.ts +87 -87
  64. package/src/programmers/json/JsonValidateStringifyProgrammer.ts +111 -111
  65. package/src/programmers/misc/MiscAssertCloneProgrammer.ts +87 -87
  66. package/src/programmers/misc/MiscAssertPruneProgrammer.ts +87 -87
  67. package/src/programmers/misc/MiscCloneProgrammer.ts +781 -759
  68. package/src/programmers/misc/MiscIsCloneProgrammer.ts +93 -93
  69. package/src/programmers/misc/MiscIsPruneProgrammer.ts +94 -94
  70. package/src/programmers/misc/MiscPruneProgrammer.ts +560 -560
  71. package/src/programmers/misc/MiscValidateCloneProgrammer.ts +104 -104
  72. package/src/programmers/misc/MiscValidatePruneProgrammer.ts +98 -98
  73. package/src/programmers/notations/NotationAssertGeneralProgrammer.ts +91 -91
  74. package/src/programmers/notations/NotationGeneralProgrammer.ts +709 -685
  75. package/src/programmers/notations/NotationIsGeneralProgrammer.ts +97 -97
  76. package/src/programmers/notations/NotationValidateGeneralProgrammer.ts +107 -107
  77. package/src/programmers/protobuf/ProtobufAssertDecodeProgrammer.ts +91 -91
  78. package/src/programmers/protobuf/ProtobufAssertEncodeProgrammer.ts +95 -95
  79. package/src/programmers/protobuf/ProtobufDecodeProgrammer.ts +646 -646
  80. package/src/programmers/protobuf/ProtobufEncodeProgrammer.ts +852 -852
  81. package/src/programmers/protobuf/ProtobufIsDecodeProgrammer.ts +104 -104
  82. package/src/programmers/protobuf/ProtobufIsEncodeProgrammer.ts +93 -93
  83. package/src/programmers/protobuf/ProtobufValidateDecodeProgrammer.ts +85 -85
  84. package/src/programmers/protobuf/ProtobufValidateEncodeProgrammer.ts +109 -109
  85. package/src/transformers/internal/GenericTransformer.ts +104 -104
@@ -1,97 +1,97 @@
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 { FeatureProgrammer } from "../FeatureProgrammer";
10
- import { IsProgrammer } from "../IsProgrammer";
11
- import { FunctionImporter } from "../helpers/FunctionImporter";
12
- import { NotationGeneralProgrammer } from "./NotationGeneralProgrammer";
13
-
14
- export namespace NotationIsGeneralProgrammer {
15
- export const decompose = (props: {
16
- rename: (str: string) => string;
17
- project: IProject;
18
- importer: FunctionImporter;
19
- type: ts.Type;
20
- name: string | undefined;
21
- }): FeatureProgrammer.IDecomposed => {
22
- const is: FeatureProgrammer.IDecomposed = IsProgrammer.decompose({
23
- ...props,
24
- equals: false,
25
- });
26
- const notation: FeatureProgrammer.IDecomposed =
27
- NotationGeneralProgrammer.decompose({
28
- ...props,
29
- validated: true,
30
- });
31
- return {
32
- functions: {
33
- ...is.functions,
34
- ...notation.functions,
35
- },
36
- statements: [
37
- ...is.statements,
38
- ...notation.statements,
39
- StatementFactory.constant("__is", is.arrow),
40
- StatementFactory.constant("__notation", notation.arrow),
41
- ],
42
- arrow: ts.factory.createArrowFunction(
43
- undefined,
44
- undefined,
45
- [IdentifierFactory.parameter("input", TypeFactory.keyword("any"))],
46
- ts.factory.createUnionTypeNode([
47
- notation.arrow.type ?? TypeFactory.keyword("any"),
48
- ts.factory.createTypeReferenceNode("null"),
49
- ]),
50
- undefined,
51
- ts.factory.createBlock(
52
- [
53
- ts.factory.createIfStatement(
54
- ts.factory.createPrefixUnaryExpression(
55
- ts.SyntaxKind.ExclamationToken,
56
- ts.factory.createCallExpression(
57
- ts.factory.createIdentifier("__is"),
58
- undefined,
59
- [ts.factory.createIdentifier("input")],
60
- ),
61
- ),
62
- ts.factory.createReturnStatement(ts.factory.createNull()),
63
- ),
64
- ts.factory.createReturnStatement(
65
- ts.factory.createCallExpression(
66
- ts.factory.createIdentifier("__notation"),
67
- undefined,
68
- [ts.factory.createIdentifier("input")],
69
- ),
70
- ),
71
- ],
72
- true,
73
- ),
74
- ),
75
- };
76
- };
77
-
78
- export const write =
79
- (rename: (str: string) => string) =>
80
- (project: IProject) =>
81
- (modulo: ts.LeftHandSideExpression) =>
82
- (type: ts.Type, name?: string): ts.CallExpression => {
83
- const importer: FunctionImporter = new FunctionImporter(modulo.getText());
84
- const result: FeatureProgrammer.IDecomposed = decompose({
85
- rename,
86
- project,
87
- importer,
88
- type,
89
- name,
90
- });
91
- return FeatureProgrammer.writeDecomposed({
92
- modulo,
93
- importer,
94
- result,
95
- });
96
- };
97
- }
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 { FeatureProgrammer } from "../FeatureProgrammer";
10
+ import { IsProgrammer } from "../IsProgrammer";
11
+ import { FunctionImporter } from "../helpers/FunctionImporter";
12
+ import { NotationGeneralProgrammer } from "./NotationGeneralProgrammer";
13
+
14
+ export namespace NotationIsGeneralProgrammer {
15
+ export const decompose = (props: {
16
+ rename: (str: string) => string;
17
+ project: IProject;
18
+ importer: FunctionImporter;
19
+ type: ts.Type;
20
+ name: string | undefined;
21
+ }): FeatureProgrammer.IDecomposed => {
22
+ const is: FeatureProgrammer.IDecomposed = IsProgrammer.decompose({
23
+ ...props,
24
+ equals: false,
25
+ });
26
+ const notation: FeatureProgrammer.IDecomposed =
27
+ NotationGeneralProgrammer.decompose({
28
+ ...props,
29
+ validated: true,
30
+ });
31
+ return {
32
+ functions: {
33
+ ...is.functions,
34
+ ...notation.functions,
35
+ },
36
+ statements: [
37
+ ...is.statements,
38
+ ...notation.statements,
39
+ StatementFactory.constant("__is", is.arrow),
40
+ StatementFactory.constant("__notation", notation.arrow),
41
+ ],
42
+ arrow: ts.factory.createArrowFunction(
43
+ undefined,
44
+ undefined,
45
+ [IdentifierFactory.parameter("input", TypeFactory.keyword("any"))],
46
+ ts.factory.createUnionTypeNode([
47
+ notation.arrow.type ?? TypeFactory.keyword("any"),
48
+ ts.factory.createTypeReferenceNode("null"),
49
+ ]),
50
+ undefined,
51
+ ts.factory.createBlock(
52
+ [
53
+ ts.factory.createIfStatement(
54
+ ts.factory.createPrefixUnaryExpression(
55
+ ts.SyntaxKind.ExclamationToken,
56
+ ts.factory.createCallExpression(
57
+ ts.factory.createIdentifier("__is"),
58
+ undefined,
59
+ [ts.factory.createIdentifier("input")],
60
+ ),
61
+ ),
62
+ ts.factory.createReturnStatement(ts.factory.createNull()),
63
+ ),
64
+ ts.factory.createReturnStatement(
65
+ ts.factory.createCallExpression(
66
+ ts.factory.createIdentifier("__notation"),
67
+ undefined,
68
+ [ts.factory.createIdentifier("input")],
69
+ ),
70
+ ),
71
+ ],
72
+ true,
73
+ ),
74
+ ),
75
+ };
76
+ };
77
+
78
+ export const write =
79
+ (rename: (str: string) => string) =>
80
+ (project: IProject) =>
81
+ (modulo: ts.LeftHandSideExpression) =>
82
+ (type: ts.Type, name?: string): ts.CallExpression => {
83
+ const importer: FunctionImporter = new FunctionImporter(modulo.getText());
84
+ const result: FeatureProgrammer.IDecomposed = decompose({
85
+ rename,
86
+ project,
87
+ importer,
88
+ type,
89
+ name,
90
+ });
91
+ return FeatureProgrammer.writeDecomposed({
92
+ modulo,
93
+ importer,
94
+ result,
95
+ });
96
+ };
97
+ }
@@ -1,107 +1,107 @@
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 { FeatureProgrammer } from "../FeatureProgrammer";
10
- import { ValidateProgrammer } from "../ValidateProgrammer";
11
- import { FunctionImporter } from "../helpers/FunctionImporter";
12
- import { NotationGeneralProgrammer } from "./NotationGeneralProgrammer";
13
-
14
- export namespace NotationValidateGeneralProgrammer {
15
- export const decompose = (props: {
16
- rename: (str: string) => string;
17
- project: IProject;
18
- modulo: ts.LeftHandSideExpression;
19
- importer: FunctionImporter;
20
- type: ts.Type;
21
- name?: string;
22
- }): FeatureProgrammer.IDecomposed => {
23
- const validate = ValidateProgrammer.decompose({
24
- ...props,
25
- equals: false,
26
- });
27
- const notation = NotationGeneralProgrammer.decompose({
28
- ...props,
29
- validated: true,
30
- });
31
- return {
32
- functions: {
33
- ...validate.functions,
34
- ...notation.functions,
35
- },
36
- statements: [
37
- ...validate.statements,
38
- ...notation.statements,
39
- StatementFactory.constant("__validate", validate.arrow),
40
- StatementFactory.constant("__notation", notation.arrow),
41
- ],
42
- arrow: ts.factory.createArrowFunction(
43
- undefined,
44
- undefined,
45
- [IdentifierFactory.parameter("input", TypeFactory.keyword("any"))],
46
- ts.factory.createTypeReferenceNode("typia.IValidation", [
47
- notation.arrow.type ?? TypeFactory.keyword("any"),
48
- ]),
49
- undefined,
50
- ts.factory.createBlock(
51
- [
52
- StatementFactory.constant(
53
- "result",
54
- ts.factory.createAsExpression(
55
- ts.factory.createCallExpression(
56
- ts.factory.createIdentifier("__validate"),
57
- undefined,
58
- [ts.factory.createIdentifier("input")],
59
- ),
60
- TypeFactory.keyword("any"),
61
- ),
62
- ),
63
- ts.factory.createIfStatement(
64
- ts.factory.createIdentifier("result.success"),
65
- ts.factory.createExpressionStatement(
66
- ts.factory.createBinaryExpression(
67
- ts.factory.createIdentifier("result.data"),
68
- ts.SyntaxKind.EqualsToken,
69
- ts.factory.createCallExpression(
70
- ts.factory.createIdentifier("__notation"),
71
- undefined,
72
- [ts.factory.createIdentifier("input")],
73
- ),
74
- ),
75
- ),
76
- ),
77
- ts.factory.createReturnStatement(
78
- ts.factory.createIdentifier("result"),
79
- ),
80
- ],
81
- true,
82
- ),
83
- ),
84
- };
85
- };
86
-
87
- export const write =
88
- (rename: (str: string) => string) =>
89
- (project: IProject) =>
90
- (modulo: ts.LeftHandSideExpression) =>
91
- (type: ts.Type, name?: string): ts.CallExpression => {
92
- const importer: FunctionImporter = new FunctionImporter(modulo.getText());
93
- const result: FeatureProgrammer.IDecomposed = decompose({
94
- rename,
95
- project,
96
- modulo,
97
- importer,
98
- type,
99
- name,
100
- });
101
- return FeatureProgrammer.writeDecomposed({
102
- modulo,
103
- importer,
104
- result,
105
- });
106
- };
107
- }
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 { FeatureProgrammer } from "../FeatureProgrammer";
10
+ import { ValidateProgrammer } from "../ValidateProgrammer";
11
+ import { FunctionImporter } from "../helpers/FunctionImporter";
12
+ import { NotationGeneralProgrammer } from "./NotationGeneralProgrammer";
13
+
14
+ export namespace NotationValidateGeneralProgrammer {
15
+ export const decompose = (props: {
16
+ rename: (str: string) => string;
17
+ project: IProject;
18
+ modulo: ts.LeftHandSideExpression;
19
+ importer: FunctionImporter;
20
+ type: ts.Type;
21
+ name: string | undefined;
22
+ }): FeatureProgrammer.IDecomposed => {
23
+ const validate = ValidateProgrammer.decompose({
24
+ ...props,
25
+ equals: false,
26
+ });
27
+ const notation = NotationGeneralProgrammer.decompose({
28
+ ...props,
29
+ validated: true,
30
+ });
31
+ return {
32
+ functions: {
33
+ ...validate.functions,
34
+ ...notation.functions,
35
+ },
36
+ statements: [
37
+ ...validate.statements,
38
+ ...notation.statements,
39
+ StatementFactory.constant("__validate", validate.arrow),
40
+ StatementFactory.constant("__notation", notation.arrow),
41
+ ],
42
+ arrow: ts.factory.createArrowFunction(
43
+ undefined,
44
+ undefined,
45
+ [IdentifierFactory.parameter("input", TypeFactory.keyword("any"))],
46
+ ts.factory.createTypeReferenceNode("typia.IValidation", [
47
+ notation.arrow.type ?? TypeFactory.keyword("any"),
48
+ ]),
49
+ undefined,
50
+ ts.factory.createBlock(
51
+ [
52
+ StatementFactory.constant(
53
+ "result",
54
+ ts.factory.createAsExpression(
55
+ ts.factory.createCallExpression(
56
+ ts.factory.createIdentifier("__validate"),
57
+ undefined,
58
+ [ts.factory.createIdentifier("input")],
59
+ ),
60
+ TypeFactory.keyword("any"),
61
+ ),
62
+ ),
63
+ ts.factory.createIfStatement(
64
+ ts.factory.createIdentifier("result.success"),
65
+ ts.factory.createExpressionStatement(
66
+ ts.factory.createBinaryExpression(
67
+ ts.factory.createIdentifier("result.data"),
68
+ ts.SyntaxKind.EqualsToken,
69
+ ts.factory.createCallExpression(
70
+ ts.factory.createIdentifier("__notation"),
71
+ undefined,
72
+ [ts.factory.createIdentifier("input")],
73
+ ),
74
+ ),
75
+ ),
76
+ ),
77
+ ts.factory.createReturnStatement(
78
+ ts.factory.createIdentifier("result"),
79
+ ),
80
+ ],
81
+ true,
82
+ ),
83
+ ),
84
+ };
85
+ };
86
+
87
+ export const write =
88
+ (rename: (str: string) => string) =>
89
+ (project: IProject) =>
90
+ (modulo: ts.LeftHandSideExpression) =>
91
+ (type: ts.Type, name?: string): ts.CallExpression => {
92
+ const importer: FunctionImporter = new FunctionImporter(modulo.getText());
93
+ const result: FeatureProgrammer.IDecomposed = decompose({
94
+ rename,
95
+ project,
96
+ modulo,
97
+ importer,
98
+ type,
99
+ name,
100
+ });
101
+ return FeatureProgrammer.writeDecomposed({
102
+ modulo,
103
+ importer,
104
+ result,
105
+ });
106
+ };
107
+ }
@@ -1,91 +1,91 @@
1
- import ts from "typescript";
2
-
3
- import { StatementFactory } from "../../factories/StatementFactory";
4
-
5
- import { IProject } from "../../transformers/IProject";
6
-
7
- import { AssertProgrammer } from "../AssertProgrammer";
8
- import { FeatureProgrammer } from "../FeatureProgrammer";
9
- import { FunctionImporter } from "../helpers/FunctionImporter";
10
- import { ProtobufDecodeProgrammer } from "./ProtobufDecodeProgrammer";
11
-
12
- export namespace ProtobufAssertDecodeProgrammer {
13
- export const decompose = (props: {
14
- project: IProject;
15
- modulo: ts.LeftHandSideExpression;
16
- importer: FunctionImporter;
17
- type: ts.Type;
18
- name: string | undefined;
19
- init: ts.Expression | undefined;
20
- }): FeatureProgrammer.IDecomposed => {
21
- const assert: FeatureProgrammer.IDecomposed = AssertProgrammer.decompose({
22
- ...props,
23
- project: {
24
- ...props.project,
25
- options: {
26
- ...props.project.options,
27
- functional: false,
28
- numeric: false,
29
- },
30
- },
31
- equals: false,
32
- guard: false,
33
- });
34
- const decode: FeatureProgrammer.IDecomposed =
35
- ProtobufDecodeProgrammer.decompose(props);
36
- return {
37
- functions: {
38
- ...assert.functions,
39
- ...decode.functions,
40
- },
41
- statements: [
42
- ...assert.statements,
43
- ...decode.statements,
44
- StatementFactory.constant("__assert", assert.arrow),
45
- StatementFactory.constant("__decode", decode.arrow),
46
- ],
47
- arrow: ts.factory.createArrowFunction(
48
- undefined,
49
- undefined,
50
- [
51
- ...decode.arrow.parameters,
52
- AssertProgrammer.Guardian.parameter(props.init),
53
- ],
54
- decode.arrow.type,
55
- undefined,
56
- ts.factory.createCallExpression(
57
- ts.factory.createIdentifier("__assert"),
58
- undefined,
59
- [
60
- ts.factory.createCallExpression(
61
- ts.factory.createIdentifier("__decode"),
62
- undefined,
63
- [ts.factory.createIdentifier("input")],
64
- ),
65
- AssertProgrammer.Guardian.identifier(),
66
- ],
67
- ),
68
- ),
69
- };
70
- };
71
-
72
- export const write =
73
- (project: IProject) =>
74
- (modulo: ts.LeftHandSideExpression) =>
75
- (type: ts.Type, name?: string, init?: ts.Expression): ts.CallExpression => {
76
- const importer: FunctionImporter = new FunctionImporter(modulo.getText());
77
- const result: FeatureProgrammer.IDecomposed = decompose({
78
- project,
79
- modulo,
80
- importer,
81
- type,
82
- name,
83
- init,
84
- });
85
- return FeatureProgrammer.writeDecomposed({
86
- modulo,
87
- importer,
88
- result,
89
- });
90
- };
91
- }
1
+ import ts from "typescript";
2
+
3
+ import { StatementFactory } from "../../factories/StatementFactory";
4
+
5
+ import { IProject } from "../../transformers/IProject";
6
+
7
+ import { AssertProgrammer } from "../AssertProgrammer";
8
+ import { FeatureProgrammer } from "../FeatureProgrammer";
9
+ import { FunctionImporter } from "../helpers/FunctionImporter";
10
+ import { ProtobufDecodeProgrammer } from "./ProtobufDecodeProgrammer";
11
+
12
+ export namespace ProtobufAssertDecodeProgrammer {
13
+ export const decompose = (props: {
14
+ project: IProject;
15
+ modulo: ts.LeftHandSideExpression;
16
+ importer: FunctionImporter;
17
+ type: ts.Type;
18
+ name: string | undefined;
19
+ init: ts.Expression | undefined;
20
+ }): FeatureProgrammer.IDecomposed => {
21
+ const assert: FeatureProgrammer.IDecomposed = AssertProgrammer.decompose({
22
+ ...props,
23
+ project: {
24
+ ...props.project,
25
+ options: {
26
+ ...props.project.options,
27
+ functional: false,
28
+ numeric: false,
29
+ },
30
+ },
31
+ equals: false,
32
+ guard: false,
33
+ });
34
+ const decode: FeatureProgrammer.IDecomposed =
35
+ ProtobufDecodeProgrammer.decompose(props);
36
+ return {
37
+ functions: {
38
+ ...assert.functions,
39
+ ...decode.functions,
40
+ },
41
+ statements: [
42
+ ...assert.statements,
43
+ ...decode.statements,
44
+ StatementFactory.constant("__assert", assert.arrow),
45
+ StatementFactory.constant("__decode", decode.arrow),
46
+ ],
47
+ arrow: ts.factory.createArrowFunction(
48
+ undefined,
49
+ undefined,
50
+ [
51
+ ...decode.arrow.parameters,
52
+ AssertProgrammer.Guardian.parameter(props.init),
53
+ ],
54
+ decode.arrow.type,
55
+ undefined,
56
+ ts.factory.createCallExpression(
57
+ ts.factory.createIdentifier("__assert"),
58
+ undefined,
59
+ [
60
+ ts.factory.createCallExpression(
61
+ ts.factory.createIdentifier("__decode"),
62
+ undefined,
63
+ [ts.factory.createIdentifier("input")],
64
+ ),
65
+ AssertProgrammer.Guardian.identifier(),
66
+ ],
67
+ ),
68
+ ),
69
+ };
70
+ };
71
+
72
+ export const write =
73
+ (project: IProject) =>
74
+ (modulo: ts.LeftHandSideExpression) =>
75
+ (type: ts.Type, name?: string, init?: ts.Expression): ts.CallExpression => {
76
+ const importer: FunctionImporter = new FunctionImporter(modulo.getText());
77
+ const result: FeatureProgrammer.IDecomposed = decompose({
78
+ project,
79
+ modulo,
80
+ importer,
81
+ type,
82
+ name,
83
+ init,
84
+ });
85
+ return FeatureProgrammer.writeDecomposed({
86
+ modulo,
87
+ importer,
88
+ result,
89
+ });
90
+ };
91
+ }