@dangao/bun-server 1.9.0 → 1.12.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/README.md +79 -6
- package/dist/cache/cache-module.d.ts +6 -0
- package/dist/cache/cache-module.d.ts.map +1 -1
- package/dist/client/generator.d.ts +16 -0
- package/dist/client/generator.d.ts.map +1 -0
- package/dist/client/index.d.ts +4 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/runtime.d.ts +15 -0
- package/dist/client/runtime.d.ts.map +1 -0
- package/dist/client/types.d.ts +36 -0
- package/dist/client/types.d.ts.map +1 -0
- package/dist/config/config-module.d.ts +7 -0
- package/dist/config/config-module.d.ts.map +1 -1
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/service.d.ts +13 -0
- package/dist/config/service.d.ts.map +1 -1
- package/dist/config/types.d.ts +10 -0
- package/dist/config/types.d.ts.map +1 -1
- package/dist/core/application.d.ts +7 -0
- package/dist/core/application.d.ts.map +1 -1
- package/dist/core/apply-decorators.d.ts +6 -0
- package/dist/core/apply-decorators.d.ts.map +1 -0
- package/dist/core/cluster.d.ts +47 -0
- package/dist/core/cluster.d.ts.map +1 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/server.d.ts +8 -0
- package/dist/core/server.d.ts.map +1 -1
- package/dist/dashboard/controller.d.ts +55 -0
- package/dist/dashboard/controller.d.ts.map +1 -0
- package/dist/dashboard/dashboard-extension.d.ts +20 -0
- package/dist/dashboard/dashboard-extension.d.ts.map +1 -0
- package/dist/dashboard/dashboard-module.d.ts +13 -0
- package/dist/dashboard/dashboard-module.d.ts.map +1 -0
- package/dist/dashboard/index.d.ts +4 -0
- package/dist/dashboard/index.d.ts.map +1 -0
- package/dist/dashboard/types.d.ts +16 -0
- package/dist/dashboard/types.d.ts.map +1 -0
- package/dist/dashboard/ui.d.ts +7 -0
- package/dist/dashboard/ui.d.ts.map +1 -0
- package/dist/database/database-module.d.ts +7 -0
- package/dist/database/database-module.d.ts.map +1 -1
- package/dist/debug/debug-module.d.ts +13 -0
- package/dist/debug/debug-module.d.ts.map +1 -0
- package/dist/debug/debug-ui-middleware.d.ts +8 -0
- package/dist/debug/debug-ui-middleware.d.ts.map +1 -0
- package/dist/debug/index.d.ts +5 -0
- package/dist/debug/index.d.ts.map +1 -0
- package/dist/debug/middleware.d.ts +12 -0
- package/dist/debug/middleware.d.ts.map +1 -0
- package/dist/debug/recorder.d.ts +61 -0
- package/dist/debug/recorder.d.ts.map +1 -0
- package/dist/debug/types.d.ts +48 -0
- package/dist/debug/types.d.ts.map +1 -0
- package/dist/debug/ui.d.ts +6 -0
- package/dist/debug/ui.d.ts.map +1 -0
- package/dist/di/async-module.d.ts +49 -0
- package/dist/di/async-module.d.ts.map +1 -0
- package/dist/di/lifecycle.d.ts +49 -0
- package/dist/di/lifecycle.d.ts.map +1 -0
- package/dist/di/module-registry.d.ts +24 -0
- package/dist/di/module-registry.d.ts.map +1 -1
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1887 -35
- package/dist/router/route.d.ts +5 -7
- package/dist/router/route.d.ts.map +1 -1
- package/dist/swagger/generator.d.ts +10 -0
- package/dist/swagger/generator.d.ts.map +1 -1
- package/dist/testing/test-client.d.ts +49 -0
- package/dist/testing/test-client.d.ts.map +1 -0
- package/dist/testing/testing-module.d.ts +90 -0
- package/dist/testing/testing-module.d.ts.map +1 -0
- package/dist/websocket/registry.d.ts +1 -6
- package/dist/websocket/registry.d.ts.map +1 -1
- package/docs/async-module.md +59 -0
- package/docs/client-generation.md +100 -0
- package/docs/cluster.md +81 -0
- package/docs/custom-decorators.md +1 -7
- package/docs/dashboard.md +54 -0
- package/docs/debug.md +58 -0
- package/docs/extensions.md +0 -2
- package/docs/guide.md +0 -1
- package/docs/lifecycle.md +72 -0
- package/docs/testing.md +110 -0
- package/docs/zh/async-module.md +98 -0
- package/docs/zh/client-generation.md +92 -0
- package/docs/zh/cluster.md +74 -0
- package/docs/zh/custom-decorators.md +1 -7
- package/docs/zh/dashboard.md +69 -0
- package/docs/zh/debug.md +81 -0
- package/docs/zh/extensions.md +0 -2
- package/docs/zh/guide.md +0 -1
- package/docs/zh/lifecycle.md +87 -0
- package/docs/zh/migration.md +0 -5
- package/docs/zh/testing.md +119 -0
- package/package.json +4 -4
- package/src/cache/cache-module.ts +25 -0
- package/src/client/generator.ts +36 -0
- package/src/client/index.ts +8 -0
- package/src/client/runtime.ts +101 -0
- package/src/client/types.ts +38 -0
- package/src/config/config-module.ts +44 -4
- package/src/config/index.ts +1 -0
- package/src/config/service.ts +50 -0
- package/src/config/types.ts +12 -0
- package/src/core/application.ts +37 -0
- package/src/core/apply-decorators.ts +31 -0
- package/src/core/cluster.ts +143 -0
- package/src/core/index.ts +1 -0
- package/src/core/server.ts +14 -1
- package/src/dashboard/controller.ts +227 -0
- package/src/dashboard/dashboard-extension.ts +26 -0
- package/src/dashboard/dashboard-module.ts +38 -0
- package/src/dashboard/index.ts +3 -0
- package/src/dashboard/types.ts +16 -0
- package/src/dashboard/ui.ts +219 -0
- package/src/database/database-module.ts +20 -0
- package/src/debug/debug-module.ts +70 -0
- package/src/debug/debug-ui-middleware.ts +110 -0
- package/src/debug/index.ts +9 -0
- package/src/debug/middleware.ts +126 -0
- package/src/debug/recorder.ts +141 -0
- package/src/debug/types.ts +49 -0
- package/src/debug/ui.ts +393 -0
- package/src/di/async-module.ts +141 -0
- package/src/di/lifecycle.ts +117 -0
- package/src/di/module-registry.ts +75 -0
- package/src/index.ts +35 -0
- package/src/router/route.ts +20 -20
- package/src/swagger/generator.ts +100 -0
- package/src/testing/test-client.ts +112 -0
- package/src/testing/testing-module.ts +238 -0
- package/src/websocket/registry.ts +3 -16
- package/tests/auth/auth-decorators.test.ts +0 -1
- package/tests/auth/oauth2-service.test.ts +0 -1
- package/tests/cache/cache-decorators-extended.test.ts +0 -1
- package/tests/cache/cache-decorators.test.ts +0 -1
- package/tests/cache/cache-interceptors.test.ts +0 -1
- package/tests/cache/cache-module.test.ts +0 -1
- package/tests/cache/cache-service-proxy.test.ts +0 -1
- package/tests/client/client-generator.test.ts +142 -0
- package/tests/config/config-center-integration.test.ts +0 -1
- package/tests/config/config-module-extended.test.ts +0 -1
- package/tests/config/config-module.test.ts +0 -1
- package/tests/controller/controller.test.ts +0 -1
- package/tests/controller/param-binder.test.ts +0 -1
- package/tests/controller/path-combination.test.ts +0 -1
- package/tests/core/application.test.ts +34 -0
- package/tests/core/apply-decorators.test.ts +109 -0
- package/tests/core/cluster.test.ts +32 -0
- package/tests/dashboard/dashboard-module.test.ts +85 -0
- package/tests/database/database-module.test.ts +0 -1
- package/tests/database/orm.test.ts +0 -1
- package/tests/database/postgres-mysql-integration.test.ts +0 -1
- package/tests/database/transaction.test.ts +0 -1
- package/tests/debug/debug-module.test.ts +141 -0
- package/tests/di/async-module.test.ts +125 -0
- package/tests/di/container.test.ts +0 -1
- package/tests/di/lifecycle.test.ts +140 -0
- package/tests/error/error-handler.test.ts +0 -1
- package/tests/events/event-decorators.test.ts +0 -1
- package/tests/events/event-listener-scanner.test.ts +0 -1
- package/tests/events/event-module.test.ts +0 -1
- package/tests/extensions/logger-module.test.ts +0 -1
- package/tests/health/health-module.test.ts +0 -1
- package/tests/integration/oauth2-e2e.test.ts +0 -1
- package/tests/integration/session-e2e.test.ts +0 -1
- package/tests/interceptor/base-interceptor.test.ts +0 -1
- package/tests/interceptor/builtin/cache-interceptor.test.ts +0 -1
- package/tests/interceptor/builtin/log-interceptor.test.ts +0 -1
- package/tests/interceptor/builtin/permission-interceptor.test.ts +0 -1
- package/tests/interceptor/interceptor-advanced-integration.test.ts +0 -1
- package/tests/interceptor/interceptor-chain.test.ts +0 -1
- package/tests/interceptor/interceptor-integration.test.ts +0 -1
- package/tests/interceptor/interceptor-metadata.test.ts +0 -1
- package/tests/interceptor/interceptor-registry.test.ts +0 -1
- package/tests/interceptor/perf/interceptor-performance.test.ts +0 -1
- package/tests/metrics/metrics-module.test.ts +0 -1
- package/tests/microservice/config-center.test.ts +0 -1
- package/tests/microservice/service-client-decorators.test.ts +0 -1
- package/tests/microservice/service-registry-decorators.test.ts +0 -1
- package/tests/microservice/service-registry.test.ts +0 -1
- package/tests/middleware/builtin/middleware-builtin-extended.test.ts +0 -1
- package/tests/middleware/builtin/rate-limit.test.ts +0 -1
- package/tests/middleware/middleware-decorators.test.ts +0 -1
- package/tests/middleware/middleware-pipeline.test.ts +0 -1
- package/tests/middleware/middleware.test.ts +0 -1
- package/tests/perf/optimization.test.ts +0 -1
- package/tests/queue/queue-decorators.test.ts +0 -1
- package/tests/queue/queue-module.test.ts +0 -1
- package/tests/queue/queue-service.test.ts +0 -1
- package/tests/router/router-decorators.test.ts +0 -1
- package/tests/router/router-extended.test.ts +0 -1
- package/tests/security/guards/guards-integration.test.ts +0 -1
- package/tests/security/guards/guards.test.ts +0 -1
- package/tests/security/guards/reflector.test.ts +0 -1
- package/tests/security/security-filter.test.ts +0 -1
- package/tests/security/security-module-extended.test.ts +0 -1
- package/tests/security/security-module.test.ts +0 -1
- package/tests/session/session-decorators.test.ts +0 -1
- package/tests/session/session-module.test.ts +0 -1
- package/tests/swagger/decorators.test.ts +0 -1
- package/tests/swagger/swagger-module.test.ts +0 -1
- package/tests/swagger/ui.test.ts +0 -1
- package/tests/testing/testing-module.test.ts +129 -0
- package/tests/validation/class-validator.test.ts +0 -1
- package/tests/validation/controller-validation.test.ts +0 -1
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { describe, expect, test, beforeEach } from 'bun:test';
|
|
2
|
-
import 'reflect-metadata';
|
|
3
2
|
|
|
4
3
|
import { Application } from '../../src/core/application';
|
|
5
4
|
import { MetricsModule, MetricsCollector, createHttpMetricsMiddleware, type CustomMetric } from '../../src/metrics';
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { describe, expect, test, beforeEach } from 'bun:test';
|
|
2
|
-
import 'reflect-metadata';
|
|
3
2
|
import { ConfigCenterModule, CONFIG_CENTER_TOKEN, type ConfigCenter } from '../../src/microservice/config-center';
|
|
4
3
|
import { Container } from '../../src/di/container';
|
|
5
4
|
import { ModuleRegistry } from '../../src/di/module-registry';
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { describe, expect, test, beforeEach } from 'bun:test';
|
|
2
|
-
import 'reflect-metadata';
|
|
3
2
|
import { ServiceRegistryModule, SERVICE_REGISTRY_TOKEN, type ServiceRegistry } from '../../src/microservice/service-registry';
|
|
4
3
|
import { MODULE_METADATA_KEY } from '../../src/di/module';
|
|
5
4
|
import { ControllerRegistry } from '../../src/controller/controller';
|
|
@@ -5,7 +5,6 @@ import { MiddlewarePipeline } from '../../src/middleware/pipeline';
|
|
|
5
5
|
import { Container } from '../../src/di/container';
|
|
6
6
|
import { Injectable, Inject } from '../../src/di/decorators';
|
|
7
7
|
import { PerformanceHarness } from '../../src/testing/harness';
|
|
8
|
-
import 'reflect-metadata';
|
|
9
8
|
|
|
10
9
|
/**
|
|
11
10
|
* 性能优化验证测试
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { describe, expect, test, beforeEach, afterEach } from 'bun:test';
|
|
2
|
-
import 'reflect-metadata';
|
|
3
2
|
import { Application } from '../../../src/core/application';
|
|
4
3
|
import { Controller } from '../../../src/controller';
|
|
5
4
|
import { GET, POST } from '../../../src/router/decorators';
|
|
@@ -3,7 +3,6 @@ import { SecurityModule } from '../../src/security/security-module';
|
|
|
3
3
|
import { MODULE_METADATA_KEY } from '../../src/di/module';
|
|
4
4
|
import { JWT_UTIL_TOKEN, OAUTH2_SERVICE_TOKEN } from '../../src/auth/controller';
|
|
5
5
|
import { AuthenticationManager } from '../../src/security/authentication-manager';
|
|
6
|
-
import 'reflect-metadata';
|
|
7
6
|
|
|
8
7
|
describe('SecurityModule', () => {
|
|
9
8
|
beforeEach(() => {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { describe, expect, test, beforeEach } from 'bun:test';
|
|
2
2
|
import { SwaggerModule } from '../../src/swagger/swagger-module';
|
|
3
3
|
import { MODULE_METADATA_KEY } from '../../src/di/module';
|
|
4
|
-
import 'reflect-metadata';
|
|
5
4
|
|
|
6
5
|
describe('SwaggerModule', () => {
|
|
7
6
|
beforeEach(() => {
|
package/tests/swagger/ui.test.ts
CHANGED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import { describe, expect, test, afterEach } from 'bun:test';
|
|
3
|
+
import { Test } from '../../src/testing/testing-module';
|
|
4
|
+
import { Injectable, Inject } from '../../src/di/decorators';
|
|
5
|
+
import { Controller } from '../../src/controller';
|
|
6
|
+
import { GET, POST } from '../../src/router/decorators';
|
|
7
|
+
import { Body } from '../../src/controller';
|
|
8
|
+
import type { TestHttpClient } from '../../src/testing/test-client';
|
|
9
|
+
|
|
10
|
+
const GREETER_TOKEN = Symbol('Greeter');
|
|
11
|
+
|
|
12
|
+
interface Greeter {
|
|
13
|
+
greet(name: string): string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@Injectable()
|
|
17
|
+
class RealGreeter implements Greeter {
|
|
18
|
+
public greet(name: string): string {
|
|
19
|
+
return `Hello, ${name}!`;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@Controller('/api/test')
|
|
24
|
+
class TestController {
|
|
25
|
+
public constructor(
|
|
26
|
+
@Inject(GREETER_TOKEN) private readonly greeter: Greeter,
|
|
27
|
+
) {}
|
|
28
|
+
|
|
29
|
+
@GET('/hello/:name')
|
|
30
|
+
public hello(): string {
|
|
31
|
+
return this.greeter.greet('World');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@GET('/ping')
|
|
35
|
+
public ping(): object {
|
|
36
|
+
return { pong: true };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@POST('/echo')
|
|
40
|
+
public echo(@Body() body: unknown): unknown {
|
|
41
|
+
return body;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
describe('TestingModule', () => {
|
|
46
|
+
let client: TestHttpClient | undefined;
|
|
47
|
+
|
|
48
|
+
afterEach(async () => {
|
|
49
|
+
if (client) {
|
|
50
|
+
await client.close();
|
|
51
|
+
client = undefined;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test('should create testing module and resolve providers', async () => {
|
|
56
|
+
const module = await Test.createTestingModule({
|
|
57
|
+
providers: [
|
|
58
|
+
{ provide: GREETER_TOKEN, useClass: RealGreeter },
|
|
59
|
+
],
|
|
60
|
+
}).compile();
|
|
61
|
+
|
|
62
|
+
const greeter = module.get<Greeter>(GREETER_TOKEN);
|
|
63
|
+
expect(greeter.greet('Test')).toBe('Hello, Test!');
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test('should override provider with useValue', async () => {
|
|
67
|
+
const mockGreeter: Greeter = {
|
|
68
|
+
greet: (name: string) => `Mock: ${name}`,
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const module = await Test.createTestingModule({
|
|
72
|
+
providers: [
|
|
73
|
+
{ provide: GREETER_TOKEN, useClass: RealGreeter },
|
|
74
|
+
],
|
|
75
|
+
})
|
|
76
|
+
.overrideProvider(GREETER_TOKEN)
|
|
77
|
+
.useValue(mockGreeter)
|
|
78
|
+
.compile();
|
|
79
|
+
|
|
80
|
+
const greeter = module.get<Greeter>(GREETER_TOKEN);
|
|
81
|
+
expect(greeter.greet('Test')).toBe('Mock: Test');
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test('should create HTTP client and handle GET', async () => {
|
|
85
|
+
const module = await Test.createTestingModule({
|
|
86
|
+
controllers: [TestController],
|
|
87
|
+
providers: [
|
|
88
|
+
{ provide: GREETER_TOKEN, useValue: { greet: () => 'test-response' } },
|
|
89
|
+
],
|
|
90
|
+
}).compile();
|
|
91
|
+
|
|
92
|
+
client = await module.createHttpClient();
|
|
93
|
+
|
|
94
|
+
const res = await client.get('/api/test/ping');
|
|
95
|
+
expect(res.status).toBe(200);
|
|
96
|
+
expect(res.body).toEqual({ pong: true });
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test('should create HTTP client and handle POST with body', async () => {
|
|
100
|
+
const module = await Test.createTestingModule({
|
|
101
|
+
controllers: [TestController],
|
|
102
|
+
providers: [
|
|
103
|
+
{ provide: GREETER_TOKEN, useValue: { greet: () => 'ok' } },
|
|
104
|
+
],
|
|
105
|
+
}).compile();
|
|
106
|
+
|
|
107
|
+
client = await module.createHttpClient();
|
|
108
|
+
|
|
109
|
+
const res = await client.post('/api/test/echo', {
|
|
110
|
+
body: { message: 'hello' },
|
|
111
|
+
});
|
|
112
|
+
expect(res.status).toBe(200);
|
|
113
|
+
expect(res.body).toEqual({ message: 'hello' });
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test('should override provider with useFactory', async () => {
|
|
117
|
+
const module = await Test.createTestingModule({
|
|
118
|
+
providers: [
|
|
119
|
+
{ provide: GREETER_TOKEN, useClass: RealGreeter },
|
|
120
|
+
],
|
|
121
|
+
})
|
|
122
|
+
.overrideProvider(GREETER_TOKEN)
|
|
123
|
+
.useFactory(() => ({ greet: (n: string) => `Factory: ${n}` }))
|
|
124
|
+
.compile();
|
|
125
|
+
|
|
126
|
+
const greeter = module.get<Greeter>(GREETER_TOKEN);
|
|
127
|
+
expect(greeter.greet('X')).toBe('Factory: X');
|
|
128
|
+
});
|
|
129
|
+
});
|