@navios/core 1.1.0 → 2.0.0-alpha.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/CHANGELOG.md +53 -11
- package/README.md +67 -220
- package/lib/async-context-6pdlnNLA.d.mts +237 -0
- package/lib/async-context-6pdlnNLA.d.mts.map +1 -0
- package/lib/async-context-Dqk7pE-D.d.cts +237 -0
- package/lib/async-context-Dqk7pE-D.d.cts.map +1 -0
- package/lib/attribute-factory-B3VuYnp7.d.cts +70 -0
- package/lib/attribute-factory-B3VuYnp7.d.cts.map +1 -0
- package/lib/attribute-factory-mKOXoVnV.d.mts +70 -0
- package/lib/attribute-factory-mKOXoVnV.d.mts.map +1 -0
- package/lib/attribute-value-CjX9ZkLq.cjs +172 -0
- package/lib/attribute-value-CjX9ZkLq.cjs.map +1 -0
- package/lib/attribute-value-DMEA255r.mjs +119 -0
- package/lib/attribute-value-DMEA255r.mjs.map +1 -0
- package/lib/basic-execution-context-CeGuhMOz.mjs +246 -0
- package/lib/basic-execution-context-CeGuhMOz.mjs.map +1 -0
- package/lib/basic-execution-context-DSk5MNtc.cjs +281 -0
- package/lib/basic-execution-context-DSk5MNtc.cjs.map +1 -0
- package/lib/execution-context-BPD3FeFb.d.mts +71 -0
- package/lib/execution-context-BPD3FeFb.d.mts.map +1 -0
- package/lib/execution-context-BTJdHhbf.d.cts +71 -0
- package/lib/execution-context-BTJdHhbf.d.cts.map +1 -0
- package/lib/execution-context-token-BXUKB2hf.cjs +112 -0
- package/lib/execution-context-token-BXUKB2hf.cjs.map +1 -0
- package/lib/execution-context-token-CrXmTvk2.mjs +77 -0
- package/lib/execution-context-token-CrXmTvk2.mjs.map +1 -0
- package/lib/index.cjs +1687 -4424
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +838 -3
- package/lib/index.d.cts.map +1 -0
- package/lib/index.d.mts +838 -3
- package/lib/index.d.mts.map +1 -0
- package/lib/index.mjs +1573 -4219
- package/lib/index.mjs.map +1 -1
- package/lib/legacy-compat/index.cjs +72 -371
- package/lib/legacy-compat/index.cjs.map +1 -1
- package/lib/legacy-compat/index.d.cts +42 -382
- package/lib/legacy-compat/index.d.cts.map +1 -1
- package/lib/legacy-compat/index.d.mts +41 -382
- package/lib/legacy-compat/index.d.mts.map +1 -1
- package/lib/legacy-compat/index.mjs +51 -345
- package/lib/legacy-compat/index.mjs.map +1 -1
- package/lib/module-Bha7GER_.mjs +135 -0
- package/lib/module-Bha7GER_.mjs.map +1 -0
- package/lib/module-DZewk_2r.cjs +164 -0
- package/lib/module-DZewk_2r.cjs.map +1 -0
- package/lib/module-graph-DCP9MHG0.cjs +147 -0
- package/lib/module-graph-DCP9MHG0.cjs.map +1 -0
- package/lib/module-graph-xvVEykFM.mjs +142 -0
- package/lib/module-graph-xvVEykFM.mjs.map +1 -0
- package/lib/module-metadata-C8S92seK.cjs +95 -0
- package/lib/module-metadata-C8S92seK.cjs.map +1 -0
- package/lib/module-metadata-k3RTt20x.mjs +66 -0
- package/lib/module-metadata-k3RTt20x.mjs.map +1 -0
- package/lib/module-options-Dmse0gii.d.mts +51 -0
- package/lib/module-options-Dmse0gii.d.mts.map +1 -0
- package/lib/module-options-IuDO-p8u.d.cts +51 -0
- package/lib/module-options-IuDO-p8u.d.cts.map +1 -0
- package/lib/testing/index.cjs +96 -414
- package/lib/testing/index.cjs.map +1 -1
- package/lib/testing/index.d.cts +25 -385
- package/lib/testing/index.d.cts.map +1 -1
- package/lib/testing/index.d.mts +24 -385
- package/lib/testing/index.d.mts.map +1 -1
- package/lib/testing/index.mjs +94 -408
- package/lib/testing/index.mjs.map +1 -1
- package/lib/transport.cjs +25 -0
- package/lib/transport.d.cts +190 -0
- package/lib/transport.d.cts.map +1 -0
- package/lib/transport.d.mts +190 -0
- package/lib/transport.d.mts.map +1 -0
- package/lib/transport.mjs +7 -0
- package/package.json +37 -17
- package/docs/README.md +0 -316
- package/docs/adapters.md +0 -308
- package/docs/application-setup.md +0 -524
- package/docs/attributes.md +0 -689
- package/docs/controllers.md +0 -373
- package/docs/endpoints.md +0 -444
- package/docs/exceptions.md +0 -352
- package/docs/guards.md +0 -550
- package/docs/legacy-compat.md +0 -356
- package/docs/modules.md +0 -377
- package/docs/quick-start.md +0 -290
- package/docs/services.md +0 -427
- package/docs/testing.md +0 -827
- package/lib/index-3LcTrbxz.d.mts +0 -3804
- package/lib/index-3LcTrbxz.d.mts.map +0 -1
- package/lib/index-B14SekVb.d.cts +0 -3804
- package/lib/index-B14SekVb.d.cts.map +0 -1
- package/lib/navios.factory-CUrO_p6K.cjs +0 -4538
- package/lib/navios.factory-CUrO_p6K.cjs.map +0 -1
- package/lib/navios.factory-DjUOOVVL.mjs +0 -4151
- package/lib/navios.factory-DjUOOVVL.mjs.map +0 -1
- package/lib/tokens-BEuBMGGX.cjs +0 -193
- package/lib/tokens-BEuBMGGX.cjs.map +0 -1
- package/lib/tokens-COyNGV1I.mjs +0 -97
- package/lib/tokens-COyNGV1I.mjs.map +0 -1
- package/lib/use-guards.decorator-DLmRl2CV.mjs +0 -336
- package/lib/use-guards.decorator-DLmRl2CV.mjs.map +0 -1
- package/lib/use-guards.decorator-DhumFTk3.cjs +0 -444
- package/lib/use-guards.decorator-DhumFTk3.cjs.map +0 -1
- package/project.json +0 -66
- package/src/__tests__/attribute.factory.spec.mts +0 -300
- package/src/__tests__/config.service.spec.mts +0 -43
- package/src/__tests__/console-logger.service.spec.mts +0 -312
- package/src/__tests__/controller-resolver.spec.mts +0 -229
- package/src/__tests__/controller.spec.mts +0 -58
- package/src/__tests__/guard-runner.service.spec.mts +0 -399
- package/src/__tests__/logger.service.spec.mts +0 -147
- package/src/__tests__/responders.spec.mts +0 -340
- package/src/__tests__/testing-module.spec.mts +0 -459
- package/src/__tests__/unit-testing-module.spec.mts +0 -424
- package/src/attribute.factory.mts +0 -325
- package/src/config/config-service.interface.mts +0 -47
- package/src/config/config.provider.mts +0 -69
- package/src/config/config.service.mts +0 -176
- package/src/config/index.mts +0 -5
- package/src/config/types.mts +0 -58
- package/src/config/utils/helpers.mts +0 -23
- package/src/config/utils/index.mts +0 -1
- package/src/decorators/controller.decorator.mts +0 -81
- package/src/decorators/endpoint.decorator.mts +0 -181
- package/src/decorators/header.decorator.mts +0 -38
- package/src/decorators/http-code.decorator.mts +0 -38
- package/src/decorators/index.mts +0 -8
- package/src/decorators/module.decorator.mts +0 -106
- package/src/decorators/multipart.decorator.mts +0 -169
- package/src/decorators/stream.decorator.mts +0 -155
- package/src/decorators/use-guards.decorator.mts +0 -73
- package/src/exceptions/bad-request.exception.mts +0 -28
- package/src/exceptions/conflict.exception.mts +0 -31
- package/src/exceptions/forbidden.exception.mts +0 -30
- package/src/exceptions/http.exception.mts +0 -33
- package/src/exceptions/index.mts +0 -7
- package/src/exceptions/internal-server-error.exception.mts +0 -33
- package/src/exceptions/not-found.exception.mts +0 -33
- package/src/exceptions/unauthorized.exception.mts +0 -30
- package/src/factories/adapter.factory.mts +0 -20
- package/src/factories/endpoint-adapter.factory.mts +0 -21
- package/src/factories/http-adapter.factory.mts +0 -20
- package/src/factories/index.mts +0 -8
- package/src/factories/multipart-adapter.factory.mts +0 -21
- package/src/factories/reply.factory.mts +0 -21
- package/src/factories/request.factory.mts +0 -21
- package/src/factories/stream-adapter.factory.mts +0 -20
- package/src/factories/xml-stream-adapter.factory.mts +0 -20
- package/src/index.mts +0 -16
- package/src/interfaces/abstract-adapter.interface.mts +0 -32
- package/src/interfaces/abstract-execution-context.inteface.mts +0 -48
- package/src/interfaces/abstract-http-adapter.interface.mts +0 -79
- package/src/interfaces/abstract-http-cors-options.interface.mts +0 -59
- package/src/interfaces/abstract-http-handler-adapter.interface.mts +0 -127
- package/src/interfaces/abstract-http-listen-options.interface.mts +0 -4
- package/src/interfaces/adapter-environment.interface.mts +0 -74
- package/src/interfaces/can-activate.mts +0 -38
- package/src/interfaces/http-header.mts +0 -18
- package/src/interfaces/index.mts +0 -14
- package/src/interfaces/navios-module.mts +0 -28
- package/src/interfaces/plugin-context.mts +0 -104
- package/src/interfaces/plugin-stage.mts +0 -62
- package/src/interfaces/plugin.interface.mts +0 -119
- package/src/interfaces/staged-plugin.interface.mts +0 -209
- package/src/legacy-compat/__type-tests__/legacy-decorators.spec-d.mts +0 -521
- package/src/legacy-compat/__type-tests__/tsconfig.json +0 -15
- package/src/legacy-compat/attribute.factory.mts +0 -351
- package/src/legacy-compat/decorators/controller.decorator.mts +0 -31
- package/src/legacy-compat/decorators/endpoint.decorator.mts +0 -73
- package/src/legacy-compat/decorators/header.decorator.mts +0 -43
- package/src/legacy-compat/decorators/http-code.decorator.mts +0 -39
- package/src/legacy-compat/decorators/index.mts +0 -11
- package/src/legacy-compat/decorators/module.decorator.mts +0 -37
- package/src/legacy-compat/decorators/multipart.decorator.mts +0 -72
- package/src/legacy-compat/decorators/stream.decorator.mts +0 -89
- package/src/legacy-compat/decorators/use-guards.decorator.mts +0 -80
- package/src/legacy-compat/index.mts +0 -57
- package/src/logger/README.md +0 -3
- package/src/logger/console-logger.service.mts +0 -714
- package/src/logger/index.mts +0 -6
- package/src/logger/log-levels.mts +0 -21
- package/src/logger/logger-service.interface.mts +0 -42
- package/src/logger/logger.service.mts +0 -113
- package/src/logger/logger.tokens.mts +0 -44
- package/src/logger/utils/cli-colors.util.mts +0 -17
- package/src/logger/utils/filter-log-levelts.util.mts +0 -29
- package/src/logger/utils/index.mts +0 -5
- package/src/logger/utils/is-log-level-enabled.mts +0 -33
- package/src/logger/utils/is-log-level.util.mts +0 -10
- package/src/logger/utils/shared.utils.mts +0 -51
- package/src/metadata/controller.metadata.mts +0 -79
- package/src/metadata/handler.metadata.mts +0 -80
- package/src/metadata/index.mts +0 -4
- package/src/metadata/module.metadata.mts +0 -116
- package/src/metadata/navios-managed.metadata.mts +0 -42
- package/src/navios.application.mts +0 -678
- package/src/navios.environment.mts +0 -42
- package/src/navios.factory.mts +0 -158
- package/src/responders/enums/framework-error.enum.mts +0 -38
- package/src/responders/enums/index.mts +0 -1
- package/src/responders/index.mts +0 -4
- package/src/responders/interfaces/error-responder.interface.mts +0 -42
- package/src/responders/interfaces/error-response.interface.mts +0 -22
- package/src/responders/interfaces/index.mts +0 -3
- package/src/responders/interfaces/problem-details.interface.mts +0 -34
- package/src/responders/services/error-response-producer.service.mts +0 -143
- package/src/responders/services/forbidden-responder.service.mts +0 -77
- package/src/responders/services/index.mts +0 -5
- package/src/responders/services/internal-server-error-responder.service.mts +0 -57
- package/src/responders/services/not-found-responder.service.mts +0 -76
- package/src/responders/services/validation-error-responder.service.mts +0 -78
- package/src/responders/tokens/index.mts +0 -1
- package/src/responders/tokens/responder.tokens.mts +0 -84
- package/src/services/abstract-handler-adapter.service.mts +0 -366
- package/src/services/guard-runner.service.mts +0 -152
- package/src/services/index.mts +0 -4
- package/src/services/instance-resolver.service.mts +0 -177
- package/src/services/module-loader.service.mts +0 -255
- package/src/stores/index.mts +0 -1
- package/src/stores/request-id.store.mts +0 -85
- package/src/testing/index.mts +0 -3
- package/src/testing/testing-module.mts +0 -393
- package/src/testing/unit-testing-module.mts +0 -298
- package/src/tokens/adapter.token.mts +0 -6
- package/src/tokens/endpoint-adapter.token.mts +0 -8
- package/src/tokens/execution-context.token.mts +0 -9
- package/src/tokens/http-adapter.token.mts +0 -8
- package/src/tokens/index.mts +0 -10
- package/src/tokens/multipart-adapter.token.mts +0 -8
- package/src/tokens/navios-options.token.mts +0 -6
- package/src/tokens/reply.token.mts +0 -3
- package/src/tokens/request.token.mts +0 -3
- package/src/tokens/stream-adapter.token.mts +0 -8
- package/src/tokens/xml-stream-adapter.token.mts +0 -8
- package/src/utils/adapter-supports.util.mts +0 -47
- package/src/utils/define-plugin.mts +0 -251
- package/src/utils/index.mts +0 -2
- package/tsconfig.json +0 -21
- package/tsconfig.lib.json +0 -8
- package/tsconfig.spec.json +0 -15
- package/tsdown.config.mts +0 -35
- package/vitest.config.mts +0 -15
|
@@ -1,325 +0,0 @@
|
|
|
1
|
-
import type { ClassType } from '@navios/di'
|
|
2
|
-
import type { z, ZodType } from 'zod/v4'
|
|
3
|
-
|
|
4
|
-
import type {
|
|
5
|
-
ControllerMetadata,
|
|
6
|
-
HandlerMetadata,
|
|
7
|
-
ModuleMetadata,
|
|
8
|
-
} from './metadata/index.mjs'
|
|
9
|
-
|
|
10
|
-
import {
|
|
11
|
-
getControllerMetadata,
|
|
12
|
-
getEndpointMetadata,
|
|
13
|
-
getModuleMetadata,
|
|
14
|
-
hasControllerMetadata,
|
|
15
|
-
hasModuleMetadata,
|
|
16
|
-
} from './metadata/index.mjs'
|
|
17
|
-
import {
|
|
18
|
-
getManagedMetadata,
|
|
19
|
-
hasManagedMetadata,
|
|
20
|
-
} from './metadata/navios-managed.metadata.mjs'
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Type for a class attribute decorator without a value.
|
|
24
|
-
*
|
|
25
|
-
* Attributes are custom metadata decorators that can be applied to modules,
|
|
26
|
-
* controllers, and endpoints.
|
|
27
|
-
*/
|
|
28
|
-
export type ClassAttribute = (() => <T>(
|
|
29
|
-
target: T,
|
|
30
|
-
context: ClassDecoratorContext | ClassMethodDecoratorContext,
|
|
31
|
-
) => T) & {
|
|
32
|
-
token: symbol
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Type for a class attribute decorator with a validated value.
|
|
37
|
-
*
|
|
38
|
-
* @typeParam T - The Zod schema type for validation
|
|
39
|
-
*/
|
|
40
|
-
export type ClassSchemaAttribute<T extends ZodType> = ((
|
|
41
|
-
value: z.input<T>,
|
|
42
|
-
) => <T>(
|
|
43
|
-
target: T,
|
|
44
|
-
context: ClassDecoratorContext | ClassMethodDecoratorContext,
|
|
45
|
-
) => T) & {
|
|
46
|
-
token: symbol
|
|
47
|
-
schema: ZodType
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Factory for creating custom attribute decorators.
|
|
52
|
-
*
|
|
53
|
-
* Attributes allow you to add custom metadata to modules, controllers, and endpoints.
|
|
54
|
-
* This is useful for cross-cutting concerns like rate limiting, caching, API versioning, etc.
|
|
55
|
-
*
|
|
56
|
-
* @example
|
|
57
|
-
* ```typescript
|
|
58
|
-
* // Create a simple boolean attribute
|
|
59
|
-
* const Public = AttributeFactory.createAttribute(Symbol.for('Public'))
|
|
60
|
-
*
|
|
61
|
-
* // Use it as a decorator
|
|
62
|
-
* @Controller()
|
|
63
|
-
* @Public()
|
|
64
|
-
* export class PublicController { }
|
|
65
|
-
*
|
|
66
|
-
* // Check if attribute exists
|
|
67
|
-
* if (AttributeFactory.has(Public, controllerMetadata)) {
|
|
68
|
-
* // Skip authentication
|
|
69
|
-
* }
|
|
70
|
-
* ```
|
|
71
|
-
*
|
|
72
|
-
* @example
|
|
73
|
-
* ```typescript
|
|
74
|
-
* // Create an attribute with a validated value
|
|
75
|
-
* const RateLimit = AttributeFactory.createAttribute(
|
|
76
|
-
* Symbol.for('RateLimit'),
|
|
77
|
-
* z.object({ requests: z.number(), window: z.number() })
|
|
78
|
-
* )
|
|
79
|
-
*
|
|
80
|
-
* // Use it with a value
|
|
81
|
-
* @Endpoint(apiEndpoint)
|
|
82
|
-
* @RateLimit({ requests: 100, window: 60000 })
|
|
83
|
-
* async handler() { }
|
|
84
|
-
*
|
|
85
|
-
* // Get the value
|
|
86
|
-
* const limit = AttributeFactory.get(RateLimit, endpointMetadata)
|
|
87
|
-
* // limit is typed as { requests: number, window: number } | null
|
|
88
|
-
* ```
|
|
89
|
-
*/
|
|
90
|
-
export class AttributeFactory {
|
|
91
|
-
/**
|
|
92
|
-
* Creates a simple attribute decorator without a value.
|
|
93
|
-
*
|
|
94
|
-
* @param token - A unique symbol to identify this attribute
|
|
95
|
-
* @returns A decorator function that can be applied to classes or methods
|
|
96
|
-
*
|
|
97
|
-
* @example
|
|
98
|
-
* ```typescript
|
|
99
|
-
* const Public = AttributeFactory.createAttribute(Symbol.for('Public'))
|
|
100
|
-
*
|
|
101
|
-
* @Public()
|
|
102
|
-
* @Controller()
|
|
103
|
-
* export class PublicController { }
|
|
104
|
-
* ```
|
|
105
|
-
*/
|
|
106
|
-
static createAttribute(token: symbol): ClassAttribute
|
|
107
|
-
/**
|
|
108
|
-
* Creates an attribute decorator with a validated value.
|
|
109
|
-
*
|
|
110
|
-
* @param token - A unique symbol to identify this attribute
|
|
111
|
-
* @param schema - A Zod schema to validate the attribute value
|
|
112
|
-
* @returns A decorator function that accepts a value and can be applied to classes or methods
|
|
113
|
-
*
|
|
114
|
-
* @example
|
|
115
|
-
* ```typescript
|
|
116
|
-
* const RateLimit = AttributeFactory.createAttribute(
|
|
117
|
-
* Symbol.for('RateLimit'),
|
|
118
|
-
* z.object({ requests: z.number(), window: z.number() })
|
|
119
|
-
* )
|
|
120
|
-
*
|
|
121
|
-
* @RateLimit({ requests: 100, window: 60000 })
|
|
122
|
-
* @Endpoint(apiEndpoint)
|
|
123
|
-
* async handler() { }
|
|
124
|
-
* ```
|
|
125
|
-
*/
|
|
126
|
-
static createAttribute<T extends ZodType>(
|
|
127
|
-
token: symbol,
|
|
128
|
-
schema: T,
|
|
129
|
-
): ClassSchemaAttribute<T>
|
|
130
|
-
static createAttribute(token: symbol, schema?: ZodType) {
|
|
131
|
-
const res =
|
|
132
|
-
(value?: unknown) =>
|
|
133
|
-
(
|
|
134
|
-
target: any,
|
|
135
|
-
context: ClassDecoratorContext | ClassMethodDecoratorContext,
|
|
136
|
-
) => {
|
|
137
|
-
if (context.kind !== 'class' && context.kind !== 'method') {
|
|
138
|
-
throw new Error(
|
|
139
|
-
'[Navios] Attribute can only be applied to classes or methods',
|
|
140
|
-
)
|
|
141
|
-
}
|
|
142
|
-
const isController =
|
|
143
|
-
context.kind === 'class' && hasControllerMetadata(target as ClassType)
|
|
144
|
-
const isModule =
|
|
145
|
-
context.kind === 'class' && hasModuleMetadata(target as ClassType)
|
|
146
|
-
const isManaged =
|
|
147
|
-
context.kind === 'class' && hasManagedMetadata(target as ClassType)
|
|
148
|
-
if (context.kind === 'class' && !isController && !isModule && !isManaged) {
|
|
149
|
-
throw new Error(
|
|
150
|
-
'[Navios] Attribute can only be applied to classes with @Controller, @Module, or other Navios-managed decorators',
|
|
151
|
-
)
|
|
152
|
-
}
|
|
153
|
-
let metadata =
|
|
154
|
-
context.kind === 'class'
|
|
155
|
-
? isController
|
|
156
|
-
? getControllerMetadata(target as any, context)
|
|
157
|
-
: isModule
|
|
158
|
-
? getModuleMetadata(target as any, context)
|
|
159
|
-
: isManaged
|
|
160
|
-
? getManagedMetadata(target as any)!
|
|
161
|
-
: null
|
|
162
|
-
: getEndpointMetadata(target, context)
|
|
163
|
-
|
|
164
|
-
if (!metadata) {
|
|
165
|
-
throw new Error(
|
|
166
|
-
'[Navios] Could not determine metadata for attribute target',
|
|
167
|
-
)
|
|
168
|
-
}
|
|
169
|
-
if (schema) {
|
|
170
|
-
const validatedValue = schema.safeParse(value)
|
|
171
|
-
if (!validatedValue.success) {
|
|
172
|
-
throw new Error(
|
|
173
|
-
`[Navios] Invalid value for attribute ${token.toString()}: ${validatedValue.error}`,
|
|
174
|
-
)
|
|
175
|
-
}
|
|
176
|
-
metadata.customAttributes.set(token, validatedValue.data)
|
|
177
|
-
} else {
|
|
178
|
-
metadata.customAttributes.set(token, true)
|
|
179
|
-
}
|
|
180
|
-
return target
|
|
181
|
-
}
|
|
182
|
-
res.token = token
|
|
183
|
-
if (schema) {
|
|
184
|
-
res.schema = schema
|
|
185
|
-
}
|
|
186
|
-
return res
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* Gets the value of an attribute from metadata.
|
|
191
|
-
*
|
|
192
|
-
* Returns `null` if the attribute is not present.
|
|
193
|
-
* For simple attributes (without values), returns `true` if present.
|
|
194
|
-
*
|
|
195
|
-
* @param attribute - The attribute decorator
|
|
196
|
-
* @param target - The metadata object (module, controller, or handler)
|
|
197
|
-
* @returns The attribute value, `true` for simple attributes, or `null` if not found
|
|
198
|
-
*
|
|
199
|
-
* @example
|
|
200
|
-
* ```typescript
|
|
201
|
-
* const isPublic = AttributeFactory.get(Public, controllerMetadata)
|
|
202
|
-
* // isPublic is true | null
|
|
203
|
-
*
|
|
204
|
-
* const rateLimit = AttributeFactory.get(RateLimit, endpointMetadata)
|
|
205
|
-
* // rateLimit is { requests: number, window: number } | null
|
|
206
|
-
* ```
|
|
207
|
-
*/
|
|
208
|
-
static get(
|
|
209
|
-
attribute: ClassAttribute,
|
|
210
|
-
target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>,
|
|
211
|
-
): true | null
|
|
212
|
-
static get<T extends ZodType>(
|
|
213
|
-
attribute: ClassSchemaAttribute<T>,
|
|
214
|
-
target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>,
|
|
215
|
-
): z.output<T> | null
|
|
216
|
-
static get(
|
|
217
|
-
attribute: ClassAttribute | ClassSchemaAttribute<any>,
|
|
218
|
-
target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>,
|
|
219
|
-
) {
|
|
220
|
-
return target.customAttributes.get(attribute.token) ?? null
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* Gets all values of an attribute from metadata (useful when an attribute can appear multiple times).
|
|
225
|
-
*
|
|
226
|
-
* Returns `null` if the attribute is not present.
|
|
227
|
-
*
|
|
228
|
-
* @param attribute - The attribute decorator
|
|
229
|
-
* @param target - The metadata object (module, controller, or handler)
|
|
230
|
-
* @returns An array of attribute values, or `null` if not found
|
|
231
|
-
*
|
|
232
|
-
* @example
|
|
233
|
-
* ```typescript
|
|
234
|
-
* const tags = AttributeFactory.getAll(Tag, endpointMetadata)
|
|
235
|
-
* // tags is string[] | null
|
|
236
|
-
* ```
|
|
237
|
-
*/
|
|
238
|
-
static getAll(
|
|
239
|
-
attribute: ClassAttribute,
|
|
240
|
-
target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>,
|
|
241
|
-
): Array<true> | null
|
|
242
|
-
static getAll<T extends ZodType>(
|
|
243
|
-
attribute: ClassSchemaAttribute<T>,
|
|
244
|
-
target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>,
|
|
245
|
-
): Array<z.output<T>> | null
|
|
246
|
-
static getAll(
|
|
247
|
-
attribute: ClassAttribute | ClassSchemaAttribute<any>,
|
|
248
|
-
target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>,
|
|
249
|
-
) {
|
|
250
|
-
const values = Array.from(target.customAttributes.entries())
|
|
251
|
-
.filter(([key]) => key === attribute.token)
|
|
252
|
-
.map(([, value]) => value)
|
|
253
|
-
return values.length > 0 ? values : null
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* Gets the last value of an attribute from an array of metadata objects.
|
|
258
|
-
*
|
|
259
|
-
* Searches from the end of the array backwards, useful for finding the most
|
|
260
|
-
* specific attribute value (e.g., endpoint-level overrides module-level).
|
|
261
|
-
*
|
|
262
|
-
* @param attribute - The attribute decorator
|
|
263
|
-
* @param target - An array of metadata objects (typically [module, controller, handler])
|
|
264
|
-
* @returns The last attribute value found, or `null` if not found
|
|
265
|
-
*
|
|
266
|
-
* @example
|
|
267
|
-
* ```typescript
|
|
268
|
-
* // Check attribute hierarchy: endpoint -> controller -> module
|
|
269
|
-
* const rateLimit = AttributeFactory.getLast(RateLimit, [
|
|
270
|
-
* moduleMetadata,
|
|
271
|
-
* controllerMetadata,
|
|
272
|
-
* endpointMetadata
|
|
273
|
-
* ])
|
|
274
|
-
* ```
|
|
275
|
-
*/
|
|
276
|
-
static getLast(
|
|
277
|
-
attribute: ClassAttribute,
|
|
278
|
-
target: (ModuleMetadata | ControllerMetadata | HandlerMetadata<any>)[],
|
|
279
|
-
): true | null
|
|
280
|
-
static getLast<T extends ZodType>(
|
|
281
|
-
attribute: ClassSchemaAttribute<T>,
|
|
282
|
-
target: (ModuleMetadata | ControllerMetadata | HandlerMetadata<any>)[],
|
|
283
|
-
): z.output<T> | null
|
|
284
|
-
static getLast(
|
|
285
|
-
attribute: ClassAttribute | ClassSchemaAttribute<any>,
|
|
286
|
-
target: (ModuleMetadata | ControllerMetadata | HandlerMetadata<any>)[],
|
|
287
|
-
) {
|
|
288
|
-
for (let i = target.length - 1; i >= 0; i--) {
|
|
289
|
-
const value = target[i].customAttributes.get(attribute.token)
|
|
290
|
-
if (value) {
|
|
291
|
-
return value
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
return null
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
/**
|
|
298
|
-
* Checks if an attribute is present on the metadata object.
|
|
299
|
-
*
|
|
300
|
-
* @param attribute - The attribute decorator
|
|
301
|
-
* @param target - The metadata object (module, controller, or handler)
|
|
302
|
-
* @returns `true` if the attribute is present, `false` otherwise
|
|
303
|
-
*
|
|
304
|
-
* @example
|
|
305
|
-
* ```typescript
|
|
306
|
-
* if (AttributeFactory.has(Public, controllerMetadata)) {
|
|
307
|
-
* // Skip authentication
|
|
308
|
-
* }
|
|
309
|
-
* ```
|
|
310
|
-
*/
|
|
311
|
-
static has(
|
|
312
|
-
attribute: ClassAttribute,
|
|
313
|
-
target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>,
|
|
314
|
-
): boolean
|
|
315
|
-
static has<T extends ZodType>(
|
|
316
|
-
attribute: ClassSchemaAttribute<T>,
|
|
317
|
-
target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>,
|
|
318
|
-
): boolean
|
|
319
|
-
static has(
|
|
320
|
-
attribute: ClassAttribute | ClassSchemaAttribute<any>,
|
|
321
|
-
target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>,
|
|
322
|
-
) {
|
|
323
|
-
return target.customAttributes.has(attribute.token)
|
|
324
|
-
}
|
|
325
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import type { Path, PathValue } from './types.mjs'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Interface for configuration service implementations.
|
|
5
|
-
*
|
|
6
|
-
* Provides type-safe access to configuration values with support for nested paths.
|
|
7
|
-
*
|
|
8
|
-
* @typeParam Config - The configuration object type
|
|
9
|
-
*/
|
|
10
|
-
export interface ConfigServiceInterface<Config = Record<string, unknown>> {
|
|
11
|
-
/**
|
|
12
|
-
* Gets the entire configuration object.
|
|
13
|
-
*/
|
|
14
|
-
getConfig: () => Config
|
|
15
|
-
/**
|
|
16
|
-
* Gets a configuration value by key path. Returns `null` if not found.
|
|
17
|
-
*
|
|
18
|
-
* @param key - Dot-separated path to the configuration value (e.g., 'database.host')
|
|
19
|
-
* @returns The configuration value or `null` if not found
|
|
20
|
-
*/
|
|
21
|
-
get: <Key extends Path<Config>>(key: Key) => PathValue<Config, Key> | null
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Gets a configuration value by key path, or returns a default value if not found.
|
|
25
|
-
*
|
|
26
|
-
* @param key - Dot-separated path to the configuration value
|
|
27
|
-
* @param defaultValue - Default value to return if the key is not found
|
|
28
|
-
* @returns The configuration value or the default value
|
|
29
|
-
*/
|
|
30
|
-
getOrDefault: <Key extends Path<Config>>(
|
|
31
|
-
key: Key,
|
|
32
|
-
defaultValue: PathValue<Config, Key>,
|
|
33
|
-
) => PathValue<Config, Key>
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Gets a configuration value by key path, or throws an error if not found.
|
|
37
|
-
*
|
|
38
|
-
* @param key - Dot-separated path to the configuration value
|
|
39
|
-
* @param errorMessage - Optional custom error message
|
|
40
|
-
* @returns The configuration value
|
|
41
|
-
* @throws Error if the key is not found
|
|
42
|
-
*/
|
|
43
|
-
getOrThrow: <Key extends Path<Config>>(
|
|
44
|
-
key: Key,
|
|
45
|
-
errorMessage?: string,
|
|
46
|
-
) => PathValue<Config, Key>
|
|
47
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { env } from 'node:process'
|
|
2
|
-
|
|
3
|
-
import { FactoryInjectionToken, InjectionToken } from '@navios/di'
|
|
4
|
-
|
|
5
|
-
import { z } from 'zod/v4'
|
|
6
|
-
|
|
7
|
-
import type { ConfigServiceOptions } from './config.service.mjs'
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
ConfigService,
|
|
11
|
-
ConfigServiceOptionsSchema,
|
|
12
|
-
ConfigServiceToken,
|
|
13
|
-
} from './config.service.mjs'
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Schema for configuration provider options.
|
|
17
|
-
*/
|
|
18
|
-
export const ConfigProviderOptions = z.object({
|
|
19
|
-
load: z.function({ output: ConfigServiceOptionsSchema }),
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Creates a factory injection token for ConfigService that loads configuration asynchronously.
|
|
24
|
-
*
|
|
25
|
-
* Use this when you need to load configuration from a file, database, or other async source.
|
|
26
|
-
*
|
|
27
|
-
* @param options - Configuration provider options
|
|
28
|
-
* @param options.load - Async function that loads and returns the configuration object
|
|
29
|
-
* @returns A factory injection token for ConfigService
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* ```typescript
|
|
33
|
-
* const MyConfigService = provideConfig({
|
|
34
|
-
* load: async () => {
|
|
35
|
-
* const config = await loadConfigFromFile('config.json')
|
|
36
|
-
* return config
|
|
37
|
-
* },
|
|
38
|
-
* })
|
|
39
|
-
*
|
|
40
|
-
* // Use in module setup
|
|
41
|
-
* container.bind(ConfigServiceToken).toFactory(configProvider)
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
|
-
export function provideConfig<ConfigMap extends ConfigServiceOptions>(
|
|
45
|
-
options: z.input<typeof ConfigProviderOptions>,
|
|
46
|
-
): FactoryInjectionToken<
|
|
47
|
-
ConfigService<ConfigMap>,
|
|
48
|
-
typeof ConfigServiceOptionsSchema
|
|
49
|
-
> {
|
|
50
|
-
return InjectionToken.factory(ConfigServiceToken, async () => options.load())
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Pre-configured ConfigService provider that uses environment variables.
|
|
55
|
-
*
|
|
56
|
-
* Provides a ConfigService instance bound to `process.env`.
|
|
57
|
-
*
|
|
58
|
-
* @example
|
|
59
|
-
* ```typescript
|
|
60
|
-
* // Use environment variables as configuration
|
|
61
|
-
* container.bind(ConfigServiceToken).toValue(EnvConfigProvider)
|
|
62
|
-
* ```
|
|
63
|
-
*/
|
|
64
|
-
export const EnvConfigProvider = InjectionToken.bound<
|
|
65
|
-
ConfigService<Record<string, string>>,
|
|
66
|
-
typeof ConfigServiceOptionsSchema
|
|
67
|
-
>(ConfigServiceToken, {
|
|
68
|
-
...env,
|
|
69
|
-
})
|
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
import { NaviosError } from '@navios/builder'
|
|
2
|
-
import { inject, Injectable, InjectionToken } from '@navios/di'
|
|
3
|
-
|
|
4
|
-
import { z } from 'zod/v4'
|
|
5
|
-
|
|
6
|
-
import type { ConfigServiceInterface as IConfigService } from './config-service.interface.mjs'
|
|
7
|
-
import type { Path, PathValue } from './types.mjs'
|
|
8
|
-
|
|
9
|
-
import { Logger } from '../logger/index.mjs'
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Schema for validating configuration service options.
|
|
13
|
-
*/
|
|
14
|
-
export const ConfigServiceOptionsSchema = z.record(z.string(), z.unknown())
|
|
15
|
-
/**
|
|
16
|
-
* Type for configuration service options.
|
|
17
|
-
*/
|
|
18
|
-
export type ConfigServiceOptions = z.infer<typeof ConfigServiceOptionsSchema>
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Injection token for ConfigService.
|
|
22
|
-
*/
|
|
23
|
-
export const ConfigServiceToken = InjectionToken.create<
|
|
24
|
-
IConfigService,
|
|
25
|
-
typeof ConfigServiceOptionsSchema
|
|
26
|
-
>(Symbol.for('ConfigService'), ConfigServiceOptionsSchema)
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Service for managing application configuration with type-safe access.
|
|
30
|
-
*
|
|
31
|
-
* Provides methods to access configuration values using dot-notation paths
|
|
32
|
-
* with full TypeScript type inference.
|
|
33
|
-
*
|
|
34
|
-
* @typeParam Config - The configuration object type
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* ```typescript
|
|
38
|
-
* interface AppConfig {
|
|
39
|
-
* database: {
|
|
40
|
-
* host: string
|
|
41
|
-
* port: number
|
|
42
|
-
* }
|
|
43
|
-
* api: {
|
|
44
|
-
* timeout: number
|
|
45
|
-
* }
|
|
46
|
-
* }
|
|
47
|
-
*
|
|
48
|
-
* @Injectable()
|
|
49
|
-
* export class DatabaseService {
|
|
50
|
-
* private config = inject(MyConfigService)
|
|
51
|
-
*
|
|
52
|
-
* connect() {
|
|
53
|
-
* const host = this.config.getOrThrow('database.host')
|
|
54
|
-
* const port = this.config.getOrDefault('database.port', 5432)
|
|
55
|
-
* // host is typed as string, port is typed as number
|
|
56
|
-
* }
|
|
57
|
-
* }
|
|
58
|
-
* ```
|
|
59
|
-
*/
|
|
60
|
-
@Injectable({
|
|
61
|
-
token: ConfigServiceToken,
|
|
62
|
-
})
|
|
63
|
-
export class ConfigService<
|
|
64
|
-
Config extends ConfigServiceOptions = Record<string, unknown>,
|
|
65
|
-
> implements IConfigService<Config> {
|
|
66
|
-
private readonly logger = inject(Logger, {
|
|
67
|
-
context: ConfigService.name,
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Creates a new ConfigService instance.
|
|
72
|
-
*
|
|
73
|
-
* @param config - The configuration object
|
|
74
|
-
*/
|
|
75
|
-
constructor(private config: Config = {} as Config) {}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Gets the entire configuration object.
|
|
79
|
-
*
|
|
80
|
-
* @returns The complete configuration object
|
|
81
|
-
*/
|
|
82
|
-
getConfig(): Config {
|
|
83
|
-
return this.config
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Gets a configuration value by key path.
|
|
88
|
-
*
|
|
89
|
-
* Returns `null` if the key is not found or if any part of the path is invalid.
|
|
90
|
-
*
|
|
91
|
-
* @param key - Dot-separated path to the configuration value (e.g., 'database.host')
|
|
92
|
-
* @returns The configuration value or `null` if not found
|
|
93
|
-
*
|
|
94
|
-
* @example
|
|
95
|
-
* ```typescript
|
|
96
|
-
* const host = config.get('database.host') // string | null
|
|
97
|
-
* const port = config.get('database.port') // number | null
|
|
98
|
-
* ```
|
|
99
|
-
*/
|
|
100
|
-
get<Key extends Path<Config>>(key: Key): PathValue<Config, Key> | null {
|
|
101
|
-
try {
|
|
102
|
-
const parts = String(key).split('.')
|
|
103
|
-
let value: any = this.config
|
|
104
|
-
|
|
105
|
-
for (const part of parts) {
|
|
106
|
-
if (
|
|
107
|
-
value === null ||
|
|
108
|
-
value === undefined ||
|
|
109
|
-
typeof value !== 'object'
|
|
110
|
-
) {
|
|
111
|
-
return null
|
|
112
|
-
}
|
|
113
|
-
value = value[part]
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
return (value as PathValue<Config, Key>) ?? null
|
|
117
|
-
} catch (error) {
|
|
118
|
-
this.logger.debug?.(
|
|
119
|
-
`Failed to get config value for key ${String(key)}`,
|
|
120
|
-
error,
|
|
121
|
-
)
|
|
122
|
-
return null
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Gets a configuration value by key path, or returns a default value if not found.
|
|
128
|
-
*
|
|
129
|
-
* @param key - Dot-separated path to the configuration value
|
|
130
|
-
* @param defaultValue - Default value to return if the key is not found
|
|
131
|
-
* @returns The configuration value or the default value
|
|
132
|
-
*
|
|
133
|
-
* @example
|
|
134
|
-
* ```typescript
|
|
135
|
-
* const port = config.getOrDefault('database.port', 5432) // number
|
|
136
|
-
* ```
|
|
137
|
-
*/
|
|
138
|
-
getOrDefault<Key extends Path<Config>>(
|
|
139
|
-
key: Key,
|
|
140
|
-
defaultValue: PathValue<Config, Key>,
|
|
141
|
-
): PathValue<Config, Key> {
|
|
142
|
-
const value = this.get(key)
|
|
143
|
-
return value !== null ? value : defaultValue
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Gets a configuration value by key path, or throws an error if not found.
|
|
148
|
-
*
|
|
149
|
-
* @param key - Dot-separated path to the configuration value
|
|
150
|
-
* @param errorMessage - Optional custom error message
|
|
151
|
-
* @returns The configuration value
|
|
152
|
-
* @throws Error if the key is not found
|
|
153
|
-
*
|
|
154
|
-
* @example
|
|
155
|
-
* ```typescript
|
|
156
|
-
* const host = config.getOrThrow('database.host') // string (throws if not found)
|
|
157
|
-
* const apiKey = config.getOrThrow('api.key', 'API key is required') // string
|
|
158
|
-
* ```
|
|
159
|
-
*/
|
|
160
|
-
getOrThrow<Key extends Path<Config>>(
|
|
161
|
-
key: Key,
|
|
162
|
-
errorMessage?: string,
|
|
163
|
-
): PathValue<Config, Key> {
|
|
164
|
-
const value = this.get(key)
|
|
165
|
-
|
|
166
|
-
if (value === null) {
|
|
167
|
-
const message =
|
|
168
|
-
errorMessage ||
|
|
169
|
-
`Configuration value for key "${String(key)}" is not defined`
|
|
170
|
-
this.logger.error(message)
|
|
171
|
-
throw new NaviosError(message)
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
return value
|
|
175
|
-
}
|
|
176
|
-
}
|
package/src/config/index.mts
DELETED
package/src/config/types.mts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Evaluates to `true` if `T` is `any`. `false` otherwise.
|
|
3
|
-
* (c) https://stackoverflow.com/a/68633327/5290447
|
|
4
|
-
*/
|
|
5
|
-
type IsAny<T> = unknown extends T
|
|
6
|
-
? [keyof T] extends [never]
|
|
7
|
-
? false
|
|
8
|
-
: true
|
|
9
|
-
: false
|
|
10
|
-
|
|
11
|
-
type ExcludedParts =
|
|
12
|
-
| 'services'
|
|
13
|
-
| 'mailer'
|
|
14
|
-
| 'aws'
|
|
15
|
-
| 'computedTimeRates'
|
|
16
|
-
| 'aiModelsRates'
|
|
17
|
-
type ExcludedKeys = 'computedTimeRates' | 'aiModelsRates' | 'aiModel'
|
|
18
|
-
|
|
19
|
-
export type PathImpl<T, Key extends keyof T> = Key extends string
|
|
20
|
-
? Key extends ExcludedKeys
|
|
21
|
-
? never
|
|
22
|
-
: IsAny<T[Key]> extends true
|
|
23
|
-
? never
|
|
24
|
-
: T[Key] extends string
|
|
25
|
-
? never
|
|
26
|
-
: T[Key] extends any[]
|
|
27
|
-
? never
|
|
28
|
-
: T[Key] extends Record<string, any>
|
|
29
|
-
? Key extends ExcludedParts
|
|
30
|
-
? `${Key}.${Exclude<keyof T[Key], keyof any[]> & string}`
|
|
31
|
-
:
|
|
32
|
-
| `${Key}.${PathImpl<T[Key], Exclude<keyof T[Key], keyof any[]>> & string}`
|
|
33
|
-
| `${Key}.${Exclude<keyof T[Key], keyof any[]> & string}`
|
|
34
|
-
: never
|
|
35
|
-
: never
|
|
36
|
-
|
|
37
|
-
export type PathImpl2<T> = PathImpl<T, keyof T> | keyof T
|
|
38
|
-
|
|
39
|
-
export type Path<T> = keyof T extends string
|
|
40
|
-
? PathImpl2<T> extends infer P
|
|
41
|
-
? P extends string | keyof T
|
|
42
|
-
? P
|
|
43
|
-
: keyof T
|
|
44
|
-
: keyof T
|
|
45
|
-
: never
|
|
46
|
-
|
|
47
|
-
export type PathValue<
|
|
48
|
-
T,
|
|
49
|
-
P extends Path<T>,
|
|
50
|
-
> = P extends `${infer Key}.${infer Rest}`
|
|
51
|
-
? Key extends keyof T
|
|
52
|
-
? Rest extends Path<T[Key]>
|
|
53
|
-
? PathValue<T[Key], Rest>
|
|
54
|
-
: never
|
|
55
|
-
: never
|
|
56
|
-
: P extends keyof T
|
|
57
|
-
? T[P]
|
|
58
|
-
: never
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { env } from 'node:process'
|
|
2
|
-
|
|
3
|
-
export function envInt(
|
|
4
|
-
key: keyof NodeJS.ProcessEnv,
|
|
5
|
-
defaultValue: number,
|
|
6
|
-
): number {
|
|
7
|
-
const envKey = env[key] || process.env[key]
|
|
8
|
-
|
|
9
|
-
return envKey ? parseInt(envKey as string, 10) : defaultValue
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function envString<
|
|
13
|
-
DefaultValue extends string | undefined,
|
|
14
|
-
Ensured = DefaultValue extends string ? true : false,
|
|
15
|
-
>(
|
|
16
|
-
key: keyof NodeJS.ProcessEnv,
|
|
17
|
-
defaultValue?: DefaultValue,
|
|
18
|
-
): Ensured extends true ? string : string | undefined {
|
|
19
|
-
return (env[key] ||
|
|
20
|
-
process.env[key] ||
|
|
21
|
-
defaultValue ||
|
|
22
|
-
undefined) as Ensured extends true ? string : string | undefined
|
|
23
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './helpers.mjs'
|