@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
package/dist/core/hub/index.cjs
CHANGED
|
@@ -1,146 +1,119 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var kind = require('../kind.cjs');
|
|
4
|
-
var index = require('../route/index.cjs');
|
|
4
|
+
var index$1 = require('../route/index.cjs');
|
|
5
5
|
var utils = require('@duplojs/utils');
|
|
6
6
|
require('../steps/index.cjs');
|
|
7
|
-
var
|
|
7
|
+
var index = require('../request/index.cjs');
|
|
8
8
|
var defaultNotfoundHandler = require('./defaultNotfoundHandler.cjs');
|
|
9
9
|
var defaultExtractContract = require('./defaultExtractContract.cjs');
|
|
10
|
+
var defaultBodyController = require('./defaultBodyController.cjs');
|
|
10
11
|
var hooks = require('./hooks.cjs');
|
|
11
12
|
var handler = require('../steps/handler.cjs');
|
|
12
13
|
|
|
13
14
|
const hubKind = kind.createCoreLibKind("hub");
|
|
15
|
+
class Hub extends utils.kindHeritage("hub", kind.createCoreLibKind("hub")) {
|
|
16
|
+
config;
|
|
17
|
+
plugins = [];
|
|
18
|
+
hooksRouteLifeCycle = [];
|
|
19
|
+
hooksHubLifeCycle = [];
|
|
20
|
+
routes = new Set();
|
|
21
|
+
routeFunctionBuilders = [];
|
|
22
|
+
stepFunctionBuilders = [];
|
|
23
|
+
bodyReaderImplementations = [];
|
|
24
|
+
classRequest = index.Request;
|
|
25
|
+
notfoundHandler = defaultNotfoundHandler.defaultNotfoundHandler;
|
|
26
|
+
defaultExtractContract = defaultExtractContract.defaultExtractContract;
|
|
27
|
+
defaultBodyController = defaultBodyController.defaultBodyController;
|
|
28
|
+
constructor(config) {
|
|
29
|
+
super({});
|
|
30
|
+
this.config = config;
|
|
31
|
+
}
|
|
32
|
+
register(routes) {
|
|
33
|
+
utils.pipe(routes, utils.P.when(index$1.routeKind.has, utils.A.coalescing), utils.P.when(utils.isType("iterable"), utils.A.from), utils.P.otherwise(utils.O.values), utils.A.map((route) => this.routes.add(route)));
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
addRouteFunctionBuilder(functionBuilder) {
|
|
37
|
+
this.routeFunctionBuilders.push(...utils.A.coalescing(functionBuilder));
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
addStepFunctionBuilder(functionBuilder) {
|
|
41
|
+
this.stepFunctionBuilders.push(...utils.A.coalescing(functionBuilder));
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
addRouteHooks(hook) {
|
|
45
|
+
this.hooksRouteLifeCycle.push(...utils.A.coalescing(hook));
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
addHubHooks(hook) {
|
|
49
|
+
this.hooksHubLifeCycle.push(...utils.A.coalescing(hook));
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
addBodyReaderImplementation(bodyReaderImplementation) {
|
|
53
|
+
this.bodyReaderImplementations.push(...utils.A.coalescing(bodyReaderImplementation));
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
plug(plugin) {
|
|
57
|
+
const pluginResult = typeof plugin === "function"
|
|
58
|
+
? plugin(this)
|
|
59
|
+
: plugin;
|
|
60
|
+
if (pluginResult.bodyReaderImplementations) {
|
|
61
|
+
this.addBodyReaderImplementation(pluginResult.bodyReaderImplementations);
|
|
62
|
+
}
|
|
63
|
+
if (pluginResult.hooksHubLifeCycle) {
|
|
64
|
+
this.addHubHooks(pluginResult.hooksHubLifeCycle);
|
|
65
|
+
}
|
|
66
|
+
if (pluginResult.hooksRouteLifeCycle) {
|
|
67
|
+
this.addRouteHooks(pluginResult.hooksRouteLifeCycle);
|
|
68
|
+
}
|
|
69
|
+
if (pluginResult.routeFunctionBuilders) {
|
|
70
|
+
this.addRouteFunctionBuilder(pluginResult.routeFunctionBuilders);
|
|
71
|
+
}
|
|
72
|
+
if (pluginResult.routes) {
|
|
73
|
+
this.register(pluginResult.routes);
|
|
74
|
+
}
|
|
75
|
+
if (pluginResult.stepFunctionBuilders) {
|
|
76
|
+
this.addStepFunctionBuilder(pluginResult.stepFunctionBuilders);
|
|
77
|
+
}
|
|
78
|
+
this.plugins.push(pluginResult);
|
|
79
|
+
return this;
|
|
80
|
+
}
|
|
81
|
+
setNotfoundHandler(responseContract, theFunction) {
|
|
82
|
+
this.notfoundHandler = handler.createHandlerStep({
|
|
83
|
+
responseContract,
|
|
84
|
+
theFunction: (floor, params) => theFunction(params),
|
|
85
|
+
metadata: [],
|
|
86
|
+
});
|
|
87
|
+
return this;
|
|
88
|
+
}
|
|
89
|
+
setDefaultExtractContract(responseContract) {
|
|
90
|
+
this.defaultExtractContract = responseContract;
|
|
91
|
+
return this;
|
|
92
|
+
}
|
|
93
|
+
aggregatesHooksHubLifeCycle(hookName) {
|
|
94
|
+
return utils.A.flatMap(this.hooksHubLifeCycle, (hooks) => hooks[hookName] ?? []);
|
|
95
|
+
}
|
|
96
|
+
setDefaultBodyController(bodyController) {
|
|
97
|
+
this.defaultBodyController = bodyController;
|
|
98
|
+
return this;
|
|
99
|
+
}
|
|
100
|
+
aggregatesHooksRouteLifeCycle(hookName) {
|
|
101
|
+
return utils.A.flatMap(this.hooksRouteLifeCycle, (hooks) => hooks[hookName] ?? []);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* @internal
|
|
105
|
+
*/
|
|
106
|
+
static "new"(config) {
|
|
107
|
+
return new Hub(config);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
14
110
|
function createHub(config) {
|
|
15
|
-
return
|
|
16
|
-
...hubKind.addTo({}),
|
|
17
|
-
config,
|
|
18
|
-
plugins: [],
|
|
19
|
-
hooksHubLifeCycle: [],
|
|
20
|
-
hooksRouteLifeCycle: [],
|
|
21
|
-
routeFunctionBuilders: [],
|
|
22
|
-
routes: [],
|
|
23
|
-
stepFunctionBuilders: [],
|
|
24
|
-
notfoundHandler: defaultNotfoundHandler.defaultNotfoundHandler,
|
|
25
|
-
defaultExtractContract: defaultExtractContract.defaultExtractContract,
|
|
26
|
-
classRequest: request.Request,
|
|
27
|
-
addHubHooks(hook) {
|
|
28
|
-
return {
|
|
29
|
-
...this,
|
|
30
|
-
hooksHubLifeCycle: utils.A.concat(this.hooksHubLifeCycle, utils.A.coalescing(hook)),
|
|
31
|
-
};
|
|
32
|
-
},
|
|
33
|
-
addRouteFunctionBuilder(functionBuilder) {
|
|
34
|
-
return {
|
|
35
|
-
...this,
|
|
36
|
-
routeFunctionBuilders: utils.A.concat(this.routeFunctionBuilders, utils.A.coalescing(functionBuilder)),
|
|
37
|
-
};
|
|
38
|
-
},
|
|
39
|
-
addRouteHooks(hook) {
|
|
40
|
-
return {
|
|
41
|
-
...this,
|
|
42
|
-
hooksRouteLifeCycle: utils.A.concat(this.hooksRouteLifeCycle, utils.A.coalescing(hook)),
|
|
43
|
-
};
|
|
44
|
-
},
|
|
45
|
-
addStepFunctionBuilder(hook) {
|
|
46
|
-
return {
|
|
47
|
-
...this,
|
|
48
|
-
stepFunctionBuilders: utils.A.concat(this.stepFunctionBuilders, utils.A.coalescing(hook)),
|
|
49
|
-
};
|
|
50
|
-
},
|
|
51
|
-
plug(plugin) {
|
|
52
|
-
return {
|
|
53
|
-
...this,
|
|
54
|
-
plugins: utils.A.push(this.plugins, typeof plugin === "function"
|
|
55
|
-
? plugin(this)
|
|
56
|
-
: plugin),
|
|
57
|
-
};
|
|
58
|
-
},
|
|
59
|
-
register(route) {
|
|
60
|
-
return {
|
|
61
|
-
...this,
|
|
62
|
-
routes: utils.A.concat(this.routes, utils.pipe(route, utils.P.when(index.routeKind.has, utils.A.coalescing), utils.P.when(utils.isType("iterable"), utils.A.from), utils.P.otherwise(utils.O.values), utils.A.filter((route) => !utils.A.includes(this.routes, route)))),
|
|
63
|
-
};
|
|
64
|
-
},
|
|
65
|
-
setDefaultExtractContract(defaultExtractContract) {
|
|
66
|
-
return {
|
|
67
|
-
...this,
|
|
68
|
-
defaultExtractContract,
|
|
69
|
-
};
|
|
70
|
-
},
|
|
71
|
-
setNotfoundHandler(responseContract, theFunction) {
|
|
72
|
-
return {
|
|
73
|
-
...this,
|
|
74
|
-
notfoundHandler: handler.createHandlerStep({
|
|
75
|
-
responseContract,
|
|
76
|
-
theFunction: (floor, params) => theFunction(params),
|
|
77
|
-
metadata: [],
|
|
78
|
-
}),
|
|
79
|
-
};
|
|
80
|
-
},
|
|
81
|
-
aggregates() {
|
|
82
|
-
return utils.A.reduce(this.plugins, utils.A.reduceFrom({
|
|
83
|
-
hooksRouteLifeCycle: this.hooksRouteLifeCycle,
|
|
84
|
-
routeFunctionBuilders: this.routeFunctionBuilders,
|
|
85
|
-
stepFunctionBuilders: this.stepFunctionBuilders,
|
|
86
|
-
routes: this.routes,
|
|
87
|
-
hooksHubLifeCycle: this.hooksHubLifeCycle,
|
|
88
|
-
}), ({ lastValue, element: plugin, next, }) => next({
|
|
89
|
-
hooksRouteLifeCycle: plugin.hooksRouteLifeCycle
|
|
90
|
-
? utils.A.concat(lastValue.hooksRouteLifeCycle, plugin.hooksRouteLifeCycle)
|
|
91
|
-
: lastValue.hooksRouteLifeCycle,
|
|
92
|
-
routeFunctionBuilders: plugin.routeFunctionBuilders
|
|
93
|
-
? utils.A.concat(lastValue.routeFunctionBuilders, plugin.routeFunctionBuilders)
|
|
94
|
-
: lastValue.routeFunctionBuilders,
|
|
95
|
-
stepFunctionBuilders: plugin.stepFunctionBuilders
|
|
96
|
-
? utils.A.concat(lastValue.stepFunctionBuilders, plugin.stepFunctionBuilders)
|
|
97
|
-
: lastValue.stepFunctionBuilders,
|
|
98
|
-
routes: plugin.routes
|
|
99
|
-
? utils.A.concat(lastValue.routes, plugin.routes)
|
|
100
|
-
: lastValue.routes,
|
|
101
|
-
hooksHubLifeCycle: plugin.hooksHubLifeCycle
|
|
102
|
-
? utils.A.concat(lastValue.hooksHubLifeCycle, plugin.hooksHubLifeCycle)
|
|
103
|
-
: lastValue.hooksHubLifeCycle,
|
|
104
|
-
}));
|
|
105
|
-
},
|
|
106
|
-
aggregatesRoutes() {
|
|
107
|
-
return utils.A.reduce(this.plugins, utils.A.reduceFrom(this.routes), ({ lastValue, element: { routes }, next, }) => routes
|
|
108
|
-
? next(utils.A.concat(lastValue, routes))
|
|
109
|
-
: next(lastValue));
|
|
110
|
-
},
|
|
111
|
-
aggregatesRouteFunctionBuilders() {
|
|
112
|
-
return utils.A.reduce(this.plugins, utils.A.reduceFrom(this.routeFunctionBuilders), ({ lastValue, element: { routeFunctionBuilders }, next, }) => routeFunctionBuilders
|
|
113
|
-
? next(utils.A.concat(lastValue, routeFunctionBuilders))
|
|
114
|
-
: next(lastValue));
|
|
115
|
-
},
|
|
116
|
-
aggregatesStepFunctionBuilders() {
|
|
117
|
-
return utils.A.reduce(this.plugins, utils.A.reduceFrom(this.stepFunctionBuilders), ({ lastValue, element: { stepFunctionBuilders }, next, }) => stepFunctionBuilders
|
|
118
|
-
? next(utils.A.concat(lastValue, stepFunctionBuilders))
|
|
119
|
-
: next(lastValue));
|
|
120
|
-
},
|
|
121
|
-
aggregatesHooksHubLifeCycle(hookName) {
|
|
122
|
-
const hooks = utils.A.flatMap(this.hooksHubLifeCycle, (hooks) => hooks[hookName] ?? []);
|
|
123
|
-
return utils.A.reduce(this.plugins, utils.A.reduceFrom(hooks), ({ lastValue, element: { hooksHubLifeCycle }, next, }) => {
|
|
124
|
-
if (!hooksHubLifeCycle) {
|
|
125
|
-
return next(lastValue);
|
|
126
|
-
}
|
|
127
|
-
return next(utils.A.concat(lastValue, utils.A.flatMap(hooksHubLifeCycle, (hooks) => hooks[hookName] ?? [])));
|
|
128
|
-
});
|
|
129
|
-
},
|
|
130
|
-
aggregatesHooksRouteLifeCycle(hookName) {
|
|
131
|
-
const hooks = utils.A.flatMap(this.hooksRouteLifeCycle, (hooks) => hooks[hookName] ?? []);
|
|
132
|
-
return utils.A.reduce(this.plugins, utils.A.reduceFrom(hooks), ({ lastValue, element: { hooksRouteLifeCycle }, next, }) => {
|
|
133
|
-
if (!hooksRouteLifeCycle) {
|
|
134
|
-
return next(lastValue);
|
|
135
|
-
}
|
|
136
|
-
return next(utils.A.concat(lastValue, utils.A.flatMap(hooksRouteLifeCycle, (hooks) => hooks[hookName] ?? [])));
|
|
137
|
-
});
|
|
138
|
-
},
|
|
139
|
-
};
|
|
111
|
+
return Hub.new(config);
|
|
140
112
|
}
|
|
141
113
|
|
|
142
114
|
exports.defaultNotfoundHandler = defaultNotfoundHandler.defaultNotfoundHandler;
|
|
143
115
|
exports.defaultExtractContract = defaultExtractContract.defaultExtractContract;
|
|
116
|
+
exports.defaultBodyController = defaultBodyController.defaultBodyController;
|
|
144
117
|
exports.createHookHubLifeCycle = hooks.createHookHubLifeCycle;
|
|
145
118
|
exports.hookServerExitKind = hooks.hookServerExitKind;
|
|
146
119
|
exports.hookServerNextKind = hooks.hookServerNextKind;
|
|
@@ -149,5 +122,6 @@ exports.launchHookServer = hooks.launchHookServer;
|
|
|
149
122
|
exports.launchHookServerError = hooks.launchHookServerError;
|
|
150
123
|
exports.serverErrorExitHookFunction = hooks.serverErrorExitHookFunction;
|
|
151
124
|
exports.serverErrorNextHookFunction = hooks.serverErrorNextHookFunction;
|
|
125
|
+
exports.Hub = Hub;
|
|
152
126
|
exports.createHub = createHub;
|
|
153
127
|
exports.hubKind = hubKind;
|
package/dist/core/hub/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type Route, type HookRouteLifeCycle } from "../route";
|
|
2
|
-
import { type
|
|
2
|
+
import { type MaybeArray, type MaybePromise, type DP } from "@duplojs/utils";
|
|
3
3
|
import { type HookHubLifeCycle } from "./hooks";
|
|
4
4
|
import { type HandlerStepFunctionParams, type HandlerStep } from "../steps";
|
|
5
|
-
import { Request } from "../request";
|
|
5
|
+
import { type BodyController, type BodyReaderImplementation, Request } from "../request";
|
|
6
6
|
import { type ClientErrorResponseCode, type ResponseContract } from "../response";
|
|
7
7
|
import { type Environment } from "../types";
|
|
8
8
|
import { type createStepFunctionBuilder } from "../functionsBuilders/steps";
|
|
@@ -10,6 +10,7 @@ import { type createRouteFunctionBuilder } from "../functionsBuilders/route";
|
|
|
10
10
|
export * from "./hooks";
|
|
11
11
|
export * from "./defaultNotfoundHandler";
|
|
12
12
|
export * from "./defaultExtractContract";
|
|
13
|
+
export * from "./defaultBodyController";
|
|
13
14
|
export declare const hubKind: import("@duplojs/utils").KindHandler<import("@duplojs/utils").KindDefinition<"@DuplojsHttpCore/hub", unknown>>;
|
|
14
15
|
export interface HubConfig {
|
|
15
16
|
readonly environment: Environment;
|
|
@@ -21,38 +22,36 @@ export interface HubPlugin {
|
|
|
21
22
|
readonly routes?: readonly Route[];
|
|
22
23
|
readonly routeFunctionBuilders?: readonly ReturnType<typeof createRouteFunctionBuilder>[];
|
|
23
24
|
readonly stepFunctionBuilders?: readonly ReturnType<typeof createStepFunctionBuilder>[];
|
|
25
|
+
readonly bodyReaderImplementations?: readonly BodyReaderImplementation[];
|
|
24
26
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
plug(plugin: HubPlugin | ((self: this) => HubPlugin)):
|
|
49
|
-
setNotfoundHandler<GenericResponseContract extends ResponseContract.Contract, GenericResponse extends ResponseContract.Convert<GenericResponseContract>>(responseContract: GenericResponseContract, theFunction: (param: HandlerStepFunctionParams<Request, GenericResponse>) => MaybePromise<GenericResponse>):
|
|
50
|
-
setDefaultExtractContract(responseContract: this["defaultExtractContract"]):
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
aggregatesStepFunctionBuilders(): readonly ReturnType<typeof createStepFunctionBuilder>[];
|
|
55
|
-
aggregatesHooksHubLifeCycle<GenericHookName extends keyof HookHubLifeCycle>(hookName: GenericHookName): readonly Exclude<HookHubLifeCycle[GenericHookName], undefined>[];
|
|
56
|
-
aggregatesHooksRouteLifeCycle<GenericHookName extends keyof HookRouteLifeCycle>(hookName: GenericHookName): readonly Exclude<HookRouteLifeCycle[GenericHookName], undefined>[];
|
|
27
|
+
declare const Hub_base: new (params?: {
|
|
28
|
+
"@DuplojsHttpCore/hub"?: unknown;
|
|
29
|
+
} | undefined) => import("@duplojs/utils").Kind<import("@duplojs/utils").KindDefinition<"@DuplojsHttpCore/hub", unknown>, unknown> & import("@duplojs/utils").Kind<import("@duplojs/utils").KindDefinition<"hub", unknown>, unknown>;
|
|
30
|
+
export declare class Hub<GenericConfig extends HubConfig = HubConfig> extends Hub_base {
|
|
31
|
+
config: GenericConfig;
|
|
32
|
+
plugins: HubPlugin[];
|
|
33
|
+
hooksRouteLifeCycle: HookRouteLifeCycle[];
|
|
34
|
+
hooksHubLifeCycle: HookHubLifeCycle[];
|
|
35
|
+
routes: Set<Route<import("../route").RouteDefinition>>;
|
|
36
|
+
routeFunctionBuilders: ReturnType<typeof createRouteFunctionBuilder>[];
|
|
37
|
+
stepFunctionBuilders: ReturnType<typeof createStepFunctionBuilder>[];
|
|
38
|
+
bodyReaderImplementations: BodyReaderImplementation[];
|
|
39
|
+
classRequest: typeof Request;
|
|
40
|
+
notfoundHandler: HandlerStep;
|
|
41
|
+
defaultExtractContract: ResponseContract.Contract<ClientErrorResponseCode, string, DP.DataParserEmpty>;
|
|
42
|
+
defaultBodyController: BodyController;
|
|
43
|
+
private constructor();
|
|
44
|
+
register(routes: Route | Iterable<Route> | Record<string, Route>): this;
|
|
45
|
+
addRouteFunctionBuilder(functionBuilder: MaybeArray<ReturnType<typeof createRouteFunctionBuilder>>): this;
|
|
46
|
+
addStepFunctionBuilder(functionBuilder: MaybeArray<ReturnType<typeof createStepFunctionBuilder>>): this;
|
|
47
|
+
addRouteHooks(hook: MaybeArray<HookRouteLifeCycle>): this;
|
|
48
|
+
addHubHooks(hook: MaybeArray<HookHubLifeCycle>): this;
|
|
49
|
+
addBodyReaderImplementation(bodyReaderImplementation: MaybeArray<BodyReaderImplementation>): this;
|
|
50
|
+
plug(plugin: HubPlugin | ((self: this) => HubPlugin)): this;
|
|
51
|
+
setNotfoundHandler<GenericResponseContract extends ResponseContract.Contract, GenericResponse extends ResponseContract.Convert<GenericResponseContract>>(responseContract: GenericResponseContract, theFunction: (param: HandlerStepFunctionParams<Request, GenericResponse>) => MaybePromise<GenericResponse>): this;
|
|
52
|
+
setDefaultExtractContract(responseContract: this["defaultExtractContract"]): this;
|
|
53
|
+
aggregatesHooksHubLifeCycle<GenericHookName extends keyof HookHubLifeCycle>(hookName: GenericHookName): (NonNullable<HookHubLifeCycle[GenericHookName]> extends infer T ? T extends NonNullable<HookHubLifeCycle[GenericHookName]> ? T extends readonly (infer InnerArr)[] ? InnerArr extends readonly (infer InnerArr)[] ? InnerArr : InnerArr : T : never : never)[];
|
|
54
|
+
setDefaultBodyController(bodyController: BodyController): this;
|
|
55
|
+
aggregatesHooksRouteLifeCycle<GenericHookName extends keyof HookRouteLifeCycle>(hookName: GenericHookName): (NonNullable<HookRouteLifeCycle<Request>[GenericHookName]> extends infer T ? T extends NonNullable<HookRouteLifeCycle<Request>[GenericHookName]> ? T extends readonly (infer InnerArr)[] ? InnerArr extends readonly (infer InnerArr)[] ? InnerArr : InnerArr : T : never : never)[];
|
|
57
56
|
}
|
|
58
57
|
export declare function createHub<const GenericConfig extends HubConfig>(config: GenericConfig): Hub<GenericConfig>;
|
package/dist/core/hub/index.mjs
CHANGED
|
@@ -1,140 +1,112 @@
|
|
|
1
1
|
import { createCoreLibKind } from '../kind.mjs';
|
|
2
2
|
import { routeKind } from '../route/index.mjs';
|
|
3
|
-
import {
|
|
3
|
+
import { kindHeritage, pipe, P, A, isType, O } from '@duplojs/utils';
|
|
4
4
|
import '../steps/index.mjs';
|
|
5
|
-
import { Request } from '../request.mjs';
|
|
5
|
+
import { Request } from '../request/index.mjs';
|
|
6
6
|
import { defaultNotfoundHandler } from './defaultNotfoundHandler.mjs';
|
|
7
7
|
import { defaultExtractContract } from './defaultExtractContract.mjs';
|
|
8
|
+
import { defaultBodyController } from './defaultBodyController.mjs';
|
|
8
9
|
export { createHookHubLifeCycle, hookServerExitKind, hookServerNextKind, launchHookBeforeBuildRoute, launchHookServer, launchHookServerError, serverErrorExitHookFunction, serverErrorNextHookFunction } from './hooks.mjs';
|
|
9
10
|
import { createHandlerStep } from '../steps/handler.mjs';
|
|
10
11
|
|
|
11
12
|
const hubKind = createCoreLibKind("hub");
|
|
13
|
+
class Hub extends kindHeritage("hub", createCoreLibKind("hub")) {
|
|
14
|
+
config;
|
|
15
|
+
plugins = [];
|
|
16
|
+
hooksRouteLifeCycle = [];
|
|
17
|
+
hooksHubLifeCycle = [];
|
|
18
|
+
routes = new Set();
|
|
19
|
+
routeFunctionBuilders = [];
|
|
20
|
+
stepFunctionBuilders = [];
|
|
21
|
+
bodyReaderImplementations = [];
|
|
22
|
+
classRequest = Request;
|
|
23
|
+
notfoundHandler = defaultNotfoundHandler;
|
|
24
|
+
defaultExtractContract = defaultExtractContract;
|
|
25
|
+
defaultBodyController = defaultBodyController;
|
|
26
|
+
constructor(config) {
|
|
27
|
+
super({});
|
|
28
|
+
this.config = config;
|
|
29
|
+
}
|
|
30
|
+
register(routes) {
|
|
31
|
+
pipe(routes, P.when(routeKind.has, A.coalescing), P.when(isType("iterable"), A.from), P.otherwise(O.values), A.map((route) => this.routes.add(route)));
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
addRouteFunctionBuilder(functionBuilder) {
|
|
35
|
+
this.routeFunctionBuilders.push(...A.coalescing(functionBuilder));
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
addStepFunctionBuilder(functionBuilder) {
|
|
39
|
+
this.stepFunctionBuilders.push(...A.coalescing(functionBuilder));
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
addRouteHooks(hook) {
|
|
43
|
+
this.hooksRouteLifeCycle.push(...A.coalescing(hook));
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
addHubHooks(hook) {
|
|
47
|
+
this.hooksHubLifeCycle.push(...A.coalescing(hook));
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
addBodyReaderImplementation(bodyReaderImplementation) {
|
|
51
|
+
this.bodyReaderImplementations.push(...A.coalescing(bodyReaderImplementation));
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
plug(plugin) {
|
|
55
|
+
const pluginResult = typeof plugin === "function"
|
|
56
|
+
? plugin(this)
|
|
57
|
+
: plugin;
|
|
58
|
+
if (pluginResult.bodyReaderImplementations) {
|
|
59
|
+
this.addBodyReaderImplementation(pluginResult.bodyReaderImplementations);
|
|
60
|
+
}
|
|
61
|
+
if (pluginResult.hooksHubLifeCycle) {
|
|
62
|
+
this.addHubHooks(pluginResult.hooksHubLifeCycle);
|
|
63
|
+
}
|
|
64
|
+
if (pluginResult.hooksRouteLifeCycle) {
|
|
65
|
+
this.addRouteHooks(pluginResult.hooksRouteLifeCycle);
|
|
66
|
+
}
|
|
67
|
+
if (pluginResult.routeFunctionBuilders) {
|
|
68
|
+
this.addRouteFunctionBuilder(pluginResult.routeFunctionBuilders);
|
|
69
|
+
}
|
|
70
|
+
if (pluginResult.routes) {
|
|
71
|
+
this.register(pluginResult.routes);
|
|
72
|
+
}
|
|
73
|
+
if (pluginResult.stepFunctionBuilders) {
|
|
74
|
+
this.addStepFunctionBuilder(pluginResult.stepFunctionBuilders);
|
|
75
|
+
}
|
|
76
|
+
this.plugins.push(pluginResult);
|
|
77
|
+
return this;
|
|
78
|
+
}
|
|
79
|
+
setNotfoundHandler(responseContract, theFunction) {
|
|
80
|
+
this.notfoundHandler = createHandlerStep({
|
|
81
|
+
responseContract,
|
|
82
|
+
theFunction: (floor, params) => theFunction(params),
|
|
83
|
+
metadata: [],
|
|
84
|
+
});
|
|
85
|
+
return this;
|
|
86
|
+
}
|
|
87
|
+
setDefaultExtractContract(responseContract) {
|
|
88
|
+
this.defaultExtractContract = responseContract;
|
|
89
|
+
return this;
|
|
90
|
+
}
|
|
91
|
+
aggregatesHooksHubLifeCycle(hookName) {
|
|
92
|
+
return A.flatMap(this.hooksHubLifeCycle, (hooks) => hooks[hookName] ?? []);
|
|
93
|
+
}
|
|
94
|
+
setDefaultBodyController(bodyController) {
|
|
95
|
+
this.defaultBodyController = bodyController;
|
|
96
|
+
return this;
|
|
97
|
+
}
|
|
98
|
+
aggregatesHooksRouteLifeCycle(hookName) {
|
|
99
|
+
return A.flatMap(this.hooksRouteLifeCycle, (hooks) => hooks[hookName] ?? []);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* @internal
|
|
103
|
+
*/
|
|
104
|
+
static "new"(config) {
|
|
105
|
+
return new Hub(config);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
12
108
|
function createHub(config) {
|
|
13
|
-
return
|
|
14
|
-
...hubKind.addTo({}),
|
|
15
|
-
config,
|
|
16
|
-
plugins: [],
|
|
17
|
-
hooksHubLifeCycle: [],
|
|
18
|
-
hooksRouteLifeCycle: [],
|
|
19
|
-
routeFunctionBuilders: [],
|
|
20
|
-
routes: [],
|
|
21
|
-
stepFunctionBuilders: [],
|
|
22
|
-
notfoundHandler: defaultNotfoundHandler,
|
|
23
|
-
defaultExtractContract,
|
|
24
|
-
classRequest: Request,
|
|
25
|
-
addHubHooks(hook) {
|
|
26
|
-
return {
|
|
27
|
-
...this,
|
|
28
|
-
hooksHubLifeCycle: A.concat(this.hooksHubLifeCycle, A.coalescing(hook)),
|
|
29
|
-
};
|
|
30
|
-
},
|
|
31
|
-
addRouteFunctionBuilder(functionBuilder) {
|
|
32
|
-
return {
|
|
33
|
-
...this,
|
|
34
|
-
routeFunctionBuilders: A.concat(this.routeFunctionBuilders, A.coalescing(functionBuilder)),
|
|
35
|
-
};
|
|
36
|
-
},
|
|
37
|
-
addRouteHooks(hook) {
|
|
38
|
-
return {
|
|
39
|
-
...this,
|
|
40
|
-
hooksRouteLifeCycle: A.concat(this.hooksRouteLifeCycle, A.coalescing(hook)),
|
|
41
|
-
};
|
|
42
|
-
},
|
|
43
|
-
addStepFunctionBuilder(hook) {
|
|
44
|
-
return {
|
|
45
|
-
...this,
|
|
46
|
-
stepFunctionBuilders: A.concat(this.stepFunctionBuilders, A.coalescing(hook)),
|
|
47
|
-
};
|
|
48
|
-
},
|
|
49
|
-
plug(plugin) {
|
|
50
|
-
return {
|
|
51
|
-
...this,
|
|
52
|
-
plugins: A.push(this.plugins, typeof plugin === "function"
|
|
53
|
-
? plugin(this)
|
|
54
|
-
: plugin),
|
|
55
|
-
};
|
|
56
|
-
},
|
|
57
|
-
register(route) {
|
|
58
|
-
return {
|
|
59
|
-
...this,
|
|
60
|
-
routes: A.concat(this.routes, pipe(route, P.when(routeKind.has, A.coalescing), P.when(isType("iterable"), A.from), P.otherwise(O.values), A.filter((route) => !A.includes(this.routes, route)))),
|
|
61
|
-
};
|
|
62
|
-
},
|
|
63
|
-
setDefaultExtractContract(defaultExtractContract) {
|
|
64
|
-
return {
|
|
65
|
-
...this,
|
|
66
|
-
defaultExtractContract,
|
|
67
|
-
};
|
|
68
|
-
},
|
|
69
|
-
setNotfoundHandler(responseContract, theFunction) {
|
|
70
|
-
return {
|
|
71
|
-
...this,
|
|
72
|
-
notfoundHandler: createHandlerStep({
|
|
73
|
-
responseContract,
|
|
74
|
-
theFunction: (floor, params) => theFunction(params),
|
|
75
|
-
metadata: [],
|
|
76
|
-
}),
|
|
77
|
-
};
|
|
78
|
-
},
|
|
79
|
-
aggregates() {
|
|
80
|
-
return A.reduce(this.plugins, A.reduceFrom({
|
|
81
|
-
hooksRouteLifeCycle: this.hooksRouteLifeCycle,
|
|
82
|
-
routeFunctionBuilders: this.routeFunctionBuilders,
|
|
83
|
-
stepFunctionBuilders: this.stepFunctionBuilders,
|
|
84
|
-
routes: this.routes,
|
|
85
|
-
hooksHubLifeCycle: this.hooksHubLifeCycle,
|
|
86
|
-
}), ({ lastValue, element: plugin, next, }) => next({
|
|
87
|
-
hooksRouteLifeCycle: plugin.hooksRouteLifeCycle
|
|
88
|
-
? A.concat(lastValue.hooksRouteLifeCycle, plugin.hooksRouteLifeCycle)
|
|
89
|
-
: lastValue.hooksRouteLifeCycle,
|
|
90
|
-
routeFunctionBuilders: plugin.routeFunctionBuilders
|
|
91
|
-
? A.concat(lastValue.routeFunctionBuilders, plugin.routeFunctionBuilders)
|
|
92
|
-
: lastValue.routeFunctionBuilders,
|
|
93
|
-
stepFunctionBuilders: plugin.stepFunctionBuilders
|
|
94
|
-
? A.concat(lastValue.stepFunctionBuilders, plugin.stepFunctionBuilders)
|
|
95
|
-
: lastValue.stepFunctionBuilders,
|
|
96
|
-
routes: plugin.routes
|
|
97
|
-
? A.concat(lastValue.routes, plugin.routes)
|
|
98
|
-
: lastValue.routes,
|
|
99
|
-
hooksHubLifeCycle: plugin.hooksHubLifeCycle
|
|
100
|
-
? A.concat(lastValue.hooksHubLifeCycle, plugin.hooksHubLifeCycle)
|
|
101
|
-
: lastValue.hooksHubLifeCycle,
|
|
102
|
-
}));
|
|
103
|
-
},
|
|
104
|
-
aggregatesRoutes() {
|
|
105
|
-
return A.reduce(this.plugins, A.reduceFrom(this.routes), ({ lastValue, element: { routes }, next, }) => routes
|
|
106
|
-
? next(A.concat(lastValue, routes))
|
|
107
|
-
: next(lastValue));
|
|
108
|
-
},
|
|
109
|
-
aggregatesRouteFunctionBuilders() {
|
|
110
|
-
return A.reduce(this.plugins, A.reduceFrom(this.routeFunctionBuilders), ({ lastValue, element: { routeFunctionBuilders }, next, }) => routeFunctionBuilders
|
|
111
|
-
? next(A.concat(lastValue, routeFunctionBuilders))
|
|
112
|
-
: next(lastValue));
|
|
113
|
-
},
|
|
114
|
-
aggregatesStepFunctionBuilders() {
|
|
115
|
-
return A.reduce(this.plugins, A.reduceFrom(this.stepFunctionBuilders), ({ lastValue, element: { stepFunctionBuilders }, next, }) => stepFunctionBuilders
|
|
116
|
-
? next(A.concat(lastValue, stepFunctionBuilders))
|
|
117
|
-
: next(lastValue));
|
|
118
|
-
},
|
|
119
|
-
aggregatesHooksHubLifeCycle(hookName) {
|
|
120
|
-
const hooks = A.flatMap(this.hooksHubLifeCycle, (hooks) => hooks[hookName] ?? []);
|
|
121
|
-
return A.reduce(this.plugins, A.reduceFrom(hooks), ({ lastValue, element: { hooksHubLifeCycle }, next, }) => {
|
|
122
|
-
if (!hooksHubLifeCycle) {
|
|
123
|
-
return next(lastValue);
|
|
124
|
-
}
|
|
125
|
-
return next(A.concat(lastValue, A.flatMap(hooksHubLifeCycle, (hooks) => hooks[hookName] ?? [])));
|
|
126
|
-
});
|
|
127
|
-
},
|
|
128
|
-
aggregatesHooksRouteLifeCycle(hookName) {
|
|
129
|
-
const hooks = A.flatMap(this.hooksRouteLifeCycle, (hooks) => hooks[hookName] ?? []);
|
|
130
|
-
return A.reduce(this.plugins, A.reduceFrom(hooks), ({ lastValue, element: { hooksRouteLifeCycle }, next, }) => {
|
|
131
|
-
if (!hooksRouteLifeCycle) {
|
|
132
|
-
return next(lastValue);
|
|
133
|
-
}
|
|
134
|
-
return next(A.concat(lastValue, A.flatMap(hooksRouteLifeCycle, (hooks) => hooks[hookName] ?? [])));
|
|
135
|
-
});
|
|
136
|
-
},
|
|
137
|
-
};
|
|
109
|
+
return Hub.new(config);
|
|
138
110
|
}
|
|
139
111
|
|
|
140
|
-
export { createHub, defaultExtractContract, defaultNotfoundHandler, hubKind };
|
|
112
|
+
export { Hub, createHub, defaultBodyController, defaultExtractContract, defaultNotfoundHandler, hubKind };
|
|
@@ -6,10 +6,10 @@ var utils = require('@duplojs/utils');
|
|
|
6
6
|
var hooks = require('./hub/hooks.cjs');
|
|
7
7
|
|
|
8
8
|
async function implementHttpServer(params, initHttpServer) {
|
|
9
|
-
|
|
10
|
-
const router = await index.buildRouter(
|
|
11
|
-
|
|
12
|
-
const serverErrorHooks =
|
|
9
|
+
await hooks.launchHookServer(params.hub.aggregatesHooksHubLifeCycle("beforeServerBuildRoutes"), params.hub, params.httpServerParams);
|
|
10
|
+
const router = await index.buildRouter(params.hub);
|
|
11
|
+
await hooks.launchHookServer(params.hub.aggregatesHooksHubLifeCycle("beforeStartServer"), params.hub, params.httpServerParams);
|
|
12
|
+
const serverErrorHooks = params.hub.aggregatesHooksHubLifeCycle("serverError");
|
|
13
13
|
function catchCriticalError(error) {
|
|
14
14
|
console.error("Critical Error :", error);
|
|
15
15
|
}
|
|
@@ -29,7 +29,7 @@ async function implementHttpServer(params, initHttpServer) {
|
|
|
29
29
|
execRouteSystem: execRouteSystem,
|
|
30
30
|
httpServerParams: params.httpServerParams,
|
|
31
31
|
});
|
|
32
|
-
await hooks.launchHookServer(
|
|
32
|
+
await hooks.launchHookServer(params.hub.aggregatesHooksHubLifeCycle("afterStartServer"), params.hub, params.httpServerParams);
|
|
33
33
|
return result;
|
|
34
34
|
}
|
|
35
35
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { type Hub
|
|
1
|
+
import { type Hub } from "./hub";
|
|
2
2
|
import { type RouterInitializationData } from "./router";
|
|
3
3
|
import { type MaybePromise } from "@duplojs/utils";
|
|
4
|
+
import { type HttpServerParams } from "./types";
|
|
4
5
|
export interface ImplementHttpServerParams {
|
|
5
6
|
readonly hub: Hub;
|
|
6
7
|
readonly httpServerParams: HttpServerParams;
|
|
@@ -4,10 +4,10 @@ import { forward } from '@duplojs/utils';
|
|
|
4
4
|
import { launchHookServer, launchHookServerError, serverErrorNextHookFunction, serverErrorExitHookFunction } from './hub/hooks.mjs';
|
|
5
5
|
|
|
6
6
|
async function implementHttpServer(params, initHttpServer) {
|
|
7
|
-
|
|
8
|
-
const router = await buildRouter(
|
|
9
|
-
|
|
10
|
-
const serverErrorHooks =
|
|
7
|
+
await launchHookServer(params.hub.aggregatesHooksHubLifeCycle("beforeServerBuildRoutes"), params.hub, params.httpServerParams);
|
|
8
|
+
const router = await buildRouter(params.hub);
|
|
9
|
+
await launchHookServer(params.hub.aggregatesHooksHubLifeCycle("beforeStartServer"), params.hub, params.httpServerParams);
|
|
10
|
+
const serverErrorHooks = params.hub.aggregatesHooksHubLifeCycle("serverError");
|
|
11
11
|
function catchCriticalError(error) {
|
|
12
12
|
console.error("Critical Error :", error);
|
|
13
13
|
}
|
|
@@ -27,7 +27,7 @@ async function implementHttpServer(params, initHttpServer) {
|
|
|
27
27
|
execRouteSystem: execRouteSystem,
|
|
28
28
|
httpServerParams: params.httpServerParams,
|
|
29
29
|
});
|
|
30
|
-
await launchHookServer(
|
|
30
|
+
await launchHookServer(params.hub.aggregatesHooksHubLifeCycle("afterStartServer"), params.hub, params.httpServerParams);
|
|
31
31
|
return result;
|
|
32
32
|
}
|
|
33
33
|
|