@navios/core 0.2.1 → 0.3.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 +7 -3
- 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 +76 -55
- package/{dist → lib}/_tsup-dts-rollup.d.ts +76 -55
- 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/__tests__/controller.spec.mts +1 -1
- package/src/adapters/endpoint-adapter.service.mts +1 -1
- package/src/adapters/multipart-adapter.service.mts +1 -1
- package/src/adapters/stream-adapter.service.mts +1 -1
- package/src/config/config-service.interface.mts +1 -1
- package/src/config/config.provider.mts +22 -50
- package/src/config/config.service.mts +26 -9
- package/src/decorators/endpoint.decorator.mts +1 -6
- package/src/decorators/multipart.decorator.mts +1 -1
- package/src/decorators/stream.decorator.mts +1 -1
- package/src/metadata/handler.metadata.mts +1 -1
- package/tsconfig.json +16 -0
- package/tsup.config.mts +12 -0
- package/vitest.config.mts +9 -0
|
@@ -1,61 +1,33 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BoundInjectionToken,
|
|
3
|
-
Injectable,
|
|
4
|
-
InjectableType,
|
|
5
|
-
InjectionToken,
|
|
6
|
-
syncInject,
|
|
7
|
-
} from '@navios/di'
|
|
1
|
+
import { env } from 'node:process'
|
|
8
2
|
|
|
9
|
-
import {
|
|
3
|
+
import { FactoryInjectionToken, InjectionToken } from '@navios/di'
|
|
10
4
|
|
|
11
|
-
import
|
|
5
|
+
import { z } from 'zod'
|
|
12
6
|
|
|
13
|
-
import {
|
|
14
|
-
import { ConfigServiceInstance } from './config.service.mjs'
|
|
7
|
+
import type { ConfigServiceOptions } from './config.service.mjs'
|
|
15
8
|
|
|
16
|
-
|
|
17
|
-
load: z.function(),
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
export const ConfigProvider = InjectionToken.create<
|
|
9
|
+
import {
|
|
21
10
|
ConfigService,
|
|
22
|
-
|
|
23
|
-
|
|
11
|
+
ConfigServiceOptionsSchema,
|
|
12
|
+
ConfigServiceToken,
|
|
13
|
+
} from './config.service.mjs'
|
|
24
14
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
type: InjectableType.Factory,
|
|
15
|
+
export const ConfigProviderOptions = z.object({
|
|
16
|
+
load: z.function().returns(ConfigServiceOptionsSchema),
|
|
28
17
|
})
|
|
29
|
-
export class ConfigProviderFactory {
|
|
30
|
-
logger = syncInject(Logger, {
|
|
31
|
-
context: 'ConfigService',
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
async create(
|
|
35
|
-
ctx: any,
|
|
36
|
-
args: z.infer<typeof ConfigProviderOptions>,
|
|
37
|
-
): Promise<ConfigService> {
|
|
38
|
-
const { load } = args
|
|
39
|
-
const logger = this.logger
|
|
40
|
-
try {
|
|
41
|
-
const config = await load()
|
|
42
|
-
|
|
43
|
-
return new ConfigServiceInstance(
|
|
44
|
-
config,
|
|
45
|
-
logger,
|
|
46
|
-
) as unknown as ConfigService
|
|
47
|
-
} catch (error) {
|
|
48
|
-
logger.error('Error loading config', error)
|
|
49
|
-
throw error
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
18
|
|
|
54
|
-
export function provideConfig<ConfigMap extends
|
|
19
|
+
export function provideConfig<ConfigMap extends ConfigServiceOptions>(
|
|
55
20
|
options: z.input<typeof ConfigProviderOptions>,
|
|
56
|
-
):
|
|
57
|
-
|
|
58
|
-
typeof
|
|
21
|
+
): FactoryInjectionToken<
|
|
22
|
+
ConfigService<ConfigMap>,
|
|
23
|
+
typeof ConfigServiceOptionsSchema
|
|
59
24
|
> {
|
|
60
|
-
return InjectionToken.
|
|
25
|
+
return InjectionToken.factory(ConfigServiceToken, async () => options.load())
|
|
61
26
|
}
|
|
27
|
+
|
|
28
|
+
export const EnvConfigProvider = InjectionToken.bound<
|
|
29
|
+
ConfigService<Record<string, string>>,
|
|
30
|
+
typeof ConfigServiceOptionsSchema
|
|
31
|
+
>(ConfigServiceToken, {
|
|
32
|
+
...env,
|
|
33
|
+
})
|
|
@@ -1,16 +1,33 @@
|
|
|
1
|
-
import { NaviosException } from '@navios/
|
|
1
|
+
import { NaviosException } from '@navios/builder'
|
|
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
|
|
@@ -3,7 +3,7 @@ import type {
|
|
|
3
3
|
EndpointFunctionArgs,
|
|
4
4
|
HttpMethod,
|
|
5
5
|
Util_FlatObject,
|
|
6
|
-
} from '@navios/
|
|
6
|
+
} from '@navios/builder'
|
|
7
7
|
import type { AnyZodObject, z, ZodType } from 'zod'
|
|
8
8
|
|
|
9
9
|
import { ZodDiscriminatedUnion } from 'zod'
|
|
@@ -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
package/tsup.config.mts
ADDED