@navios/core 0.2.2 → 0.4.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 +8 -4
- package/e2e/endpoints/get.spec.mts +97 -0
- package/e2e/endpoints/post.spec.mts +113 -0
- package/examples/simple-test/api/index.mts +2 -2
- package/examples/simple-test/src/acl/public.attribute.mts +1 -1
- package/lib/_tsup-dts-rollup.d.mts +22 -54
- package/lib/_tsup-dts-rollup.d.ts +22 -54
- package/lib/index.js +21 -17
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +13 -9
- package/lib/index.mjs.map +1 -1
- package/package.json +13 -11
- package/project.json +8 -3
- package/src/__tests__/config.service.spec.mts +1 -1
- package/src/__tests__/controller.spec.mts +2 -2
- package/src/adapters/endpoint-adapter.service.mts +1 -1
- package/src/adapters/multipart-adapter.service.mts +12 -8
- package/src/adapters/stream-adapter.service.mts +1 -1
- package/src/attribute.factory.mts +1 -1
- package/src/config/config.provider.mts +2 -2
- package/src/config/config.service.mts +3 -3
- package/src/decorators/endpoint.decorator.mts +9 -10
- package/src/decorators/multipart.decorator.mts +5 -5
- package/src/decorators/stream.decorator.mts +4 -4
- package/src/logger/logger.factory.mts +1 -1
- package/src/metadata/handler.metadata.mts +1 -1
- package/tsconfig.json +7 -2
- package/tsconfig.lib.json +8 -0
- package/tsconfig.spec.json +12 -0
- package/tsup.config.mts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@navios/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.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/
|
|
16
|
-
"zod": "^3.
|
|
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,18 @@
|
|
|
31
31
|
}
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@navios/
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
34
|
+
"@navios/builder": "^0.3.0",
|
|
35
|
+
"@types/supertest": "^6.0.3",
|
|
36
|
+
"supertest": "^7.1.4",
|
|
37
|
+
"tsx": "^4.20.5",
|
|
38
|
+
"typescript": "^5.9.2",
|
|
39
|
+
"zod": "^4.1.4"
|
|
38
40
|
},
|
|
39
41
|
"dependencies": {
|
|
40
|
-
"@fastify/cors": "^11.0
|
|
42
|
+
"@fastify/cors": "^11.1.0",
|
|
41
43
|
"@fastify/multipart": "^9.0.3",
|
|
42
|
-
"@navios/di": "^0.1
|
|
43
|
-
"fastify": "^5.
|
|
44
|
-
"fastify-type-provider-zod": "^
|
|
44
|
+
"@navios/di": "^0.2.1",
|
|
45
|
+
"fastify": "^5.5.0",
|
|
46
|
+
"fastify-type-provider-zod": "^5.0.3"
|
|
45
47
|
}
|
|
46
48
|
}
|
package/project.json
CHANGED
|
@@ -9,7 +9,12 @@
|
|
|
9
9
|
"check": {
|
|
10
10
|
"executor": "nx:run-commands",
|
|
11
11
|
"outputs": ["{projectRoot}/dist"],
|
|
12
|
-
"inputs": [
|
|
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"
|
|
@@ -17,7 +22,7 @@
|
|
|
17
22
|
},
|
|
18
23
|
"test:ci": {
|
|
19
24
|
"executor": "nx:run-commands",
|
|
20
|
-
"inputs": ["^projectSources","project"],
|
|
25
|
+
"inputs": ["^projectSources", "project"],
|
|
21
26
|
"options": {
|
|
22
27
|
"command": "vitest run",
|
|
23
28
|
"cwd": "packages/core"
|
|
@@ -25,7 +30,7 @@
|
|
|
25
30
|
},
|
|
26
31
|
"build": {
|
|
27
32
|
"executor": "nx:run-commands",
|
|
28
|
-
"inputs": ["projectSources"],
|
|
33
|
+
"inputs": ["projectSources", "{projectRoot}/tsup.config.mts"],
|
|
29
34
|
"outputs": ["{projectRoot}/lib"],
|
|
30
35
|
"dependsOn": ["check", "test:ci"],
|
|
31
36
|
"options": {
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
|
|
16
16
|
describe('ConfigService', () => {
|
|
17
17
|
it('should be able to get a config value', async () => {
|
|
18
|
-
const service = await inject(ConfigServiceToken, env)
|
|
18
|
+
const service = await inject(ConfigServiceToken, { ...env })
|
|
19
19
|
expect(service).toBeDefined()
|
|
20
20
|
expect(service.get('NODE_ENV')).toBe(env.NODE_ENV)
|
|
21
21
|
})
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { MultipartFile, MultipartValue } from '@fastify/multipart'
|
|
2
|
-
import type { BaseEndpointConfig } from '@navios/
|
|
2
|
+
import type { BaseEndpointConfig } from '@navios/builder'
|
|
3
3
|
import type { FastifyRequest } from 'fastify'
|
|
4
|
-
import type {
|
|
4
|
+
import type { ZodRawShape } from 'zod/v4'
|
|
5
5
|
|
|
6
6
|
import { Injectable, InjectionToken } from '@navios/di'
|
|
7
7
|
|
|
8
|
-
import { ZodArray, ZodObject, ZodOptional } from 'zod'
|
|
8
|
+
import { ZodArray, ZodObject, ZodOptional } from 'zod/v4'
|
|
9
9
|
|
|
10
10
|
import type { HandlerMetadata } from '../metadata/index.mjs'
|
|
11
11
|
|
|
@@ -38,8 +38,8 @@ export class MultipartAdapterService extends EndpointAdapterService {
|
|
|
38
38
|
target.urlParams = request.params
|
|
39
39
|
})
|
|
40
40
|
}
|
|
41
|
-
const requestSchema = config.requestSchema as unknown as
|
|
42
|
-
const shape = requestSchema.
|
|
41
|
+
const requestSchema = config.requestSchema as unknown as ZodObject
|
|
42
|
+
const shape = requestSchema._zod.def.shape
|
|
43
43
|
const structure = this.analyzeSchema(shape)
|
|
44
44
|
getters.push(async (target, request) => {
|
|
45
45
|
const req: Record<string, any> = {}
|
|
@@ -65,9 +65,13 @@ export class MultipartAdapterService extends EndpointAdapterService {
|
|
|
65
65
|
}
|
|
66
66
|
let value
|
|
67
67
|
if (part.type === 'file') {
|
|
68
|
-
value = new File(
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
value = new File(
|
|
69
|
+
[(await part.toBuffer()) as unknown as ArrayBuffer],
|
|
70
|
+
part.filename,
|
|
71
|
+
{
|
|
72
|
+
type: part.mimetype,
|
|
73
|
+
},
|
|
74
|
+
)
|
|
71
75
|
} else {
|
|
72
76
|
value = part.value
|
|
73
77
|
if (isObject && typeof value === 'string') {
|
|
@@ -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(
|
|
16
|
+
load: z.function({ output: ConfigServiceOptionsSchema }),
|
|
17
17
|
})
|
|
18
18
|
|
|
19
19
|
export function provideConfig<ConfigMap extends ConfigServiceOptions>(
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { NaviosException } from '@navios/
|
|
1
|
+
import { NaviosException } from '@navios/builder'
|
|
2
2
|
import { Injectable, InjectionToken, syncInject } 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<
|
|
@@ -3,10 +3,10 @@ import type {
|
|
|
3
3
|
EndpointFunctionArgs,
|
|
4
4
|
HttpMethod,
|
|
5
5
|
Util_FlatObject,
|
|
6
|
-
} from '@navios/
|
|
7
|
-
import type {
|
|
6
|
+
} from '@navios/builder'
|
|
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
11
|
import { EndpointAdapterToken } from '../adapters/index.mjs'
|
|
12
12
|
import { getEndpointMetadata } from '../metadata/index.mjs'
|
|
@@ -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
|
|
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
|
|
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
|
) => {
|
|
@@ -3,10 +3,10 @@ import type {
|
|
|
3
3
|
EndpointFunctionArgs,
|
|
4
4
|
HttpMethod,
|
|
5
5
|
Util_FlatObject,
|
|
6
|
-
} from '@navios/
|
|
7
|
-
import type {
|
|
6
|
+
} from '@navios/builder'
|
|
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
11
|
import { MultipartAdapterToken } from '../adapters/index.mjs'
|
|
12
12
|
import { getEndpointMetadata } from '../metadata/index.mjs'
|
|
@@ -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
|
|
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
|
|
71
|
+
params: QuerySchema extends ZodObject
|
|
72
72
|
? RequestSchema extends ZodType
|
|
73
73
|
? EndpointFunctionArgs<Url, QuerySchema, RequestSchema>
|
|
74
74
|
: EndpointFunctionArgs<Url, QuerySchema, undefined>
|
|
@@ -3,9 +3,9 @@ import type {
|
|
|
3
3
|
EndpointFunctionArgs,
|
|
4
4
|
HttpMethod,
|
|
5
5
|
Util_FlatObject,
|
|
6
|
-
} from '@navios/
|
|
6
|
+
} from '@navios/builder'
|
|
7
7
|
import type { FastifyReply } from 'fastify'
|
|
8
|
-
import type {
|
|
8
|
+
import type { ZodObject, ZodType } from 'zod/v4'
|
|
9
9
|
|
|
10
10
|
import { StreamAdapterToken } from '../adapters/index.mjs'
|
|
11
11
|
import { getEndpointMetadata } from '../metadata/index.mjs'
|
|
@@ -16,7 +16,7 @@ export type StreamParams<
|
|
|
16
16
|
},
|
|
17
17
|
Url extends string = EndpointDeclaration['config']['url'],
|
|
18
18
|
QuerySchema = EndpointDeclaration['config']['querySchema'],
|
|
19
|
-
> = QuerySchema extends
|
|
19
|
+
> = QuerySchema extends ZodObject
|
|
20
20
|
? EndpointDeclaration['config']['requestSchema'] extends ZodType
|
|
21
21
|
? Util_FlatObject<
|
|
22
22
|
EndpointFunctionArgs<
|
|
@@ -48,7 +48,7 @@ export function Stream<
|
|
|
48
48
|
}) {
|
|
49
49
|
return (
|
|
50
50
|
target: (
|
|
51
|
-
params: QuerySchema extends
|
|
51
|
+
params: QuerySchema extends ZodObject
|
|
52
52
|
? RequestSchema extends ZodType
|
|
53
53
|
? EndpointFunctionArgs<Url, QuerySchema, RequestSchema>
|
|
54
54
|
: EndpointFunctionArgs<Url, QuerySchema, undefined>
|
package/tsconfig.json
CHANGED
|
@@ -4,10 +4,15 @@
|
|
|
4
4
|
"module": "Node18",
|
|
5
5
|
"outDir": "dist"
|
|
6
6
|
},
|
|
7
|
-
"include": ["src/**/*"],
|
|
8
7
|
"references": [
|
|
9
8
|
{
|
|
10
|
-
"path": "
|
|
9
|
+
"path": "./tsconfig.lib.json"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"path": "./tsconfig.spec.json"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"path": "../builder"
|
|
11
16
|
},
|
|
12
17
|
{
|
|
13
18
|
"path": "../di"
|