@forklaunch/express 0.1.21 → 0.1.22
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/lib/app.d.ts +2 -0
- package/lib/app.d.ts.map +1 -0
- package/lib/app.js +62 -0
- package/lib/eslint.config.d.mts +1 -1
- package/lib/src/expressApplication.d.ts +2 -9
- package/lib/src/expressApplication.d.ts.map +1 -1
- package/lib/src/expressApplication.js +1 -29
- package/lib/src/expressRouter.d.ts +2 -2
- package/lib/src/expressRouter.d.ts.map +1 -1
- package/lib/src/expressRouter.js +1 -0
- package/lib/tests/typebox.forklaunch.express.test.js +3 -5
- package/lib/tests/zod.forklaunch.express.test.js +2 -4
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +13 -13
package/lib/app.d.ts
ADDED
package/lib/app.d.ts.map
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../app.ts"],"names":[],"mappings":""}
|
package/lib/app.js
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
import { SchemaValidator, string } from '@forklaunch/validator/typebox';
|
2
|
+
import { forklaunchExpress, forklaunchRouter } from './index';
|
3
|
+
const typeboxSchemaValidator = SchemaValidator();
|
4
|
+
const forklaunchApplication = forklaunchExpress(typeboxSchemaValidator);
|
5
|
+
const forklaunchRouterInstance = forklaunchRouter('/testpath', typeboxSchemaValidator);
|
6
|
+
forklaunchApplication.use(forklaunchRouterInstance);
|
7
|
+
forklaunchRouterInstance.get('/test', {
|
8
|
+
name: 'Test',
|
9
|
+
summary: 'Test Summary',
|
10
|
+
responses: {
|
11
|
+
200: string
|
12
|
+
}
|
13
|
+
}, async (_req, res) => {
|
14
|
+
res.status(200).send('Hello World');
|
15
|
+
});
|
16
|
+
forklaunchRouterInstance.post('/test', {
|
17
|
+
name: 'Test',
|
18
|
+
summary: 'Test Summary',
|
19
|
+
body: {
|
20
|
+
test: string
|
21
|
+
},
|
22
|
+
responses: {
|
23
|
+
200: string
|
24
|
+
}
|
25
|
+
}, (req, res) => {
|
26
|
+
res.status(200).send(req.body.test);
|
27
|
+
});
|
28
|
+
forklaunchRouterInstance.put('/test', {
|
29
|
+
name: 'Test',
|
30
|
+
summary: 'Test Summary',
|
31
|
+
body: {
|
32
|
+
test: string
|
33
|
+
},
|
34
|
+
responses: {
|
35
|
+
200: string
|
36
|
+
}
|
37
|
+
}, (req, res) => {
|
38
|
+
res.status(200).send(req.body.test);
|
39
|
+
});
|
40
|
+
forklaunchRouterInstance.patch('/test', {
|
41
|
+
name: 'Test',
|
42
|
+
summary: 'Test Summary',
|
43
|
+
body: {
|
44
|
+
test: string
|
45
|
+
},
|
46
|
+
responses: {
|
47
|
+
200: string
|
48
|
+
}
|
49
|
+
}, (req, res) => {
|
50
|
+
res.status(200).send(req.body.test);
|
51
|
+
});
|
52
|
+
forklaunchRouterInstance.delete('/test', {
|
53
|
+
name: 'Test',
|
54
|
+
summary: 'Test Summary',
|
55
|
+
responses: {
|
56
|
+
200: string
|
57
|
+
}
|
58
|
+
}, (_req, res) => {
|
59
|
+
res.status(200).send('Hello World');
|
60
|
+
});
|
61
|
+
forklaunchApplication.use(forklaunchRouterInstance);
|
62
|
+
forklaunchApplication.listen(6934);
|
package/lib/eslint.config.d.mts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
declare const _default: ({
|
2
2
|
readonly rules: Readonly<import("eslint").Linter.RulesRecord>;
|
3
|
-
} | import(".pnpm/@typescript-eslint+utils@8.
|
3
|
+
} | import(".pnpm/@typescript-eslint+utils@8.14.0_eslint@9.14.0_typescript@5.6.3/node_modules/@typescript-eslint/utils/ts-eslint").FlatConfig.Config | {
|
4
4
|
languageOptions: {
|
5
5
|
globals: {
|
6
6
|
readonly AbortController: false;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { ForklaunchExpressLikeApplication
|
1
|
+
import { ForklaunchExpressLikeApplication } from '@forklaunch/core/http';
|
2
2
|
import { AnySchemaValidator } from '@forklaunch/validator';
|
3
3
|
import { Express, RequestHandler } from 'express';
|
4
4
|
import { Server } from 'http';
|
@@ -7,20 +7,13 @@ import { Server } from 'http';
|
|
7
7
|
*
|
8
8
|
* @template SV - A type that extends AnySchemaValidator.
|
9
9
|
*/
|
10
|
-
export declare class Application<SV extends AnySchemaValidator> extends ForklaunchExpressLikeApplication<SV, Express> {
|
10
|
+
export declare class Application<SV extends AnySchemaValidator> extends ForklaunchExpressLikeApplication<SV, Express, RequestHandler> {
|
11
11
|
/**
|
12
12
|
* Creates an instance of Application.
|
13
13
|
*
|
14
14
|
* @param {SV} schemaValidator - The schema validator.
|
15
15
|
*/
|
16
16
|
constructor(schemaValidator: SV);
|
17
|
-
/**
|
18
|
-
* Registers middleware or routers to the application.
|
19
|
-
*
|
20
|
-
* @param {...(ForklaunchRouter<SV> | RequestHandler)[]} args - The middleware or routers to register.
|
21
|
-
* @returns {this} - The application instance.
|
22
|
-
*/
|
23
|
-
use(router: ForklaunchRouter<SV> | RequestHandler, ...args: (ForklaunchRouter<SV> | RequestHandler)[]): this;
|
24
17
|
/**
|
25
18
|
* Starts the server and sets up Swagger documentation.
|
26
19
|
*
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"expressApplication.d.ts","sourceRoot":"","sources":["../../src/expressApplication.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gCAAgC,
|
1
|
+
{"version":3,"file":"expressApplication.d.ts","sourceRoot":"","sources":["../../src/expressApplication.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gCAAgC,EAEjC,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAgB,EAAuB,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAChF,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAG9B;;;;GAIG;AACH,qBAAa,WAAW,CACtB,EAAE,SAAS,kBAAkB,CAC7B,SAAQ,gCAAgC,CAAC,EAAE,EAAE,OAAO,EAAE,cAAc,CAAC;IACrE;;;;OAIG;gBACS,eAAe,EAAE,EAAE;IAI/B;;;;;OAKG;IACH,MAAM,CACJ,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,QAAQ,CAAC,EAAE,MAAM,IAAI,GACpB,MAAM;IACT,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,IAAI,GAAG,MAAM;IACrE,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,IAAI,GAAG,MAAM;IACnD,MAAM,CAAC,QAAQ,CAAC,EAAE,MAAM,IAAI,GAAG,MAAM;IACrC,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,IAAI,GAAG,MAAM;IACnD,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,iBAAiB,CAAC,EAAE,MAAM,IAAI,GAAG,MAAM;CAuBhE"}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { ForklaunchExpressLikeApplication, generateSwaggerDocument
|
1
|
+
import { ForklaunchExpressLikeApplication, generateSwaggerDocument } from '@forklaunch/core/http';
|
2
2
|
import express from 'express';
|
3
3
|
import swaggerUi from 'swagger-ui-express';
|
4
4
|
/**
|
@@ -15,34 +15,6 @@ export class Application extends ForklaunchExpressLikeApplication {
|
|
15
15
|
constructor(schemaValidator) {
|
16
16
|
super(schemaValidator, express());
|
17
17
|
}
|
18
|
-
//TODO: change this to different signatures and handle different cases
|
19
|
-
/**
|
20
|
-
* Registers middleware or routers to the application.
|
21
|
-
*
|
22
|
-
* @param {...(ForklaunchRouter<SV> | RequestHandler)[]} args - The middleware or routers to register.
|
23
|
-
* @returns {this} - The application instance.
|
24
|
-
*/
|
25
|
-
use(router, ...args) {
|
26
|
-
if (isForklaunchRouter(router)) {
|
27
|
-
const expressRouter = router;
|
28
|
-
this.routers.push(expressRouter);
|
29
|
-
this.internal.use(expressRouter.basePath, expressRouter.internal);
|
30
|
-
return this;
|
31
|
-
}
|
32
|
-
else {
|
33
|
-
const expressRouter = args.pop();
|
34
|
-
if (!isForklaunchRouter(expressRouter)) {
|
35
|
-
throw new Error('Last argument must be a router');
|
36
|
-
}
|
37
|
-
args.forEach((arg) => {
|
38
|
-
if (isForklaunchRouter(arg)) {
|
39
|
-
throw new Error('Only one router is allowed');
|
40
|
-
}
|
41
|
-
});
|
42
|
-
this.internal.use(expressRouter.basePath, ...args, expressRouter.internal);
|
43
|
-
return this;
|
44
|
-
}
|
45
|
-
}
|
46
18
|
listen(...args) {
|
47
19
|
const port = typeof args[0] === 'number' ? args[0] : Number(process.env.PORT);
|
48
20
|
this.internal.use(`/api${process.env.VERSION ?? '/v1'}${process.env.SWAGGER_PATH ?? '/swagger'}`, swaggerUi.serve, swaggerUi.setup(generateSwaggerDocument(this.schemaValidator, port, this.routers)));
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { ForklaunchExpressLikeRouter,
|
1
|
+
import { ForklaunchExpressLikeRouter, TypedMiddlewareDefinition } from '@forklaunch/core/http';
|
2
2
|
import { AnySchemaValidator, IdiomaticSchema, LiteralSchema, SchemaResolve } from '@forklaunch/validator';
|
3
3
|
import { Router as ExpressRouter, NextFunction, RequestHandler } from 'express';
|
4
4
|
/**
|
@@ -7,7 +7,7 @@ import { Router as ExpressRouter, NextFunction, RequestHandler } from 'express';
|
|
7
7
|
* @template SV - A type that extends AnySchemaValidator.
|
8
8
|
* @implements {ForklaunchRouter<SV>}
|
9
9
|
*/
|
10
|
-
export declare class Router<SV extends AnySchemaValidator, BasePath extends `/${string}`> extends ForklaunchExpressLikeRouter<SV, BasePath, RequestHandler, ExpressRouter>
|
10
|
+
export declare class Router<SV extends AnySchemaValidator, BasePath extends `/${string}`> extends ForklaunchExpressLikeRouter<SV, BasePath, RequestHandler, ExpressRouter> {
|
11
11
|
basePath: BasePath;
|
12
12
|
/**
|
13
13
|
* Creates an instance of Router.
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"expressRouter.d.ts","sourceRoot":"","sources":["../../src/expressRouter.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,2BAA2B,
|
1
|
+
{"version":3,"file":"expressRouter.d.ts","sourceRoot":"","sources":["../../src/expressRouter.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,2BAA2B,EAO3B,yBAAyB,EAC1B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,aAAa,EACd,MAAM,uBAAuB,CAAC;AAC/B,OAAgB,EACd,MAAM,IAAI,aAAa,EACvB,YAAY,EACZ,cAAc,EACf,MAAM,SAAS,CAAC;AAGjB;;;;;GAKG;AACH,qBAAa,MAAM,CACjB,EAAE,SAAS,kBAAkB,EAC7B,QAAQ,SAAS,IAAI,MAAM,EAAE,CAC7B,SAAQ,2BAA2B,CACnC,EAAE,EACF,QAAQ,EACR,cAAc,EACd,aAAa,CACd;IASU,QAAQ,EAAE,QAAQ;IAP3B;;;;;OAKG;gBAEM,QAAQ,EAAE,QAAQ,EACzB,eAAe,EAAE,EAAE;IAQrB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAKzB,KAAK,CACH,SAAS,SAAS,MAAM,EACxB,KAAK,SAAS;QACZ,GAAG,CAAC,EAAE,aAAa,GAAG,EAAE,CAAC,iBAAiB,CAAC,CAAC;QAC5C,GAAG,CAAC,EAAE,eAAe,CAAC,EAAE,CAAC,CAAC;KAC3B,GAAG;SACD,CAAC,IAAI,SAAS,GAAG,eAAe,CAAC,EAAE,CAAC;KACtC,EAED,IAAI,EAAE,SAAS,EACf,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,CACP,GAAG,EAAE,aAAa,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAChC,GAAG,EAAE,aAAa,CAAC,KAAK,CA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AE,EAAE,CAAC,CAgE9C;IAEF,IAAI,EAAE,yBAAyB,CAAC,IAAI,EAAE,EAAE,CAAC,CAgEvC;IAEF,MAAM,EAAE,yBAAyB,CAAC,IAAI,EAAE,EAAE,CAAC,CAgEzC;CACH"}
|
package/lib/src/expressRouter.js
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
import { SchemaValidator, string } from '@forklaunch/validator/typebox';
|
2
2
|
import { forklaunchExpress, forklaunchRouter } from '../index';
|
3
3
|
const typeboxSchemaValidator = SchemaValidator();
|
4
|
+
const forklaunchApplication = forklaunchExpress(typeboxSchemaValidator);
|
5
|
+
const forklaunchRouterInstance = forklaunchRouter('/testpath', typeboxSchemaValidator);
|
4
6
|
describe('Forklaunch Express Tests', () => {
|
5
|
-
let forklaunchApplication;
|
6
|
-
let forklaunchRouterInstance;
|
7
7
|
let server;
|
8
8
|
beforeAll(async () => {
|
9
|
-
forklaunchApplication = forklaunchExpress(typeboxSchemaValidator);
|
10
|
-
forklaunchRouterInstance = forklaunchRouter('/testpath', typeboxSchemaValidator);
|
11
9
|
forklaunchRouterInstance.get('/test', {
|
12
10
|
name: 'Test',
|
13
11
|
summary: 'Test Summary',
|
14
12
|
responses: {
|
15
13
|
200: string
|
16
14
|
}
|
17
|
-
}, (_req, res) => {
|
15
|
+
}, async (_req, res) => {
|
18
16
|
res.status(200).send('Hello World');
|
19
17
|
});
|
20
18
|
forklaunchRouterInstance.post('/test', {
|
@@ -1,13 +1,11 @@
|
|
1
1
|
import { SchemaValidator, string } from '@forklaunch/validator/zod';
|
2
2
|
import { forklaunchExpress, forklaunchRouter } from '../index';
|
3
3
|
const zodSchemaValidator = SchemaValidator();
|
4
|
+
const forklaunchApplication = forklaunchExpress(zodSchemaValidator);
|
5
|
+
const forklaunchRouterInstance = forklaunchRouter('/testpath', zodSchemaValidator);
|
4
6
|
describe('Forklaunch Express Tests', () => {
|
5
|
-
let forklaunchApplication;
|
6
|
-
let forklaunchRouterInstance;
|
7
7
|
let server;
|
8
8
|
beforeAll(async () => {
|
9
|
-
forklaunchApplication = forklaunchExpress(zodSchemaValidator);
|
10
|
-
forklaunchRouterInstance = forklaunchRouter('/testpath', zodSchemaValidator);
|
11
9
|
forklaunchRouterInstance.get('/test', {
|
12
10
|
name: 'Test',
|
13
11
|
summary: 'Test Summary',
|