@navios/core 0.6.0 → 0.7.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/CHANGELOG.md +93 -0
- package/README.md +18 -1
- package/docs/README.md +1 -0
- package/docs/legacy-compat.md +320 -0
- package/docs/testing.md +140 -17
- package/lib/index-BFwNx9WQ.d.cts +1951 -0
- package/lib/index-BFwNx9WQ.d.cts.map +1 -0
- package/lib/index-D657ijFO.d.mts +1951 -0
- package/lib/index-D657ijFO.d.mts.map +1 -0
- package/lib/index.cjs +157 -0
- package/lib/index.d.cts +3 -0
- package/lib/index.d.mts +3 -190
- package/lib/index.mjs +4 -1459
- package/lib/legacy-compat/index.cjs +315 -0
- package/lib/legacy-compat/index.cjs.map +1 -0
- package/lib/legacy-compat/index.d.cts +219 -0
- package/lib/legacy-compat/index.d.cts.map +1 -0
- package/lib/legacy-compat/index.d.mts +219 -0
- package/lib/legacy-compat/index.d.mts.map +1 -0
- package/lib/legacy-compat/index.mjs +308 -0
- package/lib/legacy-compat/index.mjs.map +1 -0
- package/lib/src-Cb1aTjl0.cjs +5710 -0
- package/lib/src-Cb1aTjl0.cjs.map +1 -0
- package/lib/src-DzPY5s6d.mjs +5353 -0
- package/lib/src-DzPY5s6d.mjs.map +1 -0
- package/lib/testing/index.cjs +106 -0
- package/lib/testing/index.cjs.map +1 -0
- package/lib/testing/index.d.cts +156 -0
- package/lib/testing/index.d.cts.map +1 -0
- package/lib/testing/index.d.mts +156 -0
- package/lib/testing/index.d.mts.map +1 -0
- package/lib/testing/index.mjs +100 -0
- package/lib/testing/index.mjs.map +1 -0
- package/lib/use-guards.decorator-DdvUhB03.cjs +622 -0
- package/lib/use-guards.decorator-DdvUhB03.cjs.map +1 -0
- package/lib/use-guards.decorator-kZ3lNK8v.mjs +454 -0
- package/lib/use-guards.decorator-kZ3lNK8v.mjs.map +1 -0
- package/package.json +24 -4
- package/project.json +2 -2
- package/src/attribute.factory.d.mts +175 -0
- package/src/attribute.factory.d.mts.map +1 -0
- package/src/attribute.factory.mts +154 -0
- package/src/config/config-service.interface.d.mts +39 -0
- package/src/config/config-service.interface.d.mts.map +1 -0
- package/src/config/config-service.interface.mts +31 -0
- package/src/config/config.provider.d.mts +46 -0
- package/src/config/config.provider.d.mts.map +1 -0
- package/src/config/config.provider.mts +36 -0
- package/src/config/config.service.d.mts +108 -0
- package/src/config/config.service.d.mts.map +1 -0
- package/src/config/config.service.mts +94 -4
- package/src/config/index.d.mts +6 -0
- package/src/config/index.d.mts.map +1 -0
- package/src/config/types.d.mts +13 -0
- package/src/config/types.d.mts.map +1 -0
- package/src/config/utils/helpers.d.mts +3 -0
- package/src/config/utils/helpers.d.mts.map +1 -0
- package/src/config/utils/index.d.mts +2 -0
- package/src/config/utils/index.d.mts.map +1 -0
- package/src/decorators/controller.decorator.d.mts +33 -0
- package/src/decorators/controller.decorator.d.mts.map +1 -0
- package/src/decorators/controller.decorator.mts +28 -0
- package/src/decorators/endpoint.decorator.d.mts +89 -0
- package/src/decorators/endpoint.decorator.d.mts.map +1 -0
- package/src/decorators/endpoint.decorator.mts +76 -0
- package/src/decorators/header.decorator.d.mts +22 -0
- package/src/decorators/header.decorator.d.mts.map +1 -0
- package/src/decorators/header.decorator.mts +19 -0
- package/src/decorators/http-code.decorator.d.mts +22 -0
- package/src/decorators/http-code.decorator.d.mts.map +1 -0
- package/src/decorators/http-code.decorator.mts +20 -0
- package/src/decorators/index.d.mts +9 -0
- package/src/decorators/index.d.mts.map +1 -0
- package/src/decorators/module.decorator.d.mts +42 -0
- package/src/decorators/module.decorator.d.mts.map +1 -0
- package/src/decorators/module.decorator.mts +34 -0
- package/src/decorators/multipart.decorator.d.mts +54 -0
- package/src/decorators/multipart.decorator.d.mts.map +1 -0
- package/src/decorators/multipart.decorator.mts +41 -0
- package/src/decorators/stream.decorator.d.mts +42 -0
- package/src/decorators/stream.decorator.d.mts.map +1 -0
- package/src/decorators/stream.decorator.mts +33 -0
- package/src/decorators/use-guards.decorator.d.mts +33 -0
- package/src/decorators/use-guards.decorator.d.mts.map +1 -0
- package/src/decorators/use-guards.decorator.mts +29 -0
- package/src/exceptions/bad-request.exception.d.mts +26 -0
- package/src/exceptions/bad-request.exception.d.mts.map +1 -0
- package/src/exceptions/bad-request.exception.mts +21 -0
- package/src/exceptions/conflict.exception.d.mts +29 -0
- package/src/exceptions/conflict.exception.d.mts.map +1 -0
- package/src/exceptions/conflict.exception.mts +24 -0
- package/src/exceptions/forbidden.exception.d.mts +28 -0
- package/src/exceptions/forbidden.exception.d.mts.map +1 -0
- package/src/exceptions/forbidden.exception.mts +23 -0
- package/src/exceptions/http.exception.d.mts +33 -0
- package/src/exceptions/http.exception.d.mts.map +1 -0
- package/src/exceptions/http.exception.mts +26 -0
- package/src/exceptions/index.d.mts +8 -0
- package/src/exceptions/index.d.mts.map +1 -0
- package/src/exceptions/internal-server-error.exception.d.mts +31 -0
- package/src/exceptions/internal-server-error.exception.d.mts.map +1 -0
- package/src/exceptions/internal-server-error.exception.mts +26 -0
- package/src/exceptions/not-found.exception.d.mts +30 -0
- package/src/exceptions/not-found.exception.d.mts.map +1 -0
- package/src/exceptions/not-found.exception.mts +23 -0
- package/src/exceptions/unauthorized.exception.d.mts +28 -0
- package/src/exceptions/unauthorized.exception.d.mts.map +1 -0
- package/src/exceptions/unauthorized.exception.mts +23 -0
- package/src/factories/endpoint-adapter.factory.d.mts +6 -0
- package/src/factories/endpoint-adapter.factory.d.mts.map +1 -0
- package/src/factories/http-adapter.factory.d.mts +6 -0
- package/src/factories/http-adapter.factory.d.mts.map +1 -0
- package/src/factories/index.d.mts +8 -0
- package/src/factories/index.d.mts.map +1 -0
- package/src/factories/multipart-adapter.factory.d.mts +6 -0
- package/src/factories/multipart-adapter.factory.d.mts.map +1 -0
- package/src/factories/reply.factory.d.mts +6 -0
- package/src/factories/reply.factory.d.mts.map +1 -0
- package/src/factories/request.factory.d.mts +6 -0
- package/src/factories/request.factory.d.mts.map +1 -0
- package/src/factories/stream-adapter.factory.d.mts +6 -0
- package/src/factories/stream-adapter.factory.d.mts.map +1 -0
- package/src/factories/xml-stream-adapter.factory.d.mts +6 -0
- package/src/factories/xml-stream-adapter.factory.d.mts.map +1 -0
- package/src/index.d.mts +15 -0
- package/src/index.d.mts.map +1 -0
- package/src/index.mts +1 -0
- package/src/interfaces/abstract-execution-context.inteface.d.mts +44 -0
- package/src/interfaces/abstract-execution-context.inteface.d.mts.map +1 -0
- package/src/interfaces/abstract-execution-context.inteface.mts +35 -0
- package/src/interfaces/abstract-http-adapter.interface.d.mts +15 -0
- package/src/interfaces/abstract-http-adapter.interface.d.mts.map +1 -0
- package/src/interfaces/abstract-http-cors-options.interface.d.mts +58 -0
- package/src/interfaces/abstract-http-cors-options.interface.d.mts.map +1 -0
- package/src/interfaces/abstract-http-handler-adapter.interface.d.mts +7 -0
- package/src/interfaces/abstract-http-handler-adapter.interface.d.mts.map +1 -0
- package/src/interfaces/abstract-http-handler-adapter.interface.mts +2 -2
- package/src/interfaces/abstract-http-listen-options.interface.d.mts +5 -0
- package/src/interfaces/abstract-http-listen-options.interface.d.mts.map +1 -0
- package/src/interfaces/can-activate.d.mts +36 -0
- package/src/interfaces/can-activate.d.mts.map +1 -0
- package/src/interfaces/can-activate.mts +31 -0
- package/src/interfaces/http-header.d.mts +10 -0
- package/src/interfaces/http-header.d.mts.map +1 -0
- package/src/interfaces/index.d.mts +9 -0
- package/src/interfaces/index.d.mts.map +1 -0
- package/src/interfaces/navios-module.d.mts +29 -0
- package/src/interfaces/navios-module.d.mts.map +1 -0
- package/src/interfaces/navios-module.mts +25 -0
- package/src/legacy-compat/__type-tests__/legacy-decorators.spec-d.mts +420 -0
- package/src/legacy-compat/__type-tests__/tsconfig.json +15 -0
- package/src/legacy-compat/context-compat.d.mts +19 -0
- package/src/legacy-compat/context-compat.d.mts.map +1 -0
- package/src/legacy-compat/context-compat.mts +93 -0
- package/src/legacy-compat/decorators/controller.decorator.d.mts +21 -0
- package/src/legacy-compat/decorators/controller.decorator.d.mts.map +1 -0
- package/src/legacy-compat/decorators/controller.decorator.mts +31 -0
- package/src/legacy-compat/decorators/endpoint.decorator.d.mts +33 -0
- package/src/legacy-compat/decorators/endpoint.decorator.d.mts.map +1 -0
- package/src/legacy-compat/decorators/endpoint.decorator.mts +99 -0
- package/src/legacy-compat/decorators/header.decorator.d.mts +24 -0
- package/src/legacy-compat/decorators/header.decorator.d.mts.map +1 -0
- package/src/legacy-compat/decorators/header.decorator.mts +42 -0
- package/src/legacy-compat/decorators/http-code.decorator.d.mts +22 -0
- package/src/legacy-compat/decorators/http-code.decorator.d.mts.map +1 -0
- package/src/legacy-compat/decorators/http-code.decorator.mts +38 -0
- package/src/legacy-compat/decorators/index.d.mts +9 -0
- package/src/legacy-compat/decorators/index.d.mts.map +1 -0
- package/src/legacy-compat/decorators/index.mts +9 -0
- package/src/legacy-compat/decorators/module.decorator.d.mts +22 -0
- package/src/legacy-compat/decorators/module.decorator.d.mts.map +1 -0
- package/src/legacy-compat/decorators/module.decorator.mts +37 -0
- package/src/legacy-compat/decorators/multipart.decorator.d.mts +34 -0
- package/src/legacy-compat/decorators/multipart.decorator.d.mts.map +1 -0
- package/src/legacy-compat/decorators/multipart.decorator.mts +93 -0
- package/src/legacy-compat/decorators/stream.decorator.d.mts +34 -0
- package/src/legacy-compat/decorators/stream.decorator.d.mts.map +1 -0
- package/src/legacy-compat/decorators/stream.decorator.mts +76 -0
- package/src/legacy-compat/decorators/use-guards.decorator.d.mts +29 -0
- package/src/legacy-compat/decorators/use-guards.decorator.d.mts.map +1 -0
- package/src/legacy-compat/decorators/use-guards.decorator.mts +80 -0
- package/src/legacy-compat/index.d.mts +19 -0
- package/src/legacy-compat/index.d.mts.map +1 -0
- package/src/legacy-compat/index.mts +40 -0
- package/src/logger/console-logger.service.d.mts +196 -0
- package/src/logger/console-logger.service.d.mts.map +1 -0
- package/src/logger/console-logger.service.mts +15 -2
- package/src/logger/index.d.mts +7 -0
- package/src/logger/index.d.mts.map +1 -0
- package/src/logger/log-levels.d.mts +14 -0
- package/src/logger/log-levels.d.mts.map +1 -0
- package/src/logger/log-levels.mts +9 -0
- package/src/logger/logger-service.interface.d.mts +36 -0
- package/src/logger/logger-service.interface.d.mts.map +1 -0
- package/src/logger/logger.service.d.mts +57 -0
- package/src/logger/logger.service.d.mts.map +1 -0
- package/src/logger/logger.service.mts +19 -0
- package/src/logger/logger.tokens.d.mts +36 -0
- package/src/logger/logger.tokens.d.mts.map +1 -0
- package/src/logger/logger.tokens.mts +23 -0
- package/src/logger/utils/cli-colors.util.d.mts +10 -0
- package/src/logger/utils/cli-colors.util.d.mts.map +1 -0
- package/src/logger/utils/filter-log-levelts.util.d.mts +6 -0
- package/src/logger/utils/filter-log-levelts.util.d.mts.map +1 -0
- package/src/logger/utils/index.d.mts +6 -0
- package/src/logger/utils/index.d.mts.map +1 -0
- package/src/logger/utils/is-log-level-enabled.d.mts +8 -0
- package/src/logger/utils/is-log-level-enabled.d.mts.map +1 -0
- package/src/logger/utils/is-log-level.util.d.mts +6 -0
- package/src/logger/utils/is-log-level.util.d.mts.map +1 -0
- package/src/logger/utils/shared.utils.d.mts +14 -0
- package/src/logger/utils/shared.utils.d.mts.map +1 -0
- package/src/metadata/controller.metadata.d.mts +13 -0
- package/src/metadata/controller.metadata.d.mts.map +1 -0
- package/src/metadata/handler.metadata.d.mts +18 -0
- package/src/metadata/handler.metadata.d.mts.map +1 -0
- package/src/metadata/index.d.mts +4 -0
- package/src/metadata/index.d.mts.map +1 -0
- package/src/metadata/module.metadata.d.mts +13 -0
- package/src/metadata/module.metadata.d.mts.map +1 -0
- package/src/navios.application.d.mts +210 -0
- package/src/navios.application.d.mts.map +1 -0
- package/src/navios.application.mts +176 -2
- package/src/navios.environment.d.mts +11 -0
- package/src/navios.environment.d.mts.map +1 -0
- package/src/navios.factory.d.mts +68 -0
- package/src/navios.factory.d.mts.map +1 -0
- package/src/navios.factory.mts +59 -1
- package/src/services/guard-runner.service.d.mts +10 -0
- package/src/services/guard-runner.service.d.mts.map +1 -0
- package/src/services/guard-runner.service.mts +12 -11
- package/src/services/index.d.mts +3 -0
- package/src/services/index.d.mts.map +1 -0
- package/src/services/module-loader.service.d.mts +17 -0
- package/src/services/module-loader.service.d.mts.map +1 -0
- package/src/services/module-loader.service.mts +16 -11
- package/src/stores/index.d.mts +2 -0
- package/src/stores/index.d.mts.map +1 -0
- package/src/stores/index.mts +1 -0
- package/src/stores/request-id.store.d.mts +37 -0
- package/src/stores/request-id.store.d.mts.map +1 -0
- package/src/stores/request-id.store.mts +43 -0
- package/src/testing/index.mts +2 -0
- package/src/testing/testing-module.mts +231 -0
- package/src/tokens/endpoint-adapter.token.d.mts +4 -0
- package/src/tokens/endpoint-adapter.token.d.mts.map +1 -0
- package/src/tokens/execution-context.token.d.mts +5 -0
- package/src/tokens/execution-context.token.d.mts.map +1 -0
- package/src/tokens/http-adapter.token.d.mts +4 -0
- package/src/tokens/http-adapter.token.d.mts.map +1 -0
- package/src/tokens/index.d.mts +9 -0
- package/src/tokens/index.d.mts.map +1 -0
- package/src/tokens/multipart-adapter.token.d.mts +4 -0
- package/src/tokens/multipart-adapter.token.d.mts.map +1 -0
- package/src/tokens/reply.token.d.mts +3 -0
- package/src/tokens/reply.token.d.mts.map +1 -0
- package/src/tokens/request.token.d.mts +3 -0
- package/src/tokens/request.token.d.mts.map +1 -0
- package/src/tokens/stream-adapter.token.d.mts +4 -0
- package/src/tokens/stream-adapter.token.d.mts.map +1 -0
- package/src/tokens/xml-stream-adapter.token.d.mts +4 -0
- package/src/tokens/xml-stream-adapter.token.d.mts.map +1 -0
- package/tsconfig.lib.json +1 -1
- package/tsconfig.spec.json +3 -0
- package/tsdown.config.mts +35 -0
- package/vitest.config.mts +6 -0
- package/lib/_tsup-dts-rollup.d.mts +0 -1365
- package/lib/_tsup-dts-rollup.d.ts +0 -1365
- package/lib/index.d.ts +0 -190
- package/lib/index.js +0 -1540
- package/lib/index.js.map +0 -1
- package/lib/index.mjs.map +0 -1
- package/tsup.config.mts +0 -13
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { ClassTypeWithInstance } from '@navios/di';
|
|
2
|
+
import type { NaviosModule } from './interfaces/index.mjs';
|
|
3
|
+
import type { NaviosApplicationOptions } from './navios.application.mjs';
|
|
4
|
+
import { NaviosApplication } from './navios.application.mjs';
|
|
5
|
+
/**
|
|
6
|
+
* Factory class for creating and configuring Navios applications.
|
|
7
|
+
*
|
|
8
|
+
* This is the main entry point for bootstrapping a Navios application.
|
|
9
|
+
* It handles dependency injection container setup, adapter registration,
|
|
10
|
+
* and logger configuration.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { NaviosFactory } from '@navios/core'
|
|
15
|
+
* import { defineFastifyEnvironment } from '@navios/adapter-fastify'
|
|
16
|
+
*
|
|
17
|
+
* const app = await NaviosFactory.create(AppModule, {
|
|
18
|
+
* adapter: defineFastifyEnvironment(),
|
|
19
|
+
* logger: ['log', 'error', 'warn'],
|
|
20
|
+
* })
|
|
21
|
+
*
|
|
22
|
+
* await app.init()
|
|
23
|
+
* await app.listen({ port: 3000 })
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare class NaviosFactory {
|
|
27
|
+
/**
|
|
28
|
+
* Creates a new Navios application instance.
|
|
29
|
+
*
|
|
30
|
+
* This method sets up the dependency injection container, registers the HTTP adapter,
|
|
31
|
+
* configures logging, and initializes the application with the provided module.
|
|
32
|
+
*
|
|
33
|
+
* @param appModule - The root application module class decorated with @Module()
|
|
34
|
+
* @param options - Configuration options for the application
|
|
35
|
+
* @param options.adapter - HTTP adapter environment (required for HTTP server functionality)
|
|
36
|
+
* @param options.logger - Logger configuration. Can be:
|
|
37
|
+
* - A LoggerService instance for custom logging
|
|
38
|
+
* - An array of LogLevel strings to enable specific log levels
|
|
39
|
+
* - `false` to disable logging
|
|
40
|
+
* @param options.container - Optional custom dependency injection container (useful for testing)
|
|
41
|
+
* @returns A configured NaviosApplication instance ready to be initialized
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* // Basic setup with Fastify adapter
|
|
46
|
+
* const app = await NaviosFactory.create(AppModule, {
|
|
47
|
+
* adapter: defineFastifyEnvironment(),
|
|
48
|
+
* })
|
|
49
|
+
*
|
|
50
|
+
* // With custom logger configuration
|
|
51
|
+
* const app = await NaviosFactory.create(AppModule, {
|
|
52
|
+
* adapter: defineFastifyEnvironment(),
|
|
53
|
+
* logger: ['error', 'warn', 'log'],
|
|
54
|
+
* })
|
|
55
|
+
*
|
|
56
|
+
* // With custom container for testing
|
|
57
|
+
* const container = new Container()
|
|
58
|
+
* const app = await NaviosFactory.create(AppModule, {
|
|
59
|
+
* adapter: defineFastifyEnvironment(),
|
|
60
|
+
* container,
|
|
61
|
+
* })
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
static create(appModule: ClassTypeWithInstance<NaviosModule>, options?: NaviosApplicationOptions): Promise<NaviosApplication>;
|
|
65
|
+
private static registerEnvironment;
|
|
66
|
+
private static registerLoggerConfiguration;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=navios.factory.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"navios.factory.d.mts","sourceRoot":"","sources":["navios.factory.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,qBAAqB,EAEtB,MAAM,YAAY,CAAA;AAInB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,KAAK,EAEV,wBAAwB,EACzB,MAAM,0BAA0B,CAAA;AAGjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAG5D;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,aAAa;IACxB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAoCG;WACU,MAAM,CACjB,SAAS,EAAE,qBAAqB,CAAC,YAAY,CAAC,EAC9C,OAAO,GAAE,wBAER;mBAekB,mBAAmB;mBAanB,2BAA2B;CAyBjD"}
|
package/src/navios.factory.mts
CHANGED
|
@@ -16,14 +16,72 @@ import { ConsoleLogger, isNil, LoggerOutput } from './logger/index.mjs'
|
|
|
16
16
|
import { NaviosApplication } from './navios.application.mjs'
|
|
17
17
|
import { NaviosEnvironment } from './navios.environment.mjs'
|
|
18
18
|
|
|
19
|
+
/**
|
|
20
|
+
* Factory class for creating and configuring Navios applications.
|
|
21
|
+
*
|
|
22
|
+
* This is the main entry point for bootstrapping a Navios application.
|
|
23
|
+
* It handles dependency injection container setup, adapter registration,
|
|
24
|
+
* and logger configuration.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* import { NaviosFactory } from '@navios/core'
|
|
29
|
+
* import { defineFastifyEnvironment } from '@navios/adapter-fastify'
|
|
30
|
+
*
|
|
31
|
+
* const app = await NaviosFactory.create(AppModule, {
|
|
32
|
+
* adapter: defineFastifyEnvironment(),
|
|
33
|
+
* logger: ['log', 'error', 'warn'],
|
|
34
|
+
* })
|
|
35
|
+
*
|
|
36
|
+
* await app.init()
|
|
37
|
+
* await app.listen({ port: 3000 })
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
19
40
|
export class NaviosFactory {
|
|
41
|
+
/**
|
|
42
|
+
* Creates a new Navios application instance.
|
|
43
|
+
*
|
|
44
|
+
* This method sets up the dependency injection container, registers the HTTP adapter,
|
|
45
|
+
* configures logging, and initializes the application with the provided module.
|
|
46
|
+
*
|
|
47
|
+
* @param appModule - The root application module class decorated with @Module()
|
|
48
|
+
* @param options - Configuration options for the application
|
|
49
|
+
* @param options.adapter - HTTP adapter environment (required for HTTP server functionality)
|
|
50
|
+
* @param options.logger - Logger configuration. Can be:
|
|
51
|
+
* - A LoggerService instance for custom logging
|
|
52
|
+
* - An array of LogLevel strings to enable specific log levels
|
|
53
|
+
* - `false` to disable logging
|
|
54
|
+
* @param options.container - Optional custom dependency injection container (useful for testing)
|
|
55
|
+
* @returns A configured NaviosApplication instance ready to be initialized
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* // Basic setup with Fastify adapter
|
|
60
|
+
* const app = await NaviosFactory.create(AppModule, {
|
|
61
|
+
* adapter: defineFastifyEnvironment(),
|
|
62
|
+
* })
|
|
63
|
+
*
|
|
64
|
+
* // With custom logger configuration
|
|
65
|
+
* const app = await NaviosFactory.create(AppModule, {
|
|
66
|
+
* adapter: defineFastifyEnvironment(),
|
|
67
|
+
* logger: ['error', 'warn', 'log'],
|
|
68
|
+
* })
|
|
69
|
+
*
|
|
70
|
+
* // With custom container for testing
|
|
71
|
+
* const container = new Container()
|
|
72
|
+
* const app = await NaviosFactory.create(AppModule, {
|
|
73
|
+
* adapter: defineFastifyEnvironment(),
|
|
74
|
+
* container,
|
|
75
|
+
* })
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
20
78
|
static async create(
|
|
21
79
|
appModule: ClassTypeWithInstance<NaviosModule>,
|
|
22
80
|
options: NaviosApplicationOptions = {
|
|
23
81
|
adapter: [],
|
|
24
82
|
},
|
|
25
83
|
) {
|
|
26
|
-
const container = new Container()
|
|
84
|
+
const container = options.container ?? new Container()
|
|
27
85
|
await this.registerLoggerConfiguration(container, options)
|
|
28
86
|
const adapters = Array.isArray(options.adapter)
|
|
29
87
|
? options.adapter
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ClassTypeWithInstance, ScopedContainer } from '@navios/di';
|
|
2
|
+
import { InjectionToken } from '@navios/di';
|
|
3
|
+
import type { AbstractExecutionContext, CanActivate } from '../interfaces/index.mjs';
|
|
4
|
+
import type { ControllerMetadata, HandlerMetadata, ModuleMetadata } from '../metadata/index.mjs';
|
|
5
|
+
export declare class GuardRunnerService {
|
|
6
|
+
private readonly logger;
|
|
7
|
+
runGuards(allGuards: Set<ClassTypeWithInstance<CanActivate> | InjectionToken<CanActivate, undefined>>, executionContext: AbstractExecutionContext, context: ScopedContainer): Promise<boolean>;
|
|
8
|
+
makeContext(moduleMetadata: ModuleMetadata, controllerMetadata: ControllerMetadata, endpoint: HandlerMetadata): Set<ClassTypeWithInstance<CanActivate> | InjectionToken<CanActivate, undefined>>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=guard-runner.service.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guard-runner.service.d.mts","sourceRoot":"","sources":["guard-runner.service.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAExE,OAAO,EAAsB,cAAc,EAAE,MAAM,YAAY,CAAA;AAE/D,OAAO,KAAK,EACV,wBAAwB,EACxB,WAAW,EACZ,MAAM,yBAAyB,CAAA;AAChC,OAAO,KAAK,EACV,kBAAkB,EAClB,eAAe,EACf,cAAc,EACf,MAAM,uBAAuB,CAAA;AAK9B,qBACa,kBAAkB;IAC7B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAErB;IACI,SAAS,CACb,SAAS,EAAE,GAAG,CACV,qBAAqB,CAAC,WAAW,CAAC,GAClC,cAAc,CAAC,WAAW,EAAE,SAAS,CAAC,CACzC,EACD,gBAAgB,EAAE,wBAAwB,EAC1C,OAAO,EAAE,eAAe;IA0C1B,WAAW,CACT,cAAc,EAAE,cAAc,EAC9B,kBAAkB,EAAE,kBAAkB,EACtC,QAAQ,EAAE,eAAe,GACxB,GAAG,CACJ,qBAAqB,CAAC,WAAW,CAAC,GAAG,cAAc,CAAC,WAAW,EAAE,SAAS,CAAC,CAC5E;CAyBF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { ClassTypeWithInstance } from '@navios/di'
|
|
1
|
+
import type { ClassTypeWithInstance, ScopedContainer } from '@navios/di'
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { inject, Injectable, InjectionToken } from '@navios/di'
|
|
4
4
|
|
|
5
5
|
import type {
|
|
6
6
|
AbstractExecutionContext,
|
|
@@ -13,20 +13,24 @@ import type {
|
|
|
13
13
|
} from '../metadata/index.mjs'
|
|
14
14
|
|
|
15
15
|
import { HttpException } from '../exceptions/index.mjs'
|
|
16
|
+
import { Logger } from '../logger/index.mjs'
|
|
16
17
|
|
|
17
18
|
@Injectable()
|
|
18
19
|
export class GuardRunnerService {
|
|
19
|
-
|
|
20
|
+
private readonly logger = inject(Logger, {
|
|
21
|
+
context: GuardRunnerService.name,
|
|
22
|
+
})
|
|
20
23
|
async runGuards(
|
|
21
24
|
allGuards: Set<
|
|
22
25
|
| ClassTypeWithInstance<CanActivate>
|
|
23
26
|
| InjectionToken<CanActivate, undefined>
|
|
24
27
|
>,
|
|
25
28
|
executionContext: AbstractExecutionContext,
|
|
29
|
+
context: ScopedContainer,
|
|
26
30
|
) {
|
|
27
31
|
let canActivate = true
|
|
28
32
|
for (const guard of Array.from(allGuards).reverse()) {
|
|
29
|
-
const guardInstance = await
|
|
33
|
+
const guardInstance = await context.get(
|
|
30
34
|
guard as InjectionToken<CanActivate, undefined>,
|
|
31
35
|
)
|
|
32
36
|
if (!guardInstance.canActivate) {
|
|
@@ -47,13 +51,10 @@ export class GuardRunnerService {
|
|
|
47
51
|
.send(error.response)
|
|
48
52
|
return false
|
|
49
53
|
} else {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
message: 'Internal server error',
|
|
55
|
-
error: (error as Error).message,
|
|
56
|
-
})
|
|
54
|
+
this.logger.error('Error running guard', error)
|
|
55
|
+
executionContext.getReply().status(500).send({
|
|
56
|
+
message: 'Internal server error',
|
|
57
|
+
})
|
|
57
58
|
return false
|
|
58
59
|
}
|
|
59
60
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["index.mts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAA;AAC1C,cAAc,6BAA6B,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ClassTypeWithInstance } from '@navios/di';
|
|
2
|
+
import { Container } from '@navios/di';
|
|
3
|
+
import type { NaviosModule } from '../interfaces/index.mjs';
|
|
4
|
+
import type { ModuleMetadata } from '../metadata/index.mjs';
|
|
5
|
+
export declare class ModuleLoaderService {
|
|
6
|
+
private logger;
|
|
7
|
+
protected container: Container;
|
|
8
|
+
private modulesMetadata;
|
|
9
|
+
private loadedModules;
|
|
10
|
+
private initialized;
|
|
11
|
+
loadModules(appModule: ClassTypeWithInstance<NaviosModule>): Promise<void>;
|
|
12
|
+
private traverseModules;
|
|
13
|
+
private mergeMetadata;
|
|
14
|
+
getAllModules(): Map<string, ModuleMetadata>;
|
|
15
|
+
dispose(): void;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=module-loader.service.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module-loader.service.d.mts","sourceRoot":"","sources":["module-loader.service.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAEvD,OAAO,EAAE,SAAS,EAAsB,MAAM,YAAY,CAAA;AAE1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAK3D,qBACa,mBAAmB;IAC9B,OAAO,CAAC,MAAM,CAEZ;IACF,SAAS,CAAC,SAAS,YAAoB;IACvC,OAAO,CAAC,eAAe,CAAyC;IAChE,OAAO,CAAC,aAAa,CAA8B;IACnD,OAAO,CAAC,WAAW,CAAQ;IAErB,WAAW,CAAC,SAAS,EAAE,qBAAqB,CAAC,YAAY,CAAC;YAQlD,eAAe;IA+B7B,OAAO,CAAC,aAAa;IAkBrB,aAAa,IAAI,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC;IAG5C,OAAO;CAKR"}
|
|
@@ -38,18 +38,23 @@ export class ModuleLoaderService {
|
|
|
38
38
|
if (this.modulesMetadata.has(moduleName)) {
|
|
39
39
|
return
|
|
40
40
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
41
|
+
try {
|
|
42
|
+
this.modulesMetadata.set(moduleName, metadata)
|
|
43
|
+
const imports = metadata.imports ?? new Set()
|
|
44
|
+
const loadingPromises = Array.from(imports).map(async (importedModule) =>
|
|
45
|
+
this.traverseModules(importedModule, metadata),
|
|
46
|
+
)
|
|
47
|
+
await Promise.all(loadingPromises)
|
|
48
|
+
const instance = await this.container.get(module)
|
|
49
|
+
if (instance.onModuleInit) {
|
|
50
|
+
await instance.onModuleInit()
|
|
51
|
+
}
|
|
52
|
+
this.logger.debug(`Module ${moduleName} loaded`)
|
|
53
|
+
this.loadedModules.set(moduleName, instance)
|
|
54
|
+
} catch (error) {
|
|
55
|
+
this.logger.error(`Error loading module ${moduleName}`, error)
|
|
56
|
+
throw error
|
|
50
57
|
}
|
|
51
|
-
this.logger.debug(`Module ${moduleName} loaded`)
|
|
52
|
-
this.loadedModules.set(moduleName, instance)
|
|
53
58
|
}
|
|
54
59
|
|
|
55
60
|
private mergeMetadata(
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["index.mts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './request-id.store.mjs'
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
/**
|
|
3
|
+
* AsyncLocalStorage store for the current request ID.
|
|
4
|
+
*
|
|
5
|
+
* This allows logging and other services to access the current request ID
|
|
6
|
+
* without explicitly passing it through the call stack.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { requestIdStore, runWithRequestId, getRequestId } from '@navios/core'
|
|
11
|
+
*
|
|
12
|
+
* // Run code with a request ID in context
|
|
13
|
+
* runWithRequestId('req-123', () => {
|
|
14
|
+
* // Inside this callback, getRequestId() returns 'req-123'
|
|
15
|
+
* logger.log('Processing request') // Will include request ID if logger is configured
|
|
16
|
+
* })
|
|
17
|
+
*
|
|
18
|
+
* // Get current request ID (returns undefined if not in a request context)
|
|
19
|
+
* const currentId = getRequestId()
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare const requestIdStore: AsyncLocalStorage<string>;
|
|
23
|
+
/**
|
|
24
|
+
* Runs a function with a request ID in the async local storage context.
|
|
25
|
+
*
|
|
26
|
+
* @param requestId - The request ID to set for this context
|
|
27
|
+
* @param fn - The function to run within this context
|
|
28
|
+
* @returns The return value of the function
|
|
29
|
+
*/
|
|
30
|
+
export declare function runWithRequestId<R>(requestId: string, fn: () => R): R;
|
|
31
|
+
/**
|
|
32
|
+
* Gets the current request ID from the async local storage context.
|
|
33
|
+
*
|
|
34
|
+
* @returns The current request ID, or undefined if not in a request context
|
|
35
|
+
*/
|
|
36
|
+
export declare function getRequestId(): string | undefined;
|
|
37
|
+
//# sourceMappingURL=request-id.store.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-id.store.d.mts","sourceRoot":"","sources":["request-id.store.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAEpD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,cAAc,2BAAkC,CAAA;AAE7D;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAErE;AAED;;;;GAIG;AACH,wBAAgB,YAAY,IAAI,MAAM,GAAG,SAAS,CAEjD"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* AsyncLocalStorage store for the current request ID.
|
|
5
|
+
*
|
|
6
|
+
* This allows logging and other services to access the current request ID
|
|
7
|
+
* without explicitly passing it through the call stack.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { requestIdStore, runWithRequestId, getRequestId } from '@navios/core'
|
|
12
|
+
*
|
|
13
|
+
* // Run code with a request ID in context
|
|
14
|
+
* runWithRequestId('req-123', () => {
|
|
15
|
+
* // Inside this callback, getRequestId() returns 'req-123'
|
|
16
|
+
* logger.log('Processing request') // Will include request ID if logger is configured
|
|
17
|
+
* })
|
|
18
|
+
*
|
|
19
|
+
* // Get current request ID (returns undefined if not in a request context)
|
|
20
|
+
* const currentId = getRequestId()
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export const requestIdStore = new AsyncLocalStorage<string>()
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Runs a function with a request ID in the async local storage context.
|
|
27
|
+
*
|
|
28
|
+
* @param requestId - The request ID to set for this context
|
|
29
|
+
* @param fn - The function to run within this context
|
|
30
|
+
* @returns The return value of the function
|
|
31
|
+
*/
|
|
32
|
+
export function runWithRequestId<R>(requestId: string, fn: () => R): R {
|
|
33
|
+
return requestIdStore.run(requestId, fn)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Gets the current request ID from the async local storage context.
|
|
38
|
+
*
|
|
39
|
+
* @returns The current request ID, or undefined if not in a request context
|
|
40
|
+
*/
|
|
41
|
+
export function getRequestId(): string | undefined {
|
|
42
|
+
return requestIdStore.getStore()
|
|
43
|
+
}
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import type { ClassType, ClassTypeWithInstance, InjectionToken } from '@navios/di'
|
|
2
|
+
import type { NaviosModule } from '../interfaces/index.mjs'
|
|
3
|
+
import type { NaviosApplicationOptions } from '../navios.application.mjs'
|
|
4
|
+
|
|
5
|
+
import { TestContainer } from '@navios/di/testing'
|
|
6
|
+
|
|
7
|
+
import { NaviosApplication } from '../navios.application.mjs'
|
|
8
|
+
import { NaviosFactory } from '../navios.factory.mjs'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Configuration for overriding a provider in the testing module.
|
|
12
|
+
*
|
|
13
|
+
* @typeParam T - The type of the provider being overridden
|
|
14
|
+
*/
|
|
15
|
+
export interface TestingModuleOverride<T = any> {
|
|
16
|
+
/**
|
|
17
|
+
* The injection token or class to override.
|
|
18
|
+
*/
|
|
19
|
+
token: ClassType | InjectionToken<T, any>
|
|
20
|
+
/**
|
|
21
|
+
* Value to use instead of the original provider.
|
|
22
|
+
*/
|
|
23
|
+
useValue?: T
|
|
24
|
+
/**
|
|
25
|
+
* Class to use instead of the original provider.
|
|
26
|
+
*/
|
|
27
|
+
useClass?: ClassType
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Options for creating a testing module.
|
|
32
|
+
*
|
|
33
|
+
* Extends NaviosApplicationOptions but excludes the container option,
|
|
34
|
+
* as TestingModule manages its own TestContainer.
|
|
35
|
+
*/
|
|
36
|
+
export interface TestingModuleOptions
|
|
37
|
+
extends Omit<NaviosApplicationOptions, 'container'> {
|
|
38
|
+
/**
|
|
39
|
+
* Initial provider overrides to apply when creating the testing module.
|
|
40
|
+
*
|
|
41
|
+
* You can also use `overrideProvider()` method for a fluent API.
|
|
42
|
+
*/
|
|
43
|
+
overrides?: TestingModuleOverride[]
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* A testing-optimized wrapper around NaviosApplication.
|
|
48
|
+
* Provides utilities for setting up test environments with mock dependencies.
|
|
49
|
+
*/
|
|
50
|
+
export class TestingModule {
|
|
51
|
+
private app: NaviosApplication | null = null
|
|
52
|
+
|
|
53
|
+
constructor(
|
|
54
|
+
private readonly appModule: ClassTypeWithInstance<NaviosModule>,
|
|
55
|
+
private readonly container: TestContainer,
|
|
56
|
+
private readonly options: TestingModuleOptions,
|
|
57
|
+
) {}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Compiles the testing module and returns the NaviosApplication.
|
|
61
|
+
* Call this after setting up all overrides.
|
|
62
|
+
*/
|
|
63
|
+
async compile(): Promise<NaviosApplication> {
|
|
64
|
+
this.app = await NaviosFactory.create(this.appModule, {
|
|
65
|
+
...this.options,
|
|
66
|
+
container: this.container,
|
|
67
|
+
})
|
|
68
|
+
return this.app
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Initializes the application (loads modules, sets up HTTP if configured).
|
|
73
|
+
* This is equivalent to calling app.init() on the compiled application.
|
|
74
|
+
*/
|
|
75
|
+
async init(): Promise<NaviosApplication> {
|
|
76
|
+
if (!this.app) {
|
|
77
|
+
await this.compile()
|
|
78
|
+
}
|
|
79
|
+
await this.app!.init()
|
|
80
|
+
return this.app!
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Gets the underlying TestContainer for direct manipulation.
|
|
85
|
+
*/
|
|
86
|
+
getContainer(): TestContainer {
|
|
87
|
+
return this.container
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Gets the compiled application. Throws if not yet compiled.
|
|
92
|
+
*/
|
|
93
|
+
getApplication(): NaviosApplication {
|
|
94
|
+
if (!this.app) {
|
|
95
|
+
throw new Error(
|
|
96
|
+
'TestingModule not compiled. Call compile() or init() first.',
|
|
97
|
+
)
|
|
98
|
+
}
|
|
99
|
+
return this.app
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Override a provider with a mock value.
|
|
104
|
+
*/
|
|
105
|
+
overrideProvider<T>(token: ClassType | InjectionToken<T, any>): {
|
|
106
|
+
useValue: (value: T) => TestingModule
|
|
107
|
+
useClass: (target: ClassType) => TestingModule
|
|
108
|
+
} {
|
|
109
|
+
return {
|
|
110
|
+
useValue: (value: T) => {
|
|
111
|
+
this.container.bind(token as any).toValue(value)
|
|
112
|
+
return this
|
|
113
|
+
},
|
|
114
|
+
useClass: (target: ClassType) => {
|
|
115
|
+
this.container.bind(token as any).toClass(target)
|
|
116
|
+
return this
|
|
117
|
+
},
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Gets an instance from the container.
|
|
123
|
+
*/
|
|
124
|
+
async get<T>(token: ClassTypeWithInstance<T> | InjectionToken<T, any>): Promise<T> {
|
|
125
|
+
return this.container.get(token as any)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Disposes the testing module and cleans up resources.
|
|
130
|
+
*/
|
|
131
|
+
async close(): Promise<void> {
|
|
132
|
+
if (this.app) {
|
|
133
|
+
await this.app.close()
|
|
134
|
+
}
|
|
135
|
+
await this.container.dispose()
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Fluent builder interface for TestingModule.
|
|
141
|
+
*
|
|
142
|
+
* Provides a chainable API for configuring and using a testing module.
|
|
143
|
+
*/
|
|
144
|
+
export interface TestingModuleBuilder {
|
|
145
|
+
/**
|
|
146
|
+
* Override a provider with a mock value or class.
|
|
147
|
+
*
|
|
148
|
+
* @param token - The injection token or class to override
|
|
149
|
+
* @returns An object with `useValue` and `useClass` methods for chaining
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```typescript
|
|
153
|
+
* const testingModule = await createTestingModule(AppModule)
|
|
154
|
+
* .overrideProvider(DatabaseService)
|
|
155
|
+
* .useValue(mockDatabaseService)
|
|
156
|
+
* .compile()
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
overrideProvider<T>(token: ClassType | InjectionToken<T, any>): {
|
|
160
|
+
useValue: (value: T) => TestingModuleBuilder
|
|
161
|
+
useClass: (target: ClassType) => TestingModuleBuilder
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Compiles the testing module and returns the NaviosApplication.
|
|
166
|
+
*
|
|
167
|
+
* This creates the application instance but does not initialize it.
|
|
168
|
+
* Call `init()` if you need the application to be fully initialized.
|
|
169
|
+
*/
|
|
170
|
+
compile(): Promise<NaviosApplication>
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Initializes the application (loads modules, sets up HTTP if configured).
|
|
174
|
+
*
|
|
175
|
+
* This is equivalent to calling `compile()` followed by `app.init()`.
|
|
176
|
+
*/
|
|
177
|
+
init(): Promise<NaviosApplication>
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Gets the underlying TestContainer for direct manipulation.
|
|
181
|
+
*/
|
|
182
|
+
getContainer(): TestContainer
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Gets an instance from the container.
|
|
186
|
+
*
|
|
187
|
+
* @typeParam T - The type of the instance to retrieve
|
|
188
|
+
* @param token - The injection token or class
|
|
189
|
+
* @returns The resolved instance
|
|
190
|
+
*/
|
|
191
|
+
get<T>(token: ClassTypeWithInstance<T> | InjectionToken<T, any>): Promise<T>
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Disposes the testing module and cleans up resources.
|
|
195
|
+
*/
|
|
196
|
+
close(): Promise<void>
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Creates a testing module for the given app module.
|
|
201
|
+
* This is the main entry point for setting up tests.
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* ```typescript
|
|
205
|
+
* const testingModule = await createTestingModule(AppModule, {
|
|
206
|
+
* adapter: [],
|
|
207
|
+
* })
|
|
208
|
+
* .overrideProvider(DatabaseService)
|
|
209
|
+
* .useValue(mockDatabaseService)
|
|
210
|
+
* .compile()
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
export function createTestingModule(
|
|
214
|
+
appModule: ClassTypeWithInstance<NaviosModule>,
|
|
215
|
+
options: TestingModuleOptions = { adapter: [] },
|
|
216
|
+
): TestingModule {
|
|
217
|
+
const container = new TestContainer()
|
|
218
|
+
|
|
219
|
+
// Apply initial overrides if provided
|
|
220
|
+
if (options.overrides) {
|
|
221
|
+
for (const override of options.overrides) {
|
|
222
|
+
if (override.useValue !== undefined) {
|
|
223
|
+
container.bind(override.token as any).toValue(override.useValue)
|
|
224
|
+
} else if (override.useClass) {
|
|
225
|
+
container.bind(override.token as any).toClass(override.useClass)
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return new TestingModule(appModule, container, options)
|
|
231
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { InjectionToken } from '@navios/di';
|
|
2
|
+
import type { AbstractHttpHandlerAdapterInterface } from '../interfaces/index.mjs';
|
|
3
|
+
export declare const EndpointAdapterToken: InjectionToken<AbstractHttpHandlerAdapterInterface, undefined, false>;
|
|
4
|
+
//# sourceMappingURL=endpoint-adapter.token.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"endpoint-adapter.token.d.mts","sourceRoot":"","sources":["endpoint-adapter.token.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAE3C,OAAO,KAAK,EAAE,mCAAmC,EAAE,MAAM,yBAAyB,CAAA;AAElF,eAAO,MAAM,oBAAoB,uEAG9B,CAAA"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { InjectionToken } from '@navios/di';
|
|
2
|
+
import type { AbstractExecutionContext } from '../interfaces/index.mjs';
|
|
3
|
+
export declare const ExecutionContextInjectionToken = "ExecutionContextInjectionToken";
|
|
4
|
+
export declare const ExecutionContext: InjectionToken<AbstractExecutionContext, undefined, false>;
|
|
5
|
+
//# sourceMappingURL=execution-context.token.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execution-context.token.d.mts","sourceRoot":"","sources":["execution-context.token.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAE3C,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAA;AAEvE,eAAO,MAAM,8BAA8B,mCAAmC,CAAA;AAE9E,eAAO,MAAM,gBAAgB,4DAE5B,CAAA"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { InjectionToken } from '@navios/di';
|
|
2
|
+
import type { AbstractHttpAdapterInterface } from '../interfaces/index.mjs';
|
|
3
|
+
export declare const HttpAdapterToken: InjectionToken<AbstractHttpAdapterInterface<any, any, any, any>, undefined, false>;
|
|
4
|
+
//# sourceMappingURL=http-adapter.token.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-adapter.token.d.mts","sourceRoot":"","sources":["http-adapter.token.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAE3C,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,yBAAyB,CAAA;AAE3E,eAAO,MAAM,gBAAgB,oFAG1B,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './endpoint-adapter.token.mjs';
|
|
2
|
+
export * from './execution-context.token.mjs';
|
|
3
|
+
export * from './http-adapter.token.mjs';
|
|
4
|
+
export * from './multipart-adapter.token.mjs';
|
|
5
|
+
export * from './reply.token.mjs';
|
|
6
|
+
export * from './request.token.mjs';
|
|
7
|
+
export * from './stream-adapter.token.mjs';
|
|
8
|
+
export * from './xml-stream-adapter.token.mjs';
|
|
9
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["index.mts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAA;AAC5C,cAAc,+BAA+B,CAAA;AAC7C,cAAc,0BAA0B,CAAA;AACxC,cAAc,+BAA+B,CAAA;AAC7C,cAAc,mBAAmB,CAAA;AACjC,cAAc,qBAAqB,CAAA;AACnC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,gCAAgC,CAAA"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { InjectionToken } from '@navios/di';
|
|
2
|
+
import type { AbstractHttpHandlerAdapterInterface } from '../interfaces/index.mjs';
|
|
3
|
+
export declare const MultipartAdapterToken: InjectionToken<AbstractHttpHandlerAdapterInterface, undefined, false>;
|
|
4
|
+
//# sourceMappingURL=multipart-adapter.token.d.mts.map
|