@navios/core 0.1.15 → 0.2.1
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/_tsup-dts-rollup.d.mts +96 -425
- package/dist/_tsup-dts-rollup.d.ts +96 -425
- package/dist/index.d.mts +54 -44
- package/dist/index.d.ts +54 -44
- package/dist/index.js +111 -1023
- package/dist/index.mjs +113 -982
- package/package.json +5 -4
- package/src/adapters/endpoint-adapter.service.mts +3 -6
- package/src/adapters/handler-adapter.interface.mts +1 -1
- package/src/adapters/multipart-adapter.service.mts +2 -1
- package/src/adapters/stream-adapter.service.mts +3 -7
- package/src/attribute.factory.mts +1 -1
- package/src/config/config.provider.mts +13 -11
- package/src/decorators/controller.decorator.mts +3 -6
- package/src/decorators/endpoint.decorator.mts +17 -10
- package/src/decorators/module.decorator.mts +3 -6
- package/src/decorators/multipart.decorator.mts +17 -10
- package/src/decorators/stream.decorator.mts +17 -10
- package/src/decorators/use-guards.decorator.mts +3 -2
- package/src/index.mts +1 -1
- package/src/logger/console-logger.service.mts +3 -2
- package/src/logger/logger.factory.mts +4 -5
- package/src/logger/logger.service.mts +2 -1
- package/src/metadata/controller.metadata.mts +3 -2
- package/src/metadata/handler.metadata.mts +1 -4
- package/src/metadata/index.mts +0 -1
- package/src/metadata/module.metadata.mts +3 -2
- package/src/navios.application.mts +9 -8
- package/src/navios.factory.mts +4 -2
- package/src/services/controller-adapter.service.mts +13 -12
- package/src/services/guard-runner.service.mts +4 -6
- package/src/services/module-loader.service.mts +4 -2
- package/src/tokens/application.token.mts +1 -1
- package/src/tokens/execution-context.token.mts +2 -1
- package/src/tokens/reply.token.mts +1 -1
- package/src/tokens/request.token.mts +1 -1
- package/src/metadata/injectable.metadata.mts +0 -11
- package/src/service-locator/__tests__/injectable.spec.mts +0 -171
- package/src/service-locator/__tests__/injection-token.spec.mts +0 -129
- package/src/service-locator/decorators/get-injectable-token.mts +0 -19
- package/src/service-locator/decorators/index.mts +0 -2
- package/src/service-locator/decorators/injectable.decorator.mts +0 -113
- package/src/service-locator/enums/index.mts +0 -1
- package/src/service-locator/enums/injectable-scope.enum.mts +0 -10
- package/src/service-locator/errors/errors.enum.mts +0 -8
- package/src/service-locator/errors/factory-not-found.mts +0 -8
- package/src/service-locator/errors/factory-token-not-resolved.mts +0 -10
- package/src/service-locator/errors/index.mts +0 -7
- package/src/service-locator/errors/instance-destroying.mts +0 -8
- package/src/service-locator/errors/instance-expired.mts +0 -8
- package/src/service-locator/errors/instance-not-found.mts +0 -8
- package/src/service-locator/errors/unknown-error.mts +0 -15
- package/src/service-locator/event-emitter.mts +0 -107
- package/src/service-locator/index.mts +0 -15
- package/src/service-locator/inject.mts +0 -42
- package/src/service-locator/injection-token.mts +0 -92
- package/src/service-locator/injector.mts +0 -18
- package/src/service-locator/interfaces/factory.interface.mts +0 -11
- package/src/service-locator/override.mts +0 -22
- package/src/service-locator/proxy-service-locator.mts +0 -99
- package/src/service-locator/resolve-service.mts +0 -46
- package/src/service-locator/service-locator-abstract-factory-context.mts +0 -23
- package/src/service-locator/service-locator-event-bus.mts +0 -96
- package/src/service-locator/service-locator-instance-holder.mts +0 -63
- package/src/service-locator/service-locator-manager.mts +0 -89
- package/src/service-locator/service-locator.mts +0 -535
- package/src/service-locator/sync-injector.mts +0 -66
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@navios/core",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "Oleksandr Hanzha",
|
|
6
6
|
"email": "alex@granted.name"
|
|
@@ -11,11 +11,11 @@
|
|
|
11
11
|
"url": "https://github.com/Arilas/navios.git"
|
|
12
12
|
},
|
|
13
13
|
"license": "MIT",
|
|
14
|
-
"typings": "./dist/index.d.
|
|
14
|
+
"typings": "./dist/src/index.d.mts",
|
|
15
15
|
"main": "./dist/index.js",
|
|
16
16
|
"module": "./dist/index.mjs",
|
|
17
17
|
"peerDependencies": {
|
|
18
|
-
"@navios/common": "^0.1.
|
|
18
|
+
"@navios/common": "^0.1.6",
|
|
19
19
|
"zod": "^3.23.8"
|
|
20
20
|
},
|
|
21
21
|
"exports": {
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"./package.json": "./package.json"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@navios/common": "^0.1.
|
|
35
|
+
"@navios/common": "^0.1.6",
|
|
36
36
|
"tsx": "^4.19.4",
|
|
37
37
|
"typescript": "^5.8.3",
|
|
38
38
|
"zod": "^3.24.4"
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@fastify/cors": "^11.0.1",
|
|
42
42
|
"@fastify/multipart": "^9.0.3",
|
|
43
|
+
"@navios/di": "^0.1.2",
|
|
43
44
|
"fastify": "^5.3.2",
|
|
44
45
|
"fastify-type-provider-zod": "^4.0.2"
|
|
45
46
|
}
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import type { BaseEndpointConfig } from '@navios/common'
|
|
2
|
+
import type { ClassType } from '@navios/di'
|
|
2
3
|
import type { FastifyReply, FastifyRequest } from 'fastify'
|
|
3
4
|
|
|
5
|
+
import { inject, Injectable, InjectionToken } from '@navios/di'
|
|
6
|
+
|
|
4
7
|
import type { HandlerMetadata } from '../metadata/index.mjs'
|
|
5
|
-
import type { ClassType } from '../service-locator/index.mjs'
|
|
6
8
|
import type { ExecutionContext } from '../services/index.mjs'
|
|
7
9
|
|
|
8
|
-
import {
|
|
9
|
-
inject,
|
|
10
|
-
Injectable,
|
|
11
|
-
InjectionToken,
|
|
12
|
-
} from '../service-locator/index.mjs'
|
|
13
10
|
import { StreamAdapterService } from './stream-adapter.service.mjs'
|
|
14
11
|
|
|
15
12
|
export const EndpointAdapterToken =
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import type { ClassType } from '@navios/di'
|
|
1
2
|
import type { FastifyReply, FastifyRequest } from 'fastify'
|
|
2
3
|
|
|
3
4
|
import type { HandlerMetadata } from '../metadata/index.mjs'
|
|
4
|
-
import type { ClassType } from '../service-locator/index.mjs'
|
|
5
5
|
import type { ExecutionContext } from '../services/index.mjs'
|
|
6
6
|
|
|
7
7
|
export interface HandlerAdapterInterface {
|
|
@@ -3,11 +3,12 @@ import type { BaseEndpointConfig } from '@navios/common'
|
|
|
3
3
|
import type { FastifyRequest } from 'fastify'
|
|
4
4
|
import type { AnyZodObject, ZodRawShape } from 'zod'
|
|
5
5
|
|
|
6
|
+
import { Injectable, InjectionToken } from '@navios/di'
|
|
7
|
+
|
|
6
8
|
import { ZodArray, ZodObject, ZodOptional } from 'zod'
|
|
7
9
|
|
|
8
10
|
import type { HandlerMetadata } from '../metadata/index.mjs'
|
|
9
11
|
|
|
10
|
-
import { Injectable, InjectionToken } from '../service-locator/index.mjs'
|
|
11
12
|
import { EndpointAdapterService } from './endpoint-adapter.service.mjs'
|
|
12
13
|
|
|
13
14
|
export const MultipartAdapterToken =
|
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
import type { BaseStreamConfig } from '@navios/common'
|
|
2
|
+
import type { ClassType } from '@navios/di'
|
|
2
3
|
import type { FastifyReply, FastifyRequest } from 'fastify'
|
|
3
4
|
|
|
5
|
+
import { inject, Injectable, InjectionToken } from '@navios/di'
|
|
6
|
+
|
|
4
7
|
import type { HandlerMetadata } from '../metadata/index.mjs'
|
|
5
|
-
import type { ClassType } from '../service-locator/index.mjs'
|
|
6
8
|
import type { ExecutionContext } from '../services/index.mjs'
|
|
7
9
|
import type { HandlerAdapterInterface } from './handler-adapter.interface.mjs'
|
|
8
10
|
|
|
9
|
-
import {
|
|
10
|
-
inject,
|
|
11
|
-
Injectable,
|
|
12
|
-
InjectionToken,
|
|
13
|
-
} from '../service-locator/index.mjs'
|
|
14
|
-
|
|
15
11
|
export const StreamAdapterToken = InjectionToken.create<StreamAdapterService>(
|
|
16
12
|
Symbol.for('StreamAdapterService'),
|
|
17
13
|
)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ClassType } from '@navios/di'
|
|
1
2
|
import type { z, ZodType } from 'zod'
|
|
2
3
|
|
|
3
4
|
import type {
|
|
@@ -5,7 +6,6 @@ import type {
|
|
|
5
6
|
HandlerMetadata,
|
|
6
7
|
ModuleMetadata,
|
|
7
8
|
} from './metadata/index.mjs'
|
|
8
|
-
import type { ClassType } from './service-locator/index.mjs'
|
|
9
9
|
|
|
10
10
|
import {
|
|
11
11
|
getControllerMetadata,
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import { z } from 'zod'
|
|
2
|
-
|
|
3
|
-
import type { ConfigService } from './config-service.interface.mjs'
|
|
4
|
-
|
|
5
|
-
import { Logger } from '../logger/index.mjs'
|
|
6
1
|
import {
|
|
2
|
+
BoundInjectionToken,
|
|
7
3
|
Injectable,
|
|
8
4
|
InjectableType,
|
|
9
5
|
InjectionToken,
|
|
10
6
|
syncInject,
|
|
11
|
-
} from '
|
|
7
|
+
} from '@navios/di'
|
|
8
|
+
|
|
9
|
+
import { z } from 'zod'
|
|
10
|
+
|
|
11
|
+
import type { ConfigService } from './config-service.interface.mjs'
|
|
12
|
+
|
|
13
|
+
import { Logger } from '../logger/index.mjs'
|
|
12
14
|
import { ConfigServiceInstance } from './config.service.mjs'
|
|
13
15
|
|
|
14
16
|
export const ConfigProviderOptions = z.object({
|
|
@@ -51,9 +53,9 @@ export class ConfigProviderFactory {
|
|
|
51
53
|
|
|
52
54
|
export function provideConfig<ConfigMap extends Record<string, unknown>>(
|
|
53
55
|
options: z.input<typeof ConfigProviderOptions>,
|
|
54
|
-
)
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
): BoundInjectionToken<
|
|
57
|
+
ConfigServiceInstance<ConfigMap>,
|
|
58
|
+
typeof ConfigProviderOptions
|
|
59
|
+
> {
|
|
60
|
+
return InjectionToken.bound(ConfigProvider, options)
|
|
59
61
|
}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import type { ClassType } from '
|
|
1
|
+
import type { ClassType } from '@navios/di'
|
|
2
|
+
|
|
3
|
+
import { Injectable, InjectableScope, InjectionToken } from '@navios/di'
|
|
2
4
|
|
|
3
5
|
import { getControllerMetadata } from '../metadata/index.mjs'
|
|
4
|
-
import {
|
|
5
|
-
Injectable,
|
|
6
|
-
InjectableScope,
|
|
7
|
-
InjectionToken,
|
|
8
|
-
} from '../service-locator/index.mjs'
|
|
9
6
|
|
|
10
7
|
export interface ControllerOptions {
|
|
11
8
|
guards?: ClassType[] | Set<ClassType>
|
|
@@ -2,6 +2,7 @@ import type {
|
|
|
2
2
|
BaseEndpointConfig,
|
|
3
3
|
EndpointFunctionArgs,
|
|
4
4
|
HttpMethod,
|
|
5
|
+
Util_FlatObject,
|
|
5
6
|
} from '@navios/common'
|
|
6
7
|
import type { AnyZodObject, z, ZodType } from 'zod'
|
|
7
8
|
|
|
@@ -18,19 +19,25 @@ export type EndpointParams<
|
|
|
18
19
|
QuerySchema = EndpointDeclaration['config']['querySchema'],
|
|
19
20
|
> = QuerySchema extends AnyZodObject
|
|
20
21
|
? EndpointDeclaration['config']['requestSchema'] extends ZodType
|
|
21
|
-
?
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
? Util_FlatObject<
|
|
23
|
+
EndpointFunctionArgs<
|
|
24
|
+
Url,
|
|
25
|
+
QuerySchema,
|
|
26
|
+
EndpointDeclaration['config']['requestSchema'],
|
|
27
|
+
true
|
|
28
|
+
>
|
|
25
29
|
>
|
|
26
|
-
: EndpointFunctionArgs<Url, QuerySchema, undefined
|
|
30
|
+
: Util_FlatObject<EndpointFunctionArgs<Url, QuerySchema, undefined, true>>
|
|
27
31
|
: EndpointDeclaration['config']['requestSchema'] extends ZodType
|
|
28
|
-
?
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
? Util_FlatObject<
|
|
33
|
+
EndpointFunctionArgs<
|
|
34
|
+
Url,
|
|
35
|
+
undefined,
|
|
36
|
+
EndpointDeclaration['config']['requestSchema'],
|
|
37
|
+
true
|
|
38
|
+
>
|
|
32
39
|
>
|
|
33
|
-
: EndpointFunctionArgs<Url, undefined, undefined
|
|
40
|
+
: Util_FlatObject<EndpointFunctionArgs<Url, undefined, undefined, true>>
|
|
34
41
|
|
|
35
42
|
export type EndpointResult<
|
|
36
43
|
EndpointDeclaration extends {
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import type { ClassType } from '
|
|
1
|
+
import type { ClassType } from '@navios/di'
|
|
2
|
+
|
|
3
|
+
import { Injectable, InjectableScope, InjectionToken } from '@navios/di'
|
|
2
4
|
|
|
3
5
|
import { getModuleMetadata } from '../metadata/index.mjs'
|
|
4
|
-
import {
|
|
5
|
-
Injectable,
|
|
6
|
-
InjectableScope,
|
|
7
|
-
InjectionToken,
|
|
8
|
-
} from '../service-locator/index.mjs'
|
|
9
6
|
|
|
10
7
|
export interface ModuleOptions {
|
|
11
8
|
controllers?: ClassType[] | Set<ClassType>
|
|
@@ -2,6 +2,7 @@ import type {
|
|
|
2
2
|
BaseEndpointConfig,
|
|
3
3
|
EndpointFunctionArgs,
|
|
4
4
|
HttpMethod,
|
|
5
|
+
Util_FlatObject,
|
|
5
6
|
} from '@navios/common'
|
|
6
7
|
import type { AnyZodObject, z, ZodType } from 'zod'
|
|
7
8
|
|
|
@@ -18,19 +19,25 @@ export type MultipartParams<
|
|
|
18
19
|
QuerySchema = EndpointDeclaration['config']['querySchema'],
|
|
19
20
|
> = QuerySchema extends AnyZodObject
|
|
20
21
|
? EndpointDeclaration['config']['requestSchema'] extends ZodType
|
|
21
|
-
?
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
? Util_FlatObject<
|
|
23
|
+
EndpointFunctionArgs<
|
|
24
|
+
Url,
|
|
25
|
+
QuerySchema,
|
|
26
|
+
EndpointDeclaration['config']['requestSchema'],
|
|
27
|
+
true
|
|
28
|
+
>
|
|
25
29
|
>
|
|
26
|
-
: EndpointFunctionArgs<Url, QuerySchema, undefined
|
|
30
|
+
: Util_FlatObject<EndpointFunctionArgs<Url, QuerySchema, undefined, true>>
|
|
27
31
|
: EndpointDeclaration['config']['requestSchema'] extends ZodType
|
|
28
|
-
?
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
? Util_FlatObject<
|
|
33
|
+
EndpointFunctionArgs<
|
|
34
|
+
Url,
|
|
35
|
+
undefined,
|
|
36
|
+
EndpointDeclaration['config']['requestSchema'],
|
|
37
|
+
true
|
|
38
|
+
>
|
|
32
39
|
>
|
|
33
|
-
: EndpointFunctionArgs<Url, undefined, undefined
|
|
40
|
+
: Util_FlatObject<EndpointFunctionArgs<Url, undefined, undefined, true>>
|
|
34
41
|
|
|
35
42
|
export type MultipartResult<
|
|
36
43
|
EndpointDeclaration extends {
|
|
@@ -2,6 +2,7 @@ import type {
|
|
|
2
2
|
BaseStreamConfig,
|
|
3
3
|
EndpointFunctionArgs,
|
|
4
4
|
HttpMethod,
|
|
5
|
+
Util_FlatObject,
|
|
5
6
|
} from '@navios/common'
|
|
6
7
|
import type { FastifyReply } from 'fastify'
|
|
7
8
|
import type { AnyZodObject, ZodType } from 'zod'
|
|
@@ -17,19 +18,25 @@ export type StreamParams<
|
|
|
17
18
|
QuerySchema = EndpointDeclaration['config']['querySchema'],
|
|
18
19
|
> = QuerySchema extends AnyZodObject
|
|
19
20
|
? EndpointDeclaration['config']['requestSchema'] extends ZodType
|
|
20
|
-
?
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
? Util_FlatObject<
|
|
22
|
+
EndpointFunctionArgs<
|
|
23
|
+
Url,
|
|
24
|
+
QuerySchema,
|
|
25
|
+
EndpointDeclaration['config']['requestSchema'],
|
|
26
|
+
true
|
|
27
|
+
>
|
|
24
28
|
>
|
|
25
|
-
: EndpointFunctionArgs<Url, QuerySchema, undefined
|
|
29
|
+
: Util_FlatObject<EndpointFunctionArgs<Url, QuerySchema, undefined, true>>
|
|
26
30
|
: EndpointDeclaration['config']['requestSchema'] extends ZodType
|
|
27
|
-
?
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
? Util_FlatObject<
|
|
32
|
+
EndpointFunctionArgs<
|
|
33
|
+
Url,
|
|
34
|
+
undefined,
|
|
35
|
+
EndpointDeclaration['config']['requestSchema'],
|
|
36
|
+
true
|
|
37
|
+
>
|
|
31
38
|
>
|
|
32
|
-
: EndpointFunctionArgs<Url, undefined, undefined
|
|
39
|
+
: Util_FlatObject<EndpointFunctionArgs<Url, undefined, undefined, true>>
|
|
33
40
|
|
|
34
41
|
export function Stream<
|
|
35
42
|
Method extends HttpMethod = HttpMethod,
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import type { CanActivate } from '../interfaces/index.mjs'
|
|
2
1
|
import type {
|
|
3
2
|
ClassType,
|
|
4
3
|
ClassTypeWithInstance,
|
|
5
4
|
InjectionToken,
|
|
6
|
-
} from '
|
|
5
|
+
} from '@navios/di'
|
|
6
|
+
|
|
7
|
+
import type { CanActivate } from '../interfaces/index.mjs'
|
|
7
8
|
|
|
8
9
|
import {
|
|
9
10
|
getControllerMetadata,
|
package/src/index.mts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export * from '@navios/di'
|
|
1
2
|
export * from './adapters/index.mjs'
|
|
2
3
|
export * from './config/index.mjs'
|
|
3
4
|
export * from './decorators/index.mjs'
|
|
@@ -5,7 +6,6 @@ export * from './exceptions/index.mjs'
|
|
|
5
6
|
export * from './interfaces/index.mjs'
|
|
6
7
|
export * from './logger/index.mjs'
|
|
7
8
|
export * from './metadata/index.mjs'
|
|
8
|
-
export * from './service-locator/index.mjs'
|
|
9
9
|
export * from './services/index.mjs'
|
|
10
10
|
export * from './tokens/index.mjs'
|
|
11
11
|
export * from './attribute.factory.mjs'
|
|
@@ -2,10 +2,11 @@ import type { InspectOptions } from 'util'
|
|
|
2
2
|
|
|
3
3
|
import { inspect } from 'util'
|
|
4
4
|
|
|
5
|
+
import { getGlobalServiceLocator, Injectable } from '@navios/di'
|
|
6
|
+
|
|
5
7
|
import type { LogLevel } from './log-levels.mjs'
|
|
6
8
|
import type { LoggerService } from './logger-service.interface.mjs'
|
|
7
9
|
|
|
8
|
-
import { getServiceLocator, Injectable } from '../service-locator/index.mjs'
|
|
9
10
|
import { Request } from '../tokens/index.mjs'
|
|
10
11
|
import {
|
|
11
12
|
clc,
|
|
@@ -178,7 +179,7 @@ export class ConsoleLogger implements LoggerService {
|
|
|
178
179
|
this.originalContext = context
|
|
179
180
|
}
|
|
180
181
|
if (opts?.requestId) {
|
|
181
|
-
const locator =
|
|
182
|
+
const locator = getGlobalServiceLocator()
|
|
182
183
|
locator
|
|
183
184
|
.getEventBus()
|
|
184
185
|
.on(locator.getInstanceIdentifier(Request, undefined), 'create', () => {
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
+
import { Injectable, InjectableType, InjectionToken } from '@navios/di'
|
|
2
|
+
|
|
1
3
|
import { z } from 'zod'
|
|
2
4
|
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
InjectableType,
|
|
6
|
-
InjectionToken,
|
|
7
|
-
} from '../service-locator/index.mjs'
|
|
5
|
+
import type { LoggerService } from './logger-service.interface.mjs'
|
|
6
|
+
|
|
8
7
|
import { LoggerInstance } from './logger.service.mjs'
|
|
9
8
|
|
|
10
9
|
export const LoggerInjectionToken = 'LoggerInjectionToken'
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { Injectable } from '@navios/di'
|
|
2
|
+
|
|
1
3
|
import type { LogLevel } from './log-levels.mjs'
|
|
2
4
|
import type { LoggerService } from './logger-service.interface.mjs'
|
|
3
5
|
|
|
4
|
-
import { Injectable } from '../service-locator/index.mjs'
|
|
5
6
|
import { ConsoleLogger } from './console-logger.service.mjs'
|
|
6
7
|
import { isLogLevelEnabled, isObject } from './utils/index.mjs'
|
|
7
8
|
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import type { CanActivate } from '../interfaces/index.mjs'
|
|
2
1
|
import type {
|
|
3
2
|
ClassType,
|
|
4
3
|
ClassTypeWithInstance,
|
|
5
4
|
InjectionToken,
|
|
6
|
-
} from '
|
|
5
|
+
} from '@navios/di'
|
|
6
|
+
|
|
7
|
+
import type { CanActivate } from '../interfaces/index.mjs'
|
|
7
8
|
import type { HandlerMetadata } from './handler.metadata.mjs'
|
|
8
9
|
|
|
9
10
|
import { getAllEndpointMetadata } from './handler.metadata.mjs'
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import type { HttpMethod } from '@navios/common'
|
|
2
|
+
import type { ClassTypeWithInstance, InjectionToken } from '@navios/di'
|
|
2
3
|
import type { HttpHeader } from 'fastify/types/utils.js'
|
|
3
4
|
|
|
4
5
|
import type { HandlerAdapterInterface } from '../adapters/index.mjs'
|
|
5
6
|
import type { CanActivate } from '../interfaces/index.mjs'
|
|
6
|
-
import type {
|
|
7
|
-
ClassTypeWithInstance,
|
|
8
|
-
InjectionToken,
|
|
9
|
-
} from '../service-locator/index.mjs'
|
|
10
7
|
|
|
11
8
|
export const EndpointMetadataKey = Symbol('EndpointMetadataKey')
|
|
12
9
|
|
package/src/metadata/index.mts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import type { CanActivate } from '../index.mjs'
|
|
2
1
|
import type {
|
|
3
2
|
ClassType,
|
|
4
3
|
ClassTypeWithInstance,
|
|
5
4
|
InjectionToken,
|
|
6
|
-
} from '
|
|
5
|
+
} from '@navios/di'
|
|
6
|
+
|
|
7
|
+
import type { CanActivate } from '../index.mjs'
|
|
7
8
|
|
|
8
9
|
export const ModuleMetadataKey = Symbol('ControllerMetadataKey')
|
|
9
10
|
|
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
import type { FastifyCorsOptions } from '@fastify/cors'
|
|
2
2
|
import type { FastifyMultipartOptions } from '@fastify/multipart'
|
|
3
|
+
import type { ClassTypeWithInstance } from '@navios/di'
|
|
3
4
|
import type {
|
|
4
5
|
FastifyInstance,
|
|
5
6
|
FastifyListenOptions,
|
|
6
7
|
FastifyServerOptions,
|
|
7
8
|
} from 'fastify'
|
|
8
9
|
|
|
10
|
+
import {
|
|
11
|
+
getGlobalServiceLocator,
|
|
12
|
+
inject,
|
|
13
|
+
Injectable,
|
|
14
|
+
syncInject,
|
|
15
|
+
} from '@navios/di'
|
|
16
|
+
|
|
9
17
|
import cors from '@fastify/cors'
|
|
10
18
|
import multipart from '@fastify/multipart'
|
|
11
19
|
import { fastify } from 'fastify'
|
|
@@ -16,16 +24,9 @@ import {
|
|
|
16
24
|
|
|
17
25
|
import type { NaviosModule } from './interfaces/index.mjs'
|
|
18
26
|
import type { LoggerService, LogLevel } from './logger/index.mjs'
|
|
19
|
-
import type { ClassTypeWithInstance } from './service-locator/index.mjs'
|
|
20
27
|
|
|
21
28
|
import { HttpException } from './exceptions/index.mjs'
|
|
22
29
|
import { Logger, PinoWrapper } from './logger/index.mjs'
|
|
23
|
-
import {
|
|
24
|
-
getServiceLocator,
|
|
25
|
-
inject,
|
|
26
|
-
Injectable,
|
|
27
|
-
syncInject,
|
|
28
|
-
} from './service-locator/index.mjs'
|
|
29
30
|
import {
|
|
30
31
|
ControllerAdapterService,
|
|
31
32
|
ModuleLoaderService,
|
|
@@ -75,7 +76,7 @@ export class NaviosApplication {
|
|
|
75
76
|
await this.moduleLoader.loadModules(this.appModule)
|
|
76
77
|
this.server = await this.getFastifyInstance(this.options)
|
|
77
78
|
this.configureFastifyInstance(this.server)
|
|
78
|
-
|
|
79
|
+
getGlobalServiceLocator().storeInstance(this.server, Application)
|
|
79
80
|
// Add schema validator and serializer
|
|
80
81
|
this.server.setValidatorCompiler(validatorCompiler)
|
|
81
82
|
this.server.setSerializerCompiler(serializerCompiler)
|
package/src/navios.factory.mts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
+
import type { ClassTypeWithInstance } from '@navios/di'
|
|
2
|
+
|
|
3
|
+
import { inject } from '@navios/di'
|
|
4
|
+
|
|
1
5
|
import type { NaviosModule } from './interfaces/index.mjs'
|
|
2
6
|
import type {
|
|
3
7
|
NaviosApplicationContextOptions,
|
|
4
8
|
NaviosApplicationOptions,
|
|
5
9
|
} from './navios.application.mjs'
|
|
6
|
-
import type { ClassTypeWithInstance } from './service-locator/index.mjs'
|
|
7
10
|
|
|
8
11
|
import { isNil, LoggerInstance } from './logger/index.mjs'
|
|
9
12
|
import { NaviosApplication } from './navios.application.mjs'
|
|
10
|
-
import { inject } from './service-locator/index.mjs'
|
|
11
13
|
|
|
12
14
|
export class NaviosFactory {
|
|
13
15
|
static async create(
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
+
import type { ClassType } from '@navios/di'
|
|
1
2
|
import type { FastifyInstance, FastifyReply, FastifyRequest } from 'fastify'
|
|
2
3
|
import type { ZodTypeProvider } from 'fastify-type-provider-zod'
|
|
3
4
|
|
|
4
|
-
import type { HandlerAdapterInterface } from '../adapters/index.mjs'
|
|
5
|
-
import type { ModuleMetadata } from '../metadata/index.mjs'
|
|
6
|
-
import type { ClassType } from '../service-locator/index.mjs'
|
|
7
|
-
|
|
8
|
-
import { Logger } from '../logger/index.mjs'
|
|
9
|
-
import { extractControllerMetadata } from '../metadata/index.mjs'
|
|
10
5
|
import {
|
|
11
|
-
|
|
6
|
+
getGlobalServiceLocator,
|
|
12
7
|
inject,
|
|
13
8
|
Injectable,
|
|
14
9
|
InjectionToken,
|
|
15
10
|
syncInject,
|
|
16
|
-
} from '
|
|
11
|
+
} from '@navios/di'
|
|
12
|
+
|
|
13
|
+
import type { HandlerAdapterInterface } from '../adapters/index.mjs'
|
|
14
|
+
import type { ModuleMetadata } from '../metadata/index.mjs'
|
|
15
|
+
|
|
16
|
+
import { Logger } from '../logger/index.mjs'
|
|
17
|
+
import { extractControllerMetadata } from '../metadata/index.mjs'
|
|
17
18
|
import { ExecutionContextToken, Reply, Request } from '../tokens/index.mjs'
|
|
18
19
|
import { ExecutionContext } from './execution-context.mjs'
|
|
19
20
|
import { GuardRunnerService } from './guard-runner.service.mjs'
|
|
@@ -100,11 +101,11 @@ export class ControllerAdapterService {
|
|
|
100
101
|
executionContext: ExecutionContext,
|
|
101
102
|
handler: (request: FastifyRequest, reply: FastifyReply) => Promise<void>,
|
|
102
103
|
) {
|
|
103
|
-
const locator =
|
|
104
|
+
const locator = getGlobalServiceLocator()
|
|
104
105
|
return async (request: FastifyRequest, reply: FastifyReply) => {
|
|
105
|
-
locator.
|
|
106
|
-
locator.
|
|
107
|
-
locator.
|
|
106
|
+
locator.storeInstance(request, Request)
|
|
107
|
+
locator.storeInstance(reply, Reply)
|
|
108
|
+
locator.storeInstance(executionContext, ExecutionContextToken)
|
|
108
109
|
executionContext.provideRequest(request)
|
|
109
110
|
executionContext.provideReply(reply)
|
|
110
111
|
try {
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
+
import type { ClassTypeWithInstance } from '@navios/di'
|
|
2
|
+
|
|
3
|
+
import { inject, Injectable, InjectionToken } from '@navios/di'
|
|
4
|
+
|
|
1
5
|
import type { CanActivate } from '../interfaces/index.mjs'
|
|
2
|
-
import type { ClassTypeWithInstance } from '../service-locator/index.mjs'
|
|
3
6
|
import type { ExecutionContext } from './execution-context.mjs'
|
|
4
7
|
|
|
5
8
|
import { HttpException } from '../exceptions/index.mjs'
|
|
6
|
-
import {
|
|
7
|
-
inject,
|
|
8
|
-
Injectable,
|
|
9
|
-
InjectionToken,
|
|
10
|
-
} from '../service-locator/index.mjs'
|
|
11
9
|
|
|
12
10
|
@Injectable()
|
|
13
11
|
export class GuardRunnerService {
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import type { ClassTypeWithInstance } from '@navios/di'
|
|
2
|
+
|
|
3
|
+
import { inject, Injectable, syncInject } from '@navios/di'
|
|
4
|
+
|
|
1
5
|
import type { NaviosModule } from '../interfaces/index.mjs'
|
|
2
6
|
import type { ModuleMetadata } from '../metadata/index.mjs'
|
|
3
|
-
import type { ClassTypeWithInstance } from '../service-locator/index.mjs'
|
|
4
7
|
|
|
5
8
|
import { Logger } from '../logger/index.mjs'
|
|
6
9
|
import { extractModuleMetadata } from '../metadata/index.mjs'
|
|
7
|
-
import { inject, Injectable, syncInject } from '../service-locator/index.mjs'
|
|
8
10
|
|
|
9
11
|
@Injectable()
|
|
10
12
|
export class ModuleLoaderService {
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
InjectableScope,
|
|
3
|
-
InjectableType,
|
|
4
|
-
InjectionToken,
|
|
5
|
-
} from '../index.mjs'
|
|
6
|
-
|
|
7
|
-
export interface InjectableMetadata<Instance = any, Schema = any> {
|
|
8
|
-
type: InjectableType
|
|
9
|
-
scope: InjectableScope
|
|
10
|
-
token: InjectionToken<Instance, Schema>
|
|
11
|
-
}
|