@duplojs/http 0.6.1 → 0.7.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 (187) hide show
  1. package/dist/client/getBody.cjs +1 -1
  2. package/dist/client/getBody.mjs +1 -1
  3. package/dist/client/hooks.d.ts +1 -25
  4. package/dist/client/httpClient.d.ts +29 -25
  5. package/dist/client/promiseRequest.cjs +3 -0
  6. package/dist/client/promiseRequest.d.ts +31 -39
  7. package/dist/client/promiseRequest.mjs +4 -1
  8. package/dist/client/types/clientResponse.d.ts +6 -6
  9. package/dist/client/types/hooks.d.ts +25 -0
  10. package/dist/client/types/index.cjs +2 -0
  11. package/dist/client/types/index.d.ts +2 -0
  12. package/dist/client/types/index.mjs +2 -0
  13. package/dist/client/types/promiseRequestParams.cjs +2 -0
  14. package/dist/client/types/promiseRequestParams.d.ts +9 -0
  15. package/dist/client/types/promiseRequestParams.mjs +1 -0
  16. package/dist/client/types/serverRoute.d.ts +19 -1
  17. package/dist/client/unexpectedResponseError.d.ts +1 -2
  18. package/dist/core/builders/preflight/route.cjs +1 -0
  19. package/dist/core/builders/preflight/route.d.ts +4 -2
  20. package/dist/core/builders/preflight/route.mjs +1 -0
  21. package/dist/core/builders/route/builder.cjs +1 -0
  22. package/dist/core/builders/route/builder.d.ts +4 -2
  23. package/dist/core/builders/route/builder.mjs +1 -0
  24. package/dist/core/clean/constraint.cjs +24 -0
  25. package/dist/core/clean/constraint.d.ts +8 -0
  26. package/dist/core/clean/constraint.mjs +22 -0
  27. package/dist/core/clean/constraintsSet.cjs +27 -0
  28. package/dist/core/clean/constraintsSet.d.ts +8 -0
  29. package/dist/core/clean/constraintsSet.mjs +25 -0
  30. package/dist/core/clean/entity.cjs +33 -0
  31. package/dist/core/clean/entity.d.ts +20 -0
  32. package/dist/core/clean/entity.mjs +31 -0
  33. package/dist/core/clean/index.cjs +8 -0
  34. package/dist/core/clean/index.d.ts +5 -0
  35. package/dist/core/clean/index.mjs +5 -0
  36. package/dist/core/clean/newType.cjs +15 -0
  37. package/dist/core/clean/newType.d.ts +8 -0
  38. package/dist/core/clean/newType.mjs +13 -0
  39. package/dist/core/clean/primitive.cjs +12 -0
  40. package/dist/core/clean/primitive.d.ts +8 -0
  41. package/dist/core/clean/primitive.mjs +10 -0
  42. package/dist/core/defaultHooks/index.cjs +50 -0
  43. package/dist/core/defaultHooks/index.d.ts +5 -0
  44. package/dist/core/defaultHooks/index.mjs +48 -0
  45. package/dist/{interfaces/node/error → core/errors}/bodyParseWrongChunkReceived.cjs +6 -4
  46. package/dist/core/errors/bodyParseWrongChunkReceived.d.ts +9 -0
  47. package/dist/core/errors/bodyParseWrongChunkReceived.mjs +14 -0
  48. package/dist/{interfaces/node/error → core/errors}/bodySizeExceedsLimitError.cjs +2 -2
  49. package/dist/{interfaces/node/error → core/errors}/bodySizeExceedsLimitError.d.ts +2 -2
  50. package/dist/{interfaces/node/error → core/errors}/bodySizeExceedsLimitError.mjs +2 -2
  51. package/dist/{interfaces/node/error → core/errors}/index.cjs +6 -4
  52. package/dist/{interfaces/node/error → core/errors}/index.d.ts +3 -2
  53. package/dist/{interfaces/node/error → core/errors}/index.mjs +3 -2
  54. package/dist/core/errors/parseJsonError.cjs +16 -0
  55. package/dist/core/errors/parseJsonError.d.ts +9 -0
  56. package/dist/core/errors/parseJsonError.mjs +14 -0
  57. package/dist/core/errors/wrongContentTypeError.cjs +16 -0
  58. package/dist/core/errors/wrongContentTypeError.d.ts +9 -0
  59. package/dist/core/errors/wrongContentTypeError.mjs +14 -0
  60. package/dist/core/functionsBuilders/route/create.d.ts +2 -2
  61. package/dist/core/functionsBuilders/route/default.cjs +0 -11
  62. package/dist/core/functionsBuilders/route/default.mjs +0 -11
  63. package/dist/core/functionsBuilders/route/hook.d.ts +2 -2
  64. package/dist/core/functionsBuilders/steps/create.d.ts +2 -2
  65. package/dist/core/functionsBuilders/steps/defaults/cutStep.cjs +15 -18
  66. package/dist/core/functionsBuilders/steps/defaults/cutStep.mjs +15 -18
  67. package/dist/core/functionsBuilders/steps/defaults/extractStep.cjs +43 -19
  68. package/dist/core/functionsBuilders/steps/defaults/extractStep.d.ts +2 -1
  69. package/dist/core/functionsBuilders/steps/defaults/extractStep.mjs +44 -20
  70. package/dist/core/functionsBuilders/steps/defaults/handlerStep.cjs +14 -8
  71. package/dist/core/functionsBuilders/steps/defaults/handlerStep.mjs +14 -8
  72. package/dist/core/hub/defaultBodyController.cjs +8 -0
  73. package/dist/core/hub/defaultBodyController.d.ts +1 -0
  74. package/dist/core/hub/defaultBodyController.mjs +6 -0
  75. package/dist/core/hub/hooks.cjs +3 -1
  76. package/dist/core/hub/hooks.d.ts +2 -3
  77. package/dist/core/hub/hooks.mjs +3 -1
  78. package/dist/core/hub/index.cjs +101 -127
  79. package/dist/core/hub/index.d.ts +33 -34
  80. package/dist/core/hub/index.mjs +100 -128
  81. package/dist/core/implementHttpServer.cjs +5 -5
  82. package/dist/core/implementHttpServer.d.ts +2 -1
  83. package/dist/core/implementHttpServer.mjs +5 -5
  84. package/dist/core/index.cjs +35 -10
  85. package/dist/core/index.d.ts +3 -0
  86. package/dist/core/index.mjs +14 -2
  87. package/dist/core/request/bodyController/base.cjs +36 -0
  88. package/dist/core/request/bodyController/base.d.ts +28 -0
  89. package/dist/core/request/bodyController/base.mjs +34 -0
  90. package/dist/core/request/bodyController/formData.cjs +28 -0
  91. package/dist/core/request/bodyController/formData.d.ts +22 -0
  92. package/dist/core/request/bodyController/formData.mjs +25 -0
  93. package/dist/core/request/bodyController/index.cjs +13 -0
  94. package/dist/core/request/bodyController/index.d.ts +3 -0
  95. package/dist/core/request/bodyController/index.mjs +3 -0
  96. package/dist/core/request/bodyController/text.cjs +14 -0
  97. package/dist/core/request/bodyController/text.d.ts +10 -0
  98. package/dist/core/request/bodyController/text.mjs +11 -0
  99. package/dist/core/{request.cjs → request/index.cjs} +21 -3
  100. package/dist/core/{request.d.ts → request/index.d.ts} +10 -3
  101. package/dist/core/request/index.mjs +50 -0
  102. package/dist/core/response/contract.d.ts +1 -1
  103. package/dist/core/route/hooks.d.ts +0 -2
  104. package/dist/core/route/index.d.ts +2 -1
  105. package/dist/core/router/index.cjs +27 -8
  106. package/dist/core/router/index.d.ts +2 -1
  107. package/dist/core/router/index.mjs +28 -10
  108. package/dist/core/router/notFoundBodyReaderImplementationError.cjs +16 -0
  109. package/dist/core/router/notFoundBodyReaderImplementationError.d.ts +11 -0
  110. package/dist/core/router/notFoundBodyReaderImplementationError.mjs +14 -0
  111. package/dist/core/router/types/buildedRouter.d.ts +3 -3
  112. package/dist/core/steps/extract.d.ts +3 -1
  113. package/dist/core/steps/types/steps.d.ts +1 -3
  114. package/dist/core/types/hosts.cjs +2 -0
  115. package/dist/core/types/hosts.d.ts +4 -0
  116. package/dist/core/types/hosts.mjs +1 -0
  117. package/dist/core/types/httpServerParams.cjs +2 -0
  118. package/dist/core/types/httpServerParams.d.ts +11 -0
  119. package/dist/core/types/httpServerParams.mjs +1 -0
  120. package/dist/core/types/index.cjs +2 -0
  121. package/dist/core/types/index.d.ts +2 -0
  122. package/dist/core/types/index.mjs +2 -0
  123. package/dist/interfaces/bun/types/request.cjs +1 -1
  124. package/dist/interfaces/bun/types/request.mjs +1 -1
  125. package/dist/interfaces/node/bodyReaders/formData/error.cjs +14 -0
  126. package/dist/interfaces/node/bodyReaders/formData/error.d.ts +8 -0
  127. package/dist/interfaces/node/bodyReaders/formData/error.mjs +12 -0
  128. package/dist/interfaces/node/bodyReaders/formData/index.cjs +94 -0
  129. package/dist/interfaces/node/bodyReaders/formData/index.d.ts +4 -0
  130. package/dist/interfaces/node/bodyReaders/formData/index.mjs +90 -0
  131. package/dist/interfaces/node/bodyReaders/formData/readRequestFormData.cjs +175 -0
  132. package/dist/interfaces/node/bodyReaders/formData/readRequestFormData.d.ts +21 -0
  133. package/dist/interfaces/node/bodyReaders/formData/readRequestFormData.mjs +173 -0
  134. package/dist/interfaces/node/bodyReaders/index.cjs +9 -0
  135. package/dist/interfaces/node/bodyReaders/index.d.ts +2 -0
  136. package/dist/interfaces/node/bodyReaders/index.mjs +2 -0
  137. package/dist/interfaces/node/bodyReaders/text/index.cjs +41 -0
  138. package/dist/interfaces/node/bodyReaders/text/index.d.ts +3 -0
  139. package/dist/interfaces/node/bodyReaders/text/index.mjs +38 -0
  140. package/dist/interfaces/node/bodyReaders/text/readRequestText.cjs +37 -0
  141. package/dist/interfaces/node/bodyReaders/text/readRequestText.d.ts +6 -0
  142. package/dist/interfaces/node/bodyReaders/text/readRequestText.mjs +35 -0
  143. package/dist/interfaces/node/createHttpServer.cjs +13 -5
  144. package/dist/interfaces/node/createHttpServer.d.ts +13 -12
  145. package/dist/interfaces/node/createHttpServer.mjs +13 -5
  146. package/dist/interfaces/node/hooks/index.cjs +47 -0
  147. package/dist/interfaces/node/hooks/index.d.ts +5 -0
  148. package/dist/interfaces/node/hooks/index.mjs +45 -0
  149. package/dist/interfaces/node/index.cjs +13 -9
  150. package/dist/interfaces/node/index.d.ts +1 -1
  151. package/dist/interfaces/node/index.mjs +7 -5
  152. package/dist/interfaces/node/types/index.cjs +0 -1
  153. package/dist/interfaces/node/types/index.d.ts +0 -1
  154. package/dist/interfaces/node/types/index.mjs +0 -1
  155. package/dist/interfaces/node/types/request.cjs +1 -1
  156. package/dist/interfaces/node/types/request.mjs +1 -1
  157. package/dist/plugins/codeGenerator/index.cjs +2 -0
  158. package/dist/plugins/codeGenerator/index.mjs +1 -1
  159. package/dist/plugins/codeGenerator/plugin.cjs +8 -4
  160. package/dist/plugins/codeGenerator/plugin.mjs +9 -5
  161. package/dist/plugins/codeGenerator/routeToDataParser.cjs +24 -1
  162. package/dist/plugins/codeGenerator/routeToDataParser.d.ts +34 -0
  163. package/dist/plugins/codeGenerator/routeToDataParser.mjs +24 -3
  164. package/dist/plugins/codeGenerator/typescriptTransfomer.cjs +9 -0
  165. package/dist/plugins/codeGenerator/typescriptTransfomer.d.ts +1 -0
  166. package/dist/plugins/codeGenerator/typescriptTransfomer.mjs +7 -0
  167. package/dist/plugins/openApiGenerator/makeOpenApiRoute.d.ts +3 -0
  168. package/dist/plugins/openApiGenerator/plugin.cjs +3 -3
  169. package/dist/plugins/openApiGenerator/plugin.mjs +4 -4
  170. package/dist/plugins/openApiGenerator/routeToOpenApi.cjs +16 -1
  171. package/dist/plugins/openApiGenerator/routeToOpenApi.d.ts +10 -1
  172. package/dist/plugins/openApiGenerator/routeToOpenApi.mjs +16 -1
  173. package/dist/plugins/openApiGenerator/types/entrypoint.d.ts +6 -1
  174. package/dist/plugins/openApiGenerator/types/openApiMethod.d.ts +1 -1
  175. package/package.json +5 -6
  176. package/dist/core/request.mjs +0 -32
  177. package/dist/interfaces/node/error/bodyParseUnknownError.cjs +0 -16
  178. package/dist/interfaces/node/error/bodyParseUnknownError.d.ts +0 -9
  179. package/dist/interfaces/node/error/bodyParseUnknownError.mjs +0 -14
  180. package/dist/interfaces/node/error/bodyParseWrongChunkReceived.d.ts +0 -8
  181. package/dist/interfaces/node/error/bodyParseWrongChunkReceived.mjs +0 -12
  182. package/dist/interfaces/node/hooks.cjs +0 -126
  183. package/dist/interfaces/node/hooks.d.ts +0 -8
  184. package/dist/interfaces/node/hooks.mjs +0 -124
  185. package/dist/interfaces/node/types/host.d.ts +0 -4
  186. /package/dist/{interfaces/node/types/host.cjs → client/types/hooks.cjs} +0 -0
  187. /package/dist/{interfaces/node/types/host.mjs → client/types/hooks.mjs} +0 -0
@@ -1,8 +1,8 @@
1
1
  import { HookResponse } from "../../response";
2
- import { type HookAfterSendResponse, type HookBeforeRouteExecution, type HookBeforeSendResponse, type HookError, type HookParseBody, type HookRouteLifeCycle, type HookSendResponse, type RouteHookErrorParams, type RouteHookParams, type RouteHookParamsAfter } from "../../route";
2
+ import { type HookAfterSendResponse, type HookBeforeRouteExecution, type HookBeforeSendResponse, type HookError, type HookRouteLifeCycle, type HookSendResponse, type RouteHookErrorParams, type RouteHookParams, type RouteHookParamsAfter } from "../../route";
3
3
  export declare function exitHookFunction(): import("@duplojs/utils").Kind<import("@duplojs/utils").KindDefinition<"@DuplojsHttpCore/route-hook-exit", unknown>, unknown>;
4
4
  export declare function nextHookFunction(): import("@duplojs/utils").Kind<import("@duplojs/utils").KindDefinition<"@DuplojsHttpCore/route-hook-next", unknown>, unknown>;
5
- export declare function buildHookBefore(hooks: (HookBeforeRouteExecution | HookParseBody)[]): typeof exitHookFunction | ((params: RouteHookParams) => Promise<import("../../route").RouteHookExit | import("@duplojs/utils").Kind<import("@duplojs/utils").KindDefinition<"@DuplojsHttpCore/route-hook-next", unknown>, unknown> | HookResponse<import("../../response").ResponseCode, string, unknown>>);
5
+ export declare function buildHookBefore(hooks: (HookBeforeRouteExecution)[]): typeof exitHookFunction | ((params: RouteHookParams) => Promise<import("../../route").RouteHookExit | import("@duplojs/utils").Kind<import("@duplojs/utils").KindDefinition<"@DuplojsHttpCore/route-hook-next", unknown>, unknown> | HookResponse<import("../../response").ResponseCode, string, unknown>>);
6
6
  export declare function buildHookErrorBefore(hooks: HookError[]): typeof exitHookFunction | ((params: RouteHookErrorParams) => Promise<import("../../route").RouteHookExit | import("@duplojs/utils").Kind<import("@duplojs/utils").KindDefinition<"@DuplojsHttpCore/route-hook-next", unknown>, unknown> | HookResponse<import("../../response").ResponseCode, string, unknown>>);
7
7
  export declare function buildHookAfter(hooks: (HookBeforeSendResponse | HookSendResponse | HookAfterSendResponse)[]): typeof exitHookFunction | ((params: RouteHookParamsAfter) => Promise<import("../../route").RouteHookExit | import("@duplojs/utils").Kind<import("@duplojs/utils").KindDefinition<"@DuplojsHttpCore/route-hook-next", unknown>, unknown>>);
8
8
  export declare function createHookResponse(from: keyof HookRouteLifeCycle): RouteHookParams["response"];
@@ -10,8 +10,8 @@ export interface BuildStepResult {
10
10
  readonly buildedFunction: BuildedStepFunction;
11
11
  readonly hooksRouteLifeCycle: readonly HookRouteLifeCycle[];
12
12
  }
13
- export type BuildStepSuccessEither = E.EitherRight<"buildSuccess", BuildStepResult>;
14
- export type BuildStepNotSupportEither = E.EitherLeft<"stepNotSupport", Steps>;
13
+ export type BuildStepSuccessEither = E.Right<"buildSuccess", BuildStepResult>;
14
+ export type BuildStepNotSupportEither = E.Left<"stepNotSupport", Steps>;
15
15
  export interface StepFunctionBuilderParams {
16
16
  buildStep(element: Steps): Promise<BuildStepSuccessEither | BuildStepNotSupportEither>;
17
17
  success(result: BuildStepResult): BuildStepSuccessEither;
@@ -19,32 +19,29 @@ const defaultCutStepFunctionBuilder = create.createStepFunctionBuilder(cut.cutSt
19
19
  if (!currentContract) {
20
20
  throw new contract.ResponseContract.Error(information);
21
21
  }
22
- const result = currentContract.body.parse(body);
23
- if (utils.E.isLeft(result)) {
24
- throw new contract.ResponseContract.Error(information, utils.unwrap(result));
25
- }
26
22
  return new predicted.PredictedResponse(currentContract.code, currentContract.information, body);
27
23
  };
28
- function treatResult(result, floor) {
29
- if (cut.cutStepOutputKind.has(result)) {
30
- return {
31
- ...floor,
32
- ...utils.unwrap(result),
33
- };
34
- }
35
- return result;
36
- }
37
24
  return success({
38
- buildedFunction: (request, floor) => {
39
- const result = cutFunction(floor, {
25
+ buildedFunction: async (request, floor) => {
26
+ const cutResult = await cutFunction(floor, {
40
27
  request,
41
28
  output,
42
29
  response,
43
30
  });
44
- if (result instanceof Promise) {
45
- return result.then((awaitedResult) => treatResult(awaitedResult, floor));
31
+ if (cutResult instanceof predicted.PredictedResponse) {
32
+ const currentContract = preparedContractResponse[cutResult.information];
33
+ const resultBody = currentContract.body.isAsynchronous()
34
+ ? await currentContract.body.asyncParse(cutResult.body)
35
+ : currentContract.body.parse(cutResult.body);
36
+ if (utils.E.isLeft(resultBody)) {
37
+ throw new contract.ResponseContract.Error(cutResult.information, utils.unwrap(resultBody));
38
+ }
39
+ return cutResult;
46
40
  }
47
- return treatResult(result, floor);
41
+ return {
42
+ ...floor,
43
+ ...utils.unwrap(cutResult),
44
+ };
48
45
  },
49
46
  hooksRouteLifeCycle: [],
50
47
  });
@@ -17,32 +17,29 @@ const defaultCutStepFunctionBuilder = createStepFunctionBuilder(cutStepKind.has,
17
17
  if (!currentContract) {
18
18
  throw new ResponseContract.Error(information);
19
19
  }
20
- const result = currentContract.body.parse(body);
21
- if (E.isLeft(result)) {
22
- throw new ResponseContract.Error(information, unwrap(result));
23
- }
24
20
  return new PredictedResponse(currentContract.code, currentContract.information, body);
25
21
  };
26
- function treatResult(result, floor) {
27
- if (cutStepOutputKind.has(result)) {
28
- return {
29
- ...floor,
30
- ...unwrap(result),
31
- };
32
- }
33
- return result;
34
- }
35
22
  return success({
36
- buildedFunction: (request, floor) => {
37
- const result = cutFunction(floor, {
23
+ buildedFunction: async (request, floor) => {
24
+ const cutResult = await cutFunction(floor, {
38
25
  request,
39
26
  output,
40
27
  response,
41
28
  });
42
- if (result instanceof Promise) {
43
- return result.then((awaitedResult) => treatResult(awaitedResult, floor));
29
+ if (cutResult instanceof PredictedResponse) {
30
+ const currentContract = preparedContractResponse[cutResult.information];
31
+ const resultBody = currentContract.body.isAsynchronous()
32
+ ? await currentContract.body.asyncParse(cutResult.body)
33
+ : currentContract.body.parse(cutResult.body);
34
+ if (E.isLeft(resultBody)) {
35
+ throw new ResponseContract.Error(cutResult.information, unwrap(resultBody));
36
+ }
37
+ return cutResult;
44
38
  }
45
- return treatResult(result, floor);
39
+ return {
40
+ ...floor,
41
+ ...unwrap(cutResult),
42
+ };
46
43
  },
47
44
  hooksRouteLifeCycle: [],
48
45
  });
@@ -10,32 +10,56 @@ var predicted = require('../../../response/predicted.cjs');
10
10
  const defaultExtractStepFunctionBuilder = create.createStepFunctionBuilder(extract.extractStepKind.has, (step, { success, environment, defaultExtractContract }) => {
11
11
  const { shape, responseContract: stepResponseContract, } = step.definition;
12
12
  const responseContract = stepResponseContract ?? defaultExtractContract;
13
- function getResponse(result, key, subKey) {
14
- const response = new predicted.PredictedResponse(responseContract.code, responseContract.information, environment === "DEV"
15
- ? utils.unwrap(result)
16
- : undefined);
17
- return subKey === undefined
18
- ? response.setHeader("extract-key", `request.${key}`)
19
- : response.setHeader("extract-key", `request.${key}.${subKey}`);
20
- }
21
- function treatResult(result, floor, key, subKey) {
22
- if (utils.E.isLeft(result)) {
23
- return getResponse(result, key, subKey);
13
+ function createExtractor(parser, key, subKey) {
14
+ const createResponse = environment === "DEV"
15
+ ? (result) => new predicted.PredictedResponse(responseContract.code, responseContract.information, result)
16
+ : () => new predicted.PredictedResponse(responseContract.code, responseContract.information, undefined);
17
+ const setHeader = subKey === undefined || key === "body"
18
+ ? (response) => response.setHeader("extract-key", `request.${key}`)
19
+ : (response) => response.setHeader("extract-key", `request.${key}.${subKey}`);
20
+ const getResponse = (result) => setHeader(createResponse(result));
21
+ const treatResult = (result, floor) => utils.E.isLeft(result)
22
+ ? getResponse(utils.unwrap(result))
23
+ : {
24
+ ...floor,
25
+ [subKey ?? key]: utils.unwrap(result),
26
+ };
27
+ const getValue = typeof subKey === "string"
28
+ ? (value) => value?.[subKey]
29
+ : utils.forward;
30
+ if (key === "body") {
31
+ const parseFunction = parser.isAsynchronous()
32
+ ? parser.asyncParse
33
+ : parser.parse;
34
+ return async (request, floor) => {
35
+ const bodyResult = await request.getBody();
36
+ if (utils.E.isLeft(bodyResult)) {
37
+ return treatResult(bodyResult, floor);
38
+ }
39
+ const result = await parseFunction(getValue(utils.unwrap(bodyResult)));
40
+ return treatResult(result, floor);
41
+ };
42
+ }
43
+ if (parser.isAsynchronous()) {
44
+ const parseFunction = parser.asyncParse;
45
+ return async (request, floor) => {
46
+ const result = await parseFunction(getValue(request[key]));
47
+ return treatResult(result, floor);
48
+ };
24
49
  }
25
- return {
26
- ...floor,
27
- [subKey ?? key]: utils.unwrap(result),
50
+ const parseFunction = parser.parse;
51
+ return (request, floor) => {
52
+ const result = parseFunction(getValue(request[key]));
53
+ return treatResult(result, floor);
28
54
  };
29
55
  }
30
- const extractors = utils.A.reduce(utils.O.entries(shape), utils.A.reduceFrom([]), ({ lastValue, element: [key, value], next }) => next(utils.DP.dataParserKind.has(value)
31
- ? utils.A.push(lastValue, (request, floor) => treatResult(value.parse(request[key]), floor, key))
32
- : utils.pipe(value, utils.P.when(utils.isType("undefined"), utils.justReturn(lastValue)), utils.P.otherwise(utils.innerPipe(utils.O.entries, utils.A.map(([subKey, subValue]) => ((request, floor) => treatResult(subValue.parse(request[key]?.[subKey]), floor, key, subKey))), (subExtractor) => utils.A.concat(lastValue, subExtractor))))));
56
+ const extractors = utils.A.reduce(utils.O.entries(shape), utils.A.reduceFrom([]), ({ lastValue, element: [key, value], next, }) => utils.pipe(value, utils.P.when(utils.DP.dataParserKind.has, (value) => utils.A.push(lastValue, createExtractor(value, key, undefined))), utils.P.otherwise((value) => utils.pipe(value, utils.P.when(utils.isType("undefined"), utils.justReturn(lastValue)), utils.P.otherwise(utils.innerPipe(utils.O.entries, utils.A.map(([subKey, subValue]) => createExtractor(subValue, key, subKey)), (subExtractor) => utils.A.concat(lastValue, subExtractor))))), next));
33
57
  return success({
34
- buildedFunction: (request, floor) => {
58
+ buildedFunction: async (request, floor) => {
35
59
  let newFloor = floor;
36
60
  // eslint-disable-next-line @typescript-eslint/prefer-for-of
37
61
  for (let index = 0; index < extractors.length; index++) {
38
- const result = extractors[index](request, newFloor);
62
+ const result = await extractors[index](request, newFloor);
39
63
  if (result instanceof predicted.PredictedResponse) {
40
64
  return result;
41
65
  }
@@ -1 +1,2 @@
1
- export declare const defaultExtractStepFunctionBuilder: (step: import("../../../steps").Steps, params: import("..").StepFunctionBuilderParams) => import("@duplojs/utils").MaybePromise<import("..").BuildStepSuccessEither | import("..").BuildStepNotSupportEither>;
1
+ import { type MaybePromise } from "@duplojs/utils";
2
+ export declare const defaultExtractStepFunctionBuilder: (step: import("../../../steps").Steps, params: import("..").StepFunctionBuilderParams) => MaybePromise<import("..").BuildStepSuccessEither | import("..").BuildStepNotSupportEither>;
@@ -1,5 +1,5 @@
1
1
  import '../../../steps/index.mjs';
2
- import { unwrap, E, A, O, DP, pipe, P, isType, justReturn, innerPipe } from '@duplojs/utils';
2
+ import { unwrap, E, forward, A, O, pipe, P, DP, isType, justReturn, innerPipe } from '@duplojs/utils';
3
3
  import '../../../response/index.mjs';
4
4
  import { createStepFunctionBuilder } from '../create.mjs';
5
5
  import { extractStepKind } from '../../../steps/extract.mjs';
@@ -8,32 +8,56 @@ import { PredictedResponse } from '../../../response/predicted.mjs';
8
8
  const defaultExtractStepFunctionBuilder = createStepFunctionBuilder(extractStepKind.has, (step, { success, environment, defaultExtractContract }) => {
9
9
  const { shape, responseContract: stepResponseContract, } = step.definition;
10
10
  const responseContract = stepResponseContract ?? defaultExtractContract;
11
- function getResponse(result, key, subKey) {
12
- const response = new PredictedResponse(responseContract.code, responseContract.information, environment === "DEV"
13
- ? unwrap(result)
14
- : undefined);
15
- return subKey === undefined
16
- ? response.setHeader("extract-key", `request.${key}`)
17
- : response.setHeader("extract-key", `request.${key}.${subKey}`);
18
- }
19
- function treatResult(result, floor, key, subKey) {
20
- if (E.isLeft(result)) {
21
- return getResponse(result, key, subKey);
11
+ function createExtractor(parser, key, subKey) {
12
+ const createResponse = environment === "DEV"
13
+ ? (result) => new PredictedResponse(responseContract.code, responseContract.information, result)
14
+ : () => new PredictedResponse(responseContract.code, responseContract.information, undefined);
15
+ const setHeader = subKey === undefined || key === "body"
16
+ ? (response) => response.setHeader("extract-key", `request.${key}`)
17
+ : (response) => response.setHeader("extract-key", `request.${key}.${subKey}`);
18
+ const getResponse = (result) => setHeader(createResponse(result));
19
+ const treatResult = (result, floor) => E.isLeft(result)
20
+ ? getResponse(unwrap(result))
21
+ : {
22
+ ...floor,
23
+ [subKey ?? key]: unwrap(result),
24
+ };
25
+ const getValue = typeof subKey === "string"
26
+ ? (value) => value?.[subKey]
27
+ : forward;
28
+ if (key === "body") {
29
+ const parseFunction = parser.isAsynchronous()
30
+ ? parser.asyncParse
31
+ : parser.parse;
32
+ return async (request, floor) => {
33
+ const bodyResult = await request.getBody();
34
+ if (E.isLeft(bodyResult)) {
35
+ return treatResult(bodyResult, floor);
36
+ }
37
+ const result = await parseFunction(getValue(unwrap(bodyResult)));
38
+ return treatResult(result, floor);
39
+ };
40
+ }
41
+ if (parser.isAsynchronous()) {
42
+ const parseFunction = parser.asyncParse;
43
+ return async (request, floor) => {
44
+ const result = await parseFunction(getValue(request[key]));
45
+ return treatResult(result, floor);
46
+ };
22
47
  }
23
- return {
24
- ...floor,
25
- [subKey ?? key]: unwrap(result),
48
+ const parseFunction = parser.parse;
49
+ return (request, floor) => {
50
+ const result = parseFunction(getValue(request[key]));
51
+ return treatResult(result, floor);
26
52
  };
27
53
  }
28
- const extractors = A.reduce(O.entries(shape), A.reduceFrom([]), ({ lastValue, element: [key, value], next }) => next(DP.dataParserKind.has(value)
29
- ? A.push(lastValue, (request, floor) => treatResult(value.parse(request[key]), floor, key))
30
- : pipe(value, P.when(isType("undefined"), justReturn(lastValue)), P.otherwise(innerPipe(O.entries, A.map(([subKey, subValue]) => ((request, floor) => treatResult(subValue.parse(request[key]?.[subKey]), floor, key, subKey))), (subExtractor) => A.concat(lastValue, subExtractor))))));
54
+ const extractors = A.reduce(O.entries(shape), A.reduceFrom([]), ({ lastValue, element: [key, value], next, }) => pipe(value, P.when(DP.dataParserKind.has, (value) => A.push(lastValue, createExtractor(value, key, undefined))), P.otherwise((value) => pipe(value, P.when(isType("undefined"), justReturn(lastValue)), P.otherwise(innerPipe(O.entries, A.map(([subKey, subValue]) => createExtractor(subValue, key, subKey)), (subExtractor) => A.concat(lastValue, subExtractor))))), next));
31
55
  return success({
32
- buildedFunction: (request, floor) => {
56
+ buildedFunction: async (request, floor) => {
33
57
  let newFloor = floor;
34
58
  // eslint-disable-next-line @typescript-eslint/prefer-for-of
35
59
  for (let index = 0; index < extractors.length; index++) {
36
- const result = extractors[index](request, newFloor);
60
+ const result = await extractors[index](request, newFloor);
37
61
  if (result instanceof PredictedResponse) {
38
62
  return result;
39
63
  }
@@ -18,17 +18,23 @@ const defaultHandlerStepFunctionBuilder = create.createStepFunctionBuilder(handl
18
18
  if (!currentContract) {
19
19
  throw new contract.ResponseContract.Error(information);
20
20
  }
21
- const result = currentContract.body.parse(body);
22
- if (utils.E.isLeft(result)) {
23
- throw new contract.ResponseContract.Error(information, utils.unwrap(result));
24
- }
25
21
  return new predicted.PredictedResponse(currentContract.code, currentContract.information, body);
26
22
  };
27
23
  return success({
28
- buildedFunction: (request, floor) => handlerFunction(floor, {
29
- request,
30
- response,
31
- }),
24
+ buildedFunction: async (request, floor) => {
25
+ const predictedResponse = await handlerFunction(floor, {
26
+ request,
27
+ response,
28
+ });
29
+ const currentContract = preparedContractResponse[predictedResponse.information];
30
+ const result = currentContract.body.isAsynchronous()
31
+ ? await currentContract.body.asyncParse(predictedResponse.body)
32
+ : currentContract.body.parse(predictedResponse.body);
33
+ if (utils.E.isLeft(result)) {
34
+ throw new contract.ResponseContract.Error(predictedResponse.information, utils.unwrap(result));
35
+ }
36
+ return predictedResponse;
37
+ },
32
38
  hooksRouteLifeCycle: [],
33
39
  });
34
40
  });
@@ -16,17 +16,23 @@ const defaultHandlerStepFunctionBuilder = createStepFunctionBuilder(handlerStepK
16
16
  if (!currentContract) {
17
17
  throw new ResponseContract.Error(information);
18
18
  }
19
- const result = currentContract.body.parse(body);
20
- if (E.isLeft(result)) {
21
- throw new ResponseContract.Error(information, unwrap(result));
22
- }
23
19
  return new PredictedResponse(currentContract.code, currentContract.information, body);
24
20
  };
25
21
  return success({
26
- buildedFunction: (request, floor) => handlerFunction(floor, {
27
- request,
28
- response,
29
- }),
22
+ buildedFunction: async (request, floor) => {
23
+ const predictedResponse = await handlerFunction(floor, {
24
+ request,
25
+ response,
26
+ });
27
+ const currentContract = preparedContractResponse[predictedResponse.information];
28
+ const result = currentContract.body.isAsynchronous()
29
+ ? await currentContract.body.asyncParse(predictedResponse.body)
30
+ : currentContract.body.parse(predictedResponse.body);
31
+ if (E.isLeft(result)) {
32
+ throw new ResponseContract.Error(predictedResponse.information, unwrap(result));
33
+ }
34
+ return predictedResponse;
35
+ },
30
36
  hooksRouteLifeCycle: [],
31
37
  });
32
38
  });
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+
3
+ require('../request/index.cjs');
4
+ var text = require('../request/bodyController/text.cjs');
5
+
6
+ const defaultBodyController = text.controlBodyAsText();
7
+
8
+ exports.defaultBodyController = defaultBodyController;
@@ -0,0 +1 @@
1
+ export declare const defaultBodyController: import("../request").BodyController<"text", import("../request").TextBodyReaderParams>;
@@ -0,0 +1,6 @@
1
+ import '../request/index.mjs';
2
+ import { controlBodyAsText } from '../request/bodyController/text.mjs';
3
+
4
+ const defaultBodyController = controlBodyAsText();
5
+
6
+ export { defaultBodyController };
@@ -9,7 +9,9 @@ async function launchHookBeforeBuildRoute(hooks, route) {
9
9
  return utils.G.asyncReduce(hooks, utils.G.reduceFrom(route), async ({ element: hook, lastValue, next, }) => next(await hook(lastValue)));
10
10
  }
11
11
  async function launchHookServer(hooks, hub, httpServerParams) {
12
- return utils.G.asyncReduce(hooks, utils.G.reduceFrom(hub), async ({ element: hook, lastValue, next, }) => next((await hook(lastValue, httpServerParams)) ?? lastValue));
12
+ for (const hook of hooks) {
13
+ await hook(hub, httpServerParams);
14
+ }
13
15
  }
14
16
  const hookExit = hookServerExitKind.setTo({});
15
17
  const hookNext = hookServerNextKind.setTo({});
@@ -2,6 +2,7 @@ import { type Route } from "../route";
2
2
  import { type EscapeVoid, type Kind, type MaybePromise } from "@duplojs/utils";
3
3
  import { type Hub } from ".";
4
4
  import { type RouterInitializationData } from "../router";
5
+ import { type HttpServerParams } from "../types";
5
6
  export declare const hookServerExitKind: import("@duplojs/utils").KindHandler<import("@duplojs/utils").KindDefinition<"@DuplojsHttpCore/server-hook-exit", unknown>>;
6
7
  export interface ServerHookExit extends Kind<typeof hookServerExitKind.definition> {
7
8
  }
@@ -10,12 +11,10 @@ export interface ServerHookNext extends Kind<typeof hookServerNextKind.definitio
10
11
  }
11
12
  export type HookBeforeBuildRoute = (route: Route) => MaybePromise<Route>;
12
13
  export declare function launchHookBeforeBuildRoute(hooks: Iterable<HookBeforeBuildRoute>, route: Route): Promise<Route<import("../route").RouteDefinition>>;
13
- export interface HttpServerParams {
14
- }
15
14
  export type HookBeforeServerBuildRoutes = (hub: Hub, httpServerParams: HttpServerParams) => MaybePromise<Hub | EscapeVoid>;
16
15
  export type HookBeforeStartServer = (hub: Hub, httpServerParams: HttpServerParams) => MaybePromise<Hub | EscapeVoid>;
17
16
  export type HookAfterStartServer = (hub: Hub, httpServerParams: HttpServerParams) => MaybePromise<Hub | EscapeVoid>;
18
- export declare function launchHookServer(hooks: Iterable<HookBeforeStartServer | HookAfterStartServer | HookBeforeServerBuildRoutes>, hub: Hub, httpServerParams: HttpServerParams): Promise<Hub<import(".").HubConfig>>;
17
+ export declare function launchHookServer(hooks: Iterable<HookBeforeStartServer | HookAfterStartServer | HookBeforeServerBuildRoutes>, hub: Hub, httpServerParams: HttpServerParams): Promise<void>;
19
18
  export interface HttpServerErrorParams {
20
19
  readonly error: unknown;
21
20
  next(): ServerHookNext;
@@ -7,7 +7,9 @@ async function launchHookBeforeBuildRoute(hooks, route) {
7
7
  return G.asyncReduce(hooks, G.reduceFrom(route), async ({ element: hook, lastValue, next, }) => next(await hook(lastValue)));
8
8
  }
9
9
  async function launchHookServer(hooks, hub, httpServerParams) {
10
- return G.asyncReduce(hooks, G.reduceFrom(hub), async ({ element: hook, lastValue, next, }) => next((await hook(lastValue, httpServerParams)) ?? lastValue));
10
+ for (const hook of hooks) {
11
+ await hook(hub, httpServerParams);
12
+ }
11
13
  }
12
14
  const hookExit = hookServerExitKind.setTo({});
13
15
  const hookNext = hookServerNextKind.setTo({});