@navios/core 0.2.1 → 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 (33) 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 +71 -50
  17. package/{dist → lib}/_tsup-dts-rollup.d.ts +71 -50
  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 +10 -11
  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 +22 -50
  29. package/src/config/config.service.mts +25 -8
  30. package/src/decorators/endpoint.decorator.mts +0 -5
  31. package/tsconfig.json +16 -0
  32. package/tsup.config.mts +12 -0
  33. 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
@@ -78,11 +78,6 @@ export function Endpoint<
78
78
  ) => Promise<z.input<ResponseSchema>>,
79
79
  context: ClassMethodDecoratorContext,
80
80
  ) => {
81
- if (typeof target !== 'function') {
82
- throw new Error(
83
- '[Navios] Endpoint decorator can only be used on functions.',
84
- )
85
- }
86
81
  if (context.kind !== 'method') {
87
82
  throw new Error(
88
83
  '[Navios] Endpoint decorator can only be used on methods.',
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
+ })