@duplojs/http 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/getBody.cjs +22 -0
- package/dist/client/getBody.d.ts +1 -0
- package/dist/client/getBody.mjs +20 -0
- package/dist/client/hooks.cjs +79 -0
- package/dist/client/hooks.d.ts +33 -0
- package/dist/client/hooks.mjs +70 -0
- package/dist/client/httpClient.cjs +153 -0
- package/dist/client/httpClient.d.ts +60 -0
- package/dist/client/httpClient.mjs +130 -0
- package/dist/client/index.cjs +33 -0
- package/dist/client/index.d.ts +9 -0
- package/dist/client/index.mjs +9 -0
- package/dist/client/insertParamsInPath.cjs +12 -0
- package/dist/client/insertParamsInPath.d.ts +2 -0
- package/dist/client/insertParamsInPath.mjs +10 -0
- package/dist/client/kind.cjs +9 -0
- package/dist/client/kind.d.ts +6 -0
- package/dist/client/kind.mjs +7 -0
- package/dist/client/promiseRequest.cjs +355 -0
- package/dist/client/promiseRequest.d.ts +98 -0
- package/dist/client/promiseRequest.mjs +332 -0
- package/dist/client/queryToString.cjs +25 -0
- package/dist/client/queryToString.d.ts +2 -0
- package/dist/client/queryToString.mjs +23 -0
- package/dist/client/types/ObjectCanBeEmpty.cjs +2 -0
- package/dist/client/types/ObjectCanBeEmpty.d.ts +4 -0
- package/dist/client/types/ObjectCanBeEmpty.mjs +1 -0
- package/dist/client/types/clientRequestParams.cjs +2 -0
- package/dist/client/types/clientRequestParams.d.ts +51 -0
- package/dist/client/types/clientRequestParams.mjs +1 -0
- package/dist/client/types/clientResponse.cjs +2 -0
- package/dist/client/types/clientResponse.d.ts +34 -0
- package/dist/client/types/clientResponse.mjs +1 -0
- package/dist/client/types/index.cjs +7 -0
- package/dist/client/types/index.d.ts +4 -0
- package/dist/client/types/index.mjs +4 -0
- package/dist/client/types/serverRoute.cjs +2 -0
- package/dist/client/types/serverRoute.d.ts +22 -0
- package/dist/client/types/serverRoute.mjs +1 -0
- package/dist/client/unexpectedResponseError.cjs +44 -0
- package/dist/client/unexpectedResponseError.d.ts +38 -0
- package/dist/client/unexpectedResponseError.mjs +39 -0
- package/dist/core/functionsBuilders/route/default.cjs +10 -9
- package/dist/core/functionsBuilders/route/default.mjs +3 -2
- package/dist/core/functionsBuilders/route/hook.cjs +22 -22
- package/dist/core/functionsBuilders/route/hook.d.ts +2 -2
- package/dist/core/functionsBuilders/route/hook.mjs +2 -2
- package/dist/core/functionsBuilders/steps/create.d.ts +2 -2
- package/dist/core/functionsBuilders/steps/defaults/checkerStep.cjs +3 -2
- package/dist/core/functionsBuilders/steps/defaults/checkerStep.mjs +3 -2
- package/dist/core/functionsBuilders/steps/defaults/cutStep.cjs +3 -2
- package/dist/core/functionsBuilders/steps/defaults/cutStep.mjs +3 -2
- package/dist/core/functionsBuilders/steps/defaults/extractStep.cjs +6 -5
- package/dist/core/functionsBuilders/steps/defaults/extractStep.mjs +4 -3
- package/dist/core/functionsBuilders/steps/defaults/handlerStep.cjs +3 -2
- package/dist/core/functionsBuilders/steps/defaults/handlerStep.mjs +3 -2
- package/dist/core/functionsBuilders/steps/defaults/processStep.cjs +5 -4
- package/dist/core/functionsBuilders/steps/defaults/processStep.mjs +3 -2
- package/dist/core/hub/defaultNotfoundHandler.d.ts +1 -1
- package/dist/core/hub/index.cjs +1 -1
- package/dist/core/hub/index.mjs +1 -1
- package/dist/core/index.cjs +37 -34
- package/dist/core/index.mjs +5 -3
- package/dist/core/response/base.cjs +40 -0
- package/dist/core/response/base.d.ts +21 -0
- package/dist/core/response/base.mjs +38 -0
- package/dist/core/response/contract.cjs +2 -2
- package/dist/core/response/contract.d.ts +120 -118
- package/dist/core/response/contract.mjs +2 -2
- package/dist/core/{route/hooks/response.cjs → response/hook.cjs} +4 -3
- package/dist/core/{route/hooks/response.d.ts → response/hook.d.ts} +2 -2
- package/dist/core/{route/hooks/response.mjs → response/hook.mjs} +3 -2
- package/dist/core/response/index.cjs +9 -38
- package/dist/core/response/index.d.ts +3 -20
- package/dist/core/response/index.mjs +3 -38
- package/dist/core/response/predicted.cjs +22 -0
- package/dist/core/response/predicted.d.ts +11 -0
- package/dist/core/response/predicted.mjs +20 -0
- package/dist/core/route/{hooks/index.cjs → hooks.cjs} +2 -3
- package/dist/core/route/{hooks/index.d.ts → hooks.d.ts} +4 -4
- package/dist/core/route/{hooks/index.mjs → hooks.mjs} +2 -2
- package/dist/core/route/index.cjs +4 -4
- package/dist/core/route/index.mjs +1 -1
- package/dist/core/steps/cut.d.ts +3 -3
- package/dist/core/steps/handler.d.ts +3 -3
- package/dist/core/steps/identifier.d.ts +2 -2
- package/dist/core/steps/types/stepFunctionParams.d.ts +2 -2
- package/dist/core/types/forbiddenBigintDataParser.cjs +2 -0
- package/dist/core/types/forbiddenBigintDataParser.d.ts +6 -0
- package/dist/core/types/forbiddenBigintDataParser.mjs +1 -0
- package/dist/core/types/index.cjs +1 -0
- package/dist/core/types/index.d.ts +1 -0
- package/dist/core/types/index.mjs +1 -0
- package/dist/interfaces/node/createHttpServer.cjs +1 -0
- package/dist/interfaces/node/createHttpServer.d.ts +2 -1
- package/dist/interfaces/node/createHttpServer.mjs +1 -0
- package/dist/interfaces/node/hooks.cjs +16 -13
- package/dist/interfaces/node/hooks.mjs +15 -12
- package/dist/plugins/codeGenerator/index.cjs +0 -3
- package/dist/plugins/codeGenerator/index.mjs +1 -1
- package/dist/plugins/codeGenerator/plugin.cjs +1 -1
- package/dist/plugins/codeGenerator/plugin.mjs +1 -1
- package/dist/plugins/codeGenerator/routeToDataParser.cjs +4 -55
- package/dist/plugins/codeGenerator/routeToDataParser.d.ts +2 -181
- package/dist/plugins/codeGenerator/routeToDataParser.mjs +6 -54
- package/dist/plugins/openApiGenerator/aggregateStepContract.cjs +62 -0
- package/dist/plugins/openApiGenerator/aggregateStepContract.d.ts +18 -0
- package/dist/plugins/openApiGenerator/aggregateStepContract.mjs +60 -0
- package/dist/plugins/openApiGenerator/index.cjs +17 -0
- package/dist/plugins/openApiGenerator/index.d.ts +7 -0
- package/dist/plugins/openApiGenerator/index.mjs +7 -0
- package/dist/plugins/openApiGenerator/makeOpenApiPage.cjs +30 -0
- package/dist/plugins/openApiGenerator/makeOpenApiPage.d.ts +7 -0
- package/dist/plugins/openApiGenerator/makeOpenApiPage.mjs +28 -0
- package/dist/plugins/openApiGenerator/makeOpenApiRoute.cjs +15 -0
- package/dist/plugins/openApiGenerator/makeOpenApiRoute.d.ts +18 -0
- package/dist/plugins/openApiGenerator/makeOpenApiRoute.mjs +13 -0
- package/dist/plugins/openApiGenerator/plugin.cjs +90 -0
- package/dist/plugins/openApiGenerator/plugin.d.ts +49 -0
- package/dist/plugins/openApiGenerator/plugin.mjs +88 -0
- package/dist/plugins/openApiGenerator/routeToOpenApi.cjs +163 -0
- package/dist/plugins/openApiGenerator/routeToOpenApi.d.ts +35 -0
- package/dist/plugins/openApiGenerator/routeToOpenApi.mjs +161 -0
- package/dist/plugins/openApiGenerator/types/endpointResponse.cjs +2 -0
- package/dist/plugins/openApiGenerator/types/endpointResponse.d.ts +19 -0
- package/dist/plugins/openApiGenerator/types/endpointResponse.mjs +1 -0
- package/dist/plugins/openApiGenerator/types/entrypoint.cjs +2 -0
- package/dist/plugins/openApiGenerator/types/entrypoint.d.ts +22 -0
- package/dist/plugins/openApiGenerator/types/entrypoint.mjs +1 -0
- package/dist/plugins/openApiGenerator/types/entrypointKey.cjs +2 -0
- package/dist/plugins/openApiGenerator/types/entrypointKey.d.ts +1 -0
- package/dist/plugins/openApiGenerator/types/entrypointKey.mjs +1 -0
- package/dist/plugins/openApiGenerator/types/index.cjs +11 -0
- package/dist/plugins/openApiGenerator/types/index.d.ts +8 -0
- package/dist/plugins/openApiGenerator/types/index.mjs +8 -0
- package/dist/plugins/openApiGenerator/types/openApiDocument.cjs +2 -0
- package/dist/plugins/openApiGenerator/types/openApiDocument.d.ts +31 -0
- package/dist/plugins/openApiGenerator/types/openApiDocument.mjs +1 -0
- package/dist/plugins/openApiGenerator/types/openApiMethod.cjs +2 -0
- package/dist/plugins/openApiGenerator/types/openApiMethod.d.ts +1 -0
- package/dist/plugins/openApiGenerator/types/openApiMethod.mjs +1 -0
- package/dist/plugins/openApiGenerator/types/openApiOperation.cjs +2 -0
- package/dist/plugins/openApiGenerator/types/openApiOperation.d.ts +8 -0
- package/dist/plugins/openApiGenerator/types/openApiOperation.mjs +1 -0
- package/dist/plugins/openApiGenerator/types/openApiPath.cjs +2 -0
- package/dist/plugins/openApiGenerator/types/openApiPath.d.ts +4 -0
- package/dist/plugins/openApiGenerator/types/openApiPath.mjs +1 -0
- package/dist/plugins/openApiGenerator/types/openApiSecuritySchema.cjs +2 -0
- package/dist/plugins/openApiGenerator/types/openApiSecuritySchema.d.ts +8 -0
- package/dist/plugins/openApiGenerator/types/openApiSecuritySchema.mjs +1 -0
- package/package.json +17 -4
|
@@ -1,39 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { createCoreLibKind } from '../kind.mjs';
|
|
1
|
+
export { Response } from './base.mjs';
|
|
3
2
|
export { ResponseContract } from './contract.mjs';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
code;
|
|
7
|
-
information;
|
|
8
|
-
body;
|
|
9
|
-
headers = undefined;
|
|
10
|
-
constructor(code, information, body) {
|
|
11
|
-
super();
|
|
12
|
-
this.code = code;
|
|
13
|
-
this.information = information;
|
|
14
|
-
this.body = body;
|
|
15
|
-
}
|
|
16
|
-
setHeaders(headers) {
|
|
17
|
-
this.headers = O.override(this.headers ?? {}, headers);
|
|
18
|
-
return this;
|
|
19
|
-
}
|
|
20
|
-
setHeader(key, header) {
|
|
21
|
-
if (!this.headers) {
|
|
22
|
-
this.headers = {};
|
|
23
|
-
}
|
|
24
|
-
if (typeof header !== "undefined") {
|
|
25
|
-
this.headers[key] = header;
|
|
26
|
-
}
|
|
27
|
-
return this;
|
|
28
|
-
}
|
|
29
|
-
deleteHeader(key) {
|
|
30
|
-
if (!this.headers) {
|
|
31
|
-
return this;
|
|
32
|
-
}
|
|
33
|
-
const { [key]: deleteHeader, ...rest } = this.headers;
|
|
34
|
-
this.headers = rest;
|
|
35
|
-
return this;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export { Response };
|
|
3
|
+
export { HookResponse } from './hook.mjs';
|
|
4
|
+
export { PredictedResponse } from './predicted.mjs';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var kind = require('../kind.cjs');
|
|
4
|
+
require('./index.cjs');
|
|
5
|
+
var utils = require('@duplojs/utils');
|
|
6
|
+
var base = require('./base.cjs');
|
|
7
|
+
|
|
8
|
+
const defaultParamsParent = [undefined, undefined, undefined];
|
|
9
|
+
const defaultParams = {};
|
|
10
|
+
class PredictedResponse extends utils.kindHeritage("predicted-response", kind.createCoreLibKind("predicted-response"), base.Response) {
|
|
11
|
+
code;
|
|
12
|
+
information;
|
|
13
|
+
body;
|
|
14
|
+
constructor(code, information, body) {
|
|
15
|
+
super(defaultParams, defaultParamsParent);
|
|
16
|
+
this.code = code;
|
|
17
|
+
this.information = information;
|
|
18
|
+
this.body = body;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
exports.PredictedResponse = PredictedResponse;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ResponseCode, Response } from "../response";
|
|
2
|
+
declare const PredictedResponse_base: new (params: {
|
|
3
|
+
"@DuplojsHttpCore/predicted-response"?: unknown;
|
|
4
|
+
}, parentParams: [code: any, information: any, body: any]) => Response<any, any, any> & import("@duplojs/utils").Kind<import("@duplojs/utils").KindDefinition<"@DuplojsHttpCore/predicted-response", unknown>, unknown> & import("@duplojs/utils").Kind<import("@duplojs/utils").KindDefinition<"predicted-response", unknown>, unknown>;
|
|
5
|
+
export declare class PredictedResponse<GenericCode extends ResponseCode = ResponseCode, GenericInformation extends string = string, GenericBody extends unknown = unknown> extends PredictedResponse_base {
|
|
6
|
+
code: GenericCode;
|
|
7
|
+
information: GenericInformation;
|
|
8
|
+
body: GenericBody;
|
|
9
|
+
constructor(code: GenericCode, information: GenericInformation, body: GenericBody);
|
|
10
|
+
}
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { createCoreLibKind } from '../kind.mjs';
|
|
2
|
+
import './index.mjs';
|
|
3
|
+
import { kindHeritage } from '@duplojs/utils';
|
|
4
|
+
import { Response } from './base.mjs';
|
|
5
|
+
|
|
6
|
+
const defaultParamsParent = [undefined, undefined, undefined];
|
|
7
|
+
const defaultParams = {};
|
|
8
|
+
class PredictedResponse extends kindHeritage("predicted-response", createCoreLibKind("predicted-response"), Response) {
|
|
9
|
+
code;
|
|
10
|
+
information;
|
|
11
|
+
body;
|
|
12
|
+
constructor(code, information, body) {
|
|
13
|
+
super(defaultParams, defaultParamsParent);
|
|
14
|
+
this.code = code;
|
|
15
|
+
this.information = information;
|
|
16
|
+
this.body = body;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { PredictedResponse };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var kind = require('
|
|
4
|
-
|
|
3
|
+
var kind = require('../kind.cjs');
|
|
4
|
+
require('../response/index.cjs');
|
|
5
5
|
|
|
6
6
|
const hookRouteExitKind = kind.createCoreLibKind("route-hook-exit");
|
|
7
7
|
const hookRouteNextKind = kind.createCoreLibKind("route-hook-next");
|
|
@@ -15,7 +15,6 @@ function createHookRouteLifeCycle(...args) {
|
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
exports.HookResponse = response.HookResponse;
|
|
19
18
|
exports.createHookRouteLifeCycle = createHookRouteLifeCycle;
|
|
20
19
|
exports.hookRouteExitKind = hookRouteExitKind;
|
|
21
20
|
exports.hookRouteNextKind = hookRouteNextKind;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { type Request } from "
|
|
1
|
+
import { type Request } from "../request";
|
|
2
2
|
import { type UnionToIntersection, type AnyFunction, type Kind, type MaybePromise, type SimplifyTopLevel, type IsEqual } from "@duplojs/utils";
|
|
3
|
-
import { type HookResponse } from "
|
|
4
|
-
import { type ResponseCode, type Response } from "
|
|
5
|
-
export * from "
|
|
3
|
+
import { type HookResponse } from "../response";
|
|
4
|
+
import { type ResponseCode, type Response } from "../response";
|
|
5
|
+
export * from "../response";
|
|
6
6
|
export interface HookParamsOnConstructRequest {
|
|
7
7
|
request: Request;
|
|
8
8
|
addRequestProperties<GenericNewProperties extends Record<string, unknown>>(newProperties: GenericNewProperties): Request & GenericNewProperties;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createCoreLibKind } from '
|
|
2
|
-
|
|
1
|
+
import { createCoreLibKind } from '../kind.mjs';
|
|
2
|
+
import '../response/index.mjs';
|
|
3
3
|
|
|
4
4
|
const hookRouteExitKind = createCoreLibKind("route-hook-exit");
|
|
5
5
|
const hookRouteNextKind = createCoreLibKind("route-hook-next");
|
|
@@ -3,15 +3,15 @@
|
|
|
3
3
|
var utils = require('@duplojs/utils');
|
|
4
4
|
var kind = require('../kind.cjs');
|
|
5
5
|
require('./types/index.cjs');
|
|
6
|
-
var
|
|
6
|
+
var hooks = require('./hooks.cjs');
|
|
7
7
|
|
|
8
8
|
const routeKind = kind.createCoreLibKind("route");
|
|
9
9
|
function createRoute(definition) {
|
|
10
10
|
return utils.pipe({ definition }, routeKind.setTo);
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
exports.createHookRouteLifeCycle =
|
|
14
|
-
exports.hookRouteExitKind =
|
|
15
|
-
exports.hookRouteNextKind =
|
|
13
|
+
exports.createHookRouteLifeCycle = hooks.createHookRouteLifeCycle;
|
|
14
|
+
exports.hookRouteExitKind = hooks.hookRouteExitKind;
|
|
15
|
+
exports.hookRouteNextKind = hooks.hookRouteNextKind;
|
|
16
16
|
exports.createRoute = createRoute;
|
|
17
17
|
exports.routeKind = routeKind;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { pipe } from '@duplojs/utils';
|
|
2
2
|
import { createCoreLibKind } from '../kind.mjs';
|
|
3
3
|
import './types/index.mjs';
|
|
4
|
-
export { createHookRouteLifeCycle, hookRouteExitKind, hookRouteNextKind } from './hooks
|
|
4
|
+
export { createHookRouteLifeCycle, hookRouteExitKind, hookRouteNextKind } from './hooks.mjs';
|
|
5
5
|
|
|
6
6
|
const routeKind = createCoreLibKind("route");
|
|
7
7
|
function createRoute(definition) {
|
package/dist/core/steps/cut.d.ts
CHANGED
|
@@ -2,16 +2,16 @@ import { type WrappedValue, type Kind, type MaybePromise, type NeverCoalescing }
|
|
|
2
2
|
import { type StepKind } from "./kind";
|
|
3
3
|
import { type Floor } from "../floor";
|
|
4
4
|
import { type StepFunctionParams } from "./types";
|
|
5
|
-
import { type
|
|
5
|
+
import { type PredictedResponse, type ResponseContract } from "../response";
|
|
6
6
|
import { type Request } from "../request";
|
|
7
7
|
export declare const cutStepOutputKind: import("@duplojs/utils").KindHandler<import("@duplojs/utils").KindDefinition<"@DuplojsHttpCore/cut-output", unknown>>;
|
|
8
8
|
export interface CutStepFunctionOutput<GenericData extends Record<string, unknown> = Record<string, unknown>> extends Kind<typeof cutStepOutputKind.definition>, WrappedValue<GenericData> {
|
|
9
9
|
}
|
|
10
|
-
export interface CutStepFunctionParams<GenericRequest extends Request = Request, GenericResponse extends
|
|
10
|
+
export interface CutStepFunctionParams<GenericRequest extends Request = Request, GenericResponse extends PredictedResponse = PredictedResponse> extends StepFunctionParams<GenericRequest, GenericResponse> {
|
|
11
11
|
output<GenericData extends Record<string, unknown> = never>(data?: GenericData): CutStepFunctionOutput<NeverCoalescing<GenericData, {}>>;
|
|
12
12
|
}
|
|
13
13
|
export interface CutStepDefinition {
|
|
14
|
-
theFunction(floor: Floor, params: CutStepFunctionParams): MaybePromise<CutStepFunctionOutput |
|
|
14
|
+
theFunction(floor: Floor, params: CutStepFunctionParams): MaybePromise<CutStepFunctionOutput | PredictedResponse>;
|
|
15
15
|
readonly responseContract: ResponseContract.Contract | readonly ResponseContract.Contract[];
|
|
16
16
|
}
|
|
17
17
|
export declare const cutStepKind: import("@duplojs/utils").KindHandler<import("@duplojs/utils").KindDefinition<"@DuplojsHttpCore/cut-step", unknown>>;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { type MaybePromise, type Kind } from "@duplojs/utils";
|
|
2
2
|
import { type StepKind } from "./kind";
|
|
3
3
|
import { type Floor } from "../floor";
|
|
4
|
-
import { type
|
|
4
|
+
import { type PredictedResponse, type ResponseContract } from "../response";
|
|
5
5
|
import { type Request } from "../request";
|
|
6
6
|
import { type StepFunctionParams } from "./types";
|
|
7
|
-
export interface HandlerStepFunctionParams<GenericRequest extends Request = Request, GenericResponse extends
|
|
7
|
+
export interface HandlerStepFunctionParams<GenericRequest extends Request = Request, GenericResponse extends PredictedResponse = PredictedResponse> extends StepFunctionParams<GenericRequest, GenericResponse> {
|
|
8
8
|
}
|
|
9
9
|
export interface HandlerStepDefinition {
|
|
10
|
-
theFunction(floor: Floor, params: HandlerStepFunctionParams): MaybePromise<
|
|
10
|
+
theFunction(floor: Floor, params: HandlerStepFunctionParams): MaybePromise<PredictedResponse>;
|
|
11
11
|
readonly responseContract: ResponseContract.Contract | readonly ResponseContract.Contract[];
|
|
12
12
|
}
|
|
13
13
|
export declare const handlerStepKind: import("@duplojs/utils").KindHandler<import("@duplojs/utils").KindDefinition<"@DuplojsHttpCore/handler-step", unknown>>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Kind } from "@duplojs/utils";
|
|
2
2
|
export declare const stepIdentifier: {
|
|
3
|
-
<GenericKindHandler extends import("@duplojs/utils").KindHandler<import("@duplojs/utils").KindDefinition<"@DuplojsHttpCore/step", unknown>> | import("@duplojs/utils").KindHandler<import("@duplojs/utils").KindDefinition<"@DuplojsHttpCore/checker-step", unknown>> | import("@duplojs/utils").KindHandler<import("@duplojs/utils").KindDefinition<"@DuplojsHttpCore/cut-step", unknown>> | import("@duplojs/utils").KindHandler<import("@duplojs/utils").KindDefinition<"@DuplojsHttpCore/extract-step", unknown>> | import("@duplojs/utils").KindHandler<import("@duplojs/utils").KindDefinition<"@DuplojsHttpCore/handler-step", unknown>> | import("@duplojs/utils").KindHandler<import("@duplojs/utils").KindDefinition<"@DuplojsHttpCore/presetChecker-step", unknown>> | import("@duplojs/utils").KindHandler<import("@duplojs/utils").KindDefinition<"@DuplojsHttpCore/process-step", unknown>>, GenericInput extends
|
|
4
|
-
<GenericKindHandler extends import("@duplojs/utils").KindHandler<import("@duplojs/utils").KindDefinition<"@DuplojsHttpCore/step", unknown>> | import("@duplojs/utils").KindHandler<import("@duplojs/utils").KindDefinition<"@DuplojsHttpCore/checker-step", unknown>> | import("@duplojs/utils").KindHandler<import("@duplojs/utils").KindDefinition<"@DuplojsHttpCore/cut-step", unknown>> | import("@duplojs/utils").KindHandler<import("@duplojs/utils").KindDefinition<"@DuplojsHttpCore/extract-step", unknown>> | import("@duplojs/utils").KindHandler<import("@duplojs/utils").KindDefinition<"@DuplojsHttpCore/handler-step", unknown>> | import("@duplojs/utils").KindHandler<import("@duplojs/utils").KindDefinition<"@DuplojsHttpCore/presetChecker-step", unknown>> | import("@duplojs/utils").KindHandler<import("@duplojs/utils").KindDefinition<"@DuplojsHttpCore/process-step", unknown>>, GenericInput extends
|
|
3
|
+
<GenericKindHandler extends import("@duplojs/utils").KindHandler<import("@duplojs/utils").KindDefinition<"@DuplojsHttpCore/step", unknown>> | import("@duplojs/utils").KindHandler<import("@duplojs/utils").KindDefinition<"@DuplojsHttpCore/checker-step", unknown>> | import("@duplojs/utils").KindHandler<import("@duplojs/utils").KindDefinition<"@DuplojsHttpCore/cut-step", unknown>> | import("@duplojs/utils").KindHandler<import("@duplojs/utils").KindDefinition<"@DuplojsHttpCore/extract-step", unknown>> | import("@duplojs/utils").KindHandler<import("@duplojs/utils").KindDefinition<"@DuplojsHttpCore/handler-step", unknown>> | import("@duplojs/utils").KindHandler<import("@duplojs/utils").KindDefinition<"@DuplojsHttpCore/presetChecker-step", unknown>> | import("@duplojs/utils").KindHandler<import("@duplojs/utils").KindDefinition<"@DuplojsHttpCore/process-step", unknown>>, GenericInput extends unknown, GenericGroupedKind extends import("@duplojs/utils").UnionToIntersection<GenericKindHandler extends import("@duplojs/utils").KindHandler<import("@duplojs/utils").KindDefinition<string, unknown>> ? Kind<GenericKindHandler["definition"], GenericKindHandler["definition"]["value"]> : never>>(kind: GenericKindHandler | GenericKindHandler[]): (input: GenericInput) => input is (import("@duplojs/utils").IsEqual<import("@duplojs/utils").IsEqual<false | (GenericInput extends any ? import("@duplojs/utils").IsEqual<GenericInput, Kind<import("@duplojs/utils").KindDefinition<"@DuplojsHttpCore/step", unknown>, unknown>> : never), boolean>, true> extends true ? Extract<import("./checker").CheckerStep<import("./checker").CheckerStepDefinition>, GenericGroupedKind> | Extract<import("./cut").CutStep<import("./cut").CutStepDefinition>, GenericGroupedKind> | Extract<import("./extract").ExtractStep<import("./extract").ExtractStepDefinition>, GenericGroupedKind> | Extract<import("./handler").HandlerStep<import("./handler").HandlerStepDefinition>, GenericGroupedKind> | Extract<import("./presetChecker").PresetCheckerStep<import("./presetChecker").PresetCheckerStepDefinition>, GenericGroupedKind> | Extract<import("./process").ProcessStep<import("./process").ProcessStepDefinition>, GenericGroupedKind> : never) | Extract<GenericInput, GenericGroupedKind>;
|
|
4
|
+
<GenericKindHandler extends import("@duplojs/utils").KindHandler<import("@duplojs/utils").KindDefinition<"@DuplojsHttpCore/step", unknown>> | import("@duplojs/utils").KindHandler<import("@duplojs/utils").KindDefinition<"@DuplojsHttpCore/checker-step", unknown>> | import("@duplojs/utils").KindHandler<import("@duplojs/utils").KindDefinition<"@DuplojsHttpCore/cut-step", unknown>> | import("@duplojs/utils").KindHandler<import("@duplojs/utils").KindDefinition<"@DuplojsHttpCore/extract-step", unknown>> | import("@duplojs/utils").KindHandler<import("@duplojs/utils").KindDefinition<"@DuplojsHttpCore/handler-step", unknown>> | import("@duplojs/utils").KindHandler<import("@duplojs/utils").KindDefinition<"@DuplojsHttpCore/presetChecker-step", unknown>> | import("@duplojs/utils").KindHandler<import("@duplojs/utils").KindDefinition<"@DuplojsHttpCore/process-step", unknown>>, GenericInput extends unknown, GenericGroupedKind extends import("@duplojs/utils").UnionToIntersection<GenericKindHandler extends import("@duplojs/utils").KindHandler<import("@duplojs/utils").KindDefinition<string, unknown>> ? Kind<GenericKindHandler["definition"], GenericKindHandler["definition"]["value"]> : never>>(input: GenericInput, kind: GenericKindHandler | GenericKindHandler[]): input is (import("@duplojs/utils").IsEqual<import("@duplojs/utils").IsEqual<false | (GenericInput extends any ? import("@duplojs/utils").IsEqual<GenericInput, Kind<import("@duplojs/utils").KindDefinition<"@DuplojsHttpCore/step", unknown>, unknown>> : never), boolean>, true> extends true ? Extract<import("./checker").CheckerStep<import("./checker").CheckerStepDefinition>, GenericGroupedKind> | Extract<import("./cut").CutStep<import("./cut").CutStepDefinition>, GenericGroupedKind> | Extract<import("./extract").ExtractStep<import("./extract").ExtractStepDefinition>, GenericGroupedKind> | Extract<import("./handler").HandlerStep<import("./handler").HandlerStepDefinition>, GenericGroupedKind> | Extract<import("./presetChecker").PresetCheckerStep<import("./presetChecker").PresetCheckerStepDefinition>, GenericGroupedKind> | Extract<import("./process").ProcessStep<import("./process").ProcessStepDefinition>, GenericGroupedKind> : never) | Extract<GenericInput, GenericGroupedKind>;
|
|
5
5
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type Request } from "../../request";
|
|
2
|
-
import { type
|
|
2
|
+
import { type PredictedResponse } from "../../response";
|
|
3
3
|
import { type IsEqual, type Or } from "@duplojs/utils";
|
|
4
|
-
export interface StepFunctionParams<GenericRequest extends Request = Request, GenericResponse extends
|
|
4
|
+
export interface StepFunctionParams<GenericRequest extends Request = Request, GenericResponse extends PredictedResponse = PredictedResponse> {
|
|
5
5
|
request: GenericRequest;
|
|
6
6
|
response<GenericInformation extends GenericResponse["information"], GenericFilteredResponse extends Extract<GenericResponse, {
|
|
7
7
|
information: GenericInformation;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type DP } from "@duplojs/utils";
|
|
2
|
+
declare const SymbolForbiddenBigintDataParser: unique symbol;
|
|
3
|
+
export type ForbiddenBigintDataParser<GenericDataParser extends DP.DataParser> = DP.Contain<GenericDataParser, DP.DataParserBigInt<any>> extends true ? {
|
|
4
|
+
[SymbolForbiddenBigintDataParser]: "Bigint dataParser is not supported.";
|
|
5
|
+
} : unknown;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -10,6 +10,7 @@ declare module "../../core/hub" {
|
|
|
10
10
|
readonly port: number;
|
|
11
11
|
readonly maxBodySize: BytesInString | number;
|
|
12
12
|
readonly informationHeaderKey: string;
|
|
13
|
+
readonly predictedHeaderKey: string;
|
|
13
14
|
readonly fromHookHeaderKey: string;
|
|
14
15
|
readonly http?: http.ServerOptions;
|
|
15
16
|
readonly https?: https.ServerOptions;
|
|
@@ -19,5 +20,5 @@ declare module "../../core/hub" {
|
|
|
19
20
|
readonly serverResponse: http.ServerResponse;
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
|
-
export type CreateHttpServerParams = O.PartialKeys<Omit<HttpServerParams, "interface">, "maxBodySize" | "informationHeaderKey" | "fromHookHeaderKey">;
|
|
23
|
+
export type CreateHttpServerParams = O.PartialKeys<Omit<HttpServerParams, "interface">, "maxBodySize" | "informationHeaderKey" | "predictedHeaderKey" | "fromHookHeaderKey">;
|
|
23
24
|
export declare function createHttpServer(inputHub: Hub, params: CreateHttpServerParams): Promise<https.Server<typeof http.IncomingMessage, typeof http.ServerResponse> | http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>>;
|
|
@@ -3,18 +3,20 @@
|
|
|
3
3
|
require('../../core/route/index.cjs');
|
|
4
4
|
var utils = require('@duplojs/utils');
|
|
5
5
|
require('./error/index.cjs');
|
|
6
|
-
var
|
|
7
|
-
var
|
|
6
|
+
var hooks = require('../../core/route/hooks.cjs');
|
|
7
|
+
var predicted = require('../../core/response/predicted.cjs');
|
|
8
|
+
var hook = require('../../core/response/hook.cjs');
|
|
8
9
|
var bodySizeExceedsLimitError = require('./error/bodySizeExceedsLimitError.cjs');
|
|
9
10
|
var bodyParseWrongChunkReceived = require('./error/bodyParseWrongChunkReceived.cjs');
|
|
10
11
|
var bodyParseUnknownError = require('./error/bodyParseUnknownError.cjs');
|
|
11
12
|
|
|
12
13
|
function makeNodeHook(hub, serverParams) {
|
|
13
14
|
const informationHeaderKey = serverParams.informationHeaderKey;
|
|
15
|
+
const predictedHeaderKey = serverParams.predictedHeaderKey;
|
|
14
16
|
const fromHookHeaderKey = serverParams.fromHookHeaderKey;
|
|
15
17
|
const isDev = hub.config.environment === "DEV";
|
|
16
18
|
const maxBodySize = utils.stringToBytes(serverParams.maxBodySize);
|
|
17
|
-
return
|
|
19
|
+
return hooks.createHookRouteLifeCycle({
|
|
18
20
|
async parseBody({ request, exit }) {
|
|
19
21
|
const contentType = request.headers["content-type"] instanceof Array
|
|
20
22
|
? request.headers["content-type"].join(", ")
|
|
@@ -79,17 +81,20 @@ function makeNodeHook(hub, serverParams) {
|
|
|
79
81
|
},
|
|
80
82
|
beforeSendResponse({ request, currentResponse, exit }) {
|
|
81
83
|
const body = currentResponse.body;
|
|
82
|
-
if (typeof body === "
|
|
83
|
-
|| typeof body === "string"
|
|
84
|
-
|| body === null
|
|
84
|
+
if (typeof body === "string"
|
|
85
85
|
|| body instanceof Error) {
|
|
86
86
|
currentResponse.setHeader("content-type", "text/plain; charset=utf-8");
|
|
87
87
|
}
|
|
88
|
-
else if (typeof body === "object"
|
|
88
|
+
else if (typeof body === "object"
|
|
89
|
+
|| typeof body === "number"
|
|
90
|
+
|| typeof body === "boolean") {
|
|
89
91
|
currentResponse.setHeader("content-type", "application/json; charset=utf-8");
|
|
90
92
|
}
|
|
91
93
|
currentResponse.setHeader(informationHeaderKey, currentResponse.information);
|
|
92
|
-
if (currentResponse instanceof
|
|
94
|
+
if (currentResponse instanceof predicted.PredictedResponse) {
|
|
95
|
+
currentResponse.setHeader(predictedHeaderKey, "1");
|
|
96
|
+
}
|
|
97
|
+
else if (currentResponse instanceof hook.HookResponse) {
|
|
93
98
|
currentResponse.setHeader(fromHookHeaderKey, currentResponse.fromHook);
|
|
94
99
|
}
|
|
95
100
|
request.raw.response.writeHead(Number(currentResponse.code), currentResponse.headers);
|
|
@@ -101,16 +106,14 @@ function makeNodeHook(hub, serverParams) {
|
|
|
101
106
|
if (body instanceof Error) {
|
|
102
107
|
rawResponse.write(body.toString());
|
|
103
108
|
}
|
|
104
|
-
else if (typeof body === "object"
|
|
109
|
+
else if (typeof body === "object"
|
|
110
|
+
|| typeof body === "number"
|
|
111
|
+
|| typeof body === "boolean") {
|
|
105
112
|
rawResponse.write(JSON.stringify(body));
|
|
106
113
|
}
|
|
107
114
|
else if (typeof body === "string") {
|
|
108
115
|
rawResponse.write(body);
|
|
109
116
|
}
|
|
110
|
-
else if (typeof body === "number"
|
|
111
|
-
|| typeof body === "bigint") {
|
|
112
|
-
rawResponse.write(body.toString());
|
|
113
|
-
}
|
|
114
117
|
rawResponse.end();
|
|
115
118
|
return exit();
|
|
116
119
|
},
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import '../../core/route/index.mjs';
|
|
2
2
|
import { stringToBytes } from '@duplojs/utils';
|
|
3
3
|
import './error/index.mjs';
|
|
4
|
-
import { createHookRouteLifeCycle } from '../../core/route/hooks
|
|
5
|
-
import {
|
|
4
|
+
import { createHookRouteLifeCycle } from '../../core/route/hooks.mjs';
|
|
5
|
+
import { PredictedResponse } from '../../core/response/predicted.mjs';
|
|
6
|
+
import { HookResponse } from '../../core/response/hook.mjs';
|
|
6
7
|
import { BodySizeExceedsLimitError } from './error/bodySizeExceedsLimitError.mjs';
|
|
7
8
|
import { BodyParseWrongChunkReceived } from './error/bodyParseWrongChunkReceived.mjs';
|
|
8
9
|
import { BodyParseUnknownError } from './error/bodyParseUnknownError.mjs';
|
|
9
10
|
|
|
10
11
|
function makeNodeHook(hub, serverParams) {
|
|
11
12
|
const informationHeaderKey = serverParams.informationHeaderKey;
|
|
13
|
+
const predictedHeaderKey = serverParams.predictedHeaderKey;
|
|
12
14
|
const fromHookHeaderKey = serverParams.fromHookHeaderKey;
|
|
13
15
|
const isDev = hub.config.environment === "DEV";
|
|
14
16
|
const maxBodySize = stringToBytes(serverParams.maxBodySize);
|
|
@@ -77,17 +79,20 @@ function makeNodeHook(hub, serverParams) {
|
|
|
77
79
|
},
|
|
78
80
|
beforeSendResponse({ request, currentResponse, exit }) {
|
|
79
81
|
const body = currentResponse.body;
|
|
80
|
-
if (typeof body === "
|
|
81
|
-
|| typeof body === "string"
|
|
82
|
-
|| body === null
|
|
82
|
+
if (typeof body === "string"
|
|
83
83
|
|| body instanceof Error) {
|
|
84
84
|
currentResponse.setHeader("content-type", "text/plain; charset=utf-8");
|
|
85
85
|
}
|
|
86
|
-
else if (typeof body === "object"
|
|
86
|
+
else if (typeof body === "object"
|
|
87
|
+
|| typeof body === "number"
|
|
88
|
+
|| typeof body === "boolean") {
|
|
87
89
|
currentResponse.setHeader("content-type", "application/json; charset=utf-8");
|
|
88
90
|
}
|
|
89
91
|
currentResponse.setHeader(informationHeaderKey, currentResponse.information);
|
|
90
|
-
if (currentResponse instanceof
|
|
92
|
+
if (currentResponse instanceof PredictedResponse) {
|
|
93
|
+
currentResponse.setHeader(predictedHeaderKey, "1");
|
|
94
|
+
}
|
|
95
|
+
else if (currentResponse instanceof HookResponse) {
|
|
91
96
|
currentResponse.setHeader(fromHookHeaderKey, currentResponse.fromHook);
|
|
92
97
|
}
|
|
93
98
|
request.raw.response.writeHead(Number(currentResponse.code), currentResponse.headers);
|
|
@@ -99,16 +104,14 @@ function makeNodeHook(hub, serverParams) {
|
|
|
99
104
|
if (body instanceof Error) {
|
|
100
105
|
rawResponse.write(body.toString());
|
|
101
106
|
}
|
|
102
|
-
else if (typeof body === "object"
|
|
107
|
+
else if (typeof body === "object"
|
|
108
|
+
|| typeof body === "number"
|
|
109
|
+
|| typeof body === "boolean") {
|
|
103
110
|
rawResponse.write(JSON.stringify(body));
|
|
104
111
|
}
|
|
105
112
|
else if (typeof body === "string") {
|
|
106
113
|
rawResponse.write(body);
|
|
107
114
|
}
|
|
108
|
-
else if (typeof body === "number"
|
|
109
|
-
|| typeof body === "bigint") {
|
|
110
|
-
rawResponse.write(body.toString());
|
|
111
|
-
}
|
|
112
115
|
rawResponse.end();
|
|
113
116
|
return exit();
|
|
114
117
|
},
|
|
@@ -9,8 +9,5 @@ var stepsToDataParser = require('./stepsToDataParser.cjs');
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
exports.codeGeneratorPlugin = plugin.codeGeneratorPlugin;
|
|
12
|
-
exports.digitDataParser = routeToDataParser.digitDataParser;
|
|
13
|
-
exports.responseCodeDataParser = routeToDataParser.responseCodeDataParser;
|
|
14
|
-
exports.responseCodeDataParsers = routeToDataParser.responseCodeDataParsers;
|
|
15
12
|
exports.routeToDataParser = routeToDataParser.routeToDataParser;
|
|
16
13
|
exports.stepsToDataParser = stepsToDataParser.stepsToDataParser;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import '@duplojs/data-parser-tools/toTypescript';
|
|
2
2
|
import './types/index.mjs';
|
|
3
3
|
export { codeGeneratorPlugin } from './plugin.mjs';
|
|
4
|
-
export {
|
|
4
|
+
export { routeToDataParser } from './routeToDataParser.mjs';
|
|
5
5
|
export { stepsToDataParser } from './stepsToDataParser.mjs';
|
|
@@ -31,7 +31,7 @@ function codeGeneratorPlugin(pluginParams) {
|
|
|
31
31
|
{
|
|
32
32
|
beforeStartServer: async (hub) => {
|
|
33
33
|
const routes = hub.aggregatesRoutes();
|
|
34
|
-
const dataParserRoutes = utils.A.
|
|
34
|
+
const dataParserRoutes = utils.A.flatMap(routes, (route) => routeToDataParser.routeToDataParser(route, {
|
|
35
35
|
defaultExtractContract: hub.defaultExtractContract,
|
|
36
36
|
}));
|
|
37
37
|
if (!utils.A.minElements(dataParserRoutes, 1)) {
|
|
@@ -10,7 +10,7 @@ function codeGeneratorPlugin(pluginParams) {
|
|
|
10
10
|
{
|
|
11
11
|
beforeStartServer: async (hub) => {
|
|
12
12
|
const routes = hub.aggregatesRoutes();
|
|
13
|
-
const dataParserRoutes = A.
|
|
13
|
+
const dataParserRoutes = A.flatMap(routes, (route) => routeToDataParser(route, {
|
|
14
14
|
defaultExtractContract: hub.defaultExtractContract,
|
|
15
15
|
}));
|
|
16
16
|
if (!A.minElements(dataParserRoutes, 1)) {
|
|
@@ -3,41 +3,6 @@
|
|
|
3
3
|
var stepsToDataParser = require('./stepsToDataParser.cjs');
|
|
4
4
|
var utils = require('@duplojs/utils');
|
|
5
5
|
|
|
6
|
-
const digitDataParser = utils.DP.literal(["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]).setIdentifier("Digit");
|
|
7
|
-
const responseCodeDataParsers = {
|
|
8
|
-
information: utils.DP.templateLiteral([
|
|
9
|
-
"1",
|
|
10
|
-
digitDataParser,
|
|
11
|
-
digitDataParser,
|
|
12
|
-
]),
|
|
13
|
-
success: utils.DP.templateLiteral([
|
|
14
|
-
"2",
|
|
15
|
-
digitDataParser,
|
|
16
|
-
digitDataParser,
|
|
17
|
-
]),
|
|
18
|
-
redirection: utils.DP.templateLiteral([
|
|
19
|
-
"3",
|
|
20
|
-
digitDataParser,
|
|
21
|
-
digitDataParser,
|
|
22
|
-
]),
|
|
23
|
-
clientError: utils.DP.templateLiteral([
|
|
24
|
-
"4",
|
|
25
|
-
digitDataParser,
|
|
26
|
-
digitDataParser,
|
|
27
|
-
]),
|
|
28
|
-
serverError: utils.DP.templateLiteral([
|
|
29
|
-
"5",
|
|
30
|
-
digitDataParser,
|
|
31
|
-
digitDataParser,
|
|
32
|
-
]),
|
|
33
|
-
};
|
|
34
|
-
const responseCodeDataParser = utils.DP.union([
|
|
35
|
-
responseCodeDataParsers.information,
|
|
36
|
-
responseCodeDataParsers.success,
|
|
37
|
-
responseCodeDataParsers.redirection,
|
|
38
|
-
responseCodeDataParsers.clientError,
|
|
39
|
-
responseCodeDataParsers.serverError,
|
|
40
|
-
]).setIdentifier("ResponseCode");
|
|
41
6
|
function routeToDataParser(route, params) {
|
|
42
7
|
return utils.pipe([
|
|
43
8
|
...route.definition.preflightSteps,
|
|
@@ -52,28 +17,12 @@ function routeToDataParser(route, params) {
|
|
|
52
17
|
return select(utils.O.entry(key, utils.DP.object(value)));
|
|
53
18
|
}
|
|
54
19
|
return skip();
|
|
55
|
-
}), utils.O.fromEntries)), ({ endpointContract, entrypointContract }) => utils.DP.object({
|
|
20
|
+
}), utils.O.fromEntries)), ({ endpointContract, entrypointContract }) => utils.A.map(route.definition.paths, (path) => utils.DP.object({
|
|
56
21
|
method: utils.DP.literal(route.definition.method),
|
|
57
|
-
path: utils.DP.literal(
|
|
22
|
+
path: utils.DP.literal(path),
|
|
58
23
|
...entrypointContract,
|
|
59
|
-
responses: utils.DP.union(
|
|
60
|
-
|
|
61
|
-
code: responseCodeDataParser,
|
|
62
|
-
information: utils.DP.string(),
|
|
63
|
-
body: utils.DP.unknown(),
|
|
64
|
-
fromHook: utils.DP.literal(true),
|
|
65
|
-
}),
|
|
66
|
-
utils.DP.object({
|
|
67
|
-
code: responseCodeDataParsers.serverError,
|
|
68
|
-
information: utils.DP.string(),
|
|
69
|
-
body: utils.DP.unknown(),
|
|
70
|
-
}),
|
|
71
|
-
...endpointContract,
|
|
72
|
-
]),
|
|
73
|
-
}));
|
|
24
|
+
responses: utils.DP.union(endpointContract),
|
|
25
|
+
})));
|
|
74
26
|
}
|
|
75
27
|
|
|
76
|
-
exports.digitDataParser = digitDataParser;
|
|
77
|
-
exports.responseCodeDataParser = responseCodeDataParser;
|
|
78
|
-
exports.responseCodeDataParsers = responseCodeDataParsers;
|
|
79
28
|
exports.routeToDataParser = routeToDataParser;
|