node-honest 0.0.1 → 0.1.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/index.cjs +2185 -0
- package/dist/index.d.cts +1539 -0
- package/dist/index.d.ts +1539 -16
- package/dist/index.js +2116 -15
- package/package.json +14 -11
- package/dist/app.d.ts +0 -1
- package/dist/app.js +0 -36
- package/dist/application/plugin-entries.d.ts +0 -13
- package/dist/application/plugin-entries.js +0 -38
- package/dist/application/startup-guide.d.ts +0 -4
- package/dist/application/startup-guide.js +0 -53
- package/dist/application-context.d.ts +0 -13
- package/dist/application-context.js +0 -22
- package/dist/application.d.ts +0 -34
- package/dist/application.js +0 -224
- package/dist/components/index.d.ts +0 -1
- package/dist/components/index.js +0 -1
- package/dist/components/layout.component.d.ts +0 -31
- package/dist/components/layout.component.js +0 -94
- package/dist/constants/index.d.ts +0 -2
- package/dist/constants/index.js +0 -2
- package/dist/constants/pipeline.constants.d.ts +0 -6
- package/dist/constants/pipeline.constants.js +0 -6
- package/dist/constants/version.constants.d.ts +0 -5
- package/dist/constants/version.constants.js +0 -5
- package/dist/decorators/controller.decorator.d.ts +0 -9
- package/dist/decorators/controller.decorator.js +0 -16
- package/dist/decorators/http-method.decorator.d.ts +0 -43
- package/dist/decorators/http-method.decorator.js +0 -44
- package/dist/decorators/index.d.ts +0 -11
- package/dist/decorators/index.js +0 -11
- package/dist/decorators/module.decorator.d.ts +0 -8
- package/dist/decorators/module.decorator.js +0 -12
- package/dist/decorators/mvc.decorator.d.ts +0 -26
- package/dist/decorators/mvc.decorator.js +0 -36
- package/dist/decorators/parameter.decorator.d.ts +0 -41
- package/dist/decorators/parameter.decorator.js +0 -59
- package/dist/decorators/service.decorator.d.ts +0 -6
- package/dist/decorators/service.decorator.js +0 -11
- package/dist/decorators/use-component.decorator.d.ts +0 -10
- package/dist/decorators/use-component.decorator.js +0 -19
- package/dist/decorators/use-filters.decorator.d.ts +0 -8
- package/dist/decorators/use-filters.decorator.js +0 -17
- package/dist/decorators/use-guards.decorator.d.ts +0 -9
- package/dist/decorators/use-guards.decorator.js +0 -18
- package/dist/decorators/use-middleware.decorator.d.ts +0 -9
- package/dist/decorators/use-middleware.decorator.js +0 -18
- package/dist/decorators/use-pipes.decorator.d.ts +0 -9
- package/dist/decorators/use-pipes.decorator.js +0 -18
- package/dist/di/container.d.ts +0 -34
- package/dist/di/container.js +0 -114
- package/dist/di/index.d.ts +0 -1
- package/dist/di/index.js +0 -1
- package/dist/errors/framework.error.d.ts +0 -19
- package/dist/errors/framework.error.js +0 -23
- package/dist/errors/index.d.ts +0 -1
- package/dist/errors/index.js +0 -1
- package/dist/handlers/error.handler.d.ts +0 -28
- package/dist/handlers/error.handler.js +0 -17
- package/dist/handlers/index.d.ts +0 -2
- package/dist/handlers/index.js +0 -2
- package/dist/handlers/not-found.handler.d.ts +0 -14
- package/dist/handlers/not-found.handler.js +0 -17
- package/dist/helpers/create-error-response.helper.d.ts +0 -25
- package/dist/helpers/create-error-response.helper.js +0 -90
- package/dist/helpers/create-http-method-decorator.helper.d.ts +0 -16
- package/dist/helpers/create-http-method-decorator.helper.js +0 -30
- package/dist/helpers/create-param-decorator.helper.d.ts +0 -16
- package/dist/helpers/create-param-decorator.helper.js +0 -60
- package/dist/helpers/index.d.ts +0 -3
- package/dist/helpers/index.js +0 -3
- package/dist/interfaces/application-context.interface.d.ts +0 -35
- package/dist/interfaces/application-context.interface.js +0 -1
- package/dist/interfaces/controller-options.interface.d.ts +0 -17
- package/dist/interfaces/controller-options.interface.js +0 -1
- package/dist/interfaces/di-container.interface.d.ts +0 -35
- package/dist/interfaces/di-container.interface.js +0 -1
- package/dist/interfaces/error-response.interface.d.ts +0 -13
- package/dist/interfaces/error-response.interface.js +0 -1
- package/dist/interfaces/filter.interface.d.ts +0 -20
- package/dist/interfaces/filter.interface.js +0 -1
- package/dist/interfaces/guard.interface.d.ts +0 -21
- package/dist/interfaces/guard.interface.js +0 -1
- package/dist/interfaces/handler-invocation.interface.d.ts +0 -10
- package/dist/interfaces/handler-invocation.interface.js +0 -1
- package/dist/interfaces/honest-options.interface.d.ts +0 -121
- package/dist/interfaces/honest-options.interface.js +0 -1
- package/dist/interfaces/http-method-options.interface.d.ts +0 -38
- package/dist/interfaces/http-method-options.interface.js +0 -1
- package/dist/interfaces/index.d.ts +0 -21
- package/dist/interfaces/index.js +0 -21
- package/dist/interfaces/logger.interface.d.ts +0 -23
- package/dist/interfaces/logger.interface.js +0 -1
- package/dist/interfaces/metadata-repository.interface.d.ts +0 -30
- package/dist/interfaces/metadata-repository.interface.js +0 -1
- package/dist/interfaces/middleware.interface.d.ts +0 -22
- package/dist/interfaces/middleware.interface.js +0 -1
- package/dist/interfaces/module-options.interface.d.ts +0 -18
- package/dist/interfaces/module-options.interface.js +0 -1
- package/dist/interfaces/parameter-metadata.interface.d.ts +0 -27
- package/dist/interfaces/parameter-metadata.interface.js +0 -1
- package/dist/interfaces/parameter-resolution.interface.d.ts +0 -14
- package/dist/interfaces/parameter-resolution.interface.js +0 -1
- package/dist/interfaces/pipe.interface.d.ts +0 -37
- package/dist/interfaces/pipe.interface.js +0 -1
- package/dist/interfaces/pipeline-context.interface.d.ts +0 -9
- package/dist/interfaces/pipeline-context.interface.js +0 -1
- package/dist/interfaces/plugin.interface.d.ts +0 -74
- package/dist/interfaces/plugin.interface.js +0 -1
- package/dist/interfaces/route-definition.interface.d.ts +0 -51
- package/dist/interfaces/route-definition.interface.js +0 -1
- package/dist/interfaces/route-info.interface.d.ts +0 -42
- package/dist/interfaces/route-info.interface.js +0 -1
- package/dist/interfaces/service-registry.interface.d.ts +0 -7
- package/dist/interfaces/service-registry.interface.js +0 -1
- package/dist/loggers/console.logger.d.ts +0 -7
- package/dist/loggers/console.logger.js +0 -21
- package/dist/loggers/index.d.ts +0 -2
- package/dist/loggers/index.js +0 -2
- package/dist/loggers/noop.logger.d.ts +0 -7
- package/dist/loggers/noop.logger.js +0 -8
- package/dist/managers/component.manager.d.ts +0 -48
- package/dist/managers/component.manager.js +0 -210
- package/dist/managers/handler.invoker.d.ts +0 -7
- package/dist/managers/handler.invoker.js +0 -37
- package/dist/managers/index.d.ts +0 -5
- package/dist/managers/index.js +0 -5
- package/dist/managers/parameter.resolver.d.ts +0 -13
- package/dist/managers/parameter.resolver.js +0 -58
- package/dist/managers/pipeline.executor.d.ts +0 -28
- package/dist/managers/pipeline.executor.js +0 -71
- package/dist/managers/route.manager.d.ts +0 -36
- package/dist/managers/route.manager.js +0 -149
- package/dist/registries/index.d.ts +0 -4
- package/dist/registries/index.js +0 -4
- package/dist/registries/metadata.registry.d.ts +0 -163
- package/dist/registries/metadata.registry.js +0 -250
- package/dist/registries/metadata.repository.d.ts +0 -30
- package/dist/registries/metadata.repository.js +0 -151
- package/dist/registries/route.registry.d.ts +0 -16
- package/dist/registries/route.registry.js +0 -46
- package/dist/registries/service.registry.d.ts +0 -8
- package/dist/registries/service.registry.js +0 -9
- package/dist/testing/create-controller-test-application.d.ts +0 -5
- package/dist/testing/create-controller-test-application.js +0 -11
- package/dist/testing/create-service-test-container.d.ts +0 -5
- package/dist/testing/create-service-test-container.js +0 -31
- package/dist/testing/create-test-application.d.ts +0 -5
- package/dist/testing/create-test-application.js +0 -20
- package/dist/testing/create-testing-module.d.ts +0 -6
- package/dist/testing/create-testing-module.js +0 -13
- package/dist/testing/fixtures/application-test-fixtures.d.ts +0 -17
- package/dist/testing/fixtures/application-test-fixtures.js +0 -230
- package/dist/testing/index.d.ts +0 -5
- package/dist/testing/index.js +0 -5
- package/dist/testing/testing.interface.d.ts +0 -96
- package/dist/testing/testing.interface.js +0 -1
- package/dist/types/constructor.type.d.ts +0 -12
- package/dist/types/constructor.type.js +0 -1
- package/dist/types/index.d.ts +0 -1
- package/dist/types/index.js +0 -1
- package/dist/utils/common.util.d.ts +0 -117
- package/dist/utils/common.util.js +0 -140
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.js +0 -1
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import { MetadataRegistry } from './metadata.registry';
|
|
2
|
-
/**
|
|
3
|
-
* Immutable metadata repository for a single Application instance.
|
|
4
|
-
* Captures a deep copy of all metadata reachable from a root module at creation time,
|
|
5
|
-
* isolating the application from later mutations to the static MetadataRegistry.
|
|
6
|
-
*/
|
|
7
|
-
export class MetadataRepository {
|
|
8
|
-
controllerPaths = new Map();
|
|
9
|
-
controllerOptions = new Map();
|
|
10
|
-
routes = new Map();
|
|
11
|
-
parameters = new Map();
|
|
12
|
-
contextIndices = new Map();
|
|
13
|
-
modules = new Map();
|
|
14
|
-
controllerComponents = new Map([
|
|
15
|
-
['middleware', new Map()],
|
|
16
|
-
['guard', new Map()],
|
|
17
|
-
['pipe', new Map()],
|
|
18
|
-
['filter', new Map()]
|
|
19
|
-
]);
|
|
20
|
-
handlerComponents = new Map([
|
|
21
|
-
['middleware', new Map()],
|
|
22
|
-
['guard', new Map()],
|
|
23
|
-
['pipe', new Map()],
|
|
24
|
-
['filter', new Map()]
|
|
25
|
-
]);
|
|
26
|
-
static fromRootModule(rootModule) {
|
|
27
|
-
const snapshot = new MetadataRepository();
|
|
28
|
-
snapshot.captureModuleGraph(rootModule);
|
|
29
|
-
return snapshot;
|
|
30
|
-
}
|
|
31
|
-
hasController(controller) {
|
|
32
|
-
return this.controllerPaths.has(controller);
|
|
33
|
-
}
|
|
34
|
-
getControllerPath(controller) {
|
|
35
|
-
return this.controllerPaths.get(controller) || '';
|
|
36
|
-
}
|
|
37
|
-
getControllerOptions(controller) {
|
|
38
|
-
const options = this.controllerOptions.get(controller);
|
|
39
|
-
return options ? { ...options } : {};
|
|
40
|
-
}
|
|
41
|
-
getRoutes(controller) {
|
|
42
|
-
return (this.routes.get(controller) || []).map((route) => this.cloneRouteDefinition(route));
|
|
43
|
-
}
|
|
44
|
-
getParameters(controller) {
|
|
45
|
-
const parameters = this.parameters.get(controller);
|
|
46
|
-
if (!parameters) {
|
|
47
|
-
return new Map();
|
|
48
|
-
}
|
|
49
|
-
const cloned = new Map();
|
|
50
|
-
for (const [handlerName, entries] of parameters.entries()) {
|
|
51
|
-
cloned.set(handlerName, entries.map((entry) => ({ ...entry })));
|
|
52
|
-
}
|
|
53
|
-
return cloned;
|
|
54
|
-
}
|
|
55
|
-
getContextIndices(controller) {
|
|
56
|
-
return new Map(this.contextIndices.get(controller) || new Map());
|
|
57
|
-
}
|
|
58
|
-
getModuleOptions(module) {
|
|
59
|
-
const options = this.modules.get(module);
|
|
60
|
-
if (!options) {
|
|
61
|
-
return undefined;
|
|
62
|
-
}
|
|
63
|
-
return {
|
|
64
|
-
controllers: options.controllers ? [...options.controllers] : undefined,
|
|
65
|
-
services: options.services ? [...options.services] : undefined,
|
|
66
|
-
imports: options.imports ? [...options.imports] : undefined
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
getControllerComponents(type, controller) {
|
|
70
|
-
const map = this.controllerComponents.get(type);
|
|
71
|
-
const components = (map.get(controller) || []);
|
|
72
|
-
return [...components];
|
|
73
|
-
}
|
|
74
|
-
getHandlerComponents(type, controller, handlerName) {
|
|
75
|
-
const typeMap = this.handlerComponents.get(type);
|
|
76
|
-
const controllerMap = typeMap.get(controller);
|
|
77
|
-
if (!controllerMap) {
|
|
78
|
-
return [];
|
|
79
|
-
}
|
|
80
|
-
const components = (controllerMap.get(handlerName) || []);
|
|
81
|
-
return [...components];
|
|
82
|
-
}
|
|
83
|
-
captureModuleGraph(rootModule) {
|
|
84
|
-
const visitedModules = new Set();
|
|
85
|
-
const controllers = new Set();
|
|
86
|
-
const visitModule = (moduleClass) => {
|
|
87
|
-
if (visitedModules.has(moduleClass)) {
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
visitedModules.add(moduleClass);
|
|
91
|
-
const moduleOptions = MetadataRegistry.getModuleOptions(moduleClass);
|
|
92
|
-
if (!moduleOptions) {
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
const moduleSnapshot = {
|
|
96
|
-
controllers: moduleOptions.controllers ? [...moduleOptions.controllers] : undefined,
|
|
97
|
-
services: moduleOptions.services ? [...moduleOptions.services] : undefined,
|
|
98
|
-
imports: moduleOptions.imports ? [...moduleOptions.imports] : undefined
|
|
99
|
-
};
|
|
100
|
-
this.modules.set(moduleClass, moduleSnapshot);
|
|
101
|
-
for (const controller of moduleSnapshot.controllers || []) {
|
|
102
|
-
controllers.add(controller);
|
|
103
|
-
}
|
|
104
|
-
for (const importedModule of moduleSnapshot.imports || []) {
|
|
105
|
-
visitModule(importedModule);
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
visitModule(rootModule);
|
|
109
|
-
for (const controller of controllers) {
|
|
110
|
-
this.captureController(controller);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
captureController(controller) {
|
|
114
|
-
if (!MetadataRegistry.hasController(controller)) {
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
this.controllerPaths.set(controller, MetadataRegistry.getControllerPath(controller) || '');
|
|
118
|
-
this.controllerOptions.set(controller, { ...MetadataRegistry.getControllerOptions(controller) });
|
|
119
|
-
const routes = (MetadataRegistry.getRoutes(controller) || []).map((route) => this.cloneRouteDefinition(route));
|
|
120
|
-
this.routes.set(controller, routes);
|
|
121
|
-
const parameters = MetadataRegistry.getParameters(controller);
|
|
122
|
-
const parameterSnapshot = new Map();
|
|
123
|
-
for (const [handlerName, entries] of parameters.entries()) {
|
|
124
|
-
parameterSnapshot.set(handlerName, (entries || []).map((entry) => ({ ...entry })));
|
|
125
|
-
}
|
|
126
|
-
this.parameters.set(controller, parameterSnapshot);
|
|
127
|
-
this.contextIndices.set(controller, new Map(MetadataRegistry.getContextIndices(controller) || new Map()));
|
|
128
|
-
for (const type of ['middleware', 'guard', 'pipe', 'filter']) {
|
|
129
|
-
const controllerMap = this.controllerComponents.get(type);
|
|
130
|
-
controllerMap.set(controller, [...(MetadataRegistry.getController(type, controller) || [])]);
|
|
131
|
-
}
|
|
132
|
-
for (const route of routes) {
|
|
133
|
-
for (const type of ['middleware', 'guard', 'pipe', 'filter']) {
|
|
134
|
-
const typeMap = this.handlerComponents.get(type);
|
|
135
|
-
if (!typeMap.has(controller)) {
|
|
136
|
-
typeMap.set(controller, new Map());
|
|
137
|
-
}
|
|
138
|
-
const controllerHandlers = typeMap.get(controller);
|
|
139
|
-
controllerHandlers.set(route.handlerName, [
|
|
140
|
-
...MetadataRegistry.getHandler(type, controller, route.handlerName)
|
|
141
|
-
]);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
cloneRouteDefinition(route) {
|
|
146
|
-
return {
|
|
147
|
-
...route,
|
|
148
|
-
version: Array.isArray(route.version) ? [...route.version] : route.version
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { RouteInfo } from '../interfaces';
|
|
2
|
-
/**
|
|
3
|
-
* Registry for managing and querying route information in the application.
|
|
4
|
-
*
|
|
5
|
-
* Each Application instance owns its own RouteRegistry, ensuring routes
|
|
6
|
-
* from one app never leak into another.
|
|
7
|
-
*/
|
|
8
|
-
export declare class RouteRegistry {
|
|
9
|
-
private readonly routes;
|
|
10
|
-
registerRoute(routeInfo: RouteInfo): void;
|
|
11
|
-
getRoutes(): ReadonlyArray<RouteInfo>;
|
|
12
|
-
getRoutesByController(controllerName: string | symbol): ReadonlyArray<RouteInfo>;
|
|
13
|
-
getRoutesByMethod(method: string): ReadonlyArray<RouteInfo>;
|
|
14
|
-
getRoutesByPath(pattern: RegExp): ReadonlyArray<RouteInfo>;
|
|
15
|
-
clear(): void;
|
|
16
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Registry for managing and querying route information in the application.
|
|
3
|
-
*
|
|
4
|
-
* Each Application instance owns its own RouteRegistry, ensuring routes
|
|
5
|
-
* from one app never leak into another.
|
|
6
|
-
*/
|
|
7
|
-
export class RouteRegistry {
|
|
8
|
-
routes = [];
|
|
9
|
-
registerRoute(routeInfo) {
|
|
10
|
-
if (!routeInfo) {
|
|
11
|
-
throw new Error('Route info is required');
|
|
12
|
-
}
|
|
13
|
-
if (!routeInfo.controller) {
|
|
14
|
-
throw new Error('Route controller is required');
|
|
15
|
-
}
|
|
16
|
-
if (!routeInfo.handler) {
|
|
17
|
-
throw new Error('Route handler is required');
|
|
18
|
-
}
|
|
19
|
-
if (!routeInfo.method) {
|
|
20
|
-
throw new Error('Route method is required');
|
|
21
|
-
}
|
|
22
|
-
if (!routeInfo.fullPath) {
|
|
23
|
-
throw new Error('Route fullPath is required');
|
|
24
|
-
}
|
|
25
|
-
const isDuplicate = this.routes.some((route) => route.fullPath === routeInfo.fullPath && route.method.toUpperCase() === routeInfo.method.toUpperCase());
|
|
26
|
-
if (isDuplicate) {
|
|
27
|
-
throw new Error(`Duplicate route detected: ${routeInfo.method.toUpperCase()} ${routeInfo.fullPath} (${String(routeInfo.controller)}.${String(routeInfo.handler)})`);
|
|
28
|
-
}
|
|
29
|
-
this.routes.push(routeInfo);
|
|
30
|
-
}
|
|
31
|
-
getRoutes() {
|
|
32
|
-
return this.routes;
|
|
33
|
-
}
|
|
34
|
-
getRoutesByController(controllerName) {
|
|
35
|
-
return this.routes.filter((route) => route.controller === controllerName);
|
|
36
|
-
}
|
|
37
|
-
getRoutesByMethod(method) {
|
|
38
|
-
return this.routes.filter((route) => route.method.toUpperCase() === method.toUpperCase());
|
|
39
|
-
}
|
|
40
|
-
getRoutesByPath(pattern) {
|
|
41
|
-
return this.routes.filter((route) => pattern.test(route.fullPath));
|
|
42
|
-
}
|
|
43
|
-
clear() {
|
|
44
|
-
this.routes.length = 0;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { IServiceRegistry } from '../interfaces';
|
|
2
|
-
import type { Constructor } from '../types';
|
|
3
|
-
/**
|
|
4
|
-
* Adapter exposing service checks through the DI service registry contract.
|
|
5
|
-
*/
|
|
6
|
-
export declare class StaticServiceRegistry implements IServiceRegistry {
|
|
7
|
-
isService(service: Constructor): boolean;
|
|
8
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { CreateControllerTestApplicationOptions, TestApplication } from './testing.interface';
|
|
2
|
-
/**
|
|
3
|
-
* Create a test application for a single controller with optional services/imports.
|
|
4
|
-
*/
|
|
5
|
-
export declare function createControllerTestApplication(options: CreateControllerTestApplicationOptions): Promise<TestApplication>;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { createTestApplication } from './create-test-application';
|
|
2
|
-
/**
|
|
3
|
-
* Create a test application for a single controller with optional services/imports.
|
|
4
|
-
*/
|
|
5
|
-
export async function createControllerTestApplication(options) {
|
|
6
|
-
const { controller, ...rest } = options;
|
|
7
|
-
return createTestApplication({
|
|
8
|
-
...rest,
|
|
9
|
-
controllers: [controller]
|
|
10
|
-
});
|
|
11
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { CreateServiceTestContainerOptions, TestServiceContainer } from './testing.interface';
|
|
2
|
-
/**
|
|
3
|
-
* Create a lightweight DI container for service-only tests without HTTP bootstrap.
|
|
4
|
-
*/
|
|
5
|
-
export declare function createServiceTestContainer(options?: CreateServiceTestContainerOptions): TestServiceContainer;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { NoopLogger } from '../loggers';
|
|
2
|
-
import { Container } from '../di';
|
|
3
|
-
/**
|
|
4
|
-
* Create a lightweight DI container for service-only tests without HTTP bootstrap.
|
|
5
|
-
*/
|
|
6
|
-
export function createServiceTestContainer(options = {}) {
|
|
7
|
-
const logger = options.logger ?? new NoopLogger();
|
|
8
|
-
const container = new Container(undefined, logger, Boolean(options.debugDi));
|
|
9
|
-
for (const override of options.overrides ?? []) {
|
|
10
|
-
const typedOverride = override;
|
|
11
|
-
container.register(typedOverride.provide, typedOverride.useValue);
|
|
12
|
-
}
|
|
13
|
-
for (const service of options.preload ?? []) {
|
|
14
|
-
container.resolve(service);
|
|
15
|
-
}
|
|
16
|
-
return {
|
|
17
|
-
container,
|
|
18
|
-
get(target) {
|
|
19
|
-
return container.resolve(target);
|
|
20
|
-
},
|
|
21
|
-
register(target, instance) {
|
|
22
|
-
container.register(target, instance);
|
|
23
|
-
},
|
|
24
|
-
has(target) {
|
|
25
|
-
return container.has(target);
|
|
26
|
-
},
|
|
27
|
-
clear() {
|
|
28
|
-
container.clear();
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { CreateTestApplicationOptions, TestApplication } from './testing.interface';
|
|
2
|
-
/**
|
|
3
|
-
* Create a test-friendly application instance with a convenience request helper.
|
|
4
|
-
*/
|
|
5
|
-
export declare function createTestApplication(options?: CreateTestApplicationOptions): Promise<TestApplication>;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Application } from '../application';
|
|
2
|
-
import { createTestingModule } from './create-testing-module';
|
|
3
|
-
/**
|
|
4
|
-
* Create a test-friendly application instance with a convenience request helper.
|
|
5
|
-
*/
|
|
6
|
-
export async function createTestApplication(options = {}) {
|
|
7
|
-
const { module, appOptions, ...moduleOptions } = options;
|
|
8
|
-
const rootModule = (module ?? createTestingModule(moduleOptions));
|
|
9
|
-
const { app, hono } = await Application.create(rootModule, appOptions);
|
|
10
|
-
const request = (input, init) => {
|
|
11
|
-
if (typeof input === 'string') {
|
|
12
|
-
const normalizedInput = input.startsWith('http://') || input.startsWith('https://')
|
|
13
|
-
? input
|
|
14
|
-
: `http://localhost${input.startsWith('/') ? input : `/${input}`}`;
|
|
15
|
-
return Promise.resolve(hono.request(normalizedInput, init));
|
|
16
|
-
}
|
|
17
|
-
return Promise.resolve(hono.request(input));
|
|
18
|
-
};
|
|
19
|
-
return { app, hono, request };
|
|
20
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { Constructor } from '../types';
|
|
2
|
-
import type { TestModuleOptions } from './testing.interface';
|
|
3
|
-
/**
|
|
4
|
-
* Create a runtime module class for tests without boilerplate.
|
|
5
|
-
*/
|
|
6
|
-
export declare function createTestingModule(options?: TestModuleOptions): Constructor;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Module } from '../decorators';
|
|
2
|
-
/**
|
|
3
|
-
* Create a runtime module class for tests without boilerplate.
|
|
4
|
-
*/
|
|
5
|
-
export function createTestingModule(options = {}) {
|
|
6
|
-
const { controllers, services, imports, name = 'TestModule' } = options;
|
|
7
|
-
const dynamicModule = {
|
|
8
|
-
[name]: class {
|
|
9
|
-
}
|
|
10
|
-
}[name];
|
|
11
|
-
Module({ controllers, services, imports })(dynamicModule);
|
|
12
|
-
return dynamicModule;
|
|
13
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { Constructor } from '../../types';
|
|
2
|
-
export declare function createTestController(): Constructor;
|
|
3
|
-
export declare function createPayloadController(): Constructor;
|
|
4
|
-
export declare function createRawResponseController(): Constructor;
|
|
5
|
-
export declare function createOnlyAController(): Constructor;
|
|
6
|
-
export declare function createOnlyBController(): Constructor;
|
|
7
|
-
export declare function createUndecoratedController(): Constructor;
|
|
8
|
-
export declare function createBrokenControllerModule(): Constructor;
|
|
9
|
-
export declare function createEmptyModule(): Constructor;
|
|
10
|
-
export declare function createDuplicateRouteControllers(): {
|
|
11
|
-
a: Constructor;
|
|
12
|
-
b: Constructor;
|
|
13
|
-
};
|
|
14
|
-
export declare function createUnsafeParamController(): Constructor;
|
|
15
|
-
export declare function createDiagnosticsAController(): Constructor;
|
|
16
|
-
export declare function createDiagnosticsBController(): Constructor;
|
|
17
|
-
export declare function createRuntimeMetadataController(): Constructor;
|
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
-
};
|
|
13
|
-
import { Body, Controller, Get, Module, Post } from '../../decorators';
|
|
14
|
-
import { createParamDecorator } from '../../helpers';
|
|
15
|
-
export function createTestController() {
|
|
16
|
-
let TestController = class TestController {
|
|
17
|
-
index() {
|
|
18
|
-
return { ok: true };
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
__decorate([
|
|
22
|
-
Get(),
|
|
23
|
-
__metadata("design:type", Function),
|
|
24
|
-
__metadata("design:paramtypes", []),
|
|
25
|
-
__metadata("design:returntype", void 0)
|
|
26
|
-
], TestController.prototype, "index", null);
|
|
27
|
-
TestController = __decorate([
|
|
28
|
-
Controller('/health')
|
|
29
|
-
], TestController);
|
|
30
|
-
return TestController;
|
|
31
|
-
}
|
|
32
|
-
export function createPayloadController() {
|
|
33
|
-
let PayloadController = class PayloadController {
|
|
34
|
-
async echo(a, b) {
|
|
35
|
-
return { a, b };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
__decorate([
|
|
39
|
-
Post('echo'),
|
|
40
|
-
__param(0, Body('a')),
|
|
41
|
-
__param(1, Body('b')),
|
|
42
|
-
__metadata("design:type", Function),
|
|
43
|
-
__metadata("design:paramtypes", [String, String]),
|
|
44
|
-
__metadata("design:returntype", Promise)
|
|
45
|
-
], PayloadController.prototype, "echo", null);
|
|
46
|
-
PayloadController = __decorate([
|
|
47
|
-
Controller('/payload')
|
|
48
|
-
], PayloadController);
|
|
49
|
-
return PayloadController;
|
|
50
|
-
}
|
|
51
|
-
export function createRawResponseController() {
|
|
52
|
-
let RawResponseController = class RawResponseController {
|
|
53
|
-
raw() {
|
|
54
|
-
return new Response('raw-ok', {
|
|
55
|
-
status: 201,
|
|
56
|
-
headers: { 'x-honest': 'yes' }
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
__decorate([
|
|
61
|
-
Get(),
|
|
62
|
-
__metadata("design:type", Function),
|
|
63
|
-
__metadata("design:paramtypes", []),
|
|
64
|
-
__metadata("design:returntype", void 0)
|
|
65
|
-
], RawResponseController.prototype, "raw", null);
|
|
66
|
-
RawResponseController = __decorate([
|
|
67
|
-
Controller('/raw')
|
|
68
|
-
], RawResponseController);
|
|
69
|
-
return RawResponseController;
|
|
70
|
-
}
|
|
71
|
-
export function createOnlyAController() {
|
|
72
|
-
let OnlyAController = class OnlyAController {
|
|
73
|
-
index() {
|
|
74
|
-
return { app: 'a' };
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
__decorate([
|
|
78
|
-
Get(),
|
|
79
|
-
__metadata("design:type", Function),
|
|
80
|
-
__metadata("design:paramtypes", []),
|
|
81
|
-
__metadata("design:returntype", void 0)
|
|
82
|
-
], OnlyAController.prototype, "index", null);
|
|
83
|
-
OnlyAController = __decorate([
|
|
84
|
-
Controller('/only-a')
|
|
85
|
-
], OnlyAController);
|
|
86
|
-
return OnlyAController;
|
|
87
|
-
}
|
|
88
|
-
export function createOnlyBController() {
|
|
89
|
-
let OnlyBController = class OnlyBController {
|
|
90
|
-
index() {
|
|
91
|
-
return { app: 'b' };
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
__decorate([
|
|
95
|
-
Get(),
|
|
96
|
-
__metadata("design:type", Function),
|
|
97
|
-
__metadata("design:paramtypes", []),
|
|
98
|
-
__metadata("design:returntype", void 0)
|
|
99
|
-
], OnlyBController.prototype, "index", null);
|
|
100
|
-
OnlyBController = __decorate([
|
|
101
|
-
Controller('/only-b')
|
|
102
|
-
], OnlyBController);
|
|
103
|
-
return OnlyBController;
|
|
104
|
-
}
|
|
105
|
-
export function createUndecoratedController() {
|
|
106
|
-
class UndecoratedController {
|
|
107
|
-
hello() {
|
|
108
|
-
return 'hello';
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
return UndecoratedController;
|
|
112
|
-
}
|
|
113
|
-
export function createBrokenControllerModule() {
|
|
114
|
-
const UndecoratedController = createUndecoratedController();
|
|
115
|
-
let BrokenControllerModule = class BrokenControllerModule {
|
|
116
|
-
};
|
|
117
|
-
BrokenControllerModule = __decorate([
|
|
118
|
-
Module({ controllers: [UndecoratedController] })
|
|
119
|
-
], BrokenControllerModule);
|
|
120
|
-
return BrokenControllerModule;
|
|
121
|
-
}
|
|
122
|
-
export function createEmptyModule() {
|
|
123
|
-
let EmptyModule = class EmptyModule {
|
|
124
|
-
};
|
|
125
|
-
EmptyModule = __decorate([
|
|
126
|
-
Module()
|
|
127
|
-
], EmptyModule);
|
|
128
|
-
return EmptyModule;
|
|
129
|
-
}
|
|
130
|
-
export function createDuplicateRouteControllers() {
|
|
131
|
-
let DuplicateAController = class DuplicateAController {
|
|
132
|
-
index() {
|
|
133
|
-
return { ok: 'a' };
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
__decorate([
|
|
137
|
-
Get(),
|
|
138
|
-
__metadata("design:type", Function),
|
|
139
|
-
__metadata("design:paramtypes", []),
|
|
140
|
-
__metadata("design:returntype", void 0)
|
|
141
|
-
], DuplicateAController.prototype, "index", null);
|
|
142
|
-
DuplicateAController = __decorate([
|
|
143
|
-
Controller('/dup')
|
|
144
|
-
], DuplicateAController);
|
|
145
|
-
let DuplicateBController = class DuplicateBController {
|
|
146
|
-
index() {
|
|
147
|
-
return { ok: 'b' };
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
__decorate([
|
|
151
|
-
Get(),
|
|
152
|
-
__metadata("design:type", Function),
|
|
153
|
-
__metadata("design:paramtypes", []),
|
|
154
|
-
__metadata("design:returntype", void 0)
|
|
155
|
-
], DuplicateBController.prototype, "index", null);
|
|
156
|
-
DuplicateBController = __decorate([
|
|
157
|
-
Controller('/dup')
|
|
158
|
-
], DuplicateBController);
|
|
159
|
-
return { a: DuplicateAController, b: DuplicateBController };
|
|
160
|
-
}
|
|
161
|
-
export function createUnsafeParamController() {
|
|
162
|
-
const unsafeParam = createParamDecorator('unsafe');
|
|
163
|
-
let UnsafeParamController = class UnsafeParamController {
|
|
164
|
-
check(value) {
|
|
165
|
-
return { hasValue: value !== undefined };
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
__decorate([
|
|
169
|
-
Get(),
|
|
170
|
-
__param(0, unsafeParam()),
|
|
171
|
-
__metadata("design:type", Function),
|
|
172
|
-
__metadata("design:paramtypes", [Object]),
|
|
173
|
-
__metadata("design:returntype", void 0)
|
|
174
|
-
], UnsafeParamController.prototype, "check", null);
|
|
175
|
-
UnsafeParamController = __decorate([
|
|
176
|
-
Controller('/unsafe')
|
|
177
|
-
], UnsafeParamController);
|
|
178
|
-
return UnsafeParamController;
|
|
179
|
-
}
|
|
180
|
-
export function createDiagnosticsAController() {
|
|
181
|
-
let DiagnosticsAController = class DiagnosticsAController {
|
|
182
|
-
index() {
|
|
183
|
-
return { controller: 'a' };
|
|
184
|
-
}
|
|
185
|
-
};
|
|
186
|
-
__decorate([
|
|
187
|
-
Get(),
|
|
188
|
-
__metadata("design:type", Function),
|
|
189
|
-
__metadata("design:paramtypes", []),
|
|
190
|
-
__metadata("design:returntype", void 0)
|
|
191
|
-
], DiagnosticsAController.prototype, "index", null);
|
|
192
|
-
DiagnosticsAController = __decorate([
|
|
193
|
-
Controller('/diag-a')
|
|
194
|
-
], DiagnosticsAController);
|
|
195
|
-
return DiagnosticsAController;
|
|
196
|
-
}
|
|
197
|
-
export function createDiagnosticsBController() {
|
|
198
|
-
let DiagnosticsBController = class DiagnosticsBController {
|
|
199
|
-
index() {
|
|
200
|
-
return { controller: 'b' };
|
|
201
|
-
}
|
|
202
|
-
};
|
|
203
|
-
__decorate([
|
|
204
|
-
Get(),
|
|
205
|
-
__metadata("design:type", Function),
|
|
206
|
-
__metadata("design:paramtypes", []),
|
|
207
|
-
__metadata("design:returntype", void 0)
|
|
208
|
-
], DiagnosticsBController.prototype, "index", null);
|
|
209
|
-
DiagnosticsBController = __decorate([
|
|
210
|
-
Controller('/diag-b')
|
|
211
|
-
], DiagnosticsBController);
|
|
212
|
-
return DiagnosticsBController;
|
|
213
|
-
}
|
|
214
|
-
export function createRuntimeMetadataController() {
|
|
215
|
-
let RuntimeMetadataController = class RuntimeMetadataController {
|
|
216
|
-
index() {
|
|
217
|
-
throw new Error('runtime metadata baseline error');
|
|
218
|
-
}
|
|
219
|
-
};
|
|
220
|
-
__decorate([
|
|
221
|
-
Get(),
|
|
222
|
-
__metadata("design:type", Function),
|
|
223
|
-
__metadata("design:paramtypes", []),
|
|
224
|
-
__metadata("design:returntype", void 0)
|
|
225
|
-
], RuntimeMetadataController.prototype, "index", null);
|
|
226
|
-
RuntimeMetadataController = __decorate([
|
|
227
|
-
Controller('/runtime-metadata')
|
|
228
|
-
], RuntimeMetadataController);
|
|
229
|
-
return RuntimeMetadataController;
|
|
230
|
-
}
|
package/dist/testing/index.d.ts
DELETED