@elysiumjs/core 0.7.0 → 0.10.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 +115 -0
- package/README.md +37 -22
- package/dist/app.d.ts +72 -54
- package/dist/command.d.ts +20 -4
- package/dist/connections.d.ts +17 -0
- package/dist/container.d.ts +134 -0
- package/dist/errors.d.ts +159 -0
- package/dist/event-wiring.d.ts +23 -0
- package/dist/event.d.ts +39 -1
- package/dist/http.d.ts +9 -3
- package/dist/index.d.ts +13 -8
- package/dist/index.js +14 -14
- package/dist/kernel.d.ts +71 -0
- package/dist/logger.d.ts +15 -0
- package/dist/metadata.d.ts +46 -0
- package/dist/middleware.d.ts +18 -5
- package/dist/module-context.d.ts +20 -0
- package/dist/module-graph.d.ts +68 -0
- package/dist/module.d.ts +83 -25
- package/dist/redis.d.ts +56 -19
- package/dist/service.d.ts +60 -16
- package/dist/testing.d.ts +39 -0
- package/dist/utils.d.ts +24 -7
- package/dist/wamp.d.ts +72 -92
- package/dist/websocket.d.ts +5 -0
- package/package.json +18 -9
- package/dist/job.d.ts +0 -105
- package/dist/worker.d.ts +0 -219
- package/tsconfig.json +0 -12
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base class of every error thrown by the Elysium framework.
|
|
3
|
+
*
|
|
4
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
5
|
+
*/
|
|
6
|
+
export declare class ElysiumError extends Error {
|
|
7
|
+
constructor(message: string);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Thrown when the module graph contains an import cycle.
|
|
11
|
+
*
|
|
12
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
13
|
+
*/
|
|
14
|
+
export declare class ModuleCycleError extends ElysiumError {
|
|
15
|
+
readonly path: string[];
|
|
16
|
+
constructor(path: string[]);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Thrown when a class used as a module is not decorated with `@Module`.
|
|
20
|
+
*
|
|
21
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
22
|
+
*/
|
|
23
|
+
export declare class InvalidModuleError extends ElysiumError {
|
|
24
|
+
readonly className: string;
|
|
25
|
+
constructor(className: string);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Thrown when two modules declare the same global service.
|
|
29
|
+
*
|
|
30
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
31
|
+
*/
|
|
32
|
+
export declare class DuplicateGlobalServiceError extends ElysiumError {
|
|
33
|
+
readonly serviceName: string;
|
|
34
|
+
readonly modules: [string, string];
|
|
35
|
+
constructor(serviceName: string, modules: [string, string]);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Thrown when two modules register the same command.
|
|
39
|
+
*
|
|
40
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
41
|
+
*/
|
|
42
|
+
export declare class DuplicateCommandError extends ElysiumError {
|
|
43
|
+
readonly command: string;
|
|
44
|
+
readonly modules: [string, string];
|
|
45
|
+
constructor(command: string, modules: [string, string]);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Thrown when a module is configured from two conflicting sites.
|
|
49
|
+
*
|
|
50
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
51
|
+
*/
|
|
52
|
+
export declare class ConflictingModuleConfigError extends ElysiumError {
|
|
53
|
+
readonly module: string;
|
|
54
|
+
readonly sites: [string, string];
|
|
55
|
+
constructor(module: string, sites: [string, string]);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Thrown when a module requires configuration that was never provided.
|
|
59
|
+
*
|
|
60
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
61
|
+
*/
|
|
62
|
+
export declare class MissingModuleConfigError extends ElysiumError {
|
|
63
|
+
readonly module: string;
|
|
64
|
+
readonly keys: string[];
|
|
65
|
+
constructor(module: string, keys: string[]);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Thrown when a module's configuration is present but invalid.
|
|
69
|
+
*
|
|
70
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
71
|
+
*/
|
|
72
|
+
export declare class InvalidModuleConfigError extends ElysiumError {
|
|
73
|
+
readonly module: string;
|
|
74
|
+
readonly key: string;
|
|
75
|
+
readonly reason: string;
|
|
76
|
+
constructor(module: string, key: string, reason: string);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Thrown when a service is requested from a module that cannot see it.
|
|
80
|
+
*
|
|
81
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
82
|
+
*/
|
|
83
|
+
export declare class ServiceNotVisibleError extends ElysiumError {
|
|
84
|
+
readonly service: string;
|
|
85
|
+
readonly requester: string;
|
|
86
|
+
readonly module: string | null;
|
|
87
|
+
readonly owner: string | null;
|
|
88
|
+
constructor(service: string, requester: string, module: string | null, owner: string | null);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Thrown when a service is not registered anywhere.
|
|
92
|
+
*
|
|
93
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
94
|
+
*/
|
|
95
|
+
export declare class ServiceNotFoundError extends ElysiumError {
|
|
96
|
+
readonly service: string;
|
|
97
|
+
constructor(service: string);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Thrown when a service is requested before it has been initialized.
|
|
101
|
+
*
|
|
102
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
103
|
+
*/
|
|
104
|
+
export declare class ServiceNotReadyError extends ElysiumError {
|
|
105
|
+
readonly service: string;
|
|
106
|
+
readonly owner: string | null;
|
|
107
|
+
constructor(service: string, owner?: string | null);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Thrown when services depend on each other in a cycle.
|
|
111
|
+
*
|
|
112
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
113
|
+
*/
|
|
114
|
+
export declare class CircularDependencyError extends ElysiumError {
|
|
115
|
+
readonly path: string[];
|
|
116
|
+
constructor(path: string[]);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Thrown when two different module classes share the same name.
|
|
120
|
+
*
|
|
121
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
122
|
+
*/
|
|
123
|
+
export declare class DuplicateModuleNameError extends ElysiumError {
|
|
124
|
+
readonly moduleName: string;
|
|
125
|
+
constructor(moduleName: string);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Thrown when a service lives in a module skipped for the current environment.
|
|
129
|
+
*
|
|
130
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
131
|
+
*/
|
|
132
|
+
export declare class EnvironmentSkippedModuleError extends ElysiumError {
|
|
133
|
+
readonly service: string;
|
|
134
|
+
readonly requester: string;
|
|
135
|
+
readonly skippedModule: string;
|
|
136
|
+
readonly environment: string;
|
|
137
|
+
constructor(service: string, requester: string, skippedModule: string, environment: string);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Thrown when a class listed in a module's `controllers` is not a decorated controller.
|
|
141
|
+
*
|
|
142
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
143
|
+
*/
|
|
144
|
+
export declare class InvalidControllerError extends ElysiumError {
|
|
145
|
+
readonly className: string;
|
|
146
|
+
readonly moduleName: string;
|
|
147
|
+
constructor(className: string, moduleName: string);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Thrown when an instance method of a class that is not a service is declared an event listener.
|
|
151
|
+
*
|
|
152
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
153
|
+
*/
|
|
154
|
+
export declare class EventListenerNotSupportedError extends ElysiumError {
|
|
155
|
+
readonly className: string;
|
|
156
|
+
readonly method: string;
|
|
157
|
+
readonly moduleName: string;
|
|
158
|
+
constructor(className: string, method: string, moduleName: string);
|
|
159
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Class } from 'type-fest';
|
|
2
|
+
import type { EventData } from './event';
|
|
3
|
+
import type { ModuleNode } from './module-graph';
|
|
4
|
+
/**
|
|
5
|
+
* A listener the kernel added to the event bus.
|
|
6
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
7
|
+
*/
|
|
8
|
+
export type WiredListener = {
|
|
9
|
+
readonly event: string;
|
|
10
|
+
readonly wrapper: (data: EventData<any>) => Promise<void>;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Registers the decorated event listeners of `owned` classes on the event bus, each running
|
|
14
|
+
* in `node`'s module context.
|
|
15
|
+
*
|
|
16
|
+
* @param node The module the classes belong to.
|
|
17
|
+
* @param owned The module's own classes (services and controllers).
|
|
18
|
+
* @param services The subset of `owned` registered as services in the module.
|
|
19
|
+
* @returns The listeners added, so they can be removed on shutdown.
|
|
20
|
+
* @throws {EventListenerNotSupportedError} For an instance listener on a non-service class.
|
|
21
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
22
|
+
*/
|
|
23
|
+
export declare function wireEventListeners(node: ModuleNode, owned: readonly Class<any>[], services: ReadonlySet<Class<any>>): WiredListener[];
|
package/dist/event.d.ts
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
/**
|
|
3
|
+
* Internal event bus used by the framework.
|
|
4
|
+
* @internal
|
|
5
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
6
|
+
*/
|
|
7
|
+
export declare class EventBus extends EventEmitter {
|
|
8
|
+
static readonly instance: EventBus;
|
|
9
|
+
private constructor();
|
|
10
|
+
emitError(error: unknown): void;
|
|
11
|
+
emitEvent(event: string, data: unknown, source?: unknown): void;
|
|
12
|
+
}
|
|
1
13
|
/**
|
|
2
14
|
* Stores the event data with the source.
|
|
3
15
|
* @author Axel Nana <axel.nana@workbud.com>
|
|
@@ -39,6 +51,23 @@ export type ListenProps = {
|
|
|
39
51
|
*/
|
|
40
52
|
prepend?: boolean;
|
|
41
53
|
};
|
|
54
|
+
/**
|
|
55
|
+
* A listener recorded on a class by `@Event.on` / `@Event.once`.
|
|
56
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
57
|
+
*/
|
|
58
|
+
export type EventListenerMeta = {
|
|
59
|
+
readonly event: string;
|
|
60
|
+
readonly method: string | symbol;
|
|
61
|
+
readonly mode: 'on' | 'once';
|
|
62
|
+
readonly prepend: boolean;
|
|
63
|
+
readonly static: boolean;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Gets the listeners recorded on a class by the `@Event.on` / `@Event.once` decorators.
|
|
67
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
68
|
+
* @param cls The class to inspect.
|
|
69
|
+
*/
|
|
70
|
+
export declare function getEventListeners(cls: object): readonly EventListenerMeta[];
|
|
42
71
|
export declare namespace Event {
|
|
43
72
|
/**
|
|
44
73
|
* Emits an event with the provided data and source.
|
|
@@ -49,7 +78,14 @@ export declare namespace Event {
|
|
|
49
78
|
*/
|
|
50
79
|
const emit: <TData, TSource = any>(event: string, data: TData, source?: TSource | null) => void;
|
|
51
80
|
/**
|
|
52
|
-
* Marks a method as an event listener.
|
|
81
|
+
* Marks a method as an event listener. The decorator only records the listener on the class.
|
|
82
|
+
* The kernel registers it when the module that lists the class in its `services` or
|
|
83
|
+
* `controllers` initialises, and runs it in that module's context, so it sees the module's
|
|
84
|
+
* private services. Listeners on classes that no loaded module lists never fire, and a lazy
|
|
85
|
+
* CLI boot only wires the modules it prepares (eager boot wires every module).
|
|
86
|
+
*
|
|
87
|
+
* Static methods are called on the class. Instance methods require a class registered as a
|
|
88
|
+
* service: they run on the instance the container resolves.
|
|
53
89
|
* @author Axel Nana <axel.nana@workbud.com>
|
|
54
90
|
* @param options The decorator options.
|
|
55
91
|
*/
|
|
@@ -63,6 +99,7 @@ export declare namespace Event {
|
|
|
63
99
|
function on<TData, TSource = any>(event: string, handler: EventHandler<TData, TSource>): void;
|
|
64
100
|
/**
|
|
65
101
|
* Marks a method as an event listener that listens for the event only once.
|
|
102
|
+
* Like {@link Event.on}, the decorator is metadata-only and the kernel wires it per module.
|
|
66
103
|
* @author Axel Nana <axel.nana@workbud.com>
|
|
67
104
|
* @param options The decorator options.
|
|
68
105
|
*/
|
|
@@ -88,6 +125,7 @@ export declare namespace Event {
|
|
|
88
125
|
/**
|
|
89
126
|
* Marks a method as an event listener.
|
|
90
127
|
* @param options The decorator options.
|
|
128
|
+
* @throws {ElysiumError} If `options.mode` is neither `on` nor `once`.
|
|
91
129
|
*/
|
|
92
130
|
const listen: (options: ListenProps) => MethodDecorator;
|
|
93
131
|
}
|
package/dist/http.d.ts
CHANGED
|
@@ -62,6 +62,12 @@ export type Context<TBody = unknown, TController = unknown, TModule extends Modu
|
|
|
62
62
|
body: TBody;
|
|
63
63
|
}, Singleton<TController, TModule>>;
|
|
64
64
|
export type ElysiaApp = Elysia<Route, Singleton>;
|
|
65
|
+
/**
|
|
66
|
+
* Name of the global service running a callback in a database transaction, used by
|
|
67
|
+
* `@transactional` handlers. Provided by database modules such as `DrizzleModule`.
|
|
68
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
69
|
+
*/
|
|
70
|
+
export declare const DATABASE_TRANSACTION_SERVICE = "db.transaction";
|
|
65
71
|
/**
|
|
66
72
|
* The scope of an HTTP controller.
|
|
67
73
|
* @author Axel Nana <axel.nana@workbud.com>
|
|
@@ -92,7 +98,7 @@ export type HttpControllerProps = {
|
|
|
92
98
|
scope?: HttpControllerScope;
|
|
93
99
|
/**
|
|
94
100
|
* The list of tags for the controller.
|
|
95
|
-
* Used in
|
|
101
|
+
* Used in OpenAPI documentation.
|
|
96
102
|
*/
|
|
97
103
|
tags?: Array<string>;
|
|
98
104
|
/**
|
|
@@ -120,12 +126,12 @@ export type RequestHandlerDecoratorProps = {
|
|
|
120
126
|
response?: TSchema | Record<number, TSchema>;
|
|
121
127
|
/**
|
|
122
128
|
* The operation ID for the handler.
|
|
123
|
-
* Used in
|
|
129
|
+
* Used in OpenAPI documentation.
|
|
124
130
|
*/
|
|
125
131
|
operationId?: string;
|
|
126
132
|
/**
|
|
127
133
|
* The description for the handler.
|
|
128
|
-
* Used in
|
|
134
|
+
* Used in OpenAPI documentation.
|
|
129
135
|
*/
|
|
130
136
|
description?: string;
|
|
131
137
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -5,17 +5,22 @@ export { type CommandArgumentProps, type CommandClass, Command, CommandArgumentT
|
|
|
5
5
|
export { ConsoleFormat, InteractsWithConsole } from './console';
|
|
6
6
|
export { Env } from './env';
|
|
7
7
|
export { type EventData, type EventHandler, Event } from './event';
|
|
8
|
-
export { type LoggerInterface, ConsoleLogger } from './logger';
|
|
9
|
-
export { type Context, type Route, HttpControllerScope, Http } from './http';
|
|
10
|
-
export {
|
|
8
|
+
export { type LoggerInterface, ConsoleLogger, getLogger, LOGGER_SERVICE } from './logger';
|
|
9
|
+
export { type Context, type Route, DATABASE_TRANSACTION_SERVICE, HttpControllerScope, Http } from './http';
|
|
10
|
+
export { Metadata } from './metadata';
|
|
11
11
|
export { Middleware } from './middleware';
|
|
12
12
|
export { RequestLoggerMiddleware } from './middlewares/request-logger.middleware';
|
|
13
|
-
export {
|
|
14
|
-
export {
|
|
15
|
-
export {
|
|
16
|
-
export { type
|
|
13
|
+
export { CircularDependencyError, ConflictingModuleConfigError, DuplicateCommandError, DuplicateGlobalServiceError, DuplicateModuleNameError, ElysiumError, EnvironmentSkippedModuleError, EventListenerNotSupportedError, InvalidModuleError, InvalidModuleConfigError, MissingModuleConfigError, ModuleCycleError, ServiceNotFoundError, ServiceNotReadyError, ServiceNotVisibleError } from './errors';
|
|
14
|
+
export { needsDefaultAlias, runAll } from './connections';
|
|
15
|
+
export { Kernel, KERNEL_SERVICE } from './kernel';
|
|
16
|
+
export { type ConfiguredModule, type ModuleClass, type ModuleProps, Module } from './module';
|
|
17
|
+
export { ModuleContext } from './module-context';
|
|
18
|
+
export { type ModuleGraph, type ModuleNode } from './module-graph';
|
|
19
|
+
export { type TestingApp, type TestingOptions } from './testing';
|
|
20
|
+
export { type RedisConnectionProps, type RedisModuleConfig, Redis, RedisModule } from './redis';
|
|
21
|
+
export { type ServiceDefinition, type ServiceFactoryDefinition, ServiceScope, Service } from './service';
|
|
22
|
+
export { type WampRegistrationOptions, type WampSubscriptionOptions, type WampProps, type WampRegistrationHandlerArgs, type WampSubscriptionHandlerArgs, type WampRegistrationHandler, type WampSubscriptionHandler, type WampClientProps, type WampModuleConfig, Wamp, WampModule } from './wamp';
|
|
17
23
|
export { type WS, type WSError, Websocket } from './websocket';
|
|
18
|
-
export { type QueueOptions, WorkerPool, Worker } from './worker';
|
|
19
24
|
/**
|
|
20
25
|
* The type for the context of the application.
|
|
21
26
|
* @author Axel Nana <axel.nana@workbud.com>
|