@navios/core 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +96 -3
- package/docs/README.md +310 -3
- package/docs/adapters.md +308 -0
- package/docs/application-setup.md +524 -0
- package/docs/attributes.md +689 -0
- package/docs/controllers.md +373 -0
- package/docs/endpoints.md +444 -0
- package/docs/exceptions.md +316 -0
- package/docs/guards.md +550 -0
- package/docs/modules.md +251 -0
- package/docs/quick-start.md +295 -0
- package/docs/services.md +428 -0
- package/docs/testing.md +704 -0
- package/lib/_tsup-dts-rollup.d.mts +313 -280
- package/lib/_tsup-dts-rollup.d.ts +313 -280
- package/lib/index.d.mts +47 -26
- package/lib/index.d.ts +47 -26
- package/lib/index.js +633 -1068
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +632 -1061
- package/lib/index.mjs.map +1 -1
- package/package.json +11 -12
- package/project.json +17 -4
- package/src/__tests__/config.service.spec.mts +11 -9
- package/src/__tests__/controller.spec.mts +1 -2
- package/src/attribute.factory.mts +1 -1
- package/src/config/config.provider.mts +2 -2
- package/src/config/config.service.mts +4 -4
- package/src/decorators/controller.decorator.mts +1 -1
- package/src/decorators/endpoint.decorator.mts +9 -10
- package/src/decorators/header.decorator.mts +1 -1
- package/src/decorators/multipart.decorator.mts +5 -5
- package/src/decorators/stream.decorator.mts +5 -6
- package/src/factories/endpoint-adapter.factory.mts +21 -0
- package/src/factories/http-adapter.factory.mts +20 -0
- package/src/factories/index.mts +6 -0
- package/src/factories/multipart-adapter.factory.mts +21 -0
- package/src/factories/reply.factory.mts +21 -0
- package/src/factories/request.factory.mts +21 -0
- package/src/factories/stream-adapter.factory.mts +20 -0
- package/src/index.mts +1 -1
- package/src/interfaces/abstract-execution-context.inteface.mts +13 -0
- package/src/interfaces/abstract-http-adapter.interface.mts +20 -0
- package/src/interfaces/abstract-http-cors-options.interface.mts +59 -0
- package/src/interfaces/abstract-http-handler-adapter.interface.mts +13 -0
- package/src/interfaces/abstract-http-listen-options.interface.mts +4 -0
- package/src/interfaces/can-activate.mts +4 -2
- package/src/interfaces/http-header.mts +18 -0
- package/src/interfaces/index.mts +6 -0
- package/src/logger/console-logger.service.mts +28 -44
- package/src/logger/index.mts +1 -2
- package/src/logger/logger.service.mts +9 -128
- package/src/logger/logger.tokens.mts +21 -0
- package/src/metadata/handler.metadata.mts +7 -5
- package/src/navios.application.mts +65 -172
- package/src/navios.environment.mts +30 -0
- package/src/navios.factory.mts +53 -12
- package/src/services/guard-runner.service.mts +19 -9
- package/src/services/index.mts +0 -2
- package/src/services/module-loader.service.mts +4 -3
- package/src/tokens/endpoint-adapter.token.mts +8 -0
- package/src/tokens/execution-context.token.mts +2 -2
- package/src/tokens/http-adapter.token.mts +8 -0
- package/src/tokens/index.mts +4 -1
- package/src/tokens/multipart-adapter.token.mts +8 -0
- package/src/tokens/reply.token.mts +1 -5
- package/src/tokens/request.token.mts +1 -7
- package/src/tokens/stream-adapter.token.mts +8 -0
- package/tsconfig.json +6 -1
- package/tsconfig.lib.json +8 -0
- package/tsconfig.spec.json +12 -0
- package/tsup.config.mts +1 -0
- package/docs/recipes/prisma.md +0 -60
- package/examples/simple-test/api/index.mts +0 -64
- package/examples/simple-test/config/config.service.mts +0 -14
- package/examples/simple-test/config/configuration.mts +0 -7
- package/examples/simple-test/index.mts +0 -16
- package/examples/simple-test/src/acl/acl-modern.guard.mts +0 -15
- package/examples/simple-test/src/acl/acl.guard.mts +0 -14
- package/examples/simple-test/src/acl/app.guard.mts +0 -27
- package/examples/simple-test/src/acl/one-more.guard.mts +0 -15
- package/examples/simple-test/src/acl/public.attribute.mts +0 -21
- package/examples/simple-test/src/app.module.mts +0 -9
- package/examples/simple-test/src/user/user.controller.mts +0 -72
- package/examples/simple-test/src/user/user.module.mts +0 -14
- package/examples/simple-test/src/user/user.service.mts +0 -14
- package/src/adapters/endpoint-adapter.service.mts +0 -72
- package/src/adapters/handler-adapter.interface.mts +0 -21
- package/src/adapters/index.mts +0 -4
- package/src/adapters/multipart-adapter.service.mts +0 -131
- package/src/adapters/stream-adapter.service.mts +0 -91
- package/src/logger/logger.factory.mts +0 -36
- package/src/logger/pino-wrapper.mts +0 -64
- package/src/services/controller-adapter.service.mts +0 -124
- package/src/services/execution-context.mts +0 -54
- package/src/tokens/application.token.mts +0 -9
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { AnyInjectableType, InjectionToken } from '@navios/di'
|
|
2
|
+
|
|
3
|
+
import { Injectable } from '@navios/di'
|
|
4
|
+
|
|
5
|
+
export interface NaviosEnvironmentOptions {
|
|
6
|
+
// Future options can be added here
|
|
7
|
+
httpTokens?: Map<InjectionToken<any, undefined>, AnyInjectableType>
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
@Injectable()
|
|
11
|
+
export class NaviosEnvironment {
|
|
12
|
+
private httpTokens = new Map<
|
|
13
|
+
InjectionToken<any, undefined>,
|
|
14
|
+
AnyInjectableType
|
|
15
|
+
>()
|
|
16
|
+
|
|
17
|
+
setupHttpEnvironment(
|
|
18
|
+
tokens: Map<InjectionToken<any, undefined>, AnyInjectableType>,
|
|
19
|
+
) {
|
|
20
|
+
this.httpTokens = tokens
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
getHttpToken(token: InjectionToken<any, undefined>) {
|
|
24
|
+
return this.httpTokens.get(token)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
hasHttpSetup() {
|
|
28
|
+
return this.httpTokens.size > 0
|
|
29
|
+
}
|
|
30
|
+
}
|
package/src/navios.factory.mts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
AnyInjectableType,
|
|
3
|
+
ClassTypeWithInstance,
|
|
4
|
+
InjectionToken,
|
|
5
|
+
} from '@navios/di'
|
|
2
6
|
|
|
3
|
-
import {
|
|
7
|
+
import { Container, InjectableScope, InjectableType } from '@navios/di'
|
|
4
8
|
|
|
5
9
|
import type { NaviosModule } from './interfaces/index.mjs'
|
|
6
10
|
import type {
|
|
@@ -8,29 +12,66 @@ import type {
|
|
|
8
12
|
NaviosApplicationOptions,
|
|
9
13
|
} from './navios.application.mjs'
|
|
10
14
|
|
|
11
|
-
import { isNil,
|
|
15
|
+
import { ConsoleLogger, isNil, LoggerOutput } from './logger/index.mjs'
|
|
12
16
|
import { NaviosApplication } from './navios.application.mjs'
|
|
17
|
+
import { NaviosEnvironment } from './navios.environment.mjs'
|
|
13
18
|
|
|
14
19
|
export class NaviosFactory {
|
|
15
20
|
static async create(
|
|
16
21
|
appModule: ClassTypeWithInstance<NaviosModule>,
|
|
17
|
-
options: NaviosApplicationOptions = {
|
|
22
|
+
options: NaviosApplicationOptions = {
|
|
23
|
+
adapter: [],
|
|
24
|
+
},
|
|
18
25
|
) {
|
|
19
|
-
const
|
|
20
|
-
this.registerLoggerConfiguration(options)
|
|
21
|
-
|
|
26
|
+
const container = new Container()
|
|
27
|
+
await this.registerLoggerConfiguration(container, options)
|
|
28
|
+
const adapters = Array.isArray(options.adapter)
|
|
29
|
+
? options.adapter
|
|
30
|
+
: [options.adapter]
|
|
31
|
+
for (const adapter of adapters) {
|
|
32
|
+
await this.registerEnvironment(container, adapter)
|
|
33
|
+
}
|
|
34
|
+
const app = await container.get(NaviosApplication)
|
|
35
|
+
await app.setup(appModule, options)
|
|
22
36
|
return app
|
|
23
37
|
}
|
|
24
38
|
|
|
25
|
-
private static
|
|
26
|
-
|
|
39
|
+
private static async registerEnvironment(
|
|
40
|
+
container: Container,
|
|
41
|
+
environment: {
|
|
42
|
+
httpTokens?: Map<InjectionToken<any, undefined>, AnyInjectableType>
|
|
43
|
+
} = {},
|
|
27
44
|
) {
|
|
28
|
-
|
|
29
|
-
|
|
45
|
+
const naviosEnvironment = await container.get(NaviosEnvironment)
|
|
46
|
+
const { httpTokens } = environment
|
|
47
|
+
if (httpTokens) {
|
|
48
|
+
naviosEnvironment.setupHttpEnvironment(httpTokens)
|
|
30
49
|
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
private static async registerLoggerConfiguration(
|
|
53
|
+
container: Container,
|
|
54
|
+
options: NaviosApplicationContextOptions,
|
|
55
|
+
) {
|
|
31
56
|
const { logger } = options
|
|
57
|
+
if (Array.isArray(logger) || isNil(logger)) {
|
|
58
|
+
const loggerInstance = (await container.get(
|
|
59
|
+
LoggerOutput,
|
|
60
|
+
)) as ConsoleLogger
|
|
61
|
+
loggerInstance?.setup({
|
|
62
|
+
logLevels: logger,
|
|
63
|
+
})
|
|
64
|
+
}
|
|
32
65
|
if ((logger as boolean) !== true && !isNil(logger)) {
|
|
33
|
-
|
|
66
|
+
container
|
|
67
|
+
.getServiceLocator()
|
|
68
|
+
.getManager()
|
|
69
|
+
.storeCreatedHolder(
|
|
70
|
+
LoggerOutput.toString(),
|
|
71
|
+
logger,
|
|
72
|
+
InjectableType.Class,
|
|
73
|
+
InjectableScope.Singleton,
|
|
74
|
+
)
|
|
34
75
|
}
|
|
35
76
|
}
|
|
36
77
|
}
|
|
@@ -1,24 +1,32 @@
|
|
|
1
1
|
import type { ClassTypeWithInstance } from '@navios/di'
|
|
2
2
|
|
|
3
|
-
import { inject, Injectable, InjectionToken } from '@navios/di'
|
|
3
|
+
import { Container, inject, Injectable, InjectionToken } from '@navios/di'
|
|
4
4
|
|
|
5
|
-
import type {
|
|
6
|
-
|
|
5
|
+
import type {
|
|
6
|
+
AbstractExecutionContext,
|
|
7
|
+
CanActivate,
|
|
8
|
+
} from '../interfaces/index.mjs'
|
|
9
|
+
import type {
|
|
10
|
+
ControllerMetadata,
|
|
11
|
+
HandlerMetadata,
|
|
12
|
+
ModuleMetadata,
|
|
13
|
+
} from '../metadata/index.mjs'
|
|
7
14
|
|
|
8
15
|
import { HttpException } from '../exceptions/index.mjs'
|
|
9
16
|
|
|
10
17
|
@Injectable()
|
|
11
18
|
export class GuardRunnerService {
|
|
19
|
+
protected container = inject(Container)
|
|
12
20
|
async runGuards(
|
|
13
21
|
allGuards: Set<
|
|
14
22
|
| ClassTypeWithInstance<CanActivate>
|
|
15
23
|
| InjectionToken<CanActivate, undefined>
|
|
16
24
|
>,
|
|
17
|
-
executionContext:
|
|
25
|
+
executionContext: AbstractExecutionContext,
|
|
18
26
|
) {
|
|
19
27
|
let canActivate = true
|
|
20
28
|
for (const guard of Array.from(allGuards).reverse()) {
|
|
21
|
-
const guardInstance = await
|
|
29
|
+
const guardInstance = await this.container.get(
|
|
22
30
|
guard as InjectionToken<CanActivate, undefined>,
|
|
23
31
|
)
|
|
24
32
|
if (!guardInstance.canActivate) {
|
|
@@ -60,7 +68,9 @@ export class GuardRunnerService {
|
|
|
60
68
|
}
|
|
61
69
|
|
|
62
70
|
makeContext(
|
|
63
|
-
|
|
71
|
+
moduleMetadata: ModuleMetadata,
|
|
72
|
+
controllerMetadata: ControllerMetadata,
|
|
73
|
+
endpoint: HandlerMetadata,
|
|
64
74
|
): Set<
|
|
65
75
|
ClassTypeWithInstance<CanActivate> | InjectionToken<CanActivate, undefined>
|
|
66
76
|
> {
|
|
@@ -68,9 +78,9 @@ export class GuardRunnerService {
|
|
|
68
78
|
| ClassTypeWithInstance<CanActivate>
|
|
69
79
|
| InjectionToken<CanActivate, undefined>
|
|
70
80
|
>()
|
|
71
|
-
const endpointGuards =
|
|
72
|
-
const controllerGuards =
|
|
73
|
-
const moduleGuards =
|
|
81
|
+
const endpointGuards = endpoint.guards
|
|
82
|
+
const controllerGuards = controllerMetadata.guards
|
|
83
|
+
const moduleGuards = moduleMetadata.guards
|
|
74
84
|
if (endpointGuards.size > 0) {
|
|
75
85
|
for (const guard of endpointGuards) {
|
|
76
86
|
guards.add(guard)
|
package/src/services/index.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ClassTypeWithInstance } from '@navios/di'
|
|
2
2
|
|
|
3
|
-
import { inject, Injectable
|
|
3
|
+
import { Container, inject, Injectable } from '@navios/di'
|
|
4
4
|
|
|
5
5
|
import type { NaviosModule } from '../interfaces/index.mjs'
|
|
6
6
|
import type { ModuleMetadata } from '../metadata/index.mjs'
|
|
@@ -10,9 +10,10 @@ import { extractModuleMetadata } from '../metadata/index.mjs'
|
|
|
10
10
|
|
|
11
11
|
@Injectable()
|
|
12
12
|
export class ModuleLoaderService {
|
|
13
|
-
private logger =
|
|
13
|
+
private logger = inject(Logger, {
|
|
14
14
|
context: ModuleLoaderService.name,
|
|
15
15
|
})
|
|
16
|
+
protected container = inject(Container)
|
|
16
17
|
private modulesMetadata: Map<string, ModuleMetadata> = new Map()
|
|
17
18
|
private loadedModules: Map<string, any> = new Map()
|
|
18
19
|
private initialized = false
|
|
@@ -43,7 +44,7 @@ export class ModuleLoaderService {
|
|
|
43
44
|
this.traverseModules(importedModule, metadata),
|
|
44
45
|
)
|
|
45
46
|
await Promise.all(loadingPromises)
|
|
46
|
-
const instance = await
|
|
47
|
+
const instance = await this.container.get(module)
|
|
47
48
|
if (instance.onModuleInit) {
|
|
48
49
|
await instance.onModuleInit()
|
|
49
50
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { InjectionToken } from '@navios/di'
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import type { AbstractExecutionContext } from '../interfaces/index.mjs'
|
|
4
4
|
|
|
5
5
|
export const ExecutionContextInjectionToken = 'ExecutionContextInjectionToken'
|
|
6
6
|
|
|
7
|
-
export const
|
|
7
|
+
export const ExecutionContext = InjectionToken.create<AbstractExecutionContext>(
|
|
8
8
|
ExecutionContextInjectionToken,
|
|
9
9
|
)
|
package/src/tokens/index.mts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './endpoint-adapter.token.mjs'
|
|
2
2
|
export * from './execution-context.token.mjs'
|
|
3
|
+
export * from './http-adapter.token.mjs'
|
|
4
|
+
export * from './multipart-adapter.token.mjs'
|
|
3
5
|
export * from './reply.token.mjs'
|
|
4
6
|
export * from './request.token.mjs'
|
|
7
|
+
export * from './stream-adapter.token.mjs'
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import type { FastifyReply } from 'fastify'
|
|
2
|
-
|
|
3
1
|
import { InjectionToken } from '@navios/di'
|
|
4
2
|
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
export const Reply = InjectionToken.create<FastifyReply>(ReplyInjectionToken)
|
|
3
|
+
export const Reply = InjectionToken.create<any>('ReplyToken')
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
import type { FastifyRequest } from 'fastify'
|
|
2
|
-
|
|
3
1
|
import { InjectionToken } from '@navios/di'
|
|
4
2
|
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
export const Request = InjectionToken.create<FastifyRequest>(
|
|
8
|
-
RequestInjectionToken,
|
|
9
|
-
)
|
|
3
|
+
export const Request = InjectionToken.create<any>('RequestToken')
|
package/tsconfig.json
CHANGED
package/tsup.config.mts
CHANGED
package/docs/recipes/prisma.md
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
# Prisma ORM
|
|
2
|
-
|
|
3
|
-
Prisma ORM is a modern database toolkit that simplifies database access and management. It provides a type-safe query builder, migrations, and an intuitive API for working with databases.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
Follow the steps from the [Prisma documentation](https://www.prisma.io/docs/getting-started/quickstart-typescript) to install Prisma in your project.
|
|
8
|
-
|
|
9
|
-
## Integration
|
|
10
|
-
|
|
11
|
-
The simplest way to integrate Prisma with your project is to create a factory:
|
|
12
|
-
|
|
13
|
-
```typescript
|
|
14
|
-
import { Injectable, InjectableType, InjectionToken } from '@navios/core'
|
|
15
|
-
|
|
16
|
-
import { PrismaClient } from '@prisma/client'
|
|
17
|
-
|
|
18
|
-
export const PrismaService = InjectionToken.create(PrismaClient)
|
|
19
|
-
|
|
20
|
-
@Injectable({
|
|
21
|
-
token: PrismaService,
|
|
22
|
-
type: InjectableType.Factory,
|
|
23
|
-
})
|
|
24
|
-
export class PrismaServiceFactory {
|
|
25
|
-
async create() {
|
|
26
|
-
const client = new PrismaClient()
|
|
27
|
-
await client.$connect()
|
|
28
|
-
return client
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
## Usage
|
|
34
|
-
|
|
35
|
-
You can use the Prisma Service in your application by injecting it into your classes. Here's an example of how to use it in a service:
|
|
36
|
-
|
|
37
|
-
```typescript
|
|
38
|
-
import { Injectable, syncInject } from '@navios/core'
|
|
39
|
-
|
|
40
|
-
import { PrismaService } from './prisma.service.mjs'
|
|
41
|
-
|
|
42
|
-
@Injectable()
|
|
43
|
-
export class UserService {
|
|
44
|
-
private readonly prisma = syncInject(PrismaService)
|
|
45
|
-
|
|
46
|
-
async getUser(id: string) {
|
|
47
|
-
return this.prisma.user.findUnique({
|
|
48
|
-
where: { id },
|
|
49
|
-
})
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
async createUser(data: { name: string; email: string }) {
|
|
53
|
-
return this.prisma.user.create({
|
|
54
|
-
data,
|
|
55
|
-
})
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
That's it! You can now use Prisma in your application to interact with your database. You can find more information about Prisma and its features in the [Prisma documentation](https://www.prisma.io/docs/).
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { builder } from '@navios/builder'
|
|
2
|
-
|
|
3
|
-
import { z } from 'zod'
|
|
4
|
-
|
|
5
|
-
export const authApi = builder({
|
|
6
|
-
useDiscriminatorResponse: true,
|
|
7
|
-
})
|
|
8
|
-
|
|
9
|
-
export const userEndpoint = authApi.declareEndpoint({
|
|
10
|
-
method: 'GET',
|
|
11
|
-
url: '/user',
|
|
12
|
-
responseSchema: z.object({
|
|
13
|
-
id: z.string(),
|
|
14
|
-
name: z.string(),
|
|
15
|
-
email: z.string(),
|
|
16
|
-
}),
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
export const patchUserEndpoint = authApi.declareEndpoint({
|
|
20
|
-
method: 'PATCH',
|
|
21
|
-
url: '/user',
|
|
22
|
-
requestSchema: z.object({
|
|
23
|
-
name: z.string(),
|
|
24
|
-
email: z.string(),
|
|
25
|
-
}),
|
|
26
|
-
responseSchema: z.object({
|
|
27
|
-
id: z.string(),
|
|
28
|
-
name: z.string(),
|
|
29
|
-
email: z.string(),
|
|
30
|
-
}),
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
export const discriminatorEndpoint = authApi.declareEndpoint({
|
|
34
|
-
method: 'GET',
|
|
35
|
-
url: '/discriminator',
|
|
36
|
-
responseSchema: z.discriminatedUnion('success', [
|
|
37
|
-
z.object({
|
|
38
|
-
success: z.literal(true),
|
|
39
|
-
data: z.object({
|
|
40
|
-
id: z.string(),
|
|
41
|
-
name: z.string(),
|
|
42
|
-
|
|
43
|
-
email: z.string(),
|
|
44
|
-
}),
|
|
45
|
-
}),
|
|
46
|
-
z.object({
|
|
47
|
-
success: z.literal(false),
|
|
48
|
-
error: z.object({
|
|
49
|
-
code: z.string(),
|
|
50
|
-
message: z.string(),
|
|
51
|
-
}),
|
|
52
|
-
}),
|
|
53
|
-
]),
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
export const multipartEndpoint = authApi.declareMultipart({
|
|
57
|
-
method: 'POST',
|
|
58
|
-
url: '/multipart',
|
|
59
|
-
requestSchema: z.object({
|
|
60
|
-
files: z.array(z.instanceof(File)),
|
|
61
|
-
something: z.string(),
|
|
62
|
-
}),
|
|
63
|
-
responseSchema: z.object({}),
|
|
64
|
-
})
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { Path, PathValue } from '../../../src/index.mjs'
|
|
2
|
-
|
|
3
|
-
import { provideConfig } from '../../../src/index.mjs'
|
|
4
|
-
import { configureConfig } from './configuration.mjs'
|
|
5
|
-
|
|
6
|
-
export type ConfigType = ReturnType<typeof configureConfig>
|
|
7
|
-
export type ConfigTypePaths = Path<ConfigType>
|
|
8
|
-
export type ConfigMap = {
|
|
9
|
-
[K in ConfigTypePaths]: PathValue<ConfigType, K>
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const ConfigService = provideConfig<ConfigMap>({
|
|
13
|
-
load: configureConfig,
|
|
14
|
-
})
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { inject, NaviosFactory } from '../../src/index.mjs'
|
|
2
|
-
import { ConfigService } from './config/config.service.mjs'
|
|
3
|
-
import { AppModule } from './src/app.module.mjs'
|
|
4
|
-
|
|
5
|
-
export async function boot() {
|
|
6
|
-
const app = await NaviosFactory.create(AppModule)
|
|
7
|
-
app.enableCors({
|
|
8
|
-
methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'],
|
|
9
|
-
})
|
|
10
|
-
app.enableMultipart({})
|
|
11
|
-
await app.init()
|
|
12
|
-
const configService = await inject(ConfigService)
|
|
13
|
-
const port = configService.getOrThrow('port')
|
|
14
|
-
await app.listen({ port: port, host: '0.0.0.0' })
|
|
15
|
-
}
|
|
16
|
-
await boot()
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { CanActivate, ExecutionContext } from '../../../../src/index.mjs'
|
|
2
|
-
|
|
3
|
-
import { Injectable, Logger, syncInject } from '../../../../src/index.mjs'
|
|
4
|
-
|
|
5
|
-
@Injectable()
|
|
6
|
-
export class AclModernGuard implements CanActivate {
|
|
7
|
-
logger = syncInject(Logger, {
|
|
8
|
-
context: AclModernGuard.name,
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
canActivate(executionContext: ExecutionContext): Promise<boolean> | boolean {
|
|
12
|
-
this.logger.log('ACL Modern Guard activated')
|
|
13
|
-
return true
|
|
14
|
-
}
|
|
15
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { CanActivate, ExecutionContext } from '../../../../src/index.mjs'
|
|
2
|
-
|
|
3
|
-
import { Injectable, Logger, syncInject } from '../../../../src/index.mjs'
|
|
4
|
-
|
|
5
|
-
@Injectable()
|
|
6
|
-
export class AclGuard implements CanActivate {
|
|
7
|
-
logger = syncInject(Logger, {
|
|
8
|
-
context: AclGuard.name,
|
|
9
|
-
})
|
|
10
|
-
canActivate(executionContext: ExecutionContext): Promise<boolean> | boolean {
|
|
11
|
-
this.logger.log('ACL Guard activated')
|
|
12
|
-
return true
|
|
13
|
-
}
|
|
14
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { CanActivate, ExecutionContext } from '../../../../src/index.mjs'
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
AttributeFactory,
|
|
5
|
-
Injectable,
|
|
6
|
-
Logger,
|
|
7
|
-
syncInject,
|
|
8
|
-
} from '../../../../src/index.mjs'
|
|
9
|
-
import { Public } from './public.attribute.mjs'
|
|
10
|
-
|
|
11
|
-
@Injectable()
|
|
12
|
-
export class AppGuard implements CanActivate {
|
|
13
|
-
logger = syncInject(Logger, {
|
|
14
|
-
context: AppGuard.name,
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
canActivate(executionContext: ExecutionContext): Promise<boolean> | boolean {
|
|
18
|
-
const isPublic = AttributeFactory.getLast(Public, [
|
|
19
|
-
executionContext.getModule(),
|
|
20
|
-
executionContext.getController(),
|
|
21
|
-
executionContext.getHandler(),
|
|
22
|
-
])
|
|
23
|
-
this.logger.log('App Guard activated')
|
|
24
|
-
this.logger.log('isPublic', isPublic)
|
|
25
|
-
return true
|
|
26
|
-
}
|
|
27
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { CanActivate, ExecutionContext } from '../../../../src/index.mjs'
|
|
2
|
-
|
|
3
|
-
import { Injectable, Logger, syncInject } from '../../../../src/index.mjs'
|
|
4
|
-
|
|
5
|
-
@Injectable()
|
|
6
|
-
export class OneMoreGuard implements CanActivate {
|
|
7
|
-
logger = syncInject(Logger, {
|
|
8
|
-
context: OneMoreGuard.name,
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
canActivate(executionContext: ExecutionContext): Promise<boolean> | boolean {
|
|
12
|
-
this.logger.log('One More Guard activated')
|
|
13
|
-
return true
|
|
14
|
-
}
|
|
15
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod'
|
|
2
|
-
|
|
3
|
-
import { AttributeFactory } from '../../../../src/index.mjs'
|
|
4
|
-
|
|
5
|
-
export const PublicSymbol = Symbol.for('Public')
|
|
6
|
-
|
|
7
|
-
export const Public = AttributeFactory.createAttribute(PublicSymbol)
|
|
8
|
-
export const RolesSymbol = Symbol.for('Roles')
|
|
9
|
-
|
|
10
|
-
export const RolesSchema = z.object({
|
|
11
|
-
roles: z.array(
|
|
12
|
-
z.union([
|
|
13
|
-
z.literal('VIEWER'),
|
|
14
|
-
z.literal('USER'),
|
|
15
|
-
z.literal('ADMIN'),
|
|
16
|
-
z.literal('OWNER'),
|
|
17
|
-
]),
|
|
18
|
-
),
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
export const Roles = AttributeFactory.createAttribute(RolesSymbol, RolesSchema)
|