@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.
Files changed (96) hide show
  1. package/README.md +96 -3
  2. package/docs/README.md +310 -3
  3. package/docs/adapters.md +308 -0
  4. package/docs/application-setup.md +524 -0
  5. package/docs/attributes.md +689 -0
  6. package/docs/controllers.md +373 -0
  7. package/docs/endpoints.md +444 -0
  8. package/docs/exceptions.md +316 -0
  9. package/docs/guards.md +550 -0
  10. package/docs/modules.md +251 -0
  11. package/docs/quick-start.md +295 -0
  12. package/docs/services.md +428 -0
  13. package/docs/testing.md +704 -0
  14. package/lib/_tsup-dts-rollup.d.mts +313 -280
  15. package/lib/_tsup-dts-rollup.d.ts +313 -280
  16. package/lib/index.d.mts +47 -26
  17. package/lib/index.d.ts +47 -26
  18. package/lib/index.js +633 -1068
  19. package/lib/index.js.map +1 -1
  20. package/lib/index.mjs +632 -1061
  21. package/lib/index.mjs.map +1 -1
  22. package/package.json +11 -12
  23. package/project.json +17 -4
  24. package/src/__tests__/config.service.spec.mts +11 -9
  25. package/src/__tests__/controller.spec.mts +1 -2
  26. package/src/attribute.factory.mts +1 -1
  27. package/src/config/config.provider.mts +2 -2
  28. package/src/config/config.service.mts +4 -4
  29. package/src/decorators/controller.decorator.mts +1 -1
  30. package/src/decorators/endpoint.decorator.mts +9 -10
  31. package/src/decorators/header.decorator.mts +1 -1
  32. package/src/decorators/multipart.decorator.mts +5 -5
  33. package/src/decorators/stream.decorator.mts +5 -6
  34. package/src/factories/endpoint-adapter.factory.mts +21 -0
  35. package/src/factories/http-adapter.factory.mts +20 -0
  36. package/src/factories/index.mts +6 -0
  37. package/src/factories/multipart-adapter.factory.mts +21 -0
  38. package/src/factories/reply.factory.mts +21 -0
  39. package/src/factories/request.factory.mts +21 -0
  40. package/src/factories/stream-adapter.factory.mts +20 -0
  41. package/src/index.mts +1 -1
  42. package/src/interfaces/abstract-execution-context.inteface.mts +13 -0
  43. package/src/interfaces/abstract-http-adapter.interface.mts +20 -0
  44. package/src/interfaces/abstract-http-cors-options.interface.mts +59 -0
  45. package/src/interfaces/abstract-http-handler-adapter.interface.mts +13 -0
  46. package/src/interfaces/abstract-http-listen-options.interface.mts +4 -0
  47. package/src/interfaces/can-activate.mts +4 -2
  48. package/src/interfaces/http-header.mts +18 -0
  49. package/src/interfaces/index.mts +6 -0
  50. package/src/logger/console-logger.service.mts +28 -44
  51. package/src/logger/index.mts +1 -2
  52. package/src/logger/logger.service.mts +9 -128
  53. package/src/logger/logger.tokens.mts +21 -0
  54. package/src/metadata/handler.metadata.mts +7 -5
  55. package/src/navios.application.mts +65 -172
  56. package/src/navios.environment.mts +30 -0
  57. package/src/navios.factory.mts +53 -12
  58. package/src/services/guard-runner.service.mts +19 -9
  59. package/src/services/index.mts +0 -2
  60. package/src/services/module-loader.service.mts +4 -3
  61. package/src/tokens/endpoint-adapter.token.mts +8 -0
  62. package/src/tokens/execution-context.token.mts +2 -2
  63. package/src/tokens/http-adapter.token.mts +8 -0
  64. package/src/tokens/index.mts +4 -1
  65. package/src/tokens/multipart-adapter.token.mts +8 -0
  66. package/src/tokens/reply.token.mts +1 -5
  67. package/src/tokens/request.token.mts +1 -7
  68. package/src/tokens/stream-adapter.token.mts +8 -0
  69. package/tsconfig.json +6 -1
  70. package/tsconfig.lib.json +8 -0
  71. package/tsconfig.spec.json +12 -0
  72. package/tsup.config.mts +1 -0
  73. package/docs/recipes/prisma.md +0 -60
  74. package/examples/simple-test/api/index.mts +0 -64
  75. package/examples/simple-test/config/config.service.mts +0 -14
  76. package/examples/simple-test/config/configuration.mts +0 -7
  77. package/examples/simple-test/index.mts +0 -16
  78. package/examples/simple-test/src/acl/acl-modern.guard.mts +0 -15
  79. package/examples/simple-test/src/acl/acl.guard.mts +0 -14
  80. package/examples/simple-test/src/acl/app.guard.mts +0 -27
  81. package/examples/simple-test/src/acl/one-more.guard.mts +0 -15
  82. package/examples/simple-test/src/acl/public.attribute.mts +0 -21
  83. package/examples/simple-test/src/app.module.mts +0 -9
  84. package/examples/simple-test/src/user/user.controller.mts +0 -72
  85. package/examples/simple-test/src/user/user.module.mts +0 -14
  86. package/examples/simple-test/src/user/user.service.mts +0 -14
  87. package/src/adapters/endpoint-adapter.service.mts +0 -72
  88. package/src/adapters/handler-adapter.interface.mts +0 -21
  89. package/src/adapters/index.mts +0 -4
  90. package/src/adapters/multipart-adapter.service.mts +0 -131
  91. package/src/adapters/stream-adapter.service.mts +0 -91
  92. package/src/logger/logger.factory.mts +0 -36
  93. package/src/logger/pino-wrapper.mts +0 -64
  94. package/src/services/controller-adapter.service.mts +0 -124
  95. package/src/services/execution-context.mts +0 -54
  96. package/src/tokens/application.token.mts +0 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@navios/core",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "author": {
5
5
  "name": "Oleksandr Hanzha",
6
6
  "email": "alex@granted.name"
@@ -12,8 +12,8 @@
12
12
  },
13
13
  "license": "MIT",
14
14
  "peerDependencies": {
15
- "@navios/builder": "^0.2.0",
16
- "zod": "^3.23.8"
15
+ "@navios/builder": "^0.3.0",
16
+ "zod": "^3.25.0 || ^4.0.0"
17
17
  },
18
18
  "typings": "./lib/index.d.mts",
19
19
  "main": "./lib/index.js",
@@ -31,16 +31,15 @@
31
31
  }
32
32
  },
33
33
  "devDependencies": {
34
- "@navios/builder": "^0.2.0",
35
- "tsx": "^4.19.4",
36
- "typescript": "^5.8.3",
37
- "zod": "^3.24.4"
34
+ "@navios/builder": "^0.3.0",
35
+ "@types/bun": "^1.2.22",
36
+ "@types/supertest": "^6.0.3",
37
+ "supertest": "^7.1.4",
38
+ "tsx": "^4.20.5",
39
+ "typescript": "^5.9.2",
40
+ "zod": "^4.1.8"
38
41
  },
39
42
  "dependencies": {
40
- "@fastify/cors": "^11.0.1",
41
- "@fastify/multipart": "^9.0.3",
42
- "@navios/di": "^0.1.12",
43
- "fastify": "^5.3.2",
44
- "fastify-type-provider-zod": "^4.0.2"
43
+ "@navios/di": "^0.4.0"
45
44
  }
46
45
  }
package/project.json CHANGED
@@ -9,15 +9,28 @@
9
9
  "check": {
10
10
  "executor": "nx:run-commands",
11
11
  "outputs": ["{projectRoot}/dist"],
12
- "inputs": ["^projectSources", "projectSources"],
12
+ "inputs": [
13
+ "^projectSources",
14
+ "projectSources",
15
+ "{projectRoot}/tsconfig.json",
16
+ "{projectRoot}/tsconfig.lib.json"
17
+ ],
13
18
  "options": {
14
19
  "command": ["tsc -b"],
15
20
  "cwd": "packages/core"
16
21
  }
17
22
  },
23
+ "lint": {
24
+ "executor": "nx:run-commands",
25
+ "inputs": ["^projectSources", "project"],
26
+ "options": {
27
+ "command": "oxlint --fix",
28
+ "cwd": "packages/core"
29
+ }
30
+ },
18
31
  "test:ci": {
19
32
  "executor": "nx:run-commands",
20
- "inputs": ["^projectSources","project"],
33
+ "inputs": ["^projectSources", "project"],
21
34
  "options": {
22
35
  "command": "vitest run",
23
36
  "cwd": "packages/core"
@@ -25,9 +38,9 @@
25
38
  },
26
39
  "build": {
27
40
  "executor": "nx:run-commands",
28
- "inputs": ["projectSources"],
41
+ "inputs": ["projectSources", "{projectRoot}/tsup.config.mts"],
29
42
  "outputs": ["{projectRoot}/lib"],
30
- "dependsOn": ["check", "test:ci"],
43
+ "dependsOn": ["check", "test:ci", "lint"],
31
44
  "options": {
32
45
  "command": "tsup",
33
46
  "cwd": "packages/core"
@@ -1,27 +1,29 @@
1
1
  import { env } from 'node:process'
2
2
 
3
- import { describe, expect, it } from 'vitest'
3
+ import { beforeEach, describe, expect, it } from 'vitest'
4
4
 
5
5
  import {
6
- ConfigService,
7
6
  ConfigServiceToken,
7
+ Container,
8
8
  EnvConfigProvider,
9
- getGlobalServiceLocator,
10
9
  inject,
11
10
  Injectable,
12
11
  Logger,
13
- syncInject,
14
12
  } from '../index.mjs'
15
13
 
16
14
  describe('ConfigService', () => {
15
+ let container: Container
16
+ beforeEach(() => {
17
+ container = new Container()
18
+ })
17
19
  it('should be able to get a config value', async () => {
18
- const service = await inject(ConfigServiceToken, env)
20
+ const service = await container.get(ConfigServiceToken, { ...env })
19
21
  expect(service).toBeDefined()
20
22
  expect(service.get('NODE_ENV')).toBe(env.NODE_ENV)
21
23
  })
22
24
 
23
25
  it('should be possible to use bound config service', async () => {
24
- const service = await inject(EnvConfigProvider)
26
+ const service = await container.get(EnvConfigProvider)
25
27
  expect(service).toBeDefined()
26
28
  expect(service.get('NODE_ENV')).toBe(env.NODE_ENV)
27
29
  })
@@ -29,11 +31,11 @@ describe('ConfigService', () => {
29
31
  it('should be possible to use inside service as a syncInject', async () => {
30
32
  @Injectable()
31
33
  class TestService {
32
- public readonly configService = syncInject(EnvConfigProvider)
33
- public readonly logger = syncInject(Logger)
34
+ public readonly configService = inject(EnvConfigProvider)
35
+ public readonly logger = inject(Logger)
34
36
  }
35
37
 
36
- const service = await inject(TestService)
38
+ const service = await container.get(TestService)
37
39
 
38
40
  expect(service.configService).toBeDefined()
39
41
  expect(service.configService.get('NODE_ENV')).toBe(env.NODE_ENV)
@@ -1,7 +1,7 @@
1
1
  import { builder } from '@navios/builder'
2
2
 
3
3
  import { describe, expect, it } from 'vitest'
4
- import { z } from 'zod'
4
+ import { z } from 'zod/v4'
5
5
 
6
6
  import type { EndpointParams } from '../decorators/index.mjs'
7
7
 
@@ -51,7 +51,6 @@ describe('Controller decorator', () => {
51
51
  }
52
52
 
53
53
  const metadata = extractControllerMetadata(Test)
54
- console.log(metadata)
55
54
  expect(metadata).toBeDefined()
56
55
  expect(metadata.endpoints).toBeInstanceOf(Set)
57
56
  expect(metadata.endpoints.size).toBe(2)
@@ -1,5 +1,5 @@
1
1
  import type { ClassType } from '@navios/di'
2
- import type { z, ZodType } from 'zod'
2
+ import type { z, ZodType } from 'zod/v4'
3
3
 
4
4
  import type {
5
5
  ControllerMetadata,
@@ -2,7 +2,7 @@ import { env } from 'node:process'
2
2
 
3
3
  import { FactoryInjectionToken, InjectionToken } from '@navios/di'
4
4
 
5
- import { z } from 'zod'
5
+ import { z } from 'zod/v4'
6
6
 
7
7
  import type { ConfigServiceOptions } from './config.service.mjs'
8
8
 
@@ -13,7 +13,7 @@ import {
13
13
  } from './config.service.mjs'
14
14
 
15
15
  export const ConfigProviderOptions = z.object({
16
- load: z.function().returns(ConfigServiceOptionsSchema),
16
+ load: z.function({ output: ConfigServiceOptionsSchema }),
17
17
  })
18
18
 
19
19
  export function provideConfig<ConfigMap extends ConfigServiceOptions>(
@@ -1,14 +1,14 @@
1
1
  import { NaviosException } from '@navios/builder'
2
- import { Injectable, InjectionToken, syncInject } from '@navios/di'
2
+ import { inject, Injectable, InjectionToken } from '@navios/di'
3
3
 
4
- import { z } from 'zod'
4
+ import { z } from 'zod/v4'
5
5
 
6
6
  import type { ConfigServiceInterface as IConfigService } from './config-service.interface.mjs'
7
7
  import type { Path, PathValue } from './types.mjs'
8
8
 
9
9
  import { Logger } from '../logger/index.mjs'
10
10
 
11
- export const ConfigServiceOptionsSchema = z.record(z.unknown())
11
+ export const ConfigServiceOptionsSchema = z.record(z.string(), z.unknown())
12
12
  export type ConfigServiceOptions = z.infer<typeof ConfigServiceOptionsSchema>
13
13
 
14
14
  export const ConfigServiceToken = InjectionToken.create<
@@ -23,7 +23,7 @@ export class ConfigService<
23
23
  Config extends ConfigServiceOptions = Record<string, unknown>,
24
24
  > implements IConfigService<Config>
25
25
  {
26
- private readonly logger = syncInject(Logger, {
26
+ private readonly logger = inject(Logger, {
27
27
  context: ConfigService.name,
28
28
  })
29
29
 
@@ -25,7 +25,7 @@ export function Controller({ guards }: ControllerOptions = {}) {
25
25
  }
26
26
  return Injectable({
27
27
  token,
28
- scope: InjectableScope.Instance,
28
+ scope: InjectableScope.Request,
29
29
  })(target, context)
30
30
  }
31
31
  }
@@ -4,12 +4,12 @@ import type {
4
4
  HttpMethod,
5
5
  Util_FlatObject,
6
6
  } from '@navios/builder'
7
- import type { AnyZodObject, z, ZodType } from 'zod'
7
+ import type { z, ZodType } from 'zod/v4'
8
8
 
9
- import { ZodDiscriminatedUnion } from 'zod'
9
+ import { ZodDiscriminatedUnion } from 'zod/v4'
10
10
 
11
- import { EndpointAdapterToken } from '../adapters/index.mjs'
12
11
  import { getEndpointMetadata } from '../metadata/index.mjs'
12
+ import { EndpointAdapterToken } from '../tokens/index.mjs'
13
13
 
14
14
  export type EndpointParams<
15
15
  EndpointDeclaration extends {
@@ -17,7 +17,7 @@ export type EndpointParams<
17
17
  },
18
18
  Url extends string = EndpointDeclaration['config']['url'],
19
19
  QuerySchema = EndpointDeclaration['config']['querySchema'],
20
- > = QuerySchema extends AnyZodObject
20
+ > = QuerySchema extends ZodType
21
21
  ? EndpointDeclaration['config']['requestSchema'] extends ZodType
22
22
  ? Util_FlatObject<
23
23
  EndpointFunctionArgs<
@@ -45,7 +45,6 @@ export type EndpointResult<
45
45
  },
46
46
  > =
47
47
  EndpointDeclaration['config']['responseSchema'] extends ZodDiscriminatedUnion<
48
- any,
49
48
  infer Options
50
49
  >
51
50
  ? Promise<z.input<Options[number]>>
@@ -68,13 +67,13 @@ export function Endpoint<
68
67
  }) {
69
68
  return (
70
69
  target: (
71
- params: QuerySchema extends AnyZodObject
70
+ params: QuerySchema extends ZodType
72
71
  ? RequestSchema extends ZodType
73
- ? EndpointFunctionArgs<Url, QuerySchema, RequestSchema>
74
- : EndpointFunctionArgs<Url, QuerySchema, undefined>
72
+ ? EndpointFunctionArgs<Url, QuerySchema, RequestSchema, true>
73
+ : EndpointFunctionArgs<Url, QuerySchema, undefined, true>
75
74
  : RequestSchema extends ZodType
76
- ? EndpointFunctionArgs<Url, undefined, RequestSchema>
77
- : EndpointFunctionArgs<Url, undefined, undefined>,
75
+ ? EndpointFunctionArgs<Url, undefined, RequestSchema, true>
76
+ : EndpointFunctionArgs<Url, undefined, undefined, true>,
78
77
  ) => Promise<z.input<ResponseSchema>>,
79
78
  context: ClassMethodDecoratorContext,
80
79
  ) => {
@@ -1,4 +1,4 @@
1
- import type { HttpHeader } from 'fastify/types/utils.js'
1
+ import type { HttpHeader } from '../interfaces/index.mjs'
2
2
 
3
3
  import { getEndpointMetadata } from '../metadata/index.mjs'
4
4
 
@@ -4,12 +4,12 @@ import type {
4
4
  HttpMethod,
5
5
  Util_FlatObject,
6
6
  } from '@navios/builder'
7
- import type { AnyZodObject, z, ZodType } from 'zod'
7
+ import type { z, ZodObject, ZodType } from 'zod/v4'
8
8
 
9
- import { ZodDiscriminatedUnion } from 'zod'
9
+ import { ZodDiscriminatedUnion } from 'zod/v4'
10
10
 
11
- import { MultipartAdapterToken } from '../adapters/index.mjs'
12
11
  import { getEndpointMetadata } from '../metadata/index.mjs'
12
+ import { MultipartAdapterToken } from '../tokens/index.mjs'
13
13
 
14
14
  export type MultipartParams<
15
15
  EndpointDeclaration extends {
@@ -17,7 +17,7 @@ export type MultipartParams<
17
17
  },
18
18
  Url extends string = EndpointDeclaration['config']['url'],
19
19
  QuerySchema = EndpointDeclaration['config']['querySchema'],
20
- > = QuerySchema extends AnyZodObject
20
+ > = QuerySchema extends ZodObject
21
21
  ? EndpointDeclaration['config']['requestSchema'] extends ZodType
22
22
  ? Util_FlatObject<
23
23
  EndpointFunctionArgs<
@@ -68,7 +68,7 @@ export function Multipart<
68
68
  }) {
69
69
  return (
70
70
  target: (
71
- params: QuerySchema extends AnyZodObject
71
+ params: QuerySchema extends ZodObject
72
72
  ? RequestSchema extends ZodType
73
73
  ? EndpointFunctionArgs<Url, QuerySchema, RequestSchema>
74
74
  : EndpointFunctionArgs<Url, QuerySchema, undefined>
@@ -4,11 +4,10 @@ import type {
4
4
  HttpMethod,
5
5
  Util_FlatObject,
6
6
  } from '@navios/builder'
7
- import type { FastifyReply } from 'fastify'
8
- import type { AnyZodObject, ZodType } from 'zod'
7
+ import type { ZodObject, ZodType } from 'zod/v4'
9
8
 
10
- import { StreamAdapterToken } from '../adapters/index.mjs'
11
9
  import { getEndpointMetadata } from '../metadata/index.mjs'
10
+ import { StreamAdapterToken } from '../tokens/index.mjs'
12
11
 
13
12
  export type StreamParams<
14
13
  EndpointDeclaration extends {
@@ -16,7 +15,7 @@ export type StreamParams<
16
15
  },
17
16
  Url extends string = EndpointDeclaration['config']['url'],
18
17
  QuerySchema = EndpointDeclaration['config']['querySchema'],
19
- > = QuerySchema extends AnyZodObject
18
+ > = QuerySchema extends ZodObject
20
19
  ? EndpointDeclaration['config']['requestSchema'] extends ZodType
21
20
  ? Util_FlatObject<
22
21
  EndpointFunctionArgs<
@@ -48,14 +47,14 @@ export function Stream<
48
47
  }) {
49
48
  return (
50
49
  target: (
51
- params: QuerySchema extends AnyZodObject
50
+ params: QuerySchema extends ZodObject
52
51
  ? RequestSchema extends ZodType
53
52
  ? EndpointFunctionArgs<Url, QuerySchema, RequestSchema>
54
53
  : EndpointFunctionArgs<Url, QuerySchema, undefined>
55
54
  : RequestSchema extends ZodType
56
55
  ? EndpointFunctionArgs<Url, undefined, RequestSchema>
57
56
  : EndpointFunctionArgs<Url, undefined, undefined>,
58
- reply: FastifyReply,
57
+ reply: any,
59
58
  ) => Promise<void>,
60
59
  context: ClassMethodDecoratorContext,
61
60
  ) => {
@@ -0,0 +1,21 @@
1
+ import type { FactoryContext, InjectionToken } from '@navios/di'
2
+
3
+ import { Factory, inject } from '@navios/di'
4
+
5
+ import { NaviosEnvironment } from '../navios.environment.mjs'
6
+ import { EndpointAdapterToken } from '../tokens/index.mjs'
7
+
8
+ @Factory({
9
+ token: EndpointAdapterToken,
10
+ })
11
+ export class EndpointAdapterFactory {
12
+ private readonly environment = inject(NaviosEnvironment)
13
+
14
+ create(ctx: FactoryContext) {
15
+ const service = this.environment.getHttpToken(EndpointAdapterToken)
16
+ if (!service) {
17
+ throw new Error('EndpointAdapterToken service not found in environment')
18
+ }
19
+ return ctx.inject(service as InjectionToken<any, undefined>)
20
+ }
21
+ }
@@ -0,0 +1,20 @@
1
+ import type { FactoryContext } from '@navios/di'
2
+
3
+ import { Factory, inject, InjectionToken } from '@navios/di'
4
+
5
+ import { NaviosEnvironment } from '../navios.environment.mjs'
6
+ import { HttpAdapterToken } from '../tokens/index.mjs'
7
+
8
+ @Factory({
9
+ token: HttpAdapterToken,
10
+ })
11
+ export class HttpAdapterFactory {
12
+ private readonly environment = inject(NaviosEnvironment)
13
+ create(ctx: FactoryContext) {
14
+ const service = this.environment.getHttpToken(HttpAdapterToken)
15
+ if (!service) {
16
+ throw new Error('HttpAdapterToken service not found in environment')
17
+ }
18
+ return ctx.inject(service as InjectionToken<any, undefined>)
19
+ }
20
+ }
@@ -0,0 +1,6 @@
1
+ export * from './endpoint-adapter.factory.mjs'
2
+ export * from './http-adapter.factory.mjs'
3
+ export * from './multipart-adapter.factory.mjs'
4
+ export * from './request.factory.mjs'
5
+ export * from './reply.factory.mjs'
6
+ export * from './stream-adapter.factory.mjs'
@@ -0,0 +1,21 @@
1
+ import type { FactoryContext, InjectionToken } from '@navios/di'
2
+
3
+ import { Factory, inject } from '@navios/di'
4
+
5
+ import { NaviosEnvironment } from '../navios.environment.mjs'
6
+ import { MultipartAdapterToken } from '../tokens/index.mjs'
7
+
8
+ @Factory({
9
+ token: MultipartAdapterToken,
10
+ })
11
+ export class MultipartAdapterFactory {
12
+ private readonly environment = inject(NaviosEnvironment)
13
+
14
+ create(ctx: FactoryContext) {
15
+ const service = this.environment.getHttpToken(MultipartAdapterToken)
16
+ if (!service) {
17
+ throw new Error('MultipartAdapterToken service not found in environment')
18
+ }
19
+ return ctx.inject(service as InjectionToken<any, undefined>)
20
+ }
21
+ }
@@ -0,0 +1,21 @@
1
+ import type { FactoryContext, InjectionToken } from '@navios/di'
2
+
3
+ import { Factory, inject, InjectableScope } from '@navios/di'
4
+
5
+ import { NaviosEnvironment } from '../navios.environment.mjs'
6
+ import { Reply } from '../tokens/index.mjs'
7
+
8
+ @Factory({
9
+ token: Reply,
10
+ scope: InjectableScope.Request,
11
+ })
12
+ export class ReplyFactory {
13
+ private readonly environment = inject(NaviosEnvironment)
14
+ create(ctx: FactoryContext) {
15
+ const service = this.environment.getHttpToken(Reply)
16
+ if (!service) {
17
+ throw new Error('ReplyToken service not found in environment')
18
+ }
19
+ return ctx.inject(service as InjectionToken<any, undefined>)
20
+ }
21
+ }
@@ -0,0 +1,21 @@
1
+ import type { FactoryContext, InjectionToken } from '@navios/di'
2
+
3
+ import { Factory, inject, InjectableScope } from '@navios/di'
4
+
5
+ import { NaviosEnvironment } from '../navios.environment.mjs'
6
+ import { Request } from '../tokens/index.mjs'
7
+
8
+ @Factory({
9
+ token: Request,
10
+ scope: InjectableScope.Request,
11
+ })
12
+ export class RequestFactory {
13
+ private readonly environment = inject(NaviosEnvironment)
14
+ create(ctx: FactoryContext) {
15
+ const service = this.environment.getHttpToken(Request)
16
+ if (!service) {
17
+ throw new Error('RequestToken service not found in environment')
18
+ }
19
+ return ctx.inject(service as InjectionToken<any, undefined>)
20
+ }
21
+ }
@@ -0,0 +1,20 @@
1
+ import type { FactoryContext, InjectionToken } from '@navios/di'
2
+
3
+ import { Factory, inject } from '@navios/di'
4
+
5
+ import { NaviosEnvironment } from '../navios.environment.mjs'
6
+ import { StreamAdapterToken } from '../tokens/index.mjs'
7
+
8
+ @Factory({
9
+ token: StreamAdapterToken,
10
+ })
11
+ export class StreamAdapterFactory {
12
+ private readonly environment = inject(NaviosEnvironment)
13
+ create(ctx: FactoryContext) {
14
+ const service = this.environment.getHttpToken(StreamAdapterToken)
15
+ if (!service) {
16
+ throw new Error('StreamAdapterToken service not found in environment')
17
+ }
18
+ return ctx.inject(service as InjectionToken<any, undefined>)
19
+ }
20
+ }
package/src/index.mts CHANGED
@@ -1,5 +1,4 @@
1
1
  export * from '@navios/di'
2
- export * from './adapters/index.mjs'
3
2
  export * from './config/index.mjs'
4
3
  export * from './decorators/index.mjs'
5
4
  export * from './exceptions/index.mjs'
@@ -9,5 +8,6 @@ export * from './metadata/index.mjs'
9
8
  export * from './services/index.mjs'
10
9
  export * from './tokens/index.mjs'
11
10
  export * from './attribute.factory.mjs'
11
+ export * from './factories/index.mjs'
12
12
  export * from './navios.application.mjs'
13
13
  export * from './navios.factory.mjs'
@@ -0,0 +1,13 @@
1
+ import type {
2
+ ControllerMetadata,
3
+ HandlerMetadata,
4
+ ModuleMetadata,
5
+ } from '../metadata/index.mjs'
6
+
7
+ export interface AbstractExecutionContext {
8
+ getModule(): ModuleMetadata
9
+ getController(): ControllerMetadata
10
+ getHandler(): HandlerMetadata
11
+ getRequest(): any
12
+ getReply(): any
13
+ }
@@ -0,0 +1,20 @@
1
+ import type { ModuleMetadata } from '../metadata/index.mjs'
2
+ import type { AbstractHttpCorsOptions } from './abstract-http-cors-options.interface.mjs'
3
+ import type { AbstractHttpListenOptions } from './abstract-http-listen-options.interface.mjs'
4
+
5
+ export interface AbstractHttpAdapterInterface<
6
+ ServerInstance,
7
+ CorsOptions = AbstractHttpCorsOptions,
8
+ Options = {},
9
+ MultipartOptions = {},
10
+ > {
11
+ setupHttpServer(options: Options): Promise<void>
12
+ onModulesInit(modules: Map<string, ModuleMetadata>): Promise<void>
13
+ ready(): Promise<void>
14
+ getServer(): ServerInstance
15
+ setGlobalPrefix(prefix: string): void
16
+ enableCors(options: CorsOptions): void
17
+ enableMultipart(options: MultipartOptions): void
18
+ listen(options: AbstractHttpListenOptions): Promise<string>
19
+ dispose(): Promise<void>
20
+ }
@@ -0,0 +1,59 @@
1
+ import type { LogLevel } from '../logger/index.mjs'
2
+
3
+ interface ArrayOfValueOrArray<T> extends Array<ValueOrArray<T>> {}
4
+
5
+ type OriginType = string | boolean | RegExp
6
+ type ValueOrArray<T> = T | ArrayOfValueOrArray<T>
7
+
8
+ export interface AbstractHttpCorsOptions {
9
+ /**
10
+ * Configures the Access-Control-Allow-Origin CORS header.
11
+ */
12
+ origin?: ValueOrArray<OriginType>
13
+ /**
14
+ * Configures the Access-Control-Allow-Credentials CORS header.
15
+ * Set to true to pass the header, otherwise it is omitted.
16
+ */
17
+ credentials?: boolean
18
+ /**
19
+ * Configures the Access-Control-Expose-Headers CORS header.
20
+ * Expects a comma-delimited string (ex: 'Content-Range,X-Content-Range')
21
+ * or an array (ex: ['Content-Range', 'X-Content-Range']).
22
+ * If not specified, no custom headers are exposed.
23
+ */
24
+ exposedHeaders?: string | string[]
25
+ /**
26
+ * Configures the Access-Control-Allow-Headers CORS header.
27
+ * Expects a comma-delimited string (ex: 'Content-Type,Authorization')
28
+ * or an array (ex: ['Content-Type', 'Authorization']). If not
29
+ * specified, defaults to reflecting the headers specified in the
30
+ * request's Access-Control-Request-Headers header.
31
+ */
32
+ allowedHeaders?: string | string[]
33
+ /**
34
+ * Configures the Access-Control-Allow-Methods CORS header.
35
+ * Expects a comma-delimited string (ex: 'GET,PUT,POST') or an array (ex: ['GET', 'PUT', 'POST']).
36
+ */
37
+ methods?: string | string[]
38
+ /**
39
+ * Configures the Access-Control-Max-Age CORS header.
40
+ * Set to an integer to pass the header, otherwise it is omitted.
41
+ */
42
+ maxAge?: number
43
+ /**
44
+ * Configures the Cache-Control header for CORS preflight responses.
45
+ * Set to an integer to pass the header as `Cache-Control: max-age=${cacheControl}`,
46
+ * or set to a string to pass the header as `Cache-Control: ${cacheControl}` (fully define
47
+ * the header value), otherwise the header is omitted.
48
+ */
49
+ cacheControl?: number | string
50
+
51
+ /**
52
+ * Sets the Fastify log level specifically for the internal OPTIONS route
53
+ * used to handle CORS preflight requests. For example, setting this to `'silent'`
54
+ * will prevent these requests from being logged.
55
+ * Useful for reducing noise in application logs.
56
+ * Default: inherits Fastify's global log level.
57
+ */
58
+ logLevel?: LogLevel
59
+ }
@@ -0,0 +1,13 @@
1
+ import type { ClassType, RequestContextHolder } from '@navios/di'
2
+
3
+ import type { HandlerMetadata } from '../metadata/index.mjs'
4
+
5
+ export interface AbstractHttpHandlerAdapterInterface {
6
+ prepareArguments?: (
7
+ handlerMetadata: HandlerMetadata<any>,
8
+ ) => ((target: Record<string, any>, request: any) => Promise<void> | void)[]
9
+ provideHandler: (
10
+ controller: ClassType,
11
+ handlerMetadata: HandlerMetadata<any>,
12
+ ) => (context: RequestContextHolder, request: any, reply: any) => Promise<any>
13
+ }
@@ -0,0 +1,4 @@
1
+ export interface AbstractHttpListenOptions {
2
+ port: number
3
+ host?: string
4
+ }
@@ -1,5 +1,7 @@
1
- import type { ExecutionContext } from '../services/index.mjs'
1
+ import type { AbstractExecutionContext } from '../interfaces/index.mjs'
2
2
 
3
3
  export interface CanActivate {
4
- canActivate(executionContext: ExecutionContext): Promise<boolean> | boolean
4
+ canActivate(
5
+ executionContext: AbstractExecutionContext,
6
+ ): Promise<boolean> | boolean
5
7
  }
@@ -0,0 +1,18 @@
1
+ import type { OutgoingHttpHeaders } from 'http'
2
+
3
+ export type OmitIndexSignature<T> = {
4
+ [K in keyof T as string extends K
5
+ ? never
6
+ : number extends K
7
+ ? never
8
+ : K]: T[K]
9
+ }
10
+
11
+ /**
12
+ * HTTP header strings
13
+ * Use this type only for input values, not for output values.
14
+ */
15
+
16
+ export type HttpHeader =
17
+ | keyof OmitIndexSignature<OutgoingHttpHeaders>
18
+ | (string & Record<never, never>)