@forklaunch/core 0.1.13 → 0.1.15
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/http/interfaces/forklaunchExpress.application.interface.d.ts +2 -5
- package/dist/http/interfaces/forklaunchExpress.application.interface.d.ts.map +1 -1
- package/dist/http/interfaces/forklaunchExpress.application.interface.js +6 -6
- package/dist/http/interfaces/forklaunchExpress.router.interface.d.ts +4 -47
- package/dist/http/interfaces/forklaunchExpress.router.interface.d.ts.map +1 -1
- package/dist/http/interfaces/forklaunchExpress.router.interface.js +36 -34
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
@@ -1,9 +1,6 @@
|
|
1
1
|
import { AnySchemaValidator } from '@forklaunch/validator';
|
2
|
-
|
3
|
-
|
4
|
-
protected schemaValidator: SV;
|
5
|
-
protected internal: Server;
|
6
|
-
protected routers: ForklaunchRouter<SV>[];
|
2
|
+
export declare abstract class ForklaunchExpressLikeApplication<SV extends AnySchemaValidator, Server> {
|
3
|
+
#private;
|
7
4
|
/**
|
8
5
|
* Creates an instance of the Application class.
|
9
6
|
*
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"forklaunchExpress.application.interface.d.ts","sourceRoot":"","sources":["../../../http/interfaces/forklaunchExpress.application.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;
|
1
|
+
{"version":3,"file":"forklaunchExpress.application.interface.d.ts","sourceRoot":"","sources":["../../../http/interfaces/forklaunchExpress.application.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAG3D,8BAAsB,gCAAgC,CACpD,EAAE,SAAS,kBAAkB,EAC7B,MAAM;;IAMN;;;;OAIG;gBACS,eAAe,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM;IAKjD,QAAQ,CAAC,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IACtC,QAAQ,CAAC,MAAM,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;CAC1C"}
|
@@ -1,14 +1,14 @@
|
|
1
|
-
export
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
export class ForklaunchExpressLikeApplication {
|
2
|
+
#routers = [];
|
3
|
+
#schemaValidator;
|
4
|
+
#internal;
|
5
5
|
/**
|
6
6
|
* Creates an instance of the Application class.
|
7
7
|
*
|
8
8
|
* @param {SV} schemaValidator - The schema validator.
|
9
9
|
*/
|
10
10
|
constructor(schemaValidator, internal) {
|
11
|
-
this
|
12
|
-
this
|
11
|
+
this.#schemaValidator = schemaValidator;
|
12
|
+
this.#internal = internal;
|
13
13
|
}
|
14
14
|
}
|
@@ -1,6 +1,5 @@
|
|
1
1
|
import { AnySchemaValidator } from '@forklaunch/validator';
|
2
|
-
import {
|
3
|
-
import { Body, ForklaunchMiddlewareHandler, ForklaunchRoute, ForklaunchSchemaMiddlewareHandler, HeadersObject, HttpContractDetails, LiveTypeFunction, ParamsDictionary, ParamsObject, PathParamHttpContractDetails, QueryObject, ResponsesObject } from '../types';
|
2
|
+
import { Body, ForklaunchSchemaMiddlewareHandler, HeadersObject, HttpContractDetails, LiveTypeFunction, ParamsObject, PathParamHttpContractDetails, QueryObject, ResponsesObject } from '../types';
|
4
3
|
interface ExpressLikeRouter<RouterFunction> {
|
5
4
|
use: (...args: (string | RouterFunction)[]) => this;
|
6
5
|
get(path: string, ...handlers: RouterFunction[]): void;
|
@@ -9,44 +8,10 @@ interface ExpressLikeRouter<RouterFunction> {
|
|
9
8
|
patch(path: string, ...handlers: RouterFunction[]): void;
|
10
9
|
delete(path: string, ...handlers: RouterFunction[]): void;
|
11
10
|
}
|
12
|
-
export
|
13
|
-
|
14
|
-
|
15
|
-
protected routes: ForklaunchRoute<SV>[];
|
11
|
+
export declare abstract class ForklaunchExpressLikeRouter<SV extends AnySchemaValidator, BasePath extends `/${string}`, RouterFunction, Internal extends ExpressLikeRouter<RouterFunction>> {
|
12
|
+
#private;
|
13
|
+
readonly internal: Internal;
|
16
14
|
constructor(basePath: BasePath, internal: Internal);
|
17
|
-
/**
|
18
|
-
* Resolves middlewares based on the contract details.
|
19
|
-
*
|
20
|
-
* @param {PathParamHttpContractDetails<SV> | HttpContractDetails<SV>} contractDetails - The contract details.
|
21
|
-
* @returns {MiddlewareHandler<SV>[]} - The resolved middlewares.
|
22
|
-
*/
|
23
|
-
protected resolveMiddlewares<SV extends AnySchemaValidator, P extends ParamsObject<SV>, ResBodyMap extends ResponsesObject<SV>, ReqBody extends Body<SV>, ReqQuery extends QueryObject<SV>, ReqHeaders extends HeadersObject<SV>, ResHeaders extends HeadersObject<SV>, LocalsObj extends Record<string, unknown>>(contractDetails: PathParamHttpContractDetails<SV, P, ResBodyMap, ReqQuery, ReqHeaders, ResHeaders> | HttpContractDetails<SV, P, ResBodyMap, ReqQuery, ReqHeaders, ResHeaders>): ForklaunchSchemaMiddlewareHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj>[];
|
24
|
-
/**
|
25
|
-
* Parses and runs the controller function with error handling.
|
26
|
-
*
|
27
|
-
* @template P - The type of request parameters.
|
28
|
-
* @template ResBodyMap - The type of response body.
|
29
|
-
* @template ReqBody - The type of request body.
|
30
|
-
* @template ReqQuery - The type of request query.
|
31
|
-
* @template LocalsObj - The type of local variables.
|
32
|
-
* @template StatusCode - The type of status code.
|
33
|
-
* @param {MiddlewareHandler<SV, P, ResBodyMap | string, ReqBody, ReqQuery, LocalsObj, StatusCode>} requestHandler - The request handler.
|
34
|
-
* @returns {ExpressMiddlewareHandler} - The Express request handler.
|
35
|
-
*/
|
36
|
-
protected parseAndRunControllerFunction<SV extends AnySchemaValidator, P extends ParamsDictionary, ResBodyMap extends Record<number, unknown>, ReqBody extends Record<string, unknown>, ReqQuery extends ParsedQs, ReqHeaders extends Record<string, string>, ResHeaders extends Record<string, string>, LocalsObj extends Record<string, unknown>>(requestHandler: ForklaunchMiddlewareHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj>): ForklaunchMiddlewareHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj>;
|
37
|
-
/**
|
38
|
-
* Extracts the controller function from the provided functions.
|
39
|
-
*
|
40
|
-
* @template P - The type of request parameters.
|
41
|
-
* @template ResBodyMap - The type of response body.
|
42
|
-
* @template ReqBody - The type of request body.
|
43
|
-
* @template ReqQuery - The type of request query.
|
44
|
-
* @template LocalsObj - The type of local variables.
|
45
|
-
* @param {MiddlewareHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, LocalsObj>[]} functions - The provided functions.
|
46
|
-
* @returns {MiddlewareHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, LocalsObj>} - The extracted controller function.
|
47
|
-
* @throws {Error} - Throws an error if the last argument is not a function.
|
48
|
-
*/
|
49
|
-
protected extractControllerFunction<SV extends AnySchemaValidator, P extends ParamsDictionary, ResBodyMap extends Record<number, unknown>, ReqBody extends Record<string, unknown>, ReqQuery extends ParsedQs, ReqHeaders extends Record<string, string>, ResHeaders extends Record<string, string>, LocalsObj extends Record<string, unknown>>(functions: ForklaunchMiddlewareHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj>[]): ForklaunchMiddlewareHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj>;
|
50
15
|
/**
|
51
16
|
* Registers middleware to the router.
|
52
17
|
*
|
@@ -54,14 +19,6 @@ export default abstract class ForklaunchExpressLikeRouter<SV extends AnySchemaVa
|
|
54
19
|
* @returns {this} - The router instance.
|
55
20
|
*/
|
56
21
|
use(...args: unknown[]): this;
|
57
|
-
/**
|
58
|
-
* Executes request locally, applying parameters
|
59
|
-
*
|
60
|
-
* @param functions {ForklaunchMiddlewareHandler<SV>}
|
61
|
-
* @param controllerFunction
|
62
|
-
* @returns
|
63
|
-
*/
|
64
|
-
protected localParamRequest<Path extends `/${string}`, SV extends AnySchemaValidator, P extends ParamsDictionary, ResBodyMap extends Record<number, unknown>, ReqBody extends Record<string, unknown>, ReqQuery extends ParsedQs, ReqHeaders extends Record<string, string>, ResHeaders extends Record<string, string>, LocalsObj extends Record<string, unknown>>(functions: ForklaunchMiddlewareHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj>[], controllerFunction: ForklaunchMiddlewareHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj>): LiveTypeFunction<SV, `${BasePath}${Path}`, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders>;
|
65
22
|
/**
|
66
23
|
* Registers a GET route with the specified contract details and handler functions.
|
67
24
|
*
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"forklaunchExpress.router.interface.d.ts","sourceRoot":"","sources":["../../../http/interfaces/forklaunchExpress.router.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;
|
1
|
+
{"version":3,"file":"forklaunchExpress.router.interface.d.ts","sourceRoot":"","sources":["../../../http/interfaces/forklaunchExpress.router.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAU3D,OAAO,EACL,IAAI,EAGJ,iCAAiC,EACjC,aAAa,EACb,mBAAmB,EACnB,gBAAgB,EAEhB,YAAY,EACZ,4BAA4B,EAC5B,WAAW,EACX,eAAe,EAChB,MAAM,UAAU,CAAC;AAElB,UAAU,iBAAiB,CAAC,cAAc;IACxC,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,MAAM,GAAG,cAAc,CAAC,EAAE,KAAK,IAAI,CAAC;IACpD,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,QAAQ,EAAE,cAAc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,CACX,EACD,GAAG,SAAS,EAAE,iCAAiC,CAC7C,EAAE,EACF,CAAC,EACD,UAAU,EACV,OAAO,EACP,QAAQ,EACR,UAAU,EACV,UAAU,EACV,SAAS,CACV,EAAE;;;CA8BN"}
|
@@ -1,11 +1,13 @@
|
|
1
1
|
import { enrichRequestDetails, parseReqHeaders, parseRequestAuth, parseRequestBody, parseRequestParams, parseRequestQuery } from '../middleware';
|
2
|
-
export
|
3
|
-
basePath;
|
2
|
+
export class ForklaunchExpressLikeRouter {
|
4
3
|
internal;
|
5
|
-
routes = [];
|
4
|
+
#routes = [];
|
5
|
+
#basePath;
|
6
|
+
#internal;
|
6
7
|
constructor(basePath, internal) {
|
7
|
-
this.basePath = basePath;
|
8
8
|
this.internal = internal;
|
9
|
+
this.#basePath = basePath;
|
10
|
+
this.#internal = internal;
|
9
11
|
}
|
10
12
|
/**
|
11
13
|
* Resolves middlewares based on the contract details.
|
@@ -13,7 +15,7 @@ export default class ForklaunchExpressLikeRouter {
|
|
13
15
|
* @param {PathParamHttpContractDetails<SV> | HttpContractDetails<SV>} contractDetails - The contract details.
|
14
16
|
* @returns {MiddlewareHandler<SV>[]} - The resolved middlewares.
|
15
17
|
*/
|
16
|
-
resolveMiddlewares(contractDetails) {
|
18
|
+
#resolveMiddlewares(contractDetails) {
|
17
19
|
const middlewares = [
|
18
20
|
enrichRequestDetails(contractDetails)
|
19
21
|
];
|
@@ -46,7 +48,7 @@ export default class ForklaunchExpressLikeRouter {
|
|
46
48
|
* @param {MiddlewareHandler<SV, P, ResBodyMap | string, ReqBody, ReqQuery, LocalsObj, StatusCode>} requestHandler - The request handler.
|
47
49
|
* @returns {ExpressMiddlewareHandler} - The Express request handler.
|
48
50
|
*/
|
49
|
-
parseAndRunControllerFunction(requestHandler) {
|
51
|
+
#parseAndRunControllerFunction(requestHandler) {
|
50
52
|
return (async (req, res, next) => {
|
51
53
|
if (!requestHandler) {
|
52
54
|
throw new Error('Controller function is not defined');
|
@@ -77,7 +79,7 @@ export default class ForklaunchExpressLikeRouter {
|
|
77
79
|
* @returns {MiddlewareHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, LocalsObj>} - The extracted controller function.
|
78
80
|
* @throws {Error} - Throws an error if the last argument is not a function.
|
79
81
|
*/
|
80
|
-
extractControllerFunction(functions) {
|
82
|
+
#extractControllerFunction(functions) {
|
81
83
|
const controllerFunction = functions.pop();
|
82
84
|
if (typeof controllerFunction !== 'function') {
|
83
85
|
throw new Error('Last argument must be a function');
|
@@ -92,7 +94,7 @@ export default class ForklaunchExpressLikeRouter {
|
|
92
94
|
// * @returns {string} - The extracted SDK path.
|
93
95
|
// * @throws {Error} - Throws an error if the path is not defined.
|
94
96
|
// */
|
95
|
-
//
|
97
|
+
// #extractSdkPath(path: string | RegExp | (string | RegExp)[]): string {
|
96
98
|
// let sdkPath = path;
|
97
99
|
// if (Array.isArray(path)) {
|
98
100
|
// sdkPath = path.pop() || path[0];
|
@@ -122,7 +124,7 @@ export default class ForklaunchExpressLikeRouter {
|
|
122
124
|
* @param controllerFunction
|
123
125
|
* @returns
|
124
126
|
*/
|
125
|
-
localParamRequest(functions, controllerFunction) {
|
127
|
+
#localParamRequest(functions, controllerFunction) {
|
126
128
|
return (async (route, request) => {
|
127
129
|
let statusCode;
|
128
130
|
let responseMessage;
|
@@ -196,16 +198,16 @@ export default class ForklaunchExpressLikeRouter {
|
|
196
198
|
* @returns {ExpressRouter} - The Express router.
|
197
199
|
*/
|
198
200
|
get(path, contractDetails, ...functions) {
|
199
|
-
const controllerFunction = this
|
200
|
-
this
|
201
|
-
basePath: this
|
201
|
+
const controllerFunction = this.#extractControllerFunction(functions);
|
202
|
+
this.#routes.push({
|
203
|
+
basePath: this.#basePath,
|
202
204
|
path,
|
203
205
|
method: 'GET',
|
204
206
|
contractDetails
|
205
207
|
});
|
206
|
-
this.internal.get(path, ...this
|
208
|
+
this.internal.get(path, ...this.#resolveMiddlewares(contractDetails).concat(functions), this.#parseAndRunControllerFunction(controllerFunction));
|
207
209
|
return {
|
208
|
-
get: this
|
210
|
+
get: this.#localParamRequest(functions, controllerFunction)
|
209
211
|
};
|
210
212
|
}
|
211
213
|
/**
|
@@ -223,16 +225,16 @@ export default class ForklaunchExpressLikeRouter {
|
|
223
225
|
*/
|
224
226
|
post(path, contractDetails, ...functions) {
|
225
227
|
// : LiveType<SV, P, ResBodyMap, ReqBody, ReqQuery> {
|
226
|
-
const controllerFunction = this
|
227
|
-
this
|
228
|
-
basePath: this
|
228
|
+
const controllerFunction = this.#extractControllerFunction(functions);
|
229
|
+
this.#routes.push({
|
230
|
+
basePath: this.#basePath,
|
229
231
|
path,
|
230
232
|
method: 'POST',
|
231
233
|
contractDetails
|
232
234
|
});
|
233
|
-
this.internal.post(path, ...this
|
235
|
+
this.internal.post(path, ...this.#resolveMiddlewares(contractDetails).concat(functions), this.#parseAndRunControllerFunction(controllerFunction));
|
234
236
|
return {
|
235
|
-
post: this
|
237
|
+
post: this.#localParamRequest(functions, controllerFunction)
|
236
238
|
};
|
237
239
|
}
|
238
240
|
/**
|
@@ -249,16 +251,16 @@ export default class ForklaunchExpressLikeRouter {
|
|
249
251
|
* @returns {ExpressRouter} - The Express router.
|
250
252
|
*/
|
251
253
|
put(path, contractDetails, ...functions) {
|
252
|
-
const controllerFunction = this
|
253
|
-
this
|
254
|
-
basePath: this
|
254
|
+
const controllerFunction = this.#extractControllerFunction(functions);
|
255
|
+
this.#routes.push({
|
256
|
+
basePath: this.#basePath,
|
255
257
|
path,
|
256
258
|
method: 'PUT',
|
257
259
|
contractDetails
|
258
260
|
});
|
259
|
-
this.internal.put(path, ...this
|
261
|
+
this.internal.put(path, ...this.#resolveMiddlewares(contractDetails).concat(functions), this.#parseAndRunControllerFunction(controllerFunction));
|
260
262
|
return {
|
261
|
-
put: this
|
263
|
+
put: this.#localParamRequest(functions, controllerFunction)
|
262
264
|
};
|
263
265
|
}
|
264
266
|
/**
|
@@ -275,16 +277,16 @@ export default class ForklaunchExpressLikeRouter {
|
|
275
277
|
* @returns {ExpressRouter} - The Express router.
|
276
278
|
*/
|
277
279
|
patch(path, contractDetails, ...functions) {
|
278
|
-
const controllerFunction = this
|
279
|
-
this
|
280
|
-
basePath: this
|
280
|
+
const controllerFunction = this.#extractControllerFunction(functions);
|
281
|
+
this.#routes.push({
|
282
|
+
basePath: this.#basePath,
|
281
283
|
path,
|
282
284
|
method: 'PATCH',
|
283
285
|
contractDetails
|
284
286
|
});
|
285
|
-
this.internal.patch(path, ...this
|
287
|
+
this.internal.patch(path, ...this.#resolveMiddlewares(contractDetails).concat(functions), this.#parseAndRunControllerFunction(controllerFunction));
|
286
288
|
return {
|
287
|
-
patch: this
|
289
|
+
patch: this.#localParamRequest(functions, controllerFunction)
|
288
290
|
};
|
289
291
|
}
|
290
292
|
/**
|
@@ -301,16 +303,16 @@ export default class ForklaunchExpressLikeRouter {
|
|
301
303
|
* @returns {ExpressRouter} - The Express router.
|
302
304
|
*/
|
303
305
|
delete(path, contractDetails, ...functions) {
|
304
|
-
const controllerFunction = this
|
305
|
-
this
|
306
|
-
basePath: this
|
306
|
+
const controllerFunction = this.#extractControllerFunction(functions);
|
307
|
+
this.#routes.push({
|
308
|
+
basePath: this.#basePath,
|
307
309
|
path,
|
308
310
|
method: 'DELETE',
|
309
311
|
contractDetails
|
310
312
|
});
|
311
|
-
this.internal.delete(path, ...this
|
313
|
+
this.internal.delete(path, ...this.#resolveMiddlewares(contractDetails).concat(functions), this.#parseAndRunControllerFunction(controllerFunction));
|
312
314
|
return {
|
313
|
-
delete: this
|
315
|
+
delete: this.#localParamRequest(functions, controllerFunction)
|
314
316
|
};
|
315
317
|
}
|
316
318
|
}
|