@duplojs/http 0.1.0 → 0.2.0

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 (155) hide show
  1. package/dist/core/builders/index.cjs +11 -0
  2. package/dist/core/builders/index.mjs +4 -0
  3. package/dist/core/builders/preflight/index.cjs +10 -0
  4. package/dist/core/builders/preflight/index.mjs +3 -0
  5. package/dist/core/builders/preflight/process.cjs +2 -8
  6. package/dist/core/builders/preflight/process.mjs +2 -8
  7. package/dist/core/builders/preflight/route.cjs +2 -8
  8. package/dist/core/builders/preflight/route.mjs +2 -8
  9. package/dist/core/builders/process/checker.cjs +2 -8
  10. package/dist/core/builders/process/checker.mjs +2 -8
  11. package/dist/core/builders/process/cut.cjs +2 -8
  12. package/dist/core/builders/process/cut.mjs +2 -8
  13. package/dist/core/builders/process/extract.cjs +2 -8
  14. package/dist/core/builders/process/extract.mjs +2 -8
  15. package/dist/core/builders/process/index.cjs +14 -0
  16. package/dist/core/builders/process/index.mjs +7 -0
  17. package/dist/core/builders/process/presetChecker.cjs +2 -8
  18. package/dist/core/builders/process/presetChecker.mjs +2 -8
  19. package/dist/core/builders/process/process.cjs +2 -8
  20. package/dist/core/builders/process/process.mjs +2 -8
  21. package/dist/core/builders/route/checker.cjs +2 -8
  22. package/dist/core/builders/route/checker.mjs +2 -8
  23. package/dist/core/builders/route/cut.cjs +2 -8
  24. package/dist/core/builders/route/cut.mjs +2 -8
  25. package/dist/core/builders/route/extract.cjs +2 -8
  26. package/dist/core/builders/route/extract.mjs +2 -8
  27. package/dist/core/builders/route/handler.cjs +2 -8
  28. package/dist/core/builders/route/handler.mjs +2 -8
  29. package/dist/core/builders/route/index.cjs +16 -0
  30. package/dist/core/builders/route/index.mjs +8 -0
  31. package/dist/core/builders/route/presetChecker.cjs +2 -8
  32. package/dist/core/builders/route/presetChecker.mjs +2 -8
  33. package/dist/core/builders/route/process.cjs +2 -8
  34. package/dist/core/builders/route/process.mjs +2 -8
  35. package/dist/core/floor.cjs +2 -0
  36. package/dist/core/floor.mjs +1 -0
  37. package/dist/core/functionsBuilders/index.cjs +5 -0
  38. package/dist/core/functionsBuilders/index.mjs +2 -0
  39. package/dist/core/functionsBuilders/route/build.cjs +5 -14
  40. package/dist/core/functionsBuilders/route/build.d.ts +3 -1
  41. package/dist/core/functionsBuilders/route/build.mjs +6 -15
  42. package/dist/core/functionsBuilders/route/create.d.ts +2 -0
  43. package/dist/core/functionsBuilders/route/default.cjs +1 -12
  44. package/dist/core/functionsBuilders/route/default.mjs +2 -13
  45. package/dist/core/functionsBuilders/route/index.cjs +18 -0
  46. package/dist/core/functionsBuilders/route/index.mjs +4 -0
  47. package/dist/core/functionsBuilders/steps/build.cjs +4 -0
  48. package/dist/core/functionsBuilders/steps/build.d.ts +2 -0
  49. package/dist/core/functionsBuilders/steps/build.mjs +5 -1
  50. package/dist/core/functionsBuilders/steps/create.d.ts +2 -1
  51. package/dist/core/functionsBuilders/steps/defaults/checkerStep.cjs +3 -8
  52. package/dist/core/functionsBuilders/steps/defaults/checkerStep.mjs +3 -8
  53. package/dist/core/functionsBuilders/steps/defaults/cutStep.cjs +3 -9
  54. package/dist/core/functionsBuilders/steps/defaults/cutStep.mjs +4 -10
  55. package/dist/core/functionsBuilders/steps/defaults/extractStep.cjs +4 -12
  56. package/dist/core/functionsBuilders/steps/defaults/extractStep.mjs +5 -13
  57. package/dist/core/functionsBuilders/steps/defaults/handlerStep.cjs +3 -9
  58. package/dist/core/functionsBuilders/steps/defaults/handlerStep.mjs +3 -9
  59. package/dist/core/functionsBuilders/steps/defaults/index.cjs +16 -0
  60. package/dist/core/functionsBuilders/steps/defaults/index.mjs +5 -0
  61. package/dist/core/functionsBuilders/steps/defaults/processStep.cjs +2 -8
  62. package/dist/core/functionsBuilders/steps/defaults/processStep.mjs +3 -9
  63. package/dist/core/functionsBuilders/steps/index.cjs +10 -0
  64. package/dist/core/functionsBuilders/steps/index.mjs +3 -0
  65. package/dist/core/hub/defaultNotfoundHandler.cjs +2 -8
  66. package/dist/core/hub/defaultNotfoundHandler.mjs +2 -8
  67. package/dist/core/hub/hooks.d.ts +3 -3
  68. package/dist/core/hub/index.cjs +2 -8
  69. package/dist/core/hub/index.mjs +2 -8
  70. package/dist/core/index.cjs +54 -63
  71. package/dist/core/index.mjs +21 -30
  72. package/dist/core/process/index.cjs +1 -0
  73. package/dist/core/process/index.mjs +1 -0
  74. package/dist/core/process/types/index.cjs +2 -0
  75. package/dist/core/process/types/index.mjs +1 -0
  76. package/dist/core/response/contract.cjs +11 -11
  77. package/dist/core/response/contract.d.ts +2 -2
  78. package/dist/core/response/contract.mjs +12 -12
  79. package/dist/core/route/hooks/response.cjs +1 -1
  80. package/dist/core/route/hooks/response.d.ts +1 -1
  81. package/dist/core/route/hooks/response.mjs +1 -1
  82. package/dist/core/route/index.cjs +1 -0
  83. package/dist/core/route/index.mjs +1 -0
  84. package/dist/core/route/types/buildedRoute.cjs +2 -0
  85. package/dist/core/route/types/buildedRoute.mjs +1 -0
  86. package/dist/core/route/types/index.cjs +4 -0
  87. package/dist/core/route/types/index.mjs +1 -0
  88. package/dist/core/router/buildError.cjs +3 -1
  89. package/dist/core/router/buildError.d.ts +4 -2
  90. package/dist/core/router/buildError.mjs +3 -1
  91. package/dist/core/router/index.cjs +13 -7
  92. package/dist/core/router/index.mjs +14 -8
  93. package/dist/core/router/types/buildedRouter.cjs +2 -0
  94. package/dist/core/router/types/buildedRouter.mjs +1 -0
  95. package/dist/core/router/types/index.cjs +4 -0
  96. package/dist/core/router/types/index.mjs +1 -0
  97. package/dist/core/steps/identifier.d.ts +2 -2
  98. package/dist/core/steps/index.cjs +29 -0
  99. package/dist/core/steps/index.mjs +9 -0
  100. package/dist/core/steps/types/buildedStep.cjs +2 -0
  101. package/dist/core/steps/types/buildedStep.mjs +1 -0
  102. package/dist/core/steps/types/index.cjs +6 -0
  103. package/dist/core/steps/types/index.mjs +3 -0
  104. package/dist/core/steps/types/stepFunctionParams.cjs +2 -0
  105. package/dist/core/steps/types/stepFunctionParams.mjs +1 -0
  106. package/dist/core/steps/types/steps.cjs +2 -0
  107. package/dist/core/steps/types/steps.mjs +1 -0
  108. package/dist/core/types/environment.cjs +2 -0
  109. package/dist/core/types/environment.d.ts +1 -1
  110. package/dist/core/types/environment.mjs +1 -0
  111. package/dist/core/types/index.cjs +4 -0
  112. package/dist/core/types/index.mjs +1 -0
  113. package/dist/interfaces/bun/index.cjs +1 -9
  114. package/dist/interfaces/bun/index.mjs +1 -9
  115. package/dist/interfaces/bun/types/index.cjs +4 -0
  116. package/dist/interfaces/bun/types/index.mjs +1 -0
  117. package/dist/interfaces/bun/types/request.cjs +5 -0
  118. package/dist/interfaces/bun/types/request.mjs +2 -0
  119. package/dist/interfaces/deno/index.cjs +1 -0
  120. package/dist/interfaces/deno/index.mjs +1 -0
  121. package/dist/interfaces/deno/types/index.cjs +2 -0
  122. package/dist/interfaces/deno/types/index.mjs +1 -0
  123. package/dist/interfaces/node/createHttpServer.cjs +10 -3
  124. package/dist/interfaces/node/createHttpServer.mjs +10 -3
  125. package/dist/interfaces/node/error/index.cjs +11 -0
  126. package/dist/interfaces/node/error/index.mjs +3 -0
  127. package/dist/interfaces/node/hooks.cjs +3 -2
  128. package/dist/interfaces/node/hooks.mjs +3 -2
  129. package/dist/interfaces/node/index.cjs +6 -13
  130. package/dist/interfaces/node/index.mjs +4 -11
  131. package/dist/interfaces/node/types/host.cjs +2 -0
  132. package/dist/interfaces/node/types/host.mjs +1 -0
  133. package/dist/interfaces/node/types/index.cjs +5 -0
  134. package/dist/interfaces/node/types/index.mjs +2 -0
  135. package/dist/interfaces/node/types/request.cjs +5 -0
  136. package/dist/interfaces/node/types/request.mjs +2 -0
  137. package/dist/plugins/codeGenerator/index.cjs +16 -0
  138. package/dist/plugins/codeGenerator/index.d.ts +5 -0
  139. package/dist/plugins/codeGenerator/index.mjs +5 -0
  140. package/dist/plugins/codeGenerator/plugin.cjs +51 -0
  141. package/dist/plugins/codeGenerator/plugin.d.ts +5 -0
  142. package/dist/plugins/codeGenerator/plugin.mjs +30 -0
  143. package/dist/plugins/codeGenerator/routeToDataParser.cjs +79 -0
  144. package/dist/plugins/codeGenerator/routeToDataParser.d.ts +186 -0
  145. package/dist/plugins/codeGenerator/routeToDataParser.mjs +74 -0
  146. package/dist/plugins/codeGenerator/stepsToDataParser.cjs +66 -0
  147. package/dist/plugins/codeGenerator/stepsToDataParser.d.ts +14 -0
  148. package/dist/plugins/codeGenerator/stepsToDataParser.mjs +64 -0
  149. package/dist/plugins/codeGenerator/types/entrypointKey.cjs +2 -0
  150. package/dist/plugins/codeGenerator/types/entrypointKey.d.ts +1 -0
  151. package/dist/plugins/codeGenerator/types/entrypointKey.mjs +1 -0
  152. package/dist/plugins/codeGenerator/types/index.cjs +4 -0
  153. package/dist/plugins/codeGenerator/types/index.d.ts +1 -0
  154. package/dist/plugins/codeGenerator/types/index.mjs +1 -0
  155. package/package.json +9 -3
@@ -0,0 +1,79 @@
1
+ 'use strict';
2
+
3
+ var stepsToDataParser = require('./stepsToDataParser.cjs');
4
+ var utils = require('@duplojs/utils');
5
+
6
+ const digitDataParser = utils.DP.literal(["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]).setIdentifier("Digit");
7
+ const responseCodeDataParsers = {
8
+ information: utils.DP.templateLiteral([
9
+ "1",
10
+ digitDataParser,
11
+ digitDataParser,
12
+ ]),
13
+ success: utils.DP.templateLiteral([
14
+ "2",
15
+ digitDataParser,
16
+ digitDataParser,
17
+ ]),
18
+ redirection: utils.DP.templateLiteral([
19
+ "3",
20
+ digitDataParser,
21
+ digitDataParser,
22
+ ]),
23
+ clientError: utils.DP.templateLiteral([
24
+ "4",
25
+ digitDataParser,
26
+ digitDataParser,
27
+ ]),
28
+ serverError: utils.DP.templateLiteral([
29
+ "5",
30
+ digitDataParser,
31
+ digitDataParser,
32
+ ]),
33
+ };
34
+ const responseCodeDataParser = utils.DP.union([
35
+ responseCodeDataParsers.information,
36
+ responseCodeDataParsers.success,
37
+ responseCodeDataParsers.redirection,
38
+ responseCodeDataParsers.clientError,
39
+ responseCodeDataParsers.serverError,
40
+ ]).setIdentifier("ResponseCode");
41
+ function routeToDataParser(route, params) {
42
+ return utils.pipe([
43
+ ...route.definition.preflightSteps,
44
+ ...route.definition.steps,
45
+ ], (steps) => stepsToDataParser.stepsToDataParser(steps, {
46
+ defaultExtractContract: params.defaultExtractContract,
47
+ }), utils.O.transformProperty("entrypointContract", utils.innerPipe(utils.O.entries, utils.A.select(({ element: [key, value], select, skip }) => {
48
+ if (utils.DP.dataParserKind.has(value)) {
49
+ return select(utils.O.entry(key, value));
50
+ }
51
+ if (utils.O.countKeys(value) > 0) {
52
+ return select(utils.O.entry(key, utils.DP.object(value)));
53
+ }
54
+ return skip();
55
+ }), utils.O.fromEntries)), ({ endpointContract, entrypointContract }) => utils.DP.object({
56
+ method: utils.DP.literal(route.definition.method),
57
+ path: utils.DP.literal(route.definition.paths),
58
+ ...entrypointContract,
59
+ responses: utils.DP.union([
60
+ utils.DP.object({
61
+ code: responseCodeDataParser,
62
+ information: utils.DP.string(),
63
+ body: utils.DP.unknown(),
64
+ fromHook: utils.DP.literal(true),
65
+ }),
66
+ utils.DP.object({
67
+ code: responseCodeDataParsers.serverError,
68
+ information: utils.DP.string(),
69
+ body: utils.DP.unknown(),
70
+ }),
71
+ ...endpointContract,
72
+ ]),
73
+ }));
74
+ }
75
+
76
+ exports.digitDataParser = digitDataParser;
77
+ exports.responseCodeDataParser = responseCodeDataParser;
78
+ exports.responseCodeDataParsers = responseCodeDataParsers;
79
+ exports.routeToDataParser = routeToDataParser;
@@ -0,0 +1,186 @@
1
+ import { type Route } from "../../core/route";
2
+ import { DP, type DString } from "@duplojs/utils";
3
+ import { type ResponseContract } from "../../core/response";
4
+ export interface RouteToDataParserParams {
5
+ readonly defaultExtractContract: ResponseContract.Contract;
6
+ }
7
+ export declare const digitDataParser: DP.DataParserLiteral<{
8
+ readonly value: readonly DString.Digit[];
9
+ readonly errorMessage?: string | undefined;
10
+ readonly identifier?: string | undefined;
11
+ readonly checkers: readonly [];
12
+ }>;
13
+ export declare const responseCodeDataParsers: {
14
+ information: DP.DataParserTemplateLiteral<{
15
+ readonly template: readonly ["1", DP.DataParserLiteral<{
16
+ readonly value: readonly DString.Digit[];
17
+ readonly errorMessage?: string | undefined;
18
+ readonly identifier?: string | undefined;
19
+ readonly checkers: readonly [];
20
+ }>, DP.DataParserLiteral<{
21
+ readonly value: readonly DString.Digit[];
22
+ readonly errorMessage?: string | undefined;
23
+ readonly identifier?: string | undefined;
24
+ readonly checkers: readonly [];
25
+ }>];
26
+ readonly errorMessage?: string | undefined;
27
+ readonly identifier?: string | undefined;
28
+ readonly pattern: RegExp;
29
+ readonly checkers: readonly [];
30
+ }>;
31
+ success: DP.DataParserTemplateLiteral<{
32
+ readonly template: readonly ["2", DP.DataParserLiteral<{
33
+ readonly value: readonly DString.Digit[];
34
+ readonly errorMessage?: string | undefined;
35
+ readonly identifier?: string | undefined;
36
+ readonly checkers: readonly [];
37
+ }>, DP.DataParserLiteral<{
38
+ readonly value: readonly DString.Digit[];
39
+ readonly errorMessage?: string | undefined;
40
+ readonly identifier?: string | undefined;
41
+ readonly checkers: readonly [];
42
+ }>];
43
+ readonly errorMessage?: string | undefined;
44
+ readonly identifier?: string | undefined;
45
+ readonly pattern: RegExp;
46
+ readonly checkers: readonly [];
47
+ }>;
48
+ redirection: DP.DataParserTemplateLiteral<{
49
+ readonly template: readonly ["3", DP.DataParserLiteral<{
50
+ readonly value: readonly DString.Digit[];
51
+ readonly errorMessage?: string | undefined;
52
+ readonly identifier?: string | undefined;
53
+ readonly checkers: readonly [];
54
+ }>, DP.DataParserLiteral<{
55
+ readonly value: readonly DString.Digit[];
56
+ readonly errorMessage?: string | undefined;
57
+ readonly identifier?: string | undefined;
58
+ readonly checkers: readonly [];
59
+ }>];
60
+ readonly errorMessage?: string | undefined;
61
+ readonly identifier?: string | undefined;
62
+ readonly pattern: RegExp;
63
+ readonly checkers: readonly [];
64
+ }>;
65
+ clientError: DP.DataParserTemplateLiteral<{
66
+ readonly template: readonly ["4", DP.DataParserLiteral<{
67
+ readonly value: readonly DString.Digit[];
68
+ readonly errorMessage?: string | undefined;
69
+ readonly identifier?: string | undefined;
70
+ readonly checkers: readonly [];
71
+ }>, DP.DataParserLiteral<{
72
+ readonly value: readonly DString.Digit[];
73
+ readonly errorMessage?: string | undefined;
74
+ readonly identifier?: string | undefined;
75
+ readonly checkers: readonly [];
76
+ }>];
77
+ readonly errorMessage?: string | undefined;
78
+ readonly identifier?: string | undefined;
79
+ readonly pattern: RegExp;
80
+ readonly checkers: readonly [];
81
+ }>;
82
+ serverError: DP.DataParserTemplateLiteral<{
83
+ readonly template: readonly ["5", DP.DataParserLiteral<{
84
+ readonly value: readonly DString.Digit[];
85
+ readonly errorMessage?: string | undefined;
86
+ readonly identifier?: string | undefined;
87
+ readonly checkers: readonly [];
88
+ }>, DP.DataParserLiteral<{
89
+ readonly value: readonly DString.Digit[];
90
+ readonly errorMessage?: string | undefined;
91
+ readonly identifier?: string | undefined;
92
+ readonly checkers: readonly [];
93
+ }>];
94
+ readonly errorMessage?: string | undefined;
95
+ readonly identifier?: string | undefined;
96
+ readonly pattern: RegExp;
97
+ readonly checkers: readonly [];
98
+ }>;
99
+ };
100
+ export declare const responseCodeDataParser: DP.DataParserUnion<{
101
+ readonly options: [DP.DataParserTemplateLiteral<{
102
+ readonly template: readonly ["1", DP.DataParserLiteral<{
103
+ readonly value: readonly DString.Digit[];
104
+ readonly errorMessage?: string | undefined;
105
+ readonly identifier?: string | undefined;
106
+ readonly checkers: readonly [];
107
+ }>, DP.DataParserLiteral<{
108
+ readonly value: readonly DString.Digit[];
109
+ readonly errorMessage?: string | undefined;
110
+ readonly identifier?: string | undefined;
111
+ readonly checkers: readonly [];
112
+ }>];
113
+ readonly errorMessage?: string | undefined;
114
+ readonly identifier?: string | undefined;
115
+ readonly pattern: RegExp;
116
+ readonly checkers: readonly [];
117
+ }>, DP.DataParserTemplateLiteral<{
118
+ readonly template: readonly ["2", DP.DataParserLiteral<{
119
+ readonly value: readonly DString.Digit[];
120
+ readonly errorMessage?: string | undefined;
121
+ readonly identifier?: string | undefined;
122
+ readonly checkers: readonly [];
123
+ }>, DP.DataParserLiteral<{
124
+ readonly value: readonly DString.Digit[];
125
+ readonly errorMessage?: string | undefined;
126
+ readonly identifier?: string | undefined;
127
+ readonly checkers: readonly [];
128
+ }>];
129
+ readonly errorMessage?: string | undefined;
130
+ readonly identifier?: string | undefined;
131
+ readonly pattern: RegExp;
132
+ readonly checkers: readonly [];
133
+ }>, DP.DataParserTemplateLiteral<{
134
+ readonly template: readonly ["3", DP.DataParserLiteral<{
135
+ readonly value: readonly DString.Digit[];
136
+ readonly errorMessage?: string | undefined;
137
+ readonly identifier?: string | undefined;
138
+ readonly checkers: readonly [];
139
+ }>, DP.DataParserLiteral<{
140
+ readonly value: readonly DString.Digit[];
141
+ readonly errorMessage?: string | undefined;
142
+ readonly identifier?: string | undefined;
143
+ readonly checkers: readonly [];
144
+ }>];
145
+ readonly errorMessage?: string | undefined;
146
+ readonly identifier?: string | undefined;
147
+ readonly pattern: RegExp;
148
+ readonly checkers: readonly [];
149
+ }>, DP.DataParserTemplateLiteral<{
150
+ readonly template: readonly ["4", DP.DataParserLiteral<{
151
+ readonly value: readonly DString.Digit[];
152
+ readonly errorMessage?: string | undefined;
153
+ readonly identifier?: string | undefined;
154
+ readonly checkers: readonly [];
155
+ }>, DP.DataParserLiteral<{
156
+ readonly value: readonly DString.Digit[];
157
+ readonly errorMessage?: string | undefined;
158
+ readonly identifier?: string | undefined;
159
+ readonly checkers: readonly [];
160
+ }>];
161
+ readonly errorMessage?: string | undefined;
162
+ readonly identifier?: string | undefined;
163
+ readonly pattern: RegExp;
164
+ readonly checkers: readonly [];
165
+ }>, DP.DataParserTemplateLiteral<{
166
+ readonly template: readonly ["5", DP.DataParserLiteral<{
167
+ readonly value: readonly DString.Digit[];
168
+ readonly errorMessage?: string | undefined;
169
+ readonly identifier?: string | undefined;
170
+ readonly checkers: readonly [];
171
+ }>, DP.DataParserLiteral<{
172
+ readonly value: readonly DString.Digit[];
173
+ readonly errorMessage?: string | undefined;
174
+ readonly identifier?: string | undefined;
175
+ readonly checkers: readonly [];
176
+ }>];
177
+ readonly errorMessage?: string | undefined;
178
+ readonly identifier?: string | undefined;
179
+ readonly pattern: RegExp;
180
+ readonly checkers: readonly [];
181
+ }>];
182
+ readonly errorMessage?: string | undefined;
183
+ readonly identifier?: string | undefined;
184
+ readonly checkers: readonly [];
185
+ }>;
186
+ export declare function routeToDataParser(route: Route, params: RouteToDataParserParams): DP.DataParser;
@@ -0,0 +1,74 @@
1
+ import { stepsToDataParser } from './stepsToDataParser.mjs';
2
+ import { DP, pipe, O, innerPipe, A } from '@duplojs/utils';
3
+
4
+ const digitDataParser = DP.literal(["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]).setIdentifier("Digit");
5
+ const responseCodeDataParsers = {
6
+ information: DP.templateLiteral([
7
+ "1",
8
+ digitDataParser,
9
+ digitDataParser,
10
+ ]),
11
+ success: DP.templateLiteral([
12
+ "2",
13
+ digitDataParser,
14
+ digitDataParser,
15
+ ]),
16
+ redirection: DP.templateLiteral([
17
+ "3",
18
+ digitDataParser,
19
+ digitDataParser,
20
+ ]),
21
+ clientError: DP.templateLiteral([
22
+ "4",
23
+ digitDataParser,
24
+ digitDataParser,
25
+ ]),
26
+ serverError: DP.templateLiteral([
27
+ "5",
28
+ digitDataParser,
29
+ digitDataParser,
30
+ ]),
31
+ };
32
+ const responseCodeDataParser = DP.union([
33
+ responseCodeDataParsers.information,
34
+ responseCodeDataParsers.success,
35
+ responseCodeDataParsers.redirection,
36
+ responseCodeDataParsers.clientError,
37
+ responseCodeDataParsers.serverError,
38
+ ]).setIdentifier("ResponseCode");
39
+ function routeToDataParser(route, params) {
40
+ return pipe([
41
+ ...route.definition.preflightSteps,
42
+ ...route.definition.steps,
43
+ ], (steps) => stepsToDataParser(steps, {
44
+ defaultExtractContract: params.defaultExtractContract,
45
+ }), O.transformProperty("entrypointContract", innerPipe(O.entries, A.select(({ element: [key, value], select, skip }) => {
46
+ if (DP.dataParserKind.has(value)) {
47
+ return select(O.entry(key, value));
48
+ }
49
+ if (O.countKeys(value) > 0) {
50
+ return select(O.entry(key, DP.object(value)));
51
+ }
52
+ return skip();
53
+ }), O.fromEntries)), ({ endpointContract, entrypointContract }) => DP.object({
54
+ method: DP.literal(route.definition.method),
55
+ path: DP.literal(route.definition.paths),
56
+ ...entrypointContract,
57
+ responses: DP.union([
58
+ DP.object({
59
+ code: responseCodeDataParser,
60
+ information: DP.string(),
61
+ body: DP.unknown(),
62
+ fromHook: DP.literal(true),
63
+ }),
64
+ DP.object({
65
+ code: responseCodeDataParsers.serverError,
66
+ information: DP.string(),
67
+ body: DP.unknown(),
68
+ }),
69
+ ...endpointContract,
70
+ ]),
71
+ }));
72
+ }
73
+
74
+ export { digitDataParser, responseCodeDataParser, responseCodeDataParsers, routeToDataParser };
@@ -0,0 +1,66 @@
1
+ 'use strict';
2
+
3
+ require('../../core/steps/index.cjs');
4
+ var utils = require('@duplojs/utils');
5
+ var process = require('../../core/steps/process.cjs');
6
+ var extract = require('../../core/steps/extract.cjs');
7
+ var presetChecker = require('../../core/steps/presetChecker.cjs');
8
+ var checker = require('../../core/steps/checker.cjs');
9
+ var cut = require('../../core/steps/cut.cjs');
10
+ var handler = require('../../core/steps/handler.cjs');
11
+
12
+ function stepsToDataParser(steps, params) {
13
+ const processContracts = utils.pipe(steps, utils.A.filter(process.processStepKind.has), utils.A.map((element) => stepsToDataParser(element.definition.process.definition.steps, params)), utils.O.to({
14
+ entrypointContract: utils.A.map((result) => result.entrypointContract),
15
+ endpointContract: utils.A.flatMap((result) => result.endpointContract),
16
+ }));
17
+ const entrypointContract = utils.pipe(steps, utils.A.filter(extract.extractStepKind.has), utils.A.map((extractStep) => extractStep.definition.shape), utils.A.concat(processContracts.entrypointContract), utils.A.reduce(utils.A.reduceFrom({
18
+ body: {},
19
+ headers: {},
20
+ params: {},
21
+ query: {},
22
+ }), ({ element: shape, lastValue, nextWithObject }) => utils.pipe(lastValue, utils.O.entries, utils.A.map(([key, accumulatorValue]) => {
23
+ const currentExtractDataParser = shape[key];
24
+ if (utils.DP.dataParserKind.has(accumulatorValue)
25
+ || !currentExtractDataParser
26
+ || (!utils.DP.dataParserKind.has(accumulatorValue)
27
+ && utils.O.countKeys(accumulatorValue) > 1
28
+ && utils.DP.dataParserKind.has(currentExtractDataParser)
29
+ && !utils.DP.objectKind.has(currentExtractDataParser))) {
30
+ return utils.O.entry(key, accumulatorValue);
31
+ }
32
+ if (!utils.DP.dataParserKind.has(currentExtractDataParser)) {
33
+ return utils.O.entry(key, {
34
+ ...accumulatorValue,
35
+ ...currentExtractDataParser,
36
+ });
37
+ }
38
+ if (utils.DP.identifier(currentExtractDataParser, utils.DP.objectKind)) {
39
+ return utils.O.entry(key, {
40
+ ...accumulatorValue,
41
+ ...currentExtractDataParser.definition.shape,
42
+ });
43
+ }
44
+ return utils.O.entry(key, currentExtractDataParser);
45
+ }), utils.O.fromEntries, (object) => nextWithObject(lastValue, object))));
46
+ const endpointContract = utils.pipe(steps, utils.A.flatMap((step) => utils.P.match(step)
47
+ .when(process.processStepKind.has, () => [])
48
+ .when(extract.extractStepKind.has, ({ definition }) => definition.responseContract ?? params.defaultExtractContract)
49
+ .when(presetChecker.presetCheckerStepKind.has, ({ definition }) => definition.presetChecker.definition.responseContract)
50
+ .when(utils.hasSomeKinds([
51
+ checker.checkerStepKind,
52
+ cut.cutStepKind,
53
+ handler.handlerStepKind,
54
+ ]), ({ definition }) => definition.responseContract)
55
+ .exhaustive()), utils.A.map(({ code, information, body }) => utils.DP.object({
56
+ code: utils.DP.literal(code),
57
+ information: utils.DP.literal(information),
58
+ body,
59
+ })), utils.A.concat(processContracts.endpointContract));
60
+ return {
61
+ entrypointContract,
62
+ endpointContract,
63
+ };
64
+ }
65
+
66
+ exports.stepsToDataParser = stepsToDataParser;
@@ -0,0 +1,14 @@
1
+ import { type Steps } from "../../core/steps";
2
+ import { DP } from "@duplojs/utils";
3
+ import { type EntrypointKey } from "./types";
4
+ import { type ResponseContract } from "../../core/response";
5
+ type EntrypointReduceResult = Record<EntrypointKey, DP.DataParser | Record<string, DP.DataParser>>;
6
+ export interface StepsToDataParserParams {
7
+ readonly defaultExtractContract: ResponseContract.Contract;
8
+ }
9
+ export interface StepsToDataParserResult {
10
+ entrypointContract: EntrypointReduceResult;
11
+ endpointContract: DP.DataParser[];
12
+ }
13
+ export declare function stepsToDataParser(steps: readonly Steps[], params: StepsToDataParserParams): StepsToDataParserResult;
14
+ export {};
@@ -0,0 +1,64 @@
1
+ import '../../core/steps/index.mjs';
2
+ import { pipe, A, O, DP, P, hasSomeKinds } from '@duplojs/utils';
3
+ import { processStepKind } from '../../core/steps/process.mjs';
4
+ import { extractStepKind } from '../../core/steps/extract.mjs';
5
+ import { presetCheckerStepKind } from '../../core/steps/presetChecker.mjs';
6
+ import { checkerStepKind } from '../../core/steps/checker.mjs';
7
+ import { cutStepKind } from '../../core/steps/cut.mjs';
8
+ import { handlerStepKind } from '../../core/steps/handler.mjs';
9
+
10
+ function stepsToDataParser(steps, params) {
11
+ const processContracts = pipe(steps, A.filter(processStepKind.has), A.map((element) => stepsToDataParser(element.definition.process.definition.steps, params)), O.to({
12
+ entrypointContract: A.map((result) => result.entrypointContract),
13
+ endpointContract: A.flatMap((result) => result.endpointContract),
14
+ }));
15
+ const entrypointContract = pipe(steps, A.filter(extractStepKind.has), A.map((extractStep) => extractStep.definition.shape), A.concat(processContracts.entrypointContract), A.reduce(A.reduceFrom({
16
+ body: {},
17
+ headers: {},
18
+ params: {},
19
+ query: {},
20
+ }), ({ element: shape, lastValue, nextWithObject }) => pipe(lastValue, O.entries, A.map(([key, accumulatorValue]) => {
21
+ const currentExtractDataParser = shape[key];
22
+ if (DP.dataParserKind.has(accumulatorValue)
23
+ || !currentExtractDataParser
24
+ || (!DP.dataParserKind.has(accumulatorValue)
25
+ && O.countKeys(accumulatorValue) > 1
26
+ && DP.dataParserKind.has(currentExtractDataParser)
27
+ && !DP.objectKind.has(currentExtractDataParser))) {
28
+ return O.entry(key, accumulatorValue);
29
+ }
30
+ if (!DP.dataParserKind.has(currentExtractDataParser)) {
31
+ return O.entry(key, {
32
+ ...accumulatorValue,
33
+ ...currentExtractDataParser,
34
+ });
35
+ }
36
+ if (DP.identifier(currentExtractDataParser, DP.objectKind)) {
37
+ return O.entry(key, {
38
+ ...accumulatorValue,
39
+ ...currentExtractDataParser.definition.shape,
40
+ });
41
+ }
42
+ return O.entry(key, currentExtractDataParser);
43
+ }), O.fromEntries, (object) => nextWithObject(lastValue, object))));
44
+ const endpointContract = pipe(steps, A.flatMap((step) => P.match(step)
45
+ .when(processStepKind.has, () => [])
46
+ .when(extractStepKind.has, ({ definition }) => definition.responseContract ?? params.defaultExtractContract)
47
+ .when(presetCheckerStepKind.has, ({ definition }) => definition.presetChecker.definition.responseContract)
48
+ .when(hasSomeKinds([
49
+ checkerStepKind,
50
+ cutStepKind,
51
+ handlerStepKind,
52
+ ]), ({ definition }) => definition.responseContract)
53
+ .exhaustive()), A.map(({ code, information, body }) => DP.object({
54
+ code: DP.literal(code),
55
+ information: DP.literal(information),
56
+ body,
57
+ })), A.concat(processContracts.endpointContract));
58
+ return {
59
+ entrypointContract,
60
+ endpointContract,
61
+ };
62
+ }
63
+
64
+ export { stepsToDataParser };
@@ -0,0 +1,2 @@
1
+ 'use strict';
2
+
@@ -0,0 +1 @@
1
+ export type EntrypointKey = "query" | "body" | "params" | "headers";
@@ -0,0 +1,4 @@
1
+ 'use strict';
2
+
3
+ require('./entrypointKey.cjs');
4
+
@@ -0,0 +1 @@
1
+ export * from "./entrypointKey";
@@ -0,0 +1 @@
1
+ import './entrypointKey.mjs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duplojs/http",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "author": "mathcovax",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -14,7 +14,7 @@
14
14
  "test:tu:bench": "vitest bench",
15
15
  "test:tu:watch": "vitest --coverage --watch",
16
16
  "test:tu:update": "vitest --coverage --update",
17
- "test:types": "tsc -p tests/core/tsconfig.json && tsc -p tests/interfaces/node/tsconfig.json && tsc -p tests/interfaces/bun/tsconfig.json && tsc -p tests/interfaces/deno/tsconfig.json",
17
+ "test:types": "tsc -p tests/core/tsconfig.json && tsc -p tests/interfaces/node/tsconfig.json && tsc -p tests/interfaces/bun/tsconfig.json && tsc -p tests/interfaces/deno/tsconfig.json && tsc -p tests/plugins/codeGenerator/tsconfig.json",
18
18
  "test:lint": "eslint",
19
19
  "test:lint:fix": "eslint --fix",
20
20
  "prepare": "husky"
@@ -40,6 +40,11 @@
40
40
  "import": "./dist/interfaces/deno/index.mjs",
41
41
  "require": "./dist/interfaces/deno/index.cjs",
42
42
  "types": "./dist/interfaces/deno/index.d.ts"
43
+ },
44
+ "./codeGenerator": {
45
+ "import": "./dist/plugins/codeGenerator/index.mjs",
46
+ "require": "./dist/plugins/codeGenerator/index.cjs",
47
+ "types": "./dist/plugins/codeGenerator/index.d.ts"
43
48
  }
44
49
  },
45
50
  "files": [
@@ -47,7 +52,8 @@
47
52
  "README.md"
48
53
  ],
49
54
  "peerDependencies": {
50
- "@duplojs/utils": ">=1.1.16 <2.0.0"
55
+ "@duplojs/data-parser-tools": ">=0.2.2 <1.0.0",
56
+ "@duplojs/utils": ">=1.3.32 <2.0.0"
51
57
  },
52
58
  "devDependencies": {
53
59
  "@commitlint/cli": "19.8.1",