typia 5.5.0-dev.20240303-2 → 5.5.0-dev.20240304

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 (93) hide show
  1. package/lib/functional/Namespace/functional.d.ts +4 -0
  2. package/lib/functional/Namespace/functional.js +9 -0
  3. package/lib/functional/Namespace/functional.js.map +1 -0
  4. package/lib/functional/Namespace/index.d.ts +1 -0
  5. package/lib/functional/Namespace/index.js +2 -1
  6. package/lib/functional/Namespace/index.js.map +1 -1
  7. package/lib/functional.d.ts +6 -162
  8. package/lib/functional.js +248 -48
  9. package/lib/functional.js.map +1 -1
  10. package/lib/programmers/AssertProgrammer.js +2 -2
  11. package/lib/programmers/AssertProgrammer.js.map +1 -1
  12. package/lib/programmers/CheckerProgrammer.d.ts +1 -1
  13. package/lib/programmers/FeatureProgrammer.d.ts +1 -1
  14. package/lib/programmers/IsProgrammer.d.ts +1 -1
  15. package/lib/programmers/IsProgrammer.js +3 -3
  16. package/lib/programmers/IsProgrammer.js.map +1 -1
  17. package/lib/programmers/RandomProgrammer.js +2 -2
  18. package/lib/programmers/RandomProgrammer.js.map +1 -1
  19. package/lib/programmers/ValidateProgrammer.js +2 -2
  20. package/lib/programmers/ValidateProgrammer.js.map +1 -1
  21. package/lib/programmers/functional/FunctionalAssertFunctionProgrammer.d.ts +2 -0
  22. package/lib/programmers/functional/FunctionalAssertFunctionProgrammer.js +55 -11
  23. package/lib/programmers/functional/FunctionalAssertFunctionProgrammer.js.map +1 -1
  24. package/lib/programmers/functional/FunctionalAssertParametersProgrammer.d.ts +1 -5
  25. package/lib/programmers/functional/FunctionalAssertParametersProgrammer.js +38 -21
  26. package/lib/programmers/functional/FunctionalAssertParametersProgrammer.js.map +1 -1
  27. package/lib/programmers/functional/FunctionalAssertReturnProgrammer.d.ts +1 -5
  28. package/lib/programmers/functional/FunctionalAssertReturnProgrammer.js +17 -18
  29. package/lib/programmers/functional/FunctionalAssertReturnProgrammer.js.map +1 -1
  30. package/lib/programmers/helpers/FunctionImporeter.d.ts +1 -19
  31. package/lib/programmers/helpers/FunctionImporeter.js +13 -91
  32. package/lib/programmers/helpers/FunctionImporeter.js.map +1 -1
  33. package/lib/programmers/helpers/FunctionImporter.d.ts +19 -0
  34. package/lib/programmers/helpers/FunctionImporter.js +96 -0
  35. package/lib/programmers/helpers/FunctionImporter.js.map +1 -0
  36. package/lib/programmers/helpers/StringifyJoinder.d.ts +1 -1
  37. package/lib/programmers/helpers/disable_function_importer_declare.d.ts +1 -1
  38. package/lib/programmers/http/HttpFormDataProgrammer.js +2 -2
  39. package/lib/programmers/http/HttpFormDataProgrammer.js.map +1 -1
  40. package/lib/programmers/http/HttpHeadersProgrammer.js +2 -2
  41. package/lib/programmers/http/HttpHeadersProgrammer.js.map +1 -1
  42. package/lib/programmers/http/HttpParameterProgrammer.js +2 -2
  43. package/lib/programmers/http/HttpParameterProgrammer.js.map +1 -1
  44. package/lib/programmers/http/HttpQueryProgrammer.js +2 -2
  45. package/lib/programmers/http/HttpQueryProgrammer.js.map +1 -1
  46. package/lib/programmers/internal/check_dynamic_key.d.ts +1 -1
  47. package/lib/programmers/json/JsonStringifyProgrammer.js +2 -2
  48. package/lib/programmers/json/JsonStringifyProgrammer.js.map +1 -1
  49. package/lib/programmers/misc/MiscCloneProgrammer.js +2 -2
  50. package/lib/programmers/misc/MiscCloneProgrammer.js.map +1 -1
  51. package/lib/programmers/misc/MiscPruneProgrammer.js +2 -2
  52. package/lib/programmers/misc/MiscPruneProgrammer.js.map +1 -1
  53. package/lib/programmers/notations/NotationGeneralProgrammer.js +2 -2
  54. package/lib/programmers/notations/NotationGeneralProgrammer.js.map +1 -1
  55. package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js +2 -2
  56. package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js.map +1 -1
  57. package/lib/programmers/protobuf/ProtobufEncodeProgrammer.js +2 -2
  58. package/lib/programmers/protobuf/ProtobufEncodeProgrammer.js.map +1 -1
  59. package/lib/transformers/features/functional/FunctionalGenericTransformer.d.ts +1 -1
  60. package/lib/transformers/features/functional/FunctionalGenericTransformer.js +11 -32
  61. package/lib/transformers/features/functional/FunctionalGenericTransformer.js.map +1 -1
  62. package/package.json +2 -1
  63. package/src/functional/Namespace/functional.ts +5 -0
  64. package/src/functional/Namespace/index.ts +1 -0
  65. package/src/functional.ts +258 -243
  66. package/src/programmers/AssertProgrammer.ts +1 -1
  67. package/src/programmers/CheckerProgrammer.ts +1 -1
  68. package/src/programmers/FeatureProgrammer.ts +1 -1
  69. package/src/programmers/IsProgrammer.ts +1 -1
  70. package/src/programmers/RandomProgrammer.ts +1 -1
  71. package/src/programmers/ValidateProgrammer.ts +1 -1
  72. package/src/programmers/functional/FunctionalAssertFunctionProgrammer.ts +103 -18
  73. package/src/programmers/functional/FunctionalAssertParametersProgrammer.ts +22 -45
  74. package/src/programmers/functional/FunctionalAssertReturnProgrammer.ts +44 -40
  75. package/src/programmers/helpers/FunctionImporeter.ts +1 -87
  76. package/src/programmers/helpers/FunctionImporter.ts +87 -0
  77. package/src/programmers/helpers/StringifyJoinder.ts +1 -1
  78. package/src/programmers/helpers/disable_function_importer_declare.ts +1 -1
  79. package/src/programmers/http/HttpFormDataProgrammer.ts +1 -1
  80. package/src/programmers/http/HttpHeadersProgrammer.ts +1 -1
  81. package/src/programmers/http/HttpParameterProgrammer.ts +1 -1
  82. package/src/programmers/http/HttpQueryProgrammer.ts +1 -1
  83. package/src/programmers/internal/check_dynamic_key.ts +1 -1
  84. package/src/programmers/internal/check_dynamic_properties.ts +1 -1
  85. package/src/programmers/internal/check_object.ts +1 -1
  86. package/src/programmers/internal/feature_object_entries.ts +1 -1
  87. package/src/programmers/json/JsonStringifyProgrammer.ts +1 -1
  88. package/src/programmers/misc/MiscCloneProgrammer.ts +1 -1
  89. package/src/programmers/misc/MiscPruneProgrammer.ts +1 -1
  90. package/src/programmers/notations/NotationGeneralProgrammer.ts +1 -1
  91. package/src/programmers/protobuf/ProtobufDecodeProgrammer.ts +1 -1
  92. package/src/programmers/protobuf/ProtobufEncodeProgrammer.ts +1 -1
  93. package/src/transformers/features/functional/FunctionalGenericTransformer.ts +12 -17
@@ -11,7 +11,7 @@ import { MetadataObject } from "../schemas/metadata/MetadataObject";
11
11
  import { IProject } from "../transformers/IProject";
12
12
 
13
13
  import { CheckerProgrammer } from "./CheckerProgrammer";
14
- import { FunctionImporter } from "./helpers/FunctionImporeter";
14
+ import { FunctionImporter } from "./helpers/FunctionImporter";
15
15
  import { IExpressionEntry } from "./helpers/IExpressionEntry";
16
16
  import { OptionPredicator } from "./helpers/OptionPredicator";
17
17
  import { disable_function_importer_declare } from "./helpers/disable_function_importer_declare";
@@ -22,7 +22,7 @@ import { TransformerError } from "../transformers/TransformerError";
22
22
  import { Escaper } from "../utils/Escaper";
23
23
 
24
24
  import { Format } from "../tags";
25
- import { FunctionImporter } from "./helpers/FunctionImporeter";
25
+ import { FunctionImporter } from "./helpers/FunctionImporter";
26
26
  import { RandomJoiner } from "./helpers/RandomJoiner";
27
27
  import { RandomRanger } from "./helpers/RandomRanger";
28
28
  import { random_custom } from "./internal/random_custom";
@@ -9,7 +9,7 @@ import { IProject } from "../transformers/IProject";
9
9
 
10
10
  import { CheckerProgrammer } from "./CheckerProgrammer";
11
11
  import { IsProgrammer } from "./IsProgrammer";
12
- import { FunctionImporter } from "./helpers/FunctionImporeter";
12
+ import { FunctionImporter } from "./helpers/FunctionImporter";
13
13
  import { OptionPredicator } from "./helpers/OptionPredicator";
14
14
  import { check_everything } from "./internal/check_everything";
15
15
  import { check_object } from "./internal/check_object";
@@ -1,5 +1,11 @@
1
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
+
2
7
  import { IProject } from "../../transformers/IProject";
8
+
3
9
  import { FunctionalAssertParametersProgrammer } from "./FunctionalAssertParametersProgrammer";
4
10
  import { FunctionAssertReturnProgrammer } from "./FunctionalAssertReturnProgrammer";
5
11
 
@@ -13,31 +19,110 @@ export namespace FunctionalAssertFunctionProgrammer {
13
19
  declaration: ts.FunctionDeclaration,
14
20
  init?: ts.Expression,
15
21
  ): ts.ArrowFunction => {
16
- const params = FunctionalAssertParametersProgrammer.prepare(project)(
17
- modulo,
18
- )(equals)(declaration, init);
19
- const output = FunctionAssertReturnProgrammer.prepare(project)(modulo)(
20
- equals,
21
- )(expression, declaration, init);
22
+ const { async, returns } = FunctionAssertReturnProgrammer.returnStatement(
23
+ project,
24
+ )(modulo)(equals)(
25
+ expression,
26
+ declaration.type,
27
+ declaration.parameters.map((p) =>
28
+ ts.factory.createIdentifier(p.name.getText()),
29
+ ),
30
+ );
22
31
  return ts.factory.createArrowFunction(
23
- output.async
32
+ async
24
33
  ? [ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword)]
25
34
  : undefined,
26
35
  undefined,
27
36
  declaration.parameters,
28
37
  declaration.type,
29
38
  undefined,
30
- ts.factory.createBlock(
31
- [
32
- params.assert,
33
- output.assert,
34
- params.call,
35
- output.variable,
36
- output.call,
37
- output.returns,
38
- ],
39
- true,
40
- ),
39
+ ts.factory.createBlock([
40
+ errorFactory(modulo)(init),
41
+ ...FunctionalAssertParametersProgrammer.argumentExpressions(project)(
42
+ modulo,
43
+ )(equals)(declaration.parameters).map(
44
+ ts.factory.createExpressionStatement,
45
+ ),
46
+ returns,
47
+ ]),
41
48
  );
42
49
  };
50
+
51
+ export const errorFactory =
52
+ (modulo: ts.LeftHandSideExpression) => (init: ts.Expression | undefined) =>
53
+ StatementFactory.constant(
54
+ "errorFactoryWrapper",
55
+ init ??
56
+ ts.factory.createPropertyAccessExpression(
57
+ ts.factory.createAsExpression(modulo, TypeFactory.keyword("any")),
58
+ "errorFactory",
59
+ ),
60
+ );
61
+
62
+ export const hookPath = (replacer: string): ts.ArrowFunction =>
63
+ ts.factory.createArrowFunction(
64
+ undefined,
65
+ undefined,
66
+ [
67
+ IdentifierFactory.parameter(
68
+ "p",
69
+ ts.factory.createFunctionTypeNode(
70
+ undefined,
71
+ [
72
+ ts.factory.createParameterDeclaration(
73
+ undefined,
74
+ undefined,
75
+ ts.factory.createIdentifier("p"),
76
+ undefined,
77
+ ts.factory.createImportTypeNode(
78
+ ts.factory.createLiteralTypeNode(
79
+ ts.factory.createStringLiteral("typia"),
80
+ ),
81
+ undefined,
82
+ ts.factory.createQualifiedName(
83
+ ts.factory.createIdentifier("TypeGuardError"),
84
+ ts.factory.createIdentifier("IProps"),
85
+ ),
86
+ undefined,
87
+ false,
88
+ ),
89
+ undefined,
90
+ ),
91
+ ],
92
+ ts.factory.createTypeReferenceNode(
93
+ ts.factory.createIdentifier("Error"),
94
+ undefined,
95
+ ),
96
+ ),
97
+ ),
98
+ ],
99
+ undefined,
100
+ undefined,
101
+ ts.factory.createCallExpression(
102
+ ts.factory.createIdentifier("errorFactoryWrapper"),
103
+ undefined,
104
+ [
105
+ ts.factory.createObjectLiteralExpression([
106
+ ts.factory.createSpreadAssignment(ts.factory.createIdentifier("p")),
107
+ ts.factory.createPropertyAssignment(
108
+ "path",
109
+ ts.factory.createCallExpression(
110
+ ts.factory.createPropertyAccessExpression(
111
+ ts.factory.createPropertyAccessExpression(
112
+ ts.factory.createIdentifier("p"),
113
+ "path",
114
+ ),
115
+ "replace",
116
+ ),
117
+ undefined,
118
+ [
119
+ ts.factory.createStringLiteral("$input"),
120
+ ts.factory.createStringLiteral(replacer),
121
+ ],
122
+ ),
123
+ ),
124
+ ]),
125
+ ],
126
+ ),
127
+ );
43
128
  }
@@ -1,7 +1,11 @@
1
1
  import ts from "typescript";
2
+
3
+ import { TypeFactory } from "../../factories/TypeFactory";
4
+
2
5
  import { IProject } from "../../transformers/IProject";
3
- import { StatementFactory } from "../../factories/StatementFactory";
6
+
4
7
  import { AssertProgrammer } from "../AssertProgrammer";
8
+ import { FunctionalAssertFunctionProgrammer } from "./FunctionalAssertFunctionProgrammer";
5
9
 
6
10
  export namespace FunctionalAssertParametersProgrammer {
7
11
  export const write =
@@ -13,10 +17,6 @@ export namespace FunctionalAssertParametersProgrammer {
13
17
  declaration: ts.FunctionDeclaration,
14
18
  init?: ts.Expression,
15
19
  ): ts.ArrowFunction => {
16
- const { assert, call } = prepare(project)(modulo)(equals)(
17
- declaration,
18
- init,
19
- );
20
20
  const async: boolean = (() => {
21
21
  if (declaration.type === undefined) return false;
22
22
  const type: ts.Type = project.checker.getTypeFromTypeNode(
@@ -24,7 +24,6 @@ export namespace FunctionalAssertParametersProgrammer {
24
24
  );
25
25
  return type.isTypeParameter() && type.symbol.name === "Promise";
26
26
  })();
27
-
28
27
  return ts.factory.createArrowFunction(
29
28
  async
30
29
  ? [ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword)]
@@ -35,8 +34,10 @@ export namespace FunctionalAssertParametersProgrammer {
35
34
  undefined,
36
35
  ts.factory.createBlock(
37
36
  [
38
- assert,
39
- call,
37
+ FunctionalAssertFunctionProgrammer.errorFactory(modulo)(init),
38
+ ...argumentExpressions(project)(modulo)(equals)(
39
+ declaration.parameters,
40
+ ).map(ts.factory.createExpressionStatement),
40
41
  ts.factory.createReturnStatement(
41
42
  ts.factory.createCallExpression(
42
43
  expression,
@@ -52,48 +53,24 @@ export namespace FunctionalAssertParametersProgrammer {
52
53
  );
53
54
  };
54
55
 
55
- export const prepare =
56
+ export const argumentExpressions =
56
57
  (project: IProject) =>
57
58
  (modulo: ts.LeftHandSideExpression) =>
58
59
  (equals: boolean) =>
59
- (declaration: ts.FunctionDeclaration, init?: ts.Expression) => {
60
- const typeNode: ts.TypeNode = ts.factory.createTypeLiteralNode([
61
- ts.factory.createPropertySignature(
62
- undefined,
63
- "parameters",
64
- undefined,
65
- ts.factory.createTupleTypeNode(
66
- declaration.parameters.map((p) => p.type!),
67
- ),
68
- ),
69
- ]);
70
- const type: ts.Type = project.checker.getTypeFromTypeNode(typeNode);
71
-
72
- const assert = StatementFactory.constant(
73
- "assert",
74
- AssertProgrammer.write(project)(modulo)(equals)(type, undefined, init),
75
- );
76
- const call = ts.factory.createExpressionStatement(
60
+ (parameters: readonly ts.ParameterDeclaration[]): ts.CallExpression[] =>
61
+ parameters.map((p, i) =>
77
62
  ts.factory.createCallExpression(
78
- ts.factory.createIdentifier("assert"),
79
- undefined,
80
- [
81
- ts.factory.createObjectLiteralExpression(
82
- [
83
- ts.factory.createPropertyAssignment(
84
- "parameters",
85
- ts.factory.createArrayLiteralExpression(
86
- declaration.parameters.map((p) =>
87
- ts.factory.createIdentifier(p.name.getText()),
88
- ),
89
- ),
90
- ),
91
- ],
92
- true,
63
+ AssertProgrammer.write(project)(modulo)(equals)(
64
+ p.type
65
+ ? project.checker.getTypeFromTypeNode(p.type)
66
+ : project.checker.getTypeFromTypeNode(TypeFactory.keyword("any")),
67
+ undefined,
68
+ FunctionalAssertFunctionProgrammer.hookPath(
69
+ `$input.parameters[${i}]`,
93
70
  ),
94
- ],
71
+ ),
72
+ undefined,
73
+ [ts.factory.createIdentifier(p.name.getText())],
95
74
  ),
96
75
  );
97
- return { assert, call, type };
98
- };
99
76
  }
@@ -1,7 +1,11 @@
1
1
  import ts from "typescript";
2
+
3
+ import { TypeFactory } from "../../factories/TypeFactory";
4
+
2
5
  import { IProject } from "../../transformers/IProject";
3
- import { StatementFactory } from "../../factories/StatementFactory";
6
+
4
7
  import { AssertProgrammer } from "../AssertProgrammer";
8
+ import { FunctionalAssertFunctionProgrammer } from "./FunctionalAssertFunctionProgrammer";
5
9
 
6
10
  export namespace FunctionAssertReturnProgrammer {
7
11
  export const write =
@@ -13,9 +17,15 @@ export namespace FunctionAssertReturnProgrammer {
13
17
  declaration: ts.FunctionDeclaration,
14
18
  init?: ts.Expression,
15
19
  ): ts.ArrowFunction => {
16
- const { async, assert, variable, call, returns } = prepare(project)(
17
- modulo,
18
- )(equals)(expression, declaration, init);
20
+ const { async, returns: statement } = returnStatement(project)(modulo)(
21
+ equals,
22
+ )(
23
+ expression,
24
+ declaration.type,
25
+ declaration.parameters.map((p) =>
26
+ ts.factory.createIdentifier(p.name.getText()),
27
+ ),
28
+ );
19
29
  return ts.factory.createArrowFunction(
20
30
  async
21
31
  ? [ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword)]
@@ -24,60 +34,54 @@ export namespace FunctionAssertReturnProgrammer {
24
34
  declaration.parameters,
25
35
  declaration.type,
26
36
  undefined,
27
- ts.factory.createBlock([assert, variable, call, returns], true),
37
+ ts.factory.createBlock(
38
+ [
39
+ FunctionalAssertFunctionProgrammer.errorFactory(modulo)(init),
40
+ statement,
41
+ ],
42
+ true,
43
+ ),
28
44
  );
29
45
  };
30
46
 
31
- export const prepare =
47
+ export const returnStatement =
32
48
  (project: IProject) =>
33
49
  (modulo: ts.LeftHandSideExpression) =>
34
50
  (equals: boolean) =>
35
51
  (
36
52
  expression: ts.Expression,
37
- declaration: ts.FunctionDeclaration,
38
- init?: ts.Expression,
39
- ) => {
53
+ typeNode: ts.TypeNode | undefined,
54
+ argumentExpressions: ts.Expression[],
55
+ ): {
56
+ async: boolean;
57
+ returns: ts.ReturnStatement;
58
+ } => {
40
59
  const [type, async]: [ts.Type, boolean] = (() => {
41
60
  const type: ts.Type = project.checker.getTypeFromTypeNode(
42
- declaration.type!,
61
+ typeNode ?? TypeFactory.keyword("any"),
43
62
  );
44
63
  return type.isTypeParameter() && type.symbol.name === "Promise"
45
64
  ? [type.aliasTypeArguments![0]!, true]
46
65
  : [type, false];
47
66
  })();
48
- const assert = StatementFactory.constant(
49
- "assert",
50
- AssertProgrammer.write(project)(modulo)(equals)(type, undefined, init),
51
- );
52
- const funcCaller = ts.factory.createCallExpression(
67
+ const caller: ts.CallExpression = ts.factory.createCallExpression(
53
68
  expression,
54
69
  undefined,
55
- declaration.parameters.map((p) =>
56
- ts.factory.createIdentifier(p.name.getText()),
57
- ),
70
+ argumentExpressions,
58
71
  );
59
- const variable = StatementFactory.constant(
60
- "output",
61
- async ? ts.factory.createAwaitExpression(funcCaller) : funcCaller,
62
- );
63
-
64
- const call = ts.factory.createExpressionStatement(
65
- ts.factory.createCallExpression(
66
- ts.factory.createIdentifier("assert"),
67
- undefined,
68
- [
69
- ts.factory.createObjectLiteralExpression([
70
- ts.factory.createPropertyAssignment(
71
- "return",
72
- ts.factory.createIdentifier("output"),
73
- ),
74
- ]),
75
- ],
72
+ return {
73
+ async,
74
+ returns: ts.factory.createReturnStatement(
75
+ ts.factory.createCallExpression(
76
+ AssertProgrammer.write(project)(modulo)(equals)(
77
+ type,
78
+ undefined,
79
+ FunctionalAssertFunctionProgrammer.hookPath("$input.return"),
80
+ ),
81
+ undefined,
82
+ [async ? ts.factory.createAwaitExpression(caller) : caller],
83
+ ),
76
84
  ),
77
- );
78
- const returns = ts.factory.createReturnStatement(
79
- ts.factory.createIdentifier("output"),
80
- );
81
- return { async, type, assert, variable, call, returns };
85
+ };
82
86
  };
83
87
  }
@@ -1,87 +1 @@
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
- export class FunctionImporter {
8
- private readonly used_: Set<string> = new Set();
9
- private readonly local_: Set<string> = new Set();
10
- private readonly unions_: Map<string, [string, ts.ArrowFunction]> = new Map();
11
- private sequence_: number = 0;
12
-
13
- public constructor(public readonly method: string) {}
14
-
15
- public empty(): boolean {
16
- return this.used_.size === 0;
17
- }
18
-
19
- public use(name: string): ts.Identifier {
20
- this.used_.add(name);
21
- return ts.factory.createIdentifier("$" + name);
22
- }
23
-
24
- public useLocal(name: string): string {
25
- this.local_.add(name);
26
- return name;
27
- }
28
-
29
- public hasLocal(name: string): boolean {
30
- return this.local_.has(name);
31
- }
32
-
33
- public declare(
34
- modulo: ts.LeftHandSideExpression,
35
- includeUnions: boolean = true,
36
- ): ts.Statement[] {
37
- return [
38
- ...[...this.used_].map((name) =>
39
- StatementFactory.constant(
40
- "$" + name,
41
- IdentifierFactory.access(
42
- ts.factory.createParenthesizedExpression(
43
- ts.factory.createAsExpression(modulo, TypeFactory.keyword("any")),
44
- ),
45
- )(name),
46
- ),
47
- ),
48
- ...(includeUnions === true
49
- ? [...this.unions_.values()].map(([key, arrow]) =>
50
- StatementFactory.constant(key, arrow),
51
- )
52
- : []),
53
- ];
54
- }
55
-
56
- public declareUnions(): ts.Statement[] {
57
- return [...this.unions_.values()].map(([key, arrow]) =>
58
- StatementFactory.constant(key, arrow),
59
- );
60
- }
61
-
62
- public increment(): number {
63
- return ++this.sequence_;
64
- }
65
-
66
- public emplaceUnion(
67
- prefix: string,
68
- name: string,
69
- factory: () => ts.ArrowFunction,
70
- ): string {
71
- const oldbie = this.unions_.get(name);
72
- if (oldbie) return oldbie[0];
73
-
74
- const index: number = this.unions_.size;
75
- const accessor: string = `${prefix}p${index}`;
76
-
77
- const tuple: [string, ReturnType<typeof factory>] = [accessor, null!];
78
- this.unions_.set(name, tuple);
79
- tuple[1] = factory();
80
- return accessor;
81
- }
82
-
83
- public trace(): void {
84
- console.log(...this.used_);
85
- console.log(...this.local_);
86
- }
87
- }
1
+ export * from "./FunctionImporter";
@@ -0,0 +1,87 @@
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
+ export class FunctionImporter {
8
+ private readonly used_: Set<string> = new Set();
9
+ private readonly local_: Set<string> = new Set();
10
+ private readonly unions_: Map<string, [string, ts.ArrowFunction]> = new Map();
11
+ private sequence_: number = 0;
12
+
13
+ public constructor(public readonly method: string) {}
14
+
15
+ public empty(): boolean {
16
+ return this.used_.size === 0;
17
+ }
18
+
19
+ public use(name: string): ts.Identifier {
20
+ this.used_.add(name);
21
+ return ts.factory.createIdentifier("$" + name);
22
+ }
23
+
24
+ public useLocal(name: string): string {
25
+ this.local_.add(name);
26
+ return name;
27
+ }
28
+
29
+ public hasLocal(name: string): boolean {
30
+ return this.local_.has(name);
31
+ }
32
+
33
+ public declare(
34
+ modulo: ts.LeftHandSideExpression,
35
+ includeUnions: boolean = true,
36
+ ): ts.Statement[] {
37
+ return [
38
+ ...[...this.used_].map((name) =>
39
+ StatementFactory.constant(
40
+ "$" + name,
41
+ IdentifierFactory.access(
42
+ ts.factory.createParenthesizedExpression(
43
+ ts.factory.createAsExpression(modulo, TypeFactory.keyword("any")),
44
+ ),
45
+ )(name),
46
+ ),
47
+ ),
48
+ ...(includeUnions === true
49
+ ? [...this.unions_.values()].map(([key, arrow]) =>
50
+ StatementFactory.constant(key, arrow),
51
+ )
52
+ : []),
53
+ ];
54
+ }
55
+
56
+ public declareUnions(): ts.Statement[] {
57
+ return [...this.unions_.values()].map(([key, arrow]) =>
58
+ StatementFactory.constant(key, arrow),
59
+ );
60
+ }
61
+
62
+ public increment(): number {
63
+ return ++this.sequence_;
64
+ }
65
+
66
+ public emplaceUnion(
67
+ prefix: string,
68
+ name: string,
69
+ factory: () => ts.ArrowFunction,
70
+ ): string {
71
+ const oldbie = this.unions_.get(name);
72
+ if (oldbie) return oldbie[0];
73
+
74
+ const index: number = this.unions_.size;
75
+ const accessor: string = `${prefix}p${index}`;
76
+
77
+ const tuple: [string, ReturnType<typeof factory>] = [accessor, null!];
78
+ this.unions_.set(name, tuple);
79
+ tuple[1] = factory();
80
+ return accessor;
81
+ }
82
+
83
+ public trace(): void {
84
+ console.log(...this.used_);
85
+ console.log(...this.local_);
86
+ }
87
+ }
@@ -5,7 +5,7 @@ import { TemplateFactory } from "../../factories/TemplateFactory";
5
5
 
6
6
  import { stringify_dynamic_properties } from "../internal/stringify_dynamic_properties";
7
7
  import { stringify_regular_properties } from "../internal/stringify_regular_properties";
8
- import { FunctionImporter } from "./FunctionImporeter";
8
+ import { FunctionImporter } from "./FunctionImporter";
9
9
  import { IExpressionEntry } from "./IExpressionEntry";
10
10
 
11
11
  export namespace StringifyJoiner {
@@ -1,6 +1,6 @@
1
1
  import ts from "typescript";
2
2
 
3
- import { FunctionImporter } from "./FunctionImporeter";
3
+ import { FunctionImporter } from "./FunctionImporter";
4
4
 
5
5
  export const disable_function_importer_declare = (
6
6
  importer: FunctionImporter,
@@ -18,7 +18,7 @@ import { Atomic } from "../../typings/Atomic";
18
18
 
19
19
  import { Escaper } from "../../utils/Escaper";
20
20
 
21
- import { FunctionImporter } from "../helpers/FunctionImporeter";
21
+ import { FunctionImporter } from "../helpers/FunctionImporter";
22
22
  import { HttpMetadataUtil } from "../helpers/HttpMetadataUtil";
23
23
 
24
24
  export namespace HttpFormDataProgrammer {
@@ -20,7 +20,7 @@ import { Atomic } from "../../typings/Atomic";
20
20
  import { Escaper } from "../../utils/Escaper";
21
21
  import { MapUtil } from "../../utils/MapUtil";
22
22
 
23
- import { FunctionImporter } from "../helpers/FunctionImporeter";
23
+ import { FunctionImporter } from "../helpers/FunctionImporter";
24
24
  import { HttpMetadataUtil } from "../helpers/HttpMetadataUtil";
25
25
 
26
26
  export namespace HttpHeadersProgrammer {
@@ -12,7 +12,7 @@ import { IProject } from "../../transformers/IProject";
12
12
  import { TransformerError } from "../../transformers/TransformerError";
13
13
 
14
14
  import { AssertProgrammer } from "../AssertProgrammer";
15
- import { FunctionImporter } from "../helpers/FunctionImporeter";
15
+ import { FunctionImporter } from "../helpers/FunctionImporter";
16
16
  import { HttpMetadataUtil } from "../helpers/HttpMetadataUtil";
17
17
 
18
18
  export namespace HttpParameterProgrammer {
@@ -18,7 +18,7 @@ import { Atomic } from "../../typings/Atomic";
18
18
 
19
19
  import { Escaper } from "../../utils/Escaper";
20
20
 
21
- import { FunctionImporter } from "../helpers/FunctionImporeter";
21
+ import { FunctionImporter } from "../helpers/FunctionImporter";
22
22
  import { HttpMetadataUtil } from "../helpers/HttpMetadataUtil";
23
23
 
24
24
  export namespace HttpQueryProgrammer {
@@ -4,7 +4,7 @@ import { Metadata } from "../../schemas/metadata/Metadata";
4
4
 
5
5
  import { IProject } from "../../transformers/IProject";
6
6
 
7
- import { FunctionImporter } from "../helpers/FunctionImporeter";
7
+ import { FunctionImporter } from "../helpers/FunctionImporter";
8
8
  import { ICheckEntry } from "../helpers/ICheckEntry";
9
9
  import { check_bigint } from "./check_bigint";
10
10
  import { check_number } from "./check_number";
@@ -6,7 +6,7 @@ import { StatementFactory } from "../../factories/StatementFactory";
6
6
 
7
7
  import { IProject } from "../../transformers/IProject";
8
8
 
9
- import { FunctionImporter } from "../helpers/FunctionImporeter";
9
+ import { FunctionImporter } from "../helpers/FunctionImporter";
10
10
  import { IExpressionEntry } from "../helpers/IExpressionEntry";
11
11
  import { check_dynamic_key } from "./check_dynamic_key";
12
12
  import { check_everything } from "./check_everything";
@@ -2,7 +2,7 @@ import ts from "typescript";
2
2
 
3
3
  import { IProject } from "../../transformers/IProject";
4
4
 
5
- import { FunctionImporter } from "../helpers/FunctionImporeter";
5
+ import { FunctionImporter } from "../helpers/FunctionImporter";
6
6
  import { IExpressionEntry } from "../helpers/IExpressionEntry";
7
7
  import { check_dynamic_properties } from "./check_dynamic_properties";
8
8
  import { check_everything } from "./check_everything";