@navios/core 1.1.0 → 2.0.0-alpha.1
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 +85 -13
- package/README.md +69 -220
- package/lib/async-context-BAdt7bno.d.mts +239 -0
- package/lib/async-context-BAdt7bno.d.mts.map +1 -0
- package/lib/async-context-RsWmy2Hi.d.cts +239 -0
- package/lib/async-context-RsWmy2Hi.d.cts.map +1 -0
- package/lib/attribute-factory-BW1kgBqf.d.mts +70 -0
- package/lib/attribute-factory-BW1kgBqf.d.mts.map +1 -0
- package/lib/attribute-factory-DqN4x5XM.d.cts +70 -0
- package/lib/attribute-factory-DqN4x5XM.d.cts.map +1 -0
- package/lib/attribute-value-BNiJjxl1.mjs +225 -0
- package/lib/attribute-value-BNiJjxl1.mjs.map +1 -0
- package/lib/attribute-value-Cux5HhOL.cjs +314 -0
- package/lib/attribute-value-Cux5HhOL.cjs.map +1 -0
- package/lib/basic-execution-context-5uq2DvEA.cjs +318 -0
- package/lib/basic-execution-context-5uq2DvEA.cjs.map +1 -0
- package/lib/basic-execution-context-u1VktGoM.mjs +277 -0
- package/lib/basic-execution-context-u1VktGoM.mjs.map +1 -0
- package/lib/execution-context-BVSmLkYp.d.cts +71 -0
- package/lib/execution-context-BVSmLkYp.d.cts.map +1 -0
- package/lib/execution-context-C5F9rojO.d.mts +71 -0
- package/lib/execution-context-C5F9rojO.d.mts.map +1 -0
- package/lib/execution-context-token--cKS4cJv.cjs +270 -0
- package/lib/execution-context-token--cKS4cJv.cjs.map +1 -0
- package/lib/execution-context-token-Cb3M3Ao0.mjs +223 -0
- package/lib/execution-context-token-Cb3M3Ao0.mjs.map +1 -0
- package/lib/index.cjs +1672 -4426
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +842 -3
- package/lib/index.d.cts.map +1 -0
- package/lib/index.d.mts +842 -3
- package/lib/index.d.mts.map +1 -0
- package/lib/index.mjs +1559 -4221
- 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-Bz83ZnJ5.cjs +173 -0
- package/lib/module-Bz83ZnJ5.cjs.map +1 -0
- package/lib/module-options-CSqQUSTm.d.mts +51 -0
- package/lib/module-options-CSqQUSTm.d.mts.map +1 -0
- package/lib/module-options-DSRBri4J.d.cts +51 -0
- package/lib/module-options-DSRBri4J.d.cts.map +1 -0
- package/lib/module-zPXwR2qp.mjs +138 -0
- package/lib/module-zPXwR2qp.mjs.map +1 -0
- package/lib/settled-within-B6gpu2XW.cjs +32 -0
- package/lib/settled-within-B6gpu2XW.cjs.map +1 -0
- package/lib/settled-within-Bc2pj8WB.mjs +21 -0
- package/lib/settled-within-Bc2pj8WB.mjs.map +1 -0
- package/lib/testing/index.cjs +74 -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 +72 -408
- package/lib/testing/index.mjs.map +1 -1
- package/lib/transport.cjs +36 -0
- package/lib/transport.d.cts +254 -0
- package/lib/transport.d.cts.map +1 -0
- package/lib/transport.d.mts +254 -0
- package/lib/transport.d.mts.map +1 -0
- package/lib/transport.mjs +6 -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
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { n as ExecutionContext } from "./execution-context-C5F9rojO.mjs";
|
|
2
|
+
import { AnyInjectableType, ClassType, Container, InjectionToken, Provider } from "@navios/di";
|
|
3
|
+
/**
|
|
4
|
+
* Available log levels in order of severity (lowest to highest).
|
|
5
|
+
*/
|
|
6
|
+
declare const LOG_LEVELS: ["verbose", "debug", "log", "warn", "error", "fatal"];
|
|
7
|
+
/**
|
|
8
|
+
* Log level type.
|
|
9
|
+
*
|
|
10
|
+
* Represents the severity level of a log message.
|
|
11
|
+
* Levels are: 'verbose', 'debug', 'log', 'warn', 'error', 'fatal'
|
|
12
|
+
*
|
|
13
|
+
* @publicApi
|
|
14
|
+
*/
|
|
15
|
+
type LogLevel = (typeof LOG_LEVELS)[number];
|
|
16
|
+
/**
|
|
17
|
+
* Reads log levels out of a setting: `'error'`, `'warn,error'`, `'>=warn'` or
|
|
18
|
+
* `'>warn'`. An empty string stands for every level.
|
|
19
|
+
* @publicApi
|
|
20
|
+
*/
|
|
21
|
+
declare function filterLogLevels(parseableString?: string): LogLevel[];
|
|
22
|
+
/**
|
|
23
|
+
* @publicApi
|
|
24
|
+
*/
|
|
25
|
+
interface LoggerService {
|
|
26
|
+
/**
|
|
27
|
+
* Write a 'log' level log.
|
|
28
|
+
*/
|
|
29
|
+
log(message: any, ...optionalParams: any[]): any;
|
|
30
|
+
/**
|
|
31
|
+
* Write an 'error' level log.
|
|
32
|
+
*/
|
|
33
|
+
error(message: any, ...optionalParams: any[]): any;
|
|
34
|
+
/**
|
|
35
|
+
* Write a 'warn' level log.
|
|
36
|
+
*/
|
|
37
|
+
warn(message: any, ...optionalParams: any[]): any;
|
|
38
|
+
/**
|
|
39
|
+
* Write a 'debug' level log.
|
|
40
|
+
*/
|
|
41
|
+
debug?(message: any, ...optionalParams: any[]): any;
|
|
42
|
+
/**
|
|
43
|
+
* Write a 'verbose' level log.
|
|
44
|
+
*/
|
|
45
|
+
verbose?(message: any, ...optionalParams: any[]): any;
|
|
46
|
+
/**
|
|
47
|
+
* Write a 'fatal' level log.
|
|
48
|
+
*/
|
|
49
|
+
fatal?(message: any, ...optionalParams: any[]): any;
|
|
50
|
+
/**
|
|
51
|
+
* Set log levels.
|
|
52
|
+
* @param levels log levels
|
|
53
|
+
*/
|
|
54
|
+
setLogLevels?(levels: LogLevel[]): any;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Injection token for the logger output service.
|
|
58
|
+
*
|
|
59
|
+
* This token is used to provide a custom logger implementation.
|
|
60
|
+
* By default, it's bound to ConsoleLogger.
|
|
61
|
+
*/
|
|
62
|
+
declare const LoggerOutput: InjectionToken<LoggerService, undefined, false>;
|
|
63
|
+
/**
|
|
64
|
+
* The parameters of a function that takes options: they may be left out when
|
|
65
|
+
* none of them is required.
|
|
66
|
+
*/
|
|
67
|
+
type OptionsArgument<Options, Rest extends unknown[] = []> = {} extends Options ? [options?: Options, ...rest: Rest] : [options: Options, ...rest: Rest];
|
|
68
|
+
/**
|
|
69
|
+
* Dependencies shared by every execution context of an application.
|
|
70
|
+
*/
|
|
71
|
+
interface ContextHost {
|
|
72
|
+
readonly container: Container;
|
|
73
|
+
/**
|
|
74
|
+
* Called when a context resolves a token that `needsScope` is true for; may
|
|
75
|
+
* throw.
|
|
76
|
+
*/
|
|
77
|
+
onScopedUse: ((token: AnyInjectableType) => void) | null;
|
|
78
|
+
/** Receives what an `onFinish` callback throws; without it that is dropped. */
|
|
79
|
+
readonly logger?: Pick<LoggerService, 'error'>;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Whether a context resolves `token` from a DI scope of its execution. A
|
|
83
|
+
* singleton is the same in all of them.
|
|
84
|
+
*/
|
|
85
|
+
declare function needsScope(container: Container, token: AnyInjectableType): boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Builds the host for an application's contexts, applying its policy for
|
|
88
|
+
* request-scoped services.
|
|
89
|
+
*/
|
|
90
|
+
declare function createContextHost(container: Container, mode: 'allow' | 'warn' | 'forbid', logger: LoggerService): ContextHost;
|
|
91
|
+
/**
|
|
92
|
+
* A module as it applies to one application: its guards, interceptors and
|
|
93
|
+
* attributes together with those it inherits, and the modules that import it.
|
|
94
|
+
*/
|
|
95
|
+
interface ModuleNode {
|
|
96
|
+
module: ClassType;
|
|
97
|
+
providers: Provider[];
|
|
98
|
+
/** The module's transport-specific options, by option name. */
|
|
99
|
+
entries: ReadonlyMap<string, unknown>;
|
|
100
|
+
guards: ClassType[];
|
|
101
|
+
interceptors: ClassType[];
|
|
102
|
+
attributes: Map<symbol, unknown>;
|
|
103
|
+
/**
|
|
104
|
+
* The attributes that the importers of the module do not agree about, and what
|
|
105
|
+
* each of two import paths gives it. They are not among `attributes`;
|
|
106
|
+
* `handlerChain` refuses a handler that would inherit one.
|
|
107
|
+
*/
|
|
108
|
+
disputed: ReadonlyMap<symbol, string>;
|
|
109
|
+
/** The modules that import this one, in the order they were reached. */
|
|
110
|
+
importers: ModuleNode[];
|
|
111
|
+
/** Whether the module was given to the application directly. */
|
|
112
|
+
isRoot: boolean;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* The classes a module lists under one of the options of a transport, once
|
|
116
|
+
* each. Throws for an entry that is not a class: what an import cycle between
|
|
117
|
+
* the files of two classes leaves behind.
|
|
118
|
+
*/
|
|
119
|
+
declare function moduleClasses(node: Pick<ModuleNode, 'module' | 'entries'>, entry: string): ClassType[];
|
|
120
|
+
/**
|
|
121
|
+
* Walks the import graph from the given roots and computes, for this
|
|
122
|
+
* application only, what applies to each module.
|
|
123
|
+
*
|
|
124
|
+
* - Guards and interceptors are the union over every path that reaches a
|
|
125
|
+
* module, outermost first: what the importers contribute, importers in
|
|
126
|
+
* import order, then the module's own. Nothing is written back to the
|
|
127
|
+
* classes, so two applications importing one module under different parents
|
|
128
|
+
* do not affect each other.
|
|
129
|
+
* - An attribute comes from the module itself or else from what imports it.
|
|
130
|
+
* One that the importers do not agree about is in `disputed` instead.
|
|
131
|
+
*
|
|
132
|
+
* Neither depends on the order in which a module happens to be reached.
|
|
133
|
+
* Modules are returned in dependency order: a module comes after everything
|
|
134
|
+
* it imports. That cannot be done for modules that import each other, which is
|
|
135
|
+
* an error as well.
|
|
136
|
+
*/
|
|
137
|
+
declare function buildModuleGraph(roots: ClassType[]): ModuleNode[];
|
|
138
|
+
/**
|
|
139
|
+
* What the application gives a transport when it creates it.
|
|
140
|
+
*/
|
|
141
|
+
interface TransportHost {
|
|
142
|
+
readonly container: Container;
|
|
143
|
+
readonly logger: LoggerService;
|
|
144
|
+
/** For the transport's execution contexts. */
|
|
145
|
+
readonly contextHost: ContextHost;
|
|
146
|
+
/** Whether the application keeps the current context in an async store. */
|
|
147
|
+
readonly asyncContext: boolean;
|
|
148
|
+
/**
|
|
149
|
+
* Interceptors around every handler of the application, outermost first.
|
|
150
|
+
* Complete once `setup()` is called.
|
|
151
|
+
*/
|
|
152
|
+
readonly interceptors: readonly ClassType[];
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* One way work reaches the application: an HTTP server, a queue consumer, a
|
|
156
|
+
* command line. The application creates it, hands it the module graph, and
|
|
157
|
+
* starts and stops it together with the others.
|
|
158
|
+
*/
|
|
159
|
+
interface Transport {
|
|
160
|
+
/**
|
|
161
|
+
* Reads the module graph and prepares the transport's handlers. Must not
|
|
162
|
+
* start accepting work.
|
|
163
|
+
*/
|
|
164
|
+
setup(graph: readonly ModuleNode[]): void | Promise<void>;
|
|
165
|
+
/** Starts accepting work. Called at most once. */
|
|
166
|
+
start?(): void | Promise<void>;
|
|
167
|
+
/**
|
|
168
|
+
* Stops accepting work and waits, up to `timeoutMs`, for what is in flight.
|
|
169
|
+
* One that takes much longer is left behind. When the application fails to
|
|
170
|
+
* initialise or to start it is called for every transport that was created,
|
|
171
|
+
* with no time to wait and possibly before `setup` or `start` ran; it must
|
|
172
|
+
* release what `create` acquired. Called once, and again when `start` settles
|
|
173
|
+
* only after that.
|
|
174
|
+
*/
|
|
175
|
+
stop(timeoutMs: number): void | Promise<void>;
|
|
176
|
+
}
|
|
177
|
+
interface TransportDefinition<Options, T extends Transport> {
|
|
178
|
+
/** The kind of transport, and the default name of an instance. */
|
|
179
|
+
name: string;
|
|
180
|
+
create(host: TransportHost, options: Options): T | Promise<T>;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* A transport as it is listed in an application's options.
|
|
184
|
+
*/
|
|
185
|
+
interface TransportInstance<T extends Transport = Transport> {
|
|
186
|
+
readonly definition: TransportDefinition<any, T>;
|
|
187
|
+
/** `{}` when the transport was given none. */
|
|
188
|
+
readonly options: unknown;
|
|
189
|
+
/** Unique within the application. Defaults to the definition's name. */
|
|
190
|
+
readonly instanceName: string;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* What `defineTransport` returns: called with options it gives the instance
|
|
194
|
+
* to list in an application, and it is the key to look the transport up with.
|
|
195
|
+
*/
|
|
196
|
+
interface TransportFactory<Options, T extends Transport> {
|
|
197
|
+
(...args: OptionsArgument<Options, [instanceName?: string]>): TransportInstance<T>;
|
|
198
|
+
readonly definition: TransportDefinition<Options, T>;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Defines a transport.
|
|
202
|
+
*
|
|
203
|
+
* ```ts
|
|
204
|
+
* export const queueTransport = defineTransport({
|
|
205
|
+
* name: 'queue',
|
|
206
|
+
* create(host, options: { url: string }) {
|
|
207
|
+
* return new QueueTransport(host, options)
|
|
208
|
+
* },
|
|
209
|
+
* })
|
|
210
|
+
*
|
|
211
|
+
* const app = createApplication(AppModule, {
|
|
212
|
+
* transports: [queueTransport({ url })],
|
|
213
|
+
* })
|
|
214
|
+
* await app.start()
|
|
215
|
+
* app.transport(queueTransport) // the QueueTransport
|
|
216
|
+
* ```
|
|
217
|
+
*
|
|
218
|
+
* An application can hold several transports of one definition when each has
|
|
219
|
+
* its own name: `queueTransport({ url }, 'orders')`.
|
|
220
|
+
*/
|
|
221
|
+
declare function defineTransport<Options = void, T extends Transport = Transport>(definition: TransportDefinition<Options, T>): TransportFactory<Options, T>;
|
|
222
|
+
/**
|
|
223
|
+
* Turns on the async context: one `AsyncLocalStorage` holding the current
|
|
224
|
+
* `ExecutionContext`. The `asyncContext: true` option of an application does it.
|
|
225
|
+
*/
|
|
226
|
+
declare function enableAsyncContext(): Promise<void>;
|
|
227
|
+
/**
|
|
228
|
+
* Runs `fn` with `ctx` as the current context. A transport does this when its
|
|
229
|
+
* host says that the application has an async context.
|
|
230
|
+
*/
|
|
231
|
+
declare function runInContext<R>(ctx: ExecutionContext, fn: () => R): R;
|
|
232
|
+
/**
|
|
233
|
+
* The context of the handler being run, for code that cannot receive it as an
|
|
234
|
+
* argument. Returns `undefined` outside a handler, and always when the
|
|
235
|
+
* application was not created with `asyncContext: true`.
|
|
236
|
+
*/
|
|
237
|
+
declare function currentContext(): ExecutionContext | undefined;
|
|
238
|
+
export { LoggerOutput as _, TransportDefinition as a, LogLevel as b, TransportInstance as c, buildModuleGraph as d, moduleClasses as f, OptionsArgument as g, needsScope as h, Transport as i, defineTransport as l, createContextHost as m, enableAsyncContext as n, TransportFactory as o, ContextHost as p, runInContext as r, TransportHost as s, currentContext as t, ModuleNode as u, LoggerService as v, filterLogLevels as x, LOG_LEVELS as y };
|
|
239
|
+
//# sourceMappingURL=async-context-BAdt7bno.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async-context-BAdt7bno.d.mts","names":[],"sources":["../src/logger/log-levels.mts","../src/logger/logger-output.mts","../src/internal/options-argument.mts","../src/execution/context-host.mts","../src/modules/module-graph.mts","../src/transports/transport.mts","../src/execution/async-context.mts"],"mappings":";;;;;cAGa;;;;;;;;;KAiBD,mBAAmB;;;;;;iBAkDf,gBAAgB,2BAAuB;;;;UC/DtC;;;;EAIf,IAAI,iBAAiB;;;;EAKrB,MAAM,iBAAiB;;;;EAKvB,KAAK,iBAAiB;;;;EAKtB,OAAO,iBAAiB;;;;EAKxB,SAAS,iBAAiB;;;;EAK1B,OAAO,iBAAiB;;;;;EAMxB,cAAc,QAAQ;;;;;;;;cASX,cAAY,eAAA;;;;;KC/Cb,gBAAgB,SAAS,0CAA0C,WAC1E,UAAU,YAAY,MAAM,SAC5B,SAAS,YAAY,MAAM;;;;UCGf;WACN,WAAW;;;;;EAKpB,eAAe,OAAO;;WAEb,SAAS,KAAK;;;;;;iBAsBT,WAAW,WAAW,WAAW,OAAO;;;;;iBAQxC,kBACd,WAAW,WACX,mCACA,QAAQ,gBACP;;;;;UCrCc;EACf,QAAQ;EACR,WAAW;;EAEX,SAAS;EACT,QAAQ;EACR,cAAc;EACd,YAAY;;;;;;EAMZ,UAAU;;EAEV,WAAW;;EAEX;;;;;;;iBAQc,cACd,MAAM,KAAK,mCACX,gBACC;;;;;;;;;;;;;;;;;;iBAqHa,iBAAiB,OAAO,cAAc;;;;UCnJrC;WACN,WAAW;WACX,QAAQ;;WAER,aAAa;;WAEb;;;;;WAKA,uBAAuB;;;;;;;UAQjB;;;;;EAKf,MAAM,gBAAgB,sBAAsB;;EAE5C,iBAAiB;;;;;;;;;EASjB,KAAK,2BAA2B;;UAGjB,oBAAoB,SAAS,UAAU;;EAEtD;EACA,OAAO,MAAM,eAAe,SAAS,UAAU,IAAI,QAAQ;;;;;UAM5C,kBAAkB,UAAU,YAAY;WAC9C,YAAY,yBAAyB;;WAErC;;WAEA;;;;;;UAOM,iBAAiB,SAAS,UAAU;MAC/C,MAAM,gBAAgB,UAAU,0BAA0B,kBAAkB;WACvE,YAAY,oBAAoB,SAAS;;;;;;;;;;;;;;;;;;;;;;;iBAwBpC,gBAAgB,gBAAgB,UAAU,YAAY,WACpE,YAAY,oBAAoB,SAAS,KACxC,iBAAiB,SAAS;;;;;iBCtFP,sBAAsB;;;;;iBAW5B,aAAa,GAAG,KAAK,kBAAkB,UAAU,IAAI;;;;;;iBASrD,kBAAkB"}
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { n as ExecutionContext } from "./execution-context-BVSmLkYp.cjs";
|
|
2
|
+
import { AnyInjectableType, ClassType, Container, InjectionToken, Provider } from "@navios/di";
|
|
3
|
+
/**
|
|
4
|
+
* Available log levels in order of severity (lowest to highest).
|
|
5
|
+
*/
|
|
6
|
+
declare const LOG_LEVELS: ["verbose", "debug", "log", "warn", "error", "fatal"];
|
|
7
|
+
/**
|
|
8
|
+
* Log level type.
|
|
9
|
+
*
|
|
10
|
+
* Represents the severity level of a log message.
|
|
11
|
+
* Levels are: 'verbose', 'debug', 'log', 'warn', 'error', 'fatal'
|
|
12
|
+
*
|
|
13
|
+
* @publicApi
|
|
14
|
+
*/
|
|
15
|
+
type LogLevel = (typeof LOG_LEVELS)[number];
|
|
16
|
+
/**
|
|
17
|
+
* Reads log levels out of a setting: `'error'`, `'warn,error'`, `'>=warn'` or
|
|
18
|
+
* `'>warn'`. An empty string stands for every level.
|
|
19
|
+
* @publicApi
|
|
20
|
+
*/
|
|
21
|
+
declare function filterLogLevels(parseableString?: string): LogLevel[];
|
|
22
|
+
/**
|
|
23
|
+
* @publicApi
|
|
24
|
+
*/
|
|
25
|
+
interface LoggerService {
|
|
26
|
+
/**
|
|
27
|
+
* Write a 'log' level log.
|
|
28
|
+
*/
|
|
29
|
+
log(message: any, ...optionalParams: any[]): any;
|
|
30
|
+
/**
|
|
31
|
+
* Write an 'error' level log.
|
|
32
|
+
*/
|
|
33
|
+
error(message: any, ...optionalParams: any[]): any;
|
|
34
|
+
/**
|
|
35
|
+
* Write a 'warn' level log.
|
|
36
|
+
*/
|
|
37
|
+
warn(message: any, ...optionalParams: any[]): any;
|
|
38
|
+
/**
|
|
39
|
+
* Write a 'debug' level log.
|
|
40
|
+
*/
|
|
41
|
+
debug?(message: any, ...optionalParams: any[]): any;
|
|
42
|
+
/**
|
|
43
|
+
* Write a 'verbose' level log.
|
|
44
|
+
*/
|
|
45
|
+
verbose?(message: any, ...optionalParams: any[]): any;
|
|
46
|
+
/**
|
|
47
|
+
* Write a 'fatal' level log.
|
|
48
|
+
*/
|
|
49
|
+
fatal?(message: any, ...optionalParams: any[]): any;
|
|
50
|
+
/**
|
|
51
|
+
* Set log levels.
|
|
52
|
+
* @param levels log levels
|
|
53
|
+
*/
|
|
54
|
+
setLogLevels?(levels: LogLevel[]): any;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Injection token for the logger output service.
|
|
58
|
+
*
|
|
59
|
+
* This token is used to provide a custom logger implementation.
|
|
60
|
+
* By default, it's bound to ConsoleLogger.
|
|
61
|
+
*/
|
|
62
|
+
declare const LoggerOutput: InjectionToken<LoggerService, undefined, false>;
|
|
63
|
+
/**
|
|
64
|
+
* The parameters of a function that takes options: they may be left out when
|
|
65
|
+
* none of them is required.
|
|
66
|
+
*/
|
|
67
|
+
type OptionsArgument<Options, Rest extends unknown[] = []> = {} extends Options ? [options?: Options, ...rest: Rest] : [options: Options, ...rest: Rest];
|
|
68
|
+
/**
|
|
69
|
+
* Dependencies shared by every execution context of an application.
|
|
70
|
+
*/
|
|
71
|
+
interface ContextHost {
|
|
72
|
+
readonly container: Container;
|
|
73
|
+
/**
|
|
74
|
+
* Called when a context resolves a token that `needsScope` is true for; may
|
|
75
|
+
* throw.
|
|
76
|
+
*/
|
|
77
|
+
onScopedUse: ((token: AnyInjectableType) => void) | null;
|
|
78
|
+
/** Receives what an `onFinish` callback throws; without it that is dropped. */
|
|
79
|
+
readonly logger?: Pick<LoggerService, 'error'>;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Whether a context resolves `token` from a DI scope of its execution. A
|
|
83
|
+
* singleton is the same in all of them.
|
|
84
|
+
*/
|
|
85
|
+
declare function needsScope(container: Container, token: AnyInjectableType): boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Builds the host for an application's contexts, applying its policy for
|
|
88
|
+
* request-scoped services.
|
|
89
|
+
*/
|
|
90
|
+
declare function createContextHost(container: Container, mode: 'allow' | 'warn' | 'forbid', logger: LoggerService): ContextHost;
|
|
91
|
+
/**
|
|
92
|
+
* A module as it applies to one application: its guards, interceptors and
|
|
93
|
+
* attributes together with those it inherits, and the modules that import it.
|
|
94
|
+
*/
|
|
95
|
+
interface ModuleNode {
|
|
96
|
+
module: ClassType;
|
|
97
|
+
providers: Provider[];
|
|
98
|
+
/** The module's transport-specific options, by option name. */
|
|
99
|
+
entries: ReadonlyMap<string, unknown>;
|
|
100
|
+
guards: ClassType[];
|
|
101
|
+
interceptors: ClassType[];
|
|
102
|
+
attributes: Map<symbol, unknown>;
|
|
103
|
+
/**
|
|
104
|
+
* The attributes that the importers of the module do not agree about, and what
|
|
105
|
+
* each of two import paths gives it. They are not among `attributes`;
|
|
106
|
+
* `handlerChain` refuses a handler that would inherit one.
|
|
107
|
+
*/
|
|
108
|
+
disputed: ReadonlyMap<symbol, string>;
|
|
109
|
+
/** The modules that import this one, in the order they were reached. */
|
|
110
|
+
importers: ModuleNode[];
|
|
111
|
+
/** Whether the module was given to the application directly. */
|
|
112
|
+
isRoot: boolean;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* The classes a module lists under one of the options of a transport, once
|
|
116
|
+
* each. Throws for an entry that is not a class: what an import cycle between
|
|
117
|
+
* the files of two classes leaves behind.
|
|
118
|
+
*/
|
|
119
|
+
declare function moduleClasses(node: Pick<ModuleNode, 'module' | 'entries'>, entry: string): ClassType[];
|
|
120
|
+
/**
|
|
121
|
+
* Walks the import graph from the given roots and computes, for this
|
|
122
|
+
* application only, what applies to each module.
|
|
123
|
+
*
|
|
124
|
+
* - Guards and interceptors are the union over every path that reaches a
|
|
125
|
+
* module, outermost first: what the importers contribute, importers in
|
|
126
|
+
* import order, then the module's own. Nothing is written back to the
|
|
127
|
+
* classes, so two applications importing one module under different parents
|
|
128
|
+
* do not affect each other.
|
|
129
|
+
* - An attribute comes from the module itself or else from what imports it.
|
|
130
|
+
* One that the importers do not agree about is in `disputed` instead.
|
|
131
|
+
*
|
|
132
|
+
* Neither depends on the order in which a module happens to be reached.
|
|
133
|
+
* Modules are returned in dependency order: a module comes after everything
|
|
134
|
+
* it imports. That cannot be done for modules that import each other, which is
|
|
135
|
+
* an error as well.
|
|
136
|
+
*/
|
|
137
|
+
declare function buildModuleGraph(roots: ClassType[]): ModuleNode[];
|
|
138
|
+
/**
|
|
139
|
+
* What the application gives a transport when it creates it.
|
|
140
|
+
*/
|
|
141
|
+
interface TransportHost {
|
|
142
|
+
readonly container: Container;
|
|
143
|
+
readonly logger: LoggerService;
|
|
144
|
+
/** For the transport's execution contexts. */
|
|
145
|
+
readonly contextHost: ContextHost;
|
|
146
|
+
/** Whether the application keeps the current context in an async store. */
|
|
147
|
+
readonly asyncContext: boolean;
|
|
148
|
+
/**
|
|
149
|
+
* Interceptors around every handler of the application, outermost first.
|
|
150
|
+
* Complete once `setup()` is called.
|
|
151
|
+
*/
|
|
152
|
+
readonly interceptors: readonly ClassType[];
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* One way work reaches the application: an HTTP server, a queue consumer, a
|
|
156
|
+
* command line. The application creates it, hands it the module graph, and
|
|
157
|
+
* starts and stops it together with the others.
|
|
158
|
+
*/
|
|
159
|
+
interface Transport {
|
|
160
|
+
/**
|
|
161
|
+
* Reads the module graph and prepares the transport's handlers. Must not
|
|
162
|
+
* start accepting work.
|
|
163
|
+
*/
|
|
164
|
+
setup(graph: readonly ModuleNode[]): void | Promise<void>;
|
|
165
|
+
/** Starts accepting work. Called at most once. */
|
|
166
|
+
start?(): void | Promise<void>;
|
|
167
|
+
/**
|
|
168
|
+
* Stops accepting work and waits, up to `timeoutMs`, for what is in flight.
|
|
169
|
+
* One that takes much longer is left behind. When the application fails to
|
|
170
|
+
* initialise or to start it is called for every transport that was created,
|
|
171
|
+
* with no time to wait and possibly before `setup` or `start` ran; it must
|
|
172
|
+
* release what `create` acquired. Called once, and again when `start` settles
|
|
173
|
+
* only after that.
|
|
174
|
+
*/
|
|
175
|
+
stop(timeoutMs: number): void | Promise<void>;
|
|
176
|
+
}
|
|
177
|
+
interface TransportDefinition<Options, T extends Transport> {
|
|
178
|
+
/** The kind of transport, and the default name of an instance. */
|
|
179
|
+
name: string;
|
|
180
|
+
create(host: TransportHost, options: Options): T | Promise<T>;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* A transport as it is listed in an application's options.
|
|
184
|
+
*/
|
|
185
|
+
interface TransportInstance<T extends Transport = Transport> {
|
|
186
|
+
readonly definition: TransportDefinition<any, T>;
|
|
187
|
+
/** `{}` when the transport was given none. */
|
|
188
|
+
readonly options: unknown;
|
|
189
|
+
/** Unique within the application. Defaults to the definition's name. */
|
|
190
|
+
readonly instanceName: string;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* What `defineTransport` returns: called with options it gives the instance
|
|
194
|
+
* to list in an application, and it is the key to look the transport up with.
|
|
195
|
+
*/
|
|
196
|
+
interface TransportFactory<Options, T extends Transport> {
|
|
197
|
+
(...args: OptionsArgument<Options, [instanceName?: string]>): TransportInstance<T>;
|
|
198
|
+
readonly definition: TransportDefinition<Options, T>;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Defines a transport.
|
|
202
|
+
*
|
|
203
|
+
* ```ts
|
|
204
|
+
* export const queueTransport = defineTransport({
|
|
205
|
+
* name: 'queue',
|
|
206
|
+
* create(host, options: { url: string }) {
|
|
207
|
+
* return new QueueTransport(host, options)
|
|
208
|
+
* },
|
|
209
|
+
* })
|
|
210
|
+
*
|
|
211
|
+
* const app = createApplication(AppModule, {
|
|
212
|
+
* transports: [queueTransport({ url })],
|
|
213
|
+
* })
|
|
214
|
+
* await app.start()
|
|
215
|
+
* app.transport(queueTransport) // the QueueTransport
|
|
216
|
+
* ```
|
|
217
|
+
*
|
|
218
|
+
* An application can hold several transports of one definition when each has
|
|
219
|
+
* its own name: `queueTransport({ url }, 'orders')`.
|
|
220
|
+
*/
|
|
221
|
+
declare function defineTransport<Options = void, T extends Transport = Transport>(definition: TransportDefinition<Options, T>): TransportFactory<Options, T>;
|
|
222
|
+
/**
|
|
223
|
+
* Turns on the async context: one `AsyncLocalStorage` holding the current
|
|
224
|
+
* `ExecutionContext`. The `asyncContext: true` option of an application does it.
|
|
225
|
+
*/
|
|
226
|
+
declare function enableAsyncContext(): Promise<void>;
|
|
227
|
+
/**
|
|
228
|
+
* Runs `fn` with `ctx` as the current context. A transport does this when its
|
|
229
|
+
* host says that the application has an async context.
|
|
230
|
+
*/
|
|
231
|
+
declare function runInContext<R>(ctx: ExecutionContext, fn: () => R): R;
|
|
232
|
+
/**
|
|
233
|
+
* The context of the handler being run, for code that cannot receive it as an
|
|
234
|
+
* argument. Returns `undefined` outside a handler, and always when the
|
|
235
|
+
* application was not created with `asyncContext: true`.
|
|
236
|
+
*/
|
|
237
|
+
declare function currentContext(): ExecutionContext | undefined;
|
|
238
|
+
export { LoggerOutput as _, TransportDefinition as a, LogLevel as b, TransportInstance as c, buildModuleGraph as d, moduleClasses as f, OptionsArgument as g, needsScope as h, Transport as i, defineTransport as l, createContextHost as m, enableAsyncContext as n, TransportFactory as o, ContextHost as p, runInContext as r, TransportHost as s, currentContext as t, ModuleNode as u, LoggerService as v, filterLogLevels as x, LOG_LEVELS as y };
|
|
239
|
+
//# sourceMappingURL=async-context-RsWmy2Hi.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async-context-RsWmy2Hi.d.cts","names":[],"sources":["../src/logger/log-levels.mts","../src/logger/logger-output.mts","../src/internal/options-argument.mts","../src/execution/context-host.mts","../src/modules/module-graph.mts","../src/transports/transport.mts","../src/execution/async-context.mts"],"mappings":";;;;;cAGa;;;;;;;;;KAiBD,mBAAmB;;;;;;iBAkDf,gBAAgB,2BAAuB;;;;UC/DtC;;;;EAIf,IAAI,iBAAiB;;;;EAKrB,MAAM,iBAAiB;;;;EAKvB,KAAK,iBAAiB;;;;EAKtB,OAAO,iBAAiB;;;;EAKxB,SAAS,iBAAiB;;;;EAK1B,OAAO,iBAAiB;;;;;EAMxB,cAAc,QAAQ;;;;;;;;cASX,cAAY,eAAA;;;;;KC/Cb,gBAAgB,SAAS,0CAA0C,WAC1E,UAAU,YAAY,MAAM,SAC5B,SAAS,YAAY,MAAM;;;;UCGf;WACN,WAAW;;;;;EAKpB,eAAe,OAAO;;WAEb,SAAS,KAAK;;;;;;iBAsBT,WAAW,WAAW,WAAW,OAAO;;;;;iBAQxC,kBACd,WAAW,WACX,mCACA,QAAQ,gBACP;;;;;UCrCc;EACf,QAAQ;EACR,WAAW;;EAEX,SAAS;EACT,QAAQ;EACR,cAAc;EACd,YAAY;;;;;;EAMZ,UAAU;;EAEV,WAAW;;EAEX;;;;;;;iBAQc,cACd,MAAM,KAAK,mCACX,gBACC;;;;;;;;;;;;;;;;;;iBAqHa,iBAAiB,OAAO,cAAc;;;;UCnJrC;WACN,WAAW;WACX,QAAQ;;WAER,aAAa;;WAEb;;;;;WAKA,uBAAuB;;;;;;;UAQjB;;;;;EAKf,MAAM,gBAAgB,sBAAsB;;EAE5C,iBAAiB;;;;;;;;;EASjB,KAAK,2BAA2B;;UAGjB,oBAAoB,SAAS,UAAU;;EAEtD;EACA,OAAO,MAAM,eAAe,SAAS,UAAU,IAAI,QAAQ;;;;;UAM5C,kBAAkB,UAAU,YAAY;WAC9C,YAAY,yBAAyB;;WAErC;;WAEA;;;;;;UAOM,iBAAiB,SAAS,UAAU;MAC/C,MAAM,gBAAgB,UAAU,0BAA0B,kBAAkB;WACvE,YAAY,oBAAoB,SAAS;;;;;;;;;;;;;;;;;;;;;;;iBAwBpC,gBAAgB,gBAAgB,UAAU,YAAY,WACpE,YAAY,oBAAoB,SAAS,KACxC,iBAAiB,SAAS;;;;;iBCtFP,sBAAsB;;;;;iBAW5B,aAAa,GAAG,KAAK,kBAAkB,UAAU,IAAI;;;;;;iBASrD,kBAAkB"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { InferInput, InferOutput, StandardSchemaV1 } from "@navios/di";
|
|
2
|
+
import { r as HandlerInfo } from "./execution-context-C5F9rojO.mjs";
|
|
3
|
+
type AttributeContext = ClassDecoratorContext | ClassMethodDecoratorContext | ClassFieldDecoratorContext;
|
|
4
|
+
/**
|
|
5
|
+
* The result of calling an attribute. It is a decorator for a module, a
|
|
6
|
+
* controller, a handler method or a handler field, and it can also be passed
|
|
7
|
+
* in `handler(endpoint, { attributes: [...] }, fn)`.
|
|
8
|
+
*/
|
|
9
|
+
interface AttributeApplication {
|
|
10
|
+
(target: any, context: AttributeContext): any;
|
|
11
|
+
readonly token: symbol;
|
|
12
|
+
readonly value: unknown;
|
|
13
|
+
}
|
|
14
|
+
interface ClassAttribute {
|
|
15
|
+
(): AttributeApplication;
|
|
16
|
+
readonly token: symbol;
|
|
17
|
+
}
|
|
18
|
+
interface ClassSchemaAttribute<Schema extends StandardSchemaV1> {
|
|
19
|
+
(value: InferInput<Schema>): AttributeApplication;
|
|
20
|
+
readonly token: symbol;
|
|
21
|
+
readonly schema: Schema;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* What reading an attribute needs of it. An attribute of either factory, the
|
|
25
|
+
* standard one or the one from `@navios/core/legacy-compat`, has this shape;
|
|
26
|
+
* what calling it returns differs between the two and does not matter here.
|
|
27
|
+
*/
|
|
28
|
+
interface ReadableAttribute {
|
|
29
|
+
readonly token: symbol;
|
|
30
|
+
readonly schema?: undefined;
|
|
31
|
+
}
|
|
32
|
+
interface ReadableSchemaAttribute<Schema extends StandardSchemaV1> {
|
|
33
|
+
readonly token: symbol;
|
|
34
|
+
readonly schema: Schema;
|
|
35
|
+
}
|
|
36
|
+
type AttributeSource = HandlerInfo | {
|
|
37
|
+
attributes: ReadonlyMap<symbol, unknown>;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Creates and reads attributes: typed metadata attached to modules,
|
|
41
|
+
* controllers and handlers.
|
|
42
|
+
*
|
|
43
|
+
* ```ts
|
|
44
|
+
* export const Public = AttributeFactory.createAttribute(Symbol.for('Public'))
|
|
45
|
+
* export const Roles = AttributeFactory.createAttribute(Symbol.for('Roles'), z.array(z.string()))
|
|
46
|
+
*
|
|
47
|
+
* if (AttributeFactory.has(Public, ctx.handler)) return true
|
|
48
|
+
* const roles = AttributeFactory.get(Roles, ctx.handler) // string[] | null
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
declare class AttributeFactory {
|
|
52
|
+
static createAttribute(token: symbol): ClassAttribute;
|
|
53
|
+
static createAttribute<Schema extends StandardSchemaV1>(token: symbol, schema: Schema): ClassSchemaAttribute<Schema>;
|
|
54
|
+
/**
|
|
55
|
+
* The attribute's value for a handler: the handler's own, else the controller's,
|
|
56
|
+
* else the module's. `null` when none has it.
|
|
57
|
+
*/
|
|
58
|
+
static get(attribute: ReadableAttribute, source: AttributeSource): true | null;
|
|
59
|
+
static get<Schema extends StandardSchemaV1>(attribute: ReadableSchemaAttribute<Schema>, source: AttributeSource): InferOutput<Schema> | null;
|
|
60
|
+
/**
|
|
61
|
+
* Every value of the attribute for a handler, most specific first.
|
|
62
|
+
*/
|
|
63
|
+
static getAll(attribute: ReadableAttribute, source: AttributeSource): true[];
|
|
64
|
+
static getAll<Schema extends StandardSchemaV1>(attribute: ReadableSchemaAttribute<Schema>, source: AttributeSource): InferOutput<Schema>[];
|
|
65
|
+
static has(attribute: {
|
|
66
|
+
token: symbol;
|
|
67
|
+
}, source: AttributeSource): boolean;
|
|
68
|
+
}
|
|
69
|
+
export { ClassSchemaAttribute as i, AttributeFactory as n, ClassAttribute as r, AttributeApplication as t };
|
|
70
|
+
//# sourceMappingURL=attribute-factory-BW1kgBqf.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attribute-factory-BW1kgBqf.d.mts","names":[],"sources":["../src/attributes/attribute-factory.mts"],"mappings":";;KAUK,mBACD,wBACA,8BACA;;;;;;UAOa;GACd,aAAa,SAAS;WACd;WACA;;UAGM;MACX;WACK;;UAGM,qBAAqB,eAAe;GAClD,OAAO,WAAW,UAAU;WACpB;WACA,QAAQ;;;;;;;UAqBT;WACC;WACA;;UAGD,wBAAwB,eAAe;WACtC;WACA,QAAQ;;KAGd,kBAAkB;EAAgB,YAAY;;;;;;;;;;;;;;cAwBtC;SACJ,gBAAgB,gBAAgB;SAChC,gBAAgB,eAAe,kBACpC,eACA,QAAQ,SACP,qBAAqB;;;;;SA2BjB,IAAI,WAAW,mBAAmB,QAAQ;SAC1C,IAAI,eAAe,kBACxB,WAAW,wBAAwB,SACnC,QAAQ,kBACP,YAAY;;;;SAaR,OAAO,WAAW,mBAAmB,QAAQ;SAC7C,OAAO,eAAe,kBAC3B,WAAW,wBAAwB,SACnC,QAAQ,kBACP,YAAY;SAWR,IAAI;IAAa;KAAiB,QAAQ"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { InferInput, InferOutput, StandardSchemaV1 } from "@navios/di";
|
|
2
|
+
import { r as HandlerInfo } from "./execution-context-BVSmLkYp.cjs";
|
|
3
|
+
type AttributeContext = ClassDecoratorContext | ClassMethodDecoratorContext | ClassFieldDecoratorContext;
|
|
4
|
+
/**
|
|
5
|
+
* The result of calling an attribute. It is a decorator for a module, a
|
|
6
|
+
* controller, a handler method or a handler field, and it can also be passed
|
|
7
|
+
* in `handler(endpoint, { attributes: [...] }, fn)`.
|
|
8
|
+
*/
|
|
9
|
+
interface AttributeApplication {
|
|
10
|
+
(target: any, context: AttributeContext): any;
|
|
11
|
+
readonly token: symbol;
|
|
12
|
+
readonly value: unknown;
|
|
13
|
+
}
|
|
14
|
+
interface ClassAttribute {
|
|
15
|
+
(): AttributeApplication;
|
|
16
|
+
readonly token: symbol;
|
|
17
|
+
}
|
|
18
|
+
interface ClassSchemaAttribute<Schema extends StandardSchemaV1> {
|
|
19
|
+
(value: InferInput<Schema>): AttributeApplication;
|
|
20
|
+
readonly token: symbol;
|
|
21
|
+
readonly schema: Schema;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* What reading an attribute needs of it. An attribute of either factory, the
|
|
25
|
+
* standard one or the one from `@navios/core/legacy-compat`, has this shape;
|
|
26
|
+
* what calling it returns differs between the two and does not matter here.
|
|
27
|
+
*/
|
|
28
|
+
interface ReadableAttribute {
|
|
29
|
+
readonly token: symbol;
|
|
30
|
+
readonly schema?: undefined;
|
|
31
|
+
}
|
|
32
|
+
interface ReadableSchemaAttribute<Schema extends StandardSchemaV1> {
|
|
33
|
+
readonly token: symbol;
|
|
34
|
+
readonly schema: Schema;
|
|
35
|
+
}
|
|
36
|
+
type AttributeSource = HandlerInfo | {
|
|
37
|
+
attributes: ReadonlyMap<symbol, unknown>;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Creates and reads attributes: typed metadata attached to modules,
|
|
41
|
+
* controllers and handlers.
|
|
42
|
+
*
|
|
43
|
+
* ```ts
|
|
44
|
+
* export const Public = AttributeFactory.createAttribute(Symbol.for('Public'))
|
|
45
|
+
* export const Roles = AttributeFactory.createAttribute(Symbol.for('Roles'), z.array(z.string()))
|
|
46
|
+
*
|
|
47
|
+
* if (AttributeFactory.has(Public, ctx.handler)) return true
|
|
48
|
+
* const roles = AttributeFactory.get(Roles, ctx.handler) // string[] | null
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
declare class AttributeFactory {
|
|
52
|
+
static createAttribute(token: symbol): ClassAttribute;
|
|
53
|
+
static createAttribute<Schema extends StandardSchemaV1>(token: symbol, schema: Schema): ClassSchemaAttribute<Schema>;
|
|
54
|
+
/**
|
|
55
|
+
* The attribute's value for a handler: the handler's own, else the controller's,
|
|
56
|
+
* else the module's. `null` when none has it.
|
|
57
|
+
*/
|
|
58
|
+
static get(attribute: ReadableAttribute, source: AttributeSource): true | null;
|
|
59
|
+
static get<Schema extends StandardSchemaV1>(attribute: ReadableSchemaAttribute<Schema>, source: AttributeSource): InferOutput<Schema> | null;
|
|
60
|
+
/**
|
|
61
|
+
* Every value of the attribute for a handler, most specific first.
|
|
62
|
+
*/
|
|
63
|
+
static getAll(attribute: ReadableAttribute, source: AttributeSource): true[];
|
|
64
|
+
static getAll<Schema extends StandardSchemaV1>(attribute: ReadableSchemaAttribute<Schema>, source: AttributeSource): InferOutput<Schema>[];
|
|
65
|
+
static has(attribute: {
|
|
66
|
+
token: symbol;
|
|
67
|
+
}, source: AttributeSource): boolean;
|
|
68
|
+
}
|
|
69
|
+
export { ClassSchemaAttribute as i, AttributeFactory as n, ClassAttribute as r, AttributeApplication as t };
|
|
70
|
+
//# sourceMappingURL=attribute-factory-DqN4x5XM.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attribute-factory-DqN4x5XM.d.cts","names":[],"sources":["../src/attributes/attribute-factory.mts"],"mappings":";;KAUK,mBACD,wBACA,8BACA;;;;;;UAOa;GACd,aAAa,SAAS;WACd;WACA;;UAGM;MACX;WACK;;UAGM,qBAAqB,eAAe;GAClD,OAAO,WAAW,UAAU;WACpB;WACA,QAAQ;;;;;;;UAqBT;WACC;WACA;;UAGD,wBAAwB,eAAe;WACtC;WACA,QAAQ;;KAGd,kBAAkB;EAAgB,YAAY;;;;;;;;;;;;;;cAwBtC;SACJ,gBAAgB,gBAAgB;SAChC,gBAAgB,eAAe,kBACpC,eACA,QAAQ,SACP,qBAAqB;;;;;SA2BjB,IAAI,WAAW,mBAAmB,QAAQ;SAC1C,IAAI,eAAe,kBACxB,WAAW,wBAAwB,SACnC,QAAQ,kBACP,YAAY;;;;SAaR,OAAO,WAAW,mBAAmB,QAAQ;SAC7C,OAAO,eAAe,kBAC3B,WAAW,wBAAwB,SACnC,QAAQ,kBACP,YAAY;SAWR,IAAI;IAAa;KAAiB,QAAQ"}
|