@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.
- 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/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 +19 -1
- 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/constraint.cjs +24 -0
- package/dist/core/clean/constraint.d.ts +8 -0
- package/dist/core/clean/constraint.mjs +22 -0
- package/dist/core/clean/constraintsSet.cjs +27 -0
- package/dist/core/clean/constraintsSet.d.ts +8 -0
- package/dist/core/clean/constraintsSet.mjs +25 -0
- package/dist/core/clean/entity.cjs +33 -0
- package/dist/core/clean/entity.d.ts +20 -0
- package/dist/core/clean/entity.mjs +31 -0
- package/dist/core/clean/index.cjs +8 -0
- package/dist/core/clean/index.d.ts +5 -0
- package/dist/core/clean/index.mjs +5 -0
- package/dist/core/clean/newType.cjs +15 -0
- package/dist/core/clean/newType.d.ts +8 -0
- package/dist/core/clean/newType.mjs +13 -0
- package/dist/core/clean/primitive.cjs +12 -0
- package/dist/core/clean/primitive.d.ts +8 -0
- package/dist/core/clean/primitive.mjs +10 -0
- 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 +35 -10
- package/dist/core/index.d.ts +3 -0
- package/dist/core/index.mjs +14 -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 +8 -4
- package/dist/plugins/codeGenerator/plugin.mjs +9 -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 +9 -0
- package/dist/plugins/codeGenerator/typescriptTransfomer.d.ts +1 -0
- package/dist/plugins/codeGenerator/typescriptTransfomer.mjs +7 -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 -1
- package/dist/plugins/openApiGenerator/routeToOpenApi.d.ts +10 -1
- package/dist/plugins/openApiGenerator/routeToOpenApi.mjs +16 -1
- 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,8 @@
|
|
|
1
|
+
import { DPE, type UnionToIntersection } from "@duplojs/utils";
|
|
2
|
+
import { type EligiblePrimitive, type GetConstraint, type Primitive } from "@duplojs/utils/clean";
|
|
3
|
+
declare module "@duplojs/utils/clean" {
|
|
4
|
+
interface ConstraintsSetHandler<GenericPrimitiveValue extends EligiblePrimitive = EligiblePrimitive, GenericConstraintsHandler extends readonly ConstraintHandler[] = readonly []> {
|
|
5
|
+
toExtractParser(): DPE.ContractExtended<(Primitive<GenericPrimitiveValue> & UnionToIntersection<GenericConstraintsHandler[number] extends infer InferredConstraint ? InferredConstraint extends ConstraintHandler ? GetConstraint<InferredConstraint> : never : never>), unknown>;
|
|
6
|
+
toEndpointSchema(): DPE.ContractExtended<GenericPrimitiveValue>;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { A, pipe, O, DPE, keyWrappedValue } from '@duplojs/utils';
|
|
2
|
+
import { createConstraintsSet, constrainedTypeKind } from '@duplojs/utils/clean';
|
|
3
|
+
|
|
4
|
+
createConstraintsSet.overrideHandler.setMethod("toExtractParser", (self) => {
|
|
5
|
+
const checkers = A.flatMap(self.constraints, ({ checkers }) => checkers);
|
|
6
|
+
const dataParserWithCheckers = self
|
|
7
|
+
.primitiveHandler
|
|
8
|
+
.dataParser
|
|
9
|
+
.addChecker(...checkers);
|
|
10
|
+
const constraintsKindValue = pipe(self.constraints, A.map(({ name }) => O.entry(name, null)), O.fromEntries);
|
|
11
|
+
const valueContainer = constrainedTypeKind.setTo({}, constraintsKindValue);
|
|
12
|
+
const dataParser = DPE.transform(dataParserWithCheckers, (input) => ({
|
|
13
|
+
...valueContainer,
|
|
14
|
+
[keyWrappedValue]: input,
|
|
15
|
+
}));
|
|
16
|
+
return dataParser;
|
|
17
|
+
});
|
|
18
|
+
createConstraintsSet.overrideHandler.setMethod("toEndpointSchema", (self) => {
|
|
19
|
+
const checkers = A.flatMap(self.constraints, ({ checkers }) => checkers);
|
|
20
|
+
const dataParserWithCheckers = self
|
|
21
|
+
.primitiveHandler
|
|
22
|
+
.dataParser
|
|
23
|
+
.addChecker(...checkers);
|
|
24
|
+
return DPE.lazy(() => dataParserWithCheckers);
|
|
25
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var utils = require('@duplojs/utils');
|
|
4
|
+
var clean = require('@duplojs/utils/clean');
|
|
5
|
+
|
|
6
|
+
function propertiesDefinitionToSchema(definition, method) {
|
|
7
|
+
return utils.pipe(definition, utils.P.when(clean.newTypeHandlerKind.has, (value) => value[method]()), utils.P.when(utils.isType("array"), utils.innerPipe(utils.A.map((element) => element[method]()), (options) => {
|
|
8
|
+
utils.asserts(options, utils.A.minElements(1));
|
|
9
|
+
return utils.DP.union(options);
|
|
10
|
+
})), utils.P.otherwise((definition) => utils.pipe(definition.type, (subDefinition) => propertiesDefinitionToSchema(subDefinition, method), (dataParser) => {
|
|
11
|
+
if (definition.inArray) {
|
|
12
|
+
return utils.pipe(dataParser, utils.DP.array, (dataParser) => typeof definition.inArray === "object"
|
|
13
|
+
&& typeof definition.inArray.min === "number"
|
|
14
|
+
? dataParser.addChecker(utils.DP.checkerArrayMin(definition.inArray.min))
|
|
15
|
+
: dataParser, (dataParser) => typeof definition.inArray === "object"
|
|
16
|
+
&& typeof definition.inArray.max === "number"
|
|
17
|
+
? dataParser.addChecker(utils.DP.checkerArrayMax(definition.inArray.max))
|
|
18
|
+
: dataParser);
|
|
19
|
+
}
|
|
20
|
+
return dataParser;
|
|
21
|
+
}, (dataParser) => definition.nullable === true
|
|
22
|
+
? utils.DP.nullable(dataParser)
|
|
23
|
+
: dataParser)));
|
|
24
|
+
}
|
|
25
|
+
clean.createEntity.overrideHandler.setMethod("toExtractParser", (self, keys) => utils.pipe(self.propertiesDefinition, utils.O.entries, utils.A.filter(([key]) => keys === undefined || utils.A.includes(keys, key)), utils.A.map(([key, value]) => utils.O.entry(key, propertiesDefinitionToSchema(value, "toExtractParser"))), utils.O.fromEntries, utils.DPE.object));
|
|
26
|
+
clean.createEntity.overrideHandler.setMethod("toEndpointSchema", (self, keys, params) => utils.pipe(self.propertiesDefinition, utils.O.entries, utils.A.filter(([key]) => keys === undefined || utils.A.includes(keys, key)), utils.A.map(([key, value]) => utils.O.entry(key, propertiesDefinitionToSchema(value, "toEndpointSchema"))), utils.O.fromEntries, (shape) => typeof params?.addEntityName !== "undefined"
|
|
27
|
+
? {
|
|
28
|
+
...shape,
|
|
29
|
+
_entityName: typeof params.addEntityName === "string"
|
|
30
|
+
? utils.DP.literal(`${self.name}/${params.addEntityName}`)
|
|
31
|
+
: utils.DP.literal(self.name),
|
|
32
|
+
}
|
|
33
|
+
: shape, utils.DPE.object));
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { DP, DPE, type IsEqual, type SimplifyTopLevel, type IsExtends } from "@duplojs/utils";
|
|
2
|
+
import { type EntityRawProperties, type EntityProperties, type EntityPropertiesDefinition } from "@duplojs/utils/clean";
|
|
3
|
+
interface ToEndpointSchemaParams {
|
|
4
|
+
addEntityName?: boolean | string;
|
|
5
|
+
}
|
|
6
|
+
declare module "@duplojs/utils/clean" {
|
|
7
|
+
interface EntityHandler<GenericName extends string = string, GenericPropertiesDefinition extends EntityPropertiesDefinition = EntityPropertiesDefinition> {
|
|
8
|
+
toExtractParser<GenericEntityProperties extends EntityProperties<GenericPropertiesDefinition>, const GenericKey extends keyof GenericEntityProperties = keyof GenericEntityProperties>(keys?: GenericKey[]): ReturnType<typeof DPE.object<{
|
|
9
|
+
[Prop in GenericKey]: DP.Contract<GenericEntityProperties[Prop], unknown>;
|
|
10
|
+
}>>;
|
|
11
|
+
toEndpointSchema<GenericEntityRawProperties extends EntityRawProperties<GenericPropertiesDefinition>, const GenericKey extends keyof GenericEntityRawProperties = keyof GenericEntityRawProperties, const GenericParams extends ToEndpointSchemaParams = {}>(keys?: GenericKey[], params?: GenericParams | ToEndpointSchemaParams): ReturnType<typeof DPE.object<SimplifyTopLevel<{
|
|
12
|
+
[Prop in GenericKey]: DP.Contract<GenericEntityRawProperties[Prop], unknown>;
|
|
13
|
+
} & (IsEqual<GenericParams["addEntityName"], true> extends true ? {
|
|
14
|
+
[Prop in "_entityName"]: DP.Contract<GenericName, unknown>;
|
|
15
|
+
} : {}) & (IsExtends<GenericParams["addEntityName"], string> extends true ? {
|
|
16
|
+
[Prop in "_entityName"]: DP.Contract<`${GenericName}/${GenericParams["addEntityName"]}`, unknown>;
|
|
17
|
+
} : {})>>>;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { pipe, P, isType, innerPipe, A, asserts, DP, O, DPE } from '@duplojs/utils';
|
|
2
|
+
import { newTypeHandlerKind, createEntity } from '@duplojs/utils/clean';
|
|
3
|
+
|
|
4
|
+
function propertiesDefinitionToSchema(definition, method) {
|
|
5
|
+
return pipe(definition, P.when(newTypeHandlerKind.has, (value) => value[method]()), P.when(isType("array"), innerPipe(A.map((element) => element[method]()), (options) => {
|
|
6
|
+
asserts(options, A.minElements(1));
|
|
7
|
+
return DP.union(options);
|
|
8
|
+
})), P.otherwise((definition) => pipe(definition.type, (subDefinition) => propertiesDefinitionToSchema(subDefinition, method), (dataParser) => {
|
|
9
|
+
if (definition.inArray) {
|
|
10
|
+
return pipe(dataParser, DP.array, (dataParser) => typeof definition.inArray === "object"
|
|
11
|
+
&& typeof definition.inArray.min === "number"
|
|
12
|
+
? dataParser.addChecker(DP.checkerArrayMin(definition.inArray.min))
|
|
13
|
+
: dataParser, (dataParser) => typeof definition.inArray === "object"
|
|
14
|
+
&& typeof definition.inArray.max === "number"
|
|
15
|
+
? dataParser.addChecker(DP.checkerArrayMax(definition.inArray.max))
|
|
16
|
+
: dataParser);
|
|
17
|
+
}
|
|
18
|
+
return dataParser;
|
|
19
|
+
}, (dataParser) => definition.nullable === true
|
|
20
|
+
? DP.nullable(dataParser)
|
|
21
|
+
: dataParser)));
|
|
22
|
+
}
|
|
23
|
+
createEntity.overrideHandler.setMethod("toExtractParser", (self, keys) => pipe(self.propertiesDefinition, O.entries, A.filter(([key]) => keys === undefined || A.includes(keys, key)), A.map(([key, value]) => O.entry(key, propertiesDefinitionToSchema(value, "toExtractParser"))), O.fromEntries, DPE.object));
|
|
24
|
+
createEntity.overrideHandler.setMethod("toEndpointSchema", (self, keys, params) => pipe(self.propertiesDefinition, O.entries, A.filter(([key]) => keys === undefined || A.includes(keys, key)), A.map(([key, value]) => O.entry(key, propertiesDefinitionToSchema(value, "toEndpointSchema"))), O.fromEntries, (shape) => typeof params?.addEntityName !== "undefined"
|
|
25
|
+
? {
|
|
26
|
+
...shape,
|
|
27
|
+
_entityName: typeof params.addEntityName === "string"
|
|
28
|
+
? DP.literal(`${self.name}/${params.addEntityName}`)
|
|
29
|
+
: DP.literal(self.name),
|
|
30
|
+
}
|
|
31
|
+
: shape, DPE.object));
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var utils = require('@duplojs/utils');
|
|
4
|
+
var clean = require('@duplojs/utils/clean');
|
|
5
|
+
|
|
6
|
+
clean.createNewType.overrideHandler.setMethod("toExtractParser", (self) => {
|
|
7
|
+
const constraintsKindValue = utils.pipe(self.constraints, utils.A.map(({ name }) => utils.O.entry(name, null)), utils.O.fromEntries);
|
|
8
|
+
const valueContainer = clean.newTypeKind.setTo(clean.constrainedTypeKind.setTo({}, constraintsKindValue), self.name);
|
|
9
|
+
const dataParser = utils.DPE.transform(self.dataParser, (input) => ({
|
|
10
|
+
...valueContainer,
|
|
11
|
+
[utils.keyWrappedValue]: input,
|
|
12
|
+
}));
|
|
13
|
+
return dataParser;
|
|
14
|
+
});
|
|
15
|
+
clean.createNewType.overrideHandler.setMethod("toEndpointSchema", (self) => utils.DPE.lazy(() => self.dataParser));
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DPE } from "@duplojs/utils";
|
|
2
|
+
import { type NewType } from "@duplojs/utils/clean";
|
|
3
|
+
declare module "@duplojs/utils/clean" {
|
|
4
|
+
interface NewTypeHandler<GenericName extends string = string, GenericValue extends unknown = unknown, GenericConstraintsHandler extends readonly ConstraintHandler[] = readonly ConstraintHandler[], GenericInput extends unknown = unknown> {
|
|
5
|
+
toExtractParser(): DPE.ContractExtended<NewType<GenericName, GenericValue, GenericConstraintsHandler[number]["name"]>, unknown>;
|
|
6
|
+
toEndpointSchema(): DPE.ContractExtended<GenericValue>;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { pipe, A, O, DPE, keyWrappedValue } from '@duplojs/utils';
|
|
2
|
+
import { createNewType, newTypeKind, constrainedTypeKind } from '@duplojs/utils/clean';
|
|
3
|
+
|
|
4
|
+
createNewType.overrideHandler.setMethod("toExtractParser", (self) => {
|
|
5
|
+
const constraintsKindValue = pipe(self.constraints, A.map(({ name }) => O.entry(name, null)), O.fromEntries);
|
|
6
|
+
const valueContainer = newTypeKind.setTo(constrainedTypeKind.setTo({}, constraintsKindValue), self.name);
|
|
7
|
+
const dataParser = DPE.transform(self.dataParser, (input) => ({
|
|
8
|
+
...valueContainer,
|
|
9
|
+
[keyWrappedValue]: input,
|
|
10
|
+
}));
|
|
11
|
+
return dataParser;
|
|
12
|
+
});
|
|
13
|
+
createNewType.overrideHandler.setMethod("toEndpointSchema", (self) => DPE.lazy(() => self.dataParser));
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var utils = require('@duplojs/utils');
|
|
4
|
+
var clean = require('@duplojs/utils/clean');
|
|
5
|
+
|
|
6
|
+
clean.createPrimitive.overrideHandler.setMethod("toExtractParser", (self) => {
|
|
7
|
+
const dataParser = utils.DPE.transform(self.dataParser, (input) => ({
|
|
8
|
+
[utils.keyWrappedValue]: input,
|
|
9
|
+
}));
|
|
10
|
+
return dataParser;
|
|
11
|
+
});
|
|
12
|
+
clean.createPrimitive.overrideHandler.setMethod("toEndpointSchema", (self) => utils.DPE.lazy(() => self.dataParser));
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DPE } from "@duplojs/utils";
|
|
2
|
+
import { type EligiblePrimitive, type Primitive } from "@duplojs/utils/clean";
|
|
3
|
+
declare module "@duplojs/utils/clean" {
|
|
4
|
+
interface PrimitiveHandler<GenericValue extends EligiblePrimitive = EligiblePrimitive> {
|
|
5
|
+
toExtractParser(): DPE.ContractExtended<Primitive<GenericValue>, unknown>;
|
|
6
|
+
toEndpointSchema(): DPE.ContractExtended<GenericValue, unknown>;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DPE, keyWrappedValue } from '@duplojs/utils';
|
|
2
|
+
import { createPrimitive } from '@duplojs/utils/clean';
|
|
3
|
+
|
|
4
|
+
createPrimitive.overrideHandler.setMethod("toExtractParser", (self) => {
|
|
5
|
+
const dataParser = DPE.transform(self.dataParser, (input) => ({
|
|
6
|
+
[keyWrappedValue]: input,
|
|
7
|
+
}));
|
|
8
|
+
return dataParser;
|
|
9
|
+
});
|
|
10
|
+
createPrimitive.overrideHandler.setMethod("toEndpointSchema", (self) => DPE.lazy(() => self.dataParser));
|
|
@@ -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) {
|