@duplojs/http 0.6.2 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/getBody.cjs +1 -1
- package/dist/client/getBody.mjs +1 -1
- package/dist/client/hooks.d.ts +1 -25
- package/dist/client/httpClient.d.ts +29 -25
- package/dist/client/promiseRequest.cjs +3 -0
- package/dist/client/promiseRequest.d.ts +31 -39
- package/dist/client/promiseRequest.mjs +4 -1
- package/dist/client/queryToString.cjs +2 -2
- package/dist/client/queryToString.mjs +2 -2
- package/dist/client/types/clientRequestParams.d.ts +9 -3
- package/dist/client/types/clientResponse.d.ts +6 -6
- package/dist/client/types/hooks.d.ts +25 -0
- package/dist/client/types/index.cjs +2 -0
- package/dist/client/types/index.d.ts +2 -0
- package/dist/client/types/index.mjs +2 -0
- package/dist/client/types/promiseRequestParams.cjs +2 -0
- package/dist/client/types/promiseRequestParams.d.ts +9 -0
- package/dist/client/types/promiseRequestParams.mjs +1 -0
- package/dist/client/types/serverRoute.d.ts +28 -4
- package/dist/client/unexpectedResponseError.d.ts +1 -2
- package/dist/core/builders/preflight/route.cjs +1 -0
- package/dist/core/builders/preflight/route.d.ts +4 -2
- package/dist/core/builders/preflight/route.mjs +1 -0
- package/dist/core/builders/route/builder.cjs +1 -0
- package/dist/core/builders/route/builder.d.ts +4 -2
- package/dist/core/builders/route/builder.mjs +1 -0
- package/dist/core/clean/newType.d.ts +1 -1
- package/dist/core/clean/primitive.d.ts +1 -1
- package/dist/core/defaultHooks/index.cjs +50 -0
- package/dist/core/defaultHooks/index.d.ts +5 -0
- package/dist/core/defaultHooks/index.mjs +48 -0
- package/dist/{interfaces/node/error → core/errors}/bodyParseWrongChunkReceived.cjs +6 -4
- package/dist/core/errors/bodyParseWrongChunkReceived.d.ts +9 -0
- package/dist/core/errors/bodyParseWrongChunkReceived.mjs +14 -0
- package/dist/{interfaces/node/error → core/errors}/bodySizeExceedsLimitError.cjs +2 -2
- package/dist/{interfaces/node/error → core/errors}/bodySizeExceedsLimitError.d.ts +2 -2
- package/dist/{interfaces/node/error → core/errors}/bodySizeExceedsLimitError.mjs +2 -2
- package/dist/{interfaces/node/error → core/errors}/index.cjs +6 -4
- package/dist/{interfaces/node/error → core/errors}/index.d.ts +3 -2
- package/dist/{interfaces/node/error → core/errors}/index.mjs +3 -2
- package/dist/core/errors/parseJsonError.cjs +16 -0
- package/dist/core/errors/parseJsonError.d.ts +9 -0
- package/dist/core/errors/parseJsonError.mjs +14 -0
- package/dist/core/errors/wrongContentTypeError.cjs +16 -0
- package/dist/core/errors/wrongContentTypeError.d.ts +9 -0
- package/dist/core/errors/wrongContentTypeError.mjs +14 -0
- package/dist/core/functionsBuilders/route/create.d.ts +2 -2
- package/dist/core/functionsBuilders/route/default.cjs +0 -11
- package/dist/core/functionsBuilders/route/default.mjs +0 -11
- package/dist/core/functionsBuilders/route/hook.d.ts +2 -2
- package/dist/core/functionsBuilders/steps/create.d.ts +2 -2
- package/dist/core/functionsBuilders/steps/defaults/cutStep.cjs +15 -18
- package/dist/core/functionsBuilders/steps/defaults/cutStep.mjs +15 -18
- package/dist/core/functionsBuilders/steps/defaults/extractStep.cjs +43 -19
- package/dist/core/functionsBuilders/steps/defaults/extractStep.d.ts +2 -1
- package/dist/core/functionsBuilders/steps/defaults/extractStep.mjs +44 -20
- package/dist/core/functionsBuilders/steps/defaults/handlerStep.cjs +14 -8
- package/dist/core/functionsBuilders/steps/defaults/handlerStep.mjs +14 -8
- package/dist/core/hub/defaultBodyController.cjs +8 -0
- package/dist/core/hub/defaultBodyController.d.ts +1 -0
- package/dist/core/hub/defaultBodyController.mjs +6 -0
- package/dist/core/hub/hooks.cjs +3 -1
- package/dist/core/hub/hooks.d.ts +2 -3
- package/dist/core/hub/hooks.mjs +3 -1
- package/dist/core/hub/index.cjs +101 -127
- package/dist/core/hub/index.d.ts +33 -34
- package/dist/core/hub/index.mjs +100 -128
- package/dist/core/implementHttpServer.cjs +5 -5
- package/dist/core/implementHttpServer.d.ts +2 -1
- package/dist/core/implementHttpServer.mjs +5 -5
- package/dist/core/index.cjs +34 -10
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.mjs +13 -2
- package/dist/core/request/bodyController/base.cjs +36 -0
- package/dist/core/request/bodyController/base.d.ts +28 -0
- package/dist/core/request/bodyController/base.mjs +34 -0
- package/dist/core/request/bodyController/formData.cjs +28 -0
- package/dist/core/request/bodyController/formData.d.ts +22 -0
- package/dist/core/request/bodyController/formData.mjs +25 -0
- package/dist/core/request/bodyController/index.cjs +13 -0
- package/dist/core/request/bodyController/index.d.ts +3 -0
- package/dist/core/request/bodyController/index.mjs +3 -0
- package/dist/core/request/bodyController/text.cjs +14 -0
- package/dist/core/request/bodyController/text.d.ts +10 -0
- package/dist/core/request/bodyController/text.mjs +11 -0
- package/dist/core/{request.cjs → request/index.cjs} +21 -3
- package/dist/core/{request.d.ts → request/index.d.ts} +10 -3
- package/dist/core/request/index.mjs +50 -0
- package/dist/core/response/contract.d.ts +1 -1
- package/dist/core/route/hooks.d.ts +0 -2
- package/dist/core/route/index.d.ts +2 -1
- package/dist/core/router/index.cjs +27 -8
- package/dist/core/router/index.d.ts +2 -1
- package/dist/core/router/index.mjs +28 -10
- package/dist/core/router/notFoundBodyReaderImplementationError.cjs +16 -0
- package/dist/core/router/notFoundBodyReaderImplementationError.d.ts +11 -0
- package/dist/core/router/notFoundBodyReaderImplementationError.mjs +14 -0
- package/dist/core/router/types/buildedRouter.d.ts +3 -3
- package/dist/core/steps/extract.d.ts +3 -1
- package/dist/core/steps/types/steps.d.ts +1 -3
- package/dist/core/types/hosts.cjs +2 -0
- package/dist/core/types/hosts.d.ts +4 -0
- package/dist/core/types/hosts.mjs +1 -0
- package/dist/core/types/httpServerParams.cjs +2 -0
- package/dist/core/types/httpServerParams.d.ts +11 -0
- package/dist/core/types/httpServerParams.mjs +1 -0
- package/dist/core/types/index.cjs +2 -0
- package/dist/core/types/index.d.ts +2 -0
- package/dist/core/types/index.mjs +2 -0
- package/dist/interfaces/bun/types/request.cjs +1 -1
- package/dist/interfaces/bun/types/request.mjs +1 -1
- package/dist/interfaces/node/bodyReaders/formData/error.cjs +14 -0
- package/dist/interfaces/node/bodyReaders/formData/error.d.ts +8 -0
- package/dist/interfaces/node/bodyReaders/formData/error.mjs +12 -0
- package/dist/interfaces/node/bodyReaders/formData/index.cjs +94 -0
- package/dist/interfaces/node/bodyReaders/formData/index.d.ts +4 -0
- package/dist/interfaces/node/bodyReaders/formData/index.mjs +90 -0
- package/dist/interfaces/node/bodyReaders/formData/readRequestFormData.cjs +175 -0
- package/dist/interfaces/node/bodyReaders/formData/readRequestFormData.d.ts +21 -0
- package/dist/interfaces/node/bodyReaders/formData/readRequestFormData.mjs +173 -0
- package/dist/interfaces/node/bodyReaders/index.cjs +9 -0
- package/dist/interfaces/node/bodyReaders/index.d.ts +2 -0
- package/dist/interfaces/node/bodyReaders/index.mjs +2 -0
- package/dist/interfaces/node/bodyReaders/text/index.cjs +41 -0
- package/dist/interfaces/node/bodyReaders/text/index.d.ts +3 -0
- package/dist/interfaces/node/bodyReaders/text/index.mjs +38 -0
- package/dist/interfaces/node/bodyReaders/text/readRequestText.cjs +37 -0
- package/dist/interfaces/node/bodyReaders/text/readRequestText.d.ts +6 -0
- package/dist/interfaces/node/bodyReaders/text/readRequestText.mjs +35 -0
- package/dist/interfaces/node/createHttpServer.cjs +13 -5
- package/dist/interfaces/node/createHttpServer.d.ts +13 -12
- package/dist/interfaces/node/createHttpServer.mjs +13 -5
- package/dist/interfaces/node/hooks/index.cjs +47 -0
- package/dist/interfaces/node/hooks/index.d.ts +5 -0
- package/dist/interfaces/node/hooks/index.mjs +45 -0
- package/dist/interfaces/node/index.cjs +13 -9
- package/dist/interfaces/node/index.d.ts +1 -1
- package/dist/interfaces/node/index.mjs +7 -5
- package/dist/interfaces/node/types/index.cjs +0 -1
- package/dist/interfaces/node/types/index.d.ts +0 -1
- package/dist/interfaces/node/types/index.mjs +0 -1
- package/dist/interfaces/node/types/request.cjs +1 -1
- package/dist/interfaces/node/types/request.mjs +1 -1
- package/dist/plugins/codeGenerator/index.cjs +2 -0
- package/dist/plugins/codeGenerator/index.mjs +1 -1
- package/dist/plugins/codeGenerator/plugin.cjs +11 -4
- package/dist/plugins/codeGenerator/plugin.mjs +12 -5
- package/dist/plugins/codeGenerator/routeToDataParser.cjs +24 -1
- package/dist/plugins/codeGenerator/routeToDataParser.d.ts +34 -0
- package/dist/plugins/codeGenerator/routeToDataParser.mjs +24 -3
- package/dist/plugins/codeGenerator/typescriptTransfomer.cjs +28 -0
- package/dist/plugins/codeGenerator/typescriptTransfomer.d.ts +4 -0
- package/dist/plugins/codeGenerator/typescriptTransfomer.mjs +24 -0
- package/dist/plugins/openApiGenerator/makeOpenApiRoute.d.ts +3 -0
- package/dist/plugins/openApiGenerator/plugin.cjs +3 -3
- package/dist/plugins/openApiGenerator/plugin.mjs +4 -4
- package/dist/plugins/openApiGenerator/routeToOpenApi.cjs +16 -6
- package/dist/plugins/openApiGenerator/routeToOpenApi.d.ts +10 -1
- package/dist/plugins/openApiGenerator/routeToOpenApi.mjs +16 -6
- package/dist/plugins/openApiGenerator/types/entrypoint.d.ts +6 -1
- package/dist/plugins/openApiGenerator/types/openApiMethod.d.ts +1 -1
- package/package.json +5 -6
- package/dist/core/request.mjs +0 -32
- package/dist/interfaces/node/error/bodyParseUnknownError.cjs +0 -16
- package/dist/interfaces/node/error/bodyParseUnknownError.d.ts +0 -9
- package/dist/interfaces/node/error/bodyParseUnknownError.mjs +0 -14
- package/dist/interfaces/node/error/bodyParseWrongChunkReceived.d.ts +0 -8
- package/dist/interfaces/node/error/bodyParseWrongChunkReceived.mjs +0 -12
- package/dist/interfaces/node/hooks.cjs +0 -126
- package/dist/interfaces/node/hooks.d.ts +0 -8
- package/dist/interfaces/node/hooks.mjs +0 -124
- package/dist/interfaces/node/types/host.d.ts +0 -4
- /package/dist/{interfaces/node/types/host.cjs → client/types/hooks.cjs} +0 -0
- /package/dist/{interfaces/node/types/host.mjs → client/types/hooks.mjs} +0 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
require('../response/index.cjs');
|
|
4
|
+
require('../route/index.cjs');
|
|
5
|
+
var serverUtils = require('@duplojs/server-utils');
|
|
6
|
+
var hooks = require('../route/hooks.cjs');
|
|
7
|
+
var predicted = require('../response/predicted.cjs');
|
|
8
|
+
var hook = require('../response/hook.cjs');
|
|
9
|
+
|
|
10
|
+
function initDefaultHook(hub, serverParams) {
|
|
11
|
+
const informationHeaderKey = serverParams.informationHeaderKey;
|
|
12
|
+
const predictedHeaderKey = serverParams.predictedHeaderKey;
|
|
13
|
+
const fromHookHeaderKey = serverParams.fromHookHeaderKey;
|
|
14
|
+
const isDev = hub.config.environment === "DEV";
|
|
15
|
+
return hooks.createHookRouteLifeCycle({
|
|
16
|
+
beforeSendResponse({ currentResponse, next }) {
|
|
17
|
+
if (!currentResponse.headers?.["content-type"]) {
|
|
18
|
+
const body = currentResponse.body;
|
|
19
|
+
if (typeof body === "string"
|
|
20
|
+
|| body instanceof Error) {
|
|
21
|
+
currentResponse.setHeader("content-type", "text/plain; charset=utf-8");
|
|
22
|
+
}
|
|
23
|
+
else if (serverUtils.SF.isFileInterface(body)) {
|
|
24
|
+
const filename = body.getName();
|
|
25
|
+
const filenameHeader = filename
|
|
26
|
+
? ` filename="${filename}"`
|
|
27
|
+
: "";
|
|
28
|
+
currentResponse
|
|
29
|
+
.setHeader("content-type", body.getMimeType() ?? "application/octet-stream")
|
|
30
|
+
.setHeader("content-disposition", `attachment;${filenameHeader}`);
|
|
31
|
+
}
|
|
32
|
+
else if (typeof body === "object"
|
|
33
|
+
|| typeof body === "number"
|
|
34
|
+
|| typeof body === "boolean") {
|
|
35
|
+
currentResponse.setHeader("content-type", "application/json; charset=utf-8");
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
currentResponse.setHeader(informationHeaderKey, currentResponse.information);
|
|
39
|
+
if (currentResponse instanceof predicted.PredictedResponse) {
|
|
40
|
+
currentResponse.setHeader(predictedHeaderKey, "1");
|
|
41
|
+
}
|
|
42
|
+
else if (currentResponse instanceof hook.HookResponse) {
|
|
43
|
+
currentResponse.setHeader(fromHookHeaderKey, currentResponse.fromHook);
|
|
44
|
+
}
|
|
45
|
+
return next();
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
exports.initDefaultHook = initDefaultHook;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type Hub } from "../hub";
|
|
2
|
+
import { type HttpServerParams } from "../types";
|
|
3
|
+
export declare function initDefaultHook(hub: Hub, serverParams: HttpServerParams): {
|
|
4
|
+
beforeSendResponse({ currentResponse, next }: import("../route").RouteHookParamsAfter<import("..").Request>): import("../route").RouteHookNext;
|
|
5
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import '../response/index.mjs';
|
|
2
|
+
import '../route/index.mjs';
|
|
3
|
+
import { SF } from '@duplojs/server-utils';
|
|
4
|
+
import { createHookRouteLifeCycle } from '../route/hooks.mjs';
|
|
5
|
+
import { PredictedResponse } from '../response/predicted.mjs';
|
|
6
|
+
import { HookResponse } from '../response/hook.mjs';
|
|
7
|
+
|
|
8
|
+
function initDefaultHook(hub, serverParams) {
|
|
9
|
+
const informationHeaderKey = serverParams.informationHeaderKey;
|
|
10
|
+
const predictedHeaderKey = serverParams.predictedHeaderKey;
|
|
11
|
+
const fromHookHeaderKey = serverParams.fromHookHeaderKey;
|
|
12
|
+
const isDev = hub.config.environment === "DEV";
|
|
13
|
+
return createHookRouteLifeCycle({
|
|
14
|
+
beforeSendResponse({ currentResponse, next }) {
|
|
15
|
+
if (!currentResponse.headers?.["content-type"]) {
|
|
16
|
+
const body = currentResponse.body;
|
|
17
|
+
if (typeof body === "string"
|
|
18
|
+
|| body instanceof Error) {
|
|
19
|
+
currentResponse.setHeader("content-type", "text/plain; charset=utf-8");
|
|
20
|
+
}
|
|
21
|
+
else if (SF.isFileInterface(body)) {
|
|
22
|
+
const filename = body.getName();
|
|
23
|
+
const filenameHeader = filename
|
|
24
|
+
? ` filename="${filename}"`
|
|
25
|
+
: "";
|
|
26
|
+
currentResponse
|
|
27
|
+
.setHeader("content-type", body.getMimeType() ?? "application/octet-stream")
|
|
28
|
+
.setHeader("content-disposition", `attachment;${filenameHeader}`);
|
|
29
|
+
}
|
|
30
|
+
else if (typeof body === "object"
|
|
31
|
+
|| typeof body === "number"
|
|
32
|
+
|| typeof body === "boolean") {
|
|
33
|
+
currentResponse.setHeader("content-type", "application/json; charset=utf-8");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
currentResponse.setHeader(informationHeaderKey, currentResponse.information);
|
|
37
|
+
if (currentResponse instanceof PredictedResponse) {
|
|
38
|
+
currentResponse.setHeader(predictedHeaderKey, "1");
|
|
39
|
+
}
|
|
40
|
+
else if (currentResponse instanceof HookResponse) {
|
|
41
|
+
currentResponse.setHeader(fromHookHeaderKey, currentResponse.fromHook);
|
|
42
|
+
}
|
|
43
|
+
return next();
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { initDefaultHook };
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var utils = require('@duplojs/utils');
|
|
4
3
|
var kind = require('../kind.cjs');
|
|
4
|
+
var utils = require('@duplojs/utils');
|
|
5
5
|
|
|
6
|
-
class BodyParseWrongChunkReceived extends utils.kindHeritage("body-parse-wrong-chunk-received", kind.
|
|
6
|
+
class BodyParseWrongChunkReceived extends utils.kindHeritage("body-parse-wrong-chunk-received", kind.createCoreLibKind("body-parse-wrong-chunk-received"), Error) {
|
|
7
|
+
information;
|
|
7
8
|
wrongChunk;
|
|
8
|
-
constructor(wrongChunk) {
|
|
9
|
-
super({}, [
|
|
9
|
+
constructor(information, wrongChunk) {
|
|
10
|
+
super({}, [`Received chunk is not ${information}`]);
|
|
11
|
+
this.information = information;
|
|
10
12
|
this.wrongChunk = wrongChunk;
|
|
11
13
|
}
|
|
12
14
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare const BodyParseWrongChunkReceived_base: new (params: {
|
|
2
|
+
"@DuplojsHttpCore/body-parse-wrong-chunk-received"?: unknown;
|
|
3
|
+
}, parentParams: readonly [message?: string | undefined, options?: ErrorOptions | undefined]) => Error & import("@duplojs/utils").Kind<import("@duplojs/utils").KindDefinition<"@DuplojsHttpCore/body-parse-wrong-chunk-received", unknown>, unknown> & import("@duplojs/utils").Kind<import("@duplojs/utils").KindDefinition<"body-parse-wrong-chunk-received", unknown>, unknown>;
|
|
4
|
+
export declare class BodyParseWrongChunkReceived extends BodyParseWrongChunkReceived_base {
|
|
5
|
+
information: string;
|
|
6
|
+
wrongChunk: unknown;
|
|
7
|
+
constructor(information: string, wrongChunk: unknown);
|
|
8
|
+
}
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createCoreLibKind } from '../kind.mjs';
|
|
2
|
+
import { kindHeritage } from '@duplojs/utils';
|
|
3
|
+
|
|
4
|
+
class BodyParseWrongChunkReceived extends kindHeritage("body-parse-wrong-chunk-received", createCoreLibKind("body-parse-wrong-chunk-received"), Error) {
|
|
5
|
+
information;
|
|
6
|
+
wrongChunk;
|
|
7
|
+
constructor(information, wrongChunk) {
|
|
8
|
+
super({}, [`Received chunk is not ${information}`]);
|
|
9
|
+
this.information = information;
|
|
10
|
+
this.wrongChunk = wrongChunk;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { BodyParseWrongChunkReceived };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var utils = require('@duplojs/utils');
|
|
4
3
|
var kind = require('../kind.cjs');
|
|
4
|
+
var utils = require('@duplojs/utils');
|
|
5
5
|
|
|
6
|
-
class BodySizeExceedsLimitError extends utils.kindHeritage("body-size-exceeds-limit-error", kind.
|
|
6
|
+
class BodySizeExceedsLimitError extends utils.kindHeritage("body-size-exceeds-limit-error", kind.createCoreLibKind("body-size-exceeds-limit-error"), Error) {
|
|
7
7
|
bytesInString;
|
|
8
8
|
constructor(bytesInString) {
|
|
9
9
|
super({}, [`Body size is bigger than ${bytesInString}.`]);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type BytesInString } from "@duplojs/utils";
|
|
2
2
|
declare const BodySizeExceedsLimitError_base: new (params: {
|
|
3
|
-
"@
|
|
4
|
-
}, parentParams: readonly [message?: string | undefined, options?: ErrorOptions | undefined]) => Error & import("@duplojs/utils").Kind<import("@duplojs/utils").KindDefinition<"@
|
|
3
|
+
"@DuplojsHttpCore/body-size-exceeds-limit-error"?: unknown;
|
|
4
|
+
}, parentParams: readonly [message?: string | undefined, options?: ErrorOptions | undefined]) => Error & import("@duplojs/utils").Kind<import("@duplojs/utils").KindDefinition<"@DuplojsHttpCore/body-size-exceeds-limit-error", unknown>, unknown> & import("@duplojs/utils").Kind<import("@duplojs/utils").KindDefinition<"body-size-exceeds-limit-error", unknown>, unknown>;
|
|
5
5
|
export declare class BodySizeExceedsLimitError extends BodySizeExceedsLimitError_base {
|
|
6
6
|
bytesInString: BytesInString | number;
|
|
7
7
|
constructor(bytesInString: BytesInString | number);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { createCoreLibKind } from '../kind.mjs';
|
|
1
2
|
import { kindHeritage } from '@duplojs/utils';
|
|
2
|
-
import { createInterfacesNodeLibKind } from '../kind.mjs';
|
|
3
3
|
|
|
4
|
-
class BodySizeExceedsLimitError extends kindHeritage("body-size-exceeds-limit-error",
|
|
4
|
+
class BodySizeExceedsLimitError extends kindHeritage("body-size-exceeds-limit-error", createCoreLibKind("body-size-exceeds-limit-error"), Error) {
|
|
5
5
|
bytesInString;
|
|
6
6
|
constructor(bytesInString) {
|
|
7
7
|
super({}, [`Body size is bigger than ${bytesInString}.`]);
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var wrongContentTypeError = require('./wrongContentTypeError.cjs');
|
|
4
4
|
var bodyParseWrongChunkReceived = require('./bodyParseWrongChunkReceived.cjs');
|
|
5
|
-
var
|
|
5
|
+
var bodySizeExceedsLimitError = require('./bodySizeExceedsLimitError.cjs');
|
|
6
|
+
var parseJsonError = require('./parseJsonError.cjs');
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
|
|
9
|
-
exports.
|
|
10
|
+
exports.WrongContentTypeError = wrongContentTypeError.WrongContentTypeError;
|
|
10
11
|
exports.BodyParseWrongChunkReceived = bodyParseWrongChunkReceived.BodyParseWrongChunkReceived;
|
|
11
|
-
exports.
|
|
12
|
+
exports.BodySizeExceedsLimitError = bodySizeExceedsLimitError.BodySizeExceedsLimitError;
|
|
13
|
+
exports.ParseJsonError = parseJsonError.ParseJsonError;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { WrongContentTypeError } from './wrongContentTypeError.mjs';
|
|
2
2
|
export { BodyParseWrongChunkReceived } from './bodyParseWrongChunkReceived.mjs';
|
|
3
|
-
export {
|
|
3
|
+
export { BodySizeExceedsLimitError } from './bodySizeExceedsLimitError.mjs';
|
|
4
|
+
export { ParseJsonError } from './parseJsonError.mjs';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var kind = require('../kind.cjs');
|
|
4
|
+
var utils = require('@duplojs/utils');
|
|
5
|
+
|
|
6
|
+
class ParseJsonError extends utils.kindHeritage("parse-json-error", kind.createCoreLibKind("parse-json-error"), Error) {
|
|
7
|
+
payload;
|
|
8
|
+
error;
|
|
9
|
+
constructor(payload, error) {
|
|
10
|
+
super({}, ["Error when parse on json."]);
|
|
11
|
+
this.payload = payload;
|
|
12
|
+
this.error = error;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
exports.ParseJsonError = ParseJsonError;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare const ParseJsonError_base: new (params: {
|
|
2
|
+
"@DuplojsHttpCore/parse-json-error"?: unknown;
|
|
3
|
+
}, parentParams: readonly [message?: string | undefined, options?: ErrorOptions | undefined]) => Error & import("@duplojs/utils").Kind<import("@duplojs/utils").KindDefinition<"@DuplojsHttpCore/parse-json-error", unknown>, unknown> & import("@duplojs/utils").Kind<import("@duplojs/utils").KindDefinition<"parse-json-error", unknown>, unknown>;
|
|
4
|
+
export declare class ParseJsonError extends ParseJsonError_base {
|
|
5
|
+
payload: string;
|
|
6
|
+
error: unknown;
|
|
7
|
+
constructor(payload: string, error: unknown);
|
|
8
|
+
}
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createCoreLibKind } from '../kind.mjs';
|
|
2
|
+
import { kindHeritage } from '@duplojs/utils';
|
|
3
|
+
|
|
4
|
+
class ParseJsonError extends kindHeritage("parse-json-error", createCoreLibKind("parse-json-error"), Error) {
|
|
5
|
+
payload;
|
|
6
|
+
error;
|
|
7
|
+
constructor(payload, error) {
|
|
8
|
+
super({}, ["Error when parse on json."]);
|
|
9
|
+
this.payload = payload;
|
|
10
|
+
this.error = error;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { ParseJsonError };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var kind = require('../kind.cjs');
|
|
4
|
+
var utils = require('@duplojs/utils');
|
|
5
|
+
|
|
6
|
+
class WrongContentTypeError extends utils.kindHeritage("wrong-content-type-error", kind.createCoreLibKind("wrong-content-type-error"), Error) {
|
|
7
|
+
expectedContentType;
|
|
8
|
+
contentType;
|
|
9
|
+
constructor(expectedContentType, contentType) {
|
|
10
|
+
super({}, [`expect content-type "${expectedContentType}" but receive "${contentType}".`]);
|
|
11
|
+
this.expectedContentType = expectedContentType;
|
|
12
|
+
this.contentType = contentType;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
exports.WrongContentTypeError = WrongContentTypeError;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare const WrongContentTypeError_base: new (params: {
|
|
2
|
+
"@DuplojsHttpCore/wrong-content-type-error"?: unknown;
|
|
3
|
+
}, parentParams: readonly [message?: string | undefined, options?: ErrorOptions | undefined]) => Error & import("@duplojs/utils").Kind<import("@duplojs/utils").KindDefinition<"@DuplojsHttpCore/wrong-content-type-error", unknown>, unknown> & import("@duplojs/utils").Kind<import("@duplojs/utils").KindDefinition<"wrong-content-type-error", unknown>, unknown>;
|
|
4
|
+
export declare class WrongContentTypeError extends WrongContentTypeError_base {
|
|
5
|
+
expectedContentType: string;
|
|
6
|
+
contentType: string;
|
|
7
|
+
constructor(expectedContentType: string, contentType: string);
|
|
8
|
+
}
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createCoreLibKind } from '../kind.mjs';
|
|
2
|
+
import { kindHeritage } from '@duplojs/utils';
|
|
3
|
+
|
|
4
|
+
class WrongContentTypeError extends kindHeritage("wrong-content-type-error", createCoreLibKind("wrong-content-type-error"), Error) {
|
|
5
|
+
expectedContentType;
|
|
6
|
+
contentType;
|
|
7
|
+
constructor(expectedContentType, contentType) {
|
|
8
|
+
super({}, [`expect content-type "${expectedContentType}" but receive "${contentType}".`]);
|
|
9
|
+
this.expectedContentType = expectedContentType;
|
|
10
|
+
this.contentType = contentType;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { WrongContentTypeError };
|
|
@@ -6,8 +6,8 @@ import { type BuildStepSuccessEither, type BuildStepNotSupportEither } from "../
|
|
|
6
6
|
import { type Steps } from "../../steps";
|
|
7
7
|
import { type ResponseContract } from "../../response";
|
|
8
8
|
export type BuildedRouteFunction = (request: Request) => Promise<void>;
|
|
9
|
-
export type BuildRouteSuccessEither = E.
|
|
10
|
-
export type BuildRouteNotSupportEither = E.
|
|
9
|
+
export type BuildRouteSuccessEither = E.Right<"buildSuccess", BuildedRouteFunction>;
|
|
10
|
+
export type BuildRouteNotSupportEither = E.Left<"routeNotSupport", Route>;
|
|
11
11
|
export interface RouteFunctionBuilderParams {
|
|
12
12
|
readonly globalHooksRouteLifeCycle: readonly HookRouteLifeCycle[];
|
|
13
13
|
readonly environment: Environment;
|
|
@@ -33,7 +33,6 @@ const defaultRouteFunctionBuilder = create.createRouteFunctionBuilder(index.rout
|
|
|
33
33
|
const hookBeforeRouteExecution = utils.pipe(allHooks, utils.A.map(({ beforeRouteExecution }) => beforeRouteExecution), utils.A.filter(utils.isType("function")), utils.forward);
|
|
34
34
|
const hookBeforeSendResponse = utils.pipe(allHooks, utils.A.map(({ beforeSendResponse }) => beforeSendResponse), utils.A.filter(utils.isType("function")), utils.forward);
|
|
35
35
|
const hookOnConstructRequest = utils.pipe(allHooks, utils.A.map(({ onConstructRequest }) => onConstructRequest), utils.A.filter(utils.isType("function")), utils.forward);
|
|
36
|
-
const hookParseBody = utils.pipe(allHooks, utils.A.map(({ parseBody }) => parseBody), utils.A.filter(utils.isType("function")), utils.forward);
|
|
37
36
|
const hookError = utils.pipe(allHooks, utils.A.map(({ error }) => error), utils.A.filter(utils.isType("function")), utils.forward);
|
|
38
37
|
const hookSendResponse = utils.pipe(allHooks, utils.A.map(({ sendResponse }) => sendResponse), utils.A.filter(utils.isType("function")), utils.forward);
|
|
39
38
|
const hooks = {
|
|
@@ -52,7 +51,6 @@ const defaultRouteFunctionBuilder = create.createRouteFunctionBuilder(index.rout
|
|
|
52
51
|
return newRequest;
|
|
53
52
|
}
|
|
54
53
|
: (params) => params.request,
|
|
55
|
-
parseBody: hook.buildHookBefore(hookParseBody),
|
|
56
54
|
error: hook.buildHookErrorBefore(hookError),
|
|
57
55
|
sendResponse: hook.buildHookAfter(hookSendResponse),
|
|
58
56
|
};
|
|
@@ -75,15 +73,6 @@ const defaultRouteFunctionBuilder = create.createRouteFunctionBuilder(index.rout
|
|
|
75
73
|
}
|
|
76
74
|
floor = result;
|
|
77
75
|
}
|
|
78
|
-
const parseBodyResult = await hooks.parseBody({
|
|
79
|
-
request,
|
|
80
|
-
exit: hook.exitHookFunction,
|
|
81
|
-
next: hook.nextHookFunction,
|
|
82
|
-
response: hook.createHookResponse("parseBody"),
|
|
83
|
-
});
|
|
84
|
-
if (parseBodyResult instanceof base.Response) {
|
|
85
|
-
return parseBodyResult;
|
|
86
|
-
}
|
|
87
76
|
for (let index = 0; index < buildedSteps.length; index++) {
|
|
88
77
|
const result = await buildedSteps[index].buildedFunction(request, floor);
|
|
89
78
|
if (result instanceof base.Response) {
|
|
@@ -31,7 +31,6 @@ const defaultRouteFunctionBuilder = createRouteFunctionBuilder(routeKind.has, as
|
|
|
31
31
|
const hookBeforeRouteExecution = pipe(allHooks, A.map(({ beforeRouteExecution }) => beforeRouteExecution), A.filter(isType("function")), forward);
|
|
32
32
|
const hookBeforeSendResponse = pipe(allHooks, A.map(({ beforeSendResponse }) => beforeSendResponse), A.filter(isType("function")), forward);
|
|
33
33
|
const hookOnConstructRequest = pipe(allHooks, A.map(({ onConstructRequest }) => onConstructRequest), A.filter(isType("function")), forward);
|
|
34
|
-
const hookParseBody = pipe(allHooks, A.map(({ parseBody }) => parseBody), A.filter(isType("function")), forward);
|
|
35
34
|
const hookError = pipe(allHooks, A.map(({ error }) => error), A.filter(isType("function")), forward);
|
|
36
35
|
const hookSendResponse = pipe(allHooks, A.map(({ sendResponse }) => sendResponse), A.filter(isType("function")), forward);
|
|
37
36
|
const hooks = {
|
|
@@ -50,7 +49,6 @@ const defaultRouteFunctionBuilder = createRouteFunctionBuilder(routeKind.has, as
|
|
|
50
49
|
return newRequest;
|
|
51
50
|
}
|
|
52
51
|
: (params) => params.request,
|
|
53
|
-
parseBody: buildHookBefore(hookParseBody),
|
|
54
52
|
error: buildHookErrorBefore(hookError),
|
|
55
53
|
sendResponse: buildHookAfter(hookSendResponse),
|
|
56
54
|
};
|
|
@@ -73,15 +71,6 @@ const defaultRouteFunctionBuilder = createRouteFunctionBuilder(routeKind.has, as
|
|
|
73
71
|
}
|
|
74
72
|
floor = result;
|
|
75
73
|
}
|
|
76
|
-
const parseBodyResult = await hooks.parseBody({
|
|
77
|
-
request,
|
|
78
|
-
exit: exitHookFunction,
|
|
79
|
-
next: nextHookFunction,
|
|
80
|
-
response: createHookResponse("parseBody"),
|
|
81
|
-
});
|
|
82
|
-
if (parseBodyResult instanceof Response) {
|
|
83
|
-
return parseBodyResult;
|
|
84
|
-
}
|
|
85
74
|
for (let index = 0; index < buildedSteps.length; index++) {
|
|
86
75
|
const result = await buildedSteps[index].buildedFunction(request, floor);
|
|
87
76
|
if (result instanceof Response) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { HookResponse } from "../../response";
|
|
2
|
-
import { type HookAfterSendResponse, type HookBeforeRouteExecution, type HookBeforeSendResponse, type HookError, type
|
|
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
|
|
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.
|
|
14
|
-
export type BuildStepNotSupportEither = E.
|
|
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
|
|
25
|
+
buildedFunction: async (request, floor) => {
|
|
26
|
+
const cutResult = await cutFunction(floor, {
|
|
40
27
|
request,
|
|
41
28
|
output,
|
|
42
29
|
response,
|
|
43
30
|
});
|
|
44
|
-
if (
|
|
45
|
-
|
|
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
|
|
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
|
|
23
|
+
buildedFunction: async (request, floor) => {
|
|
24
|
+
const cutResult = await cutFunction(floor, {
|
|
38
25
|
request,
|
|
39
26
|
output,
|
|
40
27
|
response,
|
|
41
28
|
});
|
|
42
|
-
if (
|
|
43
|
-
|
|
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
|
|
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
|
|
14
|
-
const
|
|
15
|
-
?
|
|
16
|
-
: undefined);
|
|
17
|
-
|
|
18
|
-
? response.setHeader("extract-key", `request.${key}`)
|
|
19
|
-
: response.setHeader("extract-key", `request.${key}.${subKey}`);
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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 }) =>
|
|
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
|
-
|
|
1
|
+
import { type MaybePromise } from "@duplojs/utils";
|
|
2
|
+
export declare const defaultExtractStepFunctionBuilder: (step: import("../../../steps").Steps, params: import("..").StepFunctionBuilderParams) => MaybePromise<import("..").BuildStepSuccessEither | import("..").BuildStepNotSupportEither>;
|