@duplojs/http 0.1.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/builders/index.cjs +11 -0
- package/dist/core/builders/index.mjs +4 -0
- package/dist/core/builders/preflight/index.cjs +10 -0
- package/dist/core/builders/preflight/index.mjs +3 -0
- package/dist/core/builders/preflight/process.cjs +2 -8
- package/dist/core/builders/preflight/process.mjs +2 -8
- package/dist/core/builders/preflight/route.cjs +2 -8
- package/dist/core/builders/preflight/route.mjs +2 -8
- package/dist/core/builders/process/checker.cjs +2 -8
- package/dist/core/builders/process/checker.mjs +2 -8
- package/dist/core/builders/process/cut.cjs +2 -8
- package/dist/core/builders/process/cut.mjs +2 -8
- package/dist/core/builders/process/extract.cjs +2 -8
- package/dist/core/builders/process/extract.mjs +2 -8
- package/dist/core/builders/process/index.cjs +14 -0
- package/dist/core/builders/process/index.mjs +7 -0
- package/dist/core/builders/process/presetChecker.cjs +2 -8
- package/dist/core/builders/process/presetChecker.mjs +2 -8
- package/dist/core/builders/process/process.cjs +2 -8
- package/dist/core/builders/process/process.mjs +2 -8
- package/dist/core/builders/route/checker.cjs +2 -8
- package/dist/core/builders/route/checker.mjs +2 -8
- package/dist/core/builders/route/cut.cjs +2 -8
- package/dist/core/builders/route/cut.mjs +2 -8
- package/dist/core/builders/route/extract.cjs +2 -8
- package/dist/core/builders/route/extract.mjs +2 -8
- package/dist/core/builders/route/handler.cjs +2 -8
- package/dist/core/builders/route/handler.mjs +2 -8
- package/dist/core/builders/route/index.cjs +16 -0
- package/dist/core/builders/route/index.mjs +8 -0
- package/dist/core/builders/route/presetChecker.cjs +2 -8
- package/dist/core/builders/route/presetChecker.mjs +2 -8
- package/dist/core/builders/route/process.cjs +2 -8
- package/dist/core/builders/route/process.mjs +2 -8
- package/dist/core/floor.cjs +2 -0
- package/dist/core/floor.mjs +1 -0
- package/dist/core/functionsBuilders/index.cjs +5 -0
- package/dist/core/functionsBuilders/index.mjs +2 -0
- package/dist/core/functionsBuilders/route/build.cjs +5 -14
- package/dist/core/functionsBuilders/route/build.d.ts +3 -1
- package/dist/core/functionsBuilders/route/build.mjs +6 -15
- package/dist/core/functionsBuilders/route/create.d.ts +2 -0
- package/dist/core/functionsBuilders/route/default.cjs +11 -21
- package/dist/core/functionsBuilders/route/default.mjs +5 -15
- 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/route/index.cjs +18 -0
- package/dist/core/functionsBuilders/route/index.mjs +4 -0
- package/dist/core/functionsBuilders/steps/build.cjs +4 -0
- package/dist/core/functionsBuilders/steps/build.d.ts +2 -0
- package/dist/core/functionsBuilders/steps/build.mjs +5 -1
- package/dist/core/functionsBuilders/steps/create.d.ts +3 -2
- package/dist/core/functionsBuilders/steps/defaults/checkerStep.cjs +5 -9
- package/dist/core/functionsBuilders/steps/defaults/checkerStep.mjs +5 -9
- package/dist/core/functionsBuilders/steps/defaults/cutStep.cjs +6 -11
- package/dist/core/functionsBuilders/steps/defaults/cutStep.mjs +7 -12
- package/dist/core/functionsBuilders/steps/defaults/extractStep.cjs +10 -17
- package/dist/core/functionsBuilders/steps/defaults/extractStep.mjs +9 -16
- package/dist/core/functionsBuilders/steps/defaults/handlerStep.cjs +6 -11
- package/dist/core/functionsBuilders/steps/defaults/handlerStep.mjs +6 -11
- package/dist/core/functionsBuilders/steps/defaults/index.cjs +16 -0
- package/dist/core/functionsBuilders/steps/defaults/index.mjs +5 -0
- package/dist/core/functionsBuilders/steps/defaults/processStep.cjs +7 -12
- package/dist/core/functionsBuilders/steps/defaults/processStep.mjs +6 -11
- package/dist/core/functionsBuilders/steps/index.cjs +10 -0
- package/dist/core/functionsBuilders/steps/index.mjs +3 -0
- package/dist/core/hub/defaultNotfoundHandler.cjs +2 -8
- package/dist/core/hub/defaultNotfoundHandler.d.ts +1 -1
- package/dist/core/hub/defaultNotfoundHandler.mjs +2 -8
- package/dist/core/hub/hooks.d.ts +3 -3
- package/dist/core/hub/index.cjs +3 -9
- package/dist/core/hub/index.mjs +3 -9
- package/dist/core/index.cjs +64 -70
- package/dist/core/index.mjs +23 -30
- package/dist/core/process/index.cjs +1 -0
- package/dist/core/process/index.mjs +1 -0
- package/dist/core/process/types/index.cjs +2 -0
- package/dist/core/process/types/index.mjs +1 -0
- 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 +13 -13
- package/dist/core/response/contract.d.ts +121 -119
- package/dist/core/response/contract.mjs +14 -14
- package/dist/core/{route/hooks/response.cjs → response/hook.cjs} +5 -4
- package/dist/core/{route/hooks/response.d.ts → response/hook.d.ts} +3 -3
- package/dist/core/{route/hooks/response.mjs → response/hook.mjs} +4 -3
- 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 +5 -4
- package/dist/core/route/index.mjs +2 -1
- package/dist/core/route/types/buildedRoute.cjs +2 -0
- package/dist/core/route/types/buildedRoute.mjs +1 -0
- package/dist/core/route/types/index.cjs +4 -0
- package/dist/core/route/types/index.mjs +1 -0
- package/dist/core/router/buildError.cjs +3 -1
- package/dist/core/router/buildError.d.ts +4 -2
- package/dist/core/router/buildError.mjs +3 -1
- package/dist/core/router/index.cjs +13 -7
- package/dist/core/router/index.mjs +14 -8
- package/dist/core/router/types/buildedRouter.cjs +2 -0
- package/dist/core/router/types/buildedRouter.mjs +1 -0
- package/dist/core/router/types/index.cjs +4 -0
- package/dist/core/router/types/index.mjs +1 -0
- 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/index.cjs +29 -0
- package/dist/core/steps/index.mjs +9 -0
- package/dist/core/steps/types/buildedStep.cjs +2 -0
- package/dist/core/steps/types/buildedStep.mjs +1 -0
- package/dist/core/steps/types/index.cjs +6 -0
- package/dist/core/steps/types/index.mjs +3 -0
- package/dist/core/steps/types/stepFunctionParams.cjs +2 -0
- package/dist/core/steps/types/stepFunctionParams.d.ts +2 -2
- package/dist/core/steps/types/stepFunctionParams.mjs +1 -0
- package/dist/core/steps/types/steps.cjs +2 -0
- package/dist/core/steps/types/steps.mjs +1 -0
- package/dist/core/types/environment.cjs +2 -0
- package/dist/core/types/environment.d.ts +1 -1
- package/dist/core/types/environment.mjs +1 -0
- 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 +5 -0
- package/dist/core/types/index.d.ts +1 -0
- package/dist/core/types/index.mjs +2 -0
- package/dist/interfaces/bun/index.cjs +1 -9
- package/dist/interfaces/bun/index.mjs +1 -9
- package/dist/interfaces/bun/types/index.cjs +4 -0
- package/dist/interfaces/bun/types/index.mjs +1 -0
- package/dist/interfaces/bun/types/request.cjs +5 -0
- package/dist/interfaces/bun/types/request.mjs +2 -0
- package/dist/interfaces/deno/index.cjs +1 -0
- package/dist/interfaces/deno/index.mjs +1 -0
- package/dist/interfaces/deno/types/index.cjs +2 -0
- package/dist/interfaces/deno/types/index.mjs +1 -0
- package/dist/interfaces/node/createHttpServer.cjs +11 -3
- package/dist/interfaces/node/createHttpServer.d.ts +2 -1
- package/dist/interfaces/node/createHttpServer.mjs +11 -3
- package/dist/interfaces/node/error/index.cjs +11 -0
- package/dist/interfaces/node/error/index.mjs +3 -0
- package/dist/interfaces/node/hooks.cjs +17 -13
- package/dist/interfaces/node/hooks.mjs +16 -12
- package/dist/interfaces/node/index.cjs +6 -13
- package/dist/interfaces/node/index.mjs +4 -11
- package/dist/interfaces/node/types/host.cjs +2 -0
- package/dist/interfaces/node/types/host.mjs +1 -0
- package/dist/interfaces/node/types/index.cjs +5 -0
- package/dist/interfaces/node/types/index.mjs +2 -0
- package/dist/interfaces/node/types/request.cjs +5 -0
- package/dist/interfaces/node/types/request.mjs +2 -0
- package/dist/plugins/codeGenerator/index.cjs +13 -0
- package/dist/plugins/codeGenerator/index.d.ts +5 -0
- package/dist/plugins/codeGenerator/index.mjs +5 -0
- package/dist/plugins/codeGenerator/plugin.cjs +51 -0
- package/dist/plugins/codeGenerator/plugin.d.ts +5 -0
- package/dist/plugins/codeGenerator/plugin.mjs +30 -0
- package/dist/plugins/codeGenerator/routeToDataParser.cjs +28 -0
- package/dist/plugins/codeGenerator/routeToDataParser.d.ts +7 -0
- package/dist/plugins/codeGenerator/routeToDataParser.mjs +26 -0
- package/dist/plugins/codeGenerator/stepsToDataParser.cjs +66 -0
- package/dist/plugins/codeGenerator/stepsToDataParser.d.ts +14 -0
- package/dist/plugins/codeGenerator/stepsToDataParser.mjs +64 -0
- package/dist/plugins/codeGenerator/types/entrypointKey.cjs +2 -0
- package/dist/plugins/codeGenerator/types/entrypointKey.d.ts +1 -0
- package/dist/plugins/codeGenerator/types/entrypointKey.mjs +1 -0
- package/dist/plugins/codeGenerator/types/index.cjs +4 -0
- package/dist/plugins/codeGenerator/types/index.d.ts +1 -0
- package/dist/plugins/codeGenerator/types/index.mjs +1 -0
- 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 +22 -3
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
require('../../core/steps/index.cjs');
|
|
4
|
+
var utils = require('@duplojs/utils');
|
|
5
|
+
var process = require('../../core/steps/process.cjs');
|
|
6
|
+
var extract = require('../../core/steps/extract.cjs');
|
|
7
|
+
var presetChecker = require('../../core/steps/presetChecker.cjs');
|
|
8
|
+
var checker = require('../../core/steps/checker.cjs');
|
|
9
|
+
var cut = require('../../core/steps/cut.cjs');
|
|
10
|
+
var handler = require('../../core/steps/handler.cjs');
|
|
11
|
+
|
|
12
|
+
function stepsToDataParser(steps, params) {
|
|
13
|
+
const processContracts = utils.pipe(steps, utils.A.filter(process.processStepKind.has), utils.A.map((element) => stepsToDataParser(element.definition.process.definition.steps, params)), utils.O.to({
|
|
14
|
+
entrypointContract: utils.A.map((result) => result.entrypointContract),
|
|
15
|
+
endpointContract: utils.A.flatMap((result) => result.endpointContract),
|
|
16
|
+
}));
|
|
17
|
+
const entrypointContract = utils.pipe(steps, utils.A.filter(extract.extractStepKind.has), utils.A.map((extractStep) => extractStep.definition.shape), utils.A.concat(processContracts.entrypointContract), utils.A.reduce(utils.A.reduceFrom({
|
|
18
|
+
body: {},
|
|
19
|
+
headers: {},
|
|
20
|
+
params: {},
|
|
21
|
+
query: {},
|
|
22
|
+
}), ({ element: shape, lastValue, nextWithObject }) => utils.pipe(lastValue, utils.O.entries, utils.A.map(([key, accumulatorValue]) => {
|
|
23
|
+
const currentExtractDataParser = shape[key];
|
|
24
|
+
if (utils.DP.dataParserKind.has(accumulatorValue)
|
|
25
|
+
|| !currentExtractDataParser
|
|
26
|
+
|| (!utils.DP.dataParserKind.has(accumulatorValue)
|
|
27
|
+
&& utils.O.countKeys(accumulatorValue) > 1
|
|
28
|
+
&& utils.DP.dataParserKind.has(currentExtractDataParser)
|
|
29
|
+
&& !utils.DP.objectKind.has(currentExtractDataParser))) {
|
|
30
|
+
return utils.O.entry(key, accumulatorValue);
|
|
31
|
+
}
|
|
32
|
+
if (!utils.DP.dataParserKind.has(currentExtractDataParser)) {
|
|
33
|
+
return utils.O.entry(key, {
|
|
34
|
+
...accumulatorValue,
|
|
35
|
+
...currentExtractDataParser,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
if (utils.DP.identifier(currentExtractDataParser, utils.DP.objectKind)) {
|
|
39
|
+
return utils.O.entry(key, {
|
|
40
|
+
...accumulatorValue,
|
|
41
|
+
...currentExtractDataParser.definition.shape,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return utils.O.entry(key, currentExtractDataParser);
|
|
45
|
+
}), utils.O.fromEntries, (object) => nextWithObject(lastValue, object))));
|
|
46
|
+
const endpointContract = utils.pipe(steps, utils.A.flatMap((step) => utils.P.match(step)
|
|
47
|
+
.when(process.processStepKind.has, () => [])
|
|
48
|
+
.when(extract.extractStepKind.has, ({ definition }) => definition.responseContract ?? params.defaultExtractContract)
|
|
49
|
+
.when(presetChecker.presetCheckerStepKind.has, ({ definition }) => definition.presetChecker.definition.responseContract)
|
|
50
|
+
.when(utils.hasSomeKinds([
|
|
51
|
+
checker.checkerStepKind,
|
|
52
|
+
cut.cutStepKind,
|
|
53
|
+
handler.handlerStepKind,
|
|
54
|
+
]), ({ definition }) => definition.responseContract)
|
|
55
|
+
.exhaustive()), utils.A.map(({ code, information, body }) => utils.DP.object({
|
|
56
|
+
code: utils.DP.literal(code),
|
|
57
|
+
information: utils.DP.literal(information),
|
|
58
|
+
body,
|
|
59
|
+
})), utils.A.concat(processContracts.endpointContract));
|
|
60
|
+
return {
|
|
61
|
+
entrypointContract,
|
|
62
|
+
endpointContract,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
exports.stepsToDataParser = stepsToDataParser;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type Steps } from "../../core/steps";
|
|
2
|
+
import { DP } from "@duplojs/utils";
|
|
3
|
+
import { type EntrypointKey } from "./types";
|
|
4
|
+
import { type ResponseContract } from "../../core/response";
|
|
5
|
+
type EntrypointReduceResult = Record<EntrypointKey, DP.DataParser | Record<string, DP.DataParser>>;
|
|
6
|
+
export interface StepsToDataParserParams {
|
|
7
|
+
readonly defaultExtractContract: ResponseContract.Contract;
|
|
8
|
+
}
|
|
9
|
+
export interface StepsToDataParserResult {
|
|
10
|
+
entrypointContract: EntrypointReduceResult;
|
|
11
|
+
endpointContract: DP.DataParser[];
|
|
12
|
+
}
|
|
13
|
+
export declare function stepsToDataParser(steps: readonly Steps[], params: StepsToDataParserParams): StepsToDataParserResult;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import '../../core/steps/index.mjs';
|
|
2
|
+
import { pipe, A, O, DP, P, hasSomeKinds } from '@duplojs/utils';
|
|
3
|
+
import { processStepKind } from '../../core/steps/process.mjs';
|
|
4
|
+
import { extractStepKind } from '../../core/steps/extract.mjs';
|
|
5
|
+
import { presetCheckerStepKind } from '../../core/steps/presetChecker.mjs';
|
|
6
|
+
import { checkerStepKind } from '../../core/steps/checker.mjs';
|
|
7
|
+
import { cutStepKind } from '../../core/steps/cut.mjs';
|
|
8
|
+
import { handlerStepKind } from '../../core/steps/handler.mjs';
|
|
9
|
+
|
|
10
|
+
function stepsToDataParser(steps, params) {
|
|
11
|
+
const processContracts = pipe(steps, A.filter(processStepKind.has), A.map((element) => stepsToDataParser(element.definition.process.definition.steps, params)), O.to({
|
|
12
|
+
entrypointContract: A.map((result) => result.entrypointContract),
|
|
13
|
+
endpointContract: A.flatMap((result) => result.endpointContract),
|
|
14
|
+
}));
|
|
15
|
+
const entrypointContract = pipe(steps, A.filter(extractStepKind.has), A.map((extractStep) => extractStep.definition.shape), A.concat(processContracts.entrypointContract), A.reduce(A.reduceFrom({
|
|
16
|
+
body: {},
|
|
17
|
+
headers: {},
|
|
18
|
+
params: {},
|
|
19
|
+
query: {},
|
|
20
|
+
}), ({ element: shape, lastValue, nextWithObject }) => pipe(lastValue, O.entries, A.map(([key, accumulatorValue]) => {
|
|
21
|
+
const currentExtractDataParser = shape[key];
|
|
22
|
+
if (DP.dataParserKind.has(accumulatorValue)
|
|
23
|
+
|| !currentExtractDataParser
|
|
24
|
+
|| (!DP.dataParserKind.has(accumulatorValue)
|
|
25
|
+
&& O.countKeys(accumulatorValue) > 1
|
|
26
|
+
&& DP.dataParserKind.has(currentExtractDataParser)
|
|
27
|
+
&& !DP.objectKind.has(currentExtractDataParser))) {
|
|
28
|
+
return O.entry(key, accumulatorValue);
|
|
29
|
+
}
|
|
30
|
+
if (!DP.dataParserKind.has(currentExtractDataParser)) {
|
|
31
|
+
return O.entry(key, {
|
|
32
|
+
...accumulatorValue,
|
|
33
|
+
...currentExtractDataParser,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
if (DP.identifier(currentExtractDataParser, DP.objectKind)) {
|
|
37
|
+
return O.entry(key, {
|
|
38
|
+
...accumulatorValue,
|
|
39
|
+
...currentExtractDataParser.definition.shape,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
return O.entry(key, currentExtractDataParser);
|
|
43
|
+
}), O.fromEntries, (object) => nextWithObject(lastValue, object))));
|
|
44
|
+
const endpointContract = pipe(steps, A.flatMap((step) => P.match(step)
|
|
45
|
+
.when(processStepKind.has, () => [])
|
|
46
|
+
.when(extractStepKind.has, ({ definition }) => definition.responseContract ?? params.defaultExtractContract)
|
|
47
|
+
.when(presetCheckerStepKind.has, ({ definition }) => definition.presetChecker.definition.responseContract)
|
|
48
|
+
.when(hasSomeKinds([
|
|
49
|
+
checkerStepKind,
|
|
50
|
+
cutStepKind,
|
|
51
|
+
handlerStepKind,
|
|
52
|
+
]), ({ definition }) => definition.responseContract)
|
|
53
|
+
.exhaustive()), A.map(({ code, information, body }) => DP.object({
|
|
54
|
+
code: DP.literal(code),
|
|
55
|
+
information: DP.literal(information),
|
|
56
|
+
body,
|
|
57
|
+
})), A.concat(processContracts.endpointContract));
|
|
58
|
+
return {
|
|
59
|
+
entrypointContract,
|
|
60
|
+
endpointContract,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export { stepsToDataParser };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type EntrypointKey = "query" | "body" | "params" | "headers";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./entrypointKey";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './entrypointKey.mjs';
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
require('../../core/steps/index.cjs');
|
|
4
|
+
var utils = require('@duplojs/utils');
|
|
5
|
+
var process = require('../../core/steps/process.cjs');
|
|
6
|
+
var extract = require('../../core/steps/extract.cjs');
|
|
7
|
+
var presetChecker = require('../../core/steps/presetChecker.cjs');
|
|
8
|
+
var checker = require('../../core/steps/checker.cjs');
|
|
9
|
+
var cut = require('../../core/steps/cut.cjs');
|
|
10
|
+
var handler = require('../../core/steps/handler.cjs');
|
|
11
|
+
|
|
12
|
+
function aggregateStepContract(steps, params) {
|
|
13
|
+
const processContracts = utils.pipe(steps, utils.A.filter(process.processStepKind.has), utils.A.map((element) => aggregateStepContract(element.definition.process.definition.steps, params)), utils.O.to({
|
|
14
|
+
entrypointContract: utils.A.map((result) => result.entrypointContract),
|
|
15
|
+
endpointContract: utils.A.flatMap((result) => result.endpointContract),
|
|
16
|
+
}));
|
|
17
|
+
const entrypointContract = utils.pipe(steps, utils.A.filter(extract.extractStepKind.has), utils.A.map((extractStep) => extractStep.definition.shape), utils.A.concat(processContracts.entrypointContract), utils.A.reduce(utils.A.reduceFrom({
|
|
18
|
+
body: {},
|
|
19
|
+
headers: {},
|
|
20
|
+
params: {},
|
|
21
|
+
query: {},
|
|
22
|
+
}), ({ element: shape, lastValue, nextWithObject }) => utils.pipe(lastValue, utils.O.entries, utils.A.map(([key, accumulatorValue]) => {
|
|
23
|
+
const currentExtractDataParser = shape[key];
|
|
24
|
+
if (utils.DP.dataParserKind.has(accumulatorValue)
|
|
25
|
+
|| !currentExtractDataParser
|
|
26
|
+
|| (!utils.DP.dataParserKind.has(accumulatorValue)
|
|
27
|
+
&& utils.O.countKeys(accumulatorValue) > 1
|
|
28
|
+
&& utils.DP.dataParserKind.has(currentExtractDataParser)
|
|
29
|
+
&& !utils.DP.objectKind.has(currentExtractDataParser))) {
|
|
30
|
+
return utils.O.entry(key, accumulatorValue);
|
|
31
|
+
}
|
|
32
|
+
if (!utils.DP.dataParserKind.has(currentExtractDataParser)) {
|
|
33
|
+
return utils.O.entry(key, {
|
|
34
|
+
...accumulatorValue,
|
|
35
|
+
...currentExtractDataParser,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
if (utils.DP.identifier(currentExtractDataParser, utils.DP.objectKind)) {
|
|
39
|
+
return utils.O.entry(key, {
|
|
40
|
+
...accumulatorValue,
|
|
41
|
+
...currentExtractDataParser.definition.shape,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return utils.O.entry(key, currentExtractDataParser);
|
|
45
|
+
}), utils.O.fromEntries, (object) => nextWithObject(lastValue, object))));
|
|
46
|
+
const endpointContract = utils.pipe(steps, utils.A.flatMap((step) => utils.P.match(step)
|
|
47
|
+
.when(process.processStepKind.has, () => [])
|
|
48
|
+
.when(extract.extractStepKind.has, ({ definition }) => definition.responseContract ?? params.defaultExtractContract)
|
|
49
|
+
.when(presetChecker.presetCheckerStepKind.has, ({ definition }) => definition.presetChecker.definition.responseContract)
|
|
50
|
+
.when(utils.hasSomeKinds([
|
|
51
|
+
checker.checkerStepKind,
|
|
52
|
+
cut.cutStepKind,
|
|
53
|
+
handler.handlerStepKind,
|
|
54
|
+
]), ({ definition }) => definition.responseContract)
|
|
55
|
+
.exhaustive()), utils.A.concat(processContracts.endpointContract));
|
|
56
|
+
return {
|
|
57
|
+
entrypointContract,
|
|
58
|
+
endpointContract,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
exports.aggregateStepContract = aggregateStepContract;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type Steps } from "../../core/steps";
|
|
2
|
+
import { DP } from "@duplojs/utils";
|
|
3
|
+
import type { ResponseCode, ResponseContract } from "../../core/response";
|
|
4
|
+
import type { EntrypointKey } from "./types";
|
|
5
|
+
export interface EndpointRouteResult {
|
|
6
|
+
code: ResponseCode;
|
|
7
|
+
information: string;
|
|
8
|
+
body: DP.DataParser;
|
|
9
|
+
}
|
|
10
|
+
export type EntrypointReduceResult = Record<EntrypointKey, DP.DataParser | Record<string, DP.DataParser>>;
|
|
11
|
+
export interface AggregateStepsResult {
|
|
12
|
+
entrypointContract: EntrypointReduceResult;
|
|
13
|
+
endpointContract: EndpointRouteResult[];
|
|
14
|
+
}
|
|
15
|
+
export interface AggregateStepsParams {
|
|
16
|
+
readonly defaultExtractContract: ResponseContract.Contract;
|
|
17
|
+
}
|
|
18
|
+
export declare function aggregateStepContract(steps: readonly Steps[], params: AggregateStepsParams): AggregateStepsResult;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import '../../core/steps/index.mjs';
|
|
2
|
+
import { pipe, A, O, DP, P, hasSomeKinds } from '@duplojs/utils';
|
|
3
|
+
import { processStepKind } from '../../core/steps/process.mjs';
|
|
4
|
+
import { extractStepKind } from '../../core/steps/extract.mjs';
|
|
5
|
+
import { presetCheckerStepKind } from '../../core/steps/presetChecker.mjs';
|
|
6
|
+
import { checkerStepKind } from '../../core/steps/checker.mjs';
|
|
7
|
+
import { cutStepKind } from '../../core/steps/cut.mjs';
|
|
8
|
+
import { handlerStepKind } from '../../core/steps/handler.mjs';
|
|
9
|
+
|
|
10
|
+
function aggregateStepContract(steps, params) {
|
|
11
|
+
const processContracts = pipe(steps, A.filter(processStepKind.has), A.map((element) => aggregateStepContract(element.definition.process.definition.steps, params)), O.to({
|
|
12
|
+
entrypointContract: A.map((result) => result.entrypointContract),
|
|
13
|
+
endpointContract: A.flatMap((result) => result.endpointContract),
|
|
14
|
+
}));
|
|
15
|
+
const entrypointContract = pipe(steps, A.filter(extractStepKind.has), A.map((extractStep) => extractStep.definition.shape), A.concat(processContracts.entrypointContract), A.reduce(A.reduceFrom({
|
|
16
|
+
body: {},
|
|
17
|
+
headers: {},
|
|
18
|
+
params: {},
|
|
19
|
+
query: {},
|
|
20
|
+
}), ({ element: shape, lastValue, nextWithObject }) => pipe(lastValue, O.entries, A.map(([key, accumulatorValue]) => {
|
|
21
|
+
const currentExtractDataParser = shape[key];
|
|
22
|
+
if (DP.dataParserKind.has(accumulatorValue)
|
|
23
|
+
|| !currentExtractDataParser
|
|
24
|
+
|| (!DP.dataParserKind.has(accumulatorValue)
|
|
25
|
+
&& O.countKeys(accumulatorValue) > 1
|
|
26
|
+
&& DP.dataParserKind.has(currentExtractDataParser)
|
|
27
|
+
&& !DP.objectKind.has(currentExtractDataParser))) {
|
|
28
|
+
return O.entry(key, accumulatorValue);
|
|
29
|
+
}
|
|
30
|
+
if (!DP.dataParserKind.has(currentExtractDataParser)) {
|
|
31
|
+
return O.entry(key, {
|
|
32
|
+
...accumulatorValue,
|
|
33
|
+
...currentExtractDataParser,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
if (DP.identifier(currentExtractDataParser, DP.objectKind)) {
|
|
37
|
+
return O.entry(key, {
|
|
38
|
+
...accumulatorValue,
|
|
39
|
+
...currentExtractDataParser.definition.shape,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
return O.entry(key, currentExtractDataParser);
|
|
43
|
+
}), O.fromEntries, (object) => nextWithObject(lastValue, object))));
|
|
44
|
+
const endpointContract = pipe(steps, A.flatMap((step) => P.match(step)
|
|
45
|
+
.when(processStepKind.has, () => [])
|
|
46
|
+
.when(extractStepKind.has, ({ definition }) => definition.responseContract ?? params.defaultExtractContract)
|
|
47
|
+
.when(presetCheckerStepKind.has, ({ definition }) => definition.presetChecker.definition.responseContract)
|
|
48
|
+
.when(hasSomeKinds([
|
|
49
|
+
checkerStepKind,
|
|
50
|
+
cutStepKind,
|
|
51
|
+
handlerStepKind,
|
|
52
|
+
]), ({ definition }) => definition.responseContract)
|
|
53
|
+
.exhaustive()), A.concat(processContracts.endpointContract));
|
|
54
|
+
return {
|
|
55
|
+
entrypointContract,
|
|
56
|
+
endpointContract,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export { aggregateStepContract };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
require('@duplojs/data-parser-tools/toJsonSchema');
|
|
4
|
+
require('./types/index.cjs');
|
|
5
|
+
var plugin = require('./plugin.cjs');
|
|
6
|
+
var routeToOpenApi = require('./routeToOpenApi.cjs');
|
|
7
|
+
var aggregateStepContract = require('./aggregateStepContract.cjs');
|
|
8
|
+
var makeOpenApiRoute = require('./makeOpenApiRoute.cjs');
|
|
9
|
+
var makeOpenApiPage = require('./makeOpenApiPage.cjs');
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
exports.openApiGeneratorPlugin = plugin.openApiGeneratorPlugin;
|
|
14
|
+
exports.routeToOpenApi = routeToOpenApi.routeToOpenApi;
|
|
15
|
+
exports.aggregateStepContract = aggregateStepContract.aggregateStepContract;
|
|
16
|
+
exports.makeOpenApiRoute = makeOpenApiRoute.makeOpenApiRoute;
|
|
17
|
+
exports.makeOpenApiPage = makeOpenApiPage.makeOpenApiPage;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import '@duplojs/data-parser-tools/toJsonSchema';
|
|
2
|
+
import './types/index.mjs';
|
|
3
|
+
export { openApiGeneratorPlugin } from './plugin.mjs';
|
|
4
|
+
export { routeToOpenApi } from './routeToOpenApi.mjs';
|
|
5
|
+
export { aggregateStepContract } from './aggregateStepContract.mjs';
|
|
6
|
+
export { makeOpenApiRoute } from './makeOpenApiRoute.mjs';
|
|
7
|
+
export { makeOpenApiPage } from './makeOpenApiPage.mjs';
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function makeOpenApiPage(params) {
|
|
4
|
+
return /* html */ `
|
|
5
|
+
<!DOCTYPE html>
|
|
6
|
+
<html lang="en">
|
|
7
|
+
<head>
|
|
8
|
+
<meta charset="utf-8" />
|
|
9
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
10
|
+
<meta name="description" content="SwaggerUI"/>
|
|
11
|
+
<title>${params.pageTitle}</title>
|
|
12
|
+
<link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist@${params.swaggerUiVersion}/swagger-ui.css" />
|
|
13
|
+
<script src="https://unpkg.com/swagger-ui-dist@${params.swaggerUiVersion}/swagger-ui-bundle.js" crossorigin></script>
|
|
14
|
+
</head>
|
|
15
|
+
<body>
|
|
16
|
+
<div id="swagger-ui"></div>
|
|
17
|
+
<script>
|
|
18
|
+
window.onload = () => {
|
|
19
|
+
window.ui = SwaggerUIBundle({
|
|
20
|
+
spec: ${params.openApiDocument},
|
|
21
|
+
dom_id: "#swagger-ui",
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
</script>
|
|
25
|
+
</body>
|
|
26
|
+
</html>
|
|
27
|
+
`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
exports.makeOpenApiPage = makeOpenApiPage;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
function makeOpenApiPage(params) {
|
|
2
|
+
return /* html */ `
|
|
3
|
+
<!DOCTYPE html>
|
|
4
|
+
<html lang="en">
|
|
5
|
+
<head>
|
|
6
|
+
<meta charset="utf-8" />
|
|
7
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
8
|
+
<meta name="description" content="SwaggerUI"/>
|
|
9
|
+
<title>${params.pageTitle}</title>
|
|
10
|
+
<link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist@${params.swaggerUiVersion}/swagger-ui.css" />
|
|
11
|
+
<script src="https://unpkg.com/swagger-ui-dist@${params.swaggerUiVersion}/swagger-ui-bundle.js" crossorigin></script>
|
|
12
|
+
</head>
|
|
13
|
+
<body>
|
|
14
|
+
<div id="swagger-ui"></div>
|
|
15
|
+
<script>
|
|
16
|
+
window.onload = () => {
|
|
17
|
+
window.ui = SwaggerUIBundle({
|
|
18
|
+
spec: ${params.openApiDocument},
|
|
19
|
+
dom_id: "#swagger-ui",
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
</script>
|
|
23
|
+
</body>
|
|
24
|
+
</html>
|
|
25
|
+
`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { makeOpenApiPage };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
require('../../core/builders/index.cjs');
|
|
4
|
+
require('../../core/response/index.cjs');
|
|
5
|
+
var utils = require('@duplojs/utils');
|
|
6
|
+
var builder = require('../../core/builders/route/builder.cjs');
|
|
7
|
+
var contract = require('../../core/response/contract.cjs');
|
|
8
|
+
|
|
9
|
+
function makeOpenApiRoute(routePath, openApiPage) {
|
|
10
|
+
return builder.useRouteBuilder("GET", routePath)
|
|
11
|
+
.handler(contract.ResponseContract.ok("swaggerUi", utils.DP.string()), (__, { response }) => response("swaggerUi", openApiPage)
|
|
12
|
+
.setHeader("content-type", "text/html"));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
exports.makeOpenApiRoute = makeOpenApiRoute;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ResponseContract } from "../../core/response";
|
|
2
|
+
import type { RoutePath } from "../../core/route";
|
|
3
|
+
import { DP } from "@duplojs/utils";
|
|
4
|
+
export declare function makeOpenApiRoute(routePath: RoutePath, openApiPage: string): import("../../core/route").Route<{
|
|
5
|
+
readonly method: "GET";
|
|
6
|
+
readonly hooks: readonly [];
|
|
7
|
+
readonly preflightSteps: readonly [];
|
|
8
|
+
readonly paths: readonly [`/${string}`];
|
|
9
|
+
readonly steps: readonly [import("../../core/steps").HandlerStep<{
|
|
10
|
+
readonly responseContract: NoInfer<ResponseContract.Contract<"200", "swaggerUi", DP.DataParserString<{
|
|
11
|
+
readonly errorMessage?: string | undefined;
|
|
12
|
+
readonly identifier?: string | undefined;
|
|
13
|
+
readonly coerce: boolean;
|
|
14
|
+
readonly checkers: readonly [];
|
|
15
|
+
}>>>;
|
|
16
|
+
theFunction(floor: {}, param: import("../../core/steps").HandlerStepFunctionParams<import("../../core/request").Request, import("../../core/response").PredictedResponse<"200", "swaggerUi", string>>): import("@duplojs/utils").MaybePromise<import("../../core/response").PredictedResponse<"200", "swaggerUi", string>>;
|
|
17
|
+
}>];
|
|
18
|
+
}>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import '../../core/builders/index.mjs';
|
|
2
|
+
import '../../core/response/index.mjs';
|
|
3
|
+
import { DP } from '@duplojs/utils';
|
|
4
|
+
import { useRouteBuilder } from '../../core/builders/route/builder.mjs';
|
|
5
|
+
import { ResponseContract } from '../../core/response/contract.mjs';
|
|
6
|
+
|
|
7
|
+
function makeOpenApiRoute(routePath, openApiPage) {
|
|
8
|
+
return useRouteBuilder("GET", routePath)
|
|
9
|
+
.handler(ResponseContract.ok("swaggerUi", DP.string()), (__, { response }) => response("swaggerUi", openApiPage)
|
|
10
|
+
.setHeader("content-type", "text/html"));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { makeOpenApiRoute };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var routeToOpenApi = require('./routeToOpenApi.cjs');
|
|
4
|
+
var utils = require('@duplojs/utils');
|
|
5
|
+
var makeOpenApiPage = require('./makeOpenApiPage.cjs');
|
|
6
|
+
var makeOpenApiRoute = require('./makeOpenApiRoute.cjs');
|
|
7
|
+
var promises = require('fs/promises');
|
|
8
|
+
|
|
9
|
+
function openApiGeneratorPlugin(pluginParams) {
|
|
10
|
+
return () => ({
|
|
11
|
+
name: "open-api-generator",
|
|
12
|
+
hooksHubLifeCycle: [
|
|
13
|
+
{
|
|
14
|
+
beforeServerBuildRoutes: async (hub) => {
|
|
15
|
+
const contextToJsonSchemaFactory = new Map();
|
|
16
|
+
const resultSchemaContext = new Map();
|
|
17
|
+
const routes = hub.aggregatesRoutes();
|
|
18
|
+
const openApiRoutes = utils.pipe(routes, utils.A.filter((route) => route.definition.method !== "OPTIONS"), utils.A.flatMap((route) => routeToOpenApi.routeToOpenApi(route, {
|
|
19
|
+
defaultExtractContract: hub.defaultExtractContract,
|
|
20
|
+
resultSchemaContext,
|
|
21
|
+
contextToJsonSchemaFactory,
|
|
22
|
+
})));
|
|
23
|
+
if (!utils.A.minElements(openApiRoutes, 1)) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const paths = utils.pipe(openApiRoutes, utils.A.group((element, { output }) => output(element.path, element)), utils.O.entries, utils.A.filter((entry) => entry[1] !== undefined), utils.A.map(([path, value]) => utils.pipe(value, utils.A.group(({ method, path, ...rest }, { output }) => output(method, rest)), utils.O.entries, utils.A.filter((entry) => entry[1] !== undefined), utils.A.map(([method, value]) => utils.O.entry(method, utils.A.first(value))), utils.O.fromEntries, (value) => utils.O.entry(path, value))), utils.O.fromEntries);
|
|
27
|
+
const schemaComponents = utils.G.reduce(resultSchemaContext.values(), utils.G.reduceFrom({}), ({ lastValue, element, nextWithObject }) => nextWithObject(lastValue, element));
|
|
28
|
+
const securityScheme = utils.P.match(pluginParams.security)
|
|
29
|
+
.with({ type: "bearer" }, (security) => ({
|
|
30
|
+
type: "http",
|
|
31
|
+
scheme: "bearer",
|
|
32
|
+
bearerFormat: security.bearerFormat ?? "JWT",
|
|
33
|
+
}))
|
|
34
|
+
.with({ type: "basic" }, utils.justReturn({
|
|
35
|
+
type: "http",
|
|
36
|
+
scheme: "basic",
|
|
37
|
+
}))
|
|
38
|
+
.with({ type: "apiKey" }, (security) => ({
|
|
39
|
+
type: "apiKey",
|
|
40
|
+
name: security.paramName,
|
|
41
|
+
in: security.in,
|
|
42
|
+
}))
|
|
43
|
+
.otherwise(utils.justReturn(undefined));
|
|
44
|
+
const securitySchemeName = "auth";
|
|
45
|
+
const securitySchemes = securityScheme
|
|
46
|
+
? {
|
|
47
|
+
[securitySchemeName]: securityScheme,
|
|
48
|
+
}
|
|
49
|
+
: undefined;
|
|
50
|
+
const openApiDocument = {
|
|
51
|
+
openapi: "3.1.0",
|
|
52
|
+
info: {
|
|
53
|
+
title: pluginParams.title ?? "Swagger API",
|
|
54
|
+
version: pluginParams.version ?? "0.0.0",
|
|
55
|
+
summary: pluginParams.summary,
|
|
56
|
+
contact: pluginParams.contact,
|
|
57
|
+
license: pluginParams.license,
|
|
58
|
+
},
|
|
59
|
+
servers: pluginParams.servers,
|
|
60
|
+
paths,
|
|
61
|
+
components: {
|
|
62
|
+
schemas: schemaComponents,
|
|
63
|
+
securitySchemes,
|
|
64
|
+
},
|
|
65
|
+
security: pluginParams.security
|
|
66
|
+
? [
|
|
67
|
+
{
|
|
68
|
+
[securitySchemeName]: [],
|
|
69
|
+
},
|
|
70
|
+
]
|
|
71
|
+
: undefined,
|
|
72
|
+
};
|
|
73
|
+
const openApiDocumentString = JSON.stringify(openApiDocument, null, 2);
|
|
74
|
+
if (pluginParams.outputFilePath) {
|
|
75
|
+
await promises.writeFile(pluginParams.outputFilePath, openApiDocumentString);
|
|
76
|
+
}
|
|
77
|
+
const openApiPage = makeOpenApiPage.makeOpenApiPage({
|
|
78
|
+
openApiDocument: openApiDocumentString,
|
|
79
|
+
pageTitle: pluginParams.title ?? "Swagger API",
|
|
80
|
+
swaggerUiVersion: pluginParams.swaggerUiVersion ?? "5.31.0",
|
|
81
|
+
});
|
|
82
|
+
const openApiRoute = makeOpenApiRoute.makeOpenApiRoute(pluginParams.routePath, openApiPage);
|
|
83
|
+
return hub.register(openApiRoute);
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
exports.openApiGeneratorPlugin = openApiGeneratorPlugin;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { HubPlugin } from "../../core/hub";
|
|
2
|
+
import type { RoutePath } from "../../core/route";
|
|
3
|
+
import type { SupportedBearerFormat } from "./types";
|
|
4
|
+
interface OpenApiSecurityOptionBearer {
|
|
5
|
+
type: "bearer";
|
|
6
|
+
bearerFormat?: SupportedBearerFormat;
|
|
7
|
+
}
|
|
8
|
+
interface OpenApiSecurityOptionApiKey {
|
|
9
|
+
type: "apiKey";
|
|
10
|
+
paramName: string;
|
|
11
|
+
in: "header" | "query" | "cookie";
|
|
12
|
+
}
|
|
13
|
+
interface OpenApiSecurityOptionBasic {
|
|
14
|
+
type: "basic";
|
|
15
|
+
}
|
|
16
|
+
export interface OpenApiGeneratorPluginParams {
|
|
17
|
+
routePath: RoutePath;
|
|
18
|
+
outputFilePath?: string;
|
|
19
|
+
/**
|
|
20
|
+
* @default "Swagger API"
|
|
21
|
+
*/
|
|
22
|
+
title?: string;
|
|
23
|
+
/**
|
|
24
|
+
* @default "0.0.0"
|
|
25
|
+
*/
|
|
26
|
+
version?: string;
|
|
27
|
+
summary?: string;
|
|
28
|
+
contact?: {
|
|
29
|
+
name?: string;
|
|
30
|
+
email?: string;
|
|
31
|
+
url?: string;
|
|
32
|
+
};
|
|
33
|
+
license?: {
|
|
34
|
+
name: string;
|
|
35
|
+
url?: string;
|
|
36
|
+
identifier?: string;
|
|
37
|
+
};
|
|
38
|
+
security?: OpenApiSecurityOptionBearer | OpenApiSecurityOptionApiKey | OpenApiSecurityOptionBasic;
|
|
39
|
+
servers?: {
|
|
40
|
+
url: string;
|
|
41
|
+
description?: string;
|
|
42
|
+
}[];
|
|
43
|
+
/**
|
|
44
|
+
* @default "5.31.0"
|
|
45
|
+
*/
|
|
46
|
+
swaggerUiVersion?: string;
|
|
47
|
+
}
|
|
48
|
+
export declare function openApiGeneratorPlugin(pluginParams: OpenApiGeneratorPluginParams): () => HubPlugin;
|
|
49
|
+
export {};
|