@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.
- package/docs/README.md +6 -0
- package/docs/recipes/prisma.md +60 -0
- package/examples/simple-test/api/index.mts +64 -0
- package/examples/simple-test/config/config.service.mts +14 -0
- package/examples/simple-test/config/configuration.mts +7 -0
- package/examples/simple-test/index.mts +16 -0
- package/examples/simple-test/src/acl/acl-modern.guard.mts +15 -0
- package/examples/simple-test/src/acl/acl.guard.mts +14 -0
- package/examples/simple-test/src/acl/app.guard.mts +27 -0
- package/examples/simple-test/src/acl/one-more.guard.mts +15 -0
- package/examples/simple-test/src/acl/public.attribute.mts +21 -0
- package/examples/simple-test/src/app.module.mts +9 -0
- package/examples/simple-test/src/user/user.controller.mts +72 -0
- package/examples/simple-test/src/user/user.module.mts +14 -0
- package/examples/simple-test/src/user/user.service.mts +14 -0
- package/{dist → lib}/_tsup-dts-rollup.d.mts +75 -59
- package/{dist → lib}/_tsup-dts-rollup.d.ts +75 -59
- package/{dist → lib}/index.d.mts +13 -4
- package/{dist → lib}/index.d.ts +13 -4
- package/{dist → lib}/index.js +270 -490
- package/lib/index.js.map +1 -0
- package/{dist → lib}/index.mjs +140 -353
- package/lib/index.mjs.map +1 -0
- package/package.json +12 -13
- package/project.json +53 -0
- package/src/__tests__/config.service.spec.mts +41 -0
- package/src/config/config-service.interface.mts +1 -1
- package/src/config/config.provider.mts +23 -47
- package/src/config/config.service.mts +25 -8
- package/src/decorators/endpoint.decorator.mts +17 -15
- package/src/decorators/multipart.decorator.mts +17 -10
- package/src/decorators/stream.decorator.mts +17 -10
- package/tsconfig.json +16 -0
- package/tsup.config.mts +12 -0
- 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
|
|
4
|
-
|
|
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
|
-
|
|
8
|
-
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
?
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
?
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
?
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
?
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
?
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
?
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
package/tsup.config.mts
ADDED