@duplojs/http 0.1.0 → 0.4.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 (266) hide show
  1. package/dist/client/getBody.cjs +22 -0
  2. package/dist/client/getBody.d.ts +1 -0
  3. package/dist/client/getBody.mjs +20 -0
  4. package/dist/client/hooks.cjs +79 -0
  5. package/dist/client/hooks.d.ts +33 -0
  6. package/dist/client/hooks.mjs +70 -0
  7. package/dist/client/httpClient.cjs +153 -0
  8. package/dist/client/httpClient.d.ts +60 -0
  9. package/dist/client/httpClient.mjs +130 -0
  10. package/dist/client/index.cjs +33 -0
  11. package/dist/client/index.d.ts +9 -0
  12. package/dist/client/index.mjs +9 -0
  13. package/dist/client/insertParamsInPath.cjs +12 -0
  14. package/dist/client/insertParamsInPath.d.ts +2 -0
  15. package/dist/client/insertParamsInPath.mjs +10 -0
  16. package/dist/client/kind.cjs +9 -0
  17. package/dist/client/kind.d.ts +6 -0
  18. package/dist/client/kind.mjs +7 -0
  19. package/dist/client/promiseRequest.cjs +355 -0
  20. package/dist/client/promiseRequest.d.ts +98 -0
  21. package/dist/client/promiseRequest.mjs +332 -0
  22. package/dist/client/queryToString.cjs +25 -0
  23. package/dist/client/queryToString.d.ts +2 -0
  24. package/dist/client/queryToString.mjs +23 -0
  25. package/dist/client/types/ObjectCanBeEmpty.cjs +2 -0
  26. package/dist/client/types/ObjectCanBeEmpty.d.ts +4 -0
  27. package/dist/client/types/ObjectCanBeEmpty.mjs +1 -0
  28. package/dist/client/types/clientRequestParams.cjs +2 -0
  29. package/dist/client/types/clientRequestParams.d.ts +51 -0
  30. package/dist/client/types/clientRequestParams.mjs +1 -0
  31. package/dist/client/types/clientResponse.cjs +2 -0
  32. package/dist/client/types/clientResponse.d.ts +34 -0
  33. package/dist/client/types/clientResponse.mjs +1 -0
  34. package/dist/client/types/index.cjs +7 -0
  35. package/dist/client/types/index.d.ts +4 -0
  36. package/dist/client/types/index.mjs +4 -0
  37. package/dist/client/types/serverRoute.cjs +2 -0
  38. package/dist/client/types/serverRoute.d.ts +22 -0
  39. package/dist/client/types/serverRoute.mjs +1 -0
  40. package/dist/client/unexpectedResponseError.cjs +44 -0
  41. package/dist/client/unexpectedResponseError.d.ts +38 -0
  42. package/dist/client/unexpectedResponseError.mjs +39 -0
  43. package/dist/core/builders/index.cjs +11 -0
  44. package/dist/core/builders/index.mjs +4 -0
  45. package/dist/core/builders/preflight/index.cjs +10 -0
  46. package/dist/core/builders/preflight/index.mjs +3 -0
  47. package/dist/core/builders/preflight/process.cjs +2 -8
  48. package/dist/core/builders/preflight/process.mjs +2 -8
  49. package/dist/core/builders/preflight/route.cjs +2 -8
  50. package/dist/core/builders/preflight/route.mjs +2 -8
  51. package/dist/core/builders/process/checker.cjs +2 -8
  52. package/dist/core/builders/process/checker.mjs +2 -8
  53. package/dist/core/builders/process/cut.cjs +2 -8
  54. package/dist/core/builders/process/cut.mjs +2 -8
  55. package/dist/core/builders/process/extract.cjs +2 -8
  56. package/dist/core/builders/process/extract.mjs +2 -8
  57. package/dist/core/builders/process/index.cjs +14 -0
  58. package/dist/core/builders/process/index.mjs +7 -0
  59. package/dist/core/builders/process/presetChecker.cjs +2 -8
  60. package/dist/core/builders/process/presetChecker.mjs +2 -8
  61. package/dist/core/builders/process/process.cjs +2 -8
  62. package/dist/core/builders/process/process.mjs +2 -8
  63. package/dist/core/builders/route/checker.cjs +2 -8
  64. package/dist/core/builders/route/checker.mjs +2 -8
  65. package/dist/core/builders/route/cut.cjs +2 -8
  66. package/dist/core/builders/route/cut.mjs +2 -8
  67. package/dist/core/builders/route/extract.cjs +2 -8
  68. package/dist/core/builders/route/extract.mjs +2 -8
  69. package/dist/core/builders/route/handler.cjs +2 -8
  70. package/dist/core/builders/route/handler.mjs +2 -8
  71. package/dist/core/builders/route/index.cjs +16 -0
  72. package/dist/core/builders/route/index.mjs +8 -0
  73. package/dist/core/builders/route/presetChecker.cjs +2 -8
  74. package/dist/core/builders/route/presetChecker.mjs +2 -8
  75. package/dist/core/builders/route/process.cjs +2 -8
  76. package/dist/core/builders/route/process.mjs +2 -8
  77. package/dist/core/floor.cjs +2 -0
  78. package/dist/core/floor.mjs +1 -0
  79. package/dist/core/functionsBuilders/index.cjs +5 -0
  80. package/dist/core/functionsBuilders/index.mjs +2 -0
  81. package/dist/core/functionsBuilders/route/build.cjs +5 -14
  82. package/dist/core/functionsBuilders/route/build.d.ts +3 -1
  83. package/dist/core/functionsBuilders/route/build.mjs +6 -15
  84. package/dist/core/functionsBuilders/route/create.d.ts +2 -0
  85. package/dist/core/functionsBuilders/route/default.cjs +11 -21
  86. package/dist/core/functionsBuilders/route/default.mjs +5 -15
  87. package/dist/core/functionsBuilders/route/hook.cjs +22 -22
  88. package/dist/core/functionsBuilders/route/hook.d.ts +2 -2
  89. package/dist/core/functionsBuilders/route/hook.mjs +2 -2
  90. package/dist/core/functionsBuilders/route/index.cjs +18 -0
  91. package/dist/core/functionsBuilders/route/index.mjs +4 -0
  92. package/dist/core/functionsBuilders/steps/build.cjs +4 -0
  93. package/dist/core/functionsBuilders/steps/build.d.ts +2 -0
  94. package/dist/core/functionsBuilders/steps/build.mjs +5 -1
  95. package/dist/core/functionsBuilders/steps/create.d.ts +3 -2
  96. package/dist/core/functionsBuilders/steps/defaults/checkerStep.cjs +5 -9
  97. package/dist/core/functionsBuilders/steps/defaults/checkerStep.mjs +5 -9
  98. package/dist/core/functionsBuilders/steps/defaults/cutStep.cjs +6 -11
  99. package/dist/core/functionsBuilders/steps/defaults/cutStep.mjs +7 -12
  100. package/dist/core/functionsBuilders/steps/defaults/extractStep.cjs +10 -17
  101. package/dist/core/functionsBuilders/steps/defaults/extractStep.mjs +9 -16
  102. package/dist/core/functionsBuilders/steps/defaults/handlerStep.cjs +6 -11
  103. package/dist/core/functionsBuilders/steps/defaults/handlerStep.mjs +6 -11
  104. package/dist/core/functionsBuilders/steps/defaults/index.cjs +16 -0
  105. package/dist/core/functionsBuilders/steps/defaults/index.mjs +5 -0
  106. package/dist/core/functionsBuilders/steps/defaults/processStep.cjs +7 -12
  107. package/dist/core/functionsBuilders/steps/defaults/processStep.mjs +6 -11
  108. package/dist/core/functionsBuilders/steps/index.cjs +10 -0
  109. package/dist/core/functionsBuilders/steps/index.mjs +3 -0
  110. package/dist/core/hub/defaultNotfoundHandler.cjs +2 -8
  111. package/dist/core/hub/defaultNotfoundHandler.d.ts +1 -1
  112. package/dist/core/hub/defaultNotfoundHandler.mjs +2 -8
  113. package/dist/core/hub/hooks.d.ts +3 -3
  114. package/dist/core/hub/index.cjs +3 -9
  115. package/dist/core/hub/index.mjs +3 -9
  116. package/dist/core/index.cjs +64 -70
  117. package/dist/core/index.mjs +23 -30
  118. package/dist/core/process/index.cjs +1 -0
  119. package/dist/core/process/index.mjs +1 -0
  120. package/dist/core/process/types/index.cjs +2 -0
  121. package/dist/core/process/types/index.mjs +1 -0
  122. package/dist/core/response/base.cjs +40 -0
  123. package/dist/core/response/base.d.ts +21 -0
  124. package/dist/core/response/base.mjs +38 -0
  125. package/dist/core/response/contract.cjs +13 -13
  126. package/dist/core/response/contract.d.ts +121 -119
  127. package/dist/core/response/contract.mjs +14 -14
  128. package/dist/core/{route/hooks/response.cjs → response/hook.cjs} +5 -4
  129. package/dist/core/{route/hooks/response.d.ts → response/hook.d.ts} +3 -3
  130. package/dist/core/{route/hooks/response.mjs → response/hook.mjs} +4 -3
  131. package/dist/core/response/index.cjs +9 -38
  132. package/dist/core/response/index.d.ts +3 -20
  133. package/dist/core/response/index.mjs +3 -38
  134. package/dist/core/response/predicted.cjs +22 -0
  135. package/dist/core/response/predicted.d.ts +11 -0
  136. package/dist/core/response/predicted.mjs +20 -0
  137. package/dist/core/route/{hooks/index.cjs → hooks.cjs} +2 -3
  138. package/dist/core/route/{hooks/index.d.ts → hooks.d.ts} +4 -4
  139. package/dist/core/route/{hooks/index.mjs → hooks.mjs} +2 -2
  140. package/dist/core/route/index.cjs +5 -4
  141. package/dist/core/route/index.mjs +2 -1
  142. package/dist/core/route/types/buildedRoute.cjs +2 -0
  143. package/dist/core/route/types/buildedRoute.mjs +1 -0
  144. package/dist/core/route/types/index.cjs +4 -0
  145. package/dist/core/route/types/index.mjs +1 -0
  146. package/dist/core/router/buildError.cjs +3 -1
  147. package/dist/core/router/buildError.d.ts +4 -2
  148. package/dist/core/router/buildError.mjs +3 -1
  149. package/dist/core/router/index.cjs +13 -7
  150. package/dist/core/router/index.mjs +14 -8
  151. package/dist/core/router/types/buildedRouter.cjs +2 -0
  152. package/dist/core/router/types/buildedRouter.mjs +1 -0
  153. package/dist/core/router/types/index.cjs +4 -0
  154. package/dist/core/router/types/index.mjs +1 -0
  155. package/dist/core/steps/cut.d.ts +3 -3
  156. package/dist/core/steps/handler.d.ts +3 -3
  157. package/dist/core/steps/identifier.d.ts +2 -2
  158. package/dist/core/steps/index.cjs +29 -0
  159. package/dist/core/steps/index.mjs +9 -0
  160. package/dist/core/steps/types/buildedStep.cjs +2 -0
  161. package/dist/core/steps/types/buildedStep.mjs +1 -0
  162. package/dist/core/steps/types/index.cjs +6 -0
  163. package/dist/core/steps/types/index.mjs +3 -0
  164. package/dist/core/steps/types/stepFunctionParams.cjs +2 -0
  165. package/dist/core/steps/types/stepFunctionParams.d.ts +2 -2
  166. package/dist/core/steps/types/stepFunctionParams.mjs +1 -0
  167. package/dist/core/steps/types/steps.cjs +2 -0
  168. package/dist/core/steps/types/steps.mjs +1 -0
  169. package/dist/core/types/environment.cjs +2 -0
  170. package/dist/core/types/environment.d.ts +1 -1
  171. package/dist/core/types/environment.mjs +1 -0
  172. package/dist/core/types/forbiddenBigintDataParser.cjs +2 -0
  173. package/dist/core/types/forbiddenBigintDataParser.d.ts +6 -0
  174. package/dist/core/types/forbiddenBigintDataParser.mjs +1 -0
  175. package/dist/core/types/index.cjs +5 -0
  176. package/dist/core/types/index.d.ts +1 -0
  177. package/dist/core/types/index.mjs +2 -0
  178. package/dist/interfaces/bun/index.cjs +1 -9
  179. package/dist/interfaces/bun/index.mjs +1 -9
  180. package/dist/interfaces/bun/types/index.cjs +4 -0
  181. package/dist/interfaces/bun/types/index.mjs +1 -0
  182. package/dist/interfaces/bun/types/request.cjs +5 -0
  183. package/dist/interfaces/bun/types/request.mjs +2 -0
  184. package/dist/interfaces/deno/index.cjs +1 -0
  185. package/dist/interfaces/deno/index.mjs +1 -0
  186. package/dist/interfaces/deno/types/index.cjs +2 -0
  187. package/dist/interfaces/deno/types/index.mjs +1 -0
  188. package/dist/interfaces/node/createHttpServer.cjs +11 -3
  189. package/dist/interfaces/node/createHttpServer.d.ts +2 -1
  190. package/dist/interfaces/node/createHttpServer.mjs +11 -3
  191. package/dist/interfaces/node/error/index.cjs +11 -0
  192. package/dist/interfaces/node/error/index.mjs +3 -0
  193. package/dist/interfaces/node/hooks.cjs +17 -13
  194. package/dist/interfaces/node/hooks.mjs +16 -12
  195. package/dist/interfaces/node/index.cjs +6 -13
  196. package/dist/interfaces/node/index.mjs +4 -11
  197. package/dist/interfaces/node/types/host.cjs +2 -0
  198. package/dist/interfaces/node/types/host.mjs +1 -0
  199. package/dist/interfaces/node/types/index.cjs +5 -0
  200. package/dist/interfaces/node/types/index.mjs +2 -0
  201. package/dist/interfaces/node/types/request.cjs +5 -0
  202. package/dist/interfaces/node/types/request.mjs +2 -0
  203. package/dist/plugins/codeGenerator/index.cjs +13 -0
  204. package/dist/plugins/codeGenerator/index.d.ts +5 -0
  205. package/dist/plugins/codeGenerator/index.mjs +5 -0
  206. package/dist/plugins/codeGenerator/plugin.cjs +51 -0
  207. package/dist/plugins/codeGenerator/plugin.d.ts +5 -0
  208. package/dist/plugins/codeGenerator/plugin.mjs +30 -0
  209. package/dist/plugins/codeGenerator/routeToDataParser.cjs +28 -0
  210. package/dist/plugins/codeGenerator/routeToDataParser.d.ts +7 -0
  211. package/dist/plugins/codeGenerator/routeToDataParser.mjs +26 -0
  212. package/dist/plugins/codeGenerator/stepsToDataParser.cjs +66 -0
  213. package/dist/plugins/codeGenerator/stepsToDataParser.d.ts +14 -0
  214. package/dist/plugins/codeGenerator/stepsToDataParser.mjs +64 -0
  215. package/dist/plugins/codeGenerator/types/entrypointKey.cjs +2 -0
  216. package/dist/plugins/codeGenerator/types/entrypointKey.d.ts +1 -0
  217. package/dist/plugins/codeGenerator/types/entrypointKey.mjs +1 -0
  218. package/dist/plugins/codeGenerator/types/index.cjs +4 -0
  219. package/dist/plugins/codeGenerator/types/index.d.ts +1 -0
  220. package/dist/plugins/codeGenerator/types/index.mjs +1 -0
  221. package/dist/plugins/openApiGenerator/aggregateStepContract.cjs +62 -0
  222. package/dist/plugins/openApiGenerator/aggregateStepContract.d.ts +18 -0
  223. package/dist/plugins/openApiGenerator/aggregateStepContract.mjs +60 -0
  224. package/dist/plugins/openApiGenerator/index.cjs +17 -0
  225. package/dist/plugins/openApiGenerator/index.d.ts +7 -0
  226. package/dist/plugins/openApiGenerator/index.mjs +7 -0
  227. package/dist/plugins/openApiGenerator/makeOpenApiPage.cjs +30 -0
  228. package/dist/plugins/openApiGenerator/makeOpenApiPage.d.ts +7 -0
  229. package/dist/plugins/openApiGenerator/makeOpenApiPage.mjs +28 -0
  230. package/dist/plugins/openApiGenerator/makeOpenApiRoute.cjs +15 -0
  231. package/dist/plugins/openApiGenerator/makeOpenApiRoute.d.ts +18 -0
  232. package/dist/plugins/openApiGenerator/makeOpenApiRoute.mjs +13 -0
  233. package/dist/plugins/openApiGenerator/plugin.cjs +90 -0
  234. package/dist/plugins/openApiGenerator/plugin.d.ts +49 -0
  235. package/dist/plugins/openApiGenerator/plugin.mjs +88 -0
  236. package/dist/plugins/openApiGenerator/routeToOpenApi.cjs +163 -0
  237. package/dist/plugins/openApiGenerator/routeToOpenApi.d.ts +35 -0
  238. package/dist/plugins/openApiGenerator/routeToOpenApi.mjs +161 -0
  239. package/dist/plugins/openApiGenerator/types/endpointResponse.cjs +2 -0
  240. package/dist/plugins/openApiGenerator/types/endpointResponse.d.ts +19 -0
  241. package/dist/plugins/openApiGenerator/types/endpointResponse.mjs +1 -0
  242. package/dist/plugins/openApiGenerator/types/entrypoint.cjs +2 -0
  243. package/dist/plugins/openApiGenerator/types/entrypoint.d.ts +22 -0
  244. package/dist/plugins/openApiGenerator/types/entrypoint.mjs +1 -0
  245. package/dist/plugins/openApiGenerator/types/entrypointKey.cjs +2 -0
  246. package/dist/plugins/openApiGenerator/types/entrypointKey.d.ts +1 -0
  247. package/dist/plugins/openApiGenerator/types/entrypointKey.mjs +1 -0
  248. package/dist/plugins/openApiGenerator/types/index.cjs +11 -0
  249. package/dist/plugins/openApiGenerator/types/index.d.ts +8 -0
  250. package/dist/plugins/openApiGenerator/types/index.mjs +8 -0
  251. package/dist/plugins/openApiGenerator/types/openApiDocument.cjs +2 -0
  252. package/dist/plugins/openApiGenerator/types/openApiDocument.d.ts +31 -0
  253. package/dist/plugins/openApiGenerator/types/openApiDocument.mjs +1 -0
  254. package/dist/plugins/openApiGenerator/types/openApiMethod.cjs +2 -0
  255. package/dist/plugins/openApiGenerator/types/openApiMethod.d.ts +1 -0
  256. package/dist/plugins/openApiGenerator/types/openApiMethod.mjs +1 -0
  257. package/dist/plugins/openApiGenerator/types/openApiOperation.cjs +2 -0
  258. package/dist/plugins/openApiGenerator/types/openApiOperation.d.ts +8 -0
  259. package/dist/plugins/openApiGenerator/types/openApiOperation.mjs +1 -0
  260. package/dist/plugins/openApiGenerator/types/openApiPath.cjs +2 -0
  261. package/dist/plugins/openApiGenerator/types/openApiPath.d.ts +4 -0
  262. package/dist/plugins/openApiGenerator/types/openApiPath.mjs +1 -0
  263. package/dist/plugins/openApiGenerator/types/openApiSecuritySchema.cjs +2 -0
  264. package/dist/plugins/openApiGenerator/types/openApiSecuritySchema.d.ts +8 -0
  265. package/dist/plugins/openApiGenerator/types/openApiSecuritySchema.mjs +1 -0
  266. package/package.json +22 -3
@@ -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';
@@ -0,0 +1,62 @@
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 aggregateStepContract(steps, params) {
13
+ const processContracts = utils.pipe(steps, utils.A.filter(process.processStepKind.has), utils.A.map((element) => aggregateStepContract(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.concat(processContracts.endpointContract));
56
+ return {
57
+ entrypointContract,
58
+ endpointContract,
59
+ };
60
+ }
61
+
62
+ exports.aggregateStepContract = aggregateStepContract;
@@ -0,0 +1,18 @@
1
+ import { type Steps } from "../../core/steps";
2
+ import { DP } from "@duplojs/utils";
3
+ import type { ResponseCode, ResponseContract } from "../../core/response";
4
+ import type { EntrypointKey } from "./types";
5
+ export interface EndpointRouteResult {
6
+ code: ResponseCode;
7
+ information: string;
8
+ body: DP.DataParser;
9
+ }
10
+ export type EntrypointReduceResult = Record<EntrypointKey, DP.DataParser | Record<string, DP.DataParser>>;
11
+ export interface AggregateStepsResult {
12
+ entrypointContract: EntrypointReduceResult;
13
+ endpointContract: EndpointRouteResult[];
14
+ }
15
+ export interface AggregateStepsParams {
16
+ readonly defaultExtractContract: ResponseContract.Contract;
17
+ }
18
+ export declare function aggregateStepContract(steps: readonly Steps[], params: AggregateStepsParams): AggregateStepsResult;
@@ -0,0 +1,60 @@
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 aggregateStepContract(steps, params) {
11
+ const processContracts = pipe(steps, A.filter(processStepKind.has), A.map((element) => aggregateStepContract(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.concat(processContracts.endpointContract));
54
+ return {
55
+ entrypointContract,
56
+ endpointContract,
57
+ };
58
+ }
59
+
60
+ export { aggregateStepContract };
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+ require('@duplojs/data-parser-tools/toJsonSchema');
4
+ require('./types/index.cjs');
5
+ var plugin = require('./plugin.cjs');
6
+ var routeToOpenApi = require('./routeToOpenApi.cjs');
7
+ var aggregateStepContract = require('./aggregateStepContract.cjs');
8
+ var makeOpenApiRoute = require('./makeOpenApiRoute.cjs');
9
+ var makeOpenApiPage = require('./makeOpenApiPage.cjs');
10
+
11
+
12
+
13
+ exports.openApiGeneratorPlugin = plugin.openApiGeneratorPlugin;
14
+ exports.routeToOpenApi = routeToOpenApi.routeToOpenApi;
15
+ exports.aggregateStepContract = aggregateStepContract.aggregateStepContract;
16
+ exports.makeOpenApiRoute = makeOpenApiRoute.makeOpenApiRoute;
17
+ exports.makeOpenApiPage = makeOpenApiPage.makeOpenApiPage;
@@ -0,0 +1,7 @@
1
+ import "@duplojs/data-parser-tools/toJsonSchema";
2
+ export * from "./types";
3
+ export * from "./plugin";
4
+ export * from "./routeToOpenApi";
5
+ export * from "./aggregateStepContract";
6
+ export * from "./makeOpenApiRoute";
7
+ export * from "./makeOpenApiPage";
@@ -0,0 +1,7 @@
1
+ import '@duplojs/data-parser-tools/toJsonSchema';
2
+ import './types/index.mjs';
3
+ export { openApiGeneratorPlugin } from './plugin.mjs';
4
+ export { routeToOpenApi } from './routeToOpenApi.mjs';
5
+ export { aggregateStepContract } from './aggregateStepContract.mjs';
6
+ export { makeOpenApiRoute } from './makeOpenApiRoute.mjs';
7
+ export { makeOpenApiPage } from './makeOpenApiPage.mjs';
@@ -0,0 +1,30 @@
1
+ 'use strict';
2
+
3
+ function makeOpenApiPage(params) {
4
+ return /* html */ `
5
+ <!DOCTYPE html>
6
+ <html lang="en">
7
+ <head>
8
+ <meta charset="utf-8" />
9
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
10
+ <meta name="description" content="SwaggerUI"/>
11
+ <title>${params.pageTitle}</title>
12
+ <link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist@${params.swaggerUiVersion}/swagger-ui.css" />
13
+ <script src="https://unpkg.com/swagger-ui-dist@${params.swaggerUiVersion}/swagger-ui-bundle.js" crossorigin></script>
14
+ </head>
15
+ <body>
16
+ <div id="swagger-ui"></div>
17
+ <script>
18
+ window.onload = () => {
19
+ window.ui = SwaggerUIBundle({
20
+ spec: ${params.openApiDocument},
21
+ dom_id: "#swagger-ui",
22
+ });
23
+ };
24
+ </script>
25
+ </body>
26
+ </html>
27
+ `;
28
+ }
29
+
30
+ exports.makeOpenApiPage = makeOpenApiPage;
@@ -0,0 +1,7 @@
1
+ interface MakeOpenApiPageParams {
2
+ pageTitle: string;
3
+ openApiDocument: string;
4
+ swaggerUiVersion: string;
5
+ }
6
+ export declare function makeOpenApiPage(params: MakeOpenApiPageParams): string;
7
+ export {};
@@ -0,0 +1,28 @@
1
+ function makeOpenApiPage(params) {
2
+ return /* html */ `
3
+ <!DOCTYPE html>
4
+ <html lang="en">
5
+ <head>
6
+ <meta charset="utf-8" />
7
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
8
+ <meta name="description" content="SwaggerUI"/>
9
+ <title>${params.pageTitle}</title>
10
+ <link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist@${params.swaggerUiVersion}/swagger-ui.css" />
11
+ <script src="https://unpkg.com/swagger-ui-dist@${params.swaggerUiVersion}/swagger-ui-bundle.js" crossorigin></script>
12
+ </head>
13
+ <body>
14
+ <div id="swagger-ui"></div>
15
+ <script>
16
+ window.onload = () => {
17
+ window.ui = SwaggerUIBundle({
18
+ spec: ${params.openApiDocument},
19
+ dom_id: "#swagger-ui",
20
+ });
21
+ };
22
+ </script>
23
+ </body>
24
+ </html>
25
+ `;
26
+ }
27
+
28
+ export { makeOpenApiPage };
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ require('../../core/builders/index.cjs');
4
+ require('../../core/response/index.cjs');
5
+ var utils = require('@duplojs/utils');
6
+ var builder = require('../../core/builders/route/builder.cjs');
7
+ var contract = require('../../core/response/contract.cjs');
8
+
9
+ function makeOpenApiRoute(routePath, openApiPage) {
10
+ return builder.useRouteBuilder("GET", routePath)
11
+ .handler(contract.ResponseContract.ok("swaggerUi", utils.DP.string()), (__, { response }) => response("swaggerUi", openApiPage)
12
+ .setHeader("content-type", "text/html"));
13
+ }
14
+
15
+ exports.makeOpenApiRoute = makeOpenApiRoute;
@@ -0,0 +1,18 @@
1
+ import { ResponseContract } from "../../core/response";
2
+ import type { RoutePath } from "../../core/route";
3
+ import { DP } from "@duplojs/utils";
4
+ export declare function makeOpenApiRoute(routePath: RoutePath, openApiPage: string): import("../../core/route").Route<{
5
+ readonly method: "GET";
6
+ readonly hooks: readonly [];
7
+ readonly preflightSteps: readonly [];
8
+ readonly paths: readonly [`/${string}`];
9
+ readonly steps: readonly [import("../../core/steps").HandlerStep<{
10
+ readonly responseContract: NoInfer<ResponseContract.Contract<"200", "swaggerUi", DP.DataParserString<{
11
+ readonly errorMessage?: string | undefined;
12
+ readonly identifier?: string | undefined;
13
+ readonly coerce: boolean;
14
+ readonly checkers: readonly [];
15
+ }>>>;
16
+ theFunction(floor: {}, param: import("../../core/steps").HandlerStepFunctionParams<import("../../core/request").Request, import("../../core/response").PredictedResponse<"200", "swaggerUi", string>>): import("@duplojs/utils").MaybePromise<import("../../core/response").PredictedResponse<"200", "swaggerUi", string>>;
17
+ }>];
18
+ }>;
@@ -0,0 +1,13 @@
1
+ import '../../core/builders/index.mjs';
2
+ import '../../core/response/index.mjs';
3
+ import { DP } from '@duplojs/utils';
4
+ import { useRouteBuilder } from '../../core/builders/route/builder.mjs';
5
+ import { ResponseContract } from '../../core/response/contract.mjs';
6
+
7
+ function makeOpenApiRoute(routePath, openApiPage) {
8
+ return useRouteBuilder("GET", routePath)
9
+ .handler(ResponseContract.ok("swaggerUi", DP.string()), (__, { response }) => response("swaggerUi", openApiPage)
10
+ .setHeader("content-type", "text/html"));
11
+ }
12
+
13
+ export { makeOpenApiRoute };
@@ -0,0 +1,90 @@
1
+ 'use strict';
2
+
3
+ var routeToOpenApi = require('./routeToOpenApi.cjs');
4
+ var utils = require('@duplojs/utils');
5
+ var makeOpenApiPage = require('./makeOpenApiPage.cjs');
6
+ var makeOpenApiRoute = require('./makeOpenApiRoute.cjs');
7
+ var promises = require('fs/promises');
8
+
9
+ function openApiGeneratorPlugin(pluginParams) {
10
+ return () => ({
11
+ name: "open-api-generator",
12
+ hooksHubLifeCycle: [
13
+ {
14
+ beforeServerBuildRoutes: async (hub) => {
15
+ const contextToJsonSchemaFactory = new Map();
16
+ const resultSchemaContext = new Map();
17
+ const routes = hub.aggregatesRoutes();
18
+ const openApiRoutes = utils.pipe(routes, utils.A.filter((route) => route.definition.method !== "OPTIONS"), utils.A.flatMap((route) => routeToOpenApi.routeToOpenApi(route, {
19
+ defaultExtractContract: hub.defaultExtractContract,
20
+ resultSchemaContext,
21
+ contextToJsonSchemaFactory,
22
+ })));
23
+ if (!utils.A.minElements(openApiRoutes, 1)) {
24
+ return;
25
+ }
26
+ const paths = utils.pipe(openApiRoutes, utils.A.group((element, { output }) => output(element.path, element)), utils.O.entries, utils.A.filter((entry) => entry[1] !== undefined), utils.A.map(([path, value]) => utils.pipe(value, utils.A.group(({ method, path, ...rest }, { output }) => output(method, rest)), utils.O.entries, utils.A.filter((entry) => entry[1] !== undefined), utils.A.map(([method, value]) => utils.O.entry(method, utils.A.first(value))), utils.O.fromEntries, (value) => utils.O.entry(path, value))), utils.O.fromEntries);
27
+ const schemaComponents = utils.G.reduce(resultSchemaContext.values(), utils.G.reduceFrom({}), ({ lastValue, element, nextWithObject }) => nextWithObject(lastValue, element));
28
+ const securityScheme = utils.P.match(pluginParams.security)
29
+ .with({ type: "bearer" }, (security) => ({
30
+ type: "http",
31
+ scheme: "bearer",
32
+ bearerFormat: security.bearerFormat ?? "JWT",
33
+ }))
34
+ .with({ type: "basic" }, utils.justReturn({
35
+ type: "http",
36
+ scheme: "basic",
37
+ }))
38
+ .with({ type: "apiKey" }, (security) => ({
39
+ type: "apiKey",
40
+ name: security.paramName,
41
+ in: security.in,
42
+ }))
43
+ .otherwise(utils.justReturn(undefined));
44
+ const securitySchemeName = "auth";
45
+ const securitySchemes = securityScheme
46
+ ? {
47
+ [securitySchemeName]: securityScheme,
48
+ }
49
+ : undefined;
50
+ const openApiDocument = {
51
+ openapi: "3.1.0",
52
+ info: {
53
+ title: pluginParams.title ?? "Swagger API",
54
+ version: pluginParams.version ?? "0.0.0",
55
+ summary: pluginParams.summary,
56
+ contact: pluginParams.contact,
57
+ license: pluginParams.license,
58
+ },
59
+ servers: pluginParams.servers,
60
+ paths,
61
+ components: {
62
+ schemas: schemaComponents,
63
+ securitySchemes,
64
+ },
65
+ security: pluginParams.security
66
+ ? [
67
+ {
68
+ [securitySchemeName]: [],
69
+ },
70
+ ]
71
+ : undefined,
72
+ };
73
+ const openApiDocumentString = JSON.stringify(openApiDocument, null, 2);
74
+ if (pluginParams.outputFilePath) {
75
+ await promises.writeFile(pluginParams.outputFilePath, openApiDocumentString);
76
+ }
77
+ const openApiPage = makeOpenApiPage.makeOpenApiPage({
78
+ openApiDocument: openApiDocumentString,
79
+ pageTitle: pluginParams.title ?? "Swagger API",
80
+ swaggerUiVersion: pluginParams.swaggerUiVersion ?? "5.31.0",
81
+ });
82
+ const openApiRoute = makeOpenApiRoute.makeOpenApiRoute(pluginParams.routePath, openApiPage);
83
+ return hub.register(openApiRoute);
84
+ },
85
+ },
86
+ ],
87
+ });
88
+ }
89
+
90
+ exports.openApiGeneratorPlugin = openApiGeneratorPlugin;
@@ -0,0 +1,49 @@
1
+ import type { HubPlugin } from "../../core/hub";
2
+ import type { RoutePath } from "../../core/route";
3
+ import type { SupportedBearerFormat } from "./types";
4
+ interface OpenApiSecurityOptionBearer {
5
+ type: "bearer";
6
+ bearerFormat?: SupportedBearerFormat;
7
+ }
8
+ interface OpenApiSecurityOptionApiKey {
9
+ type: "apiKey";
10
+ paramName: string;
11
+ in: "header" | "query" | "cookie";
12
+ }
13
+ interface OpenApiSecurityOptionBasic {
14
+ type: "basic";
15
+ }
16
+ export interface OpenApiGeneratorPluginParams {
17
+ routePath: RoutePath;
18
+ outputFilePath?: string;
19
+ /**
20
+ * @default "Swagger API"
21
+ */
22
+ title?: string;
23
+ /**
24
+ * @default "0.0.0"
25
+ */
26
+ version?: string;
27
+ summary?: string;
28
+ contact?: {
29
+ name?: string;
30
+ email?: string;
31
+ url?: string;
32
+ };
33
+ license?: {
34
+ name: string;
35
+ url?: string;
36
+ identifier?: string;
37
+ };
38
+ security?: OpenApiSecurityOptionBearer | OpenApiSecurityOptionApiKey | OpenApiSecurityOptionBasic;
39
+ servers?: {
40
+ url: string;
41
+ description?: string;
42
+ }[];
43
+ /**
44
+ * @default "5.31.0"
45
+ */
46
+ swaggerUiVersion?: string;
47
+ }
48
+ export declare function openApiGeneratorPlugin(pluginParams: OpenApiGeneratorPluginParams): () => HubPlugin;
49
+ export {};