@onebun/core 0.2.7 → 0.2.9
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/package.json +1 -1
- package/src/application/application.test.ts +52 -6
- package/src/application/application.ts +308 -220
- package/src/decorators/decorators.ts +213 -0
- package/src/docs-examples.test.ts +357 -2
- package/src/exception-filters/exception-filters.test.ts +172 -0
- package/src/exception-filters/exception-filters.ts +129 -0
- package/src/exception-filters/http-exception.ts +22 -0
- package/src/exception-filters/index.ts +2 -0
- package/src/file/onebun-file.ts +8 -2
- package/src/http-guards/http-guards.test.ts +230 -0
- package/src/http-guards/http-guards.ts +173 -0
- package/src/http-guards/index.ts +1 -0
- package/src/index.ts +9 -0
- package/src/module/module.test.ts +78 -0
- package/src/module/module.ts +47 -7
- package/src/queue/docs-examples.test.ts +2 -2
- package/src/security/cors-middleware.ts +212 -0
- package/src/security/index.ts +19 -0
- package/src/security/rate-limit-middleware.ts +276 -0
- package/src/security/security-headers-middleware.ts +188 -0
- package/src/security/security.test.ts +285 -0
- package/src/testing/index.ts +1 -0
- package/src/testing/testing-module.test.ts +199 -0
- package/src/testing/testing-module.ts +252 -0
- package/src/types.ts +98 -0
package/package.json
CHANGED
|
@@ -38,6 +38,7 @@ import {
|
|
|
38
38
|
} from '../decorators/decorators';
|
|
39
39
|
import { Controller as BaseController } from '../module/controller';
|
|
40
40
|
import { BaseMiddleware } from '../module/middleware';
|
|
41
|
+
import { clearGlobalServicesRegistry } from '../module/module';
|
|
41
42
|
import { Service } from '../module/service';
|
|
42
43
|
import { QueueService, QUEUE_NOT_ENABLED_ERROR_MESSAGE } from '../queue';
|
|
43
44
|
import { Subscribe } from '../queue/decorators';
|
|
@@ -157,6 +158,7 @@ describe('OneBunApplication', () => {
|
|
|
157
158
|
|
|
158
159
|
afterEach(() => {
|
|
159
160
|
register.clear();
|
|
161
|
+
clearGlobalServicesRegistry();
|
|
160
162
|
});
|
|
161
163
|
|
|
162
164
|
describe('Constructor and basic initialization', () => {
|
|
@@ -1842,7 +1844,7 @@ describe('OneBunApplication', () => {
|
|
|
1842
1844
|
expect(body.result.hasOptional).toBe(false);
|
|
1843
1845
|
});
|
|
1844
1846
|
|
|
1845
|
-
test('should return
|
|
1847
|
+
test('should return 400 when required query parameter is missing', async () => {
|
|
1846
1848
|
@Controller('/api')
|
|
1847
1849
|
class ApiController extends BaseController {
|
|
1848
1850
|
@Get('/required-query')
|
|
@@ -1869,7 +1871,7 @@ describe('OneBunApplication', () => {
|
|
|
1869
1871
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1870
1872
|
const response = await (mockServer as any).fetchHandler(request);
|
|
1871
1873
|
|
|
1872
|
-
expect(response.status).toBe(
|
|
1874
|
+
expect(response.status).toBe(400);
|
|
1873
1875
|
});
|
|
1874
1876
|
|
|
1875
1877
|
test('should pass validation with required query parameter present', async () => {
|
|
@@ -1966,7 +1968,7 @@ describe('OneBunApplication', () => {
|
|
|
1966
1968
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1967
1969
|
const response = await (mockServer as any).fetchHandler(request);
|
|
1968
1970
|
|
|
1969
|
-
expect(response.status).toBe(
|
|
1971
|
+
expect(response.status).toBe(400);
|
|
1970
1972
|
});
|
|
1971
1973
|
|
|
1972
1974
|
test('should validate body with arktype schema', async () => {
|
|
@@ -2045,7 +2047,7 @@ describe('OneBunApplication', () => {
|
|
|
2045
2047
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2046
2048
|
const response = await (mockServer as any).fetchHandler(request);
|
|
2047
2049
|
|
|
2048
|
-
expect(response.status).toBe(
|
|
2050
|
+
expect(response.status).toBe(400);
|
|
2049
2051
|
});
|
|
2050
2052
|
|
|
2051
2053
|
test('should handle metrics endpoint', async () => {
|
|
@@ -3449,7 +3451,7 @@ describe('OneBunApplication', () => {
|
|
|
3449
3451
|
expect(body.result.isUndefined).toBe(true);
|
|
3450
3452
|
});
|
|
3451
3453
|
|
|
3452
|
-
test('should return
|
|
3454
|
+
test('should return 400 when required cookie is missing', async () => {
|
|
3453
3455
|
@Controller('/api')
|
|
3454
3456
|
class ApiController extends BaseController {
|
|
3455
3457
|
@Get('/auth')
|
|
@@ -3474,7 +3476,7 @@ describe('OneBunApplication', () => {
|
|
|
3474
3476
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3475
3477
|
const response = await (mockServer as any).fetchHandler(request);
|
|
3476
3478
|
|
|
3477
|
-
expect(response.status).toBe(
|
|
3479
|
+
expect(response.status).toBe(400);
|
|
3478
3480
|
});
|
|
3479
3481
|
|
|
3480
3482
|
test('should extract multiple cookies with @Cookie decorator', async () => {
|
|
@@ -4036,5 +4038,49 @@ describe('OneBunApplication', () => {
|
|
|
4036
4038
|
|
|
4037
4039
|
await app.stop();
|
|
4038
4040
|
});
|
|
4041
|
+
|
|
4042
|
+
test('QueueService is injectable in controllers of child modules', async () => {
|
|
4043
|
+
@Controller('/child-queue')
|
|
4044
|
+
class ChildQueueController extends BaseController {
|
|
4045
|
+
constructor(private queueService: QueueService) {
|
|
4046
|
+
super();
|
|
4047
|
+
}
|
|
4048
|
+
|
|
4049
|
+
publishTest(pattern: string, data: unknown) {
|
|
4050
|
+
return this.queueService.publish(pattern, data);
|
|
4051
|
+
}
|
|
4052
|
+
}
|
|
4053
|
+
|
|
4054
|
+
@Controller('/child-sub')
|
|
4055
|
+
class ChildSubscribeController extends BaseController {
|
|
4056
|
+
@Subscribe('child.test')
|
|
4057
|
+
async handle(): Promise<void> {}
|
|
4058
|
+
}
|
|
4059
|
+
|
|
4060
|
+
@Module({
|
|
4061
|
+
controllers: [ChildQueueController, ChildSubscribeController],
|
|
4062
|
+
})
|
|
4063
|
+
class ChildQueueModule {}
|
|
4064
|
+
|
|
4065
|
+
@Module({
|
|
4066
|
+
imports: [ChildQueueModule],
|
|
4067
|
+
})
|
|
4068
|
+
class ParentQueueModule {}
|
|
4069
|
+
|
|
4070
|
+
const app = createTestApp(ParentQueueModule, {
|
|
4071
|
+
port: 0,
|
|
4072
|
+
queue: { enabled: true, adapter: 'memory' },
|
|
4073
|
+
});
|
|
4074
|
+
await app.start();
|
|
4075
|
+
|
|
4076
|
+
const rootModule = (app as unknown as { rootModule: ModuleInstance }).rootModule;
|
|
4077
|
+
const controller = rootModule.getControllerInstance?.(ChildQueueController) as
|
|
4078
|
+
| ChildQueueController
|
|
4079
|
+
| undefined;
|
|
4080
|
+
expect(controller).toBeDefined();
|
|
4081
|
+
await expect(controller!.publishTest('child.test', { ok: true })).resolves.toBeDefined();
|
|
4082
|
+
|
|
4083
|
+
await app.stop();
|
|
4084
|
+
});
|
|
4039
4085
|
});
|
|
4040
4086
|
});
|