@navios/core 0.2.0 → 0.2.2

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 (35) hide show
  1. package/docs/README.md +6 -0
  2. package/docs/recipes/prisma.md +60 -0
  3. package/examples/simple-test/api/index.mts +64 -0
  4. package/examples/simple-test/config/config.service.mts +14 -0
  5. package/examples/simple-test/config/configuration.mts +7 -0
  6. package/examples/simple-test/index.mts +16 -0
  7. package/examples/simple-test/src/acl/acl-modern.guard.mts +15 -0
  8. package/examples/simple-test/src/acl/acl.guard.mts +14 -0
  9. package/examples/simple-test/src/acl/app.guard.mts +27 -0
  10. package/examples/simple-test/src/acl/one-more.guard.mts +15 -0
  11. package/examples/simple-test/src/acl/public.attribute.mts +21 -0
  12. package/examples/simple-test/src/app.module.mts +9 -0
  13. package/examples/simple-test/src/user/user.controller.mts +72 -0
  14. package/examples/simple-test/src/user/user.module.mts +14 -0
  15. package/examples/simple-test/src/user/user.service.mts +14 -0
  16. package/{dist → lib}/_tsup-dts-rollup.d.mts +75 -59
  17. package/{dist → lib}/_tsup-dts-rollup.d.ts +75 -59
  18. package/{dist → lib}/index.d.mts +13 -4
  19. package/{dist → lib}/index.d.ts +13 -4
  20. package/{dist → lib}/index.js +270 -490
  21. package/lib/index.js.map +1 -0
  22. package/{dist → lib}/index.mjs +140 -353
  23. package/lib/index.mjs.map +1 -0
  24. package/package.json +12 -13
  25. package/project.json +53 -0
  26. package/src/__tests__/config.service.spec.mts +41 -0
  27. package/src/config/config-service.interface.mts +1 -1
  28. package/src/config/config.provider.mts +23 -47
  29. package/src/config/config.service.mts +25 -8
  30. package/src/decorators/endpoint.decorator.mts +17 -15
  31. package/src/decorators/multipart.decorator.mts +17 -10
  32. package/src/decorators/stream.decorator.mts +17 -10
  33. package/tsconfig.json +16 -0
  34. package/tsup.config.mts +12 -0
  35. package/vitest.config.mts +9 -0
@@ -1,16 +1,33 @@
1
1
  import { NaviosException } from '@navios/common'
2
+ import { Injectable, InjectionToken, syncInject } from '@navios/di'
2
3
 
3
- import type { LoggerService } from '../logger/index.mjs'
4
- import type { ConfigService } from './config-service.interface.mjs'
4
+ import { z } from 'zod'
5
+
6
+ import type { ConfigServiceInterface as IConfigService } from './config-service.interface.mjs'
5
7
  import type { Path, PathValue } from './types.mjs'
6
8
 
7
- export class ConfigServiceInstance<Config = Record<string, unknown>>
8
- implements ConfigService<Config>
9
+ import { Logger } from '../logger/index.mjs'
10
+
11
+ export const ConfigServiceOptionsSchema = z.record(z.unknown())
12
+ export type ConfigServiceOptions = z.infer<typeof ConfigServiceOptionsSchema>
13
+
14
+ export const ConfigServiceToken = InjectionToken.create<
15
+ IConfigService,
16
+ typeof ConfigServiceOptionsSchema
17
+ >(Symbol.for('ConfigService'), ConfigServiceOptionsSchema)
18
+
19
+ @Injectable({
20
+ token: ConfigServiceToken,
21
+ })
22
+ export class ConfigService<
23
+ Config extends ConfigServiceOptions = Record<string, unknown>,
24
+ > implements IConfigService<Config>
9
25
  {
10
- constructor(
11
- private config: Config = {} as Config,
12
- private logger: LoggerService,
13
- ) {}
26
+ private readonly logger = syncInject(Logger, {
27
+ context: ConfigService.name,
28
+ })
29
+
30
+ constructor(private config: Config = {} as Config) {}
14
31
 
15
32
  getConfig(): Config {
16
33
  return this.config
@@ -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
- ? EndpointFunctionArgs<
22
- Url,
23
- QuerySchema,
24
- EndpointDeclaration['config']['requestSchema']
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
- ? EndpointFunctionArgs<
29
- Url,
30
- undefined,
31
- EndpointDeclaration['config']['requestSchema']
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 {
@@ -71,11 +78,6 @@ export function Endpoint<
71
78
  ) => Promise<z.input<ResponseSchema>>,
72
79
  context: ClassMethodDecoratorContext,
73
80
  ) => {
74
- if (typeof target !== 'function') {
75
- throw new Error(
76
- '[Navios] Endpoint decorator can only be used on functions.',
77
- )
78
- }
79
81
  if (context.kind !== 'method') {
80
82
  throw new Error(
81
83
  '[Navios] Endpoint decorator can only be used on methods.',
@@ -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
- ? EndpointFunctionArgs<
22
- Url,
23
- QuerySchema,
24
- EndpointDeclaration['config']['requestSchema']
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
- ? EndpointFunctionArgs<
29
- Url,
30
- undefined,
31
- EndpointDeclaration['config']['requestSchema']
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
- ? EndpointFunctionArgs<
21
- Url,
22
- QuerySchema,
23
- EndpointDeclaration['config']['requestSchema']
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
- ? EndpointFunctionArgs<
28
- Url,
29
- undefined,
30
- EndpointDeclaration['config']['requestSchema']
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,
package/tsconfig.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "module": "Node18",
5
+ "outDir": "dist"
6
+ },
7
+ "include": ["src/**/*"],
8
+ "references": [
9
+ {
10
+ "path": "../common"
11
+ },
12
+ {
13
+ "path": "../di"
14
+ }
15
+ ]
16
+ }
@@ -0,0 +1,12 @@
1
+ import { defineConfig } from 'tsup'
2
+
3
+ export default defineConfig({
4
+ entry: ['src/index.mts'],
5
+ outDir: 'lib',
6
+ format: ['esm', 'cjs'],
7
+ clean: true,
8
+ treeshake: 'smallest',
9
+ sourcemap: true,
10
+ platform: 'node',
11
+ experimentalDts: true,
12
+ })
@@ -0,0 +1,9 @@
1
+ import { defineProject } from 'vitest/config'
2
+
3
+ export default defineProject({
4
+ test: {
5
+ typecheck: {
6
+ enabled: true,
7
+ },
8
+ },
9
+ })