@navios/core 0.1.0 → 0.1.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/index.d.mts +432 -11
- package/dist/index.d.ts +432 -11
- package/dist/index.js +798 -38
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +771 -37
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/index.mts +1 -0
- package/src/logger/README.md +3 -0
- package/src/logger/console-logger.service.mts +588 -0
- package/src/logger/index.mts +7 -0
- package/src/logger/log-levels.mts +12 -0
- package/src/logger/logger-service.interface.mts +42 -0
- package/src/logger/logger.factory.mts +37 -0
- package/src/logger/logger.service.mts +214 -0
- package/src/logger/pino-wrapper.mts +63 -0
- package/src/logger/utils/cli-colors.util.mts +17 -0
- package/src/logger/utils/filter-log-levelts.util.mts +29 -0
- package/src/logger/utils/index.mts +5 -0
- package/src/logger/utils/is-log-level-enabled.mts +33 -0
- package/src/logger/utils/is-log-level.util.mts +10 -0
- package/src/logger/utils/shared.utils.mts +51 -0
- package/src/navios.application.mts +71 -18
- package/src/navios.factory.mts +18 -1
- package/src/service-locator/inject.mts +6 -1
- package/src/service-locator/injection-token.mts +11 -6
- package/src/service-locator/service-locator.mts +44 -15
- package/src/service-locator/sync-injector.mts +6 -1
- package/src/services/controller-adapter.service.mts +8 -0
- package/src/services/module-loader.service.mts +6 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-empty-object-type */
|
|
3
|
-
import type { AnyZodObject, z } from 'zod'
|
|
3
|
+
import type { AnyZodObject, z, ZodOptional } from 'zod'
|
|
4
4
|
|
|
5
5
|
import type { ServiceLocatorAbstractFactoryContext } from './service-locator-abstract-factory-context.mjs'
|
|
6
6
|
import type { ServiceLocatorInstanceHolder } from './service-locator-instance-holder.mjs'
|
|
@@ -65,7 +65,7 @@ export class ServiceLocator {
|
|
|
65
65
|
|
|
66
66
|
public registerAbstractFactory<
|
|
67
67
|
Instance,
|
|
68
|
-
Schema extends AnyZodObject | undefined,
|
|
68
|
+
Schema extends AnyZodObject | ZodOptional<AnyZodObject> | undefined,
|
|
69
69
|
>(
|
|
70
70
|
token: InjectionToken<Instance, Schema>,
|
|
71
71
|
factory: (
|
|
@@ -88,10 +88,14 @@ export class ServiceLocator {
|
|
|
88
88
|
|
|
89
89
|
public getInstanceIdentifier<
|
|
90
90
|
Instance,
|
|
91
|
-
Schema extends AnyZodObject | undefined,
|
|
91
|
+
Schema extends AnyZodObject | ZodOptional<AnyZodObject> | undefined,
|
|
92
92
|
>(
|
|
93
93
|
token: InjectionToken<Instance, Schema>,
|
|
94
|
-
args: Schema extends AnyZodObject
|
|
94
|
+
args: Schema extends AnyZodObject
|
|
95
|
+
? z.input<Schema>
|
|
96
|
+
: Schema extends ZodOptional<AnyZodObject>
|
|
97
|
+
? z.input<Schema> | undefined
|
|
98
|
+
: undefined,
|
|
95
99
|
): string {
|
|
96
100
|
const validatedArgs = token.schema
|
|
97
101
|
? token.schema.safeParse(args)
|
|
@@ -106,9 +110,16 @@ export class ServiceLocator {
|
|
|
106
110
|
return this.makeInstanceName(token, validatedArgs)
|
|
107
111
|
}
|
|
108
112
|
|
|
109
|
-
public async getInstance<
|
|
113
|
+
public async getInstance<
|
|
114
|
+
Instance,
|
|
115
|
+
Schema extends AnyZodObject | ZodOptional<AnyZodObject> | undefined,
|
|
116
|
+
>(
|
|
110
117
|
token: InjectionToken<Instance, Schema>,
|
|
111
|
-
args: Schema extends AnyZodObject
|
|
118
|
+
args: Schema extends AnyZodObject
|
|
119
|
+
? z.input<Schema>
|
|
120
|
+
: Schema extends ZodOptional<AnyZodObject>
|
|
121
|
+
? z.input<Schema> | undefined
|
|
122
|
+
: undefined,
|
|
112
123
|
): Promise<[undefined, Instance] | [UnknownError | FactoryNotFound]> {
|
|
113
124
|
const validatedArgs = token.schema
|
|
114
125
|
? token.schema.safeParse(args)
|
|
@@ -161,10 +172,14 @@ export class ServiceLocator {
|
|
|
161
172
|
|
|
162
173
|
public async getOrThrowInstance<
|
|
163
174
|
Instance,
|
|
164
|
-
Schema extends AnyZodObject | undefined,
|
|
175
|
+
Schema extends AnyZodObject | ZodOptional<AnyZodObject> | undefined,
|
|
165
176
|
>(
|
|
166
177
|
token: InjectionToken<Instance, Schema>,
|
|
167
|
-
args: Schema extends AnyZodObject
|
|
178
|
+
args: Schema extends AnyZodObject
|
|
179
|
+
? z.input<Schema>
|
|
180
|
+
: Schema extends ZodOptional<AnyZodObject>
|
|
181
|
+
? z.input<Schema> | undefined
|
|
182
|
+
: undefined,
|
|
168
183
|
): Promise<Instance> {
|
|
169
184
|
const [error, instance] = await this.getInstance(token, args)
|
|
170
185
|
if (error) {
|
|
@@ -185,11 +200,15 @@ export class ServiceLocator {
|
|
|
185
200
|
|
|
186
201
|
private async createInstance<
|
|
187
202
|
Instance,
|
|
188
|
-
Schema extends AnyZodObject | undefined,
|
|
203
|
+
Schema extends AnyZodObject | ZodOptional<AnyZodObject> | undefined,
|
|
189
204
|
>(
|
|
190
205
|
instanceName: string,
|
|
191
206
|
token: InjectionToken<Instance, Schema>,
|
|
192
|
-
args: Schema extends AnyZodObject
|
|
207
|
+
args: Schema extends AnyZodObject
|
|
208
|
+
? z.input<Schema>
|
|
209
|
+
: Schema extends ZodOptional<AnyZodObject>
|
|
210
|
+
? z.input<Schema> | undefined
|
|
211
|
+
: undefined,
|
|
193
212
|
): Promise<[undefined, Instance] | [FactoryNotFound | UnknownError]> {
|
|
194
213
|
this.logger?.log(
|
|
195
214
|
`[ServiceLocator]#createInstance() Creating instance for ${instanceName}`,
|
|
@@ -206,8 +225,12 @@ export class ServiceLocator {
|
|
|
206
225
|
|
|
207
226
|
private async createInstanceFromAbstractFactory<
|
|
208
227
|
Instance,
|
|
209
|
-
Schema extends AnyZodObject | undefined,
|
|
210
|
-
Args extends Schema extends AnyZodObject
|
|
228
|
+
Schema extends AnyZodObject | ZodOptional<AnyZodObject> | undefined,
|
|
229
|
+
Args extends Schema extends AnyZodObject
|
|
230
|
+
? z.input<Schema>
|
|
231
|
+
: Schema extends ZodOptional<AnyZodObject>
|
|
232
|
+
? z.input<Schema> | undefined
|
|
233
|
+
: undefined,
|
|
211
234
|
>(
|
|
212
235
|
instanceName: string,
|
|
213
236
|
token: InjectionToken<Instance, Schema>,
|
|
@@ -320,7 +343,6 @@ export class ServiceLocator {
|
|
|
320
343
|
: undefined
|
|
321
344
|
const instanceName = self.makeInstanceName(token, validatedArgs)
|
|
322
345
|
dependencies.add(instanceName)
|
|
323
|
-
// @ts-expect-error TS2322 This is correct type
|
|
324
346
|
return self.getOrThrowInstance(injectionToken, args)
|
|
325
347
|
}
|
|
326
348
|
throw new Error(
|
|
@@ -338,9 +360,16 @@ export class ServiceLocator {
|
|
|
338
360
|
}
|
|
339
361
|
}
|
|
340
362
|
|
|
341
|
-
public getSyncInstance<
|
|
363
|
+
public getSyncInstance<
|
|
364
|
+
Instance,
|
|
365
|
+
Schema extends AnyZodObject | ZodOptional<AnyZodObject> | undefined,
|
|
366
|
+
>(
|
|
342
367
|
token: InjectionToken<Instance, Schema>,
|
|
343
|
-
args: Schema extends AnyZodObject
|
|
368
|
+
args: Schema extends AnyZodObject
|
|
369
|
+
? z.input<Schema>
|
|
370
|
+
: Schema extends ZodOptional<AnyZodObject>
|
|
371
|
+
? z.input<Schema> | undefined
|
|
372
|
+
: undefined,
|
|
344
373
|
): Instance | null {
|
|
345
374
|
const validatedArgs = token.schema
|
|
346
375
|
? token.schema.safeParse(args)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AnyZodObject, z } from 'zod'
|
|
1
|
+
import type { AnyZodObject, z, ZodOptional } from 'zod'
|
|
2
2
|
|
|
3
3
|
import type { ClassType } from './injection-token.mjs'
|
|
4
4
|
|
|
@@ -13,6 +13,11 @@ export function syncInject<T, S extends AnyZodObject>(
|
|
|
13
13
|
token: InjectionToken<T, S>,
|
|
14
14
|
args: z.input<S>,
|
|
15
15
|
): T
|
|
16
|
+
export function syncInject<T, S extends ZodOptional<AnyZodObject>>(
|
|
17
|
+
token: InjectionToken<T, S>,
|
|
18
|
+
args: z.input<S>,
|
|
19
|
+
): T
|
|
20
|
+
|
|
16
21
|
export function syncInject<T>(token: InjectionToken<T, undefined>): T
|
|
17
22
|
export function syncInject<
|
|
18
23
|
T,
|
|
@@ -5,6 +5,7 @@ import type { ModuleMetadata } from '../metadata/index.mjs'
|
|
|
5
5
|
import type { ClassType } from '../service-locator/index.mjs'
|
|
6
6
|
|
|
7
7
|
import { HttpException } from '../exceptions/index.mjs'
|
|
8
|
+
import { Logger } from '../logger/index.mjs'
|
|
8
9
|
import { extractControllerMetadata } from '../metadata/index.mjs'
|
|
9
10
|
import {
|
|
10
11
|
getServiceLocator,
|
|
@@ -19,6 +20,9 @@ import { GuardRunnerService } from './guard-runner.service.mjs'
|
|
|
19
20
|
@Injectable()
|
|
20
21
|
export class ControllerAdapterService {
|
|
21
22
|
guardRunner = syncInject(GuardRunnerService)
|
|
23
|
+
private logger = syncInject(Logger, {
|
|
24
|
+
context: ControllerAdapterService.name,
|
|
25
|
+
})
|
|
22
26
|
|
|
23
27
|
setupController(
|
|
24
28
|
controller: ClassType,
|
|
@@ -119,6 +123,10 @@ export class ControllerAdapterService {
|
|
|
119
123
|
}
|
|
120
124
|
},
|
|
121
125
|
})
|
|
126
|
+
|
|
127
|
+
this.logger.debug(
|
|
128
|
+
`Registered ${httpMethod} ${url} for ${controller.name}:${classMethod}`,
|
|
129
|
+
)
|
|
122
130
|
}
|
|
123
131
|
}
|
|
124
132
|
}
|
|
@@ -2,11 +2,15 @@ import type { NaviosModule } from '../interfaces/index.mjs'
|
|
|
2
2
|
import type { ModuleMetadata } from '../metadata/index.mjs'
|
|
3
3
|
import type { ClassTypeWithInstance } from '../service-locator/index.mjs'
|
|
4
4
|
|
|
5
|
+
import { Logger } from '../logger/index.mjs'
|
|
5
6
|
import { extractModuleMetadata } from '../metadata/index.mjs'
|
|
6
|
-
import { inject, Injectable } from '../service-locator/index.mjs'
|
|
7
|
+
import { inject, Injectable, syncInject } from '../service-locator/index.mjs'
|
|
7
8
|
|
|
8
9
|
@Injectable()
|
|
9
10
|
export class ModuleLoaderService {
|
|
11
|
+
private logger = syncInject(Logger, {
|
|
12
|
+
context: ModuleLoaderService.name,
|
|
13
|
+
})
|
|
10
14
|
private modulesMetadata: Map<string, ModuleMetadata> = new Map()
|
|
11
15
|
private loadedModules: Map<string, any> = new Map()
|
|
12
16
|
private initialized = false
|
|
@@ -41,6 +45,7 @@ export class ModuleLoaderService {
|
|
|
41
45
|
if (instance.onModuleInit) {
|
|
42
46
|
await instance.onModuleInit()
|
|
43
47
|
}
|
|
48
|
+
this.logger.debug(`Module ${moduleName} loaded`)
|
|
44
49
|
this.loadedModules.set(moduleName, instance)
|
|
45
50
|
}
|
|
46
51
|
|